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 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;
View redis-security-group.yml
# Security group to add the Redis cluster to the VPC,
# and to allow the Fargate containers to talk to Redis on port 6379
RedisSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: "Redis Security Group"
VpcId:
Fn::ImportValue:
!Join [':', [!Ref 'EnvironmentName', 'VPCId']]
RedisIngress: