...is edited by WSYIWYG-Editor but want some length checking nevertheless, you need to strip all tags and then the special characters: def hard_sanitize(text) ActionController::Base.helpers.strip_tags(text...
...gsub(/[^[:word:]]+/, " ") end :001 > hard_sanitize("This is beautiful markup ") => "This is beautiful markup" If you allready have nokogiri on board, you can use that as well, though it has...
...when you work for clients from Europe or the US, there are two dominantish standards you should know about. Each of these has subtle differences. ISO 8601 This is adhered...
...to by most European countries. Weeks start on Monday and end on Sunday. To get the number of the weekday in Ruby as defined by ISO 8601, use Date#cwday...
Delegating methods to other objects is often helpful but the syntax of both def_delegators and def_delegator is a complete mess that makes your code hard to read.
...ActiveRecord::Base belongs_to :topic def_delegators :topic, :title, :category end Here, we can say Post.new.title and actually read title from the Post's Topic object. Because of what we...
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...
The SQL code generated by Graticule's spherical distance computation is insufficient and can lead to NULL distances in edge cases. The reason for this is that MySQL is performing...
...several sine and cosine computations which can result in slight rounding errors -- which is usually okay. Rarely, though, for the exact center of the given circle, it is then asked...
Given those modules: module A def foo; end def bar; end end module B end When you want to call...
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...
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...
...It must be fixed by patching the Jasmine sources. Fix for Webpacker Add the package string-replace-loader to your package.json. If you're on Webpacker 5 (Webpack 4) the...
...your config/webpack/environment.js: environment.loaders.prepend('fix-jasmine4-global-detection', { test: /jasmine-core\/lib\/jasmine-core\/jasmine\.js$/, use: [{ loader: 'string-replace-loader', options: { search: 'window.toString() === \'[object GjsGlobal]\'', replace: 'window.toString() === \'[object Window]\'' } }] }) Fix for ESBuild...
...MySQL and you know the "error" is okay (e.g. you've executed the same statement at the same time on 2 masters which sync each other), you can skip this...
...error and continue with the replication without having to set up the slave from the ground up. stop slave; set global sql_slave_skip_counter = 1; start slave;
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...
...written in pure Ruby and integrates with Rails applications. It provides features as automatic sizing of dots and lines (the more values, the thinner the graph's elements), custom or...
...predefined themes, different styles (bar, line, dot and many more) and multiple graphs in one chart. Installation In your Gemfile: gem 'rmagick', :require => false gem 'gruff' Then run bundle install...
...entering only http://example.com/). If you want to make a request to that site's web server without actually talking to www.example.com (e.g. because this is a load balancer...
...s address but you want to access one specific machine), you cannot just request machine1.example.com or localhost as the above vhost will redirect your request. When talking HTTP 1.1, your...
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).
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...
How to ignore new files Globally Add the path(s) to your file(s) which you would like to ignore...
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...
...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...
...A minimum total number of forms (both blank and pre-filled) so the user sees more than just 2 blank Actor forms when she is entering Actors for the first...
...the number of total rows. By default there is no limit. You can also set defaults for built records by adding additional keys to the options hash: form.build_nested_records...
can’t find executable rails for rails-3.2.3 (Gem::Exception) ... one of several...
...things might be wrong. You're using RVM It's possible that you have a system-wide gem executable (like rails) that requires a gem that is not available in...
...you pin all "important" files, you can follow method definitions, wildly open files from search results and have a ton of open tabs -- without the problem of finding the stuff...
...tabs of files that are currently in the focus of your work (important models, specs, etc): Right-click a tab and select "Pin tab" Or use a shortcut (see below...
On your local system that only hosts non-critical development data and only you have access to, you can store MySQL's root password in your home directory so you...
...out of the question if there's any confidential data in your databases. Assuming diligent screen-locking, an encrypted hard disk and correct permissions set on your credential file, it...
With ES2021 you now can use str.replaceAll(), Promise.any(), logical assignment operators, numeric separators and WeakRef on all major browsers except IE11. replaceAll JavaScript's replace(searchValue, replaceValueOrFn) by...
...default replaces only the first match of a given String or RegExp. When supplying a RegExp as the searchValue argument, you can specify the g ("global") modifier, but you have...
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...