Skip to content

Instantly share code, notes, and snippets.

@ccc-larc
ccc-larc / gist:7717083
Created November 30, 2013 09:42
join v.s. +=
import timeit
#STRING = 'addddddeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeewweeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeffffffffffffffffffffffffffffffffffffffffffffffffffffffffeeeeeeeeeeeeeeeeeeeeeeeeeerwerwerwerwetrwegfsghklujsahdflkiuahfgluhewihrlwelfhlwuhfawhrgfiuhagrliwrwreqwerqwerwefsdfasdfasdfasdfdsfddddddddddddddddeeeeeeeewwwwwwwwwwwwwddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd'
STRING = 'sss'
LOOP = 1000000
TIMEIT_REPEAT = 30
def test_join():
data = []
@ccc-larc
ccc-larc / Hack!Python Tetris Visual
Created September 2, 2012 08:50
tetris-visual.py
# -*- coding=utf8 -*-
'''
* 參考 weijr 老師的 tetris in tkinter -- ``http://weijr-note.blogspot.tw/2007/04/tetris-program-in-lines.html``
* full documents of Vpython -- ``http://vpython.org/contents/docs/visual/index.html``
'''
# update: 2012.07.29 完成大部分功能
# update: 2012.09.01 加入暫停與 hjkl 方向鍵控制 (Vim 操作練習?!)
@ccc-larc
ccc-larc / tetris-tkinter.py
Created September 1, 2012 16:28
Hack!Python Tetris (CCC ver.)
# -*- coding: utf-8 -*-
import copy
import random
import sys
import Tkinter
#===============================================================================
# global constant
#===============================================================================
BOARD_WIDTH = 10
@ccc-larc
ccc-larc / tetris-tkinter.py
Created August 26, 2012 07:40 — forked from anonymous/tetris-tkinter.py
Hack!Python Tetris
# -*- coding=utf8 -*-
import sys,random
from Tkinter import *
score,bw,bh,H,W=0,10,20,30,30
blk = {0xf:"red",0x2e:"#0f0",0x27:"blue",0x47:"#ff0",0x66:"#0ff",0xC6:"#38f",0x6C:"#f0f"}
board = [ [0xf if j==bh else 0]*bw+[0xf]*2 for j in range(bh+2+1) ]
new_piece = lambda pc: ( [((z>>2)+1,z&3) for z in range(16) if (pc>>z)&1], 3, -2, pc )
collide=lambda piece,px,py: [1 for (i,j) in piece if board[j+py][i+px]] #是否碰撞
piece, px, py, pc = new_piece(random.choice(blk.keys())) # 第一個piece
def tick(e=None):