Skip to content

Instantly share code, notes, and snippets.

Avatar
🏀
Building a site for basketball fans

Alec Larson aleclarson

🏀
Building a site for basketball fans
View GitHub Profile
View gaussianBlurMatrix.ts
// 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
View findFile.ts
// 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 Apr 13, 2021
Gist for indo test suite
View .indo.json
{
"repos": {
"mixpa": {
"url": "https://github.com/aleclarson/mixpa"
}
}
}
@aleclarson
aleclarson / CGImage-AlphaMask.m
Created Jan 30, 2021
Alpha mask from CGImage
View CGImage-AlphaMask.m
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 Nov 16, 2020
rollup-plugin-preserve-jsx
View .rollup-plugin-preserve-jsx.md

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 Nov 12, 2020
Failed attempt to apply separate tsconfig.json to __tests__ and __stories__ modules
View fail.patch
commit 3c0e91303b54f3e01ff136f11e9f4b08017a9a45
Author: Alec Larson <1925840+aleclarson@users.noreply.github.com>
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
View ople-forwardListeners.js
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))
@aleclarson
aleclarson / rollup-typescript.md
Last active Jan 17, 2022
The best Rollup config for TypeScript libraries
View rollup-typescript.md

Features

🔥 Blazing fast builds
😇 CommonJS bundle
🌲 .mjs bundle
.d.ts bundle + type-checking
🧐 Source maps

Install

@aleclarson
aleclarson / ssl-dev.patch
Last active Jul 17, 2020
Trust all SSL certificates in React Native (in development only)
View ssl-dev.patch
diff --git a/node_modules/react-native/Libraries/Network/RCTHTTPRequestHandler.mm b/node_modules/react-native/Libraries/Network/RCTHTTPRequestHandler.mm
index 274f381..3b573dc 100644
--- a/node_modules/react-native/Libraries/Network/RCTHTTPRequestHandler.mm
+++ b/node_modules/react-native/Libraries/Network/RCTHTTPRequestHandler.mm
@@ -108,6 +108,15 @@ - (void)cancelRequest:(NSURLSessionDataTask *)task
#pragma mark - NSURLSession delegate
+#if DEBUG
+- (void)URLSession:(NSURLSession *)session
View Nothing.h
#import <AppKit/AppKit.h>
// This window becomes main and key when the app loses focus, which ensures
// the "didBecomeKey" and "didBecomeMain" events are posted when they should be.
@interface Nothing : NSWindow <NSWindowDelegate>
- (instancetype)init;
- (instancetype)initWithContentRect:(NSRect)contentRect styleMask:(NSWindowStyleMask)style backing:(NSBackingStoreType)backingStoreType defer:(BOOL)flag NS_DESIGNATED_INITIALIZER;
@end