From Ubuntu 17, rbenv fails to install Ruby below 2.4 because of a mismatching OpenSSL dependency: it needs libssl1.0-dev
for the installation process, but recent Ubuntus come with libssl-dev
.
From the linked StackOverflow comment:
As far as I know (and tested), Ruby versions < 2.4 requires libssl1.0, while >2.4 libssl1.1+. The two libssl packages conflict with each other, so you can't have both of them, so I had to juggle the libs in order to install the required ruby version. To make things even funnier (or more complicated),...
Inspecting the source of an email does not always reveal the plain HTML source, but some encoded byte mess. In order to inspect the HTML anyways, you can use a little trick:
While composing a message, select all (Ctrl + A), then navigate to Insert > HTML on the message window.
If you need to inspect a received message, hit "Reply" to turn it into composition mode.
git apply
allows you to apply a diff onto your HEAD
. Most often you can achieve the same result with a rebase
& merge
.
Example:
master commit1 - commit3
feature-branch \ commit2 - commit4
git checkout feature-branch
git reset --hard commit3
git diff ..commit4 | git apply
master commit1 - commit3
feature-branch \ Unstaged commit 2 & 4
You can also [create a patch and apply it afterwards](https://makandracards.com/makandra/2521-git-how-to...
The goal is to get Jasmine specs running in a Rails project using Webpacker, with the browser based test runner. Should be easily adaptable to a pure Webpack setup.
yarn add jasmine-core
Since we do not want to mix Jasmine into our regular Javascript, we will create two additional packs. The first only contains Jasmine and the test runner. The second will contain our normal application code and the specs themselves.
We cannot...
If rspec hangs with no output and you dont get a backtrace neither with --backtrace
nor by just killing it with crtl-c,
you can put the following in your spec/spec_helper.rb
:
puts "rspec pid: #{Process.pid}"
trap 'USR1' do
threads = Thread.list
puts
puts "=" * 80
puts "Received USR1 signal; printing all #{threads.count} thread backtraces."
threads.each do |thr|
description = thr == Thread.main ? "Main thread" : thr.inspect
puts
puts "#{description} backtrace: "
puts thr.backtrace.join("\n")
end
...
Capybara clears cookies before each scenario, but not other client-side data stores. If your app is using localStorage
or sessionStorage
, contents will bleed into the next scenario.
Use this hook to remove all site data after each scenario:
After do
if Capybara.current_driver == :selenium && !Capybara.current_url.starts_with?('data:')
page.execute_script <<-JAVASCRIPT
localStorage.clear();
sessionStorage.clear();
JAVASCRIPT
end
end
In Ruby on Rails, all objects have a useful blank?
method. It returns true for nil
but also for empty strings or empty arrays. There is also a universal method present?
which returns true
for all values that are not blank?
.
In JavaScript you need to roll your own implementation of blank?
and present?
.
If your application uses [Unpoly](...
The gem json
fails to install for Ruby 2.5 if you use a version equal or below 1.8.3
.
Run bundle update json --conservative
to solve this issue.
The backtrace you will encounter looks like this:
Building native extensions. This could take a while...
ERROR: Error installing json:
ERROR: Failed to build gem native extension.
current directory: /home/user/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/json-1.8.3/ext/json/ext/generator
/home/user/.rbenv/versions/2.5.3/bin/ruby -I /home/user/.rbenv/versions/2.5.3/lib/ruby/si...
Katapult was an endeavor to dramatically speed up starting a new Rails application. However, it turned out to save less time than expected, while requiring more time for maintenance than anticipated. Since its benefits fell too low, we have decided to not continue developing Katapult.
You can still use Katapult for generating ready-to-run applications with model CRUD, authentication and all of Katapult's features, but the rapid development of the web will quickly render the generated code antiquated. Nevertheless, its architecture may remai...
Eduardo Russo was tired of complex favicon creation and created his own favicon generator. It's really easy and allows a lot of image editing before rendering the favicons, in all needed sizes, formats and with the HTML needed to include them!
In Rails applications with Haml:
/public
app/views/layouts/_favicon.html
= render 'layouts/favicon'
to <head>
in your application layout(s)... and you're all...
When you need to check a value for presence, don't rely on JavaScript since it considers 0
or "0"
false. Also don't rely on LoDash's _.isEmpty
:
if ('0') { ... } // false
if (0) { ... } // false
^
if (!.isEmpty('0')) { ... } // true (= good)
if (!.isEmpty(0)) { ... } // false (= not good)
This is because isEmpty
it is only meant for objects with a length
.
While the name implies that it's meant only for collections, you probably still want something like isBlank
or `is...
Rails guide that covers PostgreSQL-specific column types and usages for Active Record.
You should especially keep in mind the special datatypes that PostgreSQL offers. \
Types like json
and array
take away a lot of the pain that you had on MySQL projects.
Example use cases for array
are tags or storing foreign keys (instead of a join model). You can even index them.
Travis changed their default distribution from Ubuntu 14.04 (trusty) to 16.04 (precise). This might break your test setup for new builds.
You can solve this issue by freezing your test distribution in the .travis.yml
to Ubuntu 14.04 until you have the time to solve all the issues you will have in 16.04:
dist: trusty
Here are few indicators that you ran into this issue:
Your travis-ci builds might have started failing on the usual
psql -c...
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...
Cucumber up to version 2 had a neat feature called Step Argument Transforms which was dropped in favor of Cucumber 3 ParameterTypes. While I strongly encourage you to drop your legacy Transforms when upgrading to Cucumber 3, it might not always be possible due to their different design.
This is a guide on how to keep the exact same functionality of your old Transforms
while writing them in the style of new `Paramet...
When installing a gem you can use version comparators like >=
or ~>
. That way it is possible to fetch the latest version of Bundler 1 with this command:
gem install bundler -v '~>1'
How to install bundler for Ruby < 2.3 is a common usecase where you might need Bundler 1.
When you update your ChromeDriver to version 75 or beyond, you might get w3c errors in your tests.
For example, reading the browser console for errors no longer works, and page.driver.browser.manage.logs.get(:browser)
will raise an error like "undefined method `log' for #<Selenium::WebDriver::Remote::W3C::Bridge:0x000055903f307aa8>
".
Add options.add_option('w3c', false)
to your Selenium configuration (e.g. features/support/selenium.rb
) and you should be back to normal:
Capybara.register_driver :selenium do |app|
options ...
If you get requests with values for formats
like this:
{:locale=>[:de], :formats=>["../../../../../../../../../../etc/services{{"], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :haml]}
or fails like this:
Invalid query parameters: invalid %-encoding (../../../../../../../../../etc/passwd%%0000.html)
Someone tries to exploit CVE-2019-5418.
If you use the latest Rails (or latest Rails LTS) you're...
This is just a reference for legacy code. For new code, always use capture3
.
Returns the standard output of running the given command in a subshell. This is an alias for `...`, and you can use string interpolation.
Example:
name = 'ls'
result = `which #{name}`
It does not escape anything you inject in the string, so be aware of possible security vulnerabilities...
All quoted.
Set up a package root in your homedir to hold the Node "global" packages:
$ NPM_PACKAGES="$HOME/.npm-packages"
$ mkdir -p "$NPM_PACKAGES"
Set NPM to use this directory for its global package installs:
$ echo "prefix = $NPM_PACKAGES" >> ~/.npmrc
Configure your PATH and MANPATH to see commands in your $NPM_PACKAGES prefix by adding the following to your .bashrc:
# NPM packages in homedir
NPM_PACKAGES="$HOME/.npm-packages"
# Tell our environment about user-ins...
Webpacker can automatically create an icon font from SVG files, which is really handy. When you're using the asset pipeline, you can still have an icon font from SVG files, but it requires some manual work.
icon-font-generator
. If you're not using nvm
, run sudo npm install -g icon-font-generator
Configure
...It is quite easy to migrate from CoffeeScript to ES6. You can use decaffeinate to convert your CoffeeScript source to modern JavaScript.
yarn global add decaffeinate
~/.bashrc
to export the Yarn binaries in your Bashexport PATH="$PATH:$(yarn global bin)"
decaffeinate some.coffee
to get the converted modern JavaScript file.In a nutshell: return
statements inside blocks cause a method's return value to change. This is by design (and probably not even new to you, see below) -- but can be a problem, for example for the capture
method of Rails.
Consider these methods:
def stuff
puts 'yielding...'
yield
puts 'yielded.'
true
end
We can call our stuff
method with a block to yield. It works like t...
If you struggle with a /boot partition that is too small for updates, and you are too intimidated by the way to resize your /boot partition, there might be an easier fix:
It is possible to configure a better compression algorithm for the images in /boot
. To do this, edit /etc/initramfs-tools/initramfs.conf
and change the existing line to
COMPRESS=xz
Then rebuild the images using
sudo update-initramfs -u -k all
If you get an error during the last step, please immediately get help, because otherwise...