recursive symbolize_keys

Update deep_symbolize_keys is in rails 4

Could not find it elsewhere, so here it is: recursive_symbolize_keys, that will symbolize all keys inside a hash and its nested hashes.

Hash extension

class Hash
  def recursive_symbolize_keys!
    symbolize_keys!
    # symbolize each hash in .values
    values.each{|h| h.recursive_symbolize_keys! if h.is_a?(Hash) }
    # symbolize each hash inside an array in .values
    values.select{|v| v.is_a?(Array) }.flatten.each{|h| h.recursive_symbolize_keys! if h.is_a?(Hash) }
    self
  end
end

Or standalone

  def recursive_symbolize_keys! hash
    hash.symbolize_keys!
    hash.values.select{|v| v.is_a? Hash}.each{|h| recursive_symbolize_keys!(h)}
  end

My Netbeans Shortcuts

Since there are so few tips and tricks collection, I wanted to share what I use most often.

These are my shortcuts, i changed some of them, so try searching for the text in keybord shortcuts view.

  • Go to line Strl+L
  • Open Resource (any file) Ctrl+R
  • Open type Ctrl+O
  • Delete line Ctrl+D
  • Move line up/down Ctrl+Alt+Up/Down
  • Copy line up/down Ctrl+Shift+Up/Down
  • Insert next matching word, this is no intelligent autocomplete, but just takes the next work that matches the currently started work Ctrl+K
  • Close editor Ctrl+W
  • Show file in files view Ctrl+Shift+2

How Stop Autotest From Running After Each Failed Test Was Fixed

Autotest until recently only had one flaw: it could not be used for large test suites, since after each red-green cycle I had to wait x minutes for all tests to pass, which made autotest really frustrating.

So grep autotest (the ‘without ZenTest version’) from github and enjoy “autotest -c” (also works with auospec).

And remember kids: always run autospec with script/spec_server and its twice the fun 😉

Passenger for Local Development of Multiple Applications on Ubuntu

Starting with the Railscasts episode on passenger I tried to get passenger working for development, since it removes the burden of always starting an extra console for the server and reveals errors that happen in passenger and not in mongel alone.

Apache should use the same group/user you use, otherwise you may get an 302 not allowed error, this can be changed in /etc/apach2/apache2.conf (User / Group).

httpd.conf

#/ets/apacha2/httpd.conf
# /apps is the folder where your projects lie
# I name them all *.lc so i can easily distinguish them from a live application
# if you use subdomains add the *. before the servername (example 1)
<Directory "/apps">
  Order allow,deny
  Allow from all
</Directory>

<Directory "/apps">
  Options FollowSymLinks
  AllowOverride None
</Directory>

<VirtualHost *:80>
  ServerAlias *.dw.lc
  PassengerPoolIdleTime 1800
  RailsEnv development
  DocumentRoot /apps/someproject/public
</VirtualHost>

<VirtualHost *:80>
  ServerAlias rs.lc
  PassengerPoolIdleTime 1800
  RailsEnv development
  DocumentRoot /apps/anotherproject/public
</VirtualHost>

hosts file

#/ets/hosts
127.0.0.1       de.dw.lc en.dw.lc fr.dw.lc
127.0.0.1       rs.lc
127.0.0.1       localhost
...

restart apache

sudo /etc/init.d/apache2 restart

Hope it works for you 😉