Skip to content

Instantly share code, notes, and snippets.

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

Yuki Kurihara ksss

🏠
Working from home
View GitHub Profile
user system total real
100000times 0.010000 0.000000 0.010000 ( 0.005554)
Array#new 100000times 0.020000 0.000000 0.020000 ( 0.024416)
List#new 100000times 0.040000 0.000000 0.040000 ( 0.037131)
Array#[] 100000times 0.020000 0.000000 0.020000 ( 0.016521)
List#[] 100000times 17.200000 0.020000 17.220000 ( 17.238337)
Array#push 100000times 0.010000 0.000000 0.010000 ( 0.019409)
List#push 100000times 0.030000 0.000000 0.030000 ( 0.026331)
Array#unshift 100000times 0.020000 0.000000 0.020000 ( 0.019558)
List#unshift 100000times 0.030000 0.000000 0.030000 ( 0.030940)
class HashDoubly
attr_accessor :key, :value
def initialize hash=nil
if hash
@key = hash.dup
@value = hash.dup.invert
else
@key = {}
$ ./bin/mruby hash_symbol_key.rb
set * 100 : 0.35799999999999
get * 100 : 0.11299999999999
update * 100 : 0.12799999999999
set * 1000 : 6.31099999999999
get * 1000 : 2.2480
update * 1000 : 2.4580
set * 10000 : 387.5570
get * 10000 : 184.548999999999
update * 10000 : 186.326999999999
a = []
h = {}
h[a] = 1
a.push 1
p h #=> {[1]=>1}
p h[a] #=> nil
b = []
p h[b] #=> nil
h[b] = 2
p h #=> {[1]=>1, []=>2}
@ksss
ksss / prepend.rb
Created July 4, 2014 03:02
Can not prepend after include
module Mod
def foo
:orig
end
end
class Cla
include Mod
end
@ksss
ksss / output.txt
Last active August 29, 2015 14:06
Multi Process [study]
$ ruby simple_worker.rb 4
[52341]
[52341, 52342]
[52341, 52342, 52343]
[52341, 52342, 52343, 52344]
after wait pid:52341, status:#<Process::Status: pid 52341 exit 0>
[52342, 52343, 52344, 52345]
after wait pid:52343, status:#<Process::Status: pid 52343 exit 0>
[52342, 52344, 52345, 52346]
after wait pid:52342, status:#<Process::Status: pid 52342 exit 0>
@ksss
ksss / nano_worker.rb
Last active August 29, 2015 14:08
nano_worker
# NanoWorker
# nano worker implementation use by thread
class NanoWorker
attr_accessor :queue, :thread
@@thread_map = {}
class << self
def [](name)
@@thread_map[name] ||= new
@ksss
ksss / prqueue.rb
Last active August 29, 2015 14:09
Pure Ruby Queue sample
#! /usr/bin/env ruby
class PureRubyQueue
def initialize
@que = []
@waiters = []
end
def push(obj)
@que << obj
$ cat test.rb
require 'tempfile'
Tempfile.open('tmp') do |f|
f2 = f.dup
f.write "aaa\nbbb\nccc\n"
f.rewind
p f.readline
p f2.readline
@ksss
ksss / strip_exif.rb
Last active August 29, 2015 14:11
split exif and other form .jpg image
#! /usr/bin/env ruby
# ruby strip_exif.rb [input.jpg] [output.jpg]
require 'stringio'
io = nil
in_path = ARGV[0]
out_path = ARGV[1]
File.open(in_path, 'rb') do |rf|