Skip to content

Instantly share code, notes, and snippets.

View oliverbarnes's full-sized avatar

Oliver Azevedo Barnes oliverbarnes

View GitHub Profile
@oliverbarnes
oliverbarnes / gist:904734
Created April 5, 2011 22:43
Cucumber step to test xml output
Then /^I should see the following output$/ do |xml_output|
response = Hash.from_xml(page.body)
expected = Hash.from_xml(xml_output)
expected.diff(response).should == {}
end
@oliverbarnes
oliverbarnes / gist:904740
Created April 5, 2011 22:46
Cucumber step to test json output
#step
Then /^(?:|I )should see JSON:$/ do |expected_json|
require 'json'
expected = JSON.parse(expected_json)
actual = JSON.parse(page.body)
expected.should == actual
end
#in the feature
Then I should see JSON:
@oliverbarnes
oliverbarnes / gist:904743
Created April 5, 2011 22:48
Rspec request spec example
#From rspec-rails readme on github
describe "widgets resource" do
describe "GET index" do
it "contains the widgets header" do
get "/widgets/index"
response.should have_selector("h1", :content => "Widgets")
end
end
end
@oliverbarnes
oliverbarnes / gist:932207
Created April 20, 2011 18:18
trying to save navigation when clicking on final node's link
<script type="text/javascript" charset="utf-8">
$(function() {
{% if item.root? %}
$.jStorage.flush();
{% endif %}
$('#nav').columnview({
preview: function(element) {
$.jStorage.flush();
if($.browser.msie) {
@oliverbarnes
oliverbarnes / removes_spaces_from_usernames.rb
Created May 31, 2011 16:56
remove spaces from usernames
Profile.all({:username => /\s/}).each do |p|
old_username = p.username
p.set(:username => p.username.gsub(/\s+/, ""))
p.reload
msg = "Notify: #{p.full_name} <#{p.email}>"
msg << " - Old username: \"#{old_username}\""
msg << " => New username: \"#{p.username}\""
puts msg
@oliverbarnes
oliverbarnes / .bashrc
Created July 24, 2011 16:32
.bashrc with git branch parsing, rvm scripts and bunch of aliases for git/rails workflow
if [ -f /etc/bashrc ]; then
. /etc/bashrc # --> Read /etc/bashrc, if present.
fi
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/usr/local/mongodb/bin:$PATH"
export RUBYLIB=".:test:$RUBYLIB"
@oliverbarnes
oliverbarnes / opening_hours.rb
Created August 1, 2011 18:34
Quick opening hours object with mongomapper and a little meta
class OpeningHours
include MongoMapper::EmbeddedDocument
[:monday, :tuesday, :wednesday, :thursday, :friday, :saturday, :sunday].each do |weekday|
class_eval <<-KEYS_AND_ACCESSORS
key :#{weekday}_opening, :default => "CLOSED"
key :#{weekday}_closing
def #{weekday}
#{weekday}_opening == "CLOSED" ? #{weekday}_opening : \"\#\{#{weekday}_opening\} - \#\{#{weekday}_closing\}\"
@oliverbarnes
oliverbarnes / start_on_project.scpt
Created August 2, 2011 22:30
Automating iterm 2 sessions for a rails 3 project using applescript
-- open terminal sessions
tell application "iTerm 2"
activate
set myterm to (make new terminal)
tell myterm
-- start mongo
launch session "Default"
@oliverbarnes
oliverbarnes / gist:1207693
Created September 10, 2011 00:25 — forked from darkside/gist:1207663
God override sudo with rvmsudo
namespace :god do
namespace :restart do
task :default, :roles => :app, :except => { :no_release => true } do
run "rvmsudo #{bin_god} restart #{application}"
end
desc "|capistrano-recipes| Restarts the app server"
task :app, :roles => :app, :except => { :no_release => true } do
run "rvmsudo #{bin_god} restart #{application}-#{app_server.to_s.downcase}"
end
@oliverbarnes
oliverbarnes / install_postgis_osx.sh
Created April 20, 2012 14:45 — forked from juniorz/install_postgis_osx.sh
Installing PostGIS 1.5.3 (old formula) for Postgres 9.1.3 (Mac)
#If you don't have Postgres installed yet:
# https://github.com/tsaleh/tammer-saleh/blob/master/views/posts/installing-postgresql-for-rails-3-1-on-lion.html.textil
#1. Install postgis 1.5.3. Latest is 2.0.0, so using url old formula on github
brew install https://raw.github.com/mxcl/homebrew/8a04a43763906e6a9bef68881acf997f3a6f6687/Library/Formula/postgis.rb
#2. Create a template to be used on creating GIS-enabled databases
createdb template_postgis
#3. Import Postgis Data