Author: Dave Lasley

  • NAT Reflection – Ubiquiti EdgeRouter Lite (V>=1.3.0) & Dynamic IP

    NAT Loopback/hairpin/reflection allows internal clients to access internal resources using an external IP/hostname. This is useful when you run a server inside of a local network, and would like to access it using your domain name/external IP. This tutorial will walk you through creating a NAT hairpin for a Ubiquiti EdgeRouter Lite running at least…

  • Determine Which Modules Are In A Package – Python

    Below is a method to enumerate Python modules located in a directory: {{{ lang=python import pkgutil def get_pkg_modules(pkg_path, recurse=False, add_prefix=”): ”’ Get modules of a package located at pkg_path @param str pkg_path Path of package to inspect @param bool recurse Recursive inspection? @param str add_prefix Add this prefix to results @return list List of modules…

  • Mercurial/Trac Changeset Hook

    Below is a Mecurial changegroup hook to modify tickets on a remote Trac instance using XML-RPC. To use it, place the following in your hgrc (make necessary changes in [trac-hook] section). * File: repo/.hg/hgrc {{{ lang=ini [extensions] trac_hg_hook = /path/to/trac_hg_hook.py [hooks] changegroup.sync = python:trac_hg_hook.hook [trac-hook] trac_root = /var/lib/trac api_url = https://trac_user:trac_pass@trac.example.com/xmlrpc repo_name = test python_eggs…

  • Performance Metrics – Apache vs Nginx

    We just deployed [[http://wiki.nginx.org/Main|Nginx]] as a forward proxy for our production server. Before deploying, we took some page load benchmarks so that we could get an idea of what we improved with this change. The benchmarking was a simple python script that opened 100 concurrent threads (3 times to spot outliers) to a list of…

  • Reorder all fields in Trac

    We decided to add a business justification field to our Trac instance today, but needed to put it directly below the description field so that it was in a more logical position for the users. It is not possible to intermingle custom ticket fields with standard ones (from within Trac), so editing the ticket template…

  • Finding The Geometric Mean In Python

    Geometric means are a quick and easy way to benchmark system/interpreter performance. The below function is an example of calculating geometric averages in Python: {{{ lang=python def geometric_mean(nums): ”’ Return the geometric average of nums @param list nums List of nums to avg @return float Geometric avg of nums ”’ return (reduce(lambda x, y: x*y,…

  • Compiling PyPy From Source

    [[http://pypy.org/|PyPy]] is significantly faster when compared against the default [[http://en.wikipedia.org/wiki/CPython|CPython]] interpreter. For the most part, this interpreter functions the same way that CPython does, and most libraries will run with no issues. In my testing, PyPy was 5-10 times faster than CPython and I was able to install/use every library other than [[http://www.riverbankcomputing.com/software/pyqt/download|PyQt4]] and [[http://trac.edgewall.org|Trac]].…

  • OpenVPN Server Configuration Script – Ubiquiti EdgeRouter Lite

    =The lazy way to configure OpenVPN Server on a Ubiquiti EdgeRouter Lite= I have a Ubiquiti EdgeRouter Lite that I use as a staging platform for systems in production. Because I have had to reconfigure the VPN so many times on this device, I created a simple Python tool to run through the entire process…

  • Dynamic DNS Using LibCloud – EdgeRouter

    This tutorial is aimed for users with a dynamic IP, and a DNS host that does not support DynDNS. Basically, we will push our new IP every time that it changes. The steps outlined in this tutorial will work with the providers listed in [[https://ci.apache.org/projects/libcloud/docs/dns/supported_providers.html#provider-matrix|Apache’s documentation]], but I have only actually tested with Rackspace. ===…

  • Fix incorrect client IP for WordPress behind reverse proxy

    If you are running WordPress behind a reverse proxy, you will need to add the below code to the top of `wp-config.php`: {{{ // Alter `REMOTE_ADDR` header to `HTTP_X_FORWARDED_FOR` if it exists. if($_SERVER[‘HTTP_X_FORWARDED_FOR’]) { $xaddr = explode(‘,’,$_SERVER[‘HTTP_X_FORWARDED_FOR’]); $_SERVER[‘REMOTE_ADDR’] = $xaddr[0]; } }}}