UTF-8: The preferred encoding

March 23rd, 2011 | Encoding

The capability to display multiple languages in the same document can be achieved using Unicode and it is supported in most operating systems and applications.

The two standard encodings are UTF-8 and UTF-16. UTF-8 is preferred. Let me explain why.

1. Backward-compatible with ASCII. An ASCII character can also be a valid UTF-8 character.
2. Supports modern browsers and operating systems.
3. No need to modify every bit of code. Simply change the encoding to UTF-8.

Read more…

Quick overlay with Scripty2

November 3rd, 2010 | Scripty2

Creating overlay in scripty2 is very simple.

Create a button with an id mybutton. Add the javascript below at the head section of your file.

document.observe('dom:loaded', function() {
	$("mybutton").observe("click", function() {
		$(document.body).insert(S2.viewportOverlay().setStyle(
'background:#000;opacity:0.5;height:100%;'));
	});
});

Lines 3 and 4 does the overlay. If you wanted the overlay to be a bit darker, set the opacity to 0.6 or higher.

And last… the html.

<body>
<div id="mybutton">Click Me</div>
</body>

Scripty2 is still in beta as of this writing.

Browser Support
It is not working on IE versions. Tested in Firefox, Google Chrome, Opera and Safari

1st party and 3rd party libraries in cakephp 1.3

October 17th, 2010 | CakePhp

To use first party libraries, simply put the files inside app/libs folder. In your controller, reference import function of App class.

App::import( 'Lib', 'php_file' );

For third party libraries, put the files inside app/vendors. In your controller, reference again import function of App class.

App::import( 'Vendor', 'php_file' );

Note: You don’t have to include the .php file extension. Cakphp will handle it for you. Libs directory is intended to contain first party libraries. Vendors directory is intended to contain third party libraries or external vendors. App::import only includes the file so you would have to create new instances overtime.

app/libs is a new feature in Cakephp 1.3. To know more visit http://book.cakephp.org/view/1572/New-features-in-CakePHP-1-3.

Fetching data from Facebook using CURL and JavaScript SDK

September 21st, 2010 | Facebook | 2 Comments »

In Facebook’s Single Sign-on using JavaScript SDK , i discussed how single-sign on works. Now, I will discuss how to use the signed cookie and curl in fetching the active user’s data.

Parsing the signed cookie
Below is a script that is available in the facebook developer’s page. It parses the signed cookie saved on your registered site having the fbs_APP_ID format.

function get_facebook_cookie($app_id, $application_secret) {
  $args = array();
  parse_str( trim( $_COOKIE['fbs_' . $app_id], '\\"' ), $args );
  ksort( $args );
  $payload = '';
  foreach ( $args as $key => $value ) {
    if ($key != 'sig') {
      $payload .= $key . '=' . $value;
    }
  }
  if ( md5( $payload . $application_secret ) != $args['sig'] ) {
    return null;
  }
  return $args;
}

The most important part of the cookie that we will use is the access_token. If the token is incorrect the Graph API will give a OAuthException error type.
Read more…

Facebook’s Single Sign-on using JavaScript SDK

September 18th, 2010 | Facebook

Using JavaScript SDK is an easy way to implement login and sign up using OAuth 2.0 protocol.

How does it work?
The JavaScript SDK saves the credentials for the active facebook user in a cookie on your registered site’s domain. Once there is a cookie present, you can fetch the active facebook user’s information in facebook and use it in your code.

Session Detection
The SDK automatically detects if there is a cookie present in your registered site. If there is, it will automatically login the currrent user without the need to click the facebook login button.

Read more…