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
@sandyxu
sandyxu / workers.rake
Created February 19, 2014 04:39 — forked from karmi/workers.rake
# 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.
@sandyxu
sandyxu / git-description.md
Last active August 29, 2015 14:04
git command description

Git 安装与初始化

Linux

如果你用的是Linux,你可以用你的本地包管理系统(native package management system)来安装.

$ yum install git-core  #译者注,在redhat等系统下用yum

$ apt-get install git-core #译者注,在debian, ubuntu等系统下用apt-get
@sandyxu
sandyxu / scan_chinese.rb
Created August 8, 2014 10:29
找出指定路径下文件中包含中文的行
# encoding: utf-8
class ScanChinese
def self.scan(file)
if File.directory?(file)
files = (Dir.entries(file) - %w( . .. ))
dir = files.map{|name| File.join(file, name)}
dir.each do |filename|
if File.directory?(filename)
scan(filename)
else
@sandyxu
sandyxu / benchmark_test.rb
Created November 7, 2014 10:07
benchmark
# need gem install benchmark-ips
require 'benchmark/ips'
def slow(&block)
block.call
end
def fast
yield
@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)
#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
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
#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
@sandyxu
sandyxu / elasticsearch-ik-plugin.md
Last active August 29, 2015 14:12
config elasticsearch and ik Analysis (Chinese word)
@sandyxu
sandyxu / Linux 系统中的目录
Created February 26, 2015 07:32
Linux 系统中的目录
目录 评论
/ 根目录,万物起源。
/bin 包含系统启动和运行所必须的二进制程序。
/boot
包含 Linux 内核,最初的 RMA 磁盘映像(系统启动时,由驱动程序所需),和 启动加载程序。
有趣的文件:
/boot/grub/grub.conf or menu.lst, 被用来配置启动加载程序。
/boot/vmlinuz,Linux 内核。