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
| # TempfileEnsureCloser.new.begin do |tmp| | |
| # gz = tmp.create(["tmp", ".gz"]) # File instance | |
| # get_object(gz) | |
| # csv = tmp.create(["tmp", ".csv"]) | |
| # system("gunzip -c #{gz.path} > #{csv.path}") | |
| # end #=> close and unlink all temp file | |
| class TempfileEnsureCloser | |
| def initialize | |
| @tempfiles = [] | |
| 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
| def packuuid(uuid) | |
| uuid.split('-').pack("H8H4H4H4H12") | |
| end | |
| def unpackuuid(byte) | |
| byte.unpack("H8H4H4H4H12").join('-') | |
| end | |
| uuid = "43e1254f-2d13-4193-b4b4-b9520ef0e9f3" | |
| p uuid.length #=> 36 | |
| packed = packuuid(uuid) |
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 TypeChecker | |
| Error = Class.new(StandardError) | |
| class << self | |
| def register(this, meth, klass) | |
| this.module_eval(<<~RUBY, __FILE__, __LINE__ + 1) | |
| def #{meth} | |
| ret = super | |
| unless ret.kind_of?(#{klass}) | |
| raise Error, "no implicit conversion of \#{self.class} into #{klass} got \#{ret.class}" |
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
| FROM matsumotory/ngx-mruby |
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
| require 'open-uri' | |
| class MultiDownload | |
| def initialize(*urls) | |
| @urls = urls | |
| end | |
| def to_h | |
| @urls.map { |url| | |
| Thread.new(url) do |url| |
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 pretty-argumenterror.rb | |
| ArgumentError: wrong number of arguments (given 3, expected 2) | |
| from: pretty-argumenterror.rb | |
| 1 | #! /usr/bin/env ruby | |
| 2 | | |
| -> 3 | def foo(a, b) | |
| 4 | end | |
| 5 | | |
| 6 | begin |
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 SwfFile | |
| # @example: | |
| # SwdFile.new("foo.swf") | |
| def initialize(path) | |
| @path = path | |
| end | |
| # @example: | |
| # x_min, x_max, y_min, y_max = swf.stage_size | |
| def stage_size |
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 | |
| p [[ | |
| "0111010001101000011000010110", | |
| "1110011010110010000001111001", | |
| "01101111011101010010000001100", | |
| "1100110111101110010001000000", | |
| "11011100110010101110110011001", | |
| "010111001000100000011001110", | |
| "11010010111011001101001011011", |
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 perl | |
| use utf8; | |
| use Encode; | |
| use charnames ':full'; | |
| binmode STDIN, ":utf8"; | |
| binmode STDOUT, ":utf8"; | |
| if (@ARGV == 0) { |
