Skip to content

Instantly share code, notes, and snippets.

@jamesbjackson
jamesbjackson / get_sizes.sql
Created February 27, 2019 16:07 — forked from peterc/get_sizes.sql
Get the size of different tables and other relations in a PostgreSQL database
SELECT
schema_name, rel_name, table_size,
pg_size_pretty(table_size) AS size
FROM (
SELECT
nspname AS schema_name,
relname AS rel_name,
pg_table_size(pg_class.oid) AS table_size
FROM pg_class, pg_namespace
WHERE pg_class.relnamespace = pg_namespace.oid
@jamesbjackson
jamesbjackson / fpm-openssl.sh
Created February 13, 2019 14:26 — forked from jbuchbinder/fpm-openssl.sh
FPM OpenSSL build
#!/bin/bash
# fpm-openssl - @jbuchbinder
# Build script for recent openssl builds using FPM on EL7. Untar the release and run this script to build
# your RPM. Requires:
# - RPMS: ruby-devel make gcc rpm-build
# - GEMS: fpm
./config && make depend && make all && make install INSTALL_PREFIX=/tmp/openssl
fpm -s dir -t rpm -n openssl-recent \
@jamesbjackson
jamesbjackson / https-server.txt
Created December 6, 2018 17:13 — forked from rlipscombe/https-server.txt
Ad-hoc HTTPS server
## On the server
# AWS EC2
SERVER_IP=$(curl http://169.254.169.254/latest/meta-data/public-ipv4)
# Digital Ocean
SERVER_IP=$(curl http://169.254.169.254/metadata/v1/interfaces/public/0/ipv4/address)
# Generate a self-signed server certificate
openssl genrsa -out server.key 4096
@jamesbjackson
jamesbjackson / web-servers.md
Created December 6, 2018 17:12 — forked from willurd/web-servers.md
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
#!/bin/bash
# bash generate random alphanumeric string
#
# bash generate random 32 character alphanumeric string (upper and lowercase) and
NEW_UUID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
# bash generate random 32 character alphanumeric string (lowercase only)
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1
@jamesbjackson
jamesbjackson / chef-roles-to-json-task.rb
Created September 24, 2018 15:26 — forked from tobami/chef-roles-to-json-task.rb
Chef ruby roles to json
# ADD this to Rakefile and run it by issuing rake roles.to_json
ROLE_DIR = File.expand_path(File.join(TOPDIR, "roles"))
namespace :roles do
desc "Convert ruby roles from ruby to json, creating/overwriting json files."
task :to_json do
Dir.glob(File.join(ROLE_DIR, '*.rb')) do |rb_file|
role = Chef::Role.new
role.from_file(rb_file)
json_file = rb_file.sub(/\.rb$/,'.json')
@jamesbjackson
jamesbjackson / put-s3-bucket-notification-configuration
Created September 11, 2018 10:46 — forked from mattupstate/put-s3-bucket-notification-configuration
Example of how to configure S3 bucket notifications from the command line
#!/usr/bin/env python
import argparse
import sys
try:
import boto3
except ImportError:
print('Please install boto3 to use this tool')
sys.exit(1)
@jamesbjackson
jamesbjackson / README.md
Created September 11, 2018 09:18 — forked from eldondevcg/README.md
Cross account bucket access for IAM roles

For: https://www.reddit.com/r/aws/comments/5jf7fb/permissions_for_lambda_accessing_s3_buckets_in/

This is a little tricky, because it requires several different moving parts, specifically,

  • the lambda task that you want to execute the copy must have IAM access to the bucket in the other account. This is not something that was obvious to me to begin with, although my use case was more complicated.
  • the bucket policy on the destination account must be set to permit your lambda function to write to that bucket. For my special use cases, I have to upload a new bucket policy daily to the receiving buckets. Alternatively, the destination accounts could probably give your a cross-account IAM role to upload the bucket policy yourself.
  • You will likely want to write your objects with the bucket-owner-full-control acl, http://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html otherwise, the bucket owner may not be able to download them.
import os
import boto3
import datetime
import dateutil
DEFAULT_MAX_MEM = 3000
LOW_CLUSTER_CPU_TH = 20
HIGH_CLUSTER_CPU_TH = 65
CONTAINERS_MAX_MEM = {
'cluster1': 1200,
@jamesbjackson
jamesbjackson / systemd.erl
Created July 25, 2018 15:06 — forked from maxlapshin/systemd.erl
Systemd support
-module(systemd).
% This is what you need to adopt systemd in erlang
-export([ready/0, reloading/0, stopping/0, watchdog/0]).
-export([start_link/0]).
-export([init/1, handle_info/2, terminate/2]).
ready() -> call(<<"READY=1">>).