Wednesday, December 23, 2009

Javascript textfield counter

maxL = 1000;
var bName = navigator.appName;

function taLimit(taObj) {
if (taObj.value.length == maxL) {
return false;
}
return true;
}

function taCount(taObj,Cnt) {
objCnt=createObject(Cnt);
objVal=taObj.value;
if (objVal.length > maxL) {
alert("Description field has to be less than 1000 characters.");
objVal = objVal.substring(0, maxL);
}

if (objCnt) {
if(bName == "Netscape"){
objCnt.textContent=maxL-objVal.length;}
else{objCnt.innerText=maxL-objVal.length;}
}
return true;
}
function createObject(objId) {
if (document.getElementById) return document.getElementById(objId);
else if (document.layers) return eval("document." + objId);
else if (document.all) return eval("document.all." + objId);
else return eval("document." + objId);
}


To update the counter at last, do something like this:
<script type="text/javascript">
taCount(document.getElementById('txtDescription'), 'myCounter');
</script>

Monday, December 21, 2009

PHP Date Convert

echo date("d/m/y", strtotime($row_sprees['issueDate'])); ?>

Monday, December 14, 2009

mySQL and msSQL Limit and TOP

SELECT TOP 10 * FROM stuff;

Will return the top ten rows, effectively doing the same thing as

SELET * FROM stuff LIMIT 10;

Saturday, December 12, 2009

Router configuration

Home network setup:
WRT300N - the router at level 1
WRT54G - the router at level 2 flashed with DD-WRT firmware, used as repeater.

The information to access the router are as follows:
level1: 192.168.1.1 (admin, admin)
Level2: 10.0.0.1 (root, admin)

Tuesday, December 8, 2009

convert url to links in C# using Regex

public string ConvertUrlsToLinks(string msg)
{
string newMsg = "";

string regex = @"((www\.|(http|https|ftp|news|file)+\:\/\/)[_.a-z0-9-]+\.[a-z0-9\/_:@=.+?,##%&~-]*[^.|\'|\# |!|\(|?|,| |>|<|;|\)])";
Regex r = new Regex(regex, RegexOptions.IgnoreCase);
newMsg = r.Replace(msg, "$1").Replace("href=\"www", "href=\"http://www");

string emailRegex = @"(([a-zA-Z0-9_\-\.]+@)[_.a-z0-9-]+\.[a-z0-9\/_:@=.+?,##%&~-]*[^.|\'|\# |!|\(|?|,| |>|<|;|\)])";
Regex r2 = new Regex(emailRegex, RegexOptions.IgnoreCase);
newMsg = r2.Replace(newMsg, "$1");

return newMsg;
}

Monday, December 7, 2009

Java Exam Prep

int count = 0;
System.out.println(count++);
System.out.println(count++);
output: 0, 1

int count = 0;
System.out.println(++count);
System.out.println(++count);
output: 1, 2

int count = 0;
System.out.println(count++);
System.out.println(++count);
output: 0, 2

Wednesday, December 2, 2009