Searching yarn

Twts matching #python
Sort by: Newest, Oldest, Most Relevant
In-reply-to » @lyse Nice! Next up: Passing file descriptors over Unix sockets. 😃

Thanks, @movq@www.uninformativ.de! That seems to be much easier. It’s already implemented in the Python docs as examples of recvmsg(…) and sendmsg(…):

I looked at them sooo many times in order to figure out why my SCM_CREDENTIALS sending code didn’t work. :-D

⤋ Read More

Nobody want to be a shitty programmer. The question is: Do you do anything not to not be one?
Reading blogs or social media and watching YouTube videos is fun. After them, your code may be a little better, of course. But you need a lot. You need to study! Read good books and study the code of other programmers, for example. Maybe work with a new language, architectures and paradigms. You need break the routine.

If you know Object-oriented programming, you learn functional programming.
If you know Model-View-Controller, you learn Model-View-ViewModel.
If you don’t know anything about architectures, you learn Clean Architecture, Hexagonal Architecture, etc.
If you know Python, you learn Ruby or Go.
If you know Clojure or Lisp… you don’t need to learn anything else. You are already a good programmer. Just kidding. You can learn Elixir or Scala.

Be a good programmer my friend.

⤋ Read More
In-reply-to » To the parents or teachers: How do you teach kids to program these days? 🤔

We’re all old farts. When we started, there weren’t a lot of options. But today? I’d be completely overwhelmed, I think.

Hence, I’d recommend to start programming with a console program. As for the language, not sure. But Python is probably a good choice

That’s what I usually do (when we have young people at work who never really programmed before), but it doesn’t really “hit” them. They’ve seen so much, crazy graphics, web pages, it’s all fancy. Just some text output is utterly boring these days. ☹️ And that’s my problem: I have no idea how I could possibly spark some interest in things like pointers or something “low-level” like that. And I truly believe that you need to understand things like pointers in order to program, in general.

⤋ Read More
In-reply-to » To the parents or teachers: How do you teach kids to program these days? 🤔

@movq@www.uninformativ.de I started with Delphi in school, the book (that we never ever used even once and I also never looked at) taught Pascal. The UI part felt easy at first but prevented me from understanding fundamental stuff like procedures or functions or even begin and end blocks for ifs or loops. For example I always thought that I needed to have a button somewhere, even if hidden. That gave me a handler procedure where I could put code and somehow call it. Two or three years later, a new mate from the parallel class finally told me that this wasn’t necessary and how to do thing better.

You know all too well that back in the day there was not a whole lot of information out there. And the bits that did exist were well hidden. At least from me. Eventually discovering planet-quellcodes.de (I don’t remember if that was the original forum or if that got split off from some other board) via my best schoolmate was like finding the Amber Room. Yeah, reading the ITG book would have been a very good idea for sure. :-)

In hindsight, a console program without the UI overhead might have been better. At least for the very start. Much less things to worry about or get lost.

Hence, I’d recommend to start programming with a console program. As for the language, not sure. But Python is probably a good choice, it doesn’t require a lot of surrounding boilerplate like, say Java or Go. It also does exceptionally well in the principle of least surprise.

⤋ Read More
In-reply-to » @david @andros The correct hash would be si4er3q. See https://twtxt.dev/exts/twt-hash.html, a timezone offset of +00:00 or -00:00 must be replaced by Z.

@eaplme@eapl.me you wrote:

“That PHP snippet could be merged into https://twtxt.dev/exts/twt-hash.html”

Why, though? AFAIK @andros@twtxt.andros.dev’s client is on Emacs, @lyse@lyse.isobeef.org’s is on Python (and Golang, for tt2), @movq@www.uninformativ.de’s is on Python, and @prologic@twtxt.net’s is on Golang. All the client creator needs to know is in the documentation already, coding language agnostic.

⤋ Read More
In-reply-to » @david @andros The correct hash would be si4er3q. See https://twtxt.dev/exts/twt-hash.html, a timezone offset of +00:00 or -00:00 must be replaced by Z.

Scratch that, no bug in jenny. There’s actually a test case for this. Python normalizes -00:00 to +00:00, so the negative case never happens.

⤋ Read More

Elliptical Python programming
One thing I love about Python is how it comes with its very own built-in zen. In moments of tribulations, when I am wrestling with crooked code and tangled thoughts, I often find solace in its timeless wisdom. ↫ Susam Pal I can’t program and know nothing about Python, but this still made me laugh. ⌘ Read more

⤋ Read More
In-reply-to » I now subscribed to most feeds in my Go tt reimplementation that I already followed with the old Python tt. Previously, I just had a few feeds for testing purposes in my new config. While transfering, I "dropped" heaps of feeds that appeared to be inactive.

Thanks, @movq@www.uninformativ.de!

My backing SQLite database with indices is 8.7 MiB in size right now.

The twtxt cache is 7.6 MiB, it uses Python’s pickle module. And next to it there is a 16.0 MiB second database with all the read statuses for the old tt. Wow, super inefficient, it shouldn’t contain anything else, it’s a giant, pickled {"$hash": {"read": True/False}, …}. What the heck, why is it so big?! O_o

⤋ Read More

I now subscribed to most feeds in my Go tt reimplementation that I already followed with the old Python tt. Previously, I just had a few feeds for testing purposes in my new config. While transfering, I “dropped” heaps of feeds that appeared to be inactive.

This might motivate me to actually “finish” the new client, so that it could become my daily driver. No need to use the old software stack any longer. Let’s see how bad this goes.

⤋ Read More
In-reply-to » When will the flat UI craze end? Can I get my buttons, scrollbars, and toolbars back, please?

@movq@www.uninformativ.de Yeah, most of the graphical applications are actually KDE programs:

  • KMail – e-mail client
  • Okular – PDF viewer
  • Gwenview – image viewer
  • Dolphin – file browser
  • KWallet – password manager (I want to check out pass one day. The most annoying thing is that when I copy a password, it says that the password has been modified and asks me whether I want to save the changes. I never do, because the password is still the same. I don’t get it.)
  • KPatience – card game
  • Kdenlive – video editor
  • Kleopatra – certificate manager

Qt:

  • VLC – video player
  • Psi – Jabber client (I happily used Kopete in the past, but that is not supported anymore or so. I don’t remember.)
  • sqlitebrowser – SQLite browser

Gtk:

  • Firefox – web browser
  • Quod Libet – music player (I should look for a better alternative. Can’t remember why I had to move away from Amarok, was it dead? There was a fork Clementine or so, but I had to drop that for some unknown reason, too.)
  • Audacity – audio editor
  • GIMP – image editor

These are the things that are open right now or that I could think of. Most other stuff I actually do in the terminal.

In the past™, I used the Python KDE4 bindings. That was really nice. I could pass most stuff directly in the constructor and didn’t have to call gazillions of setters improving the experience significantly. If I ever wanted to do GUI programming again, I’d definitely go that route. There are also great Qt bindings for Python if one wanted to avoid the KDE stuff on top. The vast majority I do for myself, though, is either CLI or maybe TUI. A few web shit things, but no GUIs anymore. :-)

⤋ Read More
In-reply-to » Wow, this is a nice way to practice internationalization for our systems https://i18n-puzzles.com

I have finished 1-9 on Python. If anyone is interested, I could share the code, or in Reddit many people have shared theirs.

⤋ Read More
In-reply-to » The other day, after a discussion online, we came to the conclusion that using awk+sed+tr could replace much of the development that requires a database. However, using SQLite to have a SQL syntax isn't a bad idea either. What do you think?

@andros@twtxt.andros.dev If something fits in a CSV file, it typically doesn’t require a database. I agree with that. Depending on the application, more complicated queries might benefit from a database, though. I don’t know awk very well, but I could imagine that grep, sed and cut reach their CSV processing limits rather quickly when you have to deal with escaped (multiline) fields.

I only very rarely have to deal with CSV files or databases in my day to day life. Maybe, these classic Unix tools offer some tricks I’m not aware of. When I have some more complicated CSV input, I generally reach for Python.

⤋ Read More
In-reply-to » Have you ever had to refactor a project that was not documented? Any suggestions?

The project is a POC (Proof of Concept) that went into production and the company has customers who are using it. The developers had been working for several years, without testing, structure, isolation and so on. The company hired me to transform the project into a real product. There are in my hands 422 python files to transform that they beg me a refactore, architecture and testing. Every developer’s bad dream.
My first step is to read and understand the tree because there are apps inside other apps call each other. I am very determined to work on a new repository.

⤋ Read More
In-reply-to » My take on the discussion to introduce an ? operator in Go 👈 No. For so many reasons.

@prologic@twtxt.net Which one? I don’t mind the ternary operator at all. In fact, I often find myself missing it in Go. I don’t find the two alternatives particularly elegant:

foo := "eggs"
if bar {
    foo = "spam"
}

Or:

var foo string
if bar {
    foo = "spam"
} else {
    foo = "eggs"
}

To my eye, this just would look a lot nicer:

foo := bar ? "spam" : "eggs"

Or at least as the Pythons do it:

foo = "spam" if bar else "eggs"

The ternary operator especially shines with relatively short expressions.

⤋ Read More

For many years I have found Flask to be too basic a tool for modern development. But since I create APIs using Flask with Pydantic to validate the input data, some middlewares for parsing and Blueprint to separate the code into modules… I must admit that I am super comfortable, fast and easy to test.
#flask #python #pydantic

⤋ Read More
In-reply-to » I share a simple API template with Clean Architecture using #flask and #fastapi https://git.andros.dev/andros/api-template-with-clean-architecture #cleancode #cleanarchitecture

What is clean architecture? That’s a good question.

You think of a pattern for ordering code with good decisions isolating technologies (you can change the web framework or database without break the business logic), easy to test (you only test interfaces and use cases), sharing code between frameworks (entities and use cases), scalability, modulations and standardizing names. Clean architecture is not perfect, it has a learning curve and some abstraction in each technology. You can even find rejection with yours colleagues.
I have a good article on this topic.
https://programadorwebvalencia.com/implementando-arquitectura-limpia-en-python/
#python

⤋ Read More
In-reply-to » I’ve made it a habit to always put on my noise cancelling headphones when going to bed (without music). It’s pure heaven. 😂 Silence and darkness. I fall asleep within minutes. 😂 Good night. 😴

Yeah, @bender@twtxt.net, I absolutely love it! :-D Monty Python just rocks!

This very knight inspired me to make myself a knight helmet with opening visor out of an old washing machine sheet metal years ago for a theater play. It was really great fun, both making the helmet as well as using it during the week in the play as a silly and shady prince who got all his tracts of land by winning dubious games.

I just couldn’t really hear very well in it. And if somebody hit me on the head or just slightly knocked on the helmet, it was incredibly loud. No fine craftmanship by any means and obviously historically extremely questionable at best, but it did the job well enough. One of the running gags was that I had to open the visor when I wanted to talk. Here are some photos in action, you’ll find many more when surfing through the gallery:

⤋ Read More
In-reply-to » i love posting to my own personal youtube site i can just do whatever tf i want. no content ID here just vibes and finger crossing that i don't get a cease and desist one day

@prologic@twtxt.net mediacms! it’s janky yeah but it does the job ultimately (even if sometimes videos don’t encode and i gotta do some weird python venv shit to force the encode lol…)

⤋ Read More
In-reply-to » For some reason, I was using calc all this time. I mean, it’s good, but I need to do base conversions (dec, hex, bin) very often and you have to type base(2) or base(16) in calc to do that. That’s exhausting after a while.

@movq@www.uninformativ.de Thanks! I already found it and patched it to run in my ancient Python version (no match keyword and exec(…) only allows globals and locals as positional arguments). :-) https://lyse.isobeef.org/tmp/mcalc-patched.py.txt

⤋ Read More
In-reply-to » The fact that the official Python docs don’t clearly state what a function returns, grinds my gears. This has cost me so much time over the years. You always have to read through a huge block of text.

@movq@www.uninformativ.de Yeah, the Python docs are more like a book. They absolutely shine if you have no idea and read them from top to bottom. The tutorial is baked right in. But they don’t work all that perfect as cheat sheets. I also remember looking for the return types way too long in the past.

I would have thought that this could be easily improved when type hints are in place. And it sure does: https://www.tornadoweb.org/en/stable/httpclient.html#tornado.httpclient.HTTPClient.fetch

⤋ Read More

For some reason, I was using calc all this time. I mean, it’s good, but I need to do base conversions (dec, hex, bin) very often and you have to type base(2) or base(16) in calc to do that. That’s exhausting after a while.

So I now replaced calc with a little Python script which always prints the results in dec/hex/bin, grouped in bytes (if the result is an integer). That’s what I need. It’s basically just a loop around Python’s exec().

$ mcalc 
> 123
         123        0x[7b]    0b[01111011]

> 1234
        1234        0x[04 d2]    0b[00000100 11010010]

> 0x7C00 + 0x3F + 512
       32319        0x[7e 3f]    0b[01111110 00111111]

> a = 10; b = 0x2b; c = 0b1100101
          10        0x[0a]    0b[00001010]

> a + b + 3 * c
         356        0x[01 64]    0b[00000001 01100100]

> 2**32 - 1
  4294967295        0x[ff ff ff ff]    0b[11111111 11111111 11111111 11111111]

> 4 * atan(1)
3.141592653589793

> cos(pi)
-1.0

⤋ Read More

The fact that the official Python docs don’t clearly state what a function returns, grinds my gears. This has cost me so much time over the years. You always have to read through a huge block of text.

Image

You could at least put a list of possible return values in there (always at the same location, please!), here’s a mockup:

Image

⤋ Read More
In-reply-to » @doesnm Agree. salty.im should allow the user to post multiple brokers on their webfinger so the client can find a working path.

Honestly… not much. Have abandon two projects (both private) on Golang and one related to cryptography. My mostly languages are Python and Javascript (also can PHP). After writing code on Go i spend same time on fixing dumb errors

⤋ Read More
In-reply-to » @movq Non-ASCII characters were broken. Like U+2028, degrees (°), etc.

Now WTF!? Suddenly, @falsifian@www.falsifian.org’s feed renders broken in my tt Python implementation. Exactly what I had with my Go rewrite. I haven’t touched the Python stuff in ages, though. Also, tt and tt2 do not share any data at all.

By any chance, did you remove the ; charset=utf-8 from your Content-Type: text/plain header, falsifian?

Image

⤋ Read More
In-reply-to » On the Subject of Feed Identities; I propose the following:

@mckinley@twtxt.net To answer some of your questions:

Are SSH signatures standardized and are there robust software libraries that can handle them? We’ll need a library in at least Python and Go to provide verified feed support with the currently used clients.

We already have this. Ed25519 libraries exist for all major languages. Aside from using ssh-keygen -Y sign and ssh-keygen -Y verify, you can also use the salty CLI itself (https://git.mills.io/prologic/salty), and I’m sure there are other command-line tools that could be used too.

If we all implemented this, every twt hash would suddenly change and every conversation thread we’ve ever had would at least lose its opening post.

Yes. This would happen, so we’d have to make a decision around this, either a) a cut-off point or b) some way to progressively transition.

⤋ Read More

I love shell scripts because they’re so pragmatic and often allow me to get jobs done really quickly.

But sadly they’re full of pitfalls. Pitfalls everywhere you look.

Today, a coworker – who’s highly skilled, not a newbie by any means – ran into this:

$ bash -c 'set -u; foo=bar; if [[ "$foo" -eq "bar" ]]; then echo it matches; fi'
bash: line 1: bar: unbound variable

Why’s that happening? I know the answer. Do you? 😂

Stuff like that made me stop using shell scripts at work, unless they’re just 4 or 5 lines of absolutely trivial code. It’s now Python instead, even though the code is often much longer and clunkier, but at least people will understand it more easily and not trip over it when they make a tiny change.

⤋ Read More
In-reply-to » Go 1.22.0 introduces a new experiment for range functions. Have you tried them out? What do you think it can make easier to accomplish?

Things can get very interesting when we add the iter.Pull function in the mix. It works like pythons yield from.

Image

⤋ Read More