<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Pragmatic Coder - Richard Nichols - RSS Feed</title>
    <link>http://www.richardnichols.net/</link>
    <description>Latest posts from http://www.richardnichols.net/</description>
    <item>
      <title><![CDATA[Use tcpdump to capture web traffic for debugging]]></title>
      <link>http://www.richardnichols.net/2015/02/use-tcpdump-to-capture-web-traffic-for-debugging/</link>
      <description><![CDATA[<p>Note to self type post - <code>tcpdump</code> can be used for watching raw HTTP traffic on pretty much any linux host in realtime, which is really handy.</p>

<p>e.g.</p>

<pre><code>sudo tcpdump -A -i eth0 port 80
</code></pre>

<p>The <code>-A</code> option says to print in ASCII, the rest is pretty obvious.</p>
]]></description>
      <pubDate>2015-02-10T03:55:14.81Z</pubDate>
      <guid>http://www.richardnichols.net/2015/02/use-tcpdump-to-capture-web-traffic-for-debugging/</guid>
      <dc:date>2015-02-10T03:55:14.81Z</dc:date>
    </item>
    <item>
      <title><![CDATA[Useful shell scripts: nightly postgresql backup]]></title>
      <link>http://www.richardnichols.net/2015/01/useful-shell-scripts-nightly-postgresql-backup/</link>
      <description><![CDATA[<p>Here's a shell script which does a daily backup of a postgresql database and keeps a weeks worth of backups locally.</p>

<p>You can then rsync this folder over ssh from another server or something like that.</p>

<h3>backupdb.sh</h3>

<p>Run with <code>./backupdb.sh [databasename]</code> - assuming you have access to the database from your user account.</p>

<pre><code>#!/bin/bash
pg_dump -Fc $1 &gt; /var/lib/pgsql/9.3/backups/$1_$(date +"%Y-%m-%d").dump
find /var/lib/pgsql/9.3/backups/* -mtime +7 -exec rm {} \;
</code></pre>

<p>This is a custom format archive which you can use multi-job concurrency to restore in parallel (useful for big databases), e.g.</p>

<pre><code>pg_restore -d myrestoredb -j 8 mydb_2015-01-01.dump
</code></pre>

<p>Would restore the dump into <code>myrestoredb</code> with 8 concurrent processors.</p>
]]></description>
      <pubDate>2015-01-11T23:11:16.17Z</pubDate>
      <guid>http://www.richardnichols.net/2015/01/useful-shell-scripts-nightly-postgresql-backup/</guid>
      <dc:date>2015-01-11T23:11:16.17Z</dc:date>
    </item>
    <item>
      <title><![CDATA[Fixing the Home/End Key Behaviour on Mac OSX]]></title>
      <link>http://www.richardnichols.net/2014/04/fixing-the-homeend-key-behaviour-on-mac-osx/</link>
      <description><![CDATA[<p>Something that always drives me mad when using OS-X is the way keyboard bindings for basic text editing are different to Windows/Linux PCs. For a developer this can reduce your productive by a huge margin and adapting when you have to switch frequently (which I have to at the moment), can be a mental hurdle that's hard to manage each time.</p>

<p>Fortunately I found an nice OSS app that mostly solves the problem - <a href="http://doublecommand.sourceforge.net/">Double Command</a></p>

<p>This app lives in the System Settings and let's you click a few checkboxes to remap the home/end keys, the command key (yay Ctrl+C / Ctrl+V for cut and paste!)</p>

<p>Yay!</p>
]]></description>
      <pubDate>2014-04-30T07:05:18.09Z</pubDate>
      <guid>http://www.richardnichols.net/2014/04/fixing-the-homeend-key-behaviour-on-mac-osx/</guid>
      <dc:date>2014-04-30T07:05:18.09Z</dc:date>
    </item>
    <item>
      <title><![CDATA[Setting Up iptables for SSH/HTTP/HTTPS for new server install]]></title>
      <link>http://www.richardnichols.net/2014/04/setting-up-iptables-for-sshhttphttps-for-new-server-install/</link>
      <description><![CDATA[<p>Whenever I set up a new cloud server I have to lookup the commands to set up iptables correctly for the three sevices I almost always have switched on - SSH, HTTP, HTTPS. So here's a script for later reference!</p>

<pre><code>iptables -F
iptables -I INPUT 1 -i lo -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
iptables -A INPUT -j DROP
</code></pre>

<p>Also a basic port 8080 reverse proxy setup for HTTP/HTTPS on <strong>nginx</strong> is handy too...</p>

<pre><code>upstream app {
    #ip_hash;
    server localhost:8080;
}

server {
    listen 80;
    #rewrite ^(.*) https://$host$1 permanent;
    location / {
        proxy_pass http://app;
        proxy_redirect http:// https://;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
 }

server {

    listen 443;
    ssl on;
    ssl_certificate      /etc/nginx/myssl.crt;
    ssl_certificate_key  /etc/nginx/myssl.key;
    server_name  localhost;

    location / {
        proxy_pass http://app;
        proxy_redirect http:// https://;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
}
</code></pre>
]]></description>
      <pubDate>2014-04-07T06:09:40.20Z</pubDate>
      <guid>http://www.richardnichols.net/2014/04/setting-up-iptables-for-sshhttphttps-for-new-server-install/</guid>
      <dc:date>2014-04-07T06:09:40.20Z</dc:date>
    </item>
    <item>
      <title><![CDATA[Creating and importing an external certificate to SQL Server]]></title>
      <link>http://www.richardnichols.net/2014/03/creating-and-importing-an-external-certificate-to-sql-server/</link>
      <description><![CDATA[<p>This was kind of a pain to get working, so I'm logging the steps here. Certificates can be used in SQL Server to authenticate remote communication (e.g. for mirroring).</p>

<p>Most resources show you how to create certificates for this directly in SQL Server, but for the purpose of being able to manage configuration externally, I think it's better to be able to generate an x509 certificate using normal tools (e.g. OpenSSL) and import that into SQL Server.</p>

<p>There's two bits of information on this that are not very well publicised - </p>

<ul>
<li>The certificate itself must be in DER binary format to import correctly.</li>
<li>The private key must be in Microsoft's proprietary "PVK" format.</li>
</ul>

<p>If these requirements aren't met, then a you will get a cryptic:</p>

<pre><code>Msg 15468, Level 16, State 6, Line 1
An error occurred during the generation of the certificate.
</code></pre>

<p>To generate the proprietary PVK file from a regular RSA private key generated in OpenSSL a <a href="http://www.drh-consultancy.demon.co.uk/pvk.html">3rd party utility is required</a></p>

<p>For this example, we'll generate a key and self-signed certificate using OpenSSL and convert it to the correct format for SQL Server, and import the certificate.</p>

<ol>
<li><p>Generate 2048 bit RSA key</p>

<p><code>openssl genrsa -des3 -out sql.key 2048</code></p></li>
<li><p>Generate certificate signing request</p>

<p><code>openssl req -new -key sql.key -out sql.csr</code></p></li>
<li><p>Sign key with itself for 20 years (!)</p>

<p><code>openssl x509 -req -in sql.csr -days 7300 -signkey sql.key -out sql.pem</code></p></li>
<li><p>Convert to binary DER in sql.cer</p>

<p><code>openssl x509 -in sql.pem -inform PEM -out sql.cer -outform DER</code></p></li>
<li><p>Use pvk utility from above to convert to Microsoft format</p>

<p><code>pvk -in sql.key -out sql.pvk -topvk</code></p></li>
<li><p>Now in SQL Server:</p></li>
</ol>

<pre><code>create certificate mysqlcert
      from file = 'c:\temp\sql.crt'
      with private key 
        (file = 'c:\temp\sql.pvk', 
         encryption by password = 'password entered during key generation', 
         decryption by password = 'password entered in step above')
</code></pre>
]]></description>
      <pubDate>2014-03-04T03:28:50.60Z</pubDate>
      <guid>http://www.richardnichols.net/2014/03/creating-and-importing-an-external-certificate-to-sql-server/</guid>
      <dc:date>2014-03-04T03:28:50.60Z</dc:date>
    </item>
</channel>
</rss>    