Search_spinner
External content

Who broke the build?

Retaliation is a Jenkins CI build monitor that automatically coordinates a foam missile counter-attack against the developer who breaks the build. It does this by playing a pre-programmed control sequence to a USB Foam Missile Launcher to target the offending code monkey.

An ActiveRecord is invalid, but has no errors

Did you return false in a before_validation callback?

Print large PDFs as a poster

Pdfposter is a Python script that allows to convert large PDFs into a PDF with multiple pages that can be printed and turned into one big poster.

In Ubuntu, you can install it with
sudo apt-get install pdfposter

Scaling to the desired size is a bit cumbersome. If you want to split large.pdf, I suggest you run
pdfposter -vns 0.5 large.pdf larger.poster.pdf
which will tell you into how many pages the file would be split. Then simply tweak the -s value till you get the desired number of pages, and remove the -n to generate the r…

How to make a single check box (or image, etc) align vertically

Consider this HTML:
<div style="line-height: 42px">

</div>

Even though the surrounding container defines a line-height, which vertically centers its inline elements, the check box will be top aligned if it is the only element inside the container.

It will be aligned correctly if the HTML looks like this:
<div style="line-height: 42px">
foo
</div>

So the actual fix is to add some inline elements next to the check box. You could use a non-breaking space left a…

Grep the number of occurences in a file, counting multiple hits per line

This will output the number of matches lines – if a word appears more than once in a line, it’s not counted, though:

grep -c "something" filename

When you wish to count every hit, just trick grep by using sed:

sed 's/something/something\n/g' filename | grep -c "something"

Here you append a line break to each hit (which makes it live in its own row) and pipe the result into grep which can now count lines.

How to change the font in Sublime Text 2

Open up your “Base File.sublime-settings” (Preferences Menu → File Settings – User) in Sublime Text 2. Add entries for font_face, and optionally font_size, so it looks similar to this:

{
  "font_face": "Envy Code R",
  "font_size": 11.5
}

Cool: when you save the configuration file, changes will be applied instantly.

Downgrade Firefox 6 to Firefox 5 on Ubuntu

Note that if you plan to downgrade Firefox because your Selenium tests broke after a Firefox upgrade, there is a better way that doesn’t involve downgrading. Mozilla has stated that they will no longer provide security patches for any but the most recent versions of Firefox. So running an old Firefox should not be a long-term solution for anything.

If you still want to downgrade your Firefox for other reasons, here is how I downgraded my Fi…

Distance of time in what you like: days, months, years

Sometimes the Rails method distance_of_time_in_words is using too much magic.
When you need a time difference in a specific unit, use this method.

def distance_of_time_in(unit, from, to)
  if 1.respond_to? unit
    ((to - from) / 1.send(unit)).abs.round
  else
    raise ArgumentError, "#{unit} is not supported as unit"
  end
end

Remove the abs if you want the mathematical difference.

Best GitHub feature

When browsing a repository, pressing “t” allows you to quickly search for file names. Very awesome!

Go here to try it out.

Ruby GetText will eval scripts containing ActiveRecord classes

When the Ruby parser module of Ruby-GetText comes across a file in one of its search directories (e.g. lib/scripts/) and finds out that you are defining ActiveRecord classes inside it, it evaluates the whole file. Here is how to avoid that.

What’s happening?

Let’s say you have the following script which is only run once, manually, via script/runner:
# lib/scripts/doomsday.rb
class User < ActiveRecord::Base; end
User.destroy_all

In that case we w…

Solarized color scheme for Rubymine

If you want to use the (badly implemented!) solarized color scheme in your Rubymine IDE:

  1. Clone the IntelliJ IDEA port:

    git clone https://github.com/jkaving/intellij-colors-solarized.git

  2. Import the settings in Rubymine by chosing the above directory File -> Import Settings

  3. Change the color scheme in the settings (Ctrl-Alt-S) in Editor -> Colors & Fonts

Note that selecting a color scheme will also reset your previous editor font choice. You might want to change the font to [Envy Code R](http://damieng.com/blog/2008/05/2…

Solve issues with Samsung TV as computer screen

We have a big flat screen TV (Samsung LE46c650l1kxxu) in our conference room. Configuring it properly, we were encountering some issues.
This is a list of issues, providing a solution to each.

No sound with DVI/HDMI and separate audio
There are some inputs on the side of the TV. These will not work for split video and audio.
On the back are more inputs you might not have seen. Choose HDMI/DVI as video in and Audio in for HDMI/DVI as audio in. Do not use RCA audio input but the [T…

Prevent your Firefox from auto-updating

Note that if you plan to freeze your Firefox versions because your Selenium tests break whenever Firefox updates, there is a better way that lets you keep an up-to-date Firefox. Mozilla has stated that they will no longer provide security patches for any but the most recent versions of Firefox. So running an old Firefox should not be a long-term solution for anything.

If you still wish to disable the auto-update in Firefox, a poster in [thi…

External content

IE9 DELETES stuff

Kyle and I discovered some interesting IE9 behavior. Redirect responses from DELETE requests are followed with another DELETE

Random list of ActiveSupport goodies

I recently browsed through the ActiveSupport code and found some nice stuff I did not know about:

ActiveSupport::Callbacks
ActiveRecord-like callbacks, if you need callbacks in non ActiveRecord objects
ActiveSupport::MessageEncryptor
encrypt and decrypt ruby objects

[ActiveSupport::MessageVerifier](https://github.com/rails/rails/blob/master…

List sizes of MySQL databases

Do you wonder which databases are actually taking up how much space but only have one huge ibdata1 in your /var/lib/mysql and the directories inside your mysql data directory don’t represent the actual database sizes? This is for you!

Run from a mysql root console:

SELECT table_schema AS "Database name", SUM(data_length + index_length) / 1024 / 1024 AS "Size (MB)" FROM information_schema.TABLES GROUP BY table_schema;

This will get you a result like the following:

+----------------------+--------------+
| Database name    ...

Fix: FreeBSD is not able to connect to the network

This article from the FreeBSD Handbook suggests that editing /etc/rc.conf enables DHCP. Unfortunately, some times this seems not sufficient.

Try a reboot, or start the DHCP client manually with the command

dhclient <network adapter>

You can find a list of network adapters by running ifconfig. Examples are em0 or lo0.

Create RAID on Amazon EC2 EBS volumes

If you use Amazon AWS cloud services you definitively want to utilize software raid for IO intensive stuff such as database data directories and the like.

Here’s how you create it:

  • Create some EBS volumes within management console or
  • sudo mdadm --create -f /dev/md0 --chunk=256 --level 10 --raid-devices 4 /dev/sdf /dev/sdg /dev/sdh /dev/sdi
  • Create a fs on /dev/md0 using mkfs*-tools
  • As soon as this is running, you should do that:
    sudo mdadm –detail –scan » /etc/mdadm/mdadm.conf

Make sure the last line in `/etc/mdadm/md…

2727 cards