...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...
...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...
...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...
...a?(String) && value.blank? - nil - else - value - end activerecord/lib/active_record/connection_adapters/column.rb + def type_cast_for_write(value) + return value unless number? + + if value == false + 0 + elsif value == true + 1 + elsif value.is_a?(String...
...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...
...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...
git name-rev --tags Note The more commonly used git describe command will return the last tag before a commit, git name-rev the next tag after the commit...
...jQuery (but before jquery-ujs): whitelisted = (url) -> for domain in ["http://trusted.host/", "https://another.trusted.host/"] return true if url.indexOf(domain) == 0 false $.ajaxPrefilter (options) -> if whitelisted(options.url) options.crossDomain = false
The attached download_helpers.rb provides a download_link method for your Capybara tests. It returns a hash describing the download's response: details = download_link('Download report') details[:disposition] # => 'attachment...
...secret folder with its contents. def migrate! correct_store_path = Pathname.new(new_store_dir) return if correct_store_path.directory? # already moved if the directory exists, nothing to do parent_path = correct_store_path.parent # this...
foo bar baz Hello Universe without :scope A simple document.body.querySelectorAll('div') will return a NodeList with 5 items, i.e. all 5 divs from above. with :scope Using document.body.querySelectorAll...
...path like "./foo.coffee". // The call to "substring" removes the "./" prefix. let preparePath = function(filePath) { return filePath.substring(2); }; modelFiles = require.context('js/models', true, /\.(js|coffee)$/); for(let filePath of modelFiles.keys()) { import(`js/models...
...callback this list might help you to fix your code afterwards: attribute_changed? will return true in the after_save callback and false in the after_commit callback. Use something...
...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...
If you do not provide a block to find_each, it will return an Enumerator for chaining with other methods: Person.find_each.with_index do |person, index| person.award_trophy(index...
...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...
...doesn't, and that's what causes pain. The method is defined as follows: # Returns whether or not +file+ is a binary file. Note that this is # not guaranteed to...
...raised for characters that are undefined in UTF-8. def is_file_binary?(path) return false unless File.binary?(path) content = File.read(path) content&.encode('UTF-8', 'binary') true rescue Encoding...
...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...
With this, the scope chain Meal.for_date(Date.today).suitable_for(current_user) would return all meals, not only those of today. Do this instead: def self.suitable_for(user)
...for Rails 2 use `scoped({})` instead of `all` end end Note how we're returning #all instead of self. This ensures that we're preserving the upstream scope chain...
...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.”. Promises un-invert the...
...Edge, there are polyfills for Internet Explorer. Usage: Usage Assume this piece of code returns a promise: api.get('pages') // => Promise You may now chain function calls to the promise using...
...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. ^
>> user.errors.of_kind?(:email, :taken) => true Using added? without specifying options will return false: >> user.errors.added?(:email, :taken) => false >> user.errors.added?(:email, :taken, value: "user@example.com") => true Most often, you probably...
...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...