Skip to content

Instantly share code, notes, and snippets.

Kuniaki IGARASHI igaiga

Block or report user

Report or block igaiga

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gem_source.txt
## rubyforge
$ gem sources -l
*** CURRENT SOURCES ***
http://gems.rubyforge.org/
$ gem i awesome_print
ERROR: While executing gem ... (TypeError)
View enc_test.rb
# enc_test.txt に 日本語 を1行書いておく
File.open("enc_test.txt") do |f|
puts out_str = f.each_line.first
puts out_str.encoding
end
puts in_str = "中の日本語"
puts in_str.encoding
@igaiga
igaiga / imgge_uploader.m
Created Nov 10, 2011
Multipart POST to upload jpeg sample code for iOS
View imgge_uploader.m
@interface ImageUploader : NSObject {
NSData *theImage;
}
@property (retain) NSData *theImage;
- (void) syncUpload:(NSData *) uploadImage;
@end
#import "ImageUploader.h"
View hoimi.rb
module Hoimirable
def hoimi
@hp = [@hp + 20, @max_hp].min
end
end
class Sumaltria
include Hoimirable
end
View hash_default_proc.rb
h1 = {}
h1.default= []
h1[:a] = h1[:a] << "hi"
h1[:b] = h1[:b] << "ho"
p h1 #=> {:a=>["hi", "ho"], :b=>["hi", "ho"]}
h2 = {}
h2.default_proc = ->(hash, key){ [] }
h2[:a] = h2[:a] << "hi"
h2[:b] = h2[:b] << "ho"
View smalrubot_sample.rb
require 'smalrubot'
board = Smalrubot::Board.new(Smalrubot::TxRx::Serial.new)
100.times do
p board.analog_read(0)
sleep 1
end
View self.rb
class Foo
p self #=> Foo (Fooクラス)
@bar = "hello!"
def foo
p self #=> #<Foo:0x007ff63a2471f0> (Fooクラスインスタンス)
p @bar = "hi!"
end
def self.foo
p self #=> Foo (Fooクラス)
p @bar #=> "hello!"
View hash_example.rb
h = {}
["a", "a", "b"].each do |x|
h[x] = [] unless h[x]
h[x] << x
end
p h
#=> {"a"=>["a", "a"], "b"=>["b"]}
View find_no_spec_end_points.rb
# routesの中でrequest_specで呼ばれないエンドポイントを探す
require "active_support"
require "active_support/core_ext"
require "awesome_print"
### routes
raw_routes_string = ActionDispatch::Routing::RoutesInspector.new(Rails.application.routes.routes).format(ActionDispatch::Routing::ConsoleFormatter.new)
raw_routes = raw_routes_string.split("\n")
raw_routes.shift # 先頭行はヘッダ行なので読み飛ばし
routes = raw_routes.map do |line|
You can’t perform that action at this time.