Skip to content

Instantly share code, notes, and snippets.

@danneu
danneu / esm-package.md
Created January 17, 2024 06:15 — forked from sindresorhus/esm-package.md
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.
@danneu
danneu / golang-vs-clojure-async.md
Last active November 6, 2023 04:09
Google I/O 2012 - Go Concurrency Patterns ported to Clojure Video: http://www.youtube.com/watch?v=f6kdp27TYZs
@danneu
danneu / queue.ts
Created March 24, 2023 21:04
A queue impl where `queue.take()` returns a promise that resolves into a lock when a lock is available.
// USAGE
const queue = new Queue(50)
const middleware = () => async (ctx, next: () => Promise<void>) => {
const lock = await queue.take()
await next().finally(() => {
queue.release(lock)
})
}
@danneu
danneu / plink-plonk.js
Created February 15, 2020 20:00 — forked from tomhicks/plink-plonk.js
Listen to your web pages
@danneu
danneu / 0-README.md
Last active May 9, 2022 06:17
Elm quickstart with Parcel

Elm quickstart with Parcel

Create project boilerplate:

mkdir my-elm-project
cd my-elm-project
elm init
touch src/Main.elm # This is where we put our Elm app
@danneu
danneu / benchmark
Created October 29, 2012 23:04
Ox vs Nokogiri: DOM and SAX parsing comparison
# I'm no benchmark guru. Just did a bunch of:
$ time ruby <filename>
# Note: This is just an 80mb XML file with 38,000 nodes.
ox_dom.rb 4.56s user 0.78s system 93% cpu 5.714 total (550mb)
ox_dom.rb 4.58s user 0.79s system 87% cpu 6.126 total (550mb)
ox_dom.rb 4.60s user 0.80s system 87% cpu 6.140 total (550mb)
nokigiri_dom.rb 11.75s user 1.02s system 94% cpu 13.518 total (895mb)
nokigiri_dom.rb 11.36s user 1.02s system 93% cpu 13.211 total (895mb)
@danneu
danneu / diskio.h
Created February 23, 2021 10:05 — forked from RickKimball/diskio.h
msp430 Petit FatFile System sample
/*-----------------------------------------------------------------------
/ PFF - Low level disk interface modlue include file (C)ChaN, 2009
/-----------------------------------------------------------------------*/
#ifndef _DISKIO
#include "integer.h"
/* Status of Disk Functions */
typedef BYTE DSTATUS;
@danneu
danneu / ruby_koans_151_solution.rb
Created August 4, 2011 22:09
Ruby Koans 151 triangle.rb solution
def triangle(a, b, c)
raise TriangleError if a<=0 or b<=0 or c<=0
raise TriangleError if a+b<=c or b+c<=a or a+c<=b
return :equilateral if a==b and a==c
return :isosceles if a==b or b==c or a==c
:scalene
end
@danneu
danneu / text_to_svg_path.py
Created August 22, 2020 06:15 — forked from CatherineH/text_to_svg_path.py
Convert a text character to an SVG path.
from svgpathtools import wsvg, Line, QuadraticBezier, Path
from freetype import Face
def tuple_to_imag(t):
return t[0] + t[1] * 1j
face = Face('./Vera.ttf')
@danneu
danneu / index.js
Created March 21, 2020 04:44 — forked from joepie91/index.js
Breaking CloudFlare's "I'm Under Attack" challenge
'use strict';
const parseExpression = require("./parse-expression");
function findAll(regex, target) {
let results = [], match;
while (match = regex.exec(target)) {
results.push(match);
}