Skip to content

Instantly share code, notes, and snippets.

View metruzanca's full-sized avatar

Sam Zanca metruzanca

View GitHub Profile
type Modifiers = {
ctrl?: boolean;
shift?: boolean;
};
type HotkeyDetails = { key: string } & Modifiers;
const hotkeyName = ({ key, ctrl, shift }: HotkeyDetails) =>
`hotkey:${ctrl || ""}+${shift || ""}+${key}`;
@metruzanca
metruzanca / Gleam Lustre alternative syntax.md
Last active September 7, 2024 23:06
Can't help but wonder if Lustre could have less noise. Without adding a preprocessor, maybe we can use a pipeline instead?

Current

  html.div([], [
    html.button([event.on_click(Increment)], [
      element.text("+")
    ]),
    element.text(count),
    html.button([event.on_click(Decrement)], [
      element.text("-")
 ]),
@metruzanca
metruzanca / truncateMiddle.test.ts
Last active July 30, 2024 19:06
Didn't end up using this in the end, didn't wanna delete it outright.
import { truncateMiddle } from '.';
describe('utils', () => {
// ...pretty exaustive for a string utility, I know...
describe('truncateMiddle', () => {
const testStrings = [
'0x3172635bc846d0c68afce1738d048520dcfafed2d55d1866a5ed5a40d5ea66c7', // 66 chars
'0000000000000000000000000000000000000000000000', // 46 chars
'00000000000000000000000000000000000000000000000', // 47 chars
];
@metruzanca
metruzanca / solid.userscript.js
Last active January 25, 2024 13:27
The poor man's SolidJS implemented in 40 lines
const $ = document.querySelector.bind(document),
$$ = document.querySelectorAll.bind(document),
h = (name, props) => Object.assign(document.createElement(name), props);
const context = []
const getCurrentObserver = () => context[context.length - 1]
function createEffect(fn, name) {
const execute = () => {
context.push(execute)
@metruzanca
metruzanca / signal.ts
Created December 14, 2023 21:56
Basic signal implementation from a Ryan Carnianto Talk
const context: Function[] = []
function getCurrentObserver() {
return context[context.length - 1]
}
function createEffect(fn: Function, name: string) {
const execute = () => {
context.push(execute)
try {
@metruzanca
metruzanca / firebase-query-builder.ts
Created September 12, 2023 22:39
An experimental util for making firebase queries following the Builder Pattern. I've since moved to using something cooler though :D
export class QueryBuilder {
private collection: CollectionReference<DocumentData, DocumentData>
constructor(path: string) {
this.collection = collection(firestore, path)
}
private where: QueryFieldFilterConstraint[] = []
filter(fieldPath: string | FieldPath, opStr: WhereFilterOp, value: unknown) {
this.where.push(where(fieldPath, opStr, value))
return this

Ship building

Each shipyard where you can build ships from has a different stock of parts.

Manufacturer Locations
Stroud Neon
Taiyo Neon
// Inspired by https://github.com/codediodeio/sveltefire & previous stuff I did here https://gist.github.com/metruzanca/e516aac42c79d16c894883e88d8af5f8
import { CollectionReference, DocumentData, Firestore, Query, QueryDocumentSnapshot, QuerySnapshot, collection, onSnapshot } from "firebase/firestore";
import { Accessor, from } from "solid-js";
type CollectionSignal<T> = {
signal: Accessor<T[]>
ref: CollectionReference<T> | Query<T> | null
}
@metruzanca
metruzanca / jira-points.user.js
Last active August 25, 2023 17:22
jira user script
// ==UserScript==
// @name Jira Column Points
// @namespace metruzanca
// @version 0.1.0
// @description Adds utilities to jira boards
// @author metruzanca
// @match https://*.atlassian.net/jira/software/c/projects/*/boards/*
// ==/UserScript==
function addStyle(cssString, container = document.head) {
@metruzanca
metruzanca / result.ts
Created July 24, 2023 11:44
Rust & Golang inspired error handing in Node
export type Success<Data> = readonly [Data, undefined];
export type Failure<Err = Error> = readonly [undefined, Err];
/** A cross between Rust and Golang exception handling. I greatly dislike exceptions */
export type Result<Data, Err = Error> = Promise<(Success<Data> | Failure<Err>)>
export const Ok = <T>(data: T): Success<T> => [data, undefined]
export const Err = <E = Error>(error: E): Failure<E> => [undefined, error]