Skip to content

Instantly share code, notes, and snippets.

@a10y
a10y / eclipse.py
Created March 31, 2024 00:50
Marimo notebook of 2024 Solar Eclipse
import marimo
__generated_with = "0.1.76"
app = marimo.App()
@app.cell
def __():
from astropy.time import Time
from astropy.coordinates import EarthLocation, get_sun, get_moon, AltAz
#include <stdlib.h>
#include <arm_neon.h>
#include <arm_acle.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <sys/time.h>
#include <time.h>
@a10y
a10y / leaky.rs
Created March 25, 2024 15:20
Exploring memory leaks with Rust
use std::hint::black_box;
fn main() {
// Leak the reference in a loop.
println!("begin leaking memory");
for _ in 0..10 {
let data = Box::new("hello world".to_string());
let _ = black_box(Box::leak(data)); // Needed to avoid allocs being optimized away by the compiler.
}
println!("done leaking memory");
@a10y
a10y / simple_executor.rs
Created March 25, 2024 02:40
Simple current-thread async executor in Rust
#![feature(noop_waker)]
#![feature(local_waker)]
use std::collections::{HashMap, VecDeque};
use std::fmt;
use std::fmt::Formatter;
use std::future::Future;
use std::marker::PhantomData;
use std::pin::Pin;
use std::ptr::null_mut;
@a10y
a10y / pinfun.rs
Created March 24, 2024 19:41
Small exploration of Rust Pinning
use std::fmt;
use std::fmt::Formatter;
use std::marker::PhantomPinned;
use std::pin::{pin, Pin};
struct MyField {
name: String,
name_ptr: Option<*mut String>,
__pinned: PhantomPinned,
}
@a10y
a10y / mqtt_ddot.go
Created December 31, 2023 00:21
MQTT connection for DDOT CCTV Cameras
package main
import (
"bytes"
"fmt"
"github.com/eclipse/paho.mqtt.golang/packets"
)
func main() {
connectPkt := bytes.NewBuffer([]byte{
@a10y
a10y / pathMatcher.ts
Created September 29, 2023 12:10
Path matching in TypeScript to allow type-safe extraction of path params as union type
// ID for the parameter
type ParamId<T> = T;
type ParamKey<Component> = Component extends `:${infer NameWithPattern}`
? `param_${ParamId<NameWithPattern>}`
: never;
type ParamKeys<Path> = Path extends `${infer Component}/${infer Rest}`
? ParamKey<Component> | ParamKeys<Rest>
: ParamKey<Path>;
@a10y
a10y / scoop.py
Created September 16, 2023 01:35
# Pull data from SAM.gov, extract all attachments, push to S3 storage
import subprocess
import json
import os
from pathlib import Path
from multiprocessing import Pool
@a10y
a10y / nprof.sh
Created August 11, 2023 20:03
PyTorch Llama2 Profiler Results
#!/usr/bin/env bash
#nsys profile -w true -t cuda,nvtx,osrt,cudnn,cublas -s none -o nsight_prof.bin -f true -x true python3 test.py
nsys profile -w true -t cuda,nvtx,osrt,cudnn,cublas -s none \
-o nsight_prof.bin \
--capture-range=cudaProfilerApi \
--cudabacktrace=true \
-f true \
-x true \
python3 test.py
@a10y
a10y / prompt.txt
Last active August 2, 2023 23:50
Example prompt using the new grammar-guided generation functionality from llama.cpp
SYSTEM: Transcript of conversation between HUMAN and ASSISTANT. ASSISTANT can respond to USER with structured JSON messages.
USER: Extract information from an email as a JSON object matching the following TypeScript interface
```typescript
interface DeliveryInformation {
/* Tracking number for the delivery */
tracking_number: string;
/* Status of the delivery, one of "preparing", "out-for-delivery", or "delivered" */
status: string;
/* Weight of the package, e.g. "2oz" or "3lb" */
weight: string;