Skip to content

Instantly share code, notes, and snippets.

@wujiang
wujiang / tree.md
Created January 3, 2013 19:57 — forked from hrldcpr/tree.md

One-line Tree in Python

Using Python's built-in defaultdict we can easily define a tree data structure:

def tree(): return defaultdict(tree)

That's it!

Using strace and lsof to debug blocked processes

You can use strace on a specific pid to figure out what a specific process is doing, e.g.:

strace -fp <pid>

You might see something like:

select(9, [3 5 8], [], [], {0, 999999}) = 0 (Timeout)

@wujiang
wujiang / archive_old_mails
Created July 15, 2013 22:52
Archive old Maildir type messages
#!/usr/bin/env python
# Archive old Maildir type messages
# Wu Jiang (wu@morediff.info)
import argparse
from datetime import timedelta
import mailbox
import time
@wujiang
wujiang / def.py
Last active December 27, 2015 19:09
A dictionary
#!/usr/bin/env python
import argparse
from wordnik import *
parser = argparse.ArgumentParser()
parser.add_argument("word", help="word to look for")
parser.add_argument("--example", "-i", action="store_true",
@wujiang
wujiang / gist:9507248
Created March 12, 2014 13:47
Surround option words with quotes
;; Surround option words with quotes
;; It's helpful for making javascript work with IE.
;; i.e.:
;;
;; title: {
;; text: "highcharts example"
;; },
;; exporting: {
;; enabled: false
;; },
;;; auto-rsync-mode -- minor mode for auto rsync
;;
;; Author: @l3msh0
;;
;;; Example
;;
;; (require 'auto-rsync)
;; (auto-rsync-mode t)
;; (setq auto-rsync-dir-alist
# $OpenBSD: pf.conf,v 1.54 2014/08/23 05:49:42 deraadt Exp $
#
# See pf.conf(5) and /etc/examples/pf.conf
set skip on lo
block return # block stateless traffic
pass # establish keep-state
# By default, do not permit remote connections to X11
@wujiang
wujiang / gist:87845bafa15cb81b0959
Created January 31, 2016 19:29
openbsd network
(core)~ $ ifconfig -A
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 32768
priority: 0
groups: lo
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x5
inet6 ::1 prefixlen 128
inet 127.0.0.1 netmask 0xff000000
em0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
lladdr 00:0c:29:81:a7:db
priority: 0
@wujiang
wujiang / gist:cdf03b5a2d13af24b8a1
Created February 1, 2016 19:43
openbsd ifconfig
~ $ ifconfig
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 32768
priority: 0
groups: lo
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x3
inet6 ::1 prefixlen 128
inet 127.0.0.1 netmask 0xff000000
em0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
lladdr 00:0c:29:81:a7:db
priority: 0
class mapNode(object):
def __init__(self):
self.num = None
self.e = None
self.w = None
self.n = None
self.s = None
self.lock = None
def main():