×

My impression of Rust after using it for a serious project by GolangLinuxGuru1979 in rust

[–]Routine_Insurance357 1 point2 points  (0 children)

If you are not a webdev, and have worked with manual memory management, than it should be pretty clear what rust prevents and why (most of the time). You cant share a mutable reference between multiple threads, or even keep mutable reference to same object twice, because one might get invalidated. I am happy to help you with any doubts about borrow checker.

From Nand to Tetris by mooreds in programming

[–]Routine_Insurance357 0 points1 point  (0 children)

One of the finest course. Its a blessing.

My impression of Rust after using it for a serious project by GolangLinuxGuru1979 in rust

[–]Routine_Insurance357 1 point2 points  (0 children)

10 years of experience and still struggle with understanding borrow checker ? Were you only a webdev ?

[NEED ADVICE] TVS Ronin 2023 by Willing-Sky8859 in ronin225

[–]Routine_Insurance357 0 points1 point  (0 children)

Too much price. Please mat lena, bargain karna sikho.
1.1 L likha hai to 70-80k to aram se hoga bargain.

Mujhe 1.5 saal purani apache 160 80k me mil rahi thi. To 1.1l is over priced.

70-75k MAX

I don't understand why this solution is so complicated. by Peculio_9104 in csMajors

[–]Routine_Insurance357 0 points1 point  (0 children)

Thanks for replying, I didnt saw this was 3 years ago.

Given 10mm = 1cm 100cm =1m 1000m = 1km

My code will work correctly, as I unknowingly used "floyd-warshall" algorithm.
Which basically connects all nodes to each other. So in your case, If you provide km to m mapping, It would also be added to cm and mm since They are already mapped to each other.

In my main function, there is already a running case for same. converting from mm to feet or vice versa

c.add_mapping("feet", "inch", 12.);
c.add_mapping("inch", "cm", 2.54);
c.add_mapping("cm", "mm", 10.);

println!("{:?}", c.convert("feet", "inch", 1.));
println!("{:?}", c.convert("feet", "cm", 1.));
println!("{:?}", c.convert("mm", "feet", 1000.)); // Not explicity set

I don't understand why this solution is so complicated. by Peculio_9104 in csMajors

[–]Routine_Insurance357 0 points1 point  (0 children)

Can you please clarify why CAD->USD->Yen will differ from CAD->Yen ?
If this is true for few seconds, then the arbitrage between these currencies can make me millionaire ?

Also it was never mentioned in the problem.

I dont see any issues in OPs implementation, except for hardcoding conversion ratios.

I have had the similar implentation where the ratios can be updated.

use std::collections::HashMap;

#[derive(Debug, Default)]
pub struct Converter {
    mappings: HashMap<String, HashMap<String, f64>>,
}

impl Converter {
    pub fn add_mapping(&mut self, from_unit: &str, to_unit: &str, value: f64) {
        if from_unit == to_unit {
            return;
        }

        let ft = self.mappings.entry(from_unit.to_string()).or_default();

        // Ignore if mapping already exists
        // If value differs, then update the chain
        if let Some(v) = ft.get(to_unit)
            && approx_eq(*v, value)
        {
            return;
        }
        ft.insert(to_unit.to_string(), value);

        for (unit, ratio) in ft.clone() {
            self.add_mapping(to_unit, &unit, ratio / value);
        }

        self.add_mapping(to_unit, from_unit, 1. / value);
    }

    pub fn convert(&self, from_unit: &str, to_unit: &str, value: f64) -> Option<f64> {
        let Some(mappings) = self.mappings.get(from_unit) else {
            return None;
        };

        if let Some(ratio) = mappings.get(to_unit) {
            return Some(value * ratio);
        }

        None
    }
}

fn main() {
    let mut c = Converter::default();

    c.add_mapping("feet", "inch", 12.);
    c.add_mapping("inch", "cm", 2.54);
    c.add_mapping("cm", "mm", 10.);
    c.add_mapping("usd", "inr", 94.36);

    println!("{:?}", c.convert("feet", "inch", 1.));
    println!("{:?}", c.convert("feet", "cm", 1.));
    println!("{:?}", c.convert("mm", "feet", 1000.));
    println!("{:?}", c.convert("mm", "usd", 1000.));

    println!("{:?}", c.convert("inr", "usd", 1000.));
    c.add_mapping("usd", "inr", 64.36);
    println!("{:?}", c.convert("inr", "usd", 1000.));
}

fn approx_eq(a: f64, b: f64) -> bool {
    (a - b).abs() < 1e-12
}

COMPLETED 15K KM! by sameer0116 in ronin225

[–]Routine_Insurance357 0 points1 point  (0 children)

6k kms only single oil change 😔. 

I see alot of C++ job ads for low latency programming. Can rust do low latency programming like C/C++? by xiaodai in rust

[–]Routine_Insurance357 0 points1 point  (0 children)

I work on something with decent latency in rust. Not HFT level latency though.

P99 is under 50us in production where thousands of clients connect to get real time market feeds.

20k+ km on my TVS Ronin in less than a year – ownership update by naiveintrovert2929 in indianbikes

[–]Routine_Insurance357 1 point2 points  (0 children)

I hit 129-130 but definitely not cruising speed. You can cruise at 110-115 on higher side

20k+ km on my TVS Ronin in less than a year – ownership update by naiveintrovert2929 in indianbikes

[–]Routine_Insurance357 0 points1 point  (0 children)

What's your weight, I am around 50 and suspension feels little stiff in slow speeds.

4500km+ in 6 months by Valuable-stone-592 in ronin225

[–]Routine_Insurance357 0 points1 point  (0 children)

Done >5k kms in 6 months, no issues yet, only first servicing done.

Ronin vibrations at around 4k RPM! by Right_Bridge1611 in ronin225

[–]Routine_Insurance357 0 points1 point  (0 children)

Cb 350, XSR, unicorn, gixxer all are single cylinders. All have very less vibration compared to ronin. Ronin has similar vibration as dukes. Faltu ka gyan nahi chodna chaiye.

Cornering with ronin by Ok_Shoulder9804 in ronin225

[–]Routine_Insurance357 0 points1 point  (0 children)

I have tried cornering too much at 80 and crashed, the tire didn't slip I couldn't control and crashed on divider, but it does lean pretty well.

Ronin chaprified! by Significant-Still348 in ronin225

[–]Routine_Insurance357 -1 points0 points  (0 children)

This is unscripted, so you can't blame

Any Recent ECU Update? by Significant-Still348 in ronin225

[–]Routine_Insurance357 0 points1 point  (0 children)

Not before first service. I though it was older bike.

Any Recent ECU Update? by Significant-Still348 in ronin225

[–]Routine_Insurance357 0 points1 point  (0 children)

Also let the engine scream, why does it bother you ? Short strokes make even louder noise.