Skip to content

Instantly share code, notes, and snippets.

View ties's full-sized avatar

Ties de Kock ties

  • The Netherlands
View GitHub Profile
@ties
ties / gist:1424374
Created December 2, 2011 18:51
pcap/dpkt example that dumps (some) http request headers
#!/usr/bin/env python
import dpkt, pcap, socket
from ipaddr import IPv4Address, IPv6Address
import syslog
class HTTPRequest():
def __init__(self, host, uri, ip = None, user_agent = None):
self.uri = uri
self.user_agent = user_agent
self.host = host
@ties
ties / triangle.py
Created January 27, 2012 19:04
ADC triangle finding exercist
#
# Find triangles in a graph stored as adjacency matrix
#
import itertools
import random
SIZE = 4
# Generate graph in adjacency list format with random edges
# the random edges are sampled from all possible edges, |e| is random up to size
@ties
ties / words.py
Created March 14, 2012 22:21
random passphrase generator
#
# Generate random word list from Linux Dictionary
#
# Based on script seen at CCC talk 4494 <http://ftp.ccc.de/events/camp2011/video/cccamp11-4494-laptop_and_electronics_searches_at_the_us_border-en.mp4> at 25:30
# (c) Electronic Fronteer Foundation (it's from the presentation)
import random, math
d = open('/usr/share/dict/words').readlines()
n = 5
print ' '.join(random.choice(d).rstrip() for i in range(n))
print n * math.log(len(d))/math.log(2), 'bits'
@ties
ties / gist:3123086
Created July 16, 2012 14:41
Flask+AppEngine user decorator
"""
Decorator that retrieves the current user from app engine and sets it on the wrapped function
Usage:
@user
[function definition]
or
@user("userobj")
def func(userobj, bar, baz)
@ties
ties / resolution.py
Created August 9, 2012 12:59
namedtuple + property = elegant
from collections import namedtuple
class Resolution(namedtuple('_Resolution', ['width', 'height'])):
@property
def pixels(self):
return self.width * self.height
@ties
ties / u10465.cpp
Last active December 17, 2015 17:09
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <set>
require 'formula'
class Bob < Formula
homepage ''
url 'https://www.idiap.ch/software/bob/packages/bob-1.1.4.zip'
sha1 'be4385daab4e11af3f91fb09d2d1d54629f1a59c'
# dependencies from <http://www.idiap.ch/software/bob/docs/nightlies/last/bob/sphinx/html/Dependencies.html>
# depends_on 'cmake' => :build
depends_on 'blitz'
#!/usr/bin/python
# based on monitor-bluetooth
# Changes by Domen Puncer <domen@cba.si>
import gobject
import dbus
import dbus.mainloop.glib
import os, subprocess
import re
#!/usr/bin/env python
"""
The libvirt API is much easier than my old kludge based on `virsh list` and sed…
"""
import libvirt
conn = libvirt.open(None)
for id in conn.listDomainsID():
domain = conn.lookupByID(id)
@ties
ties / sample_ssl.conf
Created November 15, 2013 15:11
SSL settings that score high on Qualys ssl check…
ssl_session_cache shared:SSL:10m;
server_name <name>;
ssl on;
ssl_certificate <path to concatenated certificate chain>;
ssl_certificate_key <path to certificate private key>;
ssl_dhparam <path to dh params>;
ssl_session_timeout 5m;