If you have jQuery code like this: if (condition) { $element.show(); } else { $element.hide(); } ... you can shorten this to: $element.toggle(condition);

Here are some hints on best practices to maintain your tasks in larger projects. Rake Tasks vs. Scripts The Rails default is using rake tasks for your application tasks. These...

run_script(subject, 42, 'some_arg') assert_something end end Further reading Best practices: Writing a Rails script (and how to test it...

tenderlovemaking.com

In Ruby, the meaning of protected and private is different from other languages like Java. (They don't hide methods...

makandra dev

...make block elements take up much more space than desired, even stretching their container beyond the screen edge on small screens. min-width is defined to win against competing width...

...is something like # WRONG class Page < ActiveRecord::Base %w[main sub].each do |type| belongs_to "#{type}_title" end end # RIGHT class Page < ActiveRecord::Base %w[main sub].each do...

belongs_to :"#{type}_title" end end Always convert to a symbol, otherwise you'll have all kinds of fun. Newer rails / activerecord (at least 5.2) will throw an association...

In a nutshell: Use git rebase --onto target-branch source-commit target-branch means "branch you want to be based...

A recent patch level Ruby update caused troubles to some of us as applications started to complain about incompatible gem...

Exercise 1: Maps In MovieDB, add a new field “Principal filming location”. In a movie’s show view, geocode that...

Edit /etc/default/bind9 and change OPTIONS="-u bind" to OPTIONS="-u bind -d 50 -g" Restart BIND and you'll see...

I recently ran into this issue when processing a massive backlog of documents. The server completely stalled, sometimes taking up...

...pre-existing mocks inside the block, they are not reverted to the previously mocked behavior. This is usually not relevant and you should be fine in most cases...

makandra dev
tom.preston-werner.com

A perfect implementation of the wrong specification is worthless. By the same principle a beautifully crafted library with no documentation is also damn near worthless. If your software solves the...

...like these before applying them to production. When entering these rules in the screen behind the Edit Test Rules button in the AWS console and testing it, the results section...

w3c.github.io

Here is how to use Chromedriver without libraries like selenium-webdriver. This can be useful for debugging. The following example...

thepugautomatic.com

The linked article shows how metapogramming macros can use define_method to make a method that can be overridden with...

PostgreSQL can cosplay as a full-text search engine. It doesn't have the features or fidelity of ElasticSearch or...

greg.molnar.io

Greg Molnar has written a neat article about creating a single-file Rails app. This is not meant for production...

makandra dev

If you want to rename a key of a Ruby hash, this could help you out. Just put it into...

This is useful to kill processes like ruby my-script.rb: pkill -f my-script.rb With great power comes great responsibility.

At least Selenium cannot find disabled fields. Unless you find them explicitly: find_field 'This is disabled', disabled: true

...provide a lot of ways to style your scrollbars for now, it might be best to only use them in Browsers that don't support the non-standard scrollbar styling...

...fail with an SQL error due to duplicate index key. You can change Rails' behaviour, by saying class User < ActiveRecord::Base validates_uniqueness_of :name, case_sensitive: false end

...described above. legacy_transforms.rb This file adds a Transform method to the Cucumber "World" which behaves similar to the Cucumber 1 and 2 transformations. This allows cucumber_factory to keep using...

...relative_path_from(fixture_root).sub_ext('').to_s method_name = fixture_name.tr('/', '_') model_class = begin fixture_name.classify.constantize rescue NameError next end define_method(method_name) do |*labels| records = labels.map do |label...

...under test/fixtures/. For each file it derives a helper name from the path (users.yml becomes users) and maps it back to a model class via classify.constantize . It will also silently...