playing with chatgpt

While I’ve been playing some with ChatGPT, I’m just not writing a blog post about it. It seems to be learning>L The first time I asked it about CodeRanch, it hadn’t heard of it. I tried again and got an answer. In this blog post, I show three different styles of questions.

Joke

I provided the prompt “tell me a joke about java lambdas” and got:

Sure! Here’s a joke about Java lambdas:

Why was the Java lambda feeling depressed?

Because it was an anonymous function without a name!

I hope you found that joke amusing. Do you have any other questions about Java or something else?

This joke amused me so mission accomplished.

Bio

When providing the prompt “who is jeanne boyarsky”, I got:

Jeanne Boyarsky is an American computer programmer and author who has written several books on Java programming. She is also a co-author of the popular Java certification study guide “OCA/OCP Java SE 8 Programmer Certification Kit.” In addition to her work as an author, Boyarsky is also an experienced Java developer and has worked on a variety of software development projects. She is a frequent speaker at software development conferences and has taught programming courses at both the college and high school level. Boyarsky is also known for her contributions to the open source software community and has been recognized as a Java Champion by Oracle.

A lot of this my bios, but not all of it. Taking it apart:

  • Jeanne Boyarsky is an American computer programmer – many of my bios say I’m from New York City. ChatGPT generalized that to the country.
  • and author who has written several books on Java programming – this is true although we usually listed the books rather than say “several”. But counting and generalizing is reasonable.
  • She is also a co-author of the popular Java certification study guide “OCA/OCP Java SE 8 Programmer Certification Kit.” – This language is in my conference bios. Scott actually wrote it this sentence and I copied it into my bio. However while this is factually accurate, that was published about 6 years ago. We’ve written Java 11 and 17 books since. A human would have highlight the more recent additions.
  • In addition to her work as an author, Boyarsky is also an experienced Java developer and has worked on a variety of software development projects. She is a frequent speaker at software development conferences and has taught programming courses at both the college and high school level. Boyarsky is also known for her contributions to the open source software community and has been recognized as a Java Champion by Oracle. – The rest of this is also paraphrased from various conference bios. I’m pleased ChatGPT didn’t attempt to do math to list my number of years of experience. I’ve read that arithmetic is not ChatGPT’s strong suit.

Coding

I tried a harder prompt of “how do i write a postgres sql statement to create a database table for id, link and a boolean toggle?” to see if I got ChatGPT to write a bit of code I was going to write for the CodeRanch forum software. I got

To create a database table in PostgreSQL with three columns – an ID column, a link column, and a boolean toggle column – you can use the following SQL statement:

Copy code
CREATE TABLE my_table ( id INTEGER PRIMARY KEY, link TEXT, toggle BOOLEAN );

This statement creates a table called my_table with three columns:

  • id: an integer column that is set as the primary key for the table. The primary key is a unique identifier for each row in the table and is used to identify and distinguish individual rows from one another.
  • link: a text column that will store a string value.
  • toggle: a boolean column that will store a true or false value.

Note that you can customize the names and data types of the columns to fit your specific needs. For example, you could use a different data type for the ID column, such as a serial data type, or you could give the columns different names.

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

The code was syntax highlighted and had a copy option. The explanation was detailed and ChatGPT inferred my key and types. It didn’t get the names of the fields (or table) right because i didn’t supply them in my prompt and can’t be expected to read my mind. And it was almost what I wanted. I needed “character varying” rather than “text” which shows the importance of knowing what you are doing in the prompt.

scheduling toots on mastodon

Last week, I wrote about my first month of Mastodon. This post is about three options for scheduling a Mastodon toot.

Option 1 – scheduler

The scheduler is easy to find. To use it, you go to your mastodon profile and choose “Development”. This lets you get an API key which you use to login and post. However, it doesn’t support images. (My use case involves an image in each toot.) It also didn’t work in Safari, but did in CHhome for me.

Option 2 – write your own

I started doing this. The REST APIs are well documented. There’s a variety of API wrappers for different languages. The Java one hadn’t been updated in four years and the Python one appears to want your password (not just access key), so I decided to stick with REST APIs. I created a GitHub action. First I used curl to test getting the token from a secret and calling a URL Then I played at the command line on uploading files.

name: JeanneTest

"main" branch
 #  push:
 #   branches: [ "main" ]
 # pull_request:
 #   branches: [ "main" ]
 
 #schedule:
 #  - cron: "0 2 * * 1-5"

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

jobs:

  build:
    runs-on: ubuntu-latest

    steps:
      - name: REST API test
        env:
             MASTODON_ACCESS_TOKEN: ${{ secrets.MASTODON_ACCESS_TOKEN }}
           
        run: |
          curl --header "Authorization: Bearer $MASTODON_ACCESS_TOKEN" -sS https://mastodon.social/api/v1/timelines/home

This all worked. My next step would have been to switch to Python or Perl to call the attachment API, parse it’s JSON and publish the toot. Then add some sort of scheduler logic. I didn’t get that far because I learned about option 3.

Option 3 – Fedilabs

Fedilabs has an app for that. To use it, you login to your instance and get an auth code. (Each time you schedule.) Then you schedule your toots.

The only think I didn’t find intuitive was the alt text. (You have to upload your image and then the option appears.) What’s cool is that nothing is stored. The app uses the Mastodon REST APIs right away. You can even see your scheduled toots on top.

While I could have written my own, this one is better. And it already exists. So I put some money in the tip jar and am happily using.

Bonus – asking OpenGPT for help

I was thinking to have OpenGPT help me write this blog post. I asked “how do i schedule a mastodon post“. Alas:

I’m sorry, but I’m not able to browse the internet, so I’m not able to provide specific instructions on how to schedule a post on Mastodon. However, Mastodon is a social networking service, so you may be able to schedule a post by accessing your account and looking for a scheduling or scheduling option in the settings or composing a new post.

I then clicked “try again” and got the following. That’s probably true on some client. It isn’t the web browser nor the official iOS Mastodon app.

To schedule a post on Mastodon, follow these steps:

  1. Open the Mastodon app on your device and log in to your account.
  2. Click on the “+” button in the bottom right corner to create a new post.
  3. Type your post in the text field and add any photos or videos you want to include.
  4. Click on the “Schedule” button in the bottom left corner of the screen.
  5. A calendar will appear, allowing you to choose the date and time you want your post to be published.
  6. Once you have selected the date and time, click on the “Schedule” button to confirm.
  7. Your post will now be scheduled and will automatically be published at the specified time.