touch -t `date +%m%d0000` /tmp/$$ find . -cnewer /tmp/$$ Note that $$ returns the current bash's PID so you will get some file like /tmp/12345 that stays...
...then each element of the page is represented by a method that, when called, returns a reference to that element that can then be acted upon (clicked, set text value...
...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...
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.
...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.
...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:
...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...
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...
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:
...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...