...carefully checked. In particular you will need to clean up a lot of unnecessary return statements...
...have this use case in tests. Example Time.parse('2020-08-09 00:00') will return different results e.g. 2020-08-09 00:00:00 +0200 depending on the Rails timezone...
...want to have the given time in UTC because that's what the API returns. it 'returns a valid API response', vcr: true do expect(client.get('/users/1')).to have_attributes...
...module_function def redis_url "redis://localhost:#{port}/#{db_number}" end def db_number # Returns a number between 2 and n. # Redis db#1 is used for development.
# of all files in app/. Files cannot change in tests, so we immediately # return if we have compiled before. if test? if @compiled_before return true else @compiled_before...
...its cache store, this is how you can list existing keys: Check: Rails.cache should return an ActiveSupport::Cache::RedisCacheStore. Rails.cache.redis.with(&:keys) lists existing keys. Cached views start with "views/".
...timer is a timeout that, when triggered, schedules itself again and again. Because $timeout returns a promise for the timer's execution, and because Coffeescript uses the last expression in...
...a block as implicit return value, this pattern is a great way to create an infinitely growing object graph. More details here. This code leaks more and more memory over...
...in Coffeescript...: @app.filter 'htmlSafe', ['$sce', ($sce) -> $sce.trustAsHtml ] # ...or JS: app.filter('htmlSafe', [ '$sce', function($sce) { return $sce.trustAsHtml; } ]); # Usage: This is a replacement for the ng-bind-html-unsafe directive which has...
...might think of XPath's contain() function: page.find(:xpath, ".//*[contains(text(), 'hello')") Unfortunately that returns a lot more elements than you expect:
hello ] What you need to do instead is...
...document.body.append(overlay);function getElement(event){overlay.style.pointerEvents='none';var element=document.elementFromPoint(event.clientX,event.clientY);overlay.style.pointerEvents='auto';return element};document.addEventListener('mousemove',function(event){var element=getElement(event);if(!element)return;var position=element.getBoundingClientRect...
...document.body.append(overlay); function getElement(event) { overlay.style.pointerEvents = 'none'; var element = document.elementFromPoint(event.clientX, event.clientY); overlay.style.pointerEvents = 'auto'; return element; } document.addEventListener('mousemove', function(event) { var element = getElement(event); if (!element) return; var position = element.getBoundingClientRect...
...by disabling an unused compression webpackConfig.plugins = webpackConfig.plugins.filter(plugin => { const isBrotliCompression = plugin.constructor.name === 'CompressionPlugin' && plugin.options.algorithm === 'brotliCompress' return !isBrotliCompression }) Older Webpacker versions might need this instead: // Save compile time by disabling an unused...
...JavaScript function that you can use for that: function debounce(callback, delay) { let timer return function(...args) { clearTimeout(timer) timer = setTimeout(() => { callback.apply(this, args) }, delay) } } Usage example function onScroll() { ... } window.addEventListener...
...match a certain criteria or not, Enumerable#partition can come in handy. # Enumerable#partition returns two arrays, # the first containing the elements of enum # for which the block evaluates to...
JavaScript Create an object with no properties with Object.create(null) => {} The comma operator returns its last expression
...call Nokogiri::HTML to be more liberal about accepting invalid XML. xml / 'list item' returns all matching nodes; list item is used like a CSS selector xml / './/list/item' also returns...
...an XPath selector XPath seems to be triggered by a leading . or / xml % 'item' returns the first matching node node.attribute('foo') returns the attribute named foo node.attribute('foo').value returns...
...simply mock time using Timecop.travel or its respective Spreewald steps and the browser will return the same time in new Date(). If you would like to stop the time from...
...write something similar using jQuery.grep. let classes = Array.from($element.prop('classList')) let existingModifiers = classes.filter(className => { return className.match(/^is-/) }) $layout.removeClass(existingModifiers.join(' ')) Note that classList is native DOM API and returns a DOMTokenList...
...read: forever) you may pass a function that disects an element's class, and returns a string that will then be removed through the "classic" string approach. It's a...
...developer who just wrote it. To check its readability, a good strategy is to return after a few months. You will have forgotten the direct context, but will still be...
...Summary ---------------------------- So, what's the final verdict on those 7 closure-like entities? "return" returns from closure True closure? or declaring context...? Arity check? --------------- ----------------------------- ------------------- 1. block (called with yield) N...
...block (&b => f(&b) => yield) N declaring no 3. block (&b => b.call) Y except return declaring warn on too few 4. Proc.new Y except return declaring warn on too few...
...and .then() do not behave the same. In particular, if a standard promise callback returns another promise, this will delay the resolution of all later promises. jQuery's then behaves...
...the response, make a second request to /bar: var promise = $.ajax('/foo').done(function() { return $.ajax('/bar'); }); Quiz: When does promise resolve? Well, if you use done, it will resolve...
...into your ~/.config/awesome/rc.lua. It supplies two methods: execute_command will run a command and return its output. Multiple lines will be joined into one line. The code is from the...
...method that takes a command to run and a timeout in seconds. It'll return an object which contains a widget that you can put into your panel. ^
...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 the center of...
...achieve this by using a callback. before_initialize :set_newsletter private def set_newsletter return unless [nil, ''].include?(receive_newsletter) self.receive_newsletter = (user.role == 'customer') end Note: When using active_type...
...in mind that their syntax is a bit different. UnderscoreJS In UnderscoreJS, methods always return a value: x = [1, 2, 2] _.uniq(x) // => [1, 2] _(x).uniq() // => [1, 2]
...chain, and call value() to terminate the chain. _.chain(x).uniq().map(function(i) { return i + 10 }).reverse().value() // => [12, 11] LoDash In LoDash, methods called from _ (like _.uniq) will...
var languageString = navigator.language || navigator.userLanguage || ''; var language = languageString.split(/[_-]/)[0]).toLowerCase(); switch (language) { case 'de': return "/de/"; case 'en': return "/en/"; default: return "/en/"; } })(); Note that old IEs support only navigator.userLanguage...
...which returns the regional setting of the operating system. Fallback For users without JavaScript, you may want to redirect them to your default locale. Do that by adding a meta...