Wednesday, February 3, 2010

Live news feeds on your web site (Local news at Sri Lanka)

Lanka News papers website http://www.lankanewspapers.com provides a simple and nice tool to publish news on your website. Add the following piece of code on your website to add this feature.
 <script language="javascript" src="http://www.lankanewspapers.com/news/RSS_Java.jsp">
</script>

<script language='JavaScript'>
SL_News_Display(
'10', // Number of headlines to show (Max 20)
'200', // Width of the news table
'font-family: helvetica, impact, sans-serif;font-size: 10pt;', // Font
'#FFFFFF', // Background color of news table
'1' // Border width
);
</script>


Reference:

Friday, January 1, 2010

Sony Ericsson Information Web Synchronize (Store, Edit, share your mobile life)

Hi all....
This will be really helpful you guyz for save your valuable information on you phone. For instance if you lost your phone all the information on your phone will be lost with this. But Sony Ericsson has introduce nice web synchronizing tool which creates a clone of the information on your phone with them. It will help you to get back your information.
It keeps,
  • Contacts
  • Calendar
  • Bookmarks
  • Notes
  • Tasks


What you have to do is visit http://www.sonyericsson.com/wportal/uss/promotion?cc=lk&lc=en and create your own account. And according to the instructions giving by the application setup your synchronizing account of your mobile phone. To that, go in your phone, Menu > Settings >Connectivity >Synchronization. Create new account and add settings For example synchronizing server will be http://sync.sonyericsson.com/sync/server. Like wise set your settings according to the instructions giving.
Then go to the created profile and start synchronizing.
It's still on Beta version. But it is working properly.

Thursday, December 24, 2009

Snow fall on your website

You can add snow storm for your web site easily.....
Copy the following code to a new javascript file....

var snowStorm = null;

function SnowStorm() {

// --- PROPERTIES ---

this.flakesMax = 128; // Limit total amount of snow made (falling + sticking)
this.flakesMaxActive = 64; // Limit amount of snow falling at once (less = lower CPU use)
this.animationInterval = 35; // Theoretical "miliseconds per frame" measurement. 20 = fast + smooth, but high CPU use. 50 = more conservative, but slower
this.flakeBottom = null; // Integer for Y axis snow limit, 0 or null for "full-screen" snow effect
this.targetElement = null; // element which snow will be appended to (document body if null/undefined) - can be an element ID string, or a DOM node reference
this.followMouse = true; // Snow will change movement with the user's mouse
this.snowColor = '#fff'; // Don't eat (or use?) yellow snow.
this.snowCharacter = '*'; // • = bullet, · is square on some systems etc.
this.snowStick = false; // Whether or not snow should "stick" at the bottom. When off, will never collect.
this.useMeltEffect = true; // When recycling fallen snow (or rarely, when falling), have it "melt" and fade out if browser supports it
this.useTwinkleEffect = false; // Allow snow to randomly "flicker" in and out of view while falling
this.usePositionFixed = false; // true = snow not affected by window scroll. may increase CPU load, disabled by default - if enabled, used only where supported

// --- less-used bits ---

this.flakeLeftOffset = 0; // amount to subtract from edges of container
this.flakeRightOffset = 0; // amount to subtract from edges of container
this.flakeWidth = 8; // max pixel width for snow element
this.flakeHeight = 8; // max pixel height for snow element
this.vMaxX = 5; // Maximum X velocity range for snow
this.vMaxY = 4; // Maximum Y velocity range
this.zIndex = 0; // CSS stacking order applied to each snowflake

// --- End of user section ---

// jslint global declarations
/*global window, document, navigator, clearInterval, setInterval */

var addEvent = (typeof(window.attachEvent)=='undefined'?function(o,evtName,evtHandler) {
return o.addEventListener(evtName,evtHandler,false);
}:function(o,evtName,evtHandler) {
return o.attachEvent('on'+evtName,evtHandler);
});

var removeEvent = (typeof(window.attachEvent)=='undefined'?function(o,evtName,evtHandler) {
return o.removeEventListener(evtName,evtHandler,false);
}:function(o,evtName,evtHandler) {
return o.detachEvent('on'+evtName,evtHandler);
});

function rnd(n,min) {
if (isNaN(min)) {
min = 0;
}
return (Math.random()*n)+min;
}

function plusMinus(n) {
return (parseInt(rnd(2),10)==1?n*-1:n);
}

var s = this;
var storm = this;
this.timers = [];
this.flakes = [];
this.disabled = false;
this.active = false;

var isIE = navigator.userAgent.match(/msie/i);
var isIE6 = navigator.userAgent.match(/msie 6/i);
var isOldIE = (isIE && (isIE6 || navigator.userAgent.match(/msie 5/i)));
var isWin9X = navigator.appVersion.match(/windows 98/i);
var isiPhone = navigator.userAgent.match(/iphone/i);
var isBackCompatIE = (isIE && document.compatMode == 'BackCompat');
var noFixed = ((isBackCompatIE || isIE6 || isiPhone)?true:false);
var screenX = null;
var screenX2 = null;
var screenY = null;
var scrollY = null;
var vRndX = null;
var vRndY = null;
var windOffset = 1;
var windMultiplier = 2;
var flakeTypes = 6;
var fixedForEverything = false;
var opacitySupported = (function(){
try {
document.createElement('div').style.opacity = '0.5';
} catch (e) {
return false;
}
return true;
})();
var docFrag = document.createDocumentFragment();
if (s.flakeLeftOffset === null) {
s.flakeLeftOffset = 0;
}
if (s.flakeRightOffset === null) {
s.flakeRightOffset = 0;
}

this.meltFrameCount = 20;
this.meltFrames = [];
for (var i=0; i this.meltFrames.push(1-(i/this.meltFrameCount));
}

this.randomizeWind = function() {
vRndX = plusMinus(rnd(s.vMaxX,0.2));
vRndY = rnd(s.vMaxY,0.2);
if (this.flakes) {
for (var i=0; i if (this.flakes[i].active) {
this.flakes[i].setVelocities();
}
}
}
};

this.scrollHandler = function() {
// "attach" snowflakes to bottom of window if no absolute bottom value was given
scrollY = (s.flakeBottom?0:parseInt(window.scrollY||document.documentElement.scrollTop||document.body.scrollTop,10));
if (isNaN(scrollY)) {
scrollY = 0; // Netscape 6 scroll fix
}
if (!fixedForEverything && !s.flakeBottom && s.flakes) {
for (var i=s.flakes.length; i--;) {
if (s.flakes[i].active === 0) {
s.flakes[i].stick();
}
}
}
};

this.resizeHandler = function() {
if (window.innerWidth || window.innerHeight) {
screenX = window.innerWidth-(!isIE?16:2)-s.flakeRightOffset;
screenY = (s.flakeBottom?s.flakeBottom:window.innerHeight);
} else {
screenX = (document.documentElement.clientWidth||document.body.clientWidth||document.body.scrollWidth)-(!isIE?8:0)-s.flakeRightOffset;
screenY = s.flakeBottom?s.flakeBottom:(document.documentElement.clientHeight||document.body.clientHeight||document.body.scrollHeight);
}
screenX2 = parseInt(screenX/2,10);
};

this.resizeHandlerAlt = function() {
screenX = s.targetElement.offsetLeft+s.targetElement.offsetWidth-s.flakeRightOffset;
screenY = s.flakeBottom?s.flakeBottom:s.targetElement.offsetTop+s.targetElement.offsetHeight;
screenX2 = parseInt(screenX/2,10);
};

this.freeze = function() {
// pause animation
if (!s.disabled) {
s.disabled = 1;
} else {
return false;
}
for (var i=s.timers.length; i--;) {
clearInterval(s.timers[i]);
}
};

this.resume = function() {
if (s.disabled) {
s.disabled = 0;
} else {
return false;
}
s.timerInit();
};

this.toggleSnow = function() {
if (!s.flakes.length) {
// first run
s.start();
} else {
s.active = !s.active;
if (s.active) {
s.show();
s.resume();
} else {
s.stop();
s.freeze();
}
}
};

this.stop = function() {
this.freeze();
for (var i=this.flakes.length; i--;) {
this.flakes[i].o.style.display = 'none';
}
removeEvent(window,'scroll',s.scrollHandler);
removeEvent(window,'resize',s.resizeHandler);
if (!isOldIE) {
removeEvent(window,'blur',s.freeze);
removeEvent(window,'focus',s.resume);
}
};

this.show = function() {
for (var i=this.flakes.length; i--;) {
this.flakes[i].o.style.display = 'block';
}
};

this.SnowFlake = function(parent,type,x,y) {
var s = this;
var storm = parent;
this.type = type;
this.x = x||parseInt(rnd(screenX-20),10);
this.y = (!isNaN(y)?y:-rnd(screenY)-12);
this.vX = null;
this.vY = null;
this.vAmpTypes = [1,1.2,1.4,1.6,1.8]; // "amplification" for vX/vY (based on flake size/type)
this.vAmp = this.vAmpTypes[this.type];
this.melting = false;
this.meltFrameCount = storm.meltFrameCount;
this.meltFrames = storm.meltFrames;
this.meltFrame = 0;
this.twinkleFrame = 0;
this.active = 1;
this.fontSize = (10+(this.type/5)*10);
this.o = document.createElement('div');
this.o.innerHTML = storm.snowCharacter;
this.o.style.color = storm.snowColor;
this.o.style.position = (fixedForEverything?'fixed':'absolute');
this.o.style.width = storm.flakeWidth+'px';
this.o.style.height = storm.flakeHeight+'px';
this.o.style.fontFamily = 'arial,verdana';
this.o.style.overflow = 'hidden';
this.o.style.fontWeight = 'normal';
this.o.style.zIndex = storm.zIndex;
docFrag.appendChild(this.o);

this.refresh = function() {
if (isNaN(s.x) || isNaN(s.y)) {
// safety check
return false;
}
s.o.style.left = s.x+'px';
s.o.style.top = s.y+'px';
};

this.stick = function() {
if (noFixed || (storm.targetElement != document.documentElement && storm.targetElement != document.body)) {
s.o.style.top = (screenY+scrollY-storm.flakeHeight)+'px';
} else if (storm.flakeBottom) {
s.o.style.top = storm.flakeBottom+'px';
} else {
s.o.style.display = 'none';
s.o.style.top = 'auto';
s.o.style.bottom = '0px';
s.o.style.position = 'fixed';
s.o.style.display = 'block';
}
};

this.vCheck = function() {
if (s.vX>=0 && s.vX<0.2) {
s.vX = 0.2;
} else if (s.vX<0 && s.vX>-0.2) {
s.vX = -0.2;
}
if (s.vY>=0 && s.vY<0.2) {
s.vY = 0.2;
}
};

this.move = function() {
var vX = s.vX*windOffset;
s.x += vX;
s.y += (s.vY*s.vAmp);
if (s.x >= screenX || screenX-s.x < storm.flakeWidth) { // X-axis scroll check
s.x = 0;
} else if (vX < 0 && s.x-storm.flakeLeftOffset<0-storm.flakeWidth) {
s.x = screenX-storm.flakeWidth-1; // flakeWidth;
}
s.refresh();
var yDiff = screenY+scrollY-s.y;
if (yDiff s.active = 0;
if (storm.snowStick) {
s.stick();
} else {
s.recycle();
}
} else {
if (storm.useMeltEffect && s.active && s.type < 3 && !s.melting && Math.random()>0.998) {
// ~1/1000 chance of melting mid-air, with each frame
s.melting = true;
s.melt();
// only incrementally melt one frame
// s.melting = false;
}
if (storm.useTwinkleEffect) {
if (!s.twinkleFrame) {
if (Math.random()>0.9) {
s.twinkleFrame = parseInt(Math.random()*20,10);
}
} else {
s.twinkleFrame--;
s.o.style.visibility = (s.twinkleFrame && s.twinkleFrame%2===0?'hidden':'visible');
}
}
}
};

this.animate = function() {
// main animation loop
// move, check status, die etc.
s.move();
};

this.setVelocities = function() {
s.vX = vRndX+rnd(storm.vMaxX*0.12,0.1);
s.vY = vRndY+rnd(storm.vMaxY*0.12,0.1);
};

this.setOpacity = function(o,opacity) {
if (!opacitySupported) {
return false;
}
o.style.opacity = opacity;
};

this.melt = function() {
if (!storm.useMeltEffect || !s.melting) {
s.recycle();
} else {
if (s.meltFrame < s.meltFrameCount) {
s.meltFrame++;
s.setOpacity(s.o,s.meltFrames[s.meltFrame]);
s.o.style.fontSize = s.fontSize-(s.fontSize*(s.meltFrame/s.meltFrameCount))+'px';
s.o.style.lineHeight = storm.flakeHeight+2+(storm.flakeHeight*0.75*(s.meltFrame/s.meltFrameCount))+'px';
} else {
s.recycle();
}
}
};

this.recycle = function() {
s.o.style.display = 'none';
s.o.style.position = (fixedForEverything?'fixed':'absolute');
s.o.style.bottom = 'auto';
s.setVelocities();
s.vCheck();
s.meltFrame = 0;
s.melting = false;
s.setOpacity(s.o,1);
s.o.style.padding = '0px';
s.o.style.margin = '0px';
s.o.style.fontSize = s.fontSize+'px';
s.o.style.lineHeight = (storm.flakeHeight+2)+'px';
s.o.style.textAlign = 'center';
s.o.style.verticalAlign = 'baseline';
s.x = parseInt(rnd(screenX-storm.flakeWidth-20),10);
s.y = parseInt(rnd(screenY)*-1,10)-storm.flakeHeight;
s.refresh();
s.o.style.display = 'block';
s.active = 1;
};

this.recycle(); // set up x/y coords etc.
this.refresh();

};

this.snow = function() {
var active = 0;
var used = 0;
var waiting = 0;
var flake = null;
for (var i=s.flakes.length; i--;) {
if (s.flakes[i].active == 1) {
s.flakes[i].move();
active++;
} else if (s.flakes[i].active === 0) {
used++;
} else {
waiting++;
}
if (s.flakes[i].melting) {
s.flakes[i].melt();
}
}
if (active flake = s.flakes[parseInt(rnd(s.flakes.length),10)];
if (flake.active === 0) {
flake.melting = true;
}
}
};

this.mouseMove = function(e) {
if (!s.followMouse) {
return true;
}
var x = parseInt(e.clientX,10);
if (x windOffset = -windMultiplier+(x/screenX2*windMultiplier);
} else {
x -= screenX2;
windOffset = (x/screenX2)*windMultiplier;
}
};

this.createSnow = function(limit,allowInactive) {
for (var i=0; i s.flakes[s.flakes.length] = new s.SnowFlake(s,parseInt(rnd(flakeTypes),10));
if (allowInactive || i>s.flakesMaxActive) {
s.flakes[s.flakes.length-1].active = -1;
}
}
storm.targetElement.appendChild(docFrag);
};

this.timerInit = function() {
s.timers = (!isWin9X?[setInterval(s.snow,s.animationInterval)]:[setInterval(s.snow,s.animationInterval*3),setInterval(s.snow,s.animationInterval)]);
};

this.init = function() {
s.randomizeWind();
s.createSnow(s.flakesMax); // create initial batch
addEvent(window,'resize',s.resizeHandler);
addEvent(window,'scroll',s.scrollHandler);
if (!isOldIE) {
addEvent(window,'blur',s.freeze);
addEvent(window,'focus',s.resume);
}
s.resizeHandler();
s.scrollHandler();
if (s.followMouse) {
addEvent(document,'mousemove',s.mouseMove);
}
s.animationInterval = Math.max(20,s.animationInterval);
s.timerInit();
};

var didInit = false;

this.start = function(bFromOnLoad) {
if (!didInit) {
didInit = true;
} else if (bFromOnLoad) {
// already loaded and running
return true;
}
if (typeof s.targetElement == 'string') {
var targetID = s.targetElement;
s.targetElement = document.getElementById(targetID);
if (!s.targetElement) {
throw new Error('Snowstorm: Unable to get targetElement "'+targetID+'"');
}
}
if (!s.targetElement) {
s.targetElement = (!isIE?(document.documentElement?document.documentElement:document.body):document.body);
}
if (s.targetElement != document.documentElement && s.targetElement != document.body) {
s.resizeHandler = s.resizeHandlerAlt; // re-map handler to get element instead of screen dimensions
}
s.resizeHandler(); // get bounding box elements
s.usePositionFixed = (s.usePositionFixed && !noFixed); // whether or not position:fixed is supported
fixedForEverything = s.usePositionFixed;
if (screenX && screenY && !s.disabled) {
s.init();
s.active = true;
}
};

function doStart() {
s.start(true);
}

if (document.addEventListener) {
// safari 3.0.4 doesn't do DOMContentLoaded, maybe others - use a fallback to be safe.
document.addEventListener('DOMContentLoaded',doStart,false);
window.addEventListener('load',doStart,false);
} else {
addEvent(window,'load',doStart);
}

}

snowStorm = new SnowStorm();
Assume that we saved this code in a javascript file called snow.js....
Then import that file on your master page.
 <script type="text/javascript" src="snow.js"></script>

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 192.168.0.1 machine on port 808, then this settings will be
export http_proxy="http://192.168.0.1:808"

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@192.168.0.1:808, but it is only necessary to give http://192.168.0.1:808. 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="http://192.168.0.1:808" on ~/.bashrc file.
 vi ~/.bashrc

If you want to do it for current user, add export http_proxy="http://192.168.0.1:808" 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 log4j.properties file. In your IDE, as other property files add your log4j properties file. For example create new file called "log4j.properties" 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("log4j.properties");
properties.load(inputStream);
PropertyConfigurator.configure(properties);
logger.info("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.
Cheers......

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...............
Yaaahooooooooooooo..........
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.pub, 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@192.168.4.90:my_first_repo 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........???