Make sure you are closing the DB connections after accessing Django ORM in your threads

I was writing a service which import various feeds and then post to another RESTful API, simple enough as below:

Then the feed model:

Then run this feed in trivial code:

And you will quickly notice the threads complaining

What it’s happening is Django will create a new connection per thread… Read More »

EJB stateful vs stateless

I have been studying Java EE and I posted a question on Stackoverflow to verify my understanding of “SessionBean”, here is the summary: Stateless bean in client:

  Stateful bean in client:

  A stateless session bean, should not store a state in the bean instance, in order words, it’s class members should… Read More »

Your function parameters should be as simple as possible

Let’s say you have a function to process a GET parameter from a HTTP request, the bad example to do this is:

The above example has 2 problems: 1. This will become a nightmare to write unit tests on this function, now you need to mock the request object to contain the attribute GET… Read More »

Writing static typed style code in dynamic type language

I am not sure who else is doing this but I have a static typed language background and I tend to write code in static type style. Don’t assign different value types to the same variable Let’s see what dynamic type in the simplest form in Python:

While this is perfectly legitimate, but it’s… Read More »

PHP developers should try Python.

PHP and Python both are dynamic typed language, so there is no point the discuss anything related in this aspect. Exception is first class citizen

Prints ‘Caught’ Let’s look at PHP:

Better functions Imagine you can write functions like this

Short-lived vs Long-lived Almost all PHP scripts are short-lived, including most frameworks, which… Read More »

Recommended fuel for Alphard 2004

My friend google doesn’t know what type of fuel is recommended for my recently bought Alphard 2004, so I asked Toyota NZ directly and they said is the recommended fuel is Octane 95, whilst using 91 it doesn’t hurt but it will not be as fuel efficient as using 95. BTW, I had always pondered… Read More »

Revisiting Home NAS

A while ago I blogged about turning an old PC into a NAS server, while it was fine and dandy it worked pretty well, until it refused to boot up again. So being data safety paranoid person, I went to purchase a NAS off the shelve, lucky PBTech had an incorrect price labelled, and I was able… Read More »

Laravel for Django developers, part 2

Global functions I am seeing a lot of framework specific global functions but don’t know where they come from, such as “view()”, “redirect()” etc etc. ORM Again, as mentioned in part 1, since we are creating migration files first, then we won’t be able to define FK relationships directly point to another model. According to… Read More »