How to make your app open in full screen on Lion

One of Lions new features is full screen apps. Full screening an app is supposed to remove all distractions and make room for more of the app’s UI. Actually implementing this in your app is quite simple, but finding how to do it online can be a bit tricky.

There are two ways to do it, one is with NSApplication and the other is with NSWindow.

To do it with NSApplication, you’ll make this simple call

   [[NSApplication sharedApplication]
           setPresentationOptions:NSFullScreenWindowMask];

To do it with NSWindow you’ll make this one

   [window setCollectionBehavior:
             NSWindowCollectionBehaviorFullScreenPrimary];

There is also an NSWindowCollectionBehaviorFullScreenAuxiliary that you can use to allow auxiliary windows to show up in the space with the main window.

Calling either of these methods will add the resize button to the upper right corner of the window. You can call them at any time also. If you want it to be in the app all the time, call it somewhere like applicationDidFinishLaunching.

One thing to remember is that fullscreen functionality like this is LION ONLY. If you’re using this in an app that targets more than 10.7, make sure to do the appropriate checks around this code.

Posted in Uncategorized | Tagged , , , , | 2 Comments

How to add the Konami code to your WordPress blog

The Konami code is a cheat code first popularized by the game Contra, where entering it would give you 30 extra lives. Since then, the code has been used in tons of video games and websites to unlock bonuses and easter eggs.

So how can you add it to your site?

There are probably a bunch of javascript libraries for it but I’m going to show you Konami JS by snaptortoise. Basically, you just take this block of code and include it somewhere in your site.

<script type="text/javascript" src="http://konami-js.googlecode.com/svn/trunk/konami.js"></script><script type="text/javascript">// <![CDATA[
	konami = new Konami()
	konami.load("http://www.google.com");
// ]]></script>

You’ll want to add it somewhere that will always be loaded by your blog, so someplace like header.php is a great place. From your dashboard click Appearance. Under Appearance you should see Editor. Click that next. Along the right hand side you should see a list of different files. Pick Header.

Now you just need to edit header.php. Putting the javascript in the <head> tag works great. Save it and you’re done. Try it out for yourself by pressing

up, up, down, down, b, a, b, a, enter

Right now, it just redirects you to whatever website is passed into the load() function. You can do other stuff with it too by passing in a function to the konami object like this.

konami.code = function() {
		alert("You have entered the KONAMI CODE!  You now have 30 lives.  Kinda.")
		}

In order to do this on a WordPress.com site, you’ll need to pay to be able to customize the look and feel of your site.

There is also a WordPress plugin written that will do this same thing called Konami Easter Egg.

Posted in Uncategorized | Leave a comment

Netflix customer service is pretty good

A week or so ago I had some trouble with the post office. All of my mail stopped showing up. I went to the post office and asked about it. They said they’d call me. They didn’t, so I called them. It turns out the delivery guy thought my mail was supposed to be forwarded, based on mail forwarding I had turned on over a year ago.

One piece of mail I didn’t get was a Blu-Ray from Netflix. I wasn’t sure what happened to it, so I told Netflix it got lost in the mail. They sent me another one and all was well.

Then I get an email from Netflix saying they got the lost Blu-Ray back from the post office and my address might be wrong. No big deal, my address wasn’t wrong. I didn’t do anything.

A couple days later I sat down to watch some Mad Men on my Xbox. I was greeted with an error saying there was something wrong with my account. I went to the website and checked everything out.

They had temporarily locked my account until I fixed the address problem. The problem with that was that I didn’t have an address problem. When I went and tried re-saving my address, it never marked the issue as fixed because nothing ever changed.

So I called up Netflix and was able to talk to a person in less than a minute. They give you a code that you enter that is supposed to make you get help faster. I have no idea if it worked, but it seemed like it did.

I got someone that I could understand and someone who was very helpful. I explained the problem and he unlocked my account. He told me that it would take about an hour for the streaming servers to get the change.

5 minutes later I was watching Mad Men. Thanks Netflix.

Posted in Uncategorized | Tagged , | Leave a comment

Getting started with Cocoa’s new auto layout

Auto layout might be the most exciting Mac only thing announced at WWDC this year. It improves on Cocoa’s idea of springs and struts and will let spend way less time building your UI.

Despite seeing auto layout used at WWDC, I couldn’t remember how to use it a couple months later when I sat down to play with it. Apple’s programming guide has lots of good stuff, but it seems to be missing a bit about getting started.

Default projects in Xcode 4.1 on 10.7 don’t default to using  auto layout so you’ll need to enable it. (Note: Projects using auto layout are 10.7 only)

Continue reading

Posted in Uncategorized | Tagged , | Leave a comment

Automatic Link Detection in an NSTextView

NSTextView is a really powerful text view class. It can do all kinds of stuff like automatic spelling correction, email, phone number, and address detection, and link detection. I was working on a chat application and I wanted to have links that people sent be clickable. I was using an NSTextView because it has the automaticLinkDetection property.

Unfortunately, I couldn’t get links to show up in my app. I tried sending it delegate messages and lots of other stuff. It just wouldn’t work when I set the text programatically. It would only work when I was actually typing in to the NSTextView and even then, it was a little flaky. I posted a question on StackOverflow and didn’t get any answers.

So to fix the problem, I did the link detection myself. I look through the text view for links and then add them myself as NSAttributedStrings. I did this using three different categories.

There is NSAttributedString+Hyperlink, NSString+FindURLs, and NSTextView+AutomaticLinkDetection. I use the FindURLs category to find the links and their locations, then I use the Hyperlink category to format the string like a link, and the AutomaticLinkDetection category to bring them together.

You use it like this

   [myTextView setString:@"http://google.com http://apple.com"];
   [myTextView detectAndAddLinks];

And here is the implementation

-(void)detectAndAddLinks
{
   NSArray *linkLocations = [[self string] locationsOfLinks];
   NSArray *links = [[self string] arrayOfLinks];

   int i=0;
   for( NSString *link in links )
   {
      NSAttributedString *linkString = [NSAttributedString hyperlinkFromString:link withURL:[NSURL URLWithString:link]];
      [[self textStorage] replaceCharactersInRange:[[linkLocations objectAtIndex:i] range] withAttributedString:linkString];
      i++;
   }

}

I put an example project on GitHub that you can look at and use.

Let me know if there was something I missed that would make it so I don’t have to use the category.

Posted in Uncategorized | Tagged , , , | 5 Comments

Replacing the screen on your iPhone 4

Last week, on my way to work I dropped my phone and broke the glass. I was riding my skateboard to work and wanted to check something on my phone. When I went to slide my phone back into my pocket, I missed and just dropped it on the ground… while moving. I stopped and walked back to pick up my phone just hoping it would be okay. It wasn’t okay. The cracked glass of the phone screen was staring up at me. It felt like one of those moments in a bad dream where something just terrible happens and you force yourself to wake up so it goes away. Unfortunately, I didn’t wake up and the screen was really broken. I tried using the phone and it seemed to work fine so I swore silently to myself, put it in my pocket, and continued on my way to work.

I was torn on what to do. The new iPhone should be coming out in a couple months. I could make due with the cracked screen. By the time I got to work I had made my decision. I immediately googled how to replace the iPhone 4 screen and stumbled upon this Gizmodo post. I ordered a new screen from DirectFix.com as well as some of the tools I would need to actually do the repair. Instead of the black replacement screen, I decided to get a white one. That way it would at least give my phone a unique look.

For the next few days, I used my phone with the broken screen. It worked fine. Some things were hard to see and when I swiped my finger across the broken glass I’m pretty sure I got some glass splinters but it wasn’t too bad.

Yesterday, I got the package in the mail with my new screen and I got to work on the replacement. The screwdriver I bought was too big for the iPhone’s tiny screws. Luckily, my pocketknife had a small enough screwdriver. I followed the instructions of a YouTube video in the Gizmodo post and soon enough, my iPhone was laying in more than 50 pieces on my coffee table. So what happened? Continue reading

Posted in Uncategorized | Tagged , , | 10 Comments

Why aren’t there more startups in Michigan?

A friend of mine asked this question on Quora the other day and I’ve been thinking a lot about it lately. What does it take to make somewhere a good place for startups?

At first glance, Michigan doesn’t seem like a very good place to start a tech company. First of all, it’s not California. There are no sunny beaches or 25 year old billionaires. Second of all, when you think of Michigan, you think of the auto industry, not software companies. If you look a little bit closer though, Michigan starts looking like a pretty great place for startups.

We have VC. We have talent at our universities. The thing we’re missing the most is culture, but even that is getting better. I also have to imagine that Michigan was a pretty amazing place for startups not too long ago (as long as you were in the auto industry). I’ve touched on this a little bit more in a previous blog post.

So if Michigan has the potential to be a “startup state” then why isn’t it one? Continue reading

Posted in Uncategorized | Tagged , | 4 Comments

How to launch your Mac/iOS app with a custom URL

One interesting feature of iOS and Mac apps is the ability for them to be launched by a custom URL. What this means is that you can set up your app to respond to different links in different ways.

Clicking a link that says myTwitterApp://sendTweet?tweet=hello could send a tweet from your twitter app. It could also be used for configuring your app. Maybe you have an email app that needs some special server configurations. It could be set up so that you just have to visit a webpage on your server and click a link and have it automatically configure your email settings.

Facebook uses the URL scheme for authentication in their iPhone app. If I have an app that wants to authenticate with Facebook, it will try and talk to the Facebook app on the phone so I don’t have to authenticate again in my other app.

I think this is a pretty underused feature and I would bet there are TONS of clever things people can do with it. So how do you actually do it? Continue reading

Posted in Uncategorized | Tagged , , , , | Leave a comment

1 Month with my Chromebook and it’s going back to Samsung

Less than a month ago I wrote a blog post about the first 20 minutes with my Chromebook. I talked about how I really liked the idea of ChromeOS but the execution with the Chromebook wasn’t quite there. Well one month later, I can say it’s not even close.

The biggest problem is the stability. Tabs regularly crash. Sometimes it’s out of memory and sometimes it just crashes for no reason. It’s not like I have 30 tabs open either. I was having constant crashes with 5 or 6. On an OS that doesn’t have windows, 6 tabs is not very many. Flash works ok, but not well enough that I want to spend very much time watching videos or anything with it.

Lots of things that I want to work (Netflix, Silverlight, Skype, etc.) do not. Hopefully those things come soon, but they might not.

The trackpad is really bad. I thought it was okay at first, but after a month, I really don’t like using it. The scrolling is slow. Clicking and dragging is a struggle. It’s missing tons of gestures that I really like on my Macbook Pro. Is writing a trackpad driver really that hard? Is there only one person in the world that has solved that problem and Apple hired them?

I still haven’t gotten to the worst part.

Continue reading

Posted in Uncategorized | Tagged , | 4 Comments

A response to “10000 things all ICS students should do before graduating”

About a week ago, I saw an article on Hacker News about 10000 things that every CS major should have done before graduating. Obviously, any list like this is going to be very subjective and the comments on Hacker News show that a lot of people disagreed with the kid. Instead of going on about how not everyone wants to be a web developer, I’m going to say the things on the list that I actually accomplished.

0000 – Buy your own domain name.

www.fredandrandall.com

0001 – Install an Apache web server and configure it in a non-trivial way, e.g. to serve multiple domains.

Never did that. I’ve installed Apache using MAMP before but only used the default settings.

0010 – Install WordPress and have your own blog. Write blog posts regularly. Write well. Good writing is a critical skill to master in this profession.

Damn, about a year too late. I didn’t have this blog until I had been working in the real world for a little while. Installing WordPress on my host was trivial too.

0011 – Run your own web site at home or in a hosting company.

I’ve been using this host since my freshman year of college.

0100 – Write at least one complete LAMP web app, preferably two — one where P=PHP, the other where P=Python.

Never did anything til after I graduated. Let’s see, there’s farp.me, Waypoint and Toto’s syncing. No Python though, just PHP.

0101 – Have your own [physical or virtual] server on the cloud.

No cloud for me yet.

0110 – Install VMWare or equivalent in order to boot up your laptop with more than one OS.

I dual booted Linux for awhile in college. I even installed it on my parents computer which was actually a huge mistake. Every once in awhile when my mom restarts it she’ll get booted into Xubuntu and I have to spend 15 minutes doing tech support.

0111 – Configure your home DSL router so that you serve a web site or other kind of server from your home machine / laptop to your friends.

I did it. I wrote a little AJAX chat application that was kinda neat. It didn’t work very well at all, but it was only available within our little LAN.

1000 -Use a packet sniffer to learn about the network requests your computer does to your favorite game server.

I don’t think I played with any packet sniffers until after I graduated. I guess looking at requests in Firebug counts.

1001 – Make contributions to an open source project.

Still haven’t done that but one of my friends works for Mozilla now. Maybe he’ll inspire me to submit a patch to Firefox.

1010 – Write an app that uses at least one of the popular Web APIs, like Facebook Connect or one of Google’s.

The Go Mongo app uses Facebook, Twitter, and some custom Web APIs built for the app. Again that was after college.

1011 – Use Google AdSense on your web site, and make money just by virtue of attracting traffic.

I’ve made 82 dollars in the past few years. I’m so close to getting a check I can taste it.

1100 – Compile a complicated open source project from scratch, like OpenSim orMatterhorn. (Thanks, Sean!)

See 1001

1101 – Read works of literature and, besides enjoying the ride, pay close attention to how the author tells the story and makes use of words. Your programs should be as carefully written as those works of art! (Thanks, Beki!)

I read a bunch of the Harry Potter books in college. I also read the Mythical Man Month which was probably the most relevant book to CS that I read beyond my textbooks. I’ve been reading a lot lately. I’m currently in the middle of Coders at Work and the Hunger Games series.

1110 – Get yourself involved in a software project where requirements are bound to change halfway through — that’s about 0.01% of homework projects and about 99.99% of real world projects, so find one of the latter kind. Finish the project with patience and the ability to take criticism in a constructive way. (Thanks, Lorraine!)

My final project for EECS 497 was kinda like that. We got to pick the feature set though.

1111 – Write an application using map-reduce. Run it on Google app-engine or amazon EC2. (Thanks, Ian!)

Don’t have a huge use for this. Maybe someday.

While I didn’t actually get very much of this stuff done while I was in school, I’ve done a surprising amount of it in the 2 years since I graduated. Now that I actually have free time, it’s nice to put my skills to use outside of work and see what else I can do.

Posted in Uncategorized | Tagged , | 1 Comment