Skip to content

Instantly share code, notes, and snippets.

@wrouesnel
wrouesnel / cliptype
Created Apr 22, 2021
Autotype clipboard contents
View cliptype
#!/bin/bash
xclip -selection clipboard -out | xdotool selectwindow windowfocus type --clearmodifiers --delay 25 --window %@ --file -
View csharp_from_db.sql
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 Feb 13, 2021
Powershell script to make a bunch of initial windows annoyances changes
View windows_ux_annoyances.ps1
# 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 `
View gpg.conf
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 Jul 6, 2020
Get the current script directory for a bash shell script.
View bash-get-current-script-dir.sh
# 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
Implementation of determining ZFS stream type before receiving.
View zfs_recieve_stream.go
package main
import (
"bytes"
"errors"
"fmt"
"io"
"os"
"os/exec"
"os/signal"
@wrouesnel
wrouesnel / gist:0ddb530bf661c43056ff72a9bb95ba76
Created Mar 23, 2020
How to get the source directory of a Bash script from within the script itself (so I can stop looking up SO)
View gist:0ddb530bf661c43056ff72a9bb95ba76
#!/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 Mar 11, 2020
Generic interface for greedily switching amongst arbitrary numbers of exclusive modes.
View exclusive_mode_switcher.go
// 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 Mar 11, 2020
Building a struct which mode switches
View mode_switcher.go
// test application for how to switch modes
package main
import (
"fmt"
"sync"
"time"
)
type ReadMode interface {
View gist:e3078ac992c5dfe74eb2e79397cc134e
// Randomly corrupts a file by writing a minimum amount of zeros.
package main
import (
"fmt"
"math/rand"
"os"
"time"
"gopkg.in/alecthomas/kingpin.v2"