Skip to content

Instantly share code, notes, and snippets.

View jhurliman's full-sized avatar
🐨

John Hurliman jhurliman

🐨
View GitHub Profile
@jhurliman
jhurliman / famous-sleepOnIdle.js
Last active August 29, 2015 14:01
famo.us - Sleep after n milliseconds of no touch/mouse movement
var Engine = require('famous/core/Engine');
/**
* Sleep after n milliseconds of no touch/mouse movement
*/
function sleepOnIdle(idleMS) {
var lastMoveMS = Date.now();
window.addEventListener('mousemove', _handleMovement, true);
window.addEventListener('touchmove', _handleMovement, true);
@jhurliman
jhurliman / RenderPool.js
Created April 17, 2014 08:29
famo.us RenderPool. Work in progres...
define(function(require, exports, module) {
var RenderNode = require('famous/core/RenderNode');
var Modifier = require('famous/core/Modifier');
var Surface = require('famous/core/Surface');
function RenderPool() {
this._node = new RenderNode();
this._children = {};
this._unusedChildren = [];
@jhurliman
jhurliman / famous-scrollview-nodechange.js
Last active August 29, 2015 13:59
famo.us - Emit an event from Scrollview when the current node changes
myScrollView.render = function() {
_tickScrollViewRender() {
var prevNode = this._node;
var retValue = Scrollview.prototype.render.call(this);
var node = this._node;
if (node !== prevNode)
this._eventOutput.emit('sequenceChange', { node: node, prevNode: prevNode });
@jhurliman
jhurliman / famous-slidepanel.js
Created April 10, 2014 07:04
famo.us Slide Panel
/*globals define*/
define(function(require, exports, module) {
'use strict';
// import dependencies
var Engine = require('famous/core/Engine');
var Surface = require('famous/core/Surface');
var Modifier = require('famous/core/Modifier');
var Transform = require('famous/core/Transform');
var Utility = require('famous/utilities/Utility');
@jhurliman
jhurliman / ios-exif-timestamp-bug.json
Last active August 29, 2015 13:57
Broken EXIF timestamp in iPhone 5 (iOS 7.1) camera photo
{
"{Exif}": {
"ExposureTime": 0.06666666666666667,
"LensMake": "Apple",
"Flash": 16,
"ColorSpace": 1,
"SubjectArea": [1210, 1108, 509, 509],
"ExifVersion": [2, 2, 1],
"FocalLenIn35mmFilm": 33,
"SceneCaptureType": 0,
@jhurliman
jhurliman / microevent.js
Last active August 29, 2015 13:56
Micro EventEmitter-like library for JS, based on https://github.com/jeromeetienne/microevent.js/blob/master/microevent.js#L12-31 but with method names more closely matching node.js EventEmitter
window.MicroEvent = function() {};
MicroEvent.prototype = {
on: function(event, listener) {
this._events = this._events || {};
this._events[event] = this._events[event] || [];
this._events[event].push(listener);
},
removeListener: function(event, listener) {
this._events = this._events || {};
@jhurliman
jhurliman / getIP.js
Created December 27, 2013 03:39
Make a best guess at the IP address for the local machine, preferring the first non-loopback non-internal IPv4 address.
function getIP() {
var interfaces = require('os').networkInterfaces();
var names = Object.keys(interfaces);
var addresses = [];
var idx = 0;
for (var i = 0; i < names.length; i++) {
var name = names[i];
var nic = interfaces[name];
@jhurliman
jhurliman / convolve.js
Last active February 6, 2023 12:39
1D convolution
/**
* Copyright 2017 John Hurliman <jhurliman.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
@jhurliman
jhurliman / readCSV.js
Last active December 26, 2015 11:29
Asynchronously iterate over a CSV file one line at a time
function readCSV(filename, eachCallback, doneCallback) {
var error;
var reader = require('readline').createInterface({
input: require('fs').createReadStream(filename),
output: null,
terminal: false
});
reader.on('line', function(line) {
@jhurliman
jhurliman / cloudformation.yaml
Created July 16, 2013 22:19
Run CloudFormation via Ansible
- name: CloudFormation deployment
hosts: local
connection: local
user: root
gather_facts: false
tags:
- initialize
tasks: