...know anything about the API internals. It feels more natural, that you don't call client internals from your models. Only the public methods like GithubClient::Client.new.users('makandra GmbH') or...
...def log(message) message.each_line do |line| Rails.logger.info(line.rstrip) end end You can then call log with your multi-line string and each line will be tagged. To improve even...
Check if ~/.cache/selenium/se-metadata.json exists. (It contains a "ttl" timestamp of its last/next anaytics call. You can parse it with Ruby's Time.at.) Opt out You can opt out either...
Now, another commit will be checked out. See if the issue persists and call git bisect good or git bisect bad, resulting in another commit being fetched and so...
...window rendering effects added by a window manager, and browsers don't provide a callback that would allow to detect the end of windows size changing process. Capybara provides a...
...WebDriverError, 'Switch to desired window before changing its size' unless handle == :current # Chromedriver API call named "set_window_rect" set_window_rect(width: width, height: height) end end
...inlined, because it is only used once. Let's use a similiar input, but call fn() twice: function fn() { if (a) { return 'foo' } else if (b) { return 'foo' } else {
...console.log(o()) Note how: The function remains in the compressed output, as it is called more than once. The function name has been shortened to o, as it is not...
To reload a single-item association in Rails 5+, call #reload_ : post.reload_author In older Railses you can say post.author(true...
...that RequestStore just uses Thread.current under the hood and injects a Rack middleware that calls RequestStore.clear! after each request. If you use RequestStore in a non-request context where (like...
...archived => false) authors = posts.traverse_association(:author) You can traverse multiple associations in a single call. E.g. to turn a relation of posts into a relation of all posts of their...
...well as to query the record for registered errors. This object is returned when calling .errors: errors = @user.errors # => # Here are some helpful messages of its API: [ ] Returns an array of...
...Will retrieve the error message from the locale files. get( ) (Almost) an alias of []. Calls messages[ ] and returns an array of error messages for that attribute. include?( ) Returns whether there...
...to express "Do this, and once you're done, do that". In contrast to callbacks, promises are easily chainable. From the readme of Q, an early implementer of the pattern...
...The callback approach is called an “inversion of control”. A function that accepts a callback instead of a return value is saying, “Don’t call me, I’ll call you...
...that table object will have the cryptic type Cucumber::Ast::Table. Don't immediately call table.raw to convert it into an array of arrays! Cucumber::Ast::Table has a lot...
Browsers blocks abusable JavaScript API calls until the user has interacted with the document. Examples would be opening new tab or start playing video or audio. E.g. if you attempt...
...to call video.play() in a test, the call will reject with a message like this: NotAllowedError: play() failed because the user didn't interact with the document first. https://goo.gl...
...s encrypted password hash, salt and KMS key ID from the database. Make a call to KMS to decrypt the hash (KMS internally stores the corresponding private key but never...
...get exposed either. The only way to decrypt something is to make an API call to KMS. Thus, the only valid attack really is if the attacker is able to...
...let the page jump to the top when the link is clicked, unless you call preventDefault on the event. This is probably not what you want. Do something with js...
JavaScript objects can have getter and setter functions that are called when a property is read from or written to. For example, if you'd like an object that has...
...Performance considerations Read and write accesses have the same performance characteristics of regular function calls, so it's slower than a dumb property...
...the array of methods. @user.methods.grep /name/ # => [:name, :first_name, :last_name] You can also call #private_methods or #public_methods. To find only relevant methods, it is suggested to subtract...
...by native event listeners: let $element = $('.foo') $element.on('change', event => console.log('I will be called')) $element[0].addEventListener('change', event => console.log("I WON'T be called")) $element.trigger('change')
...event listeners (Element#addEventListener()): let $element = $('.foo') $element.on('change', event => console.log('I will be called')) $element[0].addEventListener('change', event => console.log('I will also be called')) let event = new CustomEvent...
...convert your CoffeeScript source to modern JavaScript. Install decaffeinate globally: npm install -g decaffeinate Call decaffeinate on each .coffee file, relaxing some options to get the most modern (and concise...
When changing code in mailers, updating the corresponding mailer preview can be forgotten very easily. Mailer previews can be tested...
...and background sections. The reason is that with background jobs (e.g. methods that are called by a cron job) some variables are not available for exception notifier, e.g. @request and...
...will crash itself and not send a mail! With foreground jobs, exception notifier gets called automatically when an error raises. For background jobs, exceptions need to be catched and delivered...
...an ActionDispatch::Request::Session object. class MyMiddlware def initialize(app) @app = app end def call(env) status, headers, body = @app.call(env) session = env['rack.session'] Rails.logger.info("Value of session['foo'] is...
...to .test("null"). Globally matching regex objects remember the last index they matched. Multiple calls to test() will advance this pointer: matcher = new RegExp("foo", "g") // <- "global" flag matcher.test("foobar...
To catch all possible exceptions from a network call, we need to rescue many error classes like this: rescue SocketError, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::ECONNABORTED, Errno::EHOSTUNREACH, OpenSSL::SSL...