Skip to content

Instantly share code, notes, and snippets.

@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": [{
module Admin
class CategoriesController < BaseController
def new
@form = CategoryForm.new
end
def create
@form = CategoryForm.new(params[:category])
if @form.valid?
@jessefreeman
jessefreeman / GruntFile.js
Created August 20, 2013 12:52
Sample build script for Super Falling Zombies.
module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-shell');
grunt.loadNpmTasks('grunt-express-server');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-text-replace');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-open');
@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);
  }
 // ...
@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) { ... }
@bf4
bf4 / Gemfile
Last active November 11, 2017 22:18
Download my destroyallsoftware videos
# A sample Gemfile
source "https://rubygems.org"
gem 'mechanize'
@jklein
jklein / Vagrantfile
Last active September 19, 2018 10:18
Vagrant file for a private WebPagetest instance
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.
@monde
monde / .gitignore
Last active February 19, 2020 19:02
Micro Gem to get an OAuth token and secret for the Tumblr.com API allowing an external application to post Tumblr.com blog.
Gemfile.lock
@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