Skip to content

Instantly share code, notes, and snippets.

View dankrause's full-sized avatar

Dan Krause dankrause

View GitHub Profile
import builtins
import collections
import contextlib
import copy
import dis
import json
import socket
import struct
import types
class _ExceptionHandlerBase:
def __init__(self, handler_map):
self._handler_map = handler_map
def __call__(self, func):
def wrapper(*args, **kwargs):
with self:
func(*args, **kwargs)
return wrapper
### Keybase proof
I hereby claim:
* I am dankrause on github.
* I am dankrause ( on keybase.
* I have a public key ASBmYrX3pc6j-rDw3Yfm1F_mBjHX0SLjDc1izIvsgICs7wo
To claim this, I am signing this object:
dankrause / postgresql_recursive.sql
Last active February 26, 2024 16:03
An example of creating a recursive postgresql query to generate data about parent-child relationships within a single table.
parent INTEGER
INSERT INTO test (id, parent) VALUES
(1, NULL),
(2, 1),
dankrause / smilebasic.lang
Last active December 13, 2017 14:31
GTKSourceView syntax highlighting for SmileBASIC
<?xml version="1.0" encoding="UTF-8"?>
<!-- Place this file in /usr/share/gtksourceview-3.0/language-specs/ -->
<language id="smilebasic" _name="SmileBASIC" version="2.0" _section="Sources">
<property name="mimetypes">text/x-smilebasic</property>
<property name="globs">*.sbas</property>
<property name="line-comment-start">'</property>
dankrause /
Last active April 13, 2024 10:50
Create a custom tinycore linux iso. Adjust the config at the beginning of the script, or supply a conf as the first arg. Requires xorriso.
set -e
function cleanup() {
# clean up our temp folder
rm -rf "${TMPDIR}"
trap cleanup EXIT
dankrause /
Last active August 29, 2015 14:05
Toy finite state machine implementation in Python
import itertools
class FSMException(Exception):
class DuplicateRule(FSMException):
class InvalidStateTransition(FSMException):
dankrause /
Last active August 29, 2015 14:00
An example jobboard client for taskflow
#!/usr/bin/env python
Usage: [options] <jobboard_name> create <name> <details> [options] <jobboard_name> list [options] <jobboard_name> delete <uuid> [options] <jobboard_name> clear
dankrause /
Last active February 16, 2024 16:23
Simple socket IPC in python
# Copyright 2017 Dan Krause
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
dankrause /
Last active August 29, 2015 13:57
Toy pub/sub implementation in python
from functools import partial
from fnmatch import fnmatchcase
from collections import defaultdict
class Event(dict):
handlers = defaultdict(list)
def subscribe(cls, *args):
if not callable(args[-1]):