Hi, this blog is no longer maintained, my new blog is here

Ruby On Rails and a Conning Israeli entrepreneur

Seeking Alpha 2.0: Launch successful

After a massive amount of work to do, we all can finally rest for a couple of days (but not too much).

The all new Seeking Alpha site is air-born. i am very proud to be in the technical name list for this one, it is a truly Rails'ish web platform brought to life in the hands of the top israeli ruby on rails aces, and may i add, the best people i had ever had the honour to work with.
so thank you all: Koby "sleepy" Menachemi, Dor "Diet Coke" Kalev, Shmuel l. Unity, Rita "Wacom" Kaplan, Yuval "Float:right;" Raz and the master, Adam "Big Blue" Fine.

way to go guys!

Webistrano - Capistrano deployment the easy way

Blogfish introduced Webistrano, Webistrano is a Web UI for managing Capistrano deployments. It lets you manage projects and their stages like test, production, and staging with different settings. Those stages can then be deployed with Capistrano through Webistrano.



Webistrano's purpose is to make the deployment of multi-stage and multi-environment scenarios easy. Further it allows you to track who deployed what when to which servers and be alerted by email on each deployment.

Webistrano itself is a Ruby on Rails application that includes an edge version of Rails and all needed dependencies like Capistrano or Net::SSH. The only required dependencies are Ruby, Rake, and a database.
Currently the deployment part of Webistrano does not run on Windows.
The code is hosted at Rubyforge and distributed under the BSD license.

Webistrano can be downloaded here

Ruby For bloggers

There are 2 main issues to deal with when posting a technial post on a blog:

1. Syntax Highlighting
There is a wonderful service at The Complex which exports a beautiful Ruby (and other) code, as you see in this blog also.

2. Exampling

You want to example a piece of code you did, how to do it?
try this line:

  1. def show(&block)
  2. printf("%-25s>> %s\n", expr = block.call, eval(expr, block.binding).inspect)
  3. end

for example:
  1. show {%{ a = [1,2,3] }} ; show {%{ a.slice(1,2) }} ; show {%{ a.map { |x| x**3 } }}  

will result in:
  1. a = [1,2,3]                 >>  [1, 2, 3]  
  2. a.slice(1,2)                 >>  [2, 3]  
  3. a.map { |x| x**3 }      >>  [1, 8, 27]  

37 seven reasons to love Ruby

over here

Using your GMail as ActionMailer Carrier

this was merely a try, it worked, but i don't think it's recommended so much, google might get angry.

create a conf file named ssmtp.conf in /etc/ssmtp

  1. # Config file for sSMTP sendmail  
  2. #  
  3. # The person who gets all mail for userids < 1000  
  4. # Make this empty to disable rewriting.  
  5. root=postmaster  
  6.    
  7. # The place where the mail goes. The actual machine name is required no   
  8. # MX records are consulted. Commonly mailhosts are named mail.domain.com  
  9.    
  10. # GMAIL configuration  
  11. mailhub=smtp.gmail.com:587  
  12. AuthUser=youremail@gmail.com  
  13. AuthPass=pass  
  14. UseSTARTTLS=YES  
  15.    
  16. # The full hostname  
  17. hostname=machinehostname  
  18.    
  19. # Are users allowed to set their own From: address?  
  20. # YES - Allow the user to specify their own From: address  
  21. # NO - Use the system generated From: address  
  22. FromLineOverride=YES  


then just point ActionMailer to user sendmail as carrier in your environment:

  1. ActionMailer::Base.delivery_method = :sendmail  


and you are all set

Connection Options

i found a way to get the connection parameters (other than reading database.yml) of the current database connection.

  1. def connection_hash  
  2.   ActiveRecord::Base.connection.instance_variable_get(:@config_options)  
  3. end  

Dynamically adding methods

This is divine, ruby is too great to be true. no explanation needed.


  1. class Object  
  2.   def def(method_name, &block)  
  3.     (class << selfself end).send(:define_method, method_name, block)  
  4.   end  
  5. end  
  6.   
  7. x = Object.new  
  8.   
  9. string = "This is a test"  
  10. x.def(:elad_says) {puts "Elad says: " + string}  
  11.   
  12. x.elad_says  

Routing List

i have seen someone doing this somewhere and i can't remember where. i personally didn't find any use to it, but, you know... someone will.

listing all your routes.

  1. ActionController::Routing::Routes.routes.each do |r|
  2. puts r
  3. end

Mean Mail Machine

i was trying the other day to create some sort of a newsletter. sadly it took me about 2 hours to generate and send 51000 emails (not spam :) ) so i tried to find a way to do it a little faster.
a friend of mine came across the idea of using threads so i tried to override the basics of ActionMailer in order to make the delivery method to user threads.
the change boosted me up to 18-20 mails per second, in other words, 1900% more efficient!
here is the code, just push it in your environment.rb (or lib, whatever), just don't use it for mean/nasty/microsoft needs :).

  1. ActionMailer::Base.delivery_method = :thread_smtp  
  2.   module ActionMailer  
  3.     class Base  
  4.       def perform_delivery_thread_smtp(mail)  
  5.         thread = Thread.new do  
  6.           perform_delivery_smtp(mail)  
  7.         end  
  8.         thread.run   
  9.       end  
  10.   end  
  11. end  

Customize Logger message format

I Hate these long, frustrating long messages coming out on me when i look at the log. They are long, and needed a refreshing change for my opinion.

here is what i found:
There is a method which is responsible for the actual STDOUT printing for the log file, it's called Logger#format_message. I decided to overrun it in a more pretty way.

I created a /lib library called logger_format.rb and required it in environment.rb,

  1. class Logger
  2. def format_message(level, time, progname, msg)
  3. "#{time.to_s(:long)} -- #{msg}\n"
  4. end
  5. end
for example.
try it out and feel free to modify the output structure at will.



The Web Ask eizesus.com

Subscribe

    follow me on Twitter

    Twiters Around

    About Me

    My photo
    I am a web developer for more than 9 years, managed, cried, coded, designed and made money in this industry. now trying to do it again.

    Labels