iPhone and memory leaks: two watch-out tips

The time I spent believing that my buffered input stream class had a leak because of two silly mistakes somewhere else could have easily been better employed. So I am happy to share my findings and spare other developers the same frustration. No rocket science here, just two simple anti-patterns. Continue reading “iPhone and memory leaks: two watch-out tips”

iPhone/iPad Simulator screenshots

I just found out about a convenient way of taking screenshots from the iPhone Simulator (which, incidentally, is also an iPad Simulator). Just run your application and when you get to the screen you need to save, press Control + Command + C. The ‘screenful’ will be copied to your clipboard. One easy option at this point is to start Preview, create a new file with the clipboard contents (Command + N), and save (Command + S). It couldn’t be any easier, and it spares you having to connect the device and taking shots from the Organizer.

As a side note, you could have discovered this shortcut yourself by opening the Edit menu in the Simulator and pressing the Control key. Moral of the story, it’s always worth spending some time checking an application’s menu with the Shift, Control, Option, or Command key pressed to see whether any ‘hidden’ shortcuts crop up…

Buffered stream reading in Cocoa

Strangely enough, there is no way in the Cocoa or Cocoa Touch frameworks to read a stream of bytes as a sequence of characters line by line. The option of creating a string from a file, with methods such as stringWithContentsOfFile of NSString, and then generating an array of lines with componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet] certainly seems simple and convenient enough. But when you’re dealing with very big text files (hundreds of Mb onwards), memory and performance become a concern, or even – on the iPhone platform more specifically – a full blown show-stopper. Continue reading “Buffered stream reading in Cocoa”

Truncate files on Linux/Mac OS

A quick way to truncate a file to zero length without affecting any other attributes (owner, permissions, and so on)? Here goes…
In the terminal window, type the following command at the prompt

: > filename.ext

The file called filename.ext will be reduced to zero bytes (emptied, basically). Everything else stays as it is, apart from the last-modified timestamp.

MySQL, PHP and Unix time

When working in PHP, the most convenient way of dealing with timestamps is through the time() function, which returns an integer representing the number of seconds from the UNIX epoch (1 Jan 1970 at 00:00 GMT). That’s perfect for passing around your code modules, calculating time differences and easy conversion to string with the date() function. MySQL though handles the same data type differently – if storing or retrieving timestamps in a MySQL table, there are a couple of options available. Continue reading “MySQL, PHP and Unix time”

Ignoring files with SVN

I’m using SVN for my XCode projects, but have soon realised that XCode support for SVN is not powerful enough. So I have decided to go the old good command-line way…

One of the most fundamental things I want to be able to do is ignore files – there is a lot of stuff in my projects that I do not want to go into my SCM tool: data files, build files, and so on. Subversion offers an ignore feature, but I wasn’t able to use it through XCode, so here goes. Continue reading “Ignoring files with SVN”

Mac OS and file splitting

It’s often useful to be able to split big archived files into smaller chunks, move them to – say – an external FAT32 hard drive (that won’t take anything bigger than 4Gb), and then recompose the original by combining the pieces. The MacOS X native archiver doesn’t handle that, and I didn’t like the idea of installing an application just for this purpose, therefore I thought I’d resort to the Terminal console. Continue reading “Mac OS and file splitting”

Type Associations in Windows

I’ve just found out about two convenient shell commands that can be used to check out and change/remove file associations in Windows. The first one is ftype, that allows you to define aliases for executable files to be invoked. The other one is assoc, whereby you can associate file name extensions to the aforementioned aliases. Continue reading “Type Associations in Windows”

Limits of Method Extensions in C# (dotNET 3.5)

After spending almost an hour trying to understand why an extended method would just not be available to the extended object types, I found out about a limit of this feature that I will make a note of, for future reference. Continue reading “Limits of Method Extensions in C# (dotNET 3.5)”

Risolto problema su postfix!

ricmest (09.04.2008 15:43:44): 

FEDE NOSTRO CHE SEI SOTTO I CIELI DI LONDRA, GRAZIE PER AVERCI AIUTATO A GUADAGNARE IL NOSTRO PANE QUOTIDIANO, NON CI INDURRE NELLA TENTAZIONE DI MANDARTI A QUEL PAESE, OGNI TANTO… MA LIBERACI DAI PROBLEMI AFFINCHE’ CI SI POSSA DEDICARE MEGLIO AL NOSTRO PORTALE, AMEN