26 October 2012

MacBook Air Wifi slowness resolution before Apple fix it

Wifi is barely working on my MacBook Air with Mountain Lion, both at work and home. Symptom might be seen as the following:

  • On connection to your Wifi, it works for the first a few page load, then slows down and even lose connection.
I've searched online and there're quite a few "fixes" and only the following works for me and I also consider it as "an easiest fix" for now.
  1. Go to "System Preferences" -> "Network".
  2. Select your "Wifi", click on "Advanced".
  3. Select "Hardware" tab.
  4. Choose "Manual" from the "Configure" dropdown.
  5. Choose "Custom" from the "MTU" dropdown.
  6. Fill in "1453" in the blank box.
  7. Save, turn off then turn on your Wifi.

17 September 2012

Hosts file gets reset after reboot on Mac Lion

I updated my hosts file on my Mac by doing the following:

sudo vi /etc/hosts

but it was reset every time when system was rebooted.

The reason being I have installed Cisco AnyConnect VPN client, which keeps a separate copy of the original hosts file, and will restore my hosts file from it each time after reboot.

ls /etc/hosts*   =>  /etc/hosts   /etc/hosts.ac    /etc/hosts.equiv

So the solution is to update both "/etc/hosts" and "/etc/hosts.ac" to keep them in sync.

Hope this helps you too.


12 September 2012

Missing "usb.h" for Blinky on you Mac?

Playing with Blinky today, but getting the following lovely error messages:

Installing ruby-usb (0.2.1) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

/Users/felix/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb 
checking for usb_init() in -lusb... no
checking for ruby/st.h... yes
creating Makefile

Makefile:165: warning: overriding commands for target `/Users/felix/.rvm/gems/ruby-1.9.2-p290@blinky/gems/ruby-usb-0.2.1/lib'
Makefile:163: warning: ignoring old commands for target `/Users/felix/.rvm/gems/ruby-1.9.2-p290@blinky/gems/ruby-usb-0.2.1/lib'
clang -I. -I/Users/felix/.rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1/x86_64-darwin11.4.0 -I/Users/felix/.rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1/ruby/backward -I/Users/felix/.rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1 -I. -DHAVE_RUBY_ST_H -I/Users/felix/.rvm/usr/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE   -fno-common -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wshorten-64-to-32 -Wno-long-long  -fno-common -pipe  -o usb.o -c usb.c
clang: warning: argument unused during compilation: '-ggdb'
usb.c:27:10: fatal error: 'usb.h' file not found
#include <usb.h>
1 error generated.
make: *** [usb.o] Error 1

Gem files will remain installed in /Users/felix/.rvm/gems/ruby-1.9.2-p290@blinky/gems/ruby-usb-0.2.1 for inspection.
Results logged to /Users/felix/.rvm/gems/ruby-1.9.2-p290@blinky/gems/ruby-usb-0.2.1/./gem_make.out
An error occured while installing ruby-usb (0.2.1), and Bundler cannot continue.
Make sure that `gem install ruby-usb -v '0.2.1'` succeeds before bundling.

Why? -- Because I didn't follow the instructions!

Well, after coming back and reading through all the instructions on Blinky Wiki page, I thought it would be very easy, but it turned out not.

23 August 2012

Install Ruby 1.9.2 with XCode 4.3+ on Mac OS X 10.7

Is this what you're looking for?

rvm install ruby-1.9.2-p290 --with-gcc=clang

Problem solved?

Good luck and thanks for trying.

3 June 2012

A Gem hack in Rails 3 project

I have a little project, one piece of the main function requires some help from a gem named 'HelloWorld'. However, this gem doesn't have the exact support I need. Before the owner of the gem accept my github pull request, I need do some hack to extend two of the the gem's classes 'Hello' and 'HelloWorld'.

I put the class "Hello" in a file named 'hello.rb', placed the file in the 'lib',
and 'autoload' the 'lib' directory by putting in the following line in the 'Application.rb' file:
config.autoload_paths += %W(#{config.root}/lib)
It worked like a charm! I can invoke the class method of my "Hello" class in Rails Console! Hooary!

25 March 2012

The bitter love of Ruby with LLVM

I love new toys, and I upgraded my XCode to 4.3.2 for that reason. Like what happens to me with all my other new toys, it broke my RVM and Ruby.

 Thanks to Shigeya, who contributed the solution and it worked for me like a charm:
  1. Uninstall XCode.
  2. Install XCode 4.3.2 (by the time I put up this post) from Apple's App Store.
  3. Open a terminal, run 'sudo xcode-select -switch /Applications/Xcode.app'.
  4. Open XCode, go to 'Xcode -> Preferences -> Components', install 'Command Line Tools'.
  5. Install RVM from master branch, or run 'rvm get head' if you've installed RVM.
  6. Install Ruby 1.9.3-p125 using RVM.
You should be able to install Ruby with no problems now. If not, you might want to do what RVM suggests:

24 March 2012

How to uninstall XCode

I have a Mac, You have a Mac; I had a problem with XCode, and now you have it too. That's why you're here, and here's how I killed it off my Mac:

sudo /Developer/Library/uninstall-devtools -mode=all
 And here's the last message displayed on my screen:

IMPORTANT: If you are going to install a previous version ofthe Developer Tools, be sure to restart the machine after in-stalling.
BUT, don't expect the same for XCode 4.3 and above. Things're getting simpler now:

sudo rm /Applications/Xcode.app 

Good luck, my friend!

23 March 2012

Uninstall MySQL from Mac Leopard/Lion

I installed MySQL 5.5.21 64 bits on my Mac OS X Lion (10.7.3), and I couldn't get it working with my Ruby 1.9.3, then I decided to uninstall it and install MySQL 32 bits. The following are the steps that I follow to remove it completely (Thanks to Tom Keur):
  1. Open the 'System Preferences' panel.
  2. Click on the 'MySQL' icon at the bottom of the panel in 'Other' section.
  3. On the 'MySQL' panel, click 'Stop MySQL Server', and uncheck the 'Automatically Start MySQL Server on Startup'.
  4. Close the panel, and open a terminal.
  5. In the terminal, run the following commands:
sudo rm /usr/local/mysql
sudo rm -rf /usr/local/mysql*
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
sudo rm /etc/my.cnf

16 February 2012

Mind your rescue magic

Rescue someone unwilling to look after himself, and he will cling to you like a dangerous illness.

--Mason Cooley
It is always a good practice to rescue exceptions in Ruby, but be aware that, keep best the practices all times even when you are doing your rescue magic.

Let us take a look at the following code:

  HTTParty.get(@url, :timeout => 5)
  "Time out!"

14 February 2012

Nokogiri Segmentation Fault on Mac Lion

I have a web project running on ruby-1.8.7-p352 with Nokogiri 1.5.0. It works well until I incidentally did a system update. When I started rails server, tried to access my website, the server would throw an exception and abort. The error message I got was like the following:
nokogiri-1.5.0/lib/nokogiri/xml/node.rb:930: [BUG] Segmentation fault
ruby 1.8.7 (2011-06-30 patchlevel 352) [i686-darwin11.2.0]
The Nokogiri information was like the following:
# Nokogiri (1.5.0)
    warnings: []
      engine: mri
      version: 1.8.7
      description: ruby 1.8.7 (2011-06-30 patchlevel 352) [i686-darwin11.2.0]
      platform: i686-darwin11.2.0
      loaded: 2.7.3
      binding: extension
      compiled: 2.7.3
    nokogiri: 1.5.0