Asset Pipeline Basics

The Rails asset pipeline improves delivery of application assets (javascripts, stylesheets, images, fonts). Here are some basic facts about its inner workings.

No magic

Manifests are the handle on your assets:

app/assets/stylesheets/application.css # use via: stylesheet_link_tag 'application'

The asset pipeline only considers files you explicitly require within your manifest files. The most common directives used in manifests are require some/file and require_tree some/directory. Paths may be **relative to the current director...

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 element.is(':visible')) you may end up with "page flickering" or scroll offset changes.

You can hook to the end of a digest cycle to avoid that.

The following is basically straight from the docs, but pretty awkward to use. Do it...

LibreOffice Writer prints text frames as black areas

To fix this:

  • Right-click on the frame
  • Select Frame...
  • Open Background
  • Set As to "Color"
  • Set the background color to "No fill"

Install or update Chromedriver on Linux

Option 0: Download from the official page (preferred)

Chromedriver must be available in your path. You can add ~/bin to your path like this:

echo "export PATH=$PATH:$HOME/bin" >> $HOME/.bash_profile

If you're also using Geordi, disable automatic updating of chromedriver in ~/.config/geordi/global.yml:

a...

Enqueue sidekiq jobs dynamically

Sidekiq::Client.push('class' => 'WorkerClass', 'args' => [11, 5, 1993])

is equivalent to

WorkerClass.perform_async(11, 5, 1993)

Resolving Angular not updating an image src when ng-src is empty

The Angular ngSrc directive serves to properly set an image src via Angular. As anything in Angular, it updates the image as soon as the contained Angular expression changes. However, when the ng-src attribute is empty, Angular will not empty the src attribute. To overcome this, use the trick below.

<img ng-src="{{ element.image || '//:0' }}" />

Background

The ngSrc directive explicitly returns when the attribute value is falsy. As a workaround, set a "blank" image src when the image is empty. As [somebody ...

vague puppet error messages with broken yaml files

If you get one of this errors:

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: (<unknown>): found character that cannot start any token while scanning for the next token at line 1297 column 3
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: undefined method `empty?' for nil:NilClass at /etc/puppet/environments/production/manifests/nodes.pp:1 on node example.makandra.de
Warning: ...

tel_to Rails helper for linking phone numbers

When putting phone numbers into web pages, you should use tel: links so smartphone users can click those numbers to call someone.

Here is a small helper method that you can use to simplify this:

def tel_to(text)
  groups = text.to_s.scan(/(?:^\+)?\d+/)
  link_to text, "tel:#{groups.join '-'}"
end

This will allow you to use human-readable numbers and get clean links:

>> tel_to '(01234) 555 6789'
=> <a href="tel:01234-555-6789">(01234) 555 6789</a>

^
>> tel_to '+1 555 123-456'
=> <a href="tel:+1-555-123-45...

Rubymine 7: Howto disable backspace deletes lines instead of whitespaces

RubyMine 7.1:

Settings -> Editor -> General -> Smart Keys -> Unindent -> To nearest indent position

RubyMine 7.0:

Settings -> Editor -> General -> Smart Keys -> Backspace smart indent -> uncheck

Bower complains about missing NodeJS on Ubuntu

If bower complains about a missing node binary, do not install Ubuntu's node package.

Instead, you need to create a symlink that points to the binary one of the nodejs package:

sudo ln -s /usr/bin/nodejs /usr/bin/node

You probably already installed NodeJS. In case you did not:

sudo apt-get install nodejs

If you already installed the node Ubuntu package, bower will just do nothing (i.e. not show any input, or respond to any switches) and you need to uninstall that package first.

Upgrading a Rails 3.2 application to Ruby 2.1 is really easy

Upgrading from Ruby 1.8.7 to 2.1.2 took me an hour for a medium-sized application. It involved hardly any changes except

  • removing the occasional monkey patch where I had backported functionality from modern Rubies
  • Migrating from require to require_relative where I loaded RSpec factories in Cucumber's env.rb (the Rails application root is no longer in the load path by default)
  • replacing the old debugger with byebug
  • removing sytem_timer from Gemfile (see [this SO thread](http://stackoverflow.com/questions/7850216/how-to-inst...

Deutsche Bahn: Show details of past rides

On your credit card summary, you will find order numbers of rides with Deutsche Bahn ("DB BAHN A-NR XYZ123")

If you need to find out details about the ride, have a look at that: https://fahrkarten.bahn.de/privatkunde/start/start.post?scope=bahnatsuche&lang=de

How to (possibly) fix Google Calendar in Thunderbird (Lightning) on Ubuntu

Google Calendar integration into Thunderbird suddenly did not work any more for me. Thunderbird kept asking me for my password to access calendars, but did not show them when given the correct credentials. Instead, calendars in the list got the famous "yellow triangle".

I got it working again doing the following.

  1. Remove the Ubuntu packages the "Lightning" and "Google Calendar Provider" Thunderbird addons:
    ^
    sudo apt-get remove xul-ext-gdata-provider xul-ext-lightning

  2. Restart Thunderbird

  3. Install the addons using Thu...

PSA: Dont allow private gems to be pushed to rubygems.org

If you make a gem with Bundler, you will get a rake release task that will instantly publish your gem to rubygems.org for all the world to admire. For private gems this is very bad.

To make sure this cannot happen, rubygems 2.2+ allows you to restrict eligible push hosts:

Gem::Specification.new 'my_gem', '1.0' do |s|
  # ...
  s.metadata['allowed_push_host'] = 'https://gems.my-company.example'
end

In case you already messed up, [follow these instructions to get your gem removed](http://help.rubygems.org/kb/rubygems/removing-an-a...

Downgrade Bundler in RVM

Confusingly, RVM installs the bundler gem into the @global gemset, which is available to all gemsets and Rubies.

You can get around this and install a particular bundler version like this:

rvm @global do gem uninstall bundler
rvm @global do gem install bundler -v 1.6.5