Programming Perls Rewritten in Ruby

Just for a little exercise i am doing the programming pearls examples/tasks in ruby, and so far it has been funny/challenging.
Source is on github

Trivial examples

#displaying all words from STDIN
#C++
int main(void)
{   set S;
    set::iterator j;
    string t;
    while (cin >> t)
        S.insert(t);
    for (j = S.begin(); j != S.end(); ++j)
        cout << *j << "\n";
    return 0;
}

#Ruby
puts STDIN.readlines(' ').uniq * "\n"

ruby is my winner 😀

How much Memory does my Ruby Script use ?

I could not find any in-ruby solution for this question, so here is a unix-solution.

def memory
  pid = Process.pid
  map = `pmap -d #{pid}`
  map.split("\n").last
end

Output

mapped: 17652K    writeable/private: 2180K    shared: 0K

Lesson learned
Use `open(file).each(seperator)` over `open(file).read.split(seperator)` if you want to optimize for memory (is slightly slower)

Spammers arrive on Github

Hello,
Nice to meet you, how is everything, hope all is well with you. My name is Madam Avelin Regato, 
I found your contact after reading your profile I picked interest to contact you. I've something 
very important which I would love to share with you privately, therefore, would advise you to 
kindly write me back on: (avelin_regato7@yahoo.com) so that I'll give you details. 
Waiting anxiously for your anticipated corporation,
Yours,
Madam Avelin
Email me on: avelin_regato7@yahoo.com

Finally spammers have arrived…

Hopefully the github team has some counter-measures up their sleeves…
A search for this spam only returns 1200 results, but none in combination with github seems to be new…

A More Useful login_as Test Helper

I just got upset that i could not do login_as User.first or User.first.id, so i fixed that…

Usage

#in your tests...
login_as :quentin
login_as false
login_as User.first
login_as User.first.id + 1

Install

#authenticated_test_helper
  def login_as(user)
    id = case user
      when false,nil then nil
      when Symbol,String then users(user).id
      when Fixnum then user
      else user.id
    end
    @request.session[:user_id] = id
  end