Skip to content

Instantly share code, notes, and snippets.

@jaytaylor
jaytaylor / yaml2json.py
Created August 9, 2018 22:01
Python one-liner to convert YAML to JSON
python -c 'import json, sys, yaml ; y = yaml.safe_load(sys.stdin.read()) ; print(json.dumps(y))'
@jaytaylor
jaytaylor / download-instance-attributes.py
Last active September 6, 2018 16:23
AWS Instance attributes recursive downloader
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Recursive AWS-style instance attributes downloader."""
import logging
import os
import re
import requests

Got this from bbolt today, not sure what to make of it. Is this a known issue? Have I done something wrong?

Jun 28 00:11:24 andromeda.host andromeda[28574]: fatal error: fault
Jun 28 00:11:24 andromeda.host andromeda[28574]: unexpected fault address 0x7fd918028008
Jun 28 00:11:24 andromeda.host andromeda[28574]: [signal SIGSEGV: segmentation violation code=0x1 addr=0x7fd918000000 pc=0x95324d]
Jun 28 00:11:24 andromeda.host andromeda[28574]: goroutine 59 [running]:
Jun 28 00:11:24 andromeda.host andromeda[28574]: runtime.throw(0xb73dca, 0x5)
Jun 28 00:11:24 andromeda.host andromeda[28574]:         /usr/local/go/src/runtime/panic.go:616 +0x81 fp=0xc42007f198 sp=0xc42007f178 pc=0x42c851
Jun 28 00:11:24 andromeda.host andromeda[28574]: runtime.sigpanic()
@jaytaylor
jaytaylor / _README.md
Created April 16, 2018 16:42
hn-utils example favorites output for user: sharemywin

hn-utils favorites usage example

hackernews favorites output for user sharemywin

Package source code is available from jaytaylor.com/hn-utils.

Command

hn-utils -u sharemywin
@jaytaylor
jaytaylor / 0-example-pre-autopep8-formatting.py
Created April 6, 2018 18:36
autopep8 command: autopep8 --pep8-passes 2000 --verbose --aggressive --aggressive --ignore=E501,E722
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse
import sys
def main(args):
parser = argparse.ArgumentParser(
description='Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text.. ',
argument_default=False,
package main
import (
"fmt"
"github.com/jaytaylor/html2text"
)
func main() {
inp := ` <html><head><meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Diso-8859-=1"><style type=3D"text/css" style=3D"display:none;"><!-- P {margin-top:0;margi=n-bottom:0;} --></style></head><body dir=3D"ltr"><div id=3D"divtagdefaultwrapper" style=3D"font-size:12pt;color:#000000;font=-family:Calibri,Helvetica,sans-serif;" dir=3D"ltr"><p style=3D"margin-top:0;margin-bottom:0"><br></p><p style=3D"margin-top:0;margin-bottom:0"><br></p><div id=3D"Signature"><div id=3D"divtagdefaultwrapper" dir=3D"ltr" style=3D"font-size:12pt; color=:rgb(0,0,0); background-color:rgb(255,255,255); font-family:Calibri,Arial,H=elvetica,sans-serif,EmojiFont,&quot;Apple Color Emoji&quot;,&quot;Segoe UI =Emoji&quot;,NotoColorEmoji,&quot;Segoe UI Symbol&quot;,&quot;Android Emoji&=quot;,EmojiSymbols,EmojiFont,&quot;Apple Color Emoji&quot;,&quot;Segoe UI E=moji&quot;,NotoColorEmoji,&quot;Segoe UI Symbol&quot;,&quot;Android Emoji&q=uot;,EmojiSy
@jaytaylor
jaytaylor / macos-howto-kill-pid-listening-on-port.md
Created March 16, 2018 19:12
HOWTO: Kill PID occupying a port on macOS.

Mac OS X

HOWTO: Kill PID occupying a port on macOS.

lsof -t -i tcp:<port-number> | xargs kill

Example

@jaytaylor
jaytaylor / LXC-LXD-2.x-curl-API.md
Created March 4, 2018 22:56
HOWTO: Curl the LXD unix.socket file.

It is possible to use curl to query the LXD unix.socket directly:

curl --unix-socket /var/lib/lxd/unix.socket http:/1.0/containers | jq .

Example output:

{
@jaytaylor
jaytaylor / LXC_LXD_2.x_mount_errors.md
Last active February 24, 2018 02:04
LXC / LXD 2.0 Mount Permission Denied Errors

LXC / LXD 2.0 Mount Errors

2018-02-23

Symptom

root@ip-1-2-3-4:~# lxc list
cannot perform operation: mount /var/lib/snapd/hostfs/var/lib/lxd /var/lib/lxd -o nosuid,nodev,noexec,rbind,rslave: Permission denied
@jaytaylor
jaytaylor / k8s-gigawatt-messed-up-subnetting-networking-workaround.md
Last active February 24, 2018 00:27
Kubernetes kubeadm-setup.sh: Workaround for Gigawatt's crazy DC networking..

Initial symptoms

Kubernetes master setup went fine, but when I tried to join a kbminion slave node:

Checking whether docker can run container ...
Checking iptables default rule ...