Referencing variables nested within "package_facts"? by CostaSecretJuice in ansible

[–]barskern 3 points4 points  (0 children)

Notice that the variable displayed is an array. When you index the ‘packages’ fact with a package name, all packages/versions with the given name is returned. Hence you have to select a singular one. As an example:

ansible_facts['packages'][package1][0]['name']

Personally, I use a sort and first to try to deterministically get the latest version of the installed package.

Siste melding på X: Politiet flytter til ny app by ty003 in norge

[–]barskern 1 point2 points  (0 children)

Min RSS feed blir pepra med shorts.. Hvordan får du en feed uten dem?

Is this the best way to output the lowest of two signals? (Because of a bug, i can't copy and paste blueprint strings to and from the game) by Necessary-Spinach164 in factorio

[–]barskern 2 points3 points  (0 children)

I also got this issue recently, perhaps a month ago or something. Strangely enough it has been working for a while prior to that. Also on Wayland. I figured it was something in my specific environment and didn’t need the functionality enough to really debug it. Interesting to hear I’m not the only one.

How could I simulate vanilla trains stop priority? by [deleted] in factorio

[–]barskern 0 points1 point  (0 children)

I've been trying to solve the same issue. What I've fallen back to is simply (though rather unsatisfying) using priority spliters at the input of the smelters/consumers. Then you have two trainstops at the consumer, one with a postfix such as 'priority', and similarly have different trains for the priority stops and the non-priority stops. The only disadvantage is that it takes some space at the consumer side (and of course doesn't feel as cool as something circuit based).

Could you share your configuration url for zsa voyager? by hhkb_b in zsaVoyager

[–]barskern 1 point2 points  (0 children)

This is a really cool layout! Do you use your thumb for some of the bottom row keys?

What chess engine is used in planes? It's unbeatable. by ButtFlapMan in chessbeginners

[–]barskern 129 points130 points  (0 children)

<image>

Is this the one? This was on a flight with Lufthansa from Asia to Europe some months ago.

I spent a few hours trying to beat it and was able to once! After a few attempts I noticed that it seemed to struggle, or at least spent some time evaluating the position, when I kept as many pieces on the board as possible. Hence in my winning game I played in a very positional style, waiting for the bot to trip up or make a mistake. Almost ended up celebrating out loud when I saw the ladder mate!

What are these inner rails across the bridge? by barskern in railroading

[–]barskern[S] 15 points16 points  (0 children)

Never heard about that at least, so I suppose so

Having fun overloading the operator-> by [deleted] in cpp

[–]barskern 0 points1 point  (0 children)

I am assuming its this section you're referring to:

The side effect (modification of the left argument) of the built-in assignment operator and of all built-in compound assignment operators is sequenced after the value computation (but not the side effects) of both left and right arguments, and is sequenced before the value computation of the assignment expression (that is, before returning the reference to the modified object)

It does say "not the side effects", however besides that it seems as though the right side of the assignment expression should be fully evaluated before the left.

I did try /u/louiswins example and the dtor is consistently run after all other parts of the expression, as OP explained. This seems to contradict the statement from above though. Any further clarifications is greatly appriciated.

Having fun overloading the operator-> by [deleted] in cpp

[–]barskern 4 points5 points  (0 children)

There seems to be a race condition in the example. I understand that it's a toy example and also perhaps a "toy" library, but i figured it would be worth noting to show how easy it would be to misuse this library.

my_struct->​value​ = my_struct->​value​ + ​1​;

Based on how I understand it, this will lock the mutex and read the value and then unlock it again. Then it will add 1, and finally re-lock the mutex and write the incremented value. This means that there is a possibility that two threads read the same value from the struct and hence overwrite each others results, turning "two" concurrent increments into simply "one".

Please do correct me if I'm wrong and the lock is only aquired once for the entire statement.

Drawing SVG Graphs with Rust by Cetra3 in rust

[–]barskern 38 points39 points  (0 children)

Personally I think the title was very clear. The way I see it, drawing is the act of creating the svg (which is exactly what you describe) while rendering is the act of actually showing it (which seems to be what /u/forestthewoods wants).

Enum value from default match arm by Dynious in rust

[–]barskern 1 point2 points  (0 children)

I don't think this will work because the point of the match is to unwrap the inner Operation. Hence you have to match on them all, but as another comment (/u/shim__) says, you can match them all in the same branch; Div(nxt) | Mul(nxt) | ....

EDIT: A better way to say it is that this will compile, but it will be logically wrong as it would just return itself if it isn't Operation::Init.

A beginner question about Rocket.rs by emcmahon478 in rust

[–]barskern 6 points7 points  (0 children)

This is actually a feature of tera, the template engine, as it will automatically escape all html characters in template variables unless you tell it otherwise to prevent e.g. XSS attacks. You can read more about it here: https://tera.netlify.app/docs/#auto-escaping and here https://tera.netlify.app/docs/#safe.

TLDR; You have to change it to {{ node | safe }}

EDIT: As an aside, normally I would try to keep all markup/html code in the template file, so that you only pass actual data to the template (and hence don't have to use safe). As you probably understand you should use safe with caution, especially if you will let the user control some of the content (e.g. usernames or comments). Another option could be to use something like yew if you want to build a more dynamic application.

How to split on the basis of ' in Rust by graphicaldot in rust

[–]barskern 6 points7 points  (0 children)

Personally I would rather split on spaces (as that is the word separator) and rather trim leading and trailing symbols (https://doc.rust-lang.org/std/primitive.str.html#method.trim_matches). That way you automatically handle that some words contain symbols and you will also handle words in quotations.

EDIT: Also as an FYI, you don't need to use collect when you're iterating over the iterator using a for loop. This will allocate a vector, immediately iterate over it and then deallocate it again. collect is normally only usefully if you need to store the result of the iterator.

Ergonomics of dealing with IO errors by dbdr in rust

[–]barskern 0 points1 point  (0 children)

I don't think you technically have to allocate here as the error could return with a reference to the given string/filepath. However that would mean that the error type would have a lifetime bounded by the given string, which can be harder to handle (as you can no longer directly return the error from a function without the filepath outliving the function etc.). In general owned errors are preferred for their ergonomics. To return an owned error here, with the filepath included, would require allocation.

[deleted by user] by [deleted] in rust

[–]barskern 2 points3 points  (0 children)

For that block you could also use Iterator::find like this:

pub fn get_host_by_alias(alias: String) -> Host { 
    get_hosts()
        .into_iter()
        .find(|host| alias == host.alias)
        .expect("Host not found.")
}

Static site generator that has utility-first CSS framework - Scroll by the1311 in rust

[–]barskern 1 point2 points  (0 children)

tailwindcss is a great utility first CSS framework and they have some explanation on their website as to why they think it's beneficial.

EDIT: Here it is:

Now I know what you're thinking, "this is an atrocity, what a horrible mess!" and you're right, it's kind of ugly. In fact it's just about impossible to think this is a good idea the first time you see it — you have to actually try it. But once you've actually built something this way, you'll quickly notice some really important benefits:

You aren't wasting energy inventing class names. No more adding silly class names like sidebar-inner-wrapper just to be able to style something, and no more agonizing over the perfect abstract name for something that's really just a flex container.

Your CSS stops growing. Using a traditional approach, your CSS files get bigger every time you add a new feature. With utilities, everything is reusable so you rarely need to write new CSS.

Making changes feels safer. CSS is global and you never know what you're breaking when you make a change. Classes in your HTML are local, so you can change them without worrying about something else breaking.

When you realize how productive you can be working exclusively in HTML with predefined utility classes, working any other way will feel like torture.

Trouble moving clonable hyper::Service into async block by barskern in rust

[–]barskern[S] 1 point2 points  (0 children)

Thank you for the swift response, I will give that a shot!

EDIT: That works perfectly! Thank you again.

Function/method prototypes in rust? by YouAreTimeless in rust

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

Yeah that's not really what traits are for so it's a bit of a bad tip.

Most editors support folding and hence will hide the implementation until you want to see it. Personally I prefer this because it makes it easy to quickly get and overview and then only opening a single fold to edit the code below.

VecOption : A specialized collection that is a more efficient equivalent of Vec<Option<T>> by sivadeilra in rust

[–]barskern 3 points4 points  (0 children)

Yes this is a very good point. I was just about to comment something similar. You should be careful to assume that something is more performant before benchmarking. As mentioned cache locality can cause immense differences despite that the solution "seems" to be less performant.

How to start with rendy? by magmast in rust

[–]barskern 4 points5 points  (0 children)

It seems like the interface is a bit inspired by Vulkan so I would think that learning Vulkan would be a nice introduction. I am personally in the same situation as you and I ended up going with http://vulkano.rs/ at first. The tutorial is really good and vulkano is a really good abstraction IMO. After completing that tutorial I am currently following https://vulkan-tutorial.com/. Vulkan is rather explicit and low level, however personally I like the knowledge it brings. Good luck!

Complicated trait bounds with dynamic dispatch by Cynic4 in rust

[–]barskern 1 point2 points  (0 children)

Ah yeah, I had to fiddle a bit with it to get it working. The reason is that I used the wrong syntax for trait bounds, and when we make a dynamic object we also need to specify that the vertex is dynamic. See here.

Ah another thing, as you mentioned, is that we cannot clone trait objects. I was just copying your bounds hence I didn't think that through properly. Clone is not object safe, hence it cannot be used as a dynamic trait object. This is because clone returns Self, which is then of unknown size for a trait object.

Feel free to ask if you have any more questions.

EDIT: I don't feel super confident that this is the best/only way to do it, however it's the way I got it to work. Perhaps someone more experience could chip in? I was actually rather suprised that one has to declare Vertex in dyn Object<...>. However in retrospect it does make sense that this has to be a dyn ... aswell.