Skip to content

Instantly share code, notes, and snippets.

View BillBarnhill's full-sized avatar
💭
Learning Rust

=Bill.Barnhill BillBarnhill

💭
Learning Rust
View GitHub Profile
@BillBarnhill
BillBarnhill / vecsort_with_index.rs
Created June 23, 2023 16:02
Rust: Sort a vector of ints and preserve indices
use std::cmp::Ordering;
fn main() {
fn sort_pairs<'r,'s>((_,a): &'r (usize, &i32), (_,b): &'s (usize, &i32)) -> Ordering {
if a > b { Ordering::Greater }
else if b > a { Ordering::Less }
else { Ordering::Equal}
}

Local Web Worker

Under normal circumstances, a Web Worker should be passed a URL of the script to execute. However, a local function can also be used

This is done by converting a function to a string, converting that string to a Blob, and converting that Blob to an Object URL.

Code

The code to do this would look a bit like this:

@BillBarnhill
BillBarnhill / README.md
Created May 11, 2023 13:41 — forked from Potherca/README.md
Markdown Template for Daily Scrum meetings

Daily Scrum Template

When taking part of a Daily Scrum as Scrum Master, I find it handy to take notes. This makes sure I can hand over the role, if need be. It also means I don't have to rememeber everything as I can look things up in my notes later.

Below is the structure I use as format or "template" for taking notes.

Some things of importance:

@BillBarnhill
BillBarnhill / queues.io.md
Created January 18, 2023 21:41 — forked from gtors/queues.io.md
queues.io snapshot

Queues

Job queues, message queues and other queues. Almost all of them in one place.

About

There are many queueing systems out there. Each one of them is different and was created for solving certain problems. This page tries to collect the libraries that are widely popular and have a successful record of running on (big) production systems.

@BillBarnhill
BillBarnhill / playground.rs
Created December 21, 2022 14:43 — forked from rust-play/playground.rs
Code shared from the Rust Playground
//use std::{thread, time::Duration};
//use rand::Rng;
#![feature(thread_id_value)]
use std::{thread, time::Duration, time::Instant};
use rand::Rng;
#[allow(unused_imports)]
use rayon::prelude::*;
@BillBarnhill
BillBarnhill / Returning a module name
Last active April 19, 2021 18:40 — forked from rust-play/playground.rs
Code shared from the Rust Playground
mod foo {
pub fn name() -> &'static str {
module_path!()
}
}
fn main() {
println!("Hello, {}", foo::name());
}
@BillBarnhill
BillBarnhill / main.rs
Last active March 19, 2021 10:25
Main.rs with problem with signature of on_ws_request
// This version compiles, and works
#[macro_use]
extern crate serde_derive;
use serde_json::{Map, Value};
use tide_websockets::{
WebSocket,
Message
};
use async_std::stream::StreamExt;
@BillBarnhill
BillBarnhill / app.js
Last active March 16, 2021 21:40
A main.rs for tide-websocket use.Unfortunately it closes the WebSocket immediately
// This is at present within a script tag in html page
app = function(){
function onLoad()
{
console.log("[page] loaded");
this.websocket = new WebSocket(this.wsUri);
this.websocket.onopen = this.onWsOpen;
this.websocket.onclose = this.onWsClose;
@BillBarnhill
BillBarnhill / Cargo.toml
Created March 6, 2021 15:58
Cargo.toml producing mio error
[package]
name = "xdaytime"
version = "0.1.0"
edition = "2018"
[features]
default = ["os-poll", "os-ext", "net"]
os-poll = []
os-ext = ["os-poll"]
#nop This file is read on startup by WinTin++ by default.
#event {SESSION CONNECTED} {
#showme {CONNECTED: '%0'};
#regex {%0} {^alonzo$} {
CONNECT Alonzo password;
#format {logfile} {C:/Users/wabar/WinTin++/logs/alonzo_%t.html} {%Y-%m-%d};
#log append $logfile;
} {0};
}