Skip to content

Instantly share code, notes, and snippets.

require 'rubygems'
require 'capybara/dsl'
require 'minitest/autorun'
Capybara.default_driver = :selenium
Capybara.default_selector = :css
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app, :browser => :chrome)
end
@rmurphey
rmurphey / original.js
Created September 20, 2012 17:42
Reduce the Complexity of a Function
// a function that does too many things
function showPrice(row, standardPrice, discountPrice, savings, isProrated, isDeferred) {
var priceCol = row.find('td.price').eq(0);
var discountCol = row.find('td.price').eq(1);
var txt = '';
if (!discountPrice && !standardPrice && !savings && !isProrated && !isDeferred) {
discountCol.html('<img src="/img/loading.gif" />');
} else {
// repetitive code!
function selectedLocation() {
var selected = document.getElementById("countyLocation").value;
if (selected == "Ireland") {
var Ireland = new google.maps.LatLng(53.527248, -8.327637);
map.setCenter(Ireland);
map.setZoom(6);
}
function selectedLocation() {
var selected = document.getElementById("countyLocation").value;
if (selected == "Ireland") {
var Ireland = new google.maps.LatLng(53.527248, -8.327637);
map.setCenter(Ireland);
map.setZoom(6);
}
if (selected == "Clare") {
function getSomeThings(callback) {
var completed = 0;
var people, tasks;
$.ajax('/data/people.json', {
dataType: 'json',
success: function(data) {
completed++;
people = data.people;
onFinished();
@rmurphey
rmurphey / original.js
Created September 12, 2012 22:03
DRY Out Your Code with Functions
// repetitive code!
function updateDates() {
var startDate = $("#start-date").datepicker("getDate");
$("#menu-item-1 .day").text(startDate.getDate());
$("#menu-item-1 .month").text(Util.monthToText(startDate.getMonth()));
$("#menu-item-1 .year").text(startDate.getFullYear());
var endDate = $("#end-date").datepicker("getDate");

Files would be laid out as follows ... obviously this is a little contrived :)

grunt.js
app/
  index.html
  js/
    foo.js
    runner.js
 tests/
@rmurphey
rmurphey / notes.md
Created August 24, 2012 01:34
Johnny-Five: 7-Segment Display with Shift Register

Johnny-Five: 7-Segment Display with Shift Register

seven segment display with shift register

See code for presumed segment layout. Segment A is attached to Q0 of the shift register, B-Q1, etc. The DP is attached to Q7.

schematic

@rmurphey
rmurphey / gist:3325237
Created August 11, 2012 15:27
Motion detector
var five = require("../lib/johnny-five.js"),
board, sensor, red, green, blue, piezo;
board = new five.Board();
board.on("ready", function() {
var status = new five.Led(13);
status.on();
red = new five.Led(8);
@rmurphey
rmurphey / gist:3318978
Created August 10, 2012 23:40
Cajun Pork Roast

Cajun Pork Roast

  • 2 lb boneless pork roast
  • canola oil
  • 3 T paprika
  • 1/2 t cayenne
  • 2 t oregano
  • 2 t thyme
  • 1/2 t salt
  • 1/2 t white pepper