Skip to content

Instantly share code, notes, and snippets.

Avatar

ugo ugovaretto

  • The Pawsey Supercomputing Centre
  • Kensington, Western Australia
View GitHub Profile
@ugovaretto
ugovaretto / build-static-rust.sh
Created Apr 6, 2022
Static compilation of Rust binaries
View build-static-rust.sh
RUSTFLAGS='-C target-feature=+crt-static' cargo build --release --target x86_64-unknown-linux-gnu
View equalizer.rs
/// 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,
@ugovaretto
ugovaretto / Cargo.toml
Last active Feb 14, 2022
Create web service that sends a request to github api
View Cargo.toml
[package]
name = "rocket_reqw"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rocket = "0.4"
serde = {version = "1", features = ["derive"]}
@ugovaretto
ugovaretto / Task-based executor.cpp
Last active Feb 12, 2022
Task executor and wrapper for concurrent access to variable
View Task-based executor.cpp
// Author: Ugo Varetto
// Implementation of task-based concurrency (similar to Java's Executor)
// and wrapper for concurrent access
// g++ task-based-executor-concurrent-generic.cpp -std=c++11 -pthread
#include <algorithm>
#include <chrono>
#include <condition_variable>
#include <cstdlib> //EXIT_*
View rust-reqwest-stream-example.rs
let offset = 20000;
let chunk_size = 10000;
// File handle:
let mut handle = BufReader::new(File::open("data.bin").await?);
// Set cursor to needed chunk:
let mut chunk_stream = handle
.bytes()
.skip(offset)
View barrier.cpp
#include <chrono>
#include <condition_variable>
#include <iostream>
#include <thread>
class Barrier {
public:
Barrier(uint32_t count) : threadCount(count), counter(0), waiting(0) {}
void wait() {
@ugovaretto
ugovaretto / du_hidden.sh
Last active Nov 16, 2020
List disk usage for hidden files
View du_hidden.sh
#!/usr/bin/env bash
du -sch .[!.]* * | sort -h
View vector_allocation.cpp
// Author: Ugo Varetto
// buffer allocation performance tests: vector, vector+pod allocator (same as
// vector), raw aligned buffer (faster)
#include <sys/mman.h>
#include <unistd.h>
#include <cstdlib>
#include <ctime>
#include <iostream>
@ugovaretto
ugovaretto / pwcpp_mm.cpp
Created Oct 15, 2020
Parallel copy with memory mapped files
View pwcpp_mm.cpp
/*******************************************************************************
* BSD 3-Clause License
*
* Copyright (c) 2020, Ugo Varetto
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions inputFile source code must retain the above copyright
View pwcp.cpp
/*******************************************************************************
* BSD 3-Clause License
*
* Copyright (c) 2020, Ugo Varetto
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions inputFile source code must retain the above copyright