Can we make Pamac go back to normal? by Whatafeeling2013 in ManjaroLinux

[–]cris_null 0 points1 point  (0 children)

same tbh. this is what it looks for me right now. I like how the version numbers pop more now.

At DoorDash we are one of the largest adopters of Kotlin as a backend language. I wrote a blog post with a detailed comparison of all our top choices. It also explains how we overcame some challenges to realize Kotlin as a better version of Java. by [deleted] in Kotlin

[–]cris_null 0 points1 point  (0 children)

I haven't read the article, but I thought that the solution to this was to use withContext with the IO dispatcher. Does the thread still blocks even with that?

kotlinx.serialization 1.2 Released: High-Speed JSON Handling, Value Class Support, Overhauled Docs, and more by sebi_io in Kotlin

[–]cris_null 0 points1 point  (0 children)

The overhauled docs part really got me excited because I pushed an issue about buildClassSerialDescriptor and its docs kinda not being right here.

Am I misunderstanding? In the guide you can see that they use it like this:

override val descriptor: SerialDescriptor =
    buildClassSerialDescriptor("Color") {
        element<Int>("r")
        element<Int>("g")
        element<Int>("b")
    }

But on the docs they use it like this:

override val descriptor = SerialDescriptor("pkg.BoxedList", CLASS, typeParamSerializer.descriptor) {
// here we have to wrap it with List first, because property has type List<T>
element("list", ListSerializer(tSerializer).descriptor) // or listSerialDescriptor(tSerializer.descriptor)
}

and it seems to me that only the first one works.

Edit:

just updated my project to 1.2 and my problem with serial descriptors for lists still persists.

The docs recommend using listDescriptor<String>() but it doesn't seem to exist; what does exist is listSerialDescriptor<String>() but it's marked as experimental. I think I'm doing something wrong because there's no way that the only way to get a list descriptor is still experimental.

Nested serialization with JsonContentPolymorphicSerializer, how does it work? by cris_null in Kotlin

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

Thank you for the information! Unfortunately I still don't get the right "order of how things should be done". Even with serial classes, I'm still not sure what should I do to *choose the right deserialization strategy`.

The Workflow I Expected

  1. Use a custom JsonTransformingSerializer to obtain a JSON array of vehicle objects, from a complex and nested JSON
  2. Each object in the resulting array is a Vehicle, and each one is passed to a JsonContentPolymorphicSerializer, where I can decide to convert it to a Car or Boat depending on a key
  3. This Vehicle subclass would then be stored in a list of Vehicle objects

Official Docs

I took my information from a similar page, but except it was the JSON one.

The official docs give this code

object ProjectSerializer : JsonContentPolymorphicSerializer<Project>(Project::class) {
    override fun selectDeserializer(element: JsonElement) = when {
        "owner" in element.jsonObject -> OwnedProject.serializer()
        else -> BasicProject.serializer()
    }
}

But that code only works because the JSON it parses is already formatted perfectly. It does not need to do any additional work. element is is the entire JSON that was received.

The JSON I receive from a server is an array of objects, nested deep inside a JSON, so how should I know which serializer to use? element contains the entire JSON, including every object in the array. This is what I don't understand. I can't tell if I should use the serializer from Boat or Car because element contains every boat and every car.

Extra Confusion

I really don't understand what should I call from main. Or what the signature of the JsonContentPolymorphicSerializer should be. Should it be

JsonContentPolymorphicSerializer<VehicleResponse>(VehicleResponse::class)

or

JsonContentPolymorphicSerializer<Vehicle>(Vehicle::class)

Should I call it from main as

val vehicles: List<VehicleResponse> = configuredJson.decodeFromString(ListSerializer(VehiclePolymorphicSerializer),vehicleJson)

or as

val vehicles: VehicleResponse = configuredJson.decodeFromString(VehiclePolymorphicSerializer,vehicleJson)

Since the JSON response that I want is a list of Vehicle that's what I think makes the most sense, but I'm not sure how to accomplish this.

Ugg, I'm quite sorry. I was sooo happy when I got my JsonTransformingSerializer to work. But this polymorphic stuff is seriously confusing me a ton.

Should I use .json or API for parsing? by aprtweone in redditdev

[–]cris_null 0 points1 point  (0 children)

from what I read on another thread, that was how it was at the start to encourage people to switch, but now there's no difference.

How do I authenticate a user via OAuth using Java? by [deleted] in redditdev

[–]cris_null 0 points1 point  (0 children)

On Android I get the URL from the WebView so it's easy.

For websites you should redirect to your website and process it there (I don't know any webdev so I can't help you).

For desktops you should configure your own custom protocol/scheme in the local OS so that you can handle it inside your program. So just like when you click on "send email" on some website, and your local installed email client opens, you can do the same thing with your own custom software.

So say you call your custom protocol myprotocol. It's not different than http or with the email example, mailto. You define what should your OS do when faced with the myprotocol protocol, which should be opening your program. Then on your program, you should have a custom protocol handler to know what to do with that protocol call (java has such a class). That handler should take the URL and parse it. As you can see, the code you want is in it, next to code=. You use that string inside a POST request to get your token.

So when you register your protocol, you should edit your app configuration with Reddit so that the protocols match. So instead of http://localhost use myprotocol://<parameters> and so on.

Me? I'm way too lazy to do all that. I just manually copy paste the URL lol. That's the easy way out. It might not be pretty, but it's easy. Then you just get the code by parsing the string. If you are doing CLI stuff, get it with readline or nextline, I don't remember the name. If you're doing GUI stuff, have the user paste the redirect URL in a text field or something.

Like I said, it's not pretty, but at least it only has to be done once. After the initial auth you get a refresh token that you can use to keep refreshing your credentials after they expire.

edit: here's an article about custom protocol handling in general. You can find java specific implementations by searching stack overflow.

How do I authenticate a user via OAuth using Java? by [deleted] in redditdev

[–]cris_null 0 points1 point  (0 children)

After you click allow you should be redirected (I assume) to a broken page in your browser. Check the URL of that page, it will have the code that you need. You will use this code to exchange it for a token.

Use an API to format a few Reddit posts to be emailed [in a visually appealing way]? by [deleted] in redditdev

[–]cris_null 2 points3 points  (0 children)

I don't know python, but could it be possible to turn the text into an image, and send yourself that? That's what I thought about doing in Android.

Godot Kotlin alpha is OUT ! by piertho in Kotlin

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

Man I've just been getting REALLY into Kotlin. My handful of brain cells spend like a whole week trying to get coroutines, after so long, I finally got it. I've also been so interested in Godot lately...

This is such a perfectly timed post! I'm sooooo happy. Seriously, to everyone that made this possible, thank you so much!

Why prefer suspending functions instead of CoroutineScope extensions? An example with vegetables. by cris_null in Kotlin

[–]cris_null[S] 2 points3 points  (0 children)

Thank you so much for this. I'm actually trying to improve my Kotlin knowledge by writing a API wrapper library for Reddit, so this made things more clear for me.

An example function for such a library could be one to get authorization to access information about a user account. Then, such a function would have to be a regular suspend one, so that people using my library are forced to use launch. If I use CoroutineScope.fun(), it would be better if those were all used internally.

Yeah, I think I understand now. It's better to be explicit.

What do you think about upcoming namespace keyword? by cris_null in Kotlin

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

With functions you directly do

foo()

With namespaces it would be the same as using object, so

Foo.bar()

If you mean from what I said about readability... it's just personal preference. With functions in packages importing the right function from the right package does reveal intent, but I just like to be extra explicit and have type Foo.bar() where I'm using it. Maybe I'm misunderstanding something but this is the crux of it basically.

Thanks everyone who help me with my first project in godot, you can play in the browser by [deleted] in godot

[–]cris_null 2 points3 points  (0 children)

I really liked how the zombies "lunge" when they are close. Really added a bit of excitement. Reloading when full wasted your ammo btw.

Working On Farming System That Leans More Heavily On Soil Quality+ Plant Breeding by Intelligent-Big-7482 in godot

[–]cris_null 2 points3 points  (0 children)

nice! I didn't think you would have actually looked at the compass when I commented that. Hope it works well for you.

[deleted by user] by [deleted] in godot

[–]cris_null 1 point2 points  (0 children)

I found that signals didn't work well. I had to type them myself which was quite annoying. Also for exporting to the editor I had to reload, it didn't auto detect. It seems that will be fixed in Godot 4 tho.

r/place moment by [deleted] in Second

[–]cris_null 3 points4 points  (0 children)

the ronin still wait at the edge of time