Skip to content

Instantly share code, notes, and snippets.

View PageotD's full-sized avatar

Damien Pageot PageotD

View GitHub Profile
@PageotD
PageotD / key_detect.py
Created August 18, 2024 07:27 — forked from jasonrdsouza/key_detect.py
Python function to get keypresses from the terminal
def getchar():
#Returns a single character from standard input
import tty, termios, sys
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
@PageotD
PageotD / diff.py
Created August 17, 2024 13:33 — forked from adamnew123456/diff.py
An implementation of the Myers diff algorithm
# This is free and unencumbered software released into the public domain.
#
# Anyone is free to copy, modify, publish, use, compile, sell, or
# distribute this software, either in source code form or as a compiled
# binary, for any purpose, commercial or non-commercial, and by any
# means.
#
# In jurisdictions that recognize copyright laws, the author or authors
# of this software dedicate any and all copyright interest in the
# software to the public domain. We make this dedication for the benefit
@PageotD
PageotD / vault.py
Last active August 14, 2024 05:57
simple file encryption/decrytion in python
import argparse
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
from cryptography.hazmat.backends import default_backend
import os
# Constants
SALT_SIZE = 16
IV_SIZE = 16
@PageotD
PageotD / bash-colors.md
Created August 3, 2024 08:40 — forked from JBlond/bash-colors.md
The entire table of ANSI color codes.

Regular Colors

Value Color
\e[0;30m Black
\e[0;31m Red
\e[0;32m Green
\e[0;33m Yellow
\e[0;34m Blue
\e[0;35m Purple
@PageotD
PageotD / Dockerfile
Created July 31, 2024 15:29
Simple SQLite Docker image
# Dockerfile for SQLite
FROM alpine:latest
# Install SQLite
RUN apk --no-cache add sqlite sqlite-dev
# Set the working directory
WORKDIR /data
# Expose the port SQLite may use
@PageotD
PageotD / 2020.08-D.Quah-Pandoc-Workflow-Markdown-PDF.md
Created January 20, 2024 17:29 — forked from DannyQuah/2020.08-D.Quah-Pandoc-Workflow-Markdown-PDF.md
My Pandoc Markdown-PDF Workflow for Routine, Not Especially Technical Writing

My Pandoc Markdown-PDF Workflow for Routine, Not Especially Technical, Writing

by Danny Quah, Aug 2020 (revised Jan 2022)

TL;DR: I write technical articles in LaTeX. But shorter, non-technical writings are easier to do in Markdown. How do I produce PDF from Markdown documents? Answer: provide YAML information in the Markdown; run Pandoc (typically through a Makefile or Atom's Markdown Preview Enhanced). To make all this work, some adjustment is needed in Pandoc options and template files.

Pandoc is a filter that takes a written document in a particular format, and produces a version of that same document in yet a different format. I use Pandoc primarily to transform Markdown documents to PDF, but I also draw on Pandoc to convert Word or ODT documents to Markdown. And vice versa.

Available official Pandoc documentation is voluminous. So as a matter of logic the knowledge to generate PDF from Markdown, to the user's desired degree of control, is already extant, out there somewhere. But a user j

@PageotD
PageotD / CBcolors.py
Created December 14, 2022 19:30 — forked from thriveth/CBcolors.py
A color blind/friendly color cycle for Matplotlib line plots. Might want to shuffle it around a bit more,but already not it gives kinda good contrasts between subsequent colors, and shows reasonably well in colorblind filters (though not in pure monochrome).
CB_color_cycle = ['#377eb8', '#ff7f00', '#4daf4a',
'#f781bf', '#a65628', '#984ea3',
'#999999', '#e41a1c', '#dede00']
@PageotD
PageotD / pomodoro.py
Last active June 22, 2022 18:53
A simple Pomodoro script in Python
import time
import chime
from rich.progress import Progress
def ptimer(phase, ptime, pcolor="white"):
"""
A generic timer for the three phases of the pomodoro
technique.
phase: (str) name of the phase
@PageotD
PageotD / gpdcwrap.py
Created May 16, 2022 18:16
Wrap for Geopsy-GPDC
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -------------------------------------------------------------------
# Filename: gpdcwrap.py
# Author: Damien Pageot
# ------------------------------------------------------------------
"""
Functions to use the Geopsy-gpdc engine.
"""
@PageotD
PageotD / neighborhood.py
Created January 19, 2022 12:06
Sambridge's Neighborhood Algorithm (Coffee Break Scripting)
import matplotlib.pyplot as plt
import numpy as np
def voronoi(nx, ny, dh, xp, yp, val, xrng, yrng):
"""
Simple Voronoi 2D interpolation.
:param n1: number of points in the first dimension of the output model
:param n2: number of points in the second dimension of the output model
:param dh: spatial sampling