Skip to content

Instantly share code, notes, and snippets.

View vayn's full-sized avatar

Vayne Tsai vayn

View GitHub Profile
@vayn
vayn / prime_number.php
Created May 22, 2010 05:55
Prime Number
<?php
$sum = 2;
for ($i = 3; $i <= 10000; $i++) {
$k = 1;
for ($j = 2; $j < $i; $j++) {
if ($i % $j == 0) {
$k = 0;
@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 / prime_number_2.php
Created May 22, 2010 08:33
Prime_Number_2
<?php
$sum = 2;
for ($i = 3; $i < 10000; $i+=2) {
$flag = TRUE;
for ($j = 2; $j <= sqrt($i); $j++) {
if ($i % $j == 0) {
$flag = FALSE;
@vayn
vayn / oldschool.css
Created May 22, 2010 12:50
oldschool css
/* Design done by Arthur Steiner (c), the rest by Anne van Kesteren (c) */
@font-face { font-family:anneisawesome; src:url(/fonts/big-noodle-titling) }
html { margin:20px 30px; font:1em/1.5 Verdana, sans-serif; background:#46016a }
body { position:relative; margin:0 0 0 160px; padding:0 1em; border-left:10px solid #7e7a4c; min-width:200px; background:#c2c152 }
h1 { position:absolute; top:5px; left:-155px; margin:0; height:107px; width:282px; z-index:1; content:url(/img/logo) "Weblog 4.2"; font:2.6em/0.4 anneisawesome, Impact, sans-serif; text-indent:-4px }
p#tagline { margin:0; padding-top:5em; font-size:1.2em }
form#search { position:absolute; top:10px; right:20px; z-index:1 }
form#search input[type=search] { border:thin solid #000; vertical-align:top }
form#search input[type=search]:focus { outline:thick solid #000 }
form#search input[type=submit] { margin:2px 0 0; padding:0; border:none; float:right; display:block; content:url(/img/find); width:30px; cursor:pointer }
@vayn
vayn / array_filter.php
Created May 22, 2010 14:40
array_filter
<?php
function odd($var) {
return($var & 1);
}
function even($var) {
return(!($var & 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.php
Created November 3, 2010 07:41
八皇后 Eight Queens PHP
<?php
/*
* 八皇后问题是一个非常有趣的问题,是由德国大数学家高斯首先提出来的。
* 要求在国际象棋的棋盘上放置八个皇后,使她们不能互相攻击。
* 即任何两个皇后不能处在同一行、同一列、同一条斜线上。
*
* 问有多少种不同的摆法?并找出所有的摆法。
*
* 问题分析:
* (1) 满足上述条件的八个皇后,必然是每行一个,每列一个。
@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条右对角线