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
# This is a place where you can put code that should be executed once, | |
# and accessed by several different threads. When it is called, it will | |
# block the thread until the calculation has been completed, and memoize it. | |
# | |
# This means all threads that call the same method will wait for the same result, | |
# that is only carried out once. Think of it as a traffic light; cars arrive at the | |
# red light at different times, wait, and all take off together once it turns green. | |
class CrossThreadMemoizer | |
def initialize(callable) | |
@callable = callable |
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 x(one: 1, two: 2) | |
local_variables.each_with_object({}) do |var, memo| memo[var] = eval(var.to_s) end | |
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
#!/bin/sh | |
for i in $(find $PWD -maxdepth 1 -type d); do | |
cd $i | |
if [ -d .git ]; then | |
remotes=$(git remote -v) | |
if [[ "$remotes" =~ [email protected]:myorg ]]; then | |
git remote set-url origin [email protected]:myneworg/$(basename `git rev-parse --show-toplevel`) | |
fi | |
fi | |
cd .. |
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
# Create or edit /etc/fstab/ to contain this: | |
LABEL=VOLUME_NAME none ntfs rw,auto,nobrowse |
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
" Inline ruby interpretation, inspired by RubyTapas. | |
" | |
" Example output when run over the top line: | |
" | |
" 3.times { |num| puts num } | |
" # => 0 | |
" # => 1 | |
" # => 2 | |
" | |
vmap <leader>r :!tee >(cat) \| ruby \| sed 's/^/\\# \=> /'<cr> |
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 Typoglycemia | |
def self.convert(text) | |
text.gsub(/(\w+)/) { |word| scramble_middle_characters(word) } | |
end | |
def self.scramble_middle_characters(word) | |
return word if word.length < 4 | |
word[0] + shuffle_letters(word[1...-1]) + word[-1] | |
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
IO.readlines("/usr/share/dict/words").map(&:strip) # array of english words |
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
task :register_statistics do | |
require 'rails/code_statistics' | |
STATS_DIRECTORIES << ['Services', 'app/services'] | |
STATS_DIRECTORIES << ['Services Tests', 'test/services'] | |
CodeStatistics::TEST_TYPES << 'Services Tests' | |
end | |
Rake::Task['stats'].enhance [:register_statistics] |
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 'simplecov' | |
SimpleCov.start 'rails' | |
ENV["RAILS_ENV"] ||= "test" | |
require File.expand_path('../../config/environment', __FILE__) | |
require 'minitest/autorun' | |
require 'rails/test_help' | |
require 'factories' |
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 JsonForStrategy | |
def initialize | |
@strategy = FactoryGirl.strategy_by_name(:build).new | |
end | |
delegate :association, to: :@strategy | |
def result(evaluation) | |
@strategy.result(evaluation).to_json | |
end |