Search_spinner

Couldn't create database for ...

When you run rake db:create and get this error message

Couldn't create database for {"encoding"=>"utf8", "username"=>"root", "adapter"=>"mysql", "database"=>"project_development", "password"=>"topsecret"}, charset: utf8, collation: utf8_unicode_ci (if you set the charset manually, make sure you have a matching collation)

make sure the user you have specified (root/topsecret) in your database.yml has access to MySQL. You can check this by running mysql -uroot -p.

Dealing with Solr's "404 Not Found" response

When your Solr seems to be started properly (a process is running with the correct data directory) but never responds properly and replies (via the API or web interface) with…
404 “Not Found”

… check if Solr’s log directory is actually writable for the user running it.

Disable output when using cURL

cURL makes a web request and shows you the response body.

You can redirect the response body to /dev/null just like for many other programs. But if you do that, cURL will display some short information about the request you are making:
$ curl http://www.example.com/ > /dev/null
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 30865 100 30865 0 0 4793 0 0:00:06 0:00:06 –:–:– 10199

If you want…

We forked craken

We forked craken today and fixed one of the issues we had with new (>0.8.7) rake versions.

The craken:install rake task raised a “can’t convert Hash into String” error e.g. while deploying with Capistrano.

https://github.com/makandra/craken

External content

A few git tips you didn't know about

Random list of useful git commands for advanced users. I found some of them useful.

Dragging a file into your terminal pastes the file path

When you drag a file from a Nautilus window into a terminal window, the file’s path will be pasted into the terminal. This also works with multiple files.

Solving "cannot remove Object::ClassMethods"

Most likely you run rake and your code is causing an exception which is not the one shown in your terminal.

Rails tries to catch this exception and clean up constants but – while it’s still booting up – fails on this which causes another exception:

rake aborted!
cannot remove Object::ClassMethods

Running rake with the --trace parameter will give you no love; the backtrace is useless in most cases.

Try these approaches:

  1. Check if there is a helpful error message

  • Have…

When Rails does not recognize Rake tasks in lib/tasks

When you put a Rake task into lib/tasks, but running it fails with…

Don't know how to build task name:of:task

… does your Rake task’s filename end in .rb? It needs to end in .rake instead.

Make an HTTP request to a machine but fake the hostname

Consider you have a website vhost listening to www.example.com, redirecting all incoming requests that do not talk about the configured hostname (this is often used to redirect users to http://www.example.com when entering only http://example.com/).

If you want to make a request to that site’s web server without actually talking to www.example.com (e.g. because this is a load balancer’s address but you want to access one specific machine), you cannot just request machine1.example.com or localhost as the above vhost will redirect…

gpg encrypted backup fails in crontab

If you using gpg for your encrypted backup and it fails after you put it in crontab make sure you have the “–no-tty” option enabled for gpg.

Otherwise you get this error: “cannot open /dev/tty: No such device or address” and the backup size is 0 byte.

Line wrap text from a Ubuntu Linux terminal

You can use fold:

fold -sw 60

You can now paste your texts. fold will echo them back, word-wrapped after 60 columns. Exit with Ctrl+C or Ctrl+D.

You can also use files for input and output:

fold -sw 60 input.txt > output.txt

Auto-generate state_machine graphs as PNG images

The state_machine gem comes with a rake task that lets you generate PNG graphs from any model using state_machine.

Install the required dependencies like this:

sudo apt-get install graphviz
sudo gem install ruby-graphviz

You can now generate a graph like this:

rake state_machine:draw CLASS=ModelUsingStateMachine

Replace ModelUsingStateMachine with the name of your model class.


If it the raketask does not exist for you, add to Rakefile (in your pr…

Fixing Homebrew "Permission denied" issues

When installing your first formula, Homebrew may complain about not being able to access certain directories. The easiest solution to this is:

chown <username> /usr/local/Cellar /usr/local/share # create these directories if they do not exist

Then sudo brew install abc and you’re going.

External content

What's My DNS? Global DNS Propagation Checker

whatsmydns.net is an online service that allows you to instantly perform a DNS lookup to check a hostnames current IP Address and other DNS information against a selection of random name servers around the world. This is especially useful to check the current state of DNS propagation after making changes to your domains zones.

External content

sstephenson/execjs - GitHub

ExecJS lets you run JavaScript code from Ruby. It automatically picks the best runtime available to evaluate your JavaScript program, then returns the result to you as a Ruby object.

Fixing "Lock obtain timed out: SimpleFSLock" for Solr

If your application raises an error like …
Couldn’t connect to the Solr server at http://127.0.0.1:8983/solr. 500 “Lock_obtain_timed_out_SimpleFSLock(…)”

… and if your jetty.request.log contains entries such as …
127.0.0.1 - - [13/09/2011:12:42:23 +0000] “POST /solr/update HTTP/1.1” 500 4412
127.0.0.1 - - [13/09/2011:13:37:03 +0000] “POST /solr/update HTTP/1.1” 500 4309

… you probably have a lucene-...-write.lock file lying around in your Solr data directory that is not being cleaned up properly. This causes…

Open a Nautilus window in your terminal's working directory

In order to open a Nautilus window in your terminal’s working directory, you can say:

nautilus .

"Address already in use" with autossh

If you get an error “Adress already in use” with autossh check with lsof or netstat if something already listen on the Ports you want to use.

There are three Ports you have to look at. If your Command look like this:

/usr/local/bin/autossh -f -M 5100 -g -N -C -L 8080:127.0.0.1:80 example.com -i ~/.ssh/id_rsa -l user

The following three ports need to be available:

  1. 8080: The Port you want the tunnel to listen
  2. 5100: The Autossh Monitoring Port
  3. 5101: Autossh also uses the Monitoring Port +1
2724 cards