Skip to content

Instantly share code, notes, and snippets.

@th0ma5w
th0ma5w / readBack.py
Created Dec 19, 2010
print the last x lines from your interpreter (default 50)
View readBack.py
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 Jan 12, 2011
Example of Generating URLs for downloading
View horoscopescrape.py
"""
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 Jan 12, 2011
extract context from downloaded html files
View extract_horoscope.py
"""
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 Mar 1, 2011
play a sound when there's a tornado warning near me
View alarm.py
#!/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
Python-like dir function for scheme
View directory.scm
;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 Oct 19, 2011
dim blue-green (traffic light mix) color filter for compiz
View gist:1297161
!!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 Apr 7, 2012
Play YouTube on LAN XBMC Eden
View xbmcyoutube.sh
#!/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:xbmc@192.168.1.10: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 Nov 7, 2012
Bezier Curve Subdivision Functions
View curve.clj
(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 Jan 9, 2014
JSON parsing script for BitCoin prices within Google Docs
View gist:8327127
// 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 Jan 25, 2014
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.
View multimon-ng-filter.py
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",