If you expect method calls in RSpec 3, be aware that the argument matchers use very liberal equality rules (more like
=== instead of
expect(subject).to receive(:foo).with(MyClass) subject.foo(MyClass) # satisfies the expectation subject.foo(MyClass.new) # also satisfies the expectation expect(subject).to receive(:bar).with(/regex/) subject.bar(/regex/) # satisfies the expectation subject.bar('regex') # also satisfies the expectation
This is usually not an issue, except when your method argu...
This card existed before, but was outdated due to browser implementation changes. The information below is validated for the current list of browsers we support.
By default your
body elements are only as high as the actual page content. If you only have two lines of text in your page, your
body elements will only be around 40 pixels high, regardless of the size of your browser window.
You might be surprised by this, since setting a
background on either
body does cover the enti...
Expecting a primitive value as an argument to a method invocation is easy:
expect(object).to receive(:foo).with('arg1', 'arg2')
This expectation would be met with this call:
But what if the argument is expected to be an object with a given set of methods? E.g. this class with
class Person def initialize(first_name, last_name) @first_name = first_name @last_name = last_name end attr_reader :first_name, :last_name end
To just t...
We structure our CSS using the BEM pattern.
Our naming convention for blocks, elements and modifiers has evolved over the years. This card shows our current style and various alternative styles that you might encounter in older projects.
The difference between the various styles are mostly a matter of taste and optics. I do recommend to not mix styles and be consistent within a given project.
Our current BEM naming convention looks...
I experienced a lot of issues with google chrome that made it almost impossible to work with it. Here are some of them:
I finally discovered a setting that fixed these issues for me:
Use system title bar and borders
I'm not sure if this setting was changed by me or if it was the browser default.
CSP hat zum Ziel einen Browser-seitigen Mechanismus zu schaffen um einige Angriffe auf Webseiten zu verhindern, hauptsächlich XSS-Angriffe.
XSS = Cross Site Scripting. Passiert wenn ein User ungefiltertes HTML in die Webseite einfügen kann.
<div class="comment"> Danke für den interessanten Beitrag! <script>alert('you have been hacked')</script> </div>
Rails löst das Problem weitgehend, aber
Ruby's File class has a handy method
binary? which checks whether a file is a binary file. This method might be telling the truth most of the time. But sometimes it doesn't, and that's what causes pain. The method is defined as follows:
# Returns whether or not +file+ is a binary file. Note that this is # not guaranteed to be 100% accurate. It performs a "best guess" based # on a simple test of the first +File.blksize+ characters. # # Example: # # File.binary?('somefile.exe') # => true # File.binary?('somefile.txt') # => fal...
For webpages to load fast it's recommended to optimize images. Ideally an image's file size should be as small as possible while still being of decent quality. This card demonstrates two command line tools for image optimization
identify to fetch information about pictures.
convert can change size/quality and strip meta information. Both commands are supplied by ImageMagick.
$ identify in.jpg in.jpg JPEG 294x440 294x440+0+0 8-bit sRGB 92.8KB 0.000u 0:00.000 $ convert in.jpg -resize x220 -strip -set profile sRGB2014.icc -qua...
One of the many useful features of TextMate is autocompletion of words. If I were in TextMate right now, I could write "au[tab]", and it would complete it to "autocompletion". RubyMine can do this, too. When you write a word (e.g. a variable name), just hit ALT + / repeatedly and it will offer all completions for the letters you typed. This action is called Cyclic Expand Word in RubyMine / IntelliJ IDEA.
This feature keeps you from mistyping variable names, saves you keystrokes and speeds up development. ~10 keystrokes to the price ...
This note is a reminder that there is something called AppArmor that could cause weird errors ("File not found", "Can't open file or directory", ...) after configuration changes, e.g. when changing MySQL's data directory.
Remember to have a look at AppArmor's daemon configuration (usually at
/etc/apparmor.d/) if you change daemon configuration and run into errors such as the one above.
If you want to prevent that two processes run some code at the same time you can use the gem with_advisory_lock.
- The thread will wait indefinitely until the lock is acquired.
- While inside the block, you will exclusively own the advisory lock.
- The lock will be released after your block ends, even if an exception is raised in the block.
This is usually required if there is no suitable database row to lock on.
You want to generate a...
grep is the go-to CLI tool to accomplish tasks like filtering large files for arbitrary keywords. When additional context is needed for search results, you might find yourself adding flags like
-B5 -A10 to your query. Now, every search result covers 16 lines of your bash.
There is another way: You can easily pipe your search results to the VIM editor and cycle through them.
vim -q <(grep -Hn -r "User" .) # vim -q starts vim in the "quickfix" mode. See ":help quickfix" # grep -...
-class @User +class window.User
requirestatement with Webpacker's...
We're pleased to announce Ruby 3’s new language for type signatures, RBS. One of the long-stated goals for Ruby 3 has been to add type checking tooling. After much discussion with Matz and the Ruby committer team, we decided to take the incremental step of adding a foundational type signature language called “RBS,” which will ship with Ruby 3 along with signatures for the stdlib. RBS command line tooling will also ship with Ruby 3, so you can generate signatures for your own Ruby code.
Ruby 3 is coming, and it will have optional type sign...
Ag (aka "the silver searcher") is a very fast replacement for
It will parse your
.gitignore for additional speedup. To ignore even more files (
*.min.js etc), add an
.ignore with syntax identical to
See Faster Grepping in Vim for hints about vim integration.
RSpec 3 has verifying doubles. This breed of mock objects check that any methods being stubbed are present on an instance of a given class. They also check methods aren't called with the wrong number of arguments.
This dual approach allows you to move very quickly and test components in isolation, while
giving you confidence that your doubles are not a complete fiction.
You should always prefer using a verifying double to using an old-...