It might sometimes be useful to check whether your Rails application accesses the file system unnecessarily, for example if your file system access is slow because it goes over the...

...or modification times, whereas your application could determine all this from your database. Introducing strace One option it to use strace for this, which logs all system calls performed by...

makandra dev

Sometimes you might want to check a short link for it's destination before clicking on it. Additional you get information about the redirects. Use the magic + at the end...

...of the short url! Google: https://goo.gl/TXe0Kx => https://goo.gl/TXe0Kx+ Since the original publication of this post, Google's URL shortening service goo.gl has been discontinued. Bitly:

...you store files for 500k records, that store_dir's parent directory will have 500k sub-directories which will cause some serious headaches when trying to navigate the file system...

...still only have 500 directories inside /app-root/public/users/avatar/. And inside each of them, at most 1000 sub-directories. But I have millions of files If you expect to store a lot...

Using rem only ever makes sense when the root font size is dynamic, i.e. you leave control to the user. Either by a) respecting their user agent defaults, or...

...by b) offering multiple root font sizes in your application. By defining @media queries in rem, they will accommodate to the root font size of your page. At a larger...

We're always striving towards keeping our website's JavaScript as small as possible. If you're using webpack(er), you can use the webpack-bundle-analyzer plugin to get...

...a good overview, which of your JavaScript modules take up how much space, and where you can optimize. To use it, add it via npm or yarn yarn add webpack...

Sometimes you'll find yourself with a set of tasks that require similar code for different models. For example, if you start working at a new application that allows CRUDing...

...pears and apples, each commit might look similar to this: commit 41e3adef10950b324ae09e308f632bef0dee3f87 (HEAD -> ml/add-apples-12345) Author: Michael Leimstaedtner <michael.leimstaedtner@acme.com> Date: Fri Aug 11 09:42:34 2023 +0200 Add Apples...

...updates all your gems at once. Given that many gems don't care about stable APIs, this might break your application in a million ways. To stay sane, update your...

...This ensures that your libraries are up-to-date while it's easy to spot major version bumps which may break the app. Projects that have not been updated in...

makandracards.com

...bug) and want to use git bisect to find out when it was introduced? Smart kid. If you have a shell command ready to reveal if your current state is...

...other hand will use the return value of that call to decide if the state is good or bad. First, start bisecting git bisect start Then tell git which revisions...

...the commit which was deployed. If you want to know the currently deployed release, simply SSH to a server and view that file. $ cat /var/www/my-project/current/REVISION cf8734ece3938fc67262ad5e0d4336f820689307 Capistrano task

...application is deployed to multiple servers, you probably want to see a result for all of them. Here is a Capistrano task that checks all servers with the :app role...

developer.mozilla.org

You can do so much more than console.log(...)! See the attached link for a great breakdown of what the developer console can give you. Some of my favorites: console.log takes...

E.g. console.log("Current string:", string, "Current number:", 12) Your output can have hyperlinks to Javascript objects E.g. console.log("Check out the current %o, it's great", location)

github.com

Capybara-screenshot can automatically save screenshots and the HTML for failed Capybara tests in Cucumber, RSpec or Minitest. Requires Capybara-Webkit, Selenium or poltergeist for making screenshots. Screenshots are saved...

...into $APPLICATION_ROOT/tmp/capybara. Manually saving a page Additionally you can trigger the same behavior manually from the test using Capybara::Session#save_and_open_page and Capybara::Session#save_screenshot...

makandra dev

Geordi provides a pretty neat way to generate beautiful commit messages according to your stories in Linear: geordi commit Geordi reads from a .geordi.yml file inside your repo and connects...

...to Linear to list started and finished stories with their title. Choosing one of them generates a commit message including id and title from Linear app and a link to...

makandra dev

...is just awesome. Install via apt-get or brew. Handy commands t ("tree"): Directory-structure based access. You'll see the current directory annotated with the latest change date and...

...date and author. d ("diff"): Like ENTER on a commit, but arrow keys will scroll the diff! /: Search current view (e.g. commit list, diff). Jump to next hit with n...

...the following content: class AddAttachmentToNotes < ActiveRecord::Migration[6.0] def change add_column :notes, :attachment, :string end end Don't forget to rename the class and change the column details to...

...you access http://yourpage.com/system/attachments. 3) Using expiring URLs There are also option to generate self-expiring URLs, which might be a good compromise between performance and safety. It is...

...and Redis.current=: `Redis.current=` is deprecated and will be removed in 5.0. If your application still uses Redis.current, you can only fix it by no longer using it. Here is how...

...There is probably already a constant like REDIS_URL that you use to configure Sidekiq or similar. So just use that one. redis = Redis.new(url: REDIS_URL) redis.get('example') # instead...

Sometimes you need to remove high Unicode characters from a string, so all characters have a code point between 0 and 127. The remaining 7-bit-encoded characters ("Low-ASCII...

...can be transported in most strings where escaping is impossible or would be visually jarrring. Note that transliteration this will change the string. If you need to preserve the exact...

Let's say you have a gem which has the following module: module SuperClient def self.foo 'Foo' end def bar 'Bar' end end For reasons you need to override foo...

...library extensions). Try to avoid it if possible. Add a lib/ext/super_client.rb to your project (see How to organize monkey patches in Ruby on Rails projects) Add the extension, which overrides...

When your Rails application server raises error, Capybara will fail your test when it clears the session after the last step. The effect is a test that passes all steps...

...behavior will help you to detect and fix errors in your application code. However, sometimes your application will explode with an error outside your control. Two examples: A JavaScript library...

makandra dev
rubydoc.info

CarrierWave comes with some RSpec matchers which will make testing more comfortable. Let's say you have an Uploader like this: class MyUploader < CarrierWave::Uploader::Base include CarrierWave::MiniMagick

...different versions of your uploaded files: version :small do process resize_to_fill: [100, 100] end version :medium do process resize_to_fit: [200, nil] end version :large do

makandra dev

...or ::1 (IPv6) can only be reached from your own PC: Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port Process tcp LISTEN...

...address 0.0.0.0 can be reached from other PCs on your network: Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port Process tcp LISTEN...

bibwild.wordpress.com

...is much more than a lightweight wrapper around Ruby's net/http. In particular: A single HTTPClient instance can re-use persistent connections across threads in a thread-safe way.

...a custom and configurable SSL certificate store (which you probably want to disable by default) Manages cookies Can make asynchronous requests (spins off a thread internally) Allow to set a...

nolanlawson.com

In my experience, the most common sources of memory leaks are APIs like these: addEventListener. This is the most common one. Call removeEventListener to clean it up. setTimeout / setInterval. If...

...you create a recurring timer (e.g. to run every 30 seconds), then you need to clean it up with clearTimeout or clearInterval. (setTimeout can leak if it’s used like...

This is a small example on how you can check if your Postgres index can be used by a specific query in you Rails application. For more complex execution plans...

...it might still be a good idea to use the same path of proof. 1. Identify the query your application produces query = User.order(:last_name, :created_at).to_sql

The Web Animations API has great browser support, and you should be using it to animate DOM elements from JavaScript, or to control or wait for CSS animations.

...Its API probably a bit different from how your favorite frontend framework animates, but simple enough to get used to. Like for CSS animations, you specify keyframes to animate. This...