Skip to content

Instantly share code, notes, and snippets.

View evanderkoogh's full-sized avatar

Erwin van der Koogh evanderkoogh

View GitHub Profile
@evanderkoogh
evanderkoogh / gist:2ae2904aff498e050061
Created October 19, 2014 06:36
Store a realtime stream of Twitter search in Redis DB
redis = require('redis').createClient process.env['REDIS_PORT_6379_TCP_PORT'], process.env['REDIS_PORT_6379_TCP_ADDR']
redis.select 1
Twitter = require 'twitter'
credentials =
consumer_key: process.env.TWITTER_CONSUMER_KEY
consumer_secret: process.env.TWITTER_CONSUMER_SECRET
access_token_key: process.env.TWITTER_ACCESS_TOKEN_KEY
access_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET
twitter = new Twitter credentials
@evanderkoogh
evanderkoogh / client.js
Created December 29, 2015 13:52
Reproduce problem in request/request with regards to maxSocket & timeouts
var request = require('request');
request = request.defaults({agentOptions: {maxSocket: 1}, timeout: 1200});
for(i=0;i < 10;i++) {
console.log("Requesting");
request.get("http://localhost:3000/", function(err, res, body) {
if(err) {
console.log(err);
}
@evanderkoogh
evanderkoogh / gist:f9012bc0163b6d9f2bde49046d8cf720
Created April 23, 2017 15:18
Example Edge@Lambda in AWS Cloudfront. Change URI based on host header
'use strict';
/*
* HTTP headers are case-insensitive. So 'Host' is a valid header, but so
* is 'host' or 'hOst'. To make sure we don't miss a header we first lowerCase
* all of them and then check for the lowercase version of the header
*/
const normaliseHeaders = (headers) => {
const normalisedHeaders = {};
const fields = Object.keys(headers);
@evanderkoogh
evanderkoogh / example.csv
Created November 20, 2017 13:29
Import CSV into DynamoDB
whateverId attribute1 someotherattribute
foo bar baz
hello erwin world
@evanderkoogh
evanderkoogh / index.js
Created August 24, 2018 05:18
Add and/or overwrite values in a DynamoDB table with the Document Client
const AWS = require('aws-sdk')
const docClient = new AWS.DynamoDB.DocumentClient()
const mapKeys = (input, transform) => {
const output = {}
Object.keys(input).forEach((key, index, array) => {
output[transform(key, index, array)] = input[key]
})
return output
@evanderkoogh
evanderkoogh / index.js
Created October 3, 2018 10:24
How to execute promises both serially and in parallel
const wait = async (time) => {
console.log(`Going to be waiting for ${time} seconds`)
return new Promise((resolve) => {
setTimeout(() => {
console.log(`Done waiting for ${time} seconds!`)
resolve()
}, time * 1000)
})
}