Unless you have ultra simplistic needs, (and are using Rails) I always recommend using the fantastic will_paginate plugin for paginating ActiveRecord, and even non-ActiveRecord collections! But, if you have a basic need to to page an array, you could open up the Array class and add this method:

class Array
  def page(pg, offset = 10)
    self[((pg-1)*offset)..((pg*offset)-1)]
  end
end

This is a beautiful little method that adds #page to all arrays, and can be utilized like this:

my_array = [1,2,3,4,5, ... ,20,21,22,23,24,25]
my_array.page(1) #=> [1,2,3,4,5,6,7,8,9,10]
OR
my_array.page(1, 5) #=> [1,2,3,4,5]

Feel free to use this if you like it!

At Caring.com, we write our view templates using Haml and Sass (with Chris Eppstein’s Compass CSS Framework). It was a little strange to get used to at first, especially coming from tag-based/ERB-style frontend templating, but I have found that it is surprisingly straightforward, and succinct. TextMate, which is a fabulous text editor for rails and ruby, has two bundles that I use constantly that make my life easier (code coloring especially) in both Haml and Sass.

I am writing this blog post to share the bundles I use everyday with you, and so that I can remember where they live, for myself.

For Sass integration I use this bundle by seaofclouds:
git clone git://github.com/seaofclouds/sass-textmate-bundle.git "Ruby Saas.tmbundle"

For Haml integration, I use the “official” one provided by MacroMates (the creators of TextMate):
svn co "http://macromates.com/svn/Bundles/trunk/Bundles/Ruby Haml.tmbundle"

Clearly, you need to have both Subversion and Git installed to install these plugins, however you may be able to travel to github and download a zip file if need be.

I’ve been working with Mr. Scott Robbins on his fantastic jQuery PageSlide plugin for the last few weeks. It has been a lot of fun, we’ve moved the project off of google code completely, and today have released version 1.1 of PageSlide on Github. version 1.1 is essentially a complete re-write touting a ton of new/awesome features, here is a list from the README:

I am very excited about this plugin, and will be using it in some of my projects very shortly! If you like the project, please “watch it” on Github and tweet about it and stuff while you’re at it :)

Get jQuery PageSlide here, it works with jQuery 1.26 and up!

EDIT: Live demo can be found here: http://derekperez.com/jquery-pageslide/demo/

Thanks so much everyone for submitting your Fibonacci examples! One of the reasons why I asked everyone to do this is because it gives me (and all of us) a chance to learn about different approaches and different languages. So, in case you haven’t figured it out, it was sort of a trick question.

Fibonacci is generally very fast, unless you are over-architecting the solution. Let me show you what I mean:

def fibo(n)
  (!(n>2)) ? n : fibo(n-1)+fibo(n-2)
end
 
37.times do |i|
  puts "n=#{i} => #{fibo(i)}"
end

This was my first attempt. Its a beautifully complex execution of the algorithm, using recursion. However, notice that I am not storing any of the values that I am calculating? That causes the processor to go crazy around time 30. This would be what I call a classic example of over-architecting a simple problem.

But its cool right? :)

Here is my faster, smarter, more performant version:

$fibs = [];
 
 
def fibo_calc(n)
  (!(n>2)) ? n : fibonacci(n-1)+fibonacci(n-2)
end
 
def fibonacci(n)
  if $fibs[n]
    return $fibs[n]
  else
    x = fibo_calc(n)
    $fibs[n] = x
    return x
  end
end
 
37.times do |i|
  puts "n=#{i} => #{fibonacci(i)}"
end

This is much much much faster, and can hit 30,000 iterations without missing a beat. The cooler thing too is that I can mix up the 30,000 integers that its calculating for, and it can run a “shortcut” using the array. Very cool.

So that was my nerd realization of the month. Of course, there are a billion ways to skin an algorithm, but sometimes the most concise or technically interesting way, is the slowest.

Lately, I’ve been studying algorithms, just for fun, because I am hardcore like that. Also, I’ve been very excited to test the speed/performance of the newly released and stable Ruby 1.9.1. I have been waiting patiently for the release, it is full of great new things like a modern VM, massive integer performance tweaks, language readability improvements, and full unicode support.

So I decided to do some masturbatory benchmarking, using Fibonacci! Also, did you know that Ruby has a builtin benchmarking framework?

Fibonacci is not a very difficult algorithm, though I learned a lot about what to do (and not do) when it comes to writing this sort of code in Ruby. (and any language for that matter)

So here is the challenge, write your best Fibonacci Sequence algorithm in any language you choose, discuss the pros/cons of your implementation, and speed of execution. Also, its mandatory that your algorithm calculates a minimum of 36 sequences deep, extra points if you get to 30,000 in less than 5 seconds.

In a few days, I will post how I did it in Ruby. I don’t really have a prize lined up or anything, maybe I will come up with something. At the very least, you’ll have bragging rights.

The iPhone is hot. Its a badass micro-computer-internet-having-app-installing-jizz-casting-awesome-machine that can also make phone calls, but I have to bitch about one major flaw in the entire thing, and that flaw is Mobile Safari. Don’t get me wrong, I am a big fan of the mobile browser, it is leaps and bounds greater than anything else out on the market, but I ask you Apple, why not make it the greatest mobile browser on the market?

So what am I bitching about specifically? The iPhone has immense data harvesting capabilities, from geo-location, to the accelorometer, etc. But all of these fantastic API’s are available only to native, objective-c based applications, not Mobile Safari!? Explain this to my Apple, why is this not exposed through a JavaScript API? That is absolutely trivial to provide to the lowly web developer!

Apple and the iPhone are doing amazing things with the types of datasets it makes available to developers in the native context, all I am saying is, make it available to every context of applications! Libraries like PhoneGap are attempting to make this a reality, but again, the biggest limitation is the fact that PhoneGap still requires you to create a native application to act as a wrapper to your web application, this seems like a stop gap solution (heh) or an unfortunate hack.

Its also very apparent that Mozilla sees the future of location-based services being able to provide very personalized and exciting experiences to the web through their efforts in Mozilla Geode. Perhaps its true that at this point, that sort of data availability in a web browser could be seen as negative, but I am not sure I agree. I am willing to bet that within the next 6 years, Apple will be introducing GPS into their laptops, providing application developers with the same location-awareness capabilities on their computers that exist today on their phones.

Hopefully Apple will wise up in the future, but I highly doubt it. Something tells me this is a designed limitation, they are probably doing their best to keep control over what people are doing with that data through the app store vetting process. Oh well, one can dream!

I am absolutely excited about this news!! Yesterday, both the Merb and Rails camp have announced the news, so I won’t bother reiterating whats already been said. I’d rather talk about some of the major points that really get me excited about this announcement and how it is going to impact not only the history of Ruby on the web, but potentially web programming from this point on.

Fully Modular Core
I am happy that DHH and co have embraced the modularity concept that is one of the core ideals of the Merb project. Now, if you don’t want to Prototype as your JavaScript system, you can toss it and stick in jQuery, which will run 100% as well as the default. Although its 100% modular, the “Rails Way” is going to give you a smart set of defaults that you can completely customize to fit your needs!

I must admit, this is one of the sexiest things about Merb.

Speed is Quickly Becoming a Non-Issue
In the Ruby world, there is a ton of exciting innovation going on around building some amazing virtual machine technologies and really pushing the limits of what can be done with such an expressive and dynamic language. Also, we are seeing some fantastic developments on the deployment side of things that are making it not only extremely easy to deploy, but faster the serve requests as well.

So naturally, the next place to go for optimization is our framework. Merb has already made a ton of strides in making a thread-safe, and extremely fast framework. This development stack is going to scream in 2009!

AmazingĀ  Base and Synergy
Between the Merb and Rails technologies and groups, there is going to be all kinds of new things to learn and all sorts of great people to work with and learn from. I am absolutely excited about what all of this means for the Ruby/Rails/Merb communities. We have got one of the fastest growing and fully-integrated technology stacks available for the internet today as an open source foundation.

With the emerging ecosystem of technology and thought that is occurring in this community, we are going to be seeing some amazing things in 2009.

Lately I’ve been doing a lot of thinking, thinking about how technology and the internet have been applied in such fascinating and unbelievable ways, ways that have absolutely re-written the fabric of how we as citizens of earth interact with information, but also each other. When I think about all of this, the truly astounding thing is the passage of time that has elapsed. Companies like Apple, Google, and Wikipedia are doing their best to make sure that the way we interact today, is nothing like the way we will interact tomorrow.

These are visionary companies, ran by some of the best and brightest of our time, can you imagine a world without Google? (your children won’t be able to). The internet itself has been the biggest catalyst of our 21st century evolution, providing a platform and foundation for limitless connectivity, where our ideas and capabilities are the only limitation.

Its not often that I feel so inclined to be nostalgic about an industry that hasn’t even been around for 50 years, but lately, I’ve been evaluating my place in the scheme of things. I’ve been watching the innovations and “innovations” that have hit the market in 2008, and frankly, I think we can do better.

But this isn’t new, people have been inventing solutions to problems nobody has had forever. I guess you could say, this is my letter to myself to make sure I am actually doing things and working with people who want to make a difference in the world, rather than “minnovate”. People say that times like this (referring to our economy) are when people sit down and do the most amazing things, not because its the hip thing to do, but moreso out of necessity.

So here is to a world changing 2009.

Linkedin just minutes ago announced they’ve thrown their hat in the “social application platform” ring! This is exciting news for people who are poised to bring innovative and interesting applications to the business and professional network.

Read more about the press release here at TechCrunch. As of today, there is no documentation or word on how exactly one creates an application for the new platform, but you can contact them to recieve more information!

I have been rolling around the idea of starting up more freelancing to try to bolster my savings for the coming years, so I’ve decided to take on more consulting work. For an indepth look at my work experience and skills, please visit my linkedin profile, here are some highlights.

- 5 years relevant web development experience
I’ve worked a ton with the web, I’ve done everything from ColdFusion to my current favorite, Ruby (and Rails). I have a lot of experience working with JavaScript and XHTML/CSS, very comfortable doing frontend and backend development, as well as database work (although, I don’t want to use the term DBA). If you’d like to see my portfolio, contact me directly.

- Did I mention I love Ruby?
I have done a lot of work with Ruby in the past couple of years, I was highlighted on the RailsEnvy podcast a few weeks ago for a modest open source contribution I made called SmartMonth. I’ve worked on some medium-sized rails deployments, and am looking to grow my portfolio.

- Plays well with others
I love working on small, motivated teams. I always enjoy adding (and learning) from the synergy of a great team. I also test all of my code (quite thoroughly) and won’t break “the build”.

- UNIX Aficionado
I love UNIX, and its my deployment environment of choice, I’ve got a lot of experience working with Capistrano, and am very adamant about automating things wherever possible, and documenting things thoroughly.

- Entrepreneurial-Minded
I have a passion for growing things, I am a very dedicated team member, and am also very aware of the needs of startup-oriented businesses, I’ve worked with a few startups at this point, and have gathered a decent amount of relevant experience helping companies and products grow.

If I sound at all interesting to you, please don’t hesitate to drop me a line, or if you know someone who might be interested in hiring me, please forward my information along and I’ll send you a Christmas card.
Thanks everyone!

keep looking »