choose a strong password (explained)

The media is packed with articles about hackers that got access to pc’s because they had weak passwords. It seems these problems are huge, most people use Password[0-9] as their password. really smart people even use [email protected]$$w0rd[0-9]:

processing queued netfilter packets with scapy

I found myself in need of writing something that filters packets according to their payload,and it had to be fast.

I wrote a netfilter module that filtered the data so it’ll meet my performance needs, but I was curious if it’s possible to hook nfq to scapy.

A quick query and I found someone who already did it! cool right?

You can write an iptables rule that redirects packets to a specific queue and process it with scapy!

by the way, did you know that iptables is being replaced by the superior nftables?

linux command basics

At my previous workplace I spent 90% of my time writing server side .Net code, on Windows (no mono). At my current workplace I shifted to a linux only environment.

Linux is an old buddy, but It was always a fling, not a serious relationship.

It took me a while to adjust to working on linux every day, and finding out that now the terminal is my best friend, as opposed to GUI in windows.

linux command line basics series really helped me get started: part one, part two.

how to create a local PyPI mirror

PyPI is amazing, but it does have its drawbacks:

  • If PyPI is down, you can’t download any packages or run any tests
  • PyPI can be extremely slow at times
  • PyPI doesn’t offer private package support

The solution? set up a local PyPI mirror of course.

Python already has a PEP that describes the mirroring infrastructure for PyPI: PEP 381, and the tooling that implements it.

I started by looking at my options, and at the end decided to follow these articles to do so:

During my search endeavours, I found out that Artifactory provides support for PyPI repositories. If you already have it installed, I suggest using it instead.

python metaclasses

Ever heard about python metaclasses?

A metaclass is the class of a class. Like a class defines how an instance of the class behaves, a metaclass defines how a class behaves. A class is an instance of a metaclass.

metaclasses make a lot of magic possible. This article describes:

  • What metaclasses are
  • Why they exists
  • How to use them (with code snippets!)
  • Why use them

after reading this you’ll be able to understand the magic behind abstract python classes.

P.S: If you’ve ever missed interfaces in python, zope.interfaces uses ABC’s achieve that. twisted blog has a post about that - Why Interfaces Are Great

'Must' watch python videos

I’m a reddit addict, & regularly follow /r/python.
A few years ago I came across a post called “Must-watch videos about Python”, and I’ve been following pymust.watch ever since.

The list is well balanced, and covers many important topics.
If you feel that a specific topic is missing, send a pull request to the websites GitHub repository.

Overwhelmed by the length of the list? go through my favorites first:

a new look at exception handling

I was taught that good exception handing means:

  • Don’t catch all exceptions -> only catch exceptions you know how to handle
  • If your application needs to raise an exception, create a unique exception and raise it.
  • Never silently ignore exceptions (it’s even part of the zen of python)

I strongly believe in these rules. they, in my opinion, make your code more readable, testable and easier to debug. Anyway, I just read a nice article with nice tips about exception handling.

By the way, I also add the locals (it’s really easy in python) of the exception I just raised. It helped a few times!

Internals of python string interning

String interning is an implementation of the Flyweight design pattern:

In computer programming, flyweight is a software design pattern. A flyweight is an object that minimizes memory usage by sharing as much data as possible with other similar objects; it is a way to use objects in large numbers when a simple repeated representation would use an unacceptable amount of memory. Often some parts of the object state can be shared, and it is common practice to hold them in external data structures and pass them to the flyweight objects temporarily when they are used.

Almost every language has an implementation of string interning and python is no exception.

I just read a The internals of Python string interning and found it very interesting!