This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useEffect, useLayoutEffect, useState } from 'react' | |
import { FlatList, SafeAreaView } from 'react-native' | |
import RNFS from 'react-native-fs' | |
import Realm from 'realm' | |
export function App() { | |
const r = useWaitForRealm() | |
const [initialized, setInitialized] = useState(false) | |
useEffect(() => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useEffect, useLayoutEffect, useState } from 'react' | |
import { FlatList, SafeAreaView } from 'react-native' | |
import RNFS from 'react-native-fs' | |
import Realm from 'realm' | |
export function App() { | |
const r = useWaitForRealm() | |
const [initialized, setInitialized] = useState(false) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* The transformer signature is based on https://github.com/cevek/ttypescript#program | |
* Need to use https://github.com/microsoft/TypeScript/blob/bae0f508184280c59d2865a35efc63be362eacfa/src/compiler/factory/nodeFactory.ts | |
* The goal is to conver `a!.m()` to `if (!a) { throw new Error('Attempted to use nullish value "a"'} else { a.m() }` | |
* https://astexplorer.net/#/gist/9ec2af3e8c15fd2cde848941e14f566b/d9ddca954379374f98a4097d9bde4c346dac8567 | |
*/ | |
export default function (program) { | |
const checker = program.getTypeChecker() | |
return (context) => { | |
return (sourceFile) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ---- START IMPORTS ---- | |
export type AssertionExtra = (Record<string, unknown> & { name?: ErrorCode }) | ErrorCode | |
export function assert(predicate: any, message: string, extra: AssertionExtra = {}): asserts predicate { | |
if (!predicate) { | |
extra = typeof extra === 'string' ? { name: extra } : extra | |
if (!('name' in extra)) { | |
extra.name = ErrorCode.AssertionError | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { serve } from 'https://deno.land/std/http/server.ts' | |
// import { assert, ErrorCode } from './assert.ts' | |
export enum ErrorCode { | |
RaceNotFound = 'RaceNotFound', | |
RaceMemberNotFound = 'RaceMemberNotFound', | |
RaceAlreadyExists = 'RaceAlreadyExists', | |
RaceMemberAlreadyExists = 'RaceMemberAlreadyExists', | |
AssertionError = 'AssertionError', | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const wrap = (obj, method) => { | |
const oldMethod = obj[method] | |
async function innerMethod(...args) { | |
const start = Date.now() | |
try { | |
const ret = await oldMethod.call(obj, ...args) | |
console.log(method, 'took', Date.now() - start, args[0]) | |
return ret | |
} catch (error) { | |
console.log(method, 'took', Date.now() - start) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import AWS from 'aws-sdk' | |
import { uuid } from 'short-uuid' | |
import { yesno } from 'yesno-http' | |
yesno.spy() | |
const documentClient = new AWS.DynamoDB.DocumentClient({ | |
apiVersion: 'latest', | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function area(image) { | |
return image.width * image.height; | |
} | |
/** https://en.wikipedia.org/wiki/Halton_sequence */ | |
function halton(index, base) { | |
let fraction = 1; | |
let result = 0; | |
while (index > 0) { | |
fraction /= base; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Fn = (signal: AbortController['signal']) => Promise<unknown> | |
/** or woman or non-binary for that matter */ | |
export const createOneManQueue = () => { | |
let task: Promise<unknown> = Promise.resolve() | |
let abortController = new AbortController() | |
const enqueue = (fn: Fn) => { | |
abortController.abort() | |
abortController = new AbortController() | |
task.finally(() => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class AbortSignal { | |
public pending = false | |
public completed = false | |
public onAbort: () => void | undefined | |
private resolve: () => void | undefined | |
async abort() { | |
if (this.completed) return | |
const promise = new Promise<void>((r) => { | |
this.resolve = r |
NewerOlder