Skip to content

Instantly share code, notes, and snippets.

View samwyse's full-sized avatar

Sam Denton samwyse

  • Dell/EMC
  • St. Louis, MO
View GitHub Profile
@samwyse
samwyse / defer.py
Created October 7, 2020 21:16
Python decorator to emulate Go's defer statement
#! /usr/bin/env python
"""Emulate Go's 'defer' statement.
The defer decorator adds the 'defer' function to the wrapped opject
that will push a callable and its arguments to a stack. The list of
saved calls is executed after the surrounding function returns. Defer
is commonly used to simplify functions that perform various clean-up
actions.
@samwyse
samwyse / FormatFromDictionary.vb
Created August 30, 2017 15:37
Useful VB.net class definitions
Imports Microsoft.VisualBasic
Public Class FormatFromDictionary
Private format As String
Private safe As Boolean
Private rex As System.Text.RegularExpressions.Regex
Sub New(format As String, Optional safe As Boolean = False)
Me.format = format
Me.safe = safe
Me.rex = New System.Text.RegularExpressions.Regex("\{([^,:}]+)([,:][^}]*)?\}")
End Sub