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
""" Lambda to launch ec2-instances """ | |
import boto3 | |
REGION = 'eu-central-1' # region to launch instance. | |
AMI = 'ami-24bd1b4b' | |
# matching region/setup amazon linux ami, as per: | |
# https://aws.amazon.com/amazon-linux-ami/ | |
INSTANCE_TYPE = 'm3.medium' # instance type to launch. | |
EC2 = boto3.client('ec2', region_name=REGION) |
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
// a connection singleton. | |
let dbConnectionPromise; | |
function getDb() { | |
if (dbConnectionPromise) { | |
return dbConnectionPromise; | |
} | |
dbConnectionPromise = DbClient.connect(options); | |
return dbConnectionPromise; | |
} |
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
// with arrays | |
const dupArr = [1, 1, 2, 3, 1]; | |
const uniArr = [...(new Set(dupArr))]; | |
// [1, 2, 3] | |
// with objects on a key. | |
const dupObj = [{ id: 1, value: 'a' }, { id: 2, value: 'b' }, { id: 1, value: 'c' }]; | |
const uniKeys = [...(new Set(dupObj.map(({ id }) => id)))]; | |
// [ '1', '2' ] |
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 testCount = 1e7; | |
const keyCount = 10; | |
const times = count => Array.from(Array(count)) | |
const message = (test, runtime) => `${test} took ${((runtime[0] * 1e9) + runtime[1]) / 1e6}ms`; | |
const obj = times(keyCount) | |
.map(Math.random) | |
.reduce((o, p) => Object.assign({}, o, { [p.toString()]: Math.random() }), {}); | |
const hasKey = Object.keys(obj)[0]; |
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
describe('My awesome new way of doing things', () => { | |
it('should be performant.' () => { | |
const maxRunTimeMs = 500; | |
const start = process.hrtime(); | |
return doSomethingAwesome() | |
.then(() => { | |
const runtime = process.hrtime(start); | |
const runtimeNs = (runtime[0] * 1e9) + runtime[1]; | |
const runtimeMs = runtimeNs / 1e6; | |
expect(runtimeMs).to.be.lessThan(maxRunTimeMs); |
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
files: | |
"/etc/cron.hourly/cron.logrotate.elasticbeanstalk.nodejs.conf": | |
mode: "000655" | |
owner: root | |
group: root | |
content: | | |
#!/bin/sh | |
test -x /usr/sbin/logrotate || exit 0 | |
/usr/sbin/logrotate /etc/logrotate.elasticbeanstalk.hourly/logrotate.elasticbeanstalk.nodejs.conf | |
/sbin/service awslogs restart |
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 amazing = (event, context, callback) => { | |
const { requestContext: { authorizer } } = event; | |
const body = { | |
hello: 'world', | |
authContext: authorizer, | |
}; | |
const response = { | |
statusCode: 200, | |
headers: { 'Content-Type': 'application/json' }, | |
body: JSON.stringify(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
container_commands: | |
00download: | |
command: "wget http://aws-cloudwatch.s3.amazonaws.com/downloads/CloudWatchMonitoringScripts-1.2.1.zip" | |
ignoreErrors: true | |
01extract: | |
command: "unzip -o CloudWatchMonitoringScripts-1.2.1.zip" | |
ignoreErrors: true | |
02rmzip: | |
command: "rm CloudWatchMonitoringScripts-1.2.1.zip" | |
ignoreErrors: true |