...named groups in Regex Exercises Find words Write a method second_words(string) that returns the second word of every sentence in the given string. Tip You can generate paragraphs...
...accessor sit on the same line. The superclass may be optional. ClassScanner#superclass should return nil in that case. Info In practice we would never parse Ruby code like this...
...The execution times in the examples are very high, usually a Bitmap Index Scan returns within a few milliseconds. The approach above assumes you have a search_text field, where...
Retrieve child nodes contents() (which behaves like children() except that it returns all types of child nodes) Filter manually using either plain Javascript or jQuery's filter...
Example Let's write a function that takes a jQuery element and returns an array of all child nodes that are text nodes: function selectTextNodes($container) { return $container.contents().filter...
}, "last_data_send_time" : null, tells me, that this process did not return any data to the client "path" : "/admin/search_user?query=4", shows me the request caused the...
...your command will reveal the issue; git on the other hand will use the return value of that call to decide if the state is good or bad.
Note: In case a string does not match the pattern, .match will return nil. With Ruby 2.4 the result of .match can be transformed to a Hash with...
The Edge Rider gem gives your relations a method #traverse_association which returns a new relation by "pivoting" around a named association. Say we have a Post model and each...
...traversal is achieved internally by collecting all foreign keys in the current relation and return a new relation with an IN(...) query (which is very efficient even for many thousand...
...function escapeHighASCII(string) { let unicodeEscape = (char) => "\\u" + char.charCodeAt(0).toString(16).padStart(4, '0') return string.replace(/[^\x00-\x7F]/g, unicodeEscape) } Escaping high ASCII in Ruby def escape_high_ascii(string...
...but includes the space character /[[:punct:]]/ Punctuation character /[[:space:]]/ Whitespace character ([[:blank:]], newline, carriage return, etc.) /[[:upper:]]/ Uppercase alphabetical /[[:xdigit:]]/ Digit allowed in a hexadecimal number (i.e., 0-9a...
...error, it will fail with a not-so-helpful error message: expected present? to return true, got false (Spec::Expectations::ExpectationNotMetError) Solution That can be fixed easily. RSpec expectations allow...
When you use method_missing to have an object return something on a method call, always make sure you also redefine respond_to_missing?. If you don't do it...
...is not defined within the receiver. When it has not been defined properly, its return value is a false negative! Thus, you need to patch respond_to_missing? as well...
...e.g. for use in the client's browser: function svgUri(text) { let svg = ` ${text} ` return 'data:image/svg+xml;charset=utf8,' + window.escape(svg) } See the attached JSFiddle for an example.
...If you want to check your setting, do the following. By default, it will return matching (see above). $ git config --global push.default matching So to change that to push only...
...of hashes, where the keys are the table headers from the first row table.headers Return only the first row table.rows Return all but the first row as an array of...
...HTTPS forwarding header, Rails recognizes that a request originally was on HTTPS and will return the correct protocol. Caveats: You need to harden your server setup to forbid the routing...
...that dynamically composes person.firstName and person.lastName: var person = { firstName: 'Guybrush', lastName: 'Threepwood', get fullName() { return this.firstName + " " + this.lastName; }, set fullName(name) { var parts = name.split(" "); this.firstName = parts[0]; this.lastName = parts[1]; } };
...use Object.defineProperty() instead: var person = { firstName: 'Guybrush', lastName: 'Threepwood' }; Object.defineProperty(person, "fullName", { get: function() { return this.firstName + " " + this.lastName; }, set: function(name) { var parts = name.split(" "); this.firstName = parts[0]; this.lastName = parts[1]; } });
...PATH=$(find-up .nvmrc | tr -d '[:space:]') if [[ $NVM_PATH == $NVM_PATH_WAS ]]; then return fi NVM_PATH_WAS=$NVM_PATH if [[ -f "$NVM_PATH/.nvmrc" ]]; then nvm use $(<"$NVM_PATH/.nvmrc...
...in replacement for trigger() (requires Unpoly): jQuery.fn.triggerNative = function(...args) { this.each(function() { up.emit(this, ...args) }) return this } With this you can replace a call like $element.trigger('change') with $element.triggerNative('change'). You...
if (!$event.originalEvent) { let eventProps = up.util.only($event, ...convertedPropNames) up.emit($event.target, eventName, eventProps) up.event.halt($event) } }) return this } Here is an example usage: $element.select2().enableNativeEvent('change') Make sure this function is applied...
text: ' ', } element.addEventListener('click', (event) => { navigator.share(data) event.preventDefault() }) } If you require feedback, navigator.share will return a promise that resolves or rejects, depending on whether the sharing was completed.
...an element is present, without errors raised, you can use #has_css?. It will return a Boolean – but will wait as well. If the element does not exist, it will...
...take the configured Capybara.default_wait_time for this check to return false, which is usually several seconds. The solution is to disable the waiting for just that check:
When your JavaScript bundle is so massive that you cannot load it all up front, I would recommend to load...
...can safely be represented in JavaScript. Number.MAX_SAFE_INTEGER will return the largest integer that can accurately be represented. For arbitrary large numbers (even >= 2^53), BigInt objects can be...
...is no longer possible. You might want to set event.returnValue = true, as a truthy returnValue was necessary to trigger the alert in Chrome < 119 You might want to return any...
...page? Changes you made may not be saved.' event.returnValue = leaveMessage // support for Chrome < 119 return leaveMessage // support for older browsers } } window.addEventListener('beforeunload', warnBeforeUnload...
Task.where("details->'a'->>'b' = ?", "value") # same as above, but via operator chaining -> returns JSON, whereas ->> returns text. Note that the key(s) must be passed with single quotes...