Programming Blog

Programming related articles.

Advanced json manipulation with python

Python provides really simple api for json manipulation. Here is some code that does basic json to python conversation...

Using multiple settings file for a django project

When I use django for development, I usually need multiple versions of file for my project.One for development and one for production. My current approach to solve multiple settings file problem is using tree files. In my project directory I have following

Convert python dict to xml

Among all those terrible technologies, I hate the DOM API most. It accomplishes simple tasks with most complicated way possible. So Instead of manipulating XML with DOM API I wrote a simple python dict to XML converter which converts dictionary structures to python minidom object or xml string.

Add pep8 style check to emacs

If you need to check if your code is compatible with pep8 (Style Guide for Python Code). You can add pep8 style check to emacs...

Create thumbnails for an ImageField in django

Django does not provide any standard way of organizing thumbnails. Even though community has some applications to work with thumbnails, they are usually over kill if You only want to create a thumbnail for an ImageField. So here is my solution to handle thumbnails...

Use python as a Simple HTTP Server

The other day, I needed to share files with a Windows based computer. I did not have any ftp nor samba server installed on my machine. For some reason ssh did not work either. As a quick solution, I decided to use a trick I saw some time ago. I started a python process which works as a simple HTTP server. Next, I opened a browser on remote machine and connected to my HTTP server and downloaded the files through HTTP.

Emacs setup for python development

This is the follow up for basic emacs setup post. In this post I will explain how to update your emacs setup for python development. I will cover

  • pymacs (Python binding for emacs. This is a ropemacs dependency)
  • rope (Python refactoring library)
  • ropemacs (Rope bindings for emacs)
  • rope-mode (Minor mode for ropemacs)
  • pyflakes (passive checker of Python programs)
  • flymake (an on-the-fly syntax checker for GNU Emacs)
  • flymake-mode (Minor mode for flymake)
  • pyflakes error format script
  • autocomplete rope integration

How to convert python tuple to dict

Sometimes you might need to convert tuple (or list) to dict object to make it more readable. After all l['product_id'] is more readable than l[4]...

Django ORM performance tips - part 2

This is the second part of the two-part series. First part can be found here. Here are some more tips that every django developer should know in order to write faster apps....

Pretty printing JSON output in terminal

If you need to pretty print the json output of a terminal command (so you can inspect it more easily), you can use python's json module. I usually use it to pretty print the output of curl command. Here is an example

    curl | python -m json.tool

This utility can also be used to pretty print json files like following

    python -m json.tool minified.json > prettyprint.json

Django ORM performance tips - part 1

This blog post will be split into two part. After I finish part two, I will add a link at the bottom of this one. For both parts I will use a sample project with sqlite3 database. file for sample application is here...