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| |
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
# using memcache | |
memcached -d -m 1024 -l 0.0.0.0 -p 11211 | |
cached_obj = Memcache.new('localhost:11211', :readonly => true) | |
cached_obj.request_timeout = 10 | |
cached_obj = Memcache.new('localhost:11211', "mem2.example.com:11211") | |
zoo = Memcache.new("localhost:11211") | |
zoo[:donkeys] = ["siva","siva","siva"*4] |
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
task :default => :test | |
task :test do | |
ruby "tests/test1.rb" | |
ruby "tests/test2.rb" | |
end | |
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
# attempting to present data without thought as to the analysis often gives rise to | |
# presentations that are nothing more than stylish gloss on a stinky foundation. | |
# 其实这一章没有太多好用的类库介绍,基本是使用。ruby的使用 | |
# 回去可以整理下。 | |
# Listing 9-8. Storing the Array of Logins in a Timestamped File for Later Retrieval | |
require "fileutils" | |
require "remote_host" |
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 "socket" | |
socket = TCPSocket.open("www.theonion.com", "80") | |
TCPSocket.open("www.theonion.com", 80) do |socket| | |
socket.puts "GET / HTTP/1.0\n\n" | |
puts socket.read | |
end |
OlderNewer