Skip to content

Instantly share code, notes, and snippets.

View areichman's full-sized avatar

Aaron Reichman areichman

View GitHub Profile
@areichman
areichman / map_tile_iterator.js
Created June 29, 2015 21:36
Iterate through all image tiles for a given bounds and zoom range
// Iterate through all map tiles for a given bounds and zoom range
// lat-lon to tile conversions from http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#Derivation_of_tile_names
function lat2tile(lat, zoom) {
return (Math.floor((1-Math.log(Math.tan(lat*Math.PI/180) + 1/Math.cos(lat*Math.PI/180))/Math.PI)/2 *Math.pow(2,zoom)))
}
function lon2tile(lon, zoom) {
return (Math.floor((lon+180)/360*Math.pow(2,zoom)))
}
@areichman
areichman / reload_rsyslog.sh
Created August 24, 2016 15:44
Reload rsyslog configuration without restarting
# Restart rsyslog so it re-opens its file pointer (e.g. during logrotate postrotate script)
# via https://access.redhat.com/solutions/232793
kill -HUP $(cat /var/run/syslogd.pid)
@areichman
areichman / grunt-githash.js
Created August 30, 2016 16:23
Grunt task to get a repo's short Git hash
'use strict';
module.exports = function(grunt) {
grunt.task.registerTask('githash', function() {
var done = this.async();
grunt.util.spawn({
cmd: 'git',
args: ['rev-parse', '--short', 'HEAD']
}, function(err, result, code) {
@areichman
areichman / fetch.js
Created January 17, 2017 20:15
ES6 fetch
fetch(url, {credentials: 'include'})
.then((response) => {
if (response.ok) {
response.json().then(fetchSuccess);
} else {
response.json().then(fetchError);
}
}).catch(fetchError);
@areichman
areichman / parse_as_module.js
Last active March 22, 2018 19:34
Parse a raw JS file as a Node.js module
request('/foo.js')
.then((body) => {
const bodyExported = body + 'module.exports = foo;';
const Module = module.constructor;
const m = new Module();
m._compile(bodyExported, '');
console.log(m.exports);
});
@areichman
areichman / classify.js
Last active August 5, 2024 22:49
Perform an image classification using TensorFlow.js and AWS Lambda
const tf = require('@tensorflow/tfjs');
const jpeg = require('jpeg-js');
const axios = require('axios');
async function handler(event) {
try {
// extract the model and image urls from the lambda event payload and fetch the data
const { modelUrl, imageUrl } = event;
const model = await tf.loadLayersModel(modelUrl);