Today I Learned

15 posts by marekpolakowski

Native <select> dropdown behavior

In case anybody wondering why native <select> dropdown opens in random directions (sometimes upwards, sometimes downwards) it just opens in the way so currently selected option is already on the cursor level.

It means when first option is selected, dropdown opens downwards, when last - upwards. And somewhere in the middle when some other option is selected. See image:

easter egg here

Ruby's "Class < OtherClass"


You can use ruby’s “greater than” and “less than” operators for checking class inheritance.

Foo < Bar
# returns true if Foo is included in Bar's ancestors
# returns false if Foo is a Bar's descendant
# otherwise returns nil

Source: Selleo/pattern - lib/patterns/query.rb

Real life examples:

User < ActiveRecord::Base # => true
ActiveRecord::Base < User # => false
TrueClass < String # => nil

Group console logs

There’s this cool feature in JS console (works in Chrome and Firefox) you can use if you want to log a lot of information, but you’re afraid of JS console getting too crowded. See example:

Code example

console.groupCollapsed("types of components");
console.log(typeof ComponentOne);
console.log(typeof ComponentTwo);
console.log(typeof ComponentThree);

That’s what you’ll get in JS console


Using multiple commands on heroku CLI

Need to use multiple heroku CLI commands one after another and don’t want to type -a foo-bar-baz every time?

Type export HEROKU_APP=foo-bar-baz in terminal and then just happily run heroku command on foo-bar-baz application.

heroku pg:backups:capture -a foo-bar-baz

# is equivalent to:

export HEROKU_APP=foo-bar-baz
heroku pg:backups:capture

PS. After that you might want to unset HEROKU_APP to remove variable.