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

Sunday, October 19, 2008

Textarea: Preserving Whitespace

A lot of the times when you let users post things using textareas, it becomes frustrating to lose whitespace when you display their posts (especially carriage returns).

Well, enter <pre>. This nifty little tag preserves any whitespace within the tags. However, there is one caveat. It preserves whitespace so well that it doesn't know how to word wrap. This is troublesome when your user continues to type in the textarea without hitting the carriage return. When displayed with the pre tags, the words are all on one long line.

Well, here's a nice little hack:

http://www.longren.org/2006/09/27/wrapping-text-inside-pre-tags/


W

Saturday, October 18, 2008

Ruby: Time made easy

Here's another example of how Ruby just makes things simple. Imagine you're working with time and you have to figure out the difference between 2 times and whether they fall within a certain range. In most languages, you have to figure out how many seconds exist in your time range. For example, 1 minute would have 60 seconds and 1 day would have 86,400 seconds. That's not too hard to figure out, but imagine the readability!

t2 - t1 < 86400

That just begs the question, "Where does 86400 come from?". Imagine you had to explicitly put down the number for 1 week?

Well, Ruby is awesome in that it concentrates on readability. Since everything in Ruby is an object, numbers are just Fixnum (or Bignum). Either way, that means we can use certain methods associated with the object. Check this out:

t2 - t1 < 1.second
t2 - t1 < 1.minute
t2 - t1 < 1.hour
t2 - t1 < 1.day
t2 - t1 < 1.week
t2 - t1 < 1.month
t2 - t1 < 1.year

Now how readable is that?


W

Friday, October 17, 2008

VMware Server: Adding a USB

Ever wondered how to add USB capability to your VMware server? Well, I had a little bit of a problem trying to get my USB connected.

I had gone to the settings for my VM and added the USB controller. Then, when I booted up my VM, I went to

VM > Removable Devices > USB Devices > ...

To my surpise, it was empty! I knew my device was plugged in because my Ubuntu detected it, but I couldn't see it. After searching around, I found a solution:

1. power off your VM
2. unplug your USB
3. >sudo gvim /etc/init.d/mountdevsubfs.sh
4. uncomment lines 42-45 (starts off with #mkdir -p /dev/bus/usb/.usbfs...)
5. >sudo /etc/init.d/mountdevsubfs.sh start
6. start your VM
7. plug in your USB
8. add your USB to the VM

Good luck!


W