Skip to content

Instantly share code, notes, and snippets.

View tomkinsc's full-sized avatar

Chris Tomkins-Tinch tomkinsc

View GitHub Profile
@tomkinsc
tomkinsc / attach-to-running-container.sh
Created January 21, 2014 01:50
This shell script allows the user to reattach a bash session to a running Docker container.
#!/bin/bash
# Chris Tomkins-Tinch <chris@takeitapart.com>
if [ "$1" == "-h" ] ; then
echo "Purpose: Attaches a bash session to a running docker container"
$0
exit 0
fi
@tomkinsc
tomkinsc / gist:8546608
Created January 21, 2014 19:29
One-liner to remove all untagged Docker images (those with hash-like IDs rather than ones explicitly specified with the -t flag).
sudo docker rmi $(sudo docker images | grep "^<none>" | awk "{print $3}" | tr -s ' ' | cut -d ' ' -f 3)
@tomkinsc
tomkinsc / gist:8546616
Created January 21, 2014 19:29
Remove all docker containers that are not currently running
sudo docker rm $(sudo docker ps -a | grep Exit | cut -d " " -f1)
@tomkinsc
tomkinsc / gist:8546623
Created January 21, 2014 19:30
Stop all docker containers
sudo docker stop $(sudo docker ps -a -q)
@tomkinsc
tomkinsc / gist:8546631
Created January 21, 2014 19:30
Remove all docker containers
sudo docker rm $(sudo docker ps -a -q)
@tomkinsc
tomkinsc / gist:8546637
Created January 21, 2014 19:30
Remove all docker images
sudo docker rmi $(sudo docker images -a -q)
@tomkinsc
tomkinsc / .bashrc_partial
Last active March 1, 2022 22:06
.bashrc additions to alias ls to the full ls -lap with colors, and also to store each directory change so that a new shell session restores location to the last directory used. Simply add to ~/.bashrc. Changes go into effect in the next terminal session or when you call "source ~/.bashrc" If on mac, set to use this profile by adding this to .bas…
ls_ext() {
if [ $# -eq 0 ]; then # if ls is called without any arguments
# make ls print full info, with color
ls -laF
else
ls $@ # otherwise call as intended
fi
}
alias ls="ls_ext"
@tomkinsc
tomkinsc / is_docker_running.sh
Created January 24, 2014 22:16
This script checks to see if docker is running, waits until timing out or docker is up. Must be run as root.
#!/bin/bash
DAEMON_TIMEOUT=${DAEMON_TIMEOUT:-20} # timeout in seconds
DOCKER_UNIX_SOCKET="/var/run/docker.sock"
# Start docker here
service docker start
CHECK_CMD="while ! /bin/echo -e 'GET /v1.3/version HTTP/1.0\n\n' | socat - unix-connect:$DOCKER_UNIX_SOCKET 2>/dev/null | grep -q '200 OK'; do
# Wait before checking again to see if Docker is up
@tomkinsc
tomkinsc / vimdiff
Created January 28, 2014 18:47
Findings on vimdiff: How I Learned to Stop Worrying and Love the Three-Way Merge
ctrl-w //allows jumping between the three documents
:ls //lists the buffer (each of the 3 way documents) names
:diffget [buffer number] //focuses on the window you want to keep
:only //closes text areas that aren’t in focus
:wq //write this text to file and quit
@tomkinsc
tomkinsc / DefaultKeyBinding.dict
Last active August 3, 2022 18:59
Remap mac home/end keys so they work as expected
/*
mkdir ~/Library/KeyBindings
touch ~/Library/KeyBindings/DefaultKeyBinding.dict
via:
https://ss64.com/osx/syntax-keybindings.html
https://ss64.com/osx/syntax-keyboard.html
Key Modifiers
^ : Ctrl