Skip to content

Instantly share code, notes, and snippets.

<!doctype html>
<html lang="en">
<head>
<title>JavaScript 模式和反模式</title>
<meta charset="utf-8">
</head>
<body>
<script>
/* 题目: 窗口滚动事件
* 描述: 不要在窗口滚动事件上附加事件处理程序
<!doctype html>
<html lang="en">
<head>
<title>JavaScript 模式和反模式</title>
<meta charset="utf-8">
</head>
<body>
<script>
/* 题目: 重复查询
* 描述: 使用jQuery的链接,可以避免重复查询
@sivagao
sivagao / index.jade
Created April 30, 2014 03:43
A Pen by siva Gao.
div#da-slider.da-slider
each item in [1,2,3,4]
div.da-slide
h2 Warm Welcome
p When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane.
a.da-link Read More
.da-img
img(src='http://tympanus.net/Development/ParallaxContentSlider/images/1.png')
header.
@sivagao
sivagao / index.html
Last active August 29, 2015 14:04 — forked from minikomi/index.html
<!DOCTYPE html>
<meta charset="utf-8">
<body>
<script src="http://d3js.org/d3.v2.min.js?2.10.0"></script>
<script>
var width = 960,
height = 700;
var svg = d3.select("body").append("svg")
@sivagao
sivagao / douban_lib_info_mashup_plugin.js
Created October 26, 2012 22:08
javascript , douban & lib info mashup , which use the chrome plugin's permissions to solve the cross origin(跨域问题)
function check() {
var a = location.href;
a = a.search("book.douban.com/subject");
if(a == -1) {
checkJun()
} else {
checkDouban()
}
}
function checkDouban() {
@sivagao
sivagao / Python strategy pattern.py
Created November 3, 2012 10:39
Python: strategy pattern + function2method using types.MethodType
# sivagao
# 2012年11月3日
class StrategyExample:
def __init__(self, func=None):
self.name = 'StrategyExample 0'
if func:
self.execute = types.MethodType(func, self)
def execute(self):
@sivagao
sivagao / microtemplate.js
Created November 5, 2012 14:06
micro template - quickly execute js in template string by john resing
// Simple JavaScript Templating
// John Resig - http://ejohn.org/ - MIT Licensed
(function(){
var cache = {};
this.tmpl = function tmpl(str, data){
// Figure out if we're getting a template, or if we need to
// load the template - and be sure to cache the result.
var fn = !/\W/.test(str) ?
cache[str] = cache[str] ||
@sivagao
sivagao / rake_learning.rb
Created November 7, 2012 01:41
learning Rake@Ruby
=begin
in our Rakefile, we create a file task entry named “passwd”.
This says the goal of this task is to create a file name “passwd”.
The contents of “passwd” depend on the contents of a file containing a list of our users. Let’s call this file “userlist”.
=end
file "passwd" => ["userlist"] do
pwds = read_passwords
users = read_users userlist
@sivagao
sivagao / using builder,GD,Dir to build file.rb
Created November 7, 2012 03:02
#practical ruby for system administrator practical ruby for system administrator #使用builder写xml(html), 使用GD生成图片,使用file.open 生成重复内容,Dir对系类文件操作
require "builder"
builder = Builder::XmlMarkup.new
page = builder.html do |html|
html.head { |head| head.title("Users") }
html.body { |body| body.a("bob", "href" => "b1") }
end
require "GD"
image = GD::Image.new(100, 100) # create an empty canvas, 100 pixels square
@sivagao
sivagao / using_file_safely_with_lock.rb
Created November 7, 2012 03:38
#practical ruby for system administrator #practical ruby for system administrator - 用聪明的方式构建文件 - 安全的使用文件,通过File::LOCK_EX,等
File.open("/tmp/foo", "w") do |f|
f.flock(File::LOCK_EX) # 取得互斥锁,如果未得,等待block,直到获取成功
f.puts "Locking is the key to ... pun interrupted"
f.flock(File::LOCK_UN)
end
File.open("/tmp/foo", "w") do |f|