Thursday, November 11, 2010

Convert string with carriage returns to one line in php

I have a database string containing new lines characters (\n) and needed to print it out with no linebreaks -- since it was being printed as a javascript variable. This script does the trick:

$input = trim( preg_replace( '/\s+/', ' ', $input ) );

courtesy: http://www.codingforums.com/showthread.php?t=137009

Sunday, November 7, 2010

Print booklets on Mac

One feature that is missing on Mac Snow Leopard is the ability to print a booklet from a pdf. But here is a great free application that fills that void:

http://bit.ly/2JupkE

By the way, to print even and odd pages on a Mac you need to select the "Paper Handling" option in the "Preview" dropdown.

Thursday, November 4, 2010

Create AIR app without a taskbar icon

I needed to create a chromeless AIR app that would act like the the old Active Desktop in Windows -- and did not show a taskbar icon that a user could close. Here is how it was done:


Create a new AIR app (for which a taskbar icon is required). This app spawns a new application component based on mx:Window with the HTMLLoader in it. I used a separate component for this so it could function independently from the main app. Child apps in AIR do *not* require an icon so you can set the type=NativeWindowType.LIGHTWEIGHT on this new component when you open it. As soon as this new window opens it dispatches a complete event. The main window listens for the complete event and then closes itself -- taking the taskbar icon with it. Since (I believe) in Windows 7 the shortcut "Windows/M" works from the items in the task bar, the fact that the child app is not in the task bar prevents it from being minimized by the shortcut.

By the way, this seems to work only on Windows -- not Mac -- so a different solution would be required for that.

Thursday, October 28, 2010

Communicating between Javascript and Actionscript in an AIR application

Using the HTMLLoader class you can communicate between javascript and actionscript in the same application. This means that you can trigger AS3 functions from a loaded HTML page through javascript (and vice versa). Here is a quick sample:

// AS3 code:

var windowBounds:Rectangle = new Rectangle(0,0,1024,768);
var htmlLoader:HTMLLoader = HTMLLoader.createRootWindow(true, null, false, windowBounds );
htmlLoader.runtimeApplicationDomain = ApplicationDomain.currentDomain;
htmlLoader.load(new URLRequest('myfile.html'));

htmlLoader.addEventListener(Event.COMPLETE, onComplete);

private function onComplete(e:Event):void{
// creates a new javascript function in the HTML page that map to the AS3 function
// you don't need to define these functions at all in the JS -- they become available automatically
htmlLoader.window.jsFunction = flashFunction;
}

private function flashFunction(msg:String):void{
trace("message: " + msg);
}


Once the onComplete() function runs, it creates the link between the newly created HTML javascript function and the AS3 function -- which can then be called directly in the HTML:

HTML code:

onclick="jsFunction('called from js');"

Wednesday, October 27, 2010

Round time to nearest 30 seconds

I had a requirement to round the time for a video (in seconds) to the nearest 30 seconds. Not being so strong in math, I am grateful to be better at Googling. So here it is for anyone else in a similar situation:

Math.round(myTime/30)*30

Awesome and simple!

Wednesday, October 20, 2010

Titanium gradient for buttonbar

Doesn't seem that the gradient works for the buttonbar either. So here is the workaround:

myButtonBar = Ti.UI.createButtonBar({
id:'buttonbar',
height:40,
backgroundColor:'#663399',
style:Titanium.UI.iPhone.SystemButtonStyle.BAR,
labels:['Close Keyboard >']
});

Just use a background color and the Titanium.UI.iPhone.SystemButtonStyle.BAR as the style -- and the app will create a gradient for you -- from lighter to darker.

Tuesday, October 19, 2010

Show and hide hidden files on a Mac

This command shows the hidden files in Finder on a Mac:

$ defaults write com.apple.finder AppleShowAllFiles TRUE
$ killall Finder

and this hides them again:

$ defaults write com.apple.finder AppleShowAllFiles FALSE
$ killall Finder