Skip to content

Instantly share code, notes, and snippets.

@rstacruz
rstacruz / README.md
Last active Apr 29, 2021
Next.js: loading a list of articles for a blog
View README.md

Next.js: loading a list of articles for a blog

A blog might need a list of articles on its index page. Here's now I did it with Next.js.

Article files

@rstacruz
rstacruz / settings.js
Last active Jul 28, 2020
My VSCode settings
View settings.js
{
// --------------------------------------------------------------------------------
// Font settings
// --------------------------------------------------------------------------------
// Fonts
"editor.fontFamily": "Victor Mono, Iosevka, monospace", // 15/18 or 16/18
"editor.fontWeight": "600",
"editor.letterSpacing": 0,
"editor.lineHeight": 17,
View 0 Cloudflare worker redirect example.md

CloudFlare worker example

Sample CloudFlare worker that does redirects and rewrites.

View Docker on ArchWSL.md

Running Docker in ArchWSL

Problem: Running Docker on [ArchWSL] doesn't work by default. ArchWSL doesn't allow systemd services.

docker info
# ERROR: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

sudo systemctl start docker
# System has not been booted with systemd as init system (PID 1). Can't operate.
View Opinion: Ruby's pessimistic operator.md

Opinion: Ruby's pessimistic operator

Today I realised that Ruby's >= is more useful than ~>.

Rubygems’s pessimistic operator ~>, also known as “twiddle-wakka”, allows developers to specify flexible gem version ranges.

This... Is equivalent to...
gem 'i18n', '~> 2.3.5' gem 'i18n', ‘>= 2.3.5’, '< 2.4.0'
gem 'i18n', '~> 2.3' gem 'i18n', ‘>= 2.3.0’, ‘< 3’
View Reasons to avoid using ID's.md
View Updating gems with Bundler.md

Updating gems with Bundler

Bundler recommends using bundle update to update Rails. It also accepts --conservative to try not to update shared dependencies.

bundle update [--conservative] rails

This method can often produce unexpected results. Even with the conservative flag, it may try to update gems that you may not need updated. In some cases, bundler might even give some errors.

View Using multiple Ruby versions with Appraisal.md

Using multiple Ruby versions with Appraisal

[Appraisal] is often used for testing multiple versions of a Ruby gem's dependencies at once. When authoring a gem that requires compatibility with Rails 4 and 5, appraisal is often used to make this easier:

# Appraisals
appraisal 'rails-4' do
  gem 'rails', '~> 4'
end