The cancelable promises proposal was withdrawn some time ago.
The new standard way is that your long-running function take a AbortSignal
{ signal }
property. The caller can use this signal to send an abort request to your function. Upon receiving the request, your function should reject its promise with an error.
Async browser functions like fetch()
reject their promises with a `new DOMException('Message here', 'Abo...
URLs can transport key/value pairs ("parameters") using this syntax:
/path?foo=bar
If the value is blank, mind these subtle differences:
URL | Meaning |
---|---|
/path?foo= |
Parameters have a key foo . Its value is an empty string. |
/path?foo |
Parameters have a key foo . Its value is null . |
/path |
Parameters have no key foo . |
In long diffs, it can become impossible to spot small changes in larger blocks of moved code. This may be either a method that was moved from the top to the bottom of a file, or a long test file that was split in many.
Fortunately, Git offers a special highlighting mode that directs the reader's attention to relevant code parts:
git diff --color-moved=dimmed-zebra
It will dim lines that were moved around without changes, and highlight changed lines. See this SO answer for an illustra...
To restart all tasks monitored by God, don't use god restart
. This command is only meant to soft-restart a given process or group.
Instead you should:
god stop
god terminate
god start -c yourgodconfig.god
Migrating data from a legacy into a new system can be a surprisingly large undertaking. We have done this a few times. While there are significant differences from project to project, we do have a list of general suggestions.
Before you start, talk to someone who has done it before, and read the following hints:
Before any technical considerations, you need to understand the old system as best as possible. If feasible, do not only look at its API, or database, or frontend, but let a user of the old system sho...
There are two ways to lock a user in devise.
It depends on your requirements which methods works best.
We recommend to use option 2 when you want to couple the lock to the m...
TinyMCE is a WYSIWYG editor which is quite customizable.
tinymce.init({
// ...
toolbar: 'myCustomButton',
setup: function(editor) {
editor.ui.registry.addButton('myCustom Button', {
...
When testing with Cucumber / Caypbara, iframes are ignored, so you can't interact with them.
To interact with your iframe, you have to explicitly tell your driver to use it.
You can reference your iframe either through it's id, or if none given, by it's number:
When /^(.*?) inside the (.*?). iframe$/ do |nested_step, frame_number|
page.within_frame(frame_number.to_i) do
step nested_step
end
end
When /^(.*?) inside the (.*?). iframe:$/ do |nested...
Using .downcase
or .upcase
on strings containing umlauts does not work as expected in Ruby versions before 2.4. It leaves the umlauts unchanged:
"Über".downcase
=> "Über"
"Ärger".downcase
=> "Ärger"
The very same applies for french accents (Thanks Guillaume!):
"Être ou ne pas être, telle est la question".downcase
=> "Être ou ne pas être, telle est la question"
Obviously, this leads to problems when comparing strings:
"Über".downcase == "über"
=> false
In Rails you can use ActiveSupports' [multib...
We already know that that we can create strings using the percent notation:
%{<foo="bar's ton">}
is perfectly fine Ruby.
But there is more. The curly brackets ({}
) are interchangable with most unicode characters (e.g. square brackets[]
).
Furthermore, you can add a "modifier" to the percent notation to control the return type of th...
When two classes implement the same behavior (methods, callbacks, etc.), you should extract that behavior into a trait or module. This card describes how to test that extracted behavior without repeating yourself.
Note that the examples below use Modularity traits to extract shared behavior. This is simply because we like to do it that way at makandra. The same techniques apply for modules and overriding self.included
.
Example
---...
Ruby's String#split
returns an array of substrings from the given string. Usually, this is missing the split characters:
>> 'user@example.com'.split('@')
=> ["user", "example.com"]
If you want to join those parts later on, you might know the split character and can just use it to join explicitly.
But if you split by a regular expression (for a set of split characters) that information is lost:
>> 'user@example.com'.split(/[@\.]/)
=> ["user", "example", "com"]
You can use a capture group to make those characters ...
Headless Chrome is a way to run the Chrome browser without a visible window.
Configure the Capybara driver like this:
Capybara.register_driver :selenium do |app|
options = Selenium::WebDriver::Chrome::Options.new
options.add_argument('--headless') unless ENV.key?('NO_HEADLESS')
options.add_argument('--disable-infobars')
options.add_option('w3c', false)
options.add_emulation(device_metrics: { width: 1280, height: 96...
SSHKit 1.9.0 might fail with the following error, when trying to deploy a Rail application. Upgrading the gem to version 1.21.0 fixed the issue.
Traceback (most recent call last):
17: from /home/user/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/sshkit-1.9.0/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
16: from /home/user/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/sshkit-1.9.0/lib/sshkit/backends/abstract.rb:29:in `run'
15: from /home/user/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/sshkit-1.9....
Whenever requires you to set the application
attribute in your Capistrano configuration. Otherwise your cronjobs are created multiple times.
Example entry in config/deploy.rb
:
set :application, 'some-app' # allows "set :whenever_identifier, ->{ "#{fetch(:application)}_#{fetch(:stage)}" }" to work as expected
Then the crontab will look like this:
# Begin Whenever generated tasks for: some-app_staging
34 2...
This is an informational site about video and how it works. We started by talking about Playback, next we added content about Delivery. Stay tuned for more about Processing and Capture.
PostgreSQL, unlike MySQL, treats strings as case sensitive in all circumstances.
This includes
=
and LIKE
Usually this is fine, but some strings (like emails and usernames) should typically be treated as case insensitive.
There are a few workarounds available:
ILIKE
instead of LIKE
lower()
functionlower(email)
Probably th...
Building plain text emails with an .erb template doesn't allow you to indent code like you normally do in HTML mails.
<%= 'foo' if bar %>
"\n"
if bar is false
"foo\n"
if bar is true
<%= nil %>
"\n"
<% if true %>
<%= 'foo' %>
<% end %>
" foo"
<%= 'foo' %>
<%= 'bar' %>
"foo\n\nbar\n"
Write unindented code to get the expected result.
<% if bar %>
<%= 'bar' %>
<% end %>
<%= 'foo' %>
<%= 'bar' %>