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 Integer | |
| N_BYTES = [42].pack('i').size | |
| N_BITS = N_BYTES * 16 | |
| MAX = 2 ** (N_BITS - 2) - 1 | |
| MIN = -MAX - 1 | |
| end | |
| p Integer::MAX #=> 4611686018427387903 | |
| p Integer::MAX.class #=> Fixnum | |
| p (Integer::MAX + 1).class #=> Bignum |
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
| function hexdump(buffer, blockSize) { | |
| blockSize = blockSize || 16; | |
| var lines = []; | |
| var hex = "0123456789ABCDEF"; | |
| for (var b = 0; b < buffer.length; b += blockSize) { | |
| var block = buffer.slice(b, Math.min(b + blockSize, buffer.length)); | |
| var addr = ("0000" + b.toString(16)).slice(-4); | |
| var codes = block.split('').map(function (ch) { | |
| var code = ch.charCodeAt(0); | |
| return " " + hex[(0xF0 & code) >> 4] + hex[0x0F & code]; |
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 timestamp | |
| Time.now.to_i | |
| 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
| require 'io/console' | |
| # Reads keypresses from the user including 2 and 3 escape character sequences. | |
| def read_char | |
| STDIN.echo = false | |
| STDIN.raw! | |
| input = STDIN.getc.chr | |
| if input == "\e" then | |
| input << STDIN.read_nonblock(3) rescue nil |