Created
March 28, 2014 15:06
-
-
Save asaaki/9834918 to your computer and use it in GitHub Desktop.
Golfing
This file contains 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
# abuse of `inject` and `tap` | |
# | |
# it's not really short | |
# but shows some nice Ruby stuff | |
%w[bigdecimal /util].inject(""){|a,e|(a<<e).tap{|r|require r}} |
This file contains 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
# binary to hex string - and back to binary | |
sig = "<bin data>" | |
hexsig = sig.unpack("H*").first #=> "3c62696e20646174613e" | |
sig2 = hexsig.scan(/../).map{|hx| Integer("0x#{hx}").chr}.join | |
sig2 == sig #=> true |
This file contains 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
# can be useful in some cases: | |
(1..23).each_slice(9).with_index.map{|c,i|[i,c]} | |
#=> [ [0,[1..9]], [1,[10..19]], [2,[20..23]] ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment