Skip to content

Instantly share code, notes, and snippets.

Avatar
📦
Bin packing containers onto hosts

Nathan Peck nathanpeck

📦
Bin packing containers onto hosts
View GitHub Profile
@nathanpeck
nathanpeck / tank_ai.js
Created Aug 10, 2015
Very simple, dumb AI for code challenge
View tank_ai.js
var api = require('./API.js');
/**
* http://honeypot.softwareskills.se/#/contest/5587cf988a4c5edb08ffa049
*
* Executes a single step of the tank's programming. The tank can only move,
* turn, or fire its cannon once per turn. Between each update, the tank's
* engine remains running and consumes 1 fuel. This function will be called
* repeatedly until there are no more targets left on the grid, or the tank runs
* out of fuel.
@nathanpeck
nathanpeck / autoscale-ecs-tasks-lambda.js
Created Apr 28, 2016
Simplistic lambda function for autoscaling the number of tasks in an ECS service
View autoscale-ecs-tasks-lambda.js
var aws = require('aws-sdk');
exports.handler = function(event, context) {
var ecsRegion = 'us-east-1';
// Safegaurd against out of control service scaling
var maxCount = {
deathstar: 6
};
View keybase.md

Keybase proof

I hereby claim:

  • I am nathanpeck on github.
  • I am nathanpeck (https://keybase.io/nathanpeck) on keybase.
  • I have a public key whose fingerprint is F2B3 75B6 7540 542A FB63 61B8 F657 950F EF75 2863

To claim this, I am signing this object:

View friend-messages-join.sql
CREATE TABLE IF NOT EXISTS `users` (
`id` int(6) unsigned NOT NULL,
`name` varchar(200) NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARSET=utf8;
INSERT INTO `users` (`id`, `name`) VALUES
('1', 'Marceline'),
('2', 'Finn'),
('3', 'Jake');
View join-sample.sql
SELECT
m.id id,
m.user `user`,
u.name name,
u.avatar avatar,
m.text `text`,
m.when `when`
FROM messages m
INNER JOIN (
SELECT `from`, `to`
View docker-compose.yaml
version: "3"
services:
web:
build: ./web
links:
- "stub-api:api"
stub-api:
build: ./stub-api
View multiple-ports-per-ecs-service.md

The information below was written in Oct 2017. In August 2019 AWS launched official support for multiple target groups per AWS ECS service. Please use that feature instead!


Unfortunately as of writing this (Oct 18, 2017) there is no built in integration for multiple target groups per AWS ECS service. Here are a few things you can try:

  1. If your application just serves port 80 (HTTP) & port 443 (HTTPS) then you should consider using the application load balancer and terminating SSL at the load balancer. This will allow your application to function using just port 80.
View Dockerfile
FROM mhart/alpine-node:9 AS build
WORKDIR /srv
ADD package.json .
RUN npm install
ADD . .
FROM mhart/alpine-node:base-9
COPY --from=build /srv .
EXPOSE 3000
CMD ["node", "index.js"]
View socketio-redis.js
var server = require('http').createServer(app);
var io = require('socket.io')(server);
var redis = require('socket.io-redis');
io.adapter(redis({ host: process.env.REDIS_ENDPOINT, port: 6379 }));
View snippet.js
var numUsers = 0;
// when the client emits 'add user', this listens and executes
socket.on('add user', function (username) {
if (addedUser) return;
// we store the username in the socket session for this client
socket.username = username;
++numUsers;
addedUser = true;