This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib, urllib2 | |
import cookielib | |
def getInstapaperArchive(username, password): | |
login_url = "http://www.instapaper.com/user/login" | |
home_url = "http://www.instapaper.com/u" | |
kindle_url = "http://www.instapaper.com/mobi" | |
params = {"username":username, "password":password} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def merge(left, right): | |
""" Merges two sorted lists into one sorted list """ | |
result = [] | |
while len(left) > 0 or len(right) > 0: | |
if len(left) > 0 and len(right) > 0: | |
if left[0] <= right[0]: | |
result.append(left.pop(0)) | |
else: | |
result.append(right.pop(0)) | |
elif len(left) > 0: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_all_substrings(string): | |
substrings = [] | |
for i in xrange(len(string)): | |
n = i | |
while n >= 0: | |
substrings.append(string[n:i+1]) | |
n -= 1 | |
return substrings |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unicodedata | |
def normalize(s): | |
""" Safely/sanely ransforms a string from unicode to ascii. """ | |
return unicodedata.normalize('NFKD', unicode(s)).encode('ascii','ignore') | |
def sanitize(s, replace_with=None): | |
""" Replace control chars, unicode chars, and whitespace with '?'. """ | |
if not replace_with: replace_with = '?' | |
return ''.join(c if (32 < ord(c) < 127) else replace_with for c in s) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def levenshtein_distance(first, second): | |
""" | |
Find the Levenshtein distance between two strings. | |
Levenshtein distance gives you a basic idea of how similar two strings are. | |
""" | |
if len(first) > len(second): | |
first, second = second, first | |
if len(second) == 0: | |
return len(first) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Growl | |
def growlnotify(title, message, sticky=False): | |
""" | |
Sends a notification to Growl with title and message. | |
`sticky` specifies whether or not the user has to click | |
the message to make it go away. | |
TODO: | |
- allow specification of an icon | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import operator | |
def sort_dict(d): | |
""" | |
Sorts a dict by it's values, assuming the values are ints. | |
""" | |
return sorted(d.iteritems(), key=lambda (k,v): (v,k), reverse=True) | |
def sort_dict_list(l, key): | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
int isrotation(char*, char*); | |
main() { | |
int result = isrotation("byegood", "goodbye"); | |
if (result == 0) { | |
printf("Nope.\n"); | |
} else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
void foo() | |
{ | |
static int i = 1; | |
int j = 1; | |
i++; // | |
printf("i: %d, ", i); | |
j++; // |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string.h> | |
void reverse(char* str) { | |
int i; | |
int len = strlen(str); | |
for (i = 0; i < len/2 ; ++i){ | |
str[len] = str[i]; | |
str[i] = str[len - i - 1]; | |
str[len - i - 1] = str[len]; |
OlderNewer