Debugging cucumber feature with javascript + firefox vnc

TL;DR Debugging problems with javascript errors in cucumber tests is sometimes easier in the browser. Run the test, stop at the problematic point (with Then pause from Spreewald 1.7+) and open VNC for Firefox.

Features:

Howto: Free disk space when /boot is full

Easy mode

This method will remove automatically installed packages that no other packages depend on any more. This, of course, includes obsolete kernel versions, with the explicit exception of the currently running kernel, the kernel version that was installed on the system before that and, of course, the latest updated version of the kernel. However, it will also remove any and all other packages that have been marked as installed automatically but have no other packages depending on them. This could lead to unexpected removal of packag...

How to inspect really large directories

When a directory has more than a few thousand entries, ls will start taking really long to list its content. Reason for this is that ls by default a) sorts the file names and b) prints them in columns. For both, it needs to know (thus load into memory) the whole list of files before it can start printing anything.

By disabling sorting and columns, you get a lean, superfast ls that prints "live" as it reads:

$> ls -f -1
file1
file2
...
file9999
file10000
file10001
...

List of handy Chrome plugins

These are Chrome plugins that proved useful at makandra. Each is the best-in-class.

Dimensions

Auto-measure distances by moving your mouse.

Google Analytics Debugger

See details about Google Analytics events that you trigger on a page. Useful for debugging on production sites.

[JSON Formatter](https://chrome.google.com/webstore/detail/json-for...

Browsers have built-in pretty printing for JSON

This pretty-prints a JSON object, with two spaces of indentation:

JSON.stringify(object, null, 2)

Building web applications: Beyond the happy path

When building a web application, one is tempted to claim it "done" too early. Make sure you check this list.

Different screen sizes and browsers

Desktops, tablets and mobile devices have all different screen resolutions. Does your design work on each of them?

  • Choose which browsers to support. Make sure the page looks OK, is usable and working in these browsers.
  • Use @media queries to build a responsive design
    • If you do not suppo...

Testing terminal output with RSpec

When testing Ruby code that prints something to the terminal, you can test that output.
Since RSpec 3.0 there is a very convenient way to do that.

Anything that writes to stdout (like puts or print) can be captured like this:

expect { something }.to output("hello\n").to_stdout

Testing stderr works in a similar fashion:

expect { something }.to output("something went wrogn\n").to_stderr

Hint: Use heredoc to test multi-line output.

expect { something }.to output(<<-MESSAGE.strip_heredoc).to_stdout...

Bitmap to Vector Converter

Automatically convert bitmap images like JPEGs, GIFs and PNGs to the crisp, clean, scalable vector art of EPS, SVG, and PDF with the world's best auto-tracing software.

It's true, it does a great job.

Linux: Open a file with the default application

If you are on a Linux shell and want to open a file with whatever default application is configured for that type, this often works:

xdg-open Quote.odt
xdg-open invoice.pdf
xdg-open index.html

Pro Tip

Make an alias so you have a simpler API (like Mac OS): alias open=xdg-open or alias x=xdg-open.

Background

You can choose your "Default applications" via UI in the Ubuntu "Settings" application (gnome-control-center). This is just a very rough setting (e.g. open Photos with Shotwell Viewer).

If a certain file...

netstat: Sum open connections by IP (and sort it)

The following sums up all connections (ESTABLISHED, TIME_WAIT, FIN_WAIT, etc.) and sorts it:

netstat -n | awk ' $5 ~ /^[0-9]/ {print $5}' | cut -d: -f1 | sort | uniq -c | sort -n

Works on FreeBSD and Linux.

Geordi 1.3 released

Changes:

  • Geordi is now (partially) tested with Cucumber. Yay!
  • geordi cucumber supports a new @solo tag. Scenarios tagged with @solo will be excluded from parallel runs, and run sequentially in a second run
  • Support for Capistrano 2 AND 3 (will deploy without :migrations on Capistrano 3)
  • Now requires a .firefox-version file to set up a test firefox. By default now uses the system Firefox/a test Chrome/whatever and doesn't print warnings any more.
  • geordi deploy --no-migrations (aliased -M): Deploy with `cap ...

bash: print columns / a table

Ever wondered how you can create a simple table output in bash? You can use the tool column for creating a simple table output.

Column gives you the possibility to indent text accurate to the same level. Pipe output to column -t (maybe configure the delimeter with -s) and see the magic happening.

detailed example

I needed to separate a list of databases and their corresponding size with a pipe symbol: |
Here is a example list.txt:

DB	Size_in_MB
foobar	11011.2
barfoo	4582.9
donkey	4220.8
shoryuken	555.9
hadouken	220.0
k...

find out which processes using swap

Wondering which processes are placed in your swap you can use this bash oneliner:

for file in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done | sort -k 2 -n -r

You will see the swap usage of each process sorted by the highes amount of swap usage.

Please don't forget that swap usage of a process isn't an indicator for high memory usage of this process but for the frequency of access or activity of it. The kernel tries to avoid swapping pages which were recently accessed.

Also you should notic...

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...

get haproxy stats/informations via socat

You can configure a stat socket for haproxy in the global section of the configuration file:

global
  daemon
  maxconn 999
  user foobar
  stats socket /var/run/haproxy.stat  # this is the line you want to configure

You need socat to query data from this socket.

After installing socat and reconfiguring haproxy you can use this socket to query data from it:

  • show informations like haproxy version, PID, current connections, session rates, tasks, etc..

    echo "show info" | socat unix-connect:/var/run/haproxy.stat stdio
    

...

Sending TCP keepalives in Ruby

When you make a simple TCP connection to a remote server (like telnet), your client won't normally notice when the connection is unexpectly severed on the remote side. E.g. if someone would disconnect a network cable from the server you're connected to, no client would notice. It would simply look like nothing is being sent.

You can detect remote connection loss by configuring your client socket to send TCP keepalive signals after some period of inactivity. If those signals are not acknowledged by the other side, your client will terminat...

Matching unicode characters in a Ruby (1.9+) regexp

On Ruby 1.9+, standard ruby character classes like \w, \d will only match 7-Bit ASCII characters:

"foo" =~ /\w+/   # matches "foo"
"füü" =~ /\w+/   # matches "f", ü is not 7-Bit ASCII

There is a collection of character classes that will match unicode characters. From the documentation:

  • /[[:alnum:]]/ Alphabetic and numeric character
  • /[[:alpha:]]/ Alphabetic character
  • /[[:blank:]]/ Space or tab
  • /[[:cntrl:]]/ Control character
  • /[[:digit:]]/ Digit
  • /[[:graph:]]/ Non-blank character (excludes spaces...

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.

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...

Parallel Rspec with RTeX

Running projects parallel makes some trouble with PDF generation. Use geordi rspec spec to force sequential tests for the whole application or failed specs only.


geordi rspec
RTeX::Document::GenerationError in '...'
Could not find result PDF document.pdf after generation.
Check .../document.log

The document will show you, that RTeX tries to generate a PDF document out of a HTML file, which won't work.

Make timestamp of dmesg in Ubuntu human readable

dmesg shows the kernel ring buffer containing low-level system messages.
Per default, dmesg shows a timestamp:

12:59:26 fnordomator ~ > dmesg | tail
[101925.211846] usb 2-1.1: USB disconnect, device number 16
[110486.855788] usb 2-1.1: new high-speed USB device number 17 using ehci_hcd

If you're a human, use dmesg -T to print the timestamp human readable:

12:59:31 fnordomator ~ > dmesg -T | tail
[Di Apr 21 12:43:16 2015] usb 2-1.1: USB disconnect, device number 16
[Di Apr 21 15:05:57 2015] usb 2-1.1: new hig...

RSpec: Tagging examples and example groups

In RSpec you can tag examples or example groups with any tags you like simply by saying

describe ReportCreator, slow: true do
  # ..
end

describe ReportCreator do
  it 'generates reports', slow: true do
    # ...
  end
end

You can then only run examples with these tags.

rspec --tag slow
rspec -t slow

# Using the parallel_tests gem
rake "parallel:spec[,,--tag slow]"

Or you can run all examples except the ones with a certain tag:

rspec --tag ~slow # note the ~
rspec -t ~slow

# Using the parallel_tests gem
r...

Fontawesome 4+ icon naming conventions

Fontawesome 4 has introduced new naming conventions that make it easy to retrieve variants of a given icon.

The format is:

fa-[name]-[alt]-[shape]-[o]-[direction]

Note that this is a naming convention which doesn't imply there's an icon for any combination of tags.

name

The name of the icon, e.g. comment, print, bookmark etc. See the full list.

alt

An alternative icon.

shape

The icon inside a circle or square.

o

An outlined ...

AngularJS Cheat Sheet (PDF)

This cheat sheet ... aims at providing a quick reference to
the most commonly used features in AngularJS.