Wednesday, October 31, 2012

BeautifulSoup v4.1.3 patch

Apparently a tag such as the following will break BeautifulSoup when using HTML5lib:

<svg xmlns="" xmlns:xlink="">

  File "/home/external/html5lib/treebuilders/", line 291, in insertElementNormal
    element.attributes = token["data"]
  File "/home/external/bs4/builder/", line 147, in setAttributes
    new_name = NamespacedAttribute(*name)
  File "/home/external/bs4/", line 30, in __new__
    obj = unicode.__new__(cls, prefix + ":" + name)
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

Tuesday, October 23, 2012

Getting HTML5 audio to work on Chrome Ubuntu

Apparently you need to install this code to make HTML5 audio tags play correctly:

sudo apt-get install chromium-codecs-ffmpeg-extra

Wednesday, October 17, 2012

Difference between mock and MagicMock

>>> x = mock.MagicMock(tst='abc')
>>> x[0]

>>> x = mock.Mock(tst='abc')

>>> x[0]
Traceback (most recent call last):
  File "", line 1, in 
TypeError: 'Mock' object does not support indexing

Friday, October 12, 2012

Using iptables and ufw

There are a lot of instructions out there about configuring a VPN server on Ubuntu, but how does it all work?   The basic idea is that once you setup a PPTPD server, you need to configure your iptables rules to allow packets from your ppp interface to your Ethernet.

Some basic commands that you can use for iptables.   There are INPUT, FORWARD, and OUTPUT filters.   The default policy (either ACCEPT or DROP) determine the default action in case there are no rules that matched.

If you want to see how your rules are working, you can add a rule for logging;

iptables -A <INPUT/FORWARD/OUTPUT> -j LOG --log-prefix="INPUT/FORWARD/OUTPUT prefix" --log-level=3

(The -j represents a keyword target 'LOG', and it uses the --log-prefix and --log-level as supplementary commands.)

To replace an existing iptables rule (they are numbered from starting from 1), you can do:
iptables -R INPUT/FORWARD/OUTPUT <rule #> rule>

To insert a rule in the beginning of the chain, you can do:

If you don't want to have a default ACCEPT policy for the FORWARD iptables chain that is mentioned in a lot of PPTPD documentation, you can do:

-A ufw-before-forward -i ppp0 -o eth0 -j ACCEPT
-A ufw-before-forward -i eth0 -o ppp0 -j ACCEPT
Apparently ufw adds some extra iptables rules called ufw-before-input, ufw-before-output, and ufw-before-forward so you can take advantage of those rules.