Archive for the 'Language' Category

December 10th 2007

Javascript Framework Speed Tests

A coworker just pointed out a cool JS speed test to me today. The folks over at MooTools have a handy dandy speed test to compare the top three JS framework libraries to each other. As you can see, Prototype seems to be optimized for Firefox, JQuery for IE and MooTools appears to be a nice middle ground for comparable performance cross browser.

http://mootools.net/slickspeed/

No Comments yet »

September 11th 2007

Auto Converting PHP Objects to Strings using the __toString() ‘Magic Method’

Ever wished there was a way to echo or print a PHP Object as if it were just a string and have it print something more usefull than Object id #1? In PHP5+ there is a Magic Method __toString() that will allow you to specify how you want your Object to react when converted to a string.

<?php
class Person{
  private $firstName="Brien";
  private $lastName="Wankel";
  private $age="30";
  ...
  public function __toString(){
      return "{$this->firstName} {$this->lastName}";
  }
}
$me = new Person();
echo("My name is {$me}"); // prints: My name is Brien Wankel
?>

No Comments yet »

August 26th 2007

Web Development With PLT Scheme

I just ran across this article about using PLT Scheme to write web applications. It’s a great read and a good introduction to Sceme and how it can be used to write “real” programs, not just academic assignments.

From time to time people ask how to develop for the web with PLT Scheme on the PLT mailing list. The quick answer is “Just as in any other language”, but that’s not how to get people hooked on Scheme. To write a decent web-application require knowledge of a range of subjects such as HTML, databases, servlets, and web-servers. For some reason there is a lack of tutorials on these subjects, so I have decided to make an attempt at writing, if not a complete tutorial, then an elaborate get-started example.

[Read the whole article at http://scheme.dk]
[part two: the view]
[part three: an intermezzo]
[part four: the control]

No Comments yet »

July 12th 2007

Learn Python in 10 Minutes

From http://www.poromenos.org/:

So, you want to learn the Python programming language but can’t find a concise and yet full-featured tutorial. This tutorial will attempt to teach you Python in 10 minutes. It’s probably not so much a tutorial as it is a cross between a tutorial and a cheatsheet, so it will just show you some basic concepts to start you off. Obviously, if you want to really learn a language you need to program in it for a while. I will assume that you are already familiar with programming and will, therefore, skip most of the non-language-specific stuff. The important keywords will be highlighted so you can easily spot them. Also, pay attention because, due to the terseness of this tutorial, some things will be introduced directly in code and only briefly commented on.

Go to the article >>

No Comments yet »

May 30th 2007

The One Line Cross-Browser Ajax Request Object

The simple task of getting a working XMLHTTPRequest object can quickly turn into a mess of if/then browser checking. With the help of one of my favorite operators, the ternary operator, this becomes a simple one-liner:

  reqObj = window.XMLHttpRequest
      ? new XMLHttpRequest() :
        new ActiveXObject("Microsoft.XMLHTTP");

There you go, it’s that easy? Now, of course, this is an extremely stripped down browser check, with no error checking, so depending on your need, this may not be the best way to go.

No Comments yet »

January 26th 2007

An easier way to do simple matches with PHP

Tired of trying to figure out that perfect Perl-style regular expression when all you need to do is a simple match? Well, toss away that ereg or preg_match call you’ve been working on for the last 20 minutes and use your new friend fnmatch(). fnmatch will let you match using POSIX shell command style patterns, which may be much much easier for a non regex guru to wrap their head around.

<?php
if (fnmatch("*gr[ae]y", $color)) {
  echo "some form of gray ...";
}
?>

This function is only available on POSIX compliant systems, so all you Windows PHP users are out of luck.

Enjoy!

2 Comments »

December 20th 2006

Marco Tabini: 5 PHP Performance Tips You Probably Don’t Want To Hear

From Marco Tabini’s blog, also available in the Dec. issue of php|architect

Search the Internet—Google or no Google—and you’ll find a number of “top five lists” of tips to improve the performance of your code. Most of these lists promise you the developer’s version of all gain and no pain: performance increases without the need for any changes to your code. Some of the suggestions are too good to be true, some are just plain wrong, and some will yield some modest form of performance increase.

Installing an opcode cache, however, is not going to save you from the depths of Hell when you’re trying to run a complex select statement over a table with ten million records and no indices, however. With all these “get performing quick” articles floating around the Web, I thought it might be interesting to write an article about the performance-enhancing tips you probably don’t want to hear about—that is, those that are most likely to produce measurable (and durable) results but do require some effort on your part.

Go to Marco’s blog to read the tips

No Comments yet »

November 20th 2006

Suppress errors in PHP function calls

Some run-time errors in PHP may cause sensitive information to be output to the browser. PHP provides as special operator, called the error suppression operator (@), as a way to stop these errors from being displayed. By placing ,@ before a function call, most errors will be suppressed. I say most because this operator will only suppress errors that for functions that use PHP’s built in error reporting functionalities.

For more information, check out the Error Control Operators section of the PHP manual.

No Comments yet »

November 14th 2006

Fun With Flickr Feeds

Flickr has some really great web services, one of the easiest to use is the feeds service. To grab a set of data from flickr in XML format, just open the following URL in your application:
http://api.flickr.com/services/feeds/photos_public.gne?tags=[comma separated tags here]

by default, the feeds are returned in “plain” XML format, to make things more interesting you can specify a format parameter

prefer PHP data? just:

<?php
  include_once("http://api.flickr.com/services/feeds/\
                    photos_public.gne?tags={$tags}&format=php");
  // broken up to fit format, but in practice leave this as one line
  // i now have a $feed array set with all the feed data:
  print_r($feed);
?>

or perhaps json:
to use the json (in javascript) you must first define a function called jsonFlickrFeed which takes in one object. This object will be your flickr feed data, then below that in your HTML head, you include the feed url as a javascript src file:

  <head>
    <title>Flickr Testbed</title>
    <script type="text/javascript">
      var photos = null;
      function jsonFlickrFeed(feedData){
        photos = feedData;
      }
    </script>
    <script type="text/javascript" src="http://api.flickr.com/services/feeds/\
            photos_public.gne?tags=toothbrush,red&format=json">
    </script>
  </head>
...

to view all the other feed formats, check out the formats section of the Flickr Feeds page.

No Comments yet »

November 1st 2006

More Crockford Online: Theory of the DOM

If you liked the “Advanced Javascript” presentation that i posted about last week, then you should enjoy another one of Douglas Crockford’s talks that has been made available online - Douglas Crockfords “Theory of the DOM”

An Inconvenient API: The Theory of the DOM - Part I

An Inconvenient API: The Theory of the DOM - Part II

An Inconvenient API: The Theory of the DOM - Part III

No Comments yet »

Next »