Skip to content

Instantly share code, notes, and snippets.

@anandkunal
anandkunal / gmail_pagination_hack.js
Created March 8, 2010 07:03
Gmail Pagination Hack
// 1: older page for all mail
49: function() {
currentPage = GrabCurrentAllMailPage();
if (currentPage >= 2) {
window.location.hash = "#all/p" + (currentPage-1);
}
},
// 2: newer page for all mail
50: function() {
@anandkunal
anandkunal / list_predicates.py
Created March 8, 2010 07:07
Python List Predicates
from types import FunctionType
from UserList import UserList
class PredicateList(UserList):
def Exists(self, predicate):
"""Returns true if the predicate is satisfied by at least one list member."""
if type(predicate) is FunctionType:
for item in self.data:
if predicate(item):
return True
@anandkunal
anandkunal / gist:324963
Created March 8, 2010 07:24
ColdFusion Tagging Library
<cfset tags_list = " CaMELCaSE comma, 'singlequoted' <b>bold</b> ""doublequoted"" double double this should be over the limit now " />
<cfset amount = 10 />
<cfset length = 20 />
<pre><cfset tags_list = trim(tags_list) />
<cfset tags_list = lcase(tags_list) />
<cfset tags_struct = structnew() />
@anandkunal
anandkunal / duplicate_image.py
Created March 8, 2010 07:38
I whipped up this quick recipe using the Python Imaging Library. It's nothing fancy, but it gets the job done. Hacking this script to scoop/compare images in a directory is rather trivial.
import Image
def is_the_same(base, test_image):
for i in range(len(base)):
if (base[i] - test_image[i]) != 0:
return False
return True
base = Image.open('base.png').getdata()
bad = Image.open('bad.png').getdata()
total_pages = 68;
full_document_path = "~/Project/Assets/catalog.pdf";
full_output_path = "~/Project/Assets/jpg/";
function open_document(page) {
FileReference = new File(full_document_path);
PDFOpenOptions = new PDFOpenOptions();
PDFOpenOptions.page = page;
PDFOpenOptions.resolution = 72;
app.open(FileReference, PDFOpenOptions);
import sets
import string
whitespace = sets.ImmutableSet(string.whitespace)
def qs(test_string, abbreviation, offset=None):
offset = offset or 0
if len(abbreviation) == 0: return 0.9
if len(abbreviation) > len(test_string): return 0.0
class Stacker(object):
""" A minimal calculator that only supports addition/multipliction. """
def __init__(self):
self.s = []
self.ops = {
'+' : lambda: self.s.append(self.s.pop() + self.s.pop()),
'*' : lambda: self.s.append(self.s.pop() * self.s.pop())
}
class Thing(object):
def __init__(self):
self.__missing_method_name = None # Hack!
def __getattribute__(self, name):
return object.__getattribute__(self, name)
def __getattr__(self, name):
self.__missing_method_name = name # Could also be a property
return getattr(self, '__methodmissing__')
pattern_punctuation = re.compile('(\!|\.|\?|\;|\,|\:|\&|\_|\{|\}|\[|\]|\~|\:|\-|\;|\$|\(|\))')
pattern_numbers = re.compile('[0-9]')
pattern_plurals = re.compile('\'s$')
pattern_possesives = re.compile('s\'$')
pattern_quotations = re.compile('(\'|\")')
pattern_word = re.compile('[a-z]+')
def tokenize_word(word):
before = word
word = word.lower()
from __future__ import with_statement
import inspect
class Test(object):
def __init__(self, name):
self.name = name
def __enter__(self):
return self