Oct 10 2012

Generator

My implementation of a very useful tool

Read More

Oct 10 2012

Book information:

Author: Diego Cantor and Brandon Jones
Publisher: Packt Publishing
ISBN: 978-1849691727

Review

I was asked to review this book about a month ago. I don’t have any background in 3d programming and the mathematics involved, so I was curious if this book could help me grasp the firm knowledge needed to program 3d applications for the web.

The book is written for JavaScript developers who are interested in 3D web development. It is a step–by–step tutorial that includes complete source code for all of the examples covered. The first chapters introduce how to use javascript to setup a WebGL context load model data, encode and decode JSON objects and how to setup a project.

The graphic chapters that followed are in my opinion not very suitable for complete beginners. The book assumes that you already have knowledge about 3d programming and already familiar with basic concepts like, shaders, normals and reflections.

The examples where useful to experiment with different settings and to see how to make use of existing library’s so you don’t have to invent the wheel. I would expect more boilerplate code to get you quickly up and running.

Overall it is a really good book. It is not 100% suitable for the complete beginner. The topic is hard to grasp, but the book tries to make it as simple as possible, but it is not easy to read. This book can be useful and should be used together with other OpenGL/gamedesign books.

If you are prepared for the technical stuff it is a good introduction to WebGL.

Jul 03 2012

Today I wanted to experiment with Magento somewhat. A year or so back I installed Magento out-of-the-box on my osX apache, php, mysql server.

Okay, this shouldn’t be too hard or..
- Got Magento latest version… check
- Unpacked it to localhost/magento… check
- Created a database… check
- Fired up the web browser to localhost/magento.. check

But whaaat after finishing the localization it stated that it uses libmcrypt. Okay nice.. We’ll have to fix that..

Lib mcrypt for php

After a bit of searching I stumbled upon Michael Gracie’s blog about setting up mcrypt for php nice, just what I needed ;-) Before I found this, I had followed about 3 other guides without succes. Michael keeps it clean and simple just how I like it.

So.. on with the Magento installation.

Installing Magento

After making directories writable and filling out all the required steps. I had te create username password en hash code. AT LAST! The system gives me the choice: frontend or backend. So I chose the backend to see what changed but.. darn I can’t login.

After investigating somewhat I discovered that magento can’t set any cookies on domains without dots. Thus localhost/magento/admin/ doesn’t work but 127.0.0.1/magento/admin/ will. After trying to make some changes to /etc/hosts renaming localhost to localhost.com. Which broke all other sites I run locally. I resorted to reinstalling Magento from scratch (throw away db and replacing fies with their original versions). This time when starting the installation procedure I went to 127.0.0.1/magento/ which did the trick.

Now I’m able to log into the Magento backend. And can start devving on my local box :-)

Are you getting errors when loading XML with Internet Explorer? Ever wanted to place a piece of XML in an HTML page and load it up with a GET request? Having trouble with the mime type of XML documents?

Since IE’s problem is its xml parser chokes on xml files that are not passed down using the correct “text/xml” header.. This jQuery plugin will get you up and running quickly.

Plugin code


(function ($){
 
    $.fn.getXML = function (url, callback) {
 
    	$.ajax({
            type: "GET",
            url: url,
            dataType: "xml",
            success: function(xmlDoc, status){
                callback(xmlDoc);
            },
            complete: function(xhr, status){
                if(status == 'parsererror'){
                    xmlDoc = null;
                    if(window.DOMParser){
                        parser = new DOMParser();
                        xmlDoc = parser.parseFromString(xhr.responseText, "text/xml");
                    } else { // Internet Explorer
                        xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
                        xmlDoc.async = "false";
                        xmlDoc.loadXML(xhr.responseText);
                    }
                    callback(xmlDoc);
                }
            },
            error: function(xhr, status, error){
                console.log(status, error);
            }
        });
 
    };
 
})(jQuery);

Usage

You can both use inline function or an external function to parse the results of the ajax request.


$(function(){

	//inline function
	$.getXML('test.xml', function(data){
		alert(data);
	});
	
	
	//external function
	$.getXML('test.xml', parseXML);
	
	function parseXML(data){
		alert(data);
	}

});

That’s it!

Mar 06 2011

IE 8 LogoSince google dropped support for IE6 beginning 2010 a lot of companies followed their lead.

Now over a year later Microsoft creates a new website: http://www.ie6countdown.com which is dedicated to watching Internet Explorer 6 usage drop to less than 1% worldwide, so more websites can choose to drop support for Internet Explorer 6, saving hours of work for web developers… LoL beter late than never.

As a developer I try to develop cross browser/cross plaform websites. In that respect I spent a lot of hours debugging and hacking markup, css and javascript in IE6. My employer doesn’t care about the fact that this browser is over a decade old and still wants pixel-perfect designs with state-of-the-art functionality and behaviors arghh.

The fact that a lot of people (mainly marketing and management) in the company still view their pages with IE6 mainly because the guys and galls from workplace management can’t install a newer version of this darn piece of software. Yo guys and galls check out this page and read the “What about corporate users?” section..

I hope that the site will encourage big companies to put some extra effort in replacing this old and outdated browser.

If you are viewing this post with IE6….pretty please with sugar on top donwload:

Molehill is the codename for the upcoming Flash version. The 3D capabilities enabled by the new APIs will also be available through ActionScript 3D frameworks, such as Alternativa3D, Away3d, CopperCube, Flare3D, Minko, Sophie3D or Yogurt3D.

Very impressive check out some Molehill demo’s:

Get the Flash Player Incubator and check out:

Mar 02 2011

ApacheCaching is great for production sites and should be configured. However during development it can be a royal PITA. Below a few rules you can put in your .htaccess file when your site is on apache hosting. The benefits of caching your site are not always obvious:

  • Optimise site performance
  • Improve conversion rate
  • Bandwith saving through gzip and http compression

Editing .htaccess

First of all add MIME types using mod_mime.c. The AddType directive maps the given filename extensions onto the specified content type. MIME-type is the MIME type to use for filenames containing extension. This mapping is added to any already in force, overriding any mappings that already exist for the same extension.

<IfModule mod_mime.c>
    AddType text/css .css
    AddType application/x-javascript .js
    AddType text/html .html .htm
    AddType text/richtext .rtf .rtx
    AddType image/svg+xml .svg .svgz
    AddType text/plain .txt
    AddType text/xsd .xsd
    AddType text/xsl .xsl
    AddType text/xml .xml
    AddType video/asf .asf .asx .wax .wmv .wmx
    AddType video/avi .avi
    AddType image/bmp .bmp
    AddType application/java .class
    AddType video/divx .divx
    AddType application/msword .doc .docx
    AddType application/x-msdownload .exe
    AddType image/gif .gif
    AddType application/x-gzip .gz .gzip
    AddType image/x-icon .ico
    AddType image/jpeg .jpg .jpeg .jpe
    AddType application/vnd.ms-access .mdb
    AddType audio/midi .mid .midi
    AddType video/quicktime .mov .qt
    AddType audio/mpeg .mp3 .m4a
    AddType video/mp4 .mp4 .m4v
    AddType video/mpeg .mpeg .mpg .mpe
    AddType application/vnd.ms-project .mpp
    AddType application/vnd.oasis.opendocument.database .odb
    AddType application/vnd.oasis.opendocument.chart .odc
    AddType application/vnd.oasis.opendocument.formula .odf
    AddType application/vnd.oasis.opendocument.graphics .odg
    AddType application/vnd.oasis.opendocument.presentation .odp
    AddType application/vnd.oasis.opendocument.spreadsheet .ods
    AddType application/vnd.oasis.opendocument.text .odt
    AddType audio/ogg .ogg
    AddType application/pdf .pdf
    AddType image/png .png
    AddType application/vnd.ms-powerpoint .pot .pps .ppt .pptx
    AddType audio/x-realaudio .ra .ram
    AddType application/x-shockwave-flash .swf
    AddType application/x-tar .tar
    AddType image/tiff .tif .tiff
    AddType audio/wav .wav
    AddType audio/wma .wma
    AddType application/vnd.ms-write .wri
    AddType application/vnd.ms-excel .xla .xls .xlsx .xlt .xlw
    AddType application/zip .zip
</IfModule>

Next we add expire headers to the file types. Mod_expires.c controls the setting of the Expires HTTP header in server responses. The expiration date can set to be relative to either the time the source file was last modified, or to the time of the client access.

<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType text/css A31536000
    ExpiresByType application/x-javascript A31536000
    ExpiresByType text/html A3600
    ExpiresByType text/richtext A3600
    ExpiresByType image/svg+xml A3600
    ExpiresByType text/plain A3600
    ExpiresByType text/xsd A3600
    ExpiresByType text/xsl A3600
    ExpiresByType text/xml A3600
    ExpiresByType video/asf A31536000
    ExpiresByType video/avi A31536000
    ExpiresByType image/bmp A31536000
    ExpiresByType application/java A31536000
    ExpiresByType video/divx A31536000
    ExpiresByType application/msword A31536000
    ExpiresByType application/x-msdownload A31536000
    ExpiresByType image/gif A31536000
    ExpiresByType application/x-gzip A31536000
    ExpiresByType image/x-icon A31536000
    ExpiresByType image/jpeg A31536000
    ExpiresByType application/vnd.ms-access A31536000
    ExpiresByType audio/midi A31536000
    ExpiresByType video/quicktime A31536000
    ExpiresByType audio/mpeg A31536000
    ExpiresByType video/mp4 A31536000
    ExpiresByType video/mpeg A31536000
    ExpiresByType application/vnd.ms-project A31536000
    ExpiresByType application/vnd.oasis.opendocument.database A31536000
    ExpiresByType application/vnd.oasis.opendocument.chart A31536000
    ExpiresByType application/vnd.oasis.opendocument.formula A31536000
    ExpiresByType application/vnd.oasis.opendocument.graphics A31536000
    ExpiresByType application/vnd.oasis.opendocument.presentation A31536000
    ExpiresByType application/vnd.oasis.opendocument.spreadsheet A31536000
    ExpiresByType application/vnd.oasis.opendocument.text A31536000
    ExpiresByType audio/ogg A31536000
    ExpiresByType application/pdf A31536000
    ExpiresByType image/png A31536000
    ExpiresByType application/vnd.ms-powerpoint A31536000
    ExpiresByType audio/x-realaudio A31536000
    ExpiresByType application/x-shockwave-flash A31536000
    ExpiresByType application/x-tar A31536000
    ExpiresByType image/tiff A31536000
    ExpiresByType audio/wav A31536000
    ExpiresByType audio/wma A31536000
    ExpiresByType application/vnd.ms-write A31536000
    ExpiresByType application/vnd.ms-excel A31536000
    ExpiresByType application/zip A31536000
</IfModule>

Then we set the mod_deflate module. This module provides the DEFLATE output filter that allows output from your server to be compressed before being sent to the client over the network. To set the correct gzip directions there has to be a browser match.

<IfModule mod_deflate.c>
    <IfModule mod_setenvif.c>
        BrowserMatch ^Mozilla/4 gzip-only-text/html
        BrowserMatch ^Mozilla/4\.0[678] no-gzip
        BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
        BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
    </IfModule>
    <IfModule mod_headers.c>
        Header append Vary User-Agent env=!dont-vary
    </IfModule>
    AddOutputFilterByType DEFLATE text/css application/x-javascript text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon
</IfModule>
<FilesMatch "\.(css|js)$">
    <IfModule mod_headers.c>
        Header set Pragma "public"
        Header set Cache-Control "public, must-revalidate, proxy-revalidate"
    </IfModule>
    FileETag MTime Size
    <IfModule mod_headers.c>
         Header set Author "Dotinga.com"
    </IfModule>
</FilesMatch>
<FilesMatch "\.(html|htm|rtf|rtx|svg|svgz|txt|xsd|xsl|xml)$">
    <IfModule mod_headers.c>
        Header set Pragma "public"
        Header set Cache-Control "public, must-revalidate, proxy-revalidate"
    </IfModule>
    FileETag MTime Size
    <IfModule mod_headers.c>
         Header set Author "Dotinga.com"
    </IfModule>
</FilesMatch>
<FilesMatch "\.(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|swf|tar|tif|tiff|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip)$">
    <IfModule mod_headers.c>
        Header set Pragma "public"
        Header set Cache-Control "public, must-revalidate, proxy-revalidate"
    </IfModule>
    FileETag MTime Size
    <IfModule mod_headers.c>
         Header set Author "J. Dotinga.com"
    </IfModule>
</FilesMatch>

More resources

Mar 01 2011

FLV logoWhen working with Flash video I always end up using extra time finishing a project. This is mainly because I get these project not so often. So everytime I have to create video content I have to brush up my as3 video skills.

In this posts I will point out a few pitfalls when doing a Flash as3 movie project.

Decide where the videocontent is placed

This is handy to know beforehand. It saves a lot of time and effort to do it first time right. Are you going to progressively download the movie or is it streaming? Does it come from a flash mediaserver? Know what you are working with before you start.

Create a prototype

Start with creating a prototype so you know the pitfalls. And you know the steps to recreate the experience. Afterwards you can tweak layout, performance etc.

When using Cue Points

FLV logoMake sure you export your movie as .flv. F4v doesn’t support cue points. Cue points are a feature of the FLV video container format. FLV is a proprietary format developed specifically to complement Adobe Flash.

Cue Point code

Handling cuepoints in ActionSctipt3 is easy once you know the drill. One of the simplest methods is to create a simple Object which processes the onCuePoint and onMetaData event handlers in ActionScript 3.0. You can see an example of this in the following code:

var customClient:Object = new Object();
customClient.onCuePoint = cuePointHandler;
customClient.onMetaData = metaDataHandler;

var myVideo:Video = new Video();
addChild(myVideo);

var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
ns.client = customClient;
myVideo.attachNetStream(ns);
ns.play("http://www.helpexamples.com/flash/video/cuepoints.flv");

function cuePointHandler(infoObject:Object):void
{
    trace("cuePoint");
}
function metaDataHandler(infoObject:Object):void 
{
    trace("metaData");
}

Or you can create a CustomClient class which handles the meta data and cuepoints.

package
{
	public class CustomClient 
	{
		public function onMetaData(info:Object):void 
		{
			trace("metadata: duration=" + info.duration + " width=" + info.width + " height=" + info.height + " framerate=" + info.framerate);
		}
		public function onCuePoint(info:Object):void 
		{
			trace("cuepoint: time=" + info.time + " name=" + info.name + " type=" + info.type);
		}
	}
}

These are the basics to start embedding video content.

Other resources

In this post I’m setting up a secure password management system which is accesible from anywhere with Windows and Mac (any OS will do).

When my Macbook Pro was stolen I succesfully changed all my account passwords whitin a day. I had backup copies of my passwords stored in my dropbox account. All I needed was another computer and access to my account. Here are the steps to keep your passwords safe and in the cloud.

DropboxI use a free Dropbox account to sync files that I access from multiple locations, using their secure web storage. It is incredibly convenient to develop something on my laptop, save it in my Dropbox folder, and access the files from my desktop or phone. Before, I would have emailed the files to myself.

Signup for a Dropbox account and download the client

Create an account first, then run the Dropbox Installer. From your browser’s Downloads window, double click the .dmg/.exe file that just downloaded. After downloading the client, follow the steps to install the client. Double click the Dropbox icon in your Applications folder or desktop to get all set up, and you’re good to go.

Keepass

Download and Configure Keepass(X)

Start Keepass(X). The very first step is creating a new password database. To create one, click ‘File – New…’ in the main menu. A window will appear, which prompts you for a master password and/or key file. The database will be encrypted with the password you enter here. The password you enter here will be the only password you’ll ever have to remember from on now. It should be long and built up of mixed characters. Keep in mind that when someone gets your database file and guesses the password, he could access all passwords you stored in the database.

Adding an entry

Time to store your passwords in the database! Right-click and choose ‘Add Entry…’. In this window you can now edit your entry: enter some title for it, an username, an URL, the actual password, etc. If you don’t need some of the fields, just leave them empty. When you’re done, click [OK].

You’ll see your new entry in the password list on the right now.

Putting it al together

When dropbox is installing the program creates a shared folder which is synced to internet (the cloud). This is default your public folder.

The final thing to do is move your Keepass(X) database and keyfile to your shared folder and it is synced automatically.

Edit a Photoshop scripting jsx file to export each layer as seperate file, with the layername as filename.

Today I needed to export every layer in a photoshop document as files. Photoshop has a default script for this. You can find it here: file -> scripts -> Export Layers to Files.

The only drawback is that the filename is composed from a prefix + number + layer name. And I want only the layername. What we have to do is edit the “Export Layers to Files.jsx” file. This is a javascript file that we can edit.

  • mac: /Applications/Adobe/Adobe\ Photoshop\ CS4/Presets/Scripts/
  • win: C:\Program Files\Adobe\Adobe Photoshop CS3\Presets\Scripts

Then open the file and search for “fileNameBody +=” and edit:

var fileNameBody = fileNamePrefix;
fileNameBody += "_" + zeroSuppress(i, 4);
fileNameBody += "_" + layerName;

to:

var fileNameBody = fileNamePrefix;
fileNameBody += layerName;

You have to make sure there are no duplicate layernames otherwise the script will overwrite these files. If you don’t want to edit this file you can download my version.