Technology Musings

May 18, 2011

Platforms / Blocks in Objective C

JB

Blocks is a new feature of Objective C that was announced roughly at the same time as Apple announced Grand Central Dispatch.  I haven't had the time to look into it thoroughly, so I'm sticking my bookmarks here for future reference:

May 11, 2011

Platforms / Using Indexes on LIKE queries on PostgreSQL

JB

Apparently, under some configurations (I think they are compile settings dealing with the locale), PostgreSQL will not, by default, use an index for LIKE queries.  First of all, note that PostgreSQL will NEVER use an index for an ILIKE query (case-insensitive like).  For that, you should use a functional index using the LOWER function.  It will also not use an index if the LIKE starts with a wildcard.  But, for queries that *end* in a wildcard, if you set it up right, you can get PostgreSQL to use an index.

Anyway, apparently the problem is that PostgreSQL doesn't know what locale it is in, and therefore doesn't know how to order the characters.  Therefore, you have to give it some help.  After your index column, you need to add text_pattern_ops.  So, for my own table, I did the following:

create index entity_lower_name_idx on entities(lower(name) text_pattern_ops)

And viola!  Postgres is now using the index.  Since this is a functional index, it indexes queries like

select * from entities where lower(name) like 'hello%'

Hope that helps someone!  I received the information here and here.

May 05, 2011

Platforms / Making Reusable iPhone Widgets with Interface Builder

JB

One annoying thing about Interface Builder, at least for the iPhone, is that there is not a direct way of making reusable widgets that are both made *in* Interface Builder and *for* Interface Builder.  I came up, though, with a set of instructions and helpers that make the process fairly painless.  The class is called IBView, and should be used as the parent class for your reusable widget.

Here's how to create the widget:

  1. Create a class for your new widget, called MyWidget.  Inherit from the IBView class (code provided below).  Create all of the IBOutlets you want for your widget.
  2. Create a view with the same name as your widget class in Interface Builder.  If your widget was named "MyWidget.m" then your interface should be called "MyWidget.xib".  DO NOT set the class of this view or any subview to be of the MyWidget (or whatever class you are create) type.  DO NOT do it.
  3. Set the "File's Owner" of your interface in Interface Builder to be the name of the class that you are creating - MyWidget in this case.
  4. Set up any connections you want between your IB view and File's Owner (i.e. your widget).

Now, your widget is created.  You can now use the view in any IB panel by doing putting in a generic UIView, and setting the class name to your new class (MyWidget in this case).

Important caveat - one consequence of creating the view in Interface Builder is that there will be an extra view between the main view represented by your class and the rest of the elements of your class.  Basically, your custom view acts as a generic view, and then *loads in* your Interface Builder file as a subview, meaning that the toplevel view in Interface Builder will sit under your MyWidget view.  This is usually unimportant if you are just using IBOutlet stuff, but if you do advanced view management, it would be important to know that a view sits between you and the rest of your sub-widgets.

Okay, here is the code for IBView.m - just very simple code, with a tiny bit of Objective-C magic thrown in:

#import "IBView.h"

@implementation IBView

-(void) loadViewsFromBundle {
NSString *class_name = NSStringFromClass([self class]);
NSLog(@"Loading bundle: %@", class_name);
UIView *mainSubView = [[[NSBundle mainBundle] loadNibNamed:class_name owner:self options:nil] lastObject];
[self addSubview:mainSubView];
}

-(id) initWithCoder:(NSCoder *)coder {
self = [super initWithCoder:coder];
if(self) {
[self loadViewsFromBundle];
}
return self;
}

- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self loadViewsFromBundle];
// Initialization code.
}
return self;
}

@end

And IBView.h is super-simple:

#import <UIKit/UIKit.h>
@interface IBView : UIView {
}
@end

And that's all there is to it!

May 02, 2011

General / Readings around the Web

JB

Here's a collection of links that I have open.  Just putting them here so I can close them :)

February 09, 2011

General / Fixing Clicking Hard Drives

An Old School Approach

All right - my wife's computer died today.  It gave the Apple folder-with-a-question-mark sign which says it can't find the system software.  Booting from the install disk - I found out that it couldn't even find the drive.

In addition to that, the hard drive was making clicking sounds when the computer first turned on.

I was certain that the computer was fried.

However, I dug through a bunch of forums.  Most of them agreed - if your hard drive makes a clicking noises, then it is probably dead.  I ran through all of Apple's troubleshooting steps - nothing.  It seemed that it was truly dead.

Then, at the bottom of a forum post, a poster named "deepika" gave an amazing piece of advice.  I thought it was a joke when I first read it.  But, since the hard drive was probably dead anyway, I felt it couldn't hurt.  The advice?  It seems that the drive is having trouble spinning up.  Therefore, you have to "convince" it to spin up.  How?

  1. Turn off the computer
  2. Put the computer on a flat surface
  3. Close the computer (it's a laptop)
  4. Bang on it a few times

Seriously.

And guess what?  When I turned on my wife's computer again - it worked!

December 10, 2010

Platforms / Opening other apps from the iPhone

JB

I was looking into how to open another app from the current app today, and came across these posts which look interesting:

 

Anyway, an interesting list for anyone trying to do this.

 

December 06, 2010

Platforms / Bundler is Evil

JB

If anyone is thinking about using the Bundler plugin for ruby-on-rails for *any* reason, DON'T!!!!!!!!!

I have lost probably 5-6 hours just messing around with bundler trying to get it to work consistently.  Unfortunately, a fairly decent library, formtastic, requires it, for some reason I really don't understand.  Anyway, I've lost hours of sleep and work time trying to mess with bundler.  So, for all of you wondering if this will be worthwhile - beware!!!  It just eats up your time and sanity with no real payoff.

It is especially evil if you are trying to manage dependencies for the same app running on multiple boxes, which, in theory, that's the problem it is trying to solve.

TO UNINSTALL BUNDLER

Amazingly, there is NOTHING AT ALL in the documentation to tell you how to uninstall bundler.  How nice.  

Here's what I found out:

1) Remove config/preinitializer.rb

2) Bundler adds a function at the bottom of config/boot.rb.  It looks something like this:

class Rails::Boot
  def run
    load_initializer

    Rails::Initializer.class_eval do
      def load_gems
        @bundler_loaded ||= Bundler.require :default, Rails.env
      end
    end

    Rails::Initializer.run(:set_load_path)
  end
end

Get rid of that function.  

3) Bundler should now be gone!  You can remove the gem, now, too.  I'll let you know if I find any other vestiges of bundler laying around.

And, it looks like formtastic still works after you remove bundler.  So if you must use formtastic, maybe you should use bundler to install it, and then remove bundler to use it.

December 03, 2010

Amusing / Model Rocket Stuff

JB

Playing around with model rockets this week.  I found that you could use crepe paper (or even cellulose wall insulation) for recovery wadding, and that loctite at walmart was a decent substitute for plastic cement.  There's also a link to make your own fire-resistant wadding here, but it looks like you have to pay for the content.

Also, while looking around, I found that someone even came up with a method of making homemade engines (also other sites here, here, and here - that last link also has info on homemade fireworks)!   That's pretty cool, but I don't think I'm ready for it yet.  Also a link for homemade igniters.  

Anyway, I think the only part of that I'm brave enough to try is using crepe paper for recovery wadding, but the rest sure is interesting!

October 06, 2010

Platforms / When XCode Won't Symbolicate your Crash Log

On the iPhone, when you get crash logs, XCode is supposed to automatically look up symbols for you.  Sometimes, it doesn't.  Just had a crash report from the app store.  Loaded it up in the XCode organizer, and... nothing.  Zilch.  A lot of posts on the internet talked about "atos" but I just kept on getting the error:

atos cannot load symbols for the file

So, thankfully, I found this page on manually symbolicating your file.  Yay!

Basically, you can just run gdb on your archived package, set some configs, and then do p/a on the addresses and it will give you the proper symbols, files, and line numbers.  Magic!

/Developer/Platforms/iPhoneOS.platform/Developer/usr/libexec/gdb/gdb-arm-apple-darwin YOURFILE.app
set print asm-demangle on
set print symbol-filename on
p/a 0x0whatever

Thanks so much to PiC Software for pointing this out.  And, of course, yay to the gcc and gdb developers who never get the credit that they should.

September 29, 2010

Amusing / Why to Not Use Dreamhost for Important Sites

JB

I host one of my sites on Dreamhost.  Dreamhost is very alluring, because of the number of features you get for almost no money at all.  The problem is, Dreamhost has the right to pull the rug out from under you with no warning.

I had spent hours trying to get my rails app to work under Dreamhost.  I had frozen Rails, specified which version of Rack to use, and a number of other tweaks.  Then, today, I go there, and I get the dreaded "Passenger Error".  I logged in, and tried to change some settings, and got nothing.  However, I noticed that the error message continued to display the same line numbers even though I had changed the file.  Wierd.

So I keep messing with it, and even start deleting files.  The errors *still* pop up, no matter which files I delete - it keeps the same filenames and line numbers even though the files no longer exist.  I had assumed that it just wasn't restarting, and maybe it had cached the files.  So I went looking for a force-restart thingy on the Dreamhost panel.

I didn't find one, but I found something else - Dreamhost had, without so much as an email saying so, moved me to a completely different server!  They left the files on the old server, but my domain was no longer pointed there.  Surprise!  I had been working on the wrong server altogether!

So, once I logged into the correct server, I was able to delete my frozen version of Rails, and unset my Rack preferences, and all was well with the world.  But who in the world switches apps to a box with a different configuration without notifying the customer!

If you want to know why you shouldn't buy webhosting for $5/month, this is it.

I'll probably still keep my account, but I'll stick with only having very-low-profile domains there.