Search_spinner Cross_grey Magnifier
help

Search syntax

  • Search for repeating cards with repeats:yes
  • Search for unfinished cards with unfinished:yes
  • Search for cards in a certain topic with topic:"name"
  • Search for phrases with "a phrase"
  • Exclude a word from search: -word
  • Exclude a phrase from search: -"a phrase"
  • Exclude a topic from search: -topic:"name"

How to ignore new files or changed files in git

How to ignore new files

Globally
Add the path(s) to your file(s) which you would like to ignore to your .gitignore file (and commit them). These file entries will also apply to others checking out the repo.
Locally
Add the path(s) to your file(s) which you would like to ignore to your .git/info/exclude file. These file entries will only apply to your local working copy.

How to ignore changed files (temporarily)

In order to ignore changed files to being listed as …

Create a new gemset with RVM

To use different Ruby versions on your computer you can use the Ruby Version Manager. It also allows you to pack different gemsets for each of your applications. In order to create on of those just type …

rvm use 1.8.7-p323@makandra_project_xy --create

This command creates and switches to the newly created gemset.

Find geocoded records that are close to a location (radius search)

When you have objects in your database that hold latitude and longitude and you want to find others that are close to given coordinates you can use the Graticule gem.

Graticule

Graticule offers several methods to compute the distance between two geo-dated objects but fetching records from the database that are within a given radius of a location is a bit trickier:

def close_destinations(latitude, longitude)
  distance_sql = Graticule::Distance::Spherical.to_sql(:latitude => l...

Run a script on the server

You have to specify the environment with -e env_name or RAILS_ENV=env_name if you want to run a script on the server.

at Rails 2 it’s script/runner

bundle exec script/runner -e env_name path/to/script.rb argument1 argument2 ...

at Rails 3 it’s rails runner

RAILS_ENV=env_name bundle exec rails runner path/to/script.rb argument1 argument2 ...

Preparing your test database: mind the differences

Instead of running all missing migrations on your test database with rake db:migrate RAILS_ENV=test you can also use a handful of rake tasks to prepare the database structure directly. They can produce different results, though.

In a nutshell, to ensure your test database gains the correct structure:

  • Don’t use rake db:test:prepare carelessly
  • or use rake db:test:clone_structure ← preferred :)
  • or use rake db:migrate RAILS_ENV=test and don’t mix it with other ways, like some of the rake tasks.

rake db:test:prepare ————…

Login forms: Disable browser prompt to remember the password

In order to prevent the browser from asking whether to remember the password, give a form an autocomplete attribute with the value off:

<form "/session" method="post" autocomplete="off">
  ...
</form>

Rails example

form_for @model, :html => { :autocomplete => "off" } do |form|

How to define a custom context menu within HTML (Firefox 8+)

Since Firefox 8 it is possible to define custom context menus (right clicking) with HTML markup.

Error "execution expired (Timeout::Error)" when using Selenium and Webmock

If you get the above error when running tests in bulk (but not individually), it’s actually the fault of Webmock.

Updating Webmock to version 1.7+ fixes this.

"Require group" doesn't work with Ubuntu's default Apache installation

If you want to use Require group $GROUPNAME on your default Apache installation like this:

<Directory "/var/www/foobar">
    Order allow,deny
    Allow from all
    Options None
    AllowOverride all
    AuthName "Area 51"
    AuthType Basic
    AuthBasicProvider external
    AuthExternal pwauth
    Require group admin
</Directory>

You need to first install libapache2-mod-auth-sys-group. You don’t get any error message if you haven’t installed it but it doesn’t work.

sudo apt-get install...

Declare different CSS background-images for different locales

If you would like to use language specific layout (e.g. background-images) in your applications stylesheets you can achieve this easily by using the lang attribute in your views (ERB):

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<%= I18n.locale || 'en' %>" lang="<%= I18n.locale || 'en'%>">
...
</html>

or in HAML:

%html :xmlns => "http://www.w3.org/1999/xhtml", :"xml:lang" => I18n.locale || 'en', :lang => I18n.locale || 'en'

Then, in your stylesheet you can for example declare different background-images fo…

See with tig which git commits touch a file or files or folders

tig path_to_file_or_files_or_path_with_wildcard

Large forms are slow on the iPad

  • Forms with many inputs (600+ in my case) become extremely unresponsive on an iPad, up to the point where it can take several seconds for a control to respond to touch commands.
  • This is true for both iPad 1 and iPad 2 models.
  • While certain CSS styles can lead to performance issues, removing those styles won’t help if the form simply is very large.
  • A workaround is to only show a limited number of form inputs at the time, e. g. by toggling groups of form…
External content

Configuration for Rails, the Right Way

I still see people promoting various gems and plugins to handle miscellaneous configuration elements for your application. One little known secret is that Rails 3 allows you to define your own configuration elements trivially.

Excel files can't hold more than 65535 rows per worksheet

“Classic” Excel (XLS) has a magic limit of 65535 rows per worksheet. This was fixed in XLSX but the version used by the Spreadsheet gem can only write XLS files.

If you want to write more data, consider hacking around it using in_groups_of and writing multiple column sets of your data (i.e. split 1 block of 3 columns and 100000 rows into 4 blocks of 3 (12 in total) columns and 25000 rows).

You can do this until you reach the other limit of 256 columns. After that, open up a new workbook or consider a …

Solve: Unable to send PGP/GPG encrypted e-mail with Enigmail

So you changed your GPG key (e.g. because it expired) and Thunderbird won’t send any more encrypted e-mails with Enigmail?\
Your key is showing up in the key management window but does not seem to work?

Fix Thunderbird settings

If you get errors like “encryption failed: public key not found” your account settings point to the wrong key ID.

Fix it by navigating to: Edit → Account settings → Your account → OpenPGP Security. \
You will find the old key ID there which of course is no longer valid (and you may…

How to manage Thunderbird mailing lists

You can group contacts using a mailing list in Thunderbird for easier access and less trouble when trying to find out who to send a message to. Here is how to do this:

  1. Open your Thunderbird address book
  2. Press the “New List” button
  3. Choose a name for your list and add contacts. There will be auto completion from your address book.

When sending e-mails you can now add a recipient with the mailing list’s name and the e-mail will be sent to all its members.

state_machine: Test whether an object can take a transition

When using state_machine you sometimes need to know whether an object may execute a certain transition. Let’s take an arbitrary object such as a blog article as an example that has those states:

A -> B -> C -> D

Additionally, you have transitions between the states as shown above. Let’s call the transition between ‘A’ and ‘B’ transition_ab for simplicity. \
Given an object in state ‘A’. You can call object.transition_ab but calling object.transition_bc! will obviously fail because …

Be careful with "memoize"

ActiveSupport’s memoize has a dangerous feature you might not know about.

Assume you have

class DeepThought
  extend ActiveSupport::Memoizable
   
  def life_universe_and_everything
     # some lengthy calculation returning 42
  end
  memoize :life_universe_and_everything
end

Then #life_universe_and_everything will of course cache the result after calculating it once. However, you can trigger a recalculation by calling #life_universe_and_everything(true).

If, however, your method looks like

de...
2808 cards