Skip to content

Instantly share code, notes, and snippets.

Using rem units in CSS

One pattern I've noticed lately is using rem as a unit of distance in CSS. This seems like a pretty good idea.

.box {
  height: 1.5rem;
  padding: 1rem;
}
@rstacruz
rstacruz / README.md
Last active April 23, 2024 00:19
Setting up Jest with ESM

Setting up Jest with ESM

Here are some different ways on how to set up Jest to support ESM. This applies for Jest v25, Node v13, and Babel v7.

Method A: Native Node.js support

Node v14 and Jest v26 support ESM natively with the --experimental-vm-modules flag.

Install cross-env:

@rstacruz
rstacruz / ansible.md
Last active April 8, 2024 23:36
Getting started with Ansible
@rstacruz
rstacruz / README.md
Last active January 17, 2024 22:27
Setting up Babel and TypeScript

Install Babel 7 and TypeScript

yarn add --dev \
  @babel/core \
  @babel/cli \
  @babel/preset-env \
  @babel/preset-typescript \
  typescript

⭐ This post is best experienced in my blog: https://ricostacruz.com/posts/javascript-in-rails-7

JavaScript in Rails 7

JavaScript in Rails 7 will be different: Webpacker is retired, and there are 2 new gems to manage frontend files.

Situation

  • 🛌 Webpacker is retired — Webpacker 5 will be the last version, as announced on Jan 2022. The Webpacker 6 release candidate is now going to be community-maintained under a new name. (github.com: webpacker readme)
@rstacruz
rstacruz / index.md
Last active November 3, 2023 09:56
Rails models cheatsheet

Rails Models

Generating models

$ rails g model User

Associations

belongs_to

has_one

@rstacruz
rstacruz / README.md
Last active October 23, 2023 09:06
How to install Docker in Mac, Windows, and Linux

Getting Docker

Docker is available for Linux, MacOS, and Windows.

MacOS

Docker for Mac is best installed with Homebrew and Homebrew Cask. For other ways to install on MacOS, see Install Docker for Mac in Docker's docs.

brew cask install docker # Install Docker
@rstacruz
rstacruz / classes.js
Created February 15, 2012 09:14
JS Classes
function Person() {
this.initialize.apply(this, arguments);
return this;
};
Person.prototype = {
// default attributes here
firstName: "Jason",
lastName: "Mitchels",

Faster multi-line jumps in VSCode-Vim

One of the things that bothered me with VSCode-Vim was with how slow it was to use (number)(arrow) (eg, 42(down)) to move multiple lines down. In the screencast below, notice how it goes line-by-line rather than skipping ahead instantly.

☝ Figure 1: VSCode scrolls slooowly line-by-line when pressing 42(down).

Update (March 2023)

Make WSL2 faster by removing /mnt/c in the PATH variable

Turning off appendWindowsPath (the feature that adds /mnt/c paths to $PATH) can make WSL faster.

For Ubuntu on WSL

For most distros, it can be done by editing /etc/wsl.conf. These instructions were taken from https://gist.github.com/ilbunilcho/4280bd55a10cefef75e74986b6bff936

$ sudo vi /etc/wsl.conf