Text

#Defining your wrappers

I’m working on a new project that uses ARC, because, frankly, I suck at memory management (in Objective-C and in real life). Zeroing weak references (ZWRs) are my absolute favorite new feature, as I use weak references fairly often to reference the parent object in a tree. So, I was very disappointed to learn that ZWRs do not, in fact, work on Snow Leopard.

Luckily, the Mac community came through for me, and I found MAZeroingWeakRef. It gives me all of the benefits of ZWRs without the limitation of excluding Snow Leopard users from the fun. The only downside of using it is that it makes your variable declarations somewhat opaque. For example:

NSPotato *parentPotato;

becomes:

MAZeroingWeakRef *parentPotato; // This is an NSPotato.

Now, this is a minor issue, but I like my interfaces to be as readable as possible, so I decided to come up with a way to remedy this. This is what I came up with:

#define weak(className) MAZeroingWeakRef

It’s just your average preprocessor macro, with a parameter that isn’t used in the definition to give you a place to put the actual class name. I just dropped that into my prefix (.pch) file, along with the #import statement for MAZeroingWeakRef.h, and now I can write:

weak(NSPotato) *parentPotato;

and my interfaces can live up to my own ridiculous standards again! The one thing you do have to remember is to import MAZeroingWeakRef.h wherever you use this.

The best part of this is that it will work for any wrapper style object, just swap out the relevant class and macro names in the #define, and away you go! So, say I had a wrapper for NSPotato objects called NSVegetable:

#define vegetable(className) NSVegetable

It’s that easy! Enjoy.

(Disclaimer: I haven’t tested this outside of Xcode 4.2, not sure if all versions of the preprocessor will take kindly to having an unused parameter in the macro. If you have issues, please let me know here or on Twitter, @SphereCat1.)

Text

Eject key hacking for fun and profit

A while back, I wrote about how you can make the Caps Lock key actually do something useful. Today, I’ll do the same thing with the Eject key.

Now, granted, the Eject key isn’t quite as useless as Caps Lock, since it is the easiest way to get a disc out of your SuperDrive. However, and I don’t know about you, but I haven’t been putting very many discs in there lately that need ejecting. So, today I decided that I would make the Eject key do something much more helpful: eject external drives.

The process for doing this is fairly simple, and uses tools from the same people who made the one used in the Caps Lock article. So, let’s get started!

Step #1: Download KeyRemap4MacBook and NoEjectDelay.
KeyRemap4MacBook
is a preference pane which allows you to do all kinds of fun stuff to your keyboard. You should play with some of the other options after setting this up, it’s very powerful. NoEjectDelay is a simple utility that removes the need to hold the Eject key for a couple seconds for it to work. This one is optional.

Install at least KeyRemap, then reboot as directed.

Step #2: Download the script and make it a hotkey.
To eject all external disks, we’ll be using a simple AppleScript, which you can download here. Save it somewhere where it can live permanently. Now, you’ll need to set it up as a hotkey in your launcher of choice, I’ll be covering Alfred.

To set up a custom hotkey in Alfred, open the Alfred preferences. Go to the Features tab, and then Global Hotkeys. Click the [+] button, and set the Hotkey to Shift+Control+Option+Command+E. Set the Action to the path where you saved the script.

Step #3: Remap the Eject key.
Alright, we’re almost there. The last thing you have to do is remap the Eject key to the key combination you entered in the Hotkey field. We’re using that shortcut simply because it’s one of the options built into KeyRemap4MacBook. So, open up the newly installed preference pane, and type “Eject to Command” (without the quotes) into the search box. Once it filters the options, check the one that says “Eject to Command+Control+Option+Shift+E”.

Step #4: Profit!
Congratulations, you can now eject all of your drives by hitting the Eject key! This is especially useful with laptops, so you can quickly undock and leave your desk. When you actually do need to eject optical media, you can simply hit Fn+Eject. Enjoy, and thanks for reading!

Link

Absolutely spot-on.

wildchocolate:

Dear Mac/iOS Developer Community,

Empathy is the ability to put yourself in someone else’s shoes who may be different from yourself and attempt to understand/have compassion towards that person’s feelings, especially if their feelings are different from your own. If you do not consider yourself…

Text

Grocery Culture

I wrote this essay for Michigan State University’s application. I spotted two typos immediately after submitting it. *bleeping bleepity bleep*

I work at Rahilly’s IGA, one of two grocery stores in my hometown of Newberry. Newberry is a small town in the middle of nowhere, and, as such, doesn’t have much in the way of diversity. The only exposure you really get to other cultures is the two or three foreign exchange students that live here each year. However, Newberry is a tourist town. People from all corners of the US, and even from other countries, come through on a regular basis, and they all have one thing in common: they need food.

During the spring and summer, tourists are here because we’re one of two “gateways to the Falls,” the Falls being Tahquamenon Falls, a popular sightseeing and camping destination. We’re also a popular ATV riding area. During the fall, hunters descend on the area, and in the winter people enjoy snowmobiling and ice fishing. This means that most people who are touring the area will end up traveling through Newberry at some point during their trip.

As a bag boy (or as I prefer to call it, Grocery Conveyance Engineer) at Rahilly’s, I interact with all of these people on a daily basis. Even though my job description only includes putting their groceries into bags and transporting them to their vehicles, my job goes far beyond that. I get to hear all about where they come from, where they’re going, and how the trip has been so far. I have to be able to give them directions, recommend restaurants, and much more. During the few minutes that I spend bagging for them, I can learn quite a bit about them, and get a feel for their culture.

That’s pretty much the limit of my cultural experience. However, I see this as an opportunity, not a limitation. Because I’ve never really been immersed in another culture, I can go into the experience of Michigan State with a completely open mind. There are lots of interesting things to learn about in the world, and I look forward to learning as much as possible about people and their culture.

Tags: college essay
Link

I wish we had stuff like this in third grade. I don’t think most of my class could even handle the Roman Numerals, and they’re graduating this year.

Link
Link
Link
Text

Why Computers?

This is an essay I wrote for the Michigan Tech Leading Scholar Award scholarship. I’ll probably be posting other essays as I write them.

Why computers?

I’ve been programming since I was six years old. I started with Liberty BASIC on an ancient Panasonic Toughbook that my Dad gave me. Ever since then, I’ve been learning every language I could get my hands on, writing everything from games to text editors. I love it. And despite all of this experience, I’m still a terrible programmer.

Read More

Tags: college essay
Link