Skip to content

Instantly share code, notes, and snippets.

Avatar

Mark Betz Markbnj

View GitHub Profile
@Markbnj
Markbnj / gce_project.sh
Created Oct 9, 2015
Grab Google compute engine project ID into environment variable
View gce_project.sh
export GCLOUD_PROJ=$( gcloud info | awk '$1 == "Project:" {print $2}' | tr -d '[][:space:]' )
@Markbnj
Markbnj / update-policy.sh
Created Sep 15, 2015
Allow services to start in an Ubuntu 15.04 Docker container
View update-policy.sh
# By default the /usr/sbin/policy-rc.d script in the ubuntu:15.04 docker image is set to return 101
# (action forbidden by policy) every time it is invoked. This prevents systemctl start requests for
# services from completing succesfully. The following command overwrites the contents of policy-rc.d
# to allow service starts.
#
# Note that this won't work right under bash due to expansion of the '!' character. Docker uses sh
# by default when executing the commands in the dockerfile, so this will work there, and you can
# also use sh interactively to run this.
echo "#!/bin/sh\nexit 0" > /usr/sbin/policy-rc.d
@Markbnj
Markbnj / getch.py
Created Aug 26, 2015
Get a single key press from the terminal in python
View getch.py
import termios
import sys
import tty
def _getch():
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(fd)
ch = sys.stdin.read(1)
@Markbnj
Markbnj / cmdline-example.sh
Created Aug 24, 2015
Handling command line options in bash scripts, example
View cmdline-example.sh
# Starts the elasticsearch node container, optionally setting
# a cluster name and host IP to expose to other nodes. Mounts
# the directory at /var/lib/elasticsearch to the same location
# on the host.
#
# exposes ports:
# 9200 = elasticsearch http
# 9300 = elasticsearch transport
#
IP=""
@Markbnj
Markbnj / removepyc.sh
Created Aug 23, 2015
Recursively remove all .pyc files from a python project
View removepyc.sh
find . -name "*.pyc" -exec rm -rf {} \;
@Markbnj
Markbnj / install-pip.sh
Created Aug 23, 2015
Install updated pip
View install-pip.sh
# get rid of the version installed with ubuntu
sudo apt-get remove --auto-remove python-pip
# get the official installer
wget https://bootstrap.pypa.io/get-pip.py
# install it
sudo -H python get-pip.py
@Markbnj
Markbnj / simple-redis-log-handler.py
Created Aug 12, 2015
Simple redis log handler for python
View simple-redis-log-handler.py
import logging
import redis
class RedisLogHandler(logging.Handler):
"""
Class used to emit log messages to a redis list
"""
def __init__(self, host, port, key, db=0, formatter=None, level=logging.NOTSET):
logging.Handler.__init__(self, level)
@Markbnj
Markbnj / remove-images.sh
Created Aug 11, 2015
Remove all Docker images
View remove-images.sh
sudo docker rmi $(sudo docker images -a -q)
@Markbnj
Markbnj / remove-containers.sh
Created Aug 11, 2015
Stop and remove all Docker containers
View remove-containers.sh
sudo docker stop $(sudo docker ps -a -q)
sudo docker rm $(sudo docker ps -a -q)
@Markbnj
Markbnj / Dockerfile
Created Aug 11, 2015
Dockerfile for a simple redis server
View Dockerfile
# Dockerfile for building a redis server
FROM ubuntu:15.04
MAINTAINER Someone <someone@some.where>
# install and configure redis from source
RUN cd /home/root && \
wget -q http://download.redis.io/redis-stable.tar.gz && \
tar xvzf redis-stable.tar.gz && \
cd redis-stable && \