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
# usable in `Rakefile`: | |
rask = Class.new do | |
def initialize | |
@stack = [] | |
end | |
def method_missing name, *_args | |
name == :run! ? | |
Rake::Task[@stack.join(":").to_sym].invoke : | |
self.tap{ @stack << name } |
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
module SourceAnnotationExtractorExtension | |
extend ActiveSupport::Concern | |
included do | |
def find_in_with_rabl dir | |
results = {} | |
Dir.glob("#{dir}/*") do |item| | |
next if File.basename(item)[0] == ?. |
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
# Another example for: http://onor.io/2014/03/31/partial-function-application-in-elixir/ | |
defmodule PartFuncs do | |
defp addfun(x, y), do: x + y | |
# return a partially applied function | |
def add(a), do: &addfun(a, &1) | |
# could also easily be written as: addfun(a, b) | |
def add(a, b), do: (&addfun/2).(a, b) |
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
require "yaml" | |
begin | |
application_yml = YAML.load_file(File.join(File.dirname(__FILE__), "../config/application.yml")) | |
global_envs = application_yml.select { |key, _| key =~ /([A-Z_])+/ } | |
environment = ENV["RACK_ENV"] || ENV["RAILS_ENV"] || "development" | |
env_envs = application_yml.fetch(environment, {}) | |
current_envs = global_envs.merge(env_envs) | |
current_envs.each_pair do |key, value| | |
ENV[key.to_s.upcase] ||= value.to_s |
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
=begin | |
Message Pack vs similar utilities | |
ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin13.0] | |
Packing | |
user system total real | |
pack: bert 60.850000 0.270000 61.120000 ( 62.003839) | |
pack: bson 2.750000 0.010000 2.760000 ( 2.799844) | |
pack: bson (moped) 12.260000 0.030000 12.290000 ( 12.468642) |
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
#!/bin/sh | |
# Conflict markers | |
git diff --cached --diff-filter=ACMR | awk '/\+(<<<[<]<<<|>>>[>]>>>|===[=]===$)/ { exit 1 }' | |
CODE=$? | |
if [ "$CODE" != "0" ]; then | |
echo "COMMIT ABORTED: Conflict markers found." >&2 | |
exit $CODE | |
fi |
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
module ZoneConversion | |
module_function | |
def float2zone(offset) | |
("%+06.2f" % offset).tr(".", ":") | |
end | |
end | |
### Example |
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
module Token | |
module_function | |
MAX_RETRIES = 3 | |
TokenTakenError = Class.new(StandardError) | |
def token_generator | |
# SecureRandom.hex(32) | |
("a".."z").to_a.sample |
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
require "forwardable" | |
class ProcString | |
extend Forwardable | |
def_delegators :stringified_proc, :to_s, *("".methods - BasicObject.methods) | |
attr_reader :proc | |
def initialize(&string_proc) | |
@proc = string_proc |