Saturday, December 31, 2011

MODx page not found on manager

This was a real trouble for me in the first place.
How am i suppose to fix this...
First, i did the throw exception as stated in my last post.

then next thing i know, i realize the $modx->config["modRequest.class"] wasn't declared...
so it uses modRequest instead of modManagerRequest class.

after digging for hours, ive finally noticed that the $modx->context->prepare() doesnt seems to return
proper config in $modx->context->config;

to fix it, add in true  into the parameter:
$modx->context->prepare(true);
then, load the manager page. you should be able to see the manager page now.
next, remove the true (restore the code to its previous state).
then login into the manager.
and Site > Clear cache.
Now all your site should have the proper config loaded based on the respective context.


MODx page not found...

Stumble upon modx page not found?
MODx by default, will send an error page if any error found during the loading of the page.
its in modx/core/model/modx.class.php

want to see the actual error?
go to the line declaration of
public function sendError($type = '', $options = array()) {
throw new Exception($errorMessage); //after $errorMessage is defined

Tuesday, December 27, 2011

more google Sucks?

Here lies the support forum:
http://www.google.com/support/forum/p/Google+Apps?hl=en

and no way to post any topic.. yay!

updates: if you are a google app user, no way,
unless u r a gmail user...

mysql select condition and sum select

When one select some records from a table, if the condition didnt meet, there will be 0 records returned..
But for a sum record, there will be min 1 record return, even if the record is not found.

SELECT * FROM `table` WHERE 1=2
#return 0 records;

SELECT id, sum(field1) FROM `table` WHERE 1=2
#return min 1 record, even if id is null

Friday, December 16, 2011

GMail sucks?

I've been a long time users of gmail.
I've my email hosted on google apps, and find their anti-spam protection rocks.
But lately, i found their flaws. This flaws is so extreme that i almost want to move out of their app server.

Their spam protection have moved to another level, TOTALLY BLOCKING IP.
Even after several attempt to request them to white list my ip, They FAILED to response on time or response any emails to my request.
I've my RDNS setup, SPF and DKIM, but they just block my ip.
And its a new vps ive just gotten, so im not sharing the ip with anyone else.
Probably someone have miss-used it in the past, but they should response on time to legitimate ip users. This is very unacceptable attitude from Google Team!
My IP is perfectly clean from any black list servers, and why the heck google need to BLOCK IP????

Thursday, December 15, 2011

white listing your mail server

Its so often that our email got miss-tagged as spam and thrown into the recipient junk mail.
It has and will be an on going research on how to white list our mail server to have those emails going into the proper inbox of the recipient.
Even with perfect configuration of white-listing, SPF and SNDS and RDNS, we need to take important consideration into spam filtering on all your outgoing emails. This is extremely important, as we need to protect our good users from bad users. Also to prevent virus infected pc from sending out spams or viruses.
(This article is a work in progress)

Several options availble:

  • SPF (Sender Policy Framework) Record
    Setting up custom TXT record to domain to whitelist your mail server for each domain
    http://www.openspf.net/
    Used by: Gmail, yahoo mail
  • SNDS (Smart Network Data Services)
    Join the White list channel.
    This will requires a RDNS to point to your domain, and have postmaster or abuse@yourdomain.com to handle the add to white list
    https://postmaster.live.com/snds/FAQ.aspx#WhatIsSNDS
    Used by: hotmail and more..
  • AuthKey
    Used by hotmail
  • DomainKey
    Used by hotmail and yahoo mail
  • RDNS (Reverse DNS)
    Need data center or IP owner to point the ip lookup to domain
Suggestion:
  1. Setup RDNS
  2. Setup SNDS
  3. Setup SPF Record for every domain
  4. Dmainkey and Authkey

Useful resources:

Wednesday, December 14, 2011

I was doing my coding in netbean as usual, and was shock to find my changes been replaced and deleted by git. im not sure where went wrong, is it netbean commit that didnt register, or is it git messed up by replacing my commit with its old version.

Wondering how to revert a pull which messed up your code?
run:
git reflog
#example return:

d5ca5a5 HEAD@{0}: pull : Merge made by recursive.
772321b HEAD@{1}: commit: ....
585e66b HEAD@{2}: commit: ....
5a61fe4 HEAD@{3}: commit: ....

run:
git reset 772321b
#reset to a version before the merge was made

then go to netbean and revert all modification done.
This modification basically meants changes that reverse your commit to the older version


then make a copy of the version you have else where.
then run:
git pull
#redo the merge again , which messed up.

#then run meld and compare both directory and put back your latest files and updates into the working directory.
#then recommit your changes.
#then run:
git push
#again.


Saturday, December 10, 2011

smtp relay and spam?

If you are using an external email server to relay your emails,
makesure to add spf record to your dns:

Example:
#Create a TXT record containing this text:
v=spf1 a:mail.yourdomain.com -all
#above meants only allow email to be sent directly from mail.yourdomain.com

if you want to use google:
v=spf1 include:aspmx.googlemail.com -all

for multiple mail server:
v=spf1 a:mail.yourdomain.com a:mail2.yourdomain.com -all

-all = exclude all others..


-----
How to setup qmail to forward emails to another smtp server?
sudo vi /var/qmail/control/smtproutes

:yourexternalserver.com:port# username password
#port, username and password are optional

if you want to set for specific domain:
mydomain.com:yourexternalserver.com:port# username password
:otherexternalserver.com:port# username password

Other useful commands for kloxo qmail:
List queue:
/var/qmail/bin/qmail-qread
To test send email:
echo to: your@email.com | /var/qmail/bin/qmail-inject

Kloxo logs -
tail /var/log/kloxo/smtp.log

To force qmail to send queue:
#grap id from qmail-send pid
ps -Af | grep qmail-send
kill -9 #id

sudo /etc/init.d/qmail restart




Thursday, December 1, 2011

htmlentities and utf8

Ever wonder why your utf8 charactors doesn't work with htmlentities?
try htmlspecialchars
Example:
$sResult = htmlspecialchars($sText, ENT_COMPAT, "UTF-8");

Friday, November 4, 2011

magento rant

First, their javascript validation for setup Fail big time!
once it failed to validate, no matter what you have change in that field, it will not validate anymore!
need to refresh the page, that sucks big time!

installation, took more than 2minutes!
200+tables, omg, do we need that much?

PHP Memory limit of 256MB ?? omg...

Thursday, October 20, 2011

ubuntu virtualbox alt+click

i find it troublesome that i couldn't alt click in my Virtualbox client.
one way to fix it is by resetting the alt key in the host file to super(windows) key.

Go to windows preferences in setting, and change "movement key" from "alt" to "Super"

Wednesday, October 19, 2011

samba sharing on linux

After several frustration to get sharing working from linux,
finally found the root of the problem.

It is often that ubuntu / linux seems to add invalid charactor to the sharing name.
The solution is to remove them.

Exampke: user-intel (Linux mint)
Change to userintel


Thursday, October 13, 2011

Qmail route email to external smtp relay

Edit
/var/qmail/control/smtproutes
content:
:hostname.com

Example:
:smtp.tm.net.my

References:

Monday, October 10, 2011

Kloxo Yum Gave Error... Trying Again

If you ever tried to install kloxo, and encounter this error,
it might be that you are trying to install kloxo on 64bits system.
Do a uname -m to see if its x86_64 (if yes, then its 64bits).
If its a i686, its not.

If you encounter that error, its likely that your /etc/php.ini is configured to disallow function "system".
Edit the php.ini and find for all line with:
disable_functions =exec,passthru,shell_exec,system...
and comment it off by adding #
Try to find for more of these line. Sometimes its been set more than once.

Updated: 24 Sept 2012:
Okay, normally this error comes out when an installation is incomplete along the process.
So the system have been configured to reject system call, therefore reinstalling it is not possible.
Best way is to reformat your server and install from fresh again.
Normally happen to 64 bits os, best to fall back to 32bits.

Tuesday, October 4, 2011

MySQL Lock tables and subqueries

Example error:
Table 'table' was not locked with LOCK TABLES

Example:
LOCK TABLES x write, y write;
select * from x; #works
select * from y; #works

But:
select *,
(select fieldname from y where fieldcond=x.field2) as yname
from x where field1='xxx'; #failed with
#y tables is not locked

Solution:
LOCK TABLES x write, y write, y as yalias write;
select *,
(select fieldname from y yalias where fieldcond=x.field2) as yname
from x where field1='xxx';
#WORKS!

Check system file changes from installed package

On redhat based system:

rpm --verify -all

On Debian based system:

dpkg -l \*|while read s n rest; do if [ "$s" == "ii" ]; then echo $n;
fi; done > ~/tmp.txt
for f in `cat ~/tmp.txt`; do debsums -s -a $f; done

Monday, October 3, 2011

select a field by first row via left join

There are times when we need to select first record of a table in a join tables.
Problem with mysql is that after joining tables together, there will be no indexing,
making query extremely slow.

First, makesure all inner join uses on query to limit the records instead of where condition.
This way, the record is filtered based on table indexes (make sure you index'em first) in the joining process.

2nd, to only populate a field by first row which matches the criteria, do a left join

select x.field1, x.field2 from table1 x inner join table2 x2 on x.field3=x2.field2
left join table2 x3 on x2.field1=x3.field1 and x3.fields=[some condition to filter to first row]
group by ...

Roundcube Error 500

It seems that kloxo always have issue updating roundcube.
Most of the time, the webmail is updated, but the database is not.
to fix it:
mysql -u root -p roundcubemail
source /home/kloxo/httpd/webmail/roundcube/SQL/mysql.update.sql


Wednesday, September 28, 2011

MySQL data contains chinese charactor become äöüßæåéé

It took me hours figuring this.
All my mysql data became symbols.
Then finally, i found the culprit.
1st, i converted my field and default charset of my table to unicode.
But i did not update the existing data to unicode. So it was my mistake.

2nd, in php, i changed my mysql_set_charset("UTF-8");
So now all the data from the table which contains original latin will be forced to utf-8.
So the symbol appear in my html output, so does phpmyadmin.

To fix this, i wrote a program to retrieve the data from latin charset, and
then output it as a code in array to replace the data later back to the database as utf-8.

Example:
mysql_set_charset("latin1", $conndb);
mysql_query("select ...");
$aData = mysql_fetch_assoc($query);

mysql_set_charset("utf-8", $conndb);
$aData["fieldname"] = utf8_encode($aData["fieldname"]);
//then update those record with newly encoded utf8
mysql_query("update table ... ");

so, the next time we query the database, ensure to use
mysql_set_charset("utf-8", $conndb);


Wednesday, September 21, 2011

utf encoding and json

If someone tell you that json doesnt work with utf8, they are wrong.
It does support utf8.
The main problem is the database side.
Ensure to set encoding of mysql connection charset to utf8 to have it working properly.

mysql_set_charset("utf8", $conn);//support for unicode

Tuesday, September 6, 2011

Banning ip from DDOS

After surfing around, ive found some very handy commands to handle blocking of ips

#to list all ip and # of connections
sudo netstat -plan|grep :80|awk {'print $5'}|cut -d: -f 1|sort|uniq -c|sort -n
# list all ports
sudo netstat -plan|awk {'print $5'}|cut -d: -f 1|sort|uniq -c|sort -n

#to block a specific ip
sudo iptables -I INPUT 1 -s xx.xx.xx.xx -j DROP

#to block a class B ip
sudo iptables -I INPUT 1 -s xx.xx.0.0/16 -j DROP


#to block a class C ip
sudo iptables -I INPUT 1 -s xx.xx.xx.0/24 -j DROP


#to block a class A ip
sudo iptables -I INPUT 1 -s xx.0.0.0/16 -j DROP

Normally you might want to use Class B block if you want to block entire ip sets from a particular country...
*be very careful when blocking class B address, some ip range might be shared among different countries.

To know which country the ip resides on:

To list all the iptables rules for incoming traffic:
sudo iptables -L INPUT -n -v

A very good list of cidr ip for each particular country:

Another way of attack is tcp level flood, aka: SYN FLOOD
#check tcp on SYN_RECV
sudo netstat -n -p TCP tcp | grep SYN_RECV

Good article about hardening system:

#Very handy command to limit # of connections to a specific port from an ip
sudo iptables -A INPUT -p tcp --syn --dport 80 -m connlimit --connlimit-above 20 -j REJECT --reject-with tcp-reset
sudo iptables -A INPUT -p tcp --syn --dport 110 -m connlimit --connlimit-above 10 -j REJECT --reject-with tcp-reset
sudo iptables -A INPUT -p tcp --syn --dport 25 -m connlimit --connlimit-above 10 -j REJECT --reject-with tcp-reset

#To remove a rule (example):
sudo iptables -D INPUT -p tcp --syn --dport 80 -m connlimit --connlimit-above 20 -j REJECT --reject-with tcp-reset


#To save it:
sudo service iptables save

Updated 2012 Feb 28:
Encountered another type of DOS attack using TIME_OUT ip status.
One way to solve this is to reduce the # of seconds the tcp will timeout to a incomplete disconnected tcp.
vi /etc/sysctl.conf

net.ipv4.tcp_fin_timeout = 35
net.ipv4.tcp_keepalive_time = 1800
net.ipv4.tcp_keepalive_intvl = 35
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1

sudo sysctl -p

Then restart the services effected, such as http and mysql.
To show all states of tcp in the system, run this:
netstat -an|awk '/tcp/ {print $6}'|sort|uniq -c


Hope this help :)


Monday, August 29, 2011

flowplayer error 2036

Took me hours figuring this out,
and finally found a post on the same error.

First, makesure the control swf is located in the same root as flowplayer swf.
Example: flowplayer.controls-3.2.5.swf and flowplayer-3.2.7.swf in the same folder.

then, makesure your unique id.
Example: id="myflowplayer" ...

This shall works fine :)

Tuesday, August 23, 2011

Kloxo /script empty!

For some freaking vps problem, i was facing very slow processing with vps from ds.my as usual.
running /script/upcp seems to somehow run halfway and hang...

So i decided to stop it, and realize, the entire folder /script is empty!...

To fix it:
cd /usr/local/lxlabs/kloxo/httpdocs
sudo lphp.exe ../bin/update.php

And wait for it to complete.. duh...

Saturday, August 20, 2011

MODx Revolution and UTF8

If you ever need to insert in latin symbol or unicode into modx title or content...
Modify modx_site_content fields:
+ pagetitle, longtitle, description, introtext, content
to unicode_general_ci encoding.
(Note: This is a fulltext index, so you will have to execute 1 statement to alter all 5 fields)
And also modify template variable content:
ALTER TABLE  `modx_site_tmplvar_contentvalues` CHANGE  `value`  `value` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL

Next, modify core/config/config.inc.php and change the line:
+ $database_connection_charset = 'utf8';
+ $database_dsn = 'mysql:host=...;dbname=...;charset=utf8';

And you may start testing it it works :)
In my setup, its somehow in njis charset... (im not sure why)

Tuesday, August 9, 2011

MODx Revolution Root resource alias / path?

I tried google around on this, and find it difficult to find the result.
I've found a solution to based my resource alias to the root of the site.
By going to system > settings
use_alias_path : no

This will change all your resource alias to be based from root.
Example:
Container1 > My page (resourcealias: mypage)
now become:
http://www.example.com/mypage

If you need the container path, just put the full folder path:
Example:
Resource alias: container1/mypage

Monday, August 1, 2011

convert pdf to image in linux

convert -density 150 file.pdf outputname.png

-density to set pixel / resolution, the bigger the number, the bigger the image size

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

Sunday, May 22, 2011

jQuery idTabs switching tab

idTabs contains a bug where you may not program it to switch tab by passing

jQuery("#mytab.idTabs").idTabs(0);

This is due to the if statement in idTabs function which collect the "selected" class in a tag to determine the active tab.

the fixed version is available here:

Friday, May 20, 2011

HTML5 framework

52 Framework is pretty much a all in one packed framework for any html5 start off.
It contains grid with columns CSS, CSS 3 , HTML5, Form CSS, Form Validation and CSS reset.
It also include modernizer to fix up some issue with IE.

For those whom need IE canvas on IE 8 or below:

Sunday, May 8, 2011

div offsetWidth 0?

Did you ever encounter offsetWidth returning 0?
In my case, it happen when ive a div within a div where it represent a container for a jquery tab.
Somehow, i found out that the offsetWidth return 0 if i did not tab to that tab.
Once ive tab into that tab, the offsetWidth now return the actual width rendered.
Took me some hours to solve this issue...

Thursday, May 5, 2011

Netbean 7 is out


Hmm i know, im kinda outdated.
Recently, due to some problem with netbean, ive decided to check out the latest version.
To my surprise, i was outdated , lol.
My first try on netbean 7 was wonderful :)
Now, the project scanning is less of a nuisance , and lighter processing weight.
I could do my work while the project scanning doing its job, unlike netbean 6.9...

And also, great improvement on the version control ui. The new version has git in the plugin repository. It seems like this version control is much faster :).
I still remember, preferring to run git command from console due to the netbean slow scanning speed for version control. But still, console command git is still much faster.

vps ssh not starting after update in openvz

if you face this condition, you are almost doomed for reinstall, but wait!

updated:
edit /vz/private/[vbox#]/etc/init/ssh.conf,
comment off oom never:
#oom never

reboot the vps, it shall work :)
or else, try alternative below:
---------------------

there is a way to solve this..
1st, create a file in /etc/init.d/sshstart

fill it up with:
sh /etc/init.d/ssh start

then run
/sbin/vzctl runscript [vps container #] /vz/private/[vpscontainer#]/etc/init.d/sshstart

if you get any error, this might give you lead on how to solve it.

but as for my condition, i found the problem in the /var/log/daemon.log to refer to:
init: ssh main process (21717) terminated with status 255
Failed to spawn ssh pre-start process: unable to set oom adjustment: Operation not permitted

Someone suggested that the issue is because the ssh is not launched after network, therefore to fix it, you will need to edit /etc/ssh/sshd_config and enable the line ListenAddress 0.0.0.0

But in my case, it didnt work. so ive done a work around to start it via vzctl.
If you dont know your vps container #, its in
ls /vz/private/

References:

openvz stop running

Sometimes, updating the o/s of the dedicated server with openvz installed, might trigger change of default kernel to boot from.
To fix it...
sudo vi /boot/grub/menu.lst

Change the line to point to the index of the openvz kernel. the starting index will be 0
Example:
default 1
to:
default 0

Userful command:
/usr/sbin/vzlist -a
/usr/sbin/vzctl
uname -a


Wednesday, May 4, 2011

openvz meta data checksum failed

If you face checksum failed when trying to sudo yum update, try this:

sudo yum clean all
sudo yum makecache

Tuesday, May 3, 2011

baseurl for ie7 or ie6

BASEURL can be used to set the root path for all image, links and javascript src path within the page.
But IE 7 or below seems to have problem if we use baseurl to "/".
Instead, use full url: example: http://www.mydomain.com/

But in IE 8 or above, or chrome 11 or firefox 4, its okay.

Friday, April 29, 2011

security with nmap

if you are running a server, or curious about what services is running on your system,
you may use nmap to have a port scan on your machine,
and show you some good information about the machine runnning ports, machine o/s and service specific information such as netbios, file sharing server, web server and mail servers..

Quick start:
nmap -A -T4 [ip/domainname]

Tuesday, April 26, 2011

MODx Revo unable to login to manager

If you try to login to manager screen, but unable to get any error message..
then you are likely to have key in the right password, but it auto redirect you back to manager login screen.

This is due to problem with current session.
Just clear the browser cache, and try reload the page and login again.
Hope this helps :)

Kloxo Roundcube unable to connect to database

Its most likely to occur after an update on kloxo.
To fix it, go to shell:
and sudo /script/fixwebmail

sudo chmod 644 /home/kloxo/httpd/webmail/roundcube/config/db.inc.php
sudo chmod 644 /home/kloxo/httpd/webmail/horde/config/conf.php

then try again, it shall work now...
if not, please try searching their forum

Monday, April 25, 2011

jQuery No Conflict

jQuery No Conflict need to be positioned after all jquery plugin has been included.
Because some plugin is still using $ in the code, therefore the noconflict will remove $ and only made jQuery or the variable assigned as jQuery function.
If you are mixing with Mootool, you should include jquery, jquery plugins, jquery noconflict, then only moo tool .

Example:
jquery/jquery-1.5.min.js
jquery/jquery-ui-1.8.9.custom.min.js
jquery/jquery.form.js
jquery/jquery.ui.datetime.min.js
jquery/jquery.noconflict.js"

Example of jquery.noconflict.js
---------------
$j = jQuery.noConflict();
---------------


Saturday, April 23, 2011

VPS hosting: Ping comparisons

host:www.g2khosting.com, min:441.092, max:569.35, avg:519.856, loss:0, ip:200.32.8.20, os:darwin
host:www.ihserver.net, min:522.827, max:547.028, avg:534.928, loss:0, ip:200.85.152.197, os:darwin
host:www.austrosolutions.at, min:254.584, max:354.166, avg:303.693, loss:0, ip:188.40.176.4, os:darwin
host:www.carrot-server.at, min:296.847, max:367.524, avg:332.37, loss:0, ip:78.47.212.123, os:darwin
host:kapper.net, min:293.862, max:390.25, avg:332.811, loss:0, ip:62.116.5.4, os:darwin
host:www.snb.at, min:283.39, max:361.89, avg:320.441, loss:0, ip:78.47.53.147, os:darwin
host:www.vboxes.net, min:297.108, max:367.966, avg:332.634, loss:0, ip:212.24.124.41, os:darwin
host:www.globalmedia.com.br, min:377.481, max:456.282, avg:419.154, loss:0, ip:208.43.42.56, os:darwin
host:www.fcolor.bg, min:321.025, max:399.464, avg:358.438, loss:0, ip:87.119.79.248, os:darwin
host:www.fitvps.com, min:399.47, max:470.799, avg:435.15, loss:0, ip:217.79.65.94, os:darwin
host:compevo.com, min:378.025, max:433.338, avg:400.168, loss:0, ip:174.34.156.179, os:darwin
host:www.delimitervps.com, min:426.986, max:813.309, avg:563.69, loss:0, ip:96.45.186.188, os:darwin
host:www.letstalkdigital.com, min:, max:, avg:, loss:0, ip:208.73.210.152, os:darwin
host:secure.media-hosts.com, min:321.619, max:393.599, avg:358.079, loss:0, ip:38.127.71.126, os:darwin
host:protoserver.com, min:, max:, avg:, loss:0, ip:208.88.184.25, os:darwin
host:www.vistapages.com, min:354.111, max:433.252, avg:393.436, loss:0, ip:208.83.212.226, os:darwin
host:vpsville.ca, min:368.72, max:447.102, avg:409.805, loss:0, ip:76.74.137.21, os:darwin
host:www.ultimatehosting.eu, min:409.251, max:479.576, avg:444.724, loss:0, ip:81.91.83.151, os:darwin
host:www.lws.fr, min:, max:, avg:, loss:0, ip:46.20.166.242, os:darwin
host:www.1euro-hosting.eu, min:347.067, max:433.18, avg:385.735, loss:0, ip:188.165.85.131, os:darwin
host:fanaticalvps.com, min:263.228, max:345.555, avg:305.848, loss:0, ip:46.4.26.125, os:darwin
host:www.ingate.de, min:344.516, max:423.093, avg:383.674, loss:0, ip:80.190.156.11, os:darwin
host:www.synapseglobal.com, min:398.321, max:469.233, avg:433.949, loss:0, ip:67.215.224.130, os:darwin
host:www.vStarVPS.com, min:409.115, max:455.56, avg:432.337, loss:0, ip:188.72.238.176, os:darwin
host:whynotavps.com, min:306.566, max:377.59, avg:338.345, loss:0, ip:91.213.214.152, os:darwin
host:vps.timway.com, min:93.611, max:113.635, avg:102.98, loss:0, ip:58.64.143.70, os:darwin
host:www.servers.co.in, min:339.132, max:439.172, avg:390.34, loss:0, ip:74.86.169.206, os:darwin
host:www.ehost.ir, min:347.298, max:425.692, avg:384.407, loss:0, ip:174.34.242.164, os:darwin
host:www.altnet.lv, min:342.203, max:420.984, avg:381.367, loss:0, ip:195.3.144.37, os:darwin
host:www.serveriai.lt, min:344.633, max:429.264, avg:385.151, loss:0, ip:79.98.24.240, os:darwin
host:www.bakka.my, min:49.773, max:62.386, avg:53.347, loss:0, ip:202.190.85.200, os:darwin
host:www.cubiex.com, min:53.688, max:93.677, avg:70.92, loss:0, ip:202.190.179.125, os:darwin
host:www.adk-media.com, min:381.121, max:460.078, avg:418.098, loss:0, ip:174.142.235.21, os:darwin
host:www.naja7host.com, min:312.96, max:383.181, avg:348.36, loss:0, ip:63.247.87.202, os:darwin
host:www.belsemtech.com, min:296.357, max:367.045, avg:332.16, loss:0, ip:108.60.194.130, os:darwin
host:www.avanpad.com, min:, max:, avg:, loss:0, ip:85.17.184.44, os:darwin
host:www.signet.nl, min:387.523, max:466.574, avg:429.279, loss:0, ip:217.21.253.53, os:darwin
host:www.touchvps.com, min:354.162, max:433.312, avg:393.548, loss:0, ip:93.186.193.39, os:darwin
host:www.voipcomplete.com, min:344.056, max:422.711, avg:378.875, loss:0, ip:94.124.56.35, os:darwin
host:www.efeito.net, min:430.129, max:486.35, avg:454.821, loss:0, ip:77.91.206.141, os:darwin
host:www.intovps.com, min:409.337, max:479.387, avg:444.625, loss:0, ip:93.113.174.175, os:darwin
host:www.ename.ro, min:420.336, max:466.842, avg:443.74, loss:0, ip:85.120.61.162, os:darwin
host:www.ch-center.com, min:298.783, max:367.252, avg:332.505, loss:0, ip:89.41.172.10, os:darwin
host:linhost.ru, min:375.047, max:477.988, avg:423.077, loss:0, ip:217.112.34.76, os:darwin
host:hosting.agava.ru, min:306.631, max:378.18, avg:342.663, loss:0, ip:89.108.96.156, os:darwin
host:vdsplanet.ru, min:, max:, avg:, loss:0, ip:88.198.28.22, os:darwin
host:www.demos.ru, min:479.105, max:557.768, avg:520.639, loss:0, ip:194.87.0.48, os:darwin
host:www.net.ru, min:479.356, max:479.356, avg:479.356, loss:0, ip:193.36.35.62, os:darwin
host:www.heihachi.net, min:, max:, avg:, loss:0, ip:188.190.98.57, os:darwin
host:conceptlane.com, min:61.978, max:103.334, avg:81.394, loss:0, ip:202.150.222.135, os:darwin
host:www.secureax.com, min:377.285, max:456.388, avg:418.858, loss:0, ip:207.7.84.199, os:darwin
host:www.SoftDux.co.za, min:353.665, max:433.24, avg:393.366, loss:0, ip:96.31.66.11, os:darwin
host:www.clickworks.co.za, min:410.822, max:479.591, avg:445.03, loss:0, ip:196.41.137.6, os:darwin
host:acon.se, min:307.006, max:377.329, avg:342.659, loss:0, ip:85.194.160.96, os:darwin
host:www.7x24web.net, min:478.884, max:510.827, avg:494.856, loss:0, ip:64.120.135.178, os:darwin
host:www.istanbulhost.com, min:408.807, max:479.637, avg:444.658, loss:0, ip:88.255.156.55, os:darwin
host:www.DubHosting.co.uk, min:354.125, max:433.194, avg:393.505, loss:0, ip:89.21.14.181, os:darwin
host:www.europhase.net, min:377.346, max:457.126, avg:419.26, loss:0, ip:213.229.64.100, os:darwin
host:www.infrenion.com., min:337.435, max:445.82, avg:387.064, loss:0, ip:74.86.224.33, os:darwin
host:www.rshosting.co.uk, min:396.304, max:511.813, avg:461.134, loss:0, ip:94.76.214.5, os:darwin
host:www.vpsmachine.co.uk, min:377.705, max:559.627, avg:445.838, loss:0, ip:85.159.58.87, os:darwin
host:www.vt6.co.uk, min:, max:, avg:, loss:0, ip:69.64.147.243, os:darwin
host:www.webhosting.uk.net, min:409.45, max:479.815, avg:444.687, loss:0, ip:94.76.255.204, os:darwin
host:www.weycrest.co.uk, min:354.606, max:511.717, avg:419.383, loss:0, ip:78.40.245.178, os:darwin
host:sysadminman.net, min:409.321, max:479.772, avg:444.625, loss:0, ip:213.5.180.160, os:darwin
host:www.xilo.net, min:, max:, avg:, loss:0, ip:91.199.78.20, os:darwin
host:www.zxvps.co.uk, min:355.445, max:457.25, avg:400.024, loss:0, ip:188.165.152.217, os:darwin
host:www.AceShells.com, min:330.636, max:409.327, avg:367.792, loss:0, ip:82.197.73.170, os:darwin
host:www.gelihost.com, min:456.233, max:535.526, avg:495.775, loss:0, ip:195.88.242.210, os:darwin
host:www.hostpro.ua, min:511.757, max:581.668, avg:547.212, loss:0, ip:77.222.131.110, os:darwin
host:www.a2hosting.com, min:347.299, max:417.442, avg:382.611, loss:0, ip:69.39.89.15, os:darwin
host:www.alticon.net, min:, max:, avg:, loss:0, ip:205.134.170.234, os:darwin
host:beyondhosting.net, min:345.465, max:471.01, avg:405.803, loss:0, ip:74.126.89.50, os:darwin
host:www.bittraffic.com, min:274.893, max:353.686, avg:316.61, loss:0, ip:72.20.21.60, os:darwin
host:www.buildyourvps.com, min:343.534, max:398.717, avg:369.797, loss:0, ip:199.223.127.213, os:darwin
host:www.byethost.com, min:348.737, max:506.11, avg:406.469, loss:0, ip:207.182.129.30, os:darwin
host:www.clubuptime.com, min:367.882, max:549.321, avg:434.936, loss:0, ip:173.192.122.129, os:darwin
host:www.chhost.net, min:293.882, max:367.044, avg:330.463, loss:0, ip:184.95.45.36, os:darwin
host:www.cortexnetworks.com, min:300.464, max:370.088, avg:335.336, loss:0, ip:74.124.31.180, os:darwin
host:www.damnvps.com, min:399.643, max:470.395, avg:431.158, loss:0, ip:78.129.175.165, os:darwin
host:www.DubHosting.com, min:375.17, max:431.566, avg:401.743, loss:0, ip:89.21.14.181, os:darwin
host:glesys.se, min:306.859, max:377.384, avg:342.316, loss:0, ip:79.99.6.7, os:darwin
host:goodealhosting.com, min:367.702, max:399.244, avg:383.473, loss:0, ip:208.89.219.198, os:darwin
host:www.greengeeksvps.com, min:354.222, max:479.649, avg:419.106, loss:0, ip:69.175.12.59, os:darwin
host:www.hostmist.com, min:367.826, max:446.683, avg:409.715, loss:0, ip:69.147.224.162, os:darwin
host:www.hostingrails.com, min:345.08, max:470.029, avg:409.392, loss:0, ip:216.222.204.153, os:darwin
host:www.joinvps.com, min:314.387, max:409.619, avg:352.352, loss:0, ip:207.99.118.3, os:darwin
host:www.lovevps.com, min:274.96, max:433.174, avg:342.27, loss:0, ip:199.27.135.78, os:darwin
host:lylix.net, min:, max:, avg:, loss:0, ip:208.122.45.10, os:darwin
host:www.micfo.com, min:323.477, max:393.637, avg:358.61, loss:0, ip:72.3.252.40, os:darwin
host:www.neostreams.info, min:292.389, max:378.157, avg:338.695, loss:0, ip:74.63.117.212, os:darwin
host:www.theserverexperts.com, min:360.865, max:439.35, avg:397.847, loss:0, ip:75.126.29.93, os:darwin
host:thenynoc.com, min:, max:, avg:, loss:0, ip:67.202.100.2, os:darwin
host:railsplayground.com, min:344.937, max:424.042, avg:382.128, loss:0, ip:208.101.3.187, os:darwin
host:www.ramhost.us, min:353.767, max:432.95, avg:393.25, loss:0, ip:199.21.220.75, os:darwin
host:www.rokabear.com, min:469.425, max:469.425, avg:469.425, loss:0, ip:199.58.210.4, os:darwin
host:www.rshosting.com, min:369.25, max:447.413, avg:410.639, loss:0, ip:74.86.125.111, os:darwin
host:www.servercomplete.com, min:409.18, max:479.607, avg:448.402, loss:0, ip:199.48.167.3, os:darwin
host:www.servergrove.com, min:329.693, max:408.124, avg:366.692, loss:0, ip:69.195.198.100, os:darwin
host:www.silverrack.com, min:272.451, max:367.37, avg:319.971, loss:0, ip:208.53.44.217, os:darwin
host:www.syera.net, min:330.91, max:479.784, avg:393.538, loss:0, ip:76.73.96.130, os:darwin
host:www.tektonic.net, min:330.785, max:409.41, avg:367.912, loss:0, ip:65.254.45.254, os:darwin
host:www.tigerservers.com, min:, max:, avg:, loss:0, ip:98.124.198.1, os:darwin
host:www.tocici.com, min:330.907, max:354.097, avg:342.502, loss:0, ip:199.223.127.213, os:darwin
host:www.ultravps.com, min:323.595, max:369.873, avg:346.734, loss:0, ip:76.164.236.60, os:darwin
host:www.Webhost.US.Com, min:355.009, max:433.291, avg:393.725, loss:0, ip:74.86.169.207, os:darwin
host:unixservice.com, min:432.992, max:513.794, avg:470.522, loss:0, ip:209.177.154.77, os:darwin
host:vpslink.com, min:, max:, avg:, loss:0, ip:38.113.1.225, os:darwin
host:www.vpsspeed.com, min:, max:, avg:, loss:0, ip:67.202.100.2, os:darwin
host:vpsnoc.com, min:332.793, max:433.304, avg:382.322, loss:0, ip:208.110.88.210, os:darwin
host:www.webappcabaret.com, min:355.903, max:432.526, avg:393.395, loss:0, ip:208.43.117.131, os:darwin
host:www.zoidial.com, min:307, max:479.822, avg:384.083, loss:0, ip:216.218.235.150, os:darwin
host:www.shackservers.com, min:, max:, avg:, loss:, ip:, os:
host:zensix.com, min:353.98, max:479.761, avg:422.337, loss:0, ip:69.197.147.151, os:darwin
host:pogiweb.com, min:354.152, max:433.369, avg:393.584, loss:0, ip:173.208.148.73, os:darwin
host:appvz.com, min:276.128, max:355.351, avg:317.931, loss:0, ip:188.40.68.114, os:darwin

Friday, April 22, 2011

PHP Gotcha! Running 2 php process via same Session ID

If you came accross requirement to run 2 or more php execution via ajax or cron,
with same Session id, you will meet 1 fallback to the 2 process.

The 2nd php process cannot end until the first process end.
Therefore, if you have a big file uploading on 1 ajax call, and you may call another ajax later,
all your other ajax have to wait for the initial big file uploading to be done before this ajax can fully end.
The 2nd process will execute everything until all register_shutdown_function function is executed, but will not exit until 1st process is done.

This is logically acceptable as you may not want 1 session changes to mixed up with another session changes between 2 processes.
But hope this will save you some time on it...

Friday, April 15, 2011

MySQL query gotcha!

Example:
SELECT * FROM `modx_listvalues` WHERE listvalue like '%_'

like '%_' will result in having all records selected.
Instead, use this
like '%\_'


Thursday, April 14, 2011

Cron but not frequent enough?

If you ever need a on going php process, lets say every 5 or 2 seconds once, you may use python script to do this.
Here is an example of a script:
--------------------
#!/usr/bin/env python
import thread
import time
import os
import sys

sPHPPath = "/usr/bin/php"

def myphp1():
  while 1:
    os.system(sPHPPath + " " + sys.path[0] + "/myphp1.php")
    time.sleep(2)

def myphp2():
  while 1:
    os.system(sPHPPath + " " + sys.path[0] + "/myphp2.php")
    time.sleep(2)

if __name__=="__main__":
  thread.start_new_thread(myphp1, ())
  thread.start_new_thread(myphp2, ())
  while 1:
    time.sleep(60)


Monday, April 11, 2011

PHPUnit and global variable

"PDOException: You cannot serialize or unserialize PDO instances"

If you use phpunit and encounter this message above, you are hit by phpunit nature.
PHPUnit by default serialize all object in global.
So if you have a pdo connection as global variable, or as a variable / properties of a global variable, then you will doomed to face this problem.

Solution:
If you have a class with a property of type xpdo,
create a function __sleep()
and return variable names in array without the xpdo property:
Example:
public function __sleep() {
$aKey = array_keys(get_object_vars($this));

$aResult = array();
foreach($aKey as $sKey) {
if ($sKey != "xpdo") $aResult[] = $sKey;
}
return $aResult;
}

Tuesday, April 5, 2011

php float problem

Example:
326.3 * 100 => 32630 (in double, as displayed in echo)
But, when you floor(326.3*100) => resulted as 32629 (sigh*)

The issue is because after multiplying 326.3 by 100, the double is kept as 32629.9999999 instead of 32630.

But if you floor(32630), as raw integer, you will get 32630.

To fix this issue, convert the result in string, and floor it.
Example:
$iResult = floor((326.3*100)."");
//resulting: 32630.


Tuesday, March 29, 2011

Development Type


There are several type of development for each project.
Either its:
  • New development
  • Change Feature
  • Adding new Feature
  • or redesign / revamp code
  • Bug fixing / Code refactoring
A lot of people get both "bug fixing" and "revamp code" mixed up.
Its unlikely for client (non-programmer) to fully understand the concept behind revamping code,
as in their point of view, its just a piece of program which doesn't work with new business process or doesn't change with new business process.

Out of all 5 different type of tasks, new "development" and "redesign/revamp code" takes the longest time. But this is subjective to either, the code is developed by the same developer, or other developer.

As known that redesign/revamp code could take as long as new development, its best that every new development should goes with proper planning. Both the client / business development manager must cooperate together to discuss the business flow and future path for the system to be used for. The sole purpose would be meeting business long term goal and objective. Without a proper planning, revamping code could possibly be a better choice in later stage of the development. But, lots of time will be wasted bug fixing existing code / work around to fix issue to suite business where it was not developed for that sole purpose.
But, migration of existing system to a new revamped system will also incur lots of time. Not only that, new code also meant new bugs and the process get all reloaded from the start again.

To sum it up, developer should take more time to think of long term solution to the client business, while business manager should consider proper plan for the direction of the company along with the system to build.

By end of the day, both developer and business manager should shake hand and work as a team to make things happen. A little higher price / time spent for a properly planned system save a lot of time along the life of the system.

Saturday, March 26, 2011

modx-combo cascading selection

After spending hours trying to figure this out,
and realized that modx have override most extjs combo with its own data store calling.

I've finally found a way to do cascading to work.
To force it to add the parameter to on call ajax to populate the list,
you will have to add it as baseParams, as the 1st time you select the drop down,
it seems to be doing a auto load.
If you attempt to reload the store without setting baseParams, the first time it got populate, it will be without your additional param.
Example:
Ext.getCmp("state").baseParams.key1 = Ext.getCmp("region").getValue();

But this baseParams only work for 1st time call. It wont work when you subsequencely reselect the parent component.
To do that, we will have to use the load.
Ext.getCmp("state").store.reload({
params: { key1: Ext.getCmp("region").getValue() }
});

This will solve the cascading selection issue.
For example of complete code:
----------------------------------------------------
lets say we have a region > state > district
Ext.getCmp("region").on("change", function() {
var oState = Ext.getCmp("state");
var oDistrict = Ext.getCmp("district");
oState.setDisabled(true);
oState.setValue('');
oState.store.removeAll();
oState.baseParams.key1 = Ext.getCmp("region").getValue();
oState.store.reload({
params: { key1: Ext.getCmp("region").getValue() }
});
oState.setDisabled(false);
oDistrict.setDisabled(true);
oDistrict.setValue('');
oDistrict.store.removeAll();
oDistrict.setDisabled(false);
});
Ext.getCmp("state").on("change", function() {
var oDistrict = Ext.getCmp("district");
oDistrict.setDisabled(true);
oDistrict.setValue('');
oDistrict.store.removeAll();
oDistrict.baseParams.key1 = Ext.getCmp("state").getValue();
oDistrict.store.reload({
params: { key1: Ext.getCmp("state").getValue() }
});
oDistrict.store.reload();
oDistrict.setDisabled(false);
});
-------------------------------------

Thursday, March 17, 2011

object to array of a class with protected variable

Interesting finding for PHP.
By default, if you plan to use get_object_vars to change a class into array, its known that protected and private variable will not be exported to array. Even if you have __sleep method and __get method set to retrieve those variable.

The solution is to put get_object_vars within a method to return get_object_vars($this);

----------------
class A {
public $id = 1;
protected $name = "";

public function __get($name) {
return $this->$name;
}

public function __sleep() {
return array("id", "name");
}

public function toArray() {
return get_object_vars($this);
}
}

$o = new A();
print_r(get_object_vars($o)); //only public variable exposed
print_r($o->toArray()); // all variable are exposed

Tuesday, March 8, 2011

Started a project: FlexiSiteCopy

A general purpose flexible utility to copy database from 1 site to another. Currently tested on MODx 2 and standalone database. Allow modification on data before inserting remote data to local database

Relaying mail for internal server

Having a running staging server would be nice to test application before putting it live.
But since most of us in malaysia is on Streamyx or Unifi, the port25 has been blocked.

One way to solve it is to ask the smtp server to relay mail to an external mail server.
But will require a valid loginid and password of an email account to do so.

If you are using sendmail, you may do setup this way:
1. Find “DS” in /etc/mail/sendmail.cf and add your mail server name as below: -
DSmail.yourdomain.com

2. Find “Mrelay” in /etc/mail/sendmail.cf and add “587″ to “A=TCP $h”.
This port represent your external mail smtp port, since port 25 is blocked:
A=TCP $h 587

3. Add the following line below in /etc/mail/access file in one line: -

AuthInfo:mail.yourdomain.com "U:user@yourdomain.com" "I:user@yourdomain.com" "P:youremailpassword" "R:yourdomain.com" "M:LOGIN PLAIN"

4. Then, restart your Sendmail service as below: -

service sendmail restart

4. Finally, you can monitor your maillog using the command below: -

tail -f /var/log/mail.log

IE8 bypass self signed ssl

* Click on View certificates
* In the Certificate dialog, press Install Certificate
* In the Certificate Import Wizard, click Next
* On page 2 of the wizard, select Place all certificates in the following store and click Browse;
* In the Select Certificate Store dialog, select Trusted Root Certification Authorities, click OK

* In the wizard, click Next, click Finish
* If a security message pops up, choose Yes

Sunday, March 6, 2011

firefox bypass self signed ssl

Bypassing the warning

  1. On the warning page, click Or you can add an exception....
  2. Click Add Exception.... The Add Security Exception dialog will appear.
  3. Click Get Certificate.
  4. Read the text describing the problems with this site.
  5. Click Confirm Security Exception if you want to trust the site.

Monday, February 28, 2011

Gnu PG (gpg) to encrypt .tar.gz

I came to realize that its important to encrypt file that we backup.
We might never know who is touching on those file on the server,
especially when its publicly available on the internet.

One way to encrypt the file is with Gnu PG (gpg).
To create your private + public key:
gpg --gen-key

After completed the prompt, the keys will be created.
Public key is for you to distribute to others, so that they can encrypt the file specially for you only. Because your public key encrypted file can only be decipher by your "private" key.

On MAC / Linux, the keys is stored in [home]/.gnupg/*

To encrypt a file:
gpg -e [filename]

A file by name [filename].gpg will be created with the encrypted data.

to decrypt the file:
gpg -d -o [filename] [filename].gpg

GPG encryption also does compression. Therefore, there is no need to gzip a tar file to use gpg with it. GPG allow console input for encryption. There fore, you may run this:
tar -cp [directory/filename] | gpg -c -o [newfilename].tar.gz.gpg


If you are planning to open your encrypted file in another computer, you will need to have the private key on that machine. Todo that:
To export your secret keys, use:
gpg --export-secret-key -a > secret.key

and to import them in the other machine:
gpg --import secret.key


Other usage:

GPG can also be used for mail purpose. But you will need to allow your sender to have your public key, in order to send encrypted email to you.
You may export your key to your sender by running:
gpg --armor --export --output [newfilename].asc "[yourkeyuid]"

To get the list of keys available on your machine:
gpg --list-keys
The uid role will be needed for above export.




Tuesday, February 22, 2011

jQuery datepicker show only month and year

This code from: http://stackoverflow.com/questions/2208480/jquery-date-picker-to-show-month-year-only
seems to work:
---------------
[script]
$(function() {
$('.date-picker').datepicker( {
changeMonth: true,
changeYear: true,
showButtonPanel: true,
dateFormat: 'MM yy',
onClose: function(dateText, inst) {
var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
$(this).datepicker('setDate', new Date(year, month, 1));
}
});
});
[/script]
-----------
But the main problem is showing back the month,year in the dialog box.To do that, you will have to modify the jquery.ui.datepicker.js

with the code (line #1548, #1549):
----------------
var date = this._daylightSavingAdjust(new Date(year, month - 1, (day >= 1 ? day: 1)));
if (date.getFullYear() != year || date.getMonth() + 1 != month || (day > 0 && date.getDate() != day))
----------------

Sunday, February 20, 2011

Web based application problem

One thing the internet should do better is the consistency check of the data retrieved.
I know, there are suppose to be Network level check, but what im focusing on is the streamed/downloaded data.
Is it complete? or is it half way done.

One good example is downloading a huge file on the internet.
If its a zip file, its easy. Because we can check the zip file crc from the achieve application.

But isnt this suppose to be a web browser job?

There have been more and more Ajax base application out there, but yet,
i find that its not consistant in terms of opening the processed ajax output.
There are times when the internet got instable , and the browser thought the process is complete.
There are also time when the browser thought the javascript is downloaded complete, but its not.
This lead to instable output or undesired response from the server.
Most of the time, this could be fixed by refreshing, or clearing the cache and refresh.
But i think its best that there should be some kind of browser parity or consistancy check for completion, or dont render the output and output some kind of error message to the user.

Sunday, February 6, 2011

PHP gmtime?

I've seen some forum talking about, how nice to have gmtime() function.
But according to some post, it seems that time() is already in gmtime.

But how do we convert a unixtimestamp stored via gmdate("Y-m-d H:i:s") to a offset where its not the server locale timezone?

Its kind of confusing.
But the trick i used was to add the offset to the timestamp, and check if daylight is in effect.
Example of code:
$gmtime = $oRow["ftime"];
$daylight = date("I", $gmtime);
$iOffsetHour = _user_timezone_offset_here;
if ($daylight){
if ($iOffsetHour > 0){ $iOffsetHour-=1; }
else { $iOffsetHour+=1; }
}
$iLocalTime = $gmtime + (60*60*$iOffsetHour);

And to get a quick gmtime():
$gmtime = strtotime(gmdate("Y-m-d H:i:s"));

If anyone find this wrong, please correct me.
thank you :)

Wednesday, February 2, 2011

What may speed up development?


Development speed is what most business is looking forward.
As business client expectation changes, business system have to change according to business requirement from time to time.

Most developer seems to forget about maintenance of existing projects. This is also the same case for most project managers and bosses.
And development doesn't just count new projects and add-on features, but developer should consider detecting "smelly" code and make the code easy to debug.

Unit testing is critical in creating a more stable code. Each time new features is added in, the code shall be tested through series of unit test to ensure existing functionality behave accordingly (as of before add-on or change).

Every developer should consider easy maintainability of their project.
It shall be easy to backup, easy to restore, easy to detect bugs, easy to read code, easy to detect problems or exception.
All these "easy" doesn't come easy to accomplish.
One may consider doing:
  • automated backup of database and site;
  • write brief and useful comments in code;
  • separate "god"-like functional code into parts;
  • write testunit for every functional part of the program;
  • automate background process to cleanup old or unwanted data like logs;
  • automate touch and undo unit-test processers;
  • automate warning message to notify developer of exception and errors;

Here are several things which can be use in most projects:
  • TestUnits for:
    + Date and time zone check and notification
    + Environment requirement check

  • Background processors:
    + # of requests check in a minute
    + Logs reports generation
    + Automated remote update
    + Database rows / size check and notification
    + Database integrity check and notification

  • Maintenance utilities:
    + Server-client communication library
    + Site database copy to local machine
    + Online site and users monitoring
    + Site reports: page count, exceptions, logs
    + Site files download, deployment and updating
    + Site version control and remote updates
    + Framework version update check



Site testing


Aha, you are done with a site!
Is it really done?
What you might want to consider to test? :
  • Cross browser look and feel?
  • Spell & grammar check?
  • Browser check script? (stop user from continuing and browser recommendation)?
  • Have you done a LinkChecker on the site?
  • Have you optimize the site for search engine? Have you put up robots.txt? Have you put up favicon?
  • Have you done a webpagetest.org test on your site?
  • Have you done a country base test on just-ping.com and http://www.websitepulse.com/help/testtools.china-test.html for china users?
  • Is the site ready for mobile users? IPhone? Ipad? Blackberry? Mini opera?
  • Unit Testing for each function in controller of mv"c"?
  • Data entry of invalid values in form fields?
  • Detect and blocking DOS attack?
  • What if facing heavy traffic? Temporary stop execution ? How to detect it?
  • Cross Site scripting by script entry in form?
  • IP Spoofing prevention / proxy connection prevention for transaction?
  • IP filtering to narrow down user access from specific countries?
  • Is the server date and timezone correct?
  • What if multiple user hit concurrently on 1 process? Will duplicate happen?
  • If flash is involved, how to detect for flash block? and put up notices?
  • If you have file protected, is the indexing of directory disabled? Is direct URL access being disabled?
  • Have the website being optimized? (example: setup css and js into separate files)
  • Do you have large files to target specific country audiences? Do you need fast loading? CDN (Content delivery network)?
  • Have you put up notes on project/site objective and target audience?
  • Do you provide font-size adjustment on site?
  • Does the site require multi-lingual in the future? is it ready for that?
  • Do you have logs to track invalid calls or exception on site?
  • Have you combined all functions by avoiding duplicate codes?
  • Have you documented / commented the code?

Wednesday, January 26, 2011

MODx 2 Context setup

When setting up a site to a context, be sure to set these setting in the context:
  • site_url - site url to the domain
  • filemanager_path - the file manager path for this context to upload images / media
  • site_start - the starting resource id as home / landing page
  • site_name - the Site name to be displayed in email and page title

Sunday, January 16, 2011

MODx 2 Adding ... to intro text summary

If you plan to add "..." to a intro text or content which is more than some # of characters,
you may use if condition within the chunk.

Example below will add ... to intro text:
[[+introtext:if=`[[+introtext:len]]`:gt=`200`:then=`[[+introtext:limit=`200`]] ...`:else=`[[+introtext]]`]]

Saturday, January 15, 2011

extjs Adding html to panel

After struggling to check why is my panel no reflecting,
i realised ive forgotten to call doLayout in the end.

To add a html to a extpanel,
Ext.getCmp("panelid").add( {
type: "panel",
html: "some html here"
});

Ext.getCmp("panelid").doLayout();


To remove all html content in a panel:
Ext.getCmp("panelid").removeAll();
//only works in 2.2.1 all later



Thursday, January 6, 2011

MAC /etc/hosts

MAC /etc/hosts is in /private/etc/hosts

Wednesday, January 5, 2011

MAC Finder alike windows explorer

I find it handy to show full path of the current folder at the application title bar.
here is how it can be done:

Tuesday, January 4, 2011

MAMP package and mysql sock

/tmp/mysql.sock was missing because its in /Application/MAMP/temp/mysql/mysql.sock

http://www.fischerlaender.net/web-20/mac-os-x-trouble-with-mamp-mysql

Monday, January 3, 2011

MODx loading other components lexicon

If you need some lexicon from another components from your snippet,
you may do so by running this in snippet:
$modx->lexicon->load("namespacename:filename");

Example:
$modx->lexicon->load("login:register");
//resolve to: core/components/login/lexicon/register.inc.php