cheatsheets devlog projects search


2022-12-04 1

Played around with chatgpt and it is utterly mindblowing.

Copilot and the like are cool but I never actually tried it so didn’t get it but chatgpt is next level.

I asked for a distance calculator and it gave me one that takes latitude and longitude and converts it to points on a sphere. It then uses the haversine formulate to calculate the distance.

function calculateDistance(lat1, lon1, lat2, lon2) {
  // Convert the latitude and longitude values from degrees to radians
  lat1 = (lat1 * Math.PI) / 180;
  lon1 = (lon1 * Math.PI) / 180;
  lat2 = (lat2 * Math.PI) / 180;
  lon2 = (lon2 * Math.PI) / 180;

  // Calculate the distance using the Haversine formula
  const a =
    Math.pow(Math.sin((lat2 - lat1) / 2), 2) +
    Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin((lon2 - lon1) / 2), 2);
  const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
  const d = 6371 * c;

  // Return the distance in kilometers
  return d;

We asked it to make a specific table cell in html half yellow and half blue and it did it perfectly.

table tr:nth-child(2) td:nth-child(3) {
  background: linear-gradient(to right, blue 50%, yellow 50%);

It was able to generate a vue table of specific columns and rows.

      <tr v-for="item in items" :key="">
        <td>{{ }}</td>
        <td>{{ }}</td>
        <td>{{ item.description }}</td>
        <td>{{ item.price }}</td>
        <td>{{ item.quantity }}</td>

I asked it to write a http server that responds to requests in bash.


# Set the port number to listen on

# Start the server using netcat
while true; do
  # Accept an incoming connection
  nc -l $port > /tmp/request

  # Read the HTTP request from the temporary file
  method=$(head -n 1 /tmp/request | awk '{print $1}')
  resource=$(head -n 1 /tmp/request | awk '{print $2}')

  # Handle the request based on the HTTP method and resource
  if [[ "$method" == "GET" ]]; then
    # Handle a GET request
    if [[ "$resource" == "/" ]]; then
      # Return the "Hello, World!" message
      printf "HTTP/1.0 200 OK\n\nHello, World!\n"
      # Return a 404 "Not Found" error
      printf "HTTP/1.0 404 Not Found\n\n"
    # Return a 405 "Method Not Allowed" error for other methods
    printf "HTTP/1.0 405 Method Not Allowed\n\n"

I asked it for some test cases.

Here are some test cases for a function that sums up numbers:

    The function should return 0 when given an empty array of numbers.

Input: sum([])

Expected output: 0

    The function should return the sum of the numbers in the array when given an array with one or more numbers.

Input: sum([1, 2, 3])

Expected output: 6

Input: sum([-1, -2, -3])

Expected output: -6

Input: sum([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])

Expected output: 55

    The function should return the sum of the numbers in the array, ignoring any non-numeric values.

Input: sum([1, 'a', 2, 'b', 3])

Expected output: 6

Input: sum([1, {}, 2, [], 3])

Expected output: 6

I hope this helps! Let me know if you have any other questions.

The most impressive part is that it also provides an explanation of what it is doing.

This is going be a paradigm shift, it might be that a programmers job is going to be to coax code out of AI and then read and modify that. At some point I imagine we will just need to the coaxing part once we begin trusting the AI written code. I only took a glance at the code it generated and it all looks right but the real test would be running things and making sure it works.

I will need to come back to this post in a week to see if my thoughts are the same and if it is indeed the change I think it is. Copilot had it’s issues and stable diffusion was cool but both fell off for me personally. I’m sure people are doing awesome things with both still.

This might be a case of Amara’s law:

We tend to overestimate the effect of a technology in the short run and underestimate the effect in the long run.