Tuesday, June 5, 2012

jquery - get id of element that fired event

In jquery, event.target.id always refers to the element that triggers the event (or selected event). Sample below


$(document).ready(function() {
    $("a").click(function(event) {
        alert(event.target.id);
    });
});

download firefox 13 final release

In case you could not use auto upgrade, please download firefox 13 release here (link from mozilla)

http://www.mozilla.org/en-US/products/download.html?product=firefox-13.0&os=win&lang=en-US

Monday, June 4, 2012

List root folders in J2ME/Blackberry


The following code list/check all the folders that existed in SD card, which is inserted in J2ME or Blackberry running OS. Please remember to import necessarily packages (in eclipse based, us Ctrl + Shift + O)

String root = null;
Enumeration e = FileSystemRegistry.listRoots();
while (e.hasMoreElements()) {
root = (String) e.nextElement(); // device has a microSD
        if (root.equalsIgnoreCase("store")) {
          System.out.println("okies man - store/ is available");
        } else {
  System.out.println(root);
        }
}

Friday, May 11, 2012

Rails + PostgreSQL on Mac Lion

1) Install PostgreSQL

$brew install postgresql

Once the installation is complete it is important to follow all the instructions that brew created for us!
Here is a list of instructions to initialize a database named postgres and run postgresql on start-up:

$ initdb /usr/local/var/postgres
$ mkdir -p ~/Library/LaunchAgents
$ cp /usr/local/Cellar/postgresql/9.0.4/org.postgresql.postgres.plist ~/Library/LaunchAgents/
$ launchctl load -w ~/Library/LaunchAgents/org.postgresql.postgres.plist







or follow the instruction generated after installing.

2) Create PostgreSQL users

Login to psql console:

$ psql -h localhost postgres

If all is good we should see the command prompt:

postgres=#

Now lets create a user postgres:

postgres=# CREATE USER postgres WITH PASSWORD 'postgres';

And give it all permissions for postgres database that we created earlier:

postgres=# GRANT ALL PRIVILEGES ON DATABASE postgres to postgres;

3) Install pg gem

env ARCHFLAGS="-arch x86_64" gem install pg

4) Configure Rails project

Add the following lines to database,yml file:



  development:
    adapter: postgresql
    database: postgres
    username: postgres
    password: postgres
    host: localhost
    encoding: UTF8

Add pg gem to Gemfile:

gem 'pg', :require => 'pg'

Thursday, May 10, 2012

PHP - get full URL

There are times when we want to get the full path (URL) of a page, PHP makes it easy

function getPageURL() {
    $pageURL = 'http';

        // Check if https is enabled
    if ($_SERVER["HTTPS"] == "on") {
        $pageURL .= "s";
    }
    $pageURL .= "://";
    if ($_SERVER["SERVER_PORT"] != "80") {
        $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
    } else {
        $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
    }
 
    return $pageURL;
}

Call getPageURL() whenever you want to get the expected path.

Thursday, May 3, 2012

install ruby and ruby on rails on ubuntu 12.04

In summary

  • update your system
  • install git, curl, rvm
  • install required packages
  • install rails
  • done
Step by step

Update system
sudo apt-get update

Install git
sudo apt-get install git

Install curl
sudo apt-get install curl

Install rvm
curl -L get.rvm.io | bash -s stable

Reload to start using rvm
source ~/.rvm/scripts/rvm
or 
source /home//.rvm/scripts/rvm

Check required packages
rvm requirements

and then copy the install command from output, it should look like this
sudo apt-get -y install build-essential openssl libreadline6 libreadline6-dev zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion

Install Javascript runtime
sudo apt-get install nodejs

Install ruby
rvm install 1.9.3
(1.9.3 is the newest version at the time of this writing)

Set ruby version to default
rvm use 1.9.3 --default

Install rails
gem install rails

Done
start your app and see it works! cheers!


ubuntu - install LAMP server with one click

tasksel is a good service for installing LAMP on ubuntu 12.04 and 11.10

sudo apt-get install tasksel

sudo tasksel

this can be used to install postgreSQL and many others