Skip to content

Instantly share code, notes, and snippets.

View chrisdarroch's full-sized avatar

Christopher Darroch chrisdarroch

View GitHub Profile
@chrisdarroch
chrisdarroch / .bashrc
Last active December 20, 2016 16:29
A shell function that shows you the difference a Git branch made at the point it branched from your current one
function gdist {
basename="$1"
basesha="git merge-base HEAD $basename"
git diff "$basesha" "$basename"
}
@chrisdarroch
chrisdarroch / idea
Created October 17, 2013 03:40
Open a project in IntelliJ IDEA from your command line!
#!/bin/sh
# check for where the latest version of IDEA is installed
IDEA=`ls -1d /Applications/IntelliJ\ * | tail -n1`
wd=`pwd`
# were we given a directory?
if [ -d "$1" ]; then
# echo "checking for things in the working dir given"
wd=`ls -1d "$1" | head -n1`
@chrisdarroch
chrisdarroch / laksatime.js
Created May 13, 2011 06:52 — forked from jaredwy/laksatime.js
Laksa time without jQuery
(function(){
var options = {
yesMessage: "YES!",
noMessage: "No",
target: document.getElementById("isitlaksatime"),
wrapper: document.body,
day: 5, // 5 for friday
hour: 12 // 12 for noon!
};
# Some handy-dandy sub-domain steps for use with Capybara if you're using SubdomainFu
def get_base_url
# NOTE: I'm defining SITE_URL higher up somewhere. You might want to change that piece.
base_url = SITE_URL.split('.').reject { |piece| SubdomainFu.mirrors.include? piece }.join('.')
end
When /^(?:|I )visit (.+) for the subdomain "([^\"]*)"$/ do |new_path, subdomain|
new_url = get_base_url
new_url = subdomain + "." + new_url if subdomain.present?
# Determines if a particular ActiveRecord model or form object has errors on it.
# The method returns:
# - false if the object doesn't respond to #errors
# - true if the array of errors on the object is not empty
# - false in all other cases.
#
# You can optionally scope the check to look for specific errors.
# - In the case of a symbol, it will return a subset of errors as returned by the ActiveRecord::Errors#on(model) method
# - In the case of a String or Regexp, The errors array will be reduced by selecting only those who have keys containing the specified string/regexp to match.
#
<html>
<body>
<div id="wrapper">
<%# Huzzah! I can render messages way outside the bounds of my content structure! %>
<div id="messages">
<%= yield :messages %>
</div>
<section id="main">
<nav class="sidebar">
// You can try running these in FireBug console on the above html file.
$x("//li[@id='two']//preceding::li")
// => [ li#first, li#second, li#third, li#one ]
$x("//li[@id='two']//preceding-sibling::li")
// => [ li#one ]
$x("//ul[@class='outside']/li[1]//preceding::li")
string = "this is a string"
string.split("is") #=> ["th", " ", " a string"]
string.split("is a") #=> ["this ", " string"]
first, last = string.split("is a")
puts first #=> "this "
puts last #=> " string"
Feature: Application live validations
I want validation errors to appear as soon as they can be
In order to give feedback to the user as quickly as possible
Background: # features/application_live_validations.feature:5
Given a user exists with email: "test@easylodge.com.au", first_name: "Test", last_name: "Man" # features/step_definitions/pickle_steps.rb:4
[2010-07-14 08:38:38] INFO WEBrick 1.3.1
[2010-07-14 08:38:38] INFO ruby 1.8.7 (2009-06-12) [universal-darwin10.0]
[2010-07-14 08:38:38] INFO WEBrick::HTTPServer#start: pid=47066 port=9887
And I log in as that user # features/step_definitions/user_steps.rb:21
# Now I can do stuff like this!
# ...
When I follow "Personal Details"
Then I should see an inline error "can't be blank" for the following formtastic fields:
| label | within |
| Full Name | .identity |
| Date of birth | .identity |
| Gender | .identity |
| Marital status | .citizenship |
And I should see an inline error "must be selected" for the formtastic field "Title" within ".identity"