Skip to content

Instantly share code, notes, and snippets.

Avatar

Dan Krause dankrause

View GitHub Profile
View exception_handler.py
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
View keybase_proof.txt
### Keybase proof
I hereby claim:
* I am dankrause on github.
* I am dankrause (https://keybase.io/dankrause) on keybase.
* I have a public key ASBmYrX3pc6j-rDw3Yfm1F_mBjHX0SLjDc1izIvsgICs7wo
To claim this, I am signing this object:
@dankrause
dankrause / postgresql_recursive.sql
Last active Jul 25, 2022
An example of creating a recursive postgresql query to generate data about parent-child relationships within a single table.
View postgresql_recursive.sql
CREATE TABLE test
(
id INTEGER,
parent INTEGER
);
INSERT INTO test (id, parent) VALUES
(1, NULL),
(2, 1),
@dankrause
dankrause / smilebasic.lang
Last active Dec 13, 2017
GTKSourceView syntax highlighting for SmileBASIC
View smilebasic.lang
<?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">
<metadata>
<property name="mimetypes">text/x-smilebasic</property>
<property name="globs">*.sbas</property>
<property name="line-comment-start">'</property>
</metadata>
@dankrause
dankrause / find-bad-filenames.py
Last active Aug 29, 2015
Walk through one or more folders looking for files with characters in the filename that python can't automatically encode to utf-8
View find-bad-filenames.py
#!/usr/bin/env python
import os
import sys
if len(sys.argv) < 2:
print "Usage: {0} PATH [PATH ...]".format(sys.argv[0])
sys.exit(1)
for folder in sys.argv[1:]:
for root, dirs, files in os.walk(folder):
@dankrause
dankrause / custom-tinycore.sh
Last active Jun 11, 2022
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.
View custom-tinycore.sh
#!/bin/bash
set -e
function cleanup() {
# clean up our temp folder
rm -rf "${TMPDIR}"
}
trap cleanup EXIT
@dankrause
dankrause / fsm.py
Last active Aug 29, 2015
Toy finite state machine implementation in Python
View fsm.py
import itertools
class FSMException(Exception):
pass
class DuplicateRule(FSMException):
pass
class InvalidStateTransition(FSMException):
@dankrause
dankrause / jobclient.py
Last active Aug 29, 2015
An example jobboard client for taskflow
View jobclient.py
#!/usr/bin/env python
"""jobclient.py
Usage:
jobclient.py [options] <jobboard_name> create <name> <details>
jobclient.py [options] <jobboard_name> list
jobclient.py [options] <jobboard_name> delete <uuid>
jobclient.py [options] <jobboard_name> clear
Options:
@dankrause
dankrause / ipc.py
Last active Mar 24, 2022
Simple socket IPC in python
View ipc.py
# 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
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@dankrause
dankrause / event.py
Last active Aug 29, 2015
Toy pub/sub implementation in python
View event.py
from functools import partial
from fnmatch import fnmatchcase
from collections import defaultdict
class Event(dict):
handlers = defaultdict(list)
@classmethod
def subscribe(cls, *args):
if not callable(args[-1]):