May18

Adding shadow to wp-codebox

Posted by: Brian Chan | Filed in: technology | Tags: , | 05:55 pm, May 18th, 2012 No Comments »

Too bad wp-codebox contains two divs namely wp_codebox_msgheader and wp_codebox, we cannot simply give the box-shadow to one single div. After playing with this a bit, here is my parameters. The css file is located at /your-wp-root/wp-content/plugins/wp-codebox/css/codebox.css.

1
2
3
4
5
6
.wp_codebox_msgheader {
        box-shadow: 6px 14px 11px #808083;
}
.wp_codebox {
        box-shadow: 7px 10px 10px #888;
}

The overlapped area seems smooth with this setting.

I also added bottom margin to the codebox, see if you like it.

1
2
3
.wp_codebox {
        margin-bottom: 20px;
}


May18

Installing Ruby on Rails in osx

Posted by: Brian Chan | Filed in: technology | Tags: | 05:23 pm, May 18th, 2012 No Comments »

Install Xcode first. You will need the one from the Mac App Store. You will need version 4.3 or above.

Then install homebrew. Go to this link (https://github.com/mxcl/homebrew/wiki/installation) to find the installation command. As of May 2012, the command is:

1
/usr/bin/ruby -e "$(/usr/bin/curl -fsSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)"

Then after the process finishes (it took like 30 seconds), run

1
brew doctor

This is just to make sure your environment is good to move on. If your Xcode is old you will get a complain here like the following:

1
2
3
4
$ brew doctor
 
Error: You have Xcode 4.1, which is outdated.
Please install Xcode 4.3.

I have installed the mcrypt lib myself, and I got warnings about that (see below). If that happens to you just ignore it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Error: Unbrewed dylibs were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.
 
Unexpected dylibs:
    /usr/local/lib/libmcrypt.4.4.8.dylib
Error: Unbrewed .la files were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.
 
Unexpected .la files:
    /usr/local/lib/libmcrypt.la
Error: Unbrewed static libraries were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.
 
Unexpected static libraries:
    /usr/local/lib/libarmdis.a    /usr/local/lib/libAstrisAPI.a

Then Install git by:

1
brew install git

You can make sure git is successfully installed by issuing:

1
git --version

Then install MySQL. Now, I believe you already have it if you are using Lion. Type the following command to see if you have mysql installed.

1
mysql -u root

If you get a mysql prompt, then you are good. If not, install it by issuing:

1
brew install mysql

You can alternatively install MAMP if you like, as MySQL will be one of the packages inside MAMP.

Then install RVM. This is the Ruby Version Manager. It will make your life so much easier down the road.

1
bash < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)

After installing rvm, edit your ~/.bash_profile file to include the following line. Make sure it’s there.

?View Code BASH_PROFILE
1
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

Then source your bash_profile file as you always do.

1
source ~/.bash_profile

Now Install Ruby. Lion already has 1.8 but we are going to install the latest 1.9.3.

1
rvm install 1.9.3

It will start downloading and installing. Just wait until it’s done, all automated. Isn’t it nice?

After installing check your ruby version by issuing:

1
ruby -v

You should see something like ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.3.0].

Then lastly install Rails.

1
2
3
gem install bundler
gem install mysql2
gem install rails

Now that we have rails installed, it’s time to test it out! Let’s create a simple test app in our home directory.

1
2
cd
rails new mytest

All your new projects files are inside the newly created directory called mytest. Now to run this app issue:

1
2
cd mytest
rails server

You will see something like the following:

?View Code CONSOLE
1
2
3
4
5
6
7
8
$ rails server
=> Booting WEBrick
=> Rails 3.2.3 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2012-05-18 17:09:11] INFO  WEBrick 1.3.1
[2012-05-18 17:09:11] INFO  ruby 1.9.3 (2012-04-20) [x86_64-darwin11.3.0]
[2012-05-18 17:09:11] INFO  WEBrick::HTTPServer#start: pid=7008 port=3000

So open a web browser and type in http://0.0.0.0:3000 into the location bar. If you see the rails welcome page, then congratulations! You are on Rails now!


You can find more very useful info on the rails official site at http://guides.rubyonrails.org/getting_started.html

I heavily borrowed much content and edited some portions from http://thinkvitamin.com/code/ruby-on-rails/installing-ruby-rails-and-mysql-on-os-x-lion/.



May16

Check the existence of an element in jquery

Posted by: Brian Chan | Filed in: technology | Tags: , | 11:18 am, May 16th, 2012 No Comments »

When dealing with dynamic creation of DOM objects, sometimes you need to check if a certain element exists. Below is how you check:

1
2
3
if ($('#my_element').length > 0){
  // it exists!
}

If you need to check whether a dropdown has any options, here is how

1
2
3
if ($('#my_dropdown option').length > 0){
  // contains options
}


May9

Breathing Observation Bubble (B.O.B.) in Hawaii

Posted by: Brian Chan | Filed in: fun | Tags: | 10:45 am, May 9th, 2012 No Comments »


This apparently is a new “water tourist thing” in Hawaii. Looks interesting!



May8

A Short History of the Modern Calendar

Posted by: Brian Chan | Filed in: fun | Tags: | 01:56 pm, May 8th, 2012 No Comments »



May5

What does “al dente” mean when cooking pasta?

Posted by: Brian Chan | Filed in: life | Tags: | 10:04 am, May 5th, 2012 No Comments »

Al dente is a fancy term for pasta that’s fully cooked, but not overly soft. The phrase is Italian for “to the tooth,” which comes from testing the pasta’s consistency with your teeth. [wikipedia]

How does one cook pasta “just right”? According to the National Pasta Association:

  1. Boil 4 to 6 quarts of water for one pound of dry pasta. (You can divide this recipe depending on how much pasta you are cooking.)
  2. Add the pasta with a stir and return the water to a boil.
  3. Stir the pasta occasionally during cooking.
  4. Follow the package directions for cooking times. If the pasta is to be used as part of a dish that requires further cooking, undercook the pasta by 1/3 of the cooking time specified on the package.
  5. Taste the pasta to determine if it is done. Perfectly cooked pasta should be “al dente,” or firm to the bite, yet cooked through.
  6. Drain pasta immediately and follow the rest of the recipe.

So next time you can appear to be cultural at an Italian restaurant by saying to your waiter, “May I have my pasta al dente please?” … Um… actually nevermind. ;)



May2

Find out the physical memory size in osx

Posted by: Brian Chan | Filed in: technology | Tags: | 01:22 pm, May 2nd, 2012 No Comments »

Far too often I accomplish this by clicking on the apple icon on the menu bar, then click “About this Mac”, then just read from the popup window. This is perfectly fine and all, until one day I was given only a shell and I needed to get that info.

Well, here is how you can do it in command line:

1
sysctl -a | grep mem

Then look for hw.memsize in the list. The number is in byte size, so you will need to do some conversion in your head. For example, if you see hw.memsize = 12884901888, that’s actually 12 * 1024 * 1024 * 1024, which is 12Gb.



May1

English is a crazy language

Posted by: Brian Chan | Filed in: fun | Tags: | 09:24 pm, May 1st, 2012 No Comments »


May1

Nest Learning Thermostat

Posted by: Brian Chan | Filed in: DIY, technology | Tags: | 01:52 pm, May 1st, 2012 No Comments »

Interesting thermostat from Nest. The website also has an installation tutorial video.



Apr27

Bach, Toccata and Fugue in D minor, organ

Posted by: Brian Chan | Filed in: music | Tags: | 02:14 pm, April 27th, 2012 No Comments »