<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>swag.dk</title>
	<atom:link href="http://swag.dk/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://swag.dk/blog</link>
	<description></description>
	<lastBuildDate>Wed, 21 Jul 2010 12:34:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>iptables throughput on Soekris net4801</title>
		<link>http://swag.dk/blog/2010/07/21/iptables-thruput-on-soekris-net4801/</link>
		<comments>http://swag.dk/blog/2010/07/21/iptables-thruput-on-soekris-net4801/#comments</comments>
		<pubDate>Wed, 21 Jul 2010 12:33:17 +0000</pubDate>
		<dc:creator>Mads Sülau Jørgensen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://swag.dk/blog/?p=219</guid>
		<description><![CDATA[Earlier today I had to find out what the capacity of a soekris net4801 running openwrt. Using a fairly normal rule set, it can forward 51.8 Mbits/sec which is alright for a 266 MHz processor. Sadly for me, we&#8217;ll be &#8230; <a href="http://swag.dk/blog/2010/07/21/iptables-thruput-on-soekris-net4801/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Earlier today I had to find out what the capacity of a <a href="http://soekris.com/net4801.htm">soekris net4801</a> running <a href="http://www.openwrt.org/">openwrt</a>.</p>

<p>Using a fairly normal rule set, it can forward <strong>51.8 Mbits/sec</strong> which is alright for a 266 MHz processor.</p>

<p>Sadly for me, we&#8217;ll be getting a 100 Mbit fiber optic connection at work in a few months, so I guess I&#8217;ll have to move to a <a href="http://soekris.com/net5501.htm">net5501</a> unit in order to max out the connection.</p>

<p>Output from <code>iperf -s</code> (second run is over the lan):</p>


<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">------------------------------------------------------------
Server listening on TCP port 5001
TCP window size: 85.3 KByte (default)
------------------------------------------------------------
[  4] local x port 5001 connected with x port 64183
[ ID] Interval       Transfer     Bandwidth
[  4]  0.0-10.0 sec  61.7 MBytes  51.7 Mbits/sec
[  5] local x port 5001 connected with x port 64184
[  5]  0.0-10.0 sec  1.07 GBytes    921 Mbits/sec</pre></div></div>


<p>Output from <code>iperf -c</code>:</p>


<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">------------------------------------------------------------
Client connecting to x, TCP port 5001
TCP window size:   129 KByte (default)
------------------------------------------------------------
[  3] local x port 64183 connected with x port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.0 sec  61.7 MBytes  51.8 Mbits/sec</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://swag.dk/blog/2010/07/21/iptables-thruput-on-soekris-net4801/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to resize ext3 partition on LVM</title>
		<link>http://swag.dk/blog/2010/07/05/how-to-resize-ext3-partition-on-lvm/</link>
		<comments>http://swag.dk/blog/2010/07/05/how-to-resize-ext3-partition-on-lvm/#comments</comments>
		<pubDate>Mon, 05 Jul 2010 15:13:06 +0000</pubDate>
		<dc:creator>Mads Sülau Jørgensen</dc:creator>
				<category><![CDATA[Work]]></category>
		<category><![CDATA[ext3]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[lvm]]></category>
		<category><![CDATA[xen]]></category>

		<guid isPermaLink="false">http://swag.dk/blog/?p=210</guid>
		<description><![CDATA[From time to time I have to resize the file systems on various systems which are primarily using ext3 on top of LVM. Resizing such an ext3 file system is not a complex task at all. For starters, make sure &#8230; <a href="http://swag.dk/blog/2010/07/05/how-to-resize-ext3-partition-on-lvm/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>From time to time I have to resize the file systems on various systems which are primarily using ext3 on top of LVM.</p>

<p>Resizing such an ext3 file system is not a complex task at all. For starters, make sure you shut the domU down (or unmount the file system &#8211; unless you feel brave enough to do an online resize, in which case you should not be reading this).</p>

<p>After unmounting the file system, the LVM volume can be resized with <code>lvresize</code>:
<pre>
$ sudo lvresize -L +2G /dev/vg00/foo.example.com-disk
  Extending logical volume foo.example.com-disk to 8,00 GB
  Logical volume foo.example.com-disk successfully resized
</pre></p>

<p>Then, you&#8217;re ready to tell the file system that it has been resized:
<pre>
$ sudo resize2fs /dev/foo.example.com-disk 
resize2fs 1.40-WIP (14-Nov-2006)
Resizing the filesystem on /dev/vg00/foo.example.com-disk to 2097152 (4k) blocks.
The filesystem on /dev/vg00/petitepeople01.koho.dk-disk is now 2097152 blocks long.
</pre></p>

<p>And there you have it, a file system resized and ready for use.</p>

<p>P.S.
I&#8217;ve read numorus times that you have to run <code>fsck -f</code> and turn off journaling to use <code>resize2fs</code> but can&#8217;t really find any good reason to do so. If you want to, the commands are:</p>

<p>Turn off journal: <code>tune2fs -O ^has_journal <dev><dev></code></p>

<p>Force check of file system: <code>fsck -f <dev></code></p>

<p>Turn on journal: <code>tune2fs -j <dev></code></p>
]]></content:encoded>
			<wfw:commentRss>http://swag.dk/blog/2010/07/05/how-to-resize-ext3-partition-on-lvm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Extracting a single database from a pg_dumpall PostgreSQL dump</title>
		<link>http://swag.dk/blog/2010/04/09/extracting-a-single-database-from-a-pg_dumpall-postgresql-dump/</link>
		<comments>http://swag.dk/blog/2010/04/09/extracting-a-single-database-from-a-pg_dumpall-postgresql-dump/#comments</comments>
		<pubDate>Fri, 09 Apr 2010 15:00:26 +0000</pubDate>
		<dc:creator>Mads Sülau Jørgensen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://swag.dk/blog/?p=191</guid>
		<description><![CDATA[Some data got deleted from one of our databases, and we had to restore it from our backups. To make sure we get everything from our PostgreSQL cluster&#8217;s, we use pg_dumpall to make a SQL dump. It&#8217;s in no way &#8230; <a href="http://swag.dk/blog/2010/04/09/extracting-a-single-database-from-a-pg_dumpall-postgresql-dump/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Some data got deleted from one of our databases, and we had to restore it from our backups.</p>

<p>To make sure we get <em>everything</em> from our PostgreSQL cluster&#8217;s, we use <code>pg_dumpall</code> to make a SQL dump. It&#8217;s in no way the most efficient way to do a backup of a PostgreSQL database cluster, but it is by far the most flexible.</p>

<p>Numerous times I&#8217;ve had to fish our just one database from the dump created by <code>pg_dumpall</code> and finally got around to sticking it in a script.</p>

<p>Usage: <code>postgresql_dump_extract.sh &lt;dump_file&gt; &lt;db_name&gt; &gt; database.sql</code></p>

<p>The script does one pass over the file using <code>grep</code> and then uses byte offsets to cut the dump apart using <code>tail</code> and <code>head</code>. It&#8217;s fairly fast.</p>

<p>Enjoy!</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$#</span> <span style="color: #660033;">-ne</span> <span style="color: #000000;">2</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Usage: $0 &lt;postgresql sql dump&gt; &lt;db_name&gt;&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">2</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #007800;">db_file</span>=$<span style="color: #000000;">1</span>
<span style="color: #007800;">db_name</span>=$<span style="color: #000000;">2</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">$db_file</span> <span style="color: #660033;">-o</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-r</span> <span style="color: #007800;">$db_file</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;error: <span style="color: #007800;">$db_file</span> not found or not readable&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">2</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">2</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-b</span> <span style="color: #ff0000;">&quot;^\\\connect&quot;</span> <span style="color: #007800;">$db_file</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">1</span> <span style="color: #660033;">-A</span> <span style="color: #000000;">1</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$db_name</span>$&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #c20cb9; font-weight: bold;">read</span> line
<span style="color: #000000; font-weight: bold;">do</span>
	<span style="color: #007800;">bytes</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$line</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> -d: -f1<span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$start_point</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
	<span style="color: #000000; font-weight: bold;">then</span>
		<span style="color: #007800;">start_point</span>=<span style="color: #007800;">$bytes</span>
	<span style="color: #000000; font-weight: bold;">else</span>
		<span style="color: #007800;">end_point</span>=<span style="color: #007800;">$bytes</span>
	<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$start_point</span>&quot;</span> <span style="color: #660033;">-o</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$end_point</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;error: start or end not found&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">2</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">3</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #007800;">db_length</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">expr</span> <span style="color: #007800;">$end_point</span> - <span style="color: #007800;">$start_point</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">tail</span> <span style="color: #660033;">-c</span> +<span style="color: #007800;">$start_point</span> <span style="color: #007800;">$db_file</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">head</span> <span style="color: #660033;">-c</span> <span style="color: #007800;">$db_length</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tail</span> +<span style="color: #000000;">3</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://swag.dk/blog/2010/04/09/extracting-a-single-database-from-a-pg_dumpall-postgresql-dump/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Figuring out largest/smallest/median filesizes</title>
		<link>http://swag.dk/blog/2010/02/04/figuring-out-largestsmallestmedian-filesizes/</link>
		<comments>http://swag.dk/blog/2010/02/04/figuring-out-largestsmallestmedian-filesizes/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 14:00:52 +0000</pubDate>
		<dc:creator>Mads Sülau Jørgensen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://swag.dk/blog/2010/02/04/figuring-out-largestsmallestmedian-filesizes/</guid>
		<description><![CDATA[I had to get some statistics about file sizes today, but couldn&#8217;t really find a tool for the job, so naturally, I wrote one. import os, sys, re from os.path import join, getsize, exists &#160; def median&#40;numbers&#41;: s = sorted&#40;numbers&#41; &#8230; <a href="http://swag.dk/blog/2010/02/04/figuring-out-largestsmallestmedian-filesizes/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I had to get some statistics about file sizes today, but couldn&#8217;t really find a tool for the job, so naturally, I wrote one.</p>


<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>, <span style="color: #dc143c;">sys</span>, <span style="color: #dc143c;">re</span>
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span> <span style="color: #ff7700;font-weight:bold;">import</span> join, getsize, exists
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> median<span style="color: black;">&#40;</span>numbers<span style="color: black;">&#41;</span>:
    s = <span style="color: #008000;">sorted</span><span style="color: black;">&#40;</span>numbers<span style="color: black;">&#41;</span>
    l = <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>numbers<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> l <span style="color: #66cc66;">%</span> <span style="color: #ff4500;">2</span> == <span style="color: #ff4500;">0</span>:
        a, b = s<span style="color: black;">&#91;</span>l / <span style="color: #ff4500;">2</span> - <span style="color: #ff4500;">1</span> : l / <span style="color: #ff4500;">2</span> + <span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> a <span style="color: #66cc66;">!</span>= b:
            <span style="color: #ff7700;font-weight:bold;">return</span> a + b / <span style="color: #ff4500;">2.0</span>
        <span style="color: #ff7700;font-weight:bold;">else</span>:
            <span style="color: #ff7700;font-weight:bold;">return</span> a
    <span style="color: #ff7700;font-weight:bold;">else</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> s<span style="color: black;">&#91;</span>l / <span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span>
&nbsp;
sizes = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
req_re = <span style="color: #008000;">None</span>
target = <span style="color: #483d8b;">'.'</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">1</span>:
    target = <span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#41;</span> == <span style="color: #ff4500;">3</span>:
    req_re = <span style="color: #dc143c;">re</span>.<span style="color: #008000;">compile</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">for</span> root, dirs, files <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">walk</span><span style="color: black;">&#40;</span>target<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">for</span> name <span style="color: #ff7700;font-weight:bold;">in</span> files:
        absp = join<span style="color: black;">&#40;</span>root, name<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> exists<span style="color: black;">&#40;</span>absp<span style="color: black;">&#41;</span>:
            <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> req_re <span style="color: #ff7700;font-weight:bold;">or</span> req_re.<span style="color: black;">search</span><span style="color: black;">&#40;</span>absp<span style="color: black;">&#41;</span>:
                sizes.<span style="color: black;">append</span><span style="color: black;">&#40;</span>getsize<span style="color: black;">&#40;</span>absp<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
num = <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>sizes<span style="color: black;">&#41;</span>
total = <span style="color: #008000;">sum</span><span style="color: black;">&#40;</span>sizes<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Num files: %d&quot;</span> <span style="color: #66cc66;">%</span> num
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Average  : %0.2f KB&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>total / num<span style="color: black;">&#41;</span> / <span style="color: #ff4500;">1024.0</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Median   : %0.2f KB&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>median<span style="color: black;">&#40;</span>sizes<span style="color: black;">&#41;</span> / <span style="color: #ff4500;">1024.0</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Min      : %0.2f KB&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span><span style="color: #008000;">min</span><span style="color: black;">&#40;</span>sizes<span style="color: black;">&#41;</span> / <span style="color: #ff4500;">1024.0</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Max      : %0.2f KB&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span><span style="color: #008000;">max</span><span style="color: black;">&#40;</span>sizes<span style="color: black;">&#41;</span> / <span style="color: #ff4500;">1024.0</span><span style="color: black;">&#41;</span></pre></div></div>


<p>Usage should be self-explanatory.</p>
]]></content:encoded>
			<wfw:commentRss>http://swag.dk/blog/2010/02/04/figuring-out-largestsmallestmedian-filesizes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AppleScript application to slow network</title>
		<link>http://swag.dk/blog/2009/09/15/applescript-application-to-slow-network/</link>
		<comments>http://swag.dk/blog/2009/09/15/applescript-application-to-slow-network/#comments</comments>
		<pubDate>Tue, 15 Sep 2009 10:40:06 +0000</pubDate>
		<dc:creator>Mads Sülau Jørgensen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://swag.dk/blog/?p=186</guid>
		<description><![CDATA[I keep doing the same ipfw commands over and over. Enough of that, here is my first applescript application every. Probably filled with bugs and other scary things, and I&#8217;m probably not the first one to do this, but I &#8230; <a href="http://swag.dk/blog/2009/09/15/applescript-application-to-slow-network/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I keep doing the same <code>ipfw</code> commands over and over. Enough of that, here is my first applescript application every. Probably filled with bugs and other scary things, and I&#8217;m probably not the first one to do this, but I think I&#8217;m the first to stick the source out there.</p>


<div class="wp_syntax"><div class="code"><pre class="applescript" style="font-family:monospace;"><span style="color: #ff0033; font-weight: bold;">property</span> FLUSH_TEXT : <span style="color: #009900;">&quot;Quit and flush&quot;</span>
<span style="color: #ff0033; font-weight: bold;">property</span> SET_TEXT : <span style="color: #009900;">&quot;Set speed&quot;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">-- be damn carefull what you input here, it will run as root</span>
<span style="color: #ff0033; font-weight: bold;">on</span> ipfwLimit<span style="color: #000000;">&#40;</span>bandwidth<span style="color: #000000;">&#41;</span>
	<span style="color: #ff0033; font-weight: bold;">my</span> ipfwFlush<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
	<span style="color: #0066ff;">do shell script</span> <span style="color: #009900;">&quot;ipfw pipe 1 config bw &quot;</span> <span style="color: #000000;">&amp;</span> bandwidth <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;KB&quot;</span> <span style="color: #ff0033; font-weight: bold;">with</span> administrator privileges
	<span style="color: #0066ff;">do shell script</span> <span style="color: #009900;">&quot;ipfw add 10 pipe 1 tcp from any 80 to me&quot;</span> <span style="color: #ff0033; font-weight: bold;">with</span> administrator privileges
	<span style="color: #0066ff;">do shell script</span> <span style="color: #009900;">&quot;ipfw add 11 pipe 1 tcp from me to any 80&quot;</span> <span style="color: #ff0033; font-weight: bold;">with</span> administrator privileges
<span style="color: #ff0033; font-weight: bold;">end</span> ipfwLimit
&nbsp;
<span style="color: #808080; font-style: italic;">-- flush any ipfw rules</span>
<span style="color: #ff0033; font-weight: bold;">on</span> ipfwFlush<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #0066ff;">do shell script</span> <span style="color: #009900;">&quot;ipfw -f flush&quot;</span> <span style="color: #ff0033; font-weight: bold;">with</span> administrator privileges
<span style="color: #ff0033; font-weight: bold;">end</span> ipfwFlush
&nbsp;
<span style="color: #ff0033; font-weight: bold;">on</span> main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #ff0033; font-weight: bold;">set</span> question <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">display dialog</span> <span style="color: #009900;">&quot;Control your http traffic speed&quot;</span> <span style="color: #0066ff;">buttons</span> <span style="color: #000000;">&#123;</span>FLUSH_TEXT, SET_TEXT<span style="color: #000000;">&#125;</span> default button <span style="color: #000000;">2</span>
	<span style="color: #ff0033; font-weight: bold;">set</span> answer <span style="color: #ff0033; font-weight: bold;">to</span> button returned <span style="color: #ff0033; font-weight: bold;">of</span> question
&nbsp;
	<span style="color: #ff0033; font-weight: bold;">if</span> answer <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #ff0033;">equal</span> <span style="color: #ff0033; font-weight: bold;">to</span> FLUSH_TEXT <span style="color: #ff0033; font-weight: bold;">then</span>
		<span style="color: #ff0033; font-weight: bold;">my</span> ipfwFlush<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
&nbsp;
	<span style="color: #ff0033; font-weight: bold;">if</span> answer <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #ff0033;">equal</span> <span style="color: #ff0033; font-weight: bold;">to</span> SET_TEXT <span style="color: #ff0033; font-weight: bold;">then</span>
		<span style="color: #ff0033; font-weight: bold;">set</span> bandwidth_question <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">display dialog</span> <span style="color: #009900;">&quot;Enter bandwidth in KB/s (don't do something stupid like entering <span style="color: #000000; font-weight: bold;">\&quot;</span>; rm -rf /)&quot;</span> <span style="color: #0066ff;">default answer</span> <span style="color: #009900;">&quot;56&quot;</span>
		<span style="color: #ff0033; font-weight: bold;">set</span> bandwidth <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">text</span> returned <span style="color: #ff0033; font-weight: bold;">of</span> bandwidth_question
&nbsp;
		<span style="color: #ff0033; font-weight: bold;">my</span> ipfwLimit<span style="color: #000000;">&#40;</span>bandwidth<span style="color: #000000;">&#41;</span>
&nbsp;
		<span style="color: #ff0033; font-weight: bold;">my</span> main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
<span style="color: #ff0033; font-weight: bold;">end</span> main
&nbsp;
<span style="color: #ff0033; font-weight: bold;">my</span> main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://swag.dk/blog/2009/09/15/applescript-application-to-slow-network/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building postgresql8x and psycopg2 for x86_64 and i386 on Snow Leopard (OS X 10.6)</title>
		<link>http://swag.dk/blog/2009/09/03/building-postgresql8x-x86_64-i386-snow-leopard/</link>
		<comments>http://swag.dk/blog/2009/09/03/building-postgresql8x-x86_64-i386-snow-leopard/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 09:42:30 +0000</pubDate>
		<dc:creator>Mads Sülau Jørgensen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://swag.dk/blog/?p=171</guid>
		<description><![CDATA[I&#8217;ve recently installed Apple&#8217;s new 64 bit OS Snow Leopard, on my work computer. I use postgresql extensivly together with python, and usually use apple&#8217;s bundled python2.5 for working with django. As the daredevil I am, I wanted to recompile &#8230; <a href="http://swag.dk/blog/2009/09/03/building-postgresql8x-x86_64-i386-snow-leopard/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently installed Apple&#8217;s new 64 bit OS Snow Leopard, on my work computer. I use postgresql extensivly together with python, and usually use apple&#8217;s bundled python2.5 for working with django.</p>

<p>As the daredevil I am, I wanted to recompile all my macports to use the new 64 bit system, and therefore deleted them all, and made a fresh install of macports. After building the postgresql81 port, I was about to build the psycopg2 python postgresql driver for python 2.5, when it gave me a warning about not being able to find some symbols in the postgresql library it had linked to. I quickly realized that this might be an architecture problem, and sure enough, it turns out that python 2.5 is a i386/ppc and python 2.6 is x86_64/i386/ppc binary, as can be seen here:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">which</span> python<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>python: Mach-O universal binary with <span style="color: #000000;">3</span> architectures
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>python <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">for</span> architecture x86_64<span style="color: #7a0874; font-weight: bold;">&#41;</span>:	Mach-O <span style="color: #000000;">64</span>-bit executable x86_64
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>python <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">for</span> architecture i386<span style="color: #7a0874; font-weight: bold;">&#41;</span>:	Mach-O executable i386
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>python <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">for</span> architecture ppc7400<span style="color: #7a0874; font-weight: bold;">&#41;</span>:	Mach-O executable ppc
$ <span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">which</span> python2.5<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>python2.5: Mach-O universal binary with <span style="color: #000000;">2</span> architectures
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>python2.5 <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">for</span> architecture i386<span style="color: #7a0874; font-weight: bold;">&#41;</span>:	Mach-O executable i386
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>python2.5 <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">for</span> architecture ppc7400<span style="color: #7a0874; font-weight: bold;">&#41;</span>:	Mach-O executable ppc</pre></div></div>


<p>The solution seemed so simple. Recompile postgresql81 for both architectures, and let the linker figure out the rest.</p>

<p>Building the postgresql81 port as the +universal variant, does not work. It has something to do with the fact, that the linker (<code>ld</code>) does not know how to produce a binary for multiple architectures. After a good nights sleep, the solution was only a <a href="http://trac.macports.org/ticket/14619">trac ticket</a> away.</p>

<p>So, to build a i386 and x86_64 version of postgresql8x via macports, you have to patch the <code>Portfile</code>, which is located in <code>/opt/local/var/macports/sources/rsync.macports.org/release/ports/databases/postgresql81</code>.</p>

<p>That can be done like this &#8211; notice that the patch seem to place the files wrong, so we&#8217;re moving them as well:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>macports<span style="color: #000000; font-weight: bold;">/</span>sources<span style="color: #000000; font-weight: bold;">/</span>rsync.macports.org<span style="color: #000000; font-weight: bold;">/</span>release<span style="color: #000000; font-weight: bold;">/</span>ports<span style="color: #000000; font-weight: bold;">/</span>databases<span style="color: #000000; font-weight: bold;">/</span>postgresql81
$ curl <span style="color: #660033;">-s</span> http:<span style="color: #000000; font-weight: bold;">//</span>trac.macports.org<span style="color: #000000; font-weight: bold;">/</span>raw-attachment<span style="color: #000000; font-weight: bold;">/</span>ticket<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">14619</span><span style="color: #000000; font-weight: bold;">/</span>combined_updated_universal.patch <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">patch</span>
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> files<span style="color: #000000; font-weight: bold;">/</span>
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mv</span> ld.sh files<span style="color: #000000; font-weight: bold;">/</span>
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mv</span> patch_pg_config_h files<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>


<p>Now you can go ahead and build the postgresql81 port with both architectures, like so:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> port <span style="color: #c20cb9; font-weight: bold;">install</span> postgresql81 +universal</pre></div></div>


<p>And then, finally, we can build the psycopg2 extension for python:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>initd.org<span style="color: #000000; font-weight: bold;">/</span>pub<span style="color: #000000; font-weight: bold;">/</span>software<span style="color: #000000; font-weight: bold;">/</span>psycopg<span style="color: #000000; font-weight: bold;">/</span>psycopg2-2.0.12.tar.gz
$ <span style="color: #c20cb9; font-weight: bold;">tar</span> zxf psycopg2-2.0.12.tar.gz
$ <span style="color: #7a0874; font-weight: bold;">cd</span> psycopg2-2.0.12
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> python2.5 setup.py <span style="color: #c20cb9; font-weight: bold;">install</span>
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> python2.5 setup.py clean
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> python2.6 setup.py <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>


<p>And you&#8217;re off.</p>
]]></content:encoded>
			<wfw:commentRss>http://swag.dk/blog/2009/09/03/building-postgresql8x-x86_64-i386-snow-leopard/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Managing multiple AWS identities</title>
		<link>http://swag.dk/blog/2009/07/22/managing-multiple-aws-identities/</link>
		<comments>http://swag.dk/blog/2009/07/22/managing-multiple-aws-identities/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 14:50:12 +0000</pubDate>
		<dc:creator>Mads Sülau Jørgensen</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://swag.dk/blog/?p=167</guid>
		<description><![CDATA[I&#8217;m running multiple different project on AWS which was so much of a pain to use, as I often find myself having to use the identity of project-a together with the official amazon ec2 tools. To help myself manage the &#8230; <a href="http://swag.dk/blog/2009/07/22/managing-multiple-aws-identities/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m running multiple different project on <a href="http://aws.amazon.com/">AWS</a> which was so much of a pain to use, as I often find myself having to use the identity of project-a together with the official amazon ec2 tools.</p>

<p>To help myself manage the multiple identities, I wote a set of bash functions, called:</p>

<ul>
<li><code>aws_load &lt;config-name&gt;</code> &#8211; loads configuration from config-name</li>
<li><code>ec2ssh &lt;instance-number-in-ec2din-list&gt;</code> &#8211; ssh&#8217;s into a given instance, with the root key</li>
<li><code>ec2scp</code> &#8211; a shorthand for scp -i &lt;keyfile&gt;
<!-- more --></li>
</ul>

<p>I keep the configuration files in the directory <code>~/amazon/conf/name.sh</code> and keypairs in <code>~/amazon/keypairs/</code> but that should be obvious to change.</p>

<p>To change or load an identity, one simply calls the function from a shell prompt like so:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mads<span style="color: #000000; font-weight: bold;">@</span>workmads ~ <span style="color: #000000; font-weight: bold;">%</span> aws_load some-identity
loaded certificate ...
loaded <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>mads<span style="color: #000000; font-weight: bold;">/</span>amazon<span style="color: #000000; font-weight: bold;">/</span>conf<span style="color: #000000; font-weight: bold;">/</span>some-identity.sh <span style="color: #7a0874; font-weight: bold;">&#40;</span>...<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>


<p>I hope someone finds this as useful as I do.</p>

<p>Functions (could be placed in <code>.bashrc</code> or <code>.zshrc</code>).</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> aws_load <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
		<span style="color: #007800;">ec2_configurations</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$HOME</span>/amazon/conf&quot;</span>
		<span style="color: #007800;">ec2_keys</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$HOME</span>/amazon/keypairs&quot;</span>
		<span style="color: #007800;">conf</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$ec2_configurations</span>/$1.sh&quot;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-x</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$conf</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
			<span style="color: #7a0874; font-weight: bold;">unset</span> AMAZON_ID AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_CERT EC2_PRIVATE_KEY EC2_CERT AWS_KEYPAIR_NAME
&nbsp;
			<span style="color: #7a0874; font-weight: bold;">source</span> <span style="color: #007800;">$conf</span>
&nbsp;
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$AWS_KEYPAIR_NAME</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
				<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">AWS_SSH_KEY</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$ec2_keys</span>/id_rsa_<span style="color: #007800;">${AWS_KEYPAIR_NAME}</span>-keypair&quot;</span>
			<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$AWS_CERT</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
				<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">EC2_PRIVATE_KEY</span>=~<span style="color: #000000; font-weight: bold;">/</span>.ec2<span style="color: #000000; font-weight: bold;">/</span>pk-<span style="color: #007800;">$AWS_CERT</span>.pem
				<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">EC2_CERT</span>=~<span style="color: #000000; font-weight: bold;">/</span>.ec2<span style="color: #000000; font-weight: bold;">/</span>cert-<span style="color: #007800;">$AWS_CERT</span>.pem
&nbsp;
				<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;loaded certificate <span style="color: #007800;">$AWS_CERT</span>&quot;</span>
			<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
			<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;loaded <span style="color: #007800;">$conf</span> (<span style="color: #007800;">$AMAZON_ID</span>)&quot;</span>
		<span style="color: #000000; font-weight: bold;">else</span>
			<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;configuration <span style="color: #007800;">$conf</span> not found (or not executable)&quot;</span>
		<span style="color: #000000; font-weight: bold;">fi</span>
    <span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;usage: aws_load &lt;configuration name&gt;&quot;</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> ec2ssh <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">HOST</span>=<span style="color: #ff0000;">&quot;<span style="color: #780078;">`ec2din | awk '/i-/ {print $4}' | tail +$1 | head -n 1`</span>&quot;</span>
        <span style="color: #c20cb9; font-weight: bold;">ssh</span> <span style="color: #660033;">-i</span> <span style="color: #007800;">$AWS_SSH_KEY</span> <span style="color: #660033;">-l</span> root <span style="color: #800000;">${HOST}</span>
    <span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Please write a number&quot;</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> ec2scp <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	<span style="color: #c20cb9; font-weight: bold;">scp</span> <span style="color: #660033;">-i</span> <span style="color: #007800;">$AWS_SSH_KEY</span> $<span style="color: #000000; font-weight: bold;">@</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>


<p>Configuration &#8220;file&#8221; template to be placed in <code>~/amazon/conf/&lt;config-name&gt;.sh</code>:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">AMAZON_ID</span>=<span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">AWS_ACCESS_KEY_ID</span>=<span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">AWS_SECRET_ACCESS_KEY</span>=<span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">AWS_CERT</span>=<span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">AWS_KEYPAIR_NAME</span>=<span style="color: #ff0000;">&quot;&quot;</span></pre></div></div>


<p>Happy identity switching.</p>
]]></content:encoded>
			<wfw:commentRss>http://swag.dk/blog/2009/07/22/managing-multiple-aws-identities/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Detaching a running process on *nix (or how to make a process continue to run after logging out)</title>
		<link>http://swag.dk/blog/2009/07/16/detaching-a-process-on-nix/</link>
		<comments>http://swag.dk/blog/2009/07/16/detaching-a-process-on-nix/#comments</comments>
		<pubDate>Thu, 16 Jul 2009 12:31:12 +0000</pubDate>
		<dc:creator>Mads Sülau Jørgensen</dc:creator>
				<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://swag.dk/blog/?p=156</guid>
		<description><![CDATA[Today, I had to copy 70 GiB of data from a ext3 filesystem to a XFS filesystem. This involved a lot of small files. After a couple of hours of waiting, I thought it&#8217;d be best to just leave it &#8230; <a href="http://swag.dk/blog/2009/07/16/detaching-a-process-on-nix/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Today, I had to copy 70 GiB of data from a ext3 filesystem to a XFS filesystem. This involved a lot of small files. After a couple of hours of waiting, I thought it&#8217;d be best to just leave it running, and resume my activities the day after. But <a href="http://www.youtube.com/watch?v=rks-Cr3Fr_k">oh nooo</a>, I forgot to run it in a <a href="http://www.gnu.org/software/screen/">screen</a>.<span id="more-156"></span></p>

<p>Detaching a running process from your shell, proved to be very easy in deed, using a shell command called <a href="http://www.google.com/search?q=disown+linux">disown</a>.</p>

<p>To disown a running process, start by suspending the process by pressing <code>^Z</code>, then send it to the background with the command <code>bg</code> <em>then</em> you can make it run until it&#8217;s done by using the <code>disown</code> command. To access the processes you&#8217;ve got suspended, you can use the <code>%</code> prefix (<code>%1</code> for the first, <code>%2</code> for the second etc.). To get a list of running processes you can use the <code>jobs</code> command.</p>

<p>Example:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mads<span style="color: #000000; font-weight: bold;">@</span>workmads ~ <span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">120</span>
^Z
<span style="color: #c20cb9; font-weight: bold;">zsh</span>: suspended  <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">120</span>
mads<span style="color: #000000; font-weight: bold;">@</span>workmads ~ <span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">bg</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>  + continued  <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">120</span>
mads<span style="color: #000000; font-weight: bold;">@</span>workmads ~ <span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">disown</span> <span style="color: #000000; font-weight: bold;">%</span>1
&nbsp;
mads<span style="color: #000000; font-weight: bold;">@</span>workmads ~ <span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">ps</span> xawu<span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #c20cb9; font-weight: bold;">sleep</span>
mads     <span style="color: #000000;">31725</span>   <span style="color: #000000;">0.0</span>  <span style="color: #000000;">0.0</span>    <span style="color: #000000;">75332</span>    <span style="color: #000000;">304</span> s003  S     <span style="color: #000000;">2</span>:25PM   <span style="color: #000000;">0</span>:<span style="color: #000000;">00.00</span> <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">120</span></pre></div></div>


<p>If you accedently didn&#8217;t background your process, you can tell it to resume by sending it a <code>SIGCONT</code> signal with <code>kill -SIGCONT &lt;pid&gt;</code>.</p>

<p>Of course, this is no replacement for <code>nohup</code> or <code>screen</code>, but I think it is a great supplement.</p>
]]></content:encoded>
			<wfw:commentRss>http://swag.dk/blog/2009/07/16/detaching-a-process-on-nix/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Poormans cloudfront with EC2 and varnish</title>
		<link>http://swag.dk/blog/2009/06/30/poormans-cloudfront-with-ec2-and-varnish/</link>
		<comments>http://swag.dk/blog/2009/06/30/poormans-cloudfront-with-ec2-and-varnish/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 08:51:33 +0000</pubDate>
		<dc:creator>Mads Sülau Jørgensen</dc:creator>
				<category><![CDATA[Work]]></category>
		<category><![CDATA[amazon aws]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[cloudfront]]></category>
		<category><![CDATA[varnish]]></category>

		<guid isPermaLink="false">http://swag.dk/blog/?p=152</guid>
		<description><![CDATA[Recently (10-20 minutes ago), amazon couldfront (a cdn) stopped sending dns replies in europe: % dig -t ns cloudfront.net ; DiG 9.4.3-P1 -t ns cloudfront.net ;; global options: printcmd ;; connection timed out; no servers could be reached I was &#8230; <a href="http://swag.dk/blog/2009/06/30/poormans-cloudfront-with-ec2-and-varnish/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Recently (10-20 minutes ago), amazon couldfront (a cdn) stopped sending dns replies in europe:</p>

<pre>
% dig -t ns cloudfront.net

; <<>> DiG 9.4.3-P1 <<>> -t ns cloudfront.net
;; global options:  printcmd
;; connection timed out; no servers could be reached
</pre>

<p>I was going to do a guide to set up a varnish to replace cloudfront temporarily (and did actually set up the instance, and software &#8211; I might do the guide and ami anyway) when I realized, that I (as well as most other people) can just change the relevant url to point to the S3 bucket. Problem solved. That will, however, not be as fast as either cloudfront itself, or a varnish cached backend.</p>

<p>Should anyone be interested in how varnish is setup to handle failures from cloudfront, I&#8217;ll happily do an ami.</p>
]]></content:encoded>
			<wfw:commentRss>http://swag.dk/blog/2009/06/30/poormans-cloudfront-with-ec2-and-varnish/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Django &#8211; sharing a memcached instance</title>
		<link>http://swag.dk/blog/2009/06/23/django-sharing-a-memcached-instance/</link>
		<comments>http://swag.dk/blog/2009/06/23/django-sharing-a-memcached-instance/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 11:23:00 +0000</pubDate>
		<dc:creator>Mads Sülau Jørgensen</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[memcached]]></category>
		<category><![CDATA[prefix]]></category>

		<guid isPermaLink="false">http://swag.dk/blog/?p=135</guid>
		<description><![CDATA[Update: Some Curious User brought to my attention, that a ticket has been opened which, when implemented, will add a setting for a cache prefix. It will also allow other cache key manipulations. Until recently I&#8217;ve been using the file:// &#8230; <a href="http://swag.dk/blog/2009/06/23/django-sharing-a-memcached-instance/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><strong>Update:</strong>
Some <a href="http://swag.dk/blog/2009/06/23/django-sharing-a-memcached-instance/comment-page-1/#comment-812">Curious User</a> brought to my attention, that <a href="http://code.djangoproject.com/ticket/13795">a ticket</a> has been opened which, when implemented, will add a setting for a cache prefix. It will also allow other cache key manipulations.</p>

<p>Until recently I&#8217;ve been using the <code>file://</code> django cache, but that has a &#8220;problem&#8221; when multiple users needs to manipulate the cache (think uid 80 writes a key, that uid 1000 wants to delete).</p>

<p>My problem with the <code>memcached://</code> django cache provider has been, that it cannot handle being used on a shared memcached instance, because of the danger of key collissions.</p>

<p><span id="more-135"></span>
If project A and project B would share a memcached instance, they basiclly share the same global namespace. So if they both write a key called <code>actor</code> there is no telling what will happen.</p>

<p>So I wrote a little cache backend for django, that uses the current <code>memcached</code> backend, but adds a pre-defined prefix to all keys.</p>

<p><strong>Usage:</strong>
Put the code somewhere inside your project in a file called <code>memcached&#95;key&#95;prefix.py</code>, and set your <code>CACHE&#95;BACKEND</code> to something like: <code>path.to.memcached&#95;key&#95;prefix:///127.0.0.1:11211/?key&#95;prefix=sewc&#95;&amp;foo=bar&amp;timeout=3600</code></p>


<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #483d8b;">&quot;Memcached cache backend with key prefixing&quot;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">core</span>.<span style="color: black;">cache</span>.<span style="color: black;">backends</span>.<span style="color: black;">base</span> <span style="color: #ff7700;font-weight:bold;">import</span> InvalidCacheBackendError
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">core</span>.<span style="color: black;">cache</span>.<span style="color: black;">backends</span>.<span style="color: black;">memcached</span> <span style="color: #ff7700;font-weight:bold;">import</span> CacheClass <span style="color: #ff7700;font-weight:bold;">as</span> MemcachedCacheClass
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">utils</span>.<span style="color: black;">encoding</span> <span style="color: #ff7700;font-weight:bold;">import</span> smart_unicode, smart_str
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> CacheClass<span style="color: black;">&#40;</span>MemcachedCacheClass<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, server, params<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">try</span>:
            <span style="color: #008000;">self</span>._key_prefix = smart_str<span style="color: black;">&#40;</span>params<span style="color: black;">&#91;</span><span style="color: #483d8b;">'key_prefix'</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #008000;">KeyError</span>:
            <span style="color: #ff7700;font-weight:bold;">raise</span> InvalidCacheBackendError<span style="color: black;">&#40;</span><span style="color: #483d8b;">'key_prefix not specified'</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #008000;">super</span><span style="color: black;">&#40;</span>CacheClass, <span style="color: #008000;">self</span><span style="color: black;">&#41;</span>.<span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span>server, params<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> _get_key<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, key<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">self</span>._key_prefix + smart_str<span style="color: black;">&#40;</span>key<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> add<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, key, value, timeout=<span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">super</span><span style="color: black;">&#40;</span>CacheClass, <span style="color: #008000;">self</span><span style="color: black;">&#41;</span>.<span style="color: black;">add</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>._get_key<span style="color: black;">&#40;</span>key<span style="color: black;">&#41;</span>, value, timeout<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> get<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, key, default=<span style="color: #008000;">None</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">super</span><span style="color: black;">&#40;</span>CacheClass, <span style="color: #008000;">self</span><span style="color: black;">&#41;</span>.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>._get_key<span style="color: black;">&#40;</span>key<span style="color: black;">&#41;</span>, default<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #008000;">set</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, key, value, timeout=<span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">super</span><span style="color: black;">&#40;</span>CacheClass, <span style="color: #008000;">self</span><span style="color: black;">&#41;</span>.<span style="color: #008000;">set</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>._get_key<span style="color: black;">&#40;</span>key<span style="color: black;">&#41;</span>, value, timeout<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> delete<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, key<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">super</span><span style="color: black;">&#40;</span>CacheClass, <span style="color: #008000;">self</span><span style="color: black;">&#41;</span>.<span style="color: black;">delete</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>._get_key<span style="color: black;">&#40;</span>key<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> get_many<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, keys<span style="color: black;">&#41;</span>:
        keys = <span style="color: black;">&#91;</span><span style="color: #008000;">self</span>._get_key<span style="color: black;">&#40;</span>key<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> key <span style="color: #ff7700;font-weight:bold;">in</span> keys<span style="color: black;">&#93;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">super</span><span style="color: black;">&#40;</span>CacheClass, <span style="color: #008000;">self</span><span style="color: black;">&#41;</span>.<span style="color: black;">get_many</span><span style="color: black;">&#40;</span>keys<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> incr<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, key, delta=<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">super</span><span style="color: black;">&#40;</span>CacheClass, <span style="color: #008000;">self</span><span style="color: black;">&#41;</span>.<span style="color: black;">incr</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>._get_key<span style="color: black;">&#40;</span>key<span style="color: black;">&#41;</span>, delta<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> decr<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, key, delta=<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">super</span><span style="color: black;">&#40;</span>CacheClass, <span style="color: #008000;">self</span><span style="color: black;">&#41;</span>.<span style="color: black;">decr</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>._get_key<span style="color: black;">&#40;</span>key<span style="color: black;">&#41;</span>, delta<span style="color: black;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://swag.dk/blog/2009/06/23/django-sharing-a-memcached-instance/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
