Skip to content

Instantly share code, notes, and snippets.

View caius's full-sized avatar
👻

Caius Durling caius

👻
View GitHub Profile
@caius
caius / gist:40372
Created December 28, 2008 04:41 — forked from emk/gist:40364
Feature: Logging in and out
Scenario: Log in with valid name and password
Given a site
And a global admin
When I try to access the overview page
And I log in as with valid credentials
Then I should see the overview page
And should be logged in
@caius
caius / httpdump
Created April 4, 2009 00:35 — forked from peterc/httpdump
# Monitor HTTP requests being made from your machine with a one-liner..
# Replace "en1" below with your network interface's name (usually en0 or en1)
sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E "Host\: .*|GET \/.*"
# OR.. to be able to use as "httpdump" from anywhere, drop this into ~/.bash_profile:
# (again replace "en1" with correct network interface name)
alias httpdump="sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E "Host\: .*|GET \/.*""
# All the above tested only on OS X.
1) Put terminal_clone_tab somewhere in
your path and make sure it is executable (I put it in ~/bin)
chmod u+x terminal_clone_tab
2) Then add the following alias (~/.bash_profile or something)
alias nt='terminal_clone_tab'
3) Then you can hit nt (for new tab) anywhere
and a new tab will open up in same directory.
If there is an easier way to do this, let me know nunemaker@gmail.com.
# coding: utf-8
# rails application template for generating customized rails apps
#
# == requires ==
#
# * rails 2.3+, rspec, cucumber, culerity (langalex-culerity gem), machinist
#
# == a newly generated app using this template comes with ==
#
class SecureController < ApplicationController
layout 'secure'
def booking
@secure = Secure.find(:first, :conditions => {
:email => params[:secure][:email],
:reference => params[:secure][:reference]
})
# Redirect if we have the data
redirect_to secure_booking2_path and return unless @secure.nil?
module ExtendNumericRounding
def roundup(nearest=10)
self % nearest == 0 ? self : self + nearest - (self % nearest)
end
def rounddown(nearest=10)
self % nearest == 0 ? self : self - (self % nearest)
end
@caius
caius / gist:312437
Created February 23, 2010 17:26 — forked from jimneath/gist:312432
# I want to turn this:
array = [1, 2, 3, 4, 5, 6, 7, 8, 9]
# into this:
# [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
arr = []
array.each_slice(3) {|x| arr << x }
arr # => [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
@caius
caius / option.rb
Created March 31, 2010 12:33 — forked from djgraham/option.rb
class Option < ActiveRecord::Base
attr_accessor :view_type, :comments_count, :expires_at_date, :expires_at_time
before_save :set_expires_at
after_save :set_reference, :set_default_room_allocation_name, :set_room_allocation_dates
private
def set_reference
self[:reference] = "OPT%05d" % id
#
# Results:
# X adult(s), Y child(ren) and Z infant(s)
#
# rules: -
# - pluralization hacks in case of 1 of each of them.
# - only show children and infants if they're > 0
# - at least one adult is always present
#
# examples...
#!/usr/bin/env ruby
require 'rubygems'
require 'open-uri'
require 'nokogiri'
doc = Nokogiri::HTML(open('http://xkcd.com/').read)
image = doc.css("div#contentContainer > div#middleContent > div.bd > div.c > div.s > img")