Skip to content

Instantly share code, notes, and snippets.

View SaitoWu's full-sized avatar
:shipit:
Hacking everyday

Xin Wu SaitoWu

:shipit:
Hacking everyday
View GitHub Profile
require 'socket'
DN = %w{us1 us2 us3 us4 us5 jp1 jp2 jp3 sg1 hk1 hk2 uk1}
DN.each do |prefix|
domain = "#{prefix}.vpncloud.me"
ip = IPSocket::getaddress domain
# address=/.dev/127.0.0.1 for dnsmasq
puts "address=/#{domain}/#{ip}"
end
@SaitoWu
SaitoWu / clone.rb
Last active December 15, 2015 07:59
Grack ObjectSpace.count_objects.
100.times do
sleep 1
system("git clone http://127.0.0.1:9292/hanwen.git /Users/saito/Develop/grack-test/#{Time.now.to_i}")
end
@SaitoWu
SaitoWu / proc.rb
Created March 17, 2011 14:44
magic ruby proc demo
def block_new
puts Proc.new.call
end
block_new{"hello"}
#slow practice
def herp_pass_block(&block)
derp_call_block &block
end
@SaitoWu
SaitoWu / runable.rb
Created February 11, 2011 08:57
exec something on ruby.
#0> non-block call
Thread.new do
blahbla...
end
#1> 4 simple ways to call shell or cmd
`ps aux`
@SaitoWu
SaitoWu / gist:3998195
Created November 2, 2012 02:00
ssh config
# ~/.ssh/config
#attempts
ConnectionAttempts 10
#allow 30*120 = 1 hour down time
ServerAliveInterval 30
ServerAliveCountMax 120
@SaitoWu
SaitoWu / apply_patch.rb
Created October 8, 2012 17:31
grit patch apply
require'grit'
repo = Grit::Repo.new(".") #=> #<Grit::Repo "/Users/saito/hanwen/.git">
# check_applies => 0(can apply) or 1(can not)
repo.git.check_applies("master", "new") #=> 0
patch = repo.git.get_patch("new") #=> raw_patch
# apply_patch => tree_sha
repo.git.apply_patch("master", patch) #=> "c9a4861d9b3229974a0b1b05b87583ab3a887629"
# commit => commit_sha
# commit_message, array_of_commit, actor, tree_sha, head
@SaitoWu
SaitoWu / system.log
Created August 31, 2012 09:23
Mountain Lion systemlog
Aug 31 15:09:01 Saitos-MacBook-Pro kernel[0]: stampWait: Overflowed checking for stamp 0x39eb098 on MAIN ring: called from
Aug 31 15:09:01 Saitos-MacBook-Pro kernel[0]: timestamp = 0x39eb096
Aug 31 15:09:01 Saitos-MacBook-Pro kernel[0]: **** Debug info for *possible* hang in MAIN graphics engine ****
Aug 31 15:09:01 Saitos-MacBook-Pro kernel[0]: ring head = 0xa0e045d8, wrap count = 1287
Aug 31 15:09:01 Saitos-MacBook-Pro kernel[0]: ring tail = 0x00004c48
Aug 31 15:09:01 Saitos-MacBook-Pro kernel[0]: ring control = 0x0000f401 enabled, auto report disabled, not waiting, semaphore is waiting, length = 0x010 4KB pages
Aug 31 15:09:01 Saitos-MacBook-Pro kernel[0]: timestamps = 0x39eb096
Aug 31 15:09:01 Saitos-MacBook-Pro kernel[0]: Semaphore register values:
Aug 31 15:09:01 Saitos-MacBook-Pro kernel[0]: VRSYNC: (0x12044) = 0x39eb096
Aug 31 15:09:01 Saitos-MacBook-Pro kernel[0]: BRSYNC: (0x22040) = 0x0
@SaitoWu
SaitoWu / server.rb
Created August 23, 2012 07:01
ruby web server
# unicorn
# tee_input.rb 36L
@tmp = @len && @len <= @@client_body_buffer_size ?
StringIO.new("") : Unicorn::TmpIO.new
# Puma
# client.rb 106L
if remain > MAX_BODY
@SaitoWu
SaitoWu / rubygems.md
Created August 8, 2012 01:03
gem log
~ ❯ gem i rails -V                                                                                                    ⏎
GET http://rubygems.org/latest_specs.4.8.gz
302 Moved Temporarily
GET http://production.s3.rubygems.org/latest_specs.4.8.gz
200 OK
GET http://rubygems.org/specs.4.8.gz
302 Moved Temporarily
GET http://production.s3.rubygems.org/specs.4.8.gz
200 OK
@SaitoWu
SaitoWu / config.ru
Created June 28, 2012 06:51
Grack Server.
# install
# git clone https://github.com/SaitoWu/grack.git
# cd grack
# rake install
require 'grack'
config = {
:project_root => "/Users/saito/Develop/Repositories/",
:git_path => '/usr/bin/git',