Skip to content

Instantly share code, notes, and snippets.

View ssokolow's full-sized avatar

Stephan Sokolow ssokolow

View GitHub Profile
@ssokolow
ssokolow / api_wan_ipaddr4.php
Created July 31, 2010 02:20
Simple "Get WAN IPv4 Address" script for m0n0wall
#!/usr/local/bin/php
<?php
/*
Simple "Get WAN IPv4 Address" script for m0n0wall
Adapted from m0n0wall's status_interfaces.php
See http://blog.ssokolow.com/archives/2010/07/30/a-quick-and-dirty-m0n0wall-get-wan-ip-api/
Copyright (C) 2003-2007 Manuel Kasper <mk@neon1.net>.
All rights reserved.
@ssokolow
ssokolow / gist:509294
Created August 5, 2010 05:29
Relative interval pretty-printer for timestamps
def pretty_date(time=None, utc=False):
"""
Get a datetime object, time tuple, or int/float Epoch timestamp
and return a pretty string like 'an hour ago', 'Yesterday',
'3 months ago', 'just now', etc.
If utc=True, naive date comparisons will assume UTC rather than
the local timezone.
Modified to handle timezone-aware datetime instances, floats, and time tuples
@ssokolow
ssokolow / README.markdown
Created August 13, 2010 06:09
Wordpress WXR to Jekyll exporter

Having decided to move my blog to Jekyll, I went looking for solutions. AzizLight's class proved the simplest, but fell short of what I wanted.

This version has been modified to be runnable as a command-line script (help available via -h) and, aside from category permalink continuity (which I'm working on), produces a ready-to-use _posts directory for your Jekyll blog.

Full details on the changes are available in the git commit log.

@ssokolow
ssokolow / minecraft_backup.py
Created April 25, 2011 08:49
Python port of Tjb0607's Minecraft Backup Script
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Tjb0607's Minecraft Backup Script
Ported to Python and enhanced by ssokolow
Version: 2.1_01+py02
Changes:
- 2.1_01+py02: Add a simple corruption check using the level.dat gzip checksum.
@ssokolow
ssokolow / .Xresources
Created May 1, 2011 15:54
.Xresources settings for more modern XTerm keybindings
! {{{ Quick Reference
!
! Scrolling:
! Scroll Wheel
! Shift-PgUp/PgDn
!
! Copy/Paste:
! Mouse-Select : Copy to PRIMARY
! Shift + Mouse-Select: Copy to CLIPBOARD
!
@ssokolow
ssokolow / gist:950615
Created May 1, 2011 16:17
Hotplug Scripts for LCDProc and G15Daemon
We couldn’t find that file to show.
@ssokolow
ssokolow / creeper.py
Created May 2, 2011 13:37
Gag script for xkcd-reading Minecraft players
# Try typing "import creeper" at the Python prompt.
import os, signal
print "sssssssssssssss..."
os.kill(os.getpid(), signal.SIGSEGV)
@ssokolow
ssokolow / winenv.py
Created June 5, 2011 21:55
Helpers for permanent modifications to the Windows environment
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Helpers for automating the process of setting up ported Linux/UNIX
applications which were designed with expectations like being in $PATH.
@note: Basic functionality requires only the Python standard library.
Some functions and methods also require the PyWin32 package.
@note: A much more verbose "sudo for Windows" implementation (BSD-licensed)
@ssokolow
ssokolow / get_default_gateway_linux.py
Created July 2, 2011 12:15
Snippet for getting the default gateway on Linux
#Snippet for getting the default gateway on Linux
#No dependencies beyond Python stdlib
import socket, struct
def get_default_gateway_linux():
"""Read the default gateway directly from /proc."""
with open("/proc/net/route") as fh:
for line in fh:
fields = line.strip().split()
@ssokolow
ssokolow / upd_ipv6.py
Created July 9, 2011 05:07
IPv6 Updater for HE.net Tunnels, m0n0wall endpoints, and dynamic IPv4 Addresses
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Simple cronscript for updating HE.net when using m0n0wall with a dynamic IP.
Auto-detects the default gateway address on Linux when not given.
Requires:
- Python 2.5+
- LXML (Feel free to patch to use Python stdlib for parsing m0n0wall's output)