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

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

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

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

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

The API is a little confusing because animate returns a reference to the element to enable chaining. But you can do this: $element.animate(...); $element.promise().then(function...

nginx.org

...code that nginx will interpret as "drop connection". Example: server { listen 127.0.0.1; location /api/ { return 444; } } An example use case is reverse-proxying with nginx and simulating a route that...

coffeescript.org

The Javascript in operator does what Hash#has_key? does in Ruby: Return whether an object has a property. However, Coffeescript has its own in operator that checks for array...

...activation of that feature on the value of that constant: private def captcha_valid? return true if SKIP_CAPTCHA ... To manually activate the feature in tests that actually need it...

tldp.org

...RANDOM on bash returns a random integer between 0 and 32767. echo $RANDOM 9816 echo $RANDOM 30922 If you want to limit that to a certain maximum, you can just...

stackoverflow.com

...type of an attribute, you can just use ActiveRecord's columns_hash method. It returns a hash of column objects that include a type attribute (and more database-related information...