Skip to content

Instantly share code, notes, and snippets.

View cgsdev0's full-sized avatar
🐻

cgsdev0

🐻
View GitHub Profile
#!/bin/bash
function quote_args() {
SPACER=
while [[ $# -gt 0 ]]; do
printf "%s\"%s\"" "$SPACER" "${1//\"/\\\"}"
shift
SPACER=' '
done
}
#!/bin/bash
popup() {
TMP="$(mktemp)"
trap "rm $TMP" EXIT
cat > "$TMP"
tmux display-popup -w $WIDTH -h $HEIGHT $* "cat \"$TMP\" | termsand"
}
PANE=$(tmux display -p "#{pane_id}")
@cgsdev0
cgsdev0 / k-smallest-pairs.bash
Created July 23, 2024 07:15
k smallest pairs
#!/bin/bash
ARR1=(1 2 3 4 5)
ARR2=(2 3 4 5 6)
K=5
declare -a priority_queue
@cgsdev0
cgsdev0 / command.sh
Created March 11, 2024 01:56
uploadthing speedrun
APP_NAME="bash"; COOKIE_STR="$(cat ~/.uploadthingcookie)"; \
JWT="$(curl -Ss \
'https://clerk.uploadthing.com/v1/client/sessions/sess_2dW3vhIqxSNMjfSOZnFoDgWHYfZ/tokens?_clerk_js_version=4.70.3' \
-X 'POST' \
-H 'authority: clerk.uploadthing.com' \
-H 'accept: */*' \
-H 'accept-language: en-US,en;q=0.9' \
-H 'content-length: 0' \
-H 'content-type: application/x-www-form-urlencoded' \
-H "$COOKIE_STR" \
@cgsdev0
cgsdev0 / house_builder.sh
Created February 3, 2024 16:07
house builder pattern in bash
#!/usr/bin/env bash
function house_builder() {
# floors,rooms,has_garage
echo "0,0,0"
}
function set_field() {
local f r g
IFS=, read f r g
@cgsdev0
cgsdev0 / index.sh
Created December 29, 2023 03:50
htmx.trigger test
htmx_page <<-EOF
<script>
window.addEventListener("DOMContentLoaded", () => {
htmx.trigger("#thing", "myEvent", {answer : 42});
});
</script>
<div id="thing" hx-trigger="myEvent" hx-post="/test"></div>
EOF
@cgsdev0
cgsdev0 / ld54.sh
Created October 4, 2023 13:42
LD54 analysis tools
#!/bin/bash
cd /var/lib/docker/volumes/root_ld54volume/_data
list_scores() {
for LEVEL in {0..14}; do
SCORE_AND_USER=$(sort $LEVEL -n | head -1)
SCORE=$(echo "$SCORE_AND_USER" | cut -d' ' -f1)
USER=$(echo "$SCORE_AND_USER" | cut -d' ' -f2)
FREQ=$(sort -u "$LEVEL" | grep -c '^'"$SCORE ")
@cgsdev0
cgsdev0 / twitch_oauth.js
Created August 19, 2023 10:59
twitch identity provider flow
///////////////////////////
// Client
///////////////////////////
// when the user clicks the 'login with twitch' button...
document.location =
`https://id.twitch.tv/oauth2/authorize` +
`?client_id=${TWITCH_CLIENT_ID}` +
`&redirect_uri=${redirect}` +
`&response_type=token`;
@cgsdev0
cgsdev0 / fizzbuzz_x-state.js
Last active July 27, 2023 07:24
fizzbuzz in x-state
// try it out here: https://codesandbox.io/s/recursing-meadow-t87lvp?file=/src/index.js
export const machine = createMachine(
{
id: "fizzbuzz",
context: {
i: "0"
},
initial: "Start",
states: {
@cgsdev0
cgsdev0 / fizzbuzz.c
Last active May 22, 2023 20:25
new fizzbuzz just dropped
#include <stdio.h>
#include <stdlib.h>
// boilerplate; ignore this part
#define loop(x) for(int _i=x;_i<=0x64;_i+=x)
#define i c+(_i-1)*012
#define pn sprintf(i,"%d\n",_i)
#define ps(s) strcpy(i,#s"\n")
#define say(s) strcmp(#s,"Number")?ps(s):pn