Skip to content

Instantly share code, notes, and snippets.

@raggi
raggi / sinatra_metal.rb
Created March 18, 2009 15:40
sinatra as rails metal example - mostly unnecessary
require 'sinatra/metal'
class SinatraMetal < Sinatra::Base
include Sinatra::Metal
get '/sinatra' do
'hello sinatra!'
end
end
@dnagir
dnagir / rspec-syntax-cheat-sheet.rb
Created November 5, 2010 09:29
RSpec 2 syntax cheat sheet by example
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")
@trey
trey / rwd.css
Created January 26, 2012 20:14
Bootstrap's RWD breakpoints
/* http://twitter.github.com/bootstrap/scaffolding.html#responsive */
/* Landscape phones and down */
@media (max-width: 480px) { ... }
/* Landscape phone to portrait tablet */
@media (max-width: 768px) { ... }
/* Portrait tablet to landscape and desktop */
@media (min-width: 768px) and (max-width: 940px) { ... }
@addyosmani
addyosmani / backboneglobalpubsub.md
Created February 4, 2012 19:37
Backbone.js global pub/sub

Generally one implements notifications by listening for events on specific models but if one wishes to have a single global message interchange, it could be done as follows:

var pubsub = new Backbone.Model;

View1 = Backbone.View.extend({
  initialize: function(){
    pubsub.bind('custom event', callback);
  }
 // ...
@jrochkind
jrochkind / gist:2161449
Created March 22, 2012 18:40
A Capistrano Rails Guide

A Capistrano Rails Guide

by Jonathan Rochkind, http://bibwild.wordpress.com

why cap?

Capistrano automates pushing out a new version of your application to a deployment location.

I've been writing and deploying Rails apps for a while, but I avoided using Capistrano until recently. I've got a pretty simple one-host deployment, and even though everyone said Capistrano was great, every time I tried to get started I just got snowed under not being able to figure out exactly what I wanted to do, and figured I wasn't having that much trouble doing it "manually".

@justinko
justinko / Plea.markdown
Created May 30, 2012 19:40
Am I doing it wrong?

Dear Rubyists,

I just lost a contract because of my code in a Rails project.

The specific code in question is related to a "posting a comment" feature. Here are the details:

In this project, "posting a comment" does not simply entail inserting a row into the database. It involves a procedure to yes, insert a row, but also detect its language, check for spam, send emails, and "share" it to Twitter and Facebook. I believe this algorithm should be encapsulated. I do not believe it belongs in a controller or a model. I do not believe Active Record callbacks should be used.

The "senior developer", whom is the stake holder's right hand man, said this:

@timruffles
timruffles / chunk.js
Last active October 8, 2015 19:18
underscore chunk method
// Turns a list into a list of lists of specified lengths.
_.chunk = function(array,chunkSize) {
return _.reduce(array,function(reducer,item,index) {
reducer.current.push(item);
if(reducer.current.length === chunkSize || index + 1 === array.length) {
reducer.chunks.push(reducer.current);
reducer.current = [];
}
return reducer;
},{current:[],chunks: []}).chunks
@boazsender
boazsender / sample-backbone.routefilter-router.js
Created August 30, 2012 14:46
Sample Backbone.Router use case for backbone.routefilter (https://github.com/boazsender/backbone.routefilter)
/*
* This code does not actually work, it is for demonstration purposes
* of a router using https://github.com/boazsender/backbone.routefilter
*/
// Imagine this came from the server into a big app wide state object
// (likely a Backbone.Model if we were actually doing this for real).
var data = {
// Here are my app's pages (it's content heavy app)
"pages": [{
@bf4
bf4 / Gemfile
Last active November 11, 2017 22:18
Download my destroyallsoftware videos
# A sample Gemfile
source "https://rubygems.org"
gem 'mechanize'
@bensie
bensie / base.rb
Created December 6, 2012 17:53
Sinatra API Helpers
require "sinatra/base"
require "sinatra/namespace"
require "multi_json"
require "api/authentication"
require "api/error_handling"
require "api/pagination"
module Api
class Base < ::Sinatra::Base