Searching yarn

Twts matching #lang
Sort by: Newest, Oldest, Most Relevant

Okay, here’s a thing I like about Rust: Returning things as Option and error handling. (Or the more complex Result, but it’s easier to explain with Option.)

fn mydiv(num: f64, denom: f64) -> Option<f64> {
    // (Let’s ignore precision issues for a second.)
    if denom == 0.0 {
        return None;
    } else {
        return Some(num / denom);
    }
}

fn main() {
    // Explicit, verbose version:
    let num: f64 = 123.0;
    let denom: f64 = 456.0;
    let wrapped_res = mydiv(num, denom);
    if wrapped_res.is_some() {
        println!("Unwrapped result: {}", wrapped_res.unwrap());
    }

    // Shorter version using "if let":
    if let Some(res) = mydiv(123.0, 456.0) {
        println!("Here’s a result: {}", res);
    }

    if let Some(res) = mydiv(123.0, 0.0) {
        println!("Huh, we divided by zero? This never happens. {}", res);
    }
}

You can’t divide by zero, so the function returns an “error” in that case. (Option isn’t really used for errors, IIUC, but the basic idea is the same for Result.)

Option is an enum. It can have the value Some or None. In the case of Some, you can attach additional data to the enum. In this case, we are attaching a floating point value.

The caller then has to decide: Is the value None or Some? Did the function succeed or not? If it is Some, the caller can do .unwrap() on this enum to get the inner value (the floating point value). If you do .unwrap() on a None value, the program will panic and die.

The if let version using destructuring is much shorter and, once you got used to it, actually quite nice.

Now the trick is that you must somehow handle these two cases. You must either call something like .unwrap() or do destructuring or something, otherwise you can’t access the attached value at all. As I understand it, it is impossible to just completely ignore error cases. And the compiler enforces it.

(In case of Result, the compiler would warn you if you ignore the return value entirely. So something like doing write() and then ignoring the return value would be caught as well.)

​ Read More

fn sub(foo: &String) {
    println!("We got this string: [{}]", foo);
}

fn main() {
    // "Hello", 0x00, 0x00, "!"
    let buf: [u8; 8] = [0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x00, 0x00, 0x21];

    // Create a string from the byte array above, interpret as UTF-8, ignore decoding errors.
    let lossy_unicode = String::from_utf8_lossy(&buf).to_string();

    sub(&lossy_unicode);
}

Create a string from a byte array, but the result isn’t a string, it’s a cow 🐼, so you need another to_string() to convert your “string” into a string.

I still have a lot to learn.

(into_owned() instead of to_string() also works and makes more sense to me, it’s just that the compiler suggested to_string() first, which led to this funny example.)

​ Read More
In-reply-to » So I was using this function in Rust:

@lyse@lyse.isobeef.org Rust is so different and, at the same time, so complex – it’s not far fetched to assume that I simply don’t understand what’s going on here. The docs appear to be clear, but alas 
 is it a bugs in the docs? Is it a lack of experience on my part? Who knows.

By the way, looks like there was a bit of a discussion regarding that name:

https://github.com/rust-lang/rust/issues/120048

​ Read More

So I was using this function in Rust:

https://doc.rust-lang.org/std/path/struct.Path.html#method.display

Note the little 1.0.0 in the top right corner, which means that this function has been “stable since Rust version 1.0.0”. We’re at 1.87 now, so we’re good.

Then I compiled my program on OpenBSD with Rust 1.86, i.e. just one version behind, but well ahead of 1.0.0.

The compiler said that I was using an unstable library feature.

Turns out, that function internally uses this:

https://doc.rust-lang.org/std/ffi/struct.OsStr.html#method.display

And that is only available since Rust 1.87.

How was I supposed to know this? đŸ€šđŸ«©

​ Read More
In-reply-to » Heute auf dem Heimweg roch es leicht gĂŒllig vom Stadtrand her. Is denn all wedder GĂŒlletied? đŸ„đŸ–đŸ’©đŸšœđŸ€ą https://m.youtube.com/watch?v=STPvOxUDekU

@arne@uplegger.eu Das ist ein recht zuverlĂ€ssiger Wetterbericht. Wenn die Bauern mit ihren GĂŒllefĂ€ssern hier vorbeifahren, weiß ich sofort, dass Regen angekĂŒndigt ist. :-)

Ha, das Lied gefĂ€llt mir außerordentlich gut! \o/ Mit Abstand das beste GĂŒllelied. Ich kenn noch ein paar schwĂ€bische, aber die gehen lang nicht so ab wie dieses hier.

​ Read More
In-reply-to » I watched two squirrels this morning for about half an hour: https://lyse.isobeef.org/eichhoernchen-2025-03-11/ They were super crazy fast. Also, they bit off plenty of twigs and carried them around, not sure where they put them. I've never seen them do that before. Once more I realized that I need a better zoom.

@eapl.me@eapl.me @arne@uplegger.eu @andros@twtxt.andros.dev Thanks mates!

Hmmm, Eberhardt. Ist das eine plattdeutsche Sache? Dass ich den flinken Nagern so lang zuschauen konnte, war ein seltener GlĂŒcksfall. Normalerweise sind die nach fĂŒnf oder spĂ€testens zehn Minuten wieder aus dem Sichtfeld verschwunden.

​ Read More
In-reply-to » Hacer software cĂłdigo opensource es desafiante y paulatinamente desgasta a su autor. Todo comienza con pasiĂłn y entusiasmo, por supuesto. Si logras repercusiĂłn, te enfrentas a una carrera de fondo que muchos terminan abandonando por las demandas constantes de usuarios que, a menudo, no valoran el trabajo ni contribuyen de manera significativa. Por mencionar un caso reciente: Hector Martin. LĂ­der del proyecto Asahi Linux, quien dedicĂł años a adaptar Linux para los procesadores Apple Silicon, un logro tĂ©cnico impresionante. Sin embargo, terminĂł renunciando debido a la presiĂłn de usuarios que exigĂ­an soporte y mejoras como si fueran clientes pagos.

[lang=es] definitivamente es una buena llamada de atención para promover más donaciones a proyectos opensource. La verdad apoyo menos proyectos de los que ‘debería’, por el valor que me ofrecen.

Una opiniĂłn pragmĂĄtica es que hay la libertad de no pagar, pero tambiĂ©n esto nos deberĂ­a llevar a que tenemos la libertad de SÍ reconocer los proyectos que nos dan valor, por medio de un donativo puntual o constante. Adaptarnos al contexto de lo que estamos ofreciendo.

Mi chava trabaja en Asociaciones Civiles (tipo OSALs/ONGs) y es un reto pedir donativos, por lo que es comĂșn pedir ‘Cuotas de recuperaciĂłn’ pues ayudan a valorar mĂĄs el servicio, y a que fluya el donativo. Creo que se puede hacer algo asĂ­ en el cĂłdigo libre, apelando a diferentes motivadores en los usuarios.

​ Read More
In-reply-to » lang=en @xuu gotcha! From that PR #17 I think it was reverted? We could discuss about metadata later this month, as it seems that I'm the only person using it.

it seems to be confused with the subject right next to it.. it works better at the end of the twt string.
Yarn won’t display anything. but the parser does add it to the AST in a way that you can parse it out using twt.Attrs().Get("lang")

https://git.mills.io/yarnsocial/go-lextwt/src/branch/main/ast.go#L1270-L1272

https://git.mills.io/yarnsocial/go-types/src/branch/main/twt.go#L473-L478

​ Read More

lang=en @xuu@txt.sour.is gotcha!
From that PR #17 I think it was reverted? We could discuss about metadata later this month, as it seems that I’m the only person using it.

I’ve added a [lang=en] to this twt to see current yarn behaviour.

​ Read More
In-reply-to » @eapl.me There are several points that I like, but I want to highlight number 7. https://text.eapl.mx/a-few-ideas-for-a-next-twtxt-version #twtxt

For point 1 and others using the metadata tags. we have implemented them in yarnd as [lang=en][meta=data]

​ Read More

Heute waren das Ziehkind und ich zwei Stunden lang auf drei SpielplĂ€tzen und quer durch die Stadt unterwegs. Ein riesiger Spaß!
Vorab habe ich im hiesigen Spielzeugladen ein Konvolut von Klemmbausteinen erstanden, welche wohl zu einer Polizeistation gehörten!?

Image

​ Read More
In-reply-to » (#mp6ox4a) @cuaxolotl Ah, thanks for reporting back! Okay, so you’re basically manually “crawling” feeds right now. đŸ€” What do you think about the idea of adding something like # follow_notify = gemini://foo/bar to your feed’s metadata, so that clients who follow you can ping that URL every now and then? How would you even notice that, do you regularly read your gemini logs? đŸ€”

@movq@www.uninformativ.de @prologic@twtxt.net Hey! I may have found a silly trick to announce my following to people hosting their feeds on the Gemini space using the requested URI itself instead of relaying on the USER Agent 😂. I’ve copied my current feed over to my (to be) Gemlog for testing. And if I do a jenny -D "gemini://gem.aelaraji.com/twtxt.txt?follower=aelaraji@https://aelaraji.com/twtxt.txt" and this happens:

A) As a follower, I get the feed as usual.
B) As the feed owner, I get this in logs:

hostname:1965 - “gemini://gem.aelaraji.com/twtxt.txt?follower=aelaraji@https://aelaraji.com/twtxt.txt” 20 “text/plain;lang=en-US”

You could do the same for Gopher feeds but only if you want to announce yourself by throwing in an error in their logs, then you’ll need a second request to fetch the feed. jenny -D "gopher://gopher.aelaraji.com/twtxt.txt&follower=aelaraji@https:/aelaraji.com/twtxt.txt" gave me this :

gopher.aelaraji.com:70 - [09/Sep/2024:22:08:54 +0000] “GET 0/twtxt.txt&follower=aelaraji@https:/aelaraji.com/twtxt.txt HTTP/1.0” 404 0 “” “Unknown gopher client”

NB: the follower=... string won’t appear in gopher logs after a ? but if I replace it with a + or a & and it works. There will be a missing / after the https:. Probably a client thing.

​ Read More
In-reply-to » @prologic well, I think OP mother tongue isn’t English, so certainly not an encoding I might be familiar with.

@bender@twtxt.net I’m using both machines in English.

Checked my locale and it spits out:

LANG=en_US.UTF-8
LC_CTYPE=“en_US.UTF-8”
LC_NUMERIC=“en_US.UTF-8”
LC_TIME=“en_US.UTF-8”
LC_COLLATE=“en_US.UTF-8”
LC_MONETARY=“en_US.UTF-8”
LC_MESSAGES=“en_US.UTF-8”
LC_PAPER=“en_US.UTF-8”
LC_NAME=“en_US.UTF-8”
LC_ADDRESS=“en_US.UTF-8”
LC_TELEPHONE=“en_US.UTF-8”
LC_MEASUREMENT=“en_US.UTF-8”
LC_IDENTIFICATION=“en_US.UTF-8”
LC_ALL=

đŸ€·đŸœ 
 and that only happens when vi, vim or nvim are launched by Jenny to compose a twt.

​ Read More
In-reply-to » Diving into vintage games, roms, emulators and raspberry/retropie's mode. Now waiting to enjoy Family computer, last acquisition 😍😍

[lang=en] hey! What are you playing now?

I’ve been into PokĂ©mon Black, although it’s going slowly and switched to a more recent game, Inscryption, which has a 90s-2000s vibes.

​ Read More
In-reply-to » Yep, that's right, we have to use these tools in a proper way; terminal it’s not a friendly tool to use for this kind of stuff, on mobile devices, and web interfaces are prepared to bring us a confortable space.

[lang=en] By the way, have you played with Station on Gemini?

I like that using Gemtext, you can have a pretty decent microblogging platform. Imagine that with decentralization from twtxt. That sounds appealing to me!

​ Read More
In-reply-to » All it's about definitions:

[lang=en] I love this topic about definitions, it’s key to have meaningful conversations. Thanks for sharing that link.

Communication is vital for succeeding in any activity that requires the participation of more than one individual.

This is why it is so important to be tight and consistent with definitions and to fully understand them.
Love this

​ Read More
In-reply-to » I'm using rss on a terminal (Termux) in my phone, it's more confortable read there articles and other stuff, but for posting on twtxt, I tried , I swear it, but it's too much, it's not practical, I have to assume that it's better in a website/app like this.

[lang=en] That was the reason for twtxt-php =P
I tried using CLI tools but it was too hacky, I think.
More if we consider Jakob’s Law, where we have prior expectations of a microblogging system.

A Web interface could be quite minimalistic and usable as well. (And mobile-friendly)

​ Read More