HomeRamblings  ⁄  Programming

Programming

General topics of interest to software development.

A Reflection of the Technologies I Built Things With

Sometimes, a random event triggers a walk back down memory lane. That moment came for me the other day when I came across a CDR containing the code I ever wrote the first 15 years of my programming career. For just over 30 years, I’ve been building software professionally and I have kept backups of nearly everything I’ve ever written. What somewhat surprised me as I looked through all this old code is the breadth of machines, operating systems, and languages I touched along the way. As I thought on this list, I wondered what all I made use of during my career and wondered what that list might look like, so I set out to compile just such a list. If I used the language, operating system, or platform and built a complete application that was deployed and used… read more


Dynamic Routing in Rails Revisited

Ever since my original post Creating Dynamic Routes at runtime in Rails 4, I have been digging into Rails routing more and more. I’ve gotten a lot of feedback on the post itself as well as comments in the IRC #rubyonrails channel with an over abundance of passionate pleas not to do routing this way in Rails.… read more


Creating Dynamic Routes at runtime in Rails 4

I was working on a fairly simple site that has a content management component to it and wanted to find a way to dynamically generate the routes to the pages that were managed on the back-end by the site authors. This article presents an alternative to the usual approach of creating a catch-all route in the routes.rb by generating specific routes to each and every page.… read more


Adding Google Analytics script to Sprockets

Today, I wanted to add Google Analytics for tracking my website’s usage history. Rails 4.0 has an excellent assets pipeline that generally works well out of the box with little fuss, but when you try to do something outside adding another require to the “assets/javascripts/application.js.coffee” file, it gets a little more complicated to implement. Here, I show you exactly how to add Google Analytics as a coffeescripted script that is only loaded in the production environment.… read more


Gems you should consider for every Rails projects

Ruby on Rails provides a lot of great functionality out of box, but there are a few gems I almost always add to my new Rails projects. Here are some of those gems I practically cannot live without.… read more


Implementing Ruby jobs in the background

I needed a way to kick off a background job that was triggered by an end-user on my Ramaze-backed website and could run for almost two hours! This article brings together all the elements to get the job done.… read more


One ActiveRecord Model Acting as a List and Tree

Occasionally, Rails can appear to make your life extremely easy while silently throwing you a curve-ball. I needed a model that required a hierarchy while also preserving order of the records. Although fairly straightforward to set up and start immediately using, there are a couple of “gotchas” to watch out for and this article covers those pitfalls and shows how to apply the cool new “dirty attributes” feature in ActiveRecord.… read more


Ultraviolet gives new life to Syntax highlighting

I am tired of Google’s Syntax highlighter.  If I accidentally switch to Visual mode in the editor and do some edits and switch back to HTML mode, then I lose the class=”code” moniker and I have to go through the entire post and fix. Another drawback I have with Google Syntax highlighter is that the page renders without highlighting and then all the code listings change to syntax highlighted text a few moments later. Introducing Ultraviolet, a syntax highlighter supporting over 50 syntaxes and any TextMate theme.  Ultraviolet is based on Oniguruma, a regular expression library that comes standard with Ruby 1.9. Ultraviolet requires a little more effort for me to cut and paste, but I am definitely much happier with the end results and Wordpress no longer mungs my posts. Only real complaint I have is that I can’t… read more


Ramaze and ActiveRecord

Thanks to the great folks on IRC over at Freenode#ramaze, I was able to not only get Ramaze working with Erubis and Activerecord for a pseudo apples to apples comparison of Rails vs. Ramaze performance benching, but I was also able to get Apache 2.2.9 talking to Passenger to Ramaze. This quick post will take you through the basics.… read more


Initial release of Elemental

I am happy to announce the initial release of Elemental 0.1.1. Elemental provides enumerated collection of elements that allow you to associate ruby symbols to arbitrary “display” values, thus allowing your code to think symbolically and unambiguously while giving you the means to easily display what end-users need to see. Additionally, symbols are associated with ordinal values, allowing easy storage/retrieval to persistent stores (databases, files, marshalling, etc) by saving the  Element#value as appropriate (String by default, Fixnum if you “persist_ordinally”). The primary aim of Elemental is to collect and abstract literals away from your code logic. There’s an old programmer’s wisdom that you should not encode your logic using literal values, especially those the end-user is exposed to. Complete details provided in README.txt http://github.com/mwlang/elemental/tree/master http://rubyforge.org/projects/elemental/ From Gem:… read more


Rails has and belongs to many (habtm) demystified

Every time I have to implement a many-to-many relationship between Rails models, I seem to have to figure out how to do it effectively all over again. Especially as Rails seems to evolve the relational hooks with better support and elegance. Here, I will show a has_and_belongs_to_many strategy that works well for me. Along the way, I’ll expose a few other minor tricks, such as adding a custom inflector for pluralizing your model or not adding the ID column on a table declaration. The following Browser Edit form is what we’re going for. That is, having a list of Operating Systems to check off while editing a Browser object:… read more


Converting Oddmuse Wiki to Edgewall Trac

Our company began long ago with wiki’s, but we chose the Oddmuse wiki way back when. These days, we’re heavy users of Trac wiki because of its integrated ticket support system. So what to do with all those old wiki’s that folks have stopped using and reading. The Oddmuse wikis still hold valuable data, but they have since become an administrative overhead to keep around, so I decided to convert them all to Edgewall’s Trac. To get started, I needed to know how to get the data into Trac. The following links gave me an API I could utilize to create trac pages and content:… read more


A model-free wizard

Maybe I’m taking the whole MVC thing too far, but I’ve been reading and learning both Ruby and Rails at a fairly fast clip and just when I thought I was getting the hang of what goes in models, views, and controllers respectively, along comes The Advanced Recipe for Rails book with a recipe for implementing a wizard that threw me for a loop here. This implementation just so happens to be based off acts_as_state_machine, which plugs into your model classes. And of course, the acts_as_wizard plugin wasn’t too far behind! Well, asking myself whether the wizard logic should be allowed to bleed over into the model prompted me to see just how hard it was to build a wizard in a web interface anyhow (this is my first attempt at a multi-step workflow bit on the web). Most of… read more


Handling Date Entries

Separate inputs for a single Date Entry? pop-up Calendars? Enforce one way (i.e. enter in “mm/dd/yyyy” format)? What happened to the end-user perspective? User input parsing and validation is classic computer science and usability fodder, yet we seem to get ever more clever at making it more cumbersome to enter a date than to get a date! (I’ll leave the pun implications to the reader…)… read more


Conway's Game of Life in CoffeeScript

I was recently invited by Jonathan Wallace to a local Code Retreat where the developers were going to tackle Tim Conway’s famous Game of Life  Unfortunately, I was unable to attend, but the whole idea sparked my own self-exploration into both CoffeeScript and Middleman, which I had little practice and practical experience with.  You can find the resulting code in its entirety at https://github.com/mwlang/life_with_coffeescript… read more