developer.mozilla.org

You can easily have a JavaScript hash/object that returns a default value for unset keys/properties -- as long as you need to support only recent browsers. The key are JavaScript proxies...

...getter method. They work like this: var hash = new Proxy({}, { get: function(object, property) { return object.hasOwnProperty(property) ? object[property] : 'hello'; } }); When you set a key, you can read its value...

should include the model and tag if the tool has a tag should return the model if the tool has no tag .search should find tools by model and...

...attr_writer :browser_died def scenario_started self.browser_died = false end def scenario_ended return unless session.driver.is_a?(::Capybara::Selenium::Driver) self.driver_scenario_count += 1 if !browser_died? && driver_scenario...

blog.jayfields.com

...legacy code. For new code, always use capture3. %x{ } or backticks – quick and easy Returns the standard output of running the given command in a subshell. This is an alias...

...exec, but executes the given command in a subshell. Your script will go on. Returns: true if the command gives zero exit status false for non zero exit status

makandra dev

...image_tag), Rails will compile your entire assets within its process before that helper returns. This will cause your helper to freeze for many seconds. Since Webpack needs to boot...

Consider you have a website vhost listening to www.example.com, redirecting all incoming requests that do not talk about the configured...

...var container = $.find('.container', document.body)[0]; var openTasks = $.find('.task.open', container); Note that Sizzle returns vanilla DOM nodes in a vanilla Javascript array. It does not return jQuery collections...

...child of the element we're checking var candidateFromPoint = $(elementFromPoint).closest(elementFromSelector).get(0); return elementFromSelector == candidateFromPoint; JS is_top_element = page.execute_script(js) expect(is_top_element).to eq...

...for(locator) method, which takes a prose locator like "the very important notice" and returns a CSS selector like .very-important-notice. If you are using Spreewald, this method is...

...requests for every page. The browser will first request /foo, then the server will return a redirect to /foo/ (mind the trailing slash), then the browser makes a second request...

...by configuring your static web server. What we want is: Accessing /foo should directly return the content of /foo/index.html without a redirect Accessing /foo/ should redirect to the canonical /foo...

...Laden von Models passieren # search_spec.rb describe Search, search: true do # enable indexing # ... it 'only returns posts for a post query' do post = create(:post) create(:event) Post.search_index.refresh # force index to...

angular-tips.com

...app.factory('name', someFunction) someFunction is called when the name service is instantiated and should return an object Service just like Factory, but: instead of a funciton, it receives a Javascript...

^ app.config(function($provide) { $provide.decorator('serviceToBeDecorated', function($delegate) { // modify $delegate by adding functions etc. return $delegate; }); }); More differences | | Factory | Service | Value | Constant | Provider | | can have dependencies | yes | yes | no | no...

edgeapi.rubyonrails.org

# or b.label(class: "my-#{ b.object.class.name.parameterize }", 'data-value': b.value) { b.check_box + b.text } end The return values of each call will be joined and returned. You may of course render HTML...

RuntimeError: can't modify frozen String /home/user/.rbenv/versions/1.9.3-p551/lib/ruby/1.9.1/rubygems/version.rb:191:in `strip!': #stringify_keys - returns hash or session hash with keys stringified /home/user/.rbenv/versions/1.9.3-p551/lib/ruby/1.9.1/rubygems/version.rb:191:in `initialize' /home/user/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/pry-0.13.1/lib/pry/pry_class.rb:13:in `new...

...for RSpec users: |---------------------------------------------------------| | RSpec | Mocha | |---------------------------------------------------------| | obj = double() | obj = mock() | | obj.stub(:method => 'value') | obj.stubs(:method).returns('value') | | obj.should_receive(:method).with('argument').and_return('value') | obj.expects(:method).with('argument').returns('value...

makandra dev

...below gives you just that. // Call with two desired values at two different widths. // Returns a calc() expression that will scale proportionally between those two. // Example: // Spacing should be 15px...

$width2 * $relative + $static = $spacing2 $relative: ($spacing2 - $spacing1) / ($width2 - $width1) $static: $spacing1 - ($width1 * $relative) @return calc(#{$relative * 100%} + #{$static * 1px...

...form = up.element.first(formSelector) element.addEventListener('click', (event) => { event.preventDefault() let linkTag = buildLinkTag(form) if (linkTag == null) return window.parent.postMessage({ mceAction: 'insertContent', content: linkTag, }); window.parent.postMessage({ mceAction: 'insertContent', content: ' ', }) window.parent.postMessage({ mceAction: 'close' }); }) function buildLinkTag(form...

...the element "([^\"]+)" should( not)? have scrollbars$/ do |selector, no_scrollbars| scroll_height = page.execute_script("return $('#{selector}').get(0).scrollHeight;") offset_height = page.execute_script("return $('#{selector}').get(0).offsetHeight;") comparison = no...

...parentheses) instead of using it as a keyword import (without parentheses). The import() function returns a promise with the exported variables: let exports = await import('large-library') console.log("A named...

makandra dev

...video's initial playback time. Setting this value seeks to the new time. readyState returns a value in [0:4] indicating its state. Caveats On iOS, the video.preload attribute is...

Ruby's String#split returns an array of substrings from the given string. Usually, this is missing the split characters: >> 'user@example.com'.split('@') => ["user", "example.com"] If you want to join those...

..... Your supported Ruby versions for this gem must be >= 2.3. When rake release returns an error rake aborted! Your rubygems.org credentials aren't set. Run `gem push` to set...

...is some plain JavaScript, should you prefer that: function joinSentence(array) { if (array.length > 1) { return array.slice(0, -1).join(', ') + ', and ' + array.slice(-1); } else { return array.join...

...extra attribute) you might run into trouble when submitting the form by pressing the return key in a field. When nothing fancy like a tabindex is defined it seems as...

...submit element inside a form is chosen (and has its attributes submitted) when pressing return.\ So, if possible, put your "default" (aka least harmful) submit element before others.

...pattern below. Note how the class is replaced by a constructor function newDog, which returns an object that has the object's public methods as properties: function newDog(name) {

console.log(name + " is a good boy"); } } function walk(additionalMeters) { meters += additionalMeters; } function isHungry() { return meters > 50; } return { bark: bark, walk: walk } } As function isHungry() is not returned, it remains...