Skip to content

Instantly share code, notes, and snippets.

View Terrance's full-sized avatar
🚒
​The world is quiet here.

Terrance Terrance

🚒
​The world is quiet here.
View GitHub Profile
@Terrance
Terrance / CygwinSetup.py
Created June 8, 2016 18:55
A wrapper script for Cygwin's setup.exe, with argparse-based command line handling.
#!/usr/bin/env python
from argparse import ArgumentParser
from itertools import chain
import os
import subprocess
try:
import urllib.request as urllib
except ImportError:
import urllib
@Terrance
Terrance / AjaxQueue.js
Created April 10, 2016 14:37
Limit concurrent jQuery ajax requests to at most 3 at a time, and queue the rest.
var ajaxReqs = 0;
var ajaxQueue = [];
var ajaxActive = 0;
var ajaxMaxConc = 3;
function addAjax(obj) {
ajaxReqs++;
var oldSuccess = obj.success;
var oldError = obj.error;
var callback = function() {
ajaxReqs--;
@Terrance
Terrance / SMModMgr.lua
Last active February 26, 2016 21:16
A Lua library that simplifies scripting custom mods within a song. SM allows stepped songs (in addition to themes) to make use of additional logic programmed in Lua -- the API provides full access to notes, mods and timing.
function val2key(vals)
keys = {}
for i, key in ipairs(vals) do keys[key] = true end
return keys
end
local modmgr = {}
modmgr.__index = modmgr
setmetatable(modmgr, {
@Terrance
Terrance / IngressAlertParser.md
Created February 12, 2016 18:47
A script for processing data from Ingress attack notification emails.

Requirements

  • phpQuery
  • Medoo

NB: db.php is just a wrapper for Medoo that reads $dbPath and returns a corresponding Medoo instance.

Database schema

@Terrance
Terrance / CardViewer.py
Created November 18, 2015 21:53
An Anki plugin to preview cards in the browser. Old and probably broken; uploaded here for completeness.
# Card Viewer 1.3: a small plugin to show cards without reviewing.
# This plugin will export cards to HTML, and open them in your browser.
# Select a card, then go to Edit > View Card, select View from the toolbar, or press Ctrl+Return.
from aqt.browser import BrowserToolbar
from aqt import mw
from aqt.qt import *
from aqt.utils import shortcut, showInfo
from anki.find import fieldNames
@Terrance
Terrance / CacheResult.py
Created October 21, 2015 21:03
A Python decorator for caching a function result on first call (e.g. for network requests). Works well with the property decorator.
from functools import wraps
from inspect import getargspec
def cacheResult(fn):
cacheAttr = "{0}Cache".format(fn.__name__)
argSpec = getargspec(fn)
argNames = argSpec.args[1:]
if len(argNames) > 1:
raise RuntimeError("can't cache results if function takes multiple args")
argName = argNames[0] if len(argNames) else None
@Terrance
Terrance / keystore.php
Last active September 16, 2015 21:30
An importable script to hold sensitive information not to be committed in other files. Provides string value lookup with keys, or categorised sub-keys.
<?php
/*
The keystore is a map from keys to values, but nested arrays allow sub-key organisation.
This means an array cannot be retrieved as a value, only its (scalar) contents.
*/
$keystore = array(
"key" => "valueA",
"group" => array(
"subkey1" => 42,
"subkey2" => true
@Terrance
Terrance / ActLogBulkPrivacyMod.js
Created July 1, 2015 22:09
A snippet for bulk converting Facebook privacy modes on all currently visible posts in Activity Log.
// Mode to find, and mode to switch to, as shown in the privacy dropdown.
var from = "Public", to = "Friends";
// Gather all posts on the old mode.
var posts = $$('a[aria-label="' + from + '"]');
// Assuming running from the console, copy the $$ selector method.
window.$$_ = $$;
// Facebook overrides setTimeout, so need to obtain one from elsewhere.
// Don't destroy the frame, otherwise it'll stop working.
var f = document.createElement("iframe");
f.style.display = "none";
@Terrance
Terrance / GooglePlayTesting.user.js
Created May 24, 2015 13:09
A userscript to set the current Google account (according to `?authuser=`) when joining and leaving tests.
// ==UserScript==
// @name Google Play Testing per-account
// @namespace http://terrance.uk.to
// @version 0.1
// @description Makes the "Become a Tester" button respect the current auth user.
// @author Ollie Terrance
// @match https://play.google.com/apps/testing/*
// @grant none
// ==/UserScript==
@Terrance
Terrance / PortalListExporter.user.js
Last active August 21, 2023 14:29
An IITC plugin for generating CSV lists of portals (either all visible, or just enemy ones).
// ==UserScript==
// @id iitc-plugin-listexport@OllieTerrance
// @name IITC plugin: Portal List Exporter
// @category Info
// @version 0.0.0.1
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion
// @description Exports a CSV list of all or enemy portals.
// @include https://www.ingress.com/intel*
// @include http://www.ingress.com/intel*
// @match https://www.ingress.com/intel*