Posts Tagged‘improvement’

Know Thyself, Genetically Speaking.

The body is a machine, one that consists of innumerable complexities of which modern science is only just beginning to get a grasp on. Still even with our admittedly limited understanding of how many of the bodily functions work we’re still able to figure out how to optimize its performance at various tasks. To that end I’ve personally read through reams of research to find out what I can to do maximise many aspects of my life, from my fitness to my cognitive faculties and even to my skills as a gamer. Of course my process lacks much of the scientific rigour that I’ve come to admire so more often than not I’ve found myself pursuing something without doing the right amount of research into it.

23andmekitOne of the many things that’s been on my to do list for a while was to get my DNA sequenced by 23andMe to find out what my genetic profile is like when compared to the rest of the world. Whilst I’m already somewhat aware of the health risks that run in my family I’ve always thought it would be good to backup the anecdotes with a little bit of data, even if it was only a single sample point. I’m also lucky enough to have a wife who understands biology on a level that far surpasses mine so the possibility of me finding out that I have a propensity for a rare genetic condition and flying into a wild panic are somewhat diminished.

However it seems that others aren’t so lucky and upon finding out the results of their 23andMe test are seeking treatments for conditions which may be completely unnecessary. This has since prompted the FDA to serve 23andMe with an enforcement action, essentially a cease and desist order giving the company a couple weeks with which to comply with them or face the consequences. Honestly when I first heard about it I was wondering why the FDA would bother targeting them, indeed I thought the kinds of people interested in such data would be well equipped to interpret it, however reading over one particular case showed that 23andMe could stand to use a little more rigour.

Of course the big issue here is people using this data in a vacuum and failing to consult with others to get clarity on what the numbers mean in the real world. My sister in-law found herself in a similar situation recently when the doctors refused to guarantee her child would be free of downs syndrome. The reality is that it’s simply something that we can’t rule out, no matter how good the indicators are, however when the chances are on the order of 1 in 100,000 or greater you have to understand that the risk of it actually happening is quite low. 23andMe results need to be taken in a similar light and in the event should they predict something horrific the next stop should be a genetic counsellor, not the surgeons knife.

I still plan to use the service one day as whilst my primary focus would be looking for potential treatments to improve parts of my life I’m also very interested to see what statistics has to say about the things locked away in my genetic code. Whilst I’ll likely research anything that I feel might be a threat I’ll be sure to temper that research with advice from people more qualified on this area than me. Perhaps this is something that 23andMe should look into doing as whilst it’s nice that they don’t alert you to potentially life changing facts without warning you first getting some context from a real person would probably go a long way to solving their problems with the FDA.

Why I (and You Should) Blog.

I was never a big fan of writing. I’m a very stereotypical nerd/engineer in that respect as I always struggled to get my thoughts down on paper, especially when I was told I wasn’t elaborating enough. I became frustrated with the arbitrary word counts as everything I needed to say could be summed up in a couple paragraphs and struggled with gathering supporting arguments. It got easier when I started writing documentation professionally, since all you really need there are the facts, but I only really started to enjoy writing about 6 months after I started this blog when I started to force myself to punch out at least 1 post per weekday.

I’ll be honest with you though, I still struggled with the basics for quite a while. Back then inspiration was a lot easier to come across than it was today (thanks to me not having a massive back catalogue of stuff I’ve already written about) but writing anything more than 500 words was a complete chore as the engineer in me yelled continually that anything more was just me waffling on. Over time however I came to realise just how to trigger that part of my brain that knows how to break down a subject into several key points that I can then turn into a paragraph each and now I routinely find myself writing 1000~2000 word posts on things that I’m passionate about.

Of course the small bit of recognition I get amongst my friends and peers for my various musings here go a long way to keeping me coming back to continue writing. It’s why whenever I hear about a friend starting up a blog I’ll link to them, subscribe to their blog and comment on their posts as I know how hard it is when you’re first starting out. I was shouting into the darkness for a good year before I got anything above what I’d classify Internet background noise so I know exactly what it can feel like to do something with seemingly no return. Of course most of the benefits don’t come from page views, but they certainly help to keep you on track to improving your writing (and hopefully other aspects of your life too).

Now I don’t necessarily recommend doing what I do exactly as whilst it’s been immensely helpful for me it’s also had the rather undesirable side effect of giving me a crazy OCD for getting a post out every day. Whilst some of my most complimented bits of writing come from the days when I have to drag inspiration kicking and screaming out of the dark reaches of my brain it would probably be a whole lot better, at least creatively, if I only wrote when the inspiration hit me. Indeed some of the best blogs I read come from those who only write when they really have to. That’s not to say that all my posts are forced out (the majority, thankfully, aren’t) but unless your goal is SEO and page views blogging or writing whenever suits you is probably the best option.

I’d also go out on a limb and say that any sort of online creative expression (whether blogging, vlogging, tweeting or whatever) will help you better yourself in some way. Of course I think some mediums are better for certain things (blogging is best for writing, of course) but giving yourself some sort of creative outlet, even if you think you aren’t that good, will do wonders for you. Sure many people already have these, especially those who make a living off their creativity, but having your own place of expression where only you are in control is definitely something worth having.

I’m not going to say that everyone in the world should blog, more that if you’re looking for a sure fire way to improve your writing and being able focus your thoughts then starting a blog might be the way to go. Plus there’s always the possibility that what you jot down will gain you an audience that will keep coming back for your musings, something that’s extremely gratifying (even the trolls, to a point). Hell if you’re worried about what people might think then just open up notepad every time you want to write something down and save the files off in some random location. Even doing that I think you’d be surprised of the improvements after a while, I know I certainly have.

The Build, The Results and The Tribulations.

So last week saw me pick up the components that would form my new PC, the first real upgrade I have bought in about 3 years. Getting new hardware is always an exciting experience for someone like me which is probably why I enjoy being in the datacenter so much these days, with all that new kit that I get to play with. I didn’t really have the time to build the PC until the weekend though and so I spent a good 5 days with all the parts laid out on the dining table beside me, begging me to put them together right now rather than waiting. My resolve held however and Saturday morning saw me settle down with a cup of coffee to begin the longest build I’ve ever undertaken.

I won’t go over the specifications again since I’ve already mentioned them a dozen times elsewhere but this particular build had a few unique challenges that you don’t see in regular PCs. For starters this would be my first home PC that had a RAID set in it, comprising of 4 1TB Seagate drives that would be held in a drive bay enclosure. Secondly the CPU would be watercooled using a Corsair H70 fully sealed system and since I hadn’t measured anything I wasn’t 100% sure I’d be able to fit it where I thought I could. Lastly with all these drives, watercooling and other nonsense the number of power cables required also posed a unique challenge as I wasn’t 100% sure I could get them all to fit in my mid-sized tower.

The build started off quite well as I was able to remove the old components without issue and give the case a good clean before installing bits and pieces in it. The motherboard, CPU and RAM all went together quite easily as you’d expect but when it came time to affix the mounting bracket for the watercooling I hit a bit of a stumbling block. You see the motherboard I purchased does you the favor of having the old style LGA775 mounting holes, letting you use old style coolers on the newer CPUs. This is all well and good but since the holes are only labelled properly on one side attempting to line up the backing plate with the right holes proved to be somewhat of a nightmare, especially considering that when it did line up it was at a rather odd angle. Still it mounted and fit flush to the motherboard so there was no issues there.

The next challenge was getting all the hard drives in. Taking off the front of my case to to do a dry fit of the drive bay extension showed that there was a shelf right smack bang in the middle of the 4 bays. No problem though it looked to just be screwed in however upon closer inspection it showed that the screws in the front could only be accessed by a right angle screw driver, since the holes that needed to be drilled for a regular driver hadn’t been done. After attempting several goes with a drive bit and a pair of pliers I gave up and got the drill out, leaving aluminium shavings all over the place and the shelf removed. Thankfully the drive bay extender mounted with no complaints at all after that.

Next came the fun part, figuring out where the hell the watercooling radiator would go. Initially I had planned to put it at the front of the case but the hosing was just a bit too short. I hadn’t bought any fan adapters either so mounting it on the back would’ve been a half arsed effort with cable ties and screws in the wrong place. After fooling around for a while I found that it actually fit quite snuggly under the floppy drive bays, enough so that it barely moved when I shook the case. This gave me the extra length to get to the CPU whilst also still being pretty much at the front of the case, although this also meant I could only attach one of the fans since part of the radiator was mere millimeters away from the end of the graphics card.

With everything all put together and wired up it was now the moment of truth, I took a deep breath and pressed the power button. After a tense couple milliseconds (it seemed like forever) the computer whirred into life and I was greeted with the BIOS screen. Checking around in the BIOS though revealed that it couldn’t see the 4 drives I had attached to the external SATA 6Gbps controller so I quickly booted into the windows installer to make sure they were all there. They did in fact come up and after a furious 2 hours of prodding around I found that the external controller didn’t support RAID at all, only the slower ports did. This was extremely disappointing as it was pretty much the reason why I got this particular board but figuring that the drives couldn’t saturate the old SATA ports anyway I hooked them up and was on my merry way with the Windows install being over in less than 10 minutes.

I’ve been putting the rig through its paces over the past week and I must say the biggest improvement in performance comes solely from the SSD. The longest part of the boot process is the motherboard initializing the 3 different controllers with Windows loading in under 30 seconds and being usable instantly after logging in. I no longer have to wait for things to load, every program loads pretty much instantaneously. The RAID array is none too shabby either with most games loading in a fraction of the time they used to.

Sadly with all games being optimized for consoles these days the actual performance improvement in nearly every game I’ve thrown at it has been very minimal. Still Crysis 2 with all the settings set to their maximum looks incredibly gorgeous even if I can’t seem to make it chug even on the biggest multi-player maps. The new mouse I bought (Logitech G700) is quite an amazing bit of kit too and the TRON keyboard my wife got me for my birthday just adds to the feeling that I’m using a computer from the future. Overall I’m immensely satisfied with it and I’m sure it’ll prove its worth once I throw a few more programs at it.

Speaking of which, I can’t wait to code on that beasty.

 

Fast Scrolling UITableView: Updates for iOS 4.2.

I’ll be honest and say that most of the programs I’ve built have never really been that resource intensive so optimising them for performance really hadn’t been much of a priority. Sure there were the occasional thing that I’d catch and try to improve, like when an early copy of Geon had a dropped shadow around the map that inexplicably made it run like a dog, but for the most part I’d just code them up and leave it at that. Coding for the iPhone and other resource poor systems however does not afford me such luxuries and performance tuning the app has taken up a considerable amount of my development time, but the pay offs have been quite great.

After getting my first shot at the Lobaco app up and running I noticed there was considerable slow down when scrolling through the main list of items. Since I’m a big fan of the official Twitter app I knew that it was possible to have quite smooth scrolling even when you had multiple images and gobs of text on the screen. As it turns out I wasn’t alone with this performance problem with UITableViews (the class used for that main list display) and the developers behind it posted up some code to demonstrate how they achieved such fast scrolling.

If you follow that link you’ll notice that that particular blog post is now over 2 years old, back when the iPhone 3G was still the top offering from Apple. Whilst the code given in that blog post still functions I ran into a couple of issues implementing it in the latest SDK (4.2). The first issue you’ll hit when trying to use this code is the initWithFrame function, which is used to create your cell, is now deprecated. Whilst it should still function I could not get my code to work until I made the following change in ABTableViewCell.m:

// Copyright (c) 2008 Loren Brichter
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
//  ABTableViewCell.m
//
//  Created by Loren Brichter
//  Copyright 2008 Loren Brichter. All rights reserved.
//

#import "ABTableViewCell.h"

@interface ABTableViewCellView : UIView
@end

@implementation ABTableViewCellView

- (void)drawRect:(CGRect)r
{
	[(ABTableViewCell *)[self superview] drawContentView:r];
}

@end

@implementation ABTableViewCell

/*- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier
{
    if(self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier])
	{
		contentView = [[ABTableViewCellView alloc] initWithFrame:CGRectZero];
		contentView.opaque = YES;
		[self addSubview:contentView];
		[contentView release];
    }
    return self;
}*/

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
	if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
	{
		contentView = [[ABTableViewCellView alloc] initWithFrame:CGRectZero];
		contentView.opaque = YES;
		contentView.backgroundColor = [UIColor whiteColor];
		[self addSubview:contentView];
		[contentView release];
    }
    return self;
}

- (void)dealloc
{
	[super dealloc];
}

- (void)setFrame:(CGRect)f
{
	[super setFrame:f];
	CGRect b = [self bounds];
	b.size.height -= 1; // leave room for the seperator line
	[contentView setFrame:b];
}

- (void)setNeedsDisplay
{
	[super setNeedsDisplay];
	[contentView setNeedsDisplay];
}

- (void)drawContentView:(CGRect)r
{
	// subclasses should implement this
}

@end

The main change is to replace the old initWithFrame with the new initWithStyle. This also requires changing the super call to the UITableViewCell class we’re subclassing, but apart from that everything else remains the same. Once I had that problem out of the way my custom cells were now drawing properly and appeared to be scrolling much more smoothly than they were before. However I was noticing another strange issue with my cells, they seemed to be displaying data at random from my data array. Try as I might to find the solution to this problem I couldn’t, until went back to the fundamentals of the UITableView.

You see creating cells with a UITableView is a pretty expensive process, just as it is for any system when creating new objects. This is even more pronounced with the resource limitations of the iPhone and so the iOS SDK employs a simple trick to work around this. Instead of creating and deleting a new cell every time one is needed it will instead reuse a cell that’s no longer in use, I.E. one that’s scrolled off screen. Since the cell will usually have new data in it at this point when it comes back on screen it should redraw itself to reflect this. However it seems that the ABTableViewCell class wasn’t doing this and the only way I could get it to update the data was by clicking on the cell, which caused a refresh.

If you’re not using this class then you’ll probably never encounter this issue and I believe this is because of the way ABTableViewCell does it’s drawing. You see in order to get the performance improvement you’re basically bypassing the regular way of drawing the cell and doing it yourself. This has enormous performance benefits since you’re not doing any unnecessary drawing, but it appears that the UITableViewCell class doesn’t call the drawContentView function as part of its normal drawing routine anymore. Thankfully this can be solved with a one liner in your UITableView controller class by letting the cell know it needs to redraw itself with setNeedsDisplay:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";
	int nodeCount = [displayItems count];

    LobacoTableCell *cell = (LobacoTableCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        //cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
		cell = [[[LobacoTableCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    }

    // Configure the cell...

	if (nodeCount > 0)
	{
		Post *post = [displayItems objectAtIndex:indexPath.row];
		cell.post = post;
		if (!post.profileImage)
		{
			if (self.tableView.dragging == NO && self.tableView.decelerating == NO)
			{
				[self startImageDownload:post forIndexPath:indexPath];
			}

			cell.image = [UIImage imageNamed:@"Placeholder.png"];

		}
		else
		{
			cell.image = post.profileImage;
		}
	}
	[cell setNeedsDisplay];
    return cell;
}

I do this after I’ve done all the reconfiguration of the cell so that it’s drawn with all the correct information. The image code in this part will also trigger a redraw of the cell when it’s finished downloading the image (in this case the user’s profile picture) ensuring that it’s displayed immediately rather than when the drops out and comes back into view again. With all these fixes in place my new custom UITableViewCell works perfectly and the scrolling performance is glassy smooth.

All of the above issues I encountered after I upgraded my Xcode installation to iOS 4.2 and despite my intense Googling I couldn’t find any real solutions to these problems. If you’re a budding iPhone developer like me struggling to figure out why some things just aren’t working the way they should I hope this post gives you a little insight into what was going wrong and ultimately how to fix it. It’s these kinds of curious problems that frustrate the hell out of me when I’m in them but they’re always quite satisfying once you’ve managed to knock them over.