<?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"
	>

<channel>
	<title>Dev360.com</title>
	<atom:link href="http://blog.dev360.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.dev360.com</link>
	<description>Web Development. Every Angle Covered.</description>
	<pubDate>Sun, 07 Feb 2010 17:13:08 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.1</generator>
	<language>en</language>
			<item>
		<title>Using a text input for ManyToMany relations in Django</title>
		<link>http://blog.dev360.com/2010/02/07/using-a-text-input-for-manytomany-relations-in-django/</link>
		<comments>http://blog.dev360.com/2010/02/07/using-a-text-input-for-manytomany-relations-in-django/#comments</comments>
		<pubDate>Sun, 07 Feb 2010 17:13:08 +0000</pubDate>
		<dc:creator>Christian Toivola</dc:creator>
		
		<category><![CDATA[Django]]></category>

		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://blog.dev360.com/?p=164</guid>
		<description><![CDATA[Problem:
You have a many-to-many relationship on a model &#8212; i.e. Video has many Tags &#8212; and you want to be able to use just a text input to manage that relationship.
I recently came across this problem while working on a Video site that called for tagging of uploaded Media. Django&#8217;s default way of dealing with [...]]]></description>
			<content:encoded><![CDATA[<h3>Problem:</h3>
<p>You have a many-to-many relationship on a model &mdash; i.e. Video has many Tags &mdash; and you want to be able to use just a text input to manage that relationship.</p>
<p>I recently came across this problem while working on a Video site that called for tagging of uploaded Media. Django&#8217;s default way of dealing with ManyToMany fields (checkboxes) did not seem appropriate since the UX would degrade very quickly as the number of tags grow. The UI paradigm that everyone is familiar with is obviously to enter the tags in a comma-delimited format, like how most popular blog sites have it. This post will walk you through how to implement this in a ModelForm that can be used in your admin. This tutorial is for Django version 1.1.1. In retrospect, I guess a custom widget may have been the option with best reusability, but if for nothing else, this post could give you a pretty good idea of how flexible Django is to extend and modify.</p>
<h3>Models</h3>
<p>First off, we create the VideoTag and Video class. Notice how the tags attribute of the Video model has editable=False - since we do not want to bother with the select boxes in our form.</p>
<pre>from django.utils.translation import ugettext as _
from django.db import models
from django.template.defaultfilters import slugify

# models.py
class VideoTag(models.Model):
	slug = models.SlugField(max_length=30, editable=False, blank=True, unique=True)
	name = models.CharField(_('name'), max_length=30)
	parent = models.ForeignKey('VideoTag', verbose_name=_('parent'), related_name='children', blank=True, null=True)

	def __str__(self):
		return '%s' % (self.name)

	def __unicode__(self):
		return u'%s' % (self.name)

	def save(self, force_insert=False, force_update=False):
		self.slug = slugify(self.name)
		super(VideoTag, self).save(force_insert, force_update)

class Video(models.Model):
	title = models.CharField(_('title'), max_length=32)
	summary = models.TextField(_('summary'), max_length=300)
	tags = models.ManyToManyField(VideoTag, verbose_name=_('tags'), related_name='videos', blank=True, editable=False)</pre>
<h3>Forms</h3>
<p>Now that we have the models, we can run go straight to the forms part, where all the relevant code is. As you can see, there are two steps to this: the first part is to override the initialization of the form to set the initial value of the tags_text field to read the tags M2M fields; the second part is to capture the input and save it as related objects.</p>
<pre>#forms.py
from django.utils.translation import ugettext as _
from django import forms
from django.template.defaultfilters import slugify

from your_app.models import Video, VideoTag

class VideoForm(forms.ModelForm):
	tags_text = forms.CharField(label=_("video tags"), required=False, help_text=_("A comma-delimited list of the tags that you would like to tag this with"),)

	def __init__(self, *args, **kwargs):
		super(VideoForm, self).__init__(*args, **kwargs)

		# args.__len__ is greater than zero if it is a postback
		if len(args) == 0 and self.instance != None and self.instance.id != None:
			tags = list(self.instance.tags.all().order_by('name'))
			if len(tags) &gt; 0:
				initial_text = reduce(lambda x, y: u'%s, %s' % (x, y.name), tags)
				self.fields["tags_text"].initial = initial_text

	def save(self, commit=True):
		instance = super(VideoForm, self).save(commit=True)
		tags = self.cleaned_data["tags_text"]
		instance.tags.clear()
		if tags:
			for tag in tags.split(','):
				if tag.lower().strip() != "":
					video_tag = None
					tag = tag.strip()
					try:
						video_tag = VideoTag.objects.get(slug=slugify(tag))
					except VideoTag.DoesNotExist:
						video_tag = VideoTag()
						video_tag.name = tag
						video_tag.save()
					instance.tags.add(video_tag)
		return instance

	def save_m2m(self):
		pass

	class Meta:
		model = Video</pre>
<h3>Admin</h3>
<p>Next, you may want to use this form in your admin, so let&#8217;s set the admin to use the correct form:</p>
<pre>#admin.py
from django.contrib import admin
from your_app.models import Video
from your_app.forms import VideoForm

class VideoAdmin(admin.ModelAdmin):
	form = VideoForm
admin.site.register(Video, VideoAdmin)</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.dev360.com/2010/02/07/using-a-text-input-for-manytomany-relations-in-django/feed/</wfw:commentRss>
		</item>
		<item>
		<title>ManyToManyField and Ordered fields in Django ModelForms</title>
		<link>http://blog.dev360.com/2009/06/15/manytomanyfield-and-ordered-fields-in-django-modelforms/</link>
		<comments>http://blog.dev360.com/2009/06/15/manytomanyfield-and-ordered-fields-in-django-modelforms/#comments</comments>
		<pubDate>Mon, 15 Jun 2009 18:59:34 +0000</pubDate>
		<dc:creator>Christian Toivola</dc:creator>
		
		<category><![CDATA[Django]]></category>

		<category><![CDATA[ModelForm]]></category>

		<guid isPermaLink="false">http://blog.dev360.com/?p=145</guid>
		<description><![CDATA[I was working on some code and realized that ManyToManyFields always show up last in a ModelForm, regardless if you specify the order in the Meta fields property. Apparently this is due to be fixed in Django 1.1 which is right around the corner.. unfortunately I&#8217;m on 1.0 and feel anxious about moving 10+ sites [...]]]></description>
			<content:encoded><![CDATA[<p>I was working on some code and realized that ManyToManyFields always show up last in a ModelForm, regardless if you specify the order in the Meta fields property. Apparently this is due to be fixed in Django 1.1 which is right around the corner.. unfortunately I&#8217;m on 1.0 and feel anxious about moving 10+ sites to 1.1 beta right at this moment. I also felt it was a bit inappropriate to <a href="http://code.djangoproject.com/ticket/6953">diff my Django source</a>.</p>
<p>Please be aware that this is a <em>hack</em>. It is not an optimal solution. Stuff like form.as_* will <strong>NOT</strong> work with the solution below. All this does is add a property called <code>ordered_fields</code> to your ModelForm which implements the correct behavior.</p>
<pre>
# models.py
class Bar(models.Model):
	pass

class Foo(models.Model):
        # ordinarily, Django 1.0 would list the regular_field first and all M2Ms last
	many_to_many = models.ManyToManyField('Bar', related_name='foos')
	regular_field = models.CharField(max_length=10)
</pre>
<pre>
# forms.py
class FooForm(forms.ModelForm):
	def ordered_fields(self):
		list = []
		for field_name in self._meta.fields:
			list.append(self[field_name])
		return list

	class Meta:
		model = Foo
		fields = ('many_to_many',
			     'regular_field',)
</pre>
<pre>
#Template:

&lt;form action=&quot;{{ app_path }}&quot; method=&quot;post&quot; id=&quot;foo-form&quot;&gt;
	&lt;fieldset class=&quot;module aligned ()&quot;&gt;
	{% for field in form.ordered_fields %}
		&lt;div class=&quot;form-row thin wide ()&quot;&gt;

			{{ field.label_tag }}
			{{ field }}
			{{ field.errors }}
			{% if field.help_text %}
			&lt;p class=&quot;help&quot;&gt;{{ field.help_text }}&lt;/p&gt;
			{% endif %}
		&lt;/div&gt;
	{% endfor %}
	&lt;/fieldset&gt;
	&lt;div class=&quot;submit-row aligned ()&quot;&gt;
		&lt;input class=&quot;default&quot; type=&quot;submit&quot; value=&quot;Send&quot; /&gt;
	&lt;/div&gt;
&lt;/form&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.dev360.com/2009/06/15/manytomanyfield-and-ordered-fields-in-django-modelforms/feed/</wfw:commentRss>
		</item>
		<item>
		<title>ImageField not validating in Django ModelForm</title>
		<link>http://blog.dev360.com/2009/06/05/imagefield-not-validating-in-django-modelform/</link>
		<comments>http://blog.dev360.com/2009/06/05/imagefield-not-validating-in-django-modelform/#comments</comments>
		<pubDate>Fri, 05 Jun 2009 15:21:19 +0000</pubDate>
		<dc:creator>Christian Toivola</dc:creator>
		
		<category><![CDATA[Django]]></category>

		<category><![CDATA[ModelForm]]></category>

		<guid isPermaLink="false">http://blog.dev360.com/?p=143</guid>
		<description><![CDATA[The other day I was working on a Django ModelForm that had an ImageField in it and to my great surprise the ImageField would not validate in the ModelForm, even when I had selected an image. The solution was simple enough: add request.FILES to the instantiation parameters of the ModelForm.. DUH!

    #ProfileForm [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I was working on a Django ModelForm that had an ImageField in it and to my great surprise the ImageField would not validate in the ModelForm, even when I had selected an image. The solution was simple enough: add request.FILES to the instantiation parameters of the ModelForm.. DUH!</p>
<pre>
    #ProfileForm is a ModelForm
    form = ProfileForm(request.POST, request.FILES, instance=profile)
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.dev360.com/2009/06/05/imagefield-not-validating-in-django-modelform/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Rendering a RSS feed in Django</title>
		<link>http://blog.dev360.com/2009/05/24/rendering-a-rss-feed-in-django/</link>
		<comments>http://blog.dev360.com/2009/05/24/rendering-a-rss-feed-in-django/#comments</comments>
		<pubDate>Mon, 25 May 2009 01:47:36 +0000</pubDate>
		<dc:creator>Christian Toivola</dc:creator>
		
		<category><![CDATA[Django]]></category>

		<category><![CDATA[RSS]]></category>

		<guid isPermaLink="false">http://blog.dev360.com/?p=139</guid>
		<description><![CDATA[I have been working to get the new version of DEV360.com out the door and found myself in need of displaying RSS items from my Wordpress-powered blog on the DEV360 site which is developed in Django.
There were two libraries that I found for parsing RSS; RSS.py by Mark Nottingham which unfortunately didn&#8217;t support RSS 2.0, [...]]]></description>
			<content:encoded><![CDATA[<p>I have been working to get the new version of DEV360.com out the door and found myself in need of displaying RSS items from my Wordpress-powered blog on the DEV360 site which is developed in Django.</p>
<p>There were two libraries that I found for parsing RSS; RSS.py by Mark Nottingham which unfortunately didn&#8217;t support RSS 2.0, and Mark Pilgrim&#8217;s <a href="http://www.feedparser.org/">feedparser.py</a>. I settled on the latter since it contains more features, has easier syntax and has better unit-test coverage.</p>
<p>For what I&#8217;m doing, a template tag works out best for rendering the RSS items; let&#8217;s fast-forward to the code:</p>
<p><strong>foo.html:</strong></p>
<pre>
{% load rss_feed %}
{% rss_feed %}
</pre>
<p><strong>[application]/templatetags.py:</strong></p>
<pre>
import feedparser
from datetime import datetime
from django.template import Library, Node
register = Library()

@register.simple_tag
def rss_feed(itemCount=5):
	channel = feedparser.parse('http://blog.dev360.com/feed/')

	html = []
	html.append('&lt;div id="rss-feed"&gt;')
	html.append('	&lt;h1&gt;Latest blog posts&lt;/h1&gt;')
	html.append('	&lt;ul&gt;')
	for entry in channel.entries[:itemCount]:
		url = entry.id
		title = entry.title
		date = datetime.strptime(entry.date, "%a, %d %b %Y %H:%M:%S +0000");
		html.append('&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;a href="%s"&gt;%s&lt;/a&gt;&lt;/strong&gt;' % (url, title));
		html.append('%s&lt;/p&gt;&lt;/li&gt;' % (date.strftime("%B %d, %Y")))

	html.append('	&lt;/ul&gt;')
	html.append('&lt;/div&gt;')
	return "\n".join(html)
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.dev360.com/2009/05/24/rendering-a-rss-feed-in-django/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Non-obtrusive JS rollovers with jQuery</title>
		<link>http://blog.dev360.com/2009/05/22/non-obtrusive-js-rollovers-with-jquery/</link>
		<comments>http://blog.dev360.com/2009/05/22/non-obtrusive-js-rollovers-with-jquery/#comments</comments>
		<pubDate>Fri, 22 May 2009 17:09:14 +0000</pubDate>
		<dc:creator>Christian Toivola</dc:creator>
		
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://blog.dev360.com/?p=135</guid>
		<description><![CDATA[I thought I&#8217;d share a technique that I have grown very fond of over the last year - all made possible by jQuery&#8217;s syntactic bliss.
On many occassions in the past, I have found myself writing roll-over code that looks something like this:

&#60;ul class="navigation"&#62;
  &#60;li onmouseover="this.className='selected';" onmouseout="this.className='';" class="selected"&#62;&#60;a href="#"&#62;Link 1&#60;/a&#62;&#60;/li&#62;
  &#60;li onmouseover="this.className='selected';" onmouseout="this.className='';"&#62;&#60;a href="#"&#62;Link [...]]]></description>
			<content:encoded><![CDATA[<p>I thought I&#8217;d share a technique that I have grown very fond of over the last year - all made possible by jQuery&#8217;s syntactic bliss.</p>
<p>On many occassions in the past, I have found myself writing roll-over code that looks something like this:</p>
<pre>
&lt;ul class="navigation"&gt;
  &lt;li onmouseover="this.className='selected';" onmouseout="this.className='';" class="selected"&gt;&lt;a href="#"&gt;Link 1&lt;/a&gt;&lt;/li&gt;
  &lt;li onmouseover="this.className='selected';" onmouseout="this.className='';"&gt;&lt;a href="#"&gt;Link 2&lt;/a&gt;&lt;/li&gt;
  &lt;li onmouseover="this.className='selected';" onmouseout="this.className='';"&gt;&lt;a href="#"&gt;Link 3&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</pre>
<p>As you can see, the onmouseover/onmouseout makes the code less readable and takes up a lot of unnecessary space. One way to get rid of it is obviously to take advantage of the :hover pseudo class on the a element but if you want the hovered item to be the only item marked with the <code>selected</code> class then obviously that solution doesn&#8217;t cut it.</p>
<p>jQuery&#8217;s event wiring, along with its selector syntax allows you to remove the onmouse**** tags and earn some well deserved HTML karma.</p>
<p><strong>JS</strong></p>
<pre>
$lastActiveItem = null;
jQuery(document).ready(function(){
	$('.navigation li').mouseover(function(){
		$lastActiveItem = $('.navigation li.selected');
		$('.navigation li').removeClass('selected');
		$(this).addClass('selected');
	});

	$('.navigation li').mouseout(function(){
		$('.navigation li').removeClass('selected')
		$lastActiveItem.addClass('selected')
	});
});
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.dev360.com/2009/05/22/non-obtrusive-js-rollovers-with-jquery/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Ignoring deprecation warnings in Twill/Python</title>
		<link>http://blog.dev360.com/2009/05/19/supressing-deprecation-warnings-in-twill-or-python/</link>
		<comments>http://blog.dev360.com/2009/05/19/supressing-deprecation-warnings-in-twill-or-python/#comments</comments>
		<pubDate>Tue, 19 May 2009 17:51:26 +0000</pubDate>
		<dc:creator>Christian Toivola</dc:creator>
		
		<category><![CDATA[Python]]></category>

		<category><![CDATA[Twill]]></category>

		<guid isPermaLink="false">http://blog.dev360.com/?p=133</guid>
		<description><![CDATA[I wrote a small command-line utility with Twill and Python that I use to scrape prices from our booking engine at work. The Python script worked fine when I ran it on my Mac/Python2.5 but Twill (or mechanize, to be exact) was giving deprecation warnings when I tried to run it on Windows/Python2.6.1.

C:\Users\Administrator\twill\other_packages\_mechanize_dist\_auth.py:14: DeprecationWarning: the [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote a small command-line utility with Twill and Python that I use to scrape prices from our booking engine at work. The Python script worked fine when I ran it on my Mac/Python2.5 but Twill (or mechanize, to be exact) was giving deprecation warnings when I tried to run it on Windows/Python2.6.1.</p>
<pre>
C:\Users\Administrator\twill\other_packages\_mechanize_dist\_auth.py:14: DeprecationWarning: the md5 module is deprecated; use hashlib instead import re, base64, urlparse, posixpath, md5, sha, sys, copy
C:\Users\Administrator\twill\other_packages\_mechanize_dist\_auth.py:14: DeprecationWarning: the sha module is deprecated; use the hashlib module instead import re, base64, urlparse, posixpath, md5, sha, sys, copy</pre>
<p>The solution is trivial; to supress deprecation warnings in python, just add an ingore filter <strong>before</strong> the line where you import Twill (or any other offending library). The alert reader may notice that the second part of the filterwarnings argument (&#8217;.*&#8217;) is a regular expression; this would allow you to tailor exactly which deprecation warnings you wish to propagate to the command-line.</p>
<pre>
import warnings
warnings.filterwarnings('ignore', '.*')

from twill.commands import *
import twill
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.dev360.com/2009/05/19/supressing-deprecation-warnings-in-twill-or-python/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Wolfram&#124;Alpha - A New Kind of Search Engine?</title>
		<link>http://blog.dev360.com/2009/05/04/wolframalpha-a-new-kind-of-search-engine/</link>
		<comments>http://blog.dev360.com/2009/05/04/wolframalpha-a-new-kind-of-search-engine/#comments</comments>
		<pubDate>Mon, 04 May 2009 20:36:34 +0000</pubDate>
		<dc:creator>Christian Toivola</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.dev360.com/?p=114</guid>
		<description><![CDATA[I just read about a new search AI dubbed Wolfram Alpha (WolframAlpha.com) in an article that was published on Sunday May 3 in The Independent. It talks about this new search engine AI invented by Dr. Stephen Wolfram which supposedly &#8220;understands and responds to ordinary language in the same way a person does&#8221;. Skimming through [...]]]></description>
			<content:encoded><![CDATA[<p>I just read about a new search AI dubbed Wolfram Alpha (WolframAlpha.com) in an <a href="http://www.independent.co.uk/life-style/gadgets-and-tech/news/an-invention-that-could-change-the-internet-for-ever-1678109.html">article</a> that was published on Sunday May 3 in The Independent. It talks about this new search engine AI invented by Dr. Stephen Wolfram which supposedly &#8220;understands and responds to ordinary language in the same way a person does&#8221;. Skimming through the article, I can&#8217;t remember getting this excited about a site since learning about the <a href="http://http://www.freebase.com/view/en/documentation">MetaWeb/Freebase API</a>, but after scratching the surface a little bit, the excitement faded away very quickly.</p>
<p>Let me start by saying that I can&#8217;t say that I&#8217;m very knowledgeable or up to date when it comes to the academic research on the subject - apart from following a few AI and Semantic Web blogs. Now, the thing that immediately raised my eyebrows was a little time line of the history of the Internet which listed a handful of milestones - with the most recent item reading &#8220;<strong>2009</strong> Dr Stephen Wolfram launches Wolfram Alpha.&#8221;, listed right after the traditional stuff that you would expect to see (ARPANET, first PC etc). For a site that is not even public (as of Monday May 4, 2009), it seems awfully rash to have it on a list like that.</p>
<p>Reading the fine print confirmed more and more of my skepticism. For instance, Dr. Wolfram admits that information in the engine is first &#8220;curated&#8221; or assessed by experts AND it also requires approximately 1,000 people for maintaining the site&#8217;s databases and keeping current with new information. All this begs to question how <em>exactly</em> is this an AI or <em>anything</em> revolutionary? And to top that off, the end of the article mentions that Google already is working on something similar which is <em>already live</em>. Wow! - Revolutionary - let&#8217;s credit Dr. Wolfram and say a loud Amen.</p>
<p>A person&#8217;s past is perhaps the best way to look for clues and Dr. Wolfram is no exception. This is where Dr. Dubya appears to have a solid track record as a self-indulgent hype machine. Consider for instance the overwhelmingly <a href="http://www.amazon.com/New-Kind-Science-Stephen-Wolfram/product-reviews/1579550088/ref=dp_top_cm_cr_acr_pop_hist_all?ie=UTF8&amp;showViewpoints=1#RUGSCP3XBNBUV">negative feedback</a> and <a href="http://en.wikipedia.org/wiki/A_New_Kind_of_Science#Originality_and_self-image">concerns about originality</a> for his supposedly epic &#8216;10 years in the making&#8217; book ironically titled &#8220;A New Kind of Science&#8221;. A New Kind of Search-Engine? - No, I doubt so.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.dev360.com/2009/05/04/wolframalpha-a-new-kind-of-search-engine/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Unable to SSH to EC2 Fedora 8 instance</title>
		<link>http://blog.dev360.com/2009/01/09/unable-to-ssh-to-ec2-fedora-8-instance/</link>
		<comments>http://blog.dev360.com/2009/01/09/unable-to-ssh-to-ec2-fedora-8-instance/#comments</comments>
		<pubDate>Fri, 09 Jan 2009 19:54:41 +0000</pubDate>
		<dc:creator>Christian Toivola</dc:creator>
		
		<category><![CDATA[EC2]]></category>

		<category><![CDATA[Fedora]]></category>

		<guid isPermaLink="false">http://blog.dev360.com/?p=92</guid>
		<description><![CDATA[A few months ago when I wanted to log into my EC2 Fedora 8 instance, Putty as well as the Terminal in OS X started greeting me with the message &#8216;Server refused to allocate pty&#8217;. Apparently the new version of the EC2 Bundling files had changed the FSTAB file which caused this error to occur.
The [...]]]></description>
			<content:encoded><![CDATA[<p>A few months ago when I wanted to log into my EC2 Fedora 8 instance, Putty as well as the Terminal in OS X started greeting me with the message &#8216;Server refused to allocate pty&#8217;. <a href="http://developer.amazonwebservices.com/connect/message.jspa?messageID=84513">Apparently</a> the new version of the EC2 Bundling files had changed the FSTAB file which caused this error to occur.</p>
<p>The only way I was able to connect to the server was with SCP and the Windows client WinSCP actually somehow managed to give me SSH access. For some reason I post-poned this fix for the longest time and just used WinSCP&#8217;s SSH access, but 3 days ago I decided to do something about it. First, I backed up my /etc/fstab file and used WinSCP to edit it to say:</p>
<pre>/dev/sda1               /                       ext3    defaults 1 1
/dev/sda2               /mnt                    ext3    defaults 0 0
/dev/sda3               swap                    swap    defaults 0 0
none                    /dev/pts                devpts  gid=5,mode=620 0 0
none                    /dev/shm                tmpfs   defaults 0 0
none                    /proc                   proc    defaults 0 0
none                    /sys                    sysfs   defaults 0 0</pre>
<p>After that, just reboot your instance and you will be able to log in as usual again.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.dev360.com/2009/01/09/unable-to-ssh-to-ec2-fedora-8-instance/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Running Apache in 32-bit mode on OS X</title>
		<link>http://blog.dev360.com/2009/01/08/running-apache-in-32-bit-mode-on-mac-os-x/</link>
		<comments>http://blog.dev360.com/2009/01/08/running-apache-in-32-bit-mode-on-mac-os-x/#comments</comments>
		<pubDate>Thu, 08 Jan 2009 20:28:14 +0000</pubDate>
		<dc:creator>Christian Toivola</dc:creator>
		
		<category><![CDATA[Mac OS X]]></category>

		<guid isPermaLink="false">http://blog.dev360.com/?p=83</guid>
		<description><![CDATA[By default, Mac OS X runs Apache in 64-bit mode. Unfortunately, there are a handful of apache mods that are only available as 32-bit downloads and they can be a bit challenging to modify and recompile in 64-bit unless you are confident with the compiler.
Mod_python is one of those mods - and it also happens [...]]]></description>
			<content:encoded><![CDATA[<p>By default, Mac OS X runs Apache in 64-bit mode. Unfortunately, there are a handful of apache mods that are only available as 32-bit downloads and they can be a bit challenging to modify and recompile in 64-bit unless you are confident with the compiler.</p>
<p>Mod_python is one of those mods - and it also happens to be something that I rely on for my development environment on the Mac. The following is the command to change from 64-bit to 32-bit:</p>
<pre>
sudo mv /usr/sbin/httpd /usr/sbin/httpd.bkp
sudo lipo -thin i386 /usr/sbin/httpd.bkp -output /usr/sbin/httpd.i386
sudo ln -s /usr/sbin/httpd.i386 /usr/sbin/httpd</pre>
</pre>
<p>Unfortunately, I have noticed that Apache goes back to 64-bit mode each time I run a system update. It probably restores the original httpd file. It might go away if you use the actual file and not the sym-link, but I just run the command again.</p>
<p>Use this command if you want to revert back to 64-bit:</p>
<pre>sudo mv /usr/sbin/httpd.bkp /usr/sbin/httpd</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.dev360.com/2009/01/08/running-apache-in-32-bit-mode-on-mac-os-x/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Is code generation evil?</title>
		<link>http://blog.dev360.com/2009/01/08/is-code-generation-evil/</link>
		<comments>http://blog.dev360.com/2009/01/08/is-code-generation-evil/#comments</comments>
		<pubDate>Thu, 08 Jan 2009 15:07:46 +0000</pubDate>
		<dc:creator>Christian Toivola</dc:creator>
		
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://blog.dev360.com/?p=54</guid>
		<description><![CDATA[A few weeks ago I had an interesting exchange with a friend of mine concerning code generation. This post echoes some of the thoughts and perhaps reservations that I have towards the practice.
So what exactly do I mean by the term code generation? Code generation is the practice whereby a tool or a script generates [...]]]></description>
			<content:encoded><![CDATA[<p>A few weeks ago I had an interesting exchange with a friend of mine concerning code generation. This post echoes some of the thoughts and perhaps reservations that I have towards the practice.</p>
<p>So what exactly do I mean by the term code generation? Code generation is the practice whereby a tool or a script generates source code from templates as opposed to typing the code by hand. One example would be of a script that examines the columns in a table and creates a stored procedure. A more extreme case would be an <acronym title="Model Driven Architecture">MDA</acronym>/<acronym title="Model Code Deploy">MCD</acronym> tool like Visual Paradigm.</p>
<h3>Learning the hard way</h3>
<p>A few months ago I was tasked with developing a large application for one of my clients that made use of extensive model taxonomies that also required a management interface.</p>
<p>With a good ORM and some thought behind the persistence mechanism, we were able to leverage a lot of reusable code that gave us a unified, <accronom title="Don't Repeat Yourself">DRY</accronom> approach to persistence, validation, search queries, caching, lazy row-fetching and transactional operations. Only one daunting task remained and that was the UI. Again, we did our due diligence and came up with some useful generic base classes for Save/Update/List views but even so, the amount of fields on each Save/Update view was staggering and it was incredibly time-consuming to add them all. At some point when I had done about 10% of the work, I started realizing how genuinely tedious the task was. Integers would always be rendered as asp:TextBox accompanied by an asp:RegularExpressionValidator, one-to-many relationships would use a select-box or auto-complete widget and so forth and so on.</p>
<p>Knowing that my models’ members were lush with juicy meta data defined via attributes, I decided to use introspection to generate the code for the views. It took me about 2 weeks to write an IronPython script that could make sense of all the various types, validation attributes and implicit rules in my DLL. Once I had that, the rest was pretty easy. A single command would spit out thousands of lines of HTML and C#, but it still required modifications here and there since there were spots of non-standard behavior.</p>
<p>We now we have some 60 views that contain <strong>a lot</strong> of tedious code. As soon as something changes in our model, we still have to update the templates to reflect new validation rules or object definitions. It’s not as simple as re-generating the views because that would overwrite changes that have been made. I&#8217;m not ashamed of the quality of the code - with the abstractions that are already there its far exceeding the level of quality that you would expect from our average .NET developer. What bothers me is the sheer size and complexity which threatens to turn this code into an unmaintainable mess and a recipe for failure in the long run.</p>
<p>What went wrong? For starters, the problem wasn’t <em>how</em> to create hundreds of lines of HTML in each view – the appropriate question was <em>why</em>. To use a common anology – I was curing the symptom, not the disease. The real problem I was trying to solve was the severe GUI/Model impedance mismatch in my web-framework, ASP.NET. Had I been brave enough then I could just have used those two weeks wrangling with ViewState to come up with a well thought out, Reflection-based Form abstraction like the one found in Django.</p>
<h3>Conclusion</h3>
<p>In many instances code generation is an appropriate solution to a repetitive task, but first you have to ask yourself why you want to use it. If it’s solving a time-consuming, reoccurring task of low complexity then go ahead and use it, but implore yourself to look beyond the immediate problem at hand. You will be surprised to find out that frequently, the problems you are trying to solve are far more systemic and can be solved more elegantly by adopting a useful abstraction instead.</p>
<p>Code-generation can be a divisive and destructive approach to programming when applied systematically in a development environment or development methodology. Programming should not be viewed as a necessary evil as this fosters the wrong mind-set. It tends to put developers in two camps – one that knows how to solve problems and one that just knows a tool - most people who interview and hire programmers can attest to this.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.dev360.com/2009/01/08/is-code-generation-evil/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
