Skip to content

Instantly share code, notes, and snippets.

View joshnesbitt's full-sized avatar

Josh Nesbitt joshnesbitt

View GitHub Profile
function sayHello(name){
console.log("Hi " + name + "!");
};
var name = "Bill";
{
var name = "Bob";
sayHello(name);
};
require 'rubygems'
require 'redcarpet'
require 'pathname'
path = Pathname.new(ARGV.shift)
raise "Input path must be absolute." unless path.absolute?
raise "Input path must point to a file that exists" unless path.exist?
raise "Input path must point to a file that is readable" unless path.readable?
// #suite is a helper method to more concisely list
// #describe groups. Example usage:
//
// suite("Examples", {
//
// "before" : function(){
// // ... setup
// },
//
// "should one" : function(){
(function(window) {
// stuff that uses window a lot here...
})(window);
@joshnesbitt
joshnesbitt / args.js
Created September 22, 2011 10:04
Turning a functions arguments into an array
var test = function(){
var args = arguments;
args.push(4);
console.log(args);
}
// Results in a TypeError, as arguments isn't actually an array object.
// To coerce arguments to an array, call Array's slice method:
var test = function(){
@joshnesbitt
joshnesbitt / production.rb
Created August 31, 2011 16:01
Rails 3.1 upgrade options
config.assets.compress = true
config.assets.compile = true
config.assets.digest = true
# Random idea to use a single integer attribute to store information
# about a group of predefined items on any given object. More about
# bitwise operations and bit shifting: http://en.wikipedia.org/wiki/Bitwise_operation
require 'groupable'
class User
include Groupable
group :roles, %w{ basic admin }
@joshnesbitt
joshnesbitt / gist:1048447
Created June 27, 2011 07:32 — forked from clarkware/gist:1046693
View Source for Ruby
# Toss this in your ~/.irbrc file for a convenient way
# to peruse Ruby source code in TextMate. This
# only works in Ruby 1.9!
#
# Use it in irb like so:
#
# >> require 'active_record'
# >> ActiveRecord::Base.source_for_method(:create)
class Object
@joshnesbitt
joshnesbitt / LICENSE.txt
Created May 16, 2011 12:04 — forked from jed/LICENSE.txt
calculate # of ms/seconds/minutes/hours/days in the past
Copyright (c) 2011 Jed Schmidt, http://jed.is
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
function HostInformation(target, opts){
var opts = opts || {},
output = {},
target = target.location || target;
this.host = function()
{
return target.host;
}