Skip to content

Instantly share code, notes, and snippets.


Cole Lawrence colelawrence

View GitHub Profile
colelawrence /
Last active Sep 9, 2020
`shipyard_app` plugin for adding a "tracked" unique which is reset across updates.
//! A small change tracker to wrap around a unique so you can determine if the value changes between updates.
use crate::prelude::*;
use std::{fmt, ops::Deref, ops::DerefMut};
pub struct TrackedUnique<T: ?Sized>(InnerTrackedState, T);
pub type TrackedUniqueView<'a, T> = UniqueView<'a, TrackedUnique<T>>;
pub type TrackedUniqueViewMut<'a, T> = UniqueViewMut<'a, TrackedUnique<T>>;
colelawrence /
Created Sep 9, 2020
Change `Tracked` container for Rust to be used with Shipyard
use std::{fmt, mem, ops::Deref};
pub struct Tracked<T: ?Sized>(InnerTrackedState, T);
enum InnerTrackedState {
colelawrence /
Created Jul 14, 2020
pre-commit configs which basically does what checks both rust and typescript files hmm...
git config core.hooksPath .githooks/
chmod +x .githooks/pre-commit
colelawrence /
Last active Jul 10, 2020
Implementing tracing Layer for use with browser performance
use std::fmt::{self, Write};
use std::sync::atomic::AtomicUsize;
use tracing;
use tracing::field::{Field, Visit};
use tracing::Subscriber;
use tracing_subscriber;
use tracing_subscriber::layer::*;
use tracing_subscriber::registry::*;
use wasm_bindgen::prelude::*;
View promise-once-lazy.ts
/** Lazy promise fetch will reuse promise if one was already created */
export function lazy<F extends () => Promise<any>>(f: F): F {
let once: ReturnType<F> | undefined
// @ts-ignore
return function () {
// @ts-ignore
if (once === undefined) once = f.apply(this, arguments)
return once
colelawrence / diffSets.js
Last active May 25, 2020
Determine the difference between two iterables, returns {toAdd, toRemove}
View diffSets.js
* @template T
* @param {Iterable<T>} original
* @param {Iterable<T>} updated
function diffSets(original, updated) {
const toRemove = new Set(original);
const toAdd = new Set();
// compare which items are new to us
for (const id of updated) {
View prosemirror-changeset.d.ts
* # prosemirror-changeset
* This is a helper module that can turn a sequence of document changes into a set of insertions and deletions, for example to display them in a change-tracking interface. Such a set can be built up incrementally, in order to do such change tracking in a halfway performant way during live editing.
* This code is licensed under an MIT licence.
* ## Programming interface
* Insertions and deletions are represented as ‘spans’—ranges in the document. The deleted spans refer to the original document, whereas the inserted ones point into the current document.
* It is possible to associate arbitrary data values with such spans, for example to track the user that made the change, the timestamp at which it was made, or the step data necessary to invert it again.
* Based on last [commit made Mar 12, 2019]( */
View get-cookie.ts
View .logger.ts
const toString = str => (typeof str === 'function' ? : String(str));
export function getLogger(...names: (string | Function)[]): Logger {
return createLogger(;
interface Logger {
info(message: string, ...args: any[]): void;
debug(message: string, ...args: any[]): void;
warn(message: string, ...args: any[]): void;
View .define-i18n.ts
type LanguageKey = keyof Definitions<any>
let currentLanguage: LanguageKey = "en"
* @param namespace most underlying i18n solutions like to have a namespace
function define<T>(namespace: string, definitions: Definitions<T>): Translate<T> {
// ... set up with your existing translation library which supports fallbacks and such...
return key => `Key (${key}) has no definition`
You can’t perform that action at this time.