Unindent HEREDOCs in Ruby 2.3

In Ruby 2.3 you can use <<~ instead of <<- to automatically remove indentation from a HEREDOCs:

str = <<~MESSAGE
  Hello Universe!
  This is me.
             Bye!
MESSAGE

str will now be:

Hello Universe!
This is me.
           Bye!

Git: Keep your repository tidy

When you're using feature branches, they will stack up if you don't delete them after the merge to master. Here's how to tidy them up.

Delete feature branches

Find already-merged branches by running

# On branch master
git branch --merged

You may safely delete each of the listed branches, because they point to commits that are contained in the history of your current branch (i.e. master).

git branch -d my/feature-branch # Delete feature branch locally
git push origin :my/feature-branch # Push *nothi...

How to open a new tab with Selenium

Until recently, you could open a new tab via window.open when using execute_script in Selenium tests. It no longer works in Chrome (will show a "popup blocked" notification).

This is because browsers usually block window.open unless the user interacted with an element for security reasons. I am not sure why it did work via Selenium before.

Here is an approach that will insert a link into the page, and have Selenium click it:

path = "/your/path/here"
id = "helper_#{SecureRandom.hex(8)}"
execute_script <<-JAVASCRIPT
  ...

We have an Angular 1 styleguide for CoffeeScript

We will use this for new Angular code.

Consider the guide in "beta". Things will still refine, but the general structure should be final.

CSS: Select elements that contain another selector

CSS4 comes with :has. E.g. h1:has(b) would select all <h1> tags that contain a <b> tag.

This is implemented in no browser but the jQuery query engine already supports it as a custom extension.

How to encode or decode quoted-printable strings

E-mails are usually encoded using Quoted Printable. Here is how to decode or encode such strings.

You probably know Quoted Printable from e-mail bodies appearing in Rails logs, where =s become =3Ds in URLs, or where long lines are split up and trailed by = after each split.

Decode Quoted Printable

Decoding such strings is actually quite simple using plain Ruby:

"foo=3Dbar".unpack('M')[0]
# => "foo=bar"

Note that unpack will return an array. Our result is the 1st item.
...

Stop using bundle exec

Install this gem and stop using bundle exec or even Geordi's handy b. Yay!

nginx proxy_hide_header when used in multiple contextes

You can use proxy_hide_header in different contextes:

Syntax:	proxy_hide_header field;
Default:	 —
Context:	http, server, location

(from http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_hide_header)

But if you use it in multiple contexes only the "lowest" occurrences are used.

So if you specify it in the server and location context (even if you hide different header) only the proxy_hide_header in the location block are used.

Example:

server {
[...]
  proxy_hide_header X-Example;
[...]
  location / {
  ...

A collection of SVG Logos for developers

A collection of 700+ svg vector logos. The logos are optimized (removed duplicated paths / excessive groups / empty defs, linting, etc).
Almost 100 logos were recreated from rastered images #vectorized.

All logos appearing on the site are the property of their respective owners.

http://svgporn.com/

RSpec & Devise: How to sign in users in request specs

You know that Devise offers RSpec test helpers for controller specs. However, in request specs, they will not work.

Here is a solution for request specs, adapted from the Devise wiki. We will simply use Warden's test helpers -- you probably already load them for your Cucumber tests.

First, we define sign_in and sign_out methods. These will behave just like ...

Geordi: Running Selenium tests in a VNC buffer

Geordi now supports our solution for running Selenium tests without having Firefox or Chrome windows popping up all over your workspace.

This will stop Selenium windows from appearing on your desktop, but you can still inspect them when necessary.

Installation

Update geordi with gem install geordi.

Run geordi vnc --setup and follow the instructions.

Usage

geordi cucumber will automatically use VNC. Launchy will still open pages in the usual place.

geordi vnc will allow...

Asset pipeline: Precompile non-standard manifests

By default, only application.js, application.css and all non-JS/CSS files are precompiled into public/assets.

If you have asset manifests in non-standard locations, declare them in your config/application.rb:

config.assets.precompile += ['application/all.css', 'result/all.css', 'application/all.js', 'result/all.js']

This way you can also precompile files that do not have any manifest.

Beware ruby's var1 = var2 = "value" multiple assignment

This looks like it is safe to use:

2.2.1 :001 > a = b = "hello world"
"hello world"
2.2.1 :002 > a
"hello world"
2.2.1 :003 > b
"hello world"
2.2.1 :004 > b = " goodbye!"
" goodbye!"
2.2.1 :005 > a
"hello world"
2.2.1 :006 > b
" goodbye!"

But it isn't!

2.2.1 :010 > a = b = "hello world"
"hello world"
2.2.1 :011 > a
"hello world"
2.2.1 :012 > b
"hello world"
2.2.1 :013 > b << " goodbye!"
"hello world goodbye!"
2.2.1 :014 > a
"hello world goodbye!"
2.2.1 :015 > b
"hello world goodbye!"

What is happening when we do `a = b = ...

Upgrade from Ruby 1.8.7 to 2.1.5 – an incomplete guide

I recommend to go straight to 2.1.5+ without intermediate steps. Otherwhise you burden yourself with unnecessary work of encoding problems.

Issues you may encounter:

  • Set the ruby version within your .ruby-version file to 2.1.5
  • Remove gem ruby-debug and use e.g. byebug
  • Remove gem oniguruma
  • Remove gem fastercsv
  • Replace gem mysql with mysql2
  • Update gem capistrano 2.12.0 to ~>2.12 when bound for Ruby 1.8.7 and remove obsolete explicite Gemfile entries for net-scp and net-ssh if present.
  • Update gem `and...

You can now override all Spreewald steps with more specific versions

You can now define this step without Cucumber raising Cucumber::Ambiguous:

Then /^I should see "whatever I want"$/ do
  ...
end

This is available in Spreewald 1.5.0+.

Override Cucumber steps without an ambiguity error

Cucumber raises a Cucumber::Ambiguous if more than one step definitions match a step.

Our new cucumber_priority gem provides a way to mark step definitions as overridable, meaning that they can always be overshadowed by a more specific version without raising an error.

This gem is currently used by spreewald and cucumber_factory.

Marking step definiti...

Spreewald: Click on an element with a CSS selector

Spreewald 1.4.0 comes with this step:

When I click on the element ".sidebar"

We recommend to define a selector_for method in features/support/selectors.rb so you can refer to the selector in plain English:

When I click on the element for the sidebar

start tcpdump log on high traffic

Logging tcpdump output all the time can create a huge amount of data. This can be both: too much data size on HDD and tiring to analyze. You can run a script in a screen which checks out the packages transfered per second and start a tcpdump when the packages exceed a fixed number.

#!/usr/bin/env bash

interface=eth0
dumpdir=/tmp/
packet_threshold=5000
log_packets=100000

while /bin/true; do
  pkt_old=`grep $interface: /proc/net/dev | cut -d :  -f2 | awk '{ print $2 }'`
  sleep 1
  pkt_new=`grep $interface: /proc/net/dev | cut -d :  -f...

Spreewald: Check that a CSS selector is present on the current page

Spreewald 1.3.0 comes with these steps:

Then I should see an element ".panel"
Then I should not see an element ".sidebar"
Then I should see an element ".twitter-timeline"

We recommend to define a selector_for method in features/support/selectors.rb so you can refer to the selector in plain English:

Then I should see an element for a panel
Then I should not see an element for the sidebar
Then I should see an element for the Twitter timeline

Using the Bash in VI mode

Activate VI mode by running

set -o vi

Now use your Bash as if it were VI! Hit Esc to enter command mode, jump around with e, w, b, 0, $ etc. and edit just as you're used to.

Bash history is searched with /. See the linked cheat sheet for more hints.

Adjust cron jobs to allow full backtraces for rake tasks

As we get an exception notification, when a cron job fails, we wish to have the full backtrace in this mail. A rake task doesn't output the full backtrace by default, so you need the --backtrace option.

Trigger

You will find fail mails with a shortened backtrace

#[...]
Tasks: TOP => some_namespace:some_task
(See full trace by running task with --trace)

What rake wants from you
Running the rake task like rake some_namespace:some_task --backtrace

How this works with whenever
Define a own job_type and use it for r...

Git: Issues with Gemfile.lock

When there's a Gemfile.lock in your working directory that you cannot remove by either checkout, reset [--hard], stash, probably Rails' Spring is the culprit and not Bundler itself.

Fix

spring stop

The author of the linked Stackoverflow post supposes Spring re-writes the Gemfile.lock on change to ensure all Spring processes are using the same gem versions. Meh.

Instant Markdown previews from Vim

Live markdown previewer (with Github flavored syntax) for VIM.

Will open a preview in your browser and update automatically on each key press.