Skip to content

Instantly share code, notes, and snippets.

View sandyxu's full-sized avatar
Working from office

Sandy Xu sandyxu

Working from office
  • Shanghai, China
View GitHub Profile
@jhjguxin
jhjguxin / deploy.rb
Last active May 10, 2019 03:37
use qiniu to speed up your site asset file load time
set :linked_files, %W{
... config/app.god config/qrsync.json
config/application.yml
}
# you should remove bin from linked_dirs config
# https://github.com/capistrano/bundler/issues/45
set :linked_dirs, %w{config/unicorn log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
namespace :deploy do
@sandyxu
sandyxu / get_prime_numbers.rb
Last active August 29, 2015 14:09
素数算法比较,使用Benchmark进行测试。
require 'benchmark'
# 遍历N是否能被从2到sqrt(N)之间的素数整除。若不能则为素数
def fast(max)
mini = Math.sqrt(max).to_i
sub_primes = sub_primes(mini)
sub_primes + ((mini+1)..max).select{|n| sub_primes.all?{|obj| n % obj > 0 } }
end
def sub_primes(sub)
@rob-murray
rob-murray / commands.txt
Last active November 24, 2020 10:36
Testing Google Play In App Billing receipt validation.Commands to generate signature digest from receipt using private key; also validate signature using public key
#1 Generate Public & Private Keypair
#2 Create receipt.json - eg below - careful with line-endings, etc if line breaks
#3 Create signature & Encode
openssl dgst -binary -sha1 -sign private.pem receipt.json | openssl base64 > signature.txt
#4 Verify using OpenSSL & public key
openssl base64 -d -in signature.txt -out signature.sha1 | openssl dgst -sha1 -verify public.pem -signature signature.sha1 receipt.json
@nightire
nightire / Changes in Rails 4_1.md
Last active May 11, 2022 04:50
拥抱 Rails 4 —— 详述 Rails 4 的新变化

Routes

小心地使用 Match(Rails 3 已实现)

Rails 3 提供了 match 方法供我们自定义 routes,然而我们要小心使用它以避免“跨站脚本攻击”(XSS Attack)。比如像这样的 routes:

注:(r3 代表 Rails 3,r4 代表 Rails 4)

# routes.rb
@nightire
nightire / How to use Backbone.js.md
Last active November 14, 2017 08:15
How to use Backbone.js

Simple Starting Point

创建 Model

var Person = Backbone.Model.extend();
@sauloarruda
sauloarruda / receipt
Created April 30, 2012 15:47
Apple iOS in app purchase validate receipt in Ruby
ewoJInNpZ25hdHVyZSIgPSAiQXBNVUJDODZBbHpOaWtWNVl0clpBTWlKUWJLOEVk
ZVhrNjNrV0JBWHpsQzhkWEd1anE0N1puSVlLb0ZFMW9OL0ZTOGNYbEZmcDlZWHQ5
aU1CZEwyNTBsUlJtaU5HYnloaXRyeVlWQVFvcmkzMlc5YVIwVDhML2FZVkJkZlcr
T3kvUXlQWkVtb05LeGhudDJXTlNVRG9VaFo4Wis0cFA3MHBlNWtVUWxiZElWaEFB
QURWekNDQTFNd2dnSTdvQU1DQVFJQ0NHVVVrVTNaV0FTMU1BMEdDU3FHU0liM0RR
RUJCUVVBTUg4eEN6QUpCZ05WQkFZVEFsVlRNUk13RVFZRFZRUUtEQXBCY0hCc1pT
QkpibU11TVNZd0pBWURWUVFMREIxQmNIQnNaU0JEWlhKMGFXWnBZMkYwYVc5dUlF
RjFkR2h2Y21sMGVURXpNREVHQTFVRUF3d3FRWEJ3YkdVZ2FWUjFibVZ6SUZOMGIz
SmxJRU5sY25ScFptbGpZWFJwYjI0Z1FYVjBhRzl5YVhSNU1CNFhEVEE1TURZeE5U
SXlNRFUxTmxvWERURTBNRFl4TkRJeU1EVTFObG93WkRFak1DRUdBMVVFQXd3YVVI
@menny
menny / verify_appstore_in_app.php
Last active February 15, 2024 14:45
How to verify in-app purchases from AppStore and Market in PHP code (server-side)
function verify_app_store_in_app($receipt, $is_sandbox)
{
//$sandbox should be TRUE if you want to test against itunes sandbox servers
if ($is_sandbox)
$verify_host = "ssl://sandbox.itunes.apple.com";
else
$verify_host = "ssl://buy.itunes.apple.com";
$json='{"receipt-data" : "'.$receipt.'" }';
//opening socket to itunes
@lucasfais
lucasfais / gist:1207002
Created September 9, 2011 18:46
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
@karmi
karmi / workers.rake
Created July 22, 2010 15:58
Rake taks to launch multiple Resque workers in development/production with simple management included
# Rake task to launch multiple Resque workers in development/production with simple management included
require 'resque/tasks' # Require Resque tasks
namespace :workers do
# = $ rake workers:start
#
# Launch multiple Resque workers with the Rails environment loaded,
# so they have access to your models, etc.