Skip to content

Instantly share code, notes, and snippets.

# event.py (improved)
class Event(object):
def __init__(self, doc=None):
self.__doc__ = doc
def __get__(self, obj, objtype=None):
if obj is None:
return self
# event.py (simple)
class Event(object):
def __init__(self):
self.handlers = []
def add(self, handler):
self.handlers.append(handler)
return self
#!/usr/bin/env python
"""Sample script which uses event.py (simple). """
import event
class Publisher(object):
def __init__(self):
#!/usr/bin/env python
"""Sample script which uses event.py (improved). """
import event
class Publisher(object):
# Set event object in class declaration.
@emptypage
emptypage / wol.py
Created August 17, 2014 05:09
Send the magic packet of Wake on LAN
#!/usr/bin/env python
import binascii
import socket
PORT_DEFAULT = 9
IPADDR_DEFAULT = '<broadcast>'
_USAGE = """Usage:
python wol.py [options] <MAC address>...
@emptypage
emptypage / redirect-package.py
Last active August 29, 2015 14:15
Create hard links / junctions to the system-installed packages in a given virtualenv ("site-packages") directory.
#!/usr/bin/env python
#
# Create hard links / junctions to the system-installed packages in
# a given virtualenv ("site-packages") directory.
#
#
# Background
# ==========
#
# Some libraries such as wxPython do not support pip installation yet.
@emptypage
emptypage / new.cmd
Created February 15, 2015 00:48
A batch to create new file(s) from templates.
@echo off
setlocal enabledelayedexpansion
set TemplateDir=new-templates
REM # If no args are given, show help (and exit).
if "%1"=="" goto HELP
REM # Options
if /i "%1" == "/?" goto HELP
@emptypage
emptypage / Registry Entries to Customize Keyboard Layout.md
Last active April 6, 2022 03:50
Registry entries to customize keyboard layout

Registry Entries to Customize Keyboard Layout

2015-02-27

Caution: these (.reg) files change a registry entry of your PC and will affect its behavior. You should not apply them unless you understand the consequence.

@emptypage
emptypage / wx-clock.py
Last active August 29, 2015 14:16
A wxPython-based sample clock app.
#!/usr/bin/env python
from __future__ import (absolute_import,
division,
print_function,
unicode_literals)
import math
import time
import wx
@emptypage
emptypage / iterlines_backward.py
Created March 1, 2015 10:34
Iterate lines of the string from its tail to its top.
def iterlines_backword(s):
""" Iterate lines of `s` from its tail to its top.
>>> list(iterlines_backword('a'))
['a']
>>> list(iterlines_backword('a\\n'))
['a\\n']
>>> list(iterlines_backword('a\\nb'))
['b', 'a\\n']