Skip to content

Instantly share code, notes, and snippets.

@keyan
keyan / lost.json
Last active October 6, 2019 21:31
Script for converting MTA XML lost and found feed to JSON/XML as well as a sample converted JSON file.
{
"name": "items",
"children": [
{
"name": "Home Furnishings",
"children": [
{
"name": "Wall and Window Covering",
"value": 98
},
@keyan
keyan / appt.sh
Created August 6, 2019 18:58
bash script that curls a url every minute and outputs audio if a regex doesn't match
check_for_opening () {
res=`curl --silent "https://unionpt.fullslate.com/employees/4320?iid=7959&services%5B%5D=208" | grep "Next opening"`
if [ -n "`echo $res | grep -e '.*Thursday, September 5.*'`" ]
then
echo "No openings found, sleeping..."
else
say "Found an appointment opening"
fi
}
@keyan
keyan / halyard.md
Created January 4, 2018 16:51
Some notes on how to setup spinnaker and use halyard

Installation

  • Halyard must be run on Ubuntu 14.04 (Trusty), you will likely use a VM to run it:
$ vagrant init ubuntu/trusty64; vagrant up --provider virtualbox
  • Sync your local kubeconfig with the guest VM by adding the following line to your newly created Vagrantfile:
@keyan
keyan / gist:adda12dd749d35090bc69fce76355805
Last active May 29, 2019 22:57
Minimal vimrc, with most super custom stuff removed
set nocompatible "be iMproved
filetype off " necessary to make sure vundle does something
set modelines=0 "security hole involving modelines, probably patched by now?
" General Options
" -------------------------------------
" Automatically set up vundle and install all bundles if vundle is not installed.
let iCanHazVundle=1
let vundle_readme=expand('~/.vim/bundle/vundle/README.md')
if !filereadable(vundle_readme)
@keyan
keyan / lmdb.tcl
Created February 27, 2019 07:19 — forked from antirez/lmdb.tcl
LMDB -- First version of Redis written in Tcl
# LVDB - LLOOGG Memory DB
# Copyriht (C) 2009 Salvatore Sanfilippo <antirez@gmail.com>
# All Rights Reserved
# TODO
# - cron with cleanup of timedout clients, automatic dump
# - the dump should use array startsearch to write it line by line
# and may just use gets to read element by element and load the whole state.
# - 'help','stopserver','saveandstopserver','save','load','reset','keys' commands.
# - ttl with milliseconds resolution 'ttl a 1000'. Check ttl in dump!
@keyan
keyan / gtfs_rt_proto_parser.py
Created February 15, 2019 18:21
A small helper script for quickly parsing agency GTFS-RT feeds for debugging
"""
A small helper script for quickly parsing agency GTFS-RT feeds for debugging.
Usage:
$ service_venv python3 parse_gtfs_rt_feed.py --help
"""
import argparse
import requests
from google.transit import gtfs_realtime_pb2
@keyan
keyan / nested_map.py
Created November 1, 2018 22:13
Apply a func to a target class to any fields and items nested within an object
def nested_map(obj: object, func, target_class) -> Any:
"""
Accepts any object type and calls .func() on any nested fields of the specified class.
"""
def _nested_map(obj: object) -> None:
"""
Traverse all object fields and list items, calling func when possible.
"""
# Objects without __dict__ cannot have vars() called
if not hasattr(obj, '__dict__'):
@keyan
keyan / ssl_disable.md
Last active March 19, 2018 16:31
Disabling Python's SSL verification

It is pretty confusing how to add custom root certificates to Python's trusted cert list as it doesn't use system certs. Instead I just disabled verification entirely. Note this is for local development only and SHOULD NOT BE USED IN PRODUCTION:

$ export PYTHONHTTPSVERIFY=0

This is helpful for capturing and inspecting outbound packets using Charles proxy or a similar tool.

@keyan
keyan / fair_lock.py
Created January 19, 2018 03:23
Implement a "fair lock"
"""
A "fair lock" is a lock which guarantees threads are given access in
the order that they requested it. The whole idea here is just to play
with the concurrency control ideas, because Python's Queue
implementation is already threadsafe, therefore acheiving the same
behavior as the FIFO lock below.
"""
import threading
@keyan
keyan / email_todo_authors.py
Last active January 4, 2018 18:24
A script you can run in your repo to scan for TODO messages and email the authors asking them to fix it! Can be easily adapted for other search strings.
#!/usr/bin/python
"""
This script searches the git repo looking for TODO messages, determines the
author of the line, then emails that author asking them to repair the issue.
It is intended to be run at a regular interval on a CI server or cron-job
server. By changing the `SEARCH_STRING` the script can be easily adapted to
trigger on any undesired code.
Usage: