Category: Programming

  • 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/ [hooks] changegroup.sync = python:trac_hg_hook.hook [trac-hook] trac_root = /var/lib/trac api_url = repo_name = test python_eggs […]

  • Performance Metrics – Apache vs Nginx

    We just deployed [[|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

    [[|PyPy]] is significantly faster when compared against the default [[|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 [[|PyQt4]] and [[|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 [[|Apache’s documentation]], but I have only actually tested with Rackspace. === […]

  • Install scipy for python 2.7 in Ubuntu

    Surprisingly the `scipy` package was not as straightforward of an installation as most Python modules; this tutorial will walk you through that process. # The first step is to download `easy_install`, and the libraries required for `scipy` {{{ lang=bash sudo apt-get install python-setuptools liblapack-dev libblas-dev }}} # Use `easy_install` to install `scipy` and other required […]

  • Setup & Use Pymongo

    Install mongodb [[|Red Hat Enterprise, CentOS, or Fedora Linux]] [[|Ubuntu]] [[|Debian]] [[|Generic Linux]] [[|OS X]] [[|Windows]] Install pymongo {{{ lang=sh sudo easy_install pymongo }}} Connect with MongoClient {{{ lang=python import pymongo client = pymongo.MongoClient(‘localhost’, 27017) }}} Get a Database {{{ lang=python db = client.test_db # OR db = client[‘test-db’] }}} Get a Collection {{{ lang=python […]

  • Unix Epoch Programming Reference

    Below is a table indicating how to obtain a Unix Epoch Timestamp from various programming languages: |=Language|=Command| |Actionscript| (new Date()).time | |ASP| DateDiff(“s”, “01/01/1970 00:00:00”, Now()) | |C++| #include std::time(0); | |C#| epoch = (DateTime.Now.ToUniversalTime().Ticks – 621355968000000000) / 10000000; | |Erlang| calendar:datetime_to_gregorian_seconds( calendar:now_to_universal_time( now()) )-719528*24*3600 | |Java| long epoch = System.currentTimeMillis()/1000; | |JavaScript| Math.round(new Date().getTime()/1000.0) getTime() […]