July 06, 2009

CSS float for firefox and IE

Dom.styleFloat // for IE
Dom.cssFloat // for firefox

June 24, 2009

Set class path for java:

I almost forget how to run Java command outside Java's root folder, bin. Here are the steps to set class path for java.
=======================================
1./ Go into Advanced system settings in Control Panel/System
2./ Click on Environment Variables
3./ Click on New... to create "JAVA_HOME" with value "C:\Program Files (x86)\Java\jdk1.6.0_02"
4./ Edit "Path" with value "%JAVA_HOME%\BIN"
5./ Open your new CMD.

Note: Each value in "Path" is seperated by ";"

June 21, 2009

TileCache with Geoserver

When we use many layers in one map, we should better use Tilecache which stores all of those images in temporary in local computer, hence our map will load much faster than normal. Here are some ways to configure Tilecache.
=========================================
1./ you need to have Apache server installed and make sure your Geoserver is available.

2./ Define your temp folder to store those temporary images and your layers which is already generated from Geoserver in "tilecache.cfg"
//temp folder
[cache]
type=Disk
base= C:/temp/tilecache
// layer from Geoserver
[cambodia]
type=WMS
url=http://127.0.0.1:8080/geoserver/wms?transparent=true
extension=png
layers= mango:cam_DistrictCenter
srs= EPSG:41001
#metatile= yes
metaBuffer=10
metaSize=20,20

3./ Define tilecache folder in "httpd.conf"
<Directory C:\wamp\www\tilecache>
AddHandler cgi-script .cgi
Options +ExecCGI
</Directory>


Reference: Tilecache's docs

June 05, 2009

Artisteer

It is a cool program which helps you to design any website in a few minutes by some easy steps. I can only use Artisteer v2.1.0 since I haven't found the cracked for other versions yet. Artisteer supports either many technologies such as CodeCharge Studio4, WordPress(2.5-2.7), Joomla 1.5 and Drupal(5.x, 6.x) or Browsers like IE 6+, Firefox 2+, Opera 9+, Safari 1+ and Chrome 1+. You should watch it's demo then you will know how cool it is.

Here are some steps to use Artisteer v2.1.0 without trial version:
=========================================
1./ You must download Artisteer v2.1.0 by this url:
Artisteer v2.1.0 and install it.

2./ Download this video which tells you how to remove trial:
Untrial artisteer video

3./ Bat file is the key file to remove it's trial.

4./ Artisteer's doc

Note You may not be able to view Artisteer's doc directly on the internet but you can download and view it in your own PC.

May 27, 2009

Remote Desktop in Ubuntu

You will be able to remote other ubuntu desktop by this following command:

vinagre 192.168.0.174

May 18, 2009

Javascript Unique Item in Array

After we follow this code bellow, we'll get tempArr[] which store unique items.
Example: array[1,10,2,2,5,4,5,6,6,8,10,8] => array[1,2,4,5,6,10,8]
=========================================

function contains(a, e) {
for(j=0;j<a.length;j++)if(a[j]==e)return true;
return false;
}

if(!contains(tempArr, urlObj[i].group)){
tempArr.length +=1;
tempArr[tempArr.length-1] = urlObj[i].group;
}

May 09, 2009

Selenium

Selenium is a test tool that allows you to write automated web application UI tests in any programming language against any HTTP website using any mainstream JavaScript-enabled browser.
=========================================
1./ You need to have Ruby in your pc then install selenium by a command below.

sudo gem install Selenium

2./ cd to our JSSpec's path then run command below in order to access HTTP Server from that directory by default it's "http://localhost:8000"

python -m SimpleHTTPServer

3./ run you JSSpec file by putting it's name after the http's path above


Reference:
ChrisinCambo - jsspec_ci

April 27, 2009

GeoServer in Ubuntu

It's not difficult to setup Geoserver on your local Ubuntu by following these steps bellow:
=========================================

1./ install java
2./ download binary Geoserver then unzip it in usr/local

3./ edit file startup.sh:
#PATH=/usr/sbin:/usr/bin:/sbin:/bin;
#DESC="Description of the service";
#NAME="geoserver";
#SCRIPTNAME=/etc/init.d/$NAME;

JAVA_HOME="/usr/lib/jvm/java-6-sun";
#GEOSERVER_USER="geoserver";
#GEOSERVER_DATA_DIR="/usr/local/geoserver/data_dir";
GEOSERVER_HOME="/usr/local/geoserver";

4./ to change default port 8080 to other by :
edit file jetty.xml

April 21, 2009

Mercurial

It's the way to access mercurial by hg command.
=================================================
Clone from webserver to local-1
Clone from local-1 to local-2
After modifying local-2 then
"hg add filename/foldername"
"hg commit and write file"
Go back to local-1 then
"hg pull ../local-2"
"hg update"

Sprockets & JSDoc

Sprockets is the Ruby's method which is used to generate all associated namespaces into one file.
----------------------------------------------
1./ Install Ruby and then install Sprockets by this command "$ gem install --remote sprockets" after Ruby.
2./ Write comments in your file as Sprockets' format.

/**
* Dependencies - for Sprockets packaging
**/
//= require
//= require
//= require
//= require

3./ Run command sprocketize with it's options in order to get your binded file.
$ sprocketize method_injector.js > method_injector_spro.js

==============================================

JSDoc is a good way to write the project's documentations.
----------------------------------------------
1./ Install Java and download JSDoc toolkit into your computer.
2./ Write comments to describe your project as JSDoc's format.

/**
* Class that detects changes of a property on a source object then passes that new value to
a method on a target object
* @constructor
* @extends LL.AbstractNode
* @param {string} targetSetter The name of the method on the target objects
* @param {function} source Constructor of the object whose property we wish to observe
* @param {string} sourceKey The property we wish to observe on the source object
* @property {string} targetSetter The name of the method on the target objects
* @property {function} source Constructor of the object whose property we wish to observe
* @property {string} sourceKey The property we wish to observe on the source object
*/

3./ Run command bellow to generate your documentation as HTML file.

java -jar jsrun.jar app\run.js -a -t=templates\jsdoc mycode1.js mycode2.js mycode3.js

April 19, 2009

Javascript & Cookie

Here are the initial functions of Cookie in Javascript.
====================================================
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.valueOf() + (30*60*1000)); // next 30 mins
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}

function eraseCookie(name) {
createCookie(name,"",-1);
}

March 26, 2009

JSONP

JSONP:
//get Data cross domain
<img src="binary">
<Iframe src="HTML">
<script src="javascript">

March 25, 2009

Basic Ajax

//Ajax is possible to return responseXML(Content-type: text/xml), responseText(raw text)

//Any status in the 200 range is good
( xmlHttp.status >= 200 && xmlHttp.status < 300 ) ||
// Successful if the document has not been modified
xmlHttp.status == 304 ||


xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET","http://www.google.com",true);
xmlHttp.send(null);
xmlHttp.onreadystatechange = function(){
if ( xmlHttp.readyState == 4 ) {
document.getElementById('display').innerHTML=xmlHttp.responseText;
console.log(xmlHttp.getResponseHeader("content-type"));
console.log(xmlHttp.status)
}
};
--------------------------------------------
//Ajax with Timeout
var timeoutLength = 5000;
var requestDone = false;
setTimeout(function(){requestDone = true;}, timeoutLength);

xmlHttp.send(null);
xmlHttp.onreadystatechange = function(){
if ( xmlHttp.readyState == 4 && !requestDone ) {
document.getElementById('display').innerHTML=xmlHttp.responseText;
}
};

March 24, 2009

Javascript Image slideShow


//set div to display in the middle of the screen even it's scrolled

div.style.top = window.pageYOffset + (screen.height/2) - (parseInt(div.style.height)/2) + "px";
----------------------------------------
function windowHeight() {
var de = document.documentElement;
return self.innerHeight || ( de && de.clientHeight ) || document.body.clientHeight;
}
function windowWidth() {
var de = document.documentElement;
return self.innerWidth || ( de && de.clientWidth ) || document.body.clientWidth;
}

function getWidth( elem ) {
return parseInt( getStyle( elem, 'width' ) );
}

function getHeight( elem ) {
return parseInt( getStyle( elem, 'height' ) );
}

function pageHeight() {
return document.body.scrollHeight;
}

function pageWidth() {
return document.body.scrollWidth;
}

function scrollX() {
var de = document.documentElement;
return self.pageXOffset || ( de && de.scrollLeft ) || document.body.scrollLeft;
}

function scrollY() {
var de = document.documentElement;
return self.pageYOffset || ( de && de.scrollTop ) || document.body.scrollTop;
}

function setX(elem, pos) {
elem.style.left = pos + "px";
}

function setY(elem, pos) {
elem.style.top = pos + "px";
}

function addX(elem,pos) {
setX( posX(elem) + pos );
}

function addY(elem,pos) {
setY( posY(elem) + pos );
}

function hide( elem ) {
var curDisplay = getStyle( elem, 'display' );
if ( curDisplay != 'none' )
elem.$oldDisplay = curDisplay;
elem.style.display = 'none';
}

function show( elem ) {
elem.style.display = elem.$oldDisplay || '';
}

function hideOverlay() {
curImage = null;
hide( document.getElementById("overlay") );
hide( document.getElementById("gallery") );
}

function showOverlay() {
var over = document.getElementById("overlay");
over.style.height = pageHeight() + "px";
over.style.width = pageWidth() + "px";
fadeIn( over, 50, 10 );
}
//--------------------------------------------------------------
function showImage(cur) {
curImage = cur;
var img = document.getElementById("gallery_image");
if ( img.firstChild )
img.removeChild( img.firstChild );
img.appendChild( cur.firstChild.cloneNode( true ) );
//id("gallery_title").innerHTML = cur.firstChild.firstChild.alt;
var gallery = document.getElementById("gallery");
gallery.className = cur.className;
fadeIn( gallery, 100, 10 );
adjust();
}
function adjust(){
var obj = document.getElementById("gallery");
if ( !obj ) return;
var w = getWidth( obj );
var h = getHeight( obj );
var t = scrollY() + ( windowHeight() / 2 ) - ( h / 2 );
if ( t < 0 ) t = 0;
var l = scrollX() + ( windowWidth() / 2 ) - ( w / 2 );
if ( l < 0 ) l = 0;
setY( obj, t );
setX( obj, l );
};

function prevImage() {
showImage( prev( curImage ) );
return false;
}

function nextImage() {
showImage( next( curImage ) );
return false;
}

function startShow(obj) {
var elem = obj.getElementsByTagName('li');
var gallery = document.getElementById("gallery");
for ( var i = 0; i < elem.length; i++ ) new function() {
var cur = elem[i];
setTimeout(function(){
showImage( cur );
setTimeout(function(){
fadeOut( gallery, 0, 10 );
}, 3500 );
}, i * 5000 );
};
setTimeout( hideOverlay, 5000 * elem.length );
showOverlay();
}

March 23, 2009

Javascript feature functions & properties


//Browser size:
document.body.scrollHeight;
document.body.scrollWidth;
----------------------------------------------------------
// get Left and Top of an element:
e = e || window.event;
return e.pageX || e.clientX + document.body.scrollLeft;
return e.pageY || e.clientY + document.body.scrollTop;
----------------------------------------------------------
function hide( elem ) {
var curDisplay = getStyle( elem, 'display' );
if ( curDisplay != 'none' )
elem.$oldDisplay = curDisplay;
elem.style.display = 'none';
}
function show( elem ) {
elem.style.display = elem.$oldDisplay || '';
}
----------------------------------------------------------
// Slide Element down
function slideDown(elem){
elem.style.height = '0px';
elem.style.display = 'block';
var h = document.body.scrollHeight;
for ( var i = 0; i <= 100; i += 5 ) {
(function(){
var pos = i;
setTimeout(function(){
elem.style.height = (( pos / 100 ) * h ) + "px";
},( pos + 1 ) * 10 );
})();
}
}
----------------------------------------------------------
function setOpacity( elem, level ) {
if ( elem.filters )
elem.style.filters = 'alpha(opacity=' + level + ')';
else
elem.style.opacity = level / 200;
}

function fadeIn( elem ) {
setOpacity( elem,0);
// elem.style.display = elem.$oldDisplay || '';
elem.style.display = "block";
for ( var i = 0; i <= 100; i += 5 ) {
(function(){
var pos = i ;
setTimeout(function(){
setOpacity( elem, pos );
}, ( pos + 1 ) * 10 );
})();
}
}

function fadeOut( elem ) {
var j = 0;
for ( var i = 100; i > 0; i -= 5 ) {
j +=5;
(function(){
var pos = i ;
setTimeout(function(){
setOpacity( elem, pos);
if(pos <= 5){
elem.style.display = "none";
}
}, (j+1) * 5);
})();
}
}

March 18, 2009

Javascript Validation expression


Validate an Email address:
/^https?:\/\/([a-z0-9-]+\.)+[a-z0-9]{2,4}.*$/.test("http://www.google.com")

Validate a URL:
/^[a-z0-9_+.-]+\@([a-z0-9-]+\.)+[a-z0-9]{2,4}$/i.test('abc@yahoo.com')

Validate a phone number:
/(\d{3}).*(\d{3}).*(\d{4})/.exec('1232344567') => 1232344567 123 234 4567

Validate a date:
/^\d{2}\/\d{2}\/\d{2,4}$/.test('12/32/1231')

//Change these 4 condition into JSON object
--------------------------------------------------------------------

var errMsg = {
required: {
msg: "This field is required.",
test: function(obj,load) {
return obj.value.length > 0 || load || obj.value == obj.defaultValue;
}
},
email: {
msg: "Not a valid email address.",
test: function(obj) {
return !obj.value ||
/^[a-z0-9_+.-]+\@([a-z0-9-]+\.)+[a-z0-9]{2,4}$/i.test( obj.value );
}
},
phone: {
msg: "Not a valid phone number.",
test: function(obj) {
var m = /(\d{3}).*(\d{3}).*(\d{4})/.exec( obj.value );
if ( m ) obj.value = "(" + m[1] + ") " + m[2] + "-" + m[3];
return !obj.value || m;
}
},
date: {
msg: "Not a valid date.",
test: function(obj) {
return !obj.value || /^\d{2}\/\d{2}\/\d{2,4}$/.test(obj.value);
}
},
url: {
msg: "Not a valid URL.",
test: function(obj) {
return !obj.value || obj.value == 'http://' ||
/^https?:\/\/([a-z0-9-]+\.)+[a-z0-9]{2,4}.*$/.test( obj.value );
}}};

errMsg['email'].test('234@yahoo.com');

/*for(name in errMsg){
console.log(name);
for(tempname in errMsg[name]){
console.log(tempname);
}
}*/

March 12, 2009

get any style attributes from your element


//elem = element( document.getElementsByTagName("font")[0].childNodes[2]), name = name of style's attribute( height, width)
function getStyle( elem, name ) {
if (elem.style[name])
return elem.style[name];
else if (elem.currentStyle)
return elem.currentStyle[name];
else if (document.defaultView && document.defaultView.getComputedStyle) {
name = name.replace(/([A-Z])/g,"-$1");
name = name.toLowerCase();
var s = document.defaultView.getComputedStyle(elem,"");
return s && s.getPropertyValue(name);

} else
return null;
}

To apply stylesheet when Javascript is not enabled

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<!--The instant the script is run, a new class is attached to the <html> element
giving us the ability to know if JavaScript is enabled, or not.-->
<script>document.documentElement.className = "js";</script>
<!--If JavaScript is enabled, hide the block of text,
which we will fade in later.-->
<style>.js #fadein { display: none }</style>
</head>
<body>
<div id="fadein">Block of stuff to fade in...</div>
</body>
</html>

March 11, 2009

Stop Default Browser Action

A Generic Function for Preventing the Default Browser Action from Occurring
================================================================

function stopDefault( e ) {
// Prevent the default browser action (W3C)
if ( e && e.preventDefault )
e.preventDefault();
// A shortcut for stoping the browser action in IE
else
window.event.returnValue = false;
return false;
}

Capturing and Bubbling in Javascript

Normally in Javascript, whenever you apply stylesheet to any parents which containe many elements, those stylesheets will effect to all elements and their parents but we can use stopBubble() to prevent this problem.
================================================================
function stopBubble(e) {
if ( e && e.stopPropagation )
e.stopPropagation();
else
window.event.cancelBubble = true;
}
-----------------------------------------------------------------
Using stopBubble() to Create an Interactive Set of Elements
var all = document.getElementsByTagName("*");
for ( var i = 0; i < all.length; i++ ) {
all[i].onmouseover = function(e) {
this.style.border = "1px solid red";
stopBubble( e );
};
all[i].onmouseout = function(e) {
this.style.border = "0px";
stopBubble( e );
};
}

March 10, 2009

My first javascript with DOM

parentNode, childNodes, nodeValue, nodeName, nodeType, firstChild, lastChild, nextChild, previousSibling, nextSibling
- nodeType (Element = 1, Attribute = 2, Text = 3, Comment = 8, Document = 9)
-----------------------------------------------------------
createElement, insertBefore, appendChild, removeChild, getAttribute, setAttribute
===========================================================

for(var i = 0; i < center.length; i++){
console.log(center[i].nodeName);
var child_node = center[i].childNodes;
//console.log(center[i].innerHTML);
for(var j = 0; j < child_node.length; j++){
//console.log(child_node[j].nodeName);
if(child_node[j].nodeName =='A'){
console.log(child_node[j].innerHTML);
console.log(child_node[j].getAttribute('href'));
}
}
}
-----------------------------------------------------------
var temp = document.getElementsByTagName("font");
var element = document.createElement('<a>');
element.innerHTML="samneang";
element.setAttribute('href','http://samneang-ngeth.blogspot.com');
temp[0].appendChild(element);
temp[0].removeChild(temp[0].lastChild);

February 26, 2009

The addEvent/removeEvent Library Written by Dean Edwards

I think, these are the good functions which I don't want to write more code by myself.
======================================================================

function addEvent(element, type, handler) {
if (!handler.$$guid) handler.$$guid = addEvent.guid++;
if (!element.events) element.events = {};
var handlers = element.events[type];
if (!handlers) {
handlers = element.events[type] = {};
if (element["on" + type]) {
handlers[0] = element["on" + type];
}
}
handlers[handler.$$guid] = handler;
element["on" + type] = handleEvent;
};
addEvent.guid = 1;
function removeEvent(element, type, handler) {
if (element.events && element.events[type]) {
delete element.events[type][handler.$$guid];
}
};
function handleEvent(event) {
var returnValue = true;
event = event || fixEvent(window.event);
var handlers = this.events[event.type];
for (var i in handlers) {
this.$$handleEvent = handlers[i];
if (this.$$handleEvent(event) === false) {
returnValue = false;
}
}
return returnValue;
};
function fixEvent(event) {
event.preventDefault = fixEvent.preventDefault;
event.stopPropagation = fixEvent.stopPropagation;
return event;
};
fixEvent.preventDefault = function() {
this.returnValue = false;
};
fixEvent.stopPropagation = function() {
this.cancelBubble = true;
};

Flyweight pattern and Pacade pattern

here are the new two interesting patterns which I learned from many team members.
===============================================================

Flyweight patter is a pattern which is used to make the memory low usage by catching many the same objects in one location and take them to use in many different location or apply their style in different style. as similar as word processor that we store only characters those characters' style are apply in different way.

Pacade pattern is the common pattern which is very useful while we have many complex class that contain a lot of subsystems inside. Pacade is an interface that store or catch only the needed subsystems and apply them to all client to use.

Javascript preventDefault

It's quite strange for me to start with Javascript. But there are many interesting things inside it. such as this preventDefault I found it in Event chapter of John Resig Pro javascript
=================================================================

function preventDef(event) {
event.preventDefault();
}

function addHandler() {
document.getElementById("checkbox").addEventListener("click",
preventDef, false);
}

function removeHandler() {
document.getElementById("checkbox").removeEventListener("click",
preventDef, false);
}

function simulateClick() {
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent("click", true, true, window,
0, 0, 0, 0, 0, false, false, false, false, 0, null);
var cb = document.getElementById("checkbox");
var canceled = !cb.dispatchEvent(evt);
if(canceled) {
// A handler called preventDefault
alert("canceled");
} else {
// None of the handlers called preventDefault
alert("not canceled");
}
}

February 17, 2009

State pattern and Visitor pattern

It's and appropriate of time that I can join the Yoolk team. I've learned a lot of new things.
============================================================================
State pattern is mostly used in State machine. It has all of methods in itself to calculation in everything. as an example, if you have some methods such as, Add, delete, Update and Save. you will write all of these operations. Like when will you allow to press button after this button you will move to another button, so If you have many of these operation in your project you should better write these operation in State pattern by writing only one time and use it in many places.

Visitor pattern is the pattern that we don't want to change anything in the existing class. we just derive it and override some method over the main class. As example, we have employee department and have many levels of employee in it, so if we want to increase their salary we just write another method to the new object and update all of their salary by their own different level.

February 10, 2009

Momento and Prototype pattern

I don't know much about design pattern but it's quite great that I've been joined with Mylab team.
================================================

Memento pattern is the way which we use to store our object as temporary in order to undo or redo by the parent object only.

Prototype pattern is the clone object method which is used to copy only the value of each object it's the same as deep copy but different to shallow copy which is used to copy as reference.

January 21, 2009

Rich Textbox control

It's a cool control which we can use as our content editor.
We have some sample as ASP, PHP or HTML for you.
=====================================================
FreeRTE_v1 download

January 18, 2009

Javascript function: window.open

Mostly I forget this syntax because of the property here is too long for me to remember
====================================================
window.open('yourpage.html','','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, width=600, height=600, left=200, top=200');

January 14, 2009

encodeURIComponent

It's a javascript function which is used to encodes a string as a component of a URI.
=================================================

<script type="text/javascript">
document.write(encodeURIComponent(",/?:@&=+$#"));
</script>
--------------------
%2C%2F%3F%3A%40%26%3D%2B%24%23

December 15, 2008

PHP resize image

Here is the function which you can resize your image by call it like this:
<img src="resize_pic.php?name='.$photo.'&width=500&height=500" border="0" />
===========================================
resize_pic.php
-------------------------------------------
function Resize($Dir,$Image,$MaxWidth,$MaxHeight) {
list($ImageWidth,$ImageHeight,$TypeCode)=getimagesize($Dir.$Image);
$ImageType=($TypeCode==1?"gif":($TypeCode==2?"jpeg":($TypeCode==3?"png":FALSE)));
$CreateFunction="imagecreatefrom".$ImageType;
$OutputFunction="image".$ImageType;
if ($ImageType) {
$RatioHeight=($ImageHeight/$ImageWidth);
$RatioWidth=($ImageWidth/$ImageHeight);
$ImageSource=$CreateFunction($Dir.$Image);
if ($ImageWidth > $MaxWidth || $ImageHeight > $MaxHeight) {
if ( $MaxWidth <= $ImageWidth && $ImageWidth >= $ImageHeight) {
$ResizedWidth = $MaxWidth;
$ResizedHeight = $ResizedWidth*$RatioHeight;
}else if ( $MaxHeight <= $ImageHeight && $ImageHeight >= $ImageWidth) {
$ResizedHeight = $MaxHeight;
$ResizedWidth = $ResizedHeight*$RatioWidth;
}else{
$ResizedWidth = $ImageWidth;
$ResizedHeight = $ImageHeight;
}
$ResizedImage=imagecreatetruecolor($ResizedWidth,$ResizedHeight);
imagecopyresampled($ResizedImage,$ImageSource,0,0,0,0,$ResizedWidth,$ResizedHeight,$ImageWidth,$ImageHeight);
}else {
$ResizedWidth=$ImageWidth;
$ResizedHeight=$ImageHeight;
$ResizedImage=$ImageSource;
}
$OutputFunction($ResizedImage);
return true;
}else
return false;
}

$name = $_GET["name"];
$width = $_GET["width"];
$height = $_GET["height"];
$dir = "images/image_for_estate/";
Resize($dir,$name,$width,$height);

November 17, 2008

Failed to access IIS metabase.

This error typically occurs when you install IIS after you have asp.net installed. It is a very simple fix.

Copy and paste this into the Run Command from the Start Menu.
%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -i

Failed to access IIS metabase.

This error typically occurs when you install IIS after you have asp.net installed. It is a very simple fix.

Copy and paste this into the Run Command from the Start Menu.
%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -i

November 02, 2008

Transfer PHP to XML

This function below is used to transfer the select statement of Mysql into XML file.
================================
function tbl_xml($sql,$tbl_name){
$ds =mysql_query($sql);
if(!$ds){
die("mysql error ". mysql_error());
}
//xml declaration
$dom= new DOMDocument("1.0");
$xml_root=$dom->appendChild($dom->createElement("$tbl_name"));
$n_row=0;
while($row=mysql_fetch_array($ds)){
$n_field=0;
$fieldname=$xml_root->appendChild($dom->createElement("field"));
while($n_field<mysql_num_fields($ds)){
$field=mysql_fetch_field($ds,$n_field);
//$fieldname->appendChild($dom->createTextNode($row[$field->name]));
$fieldname->setAttribute($field->name,$row[$field->name]);
$n_field++;
}
$n_row++;
}
$dom->formatOutput=true;
$dom->save("$tbl_name.xml");
}

October 23, 2008

PHP configuration

There is a problem when we use imagettftext() in php and we can solve it by take off the comment before this following phrase. (php.ini)
==============================
extension=php_gd2.dll


Another common problem is happened when we use the short tag and we should change the value of this following phrase from "off" to "on".(php.ini)
==============================
short_open_tag = on

The following solution is for any variable that you want to use without $_POST OR $_GET.(php.ini)
==============================
register_globals=On

The following solution is for solving the error of DB connection.(php.ini)
==============================
error_reporting = E_ERROR & ~E_NOTICE & ~E_STRICT

This one is used to allow other machine to browse our local file. (httpd.conf)
==============================
Allow from all

October 12, 2008


var s = 3;
alert(s);
<h1>

jkjk

October 03, 2008

Install Ruby on Rails in Ubuntu

Step 1: Install Ruby from apt-get.
~$ sudo apt-get install ruby irb ri rdoc ruby1.8-dev libzlib-ruby libyaml-ruby libreadline-ruby libncurses-ruby libcurses-ruby libruby libruby-extras libfcgi-ruby1.8 build-essential libopenssl-ruby libdbm-ruby libdbi-ruby libdbd-sqlite3-ruby sqlite3 libsqlite3-dev libsqlite3-ruby libxml-ruby libxml2-dev

Step 2: Download and install RubyGems
Just download and extract the latest Gem and run following command.
~$ sudo ruby setup.rb

After successful installation, run this to create the link in /usr/bin
~$ sudo ln -s /usr/bin/gem1.8 /usr/bin/gem

Step 3: Install Rails and Gems
~$ sudo gem install rails
~$ sudo gem install sqlite3-ruby mongrel capistrano


Since I don’t use MySQL anymore, it’s really optional. It’s basically same as before, just make sure you are using following command to get everything you need for MySQL.
~$ sudo apt-get install mysql-server mysql-client libdbd-mysql-ruby libmysqlclient15-dev

September 18, 2008

PHP send mail

Here is the function which you can send Email to any account by your gmail account
==============================
function sendmail(){
require_once("class/class.phpgmailer.php");
$mail = new PHPGMailer();
$mail->Username = "your name";
$mail->Password = "your gmail's password";
$mail->From = "your gmail's account(full)";
$mail->FromName = 'your display name';
$mail->Subject = 'your subject';
$mail->AddAddress("destination address");
$mail->Body =trim("your content");
$mail->Send();
return "mail was sent";
}

------------------------------------
you must include 3 classes in this file below:
http://www.esnips.com/doc/d7cbc4df-104a-4db6-9e4a-e46939326160/PHP-send-mail

September 09, 2008

Ajax for getting RSS from other sites

Here are the functions which you can request the RSS Hot News from Yahoo, Google, Hotmail, Craigslist, BBC and CNN and display them in your page.
==========================================
--------------------First step------------------------

//Here are the function that I use to display RSS.
var xmlHttp
function showRSS(str) {
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null) {
alert ("Browser does not support HTTP Request")
return }
var url="getrss.php"
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function stateChanged() {
if (xmlHttp.readyState==1){
document.getElementById("rssOutput").innerHTML="Loading..."
}else if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
document.getElementById("rssOutput").innerHTML=xmlHttp.responseText
}}
function GetXmlHttpObject(){
var xmlHttp=null;
try {
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}catch (e) {
// Internet Explorer
try {
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } }
return xmlHttp;}

--------------------Second step------------------------

//here is the php script which I use to get the RSS.
$q=$_GET["q"];//find out which feed was selected
if($q=="2") {
$xml=("http://news.google.com/news?ned=us&topic=h&output=rss");
}elseif($q=="3") {
$xml=("http://rss.msnbc.msn.com/id/3032091/device/rss/rss.xml");
}elseif($q=="1"){
$xml=("http://rss.news.yahoo.com/rss/topstories");
}elseif($q=="4"){
$xml=("http://webns.net/mvcb/");
//$xml=("http://newyork.craigslist.org/ccc/index.rss");
}elseif($q=="5_1"){
$xml=("http://rss.cnn.com/rss/cnn_topstories.rss");
}elseif($q=="5_2"){
$xml=("http://rss.cnn.com/rss/cnn_latest.rss");
}elseif($q=="6"){
$xml=("http://newsrss.bbc.co.uk/rss/newsonline_world_edition/front_page/rss.xml");}

$xmlDoc = new DOMDocument();
$xmlDoc->load($xml);//get elements from ""
$channel=$xmlDoc->getElementsByTagName('channel')->item(0);
if($q!="4"){
$channel_title = $channel->getElementsByTagName('title')->item(0)->childNodes->item(0)->nodeValue;
$channel_link = $channel->getElementsByTagName('link')->item(0)->childNodes->item(0)->nodeValue;
}
$channel_desc = $channel->getElementsByTagName('description')->item(0)->childNodes->item(0)->nodeValue;//output elements from ""
echo("<p><a href= $channel_link>$channel_title</a>");
echo("
");
echo($channel_desc . "

");//get and output "" elements
$x=$xmlDoc->getElementsByTagName('item');
for ($i=0; $i<=9; $i++) {
$item_title=$x->item($i)->getElementsByTagName('title') ->item(0)->childNodes->item(0)->nodeValue;
$item_link=$x->item($i)->getElementsByTagName('link') ->item(0)->childNodes->item(0)->nodeValue;
if($q!="4"){
$item_desc=$x->item($i)->getElementsByTagName('description') ->item(0)->childNodes->item(0)->nodeValue;
}
echo ("<p><a href=$item_link>$item_title</a>");
echo ("
");
echo ($item_desc . "

");
}

September 08, 2008

Ajax request

Here is the function which you can use to execute the server script without refreshing the page.
===================================================

function Ajaxrequest(){
var xmlHttp;
try
{ // Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest(); }
catch (e)
{ // Internet Explorer
try
{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
catch (e)
{ try
{ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
catch (e)
{ alert("Your browser does not support AJAX!");
return false; } } }
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==1){
document.getElementById('display').innerHTML="Loading...!";
}
if(xmlHttp.readyState==4)
{
document.getElementById('display').innerHTML=xmlHttp.responseText;
}
}
//alert(page);
xmlHttp.open("GET","URL",true);
xmlHttp.send(null);
}

September 07, 2008

php paging

Here is the function which you can paging your data to next or previous
==========================================

//$page is refer to the page which you will link to.
//$startnum is refer to the startnumber in limit
//$numrow is refer to the number of record in limit
//$maxrow is the count number of your data
function paging($page,$startnum,$numrow,$maxrow){
if($startnum<=0){
$btnprevious="Previous";
}else{
$btnprevious="<a href=$page?startnum=$startnum-$numrow>Previous</a>";
}
if($startnum+$numrow < $maxrow){
$btnnext="<a href=$page?$startnum+$numrow>Next</a>";
}else{
$btnnext="Next";
}
return $btnprevious."  ".$btnnext;
}

September 04, 2008

php file system

Here is the function which is used to delete a folder and all sub folders and files in it.
=======================================

function removeallfile($dirname){
if (is_dir($dirname))
$dir_handle = opendir($dirname);
if (!$dir_handle)
return false;
while($file = readdir($dir_handle)) {
if ($file != "." && $file != "..") {
if (!is_dir($dirname."/".$file))
unlink($dirname."/".$file);
}
}
closedir($dir_handle);
return true;
}


Here is the function which is used for copy all files from 1 folder to another folder
=======================================

function copydir($dirname1,$dirname2)
{
if (is_dir($dirname1))
$dir_handle = opendir($dirname1);
if (!$dir_handle)
return false;
while($file = readdir($dir_handle)) {
if ($file != "." && $file != "..") {
if (!is_dir($dirname1."/".$file))
$tempfile=fopen($dirname2."/".$file,"w+");
copy($dirname1."/".$file,$dirname2."/".$file);
//unlink($dirname1."/".$file);
}
}
closedir($dir_handle);
return true;
}


Here are the files which contain upload file function and you can upload your file by using these files.
=======================================
1./ http://www.esnips.com/doc/1bc71467-47d8-4085-9afd-d2073c725513/upload
2./ http://www.esnips.com/doc/33d8a913-5bc7-498b-9c26-74f59af4dc07/upload-file