Skip to content

Instantly share code, notes, and snippets.

@vilterp
vilterp / x
Created November 4, 2008 02:17
Instapaper bookmarlet >> Ubiquity command
CmdUtils.makeBookmarkletCommand({
name: "Read Later",
url: "javascript:var%20d=document,w=window,e=w.getSelection,k=d.getSelection,x=d.selection,s=(e?e():(k)?k():(x?x.createRange().text:0)),f='http://www.instapaper.com/b',l=d.location,e=encodeURIComponent,p='?v=4&k=9UhIRDKrjIUD&u='+e(l.href)%20+'&t='+e(d.title)%20+'&s='+e(s),u=f+p;try{if(!/^(.*\.)?instapaper([^.]*)?$/.test(l.host))throw(0);iptstbt();}catch(z){a%20=function(){if(!w.open(u,'t','toolbar=0,resizable=0,status=1,width=250,height=150'))l.href=u;};if(/Firefox/.test(navigator.userAgent))setTimeout(a,0);else%20a();}void(0)"
})
@vilterp
vilterp / x
Created November 4, 2008 02:30
Chyrp Ubiquity command
CmdUtils.makeBookmarkletCommand({
name: "Chyrp this",
url: "javascript:var%20d=document,w=window,e=w.getSelection,k=d.getSelection,x=d.selection,s=(e?e():(k)?k():(x?x.createRange().text:0)),f='http://thinking-chair.com/notebook/admin/?action=bookmarklet',l=d.location,e=encodeURIComponent,p='&url='+e(l.href)+'&title='+e(d.title)+'&selection='+e(s),u=f+p;a=function(){if(!w.open(u,'t','toolbar=0,resizable=1,status=1,width=450,height=430'))l.href=u;};if(/Firefox/.test(navigator.userAgent))setTimeout(a,0);else%20a();void(0)"
})
@vilterp
vilterp / js
Created November 5, 2008 22:37
is.gd Ubiquity command
CmdUtils.CreateCommand({
name: "is.gd",
takes: {"url to shorten": noun_type_url},
icon: "http://is.gd/favicon.ico",
description: "Shortens the selected url with <a href=\"http://is.gd/\">is.gd</a>",
preview: function(pblock, urlToShorten){
pblock.innerHTML = "Shortens the selected url with is.gd.";
var baseUrl = "http://is.gd/api.php?longurl=";
pblock.innerHTML = "Replaces the selected URL with ";
jQuery.ajax({
@vilterp
vilterp / scalifier.py
Created December 8, 2008 00:59
scale name >> key signature
octave = ['C',('C#','Db'),'D',('D#','Eb'),'E','F',('F#','Gb'),'G',('G#','Ab'),'A',('A#','Bb'),'B']
def is_valid_scale_name(scalename):
if len(scalename) > 2: return False
if len(scalename) == 2 and scalename[1] != 'b': return False
if scalename[0].upper() not in 'ABCDEFG': return False
return True
def find_note(name):
for i in range(len(octave)):
@vilterp
vilterp / twinecommand.js
Created December 9, 2008 01:28
Twine advanced bookmarklet Ubiquity command
CmdUtils.makeBookmarkletCommand({
name: "twine-this",
url:"javascript:(function(){var%20d=document,w=window,a=window.getSelection,b=document.getSelection,c=document.selection,s=(a?a():(b)?b():(c?c.createRange().text:0)),l=d.location,e=encodeURIComponent;if(!d.getElementById('rdr-script'))try{var%20s=d.createElement('script');s.type='text/javascript';s.id='rdr-script';s.src='http://www.twine.com/js/spotthis.js';(d.body||d.documentElement).appendChild(s);}catch(x){var%20p='?u='%20+e(l.href)%20+'&t='+e(d.title)%20+'&s='+e(s)%20+'&v=1',u='http://www.twine.com/bookmark/basic'+p;l.href=u%20+'&adv=1';}})()"
})
import java.util.ArrayList;
public class SudokuBoard {
private int[][] board;
public SudokuBoard() {
board = new int[9][9];
}
def quicksort(array, start=None, end=None):
"""end is the index of the last element to be sorted"""
if start is None and end is None:
quicksort(array,0,len(array)-1)
return array
else:
if start < end:
pivot_index = partition(array,start,end)
quicksort(array,start,pivot_index-1)
quicksort(array,pivot_index+1,end)
@vilterp
vilterp / presidents.txt
Created January 2, 2009 02:54
test for quicksorting Comparables
George Washington
John Adams
Thomas Jefferson
James Madison
James Monroe
John Quincy Adams
Andrew Jackson
Martin Van Buren
William H. Harrison
John Tyler
def mergesort(array, start=None, end=None):
if start is None and end is None:
return mergesort(array,0,len(array)-1)
else:
if start == end: return
middle = start+(end-start)/2
mergesort(array,start,middle)
mergesort(array,middle+1,end)
merge(array,start,middle,middle+1,end)
return array
@vilterp
vilterp / httpproxy.py
Created January 20, 2009 00:45
attempt at a proxy server. Really slow, I think it has to be threaded or something to work right.
import socket
class Proxy:
serversock_port = 987654
def __init__(self, host='localhost', port=1234, req_func=None, resp_func=None):
self.browsersock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.browsersock.bind((host,port))
print 'listening %s:%d' % (host,port)