...default when assigning attributes. It works good for a small number of attributes, but becomes more difficult to read when using multiple attributes. Example: class User def initialize(salutation, first...
@newsletter = newsletter end end User.new( 'Mr.', 'John', 'Doe', 'Potsdamer Platz 1', '10117', 'Berlin', '+49 0151 1122334455', 'john.doe@example.com', true ) Using keyword arguments Using keyword arguments is easier for others...
...the old versions you wish to remove. Keep at least one recent, working kernel besides the one you are currently running. Address Metapackage Conflict (GA vs. HWE)
...holds your bash prompt. You might want to change it to serve your needs best. Here is how to: General non-printing escape sequences in your prompt have to be...
Occasionally you need to do something directly on the server -- like having all records recalculate something that cannot be done...
I recommend install Node.js using nvm. This way you can have multiple Node versions in your ~/.nvm. You also won...
...Tue, 09 Oct 2018 In most of the cases it would be better to use Date.strptime as you can provide a date or time pattern to match against. Date.strptime('Foobar...
...blocks or confusingly sometimes also procs Those with "method semantics", called lambdas lambdas They behave like Ruby method definitions: They are strict about their arguments. return means "exit the lambda...
...the lambda literal -> (since Ruby 1.9.1) test = ->(arg) do puts arg end blocks They behave like do-blocks or simply "segments of code": They try to be smart about their...
CSS transitions are a simple animation framework that is built right into browsers. No need for Javascript here. They're...
...helper in many views, but in the index view I hide the label to better fit the layout. Here is the helper: module IconHelper def icon(*args, &block) options = args.extract...
It's not a good idea to leave data objects mutable. They should behave like integers. Ruby's Data would have already enforced that. Because I used a regular...
...attr}=" do |value| if @readonly raise 'Readonly' else super(value) end end end Weird behavior changes from composed_of The method composed_of accepts the option :mapping, which is required...
...very nasty fails. Below are the basic changes you need to perform and some behavior you may eventually run into when upgrading your application. This aims to save you some...
...in your uploaders... def extension_white_list %w[jpg jpeg gif png] end must become def extension_allowlist %w[ jpg jpeg png gif ] end Also, every uploader must define allowlists...
When loading a database dump created with pg_dump into your database, you might run into an error like
...visibilitychange event to be notified if visibility changes. This allows your background tab to become completely passive: function pulse() { // do expensive thing } let pulseInterval function schedulePulse() { if (document.hidden) { if (pulseInterval...
...your commits are the changes. Never use merge. You've found some code that belongs to an earlier commit in your feature branch If you already have a "final" (i.e...
git rebase -i master Move the fixup directly below the commit it belongs to. Change the "pick" in front of the fixup commit to "f". Don't touch...
...the "space" character class For matching whitespaces in a regular expression, the most common and best-known shorthand expression is probably \s. It matches the following whitespace characters: " " (space)
Most forms have a single submit button that will save the record when pressed. Sometimes a form needs additional submit...
The DB schema is the most important source of truth for your application and should be very self-explanatory. If...
Do not pass times to date attributes. Always convert times to dates when your application uses time zones. Background
Getting an entire test suite green can be a tedious task which involves frequent switches between the CLI that is...
...from using fixtures over FactoryBot, as fixtures load essential test data upfront at the beginning of the testsuite. Finding peace with fixtures While setting up the database upfront challenges the...
...idea of maintaining a perfectly clean database state at the beginning of each test, with some disciplined practices, handling fixtures becomes quite manageable. Let’s dive into how this works...
...no longer recommend this option. After a chrome update, the chromedriver package sometimes lags behind and is not compatible. Install via apt install chromium-chromedriver Option 3: Install via npm...
...no longer recommend this option. After a chrome update, the chromedriver package sometimes lags behind and is not compatible. There's a handy npm package. sudo npm -g install chromedriver...
Here is a bash script that I use to auto-configure displays on Ubuntu 24.04 with Xorg. Background
Sometimes you need to remove high Unicode characters from a string, so all characters have a code point between 0...
has_many :images, through: :album_images end # Join model class AlbumImage < ActiveRecord::Base belongs_to :album belongs_to :image end Destroying a record in this setup will only remove...
...the record itself, and leave orphaned join records behind. image = Image.last image.destroy # removes only the `image` record, # but none of the associated `album_image` join records Good