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 settings.py 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

My love themed js1k competition entry

For this year's love themed js1k competition I made a classic snake game. Here is the code and here is the demo.

How to export a git repository

When I need to export my code from a git repo, I used to copy my repository to another location and delete git specific stuff from it (.git directory and .gitignore file etc.) and zip the directory.This is a trick that I learned from one of my co-workers. Following command exports your project and creates a tar.gz file from it

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...

Truck game: A javascript game that uses svg animations for movement (firefox only)

The other day my wife and I were looking for an educational game to teach our son how to use a computer. Unfortunately most of the games on the internet were a little too competitive for our purposes. So I decided to roll my own.

It is a javascript game that uses svg animations for movement. Unfortunately game is using some of the firefox specific methods, so it is only working in firefox right now. But I will fix it as soon as I have some spare time.

Anyway here is the game. Source code can be found in github.

Create a default django development environment on python virtualenv

Recently, I decided to build my development environments on a python virtualenv, so project dependencies will not clobber global python path. Here is how I start a default django project from scratch...

Tetris in javascript

As an experiment, I wrote a tetris implementation in ecmascript 5. I used canvas to draw the images. My goal was to drop it under 1K and join the js1K. But I couldn't take it under 2K even I drop some features. Here is the page (Source can be found in github).http://thisguyhasmymacbook.tumblr.com/

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.

Disable flymake for specific file types

Flymake uses external applications to validate buffers. But sometimes, You don't have those external apps installed. For instance, HTML validation with flymake on Ubuntu is really problematic for this reason. Flymake uses xmlstarlet for HTML validation. It does it by calling xmlstarlet by command 'xml val file name.html'. But when xmlstarlet is installed in Ubuntu, it is installed by name 'xmlstarlet' instead of 'xml'. That name change causes emacs to raise exception every time an HTML file if opened. Since I don't really need XML/HTML validation in emacs, I thought I could just disable flymake for those types of files.

Emacs setup for web development

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

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

Basic emacs setup

Emacs is a great editor. But it is really hard to set it up. So I decided to write a document for my current emacs setup. In this post, I will explain how to install emacs with a basic setup.

I will cover how to:

  • Install emacs
  • Enable IDO mode
  • Add autocomplete mode
  • Add yasnippet mode
  • Set window title to full file name
  • Install color themes

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....

curl tutorial with examples of usage

Curl is a linux utility that is used to make HTTP requests to a given url. It outputs HTTP response to standard output and is actually very easy to use. Here are some examples to show its usage...

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

    :::bash
    curl http://somesite.com/my/json/ | python -m json.tool

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

    :::bash
    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. models.py file for sample application is here...