Wednesday, December 02, 2009

Locking a Mac

Leaving your mac sitting logged in on your desk is not very secure... is there an easy way to lock access to your machine when you step away? Unfortunately there is no ctrl-L style key combination built in, but you can get the same effect using the Screen Saver and hot corners.

  1. Open System Preferences, and move into the Desktop & Screen Saver preference pane.

  2. Click the Hot Corners button and have the screen saver start when you move the mouse to one of the four corners of your screen. I use the top left corner. Then click OK, and Show All to return back to the System Preferences window.
  3. Now open the Security preference pane.
  4. Finally set the Require password n seconds after sleep or screen saver. I use the 5 seconds setting as this gives you a few of seconds to move the mouse when the screen saver kicks in when you are reading a document or similar.
  5. Now when its coffee time just move your mouse to the appropriate hot corner and your screen saver will lock your computer.


Monday, November 09, 2009

Regex for Tracing

I've been working on SwinGame, and one of the tasks has been to add tracing code to the core to make it easier to debug problems. This involves adding TraceEnter and Trace exit calls to each procedure in the code.

To avoid having to do this by hand I am using a Regular Expression in TextMate to find procedures in the code, and replace them with a version that includes the injected trace enter and exit code. The regex I am using is shown below. It will work with a maximum depth of four begin/end groups... so its not completely automatic, but is a good start.

(function |procedure )(.*?)(;(\n|.)*?begin)((\n|(begin(\n|(begin(\n|(begin(\n|(begin(\n|.)*?end)|.)*?end)|.)*?end)|.)*?end)|.)*?)(\n end;)
This is then replaced using the following replace text. The $1 values are the groups that are matched in the regular expression. This enables me to place the procedure name, parameters and return type in the traced output ($2). It also ensures that all of the code from the program is output in the right spot.
$1$2$3
{$IFDEF TRACE}
TraceEnter('sgCamera', '$2', '');
{$ENDIF}
$5
{$IFDEF TRACE}
TraceExit('sgCamera', '$2', '');
{$ENDIF}
$15
This regular expression converts the following code...
function VectorFrom(x, y: Single): Vector; overload;
begin
result := VectorFrom(x, y, false);
end;
into this code which now has the tracing details added.
function VectorFrom(x, y: Single): Vector; overload;
begin
{$IFDEF TRACE}
TraceEnter('sgCamera', 'VectorFrom(x, y: Single): Vector', '');
{$ENDIF}

result := VectorFrom(x, y, false);

{$IFDEF TRACE}
TraceExit('sgCamera', 'VectorFrom(x, y: Single): Vector', '');
{$ENDIF}
end;
This should save me some time... though a real parser trace injector would be great!

Friday, October 09, 2009

Finding Menu Options

Another small feature of MacOS that I use often is the help search feature. This searches for the text you type in the program's menu options. The image here shows searching for "Picture" in Word. Selecting one of the found options opens the menu and a pointer indicates where the option is. You can then either click the menu or just execute it directly from the help itself.


This has actually changed the way I use the menu itself. I no longer try to remember where a menu option is. Instead I use the help to search and execute the option.

Friday, September 25, 2009

Dictionary Mac Tip

A few people I know have recently switched to using Macs, so I thought I would try to put up Mac related tips for them here on my blog. I'll try to do one each week, but... we'll see :).


One cool feature of Mac OS is the ability to use the dictionary to lookup words in many applications (any that use the basic mac text rendering - so not office for example). I find this useful when reading web sites and when writing documents. Try hovering the mouse over any word and pressing Command + Control + D. You should get a drop down that shows you the words details from the dictionary. The drop down also lets you look the word up in the thesaurus.

Friday, September 11, 2009

SDL + Objective-C Garbage Collection

Today I had another try at getting a version of SDL 1.2 with support for garbage collection. I got a bit further this time... I managed to get SDL to compile for 10.5 (and 10.6 Snow Leopard) with gc support turned on. My games run with the new framework as long as -fobj-gc isn't supported or required by the application... The games start with garbage collection, but don't it seems that there is an issue loading LiveType.

I'll have to look into it again later... but if you have any ideas let me know! (happy to provide compiled SDL framework for anyone interested in helping)




Wednesday, September 09, 2009

Setting the title of a slide...

I've been playing around with two different presentation tools and found the different approaches to scripting to be quite interesting. The two scripts are shown below.


tell application "A"

set title of (current slide of first slideshow) to "Hello World"

end tell



tell application "B"

activate

set theIndex to slide index of slide of view of active window

set selectedSlide to slide theIndex of active presentation

set content of text range of text frame of shape 1 of selectedSlide to "Hello World"

end tell


The two scripts both set the title of the current slide to "Hello World". Its interesting to note that while "B" has more features the script is quite brittle, things like selecting the slide in the outline cause it to fail to select the current slide.

and the moral of the story is... "don't over engineer your code... keeping things simple with clean abstractions is always better"

Tuesday, May 12, 2009

Explore Regex

I've been playing around with the Google Web Toolkit, and it looks very interesting. As a small project I created a Regular Expression testing web site (see http://exploreregex.appspot.com/). This uses a simple regular expression highlighting service that you post sample data and a regex, and it returns HTML formatted data indicating the matched expressions. This all works asynchronously, which the GWT makes easy...


Next will be to add in some of the AppEngine features...