SVG files are often much larger than necessary, containing comments, metadata, hidden elements etc. Optimize them with this tool. Web UI: https://jakearchibald.github.io/svgomg/ Binary: https://github.com/svg/svgo
...for a properly scaling SVG, you need to keep the viewBox attribute. There's an option --disable=removeViewBox for this...
...IDENTIFIED BY 'some_password'; GRANT REPLICATION SLAVE ON *.* TO 'replicator'@'%'; Adjust MySQL configuration : Edit /etc/mysql/my.cnf: server-id = 1 log_bin = /var/log/mysql/mysql-bin.log replicate-do-db = some_project_production replicate-do-db...
...other_project_production replicate-ignore-db = mysql server-id needs to be unique among all connected master and slave servers. When replicate-do-db is provided only the chosen databases...
# the value from the form field's ngModel (which means it's not sent to the # server, and old values would not be overwritten). # # This directive makes sure that...
...form fields with an invalid value return an # empty string instead of undefined. for elementType in ['input', 'textarea', 'select'] @app.directive elementType, -> priority: 1 restrict: 'E' require: '?ngModel' link: (scope, element...
...unwrap(). Here is how. Consider the following example element. $container = $(' Hello World ') Let's say we want to discard any tags, but keep their contents. Simply find them, then dive...
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...
When using state_machine you sometimes need to know whether an object may execute a certain transition. Let's take an arbitrary object such as a blog article as an...
...example that has those states: A -> B -> C -> D Additionally, you have transitions between the states as shown above. Let's call the transition between 'A' and 'B' transition_ab...
...we use pagination Exercises Create 7500 movies in MovieDB (hint: Doing it in a single transaction is much faster). Load the movies index and measure how long it renders.
...the movies index render now? Inspect the HTML generated by will_paginate. Customize the style so it matches the look of your MovieDB. tail -f log/development.log and see which queries...
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...
...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...
Note: Making a reverse proxy with nginx is much more straightforward. A reverse proxy is a "man in the middle" server that tunnels requests to another server. You can use...
...makes sure that it can fetch from HTTPS internally. You've basically built your custom SSL-stripping MITM attack server. If your proxy server should be accessible over HTTPS, use...
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...
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...
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...
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...
A print stylesheet is easy to create. Choose a font suited for paper, hide some elements, done. Unfortunately print stylesheets often break as the application is developed further, because they...
...are quickly forgotten and nobody bothers to check if their change breaks the print stylesheet. This card describes how to write a simple Cucumber feature that tests some aspects of...
ActiveRecord provides the ids method to pluck ids from a scope, but what if you need to pluck Global IDs? While you could just call map(&:to_global_id) on...
...your scope, this approach would instantiate each record just to do that. When you have many records, this will at the very least be slow. Here is a method that...
This is how you regain disk space from OpenStack instances if you are using kvm and qcow. If your instance used up all configured disk space once the disk file...
...remains big. You can end up in a situation where for example the instance use only 20GB disk space but the disk file on the server has 100GB (or even...
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...
...of control”. A function that accepts a callback instead of a return value is saying, “Don’t call me, I’ll call you.”. Promises un-invert the inversion, cleanly separating...
...the input arguments from control flow arguments. This simplifies the use and creation of APIs, particularly variadic, REST and spread arguments. Note that promises are not a drop-in replacement...
Haml 3.1.2 displays single quotes in FormBuilder#text_ field html escaped. You may see something like that: David's Chapter Looking at the page's HTML, your field's...
Capistrano 2 brings the shell command which allows you to run commands on your deployment targets. There is also invoke to run a command directly from your terminal.
...allow running Capistrano tasks or shell commands, and scope to individual machines or machine roles. Unfortunately Capistrano 3 does not include these commands any more. cap shell Basics
This is an extract from the linked article. It shows an approach on how to implement encrypted passwords with the AWS Key Management Service (KMS). For most applications it's...
...enough to use a hashed password with a salt (e.g. the gem devise defaults to this). Upon password creation Generate hash as hash of password + salt. Encrypt the hash with...