MetaSkills.net
Coding things under other things!

Heuristics

Keep Trying

One part of Objective-C that I like is being able to send messages to nil objects safely and more so their KVC and KVO patterns. In Ruby I often use the #try method to safely send messages to objects that may be nil at runtime. But one thing I always wanted was a nice way to send a key path, basically a string of methods signatures, to an object in the same way. I give you my simple #try_keypath method...

PDFKit Overview & Advanced Usage

Last week I had the pleasure of rewriting 4 years of legacy PDF::Writer code to PDFKit. Why? Well drawing pdfs in ruby using libraries like PDF::Writer is like composing a webpage with an Etch A Sketch. In short, its a damn chore that involves a bunch of code that mixes both data and presentation. Sure there are gems like Prawn that make this much easier, but nothing beats drawing your pdf code in native HTML and CSS, and that is...

Protip: Exclude Your RVM Install From Time Machine Backups

You may not realize it, but that ~/.rvm directory is getting big and may be hurting your Time Machine backups. Especially if you are doing a lot of development. I just checked mine today. du -skh ~/.rvm/gems 1012M /Users/kencollins/.rvm/gems Ouch! That's around 1gig of stuff that is pointless to backup just in the gems directory. I frequently blow away certain rubies and install them again using various rake tasks and just found out today that you have to pass the...

A MacPort/RubyODBC Update

TinyTDS is the upcoming de facto raw connection method for the SQL Server adapter. Please read the Using TinyTDS wiki page on the adapter for switching. No longer do you have to worry about compiling ODBC layers! I have changed my mind about the UTF-8 version of RubyODBC. Please read that section in the the rails 3 announcements for the SQL Server adapter. Quite a while ago I wrote a soup to nuts article on getting the full multi-ruby development...

Interactive JavaScript Console With TextMate

Last week I started reading JavaScript: The Good Parts by Douglas Crockford. It was on my list of long overdue things to do. While reading it, I wanted to be able to kick some simple JavaScript examples around. As rubyist we have it good, irb let's us fire up an interactive console anytime we want. But with JavaScript, options are limited. Sure you could install Johnson/EnvJS, Rhino or some other JavaScript engine. Maybe even load up firebug or the web...

The alias_method_chain of Rake - Override Rake Task

Rake is cool. It is built so that multiple tasks with the same name run in a reverse defined series. This is great, but sometimes you want to override a task with your own behavior and conditionally call the earlier task. Especially if that task is defined deep somewhere else, like in a rails gem. I have had to solve this problem before in Rake. Awhile back I hacked something up that would totally trump a predefined rake task and...

Git Init XCode Projects

Here is a little ZSH function I have been using for quickly setting up new XCode apps I call tire kickers, little play and learn apps. Being able to track your learning as you go with git. if [[ -x `which git` ]]; then function ginit_xcode () { git init echo "\n\n# XCode\nbuild\n*.mode1v3\n*.mode2v3\n*.nib\n*.swp\n\ *.pbxuser\n*.perspective\n*.perspectivev3\n\n# OSX\n.DS_Store\n\n\ # TextMate\n*.tm_build_errors\n\n\n" >> .gitignore git add .gitignore git commit -m "Ignore Xcode stuff." git add . git commit -m "Initial Xcode project." } fi The...

Simple Script/Console Function

This is something simple I worked up today for my ZSH profile that let's me keep my simple sc alias and have it work with all versions of rails. If you did not know, all the script files in rails 3 are gone and the new all-in-one rails executable does all the heavy lifting. This little function even passes down all the arguments too. sc () { if [ -f ./script/rails ]; then rails console $argv else ./script/console $argv fi...

Unobtrusive JS In Rails 3 With Prototype

An updated version of UJS and forgery protection in Rails3 here. Are you bleeding on the edge of rails 3 and need to shim up some unobtrusive JavaScript to work with your link_to code that uses a destructive :method option? I did today and here is what I did to solve it. If you are unfamiliar with the problem, and what has been happening in rails 3 with UJS, check out Piotr Solnica's blog for a good run down. Or...

Quickie.js - Prototype wrapper for QuickTime

UPDATE: May 15th, 2011 - Today I decided to to re-write this class as my first dive into both CoffeeScript and jQuery. You can find an updated version in this gist on github. As some of you know, I am in the last steps of announcing my first iPhone application. We all know that every good iPhone application has a great marketing website with a screen cast. I myself was heavily inspired by the Tapbots Convertbot website while building my...

Rails Button Links In Embedded Forms

This is one I have had sitting around for almost 3 years now in my toolbox and thought I would share. Have you ever had complicated rails forms and needed simple form buttons that just took you to a simple link? Were you bitten by the button_to helper code because it generates another form inside of a form? If so, here is a simple rails view helper I made that creates simple button links for embedded forms by making an...

Authenticated S3 GETs For Private Objects Using Paperclip

UPDATE: [10/18/2011] I now use Fog vs AWS::S3 with Paperclip. I have included a Fog specific example below. Yea I know, I am probably the last person on earth that is just getting around to using Paperclip. To be honest, most of my file upload code was written way before Paperclip or even AttachementFu was ever conceived. And frankly, I do not do much social app coding on the side - so the need never came up. But that changed...

Meta Programming In...

Last nights 757.rb meeting was a great success. We did a talk titled Introduction To Ruby & Rails for all the new comers that might have been interested in learning more about both - from the ground up. Since Ruby was my first language and my toolbelt only extends to JavaScript and Objective-C, I'm always interested in how other languages do the things that I love so much in Ruby. One of the biggest pluses for Ruby, to me, is...

Installing REE With The Snow Leopard SQL Server Stack

Today I noticed that Ruby Enterprise Edition 2009.10 was released and I have really been wanting to see if I could get the SQL Server adapter tested and running under it. I am really curious how the speed improvements might look and will share my results below. This article assumes that you read my previous guide titled The Ultimate OS X Snow Leopard Stack For Rails Development - x86_64, MacPorts, Ruby 1.8/1.9, SQL Server, SQLite3, MySQL & More as I...

The Zombie Shotgun Revisited

My how time flies. Over a year ago I created a simple bit of code that was useful for stopping ActionController routing errors from common Microsoft attacks from sending exception notification emails. Well now most people do not use exception notifications emails in favor of apps like Hoptoad. And hey, most code like this has moved to Rack middlewares. Yesterday I noticed a rack code competition that encouraged "most useful and top quality Rack middlewares". Well the Zombie Shotgun is...

The Ultimate OS X Snow Leopard Stack For Rails Development - x86_64, MacPorts, Ruby 1.8/1.9, SQL Server, SQLite3, MySQL & More

If you are interested in using RVM with a MacPort base for the SQL Server stack, check out this article. TinyTDS is the upcoming de facto raw connection method for the SQL Server adapter. Please read the Using TinyTDS wiki page on the adapter for switching. No longer do you have to worry about compiling ODBC layers! I have written an updated article on the MacPorts installation of the latest RubyODBC. It includes information pertaining to utf8 support. This guide...

757rb Memcached Talk

Earlier this week I gave a talk at our local ruby users group, 757.rb, about Memcached. Here recently I started picking it up again so that I could keep track of large sets of PK/FK changes during a big database move. In doing so, I decided to dig deep into it's internals and get a better grasp of how I would use it when I decided to do some serious fragment caching again. The biggest thing I took away from...

PDF::Writer For Ruby 1.9

If you have legacy code written for ruby 1.8 and you want to run 1.9 and support your old PDF::Writer code, then just jump right over to my Github pdf-writer fork and get it. $ gem install metaskills-pdf-writer If you are interested in knowing some of the dirty details about what pitfalls are under 1.9, read on. The biggest thing for me was getting used to the character encodings. Including string literals in your code that are say UTF-8 or...

Learning Objective-C & iPhone Development

What have I been up too lately? Well primary working my butt off in my day job and after that, I just finished a week of vacation. As an aside, I need to disconnect more often, my vacation was very relaxing. But what's more relaxing that doing things in the fresh outdoors? Well learning another programming language of course. That is why this week I have seriously started learning Objective-C and iPhone application development. In fact I just got my...

Git & Subversion User Commit Reports

Want a list of the users and the number of commits they made? Git makes it really really easy, while I could not find such an easy method on Subversion. Here they are. Git $ git log | git shortlog -n -s Subversion #!/usr/bin/env ruby require 'rubygems' require 'activesupport' log_xml = `svn log -q --xml` svn_logs = XmlSimple.xml_in(log_xml)['logentry'] report_hash = svn_logs.inject({}) do |report,log| author = log['author'][0] report[author] ||= {:commit_count => 0} report[author][:commit_count] += 1 report end commits_authors = report_hash.keys.map {...

MultiRuby The MacPorts Way. Testing Your Rails Apps With Ruby 1.9

UPDATE: In a recent article, I covered how to install REE and have hence NOOP'ed this function to ignore the symlinking when REE is installed. Ruby 1.9.1, the stable release, is just around the corner and if your like me, maybe you want to start playing around with it and perhaps test a few projects using 1.9 with edge rails 2.3. If so, and your on a Mac, then perhaps this installation method might appeal to you. I'll break this...

Autotestify Brothers and Sisters

Based on my previous article Using Autotest For Rails Plugin Development, Brennan Dunn wrote a ZSH function that helps him with his eager rails plugin work. Testing plugins is simply the most fun you will ever have. It's nice to test in isolation and easy to make a plugin test multiple rails versions, etc. Typically plugin testing is very fast to because you are not burdened with excessive tests in a big app that might use it. Just the ones...

Go Buy Envycasts Now!

I got a chance to meet Gregg Pollack at this years RubyConf, a great guy. In fact I seem to owe him alot. Not only did I get 3 mentions lately on the main rubyonrails.org site, but it appears I got one of my 2.2 additions mentioned in their new envycast that covers rails 2.2. Sweet! So now it is my duty to help the Rails Envy guys to bank it Grossenbach-style. If you have not done so, go check...

SQL Server Adapter For Rails 2.2

So that about sums up what I've been doing for the past 4 weeks. A total rewrite of the SQL Server Adapter for Rails. On top of passing all the Rails 2.2.2 tests, which is MAJOR news, it includes tons of new features. Unicode column support, pessimistic locking, date/time column casting, DDL transactions and way more. On top of that. It was nice being mentioned on the rubyonrails.org website not for my first, second, but a THIRD time. Thanks Gregg!...

Code-O-Lanterns: What Scares You?

While reading the The Unofficial Apple Weblog today I noticed this sweet little Jack-O-Lantern screensaver for OS X. After some feedback on the 757.rb group, I decided to make some Code-O-Lanterns. Follow the instructions for the Jack-O-Lantern screensaver on where to put the carving files. If you are not on a Mac, I have taken some screen shots that you can use for desktop pictures. If you would like to see a code o lantern that is not up... just...

Plug It In Plug It In

I've been busy putting together some plugins form misc work. If you did not catch my latest article Jack has_many :things where I covered GroupeScope, by all means check it out. I've also just finished up a pretty solid backport of NamedScope that can be found on my Github page. It bills itself as a well tested complete back port for rails 1.2.6 and 2.0.4. One thing that has been a real help while I've been developing these plugins is...

Jack has_many :things

UPDATE: [12/06/2011] The GroupedScope gem has been updated for Rails 3.1. Many new features have been added with a few mentioned below. Check the project's readme for complete details. I am Jack's sofa, stereo and wardrobe... I make Jack's life complete. I reside in a ActiveRecord table called "things" and Jack is the only one that has the key. This is Jack's life, and it's ending one minute at a time. As rails developers, we have done this simple relationship...

Using Autotest For Rails Plugin Development

I love autotest. I have event posted before how to extend the idea of autotest sounds to a red/green playlist but now that I am taking more time to extract some of my work to plugins, I really wanted autotest to come with me. The problem is that the default autotest mappings do not play with rails conventions, the biggest being that test files for a lib match the name of the lib with _test.rb at the END of the...

Hell'OO HomeMarks

Well HomeMarks v2.0 is done and ready for the public. You can download it from my Github project page. It has a real simple rake app:bootstrap task that I came up with over the weekend will have you running a local copy in only a few seconds, give it a try. Sometime over the next few days, I'll move over the live site to this code base too. If you have not yet kept up on the implementation mantra I...

Stop Exception Notifications With The ZombieShotgun

I am all about knowing how to survive a zombie invasion – as much as I am a firm believer of using the right tool for a given job. It can not be argued that killing zombies with a shotgun to the head is as natural a fit as peanut butter to chocolate. They simply just go together. Now real zombies may not be a daily nuisance, but computer zombies are a daily pain in the butt to network administrators...

RESTful AJAX with Forgery Protection

Writing the new HomeMarks has been a great exercise. I've learned that the AJAX Head Design Pattern Implementation is more akin to developing a service-oriented application (SOA) since I have moved all client-side coupling from the controllers, like RJS, and only respond with HEAD or JSON data. Today I learned about Halcyon which is self described as a JSON web application framework built on Rack. If you take a look at their example, it looks a lot like HomeMarks v2,...

Coulda Shoulda Woulda

It has been about 6 months now since I started using the Shoulda testing plugin as my BDD/TDD tool of choice. Unlike a lot of other people, I did not flock to the RSpec bandwaggon. Personally I think RSpec is horribly bloated a sledgehammer for a simple issue, the need to have test code organized with nested setups and context blocks. If you are new to Shoulda, I highly urge you to take a look at the Thoughbot project page...

The "AJAX Head" Design Pattern

Chris Williams did a really great write up on this pattern with great details on when/how to use it. Please considering reading it afterward. This is the first of a few articles covering the total rewrite of the HomeMarks.com code base as I upgrade it to Rails 2.1. The "AJAX Head" pattern is the moniker I have assigned to methodology that has come about during said rewrite and the design decisions I choose early on. The rules were simple. Total...

Using RubyAMP TextMate Bundle With /opt Ruby

I've been a TextMate user for a long time now and I'm still finding new things to do with it. Here recently I wanted to use the RubyAMP TextMate Bundle and was a little miffed to find that it was pointing to my OS X system ruby. The error message looked something like this when it went looking for my ruby/gems. No such file to load -- appscript (LoadError) from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require’ /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `require’ ... My problem is that I...

How to use Passenger (mod_rails) with rails edge 2.1

UPDATE: This issue has now been resolved in the official release. If you are like me and have been using passenger, then you may have run into an issue when working with rails edge. I mean the REAL rails edge on Git, not that fancy rake task which I think is still pointing to a subversion snapshot. Let me take an aside on how to freeze rails edge to a project that you are managing in Git. This method is...

Now on Passenger (mod_rails)

Well this is working out well so far. I'm really liking the Passenger (mod_rails for Apache) extension. Right now I have this Mephisto site running it and it seems to be doing really well. Also, most people do not do this, but I run a full development stack Apache/MongrelCluster to mimic production boxes the best way I can. Now I am running mod_rails on all my development hosts. Some Things I Like I do not have to fuss with OS...

Autotest Playlist For Red/Green Feedback

Here is how to get a playlist of sounds that will be hooked to both your autotest :red and :green callbacks. Basically this gives you a folder of sounds that are played one after another, in a loop, as your tests pass or fail. See this move below for a quick example. Step 1: Install QTPlay from MacPorts $ sudo port install qtplay Step 2: Download My Autotest Playlist Files $ cd ~ $ curl -O http://cdn.metaskills.net/downloads/autotest_playlist.tar $ tar -xf...

Autotest Infinite Loop On Failure & Error

I just had an issue pop up today that seemed to be an issue for a few others. It seemed that all of a sudden that my autotest was stuck in an infinite loop after a failure or error. At first I thought it was related to some additions to my ~/.autotest file but after commenting out the whole lot of additions there, I realized it was something else. Here was my fix. Basically I think these errors are always...

How To Stop Delivery Of An Email Within An ActionMailer Method

OK, so you want to keep your code placement REALLY organized. You have read about my persnicketyness and now you want to practice the best in concern placement and keep those controllers of yours really slim. Like me, you may want to try and keep controller feature additions to very specific one liners of code. Organizing your controller code to do just that with ActiveRecord models or even your own custom classes is a pretty easy task, but how do...

MetaSkills.net Reborn on Mephisto

Well after a year of neglect, the MetaSkills.net blog has been reborn on Mephisto. Previously I was using Drupal and it finally got to a point where I was so deep into ruby that I did not even have the gumption to open up a PHP session to publish anything. The sad part is that I told myself that this PHP disdain would help me get off my butt and move to Mephisto. You know, eat my own dog food...

Quake Style Terminal Window on OS X

Well this is far beyond cool but highly functional, a Quake like terminal implementation of Terminal.app that is a HotKey away from within any application. A friend turned me on to this after it showed up on the Monday morning Apple links post from arstechnica.com. Although I have never thought of this idea, it seems to have been a popular request for quite some time and after a public request, the author of QuickSilver stepped up to the challenge and...

Getting On Good Terms With The OS X Shell

I will be the first to admit that I am really just learning how to tap into the power of my shell environment and to be honest, I've spent way to many hours reading man pages and figuring out how to do some really neat things that help my automate my workflow and system administration. Mostly these are just basic tasks like my Simple MySQL Backup and Deleting Invisible Resource Files scripts. But in all seriousness, when you get right...

Learn To Program in Ruby and Basic SQL

I've been learning to or "trying to learn" Ruby on Rails for a few months now and things have always kept me from finishing the book that I purchased from those great publishers at the pragmatic bookshelf. My problem has been that sometimes other work has gotten in the way, but mostly it was because I did not have the core understanding of the basics for building web applications. Especially in the areas of object oriented programming and database languages....

How To Control Browser Caching with Apache 2

If you are like me, an up and coming network geek, you probably thought that browsers automatically cached a site's assets and media as you went through it and looked at each page. I was very surprised to find out that this was not the case. In fact, every time I went from page to page on my newly created MetaSkills.net blog all of the CSS, PNG, JavaScript and other media files that were common to those pages were being...

A Review of Digg.com Traffic and CDNs

Thanks to all those that read my recent post about networking 3 Mac Mini's Hopefully it can help you create a network that is as close as possible to the administrator's second home, the NOC. As an aside form the posts I had planned, I did want to share some of the statistics that the digg.com exposure generated and some "simple" helpful tips to those interested in surviving high traffic/bandwidth peaks. I'll cover more "technical" ways of setting up your...

Mini Network with a Big XServe Style

Or, how to be the biggest network geek you can in only 1 square foot of space. Starting last year after reading Ward Mundy's How-To Bonanza, I knew I needed to use the Mac Mini as the core hardware component for my home network. Mostly because it looks good and small form fits easily on my desk. Good as that might be, the Mac Minis do have drawbacks and, if you're serious about your hosting choices, these do have to...

How To Setup a Simple MySQL Backup Script

Lately, I've been loving all things that can be solved by using RsyncX. It's my de facto backup utility and I just keep finding more and more tasks for it as each day goes by. It has become the hammer for all my system's needs. So when it came time for me to implement a nice little backup routine for the MySQL databases hosted here at ActionMoniker.com, it was the first tool I considered. My requirements were simple, I needed...