<?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>froztbyte.getBlog() &#187; python</title>
	<atom:link href="http://blog.froztbyte.net/tag/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.froztbyte.net</link>
	<description>returns the contents of froztbyte.blog</description>
	<lastBuildDate>Mon, 13 Oct 2014 20:19:25 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.0</generator>
	<item>
		<title>&#8220;Tip me that output quickly, would you?&#8221;</title>
		<link>http://blog.froztbyte.net/2012/11/tip-me-that-output-quickly-would-you/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=tip-me-that-output-quickly-would-you</link>
		<comments>http://blog.froztbyte.net/2012/11/tip-me-that-output-quickly-would-you/#comments</comments>
		<pubDate>Fri, 02 Nov 2012 11:43:32 +0000</pubDate>
		<dc:creator><![CDATA[froztbyte]]></dc:creator>
				<category><![CDATA[tech]]></category>
		<category><![CDATA[codetip]]></category>
		<category><![CDATA[hastebin]]></category>
		<category><![CDATA[nodejs]]></category>
		<category><![CDATA[pastebin]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[twisted]]></category>

		<guid isPermaLink="false">http://blog.froztbyte.net/?p=331</guid>
		<description><![CDATA[Jonathan recently wrote Codetip, a pastebin based on Twisted.Web with some neat client-side features and integrating server-side JS as well. There&#8217;s a demo one running at http://pb.vuze.la/ Short of the setup doc in the readme, there&#8217;s some further work you &#8230;<p class="read-more"><a href="http://blog.froztbyte.net/2012/11/tip-me-that-output-quickly-would-you/">Read more &#187;</a></p>]]></description>
				<content:encoded><![CDATA[<p><a href="http://jonathan.jsphere.com/">Jonathan</a> recently wrote <a href="https://github.com/jonathanj/Codetip">Codetip</a>, a pastebin based on Twisted.Web with some neat client-side features and integrating server-side JS as well.</p>
<p>There&#8217;s a demo one running at <a href="http://pb.vuze.la/">http://pb.vuze.la/</a></p>
<p>Short of the setup doc in the readme, there&#8217;s some further work you get to do when installing this on something like Debian Squeeze. Here&#8217;s a quick rundown from my shell history:</p>
<pre> 1237  aptitude -t wheezy install python-pip
 1242  aptitude -t wheezy install virtualenvwrapper
 1252  aptitude -t wheezy install python-virtualenv
 1257  aptitude -t wheezy install python-sqlite python-pysqlite2</pre>
<p>All of those mostly because of versioning. Node.js was also installed previously (for Brewer.js), so npm was around as well, at the <em>sid</em> package version level.</p>
<p>It was set up in a separate user account, with a virtualenv to avoid crapping all over the system. For those who don&#8217;t know, a virtualenv is used to make a little jail for python things to get installed into. This way you can have a different local version of something to what&#8217;s installed globally (globally meaning system level). Turns out this makes life a bit more painful:</p>
<p>Drop this into .zshenv (or the appropriate equivalent for your shell):</p>
<pre># virtualenv
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_VIRTUALENV_ARGS='--system-site-packages'
export VIRTUALENVWRAPPER_LOG_DIR=$WORKON_HOME
export PIP_VIRTUALENV_BASE=$WORKON_HOME
export PIP_RESPECT_VIRTUALENV=true</pre>
<p>And then run:</p>
<pre>git clone https://github.com/jonathanj/Codetip.git
mkvirtualenv Codetip
activate Codetip
pip install Twisted; pip install Epsilon; pip install Axiom; ln -s =nodejs $(VIRTUAL_ENV)/bin/node
npm install brewer
cd Codetip
./node_modules/brewer/bin/brake install
./node_modules/brewer/bin/brake all
twistd -no-web --notracebacks --class=Codetip.resource.RootResource</pre>
<p>The virtualenvwrapper package provides &#8216;mkvirtualenv&#8217; amongst other things, use `<em>source /etc/bash_completion.d/virtualenvwrapper` </em>to get the hooks. This shellscript also works in zsh.</p>
<p>And that&#8217;s it, a working Codetip instance.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.froztbyte.net/2012/11/tip-me-that-output-quickly-would-you/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Should I buy some stock?</title>
		<link>http://blog.froztbyte.net/2012/08/should-i-buy-some-stock/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=should-i-buy-some-stock</link>
		<comments>http://blog.froztbyte.net/2012/08/should-i-buy-some-stock/#comments</comments>
		<pubDate>Tue, 07 Aug 2012 15:03:21 +0000</pubDate>
		<dc:creator><![CDATA[froztbyte]]></dc:creator>
				<category><![CDATA[minipost]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[decisions]]></category>
		<category><![CDATA[life]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[stocks]]></category>

		<guid isPermaLink="false">http://blog.froztbyte.net/?p=283</guid>
		<description><![CDATA[thoughts: I still have some stock account balance left..wonder if I should buy some.. In [1]: from random import choice In [2]: choices = {'buy': 0, 'wait': 0} In [3]: for i in range(0,5000): choices[choice(['buy','wait'])] += 1 ...: In [4]: &#8230;<p class="read-more"><a href="http://blog.froztbyte.net/2012/08/should-i-buy-some-stock/">Read more &#187;</a></p>]]></description>
				<content:encoded><![CDATA[<p>thoughts: I still have some stock account balance left..wonder if I should buy some..</p>
<pre>In [1]: from random import choice
In [2]: choices = {'buy': 0, 'wait': 0}
In [3]: for i in range(0,5000):
    choices[choice(['buy','wait'])] += 1
   ...:
In [4]: choices
Out[4]: {'buy': 2518, 'wait': 2482}</pre>
<p>Guess I&#8217;ll buy some stocks.</p>
<p>[ed's note: this method works equally well to decide <em>which</em> stocks you want to buy when you're lazy]</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.froztbyte.net/2012/08/should-i-buy-some-stock/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zenoss &#8211; Find transforms</title>
		<link>http://blog.froztbyte.net/2011/08/zenoss-find-transforms/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=zenoss-find-transforms</link>
		<comments>http://blog.froztbyte.net/2011/08/zenoss-find-transforms/#comments</comments>
		<pubDate>Thu, 25 Aug 2011 11:10:33 +0000</pubDate>
		<dc:creator><![CDATA[froztbyte]]></dc:creator>
				<category><![CDATA[tech]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[hacks]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[zenoss]]></category>

		<guid isPermaLink="false">http://blog.froztbyte.net/?p=58</guid>
		<description><![CDATA[So I was looking around in one of my zenoss installs some time ago to find what EventClasses I&#8217;d set up transforms in, but didn&#8217;t feel like digging around through the entire tree of EventClasses (a cursory check now reveals &#8230;<p class="read-more"><a href="http://blog.froztbyte.net/2011/08/zenoss-find-transforms/">Read more &#187;</a></p>]]></description>
				<content:encoded><![CDATA[<p>So I was looking around in one of my zenoss installs some time ago to find what EventClasses I&#8217;d set up transforms in, but didn&#8217;t feel like digging around through the entire tree of EventClasses (a cursory check now reveals that there&#8217;s 136 of them in my one installation). At the time, I solved the problem, extracted the data I needed, and then consequently forgot about it.</p>
<p>And then today I needed that info again. \o/ for IRC logs. To do this, connect to the dmd (on my system, which is installed with the debian package, the command for this is <em>su -c &#8220;/usr/local/zenoss/zenoss/bin/zendmd&#8221; zenoss</em>. Adjust it for your own system), and then run the following code</p>
<pre>foo = dmd.Events.getSubEventClasses()
for i in foo:
    if len(i.transform) != 0: print "%s :: \n%s\n\n" % (i.getOrganizerName(), i.transform)</pre>
<p>This will give you human-readable list of all your existing transforms, which makes it easy to find and re-use them.</p>
<p>Edit: this is confirmed working on 3.2.1 (and probably works on the rest of 3.x as well, post in the comments if it doesn&#8217;t). Thanks to jmp242 from #zenoss for testing.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.froztbyte.net/2011/08/zenoss-find-transforms/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DNS Platform Migration Fun</title>
		<link>http://blog.froztbyte.net/2011/08/dns-platform-migration-fun/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=dns-platform-migration-fun</link>
		<comments>http://blog.froztbyte.net/2011/08/dns-platform-migration-fun/#comments</comments>
		<pubDate>Sat, 06 Aug 2011 00:14:17 +0000</pubDate>
		<dc:creator><![CDATA[froztbyte]]></dc:creator>
				<category><![CDATA[tech]]></category>
		<category><![CDATA[dns]]></category>
		<category><![CDATA[hacks]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[rants]]></category>

		<guid isPermaLink="false">http://blog.froztbyte.net/?p=23</guid>
		<description><![CDATA[This post could go by the alternative title &#8220;Screw you, ISC, and thanks for making software that makes me hate DNS even more&#8221;. So let&#8217;s dive right in, shall we? (to those who don&#8217;t care for the intermediate ranting and &#8230;<p class="read-more"><a href="http://blog.froztbyte.net/2011/08/dns-platform-migration-fun/">Read more &#187;</a></p>]]></description>
				<content:encoded><![CDATA[<p>This post could go by the alternative title &#8220;Screw you, ISC, and thanks for making software that makes me hate DNS even more&#8221;. So let&#8217;s dive right in, shall we?</p>
<p><em>(to those who don&#8217;t care for the intermediate ranting and DNS explanations, page down for the tech bits)</em></p>
<p>There are various criticisms of the Domain Name System — the thing which enables anything on the internet to turn &#8220;www.google.com&#8221; or any other such name into something that is meaningful to a computer (see <a href="http://cr.yp.to/djbdns/intro-dns.html">here</a>) — but for the most part it works reasonably well. You set up some DNS software, perhaps battle with the config for a while, and then it works. But as a quote I&#8217;ve seen somewhere (and can&#8217;t find the origin of now with a quick search) says, &#8220;you can&#8217;t truly recommend some software [tool] until you can tell me why it sucks.&#8221; And ISC&#8217;s BIND is arguably a highly irritating piece of software, which has over the years led to a rise in popularity for various other options. Amongst these you&#8217;ll find some general free/opensource implementations, as well as some commercial platforms:</p>
<ul>
<li><a href="http://www.maradns.org/">MaraDNS</a></li>
<li><a href="http://cr.yp.to/djbdns.html">djbdns</a></li>
<li><a href="http://www.powerdns.com/content/home-powerdns.html">PowerDNS</a></li>
<li><a href="http://www.infoblox.com/en/home.html">Infoblox</a></li>
<li><a href="http://www.bluecatnetworks.com/solutions/dns_dhcp">Bluecat Adonis</a></li>
<li><a href="http://aws.amazon.com/route53/">Route53</a></li>
</ul>
<div><span class="Apple-style-span" style="line-height: 18px;">(That&#8217;s the nice thing about diversity and openness — in this regard, an open protocol — you always get some choice and you can pick which one best suits your needs.)</span></div>
<p>&nbsp;</p>
<div>Some years ago, long before my time at my current employer, there was a business requirement for some DNS support in our product suite. And BIND was chosen as the platform, since it&#8217;s a fairly well-known one. As time progresses, so do the things we do, and one day we found BIND was no longer sufficient to do what we needed to. Amongst others, things like a supermaster (a master from which a slave will accept all domain information, regardless of whether that slave knows of such a domain) and dynamic backend functionality were some of those needs.<br />
Now some options like <a href="http://bind-dlz.sourceforge.net/">bind-dlz</a> and friends existed, but none of these really suited us. In the end we decided upon PowerDNS with our own custom software written to handle the dynamic things as business rules would require, and set forth on this path. Some time passes with <a href="http://geekz.za.net/">Rossi</a> writing all the backend code which we&#8217;ve then successfully been running in combination with PowerDNS for some time now.</div>
<p>&nbsp;</p>
<div>Of course, we still have all those old BIND-based installations to get upgraded, and this is that tale. Thankfully, the latest version of our platform was designed with exactly this sort of scenario in mind, since we have to inter-operate with other AXFR-speaking nameservers. So I think &#8220;let&#8217;s just use the config interface to add the migration host as a second slave, massage the data as required on there and then port that data over to the new platform&#8221; even as a tiny voice in my head says &#8220;it&#8217;s never that simple and you know it.&#8221; About 2 hours later I&#8217;m found at my desk swearing violently about all manner of things, which is my out when dealing with frustrating software. This is because I&#8217;d ended up trying to find out why BIND wasn&#8217;t actually slaving anything to my &#8220;new&#8221; nameserver, even though all the configs and zonefiles were right. Not just that, it had also at some point stopped slaving everything it should to the secondary nameserver, which at this point isn&#8217;t a worry since I&#8217;m replacing it anyway.</div>
<p>&nbsp;</p>
<p><span style="text-decoration: underline;">:: TECH ::</span></p>
<div>After figuring out the bits of the migration that matter — such as fixing up the SQL output (from the handy</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">zone2sql</div></td></tr></tbody></table></div>
<p>tool from pdns) that had some oddities due to what looked like multiple $ORIGIN statements in one file — had been figured out, it was pretty painless to move. There were some fun points, like handling multiple $INCLUDE statements in a zonefile, and *hattip* to <a href="http://vhata.net">Jonathan Hitchcock</a> (for the pre- and post-insert idea) and <a href="http://bryndivey.co.za/">Bryn Divey</a> (for googling better than I).</div>
<p>&nbsp;</p>
<div>So, sed trick 1, splitting the file into parts:</div>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">cat foo.zone | sed -n '1,/match/p' &amp;gt; firstbit<br />
cat foo.zone | sed -n '1,/match/!p' &amp;gt; secondbit<br />
cat firstbit secondbit &amp;gt; newfoo</div></td></tr></tbody></table></div>
<div>Sed trick 2, reading in an external file to use it as the replacement text. We have:</div>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"># grep INCLUDE 10_in-addr_arpa.zone<br />
$INCLUDE &quot;/var/cache/bind/10_in-addr_arpa.zone.ns&quot;;<br />
$INCLUDE &quot;/var/cache/bind/10_in-addr_arpa.zone.mx&quot;;</div></td></tr></tbody></table></div>
<div>We do:</div>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">sed -i '/$INCLUDE.*\.ns.*$/ r 10_in-addr_arpa.zone.ns' 10_in-addr_arpa.zone<br />
sed -i '/$INCLUDE.*\.mx.*$/ r 10_in-addr_arpa.zone.mx' 10_in-addr_arpa.zone<br />
&lt;code&gt;</div></td></tr></tbody></table></div>
<p></code></p>
<div>And tada, instant awesome. This reads the 10_in-addr_arpa.zone.mx file for us, and replaces from the appropriate &#8220;$INCLUDE&#8221; start to end with the contents of said file.</div>
<p>&nbsp;</p>
<div>Another issue I ran into was having the generate the appropriate reverse-entry zones for all the public IP netblocks, and with two /21s and a /18 to worry about I wasn&#8217;t planning to do myself if I could help it, so I employed a quick hack with ipcalc and dnspython to transform my /18 into its various component /24s, and then generate reverses:</div>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">ipcalc 11.22.33.0/18 /24 | grep 'Network.*/24' | awk '{print $2}' | cut -d&quot;/&quot; -f 1<br />
11.22.0.0<br />
11.22.1.0<br />
11.22.2.0<br />
...</div></td></tr></tbody></table></div>
<div>We can then easily manipulate these in python or sed or cut, depending on how hacky we feel, but I went with python since I was already using MySQLdb to insert the records after massaging them into the right form.</div>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&amp;gt;&amp;gt;&amp;gt; import dns.reversename<br />
&amp;gt;&amp;gt;&amp;gt; range = &quot;10.22.0.0&quot;<br />
&amp;gt;&amp;gt;&amp;gt; print dns.reversename.from_address(range).to_text().split(&quot;.&quot;,1)[1]<br />
0.22.10.in-addr.arpa.</div></td></tr></tbody></table></div>
<div>And that&#8217;s it for somewhat useful little tricks. There was a bit of a discussion had about delimited formats like this, and Piet Delport (see blogroll) hacked up a neat little delimited datatype which you can find over <a href="http://elegua.za.net/~froztbyte/delimited.py">here</a>. Quick usage instructions:</div>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&amp;gt;&amp;gt;&amp;gt; d = delimited('foo.bar.baz', '.'); d.sort(); print d<br />
bar.baz.foo<br />
d[1:] -&amp;gt; 'bar.baz'<br />
d[1:2] = ['x', 'y', 'z']; d -&amp;gt; 'foo.x.y.z.baz'<br />
&amp;gt;&amp;gt;&amp;gt; d = delimited('0.2.1.10.in-addr.arpa', '.'); del d[0]; print d<br />
2.1.10.in-addr.arpa.</div></td></tr></tbody></table></div>
<div>And now as the sounds of Mogwai, Flunk and Placebo massage my tired noggin, it&#8217;s time for me to go to bed.</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.froztbyte.net/2011/08/dns-platform-migration-fun/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
