Skip to content

Instantly share code, notes, and snippets.

View lorenzoongithub's full-sized avatar

lorenzo puccetti lorenzoongithub

  • london, united kingdom
View GitHub Profile
@lorenzoongithub
lorenzoongithub / uri.js
Last active August 29, 2015 14:22
uri.js
//
// URI.js is a javascript library for working with URLs
// http://medialize.github.io/URI.js/
//
load('https://cdnjs.cloudflare.com/ajax/libs/URI.js/1.15.2/URI.min.js');
u = new URI("http://www.example.org");
if (u.protocol() !== "http") throw "";
if (u.username() !== "") throw "";
load('https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/3.0.3/handlebars.min.js');
//
// Basic Stuff
//
r = Handlebars.compile('{{test}}')({test:1});
if (r !== '1') throw ''
r = Handlebars.compile('{{test}} is {{test}}')({test:1});
if (r !== '1 is 1') throw ''
//
// An example to show the 'waitUntil' function
//
var x = 0;
setTimeout(function() { x = 1; },1000);
waitUntil(x==1);
setTimeout(function() { x = 2; },2000);
waitUntil(x==2);
// THE CODE BELOW WAS ADAPTED FROM https://gist.github.com/jeffcogswell/8257755
// Q sample by Jeff Cogswell
/*
We want to call three functions in sequence, one after the other:
First we want to call one, which initiates an ajax call. Once that
ajax call is complete, we want to call two. Once two's ajax call is
complete, we want to call three.
//
// Simple use case for: https://github.com/getify/grips
//
load('http://getify.github.io/grips/deploy_0.3.3-a/grips-full.debug.js');
var text = '{$define "#main" }Hello <b>{$insert $.who $}</b>!{$}';
grips.compileCollection(text,'sample_tmpl_1');
v = grips.render("sample_tmpl_1#main", {"who":"World"});
if (v != 'Hello <b>World</b>!') throw '';
//
// xregexp - The one of a kind JavaScript regular expression library
// https://github.com/slevithan/xregexp
// (this code is an adaptation on the example on the main page on github)
//
load('//cdnjs.cloudflare.com/ajax/libs/xregexp/2.0.0/xregexp-min.js');
// Using named capture and flag x (free-spacing and line comments)
var date = XRegExp('(?<year> [0-9]{4} ) -? # year \n\
@lorenzoongithub
lorenzoongithub / immutable.js
Last active August 29, 2015 14:23
immutable.js
//
// Description:
// A manual port of the tests here: https://github.com/facebook/immutable-js (4/Feb/2015)
//
//
load("https://cdnjs.cloudflare.com/ajax/libs/immutable/3.6.2/immutable.min.js");
map1 = Immutable.Map({ a: 1, b: 2, c: 3 });
map2 = map1.set("b", 2);
@lorenzoongithub
lorenzoongithub / tc39-test-262-toString.js
Created June 23, 2015 19:53
TC39 - test 262 - toString
//
// test-262 - toString
// The snippet of code here was derived by the js files here:
// https://github.com/tc39/test262/tree/master/test/built-ins/Object/prototype/toString
//
if (Object.prototype.toString.call(undefined) !== "[object Undefined]") throw ''; //15.2.4.2-1-1.js
if (Object.prototype.toString.apply(undefined, []) !== "[object Undefined]") throw ''; //15.2.4.2-1-2.js
if (Object.prototype.toString.call(null) !== "[object Null]") throw ''; //15.2.4.2-2-1.js
if (Object.prototype.toString.apply(null, []) !== "[object Null]") throw ''; //15.2.4.2-2-2.js
//
// test-262 - infinity
// The snippet of code here was derived by the js files here:
// https://github.com/tc39/test262/tree/master/test/built-ins/Infinity
//
// 15.1.1.2_A1
if (typeof(Infinity) !== 'number') throw ''
if (isFinite(Infinity) !== false) throw ''
if (isNaN(Infinity) !== false) throw ''
//
// jasmine
//
load('https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.3.4/jasmine.js');
load('https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.3.4/jasmine-html.js');
load('https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.3.4/boot.js');
describe("A suite is just a function", function() {
var a;
it("and so is a spec", function() {