<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Andrew's Tech Musings &#187; early adopters</title>
	<atom:link href="http://andrewcurioso.com/tag/early-adopters/feed/" rel="self" type="application/rss+xml" />
	<link>http://andrewcurioso.com</link>
	<description>Tech, Social Media, PHP, Opinions</description>
	<lastBuildDate>Wed, 12 Oct 2011 19:43:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>RIA: Desktop Notifications in Google Chrome</title>
		<link>http://andrewcurioso.com/2011/01/ria-desktop-notifications-in-google-chrome/</link>
		<comments>http://andrewcurioso.com/2011/01/ria-desktop-notifications-in-google-chrome/#comments</comments>
		<pubDate>Thu, 27 Jan 2011 17:37:36 +0000</pubDate>
		<dc:creator>Andrew Curioso</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[early adopters]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://andrewcurioso.com/?p=596</guid>
		<description><![CDATA[I&#8217;ve seen a number of blog posts floating around today about GMail Desktop Notifications (here, here, here, here and here &#8212; did I miss anyone?). I tried them out myself and they are very useful. Being a rich web applications developer I, of course, wanted to figure out how it works and how I could [...]]]></description>
			<content:encoded><![CDATA[<pre style="display:none"><script type="text/javascript">
<!--
function demoCheck() {
  var c = ( window.webkitNotifications !== undefined );
  if ( !c ) alert("Your browser does not support desktop notifications using this method. Try out the demos in Google Chrome!");
  return c;
}

function demoCheckPermission() {
  if ( !demoCheck() ) return;
  switch ( webkitNotifications.checkPermission() )
  {
    case 0: // PERMISSION_ALLOWED
      alert( "Permission: allowed" );
      break;
    case 1: // PERMISSION_NOT_ALLOWED
      alert( "Permission: not allowed" );
      break;
    case 2: // PERMISSION_DENIED
      alert( "Permission: denied" );
      break;
  }
}

function demoRequestPermission() {
  if ( !demoCheck() ) return;
  webkitNotifications.requestPermission();
}

function demoNotify() {
  if ( !demoCheck() ) return;
  if ( webkitNotifications.checkPermission() == 0 )
  {
    var iconImageUrl = "http://0.gravatar.com/avatar/25c07794aa15e4173b0f8b5c3f66c66b?s=64&#038;d=http://0.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536%3Fs%3D32&#038;r=G";
    var title = "Andrew sent you a message";
    var subTitle = "Hello world.";

    var notification = webkitNotifications.createNotification( iconImageUrl, title, subTitle );
    notification.show();
  }
  else
  {
    alert( "Please request permissions first." );
  }
}

function demoHtmlNotify() {
  if ( !demoCheck() ) return;
  if ( webkitNotifications.checkPermission() == 0 )
  {
    var url = "http://andrewcurioso.com/wp-content/custom/2011/notification.html";
    var notification = webkitNotifications.createHTMLNotification( url );
    notification.show();
  }
  else
  {
    alert( "Please request permissions first." );
  }
}

function demoTimerNotify() {
  if ( !demoCheck() ) return;
  if ( webkitNotifications.checkPermission() == 0 )
  {
    var iconImageUrl = "http://0.gravatar.com/avatar/25c07794aa15e4173b0f8b5c3f66c66b?s=64&#038;d=http://0.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536%3Fs%3D32&#038;r=G";
    var title = "Andrew sent you another message";
    var subTitle = "This notification will disappear in 10 seconds.";

    var notification = webkitNotifications.createNotification( iconImageUrl, title, subTitle );
    notification.show();
    setTimeout( function() { notification.cancel() }, 10000 );
  }
  else
  {
    alert( "Please request permissions first." );
  }
}
//--></script></pre>
<p>I&#8217;ve seen a number of blog posts floating around today about GMail Desktop Notifications (<a href="http://downloadsquad.switched.com/2011/01/26/gmail-enables-html5-powered-desktop-notifications/?utm_source=feedburner&#038;utm_medium=feed&#038;utm_campaign=Feed%3A+weblogsinc%2Fdownloadsquad+%28Download+Squad%29&#038;utm_content=Google+Reader">here</a>, <a href="http://lifehacker.com/5744356/gmail-now-has-desktop-notifications-baked-in-for-chrome">here</a>, <a href="http://mashable.com/2011/01/27/gmail-desktop-notifications/">here</a>, <a href="http://www.engadget.com/2011/01/27/google-adds-html5-gmail-and-gtalk-notifications-for-the-desktop/">here</a> and <a href="http://googlesystem.blogspot.com/2011/01/gmail-desktop-notifications.html">here</a> &#8212; did I miss anyone?). I tried them out myself and they are very useful. Being a rich web applications developer I, of course, wanted to figure out how it works and how I could use it for my own apps. Here&#8217;s a quick overview of what I found.<br />
<span id="more-596"></span></p>
<p>There is a proposed web notification standard over at the W3C that Google submitted earlier this month (you can find it on the <a href="http://dev.w3.org/2006/webapi/WebNotifications/publish/Notifications.html">W3C site</a>) but from what I can tell, that draft isn&#8217;t implemented in any browsers (including Google Chrome!). But  you can get desktop notifications today without the need for any third-party browser extensions, if you&#8217;re using Google Chrome. You can find the documentation <a href="http://www.chromium.org/developers/design-documents/desktop-notifications/api-specification">over on the Chromium developer site</a>. The rest of this post is a collection of quick examples I put together for using notifications:</p>
<h3>Checking for permission</h3>
<p>It is pretty easy to check to see if the user has allowed notifications for your website. The first example displays an alert depending on the permission level.</p>
<pre class="brush: jscript; title: ; notranslate">
switch ( webkitNotifications.checkPermission() )
{
  case 0: // PERMISSION_ALLOWED
    alert( &quot;Permission: allowed&quot; );
    break;
  case 1: // PERMISSION_NOT_ALLOWED
    alert( &quot;Permission: not allowed&quot; );
    break;
  case 2: // PERMISSION_DENIED
    alert( &quot;Permission: denied&quot; );
    break;
}
</pre>
<p>Try it: <a href="javascript: demoCheckPermission()">Check Permission</a></p>
<p>Unless you skipped ahead and tried the next bit of code, the answer is &#8220;No&#8221; my site doesn&#8217;t have permission to display notifications.</p>
<h3>Requesting Permission</h3>
<p>So before we do anything we need to ask for permission.</p>
<p>This method will only work when responding to a user gesture. Which means you can call it as a direct response to an action taken by the user; but you can&#8217;t call it (for example) on the response to an Ajax function. So if you wanted to call it when your Ajax call returns or when a timer fires, you&#8217;re out of luck. You need to request permission before then.</p>
<pre class="brush: jscript; title: ; notranslate">
webkitNotifications.requestPermission();
</pre>
<p>Try it: <a href="javascript: demoRequestPermission()">Request Permission</a></p>
<h3>Creating and Showing Notification</h3>
<p>Notably, showing a standard browser alert dialog when permission is denied is a terrible user experience. Don&#8217;t do that! This is just for demo purposes.</p>
<pre class="brush: jscript; title: ; notranslate">
if ( webkitNotifications.checkPermission() == 0 )
{
  var iconImageUrl = &quot;http://www.example.com/foo.png&quot;;
  var title = &quot;Hello World&quot;;
  var subTitle = &quot;This is a sample desktop notification.&quot;

  var notification = webkitNotifications.createNotification( iconImageUrl, title, subTitle );
  notification.show();
}
else
{
  alert( &quot;Please request permissions first.&quot; );
}
</pre>
<p>Try it: <a href="javascript: demoNotify()">Show Notification</a></p>
<p>The new notification looks something like this (for those of you not using Chrome and want to see what I am talking about):</p>
<div id="attachment_620" class="wp-caption alignnone" style="width: 318px"><a href="http://andrewcurioso.com/wp-content/uploads/2011/01/Screen-shot-2011-01-27-at-11.30.06-AM.png"><img src="http://andrewcurioso.com/wp-content/uploads/2011/01/Screen-shot-2011-01-27-at-11.30.06-AM.png" alt="Andrew sent you a message" title="Example Google Chrome Notification" width="308" height="80" class="size-full wp-image-620" /></a><p class="wp-caption-text">Example Notification (Google Chrome on OS X)</p></div>
<h3>Creating and Showing an HTML Notification</h3>
<p>You can also create a notification by passing in a URL.</p>
<pre class="brush: jscript; title: ; notranslate">
if ( webkitNotifications.checkPermission() == 0 )
{
  var url = &quot;http://www.example.com/notification.html&quot;;
  var notification = webkitNotifications.createHTMLNotification( url );
  notification.show();
}
else
{
  alert( &quot;Please request permissions first.&quot; );
}
</pre>
<p>Try it: <a href="javascript: demoHtmlNotify()">Show Notification</a></p>
<p>At first this seems like a terrible idea. It could be yet another way to have annoying advertisements pop up on a site. But it&#8217;s not as bad as it sounds since the user has to explicitly allow the notifications and they can be turned off at any time.</p>
<h3>One Final Example</h3>
<p>Now, you probably don&#8217;t want the notification to pop up and stay there forever. So, you can auto-hide it using a timer.</p>
<pre class="brush: jscript; title: ; notranslate">
if ( webkitNotifications.checkPermission() == 0 )
{
  var iconImageUrl = &quot;http://www.example.com/foo.png&quot;;
  var title = &quot;Hello World&quot;;
  var subTitle = &quot;This is a sample desktop notification.&quot;

  var notification = webkitNotifications.createNotification( iconImageUrl, title, subTitle );
  notification.show();
  setTimeout( function() { notification.cancel() }, 10000 );
}
else
{
  alert( &quot;Please request permissions first.&quot; );
}
</pre>
<p>Try it: <a href="javascript: demoTimerNotify()">Show Notification</a></p>
<h3>Wrapping it Up</h3>
<p>I hope someone found this useful. If you do anything cool with this library please let me know in the comments.</p>
<p class="pitfall">Note: this is an experimental API that only works in Google Chrome right now. The API may change at any time and may be different when other browsers decide to implement similar functionality. Use with caution. Always check to make sure <code>window.webkitNotifications !== undefined</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewcurioso.com/2011/01/ria-desktop-notifications-in-google-chrome/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>5 things about PHP 5.3 that make me smile</title>
		<link>http://andrewcurioso.com/2009/06/5-things-about-php-53-that-make-me-smile/</link>
		<comments>http://andrewcurioso.com/2009/06/5-things-about-php-53-that-make-me-smile/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 03:41:08 +0000</pubDate>
		<dc:creator>Andrew Curioso</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[early adopters]]></category>

		<guid isPermaLink="false">http://andrewcurioso.com/?p=89</guid>
		<description><![CDATA[Rest assured. Soon I will be writing &#8220;Things about PHP 5.3 that make me cringe&#8221; but for now I sing the praises of the latest release of PHP that that came out today. I&#8217;ve been playing with the new release for months and there are indeed many good things about it and many of them [...]]]></description>
			<content:encoded><![CDATA[<p>Rest assured. Soon I will be writing &#8220;Things about PHP 5.3 that make me cringe&#8221; but for now I sing the praises of the latest release of PHP that that came out today. I&#8217;ve been playing with the new release for months and there are indeed many good things about it and many of them have been a long time coming.</p>
<p>The other day I was reading the release notes and I couldn&#8217;t help but smile.<br />
<span id="more-89"></span></p>
<h3>1. New native MySQL driver</p>
<p>I&#8217;m saving the best for last. So bear with me. Lets get through the small grins before we get to the big toothy ones (or you can read ahead&#8230; you&#8217;re choice). PHP 5.3 ships with a new MySQL driver called mysqlnd. A database driver is responsible for making the actually connection from PHP to MySQL. The previous MySQL driver had some flaws. For one, it was license in a way that was not compatible with the PHP license. The new <em>MySQL Native Driver</em> has a more amicable license (which is big in the open source world). It also adds some experimental functionality including improved persistent connections. There is also a down side but that is for another post.</p>
</h3>
<h3>2. Host specific PHP INI configurations</h3>
<p>I previously worked on a hosted CMS and web publishing tool that had dozens of virtual hosts but only one php.ini. The new functionality allows to section off your PHP configuration to have a different configuration for every host or file path. I haven&#8217;t tried this one yet so I&#8217;m not sure how well it works. Try it out for yourself. There is a comment on <a href="http://www.php.net/">PHP.net</a> right now saying that it only works for CGI PHP and not for the CLI implementation.<br />
<span class="syntaxhighlighterContainer">
<pre class="brush: plain; title: ; notranslate">
[HOST=example.com]
error_reporting = E_ALL
display_errors = On
</pre>
<p></span><br />
Example from the PHP documentation.</p>
<h3>3. Shortcut ternary operator</h3>
<p>I had never considered this before. However, this saves a lot of time for rather repetitive code. Consider these three identical code snipits.<br />
<span class="syntaxhighlighterContainer">
<pre class="brush: php; title: ; notranslate">
&lt;?php
if ( $foo ) $x = $foo;
else $x = $bar;

$x = ( $foo ? $foo : $bar );
$x = ( $foo ?: $bar );
?&gt;
</pre>
<p></span></p>
<p>The third method is the new shortcut. It reads simply: &#8220;if foo than foo else bar.&#8221; I am still waiting for the first time for this to be useful. The biggest issue I see is that in the above example $foo cannot legitimately be anything that evaluates to false. As a result it is best used for variables that should be non-empty strings or non-zero numbers.</p>
<h3>4. Date math</h3>
<p>The DateTime class now has several new methods in it for dealing with date arithmetic. It puts an end to manually converting to timestamps and back to dates again. It works very simply:<br />
<span class="syntaxhighlighterContainer">
<pre class="brush: php; title: ; notranslate">
&lt;?php
$date = new DateTime('2009-06-30 09:00:00');
$date-&gt;sub('P5D'); // Subtract five days
echo $data-&gt;diff( new DateTime() )-&gt;format('%d').' days ago';
?&gt;
</pre>
<p></span><br />
The new DateTime methods and the new DateInterval class (returned from and passed to math functions) aren&#8217;t very well documented because they are so new.<br />
It is worth noting that the format methods are different in the two classes. Intervals require a percentage (%) in front of placeholders. Watch out for that.</p>
<h3>5. Closures</h3>
<p>Closures are one of the best parts of PHP 5.3. At first I wasn&#8217;t very excited about them. I use closures constantly in Javascript but in a stateless HTTP request situation they appear less useful. But then I got into it. They are improved methods of dealing with lambda-functions. In other words, they are functions that are nameless and can be assigned to variables. In actuality they are classes.<br />
<span class="syntaxhighlighterContainer">
<pre class="brush: php; title: ; notranslate">
&lt;?phpi
$y = 10;
$x = function($number) use ( &amp;$y ) {
  return $number * $y;
};
$y = 100;
echo $x(8); // Output: 800
?&gt;
</pre>
<p></span><br />
This is the point at which a lot of PHP programmers would pause. Did I say they are classes? Since when can you call a class like it was a function? Since PHP 5.3 you can! . You do it by defining the &#8220;_invoke&#8221; magic method. Like so:<br />
<span class="syntaxhighlighterContainer">
<pre class="brush: php; title: ; notranslate">
&lt;?php
class testInvoke {
  public function __invoke( $x ) { echo &quot;Hello $x&quot;; }
};
$x = new TestInvoke();
echo $x('world'); // outputs &quot;Hello World&quot;
?&gt;
</pre>
<p></span><br />
This is by far one of the coolest new features in PHP 5.3. It opens a whole new world of possibilities for clean / manageable code.</p>
<h3>Bonus Things</h3>
<h4>5.1. New magic method for matching calls to static methods</h4>
<p>For a while now we have been able to define the magic method &#8220;__call&#8221; in our classes that will be executed if you try to call a method in a class instance that does not exist. Now the &#8220;__callStatic&#8221; method does the same thing only for methods of static classes.</p>
<h4>5.2. Late static binding</h4>
<p>Late static binding is a long time coming. In fact, this has tripped me up in several projects. In simplest terms late binding is waiting to determine what object a method or member variable belongs to until it is called. Late static binding in PHP, as its name indicates, applies this concept to static methods and members variables in PHP. The PHP.net website bests describes in on the <a href="http://us.php.net/lsb">manual page for late static binding</a>.</p>
<h4>5.3. E_DEPRECATED</h4>
<p>Here is a tip for everyone: if you are developing open source PHP software you should develop it in E_STRICT mode. This new E_DEPRECATED flag is actually part of E_ALL which sends a strong message that you shouldn&#8217;t be using these depreciated functions. I am a huge fan of anything that helps us write better code.</p>
<p>I hope everyone got through this post just fine. It is a long one. Leave comments (the comment section is OpenID enabled).</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewcurioso.com/2009/06/5-things-about-php-53-that-make-me-smile/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

