Skip to content

Instantly share code, notes, and snippets.

View joelgallant's full-sized avatar
🚗

Joel Gallant joelgallant

🚗
View GitHub Profile
@sindresorhus
sindresorhus / esm-package.md
Last active June 26, 2024 12:32
Pure ESM package

Pure ESM package

The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
@lukehoban
lukehoban / lambda_test.go
Created February 25, 2020 06:19
Untyped Lambda Calculus, Chruch Numerals, Y Combinator in Golang
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
type V func(v V) V
@laughinghan
laughinghan / Every possible TypeScript type.md
Last active June 19, 2024 10:18
Diagram of every possible TypeScript type

Hasse diagram of every possible TypeScript type

  • any: magic, ill-behaved type that acts like a combination of never (the proper [bottom type]) and unknown (the proper [top type])
    • Anything except never is assignable to any, and any is assignable to anything at all.
    • Identities: any & AnyTypeExpression = any, any | AnyTypeExpression = any
    • Key TypeScript feature that allows for [gradual typing].
  • unknown: proper, well-behaved [top type]
    • Anything at all is assignable to unknown. unknown is only assignable to itself (unknown) and any.
    • Identities: unknown & AnyTypeExpression = AnyTypeExpression, unknown | AnyTypeExpression = unknown
  • Prefer over any whenever possible. Anywhere in well-typed code you're tempted to use any, you probably want unknown.
@cb109
cb109 / yup_array_oneOfSchemas.js
Last active June 5, 2023 11:30
YUP: Validate that items in an Array match one of multiple allowed Schemas
/**
* The yup library has no builtin way to check if items in an array
* match one or more defined shapes, we can only check against a set of
* whitelisted values using yup.array().oneOf([..]).
*
* Using yup.addMethod() and yup.mixed().test() however we can pretty
* much add any custom validation we want. The function below allows to
* make validation pass for array items of different shapes.
*/
@bcantrill
bcantrill / ub.c
Created January 11, 2019 18:41
Punishment doesn't fit the crime?
#define NULL ((void *)0)
static char *arr[2] = { "nasal", "demons" };
long
func()
{
int i;
for (i = 0; i <= 2; i++) {
from __future__ import division
import cv2
import numpy as np
import matplotlib.pyplot as plt
import os
os.chdir('C:/Users/gennady.nikitin/Dropbox/Coding/OpenCV')
# define variable for resize tratio
ratio = 1
@KodrAus
KodrAus / Profile Rust on Linux.md
Last active November 14, 2023 17:19
Profiling Rust Applications

Profiling performance

Using perf:

$ perf record -g binary
$ perf script | stackcollapse-perf.pl | rust-unmangle | flamegraph.pl > flame.svg

NOTE: See @GabrielMajeri's comments below about the -g option.

@Rich-Harris
Rich-Harris / footgun.md
Last active June 16, 2024 00:01
Top-level `await` is a footgun

Edit — February 2019

This gist had a far larger impact than I imagined it would, and apparently people are still finding it, so a quick update:

  • TC39 is currently moving forward with a slightly different version of TLA, referred to as 'variant B', in which a module with TLA doesn't block sibling execution. This vastly reduces the danger of parallelizable work happening in serial and thereby delaying startup, which was the concern that motivated me to write this gist
  • In the wild, we're seeing (async main(){...}()) as a substitute for TLA. This completely eliminates the blocking problem (yay!) but it's less powerful, and harder to statically analyse (boo). In other words the lack of TLA is causing real problems
  • Therefore, a version of TLA that solves the original issue is a valuable addition to the language, and I'm in full support of the current proposal, which you can read here.

I'll leave the rest of this document unedited, for archaeological

@juhaelee
juhaelee / react-typescript.md
Last active May 28, 2024 17:41
React + Typescript Cheatsheet

React + Typescript Cheatsheet

Setup

If you use atom... download & install the following packages:

What are Typescript type definition files? (*.d.ts)