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"

Capistrano 3 has slightly changed its symlink implementation

In Capistrano 2, directories in shared_children used to be symlinked to the shared directory during the finalize_update task.

# <capistrano>/lib/capistrano/recipes/deploy.rb

_cset :shared_children,   %w(public/system log tmp/pids)
# ...
task :finalize_update, :except => { :no_release => true } do
  # ...
  shared_children.map do |d|
    run "ln -s #{shared_path}/#{d.split('/').last} #{latest_release}/#{d}"
  end
  # ...
end

This wo…

get debug output for puppetmaster running with passenger

If you need the debug output of the puppetmaster running with passenger you have to uncomment this setting in the config.ru:

#ARGV << "--debug"

If you don’t know where your config.ru is, check the Apache DocumentRoot. It’s in /path/to/DocumentRoot/../config.ru. For example if your DocumentRoot is /etc/puppet/rack/public/ the config.ru is in /etc/puppet/rack/config.ru.

How to fix: iPad does not trigger click event on some elements

iPads will not trigger click events for all elements. You can fix that, but you don’t want to know why.

Example: Capturing clicks on table rows (use case would be clicking the 1st link inside it for better UI). Consider this setup:

<table>
  <tr>
    <td>hello</td>
  </tr>
</table>
$(document).on('click', 'tr', function () {
  alert('row clicked')
});

While this works on a desktop browser, clicking the row/cell on an iPad will just do nothing.

Turns out, the iPad will only trigger such events for …

Parallel Rspec with RTeX

Running projects parallel makes some trouble with PDF generation. Use geordi rspec spec to force sequential tests for the hole application or failed specs only.


geordi rspec
RTeX::Document::GenerationError in '...'
Could not find result PDF document.pdf after generation.
Check .../document.log

The document will show you, that RTeX tries to generate a PDF document out of a HTML file, which won’t work.

Repeats

How to write complex migrations in Rails

Rails gives you migrations to change your database schema with simple commands like add_column or update.
Unfortunately these commands are simply not expressive enough to handle complex cases.

This card outlines three different techniques you can use to describe nontrivial migrations in Rails / ActiveRecord.

Note that the techniques below should serve you well for tables with many thousand rows. Once your database tables grows to millions of rows, migration performance becomes an iss…

External content

emcien/iso_latte

Sometimes you need to run background jobs that you can’t make important guarantees about - they may run out of memory and get killed, or produce segmentation faults, or exit! directly - and you need to be able to clean up after such problems.

IsoLatte is a gem that allows a block of code to be executed in a subprocess. Exceptions get passed back to the parent process through a pipe, and various exit conditions are handled via configurable callbacks.

JavaScript events: target vs currentTarget

tl;dr: Use event.currentTarget unless you are absolutely certain that you need event.target.


Since it hasn’t been written down in this deck before, here it goes:

When working with JavaScript Event objects, the DOM element that triggered the event is attached to them. [1]
However, there are 2 “opinions” on which element that would be:

  • The element that the user interacted with (event.target),
  • or the element that the event listener is bound to (event.currentTarget).

Note that both can be, but not…

External content

How to capture changes in after_commit

Your after_commit callbacks will not know about changes, as Rails discards them when committing.

The linked article shows a clever trick to work around that: It uses an after_save method that looks at changes and writes its decision to an instance variable. That instance variable can then be used in the after_commit method.

Note that while callbacks like after_save are not affected, there are valid reasons for using only after_commit, and not after_save. Enqueueing a Sidekiq job is just one of them.

External content

24 little known CSS facts

This blew my mind today:

Please make sure to check browser support for CSS features on Can I Use and the Mozilla Development Network before using.

Favorites

  • outline-offset: specify how far away from the element an outline is rendered
  • ::first-letter: matches the first letter insid…
Auto-destruct in 48 days

Updated: Manually trigger a delegated DOM event

Added a workaround for Internet Explorer, which cannot instantiate MouseEvent objects directly.

Repeats

Execution of shell code in Ruby scripts

There are several ways to execute shell code in Ruby. Spawn is the method behing exec, system and %x[…], don’t use it, but check the documentation below.

%x{ } or backticks – quick and easy

Returns the standard output of running the given command in a subshell. This is an alias for `…`, and you can use string interpolation.

Example:

name = 'ls'
result = `which #{name}`

It does not escape anything you inject in the string.

If you want to find out if…

Savon: Use complex SOAP types as arguments

If a SOAP API expects you to call a remote method with arguments of complex types, Savon lets you manually set the xsi:type attribute like this:

client.call(:rpc_method,
  message: {
    :some_object => {
      :name => 'foo',
      :other => 'bar',
      '@xsi:type' => 'somenamespace:SomeObject'
    }
  }
)

This is roughly equivalent to this in Javaland, where you have magic generated stub code:

SomeObject so = new SomeObject();
so.setName('foo');
so.setOther('bar');
client.rpcMethod(so);
External content

A commitment is not a guarantee - Pivotal Tracker

The team is responsible for building great software—that’s it. It’s the only thing the team is responsible for and it’s the only thing that they actually control. In other words, the development team is committed to quality software.

Repeats

Invoices: How to properly round and calculate totals

While it might seem trivial to implement an invoice that sums up items and shows net, gross and vat totals, it actually involves a lot of rules and caveats. It is very easy to create invoices where numbers don’t add up and a few cents are missing. A missing cent is a big deal for an accountant, so it is important for your invoices to list correct numbers.

Note that this is not legal advice. Also note that while this note has a number of code examples in Ruby and MySQL, the concepts apply to all programming languages and data stores.

When …

Padrino: "incompatible marshal file format (can't be read)"

If you see a stacktrace beginning with lines like this:

E, [2015-07-16T09:23:10.896146 #23308] ERROR -- : app error: "incompatible marshal file format (can't be read)\n\tformat version 4.8 required; 32.32 given" (TypeError)
E, [2015-07-16T09:23:10.896282 #23308] ERROR -- : /.../bundle/ruby/2.0.0/gems/moneta-0.7.20/lib/moneta/transformer.rb:132:in `load'
E, [2015-07-16T09:23:10.896311 #23308] ERROR -- : /.../bundle/ruby/2.0.0/gems/moneta-0.7.20/lib/moneta/transformer.rb:132:in `load'
E, [2015-07-16T09:23:10.896334 #23308] ERR...
Repeats

Creating many records works faster in a transaction

When you need to insert many records into the same table, a fast way to do it is to have a single INSERT statement describing multiple rows. Unfortunately there is no way to do this through ActiveRecord.

What you can do to save time is to open a transaction and save multiple records within that transaction:

transaction do
  500.times { Model.create! }
end

Although you will still trigger 500 INSERT statements, they will complete considerably faster.

When I trie…

Protip: Clone large projects multiple times

Large projects usually have large test suites that can run for a long time.
This can be annoying as running tests blocks you from picking up the next story – but it doesn’t have to be that way!

Simply clone your project’s repo twice (or even more often).

When your work on a feature branch is done, simply push that branch and check it out on your 2nd copy to run tests there.
You can pick up a new story and work on that on your “main” project directory.

If you do it right, you will even be able to run tests in both your 2nd copy and your m…

2843 cards