Skip to content

Instantly share code, notes, and snippets.

View stavxyz's full-sized avatar
😿

samuel stavxyz

😿
View GitHub Profile
@stavxyz
stavxyz / watchman-rsync.md
Last active December 13, 2022 04:30
keeping files in sync over ssh for modern humans

the problem

  • I want to keep files instantaneously in-sync across two workstations
  • I want the solution to be platform-independent (mostly)
  • I want this to run in the foreground in a tmux pane so I can easily monitor
  • I want one simple command that I can re-use for any combination of target files/directories and destination directories
  • I want some control on how deletions are handled
  • Preferably, I won't have to mess with fsevents or inotify or maintaining additional scripts

https://github.com/facebook/watchman (specifically, watchman-make with --run) and an ssh connection makes this super easy.

@stavxyz
stavxyz / main.dart
Last active November 3, 2021 22:28
calculate session price
import 'dart:math' as math;
import 'dart:developer' as developer;
void main() {
var sessionPrice = "125.00";
print(calculateSessionPriceTotal(sessionPrice));
}
//////////////////////////////////////////////////////////////////
// N.B. For FlutterFlow, you only need to copy from here down
@stavxyz
stavxyz / script.sh
Last active June 6, 2022 17:53
BASHISM - If you are a civilized person, you'll start all your bash scripts like this
#!/usr/bin/env bash
# Undefined variables are errors.
set -euoE pipefail
errcho ()
{
printf "%s\n" "$@" 1>&2
}
@stavxyz
stavxyz / hello.txt
Last active June 2, 2020 19:47
hello
👍
cowabunga
@stavxyz
stavxyz / hasItem.sh
Created December 3, 2019 19:40
Does the bash array include the item?
function hasItem() {
local _item=${1}
# local _array=("$@")
local _array=("${@:2}")
echo "Looking at array --> ${_array[*]}"
for i in "${_array[@]}"; do
echo "Comparing ${i} to ${_item}"
if [[ $_item == "${i}" ]]; then
echo "yes"
@stavxyz
stavxyz / Makefile
Created November 1, 2019 16:17
makefile, act like a CLI
#
# HACKS TO MAKE THIS BEHAVE MORE LIKE A CLI
#
PASS_ARGS_COMMANDS := run-command next-command-not-yet-implemented
FIRST_TARGET := $(firstword $(MAKECMDGOALS))
ifneq ($(filter $(FIRST_TARGET),$(PASS_ARGS_COMMANDS)),)
# use the rest as arguments to pass to subcommand
$(info $(FIRST_TARGET) is a pass-args command)
PASS_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
# ...and turn them into do-nothing targets
@stavxyz
stavxyz / args_hash.py
Last active October 25, 2019 15:49
args / kwargs hash - works in python 2 & 3. Useful for memoizers.
def _tob(_string, enc='utf8'):
if isinstance(_string, unicode):
return _string.encode(enc)
return b'' if _string is None else bytes(_string)
def args_hash(*args, **kw):
"""Calculate a hash value from string args and kwargs.
Given the same positional arguments and keyword
@stavxyz
stavxyz / readGatsbyConfig.go
Last active September 27, 2019 16:40
read a gatsby config with golang
package main
import (
"encoding/json"
"fmt"
"log"
"os"
"os/exec"
)
@stavxyz
stavxyz / tf-plugin.sh
Last active August 14, 2019 17:59
build terraform plugins
#!/usr/bin/env bash
# Undefined variables are errors.
set -euo pipefail
errcho ()
{
echo "$@" 1>&2
}
@stavxyz
stavxyz / expected.json
Last active June 19, 2019 00:58
JSON migrations with `jq`
{
"A": "1!",
"b": "2",
"Z": "spam!",
"?": [
83,
65,
84,
85,
82,