Skip to content

Instantly share code, notes, and snippets.

View Spindel's full-sized avatar
👷‍♂️
For hire

Spindel Ljungmark Spindel

👷‍♂️
For hire
  • https://www.modio.se/ @ModioAB
  • Sweden
  • 00:10 (UTC +02:00)
View GitHub Profile
@Spindel
Spindel / gist:2f3dbd8323af331064bb3360bbb0211a
Created July 29, 2024 19:01
Bloody traits and traitorous traits....
trait MustHave {}
trait First: MustHave {}
trait Second: MustHave {}
trait Final: MustHave {}
impl Final for dyn First {}
impl Final for dyn Second {}
Client rpc stats:
calls retrans authrefrsh
46187 0 46191
Client nfs v4:
null read write commit open
4 0% 9455 20% 0 0% 0 0% 6644 14%
open_conf open_noat open_dgrd close setattr
0 0% 855 1% 0 0% 855 1% 0 0%
fsinfo renew setclntid confirm lock
@Spindel
Spindel / mytest.py
Created May 6, 2020 18:54
Mypy complains
import abc
import typing
import dataclasses
from functools import singledispatchmethod
@dataclasses.dataclass
class Root:
find . -type f -print0 |xargs -0 filefrag  |awk -F: '{ gsub("extents", "extent", $2); gsub("extent found", "", $2); print( $2,  $1)}' |sort -n

start by calculating ssdeep on files to find similar hashing files
use this to find "close" matches.
apply python:
all close matches get compared against each-other, pairwise

import os
with open(f1, "r+b") as fb1, open(f2, "r+b") as fb2:

m1 = mmap.mmap(fb1.fileno, 0)

@Spindel
Spindel / mapping.py
Last active March 31, 2019 15:11
Delay Maps
#!/usr/bin/env python3
import asyncio
import random
import uuid
import time
class MaxMap:
def __init__(self):
@Spindel
Spindel / humbug.rs
Created November 13, 2017 17:29
i2c and rust
use std::io::Write;
use std::os::unix::io::AsRawFd;
use std::fs::OpenOptions;
extern crate libc;
fn main() {
const I2C_SLAVE: u64 = 0x0703;
const DEVICE: u32 = 0x2a;
const I2C_DATA: [u8;2] = [0x2a, 0x2a];
let mut file = OpenOptions::new().read(false).write(true).create(false).open("/dev/i2c-1").expect("File not found?");
@Spindel
Spindel / README.md
Created April 16, 2017 16:18
containerised caramel

Caramel setup instructions

This setup assumes dockerized containers, we're using this on CoreOS, but you can use whatever that's using docker.

This setup is more complex than the simplest possible, but it's production ready.

  1. set up a new host, point a DNS name at it
  2. Sets up a http proxy to get a LetsEncrypt cert up
  3. Sets up LetsEncrypt for public infra (https to the CA server)
  4. Sets up caramel server
@Spindel
Spindel / model.py
Last active March 22, 2023 01:19
Interview question model.
import uuid
import random
from afase.models.meta import Base
from sqlalchemy import (
Column,
Text,
Date,
ForeignKey,
#! /bin/bash -e
# Note "-e" above, as that's what prevents removing old dump
# when new dump fails.
TSPEC=$(date "+%F_%T")
filename="/backup/modio-$TSPEC"
workname="/backup/running"
backup="/backup/old-in-progress"
@Spindel
Spindel / directio_mmap.py
Created December 9, 2016 17:44
Direct IO in Python
#!/bin/env python3
import os
import mmap
import logging
import hashlib
import contextlib
log = logging.getLogger(__name__)
@contextlib.contextmanager
def directio_mmap(filename, readsize, offset):