Skip to content

Instantly share code, notes, and snippets.

View coxley's full-sized avatar

Codey Oxley coxley

View GitHub Profile
@coxley
coxley / read_zstd_dict.go
Created December 6, 2023 04:57
Read zstd dict
package main
import (
"bytes"
"encoding/binary"
"fmt"
)
// Little Endianed
var ZstdMagic = []byte("\x28\xB5\x2F\xFD")
@coxley
coxley / main.go
Last active July 27, 2022 04:11
Problem: Number of Islands
// Problem: https://leetcode.com/problems/number-of-islands/
// ASCII byte reference
// 48 = "0"
// 49 = "1"
// 120 = "x"
package main
import "fmt"
func findBounds(input [][]byte, row, col int) int {
@coxley
coxley / buggy_timeout.py
Created May 14, 2020 22:22
This demonstrates why asyncio.wait_for should never be used with loop.run_in_executor. Cancellation doesn't cross that boundary.
import time
import asyncio
def blocking():
time.sleep(5)
print("hell yeah")
async def main():
@coxley
coxley / async_logging.py
Last active November 21, 2021 00:28
Handler w/ flusher thread running in an event loop.
import asyncio
import logging
import time
import threading
import typing as t
import janus
LOG = logging.getLogger(__name__)
@coxley
coxley / async_logging.py
Created April 26, 2020 05:54
Handler w/ flusher thread running in an event loop.
import asyncio
import logging
import time
import threading
import typing as t
import janus
LOG = logging.getLogger(__name__)
#!/bin/env python
def toggle_comment(lines, filename, startswith=False):
'''Toggle comment on lines in filename
Options:
lines (list): lines to comment.
filename (str): filname
startswith (bool): allows providing start of a line vs exact matching
@coxley
coxley / asn_convert.py
Last active February 24, 2016 20:19
ASPLAIN to ASDOT (AS-PLAIN AS-DOT) and reverse
def plain_to_dot(asn): # -> str
'''Take ASPLAIN and return ASDOT notation
asn: int
'''
barray = struct.pack('>I', asn)
return '%d.%d' % struct.unpack('>HH', barray)
def dot_to_plain(asn): # -> int
@coxley
coxley / 01_MPLS_SDN_Era_Vagrant.md
Last active August 26, 2020 17:21
MPLS in the SDN Era Vagrant Topology

Instructions

Rename 03_Vagrantfile to Vagrantfile and run vagrant up

You may need a couple extra plugins. If it complains, install what is mentioned in the error msg with vagrant install [x]

Loopback IPs are not configured here

Topology

Keybase proof

I hereby claim:

  • I am coxley on github.
  • I am codey (https://keybase.io/codey) on keybase.
  • I have a public key ASAdPlQ6Amw-Cm_WrqBP9Qoe15zwQanYo__bBTTwlMAMHQo

To claim this, I am signing this object:

@coxley
coxley / dyndnsd.conf
Created December 11, 2015 21:45
Upstart init for cmur2/dyndnsd
description "dyndnsd"
author "codey.a.oxley+os@gmail.com"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
respawn limit 15 5
exec /usr/local/bin/dyndnsd /opt/dyndnsd/config.yaml
# vim: set ft=upstart: