Skip to content

Instantly share code, notes, and snippets.

View jdmichaud's full-sized avatar

jdmichaud

View GitHub Profile
@jdmichaud
jdmichaud / wget.sh
Created May 2, 2024 11:49
Mirror a site with wget
wget \
--mirror \
--convert-links \
--adjust-extension \
--page-requisites \
--no-parent --execute robots=off \
--user-agent="Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:125.0) Gecko/20100101 Firefox/125.0" \
<url>
@jdmichaud
jdmichaud / display-pixel.cc
Created April 17, 2024 13:38
Easiest way to display pixels on a screen on Linux
//g++ main.cc -O3 -o test -lX11 && ./test
#include <chrono>
#include <iostream>
#include <string>
#include "CImg.h"
using namespace cimg_library;
int main(int argc,char **argv) {
const unsigned char white[] = { 255, 255, 255 };
@jdmichaud
jdmichaud / generate-toc
Last active April 11, 2024 16:21
Markdown shell script utilities
#!/usr/bin/env bash
# reference: https://medium.com/@acrodriguez/one-liner-to-generate-a-markdown-toc-f5292112fd14
function printusage {
echo "Usage: $0 <minimum-level> <maximum-level> <markdown-file.md>"
echo ""
echo "Example:"
echo " $0 2 5 README.md"
}
@jdmichaud
jdmichaud / add-subtitles-to-a-video.md
Created March 28, 2024 18:39
Add subtitles to a video
cd /tmp && \
  mkdir auto-subtitle && cd auto-subtitle && \
  python3 -mvenv venv && \
  source venv/bin/activate && \
  pip install git+https://github.com/m1guelpf/auto-subtitle.git && \
  pip install ffmpeg-python && \
  python3 auto_subtitle /path/to/video.mp4 -o subtitled/
# python3 -mvenv venv && source venv/bin/activate && pip install flask requests && python3 server.py
# open http://localhost:8080
import flask
import requests
app = flask.Flask(__name__)
# To create a client ID/secret for Google oauth:
# 1. Go to the Google Cloud Console,
# 2. Create a project
@jdmichaud
jdmichaud / totp.rs
Created February 26, 2024 15:27
TOTP client in Rust
// https://rednafi.com/go/totp_client/
// https://datatracker.ietf.org/doc/html/rfc6238
use sha1::{Sha1};
use hmac::{Hmac, Mac};
use std::time::{SystemTime, UNIX_EPOCH};
fn generate_totp(secret_key: &str, timestamp: u64) -> u32 {
// The base32 encoded secret key string is decoded to a byte slice
@jdmichaud
jdmichaud / list.h
Created February 18, 2024 15:32
proxy in C based on IOUring
/* From https://git.kernel.dk/cgit/liburing/tree/examples/list.h */
#ifndef LIBURING_EX_LIST_H
#define LIBURING_EX_LIST_H
struct list_head {
struct list_head *prev, *next;
};
#ifndef offsetof
#define offsetof(TYPE, FIELD) ((size_t) &((TYPE *)0)->FIELD)
@jdmichaud
jdmichaud / export_c_lib_with_zig.md
Last active September 18, 2023 14:47
Export C lib with zig

Compile your zig library with:

zig build-lib -fPIE -fcompiler-rt -femit-h mylib.zig
  • -fcompiler-rt: Needs to include a couple of implementation (especially true for debug)
  • -femit-h: generate a c header
  • -fPIE: gcc complains without it Compile your c program with"
cc -I/path/to/zig/lib/ -L. main.c -o test -lmylib
@jdmichaud
jdmichaud / firejail_howto.md
Last active September 16, 2023 14:50
Firejail

Launch a program with /some/path as you home folder:

firejail --private=/some/path/ your_program your program arguments

wine

firejail --profile=wine --private=/tmp/wine/ wine <...>