Skip to content

Instantly share code, notes, and snippets.

View ameknite's full-sized avatar
💙
I may be slow to respond.

Ame アメ ameknite

💙
I may be slow to respond.
View GitHub Profile
@ameknite
ameknite / mpv.nu
Last active January 28, 2025 06:01
music and video player
def music-all [] {
task spawn {glob ~/Music/**/*.{opus} | shuffle | mpv --force-window ...$in}
}
def music-all-sync [] {
glob ~/Music/**/*.{opus} | shuffle | mpv --force-window ...$in
}
def music-shuffle [folder] {
let glob_folder = $folder
@ameknite
ameknite / opus.nu
Last active January 28, 2025 01:16
convert flac to opus
def opus [folder] {
let glob_folder = $folder
| str replace -a "]" "\\]"
| str replace -a "[" "\\["
| str replace -a "(" "\\("
| str replace -a ")" "\\)"
| str replace -a "," "\\,"
let new_folder = ($folder | str replace -r "/$" "") + " - [OPUS]/"
let music_paths = glob ($glob_folder | path join "**/*.{flac,wav,aiff,aif,ogg,oga,pcm}")
let image_paths = glob ($glob_folder | path join "**/*.{png,jpg,jpeg}")
@ameknite
ameknite / parallel-extract-batch-subs.nu
Last active January 28, 2025 01:16
par-extract-batch-subs
#!/usr/bin/env nu
def extract-subs [] {
if (glob *.mkv | is-empty) {
error make {msg: "No .mkv files found" , help: "Script only work with .mkv files"}
}
print "START"
let paths = glob *.mkv --exclude ['._*'] | sort
let names = ls | get name | where { |f| $f | str ends-with '.mkv'} | each {|f| $f | str replace ".mkv" ""} | sort
@ameknite
ameknite / extract-batch-subs.nu
Last active December 24, 2024 19:12
extract-batch-subs
#!/usr/bin/env nu
if (glob *.mkv | is-empty) {
error make {msg: "No .mkv files found" , help: "Script only work with .mkv files"}
}
print "START"
let paths = glob *.mkv --exclude ['._*'] | sort
let names = ls | get name | where { |f| $f | str ends-with '.mkv'} | each {|f| $f | str replace ".mkv" ""} | sort
let tuple_list = $paths | zip $names
# print ($tuple_list | flatten)
@ameknite
ameknite / compare_color.rs
Last active September 13, 2023 05:54
compare_color.rs
/// Implements equality comparison for Color instances.
/// Compares the colors represented as RGBA vectors for approximate equality,
/// using a tolerance specified by `f32::EPSILON`.
impl PartialEq for Color {
fn eq(&self, other: &Self) -> bool {
let self_rgba: Vec4 = self.as_rgba().into();
let other_rgba: Vec4 = other.as_rgba().into();
self_rgba.abs_diff_eq(other_rgba, f32::EPSILON)
}
}
@ameknite
ameknite / _cell.rs
Last active February 17, 2023 01:58
_cell_refcell_rc
use std::cell::UnsafeCell;
pub struct Cell<T> {
value: UnsafeCell<T>,
}
// implied by UnsafeCell
// impl<T> !Sync for Cell<T> {}
impl<T> Cell<T> {
pub fn new(value: T) -> Self {
Cell {
@ameknite
ameknite / movement_text.rs
Created February 15, 2023 21:59
bevy_basic_movement
//! Renders a 2D scene containing a single, moving sprite.
use std::f32::consts::PI;
use bevy::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_startup_system(setup)
| "OS Build Version" = "22A380"
+-o J274AP <class IOPlatformExpertDevice, id 0x100000207, registered, matched, active, busy 0 (7383 ms), retain 36>
| | | | "perf-states" = <0000000090010000007b9a175e02000000a4781f800200000054ea2aa6020000001f13370003000000ea3b435b03000080bb2c4ca3030000>
| | | | "gfx-shared-region-base" = <0080f7ff09000000>
| | | | "gpu-num-perf-states" = <06000000>
| | | | "AGXParameterBufferMaxSizeEverMemless" = 293076992
| | | | "AGXParameterBufferMaxSizeNeverMemless" = 146538496
| | | | "gpu-core-count" = 8
| | | | "AGXParameterBufferMaxSize" = 439615488
| | | | "GPUConfigurationVariable" = {"gpu_gen"=13,"num_gps"=4,"num_cores"=8,"core_mask_list"=(255),"num_frags"=8,"num_mgpus"=1}
@ameknite
ameknite / flatten.rs
Last active August 14, 2022 23:11
Iterators + Traits -- Flatten
pub trait IteratorExt {
fn our_flatten(self) -> Flatten<Self>
where
Self: Iterator + Sized,
Self::Item: IntoIterator;
}
impl<T> IteratorExt for T
where
T: Iterator,
@ameknite
ameknite / avec.rs
Last active August 13, 2022 01:25
Declarative macros - vec
https://www.youtube.com/watch?v=q6paRBbLgNw&list=PLqbS7AVVErFiWDOAVrPt7aYmnuuOLYvOa&index=2
#[macro_export]
macro_rules! avec {
() => {
Vec::new()
};
($($element:expr),+ $(,)?) => {{
let mut vs = Vec::with_capacity($crate::count!($($element),+));
$(vs.push($element);)+