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 String | |
# Defaults for String#scrubbed_utf8's options argument | |
ScrubbedUtf8Defaults = {invalid: :replace, undef: :replace} | |
# Similar to what String#encode does, the options argument is also the same, | |
# but it defaults to :replace for both :invalid and :undef options. | |
# | |
# :invalid: | |
# If the value is :replace, #encode replaces invalid byte sequences in str | |
# with the replacement character. The default is :replace. |
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' # requires ruby 1.9.3 | |
module PasswordString | |
def inspect; "[PASSWORD]"; end | |
def to_s; "[PASSWORD]"; end | |
def dup; obj=super;obj.extend PasswordString; obj; end | |
def clone; obj=super;obj.extend PasswordString; obj; end | |
end | |
def password |
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 'yaml' | |
class Configuration | |
def self.load_yaml(file) | |
new(YAML.load_file(file)) | |
end | |
def initialize(config, schema=nil) | |
config.each do |key, value| | |
value = Configuration.new(value) if value.is_a?(Hash) |
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 Object.create(attrs) | |
obj = new | |
obj.singleton_class.send(:attr_accessor, *attrs.keys) | |
attrs.each do |name,value| obj.instance_variable_set(name.to_s.sub(/\A@?/, '@'), value) end | |
obj | |
end | |
o = Object.create(foo: 12, bar: "hi") # => #<Object:0x007fc53a0f7bc8 @bar="hi", @foo=12> | |
o.bar # => "hi" |
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 | |
require 'sorting/ascending' | |
require 'sorting/descending' | |
module Sorting |
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
= Object#<=> | |
(from ruby site) | |
------------------------------------------------------------------------------ | |
obj <=> other -> 0 or nil | |
------------------------------------------------------------------------------ | |
Returns 0 if obj === other, otherwise nil. |
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
Released gem 'sorting'. It provides methods to sort_by asc & desc, and lazily evaluate sort values: https://rubygems.org/gems/sorting feedback welcome! |
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
# BEWARE! This code is largely untested and not ready for production! | |
Result = Struct.new(:entries, :raw_error, :status) | |
class Entry | |
HeaderUnpackFormat = "Z100A8A8A8A12A12A8aZ100A6A2Z32Z32A8A8Z155".freeze | |
EmptyString = "".freeze | |
OctalFields = [1,2,3,4,5,6,10,13,14] | |
def self.from_stream(io) | |
header = io.read(512) |
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
ref=`git symbolic-ref --short HEAD` && \ | |
git checkout SOME_REVISION && \ | |
cp -r some/dir /to/dir/outside/of/repo && \ | |
git checkout $ref |
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 | |
# Sadly, in ruby <2.0 Object#inspect uses to_s, and will use a redefined to_s. Not even | |
# Object.instance_method(:inspect).call(obj) gets you around that. | |
# This module provides something akin to Object#inspect for arbitrary objects. | |
# | |
# @example Generic object inspection | |
# puts Inspector.inspect_object(some_obj) | |
# | |
# @example Including it into a class |