Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
#-*-coding:utf-8-*-
d = {
1: ['a', 'b'],
2: ['b', 'c', 'd'],
3: ['b', 'c', 'e']
}
print reduce(lambda r, k: reduce(lambda s, i: r.__setitem__(i, r.get(i, 0) + 1), set(d[k]), False) or r, d, {})
.saaanYYTYnaaac.
_a/??+....:.....-.. -??<a/
_a)?=--......:.--:-:.:::::-:..?!a,
a?(... . . . ...:.:..--...-.-.:-:..)?a,
.u?:. .. . . . ...:.:.:.:.::--:.:.-.:-.:.?s,
_a?:... . . ....-:.:.:.:.:.:..--.:.:.:.-:.:..?\,
a7.. . ....:.-.:.--.:.:.-.:.:.:.:.-.:.:.--.:;:.4a
.a!.... ...--.----.-----.:.:.:..:.:.:.:.:.:.:.:.==:)a
J^- . ..-.:-.=aaaaaa.:.:.-:.aaaaaa.: :.:.-.:.:.::;=:+L
d(:.. :.:.:.a?' "5/-:a7" ?\/::.:.:.:.-.::;=:/$
@013231
013231 / placeholder.py
Created October 11, 2012 13:19
Create a placeholder picture.
#!/usr/bin/env python
from tornado.web import Application, RequestHandler
from tornado.ioloop import IOLoop
from PIL import Image, ImageDraw, ImageFont, ImageColor
import cStringIO
import re
fontPath = '/Library/Fonts/Arial.ttf'
port = 8080
@013231
013231 / iAny.py
Created September 24, 2012 07:49
def iAny(seq):
for item in seq:
if item:
return True
return False
allNum = range(1000*1000)
random.shuffle(allNum)
for promoCodeNeverRepeat in allNum:
doSomethingWith(promoCodeNeverRepeat)
def getCode():
result = allNum[getCode.usedNum]
getCode.usedNum += 1
return result
getCode.usedNum = 0
class Fruit(object):
Apple = 0
Pear = 1
Banana = 2
#________________________________
#/ 其它的一些定義, \
#\ 使Fruit類可以下標訪問. /
# --------------------------------
# \ ^__^
# \ (oo)\_______
#!/usr/bin/env python
import os
import shutil
count = 0
for filename in os.listdir('.'):
if filename.endswith('.txt') and os.path.isfile(filename):
destDir = 'AAA%d' % (count / 500 + 1)
#!/bin/sh
count=0
IFS=$'\n'
for filename in `find *.txt`
do
destDir="AAA$((count / 500 + 1))"
if (($count % 500 == 0 ))
then
echo mkdir $destDir
#!/usr/bin/env python
from flask import Flask
from time import sleep
application = Flask(__name__)
application.debug = True
@application.route('/a')
@application.route('/b')