Skip to content

Instantly share code, notes, and snippets.

@zernel
zernel / 360buy.rb
Created October 23, 2012 15:55 — forked from mimosz/.gitignore
京东商品价格解析
# -*- encoding: utf-8 -*-
require 'mini_magick'
require 'rtesseract'
require 'nokogiri'
require 'nestful'
require 'csv'
require 'pp'
class Buy360
def initialize(url='')
@zernel
zernel / copsy.org.config
Created October 22, 2012 08:57 — forked from ouyangzhiping/copsy.org.config
nginx配置php站点示范
server {
server_name localhost www.copsy.org copsy.org;
access_log /srv/www/copsy.org/logs/access.log;
error_log /srv/www/copsy.org/logs/error.log;
root /srv/www/copsy.org/public_html;
location / {
index index.html index.htm index.php;
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
@zernel
zernel / smser.rb
Created October 20, 2012 10:32 — forked from mimosz/smser.rb
短信宝
# -*- encoding: utf-8 -*-
require 'digest/md5'
require 'nestful'
class Smsbao
def initialize(login, passwd)
@login = login
@passwd = Digest::MD5.hexdigest(passwd.to_s)
end
@zernel
zernel / gist:3807297
Created September 30, 2012 16:12
Ruby 异常处理
begin #开始
raise.. #抛出异常
rescue [ExceptionType = StandardException] #捕获指定类型的异常 缺省值是StandardException
$! #表示异常信息
$@ #表示异常出现的代码位置
else #其余异常
..
ensure #不管有没有异常,进入该代码块
@zernel
zernel / init git repos
Created September 26, 2012 07:11
Git tips
1 服务器上:
2 git init --bare --shared reggin.git
3 本地:
4 git remote add origin [email protected]:/home/dev/repos/xxxx.git
@zernel
zernel / apache2
Created September 20, 2012 04:35
nginx/apache2 裸域名跳转
<VirtualHost *:80>
ServerName anderweb.ca
RewriteEngine on
RewriteRule ^(.*)$ http://www.anderweb.ca$1 [R=301,L]
</VirtualHost>
@zernel
zernel / gist:3749856
Created September 19, 2012 14:03
Logger
file = File.join(Rails.root, 'log/markdown.log')
File.new(file, 'w+') unless File.exist?(file)
logger = Logger.new(file)
logger.info("#{Time.now}: Share##{_id}'s price is from #{latest_price} to #{new_price}")
logger.close
@zernel
zernel / gist:3720010
Created September 14, 2012 05:40
Backup the database
导出数据库pg_dump -Fc mydb > db_name.dump
导入数据库 pg_restore -d mydb db_name.dump
导出 pg_dump mydb > db_name.sql
表导出 pg_dump database -t table > table.sql
加上' -a '可只到导出表内容,不导出表结构
@zernel
zernel / flash.html.erb
Created August 27, 2012 03:08
Flash List Tips
<% flash.each do |name, msg| %>
<div class="alert alert-<%= name == :notice ? "success" : "error" %>">
<a class="close" data-dismiss="alert">×</a>
<%= msg %>
</div>
<% end %>
@zernel
zernel / gist:3444718
Created August 24, 2012 02:06
OmniAuth Google OAuth2 strategy – where to get Google Key and Secret
* Go to https://code.google.com/apis/console, log in with your Google account and click on API Access.
* Create OAuth2 credentials by clicking the big blue OAuth2 button.
* Set the callback url and the name of your app (can be edited later)
* The Google Key (as it is referred to by OmniAuth) is the Client ID
* The Google Secret (as it is referred to by OmniAuth) is the Client Secret
* Use those credentials as per your documentation for implementing OAuth2 authentication.
The Google OmniAuth strategy for OAuth2 is here: https://github.com/zquestz/omniauth-google-oauth2. Look in the examples folder for details on the rest of the implementation.