Skip to content

Instantly share code, notes, and snippets.

@ZoeyYoung
ZoeyYoung / Preferences.sublime-settings
Created December 8, 2012 11:18
Sublime Text 2 User Setting
{
"auto_complete_commit_on_tab": true,
"bold_folder_labels": true,
"color_scheme": "Packages/User/Monokai Soda.tmTheme",
"default_line_ending": "unix",
"detect_slow_plugins": false,
"draw_minimap_border": true,
"draw_white_space": "all",
"fade_fold_buttons": false,
"font_face": "Ubuntu Mono",
@ZoeyYoung
ZoeyYoung / gist:4239908
Created December 8, 2012 11:27 — forked from aisensiy/gist:3618541
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (PC)

Loosely ordered with the commands I use most towards the top. Sublime also offer full documentation.

Editing

Ctrl+C copy current line (if no selection)
Ctrl+X cut current line (if no selection)
Ctrl+⇧+K delete line
Ctrl+↩ insert line after
@ZoeyYoung
ZoeyYoung / gist:5677849
Last active December 17, 2015 21:49
Python: Merge Sort
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
算法导论, “哨兵牌”版本
"""
INF = float("inf")
def merge_sort(A, p, r):
if p < r:
@ZoeyYoung
ZoeyYoung / closest.py
Created June 5, 2013 07:25
Python Algorithms CHAPTER 4
from random import randrange
seq = [randrange(10**10) for i in range(100)]
seq.sort()
dd = float("inf")
for i in range(len(seq)-1):
x, y = seq[i], seq[i+1]
if x == y: continue
d = abs(x-y)
if d < dd:
xx, yy, dd = x, y, d
@ZoeyYoung
ZoeyYoung / counting_sort.py
Last active December 18, 2015 02:39
Counting Sort
#-*-coding:utf-8-*-
def counting_sort(A, k):
B, C = [0] * len(A), [0] * (k + 1) # 包括0和k,长度k+1
for a in A:
C[a] += 1
for i in range(1, k + 1): # 1 to k
C[i] += C[i-1]
for j in range(len(A) - 1, -1, -1):
# 这里要注意索引从0开始的,所以要-1
B[C[A[j]] - 1] = A[j]
s = 'abcdefgh'
r = s[::-1]
print(r) #a : hgfedcba
@ZoeyYoung
ZoeyYoung / binary_search_tree.py
Created June 5, 2013 15:49
算法导论: 二叉查找树
class Node:
p = None
left = None
right = None
def __init__(self, key, val):
self.key = key
self.val = val
class Tree:
@ZoeyYoung
ZoeyYoung / gcd.py
Created June 6, 2013 06:24
最大公约数
def gcd(i, j):
while i != 0:
if j >= i:
j -= i
else:
i, j = j, i
return j
i = int(raw_input("i:"))
j = int(raw_input("j:"))
@ZoeyYoung
ZoeyYoung / timeit.py
Created June 6, 2013 08:01
use timeit
import timeit
from functools import partial
t1 = timeit.Timer(partial([func, *args])).timeit(1)
print(t1)
'''
From Python Algorithms - Mastering Basic Algorithms in the Python Language Book
'''
def partition(seq):
pi, seq = seq[0], seq[1:] # Pick and remove the pivot
lo = [x for x in seq if x <= pi] # All the small elements
hi = [x for x in seq if x > pi] # All the large ones
return lo, pi, hi # pi is "in the right place"