Skip to content

Instantly share code, notes, and snippets.

View dhoeric's full-sized avatar

Eric Ho dhoeric

View GitHub Profile
@dhoeric
dhoeric / .zshrc
Last active August 25, 2017 04:06
A snippet for auto-load/unload virtualenv by calling `workon` on a directory. This can be added on .profile/.bashrc/.zshrc, etc.
# Call virtualenvwrapper's "workon" if .venv exists. This is modified from--
# http://justinlilly.com/python/virtualenv_wrapper_helper.html
# and https://gist.github.com/cjerdonek/7583644
has_virtualenv() {
if [ -e .venv ]; then
ENV_NAME=`cat .venv`
workon "$ENV_NAME" && export CD_VIRTUAL_ENV="$ENV_NAME"
elif [ $CD_VIRTUAL_ENV ]; then
deactivate && unset CD_VIRTUAL_ENV
fi
@dhoeric
dhoeric / ip2geo.sh
Last active April 20, 2018 06:05
Get geographic location by IP address #scripts
# Put into .bashrc, source .bashrc, (max. 1000 requests per day)
# Example:
# $ ip2geo 8.8.8.8
# {
# "ip": "8.8.8.8",
# "hostname": "google-public-dns-a.google.com",
# "city": "Mountain View",
# "region": "California",
# "country": "US",
# "loc": "37.3860,-122.0838",
@dhoeric
dhoeric / docker-cheat-cheat.md
Last active April 20, 2018 06:25
[Docker Cheat Sheet] #docker

Export vm-based variable to environment

eval `docker-machine env your-vm`

Remove non-tagged docker image

docker rmi $(docker images | grep "^<none>" | awk '{print $3}' | tr '\n' ' ')
#!/bin/bash -e
# To unset cluster config in ~/.kube/config
if [ -z "$1" ]
then
echo "Usage: unset-kube-cluster.sh [cluster-name]"
exit
fi
cluster_name=$1
@dhoeric
dhoeric / Ubuntu 16.04
Last active July 18, 2024 17:07
install-docker-aws-ec2-user-data
#!/bin/bash
# Install docker
apt-get update
apt-get install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
apt-get update

Keybase proof

I hereby claim:

  • I am dhoeric on github.
  • I am dhoeric (https://keybase.io/dhoeric) on keybase.
  • I have a public key ASCYOMc3sblrgOG6ZdsJUrKJW7lUlIPWkmi6E-BkssZMDQo

To claim this, I am signing this object:

version: '3'
services:
app:
image: ghost:alpine
ports:
- 8080:2368
volumes:
- ./blog/content:/var/lib/ghost/content
@dhoeric
dhoeric / json2yaml.md
Last active November 7, 2017 03:59
json2yaml

Usage

pip install pyyaml
cat whatever.json | python ./main.py

Example

-> % cat test.json
{
@dhoeric
dhoeric / README.md
Last active April 23, 2018 02:51
[Check listening port] #troubleshoot #linux

Check all listening ports in server

$ sudo netstat -nat
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN
tcp6 0 0 :::22 :::* LISTEN
@dhoeric
dhoeric / README.md
Created May 2, 2018 04:13
[shell tricks] #unix #shell #find