Interests: programming, video games, anime, music composition

I used to be on kbin as e0qdk@kbin.social before it broke down.

  • 1 Post
  • 35 Comments
Joined 1 year ago
cake
Cake day: November 27th, 2023

help-circle
  • It’s really about lowering cognitive load when making edits. It’s not necessarily that someone can’t figure out how to do something more sophisticated, but that they’re more likely to get things right if the code is just kind of straightforwardly dumb.

    The last two are definitely situational – changing things like that might lower cognitive load for one kind of work but raise it significantly for another – but I can see where they’re coming from with those suggestions.





  • Try adding some prints to stderr through my earlier test program then and see if you can find where it stops giving you output. Does output work before curl_easy_init? After it? Somewhere later on?

    Note that I did update the program to add the line with CURLOPT_ERRORBUFFER – that’s not strictly needed, but might provide more debug info if something goes wrong later in the program. (Forgot to add the setup line initially despite writing the rest of it… 🤦‍♂️️)

    You could also try adding curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); to get it to explain more details about what it’s doing internally if you can get it to print output at all.



  • As a sanity check, does this work?

    #include <curl/curl.h>
    #include <stdio.h>
    #include <stdlib.h>
    
    size_t save_to_disk(char* ptr, size_t size, size_t nmemb, void* user_data)
    {
        /* according to curl's docs size is always 1 */
        
        FILE* fp = (FILE*)user_data;
        fprintf(stderr, "got %lu bytes\n", nmemb);
        return fwrite(ptr, size, nmemb, fp);
    }
    
    int main(int argc, char* argv[])
    {
        char errbuf[CURL_ERROR_SIZE];
        FILE* fp = NULL;
        CURLcode res;
        
        CURL* curl = curl_easy_init();
        
        if(!curl)
        {
            fprintf(stderr, "Failed to initialize curl\n");
            return EXIT_FAILURE;
        }
        
        fp = fopen("output.data", "wb");
        if(!fp)
        {
            fprintf(stderr, "Failed to open file for writing!");
            return EXIT_FAILURE;
        }
        
        curl_easy_setopt(curl, CURLOPT_URL, "https://www.wikipedia.org");
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, save_to_disk);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
        curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf);
        
        errbuf[0] = 0;  /* set error buffer to empty string */
        res = curl_easy_perform(curl);
        
        if(fp)
        {
            fclose(fp);
            fp = NULL;
        }
        
        if(res != CURLE_OK)
        {
            fprintf(stderr, "error code   : %d\n", res);
            fprintf(stderr, "error buffer : %s\n", errbuf);
            fprintf(stderr, "easy_strerror: %s\n", curl_easy_strerror(res));
            
            return EXIT_FAILURE;
        }
        else
        {
            fprintf(stderr, "\nDone\n");
            return EXIT_SUCCESS;
        }
    }
    

    That should write a file called output.data with the HTML from https://www.wikipedia.org and print out the number of bytes each time the write callback receives data for processing.

    On my machine, it prints the following when it works successfully (byte counts may vary for you):

    got 13716 bytes
    got 16320 bytes
    got 2732 bytes
    got 16320 bytes
    got 16320 bytes
    got 128 bytes
    got 16320 bytes
    got 16320 bytes
    got 1822 bytes
    
    Done
    

    If I change the URL to nonsense instead to make it fail, it prints text like this on my system:

    error code   : 6
    error buffer : Could not resolve host: nonsense
    easy_strerror: Couldn't resolve host name
    

    Edit: corrected missing line in source (i.e. added line with CURLOPT_ERRORBUFFER which is needed to get extra info in the error buffer on failure, of course)

    Edit 2: tweaks to wording to try to be more clear






  • You can do this by configuring an HTTP server (e.g. Apache) to listen on port 80 and/or 443 (HTTP and HTTPS standard ports, respectively) and select which site to serve based on the name of the site requested. Apache documentation for this feature is here: https://httpd.apache.org/docs/2.4/vhosts/name-based.html

    Note the sample config snippet showing how to set up a simple static site serving both www.example.com and other.example.com using ServerName in a VirtualHost to select between them.

    You can also have Apache match a pattern in the URL and reverse proxy to another HTTP server – that can just be another program on the same computer listening on a different port, or could be on another computer entirely. See the simple reverse proxy config example on this page for a starting point: https://httpd.apache.org/docs/2.4/howto/reverse_proxy.html (Note also that you probably don’t need anything further down that page – e.g. the load balancer and failover stuff is not likely to be useful to you for a small personal project.)

    Other popular HTTP servers can do this too; I just happen to have done it with Apache before.


  • Best way to fix that is to join in and post something!

    Otome isn’t my personal interest (my sexuality goes the other way), so I don’t have much to say myself, but I’ve seen Elevator7009 trying to build a community first on kbin.social (before that site died) and then on kbin.run (before it died) and now there and I’d like to see her efforts succeed.

    If you’re not interested, feel free to ignore it, but if you’d like a place on Lemmy for discussion, there are at least a few people there who’ve been trying their damnedest to get something going.






  • If you want to improve significantly, go read someone else’s code and modify it. Try to fix a bug in a program you use, add a feature you want that doesn’t exist already, or even just do something simple for the sake of proving to yourself that you can do it – like compiling it from source and figuring out how to change some small snippet of text in a message box. Even if you don’t succeed, if you put in a serious effort attempting it, you will almost certainly learn a lot from trying.

    Edit: changed wording to try to be clearer



  • How 'bout that! :D

    If the SSD itself is OK, then it was probably trying to boot the SSD still. The blank screen issue might have to do with the graphics drivers then? I remember having a similar blank screen problem with Ubuntu a long time ago where I had to put in “nomodeset” as a parameter in GRUB when booting until I got the right drivers set up.