Skip to content

Instantly share code, notes, and snippets.

@homeyjd
homeyjd / lib.js
Created March 26, 2019 20:08
lifecycle-poller Lambda with less characters
let AWS = require('aws-sdk')
let ecs = new AWS.ECS()
let sqs = new AWS.SQS()
let asg = new AWS.AutoScaling()
let cluster = process.env.CLUSTER
let QueueUrl = process.env.QUEUE_URL
let drainingTimeout = process.env.DRAINING_TIMEOUT
async function getContainerInstanceArn(id) {
@homeyjd
homeyjd / batch-events.js
Created January 23, 2019 16:46
Replacement for src/parsers/batch-events.js
"use strict";
const _ = require("lodash")
, SNSParser = require("./sns")
, Slack = require("../slack");
class BatchParser extends SNSParser {
handleMessage(message) {
if (_.get(message, "source") !== "aws.batch") {
@homeyjd
homeyjd / benchmark.php
Created January 7, 2015 04:55 — forked from ranacseruet/gist:8412771
Benchmark ArrayAccess vs. Magic Methods __get/__set() in PHP classes
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
class Test implements ArrayAccess
{
public $data = array();
public function __set($key, $value){
$this->data[$key] = $value;
}
@homeyjd
homeyjd / strace_and_clean
Last active December 21, 2015 13:39
Playing with bash pipe redirection
# If you examine this command, you'll see I'm trying to run stderr through a piped command and leave stdout alone.
# The problem is that you have to redirect things around. Yes, you could simply swap stderr/out and it would work, but when they're muxed together, you get crossover.
# So, in bash world it makes perfect sense to use a new file descriptor -- #3 -- to bypass the processing in the piped commands, and then redirect 3>&1 to get it back.
# THIS WON'T WORK.
# Example from a real problem:
# This runs strace against a PHP command, removes duplicate gettimeofday system calls (which number in the 100s of thousands for running PHP processes), and colorizes the stderr output from strace as red so it can be differentiated from stdout.
$ strace -r "$@" 2>&1 1>&3 | perl -ne'$|=1; $cur = /gettimeofday/; if(!$prev){ print; }else{ if($cur){ print "."; }else{ print "\n"; print; }} $prev = $cur;' | sed $'s#.*#\e[31m&\e[m#' 1>&2 3>&1
ERROR: Bad file descriptor: 3
@homeyjd
homeyjd / ComputeOpsBetweenKeys.php
Last active December 20, 2015 21:18
Compute the synchronization steps between two key-value pairs. Consider: * no key can conflict. That is, if 4 is deleted, and 5 is moved to 4, all currently-tagged 4's must be moved OUT before 5 can be moved, else you get key conflicts. * delete operations should be reduced to default, but since default might be equal to a changing ID, the delet…
<?php
/**
* Compute the tasks that must occur to convert a key-value table specified by $src
* into a new key-value $dest where the VALUES are the important tags and the IDs
* are simply placeholders.
*
* This is helpful with user-provided data where keys are stored in the database
* (especially as integers) but user-provided values (labels for records, etc.)
* are the actual identifiers for the data.
*
@homeyjd
homeyjd / .multitailrc
Last active December 22, 2021 18:40
multitail color scheme
#~/.bash_profile
alias mt='multitail -CS php'
#~/.multitailrc
# See documentation
# keetweej.vanheusden.com/svn/multitail/trunk/multitail.conf
#
# Get this file right! If you don't multitail will just crash.
# No warning, no error, just won't start. And it's your fault.