Skip to content

Instantly share code, notes, and snippets.

View darknoon's full-sized avatar

Andrew Pouliot darknoon

View GitHub Profile
@darknoon
darknoon / jsx.min.gbnf
Created October 15, 2023 23:03
Minimal gbnf for jsx-ish content
## Trying to debug why this is slow
# root rule
root ::= jsxElement
# Main JSX Element
jsxElement ::=
"<" jsxElementName jsxAttributesOpt ">" jsxChildrenOpt "</" jsxElementName ">"
# JSX Self-Closing Element
/* eslint-disable @typescript-eslint/no-var-requires */
const { ReplaceSource } = require("webpack-sources")
/// This is a workaround for a bug in Figma plugins where they don't like the text "import("
class FigmaWorkaroundPlugin {
// based on BannerPlugin https://github.com/webpack/webpack/blob/05ebf5bba670152101d1cc0f42f165b9fd295164/lib/BannerPlugin.js
process(file) {
if (file.source().includes("import(")) {
const replace = new ReplaceSource(file, "fix import( in Figma plugins FigmaWorkaroundPlugin")
@darknoon
darknoon / gist:65d06b5da6541672d1e774ea7297a641
Created January 5, 2022 17:38
Typescript error with react-spring and @react-three/fiber
Type 'Interpolation<[pan: number, tilt: number], [x: number, y: number, z: number, order?: string | undefined]>' is not assignable to type '[x: number, y: number, z: number, order?: string | undefined] | { x: number | FluidValue<number, any>; y: number | FluidValue<number, any>; z: number | FluidValue<number, any>; ... 14 more ...; _onChange: {}; } | [x: ...] | undefined'.
Type 'Interpolation<[pan: number, tilt: number], [x: number, y: number, z: number, order?: string | undefined]>' is not assignable to type '[x: number | FluidValue<number, any>, y: number | FluidValue<number, any>, z: number | FluidValue<number, any>, order?: string | FluidValue<string, any> | undefined]'.
@darknoon
darknoon / XCAssets.ts
Created September 17, 2021 15:38
Is this the best way to generate a Zip file in Scripter?
const colors = figma.getLocalPaintStyles()
.map(c => {
const {name, paints} = c
const paint = paints[0]
if (isSolidPaint(paint)) {
const {opacity, color} = paint
const {r,g,b} = color
return {name, color: {red: r, green: g, blue: b, alpha: opacity} }
} else {
return undefined
@darknoon
darknoon / LocklessQueue.swift
Created November 11, 2020 21:30
LocklessQueue
//
// LocklessQueue.swift
// Famera
//
// Created by Andrew Pouliot on 11/11/20.
// Copyright © 2020 Famera. All rights reserved.
//
import Foundation
import CoreMedia
@darknoon
darknoon / sign_s3_url.sql
Last active March 30, 2022 16:37
A function that lets you sign S3 urls for viewing from within your database queries
-- This function is based on this description:
-- https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-query-string-auth.html
CREATE OR REPLACE FUNCTION
sign_s3_url(
m_host text,
m_verb text,
m_resource text,
m_region text,
m_key text,
@darknoon
darknoon / getHost.ts
Created November 5, 2019 21:46
A simple way to get the right host to query your API in serverless next.js
const getHost = (context: NextPageContext): { host: string; proto: string } => {
const { req } = context;
if (req !== undefined) {
const {
"x-forwarded-host": host,
"x-forwarded-proto": proto
} = req.headers;
if (
typeof host === "string" &&
typeof proto === "string" &&
@darknoon
darknoon / now.json
Last active October 30, 2019 16:33
How to make Private GH packages work with now and yarn
{
"build": {
"env": {
"MY_GH_TOKEN": "@my_gh_packages_access_token",
"NPM_RC": "registry=https://npm.pkg.github.com/<USERNAME or ORG>\n//npm.pkg.github.com/:_authToken=${MY_GH_TOKEN}\n//npm.pkg.github.com/<USERNAME or ORG>/:_authToken=${MY_GH_TOKEN}\nalways-auth=true\n"
}
},
}
@darknoon
darknoon / figma-default-layers.json
Last active October 25, 2019 04:07
Default values for the different layer types in the Figma plugin API
{
"RECTANGLE": {
"type": "RECTANGLE",
"name": "Rectangle",
"visible": true,
"locked": false,
"opacity": 1,
"blendMode": "PASS_THROUGH",
"isMask": false,
"effects": [],
@darknoon
darknoon / SwiftUIEnum.swift
Created June 12, 2019 22:43
How to create a View that renders different content based on enum cases in Swift UI
enum Block {
case h(title: String)
case p(body: String)
}
extension View {
func erased() -> AnyView {
return AnyView(self)
}
}