Monthly Archives: August 2010

SSH and Remote Proxy

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/

Unique Ruby methods

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.