Archive for 2012

  • Rambling Trie: A custom Trie data structure implementation in Ruby

    February 10, 2012


    This post was originally published in the Rambling Labs Blog on February 10, 2012.


    We’re proud to announce that our first gem is here!

    It’s called rambling-trie, and it’s an implementation of the Trie data structure. A Trie is an ordered tree data structure, and it is great for managing dictionaries and for word searching and matching.

    Now, to install the rambling-trie, you can either install it manually by running:

    gem install rambling-trie
    

    Or, you can add this line to the Gemfile of your application:

    gem 'rambling-trie'
    

    To create a new Trie you can do this:

    require 'rambling-trie'
    
    trie = Rambling::Trie.new
    

    And to add a new word to the Trie, you can call this:

    trie.add_branch_from 'word'
    

    Or to automatically load words from a...

    Continue Reading →

  • Migrating your blog posts to Markdown with Upmark and Nokogiri

    February 3, 2012


    This post was originally published in the Rambling Labs Blog on February 3, 2012.


    As I said in my last post, for our new site, we changed our blog engine from WordPress to the Postmarkdown gem. At the end of that post, I mentioned that we had to migrate the old posts from WordPress to Markdown.

    To do this, we built a ruby script using the Upmark gem and the Nokogiri gem. Nokogiri is used for HTML and XML parsing, among other things, while Upmark is used to generate Markdown from a given HTML.

    First, we exported our old blog posts from WordPress to an XML file that looks like this:

    <?xml version="1.0" encoding="UTF-8" ?>
    <!-- This is a WordPress eXtended RSS file generated by WordPress as an export of your site. -->
    <!-- ... -->
    <rss

    Continue Reading →

  • Writing your blog posts in Markdown with Postmarkdown

    February 3, 2012


    This post was originally published in the Rambling Labs Blog on February 3, 2012.


    Another thing we added to our new site, uploaded back at the end of December, was the ability to write our blog posts in Markdown, which is a text-to-html tool that allows you to write formatted text without actually having to write all the corresponding HTML. Markdown is used for the project wiki pages on GitHub, and can also be used for the project’s readme file.

    Most of the time, I don’t like that HTML gets autogenerated for me, since I usually don’t get the results I want. We used to have the site (which was really the blog only) in WordPress, and I never used the autogenerated HTML. In fact, it was quite the opposite: I wrote every blog post in plain...

    Continue Reading →

  • Rails 3.1: Treating your '.swf' files as assets

    January 12, 2012


    This post was originally published in the Rambling Labs Blog on January 12, 2012.


    This week, I’ve been deploying one of my current Ruby on Rails projects to WebFaction. For what we found, it’s definitely one of the best options out there for shared hosting with Python and Ruby.

    The application being deployed happened to contain some static flash content (not my idea of course :P), which so far we had put in the public/ directory and had served with no problems so far, while testing locally and on Heroku. However, when we were testing it out on WebFaction, it kept returning 404 errors.

    So, googling for a while, I stumbled into the swf_fu gem. It’s main function is to treat the swf objects as just another asset in the application. So...

    Continue Reading →

  • jQuery Rambling Slider v0.3.1 is out!

    January 7, 2012


    This post was originally published in the Rambling Labs Blog on January 7, 2012.


    Version 0.3.1 of the jQuery Rambling Slider has been released! You can download it from GitHub and test it out.

    The latest documentation of the jQuery Rambling Slider can be found on the project’s wiki on GitHub.

    There was an issue with the slider not working on IE 8, due to an undefined function. I have to thank the people that emailed me about it. Because of them I was able to spot the issue and fix it!

    This release includes the following:

    • Removed dev7 logo and added RamblingLabs logo.
    • Added the box and slice generators.
    • Removed some unnecessary px suffixes (top, left, right, bottom).
    • Fixed indexOf issue with IE 8.
    • Some additional refactoring.

    Continue Reading →

  • Rails 3.1 - Adding custom 404 and 500 error pages

    January 5, 2012


    This post was originally published in the Rambling Labs Blog on January 5, 2012.


    As I said when announcing the Rambling Labs new site, we’ve been learning a lot of stuff while building it.

    Something that we didn’t have the chance to implement on our current projects (but that we will be including soon), is adding custom error pages to the site. So far, what we were looking for was two things: a custom 404 error page and a custom generic 500 error page.

    For the experience I have now with Rails, I thought this would be a piece of cake. Well, in fact… it would’ve been if we were using Rails 2. But guess what? The error handling behavior in Rails 3 is not what you would expect. Even worse, it’s broken for routing errors!

    For what I could...

    Continue Reading →

  • Replacing ERb with HAML on your Rails application generators

    January 5, 2012


    This post was originally published in the Rambling Labs Blog on January 5, 2012.


    As you may know, we’ve been using HAML lately for our views.

    Since I don’t plan to use ERb for my views anytime soon, I want HAML to fit in as smoothly as possible. Luckily, there is a way to replace ERb as the default generated view.

    Just add this line to your Gemfile:

    gem 'haml-rails'
    

    And you should be good to go!

    Now, when you run rails generate controller test method_one method_two, you should see something like this:

          # ...
          invoke haml
          create app/views/test
          create app/views/test/method_one.html.haml
          create app/views/test/method_two.html.haml
          # ...
    

    Way easier than what I thought it would be. But you know, that...

    Continue Reading →

  • Writing elegant HTML with HAML

    January 4, 2012


    This post was originally published in the Rambling Labs Blog on January 4, 2012.


    Another cool thing that we learned while building the new Rambling Labs site was HAML. It’s a markup language that is based on the premise that ‘Markup should be beautiful’, in their own words.

    It’s very easy to install, just add gem 'haml' to your Gemfile and run bundle install. To use it, replace your view_name.html.erb file with a view_name.html.haml file.

    Like SASS and CoffeeScript, to achieve the beauty it professes, HAML uses indentation to determine what it should do next. This means, and you guessed it, that it writes beautifully.

    Compare this ERb file:

    <div id="single_post">
      <h2 class="post_title"><%= link_to post.title, post %></h2>
      <div

    Continue Reading →

  • Generating your site menu with the 'simple-navigation' gem

    January 3, 2012


    This post was originally published in the Rambling Labs Blog on January 3, 2012.


    One of the cool things I learned while building our new site was how to generate your site navigation menu without having to do the highlighting logic yourself.

    There’s a great gem out there for this called simple-navigation, which you can find on GitHub. It’s easy to set up and use, so you will probably do what you need to do really quick. To install, add it to your rails application Gemfile:

    gem 'simple-navigation'
    

    Then, run bundle install. After it’s installed, generate the configuration file for it, which will be the config/navigation.rb, with the following:

    rails generate navigation_config
    

    Go ahead and open the config/navigation.rb file, and add...

    Continue Reading →