iPhone SDK: CGAffineTransformInvert and iPhone 4

So if you tried a piece of code like:

CGAffineTransform t0 = CGContextGetCTM(context);
t0 = CGAffineTransformInvert(t0);
CGContextConcatCTM(context, t0);

You know that in iPhone 4, your drawings will be smaller, and if you don’t use this bit of code, your origin is not in the lower left corner but in top left.

The reason for this is that t0 is a transformation matrix, Core Graphics will multiply every point by this matrix to find it’s location on the screen.

Read more about this matrix here:

http://iphonedevelopment.blogspot.com/2008/10/demystifying-cgaffinetransform.html

This matrix is a 3×3 matrix like this:

| a  b  0 |
| c  d  0 |
| tx ty 1 |

Now if print these before the call to CGAffineTransformInvert values to console, you will see this for iPhone 4:
a: 2.000000 – b: 0.000000 – c: 0.000000 – d: -2.000000 – tx: 0.000000 – ty: 960.000000

And after:
a: 0.500000 – b: 0.000000 – c: 0.000000 – d: -0.500000 – tx: -0.000000 – ty: 480.000000

You can see that a and d are used to scale the shapes you draw and CGAffineTransformInvert changes these values to a smaller value since iPhone 4 has much more pixels in it’s display and is capable of better resolutions.

Here are the values for iPhone 3:
a: 1.000000 – b: 0.000000 – c: 0.000000 – d: -1.000000 – tx: 0.000000 – ty: 480.000000

And after the call to CGAffineTransformInvert:
a: 1.000000 – b: 0.000000 – c: 0.000000 – d: -1.000000 – tx: -0.000000 – ty: 480.000000

The Solution

(Or at least I’m using this until I find a better solution) Add this to your code:

CGAffineTransform t0 = CGContextGetCTM(context);
 
    CGFloat xScaleFactor = t0.a > 0 ? t0.a : -t0.a;
    CGFloat yScaleFactor = t0.d > 0 ? t0.d : -t0.d;
    t0 = CGAffineTransformInvert(t0);
    if (xScaleFactor != 1.0 || yScaleFactor != 1.0)
        t0 = CGAffineTransformScale(t0, xScaleFactor, yScaleFactor);
    CGContextConcatCTM(context, t0);

This code will check the value of t0.a and t0.d in the matrix and if it’s not equal to one, it scales the matrix to match the original values. It also ensures that the xScaleFactor and yScaleFactor values are positive.

Again, this looks nasty but works, if there is a better way, please let me know…

iPhone SDK: CGAffineTransformInvert and iPhone 4
Comments (0)   Filed under: iPhone SDK   Posted by: Codehead

iPhone SDK: Base SDK Missing

Here is a solution that will probably fix your issue:

First go to: Project > Edit Project Settings > Build Tab > Edit the value for Base SDK
Then go to: Project > Edit Active Target > Build Tab > Edit the value for Base SDK here too

This should fix it…

iPhone SDK: Base SDK Missing
Comments (0)   Filed under: iPhone SDK   Posted by: Codehead

iPhone SDK: didFinishLaunchingWithOptions Is Not Being Called – Skipped

Double-Click on MainWindow.xib then select ‘File’s Owner’, then go to:

Tools > Connections Inspector

Under outlets you will see ‘Delegate’ drag from the circle next to it to your “APP_NAME App Delegate” icon, save and try again…

iPhone SDK: didFinishLaunchingWithOptions Is Not Being Called – Skipped
Comments (0)   Filed under: iPhone SDK   Posted by: Codehead

PHP: Problem With Displaying French Accented Characters; black diamond…

If you have this problem and your accented characters are being replaced by black diamonds with question marks in them and you tried EVERYTHING you could find and nothing worked and no one seems to know what’s going on and you think it’s PHP or Apache that is causing this issue and you tried changing their configuration directives and you are pulling your hair out then this could be your editor!

Go to it’s preferences, most of them have a section for font encoding, for example in Komodo Edit, go to:

Preferences > Fonts and Colors > Under the Fonts tab > There is the font encoding, choose UTF-8

After this step you might have to change the encoding of the current file, again most editors should be able to do this, refer to your editor’s docs for more info on this, but here is how to do this in Komodo Edit:

Open File > Edit > Current File Settings > In File Settings Box > Change Encoding To UTF-8 > Save

and Viola!

PHP: Problem With Displaying French Accented Characters; black diamond…
Comments (0)   Filed under: Komodo Edit, PHP, Web Design, Web Development   Posted by: Codehead

MySQL: ERROR 1114 (HY000) at line 4424: The table ‘X’ is full

Even though this could be a limitation by your file system check the value of the system variable:

myisam_data_pointer_size

If it’s set to 4 then the table can be a maximum of 4GB in size but if it’s set to 6 then the table can be a maximum of 256TB…

To fix this try:

edit /etc/my.cnf

And add this line to the end of it:

myisam_data_pointer_size = 6

Save it and restart mysql:

service mysql restart

I hope this helps…

MySQL: ERROR 1114 (HY000) at line 4424: The table ‘X’ is full
Comments (0)   Filed under: MySQL, Operating Systems, Server   Posted by: Codehead

WHM/cPanel: MySQL Errors While Manually Transferring Accounts

Errors like:

DELIMITER must be followed by a ‘delimiter’ character or string
or
ERROR X (X): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near

If you get those errors the chances are that the MySQL version on the source and destination servers don’t match, most probably the destination server runs an older version of MySQL, to fix this issue, you must let /scripts/pkgacct know your version of MySQL, find out the version, then do something like this:

/scripts/pkgacct UNAME –mysql 4.1
Note: 2 dashes before mysql, they are not showing up here…

Please note that, in my case, my MySQL server was version 4.1 so you may need to change this version number to match your own destination server’s MySQL server version.

I hope this helps someone :)

WHM/cPanel: MySQL Errors While Manually Transferring Accounts
Comments (0)   Filed under: MySQL, Server, WHM/cPanel   Posted by: Codehead

Playing WMV Videos On Mac

You can download and install Flip4Mac and you are all set:

http://www.microsoft.com/windows/windowsmedia/player/wmcomponents.mspx

Playing WMV Videos On Mac
Comments (0)   Filed under: Mac, Windows   Posted by: Codehead

Putty on Mac

Let me show you something cool, you don’t need Putty, open a terminal (Applications > Utilities) and do:

ssh root@YOURSERVERSIP

To all the noobs :)

Putty on Mac
Comments (0)   Filed under: Mac, SSH   Posted by: Codehead

RSA host key for HOST has changed and you have requested strict checking

If you get this:

————————————-
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: POSSIBLE DNS SPOOFING DETECTED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
The RSA host key for HOST has changed,
and the key for the corresponding IP address IP
is unknown. This could either mean that
DNS SPOOFING is happening or the IP address for the host
and its host key have changed at the same time.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
SOME_KEY
Please contact your system administrator.
Add correct host key in /Users/user… to get rid of this message.
Offending key in /Users/user…
RSA host key for HOST has changed and you have requested strict checking.
Host key verification failed.
————————————-

Then try:

ssh-keygen -R HOST

And try reconnecting…

RSA host key for HOST has changed and you have requested strict checking
Comments (0)   Filed under: CentOS, Linux, SSH   Posted by: Codehead

Google Maps API V3; infowindow is only attached to the last marker problem

You can fix this issue like this:

for (var i = 0; i < addresses.length; i++) {
			(function () { /* ################################################## */
				var address = addresses[i];
				var lat_lang = new google.maps.LatLng(address.latitude, address.longitude);
				var marker = new google.maps.Marker({
					position: lat_lang,
					map: map
				});
				markers[markers.length] = marker;
				var infowindow = new google.maps.InfoWindow({
					content: address.address
				});
				infowindows[infowindows.length] = infowindow;
				google.maps.event.addListener(marker, 'click', function() {
					close_infowindows();
					infowindow.open(map, marker);
				});
			})(); /* ################################################## */
		}

By adding the lines marked with /* ################################################## */ in the middle of your loop…

I hope this helps someone :)

Google Maps API V3; infowindow is only attached to the last marker problem
Comments (1)   Filed under: APIs, Google Maps API, JavaScript, Web Development   Posted by: Codehead
Older Posts »