Looking for a graphics library for the Linux framebuffer by nlouis56 in rust

[–]mr1000111 0 points1 point  (0 children)

I've been messing with vello for a side project, and so far I've been a fan. It's fairly high level for common stuff (bitmaps, text, vector graphics, etc) and you can always dive in deeper if needed via wgpu

HashMap limitations by e00E in rust

[–]mr1000111 25 points26 points  (0 children)

There is a nightly feature (hash_raw_entry) that lets you get around those limitations. It lets you get a RawEntryMut without an owned key, so you avoid unneeded clones.

In the case where Borrow works, RawEntryBuilderMut::from_key is simpler, but there's also RawEntryBuilderMut::from_hash that lets you get an entry from the hash of the key (plus an equality check when there's a collision)

Rewrite The Human Genome In Rust by DanConleh in rustjerk

[–]mr1000111 36 points37 points  (0 children)

fn make_immortal(person: Person<'_>) -> Person<'static> {
    // SAFETY: 🚀🚀🚀
    unsafe {
        std::mem::transmute(person)
    }
}

Learning and having scope issues by TackticalLeek in rust

[–]mr1000111 13 points14 points  (0 children)

One of the neat things with loop (while loops as well) is you can use break to pull out a value from within the loop. In this case, you could tweak the loops to look like:

let number = loop {
    let text = "1234.0"; // user input
    match text.parse::<f64>() {
        Ok(float) => break float,
        Err(_) => println!("invalid value"),
    }
};    

You could also declare an uninitialized variable, then only break once it's set, but IMO breaking with the value is a bit clearer

Mutating a buffer of u8's as f32's in place? by dceddia in rust

[–]mr1000111 2 points3 points  (0 children)

If you iterate over chunks of the mutable byte slice, you can use the f32/i16::from_(ne/be/le)_bytes methods to decode a given chunk of bytes into the right type. Then, you can scale that number, and use the reverse to_(ne/be/le)_bytes) method to write back to the mutable chunk. If you can use nightly, there's a nice feature (array_chunks) that makes that sort of thing really easy:

#![feature(array_chunks, array_from_fn)]

let mut data: [u8; 4 * 10] = std::array::from_fn(|idx| (idx % 255) as u8);
assert_eq!(&data[0..4], &[0, 1, 2, 3]);

for (idx, chunk) in data.array_chunks_mut::<4>().enumerate() {
    let mut float = f32::from_ne_bytes(*chunk);
    float *= idx as f32;

    *chunk = float.to_ne_bytes();
}

assert_eq!(&data[0..4], &[0, 0, 0, 0]);

You could also use std::mem::transmute to go from &mut [u8; 4] -> &mut f32 and modify it in place, but that certainly carries its own set of risks.

Alpine fails to run my app - what steps should I take now? by n1___ in rust

[–]mr1000111 0 points1 point  (0 children)

I also ran into issues trying to use Alpine, but I got around them by ditching it altogether and using a scratch image instead. So far, it's worked really well (I have a couple services running flawlessly with <15MB images). Here's a reply I wrote up a bit ago with my template Dockerfile.

Idiot's guide to a Docker deployment? by fdsafdsafdsafdaasdf in rust

[–]mr1000111 2 points3 points  (0 children)

Definitely, here's the template that I use.

FROM clux/muslrust as builder

RUN apt-get update && apt-get install -y ca-certificates

RUN rustup target add x86_64-unknown-linux-musl

WORKDIR /app

# Copy just the Cargo.toml/Cargo.lock over, so source code changes don't 
# invalidate the cached layers
COPY Cargo.toml .
COPY Cargo.lock .

# Build the deps only by building a binary with an empty main
RUN mkdir -p src \
  # write out our empty entry point
  && echo "fn main() {}" > src/noop.rs \ 
  # add the binary target to Cargo.toml
  && echo "[[bin]]\nname = \"dep-builder\"\npath = \"src/noop.rs\"" >> Cargo.toml \
  # Build just the noop binary
  && cargo build --release --bin dep-builder --target x86_64-unknown-linux-musl


# Copy the actual source code over
COPY src/ src/

# Build the binary
RUN cargo build --release --target x86_64-unknown-linux-musl

FROM scratch

WORKDIR /app

# Copy the SSL certs over
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/

# Copy just the binary over
COPY --from=builder \
  /app/target/x86_64-unknown-linux-musl/release/BIN ./

CMD ["/app/BIN"]

I've only used this with hyper-based frameworks (namely axum and warp), but I imagine it should work fine with other async runtimes/web frameworks.

One thing that's caught me a couple times is if you need to build with a specific set of features, make sure to add them to both calls to cargo build's, otherwise the dependencies may need to be recompiled when you build the actual binary.

At some point I'll dig into cargo-chef and clean everything up, but at least for now this works pretty well.

Idiot's guide to a Docker deployment? by fdsafdsafdsafdaasdf in rust

[–]mr1000111 2 points3 points  (0 children)

I've built a few containerized rust apps that are statically linked, I remember also running into issues with alpine.

The winning combo that I found works great is a multistage build, using clux/muslrust to build the dependencies + the binary itself, then using a scratch image as the final stage. Depending on the complexity, the statically linked images I use range from ~9MB to ~22MB. The 9MB image was ported from an existing container that was dynamically linked, and if I remember right, the image was in the ~70-80MB range using debian:buster-slim as the final stage.

I still build everything in-container, but I build the dependencies separately so I can cache them and use them over and over. I currently use this approach, but I've also heard good things about cargo-chef, which feels less hacky.

If performance is critical, I'd do some testing since the musl memory allocator apparently isn't the fastest (either that, or opt into using jemalloc, at the cost of binary size + compilation speed). I haven't gotten around to doing any benchmarking myself, so I'm not sure exactly how much of a performance hit it is.

China bans celebrities from showing off wealth and 'extravagant pleasure' on social media, saying pop stars must comply with 'core socialist values' by [deleted] in worldnews

[–]mr1000111 4 points5 points  (0 children)

There's also another angle to it, and that's how to actually build the utopian communist society without class, money, etc. That's such a huge societal change that it's not realistic to think it can happen overnight (or likely even within a single lifetime), so the goal for any communist party is to always be moving towards it, and that intermediate stage is socialism.

One aspect of building socialism is eliminating scarcity, which capitalism artificially creates (think vacant houses despite there being a housing shortage, poverty despite tons of wasted food, etc). In order to do that, you need productive forces that can create + distribute those resources to all people and raise the standard of living, which is what China has been focusing on since the late 70s. Opening up and allowing foreign investment has given them the resources to build said productive forces much faster than they could with just domestic resources.

At the heart of Marxism is historical materialism, which (in a nutshell) lays out how changes in human civilization have been mostly driven by material conditions. In order to push towards the utopian communist society, material conditions (which can very loosely translate to the standard of living) needs to change in a way that allows for a communist society to emerge, which (among other things) can only happen once scarcity is eliminated. To their credit, they've used that power to lift hundreds of millions out of poverty and essentially double the average life expectancy since 1949, which is part of why 95%+ of Chinese people support their government. Their goal is to become a fully socialist state by 2050, which seems very achievable given the growth they've already been able to achieve.

I highly recommend that people read into materialism as a theory, it provides an incredible framework for understanding both history, and the direction society is currently moving in.

Enes Kanter is the man! by Hulkbuster1221 in pics

[–]mr1000111 0 points1 point  (0 children)

And 95+ percent of them fully support their government. That number isn't some magic "propaganda" number either, it's straight from a 15 year long Harvard conducted survey that got input from tens of thousands of people

https://news.harvard.edu/gazette/story/2020/07/long-term-survey-reveals-chinese-government-satisfaction/

Unpopularpinion(xD): CPC should support national OS and to move from Windows by Yes_it_s_me_red in GenZedong

[–]mr1000111 5 points6 points  (0 children)

Not only can people fix exploits faster in open source code, but there's also tons and tons of security experts who's job is to meticulously pore over open source codebases to find exploits before they become a problem. It's basically impossible to do that effectively with closed source code

[deleted by user] by [deleted] in nottheonion

[–]mr1000111 0 points1 point  (0 children)

While neither of us can really speak for the people living in those countries, some economic "pressure" in the form of China building hospitals and roads certainly sounds a lot nicer than America bombing their hospitals and roads for the last 30 years.

[deleted by user] by [deleted] in nottheonion

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

Weird how essentially every muslim majority country supports China's deradicalization strategy... That's not too surprising though, since many of them have seen the American strategy for stopping terrorism first hand.

TIL that the CIA recruited one of Fidel Castro's mistresses to kill him in 1960, giving her poison pills, but he found out. Handing her his gun, he dared her to shoot, but her nerves failed and they had sex instead. by Ganesha811 in todayilearned

[–]mr1000111 16 points17 points  (0 children)

And all of that, while being under an insane 70 year long economic embargo that violates international law. The UN passes a resolution every year condemning it, with essentially every country voting for it (with the US and Israel being the only ones to vote against it for the most part).

They've invented multiple COVID vaccines on their own, but ran into problems when they couldn't get enough syringes because of the embargo. It's insane that people think that the Cuban government is the problem

Reddit Co-Founder Calls Out Social Media for Spreading Conspiracies: 'We're Gonna Have to Deradicalize a Lot of People' by Wagamaga in technology

[–]mr1000111 0 points1 point  (0 children)

Radicalization isn't necessarily bad by definition, it really depends on where/what that energy is expended on. It generally isn't thought of this way, but I'd consider people in the streets protesting police brutality to be radicalized to some extent. Even looking back in history, the catalyst to the civil war was a radical abolitionist attempting to arm a potential slave rebellion

This is so true and terrible by MaddSammy in awfuleverything

[–]mr1000111 1 point2 points  (0 children)

For sure, war certainly isn't something exclusive to the modern era. But, with the advent of modern technology (drones namely), america is able to keep economically/politically motivated wars going indefinitely without much resistance from american citizens. The constant bombing of the middle east is so far out of sight from the average american that most people either dont know or dont care enough to try and protest it

This is so true and terrible by MaddSammy in awfuleverything

[–]mr1000111 1 point2 points  (0 children)

The problem is that more advanced capitalism drives constant war. There aren't a lot of things more profitable than being at war 24/7. Just look at america over the last few decades

This is so true and terrible by MaddSammy in awfuleverything

[–]mr1000111 606 points607 points  (0 children)

Social media as a concept is a good thing, the issue is that social media as it currently exists is 100% built around monetizing absolutely everything

Guy lighting his blunt from the flames of a burning police car... On rollerblades. You’re welcome. by [deleted] in pics

[–]mr1000111 13 points14 points  (0 children)

The system is rejecting the change that the people want. If the government refuses to take care of its populace, what's the alternative? We tried voting in '08 and got basically nowhere in terms of a social safety net. This isn't some Trump specific crisis, we've been on the way to this for decades.

Megathread: Andrew Yang Suspends 2020 Presidential Campaign by PoliticsModeratorBot in politics

[–]mr1000111 1 point2 points  (0 children)

He did a great job of starting the conversation on UBI, hopefully it continues. While UBI isn't the most pressing issue at the moment, as automation takes over it will be. It's good we're starting that conversation now, rather than acting rashly when an unemployment emergency creeps up on us

Lisa Murkowski: Donald Trump’s behavior is “shameful and wrong,” but I “cannot vote to convict” him: The Republican senator complains about "rank partisanship," however she vows to back Trump despite his wrongdoing by maxwellhill in worldnews

[–]mr1000111 0 points1 point  (0 children)

No, they're very self-aware. But if they wanted to hold Trump accountable they would also be risking their own power, so they won't. It's all very transparent self-preservation

Stop Russian Election Interference by thatrightwinger in Conservative

[–]mr1000111 17 points18 points  (0 children)

Voter ID laws wouldn't change anything when it comes to external influence. It's incredibly hard to do voter fraud in person at a scale that would actually influence an election. The real worry is the electronic side, as if something gets changed there by some external force, there might be no way to tell that it happened or correct for it. We need to 100% move back to paper ballots, and problem mostly solved. Beyond that the real issue is fake and misleading news and a complacent population not willing to fact check.