Skip to content

Instantly share code, notes, and snippets.

View singpolyma's full-sized avatar

Stephen Paul Weber singpolyma

View GitHub Profile
@singpolyma
singpolyma / prompt.sh
Created November 14, 2008 16:47
Awesome git prompt
# Determine if the current directory is a GIT repo
# and print out '*' if there are changes to be committed
iz_git_dirty() {
#IZ_GIT=`git status 2>/dev/null`
IZ_DIRTY=`git status 2>/dev/null | grep 'nothing to commit (working directory clean)'`
#if [ "." != "$IZ_GIT." ]; then
if [ "." == "$IZ_DIRTY." ]; then
echo '*'
fi
@singpolyma
singpolyma / version_number.rb
Created November 15, 2008 02:09
Describe a version number in Ruby as a Numeric, with math and comparators defined sanely
# A version number is a kind of number
class VersionNumber < Numeric
attr_reader :parts, :labels, :literal
# Create a new VersionNumber
def initialize(literal=nil)
@parts = [0,0,0] # Numeric parts
@labels = ['major', 'minor', 'patch'] # Alpha parts
@literal = literal.to_s # The original literal
# Generates a patch by comparing two directories using a simple logfile format
# A relative/path for added files (will be directly copied)
# D relative/path for removed files (will be directly removed using the command defined in RM)
# M relative/path for modified files (will be included in the output patch)
olddir = ARGV[0] # Unchanged
newdir = ARGV[1] # Changes
unless olddir && newdir
warn 'ERROR, must pass two directories'
require 'rubygems'
require 'hpricot'
require 'open-uri'
require 'uri'
require 'cgi'
def get_doc(uri)
if uri.to_s =~ /explore\.twitter\.com/
uri = URI.parse('http://twitter.com/' + uri.to_s.scan(/.+\/(.+)$/)[0][0])
<?php
class Outline {
var $_fields = array();
var $_subnodes = array();
var $_constructed = false;
function Outline($data='',$options=array()) {
if($_constructed) return;
$this->__construct($data,$options);
<?php
require_once(dirname(__FILE__).'/Outline.php');
class OutlineFromXML extends Outline {
var $_errorcode = 0;
function getError() { return $this->_errorcode; }
<?php
require_once dirname(__FILE__).'/Outline.php';
require_once dirname(__FILE__).'/OutlineFromXML.php';
function checkXML($data) {//returns FALSE if $data is well-formed XML, errorcode otherwise
$rtrn = 0;
$theParser = xml_parser_create();
if(!xml_parse_into_struct($theParser,$data,$vals)) {
$errorcode = xml_get_error_code($theParser);
#!/bin/sh
FLASHVARS=`curl -s "$*" | grep swfArgs | sed -e 's/: /=/g' | sed -e 's/, /\&/g' | sed -e 's/"//g' | sed -e 's/^.*{//g' | sed -e 's/}.*$//g'`
echo "http://youtube.com/get_video.php?$FLASHVARS"
#!/bin/sh
YT=`which yt`
if [ -z "$YT" ]; then
YT="`dirname $0`/yt"
fi
if [ -z "$YT" ]; then
echo "ERROR: could not find yt script" 1>&2
exit 1
fi
class Array
def invert
[1,2,3,4,5,6,7,8,9].select do |i|
! self.include?i
end
end
end
class Unsolvable < Exception
end