Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env bash
set -o pipefail -o errtrace -o errexit -o nounset
shopt -s inherit_errexit
[[ -n "${TRACE:-}" ]] && set -o xtrace
trap 'stacktrace "Error trapped rc=${PIPESTATUS[@]}, see trace above"' ERR
stacktrace() {
#!/usr/bin/env python3
from neo4j import GraphDatabase
import logging
import os
import time
import signal
from neo4j.exceptions import ServiceUnavailable
class App:
@jonatanblue
jonatanblue / ubuntu_troubleshooting_tools.sh
Last active July 2, 2021 12:56
Things I install on Ubuntu containers for troubleshooting
# procps - for ps
# net-tools - for netstat
apt update && apt install -y procps telnet net-tools curl less vim
#!/bin/bash
grep_this=xvda1; d1=0; d2=0; while true; do d1=$(df | grep ${grep_this} | awk '{ print $4 }'); sleep 1; d2=$(df | grep ${grep_this} | awk '{ print $4 }'); diff=$(( ${d1} - ${d2} )); echo $diff; done
@jonatanblue
jonatanblue / sed_or_grep_a_stream.sh
Created April 26, 2017 13:34
sed or grep a stream
# grep
tail -f file | grep --line-buffered my_pattern
# sed
stdbuf -o0 tail -f /var/log/syslog | sed 's/Dec/LOOL/'
# credits:
# Thanks to @amblina for collecting these.
@jonatanblue
jonatanblue / docker_py_to_docker.md
Last active July 18, 2019 12:15
Resolve docker-py older version naming conflict

Problem

When running docker-compose I get this error:

docker-compose --version
> ERROR: Dependency conflict: an older version of the 'docker-py' package is polluting the namespace. Run the following command to remedy the issue:
> pip uninstall docker docker-py; pip install docker
@jonatanblue
jonatanblue / export_secret_variable.sh
Last active March 8, 2017 11:00
Export secret variable on the command line without writing to history
#!/bin/bash
#
# Set a secret environment variable on the command line without saving it in history:
export MY_TOKEN="$(read token && echo ${token})"
# type/paste secret value
echo ${MY_TOKEN}
# value is echoed
@jonatanblue
jonatanblue / move_folder_between_projects.sh
Created February 27, 2017 18:17
Move a folder from one Git project to another preserving history
# Clone repo 1
git clone repo1
cd repo1
# Use subtree on the folder you want to move
git subtree split -P dir1 -b split-dir1-branch
# Check out branch and move files
git checkout split-dir1-branch
mkdir dir1
@jonatanblue
jonatanblue / terraform_ecs_elb_error.log
Created July 24, 2016 10:30
terraform command output
#### Output from `terraform plan`:
$ terraform plan
Refreshing Terraform state prior to plan...
aws_ecs_cluster.example_cluster: Refreshing state... (ID: arn:aws:ecs:us-east-1:123456789012:cluster/example-cluster)
aws_iam_role.ecs_instance: Refreshing state... (ID: ecs-instance)
aws_iam_role.ecs_service_role: Refreshing state... (ID: ecs-service-role)
aws_ecs_task_definition.sinatra_backend: Refreshing state... (ID: sinatra-backend)
aws_security_group.ecs_instance: Refreshing state... (ID: sg-432b2038)
#Pre-req: install gcloud (Google Cloud CLI)
PROJECT_NAME=${1}
CLUSTER_NAME=kubernetes-lab-1
GOOGLE_REGION=europe-west1-d
brew update
brew install kubernetes-cli
brew install gcloud
gcloud config set project $PROJECT_NAME
gcloud config set compute/zone $GOOGLE_REGION