Skip to content

Instantly share code, notes, and snippets.

View Kylep342's full-sized avatar

Kyle Pekosh Kylep342

View GitHub Profile
#!/usr/bin/env python
class Clock:
def __init__(self, year, hour, minute, second):
self.year = year
self.hour = hour
self.minute = minute
self.second = second
@Kylep342
Kylep342 / shipt.sh
Last active April 5, 2022 14:27
Small command to atomically build, tag, and push images to a registry
#!/usr/bin/env bash
shipt() {
if [[ $# -ne 3 ]]; then
echo 'Need 3 arguments\n1. Name of local docker tag\n2. Path to local dockerfile\n3. Name of remote docker registry'
else
docker build --tag $1 $2;
docker image tag $1 $3/$1;
docker image push $3/$1;
fi
}
@Kylep342
Kylep342 / thread_dumper.py
Last active March 10, 2022 22:31
Dump the stack traces of all executing Python threads when the Python Process receives the `usr1` signal.
import signal
import sys
import traceback
def sigterm_handler(signal, frame):
# save the state here or do whatever you want
for thread_id, frame in sys._current_frames().items():
logger.info(f"Stack for thread {thread_id}")
traceback.print_stack(frame, file=sys.stdout)
logger.info("")
@Kylep342
Kylep342 / CubicalConundrum.md
Last active February 13, 2022 14:11
Riddler Classic - 2/11/2022

Riddler Classic - 2/11/2022

Riddle

From Dean Ballard comes a cubical conundrum:

Consider a cube, which has eight vertices, or corners. Suppose I assign a prime number to each vertex. A “face sum” is the value I get when I add up all four prime numbers on one of the six faces.

Can you find eight primes and arrange them on a cube so that the six face sums are all equal?

Extra credit: Can you find another set of eight primes that can similarly be arranged on the vertices of a cube? How many more can you find?

@Kylep342
Kylep342 / trapezoidal.py
Last active February 11, 2022 16:58
Riddler Express - 2/11/2022
# please don't crucify me for this brutally inefficient method
import collections
def first_nth_trapezoidal(n):
tz = collections.defaultdict(list)
for i in range(1, 1001):
for j in range(i + 1, 1001):
candidate = list(range(i, j))
@Kylep342
Kylep342 / README.sql
Last active March 10, 2022 21:15
Configure postgres for `psql` use after install via homebrew
-- Substitue my name with your OS user's name
-- for both login and database creation
-- connect to the database
psql -U kyle.pekosh -d postgres
-- Create the postgres role and your database
CREATE ROLE postgres;
ALTER ROLE postgres WITH CREATEROLE;
CREATE DATABASE "kyle.pekosh";