Skip to content

Instantly share code, notes, and snippets.

Avatar

Will Rouesnel wrouesnel

View GitHub Profile
@wrouesnel
wrouesnel / main.py
Last active May 23, 2021
Python argparse with config file fallback. This is great for scripting up daemon-like tools (note PyDev template syntax - replace as needed)
View main.py
#!/usr/bin/env python
# encoding: utf-8
'''
${module}
'''
import sys
import os
from os import path
@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 `
@wrouesnel
wrouesnel / .remote-backup-excludes.txt
Last active Jan 22, 2021
A script for performing a remote backup to another server using rsync and bup for versioning.
View .remote-backup-excludes.txt
# this is an rsync-excludes format list of files to exclude.
@wrouesnel
wrouesnel / ansible-vm-base-image.yml
Created Jan 29, 2016
Ansible VM base image builder
View ansible-vm-base-image.yml
---
# Provisions a Debian base-image
- hosts: local
connection: local
force_handlers: True
sudo: yes
tasks:
# - name: Check environment set
# fail: msg="Configuration incompletely specified!"
# when: (server_ip is defined|bool and netmask is defined|bool and gateway is defined|ipaddr and
@wrouesnel
wrouesnel / gist:6240468b75c6d72053ed
Created Mar 15, 2016
Updating system SSL and java keystore in a docker build
View gist:6240468b75c6d72053ed
# Compile and install certificates for the Java trust keystore
# and main keystore. Let's face it, this is everyone's keystore password.
# Note I install java very flatly normally.
COPY trust-certs/ /usr/local/share/ca-certificates/
RUN update-ca-certificates && \
ls -1 /usr/local/share/ca-certificates | while read cert; do \
openssl x509 -outform der -in /usr/local/share/ca-certificates/$cert -out $cert.der; \
/java/bin/keytool -import -alias $cert -keystore /java/jre/lib/security/cacerts -trustcacerts -file $cert.der -storepass changeit -noprompt; \
rm $cert.der; \
done
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 / gist:4517f5088a2ac84db5dd6a40191610e2
Last active Jul 17, 2020
Easy bash "atexit" shutdown hooks.
View gist:4517f5088a2ac84db5dd6a40191610e2
#!/bin/bash
shutdown_hooks=()
function atexit() {
val=$(echo "$@")
shutdown_hooks+=("$val")
}
trap "shutdown" INT TERM
@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 )"