Saturday, September 21, 2013

Enabling telnet daemon on Mac OS X

To enable the telnet daemon, launch Terminal.app and issue:
$ sudo launchctl load -w /System/Library/LaunchDaemons/telnet.plist
 
To disable the daemon:
$ sudo launchctl unload -w /System/Library/LaunchDaemons/telnet.plist

Enabling "root" user in Mac OS X


About the root user

The user named "root" is a special user in UNIX-style operating systems that has read and write privileges to all areas of the file system. The root user should only be used for specific administration or monitoring tasks. After completing a task as the root user, you should log out of Mac OS X and log back in using a normal or administrator account. You should disable root access if you do not use it often.
The root user does not appear in Users or Accounts preferences.

Important notes
  • Only the owner of a computer or its designated administrator(s) should have an administrator account or the root password.
  • Any user with an administrator account can become the root user or reset the root password.
  • A root password should be difficult to guess, containing both numbers and letters within the first eight characters.
  • A root user has the ability to access other users' files.
  • The root user has the ability to relocate or remove required system files and to introduce new files in locations that are protected from other users.

How to enable the root user

OS X Lion
  1. From the Apple menu choose System Preferences....
  2. From the View menu choose Users & Groups.
  3. Click the lock and authenticate as an administrator account.
  4. Click Login Options....
  5. Click the "Edit..." or "Join..." button at the bottom right.
  6. Click the "Open Directory Utility..." button.
  7. Click the lock in the Directory Utility window.
  8. Enter an administrator account name and password, then click OK.
  9. Choose Enable Root User from the Edit menu.
  10. Enter the root password you wish to use in both the Password and Verify fields, then click OK.
Mac OS X v10.6.x
  1. From the Apple menu choose System Preferences....
  2. From the View menu choose Accounts.
  3. Click on the lock and authenticate with an administrator account.
  4. Click Login Options....
  5. Click the "Edit..." or "Join..." button at the bottom right.
  6. Click the "Open Directory Utility..." button.
  7. Click the lock in the Directory Utility window.
  8. Enter an administrator account name and password, then click OK.
  9. Choose Enable Root User from the Edit menu.
  10. Enter the root password you wish to use in both the Password and Verify fields, then click OK.
Note: If you are troubleshooting an issue that prevents you from logging in as an administrator, follow the steps in this article to enable the root user.
Mac OS X v10.5.x
  1. From the Finder's Go menu, choose Utilities.
  2. Open Directory Utility.
  3. Click the lock in the Directory Utility window.
  4. Enter an administrator account name and password, then click OK.
  5. Choose Enable Root User from the Edit menu.
  6. Enter the root password you wish to use in both the Password and Verify fields, then click OK.
Note: If you are troubleshooting an issue that prevents you from logging in as an administrator, follow the steps in this article to enable the root user.
Mac OS X v10.4.x or earlier
  1. Click the Finder icon in the Dock.
  2. From the Go menu, choose Applications.
  3. Open the Utilities folder.
  4. Open the NetInfo Manager utility.
  5. Click the lock in the NetInfo Manager window.
  6. Enter an administrator account name and password, then click OK.
  7. For Mac OS X 10.2 and later, choose Enable Root User from the Security menu.
  8. For Mac OS X 10.0 and 10.1, choose Security from the Domain menu, then Enable Root User from the submenu.
  9. If you have not previously set a root password, an alert box may appear that says "NetInfo Error," indicating that the password is blank. Click OK.
  10. Enter the root password you wish to use and click Set.
  11. Enter the password again for verification and click Verify.
  12. Click the lock again to prevent changes.
     
How to log in as root

Use these steps for Mac OS X v10.2 or later

  1. If you are logged in, choose Log Out from the Apple menu.
  2. If you are logging in from a list of usernames with pictures, click Other.
  3. In the Name field, type: root
  4. In the Password field, type the password you defined in the steps above.
Use these steps for Mac OS X v10.0 to v10.1.5

After enabling the root user, you must log out from Mac OS X and log back in as the root user. Logging in to Mac OS X from a list of usernames is the default behavior for later versions of Mac OS X. Logging in by typing your username in a text entry field is the default behavior in earlier versions of Mac OS X. You can choose either method in Login preferences. The root user does not appear in the list, so you need the text entry option. If necessary, follow these steps to change the login method to text entry:
  1. From the Apple menu, choose System Preferences.
  2. From the View menu, choose Login.
  3. Click the Login Window tab.
  4. Select the radio button for "Name and password entry fields."
Follow these steps to log in as root:
  1. If you are logged in, choose Log Out from the Apple menu.
  2. In the Name field, type: root
  3. In the Password field, type the password you defined in the steps above.


How to disable the root user
 

OS X Lion
  1. From the Apple menu choose System Preferences....
  2. From the View menu choose Users & Groups.
  3. Click on the lock and authenticate with an administrator account.
  4. Click Login Options....
  5. Click the "Edit..." or "Join..." button at the bottom right
  6. Click the "Open Directory Utility..." button.
  7. Click the lock in the Directory Utility window.
  8. Enter an administrator account name and password, then click OK.
  9. Choose Disable Root User from the Edit menu. 
Mac OS X v10.6.x
  1. From the Apple menu choose System Preferences....
  2. From the View menu choose Accounts.
  3. Click on the lock and authenticate with an administrator account.
  4. Click Login Options....
  5. Click the "Edit..." or "Join..." button at the bottom right
  6. Click the "Open Directory Utility..." button.
  7. Click the lock in the Directory Utility window.
  8. Enter an administrator account name and password, then click OK.
  9. Choose Disable Root User from the Edit menu. 
Mac OS X v10.5.x
  1. Click the Finder icon in the Dock.
  2. From the Go menu, choose Utilities.
  3. Open Directory Utility.
  4. Click the lock in the Directory Utility window.
  5. Enter an administrator account name and password, then click OK.
  6. Choose Disable Root User from the Edit menu.
Mac OS X v10.4.x or earlier
  1. Open NetInfo Manager. It's in the Utilities folder.
  2. Click the lock.
  3. Enter the name and password for an administrator account, then click OK.
  4. For Mac OS X 10.2 and later, choose Disable Root User from the Security menu.
  5. For Mac OS X 10.0 and 10.1, choose Security from the Domain menu, then Disable Root User from the submenu.
What is the root directory?

The term root is used in two distinct ways: The "root user" and the "root directory." The root directory is the highest directory level of a disk. The files and folders you see when you open (double-click) your hard disk icon are the contents of that disk's root directory. A directory is represented graphically as a folder. You may know your home directory as your "home folder." The terms "folder" and "directory" are generally interchangeable.
A user's short name is also the name of his home directory.
The Finder and the Terminal show different contents for the root directory. Some items in the root directory are not visible in the Finder. This reduces visual clutter and enhances simplicity. If you are familiar with a UNIX-style command line you can use Terminal to view all items in a directory.

Cocos2d Basics Concepts

There are some basic concepts introduced in this library that you will need to know when developing a cocos2d application:

 

 Scenes:

A scene (implemented with the CCScene object) is more or less an independent piece of the app workflow. Some people may call them “screens” or “stages”. Your app can have many scenes, but only one of them is active at a given time.
For example, you could have a game with the following scenes: Intro, Menu, Level 1, Cutscene 1, Level 2, Winning cutscene, losing cutscene, High scores screen.
You can define every one of these scenes more or less as separate apps; there is a bit of glue between them containing the logic for connecting scenes (the intro goes to the menu when interrupted or finishing, Level 1 can lead you to the cutscene 1 if finished or to the losing cutscene if you lose, etc.).

A cocos2d CCScene is composed of one or more layers (implemented with the CCLayer object), all of them piled up. Layers give the scene an appearance and behavior; the normal use case is to just make instances of Scene with the layers that you want.
There is also a family of CCScene classes called transitions (implemented with the CCTransitionScene object) which allow you to make transitions between two scenes (fade out/in, slide from a side, etc).
Since scenes are subclasses of CCNode, they can be transformed manually or by using actions. See Actions for more detail about actions.

 

 Director:

The CCDirector is the component which takes care of going back and forth between scenes.
The CCDirector is a shared (singleton) object. It knows which scene is currently active, and it handles a stack of scenes to allow things like “scene calls” (pausing a Scene and putting it on hold while another enters, and then returning to the original). The CCDirector is the one who will actually change the CCScene, after a CCLayer has asked for push, replacement or end of the current scene.
The CCDirector is also responsible for initializing OpenGL ES.

 

Layers:

A CCLayer has a size of the whole drawable area, and knows how to draw itself. It can be semi transparent (having holes and/or partial transparency in some/all places), allowing to see other layers behind it. Layers are the ones defining appearance and behavior, so most of your programming time will be spent coding CCLayer subclasses that do what you need.

The CCLayer is where you define event handlers. Events are propagated to layers (from front to back) until some layer catches the event and accepts it. FIXME
Although some serious apps will require you to define custom CCLayer classes, cocos2d provides a library of useful predefined layers (a simple menu layer: CCMenu, a color layer: CCColorLayer, a multiplexor between other layers: CCMultiplexLayer, and more ).
Layers can contain CCSprite objects, CCLabel objects and even other CCLayer objects as children.
Since layers are subclass of CCNode, they can be transformed manually or by using actions. See Actions for more detail about actions.

 

Sprites:

A cocos2d' sprite is like any other computer sprite. It is a 2D image that can be moved, rotated, scaled, animated, etc.
Sprites (implemented using the CCSprite class) can have other sprites as children. When a parent is transformed, all its children are transformed as well.
Since sprites are subclass of CCNode, they can be transformed manually or by using actions. See Actions for more detail about actions.

Friday, September 20, 2013

How to prevent files from being backed up to iCloud and iTunes ?

For iOS 5.0.1 :

#import <sys/xattr.h>

- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
{
    assert([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]);
    const char* filePath = [[URL path] fileSystemRepresentation];

    const char* attrName = "com.apple.MobileBackup";
    u_int8_t attrValue = 1;

    int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0);
    return result == 0;
}



For iOS 5.1 and later:


- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
{
    assert([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]);
    NSError *error = nil;
    BOOL success = [URL setResourceValue: [NSNumber numberWithBool: YES]
                                  forKey: NSURLIsExcludedFromBackupKey error: &error];

    if(!success){
        NSLog(@"Error excluding %@ from backup %@", [URL lastPathComponent], error);
    }
    return success;
}

App Backup Best Practices in iOS

You do not have to prepare your app in any way for backup and restore operations. Devices with an active iCloud account have their app data backed up to iCloud at appropriate times. And for devices that are plugged into a computer, iTunes performs an incremental backup of the app’s data files. However, iCloud and iTunes do not back up the contents of the following directories:
  • Application_Home/AppName.app
  • Application_Home/Library/Caches
  • Application_Home/tmp
To prevent the syncing process from taking a long time, be selective about where you place files inside your app’s home directory. Apps that store large files can slow down the process of backing up to iTunes or iCloud. These apps can also consume a large amount of a user's available storage, which may encourage the user to delete the app or disable backup of that app's data to iCloud. With this in mind, you should store app data according to the following guidelines:
  • Critical data should be stored in the /Documents directory. Critical data is any data that cannot be recreated by your app, such as user documents and other user-generated content.
  • Support files include files your application downloads or generates and that your application can recreate as needed. The location for storing your application’s support files depends on the current iOS version.
  • Cached data should be stored in the /Library/Caches directory. Examples of files you should put in the Caches directory include (but are not limited to) database cache files and downloadable content, such as that used by magazine, newspaper, and map apps. Your app should be able to gracefully handle situations where cached data is deleted by the system to free up disk space.
  • Temporary data should be stored in the /tmp directory. Temporary data comprises any data that you do not need to persist for an extended period of time. Remember to delete those files when you are done with them so that they do not continue to consume space on the user's device.
Although iTunes backs up the app bundle itself, it does not do this during every sync operation. Apps purchased directly from a device are backed up when that device is next synced with iTunes. Apps are not backed up during subsequent sync operations, though, unless the app bundle itself has changed.

iOS 7.0 Screen Size and App Icons


App Icon and Image Size for iOS

Icon and Image Sizes

Every app needs an app icon and a launch image. In addition, some apps need custom icons to represent app-specific content, functions, or modes in navigation bars, toolbars, and tab bars. 

Unlike other custom artwork in your app, the icons and images listed in Table 38-1 must meet specific criteria so that iOS can display them properly. 

In addition, some icon and image files have naming requirements. (If you need to support standard-resolution iPhone or iPod touch devices, divide by 2 the high-resolution sizes listed below.) 

Table 38-1Size (in pixels) of custom icons and images
Description
Size for iPhone 5 and iPod touch (high resolution)
Size for iPhone and iPod touch (high resolution)
Size for iPad (high resolution)
Size for iPad 2 and iPad mini (standard resolution)
App icon (required for all apps)
120 x 120
120 x 120
152 x 152
76 x 76
App icon for the App Store (required for all apps)
1024 x 1024
1024 x 1024
1024 x 1024
1024 x 1024
Launch image (required for all apps)
640 x 1136
640 x 960
1536 x 2048 (portrait)
2048 x 1536 (landscape)
768 x 1024 (portrait)
1024 x 768 (landscape)
Spotlight search results icon (recommended)
80 x 80
80 x 80
80 x 80
40 x 40
Settings icon (recommended)
58 x 58
58 x 58
58 x 58
29 x 29
Toolbar and navigation bar icon (optional)
About 44 x 44
About 44 x 44
About 44 x 44
About 22 x 22
Tab bar icon (optional)
About 50 x 50 (maximum: 96 x 64)
About 50 x 50 (maximum: 96 x 64)
About 50 x 50 (maximum: 96 x 64)
About 25 x 25 (maximum: 48 x 32)
Default Newsstand cover icon for the App Store (required for Newsstand apps)
At least 512 pixels on the longest edge
At least 512 pixels on the longest edge
At least 512 pixels on the longest edge
At least 256 pixels on the longest edge
Web clip icon (recommended for web apps and websites)
120 x 120
120 x 120
152 x 152
76 x 76

For all images and icons, the PNG format is recommended. 

The standard bit depth for icons and images is 24 bits—that is, 8 bits each for red, green, and blue—plus an 8-bit alpha channel.

Wednesday, September 18, 2013

Removing Annotations From MKMapView


for (int index = 0; index < [[[self aMapView] annotations] count]; index++) {
    if ([[[[self aMapView] annotations] objectAtIndex:index] isKindOfClass:[MyAnnotation class]]) {
        [[self aMapView] removeAnnotation:[[[self aMapView] annotations] objectAtIndex:index]];
    }
}

Tuesday, September 17, 2013

Funny Source Code Comments

I recently stumbled upon an awesome Stack Overflow thread, entitled “What is the best comment in source code you have ever encountered?”.

As you might have guessed, it is a collection of funny source code comments, provided by developers all over the world. Take a look at it, it could definitely make your day.

I am reposting here my personal favorites from that long long collection:

// sometimes I believe compiler ignores all my comments
Exception up = new Exception(“Something is really wrong.”);
throw up; //ha ha

//When I wrote this, only God and I understood what I was doing
//Now, God only knows

// I dedicate all this code, all my work, to my wife, Darlene, who will
// have to support me and our three children and the dog once it gets
// released into the public.

// drunk, fix later

// Magic. Do not touch.

return 1; # returns 1

double penetration; // ouch

/////////////////////////////////////// this is a well commented line

// I am not sure if we need this, but too scared to delete.

// I am not responsible of this code.

// They made me write it, against my will.

//Dear future me. Please forgive me.

//I can’t even begin to express how sorry I am.

options.BatchSize = 300; //Madness? THIS IS SPARTA!

// I have to find a better job

// hack for ie browser (assuming that ie is a browser)
} catch (PartInitException pie) {
// Mmm… pie
}

// John! If you’ll svn remove this once more,
// I’ll shut you, for God’s sake!

// That piece of code is not “something strange”!

// That is THE AUTH VALIDATION.
try {
}
catch (SQLException ex) {
// Basically, without saying too much, you’re screwed. Royally and totally.
}
catch(Exception ex)
{
//If you thought you were screwed before, boy have I news for you!!!
}

// Catching exceptions is for communists

// If you’re reading this, that means you have been put in charge of my previous project.

// I am so, so sorry for you. God speed.

// if i ever see this again i’m going to start bringing guns to work

// The magnitude of this hack compares favorably with that of the national debt.

//ALL YOUR BASE ARE BELONG TO US

// If this code works, it was written by Paul. If not, I don’t know who wrote it

//You are not expected to understand this
/**
* If you don’t understand this code, you should be flipping burgers instead.
*/
‘NO COMMENT

//Abandon all hope yea who enter beyond this point

//Mr. Compiler, please do not read this.
catch (Ex as Exception)
{
// oh crap, we should do something.
}

// TODO make this work

// If you delete the credits, I will fucking kill you.

// This is crap code but it’s 3 a.m. and I need to get this working.

// For the sins I am about to commit, may James Gosling forgive me

// Houston, we have a problem
// If I from the future read this I’ll back in time and kill myself.


Pure awesomeness… Don’t forget to share your own favorites in the comments!

Missing recommended icon file - The bundle does not contain an app icon for iPhone / iPod Touch of exactly '120x120' pixels, in .png format


Yes you need to add 120x120 high resolution icon now for iOS 7.0


Monday, September 16, 2013

Malaysian Education Reforms

The Malaysian Govt has started a new education scheme under which all the schools will be provided free Chromebooks.

While this initiative is welcomed by all , it brings a chance for all the rural students to get computer knowledge.

Malaysia has more than 10,000 schools. It targets to provide seamless 4G internet connection for all the schools.