Skip to content

Instantly share code, notes, and snippets.

View vayn's full-sized avatar

Vayne Tsai vayn

View GitHub Profile
@vayn
vayn / sieve_of_eratosthenes.php
Created May 22, 2010 07:45
sieve_of_eratosthenes
<?php
define('MAX_NUM', 1000000);
$all = array_fill(0, MAX_NUM, 0);
$i = 2;
if ($all[$i] == 0) {
echo $i . "\n"; //测试性能时去掉这行。输出会占据大部分时间。
for ($j = $i; $j < MAX_NUM; $j+=$i) {
$all[$j] = 1;
@vayn
vayn / no-displayed-link-in-status-bar.js
Created October 12, 2010 09:44
no-displayed-link-in-status-bar
@vayn
vayn / gist:638342
Created October 21, 2010 11:42
Readability
javascript:(function(){readConvertLinksToFootnotes=false;readStyle='style-novel';readSize='size-medium';readMargin='margin-wide';_readability_script=document.createElement('script');_readability_script.type='text/javascript';_readability_script.src='http://lab.arc90.com/experiments/readability/js/readability.js?x='+(Math.random());document.documentElement.appendChild(_readability_script);_readability_css=document.createElement('link');_readability_css.rel='stylesheet';_readability_css.href='http://lab.arc90.com/experiments/readability/css/readability.css';_readability_css.type='text/css';_readability_css.media='all';document.documentElement.appendChild(_readability_css);_readability_print_css=document.createElement('link');_readability_print_css.rel='stylesheet';_readability_print_css.href='http://lab.arc90.com/experiments/readability/css/readability-print.css';_readability_print_css.media='print';_readability_print_css.type='text/css';document.getElementsByTagName('head')[0].appendChild(_readability_print_cs
@vayn
vayn / attr.title.to.textNode.js
Created October 23, 2010 00:51
theoutlookmagazine.com navBar
sfHover = function() {
var sfEl = document.getElementById("menu");
if(sfEl){
var sfEls = document.getElementById("menu").getElementsByTagName("LI");
for (var i=0; i<sfEls.length; i++) {
sfEls[i].onmouseover=function() {
this.className+=" sfhover";
}
sfEls[i].onmouseout=function() {
this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
@vayn
vayn / eightqueen.py
Created November 3, 2010 07:42
八皇后 Eight Queens Python
# -*- coding:utf-8 -*-
u'''cdays-3-exercise-3.py
@note: 使用全局变量和函式的递归调用
'''
global col # 竖直线(列线),用于记录列线冲突状态
global row # 行号,本代码是逐行放置的,这里的row是可以当做do_queen函数的参数的。
global pos_diag # 右对角线,用于记录右对角线冲突,拿笔画画就知道有15条左对角线了
global nag_diag # 左对角线,用于记录左对角线冲突状态,同样也有15条右对角线
@vayn
vayn / parallax.js
Created November 4, 2010 12:01
利用视差制造从空中鸟瞰效果的背景
/*
* view-source:http://www.rowtothepole.com/
*
* <body id="home" class="js-disabled section-">
* <div id="outer">
* </body>
*
* style.css
* body {
* background: #1a2732 url(/release/images/inverted/layout/body-bg.jpg) repeat-y center top;
@vayn
vayn / wise.py
Created November 8, 2010 13:44
排序并选出最大的乘法组合
# 想的我快吐血~~~
# http://wiki.woodpecker.org.cn/moin/AllStartFromGame
def solve(seq,where):
n = len(seq)
seq.sort()
seq.reverse()
table = [ [] for i in range(n) ]
left, right = where, n - where
leftr = long('1'*left)
rightr = long('1'*right)
@vayn
vayn / Karrigell.rc.sh
Created December 12, 2010 08:19
让Karrigell作为服务运行
#!/bin/sh
## runK.sh
## 先进入对应目录 cd /path/to/Karrigell
## 使用 daemon 命令来包裹并记录 Karrigell 的运行 pid
/usr/sbin/daemon -p /var/run/karrigell.pid /usr/local/bin/python Karrigell.py 2>/var/log/K.log &
#!/bin/sh
#
# rcNG
@vayn
vayn / shanzhai_wordpad.sh
Created March 28, 2011 11:07
命令行字典外加保存到在线生词本
# .bashrc
function vasa {
if [ ! "$*" ]; then
echo 'Oops, I need food!'
return 1
fi
gougou $*
echo "$* #vasa" | bti
}
#!/usr/bin/env python
# vim:fileencoding=utf-8
# @Author: Vayn a.k.a. VT <vayn@vayn.de>
# @Name: a.py
# @Date: 2011年04月04日 星期一 13时24分03秒
input = raw_input('Please type:')
data = input.split()
price = 200