Posts

Babysitting ChatGPT

 After my initial excitement with chatGPT, I have been trying to use it in the real world. I needed to plan a certain programming task and I was expecting to get it done quickly and easily with the help of AI, but the result has been quite different.  The first big problem is that code tends to get cut with no warning sign. You get a snippet of code where part of it is missing. Sometimes it is more evident than others and when you mention that in the chat, the machine goes back to produce another snippet that many times is cut again. Not so smart or efficient. The only workaround I have found digging in the OpenAI discourse forum is to report the last line of the output so the machine can continue with (hopefully) the rest of the code. That approach seems to work better as I guess the culprit is the limitation of the maximum length of the output code. But the next problem is the code generated did not work. Sometimes the reason was quite evident like they are trying to use a data type

From Android to iOS

 Against my better judgment, I am moving away from Android and into Apple claws. The fact that Samsung has consistently priced its Galaxy line above almost anyone else is not helping. Not an Apple hater here so I thought I could give the iPhone 13 a try.  I was not eager to make such a switch as I dreaded moving all the apps to another system and keeping my data in the process. My wife did a while ago and lost all the WhatsApp messages in the process no matter how hard we tried. Meta is mostly the one to blame in my opinion.  So how was the move?  In a nutshell, not good.  I installed the Android app made by Apple to ease the transition. I selected I wanted to move all my data and apps together with WhatsApp messages. The Android and iPhone told me it would take 41 minutes, later just 22 minutes, which lasted several hours. Oddly, the Android transfer seemed to keep working at a slow pace while it looked stuck to 22 minutes on the iPhone side. Frustrated I went to bed.  The next mornin

The future of programming

Image
I am following the Advent of Code 2022 programming event. I was about to say contest, but I wonder if that would be the correct name. Anyway, AoC presents different programming challenges to the users to be solved daily from December 1st to 25th.  The humorous problem statements and quite doable problems make it a fun programming experience that does not use much of your time. But what shocked me this year was that GPT-3 was being used to solve problems at lightning speed .  Once I opened an OpenAI account, I could try how good this thing is at solving programming exercises. I see the system is powerful enough to solve many programming quizzes I wrote for my students. It even handles them if written in Spanish.  And it is not only that you get some code as a result, but you can keep asking for refinements in case the first version does not have all the required features. Of course, to provide such a level of guidance, you need to be knowledgeable about programming, but now I will be p

Learning new Java tools

Image
 While I have been using Java for almost 30 years, every now and then, I find new things I was not aware of in the Java toolset. Sometimes it is due to new libraries/classes; other times, it is brand-new tools.  I have been using Python lately, and I have found the use of an interpreter for testing code snippets very helpful. Unfortunately, that is not something you can do with Java, right? Well, that was the case till jshell was released. But what is jshell , let us say it is a Java's REPL. Like in Python, you can have an interactive session with the language interpreter, but now using Java.  How does it work? jshell is a command line tool you can find in OpenJDK or in Oracle's JDK since JDK 9 .  Not much different than Python, right? And you can ignore the semicolon at the end of each line :-) But it is more than just a calculator; you can instantiate any type of object, and it all persists in memory the whole session. It feels great to be able to have access to all the progr

Enforce line separator when using Scanner class in Java

Image
Parsing the data stream from a file or a socket can be very easy using the Scanner class. However, if you need to honor a given line separator sequence, using the nextLine() method can be problematic. The reason being the nextLine() method can accept a variety of line separators (like "\r\n", "\n", or "\r"). That behavior might be ok most of the time, but sometimes you may want to be sure that the line you are reading is precisely delimited by a given line separator and only by that one. The solution that works for me is not to use nextLine() but next()  after changing the token delimiter to the desired line separator. For example, I want to get a line read from the input delimited by "\r\n" only. ...  Scanner sc = new Scanner(s.getInputStream()).useDelimiter("\r\n");  String line = sc.next(); // before this was sc.nextLine(); ... Now full lines can be read as if they were a single token as now tokens are separated by the desired line s

Replacing my MacBook Air

 My 2013 MacBook Air is still well and kicking, all but the battery is in good condition. I replaced the battery for a random one off Amazon and it was no good. Eventually the seller refunded my money after I reported the system would just cut off when the battery indicated around 55%. My guess is the power management was poor or the dialog with the laptop's control logic was not good so battery voltage and battery capacity were not interpreted properly. Whatever the reason, I was left with a computer that could be used only when battery was over 60% and that it can shut off anytime the number was below that. The old battery only lasted for less than one hour and I was not sure whether I would be any luckier buying another battery unless it came from Apple (which was pricier).  OTOH, that laptop had served me well for almost nine years and though it was a top of the line model (that was expensive at the time) with an i7, 8GB or RAM, and a 512GB SSD, I chose to look for a new model

Set the time of Raspberry Pi Pico W using NTP

Image
 While the new RPi Pico W does not have a battery to keep the RTC, it does have something the previous model was lacking, network connectivity. So using the built-in Wifi module it can figure out the time and date from a network server using the Network Time Protocol (NTP).  It can work with it but the MicroPython binary I am using does not include a module for that at the moment (as the binary for ESP32 does) but it should not be a big deal to use that. As usual, it was easier to say than to do, but now I have it working. Please note that if you use the Thonny program, it will adjust the Pico real-time clock without warning you. So for a while, you may think it was your code that did it when it may well it is not the case. I just recycled some code I found but I was getting errors till I figured out the right offset for my board and timezone. You may need to tweak that to adjust it to yours. try: import usocket as socket except: import socket try: import ustruct as struc