Skip to content

Instantly share code, notes, and snippets.

View sxross's full-sized avatar

s.ross sxross

View GitHub Profile
Some basic features and scenarios for authentication. Implementation left out. Sorry.
Feature: Signing up for an account
In order to use the site
As a visitor
I sign up for an account
Scenario:
Given I'm an anonymous visitor
And I go to the home page
#!/usr/env ruby
require 'rubygems'
require 'fileutils'
class Object
def empty?
return true if self.nil?
case
when String, Array, Hash
return true if self.length == 0
module FindOrCreate
def self.included(base)
base.class_eval do
extend ClassMethods
end
end
module ClassMethods
def find_or_create(arg)
first(arg) || create(arg)
require "mongo_mapper"
MongoMapper.database = 'test'
module FindOrCreate
def self.included(base)
base.class_eval do
extend ClassMethods
end
end
# This may well be user error, but CoffeeScript:
ubb_text: ubb_text.replace /\[img\](.+?)\[\/img\]/gi, (str, args...) ->
throw "oh, crap!" unless args[0]
image_url: if args[0].match(/^http/i) then args[0] else "http://www1.istockphoto.com${args[0]}"
"<img src=\"${image_url}\" />"
# The resultant js is:
ubb_text = ubb_text.replace(/\[img\](.+?)\[\/img\]/gi, function(str) {
@sxross
sxross / html_tag.coffee
Created May 27, 2011 21:06
Coffeescript HTML Tag Helper Class
# HTML Tag class
#
# Purpose: Programmatically generate HTML so you aren't scotch-taping
# strings together all the time.
#
# Usage: targetString = Tag.make(tagName, attributeHash, text)
#
# Where: targetString: is what you will eventually inject into the DOM -- the HTML
# tagName: is the actual tag name (i.e., "tr" or "input")
# attributeHash: is the set of tag attributes, for example --
@sxross
sxross / install_node.sh
Created November 27, 2011 19:28
Installing node.js Using Homebrew
$ sudo brew install node
Password:
Formula already installed: /usr/local/Cellar/node/0.2.2
steve-rosss-iMac-2:~ sxross$ sudo brew uninstall node
Uninstalling /usr/local/Cellar/node/0.2.2...
steve-rosss-iMac-2:~ sxross$ sudo brew install node
==> Downloading http://nodejs.org/dist/node-v0.2.2.tar.gz
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/node/0.2.2
==> make install
@sxross
sxross / install_coffeescript.sh
Created November 27, 2011 19:30
Homebrew Install Coffeescript
$ brew install coffee-script
==> Downloading http://github.com/jashkenas/coffee-script/tarball/0.9.2
######################################################################## 100.0%
==> ./bin/cake --prefix /usr/local/Cellar/coffee-script/0.9.2 install
/usr/local/Cellar/coffee-script/0.9.2: 33 files, 556K, built in 2 seconds
@sxross
sxross / band.js
Created November 27, 2011 20:00
Band Model (Backbone.js / Coffeescript)
$ ->
bands = null
class Band extends Backbone.Model
initialize: ->
console.log "initializing model #{@inspect()}"
inspect: ->
console.log "inspect"
s = []
@sxross
sxross / mm_init.sh
Created November 27, 2011 21:36
Initializing Middleman Project
$ mm-init my_fine_project
create my_fine_project/config.rb
create my_fine_project/source/index.html.erb
create my_fine_project/source/layout.erb
create my_fine_project/source/stylesheets
create my_fine_project/source/stylesheets/site.css.scss
create my_fine_project/source/javascripts
create my_fine_project/source/images