This file contains hidden or 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
puts 16.times.map { ('!'..'~').to_a.sample }.join |
This file contains hidden or 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 'rack/reverse_proxy' | |
require 'sinatra' | |
use Rack::ReverseProxy do | |
reverse_proxy /^.*$/, 'http://api.secipin.com/guide/products.json?per=1' | |
end |
This file contains hidden or 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
zh-CN: | |
errors: | |
messages: | |
invalid_date: "是无效的日期" | |
invalid_time: "是无效的时间" | |
invalid_datetime: "是无效的时间" | |
is_at: "必须在 %{restriction}" | |
before: "必须早于 %{restriction}" | |
on_or_before: "必须在或早于 %{restriction}" | |
after: "必须晚于 %{restriction}" |
This file contains hidden or 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
class Game2048 | |
def initialize | |
@array = 4.times.map { [ nil ] * 4 } | |
2.times { fill } | |
end | |
def fill | |
i, j = rand(4), rand(4) | |
return fill if @array[i][j] | |
@array[i][j] = [2, 2, 2, 2, 4].shuffle.first |
This file contains hidden or 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
gzip on; | |
gzip_comp_level 9; | |
gzip_min_length 1024; | |
gzip_buffers 4 8k; | |
gzip_types application/javascript application/json application/x-javascript application/xml text/css text/csv text/plain; | |
gzip_disable "MSIE [1-6]\."; |
This file contains hidden or 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
--- | |
pid: tmp/pids/thin.pid | |
wait: 30 | |
log: log/thin.log | |
timeout: 30 | |
max_conns: 1024 | |
port: 4000 | |
environment: production | |
chdir: /opt/project/ | |
max_persistent_conns: 512 |
This file contains hidden or 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
for i in `gem list --no-versions`; do gem uninstall -aIx $i; done |
This file contains hidden or 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
records = ActiveRecordClass.select().where().order().paginate() | |
# before | |
records.to_json | |
# after - with 1000% performance improvement | |
records.klass.connection.execute(records.to_sql).to_a.map { |record| [records.select_values, record].transpose.to_h } }.to_json |
This file contains hidden or 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 alipay_url(options) | |
options.merge!(seller_email: EMAIL, partner: ACCOUNT, _input_charset: 'utf-8') | |
options.merge!(sign_type: 'MD5', sign: Digest::MD5.hexdigest(options.sort_by(&:first).to_h.to_param + KEY)) | |
HTTParty.get("https://www.alipay.com/cooperate/gateway.do?#{options.sort.map{ |k, v| "#{CGI::escape(k.to_s)}=#{CGI::escape(v.to_s)}"}.join('&') }") | |
end |
This file contains hidden or 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
gem install sinatra # run once | |
ruby -e "require 'sinatra'; set :port, 80; set :environment, :production; set :public_folder, File.dirname(__FILE__)" |
NewerOlder