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
console.log("My awesome snippet"); | |
console.warn("Avoid running untrusted snippets!"); |
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, { useState, useRef, useEffect } from 'react'; | |
import RectContentLoader from './RectContentLoader'; | |
export interface VirtRenderingProps { | |
placeholderHeight?: number; // the height of the rendered item | |
root?: HTMLElement | null; // If the root is null, then the bounds of the actual document viewport are used. | |
children: React.ReactNode; | |
} | |
/** |
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 interface RectContentLoaderProps { | |
placeholderHeight: number; | |
} | |
const RectContentLoader = ({ placeholderHeight }: RectContentLoaderProps) => { | |
return ( | |
<svg height={placeholderHeight}> | |
<rect | |
x="0" | |
y="0" |
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
let textWithSpaces = `foo == "hey there" && foo == "eatPizza"`; | |
let output = parseDummyQL(textWithSpaces); | |
console.log(output); | |
// [ | |
// [ 'foo', '==', 'hey there 🍕' ], | |
// [ '&&', [ 'foo', '==', 'eatPizza 🍕' ] ] | |
// ] |
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 Parsimmon from 'parsimmon'; | |
const P = Parsimmon; | |
let MyFooQueryLang = P.createLanguage({ | |
// `r` eq rules. | |
dummy_query: (r) => r.expression.many(), | |
expression: (r) => P.alt(r.base, r.sub), | |
base: (r) => P.seq(r.field, r.operator, r.value), |
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
/** | |
* Since we don't have a type based pattern matching we're using "tags" runtime check | |
* @param result | |
*/ | |
export function isError<T, E extends ErrorClassification>(result: Result<E, T>): result is E { | |
return typeof result === 'object' && 'message' in result && 'type' in result; | |
} |
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 ResultT<E, T> { | |
private result: Result<ErrorClassification, T>; | |
constructor(result: Result<ErrorClassification, T>) { | |
this.result = result; | |
} | |
ok(onSuccessFn: (lifted: T) => ResultT<E, T>): ResultT<E, T> { | |
return isError(this.result) ? this : onSuccessFn(this.result as T); | |
} |
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
async function fetchTables<E>(auth: any): Promise<Either<void, Promise<void>>> { | |
const sheets = google.sheets({ version: 'v4', auth }); | |
const authorised: Task<string> = async () => readFromFile('src/private/table_meta.json', 'utf-8'); | |
const authErr = () => console.log('error reading private/table_meta.json'); | |
const fetchTables = async (data: string) => { | |
const { tables, id } = JSON.parse(data); | |
const ft: (t: string) => Task<Promise<Either<Error, unknown>>> = (t: string) => task.of(fetchTable(sheets, t, id)); | |
const tasks: Task<string>[] = tables.map(ft); |
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 readCreds: Task<string> = async () => readFromFile('src/private/credentials.json', 'utf-8'); | |
const fail = <T>(reason: T) => new Error(`${reason}`); | |
const auth = (creds: string) => authorize(JSON.parse(creds), fetchTables); | |
export async function exportTables<E>(): Promise<Either<Error, Promise<Either<void, void>>>> { | |
const result: TaskEither<Error, string> = tryCatch(readCreds, fail); | |
return await pipe(result, map(auth))(); | |
} |
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 fetchTable<T>(sheets: Sheets, range: any, spreadsheetId: any): Promise<Either<Error, unknown>> { | |
return new Promise((resolve, reject) => { | |
sheets.spreadsheets.values.get({ spreadsheetId, range }, (err, res) => { | |
if (err || !res.data) { | |
console.log('The API returned an error: ' + err); | |
return reject(err); | |
} | |
return resolve(tableAsJson(res.data.values, range)); | |
}); | |
}); |
NewerOlder