This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// start | |
console.time('foo'); | |
// do stuff | |
// end | |
console.timeEnd('foo'); | |
// log output will be in ms -> foo: 268ms |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This only works if you call - return next - in your middleware. Otherwise the cb (i.e next) won't return anything and the var will be undefined | |
// And you don't even need node - You can run it in a browser - Totally runtime agnostic | |
// Reference -> https://github.com/karlpokus/konstapel/blob/master/test/tests.js | |
var test = require('tape'), | |
m = require('module'); | |
test('.usernameIsValid', function(t){ | |
// mock req, res and next | |
var pass = m.usernameIsValid({user: {}}, null, function(){ return true }), | |
fail = m.usernameIsValid({}, null, function(err){ return err }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MAPPY | |
Array.prototype.mappy = function(fn, that) { | |
var out = [], | |
x, | |
that = that || {}; | |
for (var i = 0; i < this.length; i++) { | |
x = fn.call(that, this[i], i, this); | |
out.push(x); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
**VARIABLER** | |
# calc age | |
=Om Längd([Personnummer]) <= 13 | |
Så | |
TillNummer(FormatDatum(AktuelltDatum(); "yyyy")) - | |
TillNummer(Delstr([Personnummer]; 0; 4)) | |
Annars "-" | |
# relative date; today -n month |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function dayDiff(f, s, abs){ | |
var f = new Date(f), | |
s = new Date(s), | |
oneDay = 24*60*60*1000; | |
if (abs) { | |
return Math.round(Math.abs((f.getTime() - s.getTime())/(oneDay))); | |
} else { | |
return Math.round((f.getTime() - s.getTime())/(oneDay)); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function randomList(range, n) { | |
// | |
var checklist = [], out = []; | |
// loop | |
for (var i = 0; out.length < n; i++) { | |
// | |
var num = Math.floor((Math.random() * range)); | |
// if not in checklist | |
if (checklist.indexOf(num) === -1) { | |
// |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// data is an array | |
function unique(data) { | |
return data.reduce(function(base, item){ | |
if (base.indexOf(item) < 0 ) { | |
base.push(item); | |
} | |
return base | |
}, []) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function dataToJSON(data) { | |
// out | |
var out= []; | |
// split | |
var header = data[0], | |
body = data.slice(1); | |
// body LOOP | |
for (var i = 0; i < body.length; i++) { | |
// | |
var o = {}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// count unique values in pivot | |
http://stackoverflow.com/questions/11876238/simple-pivot-table-to-count-unique-values | |
Use "distinct antal" in dialog |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// count by regex | |
COUNTIF(range, "F1*") | |
// countif more/less | |
COUNTIF(range, ">2015-01-01") | |
// countif NOT | |
COUNTIF(range, "<>Läkare") | |
// url - google sheets regex syntax |