Skip to content

Instantly share code, notes, and snippets.

View coxley's full-sized avatar

Codey Oxley coxley

View GitHub Profile
@coxley
coxley / slack-pagerduty-oncall.py
Created September 25, 2024 14:53 — forked from tr-fteixeira/slack-pagerduty-oncall.py
Updates a Slack User Group with People that are on call in PagerDuty (updated for slack_sdk after previous auth method was deprecated, changed user lookup on slack). Based on: https://gist.github.com/markddavidoff/863d77c351672345afa3fd465a970ad6
"""
Script to update on-call groups based on pagerduty escalation policies
From: https://gist.github.com/markddavidoff/863d77c351672345afa3fd465a970ad6
Slack permissions required:
- Installer must be able to update user groups.
- usergroups:read
- usergroups:write
- users:read
- users:read.email
@coxley
coxley / postgres_test.go
Created July 18, 2024 15:17
Postgres test isolation helper
package pgtest
import (
"context"
"fmt"
"strings"
"sync"
"testing"
"github.com/docker/go-connections/nat"
@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