Skip to content

Instantly share code, notes, and snippets.

@ToJans
ToJans / overrule-material.json
Last active January 26, 2024 16:09
testing if my json-patch-url works
[
{
"op": "add",
"path": "/builders/textures/-",
"value": {
"id": "lshape",
"name":"lshape",
"imageUrl": "https://picsum.photos/512",
"repeat":{"x":1,"y":1},
"rotation": 3.14159
@ToJans
ToJans / InventoryItems.hs
Last active January 19, 2024 10:47
Haskell implementation of Greg Young's CQRS sample: https://github.com/gregoryyoung/m-r Love the sheer elegance of Haskell; no need for all that infrastructure crap
module InventoryItems(Command(..), Event(..), handle) where
import Data.Maybe(isJust)
type Id = String
type Name = String
type Amount = Int
data Command = CreateInventoryItem Id
| RenameInventoryItem Id Name
@ToJans
ToJans / directus_extensions_endpoints_filestorage_index.js
Last active July 13, 2023 14:06
Quick hack: Redirect to asset by URL - Endpoint extension for directus.io
// Quick hack: Redirect to asset by URL - Endpoint extension for directus.io
// =========================================================================
//
// 2021 - ToJans - Public Domain
//
// *** Don't hold me liable if it breaks anything! Quick hack, might expose all your data!
//
// You can use this endpoint extension to access assets via the folder and file structure
// you used in the file module, so you don't need to reference assets by guid anymore.
//
@ToJans
ToJans / ganja.js
Last active March 20, 2022 12:25
Ganja.js extrude cheat sheet
window.d = 2;
Algebra(d,0,1,()=>{
var point = (x,y)=>!(1e0 + x*1e1 + y*1e2),
// return functions instead of values, so they update when you drag the points
linesFromPoints = ps => ps.map((p,i,a) => ()=>p & (a[(i+1)%a.length]||a[0])),
pointsFromLines = e => e.map((ev,i,a) => ()=> ev * (a[(i+1)%a.length]||a[0])),
@ToJans
ToJans / CVector.js
Created February 17, 2022 21:08
Here's a super compact vector class that supports multiple dimensions
class CVector {
constructor(components = []) { this.components = components; }
get lengthSquared() { return this.components.reduce((p, c) => p + c * c); }
get length() { return Math.sqrt(this.lengthSquared); }
get normalized() { return new CVector(this.components.map(x => x / this.length)); }
get sum() { return Math.sum(this.components); }
add(other, missingComponentValue = 0) { return this._zip(other, (a, b) => a + b, missingComponentValue); }
sub(other, missingComponentValue = 0) { return this._zip(other, (a, b) => a - b, missingComponentValue); }
mul(other, missingComponentValue = 1) { return this._zip(other, (a, b) => a * b, missingComponentValue); }
div(other, missingComponentValue = 1) { return this._zip(other, (a, b) => a / b, missingComponentValue); }
@ToJans
ToJans / javascript-ast.ts
Last active February 17, 2022 16:24
Minimalistic example to parse javascript.
const TokenExpressions = {
comment: /^((\/\/[^\n]+)|(\/\*[^(\*\/)]+)\*\/)/,
strings: /^("(\\"|[^"])*")/,
multiline_strings: /^(`[^\`]+`)/,
whitespace: /^([\s\n\r]+)/,
brace: /^[\(\)]/,
curlyBrace: /^[\{\}]/,
array: /^[\[\]]/,
comma: /^\,/,
operator: /^(\+|-|\*|\/|=|>|<|>=|<=|&|\||%|!|\^|)/,
@ToJans
ToJans / whut.txt
Created May 6, 2021 08:52
Muahaha
Hello world!
using System;
using System.Collections.Generic;
using System.Linq;
/**
Chess: potential moves etc by @ToJans
Spiked in a couple of hours of late-night code for a tweet by @gregyoung
https://twitter.com/gregyoung/status/1385285718113722374
@ToJans
ToJans / fpexplained.cs
Last active July 25, 2020 04:02
This is a C# implementation showing what functors, applicatives and monads look like.
using System;
namespace FPExplained
{
// This is a C# implementation showing what functors, applicatives and monads look like.
//
// ----><8-----------------------------------
// UPDATE:
// ***********************************
// For a maybe monad, all these constructs look a bit redundant; their reason of existance is more obvious
@ToJans
ToJans / AggregateRootStore.cs
Created September 1, 2010 10:16
combining CQRS, Event sourcing and BDD
using System;
using System.Collections.Generic;
using System.Linq;
namespace SimpleCQRS2.Framework.Services
{
public class AggregateRootStore : IAggregateRootStore
{
public IAggregateRoot GetAggregateRoot(Type aggregateRootType, Guid aggregateRootId)
{