Skip to content

Instantly share code, notes, and snippets.

@snowleung
snowleung / cs_url.py
Last active April 11, 2016 10:12
CS URL
'''
struct is ["url", "introduction"]
'''
cs_site=[
"http://composingprograms.com", "Welcome to Composing Programs, a free online introduction to programming and computer science.",
]
unittest_site = [
"http://stackoverflow.com/questions/155436/unit-test-naming-best-practices", " [UnitOfWork_StateUnderTest_ExpectedBehavior]",
]
python_site = [
@snowleung
snowleung / sources.list
Last active January 1, 2016 08:03
ubuntu14.04 164 source
deb http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse
@snowleung
snowleung / auto_assert_dict_value
Last active December 25, 2015 07:12
auto_assert_dict_value
def dict_to_assert(dict_name, d):
template = '''self.assertEqual({}['{}'], {})'''.format(dict_name, '{}', '{}')
for k,v in d.items():
try:
assert_line = template.format(k, v)
except Exception as ex:
assert_line = template.format(k, ex)
print assert_line
@snowleung
snowleung / validators.py
Last active November 24, 2015 02:26
django form validators
# coding:utf-8
from django import forms
from django.core.validators import RegexValidator
from datetime import datetime
import re
def only_character_number_underline(value):
RegexValidator(regex=r'^[A-Za-z0-9_]+$', message='only number, A-Z, a-z, _')(value)
@snowleung
snowleung / render_format.py
Created October 21, 2015 02:12
for api error code format
def render_format(kv):
k = kv[0]
v = kv[1]
with_span = lambda: '{}{}'.format(v[1], ' '*(48-len(v[1])))
return '| {} | {} | {}|'.format(v[0], k, with_span())
@snowleung
snowleung / parameters.el
Created September 14, 2015 14:08
try to make skeleton
(defun gg-input (li)
;;(setq v2 '())
(setq li (split-string li ","))
(setq format-str
(mapcar
(lambda (f) (format "\n:param %s: %s" f f))
li))
(require 'cl-lib)
(prin1-to-string format-str)
# coding:utf-8
'''
Aggregation of datapoints
~~~~~~~~~~~~~~~~~~~~~~~~~
对数据点得值进行聚合运算, 包括【sum, avg, max, min】
'''
import json
# coding:utf-8
'''
Aggregation of datapoints
~~~~~~~~~~~~~~~~~~~~~~~~~
对数据点得值进行聚合运算, 包括【sum, avg, max, min】
'''
import json
@snowleung
snowleung / .emacs
Created January 6, 2015 09:36
my .emacs
(add-to-list 'load-path "~/.emacs.d/plugins/")
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories "~/.emacs.d/plugins//ac-dict")
(ac-config-default)
(global-linum-mode 1)
(add-to-list 'load-path
"~/.emacs.d/plugins/yasnippet")
#coding:utf-8
import logging
import json
from datetime import datetime, timedelta
import time
import random
USE_MONGO = True