Skip to content

Instantly share code, notes, and snippets.

View JakobJingleheimer's full-sized avatar

Jacob Smith JakobJingleheimer

View GitHub Profile
import path from 'path';
import { pathToFileURL } from 'url';
const npmPackage = await import(
pathToFileURL(`${process.cwd()}/package.json`).href
).then(({ default: json }) => json);
const aliases = (() => {
const base = process.cwd();
const { aliases } = npmPackage || {};
@JakobJingleheimer
JakobJingleheimer / mergeSort.js
Created August 3, 2018 08:26
recursive merge sort: Average runtime O(log n)
function mergeSort(arr, low = 0, top = arr.length - 1) {
if (low < top) {
const mid = Math.floor((low + top) / 2);
mergeSort(arr, low, mid);
mergeSort(arr, mid+1, top);
merge(arr, low, mid, top);
}
/**
* Find a number in an ordered list of numbers. It does cheap detection for common invalid input:
* * Argument types
* * An incorrectly sorted list (descending)
* * An unsorted list
* @param {number} x - The "needle" for which to search
* @param {array<number>} arr - The list to search
* @return {number} - The (first) index where `x` occurs in `arr`, or `-1` when not found.
* @example
* binarySearch(2, [-1, 0, 0.5, 0.75, 1, 2, 5, 10]); // 5
@JakobJingleheimer
JakobJingleheimer / twitter.js
Last active December 31, 2015 11:09
WebSocket (socket.io) proxy for Twitter stream (Twit).
// var server …
// …
var io = require('socket.io').listen(server),
Twit = require('twit');
var twitter = new Twit({ … });
io.sockets.on('connection', function connect( socket )
{
function emitTweets( sn , tweets )
@JakobJingleheimer
JakobJingleheimer / controllers.js
Created April 19, 2013 20:15
Html markup for uiMap (before refactor)
//…
$scope.openMarkerInfo = function(marker)
{
$scope.currentMarker = marker;
$scope.currentMarkerLat = marker.getPosition().lat();
$scope.currentMarkerLng = marker.getPosition().lng();
$scope.model.myInfoBox.open($scope.model.myMap, marker);
};
//…