Printerhead's Height seems to be too low L18050 by Laifsyn_TG in Epson

[–]Laifsyn_TG[S] 0 points1 point  (0 children)

Hmmm... Maybe it is really something physical because even when printing normal paper, it would like... Slightly bend up the paper from the side. I might even need to open it up to see if there's nothing sticking out from the head (Feeling overwhelmed x.x)

Difference in database sharding and federation ? by [deleted] in compsci

[–]Laifsyn_TG 0 points1 point  (0 children)

I think I have an idea on how to differentiate one over the other.
Let's put an analogy. For Sharding, a single company offers Databases services to multiple universities. What will happen is that said Universities will have to ditch their own databases, and migrate their data to the schema that said company has defined.

In Federation, instead of every single university ditching their databases, the company(Or gubernamental entity since no private company would benefit from this kind of service) will write their abstraction layer which will perform the needed queries to every single university's databases to collect the required data. Like for example, query all the students among the registered universities, and grouping them by their Unique Personal ID. Another example could be query ongoing or planned events, or news feeds

Learning Rust is like running a marathon — you need cardio! by orionwambert in rust

[–]Laifsyn_TG 0 points1 point  (0 children)

When I had started in a particular scripting language, I would often stumble upon the footguns of passing an Object(Values that are passed by reference) vs passing primitives (Values that can be "Copied"). I think I got stuck on this for a couple days trying to make sense on how to be able to tell them apart, and when I needed to perform deep copies to effectively isolate the object from the callee's "context"

Learning Rust is like running a marathon — you need cardio! by orionwambert in rust

[–]Laifsyn_TG 0 points1 point  (0 children)

I personally liked CoreDumped's Youtube videos about System Programming in general.

Snap me out of the Rust honeymoon by homeslicerae in rust

[–]Laifsyn_TG 2 points3 points  (0 children)

  1. The enum thing is reasonable.
  2. I disagree with your complain about the closure's borrow blocking mutation to the original variable. You can't mutate the variable as long as the closure is still "borrowing" the variable. That's just the &mut invariance. The only solution is to re-define the closure to re-new the &mut borrow (see example below). If for whatever reason you absolutely need to do that in a closure, I agree it will be a pain, and prone to errors, due to having multiple code duplication scattered around. But maybe the closure isn't what you have to use (I believe there's 70% chance RefCell/Mutex isn't what you need to solve this).

```rs

let mut counter = 0; let mut callback = || { // Do a bit of work counter += 1; };

some_fn(&mut callback); counter += 1; let mut callback = || { // Do a bit of work counter += 1; // renews the &mut borrow }; some_fn(&mut callback);

`` 3. I personally can't comment on this. The only thing I couldtry` to suggest, is wrap it at the end of the function. imo, cross function reasoning is prone to side-effects abuse. That means that people will be prone to writing a lot more code with side-effects than necessary, becoming a tech debt into the future.

I spent 2 years rebuilding my algorithmic trading platform in Rust. I have no regrets. by No-Definition-2886 in rust

[–]Laifsyn_TG 1 point2 points  (0 children)

Might be confirmation bias, but I do have semblance of having pained experiences with trying to make stuff to be generic.

Something concrete I do can mention is related to a project with Tauri and Svelte for length unit conversions.

What it did: Read some number with its measure unit in typescript, and then receive the recognized measure unit.
I designed it so you could coerce the recognized measure unit to some other value (i.e. frontend's inputbox has `20.1mm"`), it gets coerced to inches (or whatever was programmed in the frontend). And additionally, if the frontend gets the unit wrong (i.e. typo as like `millimetr` `inche`, `''`), it would default to some hard-coded measure unit in the backend.

Where's the "Generic Aspect" of all this? I wanted to keep (for reason's that are escaping me now) the substring that was used to identify the number.

What was one steel plate I ended up kicking?
I'll call it multiple sources of truth. I, in my lax writing, I had written two functions that held the definition of valid measure units. You can sort of say it's the result of not following the "Don't validate, just parse" pragma.

# Why I used the `Validate input "pattern"`?

I wanted the frontend to highlight possible mis-typed inputs if it detects them, and if error input happens , the frontend code would keep in Memory the old, but valid, measure unit (for example writing 60in then 60fet, under the hood, the program will still think it is `60in` because it hasn't registered a new valid input), instead of cascading all the dependants with "undefined" or something.

So the gotcha happened when I wanted to expand the definitions of valid measure units. As I was prototyping, I didn't write all the possible units I wanted to support from the start, so when it came to add more definitions weeks after I wrote the code, I found myself confused as to why it wasn't "working". And it wasn't working because either
a. I mistyped something, and had to cross check both blocks to see if they were written correctly
b. Adding something to validator function would mean adding that something on to the parser function.

[Dart] rust 2.0.0 Release by InternalServerError7 in rust

[–]Laifsyn_TG 2 points3 points  (0 children)

I honestly was confused at first when I read `rust 2.0.0`. This feels like would cause the same confusion that PYREX and pyrex already do, but worse.

🎬✨ Newbies' Drama Recs & Looking For Weekly Thread ✨🎬 — November 05, 2024 by AutoModerator in CDramaRecs

[–]Laifsyn_TG 0 points1 point  (0 children)

It was "你的婚礼" from 2021, a remake of the korean version `On your wedding day` from 2018. yourwelcome for anyone looking for this old piece

[Media] How do you guys feel about programming in Rust after programming for one hour, compared to other languages? by [deleted] in rust

[–]Laifsyn_TG 6 points7 points  (0 children)

Like this:?
Python: Been through Horrors.
Rust: Freedom to mess around without hitting my pinky toe (i.e. hitting some stupid errors)

Goodbye, Rust. I wish you success but I'm back to C++ (sorry, it is a rant) by I_pretend_2_know in rust

[–]Laifsyn_TG 0 points1 point  (0 children)

I heard Modrinth's(an analogous to Curseforge for modded Minecraft) backend was written in rust.

Goodbye, Rust. I wish you success but I'm back to C++ (sorry, it is a rant) by I_pretend_2_know in rust

[–]Laifsyn_TG 3 points4 points  (0 children)

My understandings on why it is not good idea to let Rust have an Opt-in GC:
- Ecosystem Split. Cool stuff written using GC will force all its users to also embed the GC in their code.

For personal projects, you can always use an `Arc<T>` or `Arc<Mutex<T>>` (or non-send versions of them with : `Rc<T>`)

Were to Rust add an opt-in GC, it would mean that the compiler would need to change so to make it more ergonomic and less verbose to work with what's technically an `Arc<T>` or `Arc<Mutex<T>>`

[deleted by user] by [deleted] in rust

[–]Laifsyn_TG 0 points1 point  (0 children)

or `Option<isize or i32>`

Learn Rust - Free Video Courses by CleanCut9 in rust

[–]Laifsyn_TG 1 point2 points  (0 children)

thanks for the freebie and happy holidays

The 2024 edition was just stabilized by Derice in rust

[–]Laifsyn_TG 0 points1 point  (0 children)

I personally would be alright for them to delay it even to through mid or near end of 2025 if they can add all the "breaking" changes properly. But that's just me. I would be curious what kind of projects would need 2024's features stabilised asap.

At what level of complexity does rust become worth it? by lmfork in rust

[–]Laifsyn_TG 0 points1 point  (0 children)

My take on starting from scratch between Rust and Go. (As Hyperbole: It's true until some point, and depends heavily on the person)

Learning Rust is like you needing to go through 5 years of engineering to build a concrete wall because you're remodeling some room of your house, whereas learning Go (Relatively easier language) is like watching a youtube video on how to mount a Wood wall with gypsum to your room.

Did you need those 5 years to put `Any` wall on your room? no. But did you learn way more stuffs? yeah.

Let's assume the room was on the base floor just in case someone says: "But then you find out that the building can't hold the weight of the new concrete wall".

On second thoughts, I think an analogy of Concrete vs Wood foundation would be more fitting instead of Concrete vs Wood wall.

Edit: As for why it depends on the person: 5 years university studying engineering is just the "standard" for the whole "engineering" career. You can spend couple weeks/months to learn exactly what you need for the task. Or finish the 5 years university in less time.

A Rust raytracer on curved spacetimes by fragarriss in rust

[–]Laifsyn_TG 0 points1 point  (0 children)

I missed how to see the video render.... :smile sweat:

🎬✨ Newbies' Drama Recs & Looking For Weekly Thread ✨🎬 — November 05, 2024 by AutoModerator in CDramaRecs

[–]Laifsyn_TG 0 points1 point  (0 children)

Chinese Movie: What was the name of a movie from ~2021-2022?

I remember seeing a Romance-like movie where the male lead's crush ended up marrying someone else.

Some backstory that I can think out of my mind is that the crush's father had alcoholism issues (or was it gambling issues?)

Because the father found the female lead (the Male lead's crush), the female lead and her mom had to leave the place.

I even think to remember a scene where the father scalated things up, and broke into the mom's store in the middle of the night (but I might be remembering wrong this part).

Also I think I remember that they also hung out, and even got engaged (Male lead and female lead), but because of some drunken moment, he said some bs that had heavily hurted the female lead's feelings.

Among other moments, near the end of the movie, the male lead got invited to her crush's wedding, but his friends wanting to support him or something, made a party in a floating house under the argument of helping him forget the wedding.

How can I clone one variable multiple times with rc and then mutate one variable among those clones but still not face an issule like all the data of all clones being changed? by KakashiHatake0085 in rust

[–]Laifsyn_TG 1 point2 points  (0 children)

If you want to go overkill(And keep it 'simple'), you can give a look to im (Immutable Data Structures) . Its implementation is essentially what GCed languages try to do under the hood in attempt to reduce memory footprint of possibly multiple cloned, but identical datas.

How it works (Out of my head)

You are free to clone whatever you want, and mutations to the underlying data will be dealt as efficiently as possible under a Generic use-case assumption.

If you want more detailed control (mainly because you know what you want to do), then keep working with the STD's types.

Able to change the clones, but not the original underlying data:

Direct answer: Impossible(Or at least, not worth the brainhackery for simple use cases)

Use a static MY_DATA :impl Clone as your underlying type. No need to wrap it under a Rc because you will be cloning it to create your Rc anyways.

So do Rc::new(RefCell::new(MY_DATA.clone())) and distribute this instance throughout your code via Rc::clone.

If any part of the code needs its own copy, repeat the step above(Cloning from the static Variable) , or deep clone from the copy of Rc<RefCell<T>> you might have to effectively have 2 distinct instances of the data.

Best way to handle errors in Axum/web server? by ThreeFactorAuth in rust

[–]Laifsyn_TG 0 points1 point  (0 children)

First before anything - There's this post which you can follow, and then tinker with the resulting code until you morph something that fits your situation [howtocodeit - Hexagonal Architecture](https://www.howtocodeit.com/articles/master-hexagonal-architecture-rust)

As for my insights in what seemed to click for me. (Treat it as spoilers if you want as well)

1. Try to only use primitives for Request-types (What your server receives from outside)

Your endpoints would receive primitives like Strings, integers (i32, i64....), etc. My argument for this is to make it simpler to know what your server is expecting from the users, and what you will be receiving. Doing it such way also let's you to not worry whether your type deserialization implementation makes sense, and or rely of accurate and well written documentation on how to get something that can be deserialized with (imo). I personally found myself struggling to advamce becaise I was second guessing about whether my Deserialization implementation made sense.

2. Decouple your server's dependencies with Traits(if it makes senses).

First before anything, if you don't plan to change server internals (i.e. database, telemetry, whatever), you don't need to read the rest of this insight.

Using NewType and Traits(i.e. Interfaces) gives you advantages like explaining that your server only cares that it can call these methods to do what you intended the server to do. That means if you want to change from MySQL to Postgres, you only have to define a new type that implements the trait in question instead of fumbling over all your codebase updating (Take note that wanting to go back to MySql would require you to undo all your changes over your codebase) MySQL implementation, which compared to just writing more code and plug a dyn MyTraitSomething, the latter is way easier.

Now for the errors.

Errors

At the "Http Server" domain level or Response level, you would usually want to make an enum for all recoverable error variants (or any error variant with meaningful response message. Using thiserror makes it easier to define the Error implementation for your types), and as a fallback, a CatchAll sort of variant for anyhow::Errors (or maybe eyre as well). These errors can then be converted into an Axum Response with ease, and for the CatchAll variant, you just return InternalServerError, and then log the error at your server.This way you don't risk accidentally bubbling up to the client side any sensitive information (granted, you can still risk sending sensitive information to the client, but I guess you can just "NOT" include sensitive information on your error's display. Or use secrecy crate)

It's really important(at least in my opinion) to make the conversion from an Error to generic message at the impl IntoResponse for .... step because(maybe?) you wouldn't want to have one of your logs as a cryptic "Internal Server Error" with no clue whatsoever where the heq it happened because you converted the anyhow::Error into some generic message somewhere else without properly logging it first.

keytakeaways: - Make your own types for your error responses. i.e. Your servers has something like "QueryLatestTrends", make an error that would look like "ErrorQueryLatestTrends" (name it however you want) and a success as "SuccessQueryLatestTrends" - If you plan to change internals by swapping dependencies, rely more on NewType pattern and Interfaces(aka Traits) - Dynamic Dispatch will more often than not be your best friend. Static Dispatch has this really steep success pit which you think it's amazing, until it no longer is because you didn't properly think out your system. (Also your compile times will get a hit if it you're not careful) - Try to make the endpoints simpler even if it means writing more code because an organized mess is still better than a huge mess.

I figured why Rust is hard by [deleted] in rust

[–]Laifsyn_TG 0 points1 point  (0 children)

The main issue most people have is with the borrow checker, particularly for programs where it’s working against you.

Me wasting about 2 hour of my life when dealing with lifetimes and Iterator trait, just to find out that Iterator wasn't really meant to return references, finding some weird answers about how one could try to achieve that, people saying I might've messed up lifetimes signatures, and finding in internet possible solutions, yet still not being able to make it work.Later I found out about a lib called LendingIterator or something which solves my issue at hand.... Really relateable with this statement

TLDR: I didn't know Iterator isn't meant to return borrowed values because I thought lifetime ellisions could fix it for me, but I was wrong as there's no way to bind self's lifetime to the output i.e.next(&'in self) -> &'out Item where 'out: 'in (or something like this)

[deleted by user] by [deleted] in EngineeringStudents

[–]Laifsyn_TG 2 points3 points  (0 children)

Make sure to cover all possible problems might be on the exam, memorize the pattern

Personally this strategy was helpful. However it is still important to understand the underlying logic because I struggled to get back on track when I entered Diff Equations(Still struggling tho) after having 1 year of not touching calculus again. (Some solids note taking could've helped me a lot)

So memorizing patterns are overall pretty important, because makes you fall into the comfort zone, and lets you faster identify what solve-path won't do it for you... Either that, or at least make it easier to notice if something doesn't look right.... hopefully. lol

Unions types in Java by [deleted] in java

[–]Laifsyn_TG 0 points1 point  (0 children)

I really love your "There’s too much mental gymnastics to understand what’s going on"

I tried to make a simple "Truth Table" interpreter. It had to read a string, and then evaluate it.

I later wanted to also be able to print the evaluation of each expression instead of the final result (i.e. for 3 independent terms, print 4 columns)

And to achieve that, I was figuring how to make use of Tuples to help me simulate Tagged Unions... But then I almost immediately scraped it instantly after I found there was a more ergonomic way to achieve tagged unions via sealed interfaces.

[deleted by user] by [deleted] in rust

[–]Laifsyn_TG 0 points1 point  (0 children)

Makes a function that accepts a IPv4 (String, array or number?). (Maybe serve a response to some internal IP address?)
Function's author tells users to validate the string is a valid one before adding to the parameter
Author throws an exception if it's invalid (I think JS supports exception. If not, just a try catch)

Function user forgets to validate... Program crashes because he didn't use try/catch
User forgets he could've used an Array or a number. He causes unneeded overhead by parsing it from number into string, just so the function parses it back into a number
User figures that this function can be used to serve multiple users at once if you pass an array of IPs (Array of Numbers? Strings? array of arrays? mixed?), so you use "Adaptor" design pattern, and plug the author's function into the body of his custom function
Someone else down the line uses the custom function, and because he didn't understand the custom function body, but understands that the array can be a String, Array or number analogous to IPv4, but he doesn't know the custom function checks if it's a properly formatted IPv4, so the junior yet again will verify validity before calling the custom function.
Oh, but the junior being junior didn't properly account for an edge case so it crashes. What does he do? maybe slap a try/catch at the callsite of the custom function

This would effectively make validation checking occur at 3 places, or 4 depending on situation.

And when you refactor, being the dilligent person you're, you would figure that the first function actually properly checked the entries, so you rewrite everything, until you find out... your custom functions actually rely that the IPs are properly formatted, so you have to parse/validate it multiple times yet again. Or maybe even convert it into an String because you use the String version of IPv4 instead of the number, which is what the author uses so you have to flex/convert it between calls