This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fetch(url, {credentials: 'include'}) | |
.then((response) => { | |
if (response.ok) { | |
response.json().then(fetchSuccess); | |
} else { | |
response.json().then(fetchError); | |
} | |
}).catch(fetchError); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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))) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Checkbox helper, based on http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-check_box | |
// | |
// Usage: | |
// {{check_box object name="test" type="checkbox" value=true hidden="false"}} | |
// | |
// Note that the value in the hash can be specified with/without quotes so a proper type comparison | |
// can be made. | |
// | |
Handlebars.registerHelper('check_box', function(context, options) { | |
var checked = context !== undefined && context == options.hash.value ? 'checked' : '', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var request = require('request') | |
spyOn(request, 'get').andCallFake(function(params, callback) { | |
var res = { | |
statusCode: 200 | |
} | |
var body = { | |
// JSON attributes | |
} | |
callback(null, res, body) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Make the nested fields parsed by multiparty look like req.body from body-parser | |
// e.g. 'metadata[foo]': ['1'] => {metadata: {foo: 1}} | |
// 'metadata[foo]': ['bar'] => {metadata: {foo: 'bar'}} | |
// 'metadata[foo][]': ['bar', 'bat'] => {metadata: {foo: ['bar', 'bat']}} | |
var qs = require('qs'); | |
function reformatFields(fields) { | |
// convert numbers to real numbers instead of strings | |
function toNumber(i) { |
NewerOlder