Skip to content

Instantly share code, notes, and snippets.

View toranb's full-sized avatar

Toran Billups toranb

View GitHub Profile
@toranb
toranb / withoutnew.js
Created August 3, 2012 22:44
How the new keyword works in javascript part 2
var Animal = function(omnivore) {
this.omnivore = omnivore;
}
var human = Animal(true);
console.log("the human is an omnivore " + human.omnivore);
//this will throw "TypeError: Cannot read property 'omnivore' of undefined"
@toranb
toranb / withapply.js
Created August 3, 2012 22:47
How the new keyword works in javascript part 3
var Animal = function(omnivore) {
this.omnivore = omnivore;
}
var human = {};
Animal.apply(human, [true]);
console.log("the human is an omnivore " + human.omnivore);
//this will print "the human is an omnivore true"
@toranb
toranb / withcall.js
Created August 3, 2012 23:03
How the new keyword works in javascript part 4
var Animal = function(omnivore) {
this.omnivore = omnivore;
}
var human = {};
Animal.call(human, true);
console.log("the human is an omnivore " + human.omnivore);
//this will print "the human is an omnivore true"
@toranb
toranb / package.json
Created September 1, 2012 19:29
npm package definition
{
"name": "unit_testing_javascript",
"description": "npm files needed to unit test javascript in isolation",
"version": "0.0.1",
"dependencies": {
"jasmine-node": "",
"jsdom": "",
"jasmine-jquery": ""
}
}
@toranb
toranb / osx_node_installer.sh
Created September 1, 2012 19:36
Install node on OSX
#!/bin/sh
brew install node
curl http://npmjs.org/install.sh | sh
export NODE_PATH="$NODE_PATH:/usr/local/lib/node_modules"
@toranb
toranb / hello.spec.js
Created September 1, 2012 23:45
My first jasmine unit test
describe ("first test suite", function(){
it ("2 should equal 2", function(){
expect("2").toBe("2");
});
it ("1 should not equal 2", function(){
expect("1").not.toBe("2");
});
})
@toranb
toranb / install_node.rb
Created September 2, 2012 00:07
Quick n dirty node installer for ubuntu
node_installed = `which node`
if node_installed.empty?
home_dir = "/home/someuserhere/"
node_dir = "#{home_dir}Downloads/"
node_download = "#{node_dir}joyent-node-v0.8.1-0-g2134aa3.zip"
node_extracted_dir = "#{node_dir}joyent-node/"
execute "rm -rf #{node_download}"
execute "rm -rf #{node_extracted_dir}"
@toranb
toranb / installnode.rb
Created September 4, 2012 14:18
quick n dirty node installer for ubuntu
node_dir = "/home/someuserhere/Downloads/"
node_download = "#{node_dir}joyent-node-v0.8.1-0-g2134aa3.zip"
node_extracted_dir = "#{node_dir}joyent-node/"
execute "rm -rf #{node_download}"
execute "rm -rf #{node_extracted_dir}"
execute "wget 'https://github.com/joyent/node/zipball/v0.8.1' -O #{node_download}"
execute "unzip #{node_download} -d #{node_extracted_dir}"
@toranb
toranb / phantomTestRunner.js
Created September 7, 2012 10:00
Simple command line javascript test runner using phantomjs-node
var phantom = require('phantom');
phantom.create(function(ph) {
return ph.createPage(function(page) {
return page.open("http://localhost:8090/runner.html", function(status) {
return page.evaluate((function() {
var results = $(document.body).find('.description')[0].text;
var failures = $(document.body).find(".description:contains('failures')");
if (failures.size() > 0) return "All tests passed! %@".fmt(results);
@toranb
toranb / filtersortpagemixin.js
Created September 24, 2012 02:37
filter/sort/pagination mixin for ember.js
var get = Ember.get;
/**
* @extends Ember.Mixin
*
* Implements common filter / sort / pagination behavior for array controllers
* */
Ember.FilterSortSliceMixin = Ember.Mixin.create({
filterBy: '',