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 / 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*
@Terrance
Terrance / DB.php
Created September 30, 2014 15:11
A simplified PHP wrapper for accessing a MySQL database, including debugging using Debug.php.
<?
include "Debug.php";
class DB {
private static $conn = null;
private static $prefix = "";
public static function connect($host="localhost", $user="root", $pass=null, $db=null) {
DB::$conn = mysqli_connect($host, $user, $pass, $db);
}
public static function setPrefix($newPrefix="") {
DB::$prefix = ($newPrefix ? $newPrefix : "");
@Terrance
Terrance / Debug.php
Created September 30, 2014 14:12
A lightweight PHP include to post and view debugging messages for a session. Call `Debug::start()` then `Debug::post("message", [0-3])`. View output by appending `?d` to the URL.
<?
class Debug {
const log = 0;
const success = 1;
const warning = 2;
const error = 3;
private static $init = false;
public static function start() {
session_start();
if (!$_SESSION["debug"]) {
@Terrance
Terrance / cert.sh
Last active September 22, 2017 19:58
A bash script to ease (re)generation of OpenSSL certificates.
#!/usr/bin/env sh
NEWROOT=0
GENROOTKEY=0
NEWCERT=0
GENCERTKEY=0
DAYS=3653
PFX=0
MERGE=0