Skip to content

Instantly share code, notes, and snippets.

View ugovaretto's full-sized avatar

Ugo Varetto ugovaretto

View GitHub Profile
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 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 / 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|
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)
@ugovaretto
ugovaretto / opencl-error-codes.txt
Created April 19, 2020 09:37 — forked from bmount/opencl-error-codes.txt
OpenCL Error Codes
CL_SUCCESS 0
CL_DEVICE_NOT_FOUND -1
CL_DEVICE_NOT_AVAILABLE -2
CL_COMPILER_NOT_AVAILABLE -3
CL_MEM_OBJECT_ALLOCATION_FAILURE -4
CL_OUT_OF_RESOURCES -5
CL_OUT_OF_HOST_MEMORY -6
CL_PROFILING_INFO_NOT_AVAILABLE -7
CL_MEM_COPY_OVERLAP -8
CL_IMAGE_FORMAT_MISMATCH -9
@ugovaretto
ugovaretto / sendRawEth.c
Created September 9, 2018 14:21 — forked from austinmarton/sendRawEth.c
Send a raw Ethernet frame in Linux
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/
#include <arpa/inet.h>
#include <linux/if_packet.h>
#include <stdio.h>
@ugovaretto
ugovaretto / recvRawEth.c
Created September 9, 2018 14:21 — forked from austinmarton/recvRawEth.c
Receive raw Ethernet frames in Linux
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/
#include <arpa/inet.h>
#include <linux/if_packet.h>
#include <linux/ip.h>