Gray Soft

The programming blog of James Edward Gray II (JEG2).
  • 8

    JUN
    2008

    Getting Git Thanks to PeepCode

    It's pretty clear that Git has landed. More and more projects are migrating to Git for their version control needs and developers have another system we need to get up to speed on.

    I'm usually a traditional dead-tree book learner, but this time I decided to try the PeepCode approach. I had heard good things about them and I can now tell you that reputation is well deserved.

    PeepCode has two resources available for those wanting to learn more about Git. First, there is a one hour screencast called Git covering everything from installing through basic usage. There's also a newer 120 page PDF book called Git Internals, that ships with some different screencast material. You can purchase either product for $9, which really is a steal in my opinion. Both are well done, but let me break down their strengths for you below.

    The original screencast is a great resource for the developer who wants to get up to speed on Git in a hurry. You just watch for an hour, perhaps try a few examples as you go, and you should come out the other side with basic Git usage skills. An added bonus is that the screencast covers Git's Subversion integration which is a topic you don't want to miss, but it's sadly missing in the PDF book. It also has some good tips on configuring the gitk browser under Mac OS X.

    Read more…

  • 8

    JUN
    2008

    Programming Amazon Web Services

    I really wanted to love Programming Amazon Web Services and it does have some things going for it, but there are enough minuses to keep me from giving it full marks. Let me start by talking about what the book covers, then we will take a look at what it did well and not so well.

    This book provides full coverage of Amazon's suite of Web services. You'll find detailed chapters on Amazon's file storage service S3, their cloud computing service EC2, their messaging service SQS, their payment gateway FPS, and their document database service SimpleDB. The book begins by explaining Amazon's philosophies for these services, how they affect the suite as a whole, and why that should be important to you. For each service you will find detailed information about the design and intent of the service, how to interact with the API (including a full client implementation), and example applications making use of the service. The larger and more complicated services span multiple chapters to make sure all key aspects of using that service are covered.

    Read more…

  • 23

    APR
    2008

    The Nice New Italian Restaurant of Server Monitoring

    David Heinemeier Hanson, the creator of Rails, has made one of his business strategy talks available recently. This is a great talk about how we all might be trying just a little too hard at what can be a fairly simple task.

    We all hear advice like this over and over again, but we seem to forget it so fast that we need that constant reminding. Just today I saw a site redesigned to improve a section users haven't even seen yet (as that section isn't yet public). Is that really the top use of resources for an unlaunched portion of the site? How do we know they wouldn't have liked it? How do we know they will like the new version better? I'm sure it won't surprise readers to learn that this site is over budget on time and money.

    The point of all of this is that I want to tell you about a new server monitoring tool the company I work for has recently launched. The new service is called Scout and we've done our dead-level best to keep to the simplicity principal both because we agree with David and because we flat out need it to work that way.

    Read more…

    In: Rails | Tags: Monitoring | 2 Comments
  • 10

    APR
    2008

    Five ActiveRecord Tips

    This article was written for the Railcasts 100th Episode Contest. I think the idea is great and I look forward to reading great tips from all who decide to participate.

    1. create_or_find_by_…

    I imagine most of you know that ActiveRecord can handle finders like:

    MyARClass.find_or_create_by_name(some_name)
    

    This will attempt to find the object that has some_name in its name field or, if the find fails, a new object will be created with that name. It's important to note that the order is exactly as I just listed it: find then create. Here are the relevant lines from the current Rails source showing the process:

    record = find_initial(options)
    
    if record.nil?
      record = self.new { |r| r.send(:attributes=, attributes, guard_protected_attributes) }
      #{'yield(record) if block_given?'}
      #{'record.save' if instantiator == :create}
      record
    else
      record
    end
    

    The above code is inside a String literal fed to class_eval(), which is why you see interpolation being used.

    Unfortunately, this process is subject to race conditions because the object could be created by another process (or Thread) between the find and the creation. If that happens, you are likely to run into another hardship in that calls to create() fail quietly (returning the unsaved object). These are some pretty rare happenings for sure, but they can be avoided under certain conditions.

    Read more…

  • 18

    MAR
    2008

    Death and Spam

    The popular expression warns us that death and taxes are the only two certainties, but I'm worried we may need to add spam to the list. Publish any material that draws readership on the Web and invites reader feedback and you can be certain sure you will be swimming in spam soon enough.

    One of the biggest reasons I switched to my own blogging engine was to fine tune my spam control strategy. Until today, the system was that I received an email anytime a comment was posted to this blog and it was a single keystroke to remove any offensive content. While that was as simple as I can think to make a process, the fact was that it still wasn't good enough.

    The spammers ramped up their efforts until I was facing about 50 useless posts every 12 hours. While I didn't mind clearing them, the fact was that visitors were probably seeing spam due to the regularity of the postings and the time between the post and my clearing it. Obviously, there was at least spam on the blog while I slept each night.

    Read more…

  • 1

    MAR
    2008

    Design Patterns in Ruby

    I've been lucky enough to read a string of good Ruby books lately and the latest in that line is Design Patterns in Ruby. This book attempts to modernize the software design patterns by showing how these patterns can be applied in a language as dynamic as Ruby. Despite a couple of minor missteps along the way, the book definitely delivers on this goal.

    Design Patterns in Ruby begins with a couple of introductory chapters introducing both the concepts behind reusable software patterns and the Ruby programming language. After that, the main section of the book has 13 chapters that walk through 14 of the patterns first introduced in the famous "Gang of Four" book that began the design patterns movement. The author then introduces three new patterns he feels have grown out of day to day Ruby usage. Finally the book closes with a short conclusion and two appendices on installing Ruby and other sources of information.

    Most of that content is exactly what I wanted to find in this book, but you're going to have to tolerate a diversion about a pet peeve of mine that is strangely common in Ruby books. This is really, really important, so listen up: you can't teach Ruby in 30 pages. Period. I can hear all on the "But…" replies forming out there now… No buts. You can't. Trust me. Not even if the person is already an experienced programmer. It just can't be done. Authors and publishers need to come to terms with that and move on. Its just fine to say, "This is not a beginning Ruby book." We even prefer that, because we know when we are ready to read it and we don't have to skip that useless 30 page chapter when we do. Please, stop including introductory Ruby chapters in every book.

    Read more…

  • 29

    FEB
    2008

    A Bug, Today Only

    I had to debug some tests that just started failing first thing this morning. I guess I should have procrastinated though, because they would have magically fixed themselves tomorrow morning. The cause of the one day only bug: Leap Year Day, of course.

    If you run the following code on a day like today, February 29th 2008, Date will choke on your invalid date:

    require "date"  
    
    class Date
      # Returns a Date in the past +year_offset+ years ago.
      def self.years_ago(year_offset)
        now = today
        Date.civil(now.year - year_offset, now.month, now.day)
      end
    end
    
    puts Date.years_ago(1)
    

    I came up with the following fix, which is accurate enough for my purposes:

    require "date"
    
    class Date   # Returns a Date in the past +year_offset+ years ago.
      def self.years_ago(year_offset)
        today - 365 * year_offset
      end
    end
    
    puts Date.years_ago(1)
    

    I'm not 100% sure that covers all cases though, so use with caution. Date's are tricky business!

  • 28

    JAN
    2008

    Practical Ruby Projects

    Practical Ruby Projects is a pretty poorly named title, but, luckily, that doesn't stop it from being a very strong book. The book actually turns out to be an exploring-the-Ruby-programming-language-by-example book. These aren't your trivial beginners-only tasks though. There's enough meat in these pages for the intermediate crowd to really get into.

    Let me start by clarifying my earlier comment about the title. It's clear this book is named after the series it appears in, instead of the actual content it holds. There are lots of projects in the book and they are definitely written in Ruby, but Practical is not the word I would use to describe them. Fun, on the other hand, would be a great word. Beyond that, the code and concepts used in these projects is well worth studying. Just don't expect to find the typical (for Ruby) collection of Web programming tips inside. To me, that was a big plus. The title just misrepresents what's inside.

    The projects you will find in the book include: MIDI music generation, SVG graphic building, pocket change simulations, a turn-based strategy game, a Mac OS X GUI, a genetic algorithms framework, as well as both a parser and interpreter for the Lisp programming language. While these projects obviously tackle subsets of each problem space, they go deep enough to serve as a solid introduction in each area. The author is also good at focusing on the more interesting aspects of each challenge and throwing in a few twists to keep your interests high.

    Read more…

  • 24

    JAN
    2008

    From Bash to Z Shell

    I work on multiple Unix platforms all day long. I had never really taken the time to learn about the shells, but I had picked up the basics over time. I knew how to run commands, string them together with pipes, and redirect their output into files. So when I tell you that I started learning new things in the first chapter of From Bash to Z Shell, you will know the coverage is in depth. If you are a casual shell user, or even less experienced, this book has a lot to offer you.

    From Bash to Z Shell is organized into three parts. Part one is an introduction to shell basics. It focuses on typical interactions with a shell including all of the things I mentioned knowing before reading this book. There is surprisingly good depth even here though and I doubt that anyone short of a power user could make it through this section without picking up a new trick or two. I learned multiple things from each chapter in this section.

    In part two, each chapter takes a single aspect of the shells and really focuses in on just that. You will find chapters about the startup files each shell invokes as well as shell command histories. This is comprehensive coverage that really gets you to understand how things work as well as how to tune them to your personal tastes. You are even less likely to not pickup great tips in here.

    Read more…

  • 4

    JAN
    2008

    Dave Thomas is Definitely the Sammy Sosa of Programming

    There is a debate raging in the Ruby community that I don't want any part of. I'm not going to engage in any of the mud slinging and there will be no debate here. Commenters have been warned. What I do want to do is to share some simple uncontested facts about a man I am lucky enough to know.

    Sammy Sosa is famous for one thing: hitting home runs. In the entire history of the game of baseball five players have managed to hit over 600 home runs and Sammy is one of them. If that wasn't amazing enough, he has hit at least one home run against every single Major League team and in 44 Major League ballparks. Baseball fans everywhere love to watch Sammy Sosa at bat.

    Now if I had to name five programmers who get me as excited about programming as Sammy Sosa does about baseball, Dave Thomas would definitely make the list. Dave does exactly what Sammy always does: continually preforms the hardest tasks of his profession while making it look easy to the fans. Allow me to give a few examples.

    Read more…