<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" xml:lang="pl"><title>nme.pl/en</title><link href="http://nme.pl" rel="alternate" /><id>http://nme.pl</id><updated>2012-02-05T05:27:02Z</updated><subtitle>nme.pl</subtitle><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/nmepl_en" /><feedburner:info uri="nmepl_en" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry><title>Multiple arguments in Django template filters</title><link href="http://feedproxy.google.com/~r/nmepl_en/~3/EHunM2gImhE/multiple-arguments-in-django-template-filters" rel="alternate" /><id>http://nme.pl/en/2011/07/multiple-arguments-in-django-template-filters</id><summary type="html">&lt;p&gt;By default, it is not currently possible to pass multiple arguments to Django template filter - &lt;a href="http://docs.djangoproject.com/en/dev/howto/custom-template-tags/"&gt;documentation&lt;/a&gt; states: &lt;span style="color:#777;font-style:italic"&gt;"Custom filters are just Python functions that take one or two arguments"&lt;/span&gt;.&lt;/p&gt;

&lt;p&gt;Here I describe solution that allows passing more arguments.&lt;/p&gt;

&lt;p&gt;Lets say we have &lt;code&gt;key&lt;/code&gt; and current &lt;code&gt;query_string&lt;/code&gt; in our template context. We loop in paginator and alter query_string current key value with &lt;code&gt;page&lt;/code&gt;. The key is to group arguments in an array. We use following custom filter:&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
@register.filter
def keys (first,second):
    if isinstance(first,list):
        return first+[second]
    else:
        return [first,second]
&lt;/pre&gt;

&lt;p&gt;following filter allows us to:&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
{{ "1"|keys:"2"|keys:"3" }}
&lt;/pre&gt;

&lt;p&gt;which will return in our template:&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
[u'1', u'2', u'3']
&lt;/pre&gt;

&lt;p&gt;Returning to described query_string altering problem - we use &lt;code&gt;alter_query&lt;/code&gt; filter:&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
@register.filter
def alter_query (keys, query_string):
    from django.http import QueryDict
    query_dict = QueryDict(query_string, mutable=True)
    query_dict[keys[0]] = keys[1]
    return query_dict.urlencode()
&lt;/pre&gt;

&lt;p&gt;inside pagination template, we use following code:&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
&amp;lt;a href="?{{ key|keys:page|alter_query:query_string }}"&amp;gt;{{ page }}&amp;lt;/a&amp;gt;
&lt;/pre&gt;

&lt;p&gt;Doesn't look pretty, but works perfectly.&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/nmepl_en/~4/EHunM2gImhE" height="1" width="1"/&gt;</summary><feedburner:origLink>http://nme.pl/en/2011/07/multiple-arguments-in-django-template-filters</feedburner:origLink></entry><entry><title>hv - kvm virtualization swiss knife (requires kvm-admin)</title><link href="http://feedproxy.google.com/~r/nmepl_en/~3/MR5eHnMA07I/hv-kvm-virtualization-swiss-knife" rel="alternate" /><id>http://nme.pl/en/2011/02/hv-kvm-virtualization-swiss-knife</id><summary type="html">&lt;img class="post-image" src="/img/2011/02/virtualization.jpg" alt="" /&gt;
&lt;p&gt;&lt;a href="http://www.linux-kvm.org/"&gt;Kvm&lt;/a&gt; is currently one of best choices for virtualization under GNU Linux operating systems. It is fast and stable. No wonder there are many frontend utilities that handles it. &lt;/p&gt;

&lt;p&gt;RedHat Enterprise Linux and Ubuntu Server Linux are both suggesting to relay on &lt;a href="http://libvirt.org/"&gt;libvirt&lt;/a&gt;, but whenever I try to use that I always finish with "It is not good enough yet", "new features come, old bugs still exist" etc. As I suppose - it will never be good enough. The reason is the &lt;code&gt;libvirt&lt;/code&gt; layer which completly separates system administrator from kvm console.&lt;/p&gt;

&lt;p&gt;In opposition to libvirt - we can use kvm and qemu tools, but sooner or later we will start to look after another toolkit to make life easier. I found mine - &lt;a href="http://www.linux-kvm.org/page/Kvmtools"&gt;kvmtools&lt;/a&gt; - it is slick, lightweight, written in Python language and offers possibility to perform most tasks using single command. It is really great, but... I don't like &lt;code&gt;kvm-admin&lt;/code&gt; command syntax. That is why I created &lt;code&gt;hv&lt;/code&gt; - simple bash script that makes &lt;code&gt;kvm-admin&lt;/code&gt; more friendly - especially - for (former) &lt;code&gt;virsh&lt;/code&gt; users.&lt;/p&gt;

&lt;div class="footnotes"&gt;Mercurial repository for &lt;code&gt;hv&lt;/code&gt; util is available &lt;a href="/pub/repos/hv"&gt;here&lt;/a&gt;.&lt;br /&gt;
You can download it using the following command:
&lt;code&gt;hg clone http://nme.pl/pub/repos/hv&lt;/code&gt;
&lt;/div&gt;

&lt;pre class="green"&gt;
hv&lt;br /&gt;
Usage:&lt;br /&gt;
	hv (list|running)
	hv (boot|bootp|reboot|kill) domain-name (bootp = boot domain-name, but keep it in paused state)
	hv (vnc|vncinfo) domain-name
	hv serial domain-name
	hv monitor domain-name qemu-monitor-command
	hv (pause|cont|status) domain-name
	hv edit domain-name
	hv snapshots domain-name
	hv (savevm|loadvm|delvm|bootvm) domain-name snapshot-name
	hv shutdown domain-name
	hv verify
	hv example-domain&lt;br /&gt;
	Commands might be shortened, eg. hv li
&lt;/pre&gt;

&lt;h4&gt;What does hv offer?&lt;/h4&gt;

&lt;p&gt;List of all commands with examples, like mentioned in hv usage above - it is possible to shorten commands, as long as they are unambiguous. &lt;code&gt;hv&lt;/code&gt; offers as much syntatic sweetness as I could figure out ;)&lt;/p&gt;

&lt;p&gt;More verbose help:&lt;/p&gt;
&lt;table&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;hv list&lt;/code&gt;&lt;/td&gt;&lt;td&gt;list all available virtual machines.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;hv running&lt;/code&gt;&lt;/td&gt;&lt;td&gt;list running virtual machines.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;hv boot domain-name&lt;/code&gt;&lt;/td&gt;&lt;td&gt;start given virtual machine.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;hv bootp domain-name&lt;/code&gt;&lt;/td&gt;&lt;td&gt;start given virtual machine in a paused state.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;hv reboot domain-name&lt;/code&gt;&lt;/td&gt;&lt;td&gt;warm reboot virtual machine.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;hv kill domain-name&lt;/code&gt;&lt;/td&gt;&lt;td&gt;power off virtual machine.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;hv vnc domain-name&lt;/code&gt;&lt;/td&gt;&lt;td&gt;connect vncviewer with virtual machine (and keep it turning on when it disconnects - in case of resolution change etc, ^C breakable).&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;hv vncinfo domain-name&lt;/code&gt;&lt;/td&gt;&lt;td&gt;return vnc listen ip:port.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;hv serial domain-name&lt;/code&gt;&lt;/td&gt;&lt;td&gt;connect to serial tty of virtual machine.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;hv monitor domain-name qemu-monitor-command&lt;/code&gt;&lt;/td&gt;&lt;td&gt;kvm monitor interface - if no monitor-command is given, issuing help command will be suggested.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;hv pause domain-name&lt;/code&gt;&lt;/td&gt;&lt;td&gt;freeze virtual machine.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;hv cont domain-name&lt;/code&gt;&lt;/td&gt;&lt;td&gt;continue feezed virtual machine.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;hv status domain-name&lt;/code&gt;&lt;/td&gt;&lt;td&gt;virtual machine status.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;hv edit domain-name&lt;/code&gt;&lt;/td&gt;&lt;td&gt;same as vim /etc/kvm/domain/name.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;hv snapshots domain-name&lt;/code&gt;&lt;/td&gt;&lt;td&gt;list current virtual-machine snapshots.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;hv savevm domain-name snapshot-name&lt;/code&gt;&lt;/td&gt;&lt;td&gt;create snapshot for virtual-machine&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;hv loadvm domain-name snapshot-name&lt;/code&gt;&lt;/td&gt;&lt;td&gt;apply (load) snapshot for virtual-machine&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;hv delvm domain-name snapshot-name&lt;/code&gt;&lt;/td&gt;&lt;td&gt;delete snapshot&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;hv bootvm domain-name snapshot-name&lt;/code&gt;&lt;/td&gt;&lt;td&gt;boot domain and apply (load) snapshot&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;hv shutdown domain-name&lt;/code&gt;&lt;/td&gt;&lt;td&gt;gracefully shutdown virtual machine (requires acpid / acpi support on virtual-machine).&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;hv verify&lt;/code&gt;&lt;/td&gt;&lt;td&gt;simplifies manual check of all virtual machines configuration - disks, mac addresses, tap interfaces and vnc ports.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;hv example-domain&lt;/code&gt;&lt;/td&gt;&lt;td&gt;bootstrap configuration of virtual machine, eg. hv example &amp;gt;/etc/kvm/domain/new-vm&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;

&lt;h4&gt;Feedback?&lt;/h4&gt;

&lt;p&gt;As usual - every opinion and suggestion is appreciated!&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/nmepl_en/~4/MR5eHnMA07I" height="1" width="1"/&gt;</summary><feedburner:origLink>http://nme.pl/en/2011/02/hv-kvm-virtualization-swiss-knife</feedburner:origLink></entry><entry><title>Upgrading Postgres 8.4 to 9.0 - Ubuntu / GNU Debian step by step</title><link href="http://feedproxy.google.com/~r/nmepl_en/~3/r7hL7sLMmiQ/upgrading-postgres-84-to-90-ubuntu-gnu-debian" rel="alternate" /><id>http://nme.pl/en/2011/02/upgrading-postgres-84-to-90-ubuntu-gnu-debian</id><summary type="html">&lt;p&gt;If your &lt;code&gt;safe-upgrade&lt;/code&gt; just upgraded your postgresql to 9.0, your databases probably does not work and there is no postgresql-8.4 in your system. It is an unfortunate behavior, but we can simply migrate our data to new Postgres, here is how:&lt;/p&gt;

&lt;p&gt;First, install your old postgres 8.4:&lt;/p&gt;

&lt;pre&gt;
&lt;code&gt;sudo -i&lt;/code&gt;
&lt;code&gt;aptitude install postgresql-8.4&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;Stop all services using postgres databases and make backup of all databases and roles:&lt;/p&gt;

&lt;pre&gt;
&lt;code&gt;su&amp;nbsp;- postgres&lt;/code&gt;
&lt;code&gt;pg_dumpall &gt;migration&lt;/code&gt;
&lt;code&gt;exit&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;Make copy of your data (just to be sure you have backup):&lt;/p&gt;

&lt;pre&gt;
&lt;code&gt;cp ~postgres/migration /root/&lt;/code&gt;
&lt;/pre&gt;

Purge old Postgres 8.4 and install Postgres 9.0:

&lt;pre&gt;
&lt;code&gt;aptitude purge postgresql-8.4&lt;/code&gt;
&lt;code&gt;aptitude install postgresql-9.0&lt;/code&gt;
&lt;/pre&gt;

Get all of your data back to Postgres:

&lt;pre&gt;
&lt;code&gt;su&amp;nbsp;- postgres&lt;/code&gt;
&lt;code&gt;psql &amp;lt;migration&lt;/code&gt;
&lt;code&gt;exit&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;Turn your services back online, check if everything works again - if it does, remove migration data from postgres user and make a bz2 compressed archive containing all databases and roles:&lt;/p&gt;

&lt;pre&gt;
&lt;code&gt;rm ~postgres/migration&lt;/code&gt;
&lt;code&gt;bzip2 migration&lt;/code&gt;
&lt;code&gt;mv migration.bz2 `date +%Y-%m-%d`-migration.bz2&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;Keep that backup for a while until you will be sure that is safe to delete it.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/nmepl_en/~4/r7hL7sLMmiQ" height="1" width="1"/&gt;</summary><feedburner:origLink>http://nme.pl/en/2011/02/upgrading-postgres-84-to-90-ubuntu-gnu-debian</feedburner:origLink></entry><entry><title>Real-time graph using Javascript</title><link href="http://feedproxy.google.com/~r/nmepl_en/~3/3KsEyEvRmVI/real-time-graph-using-javascript" rel="alternate" /><id>http://nme.pl/en/2011/01/real-time-graph-using-javascript</id><summary type="html">&lt;p class="footnotes"&gt;Post below describes solution which requires Raphaël JS to draw graph using SVG.&lt;br /&gt;I've also made a cleaner version - &lt;a href="http://nme.pl/example/canvas-graph/"&gt;html5 canvas real-time graph&lt;/a&gt; - enjoy!&lt;/p&gt;

&lt;p&gt;This idea was wandering through my mind for quite some time now, and finally I got a project I'm working on where it will be perfect to fit. That is why I decided to try to put this idea to the test. Suprisingly, it works :)&lt;/p&gt;

&lt;p&gt;I was never a fan of Flash technology which would solve real-time graphing very fast so I had to pick Javascript libraries that will do the work. One of them is jQuery, because I like to have clean code. The other is &lt;a href="http://raphaeljs.com/"&gt;Raphaël JS&lt;/a&gt; - Javascript library which aims allowing web developers to draw using SVG.&lt;/p&gt;

&lt;p&gt;So, here is the effect of "step" scrolling:&lt;/p&gt;

&lt;script type="text/javascript" src="/example/svg-graph/step_graph.js"&gt;&lt;/script&gt;
&lt;div style="margin:1.5em auto;width:200px"&gt;&lt;p id="animatedgraph-demo" style="text-align:center"&gt;&lt;img src="/img/2011/01/svg-graph.png" alt="SVG graph preview" /&gt;&lt;br /&gt;&lt;em&gt;See a &lt;a href="http://nme.pl/en/2011/01/real-time-graph-using-javascript"&gt;working example&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;&lt;/div&gt;

&lt;p class="footnotes"&gt;&lt;a href="/example/svg-graph/"&gt;Full sources&lt;/a&gt; are published and dual licensed under MIT and GPL. The above example is called &lt;code&gt;step.html&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;As an alternative, there is also &lt;a href="/example/svg-graph/smooth.html"&gt;"smooth" scrolling example&lt;/a&gt; included, but unfortunately - it makes web browser to consume 100% time of one CPU core. It might not be a problem on a desktop computer, but some older laptops will most likely "feel" the issue. If you know how to solve the problem - please let me know.&lt;/p&gt;

The actual source code consists of three parts:

&lt;h4&gt;animatedGraph jQuery plugin&lt;/h4&gt;

&lt;pre class="prettyprint"&gt;
// animatedGraph jQuery plugin, requires jQuery and Raphael libraries
(function($) {
    $.fn.extend({
        animatedGraph: function(width, height, steps, max, single, many, ms) {
            var path = function(array, step, left) {
                var scale = height/max,
                    path = '',          
                    x=-left,            
                    y=0;                
                for (var i=0;i&amp;lt;array.length;i++) {
                    if (i) {            
                        path += "S" + [(x += step), (y = height - array[i]*scale), x, y];
                    } else {            
                        path += "M" + [-10, (y = height - array[i]*scale)]; 
                        path += "C" + [0, (y = height - array[i]*scale)]; 
                    }                   
                }               
                return path+'L'+(array.length*step+10)+','+(height+10)+' '+(-10)+','+(height+10)+'+z';
            };          
            return this.each(function() {
                var self = this;
                self.step = width/(steps-1);
                $(self)         
                    .css('width',width+'px')
                    .css('height',height+'px');
                self.r = Raphael(self, width, height); 
                self.data = many(steps);
                self.path = self.r.path(path(self.data, self.step, 0))
                    .attr({             
                        stroke: '#66f',         
                        fill: '#ddf',           
                        'stroke-width': 2,      
                        'clip-rect': ''+[0,0,width-1,height]
                    });                 
                setInterval(function() {
                    self.data.shift();  
                    self.data.push(single());
                    self.path.animate({path:path(self.data, self.step, 0)});
                }, ms);         
            });         
        }       
    }); 
})(jQuery);
&lt;/pre&gt;

&lt;h4&gt;Pseudo-random source data generator&lt;/h4&gt;

&lt;pre class="prettyprint"&gt;
// rotating across pseudo-random values array
var Rotator = function() {
    var self = this;
    self.data = [ 
        16,23,41,38,45,31,29,22,27,22,25,29,32,45,88,30,
        26,22,45,23,36,48,99,22,32,26,22,27,5,0,0,3,15
    ];  
    self.index = 0;
    self.single = function() {
        self.index += 1;
        if (self.index &amp;gt; self.data.length) {
            self.index = 1;
        }       
        return self.data[self.index-1];
    };  
    self.many = function(length) {
        var results = [];
        for (var i=0;i&amp;lt;length;i++) {
            results.push(self.single());
        }       
        return results;
    };  
};
&lt;/pre&gt;

&lt;h4&gt;The main function&lt;/h4&gt;

&lt;pre class="prettyprint"&gt;
$(document).ready(function() {

    var self = this;

    $('#animatedgraph-demo')
        .replaceWith(function() {
            return $('&amp;lt;div id="animatedgraph-demo"&amp;gt;&amp;lt;/div&amp;gt;');
        });     

    var rotator = new Rotator();

    $('#animatedgraph-demo')
        .animatedGraph(200, 50, 20, 100, rotator.single, rotator.many, 1000);

});
&lt;/pre&gt;
&lt;img src="http://feeds.feedburner.com/~r/nmepl_en/~4/3KsEyEvRmVI" height="1" width="1"/&gt;</summary><feedburner:origLink>http://nme.pl/en/2011/01/real-time-graph-using-javascript</feedburner:origLink></entry><entry><title>Django application development</title><link href="http://feedproxy.google.com/~r/nmepl_en/~3/5U4XhKfQ2gs/django-application-development" rel="alternate" /><id>http://nme.pl/en/2010/07/django-application-development</id><summary type="html">&lt;p&gt;Most developers work on their startups far away from the daylight - they keep it in complete secret till the end. I've decided to do something new - I have started a project which is available to preview during the whole development. It is available at &lt;a href="http://urevs.com/"&gt;urevs.com&lt;/a&gt;. I also share all the project info on dedicated blog: &lt;a href="http://blog.urevs.com/"&gt;blog.urevs.com&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This project consists currently of authentication framework and a lot of backend solutions. Site allows users to login using OpenID's, Google, Twitter, Facebook or Yahoo Accounts. Full details are available here - &lt;a href=" http://blog.urevs.com/2010/07/19/social-bootstrap-engine-for-django/"&gt;social bootstrap engine for Django&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I'd be very glad to hear from You, about every suggestion You have.&lt;/p&gt;

&lt;a href="http://blog.urevs.com/"&gt;&lt;img class="center" title="openid-auth" src="/img/2010/07/openid-auth.png" alt="" width="467" height="106" /&gt;&lt;/a&gt;

&lt;div class="footnotes-red"&gt;urevs.com has been dropped. I've merged its functionality into this blog site but it is not currently available to public.&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/nmepl_en/~4/5U4XhKfQ2gs" height="1" width="1"/&gt;</summary><feedburner:origLink>http://nme.pl/en/2010/07/django-application-development</feedburner:origLink></entry><entry><title>Ubuntu: which package a file belongs to?</title><link href="http://feedproxy.google.com/~r/nmepl_en/~3/4hyOw2rlaK0/ubuntu-which-package-a-file-belongs-to" rel="alternate" /><id>http://nme.pl/en/2010/07/ubuntu-which-package-a-file-belongs-to</id><summary type="html">&lt;p&gt;Some of us dont know this command, so:&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
nme@werewolf ~ $ &lt;code&gt;dpkg -S /usr/bin/ffmpeg 
ffmpeg: /usr/bin/ffmpeg&lt;/code&gt;
nme@werewolf ~ $ 
&lt;/pre&gt;

&lt;p&gt;or&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
nme@werewolf ~ $ &lt;code&gt;dpkg -S `which gcc`
gcc: /usr/bin/gcc&lt;/code&gt;
nme@werewolf ~ $ 
&lt;/pre&gt;

&lt;p&gt;or&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
nme@werewolf ~ $ &lt;code&gt;dpkg -S *bash 
xz-utils: /usr/share/doc/xz-utils/extra/7z2lzma/7z2lzma.bash
bash: /usr/share/menu/bash
util-linux: /usr/share/doc/util-linux/examples/getopt-test.bash
util-linux: /usr/share/doc/util-linux/examples/getopt-parse.bash
bash: /bin/bash
apparmor: /etc/apparmor.d/abstractions/bash
bash: /bin/rbash
bash-completion, bash: /usr/share/doc/bash
global: /usr/bin/globash&lt;/code&gt;
nme@werewolf ~ $ 
&lt;/pre&gt;

&lt;p&gt;You know smarter way? Add Your comment!&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/nmepl_en/~4/4hyOw2rlaK0" height="1" width="1"/&gt;</summary><feedburner:origLink>http://nme.pl/en/2010/07/ubuntu-which-package-a-file-belongs-to</feedburner:origLink></entry><entry><title>IPv4 CIDR to netmask in Python</title><link href="http://feedproxy.google.com/~r/nmepl_en/~3/k74ets3SAj4/ipv4-cidr-to-netmask-in-python" rel="alternate" /><id>http://nme.pl/en/2010/05/ipv4-cidr-to-netmask-in-python</id><summary type="html">&lt;p&gt;I needed small function to validate IPv4 netmasks, havent found one, so I wrote my own. I've decided to use &lt;a href="http://infocenter.guardiandigital.com/manuals/IDDS/node9.html"&gt;IPv4 CIDR notation&lt;/a&gt; to get corresponding netmasks. Here is the code:&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
def ipv4_cidr_to_netmask(bits):

    """ Convert CIDR bits to netmask """

    netmask = ''
    for i&lt;b&gt;&lt;/b&gt; in range(4):
        if i:
            netmask += '.'
        if bits &gt;= 8:
            netmask += '%d' % (2**8-1)
            bits -= 8
        else:
            netmask += '%d' % (256-2**(8-bits))
            bits = 0
    return netmask
&lt;/pre&gt;

&lt;p&gt;Example usage is presented below. They also show how lambda mappings are useful in regular, daily use.&lt;/p&gt;

&lt;h4&gt;List all possible netmasks:&lt;/h4&gt;

&lt;pre class="prettyprint"&gt;
for netmask in map(lambda x: ipv4_cidr_to_netmask(x), range(0,33)):
    print netmask

0.0.0.0
128.0.0.0
192.0.0.0
224.0.0.0
240.0.0.0
248.0.0.0
252.0.0.0
254.0.0.0
255.0.0.0
255.128.0.0
255.192.0.0
255.224.0.0
255.240.0.0
255.248.0.0
255.252.0.0
255.254.0.0
255.255.0.0
255.255.128.0
255.255.192.0
255.255.224.0
255.255.240.0
255.255.248.0
255.255.252.0
255.255.254.0
255.255.255.0
255.255.255.128
255.255.255.192
255.255.255.224
255.255.255.240
255.255.255.248
255.255.255.252
255.255.255.254
255.255.255.255
&lt;/pre&gt;

&lt;h4&gt;Get netmask for /24:&lt;/h4&gt;

&lt;pre class="prettyprint"&gt;
print ipv4_cidr_to_netmask(24)

255.255.255.0
&lt;/pre&gt;

&lt;h4&gt;Is 255.255.254.0 valid IPv4 netmask?&lt;/h4&gt;

&lt;pre class="prettyprint"&gt;
print "255.255.254.0" in map(lambda x: ipv4_cidr_to_netmask(x), range(0,33))

True
&lt;/pre&gt;

&lt;h4&gt;Reverse search - get CIDR for 255.255.192.0 netmask&lt;/h4&gt;

&lt;pre class="prettyprint"&gt;
print map(lambda x: ipv4_cidr_to_netmask(x), range(0,33)).index('255.255.254.0')

23
&lt;/pre&gt;
&lt;p&gt;
As usual - enjoy :)&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/nmepl_en/~4/k74ets3SAj4" height="1" width="1"/&gt;</summary><feedburner:origLink>http://nme.pl/en/2010/05/ipv4-cidr-to-netmask-in-python</feedburner:origLink></entry><entry><title>Simple Wordpress plugin debugging</title><link href="http://feedproxy.google.com/~r/nmepl_en/~3/IZpbJUuK4Qc/simple-wordpress-plugin-debugging" rel="alternate" /><id>http://nme.pl/en/2010/05/simple-wordpress-plugin-debugging</id><summary type="html">&lt;p&gt;I'd like to present simplest way I know to debug Wordpress plugins. It is a method I was using developing &lt;a href="/en/2010/05/wordpress-plugin-to-redirect-or-cloak-urls/"&gt;plugin to cloak URL&lt;/a&gt;'s described earlier.&lt;/p&gt;

&lt;p&gt;Below You can find the most minimalistic example plugin code possible - all it does is log &lt;code&gt;REQUEST_URI&lt;/code&gt; to our debug file located at &lt;code&gt;wp-content/plugins/debug&lt;/code&gt;. Row by row. Dirty and simple - and the most important - it does &lt;strong&gt;not require&lt;/strong&gt; us to switch our Wordpress to  debug mode.&lt;/p&gt;

&lt;p&gt;Plugin consists of three parts - plugin description header, debugging function and hook to &lt;code&gt;main&lt;/code&gt; function which is executed right before page is rendered.&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
&amp;lt;?php
/*
Plugin Name: test
Plugin URI:
Description:
Version:
Author:
Author URI:
*/

function debug($msg)
{
        $fp = fopen('wp-content/plugins/debug', 'a');
        fwrite($fp, $msg."\n");
        fclose($fp);
}

function main()
{
        debug($_SERVER['REQUEST_URI']);
}

add_action('init', 'main');

?&amp;gt;
&lt;/pre&gt;

&lt;p&gt;Of course the most important part of the code is &lt;code&gt;debug&lt;/code&gt; function which stores results we need to verify to our debug file.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/nmepl_en/~4/IZpbJUuK4Qc" height="1" width="1"/&gt;</summary><feedburner:origLink>http://nme.pl/en/2010/05/simple-wordpress-plugin-debugging</feedburner:origLink></entry><entry><title>jQuery-UI themeselect widget published</title><link href="http://feedproxy.google.com/~r/nmepl_en/~3/AfjJatXbCos/jquery-ui-themeselect-widget-published" rel="alternate" /><id>http://nme.pl/en/2010/05/jquery-ui-themeselect-widget-published</id><summary type="html">&lt;img class="post-image" title="screenshot" src="/img/2010/05/screenshot-150x150.png" alt="" width="150" height="150" /&gt;

&lt;p&gt;&lt;/a&gt;I've recently published jQuery-UI &lt;a href="http://code.google.com/p/ui-themeselect/"&gt;themeselect&lt;/a&gt; widget allowing users to add friendly looking, themable dropdown to instant theme switch.&lt;/p&gt;

&lt;p&gt;In oppose to standard jQuery-UI themeswitcher, this one looks exacly like the rest of the theme.&lt;/p&gt;

&lt;p&gt;My ui-themeselect has been published on &lt;a href="http://www.opensource.org/licenses/bsd-license.php"&gt;New BSD License&lt;/a&gt; making it freely available and the code is hosted at Google Code. If You are familiar with Mercurial, you can clone the repository using command below:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;hg clone https://ui-themeselect.googlecode.com/hg/ ui-themeselect&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I have ripped the code out from my own Django / Google App Engine applications development Javascript bootstrap, because I think that someone else might consider it useful.&lt;/p&gt;

&lt;p&gt;As an example how can it look inside jQuery-UI themed interface, take a look at this screenshot taken from one of my apps:&lt;/p&gt;

&lt;p style="margin: 0.4em 0;"&gt;&lt;/p&gt;

&lt;img class="center" title="themeselect-usage" src="/img/2010/05/themeselect-usage.png" alt="" width="400" height="349" /&gt;

&lt;p style="margin: 0.7em 0;"&gt;Enjoy! :)&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/nmepl_en/~4/AfjJatXbCos" height="1" width="1"/&gt;</summary><feedburner:origLink>http://nme.pl/en/2010/05/jquery-ui-themeselect-widget-published</feedburner:origLink></entry><entry><title>Wordpress plugin to redirect or cloak URL's</title><link href="http://feedproxy.google.com/~r/nmepl_en/~3/eurEza7g86E/wordpress-plugin-to-redirect-or-cloak-urls" rel="alternate" /><id>http://nme.pl/en/2010/05/wordpress-plugin-to-redirect-or-cloak-urls</id><summary type="html">&lt;p&gt;After few unsuccessful searches for &lt;strong&gt;free&lt;/strong&gt; Wordpress plugin that would allow me to cloak URL's on my blog - I decided to write my own. It was not really hard. I'm publishing it on &lt;a href="http://www.gnu.org/licenses/gpl.html"&gt;GPLv3&lt;/a&gt; license.&lt;/p&gt;

&lt;p&gt;Plugin is really simple - full code consists of 75 lines of code. It &lt;strong&gt;does not&lt;/strong&gt; contain database support, hits counting nor wp-admin interface. If some of You will like to extend it including those features - please do it and inform me - I will be first betatester :)&lt;/p&gt;

&lt;p&gt;Plugin assumes that You already accomplished redirecting URL's to Wordpress subsystem that You would like to be handled by Wordpress in a different way.&lt;/p&gt;

&lt;p&gt;There are three possible kinds of URL threating:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Permanent redirect - typical &lt;code&gt;HTTP 301 redirect&lt;/code&gt;&lt;/li&gt;
	&lt;li&gt;Temporary redirect - typical &lt;code&gt;HTTP 302 redirect&lt;/code&gt;&lt;/li&gt;
	&lt;li&gt;Local cloak - &lt;strong&gt;it works only on Your blog web page&lt;/strong&gt; (thats why it is called local) - it will hide real destination URL leaving it cloaked&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;How does it work?&lt;/h4&gt;

&lt;p&gt;The core of the plugin source is pasted below. Maybe some of You will consider it as interesting :) The most unfortunate part of the plugin is need to use &lt;code&gt;/wp-admin/plugins.php&lt;/code&gt; &lt;code&gt;Edit plugin&lt;/code&gt; feature to manually change URL's. Those are listed inside &lt;code&gt;$redirect&lt;/code&gt; variable.&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
define('PERMANENT_REDIRECT',301);
define('TEMPORARY_REDIRECT',302);
define('LOCAL_CLOAK',1);

$redirects = array(
  # source match         TYPE                           destination url
  # /u
  "^/u$" =&amp;gt;              array(TEMPORARY_REDIRECT,      "/u/"),
  "^/u/(.*)$" =&amp;gt;         array(LOCAL_CLOAK,             "/category/u/$1"),
}

function url_cloaker()
{
    global $redirects;
    $src_url = $_SERVER['REQUEST_URI'];
    foreach ($redirects as $src =&amp;gt; $dst) {
        $src = str_replace('/','\/',$src);
        if (preg_match('/'.$src.'/',$src_url)) {
            #__d('Matched: '.$src);
            $dst_url = preg_replace('/'.$src.'/', $dst[1], $src_url);
            switch ($dst[0]) {
                case PERMANENT_REDIRECT:
                    wp_redirect($dst_url, PERMANENT_REDIRECT);
                    exit;
                case TEMPORARY_REDIRECT:
                    wp_redirect($dst_url, TEMPORARY_REDIRECT);
                    exit;
                case LOCAL_CLOAK:
                    $_SERVER['REQUEST_URI'] = $dst_url;
                    break;
            }
        }
    }
}

add_action('init', 'url_cloaker');
&lt;/pre&gt;

&lt;p&gt;Plugin use actions hooking framework inside Wordpress to make sure it is fired before page is shown.&lt;/p&gt;

&lt;div class="footnotes"&gt;&lt;em&gt;The plugin is available &lt;a href="/pub/url-cloaker-wordpress-plugin/url-cloaker.phps"&gt;here&lt;/a&gt; for download.&lt;/em&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/nmepl_en/~4/eurEza7g86E" height="1" width="1"/&gt;</summary><feedburner:origLink>http://nme.pl/en/2010/05/wordpress-plugin-to-redirect-or-cloak-urls</feedburner:origLink></entry><entry><title>How to add IMQ patch to Ubuntu 10.04 Lucid Lynx</title><link href="http://feedproxy.google.com/~r/nmepl_en/~3/tSj3hZ7ZdK0/how-to-add-imq-patch-to-ubuntu-10-04-lucid-lynx" rel="alternate" /><id>http://nme.pl/en/2010/05/how-to-add-imq-patch-to-ubuntu-10-04-lucid-lynx</id><summary type="html">&lt;img class="post-image" style="margin-top: -30px; margin-right: -25px;" title="ipt_limit" src="/img/2010/05/ipt_limit.png" alt="" width="302" height="182" /&gt;

&lt;p&gt;Those of you, who are having problems adding IMQ support to recent Ubuntu/Debian release, might consider this blog entry useful :)&lt;/p&gt;

&lt;p&gt;I will not discuss &lt;a href="http://wiki.nix.hu/cgi-bin/twiki/view/IMQ/ImqFaq#Use_of_IMQ"&gt;what IMQ is&lt;/a&gt; and wheater is it good or bad - I will describe how to prepare kernel, iptables packages and how to deploy them to our Debian/Ubuntu system including taking care of making them immune to accidential system upgrade packages replacement.&lt;/p&gt;

&lt;h4&gt;Kernel package with IMQ support&lt;/h4&gt;

&lt;p&gt;Before we start - we need few packages that will might be required:&lt;/p&gt;

&lt;code&gt;sudo aptitude install fakeroot build-essential kernel-package ncurses-dev&lt;/code&gt;

&lt;p&gt;Now we are ready to start: first, we need our current kernel with distro patches. For desktop instance I would use &lt;code&gt;-generic&lt;/code&gt; instead of &lt;code&gt;-server&lt;/code&gt;:&lt;/p&gt;

&lt;code&gt;apt-get source linux-image-2.6.32-22-server&lt;/code&gt;

Now, we download imq patch, apply it and compile kernel:

&lt;pre class="prettyprint"&gt;
wget http://linuximq.net/patchs/linux-2.6.32-imq-test2.diff

cd linux-2.6.32/

patch -p1 &amp;lt; ../linux-2.6.32-imq-test2.diff

fakeroot time make-kpkg --initrd --append_to_version=imq linux-image
&lt;/pre&gt;

During the compilation process, make-kpkg script will discover unanswered features that we need to check as modules:

&lt;pre&gt;
  "IMQ" target support (NETFILTER_XT_TARGET_IMQ) [N/m/?] (NEW) &lt;code&gt;m&lt;/code&gt;

  IMQ (intermediate queueing device) support (IMQ) [M/y/?] (NEW) &lt;code&gt;M&lt;/code&gt;

    IMQ behavior (PRE/POSTROUTING)

      1. IMQ AA (IMQ_BEHAVIOR_AA) (NEW)

    &amp;gt; 2. IMQ AB (IMQ_BEHAVIOR_AB) (NEW)

      3. IMQ BA (IMQ_BEHAVIOR_BA) (NEW)

      4. IMQ BB (IMQ_BEHAVIOR_BB) (NEW)

    choice[1-4?]: &lt;code&gt;2&lt;/code&gt;

    Number of IMQ devices (IMQ_NUM_DEVS) [16] (NEW)
&lt;/pre&gt;

&lt;p&gt;Finally... in parent directory we will find:&lt;/p&gt;

linux-image-2.6.32.11+drm33.2imq_2.6.32.11+drm33.2imq-10.00.Custom_i386.deb

&lt;p&gt;If everything went fine and our package is present - we can clean up compiled object files that will not be required anymore, recovering few GB of hard disk space:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;./debian/rules clean&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;in case You forget to generate &lt;code&gt;initrd&lt;/code&gt; file, it always might be generated by hand:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo -i&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;cd /boot/&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;mkinitramfs-kpkg -o initrd.img-2.6.32.11+drm33.2imq 2.6.32.11+drm33.2imq&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;update-grub&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;Iptables package with IMQ support&lt;/h4&gt;

&lt;p&gt;First, the patch - there is no iptables-1.4.4 imq patch available on &lt;a href="http://linuximq.net"&gt;linuximq.net&lt;/a&gt; I'm afraid. I have used iptables-1.4.6-imq patch and fixed it to compile with iptables-1.4.4.&lt;/p&gt;

&lt;p&gt;Original patch can be found &lt;a href="http://linuximq.net/patchs/iptables-1.4.6-imq.diff"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Changes:&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
diff -Naurw iptables-1.4.6-imq.diff iptables-1.4.4-imq.diff
--- iptables-1.4.6-imq.diff	2010-01-27 11:53:22.000000000 +0100
+++ iptables-1.4.4-imq.diff	2010-05-08 13:18:21.000000000 +0200
@@ -43,7 +43,7 @@
 +
 +	switch(c) {
 +	case '1':
-+		if (xtables_check_inverse(optarg, &amp;amp;invert, NULL, 0, argv))
++		if (xtables_check_inverse(optarg, &amp;amp;invert, 0, argv))
 +			xtables_error(PARAMETER_PROBLEM,
 +				   "Unexpected `!' after --todev");
 +		mr-&amp;gt;todev=atoi(optarg);
&lt;/pre&gt;

&lt;p&gt;Ready to use patch can be downloaded from &lt;a href="/pub/patches/iptables-1.4.4-imq.diff"&gt;here&lt;/a&gt; using command below:&lt;/p&gt;

&lt;code&gt;wget http://nme.pl/pub/patches/iptables-1.4.4-imq.diff&lt;/code&gt;

&lt;p&gt;Ok, now since we got patch ready, we can download iptables sources and compile our deb package:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;apt-get source iptables&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;cd iptables-1.4.4&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;del datetime="2010-05-10T08:28:38+00:00"&gt;cp ../iptables-1.4.4-imq.diff debian/patch/1009-iptables-1.4.4-imq.diff
echo "1009-iptables-1.4.4-imq.diff" &amp;gt;&amp;gt;debian/patch/series&lt;/del&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;patch -p0 &amp;lt; ../iptables-1.4.4-imq.diff&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Following will be required:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo aptitude install debhelper quilt autoconf automake linuxdoc-tools libtool&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;dpkg-buildpackage -rfakeroot -uc -b&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In case You are recompiling for some reason, one of the distro patches might fail - in this case edit debian/patches/series using Your favourite editor and comment out the following patch:&lt;/p&gt;

&lt;pre&gt;
0902-docs-version-reference.diff    -&amp;gt;    #0902-docs-version-reference.diff
&lt;/pre&gt;

&lt;p&gt;Operation above might be archived by in place edition of debian/patch/series using command below:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sed -i 's/^0902/#0902/' debian/patch/series&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;When compilation ends, You should get two packages in parent directory: &lt;code&gt;iptables&lt;/code&gt; and &lt;code&gt;iptables-dev&lt;/code&gt;.&lt;/p&gt;

&lt;h4&gt;Installation &amp;amp; freezing our changes&lt;/h4&gt;

&lt;p&gt;Now we can install our packages:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;dpkg -i *.deb&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;It will install following packages:&lt;/p&gt;

&lt;pre&gt;
iptables_1.4.4-2ubuntu2_i386.deb
linux-image-2.6.32.11+drm33.2imq_2.6.32.11+drm33.2imq-10.00.Custom_i386.deb
iptables-dev_1.4.4-2ubuntu2_i386.deb
&lt;/pre&gt;

&lt;p&gt;You might also consider holding packages to be sure that they will not be replaced during standard regular-basis upgrade:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;aptitude hold linux-image iptables iptables-dev&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;IMQ development, status and replacement discussion&lt;/h4&gt;

&lt;p&gt;It is not true that recent IMQ patches are not stable as I have read on some web pages. Since Jussi joined the IMQ team, problems I have had with 2.6.18-24 kernels have gone to past.&lt;/p&gt;

&lt;p&gt;Kernel 2.6.28.9 with iptables 1.4.0 works perfectly stable taking care of huge loads of network traffic. I think that current patch described above will work the same (im making before-production tests currently and it seems to work fine).&lt;/p&gt;

&lt;p&gt;On the other hand - &lt;a href="http://www.linuxfoundation.org/collaborate/workgroups/networking/ifb"&gt;IFB&lt;/a&gt; - which is meant as replacement for IMQ - as for me - it does not offer the same functionality for bridge environment I need... Of course - I might be mistaken. Thats why - if anyone of You have replaced IMQ with IFB for bridge devices with ingress and egress traffic shaping - I'm very interested in the solution.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/nmepl_en/~4/tSj3hZ7ZdK0" height="1" width="1"/&gt;</summary><feedburner:origLink>http://nme.pl/en/2010/05/how-to-add-imq-patch-to-ubuntu-10-04-lucid-lynx</feedburner:origLink></entry></feed>

