Working with Ruby Version Manager
You should first install the Ruby Version Manager (RVM), you can follow my other article on how to do it and get the latest version of Ruby and Rails working on your Mac.
Once you have RVM you can change Ruby versions at will. For a full documentation of RVM you can go the the website.
This article is in no way a full on manual but a set of quick tips on how to get going, and best practices. So we’ll see how to:
- Choose a Ruby version
- Gemsets and their basic functionality
- How to use gemsets with rails projects
Choose a Ruby Version
To select a working version of Ruby you can do
bigdiver$ rvm use 1.9.3
Using /Users/bigdiver/.rvm/gems/ruby-1.9.3-p0
Then you can verify that you’re really using that version by running
bigdiver$ ruby -v
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin10.8.0]
bigdiver$ which ruby
/Users/bigdiver/.rvm/rubies/ruby-1.9.3-p0/bin/ruby
Notice that we’re using the ruby installed in the user’s home directory (~/.rvm)and not the system’s which is in /usr/bin.
Gemsets
The next thing to get familiar with are gemsets. RVM gives you a compartmentalized ruby environment that is independent of the other versions on the system. This is great because it gives you full control over the gem, or package, versions your projects needs to function properly.
A huge part of that compartmentalization are the RVM gemsets. Gemsets are groups of Ruby Gems, that are associated with a version of ruby managed by RVM. You can think of them as gem repositories. You should have one gemset per project, and that’s where RVM really shines, because it makes the process really easy.
You can list the existing gemsets with the command
bigdiver$ rvm gemset list
gemsets for ruby-1.9.3-p0 (found in /Users/bigdiver/.rvm/gems/ruby-1.9.3-p0)
global
At this point, and if you just installed RVM you should only have one global gemset, you can choose by using the command gemset use
bigdiver$ rvm gemset use global
Using /Users/bigdiver/.rvm/gems/ruby-1.9.3-p0 with gemset global
bigdiver$ rvm gemset name
global
bigdiver$ rvm gemset list
gemsets for ruby-1.9.3-p0 (found in /Users/bigdiver/.rvm/gems/ruby-1.9.3-p0)
=> global
Both gemset name and gemset list show the current gemset.
To create a gemset you run the command
bigdiver$ rvm gemset create repo1
'repo1' gemset created (/Users/bigdiver/.rvm/gems/ruby-1.9.3-p0@repo1).
bigdiver$ rvm gemset use repo1
Using /Users/bigdiver/.rvm/gems/ruby-1.9.3-p0 with gemset app4
Easy. Repo1 gemset was created and selected for use. Notice the notation 1.9.3@repo1? This indicates that we created the repo1 gemset “under” or “at” the “1.9.3″ ruby version. By default RVM creates the gemset under the current ruby version (the one you chose with rvm use command).
You can abbreviate the two commands above with the –create option.
bigdiver$ rvm --create 1.9.3@repo2
bigdiver$ rvm gemset list
gemsets for ruby-1.9.3-p0 (found in /Users/bigdiver/.rvm/gems/ruby-1.9.3-p0)
repo1
=> repo2
global
As you can see the hash-rocket (=>) now points to the newly created repo2 indicating that it is the selected gemset.
All the gem operations you make, like gem install, etc will only affect the current gemset.
The exception to this is the global gemset, which as the name indicates, is global to the ruby version in use. So all the gems installed to global will be available in all other gemsets created under this version. This is a very good thing since it saves us a lot of time and work when creating new projects.
Using Gemsets with Rails
I usually create a rails directory where all the projects go. And create a gemset per project. You should create the gemset and select it before creating the new rails application.
Let’s do it:
bigdiver$ mkdir ~/work/rails/
bigdiver$ cd ~/work/rails
bigdiver$ rvm --create app1
bigdiver$ rails new app1
If rvm, ruby and rails were properly installed all the commands should run without error, and the Bundler will install a bunch of new gems into the app1 gemset repository.
Now you’re ready for some RVM magic! Lets create a .rvmrc file so that RVM changes to the app1 gemset as soon as we enter, or cd, to the app1 directory.
bigdiver$ cd app1
bigdiver$ rvm --rvmrc 1.9.3@app1
Again we’re using the @ syntax. This creates a .rvmrc file in the current directory, which was ~/work/rails/app1. Now all you need to do is exit from the directory and jump back in again.
bigdiver$ cd ..
bigdiver$ cd app1
==============================================================================
= NOTICE =
==============================================================================
= RVM has encountered a new or modified .rvmrc file in the current directory =
= This is a shell script and therefore may contain any shell commands. =
= =
= Examine the contents of this file carefully to be sure the contents are =
= safe before trusting it! ( Choose v[iew] below to view the contents ) =
==============================================================================
Do you wish to trust this .rvmrc file? (/Users/bigdiver/work/rails/app1/.rvmrc)
y[es], n[o], v[iew], c[ancel]> Yes
Answer Yes to trust the current .rvmrc file, and you’re done. Now every time you change to the app1 directory the 1.9.3@app1 gemset is selected automatically. Nice!
I also create a .rvmrc file in the rails directory that points to the global gemset, so when I want to install gems globally all i need to do is cd .. from any project.
bigdiver$ cd ..
bigdiver$ rvm --rvmrc 1.9.3@global
bigdiver$ cd ..
bigdiver$ cd rails
==============================================================================
= NOTICE =
==============================================================================
= RVM has encountered a new or modified .rvmrc file in the current directory =
= This is a shell script and therefore may contain any shell commands. =
= =
= Examine the contents of this file carefully to be sure the contents are =
= safe before trusting it! ( Choose v[iew] below to view the contents ) =
==============================================================================
Do you wish to trust this .rvmrc file? (/Users/bigdiver/work/rails/global/.rvmrc)
y[es], n[o], v[iew], c[ancel]> yes
Using: /Users/bigdiver/.rvm/gems/ruby-1.9.3-p0@global
Try it out
bigdiver$ cd app1
Using: /Users/bigdiver/.rvm/gems/ruby-1.9.3-p0@app1
bigdiver$ cd ..
Using: /Users/bigdiver/.rvm/gems/ruby-1.9.3-p0@global
Neat.
Update Ruby and Rails on Mac OS X
The system version of Ruby is a bit outdated. In order to update it you should install the Ruby Version Manager or RVM, and not touch the System’s Ruby version. Trying to install it through MacPorts also gave me a bunch of problems, especially in OS X Lion (10.7).
This install also requires Git Version Control system.
If you’re using MacPorts you can install it by running
sudo port install git
But like I said some Ruby and Rails applications do not play well with MacPorts so you will sooner or later should migrate to Homebrew. Here is one of such problems due to mismatched OpenSSL MacPort library versions, that caused me to have to reinstall the whole thing…
Well using the system’s version of ruby it is easy to install Homebrew:
ruby -e "$(curl -fsSL https://gist.github.com/raw/323731/install_homebrew.rb)"
and then install Git
brew install git
Now you can install RVM. Just Copy & Paste the whole line and run it as a single line in your terminal
bash < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer )
I usually install RVM in my home directory, and run the previous command with my regular user. This is ok since we mostly use our Macs for development, with only one developer on that machine.
If you need to install RVM system wide you can run:
sudo bash < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer )
Now you need to add RVM to your shell so it can do its magic.
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"' >> ~/.bash_profile
Close your Terminal and reopen it. This will force it to process the code we just entered into .bash_profile. You can also run the following:
. ~/.bash_profile
Now you need to make sure you have the latest Xcode from Apple. You can download it from the App Store for free, or install it from your Mac OS X installation DVD.
If you are a die hard fan of MacPorts, please remove it from the PATH so Ruby does not compile against its libraries causing all sorts of errors later on. It usually suffices to remove all references to /opt/local from the /etc/profile, but your configuration maybe a little bit different.
Now that you have installed Xcode and removed the MacPorts from the PATH you can continue
At the time of this writing the current stable version of Ruby was 1.9.3 so that is what I use, you should probably use the latest sable version, and not 1.9.3, by the time you follow this procedure…
rvm install 1.9.3
If you’re on Mac OS X Lion 10.7.2 with Xcode 4.2.1 you may get a compilation error. In that case run
rvm install 1.9.3 --with-gcc=clang
Once it finishes downloading, compiling and installing ruby you can do
rvm --default use 1.9.3
To use the ruby version we just installed, and to make it the default version.
RVM is kind of neat since it does not disturb the system version of Ruby and allows you to maintain and work with different versions of Ruby so you can make sure your older projects that require older versions of Ruby, Rails or some other Gem still run even when you upgrade to newer versions.
RVM is kind of like a virtual machine, or environment that allows you to keep separate Ruby installs that will coexist peacefully, and that is why you should use it and not replace the system Ruby version.
RVM allows for the creation and use of several Gem Repositories or gemsets, that you can keep for each of your projects, and this is an invaluable feature so you don’t get stuck into gem dependency issues later on.
By default a global gemset is created and all gems installed to global will be shared among all the other gemsets that you create for a specific ruby version maintained by RVM.
You should install gems, that like Rails, will be shared by all projects running under a Ruby version. So lets install some of the basic gems to get us going.
rvm gemset list
You should get something like:
gemsets for ruby-1.9.3-p0 (found in /Users/pedro/.rvm/gems/ruby-1.9.3-p0)
global
Lets double check that we’re using the Ruby version we just installed:
bigdiver$ ruby -v
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin10.8.0]
bigdiver$ gem -v
1.8.10
Nice!
Install sQlite3, JSON, and Rails
gem install sqlite3 json rdoc rails cheat
If you get UTF-8 errors just set the LANG and LC_CTYPE environment variables. I usually do it in the /etc/profile, but you can do it in the .bash_profile in your home directory.
Add the following lines to one of them and “source” them into your environment
export LC_CTYPE="utf-8"
export LANG=en_US.UTF-8
. /etc/profile
or
. ~/.bash_profile
And then install your gems.
Get Coverage Reports working with PHPUnit and MAMP
If you get a “The Xdebug extension is not loaded. No code coverage will be generated.” error message when running phpunit –coverage-html test, you need to add Xdebug to the php.ini as follows:
zend_extension="/Applications/MAMP/bin/php/php5.3.6/lib/php/extensions/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
;xdebug.idekey=
The actual path may actual be different as I am using ActiveState’s Komodo version of Xdebug that I manually copied to the PHP extensions directory.
If you are running MAMP Pro you should also add the above lines to the php.ini template. Do this by opening MAMP Pro Application and click “Edit Template” from the File menu, then click “PHP 5.3.6 php.ini”.
Save and restart your servers.
PHPUnit 3.6 Tests and Komodo IDE Unit Testing
The latest version of PHPUnit, which at the time of this writing is 3.6.3 breaks the Komodo IDE Test Plan feature due to the wrong PHPUnit include in the drive_testrunner.php file.
My php_error.log file had the following:
Fatal error: require_once(): Failed opening required 'PHPUnit/Framework.php' (include_path='.:/Applications/MAMP/bin/php/php5.3.6/lib/php') in /Applications/Komodo IDE.app/Contents/MacOS/python/komodo/harnesses/php/drive_testrunner.php on line 16
...
require_once() /Applications/Komodo IDE.app/Contents/MacOS/python/komodo/harnesses/php/drive_testrunner.php:57
All that I needed to do was to edit the file /Applications/Komodo IDE.app/Contents/MacOS/python/komodo/harnesses/php/drive_testrunner.php and replace the outdated
require_once 'PHPUnit/Framework.php'
With
require_once 'PHPUnit/Autoload.php'
right at the top and now all is working.
If your tests stil don’t run under Komodo set the PHP interpreter to the MAMP binary in the PHP Languages Properties in the Komodo Preferences.
In my case /Applications/MAMP/bin/php/php5.3.6/bin/php.
Happy testing.
If you’re having problems in getting PHPUnit to work in the first place check my other article to get PHPUnit to work with MAMP on Mac OSX Snow Leopard and Lion.
MAMP 2.0 Pear and PHPUnit Installation
I have been struggling to get PHPUnit working under MAMP 2.0 on OSX Lion, and Snow Leopard. After a lot of searching and googling, and combing through countless forums I figured it out and my tests are finally running.
Here are the steps I took for MAMP using PHP 5.3.6, if your PHP is different adjust accordingly, but basically you have to be in the bin directory of MAMP’s PHP install. If you are you should see the binary for php, for pear, in this directory.
cd /Applications/MAMP/bin/php/php5.3.6/bin
sudo ./pear upgrade pear
In my brand new, fresh, install of MAMP i got the following error:
Notice: unserialize(): Error at offset 276 of 1133 bytes in Config.php on line 1050
ERROR: The default config file is not a valid config file or is corrupted.
If you get this error as well just delete the pear.conf file, and rerun the pear upgrade
rm /Applications/MAMP/bin/php/php5.3.6/conf/pear.conf
sudo ./pear upgrade pear
You should now see something like (truncated the output for space):
downloading PEAR-1.9.4.tgz ...
Starting to download PEAR-1.9.4.tgz (296,332 bytes)
.............................................................done: 296,332 bytes
downloading Archive_Tar-1.3.8.tgz ...
Starting to download Archive_Tar-1.3.8.tgz (17,995 bytes)
...done: 17,995 bytes
downloading Console_Getopt-1.3.1.tgz ...
Starting to download Console_Getopt-1.3.1.tgz (4,471 bytes)
...done: 4,471 bytes
upgrade ok: channel://pear.php.net/Archive_Tar-1.3.8
upgrade ok: channel://pear.php.net/Console_Getopt-1.3.1
upgrade ok: channel://pear.php.net/PEAR-1.9.4
...
Now that you’ve upgraded Pear you can install PHPUnit and its dependencies. Following instructions from the PHPUnit Github repository, i.e. directly from the developer, you can install PHPUnit by running:
./pear config-set auto_discover 1
./pear install --alldeps pear.phpunit.de/PHPUnit
DO NOT RUN ./pear install phppunit as that will install some old and useless version that will not work! There are a lot of tutorials out on the web that are outdated and will not work for the latest version of MAMP and PHPUnit.
You should get something similar to the following (truncated for space):
Attempting to discover channel "pear.phpunit.de"...
downloading channel.xml ...
Starting to download channel.xml (804 bytes)
...
install ok: channel://pear.phpunit.de/PHP_CodeCoverage-1.1.1
install ok: channel://pear.phpunit.de/PHPUnit_MockObject-1.1.0
install ok: channel://pear.phpunit.de/PHPUnit-3.6.3
Notice that PHPUnit_MockObject and PHP_CodeCoverage are also installed.
You are now ready to run phpunit and see if it works…
./phpunit
Should print usage information without any errors, on the screen your your PHP Error log file. If there are any include errors in you PHP Error file, you may have multiple PHPUnit versions installed and you need to remove them all by using the pear uninstall command.
My php_error.log had a bunch of entries that looked like this:
PHP Fatal error: require_once(): Failed opening required 'PHPUnit/Framework/MockObject/Autoload.php' (include_path='.:/Applications/MAMP/bin/php/php5.3.6/lib/php') in /Applications/MAMP/bin/php/php5.3.6/lib/php/PHPUnit/Autoload.php on line 48
...
PHP Warning: require_once(PHPUnit/TestCase.php): failed to open stream: No such file or directory in /Applications/MAMP/bin/php/php5.3.6/lib/php/PHPUnit.php on line 49
To resolve this I uninstalled all PHPUnit, and PHPUnit_MockObject.
./pear uninstall phpunit
./pear uninstall pear.phpunit.de/PHPUnit
./pear uninstall pear.phpunit.de/PHPUnit_MockObject
Then reinstalled PHPUnit as explained earlier in this article.
One final comment on Using PHPUnit in your tests. A lot of the tutorials I found on the web, including the PHPUnit manual tell you to include PHPUnit in your code as:
require_once 'PHPUnit/Framework.php'
For the version at the time of this writing which was PHPUnit 3.6.3 you must do the following instead
require_once 'PHPUnit/Autoload.php';
Happy testing!
Jailbreak the Internet Browser on your Sharp Aquos
Just got a new Sharp Aquos LC-52LE830U and I am really happy with it!
The only problem is that Sharp decided to lock you out of a full Internet browser experience, and only give you access to a very limited set of Widgets. Not to sure why but definitely not a very consumer friendly policy. I just hate this new trend where manufacturers arbitrarily limit the functionality of the products we spend top dollar on.
Geting out of the Sharp Aquos Net jail is easy enough and will not damage your TV in anyway. In reality you do not have to change anything on the TV it self but as usual do this at your own risk and responsibility.
The basic idea is to use the bookmark feature to add a Bookmark to Google or any other page of your liking, so it is always accesible. From there you can then access any site you like.
Unfortunately the TV browser does not support Flash so no Youtube…
You will need:
- DNS Server (this can be done on your Internet router, Mac/Linux or Windows computer)
- Web Server
Install webserver on your laptop. I used MAMP on MAC OSX
- Create the sharpaquos folder on the web server root (/Applications/MAMP/htdocs/sharpaquos in my case)
- Create the widget_split.php file in the sharpaquos folder with the following content
<html> <script language="JavaScript"> if (window != top) top.location.href = location.href; </script> <a href="http://www.google.com">Google</a> </html>
Highjack one of the Aquos Net widgets by redirecting the DNS name resolution to your webserver
- We need to redirect special.accesshollywood.com to the webserver in my case 192.168.32.60
- I added a the accesshollywood.com DNS Zone to my Fortigate, and configured it as follows:

- Add the special.accesshollywood.com host and point it to the webserver
Press the Aquos Net button on your TV remote, and access the Access Holywood widget, mine was on page 4.- You should see the “Google” link inside the widget instead of the regular Access Hollywood widget content.
- Navigate to the Widget and Google should open on the full page, and not restricted to the inside of the widget.
- You can now bookmark the Google page by pressing the “D” button on the TV remote
“There’s no App for that” should be RIM’s catch phrase for the Playbook
Thanks to my beautiful wife and daughter I got a Blackberry Playbook for Father’s Day. We already have an iPad and they thought the sharing was becoming a burden on the family…
Knowing that I am a BlackBerry person she decided to buy a Playbook instead of another iPad.
The initial setup was easy, but the first signs of trouble came when it connected to RIM to check for new updates.
The Playbook determined that there was a new version on the server, and started downloading it. The file was over 300 MB and the Playbook lost Wifi signal several times, delaying the download considerably.
I noticed that when the Playbook was flat on my desk the signal went down by a couple of bars, not as bad as the iPhone 4 but noticeable, and enough to cause the connection losses. So there I stood with the Playbook in hand until it finally downloaded the update file. It stared installing it, and after did a reboot. At this point I unplugged the device and went out.
Like any other Black Berry the Playbook takes FOREVER to boot, and when it was finally done it wanted me to connect to Wifi network and would not do anything else, or give me any option to continue. I was basically locked out!
So there I was stuck with a fresh new device searching for any open wireless network I could connect to. When I did find one, all the Playbook did was to give me a message thanking me for the upgrade. Well done RIM. Strike 1 – First impression: not good!
The second nightmare was installing the Blackberry Bridge software on my phone. I’m told by the Playbook that I need to go to the App World on the phone and download it, it even gave me a convenient QR code which, once scanned, opened the App World app on the phone. Easy. I was beginning to feel happy again, I could see my self doing all my corporate email, using my BBM, you know all that we love about our Blackberry phones.
That was not to be. Unfortunately, and to my utter amazement, AT&T does not allow RIM to provide the Blackberry Bridge app to its subscribers, and all I got was message saying that I was SOL!
Strike 2.
Now lets think about this for a moment. AT&T does not let RIM use messaging, calendar, BBM, and all the applications and services we love the Blackberries for. Why do I need a Playbook for?
As a consolation prize the Playbook came with 2 pre-installed games Need for Speed and Tetris. The first time I ran the Blackberry world app it told me that these needed updating so I clicked the button. Big mistake! The NFS download was almost 300MB and the Playbook kept loosing Wifi connection, so it took over 2h and several failed attempts to get that update installed.
That brings me to my last point, THERE’S NO APP FOR THAT!
Once running the Playbook is easy on the eyes, I liked the interface a lot, flash websites worked fine, but other than that there’s very few things to do with it. There are so few apps on the App World for the Playbook that the only parallel would be to compare it to the vast emptiness of the outer space. The claim that the Playbook runs Android apps had me excited, so I looked for a way to install the Android Market app so that I, at least could try those out, but no… no sir, RIM added one final hurdle to overcome. Developers need to submit their Apps to RIM so that they can approve, and add them to the Blackberry World.
Strike 3. The Playbook went back to the shelf at Best Buy.
Clearly this is a half-baked device, much like their recent phones, with a lot of limitations, installation problems, bugs (some pre-installed app for online video kept crashing) and above all no Bridge, ie, nothing Blackberry for AT&T subscribers.
The combination of very few consumer apps, and the inability to use the enterprise apps for which Blackberry is known for will kill this device faster than you can say Steve Jobs!
Clean your Apple Mighty Mouse Scroll Ball
The scroll ball in the Apple Mighty Mouse is an essential piece of mouse hardware and it gets clogged often. When it does scrolling tends to become erratic and difficult, to the point where it stops completely. I use this method to clean the ball without opening the mouse. Trust me when I say you do not want to open the Mighty Mouse…
- soak one Q-tip in alcohol, not dripping wet, you do not want to drown your mouse
- start rubbing the Q-tip over the ball in all directions and notice that you’ll start to see dirt come to the top
- gently rub off the dirt, or use a dry Q-tip to get it out.
- repeat process until the ball is totally clean
Hope this helps. If you have no time, no Q-tips, or no alcohol, just press the ball down hard, and scroll it. Do this a few times and whatever is stuck will become free and you’ll usually regain scrolling right away.
Cassandra Development Environment in Mac OS Snow Leopard
I just started working with Cassandra so I am no expert on the subject, and this post is more about self documentation of what I did to get it working on my laptop, running Snow Leopard, than an expert’s How to guide. If it helps you out all the better, and leave your comments.
Getting Cassandra to run on Mac OSX is very easy just download the latest binary from http://cassandra.apache.org/. At the time of this writing the version was 0.6.3, but I updated the important parts to 0.7rc3 so it should work with that version as well.
Create the directories Cassandra needs to work:
sudo mkdir -p /opt/cassandra
sudo chown -R `whoami` /opt/cassandra
sudo mkdir -p /var/log/cassandra
sudo chown -R `whoami` /var/log/cassandra
sudo touch /var/log/cassandra/system.log
sudo mkdir -p /var/lib/cassandra
sudo chown -R `whoami` /var/lib/cassandra
Get Cassandra and copy it to /opt/cassandra. In this example I used wget. Notice that the version numbers may change so use the correct link for your version from http://cassandra.apache.org/download/
wget http://apache.opensourceresources.org/cassandra/0.6.3/apache-cassandra-0.6.3-bin.tar.gz
tar xzf apache-cassandra-0.6.3-bin.tar.gz
cd apache-cassandra-0.6.3/bin
./cassandra -f
If all is ok you should now see
INFO 22:01:15,273 Auto DiskAccessMode determined to be mmap
INFO 22:01:15,887 Saved Token not found. Using 114412163776176127313248360017471199843
INFO 22:01:15,888 Saved ClusterName not found. Using Test Cluster
INFO 22:01:15,898 Creating new commitlog segment /var/lib/cassandra/commitlog/CommitLog-1278036075898.log
INFO 22:01:15,937 LocationInfo has reached its threshold; switching in a fresh Memtable at CommitLogContext(file='/var/lib/cassandra/commitlog/CommitLog-1278036075898.log', position=419)
INFO 22:01:15,946 Enqueuing flush of Memtable-LocationInfo@1373164447(169 bytes, 4 operations)
INFO 22:01:15,954 Writing Memtable-LocationInfo@1373164447(169 bytes, 4 operations)
INFO 22:01:16,262 Completed flushing /var/lib/cassandra/data/system/LocationInfo-1-Data.db
INFO 22:01:16,295 Starting up server gossip
INFO 22:01:16,406 Binding thrift service to localhost/127.0.0.1:9160
INFO 22:01:16,414 Cassandra starting up...
Now lets test Cassandra. Open a new Terminal window, or tab, and:
cd /opt/cassandra/bin
./cassandra-cli --host localhost --port 9160
Cassandra 0.7rc3 output and testing is a bit different so check with the comments bellow.
At the prompt (for 0.6.x)
cassandra> set Keyspace1.Standard2['jsmith']['first'] = 'John'
Value inserted.
cassandra> set Keyspace1.Standard2['jsmith']['last'] = 'Smith'
Value inserted.
cassandra> set Keyspace1.Standard2['jsmith']['age'] = '42'
Value inserted.
cassandra> get Keyspace1.Standard2['jsmith']
(column=age, value=42; timestamp=1249930062801)
(column=first, value=John; timestamp=1249930053103)
(column=last, value=Smith; timestamp=1249930058345)
Returned 3 rows.
cassandra> quit
If you’re able to get the values out of Keyspace1 all is good and Cassandra is up and running.
If you are installing 0.7 or higher the test Keyspace1 is not loaded automatically and you need to run jconsole to load the “schema”. And go to MBeans -> org.apache.cassandra.service -> StorageService -> Operations -> loadSchemaFromYAML as documented on LiveSchemaUpdates
Please note that jconsole needs to connect to localhost on port 8080, to talk to Cassandra. Do not use the Thrift port 9160.
Now lets install Chiton, a GTK GUI written in Python that will allow us to view the data stored in Cassandra.
mkdir chiton-temp
cd chiton-temp
git clone git://github.com/driftx/chiton.git
export VERSIONER_PYTHON_PREFER_32_BIT=yes
In order to fulfill a Chiton dependecies we also need
- Twisted 8.1.0 or later
- Thrift (latest svn)
- PyGTK 2.14 or later
- simplejson
- Telephus
First download and install Apple’s Xcode if you don’t have it already then, get a PyGTK Mac OS build from http://www.daimi.au.dk/%7Emadsk/files/
Copy PyGTK to /Develper as instructed in the README.txt of the PyGTK package.
- Get simplejson from http://pypi.python.org/pypi/simplejson
- Get Twisted from http://twistedmatrix.com/trac/wiki/Downloads and install the Twisted.mpkg package from the dmg file you just downloaded
- Get Telephus using
git clone git://github.com/driftx/Telephus.git
- Get Thrift using
svn co http://svn.apache.org/repos/asf/thrift/trunk thrift
Now for each of the packages, except Thrift run
cd
sudo python setup.py install
If you want to use Python 2.6 run
sudo python2.6 setup.py install
Compiling thrift. Go to the directory to which you checked out Thrift from the SVN
Because of the time it may take to compile all the updates, you may skip the
port selfupdate and port upgrade outdated. But if you start getting compilation errors you MUST do them and wait ![]()
My iMac took 5 hours!!!
cd
sudo port selfupdate
sudo port upgrade outdated
sudo port install boost pkgconfig libevent
cp /opt/local/share/aclocal/pkg.m4 ./aclocal
aclocal --acdir=./aclocal
./bootstrap.sh
./configure --with-boost=/opt/local --with-libevent=/opt/local --prefix=/opt/local
sudo make install
cd /opt/cassandra/apache-cassandra-0.6.3/interface/
thrift --gen py:new_style cassandra.thrift
cp -a ./gen-py/cassandra ~/chiton-temp/
(thank you Rich for the configure details
Almost done!!!
All we need to do is add the PYTHONPATH to our ~/.profile. Using your favorite editor open ~/.profile and add:
export PYTHONPATH=/usr/lib/python2.6/site-packages/:/Developer/MacPyGTK/inst/lib/python2.6/site-packages:/usr/lib/python2.6/site-packages/thrift:/Library/Python/2.6/site-packages/telephus:~/chiton-temp/chiton
export JAVA_HOME=$(/usr/libexec/java_home)
export VERSIONER_PYTHON_PREFER_32_BIT=yes
The directories in your PYTHONPATH may be a bit different, but the idea is to add all the directories where all the packages we just installed are located. If you miss one you will get import errors when running chiton-client.
Reconfigure Cassandra to allow the Thrift connections from Chiton, you need to set ThriftFramedTransport to true in cassandra’s storage-conf.xml. In my system
ThriftFramedTransport>
vi /opt/cassandra/apache-cassandra-0.6.3/conf/storage-conf.xml
<true</ThriftFramedTransport>
Done!!!!
If all is well you should now be able to run chiton-client. Login to localhost on port 9160. Don’t forget to have Cassandra daemon running (cassandra -f).
Since we changed the Thrift access to framed, from now on if you want to use the cassandra-cli don’t forget the –framed command line option. Cassandra 0.6.3 daemon crashes with:
ERROR 23:50:24,264 Uncaught exception in thread Thread[pool-1-thread-5,5,main]
java.lang.OutOfMemoryError: Java heap space
if you don’t use –framed.
Hope this guide helps you get your development machine ready to work with Cassandra.
A Good Experience with Apple Support
Today I took my Macbook Air for repair at a local Apple store – broken hinge and antenna cover. Although the Air has been out of warranty for some time they said they would replace the whole top part – not jut the hinge – for free, because it was a known issue!
The Apple “Genius” guy told me that the Air would be ready in 3 to 5 days, but a couple of hours later I got a call from him saying that the computer had been fixed and was ready to be picked up.
The great service relieved a lot of the frustration of seeing the broken hinge. So if the same thing happens to you, don’t buy the hinges on eBay (some are selling for $300). Take your Macbook to an Apple store. They’ll do a professional repair and most likely it will be free.
Great job Apple!
