Saturday, July 30, 2011

php possible datetime gotcha

Initially, i thought it was a bug in php...
but i think thats how its suppose to work.

If any month with 31days, and the last month has less days than current date,
the strtotime("-1 month", mktime())
will return this month date, instead of last month.

Example: strtotime("-1 month", strtotime("2011-07-01"))
results: time of 2011-06-01.
But,
Example: strtotime("-1 month", strtotime("2011-07-31"))
results: time of 2011-07-01.

This is because minus 1 month of 2011-07-31 in math => 2011-06-31,
which results to 2011-07-01 due to no 31 days in june.


Wednesday, July 27, 2011

Concurrency / Que with clustering

I realize a lot of people depends on existing framework or infrastructure to achieve concurrency or Que system to achieve what they need.
Basically if one need to get multiple server to be synced for write, and read, its possible to do it manually by coding it with combination of python or php scripts to connect between nodes...

But faster way to achieve so is by using open source combination such as zookerper with cassandra and cage.

But Case have issue when you are using more than 3 nodes.
This issue with zookeeper having to sync all the nodes together to have the transaction to run.
But after reading an article, its nice to have 2 or 3 nodes for transaction of 1 group of zookeeper process and separated zookeeper for read process. But do we need zookeeper for all nodes?
I think its better to have cassandra to sync those data to those server passively instead...
Only maintain between 2-3 nodes for transaction update to ensure uptime.

Monday, July 4, 2011

jQuery 1.6 buggy on IE 7

Ive been trying to figure out why my jquery colorbox seems to make ie 7 browser to hang,
and then i realize it wasnt colorbox issue, but jquery 1.6.
jQuery 1.6.1 seems to have fixed it... luckily :)

Thursday, June 30, 2011

PHP regex to match any link on text

//1st match subdomain: xyz. OR
// next, match domain
// then match .
// then match dual extension: .com or .org or ...and .sg OR
// then match single extension: TLD: .com or .org or .net or .... OR
// then match single country name .us
// then match uri, example: /xxx
// also try to match ending /
// and also try to match with ending name /xxx/lastnamehere
$sSubDomainSet = "[^.,\:\+\s]*\."; // xyz.
$sPatSubDomain = "(" . $sSubDomainSet . ")*";
$sPatCountryDomain = "((com|org|net|name|mil|gov|co|info)\.[a-z]{2})";
$sPatTLD = "(com|org|net|name|mil|gov|info)"; //top level domain tld
$sPatCountryTLD = "([a-z]{2})";
$sURIChar = "[a-z0-9\.\?\=\&\(\&amp\;)\-\_\+\%]";
$sPatURI = "([\/]*" . $sURIChar . "*)?";
$sPatURISlash = "([\/])?";
$sPatLastName = "(" . $sURIChar . "*)";
//match last uri name, example domain.com/email/xxx (match xxx)
$sPattern = "/(" . "((http:\/\/)|(https:\/\/))?" . $sPatSubDomain . $sSubDomainSet .
"(" . $sPatCountryDomain . "|" . $sPatTLD . "|" . $sPatCountryTLD . ")" .
$sPatURI . $sPatURISlash . $sPatLastName .
")/is";
preg_match_all($sPattern, $sContent, $matches, PREG_PATTERN_ORDER);
if (count($matches[1]) > 0) {
$sResult = $matches[1][0];//match first title tag
}

Example Results:
Original: this is a link https://www.yahoo.com/, result: https://www.yahoo.com/
Original: this is a link https://yahoo.com, result: https://yahoo.com
Original: this is a link http://yahoo.com, result: http://yahoo.com
Original: this is a link www.yahoo.com, result: www.yahoo.com
Original: this is a link yahoo.com, result: yahoo.com
Original: this is a link www.yahoo.org, result: www.yahoo.org
Original: this is a link www.whitehouse.gov, result: www.whitehouse.gov
Original: this is a link www.whitehouse.mil, result: www.whitehouse.mil
Original: this is a link www.yahoo.net, result: www.yahoo.net
Original: this is a link yahoo.com.my, result: yahoo.com.my
Original: this is a link yahoo.org.my, result: yahoo.org.my
Original: this is a link yahoo.co.sg, result: yahoo.co.sg
Original: this is a link yahoo.co, result: yahoo.co
Original: this is a link yahoo.my, result: yahoo.my
Original: this is a link yahoo.us, result: yahoo.us
Original: this is a link xyz.123.www.yahoo.com, result: xyz.123.www.yahoo.com
Original: this is a link yahoo.com/news is this right?, result: yahoo.com/news
Original: this is a link yahoo.com/ i think so, result: yahoo.com/
Original: this is a link yahoo.com/aboutus.php, result: yahoo.com/aboutus.php
Original: this is a link yahoo.com/email/ maybe its right, result: yahoo.com/email/
Original: this is a link yahoo.com/email/compose,gotta love it, result: yahoo.com/email/compose
Original: this is a link yahoo.COM/email/compose.html?search=233 haha, result: yahoo.COM/email/compose.html?search=233
Original: this is a link yahoo.com/email/compose.html?search=233&xx=22 haha, result: yahoo.com/email/compose.html?search=233&xx=22
Original: this is a link yahoo.com/email/compose.html?search=233&uu=232 hehe, result: yahoo.com/email/compose.html?search=233&uu=232
Original: this is a link yahoo.com/email/compose.html?search=233&xx=2?ehh, result: yahoo.com/email/compose.html?search=233&xx=2?ehh
Original: this is a link yahoo.com/email/com-pose.html, result: yahoo.com/email/com-pose.html
Original: this is a link yahoo.com/email/com-pose_.html?a=1, result: yahoo.com/email/com-pose_.html?a=1
Original: this is a link yahoo.com/email/com+20%pose.html?a=1, result: yahoo.com/email/com+20%pose.html?a=1


p/s: yes i know the line with double ? is incorrect, im lazy to write it :)

Full pattern string:
/(((http:\/\/)|(https:\/\/))?([^.,\:\+\s]*\.)*[^.,\:\+\s]*\.(((com|org|net|name|mil|gov|co|info)\.[a-z]{2})|(com|org|net|name|mil|gov|info)|([a-z]{2}))([\/]*[a-z0-9\.\?\=\&\(\&amp\;)\-\_\+\%]*)?([\/])?([a-z0-9\.\?\=\&\(\&amp\;)\-\_\+\%]*))/is

updated aug 28, avoid +,: in name, added http and https support

Wednesday, June 8, 2011

Ubuntu 11.04 / Mint 11 black screen or blank screen?

It caught me by surprise when i used the nvidia driver with 3d experimental driver.
The problem lies on 2 issue:
1. new kernel mode auto enable high resolution via vga=758, which isnt supported on my asus laptop
2. the xwindows nvidia experimental driver didnt work.
So i got a black screen (not even backlight).

to fix it....
@ the grup screen, key edit (e) to edit on recovery mode
go to the line /boot linux ... (add "nomodeset" at the end)

This shall disable high resolution screen for boot up kernel.
in recovery mode, you may reconfigure your graphic to basic graphic,
then relaunch x windows. Inside there, click on additional driver, and disable the experimental driver.
Finally, reboot ;)

Wednesday, May 25, 2011

MODx Revo TinyMCE font color, table button

Default MODx Revolution TinyMCE doesnt contain font colour or table button.
To add font color, go to system : system setting
search for filter: "tiny"
add "forecolor" into tiny.custom_buttons# key.
add "table" into tiny.custom_buttons# key.

then add "table" into tiny.custom_plugins

This shall do a quick fix to have the things you need.
But do look for tiny.css_selectors to do a proper font face and size via classes.

For other buttons and plugins:

Monday, May 23, 2011

dhtmlx combo forceselection

Hi found a way to hack on dhtmlx combo to allow forceselection.
just add this code after dhtmlxcombo.js

dhtmlXCombo.prototype._confirmSelection = function(data,status){
if(arguments.length==0){
var z=this.getOptionByLabel(this.DOMelem_input.value);
//data = z?z.value:this.DOMelem_input.value;
data = z?z.value:null;
status = (z==null);
if (data==this.getActualValue()) return;
};
this.DOMelem_hidden_input.value=data;
this.DOMelem_hidden_input2.value = (status?"true":"false");
this.callEvent("onChange",[]);
this._activeMode=false;
}