Skip to content

Instantly share code, notes, and snippets.

@jcuffe
jcuffe / Encode-With-Options-Matrix.ps1
Created August 7, 2023 15:44
Run FFMPEG against an input file with every combination of options contained in a config file
param(
[string]$inputFilePath,
[string]$configFilePath
)
if (-not $inputFilePath) {
Write-Host "Please provide a valid input file path"
exit
}
@jcuffe
jcuffe / index.js
Last active August 3, 2023 20:18
ESM internal module mocks
import { __testVisible as self } from './index.mjs';
function a() {
return 1;
}
export function b() {
return self.a();
}
@jcuffe
jcuffe / superconstellations.md
Created November 13, 2022 20:23
Superconstellations

It's never been easier to elevate your latest project from your laptop to the Internet, allowing you to show your proof of concept to anyone with a simple url. However, some pieces of the puzzle have remained frustratingly difficult to place without relying on a paid service. For me, that piece was the persistence layer. I've always been a big fan of SQL, and Postgres in particular. Simple enough for the simplest MVP, and reliably consistent enough for business-critical data, it's a piece of tech I learned once and have used in every project since. Unfortunately, free database offerings are far less common than free static file hosts.

@jcuffe
jcuffe / kcombos.js
Created August 3, 2022 06:13
Best K Combos, probably
const pq = [];
function enqueue(value, priority) {
const item = { value, priority };
for (let i = 0; i < pq.length; i++) {
const { value: pqValue, priority: pqPriority } = pq[i];
// Maintain min-heap, sorted by (value, priority)
if (value < pqValue || (value === pqValue && priority < pqPriority)) {
pq.splice(i, 0, item);
return;
@jcuffe
jcuffe / kcombos.js
Created August 3, 2022 02:03
Best K Combos, probably
const values = [5, 4, 4, 4, 4, 0, 0, 0, -1, -1, -1, -3];
const k = 20;
function main() {
// Build a lookup of value frequencies, and calculate the best combo
let bestCombo = 0;
const frequencies = {};
for (const value of values) {
const absValue = Math.abs(value);
if (!frequencies[absValue]) {
@jcuffe
jcuffe / ContextError.jsx
Created April 30, 2022 16:30
Invocation context example
import { useStore, component$ } from '@builder.io/qwik';
import axios from 'axios';
export const Main = component$(async () => {
const response = await axios.get('https://httpbin.org/')
const state = useStore({ name: 'World', status: response.status });
return (
<p>Status: {state.status}</p>
);
});
@jcuffe
jcuffe / #Query strategies for admin-record endpoint.md
Last active April 30, 2022 00:15
ApacheBench results for traditionally slow-running requests under various strategies

The various search patterns afforded to customers make it challenging to generally optimize the query performed by the /admin/record endpoint.

This gist explores several strategies that offer significant improvement for specific query patterns.

// New cursor format
const cursor = (record, columnName) => base64.encode(JSON.stringify({
name: record.constructor.name,
columnName,
value: record[columnName],
recordId: record.id
}))
// Paginate based on (potentially not unique) cursor column value, as well as (unique) record id
if (connection?.before) {
@jcuffe
jcuffe / Server Output
Created July 18, 2021 20:19
Global ID Mixup
ARGS {
input: [Object: null prototype] {
eventId: '969356d5-6156-4064-a754-b4d6399186de',
userId: 'auth0|609c4d9117bcf2007065def6',
role: 'creator'
}
}
HOST ROLE UPDATE
DEMOTED CREATOR auth0|5d9cf8731aa11a0c5bac758e
PROMOTED COHOST auth0|609c4d9117bcf2007065def6
@jcuffe
jcuffe / demo.js
Created March 30, 2021 22:45
Nested `await` demo
// Query builders are not actually promises, but have a `.then()` method which matches the promise interface.
// As soon as you `await` or `.then()` the builder, the query is executed, and a new promise is generated that will contain the result.
const getQueryBuilder = () => ({
then: (resolve) =>
resolve(
new Promise((resolve) =>
setTimeout(() => resolve(["query", "results"]), 1000),
),
),
})