Skip to content

Instantly share code, notes, and snippets.

# Install procpath tool (use "python3 -m site --user-base" to find installation directory if needed)
> pip3 install --user procpath
# Get the right version of sqlite
> pip3 install --user apsw-wheels
# Start recording metrics
# i 5 - one datapoint every 5 seconds
# r 120 - 120 datapoints (omit r for continuous capture, and use ctrl+c to stop)
# d db.sqlite - a sqlite database
@brainsiq
brainsiq / swagger.yaml
Created November 28, 2018 12:15
x-nullable apiary example
swagger: "2.0"
info:
version: '1'
title: Test API
description: Test Apiary
host: api.test.com
schemes: [https]
consumes:
- application/json
produces:
@brainsiq
brainsiq / grep.sh
Last active March 15, 2018 14:13
Grep
# Search all files in current directory that were modified today for one of many strings (stored in /tmp/findStrings)
find -daystart -mtime 0 -type f | xargs grep -lF -f /tmp/findStrings
@brainsiq
brainsiq / gist:5729929757f2c66c15fb96c4c6342438
Last active February 27, 2018 09:20
tcpdump capture traffic on port
tcpdump -i any -q -s 0 -W 5 -C 10 port <port> -w /tmp/tcp_capture
# -i any (all interfaces)
# -q (less protocol info)
# -s 0 (capture the full packet)
# -W 5 -C 10 (rotate between 5 10MB files)
tcpdump -A -r /tmp/tcp_capture0
@brainsiq
brainsiq / gist:59b9c6a74f317a3f7853bd086363371b
Last active January 11, 2018 16:02
Restart ECS service tasks
cluster=mycluster
service=myservice
# Construct a copy of the current task definition, copying over the necessary attributes
task_def_arn=$(aws ecs describe-services --cluster "$cluster" --service "$service" | jq -r '.services[0].deployments[0].taskDefinition')
task_def=$(aws ecs describe-task-definition --task-definition "$task_def_arn" | jq '.taskDefinition | { family:.family, containerDefinitions:.containerDefinitions}')
# Register as a new task and deploy it to the service. "wait" does not return until the service is stable (i.e. deployed).
new_task_def_arn=$(aws ecs register-task-definition --cli-input-json "$task_def" | jq -r '.taskDefinition.taskDefinitionArn')
aws ecs update-service --cluster "$cluster" --service "$service" --task-definition "$new_task_def_arn"
@brainsiq
brainsiq / index.js
Created October 16, 2017 10:50
Moment.js expiry time generation benchmark
/**
* Benchmark creation of a timestamp ([n] ms from now), and from it creating a unix timestamp and native Date object
*/
const Benchmark = require('benchmark');
const moment = require('moment');
const suite = new Benchmark.Suite;
const msToAdd = 36000;
const msInSec = 1000;
@brainsiq
brainsiq / docker.md
Last active June 29, 2017 08:36
Ubuntu dev machine setup

Useful helper commands, added to ~/.zshrc

# Open a bash shell in a named container
function ctr-bash() { docker exec -it $1 /bin/bash }

# Start streaming logs from the current time
alias ctr-logstream='docker logs -f --since $(date +%s)'
@brainsiq
brainsiq / nginx.conf
Created August 25, 2016 09:39
angular nginx configuration
events {}
http {
include /etc/nginx/mime.types;
gzip on;
gzip_disable "msie6";
server {
listen 8080;