Skip to content

Instantly share code, notes, and snippets.

View MattMS's full-sized avatar
🤔

Matt McKellar-Spence MattMS

🤔
View GitHub Profile
@MattMS
MattMS / python_3_http_server.py
Created February 24, 2016 11:52
Pure Python 3 HTTP server.
from http.server import BaseHTTPRequestHandler, HTTPServer
class RequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
content = 'Hello'
content_bytes = bytes(content, 'utf-8')
@MattMS
MattMS / number_bits.js
Last active November 5, 2016 09:54
Split a number into an Array of bit Strings (< 8 bits is always on left)
const bits = number => number.toString(2).split('').reverse().join('').match(/.{1,8}/g).reverse().map(v => v.split('').reverse().join(''))
/*
bits(2)
// ['10']
bits(256)
// ['1', '00000000']
*/
@MattMS
MattMS / sed_print_second_column.sh
Last active March 10, 2017 12:30
Print the second column (space-delimited) of a file.
# Given my_file containing first line of "my_id my_value", this will print "my_value".
cat ./my_file | sed -En '1{s/^(\S+)\s+(.*)$/\2/g ; p}'
size=$(ls -l ./my_file | awk '{ print $5 }')
echo $size
@MattMS
MattMS / aliases.sh
Last active March 14, 2017 04:40
Aliases to make bash slightly less annoying
alias d='docker'
alias dc='docker-compose'
alias di='docker images'
alias gitb='git branch'
alias gitc='git checkout'
alias gitg='git pull'
alias gitp='git push'
alias gits='git status'
@MattMS
MattMS / Ramda extensions.md
Created March 25, 2017 10:49
Possibly helpful function compositions for Ramda.

Ramda extensions

Test a path exists:

const has_path = R.pipe(R.path, R.complement(R.isNil))
@MattMS
MattMS / Kubernetes tasks.md
Last active March 27, 2017 11:10
Kubernetes tasks with kubectl

Kubernetes tasks

Get credentials before using kubectl:

gcloud container clusters get-credentials my-cluster --project my-project --zone my-zone

Pod management

Delete all pods (in all namespaces) that are in "Error" state:

Users in Linux

Sorted list of all users:

cat /etc/passwd | awk -v FS=: -e '{print $1}' | sort

Switch to another user (prompts for password):

su - my_other_user
@MattMS
MattMS / Append to PATH.fish
Created July 13, 2017 04:10
Append to current folder to PATH in Fish Shell
set PATH $PATH .
@MattMS
MattMS / small_file_contents.fish
Last active July 21, 2017 02:16
Print file name (minus `.txt` extension), `=`, then file contents
#!/usr/bin/env fish
set ext '.txt'
for f in (ls | grep $ext)
echo (basename $f $ext)=(cat $f)
end