Skip to content

Instantly share code, notes, and snippets.

@timhughes
timhughes / bash_assertion.sh
Created September 4, 2019 09:53
simple colored bash assertions
cecho(){
RED="\033[0;31m"
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
printf "${!1}${2} ${NC}\n"
}
assert_fail(){
@timhughes
timhughes / argparse_example.py
Created September 4, 2019 09:47
Argparse Example
import argparse
import logging
class Foo():
def __init__(self):
self.args = None
def run(self, args):
self.args = args
@timhughes
timhughes / server.py
Last active August 7, 2019 22:22
Threadding/Multiprocessing Python Server starting point
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2019 Tim Hughes <[email protected]>
#
# Distributed under terms of the MIT license.
"""
This is an example python server than can use either
@timhughes
timhughes / gnome-emoji-hotkey-disable.sh
Created April 18, 2019 21:34
Disable the emoji hotkey in Gnome 3
thughes@krypton [0] $ gsettings get org.freedesktop.ibus.panel.emoji hotkey
['<Control><Shift>e']
thughes@krypton [0] $ gsettings set org.freedesktop.ibus.panel.emoji hotkey []
thughes@krypton [0] $ gsettings get org.freedesktop.ibus.panel.emoji hotkey
@as []
@timhughes
timhughes / timezone.py
Created April 11, 2019 13:27
minimal UTC Timezone for python
from datetime import datetime, timedelta, tzinfo
class UTC(tzinfo):
def utcoffset(self, dt): return timedelta(0)
def dst(self, dt): return timedelta(0)
def tzname(self, dt): return 'UTC'
@timhughes
timhughes / Ick.java
Created September 10, 2018 15:24 — forked from phlash/Ick.java
Self-executing single-file Java programs...
#!/bin/sh
# This self-executing Java program uses the following /embedded shell script/ to compile & execute itself..
# magic constant holding length of script
SKIP=26
# parse our name..
FILE=`basename $0 .java`
# get some working space, clean up old crud
#!/bin/bash
# SPDX-License-Identifier: MIT
## Copyright (C) 2009 Przemyslaw Pawelczyk <[email protected]>
##
## This script is licensed under the terms of the MIT license.
## https://opensource.org/licenses/MIT
#
# Lockable script boilerplate
@timhughes
timhughes / build_wachman_rpm.sh
Last active May 30, 2018 10:09
Build a rpm for watchman on Fedora 28
#! /bin/sh
#
# build_wachman_rpm.sh
# Copyright (C) 2018 Tim Hughes <[email protected]>
#
# Distributed under terms of the MIT license.
#
# Uses FPM to create a rpm for easy installation and removal
VERSION='v4.9.0'
@timhughes
timhughes / OpenWRT_GandiDNS.sh
Created May 6, 2018 22:54
OpenWRT LetsEncrypt Script using dns_gandi_livedns
export FQDN=foo.int.example.com
export GANDI_LIVEDNS_KEY="xxxxxxxxxxxxxxxx"
curl https://raw.githubusercontent.com/Neilpang/acme.sh/master/acme.sh > acme.sh
chmod a+x "acme.sh"
./acme.sh --install
wget https://raw.githubusercontent.com/Neilpang/acme.sh/master/dnsapi/dns_gandi_livedns.sh -O /root/.acme.sh/dns_gandi_livedns.sh
@timhughes
timhughes / gist:b40dbd4197b67fcdbc24af903f271e75
Created April 5, 2018 15:01 — forked from cdown/gist:1163649
Bash urlencode and urldecode
urlencode() {
# urlencode <string>
old_lc_collate=$LC_COLLATE
LC_COLLATE=C
local length="${#1}"
for (( i = 0; i < length; i++ )); do
local c="${1:i:1}"
case $c in
[a-zA-Z0-9.~_-]) printf "$c" ;;