Skip to content

Instantly share code, notes, and snippets.

View aleclarson's full-sized avatar

Alec Larson aleclarson

View GitHub Profile
const MagicString = require('magic-string');
const assert = require('assert');
const kleur = require('kleur');
function test() {
const s1 = new MagicString('abcde');
const s2 = s1.clone();
const desiredResult = 'abxcde';
import { route } from 'saus'
// Default route
route(() => import('./routes/UnknownPage'))
// Catch route
route('error', () => import('./routes/ErrorPage'))
//
// Matched routes
const reservedChars = /[\r\n,"]/
module.exports = function toCSV(header, rows) {
rows = rows.map(row => row.map(valueToString).join(','))
return [header.join(','), ...rows].join('\r\n') + '\r\n'
}
function valueToString(value) {
return value === undefined
? ''
// Adapted from: https://digitalbunker.dev/2020/09/13/understanding-gaussian-blurs/
function gaussianBlurMatrix(blurRadius: number) {
if (blurRadius !== Math.round(blurRadius) || blurRadius <= 0) {
throw Error('Blur radius must be a positive integer')
}
const kernel: number[] = []
const kernelWidth = 1 + 2 * blurRadius
const kernelSize = kernelWidth * kernelWidth
// Adapted from https://github.com/lukeed/escalade/blob/2477005/src/sync.js
import { dirname, join } from 'path'
import { readdirSync } from 'fs'
/**
* Search each parent directory until a string or false is returned.
*/
export function findFile(
dir: string,
callback: (names: string[], dir: string) => string | false | undefined
@aleclarson
aleclarson / .indo.json
Last active April 13, 2021 16:29
Gist for indo test suite
{
"repos": {
"mixpa": {
"url": "https://github.com/aleclarson/mixpa"
}
}
}
@aleclarson
aleclarson / CGImage-AlphaMask.m
Created January 30, 2021 19:16
Alpha mask from CGImage
CGImageRef createAlphaMask(CGImageRef inputImage) {
int width = (int)CGImageGetWidth(inputImage);
int height = (int)CGImageGetHeight(inputImage);
int bytesPerRow = (int)CGImageGetBytesPerRow(inputImage);
CGColorSpaceRef colorSpace = CGImageGetColorSpace(inputImage);
CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(inputImage);
unsigned char *data = (unsigned char *)calloc(bytesPerRow * height, 1);
CGContextRef ctx = CGBitmapContextCreate(data,
width,
@aleclarson
aleclarson / .rollup-plugin-preserve-jsx.md
Last active May 11, 2022 06:43
rollup-plugin-preserve-jsx

rollup-plugin-preserve-jsx

Preserve JSX with proper tree-shaking.

  • acorn-jsx is injected for you.
  • @babel/plugin-syntax-jsx is needed if you're using Babel.

 

TODO

@aleclarson
aleclarson / fail.patch
Created November 12, 2020 23:51
Failed attempt to apply separate tsconfig.json to __tests__ and __stories__ modules
commit 3c0e91303b54f3e01ff136f11e9f4b08017a9a45
Author: Alec Larson <[email protected]>
Date: Thu Nov 12 18:41:10 2020 -0500
wip
diff --git a/app/tsconfig.base.json b/app/tsconfig.base.json
new file mode 100644
index 0000000..8123fe5
--- /dev/null
import {expectOple} from 'ople'
// Note: Unique function values are expected.
export function forwardListeners(listenFns) {
const disposeFns = new Map()
const self = expectOple()
hookBefore(self, {
_addListener(key, fn) {
if (!listenFns[key]) return
disposeFns.set(fn, listenFns[key](fn))