Skip to content

Instantly share code, notes, and snippets.

View hderms's full-sized avatar

Morrigan Haughey hderms

View GitHub Profile
@hderms
hderms / weird
Created October 3, 2023 20:59
Weird aurora recovery error
ERROR: Found invalid undo record! Undo record len=18446744073709546430, rec_offset=8509, next_rec_offset=3323
use std::num::Wrapping;
fn main() {
let t = Wrapping(0u64) - (Wrapping(8509u64) - Wrapping(3323u64));
println!("{}", t);
}
@hderms
hderms / parse.rs
Created February 3, 2023 17:42
implementation inspired by Redis string -> signed int parsing
// Copyright 2023 Pelikan Foundation LLC.
// Licensed under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0
//! Common, performance-oriented mechanisms of parsing byte strings into various types
/// maximum length of a string that could be stored as a u64 in Redis
/// comment from redis/util.h
/// > Bytes needed for long -> str + '\0'
@hderms
hderms / incr.rs
Created February 2, 2023 21:42
changes to set() and addition of incr() entrystore method to support incrementing integers as if they were stored as signed instead of unsigned
fn incr(&mut self, incr: &Incr) -> Response {
let value = if let Some(item) = self.data.get(incr.key()) {
match item.value() {
seg::Value::Bytes(b) => None,
seg::Value::U64(v) => {
Some(v)
}
}
} else {
Some(0)
use std::cell::RefCell;
use std::collections::HashMap;
use std::rc::Rc;
struct Node<V> {
value: Option<V>,
terminal: bool,
children: HashMap<char, Node<V>>,
}
@hderms
hderms / sparse_vector.rs
Created June 23, 2021 14:11
sparse vector dot product
struct SparseVector {
pub compressed: Vec<(usize, i32)>
}
/**
* `&self` means the method takes an immutable reference.
* If you need a mutable reference, change it to `&mut self` instead.
*/
impl SparseVector {
fn new(nums: Vec<i32>) -> Self {
@hderms
hderms / cargo.toml
Created April 6, 2021 20:54
Rust compiler bug
[package]
name = "particular"
version = "0.1.0"
authors = ["Dermot Haughey <hderms@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
piston = "0.52.1"
@hderms
hderms / hash_table.rs
Created April 6, 2021 01:45
Writing a hash table in Rust
use std::{
collections::hash_map::DefaultHasher,
hash::{Hash, Hasher},
};
const SIZE: usize = 2 << 12;
const CHAIN_CAPACITY: usize = 16;
struct HashTable<K: Hash + PartialEq, V> {
table: Vec<Vec<(K, V)>>,
}
impl<K: Hash + PartialEq, V> HashTable<K, V> {
@hderms
hderms / merge_intervals.rs
Last active March 19, 2021 21:49
Iterate through two vectors of pre-sorted disjoint intervals, returning a vector which includes any intervals which represent any overlap between ranges
use std::cmp::{min, max};
impl Solution {
pub fn interval_intersection(first_list: Vec<Vec<i32>>, second_list: Vec<Vec<i32>>) -> Vec<Vec<i32>> {
let mut i: usize = 0;
let mut j: usize = 0;
let mut vec: Vec<Vec<i32>> = Vec::with_capacity(max(first_list.len(), second_list.len()));
while (i < first_list.len() && j < second_list.len()) {
let left = &first_list[i];
let right = &second_list[j];
@hderms
hderms / palindrome.rs
Created February 25, 2021 17:53
determines if a string is a palindrome, if one character is deleted
impl Solution {
pub fn valid_palindrome(s: String) -> bool {
let mut i: usize = 0;
let mut j: usize = s.len() - 1;
let s = s.as_bytes();
loop {
if s[i] != s[j] {
return Solution::is_palindrome(s.clone(), i + 1, j) || Solution::is_palindrome(s.clone(), i, j - 1);
}
i += 1;
while let Some(chunk) = stream.next().await {
let c: UploadFileRequest = chunk?;
hasher.update(&c.chunk);
temp_file.write(&c.chunk).unwrap();
}
println!("temp file path is {:?}", temp_file.path());
temp_file.flush().unwrap()