Skip to content

Instantly share code, notes, and snippets.

View RedBlaze42's full-sized avatar
📚
Studying

RedBlaze42

📚
Studying
View GitHub Profile
import subprocess
import io
import cv2
class FfmpegVideo():
def __init__(self, output_path, framerate=30):
self.output_path = output_path
self.closed = False
self.ffmpeg_proc = subprocess.Popen(f"ffmpeg -y -loglevel error -framerate {framerate} -f image2pipe -c:v mjpeg -i - -c:v libx264 -b:v 10M -preset ultrafast -r {framerate} {output_path}", shell=True, stdin=subprocess.PIPE)#, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
@RedBlaze42
RedBlaze42 / main.py
Created February 9, 2024 10:09
Barometric flight controller micropython
# Barometric flight controller by RedBlaze (ESTACA-SiERA)
# You need the bmp280 library available here: https://github.com/dafvid/micropython-bmp280/blob/83dfdd6dff6382c7aff03138d32ae48d00ec729a/bmp280.py
import machine, neopixel, bmp280, time
import _thread
from machine import Pin, I2C, Timer
from micropython import const
from collections import deque
import rp2
@RedBlaze42
RedBlaze42 / setup.cpp
Created October 28, 2022 18:50
Rotating rocker FluidX3D
std::atomic_bool revoxelizing = false;
void revoxelize(LBM* lbm, Mesh* mesh) { // voxelize new frames in detached thread in parallel while LBM is running
for(uint n=0u; n<lbm->get_N(); n++) lbm->flags[n] &= ~TYPE_S; // clear flags
const float3x3 rotation = float3x3(float3(0.0f, 1.0f, 0.0f), radians(0.8f)); // create rotation matrix to rotate mesh
mesh->rotate(rotation); // rotate mesh
voxelize_mesh_hull(*lbm, mesh, TYPE_S); // voxelize rotated mesh in lbm.flags
revoxelizing = false; // indicate new voxelizer thread has finished
}
void main_setup() { // Rotating rocket
// ######################################################### define simulation box size, viscosity and volume force ############################################################################
@RedBlaze42
RedBlaze42 / plotly_date.py
Created September 17, 2022 16:40
Tutoriel plotly
import plotly.express as px
from datetime import datetime
dates_str = ["21/07/1998", "21/08/1998", "21/09/1998", "21/10/1998", "21/11/1998", "21/12/1998"] # X
valeurs = [1, 2, 3, 3, 2, 1] # Y
# %d = jour du mois 00-31
# %m = mois de l'année 00-12
# %Y = année en 4 chiffres 0000-9999
format_date = "%d/%m/%Y"
@RedBlaze42
RedBlaze42 / livegraph.py
Last active September 10, 2022 14:40
LiveGraph
import plotly.graph_objects as go
import dash
from dash import dcc
from dash.dependencies import Input, Output
from dash import html
from functools import partial
import serial
class LiveGraph():
@RedBlaze42
RedBlaze42 / json_config.py
Last active May 30, 2022 18:12
My take on a locking json editor for config or state files
class JsonConfig():
def __init__(self, filepath):
self.last_timestamp_loaded = None
self.file = None
if not os.path.exists(filepath):
with open(filepath, "w") as f: json.dump({}, f)
print(filepath, os.path.exists(filepath))
self.filepath = filepath
self.lockpath = f"{filepath}.lock"
@RedBlaze42
RedBlaze42 / hls_motion
Created August 7, 2021 21:55
hls_motion
import cv2, imutils
from imutils.video import VideoStream
from os import path
import os
from shutil import copy
import time, tqdm
import pickle
def digit(input,nb):
output=str(input)
@RedBlaze42
RedBlaze42 / shuffle.py
Created April 27, 2020 20:49
Streaming from a Pi
import os
import random
path="music/"
files = [f for f in os.listdir(path) if os.path.isfile(os.path.join(path, f))]
print("Nombre de musiques: {}".format(len(files)))
random.shuffle(files)
data="\n".join(["file '{}{}'".format(path,file) for file in files])
with open("list.txt","w") as concat_file:
@RedBlaze42
RedBlaze42 / snippet.json
Created February 10, 2020 15:16
C snippet
"start": {
"prefix": "startC",
"scope": "c",
"body": [
"#include<stdlib.h>",
"#include<stdio.h>",
"",
"int main(){",
" $1",
"}"
@RedBlaze42
RedBlaze42 / rename.py
Created August 20, 2019 17:17
Rename by creation date
#!/usr/bin/env python
from stat import S_ISREG, ST_CTIME, ST_MODE
import os, sys, time
def digit(input,nb):
output=str(input)
while(len(output)<nb):
output="0"+output
return output