Skip to content

Instantly share code, notes, and snippets.

@segphault
segphault / electiontrack.py
Created November 6, 2008 19:37
Retrieve data from Google's election tracker
#!/usr/bin/env python
import simplejson, urllib2
DATA_URL = "http://election2008.s3.amazonaws.com/votes/us-pres.json"
data = simplejson.loads(urllib2.urlopen(DATA_URL).read())
for candidate in data["totals"]["races"]["President"][""]["votes"]:
name = data["candidates"][candidate["id"]].split("|")[1]
@segphault
segphault / dropio_uploader.py
Created November 11, 2008 09:21
A tool for uploading files to Drop.io
#!/usr/bin/env python
# Drop.io Upload Tool for GNOME
# Copyright (C) 2008 Ryan Paul (SegPhault)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
@segphault
segphault / Main.fx
Created December 6, 2008 09:39
A Twitter search tool written in JavaFX
/*
* Main.fx
*
* Created on Dec 5, 2008, 11:27:35 AM
*/
package testapplication;
import javafx.scene.*;
import javafx.scene.image.*;
@segphault
segphault / gist.vim
Created December 9, 2008 08:25
VimGist - a plugin that integrates support for GitHub Gist in Vim
"
" Plugin: VimGist
" Author: SegPhault (Ryan Paul) - 12/08/2008
" Description: This plugin integrates support for GitHub Gist in Vim
"
python << EOF
import vim, sys, os.path
sys.path.append("/home/segphault/project/utilities/gist")
@segphault
segphault / gist:41166
Created December 29, 2008 03:47
Manually set widget icons in GTK+
# Each individual GTK+ widget has a completely different set of functions for
# manually setting an icon. It also has to be done differently depending on
# whether the icon is being set by stock name or by filename. These
# inconsistencies make GTK+ very frustrating.
def set_icon_named(name, widget, size=gtk.ICON_SIZE_MENU):
if isinstance(widget, gtk.ImageMenuItem):
if name.startswith("/"): widget.get_image().set_from_file(name)
else: widget.get_image().set_from_icon_name(name, size)
@segphault
segphault / gist:41169
Created December 29, 2008 04:03
Menu setup in GrabberSnap
def setup_menus(self):
ui_string = """
<ui>
<menubar name="menubarMain">
<menu action="menuFile">
<menuitem action="Capture"/>
<menuitem action="Open"/>
<menuitem action="Save"/>
<menuitem action="Upload"/>
<separator/>
@segphault
segphault / twittersearch.js
Created January 11, 2009 04:07
Twitter search demo for Seed
Seed.import_namespace("Gtk");
Seed.import_namespace("Gdk");
Seed.import_namespace("Gio");
Seed.include("pretty.js");
Gtk.init(null, null);
var window = new Gtk.Window({"title": "Twitter Search", "border-width": 5});
window.signal.hide.connect(Gtk.main_quit);
@segphault
segphault / monkeypatch.js
Created January 11, 2009 21:03
Monkey patching in Seed
Seed.import_namespace("Gtk");
Gtk.init(null, null);
Gtk.Container.prototype.clear = function() {
var container = this;
container.foreach(function(i) {container.remove(i)});
}
Gtk.Container.prototype._add = Gtk.Container.prototype.add;
@segphault
segphault / twin.py
Created January 16, 2009 20:28
Week in review generator
#!/usr/bin/env python
import urllib2, re
from BeautifulSoup import BeautifulStoneSoup
ARTICLE_URLS = """
<PUT URLS HERE, ONE PER LINE>
""".strip().split("\n")
xml = BeautifulStoneSoup(urllib2.urlopen("http://feeds.arstechnica.com/arstechnica/journals/openended"))
@segphault
segphault / XMLRPCServer.pm
Created January 18, 2009 19:19
Movable Type XML-RPC enhancement
sub _get_entries {
my $class = shift;
my %param = @_;
my($blog_id, $user, $pass, $num, $titles_only) =
@param{qw( blog_id user pass num titles_only )};
my $obj_type = $param{page} ? 'page' : 'entry';
my $mt = MT::XMLRPCServer::Util::mt_new(); ## Will die if MT->new fails.
my($author, $perms) = $class->_login($user, $pass, $blog_id);
die _fault(MT->translate("Invalid login")) unless $author;
die _fault(MT->translate("Permission denied.")) unless $perms && $perms->can_create_post;