This file contains 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
<!doctype html> | |
<html lang="en"> | |
<head> | |
<title>JavaScript 模式和反模式</title> | |
<meta charset="utf-8"> | |
</head> | |
<body> | |
<script> | |
/* 题目: 窗口滚动事件 | |
* 描述: 不要在窗口滚动事件上附加事件处理程序 |
This file contains 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
<!doctype html> | |
<html lang="en"> | |
<head> | |
<title>JavaScript 模式和反模式</title> | |
<meta charset="utf-8"> | |
</head> | |
<body> | |
<script> | |
/* 题目: 重复查询 | |
* 描述: 使用jQuery的链接,可以避免重复查询 |
This file contains 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
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. |
This file contains 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
<!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") |
This file contains 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
function check() { | |
var a = location.href; | |
a = a.search("book.douban.com/subject"); | |
if(a == -1) { | |
checkJun() | |
} else { | |
checkDouban() | |
} | |
} | |
function checkDouban() { |
This file contains 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
# 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): |
This file contains 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
// 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] || |
This file contains 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
=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 |
This file contains 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
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 |
This file contains 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
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| |
OlderNewer