Skip to content

Instantly share code, notes, and snippets.

View geekdenz's full-sized avatar
🙂
Zen

Tim-Hinnerk Heuer geekdenz

🙂
Zen
View GitHub Profile
interface Array<T> {
flatMap: () => T[]
}
Array.prototype.flatMap = function() {
function innerFlatMap(arr) {
if (arr instanceof Array) {
return arr.reduce((r, e) => r.concat(innerFlatMap(e)), []);
}
return arr;
}
@geekdenz
geekdenz / pipe.js
Created June 22, 2017 10:14
Pipe your shell programs through JavaScript.
var readline = require('readline');
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});
var f = process.argv[2];
rl.on('line', function(line){
var str = line.replace(/[\""]/g, '\\"');
@geekdenz
geekdenz / mysql_dump_all_dbs.bash
Created May 30, 2017 08:27
MySQL: Dump all DBs except meta data such as mysql, information_schema and performance_schema.
#!/bin/bash
MYSQL_USER=root
OUT_FILE=$1
MYSQL_PASS=$2
MYSQL_CONN="-u${MYSQL_USER} -p${MYSQL_PASS}"
#
# Collect all database names except for
# mysql, information_schema, and performance_schema
#
SQL="SELECT schema_name FROM information_schema.schemata WHERE schema_name NOT IN"
This file has been truncated, but you can view the full file.
@geekdenz
geekdenz / bind2.js
Created February 15, 2016 10:37
Description of closures on a semi-useful function bind2.
'use strict';
function log() {
//document.getElementById('log').innerHTML += Array.prototype.join.apply(arguments, ["\n"]) + "\n\n";
console.log(arguments);
}
Function.prototype.bind2 = function (o) {
var fn = this;
log('closure this:', this, "\nfn:", fn);
return function () {
@geekdenz
geekdenz / countries.json
Last active August 29, 2015 14:02 — forked from keeguon/countries.json
Valid JSON Countries file.
[
{"name": "Afghanistan", "code": "AF"},
{"name": "Åland Islands", "code": "AX"},
{"name": "Albania", "code": "AL"},
{"name": "Algeria", "code": "DZ"},
{"name": "American Samoa", "code": "AS"},
{"name": "AndorrA", "code": "AD"},
{"name": "Angola", "code": "AO"},
{"name": "Anguilla", "code": "AI"},
{"name": "Antarctica", "code": "AQ"},