Skip to content

Instantly share code, notes, and snippets.

View atupal's full-sized avatar

kangle yu atupal

View GitHub Profile
@atupal
atupal / select_input.py
Created June 26, 2013 06:36
Keyboard input with timeout in Python
import sys, select
print "You have ten seconds to answer!"
i, o, e = select.select( [sys.stdin], [], [], 10 )
if (i):
print "You said", sys.stdin.readline().strip()
else:
print "You said nothing!"
@atupal
atupal / msvcrt_input.py
Created June 26, 2013 06:31
python set time limit on input
import msvcrt
import time
def raw_input_with_timeout(prompt, timeout=30.0):
finishat = time.time() + timeout
result = []
while True:
if msvcrt.kbhit():
result.append(msvcrt.getche())
if result[-1] == '\r': # or \n, whatever Win returns;-)
@atupal
atupal / xrun.sh
Created May 16, 2013 04:25
打开一个新的X
#!/bin/bash
#xinit appname -- :10
# calculate first available VT
LVT=`fgconsole --next-available`
# calculate first usable display
XNUM="-1"
SOCK="something"
while [ ! -z "$SOCK" ]
@atupal
atupal / 神写的kmp.cpp
Created April 15, 2013 05:35
字符串树上的kmp,dfs
#pragma comment (linker, "/STACK:100000000")
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
#define N 101000
char s[3*N];
int p[3*N], l, r;
vector <int> m[N];
string w[N];
/*
网络流 之 最大流 增广路算法 http://blog.163.com/art_budder_niu/blog/static/1393646202010322115138703/
FF算法:分为三个步骤,首先寻找一条增广路(如果没有增广路,则返回最大流),同时保存路径;其次,对路径上的流量求最小值,记为min;最后根据路径修改网络,对于前向边,减去最小值,对于后向边,加上最小值,或者直接修改容量。
增广路:从源点s到汇点t的一条有向路径,如果从源点开始不可以到汇点,那么没有增广路。
保存:用一个数组保存,一般是采用父亲表示法(父链接),保存当前节点的父亲, 寻找的时候采用的是迭代的方式实现求最小值以及修改原网络。
寻找增广路,采用bfs的方式。详细算法如下:
*/
//source here
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <queue>
using namespace std;
const int N = 210;
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
const int maxn = 50001;
int n;
double x[maxn];
double y[maxn];
import Queue
import threading
import urllib2
import time
from BeautifulSoup import BeautifulSoup
hosts = ["http://yahoo.com", "http://google.com", "http://amazon.com",
"http://ibm.com", "http://apple.com"]
/**
* Optimized Code For Quantizing Colors to xterm256
*
* These functions are equivalent to the ones found in xterm256.py but
* orders of a magnitude faster and should compile quickly (fractions
* of a second) on most systems with very little risk of
* complications.
*
* Color quantization is very complex. This works by treating RGB
* values as 3D euclidean space and brute-force searching for the