May 252012
 

I can’t believe it’s taken me this long to learn this: Python’s default argument values are only evaluated once during runtime. I’ve never encountered this before because I don’t use default arguments very often, and when I do, it’s often to set something to a static value.

Today, I encountered a function definition where I wanted to default an argument to the current date/time:

Every time I ran the function, the value of date_time was the same: Whatever the date/time was when the method first ran. So, instead, I did something like this:

This is actually mentioned in the Python documentation.

May 252012
 

Install Visual Studio 2008 SP1 Express Edition.

Go to the command prompt.

First, I had to set the following variable:

Note the trailing backslash – that needs to be there. The value must also NOT be in quotes.

Then, from your PyCrypto directory, run:

And it should install with no problem.

May 032012
 

Because Python isn’t strongly typed, sometimes PyDev doesn’t know what type a variable is – and therefore it cannot give you accurate code completions. Here’s how to make that better.

In simpler situations, PyDev works very well. For example:

Typing ’emp.’ will get you a good autocomplete.

Now, let’s say you have something like this:

Then ’emp.’ won’t get you anything – PyDev doesn’t necessarily know what type is being returned.

If you use python’s assert method:

PyDev now knows what type the variable is, and you’ll get more effective code completions.

When running in production, you can pass the “-O” flag to the interpreter, and it will ignore the assert statements.

Nov 182011
 

I needed to return all the members of an object as an XML document in Python. I used the ElementTree library to do this.

The class in question is pretty basic: It has a constructor, member variables, getters and setters for the member variables, and now this new function.

Every Python class has a built-in __dict__ member, which is a dictionary ({}) of key/value pairs for all of the member variables, so I use that to get all of the variables to add to the ElementTree.

This function returns an xml.etree.ElementTree.Element object, which can be turned into a string if needed by using ElementTree’s tostring() method.

Nov 162011
 

Often times, in your Squid proxy, you may have a redirector configured – such as SquidGuard:

I ran into a problem tonight with my Roku box where SquidGuard was seeing Roku’s NetFlix access as a security threat.  So, to make Squid bypass the redirector, add an ACL and a redirector-access rule:

There you have it – any requests to *.netflix.com will skip the redirector.

Nov 062011
 

By default, Squid sends HTTP headers on every request that can give away information about your internal network. Here’s an example of these headers:

That’s three pieces of information you may not want to give away: The host name of your proxy server, the version of Squid it’s running, and the IP address of the system that’s making the request via the proxy.

Fortunately, it’s simple (and does not apparently violate any standards) to make these headers more anonymous – just use these configuration directives in your squid.conf:

That will change the headers to look more like this:

Oct 282011
 

Apparently, it’s necessary to use separate CSS properties for each browser.

Sep 072011
 

If you have a switch, access point or other piece of network hardware that supports 802.1q VLAN tagging, and you’d like to your FreeBSD system to recognize them, it’s a pretty straight-forward configuration.  I’ll use examples from my network to illustrate.  My goal in this case, which I may write about in a separate post, was to create two segmented wifi networks – one for my main network and one for guests to connect to.  I wanted the guest network to have access to the internet, but not to any of my other systems on the network.

Continue reading »

Mar 012010
 

I spent some time thinking about backup strategy, and I decided for my purposes, I’d like to handle the staging process (getting all the files put together), and I’d like the backup solution itself to simply upload the files – but since I want to do nightly backups, I’d like the backup solution to have incremental capabilities.

I narrowed it down to two possible solutions – Tarsnap and Duplicity.  Both support incremental backups, both are command-line capable.  I decided to use Duplicity because it uploads directly to whichever back-end service you use – be it Amazon S3 or an SFTP server .  Tarsnap uses S3, but that’s your only option, and they do some processing for you, and because of that, it costs more.

Now, on to the details.

Continue reading »