Skip to content

Instantly share code, notes, and snippets.

View derrickturk's full-sized avatar
💭
(Come in under the shadow of this red rock)

Derrick Turk derrickturk

💭
(Come in under the shadow of this red rock)
View GitHub Profile
@derrickturk
derrickturk / excepthook.py
Created May 14, 2025 16:14
Python: register the debugger to run in an uncaught exception hook
def _debug() -> None:
import sys
import pdb
import traceback
def debughook(etype, value, tb):
traceback.print_exception(etype, value, tb)
print() # make a new line before launching post-mortem
pdb.pm() # post-mortem debugger
@derrickturk
derrickturk / wait_relative.py
Created May 12, 2025 16:08
Selenium: wait until an element can be found by relative locator
from selenium.common import NoSuchElementException
from selenium.webdriver.common.by import By
from selenium.webdriver.remote.webdriver import WebDriver
from selenium.webdriver.remote.webelement import WebElement
from selenium.webdriver.support.relative_locator import RelativeBy, locate_with
class WaitRelative:
def __init__(self, by: RelativeBy):
self._by = by
@derrickturk
derrickturk / bonbons.hs
Created April 4, 2025 02:24
vibe coding [WIP]
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE OverloadedRecordDot #-}
import Data.List.NonEmpty (NonEmpty(..))
import Diagrams.Prelude
import qualified Diagrams.Color.XKCD as CX
import Diagrams.Backend.SVG.CmdLine
data "aws_ami" "latest_spotfire" {
most_recent = true
owners = ["aws-marketplace"]
filter {
name = "product-code"
values = ["2c7dxpxtbfm3wc7iik24lbll2"]
}
}
resource "aws_instance" "spotfire" {
@derrickturk
derrickturk / snitchboxes.py
Last active February 27, 2025 17:33
race condition in matplotlib.widgets.TextBox with QTAgg back end and toolmanager in use
import os
import sys
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.widgets import TextBox
matplotlib.use('QTAgg')
matplotlib.rcParams['toolbar'] = 'toolmanager'
@derrickturk
derrickturk / dogcrypt2.m
Created October 31, 2024 20:36
DOG + ANT = CAT
:- module dogcrypt2.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
:- import_module int, list, string, solutions.
main(!IO) :-
@derrickturk
derrickturk / blacklist.dhall
Last active October 24, 2024 15:16
A dinky "productivity app"
let Block = { level: Natural, list: List Text }
let blacklist: List Block =
[ { level = 0
, list =
[ "reddit.com"
, "old.reddit.com"
, "www.reddit.com"
, "twitter.com"
, "x.com"
, "nitter.poast.org"
@derrickturk
derrickturk / zmapgrid.py
Last active April 22, 2024 16:06
Read ZMap+ grids to NumPy arrays + metadata
# Copyright (c) 2024 dwt | terminus, LLC
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
@derrickturk
derrickturk / numbers.cpp
Created February 6, 2024 22:53
X-macros
#include <cstdio>
const std::size_t num_buttons = 16;
const std::size_t total_buttons = num_buttons + 4;
#define FOR_EACH_NUMBER(n) "Button " #n,
const char* english[total_buttons] = {
#include "numbers.def"
"Hat Up",
"Hat Down",
@derrickturk
derrickturk / metaconcat.cpp
Last active February 6, 2024 22:40
In his house at R'lyeh, dead Cthulhu waits dreaming
#include <cstddef>
#include <cstdio>
#include <utility>
constexpr std::size_t num_digits(unsigned char n) noexcept
{
if (n < 10)
return 1;
if (n < 100)
return 2;