Implementing social media "like" buttons: Everything you never wanted to know

So you client has asked you to implement a row of buttons to like the URL on Facebook, Twitter and Google+. Here are some things you should know about this.

0. Security considerations

Each "like" button is implemented by including a Javascript on your site. This means you are running fucking remote code on your page. You are giving Facebook, Twitter and Google+ full permission to e. g. copy user cookies. Check with your client if she is cool with that. Also note that if you're site is suggesting security by operating under HTTPS …

PostgreSQL cheat sheet for MySQL lamers

So you're switching to PostgreSQL from MySQL? Here is some help…

General hints on PostgreSQL

  • \? opens the command overview
  • \d lists things: \du lists users, \dt lists tables etc

Command comparison

Description MySQL command PostgreSQL equivalent
Connect to the database mysql -u $USERNAME -p sudo -u postgres psql
Show databases SHOW DATABASES; \l[ist]
Use/Connect to a database named 'some_database' USE some_database; \c some_dat…
Linked content

Output for custom migrations

When you're writing migrations that do more than changing tables (like, modify many records) you may want some output. In Rails > 3.1 you have two methods at hand: announce and say_with_time.

In the migration:

class AddUserToken < ActiveRecord::Migration

class User < ActiveRecod::Base; end

def up
add_column :users, :token, :string

announce "now generating tokens"
User.find_in_batches do |users|
  say_with_time "For users ##{} to ##{}" do
    users.each do |user|

Render a view from a model in Rails

In Rails 5 you can say:

  :template => 'users/index',
  :layout => 'my_layout',
  :assigns => { users: @users }

If a Request Environment is needed you can set attributes default attributes or initialize a new renderer in an explicit way (e.g. if you want to use users_url in the template):

ApplicationController.renderer.defaults # =>
  http_host: '',
  https:      false,

``` …

How to inspect XML files in a terminal

You can use xmllint to pretty-print ugly XML files on your terminal. Just say:

xmllint --format file.xml

That will restructure containers nicely into individual sections with proper indentation.\
Note that it will automagically work on gzipped XML files!

To write pretty output to a new file, just use the -o switch (short for --output):

xmllint --format file.xml -o pretty_file.xml

See the xmllint man page for other useful switches and more information.

Linked content

Pimp my IRB

Put the attached files into your home directory and enjoy.


  • defines interesting_methods, which is essentially all methods without top-level methods inherited from Object/Module
  • requires awesome_print, if present
  • requires interactive_editor, if present (basically makes vim available)
  • loads .irbrc_rails if in Rails (e.g. for the Rails console)


  • defines efind(email), which is a shortcut to find users by email …
Linked content

Tips And Tricks For Print Style Sheets

Smashing Magazine lists some handy tricks for print style sheets, all with CSS:

  • Expand External Links For Print
  • Print QR Codes For Easy URL References
  • Use CSS filters to improve the result of printed graphics (i.e. images with transparent parts)

Loading dumps via SSH, unpacking and sourcing them, all with a progress bar

Here is a hacky way to load dumps directly from the source server, without fully copying them over and extracting them first.

It may break horribly for you. This is the dark side of the force.

  1. Install pipe viewer, if you don't have it already: sudo apt-get install pv
  2. Know the location of the dump file on the remote server. We'll use /mnt/dumps/my_project.dump.bz2 in the example below.
  3. Find out the size of the (bzipped) file in by…
Linked content

Firefox introduces PDF viewer

Prepare to explain customers what changed if your application renders PDF documents to users.

Xfce: Take a screenshot with the "Print" key

  • Go to Settings Manager / Keyboard / Application Shortcuts
  • Add a shortcut for the Print key that calls xfce4-screenshooter -f

This may be configured for you by default.

How to not leave trailing whitespace (using your editor or Git)

There is no reason to leave trailing whitespace characters in your project's files, so don't add any.

A git diff --check will tell you if there are any and you should not commit when you see them. So go ahead and switch your editor/IDE to automatically remove them for you.
Below are a few instructions on how to get them removed by your favorite IDE or editor.

Note that except for RubyMine, the following changes will remove trailing white-space on all lines, not only those that you changed.
While this should not be a problem if your proje…

How to test print stylesheets with Cucumber and Capybara

A print stylesheet is easy to create. Choose a font suited for paper, hide some elements, done. Unfortunately print stylesheets often break as the application is developed further, because they are quickly forgotten and nobody bothers to check if their change breaks the print stylesheet.

This card describes how to write a simple Cucumber feature that tests some aspects of a print stylesheets. This way, the requirement of having a print stylesheet is manifested in your tests and cannot be inadvertedly removed from the code.

Our example —…

LibreOffice won't embed most fonts into PDFs (with fix)

Note: There's more to it than this card says. All we know right now is that sometimes PDFs generated by LibreOffice don't render properly on some machines, with e.g. characters appearing as dots. We don't know if the font is to blame, or LibreOffice, or particular versions of LibreOffice.

Compress bitmap images within PDF files

Embedding bitmap images within PDF sometimes results in large files because the bitmaps are not compressed. If you don't need high quality images within the resulting PDF file, you can use ghostscript to compress embedded images:

ghostscript -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=new-smaller-file.pdf large-original-file.pdf

Note that your PDF printer (or similiar generation tools) also often come with a compression setting for embedded raster images.

How to print Github wiki pages

I have no idea how it's supposed to work (or why the don't have a print CSS), but this works for pages written with Markdown:

  1. "Edit" the wiki page
  2. Copy all text
  3. Run a Markdown interpreter and pipe its result, e.g.: kramdown > /tmp/github.html
  4. Paste your markdown
  5. Press Ctrl-D to finalize your input
  6. Open the generated HTML file and print it.


How to embed images in higher resolutions for printing

When you print out a HTML pages, all raster images (like PNGs) will appear aliased. This is because a printer's resolution is usually much higher than that of a computer screen.

If an image absolutely must look awesome when printed, a solution is to embed the image in much higher solution than needed (e.g. four times the horizontal resolution), then scale it down to the desired width using CSS.

Note that this will slightly alter the image's appearance on the screen because browsers will scale down the image [using an anti-aliasing method](…

Linked content

monperrus/ExpandAnimations - GitHub

ExpandAnimations is a LibreOffice/ Impress extension to expand presentation animations before exporting to PDF. This way the exported PDF will have one page per animation stage.

Linked content

Single step and slow motion for cucumber scenarios using @javascript selenium

Single step and slow motion for Cucumber scenarios can come in handy, especially in @javascript scenarios.

# features/support/examiners.rb
AfterStep('@slow_motion') do
  sleep 2

AfterStep('@single_step') do
  print "Single Stepping. Hit enter to continue"

If you're using spreewald, these tags are available as @slow-motion and @single-step (with dashes instead of underscores).

Note: You can also [prevent the selenium webbrowser wind…

This website uses cookies to improve usability and analyze traffic.
Accept or learn more