Daily Ruby Tip #5 – Create your own map() or collect() method

A good Ruby programmer knows how to spin their own Ruby methods. Here is an example of what Ruby map() or collect() in the class Enumerable could look like. arr = %w{surf, sail, run} def my_map(array) i = 0 while(i < array.count) yield array[i] if block_given? i += 1...

Daily Ruby Tip #4 – Use map() inside a method to arrange arguments

This one is from the Ruby Metaprogramming book. Collapse a list of method arguments into an Array in Ruby. def organize_your_code(*args) args.map {|arg| arg } end >> organize_your_code(“spinach”, “margarita pizza”, “tiramisu”) => [“spinach”, “margarita pizza”, “tiramisu”] Happy Coding 🙂

Daily Ruby Tip #3 – Use YAML for a more readable console

Print console or IRB output in a more readable format without Pry or similar gems. $ rails console >> object = Object.new => # >> y object --- !ruby/object {} => nil With a large object you will see the object in a vertical column. 🙂

Daily Ruby Tip #2 – View gem source with Bundler

Here is a cool way of creating a link in Rails: $ bundle open 'some-gem' This opens the gem source in your default editor for inspection.

Daily Ruby Tip #1 – Ruby Hash params into URL

This is my new way of learning and promoting my intelligence in Ruby. My intention is to create a new Ruby tip everyday. These tips will come from all places and will certainly involve examples from work and frameworks. Here is a cool way of creating a link in...

Backbone.js, Ruby on Rails XSS Vulnerability Uncovered Using Presenters and .ERB

First, my apologies for really dropping my commitment to this blog the last six months. The next six months will be better, I promise. Second, the presenter pattern we built into our latest Ruby on Rails and Backbone.js application created an opportunity for XSS attacks. XSS attacks are nasty...

Ruby on Rails 3.1 Recaptcha Form with Validation

Forms are everywhere on the web. I am writing this post in a form, you will comment in the form below, and adding this post to your rss reader will require a form. The problem is, spammers love forms. The silver bullet for their attacks is the unchecked form....

Three Quick Command Line Tricks

Note: These are not all for the command line. There are so many other tricks we learn along the way and they are seldom documented. If you know others please throw them in the comments. MySQL Tip: When you run a normal query in MySQL prompt, if your table...

Local WordPress Development Environment without MAMP on OSX Lion

This post will teach you how to set up a local development environment to manipulate and create your web applications using the WordPress code base. A few years ago the status quo for getting a development environment for PHP applications was to use MAMP – Mac, Apache, MySQL &...