Skip to content

Instantly share code, notes, and snippets.

View hojberg's full-sized avatar
🔮
Building UIs for Unison

Simon Højberg hojberg

🔮
Building UIs for Unison
View GitHub Profile
testing gist
# General
alias l='ls -lash -G'
alias ll='ls -lash -G'
alias h='history'
alias flush='sudo dscacheutil -flushcache'
# ruby
alias mygems="gem list | grep ’^[a-zA-Z]’"
# Rails
var app = {
before: function () { console.log("i am going to be runned before all other functions") },
func1: function () {
console.log("func1");
},
func2: function () {
console.log("func2");
}
var app = {
before: function () { console.log("i am going to be runned before all other functions") },
func1: function () {
console.log("func1");
},
func2: function () {
console.log("func2");
}
// Simplified example
App.Controllers.Sales = Object.create(App.Controllers.Master, {
all: function () {
// Find all method on Sale initiates a callback when data has returnes
App.Models.Sale.findAll(function () {
// render method on $ initiate a callback when the template has been loaded in the dom
$('contentarea').render("sales/all", function (sales) {
// Pure template autoRender method finds some id and auto loops over and array
$('#id-of-a-list-of-sales').autoRender(sales);
@hojberg
hojberg / sandboxtesting1.js
Created February 13, 2010 12:27
how to make testing possible of sandboxed api #1
(function () {
var PublicAPI = window.PublicAPI = {};
PublicAPI.publicFunction = function (foo) {
PrivateAPI.privateFunction(foo);
return 'bar';
};
var PrivateAPI = {};
PrivateAPI.privateFunction = function (foo) {
@hojberg
hojberg / sandboxtesting2.js
Created February 13, 2010 12:29
how to make testing possible of sandboxed api #2
(function () {
var PublicAPI = window.PublicAPI = {};
PublicAPI.publicFunction = function (foo) {
PrivateAPI.privateFunction(foo);
return 'bar';
};
var PrivateAPI = {};
PrivateAPI.privateFunction = function (foo) {
# Classical
class Animal
color: 'brown'
sleep: (minutes) ->
"sleeping for " + minutes + " minutes"
class Horse extends Animal
legs: 4
gallop: ->
"galloping happily"
# http://en.wikipedia.org/wiki/Bank_card_number
CARDTYPES = {
:visa => /^4(?!571|917|913|508|844|17500)[0-9]{12,15}$/,
:mastercard => /^5(?!4130380)[1-5][0-9]{14}$/,
:dinersclub => /^3(?:0[0-5]|[68][0-9])[0-9]{11}$/,
:amex => /^3[47][0-9]{13}$/,
:discover => /^6(?:011|5[0-9]{2})[0-9]{12}$/,
:visadankort => /^4571[0-9]{12}$/,
:dankort => /^5019[0-9]{12}$/,
:eurocardbyinvitation => /^54130380\d{8}/,
(function () {
W.GET("/", function () {
$('#app').html("Hello World");
});
W.GET("#users", function () {
$('#app').html("users");
});