puppet: Beware of the Fake False!
The condition for an if statement has to resolve to a boolean true/false value. However, all facts are strings, and all non-empty strings — including the string "false" — are true. This means that facts that are “false” need to be transformed before Puppet will treat them as false.
Related cards:
Security issues with hash conditions in Rails 2 and Rails 3
Find conditions for scopes can be given either as an array (:conditions => ['state = ?', 'draft']
) or a hash (:conditions => { 'state' => 'draft' }
). The later is nicer to read, but has horrible security implications in some versions of Ru...
RSpec: Change the type of a spec regardless of the folder it lives in
In a Rails application, *_spec.rb
files get special treatment depending on the file's directory. E.g. when you put a spec in spec/controllers
your examples will have some magic context like controller
, post
or get
that appears out of now...
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.
JavaScript: Testing the type of a value
Checking if a JavaScript value is of a given type can be very confusing:
- There are two operators
typeof
andinstanceof
which work very differently. - JavaScript has some primitive types, like string literals, that are not objects (as oppose...
Beware: Coffeescript "in" is not the Javascript "in"
The Javascript in
operator does what Hash#has_key?
does in Ruby: Return whether an object has a property.
However, Coffeescript has its own in
operator that checks for array inclusion. To check whether an object has a property, use of
:
##...
Heads up: expect(object).to receive(:method_name) does not execute the original implementation of the method
Let's assume that we have a model Movie
that registers a callback function when a new instance of Movie
is created (Note: For the purpose of this card it is not important what that callback does or which type of callback it is).
This is how...
Beware of magic adblocker rules
If a customer calls and tells you that she cannot see some content of her website beware of the following before starting tcpdump
or other forensic debugging tools.
Some ad blockers like Adblock are shipped with fi...
Working around the ancestry gem's way of object destruction
The ancestry gem allows you to easily use tree structures in your Rails application.
There is one somewhat unobvious pitfall to it: its way of applying the orphan_strategy
which defines how it handles c...
AngularJS: How to hook to the end of a digest cycle (before the browser redraws)
When you run code inside a $watch
expression that forces a repaint (e.g. by computing an element's width, or running something like...
How to change the locale of a PostgreSQL cluster
There may be reasons to change the locale of your Postgres cluster. A popular one is your development system's locale being used by default (which may be annoying). Here is how to do that.
Beware: By following the steps below, you will drop and r...