Stuff and Thingshttps://gitlab-pages.jerrykan.com/2013-04-28T00:00:00+10:00Pelican Code Block CSS Classes2013-04-28T00:00:00+10:002013-04-28T00:00:00+10:00John Kristensentag:gitlab-pages.jerrykan.com,2013-04-28:/blog/2013/04/pelican-code-block-css-classes.html<p><a href="http://docs.getpelican.com/">Pelican</a> provides support for generating content from two markup languages -
<a href="">reStructuredText</a> (the default) and <a href="http://daringfireball.net/projects/markdown/">Markdown</a> (if installed). For the most
part both markup languages generate similar output, except when using
<a href="http://pygments.org/">Pygments</a> to generate code blocks with syntax highlighting.</p>
<p>Code blocks generated from reStructuredText will use the CSS class <code>highlight</code>
to …</p><p><a href="http://docs.getpelican.com/">Pelican</a> provides support for generating content from two markup languages -
<a href="">reStructuredText</a> (the default) and <a href="http://daringfireball.net/projects/markdown/">Markdown</a> (if installed). For the most
part both markup languages generate similar output, except when using
<a href="http://pygments.org/">Pygments</a> to generate code blocks with syntax highlighting.</p>
<p>Code blocks generated from reStructuredText will use the CSS class <code>highlight</code>
to handle the syntax highlighting, while Markdown will use the <code>codehilite</code>
class by default. This can cause problems when developing themes for Pelican
users who may be using either reStructuredText or Markdown, or users who choose
to generate content using both markup languages.</p>
<p>Fortunately you can customise how the Markdown processor generates its output
using the <code>MD_EXTENSIONS</code> setting in the <code>pelicanconf.py</code> file. You can
configure the Markdown processor to generate code blocks using the <code>highlight</code>
CSS class by inserting the following entry in you <code>pelicanconf.py</code> file:</p>
<div class="highlight"><pre><span></span><span class="n">MD_EXTENSIONS</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'codehilite(css_class=highlight)'</span><span class="p">]</span>
</pre></div>
<p>More information about pelicanconf.py settings can be found in the Pelican
<a href="http://docs.getpelican.com/en/latest/settings.html#basic-settings">documentation</a>.</p>DRY in Apache HTTP & HTTPS VirtualHosts2013-04-07T00:00:00+11:002013-04-07T00:00:00+11:00John Kristensentag:gitlab-pages.jerrykan.com,2013-04-07:/blog/2013/04/dry-in-apache-http-https-virtualhosts.html<p>On a number of occasions I have needed to make a site available via both HTTP
and HTTPS which can result in creating two almost identical
<code><a href="http://httpd.apache.org/docs/2.2/mod/core.html#virtualhost">VirtualHost</a></code> stanzas. The HTTPS stanza usually ends up being a
copy & paste of the HTTP stanza with the SSL certificate stuff tacked on to …</p><p>On a number of occasions I have needed to make a site available via both HTTP
and HTTPS which can result in creating two almost identical
<code><a href="http://httpd.apache.org/docs/2.2/mod/core.html#virtualhost">VirtualHost</a></code> stanzas. The HTTPS stanza usually ends up being a
copy & paste of the HTTP stanza with the SSL certificate stuff tacked on to the
end. This means you generally end up with a file that is something like the
following:</p>
<div class="highlight"><pre><span></span><span class="c"># file: /etc/apache2/sites-available/site.example.com.conf</span>
<span class="nt"><VirtualHost</span> <span class="s">*:80</span><span class="nt">></span>
<span class="nb">ServerName</span> site.example.com
<span class="nb">ServerAdmin</span> webmaster@example.com
<span class="nb">DocumentRoot</span> <span class="sx">/var/www/site</span>
<span class="nb">ErrorLog</span> <span class="sx">/var/log/apache2/site-error_log</span>
<span class="nb">CustomLog</span> <span class="sx">/var/log/apache2/site-access_log</span> vhost_combined
<span class="c"># ... some rewrite rules, ACLs, etc ...</span>
<span class="nt"></VirtualHost></span>
<span class="nt"><VirtualHost</span> <span class="s">*:443</span><span class="nt">></span>
<span class="nb">ServerName</span> site.example.com
<span class="nb">ServerAdmin</span> webmaster@example.com
<span class="nb">DocumentRoot</span> <span class="sx">/var/www/site</span>
<span class="nb">ErrorLog</span> <span class="sx">/var/log/apache2/site-error_log</span>
<span class="nb">CustomLog</span> <span class="sx">/var/log/apache2/site-access_log</span> vhost_combined
<span class="c"># ... duplicate rewrite rules, ACLs, etc ...</span>
<span class="nb">SSLEngine</span> <span class="k">On</span>
<span class="nb">SSLCertificateFile</span> ssl/crt/wc.example.com.crt
<span class="nb">SSLCertificateKeyFile</span> ssl/key/wc.example.com.key
<span class="nt"></VirtualHost></span>
</pre></div>
<p>This method tends to break the "don't repeat yourself" (DRY) principle and can
lead to inconsistencies if you make a typo, or forget to make changes to both
stanzas. One method I have found to overcome this is to make use of the
<code><a href="http://httpd.apache.org/docs/2.2/mod/core.html#include">Include</a></code> directive.</p>
<p>The first step is to take all of the configuration settings that are common to
both the HTTP and HTTPS stanzas and place them in a new file:</p>
<div class="highlight"><pre><span></span><span class="c"># file: /etc/apache2/sites-include/site.example.com.conf</span>
<span class="nb">ServerName</span> site.example.com
<span class="nb">ServerAdmin</span> webmaster@example.com
<span class="nb">DocumentRoot</span> <span class="sx">/var/www/site</span>
<span class="nb">ErrorLog</span> <span class="sx">/var/log/apache2/site-error_log</span>
<span class="nb">CustomLog</span> <span class="sx">/var/log/apache2/site-access_log</span> vhost_combined
<span class="c"># ... some rewrite rules, ACLs, etc ...</span>
</pre></div>
<p><em>Note: I generally use Debian systems which have the convention of storing
<code>VirtualHost</code> configuration files in <code>/etc/apache2/sites-available</code>, so I like
to keep these common setting files in <code>/etc/apache2/sites-include</code>.</em></p>
<p>You can then <code>Include</code> this common setting file in both of your <code>VirtualHost</code>
stanzas:</p>
<div class="highlight"><pre><span></span><span class="c"># file: /etc/apache2/sites-available/site.example.com.conf</span>
<span class="nt"><VirtualHost</span> <span class="s">*:80</span><span class="nt">></span>
<span class="nb">Include</span> sites-include/site.example.com.conf
<span class="nt"></VirtualHost></span>
<span class="nt"><VirtualHost</span> <span class="s">*:443</span><span class="nt">></span>
<span class="nb">Include</span> sites-include/site.example.com.conf
<span class="nb">SSLEngine</span> <span class="k">On</span>
<span class="nb">SSLCertificateFile</span> ssl/crt/wc.example.com.crt
<span class="nb">SSLCertificateKeyFile</span> ssl/key/wc.example.com.key
<span class="nt"></VirtualHost></span>
</pre></div>
<p>Using this method you only need to make changes in one location
(<code>sites-include/site.example.com.conf</code>) and they will be applied to both HTTP
and HTTPS.</p>
<p>You can also do something similar if you use the same wildcard SSL certificate
in a number of different <code>VirtualHost</code> files. First move the common SSL
settings into a new file:</p>
<div class="highlight"><pre><span></span><span class="c"># file: /etc/apache2/ssl/site.example.com.conf</span>
<span class="nb">SSLEngine</span> <span class="k">On</span>
<span class="nb">SSLCertificateFile</span> ssl/crt/wc.example.com.crt
<span class="nb">SSLCertificateKeyFile</span> ssl/key/wc.example.com.key
</pre></div>
<p>Then <code>Include</code> the SSL settings file in your HTTPS <code>VirtualHost</code> stanza:</p>
<div class="highlight"><pre><span></span><span class="c"># file: /etc/apache2/sites-available/site.example.com.conf</span>
<span class="nt"><VirtualHost</span> <span class="s">*:80</span><span class="nt">></span>
<span class="nb">Include</span> sites-include/site.example.com.conf
<span class="nt"></VirtualHost></span>
<span class="nt"><VirtualHost</span> <span class="s">*:443</span><span class="nt">></span>
<span class="nb">Include</span> sites-include/site.example.com.conf
<span class="nb">Include</span> ssl/wc.example.com.conf
<span class="nt"></VirtualHost></span>
</pre></div>
<p>This can be particularly useful if you have a number of extra SSL settings that
need to be configured.</p>wsgi-liveserver2013-03-22T00:00:00+11:002013-03-22T00:00:00+11:00John Kristensentag:gitlab-pages.jerrykan.com,2013-03-22:/blog/2013/03/wsgi-liveserver.html<p>Following on from my last post, I have now split the <code>LiveServerTestCase</code>
out into its own Python package to make it easier to reuse in other projects. I
have called it wsgi-liveserver and it is the first Python package that I have
released. The package can be downloaded from <a class="reference external" href="https://pypi.python.org/pypi/wsgi-liveserver/">PyPI …</a></p><p>Following on from my last post, I have now split the <code>LiveServerTestCase</code>
out into its own Python package to make it easier to reuse in other projects. I
have called it wsgi-liveserver and it is the first Python package that I have
released. The package can be downloaded from <a class="reference external" href="https://pypi.python.org/pypi/wsgi-liveserver/">PyPI</a>. The code can be found on
<a class="reference external" href="https://github.com/jerrykan/wsgi-liveserver">GitHub</a> and a welcome any feedback.</p>
Testing Bottle Applications with Selenium2013-03-17T00:00:00+11:002013-03-17T00:00:00+11:00John Kristensentag:gitlab-pages.jerrykan.com,2013-03-17:/blog/2013/03/testing-bottle-applications-with-selenium.html<p><a class="reference external" href="http://docs.seleniumhq.org/">Selenium</a> is a really nice framework for testing web application front-ends
by automating actions through a web browser, but it also requires a web server
to be running so that the browser can interact with the web application. Most
other tests usually interact with the code directly, so this requirement …</p><p><a class="reference external" href="http://docs.seleniumhq.org/">Selenium</a> is a really nice framework for testing web application front-ends
by automating actions through a web browser, but it also requires a web server
to be running so that the browser can interact with the web application. Most
other tests usually interact with the code directly, so this requirement can
also lead to a slight problem... how should the web server be started when
running tests?</p>
<p>The simplest way to run a Selenium test is to manually start up a web server
for your application and then run the tests against it, but this can get a bit
tedious after a while (especially if you keep forgetting to start the server).</p>
<p><a class="reference external" href="https://www.djangoproject.com/">Django</a> provides a <a class="reference external" href="https://docs.djangoproject.com/en/1.5/topics/testing/overview/#liveservertestcase"><code>LiveServerTestCase</code></a> which automates starting up a web
server to serve up your Django application, run your Selenium tests, and then
stop the server again. This is a really nice approach, but I wanted to be able
to do something similar when I am not using Django.</p>
<p>Last week I came across the <a class="reference external" href="https://github.com/jarus/flask-testing/">flask-testing</a> framework which <a class="reference external" href="https://github.com/jarus/flask-testing/blob/master/flask_testing/utils.py#L279">provides similar
functionality</a> for <a class="reference external" href="http://flask.pocoo.org/">Flask</a> applications. The flask-testing
<code>LiveServerTestCase</code> is inspired by the Django version, but is much
simpler. Unfortunately it is also a bit specific to Flask applications.</p>
<p>What I really wanted was a something that could be used for any WSGI compliant
web application. So I <a class="reference external" href="https://github.com/jerrykan/bottle-selenium/blob/cd4622d9f0e7f4b5d7994275959bbde4386c6176/tests/liveserver.py">wrote my own</a> which is loosely based on the
flask-testing version. You simply inherit from the <code>LiveServerTestCase</code>
class instead of from <code>unittest.TestCase</code> when creating your test class,
override the <code>create_app()</code> method to return your WSGI application and,
write your tests as normal. When you run your tests it will handle starting and
stopping the web server in the background as required. I have written a very
basic example <a class="reference external" href="http://bottlepy.org/">Bottle</a> application called <a class="reference external" href="https://github.com/jerrykan/bottle-selenium">bottle-selenium</a> to show it in
action.</p>
<p>I originally wrote this to use with Bottle applications, mainly because they
are very simple to work with. My eventual goal is to use this for testing the
development of <a class="reference external" href="http://www.roundup-tracker.org/">Roundup</a> instances, so it should work with any WSGI compliant
web application.</p>
<p><strong>Update (22/03/2012):</strong> The <code>LiveServerTestCase</code> is now <a class="reference external" href="https://gitlab-pages.jerrykan.com/blog/2013/03/wsgi-liveserver.html">available in its own package</a>
called <a class="reference external" href="https://pypi.python.org/pypi/wsgi-liveserver/">wsgi-liveserver</a>.</p>
Testing Exception Messages2013-03-11T00:00:00+11:002013-03-11T00:00:00+11:00John Kristensentag:gitlab-pages.jerrykan.com,2013-03-11:/blog/2013/03/testing-exception-messages.html<p>The Python <a class="reference external" href="http://docs.python.org/2/library/unittest.html"><code>unittest</code></a> module provides support for testing that an exception is
raised using the <a class="reference external" href="http://docs.python.org/2/library/unittest.html#unittest.TestCase.assertRaises"><code>assertRaises()</code></a> method, but sometime we need to also test
that the exception message is what is expected. Python v2.7 introduced the
<code>assertRaisesRegexp()</code> method which can be used to test exception messages
using regular expressions …</p><p>The Python <a class="reference external" href="http://docs.python.org/2/library/unittest.html"><code>unittest</code></a> module provides support for testing that an exception is
raised using the <a class="reference external" href="http://docs.python.org/2/library/unittest.html#unittest.TestCase.assertRaises"><code>assertRaises()</code></a> method, but sometime we need to also test
that the exception message is what is expected. Python v2.7 introduced the
<code>assertRaisesRegexp()</code> method which can be used to test exception messages
using regular expressions, but if you are stuck with v2.6 or earlier you will
need to do something like:</p>
<div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">unittest</span>
<span class="k">def</span> <span class="nf">raise_exception</span><span class="p">(</span><span class="n">yup</span><span class="o">=</span><span class="bp">True</span><span class="p">):</span>
<span class="k">if</span> <span class="n">yup</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">'Yup, exception raised.'</span><span class="p">)</span>
<span class="k">class</span> <span class="nc">BasicExceptionTest</span><span class="p">(</span><span class="n">unittest</span><span class="o">.</span><span class="n">TestCase</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">test_message</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">raise_exception</span><span class="p">(</span><span class="bp">True</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">fail</span><span class="p">()</span>
<span class="k">except</span> <span class="ne">ValueError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">assertEqual</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">),</span> <span class="s1">'Yup, exception raised.'</span><span class="p">)</span>
<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s1">'__main__'</span><span class="p">:</span>
<span class="n">unittest</span><span class="o">.</span><span class="n">main</span><span class="p">(</span><span class="n">verbosity</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
</pre></div>
<p>Looking at <code>test_message()</code> we first wrap the function we are testing
(<code>raise_exception()</code>) in a <code>try</code> ... <code>except</code> statement to
catch any exception that may be raised. If no exception is raised then we call
<code>fail()</code> to signal that the test has failed. If the correct exception has
been raised (in this case <code>ValueError</code>) we use <code>assertEqual()</code> to
test that the exception message is correct. If an exception that we were not
expecting is raised, then it will be handled by the <code>TestCase</code> class and
the test will be marked as having an error. With this simple test pattern every
possible outcome should be handled correctly.</p>
<p>If you plan to be writing a lot of these sorts of tests, then it may be worth
creating your own <code>TestCase</code> class that provides an assert method for
testing exception messages:</p>
<div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">unittest</span>
<span class="k">def</span> <span class="nf">raise_exception</span><span class="p">(</span><span class="n">yup</span><span class="o">=</span><span class="bp">True</span><span class="p">):</span>
<span class="k">if</span> <span class="n">yup</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">'Yup, exception raised.'</span><span class="p">)</span>
<span class="k">class</span> <span class="nc">ExceptionMessageTestCase</span><span class="p">(</span><span class="n">unittest</span><span class="o">.</span><span class="n">TestCase</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">assertRaisesMessage</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">exception</span><span class="p">,</span> <span class="n">msg</span><span class="p">,</span> <span class="n">func</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">func</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">fail</span><span class="p">()</span>
<span class="k">except</span> <span class="n">exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">assertEqual</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">),</span> <span class="n">msg</span><span class="p">)</span>
<span class="k">class</span> <span class="nc">MessageExceptionTest</span><span class="p">(</span><span class="n">ExceptionMessageTestCase</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">test_message</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">assertRaisesMessage</span><span class="p">(</span><span class="ne">ValueError</span><span class="p">,</span> <span class="s1">'Yup, exception raised.'</span><span class="p">,</span>
<span class="n">raise_exception</span><span class="p">,</span> <span class="bp">True</span><span class="p">)</span>
<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s1">'__main__'</span><span class="p">:</span>
<span class="n">unittest</span><span class="o">.</span><span class="n">main</span><span class="p">(</span><span class="n">verbosity</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
</pre></div>
<p>The <code>assertRaisesMessage()</code> method is very similar to the
<a class="reference external" href="http://docs.python.org/2/library/unittest.html#unittest.TestCase.assertRaises"><code>assertRaises()</code></a> method except that it also takes a <code>msg</code> argument that
will be used to compare against the exception message.</p>
<p>Both of these test patterns could also be extended to include the ability to
use regular expression to test messages (similar to <a class="reference external" href="http://docs.python.org/2/library/unittest.html#unittest.TestCase.assertRaisesRegexp"><code>assertRaisesRegexp()</code></a>),
but I generally find that simple string comparisons are usually enough for my
needs.</p>
Dict Diff and Test Driven Development2013-03-03T00:00:00+11:002013-03-03T00:00:00+11:00John Kristensentag:gitlab-pages.jerrykan.com,2013-03-03:/blog/2013/03/dict-diff-and-test-driven-development.html<p>I recently wrote a short function called <code>dict_diff()</code> that would take
two dicts, compare them, and return another two dicts that contain only the
differences between the original dicts (the code is available as a <a class="reference external" href="https://gist.github.com/jerrykan/5054298">gist</a>). It
works something like:</p>
<div class="highlight"><pre><span></span><span class="n">dict_diff</span><span class="p">(</span>
<span class="p">{</span><span class="s1">'a'</span><span class="p">:</span> <span class="p">{</span><span class="s1">'ab'</span><span class="p">:</span> <span class="mi">12</span><span class="p">},</span> <span class="s1">'b'</span><span class="p">:</span> <span class="p">{</span><span class="s1">'ba'</span><span class="p">:</span> <span class="mi">21</span><span class="p">,</span> <span class="s1">'bb'</span><span class="p">:</span> <span class="mi">22</span><span class="p">},</span> <span class="s1">'c …</span></pre></div><p>I recently wrote a short function called <code>dict_diff()</code> that would take
two dicts, compare them, and return another two dicts that contain only the
differences between the original dicts (the code is available as a <a class="reference external" href="https://gist.github.com/jerrykan/5054298">gist</a>). It
works something like:</p>
<div class="highlight"><pre><span></span><span class="n">dict_diff</span><span class="p">(</span>
<span class="p">{</span><span class="s1">'a'</span><span class="p">:</span> <span class="p">{</span><span class="s1">'ab'</span><span class="p">:</span> <span class="mi">12</span><span class="p">},</span> <span class="s1">'b'</span><span class="p">:</span> <span class="p">{</span><span class="s1">'ba'</span><span class="p">:</span> <span class="mi">21</span><span class="p">,</span> <span class="s1">'bb'</span><span class="p">:</span> <span class="mi">22</span><span class="p">},</span> <span class="s1">'c'</span><span class="p">:</span> <span class="p">{</span><span class="s1">'cc'</span><span class="p">:</span> <span class="mi">33</span><span class="p">}},</span>
<span class="p">{</span><span class="s1">'a'</span><span class="p">:</span> <span class="p">{},</span> <span class="s1">'b'</span><span class="p">:</span> <span class="p">{</span><span class="s1">'ba'</span><span class="p">:</span> <span class="mi">21</span><span class="p">,</span> <span class="s1">'bc'</span><span class="p">:</span> <span class="mi">23</span><span class="p">},</span> <span class="s1">'c'</span><span class="p">:</span> <span class="p">{</span><span class="s1">'cc'</span><span class="p">:</span> <span class="mi">33</span><span class="p">}},</span>
<span class="p">)</span>
<span class="c1"># outputs: (</span>
<span class="c1"># {'a': {'ab': 12}, 'b': {'bb': 22}},</span>
<span class="c1"># {'b': {'bc': 23}}</span>
<span class="c1"># )</span>
</pre></div>
<p>I wrote it to make the output of <a class="reference external" href="http://docs.python.org/2/library/unittest.html#unittest.TestCase.assertEqual"><code>assertEqual()</code></a> a lot easier to read
when dealing with large dicts that are not equal. It is a recursive function,
but other than that it is fairly simple and nothing very special. What is
different is that I wrote the function using <a class="reference external" href="http://en.wikipedia.org/wiki/Test_driven_development">test-driven development</a> (TDD).</p>
<p>Generally when writing recursive functions I tend to get a bit caught up trying
to ensure that the recursive part of the function works correctly from the
beginning and lose sight of what the function is actually supposed to be doing.
By knowing what the expected output would be ahead of time I was able to take a
test-driven development approach and write the test cases beforehand, then just
work my way through making all of the tests pass. By starting with the simple
tests first and working my way through to the more complex ones it meant
everything just fell into place and I didn't have to worry if I broke anything
when I introduced the recursive stuff.</p>
<p>In the past I have tended to just write the tests in tandem with the code
(sometimes before, sometimes after) and not really put a lot of thought into
planning it all out with test cases. Being a simple function I knew what most
of the results should be ahead of time without having to put much thought into
it, but it was valuable to see how well this approach worked. I think I'll try
to spend more time planning out my test cases to drive my development in the
future.</p>
New Blog2013-02-24T00:00:00+11:002013-02-24T00:00:00+11:00John Kristensentag:gitlab-pages.jerrykan.com,2013-02-24:/blog/2013/02/new-blog.html<p>I have finally set up my new blog after many months of thinking about doing it.</p>
<p>Ever since I first heard about using static site generators for blogs the idea
appealed to me. By their nature the content of blogs do not need to be
generated dynamically so using static …</p><p>I have finally set up my new blog after many months of thinking about doing it.</p>
<p>Ever since I first heard about using static site generators for blogs the idea
appealed to me. By their nature the content of blogs do not need to be
generated dynamically so using static html pages means a lower resource
overhead than using something with a database backend. Another bonus is that I
no longer have to worry about keeping on top of the upgrade/patch cycle to fix
security issues that comes with using something like <a class="reference external" href="http://wordpress.org/">Wordpress</a>.</p>
<p>I was mainly looking for a static site generator written in Python so that if I
ever wanted to make any modifications, I would be working with a programming
language I enjoy. The two main ones I came across that were actively being
developed (with releases) were <a class="reference external" href="http://nikola.ralsina.com.ar/">Nikola</a> and <a class="reference external" href="http://blog.getpelican.com/">Pelican</a>. I eventually chose Pelican
over Nikola because all of its dependencies were pure python libraries, making
it easier to set up in a <a class="reference external" href="http://www.virtualenv.org/">virtualenv</a>.</p>
<p>I have also been meaning to have a play with <a class="reference external" href="http://twitter.github.com/bootstrap/">Bootstrap</a> for a very long time,
so I took the opportunity to play around with it over the last few days and
have come up with a simple Pelican theme called <a class="reference external" href="https://github.com/jerrykan/bootstrap-jerrykan">bootstrap-jerrykan</a>. I am
pretty happy with the result.</p>
<p>So, here is my new blog.</p>
Environment Variables of a Running Process2012-12-03T00:00:00+11:002012-12-03T00:00:00+11:00John Kristensentag:gitlab-pages.jerrykan.com,2012-12-03:/blog/2012/12/environment-variables-of-a-running-process.html<p>When creating init scripts or trying to debug services on Linux it can be handy
to know what the environment variables are for a running process. It turns out
that you can retrieve these variables from <code>/proc</code> (along with lots of
other rather useful information). The environment variables are located …</p><p>When creating init scripts or trying to debug services on Linux it can be handy
to know what the environment variables are for a running process. It turns out
that you can retrieve these variables from <code>/proc</code> (along with lots of
other rather useful information). The environment variables are located in
<code>/proc/$PID/environ</code> where <code>$PID</code> is the ID of the process we are
interested in.</p>
<p><code>cat</code> can be used to print out the environment variables, but the entries
are separated by null characters which makes them a bit difficult to read. To
view the entries in a slightly more legible form we can pipe the output through
<code>tr</code> to replace the null characters with new line characters:</p>
<div class="highlight"><pre><span></span>cat /proc/<span class="nv">$PID</span>/environ <span class="p">|</span> tr <span class="s1">'\000'</span> <span class="s1">'\n'</span>
</pre></div>
<hr class="docutils" />
<p>References:</p>
<blockquote>
<ul class="simple">
<li><code>man proc</code></li>
<li>Server Fault: <a class="reference external" href="http://serverfault.com/questions/66363/environment-variables-of-a-running-process-on-unix">Environment variables of a running process on Unix?</a></li>
</ul>
</blockquote>