Skip to content

Instantly share code, notes, and snippets.

View palfrey's full-sized avatar

Tom Parker-Shemilt palfrey

View GitHub Profile
CmdUtils.CreateCommand({
names: ["isgd"],
author: {name: "Thomas Brownback", homepage: "http://thomasbrownback.com", blog: "http://theorybloc.com"},
contributors: ["Tom Parker"],
thanks: {first: "Aza Raskin", foremost: "Aza Raskin", honorableMention: "geero.net", lastAmpBangLeast: "users like you"},
license: "PUBLIC DOMAIN: Any and all rights herein are hereby donated to the commons.",
description: "Shortens a URL using is.gd.",
help: "Replaces a selection with (or simply inserts) a shortened URL from is.gd.",
arguments: [{role: "urlToShorten",
nountype: noun_arb_text,
// ==UserScript==
// @name Remove left blank in Google results
// @namespace http://tevp.net/projects/
// @description Remove left blank in Google results
// @include http://www.google.*/search*
// ==/UserScript==
function xpath(query) {
return document.evaluate(query, document, null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
@palfrey
palfrey / gist:629139
Created October 15, 2010 23:22
Artist/Album/Title search
artist(Name) ->
lastfm_call(artist.search, [{artist,Name}], ['artistmatches'], ['artist'], []).
album(Name) ->
lastfm_call(album.search, [{album,Name}], ['albummatches'], ['album'], ['artist']).
track(Name) ->
lastfm_call(track.search, [{track,Name}], ['trackmatches'], ['track'], ['artist','listeners']).
@palfrey
palfrey / gist:719162
Created November 28, 2010 18:26
Example KML file
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Placemark>
<name>Test item one</name>
<Point>
<coordinates>-0.000180,-0.000180</coordinates>
</Point>
</Placemark>
<Placemark>
<DocumentElement>
<Table>
<Id>657</Id>
<WLo>0.11070013046264648</WLo>
<WLa>51.493020732623478</WLa>
<GZ>15</GZ>
<LN>Abbey Wd - Felixstowe Rd</LN>
</Table>
<Table>
<Id>139</Id>
@palfrey
palfrey / ShadowMenuInflater.java
Created December 31, 2010 15:44
ShadowMenuInflater
package com.xtremelabs.robolectric.shadows;
import android.content.Context;
import android.view.Menu;
import android.view.MenuInflater;
import com.xtremelabs.robolectric.internal.Implementation;
import com.xtremelabs.robolectric.internal.Implements;
import static com.xtremelabs.robolectric.Robolectric.shadowOf;
@palfrey
palfrey / gist:761092
Created December 31, 2010 15:45
Robolectric test
@RunWith(RobolectricTestRunner.class)
public class MyActivityTest {
private Activity activity;
private Button pressMeButton;
private TextView results;
@Before
public void setUp() throws Exception {
activity = new MyActivity();
activity.onCreate(null);
@palfrey
palfrey / gist:803140
Created January 30, 2011 19:19
Revset boilerplate
try:
from mercurial import ui, hg, revset
except ImportError:
raise Exception, "Need mercurial >=1.6 for revset!"
def revs(repo, spec, items = None):
ret = []
if items == None:
items = range(len(repo))
m = revset.match(spec)
# get all the open heads
heads = revs(repo, "head() & (! closed())")
# find the common ancestor of default and revision_number ...
ancestor = revs(repo, "ancestor(%d, default)"% revision_number )[0]
# ... then get the path of changes between the common ancestor
# and our original revision
path = revs(repo, "%d::%d"%(ancestor, revision_number))
# The above can also be done just as
@palfrey
palfrey / compoundMovies.py
Created February 13, 2011 23:46
#compoundMovies generator
import gzip
from re import compile
from os.path import exists
from sys import exit, argv
from xml.dom.minidom import parseString
import codecs
try:
import urlgrab
except ImportError:
print "run 'git clone git://github.com/palfrey/urlgrab.git' and re-run this script"