Skip to content

Instantly share code, notes, and snippets.

View warvariuc's full-sized avatar

Victor Varvaryuk warvariuc

  • Moldova, Chisinau
View GitHub Profile
#!/usr/bin/env python3
"""
A pure Python "ping" implementation, based on a rewrite by Johannes Meyer,
of a script originally by Matthew Dixon Cowles. Which in turn was derived
from "ping.c", distributed in Linux's netkit. The version this was forked
out of can be found here: https://gist.github.com/pklaus/856268
I've rewritten nearly everything for enhanced performance and readability,
and removed unnecessary functions (assynchroneous PingQuery and related).
# "Understanding Python's closures".
#
# Tested in Python 3.1.2
#
# General points:
#
# 1. Closured lexical environments are stored
# in the property __closure__ of a function
#
# 2. If a function does not use free variables
@warvariuc
warvariuc / prepare-commit-msg
Last active January 25, 2016 16:38
A hook for git that inserts at the beginning of the commit message name of the current branch, if the message is empty (contains empty or comment lines).
#!/usr/bin/env python3
import sys
import subprocess
with open(sys.argv[1], 'r+') as commit_message_file:
commit_message = list(commit_message_file)
for line in commit_message:
line = line.strip()
@warvariuc
warvariuc / gist:5459407
Created April 25, 2013 12:41
Threads SIGINT
#!/usr/bin/env python
import threading
def handleSigint(*args):
print 'Received SIGINT. Notifying worker threads to stop.', args
global shutdown
shutdown = True
shutdown = False