Skip to content

Instantly share code, notes, and snippets.

View khalidx's full-sized avatar
💭
Engineering for the ☁️

Khalid Zoabi khalidx

💭
Engineering for the ☁️
View GitHub Profile
@khalidx
khalidx / fix-mac-chrome-no-clicks.md
Last active October 31, 2023 21:03
A (possible) fix for not being able to click around a webpage in Chrome on macOS.

Issue Description

After upgrading my MacBook Air M1 to macOS Sonoma 14.0 (not sure if it is related to this issue), I noticed that I often cannot click anything inside a webpage in Chrome, even though I can scroll the page.

Also, sometimes the navigation buttons don't work either.

Resolution Steps

It appears that this fix may have resolved the issue. The inspiration for this fix came from the following Apple community discussion thread:

@khalidx
khalidx / bash-reusable.md
Created October 2, 2023 22:12
Reusable bash functions.

Include the code below in any bash script!

This is a good way to start a bash script:

#!/usr/bin/env bash
set -eou pipefail

These are some useful generic reusable bash functions.

@khalidx
khalidx / validate-package-json.md
Last active October 2, 2023 09:08
Validate fields from a package.json file.

You could use this code to, for example, validate fields from a package.json file for use in a Node.js CLI application.

It gives you a packageInfo object that has some useful fields that you could use (in a help or usage message, for example):

  • packageInfo.version, so that you can display the CLI version
  • packageInfo.bin, so that you can display the name of the CLI command
  • packageInfo.repository, so that you can display a URL to the repo for the CLI

Make sure your tsconfig.json includes "resolveJsonModule": true.

@khalidx
khalidx / redis-configuration.md
Created September 25, 2023 05:29
Redis configuration settings.

Here are some configuration settings for setting up Redis.

This should go in your docker-compose.yaml:

redis:
    image: redis/redis-stack-server:7.2.0-v2
    restart: always
    volumes:
 - redis-data:/data
@khalidx
khalidx / notion-sprints.md
Last active August 28, 2023 11:52
A Notion formula for calculating sprints.

Given a date field and a sprint size (10 days), this formula calculates the number of sprints remaining (integer) until the end of the year.

This formula can be used in a Notion formula field.

floor(max((dateBetween(dateAdd(dateAdd(start(prop("Date")), 11 - month(start(prop("Date"))), "months"), 31 - date(start(prop("Date"))), "days"), start(prop("Date")), "days") - dateBetween(end(prop("Date")), start(prop("Date")), "days")), 0) / 10)

Here's an explanation of what is going on:

@khalidx
khalidx / esbuild.md
Created June 5, 2023 22:21
Build a TypeScript project with esbuild.
esbuild src/cli.ts --bundle --platform=node --target=node18 --outfile=dist/bundle.js
@khalidx
khalidx / swc.md
Last active June 2, 2023 02:36
Programmatically compile with @swc/core.

Utility function

import { transform, Options } from '@swc/core'

export async function compile (params: { source: string, options?: Options }) {
  const { code, map } = await transform(params.source, params.options)
  return { code, map }
}
@khalidx
khalidx / ls.ts
Last active November 22, 2023 19:55
List or list and import all files in a directory without any node libraries.
import { join, basename, extname } from 'path'
import { readdir } from 'fs-extra'
/**
* Lists all files in the specified `directory`, without any external libraries.
*
* If `directory` is not specified, `process.cwd()` is used.
*
* Set `includeDirectories` to `true` to also include directory names in the output.
*
@khalidx
khalidx / typescript-monorepo.md
Last active December 2, 2023 04:45
A simple setup for a TypeScript monorepo.

There are countless guides online for setting up a TypeScript monorepo.

Most rely on external tools like Lerna, Yarn, Turborepo, Yalc, or something else.

Here's a simple, zero-opinion way to get a TypeScript monorepo going.

First, make a structure like this:

root/
@khalidx
khalidx / vscode-devcontainers.md
Created December 2, 2022 09:45
A VSCode DevContainers configuration for dockerized development.

VSCode DevContainers are way better than installing tools locally and coding on your machine; it prevents tool clutter, and ensures your project is portable across your team.

For Node.js / JavaScript / TypeScript development, just create a .devcontainer/devcontainer.json file at the top-level in your workspace with the following contents:

{
  "name": "Node.js & TypeScript",
 "image": "mcr.microsoft.com/devcontainers/typescript-node:18-bullseye"