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
  • 13:22 (UTC +01:00)
View GitHub Profile
@Spindel
Spindel / gist:7896135
Created December 10, 2013 19:01
PyPy does strange things
def min_max_native(indata):
def _minmax(data):
_value = itemgetter(2)
low = min(data, key=_value)
high = max(data, key=_value)
return (_value(low), _value(high))
copy = indata[:]
minmax = _minmax(copy)
@Spindel
Spindel / flock demo
Last active April 25, 2016 09:58
Using flock for SSL key generation
#!/bin/bash
set -eu
set -o pipefail
MY_CRT=temp.crt
MY_KEY=temp.key
MY_CSR=temp.csr
CLIENTID=`sed -e 's/://g' /sys/class/net/eth0/address`
SUBJECT="/C=XX/ST=TESTING/L=Testing/O=Test Inc/OU=Test Dept/CN=$CLIENTID"
@Spindel
Spindel / IoT colo
Created February 7, 2015 11:54
The Internet of Things, A co-location in your home
# Internet of Things
## A co-location in your home.
### A real co-location
In a normal co-location (colo for short) a provider has a data hall, where they install servers of various kinds for their customers. The colo stands for power and connectivity, and some level of out-of-band monitoring to do billing or capping.
The monitoring is usually on the network level, from switches and packet flows, and not internal to your server ("what is running now") and is used to prevent customers from interfering with others, and to alert customers in case of their servers failing.
### The home co-location
@Spindel
Spindel / IoT-colo.md
Last active August 29, 2015 14:14
The Internet of Things, A co-location in your home

Internet of Things

A co-location in your home.

A real co-location

In a normal co-location (colo for short) a provider has a data hall, where they install servers of various kinds for their customers. The colo stands for power and connectivity, and some level of out-of-band monitoring to do billing or capping.

The monitoring is usually on the network level, from switches and packet flows, and not internal to your server ("what is running now") and is used to prevent customers from interfering with others, and to alert customers in case of their servers failing.

The home co-location

@Spindel
Spindel / encodings.py
Last active August 29, 2015 14:23
Python3 locale inconsistencies
#!/bin/env python
# vim: ts=4 sts=4 sw=4 ft=python expandtab fileencoding=utf8 :
""" Python2 and Python3 differ on how they handle input and output
files depending on the current locale.
Python2: behaves consistently(but badly), reading and writing utf8
as if it was ascii. Successfully giving back the same byte sequence
as was put in. (Aka. The same string)
@Spindel
Spindel / postall-curl.py
Last active August 29, 2015 14:25
Post all Certificate Requests
#!/bin/env python3
# vim: expandtab shiftwidth=4 softtabstop=4 tabstop=17 filetype=python :
"""
Upload a set of .csr files to a caramel endpoint. Used for some minor
benchmarking and to populate things
The PyCurl version
"""
import threading
import hashlib
@Spindel
Spindel / autosign.py
Created July 24, 2015 18:30
Temp copy-paste of the caramel autosign
import threading
import argparse
import datetime
import logging
import time
import uuid
import queue
import sys
import gc
@Spindel
Spindel / .SQL
Last active August 29, 2015 14:25
SQl playing
SELECT (c).csr_id, (c).not_before, (c).not_after FROM (SELECT (SELECT c FROM certificate c WHERE c.csr_id=csr.id ORDER BY c.not_after DESC LIMIT 1) AS c FROM csr offset 0) s;
@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 / watchdog.md
Last active May 24, 2023 09:48
Showing off the systemd watchdog in Python

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.