Category: Python

  • Adding HTML Emails To Trac 1.0.1

    [[[TOC]]] ——- =Intro= Below is a patch to add HTML Emails to Trac and below that is a sample template to generate a nice looking email. The completed file can be located [[file:notification.zip|Here]] and should be placed in `trac/ticket/notification.py`. This patch has been tested with [[http://trac.edgewall.org/|Trac 1.0.1dev-r11400]]. Because we will be mucking with Trac’s source,…

  • Setup Trac w/ multiple projects, mod_wsgi, LDAP & MySQL – Ubuntu 12.10

    [[[TOC]]] —– = Installation = {{{ sudo apt-get install -y apache2 libapache2-mod-python python-setuptools python-genshi mysql-server python-mysqldb easy_install a2enmod #< Base Packages sudo apt-get install -y libapache2-mod-wsgi #< WSGI support sudo apt-get install -y subversion #< Subversion (not covering the config) sudo easy_install trac #< Trac }}} ------------ = Prep MySQL = * Log in {{{…

  • Round To Nearest X

    Sometimes it is necessary to round a number to the nearest X (.1,5,10, etc). Below is some code to do that: ==PHP== {{{ lang=php line=1 # Round int to nearest $round_to function round_int($n, $round_to=10){ return round($n / $round_to) * $round_to; } # Round float to nearest $round_to, configurable rounding down function round_float($n, $round_to = .1,…

  • Median and Quartiles – Python

    [[[TOC]]] ———- = Median = {{{ lang=python line=1 import math nums = [5, 9, 10, 11, 22, 1, 0, -1] #< Fill list with values nums.sort() #< Sort the list in ascending order try: mid_num = ( len( nums ) - 1) / 2 median = nums[ mid_num ] except TypeError: #< There were an…

  • Generic Worker Thread – PyQT

    Below is a generic threading worker in PyQT: {{{ lang=python lines=1 from PyQt4 import QtGui, QtCore import logging class worker_thread(QtCore.QThread): ## Generic worker thread finished = QtCore.pyqtSignal(dict) #< Replace this for data type that will be returned def __init__(self, ret_function, function, *args, **kwargs): ## Init # @param Function ret_function Function to run on end #…