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 / 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 / Shlex.js
Last active June 5, 2024 03:17
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 / 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 / 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 / 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"]) {