- GitHub Staff
- https://justinherrick.com/
- @jah2488
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 | |
[ -z "$1" ] && echo "No argument supplied: Your ruby version is required" && exit 1 | |
RUBY_VERSION=$1 | |
PACKAGE_DIR="$HOME/Library/Application Support/Sublime Text 3/Packages/" | |
gem install seeing_is_believing | |
rvm wrapper "$RUBY_VERSION" sublime |
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
def diff(a,b) | |
hash_by_count(a) | |
.merge(hash_by_count(b)) { |_, av, bv| av - bv } | |
.flat_map { |k, v| [k] * v } | |
end | |
private | |
def hash_by_count(arr) | |
Hash[arr.group_by { |x| x }.map { |k, v| [k, v.count] }] | |
end |
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
def extract(from_record:, attribute:) | |
from_record[attribute] | |
end | |
def parse(path) | |
get_data_from(path).map do |record| | |
output_class.new(*attributes.map { |name| extract(attribute: name, from_record: record) }) | |
end | |
end |
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
(defn project-link [project] | |
(when project [:h3 [:a {:href (str "/" (:permaname project) "/project/view")} (str "Project: " (:name project))]])) |
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
vim -o `git status --porcelain | awk '{print $2}'` # Open all modified files from git in a different vim split | |
vim -o `ack -l $SEARCHTERM` # Search for all files that contain a given pattern and open them in vim splits |
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 'active_record' | |
require 'logger' | |
# This connection will do for database-independent bug reports. | |
ActiveRecord::Base.establish_connection 'sqlite3:///:memory:' | |
ActiveRecord::Schema.define do | |
create_table(:posts) { |t| t.string :name } | |
create_table(:comments) { |t| t.integer :post_id } | |
end |
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 Mod | |
A = :a | |
const_set('B', :b) | |
end | |
Mod.module_exec do | |
C = :c #This seems to just vanish entirely, but its actually being assigned elsewhere. See comments below. | |
const_set('D', :d) | |
end | |
Mod::A #=> :a |
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
def ns(namespace, delim = '.', &block) | |
nest_mod(namespace.split(delim), block) | |
end | |
def nest_mod(mod = Kernel, module_names, block) | |
return mod.module_exec(&block) if module_names.empty? | |
find_or_create_constant_in_module(mod, constantize(module_names.first)).tap do |this| | |
make_module_methods_accessible(this) | |
this.module_exec do | |
nest_mod(this, module_names.drop(1), block) |
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
ral = -> { Array.new(5) { Array.new(1..10).sample.times.map { Array('a'..'z').sample }.join } } | |
def array_of_random_strings_of_random_length(array_length: 5, string_length: 5, string_range: 'a'..'z') | |
Array.new(array_length) do | |
Array(1..string_length).sample.times.map do | |
Array(string_range).sample | |
end.join | |
end | |
end | |
#oh the joys of ruby |
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
class Object | |
def defn(name, &block) | |
@name = name | |
@fns = [] | |
instance_eval(&block) | |
self.class.send(:define_method, @name, Proc.new {|*args| | |
not_found = -> { raise "no method #{name.to_sym} found with #{args.count} args" } | |
@fns.detect(not_found) { |fn| fn.fetch(:arity) == args.count }.fetch(:proc).call(*args) | |
}) | |
end |
OlderNewer