Skip to content

Instantly share code, notes, and snippets.

View cindywu's full-sized avatar
🍍
i do not want to turn into dust, but into ashes instead

Cindy Wu cindywu

🍍
i do not want to turn into dust, but into ashes instead
View GitHub Profile
import type { Replicache } from "replicache";
import { useSubscribe } from "replicache-react";
import { getClientState, clientStatePrefix } from "./client-state";
import { getShape, shapePrefix } from "./shape";
import { getItem, itemPrefix } from "./item"
import { getArrow, arrowPrefix } from './arrow'
import type { M } from "./mutators";
export function getItems(rep: Replicache<M>) {
return useSubscribe(
import React from 'react'
import { useItemByID } from '../datamodel/subscriptions'
import TestEditor from './test-editor'
import { htmlToText } from '../util/htmlToText'
import styles from './test-editor-container.module.css'
import TestEditorFootnotes from './test-editor-footnotes'
import TestEditorSubItems from './test-editor-sub-items'
import TestEditorForwardArrows from './test-editor-forward-arrows'
import TestEditorBackArrows from './test-editor-back-arrows'
import TestEditorComments from './test-editor-comments'
import React, { useEffect, useRef, useState } from 'react'
import { createParser, createSerializer } from './editor/config/utils'
import { schema } from './editor/config/schema'
import { EditorState, Transaction } from 'prosemirror-state'
import type { EditorView } from 'prosemirror-view'
import type { Schema } from 'prosemirror-model'
import { exampleSetup } from './editor/plugins/index'
import EditorEditor from './editor-editor'
import type { Replicache } from 'replicache'
import type { M } from '../datamodel/mutators'
@cindywu
cindywu / activity-item.tsx
Created April 6, 2022 21:54
Activity Item Component
import ItemEditorContainer from './item-editor-container'
function ActivityItem({item, rep}: any) {
const [titleValue, setTitleValue] = useState<string>(item.title)
const [contentValue, setContentValue] = useState<string>(item.content)
const { id: itemID } = item
useEffect(() => {
titleValue !== item.title && rep.mutate.updateItemTitle({ id: itemID, title: titleValue })
import React, {
createContext,
useContext,
ReactNode
} from 'react'
type WorkspaceContextType = {
}
import { nanoid } from 'nanoid'
import { z } from 'zod'
const LOCAL_STORAGE_KEY = 'trunk-mini.item-arrows'
export const draftArrow = z.object({
type: z.literal(`arrow`),
id: z.string(),
created_at: z.string(),
created_by: z.string(),
@cindywu
cindywu / IndexedDB101.js
Created July 13, 2021 03:18 — forked from JamesMessinger/IndexedDB101.js
Very Simple IndexedDB Example
// This works on all devices/browsers, and uses IndexedDBShim as a final fallback
var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB || window.shimIndexedDB;
// Open (or create) the database
var open = indexedDB.open("MyDatabase", 1);
// Create the schema
open.onupgradeneeded = function() {
var db = open.result;
var store = db.createObjectStore("MyObjectStore", {keyPath: "id"});
@cindywu
cindywu / rep-pull.ts
Created June 22, 2021 22:10
pages/api/replicache-pull.ts
import { getDB } from '../../db'
// eslint-disable-next-line import/no-anonymous-default-export
export default async (req: any, res: any) => {
const pull = req.body
console.log(`Processing pull`, JSON.stringify(pull, null, ''))
const t0 = Date.now()
try {
const db = await getDB()
@cindywu
cindywu / rep-push.ts
Created June 22, 2021 20:53
pages/api/rep-push.ts
import { getDB } from '../../db.js'
// eslint-disable-next-line import/no-anonymous-default-export
export default async (req: any, res: any) => {
const push = req.body
console.log('Processing push', JSON.stringify(push, null, ''))
const t0 = Date.now()
try {
@cindywu
cindywu / main.rs
Created March 4, 2021 02:01
variant of error thing
use std::fs::File;
use std::io::ErrorKind;
fn main() {
let _f = File::open("hello.txt").unwrap_or_else(|error| {
if error.kind() == ErrorKind::NotFound {
File::create("hello.txt").unwrap_or_else(|error| {
panic!("Problem creating the file: {:?}", error);
})
} else {