Skip to content

Instantly share code, notes, and snippets.

View andyjessop's full-sized avatar

Andy Jessop andyjessop

View GitHub Profile
import { cx } from './cx';
describe('classes', () => {
describe('cx', () => {
test('cx should combine class names', () => {
const result = cx('class1', { class2: true }, null, undefined, 'class3');
expect(result).toBe('class1 class2 class3');
});
@andyjessop
andyjessop / component.ts
Last active March 13, 2023 08:05
Ant.d's Space component in CSS
import { spaced } from '@crux/design/styles';
...
html`
<div class=${cx(spaced.container, spaced.vertical, spaced.small)}>
<div>1</div>
<div>2</div>
<div>3</div>
</div>`;
@andyjessop
andyjessop / customisation.css
Last active February 22, 2023 13:02
Definition and usage of a custom element that creates equal spaces between child elements
cx-space {
--cx-space-gap-small: 2rem;
--cx-space-gap-default: 2.5rem;
--cx-space-gap-large: 5rem;
}
@andyjessop
andyjessop / draggable.ts
Created October 25, 2022 15:10
Draggable directive
import { Directive, directive } from 'lit/directive.js';
import type { ElementPart, PartInfo } from 'lit/directive.js';
import { noChange } from 'lit';
export class Draggable extends Directive {
registered = false;
render({
id,
onDrag,
@andyjessop
andyjessop / slice.ts
Last active September 12, 2022 09:58
Slice config with async handlers
export function authModule(authHttpApi: Auth, toaster: Toaster) {
return createSlice('auth', {
// In order to update the state, return a new state just as in a normal reducer.
// [name]: (state: S, Payload | Action) => S
// But if you want to make side effects, just return an async function instead of the state.
// The async function is passed a context with the API of the current slice.
// [name]: (state: S, Payload | Action) => async ({ api }) => {
// ...side effects
@andyjessop
andyjessop / build-token-fields.ts
Last active July 30, 2024 21:08
A mocked service worker for Supabase auth
import { generateRandomId } from "@crux/string-utils"; // https://github.com/andyjessop/crux
export function buildTokenFields() {
return {
access_token: generateRandomId(),
token_type: "bearer",
expires_in: 604800,
refresh_token: generateRandomId(),
}
}
function stripMarkdown(md?: string, opts?: any) {
if (!md) {
return;
}
const options = opts || {};
options.listUnicodeChar = options.listUnicodeChar ? options.listUnicodeChar : false;
options.stripListLeaders = options.stripListLeaders ? options.stripListLeaders : true;
options.gfm = options.gfm ? options.gfm : true;
options.useImgAltText = options.useImgAltText ? options.useImgAltText : true;
import * as express from 'express';
import { Server } from 'http';
import { mathService } from './math-service';
import { CreateExpressApp } from './express-service';
export function createApp({ math }: { math: MathService }): CreateExpressApp<{ MathService }> {
const app = express();
let server: Server | null = null;
app.get('/api', async (req, res) => {

This is a plan of development for the simulator that will make it easier to extend incrementally, whilst keeping our core concepts of a decoupled, framework-agnostic code base.

First, the problems with the current setup for the client:

  1. Our layout is defined in HTML (well, pug), so we only have a single layout at the moment, and our elements service is tied tightly to that layout. This is fine for the simple page that we have currently, but is not flexible and makes multiple layouts or dynamic layouts difficult.
  2. We have all sorts of ideas for being able to record events, play them back, undo/redo, etc. for which a solely event-driven architecture is unsuited.

The classical solution to these, of course, is a monolithic state-driven framework like React or Vue, but those are unsuited to long-lived applications due to their vendor lock-in. cob was created to solve that and is working really well on vs-computer/vs-personalities, enabling us to write code that is not tied to a single framework

@andyjessop
andyjessop / best-move-usage.ts
Last active January 29, 2020 19:28
Engine API proposal
const { from, raw, san, to } = await engine.getBestMove(
fen,
{
engine: Engines.Komodo,
personality: Personalities.Aggressive,
strength: 5,
}
);