Skip to content

Instantly share code, notes, and snippets.

View wolph's full-sized avatar

Rick van Hattem wolph

View GitHub Profile
@wolph
wolph / replace.zsh
Created September 23, 2015 10:18
Regular expression (Perl pie) to search and replace Django STATIC_URL with the static (from staticfiles) templatetag
perl -pi -e 's/"\{\{\s*STATIC_URL\s*\}\}\/?([^"]+)"/"{% static \x27$1\x27 %}"/g' templates/***/*.html
@wolph
wolph / eventghost_domoticz.py
Created September 13, 2015 17:47
Example script to access domoticz from eventghost, I'll make this in a plugin somewhere in the future :)
LIGHT_ID = 123
LIGHT_LEVEL = 40
DOMOTICZ_URL = 'http://domoticz/json.htm?'
def fetch(**kwargs):
import json
import urllib
params = urllib.urlencode(kwargs.items())
url = DOMOTICZ_URL + params
@wolph
wolph / quicksort_y_combinator_lambda_calculus.py
Created August 19, 2015 11:44
Quicksort using the Y Combinator (lambda calculus) in pure Python
# Quicksort using the Y Combinator (lambda calculus) in pure Python
>>> Y = lambda f: lambda *args: f(Y(f))(*args)
>>> quicksort = Y(lambda f:
... lambda x: (
... f([item for item in x if item < x[0]])
... + [y for y in x if x[0] == y]
... + f([item for item in x if item > x[0]])
... ) if x else [])
@wolph
wolph / computer_futures_worksheets.user.js
Last active July 19, 2016 09:23
Due to either incompetence or unwillingness of computer futures it seems impossible to add worksheet hours in a normal way, this script makes it easier by making the hours pasteable. Just paste them as 1 line per day and start time + end time split by space. Note, it only supports 1 start/stop time per day currently.
// ==UserScript==
// @name Computer Futures Worksheet Filler
// @namespace http://wol.ph/
// @version 1.1
// @description
// @match https://worksheets.computerfutures.com/index.php?dir=timesheet*
// @match http://worksheets.computerfutures.com/index.php?dir=timesheet*
// @copyright 2015, Wolph
// @run-at document-end
// ==/UserScript==
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.IO.MemoryMappedFiles;
using System.Threading.Tasks;
using System.Net.Sockets;
using System.Threading;
using System.Runtime.InteropServices;
@wolph
wolph / assign_to_me.user.js
Created April 15, 2015 13:29
Assign bug to me in Bugzilla
// ==UserScript==
// @name Assign to me (Bugzilla)
// @namespace http://wol.ph/
// @version 1.0
// @description
// @match http://bugzilla.3xo.eu/show_bug.cgi?id=*
// @copyright 2015, Wolph
// ==/UserScript==
var assigned_to_field = document.getElementsByName('assigned_to')[0];
@wolph
wolph / play_external.user.js
Created April 15, 2015 11:01
Userscript to play files in external media player
// ==UserScript==
// @name Play in external player
// @namespace http://wol.ph/
// @version 1.0
// @grant GM_getValue
// @grant GM_openInTab
// @grant GM_registerMenuCommand
// @grant GM_setValue
// @include http://*
// @include https://*
@wolph
wolph / math_with_sticks_solver.py
Last active August 29, 2015 14:18
Solver for "math with sticks" puzzles
import re
sticks = {
0: 6,
1: 2,
2: 5,
3: 5,
4: 4,
5: 5,
6: 6,
@wolph
wolph / whitelist_ssl_certificates_chrome.sh
Last active August 25, 2020 19:21
Easily whitelisting SSL certificates in Chrome under OS X
#!/usr/bin/env bash -e
HOST=$(echo "$1" | sed -E -e 's/https?:\/\///' -e 's/\/.*//')
if [[ "$HOST" =~ .*\..* ]]; then
echo "Adding certificate for $HOST"
echo -n | openssl s_client -connect $HOST:443 -servername $HOST \
| sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' \
| tee "/tmp/$HOST.cert"
sudo security add-trusted-cert -d -r trustRoot \
#!/bin/sh
exec <"$0" || exit; read v; read v; exec /usr/bin/osascript - "$@"; exit
-- the above is some shell trickery that lets us write the rest of
-- the file in plain applescript
-- Usage:
-- For a simple reload and nothing else:
-- # sh reload_chrome.sh
-- For a reload with activating a different app after (iTerm in this case):
-- # sh reload_chrome.sh iTerm