How to checkout submodules in Gitlab CI

Accessing other repositories in Gitlab CI is not straight forward, since the access rights of the current pipeline might not be sufficient enough.

One approach is to use project access tokens and clone the repositories via HTTPS.

  • Create a project access token for all submodules you want to have access to with the setting read_repository
  • Add the secrets as environment variable to the main project you want to have access to submodules:
    • Protected false ...

ActionMailer sometimes breaks e-mails with multiple recipients in Rails 2

The ActionMailer in Rails 2 depends on a buggy version of TMail, which sometimes inserts a blank line into the mail header when sending a mail to multiple recipients. This makes the header end prematurely.

The reason why this is not exploding in your face all the time is that when you are relaying your e-mail through an MTA like Exim, it will fix this for you.

Fix for Rails if you don't have an awesome MTA

TMail is no longer maintained. The bug is fixed...

Security fixes for Rails 2.3

Last week saw a security issue with rails 2.3 that required a fix. While an official patch was provided, the 2.3 branch is no longer maintained. So we forked it.

(I'm sure there are already 100 other forks doing absolutely the same, but they are not very easily discoverable.)

To use our fork, change the gem "rails"... line in your Gemfile to this:

gem 'rails', :git => 'https://github.com/makandra/rails.git', :branch => '2-3-fixes'

The intent is to make as few changes to the f...

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

Capistrano: Bundler stalls and asks for "Username"

Given you use Capistrano together with bundler to automatically install your gems when deploying.

I recently had the problem that Capistrano stalled like this:

[err :: host.name.tld] Username:

It turned out that I this originated from GitHub. We had a gem in our Gemfile that explicitly pointed to a GitHub URL like that:

gem 'foogem', :git => 'https://github.com/blubb/foogem.git'

The URL was returning a 404 which caused the problems. You have to get another gem or point to a fork on GitHub.

Improved gitpt now part of geordi

Our gitpt script to generate git commits from Pivotal Tracker stories has been tweaked and polished and is now part of the geordi gem.

Install the freshly released version 0.7 now:

gem install geordi

This update will bring you commit with an initial "setup wizard" (that asks for your PT API key and initials) and prettier output: stories are colored by their state and thos...

Using rbenv on Ubuntu 18.04+

We will be installing rbenv and ruby-build from our own fork, not from the Ubuntu sources.

Installing rbenv

  1. Install rbenv:

    git clone https://github.com/rbenv/rbenv.git ~/.rbenv
    

    For Bash:

    echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
    echo 'eval "$(rbenv init -)"' >> ~/.bashrc
    

    For ZSH:

    echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc
    echo 'eval "$(rbenv init -)"' >> ~/.zshrc
    

    Now reinitialize ...

Make Capistrano use SSH Key Forwarding

When deploying code with Capistrano (depending on your configuration) at some point Capistrano tries to check out code from your repository. In order to do so, Capistrano connects to your repository server from the application server you're deploying to with SSH. For this connection you can use two SSH keys:

  • the user's ~/.ssh/id_rsa [default]
  • the very same key you used for connecting to the application server - forwarded automatically to the git repository.

If you prefer the second way, add this to deploy.rb:

ssh_options[:forwar...

The new Modularity 2 syntax

We have released Modularity 2. It has many incompatible changes. See below for a script to migrate your applications automatically.

There is no does method anymore

We now use traits with the vanilla include method:

class Article < ActiveRecord::Base
  include DoesTrashable
end

When your trait has parameters, use square brackets:

class Article < ActiveRecord::Base
  include DoesStripFields[:name, :brand]
end

Note how you ...

How to install the date_performance gem

sudo gem install zip
git clone git://github.com/rtomayko/date-performance.git
cd date-performance
rake package:build
cd dist
sudo gem install --no-ri --no-rdoc date-performance-0.4.7.gem

Dotfiles: Keep your linux configuration on github

Some folks have started to keep their linux configuration in a git repository called "dotfiles". This sounds like a good idea.

here are mine

The idea is to keep all config files in a ~/.dotfiles git repository, and symlink these files to all relevant places. This happens automatically with a rake task.

Yarn: How to recognize that you are using a different node version than your colleagues

The issue in this card can occur if the node_modules directory is checked into your Git repository. We usually recommend to exclude node_modules from version control.

In any case you should document which version of node to use in your project in a .nvmrc file.


I saw a strange behaviour after we introduced webpack in one of our projects and finally found out the reason: The person who committed the files used a node version that is older than mine.

Every time I wanted to run my rai...

Rails - Multi Language with Fast_Gettext

  • sudo gem install gettext --no-ri --no-rdoc
  • sudo gem install fast_gettext --no-ri --no-rdoc
  • script/plugin install git://github.com/grosser/gettext_i18n_rails.git (didn't work as gem)
  • environment.rb: see code example at the bottom
  • if this is your first translation: cp locale/app.pot locale/de/app.po for every locale you want to use
  • use method "_" like _('text') in your rails code
  • run rake gettext:find to let GetText find all translations used
  • translate messages in 'locale/de/app.po' (leave msgstr blank and ms...

Installing Ruby <= 2.3 on Ubuntu 20.04+

Installing old Rubies (<= 2.3) with a standard rbenv + ruby-build is no longer possible on Ubuntu 20.04. This is because those Rubies depend on OpenSSL 1.0 which is no longer shipped with current Ubuntus.

We have forked ruby-build with a workaround that makes it compile and statically link the latest OpenSSL 1.0 version. This works on Ubuntu 20.04, as well as on Ubuntu 18.04.

To switch to our fork of ruby-build, update ruby-build like this

git -C ~/.rbenv/plugins/ruby-build remote add makandra...

makandra/gemika: Helpers for testing Ruby gems

We have released a new library Gemika to help test a gem against multiple versions of Ruby, gem dependencies and database types.

Here's what Gemika can give your test's development setup (all features are opt-in):

  • Test one codebase against multiple sets of gem dependency sets (e.g. Rails 4.2, Rails 5.0).
  • Test one codebase against multiple Ruby versions (e.g. Ruby 2.1.8, Ruby 2.3.1).
  • Test one codebase against multiple database types (currently MySQL or PostgreSQL).
  • Compute a matrix of all possib...

How to fix: undefined method `specifications' (caused by RubyGems 1.8)

Sometimes, when running a rake task, RubyGems 1.8.5 raises an error:

rake aborted!
undefined method `specifications' for "/usr/lib/ruby/gems/1.8":String

This has been fixed since May 31 but is still not available as a new RubyGems version.

Either wait for a new version to eventually come out, downgrade to some really old version (1.6.2 works for some) or apply the fix manually:

  • Find your rubygems.rb -- mine was located at `/usr/local/lib/sit...

Geordi 2.7.0 released

  • Fixed #68: The "cucumber" command now fails early when @solo features fail.
  • Added: The "setup" command now prints the db adapter when prompting db credentials.
  • Fixed #71: When used without staged changes, the "commit" command will print a warning and create an empty commit. Any arguments to the command are forwarded to Git.
  • Fixed: The "commit" command will not print the extra message any more.
  • Added: The "commit" command prints a (progre...

Geordi 1.0 released

Geordi 1.0 features a command line application geordi, that holds most of Geordi's previous commands.

New features

  • command help and usage examples right within geordi (geordi help and geordi help <command>)

  • quick command access: type just the first few letters of a command, e.g. geordi rs or geordi dev[server]

  • command dependencies, e.g. geordi rspec invokes geordi bundle-install (which bundles only if needed)

  • no cluttered /usr/bin, but all commands in one handy tool

  • template for easily adding new...

Test a gem in multiple versions of Rails

Plugins (and gems) are typically tested using a complete sample rails application that lives in the spec folder of the plugin. If your gem is supposed to work with multiple versions of Rails, you might want to use to separate apps - one for each rails version.

For best practice examples that give you full coverage with minimal repitition of code, check out our gems has_defaults and assignable_values. In particular, take a look at:

  • Multiple `sp...

Concurrent Tests

Install gem and plugin

sudo gem install parallel
script/plugin install git://github.com/grosser/parallel_tests.git

Adapt config/database.yml

test:
  database: xxx_test<%= ENV['TEST_ENV_NUMBER'] %>

Create test databases

script/dbconsole -p
CREATE DATABASE `xxx_test2`;
...

Generate RSpec files

script/generate rspec

(you'll probably only let it overwrite files in script/)

Prepare test databases...

Bookmarklet to generate a commit message with Pivotal Tracker story ID and title

For clarity and traceability, your commit messages should include the ID and title of the Pivotal Tracker story you're working on. For example:

[#12345] Add Google Maps to user profiles
Optional further commit messages in the body

Also see Howto: Write a proper git commit message

To quickly generate such commit messages, add a new link "Commit" to your bookmarks and use the following Javascript as the link URL:

javascript:(function() { ...

Rbenv: How to remove a gem installed from a Github source

Normally you can list all gems of the current ruby version with gem list, which also includes the gems of you Gemfile. These can be uninstalled with gem uninstall gemname.

List and uninstall a gem installed via Bundler from Github

This does not work for gems installed directly from Github. They do not appear in gem list.

Show all gems installed via Github by bundler:

ls ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/bundler/

Remove a gem installed via Github by Bundler:

rm -rf ~/.rbenv/versions/2.4.1/lib/ruby/gems/2....

Fix Capistrano warnings: Missing public directories

I got these warnings while deploying a Rails 3.2 app with asset pipeline enabled:

*** [err :: host.tld] find: `/opt/www/hollyapp.com/releases/20120503115342/public/images': No such file or directory
*** [err :: host.tld] find: `/opt/www/hollyapp.com/releases/20120503115342/public/stylesheets': No such file or directory
*** [err :: host.tld] find: `/opt/www/hollyapp.com/releases/20120503115342/public/javascripts': No such file or directory

Folders like public/javascripts might not exist if you're using the asset pipeline (...

Restore changes, even from deleted files, with RubyMines "Local History"-Feature

Sometimes, due to git or other "accidents", important files get deleted or overwritten.

At a state when even Ctrl+Z doesn't work anymore, you maybe can rescue your files with RubyMines "Local History"-Feature!

To do this try the following:

  • If the file got deleted, recreate a new empty file with the same name on the exact same place
  • Open that file in the editor
  • Go to RubyMine and click on VCS -> Local History -> Show History
  • In the now open window, you should see all greater changes made to the File, even before it got deleted/temp...