Tuesday, December 23, 2008

Ubuntu: Reset Gnome Panels

I've been customizing my gnome panels, and I happened to mess them up pretty bad. However, I found an awesome way to reset the gnome panels back to the default here.

gconftool --recursive-unset /apps/panel
rm -rf ~/.gconf/apps/panel
pkill gnome-panel


W

Thursday, November 20, 2008

Ubuntu 7.10 + Git

I got curious and wanted to start playing with Git after hearing about it in the community for a while now. This is how I did it:

sudo apt-get install git

This will get the version 1.5.* from the Gutsy repos. This is old, so I decided to upgrade it.

git clone git://git.kernel.org/pub/scm/git/git.git

This will create a git folder. But first, we need to install some dependencies:

sudo apt-get install zlib1 zlib1-dev openssl libcurl3 libcurl3-dev libexpat1 libexpat1-dev asciidoc xmlto

Next, it's time to install Git. You can install Git either for the local user or for the global system. I decided to install it globally:

cd git
make configure
./configure
make all doc
sudo make install install-doc install-html

This should run for a while. You can sit back and pretend you understand all the output, or you can now go grab a coffee. After it completes, you can do a

git --version

to check if Git was updated. Now, time to play!


W

Sunday, November 16, 2008

|| and && operators may not be doing what you expect

When you use || and &&, you may think that you are playing with true/false values. For instance, a condition that uses || or && will give you back true or false.

I found out recently that this is sometimes true (and sometimes not)! Now, what am I talking about? I always thought that if you evaluate (true || true), the expression evaluates to true because at least one of them is true. Well, apparently, it does evaluate to true, but not for the reason I had thought.

In Ruby, when you evaluate (true || true), what it is actually doing is evaluating the first condition. If it is truthy (ie. not false or nil) you get the first condition back. If it is falsy (ie. false or nil), you get the second condition back. So the following occurs:

('blah' || true) #=> 'blah' - not true!
(false || 'blah') #=> 'blah' again!

For &&, if the first condition is falsy, you get the first condition back. If it is truthy, you get the second condition back. Check it out:

(true && 'blah') #=> 'blah'
(nil && true) #=> nil - not false!

Using || and && still work in 'if' statements as expected, but it doesn't work the way as first thought. With this new insight, you can use || and && for shortcuts.

Instead of:

if options[:product].nil?
product = Product.new
else
product = options[:product]
end

You could do:

product = options[:product] || Product.new

And instead of:

unless product.nil?
name = product.name
end

You coud do:

name = product && product.name

Obviously, use these shorthands with caution, as it can convolute readability for other readers. On another note, JavaScript also follows this evaluation. Have fun!


W

Tuesday, October 28, 2008

Thursday, October 23, 2008

Named Routes: Anchor

If you're using named routes and want to add an anchor to your automatically generated URL, there's a very simple way to do it:

products_path(:anchor => 'my_anchor')

It's that simple!


W

Tuesday, October 21, 2008

Being Lean

Here's an interesting article I'd like to share. It's about keeping your company fast and light:

http://venturehacks.com/articles/lean-startups


W

Monday, October 20, 2008

Interesting Ideas

Check out this talk by Jason Fried from 37signals. Definitely some very good ideas and insight.

http://www.balsamiq.com/blog/?p=375


W