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.

AngularJS: Binding to Perl-style getter/setters functions

Angular 1.3+ has an alternative getter/setter pattern: You can bind ng-model to an accessor function. This is a function that is either a getter (when it gets no arguments) or a setter (when it gets the new value as an argument):

$scope.name = function(newName) {
  return angular.isDefined(newName) ? (_name = newName) : _name;
}

You need to bind this function with ng-model and `ng-model-options="{ getterSette...

Testing focus/blur events with Cucumber

This is a problem when using Selenium with Firefox. We recommend using ChromeDriver for your Selenium tests.


This setup allows to test focus/blur events in Cucumber tests (using Selenium). For background information, see How to solve Selenium focus issues.

Cucumber step definition:

# This step is needed because in Selenium tests, blur events are not triggered
# when the browser has no focus.
When /^I unfocus the "(.*?)" field to trigger ja...

Magnific Popup: Responsive jQuery Lightbox Plugin

Responsive Lightbox JavaScript that just works.

You can use it for single images or a gallery. Animations are optional.

pgcli - Postgres command line interface

A CLI for working with Postgres databases. Ships with auto-completion and syntax highlighting.

jQuery: Get a promise for the end of an animation

The API is a little confusing because animate returns a reference to the element to enable chaining.
But you can do this:

$element.animate(...);
$element.promise().then(function() { ... });

Make jQuery.animate run smoother with almost no code changes

jQuery comes with .animate() that lets you transition some CSS selectors:

function floatIn($element) {
  $element.css({ 'opacity': 0, 'margin-top': 200px });
  $element.animate({ 'opacity': 1, 'margin-top': 0 }, { duration: 500 });
}

The animation is implemented using setInterval and Javascript. This works great, but it's not as smooth as a CSS transition.

Fortunately the animate API can be mapped almo...

Databound

Databound provides Javascript a simple API to the Ruby on Rails CRUD.

Tries to expose a full model CRUD as an API. Not sure if this is useful for more refined requirements.

Angular: Binding strength in ngRepeat (aka operator precedence)

When you have an ngRepeat directive that uses track by, be sure to move the track by instructions to the very end of your statement, i.e. behind any filters.

Broken

Consider the following:

ng-repeat="child in category.children track by child.name | orderBy:'name'"

This will silently skip ordering; here is how AngularJS sees it (parentheses inserted to display binding strength):

ng-repeat="child in (category.children track by (child.name | orderBy:'name'))"

Working

Moving track by to the end will correctly...

Researching a new form of HTTP caching optimization - Phusion BlogPhusion Blog

Interesting approach to caching responses directly in the HTTP server, based on the value of an individual cookie.

No word yet how to force cache-invalidation.

thoughtbot/bourbon

Bourbon is a library of pure Sass mixins that are designed to be simple and easy to use. No configuration required. The mixins aim to be as vanilla as possible, meaning they should be as close to the original CSS syntax as possible.

The mixins contain vendor specific prefixes for all CSS3 properties for support amongst modern browsers. The prefixes also ensure graceful degradation for older browsers that support only CSS3 prefixed properties.

Cucumber: Removing uploaded files after test runs

Cucumber will clean up files you've uploaded in your Cucumber features automatically with the attached code. Put the file in features/support/.

RSpec matcher "be_sorted"

RSpec::Matchers.define :be_naturally_sorted do
  match do |array|
    array == array.natural_sort
  end
end

See RSpec: Where to put custom matchers and other support code. To use natural_sort, see this card.


This matcher is now part of Spreewald.

Cucumber step to test whether a select field is sorted

This step will pass if the specified select is sorted.

Then /^the "(.*?)" select should be sorted$/ do |label, negate|
  select = find_field(label)
  options = select.all('option').reject { |o| o.value.nil? }

  options.collect(&:text).each_cons(2) do |a,b|
    (a.text.downcase <=> b.text.downcase).should <= 0
  end
end

In conjunction with this custom matcher, the each_cons block can be replaced with:

options.should be_naturally_sorted

Usage

Then the "Organizations" select should be sorted...

mailru/FileAPI

A set of javascript tools for working with files.

It offers different kinds of things:

  • A cross-browser JS API to work with File objects.
  • Image helper methods, like rotating images, or generating thumbnails in the browser (because you don't want your browser to scale tons of 20MB-JPEGs just for an upload preview)
  • Webcam access
  • Uploads

When HTML5 support is unavailable, it uses Flash polyfills.

Check out the documentation and demos at their GitHub page.

To install via bower, simply add the `...

danialfarid/angular-file-upload

Lightweight Angular JS directive to upload files

Includes polyfills for old IEs. Unfortunately, their auto-loading mechanism may not work properly on your Rails application due to the asset pipeline. They use FileAPI, so you could just include it manually for old browsers, or when you want to use FileAPI's toolkit anyway.

Fixing the warning Time#succ is obsolete; use time + 1

Chances are you're seeing the warning repeated a lot of times, maybe thousands of times. Here's how to reproduce the issue:

Example 1

# bad code
(Time.current .. Time.current + 1.hour).include?(Time.current)

# Use Range#cover? instead of Range#include? since the former does no typecasting into integers.
(Time.current .. Time.current + 1.hour).cover?(Time.current)

Example 2

# bad code
Post.where(:created_at => min_date.beginning_of_day .. max_date.end_of_day)

# Use 'BETWEEN x AND y'
Post.where(['posts.created_at BETWEEN...

English words that you cannot use in Coffeescript

Today in computer: In Coffeescript, on and yes are aliases for true. off and no are aliases for false.

Defining variables or functions with such a name will give you errors like this:

reserved word "true" can't be assigned
reserved word "false" can't be assigned

This will not be fixed.

Show backtrace for all Sidekiq threads

It might happen that your Sidekiq queue gets stuck, hanging at 0% CPU load.

When we inspected the process using strace we saw a blocking select system call.

You can get backtraces for each thread by sending the TTIN signal to the Sidekiq process like this:

kill -TTIN $process_id

problem updating perl package(s) on freebsd `pkg-static: lstat(..../.packlist): No such file or directory

If you have trouble updating something on FreeBSD you should always take a look in the UPDATING file.

For this error there is this solution which worked perfectly for me:

20141127:
  AFFECTS: users of lang/perl5.*
  AUTHOR: mat@FreeBSD.org

  There was a nasty bug introduced in the update below, it was introduced in
  svn revision 373476 and corrected in 373485.  If you get errors looking like
  this one:

  ===>   Registering installation for p5-Params-Util-1.07_1 as automat...

Angular: Keeping attributes with invalid values in an ngModel

The Angular 1.2 way:

# By default, angular returns undefined for invalid attributes which removes
# the value from the form field's ngModel (which means it's not sent to the
# server, and old values would not be overwritten).
#
# This directive makes sure that form fields with an invalid value return an
# empty string instead of undefined.

for elementType in ['input', 'textarea', 'select']
  @app.directive elementType, ->

    priority: 1
    restrict: 'E'
    require: '?ngModel'

    link: (scope, element, attributes, ngModelControlle...

postgresql: Get all values for an enum

SELECT enum_range(NULL::portal) # Returns an array of all possible values
SELECT unnest(enum_range(NULL::portal)) # Unnests the array and returns a row for each value

Whereas portal is the enum type.

Heads up: LibreOffice Calc adds quotation marks when copying data from multi-line cells

Copy data from LibreOffice Calc

When you copy data from multi-line cells in LibreOffice Calc, quotation marks are automatically added, which you may not want.

For example with license keys:

09:46:24 [✔] pascal:~> icdiff license license_copy 
license                           license_copy                           
===== LICENSE BEGIN =====         "===== LICENSE BEGIN =====             
00000yIeXfhGSbt"yULWQR9n          00000yIeXfhGSbt""yULWQR9n        
olysFAv105bHmKOiqbxRX"Yr  ...

$setDirty for Angular 1.2

Angular 1.3 offers $setDirty for your ngModelController. If you are stuck on Angular 1.2, do this:

model.$setViewValue(model.$viewValue)

This turns the model dirty, while keeping its value.