Skip to content

Instantly share code, notes, and snippets.

View liang456's full-sized avatar

James liang456

  • SJTU
  • Shanghai, China
View GitHub Profile
@liang456
liang456 / weiboaccess.py
Created October 22, 2012 03:18
This a client program to access the Sina Weibo API
# This program rely on the following python SDK for sina
# https://github.com/michaelliao/sinaweibopy
from weibo import APIClient
APP_KEY = '1234567' # app key
APP_SECRET = 'abcdefghijklmn' # app secret
CALLBACK_URL = 'http://www.example.com/callback' # callback url
client = APIClient(app_key=APP_KEY, app_secret=APP_SECRET, redirect_uri=CALLBACK_URL)
url = client.get_authorize_url()
@liang456
liang456 / GraphAlg.py
Created October 19, 2012 15:55
Graph Algorithms in Python
def mark_component(G, node, marked):
marked[node] = True
total_marked = 1
for neighbor in G[node]:
if neighbor not in marked:
total_marked += mark_component(G, neighbor, marked)
return total_marked
def check_connection(G, v1, v2):
# Return True if v1 is connected to v2 in G
@liang456
liang456 / Russian Peasants Algorithm.py
Created October 19, 2012 03:34
Russian Peasants Algorithm
# This is an algorithm that people actually implemented by hand before
# there were computers. Here's the Russian Peasants Algorithm in Python.
#
def russian(a, b):
x = a
y = b
z = 0
while x > 0: