Sometimes it is useful to define a named scope by implementing a static method with the scope's name on the scoped class. For instance, when a method should decide...

...which existing scope should be the next link in the scope chain. Take this class for example: class Meal < ActiveRecord::Base named_scope :for_date, lambda { |date| :conditions => { :date => date...

We have released Modularity 2. It has many incompatible changes. See below for a script to migrate your applications automatically. There is no does method anymore We now use traits...

The script will rename your files and change your code. It will also syntax-check your files after conversion (since the script is not perfect). Check the diff...

...Linux and MacOS, they look horrible on Windows, a problem that gets worse with smaller font sizes. The culprit is something called font hinting: ... hinting is about... programming instructions that...

...hinting, causing horrible rendering for most fonts. Embedding autohinting information into font files A solution is to autohint fonts and replace the existing (bad) hinting with the autohinting information.

Ruby's standard library includes a class for creating temporary directories. Similar to Tempfile it creates a unique directory name. Note: You need to use a block or take care...

...of the cleanup manually You can create a prefix and suffix e.g. Dir.mktmpdir(['foo', 'bar']) => /tmp/foo20220912-14561-3g93n1bar You can choose a different base directory than Dir.tmpdir e.g. Dir.mktmpdir('foo', Rails.root.join('tmp...

You may want this for things where Rationals are being used, like when subtracting Date objects from one another. What's happening? Converting a Rational to a String usually...

...does something like this: 1.8.7 > Rational(2, 3).to_s => "2/3" 1.9.3 > Rational(2, 3).to_s => "2/3" 2.0.0 > Rational(2, 3).to_s => "2/3" However, when you have a...

...Content-Type on GET request (which have a blank body), an external API may still force you to send one. Angular's $http service will strip that header when the...

...is blank. [1] This is possibly a misconception of RFC2616. Here is how to send GET requests with a Content-Type header in Angular. Example Consider this request: $http({ method...

blog.intercom.io

A fantastic guide for a dilemma facing any web-based product. Here’s a simple set of Yes/No questions that you can quickly answer before you add another item to...

...your product roadmap. Saying yes to a feature request – whether it’s a to an existing customer, a product enquiry, a teammate, or a manager – is immediately rewarding. It’s...

Soon after having written our shell-for script, we wanted to easily get dumps of our productions machines, too. This is how we do it: dump-for staging [-s]

...dump to your project's tmp directory and name it according to the capistrano stage you're calling for, here: staging.dump. When you pass the optional -s option, the dump...

When using the asset pipeline your assets (images, javascripts, stylesheets, fonts) live in folders inside app: app/assets/fonts app/assets/images app/assets/javascripts app/assets/stylesheets With the asset pipeline, you can use the...

When you deploy, Rails runs assets:precompile which precompiles all assets into static files that live in public/assets. This way you have all the performance of static files...

makandra dev

...Railses. Consul now uses Memoizer for this. Temporarily change the current power When you set Power.current to a power in an RSpec example, you must remember to nilify it afterwards...

...Otherwise other examples will see your global changes. A better way is to use the .with_power method to change the current power for the duration of a block:

clipboardjs.com

We used zeroclipboard.js in some of our projects but now we switched to clipboard.js because it does not rely on flash. Flash support of the major browsers has ended.

...more advantages of clipboard.js: it consists only of a single javascript file, so it does not trigger additional requests with rails it automagically provides user feedback by selecting the text...

ActionMailer per default uses http as protocol, which enables SSL-stripping. When a logged-in user follows an http link to your application, it sends the cookies along with it...

...to send emails from public parts of your application with HTTP links and emails from SSL-protected parts with HTTPS, build a before_filter. If you need certain links with...

Git allows you to set push options when pushing a branch to the remote. You can use this to build an alias that automatically pushes a branch and creates a...

...merge request for it. Put this in your ~/.gitconfig in the [alias] section: mr = push origin HEAD -o merge_request.create -o merge_request.draft Now you can do git mr and a draft...

Our CI setup frequently sees this error while running yarn install: yarn install v1.22.19 [1/4] Resolving packages... [2/4] Fetching packages... error An unexpected error occurred: "https://registry.yarnpkg.com/typescript/-/typescript-3.9.7.tgz: unexpected end...

...here are some workarounds for Yarn 1. Increase Yarn's network timeout yarn config set network-timeout 600000 -g Retry yarn install until it succeeds The following will retry yarn...

thoughtbot.github.io

Let's say you have two factories that share some attributes and traits: FactoryBot.define do factory :user do screen_name 'john' email 'foo@bar.de' trait :with_profile do age 18 description...

age 18 description 'lorem ipsum' end end end You can re-use the shared fields by defining a trait outside the other factory definitions: FactoryBot.define do trait :person do...

Middleman is a static page generator that brings many of the goodies that Rails developers are used to. Out of the box, Middleman brings Haml, Sass, helpers etc. However, it...

...these gems to the Gemfile: group :test do gem 'cucumber' gem 'spreewald' gem 'capybara' gem 'selenium-webdriver' # Only for running tests in a real browser (suggested) gem 'capybara-screenshot' # Optionally...

hackernoon.com

...extremely popular amongst front-end developers the last couple of years. This isn’t surprising, as it has made it a lot easier for us to create dynamic layouts and...

jqueryui.com

UI sortable helps reordering items with drag 'n drop. It works quite fine. Proven configuration for sorting table rows When invoking the plugin, you may pass several options. This set...

...causing the thead border-bottom to grow // when the first table row is dragged tr.ui-sortable-helper:first-child + tr > td border-top: none

postgresql.org

...is pretty useful, but manipulating values of arrays can be awkward because of its syntax. Consider the following users table which each example below will start from: name topics

Bob {llamas} (PostgreSQL uses curly braces to represent arrays, true story.) Adding values Use the array_cat function, or the || operator. These calls will add the values "cats...

You can use JavaScript to get or set cookie values on the client. Using the vanilla JavaScript API In JavaScript, document.cookie is an accessor to all cookies on the current...

...site. It looks like a String, but its setter is actually more powerful. When setting cookies this way, remember to set the path=/ option. Reading cookies A result may look...

Our old solution for cronjobs, the "craken" plugin, is no longer maintained and does not work on Rails 3.2+. We will instead use the whenever gem. "Whenever" works just like...

...craken", by putting your rake tasks into the server's cron table. Everything seems to work just like we need it. Installation for new projects Add "whenever" to your Gemfile...

These are the results of the "personal tech stack survey". I've included only the most popular mentions, maybe it can help you find one or two useful tools for...

...Command line UI for git. htop (10 users) An improved "top". fzf (8 users) Provides super-fast fuzzy-finding in various contexts (for example for shell command history).

...you, like a browser would (e.g. move block elements out of parents which are specified to not allow them). >> Nokogiri::HTML.fragment(" foo bar ").to_s => " foo bar "

...HTML. And you don't want to be the one to blame when the SEO folks complain about an empty . To avoid said behavior, use Nokogiri::XML instead of Nokogiri...

...inherited methods but call the parent's implementation, too. In JavaScript, there is no simple "super" method like in Ruby -- so here is how to do it with Backbone.

...own initialize method, and you'd get this console output: Hello World. How to super But we want initialize of BaseClass to run as well -- and if you want to...