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

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

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

makandra dev
gist.github.com

...swapcase", "tr", "tr_s", "upcase" All these methods are possibly unsafe, so they will return an unsafe String even if called on a SafeBuffer. If used for in-place replacements...

...quoted_true} and field=#{quoted_false}. The Rails methods quoted_false and quoted_true return the correct boolean representations for your database...

blog.bitcrowd.net

...window_open') do |scenario| if scenario.respond_to?(:status) && scenario.status == :failed print "Step Failed. Press return to close browser" STDIN.getc end

jasmine.github.io

...to control setTimeout and setInterval. Using jasmine.clock().mockDate() you can mock new Date() (which returns the current time in Javascript) While you can use SinonJS Fake timers, using the built...

...by the IconfontPlugin will not work const sassLoaderConfig = environment.loaders.get('sass') const sassLoaderIndex = sassLoaderConfig.use.findIndex(config => { return config.loader === 'sass-loader' }) sassLoaderConfig.use[sassLoaderIndex].options.includePaths = ['tmp/webpack'] sassLoaderConfig.use.splice(sassLoaderIndex, 0, { loader: 'resolve-url-loader', })

engineering.wework.com

...use the configured timeout. Hence, if both requests time out, Net::HTTP will only return after twice the configured timeout. This can become an issue if you rely on the...