Personal communication channel of Alexey Kulikov broadcasting live from Vienna, Austria

MAMP + Pecl + PEAR

Awesome tutorial no how to get the above running smoothly.

Text

Fighting with MySQL to correctly isolate transaction has never been trickier since the release of MySQL 5.5.

Older versions of MySQL treated the following SQL statement as a setting for the current session:

SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;

However, MySQL 5.5 silently ignores this SQL statement and defaults to the global setting. You shall not lose faith, my young padawan. All you need to do is tell MySQL to set transaction isolation levels for the current open session explicitly by adding one small word:

SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;

And you should have immediate joy.

Text

There is a lot of confusion around the configuration of the old Airpot Express devices from Mountain Lion. Frankly speaking there is no way to configure them, as the new Airport Utility fails to recognize older devices. Yet, ze Russians know their ways ;-) Just follow the howto below to get an older version of Airport Utility up and running and you are good to go:

1. Download the disk image (you can find it here: http://support.apple.com/kb/DL1536).

2. Mount the disk image and drag the install package (AirPortUtility.pkg) to your desktop.

3. Fire up Terminal and prepare to show off…

4. Make a temporary directory and cd into it: mkdir tmp ; cd tmp

5. Extract the Payload file from the install package with xar, here’s the command: xar -x -f ~/Desktop/AirPortUtility.pkg Payload

6. The result will be a directory named AirPortUtility.pkg (just like the file, but now you can move into it to get the files you want). Inside will be a file called Payload that is a compressed archive of AirPort Utility.app.

7. So our next move is to extract the app. Here’s the command: gzcat AirPortUtility.pkg/Payload | tar -xf -

8. When it finished there will be three new folders Applications, Library, and System. Your nice new copy of AirPort Utility 5.6.1 will be in the Utilities folder inside of the Applications folder. Use Finder to rename it (assuming you want to keep version 6 as well) then drag it to your Applications/Utilities folder.

9. The other two folders hold the AirPort Base Station Agent and its supporting files. I’m not sure if you need/want these or not. As best I can figure the agent does two things: it checks for updates for AirPort Utility and it monitors AirPort base stations for problems. You probably already have a version running as it comes with the system and it seems to know how to talk to both versions of AirPort Utility (I got nagged about updating).

10. The final step is to launch AirPort Utility and confirm that it works. You’ll probably want to go into preferences and turn off the option to check for updates. If all is good you can remove the temporary directory: cd .. ; rm -rf tmp (or drag it into the trash with Finder).

Text

What may sound like a no-brainer is actually a point of failure for apple’s UI team. Almost everyone who tries to extend an existing wireless network with the aid of a time capsule fail badly, since the UI is really misleading.

The main problem is — one does NOT have to choose the option “Extend existing wireless network”, — as the option literally disables the TC to work in bridge mode.

So how does one go about this problem? Easy! Setup your TC to create a new wireless network, but use the same SSID, security settings and password as the root device. This will create a roaming network, where all your devices will automatically connect to the spot with the strongest signal.

Double win!

Text

After upgrading to Mountain Lion (and later to 10.8.1) MAMP decided that it did not like the built in Apache and failed to start. This is easy to fix, one has to follow three easy steps:

  • Bind MAMP Apache to port 8080
  • Forward all port 80 traffic to port 8080
  • Edit MAMP Apache Templates to support this transition

Steps one and three are really no-brainers, however step 2 may be hard to accomplish to the unix noob master. Here is the sacred command that will do just what needs to be done:

sudo ipfw add 100 fwd 127.0.0.1,8080 tcp from any to any 80 in

Text

I was faced with a recent challenge to maintain a legacy MySQL table with some 20 000 000 (twenty million) records having the following structure: 

  • submission_id INT UNSIGNED NOT NULL
  • field_id INT UNSIGNED NOT NULL
  • value BLOB
  • cache BLOB

However simple the table looks, there failed a unique key over the field combination (submission_id, field_id) which resulted every once in a while in duplicate values. All of this is usually no problem, yet updating the table to support partitioning required to have a primary key over the two columns, and creating such needed to get rid of the duplicates first. 

Not being a fan of heavy patches, temp-table generation and other resource-hungry procedures I started digging through the MySQL documentation in hopes to find some sacred SQL command to do a mongodb-like drop-dups query while creating a key.

Now guess what, there is a quirky for that in MySQL too, it sounds like this:

ALTER IGNORE TABLE table_name ADD UNIQUE (submission_id, field_id)

How cool could that be?

Text

For the openminded I have put together a small PostgreSQL Database of countries with their dialing codes. Feel free to use and re-distribute without any copyright whatsoever.

Simple HTML DOM Parser in PHP

Now that is honestly an AWESOME project. Get the power of almighty query-like DOM selectors when parsing html/xml files with php. This is really and honestly a fresh breath of awesomeness!

Text

When it comes to MySQL then Google does not hide many mysteries on how to optimize your queries to make them as efficient as possible. The usual advice boils down to rather simple things such as: index all columns used for filtering/sorting/joining, avoid having lots of outer joins, limit selection sizes et cetera. There are some revelations, however, one may come about when analyzing the way MySQL stores data on disk for really large datasets, and I would like to share a small tip with you :)

In case you are using an InnoDB Table in MySQL (and you most probably are using one) with a reasonably large dataset then you should do your homework on Clustered Indexes and how they can be cooked. The official documentation boils down to the following:

  • InnoDB Tables use the table’s Primary Key as a clustered B-Tree index.
  • Insertion into the middle of the table is slow as large part of the B-Tree has to be rebuilt
  • In case you decide to update the primary key, then the data will be physically relocated on the hard disk.
  • All secondary keys actually reference the primary key from the clustered index

Being equipped with that knowledge one can optimize otherwise slow queries with little change to the source code.

Read More

Text

It is common knowledge that the MongoDB Primary Key referenced to as “_id” contains quite a bit of valuable information. Here is a quote from the official documentation that references the info byte-by-byte:

The format:

01234567891011timemachinepidinc

  • TimeStamp. This is a unix style timestamp. It is a signed int representing the number of seconds before or after January 1st 1970 (UTC).
  • Machine. This is the first three bytes of the (md5) hash of the machine host name, or of the mac/network address, or the virtual machine id.
  • Pid. This is 2 bytes of the process id (or thread id) of the process generating the object id.
  • Increment. This is an ever incrementing value, or a random number if a counter can’t be used in the language/runtime.

Whereas I personally see little use for the machine code, pid or the increment when developing high-load applications, there is certainly a lot of potential in getting the created timestamp from the ID for various usable operations.

The PHP Drivers returns a MongoID object associated with the array key “_id” for almost every MongoDB Operation. Getting the timestamp from that object is dead-trivial, just use the following syntax:

$mongoDBDocument['_id']->getTimestamp();

And voila, you have a unix timestamp of when the document was inserted into the database.