Posts

Showing posts from 2022

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

Testing the ESP32-C3 ...

Image
  Having used the ESP32 using both Arduino IDE and MicroPython, I have been quite happy with it. However, I have found MicroPython more stable and powerful, especially if multithreading is needed. Do not get me wrong, you can get multiple tasks in FreeRT too, but it gets tricky quickly.  ESP32 features a dual-core 240 MHz Xtensa 32-bit processor, but the ESP32-C3 changes that to a single-core 160 MHz RISC-V processor. They both keep the handy Wifi and Bluetooth interfaces and a nice collection of built-in peripherals and communication interfaces (SPI, I2C, I2S).  What I did not know was the new architecture was also supported by Micropython , which was a nice surprise. So I went on and bought one of them to give it a go. The system feels a bit less powerful than its dual-core sibling but it works nicely with Micropython nonetheless. Having fewer I/O pins available can be a problem for certain applications but I definitely recommend this device if you need a wifi-enabled microcontrol

Crimpers, crimpers, crimpers, ...

 I happen to have bought a few crimpers over the years. I understand how convenient is to have a trusty connection using a crimper, but I have had trouble shelling out the hefty sum a brand-new required. Being mostly a hobbyist I had a difficult time accepting paying hundreds of dollars for a glorified set of pliers that I would use to make less than fifty contacts a year.  However, whenever I have had a hint that an affordable tool could do a reasonable job within a budget I have bought a new crimper. Most of the time to get a disappointing result, or a poor one at best. I usually deal with 2.54 mm DuPont and Molex connectors so I have bought SN-28B (actually twice by mistake), TU-190-8, and another one I bought from RS. The one from RS almost did the trick for DuPont but it crushed the top metal too flat so I needed to use some pliers so I could squeeze it into the plastic part. The two jaws did leave a small space on the side so I reckon the crimp was good but the geometry was off. 

The trusty ImageMagick package

Image
  Seven years ago I made a simple script to turn a pile of scanned exams into a personalized email for each student to get their marked exams. I used our photocopy machine that doubles as a scanner to create a large PDF file containing all the exams. ImageMagick's convert, identify and mogrify commands were used within the script for several massaging of the scanned pages but, years later, using WSL instead of a Linux machine, I was shown a weird error. None of the commands seemed to be able to handle a PDF file as a source anymore: identify-im6.q16: attempt to perform an operation not allowed by the security policy `PDF' @ error/constitute.c/IsCoderAuthorized/408. Luckily, I quick search lead me to a solution: just edit /etc/ImageMagick-6/policy.xml and enable PDF use, which was disabled as a safety feature as PDF can be an attack vector. More info .

Remote development of a hardware device

Image
I am familiar with helping other people remotely using tools like TeamViewer. Many times it has to do with a friend having trouble with her computer, operating system, or software.  But quite recently, I took care of the development of a complete machine without ever touching it even once. The project was part of a friend's Ph.D. work about the proper tensioning of old paintings. He asked me for help with a specific need in mind. He needed a machine that could push a probe against a canvas surface while monitoring the back force generated.  As usual, there were a few more constraints, like it was needed to be used in a few weeks as an appointment was already made with an important European museum. And all the parts needed have to be available online to get quickly to my friend's residence in Rome. Fortunately, my friend can solder and wire or build a contraption, though he cannot code. So the plan was to make this happen by shipping all the parts to his apartment and he will do