Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
wohoo!

cf karlpokus

💭
wohoo!
View GitHub Profile
@karlpokus
karlpokus / redis_api.sh
Last active Nov 18, 2015
redis api in bash
View redis_api.sh
# simple string
SET name "fido"
GET name // "fido"
# increment
SET connections 10
INCR connections // 11
DEL connections // deleted
INCR connections // 1
View py_api.py
# http://thepythonguru.com/
# start
$ python3
# end
$ exit()
# run
$ python script.py
@karlpokus
karlpokus / dummydata.json
Last active Nov 25, 2015
Just some dummy data for API tests in codepen
View dummydata.json
{
"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 Jan 27, 2016
excel syntax
View excel.text
// 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 Feb 16, 2016
Randomize dataset by randomList of unique random values for GAS
View randomize.js
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 Feb 17, 2016
Range to json in google sheets
View data_to_json.js
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
Syntax to formulas in business objects (BO)
View BO_syntax.sh
**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
Number of days between two dates
View dayDiff.js
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 Jul 6, 2016
Mute and capture console.log in the browser
View mute.js
// 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 Jul 6, 2016
Timing execution time in server or browser
View timingExecution.js
// start
console.time('foo');
// do stuff
// end
console.timeEnd('foo');
// log output will be in ms -> foo: 268ms
You can’t perform that action at this time.