Skip to content

Instantly share code, notes, and snippets.

@waggertron
waggertron / destructuring.js
Created October 18, 2016 18:09 — forked from mikaelbr/destructuring.js
Several demos and usages for ES6 destructuring. Runnable demos and slides about the same topic: http://git.mikaelb.net/presentations/bartjs/destructuring
// === Arrays
var [a, b] = [1, 2];
console.log(a, b);
//=> 1 2
// Use from functions, only select from pattern
var foo = () => [1, 2, 3];
@waggertron
waggertron / introrx.md
Created November 9, 2016 03:15 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
@waggertron
waggertron / introrx.md
Created November 9, 2016 03:15 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
@waggertron
waggertron / gist:5a57a584f876d49b6b92b02e1fc9a18d
Created December 8, 2016 07:01 — forked from dburger/gist:1008320
Javascript Array Binary Heap
/*
array implementation of a binary heap, example usage:
// can optionally provide a comparison function, a function for a max
// heap is the default if no comparison function is provided
var bh = binaryHeap();
bh.push(5);
bh.push(34);
bh.push(16);
var max = bh.pop(); // 34
@waggertron
waggertron / after_res_hooks.js
Created December 10, 2016 22:21 — forked from pasupulaphani/after_res_hooks.js
Mongoose connection best practices
var db = mongoose.connect('mongodb://localhost:27017/DB');
// In middleware
app.use(function (req, res, next) {
// action after response
var afterResponse = function() {
logger.info({req: req}, "End request");
// any other clean ups
@waggertron
waggertron / pub-sub.js
Created February 15, 2017 04:48 — forked from reu/pub-sub.js
node.js redis pub-sub example
var redis = require("redis")
, subscriber = redis.createClient()
, publisher = redis.createClient();
subscriber.on("message", function(channel, message) {
console.log("Message '" + message + "' on channel '" + channel + "' arrived!")
});
subscriber.subscribe("test");
@waggertron
waggertron / main.c
Created October 1, 2018 21:54
two loop solution
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char * char_repeat( int n, char c ) {
char * dest = malloc(n+1);
memset(dest, c, n);
dest[n] = '\0';
return dest;
}
@waggertron
waggertron / main.c
Created October 1, 2018 22:53
build pyramid one loop construction
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char * char_repeat( int n, char c ) {
char * dest = malloc(n+2);
memset(dest, c, n);
dest[n] = '\n';
dest[n + 1] = '\0';
return dest;
// https://www.reddit.com/r/dailyprogrammer/comments/98ufvz/20180820_challenge_366_easy_word_funnel_1/
const fs = require('fs');
const { promisify } = require('util');
const readFilePromise = promisify(fs.readFile);
const makeWordSet = async file => new Set((await promisify(fs.readFile)(file, 'utf8')).split('\n'));
function funnel(word1, word2) {
@waggertron
waggertron / nodegit-private-clone-test.js
Created December 10, 2018 21:42 — forked from mojavelinux/nodegit-private-clone-test.js
Clone a private repository using nodegit
const git = require('nodegit')
const fs = require('fs-extra')
const { URL } = require('url')
const REPO_URL = 'git@github.com:org/path.git'
const CLONE_DIR = '/tmp/private-repo-clone-test'
;(async () => {
await fs.emptyDir(CLONE_DIR)
let authAttempted = false
await git.Clone.clone(REPO_URL, CLONE_DIR, {