Archive for 'Technology'

the iPhone mania

iPhone.. iPhone.. iPhone.. I’ve been wanting this gadget the very first time I heard of it’s existence .. not because of its functionality, I just like to play it like in this video…. I’ll probably have my luck and get a cent from it..

Well, if your seriously thinking to buy it or not, check out this man’s blog – 20 reasons to buy an iphone – he is a certified geek btw and he hated it at first (i believe so), now he’s liking it..

What do you think of the iPhone? is it worth the fun?

cakePhp $html->checkbox htmlattributes issues

It’s not obvious but certainly I was caught offguard for a certainly small issue that made me use the old habit of doing the checkbox thingy.

When I explicitly tell the html helper to check a certain checkbox, I always do array('checked'=>'checked'); to add the checked attribute but I am left wondrin why it does not do what I want. I really can’t remember what I did to make others work but certainly it was such a headache that I opted to use the old <input type=’checkbox’ /> tags. After looking at the html helper, I found out the ffg comments

* + ‘compact’
* + ‘checked’
* + ‘declare’
* + ‘readonly’
* + ‘disabled’
* + ‘selected’
* + ‘defer’
* + ‘ismap’
* + ‘nohref’
* + ‘noshade’
* + ‘nowrap’
* + ‘multiple’
* + ‘noresize’
*
* And its value is one of:
* + 1
* + true
* + ‘true’
*
* Then the value will be reset to be identical with key’s name.
* If the value is not one of these 3, the parameter is not output.

This does not only involve the checkbox but all the input tags because they pass this step first before outputting any parameter. I wish I explored on this much earlier, it would have saved me a lot of energy. Oh well, atleast I learned something new for the day :)

You may also want to check the function yourself. It is the function _parseAttributes($options, $exclude = null, $insertBefore = ' ', $insertAfter = null) in the html helper. You can see the $insertBefore = ' ', $insertAfter = null, this is useful for checkboxes to add labels but currently, that option is not available in the 1.1 version. Someone already asked this enhancement in trac so I am not reporting it again. I hope that saves some of your time :)

Programming language for youngsters

Scratch – a free programming language designed for children 8 years and above. Here is the definition of the author/s

Scratch is a new programming language that makes it easy to create your own interactive stories, animations, games, music, and art — and share your creations on the web.

Scratch is designed to help young people (ages 8 and up) develop 21st century learning skills. As they create Scratch projects, young people learn important mathematical and computational ideas, while also gaining a deeper understanding of the process of design.

I’ll think that’ll be fun to teach to my niece when he grows a little older. He already likes playing the keyboard and mouse at 7months old! (He’ll be the upcoming super geek LOL). What is also lovely about this language is that your children or you can share the program you’ve created in their site! Wanna know more, visit them here.

Validate radio buttons in cakePhp’s ajax->form

It took me a while to learn how to add validation using the $ajax->form() of cakePhp. I think the ajax helper simplifies your work for ajax calls but you should first understand how to use it. The manual isn’t that helpful in explaining the deatails of this helper. Here is one example that I used in an application I am involve with and this hopefully could brighten someone’s day.

In my view.thtml, I have this form

<?php
// !important: name your form
$form_options['id'] = ‘myform’;
$form_options['update'] = ‘my-results’;
// this is where you’ll call the validation function
$form_options['before'] = ‘if (!validate()) return false;’;
echo $ajax->form(‘/controller/action’, null, $form_options)
?>
<div id=”errMsg”></div>
<table>
<tr valign=”top”>
<td nowrap><span class=”required”>*</span> Subscription type </td>
<td><div id=”ModelType”><?php echo $html->radio(‘Model/type’, $my_type, ‘<br />’) ?></div></td>
</tr>
<tr valign=”top”>
<td nowrap><span class=”required”>*</span> Receive updates </td>
<td><div id=”ModelRange”><?php echo $html->radio(‘Model/range’, $my_range, ‘ ‘) ?></div></td>
</tr>
</table>
</form><div id=”my-results”></div>

The validation looks like this

function validate() {
var validation_cnt = 0;
// you must delete the previous message
removeMsg(['err1', 'err2', 'err3']);

// begin the validation
if (isRadioEmpty(“myform”, “data[Rss][type]“)) {
insertMsg(‘RssType’, 1, ‘This is required.’);
validation_cnt++;
}

if (isRadioEmpty(“myform”, “data[Rss][range]“)) {
insertMsg(‘RssRange’, 2, ‘This is required.’);
validation_cnt++;
}

if (validation_cnt > 0) {
var req_msg = ”;
if (validation_cnt == 1) {
req_msg = ‘Found ‘+ validation_cnt +’ error. Please double check your answers. Some fields are required.’
} else {
req_msg = ‘Found ‘+ validation_cnt +’ errors. Please double check your answers. Some fields are required.’
}
insertMsg(‘errMsg’, 3, req_msg);
validation_cnt = 0;
return false;
}

return true;
}

One problem I had with this one is that I need to validate radio buttons. But since cakePhp uses illegal characters in its name, you cannot just use the normal call for it. I found an explanation of how to do this here. Here is the function that validates the radiobuttons:

/**
* Returns true if any of radio boxes with the NAMEs of elementName contained in the FORM named formName is checked
*
* @param formName – ID of the FORM
* @param elementName – NAME of the radio boxes
* @author: Rachel
*/
function isRadioEmpty(formName, elementName) {
var empty = true;
for (i=0; i<=document.forms[formName].elements[elementName].length – 1; i++) {
if (document.forms[formName].elements[elementName][i].checked) empty = false;
}

if (empty) return true;
return false;
}

I am also using some prototype methods to insert the error messages at the bottom of the fields and count the errors. Here is the function for that

/**
* Insert error message after the element containerID
* Add style to class errFld to add style to the error message
* You can delete the previous message created by using @link removeID(‘err’+errID)
*
* @param containerID – ID of an element preceeding the error message
* @param errID – any unique ID that you can give to the error message to uniquely identify it
* @param msg – message
* @param containerType – default value is DIV tag
* @author: rage
*/
function insertMsg(containerID, errID, msg, containerType) {
if (!containerType) containerType = ‘div’;
new Insertion.After(containerID, ‘<’+containerType+’ id=”err’+errID+’” class=”errFld”>’+msg+’</’+containerType+’>’);
}

/**
* Delete the element if it exist. Do nothing if it doesnt exist
*
* @param id – element IDs
* @author: rage
*/
function removeMsg(ids) {
for (x=0; x<=ids.length – 1; x++) {
try { Element.remove(ids[x]); } catch (err) {} // do nothing
}
}

You can check the whole code for simplicity here.

9 tools I can’t live without at work

Finally, I reinstalled my OS and used Ubuntu Feisty and it’s quite awesome! The installation was very easy and I like it very very much compared to my old Breezy. Most of the applications that I use are already in the synaptic so I don’t have to bother looking for them. I am quite one of those users who just want to click and run and ready to use. What really made the difference now is that I have an idea of the linux OS so I know how to navigate my desktop compared 6months ago that I was so clueless and afraid of this OS. Aside from having Feisty, there are also some things that I have learned I couldn’t live without:

Zend studio editor - I tried not to install Zend at the first few days after I installed feisty just to try some editors but I didn’t find anything that match my favorite feature, the autocomplete. At those days I couldn’t really do my work with much productivity. I used either Kate or Gedit but non of the 2 really satisfies me as a complete editor.Well, I tried the phpEclipse before but I didn’t really bother to use it since I have to do some configuration. Honestly, the only thing that makes me like an editor is the autocomplete power which Zend editor has, the left panel where I can see my files and the tabs which make my navigation faster. I hope there is an opensource tool like that. Please let me know if there is one existing.

Firefox – ofcourse, this is just one of those I can’t live without as long as I am a programmer specially my favorite extensions: firebug, web developer and del.icio.us buttons

IE – well, I have to live with it even if the world ends

Krusader – Just found this a few weeks ago. It’s a file manager but I use it as my FTP manager since I only need regular FTP connections. I used the gFtp before but it always crushes and it has become annoying. My favorite tool using Krusader is the Compare file content and the drag and drop copy of files. I use the xxdiff to do the comparison thing and it is really really helpful specially now that I have been involve in a project where we are a group. The drag n drop is just something I have always been looking for in FTP managers for linux. Also, I am able to open as many connections as I want using different windows. The best part is the bookmarking of sites and able to save their logins. I still have a lot of things I haven’t explored in this app yet but I think it is already great!

Tomboy – this is my piece of paper in my desktop and I like taking notes of any idea that pops up at any time of the day or just merely saving some users and passwords. It is really great to have it on your desktop.

KColorChooser – a color palette editor and color picker for KDE. I used this before when I was not aware of the difference of KDE applications and Gnome applications so I really didn’t mind installing it. Anyway, someone told me about gcolor2 and agave. I have installed them and will try but I am already satisfied with the accuracy of kcolorchooser so I really dont mind if it’s for KDE. :D

Gaim – or pidgin.. Gaim is already installed in Ubuntu so I didn’t bother to upgrade to pidgin.

And one of the most helpful thing I found just lately using Linux – the grep command line. My work always consist of debugging and tracing codes so looking for a specific function or line in hundreds of files, that is just some kinda ninghtmare. Thankfully I just use this

grep -R 'line to search for' /my/directory

and that’s it! I found what I am looking Is there such tool in windows like that? I tried to use the file search of crimson editor but it doesn’t give me the details I want.

Finally is graphics editor like Photoshop. I just hope there is a Photoshop version for Linux and I do not have to go back to windows again. I use gimp as an alternative but I just don’t see myself learning it in the near future :D

Well, those are just the stuff that I have to take note off when I plan to reinstall my pc again!

Tattoes for your desktop

I am always amazed by tattoe artworks and when I saw this one my curiosity arose more. By searching the web, I found out that you can create your own artwork with these free brushes and this. I tried to do some but I couldn’t make one that I’ll be proud to post here but maybe you could. Just a warning, the brushes are quite big in size (I wanted to load them all but my pc just hangs :( ) Also, because they are free, they have terms on using it so please be sure to read them as well if your planning on using it other than for personal use.

Enjoy!

I failed my XHTML exam!

I tried an exam about XHTML today and the result wasn’t that great (yes, shamefully I failed and I don’t wanna brag that I got a 30% score!). It lead me to search why xhtml exist (and just basically know if that makes me a really bad bad bad web programmer).

So what is the importance of xhtml anyway? I googled it and here is the 1 main reason – accessibility. Accessibility is not just for the disabled people but also related to all individuals connecting to the internet. We use different browsers, right? Browsers set standards and rules on how they will render the html tags and some old browsers, and new ones as well, will render differently if these rules are not met. Still, why the heck will you care? Here’s a list of a debatable/acceptable/sale-able reasons to answer why comply with xhtml standards:

  • if you are from the US or Australia, you dont want to get sued for breaching the Disability Discrimination Act
  • ensuring that your website is widely accessible to people across the range of computers and browsers means that you will not lose a potential sale because your website did not render properly on the website visitors computer
  • compliant sites rank better on search engines, increasing exposure of your website
  • changes in technology, such as new versions of browsers are less likely to affect the way your website renders

There you go, is that enough for us to move on and learn the beautiful world of xhtml? I found a few sites where to start learning xhtml. If you are a total newbie, this article could help you. If you have a little background and wanted to expand your knowledge, the w3schools is my favorite tambayan(place to hang out). You could also try the exam I mentioned above and let me know your score ;)

For validation (if you are serious about it, you’ll need these tools), there are free tools to validate your website. I use the ffg:

There are still a lot of sites that do not follow these standards (that comforts me a little) and probably doesn’t even care (ouch! after all those words and hard work of other people setting these standards, they still do not care?). Now that you know, let’s just try to change our ways earlier than later for a better world and a better score. It doesn’t advocate world peace but it will definitely make others have a peaceful and easier life in the www world :)

Btw, I’m taking the exam again probably by next week. It doesn’t hurt if I try again.. and again.. and again.. until I get my level 1 certificate! hihihi

Dummy content for a newly designed template

Need dummy content for your website? I know most of you have been using the lorem ipsum text so I am just giving you a quick way to find them. Good news for firefox users! There is extension available here.

How to translate your web content to different languages?

Have you heard of Altavista’s Babel Fish? I found a cool way on how to use their service to translate your website easily.. I just found this out when visiting a website so it’s not originally my idea.. just sharing thoughts..

What you will only need is to redirect your website to [html]http://babelfish.altavista.com/babelfish/trurl_pagecontent?lp=en_+language_abbr+&url=+your_site [/html]

You can put that in your link directly just like below.
[html]

[/html]

But I wont recommend that idea since BabelFish change all links to redirect to their site. Try it and you’ll see what I mean. Once you switch to German, you can’t use the same links again to switch to another language instead you are redirected to its search page which isn’t really a good behaviour. The solution is put the link in javascript. Babelfish doesn’t encrypt links inside the script tag. Here is what I use:

[js]function translate(lang){
window.location = “http://babelfish.altavista.com/babelfish/trurl_pagecontent?lp=en_”+lang+”&url=http://www.yoursite.com/”;
}
function home(){
window.location = “http://yoursite.com”;
}

<a href=’javascript:translate(“de”);’> German</a>
<a href=’javascript:home();’>English</a>
[/js]

That’s more useful. And also do not forget to link back to BabelFish, just a way to thank them.

One catch though, I am not pretty sure if this is illegal. Let me know if it is so I may inform everyone.

Force email confirmation in Mediawiki 1.9

Before proceeding to this article, have you tried the following links?

If non of the above answers the problem, you may try this solution.

How to check if a registered user has confirmed his registration email? Here is a simple modification I made. It checks if the user has confirmed his/her email before logging in. You may use it anytime at your own risk. If there are any bugs or it has been helpful, tell and share what you think here :)

Affected files are:
/wiki/languages/messages/MessagesEn.php
/wiki/includes/SpecialUserLogin.php

For Messages.php, I only added/edited the ffg:
[php]
$messages = array(
‘not_authenticated’ => ‘Please verify your email address and try again.’,
‘confirmemail_oncreate’ => ‘A confirmation code was sent to your e-mail address.
Please verify it before you can edit any page.’,
)

For the SpecialUserLogin.php, here are the changes

class LoginForm {
// Added for confirmation error in login
const NO_AUTH = 8;

function addNewAccount() {
global $wgUser, $wgEmailAuthentication;

# Create the account and abort if there’s a problem doing so
$u = $this->addNewAccountInternal();
if( $u == NULL )
return;

# If we showed up language selection links, and one was in use, be
# smart (and sensible) and save that language as the user’s preference
global $wgLoginLanguageSelector;
if( $wgLoginLanguageSelector && $this->mLanguage )
$u->setOption( ‘language’, $this->mLanguage );

# Save user settings and send out an email authentication message if needed
if( $wgEmailAuthentication && User::isValidEmailAddr( $u->getEmail() ) ) {
//Position it here
$u->saveSettings();
global $wgOut;
$error = $u->sendConfirmationMail();
if( WikiError::isError( $error ) ) {
$wgOut->addWikiText( wfMsg( ‘confirmemail_sendfailed’, $error->getMessage() ) );
} else {
$wgOut->addWikiText( wfMsg( ‘confirmemail_oncreate’ ) );
}
}

//removed the other unneccary conditions
global $wgOut;
$self = SpecialPage::getTitleFor( ‘Userlogin’ );
$wgOut->setPageTitle( wfMsgHtml( ‘accountcreated’ ) );
$wgOut->setArticleRelated( false );
$wgOut->setRobotPolicy( ‘noindex,nofollow’ );
$wgOut->addHtml( wfMsgWikiHtml( ‘accountcreatedtext’, $u->getName() ) );
$wgOut->returnToMain( $self->getPrefixedText() );
wfRunHooks( ‘AddNewAccount’, array( $u ) );
return true;
}

function authenticateUserData() {
# code before the changes
if ( 0 == $u->getID() ) {

} else {
$u->load();
}

// check if the user has confirmed his/her email
if( !$u->isEmailConfirmed() ) {
return self::NO_AUTH;
}

#code after the changes
if (!$u->checkPassword( $this->mPassword )) {
if( $u->checkTemporaryPassword( $this->mPassword ) ) {
}

function processLogin() {

# code before the changes
case self::RESET_PASS:
$this->resetLoginForm( wfMsg( ‘resetpass_announce’ ) );
break;
case self::NO_AUTH:
$this->mainLoginForm( wfMsg( ‘not_authenticated’ ) );
break;
# code after the changes
default:
wfDebugDieBacktrace( “Unhandled case value” );
}
}[/php]
Improvement:

In the Special:Confirm, you may want to make this work without having to log in. I haven’t had the time to tweak that. If you do have the solution, please share them here :)