Skip to content

Instantly share code, notes, and snippets.

import argparse
from collections import Counter
import os
from struct import unpack
from dataclasses import dataclass
@dataclass
class Mp3Frame:
data: bytes
bitrate: int
#[cfg(all(target_arch = "x86_64", target_feature = "avx2"))]
unsafe fn hammcmp_256bit_avx2(mut a: &[u8], mut b: &[u8]) -> u32 {
use std::arch::x86_64::{*};
let mut dist = 0;
while a.len() >= 32 {
let av = _mm256_loadu_si256(a.as_ptr() as *const _);
let bv = _mm256_loadu_si256(b.as_ptr() as *const _);
let axorb = _mm256_xor_si256(av, bv);
dist += _popcnt64(_mm256_extract_epi64(axorb, 0));
dist += _popcnt64(_mm256_extract_epi64(axorb, 1));
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
$ (for C in 1.0 2.0 2.5 3.0 3.5 4.0; do echo "/cfg $C"; echo "/reset"; echo "How do I become famous?"; done) | ./target/release/chat --mirostat --cfg-scale 2.0 --system-prompt "act as an expert chef"
Using ChatML prompting format.
mpt_model_load: loading model from 'minmpt.cpp/models/ggml-mpt-7b-chat-q5_1.bin' - please wait ...
mpt_model_load: ggml ctx size = 5397.09 MB
mpt_model_load: ........................ done
mpt_model_load: model size = 5397.02 MB / num tensors = 194
mpt_kvcache: memory_size = 1024.00 MB, n_mem = 65536
CFG Mode on!
mpt_kvcache: memory_size = 1024.00 MB, n_mem = 65536
cfg_scale=1
@apage43
apage43 / btree.ipynb
Last active September 25, 2024 17:39
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
// make mcs; ./mcs file
// writes <sample size> as uint32 to mincore.bin followed by 1 mincore() per second for 60 seconds
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <stdint.h>
#include <sys/mman.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
size_t memtotal() {
char buf[200];
size_t ret;
FILE* meminfo = fopen("/proc/meminfo", "r");
if (!meminfo) {
// how to create a process pipeline in C, or:
// how does the shell execute something like this:
//// $ awk '{print $3}' < /proc/mounts | sort | uniq -c
#define _GNU_SOURCE // needed for pipe2
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <stdio.h>
In [1]: from pathlib import Path
In [2]: from codecs import encode
In [3]: words = set(Path('/usr/share/dict/words').read_text().splitlines())
In [4]: rot13 = set(encode(w, 'rot13') for w in words)
In [5]: [(w, encode(w, 'rot13')) for w in (words & rot13) if len(w) >= 3]
Out[5]: