Skip to content

Instantly share code, notes, and snippets.

@danielberndt
danielberndt / sequences.ts
Created October 20, 2023 08:07
Sequences
const lettersToSequence = (
letters: string,
{startVal = 0, implicitZero = false}: {startVal: number; implicitZero: boolean} = {
startVal: 0,
implicitZero: false,
}
) => {
const length = letters.length;
const letterToIndex = letters.split("").reduce((memo, letter, index) => {
memo[letter] = index;
@danielberndt
danielberndt / README.md
Last active October 26, 2022 09:45
Codecks Api Guide

Quick Guide to Tinkering with the Codecks API

Version: Jan 2021

The Codecks API is the source for powering the web app, so expect it to be fairly stable and expansive. We can't yet make any guarantees regarding the stability of all schema definitions and endpoints at this point. So tread with care!

To get started you need to extract your access token. This token will allow anyone who holds it to impersonate you. This also means they have access to all the same Organizations and contents as you do via the web app. So be careful who you share it with. You might want to create an observer user and use their token if this helps your use case (and the observer limitations suit your use case) you might also create a new non-observer user but this will count towards your user quota.

To extract the token, check requests going to the codecks api (https://api.codecks.io). There you'll find a cookie called at containing your token.

@danielberndt
danielberndt / snippet-to-be-pasted-into-browser.js
Last active October 24, 2022 11:54
extract all cards via api
let subdomain = "MYSUBDOMAIN"; // for e.g. MYSUBDOMAIN.codecks.io
let cardQuery = {cardCreatedAt: {op: "gt", value: "2022-10-20"}};
// build up the nested query and define which models and fields we want to receive
let query = {
_root: [
{
account: [
{
@danielberndt
danielberndt / snippet-to-be-pasted-into-browser.js
Last active September 22, 2022 12:01
Codeck.io-Api: get info about card by it's three letter id
let subdomain = YOUR_SUBDOMAIN;
let CARD_ID='123'
// turns the string representation of a card id into a number.
// `111` will become 1, `15z` will become 140
let convertIdToNumber = (seq) => {
let startVal = 28 * 29 - 1;
let implicitZero= true;
let letters = "123456789acefghijkoqrsuvwxyz";
let length = letters.length;
@danielberndt
danielberndt / Group.ts
Last active September 18, 2022 20:09
React Suspense Abstraction for PouchDb (or other async ressources)
import {Nominal} from "../types";
import PouchDB from "pouchdb-browser";
import LRU from "lru-cache";
export type GroupId = Nominal<string, "GroupId">;
export type GroupOverviewEntry = {
name: string;
createdAt: Date;
};
let subdomain = SUBDOMAIN;
let segmentQuery = {
$and: [
{ startedAt: { op: "gte", value: "2020-11-03T23:00:00.000Z" } },
{ startedAt: { op: "lt", value: "2020-12-01T23:00:00.000Z" } },
],
user: { name: ["daniel","tom","Alex"] },
};
@danielberndt
danielberndt / useLocalStorageState.js
Last active August 19, 2021 10:57
useLocalStorageState
import {useEffect, useMemo, useRef, useState} from "react";
const getStorageMap = (storageGetter) => {
let storage;
try {
storage = storageGetter();
} catch {
return {
storageGet() {
return null;
@danielberndt
danielberndt / load-from-json.js
Last active February 26, 2020 12:36
load pixi.js sprite sheet jsons via webpack
`
this allows you to use all of webpack's goodness to load your sprites.
here's some benefits:
- saving one roundtrip since webpack's json-loader will inline the json data into the script. Thus it doesn't need to be loaded from the server first
- use a lot of the file-loader power and beyond to create cache-busting urls, and apply image-minification via e.g. image-webpack-loader
`
import PIXI from "pixi.js";
import React from "react";
import ResizeObserver from "resize-observer-polyfill";
import shallowEqual from "fbjs/lib/shallowEqual";
export default class PausableMeasure extends React.Component {
node = null;
state = {bounds: null};
componentWillMount() {
if (!this.props.dontMeasure) this.setup();
@danielberndt
danielberndt / IsIntersecting.jsx
Created January 7, 2019 11:20
IsIntersecting Component using IntersectionObserver
import React from "react";
export default class IsIntersecting extends React.Component {
state = {isIntersecting: false};
observer = null;
rootRef = React.createRef();
elementRef = React.createRef();
componentDidMount() {