• 2 Posts
  • 240 Comments
Joined 1 year ago
cake
Cake day: June 11th, 2023

help-circle






  • Falsehoods About Time

    Having a background in astronomy, I knew going into programming that time would be an absolute bitch.

    Most recently, I thought I could code a script that could project when Easter would land every year to mark it on office timesheets. After spending an embarrassing amount of…er…time on it, I gave up and downloaded a table of pre-calculated dates. I suppose at some point, assuming the code survives that long, it will have a Y2K-style moment, but I didn’t trust my own algorithm over the table. I do think it is healthy, if not essential, to not trust your own code.

    Falsehoods About Text

    I’d like to add “Splitting at code-point boundary is safe” to your list. Man, was I ever naive!







  • Based on my personal observations, there are sort of like 3 rings to a religion. The outermost contains the vast majority of adherents who are pretty casual in their faith. If they are of some Christian denomination say, they’ll show up for Christmas or Easter services and go their separate ways otherwise. The 2nd ring contains people who attend services regularly but are non-evangelical. They are devout in their faith but not pushy about it.

    Then finally, there is this innermost ring of evangelicals who make it their mission to tell you how great it is to find God and can be pushy enough to make a priest cringe. People from the outer rings generally try to avoid this group, but they tend to be the most active online. I guess maybe lemmy has yet to be overrun by them?




  • So you’re saying the comments themselves get cached on the local instance where the user is registered before being synced with the remote community-hosting instance?

    I honestly don’t know how these things work internally, but had assumed the comments needed to go straight to the remote instance given the way you can’t comment once said instance goes down? You can still read the cached content though.


  • When I first heard the term “fediverse”, it immediately made me think of some sort of vast interplanetary network. And let’s face it: a fediverse-like model is really what you would need if you had settlements scattered throughout the solar system. A monolithic, centralized service would be awful, given the reality of communication lag and likely limited bandwidth.

    So let’s say lemmy (or more generally activitypub) were to go interplanetary. How would that work out? You set up your first instance on Mars. Any content that’s posted there will be immediately available to your fellow Martians. Earthlings who subscribe may also be able to view it as their instances cache the content, albeit after some delay.

    But the trouble starts when Earthlings want to start contributing to the discussion. If they have to wait the better part of an hour to get a single comment lodged, it’s going to get old fast.

    So you would need to allow the Earth side to branch off to some extent from what’s happening on Mars. Then eventually, something like a git merge would try to bring it all back together? I wonder if that would work?



  • Actually, now that I think of it, there’s no reason you need to join the 2 names into a single str. You could just leave it as a tuple of last, first and Python will know what to do in comparing them.

    >>> sorted(student_ids, key = lambda i: ((rec := student_recs[i])['last'], rec['first']))
    [632453, 1261456, 532153]
    

    So the lambda would be returning ('Potter', 'Harry') rather than 'Potter, Harry'. But whatever. The := part is still the same.


  • Can you use it to initialize vars outside the scope of the lambda?

    No, that’s not what it’s for. It lets you define a temporary local variable within an expression. This is useful in situations where you might want to use the same value more than once within the expression. In a regular function, you would just define a variable first and then use it as many times as you want. But until the walrus operator came along, you couldn’t define a variable within a lambda expression.

    Can you give an example?

    Ok, I’m trying to think of a simple example. Let’s say you had a database that maps student IDs to records contain their names. To keep things simple, I’ll just make it plain old dict. And then you have a list of student IDs. You want to sort these IDs using the student names in the form “last, first” as the key. So you could go:

    >>> student_recs = {1261456: {"first": "Harry", "last": "Potter"}, 532153: {"first": "Ron", "last": "Weasley"}, 632453: {"first": "Hermione", "last": "Granger"}}
    >>> student_ids = [1261456, 532153, 632453]
    >>> sorted(student_ids, key = lambda i: (rec := student_recs[i])['last'] + ', ' +  rec['first'])
    [632453, 1261456, 532153]
    

    The problem here is that student_ids doesn’t contain the student names. You need use the ID to look up the record that contains those. So let’s say the first ID i is 1261456. That would mean:

    rec := student_recs[i]
    

    evaluates to:

    {"first": "Harry", "last": "Potter"}
    

    Then we are effectively going:

     rec['last'] + ', ' + rec['first']
    

    which should give us:

     'Potter, Harry'
    

    Without the := you would either have to perform 2 student_recs[i] look-ups to get each name which would be wasteful or replace the lambda with a regular function where you can write rec = student_recs[i] on its own line and then use it.

    Am I making any sense?