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 / Debug.php
Created April 1, 2013 11:36
PHP debugging class. Include and call post() to log an entry. View the page with ?d to display all entries.
<?
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 / SQLDB.php
Created April 1, 2013 11:40
Wrapper class for SQL database connections. Helper methods for fetching, adding, editing and deleting data.
<?
class DB {
private static $conn = null;
public static function connect($host="localhost", $user="root", $pass=null, $db=null) {
DB::$conn = mysqli_connect($host, $user, $pass, $db);
}
public static function insert($table, $data) {
if (!DB::$conn) {
DB::connect();
}
@Terrance
Terrance / DoXInstall.py
Last active December 19, 2015 12:58
A script to download DoXCmd (http://github.com/OllieTerrance/DoXCmd) and DoXTray (http://github.com/OllieTerrance/DoXTray) to the current directory, including the DoX API (http://github.com/OllieTerrance/DoX). Can also be re-run to update to newer versions. Once run, you can use DoXCmd by running DoXCmd/cmd.py from a terminal. DoXTray can be lau…
try:
import os, shutil, zipfile
except ImportError as e:
print("")
print("Error: installation module not available:")
print("{}.".format(e))
print("")
quit()
try:
@Terrance
Terrance / Shlex.js
Last active March 15, 2024 06:28
A function for parsing shell-like quoted arguments into an array, similar to Python's shlex.split. Also allows quotes mid-way through a string, and parses them out for you. Returns false on failure (from unbalanced quotes).
function shlex(str) {
var args = str.split(" ");
var out = [];
var lookForClose = -1;
var quoteOpen = false;
for (var x in args) {
if (args.hasOwnProperty(x)) {
var arg = args[x];
var escSeq = false;
for (var y in arg) {
@Terrance
Terrance / SteamMarket.py
Created September 15, 2013 14:08
A small shell for checking Steam Market prices. Commands are `watch <url>` (add item to watch), `clear` (remove all watches), `get` (get prices), `quit`.
import json, re, shlex, urllib.request
watch = []
def getPrice(item):
listings = json.loads(urllib.request.urlopen(makeUrl(item)).read().decode("utf-8"))["listinginfo"]
lowest = None
for id, obj in list(listings.items()):
try:
price = obj["converted_price"]
@Terrance
Terrance / DateTimeView.java
Created September 28, 2013 10:17
An Android class that converts a text field and two buttons into a custom date/time picker field with set and clear buttons.
import java.util.Calendar;
import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.content.Context;
import android.view.View;
import android.widget.DatePicker;
import android.widget.TextView;
import android.widget.TimePicker;
@Terrance
Terrance / IngressDualMap.user.js
Last active March 27, 2023 10:33
An IITC plugin that exports portals currently in view as a CSV list for use with Ingress Dual Map.
// ==UserScript==
// @id iitc-plugin-ingressdualmap-exporter@OllieTerrance
// @name IITC plugin: Ingress Dual Map Exporter
// @category Keys
// @version 0.0.0.1
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion
// @description Exports portals currently in view as a CSV list for use with Ingress Dual Map.
// @include https://www.ingress.com/intel*
// @include http://www.ingress.com/intel*
// @match https://www.ingress.com/intel*
@Terrance
Terrance / ActLogPubLikes.js
Last active January 24, 2016 09:07
A JavaScript snippet for removing likes on public statuses on Facebook. Operates on the mobile site (https://m.facebook.com/<you>/allactivity?log_filter=likes) by searching for lines with a "Public" tag. You need to expand times to search first.
// for all public tags
$(".sx_c87e68").each(function(i, e) {
// navigate up to the root of the item
var r = $(e).parent().parent().parent().parent().parent().next();
var id = r.parent().attr("id");
// open the dropdown
r.find("i").click();
// find the corresponding menu
$(".accelerate").find("a").each(function(j, l) {
if ($(l).data("store").domID == id) {
@Terrance
Terrance / Wikipedia.css
Created May 21, 2014 15:38
CSS for Wikipedia (usable in e.g. Stylish) to hide the top and side bars in a thinner viewport, thus making more room for the actual article.
@media (max-width: 768px) {
div#content {
margin-left: 0;
border: none;
}
#mw-page-base, #mw-head-base, #mw-head, #mw-panel {
display: none;
}
}
@Terrance
Terrance / SteamMarketBuyNow.js
Created June 21, 2014 10:18
A snippet (using Prototype.js as available on the page) to instantly buy the top item in a Steam market listing. Can be used as a bookmarket.
$$(".item_market_action_button.item_market_action_button_green")[0].click();
$$("#market_buynow_dialog_accept_ssa")[0].checked = true;
$$("#market_buynow_dialog_purchase")[0].click();