Skip to content

Instantly share code, notes, and snippets.

@th0ma5w
th0ma5w / readBack.py
Created December 19, 2010 20:35
print the last x lines from your interpreter (default 50)
import readline
def readBack(length=50):
history_items=range(readline.get_current_history_length()+1)
this_readback=history_items[-length:]
for line in this_readback:
print readline.get_history_item(line)
@th0ma5w
th0ma5w / horoscopescrape.py
Created January 12, 2011 14:38
Example of Generating URLs for downloading
"""
Creates a list of URLs to stdout based on repeating patterns found in the site, suitable for use with WGET or CURL.
"""
import datetime
scopes=[
"aries",
"taurus",
@th0ma5w
th0ma5w / extract_horoscope.py
Created January 12, 2011 14:41
extract context from downloaded html files
"""
Example of using the old BeautifulSoup API to extract content from downloaded html files into CSV... if you're doing this sort of thing today, I recommend using the newer lxml interface directly, but lxml also has a BeautifulSoup compatibility layer.
"""
import os
@th0ma5w
th0ma5w / alarm.py
Created March 1, 2011 03:29
play a sound when there's a tornado warning near me
#!/usr/bin/python
# WARNING: If you want to use it, don't rely on it, and you'd have to edit it to get to work for you, wherever you are, if you're in the US.
from lxml import etree
from urllib2 import urlopen
from subprocess import Popen, PIPE
COUNTY="franklin"
#COUNTY="union"
@th0ma5w
th0ma5w / directory.scm
Created May 22, 2011 15:10
Python-like dir function for scheme
;Python-like dir function for Kawa scheme objects (but not the global namespace)
(require 'list-lib)
(require <kawa.lib.srfi95>)
;retrieve class name as string
(define classname (lambda (x) (invoke x 'getName)))
;make a one-dimensional array into a list
(define tolist (lambda (l) (map l (iota l:length))))
@th0ma5w
th0ma5w / gist:1297161
Created October 19, 2011 00:28
dim blue-green (traffic light mix) color filter for compiz
!!ARBfp1.0
TEMP tex, temp;
TEX tex, fragment.texcoord[0], texture[0], RECT;
DP3 temp.r, tex, {0.01, 0.01, 0.01, 0};
DP3 temp.g, tex, {0.05, 0.05, 0.05, 0};
DP3 temp.b, tex, {0.04, 0.04, 0.04, 0};
MOV temp.a, tex.a;
MOV result.color, temp;
END
@th0ma5w
th0ma5w / xbmcyoutube.sh
Created April 7, 2012 16:50
Play YouTube on LAN XBMC Eden
#!/bin/bash
curl -d "{\"jsonrpc\": \"2.0\", \"method\": \"Player.Open\", \"params\":{\"item\": { \"file\" : \"plugin://plugin.video.youtube/?action=play_video&videoid=$@\" }}, \"id\" : 1}" http://xbmc:[email protected]:8080/jsonrpc
# curl and everything after it should be on one line. change the port and host to your
# liking and your username and password if you've changed it from the default
@th0ma5w
th0ma5w / curve.clj
Created November 7, 2012 22:57
Bezier Curve Subdivision Functions
(defn edges [listing]
(loop [accum (list (take 2 listing))
queue (rest listing)]
(if (> (count queue) 1)
(recur
(concat accum
(list (take 2 queue)))
(rest queue))
accum)))
@th0ma5w
th0ma5w / gist:8327127
Created January 9, 2014 00:07
JSON parsing script for BitCoin prices within Google Docs
// Adds a menu option to refresh all options.
function onOpen() {
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var entries = [{
name : "Refresh",
functionName : "refreshLastUpdate"
}];
sheet.addMenu("Refresh", entries);
};
@th0ma5w
th0ma5w / multimon-ng-filter.py
Created January 25, 2014 20:21
A way that I got working of scripting the output of multimon-ng ... not sure why the pipes are weird, but things like tee or grep seem prevent multimon-ng from producing output.
import subprocess, sys
from datetime import datetime
from time import sleep
timestamp = lambda : datetime.now().isoformat()
# # pager_rtl.sh --
# rtl_fm -M fm -f 152.48M -r22050 -s88200 -g 42 -l 30
rtl_fm = subprocess.Popen("./pager_rtl.sh",