Skip to content

Instantly share code, notes, and snippets.

View akatrevorjay's full-sized avatar
🌙

Trevor Joynson akatrevorjay

🌙
View GitHub Profile
@akatrevorjay
akatrevorjay / ipdb-run-module.py
Created March 5, 2020 22:56
ipdb run python module, aka the missing `ipdb -m`
#!/usr/bin/env python3
"""
Usage: $0 myapp.modulewithmain [ARGV..]
"""
import ipdb
import runpy
import sys
#!/bin/bash
set -eo pipefail
usage() {
cat <<-'EOF'
# Container exec
A method for exporting commands for transparent docker-compose usage from your shell,
letting you forget that you're even using commands across different containers.
@akatrevorjay
akatrevorjay / tabs-to-repos.py
Last active March 9, 2018 16:19
Download all github repos that you have open in firefox tabs
#!/usr/bin/env python3
"""
_____________
tabs-to-repos -- Quickly gnt all of the github repos that you have open in firefox tabs.
Pipe the output to your shell to actually clone them, otherwise it just prints the commands and some comments ;)
@trevorj 12/2017
https://gist.github.com/akatrevorjay/3fb5bc753edd42b2abd0accb4dde4cdc
"""
@akatrevorjay
akatrevorjay / json2yaml.py
Last active June 27, 2019 22:09
( json2yaml | yaml2json | j2y | y2j ) that preserves original ordering in all cases (for normal types at least)
#!/usr/bin/env python
"""
json2yaml -- what it says.
Features:
- Preserves order of original document, which makes diffing much easier.
- Symlink it to `j2y`, `y2j`, 'yaml2json` and it'll do what you expect.
https://gist.github.com/akatrevorjay/918755c8eb2c66a48566d77fb578630c
"""
@akatrevorjay
akatrevorjay / es-send-search-party
Last active December 6, 2017 05:12
Kick elasticsearch until it finds your unassigned shards
#!/usr/bin/env zsh
##
## "You know, for sanity."
##
## ES clusters can determine that your shards are permanently missing at times, marking them forever unassigned.
## You go and look, but the shards are right there. What?
## What this script does is kick ES to make it actually take a look.
## For some reason telling ES to move the shard makes it realize it does in fact exist. Don't ask me, man.
##
set -eo pipefail
@akatrevorjay
akatrevorjay / refind.conf
Last active December 10, 2017 03:21
vga switcheroo wrapper and such for macbook pro 10+ efi booting (intel + amd) I've ended up with over the years
#
# refind.conf
# Configuration file for the rEFInd boot menu
#
# Timeout in seconds for the main menu screen. Setting the timeout to 0
# disables automatic booting (i.e., no timeout). Setting it to -1 causes
# an immediate boot to the default OS *UNLESS* a keypress is in the buffer
# when rEFInd launches, in which case that keypress is interpreted as a
# shortcut key. If no matching shortcut is found, rEFInd displays its
@akatrevorjay
akatrevorjay / pretty.py
Last active October 12, 2017 15:56
A pprint that doesn't suck
import six
import sys
import pygments
from pprint import pformat
STYLE = pygments.styles.get_style_by_name('monokai')
FORMATTER = pygments.formatters.get_formatter_by_name('console16m', style=STYLE)
LEXER_PYTHON = pygments.lexers.get_lexer_by_name('python{}'.format(six.PY3 and '3' or ''))
@akatrevorjay
akatrevorjay / thespian-raft.py
Created June 23, 2017 03:07 — forked from rcarmo/thespian-raft.py
The Raft leader election protocol, implemented atop GoDaddy's Thespian actor library
from thespian.actors import *
from datetime import datetime, timedelta
from logging import getLogger, basicConfig, DEBUG
from random import randint
basicConfig(level=DEBUG)
log = getLogger(__name__)
class Postman(Actor):
@akatrevorjay
akatrevorjay / ini2env.py
Last active June 9, 2017 10:55
Convert ini to env file
#!/usr/bin/env python
from __future__ import print_function, absolute_import
import itertools
import logging
import logging.config
import sys
import argparse
import io
#!/bin/bash
set -eo pipefail
reset="\e[0m"
red="\033[0;31m"
green="\033[0;32m"
for url in "$@"; do
if curl -sSLfo /dev/null "$url" >/dev/null 2>&1; then
echo -e "${green}GOOD" "$url" "${reset}"