This file contains hidden or 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/env python | |
# coding: utf-8 | |
""" | |
domain.py | |
简单的whois客户端,可用于判断域名是否被注册 | |
python domain.py [num] # num为字母组合的个数(1,8) | |
""" | |
import urllib, re, os, sys |
This file contains hidden or 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 | |
def timer(func): | |
def newFunc(*pargs, **kargs): | |
start = time.time() | |
back = func(*pargs, **kargs) | |
print "Timer: %.2fs" % (time.time()-start) | |
return back | |
return newFunc |
This file contains hidden or 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/env python | |
# coding: utf-8 | |
# 最大公约数 | |
#欧几里德算法又称辗转相除法,用于计算两个整数m, n的最大公约数。其计算原理依赖于下面的定理: | |
# gcd(m, n) = gcd(n, m mod n) | |
#这个定理的意思是:整数m、n的最大公约数等于n和m除以n的余数的最大公约数。 | |
def gcd(m, n): | |
while n: | |
m, n = n, m % n |
This file contains hidden or 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
cd C:\Users\Calvin | |
set nocompatible | |
source $VIMRUNTIME/vimrc_example.vim | |
source $VIMRUNTIME/mswin.vim | |
behave mswin | |
set diffexpr=MyDiff() | |
function MyDiff() | |
let opt = '-a --binary ' | |
if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif |
This file contains hidden or 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
public class ProducerConsumer { | |
public static final int N = 100; //define the buffer | |
static Producer producer = new Producer(); //init a new producer thread | |
static Consumer consumer = new Consumer(); //init a new consumer thread | |
static Monitor monitor = new Monitor(); //init a new monitor | |
public static void main(String args[]) { | |
producer.start(); | |
consumer.start(); | |
} |
This file contains hidden or 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 java.util.*; | |
import static com.mceiba.util.Print.*; | |
class Enums{ | |
public static <T extends Enum<T>> T random(Class<T> type){ | |
Random rand = new Random(); | |
return type.getEnumConstants()[rand.nextInt(type.getEnumConstants().length)]; | |
} | |
} | |
class Mail { | |
// The NO's lower the probability of random selection: |
This file contains hidden or 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 static com.mceiba.util.Print.*; | |
import java.util.*; | |
interface Command { void action(); } | |
enum Signal { RED, YELLOW, GREEN } | |
public class Commands{ | |
public static void main(String[] args){ | |
EnumMap<Signal, Command> em = new EnumMap<Signal, Command>(Signal.class); | |
em.put(Signal.RED, new Command(){ | |
public void action() { println("stop"); } |
This file contains hidden or 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 static com.mceiba.util.Print.*; | |
import java.lang.reflect.*; | |
import java.lang.reflect.Proxy; | |
interface Something{ | |
void doSomething(); | |
void somethingElse(String arg); | |
} | |
class RealObjects implements Something{ | |
public void doSomething() { println("doSomething"); } |
This file contains hidden or 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 static com.mceiba.util.Print.*; | |
interface Interface{ | |
void doSomething(); | |
void somethingElse(String arg); | |
} | |
class RealObject implements Interface{ | |
public void doSomething() { println("doSomething"); } | |
public void somethingElse(String arg) { println("somethingElse "+arg); } | |
} |