View

Form letters with LibreOffice Writer

This is painful. Consider using Microsoft Office or switching careers. If you need to write < 20 letters consider doing it manually.

So you didn't listen and here it comes:

  1. Ignore the Mail Merge Wizard. It will crash or destroy your document.
  2. Export your addresses, recipient names, etc. as a .ods spreadsheet (.xls, .xlsx, .ods). Use any columns that work for you, but be consistent. I like to use one column for the address, one column for the salutation line.
  3. Import the spreadsheet as an address book source: *Tools => Add…
Repeats

Check that an element is visible or hidden via CSS with Cucumber/Capybara

If you have content inside a page that is hidden by CSS, the following will not work (because Capybara sees it nonetheless, even in a Selenium feature):

Then I should not see "foobear"

Instead, use the step definition below to check that an element is hidden by CSS:

Then "foo" should be hidden

For Spreewald < 1.2.3 use

Then "foo" should not be visible

You can also check that an element is visible:

Then "foo" should be visible

Implementation details

  • Regardless of whether …
Auto-destruct in 49 days

Unpoly 0.50.0 has been released

This is a major update with some breaking changes. Expect a few more updates like this as we move closer to our 1.0 release in 2018.

General

  • jQuery 3 is now supported in addition to jQuery 1.9+ and jQuery 2.
  • Unpoly now uses native Promises instead of jQuery deferreds.
  • You can now help improve Unpoly's documentation by clicking an Edit this page link on any unpoly.com subpage (like [a[up-target]](https://unpoly.com/a-up-targe…

How to find and replace empty cells in Libre Office Calc

To find and replace (CTRL + H) empty cells in Libre Office Calc you can use a regular expressions (also called "Finds an empty paragraph" in context of a spreadsheet):

Screenshot_2017-12-04_11-07-04.png

It is also possible to just enter a regular expression in the search (CTRL + F), but there is no option to only search in the current selection like in the screenshot above. Use find and replace instead if needed.

Repeats

CarrierWave: How to remove GIF animation

When accepting GIF images, you will also accept animated GIFs. Resizing them can be a time-consuming task and will block a Rails worker until the image is processed.

Save yourself that trouble, and simply tell ImageMagick to drop any frames but the first one.

Add the following to your uploader class:

process :remove_animation

private

def remove_animation
  if content_type == 'image/gif'
    manipulate! { |image| image.collapse! }
  end
end

You may also define that process for specific versions only (e….

Rails: Migration helper for inserting records without using models

You should avoid using application models in your migrations. But how else would you create records in a migration?

The simplest alternative is to write plain SQL. Since INSERT statements are no pleasant write for Rubyists, here is a simple wrapper:

Helper

The helper method below takes a table name and a hash of attributes, which it inserts into the specified table. Copy it over to your migration and profit!

```
private

def insert_record(table, **attributes)
attributes.merge!(
updated_at: Time.now,

Heads up: RSpec-Mocks' #stub_const will define intermediate modules that have not been loaded yet

The issue: You are using stub_const to change a constant value for your test.

stub_const "SomeClass::CONST", 'test'

All of a sudden, tests fail with undefined method 'some_method' for #<SomeClass:0x00000000101433a8>.

The reason

When using stub_const before the Class containing the constant has been loaded, a module is automatically created with the name.

Since RSpec does no autoloading, it will create a SomeClass module by itself. This is arguably a good idea.

As a workaround, use stub_const in your Rails specs li…

Repeats

jQuery promises: .done and .then are not the same

jQuery's deferred objects behave somewhat like standard promises, but not really.

One of many subtle differences is that there are two ways to chain callbacks to an async functions.

The first one is done, which only exists in jQuery:

$.ajax('/foo').done(function(html) {
  console.debug("The server responded with %s", html);
});

There is also then, which all promise libraries have:

```
$.ajax('/foo').then(function(html) {
console.debug("The server resp…

Repeats

Remember: LoDash syntax is a bit different from UnderscoreJS

Since we are using LoDash instead of UnderscoreJS in recent/current projects, you should keep in mind that their syntax is a bit different.

UnderscoreJS

In UnderscoreJS, methods always return a value:

x = [1, 2, 2]
_.uniq(x) // => [1, 2]
_(x).uniq() // => [1, 2]

If you want to chain multiple calls, you need to start off with a _.chain, and call value() to terminate the chain.

_.chain(x).uniq().map(function(i) { return i + 10 }).reverse().value() // => [12, 11]

##…

External contentRepeats

Create and send any HTTP request using the Postman request builder

Talking with APIs makes more fun using Postman. Otherwise you might want to read: How to send HTTP requests using cURL

Postman ist available as Chrome or Mac App.

How does it helped me?
- Editing multiline JSON bodies is much more comfortable than in the terminal
- Saving named request in a collection
- Syntax highlighting when writing JSON bodies
- History with all my request
- Multiple environments

Auto-destruct in 37 days

Updated: Snom VOIP phone shows your own name instead of the incoming number

There's an additional solution now that also logs the correct number to your call log in VoIP clients like Ekiga and Linphone. The new solution has a drawback though, in case you're using multiple phone numbers and need to see which line is ringing.

Repeats

Action Mailer Previews (since Rails 4.1)

Since Rails 4.1 there is a preview-function to see what an e-mail will look like.

All you need to do is implement a preview-class in test/mailers/preview:

class NotifierPreview < ActionMailer::Preview
  def welcome
    Notifier.welcome(User.first)
  end
end

and then a preview will be available in the browser at http://localhost:3000/rails/mailers/notifier/welcome as well as a list of previews at http://localhost:3000/rails/mailers .

Rails <4.1

You could use [Mailcatcher](https://makandracards.com/makandra/1739-mailcatcher-…

Error during Rails 5 upgrade: Environment data not found in the schema

This error is raised because your old database does not have a configured environment yet, which Rails 5 enforces.

If this error occurs while migrating your parallel test databases, make sure to update the parallel_tests gem first: current versions fix this. If you're still using Cucumber < v3, the latest version of parallel_tests will be 2.18.0.

Writing a README for a Rails project

A Rails project should have a README that gives the reader a quick overview of the project. Its size will vary as projects differ in complexity, but there should always be some introductory prose for a developer to read when starting on it.

Purpose

That's already the main purpose of a project README: Give a new developer a quick overview of the project. In sketching this outline, the README should notify the reader of any peculiarity he needs to know of.

Remember that in a few months, you'll be a kind of "new developer" yourse…

How to use cookies with curl

When making requests using curl, no cookies are sent or stored by default.
However, you can tell curl to re-use cookies received earlier (or forge your own cookies).

There are 2 command line switches you need to use:

  • -c will write cookies to a given file
  • -b will read cookies from a given file

Example

The remote server sets a "foo" cookie to value "bar". We tell curl to store them to a file at /tmp/cookies using the -c switch.

$ curl -c /tmp/cookies http://httpbin.org/cookies/set?foo=bar

You may look at the file, …

Repeats

Beware: Many browsers define window.event

Some browsers define window.event, which will return a copy of the "current" event. However, this is not defined by the W3C. Most importantly, Firefox does not support it, neither do recent versions of IE.

You should completely avoid accessing the global event and instead pass the event object around that the event handler receives. The easiest protection against accidentally accessing window.event is just never naming the event event, but e or evnt or so.

```
function brokenInFirefox() {
event.preventDefault(); // Break…

CSS: Giving text lines a background-color (with configurable line padding and margin)

The gist is:

  • wrap the text with a span
  • use line-height for the spacing between lines ("margin")
  • use box-shadow to control the line background size ("padding")

Example

text_lines_with_background_color.png

span
  box-shadow: 0 0 0 10px #fff
  background-color: #fff
  box-decoration-break: clone # Fix Firefox
  line-height: 2.2

→ [jsfiddle](https://jsfiddle.net/2fmqgbh…

View
3409 cards