import until from 'path/to/until'
import { shallow } from 'enzyme'
const EnhancedFoo = compose(
connect(...),
withHandlers(...),
withContext(...)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def eventually(timeout: Capybara.default_max_wait_time, interval: 0.2) | |
| Timeout.timeout(timeout) do | |
| begin | |
| next yield | |
| rescue Minitest::Assertion, Capybara::ExpectationNotMet | |
| sleep interval | |
| retry | |
| end | |
| end | |
| rescue Timeout::Error |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Adapted from http://thepugautomatic.com/2014/08/union-with-active-record/. | |
| def self.union *scopes | |
| sql = connection.unprepared_statement do | |
| unions = scopes.map { |scope| "(#{scope.to_sql})" }.join(' UNION ') | |
| "(#{unions}) AS #{table_name}" | |
| end | |
| from sql | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Kaminari | |
| module PageScopeMethods | |
| def padding(num) | |
| @_padding = num | |
| new_offset_value = offset_value + num.to_i | |
| if new_offset_value < 0 | |
| limit([limit_value + new_offset_value, 0].max).offset(0) | |
| else | |
| offset(new_offset_value) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| git diff-index --cached --name-only -z HEAD | | |
| xargs -0 git grep --cached -I --name-only -z -E '[[:space:]]$' -- :!'*.slim' | | |
| xargs -0 sed -i '' -E 's/[[:space:]]+$//' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fix_eol() { | |
| for f; do | |
| sed -i '' -E 's/[[:space:]]*$//' "$f" | |
| done | |
| } | |
| git grep -I --name-only ' $' -- :/ :!'*.slim' | while read f; do fix_eol "$f"; done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fix_eof() { | |
| for f; do | |
| : Add a final new line if needed. | |
| [ "$(tail -c1 $f)" = "" ] || echo >> $f | |
| : Remove extra final new lines. | |
| while [ "$(tail -c2 $f)" = "" ] && [ $(wc -l < $f) -gt 1 ]; do | |
| sed -i '' '$ d' $f | |
| done | |
| done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const shuffle = arr => | |
| arr.reduce((arr, elt) => { | |
| arr.splice(~~(Math.random() * (arr.length + 1)), 0, elt) | |
| return arr | |
| }, []) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Drop-in function to parallelize a stage of a Gulp pipeline. | |
| // | |
| // NB: order is not preserved. | |
| // | |
| // Before: | |
| // | |
| // gulp.src('./sass/**/*.scss') | |
| // .pipe(sass()) // Processes files one-by-one. | |
| // .pipe(gulp.dest('./css')) | |
| // |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Like Mongo's db.collection.distinct but with counts for each field value. | |
| * See https://docs.mongodb.org/v3.0/reference/method/db.collection.distinct. | |
| * | |
| * Example: | |
| * > distinct('inventory', 'items.sku', { dept: 'A' }) | |
| * { "111" : 2, "333" : 1 } | |
| */ | |
| function distinct(collection, field, query) { | |
| var map = {} |