Add bookmarks to self-joined PDFs

  1. join pdfs like this with pdftk

Adapted from here:

  1. pdftk in.pdf dump_data > pdf_data.txt
  2. Edit pdf_data.txt like so (add or enhance Bookmark Section):
InfoBegin
InfoKey: Producer
InfoValue: Haru Free PDF Library 2.2.1
NumberOfPages: 1
BookmarkBegin
BookmarkTitle: Ein Bookmark, yay!
BookmarkLevel: 1
BookmarkPageNumber: 1
PageMediaBegin
PageMediaNumber: 1
PageMe...

Git rebase --onto

It seems like everyone needs their own explanation of how git rebase --onto works. Here's a very short one :) For details see the linked article.

git rebase --onto can be invoked with two or three arguments. With two arguments the general syntax looks like this:

git rebase --onto <newparent> <oldparent>

This will allow us to change the current parent <oldparent> to new one <newparent>.

git rebase --onto <newparent> <oldparent> <until>

Now we can change the old parent <oldparent> to new one <newparent>, but we...

Nice pattern for creating a new class in your rspec tests

Instead of defining a regular class, which would then be available to all tests, you can create a class within a let block like this:

let(:my_object) do
  my_class = Class.new(MyClass) do
    def do_stuff(data)
      # ...
    end
  end

  my_class.new
end

If you need more than one instance, you can of course also return the class and use it for multiple records:

let(:my_class) do
  Class.new(MyClass) do
    def do_stuff(data)
      # ...
    end
  end
end

let(:first_object) { myclass.new }
let(:second_object) { mycla...

Easily check for opposite of an existing matcher

If you want to ensure the opposite of a matcher you already have, you may define a negated matcher. This comes in handy if you want to chain expectations with .and and therefore can not easily use not_to.

spec/support/matchers.rb:

RSpec::Matchers.define_negated_matcher(:keep, :change)

Example usage:

expect { config.switch_quotation! }
  .to change { @other_quotation.reload.last_shown_at.today? }
    .from(false)
    .to(true)
  .and keep { @same_category_quotation.reload.last_shown_at }

(of course you can us...

How to set up a local Postgres database for Rails development with Ubuntu 20.04

Install and configure Postgres

  1. Install Postgres: sudo apt install postgresql

  2. Start the postgres console as postgres user so you can add a user with your linux' user name: sudo -u postgres psql

  3. Create a user with the same username as your linux user and the right to create databases: postgres=# CREATE USER judith WITH createdb superuser;
    More info in the postgres docs

  4. Check that the command succeeded by listing the users known to postgres: \du

    All toge...

SSH config with Proxy

You can use either ProxyJump or do it as hack with netcat. Using ProxyJump is far easier to understand and gives less options to shoot yourself in the foot.

ProxyJump (recommended)

Host via_proxyjump
  User judith
  HostName 10.55.0.189
  ProxyJump portal.my-site.de

# OR (with separate entry for the proxy host)

Host portal
  HostName portal.my-site.de
  User judith

Host via_proxyjump
  User judith
  HostName 10.55.0.189
  ProxyJump portal

ProxyCommand

Host portal
  HostName portal.my-site.de
  User judith

Hos...

DAMP vs DRY

It's a balance, not a contradiction

DAMP and DRY are not contradictory, rather they balance two different aspects of a code's maintainability. Maintainable code (code that is easy to change) is the ultimate goal here.
DAMP (Descriptive And Meaningful Phrases) promotes the readability of the code.

To maintain code, you first need to understand the code. To understand it, you have to read it. Consider for a moment how much time you spend reading code. It's a lot. DAMP increases maintainability by reducing the time necessary to read a...

How to enable chrome cast in chromium 80

Go to chrome://flags/. Search for "Load Media Router Component Extension". Set it to "Enabled" and restart Chromium. This did it for me. No more "no cast devices found"!

Test-PDF

The attached PDF may be used for testing (e.g. code that has to download a PDF).

Find process by port

lsof -i :3000
or
netstat -tulpn | grep 1025