Skip to content

Instantly share code, notes, and snippets.

View wrouesnel's full-sized avatar

Will Rouesnel wrouesnel

View GitHub Profile
@wrouesnel
wrouesnel / recurse_object.py
Last active November 3, 2021 02:05
Simple function for recursively iterating JSON-like data in Python
from collections.abc import Mapping
from typing import Any, Callable, Iterable, MutableMapping, MutableSequence
def recurse_object(o: Any,
k=None,
fn: Callable[[Any,Any,Any],Any]=None,
prefn:Callable[[Any,Any],None]=None,
postfn:Callable[[Any,Any,Any,Any],Any]=None,
@wrouesnel
wrouesnel / cliptype
Created April 22, 2021 05:02
Autotype clipboard contents
#!/bin/bash
xclip -selection clipboard -out | xdotool selectwindow windowfocus type --clearmodifiers --delay 25 --window %@ --file -
DECLARE @TableName VARCHAR(MAX) = 'NewsItem' -- Replace 'NewsItem' with your table name
DECLARE @TableSchema VARCHAR(MAX) = 'Markets' -- Replace 'Markets' with your schema name
DECLARE @result varchar(max) = ''
SET @result = @result + 'using System;' + CHAR(13) + CHAR(13)
IF (@TableSchema IS NOT NULL)
BEGIN
SET @result = @result + 'namespace ' + @TableSchema + CHAR(13) + '{' + CHAR(13)
END
@wrouesnel
wrouesnel / windows_ux_annoyances.ps1
Last active February 13, 2021 12:20
Powershell script to make a bunch of initial windows annoyances changes
# Sets some UX annoyances in Windows
# *************************************************************
# * Change how often Windows asks you for feedback to "NEVER" *
# *************************************************************
New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Siuf\Rules" `
-Name "NumberOfSIUFInPeriod" `
-PropertyType DWORD `
-Value 0x00000000 `
@wrouesnel
wrouesnel / gpg.conf
Created September 8, 2020 02:12
GPG defaults
no-comments
no-emit-version
keyid-format 0xlong
with-fingerprint
verify-options show-uid-validity
list-options show-uid-validity
use-agent
@wrouesnel
wrouesnel / bash-get-current-script-dir.sh
Created July 6, 2020 02:03
Get the current script directory for a bash shell script.
# See: https://stackoverflow.com/questions/59895/how-to-get-the-source-directory-of-a-bash-script-from-within-the-script-itself
# Note: you can't refactor this out: its at the top of every script so the scripts can find their includes.
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
SCRIPT_DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
@wrouesnel
wrouesnel / zfs_recieve_stream.go
Created May 13, 2020 17:03
Implementation of determining ZFS stream type before receiving.
package main
import (
"bytes"
"errors"
"fmt"
"io"
"os"
"os/exec"
"os/signal"
@wrouesnel
wrouesnel / gist:0ddb530bf661c43056ff72a9bb95ba76
Created March 23, 2020 02:55
How to get the source directory of a Bash script from within the script itself (so I can stop looking up SO)
#!/bin/bash
# See: https://stackoverflow.com/questions/59895/how-to-get-the-source-directory-of-a-bash-script-from-within-the-script-itself
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
@wrouesnel
wrouesnel / exclusive_mode_switcher.go
Created March 11, 2020 03:23
Generic interface for greedily switching amongst arbitrary numbers of exclusive modes.
// ExclusiveModeSwitcher implements a generic interface for having an arbitrary number of exclusive modes
// that should only be activated in exclusion to other modes. The specific assumption is that multiple users
// of the same mode should be executed greedily until enough users finish.
type ExclusiveModeSwitcher struct {
cond *sync.Cond
users map[string]uint
}
// NewExclusiveModeSwitcher constructs a new mode switcher backend.
func NewExclusiveModeSwitcher() *ExclusiveModeSwitcher {
@wrouesnel
wrouesnel / mode_switcher.go
Created March 11, 2020 03:03
Building a struct which mode switches
// test application for how to switch modes
package main
import (
"fmt"
"sync"
"time"
)
type ReadMode interface {