Skip to content

Instantly share code, notes, and snippets.

@jamesbjackson
jamesbjackson / consul-ssh-configurator.py
Created July 2, 2018 10:40 — forked from mattupstate/consul-ssh-configurator.py
A script to generate an SSH config from Consul's HTTP API
#!/usr/bin/env python3
"""
Renders a partial SSH configuration file from Nodes and Services
located in a specified Consul catalog and then merges other partial
config files into the main ~/.ssh/config file. The Consul based SSH
config follows a convention for the SSH host::
Host <consul-cluster-name>-<service-name>-<node-address>
User <ssh-user>
Hostname <consul-node-address>
@jamesbjackson
jamesbjackson / curl.md
Created June 12, 2018 08:41 — forked from subfuzion/curl.md
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

@jamesbjackson
jamesbjackson / README.md
Created February 15, 2018 16:14 — forked from obscurerichard/README.md
Simulates a low bandwidth, high-latency network connection

slow

This bash script offers quick shortcuts to simulate slower network connections. It is useful when you need to simulate a wireless network on a Linux network server, especially when you are using a virtual machine guest on your local machine or in the cloud.

slow 3G                   # Slow network on default eth0 down to 3G wireless speeds
slow reset                # Reset connection for default eth0 to normal
slow vsat --latency=500ms # Simulate satellite internet  with a high latency
slow dsl -b 1mbps         # Simulate DSL with a slower speed than the default

slow modem-56k -d eth0 # Simulate a 56k modem on the eth1 device. eth0 is unchanged.

@jamesbjackson
jamesbjackson / logging.yml
Created February 2, 2018 10:49
A starter config I like for development/non-production Python logging. (in production I use syslog etc instead). Replace filenames as needed - by hand in YAML, or in your setup code.
version: 1
formatters:
simple:
format: "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
verbose:
format: "%(levelname)-8s %(asctime)s %(name)s %(filename)s:%(lineno)s | %(funcName)s | %(message)s"
very_verbose:
format: "%(levelname)-8s %(asctime)s %(name)s %(pathname)s:%(lineno)s | %(funcName)s | %(message)s"
handlers:
console:
@jamesbjackson
jamesbjackson / python-azure-blob-storage-download.py
Created January 18, 2018 16:58 — forked from brijrajsingh/python-azure-blob-storage-download.py
Downloadin an Azure Storage Blob Container with complex path of folders and sub folders
from azure.storage.blob import BlockBlobService
from azure.storage.blob import PublicAccess
import os
#name of your storage account and the access key from Settings->AccessKeys->key1
block_blob_service = BlockBlobService(account_name='storageaccountname', account_key='AccountKey')
#name of the container
generator = block_blob_service.list_blobs('testcontainer')
@jamesbjackson
jamesbjackson / Makefile
Created January 16, 2018 12:19 — forked from mpneuried/Makefile
Simple Makefile to build, run, tag and publish a docker containier to AWS-ECR
# import config.
# You can change the default config with `make cnf="config_special.env" build`
cnf ?= config.env
include $(cnf)
export $(shell sed 's/=.*//' $(cnf))
# import deploy config
# You can change the default deploy config with `make cnf="deploy_special.env" release`
dpl ?= deploy.env
include $(dpl)
@jamesbjackson
jamesbjackson / uid_awk.sh
Created December 21, 2017 10:08 — forked from staaldraad/uid_awk.sh
Get the uid, gid and user groups without touching /etc/passwd or running the `id` command
awk -F: 'END {print "uid:"u" gid:"g" groups:"gg}{if($1=="Uid"){split($2,a," ");u=a[1]}if($1=="Gid"){split($2,a," ");g=a[1]}if($1=="Groups"){gg=$2}}' /proc/self/status
@jamesbjackson
jamesbjackson / awk_netstat.sh
Created December 21, 2017 10:08 — forked from staaldraad/awk_netstat.sh
AWK to get details from /proc/net/tcp and /proc/net/udp when netstat and lsof are not available
# Gawk version
# Remote
grep -v "rem_address" /proc/net/tcp | awk '{x=strtonum("0x"substr($3,index($3,":")-2,2)); for (i=5; i>0; i-=2) x = x"."strtonum("0x"substr($3,i,2))}{print x":"strtonum("0x"substr($3,index($3,":")+1,4))}'
# Local
grep -v "rem_address" /proc/net/tcp | awk '{x=strtonum("0x"substr($2,index($2,":")-2,2)); for (i=5; i>0; i-=2) x = x"."strtonum("0x"substr($2,i,2))}{print x":"strtonum("0x"substr($2,index($2,":")+1,4))}'
# No Gawk
# Local
grep -v "rem_address" /proc/net/tcp | awk 'function hextodec(str,ret,n,i,k,c){
@jamesbjackson
jamesbjackson / ecs-autoscaing.json
Created December 15, 2017 12:49 — forked from igorlg/ecs-autoscaing.json
AWS CloudFormation template for ECS AutoScaling Group
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Template for a VPC with High Availability NAT for ECS",
"Parameters": {
"ClusterName": {
"Description": "The ECS Cluster Name",
"Type": "String"
},
"InstanceType": {
"Description": "NAT instance type",
@jamesbjackson
jamesbjackson / ecs-autoscaing.json
Created December 15, 2017 12:49 — forked from igorlg/ecs-autoscaing.json
AWS CloudFormation template for ECS AutoScaling Group
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Template for a VPC with High Availability NAT for ECS",
"Parameters": {
"ClusterName": {
"Description": "The ECS Cluster Name",
"Type": "String"
},
"InstanceType": {
"Description": "NAT instance type",