<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>muhuk.com &#187; Programming</title>
	<atom:link href="http://www.muhuk.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.muhuk.com</link>
	<description>know thyself</description>
	<lastBuildDate>Thu, 29 Dec 2011 05:05:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Working with files in Django &#8211; Part 3</title>
		<link>http://www.muhuk.com/2011/11/working-with-files-in-django-part-3/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=working-with-files-in-django-part-3</link>
		<comments>http://www.muhuk.com/2011/11/working-with-files-in-django-part-3/#comments</comments>
		<pubDate>Wed, 30 Nov 2011 00:02:14 +0000</pubDate>
		<dc:creator>Atamert Ölçgen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[media]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.muhuk.com/?p=463</guid>
		<description><![CDATA[First part of this article is here. How to add STATIC files You will most likely add STATIC files to your source code repository. As they are likely to be hardcoded in your code and templates it is a good idea to keep those and your STATIC files in sync. Your STATIC files are collected [...]<div><a class="addthis_button" href="//addthis.com/bookmark.php?v=250" addthis:url='http://www.muhuk.com/2011/11/working-with-files-in-django-part-3/' addthis:title='Working with files in Django &#8211; Part 3 '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div>]]></description>
			<content:encoded><![CDATA[<p><small>First part of this article is <a href="http://www.muhuk.com/2011/11/working-with-files-in-django/">here</a>.</small></p>

<h2>How to add STATIC files</h2>

<p>You will most likely add <code>STATIC</code> files to your source code repository. As they are likely to be hardcoded in your code and templates it is a good idea to keep those and your <code>STATIC</code> files in sync.</p>

<p>Your <code>STATIC</code> files are collected (found and copied or symlinked) with the help of <a href="https://docs.djangoproject.com/en/1.3/ref/contrib/staticfiles/#staticfiles-finders">finders</a>. This <em>collection</em> process might be a little confusing for you. Basically you don&#8217;t need to worry about where your files are copied, you just need to maintain the files in the locations I mention below. Collection process consolidates all your <code>STATIC</code> files for you, and it does it automatically.</p>

<p>If you are developing a reusable app place your <code>STATIC</code> files under the <code>static</code> directory. Your app directory should look like this:</p>

<pre><code>$ ls -1
models.py
static/
templates/
views.py
</code></pre>

<p>If you are developing a project absolute filesystem paths listed in your <code>STATICFILES_DIRS</code> setting will be collected:</p>

<pre><code>&gt;&gt;&gt; from django.conf import settings
&gt;&gt;&gt; settings.STATICFILES_DIRS
('/opt/myproject/src/project/static',)
</code></pre>

<p>One important thing to note, as I mentioned in the first part, is to set your <code>STATIC_ROOT</code> outside of your project directory. This is the location where all the <code>STATIC</code> files found will be consolidated. Making this directory independent from your project installation enabled its reuse.</p>

<h2>How to upload MEDIA files</h2>

<p>MEDIA files are typically uploaded by users when the project is online and a reference is stored in a model field. While this is true most of the time, <code>MEDIA</code> files can be generated by code and/or a reference can be provided in some other way that doesn&#8217;t involve models. But these edge cases are out of the scope of this post.</p>

<p>The easiest way to allow users upload their files is to use a <a href="https://docs.djangoproject.com/en/1.3/ref/models/fields/#filefield">FileField</a> or <a href="https://docs.djangoproject.com/en/1.3/ref/models/fields/#imagefield">ImageField</a> on a model and <a href="https://docs.djangoproject.com/en/dev/topics/forms/modelforms/">derive a form</a> from it:</p>

<pre><code>from django.db import models
from django.forms.models import modelform_factory


class MediaModel(models.Model):
    media_file = models.FileField(upload_to='user_media')


MediaForm = modelform_factory(MediaModel)
</code></pre>

<p>You can then use this form to provide upload functionality:</p>

<pre><code>def media_create(request):
    if request.method == "POST":
        form = MediaForm(request.POST, request.FILES)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('media-list'))
    else:
        form = MediaForm()
    return render_to_response('usermedia/create/html', {'form': form})
</code></pre>

<p>Of course it is better to use a generic <a href="https://docs.djangoproject.com/en/1.3/ref/class-based-views/#createview">CreateView</a> now we have them with Django 1.3. I wanted to emphasize one point and avoid the complexities of a class based view; you must pass <code>request.FILES</code> to the form&#8217;s constructor. Actually this is a good practice whether or not your form has an file field.</p>

<p>As in the case with <code>STATIC</code> files, <code>MEDIA_ROOT</code> should be in a location seperate from your project files. If you delete your project directory you would also lose <code>MEDIA</code> files otherwise.</p>

<h2>Conclusion</h2>

<p>This concludes <a href="">Working with files in Django</a>. I hope these posts are helpful to you. Once you are comfortable working with files I strongly recommend you to take a look at <a href="http://django_compressor.readthedocs.org/en/latest/index.html">Django Compressor</a></p>

<p><small>If you enjoyed this post please <a href="http://www.muhuk.com/about-you/">tell me a little bit about yourself</a>.</small></p>
<div><a class="addthis_button" href="http://www.muhuk.com//addthis.com/bookmark.php?v=250" addthis:url='http://www.muhuk.com/2011/11/working-with-files-in-django-part-3/' addthis:title='Working with files in Django &#8211; Part 3 '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div><p>Related posts:<ol>
<li><a href='http://www.muhuk.com/2011/11/working-with-files-in-django/' rel='bookmark' title='Working with files in Django &#8211; Part 1'>Working with files in Django &#8211; Part 1</a></li>
<li><a href='http://www.muhuk.com/2011/11/working-with-files-in-django-part-2/' rel='bookmark' title='Working with files in Django &#8211; Part 2'>Working with files in Django &#8211; Part 2</a></li>
<li><a href='http://www.muhuk.com/2011/06/pycon-apac-optimizing-media-performance-with-django_compressor/' rel='bookmark' title='My PyCon APAC 2011 Presentation: Optimizing Media Performance with django_compressor'>My PyCon APAC 2011 Presentation: Optimizing Media Performance with django_compressor</a></li>
</ol></p> <p><a href="http://www.muhuk.com/?flattrss_redirect&amp;id=463&amp;md5=690eb5cb2faa6e3c87eab634b34a4348" title="Flattr" target="_blank"><img src="http://www.muhuk.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.muhuk.com/2011/11/working-with-files-in-django-part-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="http://www.muhuk.com/?flattrss_redirect&amp;id=463&amp;md5=690eb5cb2faa6e3c87eab634b34a4348" type="text/html" />
	</item>
		<item>
		<title>Working with files in Django &#8211; Part 2</title>
		<link>http://www.muhuk.com/2011/11/working-with-files-in-django-part-2/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=working-with-files-in-django-part-2</link>
		<comments>http://www.muhuk.com/2011/11/working-with-files-in-django-part-2/#comments</comments>
		<pubDate>Sat, 26 Nov 2011 08:31:08 +0000</pubDate>
		<dc:creator>Atamert Ölçgen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[media]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.muhuk.com/?p=461</guid>
		<description><![CDATA[First part of this article is here. How to setup file serving for development server As I mentioned earlier, it is best to serve files on a fast HTTP server. But this setup is overkill for development environments, you can safely let Django handle your files. The snippet below relies on the assumption, behind the [...]<div><a class="addthis_button" href="//addthis.com/bookmark.php?v=250" addthis:url='http://www.muhuk.com/2011/11/working-with-files-in-django-part-2/' addthis:title='Working with files in Django &#8211; Part 2 '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div>]]></description>
			<content:encoded><![CDATA[<p><small>First part of this article is <a href="http://www.muhuk.com/2011/11/working-with-files-in-django/">here</a>.</small></p>

<h2>How to setup file serving for development server</h2>

<p>As I mentioned earlier, it is best to serve files on a fast HTTP server. But this setup is overkill for development environments, you can safely let Django handle your files. The snippet below relies on the assumption, behind the scenes, that <code>DEBUG</code> is always <code>True</code> in development environment and it is always <code>False</code> in production environment. It should be fine for the purposes of this post:</p>

<pre><code>from django.conf.urls.static import static
from django.contrib.staticfiles.urls import staticfiles_urlpatterns

urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += staticfiles_urlpatterns()
</code></pre>

<p>It is quite straightforward. Nothing gets added to <code>urlpatterns</code> unless <code>DEBUG</code> is <code>True</code> <strong>and</strong> prefix (<code>MEDIA_URL</code> and <code>STATIC_URL</code>) is not a fully qualified URL.</p>

<h2>How to reference <code>STATIC</code> files in templates</h2>

<p>There are two ways to reference any file. You can use a file&#8217;s location in your file storage (your filesystem for example) for internal use. Or you can build a URL for the file so that clients can access it. This post will cover the latter, as the former is a simple matter of applying <code>os.path.join()</code> to <code>STATIC_ROOT</code> and the particular file&#8217;s path.</p>

<p>To build a URL in your templates you can simply concetenate <code>STATIC_URL</code> with the file&#8217;s relative location to it:</p>

<pre><code>&lt;img src="{{ STATIC_URL }}myapp/img/logo.png" /&gt;
</code></pre>

<p>However, to have <code>STATIC_URL</code> available within your template context you need to make sure of two things:</p>

<ul>
<li>The template needs to be rendered with a <a href="https://docs.djangoproject.com/en/1.3/ref/templates/api/#django.template.RequestContext">RequestContext</a>.</li>
<li><code>django.core.context_processors.static</code> needs to be included in <code>TEMPLATE_CONTEXT_PROCESSORS</code> setting.</li>
</ul>

<p>I can&#8217;t think of a reason why, but if for some reason you are not using <code>RequestContext</code>, you can provide <code>STATIC_URL</code> using <a href="https://docs.djangoproject.com/en/1.3/ref/contrib/staticfiles/#the-get-static-prefix-templatetag">get<em>static</em>prefix</a> tag:</p>

<pre><code>{% load static %}
{% get_static_prefix as STATIC_URL %}

&lt;img src="{{ STATIC_URL }}myapp/img/logo.png" /&gt;
</code></pre>

<h2>How to reference MEDIA files in templates</h2>

<p>Dealing with <code>MEDIA</code> files is much simpler. The <code>FieldFile</code> object returned by <code>ImageField</code> and <code>FileField</code> has <code>path</code> and <code>url</code> properties and you don&#8217;t need to do concetenation yourself:</p>

<pre><code>&lt;img src="{{ some_model.some_image_field.url }}" /&gt;
</code></pre>

<p><small><a href="http://www.muhuk.com/2011/11/working-with-files-in-django-part-3/">Next part</a> deals with adding files to your project.</small></p>

<p><small>If you enjoyed this post please <a href="http://www.muhuk.com/about-you/">tell me a little bit about yourself</a>.</small></p>
<div><a class="addthis_button" href="http://www.muhuk.com//addthis.com/bookmark.php?v=250" addthis:url='http://www.muhuk.com/2011/11/working-with-files-in-django-part-2/' addthis:title='Working with files in Django &#8211; Part 2 '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div><p>Related posts:<ol>
<li><a href='http://www.muhuk.com/2011/11/working-with-files-in-django/' rel='bookmark' title='Working with files in Django &#8211; Part 1'>Working with files in Django &#8211; Part 1</a></li>
<li><a href='http://www.muhuk.com/2011/11/working-with-files-in-django-part-3/' rel='bookmark' title='Working with files in Django &#8211; Part 3'>Working with files in Django &#8211; Part 3</a></li>
<li><a href='http://www.muhuk.com/2011/06/pycon-apac-optimizing-media-performance-with-django_compressor/' rel='bookmark' title='My PyCon APAC 2011 Presentation: Optimizing Media Performance with django_compressor'>My PyCon APAC 2011 Presentation: Optimizing Media Performance with django_compressor</a></li>
</ol></p> <p><a href="http://www.muhuk.com/?flattrss_redirect&amp;id=461&amp;md5=44a4b62c499b1c44896e9f38748575eb" title="Flattr" target="_blank"><img src="http://www.muhuk.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.muhuk.com/2011/11/working-with-files-in-django-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="http://www.muhuk.com/?flattrss_redirect&amp;id=461&amp;md5=44a4b62c499b1c44896e9f38748575eb" type="text/html" />
	</item>
		<item>
		<title>Working with files in Django &#8211; Part 1</title>
		<link>http://www.muhuk.com/2011/11/working-with-files-in-django/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=working-with-files-in-django</link>
		<comments>http://www.muhuk.com/2011/11/working-with-files-in-django/#comments</comments>
		<pubDate>Mon, 21 Nov 2011 10:47:18 +0000</pubDate>
		<dc:creator>Atamert Ölçgen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[media]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.muhuk.com/?p=453</guid>
		<description><![CDATA[In this post what I mean by file is any content that is not dynamically generated. There are basically two types of files a web application deals with: Files that are hard coded in templates or in code. We will call them STATIC files. Files that are referenced in the code but only known in [...]<div><a class="addthis_button" href="//addthis.com/bookmark.php?v=250" addthis:url='http://www.muhuk.com/2011/11/working-with-files-in-django/' addthis:title='Working with files in Django &#8211; Part 1 '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div>]]></description>
			<content:encoded><![CDATA[<p>In this post what I mean by <code>file</code> is any content that is not dynamically generated. There are basically two types of files a web application deals with:</p>

<ul>
<li>Files that are hard coded in templates or in code. We will call them <code>STATIC</code> files.</li>
<li>Files that are referenced in the code but only known in the run time. We will call them <code>MEDIA</code> files.</li>
</ul>

<p>Now of course all these files are static and most of them can be classified as media, but I chose those terms because that more or less how they are referred to in <a href="https://docs.djangoproject.com/en/1.3/">Django documentation</a>.</p>

<p>Since files are stored on disk or some other <a href="https://docs.djangoproject.com/en/1.3/ref/files/storage/">storage backend</a> it is best to <a href="https://docs.djangoproject.com/en/1.3/howto/static-files/#serving-static-files-from-a-dedicated-server">serve them on a fast HTTP server</a> and let Django handle only dynamic content.</p>

<h2>How to configure STATIC/MEDIA related settings</h2>

<p>Let&#8217;s look at some code first and we can comment on it afterwards. I use the following setup in my projects:</p>

<pre><code>import os

_PATH = os.path.abspath(os.path.dirname(__file__))

MEDIA_ROOT = os.path.join(_PATH, 'files', 'media')
MEDIA_URL = '/media/'

STATIC_ROOT = os.path.join(_PATH, 'files', 'static')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
    os.path.join(_PATH, 'static'),
)
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)

ADMIN_MEDIA_PREFIX = '/static/admin/'
</code></pre>

<p><code>_PATH</code> should be obvious. But the way I use it is a little tricky here. Basically I am using a <code>files</code> directory that contains <code>media</code>, for <code>MEDIA</code> files, and <code>static</code>, for <code>STATIC</code> files, directories. This seperation is essential. You will pull your hair if you don&#8217;t seperate those two from the beginning. This will allow you to reuse them easily if you deploy a new version to a different location.</p>

<p>But why is <code>files</code> under the project directory? Because we need to check-in <code>STATIC</code> files? NO! It is just a convenience for the development environments. I strongly suggest overriding <code>MEDIA_ROOT</code> and <code>STATIC_ROOT</code> in your deployment settings and basically move the <code>files</code> directory outside of the project path. <code>STATIC</code> files that we check-in resides in <code>&lt;_PATH&gt;/static</code>. <a href="https://docs.djangoproject.com/en/1.3/ref/contrib/staticfiles/"><code>django.contrib.staticfiles</code></a> app collects your <code>STATIC</code> files from your project specific directories and within your apps and copies everything in the right places inside <code>STATIC_ROOT</code>.</p>

<p>To sum up the points above:</p>

<ul>
<li>Check-in <code>STATIC</code> files in a folder within your project directory (see <code>STATICFILES_DIRS</code> &amp; <code>FileSystemFinder</code>). If you are <a href="http://www.muhuk.com/2010/01/developing-reusable-django-apps/">developing an app</a> <code>AppDirectoriesFinder</code> will collect static files within the <code>static</code> directory in your app directory.</li>
<li>Seperate the directories, where your <code>MEDIA</code> files are saved and where your <code>STATIC</code> files are collected (see <code>STATIC_ROOT</code> &amp; <code>MEDIA_ROOT</code>).</li>
<li>Keep your <code>STATIC_ROOT</code> and <code>MEDIA_ROOT</code> outside of your project directory in production environment.</li>
</ul>

<p>One more thing to note is <code>STATIC_URL</code> and <code>MEDIA_URL</code> should both have a trailing slash. This will save you a lot of trouble later.</p>

<p><small><a href="http://www.muhuk.com/2011/11/working-with-files-in-django-part-2/">Next part</a> deals with serving files in development environment and referencing them in code and templates.</small></p>

<p><small>If you enjoyed this post please <a href="http://www.muhuk.com/about-you/">tell me a little bit about yourself</a>.</small></p>
<div><a class="addthis_button" href="http://www.muhuk.com//addthis.com/bookmark.php?v=250" addthis:url='http://www.muhuk.com/2011/11/working-with-files-in-django/' addthis:title='Working with files in Django &#8211; Part 1 '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div><p>Related posts:<ol>
<li><a href='http://www.muhuk.com/2011/11/working-with-files-in-django-part-2/' rel='bookmark' title='Working with files in Django &#8211; Part 2'>Working with files in Django &#8211; Part 2</a></li>
<li><a href='http://www.muhuk.com/2011/11/working-with-files-in-django-part-3/' rel='bookmark' title='Working with files in Django &#8211; Part 3'>Working with files in Django &#8211; Part 3</a></li>
<li><a href='http://www.muhuk.com/2011/06/pycon-apac-optimizing-media-performance-with-django_compressor/' rel='bookmark' title='My PyCon APAC 2011 Presentation: Optimizing Media Performance with django_compressor'>My PyCon APAC 2011 Presentation: Optimizing Media Performance with django_compressor</a></li>
</ol></p> <p><a href="http://www.muhuk.com/?flattrss_redirect&amp;id=453&amp;md5=f0a4d9fd68404a3679f5ab10b5700a81" title="Flattr" target="_blank"><img src="http://www.muhuk.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.muhuk.com/2011/11/working-with-files-in-django/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="http://www.muhuk.com/?flattrss_redirect&amp;id=453&amp;md5=f0a4d9fd68404a3679f5ab10b5700a81" type="text/html" />
	</item>
		<item>
		<title>Sign of a Stupid Programmer</title>
		<link>http://www.muhuk.com/2011/09/sign-of-a-stupid-programmer/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=sign-of-a-stupid-programmer</link>
		<comments>http://www.muhuk.com/2011/09/sign-of-a-stupid-programmer/#comments</comments>
		<pubDate>Thu, 29 Sep 2011 14:32:26 +0000</pubDate>
		<dc:creator>Atamert Ölçgen</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[code quality]]></category>
		<category><![CDATA[competence]]></category>
		<category><![CDATA[stupidity]]></category>

		<guid isPermaLink="false">http://www.muhuk.com/?p=430</guid>
		<description><![CDATA[if some_boolean_expression: return True else: return False Unlike programmers who can&#8217;t program, stupid programmers can and do program. That is the problem. joined = '%s%s%s%s%s%s' % ( some_list[0], some_list[1], some_list[2], some_list[3], some_list[4], some_list[5], some_list[6]) You just wish they were unable to program. Every single time you encounter their code you question yourself. You ask if [...]<div><a class="addthis_button" href="//addthis.com/bookmark.php?v=250" addthis:url='http://www.muhuk.com/2011/09/sign-of-a-stupid-programmer/' addthis:title='Sign of a Stupid Programmer '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div>]]></description>
			<content:encoded><![CDATA[<pre><code>if some_boolean_expression:
    return True
else:
    return False
</code></pre>

<p>Unlike <a href="http://www.codinghorror.com/blog/2007/02/why-cant-programmers-program.html">programmers who can&#8217;t program</a>, stupid programmers can and do program. That is the problem.</p>

<pre><code>joined = '%s%s%s%s%s%s' % (
    some_list[0],
    some_list[1],
    some_list[2],
    some_list[3],
    some_list[4],
    some_list[5],
    some_list[6])
</code></pre>

<p>You just wish they were unable to program. Every single time you encounter their code you question yourself. You ask <code>if this is programming, what the f#ck is it I have been doing all this time?</code></p>

<pre><code>def __unicode__(self):
    return '%s' % self.some_unicode_attribute
</code></pre>

<p>I have been reading on stupidity lately. It all started with <a href="http://twitter.com/onurozer">Onur</a> tweeting <a href="http://www.science20.com/hammock_physicist/survival_stupidest-77846">this article</a>. Then I have found the following definition of <a href="http://wwwcsif.cs.ucdavis.edu/~leeey/stupidity/basic.htm">stupidity</a>:</p>

<blockquote>
  <p>A stupid person is a person who causes losses to another person or to a group of persons while himself deriving no gain and even possibly incurring losses.</p>
</blockquote>

<p>They&#8217;re both good reads. I just wish I was introduced to these concepts earlier. I felt stupid for my ignorance on stupidity.</p>

<pre><code>def some_func(**kwargs):
    param1 = kwargs.get('param1', 'param1_default')
    param2 = kwargs.get('param2', 'param2_default')
    param3 = kwargs.get('param3', 'param3_default')
    param4 = kwargs.get('param4', 'param4_default')
    param5 = kwargs.get('param5', 'param5_default')
    param6 = kwargs.get('param6', 'param6_default')
</code></pre>

<p>Watch out for the stupid programmer. He is destructive.</p>
<div><a class="addthis_button" href="http://www.muhuk.com//addthis.com/bookmark.php?v=250" addthis:url='http://www.muhuk.com/2011/09/sign-of-a-stupid-programmer/' addthis:title='Sign of a Stupid Programmer '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div><p>Related posts:<ol>
<li><a href='http://www.muhuk.com/2011/11/was-it-the-imperialism-that-made-the-west-rich/' rel='bookmark' title='Was it the imperialism that made the west rich?'>Was it the imperialism that made the west rich?</a></li>
</ol></p> <p><a href="http://www.muhuk.com/?flattrss_redirect&amp;id=430&amp;md5=fd0f58163a141bc5228b69dcc0acdcdb" title="Flattr" target="_blank"><img src="http://www.muhuk.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.muhuk.com/2011/09/sign-of-a-stupid-programmer/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<atom:link rel="payment" href="http://www.muhuk.com/?flattrss_redirect&amp;id=430&amp;md5=fd0f58163a141bc5228b69dcc0acdcdb" type="text/html" />
	</item>
		<item>
		<title>F Commits: Poor Man&#8217;s Sub-commits</title>
		<link>http://www.muhuk.com/2011/07/f-commits/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=f-commits</link>
		<comments>http://www.muhuk.com/2011/07/f-commits/#comments</comments>
		<pubDate>Sun, 24 Jul 2011 13:23:49 +0000</pubDate>
		<dc:creator>Atamert Ölçgen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[vcs]]></category>
		<category><![CDATA[version control]]></category>

		<guid isPermaLink="false">http://www.muhuk.com/?p=427</guid>
		<description><![CDATA[Lately I find myself typing the following command almost a hundred times in a day: git commit -a -m"f" Instead of forming a whole changeset carefully, I just go with it and do many small f commits. If it gets hairy I can revert back to a previous step or remove one or more of [...]<div><a class="addthis_button" href="//addthis.com/bookmark.php?v=250" addthis:url='http://www.muhuk.com/2011/07/f-commits/' addthis:title='F Commits: Poor Man&#8217;s Sub-commits '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div>]]></description>
			<content:encoded><![CDATA[<p>Lately I find myself typing the following command almost a hundred times in a day:</p>

<pre><code>git commit -a -m"f"
</code></pre>

<p>Instead of forming a whole changeset carefully, I just go with it and do many small <em>f commit</em>s. If it gets hairy I can revert back to a previous step or remove one or more of them. When I am happy with the result, I rebase and mark all the <em>f commit</em>s after the initial commit as <a href="http://kernel.org/pub/software/scm/git/docs/git-rebase.html"><code>fixup</code></a>. Initial commit usually has the commit message this changeset will finally have but if I want to change it I just mark is as <code>reword</code>.</p>

<p>Note that, what I call an <em>f commit</em> is not an atomic set of modifications, they&#8217;re usually undoing or overriding the previous changes. Another way to put it; they are silly commits that I wouldn&#8217;t want anyone else to see. They are a better undo mechanism than whatever editor you are using offers, and they allow you to synchronize multiple files.</p>

<p>I am not saying this is revolutionary or anything. But this is one example of how git changed my workflow and my way of thinking, definitely in a positive way. If you are not familiar with <a href="http://book.git-scm.com/4_interactive_rebasing.html">interactive rebasing</a> please take the time to learn how it works. It is going to pay really well, trust me.</p>
<div><a class="addthis_button" href="http://www.muhuk.com//addthis.com/bookmark.php?v=250" addthis:url='http://www.muhuk.com/2011/07/f-commits/' addthis:title='F Commits: Poor Man&#8217;s Sub-commits '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div><p>No related posts.</p> <p><a href="http://www.muhuk.com/?flattrss_redirect&amp;id=427&amp;md5=4252bc4976795b0cb32e179f369b524f" title="Flattr" target="_blank"><img src="http://www.muhuk.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.muhuk.com/2011/07/f-commits/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<atom:link rel="payment" href="http://www.muhuk.com/?flattrss_redirect&amp;id=427&amp;md5=4252bc4976795b0cb32e179f369b524f" type="text/html" />
	</item>
		<item>
		<title>Programming is Debating</title>
		<link>http://www.muhuk.com/2011/07/programming-is-debating/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=programming-is-debating</link>
		<comments>http://www.muhuk.com/2011/07/programming-is-debating/#comments</comments>
		<pubDate>Thu, 14 Jul 2011 16:33:30 +0000</pubDate>
		<dc:creator>Atamert Ölçgen</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[agile development]]></category>
		<category><![CDATA[iterations]]></category>
		<category><![CDATA[software development]]></category>

		<guid isPermaLink="false">http://www.muhuk.com/?p=419</guid>
		<description><![CDATA[How difficult is it to start programming? By starting I mean producing real code, be it a personal project or something you will get paid for. But it is not written for the purpose of learning. Most of the readers of this blog are professional programmers. I am sure for many of you starting was [...]<div><a class="addthis_button" href="//addthis.com/bookmark.php?v=250" addthis:url='http://www.muhuk.com/2011/07/programming-is-debating/' addthis:title='Programming is Debating '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div>]]></description>
			<content:encoded><![CDATA[<p><div id="attachment_423" class="wp-caption alignleft" style="width: 260px"><a href="http://www.muhuk.com/wp-content/uploads/2011/07/city_centre.jpeg"><img src="http://www.muhuk.com/wp-content/uploads/2011/07/city_centre.jpeg" alt="" title="City Center, Singapore" width="250" height="750" class="size-full wp-image-423" /></a><p class="wp-caption-text">Programming is human activity, but this image still has nothing to do with it.</p></div> How difficult is it to start programming? By starting I mean producing real code, be it a personal project or something you will get paid for. But it is not written for the purpose of learning.</p>

<p>Most of the readers of this blog are professional programmers. I am sure for many of you starting was quite easy and natural. But for a lot of people it is an extremely difficult obstacle. I know people, more than 50 people, who studied CS or CE in university but has never written any real code. They get anxious when the possibility presents itself.</p>

<p>The problem with the start is usually the false expectations about programming. There are certain myths about heroic programmers writing incredible programs in impossible conditions with little or no effort. This is of course bullshit. But I have witnessed again and again people setting their expectations about the experience of writing code by these absurd standards. The actual experience inevitably fails to deliver these expectations and the person gives up. This doesn&#8217;t have be so. Programming is supposed to be fun.</p>

<p>When we open a book and start reading, the words we see are unlikely the author&#8217;s original words. The original, raw content get <a href="http://en.wikipedia.org/wiki/Copy_editing">edited</a> before printing. It is an iterative process. I don&#8217;t want to get into the details about publishing<sup>1</sup> but beginners should study this process carefully. Because the process of programming is same, sans <a href="http://groups.csail.mit.edu/mac/classes/6.001/abelson-sussman-lectures/">the magic</a>.</p>

<p>So the act of programming is also an act of debating. You debate with your tests using your code. When all tests pass, the debate is over. When you are making design decisions, no matter how small they are, there is a debate going on between the requirements, the resources and your professional judgement. Therefore it would be unreasonable to expect programming to be a smooth, frictionless process. If you want to start you should be prepared for it.</p>

<p>I would like to share a few pointers that I hope will make the start more predictable if not easier:</p>

<ol>
<li>Try to find a real problem to work on. Forget about educational/theoretical problems. Solve a real, practical problem. There is one extremely important thing to remember here; the scope of the project must be as small as possible. A series of 2-day projects are much better than a 2 week project.</li>
<li>Start by documenting the usage of the code. Write an example script that imports your hypotetical code and uses its functionality. In other words; <a href="http://www.paulgraham.com/progbot.html">design top-down, program bottom-up.</a></li>
<li>Then flesh out the structure. Create files, classes, functions, comments. Writing code is good for warming-up to write some code.</li>
<li>Divide and conquer. Implement incrementally, accomplish one thing at a time. If a functionality is giving you hard time, try to write something that produces some results but not exactly what you expect. Then continue iterating until you get it right. Don&#8217;t wait for the programming muse to come and light the way. Sometimes you need to invent all the wrong implementations before figuring out the correct one.</li>
<li>Never hesitate to ask for help. Programming is debating, why not introduce your peers and mentors into the process. If you are asking for help make sure you have a concrete question. Input, expected output and your current code is usually enough. Even when you don&#8217;t have a problem or question, share your work with others and try to get as much feedback as possible.</li>
<li>Do your research. There is no getting around the reading. I would be lying to you if I said otherwise. If you want to win the debate you need to be well prepared. It may be a little overwhelming in the beginning. But as you build up your knowledge (and experience) you will enjoy reading more.</li>
</ol>

<p>I hope these pointers are helpful. But I think the most important thing to remember is programming is not a mechanical process but it is very human, I call it a debate, some call it <a href="http://books.google.com/books/about/The_art_of_computer_programming.html?id=5oJQAAAAMAAJ">art</a>.</p>

<p><strong>1</strong>: Nor am I an expert on the subject.</p>
<div><a class="addthis_button" href="http://www.muhuk.com//addthis.com/bookmark.php?v=250" addthis:url='http://www.muhuk.com/2011/07/programming-is-debating/' addthis:title='Programming is Debating '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div><p>No related posts.</p> <p><a href="http://www.muhuk.com/?flattrss_redirect&amp;id=419&amp;md5=defd54b73fe4477e61bea1727e2a595f" title="Flattr" target="_blank"><img src="http://www.muhuk.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.muhuk.com/2011/07/programming-is-debating/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<atom:link rel="payment" href="http://www.muhuk.com/?flattrss_redirect&amp;id=419&amp;md5=defd54b73fe4477e61bea1727e2a595f" type="text/html" />
	</item>
		<item>
		<title>My PyCon APAC 2011 Presentation: Optimizing Media Performance with django_compressor</title>
		<link>http://www.muhuk.com/2011/06/pycon-apac-optimizing-media-performance-with-django_compressor/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=pycon-apac-optimizing-media-performance-with-django_compressor</link>
		<comments>http://www.muhuk.com/2011/06/pycon-apac-optimizing-media-performance-with-django_compressor/#comments</comments>
		<pubDate>Tue, 28 Jun 2011 09:41:45 +0000</pubDate>
		<dc:creator>Atamert Ölçgen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[media]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.muhuk.com/?p=416</guid>
		<description><![CDATA[I have given a presentation about django_compressor at PyCon APAC 2011. Slides are below for everyone to see: Optimizing Media Performance with django_compressor View more presentations from muhuk Related posts: Working with files in Django &#8211; Part 1 Working with files in Django &#8211; Part 2 Working with files in Django &#8211; Part 3<div><a class="addthis_button" href="//addthis.com/bookmark.php?v=250" addthis:url='http://www.muhuk.com/2011/06/pycon-apac-optimizing-media-performance-with-django_compressor/' addthis:title='My PyCon APAC 2011 Presentation: Optimizing Media Performance with django_compressor '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div>]]></description>
			<content:encoded><![CDATA[<p>I have given a presentation about <a href="http://django_compressor.readthedocs.org/">django_compressor</a> at <a href="http://apac.pycon.org/">PyCon APAC 2011</a>. Slides are below for everyone to see:</p>

<div style="width:425px" id="__ss_8387857"> <strong style="display:block;margin:12px 0 4px"><a href="http://www.slideshare.net/muhuk/optimizing-media-performance-with-djangocompressor" title="Optimizing Media Performance with django_compressor">Optimizing Media Performance with django_compressor</a></strong> <iframe src="http://www.slideshare.net/slideshow/embed_code/8387857" width="425" height="355" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe> <div style="padding:5px 0 12px"> View more <a href="http://www.slideshare.net/">presentations</a> from <a href="http://www.slideshare.net/muhuk">muhuk</a> </div> </div>
<div><a class="addthis_button" href="http://www.muhuk.com//addthis.com/bookmark.php?v=250" addthis:url='http://www.muhuk.com/2011/06/pycon-apac-optimizing-media-performance-with-django_compressor/' addthis:title='My PyCon APAC 2011 Presentation: Optimizing Media Performance with django_compressor '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div><p>Related posts:<ol>
<li><a href='http://www.muhuk.com/2011/11/working-with-files-in-django/' rel='bookmark' title='Working with files in Django &#8211; Part 1'>Working with files in Django &#8211; Part 1</a></li>
<li><a href='http://www.muhuk.com/2011/11/working-with-files-in-django-part-2/' rel='bookmark' title='Working with files in Django &#8211; Part 2'>Working with files in Django &#8211; Part 2</a></li>
<li><a href='http://www.muhuk.com/2011/11/working-with-files-in-django-part-3/' rel='bookmark' title='Working with files in Django &#8211; Part 3'>Working with files in Django &#8211; Part 3</a></li>
</ol></p> <p><a href="http://www.muhuk.com/?flattrss_redirect&amp;id=416&amp;md5=27d75947771a44d9ca505fe4b3865437" title="Flattr" target="_blank"><img src="http://www.muhuk.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.muhuk.com/2011/06/pycon-apac-optimizing-media-performance-with-django_compressor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="http://www.muhuk.com/?flattrss_redirect&amp;id=416&amp;md5=27d75947771a44d9ca505fe4b3865437" type="text/html" />
	</item>
		<item>
		<title>Drawing Gradients with PyGame</title>
		<link>http://www.muhuk.com/2010/11/drawing-gradients-with-pygame/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=drawing-gradients-with-pygame</link>
		<comments>http://www.muhuk.com/2010/11/drawing-gradients-with-pygame/#comments</comments>
		<pubDate>Sat, 20 Nov 2010 06:20:11 +0000</pubDate>
		<dc:creator>Atamert Ölçgen</dc:creator>
				<category><![CDATA[Games]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[game development]]></category>
		<category><![CDATA[gradient]]></category>
		<category><![CDATA[pygame]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.muhuk.com/?p=394</guid>
		<description><![CDATA[I have been learning myself some PyGame on my free time. Best way to learn new technologies, I believe, is to develop small project and doing a lot of reading. Everybody seems to agree on the former but most fail to put effort doing the latter. I needed to draw gradients for the background of [...]<div><a class="addthis_button" href="//addthis.com/bookmark.php?v=250" addthis:url='http://www.muhuk.com/2010/11/drawing-gradients-with-pygame/' addthis:title='Drawing Gradients with PyGame '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div>]]></description>
			<content:encoded><![CDATA[<p>I have been learning myself some <a href="http://www.pygame.org/">PyGame</a> on my free time. Best way to learn new technologies, I believe, is to develop small project <strong>and</strong> doing a lot of reading. Everybody seems to agree on the former but most fail to put effort doing the latter.</p>

<p>I needed to draw gradients for the background of my little learning project. First I tried the naive approach: iterating over each pixel and setting the correct value. This takes forever as you could have guessed. I continued my research to find out the close connection between PyGame and <a href="http://numpy.scipy.org/">NumPy</a>. Yes, fast array operations. My gradient generating code using <code>linspace</code> and <code>tile</code> is below:</p>

<p><code><pre style="color:#000000; background-color:#ffffff; font-size:10pt; font-family:'Courier New';"><span style="color:#000000; font-weight:bold">def</span> <span style="color:#010181">generate&#95;gradient</span><span style="color:#000000">(</span>from<em>color<span style="color:#000000">,</span> to</em>color<span style="color:#000000">,</span> height<span style="color:#000000">,</span> width<span style="color:#000000">):</span>
    channels <span style="color:#000000">= []</span>
    <span style="color:#000000; font-weight:bold">for</span> channel <span style="color:#000000; font-weight:bold">in</span> <span style="color:#830000">range</span><span style="color:#000000">(</span><span style="color:#2928ff">3</span><span style="color:#000000">):</span>
        from<em>value<span style="color:#000000">,</span> to</em>value <span style="color:#000000">=</span> from<em>color<span style="color:#000000">[</span>channel<span style="color:#000000">],</span> to</em>color<span style="color:#000000">[</span>channel<span style="color:#000000">]</span>
        channels<span style="color:#000000">.</span><span style="color:#010181">append</span><span style="color:#000000">(</span>numpy<span style="color:#000000">.</span><span style="color:#010181">tile</span><span style="color:#000000">(</span>numpy<span style="color:#000000">.</span><span style="color:#010181">linspace</span><span style="color:#000000">(</span>from<em>value<span style="color:#000000">,</span> to</em>value<span style="color:#000000">,</span> width<span style="color:#000000">),</span>
                                                                  <span style="color:#000000">[</span>height<span style="color:#000000">,</span> <span style="color:#2928ff">1</span><span style="color:#000000">]))</span>
    <span style="color:#000000; font-weight:bold">return</span> numpy<span style="color:#000000">.</span><span style="color:#010181">dstack</span><span style="color:#000000">(</span>channels<span style="color:#000000">)</span>
</pre></code></p>

<p>I create three 1D arrays for each channel and then tile them to get a 2D array. Then I stack those 2D arrays and get combined <code>(r, g, b)</code> values. Each 1D array contain values linearly sampled between given maximum and minimum values by <code>linspace</code>. I can then blip this array on a surface like this:</p>

<p><code><pre style="color:#000000; background-color:#ffffff; font-size:10pt; font-family:'Courier New';">gradient <span style="color:#000000">=</span> <span style="color:#010181">generate&#95;gradient</span><span style="color:#000000">((</span><span style="color:#2928ff">63</span><span style="color:#000000">,</span> <span style="color:#2928ff">95</span><span style="color:#000000">,</span> <span style="color:#2928ff">127</span><span style="color:#000000">), (</span><span style="color:#2928ff">195</span><span style="color:#000000">,</span> <span style="color:#2928ff">195</span><span style="color:#000000">,</span> <span style="color:#2928ff">255</span><span style="color:#000000">),</span> 1024<span style="color:#000000">,</span> 600<span style="color:#000000">)</span>
pygame<span style="color:#000000">.</span>surfarray<span style="color:#000000">.</span><span style="color:#010181">blit&#95;array</span><span style="color:#000000">(</span>some&#95;surface<span style="color:#000000">,</span> pygame<span style="color:#000000">.</span>surfarray<span style="color:#000000">.</span><span style="color:#010181">map&#95;array</span><span style="color:#000000">(</span>some&#95;surface<span style="color:#000000">,</span> gradient<span style="color:#000000">))</span>
</pre></code></p>

<p>This works quite well. But I was curious whether there is a better method, so I did some googling. First I stumbled upon James Tauber&#8217;s <a href="http://jtauber.com/blog/2008/05/18/creating_gradients_programmatically_in_python/">gradient code</a>. Arrays! I was a bit ashamed not remembering standard library had <a href="http://docs.python.org/release/2.6.5/library/array.html">array</a> module. James Tauber&#8217;s code builds an array with the correct values and then writes the image as a PNG file. It also has the ability to generate multi-gradients.</p>

<p>Then I found <a href="http://www.pygame.org/project-gradients-307-1586.html">gradients</a> package for PyGame. This package does much more than linear gradients. It creates a PyGame surface of 1 pixel thickness, fills it with the gradient values and then resizes it.</p>

<p>I made a small test to see which method runs faster. I had to strip file and compression related code from James Tauber&#8217;s gradient module. I run a simple method tha just generates a gradient image/array in memory and returns it 10 time, below is the average times:</p>

<ul>
<li>320&#215;240:

<ul>
<li>numpy: 0.01469659805</li>
<li>array: 3.6310561180</li>
<li>pygame: 0.0069756984711</li>
</ul></li>
<li>800&#215;600:

<ul>
<li>numpy: 0.1323119163</li>
<li>array: 19.9719331265</li>
<li>pygame: 0.0192141056061</li>
</ul></li>
</ul>

<p>Here <code>numpy</code> is my method above, <code>array</code> is the stripped version of James Tauber&#8217;s code and <code>pygame</code> is the gradiends package. If my benchmarking method doesn&#8217;t have dramatic errors fastest way to generate linear gradients is to fill a strip with correct values and then to resize it.</p>

<p>Now I&#8217;ll go back to work on my learning project.</p>
<div><a class="addthis_button" href="http://www.muhuk.com//addthis.com/bookmark.php?v=250" addthis:url='http://www.muhuk.com/2010/11/drawing-gradients-with-pygame/' addthis:title='Drawing Gradients with PyGame '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div><p>Related posts:<ol>
<li><a href='http://www.muhuk.com/2011/06/pycon-apac-optimizing-media-performance-with-django_compressor/' rel='bookmark' title='My PyCon APAC 2011 Presentation: Optimizing Media Performance with django_compressor'>My PyCon APAC 2011 Presentation: Optimizing Media Performance with django_compressor</a></li>
<li><a href='http://www.muhuk.com/2011/11/working-with-files-in-django/' rel='bookmark' title='Working with files in Django &#8211; Part 1'>Working with files in Django &#8211; Part 1</a></li>
<li><a href='http://www.muhuk.com/2011/11/working-with-files-in-django-part-2/' rel='bookmark' title='Working with files in Django &#8211; Part 2'>Working with files in Django &#8211; Part 2</a></li>
</ol></p> <p><a href="http://www.muhuk.com/?flattrss_redirect&amp;id=394&amp;md5=3cb4c095b4c366584efb33b30c607bf5" title="Flattr" target="_blank"><img src="http://www.muhuk.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.muhuk.com/2010/11/drawing-gradients-with-pygame/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="http://www.muhuk.com/?flattrss_redirect&amp;id=394&amp;md5=3cb4c095b4c366584efb33b30c607bf5" type="text/html" />
	</item>
		<item>
		<title>I Am Discontinuing Telvee</title>
		<link>http://www.muhuk.com/2010/09/i-am-discontinuing-telvee/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=i-am-discontinuing-telvee</link>
		<comments>http://www.muhuk.com/2010/09/i-am-discontinuing-telvee/#comments</comments>
		<pubDate>Thu, 02 Sep 2010 07:13:59 +0000</pubDate>
		<dc:creator>Atamert Ölçgen</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Personal]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[django-inviting]]></category>
		<category><![CDATA[django-simple-friends]]></category>
		<category><![CDATA[telvee]]></category>

		<guid isPermaLink="false">http://www.muhuk.com/?p=380</guid>
		<description><![CDATA[Telvee was originally a Facebook app. It was Burak Büyükdemir&#8216;s idea to create a virtual coffee reading app. Rakı Sofrası was super popular then. We have quickly built and deployed and getting some good results. But the competition wasn&#8217;t fair. When I decided to give this software a fair chance to succeed on its very [...]<div><a class="addthis_button" href="//addthis.com/bookmark.php?v=250" addthis:url='http://www.muhuk.com/2010/09/i-am-discontinuing-telvee/' addthis:title='I Am Discontinuing Telvee '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div>]]></description>
			<content:encoded><![CDATA[<p>Telvee was originally a Facebook app. It was <a href="http://burakbuyukdemir.com/">Burak Büyükdemir</a>&#8216;s idea to create a virtual coffee reading app. <a href="http://apps.facebook.com/rakisofrasi/">Rakı Sofrası</a> was super popular then. We have quickly built and deployed and getting some good results. But the competition wasn&#8217;t fair.</p>

<p>When I decided to give this software a fair chance to succeed on its very own domain the only question in my head was; will it pass the test of users? It doesn&#8217;t really matter what you have intended the users do with your application. What matters, first, is what they think they&#8217;d like to do with it and then whether or not they actually use it.</p>

<p>So I tried and I failed. Two main reasons of this failure are; technical deficiencies and the special way of interaction coffee reading is. Technical deficiencies is the easy one. I couldn&#8217;t devote enough time for telvee, especially lately. As a result it doesn&#8217;t even have basic stuff like e-mail changing or account deletion. This is 100% my fault. The second reason however is more complicated and there was not much I could do about it. Except one thing I will tell you at the end of this post.</p>

<p>Telvee didn&#8217;t pass the user&#8217;s test mainly because coffee reading is somewhat private. It&#8217;s more of a 1-to-1 communication, while all social applications<sup>1</sup> are designed for 1-to-many communication. This was disastrous not only because of the lack of viral growth but also because of the reluctance of users to interact with other users.</p>

<div id="attachment_383" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.muhuk.com/wp-content/uploads/2010/08/muhuk-92.jpeg"><img src="http://www.muhuk.com/wp-content/uploads/2010/08/muhuk-92-300x69.jpg" alt="An example image of coffee remains telvee generates" title="An example image of coffee remains telvee generates" width="300" height="69" class="size-medium wp-image-383" /></a><p class="wp-caption-text">An example image of coffee remains telvee generates</p></div>

<p>I would like to thank everybody who participated and I hope you had some fun playing with it. Telvee domain will soon redirect to this post and I will probably not renew it next time.</p>

<p>I won&#8217;t be starting a new experiment soon. I will spend most of my time on my work. Hopefully I will be spending a little more time on free software projects. By the way I would like to note that Telvee has spawned a couple of Django apps: <a href="http://github.com/muhuk/django-inviting">django-inviting</a> &amp; <a href="http://github.com/muhuk/django-simple-friends">django-simple-friends</a>.</p>

<p>Oh, and the thing I could do better about user experience was to be more agile. I should have either fixed the problem quickly or failed fast. I have no regrets though. This was a unique experience and I have learned a lot.</p>

<hr />

<p><strong>1</strong>: Yes, even the e-mail system and dating sites are designed for 1-to-many communication primarily in mind.</p>
<div><a class="addthis_button" href="http://www.muhuk.com//addthis.com/bookmark.php?v=250" addthis:url='http://www.muhuk.com/2010/09/i-am-discontinuing-telvee/' addthis:title='I Am Discontinuing Telvee '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div><p>Related posts:<ol>
<li><a href='http://www.muhuk.com/2011/06/pycon-apac-optimizing-media-performance-with-django_compressor/' rel='bookmark' title='My PyCon APAC 2011 Presentation: Optimizing Media Performance with django_compressor'>My PyCon APAC 2011 Presentation: Optimizing Media Performance with django_compressor</a></li>
<li><a href='http://www.muhuk.com/2011/11/working-with-files-in-django/' rel='bookmark' title='Working with files in Django &#8211; Part 1'>Working with files in Django &#8211; Part 1</a></li>
<li><a href='http://www.muhuk.com/2011/11/working-with-files-in-django-part-2/' rel='bookmark' title='Working with files in Django &#8211; Part 2'>Working with files in Django &#8211; Part 2</a></li>
</ol></p> <p><a href="http://www.muhuk.com/?flattrss_redirect&amp;id=380&amp;md5=9abc6157ccc398505c44a139757b9dae" title="Flattr" target="_blank"><img src="http://www.muhuk.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.muhuk.com/2010/09/i-am-discontinuing-telvee/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="http://www.muhuk.com/?flattrss_redirect&amp;id=380&amp;md5=9abc6157ccc398505c44a139757b9dae" type="text/html" />
	</item>
		<item>
		<title>How To Create A Debian VM With Qemu</title>
		<link>http://www.muhuk.com/2010/07/how-to-create-a-debian-vm-with-qemu/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-create-a-debian-vm-with-qemu</link>
		<comments>http://www.muhuk.com/2010/07/how-to-create-a-debian-vm-with-qemu/#comments</comments>
		<pubDate>Wed, 07 Jul 2010 10:26:39 +0000</pubDate>
		<dc:creator>Atamert Ölçgen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[qemu]]></category>
		<category><![CDATA[share]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[vm]]></category>

		<guid isPermaLink="false">http://www.muhuk.com/?p=375</guid>
		<description><![CDATA[I would like to post my notes as a little tutorial here. I am usually using these virtual machines as cheap staging servers. The first part of this tutorial, you hopefully need to do only once: creating a fresh Debian system. In the second part we will build on this image to create many different [...]<div><a class="addthis_button" href="//addthis.com/bookmark.php?v=250" addthis:url='http://www.muhuk.com/2010/07/how-to-create-a-debian-vm-with-qemu/' addthis:title='How To Create A Debian VM With Qemu '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div>]]></description>
			<content:encoded><![CDATA[<p>I would like to post my notes as a little tutorial here. I am usually using these virtual machines as cheap staging servers. The first part of this tutorial, you hopefully need to do only once: creating a fresh Debian system. In the second part we will build on this image to create many different servers.</p>

<h2>Creating A Base Debian System</h2>

<p>We will create a Qemu machine and install Debian Lenny on it first:</p>

<pre><code># Download Debian image
wget http://debian.osuosl.org/debian-cdimage/current/i386/iso-cd/debian-504-i386-businesscard.iso

# Create base VM image
qemu-img create -f qcow2 debian.qcow2 2G
</code></pre>

<p>Our disk image will have a 2 Gigabyte size limit. You can pick a different size if you need.</p>

<p>Now we need to power on our VM and install Debian:</p>

<pre><code># Install Debian
qemu -enable-kvm -k tr -cdrom debian-504-i386-businesscard.iso -hda debian.qcow2 -boot d
</code></pre>

<p>You don&#8217;t need to allocate a large swap disk, 128MB should do just fine for a file/web server. Also I wouldn&#8217;t bother creating a seperate partition for <code>/home/</code>.</p>

<p>Next let&#8217;s log in as the user (<code>www</code> here) we have created to make final changes:</p>

<pre><code># logged in as user
dpkg-reconfigure console-data
aptitude install ssh sudo
echo "www ALL=(ALL) ALL" &gt;&gt; /etc/sudoers
</code></pre>

<p>At this point you might want to take a backup of <code>debian.qcow2</code>. (Even though we will open it only read-only from now on)</p>

<h2>Creating The Actual VM</h2>

<p>To save time and space we will use copy-on-write disks and re-use <code>debian.qcow2</code>.</p>

<pre><code># Create the actual VM's disk
qemu-img create -f qcow2 -o backing_file=debian.qcow2 actual.qcow2
</code></pre>

<p>Actually we are done. You can log in to your VM using the following command and start installing/configuring/running:</p>

<pre><code>qemu -enable-kvm -k tr -hda actual.qcow2 -net user -net nic \
                                         -redir tcp:5022::22 \
                                         -redir tcp:9080::80
</code></pre>

<p>A few things to note about the command above:</p>

<ul>
<li><code>-enable-kvm</code> is meaningful only if you have <code>kvm</code> kernel module installed. It improves performance a great deal, so it&#8217;s highly recommended.</li>
<li>You probably need to change <code>-k tr</code> according to your keyboard&#8217;s layout.</li>
<li>We are setting up two TCP redirections. 22 is for SSH and 80 is for HTTP. You can add more ports if you need.</li>
</ul>

<p>Finally, I suggest you to prefer SSHing your VM instead of logging in directly:</p>

<pre><code># SSH into the VM
ssh -p 5022 www@localhost
</code></pre>

<p>I hope some of you find this useful.</p>
<div><a class="addthis_button" href="http://www.muhuk.com//addthis.com/bookmark.php?v=250" addthis:url='http://www.muhuk.com/2010/07/how-to-create-a-debian-vm-with-qemu/' addthis:title='How To Create A Debian VM With Qemu '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div><p>No related posts.</p> <p><a href="http://www.muhuk.com/?flattrss_redirect&amp;id=375&amp;md5=d713dc941f47b9510d1c7d27eb397b5c" title="Flattr" target="_blank"><img src="http://www.muhuk.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.muhuk.com/2010/07/how-to-create-a-debian-vm-with-qemu/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<atom:link rel="payment" href="http://www.muhuk.com/?flattrss_redirect&amp;id=375&amp;md5=d713dc941f47b9510d1c7d27eb397b5c" type="text/html" />
	</item>
	</channel>
</rss>

