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 / gas.js
Last active May 24, 2018 13:36
google sheets API
// 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
@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 / 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 / unique.js
Last active January 31, 2017 09:57
Unique items in array. Return count or items.
// data is an array
function unique(data) {
return data.reduce(function(base, item){
if (base.indexOf(item) < 0 ) {
base.push(item);
}
return base
}, [])
}
@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 / 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 / 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