Parallel Rspec with RTeX
Running projects parallel makes some trouble with PDF generation. Use geordi rspec spec
to force sequential tests for the whole application or failed specs only.
geordi rspec
RTeX::Document::GenerationError in '...'
Could not find result PDF document.pdf after generation.
Check .../document.log
The document will show you, that RTeX tries to generate a PDF document out of a HTML file, which won't work.
Padrino: "incompatible marshal file format (can't be read)"
If you see a stacktrace beginning with lines like this:
E, [2015-07-16T09:23:10.896146 #23308] ERROR -- : app error: "incompatible marshal file format (can't be read)\n\tformat version 4.8 required; 32.32 given" (TypeError)
E, [2015-07-16T09:23:10.896282 #23308] ERROR -- : /.../bundle/ruby/2.0.0/gems/moneta-0.7.20/lib/moneta/transformer.rb:132:in `load'
E, [2015-07-16T09:23:10.896311 #23308] ERROR -- : /.../bundle/ruby/2.0.0/gems/moneta-0.7.20/lib/moneta/transformer.rb:132:in `load'
E, [2015-07-16T09:23:10.896334 #23308] ERR...
emcien/iso_latte
Sometimes you need to run background jobs that you can't make important guarantees about - they may run out of memory and get killed, or produce segmentation faults, or exit! directly - and you need to be able to clean up after such problems.
IsoLatte is a gem that allows a block of code to be executed in a subprocess. Exceptions get passed back to the parent process through a pipe, and various exit conditions are handled via configurable callbacks.
Savon: Use complex SOAP types as arguments
If a SOAP API expects you to call a remote method with arguments of complex types, Savon lets you manually set the xsi:type
attribute like this:
client.call(:rpc_method,
message: {
:some_object => {
:name => 'foo',
:other => 'bar',
'@xsi:type' => 'somenamespace:SomeObject'
}
}
)
This is roughly equivalent to this in Javaland, where you have magic generated stub code:
SomeObject so = new SomeObject();
so.setName('foo');
so.setOther('bar');
client.rpcMethod(so);
Protip: Clone large projects multiple times
Large projects usually have large test suites that can run for a long time.
This can be annoying as running tests blocks you from picking up the next story -- but it doesn't have to be that way!
Simply clone your project's repo twice (or even more often).
When your work on a feature branch is done, simply push that branch and check it out on your 2nd copy to run tests there.
You can pick up a new story and work on that on your "main" project directory.
If you do it right, you will even be able to run tests in both your 2nd copy and your m...
Free advice: show up early
How can a client blame you for a cab driver’s mistake? How can a conference organizer hold you accountable for an airline’s cancelled flight?
They can do it because lateness is part of the order of things, and grownup professionals plan for it, just as they plan for budget shortfalls and extra rounds of revision.
Material Design Lite
CSS (+ some Javascript) framework, implementing Google's material design for static web pages.
Can be used for plain websites without requiring a full blown Javascript framework, unlike the (also excellent) Polymer paper elements, or Angular material.
Prelimiary impression:
I would recommend against using it at this stage, for a couple of reasons:
- It is much less complete than you might expect from a CSS framewor...
FactoryGirl: How to easily create users with first and last name
In most of our applications, users have their first and last name stored in separate columns. However, specifying them separately quickly gets annoying, especially when proxying them from cucumber_factory:
Given there is a user with the first name "Dominik" and the last name "Schöler"
Wouldn't it be nice if you could just say:
Given there is a user with the name "Dominik Schöler"
and have FactoryGirl assign first and last name automatically? The code below achieves that!
##...
PostgreSQL: Ordering, NULLs, and indexes
When using ORDER BY "column"
in PostgreSQL, NULL
values will come last.
When using ORDER BY "column" DESC
, NULL
s will come first. This is often not useful.
Luckily, you can tell PostgeSQL where you want your NULL
s, by saying
... ORDER BY "column" DESC NULLS LAST
... ORDER BY "column" ASC NULLS FIRST
Your indexes will have to specify this as well. In Rails, declare them using
add_index :table, :column, order: { column: 'DESC NULLS LAST' }
Multiple columns
When sorting by multiple columns, yo...
How to disable auto-complete on login forms
Disabling auto-complete in login forms is probably a bad idea, since it encourages weak passwords.
If you are still forced to implement this (maybe due to legal or policy requirements), this is how:
Prevent browsers from saving the password in the first place. Disabling autocomplete does not improve security.
How to prevent password saving:
To prevent the browser from saving passwords (and usernames), you need to:
- copy username and password to hidden form fields before submitting the login form
- c...
SmartUnderline
SmartUnderline is an open-source JavaScript library which uses clever tricks to draw underlines in a more beautiful and readable way.
We've not yet put this into a project, but its effect is very pretty. Please update this card when you use it.
Use Capybara commands inside an IFRAME
If you need to follow links, click buttons, etc. using Capybara inside an <iframe>
, you can do it like this:
page.within_frame('iframe-id') do
fill_in 'E-mail', with: 'foo@bar.com'
fill_in 'Password', with: 'secret'
click_button 'Submit'
end
Instead of the frame's [id]
attribute you may also pass a Capybara::Node
for an <iframe>
.
If you're also using Cucumber you could make a meta-step like this:
When /^(.*?) inside the (.*?) frame$/ do |step_text, frame_id|
page.within_frame(frame_id) do
s...
Faster debugging with RubyMine macros
In my RubyMine I have recorded two macros for debugging and linked them to some keyboard shortcuts. Since I believe everyone could benefit from having those I wanted to share this.
The first one simply inserts
binding.pry
and the second one
.tap { |object| binding.pry }
for when you do not have a reference to the object you want to inspect.
In order to record a macro you simply follow the path Edit > Macros > Start Macro Recording
.
Then you simply type binding.pry
or whatever you want to record and stop recor...
ZenTest "invalid gemspec" / "Illformed requirement"
Today I ran into this:
Invalid gemspec in [/usr/local/rvm/gems/ruby-1.9.3-p194/specifications/ZenTest-4.9.3.gemspec]: Illformed requirement ["< 2.1, >= 1.8"].
You need a newer Rubygems version. Try this: gem update --system 1.8.29
Copy & Paste & The Web | CSS-Tricks
Insanely detailled guide about controlling copy & paste behavior using web technology in 2015.
Note that you can now trigger a copy action through Javascript, no Flash required.
Fix: Capybara is very slow when filling out fields in large forms
In large forms (30+ controls) new Capybara version become [extremely slow] when filling out fields. It takes several seconds per input. The reason for this is that Capybara generates a huge slow XPath expression to find the field.
The attached code patches fill_in
with a much faster implementation. It's a dirty fix and probably does a lot less than Capybara's own fill_in
so don't use it unless you are having problems with test suites that are unusable because of this...
input: A DOM event that is fired whenever a text field changes
If you're supporting IE9+, you can listen to input
to see if a text field changes.
Other than change
, it fires while the user is typing and doesn't wait until the user blurs the field.
Older workarounds included polling the field every X ms to see if its value changed.
Unfortunately input
is not triggered for check boxes.
When should you use DateTime and when should you use Time?
The differences are subtle. You probably want to use Time
, except when you want to use DateTime
. See the attached article for details.
Rails 3 ActiveRecord::Persistence#becomes does not copy changed attributes
Note: ActiveRecord::Base#becomes
has a lot of quirks and inconsistent behavior. You probably want to use ActiveType.cast
instead.
This issue will be encountered when relying on attribute_was
methods of ActiveModel::Dirty
after casting a model which has defaults to a form model, for example.
In my case a record with an assignable_values legacy value beca...
Rails 4.1+ automatically detects the :inverse_of an association
Starting from 4.1, Rails automatically detects the inverse of an association, based on heuristics. Unfortunately, it does not seem to notify you when it fails to infer the :inverse_of
, so you are better off to always manually set :inverse_of anyway.
Note that automatic inverse detection only works on
has_many
,has_one
,belongs_to
associations. Extra options on the associations will prevent the association's...
High Performance Browser Networking: HTTP/2
HTTP/2 will make our applications faster, simpler, and more robust—a rare combination—by allowing us to undo many of the HTTP/1.1 workarounds previously done within our applications and address these concerns within the transport layer itself. Even better, it also opens up a number of entirely new opportunities to optimize our applications and improve performance!
HTTP/2 is here, let's optimize!
WebRTC HTTP/2 is here, let’s optimize! or, why (some) yesterday's best-practices are today's HTTP/2 anti-patterns.
Material icons - Google Design
Surprisingly exhaustive new icon set by Google.
Available as PNG, SVG and as a icon font.
Comment from Henning
I tried using the icon set in a project. I found the quality, selection and handling far worse than what we are used to in FontAwesome.
Exception Notifier: Foreground vs. background sections
Since version 2.6 exception notifier distinguishes between foreground and background sections. The reason is that with background jobs (e.g. methods that are called by a cron job) some variables are not available for exception notifier, e.g. @request
and @kontroller
.
Therefore you can configure foreground and background sections individually. Our default settings are documented in Get notified when your application raises an error.
**W...