Skip to content

Instantly share code, notes, and snippets.

View jhurliman's full-sized avatar
🐨

John Hurliman jhurliman

🐨
View GitHub Profile
@jhurliman
jhurliman / binaryninja-dijkstra.cpp
Created December 13, 2016 23:16
Find the shortest distance between source and target basic blocks in Binary Ninja
namespace BN = BinaryNinja;
using std::map;
using std::pair;
using std::priority_queue;
using std::vector;
int32_t dijkstra(vector<BN::Ref<BN::BasicBlock>> blocks, BN::Ref<BN::BasicBlock> source, BN::Ref<BN::BasicBlock> target) {
using path = pair<int32_t, uint64_t>;
@jhurliman
jhurliman / recent-ios-reviews-score.sh
Last active April 3, 2016 19:26
Return the average review score based on recent reviews for an app store app
#!/usr/bin/env bash
COUNTRY=us
APPID=1081557588
curl -s "https://itunes.apple.com/${COUNTRY}/rss/customerreviews/id=${APPID}/sortBy=mostRecent/json" |\
jq '[.feed.entry[]."im:rating".label // empty | tonumber] | add/length'
@jhurliman
jhurliman / cesium-oakland.js
Created February 8, 2016 19:25
Cesium.js viewer for Oakland buildings
var viewer = new Cesium.Viewer('cesiumContainer', {timeline: false, animation: false});
var promise = Cesium.GeoJsonDataSource.load(
'https://s3.amazonaws.com/jhurliman/oakland-building-footprints.geojson');
promise.then(function(dataSource) {
viewer.dataSources.add(dataSource);
// Get the array of buildings
var entities = dataSource.entities.values;
@jhurliman
jhurliman / es7-setup.md
Last active January 26, 2016 00:23
ES6/ES7 setup for sandbox development of modern code

These instructions will allow you to write and run one-off node.js scripts using modern ECMAScript syntax, including async/await.

  1. Install Babel globally

npm install -g babel-cli

  1. Add a .babelrc file to the folder holding your code containing the following:

{ "presets": [ "es2015", "stage-3" ] }

@jhurliman
jhurliman / mapAsync.js
Created January 25, 2016 05:06
ES7 implementation of Array.map() and the equivalent for objects
import PromisePool from 'es6-promise-pool'
/**
* Like Array.map() but supports promises and concurrency limiting.
* @param {array} array - Input array to map.
* @param {function} asyncFn(currentValue, index, array) - Called once for each
* value in the array.
* @param {number} [concurrencyLimit] - Optional cap on the number of
* asynchronous methods to execute at once.
* @returns {array} An array containing the mapped output values.
@jhurliman
jhurliman / hackernews-headlines.sh
Created January 15, 2016 20:13
XScreenSaver Apple II Emulator - Hacker News Headlines
curl -silent https://news.ycombinator.com/rss | grep -no '<item><title>[^<]*' | sed 's/<item><title>//'
@jhurliman
jhurliman / hash-buckets.js
Created January 4, 2016 19:25
Demonstration of uniformly allocating integers into a fixed number of hash buckets
import * as math from 'mathjs'
const MINUTES_PER_DAY = 1440
const REFRESH_MINUTES = 1
const HASH_BUCKETS = MINUTES_PER_DAY / REFRESH_MINUTES
const MAX_IDS = 291554
main()
@jhurliman
jhurliman / optimization-test.js
Last active December 13, 2015 20:17
Use V8 internal methods to test if a JS function can be optimized
/**
* Based on code from <https://github.com/petkaantonov/bluebird/wiki/Optimization-killers>
* Run this script using:
* `node --allow-natives-syntax optimization-test.js`
* For more diagnostic output use:
* `node --trace_opt --trace_deopt --allow-natives-syntax optimization-test.js`
*/
function myFunction() {
return 'hello world';
@jhurliman
jhurliman / uuid.js
Created November 22, 2015 04:31
Generate V4 UUIDs in node.js
function uuid() {
var bytes = require('crypto').randomBytes(16);
bytes[6] = (bytes[6] & 0x0f) | 0x40;
bytes[8] = (bytes[8] & 0x3f) | 0x80;
var str = bytes.toString('hex');
return str.substr(0, 8) + '-' +
str.substr(8, 4) + '-' +
str.substr(12, 4) + '-' +
str.substr(16, 4) + '-' +
str.substr(20, 12);
@jhurliman
jhurliman / ec2-instance-info.js
Created November 6, 2015 22:25
Retrieve metadata about the host EC2 instance
var P = require('bluebird');
var request = P.promisify(require('request'));
P.promisifyAll(request);
exports.currentInstanceInfo = currentInstanceInfo;
var INSTANCE_BASE_URL = 'http://169.254.169.254/2014-11-05/';
currentInstanceInfo().then(res => console.dir(res));