This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Photo < ActiveRecord::Base | |
extend Refile::ActiveRecord::Attachment::IDName | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env ruby | |
class PureRubyQueue | |
def initialize | |
@que = [] | |
@waiters = [] | |
end | |
def push(obj) | |
@que << obj |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# NanoWorker | |
# nano worker implementation use by thread | |
class NanoWorker | |
attr_accessor :queue, :thread | |
@@thread_map = {} | |
class << self | |
def [](name) | |
@@thread_map[name] ||= new |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Mod | |
def foo | |
:orig | |
end | |
end | |
class Cla | |
include Mod | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ./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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HashDoubly | |
attr_accessor :key, :value | |
def initialize hash=nil | |
if hash | |
@key = hash.dup | |
@value = hash.dup.invert | |
else | |
@key = {} |