Fetching a large data set with Core-Data

I needed loop over a potentially large set of data stored in Core Data, but did not want to force the system to load the entire data set in memory or have Core Data constantly process faults. There seem to be several ways to do this, some easier than others. One robust way would be to use an NSFetchedResultController, but it looked a little more complex than I wanted to deal with ( and involves implementing yet another protocol).

After poking around the NSFetchResult class page for a while I noticed these methods: setFetchLimit and setFetchOffset. It turns out that these are just like the LIMIT and OFFSET keywords in SQL, which is just what I was looking for.

Using this method is just a few extra lines of code. This is what it looks like:

Custom UISwitch to show YES / NO

You can see this in action in my free water tracking application "Hydrate Yourself". If this helped you please consider downloading it and leaving a review.

One of the great things about iPhone development are that there are lots of user interface pieces that are easy to put together and customize. Unfortunately there are also a lot of pieces which don't have all the basic customizations that may people want. The UISwitch is one of those.

Here is the standard UISwitch:

Its size, colors, and ON / OFF text are not changeable. Fortunately there are several great re-implementations (and a few hacks that use restricted API calls) to modify all this. One that I am using is the RCSwitch class available here.

I made two small changes to this code, first I renamed his RCSwitchOnOff class to RCSwitchYesNo and changed the labels to YES / NO. Second I added an init method to the RCSwitch.m base class which called the usual init function but provided the default frame size. This works fine since I am positioning the x and y coordinates using the "center" property:

The final result looks and behaves just like the original UISwitch, but is actually completely rewritten using the UIControl class. My switches now look like this:

UITableView which is its own Delegate and DataSource

I spent some time tonight working out a simple class which extends UITableView and conforms to its own protocols. If you are just learning about UITableViews they can seem a little daunting, but like so many other pieces in the iPhone toolbox they are very easy to use once you get the hang of it.

If you add a UITableView to your root view it will be a box with some lines across it and you can make them move by touching and dragging in vertical gestures. In order to respond to the touch selections you must set a delegate to the class, just like any other object (Like UIButton or UISwitch). There is a second delegate called "dataSource" which is used to populate the table "cells". The delegate class must conform to UITableViewDelegate and UITableViewDataSource.

Taking Stuff Apart: Coffee Machines

These are some broken coffee machines I've had hanging around for a while. The cheapest Mr. Coffee that Walmart sells and some fancy Morphy Richards coffee/espresso machine. The fancy one was from my first and only Woot Bag of Crap - they sent me a broken coffee machine.

Rather than throw them in the dumpster I decided to take them apart then throw them in the dumpster. Here they are:
Coffee Machines Front

This Way Up: First App Submitted

Free Version and Ad Free Version

I've submitted my first app to the app store. The process was fairly easy. Hopefully a couple people will find it and be amused. At 99c this app which uses the magical iphone accelerometer is certainly a bargain.

This Way Up: Submitted

Here is a video:

Make a TAP with a MAC in Garage Band

I'm not a very fun person, so using a fun computer like a MAC is hard for me. Using fun software like Garage Band is even harder. I needed a TAP sound for a project I'm working on and this MAC is the only device I have with a microphone, and Garage Band the only program I knew of for doing audio stuff.

This is the guide I wish I had earlier today.

1. Create a new Voice project:
1. Create New Voice Project

iPhone App: This Way Up

I started working on a new project the other night.  It took most of the night but the proof of concept looks promising.  Take a look at the video below, follow the link to flickr to see it in HD.

Taking Stuff Apart: Sony TC-800B Portable Reel-to-Reel Recorder

Today we have a Sony TC-800B to take apart. This is a portable Reel-to-Reel recorder is from the late 60's or very early 70's and is the same device that was used to record the watergate tapes. Unlike the TEAC 360S I took apart last week, this machine was very easy to take apart.

The one I came across even had a carrying case, you might notice that the handle is crooked. This thing was somewhat busted up, if you look closely you can see through the window in the case that the plastic covering the reels is cracked too:
TC-800B - Front

Card Catalog to Parts Storage

Sometime last year I started kicking myself for missing the mass exodus of the card catalog.  I came to the obvious realization that these giant dressers full of small drawers would be perfect for storing small tools and parts.  Not only do they have a nice size but they're built like tanks, they're meant to be opened and closed all day long after all.

Well I finally have one, and it has been converted ever so slightly to be usable for storage.

It is on the small side, with only six drawers:
Card Catalog Conversion - Very well made

All that was really needed was to cut some rectangles from a sheet of hardboard and tack them in place with hot glue:
Card Catalog Conversion - Drawers

I can't complain about the results though, I still need to make new labels though:
Card Catalog Conversion - Done

Taking Stuff Apart: TEAC 360S Cassette Deck

Usually I treat taking something apart like a puzzle.  It is strangely satisfying to have something come apart nicely without resorting to brute force and wire cutters.

This cassette deck didn't provide that satisfaction.  It got to the point where I was taking out every screw I could find hoping something would budge.  To make matters worse it was greased up in places so by the end it looked like I may have been working on a car instead of taking apart a piece of consumer electronics.

The reward were some swanky dB meters and a pile of switches, so it was certainly worth it.

As you can see, this was scrap so there was no guilt when it came to gutting it:
Teac 360S - Top

Taking Stuff Apart: LCD Screen + Digitizer

Occasionally while tossing a scrap into the discard pile it occurs to me that the scrap is composed of multiple pieces, and that I could throw multiple scraps into the discard pile instead of just one.

That is what happened while I was throwing the broken LCD Screen + Digitizer from my GPS Screen Replacement project. From the get go this was obviously a bad idea, evident by the shattered glass. I've also taken LCDs apart in the past and know that the only piece of real interest is the polarized sheets glued to the glass, those sheets are a pain to get off so that wouldn't even be fun.

Regardless I opened it up and have slivers of glass stuck in my arm some sort of badge of honor:
LCD Disassembly

Taking Stuff Apart: Panasonic RC-6005B

When I came across this clock the first thing I noticed was that it was branded an "AM-FM DIGITAL CLOCK". This wouldn't be unusual except that there wasn't a single digital component in site, not even an LED. This is a classic "flip" clock with impressive mechanical properties that we would barely consider digital today. Not only that, but twisting the various knobs provide satisfying mechanical clunks and ticks! The thing makes a lot of noise though, so it wasn't approved for use as my nightstand clock.

The internal components of this are very similar to the clock used in the movie "Groundhog Day". Thanks to this clip I can say the actual flip mechanism is probably identical.

Here it is, in all its digital glory. Take note of the bug lodged behind the plastic - this beautiful device is dirty:
Panasonic "Digital" Clock

Taking Stuff Apart: Panasonic WV-200 Video Camera

I couldn't find any references to this camera aside from the tube - a 20PE13A which has a few ebay auctions for $50-$70 right now. If anyone knows anything about its history I'd be curious to hear it.

Since I don't know anything about it, here it is:
Panasonic WV-200 - Side

Nuvi 760 Screen Replacement

This is how I replaced the LCD in a fairly new Garmin GPS device. The thing is not designed to be consumer serviced so it was a huge pain - likewise I couldn't find any information from other people who have been through the ordeal. Everything begins on ebay, where there were several vendors selling replacement LCD's. Be sure to get an LCD + Digitizer combination, it is likely to cost somewhere between $30 and $60.

Here is the damage:

Screen Damage

Portable TV Music Visualizer

A while back I took apart a Magnavox BH3908 portable TV and promptly turned it into some sort of DIY Oscilloscope. Well another fun thing to do with these things is to hook it up to your stereo and get a music visualizer. Take a look at the video to see what I mean.

BarCamp Boston 5 - Day 2

There were some more great presentations at Barcamp Boston 5 day 2, here are some comments on the ones I went to.

Your Website Sicks! But it can be saved
This was a great presentation, he showed a lot of examples showing how things can go wrong when the balance between form and function are skewed. One example he gave was the geeksquad website, which has lots of information but doesn't have an easy way to get an overview of what they do. After the presentation a few people volunteered their websites for critique. He had a lot of great feedback for them including "You have a FAQ section, has anyone ever asked these questions?" - which got a good laugh. There was only time for two, so I didn't have a chance to volunteer this site.

He referenced smashingmagazine.com as a good source of design info.

Agile Programming Methods
This was sort of a crash course on Agile but had some nice group discussion on what tools people are using, and on what parts of Agile methodologies are really important. For continuous integration a few people were using Hudson, he mentioned Cruise Control; no one else was using Electric Commander though. Not many people using pair programming, it will be interesting to see if that ever really picks up.

When Will Immersive 3D Web Arrive? And: What you will need to do to get ready: Maria Korolov, hypergridbusiness.com
This lady was either crazy or a visionary, either way I didn't realize 3D social environments like SecondLife were getting so big. She had a whole bunch of predictions about where this technology will be in 5, 10 and 15 years.

There were some fun-facts thrown in there too, for example, some companies use this technology and enact dress codes on the virtual characters; Some platforms like SecondLife require you to use a fantasy name rather than your real name so imagine executives with names like "Star Catcher".

She also used the early adoption curve showing that this technology was still before "The Chasm".

Rule Based Programming in Interactive Fiction; Or, How I learned to stop worrying and love them declarative languages
This was a neat view on a very specific programming problem: How to design text based adventure games. It wasn't what I was expecting at all, but was a good peek into an area that I knew nothing about. He started off by describing some pitfalls to a simple Object Oriented approach, his design got bogged down by edge cases and special conditions. He finished up by talking about a prolog-esque rule based language (I'm not sure if it exists or not) where you create many rules to describe the objects and rooms and let the language crunch all the rules for a given action and give you a result. At one point he mentioned "You need a language built from the ground up which is designed to hack itself".

Don't Be a Douche - Best Practices for Game Mechanics in Your Webb App: Sachin Agarwal
This was probably the most entertaining presentation of the day, he started out using a Wii controller to advance slides and made some wrestling characters represent people in a business. A lot of his presentation was inspired by this presentation "Design Outside the Box", you should check out his blog for more.

There were some amusing quotes that stuck out:
When describing badges / achievements "evil evil awesome shit"
"Does the house win in the app your making? It should..." response to a question mentioning online poker.
After mentioning Emoticons / Emoji are popular with Japanese girls: "You know that when shits big in Japan that its gonna come here eventually"

Version Controller Discussion: Shankar
This was a round table discussion about what people are doing with version control. Most of the group were using free centralized / distributed solutions. A handful were using commercial things like clearcase/perforce/accurev. Noone used something valled Versioning Filesystem or Visual SourceSafe. A couple funny things people mentioned was having a lava lamp automatically switched on when someone breaks the build, and having a "break the build" jar where you put some money in if you broke the build.

The event wrapped up with the programming contest winners and some feedback from the audience on the event. If you have feedback update the wiki at wiki.barcampboston.org.

BarCamp Boston 5 - Day 1

Barcamp was a lot of fun, tons of interesting talks and learned a lot too. Here are some notes and reflections from the ones I attended. Unfortunately I hardly got any of the presenters names.

Hacking the Brain
This was really neat, the guy has a way to turn neurons on and off using light. He has a small worm with about 300 neurons that he tracks with a camera and shines light on to see what the different neurons do. Interesting discussion at the end about the technical limitations he's hitting regarding latency between taking a picture of the worm and being able to calculate where to shine a light.

User Experience Design for Developers
This guy (Dennis, I think) really seemed to know is stuff. He had some interesting ideas on how to design successful software and some insights that really made the points stick. Here are the notes I took:
*The end user is the worst person to ask "What do you need it to do?"
*Develop for a specific persona, be very specific.
-Jane Doe, drives a 3 year old civic because she likes value.
-Apples persona is Steve Jobs, part of their success is having a very targeted persona
-This also helps with feature creep because you can ask "Does the persona need this?"
*Describe how the software works, ensure stakeholders agree
*Create very non-visual wireframes to demonstrate the UI. "Not a prototype"
*Ask the same question 3-4 times in different ways.

openFrameworks: C++ for artists & designers : Theo Watson
This was all about a really neat framework for artists. The technical part was extremely brief so that he could get right into showing a bunch of videos of projects people have made. Probably the most surprising part was that I had already seen / heard of many of the projects he talked about! Here's a link with some videos: http://fffff.at/author/theo/

3D Printing & MakerBot/RepRap Demo
I've been a fan of the RepRap 3D printer for a long time, and the MakerBot this guy had was even cooler; Complete with blue LED's. He went through the process of how to load up a 3D model someone else made into the printer and kicked it off. Unfortunately the session ended before it finished printing!

Quick & Dirty Usability Testing: Christine M. Perfetti
This had an interesting contrast to the other usability talk. The morning one seemed geared towards making sure the software is usable to begin with and making sure the design will work, while this one was based on how to get reactions from people to find out if the design did work.

Here are the notes I took:
*Just watch the user use it
*Don't use high-tech usability labs (makes the person uncomfortable and they know they're being watched anyway)
*Bring user in, introduce the observers (first name), sit by them, watch what they do
-explain test
-give them task, observe problems
-general Q&A (How was the Experience? What was good? Bad?)
-Debrief with observers
*5 second page test
-simple, can take less than 10 minutes, can use mock ups, tells a designer if the page is clear
*Paper Prototype #1 way to start testing
-draw the screen
-user points at drawing
-person swaps paper based on what the software will eventually do
*Comprehension Test
-sort of like SAT comprehension test

Mobile Apps & Analytics
This was almost like google analytics except for mobile devices. There is a special storage component so that 100% internet connectivity isn't required. Check out http://www.localytics.com/ there is a free version of their service.

Connecting the world of cooking with Plummelo.com
Plummelo.com looks like a really cool site, I really like the allrecipies.com iPhone app though. It sounds like its getting better every week so I'll have to give it a shot.

Game programming in Ruby
Given by the same guy as plummelo.com. There were some technical difficulties so he couldn't show off the stuff he was doing. It sounded like he was using Ruby to make some sort of MMO, which sounds like crazy talk. It was also web based though so maybe the server isn't doing much?

iPhone Splash View

I found THIS useful code for a class dedicated to displaying a startup image. Essentially it adds a UIImageView ontop of the current view then animates it away. The main use case is for the startup splash and it works nicely.

However there are a few cases where it almost fits other use cases, specifically for things like an About or Other Games page which might just have some small amount of static information. All it is really missing is an additional animateIn property to mirror the existing animate property.

Adding this required a few small changes, in splashView.h:
SplashViewAnimation animation;
SplashViewAnimation animationIn;
@property SplashViewAnimation animation;
@property SplashViewAnimation animationIn;

In splashView.m, synthesize the new variable and update the startSplash method:

Now in addition to using the splashView class for a startup splash image I can use it to display other static pages like so:
splashView *mySplash = [[splashView alloc] initWithImage:
[UIImage imageNamed:@"SomeImage.png"]];
mySplash.animationIn = SplashViewAnimationSlideDown;
mySplash.animation = SplashViewAnimationSlideUp;
[mySplash startSplash];
[mySplash release];

Cloth Simulated on iPhone

I have always wanted to make a cloth simulation program. The idea of a grid of points controlled by a bunch of springs just seems so simple to implement with such interesting results. Thanks to people much smarter than me, like Thomas Jakobsen, there is a de facto algorithm for it and plenty of tutorials. I've pretty much completed the graphics part of this exercise, which means I have a variable grid that I can draw... now I just need to put in all those equations and algorithms to make it move around.

Here's a screenshot of the progress. One interesting thing in this picture are the colored parts of the grid. I allocate an array for the vertex colors but have not yet initialized it, so its just random data. The colors change a little when I make touch events.
Cloth Simulation on iPhone

Cloth is pretty much finished now, more pictures and a short video on flickr.
iPhone Cloth - Finished With Shadows

OpenGL ES - Procedurally Generated Cylinder

I'm just getting started with OpenGL on the iPhone and the first object I need is a cylinder. I created a small C++ program to generate the structures needed. The resulting cylinder looks like this:
iPhone Cylinder 1

Here is the code:

Xcode 3.2.1, Interface Builder and Outlets

First day of iPhone development and I've already hit a problem.  Using the Stanford iPhone Application Development course as a crash course the first lecture had a demo application  using a program called "Interface Builder" to hook together a bunch of pieces for a basic UI.  Well the most important part, hooking the pieces together, changed with version 3.2.  Rather than creating the outlets from the interface they must be added explicitly to the header file.

For completeness, here is the code which needs to be added (it was difficult to read from the video)

@interface MyController : NSObject {
IBOutlet UILabel *label;
IBOutlet UISlider *slider;


int value = slider.value;
label.text = [NSString stringWithFormat: @"%d", value];

Taking Stuff Apart: Bell & Howell 2143 XL Video Camera

I came across a Bell & Howell 2143 XL, a quick search on ebay showed that this thing had little to no value. Its from the 1978-1980's and is an impressive mess of electronics and machinery. This particular device is video only.

Here it is:
Video Camera - Front

Taking Stuff Apart: Oster Battery Charger

I came across a battery charger for some heavy duty animal shears.  The thing had a nice heft to it.  Inside there were a couple relays, a barrel jack, some big caps and a bunch of ICs which I haven't looked up the part numbers for.

After opening it up it was apparent the failure was a diode that somehow cracked in half.  There were magic smoke stains on the underside and everything.

Here it is, as always click the pictures for higher resolution and additional pictures:
Oster 48591 Battery Charger

SparkFun's Free Day

Today was Free Day at SparkFun and like many geeks around the world I had a shopping cart prepared in advanced (last night to be specific). At 11AM EST the floodgates were opened and the SparkFun servers ground to a halt as thousands of people attempted to claim a $100 prize.

DIY Oscilloscope


Using the portable TV in my last post I did a simple hack to convert the tube into a really really crummy oscilloscope. Most likely all it will be able to do is tell me whether the voltage is positive or negative, but thats all I really want it to do.

Taking Stuff Apart: Portable TV

Received a Magnavox BH3908 portable TV recently. I've always wanted to take apart a TV but didn't want to worry about dangerous voltages and tube disposal. Well this one runs off of 12v and the tube is very small, so hopefully neither of those will be an issue!

Its small size also makes it a great candidate for one of those fancy CRT -> Oscilloscope hacks I've been wanting to do.

Here it is:
Magnavox BH3908 Portable TV

Taking Stuff Apart: JVC TD-W254

As far as I can tell this was a pretty standard tape deck. These things have a bunch of DC motors but not much else. The potentiometer was pretty small but I harvested it anyway. Finally there were a few motor driver chips, some op-amps, push-button switches and transistors I pulled off.

Here it is:
JVC TD-W254 - Front