Skip to content

Instantly share code, notes, and snippets.

View eplawless's full-sized avatar

Eric Lawless eplawless

View GitHub Profile
@eplawless
eplawless / gist:1256645
Created October 1, 2011 20:51
0x stuff
template <typename uint_t>
uint_t
PointKDTreeImplImpl<uint_t>::partitionAroundMedian(
uint_t idxBegin,
uint_t idxEnd,
KDTreeAxis axis)
{
uint_t halfSize = (idxEnd - idxBegin) / 2;
uint_t idxMedian = idxBegin + halfSize;
@eplawless
eplawless / selectListOfMostRecent.js
Last active August 29, 2015 14:02
selectListOfMostRecent
var Rx = require('rx');
(function(exports) {
function shiftLeft(list, value) {
var result = list.slice(1);
result.push(value);
return result;
}
@eplawless
eplawless / refcount.js
Created February 12, 2015 18:38
The semantic I expected from .publish().refCount()
var Rx = require('rx');
function RefCountObservable(source) {
this._source = source;
}
RefCountObservable.prototype = Object.create(Rx.Observable.prototype);
RefCountObservable.prototype._refCount = 0;
RefCountObservable.prototype._subject = null;
function NOOP() {}
var button = getSomeButtonSomehow();
// all of these Animation objects are immutable, and just describe the motion
var moveRight = Animate.positionX({ from: 0, to: 100, ease: Easing.easeOut, duration: 200 });
var moveDown = Animate.positionY({ from: 0, to: 100, ease: Easing.easeOut, duration: 200 });
var fadeOut = Animate.opacity({ to: 0, ease: Easing.cubicBezier(0,1,1,0), duration: 50 });
var move = moveRight.with(moveDown, 100); // start moveDown 100ms after moveRight starts
var reusableAnimation = move.then(fadeOut, -fadeOut.duration); // start fadeOut 50ms before move ends
function hash(str) {
var len = str.length;
var hash = 5381;
for (var idx = 0; idx < len; ++idx) {
hash = 33 * hash + str.charCodeAt(idx);
}
return hash;
}
@eplawless
eplawless / Navigation.js
Last active August 29, 2015 14:23
react router injection
import getNavigation from './getNavigation';
import React from 'react';
export default getNavigation({ React });
@eplawless
eplawless / output.txt
Last active April 18, 2016 05:15
Node's TCP sockets hardcode SO_REUSEADDR by default and this cannot be changed
Using IPv4 unspecified address 0.0.0.0
Using IPv6 unspecified address ::
Interface lo0 has address ::1
Interface lo0 has address 127.0.0.1
Interface lo0 has address fe80::1%lo0
Interface en0 has address 192.168.1.7
Starting too many servers on port 4567...
Listening on 0.0.0.0 port 4567
Listening on :: port 4567
Listening on ::1 port 4567
@eplawless
eplawless / node-is-a-liar-snippet-1.js
Created April 18, 2016 05:46
Let's open up a TCP server on port 4000!
var net = require('net');
var server = net.createServer();
server.listen(4000, function() {
console.log('Listening on port 4000!');
});
server.on('error', function(error) {
console.error('Help!', error);
});
@eplawless
eplawless / node-is-a-liar-snippet-2.js
Created April 18, 2016 07:46
This had better not work...
var net = require('net');
function startServer(port, host, callback) {
var server = net.createServer();
server.listen(port, host, function() {
callback(undefined, server);
});
server.on('error', function(error) {
console.error('Ah damn!', error);
callback(error);
@eplawless
eplawless / node-is-a-liar-snippet-3.js
Created April 18, 2016 08:53
Get all local host addresses
var os = require('os');
function getLocalHosts() {
var hosts = ['0.0.0.0', '::'];
var interfaces = os.networkInterfaces();
Object.keys(interfaces).forEach(function(interfaceName) {
var interface = interfaces[interfaceName];
interface.forEach(function(info) {
var address = info.address;
// append the interface name onto link-local IPv6 addresses