Skip to content

Instantly share code, notes, and snippets.

View bsodmike's full-sized avatar

Michael de Silva bsodmike

View GitHub Profile
@bsodmike
bsodmike / atomics.rs
Created October 15, 2021 13:15
Crust of Rust: Atomics and Memory Ordering // My Notes
use std::cell::UnsafeCell;
use std::sync::atomic::{AtomicBool, Ordering};
const LOCKED: bool = true;
const UNLOCKED: bool = false;
pub struct Mutex<T> {
locked: AtomicBool,
v: UnsafeCell<T>,
}
@bsodmike
bsodmike / rust.rs
Created October 10, 2021 05:29
Rust library alloc test failure (against master)
Error whilst running `./x.py test --keep-stage 1 library/alloc/`
```rust
Updating only changed submodules
Submodules updated in 0.01 seconds
Building stage0 std artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
Copying stage0 std from stage0 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
Testing alloc stage0 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
running 265 tests
@bsodmike
bsodmike / main.rs
Created October 9, 2021 14:11
Crust of Rust: functions, closures, and their traits - My Notes.
#![feature(const_trait_impl, const_fn_trait_bound)]
fn main() {
println!("Howdy partner?");
let mut x = bar::<i32>;
println!("{}", std::mem::size_of_val(&x));
baz(bar::<u32>);
baz(bar::<i32>);
//quox(bar::<u32>);
make_fn()();
@bsodmike
bsodmike / Gemfile
Created February 23, 2021 08:34
RSpec example using Webmock to stub and API request
# frozen_string_literal: true
source "https://rubygems.org"
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
gem "faraday"
gem "json"
group :test do
@bsodmike
bsodmike / rust-resources.md
Last active May 22, 2020 00:05
Rust resources and code snippets to improve writing idiomatic Rust.

Why Rust?

  • Memory safe. I like to think of it as being given a dull-rusty blade rather than a sharp finely crafted japanese katana/wakizashi. Now go run about and see which cuts you faster!
  • Support for Futures (aka Promises in JS parlance).
  • Threadsafe concurrency features: Arc vs. Mutex<T> etc.
  • Generics and Zero-cost abstractions
  • Runs on anything with a CPU. Even Android.
  • Supports full WASM (WebAssembly). Here's a demo.
  • Fabulous tooling via Cargo.
  • Much more covered by this great talk by Jon Gjengset (@jonhoo) https://www.youtube.com/watch?v=DnT-LUQgc7s
let delay = time::Duration::from_millis(1);
let now = time::Instant::now();
let thread_delay = Arc::new(1);
let mut done = false;
while !done {
let thread_delay = Arc::clone(&thread_delay);
let handle = thread::spawn(move || {
.
├── Cargo.lock
├── Cargo.toml
├── conf
│   ├── development
│   │   └── config.yml
│   └── production
│   └── config.yml
├── src
│   ├── errors.rs
@bsodmike
bsodmike / rust-mysql.rs
Created May 4, 2020 10:29
Fetching fields with Mysql crate in Rust
#[macro_use]
use crate::mysql::*;
use crate::mysql::prelude::*;
use crate::errors::Error;
#[derive(Debug)]
pub struct ConnectorMysql {
}