Make custom web font available within CKEditor content

  1. Make your custom web font available

  2. Add to ckeditor/config.js

    CKEDITOR.editorConfig = function(config) {
      config.contentsCss = [
        '/assets/myCkeditorStyles.css', // any other file to encapsulate custom styles
        '/assets/myFontFaceTags.css'  
      ];
    }
    

It's not enough to provide the font face tags within your public folder. You have to explixitly call it within the ckeditor/config.js.

...

How to call overwritten methods of parent classes in Backbone.js

When you are working with Backbone models and inheritance, at some point you want to overwrite inherited methods but call the parent's implementation, too.
In JavaScript, there is no simple "super" method like in Ruby -- so here is how to do it with Backbone.

Example

BaseClass = Backbone.Model.extend({
  initialize: function(options) {
    console.log(options.baseInfo);
  }
});

MyClass = BaseClass.extend({
  initialize: function(options) {
    console.log(options.myInfo);
  }
});

ne...

Checking the character length of a text containing markup (e.g. WSYIWYG)

If you have a text that is edited by WSYIWYG-Editor but want some length checking nevertheless, you need to strip all tags and then the special characters:

  def hard_sanitize(text)
    ActionController::Base.helpers.strip_tags(text).gsub(/[^[:word:]]+/, " ")
  end
   :001 > hard_sanitize("This is <strong>beautiful</strong> <h1>markup<h1>")
   => "This is beautiful markup" 

If you allready have nokogiri on board, you can use that as well, though it has no extra benefit:

   :001 > Nokogiri::HTML("This is <strong>beau...

Stripping all non-word-characters (a.k.a \W) and preserve diacritics (a.k.a Umlaute) in utf-8

Sometimes you want to strip a text of every special char. If you use \W, the result might not be what you wanted:

    irb> "Eine längliche Kristall §$&&%& Lampe über dem Esstisch verschönert jedes noch so kahle   \n  Speisezimmer".gsub(/\W+/, " ")
    => "Eine l ngliche Kristall Lampe ber dem Esstisch versch nert jedes noch so kahle Speisezimmer"

You need to use "[^[:word:]]", which is magically given to us by the spirit of the community

    irb> "Eine längliche Kristall §$&&%& ...

Resolving Element cannot be scrolled into view (Selenium::WebDriver::Error::MoveTargetOutOfBoundsError) on Mavericks

After I upgraded to Mac OS X Mavericks, I regularly got this error message when running Cucumber features with Selenium:

Element cannot be scrolled into view:[object XrayWrapper [object HTMLInputElement]] (Selenium::WebDriver::Error::MoveTargetOutOfBoundsError)

I had the Terminal window running the test on my secondary screen, whereas the Selenium-webdriven Firefox always started on my primary one. Now if I had focused the secondary screen when running the tests, Selenium could not start Firefox and switch to it (probably because t...

Ruby number formatting: only show decimals if there are any

Warning: Because of (unclear) rounding issues and missing decimal places (see examples below),
do NOT use this when dealing with money. Use our amount helper instead.


In Ruby, you can easily format strings using % (short for Kernel#sprintf):

'%.2f' % 1.23456 #=> 1.23
'%.2f' % 2 #=> 2.00

However, what if you only want the decimals to be shown if they matter? There is g! It will limit the total number of displayed digits, disregarding...

[Openstack] "Failed to schedule_prep_resize: No valid host was found." when trying to resize an instance

If you get this error while trying to resize an openstack instance:

# nova resize fooinstance 16 --poll

==> /var/log/nova/nova-scheduler.log <==
2014-01-30 17:40:34 WARNING nova.scheduler.manager [req-aaaaaaa-bbbb-cccc-dddd-1ed34b64adef bajd7394hftgs71dba31d642342effa0f bfe2djhg6538sg384jgb82ks070ce0b] Failed to schedule_prep_resize: No valid host was found. 
2014-01-30 17:40:34 WARNING nova.scheduler.manager [req-aaaaaaa-bbbb-cccc-dddd-1ed34b64adef bajd7394hftgs71dba31d642342effa0f bfe2djhg6538sg384jgb82ks070ce0b] Setting ...

rbenv: How to switch to another Ruby version (temporarily, per project, or globally)

Unlike RVM, rbenv does not offer a command like rvm use. By default, it respects your project's .ruby-version file.

If you need to change manually, you have several options:

  1. rbenv shell
  2. rbenv local
  3. rbenv global

You probably want rbenv shell.

Temporarily: rbenv shell

Changes your Ruby version on your current shell:

$ ruby -v
ruby 1.9.3p484 (...)

$ rbenv shell 2.0.0-p353
$ ruby -v
ruby 2.0.0p353 (...)

Background: This actually sets the RBENV_VERSION environment variable in your termi...

Bash: Setting the title of your terminal tab

If your terminal has many tabs, you'll want to keep them organized. To change their title from the prompt, run this function:

function tab_title {
  if [ -z "$1" ]
  then
    title=${PWD##*/} # current directory
  else
    title=$1 # first param
  fi
  echo -n -e "\033]0;$title\007"
}

Put it into your ~/.bashrc to have it always available. Adjust to your needs.

Usage

$> tab_title
# title set to the current directory's name
$> tab_title new_title
# title set to "new_title"

Auto-setting the title
=================...