This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#encoding: utf-8 | |
# https://github.com/tomykaira/clockwork | |
# Usage: | |
# clockwork workers/clock_worker.rb & or | |
# clockworkd -c workers/clock_worker.rb run | |
require 'clockwork' | |
require File.expand_path('../../config/boot', __FILE__) | |
ENV['RACK_ENV'] = 'test' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'csv' | |
task :token do | |
require "./config/boot.rb" | |
res_file = File.new("db/token.txt","w+") # create res file | |
CSV.foreach("db/token.csv") do |row| | |
access_token = row.split(';')[0] # get first element | |
oauth_token = OauthToken.first(:access_token => access_token) | |
if oauth_token | |
client_id = oauth_token.client_id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def slug(length=10) | |
chars = ('A'..'Z').to_a + ('a'..'z').to_a + (0..9).to_a | |
chars.sample(length).join | |
end | |
#usage: | |
slug | |
=> "x5ZlWb4Ymf" | |
slug(6) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
module Setting | |
class << self | |
@@hashes = {} | |
# environments: development, test and production. | |
def environments() | |
%w[test production development] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# list | |
get '/' do | |
list = Dir.glob("./files/*.*").map{|f| f.split('/').last} | |
# render list here | |
end | |
# upload | |
post '/' do | |
tempfile = params['file'][:tempfile] | |
filename = params['file'][:filename] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'pony' | |
mails = {:to=>"[email protected]", | |
:subject=>"问答箱子找回密码", | |
:from=>"[email protected]", | |
:html_body=>"html body", | |
:via=>"smtp", | |
:via_options=>{ | |
:address => 'smtp.exmail.qq.com', | |
:port => '25', | |
:user_name => '[email protected]', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "rubygems" | |
require "bundler/setup" | |
require "stringex" | |
## -- Rsync Deploy config -- ## | |
# Be sure your public key is listed in your server's ~/.ssh/authorized_keys file | |
ssh_user = "[email protected]" | |
ssh_port = "22" | |
document_root = "~/website.com/" | |
rsync_delete = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#(1) 把timestamp和token联合; | |
# (2) 使用HMAC算法得到加密字符串(将appkey作为参数并使用SHA256 哈希方法); | |
# (3) 比较signature和得到的加密字符串。 | |
timestamp = "1398236282767" | |
token = "THd78OwTxVGjTgCYSOxr4vkCPj3oIUg1TpZgkYpjerT2zNWdPQ" | |
signature = "df5fc888e86c8032f0c6b56e91ab91ebdfdae297e7a1dd4983e2e091042c151e" | |
data = timestamp + token | |
appkey = 'bl92t6tw-55zn-h14y-uzpd-y52k7jqe5s' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nletter = "...whatever..." | |
Newsletter.all.each do |user| | |
Mailer.deliver_letter(nletter, user) | |
end | |
# And your mailer function would look like: | |
def letter(nletter, user) | |
@nletter = nletter | |
mail(:to => user.email, :subject => @nletter.subject) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 在本地服务器建立 rubygems.org 的镜像缓存,以提高 gem 的安装速度 | |
# 此配置设置缓存过期为1天,也就是说,新上的 gem 无法马上安装 | |
# 做这个起什么作用? | |
# rubygems 的很多资源文件是存放到 Amazon S3 上面的,由于 GFW 对某些 S3 服务器又连接重置或丢包,导致 gem 安装异常缓慢或有时候根本无法连接安装。 | |
# 而通过这种跳板的方式可以很好的解决这个问题,当然前提是 Nginx反向代理 服务器需要在国外 | |
proxy_cache_path /var/cache/rubygems levels=1:2 keys_zone=RUBYGEMS:10m | |
inactive=24h max_size=1g; | |
server { | |
listen 80; |