Skip to content

Instantly share code, notes, and snippets.

View stavxyz's full-sized avatar
😿

samuel stavxyz

😿
View GitHub Profile
@stavxyz
stavxyz / com.example.logout_idle_users.plist
Created March 11, 2025 02:40
logout inactive users macOS
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.example.logout_idle_users</string>
<key>ProgramArguments</key>
<array>
<string>/bin/bash</string>
@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 / 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,
@stavxyz
stavxyz / tf_debug.txt
Last active May 9, 2019 21:16
TF_LOG=DEBUG terraform import digitalocean_record.my_z_sub_record z.example.com,70910975
2019-05-09T16:03:32.209-0500 [DEBUG] plugin.terraform-provider-digitalocean_v1.2.0_x4:
2019-05-09T16:03:32.209-0500 [DEBUG] plugin.terraform-provider-digitalocean_v1.2.0_x4: {
2019-05-09T16:03:32.209-0500 [DEBUG] plugin.terraform-provider-digitalocean_v1.2.0_x4: "id": "not_found",
2019-05-09T16:03:32.209-0500 [DEBUG] plugin.terraform-provider-digitalocean_v1.2.0_x4: "message": "The resource you were accessing could not be found."
2019-05-09T16:03:32.209-0500 [DEBUG] plugin.terraform-provider-digitalocean_v1.2.0_x4: }
2019-05-09T16:03:32.209-0500 [DEBUG] plugin.terraform-provider-digitalocean_v1.2.0_x4: -----------------------------------------------------
2019/05/09 16:03:32 [ERROR] root: eval: *terraform.EvalImportState, err: import digitalocean_record.my_z_sub_record (id: z.example.com,70910975): nil entry in ImportState results. This is always a bug with
the resource that is being imported. Please report this as
a bug to Terraform.
2019/05/09 16:03:32 [ERROR] root: eval: *terraform.EvalSequence, err: imp
@stavxyz
stavxyz / delve demo.md
Created May 3, 2019 13:55
how to use delve

dlv debug compiles your program with optimizations disabled, starts and attaches to it.

By default, with no arguments, Delve will compile the 'main' package in the current directory, and begin to debug it. Alternatively you can specify a package name and Delve will compile that package instead, and begin a new debug session.

(similar to go run ...)