Skip to content

Instantly share code, notes, and snippets.

@thorseraq
thorseraq / merge_video.sh
Created September 16, 2023 09:55
video_merger
# 1. first goto video folder
# 2. generate video file(front camera) list of current folder
ls | grep 'front' | awk '{print "file \x27" $0 "\x27"}' > merge.txt
# 3. (optional), edit merge.txt, remove unwanted video files name
# 4. merge videos
ffmpeg -f concat -safe 0 -i merge.txt -c copy output.mp4
@thorseraq
thorseraq / sea-orm-expand.rs
Created September 12, 2023 15:04
SeaORM expand
#![feature(prelude_import)]
#[prelude_import]
use std::prelude::rust_2021::*;
#[macro_use]
extern crate std;
#[forbid(unsafe_code)]
mod entities {
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.2
pub mod prelude {
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.2
use std::sync::{Arc, RwLock};
use std::thread;
use std::thread::sleep;
use std::time::Duration;
/// Option<Arc<i32>> 适合初始化时就能决定是 None 还是 Some 值,后面不需要改的情况
/// 这个例子里尝试在初始化后重新赋值,导致在不同的线程中无法得到相同的值
fn main() {
let mut apple = Apple::new();
{
use std::sync::Arc;
use std::thread;
use dashmap::{DashSet};
fn main() {
let set = Arc::new(DashSet::<i32>::default());
{
for i in 0..10 {
let set = set.clone();
thread::spawn(move || {
use std::sync::Mutex;
use std::time::Instant;
fn main() {
let last = Instant::now();
let num = Mutex::new(1);
for _ in 0..1000 * 1000 * 10 {
let mut guard = num.lock().unwrap();
*guard += 1;
}
use yrs::{DeepObservable, Doc, Map, Transact};
fn main() {
let doc = Doc::new();
let mut block = doc.get_or_insert_map("block");
let sub = block.observe_deep(move |_trx, _e| {
println!("subscribe -> observe_deep");
});
// drop(sub); // drop sub will lose observation
use std::sync::Arc;
use std::thread::sleep;
use std::time::Duration;
use tokio::sync::RwLock;
#[tokio::main]
async fn main() {
let (tx, mut rx) = tokio::sync::mpsc::channel::<i32>(100);
for i in 0..100 {
tx.send(i).await.expect("TODO: panic message");
use std::sync::{mpsc, Arc, Mutex};
use std::thread;
use std::thread::sleep;
fn main() {
let (tx, rx) = mpsc::channel();
let rx = Arc::new(Mutex::new(rx));
for _ in 0..3 {
let rx = rx.clone();
use std::sync::Arc;
use std::thread::sleep;
use tokio::runtime::Runtime;
fn main() {
let rt = Arc::new(Runtime::new().unwrap());
rt.spawn(async {
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
println!("finished");
});
fn main() {
let rt = tokio::runtime::Runtime::new().unwrap();
let rt2 = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async {
rt2.spawn(async {
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
println!("finished");
});
});