Monday, November 9, 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.

Saturday, November 7, 2009

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">
$(document).ready(function(){
$("#btnA").click(function(event){
alert("Clicked ButtonA...!!!");
});
$("#btnB").click(function(event){
alert("Clicked ButtonB...!!!")
});
});

</script>
<body>
<p>
<input id="btnA" value="ButtonA" type="button">
<input id="btnB" value="ButtonB" type="button">
</p>
</body>

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; }
</style>

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.
Example,

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

<script type="text/javascript">
$(document).ready(function(){
$("#myLabel").addClass("test");
});
</script>
</head>
<body>
<h1>
<label id="myLabel">
Testing jQuery
</label>
</h1>
</body>

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">
$(document).ready(function(){
$("#myLabel").removeClass("test");
$("#myLabel").addClass("test2");
});
</script>
</head>
<body>
<h1>
<label class="test" id="myLabel">
Testing jQuery
</label>
</h1>
</body>

Now it will present,

Many more interesting things are coming.....
KIT.....

Friday, November 6, 2009

Have fun with jQuery 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 "http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js" on development.
Then you will import js file this manner,
 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></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.


<html>
<head>

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

<script type="text/javascript">

</script>
</head>

<body>
<a href="http://www.google.com/">My test link</a>
</body>
</html>


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

 $(document).ready(function(){
// Your code content here
});


Assume you want to give a pop up when you clicked on the "My test link". It is very simple.
 $(document).ready(function(){
$("a").click(function(event){
alert("We are going to visit google....!!!");
});
});


It will give you a popup and will direct to google.com.

Let's assume that you don't need to visit to google.com. 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.

 $(document).ready(function(){
$("a").click(function(event){
alert("We are going to visit google....!!!");
event.preventDefault();
});
});



Now you will receive the popup, but you will not forward to google.com.
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...

Thursday, November 5, 2009

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.

Microcontrollers...............

History..........

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.


Secure.....
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

Problems addressed by using SI

Swarm intelligence use to solve lot of problems in the current context. We use Ant colony like context and study them well to apply for problematic situations at the real world.
When the scientists going through the researches on they have came across some useful behaviors to apply solve problems.

1. Foraging and Optimization
Usually ants goes to the nearest and most promising food source. They use mechanism to find the shortest and most promising food source by using their own methods. One of them is, two ants go in two ways to find the food sources. The ant which came first is come back to the colony with leaving some pheromone (essence) on its way. Because of that, the ant which is coming next (3rd ant) goes on 1st ants way. When the 2nd ant come back to the colony the 1st ant’s way has laid more pheromone s. Since that other ants go on the path of 1st ant went. So that, it becomes the optimize way to find food.
In computer context we use the above intelligence to create network optimization. Swarm intelligence based network optimization is a very important concept to optimize the networks depends on the feed backs of the messages.

2. Routing
Routing is the mechanism to handle the message on switching station. In this case “AntNet” is a developed model of Routing for communication systems using swarm intelligence. There are few more algorithms which developed by using swarm intelligence. But “AntNet” is the most favorite one.
When a colony trying to forage, the pheromone laid by another colony repel to add pheromone. So, that route will not allow foraging this colony. This kind of architecture helps to load balance of a network system. That’s only a one solution to decide routing. Likewise, lots of applications are there to implement efficient Routing systems.

3. Clustering and Sorting, Larvae and data
There are lots of optimization methods using Swarm Intelligence. Mainly it has been used Ant Colony Optimization (ACO) and Practical Swarm Optimization (PSO) methods to develop them.
If we take an example on Ant Colony, they use to collect and group their dead bodies in order to keep the colony clean. The scientists studied this and developed clustering methods to apply in real world context.

4. Division of Labor
Usually swarm systems are doing their works by Dividing among them to achieve. For example in a honeybee colony, each of the have specialized certain task for each bee. Basically it depends on the age of a bee. But if a particular bee wants to do more tasks, they can do it too.

5. Cooperative Transport
This is a very general characteristic of having with all Swarm Systems. For example a single ant can’t bring a little bit bigger food part to the colony. There should be many ants to carry it. All of them get together and bring it to their place.
This technique is uses to create some robots, which are having some huge tasks to do. They make the system, which is a collection of a small part to carry much larger weight.

Reference: My Previous Blog