My submission for Ruby Challenge #3: Short Circuit
rubylearning.com/blog/2009/10/30/rpcfn-short-circuit-3/
-
100% RSpec test coverage
-
Works in both Ruby 1.8 and 1.9
# Drop this file in config/initializers to run your Rails project on Ruby 1.9. | |
# This is three separate monkey patches -- see comments in code below for the source of each. | |
# None of them are original to me, I just put them in one file for easily dropping into my Rails projects. | |
# Also see original sources for pros and cons of each patch. Most notably, the MySQL patch just assumes | |
# that everything in your database is stored as UTF-8. This was true for me, and there's a good chance it's | |
# true for you too, in which case this is a quick, practical solution to get you up and running on Ruby 1.9. | |
# | |
# Andre Lewis 1/2010 | |
# encoding: utf-8 |
require 'rubygems' | |
ActiveRecord::Base.establish_connection ( | |
:adapter => 'mysql', | |
:database => 'database', | |
:username => 'username', | |
:password => 'password', | |
:host => 'localhost' | |
) | |
module LegacyDatabase | |
require 'dr_nic_magic_models' |
// ==UserScript== | |
// @name Sort Delicious bookmarks by times saved | |
// @namespace jbgutierrez.info | |
// @description Sort Delicious bookmarks by times saved | |
// @include http://delicious.com/* | |
// ==/UserScript== | |
// Add jQuery | |
var dependencies = ['http://jquery.com/src/jquery-latest.js', 'http://tinysort.sjeiti.com/scripts/jquery.tinysort.js']; | |
dependencies.forEach(function(dependency) { |
# Newbie Programmer | |
def factorial(x) | |
if x == 0 | |
return 1 | |
else | |
return x * factorial(x - 1) | |
end | |
end | |
puts factorial(6) | |
puts factorial(0) |
class String | |
alias_method :is_a, :== | |
alias_method :is_an, :== | |
end | |
class Maze | |
NAVIGABLE = ' ' | |
WALL = '#' | |
POINT_A = 'A' |
# Composite Pattern | |
class TagNode | |
include ActionView::Helpers::TagHelper | |
def initialize(name, options = {}) | |
@name = name.to_s | |
@attributes = options | |
@children = [] | |
end |
require "test/unit" | |
class TestFindRedundantResistors < Test::Unit::TestCase | |
def test_find_redundant_resistors | |
actual = find_redundant_resistors [ | |
[ 'A', 'B', 50], | |
[ 'A', 'D', 150], | |
[ 'B', 'C', 250], | |
[ 'B', 'E', 250], | |
[ 'C', 'E', 350], | |
[ 'C', 'D', 50], |
#!/bin/bash | |
## | |
# *1 Tiene algo que ver con los saltos de línea pero no sé muy bien! :-( | |
OLDIFS=$IFS | |
IFS=$'\n' | |
FILE_NAME=$1 | |
LINES=`svn log $FILE_NAME` | |
## |