Solving NSURLConnection leaks

June 29th, 2009

Recently I was having a problem with NSURLConnection showing memory leaks in Instruments even though it was being correctly allocated and released. On investigation it seemed the problem may be lying with the cache policy, however I was using NSURLRequestReloadIgnoringLocalCacheData in the NSURLRequest to completely ignore any caching requirements and was confused as to why allocation problems would then be associated with caching.

I’m still not exactly sure what the problem is (according to this thread it may be due to having the NSURLConnection run in a method that’s detached from the main thread) however, forceably setting the capacity of the URL cache before initiating the connection using the URL request seems to solve the problem. For example:

[[NSURLCache sharedURLCache] setMemoryCapacity:0];
[[NSURLCache sharedURLCache] setDiskCapacity:0];
 
NSURLConnection *connection =
	[[NSURLConnection alloc] initWithRequest:request delegate:self];

Hey presto! No more NSURLConnection leaks.

Leopard OS-wide umask support

February 19th, 2009

Recently at work we noticed problems with files and directories on network shares (namely SSHFS via Macfusion) that weren’t set to group write even with -o umask=0002 in the extra options field of the SSH Advanced tab in the mount options. Viewing the FUSE mount via its system directory would show group write, however logging in with traditional command line SSH would show the files and directories not to have it.

The simpler solution therefore would be to set umask system-wide, for GUI and CLI in Leopard, so it would be applied to everything without worrying about individual configuration options on our SSH, NFS and Samba mounts. A quick Google search revealed a recent Apple Support article that offered a convenient solution – a file named launchd-user.conf stored in /etc that holds a single line with your umask requirements, e.g.:

umask 0002

I’ve created a package installer which you can download at the link below that installs the file for you if you’re not comfortable adding it yourself. You’ll also need to restart after you make these changes.

LeopardUmask.pkg

Caveats:

  • The Apple Support article notes that it is for setting a system-wide umask in 10.5.3, brief research indicates that you may require at least this version of Leopard for it to pick up the umask from the file.
  • As the file is located in /etc, it will set the umask for all users – a possible solution for individual user support would be to place a custom launchd-user.conf file in your home directory (~/launchd-user.conf), though I haven’t tested this.

iPhone, Mac calendar collaboration with Google Calendar

November 26th, 2008

My boss came to me this morning with an interesting conundrum – could we come up with a push-compatible synced calendar solution for the company computers and mobile devices, as free as possible, without having to run an Exchange server. The stipulations were that it had to be push-compatible, dynamically synced and had to allow the continued usage of private calendars on mobile devices (namely the iPhone). There were many half-way solutions that involved subscriptions to private calendars and iTunes syncing, but we wanted something a bit more on-demand and universal.

Our first thought was to make use of the (in this case, rather lacking) capabilities of Leopard Server running on our office Xserve – this was, unfortunately, the first stumbling block; as Leopard Server’s CalDAV implementation in iCal Server lacked the ability to push any changes made down to our devices.

Several hours of research, dead-ends and spurious theories later we came up with the solution – iCal and iPhone calendar harmony, with a little help from Google and an excellent (and free) service called NuevaSync.

1. Backup

As always, back up your current calendars and settings – that includes your mobile device. Changing your current calendar setup will inevitably result in losing some data, especially on the iPhone where all current calendar data is lost when switching to a new one in the process outlined below.

2. Create your calendar

The first step is to create your shared, collaborative calendar. This is done with Google Calendar, namely as it’s the easiest calendar program to integrate into various client solutions (including the following ones), with the added benefit that you can guarantee yourself access on-the-go with Google’s own web applications. You must however be prepared to hand out the login credentials of the Google account used to create the calendar – as the following steps require that level of access. The easiest thing to do is to create a unique Google account specifically for your shared calendar.

3. Sync it with your computer

Google publishes private “feeds” from within Google Calendar that allow you to view the calendar if it’s not set to public (which would rarely be the case), but these are read-only and offer limited flexibility. For that we turned to Google Calaboration, which implements CalDAV to support real-time, dynamic calendar syncing. Google currently supports iCal v3+ (Leopard onwards) and Mozilla Sunbird, which was cross-platform enough for us.

iCal integration is as easy as selecting the calendars you wish to use

iCal integration is as easy as selecting the calendars you wish to use

Sunbird integration is simple as per the instructions, and iCal setup involved simply downloading an application from the above link, entering your Google account name and password (as mentioned above) and selecting the calendar to be synced – this creates a new calendar entry in iCal, that will dynamically sync with your Google calendar in real-time.

Our Google calendar now appears in iCal, fully editable

Our Google calendar now appears in iCal, fully editable

4. Add the calendar to NuevaSync

As mentioned before, NuevaSync is an incredibly handy (and more importantly, free) service that is crucial to creating the push-compatible calendar environment we need. This is because it takes your Google calendar and runs it through an Exchange server complete with ActiveSync capability, which will push any changes to your mobile device as long as it supports it (including the iPhone with software update 2.0 and above). Creating an account and adding your calendar with NuevaSync is easy, and well documented at their site. Once you’ve done this, you’re ready to add your calendar to your mobile device. In this example, we’ll use an iPhone.

5. Adding the calendar to your iPhone

As we mentioned before, NuevaSync makes use of Microsoft Exchange functionality, so we added a new Microsoft Exchange account to the iPhone by going to Settings -> Mail, Contacts, Calendars -> Add Account… This will give you a list of account types, and obviously “Microsoft Exchange” is the one we’re looking for.

You’ll then be presented with a list of options, the meaning of each in relation to your NuevaSync/Google Calendar accounts is documented on the NuevaSync site, but in brief Email is your Google accounts email address, Server (which may not appear until you’ve clicked the “Next” button after entering the other account information) is www.nuevasync.com, Username and Password are your NuevaSync details and Description can be anything you like.

Once you select “Next” you can turn off Email and Contacts and turn on Calendars for the new account, and you may be prompted to delete your existing calendar data if some exists on your iPhone. As you’ve already backed up your data anyway, you can safely accept this. Voilà, you should have a fully synced, push-compatible calendar on your iPhone tied to your Google Calendar account.

Thankfully, our iPhone can have a Christmas Day too.

Thankfully, our iPhone can have a Christmas Day too.

6. Private calendars, too

Our other stipulation was that we had to also support staff members’ private calendars (as their phones are necessary to organise all aspects of their life, not just work) without updating the shared collaboration calendar. Unfortunately, as far as we can tell, this is (currently) the only non-free area with regards to our setup. Once Exchange calendar syncing is turned on on the iPhone, it will no longer allow you to sync your calendars with iCal, and only one Exchange account can exist on the iPhone, barring any multiple NuevaSync/Google calendar options. Our solution to this was to use MobileMe, which it turns out was a fairly convenient solution – the iPhone allows Exchange and MobileMe accounts to coexist, and MobileMe will push any iCal calendars (excluding our Google one) to your iPhone and vice-versa. The Family Pack version of MobileMe appears to be the most cost effective solution – it supports 5 accounts, each with push calendar ability, working out at £17.80 per staff member.

So there you have it! iCal to iPhone shared, collaborative, push calendar ability with cross-platform support additionally with private calendars with some help from Google, NuevaSync and MobileMe. At least until OS X Server 10.6, anyway…

List of caveats:

  • It’s not completely free with regards to a Mac/iPhone setup, but it’s damn closer than with Microsoft Server and Exchange licensing thrown into the mix.
  • The calendar isn’t truly collaborative, as it’s effectively multiple users editing the same calendar. This means that any events are editable by anyone, and it’s hard to keep track of who added what. Thus it’s only really effective for smaller organisations.
  • There may be additional roadblocks with regards to other mobile platforms, including Android and Symbian. As we’re a company largely devoted to Apple’s hardware (at least amongst those requiring push calendar support) I’d appreciate any comments/feedback on other mobile platforms.

Ramblings has moved…

March 2nd, 2008

…to a more stable and permanent location. But it will still be chock full of the latest and greatest crap.

SCO

September 17th, 2007

You may know SCO (but probably won’t) as the company that tried to sue some of the major Linux vendors accusing them of copyright infringement based on it’s ownership of the UNIX source code copyright. It assumed that Linux contained UNIX source code, and that it owned the copyright for it – neither of which turned out to be true. It was p0wned in the courts (mostly thanks to the Novell case in which ownership of UNIX source code was found to be with Novell), hounded by Linux fanboi’s and eventually filed for Chapter 11 bankruptcy last week to the cheers of, well, pretty much everyone except SCO. Anyway, the point of all this is that there’s been some rather imaginative and amusing headlines on tech and IT news sites and blogs as a result, which I’d like to feature here:

Paul McNamara, Network World: “SCO files Chapter 11, threatens business as usual”

Egan Orion, The Inquirer: “SCO files Chapter 11 bankruptcy – Seeks court protection from its own lawsuits”

And my personal favourite,

John Paczkowski, All Things Digital: “Chapter 11, in Which SCO Finally Gets What It Deserves”

YouTube

October 20th, 2006

I’ve had several people ask me recently why on earth Google would want to buy YouTube, considering the fact that 1) they already have an online video service (Google Video) and 2) people keep going on about how YouTube is breaking copyright law, several hundred thousand times over. There were many specific questions, some pondering, some interesting and others lacking in point: who on earth would want to take on a company that is perceived to be in so much trouble with the major media conglomerates? Will Google change YouTube to the point that I can’t watch TV ads from 1997 anymore? How on earth do they make any money considering they don’t sell anything? How will this affect me, considering I spend most of my waking day searching through YouTube for videos of Borat? Let me quell your fears with some hearty breakfast facts!

YouTube makes money. Lots of it. Thousands per day. There’s adverts on YouTube – and along with Google’s philosphy, adverts = money. With so many users visiting the site on a daily basis, it’s not hard to see that they’re making a lot of money from people simply willing to look at the adverts. More importantly, YouTube is a market leader, and is therefore of great interest to venture capitalists, who like to affirm they’re faith in taking humungous risks with large sums of cash by plugging money into whatever catches people’s interest. Sequoia Capital has invested around $12 million in YouTube alone.

The more important point, however, is that of why Google would want to buy a company that is under such scrutiny from eager beavers waiting to pounce with any number of copyright lawsuits in hand. After all, once being snapped up by a company with literally billions in free capital, wouldn’t IP enforcement agencies and their lawyers not be even more eager to pursue what are for the most part largely legitimate cases against one giant rich offender? The point largely missed, even by big firm financial analysts, is this: that Google doesn’t necessarily have something, indeed anything, to gain by snapping up YouTube – it may in fact be a logistical headache – but that it has the most to lose by not taking the site under its umbrella.

YouTube is a fairly small company despite it’s market position. It has, by latest figures, 67 employees in the company – in comparison to this, Google has a figure approaching 10,000. The chances are the large part of these are IT professionals in one sense or another; project managers, web developers, hardware administrators etc. who organise and maintain the day to day running of the site. The chances are equally similar that although having legal advisors, they’re legal department doesn’t approach the kind of bait-requiring complexity that Google enjoys. In the face of several convincing IP lawsuits, and with it’s very obvious position of breaking IP law across the board, it’s unlikely that YouTube would have been able to hold its own and would have had to cave on several key positions. In this scenario, it would be Google that would have come off worst. Cases like this would have had a tendency to set precedent on several battlefields that Google itself is currently fighting on. It’s own video service, news and most importantly book search have come under intense criticism over the past year or so from those most readily defending copyright law in the US. It’s important that in these cases that others are fighting, the outcomes swing in Google’s favour, otherwise it would have found the going increasingly tough in getting it’s way in such situations. YouTube was in the unfortunate position of being the most vulnerable to these kind of attacks; having a site who’s infrigement is blindingly obvious, but being so weak in corporate terms so as not to be able to defend itself. Google’s acquisition was simply giving it the ability to allow its own legal team(s) to take care any such matters, rather than to affect the service and its millions of avid customers.

In the end, Google had very little choice – the $1.65 billion fee wasn’t so much for YouTube itself, but for the peace of mind that the major internet copyright battle was still left for Google to fight.

Under Surveillance

May 14th, 2006

I went to Manchester to see Dave Matthews friday, having left the world to read my recent interview, and I’ve come back with some interesting web stats, as the following image shows:

Web stats by country

Some of the countries stand out as being rather out of the ordinary. Most of these are fairly explainable though – the chances are somebody in France is going to have the intelligence to use a computer. Even a DMB oriented member of the US military might find themselves perusing the internet, it’s not as if there’s anything going on in Iraq at the moment. But the sudden jump in the number of hits from the US Government is what disturbs me the most, especially considering they don’t appear on the stats at all before May. Perhaps there are some more liberal minds in the overly right-wing Senate and House of Representatives. Or, far more likely, Dave is part of some massive Republican conspiracy. Perhaps those indicted in the CIA leak case will turn out to be Rove, Libby and Matthews?

Either way, I seemed to have gained a new audience as a result of my foray into semi-professional journalism. Other interesting tidbits from my stats:

- “england football club” is my second highest search string click-through (after “nancies uk”)
- Britney Spears is featured in 5 of my top 20 search strings
- Thanks to my site URL being misquoted in the DMB Rhyme & Reason newsletter I was featured in (as nancies.uk) people have had to search for that URL in Google to find my site. With all the spying going on it’s probably not a bad thing, to be honest.

Road to Newbury

March 28th, 2006

On a whim, over a Subway, Josh and myself decided last Wednesday lunchtime to travel to his home town of Newbury because he had to pick up a book, and I (apparently) had to sample a highly recommended burger bar that went by the name of “Rio’s”. Classy. So I, obviously having nothing better or more important to do, forked out the necessary £20 train fare to get from here to there (with a brief stopover in Reading to er, “assess” the place) and indulged myself in a town apparently more pretentious and upper upper middle class than Frimley.

Rio’s wasn’t fabulous. Although I think that’s a lot to do with the fact that I didn’t get the “Rio 2000″ which combined 1/2lb of beef and 1/2lb of chicken. However, on a trip to the local (which had no bitter!) Josh and I heard a rather random Dave Matthews Band song (on some kind of playlist streamed from a cable company that provides music to pubs, go figure) and also managed to break the quiz machine by forcing a 404 error on a government website available on the machine, then subsequently managing to load Outlook by randomly clicking on email addresses that appeared. We left soon after.

Dear Mr Blair

March 14th, 2006

I was musing with Josh this evening about the Computer Misuse Act and its apparent vagueness in 1) what contemplates actual misuse, and 2) the punishment one would receive in offending it. There are plans in the works to introduce a new bill which would update the current computer misuse specifics, especially in regards to network-based attacks, such as Denial of Service attacks and the production and promotion of tools which aid these (which is where a lot of vagueness on behalf of the government comes in again).

So this got me thinking – I couldn’t knowingly carry out a DoS attack on a specific target without incurring what appears to be some serious penalty (like several years in prison). So why not just apply the same logic to the new computer misuse act in the same way the government and legal system applies laws and penalties to non-tech situations?

For example; the law declares that it’s perfectly legal to protect yourself from assault using “necessary force” for “self-defence”. At the moment, if someone were to attempt to DoS me, and in retaliation and “self-defence” I quickly DoS’d them back, myself and the offending party would face prosecution under the computer misuse act. However, my attack was only in self-defence, in order to protect my(computer)self, so I think I should be immune to any prosecution.

And onto another example, the “pre-emptive strike”. The government seems to think this is a perfectly fair, reasonable and legal stance to take in the 21st century. After all, if I’ve got the name of a suspected spammer, and have the tools at my disposal to stop him before he has the chance to spam me, shouldn’t I be allowed to?

The Beatles

January 20th, 2006

I don’t listen to the Beatles particularly often. They are repeated the least on my general circulation of albums, and I’m very fussy about what actually gets on to my iPod – with artists or albums that I listen to less often I tend to cream off the really important or personally enjoyable stuff so I can guarantee that’s what I’ll hear when it does come on. As a result, they eventually spring up in conversation with friends and family. And I’m genuinely surprised by the number of people who don’t understand the Beatles, and their purpose in modern musical history. Nine times out of ten I’ll get the reply of “I don’t really understand what the fuss was all about” – and this isn’t from not liking them, its purely from a lack of understanding. You may not like quantum theory for some reason, but there is a fuss to be made. However, I also found it very hard to actually explain to people not so much why they were good, but why they were, and still are, so important. A lot of the problem stems from the fact that music that was so original and impossibly hard to produce, music that required such ingenuity and creativity unheard of at the time is fairly easy to replicate on an iMac these days, and in some way or another finds its way into the latest manufactured goop. Building a PC from components is a doddle for anyone with even a limited amount of technical knowledge these days, but trying to do it in 1902 would have been a real challenge. So where does this all come from? I read a quote in The Salmon of Doubt today that in a single paragraph neatly explains why the Beatles were great even if you like them or not, which I can just repeat to people if need be. Laziness triumphs once more…

“I didn’t know it was art then, of course. I only knew that the Beatles were the most exciting thing in the universe … you had to fight the grownups, parents and teachers who said that you were wasting your time and pocket money on rubbish that you would have forgotten by next week.

I found it hard to understand why they were telling me this. I sang in the school choir and knew how to listen for harmony and counterpoint, and it was clear to me that the Beatles were something extraordinarily clever. It bewildered me that nobody else could hear it: impossible harmonies and part playing you had never heard in pop songs before.”