jb… a weblog by Jonathan Buys

Jekyll Bookmarklet

I have a handful of Automator scripts I’ve created to make maintaining this site with Jekyll just a little easier. The first script let’s me highlight some text on a web page and click a bookmarklet (or, more likely, hit the command+3 key combo), and the script creates a newly formatted Jekyll post with the highlighted text in markdown quoted syntax, and opens it in my default Markdown editor.

April 5, 2011 - 3 minute read - blogging programming javascript

Personal Rules for Cocoa Happiness

  1. Understand every line of code written in my apps
  2. Use frameworks sparingly (see rule 1).
  3. Do not copy and paste code (see rule 1).
  4. Add lots of comments so I remember what I was doing at any given time.
  5. Manage memory as I go, don’t wait until I’m nearly finished and then go and “clean it up”.
  6. Draw out the application on paper before writing a single line of code.
  7. Search Apple’s documentation, CocoaDev mailing list archives, Google, and anything else I can think of before asking for help.
  8. When programming, quit Mail, Twitter, NetNewsWire, and IM. Turn on some non-distracting music in iTunes.
  9. Get a cup of coffee.
  10. Remember, “This is hard, you are not stupid.”

June 29, 2009 - 1 minute read - programming cocoa

Ping from Cocoa

One of the features of Servers.app is that it pings the host and shows a little indicator for it’s status: green is good, red is dead. Getting that little feature in here was not quite as easy as I thought it would be. After searching the Apple documentation for what seemed like years, I stumbled across SimplePing. It was perfect, exactly what I was looking for. I dropped the two source code files into into my project, read through the documentation commented out in the header file and added the code to call SimplePing. It worked, and everything seemed fine. Except that it kept working, even when I knew for certain that the host did not exist.

So, I started digging through the source code for SimplePing.c, and found that instead of calling a standard error message, it called perror, which, according to the documentation, doesn’t return a value. This is fine if you want to log the ping results, but I wanted to ping the server and make a decision based on code. So, I changed a couple of lines of code from this:

if (error == 0) //was able to wait for reply successfully (whether we got a reply or not)
{
    if (gotResponse == 1)
    {
		{numberPacketsReceived = numberPacketsReceived + 1;}
	}
}

to this:

if (error == 0) //was able to wait for reply successfully (whether we got a reply or not)
{
    if (gotResponse == 1)
	{
		{numberPacketsReceived = numberPacketsReceived + 1;}
	} else {
		error = 1;
	}
}

Simply adding an extra else statement in there to return an error code gave my application something to work with. Now, from my application controller I can call SimplePing like this:

int systemUp;
systemUp = SimplePing(cString, 2, 2, 1);

After that, I can make decisions based on the value of the systemUp int. Now, it’s entirely possible that I’m doing this wrong, all I can say is that it works for me now, and it didn’t before.

June 15, 2009 - 2 minute read - cocoa programming

DiggBar This

I’ve put a lot of work into this site. I’ve put thought into how I want the URLs to look, how the layout should feel, and since the site has my name on it, I wanted it to be good. I created a custom theme for the site which will purposefully only work here, and I’ve even done a bit of personal “branding” I suppose with the jb{ logo.

So, when I saw that Digg had decided to take a page out of 1999’s web play book and start framing sites inside of their DiggBar, I was more than a little annoyed. There may be only six people who read this site on a regular basis (Thanks guys!), but this site is entirely mine. The DiggBar removes the URL from the site you are reading and adds it’s own custom shortened URL, making it hard to bookmark, or really even remember where you are.

April 10, 2009 - 2 minute read - online programming php

Cocoa

Last summer I decided to dive into programming and give it everything I’ve got. For months, I would get up at 5 and pour through the Hillgass book, every page, every challenge. I’d revisit it at night, after the kids were in bed, and code till I couldn’t stay awake any more. I finished the book, and started coding my first real application. It was then that I found out how very little reading one book gave you. Hillegass says he gives you 80%, I’m thinking it’s more like 50%, tops. I reached out to the Cocoa Dev mailing list for help, and eventually even went to a CocoaHeads meeting with the local chapter. Meeting some “real” developers, I despaired. There was far, far too much that I didn’t know, I felt that it would take me an entire lifetime to learn what I needed to know. I gave up, wrote Goodbye Cocoa, and focused on something else.

January 24, 2009 - 5 minute read - programming cocoa

Goodbye Cocoa

Some times, things come easy to me. I’d like to think that I’m somewhat blessed in that way, especially when it comes to various forms of technology. Back in the Navy, I found I had a knack for telecommunications, and I found that I could grasp the flow of the circuits through various media easily. I nurtured this technological edge, and turned it into a career as a systems administrator. It meant lots of long nights and many mistakes along the way, but it was fun, I enjoyed it. Like I said, some things come easy… but some things just don’t. For example, I have no mental capacity for sports. I enjoy playing every now and again, but I can’t keep track of who’s who and what’s what in this professional team or that college team. It just doesn’t come easy to me.

September 19, 2008 - 5 minute read - programming cocoa culture