Skip to content

Instantly share code, notes, and snippets.

@queerviolet
queerviolet / letterbox.ts
Created December 22, 2020 17:35
letterbox.ts
type Ratio = [number, number]
type Size = {width: number, height: number}
type Position = {top: number, left: number}
type Frame = Position & {bottom: number, right: number}
export type Box = Frame & Size
export type Letterbox = Box & { bars: Box[], su: number }
/**
* Compute a letterbox and apply its measurements as CSS properties to document.body.
*
@queerviolet
queerviolet / airtable-blast.js
Last active May 3, 2020 04:40
sms contactless delivery
const deliveries = base.getTable('deliveries')
const subscribers = base.getTable('subscribers')
/**
* @type {deliveriesTable_Record?}
*/
let delivery = null
while (!delivery) {
output.clear()
output.markdown(
@queerviolet
queerviolet / cell.ts
Created January 10, 2020 17:46
a cellular reactive framework
export const Source_outputs = Symbol('Cell outputs')
export const Sink_inputs = Symbol('Cell inputs')
export const Source_willOpen = Symbol('Source will attach its first output')
export const Source_didClose = Symbol('Source did detach its last output')
export const Sink_willOpen = Symbol('Sink did attach its first input')
export const Sink_didClose = Symbol('Sink did detach its last input')
export const Sink_update = Symbol('Sink update')
@queerviolet
queerviolet / block-transactions.ts
Last active May 25, 2024 04:38
Handling Database Transactions with Apollo Server
/**
* If your database provides block transactions, (like Sequelize,
* here: https://sequelize.org/master/manual/transactions.html) here's how to
* use them in Apollo Server:
*/
import { ApolloServerPlugin, GraphQLRequestContext } from 'apollo-server-plugin-base'
export interface Transactable<Txn> {
transact?: Transact<Txn>
@queerviolet
queerviolet / zillow-export.js
Last active June 18, 2024 20:02
Export Saved Homes from Zillow
const homes = [...new Set(
[...document.querySelectorAll('a[href]')]
.map(x => x.href)
.filter(u => u.includes('_zpid'))
)]
.map(id => {
const addr = id.split('/')[4].replace(/-/g, ' ')
const short = addr.split(' ').slice(0, -3).join(' ')
return { addr, zillow: id,
streeteasy: `https://streeteasy.com/search?search=${short}`,
@queerviolet
queerviolet / server.js
Created November 26, 2018 15:52
Express error handling
class BadError extends Error {
get type() { 'very bad' }
}
require('express')()
// Express will convert this synchronous throw
.get('/', (_req, res) => {
throw new BadError('threw an error: failed')
})
// Into a pipeline error, handled here:
@queerviolet
queerviolet / webpack.conf.js
Created March 15, 2018 19:10
spark multitenant webpack
'use strict'
const webpack = require('webpack')
, babel = require('./babel.config')
, {isHot, isProd} = require('./env.config')
const config = env => (input, output) => ({
entry: entries(env, input),
output,
devtool: 'source-map',
resolve: {
@queerviolet
queerviolet / form.jsx
Last active March 2, 2018 04:05
Select which component to render
const Beer = () => <div>
<input name='$$abv' />
</div>
const Wine = () => <div>
<input name='$$vintage' />
<input name='$$appellation' />
</div>
class Form extends React.Component {
@queerviolet
queerviolet / happy-numbers.js
Last active February 27, 2018 20:40
Floyd's cycle finder applied to happy numbers, in JS.
/**
* Exports an Object like {1: 1, 7: 7, 10: 10, ...},
* containing happy numbers up to 1000.
*
* This makes it easy for the test to check whether a given
* number is happy.
*/
module.exports = Object.assign(
...[
1, 7, 10, 13, 19, 23, 28, 31, 32, 44, 49, 68, 70, 79, 82, 86, 91, 94, 97, 100, 103, 109, 129, 130, 133, 139, 167, 176, 188, 190, 192, 193, 203, 208, 219, 226, 230, 236, 239, 262, 263, 280, 291, 293, 301, 302, 310, 313, 319, 320, 326, 329, 331, 338, 356, 362, 365, 367, 368, 376, 379, 383, 386, 391, 392, 397, 404, 409, 440, 446, 464, 469, 478, 487, 490, 496, 536, 556, 563, 565, 566, 608, 617, 622, 623, 632, 635, 637, 638, 644, 649, 653, 655, 656, 665, 671, 673, 680, 683, 694, 700, 709, 716, 736, 739, 748, 761, 763, 784, 790, 793, 802, 806, 818, 820, 833, 836, 847, 860, 863, 874, 881, 888, 899, 901, 904, 907, 910, 912, 913, 921, 923, 931, 932, 937, 940, 946, 964, 970, 973, 989, 998, 1000
@queerviolet
queerviolet / .gitignore
Last active January 18, 2018 17:32
A little calculator
node_modules