Skip to content

Instantly share code, notes, and snippets.

View lkraider's full-sized avatar

Paul Eipper lkraider

View GitHub Profile
@lkraider
lkraider / photo-timestamps.py
Last active May 4, 2024 19:57
Synchronize the modified timestamps of files between a backup folder and a destination folder.
import os
from datetime import datetime
def sync_timestamps(backup_folder, destination_folder, dry_run=False):
# Loop through the files in the destination folder
for file_name in os.listdir(destination_folder):
destination_file_path = os.path.join(destination_folder, file_name)
destination_modified_time = os.path.getmtime(destination_file_path)
# Check if there is a corresponding file in the backup folder with the same name
@lkraider
lkraider / KafkaRoller.tla
Last active April 26, 2024 18:34
Kafka Roller 2.0 - TLA+ example spec
---------------------------- MODULE KafkaRoller ----------------------------
EXTENDS Integers, Sequences, FiniteSets
CONSTANTS
ControllerNodes, \* Set of nodes with the controller role
BrokerNodes, \* Set of nodes with the broker role
CombinedNodes, \* Set of nodes with both controller and broker roles
MaxRestartAttempts, \* Maximum number of restart attempts allowed per node
MaxRetries \* Maximum number of retries allowed per node
@lkraider
lkraider / spam_decode.py
Created June 14, 2020 21:25
X-OVH-SPAMCAUSE decoder
def decode(msg):
text = []
for i in range(0, len(msg), 2):
text.append(unrot(msg[i: i + 2]))
return str.join('', text)
def unrot(pair, key=ord('x')):
offset = 0
for c in 'cdefgh':
@lkraider
lkraider / generator.py
Created April 4, 2016 17:17
Terraform AWS policy generator
#!/usr/bin/env python
"""Convert CSV policies into AWS JSON format."""
import json
import csv
POLICIES = 'terraform.csv'
CRUD_COL = 2
ACTION_COL = 3
@lkraider
lkraider / gs-resample.sh
Created March 7, 2017 20:06
Ghostscript PDF quality downsample
#!/bin/sh
# It seems it's very hard to set resample output quality with Ghostscript.
# So instead rely on `prepress` preset parameter to select a good /QFactor
# and override the options we don't want from there.
gs \
-o resampled.pdf \
-sDEVICE=pdfwrite \
-dPDFSETTINGS=/prepress \
@lkraider
lkraider / async-socket.py
Created August 14, 2014 23:13
Example of using gevent for async socket server and client
import gevent
import gevent.server
import gevent.monkey
gevent.monkey.patch_all()
import socket
import string
import random
import filecmp
@lkraider
lkraider / avcodec_sample.c
Created February 17, 2011 16:37
ffmpeg thumbnailer - extract frame, scale and save it to disk
// avcodec_sample.0.5.0.c
// Original source:
// http://web.me.com/dhoerl/Home/Tech_Blog/Entries/2009/1/22_Revised_avcodec_sample.c.html
//
// A small sample program that shows how to use libavformat and libavcodec to
// read video from a file.
//
// This version is for the 0.4.9+ release of ffmpeg. This release adds the
// av_read_frame() API call, which simplifies the reading of video frames
@lkraider
lkraider / pbm_to_png.py
Created November 2, 2017 22:50
PPM to PBM to PNG
from PIL import Image
from io import BytesIO
import itertools
def as_pbm(w, h, data): # -> bytes
ret = bytes()
ret += b'P4\n'
ret += (str(w) + ' ' + str(h) + '\n').encode('ascii')
@lkraider
lkraider / dockerrun-jsen-schema.json
Last active August 17, 2021 16:54 — forked from sordina/dockerrun-jsen-schema.json
jsen schema to validate Dockerrun.aws.json files
{
"type": "object",
"required": [
"AWSEBDockerrunVersion",
"containerDefinitions",
"volumes"
],
"properties": {
"AWSEBDockerrunVersion": {
"type": "integer",
@lkraider
lkraider / iam-terraform-create-policy.tf
Created July 7, 2017 22:31 — forked from arsdehnel/iam-terraform-create-policy.tf
AWS IAM policies for running Terraform from an EC2 instance.
resource "aws_iam_policy" "terraform_create_policy" {
name = "terraform_create_policy"
path = "/"
policy = "${data.aws_iam_policy_document.terraform_create_policy.json}"
}
data "aws_iam_policy_document" "terraform_create_policy" {
statement {
sid = "1"
actions = [