Skip to content

Instantly share code, notes, and snippets.

Avatar

ugo ugovaretto

  • The Pawsey Supercomputing Centre
  • Kensington, Western Australia
View GitHub Profile
@ugovaretto
ugovaretto / read_at.rs
Created May 19, 2022
read_at with Rust
View read_at.rs
#[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))]
View rust_tokio_block_in_place.rs
use std::{
fs::File,
io::{Read, Write},
time::Instant,
};
use tokio::task::{self, JoinHandle};
async fn compute() {
let handles: Vec<JoinHandle<_>> = (0..1000)
.map(|_| {
@ugovaretto
ugovaretto / Cargo.toml
Created May 1, 2022 — forked from Ciantic/Cargo.toml
This example shows how to stream a file or shell execution stdout using Hyper and Futures (Rust)
View Cargo.toml
[package]
name = "yourpackage"
version = "0.1.0"
authors = ["John Doe"]
edition = "2018"
[[bin]]
name = "example"
path = "stream-a-file-using-rust-hyper.rs"
View rust-tip-rust-analyzer-customization.md
@ugovaretto
ugovaretto / README.md
Created Apr 24, 2022 — forked from PurpleBooth/README.md
A github workflow pipeline for rust that does test, build and deploy windows, linux and mac, creates releases, and does SemVer Versioning, and releases to a homebrew tap
View README.md

Features

  • Automatically bump SemVer
  • Update a personal homebrew tap
  • Keep that pesky version in the Cargo.toml up to date
  • (From dependabot) Get new versions out as soon as possible

Assumptions

  • You don't want a changelog
@ugovaretto
ugovaretto / work_queue.rs
Created Apr 19, 2022 — forked from NoraCodes/work_queue.rs
An example of a parallel work scheduling system using only the Rust standard library
View work_queue.rs
// Here is an extremely simple version of work scheduling for multiple
// processors.
//
// The Problem:
// We have a lot of numbers that need to be math'ed. Doing this on one
// CPU core is slow. We have 4 CPU cores. We would thus like to use those
// cores to do math, because it will be a little less slow (ideally
// 4 times faster actually).
//
// The Solution:
@ugovaretto
ugovaretto / Cargo.toml
Last active Apr 13, 2022
Upload data into S3 bucket with AWS Rust S3 SDK
View Cargo.toml
[package]
name = "Upload to S3"
version = "0.1.0"
authors = ["Ugo Varetto <ugo.varetto@csiro.au>"]
edition = 2021
[dependencies]
aws-config = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
# snippet-start:[s3.rust.s3-object-lambda-cargo.toml]
aws-endpoint = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
View parallel_op_vec_stable.rs
use std::thread::spawn;
// #1 Create type to move pointer can extend with new
// returning either wrapped pointer or ~None when pointer null
#[derive(Copy, Clone)]
struct Movable<T>(*mut T);
impl<T> Movable<T> {
fn get(&self) -> Option<*mut T> {
if self.0.is_null() { return None; }
@ugovaretto
ugovaretto / parallel_op_vec.rs
Created Apr 9, 2022 — forked from sitag/parallel_op_vec.rs
[rust] operating on a vector in parallel with unsafe rust
View parallel_op_vec.rs
#![feature(unique)]
use std::thread::spawn;
// operating on a vector in parallel
fn main() {
let mut data:Vec<u32> = vec![1u32, 2, 3];
println!("{:?}", data);
let head = data.as_mut_ptr();
let mut guards = (0..3).map(|i|
@ugovaretto
ugovaretto / aws-credentials.rs
Created Apr 7, 2022
Set credentials for rust AWS SDK
View aws-credentials.rs
//https://docs.rs/aws-types/0.9.0/aws_types/credentials/struct.Credentials.html
use aws_types::Credentials;
use aws_types::region::Region;
let creds = Credentials::from_keys("akid", "secret_key", None);
let config = Config::builder()
.credentials_provider(creds)
.region(Region::new("us-east-1"))
.build();