Skip to content

Instantly share code, notes, and snippets.

View huobazi's full-sized avatar
🎯
Focusing

Marble Wu huobazi

🎯
Focusing
View GitHub Profile
# RSS采集并自动发帖到某网站
require 'mechanize'
require 'simple-rss'
puts "loading exists guid list..."
# 读取已存在的guids
old_guids = []
guid_file = File.open('guids.dat',"a+")
guid_file.each_line { |line| old_guids << line.gsub("\n",'') }
@huobazi
huobazi / bottom_pop_window.js
Created May 16, 2011 02:55 — forked from huacnlee/bottom_pop_window.js
页面底部弹窗广告
// 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(){
@huobazi
huobazi / import_file_to_gridfs.rake
Created May 16, 2011 02:56 — forked from huacnlee/import_file_to_gridfs.rake
将 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'
@huobazi
huobazi / safe_login.rb
Created May 16, 2011 02:57 — forked from huacnlee/safe_login.rb
去掉字符里面的非法字符,用于处理用户名 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"
@huobazi
huobazi / coreseek_install.sh
Created May 16, 2011 02:57 — forked from huacnlee/coreseek_install.sh
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. 中文测试环境检查:
@huobazi
huobazi / spaceless.rb
Created May 16, 2011 02:57 — forked from huacnlee/spaceless.rb
去除区域里面的HTML内容的换行和空白标记
# 去除区域里面的HTML内容的换行和空白标记
def spaceless(&block)
data = with_output_buffer(&block)
data = data.gsub(/>\s+</,"><")
data
end
module StringExtensions
def remove_html_tags()
self.gsub(/<.+?>/, "")
end
# clear unsafe char with url slug
def safe_slug(spliter = '-')
@slug = self
if @slug.blank?
Guid.new
# Nginx Linux 下面创建为系统服务脚本
#!/bin/sh -e
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Deploy Rails on Ubuntu with shell
#!/bin/sh
echo "=== YTRIPTHIRD UBUNTU INSTALL ==="
cd /tmp
# Ruby
echo "=== Install Ruby library..."
sudo apt-get install g++ ruby1.8 rubygems rake irb ruby1.8-dev build-essential libopenssl-ruby libssl-dev imagemagick rdtool
echo "=== Ruby library install done."
class String
def remove_html_tags()
self.gsub(/<.+?>/, "")
end
# clear unsafe char with url slug
def safe_slug(spliter = '-')
@slug = self
if @slug.blank?
Guid.new