Skip to content

Instantly share code, notes, and snippets.

View karlpokus's full-sized avatar
💭
wohoo!

carl-fredrik grimberg karlpokus

💭
wohoo!
View GitHub Profile
@karlpokus
karlpokus / redis_api.sh
Last active November 18, 2015 15:35
redis api in bash
# simple string
SET name "fido"
GET name // "fido"
# increment
SET connections 10
INCR connections // 11
DEL connections // deleted
INCR connections // 1
@karlpokus
karlpokus / py_api.py
Created November 23, 2015 13:48
python API
# http://thepythonguru.com/
# start
$ python3
# end
$ exit()
# run
$ python script.py
@karlpokus
karlpokus / dummydata.json
Last active November 25, 2015 14:49
Just some dummy data for API tests in codepen
{
"data": [
{
"id":1, "name": "Mike", "human": true
},
{
"id":2, "name": "Lucy", "human": false
},
{
"id":3, "name": "Arnold", "human": true
@karlpokus
karlpokus / excel.text
Last active January 27, 2016 13:05
excel syntax
// count unique values in pivot
http://stackoverflow.com/questions/11876238/simple-pivot-table-to-count-unique-values
Use "distinct antal" in dialog
@karlpokus
karlpokus / randomize.js
Created February 16, 2016 11:48
Randomize dataset by randomList of unique random values for GAS
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) {
//
@karlpokus
karlpokus / data_to_json.js
Last active February 17, 2016 08:45
Range to json in google sheets
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 = {};
@karlpokus
karlpokus / BO_syntax.sh
Last active May 23, 2016 06:45
Syntax to formulas in business objects (BO)
**VARIABLER**
# calc age
=Om Längd([Personnummer]) <= 13
TillNummer(FormatDatum(AktuelltDatum(); "yyyy")) -
TillNummer(Delstr([Personnummer]; 0; 4))
Annars "-"
# relative date; today -n month
@karlpokus
karlpokus / dayDiff.js
Last active May 31, 2016 12:56
Number of days between two dates
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));
}
}
@karlpokus
karlpokus / mute.js
Last active July 6, 2016 08:40
Mute and capture console.log in the browser
// completely mute
console.log = function() {};
// captured data in log
var log = [];
console.log = function() {
log.push([].slice.call(arguments));
};
// fancy namespaced version. Demo -> http://codepen.io/KarlPokus/pen/rLwXQX/
@karlpokus
karlpokus / timingExecution.js
Last active July 6, 2016 08:52
Timing execution time in server or browser
// start
console.time('foo');
// do stuff
// end
console.timeEnd('foo');
// log output will be in ms -> foo: 268ms