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

Ruby On Rails and a Conning Israeli entrepreneur

New Design For Pdfetch.com


New design for Pdfetch.com is up, thanks to Barak Edry who did everything to make it look better.
thanks man!

PDFetch released

PDFetch.com was released today by me and Shmuel Ahdut.
PDFetch is a simple app to enable a phrase specific search of online (and free of course) PDF files (other file types will be supported later on).
i will appreciate comments and remarks.

Model Reflection Overview

We all use ActiveRecord Reflection on the fly while programming, since we declare all the relations in the model and we are considering it as obvious.
i tried to search and see if there is a way to find those reflections and to alter it in runtime.

Model.reflections


i found this collection which contains all the information about the current model reflections.
for example.

  • .macro: this will return the type of the current reflection (:has_many, etc..)

  • .primary_key_name: the reflection primary key

  • .options: the reflection SQL join options

  • etc. etc.



for example, the following code will show me all the reflections for a model named Article:

  1. >> y Article.reflections.values.collect {|e| e.macro.to_s  + " => " + e.primary_key_name.to_s }  
  2. ---   
  3. - has_many => taggee_id  
  4. - belongs_to => layout_id  
  5. - has_many => article_id  
  6. - has_one => subject_id  
  7. - belongs_to => user_id  
  8. - has_many => taggee_id  
  9. => nil  

iphone on rails

A simple way to build iPhone specific interface with Rails

  1. class ApplicationController < ActionController::Base  
  2.   exempt_from_layout('iphone_html.erb')  
  3.     
  4.   before_filter :check_iphone  
  5.     
  6.   protected  
  7.   def iphone?  
  8.     request.user_agent.include?('iPhone')  
  9.   end  
  10.     
  11.   def check_iphone  
  12.     if iphone?  
  13.       request.parameters[:format] = 'iphone_html'  
  14.     end  
  15.   end  
  16. end  
  17.   
  18. class DashboardController < ApplicationController  
  19.   def index  
  20.     @top_movies = Movie.top_movies  
  21.     @movie = @top_movies.first  
  22.       
  23.     respond_to do |format|  
  24.       format.html # index.html.erb  
  25.       format.iphone_html #index.iphone_html.erb  
  26.     end  
  27.   end  
  28. end  

The running program

sometimes it can come handy to be able to know in which program you are running know.
it can be useful when displaying error information or such.

  1. caller(0)[0].split(".rb")[0]  >>  "(irb):74:in `irb_binding'"  

WYMeditor - Standards driven WYSIWYG editor

no words are needed, just a small thanks.
thanks for my man Dor Kalev for finding this edgy top of the line XHTML WYSIWYG editor

among the amazing features of this new editor:
1. XHTML strict + CSS compliant

2. No font or text formatting, sizes or colors - WYMeditor is CSS-based Designed

3. to be easy to integrate into your application

4. No installation needed - this is 100% Javascript code - no plugin, no extension

5. Simple Javascript code, you don't need to be a 'Javascript Guru' to understand it

6. Will remain as simple as possible

7. focus on well-tested code, stability and usability before adding new features

8. Image, link, table support

9. Skins supportvia CSS

10. Free and Open Source, fully adaptable to your needs



UPDATED: 13/11/07

The dude released it as a plugin, i am a bit late with this update, but
there it is.

Setting up logger options


i was called the other day about one of my past projects server going down because it's production log exceeded 2GB.
regularly, there is a cron job to cycle the log file and prevent such joyous occasions, but for some reason it didn't happen. so i decided to read a little bit about the Logger class in Rails and see if it has some magic for me yet.



in order to replace the log file path (and/or name) use the following syntax in environment.rb:

  1. Rails::Initializer.run do |config|  
  2.   config.logger = Logger.new(File.dirname(__FILE__) + "/../log/#{RAILS_ENV}.log")  
  3. end  


The actual cure for my problem came when i found the option to prevent the logger file from exceeding a pre-defined limit.
  1. config.logger = Logger.new(File.dirname(__FILE__) + "/../log/#{RAILS_ENV}.log", 1, 2*1024*1024)  


and a little extra for creating a brand new log file for each day.
  1. config.logger = Logger.new(File.dirname(__FILE__) + "/../log/#{RAILS_ENV}.log""daily")  


i suggest reading even more on the rails development browser

Add custom operators in Ruby

Jay Phillips developed the 'superators' gem, which enables the use of custom operators in Ruby. for example.

  1. require 'rubygems'  
  2. require 'superators'  
  3.   
  4. class Array  
  5.   superator "<---" do |operand|  
  6.     self << operand.reverse  
  7.   end  
  8. end  
  9.   
  10. ["jay"] <--- "spillihp"  

relative_time_helper plugin

most of us are using rails's built in time_ago_in_words, Rick Olsan wrote a much better plugin to extend that use and gives much better results.

  1. <%= relative_time(Time.now) %>  
  2. # today  
  3. <%= relative_time(1.day.ago) %>  
  4. # yesterday  
  5. <%= relative_time(1.day.from_now) %>  
  6. # tomorrow  
  7. <%= relative_time_span([Time.now, 5.days.from_now]) %>  
  8. # May 17th - 22nd  


To install it just snap it out of:

  1. script/plugin install http://ar-code.svn.engineyard.com/plugins/relative_time_helpers  

Unique Insertion into Array


  1. [1,2,3] | [3,4,5]       >> [1, 2, 3, 4, 5]  

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


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