Showing Indexes in Postgresql

OK. If you want to see the indexes to a table in Postgresql you can do this here:

\d <TABLENMAE>

If that is not showing what you expected you can do this short sql statement.


select
 t.relname as table_name,
 i.relname as index_name,
 a.attname as column_name
from
 pg_class t,
 pg_class i,
 pg_index ix,
 pg_attribute a
where
 t.oid = ix.indrelid
 and i.oid = ix.indexrelid
 and a.attrelid = t.oid
 and a.attnum = ANY(ix.indkey)
 and t.relkind = 'r'
 and t.relname like 'not%'
order by
 t.relname,
 i.relname;

That shows all indexes which are beginning with “not”.

I heard from other database where you just have to type in “show indexes”. But why make it so easy if it can be so difficult.

The usability of postgresql is incredible bad!

jQuery textbox hinter in IE8

Maybe you know the jQuery textbox hinter. That is a JavaScript lib. that adds an text and a css class to input textbox in a HTML page. The idea behind this technic is to show a hint in a textbox. That can look like this here:

And as soon you click into the textbox the hint disappears. The jQuery textbox hinter makes a good job but in the IE8 it does not work and in my case it broke the whole jQuery code. The Problem was that in the javascript code of jQuery textbox hinter the name of the one attribute is “class”. That is keyword and it seems that makes the code IE8 broken.

I renamed the attribute and after the refactoring it worked fine in IE8. Here is my refactored version of the jQuery textbox hinter.


/*
 * jQuery - Textbox Hinter plugin v1.0
 * http://www.aakashweb.com/
 * Copyright 2010, Aakash Chakravarthy
 * Released under the MIT License.
 */

(function($){
   $.fn.tbHinter = function(options) {

   var defaults = {
      text: 'Enter a text ...',
      styleclass: ''
   };

   var options = $.extend(defaults, options);

   return this.each(function(){

      $(this).focus(function(){
         if($(this).val() == options.text){
            $(this).val('');
            $(this).removeClass(options.styleclass);
         }
      });

      $(this).blur(function(){
         if($(this).val() == ''){
            $(this).val(options.text);
            $(this).addClass(options.styleclass);
         }
      });

      $(this).blur();

   });
};
})(jQuery);

12Designer – to much mandatory

I tried to start a contest at 12Designer.com and after filling out the first form for the contest I got this error message.

Common! At least 250 character? Why??? No way!

I just skipped everything and started the contest at 99designs.com. And at 99designs there was not requirement for at least 250 characters. I just filled in the same sentence and it worked.

To much mandatory fields are not helping to get new users! It just sucks!

Dynamic method calls in Ruby

Ruby is a dynamic language. One of the coolest feature is the dynamic method call. Image you have a Integer Object.

a = 5

On every Object you can call the “to_s” method, that will convert it to String.

a.to_s

Will return the String representation of 5 that is “5″. But you can also call the method in a dynamic way:

a.send("to_s")

That is cool! Int that way you can make method calls dynamically and configurable.

Useful MongoDB commands

How to install MongoDB on Mac OS X I showed already here:
http://robert-reiz.com/2011/08/11/installing-mongodb-on-mac-ox-x-lion/

If everything is installed correctly, you can start the server process as root with this command:

mongod

and the client as no root with this command:

mongo

By default you are logged in into the “test” database. You can show all dbs with this command:

show dbs

you can switch to an existing DB or create a new DB with this command:

use mynewdb

With this command here you can show alle “collections” inside of the DB:

show collections

You can make an insert with this command:

db.users.save( { name : "myname" } )

If the collections “users” does not exist it will be created with the first call. With this command you can see all entries in the collection “users”:

db.users.find()

With count() you can see how many elements are in the collection.

db.users.count()

And with “remove” you can remove alle elements from a collections.

db.users.remove()

And with drop you can drop the entire collection.

db.users.drop()