This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$stack, $draws = [], {} | |
def method_missing *args | |
return if args[0][/^to_/] | |
$stack << args.map { |a| a or $stack.pop } | |
$draws[$stack.pop(2)[0][0]] = args[1] if args[0] == :< | |
end | |
class Array | |
def +@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import unittest | |
GREATER, LESSER, EQUAL, NOT_COMPARABLE = 1, -1, 0, None | |
def compare(e1, e2): | |
order = e1.compare(e2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from threading import Thread | |
import hashlib | |
def async(gen): | |
def func(*args, **kwargs): | |
it = gen(*args, **kwargs) | |
result = it.next() | |
Thread(target=lambda: list(it)).start() | |
return result | |
return func |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* sendevent | |
* A Simple Wraper to Send XEvent | |
* usage: | |
* sendevent key|mouse [-modifier] name | |
* | |
* Start : 2010/3/6 | |
* Last : 2010/3/24 | |
* | |
* Copyright (c) 2010 Skydark Chen <skydark2 [at] gmail.com> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding:utf-8 -*- | |
'写了一个简单的支持中文的正向最大匹配的机械分词,其它不用解释了,就几十行代码' | |
'搜狗词库下载地址:http://vdisk.weibo.com/s/7RlE5' | |
import string | |
__dict = {} | |
def load_dict(dict_file='words.dic'): | |
'加载词库,把词库加载成一个key为首字符,value为相关词的列表的字典' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
class Timer(object): | |
def __init__(self, verbose=False): | |
self.verbose = verbose | |
def __enter__(self): | |
self.start = time.time() | |
return self |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A concurrent prime sieve | |
// via: http://golang.org/doc/play/sieve.go | |
package main | |
// Send the sequence 2, 3, 4, ... to channel 'ch'. | |
func Generate(ch chan<- int) { | |
for i := 2; ; i++ { | |
ch <- i // Send 'i' to channel 'ch'. | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################ Lispy: Scheme Interpreter in Python | |
## (c) Peter Norvig, 2010; See http://norvig.com/lispy.html | |
################ Symbol, Env classes | |
from __future__ import division | |
Symbol = str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# CLOSURES IN RUBY Paul Cantrell http://innig.net | |
# Email: username "cantrell", domain name "pobox.com" | |
# | |
# 翻译: kenshin54 http://kenbeit.com | |
# I recommend executing this file, then reading it alongside its output. | |
# 我强烈建议执行此脚本,然后根据它的输出来理解它。 | |
# | |
# Alteratively, you can give yourself a sort of Ruby test by deleting all the comments, | |
# then trying to guess the output of the code! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 这里提供 Lua 中实现 OO 的一种方案: | |
local _class={} | |
function class(super) | |
local class_type={} | |
class_type.ctor=false | |
class_type.super=super | |
class_type.new=function(...) | |
local obj={} |
NewerOlder