Skip to content

Instantly share code, notes, and snippets.

@punund
punund / 0_reuse_code.js
Created January 21, 2014 10:59
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
var bases = require('bases');
var crypto = require('crypto');
// Returns a base-62 (alphanumeric only) string of the given length:
function randomStr(length) {
// We generate a random number in a space at least as big as 62^length,
// and if it's too big, we just retry. This is still statistically O(1)
// since repeated probabilities less than one converge to zero. Hat-tip to
// a Google interview for teaching me this technique! ;)
@punund
punund / gist:1034276
Created June 19, 2011 13:31
Proper exception handling in Rails 3
# coding: utf-8
class ApplicationController < ActionController::Base
protect_from_forgery
rescue_from Exception, :with => :handle_exceptions
private
def handle_exceptions(e)
case e
when CanCan::AccessDenied