...there is no built-in method -- you can add one, however: RegExp.escape = function(string) { return string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&') }; You can now say: var hostname = 'makandra.com'; new RegExp(RegExp.escape(hostname)); # => /makandra\.com...

...controller (maybe application controller is also fine): If you are in the test suite return a text with the name of the file. Otherwise super. Read the browser downloads folder...

selection = role_select.node.search(".//option[@selected = 'selected']") Why is this stupid? Because #node returns the internal node representation used by the driver, e.g. instances Nokogiri::XML::Element if you...

gist.github.com

level1: level2: 'value' value = NestedHash.read hash, 'level1' expect(value).toEqual level2: 'value' it 'returns undefined when any of the keys is missing', -> value = NestedHash.read {}, 'foo', 'bar' expect(value).not.toBeDefined...

github.com

...orphan_strategy The current implementation of this method does not add any errors or return false to prevent destruction -- it either raises an exception (for restrict) or destroys or moves...

...base color and transparency value for you. @function rgba-to-rgb($rgba, $background: #fff) @return mix(rgb(red($rgba), green($rgba), blue($rgba)), $background, alpha($rgba) * 100%)

...attributes on that collection. This is simply because of the way _.without works: It returns a new array with all elements except the removed one. Unfortunately, restangular collections are not...

...disabled that functionality and tidy up the previous original ourselves. def remove_stale_original(*) return unless original? current_original = path stale_originals = Dir[path.chomp(File.extname(current_original)) + '.*'] # Same filename, any...

...meant only for collections, you probably still want something like isBlank or isPresent that return true/false for objects humans would normally consider blank or present. Here is some CoffeeScript that...

...for pseudo elements. let style = window.getComputedStyle(element, '::before') let color = style.getPropertyValue('background-color') The returned color will be a string with a color value like "rgb(253, 126, 20)".

let hexColor = rgbColor .match(/(\d+), (\d+), (\d+)/) .slice(1, 4) .map((number) => { return Number(number).toString(16).padStart(2, '0') }) .join('') .replace(/^/, '#') Ruby My use case was comparing...

...AlphaSSL CA - G2 verify error:num=20:unable to get local issuer certificate verify return:0 --- Certificate chain 0 s:/C=DE/OU=Domain Control Validated/CN=www.projecthero.com i:/O=AlphaSSL/CN=AlphaSSL...

...cucumber_paths, 'r').each do |line| lines << line.slice(/\s+when /^?([^$]*)$?/[im]?$/, 1) # @param 1: return first matched group end paths = lines.compact.sort TextMate::UI.complete(paths, :extra_chars => " ") else %x{ "$DIALOG" tooltip...

tutorialzine.com

...parser.hostname; // => "makandracards.com" parser.pathname; // => "/makandra/29377-the-easiest-way-to-parse-urls-with-javascript/foo" if (pathname[0] != '/') pathname = '/' + pathname // Fix IE11 Caveat: IE11 will return the pathname without leading slash. Make to employ the fix as noted above.

...correct (a year is almost never exactly 365 days), even 1.year.to_f won't return a result that would justify always using floats: 31557600.0 is just the same as 365.days.to...

...pattern, and options for its switches. >> regexp.source => "^f(o+)!" >> regexp.options => 5 Note that options returns a bitmask. If necessary, you could compare that to Regexp's switch constants: >> regexp.options & Regexp...

makandra dev
github.com

...urls) it works as a drop-in-replacement. It basically overwrites #to_param to return the slug, and .find to search by the slug. Make sure, everywhere you build paths...

Enumerable#all? returns true for an empty collection. This totally makes sense but you have to think about it when making assumptions on relations which might be empty. [].all?(&:will...

...researcher.papers.all? { |topic| topic == 'computer_science' } researcher.destroy! end end There are more methods in Enumerable (returning boolean values) where you might need to think twice with empty collections...

...the DOM now, the will be gone, but its contents will be kept. $container.html() // returns " Hello World" Also note that contents() includes text and comment nodes which is essential for...

makandra dev

class DeepThought extend ActiveSupport::Memoizable def life_universe_and_everything # some lengthy calculation returning 42 end memoize :life_universe_and_everything end Then #life_universe_and_everything will of...

...parameter at all. To clarify: This not only disables the memoization, but will also return wrong results! The best solution is to use the Memoizer gem instead...

...s #collect is to call a method on each list element and collect the return values in a new array: ['hello', 'world', 'this', 'is', 'nice'].collect(&:length...

...method collect_ids on your ActiveRecord models, scopes, integer scalars and collections, which will return a list of their IDs: User.last.collect_ids # => [9] [User.first, User.last].collect_ids # => [1, 9] User.active.collect...

...was constructed by a given constructor function, use jasmine.any(Klass): describe('plus()', function() { it ('returns a number', function() { let result = plus(1, 2) expect(result).toEqual(jasmine.any(Number)) }) })

makandra dev
dev.mensfeld.pl

...attrs.fetch_values :name, :email Hash#to_proc Turns a Hash into a Proc that returns the corresponding value when called with a key. May be useful with enumerators like #map...

...sure to do it this way: params.to_hash.symbolize_keys.merge(:include => { :user => :avatar }) (Note that params.to_hash returns a hash with string keys...