Skip to content

Instantly share code, notes, and snippets.

View ugovaretto's full-sized avatar

Ugo Varetto ugovaretto

View GitHub Profile
@ugovaretto
ugovaretto / heic2jpeg.hs
Created April 16, 2023 14:52
Convert HEIC to JPEG (Haskell version)
import System.Directory
import System.FilePath
import Control.Monad
import System.Process
import Data.Char
main = do
c <- listDirectory "."
f <- filterM (\x -> return (map toLower (snd(splitExtension x)) == ".heic")) c
mapM (\x -> callProcess "convert" [x, (dropExtension x) ++ ".jpg"]) f
@ugovaretto
ugovaretto / hibernate-wol-magic.sh
Created February 11, 2023 11:44
Enable wake-on-lan magic packet before hibernating
#!/usr/bin/env bash
# run with sudo
ethtool -s enp8s0 wol g
systemctl hibernate
@ugovaretto
ugovaretto / 50-wired.link
Created February 11, 2023 11:42
Make Wake-on-line on magic packet persistent
@ugovaretto
ugovaretto / Convert from heic to jpg
Last active November 28, 2022 07:19
heic2jpg.rs
#!/usr/bin/env rust-script
use std::{
env, fs,
io::{self, Error, ErrorKind},
};
fn main() -> io::Result<()> {
let d = env::args()
.nth(1)
.ok_or(Error::new(ErrorKind::Other, "Missing argument"))?;
@ugovaretto
ugovaretto / heic2jpg.d
Last active October 15, 2022 02:21
Convert HEIC to JPG
#!/usr/bin/env rdmd
int convert(string path) {
import std.file, std.algorithm, std.path, import std.parallelism;
import std.process : execute
import std.uni: toLower;
auto dFiles = dirEntries(path, SpanMode.breadth).filter!(f=>f.name.toLower.endsWith(".heic"));
foreach (d; parallel(dFiles)) {
auto f = d.name;
auto status = execute(["convert", f.baseName, f.baseName ~ ".jpg"]);
if (status.status != 0) return status.status;
@ugovaretto
ugovaretto / Cargo.toml
Last active July 25, 2022 02:28
rust memcpy
[package]
name = "memcpy"
version = "0.1.0"
edition = "2021"
[dependencies]
page_size = "*"
nix = "*"
@ugovaretto
ugovaretto / aligned_vec.rs
Created June 7, 2022 10:29
Create aligned Vec instance
// Create aligned Vec
fn main() {
let ivec: Vec<i32> = aligned_vec(2048, 4096, 256);
assert!(ivec.as_ptr() as u64 % 256 == 0);
}
pub fn aligned_vec<T: Sized>(size: usize, capacity: usize, align: usize) -> Vec<T> {
unsafe {
if size == 0 {
Vec::<T>::new()
} else {
@ugovaretto
ugovaretto / aio_read.rs
Created June 6, 2022 10:17
Async file I/O with aio* functions
// Async file I/O
use libc::{aio_read, aiocb, aio_error, aio_return};
use std::fs::File;
use std::os::unix::io::AsRawFd;
fn main() {
let file = File::open("src/main.rs").unwrap();
let mut buf = [0; 1024];
let mut cb = aiocb {
aio_fildes: file.as_raw_fd(),
@ugovaretto
ugovaretto / read_at.rs
Created May 19, 2022 01:11
read_at with Rust
#[cfg(any(windows))]
fn load_exact_bytes_at(buffer: &mut Vec<u8>, file: &File, offset: u64) {
use std::os::windows::fs::FileExt;
let mut data_read = 0;
while data_read < buffer.len() {
data_read += file.seek_read(buffer, offset).unwrap();
}
}
#[cfg(any(unix))]
use std::{
fs::File,
io::{Read, Write},
time::Instant,
};
use tokio::task::{self, JoinHandle};
async fn compute() {
let handles: Vec<JoinHandle<_>> = (0..1000)
.map(|_| {