Skip to content

Instantly share code, notes, and snippets.

Avatar
😞

Keith Gaughan kgaughan

😞
View GitHub Profile
@kgaughan
kgaughan / vaultdecrypt.py
Created May 3, 2022
Decrypting ansible-vault files without ansible-vault
View vaultdecrypt.py
import binascii
import sys
import typing
from cryptography.hazmat.primitives import ciphers, hashes, hmac, padding
from cryptography.hazmat.primitives.ciphers import algorithms
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
def vault_parse(lines: typing.List[str]) -> typing.Tuple[bytes, bytes, bytes]:
@kgaughan
kgaughan / permute.go
Created Dec 8, 2021
Permuting a string in Go
View permute.go
package permute
func fact(n int) int {
result := 1
for i := 1; i <= n; i++ {
result *= i
}
return result
}
@kgaughan
kgaughan / index.html
Created Jun 6, 2021
YouTube embedded player façade
View index.html
<!DOCTYPE html>
<html>
<head>
<style>
.facade, .player {
margin: 0 auto;
display: block;
}
.facade {
position: relative;
@kgaughan
kgaughan / luminance.py
Created Apr 17, 2021
Python function to modify luninance of a colouur
View luminance.py
def modify_luminance(colour, lum=0):
rgb = 0
for i in range(0, len(colour), 2):
component = int(colour[i : i + 2], 16)
modified = round(min(max(0, component + (component * lum)), 255))
rgb = rgb * 256 + modified
return f"{rgb:0>6X}"
View talideon-wallpaper.py
#!/usr/bin/env python3
#
# talideon-wallpaper
# by Keith Gaughan <http://talideon.com/>
#
# A pipemenu script for Openbox for selecting and setting the current
# wallpaper.
#
# Copyright (c) Keith Gaughan, 2008.
# All Rights Reserved.
@kgaughan
kgaughan / acme-domain-renew.sh
Created Sep 11, 2019
Wrapper around acme-tiny for automation
View acme-domain-renew.sh
#!/bin/sh -e
while getopts hc:w:t: name; do
case $name in
c)
config_dir="$OPTARG"
;;
w)
challenge_dir="$OPTARG"
;;
@kgaughan
kgaughan / chan.go
Created Aug 4, 2019
Iteration benchmark
View chan.go
package iteration
func fiboChan(n int) <-chan int {
c := make(chan int)
go func() {
a := 0
b := 1
for i := 0; i < n; i++ {
a, b = b, a+b
View gist:1c3e694130210ed8247258dad0409783
For want of a nail the shoe was lost.
For want of a shoe the horse was lost.
For want of a horse the rider was lost.
For want of a rider the message was lost.
For want of a message the battle was lost.
For want of a battle the kingdom was lost.
And all for the want of a horseshoe nail.
@kgaughan
kgaughan / selfmutex.py
Created Mar 8, 2019
Using a python script as its own mutex to prevent it executing concurrently with multiple instances of itself
View selfmutex.py
#!/usr/bin/env python3
import contextlib
import fcntl
import sys
import time
class MutexException(Exception):
"""
View dyck.py
#!/usr/bin/env python3
def is_dyck_word(word):
i = 0
for ch in word:
if ch == '[':
i += 1
elif ch == ']':
i -= 1