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
h,m,s = *"23:34:02".match(/\A(\d+):(\d\d):(\d\d)\z/).captures | |
Time.now+h.to_i*3600+m.to_i*60+s.to_i |
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 Float | |
ExponentBits = 11 # 11 bits for exponent | |
SignificandBits = 52 # 52 bits for significand | |
ApproximativeEqualityDefault = 37 # precise to about 5 decimal places, which should be good for anything non-scientific | |
ApproximativeMaxExponent = 1<<ExponentBits | |
ApproximativeMaxSignificand = 1<<SignificandBits | |
ApproximativeMask1 = (1<<11)-1 | |
ApproximativeMask2 = (1<<20)-1 | |
ApproximativeMask3 = (1<<32)-1 |
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
# encoding: utf-8 | |
if defined?(Encoding) then | |
Encoding.default_external = 'utf-8' | |
Encoding.default_internal = 'utf-8' | |
else | |
$KCODE = 'utf-8' | |
end | |
ENV["LANG"] = 'en_US.UTF-8' |
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
## sortby.rb | |
module SortBy | |
class Reverse | |
include Comparable | |
attr_reader :value | |
def initialize(value) | |
@value = value | |
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
# Encoding: utf-8 | |
# The following code is under BSD 2-clause license | |
# -> http://en.wikipedia.org/wiki/BSD_licenses#2-clause_license_.28.22Simplified_BSD_License.22_or_.22FreeBSD_License.22.29 | |
# | |
# Author: Stefan Rusterholz <[email protected]> - https://github.com/apeiros/ | |
# | |
# A module to help with transliteration issues. | |
# Provides methods for: | |
# * Changing the case of characters/strings, mapping most latin characters |
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
# An example implementation of caching | |
# WARNING: this implementation does not feature any pruning/expiration strategy, | |
# be careful not to create a memory leak | |
require 'thread' | |
module Cacheable | |
@global_cache = {} | |
@mutex = Mutex.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
(1..Bigger).first(5) # => [1, 2, 3, 4, 5] |
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 Kernel | |
# Terminate the current process - the hard way | |
def t! | |
`kill -9 #{$$}` | |
end | |
module_function :t! | |
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
unless YAML.respond_to?(:dump_file) then | |
def YAML.dump_file(path, content) | |
File.open(File.expand_path(path), 'wb') do |fh| | |
fh.write(content.to_yaml) | |
end | |
end | |
class Object | |
def to_y(path=nil) | |
path ? YAML.dump_file(path, self) : to_yaml |
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 'thread' | |
class Thread | |
# Example: | |
# pool = Thread::Pool.new(10) do |exception| handle(exception) end | |
# pool.execute(1,2,3) do |x,y,z| whatever(x,y,z) end | |
# pool.join | |
class Pool |