This file contains 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
<!-- | |
JSON-P Google Plus fetcher for Octopress | |
(c) Jolam Jiang // MIT License | |
You can see the tutorial of adding sidebar here: | |
http://bandj.us/jo/blog/blog/2011/12/03/adding-google-plus-sidebar-to-octopress/ | |
--> | |
{% if site.googleplus_user %} | |
<section> | |
<!-- load jquery --> |
This file contains 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 twitter | |
#gist https://gist.github.com/1592859 | |
twitter_api=twitter.Twitter(domain="api.twitter.com", api_version='1') | |
WORLD_WOE_ID = 1 # The Yahoo! Where On Earth ID for the entire world | |
world_trends = twitter_api.trends._(WORLD_WOE_ID) # get back a callable | |
print [ trend for trend in world_trends()[0]['trends'] ] # call the callable and iterate through the trends returned | |
twitter_search = twitter.Twitter(domain="search.twitter.com") | |
search_results = [] |
This file contains 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
# implemented according to the psudocode from: | |
# http://en.wikipedia.org/wiki/Heapsort (2013/03/05) | |
def heapSort(unsortedList): | |
heapify(unsortedList) | |
end = len(unsortedList) - 1 | |
while end > 0: | |
unsortedList[end], unsortedList[0] = unsortedList[0], unsortedList[end] | |
end -= 1 | |
shiftDown(unsortedList, 0, end) |
This file contains 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
# Given a balanced binary tree like this: | |
# 1 | |
# / \ | |
# 2 3 | |
# / \ / \ | |
# 4 5 6 7 | |
# | |
# Sample Output: | |
# 1. preorder traversal: 1 2 4 5 3 6 7 | |
# 2. inorder traversal: 4 2 5 1 6 3 7 |
This file contains 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
class KdTree(object): | |
# the KdTree must know the domains (numerical) and ensure the | |
# consistence of domains of all the points in the tree | |
def __init__(self, domains, root=None): | |
self.domains = domains | |
self.root = root | |
if not root is None: | |
for domain in domains: | |
setattr(self, domain, getattr(root.point, domain)) |
This file contains 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
#!/usr/bin/python | |
""" | |
This program is used for face detection and save the faces it detects. | |
""" | |
import sys | |
import re | |
import cv2 | |
import cv2.cv as cv | |
import numpy |
This file contains 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
# sample input: [1, -1, 0, -1, -1] | |
# means one sailor on the first plank, the third plank | |
# is the one with nothing and the left are pirates. | |
# sample output: | |
# 00 [1, -1, 0, -1, -1] | |
# 01 [0, 1, 1, -1, -1] | |
# 02 [-1, -1, -1, 0, -1] | |
# 03 [-1, 0, 1, -1, -1] | |
# 04 [-1, -1, -1, 1, 0] |
This file contains 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
from collections import deque | |
from functools import reduce | |
a = deque([9, 6, 6, 6]) | |
b = deque([7, 1, 5, 3]) | |
c = deque([4, 3, 2, 8]) | |
def is_satisfied(a, b, c): | |
avg = (sum(a) + sum(b) + sum(c)) / 4 |
This file contains 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
from itertools import combinations | |
from functools import reduce | |
from operator import xor | |
a = [1, 2, 4, 7, 15, 31] | |
s = set([]) | |
for i in range(1, len(a) + 1): | |
for e in combinations(a, i): | |
s.add(sum(e)) |
This file contains 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 json | |
f = open('all.json') | |
json = json.loads(f.read()) | |
f.close() | |
predicts = [] | |
results = [] | |
for i in json: | |
bodys = i['data']['body'] |
OlderNewer