Vim user? You’ll love NetBeans

Tags:

Here’s another reason to like NetBeans: the jVi plugin.

It changes the NetBeans code editor to Vim, which is in my opinion much more powerful text editor than the standard one in NB. What makes jVi even better is that you actually get all the code-assist and other features present in NetBeans’ normal editor!

I’ve used some Vim plugin for Eclipse, and another for Visual Studio, and neither of them got it right. jVi is definitely the best Vim-IDE integration I’ve seen so far.

Thanks to Adam Jorgensen for pointing it out!

Another idea for using models with forms

Tags:

Matthew Weier O’Phinney wrote about using Zend_Form with models. His approach puts a form inside a model, which then uses the form to validate itself.

While this idea is not bad, I find it being upside down – I think the form should use the model to validate itself, not the other way around.

But how would you utilize a model class to validate a form? I think there are two feasible ways to do so: A global model for a form, and a model-based validator class…

Read More

Decoupling models from the database: Data Access Object pattern in PHP

Tags:

Nowadays it’s a quite common approach to have models that essentially just represent database tables, and may support saving the model instance right to the database. While the ActiveRecord pattern and things like Doctrine are useful, you may sometimes want to decouple the actual storage mechanism from the rest of the code.

This is where the Data Access Object pattern comes in. It’s a pattern which abstracts the details of the storage mechanism – be it a relational database, OO database, an XML file or whatever. The advantage of this is that you can easily implement different methods to persist objects without having to rewrite parts of your code.

I’m again going to use the programming language quiz game I wrote as an example. Since I initially wrote it to use Doctrine ORM directly, and both the old and new code are available, you can easily see how the code was improved.

Read More

Sandboxing Rhino in Java

Tags:

I’ve been working on a Java app which needed Rhino for scripting. The app would need to run untrusted JavaScript code from 3rd parties, so I had to find a way to block access to all Java methods, except the ones I wanted. This would not be a problem if there was an easy way to disable LiveConnect – the feature of Rhino which provides java access to scripts – but there is no such thing.

However, after a lot of digging around, I finally found a way to do this without too much hacking. In fact, it can be done by just extending a few of the Rhino classes, and using the setters provided to override some of the default ones.

Read More

Best of 2008

Tags:

Since the year is about to end, I think now is a good time to highlight some best things of 2008

Read More

Reusable “generic” actions in Zend Framework

Tags:

Sometimes you will need nearly the same functionality in many actions. This can lead to unnecessary code duplication if you aren’t careful, and there’s been a couple of occasions on #zftalk, where people have been asking for a good practice to avoid this.

There are several ways to deal with this, such as moving the code into a separate function, or an action helper. But in this post, I’m going to introduce so called “generic actions” – parametrized, easy to reuse actions – which is an idea similar to django generic views

Read More

Happy holidays

Tags:

Merry christmas to everyone, or if you don’t do xmas, happy <insert your holiday’s name here>!

Also, here’s a small challenge for you: draw santa in mspaint (or something else) – but do it with your eyes closed!
Read More

What will you do during the holidays?

Tags:

I’ve been asked this a couple of times.. What will I be doing during xmas?

Since the people asking that aren’t exactly computer people, the usual non-nerdy answer I give out is that I’ll probably take it easy and relax – you know, the usual stuff.

But since this is the internet, and this is a programming blog…

  • I’ll be learning some Java
  • I’ll be writing something hopefully awesome in Java
  • I’ll be coding a website with Python and Django
  • I’ll also hopefully be writing some interesting blogposts
  • And maybe I’ll even do something unrelated to computers!

What are your plans?

JavaScript margin/block commenting system

Tags:

On Djangobook, they used to have this interesting commenting mechanism on their book’s pages:

Each paragraph in the book could have comments, by use of a JavaScript commenting system which would display the amount of comments on each paragraph when you hovered over them with the mouse. You could also click on the little bubble which displayed the count, and leave a comment of your own.

A while ago, Pádraic Brady was looking for a similar system. This got me thinking about it again… and of course I had to try implementing it myself!

Read More