Skip to content

Instantly share code, notes, and snippets.

View chrisbloom7's full-sized avatar
✈️
Traveling

Chris Bloom chrisbloom7

✈️
Traveling
View GitHub Profile
@chrisbloom7
chrisbloom7 / tail_recursive.sh
Created October 25, 2011 16:45
Bash shell command to recursively monitor a directory for new and changed files
#!/bin/sh
# Recursively `tail` new and changed files
# See https://gist.github.com/1313404#file_watch_recursive.sh for usage
watch -d -n 5 'tail `find . -type f \( ! -iname ".*" ! -ipath "*.svn*" \) -newerct "'"15 minutes ago"'" -print`'
@chrisbloom7
chrisbloom7 / excercise_custom_factory_girl_steps.feature
Created December 23, 2011 09:16 — forked from blaix/factory_girl_steps.rb
A modified version of the cucumber steps included in factory_girl, which will set an instance variable based on the factory/factories being generated. Drop this file into the features/support folder and don't require the original factory_girl/step_definit
# Assumes you have a factory named :customer defined with attributes first_name and last_name
Feature: Testing customized factory_girl step definitions
As an open source advocate
I
Want to make sure that my customized step definitions don't throw any errors
Scenario: Generating factories from a table
Given the following customers exist:
| first_name | last_name |
| Bob | Smith |
@chrisbloom7
chrisbloom7 / cucumber.yml
Created December 23, 2011 14:48 — forked from oliverbarnes/env.rb
Cucumber setup with spork and database_cleaner
<%
rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip"
%>
default: <%= std_opts %> features
wip: --drb -tags @wip:3 --wip features
autotest: --drb --color --format progress --strict
rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip
@chrisbloom7
chrisbloom7 / preload_sti_models.rb
Created January 31, 2012 22:17
Setting up STI subclass routes programmatically
if Rails.env.development?
# Make sure we preload the parent and children class in development
# since classes aren't pre-cached. Otherwise we get an error when
# accessing a child class before we access the parent.
%w[kase coaching_kase training_kase alpha_kase].each do |c|
require_dependency File.join("app","models","#{c}.rb")
end
end
@chrisbloom7
chrisbloom7 / exception_flow.rb
Created February 3, 2012 19:36
Testing the process flow of exception handling blocks in Ruby
# A contrived example
def a (dividend, divisor)
puts "-- Entering!"
if dividend >= 5
puts "-- Dividend >= 5!"
begin
puts "-- Beginning!"
puts "-- #{dividend.to_i / divisor.to_i}"
rescue => e
puts "-- Exception! #{e}"
@chrisbloom7
chrisbloom7 / .bash_aliases
Last active June 23, 2018 00:37
A portion of my alias entries and some other useful snippets for Bash
#!/bin/sh
# GENERAL COMMANDS
alias l='ls -AHhlp'
alias c='clear'
alias cx='chmod +x'
alias tree="find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'"
alias reload='source ~/.bash_profile'
alias release='xattr -d com.apple.quarantine'
alias flushdns='sudo discoveryutil udnsflushcaches'
@chrisbloom7
chrisbloom7 / order_test_steps.rb
Created March 20, 2012 21:15
A cucumber/capybara step to test the order of elements in a list
Then /^I should see each item listed in alphabetical order in the items section$/ do
@items.each_with_index do |item, index|
find(:xpath, "//*[@id='items']/ul[@class='items']/li[#{index+1}]").inspect.should eq(find("li#item-#{item.friendly_id}").inspect)
@item = item
step "I should see the item listed in the items section"
end
end
Then /^I should( not)? see the item listed in the items section$/ do |negation|
assertion = negation ? :should_not : :should
@chrisbloom7
chrisbloom7 / random_password.rb
Created April 24, 2012 05:47
Generate a random password containing at least one number and one special character
# Generate a password that is 8 - 20 characters in length, and which contains at least one number and one special character
# Requires Ruby >= 1.9
def random_password
specials = ((32..47).to_a + (58..64).to_a + (91..96).to_a + (123..126).to_a).pack('U*').chars.to_a
numbers = (0..9).to_a
alpha = ('a'..'z').to_a + ('A'..'Z').to_a
%w{i I l L 1 O o 0}.each{ |ambiguous_character|
alpha.delete ambiguous_character
}
characters = (alpha + specials + numbers)
@chrisbloom7
chrisbloom7 / git_make_branch.sh
Last active October 3, 2015 15:58
Unix function and alias to create git branches based off arbitrary text (e.g. A ticket number and description)
# Create a git branch based off of an arbitrary string. Call the function from
# the command line inside a git project and pass in the description (quoted or
# not) as the argument. Your description will be converted to slug format and
# used to checkout a new branch. Useful for quickly creating branches named
# after a ticket # and description.
# Example:
$ git-mb 123 Add a new feature \(Don't forget the tests\!\)
Switched to a new branch '123-add-a-new-feature-don-t-forget-the-tests'
@chrisbloom7
chrisbloom7 / db.rake
Created June 8, 2012 01:51
Extend Rails' defaut set of rake tasks to add a db:bootstrap task. Similar to db:reset but doesn't use the schema file. Useful for testing your complete migration set (i.e. simulating a fresh setup) or for resetting your seed data in development.
namespace :db do
desc "Completely tears down the database, rebuilds it from scratch using your migrations (i.e. ignoring the current schema file), re-seeds the database based on the current environment, and finally prepares the test database"
task :bootstrap => ["db:drop", "db:create", "db:migrate", "db:seed", "db:test:prepare"]
end