spec
|--- apis #do not put into controllers folder.
|--- your_api_test_spec.rb
|--- controllers
|--- models
|--- factories
|--- views
class postgresql::server::config { | |
exec { | |
'postgresql-drop-cluster': | |
command => '/usr/bin/pg_dropcluster --stop 9.1 main', | |
onlyif => "/usr/bin/psql -c '\\l+' |awk '/template0/ { print \$5 }' |grep 'SQL_ASCII'", | |
user => postgres, | |
notify => Exec['postgresql-create-cluster']; | |
'postgresql-create-cluster': | |
command => '/usr/bin/pg_createcluster --locale=en_GB.UTF-8 9.1 main', |
Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.
$ python -m SimpleHTTPServer 8000
#!/usr/bin/env bash | |
for config in `find . -type f -name .vagrant` | |
do | |
uuid=`cat "$config" | php -r 'echo json_decode(fgets(STDIN))->active->default;'` | |
if VBoxManage showvminfo $uuid > /dev/null 2>&1; then | |
if VBoxManage showvminfo $uuid --machinereadable | egrep -q 'VMState="running|paused|stuck"'; then | |
VBoxManage controlvm $uuid poweroff | |
fi | |
VBoxManage unregistervm $uuid --delete | |
rm -f "$config" |
Here's a preliminary experiment to see how much memory is saved with the new copy-on-write friendly (bitmap marking) GC.
Calculated by memstats.rb https://gist.github.com/kenn/5105061 on Debian x86_64.
# ./memstats.rb 20547
# Start the old vagrant | |
$ vagrant init centos-6.3 | |
$ vagrant up | |
# You should see a message like: | |
# [default] The guest additions on this VM do not match the install version of | |
# VirtualBox! This may cause things such as forwarded ports, shared | |
# folders, and more to not work properly. If any of those things fail on | |
# this machine, please update the guest additions and repackage the | |
# box. |
Below are the actual files we use in one of our latest production applications at Agora Games to achieve zero downtime deploys with unicorn. You've probably already read the GitHub blog post on Unicorn and would like to try zero downtime deploys for your application. I hope these files and notes help. I am happy to update these files or these notes if there are comments/questions. YMMV (of course).
Other application notes:
- Our application uses MongoDB, so we don't have database migrations to worry about as with MySQL or postgresql. That does not mean that we won't have to worry about issues with the database with indexes being built in MongoDB or what have you.
- We use capistrano for deployment.
Salient points for each file:
$options['joins'] = array( | |
array('table' => 'images_news_articles', | |
'alias' => 'ImagesNewsArticle', | |
'type' => 'left outer', | |
'conditions' => array( | |
'NewsArticle.id = ImagesNewsArticle.news_article_id' | |
) | |
), | |
array('table' => 'images', | |
'alias' => 'Image', |
In researching topics for RailsCasts I often read code in Rails and other gems. This is a great exercise to do. Not only will you pick up some coding tips, but it can help you better understand what makes code readable.
A common practice to organize code in gems is to divide it into modules. When this is done extensively I find it becomes very difficult to read. Before I explain further, a quick detour on instance_eval
.
You can find instance_eval
used in many DSLs: from routes to state machines. Here's an example from Thinking Sphinx.
class Article < ActiveRecord::Base