Prevent page from scrolling to top after link click

Imagine you have a bunch of links, maybe images, or anything else, that dont actually have a url to jump to but instead trigger some awesome javascript that do amazing things somewhere else, or just highlight the icons/images as selector of whatever. If you use links like

<a href="#" onclick="doStuff(1)">link1</a>
<a href="#" onclick="doStuff(2)">link2</a>
<a href="#" onclick="doStuff(3)">link3</a>

When you click on these links, they do trigger all your amazing stuff, but they also make your page scroll to the top if they are below the height of your browser window.

On for the code and simple solution, well, two of them, after the jump:

|Read the Rest of the Entry…

Remove item from array in jQuery/javascript

Extremely simple problem with a million solutions. These are just a couple of ways to do it. Go learn after the jump.

|Read the Rest of the Entry…

Shortcut to create getter/setters in NetBeans

So, if you are in a hurry to create a super ninja class and dont have time to waste on stupid type-all-the-characters actions to create basic getter/setters, in NetBeans you can do this:

After defining your attributes, for example:

private String name;
private int age;

You can go to the menu “Refactor” (top menu) and choose “Encapsulate Fields…”, or the context menu (right mouse button) and chose the same (Refactor->Encapsulate Fields…”.

Choose the attributes for which you want to create getter/setters, chose your options (self explanatory) and click “Refactor”. Presto. Simple basic fast getter/setters. Go thank me.

UPDATE: Another way of achieving this (and other auto code inserting) is by clicking your right mouse button, select “Insert Code..” and go crazy with what’s in there.

How to create an auto increment primary key field in PostgreSQL

So, you want to create a fancy cool table in PostgreSQL, filled with great fields of incomparable values, along with a nice auto increment primary key.

You do something like this at table creation time:

|Read the Rest of the Entry…

PHP validate email addresses

To rapidly, and decently, validate email addresses, we can use something like this:

$email = "";

if (filter_var($email, FILTER_VALIDATE_EMAIL)) { 
    echo "This email is valid"; 

The filter_var() returns the filtered data or FALSE if it fails

Read about it, and more filters, here:

- function filter_var()

How to check Django version

Since we are in the version theme, here’s how to check what version of django is installed in your python:

From your python prompt:

>>> import django
>>> django.VERSION

you will get something like this:

$ (1,2,7, 'final', 0)

Versions depending on your installation.

Or you can type this on your command prompt (windows):

c:\whatever> python -c "import django; print(django.get_version())"

And you will get:

$ 1.2.7

How to find out what version of PostGIS is installed

If you want to find out the version of your installed PostGis, you do this:

SELECT PostGIS_full_version();

You get a row like this:

POSTGIS=”1.5.5″ GEOS=”3.3.5-CAPI-1.7.5″ PROJ=”Rel. 4.6.1, 21 August 2008″ LIBXML=”2.7.8″ USE_STATS

Versions displayed will depend on your instalation, of course.

External links:

- PostGIS website

PHP error reporting – turning on or off

So you wrote this awesome php script, that does extreme stuff, but when you run it…it shows nothing. Empty browser. So whats going on?

Well, for one, your php error reporting might be turned off by default. So how to turn it on?

Read and learn. And forget tomorrow, like me.

|Read the Rest of the Entry…

Where is php.ini

If you are configuring some remote strange not safe for work server and you have the urge to edit the php.ini – assuming you have permissions to do it – you can find out where the file is like this:

read on.

|Read the Rest of the Entry…

DELETE all duplicates from TABLE

If we have a long table with thousands of records with some duplicate contents and we want to trim it down to the bare essentials (no duplicates), here’s one (of several) way of doing it:

For this, assume we have:

- a table called “emails”, with fields: id_email, email
- the table has several records with duplicate emails in the “email” field

So we do it like this:

|Read the Rest of the Entry…

%d bloggers like this: