How to find my own IP address in CentOS

Two commands come to the rescue: ip and ifconfig. Either does the trick: #ifconfig eth0 eth0 Link encap:Ethernet HWaddr 00:19:99:0D:D2:58 inet addr:87.106.181.234 Bcast:87.106.181.234 Mask:255.255.255.255 inet6 addr: fe80::219:99ff:fe0d:d258/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:14022830 errors:1 dropped:0 overruns:0 frame:1 TX packets:17605482 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:6842851425 (6.3 GiB) TX bytes:22015650673 (20.5 … Read more

How to convert a UIImage into NSData

You can store a UIImage (or an NSImage on Mac) as raw data. This can be useful if you’d like to save this in Core Data. Here’s how you convert a UIImage into NSData: NSData *imageData = UIImagePNGRepresentation(yourImage); To convert NSData back to a UIImage, you can do this: UIImage *image = [[UIImage alloc]initWithData:yourData]; The […]

How to fix Core Data error: “Receiver type xxx for instance message is a forward declaration”

Core Data is great. But when you add it to an existing project Xcode throws some random error messages at you that make you doubt your sanity. Again. Legitimately copied and pasted code from Apple’s own templates generates totally useless errors such as Receiver type ‘NSManagedObjectContext’ for instance message is a forward declaration. This isn’t […]

How to add 64bit support to your iOS apps

Apple’s new A7 processors support 64bit under iOS 7 – but only if your app is specifically compiled for 64bit. Ideally you want to compile once and use 64bit if the architecture supports, and if not use 32bit for devices that have A4 – A6x processors. Since Xcode 5.0.2 you can do this, and here’s […]

How to read the contents of a file into a string in PHP

file_get_contents() can help us here. It reads a file and stores it in a string. Can be used with local files, as well as online content: $myLocalFile = file_get_contents(‘myfile.html’); $myOnlineFile = file_get_contents(‘http://wpguru.co.uk’); echo myOnline File; // would display the actual website This is different from the file() function which reads the contents of a file … Read more

How to replace text inside a string in PHP

If we have a string and would like to replace a portion of it, we can use the str_replace() function in PHP. It works like this: str_replace (‘whatToReplace’, ‘theReplacement’, ‘originalText’); It’s easy to remember… but I always get confused when I look this up in the manual. Here’s an example: $originalText = “Now is the … Read more