Skip to content

Instantly share code, notes, and snippets.

View huacnlee's full-sized avatar

Jason Lee huacnlee

View GitHub Profile
@huacnlee
huacnlee / spaceless.rb
Created January 11, 2011 05:33
去除区域里面的HTML内容的换行和空白标记
# 去除区域里面的HTML内容的换行和空白标记
def spaceless(&block)
data = with_output_buffer(&block)
data = data.gsub(/>\s+</,"><")
data
end
@huacnlee
huacnlee / yupoo_backup.rb
Created January 28, 2011 07:37
Yupoo 图片备份工具
# coding: UTF-8
#
# Yupoo 照片备份工具
# 此工具不需要API,直接就能备份你的照片信息,下载后以图片 + 一个文本文件的方式存放
# 备份包括内容:
# 原图,标题,说明,Tag,当然有 Exif 信息
#
# Jason Lee <[email protected]>
# http://huacnlee.com
# 2011-01-28
require "thor/shell"
say("Modifying a new Rails app ...", :yellow)
#----------------------------------------------------------------------------
# Configure
#----------------------------------------------------------------------------
=begin
unless options[:database] == 'sqlite3'
username = ask("What's your database username[root]")
username = 'root' if username.blank?
@huacnlee
huacnlee / coreseek_install.sh
Created February 22, 2011 03:28
Coreseek for MySQL 数据源 安装教程
Coreseek (Sphinx) for MySQL 数据源 安装教程
1. 下载源代码
$ wget http://www.coreseek.cn/uploads/csft/3.2/coreseek-3.2.13.tar.gz
$ tar xzf coreseek-3.2.13.tar.gz
$ cd coreseek-3.2.13
2. 中文测试环境检查:
@huacnlee
huacnlee / safe_login.rb
Created February 23, 2011 15:21
去掉字符里面的非法字符,用于处理用户名 a-z 0-9 - _
def safe_login(str)
str.gsub(/[^a-z0-9\-_]/,'')
end
# Test
ruby-1.9.2-p0 > safe_login("asdlg1-24_1(*&(sdgsdg")
=> "asdlg1-24_1sdgsdg"
@huacnlee
huacnlee / import_file_to_gridfs.rake
Created February 25, 2011 09:26
将 File System 的上传文件导入到 Mongodb 的 GridFS 里面
# coding: UTF-8
#
# 以下为 Rake 任务,功能是将普通文件系统里面的东西转移到 MongoDB GridFS 里面
# 此代码片段来自于 Homeland 项目: https://github.com/huacnlee/homeland/tree/mysql
# 场景:
# 老架构 Linux File Store, Paperclip, hash 目录:"https://github.com/huacnlee/homeland/blob/ca0bdd8ab26da7b780e2dae7eba12b79f41e6d65/config/initializers/paperclip_hashpath.rb"
# 新架构 Mongodb GridFS, Garrierwave, 继续沿用 Paperclip 目录兼容: https://github.com/huacnlee/homeland/tree/7100ce4c506cc2c4387f25e50c533e5bbcac6cc2/app/uploaders
# 整个过程不会修改任何原始数据库和上传文件
#
require 'mongo'
@huacnlee
huacnlee / install-php.sh
Created March 8, 2011 03:13
Ubuntu 10.10 install PHP Apache2 from source
sudo apt-get install libjpeg8-dev libmysqlclient-dev
curl -O http://www.php.net/get/php-5.3.5.tar.gz/from/a/mirror
curl -O http://mirror.bjtu.edu.cn/apache//httpd/httpd-2.2.17.tar.gz
tar zxf httpd-2.2.17.tar.gz
cd httpd-2.2.17
./configure --prefix=/etc/apache2 --enable-so --enable-cgi --enable-info --enable-rewrite \
--enable-speling --enable-usertrack --enable-deflate --enable-ssl --enable-mime-magic \
--enable-dav --enable-vhost-alias --enable-proxy --enable-expires --enable-headers
make && sudo make install
@huacnlee
huacnlee / bottom_pop_window.js
Created March 11, 2011 03:40
页面底部弹窗广告
// jQuery need
setTimeout(showBTW, 1000);
function showBTW(){
$("body").append('<div class="bottom_pop_window">\
<div class="title">热门推荐<a href="#" onclick="return closeBTW();" class="close">关闭</a></div> \
<iframe src="/btw" frameborder="no"></iframe></div>');
$(".bottom_pop_window").css("bottom",-140).animate({ bottom : 10 });
}
function closeBTW(){
function FindProxyForURL(url, host) {
var socksResult = "SOCKS 127.0.0.1:7070";
if (shExpMatch(url, "*://*.scribd.com/*")) { return socksResult; }
if (shExpMatch(url, "*://scribd.com/*")) { return socksResult; }
if (shExpMatch(url, "*://goo.gl/*")) { return socksResult; }
if (shExpMatch(url, "*://feedproxy.google.com/*")) { return socksResult; }
if (shExpMatch(url, "*://*.googlecode.com/*")) { return socksResult; }
if (shExpMatch(url, "*://googlecode.com/*")) { return socksResult; }
if (shExpMatch(url, "*://*.youtube.com/*")) { return socksResult; }
if (shExpMatch(url, "*://youtube.com/*")) { return socksResult; }
@huacnlee
huacnlee / gist:1150933
Created August 17, 2011 06:33
redis-search 0.3 Benchmark, 用户昵称搜索(10个字以内)
redis-search 0.3 Benchmark
Core 2 Duo CPU 2.66G, 4G Memory
20W 数据
# coding: utf-8
require "benchmark"
["的","美丽","云","云儿","花","云儿的"].each do |key|