Skip to content

Instantly share code, notes, and snippets.

View ktilcu's full-sized avatar

kyle tilman ktilcu

View GitHub Profile
@ktilcu
ktilcu / index.html
Created March 18, 2019 18:18
JS Bin Intersperse function 2 ways // source https://jsbin.com/furejas
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Intersperse function 2 ways">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src="https://bundle.run/[email protected]"></script>
<script src="https://bundle.run/tap-browser-color"></script>
@ktilcu
ktilcu / fp-ts.ts
Created February 16, 2019 05:45
FP in Typescript
function prop<T, K extends keyof T>(name: K, o: T): T[K] {
return o[name];
}
function maybeProp<T, K extends keyof T>(name: K, o: T): Option<T[K]> {
return fromNullable(o[name]);
}
const safeProp = R.curry(maybeProp);
const pipeK = R.pipeK;
@ktilcu
ktilcu / utils.js
Created October 26, 2018 03:25
utils
function isJson(str) {
try {
JSON.parse(str);
return true;
} catch (e) {
return false;
}
}
function getOr(def, path, obj) {

Blue/Green/Canary Deployments on AWS ECS Fargate

Currently we duplicate at the service level which means we have to have

  • Weighted DNS
  • 2 Load Balancers
  • 2 Services
  • 2 sets of Tasks

Thats a lot of infrastructure to maintain, configure and adjust.

What if instead we used Tasks as our unit of duplication. They are way cheaper and easier to affect.

@ktilcu
ktilcu / docker.md
Created July 6, 2018 19:54
Oft used docker cmds

Docker Basics

  • docker ps Shows you running containers (note the last column name)
  • docker logs <name> Shows you logs from the running container
  • docker logs -f <name> Tails logs from a running container
  • docker build -t <image_tag_name> . Builds the current dir as a docker image
  • docker run <image> creates a container running the specified image
    • --rm remove the container when it exits (good for dev)
    • -e use to set environment variables in the conatiner - one assignment per flag
  • --name set a name for the running container
@ktilcu
ktilcu / app.js
Last active May 10, 2018 16:35
PG Pooling with express
const db = require('./db');
const express = require('express')
const app = express()
app.get('/', (req, res) => res.send('Hello World!'))
db.init()
// after init
.then(() => app.listen(3000, () => console.log('Example app listening on port 3000!')))
function doubleBarrel (fn) {
return function (a,b) {
var len = a.length > b.length ? b.length : a.length;
if (len == 0) {
return a.length > b.length ? a : b;
}
var idx = 0;
var out = [];
while (idx < len) {
out.push(fn(a[idx], b[idx]));
@ktilcu
ktilcu / retry-future.js
Created April 13, 2018 14:28
Future URL fetching
const Future = require('fluture');
// (Number -> Number) -> Number -> Future a b -> Future (List a) b
const retry = (time, max, task) => {
const failures = new Array(max);
return (function recurse(i) {
return task.chainRej(function(failure) {
failures[i] = failure;
const total = i + 1;
return total === max
@ktilcu
ktilcu / maybes.js
Created April 13, 2018 14:17
Maybes with one null check
// type alias DOM = Object // unknown structure, defined by Cheerio
// type alias Selector = String // like a jquery selector (e.g., '#omg')
// selectAll :: Selector -> DOM -> List DOM
const selectAll = R.curry((sel, dom) => {
const res = dom(sel);
return R.map(cheerio, res.toArray());
});
// selectFirst :: Selector -> DOM -> Maybe DOM
@ktilcu
ktilcu / apaste
Created April 9, 2018 17:31 — forked from sam-roth/apaste
Aligning `paste` alternative
#!/usr/bin/env python3
import argparse
import itertools
ap = argparse.ArgumentParser()
ap.add_argument('file', nargs='*', type=argparse.FileType('r'))
ap.add_argument('-p', '--pad-char', default=' ')
ap.add_argument('-d', '--delimiter', default=' ')
ap.add_argument('-c', '--pad-color', default=None)
ap.add_argument('-s', '--align-spec', default='')