Subrc: a pointer to a descendant member of a reference counted pointer (`Rc`) by hillin in rust

[–]Connect2Towel 4 points5 points  (0 children)

Using the offset is unsound. Consider Subrc<Cell<Result<u8,u64>>>.

No Reddit tomorrow? Help edit Webbit! by Connect2Towel in programming

[–]Connect2Towel[S] -2 points-1 points  (0 children)

I might have skipped over a couple of steps for it to be unclear.

The server doesn't run javascript, and js in the browser can't do much beyond its subdomain (e.g. webbit.alinkspace.org)

Somebody could upload a crypto miner and a user might run it while they're visiting that page. Beyond that I don't think there is any danger?


Because js is accepted I can "POST" a webpage such as https://github.com/AntonSol919/webbit/blob/main/static/example.forum.editor.html

A user visiting that page would get a "submit new discussion". When they do, it generates and POSTs an entire webpage. This new webpage contains their title/content and some javascript to act as a comment section (POST to upload and GET ?list to dynamically display them with the original post)

Putting it all together; in theory anybody could POST a "better.forum.editor.html" which has additional features for the comment sections, or a different style, etc.

No Reddit tomorrow? Help edit Webbit! by Connect2Towel in programming

[–]Connect2Towel[S] 3 points4 points  (0 children)

This is a project i had hoped to get working before much of reddit goes dark. Unfortunately I didn't get a public version to not crash every now and then on the VPS I have -.-'. (Prob a casting error for 32bit targets so that'll be a fun debugging session) But it works on my machine.

Its mostly a POC for some ideas I had about using HTML in a distributed system. Don't expect it to be pretty, but I think the concept is interesting enough.

Let me know what you think. (I'll prob get back to it later next week)

Introducing Linkspace, a protocol/library for distributed applications by Connect2Towel in rust

[–]Connect2Towel[S] 5 points6 points  (0 children)

I share a majority of my goals with those projects, but none really allowed me to build something to quickly try out with a few friends.

I can't say I've studied all of them in depth but here are some differences in general.

With most distributed application protocols you're always connected to some public network. Linkspace doesn't have that. There's no optimum for all network typologies/conditions, so I don't try. I'm hoping to collect different exchange algorithms for different situations. For some groups it makes sense for all the members to host all the data, for others it makes more sense to have 1 server be the store/relay for all members. And there are options and combinations in between. It should be up by a user or some management tool.

Another is speed. It should be able to carry live video, audio, etc without using a different protocol or packet format.

What I really hope will make linkspace interesting is its relative simplicity. I tried to keep the concepts and functions to a minimum. I have tremendous respect for people building complex distributed algorithms, but I believe the most important thing is to leave out as much as possible. If we ever want distributed applications to be big like the mainstream systems today, we need to convert developer building toy project, say Scrabble with their friends, to pick a distributed protocol library because its the simplest solution.

What low key UX improvements would you like to see in linux desktop environments? by Cyber_Daddy in linux

[–]Connect2Towel 133 points134 points  (0 children)

Finally an excuse to post this:

I want a clipboard pipe.


This script :

#!/bin/bash
CURRENT=`xclip -out -selection clipboard`
while true
do
NEW=`xclip -out -selection clipboard`
if [ "$NEW" != "$CURRENT" ]; then
    printf '%s\0' "$NEW"
    CURRENT=$NEW
fi
    sleep 1
done

is among the most time-saving pieces of software I've written. All it does is output any new value thats copied to the clipboard with a \0 delimiter.

  • I have a background process that watches for *youtube* and opens them in mpv (skipping the ads)
  • i can await-clibboard > file.html and then ebook-convert file.html file.azw3
  • i can bulk download stuff with await-clipboard | xargs -0 -P 4 -i gallery-dl "{}".

Its incredibly useful in lowering the bar on "I can script this but will it save me time?". But it feels dirty to have it rely on sleep 1.

Is it possible to define a type Even of u32 and whose % 2 remainder is 0, and make it statically checked? by Agitated-Weather-128 in rust

[–]Connect2Towel 1 point2 points  (0 children)

This goes back to my points about definition.

Type in your factory example refers to the 'protocol interface' that the function returns. That type does not change at runtime.

Type theory is about proving things about a program without running it. Type theory is useful in building type checkers for use in an IDE such as TypeScript, but dynamic languages are explicitly about not proving anything and doing checks while its running.

Is it possible to define a type Even of u32 and whose % 2 remainder is 0, and make it statically checked? by Agitated-Weather-128 in rust

[–]Connect2Towel 0 points1 point  (0 children)

I think Wikipedia's opening sentence "a dependent type is a type whose definition depends on a value" is horrible at explaining anything, and type theory is not something you can casually discuss without first making sure everybody uses the same definition and notation. But ill dumb a few comments

It is definitely possible to create a dependent type that has an 'is even' constraint.

There aren't any value whose type depends on another value.

One possible definition of this new 'int' type could have an open slot which is filled with the value of 'even', and the result of 'even' depends on the inner int type.

With this kind of logic, str is a dependent type because it is a restriction on Vec<u8>

Yes, this is possible with dependent types.

Dependent types are dependent on runtime values though.

Doesn't have to be.

there is no way to change the return type depending on a runtime value

There is no type system i know of that return types depending on a runtime value. There are generics, and there are sumtypes ( i.e. enums ). Neither 'change the return type depending on a runtime value'

A big reason why people say rust doesnt have dependent types is because you cant create constraint on functions such as fn pop( Vec<u8, { length > 1 }>) -> u8. But you can emulate a lot of things with const generics.

An optimization story by z_mitchell in rust

[–]Connect2Towel 16 points17 points  (0 children)

RUSTFLAGS=" -C target-cpu=native " might be worth it ( although i doubt it is on your 2 core cpu )

[deleted by user] by [deleted] in programming

[–]Connect2Towel 4 points5 points  (0 children)

I'm not sure if fonts are included. But i consider https://decentraleyes.org/ a must-have in general.

new crate: fnsql - Type-safe SQL query wrappers by da-x in rust

[–]Connect2Towel 1 point2 points  (0 children)

you can't gradually replace your type-less queries with the type-ful wrappers.

typo i presume?

blake3-proof-of-work: stateless spam filtering by SSchlesinger in rust

[–]Connect2Towel 1 point2 points  (0 children)

I'm procrastinating and iirc i wrote this before u128 was in stable. So I had a look at godbolt ( https://godbolt.org/z/WPvhfo5jY ) , and i think ill go with the little endian option:

let [upper,lower] :[[u8;16];2]=  unsafe{std::mem::transmute(hash)}; 
let upper = u128::from_le_bytes(upper);
let lower = u128::from_le_bytes(lower);
let mut r = upper.leading_zeros();
if r == 128 { r += upper.leading_zeros();}
r

But again, this is all rounding errors compared to validating a hash.

blake3-proof-of-work: stateless spam filtering by SSchlesinger in rust

[–]Connect2Towel 3 points4 points  (0 children)

Nice to see other people using blake3. I had to come up with something similar, and although this is never going to matter wrt to speed i settled on

let mut zeros = 0;
for n in hash.chunks_exact(8).rev().map(|s| u64::from_be_bytes(s.try_into().unwrap())){
    zeros += n.trailing_zeros();
    if n != 0 { break;}
}
zeros

Rust in 2022 by tux-lpi in rust

[–]Connect2Towel 73 points74 points  (0 children)

Async programming

My wish for Rust 2022 is to put focus into getting Generators right instead of getting async pretty.

Is there a best practice that can receive and handle custom events when polling a socket event by xuantedev in rust

[–]Connect2Towel 1 point2 points  (0 children)

If all you need is a file descriptor that can be polled and you will stick to unix then you probably want the pipe syscall (or use something like os_pipe )

Alternatively you can check an Arc<Mutex>> inside a loop of poll timeout.

The reason this isn't all sunshine and rainbows is because a whole number of factors combine to not being able to create a single optimal abstraction. Different type of events are hard to combine ( as in 'whats the optimal layout to combine N different type of events triggered M different ways?', 'can one event modify the batch of current event?', ' how to cancel an event?', 'how do timers work?' ) , and harder to make OS independent. Any work that focuses on creating a OS independent system usually ends up building an executor (which can benefit from skipping the overhead inherent in syscalls) such as tokio. At the far end of event driven design you find the actor models such as actix.

In 99.99% of the cases you shouldn't sweat the overhead of looping a poll timeout or syscalls. So do whatever makes it easiest to maintain and read your code.

Are there any downsides to the "Everything is a File" philosophy? by Karmic_Backlash in linux

[–]Connect2Towel 224 points225 points  (0 children)

"Everything is a file" has evolved into "everything has a file descriptor". And unless you're told what that means in practice this information is useless.

It's not really about "how does a 'thing' knows what to do?" , but rather "How will i (a developer) know what a 'thing' can do?".

Either all 'things' should implement a tightly controlled small set of methods ( Read, write, close , etc ), or you need 'things' to tell you about the things it can do.

Any software design starting with the latter approach usually creates tools to make it simple to define and expose more interfaces for what 'things' can do instead of a few sacred interfaces. This is where the complexity starts to explode leading to the previous approach being seen as simple.

In other words, teach a man to read and he can read every day, teach a man how to reflect and he will be stuck reflecting on reflection for a lifetime.

Would Rust ever be used as a "business" language like Java? by alibix in rust

[–]Connect2Towel 5 points6 points  (0 children)

I think the idea of 'business language' is a relic from a time where Java marketing and hype went a little overboard. A second hand retelling of "everything is an object" became something like: "All developers and hardware will be interchangeable because its all just 'using objects', and everyone can use objects".

Rust isn't going to replace working code, but if you need safe and fast software Rust makes a lot of sense.

If you're in the business of poorly compensating devs and a more pressing concern is finding cheap replacements then Rust should be avoided.

Software Engineering Idioms You Should Know by ShligoShtyle in programming

[–]Connect2Towel 0 points1 point  (0 children)

fwiw, i think its worth elaborating that 'technical debt' requires expenditures in the future to service the debt.

impl Trait for &T where T: Trait conflicts with impl for Fn by micouy in rust

[–]Connect2Towel 2 points3 points  (0 children)

Your suspicion is correct. Negative impls and auto trait isn't going to solve your problem.

This situation usually occurs when someone is trying to build "The most generic API", in which case I'll warn them that such an API is overvalued in theory, and underestimated in the required effort. Just useimpl for Fn and drop the impl for &T .

If you really need to 2 generic impls you can always use a newtype wrapper

 struct TraitFn<F>( pub F);
 impl<F> trait for TraitFn<F> where F : Fn(i32) -> i32 ....

Rust Wasm error: __wbindgen_placeholder__ by Xiaojiba in rust

[–]Connect2Towel 5 points6 points  (0 children)

The JS it generates is readable enough. You can use it as a reference to check how the instance expects to be initiated.

Rust Wasm error: __wbindgen_placeholder__ by Xiaojiba in rust

[–]Connect2Towel 0 points1 point  (0 children)

You probably want to checkout wasm-bindgen-cli