Skip to content

Instantly share code, notes, and snippets.

# uses xpath to check for a form element based on the label,
# instead of using a css selector w/ label_for
# name should be the complete name in the html page.
# meaning Title: and not Title
# find the label that is name. Get the "for" of the label
# uses the for to check for the input with that as an id
Then /^I should see a "([^\"]*)" for "([^\"]*)"$/ do |type, name|
case type
@ajvargo
ajvargo / .irbrc
Created September 29, 2010 02:36
require 'pp'
require 'irb/completion'
IRB.conf[:AUTO_INDENT]=true
require 'irb/ext/save-history'
IRB.conf[:SAVE_HISTORY] = 100
IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-save-history"
@ajvargo
ajvargo / gist:703400
Created November 17, 2010 13:57
Pretty git-ified prompt in bash
# ~/.bash_profile
# give prompt as ~/foo(branch_name*)
# where the * indicates uncommitted work
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
export PS1='\[\033[36;40m\]\w\[\033[0;33m\]$(parse_git_branch)\[\e[0m\]$ '
@ajvargo
ajvargo / console
Created February 26, 2011 21:13
Homemade IRB Console, like Rails!
#!/usr/bin/env ruby
# console, generally inspired by rails console
#
# put in root of project, adjust file paths and the like
# chmod the file to be executable by you
# run:
# project_root >> ./console
@ajvargo
ajvargo / emacs_tidbits.el
Created April 14, 2011 13:54
Little emacs setting to share with co-workers
;; keep a single instance of Emacs I can send crap to
;; allows me to do things like this in my bash profile
;; export GIT_EDITOR=/Applications/Emacs.app/Contents/MacOS/bin/emacsclient
;; send files to emacs from the command line as 'emacsclient <filename>'
(server-start)
;; 2 spaces instead of 4 for javascript
(setq js-indent-level 2)
;; turn on linum for mode xxx
@ajvargo
ajvargo / grep_routes.sh
Created April 20, 2011 21:25
grep rails rake routes for strings via command line function
function grep_routes() {
ruby -e "ARGV[0].split(10.chr).each{|x| puts x if !ARGV[1..-1].map{|a| x =~ /#{a}/}.include?(nil)}" "$(rake routes)" "$@"
}
# USAGE
# > grep_routes this
# > grep_routes this that the other
@ajvargo
ajvargo / be_allowed_to_match.rb
Created May 10, 2011 04:41
Custom Matcher for Declarative Authorization authorization specs with RSpec
# in spec/spec_helper.rb, add this to make it work:
# require 'support/be_allowed_to'
# RSpec.configure |config|
# config.include(BeAllowedToMatcher)
# end
#
# allows: some_user.should be_allowed_to(:edit, thing)
# some_user.should be_allowed_to(:edit, :things)
# some_user.should be_allowed_to(:edit, thing, in_this_context)
# along with the should_not variants
@ajvargo
ajvargo / gist:1277150
Created October 11, 2011 02:50
Create a presenter object on the fly in Rails
# Inspired by Ryan Bates pro RailsCast "Presenters from Scratch"
# This is a proof of concept for 'automagically' creating presenter objects
#
# This assumes you have presenter objects that follow the convention
# Object => ObjectPresenter
#
# It intercepts the 'render' method in the controller, and does some
# introspection to see if there is a presenter defined for the class
# of the instance variable being looked at. If so, it makes a presenter
# and adds it as an instance variable
@ajvargo
ajvargo / playlister.rb
Created August 24, 2012 15:26
Generate a randomly sorted m3u playlist
Dir.chdir '/Users/avargo/Music' do
File.open('../Downloads/all_random.m3u', 'w+') do |file|
Dir.glob('**/*.{mp3,ogg,wav}').shuffle.each do |song|
next if File.directory?(file)
file.write File.join(Dir.pwd, song, "\n")
end
end
end
@ajvargo
ajvargo / input_example.el
Created January 20, 2013 03:56
An example of getting user input for an Elisp function with a default value divined from context.
(defun input-example (text)
"Gets user input and prints it back. Defaults to word at point"
(interactive
(list
(read-string
(format "Text (%s): " (word-at-point)) ; prompt. It's nice to show the default value
nil ; initial input. This value is prefilled in the mini-buffer. Available but considered deprecated.
nil ; history list if you have a specific one for this
(word-at-point) ; Whatever this evaluates to will be the default value
)))