Skip to content

Instantly share code, notes, and snippets.

D. Spindel Spindel

Block or report user

Report or block Spindel

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View idea-defrag.md
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 Mar 31, 2019
Delay Maps
View mapping.py
#!/usr/bin/env python3
import asyncio
import random
import uuid
import time
class MaxMap:
def __init__(self):
View humbug.rs
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 Apr 16, 2017
containerised caramel
View README.md

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 Feb 22, 2019
Interview question model.
View model.py
import uuid
import random
from afase.models.meta import Base
from sqlalchemy import (
Column,
Text,
Date,
ForeignKey,
View pgbackup.bash
#! /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 Dec 9, 2016
Direct IO in Python
View directio_mmap.py
#!/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):
View mainloop.py
def listen_forever(handlers):
session = DBSession()
engine = session.get_bind()
conn = engine.connect()
del engine
conn.detach()
session.close()
from sqlalchemy import text
for channel in handlers.keys():
@Spindel
Spindel / restorellnndump.py
Created Oct 28, 2015
rewrite of a script I came across
View restorellnndump.py
#!/usr/bin/python
from __future__ import print_function
import shelve
def grabfile(filename):
result = []
with open(filename, "rb") as f:
for line in f:
@Spindel
Spindel / watchdog.md
Last active Aug 29, 2019
Showing off the systemd watchdog in Python
View watchdog.md

Watchdogged

Place the service file (or a link to it) in /etc/systemd/system/ Place the watchdogged.py file somewhere ( and change the ExecStart portion in the .service to point at the file )

then do systemctl daemon-reload followed by systemctl start watchdogged.service

After this you can watch the progress using journalctl --follow -u watchdogged.service change the PROBABILITY variable to something else to watch it faster/later or succeed.

You can’t perform that action at this time.