Last active
November 22, 2021 19:45
-
-
Save danielberndt/eb59230c4ac5c2fd7edaa27dfb2b2e89 to your computer and use it in GitHub Desktop.
Revisions
-
danielberndt revised this gist
Nov 22, 2021 . 1 changed file with 46 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,46 @@ 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; return memo; }, {} as {[l: string]: number}); return { intToSeq(intVal: number) { const seq = []; let q = intVal + startVal; if (implicitZero) q += 1; let r; do { if (implicitZero) q += -1; r = q % length; q = Math.floor(q / length); seq.unshift(letters[r]); } while (q); return seq.join(""); }, seqToInt(seq: string) { let intVal = letterToIndex[seq[0]] || 0; for (let i = 1; i < seq.length; i += 1) { if (implicitZero) intVal += 1; intVal *= length; intVal += letterToIndex[seq[i]]; } return intVal - startVal; }, letters, }; }; export const pronounceSafeSeq = lettersToSequence("123456789acefghijkoqrsuvwxyz", { startVal: 28 * 29 - 1, implicitZero: true, }); // use like this: pronounceSafeSeq.seqToInt('13c') -> 67 -
danielberndt revised this gist
Nov 22, 2021 . 2 changed files with 39 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ 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"] }, }; let query = { _root: [ { account: [ { [`timeTrackingSegments(${JSON.stringify(segmentQuery)})`]: [ "startedAt", "finishedAt", "modifyDurationMsBy", "id", { user: ["name"], card: [ "accountSeq", "title", { deck: ["title"], parentCard: ["title"], }, ], }, ], }, ], }, ], }; await fetch(`https://api.codecks.io?query=${JSON.stringify(query)}&x-account=${subdomain}`).then(r => r.json()) File renamed without changes. -
danielberndt created this gist
Nov 22, 2021 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ let subdomain = YOUR_SUBDOMAIN let deckNumber = TAKE_NUMBER_FROM_URL let cardQuery = `cards({"deck":{"accountSeq":${deckNumber}},"coverFileId":null})` let query = {_root: [{account: [{[cardQuery]: [{attachments:[{file:["id","meta"]}]}]}]}]} let result = await fetch(`https://api.codecks.io?query=${JSON.stringify(query)}&x-account=${subdomain}`).then(r => r.json()) for (let cardId of result.account[result._root.account][cardQuery]) { let card = result.card[cardId] if (!card.attachments.length) continue; let files = card.attachments.map(a => result.file[result.attachment[a].file]) let img = files.find(f => f.meta.type) if (!img) continue await fetch(`https://api.codecks.io/dispatch/cards/update?x-account=${subdomain}`, { headers: {"content-type": "application/json"}, body: JSON.stringify({id: cardId, coverFileId: img.id}), method: "POST", }); await new Promise(r => setTimeout(r, 100)) }