Skip to content

Instantly share code, notes, and snippets.

When 'I create a new comment' do
steps %Q{
When I enter comment text
And I press "Add Comment"
}
end
When 'I enter comment text' do
@comment = Factory :comment, :section => @section, :user => @me
@lukesh
lukesh / gist:753527
Created December 23, 2010 20:50
question.rb
def create
respond_to do |format|
format.json do
if @my_model.save!
render :json => @my_model.to_json(:methods => [:owner_name]) #owner_name is a method that returns owner.display_name
end
end
format html do
if @my_model.save!
...
respond_to do |format|
if @comment.save!
format.json do
...
end
format.html do
...
end
else
format.json do
[ Poopin'd Status Screenshot ]
If your status reads like this, with you none-the-wiser, consider yourself Poopin'd. You have been initiated into a trend so prevalent it's got an [official set of rules].
Under normal circumstances, the lifecycle of a Poopin' involves you turning a blind eye to your cell phone for thirty seconds, a keenly aware and diabolical friend, and subsequent social media dignity losses. Statistically speaking, considering that there are approximately 5,000,000,000 cellphones globally. That's a potential of quite a bit of Poopin'.
But think about this, more people across the globe have access to cell phones than have access to clean toilets.
Preventable diseases caused by a lack of basic sanitation kill more people each year than AIDS, malaria, and the measles combined. Toilet humor is only funny when you've got one.
Sampling process 4786 for 3 seconds with 1 millisecond of run time between samples
Sampling completed, processing symbols...
Analysis of sampling Cloud (pid 4786) every 1 millisecond
Process: Cloud [4786]
Path: /Applications/Cloud.app/Contents/MacOS/Cloud
Load Address: 0x100000000
Identifier: com.linebreak.CloudApp
Version: 0.9 (0.9)
Code Type: X86-64 (Native)
Parent Process: launchd [109]
@lukesh
lukesh / gist:4342266
Created December 20, 2012 01:22
Overloading _.intersection
var arr1 = [1,2,3]
,arr2 = [2,3,4]
,arr3 = [3,4,5];
function overloadIntersection() {
var cached = _.intersection;
_.intersection = function() {
var rest = arguments, arr = [];
if(rest.length == 0) {
throw "You must pass at least one array to _.intersection."
@lukesh
lukesh / gist:4548045
Created January 16, 2013 15:38
Schema creation wrapper
// Schema, which wraps Mongoose's Schema for pretty and extendable models.
var _ = require('underscore')
, each = require('each')
, mongoose = require('mongoose')
, Schema = function(obj) {
this.schema = new mongoose.Schema(obj)
this.references = []
}
@lukesh
lukesh / gist:4661706
Created January 29, 2013 04:04
jitsu deploy error
error: Error running command deploy
error: Nodejitsu Error (500): Internal Server Error
error: There was an error while attempting to deploy the app
error:
error: Rackspace Error (404): Item not found
error: Error output from Haibu:
error:
error: Error: Rackspace Error (404): Item not found
error: at Request._callback (/root/haibu-orchestra/node_modules/haibu/node_modules/cloudfiles/lib/cloudfiles/common.js:184:18)
error: at Request.init.self.callback (/root/haibu-orchestra/node_modules/haibu/node_modules/request/main.js:119:22)
if(!Array.prototype.unique) {
Object.defineProperty(Array.prototype, "unique", {
value: function(key) {
var o = {}, i, l = this.length, r = []
for(i=0; i<l;i+=1) {
if(key) {
var _key = ""
,self = this
if(typeof key == "string") {
_key = key
if (!Array.prototype.indexOf)
{
Array.prototype.indexOf = function(elt /*, from*/)
{
var len = this.length >>> 0;
var from = Number(arguments[1]) || 0;
from = (from < 0)
? Math.ceil(from)
: Math.floor(from);