Skip to content

Instantly share code, notes, and snippets.

View jakelodwick's full-sized avatar

Jake Lodwick jakelodwick

View GitHub Profile
@jakelodwick
jakelodwick / integration_request.vtl
Created March 12, 2016 17:13
AWS API Gateway - Integration Request - Mapping Template
#*
Via <http://kennbrodhagen.net/2015/12/06/how-to-create-a-request-object-for-your-lambda-event-from-api-gateway/>.
This mapping template formats most information that API Gateway receives, for easy use in a Lambda function (or whatever).
Not sure why the same effect isn't achieved with the "Input passthrough" option!
*#
{
"method": "$context.httpMethod",
"body" : $input.json('$'),
"headers": {
#foreach($param in $input.params().header.keySet())
@jakelodwick
jakelodwick / loadSamples.coffee
Created December 21, 2015 22:16
load multiple files via XHR, then run a callback
loadSamples: (urls, callback) ->
loaded = []
requests = []
decode = (_raw) =>
@audio.decodeAudioData _raw, (sample) ->
loaded.push sample
callback(loaded) if loaded.length is urls.length
@jakelodwick
jakelodwick / http-to-https.coffee
Created October 26, 2015 20:32
redirect from http to https
if location.protocol is "http:"
window.location = window.location.toString().replace("http:", "https:")

Setting up Caffe for Running Deepdream on OS X

Dependencies

Use Brew

Install brew and pip (sudo easy_install pip)

brew update
brew install homebrew/science/openblas
@jakelodwick
jakelodwick / vcenter.css
Created December 9, 2014 03:48
vertically center in CSS
.vcenter {
display: inline-block;
position: relative;
top: 50%;
transform: translateY(-50%);
}
@jakelodwick
jakelodwick / heroku-env.sh
Created September 9, 2014 00:52
Getting Heroku environment variables into local repo
heroku plugins:install git://github.com/ddollar/heroku-config.git
heroku config:pull --overwrite --interactive
@jakelodwick
jakelodwick / phttp
Created August 18, 2014 20:54
Start webserver in current directory & open browser window to it
# run these two commands:
open http://localhost:8000/
python -m SimpleHTTPServer
# I put the following in ~/.profile (OS X) so it runs every time I open a terminal window:
alias phttp="open http://localhost:8000/; python -m SimpleHTTPServer"
@jakelodwick
jakelodwick / array-last.coffee
Created August 17, 2014 19:02
Get last element of array
# last element of array,
# alternative to `my_array[my_array.length - 1]`
# via http://stackoverflow.com/questions/9050345/selecting-last-element-in-javascript-array
unless Array::last
Array::last = ->
this[@length - 1]
@jakelodwick
jakelodwick / ppjson.coffee
Created August 17, 2014 19:01
Pretty-print JSON
# pretty-print JSON
# http://stackoverflow.com/questions/4810841/how-can-i-pretty-print-json-using-javascript
ppjson = (obj) ->
console.log JSON.stringify obj, undefined, 2
@jakelodwick
jakelodwick / gist:4b6e1f938403a1c92cf5
Created August 17, 2014 18:03
CoffeeScript in Sinatra apps
#put this in your Gemfile:
gem "rack-coffee"
#(don't forget to run `bundle` on the command line)
#put this in your Sinatra app:
use Rack::Coffee,
:root => 'public',
:urls => '/coffee',
:join => 'index',
:bare => true