Skip to content

Instantly share code, notes, and snippets.

View flyerhzm's full-sized avatar
🏠
Working from home

Richard Huang flyerhzm

🏠
Working from home
View GitHub Profile
Synvert::Rewriter.new "remote_rewriter", "Remote rewriter example" do
end
@flyerhzm
flyerhzm / image.rb
Last active August 22, 2022 11:37 — forked from basgys/simple_paperclip.rb
paperclip without activerecord
class Image
extend ActiveModel::Naming
extend ActiveModel::Callbacks
include ActiveModel::Validations
include Paperclip::Glue
define_model_callbacks :save, only: [:after]
define_model_callbacks :destroy, only: [:before, :after]
#! /bin/sh
### BEGIN INIT INFO
# Provides: god
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: God initscript
### END INIT INFO
@flyerhzm
flyerhzm / hononyms
Last active December 13, 2015 20:08
dicts api benchmark
# {"text":"富裕"}
Server Software: Goliath
Server Hostname: 127.0.0.1
Server Port: 9000
Document Path: /v1/dicts/homonyms
Document Length: 23 bytes
Concurrency Level: 10
@flyerhzm
flyerhzm / gist:3882854
Created October 13, 2012 01:39
connection pool in jstack result
"http--127.0.0.1-8180-1" daemon prio=10 tid=0x00007f4a178e8800 nid=0x7265 in Object.wait() [0x0000000049bfb000]
java.lang.Thread.State: TIMED_WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x0000000704f40e18> (a org.jruby.libraries.ThreadLibrary$ConditionVariable)
at java.lang.Object.wait(Object.java:443)
at org.jruby.RubyThread$SleepTask.run(RubyThread.java:816)
- locked <0x0000000704f40e18> (a org.jruby.libraries.ThreadLibrary$ConditionVariable)
at org.jruby.RubyThread.executeBlockingTask(RubyThread.java:832)
at org.jruby.RubyThread.wait_timeout(RubyThread.java:1097)
at org.jruby.libraries.ThreadLibrary$ConditionVariable.wait_ruby(ThreadLibrary.java:286)
@flyerhzm
flyerhzm / gist:3816533
Created October 2, 2012 05:56
shell zip perf
GC::Profiler.enable
before_stats = ObjectSpace.count_objects
start = Time.now
files = Dir["**/*"].map { |file| file unless File.directory?(file) }
`zip test.zip #{files.join(" ")}`
puts "Total time: #{Time.now - start}"
after_stats = ObjectSpace.count_objects
puts "[GC Stats] #{before_stats[:FREE] - after_stats[:FREE]} new allocated objects."
# Total time: 0.349816
@flyerhzm
flyerhzm / gist:3816526
Created October 2, 2012 05:56
ruby zip perf
require 'zip/zip'
GC::Profiler.enable
before_stats = ObjectSpace.count_objects
start = Time.now
Zip::ZipFile.open("test.zip", Zip::ZipFile::CREATE) do |z|
Dir["**/*"].each do |file|
z.add file, file
end
end
puts "Total time: #{Time.now - start}"
@flyerhzm
flyerhzm / gist:3755702
Created September 20, 2012 12:50
torquebox-lite mvn install
➜ torquebox-lite git:(master) mvn install
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] TorqueBox Lite
[INFO] TorqueBox Lite Build Aggregator
[INFO] TorqueBox Lite Build Assembly
[INFO] TorqueBox Lite Gems Parent
[INFO] TorqueBox Lite Gem
class trinidad {
$jruby_home = "/opt/jruby"
$trinidad_home = "/opt/trinidad"
package { jsvc :
ensure => present
}
exec { install_trinidad :
command => "jruby -S gem install trinidad -v 1.3.4",
require 'redis'
require 'benchmark'
# user system total real
# redis set 0.280000 0.170000 0.450000 ( 0.809112)
# redis get 0.290000 0.160000 0.450000 ( 0.806711)
# redis mset with 1000 0.070000 0.020000 0.090000 ( 0.148474)
# redis mget with 1000 0.080000 0.020000 0.100000 ( 0.142837)
# redis mset with 100 0.050000 0.000000 0.050000 ( 0.067859)
# redis mget with 100 0.050000 0.010000 0.060000 ( 0.063040)
# redis mset with 10 0.040000 0.000000 0.040000 ( 0.060200)