Skip to content

Instantly share code, notes, and snippets.

@IceskYsl
IceskYsl / 2statusespublic timeline
Created February 25, 2012 13:00
返回最新的公共微博
{ "hasvisible" : false,
"next_cursor" : 0,
"previous_cursor" : 0,
"statuses" : [ { "comments_count" : 0,
"created_at" : "Sat Feb 25 20:38:04 +0800 2012",
"favorited" : false,
"geo" : null,
"id" : 3417057616355950,
"idstr" : "3417057616355950",
"in_reply_to_screen_name" : "",
@IceskYsl
IceskYsl / reg_is_string.rb
Created January 31, 2012 05:56
判断一个字符串只有英文,数字和冒号的正则
STR_REGEXP = /[a-zA-Z0-9:]/
str = "iceskysl...balalal"
if str =~ UNICODE_STR_DLD_REGEXP
puts "==bad str: #{str}"
else
puts "ok......pass"
end
# Taken from passenger_memory_stats script
# Returns the private dirty RSS for the given process, in KB.
def determine_private_dirty_rss(pid)
total = 0
File.read("/proc/#{pid}/smaps").split("\n").each do |line|
line =~ /^(Private)_Dirty: +(\d+)/
if $2
total += $2.to_i
end
@IceskYsl
IceskYsl / sphinx.yml
Created September 20, 2011 10:07 — forked from dchentech/sphinx.yml
sphinx in chinese setup
production:
listen: 0.0.0.0:9312
address: 0.0.0.0 # 对应的安装了searchd(sphinx)的mysql服务器ip
port: 9312 # 对应的安装了searchd(sphinx)的mysql服务器端口
bin_path: '/usr/local/bin'
searchd_file_path: '/data/sphinx/production'
query_log_file: '/data/sphinx/log/searchd.query.log'
searchd_log_file: '/data/sphinx/log/searchd.log'
exceptions: '/data/sphinx/log//exception.log'
enable_star: true # 支持通配符匹配
require "rubygems"
require "date"
start_d = Date.parse( '2010-01-01' )
end_d = Date.today - 1
start_d.step(end_d , step=1){|d|
puts d
}
@IceskYsl
IceskYsl / nginx config file
Created January 13, 2011 02:18
nginx config file for static files
location ~* ^.+\.(jpg|jpeg|gif|png|bmp|ico|css|js|swf|lrc)$ {
access_log off;
expires 30d;
}
location ~* ^.+\.(mp3|wma|rar|zip|flv)$ {
expires 30d;
}
location ~* ^.+\.(htm|html|xml)$ {
@IceskYsl
IceskYsl / ip2int
Created December 20, 2010 17:29
When storing IP in a database, it’s much better to store them as integers rather than VARCHAR(15). Here’s a handy function to convert an IP string to integer and back.
# Converts an IP string to integer
def ip2int(ip)
return 0 unless ip =~ /d{1,3}.d{1,3}.d{1,3}.d{1,3}/
v = ip.split('.').collect { |i| i.to_i }
return (v[0] << 24) | (v[1] << 16) | (v[2] << 8 ) | (v[3]);
end
#!/bin/sh
svn remove log/*
svn commit -m"removing log files"
svn propset svn:ignore "*.log" log/
svn update log/
svn commit -m 'Ignoring all files in /log/ ending in .log'
svn move config/database.yml config/database.example
svn commit -m 'Moving database.yml to database.example to provide a template for anyone who checks out the code'
svn propset svn:ignore "database.yml" config/
svn update config/
%w("en", "en_US", "_US", "en__POSIX", "en_US_POSIX", "zh-rCN" , "zh-r").each do |locale|
puts locale
if(locale =~ /^([^-_]+)[-_]?r?([^-_]+)?[-_]?([^-_]+?)$/)
puts "$1=#{$1},$2=#{$2},$3=#{$3}"
end
end
output
"en",
$1="en",$2=,$3=,
<eoe status="true">
<jokes>
<page>1</page> //当前请求的页数
<per_page>20</per_page> //当前请求页中的条数
<totle_page>1</totle_page> //总页数
<total_entries>2</total_entries> //总数
<list> //笑话列表
<joke> //笑话
<id>2</id> //编号
<title>这个字段是笑话的标题</title> //笑话标题