<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1186777979804949516</id><updated>2025-10-22T08:59:37.540+02:00</updated><category term="python"/><category term="javascript"/><category term="django"/><category term="Eclipse"/><category term="jquery"/><title type='text'>Homunculus</title><subtitle type='html'>A place to discuss Python and Web programming.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://anothercomputingblog.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1186777979804949516/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://anothercomputingblog.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02425663898541762725</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>10</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1186777979804949516.post-5401318886199672703</id><published>2010-05-08T21:08:00.004+02:00</published><updated>2010-05-08T22:02:09.709+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="python"/><title type='text'>Unpacking &quot;some&quot; list elements in Python</title><content type='html'>Programming is not only about efficiency or correctness but also about style. Well, it is for me! Now &quot;my&quot; style is really not that great but from time to time I try to improve it. I may want to make my code more readable, more mathematically oriented or even just more elegant.&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;Basic unpacking&lt;/h4&gt;This is why I was searching for an elegant way to extract some data from a list and leave the rest untouched. Python offers the possibility of unpacking data from a list or tuple. In the code below you&#39;ll find the basic unpacking use. For this to work you have to know how many elements there are in your list and assign a variable to each of those elements.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: python&quot;&gt;list = [1, 2, 3, 4]
a, b, c, d = list
&lt;/pre&gt;&lt;br /&gt;
I believe this is a lot better than the code below which has exactly the same effect but does not make use of the unpacking functionality.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: python&quot;&gt;list = [1, 2, 3, 4]
a, b, c, d = list[0], list[1], list[2], list[3]
&lt;/pre&gt;&lt;br /&gt;
However this does not solve my initial problem of unapacking only part of the list and leaving the rest as is. Below I&#39;ll show you how to do just that in Python 3.x and in Python 2.x.&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;Catch-all unpacking in Python 3.x&lt;/h4&gt;With Python 3.0 came the &lt;a href=&quot;http://www.python.org/dev/peps/pep-3132/&quot;&gt;extended iterable unpacking&lt;/a&gt; which brought an elegant way to extract needed data into variables and also specify a &quot;catch-all&quot; variable that will take the rest. &lt;br /&gt;
&lt;br /&gt;
Let&#39;s suppose we want to work with the first two elements of the list and leave the rest as a list for future use. In versions 3.x you can do that as shown in the two lines of code that follow.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: python&quot;&gt;list = [1, 2, 3, 4]
a, b, *rest = list
&lt;/pre&gt;&lt;br /&gt;
The variable &lt;b&gt;a&lt;/b&gt; and &lt;b&gt;b&lt;/b&gt; will point to the first and second elements respectively. While the variable &lt;b&gt;rest&lt;/b&gt; will reference the rest of the list. The &quot;catch-all&quot; variable is marked with an asterisk. This is elegant and concise. Exactly what I was looking for. &lt;br /&gt;
&lt;br /&gt;
However life is not always that easy. While Python 3.x brings lots of new and  interesting features it is not backward compatible with python 2.x. Using the Django web development platform I am one of those poor souls stuck in version 2. So let&#39;s see what we can come up with in this version.&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;Catch-all unpacking in Python 2.x&lt;/h4&gt;The best way (as in more elegant) I found to replicate the snippet above in Python 2.x is to make use of slices. In the code sample that follows I&#39;ll show you how I do it when I want to unpack just the head of the list or more elements because the method is slightly different.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: python&quot;&gt;list = [1, 2, 3, 4]
(a, b), rest = list[:2], list[2:] # The first and second elements are interesting.
a, rest = list[0], list[1:]       # Only the head is interesting.
&lt;/pre&gt;&lt;br /&gt;
I have to admit I am disappointed with what I could come up with. However I can&#39;t think of any other way to do this that would be more elegant. the second case is just a normal assignment with the use of a slice in the right part of the assignment. While the first case is trickier and manages to actually use the unpacking functionality it still lacks clarity. Besides the use of slices only works with list and not with all iterable objects. I can&#39;t wait for Django to switch to Python 3.x!&lt;br /&gt;
&lt;br /&gt;
I would be very interested to hear how you would implement the small code pattern above.</content><link rel='replies' type='application/atom+xml' href='http://anothercomputingblog.blogspot.com/feeds/5401318886199672703/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://anothercomputingblog.blogspot.com/2010/05/functional-unpacking-style.html#comment-form' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1186777979804949516/posts/default/5401318886199672703'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1186777979804949516/posts/default/5401318886199672703'/><link rel='alternate' type='text/html' href='http://anothercomputingblog.blogspot.com/2010/05/functional-unpacking-style.html' title='Unpacking &quot;some&quot; list elements in Python'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02425663898541762725</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1186777979804949516.post-2229919308722535539</id><published>2010-05-02T20:09:00.001+02:00</published><updated>2010-05-02T20:10:38.674+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="django"/><category scheme="http://www.blogger.com/atom/ns#" term="Eclipse"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><title type='text'>Python IDE: the Pydev plugin for Eclipse</title><content type='html'>Choices for a good open source Python IDE are not many! Today I&#39;ll show you how to quickly have a basic setup working with &lt;a href=&quot;http://pydev.org/&quot;&gt;Pydev&lt;/a&gt; for &lt;a href=&quot;http://www.eclipse.org/&quot;&gt;Eclipse&lt;/a&gt;. Since the last post about &lt;a href=&quot;http://anothercomputingblog.blogspot.com/2010/04/ftpsftp-support-in-eclipse-with-remote.html&quot;&gt;SFTP and FTP&lt;/a&gt; support in Eclipse. You already know it is my platform of choice.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://pydev.org/&quot;&gt;Pydev&lt;/a&gt; is a product by &lt;a href=&quot;http://www.aptana.com/&quot;&gt;Aptana&lt;/a&gt; which also provides the Aptana Studio software for working with web development (Ajax, Ruby, PHP, etc...). &amp;nbsp;The plugin as all the usual features you would expect from a normal IDE and also some goodies like Django integration. Instead of a lengthy discussion on the pros and cons of this setup. Let&#39;s just go ahead with installing and configuring it so you can judge for yourself.&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;Installing the Pydev plugin.&lt;/h4&gt;&lt;div&gt;To install install the plugin you obviously need to first have Eclipse. I generally start with &lt;a href=&quot;http://www.eclipse.org/downloads/download.php?file=/eclipse/downloads/drops/R-3.5.2-201002111343/eclipse-SDK-3.5.2-win32.zip&quot;&gt;Eclipse Classic&lt;/a&gt; but that will pretty much depend on your preferences... From Eclipse follow theses steps to get the plugin:&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;Go the &lt;i&gt;Help&lt;/i&gt; menu and click &lt;i&gt;Install New Software&lt;/i&gt;.&lt;/li&gt;
&lt;li&gt;On the work with text box insert&amp;nbsp;&lt;i&gt;http://pydev.org/updates&lt;/i&gt; and click &lt;i&gt;Add&lt;/i&gt;.&lt;/li&gt;
&lt;li&gt;You &amp;nbsp;can insert a name for this update site and wait for Eclipse to check the available content.&lt;/li&gt;
&lt;li&gt;Select Pydev and hit&amp;nbsp;&lt;i&gt;Next &lt;/i&gt;two times.&lt;/li&gt;
&lt;li&gt;Accept the license agreement if that&#39;s ok with you and click &lt;i&gt;Finish&lt;/i&gt;.&lt;/li&gt;
&lt;/ol&gt;&lt;div&gt;After restarting Eclipse the plugin should be installed and ready to be configured.&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;&lt;h4&gt;Configuring the Pydev plugin.&lt;/h4&gt;&lt;div&gt;To get started on programming with Pydev you now need to tell it where to find the interpreter:&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;Open the Preferences window. Go to &lt;i&gt;Window&lt;/i&gt; then&amp;nbsp;&lt;i&gt;preferences&lt;/i&gt;.&lt;/li&gt;
&lt;li&gt;Next you expand &lt;i&gt;Pydev&lt;/i&gt; and select &lt;i&gt;Interpreter - Python&lt;/i&gt;. &lt;/li&gt;
&lt;li&gt;On the right pane you can select &lt;i&gt;Auto Config &lt;/i&gt;if your system path is properly set. Otherwise you might have to select your interpreter and libraries manually&lt;i&gt;.&lt;/i&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;div&gt;This is all that is needed for a basic setup. You can start exploring you newly installed Python IDE. Any suggestions are welcome.&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://anothercomputingblog.blogspot.com/feeds/2229919308722535539/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://anothercomputingblog.blogspot.com/2010/05/python-ide-pydev-plugin-for-eclipse.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1186777979804949516/posts/default/2229919308722535539'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1186777979804949516/posts/default/2229919308722535539'/><link rel='alternate' type='text/html' href='http://anothercomputingblog.blogspot.com/2010/05/python-ide-pydev-plugin-for-eclipse.html' title='Python IDE: the Pydev plugin for Eclipse'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02425663898541762725</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1186777979804949516.post-1279193498331721966</id><published>2010-04-25T02:07:00.008+02:00</published><updated>2010-04-25T22:18:44.658+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Eclipse"/><title type='text'>FTP/SFTP support in eclipse with Remote System Explorer</title><content type='html'>I got tired of using an FTP/SFTP client and switching from it to my IDE. So I went on looking for some FTP and SFTP plugins for &lt;a href=&quot;http://www.eclipse.org/&quot;&gt;Eclipse&lt;/a&gt;. &lt;br /&gt;
&lt;br /&gt;
I&#39;ve seen the Aptana Studio or plugin for Eclipse being recommended and tried to use it. Works ok but they only support SFTP in the professional version. Because of that I tried &lt;a href=&quot;http://www.eclipse.org/dsdp/tm/tutorial/&quot;&gt;Remote System Explorer&lt;/a&gt;. I was quite happy to discover that not only it supports FTP and SFTP but you actually can also open a ssh terminal or issue ssh commands from Eclipse directly.&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;Install the Remote System Explorer plugin&lt;/h4&gt;First you need to install the plugin. With version 3.5.2, you can follow these steps:&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;Go to Help -&amp;gt; Install new software&lt;/li&gt;
&lt;li&gt; From the &quot;work with&quot; drop-down list select: &quot;Galileo - http://download.eclipse.org/releases/galileo&quot;&lt;/li&gt;
&lt;li&gt;In the pane below, expand General Purpose Tools and select the Remote System Explorer end user runtime.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Click Next and follow the instructions. &lt;/li&gt;
&lt;/ol&gt;&lt;br /&gt;
&lt;h4&gt;Create a SFTP connection &lt;/h4&gt;Once installed you can start creating connections. Just do as follows:&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;switch to Remote System Explorer perspective.&lt;/li&gt;
&lt;li&gt;Right-click on the Remote Systems view on the left and choose new -&amp;gt; connection.&lt;/li&gt;
&lt;li&gt;Choose FTP only if that&#39;s what you need or SSH only if you want SFTP support as I do.&lt;/li&gt;
&lt;li&gt;Specify the Host Name and the Connection Name.&lt;/li&gt;
&lt;li&gt;Finally keep clicking on next until finished.&lt;/li&gt;
&lt;/ol&gt;Tadam! You should have your remote system on the left pane. From there you can start browsing your files or opening an ssh terminal to the remote system. Of course you don&#39;t need to be in the RSE perspective. You can switch to any perspective you like and and open the necessary views through Window -&amp;gt; Show View, etc.&lt;br /&gt;
&lt;br /&gt;
Happy Coding!</content><link rel='replies' type='application/atom+xml' href='http://anothercomputingblog.blogspot.com/feeds/1279193498331721966/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://anothercomputingblog.blogspot.com/2010/04/ftpsftp-support-in-eclipse-with-remote.html#comment-form' title='8 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1186777979804949516/posts/default/1279193498331721966'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1186777979804949516/posts/default/1279193498331721966'/><link rel='alternate' type='text/html' href='http://anothercomputingblog.blogspot.com/2010/04/ftpsftp-support-in-eclipse-with-remote.html' title='FTP/SFTP support in eclipse with Remote System Explorer'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02425663898541762725</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>8</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1186777979804949516.post-5308870654711307628</id><published>2010-04-18T13:18:00.004+02:00</published><updated>2010-04-25T22:35:47.193+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="django"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><title type='text'>Django whois using the subprocess module</title><content type='html'>Last month I wrote a post about writing a whois client. This time I want to investigate If it&#39;s possible to leverage your operating system for those kind of tasks or if you really need to reinvent the wheel.&lt;br /&gt;
&lt;br /&gt;
So why did I wrote my own crappy whois client in the first place? As you may already have noticed from my blog it&#39;s because I want to use the whois client from within Django (web application framework) hence the need to have a python module that can do whois queries.&lt;br /&gt;
&lt;br /&gt;
Ok so the need is pretty clear but there should be a way to call the whois client of my operating system from a python module instead. This would allow me to write less code and I&#39;ll probably end up with a more robust whois client. So what possibilities does Python offer to spawn a process and communicate with it?&lt;br /&gt;
&lt;br /&gt;
Since version 2.4 there is the &lt;a href=&quot;http://docs.python.org/library/subprocess.html&quot;&gt;subprocess module&lt;/a&gt;. In essence this is exactly what I need. So let&#39;s see how we can&amp;nbsp;use it from within Django to provide a web interface to the whois native client.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: python&quot;&gt;from django.shortcuts import render_to_response
from django.http import HttpResponse
from django import forms
import subprocess

def whois(domain):
    p = subprocess.Popen([&#39;whois&#39;, domain], stdout=subprocess.PIPE)
    answer = p.commmunicate()
    return answer

class WhoisForm(forms.Form):
    domainname = forms.CharField(max_length=100)

if &#39;whois&#39; in request.POST:
    whois_form = WhoisForm(request.POST, prefix=&#39;whois&#39;)
    if whois_form.is_valid():
        domainname = whois_form.cleaned_data[&#39;domainname&#39;]
        answer = whois(domainname)
else:
    whois_form = WhoisForm( prefix=&#39;whois&#39;)

return render_to_response(&#39;index.html&#39;, {&#39;whois_form&#39;: whois_form,
                                         &#39;answer&#39;: answer,})
&lt;/pre&gt;&lt;br /&gt;
What happens in the code above is that we spawn the whois subprocess and pipe its output. This enables us to communicate with it and retrieve it&#39;s standard output in a variable. We can then pass along the output to the template for the user to view in his browser. Quick and easy!&lt;br /&gt;
&lt;br /&gt;
Ok, so at this point I should be a happy man! I did reach my initial goal of not reinventing the wheel. However &amp;nbsp;I&#39;m really not sure this is the way to go. Next time we will use the &lt;a href=&quot;http://docs.python.org/library/timeit.html&quot;&gt;timeit&lt;/a&gt; module to see how this one compares to the &lt;a href=&quot;http://anothercomputingblog.blogspot.com/2010/03/whois-client-in-python.html&quot;&gt;python whois client&lt;/a&gt; regarding performance.</content><link rel='replies' type='application/atom+xml' href='http://anothercomputingblog.blogspot.com/feeds/5308870654711307628/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://anothercomputingblog.blogspot.com/2010/04/django-whois-using-subprocess-module.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1186777979804949516/posts/default/5308870654711307628'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1186777979804949516/posts/default/5308870654711307628'/><link rel='alternate' type='text/html' href='http://anothercomputingblog.blogspot.com/2010/04/django-whois-using-subprocess-module.html' title='Django whois using the subprocess module'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02425663898541762725</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1186777979804949516.post-8317502289050972159</id><published>2010-04-11T18:23:00.001+02:00</published><updated>2010-04-11T18:31:55.840+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="javascript"/><title type='text'>Javascript debugging</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;This week-end I had a hard time debugging some javascript code and could hardly find any time for posting.&amp;nbsp;While we wait for the next post I wanted to share a good article I found about javascript debugging:&lt;/div&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;a href=&quot;http://www.alistapart.com/articles/advanced-debugging-with-javascript/&quot;&gt;http://www.alistapart.com/articles/advanced-debugging-with-javascript/&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Debugging javascript can be a real pain. Please feel free to share your tips, techniques and tools in the comments section.</content><link rel='replies' type='application/atom+xml' href='http://anothercomputingblog.blogspot.com/feeds/8317502289050972159/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://anothercomputingblog.blogspot.com/2010/04/javascript-debugger.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1186777979804949516/posts/default/8317502289050972159'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1186777979804949516/posts/default/8317502289050972159'/><link rel='alternate' type='text/html' href='http://anothercomputingblog.blogspot.com/2010/04/javascript-debugger.html' title='Javascript debugging'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02425663898541762725</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1186777979804949516.post-3236078307568684627</id><published>2010-04-07T22:56:00.002+02:00</published><updated>2010-04-07T23:03:03.319+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="javascript"/><category scheme="http://www.blogger.com/atom/ns#" term="jquery"/><title type='text'>Multicolor jQuery Accordion widget</title><content type='html'>I&amp;nbsp;received&amp;nbsp;a question about having different elements in a jQuery &lt;a href=&quot;http://jqueryui.com/demos/accordion/&quot;&gt;accordion&lt;/a&gt; with different colors. There are probably many ways to achieve this. Below I&#39;ll show you how to do it with just a little bit of javascript.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: javascript&quot;&gt;$(document).ready(function(){
    $(&quot;#accordion&quot;).accordion();
    var my_colors = [&quot;aqua&quot;, &quot;black&quot;, &quot;blue&quot;, &quot;fuchsia&quot;, &quot;green&quot;, &quot;lime&quot;];
    $(&#39;.ui-accordion-header&#39;).each( function(i) {
        $(this).css(&quot;background-color&quot;,my_colors[i])
    });
});
&lt;/pre&gt;&lt;br /&gt;
What is important to note here is the use of the css classes added by jQuery to an accordion to retrieve all accordion headers. I hope I answered the question... If I can find the time I&#39;ll try to put a polished demo on the web with complete source code.</content><link rel='replies' type='application/atom+xml' href='http://anothercomputingblog.blogspot.com/feeds/3236078307568684627/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://anothercomputingblog.blogspot.com/2010/04/multicolor-jquery-accordion-widget.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1186777979804949516/posts/default/3236078307568684627'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1186777979804949516/posts/default/3236078307568684627'/><link rel='alternate' type='text/html' href='http://anothercomputingblog.blogspot.com/2010/04/multicolor-jquery-accordion-widget.html' title='Multicolor jQuery Accordion widget'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02425663898541762725</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1186777979804949516.post-5676441379906593597</id><published>2010-04-05T11:58:00.001+02:00</published><updated>2010-04-05T12:01:15.612+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="javascript"/><category scheme="http://www.blogger.com/atom/ns#" term="jquery"/><title type='text'>A collection of jQuery Modal Dialog Boxes plugins</title><content type='html'>Today I was searching for a good Modal dialog Boxes plugin for jQuery in an attempt to improve the overall look and feel of my current project. After some time I ended up on&amp;nbsp;&lt;a href=&quot;http://coderplus.com/2009/11/jquery-modal-boxes-to-improve-your-ui/&quot;&gt;19 jQuery Modal Boxes to improve your UI&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
Since I know how frustrating this kind of search can become. I thought I&#39;d better share this collection with you.</content><link rel='replies' type='application/atom+xml' href='http://anothercomputingblog.blogspot.com/feeds/5676441379906593597/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://anothercomputingblog.blogspot.com/2010/04/collection-of-jquery-modal-dialog-boxes.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1186777979804949516/posts/default/5676441379906593597'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1186777979804949516/posts/default/5676441379906593597'/><link rel='alternate' type='text/html' href='http://anothercomputingblog.blogspot.com/2010/04/collection-of-jquery-modal-dialog-boxes.html' title='A collection of jQuery Modal Dialog Boxes plugins'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02425663898541762725</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1186777979804949516.post-4779288129504571451</id><published>2010-04-02T19:50:00.006+02:00</published><updated>2010-04-02T20:41:17.728+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="django"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><title type='text'>Multiple Django forms in the same view</title><content type='html'>When you want to handle multiple &lt;a href=&quot;http://www.djangoproject.com/&quot;&gt;Django&lt;/a&gt; forms within the same view you need some extra coding as opposed to having a single form. This is needed because:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;You want to identify which form has been submitted to your view.&lt;/li&gt;
&lt;li&gt;And you don&#39;t want to confuse fields from one form with fields from another.&lt;/li&gt;
&lt;/ul&gt;&lt;div&gt;So let&#39;s start with identifying the form from your view. You&#39;ll first need to add some information to your template to distinguish between the two forms. This can be easily done by giving a unique name to each submit buttons. For the rest of this post we will assume that we have two forms: A and B.&lt;/div&gt;&lt;br /&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;&amp;lt;fieldset&amp;gt;
    &amp;lt;legend&amp;gt;Form A&amp;lt;/legend&amp;gt;
    &amp;lt;form method=&quot;post&quot;&amp;gt;
        {{ A_form.as_p }}
        &amp;lt;input name=&quot;A&quot; type=&quot;submit&quot; value=&quot;Submit&quot; /&amp;gt;
    &amp;lt;/form&amp;gt;
&amp;lt;/fieldset&amp;gt;

&amp;lt;fieldset&amp;gt;
    &amp;lt;legend&amp;gt;Form B&amp;lt;/legend&amp;gt;
    &amp;lt;form method=&quot;post&quot;&amp;gt;
        {{ B_form.as_p }}
        &amp;lt;input name=&quot;B&quot; type=&quot;submit&quot; value=&quot;Submit&quot; /&amp;gt;
    &amp;lt;/form&amp;gt;
&amp;lt;/fieldset&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
Now that you uniquely identified both forms you can add some logic to your view to get to know which submit button as been pressed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: python&quot;&gt;if &#39;A&#39; in request.POST:
    # A form processing
elif &#39;B&#39; in request.POST:
    # B_form processing
&lt;/pre&gt;&lt;br /&gt;
What happens above is that you search the submitted POST data dictionary for the name you gave to your submit buttons. That&#39;s all there is to it. &lt;br /&gt;
&lt;br /&gt;
However if for some reason fields in the different forms you present to your users have the same names then you need to add a couple more lines of code to distinguish between them. From the django documentation you can borrow the strategy in &lt;a href=&quot;http://docs.djangoproject.com/en/1.1/topics/forms/formsets/#using-more-than-one-formset-in-a-view&quot;&gt;using more than one formset in a view&lt;/a&gt;. The idea is to prefix each field name with a form identifier. I choose to use the same token for the prefix and for the submit button name.&lt;br /&gt;
&lt;br /&gt;
The end result would be something like this:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: python&quot;&gt;class AForm(forms.Form):
    fieldname = forms.CharField(max_length=25)

class BForm(forms.Form):
    fieldname = forms.CharField(max_length=25)

if &#39;A&#39; in request.POST:
    A_form = AForm(request.POST, prefix=&#39;A&#39;)
    B_form = BForm(prefix=&#39;B&#39;)
    # A form processing
elif &#39;B&#39; in request.POST:
    B_form = BForm(request.POST, prefix=&#39;B&#39;)
    A_form = AForm(prefix=&#39;A&#39;)
    # B_form processing
&lt;/pre&gt;&lt;br /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://anothercomputingblog.blogspot.com/feeds/4779288129504571451/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://anothercomputingblog.blogspot.com/2010/04/multiple-django-forms-on-same-view.html#comment-form' title='8 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1186777979804949516/posts/default/4779288129504571451'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1186777979804949516/posts/default/4779288129504571451'/><link rel='alternate' type='text/html' href='http://anothercomputingblog.blogspot.com/2010/04/multiple-django-forms-on-same-view.html' title='Multiple Django forms in the same view'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02425663898541762725</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>8</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1186777979804949516.post-9203782731158469690</id><published>2010-03-29T12:11:00.002+02:00</published><updated>2010-03-29T23:37:03.664+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="python"/><title type='text'>Whois client in Python</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;The other day I had to implement a small whois client in python. After looking for a moment on the&amp;nbsp;web I thought that this would be an easy task. Indeed the &lt;a href=&quot;http://tools.ietf.org/html/rfc3912&quot;&gt;RFC&lt;/a&gt; is so small it&#39;s disturbing. So it didn&#39;t took long to get some sort of code running that could talk to a whois server:&lt;/div&gt;&lt;br /&gt;
&lt;pre class=&quot;brush: python&quot;&gt;import socket

def whois(domain):
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect((whois.dns.be, 43))
    sock.send(domain + &quot;\r\n&quot;)
    response = &#39;&#39;
    while True:
        d = sock.recv(4096)
        response += d
        if d == &#39;&#39;:
            break
    sock.close()
    return response
&lt;/pre&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;However I soon realized that the whois RFC is small for a reason: there is nothing in the specification and so problems start to appear...&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The above snippet can talk to a server but will get a proper answer only for .be domains. To get usefull information one needs to know which server to talk to. Back on the web looking for some kind of whois server list. As it turns out whois-servers.net does provide such a list through DNS CNAME records. In order to know the whois server for .com one could do a DNS query&amp;nbsp;for &lt;em&gt;&quot;com.whois-servers.net&quot;&lt;/em&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;To make the above code more generic you could connect to the whois server with the following strategy:&lt;/div&gt;&lt;br /&gt;
&lt;pre class=&quot;brush: python&quot;&gt;tld = domain.split(&#39;.&#39;)[-1]
sock.connect(((tld + &#39;.whois-servers.net&#39;), 43))
&lt;/pre&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;While this is already alot better. Problem remains as not all domains use the same whois server even if they have the same TLD. To make things even easier not all whois servers have the same syntax or return the same results. If we take google.com we have to query .com.whois-servers.net for the string &lt;em&gt;&quot;=google.com&quot;&lt;/em&gt;&amp;nbsp; just to be informed&amp;nbsp;that&amp;nbsp;their actual whois server is different. This information could be obtained by parsing the result in search of the following&amp;nbsp;line &lt;em&gt;&quot;Whois Server: whois.markmonitor.com&quot;&lt;/em&gt;&lt;/div&gt;&lt;br /&gt;
MJJX8TPXDHKM</content><link rel='replies' type='application/atom+xml' href='http://anothercomputingblog.blogspot.com/feeds/9203782731158469690/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://anothercomputingblog.blogspot.com/2010/03/whois-client-in-python.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1186777979804949516/posts/default/9203782731158469690'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1186777979804949516/posts/default/9203782731158469690'/><link rel='alternate' type='text/html' href='http://anothercomputingblog.blogspot.com/2010/03/whois-client-in-python.html' title='Whois client in Python'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02425663898541762725</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1186777979804949516.post-6361707304399156974</id><published>2010-03-29T01:25:00.000+02:00</published><updated>2010-03-29T23:37:17.205+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="javascript"/><title type='text'>Syntax Highlighting Test</title><content type='html'>Straightforward quicksort algorithm taken from wikipedia to test syntax highlighting within&amp;nbsp;blogger:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: python&quot;&gt;def qsort1(lst):
    if len(lst) &amp;lt;= 1:
        return lst
    pivot = lst.pop(0)
    greater_eq = qsort1([i for i in lst if i &amp;gt;= pivot])
    lesser = qsort1([i for i in lst if i &amp;lt; pivot])
    return lesser + [pivot] + greater_eq
&lt;/pre&gt;&lt;div class=&quot;python&quot; name=&quot;code&quot;&gt;&lt;br /&gt;
The&amp;nbsp;idea has been borrowed from this &lt;a href=&quot;http://urenjoy.blogspot.com/2008/10/publish-source-code-in-blogger.html&quot;&gt;blog post&lt;/a&gt;&amp;nbsp;and SyntaxHighlighter can be found &lt;a href=&quot;http://alexgorbatchev.com/wiki/SyntaxHighlighter&quot;&gt;here&lt;/a&gt;.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://anothercomputingblog.blogspot.com/feeds/6361707304399156974/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://anothercomputingblog.blogspot.com/2010/03/syntax-highlighting-test.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1186777979804949516/posts/default/6361707304399156974'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1186777979804949516/posts/default/6361707304399156974'/><link rel='alternate' type='text/html' href='http://anothercomputingblog.blogspot.com/2010/03/syntax-highlighting-test.html' title='Syntax Highlighting Test'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/02425663898541762725</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry></feed>