Monday, November 23, 2009

Change Proxy Settings on linux using shell commands

You can change the proxy settings for current session by executing following command. Which changes the environment variable "http_proxy". If you want, you can do it for ftp as well (ftp_proxy).
export http_proxy="http://NewProxy_address:Port"

Assume my proxy run on machine on port 808, then this settings will be
export http_proxy=""

Personal Experience

Recently, I installed Ubuntu server 8.04 and while the installation I set proxy settings wrong manner. In that case, installation guide give the format of "http://[[[user]:[passowrd]@serverIP]:[port]]" to enter proxy settings. Since I was using my proxy server in a windows machine, I had problem of giving username@server:port format. I gave it http://janaka@, but it is only necessary to give So I needed to permanently change it. If you only used above command, it will not be there when you reboot the linux os. Because it is just changing the current environmental variable "http_proxy".
Using following changes you could permanently change the settings.
If you wanted to add it for any user add export http_proxy="" on ~/.bashrc file.
 vi ~/.bashrc

If you want to do it for current user, add export http_proxy="" on /etc/rc.local.
vi /etc/rc.local
The File will look like below.
And then change the execution bit to execute this script while loading.
chmod u+x /etc/rc.local

Now it should be working.

Sunday, November 22, 2009

Log4j - Logging package

Log4j is a package which supports to do logging very easily. This logging outputs can be taken in many ways.

There are many more types can be used,
AsyncAppender, JDBCAppender, JMSAppender, LF5Appender, NTEventLogAppender,
NullAppender, NullAppender, SMTPAppender, SocketAppender, SocketHubAppender,
SyslogAppender, TelnetAppender, DailyRollingFileAppender, RollingFileAppender.
To begin with log4j, you should first download the log4j package. Here is a sample link to download it.

Log Levels

There are some log levels defined in log4j.
  1. all - All levels including custom levels
  2. trace (since log4j 1.2.12) - Developing only, can be used to follow the program execution.
  3. debug - Developing only, for debugging purpose
  4. info - Production optionally, Course grained (rarely written information), I use it to print that a configuration is initialized, a long running import job is starting and ending.
  5. warn - Production, simple application error or unexpected behaviour. Application can continue. I warn for example in case of bad logging attempts, unexpected data during import jobs
  6. error - Production, application error/exception but
    application can continue. Part of the application is probably not working
  7. fatal - Production, fatal application error/exception, application cannot continue, for example database is down.
  8. no - Do not log at all.

A simple example

First you better add downloaded jar package to the project using your IDE. Then you have to setup the log4j properties through property file or, xml file.... In this case, let's check with file. In your IDE, as other property files add your log4j properties file. For example create new file called "" It should be look like this.
log4j.rootLogger=debug, file
log4j.appender.file=org.apache.log4j.RollingFileAppender #logging Type
log4j.appender.file.maxFileSize=100KB #Max file size of a log file
log4j.appender.file.maxBackupIndex=5 #keeping backups of
log4j.appender.file.File=C://myprogram_logs/test.log #Location which saving log file
log4j.appender.file.threshold=debug #Log Level
log4j.appender.file.layout=org.apache.log4j.PatternLayout #Layout of the log file
log4j.appender.file.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n #Layout of the log file
I am using RollingFileAppender here. Max file size is 100KB, kind of all the properties related to Log4j is stated here.
At your java file, load the property file and put it into the PropertyConfigurator on log4j package. Example code snipped here,
Improte packages

import org.apache.log4j.PropertyConfigurator;
import org.apache.log4j.Logger;
import java.util.Properties;
On the relevant class, define the Logger type global variable(in my case "logger").
private static Logger logger = Logger.getLogger(MyProgram.class);
On main method,
   public static void main(String[] args){
Properties properties = new Properties();
InputStream inputStream = MyProgram.class.getClassLoader().getResourceAsStream("");
PropertyConfigurator.configure(properties);"My program Begins");
When you catch an exception, write it on log as follows
     try {
//Your code here
} catch (Exception e) {
logger.error("Found the exception here");

Now you will find logs on C://myprogram_logs/test.log location file.
When you need to use it in ubuntu, you just have to change the file location only from the properties file (i.e. /var/myprogram_logs/test.log).
See how easy logging you programming status with Log4j........
Here is a nice pdf to follow.

Tuesday, November 17, 2009

"The Twilight Saga: New Moon" for Sri Lankans...

Hay sri lankan Twilight fans, you all will be able to watch Twilight at MC soon...............
You can buy tickets from TicketsLK.
Frnz itz movie time.....

Sunday, November 15, 2009

Windows TortoiseGit client for a linux Gitosis server

Tortoise git is really nice Graphical tool to handle git repository. You need to download TortoiseGit from here. First of all as we discussed earlier you need to install msysgit first. Then install the Tortoisegit and install it. While installing it Select open ssh client option for authentication method.
And completely install it and restart your computer. First of all you should add the msysgit path for this system. Tortoisegit gets the git options from msysgit. Right click on your desktop and go to settings,Set the path to the bin of the msysgit. Now setting your authentication on the server should be set. For that TortoiseGit has shipped putty Keygen for generate keys. But in this case, since we are connecting with a linux server the private keys which generate by putty key gen won't be recognize by the server. Since that you will not recognized correctly at the server end. To avoid this inconvenience you can create ssh keys through ssh-keygen. On your command prompt.

Do not use puttyGen in this case to create key pairs.

Go to your account on the windows os(i.e. C:\Documents and Settings\Janaka), check whether there is a folder called ".ssh" if not, create it using command prompts "mkdir .ssh" command. This is the place we keep your key pairs. keys you generated (, id_rsa) copy to this folder. Now follow the usual users adding mechanism on git server.Click here for more info.
Now you can go to any location on your computer and right click select option git clone... or git zync you will receive following screen. Put the remote URL as to your git repository. git@ It will import the repository to your local folder. Like wise all the operations can be done through GUI. You don't have to type git commands on doing this.
Any comments........???

Creating gitosis repository and adding users to projects

Cont from, Previous post

Adding new repo(gitosis.conf)

Administrator is the only authenticated user for this (In according to previous posts in my case it's janaka). First administrator can log to the server which runs git.First it is better to add the repository on the conf file. And you can add users for this repository.
janaka@versioncontrol~/gitosis-admin $ vi gitosis.conf

Your conf file look like this,

[group gitosis-admin]
writable = gitosis-admin
members = janaka@versioncontrol

Edit it and add new repo, Now it will looks like,

[group gitosis-admin]
writable = gitosis-admin
members = janaka@versioncontrol

[repo my_first_repo]
gitweb = no
description = This could be my first repo
owner = No one else thats me,
daemon = no

Creating a user group

Your conf file look like this,

[group gitosis-admin]
writable = gitosis-admin
members = janaka@versioncontrol

[repo my_first_repo]
gitweb = no
description = This could be my first repo
owner = No one else thats me,
daemon = no

Edit this file and add new group,


[group gitosis-admin]
writable = gitosis-admin
members = janaka@versioncontrol

[group my_users]
writable = my_first_repo
members = janaka@versioncontrol gituser1

[repo my_first_repo]
gitweb = no
description = This could be my first repo
owner = No one else thats me,
daemon = no

gituser1 is the newly added user, his key is named as on keydir/ directory.
Now you should add this changed gitosis.conf file and update gitosis-admin repository. You can do it by executing following commands.
janaka@versioncontrol~/gitosis-admin$ git add gitosis.conf
janaka@versioncontrol~/gitosis-admin$ git commit -m "Added new repo on conf file"
janaka@versioncontrol~/gitosis-admin$ git push

Then you can create the directory you want and create physical repository.

Creating new repository

Create a directory with naming it on your wish.
janaka@versioncontrol~$ mkdir my_first_repo
Now go into it, Don't forget to add some files before initialize this repo. Otherwise it will not be added as a repository,
janaka@versioncontrol/my_first_repo~$ touch readme
then follow the given commands to initialize the repository,
cd my_first_repo
git init
git remote add origin git@
git add .
git commit -m "Hai buddies, we added my_first_repo"
git push origin master:refs/heads/master the server which runs git on it. Now the new repository is created.
This is it, now gituser1 can use the my_first_repo repository. You can check on client machine,
git clone git@

On windows client side, If you'r only using command prompt, why don't you go for TortoiseGit to make life easier. TortoiseGit is a graphical tool to access git repository. Follow

"Graphical controls for Git windows clients"

link and study it.

Saturday, November 14, 2009

(Tortoisegit + Gitosis + msysgit) configuring - Adding windows users and creating repo

Cont. from previous post
Now you are ready to add users to the server.
It is not that much hard to add ubuntu users.
You just have to install git-core and by adding keys to the key directory. You can add users. If you are a windows user you have to do some installations. There are few ways to access repositories as windows user.

Clients using who use command prompt

First you should download msysgit from here and run the exe. Assume you downloaded the full version.

Give the path as your wish.
To run git commands at anywhere from your command prompt, define a path variable on environment variables Right Click on My Computer => Properties => Advanced => Environemnt Variables => Edit or New give the variable name as "PATH", and variable value "C:\msysgit\msysgit\bin", the bin folder of the msysgit installed. And add the "C:\msysgit\msysgit\mingw\bin" path also, that means, variable value will looks like, "C:\msysgit\msysgit\bin;C:\msysgit\msysgit\mingw\bin"

Then go to start => run => cmd type git and press enter. You will get result like,

Now you are ready to use git.

Adding user

First of all you have to create a key pair for your self. Get the command prompt and navigate to the msysgit folder to create .ssh directory.
C:\msysgit\msysgit\> mkdir .ssh

You are not allowed to create folders beginning with "." by right click => New => folder. So that it should be created this way.

Now navigate into the .ssh folder. We are going to create key pair.
C:\msysgit\msysgit\.ssh> ssh-keygen 
give id_rsa for the key name.
Following result will be shown.
Generating public/private rsa key pair.
Enter file in which to save the key (//.ssh/id_rsa): id_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in id_rsa.
Your public key has been saved in
The key fingerprint is:
92:0c:83:16:16:14:04:51:30:42:da:5d:df:fd:fb:15 Janaka@XPWINDOWS7

Now you need to transfer the public key to the server where your gitosis administrator belongs. With previous posts, you might remember my username at version control is janaka. Following command will carry your key to that server's keydir directory.On my command prompt,
C:\msysgit\msysgit\.ssh>scp janaka@
(Assume is the server that installed gitosis) using this command or anyhow you can copy your key to keydir/ directory.
Don't change the names of the public and private keys of the(id_rsa, on your local machine. Keep it as it is on .ssh folder.
Now the administrators part,
Admin should allow this key to copy to server and rename it. When renaming, keep remember to give the same name that you are planing to add in .conf file. If new user is gituser1, then public key should be renamed to on server.
On the server, admin should enter the this user into a user list of gitosis.conf file. You can see how to create new repository and work groups in this link.
On gitosis.conf,
[group myteam]
members = gituser1
writable = my_current_project
member should be the name of the added public key(without .pub) and writable is the repository which are writable by this team. Group name is myteam.
Now administrator should add these key file and changed gitosis.conf file and push it to git user. Actually administrator just cloning the gitosis-admin part from the "git" user and after changes pushing it back. Here are the commands for admin,
janaka@versioncontrol~$ git clone git@
janaka@versioncontrol~$ cd gitosis-admin
janaka@versioncontrol~/gitosis-admin $ git add keydir/
janaka@versioncontrol~/gitosis-admin $ git add gitosis.conf
janaka@versioncontrol~/gitosis-admin $ git commit -a -m "Added gituser1 as a new user"
janaka@versioncontrol~/gitosis-admin $ git push
Now on the client side (gituser1) can check whether he had successfully added. On command prompt he can try to add a clone.
C:\MyFolder> git clone git@

If it imported my_current_project folder without asking any password for git user it is successfully worked. Issued can be occured,
  • Ask a password for git user- your keys are not matching recreate the key pairs and install keys accurately.

  • Giving no permissions error- You have not been added successfully for that group on gitosis.conf file. Reedit the conf file.

Widows clients using Gitosis

You can find post regarding this from here

Creating new repository and adding permission groups

will be discussed here

Setting up Gitosis(version control system) on Linux server and adding windows clients

Git is a kind of a version control system which allows users to keep their project information safely in repositories. In this case, I will be using Gitosis for this setup, Gitosis is a tool written for Git that helps in the setup of secure access controlled repositories. It will manage multiple repositories under one user account on the host machine. Using SSH keys to identify users, your repositories will be securely accessed and controlled. One large advantage to Gitosis is that your users will not need shell accounts on the machine to access repositories, they will however speak to a singular account what will not allow arbitrary commands. Now let's see how gitosis can install in to your Ubuntu server.

Installing Gitosis

First of all you should have installed Git.
sudo apt-get install git-core

By cloning the gitosis directory from "" you will get the gitosis directory on your home page. Follow these lines to do it,
   cd ~/
git clone git://

Now you better move that folder to /usr/local
   sudo mv gitosis/ /usr/local

Now go to Gitosis folder.
   cd /usr/local/gitosis/

If you haven't installed python in your computer get it installed.
   sudo apt-get install python-setuptools

Then, you can run the file which is in this directory.
   sudo python install

Now you are successfully installed Gitosis on your Linux server.
Next, you have to create user called "git". "git" is the repositories holding real user. It creates in a way that users to identify through ssh-keys. Anyone can't login through entering password.
 sudo adduser \
--system \
--shell /bin/sh \
--gecos 'git version control' \
--group \
--disabled-password \
--home /home/git \


Now let's initialize the gitosis and begin with adding an administrator to git repository. As a convention we used to create administrator account on the same server/computer. Because administrator has the super power of creating new repository, users and so on.
To identify administrator, you need to create create ssh key and initialize gitosis with that key. So you will add as the administrator.(janaka is the user, versioncontrol is the name of the linux server)
janaka@versioncontrol~$ ssh-keygen -t rsa

Keep blank for the parse phrase of the key. Found this generated key pair at /home/janaka/.ssh/ as id_rsa(private key) and key).
Since janaka@versioncontrol wants to the admin and versioncontrol is the git server itself. You can directly initialize with this key.
sudo -H -u git gitosis-init < /home/janaka/.ssh/ 

If your admin wants to be another user, generate this kind of key pair and copy it some where at versioncontrol(i.e. /tmp/ In this case,
sudo -H -u git gitosis-init < /tmp/ 

If you are success then it will give,
Initialized empty Git repository in ./
Initialized empty Git repository in ./

Congratz, Now you are the gitosis-admin....!!!!
Now you need to make executable the post-update hook. Run following command.
sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update

Its ready to take your admin clone..............
git clone git@YOUR_SERVER_HOSTNAME:gitosis-admin.git

In my case YOUR_SERVER_NAME is "localhost". If you (admin) from another host, give the ip of the linux server/machine(versioncontrol).
Now have go to cloned gitosis-admin directory.
janaka@versioncontrol~$ cd gitosis-admin 

Have a look at the list,
You will found "gitosis.conf" file and "keydir" directory.
Have a look at the gitosis.conf file,
vi gitosis.conf


[group gitosis-admin]
writable = gitosis-admin
members = janaka@versioncontrol

Now lets see how to add users and creating new repositories.
Since this post getting longer, Follow Next post. click here

Adding Windows users to the gitosis and Many more

Thursday, November 12, 2009

Change Locale ubuntu server UTF-8 to ISO-8859-1

I was trying to get some sinhala words from database using java. It was nicely working at on windows. When I moved java program to ubuntu server, it returned some unexpected characters.
That happened because of ubuntu using itz default Locale as UTF-8. But some characters at UTF-8 doesn't support for it. Since that it can't give the real output. Since that you should update your Locale for "ISO-8859-1".
To do that you can update your Locale using

locale-gen en_GB
update-locale LANG=en_GB.ISO-8859-1

Then it you won't be getting any bad character expect you entered ones.
Have fun on developing.

Have fun with jQuery - Tutorial 2

As we discussed earlier, jQuery is a powerful javascript API on developing web applications. Here lets consider, how jQuery actions can be applied on specified elements.

Suppose you have got two buttons which we call ButtonA and ButtonB,

<script type="text/javascript" src="jquery-1.3.1.min.js"> </script>

<script type="text/javascript">
alert("Clicked ButtonA...!!!");
alert("Clicked ButtonB...!!!")

<input id="btnA" value="ButtonA" type="button">
<input id="btnB" value="ButtonB" type="button">

When you click on Buttons, it will pop up two different alert boxes as we defined in script.

That is how we define actions for a given element. To make it easy to understand, I displayed just popping up an alert box. It is useful in various applications.

Now lets see, how jQuery can be used with styling elements. First you better create some style classes like I have mentioned below.

<style type="text/css">
label.test { font-style: italic; }
label.test2 { color:#FF0033; }

Very easily you can apply your style class to an element using ELEMENT.addClass("CLASSNAME") function. If you want to remove it, you can call ELEMENT.removeClass("CLASSNAME") funciton. jQuery call for applying or removing class will receive the priority.

<script type="text/javascript" src="jquery.js"> </script>

<script type="text/javascript">
<label id="myLabel">
Testing jQuery

This will Present,

Now Lets remove an applied class and add another class,

<script type="text/javascript" src="jquery.js"> </script>

<script type="text/javascript">
<label class="test" id="myLabel">
Testing jQuery

Now it will present,

Many more interesting things are coming.....

Have fun with jQuery - Tutorial 1

jQuery is a simple javascript API which can be used in many ways to improve your web application or Web site.
First of all you have to download the jQuery javascript file from here (jquery-1.3.1.min.js). Then you can add it to your project like this way,

 <script type="text/javascript" src="jquery-1.3.1.min.js"></script>

Else you can use refer this link "" on development.
Then you will import js file this manner,
 <script type="text/javascript" src=""></script>

Now your are ready to start develop with jQuery.
Let's begin with a simple example.
Create a simple html file which is having a html component. You can use any component. In this case, Let's get a <a> tag. It can be a button, submit, label or any thing.


<script type="text/javascript" src="jquery.js"></script>

<script type="text/javascript">


<a href="">My test link</a>

We are going to use ready status of the page loading. Since that, we used to write as following simple code,

// Your code content here

Assume you want to give a pop up when you clicked on the "My test link". It is very simple.
alert("We are going to visit google....!!!");

It will give you a popup and will direct to

Let's assume that you don't need to visit to Then there is a jQuery functionality for disable default functions of the element. What you have to do is add preventDefault() method to onclick function event. It can be achieved easily following way.

alert("We are going to visit google....!!!");

Now you will receive the popup, but you will not forward to
According to above code, it will be applied for all places where <a> tags are available. It is possible to write this kind of event handling and many more things using jQuery. Let's meet on next tutorial to see how the things can be applied for specified (specified by the id) elements.
Thank you.
See you soon...

Closure Tools

Millions of Google users worldwide use JavaScript-intensive applications such as Gmail, Google Docs, and Google Maps. Like developers everywhere, Googlers want great web apps to be easier to create, so we've built many tools to help us develop these (and many other) apps. We're happy to announce the open sourcing of these tools, and proud to make them available to the web development community.

Closure Compiler
Closure Compiler is a JavaScript optimizer that compiles web apps down into compact, high-performance JavaScript code. The compiler removes dead code, then rewrites and minimizes what's left so that it will run fast on browsers' JavaScript engines. The compiler also checks syntax, variable references, and types, and warns about other common JavaScript pitfalls. These checks and optimizations help you write apps that are less buggy and easier to maintain. You can use the compiler with Closure Inspector, a Firebug extension that makes debugging the obfuscated code almost as easy as debugging the human-readable source.

Because JavaScript developers are a diverse bunch, we've set up a number of ways to run the Closure Compiler. We've open-sourced a command-line tool. We've created a web application that accepts your code for compilation through a text box or a RESTful API. We are also offering a Firefox extension that you can use with Page Speed to conveniently see the performance benefits for your web pages.

Closure Library
Closure Library is a broad, well-tested, modular, and cross-browser JavaScript library. Web developers can pull just what they need from a wide set of reusable UI widgets and controls, as well as lower-level utilities for the DOM, server communication, animation, data structures, unit testing, rich-text editing, and much, much more. (Seriously. Check the docs.)

JavaScript lacks a standard class library like the STL or JDK. At Google, Closure Library serves as our "standard JavaScript library" for creating large, complex web applications. It's purposely server-agnostic and intended for use with the Closure Compiler. You can make your project big and complex (with namespacing and type checking), yet small and fast over the wire (with compilation). The Closure Library provides clean utilities for common tasks so that you spend your time writing your app rather than writing utilities and browser abstractions.

Closure Templates
Closure Templates grew out of a desire for web templates that are precompiled to efficient JavaScript.  Closure Templates have a simple syntax that is natural for programmers.  Unlike traditional templating systems, you can think of Closure Templates as small components that you compose to form your user interface, instead of having to create one big template per page.

Closure Templates are implemented for both JavaScript and Java, so you can use the same templates both on the server and client side.

Closure Compiler, Closure Library, Closure Templates, and Closure Inspector all started as 20% projects and hundreds of Googlers have contributed thousands of patches. Today, each Closure Tool has grown to be a key part of the JavaScript infrastructure behind web apps at Google.  That's why we're particularly excited (and humbled) to open source them to encourage and support web development outside Google. We want to hear what you think, but more importantly, we want to see what you make. So have at it and have fun!

Reference: Introducing Closure Tools

Speed up your web browsing

Google has introduced an application called PAGE SPEED which increase your browsing speed.

Best Practices

If you have got installed firebug with your firefox browser, you can directly downloaded and installed Page Speed with this link.



The first microcontroller was the Intel 8048, released in 1976.

The popularity of microcontrollers increased when EEPROM memory was incorporated to replace one time programmable PROM memory. With EEPROM, the development cycle of programming, testing and erasing a part could be repeated many times with the same part until the firmware was debugged and ready for production use.

Nowadays microcontrollers are low cost and readily available for hobbyists.

Brief for Microcontrollers..............
A microcontroller (also MCU or ┬ÁC) is a computer-on-a-chip. It is a type of microprocessor emphasizing high integration, low power consumption, self-sufficiency and cost-effectiveness, in contrast to a general-purpose microprocessor (the kind used in a PC). In addition to the usual arithmetic and logic elements of a general purpose microprocessor, the microcontroller typically integrates additional elements such as read-write memory for data storage, read-only memory, such as flash for code storage, EEPROM for permanent data storage, peripheral devices, and input/output interfaces. At clock speeds of as little as a few MHz or even lower, microcontrollers often operate at very low speed compared to modern day microprocessors, but this is adequate for typical applications. They consume relatively little power (milliwatts), and will generally have the ability to sleep while waiting for an interesting peripheral event such as a button press to wake them up again to do something. Power consumption while sleeping may be just nanowatts, making them ideal for low power and long lasting battery applications.

Microcontrollers are frequently used in automatically controlled products and devices, such as automobile engine control systems, remote controls, office machines, appliances, power tools, and toys. By reducing the size, cost, and power consumption compared to a design using a separate microprocessor, memory, and input/output devices, microcontrollers make it economical to electronically control many more processes.

Maxim's secure microcontrollers encrypt program and data memory, thus preventing unauthorized system access. This memory encryption makes them ideal for applications requiring absolute protection of code and data, such as passwords and PINs.
Battery-Backed Technology "Zeroizes" Internal SRAM Upon Tamper Event
DES/3DES Encryption Prevents External Bus Eavesdropping

Reference: My Previous Blog