• 0 Posts
  • 27 Comments
Joined 2 years ago
cake
Cake day: June 13th, 2023

help-circle







  • No. In addition to browsers’ prefers-dark-mode setting, there is also the fallback foreground and background color choice, used whenever a website does not specify a foreground or background color. One common case is when viewing a plain unstyled site or txt file.

    A dark-mode preferring user might choose for these fallbacks a light foreground and dark background. The problem is then that some designers will carelessly specify either the foreground or background color (and not both), assuming that their choice will happen to have good contrast with every user’s browser preferences.

    More low contrast examples from the Statamic docs:

    Statamic search field

    Statamic adspace

    In Firefox’s preferences page those settings are accessed with the “Manage Colors” button just below dark-mode selection, and look like this:

    Firefox Preferences -- Manage Colors

    Notice that I am not overriding any colors specified by the page.







  • All of these languages are relatively succinct, and I rely on that to reduce visual and mental clutter, because I have a pea brain.

    Factor, Nim, Roc, and Zsh each offer, to differing extents, some argument-then-function ordering in the syntax, which strikes me as elegant and fun, and maybe even wise. In that order, Factor does this the most (using postfix/reverse-polish-notation and managing a data stack), and Zsh the least (piping output from one command as the input for the next command).


    Roc

    Roc is a functional language, and an offshoot of Elm in spirit. The lead developer and community are great. Relative to Elm, it’s more inclusive and experimental in the development process, and does not primarily or exclusively target web stuff. They aim to create an ambitiously integrated development environment, especially taking advantage of any guarantees the functional design can offer.

    Here’s a sample, using the |> operator a lot, which lets you order the first argument to a function before the function IIRC:

    getData = \filepath ->
        filepath
        |> Path.fromStr
        |> File.readUtf8
        |> Task.attempt \result ->
            result
            |> Result.withDefault ""
            |> Task.succeed
    

    Nim

    Nim is so darn flexible and concise, has great compilation targets, and employs Uniform Function Call Syntax to more implicitly enable the kind of ordering in the Roc example. And you can often leave out parentheses entirely.


    Factor

    Factor is a full-on postfix and concatenative language, tons of fun, and turns my brain inside out a bit. I made a community for concatenative languages here on programming.dev, and while there’s little activity so far, I’ve filled the sidebar with a bunch of great resources, including links to active chats.

    EDIT: !concatenative@programming.dev

    The Factor REPL (“listener”) provides excellent and speedy documentation and definitions, and a step-through debugger.

    One idea that seems absurd at first is that for the most part, you don’t name data variables (though you can, and you do name function parameters). It’s all about whatever’s on the top of the stack.

    In some languages it’s awkward to approximate multiple return values, but in a stack-oriented language it’s natural.

    In Factor, everything is space-separated, so functions (“words”) can and do include or consist of symbols. [1..b] is not semantically something between brackets, it’s just a function that happens to be named [1..b]. It pops 1 item off the top of the stack (an integer), and pushes a range from 1 to that integer on to the top of the stack.

    Here it is in my solution to the code.golf flavor of Fizz Buzz:

    USING: io kernel math.functions math.parser ranges sequences ;
    
    100 [1..b] [ 
      dup [ 3 divisor? ] [ 5 divisor? ] bi 2dup or [ 
        [ drop ] 2dip 
        [ "Fizz" "" ? ] [ "Buzz" "" ? ] bi* append 
      ] [ 2drop number>string ] if
      print 
    ] each
    

    And in image form for glorious syntax highlighting: Syntax Highlighted Fizz Buzz in Factor

    Factor example walkthrough

    Anything between spaced brackets is a “quotation” (lambda/anonymous function).

    So:

    • Push a range from 1-100 onto the stack.
    • Push a big quotation that doesn’t end till each at the bottom.
    • each consumes the range and the quotation. For each element of the range, it pushes the element then calls the quotation.
    • dup pushes a copy of the stack’s top item. Say we’re in the ninth iteration of the each loop, we’ve got 9 9 on the stack.
    • Two quotations are pushed (9 9 [...] [...]), then bi applies them each in turn to the single stack item directly beneath, leaving us with 9 t f (true, it’s divisble by three, false, it’s not by 5).
    • 2dup copies the top two, so: 9 t f t f
    • or combines the last two booleans: 9 t f t
    • Two quotes are pushed, followed by an if (9 t f t [...] [...] if), which pops that final t and calls only the first quotation.
    • [ drop ] 2dip takes us from 9 t f to t f – it dips under the top two, drops the temporary new top, then restores the original top two.
    • ? is like a ternary. That first quotation will push "Fizz" if called with t (true) on the stack, "" otherwise.
    • bi* applies the last two items (quotations) to the two values before them, each only taking one value. The Fizz one applies to t and the Buzz to f, taking us from t f [...] [...] to "Fizz" ""
    • append joins those strings, as it would any sequence: "Fizz"
    • Finally we print the string, leaving us with an empty stack, ready for the next iteration.

    EDIT: Walkthrough in image form, more granular:




  • I’m not trying to be combative, I’m trying to understand. I’d like to see the failure in action so I can appreciate and pursue the proposed solution.

    But when I added the community bit to the first URL, the browser resolved it and stripped the credentials, so the resulting URL matched. But the example credentials weren’t real so it’s not a great test; if there’s an real example I can test, please share it. Though I don’t see why I’d auth to an instance just to view it from a different instance.

    When I added the community bit to the second URL, it was not a match, as it shouldn’t be. The pattern must match the entire URL.




  • I just posted this on the post you linked, but yeah I am hardcoding a list of instances into my solution. Here’s my comment, copied:


    I’m using the Firefox addon Redirector, and one of my rules there redirects community links using regex. I keep adding to the pattern as I encounter more instances. Currently it’s:

    Pattern: https://(lemdro\.id|lemmy\.run|beehaw\.org|lemmy\.ml|sh\.itjust\.works|lemmy\.fmhy\.ml|lemmy\.dbzer0\.com|lemmy\.world|sopuli\.xyz|lemmy\.kde\.social|lemmygrad\.ml|mander\.xyz|lemmy\.ca|zerobytes\.monster)/c/(.*)
    
    Redirect to: https://programming.dev/c/$2@$1