Skip to content

Instantly share code, notes, and snippets.

Creating a Multi Page Form in Rails
Creating a multi-step wizard-like form is pretty difficult in Rails.
Especially when trying to apply REST and validations. There are many
different approaches to this problem, and the right one depends largely
on your application details. Here are four options, and then my final
recommendation. Skip to that if you're in a hurry.
1. Create the model at the beginning on the first page of the form, and
have each successive page update the model. Validations are tricky
@zhengjia
zhengjia / capybara cheat sheet
Created June 7, 2010 01:35
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@natritmeyer
natritmeyer / monkeypatch.rb
Created June 5, 2011 17:17
RSpec monkeypatch to expose scenario outcome in after block with Example#passed? and Example#failed? methods
class RSpec::Core::Example
def passed?
@exception.nil?
end
def failed?
!passed?
end
end
@mathewbyrne
mathewbyrne / slugify.js
Created October 12, 2011 04:34
Javascript Slugify
function slugify(text)
{
return text.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, ''); // Trim - from end of text
}
@joshj
joshj / server.js
Created February 28, 2012 16:58 — forked from jeffrafter/server.js
Twitter OAuth with node-oauth for node.js+express
/*
Node.js, express, oauth example using Twitters API
Install Node.js:
curl -0 http://nodejs.org/dist/v0.6.11/node-v0.6.11.tar.gz
tar -zxf node-v0.6.11.tar.gz
cd node-v0.6.11
./configure
make
make install
@gorlum0
gorlum0 / count-inv-lr.py
Created March 16, 2012 19:17
Count inversions in an array, not "in-place"
#!/usr/bin/env python
"""(c) gorlum0 [at] gmail.com"""
import random
from sys import maxsize as inf
def merge_sort(A):
"""merge-sort which counts inversions"""
def merge(L, R):
m = len(L)-1
B = []
@andreyvit
andreyvit / tmux.md
Created June 13, 2012 03:41
tmux cheatsheet

tmux cheat sheet

(C-x means ctrl+x, M-x means alt+x)

Prefix key

The default prefix is C-b. If you (or your muscle memory) prefer C-a, you need to add this to ~/.tmux.conf:

remap prefix to Control + a

@MohamedAlaa
MohamedAlaa / tmux-cheatsheet.markdown
Last active July 23, 2024 05:34
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@slattery
slattery / pg_nextdowinstance.sql
Created July 2, 2012 02:20
Find the next occurence of a day of the week in postgresql
-- I'd gladly pay you Tuesday for a hamburger today!
-- OK, see you next Tuesday.
SELECT *
FROM generate_series
(
current_date + '1 day'::interval, -- in case now() is same dow
current_date + '7 days'::interval,
'1 day'
) as s(a)
@possibilities
possibilities / meteor-async.md
Created August 23, 2012 22:53
Meteor Async Guide

From Meteor's documentation:

In Meteor, your server code runs in a single thread per request, not in the asynchronous callback style typical of Node. We find the linear execution model a better fit for the typical server code in a Meteor application.

This guide serves as a mini-tour of tools, trix and patterns that can be used to run async code in Meteor.

Basic async

Sometimes we need to run async code in Meteor.methods. For this we create a Future to block until the async code has finished. This pattern can be seen all over Meteor's own codebase: