Skip to content

Instantly share code, notes, and snippets.

View kiprasmel's full-sized avatar

Kipras Melnikovas kiprasmel

View GitHub Profile
@kiprasmel
kiprasmel / bash-argv-forwarding
Last active February 20, 2024 14:36
bash argv forwarding: $* vs $@ vs "$*" vs "$@" -- use "$@"
#!/usr/bin/env bash
fn() {
base="$1"
shift
printf "$base with \$*\n"
for i in $* ; do printf " $i\n"; done;
printf "$base with \$@\n"
for i in $@ ; do printf " $i\n"; done;
printf "$base with \"\$*\"\n"
@kiprasmel
kiprasmel / roam-expand-all-linked-refs.js
Last active September 17, 2023 18:02
roam: Expand All blocks of linked refs
/**
* https://gist.github.com/kiprasmel/3fb1578e1f428dd1dd8e88683ca8c400
*
* put in a javascript code block under a block containing {{[[roam/js]]}} text, like so:
* - {{[[roam/js]]}}
* - this code
*/
// https://roamresearch.com/#/app/developer-documentation/page/JTLUegLiI
window.roamAlphaAPI.ui
@gaearon
gaearon / 00-README-NEXT-SPA.md
Last active May 5, 2024 15:12
Next.js SPA example with dynamic client-only routing and static hosting

Next.js client-only SPA example

Made this example to show how to use Next.js router for a 100% SPA (no JS server) app.

You use Next.js router like normally, but don't define getStaticProps and such. Instead you do client-only fetching with swr, react-query, or similar methods.

You can generate HTML fallback for the page if there's something meaningful to show before you "know" the params. (Remember, HTML is static, so it can't respond to dynamic query. But it can be different per route.)

Don't like Next? Here's how to do the same in Gatsby.

#!/bin/sh
for p in *projects/; do
printf "\n$p\n\n"
for dir in $(find "./$p" -type d -maxdepth 1); do
gitdir="$dir/.git"
test -d "$gitdir" && {
printf "$dir\n"
git --work-tree="$dir" --git-dir="$gitdir" status -s
}
<!--
- https://preactjs.com/guide/v10/getting-started#no-build-tools-route
- https://preactjs.com/guide/v10/getting-started#alternatives-to-jsx
-->
<script type="module">
import * as preact from 'https://unpkg.com/preact?module';
import htm from 'https://unpkg.com/htm?module';
const h = htm.bind(preact.h);
/**
* https://gist.github.com/kiprasmel/75de24e48c8c442e55d4771768d7ba49
*/
export type Cb = () => void;
export class EventEmitter<Event extends string> {
listeners: Map<Event, Cb[]> = new Map();
/**
@tabatkins
tabatkins / pipeline.md
Last active October 17, 2022 22:40
Comparing the three pipeline proposals

We've been deadlocked for a while on the pipeline operator proposal, for a few reasons. Partially it's just low implementor interest, as this is fundamentally just syntactic sugar, but also because there are three competing proposals and the proponents of each haven't been convinced by the others yet.

In this essay I hope to briefly outline the problem space, summarize the three proposals, and talk about what's gained/lost by each of them. (Spoiler: they're all nearly identical; we're arguing over very small potatoes.)

@kiprasmel
kiprasmel / stdin.cpp
Last active February 4, 2021 21:08
stdin parsing with simple streams
#include <bits/stdc++.h>
using namespace std;
int main() {
// replace this with `cin` or `ifstream` or whatever)
stringstream ss("ayyy lmao asd_qwe: 69, 420,1337, nice yo\nhehe xd: 1, 2, 3, kekw pog");
string a, b, c;
getline(ss, a, ' '); // ayyy (till space)
getline(ss, b, ' '); // lmao (till space)
@kiprasmel
kiprasmel / iptables_reset.sh
Last active February 9, 2021 14:42
iptables_reset.sh - whitelist must-haves, block everything else 🥳
#!/usr/bin/env sh
# iptables_reset.sh
# get via e.g. curl ifconfig.me
MY_LOCAL_IP=""
[ -z "$MY_LOCAL_IP" ] && {
printf "
usage:
add your local ip inside to the script, then
@kiprasmel
kiprasmel / deploy.sh
Created January 18, 2021 17:03
simple docker deploy.sh
#!/usr/bin/env bash
USER="kipras"
NAME="turbo-schedule"
TAG="$1"
[ -z "$TAG" ] && TAG="latest"
docker stop "$NAME"
docker rename "$NAME" "$NAME".old