Posts

Showing posts from 2010

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

Image
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.

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

Image
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:

This Way Up: First App Submitted

Image
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. Here is a video:

Make a TAP with a MAC in Garage Band

Image
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:

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

Image
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:

Card Catalog to Parts Storage

Image
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: All that was really needed was to cut some rectangles from a sheet of hardboard and tack them in place with hot glue: I can't complain about the results though, I still need to make new labels though:

Taking Stuff Apart: TEAC 360S Cassette Deck

Image
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:

Taking Stuff Apart: LCD Screen + Digitizer

Image
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:

Taking Stuff Apart: Panasonic RC-6005B

Image
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:

Taking Stuff Apart: Panasonic WV-200 Video Camera

Image
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:

Nuvi 760 Screen Replacement

Image
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:

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 m

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.

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] i

Cloth Simulated on iPhone

Image
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. Update: Cloth is pretty much finished now, more pictures and a short video on flickr.

OpenGL ES - Procedurally Generated Cylinder

Image
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: 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) MyConenctor.h @interface MyController : NSObject { IBOutlet UILabel *label; IBOutlet UISlider *slider; } -(IBAction)changeLabelText:(id)sender; MyConnector.m -(IBAction)changeLabelText:(id)sender{ int value = slider.value; label.text = [NSString stringWithFormat: @"%d", value]; }

Taking Stuff Apart: Bell & Howell 2143 XL Video Camera

Image
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:

Taking Stuff Apart: Oster Battery Charger

Image
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:

SparkFun's Free Day

Image
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

Image
WARNING POTENTIALLY HIGH VOLTAGE INVOLVED EVEN WHEN DISCONNECTED, DO NOT ATTEMPT IF YOU ARE UNSURE WHAT PARTS ARE DANGEROUS 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

Image
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:

Taking Stuff Apart: JVC TD-W254

Image
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: