Blog posts

Jul 06

Name that function: Ternary operator

Written: Jul 6th 2008, 19:28

varName = (conditional expression) ? valueIfTrue : valueIfFalse;

So many times I have been searching for this way of setting av varible, and know it turns up it got a name:  Ternary operator.

Next time I have forgot the way of formating it, at least I know what to “Google” for.

Discovered it in ActionScript 3.0 Cookbook, which BTW is one of the best computer books I have ever bought.

Permalink for Name that function: Ternary operator
May 26

Partly support for Flash XML parsing in Adobe Air JavaScript

Written: May 26th 2008, 22:46

Working with both Ajax and Flash tecnologies I often miss the great support Actionscript has to the XML format.

Reading the Adobe Air for JavaScript Developer – Pocket Guide I saw some examples of using flash objects in JavaScript. Curious if I also could use the XML parser, I did some testing.

And yes, you can use the parser. But before you can parse it with window.runtime.XML you have to take it via the old window.runtime.flash.xml.XMLDocument() function. 

And unfortunately you can call any function on it i.e. XMLlist.length()

Here is the JavaScript code:

&lt;script src="js/AIRAliases.js" type="text/javascript"&gt;&lt;/script&gt;<br>&lt;script type="text/javascript"&gt;<br>	// Var that holds the data loaded<br>	var xml_doc;<br>	// The function that starts the asynchronously reading of the file<br>	function doLoad() { <br>		var file = air.File.applicationDirectory.resolvePath('rss.xml' ); <br>		stream = new air.FileStream(); <br>		stream.addEventListener( air.ProgressEvent.PROGRESS, doProgress ); <br>		stream.openAsync( file, air.FileMode.READ ); <br>	} <br>	// Eventlistener for the fileloading<br>	function doProgress( event ) { <br>		var data = stream.readMultiByte( stream.bytesAvailable, "utf-8" ); <br>		xml_doc += data;<br>		if( event.bytesLoaded == event.bytesTotal ) { <br>			stream.close();<br>			// Call the parse function when fileloading is completed<br>			parseXML();<br>		} <br>	}<br>	function parseXML() { <br>		var result = new window.runtime.flash.xml.XMLDocument();<br>		result.ignoreWhite = true;<br>		result.parseXML(xml_doc);<br>		var myXML = new window.runtime.XML(result.lastChild);<br>		alert(myXML.channel.item[2].title);<br>	}<br>&lt;/script&gt; 

Why: Today most webservices have a growing support  for JSON, but still XML is the most widely spread format. Working with XML files in Javascript can be a little troublesome, and often you want to use an external library for the parsing.

Permalink for Partly support for Flash XML parsing in Adobe Air JavaScript
May 09

Using Flex SDK on mac

Written: May 9th 2008, 14:17

Your first Flex application with TextMate

Adobe recently made Flex opensource. That mean that you don’t have to use their Flex Builder in order to make Flex-apps.

This is a quick intro in how to use Flex with Textmate on mac.

Download the Flex SDK

You can download the Flex SDK from Adobe’s site. Place it whereevery you want, but be sure to make it available in your Path:

/Users/gerhard/.bashrc

export PATH; PATH="/Developer/SDKs/air_sdk/bin/:/Developer/SDKs/flex_sdk_3/bin/:/Developer/Tools:/Developer/Applications:/usr/local/bin:/usr/local/subversion/bin:$PATH"<br>alias flex="mxmlc"

I also added a alias for the compiler, located inside the bin/ dir of the SDK.

Download the TextMate bundle for AS3 and Flex

The ActionScript 3 Bundle and the Flex Bundle can be downloaded from TextMates Repository at: http://macromates.com/svn/Bundles/trunk/Review/Bundles/ (Use the SvnX app for mac to access these). Install this and you are ready to start developing in Flex.

Mini tutorial – your first Flex-app with TextMate

Create a new file in TextMate, and name it FlexTest1.mxml:

&lt;?xml version="1.0"?&gt; <br>&lt;!-- mxml/TriggerCodeExample.mxml --&gt; <br>&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"&gt;<br>    &lt;mx:Panel title="My Application" <br>        paddingTop="10" <br>        paddingBottom="10" <br>        paddingLeft="10" <br>        paddingRight="10" <br>    &gt; <br>        &lt;mx:TextArea id="textarea1"/&gt; <br>        &lt;mx:Button label="Submit" click="textarea1.text='Hello World';"/&gt; <br>    &lt;/mx:Panel&gt; <br>&lt;/mx:Application&gt; <br>

The ActionScript 3 bundle will provide you with a buildin “Build (mxmlc)” command, but I prefer just compiling the files direct with Terminal.app:

gersh:~/Desktop/Adobe Flex/HelleWorldFlex gerhard$ mxmlc FlexTest1.mxml<br>Loading configuration file /Developer/SDKs/flex_sdk_3/frameworks/flex-config.xml<br>/Users/gerhard/Desktop/Adobe Flex/HelleWorldFlex/FlexTest1<br>.swf (164508 bytes)<br>gersh:~/Desktop/Adobe Flex/HelleWorldFlex gerhard$ 

If you have installed the last version of flash-player you will be able to open the .swf file in Finder.

Permalink for Using Flex SDK on mac
Apr 09

CSS Naked Day

Written: Apr 9th 2008, 13:11

This is the third year of CSS Naked Day, and the first time I joint it. So today my stylesheets are turned off.

CSS Naked Day

Permalink for CSS Naked Day
Mar 08

Easy Excel export from PHP

Written: Mar 8th 2008, 09:10

Here is a simple way of exporting data to excel documents. With utf-8 encoding you can use special nordic letters like ø, æ and å.

<span class="Apple-style-span" style="font-family: Arial; line-height: 14px; white-space: normal;"><div>&lt;?php</div><div>header("Expires: 0");</div><div>header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");</div><div>header("Cache-Control: no-store, no-cache, must-revalidate");</div><div>header("Cache-Control: post-check=0, pre-check=0", false);</div><div>header("Pragma: no-cache");</div><div>header("Content-type: application/vnd.ms-excel;charset:UTF-8");</div><div>header("Content-Disposition: attachment; filename=filename.xls"); </div><div>print "\n"; // Add a line, unless excel error..</div><div>?&gt;</div><div>&lt;table border="1"&gt;</div><div><span class="Apple-tab-span" style="white-space:pre">	</span>&lt;tr&gt;</div><div><span class="Apple-tab-span" style="white-space:pre">		</span>&lt;th&gt;header 1&lt;/th&gt;</div><div><span class="Apple-tab-span" style="white-space:pre">		</span>&lt;th&gt;header 2&lt;/th&gt;</div><div><span class="Apple-tab-span" style="white-space:pre">	</span>&lt;/tr&gt;</div><div><span class="Apple-tab-span" style="white-space:pre">	</span>&lt;tr&gt;</div><div><span class="Apple-tab-span" style="white-space:pre">		</span>&lt;td&gt;data 1&lt;/td&gt;</div><div><span class="Apple-tab-span" style="white-space:pre">		</span>&lt;td&gt;data 2 - nordic letters æ, æ, å&lt;/td&gt;</div><div><span class="Apple-tab-span" style="white-space:pre">	</span>&lt;/tr&gt;</div><div>&lt;/table&gt;</div></span>

Its really all about the headers. For the body of the document, Excel is not very choosy, we just hand it a regular HTML table, and thats it. 

Permalink for Easy Excel export from PHP
Jan 13

Zoho Creator - webapps for your mom

Written: Jan 13th 2008, 18:04

 Zoho Creator lets you export data in many formats

We all got these lists that we keep. Maybe its in a Excel sheet or in a database. Myself I have two: one for my workouts and one for novels I have read. The first is in a database, and the latter is in a Google spreadsheet. Until now it has been a hassle updating them.

But now I have found the perfect tool for these small personal lists: Zoho Creator!

Zoho is a suite of online applications (they compete with Google Docs), and of their tools is Creator, a online web-app “web-app” maker. You create Forms where you input data and Views where you view and filter data. It also supports relationship (they call it Lookup fields) that lets you link between different databases.

Zoho Creator has also its own scripting language named Delugescript that you can use, is support exporting in a variety of formats, and embedding of forms in extern sites. Go check it of on creator.zoho.com

Permalink for Zoho Creator - webapps for your mom
Dec 14

Add your CakePHP project to Google Code

Written: Dec 14th 2007, 20:04

Want to use Subversion with your CakePHP project. This is how you do it:

For developing I got a local copy of my project. Unless you got Subversion installed on your webserver, you have to start importing the local one. Mine in located here:

/Users/gersh/Sites/cakephp/APPS/gersh

  1. First you have to move your config file outside of your project tree since your project will have public access on Google Code. To do this you simply copy database.php out and rather include it by putting these lines inside your app/config/database.php file:
    (?php<br>include dirname(__FILE__) . '/../../database.php.inc';
  2. Google Code has already created a regualar Subversion structure:
    /branches (empty)
    /tags (empty)
    /trunk (content of cakephp app folder goes here)
  3. To import your project, open Terminal.app, and from inside of your /app folder run this command:
    svn import  https://gersh-no.googlecode.com/svn/trunk <br>  --username username -m "Initial import"
  4. Now that your project is hosted at Google Code, you can use SvnX – a mac SVN client to checkout your project. Note that it is a bug in SvnX with importing from https protocol, so you have to do a svn list command. Just accept it permantly
    svn list https://projectname.googlecode.com/svn/trunk/
  5. You might need to reset the permissions for your app/tmp directory in order to make the cache to work:
    chmod -R 777 tmp
Okay, so now know how to share you project with the world!

Permalink for Add your CakePHP project to Google Code
Dec 03

Wordpress as CMS, custom database and $_Get variables

Written: Dec 3rd 2007, 20:58


Screenshot Ironman.no - made with Wordpress


The great blog platform Wordpress does more than serve blogs. Lately I used it, and it’s build in classes for a new norwegian sports site: Ironman.no – hosting all norwegian triathlon results throughout history. Among the things we did there, was serving data from custom databases and ability to search and browse this data.

Permalink for Wordpress as CMS, custom database and $_Get variables
Nov 25

Tutorial: Convert RSS to JSON with PHP and import the JSON into Flash with AS 2

Written: Nov 25th 2007, 21:48

Recently we had a customer at the office who wanted a news feed from a related site displayed on their homepage. As a design element we wanted to extract the first image in the description part of each news item in the feed and display it in a separate container inside the flash file.

Permalink for Tutorial: Convert RSS to JSON with PHP and import the JSON into Flash with AS 2
Nov 05

Leopard Core Data bug affect Worktimer

Written: Nov 5th 2007, 22:01

Last weekend I got a mail from a Worktimer user, concerning a possible bug running Worktimer in the new Mac OS X Leopard. It happens when you open a document, and save it without making any changes. When you reopen the document all your data is lost.

Have been working day and night the last days trying to find the cause, unfortunately without any success. Now it turns out its in Leopard the bug is located, and it has to do with their Core Data framework (that Worktimer use).

Lets stay tune for Software Update from Apple, and meanwhile don’t double-save your document.

Read more about the bug here

Permalink for Leopard Core Data bug affect Worktimer

Page 3 of 4

<< previous | 1 | 2 | 3 | 4 | next >>