• Why ERB embedded in Javascript is wrong

    February 11, 2011

    Javascript with embedded erb is used by most, if not all, Rails developers. Here is an example:

      greeting = function() {
        return "Hi,<%= name %>"
      }
    

    Stop doing this!

    Why? Let's look at the Ruby counterpart of the above example:

      # greeting.rb
      def greeting
        "Hi, <%= name %>"
      end
    
      # Now let's executing the file
      require 'erb'
    
      name = "Bruce"
      str = File.read('greeting.rb')
      result = ERB.new(str).result(binding)
    
      eval(result)
    
      greeting # => "Hi, Bruce" 
    

    Here are better ways to write the greeting function in both languages. So stop the madness. No ERB in Javascript please!

    Comment

  • Vim Tips

    January 28, 2011

    Useful vim commands I tend to forget:

    Edit mode

    • CTRL-R % - insert the current filename with full path

    Normal mode

    • ='] - indent the last pasted text

    Comment

  • Content without Behavior

    January 14, 2011

    Here is the talk I presented at MySpace in November, 2010:

    Comment

  • SSH - The Right Setup

    May 23, 2010

    Now that you have the barebone Ubuntu server loaded on Linode, the next step is to set up a non-root user to manage it. Let's create a user called bruce:

    Login into your box as root via the List console:

    # adduser bruce --disabled-password
    # usermod -aG sudo bruce
    

    Let make sudo stop prompting for password:

    # Type `visudo`
    # Change
    %sudo ALL=(ALL) ALL
    # to
    %sudo ALL=NOPASSWD: ALL
    

    Next, we need to add our SSH public key to ~/.ssh/authorized_keys

    We need to tell the sshd_config not to ask for password:

    # in /etc/ssh/sshd_config
    PasswordAuthentication no
    

    Finally, restart your sshd with this command: /etc/init.d/ssh restart

    More resources:

    Comment

  • Firebug slows down Firefox no more!

    October 16, 2009

    Firebug slows down Firefox significantly. It's most noticeable when opening Gmail.

    To solve this, use Firefox profiles. You can run multiple instances of firefox with different profiles.

    $ firefox -P coding --no-remote
    

    That will start a new Firefox instance with "coding" profile. When plugins are installed, they are attached to a specific profile. To create/manage profiles, close Firefox and run:

    $ firefox -ProfileManager
    

    Don't you love Firefox?

    Comment

Older articles

© 2011 Rit Li