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

help-circle
rss

  • I just asked GPT-4 if the Twilight Series is “suitable for children” and the output was pretty spot on - summarised five issues that might be problematic and then finished with “It’s always a good idea for parents or guardians to consult with a librarian or teacher”.

    I bet none of this is based on the actual contents of the book - it would be based on independent reviews of the book. For example it highlights issues that “some parents” have raised. Which means you really are just getting a summary of what humans think of it.

    The suitability of the “Twilight” series by Stephenie Meyer for children depends on the age and maturity of the child, as well as what a parent or guardian deems appropriate for their child to read. Here are some factors to consider:

    Age Recommendation: The “Twilight” series is generally categorized as Young Adult (YA) fiction, which typically targets readers from about 12 to 18 years of age. However, the series has appealed to a wide age range, from preteens to adults.

    Romantic Themes: The series is centered around a romantic relationship, and much of the plot focuses on the emotional and romantic dynamics between the main characters. Some of the romantic scenes can be intense, although they are not explicitly sexual.

    Violence and Danger: The books include some violent scenes and perilous situations. Characters are placed in dangerous circumstances, and there are fights and confrontations, including some that result in serious injury or death. The violence is generally not extremely graphic, but it is a recurring element.

    Supernatural Elements: The series revolves around vampires and werewolves, and thus engages with supernatural themes and folklore. Some children may find these elements frightening, while others might be fascinated by them.

    Emotional Intensity: The series deals with intense emotions, including love, jealousy, longing, and heartbreak. Some parents might feel that these themes are more appropriate for older teens who have begun to navigate complex emotional experiences themselves.

    Moral and Ethical Themes: Some readers and parents have criticized the series for the dynamics of the central relationship, seeing it as potentially portraying an unhealthy or obsessive relationship as idealized. Others see it as a fictional exploration of intense emotions and do not take it as a model for real-world behavior.

    Reading Level: The series is written in a relatively accessible style, but the themes and vocabulary are most suitable for readers in their mid-to-late teens.

    Ultimately, the best approach might be for a parent or guardian to either read the books themselves or read them along with their child, so they can discuss any questions or concerns that arise. It’s important to consider the individual child’s maturity level and sensitivities, as well as family values and comfort with the themes of the books.

    For younger children, or for those who may be sensitive to the themes of romantic intensity or violence, waiting until they are older or choosing a different series might be advisable. It’s always a good idea for parents or guardians to consult with a librarian or teacher, who can provide age-appropriate recommendations based on a child’s interests and reading level.







  • You don’t, you get it to write both the code and the tests. And you read both of them yourself. And you run them in a debugger to verify they do what you expect.

    Yeah, that’s half the work of “normal coding” but it’s also half the work. Which is a pretty awesome boost to productivity.

    But where it really boosts your productivity is with APIs that you aren’t very familiar with. ChatGPT is a hell of a lot better than Google for simple “what API can I use for X” questions.


  • So? Those mistakes will come up in testing, and you can easily fix them (either yourself, or by asking the AI to do it, whichever is faster).

    I’ve successfully used it to write code for APIs that did not even exist at all a couple years ago when ChatGPT’s model was trained. It doesn’t need to know the API to generate working code - you just need to tell it what APIs are available as part of your conversation.



  • So this isn’t a real example, it’s just something I slapped together now as an example of how I generally use ChatGPT 4.0. In a more realistic scenario, I’d be asking more detailed questions, pasting in my existing code, and asking the AI to write smaller sections (maybe 10 lines of code at a time).

    A single chat might run for five or six hours, continuously discussing an individual task I’m working on, and I won’t just be asking it to write a bunch code. For example in this case I might spend 10 minutes hashing out the exact contents of the ‘Activity’ record (or, maybe I already did that a month ago, and I might just paste in an example). I’d also be testing the code as I go and writing some of it myself, occasionally asking questions like ‘how do I format a date as 4 Feb 2016’ in JavaScript?’ or ‘this line of code fails with X. Why?’

    In those five or six hours, I estimate I’m able to get two or three days of work done (at my level of productivity before I started paying $20/month for ChatGPT+).

    I’m also only pasting the code - ChatGPT also explains the code it outputs, and often those explanations are more useful than the actual code.

    In JavaScript write a “reserveSeat(‘A42’, ‘Adult’)” function that sends an ActivityStreams 2.0 activity to (this.apiUrl)/reserve and inform the user if it failed to be reserved

    class SeatReservationService {
      constructor(apiUrl) {
        this.apiUrl = apiUrl;
      }
    
      async reserveSeat(seatNumber, seatType) {
        // Construct an ActivityStreams 2.0 compliant JSON object
        const activity = {
          '@context': 'https://www.w3.org/ns/activitystreams',
          'type': 'Reserve',
          'actor': {
            'type': 'Person',
            'name': 'User'
          },
          'object': {
            'type': 'Seat',
            'id': seatNumber,
            'category': seatType
          }
        };
    
        try {
          // Send the activity object to the specified API endpoint using an HTTP POST request
          const response = await fetch(`${this.apiUrl}/reserve`, {
            method: 'POST',
            headers: {
              'Content-Type': 'application/json'
            },
            body: JSON.stringify(activity)
          });
    
          // Handle the server’s response
          if (response.ok) {
            // If the request was successful, log a success message
            console.log('Seat reserved successfully.');
          } else {
            // If the server responds with a status code other than 2xx, throw an error
            throw new Error('Failed to reserve seat. Server responded with ' + response.status);
          }
        } catch (error) {
          // Inform the user if the reservation failed
          console.error('Failed to reserve seat:', error);
          alert('Failed to reserve the seat. Please try again.');
        }
      }
    }
    
    // Usage
    const service = new SeatReservationService('https://example.com/api');
    service.reserveSeat('A42', 'Adult');
    

    Write a PHP request handler that does $this->reserveSeat(‘A42’), and checks if it failed with a SeatNotAvailable exception

    class SeatNotAvailable extends Exception {
        public function __construct($message = "Seat not available", $code = 0, Exception $previous = null) {
            parent::__construct($message, $code, $previous);
        }
    }
    
    class SeatReservationService {
    
        public function reserveSeat($seatNumber) {
            // Mockup condition that the seat 'A42' is not available
            if ($seatNumber === 'A42') {
                throw new SeatNotAvailable("Seat $seatNumber is not available.");
            }
    
            // Normally here you'd interact with a database or another kind of storage
            // to actually reserve the seat.
            // ... (reserve seat logic) ...
            
            return true;
        }
    }
    
    class SeatReservationController {
    
        private $service;
    
        public function __construct() {
            $this->service = new SeatReservationService();
        }
    
        public function handleRequest() {
            try {
                $this->service->reserveSeat('A42');
                echo "Seat reserved successfully.";
            } catch (SeatNotAvailable $e) {
                echo $e->getMessage();
            }
        }
    }
    

    Write a PHPUnit test for SeatReservationController, and a Jest one for SeatReservationService

    createMock(SeatReservationService::class);
            $serviceMock->method('reserveSeat')
                        ->willReturn(true);
    
            $controller = new SeatReservationController($serviceMock);
            $this->expectOutputString("Seat reserved successfully.");
            $controller->handleRequest();
        }
    
        public function testSeatNotAvailableException() {
            $serviceMock = $this->createMock(SeatReservationService::class);
            $serviceMock->method('reserveSeat')
                        ->will($this->throwException(new SeatNotAvailable()));
    
            $controller = new SeatReservationController($serviceMock);
            $this->expectOutputString("Seat not available");
            $controller->handleRequest();
        }
    }
    
    const SeatReservationService = require('./SeatReservationService'); // Adjust the path as necessary
    
    test('reserves a seat successfully', async () => {
        const service = new SeatReservationService('https://example.com/api');
        global.fetch = jest.fn(() => 
            Promise.resolve({
                ok: true
            })
        );
    
        await service.reserveSeat('A41', 'Adult');
        expect(fetch).toHaveBeenCalledWith(
            'https://example.com/api/reserve', 
            expect.objectContaining({
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
            })
        );
    });
    
    test('fails to reserve a seat', async () => {
        const service = new SeatReservationService('https://example.com/api');
        global.fetch = jest.fn(() => 
            Promise.resolve({
                ok: false,
                status: 400
            })
        );
    
        global.console = { error: jest.fn(), log: jest.fn() };
    
        await service.reserveSeat('A42', 'Adult');
        expect(console.error).toHaveBeenCalledWith(
            'Failed to reserve seat:', 
            expect.any(Error)
        );
    });
    



  • AFAIK the “action button” is going to replace the “mute” switch which is rumoured to be the most common component failure on recent model iPhones. Pocket lint/etc is can be forced into the switch every time you operate it and eventually that leads to failure (normally long after the warranty runs out and when repairing the button would cost more than the device is worth).

    Apple is on a long running effort to increase device longevity and that switch is the biggest barrier right now.

    The mute switch is also prone to accidental input, and it’s the only exterior button where accidentally triggering it is potentially a problem (you could miss an important call/etc).

    On top of all that - it’s a bit silly to have a slider on/off button for a feature that is already triggered in software and/or on a schedule. So the state of the slider button already doesn’t necessarily match the current mute status which is confusing. And with intelligent notifications why do you need a button anyway? You will surely be able to use the “Action” button to toggle the mute switch, but that won’t be the default button assignment. I’d bet it will be a camera button by default.

    It’s expected to be a solid state pressure sensitive capacitive button with haptic feedback. Apple uses those in a bunch of other devices (the whole screen was one on older iPhones) and they are cheap, almost indistinguishable from a regular button, more reliable long term, and can only be activated deliberately (they might not work with gloves on…)







  • Second paragraph of the article: “My colleague Vjeran just lost 3TB of video”.

    It’s not just the title, the entire article is about data loss. To be honest what really bothers me about the article is the whole thing points fingers at WD for making a mistake, while conveniently ignoring that fact that a Verge employee also made a mistake and I’d argue a worse one by failing to backup their data.

    If the article was about “it’s annoying to have to wait for a replacement drive to be sent” then I’d be right on board. But that’s not what the article is about.