Archive for the ‘Programming’ Category

 

Fredrik Holmström on Sep 6th, 2008Outputting html from python programmatically

After being stuck with the drudgery of string interpolation when outputting HTML from python I figured there had to be some better way to do it, yes? The combination of a single decorator and a couple of functions proved to be the solution, here’s the code:
Wordpress decided to f*ck up my syntax highlighting in this […]

Fredrik Holmström on Sep 3rd, 2008How super() should be used when calling a parent’s method

Edit: You learn something new every day, it turns I was the disillusioned one, the correct way to call super is actually this:

class Demo(object):
def __init__(self):
print “From Demo”

class Test(Demo):
[…]

Fredrik Holmström on Sep 1st, 2008Managing asynchronous operations with python generators (part3)

Part 1: Introduction to generators in Python
Part 2: Indepth generator usage in Python (part2)
Part 3: Managing asynchronous operations with python generators (part3)

You can download all the code for this part here: http://totmacher.eu/upload/generators.tar.gz
I’m sorry, I lied to you guys - this part will not contain a real world example because I felt there were to many […]

Fredrik Holmström on Aug 30th, 2008Indepth generator usage in Python (part2)

Part 1: Introduction to generators in Python
Part 2: Indepth generator usage in Python (part2)
Part 3: Managing asynchronous operations with python generators (part3)

After my last post on generators in Python I realized I missed go through one thing that I wanted to mention in the first part, namely how the return keyword interfaces with yield and […]

Fredrik Holmström on Aug 29th, 2008Introduction to generators in Python

Part 1: Introduction to generators in Python
Part 2: Indepth generator usage in Python (part2)
Part 3: Managing asynchronous operations with python generators (part3)

First, some history…
Generators is a concept that was introduced in Python at version 2.2, back then they were unidirectional that only allowed information to be passed out of the generator and not back into […]

Fredrik Holmström on May 23rd, 2008New anti-spam commenting solution

From now on your comments should appear right away when you post them, but you will be required to have javascript enabled to post. If you can’t post a comment for some reason (other then not having javascript enabled), please email me.

Fredrik Holmström on May 23rd, 2008Exceptions, you’re doing it wrong

Edit: After a couple of comments and some personal pondering I decided to remove a small part of the article, if you read it before and think something is missing, then you know why.
Once again a post aimed at the PHP community, not so much of a rant but more of something I’ve seen done […]

Fredrik Holmström on May 20th, 2008PHP is the new VB6 in a C dress

I love programming, it’s that part of my life that let me express all these crazy ideas I get. Most of my work is done in PHP, and has been for a long time - there’s a simple explanation for that; Where I live (Sweden) PHP has had an incredible boost the last few years, […]

Fredrik Holmström on May 19th, 2008pySX: Simple XML processing in Python

pySX is my latest hobby project. It’s a very simple XML library that aims to simplify the process of handling XML as much as possible. The code can be found here: http://svn.loveandtheft.org/fredrik/pysx. Here are a couple of quick usage examples:
“Manual”
When accessing an element, two things can happen:

You get a list back, which means that there […]

Fredrik Holmström on May 17th, 2008Secure your mysql_* in two minutes

If you’re still using the mysql_* functions in php instead of PDO or some other more advanced db library (propel, doctrine) there’s one big favour you can do yourself, stop using mysql_query() and use this function instead:

<?php
function mysql_squery ($sql) {
$args = array_slice(func_get_args(), 1);
$args = array_map(’mysql_sescape’, $args);
return mysql_query(sprintf($sql, $args));
}

function mysql_sescape ($value) {
if (is_string($value)) {
$value = mysql_real_escape_string($value);
}
return […]