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"

Run specific version of bundler

You want to run a specific, maybe older version of bundler for whatever reason?

$ bundle _1.0.21_ -v
Bundler version 1.0.21
External content

Ruby 1.8.7-p370 released

It's the last bugfix release. We will get another year of security fixes, then no more patches.

Err http://de.archive.ubuntu.com [...] 404 Not Found [IP: 141.30.13.20 80]

I've got often this error on just one server:

Err http://de.archive.ubuntu.com precise/universe amd64 Packages
404  Not Found [IP: 141.30.13.20 80]

But there was no problem with the network connection or the de.archive.ubuntu.com server.

After I deleted the local lists cache with rm -r /var/lib/apt/lists it works again.

How to deal with: Puppet::Parser::AST::Resource failed with error ArgumentError: Invalid resource type [...] at

  1. Check if you have puppetsync enabled on the master and client

    [main]
    logdir=/var/log/puppet
    vardir=/var/lib/puppet
    ssldir=/var/lib/puppet/ssl
    rundir=/var/run/puppet
    factpath=$vardir/lib/facter
    templatedir=$confdir/templates
    pluginsync = true
    
  2. Check in /var/lib/puppet/lib there should be a […].rb somewhere. Delete it and look if it get copied again after with the next puppet run.
  3. If you are using environments make sure the puppetmaster is also in the correct environment. (d…

Rack dies when parsing large forms

  • Rack has a limit for how many form parameters it will parse.
  • This limit is 65536 by default.
  • There is a bug in Rack that will incorrectly count the number of input fields in nested forms. In my case a form with 1326 input fields was enough to break the default limit.
  • If Rack thinks your request is too large, the request will fail with a low-level Ruby message like [*Fix: "undefined method `bytesize' for #"*](https://makandracards.com/makandra/1517-fix-undefined-method-bytesize-for-array) or the standard Rails error box.
  • You …

Rails 3.1 gives you free down migrations

In Rails 3.1+, instead of defining a separate up and down method you can define a single method change:

class AddComparisonFieldsToReport < ActiveRecord::Migration
  def change
    add_column :reports, :compare, :boolean
    update "UPDATE reports SET compare = #{quoted_false}"
    add_column :reports, :compare_start_date, :date
    add_column :reports, :compare_end_date, :date
  end
end

Migrating up works as expected:

```
b rake db:migrate
== AddComparisonFieldsToReport: migrating ==================================== – ad…

Updated: Test a gem in multiple versions of Rails

Updated the card with our current best practice (shared app code and specs via symlinks).

Consul 0.3.0 has a shortcut to quickly create an action map for CRUD controllers

In moderately complex authorization scenarios you will often find yourself writing a map like this:

class NotesController < ApplicationController
  power :notes, :map => {
    [:edit, :update] => :updatable_notes
    [:new, :create] => :creatable_notes
    [:destroy] => :destroyable_notes
  }
end

Because this pattern is so common, Consul now has a shortcut :crud to do the same:

class NotesController < ApplicationController
  power :crud => :notes
end

Get the initial username which you used to login to your Linux system

If you need the initial user which you used to login to your Linux system or the time when you login you can do:

who -m

If you're in a good mood you can also do:

who am i

or (this is my favorite):

who mom likes

One purpose of this could be the .bashrc to show different Bash Promts for root to different users:

if [ `who mom likes | awk '{print $1}'` = "foobar" ]; then
   PS1='${debian_chroot:+($debian_chroot)}\[\033[41;33m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
   PS1='${de...

RSpec claims nil to be false

RSpec's be_false behaves unexpectedly:

nil.should be_false
# passes, as the expectation returns true

If you want to check for false, you need to do it like this:

nil.should == false
# fails as expected

Wat?

See also

RSpec: be_true does not actually check if a value is true

Some useful Unicode chars

Copy and paste at will, they're free!

  • German quotation marks: „ “ (Ubuntu-Hotkey: AltGr+v and AltGr+b)
  • English quotation marks: “ ”
  • En dash: –
  • Em dash: —
  • Ellipsis: …

Some useful hints for users of Ubuntu Linux

  • Your Ubuntu comes with a searchable list of Unicode chars. Go to Accessories / Character map. Ctrl + F searches for a character by name.
  • If you want to write all of them (and more) yourself, [configure a compose key](https://makandracards.com/makandra/1030-insert-an…

Setup your terminal to not scroll when there is new output

When you are scrolling up to investigate a test failure it is super annoying when the terminal scrolls back down whenever the running test outputs another line. Luckily you can disable this behavior:

  • Gnome terminal: Edit -> Profile preferences -> Scrolling", uncheck *Scroll on output
  • Terminator: Right click on terminal screen, Preferences -> Profile -> (for each profile) -> Scrolling, uncheck Scroll on output

has_defaults is now a gem

  • has_defaults is now a gem, no longer a plugin.
  • The plugin version no longer exists. Note that plugins are no longer supported in 3.2.
  • If you are working on an application that has the plugin version of has_defaults there is no advantage to be gained from upgrading the gem. The gem is there for you should you one day upgrade to Rails 3.2+.
  • Please don't use the defaults gem which we original forked away from in 2009. It sets defaults when a field is `bl…

rake spec + rails_admin = weirdly failing specs

If you use rails_admin, your specs pass with the rspec binary, but not using rake spec (or rake parallel:spec etc), put this at the top of your spec_helper:

ENV['SKIP_RAILS_ADMIN_INITIALIZER'] = 'false'

Don't ask.

This is probably also true for cucumber, your env.rb would be the right place.

External content

Difference between class_inheritable_attribute and class_attribute | martinciu's dev blog

How to make class_attribute behave like class_inheritable_attribte which no longer exists in Rails.

Deal with error: Expected foo_trait.rb to define FooTrait

Lately, I came across a nasty error. I had a class Article that included FooTrait and BarTrait. In BarTrait, I then accidentally called a non-existent method:

has_defaults :dummy => Dummy.non_existent_method

From that moment, no page would load anymore but always display an exception: Expected foo_trait.rb to define FooTrait. That trait had nothing to do with BarTrait.

Since it doesn't tell you what's wrong, you either remember where you were working last or you need to check all [traits](https://github.com/makandra/modul…

BigDecimal#inspect for people who aren't cyborgs

I wonder if the guy that wrote BigDecimal#inspect has a tragic backstory that explains why he hates humanity.

- Tim Pope

I finally gave up and made BigDecimal#inspect return BigDecimal#to_s:

p BigDecimal.new('2.3') #=> "2.3"

Use the attached initializer.

3085 cards