Skip to content

Instantly share code, notes, and snippets.

View MattMS's full-sized avatar
🤔

Matt McKellar-Spence MattMS

🤔
View GitHub Profile
@MattMS
MattMS / remove_child_nodes.coffee
Created February 24, 2016 11:45
Remove all child nodes from a node on a web page.
remove_all_child_nodes = (node)->
while document.body.childNodes.length
document.body.removeChild document.body.childNodes[0]
@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 / time format examples.md
Last active July 26, 2018 10:02
Convert the current UTC time to different formats.

Time format examples

Gets the current UTC time to seconds accuracy (max available with date). Using date and sed so these can run in Alpine Linux.

As file path

For example: 1999/12/31/23/59/59

@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 / Google_Cloud_access_token.sh
Created March 10, 2017 12:34
Get an access token for future requests to Google Cloud APIs
access_token=$(curl
-H "Metadata-Flavor: Google"
--show-error
--silent
http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token?alt=text
| awk '$1 == "access_token" { print $2 }')
@MattMS
MattMS / Node.js Ubuntu install.md
Last active July 21, 2017 12:10
Install Node.js on Ubuntu from package manager

Install Node.js on Ubuntu

The [official instructions][install] say to download and run a script with sudo, which should sound scary. So I went through the script and wrote up what it is doing.

It's actually fine to run, but it's not much harder to do it all yourself.

Add the key

@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: