Skip to content

Instantly share code, notes, and snippets.

View aleclarson's full-sized avatar

Alec Larson aleclarson

View GitHub Profile
@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 <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
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 May 6, 2024 19:37
The best Rollup config for TypeScript libraries

Features

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

Install

@aleclarson
aleclarson / ssl-dev.patch
Last active July 17, 2020 22:56
Trust all SSL certificates in React Native (in development only)
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
#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
diff --git a/node_modules/react-update-url-on-scroll/lib/Manager.js b/node_modules/react-update-url-on-scroll/lib/Manager.js
index 6e8de9f..7cb49c4 100644
--- a/node_modules/react-update-url-on-scroll/lib/Manager.js
+++ b/node_modules/react-update-url-on-scroll/lib/Manager.js
@@ -18,11 +18,11 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
var defaultConfig = {
affectHistory: false,
- debounce: 100,
keepLastAnchorHash: false,
import { is } from 'is'
import { Lookup } from 'types'
// Reuse one array for all encoding.
const pairs: string[] = []
export function encodeForm(values: Lookup) {
for (const key in values) {
encodePair(key, values[key])
}
@aleclarson
aleclarson / unmount.tsx
Created November 2, 2019 12:49
React controlled unmount
import React from 'react'
import { animated, useSpring } from 'react-spring'
const Example = () => {
const [unmount, isUnmounting] = React.useUnmount()
const { opacity } = useSpring({
// Fade in "opacity" from 0
from: { opacity: 0 },
// Fade out "opacity" to 0 when ready to unmount