Ruby Associative Arrays
assoc_arr = [[:foo, :bar], [:baz, :qux]]
assoc_arr.assoc(:foo)
# => [:foo, :bar]
assoc_arr.assoc(:baz)
# => [:baz, :qux]
assoc_arr.rassoc(:bar)
# => [:foo, :bar]
assoc_arr.rassoc(:qux)
# => [:baz, :qux]
assoc_arr = [[:foo, :bar], [:baz, :qux]]
assoc_arr.assoc(:foo)
# => [:foo, :bar]
assoc_arr.assoc(:baz)
# => [:baz, :qux]
assoc_arr.rassoc(:bar)
# => [:foo, :bar]
assoc_arr.rassoc(:qux)
# => [:baz, :qux]
git diff -w --no-color | git apply --cached --ignore-whitespace && git checkout -- . && git reset && git add -p
git diff -w --no-color
creates a diff
git apply --cached --ignore-whitespace
applies the diff ignoring whitepace, and indexes it
git checkout — .
removes the unindexed “whitespace” changes
git reset
resets the index to just he non-whitespace cahnges
git add -p
adds the non-whitespace changes in patch mode
We did this with it alias gwap=“git diff -w --no-color | git apply --cached --ignore-whitespace && git checkout -- . && git reset && git add -p”
If you want to create a new file when you are viewing Vim’s file explorer (netrw), simply hit the %
. Vim will ask you for a file name, create that file in the currently viewed directory and open a buffer.
While your acceptance tests are running you can use pauseTest()
to pause the test suite and interact with your app. NOTE: this does not halt execution like debugger
, it only pauses the test suite.
test("my acceptance test", function(assert) {
visit('/');
pauseTest(); // returns a promise that will never resolve
andThen(function(){
// make assertions
});
});
When your cukes fail, you might want to take a screenshot, or automatically open a pry. This can help when debugging flaky tests.
After do |scenario|
if scenario.failed?
# take a screen shot, or open a pry
end
end
So you want to find all the rocketeers who wrote blog posts in a date range.
Blog::Post.where(published_at: 15.years.ago..4.years.ago).includes(:rocketeer).map(&:rocketeer)
# Blog::Post Load (0.6ms) SELECT "blog_posts".* FROM "blog_posts"
# WHERE ("blog_posts"."published_at" BETWEEN '2000-06-12 14:40:06.429288' AND '2011-06-12 14:40:06.429498')
# Rocketeer Load (0.7ms) SELECT "rocketeers".* FROM "rocketeers"
# WHERE "rocketeers"."id" IN (12, 13, 14, 16) ORDER BY "rocketeers"."name"
But you want to do it in one query!
Rocketeer.where(
id: Blog::Post.where(published_at: 15.years.ago..4.years.ago).select(:rocketeer_id)
)
# Rocketeer Load (0.9ms) SELECT "rocketeers".* FROM "rocketeers"
# WHERE "rocketeers"."id" IN (
# SELECT "blog_posts"."rocketeer_id" FROM "blog_posts"
# WHERE ("blog_posts"."published_at" BETWEEN '2000-06-12 14:42:20.005077' AND '2011-06-12 14:42:20.005317')) ORDER BY "rocketeers"."name"