Raymond Gao on August 19th, 2010

This is a good explanation about ROR’s Filter process.

http://rails.nuvvo.com/lesson/6373-action-controller-filters

Share and Enjoy:
  • Facebook
  • Digg
  • Sphinn
  • del.icio.us
  • Mixx
  • Google Bookmarks

Tags: ,

Raymond Gao on August 12th, 2010

SSH is very unique. It allows you to establish tunnels, allowing you access to a third machine through a proxy server.

For me, I found 2 types of tunneling very useful.
1. Local Tunneling
2. Remote Tunneling

Type 1. Local Tunneling, usage, you need to access a box which is sitting behind firewall, e.g. a mailserver. You can SSH to a third proxy box and establish a local tunnel to your current machine. Basically, you forward traffic from a local port to another local port which is used for SSH. This routes 9999 (remote) to 5903 (local port) on remote machine 190.120.226.69 (with ssh). Useful for VNC server with Amazon Cloud, for example. Syntax:

$ ssh -L 9999:127.0.0.1:5903 username@proxy_server

Type 2. Remote Gateway, usage, using your laptop (which does not have a static IP address) as webserver for development purpose. To do so, you need to turn on Gateway on the proxying machine (which has a static IP address.) You need to set ‘GatewayPorts yes‘ on the ‘/etc/sshd_config‘ file

GatewayPorts yes

After restarting the sshd daemon on the proxying machine. Now, you can masquerading your laptop as a machine with static IP via gateway proxying.

$ ssh -R 10337:127.0.0.1:4000 username@proxy_server

With that, all http request to the http://proxy_server:10337 is redirected back to your local laptop on port 4000, allowing you to test your app on a laptop without static IP address. Here, 10337 is the proxying port. And, 4000 is your local port for the development environment. This is particularly useful for testing Facebook type application.

Here are so good articles,

http://articles.techrepublic.com.com/5100-10878_11-5779944.html?tag=nl.e011

http://toic.org/2009/01/18/reverse-ssh-port-forwarding/

Share and Enjoy:
  • Facebook
  • Digg
  • Sphinn
  • del.icio.us
  • Mixx
  • Google Bookmarks

Tags: ,

Raymond Gao on August 12th, 2010

I have been using Ruby for over 2 years now. Still, from time to time, I see there are quirks making this language very unique. Thus, I will list some of these unique methods below and explain what they do.

object.respond_to?("special_brew")   -> #This is very similar to reflection in Java. It let's you test whether a method by "special_brew" name is available on a particular object. If you are testing for array you do object.respond_to?('[]').

object.send_to("method1", arg1, arg2) -> # This calls 'method1' method with arguments.

object.instance_variables -> # Returns an array of instance variable names.

klass.public_methods -> # Returns public methods available on a class.

klass.private_methods -> # Returns private methods for a class.

Klass.column_names -> # This is useful for ActiveRecord class. It lists columns in the DB of a table that is mapped to a Ruby class.

object.instance_variable_set(key_name, key_value) -> # Sets the value of an instance variable.

object.instance_variable_get(key_name) -> # Gets the value of an instance variable.

Most of these are listed in the API doc of the Ruby Class:Object.

Share and Enjoy:
  • Facebook
  • Digg
  • Sphinn
  • del.icio.us
  • Mixx
  • Google Bookmarks
Raymond Gao on July 20th, 2010

Today, I made some improvement to ActiveSalesforce Gem. The following method needs to be modified.

      def extract_sql_modifier(soql, modifier)
          value = soql.match(/\s+#{modifier}\s+(\d+)/mi)
          if value
            value = value[1].to_i
            if !(modifier.upcase == "LIMIT")
              # If it is not the keyword - LIMIT, remove it from the SOQL
              soql.sub!(/\s+#{modifier}\s+\d+/mi, "")
            else
              # If it is the keyword - LIMIT, do not remove it from the SOQL
            end
            # SOQL now supports LIMIT clause. If the user is not an app admin &
            # queries Newsfeed or EntitySubscription & without q limit (e.g. > 1000),
            # it would cause MQL_FORMED_QUERY exception:
            # However, OFFSET is still not supported by SOQL.
            # ***NOTE: needs to change it in the gem to make it effective.
          end

          value
      end

Because SOQL now supports the LIMIT clause and enforces it for non admin-users who tries to query the Newsfeed or EntitySubscription objects. (limit > 1000 will cause error), there it is added to preserve LIMIT and remove OFFSET clauses.

Share and Enjoy:
  • Facebook
  • Digg
  • Sphinn
  • del.icio.us
  • Mixx
  • Google Bookmarks
Raymond Gao on July 12th, 2010

This is a good blog on RoR session. http://www.quarkruby.com/2007/10/21/sessions-and-cookies-in-ruby-on-rails#sinrails

Another on passing method(a, b, *p) -> hash of arguments to the methods http://www.skorks.com/2009/08/method-arguments-in-ruby/

Share and Enjoy:
  • Facebook
  • Digg
  • Sphinn
  • del.icio.us
  • Mixx
  • Google Bookmarks