VirtualBox host IP address and hostname
When you are using NAT in your virtual machine (which you should), the host's IP address is:
10.0.2.2
You'll need it to access shared folders or your host's web server when testing pages in IE.
Fun fact: You could also use vbox.srv -- that's the corresponding hostname.
Customize path for Capybara "show me the page" files
When you regularly make use of Cucumber's "show me the page" step (or let pages pop up as errors occur), the capybara-20120326132013.html files will clutter up your Rails root directory.
To tell Capybara where it should save those files instead, put this into features/support/env.rb:
Capybara.save_and_open_page_path = 'tmp/capybara'
Connecting the "sequel" gem to MSSQL via ODBC
After you configured your ODBC describe in
- Fix [RubyODBC]Cannot allocate SQLHENV when connecting to MSSQL 2005 with Ruby 1.8.7. on Ubuntu 10.10
- and Connecting to MSSQL with Ruby on Ubuntu - lambie.org
you can connect with sequel:
require "rubygems"
require "se...
Fix [RubyODBC]Cannot allocate SQLHENV when connecting to MSSQL 2005 with Ruby 1.8.7. on Ubuntu 10.10
I followed this nice guide Connecting to MSSQL with Ruby on Ubuntu - lambie.org until I ran in the following errors:
irb(main):001:0> require "dbi"; dbh = DBI.connect('dbi:ODBC:MyLegacyServer', 'my_name', 'my_password')
DBI::DatabaseError: INTERN (0) [RubyODBC]Cannot allocate SQLHENV
from /usr/lib/ruby/1.8/dbd/odbc/driver.rb:36:in `connect'
from /usr/lib/ruby/1.8/dbi/handles/driver.rb:33:in `connect'
from /usr/lib/ruby...
Linux: Mount second encrypted HDD automatically without entering a password
This is one possibility to do this. There are other and maybe even better ways to do this.
-
Generate a key for your encrypted harddisk:
dd if=/dev/random of=/home/bob/keyfile_sdb1 bs=4096 count=1 -
Then add your keyfile to encrypted harddisk: How to change your dm-crypt passphrase (step 3)
-
Create a mountpoint:
mkdir /mnt/space -
Create a script e.g. in your homedirectory (/home/bob/mount_sdb1.sh):
#!bin/bash ...
MySQL shell: Enable UTF-8
When you do a script/dbconsole -p, your MySQL shell will already be using UTF-8. When you call it yourself using mysql, it may not be enabled.
You'll notice that when you get ASCII salad and/or question marks instead of special characters. \
Example: Hlavn� m?sto Praha instead of Hlavní město Praha.
You need to manually switch on UTF-8, in the MySQL console:
SET NAMES 'utf8';
Render Single-Line Markdown Text with Redcarpet
We love Markdown. We use it wherever we can for text formatting. In a web app, the obvious place for it is in large text areas, where we can allow complete freedom of formatting. Headers, paragraphs, lists, it’s all good.
What about the formatting of text in single-line text fields? If our form entry is a single line, that’s usually how its text will be displayed in our interface. In this case, we probably want to avoid all the block-level elements that Markdown will let the user create.
Ruby, Ruby on Rails, and _why: The disappearance of one of the world’s most beloved computer programmers
Nice article to educate your non-geek girlfriend/boyfriend about the joys of programming.
Capybara: Test that a string is visible as static text
This is surprisingly difficult when there is a <textarea> with the same text on the page, but you really want to see the letters as static text in a <p> or similiar.
The step definition below lets you say:
Then I should see the text "foo"
You should not look too closely at the step definition because when you see the light, it will blind you.
Then /^I should see the text "(.*?)"$/ do |text|
elements = page.all('*', :text => text).reject { |element| element.tag_name == 'textarea' || element.all('*', :text => text...
Fix error: rails console - no such file to load -- readline
Install libreadline:
sudo apt-get install libreadline-dev
Reinstall the ruby and tell rvm where to find readline
rvm reinstall 1.8.7 --with-readline-dir=/usr/include/readline
Make sure you get a huge cup of tea before running the command above! It will take some time.
References
- github issue
- stackoverflow
- [rvm documentation](https://rvm.beginrescueend.com/pack...
Bundler 1.1 has been released, is very fast
Bundler 1.1 has been released. With this version you no longer need to wait for this:
Fetching source index…
The new Bundler is smarter and can fetch required metadata in a few seconds.
You can install the new version by saying:
sudo gem install bundler
Install the typhoeus gem with native extensions
If you get this:
Installing typhoeus (0.3.3) with native extensions
/usr/local/lib/site_ruby/1.8/rubygems/installer.rb:483:in `build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)
/usr/bin/ruby1.8 extconf.rb
checking for curl/curl.h in /opt/local/include,/opt/local/include/curl,/usr/include/curl,/usr/include,/usr/include/curl,/usr/local/include/curl... no
need libcurl
You can fix it by installing the libcurl3-dev package:
sudo apt-get install libcurl3-dev
Now you should...
responsive.is
Online tool to test how a site behaves in popular desktop, tablet and phone resolutions.
Sass: Use black or white foreground color depending on the lightness of the background
This article shows how to create a Sass mixin for a colored button. The button's foreground color is dynamically chosen between either black or white, depending on the given background color.
It's a nice intro into @if and @else conditionals in Sass.
Find out your SSH key's fingerprint (e.g. to authenticate on GitHub)
If you want to know your public key's fingerprint, do this:
ssh-keygen -lf ~/.ssh/my.key.pub
This may be necessary to authenticate your key on GitHub because of recent events -- you need to do that if you get an error like this when talking to them (to pull etc):
ERROR: Hi foobear, it's GitHub. We're doing an SSH key audit.
Please visit https://github.com/settings/ssh/audit/...
to approve this key so we know it's safe.
Fingerprint: ab:cd:ef:...
fatal:...
Setup or update Passenger to use Ruby Enterprise
- Your current
rubymust be Ruby Enterprise. gem install passengerpassenger-install-apache2-module- Edit your
httpd.confaccording to the instructions provided at the end of the setup script. - Restart Apache:
sudo service apache2 restart
This also works when you previously ran your Passenger using MRI. Just run the setup as described.
Spec "content_for" calls in helpers
This only applies to RSpec below version 1.3.2. The issue has been fixed in RSpec 1.3.2, and most likely RSpec 2 and later versions.
When you have a helper that calls content_for and want to check its behavior you should probably write a feature instead. If you still want to do it, mind the following.
Consider this helper:
module LayoutHelper
def title(string)
content_for :title, string
string
end
end
Somewhere in the layout we'd then say something like this: `<%= yield :title %...</p>
RubyMine: Disable window animations
Under Settings / Appearance you can uncheck a box Animate windows. This will change your life.
This setting seems to not exist anymore.
Gherkin: Error during installation
When trying to install the gherkin gem, you might encounter an error with the following lines:
ERROR: Error installing gherkin:
ERROR: Failed to build gem native extension.
...
checking for main() in -lc... yes
creating Makefile
...
cc1: all warnings being treated as errors
Makefile:150: recipe for target 'gherkin_lexer_ar.o' failed
make: *** [gherkin_lexer_ar.o] Error 1
...
If upgrading is not an option, configure build options for gherkin:
bundle config --local build.gherkin --with-cflags=-w
Your .bundle/config fi...
Debugging Google Analytics
If you need to debug Analytics tracking, consider using this chrome extension. It will replace the tracking code with a debug version that prints debugging info to the JavaScript console.
Compare two XML strings as hashes
Let's say you have two XML strings that are ordered differently but you don't care about the order of attributes inside containers:
a = '<?xml version="1.0" encoding="UTF-8"?><Authenticate><User>batman</User><Password>secret</Password></Authenticate>'
b = '<?xml version="1.0" encoding="UTF-8"?><Authenticate><Password>secret</Password><User>batman</User></Authenticate>'
Working with plain string comparison is not helpful, of course:
a == b
=> false
Instead, you can use the Nori gem ...
Git: Remove information on branches that were deleted on origin
When branches get deleted on origin, your local repository won't take notice of that.
You'll still have your locally cached versions of those branches (which is actually good) but git branch -a will still list them as remote branches.
You can clean up that information locally like this:
git remote prune origin
Your local copies of deleted branches are not removed by this.
The same effect is achieved by using (kudos to Julien):
git fetch --prune
You could also set that as a default.
Markdown/Commonmarker examples
This card shows you how to format a card's content using Markdown. We use the Commonmarker interpreter, so here are examples for its dialect.
Formatting
**Bold**
Bold
_Italics_
Italics
`Monospaced`
Monospaced
> Quoted text
Quoted text
Here is [a link](http://makandra.com/).
Here is a link.

@role = value
self.email = find_email_by_name(user.name)
end
end
This piece of code works well until the object params hash contains a second element when it is updated like this:
@feedback.update_attributes!(params[:feedback])
Now it is no longer ensured that user was set before name was set. If the name...