Skip to content

Instantly share code, notes, and snippets.

View cgswong's full-sized avatar

Stuart Wong cgswong

View GitHub Profile
@cgswong
cgswong / coreid.sh
Last active August 29, 2015 14:24
Get AWS AMI ID for CoreOS channels
#!/bin/bash
# CoreOS channel ["stable" | "beta" | "alpha"]
channel=${1:-"alpha"}
# AWS AMI disk backing ["pv" | "hvm"]
disk=hvm
# Use default us-east-1 region
region=${2:-"us-east-1"}
1. Find ID of container to move
`docker ps -a` or `docker images`
2. Save container as new image:
`docker save [newimage] | gzip > /tmp/docker-[newimage].tar.gz`
3. Copy file, `/tmp/docker-[newimage].tar.gz`, to destination and gunzip
4. Load new image:
`docker load --input docker-[newimage].tar`
@cgswong
cgswong / aws-cfn.sh
Created July 7, 2016 13:35
Setup CentOS server with AWS CFN bootstrap
#!/bin/bash
# Setup CentOS 7 host as AMI
# Update base OS update, and install EPEL repo and Python Pip
sudo yum -y update
sudo yum –y install epel-release
sudo yum -y install python-pip
# Install Python add-ons:
sudo pip install pystache
@cgswong
cgswong / iterm2.md
Last active March 25, 2024 08:43
iterm2 shortcut cheat sheet

Note: You may have to go into Preferences (⌘,) -> Profiles -> Keys and enable Left option (⌥) key acts as: +Esc for the option commands to work.

Modifier Symbol
Option
Command
Control
Caps Lock
Shift
@cgswong
cgswong / Atom.md
Last active May 15, 2018 15:16
Atom shortcut cheat sheet

Use these rapid keyboard shortcuts to control the GitHub Atom text editor on Mac OSX.

Key to the Keys

  • ⌘ : Command key
  • ⌃ : Control key
  • ⌫ : Delete key
  • ← : Left arrow key
  • → : Right arrow key
  • ↑ : Up arrow key
@cgswong
cgswong / elasticsearch-iam-policy.json
Created March 8, 2017 16:12
AWS ES IAM policy allows both IP access (Kibana proxy) and resource (EC2) access
{
"Version": "2012-10-17",
"Statement": [
{
"Resource": "arn:aws:es:us-east-1:<account_id>:domain/<es_domain>/<es_index|*>",
"Principal": {
"AWS": "arn:aws:iam::<account_id>:role/<iam_role>"
},
"Action": ["es:*"],
"Effect": "Allow",
@cgswong
cgswong / .screenrc
Last active July 17, 2024 20:07
Screen config file
# Force screen to process ^S/^Q
deflogin on
# Autodetach session on hangup instead of terminating screen completely
autodetach on
# Change escape command key invocation
escape ``
# Instead of Control-a, make the escape/command character be Control-s
##escape ^Ss
@cgswong
cgswong / ssh_complete
Created May 15, 2017 14:14
SSH hostname auto complete
_complete_ssh_hosts ()
{
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
comp_ssh_hosts=$(cat ~/.ssh/config ~/.ssh/conf.d/*.ssh | \
grep "^Host " | grep -v '\*' | uniq | \
awk '{print $2}')
COMPREPLY=( $(compgen -W "${comp_ssh_hosts}" -- $cur))
return 0
}
@cgswong
cgswong / keybase.md
Created June 1, 2017 13:34
KeyBase proof

Keybase proof

I hereby claim:

  • I am cgswong on github.
  • I am cgswong (https://keybase.io/cgswong) on keybase.
  • I have a public key ASDP9xywaI3f0fjm2DdsvdJQZ_6LJH5WLUbBUwGGxz6k_wo

To claim this, I am signing this object:

@cgswong
cgswong / ansible-tester.sh
Created July 27, 2017 17:49
Ansible role tester using Docker
#!/bin/bash
#
# Ansible role test shim.
#
# Usage: [OPTIONS] ./tests/ansible-tester.sh
# - distro: a supported Docker distro version (default = "centos7")
# - playbook: a playbook in the tests directory (default = "test.yml")
# - role_name: the role name (default = "${role_name}")
# - cleanup: whether to remove the Docker container (default = true)
# - container_id: the --name to set for the container (default = timestamp)