...pool has a "reaper thread" that periodically looks for connections from inactive threads and returns them to the pool. By default the reaper runs once every 60 seconds. You can...
Will the pool ever close an unused connection? A released connection will be returned to the pool, but not disconnect from the database server. The connection will remain connected...
...not raise an exception. Instead, full_name will simply be nil, and salutation('Bob') returns 'Hi '. The same would happen in an else branch: def salutation(first_name, last_name...
...queue sizes, last run of Sidekiq) your application should have a monitoring route which returns a json looking like this: { "sidekiq": { "totals": { "failed": 343938, "processed": 117649167 }, "recent_history": {
...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...
...reflect on the class of an instance, e.g. to decide which partial to render: Returns an instance of the specified klass with the attributes of the current record. This is...
...carefully checked. In particular you will need to clean up a lot of unnecessary return statements...
# 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...
...fscommand function to call a Javascript function with a fixed name from Javascript. In return Javascript can sort of communicate with ActionScript by calling SetVariable(name, value) on the Flash...
...a method's source location Ruby 1.9 adds a method Method#source_location that returns file and line number where that method is defined. class Example; def method() end; end...
Some browsers define window.event, which will return a copy of the "current" event. However, this is not defined by the W3C. Most importantly, Firefox does not support it, neither do...
...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.
...service redis-server restart Confirm your configuration has been updated. The following command should return "OK". redis-cli select `nproc --all...
...rescue ActionController::ParameterMissing {} end def note_scope # Restrict what the user may access by returning a scope with conditions. Note.all end def load_notes @notes ||= note_scope .strict_loading # Raise...
...preloaded will raise an ActiveRecord::StrictLoadingViolationError. There is a private method #note_params that returns a permitted attributes hash that can be set through the #update and #create actions.
...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...
...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...
...other onbeforeunload handlers: $(function(){ document.body.onbeforeunload = function() { for(editorName in CKEDITOR.instances) { if (CKEDITOR.instances[editorName].checkDirty()) { return "Unsaved changes present!" } } } } A robuster implementation example Note: Don't forget to mark the 'search...
...method for others which need to know for unsaved changes function isUnsavedChangeConfirmed() { if (isUnsavedChangePresent()) { return confirm(warningMessage + "\n\n" + confirmationMessage); } else { return true; } } // opens a confirmation dialog if unsaved changes...
...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...
image = params.require(:gallery).require(:add_images).first uploader = Image.new.teh_image uploader.cache! image # Return the image's cache name to the client render json: uploader.cache_name end end
submitButton.removeAttr 'disabled' # Prevent unsubmittable form (dirty fix) Helper = # Clone the template row # @return: The newly created image row addImageToForm: -> row = imageTemplate.clone() Helper.increaseTemplateIndices() row.removeClass 'gallery-form--template' row.insertBefore imageTemplate...
JavaScript Create an object with no properties with Object.create(null) => {} The comma operator returns its last expression
...class Project < ActiveRecord::Base def user "foo" end belongs_to :user end Project.new.user still returns "foo". The reason for this is that what belongs_to does is actually this:
In Ruby on Rails, all objects have a useful blank? method. It returns true for nil but also for empty strings or empty arrays. There is also a universal method...
...present? which returns true for all values that are not blank?. In JavaScript you need to roll your own implementation of blank? and present?. If your application uses Unpoly you...
...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...
...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...
...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...