Skip to content

Instantly share code, notes, and snippets.

View ugovaretto's full-sized avatar

Ugo Varetto ugovaretto

View GitHub Profile
@ugovaretto
ugovaretto / Cargo.toml
Created May 1, 2022 09:41 — forked from Ciantic/Cargo.toml
This example shows how to stream a file or shell execution stdout using Hyper and Futures (Rust)
[package]
name = "yourpackage"
version = "0.1.0"
authors = ["John Doe"]
edition = "2018"
[[bin]]
name = "example"
path = "stream-a-file-using-rust-hyper.rs"
@ugovaretto
ugovaretto / README.md
Created April 24, 2022 02:50 — 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

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 April 19, 2022 08:20 — forked from NoraCodes/work_queue.rs
An example of a parallel work scheduling system using only the Rust standard library
// 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 April 13, 2022 11:05
Upload data into S3 bucket with AWS Rust S3 SDK
[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" }
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 April 9, 2022 02:19 — forked from sitag/parallel_op_vec.rs
[rust] operating on a vector in parallel with unsafe rust
#![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 April 7, 2022 12:28
Set credentials for rust AWS SDK
//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();
@ugovaretto
ugovaretto / build-static-rust.sh
Created April 6, 2022 07:31
Static compilation of Rust binaries
RUSTFLAGS='-C target-feature=+crt-static' cargo build --release --target x86_64-unknown-linux-gnu
@ugovaretto
ugovaretto / equalizer.rs
Created March 15, 2022 07:41
Height equalizer
/// Tower equaliser: givern list of tower heights return the minimum number
/// of moves required to obtain tower of the same height or return "No solution"
fn towers(t: &[u32]) -> Option<u32> {
let mut moves: u32 = 0;
let mut n = t.to_vec();
let max_moves: u32 = n.iter().sum();
loop {
let imax = match n.iter().enumerate().max_by(|&(_, x), &(_, y)| x.cmp(&y)) {
Some((m, _)) => m,
_ => usize::MIN,