Skip to content

Instantly share code, notes, and snippets.

📝
Documenting things

Brandon Weaver baweaver

📝
Documenting things
Block or report user

Report or block baweaver

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@baweaver
baweaver / rails.yml
Created Oct 22, 2013
A Blueprint for installing Rails. Demonstration for upcoming Handyman gem.
View rails.yml
# Blueprint for Installing Rails
# ==============================
#
# Makes Ruby 2 and Rails 4
Ruby:
RVM:
- 'apt-get install curl'
- 'curl -L https://get.rvm.io | bash'
- 'rvm install 2.0'
@baweaver
baweaver / pk-install
Created Nov 3, 2013
I get really annoyed at having to retype this exact same thing to install every tar.gz package, so I put it in a function
View pk-install
function pk-install {
url="$1"
wget $url
file_name=`echo $url | sed 's/^.*\/\(.*\)\.tar\.gz$/\1/'`
tar -zxvf "$file_name.tar.gz"
cd $file_name
make && make install
}
@baweaver
baweaver / LatLong Regex
Created Dec 22, 2013
Ruby regex for Latitude and Longitude
View LatLong Regex
/\([+-]?((?=9)90(\.0+)?|[1-8]?\d(\.\d+)?), [+-]?((?=1\d{2})((?=18\d)180(\.0+)?|1[0-7]\d(\.\d+)?)|\d{2}(\.\d+)?)\)/
@baweaver
baweaver / string-symbol
Created Jan 3, 2014
String vs Symbol instantiation. When possible, prefer symbols, as they have on average half the instantiation time.
View string-symbol
[9] pry(main)> n = 1_000
=> 1000
[10] pry(main)> Benchmark.bm { |bm|
[10] pry(main)* bm.report { n.times { :foo }}
[10] pry(main)* bm.report { n.times { 'foo'}}
[10] pry(main)* }
user system total real
0.000000 0.000000 0.000000 ( 0.000192)
0.000000 0.000000 0.000000 ( 0.000396)
=> [#<Benchmark::Tms:0x0000000263dfd8
@baweaver
baweaver / gist:8450274
Created Jan 16, 2014
Testing library: Proof. Vague musings on structure.
View gist:8450274
def my_function(n); n / 2; end
prove x.will eq(5).when { x = my_function(10) }
when { x = my_function(10) }.prove_that_it_will eq(5)
my_context = ->{ x = my_function(10) }
prove(x).will eq(5).when my_context
@baweaver
baweaver / Skyforge
Last active Jan 3, 2016
A working draft for Skyforge, a super powered mocking framework.
View Skyforge
# Skyforge
Forge mock objects for your test with immense power! This one is currently in development,
and not close to being done. So what are we planning to do here?
## !!! THIS IS THEORETICAL, UNDER CONSTRUCTION !!!
## Trace
Using Mockingjay, trace a ruby hash to make a generator for more objects like it.
@baweaver
baweaver / retrieve_keys
Created Feb 5, 2014
retrieve all keys listed
View retrieve_keys
[1] pry(main)> hash = {a: 1, b: 2, c: 3}
=> {:a=>1, :b=>2, :c=>3}
[2] pry(main)> class Hash
[2] pry(main)* def retrieve_keys(*keys)
[2] pry(main)* self.reduce({}) { |h, (k, v)|
[2] pry(main)* keys.include?(k) ? h.merge!({k => v}) : h
[2] pry(main)* }
[2] pry(main)* end
[2] pry(main)* end
=> nil
@baweaver
baweaver / prompt.rb
Created Feb 14, 2014
repeatedly prompt until something matches all conditions
View prompt.rb
def prompt(name: '', matches: '')
while true
print "#{name}: "; answer = gets.chomp
return answer if Array(matches).all? { |match| match === answer }
puts "Invalid!"
end
end
View gist:9315733
# Playing off of my prompt idea, let's take it one step further:
name = prompt for: 'Name', validate: { with: /\w+/, or: 'Invalid name given!' }
# Where if given invalid input it will say:
# Error: Invalid name given
# Name:
@baweaver
baweaver / defn.rb
Created Mar 23, 2014
Because I can
View defn.rb
module Kernel
def defn name, &block
define_method name, block
end
end
You can’t perform that action at this time.