Skip to content

Instantly share code, notes, and snippets.

View hooopo's full-sized avatar
🍏
I may be slow to respond.

Hooopo hooopo

🍏
I may be slow to respond.
View GitHub Profile
#从纯真IP数据库里查询
def search_ip_cz(ip)
#IP数据文件路径
#ip='202.38.64.10'
dat_path = "QQWry.Dat"
#检查IP地址
# if not ip~=/^d{1,3}.d{1,3}.d{1,3}.d{1,3}$/
# return 'IP Address Error'
require 'find'
puts "input your dir:"
dir = gets.chomp
puts "input your pattern:"
pattern = gets.chomp
Find.find(dir) do |file|
puts file if File.file?(file) && File.basename(file) =~/#{pattern}/
class Stack
def initialize
@store = []
end
def push(x)
@store.push x
end
def age
years = Date.today.year - birth.year
years + (Date.today < birth + years.year ? -1 : 0)
end
>> require 'htmlentities'
=> []
>> coder = HTMLEntities.new
=> #<HTMLEntities:0x4903770 @flavor="xhtml1">
=> "http://xx.com/&#x5e97;&#x94fa;&#x7ba1;&#x7406;&#x9996;&#x9875;.aspx"75;.asp"
>> coder.decode(_).to_cn
http://xx.com/店铺管理首页.aspx
#utf-8
def encode(str)
keys = "abcdefghijklmnopqrstuvwxyz234567"
str.unpack("C*").map{|b| "%08b" % b}.join.scan(/\d{1,5}/).map{|x| "0" * 3 + x.ljust(5,"0")}.map{|y| keys[y.to_i(2)].chr}.join
end
p encode "aaa" #=> "mfqwc"
p encode "JavaEye论坛频道" #=>"jjqxmykfpfs6rlv24wozx2ncshuydey"
=begin
<span class="next">
<a href="/group/douban_radio/discussion?start=525">后页></a>
</span>
http://www.douban.com/group/douban_radio/discussion?start=0
=end
require 'open-uri'
require 'hpricot'
module Douban
require 'rubygems'
require 'hpricot'
require 'open-uri'
require 'iconv'
url = "http://www.douban.com/group/yly/discussion?start="
(11..60).each do |i|
sleep 1
html = open(url + i.to_s)
doc = Hpricot.parse html
names = doc.search("div.article//tr/td[2]/a/*")
@hooopo
hooopo / gist:758391
Created December 29, 2010 10:14 — forked from xdite/gist:758319

Rails 開發注意要點

About Ruby Syntax

  • 編輯器設定 soft tab (space=2),以 2 格空白符號做為程式內縮距離(不分語言)。
  • 函式如果只有一個參數,就不強制打()
  • 函式如果有二個以上的參數,通通都要有 ()
    • (避免發生奇怪的paser bug跟保持專案一致性)
  • 字串限定用雙引號包覆
  • 善用 "#{str1} #{str3} " 等字串改寫技巧取代不需要的字串加法。