This blog has moved to devblog.riesd.com

Wednesday, January 23, 2013

RubyMotion Crashing Samples

Recently I've been playing with RubyMotion. I worked my way through the Pragmatic Programmers book which was a good introduction to the tools and workflow of RubyMotion, but left me feeling like I still had no idea what an iOS app is made of.

I got several suggestions about the Big Nerd Ranch book. Which is a great introduction to the iOS framework. I don't know Objective-C very well, but translating the samples to Ruby is pretty simple.
Now I was on my way to making awesome iOS apps in my favorite language. I even get to leverage awesome gems to make life nicer. But there was one big hurdle I ran into: mysterious simulator crashes that left no backtrace.

Let's use an example: The WhereAmI sample application from the Big Nerd Ranch book has just enough complexity to be interesting, but is simple enough to keep in your head all at once. It basically just shows a map, finds your current position and lets you name that position.

When you enter the name and hit "Done" it sticks a pin on the map with the name you entered. The main action of the app happens in the found_location method of your view controller. A very direct translation from the Objective-C samples to the Ruby might look like this:
But when you run this app and try to name your location the app suddenly crashes with the mysterious no-backtrace, no-error message screen below.

At this point it is not at all clear what is wrong with your code. The specification for a MKAnnotation just specifies that you must have a coordinate and an optional title. So why is this crashing? Well if you rewrite the BNRMapPoint class as seen below your code will suddenly work.

What is the difference between an attr_reader and defining a method that returns an instance variable? I don't know enough about the Objective-C runtime to know, but if you are getting the mysterious crash you may want to get rid of some of your Ruby-foo and trade it for old fashioned methods.

Wednesday, August 22, 2012

Books That Blew My Mind

Recently Angela Harms asked on twitter for book suggestions.  It turned out that all of my best suggestions were books she had already read.  It made me wonder if the reason I identify so closely with her presentations is because our thinking has been shaped by some of the same realizations.

This got me thinking about how some books have really affected my life.  So I decided to write down this list of books that blew my mind.  I'm also including a short list of which ideas really impacted me from each book since I am curious to know if other people were impacted by the same ideas.

Also I am on the lookout for a new book to blow my mind again so suggestions are welcome.

The Moon is a Harsh Mistress ~Robert A. Heinlein
My Dad told my older brother he would give him $25 to read this book.  I read it and never got paid.
Key Concepts:



Speaker for the Dead ~Orson Scott Card
Ender's Game was a great book.  Fun to read and has a few powerful messages, but the next book in the series is the one that really changed how I saw other people.
Key Concepts:

  • If I lived someone else's life I would probably make the same mistakes they do
  • If I get to really know someone I will love them


Stranger in a Strange Land ~Robert A. Heinlein
Definitely one of my all-time favorite books.  I think I have read it 6 times now.  The skeptical view of common moral concepts and attempt to rationalize human interaction made me step-back from my own beliefs and actions and try to justify my own personality.  I found lots of things worth changing.
Key Concepts:

  • You are absolutely accountable for your own life and potential ("Thou art God")
  • Basically everything Jubal Harshaw says
  • Love should never be used to hurt someone
  • The greatest happiness is finding a water brother


Extreme Programming Explained ~Kent Beck
This was actually a pick from Angela Harms on the Ruby Rogues.  After reading the first 3 chapters I brought up the book in a meeting and convinced by boss to buy a copy.  Shortly thereafter it blew his mind and he started pushing for doing Test-Driven-Development at work.  Hallelujah!
Key Concepts:

  • The best way to be a happy developer is to be effective
  • The key to being effective is good communication with the business
  • I should be justifying all of my own development habits to myself so I can figure out which ones make sense and which are just habits


Book of Mormon
So this might be obvious given my religion, but it did have a few key impacts on my thinking.  It is also the only other book on this list that I have read at least 6 times.
Key Concepts:

  • The book is either a giant farse, or inspired by God.  Go figure out which for yourself.
  • Religion is worth thinking about and I need to figure out what I believe.


Doctrine & Covenants
Another religious text? The things I have learned from the Doctrine and Covenants are really different from what I learned from the Book of Mormon.  In fact I probably would have left the church around age 20 if I hadn't bothered to learn from the Doctrine and Covenants because it takes a lot of the core concepts from the Book of Mormon and explains the back story so they actually make sense.
Key Concepts:

  • God did not create me entirely.
    • This is sort of a corollary to "You are absolutely accountable for your own life". If God made all of me, then I can just claim manufacturer's defect when I screw up.  Actually God is someone fundamentally similar to me who wants to help me become better.
  • The key attribute of Jesus Christ is love.  Fundamentally he loves other people more than himself.
  • The primary purpose for this life is for me to choose what I want without immediate feedback.  This way I can learn what I really want.
  • What I really want is to love other people the way Christ does.
  • Commandments are not a checklist to get into heaven.  They are suggestions for becoming a better person. Suggestions made by someone who loves me and knows what they are talking about. Heaven is about becoming the kind of person who loves other people more than myself.
  • The reason we have marriage and family is because loving other people at a distance is much easier than loving them for a long time at close proximity.  Being totally committed to someone for all eternity is really hard, but very awesome.

Sunday, April 22, 2012

project euler

I have been playing on projecteuler.net recently and I have to reccomend it as an awesome way to play with code.  If you ever feel envious of Dijkstra and the other "mathematician programmers" who wrote proofs and theorems while they programmed, this is a good place to dive into the math side of programming.

Sometimes I will rush through several problems in a row and just brute-force the solutions, but other times I get interested in a particular problem or stuck on a particular problem and I will end up spending a couple of hours reading wikipedia articles about various algorithms and mathematical proofs to help me solve a problem.

So if you love math head over to projecteuler.net.  If you hate math and love programming, this is a good place to start.

Friday, April 13, 2012

Learning to Program

I have been trying really hard to stay focused on my robotics project, but I think I am going to have to take a detour for a little while.  I keep trying to tell people that learning to program is fun and that it isn't hard, but when they ask me where to start and I tell them about html+javscript or using rvm to install ruby it actually starts to sound pretty hard.

So I have been thinking about the best way to learn to program.  The answer of course is to find a project that is fun and start working on it.  So I thought of this idea of a free AI service.

Imagine you can go to a website and click one big button to get started.  In your browser you can write some simple procedural ruby to make a move in a game of tic-tac-toe.  Then you can hit a run button and see your code play against some AI provided by the website.  There could be some guides to making your AI incrementally smarter and eventually you could write the client locally on your machine and have it connect directly the server to play.

The things I love about this idea are:

  • One beautiful language (Ruby of course)
  • Low barrier to entry
    • Play a game and watch it rendered in a single browser window
    • Incrementally add complexity to your AI
  • Interactive
    • Something more interesting than "hello, world" in a console
    • Competive drive to win
  • Plenty of games that can be implemented pretty easily
    • Tic-tac-toe
    • Connect 4
    • Checkers
  • Potentially more difficult games that can be used as code katas or koans (http://codekata.pragprog.com/ -  http://rubykoans.com/)
    • realtime racing game
    • tanks wars type game

Things I'm not sure about:

  • Can I even run ruby code in a browser?
  • Can I safely push in back to the server and execute it there? (tryruby.org)
  • Use websockets to allow the code in the browser to play the game?
  • Use eventmachine to handle the hosting of the game and writing the site-provided AI?
  • Competitions where players or teams can log into a game and compete?

So what do you think? Is this feasible? It certainly sounds like fine and something that I could use with a group of highschoolers to get kids excited about programming.  What challenges am I not thinking about yet?

Friday, March 30, 2012

Ruby Rogues

Have you ever watched a http://www.confreaks.com/ presentation that just blew your mind?  Something like Code Blindness or How Github uses Github to build Github (language warning)?

I love that feeling of realizing, "why haven't I tried that before?"  That sense of learning something new is my favorite thing about the ruby community.  In the spirit of that sense of awesome learning I highly suggest Ruby Rogues.

This podcast has several of my favorite rubyists that I follow and it even has some fellow Utahns that I hadn't known about before.  In addition to that they have guests on the show like Jim Weirich and Kent Beck.  Can you say, "scream like a nerdy fan-girl!"

I started by listening to their most recent podcasts and quickly went back to start at the beginning and get caught up on the backlog of podcast episodes.  They have a great mix of common themes with differing opinions that leave me feeling like, "why haven't I ever done that before?"

If you love programming, you will love the podcast.  Go Ruby Rogues!

Saturday, March 24, 2012

IOIO Controls a Servo

I'm turning into a posting maniac.  I'm just getting excited about how close I am to getting a household robot pet.  This afternoon I modified the HelloIOIO sample application to include a slider bar that controls an RC servo.  I follow a similar approach to http://trandi.wordpress.com/2011/07/03/android-ioio-rc-servo-or-esc/.

Here is a quick video.

Connecting the IOIO

Now that my phone is sending video back to my laptop I am ready to start trying to send commands from my phone to the ioio board.  Luckily the IOIO comes with a besic test app to make sure that your board is working correctly before you start your own experiments.
Here is the basic process:
1) Solder some headers to the pinouts you plan to use.  I just need pinouts for the power, the 5V reference supply and 2 pins that can supply a 5V PWM signal. Not all of the IOIO pins can provide a 5V signal ( https://github.com/ytai/ioio/wiki/Digital-IO )
Imag0159
2) Find a DC power source between 5-15V.  A 3 cell lipo that I had hanging around worked fine for me.  I'm actually using the balance charging plug because those pins just happen to be the right size for my breadboard prototyping wires.
Imag0157
3) Connect the power source to your IOIO vin and GND headers and you should see the power light come on.
Imag0158
4) Download the softare package for your IOIO (https://github.com/ytai/ioio/wiki/Downloads)
5) Install the HelloIOIO.apk file onto your device and start the application.
Install-ioio-apk
6) With your IOIO powered, connect the USB cable to your phone.
7) Now you should be able to hit the on/off button and see the status light on your IOIO turn on and off.
Hello-ioio
SUCCESS!!  Your phone is talking to hardware!  Now it is time to start hacking some servo commands together so we can drive an RC car.