2011/12/06

warning MSB8015

If you try to build a project in Visual Studio 2010 and you get the following error:

C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(151,5): warning MSB8015: Forcing a rebuild of all source files due to the contents of ".........\Debug\custombuild.command.1.tlog" being invalid.

Don't despair. I tried googling it and came up with a total of 3 (THREE) results in the whole web, two being in Korean. Yikes.
In any case, the solution was rather simple - check line ending inside the project file. If for some reason (due to being committed to SCM incorrectly, or something of similar nature) it has improper line endings, VS2010 will think that you have bad symbols inside build commands and make the build result invalid.
In my case, I had CR-CR-LF line endings - which, after being changed to CR-LF - solved the issue.

2011/10/31

XKCD2PDF

This one doesn't neccessary fall under the topic of this blog, but since it's a hacky thing I've done - I'm posting it here.

Some time ago I wanted to get all the XKCD comics stored on my iPad for offline viewing. Didn't find another solution so I cooked my own:


  1. A script that gets the JSON files of each comics and rips the important info
  2. Download the stuff
  3. Build a HTML page describing the comics with their 'alt' part (the good stuff)
  4. Open the HTML in Word, set margins to zero, save as PDF
  5. ...
  6. Profit!


I am really sorry about the 4th step, I know it's lame, but suprisingly, Word's "Save-as PDF" feature gave the best looking output.

And if you are lazy, you can grab the already generated PDFs here: (split in 3 chunks, the first 900 comics).

http://www.filesonic.com/file/2840295035/out.pdf
http://www.filesonic.com/file/2840295055/out2.pdf
http://www.filesonic.com/file/2840295065/out3.pdf


P.S. Here's the script:





2011/05/30

Checking if MPMediaItem exists by URL

If you are usings AVPlayer with Asset URLs, you might want to check asset's existence on the device.
If the asset is a file in local folder - no problem, you can use NSFileManager to check for existance? But what if it's inside the iPod library? The following trick wasn't easy to find, but here it is:

   NSURL* furl = [f trackUrl];
//        ipod-library://item/item.mp3?id=
        if([[furl scheme] isEqualToString:@"ipod-library"]){
            NSNumber* pid = [NSNumber numberWithLongLong: [[f.name substringFromIndex:32] longLongValue] ];;
            MPMediaPropertyPredicate *predicate = [MPMediaPropertyPredicate predicateWithValue:pid forProperty:MPMediaItemPropertyPersistentID];
            MPMediaQuery *songQuery = [[[MPMediaQuery alloc] init] autorelease];
            [songQuery addFilterPredicate: predicate];
            if (songQuery.items.count == 0) {
                return NO; // NOT FOUND!
            }

2011/05/26

Tracing Objective-C Allocation

So, let's say you have a problem tracking down some pesky retain/autorelease issue in your code. You can use NSZombieEnabled to catch double-releases, but sometimes those happen inside somebody else's code, and it's hard to track it down.

Based on a code I've found in this blog post, I've wrote a template for subclassing somebody else's class to print out the allocation history.

Here's how it looks:



And here's how you use it (in this example, I want to track AVPlayer):


SYNTESIZE_TRACE(AVPlayer)

AVPlayer* p = [[TraceAVPlayer alloc] init];


All done. Now, while running, you'll get a record of all retainCount modifications, with their stack trace.

2011/03/10

Making QT behave properly on Mac.

Couple of things I found out that helped porting a QT application to Mac:

The QMainWindow you create does not look like a native Cocoa window. The status bar is there, no matter what you request, the menu doesn't port and the icon is yucky.
Here's what you can do:

Remove status bar/resize grip:


Don't show unneeded icon in the title bar and move a QAction to Mac's main menu:

2011/01/26

SIMBL For Poking Inside Mac Application Internals

SIMBL is, according to it's Home Page:

Problem:
Some applications do about 90% of what I want.
Solution:
Develop my own applications.
Better Solution:
Patch the application myself...
SIMBL (SIMple Bundle Loader) - pronounced like "symbol" or "cymbal" - enables hacks and plugins. For instance, SIMBL enables PithHelmet to enhance Safari.

So, let's say we have a naughty program that has a behaviour we don't like. How would we treat that problem?


  1. class-dump TargetProgram
  2. Look at the list of classes and note the one that seems to be the issue. Let's call that class Victim.
  3. Inside, find your naughty method, let's call it '- (BOOL) victimMethod;'
  4. Open Info.plist of the victim, and note the bundle name and version
  5. Create new Cocoa bundle in XCode according to the steps on SIMBL site
  6. Fill in the bundle name as stated
  7. Use the following code: 
  8. Restart the target app
  9. ???
  10. Profit!

2010/11/25

Gallery, clicking and selecting

Android SDK includes a nice-looking component named Gallery.
It's supposed to provide you with functionality of flickable view-changer.
It get's an BaseAdapter and displays views it receives.
All good until you actually start using it.

First issue: 
setSelection(index, animated) method ignores the second parameter. There's no 'todo' anywhere, 'deprecated' or even acknowledgement from Google. It just doesn't give a crap what you pass there. It always navigates to your item without animation.
Now let's say that I want to change items in the gallery every X seconds. How can I make a pretty animation showing this lovely change? By hacking the bastard. Basically, the animations are initiates by the Fling motion that the component detects. If you simulate the correct fling - you will get the View flip animation.

gallery.onRealFling(null, null, -800, 0);
Here's a tricky part - the X velocity parameter needs to be adjusted per application, because to fling a larger view, you need a bigger velocity. So play with that value until you get a smooth transition.


Second issue:
Items inside the layout that you return in your adapter cannot receive click events. They just can't. No good reason for it, but someone botched up the bubbling up of mouse events in the Gallery, so now you can't have clickable items. If you set any one of them as clickable - the gallery stops handling dragging.
But fear not - you can fix it!
The solution is as follows - you add a touch listener to the gallery, and catch a Single Tap event (I did it with gesture listener), to differentiate it from the dragging that the gallery needs to handle.
Then, from the the location of the touch event, you can calculate where exactly inside your sub view the click was made - and from that you can handle the actual click.

Here's the code: