Skip to content

Instantly share code, notes, and snippets.

View lorenzoongithub's full-sized avatar

lorenzo puccetti lorenzoongithub

  • london, united kingdom
View GitHub Profile
// Based on an article by kyle simpson - youdontknowjs
// ===================================================
//
// String(x)
//
if ( String(0) !== "0") throw ''
if ( String(.0) !== "0") throw ''
if ( String(-0) !== "0") throw ''
if ( isNaN( String(NaN) ) === false) throw ''
@lorenzoongithub
lorenzoongithub / testing underscore js
Last active August 29, 2015 14:17
testing underscore.js
//
// see: http://underscorejs.org/
//
load('http://underscorejs.org/underscore-min.js');
sum = 0;
_.each([1, 2, 3],function(i) { sum+=i });
if (sum !== 6) throw '';
// first cut.
// see: http://arasatasaygin.github.io/is.js/
//
load('http://arasatasaygin.github.io/is.js/scripts/is.js');
var getArguments = function() {
return arguments;
};
var arguments = getArguments();
@lorenzoongithub
lorenzoongithub / print additional props in window
Created March 25, 2015 21:07
additional properties in the window - little script to run on the chrome console
// make sure it doesn't count my own properties
(function () {
var results, currentWindow,
// create an iframe and append to body to load a clean window object
iframe = document.createElement('iframe');
iframe.style.display = 'none';
document.body.appendChild(iframe);
// get the current list of properties on window
currentWindow = Object.getOwnPropertyNames(window);
// filter the list against the properties that exist in the clean window
@lorenzoongithub
lorenzoongithub / esprima.js
Created April 14, 2015 20:01
a simple showcase for esprima
//
// Showcase for Esprima.
// http://esprima.org
//
// This work is based on the following work
// https://github.com/marijnh/acorn/blob/master/test/tests.js
//
load('http://esprima.org/esprima.js');
@lorenzoongithub
lorenzoongithub / equal.js
Last active August 29, 2015 14:19
equal.js
//
// A basic function to check whether two values are equal, in the intuitive sense.
//
function equal(a, b) {
if (a !== null && a !== undefined && b !== null && b !== undefined) {
if (a.length !== b.length) return false;
if (a !== a.toString() && b !== b.toString()) {
for (var i in a) { if (!equal(a[i],b[i])) return false; }
for (var i in b) { if (!equal(a[i],b[i])) return false; }
}
//
// javascript's math
//
var x = 0.1;
var y = 0.2;
if (x+y == 0.3) throw '';
if (x+y != 0.30000000000000004) throw '';
//
// A falsy value is a value that translates to false when evaluated in a Boolean context.
// see: https://developer.mozilla.org/en-US/docs/Glossary/Falsy
//
if (false) throw '';
if (null) throw '';
if (undefined) throw '';
if (0) throw '';
if (NaN) throw '';
if ('') throw '';
//
// see: papaparse.com
// use cases derived from https://raw.githubusercontent.com/mholt/PapaParse/master/tests/test-cases.js
//
load('http://papaparse.com/resources/js/papaparse.js');
//One row
oj = Papa.parse("A,b,c");
if (oj.data === null) throw "";
//
// numerals.js - a javascript library for formatting and manipulating numbers
//
// http://numeraljs.com/
// https://github.com/adamwdraper/Numeral-js
//
//
// This work has been derived from
// https://github.com/adamwdraper/Numeral-js/blob/master/tests/numeral/format.js
//