Skip to content

Instantly share code, notes, and snippets.

View cored's full-sized avatar
🐔
Debugging Everything

Rafael George cored

🐔
Debugging Everything
View GitHub Profile

Introduction

This is a port of the Askeet tutorial to Merb.

The challenge

The Merb advent calendar is a set of 24 tutorials. That's right, every day including week-ends, a new tutorial will be published. Each tutorial is meant to last less than one hour, and will be the occasion to see the ongoing development of a web 2.0 application, from A to Z. The resulting application will be put online, and the source code made open source. This application will be usable, interesting, useful, and fun.

Twenty-four times less than one hour equals less than a day, and we think that's exactly how long it takes for a developer to learn Merb. Every day, new features will be added to the application, and through these new features we'll show you how to take advantage of Merb's functionality as well as good practices in developing with Merb. Every day, you will realize how fast and efficient it is to develop a web app with Merb, and you will want to know more.

# This is a code to be a romantic geek with your girlfriend
todo = "Write a poem.Cook a romantic dinner. Give a full body massage. Pack a sunset picnic. Send flowers. Give love songs. Read poetry together. Prepare strawberries with foundue chocolate (Buy cookies and cream). Leave little love notes everywhere. Send a love email. Take a moonlit walk on the beach. Snuggle together while watching a movie (Search of love movies). Watch shooting stars. Take a bath together. Take a walk down memory lane (Plaza de la Cultura). Make a list of everything you love about her. Write a love letter. Create a little box with your partner's favorite things inside"
puts todo.split(/\./).sort_by { rand }[0]
# This is a default user class used to activate merb-auth. Feel free to change from a User to
# Some other class, or to remove it altogether. If removed, merb-auth may not work by default.
#
# Don't forget that by default the salted_user mixin is used from merb-more
# You'll need to setup your db as per the salted_user mixin, and you'll need
# To use :password, and :password_confirmation when creating a user
#
# see merb/merb-auth/setup.rb to see how to disable the salted_user mixin
#
# You will need to setup your database and create a user.
GlobalHelpers
# helpers defined here available to all views.
def link_to_interested_user(question)
if session.user
interested = Interest.get(session.user.id, question.id)
if !interested.nil?
return 'interested!'
else
return link_to('interested?', url(:user_interested, :id => question.id),
:class => 'remote',
import org.apache.commons.lang.Validate;
public class Person {
private String name;
public Person(String name) { this.name = name; }
public void setPersonInformation(String name, String[] address, int age) {
Validate.notEmpty(name, "Name should not be null");
Validate.noNullElements( address, "Address cannot contain null elements" );
require 'rubygems'
require 'sinatra'
require 'open-uri'
get '/' do
erb :index
end
get '/render' do
unless /^http:/ =~ params['url']
@tweets = current_user.links_in_timeline(:page => params[:page])
def links_in_timeline(pager = 1)
links = []
client.friends_timeline.each do |timeline|
links << timeline if timeline =~ %r{https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?}
end
links
end
class User
include DataMapper::Resource
property :id, Serial
property :login, String
property :first_name, String
property :last_name, String
property :email, String
timestamps :created_at
/* StringCalculator Code Kata - I found my solution as beautiful code, even though i will try to get it better */
public class StringCalculator {
private static final String DELIMITER = "//";
public int add(String numbers) {
if (isNumbersEmpty(numbers)) {
return 0;
}
class StringCalculator
def add(numbers)
return 0 if numbers.empty?
raise ArgumentError if is_negative?(numbers)
return handle_more_than_one_number(extract_numbers(numbers), extract_delimiter(numbers)) if has_optional_delimiter(numbers)
return handle_more_than_one_number(numbers, ",") if has_more_than_one_number?(numbers)
return numbers.to_i
end
def is_negative?(numbers)