This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# run with sudo | |
ethtool -s enp8s0 wol g | |
systemctl hibernate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/etc/systemd/network/50-wired.link | |
#Make system wake up on magic packet reception | |
[Match] | |
MACAddress=80:FA:5B:78:BB:98 | |
[Link] | |
NamePolicy=kernel database onboard slot path | |
MACAddressPolicy=persistent | |
WakeOnLan=magic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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"))?; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "memcpy" | |
version = "0.1.0" | |
edition = "2021" | |
[dependencies] | |
page_size = "*" | |
nix = "*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[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))] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::{ | |
fs::File, | |
io::{Read, Write}, | |
time::Instant, | |
}; | |
use tokio::task::{self, JoinHandle}; | |
async fn compute() { | |
let handles: Vec<JoinHandle<_>> = (0..1000) | |
.map(|_| { |