Skip to content

Instantly share code, notes, and snippets.

View stuartlangridge's full-sized avatar

Stuart Langridge stuartlangridge

View GitHub Profile
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Pure CSS toggle switch</title>
<style>
body {
font-size: 2em;
}
input { position: absolute; opacity: 0 }
@stuartlangridge
stuartlangridge / gist:5799474
Created June 17, 2013 19:14
Initial cut of Ubuntu webapps script for Discourse. To be called in discourse/app/views/common/_discourse_javascript.html.erb, after Discourse.start().
// ==UserScript==
// @author Stuart Langridge <sil@kryogenix.org>
// ==/UserScript==
if (external.getUnityObject) {
window.Unity = external.getUnityObject(1.0);
// use the Apple touch icon as icon
var icnsize=0, icnurl;
Array.prototype.slice.call(document.querySelectorAll("link[rel='apple-touch-icon']")).forEach(function(icn) {
@stuartlangridge
stuartlangridge / TypeFileOut.py
Created January 9, 2014 16:11
Sublime Text 2 Python plugin to "type" the file that's currently being edited, character by character, for screencasts.
import sublime, sublime_plugin
BLOCKLEN = 4
class TypeFileOutCommand(sublime_plugin.TextCommand):
def nextchar(self):
if self.body:
totype = []
while 1:
try:
@stuartlangridge
stuartlangridge / Dalekfile.json
Created January 28, 2014 11:42
Dalekfile.json showing how to make dalekjs start Chrome in incognito mode
{
"browsers": [{
"chrome": {
"chromeOptions": { "args": ["--incognito"] }
}
}]
}
@stuartlangridge
stuartlangridge / gist:4d66733dde499a49203b
Created June 11, 2014 23:06
Multiple async tests against multiple objects with any JS test runner.
"use strict";
/*global process, console */
function Thingy() {}
Thingy.prototype.returns5 = function(cb) { process.nextTick(function() { cb(null, 5); }); };
Thingy.prototype.returns8 = function(cb) { process.nextTick(function() { cb(null, 8); }); };
var thingy1 = new Thingy(),
thingy2 = new Thingy(),
@stuartlangridge
stuartlangridge / pelican-webmentions.py
Created November 29, 2014 17:24
Pelican plugin for webmentions. This will not work out of the box for you; it's too kryogenix.org-specific. But it may help.
from pelican import signals
import json, urllib, urlparse, datetime, html5lib, os, codecs
LIVESITEURL = ""
WM_CACHE_PATH = None
WM_CACHE = {
"domains": {},
"pinged": {}
}
Verifying I am +sil on my passcard. https://onename.com/sil
@stuartlangridge
stuartlangridge / icloud-cal.php
Created January 26, 2016 22:49
PHP to fetch a calendar from iCloud with authentication and CalDAV
<?php
// get this data by logging into icloud.com on the calendars page and looking at the dev tools
// as per https://translate.google.com/translate?sl=de&tl=en&js=y&prev=_t&hl=de&ie=UTF-8&u=http%3A%2F%2Fnico-beuermann.de%2Fblogging%2Farchives%2F115-Zugriff-auf-iCloud-Kalender-mit-Thunderbird.html&edit-text=&act=url
$account = array(
'server' => '', // note, this will be p12 or something, not P0; see the server that iclod.com serves json from
'icloudid' => '', // the "dsid"
'appleid' => '', // your Apple ID; will be an email address
'pass' => '', // password for your Apple ID
'calid' => '' // the "pGuid"
@stuartlangridge
stuartlangridge / deredact.py
Created March 12, 2016 21:58
Deredact stuff in the "redact" font
import sys
# call as
# python deredact.py "$(python redact.py hello world)"
instr = " ".join(sys.argv[1:]).replace(".", "").replace(",", "")
fp = open("/usr/share/dict/words")
words = [x.lower() for x in fp.read().split("\n")]
fp.close()
@stuartlangridge
stuartlangridge / Wallpaperify
Created March 29, 2016 22:41
Simple Nautilus wallpaperify script, as per https://plus.google.com/u/0/+joeysneddon/posts/a3i2L9dyESp. (Save as $HOME/.local/share/nautilus/scripts/Wallpaperify.)
#!/bin/bash
file --brief --mime-type "$1" | grep "^image/"
if [ $? != 0 ]; then
zenity --error --text="'$1' does not seem to be an image file."
exit 1
fi
if ! hash convert 2>/dev/null; then