Skip to content

Instantly share code, notes, and snippets.

View jo32's full-sized avatar
🎯
Focusing

jo32

🎯
Focusing
View GitHub Profile
@jo32
jo32 / plusposts.html
Created December 3, 2011 13:33
Google Plus Sidebar for Octopress
<!--
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 -->
@jo32
jo32 / ex13.py
Created September 21, 2012 05:38
Mining the Social Web, Example 1-3
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 = []
@jo32
jo32 / heap.py
Created March 5, 2013 07:50
heap sort test code
# 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)
# 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
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))
@jo32
jo32 / facedetect.py
Created May 13, 2013 12:41
face detection using OpeCV haar detection and save them
#!/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
@jo32
jo32 / azran_legacy_puzzle_07.py
Last active August 29, 2015 14:01
Python Solution of Puzzle #7 of Professor Layton: Azran Legacy
# 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]
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
@jo32
jo32 / azran_legacy_puzzle_025.py
Created June 6, 2014 17:42
azran_legacy_puzzle_025.py
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))
@jo32
jo32 / analyse.py
Created June 23, 2014 13:25
is-baidu-world-cup-prediction-reliable
import json
f = open('all.json')
json = json.loads(f.read())
f.close()
predicts = []
results = []
for i in json:
bodys = i['data']['body']