Posts Tagged ‘development’

Output Logger and SQL to the Rails Console in Development Mode

Posted 10 Nov 2009 — by admin
Category Ruby on Rails

If you want to take a look at the SQL being generated by active record while your using the console, you can either type this into the console when it loads

ActiveRecord::Base.logger = Logger.new(STDOUT)

Or you can add it to your environment so that it’ll be the default behavior
rails_root/config/environments/development.rb

#...
ActiveRecord::Base.logger = Logger.new(STDOUT)

It’s a nice way to keep you away of any expensive queries you may unknowingly be writing!

Installing Scala on Mac OS X Leopard

Posted 01 Oct 2009 — by admin
Category Programming

I followed the instructions from here http://arvinderkang.com/2009/09/01/installing-scala-on-snow-leopard/ but I used version 2.7.6 (rather than .5) I installed scala under /usr/local/scala so I had to include it to my path. Type

vim .bash_profile
export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/scala/scala-2.7.6.final/bin:$PATH"

Now to download and install…

curl -O http://www.scala-lang.org/downloads/distrib/files/scala-2.7.6.final-installer.jar
sudo java -jar scala-2.7.6.final-installer.jar

This will launch an installer. Just follow the instructions and when it asks for the destination folder, remember that it’s in /usr/local/scala
Simple as pie!

Manage Sinatra Server in Development Mode with Shotgun

Posted 12 Aug 2009 — by admin
Category Sinatra

Sinatra won’t reload your files. So if you’re developing your app and want to see any changes made in the browser, install the shotgun gem.

gem install shotgun

You can then use shotgun to run your server

shotgun your_sinatra_ditty.rb

Presto, your ditty will never be out of key :)

Installing Sphinx Search Engine on Mac OS X… or ld: library not found for -lmysqlclient

Posted 30 Jun 2009 — by admin
Category Programming

If you are trying to install Sphinx on Mac OS X, it will most likely fail. The current version of MySQL bundled with Mac OS X is not supported and therefore, it will spit out the error message because it can’t find the correct libraries.

 ld: library not found for -lmysqlclient

There is a quick solution to the problem -upgrade mysql! You’ll need Mac Ports installed, available at

http://macports.org/

Run the command

sudo port install mysql5

This will not destroy any existing data from your previous MySQL installation. The mac port installation will take a while, and it will appear as if it is just hanging. It’s not. It just takes a while. I clocked it at 15 minutes on a relatively fast network connection. Drink a cappuccino!

After you have the upgrade you’ll need to download Sphinx available at:
http://sphinxsearch.com/downloads.html (latest stable) and build the Sphinx engine from source like so:

wget http://sphinxsearch.com/downloads/sphinx-0.9.8.1.tar.gz
tar xzvf sphinx-0.9.8.1.tar.gz
cd  sphinx-0.9.8.1/
./configure --with-mysql-libs=/opt/local/lib/mysql5/mysql/
--with-mysql-includes=/opt/local/include/mysql5/mysql/
make
sudo make install

Much thanks to this post b/c I spent forever trying to get the bundled version of MySQL linked properly:

http://www.fozworks.com/2008/9/5/rake-installation-of-sphinx-in-mac-osx

Postfix, ActionMailer and OpenSSL Fix on Ubuntu

Posted 23 Jun 2009 — by admin
Category Ruby on Rails

If you run into problems using ActionMailer > 2.2, Postfix and OpenSSL while sending mail from your application, try changing the following:

  vim /etc/postfix/main.cf

Change

 smtpd_use_tls=yes

to

smtpd_use_tls=no

OpenSSL support with Postfix does not work out of the box. You can either generate valid certificates or tell Postfix not to use the certificates. More information is available in this discussion forum.

http://forum.slicehost.com/comments.php?DiscussionID=2656

Sending eMail with Rails on Mac OS X Development Environment

Posted 10 May 2009 — by admin
Category Programming

You’ll need a mail transport agent (MTA). I installed and used postfix using Mac Ports.

sudo port install postfix

You’ll need to start postfix, to send mail from your Rails application. You can set it as a startup item and it will start on boot. However, since I don’t send too much mail from my Rails app, just for testing normally, I start it manually.

sudo postfix start

That should do it!

How to Install Ferret, the Full Text Search Engine with Your Rails Application

Posted 07 May 2009 — by admin
Category Ruby on Rails

Ferret is a full text search engine based on the popular Lucene Engine, which is originally written for Java. There is a great tutorial available here: http://www.railsenvy.com/2007/2/19/acts-as-ferret-tutorial

Assuming you have the plugin installed, acts_as_ferret in your vendor/plugins directory you’ll need to install the ferret engine on your box. Use gems like so

gem install ferret

If you’re running in dev mode, it should just work automatically, however in production, remember to start your ferret server in production mode with the following command!
./script/ferret_server start -e production

Starting the Rails Console in Production Mode

Posted 06 May 2009 — by admin
Category Ruby on Rails

To specify which mode you’d like the rails console to boot up in, just provide the string without any flags.

./script/console production
./script/console test
./script/console development

If you’re on windows, remember the backslash “\” rather than forward “/” and I believe you’ll also have to feed the ruby interpreter as well, like so…

ruby script\console production

When the cloud is a good idea

Posted 07 Apr 2009 — by admin
Category Business

A buddy of mine is a talented, but paranoid System Administrator for a small web company. He refuses to see the truth and the beauty in the wonderful world made possible by cloud computing services like Amazon’s EC2. Amazon is not the only game in town. There are other, and in my opinion more flexible, providers out there such as http://slicehost.com, http://joyent.com and http://rackspace.com.

cloud1

His main critique involves a lack of control over the physical disks, vague terms of service, in some cases  poor technical documentation and implementations that don’t replicate everything that you get when managing your own server. An example of this is when your server instance fails in the cloud and your data is not persisted, at least not with Amazon. This is no doubt a limitation and a serious one at that.

All these services offer a near identical product with price points at a small difference in dollars. You find on average, $70 a month for 1 Gig of RAM with 30 Gigs of hard drive space. Rackspace has the best offer with Mosso at $43 a month for 40 gigs of hard drive space and 1 gig RAM. You can get server instances as small as 256 Megs of RAM for about $10 a month. These costs don’t include bandwidth, but unless you’re doing a lot of traffic this won’t cost much. A full T1 will run you ~$350 a month with Mosso. As more and more players hop into the game, I wouldn’t be surprised to see prices go down even further.

Management of your server is simple with a nice web interface for rebuilding, rebooting, DNS configuration and scheduling backups. You can choose from the most popular operating systems such as Ubuntu, CentOS and even Windows, get full root access and can upgrade/downgrade at any time at a prorated cost. It’s wonderful and beautiful!

Just because something is easy doesn’t necessarily make it a good idea. But that doesn’t prove the opposite is true either. Just because something is easy doesn’t make it a bad idea. So why is using the ‘cloud’ a good idea, and more importantly, when is using the ‘cloud’ a good idea?

I watched a great presentation made by Mr. Bezos, Amazon’s CEO, in which he related the IT infrastructure at Amazon to the American electricity grid of the early 20th century. Bezos envisions a world where developers can just ‘plug’ in to an infrastructure that delivers everything you could possibly want from a dedicated hosting solution at a fraction of the cost. An infrastructure that maximizes power and efficiency and makes it easier to administrate your ’server’, not more complicated.

Amazon and the rest of the lot can do this because they deliver a service that a lot of people use in a similar way and can scale costs accordingly. Amazon in particular, with the infrastructure requirements for their flagship product, Amazon.com, gives them expert industry knowledge and a massive operating budget. Smaller hosting companies have taken advantage of open source technologies like the Xen Virtualization, to deliver scalable dedicated virtual boxes.

Bezo’s has a beautiful analogy. It does have its limits. Computing is not the same thing as electricity. Appliances for the household consume electricity in the exact same way. Applications for the web, however, do not consume compute power the same way.

Where cloud computing offers a lot is for the lone developer, small team or startup in the proof-of-concept stage. For those who understand software but not hardware. Where the investment of time and resources adds a burden that subtracts from the development of their product(s). And when the product(s) they deliver have nothing to do with the means they choose to deliver them. The developer or small team just require something that is secure, consistent and reliable.

I won’t argue that the cloud will ever be more secure, consistent and reliable than choosing to do it yourself, if you decide to do it right. Maintaining 100% control over the physical disks and having direct access to the physical collocation is more secure, consistent and reliable without a doubt. However, the caveat is that because you’ve decided to do it yourself you have to do it right! If you don’t do it right you’ll most likely have a setup that is neither secure, consistent and is very, very unreliable. So this asks the question how does one do it right and how much does it cost to do it right?

The cost can vary but it does involve hiring a System Administrator for 50 – 100 K a year and spending over 10 K on equipment and collocation facility hosting.

If you’re that lone developer, small team or startup in the proof-of-concept stage, you may or may not be able to afford these costs. You can of course contract out and the cost would be lower. But I’m comparing the cost of a setup that has someone fully dedicated to it. I’m also assuming that the developers, who know software, will be able to lean and manage the server remotely and thus my argument involves eliminating the formal role of System Admin. Because you no longer need to worry about the physical limitations of your setup, involving hard drive failures, new OS installs on new machine, UPS, basic redundancy and the rule of 3, developers can wear two hats.

How can the cloud be as consistent, secure and reliable? The answer is that Amazon and other cloud providers are hiring engineers who make six figures. Not just one or two, but tens or hundreds or even tens of hundreds, more than you can afford to hire. It make sense that they will have the resources, knowledge and experience to deliver a product that is consistent, secure and reliable.

Bugs and such are inevitable, after all humans are still doing the work. However, the bug risk isn’t eliminated just because you bring it in house. In fact, odds are that the risk is higher!  Who would you put your money on, 1 or 2 guys at a small company or the combined knowledge from all the engineers at Amazon.com? Now, that is an extreme comparison and of course there exists a middle ground. If you happen to find a great admin who does quality work and understands business goals etc, his consultation might be worth the price. However, if you’re not so lucky, a product from the cloud might be less risky than the infrastructure you invest in – the IT fort some employee constructs for job security!

You get what you pay for without a doubt. It’s just that in the cloud it’s not just you paying and therefore you get more for your dollar.

git checkout — file-in-question.oh-my

Posted 22 Mar 2009 — by admin
Category Programming

Problem: using git and one file, like your db/schema.rb, is out of whack with the latest branch. If you run git pull and you get a failed merge and no update. You can of course, edit the conflicts manually. But what if you’re confident that the latest schema.rb is correct? Instead of manually editing the file and doing all that work, you can grab the latest copy with the git checkout command.

Solution:  git checkout — <file>
… or for the Rails application example above…
git checkout — db/schema.rb