Google Material Design as Polymer components

The Paper elements are a set of UI elements that implement the material design system.

Sass function to set a color to an absolute hue

The adjust-hue function of Sass allows you to change a color's hue, but only relative to its current hue.

adjust-hue(#ffff00, 120)
// => #00ffff
adjust-hue(#444400, 120)
// => #004444

As you can see, we moved our yellow by 120° to cyan. \
But what if you want to move any color to a hue of 120° which is a nice shiny green?

Take this function:

@function set-hue($color, $target-hue)
  $current-hue: hue($color)
  $degree...

Skype 4.3 for Linux fixes group chats

Skype has been updated to 4.3 on Linux. This fixes group chat issues with non-linux clients.

If you have previously installed skype via ubuntu packages, you need to remove those fist via

sudo apt-get remove skype skype-bin

Note

Try to install the 32 bit version. In serveral cases this was the way that worked out.

Grab the installer here:

terminator keyboard shortcuts

When connecting to multiple (i.e. > 4) servers to dive into logfiles or do security updates, terminator is what you want.
There are several keyboard shortcuts available:

  • Ctrl-Shift-E: Split the view vertically.
  • Ctrl-Shift-O: Split the view horizontally.
  • Ctrl-Shift-P: Focus be active on the previous view.
  • Ctrl-Shift-N: Focus be active on the next view.
  • Ctrl-Shift-W: Close the view where the focus is on.
  • Ctrl-Shift-Q: Exit terminator.
  • Ctrl-Shift-X: Enlarge active window...

Rails Assets

Automatically builds gems from Bower packages (currently 1700 gems available). Packaged Javascript files are then automatically available in your asset pipeline manifests.

Why we're not using it

At makandra we made a choice to use bower-rails instead. While we believe Rubygems/Bundler to be superior to Javascript package managers, we wanted to use something with enough community momentum behind it that it won't go away in 10 years...

SudoSlider: a jQuery slider

SudoSlider is a simple yet powerful content slider that makes no (or very few) assumptions about your markup and is very customizable.

You can basically embed any HTML into the slides, so you can mix images, videos, texts, and other stuff.

Check out the demos.

Please note:

  • There is a ton to configure. Check the demos and read the docs.
  • It does not bring styles for prev/next links etc, so you need to style controls yourself (which I consider to b...

Working around OpenSSL::SSL::SSLErrors

If your requests blow up in Ruby or CURL, the server you're connecting to might only support requests with older SSL/TLS versions.

You might get an error like: OpenSSL::SSL::SSLError: SSL_connect SYSCALL returned=5 errno=0 state=unknown state

SSL Server Test

This SSL Server Test can help finding out which SSL/TLS versions the server can handle.

Ruby

In Ruby, you can teach Net::HTTP to use a specific SSL/TLS version.

uri = URI.parse(url)

ssl_options = {
   use_ssl: true,
   ssl_version...

whenever: Make runner commands use bundle exec

In whenever you can schedule Ruby code directly like so:

every 1.day, :at => '4:30 am' do
  runner "MyModel.task_to_run_at_four_thirty_in_the_morning"
end

Combined with the best practice to hide background tasks behind a single static methods you can test, this is probably preferable to defining additional Rake tasks.

Unfortunately when whenever register a runner command, it doesn't use bundle exec in the resulting crontab. This gets you errors like this:

`gem_original_require': no suc...

Material Design - Google design guidelines

Impressive set of design guidelines from Google.

shoulda-matcher methods not found in Rails 4.1

So you're getting an error message like the following, although your Gemfile lists shoulda-matchers and it has always worked:

NoMethodError:
  undefined method `allow_value' for #<RSpec::ExampleGroups::Person::Age:0x007feb239fa6a8>

This is due to Rails 4.1 (specifically, Spring) revealing a weak point of shoulda-matchers -- jonleighton explains why.

Solution

The solution is to follow [the gem's installation guide](https://github.com/thoughtbot/sh...

Telling Spring to watch certain directories/files

If you have some file or directory that should trigger a Spring reboot, tell Spring e.g. in config/spring.rb:

Spring.watch 'file.rb'
Spring.watch 'lib/templates'

However, Spring will silently drop paths that do not exist at the time calling #watch. Unless you restart Spring (thereby reloading the watch commands), it won't even watch them once they do exist.

Make sure the watchable paths exist before telling Spring to watch, e.g. with

FileUtils.touch 'file.rb'
FileUtils.mkdir_p 'lib/templates'
Spring.wa...

Device sizing and network throttling are coming to Chrome DevTools

See screenshot here.

This is great news because network throttling is very painful in Linux.

The features are already in Chrome Canary, so expect them to come to your Chrome sources soon.

How to test bundled applications using Aruba and Cucumber

Aruba is an extension to Cucumber that helps integration-testing command line tools.

When your tests involve a Rails test application, your tool's Bundler environment will shadow that of the test application. To fix this, just call unset_bundler_env_vars in a Cucumber Before block.

Previously suggested solution

Put the snippet below into your tool's features/support/env.rb -- now any command run through Aruba (e.g. via #run_simple) will have a clean Bundler envir...

Cucumber step to manually trigger javascript events in Selenium scenarios (using jQuery)

When you cannot make Selenium trigger events you rely on (e.g. a "change" event when filling in a form field), trigger it yourself using this step:

When /^I manually trigger a (".*?") event on (".*?")$/ do |event, selector|
  page.execute_script("jQuery(#{selector}).trigger(#{event})")
end

Note that this only triggers events that were registered through jQuery. Events registered through CSS or the native Javascript registry will not trigger.

Tearing Down Capybara Tests of AJAX Pages

An all-in-approach to fix the problem of pending AJAX requests dying in the browser when the server ends a test or switches scenarios.


We were able to work around this issue in most projects by doing this instead:

After '@javascript' do
  step 'I wait for the page to load'
end

ruby-concurrency/atomic · GitHub

Provides a value container that guarantees atomic updates to this value in a multi-threaded Ruby program.

Originally linked to:
ruby-concurrency/atomic (Deprecated)

Hover an element with Capybara < 2

You need this awkward command:

page.driver.browser.action.move_to(page.find(selector).native).perform

Note that there are better ways for newer Capybaras.

Ruby 2.1 returns a symbol when defining a method

Since Ruby 2.1, defining a method returns its name as a Symbol:

def foo() end             # => :foo
define_method :foo do end # => :foo

You can use this to do Python-like decorators like so:

private def foo; end 
memoize def foo; end 

Ruby 2.0 introduces keyword arguments

"Keyword arguments" allow naming method arguments (optionally setting a default value). By using the double-splat operator, you can collect additional options. Default values for standard arguments still work (see adjective).

def greet(name, adjective = 'happy', suffix: '!', count: 7, **options)
  greeting = options[:letter] ? 'Dear' : 'Hello'
  puts "#{greeting} #{adjective} #{name + suffix * count}"
end

Invoke the method like this:

greet('Otto', 'sad', suffix: '??', count: 9, include_blank: true)

In Ruby 2.1+,...

Assignable_Values 0.11.0 released

Introduces :include_old_value option to :assignable_xxx method.

Consul 0.12.0 released

Now supports Rails 4.1 and Ruby 2.1.

mattheworiordan/capybara-screenshot

Using this gem, whenever a Capybara test in Cucumber, Rspec or Minitest fails, the HTML for the failed page and a screenshot (when using capybara-webkit, Selenium or poltergeist) is saved into $APPLICATION_ROOT/tmp/capybara.

Link via Binärgewitter Podcast (German).

If Guard takes forever to start...

For me guard recently took a very long to start (as in "minutes"), because I had lots of images in public/system.

Upgrading the listen gem (which is a dependency) to 2.7.7 fixed this.

assignable_values 0.11.0 can return *intended* assignable values

As you know, assignable_values does not invalidate a record even when an attribute value becomes unassignable. See this example about songs:

class Song < ActiveRecord::Base
  belongs_to :artist
  belongs_to :record_label

  assignable_values_for :artist do
    record_label.artists
  end
end

We'll create two record labels with one artist each and create a song for one artist. When we change the song's record label, its artist is still valid.

makandra = RecordLabel.create! name: 'makandra records'
dominik...