Skip to content

Instantly share code, notes, and snippets.

#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
class MetaA(type):
def __call__(cls, *args, **kwargs):
for name, class in cls.__dict__.iteritems():
if issubclass(class.__class__, B):
# Do something
return # class A with modified fields
class B(object):
....
wlp2s0 IEEE 802.11bgn ESSID:"ASDF"
Mode:Managed Frequency:2.437 GHz Access Point: 123
Bit Rate=54 Mb/s Tx-Power=16 dBm
Retry long limit:7 RTS thr:off Fragment thr:off
Encryption key:off
Power Management:off
Link Quality=57/70 Signal level=-53 dBm
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:28 Missed beacon:0
Description='A wpa_supplicant configuration file based wireless connection'
Interface=wlp2s0
Connection=wireless
Security=wpa-config
WPAConfigFile='/etc/wpa_supplicant/wpa_supplicant.conf'
IP=dhcp
@jakab922
jakab922 / gist:5904427
Created July 1, 2013 20:41
preserve order unique
your_list
unique_d = {}
for i, el in enumerate(your_list):
unique_d.setdefault(el, i)
preserved_order_unique = map(lambda x: x[0], sorted([(key, val) for key, val in unique_d.iteritems()], lambda y: y[1]))
@jakab922
jakab922 / measure_decorator.py
Created September 18, 2013 15:19
Measure decorator and context manager, for measuring execution time. For multiple processes, multiple instances are needed.
class Measure(object):
def __init__(self):
self.__elapsed = None
def __enter__(self):
self.__start = time()
def __exit__(self, *args):
self.__elapsed = time() - self.__start
@jakab922
jakab922 / decla_mock.py
Last active December 23, 2015 17:39
Declarative mock definitions for tests on a Test class.
from unittest import TestCase
from mock import patch
class IDontNeedTheRest(Exception):
pass
DEBUG = False
@jakab922
jakab922 / sys.path.py
Created January 8, 2014 13:24
sys path manipulation
import sys
import os
from os.path import join
from mock import Mock, patch
from twisted.internet import defer
src_path = os.path.realpath(join(os.path.dirname(__file__), "../src/"))
current_path = os.path.realpath(os.path.dirname(__file__))
sys.path.insert(0, current_path)
sys.path.insert(0, src_path)
@jakab922
jakab922 / knight_pos.hs
Last active February 5, 2016 14:40
The in_n function is important which calculates the reachable squares reachable in n steps on the chessboard(quite inefficient though)
import Data.List (nub)
class Monad m => MonadPlus m where
mzero :: m a
mplus :: m a -> m a -> m a
instance MonadPlus [] where
mzero = []
mplus = (++)
from collections import defaultdict
from copy import deepcopy
daphne = defaultdict(set)
rdaphne = {}
maxx = defaultdict(set)
rmaxx = {}
mindy = defaultdict(set)
rmindy = {}