...browser's HTTPS handling works as expected (which might be compromised e.g. due to security products or enterprise proxy servers...
Plot graphs in Ruby WebGraphviz renders in your browser via JavaScript (to store the rendered graph, extract the SVG using your browser's DOM inspector) GraphViz with DOT: Online...
...graphviz.christine.website/ or offline https://makandracards.com/makandra/1589-auto-generate-state_machine-graphs-as-png-images Balsamiq Draw.io Excalidraw Asciiflow Google Presentation Egon.io: Domain storytelling with replay functionality (good to visualize and present flows) Gnuplot Ruby Bindings: Especially for more...
Note: You won't need this for single lines of text. In this case it is better to just use the text-overflow property: Use CSS "text-overflow" to truncate...
...use -webkit-line-clamp in your CSS/SASS to natively render an ellipsis (...) after a specific amount of lines for a multi-line text in your HTML. Earlier, it was necessary...
Goals After finishing this lesson you should be able to read and write simple Ruby programs. Gain an understanding of the following concepts: Working with basic datatypes: String, Integer...
Classes and inheritance The difference between class methods and instance methods (def self.method vs. def method) Modules and include Input and output Simple regular expressions Resources Tutorials
While the Software Design Basics card tried to make a point about writing self explanatory code, it's still essential for every application to maintain a good documentation. The...
...README file is essential for fellow engineers to get started quickly, as it contains documentation of all major moving parts of the given app. Resources README Driven Development
When you make a simple TCP connection to a remote server (like telnet), your client won't normally notice when the connection is unexpectly severed on the remote side. E.g...
...if someone would disconnect a network cable from the server you're connected to, no client would notice. It would simply look like nothing is being sent. You can detect...
...are usually believed to have worse performance than those defined via def. Hence, developers sometimes prefer using class_eval to define methods using def, like this: class_eval "def #{attribute...
...for_realsies?; do_things; end" You can benchmark methods defined like this and will see that those defined via def actually do perform better. Basically, it ranks like this:
A recent patch level Ruby update caused troubles to some of us as applications started to complain about incompatible gem versions. I'll try to explain how the faulty state...
...care of a few things: The new Ruby version is installed The Bundler version stated in the Gemfile.lock is installed Geordi is installed (for database dumps) The gems of the...
tl;dr: Ruby's Bundler environment is passed on to system calls, which may not be what you may want as it changes gem and binary lookup. Use Bundler.with_original...
...env to restore the environment's state before Bundler was launched. Do this whenever you want to execute shell commands inside other bundles. Example outline Consider this setup: my_project/Gemfile...
Bundler allows you to specify the name of the Gemfile you want to bundle with the BUNDLE_GEMFILE environment variable. BUNDLE_GEMFILE=Gemfile.rails.7.2 bundle By default, bundler will look...
...have multiple Gemfiles in your project, which cannot all be named Gemfile. Let's say for example, you maintain a gem and want to run automated tests against multiple rails...
...at the same time. When assets did not change, we do not want to spend time compiling them. Here is our solution for all that. Its concept should work for...
...all test suites. Copy the following to config/initializers/webpacker_compile_once.rb. It will patch Webpacker, but only for the test environment: # Avoid hardcoded asset hosts in webpack, otherwise all chunks would be loaded...
When you want to filter records in a model where a string column roughly matches a given term, you can use PostgreSQL’s trigram similarity search. Writing a fuzzy query...
User.where("similarity(name, ?) > 0.3", "John") This finds all users where the name is similar to "John" with a similarity score above 0.3. You can tune the threshold:
When giving a presentation where you do some coding, the font size you usually use is probably a bit too small and makes code hard to read for users on...
...smaller screens or low-bandwidth connections when the image quality is lower. Here are two solutions. Presentation Mode RubyMine offers a "Presentation Mode" which you can use. Simply navigate to...
When internationalizing your Rails app, you'll be replacing strings like 'Please enter your name' with t('.name_prompt'). You will be adding keys to your config/locales/*.yml files over...
...the right place is a challenging task. The gem i18n-tasks has you covered. See its README for a list of things it will do for you. Note
...a new callback to your model that (e.g.) caches some data when it is saved. Now you need to run that callback for the 10000 existing records in the production...
Write a clever migration, possibly by embedding the model into the migration script. Open the Rails console after deployment and re-save every single record. You should probably...
to create a Gallery that has a name and has_many :images, which in turn have a caption to offer the user a single form to create...
...with any number of images immediate uploads with a progress bar per image a snappy UI Enter jQuery File Upload. It's a mature library that can do the job...
When you need to see the content of a page (i.e. not all the HTML but the relevant text body) you can do pp (html_content) pp will format the...
...html String human readable pretty printed where html_content can be replaced by one of the following commands: Rails body or response.body Capybara: page.driver.html.content page.body Webrat: Nokogiri::HTML(response.body).content...
Sometimes we write plain SQL queries in migrations so we don't have to mock ActiveRecord classes. These two migrations do the same: class Migration1 < ActiveRecord::Migration[5.2]
...Migration2 < ActiveRecord::Migration[5.2] def up add_column :users, :trashed, :boolean update("UPDATE users SET trashed = #{quoted_false}") end end The plain SQL migration is less code, but has a...
...an error if your application logic ever violates it. class User < ApplicationRecord has_one :session, dependent: :destroy end class Session < ApplicationRecord belongs_to :user end create_table :users do |t...
end create_table :sessions do |t| t.references :user, null: false, foreign_key: true, index: { unique: true } # Don't forget the uniqueness here t.timestamps
...listen to other events. Quirks The "default behavior" in this case is not to show an alert, and preventing this default means the alert is being shown. In ancient browsers...
...customize the alert text, but this is no longer possible. You might want to set event.returnValue = true, as a truthy returnValue was necessary to trigger the alert in Chrome...
Rails comes with a Rake task notes that shows code comments that start with "TODO", "FIXME", or "OPTIMIZE". While it's generally not good practice to leave them in your...
...not yet available. To keep track of them, run rake notes. Its output looks something like this: $ rake notes app/controllers/frontend/media_documents_controller.rb: * [ 6] [TODO] should be part of a publication workflow app/helpers/frontend/slider_helper.rb...
Let's say we have posts with an attribute title that is mandatory. Our example feature request is to tag these posts with a limited number of tags. The following...
...In most cases you want to use Option 4 with assignable values. The basic setup for all options looks like this: config/routes.rb Rails.application.routes.draw do root "posts#index" resources :posts, except...
When you do a bitwise copy using the dd tool you will not see any output until it completes or an error occurs. However, you can send a command signal...
...to the process to have it show its progress so far. From another terminal, simply call (be root or use sudo): pkill -USR1 dd This makes dd write something like...
Most browsers have built-in drag and drop support for different page elements like text and images. While this may be useful in most situations, it may become annoying in...
...functionality. This does no longer work. You may now achieve this by explicitly preventing the startdrag-event:
const noDragElement = document.querySelector('no-drag-pls') noDragElement.addEventListener('dragstart', event => event.preventDefault())