iPhone Wifi MacAddress

#if ! defined(IFT_ETHER)
     #define IFT_ETHER 0x6/* Ethernet CSMACD */

- (IBAction)testAction:(id)sender
      #pragma unused(sender)
      BOOL                              success;
      struct ifaddrs *               addrs;
      const struct ifaddrs *           cursor;
      const struct sockaddr_dl *      dlAddr;
      const uint8_t *               base;
      int                              i;

      success = getifaddrs(&addrs) == 0;
      if (success) {
          cursor = addrs;
          while (cursor != NULL) {
               fprintf(stderr, "%s\n", cursor->ifa_name);
               if ( (cursor->ifa_addr->sa_family == AF_LINK)
               && (((const struct sockaddr_dl *) cursor->ifa_addr)->sdl_type == IFT_ETHER) ) {
               dlAddr = (const struct sockaddr_dl *) cursor->ifa_addr;
               fprintf(stderr, " sdl_nlen = %d\n", dlAddr->sdl_nlen);
               fprintf(stderr, " sdl_alen = %d\n", dlAddr->sdl_alen);
               base = (const uint8_t *) &dlAddr->sdl_data[dlAddr->sdl_nlen];
               fprintf(stderr, " ");
               for (i = 0; i < dlAddr->sdl_alen; i++) {
                    if (i != 0) {
                    fprintf(stderr, ":");
                    fprintf(stderr, "%02x", base[i]);
               fprintf(stderr, "\n");
               cursor = cursor->ifa_next;


Linq Update FK – Operation is not valid due to the current state of the object

sql serverTo update the entity in question you need to get a new entity for it from the context rather than setting it directly.

Wrong Way

OrderRecord.customerId = 105;

Throws an error!
“Operation is not valid due to the current state of the object”


OrderRecord.tblCustomer = db.tblCustomers.Single(t => t.customerID == 105);

Returns no error!

Enable TSQL xp_cmdshell command

SQL Server blocked access to procedure ‘sys.xp_cmdshell’ of component ‘xp_cmdshell’ because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of ‘xp_cmdshell’ by using sp_configure

A simple script to enable xp_cmdshell in SQL Server

sp_configure 'show advanced options',1
sp_configure xp_cmdshell,1

Remove Maintance WP State

Description of error

If you’ve been keeping on top of your WordPress updates using the automatic upgrade feature, you may have run into a problem immediately after upgrading. A message that prevents access to any page on your blog, “Briefly unavailable for scheduled maintenance. Check back in a minute”.

Cause of this message

During an automatic upgrade, WordPress places a file in the blog root directory called “.maintenance” to prevent visitors from being confronted with ugly, broken pages during the upgrade process. That’s a great little built-in feature, but if the upgrade gets interrupted or fails for any reason, that file doesn’t get deleted and nobody, including you, can access your blog. No worries, this is (most likely) the simplest fix ever.

Official Solution

All you have to do is delete the .maintenance file from the blog root directory. Simple as it gets. After you’ve deleted the files you should be able to access the site just fine, but you may have to run the automatic upgrade again. How do you know if you should run it again? You’ll see a notification on the dashboard page that a new version of WordPress is available…same as you always see when a new upgrade is available. If you don’t see that message, you’re good to go.

In case problem persists

In my case the “. maintenance” file was not there at all. Started exploring the blog files and there it was.
In wp-content/upgrade/<pluggin_name>.temp
The pluggin name was the latest pluggin i tried to update. So i deleted this folder and everything came back to normal state.

I hope this helps.

Getting NSDate from NSString

Very useful, yet short and simple, code snippet on how to rip the NSDate from NSString using NSDateFormatter:

NSString *dateString = @"2010-01-19";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
// this is imporant - we set our input date format to match our input string
// if format doesn't match you'll get nil from your string, so be careful
[dateFormatter setDateFormat:@"yyyy-MM-dd"];
NSDate *dateFromString = [[NSDate alloc] init];
// ta-daaa!
dateFromString = [dateFormatter dateFromString:dateString];

If you need more info about different date formats see Unicode Date Format Patterns. Of course if you usually work with standard dates you can use setDateStyle instead of setDateFormat.

Rebuild Icon Cache in Windows (Vista and 7)

Rebuilding the Icon Cache Database

  • Close all folder windows that are currently open.
  • Launch Task Manager using the CTRL+SHIFT+ESC key sequence, or by running taskmgr.exe.
  • In the Process tab, right-click on the Explorer.exe process and select End Process.
  • Click the End process button when asked for confirmation.
  • From the File menu of Task Manager, select New Task (Run…)
  • Type CMD.EXE, and click OK
  • In the Command Prompt window, type the commands one by one and press ENTER after each command:
    CD /d %userprofile%\AppData\Local
    DEL IconCache.db /a
  • In Task Manager, click File, select New Task (Run…)
  • Type EXPLORER.EXE, and click OK.

MySQL Change Collation Script

// Original script (v1.0) by/from: http://www.phpwact.org/php/i18n/utf-8/mysql
// Improved/modified (v1.05) by Bogdan http://bogdan.org.ua/
// Last updated: 2010-06-28
// this script will output all queries needed to change all fields/tables to a different collation
// it is HIGHLY suggested you make a MySQL backup prior to running any of the generated queries
// this code is provided AS IS and without any warranty
// add text/plain header when used not as a CLI script; PHP CLI SAPI shouldn't output headers
header("Content-Type: text/plain");
// precaution
die("Make a backup of your MySQL database, then remove this line from the code!");
// collation you want to change to:
$convert_to   = 'utf8_general_ci';
// character set of new collation:
$character_set= 'utf8';
// DB login information - *modify before use*
$username = 'user';
$password = 'pass';
$database = 'database_name';
$host     = 'localhost';
//-- usually, there is nothing to modify below this line --//
// show TABLE alteration queries?
$show_alter_table = true;
// show FIELD alteration queries?
$show_alter_field = true;
mysql_connect($host, $username, $password);
$rs_tables = mysql_query(" SHOW TABLES ") or die(mysql_error());
while ($row_tables = mysql_fetch_row($rs_tables)) {
    $table = mysql_real_escape_string($row_tables&#91;0&#93;);
    // Alter table collation
    if ($show_alter_table)
        echo("ALTER TABLE `$table` DEFAULT CHARACTER SET $character_set;\n");
    $rs = mysql_query(" SHOW FULL FIELDS FROM `$table` ") or die(mysql_error());
    while ( $row = mysql_fetch_assoc($rs) ) {
        if ( $row&#91;'Collation'&#93; == '' || $row&#91;'Collation'&#93; == $convert_to )
        // Is the field allowed to be null?
        if ( $row&#91;'Null'&#93; == 'YES' )
            $nullable = ' NULL ';
            $nullable = ' NOT NULL ';
        // Does the field default to null, a string, or nothing?
        if ( $row&#91;'Default'&#93; === NULL && $row&#91;'Null'&#93; == 'YES' )
            $default = " DEFAULT NULL ";
        elseif ( $row&#91;'Default'&#93; != '' )
            $default = " DEFAULT '".mysql_real_escape_string($row&#91;'Default'&#93;)."'";
            $default = '';
        // sanity check and fix:
        if ($nullable == ' NOT NULL ' && $default == ' DEFAULT NULL ') {
            $default = '';
            echo "/* Warning: wrong combination of 'default value' and 'NULL-flag' detected - and fixed! */\n";
            echo "/* Diagnostics: row&#91;Null&#93; = '$row&#91;Null&#93;', row&#91;Default&#93; = " . mysql_real_escape_string($row&#91;'Default'&#93;) . ", MySQL version: " . mysql_get_server_info() . " */\n";
        // Don't alter INT columns: no collations, and altering them drops autoincrement values
        if (strpos($row&#91;'Type'&#93;, 'int') !== false) {
            $show_alter_field = False;
        else {
            $show_alter_field = True;
        // Alter field collation:
        // ALTER TABLE `tab` CHANGE `field` `field` CHAR( 5 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL
        if ($show_alter_field) {
            $field = mysql_real_escape_string($row&#91;'Field'&#93;);
            echo "ALTER TABLE `$table` CHANGE `$field` `$field` $row&#91;Type&#93; CHARACTER SET $character_set COLLATE $convert_to $nullable $default;\n";

iPhone Touch Icon – Create your own Icon Set

Since the introduction to the iPhone 4, we now have some additional icons we need to create to support the Hi-Res graphics of the iPhones Retinal Display. Altogether we now have a total of 6 app icons, each with a different pixel size in order to support all devices they are as follows:

  • iPhone 4 Hi-Res App Icon ( 114 x 114 )
  • iPhone App Icon ( 57 x 57 )
  • iPad App Icon ( 72 x 72 )
  • iphone 4 Hi-Res Spotlight Icon ( 58 x 58 )
  • iPhone Spotlight Icon ( 29 x 29 )
  • iPad Spotlight Icon ( 50 x 50 )

After recently developing a few iPhone apps, I found it to be a redundant task to create 6 icons every time I make a new app. To make this process faster, I’ve created a PHP script that takes the highest resolution icon and converts it down to the 6 icons required.
You can find this script at my company website at http://empoc.com/ios-icons/
It only takes a few seconds to create all of the icons and when the script has finished running you will be able to download them all in a nicely zipped up file. I’ve also got instructions there that will show you what to do with the icons once you’ve downloaded them.
Please have a look and let me know what you think…

Alternatively you can visit make app icon to create the whole set of icons http://makeappicon.com/

IT collaboration, Tutorials, Tips