Skip to content

Instantly share code, notes, and snippets.

def replace_template(map, template):
trie = Trie(map)
iter = template.__iter__
for c in iter:
if c != '$': print c
else:
s = iter.next()
trie.lookup(iter)
if replacement:
print replacement
@jamesnvc
jamesnvc / jamesnvc-quix.txt
Created March 26, 2010 23:36
My quix commands
> James Cash's Custom Quix Commands
@James Cash's Custom Quix Commands
src view-source:%r View source natively
insta javascript:function%20iprl5(){var%20d=document,z=d.createElement('scr'+'ipt'),b=d.body,l=d.location;try{if(!b)throw(0);d.title='(Saving...)%20'+d.title;z.setAttribute('src',l.protocol+'//www.instapaper.com/j/pL8VMUDiGTio?u='+encodeURIComponent(l.href)+'&t='+(new%20Date().getTime()));b.appendChild(z);}catch(e){alert('Please%20wait%20until%20the%20page%20has%20loaded.');}}iprl5();void(0) Add to Instapaper
import media
COLOUR_MAX = 255
COLOUR_MIN = 0
def get_picture():
'''Solicit user input to select a file and load it as a Picture.
Return the Picture.
'''
filename= media.choose_file()
import media
COLOUR_MAX = 255
COLOUR_MIN = 0
def get_picture():
'''Solicit user input to select a file and load it as a Picture.
Return the Picture.
'''
filename= media.choose_file()
def ReturnExample():
return 5
x = ReturnExample()
print x # Prints 5
import media
def sum_red(pic):
total = 0
for p in pic:
r = media.get_red(p)
total = r + total
return total
# Note that these are just samples, and may not work unmodified...
# Comparing pictures stored in picture_a and picture_b
# Assumes:
# 1. You've already resized the images to the same size
# 2. The width & height of the images are stored in variables of the same names
# 3. The images have been normalized to the same average intensity
# 4. You've written a function named 'intensity' to calculate the intensity of
# a given pixel
def adjust_colours(target_pic, reference_pic):
'''Takes target pic and adjusts it's average RGB values to reference pic's RGB values...
'''
target_red_avg = red_average(target_picture)
reference_red_avg = red_average(reference_picture)
red_scale_factor = reference_red_avg/target_red_avg
target_blue_avg = blue_average(target_picture)
def smart_difference(pic1, pic2):
'''Take two pictures and tests how similar they are. Excuse the terrible docstrings. They need some work
'''
h1 = get_height(pic1)
h2 = get_height(pic2)
w1 = get_width(pic1)
w2 = get_width(pic2)
if (h1 > h2):
# Line 254
if x < media.get_width(picture2) and y < media.get_height(picture2):
pixel2 = media.get_pixel(picture2, x, y)
else:
pixel2 = media.get_pixel(picture2, media.get_width(picture2)-1, media.get_height(picture2)-1)
sum_of_difference = sum_of_difference + distance(pixel, pixel2)