Just found out about a great feature in Rails that seems to be around since Rails 2. Start a console with the --sandbox (or -s) parameter: rails console --sandbox
...database will be rolled back on exit. Warning Changes beyond the database (deleting files, sending emails, etc) cannot be rolled back...
If you have an html_safe string, you won't be able to call gsub with a block and match reference variables like $1. They will be nil inside the...
...with rails_xss) as well as Rails 3 applications. Here is a fix to SafeBuffer#gsub. Note that it will only fix the $1 behavior, not give you a safe...
This card shows you how to format a card's content using Markdown. We use the Commonmarker interpreter, so here are examples for its dialect. Formatting **Bold** Bold _Italics_
Add a new line for a paragraph. Headlines Underline headlines with an equals sign or dash -- or start a line with a hash symbol: Hello World ----------- Lorem ipsum...
...take the content-box for the element's shape, i.e. without margin, padding and border. shape-outside: content-box Set the margin where you want it, e.g. 10px left and...
Set the shape-margin to the same size as the margin. Note that the shape-margin can never exceed the (rectangular) margin-box of an element! --margin: 10px;
If you want to see how long your database queries actually take, you need to disable MySQL's query cache. This can be done globally by logging into a database...
SET GLOBAL query_cache_type=OFF; and restart your rails server. You can also disable the cache on a per query basis by saying SELECT SQL_NO_CACHE...
...ago and don't remember which one it is? You can go to chrome://settings/appearance (on Chrome 61+) to see the theme's name, and click a link to open...
...it in the Chrome Web Store. If you are on an older version, or if the above no longer works, you have to check Chrome's Preferences file. Linux /home/YOUR_USER_NAME/.config/chromium/Default/Preferences...
Sometimes you may want to print files from the command line, especially when you have lots of them. You can use lp for that. To print a single example.pdf file...
...on your default printer, simply say: lp example.pdf lp accepts multiple filenames, so to print all PDF files in the current directory: lp *.pdf You can specify a printer via...
Angular directives with isolate scopes have three different variable binding strategies, of which one is =. Example: # HTML # Coffeescript @app.directive 'panel', -> scope: evaluated: '=value' bound: '=twoway' link: -> scope.evaluated # = false scope.bound = 'foo...
...bound with = (value, twoway) have their value evaluated as Angular expression in the parent scope's context and have the result assigned to the corresponding scope variable (evaluated, bound). It...
See the attached link for a useful overview of modern (and classic) DOM API methods, like matches, contains, append, cssText, etc. You will still need to look up some documentation...
...e.g. on how to modify a ClassList, but it's still better than browsing interfaces and superclasses of Element on MDN without knowing what to look for. When coming from...
The sprintf method has a reference by name format option: sprintf("% d : % f", { :foo => 1, :bar => 2 }) # => 1 : 2.000000 sprintf("%{foo}f", { :foo => 1 }) # => "1f" The format identifier % stands for...
...this example we are using %s identifier to replace strings. class Fetcher FIND_URI = 'https://someapi.com/3/search/record?query=% s&include_many=% s&language=en-US&page=1' # some public methods
Chromedriver (or selenium-webdriver?) will not reliably scroll elements into view before clicking them, and actually not click the element because of that. We've seen this happen for elements...
...a 40px button). Our assumption is that the element is considered visible (i.e. Capybara::Selenium::ChromeNode#visible? returns true for such elements) but the Selenium driver wants to actually click...
If others on a call (Skype, SIP, ...) can not hear you loud enough, your volume levels are probably too low. Also, Skype may be changing your mixer levels.
...proper recording volume Open your mixer software (run pavucontrol). Switch to input devices. If you have more than one recording device, find the correct one. Make a test call to...
...has to decide whether and how to do authorization. The usual approaches are: Using send_file with a regular controller. This is secure, but potentially slow, especially for large collections...
...This is fast (because Apache can deliver assets without going through Rails), but less secure. When going with the "unguessable URL" approach, it is possible to somewhat increase security by...
Stringex is a gem that offers some extensions to Ruby's String class. Ruby 1.9 compatible, and knows its way around unicode and fancy characters...
...Examples for stringex's String#to_url method: # A simple prelude "simple English".to_url => "simple-english" "it's nothing at all".to_url => "its-nothing-at-all"
Today I needed to execute a ruby gem executable with sudo. But, surprisingly, bash would tell me command not found for the gem that ran lovely without sudo.
...are installed to /var/lib/gems/1.8/bin, which is not in sudo’s PATH. Unfortunately, you can’t change the path, since sudo for Ubuntu is compiled with the --with-secure-path option...
You have an async function that rejects: async function failingFunction() { throw new Error("Something went wrong") } When you call that function in a test, your test will fail:
}) The failure message will look like this: Unhandled promise rejection: Error: Something went wrong You can fix this by expecting the state of the returned promise:
In Rubocop you might notice the cop Style/CaseEquality for e.g. this example: def foo(expected, actual) expected === actual end In case expected is a Regex, it suggests to change it...
...foo(expected, actual) expected.match?(actual) end In case expected is a Regex or a String, you need to keep ===. Otherwise the actual expression is always converted to a regular expression...
In CI test runs I noticed that string sorting order changed after switching from a debian-based PostgreSQL docker image to one that is based on Alpine Linux.
...sorting: bar Bar foo Foo Alpine image sorting: Bar Foo bar foo Explanation Alpine Linux is a very slim linux distribution that results in small docker image sizes (roughly 100MB...
You can scale background images in CSS to the container size using background-size (Demo). Commonly, we use contain or cover because we want to preserve the image's aspect...
If you do not want to do that, simply provide scaling values for X and Y: background-size: 100% 100% (a simple 100% would mean 100% auto and respect...
gem install foobar --version="=2.3.0.alpha2" Also bundle update will never update a stable version to a pre-release version unless the user explicitly requests it in the Gemfile...
...gem 'foobar', '=2.3.0.alpha2' A note on Semantic Versioning Semantic Versioning has a naming convention for pre-releases that is incompatible with that from RubyGems. In Semantic Versioning, the version...
...what git checkout and git reset do. Git basics A commit holds a certain state of...
...a directory and a pointer to its antecedent commit. A commit is identified by a so-called ref looking something like 7153617ff70e716e229a823cdd205ebb13fa314d. HEAD is a pointer that is always pointing...
...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...