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
Showing posts with label W. Show all posts
Showing posts with label W. Show all posts
Tuesday, December 23, 2008
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
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
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
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
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
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
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
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
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
Tuesday, September 30, 2008
initialize + super
Here's a word of caution to those using inheritance and calling super in the initialize method. Consider this:
def initialize(name, price)
super
@name = name
@price = price
end
Which parent method does it call? I was surprised to find out that without () after super, it automatically calls the initialize in the parent that has the parameters (name, price), rather than the one without parameters. If your intention was to call the parent's initialize without parameters, than you must do:
super()
W
def initialize(name, price)
super
@name = name
@price = price
end
Which parent method does it call? I was surprised to find out that without () after super, it automatically calls the initialize in the parent that has the parameters (name, price), rather than the one without parameters. If your intention was to call the parent's initialize without parameters, than you must do:
super()
W
Sunday, September 28, 2008
RoR: attr_accessible
In a previous post, I talked about mass assignment. Well, there's something I discovered recently. If you have a polymorphic relationship, your model will have two columns: taggable_type and taggable_id. If you want to make these available for mass assignment, you cannot do:
attr_accessible taggable_type, taggable_id
Instead, RoR treats them like one attribute like so:
attr_accessible taggable
W
attr_accessible taggable_type, taggable_id
Instead, RoR treats them like one attribute like so:
attr_accessible taggable
W
Saturday, September 27, 2008
RoR Generate + SVN
We all know about RoR's ability to generate controllers, models, migrations, etc. However, if you're using a repository, you have to manually add these newly created files. This could be a pain in the ass!
Here's a tip. If you're using SVN, you'll love this. Simply add the flag --svn and the generator will automatically add the newly created files to SVN. Simple!
W
Here's a tip. If you're using SVN, you'll love this. Simply add the flag --svn and the generator will automatically add the newly created files to SVN. Simple!
W
Thursday, September 25, 2008
RoR: Mass Assignment Security
In RoR, it is possible to do something called mass assignments. For instance, when submitting a form, all the parameters are put into a params hash so you can do the following:
Product.create(params[:product])
product.update_attributes(params[:product])
Very simple, but by default, there is a security flaw. That flaw is covered in this post. If you are concerned about this, the easiest way would be to make it so that all your models will require attr_accessible on any attributes that you want mass assignment for. This then protects any attributes not listed by default.
In your config files, preferably in your initializers folder, add the following to protect all attributes:
ActiveRecord::Base.send(:attr_accessible, nil)
Then go through each model and think about which attributes should be exposed to mass assignments. For those that are not accessible, you must do the following to assign values:
product.store_id = store.id
This makes the assignment explicit and cannot be manipulated by the users.
Now that you know, go secure your applications!
W
Product.create(params[:product])
product.update_attributes(params[:product])
Very simple, but by default, there is a security flaw. That flaw is covered in this post. If you are concerned about this, the easiest way would be to make it so that all your models will require attr_accessible on any attributes that you want mass assignment for. This then protects any attributes not listed by default.
In your config files, preferably in your initializers folder, add the following to protect all attributes:
ActiveRecord::Base.send(:attr_accessible, nil)
Then go through each model and think about which attributes should be exposed to mass assignments. For those that are not accessible, you must do the following to assign values:
product.store_id = store.id
This makes the assignment explicit and cannot be manipulated by the users.
Now that you know, go secure your applications!
W
Tuesday, September 23, 2008
Shuffling an Array
I just found a very interesting article about shuffling an array correctly!
http://adrianquark.blogspot.com/2008/09/how-to-shuffle-array-correctly.html
Enjoy!
W
http://adrianquark.blogspot.com/2008/09/how-to-shuffle-array-correctly.html
Enjoy!
W
Friday, September 19, 2008
Prototype: $A is not defined
Ever get this annoying error? Well... I do. Odd thing is, everything still works like a charm. So what's happening.
Unfortunately, no one seems to really know! I did some digging and found this bug. If you go through the comments, Prototype has some problems when loading/unloading a page on Firefox 2. Or maybe it's Firebug. People can't seem to entirely agree, and the bug has been reopened several times.
However, if you want a patch and forget about finding out what the problem really is, check out this fix.
I've used it and forgot about it now. Would be nice to know why though...
W
Unfortunately, no one seems to really know! I did some digging and found this bug. If you go through the comments, Prototype has some problems when loading/unloading a page on Firefox 2. Or maybe it's Firebug. People can't seem to entirely agree, and the bug has been reopened several times.
However, if you want a patch and forget about finding out what the problem really is, check out this fix.
I've used it and forgot about it now. Would be nice to know why though...
W
Thursday, September 18, 2008
Dropbox
Recently, there has been a lot of buzz around Dropbox. It is now open to beta testing, and many people say it's awesome.
In short, Dropbox can be thought of as storage that you can access from anywhere you have an internet connection. It'll automatically sync your local and remote files, and also work on PCs, Macs, and *nix machines.
For those of you that move around a lot and need your files reliably without the hassle, check out Dropbox.
W
In short, Dropbox can be thought of as storage that you can access from anywhere you have an internet connection. It'll automatically sync your local and remote files, and also work on PCs, Macs, and *nix machines.
For those of you that move around a lot and need your files reliably without the hassle, check out Dropbox.
W
Wednesday, September 17, 2008
Database Visualization
Keeping documentation up-to-date is always a pain in the ass. I was recently working on updating our database diagrams and thought that there may be a way to automate the process.
I found 2 solutions:
1. XMI
2. RailRoad
For solution (1), it worked, but I had to tweak it slightly. Because we are using PostgreSQL, I had a problem when UmlDumper tried to execute current_database for the adapter. This works fine for the MySQL adapter, but no such function exists for the PostgreSQL adapter. I quickly hacked it and just replaced it with a general name for our database, as we didn't have to be dead-on here.
I was quite disappointed when Dia did not know how to open up the XMI file. So, searching around, I found a program called Umbrello. It works great. Unfortunately, I had all my UML classes, but no diagram! I had to drag and drop each one individually (I couldn't figure out how to drag them all at the same time T.T). I then manually added in all the lines and made it pretty. Not too bad, but it was partly automated and partly manual.
For solution (2), it worked great. I used a rake task to generate the svg files. I had several issues with this, which was the fact that RailRoad is used to diagram models in RoR, not the database. Hence, I ended up with a lot of relations that didn't exist in the database. This meant TONS of lines. The lines are also quite hard to follow as they constantly overlap and cross each other.
2 major issues I had was that there is a 1-to-1 relationship (for efficiency purposes). However, the diagram did not reflect this. For example, we have class A and B that are in a 1-to-1 relationship. A will have has_many relationships and so will B. However, the diagram showed that all of B's has_many relationships were related to A, not B. I couldn't figure out why.
The other issue was a logged bug. If the model ends in an 's', the diagram gets messed up. The diagram will automatically drop the trailing 's'. This created incorrect relationships.
For these 2 major issues, I was unable to use solution (2) in the end. However, if more improvements are made, I may give it another chance as the whole process was completely automated. If your interested, it also does Controller diagrams.
If anyone else has a better way of producing automated diagrams of their database or models, give me a shout. I'd love to hear other solutions.
W
I found 2 solutions:
1. XMI
2. RailRoad
For solution (1), it worked, but I had to tweak it slightly. Because we are using PostgreSQL, I had a problem when UmlDumper tried to execute current_database for the adapter. This works fine for the MySQL adapter, but no such function exists for the PostgreSQL adapter. I quickly hacked it and just replaced it with a general name for our database, as we didn't have to be dead-on here.
I was quite disappointed when Dia did not know how to open up the XMI file. So, searching around, I found a program called Umbrello. It works great. Unfortunately, I had all my UML classes, but no diagram! I had to drag and drop each one individually (I couldn't figure out how to drag them all at the same time T.T). I then manually added in all the lines and made it pretty. Not too bad, but it was partly automated and partly manual.
For solution (2), it worked great. I used a rake task to generate the svg files. I had several issues with this, which was the fact that RailRoad is used to diagram models in RoR, not the database. Hence, I ended up with a lot of relations that didn't exist in the database. This meant TONS of lines. The lines are also quite hard to follow as they constantly overlap and cross each other.
2 major issues I had was that there is a 1-to-1 relationship (for efficiency purposes). However, the diagram did not reflect this. For example, we have class A and B that are in a 1-to-1 relationship. A will have has_many relationships and so will B. However, the diagram showed that all of B's has_many relationships were related to A, not B. I couldn't figure out why.
The other issue was a logged bug. If the model ends in an 's', the diagram gets messed up. The diagram will automatically drop the trailing 's'. This created incorrect relationships.
For these 2 major issues, I was unable to use solution (2) in the end. However, if more improvements are made, I may give it another chance as the whole process was completely automated. If your interested, it also does Controller diagrams.
If anyone else has a better way of producing automated diagrams of their database or models, give me a shout. I'd love to hear other solutions.
W
Labels:
ActiveRecord,
Controllers,
Database,
Solutions,
W
Monday, September 15, 2008
Google: AdWords Algorithm
Sorry, this isn't a post about Google's algorithm :P
But, there is news that they're planning to modify it! That's big news to people using AdWords. Go and check it out.
Quick summary:
- dynamic calculations of Quality Score at search time
- keywords are no longer labeled as "inactive for search"
- no more "minimum bids"... in comes "first page bid estimates"
In other words, Google wants more money ;)
W
But, there is news that they're planning to modify it! That's big news to people using AdWords. Go and check it out.
Quick summary:
- dynamic calculations of Quality Score at search time
- keywords are no longer labeled as "inactive for search"
- no more "minimum bids"... in comes "first page bid estimates"
In other words, Google wants more money ;)
W
Sunday, September 14, 2008
JavaScript Heaven
I stumbled across this amazing page of JavaScript tools. Enjoy!
http://www.smashingmagazine.com/2008/09/11/75-really-useful-javascript-techniques/
W
http://www.smashingmagazine.com/2008/09/11/75-really-useful-javascript-techniques/
W
Subscribe to:
Posts (Atom)