Skip to content

Instantly share code, notes, and snippets.

View christophemarois's full-sized avatar

Christophe Marois christophemarois

  • Pathway Medical
  • Montreal
View GitHub Profile
@christophemarois
christophemarois / use-map.tsx
Last active April 18, 2024 03:24
React hook for state using ES6 Map
import { useState } from 'react'
export default function useMap<K, V>(): [
Map<K, V>,
{
set: (key: K, value: V) => void
unset: (key: K) => void
clear: () => void
}
] {
@christophemarois
christophemarois / cloudflare-tunnels.md
Last active April 9, 2024 13:24
Cloudflare Tunnels

Cloudflare is a better and free ngrok. With a domain that uses it, set it up like this

  1. Setup a tunnel
cloudflared tunnel login
cloudflared tunnel create test
cloudflared tunnel route dns test test.christophemarois.com
@christophemarois
christophemarois / redactPasswordFromUrl.ts
Created March 7, 2024 15:08
redactPasswordFromUrl.ts
/** Transform the password part of a connection string URL into [redacted].
* Useful for logging. */
export function redactPasswordFromUrl(url: string) {
return url.replace(/^([^:]+):\/\/([^:]*):([^@]+)@/, '$1://$2:[redacted]@')
}

TS/JS go-to libs

Updated Jan 2024. For looking up trending newer alternatives, use npmtrends. For Nodejs, nodejstoolbox a precompiled list of trends by category.

Universal

Standard libs

Standard libs extend the runtime with convenience helpers, structures and patterns.

@christophemarois
christophemarois / gm-inline-image-b64.user.js
Last active February 15, 2024 11:32
Demonstrate how to replace images with their base64 equivalent regardless of same-origin policy using GM_xmlhttpRequest. Still requires permission from Tampermonkey.
// ==UserScript==
// @name Base64 inline images
// @author @christophemarois
// @match *
// @grant GM_xmlhttpRequest
// @connect *
// ==/UserScript==
// NOTE: NOT MEANT TO BE INSTALLED
// AS IT WILL REPLACE EVERY IMAGE ON EVERY PAGE

Online Music Education

🗣If you'd like to add some channels to the list, leave them in the comments below. I am aware that this is not an exhaustive list, and that some areas are probably entirely missing (cough guitar cough).

Notes

  • ⭐️ = Personal faves
  • Channel must be primarily teaching-oriented
  • Order is alphanumeric
@christophemarois
christophemarois / icloud-cal-in-thunderbird.md
Last active October 10, 2023 13:43
Icloud calendars in Thunderbird
  1. Create an app-specific password for iCloud account (check Bitwarden notes)
  2. Use https://github.com/midnightmonster/icloud-calendar-urls to get your calendar's secret URL
curl -s https://raw.githubusercontent.com/midnightmonster/icloud-calendar-urls/master/icloud_calendar_urls | bash
  1. In thunderbird, add calendar with your icloud username, secret url and app-specific password
@christophemarois
christophemarois / node-monitoring.md
Last active October 2, 2023 13:50
Node Grafana/Prometheus Performance Monitoring

Monitor in Node (PerformanceObserver is not yet implemented in Bun. in bun 1.0.3)

import { collectDefaultMetrics, register } from 'prom-client'

if (req.method === 'GET' && pathname === '/metrics/') {
  return new Response(await register.metrics(), {
    headers: {
      'Content-Type': register.contentType,
 },
@christophemarois
christophemarois / zod-unique-array.ts
Created September 29, 2023 23:04
Zod Unique Array
/** Array where are elements are expected to be unique by a custom key */
export function zUniqueArray<
ArrSchema extends z.ZodArray<z.ZodTypeAny, 'many'>,
UniqueVal,
>(
uniqueBy: (item: z.infer<ArrSchema>[number]) => UniqueVal,
schema: ArrSchema,
) {
return schema.superRefine((items, ctx) => {
const seen = new Set<UniqueVal>()
@christophemarois
christophemarois / docker-cheatsheet.md
Last active September 21, 2023 15:49
Docker Cheatsheet

Run a local Dockerfile with a local .env file

docker build \

Show complete log

--progress=plain \

Nested dockerfile, useful for monorepos when we want to preserve CWD