Skip to content

Instantly share code, notes, and snippets.

@zfz
zfz / Tweetsheets
Created August 12, 2012 08:11 — forked from johannesnagl/Tweetsheets
Use Twitter directly in your Google Doc, so no one will ever blame you for being social
var CONSUMER_KEY = "<< YOUR KEY HERE >>";
var CONSUMER_SECRET = "<< YOUR SECRET HERE >>";
function getConsumerKey() {
return CONSUMER_KEY;
}
function getConsumerSecret() {
return CONSUMER_SECRET;
}
@zfz
zfz / Print_results.py
Created November 24, 2012 08:47
Recursive version: Depth First Search in a Graph
Graph:
{'a': {'d': 1, 'g': 1}, 'c': {'g': 1}, 'b': {'f': 1}, 'e': {'h': 1, 'f': 1}, 'd': {'a': 1, 'g': 1}, 'g': {'a': 1, 'c': 1, 'd': 1}, 'f': {'b': 1, 'e': 1}, 'h': {'e': 1}}
List example:
set(['a', 'c', 'd', 'g'])
set(['a', 'c', 'd', 'g'])
Dict example:
{'a': True, 'c': True, 'd': True, 'g': True}
{'a': True, 'c': True, 'd': True, 'g': True}
@zfz
zfz / Print_results.py
Created November 26, 2012 07:52
None Recursive version: Depth First Search in a Graph
Graph:
{1: {2: 1}, 2: {1: 1, 3: 1}, 3: {2: 1}, 4: {5: 1}, 5: {4: 1, 6: 1}, 6: {5: 1}}
total_marked:
1(Why not 3?)
marked:
{1: True, 2: True, 3: True}
@zfz
zfz / Print_results.py
Created November 26, 2012 09:26
Maximum distance
Chain graph:
{1: {2: 1}, 2: {1: 1, 3: 1}, 3: {2: 1, 4: 1}, 4: {3: 1, 5: 1}, 5: {4: 1, 6: 1}, 6: {5: 1}}
Tree graph:
{1: {2: 1, 3: 1}, 2: {1: 1, 4: 1, 5: 1}, 3: {1: 1, 6: 1, 7: 1}, 4: {8: 1, 9: 1, 2: 1}, 5: {2: 1}, 6: {11: 1, 10: 1, 3: 1}, 7: {3: 1}, 8: {4: 1}, 9: {4: 1}, 10: {6: 1}, 11: {6: 1}}
Distance:
{1: 0, 2: 1, 3: 2, 4: 3, 5: 4, 6: 5}
{1: 2, 2: 1, 3: 0, 4: 1, 5: 2, 6: 3}
@zfz
zfz / Kth_big.py
Created November 27, 2012 10:19
Top K proeblem and the Kth big
# Udacity, CS215, Homework 4.2
# Given a list of numbers, L, find a number, x, that
# minimizes the sum of the absolute value of the difference
# between each element in L and x: SUM_{i=0}^{n-1} |L[i] - x|
#
# Your code should run in Theta(n) time
# Why median? http://www.udacity.com/wiki/CS215Unit4SolutionsMean?course=cs215
# Modified from: http://forums.udacity.com/cs215/questions/3447/ps4-2-error-running-code-is-there-a-case-im-missing
import random
@zfz
zfz / down_heapify.py
Created November 27, 2012 15:56
Up Heapify
# Udacity, CS215, 4.2 Down Heapify
# import random
# L = [random.randrange(90)+10 for i in range(20)]
L = [50, 88, 27, 58, 30, 21, 58, 13, 84, 24, 29, 43, 61, 44 ,65, 74, 76, 30, 82, 43]
#Heap shortcuts
def left(i): return i*2+1
def right(i): return i*2+2
def parent(i): return (i-1)/2
def root(i): return i==0
@zfz
zfz / guess_number.py
Created November 29, 2012 02:35
Mini Projets for An Introduction to Interactive Programming in Python
# Mini Project 2 for An Introduction to Interactive Programming in Python
# template for "Guess the number" mini-project
# input will come from buttons and an input field
# all output for the game will be printed in the console
# url http://www.codeskulptor.org/#user6-irmTc4hgQqb60Du.py
import random
import simplegui
# initialize global variables used in your code
@zfz
zfz / vimpteratorrc
Last active December 27, 2015 10:58
inoremap <C-c> <Ins><C-c><Ins>
inoremap <C-v> <Ins><C-v><Ins>
inoremap <C-a> <Ins><C-a><Ins>
nnoremap <A-j> gT
nnoremap <A-k> gt
nnoremap <A-h> <S-h>
nnoremap <A-l> <S-l>
nnoremap x d
# 中西文切換鍵的默認設置寫在 default.yaml 裏面
# 以下的 default.custom.yaml 在全局範圍重定義該組快速鍵
#
# 可用的按鍵有 Caps_Lock, Shift_L, Shift_R, Control_L, control_R
# Mac 系統上的鼠鬚管不能區分左、右,因此只有對 Shift_L, Control_L 的設定起作用
#
# 已輸入編碼時按切換鍵,可以進一步設定輸入法中西文切換的形式。
# 可選的臨時切換策略有三:
# inline_ascii 在輸入法的臨時西文編輯區內輸入字母、數字、符號、空格等,回車上屏後自動復位到中文
# commit_text 已輸入的候選文字上屏並切換至西文輸入模式