Skip to content

Instantly share code, notes, and snippets.

View danielsdesk's full-sized avatar

danielsdesk danielsdesk

View GitHub Profile
@ScriptedAlchemy
ScriptedAlchemy / intput.js
Created June 4, 2025 06:39
Tree shake macro results
// Utility functions that would only be used by newFeature
function formatMessage(message) {
return `[NEW] ${message}`;
}
function validateFeature() {
return true;
}
function logFeatureUsage(featureName) {

State of Async WASI in Rust

Let me share what I've learned about implementing async WASIp2 components in Rust. My goal is to get the entire Tokio ecosystem working together seamlessly. This isn't a complete test of the ecosystem - some things might be simpler than we expect. Check out dicej's wasi-socket-tests repository for examples.

The first obstacle: you'll need a nightly version of Rust. Without it, you'll need major ecosystem changes to avoid the wasip2 module in the Rust standard library and use wasi crates for the necessary functionality.

Let's walk through the steps to get Reqwest working with Tokio.

Socket2

import { assign, setup } from "xstate";
type Context = {
chunks: Blob[];
mediaRecorder?: MediaRecorder;
submit: (contents: { file: File }) => void;
};
type Events =
| {
@vatsalsaglani
vatsalsaglani / mistral_ctx.py
Last active June 3, 2025 20:06
Token counting and message token management for MistralAI
from typing import List, Dict, Literal, Union
from transformers import AutoTokenizer
class MistralAICtx:
def __init__(self, model_name: str):
assert "mistral" in model_name, "MistralCtx only available for Mistral models"
self.tokenizer = AutoTokenizer.from_pretrained(
"mistralai/Mistral-7B-Instruct-v0.2")
@steveruizok
steveruizok / visibility-polygon.ts
Created November 21, 2022 23:49
Get a visibility polygon (for shadow casting).
// segments are all of the segments in all of the shapes in the scene
// point is light point
// viewport is top left, top right, bottom right, bottom left
function getVisibilityPolygon(segments: Segment[], point: Point, viewport: Point[]) {
const brokenSegments: Segment[] = []
const viewportMinCorner = viewport[0]
const viewportMaxCorner = viewport[2]
@muzzol
muzzol / SD_x11vnc-install.sh
Last active December 5, 2023 09:52
script for installing x11vnc on Steam Deck
#!/bin/bash
# script for installing x11vnc on Steam Deck
# ATENTION: USE IT AT YOUR OWN RISK!!!!
#
# this will modify root filesystem so it will probably get
# overwrite on system updates but is totally ok executing
# it several times, so if something stops working just
# launch it again
#
@steveruizok
steveruizok / Player.js
Last active March 14, 2022 23:50
TypeScript declarations for Warrior.js. (mostly complete)
class Player {
/**
* @param {Warrior} warrior
*/
playTurn(warrior) {
warrior.walk()
}
}
@steveruizok
steveruizok / multiclick.test.ts
Created January 27, 2022 15:12
Tests for multi-clicks.
import { DOUBLE_CLICK } from '~constants'
import { TLTestApp } from './TLTestApp'
jest.useFakeTimers()
describe('When detecting double/triple/quadruple clicks...', () => {
it('Detects a click', () => {
const app = new TLTestApp()
app.onClick = jest.fn()
app.onDoubleClick = jest.fn()
@steveruizok
steveruizok / useCursor.ts
Last active July 15, 2025 04:33
Generate a rotated cursor based on a cursor and rotation.
import { GeomUtils, TLCursor } from '@tldraw/core'
import * as React from 'react'
function getCursorCss(svg: string, r: number, f = false) {
return (
`url("data:image/svg+xml,<svg height='32' width='32' viewBox='0 0 35 35' xmlns='http://www.w3.org/2000/svg'><g fill='none' style='transform-origin:center center' transform='rotate(${r})${
f ? ` scale(-1,-1) translate(0, -32)` : ''
}'>` +
svg.replaceAll(`"`, `'`) +
'</g></svg>") 16 16, pointer'
@steveruizok
steveruizok / sponsors.ts
Created November 19, 2021 13:38
A Next.js API route that will generate an image of your most recent 100 Github sponsors.
// pages/api/sponsors.ts
import { NextApiRequest, NextApiResponse } from 'next'
const AV_SIZE = 32
const PADDING = 4
const COLS = 16
type SponsorResult = { avatarUrl: string; login: string }