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:28 (UTC +02:00)
View GitHub Profile
#! /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 / 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 / musings.md
Last active June 15, 2017 21:25
Musings from Kenya

Introduction

As an outsider visiting Kenya, I’m constantly amazed by the informal entrepreneurship of the many people I came across. Whether it is born out of necessity or brilliance, it’s a good and positive feature which has some downsides.

Faltering infrastructure

Sadly, one of the things that really struck me was the state of infrastructure,

@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 / 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):
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 / mytest.py
Created May 6, 2020 18:54
Mypy complains
import abc
import typing
import dataclasses
from functools import singledispatchmethod
@dataclasses.dataclass
class Root:
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 / 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):
@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,