Install Bower under Ubuntu

First install Node.js / npm.

Then you can install Bower through npm:

sudo npm install -g bower

Installing Node.js / npm under Ubuntu with nvm (with yarn)

I recommend install Node.js using nvm. This way you can have multiple Node versions in your ~/.nvm. You also won't need to install global packages with sudo anymore.

Node via nvm will automatically bring npm. yarn will automatically be available if corepack is enabled for node.

Installing nvm

DigitalOcean has a HOWTO for installing nvm on Ubuntu (16.04, [18.04](https://www.digitalocean.com/community/tutorials/how-to-...

natritmeyer/site_prism

SitePrism gives you a simple, clean and semantic DSL for describing your site using the Page Object Model pattern, for use with Capybara in automated acceptance testing.

The Page Object Model is a test automation pattern that aims to create an abstraction of your site's user interface that can be used in tests. The most common way to do this is to model each page as a class, and to then use instances of those classes in your tests.

If a class represents a page then each element of the page is represented by a method that, when cal...

Migrating legacy jQuery code to .on() and .off()

If you need to upgrade code that uses the old jQuery methods bind, delegate, live, unbind and die, the attached article has examples how to migrate to the new on and off versions.

httpbin: HTTP Client Testing Service

Some dozen generic API endpoints you can use to test how your HTTP client deals with various responses, e.g.

  • a slow connection
  • many redirects
  • compressed data

I found this useful while debugging an issue with timeouts.

Bootstrap 4 is coming

What's new

  • Moved from Less to Sass. Bootstrap now compiles faster than ever thanks to Libsass, and we join an increasingly large community of Sass developers.
  • Improved grid system. We’ve added a new grid tier to better target mobile devices and completely overhauled our semantic mixins.
    Opt-in flexbox support is here. The future is now—switch a boolean variable and recompile your CSS to take advantage of a flexbox-based grid system and components.
  • Dropped wells, thumbnails, and panels for cards. Cards are a brand new co...

Retina revolution

Looking for a way to embed raster images for both low- and high-DPI displays, this developer had some good results with using a high resolution with more JPEG compression than you would use normally.

He argues that the image looked great on both low- and high-DPI displays. Also the compression artifacts were now so small that they are not as noticable then when an 1:1 image is highly compressed.

DevDocs is your API Hub

DevDocs combines multiple API documentations in a fast, organized, and searchable interface. Here's what you should know before you start:

  • You don't have to use your mouse — see the list of keyboard shortcuts
  • The search supports fuzzy matching (e.g. "bgcp" brings up "background-clip")
  • To search a specific documentation, type its name (or an abbreviation), then Tab
  • You can search using your browser's address bar — learn how
  • DevDocs works offline, on mobile, and can be installed on Chrome and Firefox.
  • For the latest news, subscr...

Pitfall: has_defaults on virtual attributes are nil when loaded from database, of course …

It smells. Rethink your code design.

Code example with makandra/has_defaults:

class Post < ActiveRecord::Base

  has_defaults tags: []          # field in db
  has_defaults virtual_tags: []  # no db field
  
  def all_tags
    virtual_tags + tags
  end
  
end

> Post.new.virtual_tags
=> []   # ✔

> Post.find(1).virtual_tags
=> nil   # ☹

> Post.find(1).all_tags
=> Error: undefined method '+' for nil:NilClass

Creating spheres with CSS

Using the CSS border-radius property, we can create rounded shapes and circles. Add some gradients and they become spheres. Let’s try that, and add some animation to bring them to life.

How to update RubyGems binary for all installed rubies

To update your Rubygems to the latest available version, type the following:

 gem update --system

Note that you have a separate Rubygems installation for each Ruby version in your RVM or rbenv setup. Updating one does not update the others.

Ruby 1.8.7

If you are using Ruby 1.8.7 you cannot use the latest version of Rubygems. Type the following to get the latest version that is compatible with 1.8.7:

 gem updat...

Native app install banners in Android, iOS

You can make both mobile Chrome and mobile Safari display a native app install banner. The banner suggests that the user installs an app that is related to the current page. It is shown in the phone's native UI. See attached animation.

There is some fineprint you need to read to make this work (see below).

References

Continuous Security Testing with Devops - OWASP EU 2014

Interesting talk about a team that integrated automated security testing into their BDD workflow.

There is also a video of the talk.

Flash-Free Clipboard for the Web

Unfortunately, Web APIs haven’t provided the functionality to copy text to the clipboard through JavaScript, which is why visiting GitHub with Flash disabled shows an ugly grey box where the button is supposed to be. Fortunately, we have a solution. The editor APIs provide document.execCommand as an entry point for executing editor commands. The "copy" and cut" commands have previously been disabled for web pages, but with Firefox 41, which is currently in Beta, and slated to move to release in mid-September, it is becoming available to Ja...

AWS Public IP Address Ranges Now Available in JSON Form

I am happy to announce that this information is now available in JSON form at https://ip-ranges.amazonaws.com/ip-ranges.json. The information in this file is generated from our internal system-of-record and is authoritative. You can expect it to change several times per week and should poll accordingly.

whenever: Preview the crontab

If you'd like to preview the crontab that whenever will deploy, run the following:

bundle exec whenever

This will print the cron syntax without modifying your local crontab.

passenger problems with upgraded rails-app

You may encounter problems with passenger starting an application with an updated rails.
If you find an error like this in the apache error log:

[ 2015-08-21 10:53:04.1266 17680/7f4909bf7700 Pool2/Implementation.cpp:883 ]: Could not spawn process for group /var/www/example.com/current#default: An error occured while starting up the preloader.
     in 'void Passenger::ApplicationPool2::SmartSpawner::handleErrorResponse(Passenger::ApplicationPool2::SmartSpawner::StartupDetails&)' (SmartSpawner.h:455)
     in 'std::string Passenger::Appli...

postgresql create extension without giving the application superuser rights

If you need a postgresql extension for your database it isn't a good idea to give your applications database user superuser rights (like many people on stackoverflow think)

Just login to the database with a superuser account (e.g. postgres) and create the extension with it.

Example:

# with the default configuration of postgresql you normally can login as `postgres` user
# without a password if you use the systems `postgres` user
$ sudo su -l postgres
$ pgsql
postgres=# \c your_database;
psql (9.3.9, server 9.3.5)
You are now connected...

include_tags with the asset pipeline

You can include files from app/assets or from the public folder with javascript_include_tag. The subtle difference that tells rails how to build the path correctly is a single slash at the beginning of the path:

<%= javascript_include_tag('ckeditor/config') %> # for assets/ckeditor/config.js
<%= javascript_include_tag('/ckeditor/ckeditor') %> # for public/ckeditor/ckeditor.js

This also applies to stylesheet_link_tag.

Note that when you refer to a Javascript or stylesheet in /assets you need to add it to [the list of asse...

List RubyGems binary version for all installed Ruby versions

rbenv

To check which rubygems versions your different rbenv rubys are using, you can use this small bash script:

for i in $(rbenv versions --bare); do rbenv shell "${i}"; echo -n "ruby ${i} has gem version: "; gem -v; done

RVM

rvm all do gem -v

ActiveRecord: scoped `validates_uniqueness_of` allows one null value per scope

As you most likely know validates_uniqness_of :foreign_id does not allow nil values by default.

To allow nil one has to set the :allow_nil => true option.

Very unexpected scoping this validation will not raise an error if foreign_id set to nil for the first created record of this kind.

validates_uniqueness_of :foreign_id, :scope => :another_column # allows foreign_id to be nil

Without a validation for presence of foreign_id now unusual records could be created.

How to deal with 'parent id missing' error in nested forms

tl;dr

  • Use form models to handle this problem
  • Or soften the validation to validates_presence_of :parent

Usually you would validate presence of parent object id, like in this example:

class Parent < ActiveRecord::Base
  has_many :nested, :inverse_of => :parent
  accepts_nested_attributes_for :nested
end

class Nested < ActiveRecord::Base
  belongs_to :parent
  validates_presence_of :parent_id # <- 
end

With the parent already persisted creating nesteds still works fine.

But one will encounter a *'parent id missing' er...

How to silence thin boot messages

Each time thin boots, it prints a boot message :

Thin web server (v1.6.3 codename Protein Powder)
Maximum connections set to 1024
Listening on localhost:36309, CTRL+C to stop

If you are running parallel tests with thin, this will clutter you output. Disable thin logging with these lines:

# e.g. in features/support/thin.rb

require 'thin'
Thin::Logging.silent = true

Note that this disables all logging in tests. Instead, you also might set a different logger with `Thin::Loggi...

Long cards: Directly jump from a paragraph to the same paragraph in the editor

If you hover over the text of a card, you will now see EDIT links at the top right corner of each block.

This link will open the card editor and scroll the editor to this very paragraph. The cursor caret will sit on the first character of that paragraph.

This should help making small changes to longer cards.