Edge Rider gives your relations a method #origin_class that returns the class the relation is based on. This is useful e.g. to perform unscoped record look-up. Post.recent.origin_class...

if (str.length > 0) { str = str.replace(/\n\n+/g, ' '); str = str.replace(/\n/g, ' '); str = ' ' + str + ' '; } return str; } Unlike the Rails helper, this does not preserve whitespace. You probably don't care...

...side effect of that feature is that when you use the back button to return to the form, the submit button will be greyed out and disabled.

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.

mitrev.net

...it behaves very similar. The only difference is in handling of false, as false.andand.class returns false (intercepts invocation), whereas false&.class permits the invocation. &. might also remind you of Rails...

...a jQuery fallback for browsers that don't speak HTML5: var Autofocus = { supported: function() { return 'autofocus' in document.createElement('input'); }, fake: function() { $('[autofocus]').focus(); }, extend: function() { Autofocus.supported() || Autofocus.fake(); } }; $(Autofocus.extend...

If you are using Rails or ActiveSupport, calling step without a block will return an array of matching elements:

stackoverflow.com

...distracting Text Selection: // from: http://stackoverflow.com/questions/1794220/how-to-disable-mobilesafari-auto-selection $.fn.extend({ disableSelection : function() { this.each(function() { this.onselectstart = function() { return false; }; this.unselectable = "on"; $(this).css('-moz-user-select', 'none'); $(this).css('-webkit-user-select', 'none...

...simply overwrite the deliver! method like this: # In your mailer.rb def deliver!(mail = @mail) return false if (recipients.nil? || recipients.empty?) && (cc.nil? || cc.empty?) && (bcc.nil? || bcc.empty?) super

...WHERE (users.id IN (899,1084,1095,100,2424,2429,2420)) the order of the returned records is undefined. To force the query to return the records in a given order...

...able to say created_within on any ActiveRecord or its scope chain. This will return a scope of all records created between two given timestamps. Use it like that: Booking.created...

...OpenStruct.new(:foo => 23, :bar => 42).marshal_dump => { :foo => 23, :bar => 42 } Both approaches will return the underlying hash table (a clone of it in Ruby...

The attached ImageLoader helper will start fetching an image and return an image that is resolved once the image is loaded: ImageLoader.load('/my/image.png').then(function(image) { ... }); The image argument that...

jQuery's find looks in the element's descendants. It will never return the current element itself, even if the element matches the given selector. Require the attached file and...

stackoverflow.com

Some browsers define window.event, which will return a copy of the "current" event. However, this is not defined by the W3C. Most importantly, Firefox does not support it, neither do...

Grep prints one line per match. To return the number if matches, use the -c switch: grep -c "something" filename However, if a word appears more than once in a...

makandra dev

RSpec's be_false behaves unexpectedly: nil.should be_false # passes, as the expectation returns true If you want to check for false, you need to do it like this:

stackoverflow.com

...a very concise one is this: hash.merge!(hash) do |key, old_value, new_value| # Return something end The block of merge! will be called whenever a key in the argument...

...allow you to modify the value of each key to whatever you like (by returning old_value you'd get the behavior of Rails' reverse_merge!, by returning new_value...

...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)) }) })

...certain state is reached (e.g. an object appears in the scope). Angular's $watch returns a method that you can call to remove that watch. For example: unwatch = $scope.$watch...

...why he hates humanity. - Tim Pope I finally gave up and made BigDecimal#inspect return BigDecimal#to_s: p BigDecimal.new('2.3') #=> "2.3" Use the attached initializer...

...no input being displayed, strange character output) Try typing this, followed by pressing the return key: reset That should clear the screen and reset output settings etc...

...And when you do, you're probably fighting a Microsoft product. The following function returns a Number like 10, 11, 12, 13 for Internet Explorer or Edge (anything above...

...is Edge). It returns undefined for any other browser. function ieVersion(uaString) { uaString = uaString || navigator.userAgent; var match = /\b(MSIE |Trident.*?rv:|Edge\/)(\d+)/.exec(uaString); if (match) return parseInt(match...

Don't simply test for the presence of the magic Paperclip attribute, it will return a paperclip Attachment object and thus always be true: - if user.photo.present? # always true