Skip to content

Instantly share code, notes, and snippets.

@hastern
hastern / tiled_renderer.py
Last active May 15, 2021 13:49
Quick and Dirty Renderer for TILED JSON maps
#!/usr/bin/env python
import argparse
import json
import pathlib
from PIL import Image
if __name__ == "__main__":
@hastern
hastern / markovscroll.py
Created August 20, 2019 17:06
Markov Chain for image generation
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import json
import itertools
import collections
import random
import pathlib
from PIL import Image
@hastern
hastern / backup.bat
Created January 27, 2017 16:26
batch script to backup data using restic
@echo off
Setlocal EnableDelayedExpansion
IF [%RESTIC_REPOSITORY%] == [] GOTO missingrepo
IF [%RESTIC_PASSWORD%] == [] GOTO missingpass
IF NOT EXIST %RESTIC_REPOSITORY% GOTO invalidrepo
REM Expect restic to be in the system path
SET RESTIC_PATH=restic
@hastern
hastern / aoc_day2.lua
Created December 2, 2016 21:24
Advent of Code - Day 2 - Design to be used with Shenzhen IO
-- This is a custom design based on the Advent of Code Day 2
--
-- You can put your own input into the design by changing parts of
-- the code below.
-- Currently it is not possible to solve both parts at once.
function get_name()
return "AoC-Day 2-Bathroom Security"
end
@hastern
hastern / sexpr.py
Created September 26, 2015 11:17
Simple S-Expression parsing with pyparsing
import pyparsing as pp
LP = pp.Literal("(").suppress()
RP = pp.Literal(")").suppress()
String = pp.Word(pp.alphanums + '_')
SingleQuoteString = pp.QuotedString(quoteChar="'", unquoteResults=False)
DoubleQuoteString = pp.QuotedString(quoteChar='"', unquoteResults=False)
QuotedString = SingleQuoteString | DoubleQuoteString
Atom = String | QuotedString
@hastern
hastern / configloader.py
Last active October 3, 2015 16:07
A simple dictionary based config loader using either json oder yaml as storage format
#!/usr/bin/env python
# -*- coding:utf-8 -*-
#
# A simple dictionary based configuration loader
#
# -------------
# Usage example
# -------------
#
# from configloader import Configuration
@hastern
hastern / keybase.md
Last active August 29, 2015 14:06
Keybase Verification

Keybase proof

I hereby claim:

  • I am hastern on github.
  • I am hannosternberg (https://keybase.io/hannosternberg) on keybase.
  • I have a public key whose fingerprint is 4F04 BA51 330C F378 12C9 C2B7 85D2 50F6 D86F F5CD

To claim this, I am signing this object:

@hastern
hastern / vector.py
Last active August 29, 2015 13:57
A vector class with overloaded operators.
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import sys
import math
import operator
import itertools
def pad(iterable, padding=0):
for itm in itertools.chain(iterable, itertools.cycle([padding])):
/* Some list helper functions */
elementOrVal (l, idx, v) := block(
[res],
if length(l) >= idx and idx > 0 then
res: l[idx]
else
res: v,
res
);
@hastern
hastern / wxUtilityDialog.py
Last active December 23, 2015 16:39
Some utility functions for wxPython dialogs.
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import os
import wx
def messageDialog(message, caption=wx.MessageBoxCaptionStr, style=wx.OK | wx.ICON_INFORMATION):
"""Utility method to create a generic message dialog"""
dial = wx.MessageDialog(None, message, caption, style)
return dial.ShowModal()