Skip to content

Instantly share code, notes, and snippets.

@zhester
zhester / pf.conf
Created January 2, 2016 21:02
PF Minimal NAT
extif="eth0"
set skip on lo
set block-policy drop
no rdr on { lo0 } from any to any
nat on $extif from ! ($extif) to any -> ($extif)
@zhester
zhester / utf8out.py
Created March 10, 2015 14:05
Python boilerplate to encode strings sent to stdout as UTF-8
# write UTF-8 to stdout
if sys.stdout.encoding != 'UTF-8':
import codecs
writer = codecs.getwriter( 'UTF-8' )
sys.stdout = writer( sys.stdout )
@zhester
zhester / protected_iterator.py
Created January 29, 2015 14:55
Provides object iteration that filters out self-proclaimed "protected" attributes.
#=============================================================================
class protected_iterator( object ):
"""
Provides object iteration that filters out self-proclaimed "protected"
attributes.
"""
#=========================================================================
def __init__( self, obj ):
"""
@zhester
zhester / colors.csh
Last active February 4, 2016 13:15
Display foreground colors as sent by the shell.
#!/usr/bin/csh
#============================================================================
#
# Shell Console Color Previewer
#
# Prints out all the console colors using the shell ([t]csh).
#
# The color code mappings are based on these definitions:
#
# 0 | reset colors to 37;40
@zhester
zhester / is_sequence.py
Created August 25, 2014 19:47
Determine if any object is a sequence.
#=============================================================================
def is_sequence( subject ):
"""
Determines if any object/variable/whatever is a sequence.
"""
# assume the subject is not a sequence
result = False
# attempt to extract the iterable representation
@zhester
zhester / range.sh
Created August 18, 2014 16:34
Copy a range of lines from a source file into another file.
#!/usr/bin/sh
#############################################################################
#
# Copy a range of lines from a source file into another file.
#
# Usage:
# range.sh <input> <first row> <last row> [<output>]
#
#############################################################################
@zhester
zhester / get_dlist.php
Created August 13, 2014 16:17
Another directory listing function that uses a regular expression as a filter.
/**
* Returns a list of all file nodes for a given path.
*
* @param path The path for which to build a list of file node entries.
* @param pattern Optional filter pattern to test each node name against.
* The default pattern prevents returning hidden node entries.
* @return A list of node entries in the given path.
*/
function get_dlist( $path, $pattern = '/^[^.]/' ) {
$nodes = [];
@zhester
zhester / main.c
Created June 15, 2014 14:32
Example of a poor-man's WinMain-to-main entry point adapter.
/*=========================================================================*/
int WINAPI WinMain( //Windows program entry point
HINSTANCE hInstance, //handle to this application
HINSTANCE hPrevInstance,
//handle to previous application
LPTSTR lpCmdLine, //executed command
int nCmdShow //window display options
) { //program exit status
//local variables
@zhester
zhester / wxplot.py
Created May 28, 2014 14:15
Experimental matplotlib plotting within wxPython.
#*******************************************************************************
# wxplot.py
# Zac Hester <zac.hester@gmail.com>
# 2012-08-10
#
# Experimental numpy/matplotlib plotting within wxPython.
#
#*******************************************************************************
#-------------------------------------------------------------------------------
@zhester
zhester / titlecase.pl
Created May 19, 2014 16:57
Title Casing a Phrase
# A simple attempt at faking title case on a phrase.
sub titlecase {
$_ = shift;
my @words = split( / / );
my @twords;
foreach ( @words ) {
$_ = lc( $_ );
$_ = ucfirst( $_ );
push( @twords, $_ );
}