Skip to content

Instantly share code, notes, and snippets.

@bgreni
bgreni / fast.mojo
Last active April 16, 2025 21:48
Mojo issue #4354 repro
from math import gcd
@value
@register_passable("trivial")
struct Ratio[N: UInt, D: UInt = 1](Stringable, Writable):
alias Nano = Ratio[1, 10**9]()
alias Micro = Ratio[1, 10**6]()
alias Milli = Ratio[1, 10**3]()
alias Centi = Ratio[1, 100]()
@mzaks
mzaks / crazy_string.mojo
Last active April 20, 2025 14:17
Mojo String with small string optimisation and unicode support (based on UTF-8)
from algorithm.functional import vectorize
from bit import bit_width, byte_swap, count_leading_zeros
from collections._index_normalization import normalize_index
from memory import memcpy, memset_zero
from sys import is_big_endian, sizeof
from utils import StringSlice, Span
from utils.string_slice import _utf8_byte_type, _StringSliceIter
struct CrazyString[
@thesamesam
thesamesam / xz-backdoor.md
Last active March 9, 2026 22:51
xz-utils backdoor situation (CVE-2024-3094)

FAQ on the xz-utils backdoor (CVE-2024-3094)

This is a living document. Everything in this document is made in good faith of being accurate, but like I just said; we don't yet know everything about what's going on.

Update: I've disabled comments as of 2025-01-26 to avoid everyone having notifications for something a year on if someone wants to suggest a correction. Folks are free to email to suggest corrections still, of course.

Background

@Trebor-Huang
Trebor-Huang / SSet.py
Created January 7, 2024 16:47
Effective simplicial set (draft)
from abc import ABC, abstractmethod
from dataclasses import dataclass
from functools import cached_property
@dataclass(frozen=True)
class SimplexMap:
"""A sSet map symbol, mathematically defined as a
monotone map of ordered finite sets. Represented as a
tuple of natural numbers, where `l[i]` represents the
number of elements mapped to `i`."""
@guidorice
guidorice / test.yaml
Created November 19, 2023 22:44
github action for mojo + conda
name: Run Tests
on:
pull_request:
types: [opened, reopened]
push:
branches:
- 'main'
@yt7589
yt7589 / mul_ndbuffer.ipynb
Last active May 28, 2023 08:09
Multiplication of mojo NDBuffer
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
from __future__ import annotations
from contextlib import contextmanager
from typing import NamedTuple, Callable, Optional, Any
import numpy as np
Array = Any
class Node(NamedTuple):
vjp: Optional[Callable]
parents: List[Node]
@sts10
sts10 / rust-command-line-utilities.markdown
Last active March 14, 2026 17:33
A curated list of command-line utilities written in Rust

A curated list of command-line utilities written in Rust

Note: I have moved this list to a proper repository. I'll leave this gist up, but it won't be updated. To submit an idea, open a PR on the repo.

Note that I have not tried all of these personally, and cannot and do not vouch for all of the tools listed here. In most cases, the descriptions here are copied directly from their code repos. Some may have been abandoned. Investigate before installing/using.

The ones I use regularly include: bat, dust, fd, fend, hyperfine, miniserve, ripgrep, just, cargo-audit and cargo-wipe.

  • atuin: "Magical shell history"
  • bandwhich: Terminal bandwidth utilization tool
import torch
import torch.utils.dlpack
import jax
import jax.dlpack
# A generic mechanism for turning a JAX function into a PyTorch function.
def j2t(x_jax):
x_torch = torch.utils.dlpack.from_dlpack(jax.dlpack.to_dlpack(x_jax))
return x_torch
@dutc
dutc / 1.py
Created March 3, 2021 02:50
`pandas` problem of the day: analysis (with `numpy.meshgrid`‽)
from pandas import Series
s = Series({
4: 89.00,
6: 109.99,
8: 149.14,
10: 218.99,
12: 239.09,
14: 279.99,
16: 329.99,
18: 409.99,