Camelcasing & Underscoring Strings in Objective-C

Nowadays it’s all about API’s, 3rd party services and what not. In iOS universe this means connecting to remote web servers and fetching the data in [mostrly] JSON format. This is the place where the trouble starts. It’s all fine and dandy if you’re pals with web developer that coded the service and you don’t have to “map” the web parameter names to your core data attributes. But what if you’re not?

If you still haven’t recognized the problem from post’s title - I am talking about making web_app_url_parameters to pretty coreDataObjectAttributes and back. There are many heavy-weight solutions for this. I think RestKit is one of them, but I haven’t tried it so can not speak for it.

Me? I like to be dead simple. You know, SRP’n’stuff. I wrote a couple of categories for NSString class that does exactly that. With some options. So probably there goes my “dead simple”, but none the less. And as an extra bonus I did it using TDD (mad propz to Jon Reid and Graham Lee). To make it even simpler and faster I used only C string functions and no calls to Objective-C string/array methods.

Continue →

Shared Instance of NSManagedObject

I have come upon a situation, in the project that I’m working on, where I need a single shared instance of NSManagedObject. I looked around for a common practice and there was none except for some misguiding Q&As on Stack Overflow. There were (are) probably more people than I that need this kind of functionality yet they didn’t publish their solutions. That or I didn’t try hard enough to actually find them. So I decided to whip it up.

Continue →

ZeroMQ on iOS

In the current world of startups a common recipe is to have a site with REST API as well as various mobile applications for different platforms consuming said API. But sometimes that’s not enough. Sometimes you need real-time data pushed to you as soon as it becomes available on the service provider. Some of the examples might include stock exchange price changes, chat, or score changes for a match on sports website. Here’s where ZeroMQ comes to play. ZeroMQ is described as “intelligent transport layer” and is mostly used for distributed systems which have to do loads of processing and where pipelining of different tasks can greatly improve the overall performance of the system.

Continue →

Toggling Comments

Matt Gemmell has posted rather controversial piece about the state and value of comments for the blogs. After reading a round up of various opinions on his blog I came to my own conclusion.

Continue →

Mongrel2 Profiler Filter: Take 2

I wrote about creating the profiler filter for Mongrel2 web/application server before. The filter was dead simple and measured the time it took to serve a simple request. This profiler did not include the per-connection request profiling since it saved the data into global ProfilerSession struct which recorded times of receiving the request and sending the response. Since this was just a proof-of-concept thing to get to know how one can write a filter for Mongrel2 - it didn’t have a good architecture to begin with.

Continue →

Profiler Filter for Mongrel2

So I finally found some time, desire and motivation to hack on Mongrel2. For those of you who don’t know what that is - go to its website and get amazed. I’ve decided to start hacking on Mongrel2 just by creating simple filter for profiling requests. It was done almost as easy as said. In about an hour of reading and coding I had simple proof-of-concept profiler filter for Mongrel2. The code can be found on pastebin, but just in case it gets removed, I’m dumping all of the code here:

Continue →

WSCoreLaziness Is Looking for Lazy Cocoa Developers

So today I’m announcing WSCoreLaziness. A framework which is supposed to make lazy Cocoa developers happier and more productive. I’d really like to get constructive feedback on the whole matter as this is a teeny-tiny start of something that can grow big and be really useful.

Continue →

Nifty .htaccess Trick Regarding Google+

Yesterday Dave DeLong shared a post on how you can reach his Google+ profile via his domain like this: http://davedelong.com/+. Here is a couple of .htaccess snippets which will allow you to do the same:

1
2
3
4
5
6
# Snippet used in this domain
RewriteCond %{REQUEST_FILENAME} \+
RewriteRule . https://plus.google.com/{google plus id goes here}/posts [L]

#Snippet proposed by Dave DeLong
RedirectMatch ^/\+(.*)$ http://plus.google.com/{google plus id goes here}$1
Continue →

How to Store C Structs in NSArray or NSDictionary?

There might be days when you will have to store non object types in cocoa’s collection objects (like NSArray, NSDictionary, NSSet and their mutable counterparts). I actually have a very bad imagination, but let’s say you’re using 3rd party library that provides you with opaque structs, or just plain simple struct that holds latitude and longitude coordinates of the treasure. Somewhere. So the core of this is that sometimes you want to store them in (for simplicity’s sake) NSArray. The problem is that you can store only objects (a.k.a. structs having isa pointer) in these kind of collection objects. The trick is to use a wrapper for these kind of things. The most universal wrapper for these things is NSValue class.To wrap a struct with NSValue instance use one of its factory methods or designated initializer:

1
2
3
4
5
// initialization with custom factory method
NSValue *myStructValue = [NSValue value:&opaqueStruct withObjCType:@encode(OpaqueStruct)];

// initialization with designated initializer
NSValue *myStructValue = [[NSValue alloc] initWithBytes:&opaqueStruct withObjCType:@encode(OpaqueStruct)];

The difference between these statements is that factory method returns autoreleased object. Note: You can see from NSValue documentation that it has predefined factory methods for some of standard cocoa typedef:ed structs like point, range, rect and size. Now that you have an object you can actually do whatever you want with it. Shove it into NSArray, set as NSDictionary’s value for some key (or use as a key for some other value). To retrieve wrapped struct from the NSValue object you provide it with the buffer it should fill with stored value or just get the pointer to already stored data (and dereference it if needed):

1
2
3
4
5
6
// provide the value to be filled
OpaqueStruct otherStruct;
[myStructValue getValue:&otherStruct];

// get the pointer and dereference it
OpaqueStruct anotherStruct = *(OpaqueStruct *)[myStructValue pointerValue];

Fix for “W/R Access for Gitolite-admin DENIED to User”

For those of you who have this error message when trying to push/pull to gitolite-admin repository - here’s how to fix that: Preamble and disclaimer - this is a dirty dirty way for fixing these kind of errors. First off - how you got here with no access to git repo administration on own server? This is actually only ONE of the possibilities. There’s slight possibility that you were on gitosis and migrated to gitolite using provided script (something like gl-conf-convert). The issue here is that converted config does not have the gitolite-admin repository defined with you as admin. And this is what’s causing this error (no read or write access depending on git command). You can check this by running following command locally:

user@host:gitolite-admin $ ssh GITOLITE_USER@server info
Continue →