Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrew Pouliot darknoon

View GitHub Profile
View LocklessQueue.swift
//
// 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
Created Dec 16, 2019
A function that lets you sign S3 urls for viewing from within your database queries
View sign_s3_url.sql
-- 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_resource text,
m_region text,
m_key text,
m_secret text,
@darknoon
darknoon / getHost.ts
Created Nov 5, 2019
A simple way to get the right host to query your API in serverless next.js
View getHost.ts
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 Oct 30, 2019
How to make Private GH packages work with now and yarn
View now.json
{
"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 Oct 25, 2019
Default values for the different layer types in the Figma plugin API
View figma-default-layers.json
{
"RECTANGLE": {
"type": "RECTANGLE",
"name": "Rectangle",
"visible": true,
"locked": false,
"opacity": 1,
"blendMode": "PASS_THROUGH",
"isMask": false,
"effects": [],
@darknoon
darknoon / SwiftUIEnum.swift
Created Jun 12, 2019
How to create a View that renders different content based on enum cases in Swift UI
View SwiftUIEnum.swift
enum Block {
case h(title: String)
case p(body: String)
}
extension View {
func erased() -> AnyView {
return AnyView(self)
}
}
@darknoon
darknoon / error_log.txt
Created Apr 25, 2019
Error attempting to install python.js
View error_log.txt
~/Developer/ML/js-ecosystem/modules/test-pythonjs (master #) $ yarn add python.js
yarn add v1.15.2
info No lockfile found.
[1/4] 🔍 Resolving packages...
[2/4] 🚚 Fetching packages...
[3/4] 🔗 Linking dependencies...
[4/4] 🔨 Building fresh packages...
error /Users/andrew/Developer/ML/js-ecosystem/modules/test-pythonjs/node_modules/python.js: Command failed.
Exit code: 1
Command: node-gyp rebuild
View gist:e5109f74f109a3f854a8a8e1eb495610
Unpacking OpenEXR-2.3.0
-- The C compiler identification is GNU 7.2.1
-- The CXX compiler identification is GNU 4.8.5
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
@darknoon
darknoon / ObjCClass.cocoascript.js
Created Mar 23, 2017
A little bit disgusting, but you can totally create classes with ivars in cocoa script :D
View ObjCClass.cocoascript.js
// Copy-paste this into 💎Sketch.app and run it 🔥
// Scroll to bottom for usage
// Use any C function, not just ones with BridgeSupport
function CFunc(name, args, retVal) {
// Due to particularities of the JS bridge, we can't call into MOBridgeSupport objects directly
// But, we can ask key value coding to do the dirty work for us ;)
function setKeys(o, d) {
const funcDict = NSMutableDictionary.dictionary()
funcDict.o = o
@darknoon
darknoon / classWithIvar.cocoascript.js
Last active Jul 31, 2018
You can use ivars so you don't need to make so many hilarious classes
View classWithIvar.cocoascript.js
// Make a class with some handlers.
function Class(handlers){
var uniqueClassName = "fetchDelegate_" + NSUUID.UUID().UUIDString();
var cls = MOClassDescription.allocateDescriptionForClassWithName_superclass_(uniqueClassName, NSObject);
// Add each handler to the class description
for(var selectorString in handlers) {
var sel = NSSelectorFromString(selectorString);
cls.addInstanceMethodWithSelector_function_(sel, handlers[selectorString]);
}
// Add ivar to store instance-specific info