Skip to content

Instantly share code, notes, and snippets.

View MathiasYde's full-sized avatar

Mathias MathiasYde

View GitHub Profile
@MathiasYde
MathiasYde / RenderTextureUtils.cs
Created June 4, 2023 18:03
Export RenderTexture to a file
using System;
using UnityEditor;
using UnityEngine;
public static class RenderTextureUtils {
public static TextureFormat DEFAULT_TEXTURE_FORMAT = TextureFormat.RGBA64;
public static String DEFAULT_FILE_FORMAT = "png";
/// <summary>
/// Export a RenderTexture asset to a file
struct Vector3 {
union { float x; float r; };
union { float y; float g; };
union { float z; float b; };
// return a normalized vector
static Vector3 Normalize(const Vector3& v) {
float magnitude = Vector3::Magnitude(v);
return v * (1 / magnitude);
}
@MathiasYde
MathiasYde / split_mkv.py
Created August 4, 2022 00:02
Python script to extract each track in a .MKV file
# requires ffmpeg-python and click
import click
import ffmpeg
import os.path
def extract_track(filepath, track_index, output_path):
file = ffmpeg.input(filepath)
output = ffmpeg.output(file[f"{track_index}"], output_path)
ffmpeg.run(output)
#include <iostream>
#include <string>
#include <map>
#include <functional>
#include <iterator>
int main() {
//Define operations and their respective function
std::map<std::string, std::function<int(int, int)>> operations;
operations["+"] = [&](int lhs, int rhs) { return lhs + rhs; };
import numpy as np
from manimlib import *
import math
class NewtonRaphsonExample(Scene):
def newton_raphson_solve(self, x):
result = x - self.f(x)/self.df(x)
# It is possible that the result will be infinite,
# In that case, we just return a large number.
@MathiasYde
MathiasYde / solver.cpp
Last active February 15, 2022 21:43
C++ implementation of Newton Raphson
#include <iostream>
#include <chrono>
#include "math.h"
#include <tuple>
#include <vector>
#include <set>
#define printl(o) std::cout << o << std::endl;
#define print(o) std::cout << o;
#define number long double
@MathiasYde
MathiasYde / of_types.py
Last active January 11, 2022 11:57
Assert or omit function call if paramaters are not met with certain type requirements
def of_types(*types, omit_error=False):
def decorator(function):
def wrapper(*args, **kwargs):
for arg, t in zip(args, types):
if not isinstance(arg, t):
if omit_error:
return
raise TypeError(f"Invalid arguement type {t}({arg}) in {function.__name__}{args}")
return function(*args, **kwargs)
return wrapper
public static class VectorExtensions {
public static Vector2 Add(this Vector2 vector, float x = 0, float y = 0) {
return new Vector2(vector.x + x, vector.y + y);
}
public static Vector3 Add(this Vector3 vector, float x = 0, float y = 0, float z = 0) {
return new Vector3(vector.x + x, vector.y + y, vector.z + z);
}
public static Vector2 Scale(this Vector2 vector, float x = 1, float y = 1) {
@MathiasYde
MathiasYde / MinMax.cs
Created December 19, 2021 17:43
Unity MinMax datamodel
using UnityEngine;
[System.Serializable]
public struct MinMax {
public float min;
public float max;
public MinMax(float min, float max) {
this.min = min;
this.max = max;