Monday, May 23, 2011

Ruote


Ruote is a workflow engine written in Ruby. Ruote is not a state machine library.
It could be described as an ‘operating system for business processes’.
A ruote engine may execute multiple process instances at a time. Processes are instantiated from process definitions written in a Ruby DSL or in XML (or directly as JSON). Process definitions describe the flow of work among participants. Participants stand for users, groups of users, services, legacy systems, etc.

Monday, May 9, 2011

Nettuts+ Quiz #1: Beginner CSS

In the first of many Nettuts+ quizzes, you’ll be able to test your knowledge by solving some nefarious questions. But don’t worry, we’re starting today by asking you some extremely beginner level CSS questions. Get crackin’ after the jump!

Thursday, May 5, 2011

RubyGems 1.8.1

After installing RubyGems 1.8.1 you will see deprecations when loading your exsting gems. Run gem pristine --all --no-extensions to regenerate your gem specifications safely.
Currently RubyGems does not save the build arguments used to build gems with extensions. You will need to run gem pristine gem_with_extension -- --build-arg to regenerate a gem with an extension where it requires special build arguments.
  • 1 minor enhancement:
    • Added Gem::Requirement#specific? and Gem::Dependency#specific?
  • 4 bug fixes:
    • Typo on Indexer rendered it useless on Windows
    • gem dep can fetch remote dependencies for non-latest gems again.
    • gem uninstall with multiple versions no longer crashes with ArgumentError
    • Always use binary mode for File.open to keep Windows happy
    http://blog.segment7.net/2011/05/05/rubygems-1-8-1

    Wednesday, May 4, 2011

    Ruby on Rails: How to load session objects into console

    1. Look in tmp/sessions and find the most recent file (ls -alrt on UNIX). Let's say the file is called 'tmp/sessions/ruby_sess.8eb9614a7e4e1e3b'
    2. Open console and type:
      >> session = Marshal.load(File.open('tmp/sessions/ruby_sess.8eb9614a7e4e1e3b'))
      => {"hash"=>{:cart=...
      >> cart = session["hash"][:cart]
      ....
      
      In this case I was trying to access a cart object in the session, which was placed in the session with: session[:cart] = Cart.new
    That's it

    Session stored in the DB:
    # Session.find_by_id(:my_session_id)
    # CGI::Session::ActiveRecordStore::Session.find_by_session_id(session_id)

    Monday, May 2, 2011

    The Difference Between Ruby Symbols and Strings

    Symbols are quite an interesting, and often ill-understood, facet of Ruby. Used extensively throughout Rails and many other Ruby libraries, Symbols are a common sight. However, their rational and purpose is something of a mystery to many Rubyists. This misunderstanding can probably be attributed to many methods throughout Ruby using Symbols and Strings interchangeably. Hopefully, this tutorial will show the value of Symbols and why they are a very useful attribute of Ruby.

    http://www.robertsosinski.com/2009/01/11/the-difference-between-ruby-symbols-and-strings/

    Understanding Ruby Blocks, Procs and Lambdas

    Blocks, Procs and lambdas (referred to as closures in Computer Science) are one of the most powerful aspects of Ruby, and also one of the most misunderstood. This is probably because Ruby handles closures in a rather unique way. Making things more complicated is that Ruby has four different ways of using closures, each of which is a tad bit different, and sometimes nonsensical. There are quite a few sites with some very good information about how closures work within Ruby.

    http://www.robertsosinski.com/2008/12/21/understanding-ruby-blocks-procs-and-lambdas/

    .irbrc for Win32

    Create a file called anything you like (e.g. “_irbrc” or “irb.rc”) and place it anywhere you like (say C:\Documents and Settings\), and set that full path to the ENV variable IRBRC, e.g. C:\Documents and Settings\\_irbrc

    Utility Belt

    Utility Belt is a grab-bag of tricks, tools, techniques, trifles, and toys for IRB, including convenience methods, language patches, and useful extensions. It also includes a couple command-line widgets. Its primary inspirations were an awesome gem called Wirble and a blog post by Amy Hoy called "Secrets Of The Rails Console Ninjas".

    FEATURES

    • Interactively edit IRB code in your preferred text editor
    • Read from and write to OS X clipboard
    • Post your code to Pastie with one command (OS X only)
    • Kick-ass Unix-style history buffer
    • Write command history to file or vi
    • Grep classes and methods for strings
    • Verbosity controls for regular IRB and Rails console
    • Finder shortcuts for Rails console
    • Upload shortcut for Amazon S3
    • Command-line Amazon S3 upload script
    • Command-line Google shortcut (OS X only)
    • Auto-indentation
    • _ special variable (like Unix shell var !!)
    • Extremely basic themes for Wirble syntax coloring
    • Pascal/JavaScript-style "with" statement
    • String#to_proc
    • Grammatically-correct is_an? method - no more "is_a? Array" statements
    • One-character exit command
    http://utilitybelt.rubyforge.org/
    http://www.rubyinside.com/irb-lets-bone-up-on-the-interactive-ruby-shell-1771.html
    http://rors.org/2009/12/20/10-rails-console-tricks.html

    history, separate rails/console history, syntax highliting, ...

    # .irbrc - last change: 2008-01-22 (ab)
    
    ### rubygems
    require 'rubygems' rescue nil
    
    ### pretty print
    require 'pp'
    
    ### less verbose prompt
    
    #IRB.conf[:PROMPT_MODE] = :SIMPLE
    
    IRB.conf[:PROMPT][:SHORT] = {
      :PROMPT_C => "%03n:%i* ",
      :RETURN   => "%s\n",
      :PROMPT_I => "%03n:%i> ",
      :PROMPT_N => "%03n:%i ",
      :PROMPT_S => "%03n:%i%l "
    }
    #IRB.conf[:PROMPT_MODE] = :SHORT
    
    ### automatic indentation
    IRB.conf[:AUTO_INDENT] = true
    
    ### tab completion
    require 'irb/completion'
    IRB.conf[:USE_READLINE] = true
    
    ### preserve history
    require 'irb/ext/save-history'
    IRB.conf[:SAVE_HISTORY] = 1000
    IRB.conf[:EVAL_HISTORY] = 100
    
    ### syntax highlighting
    require 'wirble'
    Wirble.init(:skip_prompt => true, :skip_history => true)
    Wirble.colorize
    
    ### irb session duration
    require 'duration'
    IRB_START_TIME = Time.now
    at_exit { puts "\nirb session duration: #{Duration.new(Time.now - IRB_START_TIME)}" }
    
    ### aliases
    alias r require
    
    ### easy YAML
    def y(*data); require 'yaml'; puts YAML::dump(*data); end
    
    ### Object#tap
    class Object; def tap; yield self; self; end; end
    
    ### map by method
    # http://drnicwilliams.com/2006/10/04/i-love-map-by-pluralisation/
    require 'map_by_method'
    
    ### method finder, e.g. "foo".what?
    # http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/32844
    # http://www.nobugs.org/developer/ruby/method_finder.html
    # http://redhanded.hobix.com/inspect/stickItInYourIrbrcMethodfinder.html
    require 'what_methods'
    
    ### gaining temporary access to private methods
    # http://blog.jayfields.com/2007/11/ruby-testing-private-methods.html
    class Class
      def publicize_methods
        saved_private_instance_methods = self.private_instance_methods
        self.class_eval { public *saved_private_instance_methods }
        yield
        self.class_eval { private *saved_private_instance_methods }
      end
    end
    
    ### System-wide script/console logging
    # http://toolmantim.com/article/2007/2/6/system_wide_script_console_logging
    script_console_running = ENV.include?('RAILS_ENV') && IRB.conf[:LOAD_MODULES] && IRB.conf[:LOAD_MODULES].include?('console_with_helpers')
    rails_running = ENV.include?('RAILS_ENV') && !(IRB.conf[:LOAD_MODULES] && IRB.conf[:LOAD_MODULES].include?('console_with_helpers'))
    irb_standalone_running = !script_console_running && !rails_running
    
    if script_console_running
      require 'logger'
      Object.const_set(:RAILS_DEFAULT_LOGGER, Logger.new(STDOUT))
    end
    
    ### different history file for rails
    IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb_history_rails" unless irb_standalone_running
    http://dotfiles.org/~localhost/.irbrc

    Sunday, May 1, 2011

    mondrian-olap

    JRuby gem for performing multidimensional queries of relational database data using Mondrian OLAP Java library.

    DESCRIPTION
    SQL language is good for doing ad-hoc queries from relational databases but it becomes very complicated when doing more complex analytical queries to get summary results. Alternative approach is OLAP (On-Line Analytical Processing) databases and engines that provide easier multidimensional analysis of data at different summary levels.
    One of the most popular open-source OLAP engines is Mondrian (mondrian.pentaho.com). Mondrian OLAP engine can be put in front of relational SQL database and it provides MDX multidimensional query language which is much more suited for analytical purposes.
    mondrian-olap is JRuby gem which includes Mondrian OLAP engine and provides Ruby DSL for creating OLAP schemas on top of relational database schemas and provides MDX query language and query builder Ruby methods for making analytical queries.

    USAGE
    Schema definition
    At first you need to define OLAP schema mapping to relational database schema tables and columns. OLAP schema consists of:
    • Cubes Multidimensional cube is a collection of measures that can be accessed by dimensions. In relational database cubes are stored in fact tables with measure columns and dimension foreign key columns.
    • Dimensions Dimension can be used in one cube (private) or in many cubes (shared). In relational database dimensions are stored in dimension tables.
    • Hierarchies and levels Dimension has at least one primary hierarchy and optional additional hierarchies and each hierarchy has one or more levels. In relational database all levels can be stored in the same dimension table as different columns or can be stored also in several tables.
    • Members Dimension hierarchy level values are called members.
    • Measures Measures are values which can be accessed at detailed level or aggregated (e.g. as sum or average) at higher dimension hierarchy levels. In relational database measures are stored as columns in cube table.
    • Calculated measures Calculated measures are not stored in database but calculated using specified formula from other measures.
    Read more about about defining Mondrian OLAP schema at mondrian.pentaho.com/documentation/schema.php.

    https://github.com/rsim/mondrian-olap

    Multidimensional Data Analysis with Ruby (sample)

    Check out this SlideShare Presentation:

    How to develop rails plugin from scratch?

    Generate Plugin with command: ruby script/generate plugin hello_world
    It will create file system as bellow:
    - lib
        - hello_world.rb
    - tasks
        - hello_world_tasks.rake
    - test
        - hello_world_test.rb
    - init.rb
    - install.rb
    - uninstall.rb
    - README
    - Rakefile
    - MIT-LICENSE

    init.rb will be executed every time when your application runs. Generally hook code is to be included here like you want to make all methods of your plugin available in your app’s models, controllers, views and helpers

    http://abdul-barek-rails.blogspot.com/2010/02/how-to-develop-rails-plugin-from.html