Skip to content

Instantly share code, notes, and snippets.

View pgaskin's full-sized avatar
💭
busy for a week or two

Patrick Gaskin pgaskin

💭
busy for a week or two
View GitHub Profile
@pgaskin
pgaskin / jessie-base.preseed
Last active March 23, 2024 15:39
A preseed file for a minimal Debian Jessie installation
# How to run
# In the folder with these files
# sudo python -m SimpleHTTPServer 80
#
# Update the ip at the bottom of this file to the output of
# hostname -I
# This is your ip
#
# Start debian cd
# Press esc on menu
@pgaskin
pgaskin / PrintRevealNotes.js
Last active May 3, 2024 21:23
Prints speaker notes for a reveal.js presentation.
/*
Prints speaker notes for a reveal.js presentation.
To print the notes, run the js function PrintRevealNotes()
You need to disable the pop-up blocker
Copyright 2016 Patrick G
http://geek1011.github.io
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
@pgaskin
pgaskin / termux-themer.sh
Last active December 30, 2020 08:36
Apply color schemes to the termux app from the command line.
#!/bin/sh
function jsonValue() {
KEY=$1
num=$2
awk -F"[,:}]" '{for(i=1;i<=NF;i++){if($i~/'$KEY'\042/){print $(i+1)}}}' | tr -d '"' | sed -n ${num}p
}
if [ $# -eq 0 ]; then
echo Usage: $0 theme-name
echo
@pgaskin
pgaskin / swiper.js
Last active March 6, 2018 16:11
A simple way to detect swipes in JS.
function Swiper(el, left, right, up, down) {
var xD = null,
yD = null;
el.addEventListener("touchstart", function(ev) {
xD = ev.touches[0].clientX;
yD = ev.touches[0].clientY;
}, false);
el.addEventListener("touchmove", function(ev) {
if (!xD || !yD) return;
var xU = ev.touches[0].clientX,
@pgaskin
pgaskin / process-legacy-html-color.js
Created August 30, 2017 16:11
Parses a legacy html color
// processColor processes a legacy html color
// The legacy html colors apply only to colors in the bgcolor attribute
//
// Copyright 2017 Patrick G
// Based on http://scrappy-do.blogspot.ca/2004/08/little-rant-about-microsoft-internet.html
// Also see https://stackoverflow.com/questions/8318911/why-does-html-think-chucknorris-is-a-color
function processColor(color) {
// Remove the hash
color = color.replace("#", "");
@pgaskin
pgaskin / swiper2.js
Last active May 13, 2018 01:01
Accurate and simple way to detect swipes in vanilla js.
let start = null
let end = null;
const el = document.body;
el.addEventListener('touchstart', event => start = event.changedTouches[0], false);
el.addEventListener('touchend', event => {
end = event.changedTouches[0];
let hr = (end.screenX - start.screenX) / el.getBoundingClientRect().width;
let vr = (end.screenY - start.screenY) / el.getBoundingClientRect().height;
@pgaskin
pgaskin / IRV.py
Last active June 25, 2018 01:50
Instant-runoff voting
#!/usr/bin/env python3
ballots = list(map(list, input("ballots: ").lower().replace(" ", "").split(",")))
candidates = list(set([candidate for ballot in ballots for candidate in ballot]))
winner, last_ballots = None, ballots
while winner == None:
ballots = [b for b in ballots if len(b) > 0]
fcs = [b[0] for b in ballots]
fc_counts = {c: fcs.count(c) for c in candidates}
@pgaskin
pgaskin / selfcert-server.go
Created June 25, 2018 01:55
Generates self-signed certificates on-the-fly.
package main
import (
"bytes"
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"crypto/tls"
"crypto/x509"
"crypto/x509/pkix"
@pgaskin
pgaskin / termux-sms-backup.sh
Created September 2, 2018 14:12
Backs up all SMS messages using Termux.
#!/bin/bash
echo "Termux SMS Backup"
echo "Copyright 2018 Patrick Gaskin"
hash termux-sms-list ||
pkg install termux-api &&
hash jq ||
pkg install jq &&
termux-setup-storage &&
termux-sms-list -l 999999 -t all |
jq 'group_by(.threadid) |
package main
import (
"archive/zip"
"crypto/sha1"
"fmt"
"os"
)
func main() {