Archive for 2011

  • Stripping down Rails 3.1: Using only the database migrations

    November 23, 2011


    This post was originally published in the Rambling Labs Blog on November 23, 2011.


    The current project I’m working on is not using Ruby on Rails, but I still want to use ActiveRecord Migrations for the database changes.

    There are some options out there for this, and most people that I read about and had this issue just use the activerecord gem and set up their rake tasks.

    I don’t want to write my own rake tasks, since I feel that I would be reinventing the wheel. So what did I do? I created a new rails application, and stripped it down, removing everything that is not needed to run the migrations.

    First, I created a rails application called ‘deploy’ on the root folder of the application with:

    rails new deploy
    

    Then, I removed all the…

    Continue Reading →

  • Deploying on shared servers with git

    November 23, 2011


    This post was originally published in the Rambling Labs Blog on November 23, 2011.


    There’s a project I’m currently working on, which is right now hosted on shared servers. I worked for a little while before on this project, but just to add some tiny features and fix some bugs, so I didn’t have the need back then to have a deployment process all set up.

    But now, I’m probably going to be working for a couple of months on this, so I figured it would be better for my own sanity to just set everything up from the very beginning, to make the deployment process as easy as possible.

    I googled for a while and the people seem to be using git for this. Now, there are a couple of options out there. There’s resmo’s git-ftp which is a git powered…

    Continue Reading →

  • jQuery Rambling Slider v0.1.2 patches

    November 13, 2011


    This post was originally published in the Rambling Labs Blog on November 13, 2011.


    I didn’t have enough time to post this before, but here it is. I’ve made some patches for the jQuery Rambling Slider. You can see the tags on GitHub. These include (the key features are bolded):

    jQuery Rambling Slider v0.1.2.1 (patch 1, you can download it from GitHub):

    • Enabled method chaining on ‘start’ and ‘stop’.
    • Changed ‘animSpeed’ option to ‘speed’.
    • Added the ‘option’ and ‘effect’ methods.

    jQuery Rambling Slider v0.1.2.2 (patch 2, you can download it from GitHub), includes patch 1 and:

    • Some html validation.
    • Added the supported jQuery versions information.
    • Removed jQuery. Pulling it from the google cdn now.
    • Fixed issue with ‘getRandomAnimation…

    Continue Reading →

  • The jQuery 1.7 .animate() method and percentages

    November 13, 2011


    This post was originally published in the Rambling Labs Blog on November 13, 2011.


    As you may know, the jQuery Rambling Slider contains several animations. Some of them depend on changing the height of a div using percentages. Like this one:

    slice.animate { height: '100%', opacity: '1.0' }, settings.speed
    

    The problem with this is that with jQuery 1.7, the ‘100%’ was getting parsed to just ‘100’, so the height ended up being ‘100px’.

    Thankfully, there’s an easy workaround:

    slice.animate { height: "#{slider.height()}px", opacity: '1.0' }, settings.speed
    

    In this case, the slider is the container for the slice. So I just made the slice’s height to be animated to the slider’s total height instead of using percentages.

    I submitted a bug

    Continue Reading →

  • Adding custom method calls to the jQuery Rambling Slider

    November 12, 2011


    This post was originally published in the Rambling Labs Blog on November 12, 2011.


    The jQuery Rambling Slider v0.1.2 was released a couple of days ago. One of the features added was the ability to start and stop the slider like this:

    $('#slider').ramblingSlider('stop');
    $('#slider').ramblingSlider('start');
    

    Every serious jQuery plugin has some way to change it’s behaviour or query some data after initialized and the general approach for this is calling the custom methods as showed above.

    It is well known that in order to do this, you have to perform some dynamic method calling magic. This is what you find in the jQuery documentation:

    (function($){
      var methods = {
        init : function(options) { /*...*/ },
        show : function() { /*…

    Continue Reading →

  • jQuery Rambling Slider v0.1.2 is out!

    November 11, 2011


    This post was originally published in the Rambling Labs Blog on November 11, 2011.


    I am proud to announce that version 0.1.2 of the jQuery Rambling Slider has been released!

    It really has been out for a couple of days now, but I’ve had a couple of busy weeks. Nevertheless, I managed to do the major refactoring that I mentioned when version 0.1.1 was released. So, what have I added to this new release? Here’s the list:

    • Added the ability to call the stop and start methods from $('#slider').ramblingSlider('stop').
    • Added the foldLeft animation.
    • Refactored the build process, as the commands remain the same (cake build and cake minify)
    • Added the missing yuicompressor (oops…)
    • Reformatted the for loops to be more CoffeeScript-ish.
    • Added the…

    Continue Reading →

  • The joy of writing CoffeeScript

    November 11, 2011


    This post was originally published in the Rambling Labs Blog on November 11, 2011.


    I have been a fan of JavaScript for a while now, and I have dived into the CoffeeScript world for the last month or so.

    Guess what? I love it! It’s been a great experience so far.

    Definitely the one thing that I’m loving the most right now about CoffeeScript is the syntactic sugar. It’s basically a lot of simple shorthands for certain things (the -> is so handy). Take this example (and ignore what the excluded methods are doing):

    I had this:

    class BuildUtils
      combine_source_files: (callback) ->
        self = @
        fs.readdir './src', (err, files) ->
          self.error_handler err
          content = new Array()
    
          files = files.sort()
          for file, index

    Continue Reading →

  • Rails 3.1 - will_paginate and AJAX

    November 10, 2011


    This post was originally published in the Rambling Labs Blog on November 10, 2011.


    For a project that I’m currently working on, I have a couple of list views that needed pagination. So I went with the ol’ will_paginate gem (which I first saw years ago when I didn’t even consider myself a developer) to take care of this.

    It’s as simple as including a line with gem 'will_paginate' on your Gemfile, running bundle install, and include this in the controller:

    class OrdersController < ApplicationController
      def index
        @orders = Order.paginate(page: params[:page], per_page: 10)
      end
    end
    

    And this in the view orders/index.html.erb:

    <div id="orders">
      <ul>
        <% @orders.each do |order| %>
          <li>
              <!-- Show order stuff -->

    Continue Reading →

  • Unit testing the jQuery Rambling Slider - Part 2 - The DOM, jQuery and node.js

    November 9, 2011


    This post was originally published in the Rambling Labs Blog on November 9, 2011.


    In order to continue to add tests to the jQuery Rambling Slider, I needed to test something against the DOM. Problem is, you don’t count with the DOM when you’re running the Jasmine tests from console. So what should I do?

    As expected, I found that there is a DOM emulator in node.js :D. Also, to test using jQuery I needed to download the corresponding node package. So I didn’t waste any time and went ahead to install them:

    npm install -g jsdom
    npm install -g jquery
    

    So now, I can write something like this in my src/jquery.plugins.coffee:

    (($) ->
      $.fn.reverse = [].reverse
    )(jQuery)
    

    And test it on my spec/jquery.plugins.spec.coffee with something like this…

    Continue Reading →

  • Unit testing the jQuery Rambling Slider - CoffeeScript, Jasmine and node.js

    November 9, 2011


    This post was originally published in the Rambling Labs Blog on November 9, 2011.


    As you may know, I have been working lately on the jQuery Rambling Slider. One of my personal milestones with this project is to write as many unit tests as possible, so I began my research.

    Honestly, I didn’t know where to begin. I remember to have read once on twitter that someone was writing their tests with Jasmine and CoffeeScript, so that could be a good starting point (and it sounds really fun too!). I have worked with Jasmine before and it sure was a great experience. It’s yet another productivity tool made by the great Pivotal Labs guys.

    After googling for a while, I stumbled into a post from someone that was writing tests in Jasmine and node.js

    Continue Reading →