Skip to content

Instantly share code, notes, and snippets.

VlanTagOrType = Struct("VlanTagOrType",
Enum(UBInt16("type"),
IPv4 = 0x0800,
ARP = 0x0806,
RARP = 0x8035,
X25 = 0x0805,
IPX = 0x8137,
IPv6 = 0x86DD,
VLAN_TAG = 0x8100,
_default_ = Pass,
@tomerfiliba
tomerfiliba / construct++.cpp
Created February 25, 2014 19:54
Consturct++: Pickler combinators in C++11
#include <iostream>
#include <sstream>
#include <cstdint>
#include <cstddef>
#include <string>
#include <memory>
#include <vector>
#include <tuple>
#include <utility>
#include <type_traits>
@tomerfiliba
tomerfiliba / gist:3698403
Created September 11, 2012 13:20
get the indexes of the top n elements in a numpy 2d-array
import numpy as np
import bottleneck as bn
def top_n_indexes(arr, n):
idx = bn.argpartsort(arr, arr.size-n, axis=None)[-n:]
width = arr.shape[1]
return [divmod(i, width) for i in idx]
np.random.seed(47)
@tomerfiliba
tomerfiliba / __lazy__.py
Created June 16, 2011 22:29
__lazy__ importing
import sys
from types import ModuleType
__path__ = []
LAZY_PREFIX = "__lazy__"
class OnDemandModule(ModuleType):
def __init__(self, name):
ModuleType.__init__(self, name)
object.__setattr__(self, "__module", None)