Skip to content

Instantly share code, notes, and snippets.

module ArrayInquirer
def method_missing method, *args
begin
select { |elem| elem.send :"#{method}?", *args }
rescue NoMethodError
super method, *args
end
end
end
@kirel
kirel / application.html.haml
Last active October 12, 2015 14:08
Idea for plain dumb navigation active state
%body
%nav.main
%ul
%li= link_to 'main 1', some_path, class: active_navigation_item?(:main) # => true
%li= link_to 'main 2', some_path, class: active_navigation_item?(:more) # => false
= yield
# returns a ranking as a hash { elem => rank }
# ranks based on the sort order of the values the given block yields
# elements yielding the same value are ranked the same
module Enumerable
def rank_by
inject(Hash.new {|h, k| h[k] = []}) { |h, e| h[yield(e)] << e; h }
.sort.each_with_index
.inject({}) { |h,((_, es), i)| es.each { |e| h.update e => i + 1 }; h }
end
end
@kirel
kirel / .zshrc
Created September 5, 2012 13:36
# Path to your oh-my-zsh configuration.
export ZSH=$HOME/.oh-my-zsh
# Set to the name theme to load.
# Look in ~/.oh-my-zsh/themes/
export ZSH_THEME="robbyrussell"
[[ -s "$HOME/.rvm/bin/rvm-prompt" ]] && export RPROMPT="\$(~/.rvm/bin/rvm-prompt)"
# Set to this to use case-sensitive completion
# export CASE_SENSITIVE="true"
module Abyss
ROUNDTRIP = {}.tap { |abyss| abyss.default = abyss }.freeze
def to_abyss(obj = self)
case obj
when Hash
obj.inject({}) { |h,(k, v)| h.update k => to_abyss(v) }.tap { |h| h.default = ROUNDTRIP }
when Array
obj.map { |e| to_abyss(e) }
else
obj
require 'active_support/concern'
module MyCustomFoo
extend ActiveSupport::Concern
def foo_with_custom
puts 'custom'
foo_without_custom
end
config.treat_symbols_as_metadata_keys_with_true_values = true
config.filter_run :focus
config.filter_run_excluding :slow
config.run_all_when_everything_filtered = true
# vim FTW
Pry.config.editor = "mvim"
# Prompt with ruby version
Pry.prompt = [proc { |obj, nest_level| "#{RUBY_VERSION} (#{obj}):#{nest_level} > " }, proc { |obj, nest_level| "#{RUBY_VERSION} (#{obj}):#{nest_level} * " }]
if defined?(Rails) && Rails.env
begin
extend Rails::ConsoleMethods if defined?(Rails::ConsoleMethods)
require "rails/console/app"
module CSVMappings; ... end
module NavisionFtpsConnection; ... end
class CSVImporter
include ...
def initialize(file, clear, sep, etc...)
@file = file, ...
end
def import