Skip to content

Instantly share code, notes, and snippets.

View denizozger's full-sized avatar
🧿

Deniz Ozger denizozger

🧿
  • Zurich, Switzerland
View GitHub Profile
@denizozger
denizozger / log_object
Created December 10, 2013 15:15
Log a Javascript object preventing circular structure error (a minor amendment to http://stackoverflow.com/a/9653082)
var testObject = {
id : 5,
name : 'foo'
}
function censor(censor) {
return (function() {
var i = 0;
return function(key, value) {
@denizozger
denizozger / commentsToTree.js
Last active August 29, 2015 13:57
Sort a list of comments in date and reply order
/**
* Given a list of random comments, having dates and parentIds, this code
* sorts the list following parent-child relationships and dates.
*
* Notation:
* C1R2 stands for 'Second reply to first comment'
* C2R2R1R1 stands for '1st Reply to the 1st Reply to the
* 2nd Reply of the 2nd Comment'
*
* Input:
@denizozger
denizozger / multiple_settimeouts.js
Created August 5, 2016 12:07
Visualise settimeout behaviour in call stack
function log(n) { console.log(n); }
setTimeout(function A() {
setTimeout(function B() {
log(1);
setTimeout(function D() { log(2); }, 0);
setTimeout(function E() { log(3); }, 0);
}, 0);
setTimeout(function C() {
@denizozger
denizozger / error_after_callback_return.js
Created August 5, 2016 12:16
Demonstrate why Error()'s are useless when callback queue is used
var getValue = function(value, cb) {
setTimeout(function err() {
throw Error();
}, 0);
return cb(null, value);
};
var result = getValue(5, (err, a) => {
console.log(a);
});
#!/bin/bash
# This script confirms that the version we have now doesn't already exist in npm
GREEN='\033[0;32m'
RED='\033[0;31m'
CYAN='\033[0;36m'
NC='\033[0m'
# Version key/value should be on its own line
@denizozger
denizozger / pasc
Last active December 4, 2016 16:36
Show scripts
$ brew install jq
$ echo "alias pasc='cat package.json | jq -r .scripts'" >> ~/.bashrc
$ source ~/.bashrc
$ pasc
{
"start": "node server.js",
"test": "echo \"Error: no test specified\" && exit 1"
}
@denizozger
denizozger / fxn.js
Created December 13, 2016 18:09
Ramda cheatsheet
// Replace this:
for (const value of myArray) {
console.log(value)
}
// with:
forEach(value => console.log(value), myArray)
const double = x => x * 2
map(double, [1, 2, 3])
@denizozger
denizozger / monitor.js
Created March 10, 2017 13:23
New Relic Synthetics Monitoring Script
var assert = require('assert');
var options = {
'auth': {
'user': 'USER',
'pass': 'PASS',
'sendImmediately': false
}
};
@denizozger
denizozger / new_relic_new_health_script.js
Last active March 14, 2017 12:40
New health check script
var assert = require('assert');
var options = {
'auth': {
'user': 'USER',
'pass': 'PASS',
'sendImmediately': false
}
};
# Run this in conjunction with https://github.com/jishi/node-sonos-http-api
import urllib.request
import json
import time
BANNED_ARTISTS = ['drake']
while True:
state = json.loads(urllib.request.urlopen("http://localhost:5005/state").read().decode('utf-8'))