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"
External content

davetron5000/methadone - GitHub

Framework to write command-line apps in Ruby. Comes with a nice way of processing parameter options, some utility classes and Cucumber steps for testing your CLI app.

Caching may break relative paths in your merged stylesheet

If you turn on stylesheet caching, it might happen that stylesheets from different locations with different relative pathes will be put together to one big stylesheet.

This stylesheet then resides in /stylesheets but still holds the old pathes, which aren’t valid anymore. This leads to the effect that images are displayed on your local development machine (where caching is turned off automatically) but not on the server.

To fix this, either:

  • Move all stylesheets to the same folder
  • or have one cache per folder

Git instaweb

Git has a built-in repository viewer for your web browser. a bit similar (but less awesome) than github.

If you have apache installed, simply go to your repository, and enter
git instaweb –httpd apache2
otherwise, simply install lighttpd and just run
git instaweb

This should open a brower automatically pointing to your repository. If not, try to connect to localhost:1234.

You can stop the server with
git instaweb –stop

External content

DataMapper Retrospective

I introduced DataMapper on my last two major projects. As those projects matured after I had left, they both migrated to a different ORM. That deserves a retrospective, I think.

External content

Rails ERD – Entity-Relationship Diagrams for Rails

Gem to generate entity relationship diagrams from your Rails 3 ActiveRecord models. The diagram style is pretty and configurable.

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 …

How to fix "unknown role" errors in Capistrano recipes

When you have a complex recipe setup with multistage deployment you may run into this error:

`role_list_from': unknown role `something' (ArgumentError)

Consider this task definition:

namespace :foo do
  task :bar, :roles => :something do
    # do crazy stuff
  end
end

Whenever we call foo.bar in our recipe, Capistrano will fail if you deploy to a stage where none of the servers has the role the error complains about, “something” in this case.

However, you can [hack around it](http://groups.google.com/group/ca…

External content

Scenario outlines in Cucumber

Scenario outlines allow us to more concisely express repetitive examples through the use of a template with placeholders.

Graticule computes NULL distance for some records (and how to fix that)

The SQL code generated by Graticule’s spherical distance computation is insufficient and can lead to NULL distances in edge cases.

The reason for this is that MySQL is performing several sine and cosine computations which can result in slight rounding errors – which is usually okay. Rarely, though, for the exact center of the given circle, it is then asked to compute the arc cosine of a result like 1.0000000001.

Since this i…

Bulk-change multiple table rows in a migration

Using rename_column, remove_column, etc. more than once in a migration makes that migration run slower than it should. Use change_table instead.

Consider this migration:
add_column :users, :name, :string
remove_column :users, :first_name
remove_column :users, :last_name
rename_column :users, :cool, :awesome

Migrating in this case means that all those commands are processed step by step, causing 4 SQL statements to change the table. In turn, your database needs to modify the table structure 4 times. When working on hug…

Ubuntu 11.10: Playing sound over front and back panel (or headphones and speakers) at once

I have a pair of headphones connected to my desktop’s back panel and a headset connected to the front panel. I used to play sound over both outputs, but this suddenly stopped working this week.

Apparently, (perhaps through some update) “jack sensing” got turned on, which disables the back panel as soon as you connect something to your front panel audio jack.

To disable this feature, I used alsamixer (use the arrow keys to navigate right to “auto mute”, and disable with the up key). For some reason the corresponding checkbox in the `gnome…

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.

Pick a random element from an array in Ruby

[1,2,3,4].sample
# => e.g. 4

If you’d like to cheat and give different weights to each element in the array, you can use the attached initializer to say:

[1,2,3,4].weighted_sample([1,1,1,1000])
# => probably 4

ERB templates and comments

When you use one line Ruby comments in ERB templates you should never do this (notice the whitespace in front of #):

<% # my comment %>

<div>my html</div>

This leads to strange html output. To avoid long debugging sessions, you should never have a whitespace before the # character (but newline is allowed)

<%# this works as expected %>
   
<%
    # this works, too
    # foo bar baz
%>
External content

Sequel: The Database Toolkit for Ruby

Seems like a useful gem for cases where ActiveRecord is overkill but you don’t want to do everything by hand either.

Unfinished

User friendly form design

There are two types of forms: User forms, e.g. for sign up, and Administration forms, to maintain data. They are quite different in purpose: The former must be simple and quick to fill in, whereas the latter should organize a lot of data in a reasonable way.

Guidelines

  • Simple is win.
  • Align forms vertically, one element below the other.
  • Never explain your form. If it is too complicated, redesign.
  • Skimp on lines and boxes. If you need them, something is wrong with your form.

A form element needs

  • Label. Above the field i…

ActsAsTaggableOn: Cache tag lists

For performance improvements (and to remove the need for eager loading), the ActsAsTaggableOn gem supports caching your tag lists directly in your model. To enable this, simply add a cached_tag_list column to your table.

If you already have existing data, it suffices to simply save all records with tags once, after you’ve added the column.

Example:

class Company < ActiveRecord::Base
  acts_as_taggable_on :categories
end

The cache column has to be named cached_category_list.

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.

2805 cards