Sometimes you need to remove high Unicode characters from a string, so all characters have a code point between 0...

...be guessable, but exposing your dev server to the internet is generally not the best idea. In my tests I was not easily able to get a better errors console...

...to cache or persist it, you can use to_pem: certificate_data = certificate.to_pem # => "-----BEGIN CERTIFICATE-----\nMIIHQDCCBiigAwIBAgIQD9B43Ujxor1NDyupa2A4/jANBgkqh..." You can then instantiate a Certificate from that string: certificate = OpenSSL::X509::Certificate.new...

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

Event delegation is a pattern where a container element has a single event listener that handles events for all descendants...

Git commits should be very deliberate, and only contain changes that you really want to be in there. In order...

mitrev.net

user&.name # => nil This might remind you of andand, and indeed it behaves very similar. The only difference is in handling of false, as false.andand.class returns false (intercepts...

Note netstat has mostly been superseeded by its more modern rewrite ss which nowadays comes pre-installed rather than netstat...

makandra dev

Starting with Ruby 1.9, most #each methods can be called without a block, and will return an enumerator. This is...

I often see the use of || to set a default value for a variable that might be nil, null or...

makandra dev

There are two distinct ways of commenting Haml markup: HTML and Ruby. HTML comments This will create an HTML comment...

...to give an element a glossy or three-dimensional feel, box shadows work much better for this. This is because linear gradients always stretch to the full size of the...

When you have a program running in a hidden X screen (like with Xvfb for Selenium tests) you may want...

When loading a database dump created with pg_dump into your database, you might run into an error like

github.com

...only a millisecond or two: class FatModelMaterializedJson < ApplicationRecord def self.refresh ActiveRecord::Base.connection.execute(<<~SQL) DO $$ BEGIN IF ( (SELECT last_refreshed_at FROM aggregated_names LIMIT 1) < (SELECT MAX(updated_at) FROM...

You can download .gem files using gem fetch: gem fetch activesupport consul This will produce files like active-support-5.0.0.gem and consul-0.12.1.gem...

The recommended additional setup of the spreewald gem, a useful set of cucumber steps, includes adding a file for defining...

...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...

...whole test suite's settings because of a pending test, you can disable this behavior for pending features only. To make any pending call reconfigure the current cassette, you can...

digitalocean.com

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...

When you created a project on the Google API Console which is not being used, you may receive an e...

Occasionally you need to do something directly on the server -- like having all records recalculate something that cannot be done...