How To detect an internet connection with the iPhone SDK

There are several ways to problematically detect if an iPhone has an internet connection, but most of them cant tell you how the iPhone is connected to the internet.

Apple has sample code to accomplish just this task. The Reachability class is not shipped with the SDK, but is part of a sample project of the same name. http://developer.apple.com/iphone/library/samplecode/Reachability/index.html

Using the reachability class:

Set up:

  • Download the reachability project from Apple
  • Copy Reachability.h and Reachability.m to your project.
  • Add the ‘SystemConfiguration’ framework to your project.

Sample Usage:

Reachability *reachability = [Reachability sharedReachability];
 [reachability setHostName:@"www.JoshHighland.com"];
 NetworkStatus remoteHostStatus = [reachability remoteHostStatus];

if(remoteHostStatus == NotReachable) {
 //no internet connection
 }
 else if (remoteHostStatus == ReachableViaWiFiNetwork) {
 //wifi connection found
 }
 else if (remoteHostStatus == ReachableViaCarrierDataNetwork) {
 //EDGE or 3G connection found
 }

Kicking it, the Muay Thai way

sit rama soon logo

I have been training Traditional Muay Thai (Thai kick boxing) for 3 years now. It’s a brutal sport, and I have the scars to prove it. It’s also a very rewarding activity for me.

I train at “Sit Rama Soon” (English Translation: Students of Rama Soon), under the direction of Kru Jay and Kru Joey. Both are former champion Muay Thai fighters from Thailand. Recently my coaches started posting videos of training sessions that they have filmed over the years, including this video of me teaching a new student how to throw a proper muay thai kick. I was unaware of my coaches filming this.

coachs_josh

What I am trying to show here is that the kick is more like a baseball swing, and your knee and hip placement are more important then your lower leg. You can almost think of your lower leg and foot as the end of a whip.

[youtube]http://www.youtube.com/watch?v=JIzvHYWGvY4[/youtube]

How to throw a Muay Thai kick:

  1. Step in with your lead leg, turning your foot to a 45 degree angle
  2. Lift your rear leg, elevating your knee to the desired height
  3. As your leg raises, drop the same arm (right leg up – right arm down)
  4. Point your toes down (stand on your toes of the planted foot, point toes of the kicking foot)
  5. Turn your hips hard into the direction of the target, your hips should be verticle in impact
  6. Point your knee to the opposite side of the target (imagine the target isnt even there)
  7. Your shin should land on the target, NOT YOUR FOOT.
  8. Once the kick lands, push hard into the target
  9. Return to your fighting stance

It’s a lot of steps, but once you can make it all one solid flowing motion its a very powerful weapon. A good thai kick often has more striking power then a baseball bat.

sparing

Removing trailing comas with PHP

php_logo_mediumDealing with trailing comas in lists is common problem for developers. I found the best way to handle this situation in PHP is with the following regular expression.

$string = eregi_replace(',$', '', $string);

Before: string = “2, 6, 9,”
After:
string = “2, 6, 9”

Only the trailing coma will be stripped. If no coma is found, the string simply passes through. It’s a simple and effective solution.

20% of Twitter updates are about brands

twitter-bird-money-eyesTwitter is wildly popular and dominates the social media space. Penn State University recently conducted a study and found that 20% of all tweets (twitter updates) contain requests for product information or responses to the requests.

Twitter, with its six million active daily users (and predictions of more than 20 million users by the end of the year) is

“about as close as one can get to the customer point of purchase for products and services”

according to Jim Jansen, an associate professor in the College of Information Sciences and Technology (IST) at Penn State.

You can read the entire case study here