Skip to content

Instantly share code, notes, and snippets.

View markmals's full-sized avatar

Mark Malstrom markmals

View GitHub Profile
@thomaswilburn
thomaswilburn / signals.js
Created June 18, 2024 17:40
Preact Signals But With EventTarget
var stack = [];
var verbose = false;
// make our own undefined sentinel value
var undefined = Symbol("undefined signal");
class Signal extends EventTarget {
#value = undefined;
#computation = null;
#lifetime = new AbortController();
@iSeiryu
iSeiryu / csharp-post-example.md
Last active July 10, 2024 17:53
Simple get and post endpoints with C# vs NodeJS vs Rust

Program.cs

using System.Text.Json.Serialization;

var app = WebApplication.CreateBuilder(args).Build();

app.MapGet("/hi", () => "hi");
app.MapPost("send-money", (SendMoneyRequest request) =>
{
    var receipt = new Receipt($"{request.From.FirstName} {request.From.LastName}",
@groue
groue / ObservableState.swift
Last active June 6, 2024 13:50
WithBindable
import SwiftUI
/// Supplies an observable object to a view’s hierarchy.
///
/// The purpose of `WithBindable` is to make it possible to instantiate
/// observable objects from environment values, while keeping the object
/// alive as long as the view is rendered.
///
/// For example:
///
@april
april / find-all-electron-versions.sh
Last active March 15, 2024 00:56
find all apps using Electron and their versions, on macOS systems
#!/usr/bin/env zsh
# patched versions for CVE-2023-4863: 22.3.24, 24.8.3, 25.8.1, 26.2.1
mdfind "kind:app" 2>/dev/null | sort -u | while read app;
do
filename="$app/Contents/Frameworks/Electron Framework.framework/Electron Framework"
if [[ -f $filename ]]; then
echo "App Name: $(basename ${app})"
electronVersion=$(strings "$filename" | grep "Chrome/" | grep -i Electron | grep -v '%s' | sort -u | cut -f 3 -d '/')
@1Marc
1Marc / reactive.js
Last active July 7, 2024 15:42
Vanilla Reactive System
// Credit Ryan Carniato https://frontendmasters.com/courses/reactivity-solidjs/
let context = [];
export function untrack(fn) {
const prevContext = context;
context = [];
const res = fn();
context = prevContext;
return res;
//! A zig builder step that runs "libtool" against a list of libraries
//! in order to create a single combined static library.
const LibtoolStep = @This();
const std = @import("std");
const Step = std.build.Step;
const RunStep = std.build.RunStep;
const FileSource = std.build.FileSource;
pub const Options = struct {
@lfoust
lfoust / PaprikaExportParsing.cs
Created April 3, 2023 16:39
Parse the recipes exported from the Paprika recipe manager
var results = new List<Recipe>();
string filePath = System.IO.Path.Combine(environment.ContentRootPath, "Recipes.zip");
if (File.Exists(filePath))
{
using (ZipArchive archive = ZipFile.OpenRead(filePath))
{
foreach (ZipArchiveEntry zipItem in archive.Entries)
{
using (var stream = zipItem.Open())
import { useSignal, signal, effect } from '@preact/signals';
import { useLayoutEffect, useMemo, useRef } from 'preact/hooks';
/** @template T @typedef {T extends (infer U)[] ? U : never} Items */
/** @param {{ v, k?, f }} props */
const Item = ({ v, k, f }) => f(v, k);
/**
* Like signal.value.map(fn), but doesn't re-render.
@saagarjha
saagarjha / MetadataExtractor.js
Created February 17, 2023 09:36
Apple's metadata extraction code for link previews in Messages, taken from macOS Ventura 13.3 Beta (22E5219e)
//
// LinkPresentation
// Copyright © 2015-2020 Apple Inc. All rights reserved.
//
// FIXME: Twitter equivalents?
(function () {
var MetadataExtractor = {