Skip to content

Instantly share code, notes, and snippets.

View markmals's full-sized avatar

Mark Malstrom markmals

View GitHub Profile
@wesbos
wesbos / Bluesky.tsx
Created November 5, 2024 17:05
Bluesky RSC
export async function BlueSkyPost() {
const url = new URL('https://bsky.app/profile/danabra.mov/post/3la62zxt4rs2j');
const details = url.pathname.split('/').filter(Boolean).reduce((acc, part, index, pathParts) => {
if (index % 2 === 0 && pathParts[index + 1]) {
acc[part] = pathParts[index + 1];
}
return acc;
}, {} as Record<'post' | 'profile' | string, string>);
const endpoint = new URL('https://public.api.bsky.app/xrpc/app.bsky.feed.getPostThread');
const params = new URLSearchParams();
@mozzius
mozzius / happy-path.ts
Created October 18, 2024 20:48
Bluesky video upload - direct upload
import {
AppBskyEmbedVideo,
AppBskyVideoDefs,
AtpAgent,
BlobRef,
} from "npm:@atproto/api";
const userAgent = new AtpAgent({
service: prompt("Service URL (default: https://bsky.social):") ||
"https://bsky.social",
@gavinmn
gavinmn / KeyboardAttachedView.swift
Created August 20, 2024 02:38
Attach a view to the keyboard with interactive dismissal support
//
// ContentView.Swift
// KeyboardAttachedView
//
// Created by Gavin Nelson on 8/19/24.
//
import SwiftUI
import UIKit
@HarshilShah
HarshilShah / Task.swift
Created August 12, 2024 05:04
A SwiftUI Task modifier that gives you the current and previous ID values in the body
public extension View {
func task<T: Equatable>(
id: T,
priority: TaskPriority = .userInitiated,
@_inheritActorContext _ action: @Sendable @escaping (T, T) async -> Void
) -> some View {
self.modifier(TaskViewModifier(id: id, priority: priority, action: action))
}
}
@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 December 14, 2024 22:38
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}",
@mary-ext
mary-ext / solid-signals.ts
Last active August 8, 2024 08:10
Solid.js-like signals on top of the TC39 Signals proposal
import { Signal as WebSignal } from 'signal-polyfill';
export type Accessor<T> = () => T;
export type Setter<in out T> = {
<U extends T>(...args: undefined extends T ? [] : [value: (prev: T) => U]): undefined extends T
? undefined
: U;
<U extends T>(value: (prev: T) => U): U;
<U extends T>(value: Exclude<U, Function>): U;
<U extends T>(value: Exclude<U, Function> | ((prev: T) => U)): U;
@groue
groue / ObservableState.swift
Last active December 2, 2024 13:29
WithBindable
// Copyright (C) 2024 Gwendal Roué
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
@mayank99
mayank99 / importCss.js
Created December 12, 2023 04:29
import attributes polyfill
async function importCss(url) {
try {
return await (new Function(`return import("${url}", { with: { type: "css" } })`))();
} catch {
try {
return await (new Function(`return import("${url}", { assert: { type: "css" } })`))();
} catch {
return fetch(url).then(res => res.text()).then(cssText => {
const stylesheet = new CSSStyleSheet();