<?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>Silas Sewell - March 2009</title>
        <atom:link href="http://www.silassewell.com/blog/2009/03/rss2.xml" rel="self" type="application/rss+xml" />
        <link>http://www.silassewell.com/blog/2009/03</link>
        <description>Infrastructure Development</description>
        <lastBuildDate>Sat, 08 Jan 2011 00:00:00 GMT</lastBuildDate>
        <generator>http://www.silassewell.com/</generator>
        <language>en</language>
        <sy:updatePeriod>hourly</sy:updatePeriod>
        <sy:updateFrequency>1</sy:updateFrequency>

        <item>
            <title>Getting Started with AMQP, Qpid, Python &amp; Fedora</title>
            <link>http://www.silassewell.com/blog/2009/03/29/getting-started-with-amqp-qpid-python-fedora/</link>
            <pubDate>Sun, 29 Mar 2009 00:00:00 GMT</pubDate>
            <dc:creator>silas</dc:creator>
            <category><![CDATA[AMQP]]></category><category><![CDATA[Enterprise Messaging]]></category><category><![CDATA[Fedora]]></category><category><![CDATA[Programming]]></category><category><![CDATA[python-qpid]]></category><category><![CDATA[Qpid]]></category>
            <guid isPermaLink="true">http://www.silassewell.com/blog/2009/03/29/getting-started-with-amqp-qpid-python-fedora/</guid>
            <description><![CDATA[<p>The <a href="http://en.wikipedia.org/wiki/AMQP" title="Advanced Message Queuing Protocol">Advanced Message Queuing Protocol</a> (AMQP) is the first open
standard for Enterprise Messaging and has been adopted by Cisco,
[Microsoft][microsoft], Novel, <a href="http://www.redhat.com/solutions/specifications/amqp/" title="Red Hat">Red Hat</a> and <a href="http://jira.amqp.org/confluence/display/AMQP/AMQP+Working+Group" title="others">others</a>.</p>

<p>One implementation of AMQP currently packaged by <a href="http://www.redhat.com/mrg/messaging/" title="Red Hat">Red Hat</a> and Fedora is
Qpid. <a href="http://qpid.apache.org/" title="Qpid">Qpid</a> is a collection of brokers (C++, Java) and clients (C++,
Java, Python, Ruby) which <a href="http://qpid.apache.org/amqp-compatibility.html">aims to be 100% AMQP Compliant</a>.</p>

<p>Below is a step-by-step tutorial on getting started with Qpid and the Python
client in Fedora.</p>

<ol>
<li><p>Install the Qpid broker and Python client</p>

<pre><code class="prettyprint">yum install qpidd python-qpid
</code></pre></li>
<li><p>Start the broker</p>

<pre><code class="prettyprint">service qpidd start
</code></pre></li>
<li><p>Create a message producer (<code class="prettyprint">producer.py</code>)</p>

<pre><code class="prettyprint">from qpid.connection import Connection
from qpid.datatypes import Message, uuid4
from qpid.util import connect

# Create connection and session
socket = connect('localhost', 5672)
connection = Connection(sock=socket, username='guest', password='guest')
connection.start()
session = connection.session(str(uuid4()))

# Setup queue
session.queue_declare(queue='message_queue')
session.exchange_bind(exchange='amq.direct', queue='message_queue', binding_key='routing_key')

# Setup routing properties
properties = session.delivery_properties(routing_key='routing_key')

# Send messages
session.message_transfer(destination='amq.direct', message=Message(properties, 'Message one'))
session.message_transfer(destination='amq.direct', message=Message(properties, 'Message two'))
session.message_transfer(destination='amq.direct', message=Message(properties, 'Done'))

# Close session
session.close(timeout=10)
</code></pre></li>
<li><p>Create a message consumer (<code class="prettyprint">consumer.py</code>)</p>

<pre><code class="prettyprint">from qpid.connection import Connection
from qpid.datatypes import RangedSet, uuid4
from qpid.util import connect

# Create connection and session
socket = connect('localhost', 5672)
connection = Connection(sock=socket, username='guest', password='guest')
connection.start()
session = connection.session(str(uuid4()))

# Define local queue
local_queue_name = 'my_local_queue'

# Create local queue
queue = session.incoming(local_queue_name)

# Route messages from message_queue to my_local_queue
session.message_subscribe(queue='message_queue', destination=local_queue_name)
queue.start()

content = ''

while content != 'Done':
    # Get message from the local queue
    message = queue.get(timeout=10)
    # Get body of the message
    content = message.body
    # Accept message (removes it from the queue)
    session.message_accept(RangedSet(message.id))
    # Print message content
    print content

# Close session
session.close(timeout=10)
</code></pre></li>
<li><p>First run the producer and then the consumer</p>

<pre><code class="prettyprint">Message one
Message two
Done
</code></pre></li>
</ol>

<p>Source: <a href="https://svn.apache.org/repos/asf/qpid/trunk/qpid/python/examples/direct/" title="Qpid direct example">Qpid direct example</a></p>]]></description>
        </item>

        <item>
            <title>String Slicing in Bash (like Python)</title>
            <link>http://www.silassewell.com/blog/2009/03/12/string-slicing-in-bash-like-python/</link>
            <pubDate>Thu, 12 Mar 2009 00:00:00 GMT</pubDate>
            <dc:creator>silas</dc:creator>
            <category><![CDATA[Bash]]></category><category><![CDATA[Programming]]></category><category><![CDATA[Python]]></category><category><![CDATA[String]]></category><category><![CDATA[Systems Administration]]></category>
            <guid isPermaLink="true">http://www.silassewell.com/blog/2009/03/12/string-slicing-in-bash-like-python/</guid>
            <description><![CDATA[<p>A simple function to slice strings in Bash similar to Python's string slicing functionality.</p>

<h3>Examples</h3>

<pre><code class="prettyprint">[silas@pluto ~]$ string_slice "12345" 0 1
1
[silas@pluto ~]$ string_slice "12345" 0 3
123
[silas@pluto ~]$ string_slice "12345" 2 3
3
[silas@pluto ~]$ string_slice "12345" 2 -2
3
[silas@pluto ~]$ string_slice "12345" -3
345
</code></pre>

<h3>Implementation</h3>

<pre><code class="prettyprint">function string_slice {
    STRING="$1"
    declare -i LENGTH="${#STRING}"
    declare -i START="$2"
    declare -i END="$3"
    if [ $START -lt 0 ]; then
        START=$[ $LENGTH + $START ]
    fi
    if [ $END -le 0 ]; then
        END=$[ $LENGTH + $END ]
    fi
    START=$[ $START + 1 ]
    (echo "$STRING" | cut -c $START-$END) 2&gt; /dev/null
}
</code></pre>]]></description>
        </item>

        <item>
            <title>Profile Management with Git and GitHub</title>
            <link>http://www.silassewell.com/blog/2009/03/08/profile-management-with-git-and-github/</link>
            <pubDate>Sun, 08 Mar 2009 00:00:00 GMT</pubDate>
            <dc:creator>silas</dc:creator>
            <category><![CDATA[Bash]]></category><category><![CDATA[Configuration Management]]></category><category><![CDATA[Git]]></category><category><![CDATA[Projects]]></category><category><![CDATA[Systems Administration]]></category>
            <guid isPermaLink="true">http://www.silassewell.com/blog/2009/03/08/profile-management-with-git-and-github/</guid>
            <description><![CDATA[<p>The following describes a simple way to manage you profile configuration files using GitHub.</p>

<h3>Features</h3>

<ul>
<li>Centralized configuration management</li>
<li>Files live in their native locations (no symbolic linking)</li>
<li>Home directory is not a Git repository</li>
<li>All the power of git with a simple alias</li>
</ul>

<h3>Setup Repository</h3>

<ul>
<li>Log into <a href="http://github.com/" title="GitHub">GitHub</a> and create a repository named config</li>
<li>Add your <a href="http://github.com/guides/providing-your-ssh-key" title="Public Keys to GithHub">public keys to GitHub</a> (if you haven't done so already)</li>
<li><p>Open a terminal and switch to your home directory</p>

<pre><code class="prettyprint">cd ~
</code></pre></li>
<li><p>Create a configuration directory</p>

<pre><code class="prettyprint">mkdir .config.git
</code></pre></li>
<li><p>Add the following alias to your current session and your <code class="prettyprint">.bash_profile</code></p>

<pre><code class="prettyprint">alias config='git --git-dir=$HOME/.config.git/ --work-tree=$HOME'
echo "alias config='git --git-dir=$HOME/.config.git/ --work-tree=$HOME'" &gt;&gt; .bash_profile
</code></pre></li>
<li><p>Add your <code class="prettyprint">.bash_profile</code> to the configuration repository</p>

<pre><code class="prettyprint">config add .bash_profile
</code></pre></li>
<li><p>Commit the changes</p>

<pre><code class="prettyprint">config commit -m 'Initial commit'
</code></pre></li>
<li><p>Change the origin to GitHub</p>

<pre><code class="prettyprint">config remote add origin git@github.com:GITHUB_USERNAME/config.git
</code></pre></li>
<li><p>Push the changes</p>

<pre><code class="prettyprint">config push origin master
</code></pre></li>
</ul>

<p>If you get an error when running <code class="prettyprint">config pull</code> to the effect of <code class="prettyprint">You asked me to pull without...</code> run the follow:</p>

<pre><code class="prettyprint">    echo -e '[branch "master"]\n  remote = origin\n  merge = refs/heads/master' &gt;&gt; ~/.config.git/config
</code></pre>

<h3>Setup Configuration Management on a Different System</h3>

<ol>
<li>Add your <a href="http://github.com/guides/providing-your-ssh-key" title="Public Keys to GithHub">public keys to GitHub</a> (if you haven't done so already)</li>
<li><p>Switch to your home directory</p>

<pre><code class="prettyprint">cd ~
</code></pre></li>
<li><p>Backup your local configuration files, example:</p>

<pre><code class="prettyprint">mv .bash_profile .bash_profile.bk
</code></pre></li>
<li><p>Clone your configuration repository</p>

<pre><code class="prettyprint">git clone git@github.com:GITHUB_USERNAME/config.git config.git
</code></pre></li>
<li><p>Move the git metadata to <code class="prettyprint">~/.config.git</code></p>

<pre><code class="prettyprint">mv config.git/.git .config.git
</code></pre></li>
<li><p>Enable dotglob</p>

<pre><code class="prettyprint">shopt -s dotglob
</code></pre></li>
<li><p>Move your configuration files to your home directory</p>

<pre><code class="prettyprint">mv -i config.git/* .
</code></pre></li>
<li><p>Delete the <code class="prettyprint">config.git</code> directory</p>

<pre><code class="prettyprint">rmdir config.git
</code></pre></li>
<li><p>Logout and log back in</p></li>
</ol>

<h3>Basic Usage</h3>

<ul>
<li><code class="prettyprint">config pull</code> - get latest configuration changes</li>
<li><code class="prettyprint">config add FILENAME</code> - add a configuration file</li>
<li><code class="prettyprint">config commit -a</code> - save all configuration changes</li>
<li><code class="prettyprint">config push</code> - push configuration changes to GitHub</li>
<li>and any other <code class="prettyprint">config GIT_OPTION</code></li>
</ul>

<p>You can see my configuration repository at <a href="http://github.com/silas/config" title="config">http://github.com/silas/config</a>.</p>

<p>Source: <a href="http://robescriva.com/2009/01/manage-your-home-with-git/" title="source">Manage your $HOME with git</a> by Robert Escriva</p>]]></description>
        </item>

    </channel>
</rss>
