Prev PageNext Page
Transform Matching Text with Gsub in Ruby and Regular Expression
Here is a gist that demonstrates how easy it is to transform text using #gsub and a block with Ruby. "Scs Epc Score".gsub (/scs|epc/i) { |i| i.upcase } # => SCS EPC Score For more helpful string extensions in Ruby check out our Ruby Gem on GitHub...
Written by Sean Behan on 06/17/2012
Color Output with Test:Unit, AutoTest and Ruby 1.9
If you are testing using Test:Unit (rather than RSpec) and you're using Ruby 1.9.* colorized output of your tests using Autotest will not be immediately available. Since, 1.9 comes with mini test the test/unit/ui/console/testrunner.rb script is not loaded...
Written by Sean Behan on 06/17/2012
How to Merge a YAML File Into a Single Hash in Ruby
require 'yaml' # Nested YAML structure from something-nested.yml # # nested: # key: value # key_two: value_two # Procedural Approach to building a single Hash from nested YAML data structure. @yaml = YAML.load_file("something-nested...
Written by Sean Behan on 06/17/2012
Class
# Define a class with a class method "find" # Usage # Apple.find("macintosh") class Apple def self.find(variety) # code goes here end end # Same as above but notice the lack of self prefix before the method name # Usage # Apple.find("macin...
Written by Sean Behan on 06/17/2012
Changing GitHub Issue State in Git Commit Message
Changing issue state in git commit message for Github issues fixes #xxx fixed #xxx fix #xxx closes #xxx close #xxx closed #xxx Example git commit -am'complete bug fix closes #123'
Written by Sean Behan on 06/17/2012
Email Regex
Regular Expression that Matches Email Addresses: /\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}\b/
Written by Sean Behan on 06/17/2012
Vim Tips and Tricks
The following tips and tricks can be put into your .vimrc file Remap jj to esc imap jj <Esc> Quickly leave edit mode and back to visual mode with jj. This is probably the fastest key combination possible and one of the most frequent key combinatio...
Written by Sean Behan on 06/17/2012
How to Upgrade RVM on Mac OS X
I had an old version of rvm installed and wanted to upgrade. So old in fact that the resource for upgrading no longer existed. rvm update just returned a 301, redirect. Luckily, the following worked # checks out from repo rvm update --head # will re...
Written by Sean Behan on 06/17/2012
Ruby Reload! Method in Non Rails IRB Sessions
I love the Rails reload! function when in the console. I need it in Irb. To get it back this is what I did. If you don't already have an .irbrc file in your home directory, just create it. vim ~/.irbrc or textmate if you prefer mate ~/.irbrc Add this...
Written by Sean Behan on 06/17/2012
How to Recover a Mistakenly Deleted Branch
Workflow git checkout -b _new_branch_name # do some work and commit changed git checkout master git branch -d _new_branch_name # doh... i meant to merge first Fortunately, you can easily recover from this mistake. git reflog 395b1ea HEAD@{0}: checkout...
Written by Sean Behan on 06/17/2012
Prev PageNext Page