Quickly change a Django user password

So you have this nice django site, you try to access the admin to change some minor thing and you completely forgot (and didnt save somewhere) the password of the only user in the system – so many dont’s in that sentence, but anyway…

Since you are the developer, you can simply do this (assuming you at least know the user’s username):

python manage.py changepassword [username]

You will be prompted for a new password, and confirmation, and its done. Then you can go login to your nice admin and smile.

Read more about this and learn new things here:
Using the Django authentication system (opens in a new window)

PostgreSQL – PostGIS versions

Login to your postgresql on some database and go:

To get PostgreSQL version:

SELECT version();

To get versions for PostGIS, GEO, etc.:

SELECT PostGIS_full_version();

How to list and alter table sequences in PostgreSQL

So you screwed up with your ninja manual inserts on some lost and forgotten table. In such a way that when your shiny django backoffice gives you a fullscreen yellow error about duplicate keys. What now? Well, you read and i will show you how to circumvent the system (well, kind of).

|Read the Rest of the Entry…

How to add robots.txt to a Django project

So we had this nice, unfinished project, publicly shared on a public server being indexed like a pig’s behind on google servers. Some searches on google had hits to full length urls to this unfinished project on the test server. Easily stopped using the robots.txt, except that its a Django site and its not as simple as putting the file on the server’s root. Its not that hard either, but you have to know how.

Anyway, here are a few solutions i found:

|Read the Rest of the Entry…

Javascript Functions optional parameters

Ok, you want to create a function to be used several times (well, isnt that the main purpose of them?), but, depending on the call, you can have 1 argument or several. How do you go about doing it? Enter the world of optional parameter functions. Or something like that…after the jump.

Here are three ways:

|Read the Rest of the Entry…

PosgreSQL encoding problems

A very simple problem im sure all postgreSQL users/devs have come across one time or the other:

So you have your shiny PostgreSQL Database in some nice server somehwre and you want to manually make some changes. Say you have tons of records on some table and want to replace a word with a different one. All good, except the database in encoded in utf8 and you have text with accented characters.

Jump to learn.

|Read the Rest of the Entry…

PostgreSQL login basics

Just to keep things organized, i will leave this info here for one more hit on the interwebs.

There are tons of parameters and tips and tricks, but i will just leave the bare basics. After the jump.


|Read the Rest of the Entry…

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.

%d bloggers like this: