TL; DR WordNet helps English learners with getting a clearer grasp of relationships between a couple of words. Its API lets the users explore the whole network of English words in their own way along with their purpose.
WordNet is a huge lexical database of English. Every sense of words is represented as a “synset” (a set of synonyms) in the database. Every synset has its short definition with a couple of example sentences and pointers to related words.
To write outputs to a file in a shell, we can use redirection. However, when we read a file and modify the content and redirect to the same original file, we’ll get just an empty file. What’s going on here?
$ cat file bravo delta charlie alpha charlie $ cat file | sort | uniq > file $ cat file # empty file $ Of course, if you redirect to a different file and rename it to the original name, it works as expected. This behavior is a little annoying when we want to modify a file like sorting and removing duplicates and do it without creating any temporary file. The reason redirecting output to the source file ends up an empty file is the redirection truncates the destination file earlier than the command actually starts processing.
When stopping a container one way or another, like by Ctrl+C or docker stop, Docker sends SIGTERM to the process by default. If the first process (PID = 1) on the container is not a proper init process, the termination may take a long time to be done. It’s because processes running as PID 1 are treated differently than usual ones.
In Linux, a process running as PID 1 ignores any signal unless the process implements signal handlers on its own. While some programs like ruby trap signals, many others like tail do not.
In RSpec, some matchers can take another matcher as an argument. It is sometimes useful for writing an expectation for a collection. Let’s say we want to test that an array contains a string that includes a particular text. We can do that by combining two matchers: include and match as follows.
expect(an_array).to include(match(/Lorem/)) # Of course we also could do: # expect(an_array.grep(/Lorem/)).not_to be_empty # or # expect(an_array).to be_any {|item| /Lorem/ === item } I think that in this case, the expectation with include and match is much more concise than the commented-out alternative ways above.
Sometimes I want to create a tiny one-off script that intended to run on a sandbox environment like a Docker container and needs only one file. Most of the time, I also need test frameworks to do some refactoring. It can be done with bundler/inline and rspec/autorun.
require 'bundler/inline' gemfile do source 'https://rubygems.org' gem 'rspec' end def doit 'return a string' end require 'rspec/autorun' RSpec.describe '#doit' do example do expect(doit).to be_a(String) end end Usually, Bundler reads the dependencies from Gemfile. However, we can forgo this file by using gemfile block instead. As running the script, Bundler will install gems that are required by the block but not installed in the system. So the initial run may take a little longer time for installation. Note that you cannot place require 'rspec/autorun' before the gemfile block since some of the dependencies might not be installed yet before that.