A quality pen to stick with. OHTO GS01-S7 pen is made in Japan

If you are a person who still uses pens to take notes or write anything else on paper then you may find this post interesting. Also, do you think any pen will do or, maybe, selecting a pen is an important step to make? I think a pen that is comfortable, durable and nice is a very important thing to have.

Pens come in a number of types like ballpoint, rollerball and fountain. Also, they can be made from different materials such as plastic, aluminum and even wood. The ink that is used in pens can be water or oil based. In addition, the refill tip can have a different diameter which effects the thickness of the lines you can draw or write.

Parker Jotter pen I had for a long time

I also like the Frixon clicker series of Pilot pens which are made in Japan and have a renowned Japanese quality. These pens allow you to erase what you’ve written and functionally they are just like pencils, except you don’t need to sharpen them.

Frixon clicker erasable pen

Recently, I’ve been looking for a new comfortable pen and a quick search brought to my attention an interesting and peculiar pen from Japan. It was OHTO GS01-S7 ballpoint pen with an aluminum body and having an oil-based black color ink. What is interesting about this pen is that its body comes in a number of colors, while the ink is always black. This pen feels nice to hold and it looks good. Functionally it resembles Parke Jotter pen, but it looks more engineered, in my opinion, and it feels more comfortable than Jotter. Maybe, it’s due to the fact the OHTO pen is longer than Jotter and has a hexagonal cross-section.

OHTO GS01-S7 with 0.7 mm refill

One unexpected feature of OHTO GS01-S7 is that you can swap its original refill with the Parker Jotter one and visa versa. I’ve found about this while watching a review of the OHTO pen by a Japanese youtuber.

Parker Jotter and OHTO GS01-S7 disassembled, side by side
OHTO pen with Parker refill
Parke Jotter pen with OHTO refill

How to solve programming tasks with GPT powered chatbot

Photo by D koi on Unsplash

Code generation to the rescue

As you probably have heard by this time ChatGPT a machine learning based chatbot created by OpenAI is very famous. It is based on Generative Pretrained Transformer model, hence, GPT in short. It’s quite successful in various tasks ranging from text summarization, essays generation to questions answering. But did you know that it can also generate working code in various programming languages? If you didn’t then this post will provide you with some ideas to try.

Task at hand

For example, in the JSON Crack online tool below you can see how such a list of objects can look like

To summarize what needs to be done is as follows

Using Java Stream API approach

Java 8 version introduced a powerful Streams API that allows processing of collections in a functional way. For example, it is possible to filter, apply mapping or sorting to a collection in a single line of code using a declarative syntax somewhat similar to SQL. So, accomplishing the task of sorting a list of objects that have a createdDate field of Date type is quite simple and if you google how to do it you’ll find a number of solutions.

For example, this is how it can be done based on the Stack Overflow answer.

List<Order> orders = list.stream().
                        sorted(comparing(Order::getCreatedDate).
                        collect(Collectors.toList());

First prompt

Write a java code to sort a list of objects while converting a string field to date type

and this is the solution that the Bing chatbot provided


Certainly! Here’s an example of a Java code snippet that sorts a list of objects while converting a string field to date type:

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        List<YourObject> yourList = new ArrayList<>();
        // Add objects to yourList

        // Sort the list based on the string field "dateString"
        Collections.sort(yourList, new Comparator<YourObject>() {
            @Override
            public int compare(YourObject o1, YourObject o2) {
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                try {
                    Date date1 = dateFormat.parse(o1.getDateString());
                    Date date2 = dateFormat.parse(o2.getDateString());
                    return date1.compareTo(date2);
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                return 0;
            }
        });

        // Print the sorted list
        for (YourObject obj : yourList) {
            System.out.println(obj);
        }
    }
}

class YourObject {
    private String dateString;

    public String getDateString() {
        return dateString;
    }

    public void setDateString(String dateString) {
        this.dateString = dateString;
    }

    // Add other fields and methods as needed
}

In this example, we have a list of objects of type YourObject that contains a string field called dateString. We want to sort the list based on this field, treating it as a date.

To achieve this, we use the Collections.sort() method and provide a custom Comparator implementation. Inside the compare() method, we parse the dateString of each object into a Date object using a SimpleDateFormat. We then compare the two dates using the compareTo() method and return the result.

Please note that you need to replace YourObject with the actual class name and modify the code according to your specific requirements.

Let me know if you need any further assistance!

Second more nuanced prompt

write code to sort a list of objects while converting a string field to date type using java stream api

Certainly! Here’s an example of a Java code snippet that sorts a list of objects while converting a string field to date type using the Java Stream API:

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        List<YourObject> yourList = new ArrayList<>();
        // Add objects to yourList

        // Sort the list based on the string field "dateString" using Java Stream API
        yourList.sort(Comparator.comparing(obj -> {
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            try {
                Date date = dateFormat.parse(obj.getDateString());
                return date;
            } catch (ParseException e) {
                e.printStackTrace();
            }
            return null;
        }));

        // Print the sorted list
        yourList.forEach(System.out::println);
    }
}

class YourObject {
    private String dateString;

    public String getDateString() {
        return dateString;
    }

    public void setDateString(String dateString) {
        this.dateString = dateString;
    }

    // Add other fields and methods as needed
}

In this example, we have a list of objects of type YourObject that contains a string field called dateString. We want to sort the list based on this field, treating it as a date.

To achieve this using the Java Stream API, we use the sort() method of the List interface and provide a lambda expression as the comparator. Inside the lambda expression, we parse the dateString of each object into a Date object using a SimpleDateFormat. We then return the parsed date for comparison.

Please note that you need to replace YourObject with the actual class name and modify the code according to your specific requirements.

Let me know if you need any further assistance!

Testing the generated code almost as is in an online Java compiler

Well, that last answer was what I needed. We can take it and check that it can run almost as is in an online Java compiler. I made a couple of small adjustments in the generated code:

  • I instantiated three objects with dateString populated.
  • I added these objects to a list and
  • I adjusted println function to print the dateString field, instead of the object itself.

This is how it looked after running

// Online Java Compiler
// Use this editor to write, compile and run your Java code online

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        List<YourObject> yourList = new ArrayList<>();
        // Add objects to yourList
        YourObject obj1 = new YourObject();
        obj1.setDateString("2023-09-01");
        
        YourObject obj2 = new YourObject();
        obj2.setDateString("2022-07-02");
        
        YourObject obj3 = new YourObject();
        obj3.setDateString("2021-08-06");
        
        yourList.add(obj1);
        yourList.add(obj2);
        yourList.add(obj3);

        // Sort the list based on the string field "dateString" using Java Stream API
        yourList.sort(Comparator.comparing(obj -> {
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            try {
                Date date = dateFormat.parse(obj.getDateString());
                return date;
            } catch (ParseException e) {
                e.printStackTrace();
            }
            return null;
        }));

        // Print the sorted list
        yourList.forEach((obj -> System.out.println(obj.getDateString())));
    }
}

class YourObject {
    private String dateString;

    public String getDateString() {
        return dateString;
    }

    public void setDateString(String dateString) {
        this.dateString = dateString;
    }
    

    // Add other fields and methods as needed
}

Blowing your socks off

How to import code into Commodore 64 emulator

Back to BASIC

Recently, I went to BASICs and I found it fascinating. It is much more interesting programming paradigm then compiled languages development as C like languages since you can program in BASIC interpreter and in assembly at once and get feedback instantly. Also, 6502 CPU is quite easy to understand and memory mapping of the 6502 is also straightforward and interesting to play with.

How can you do it?

Prerequisites

Let’s do it

  • Extract the zip file where you want it and review the contents of the folder

  • Open Windows Command Prompt (aka cmd).
  • Run the command below to convert the text file to prg format.
C64List basic.txt -prg

Now let’s go to the Commodore 64 online emulator website and import our file.

Below comes the video of the process above.

Back to BASICs. Commodore 64 BASIC V2.

Fast-forward to nowadays, I continue to be interested in how hardware and software work and watched quite a few reverse engineering videos on YouTube, like Apollo Guidance Computer restoration series on CuriousMarc channel and others. Due to this YT algorithm suggests me similar videos. A couples of days ago it suggested me to watch the 27c3: Reverse Engineering the MOS 6502 CPU video about how 6502 CPU was reverse engineered by peeling layers from the chip, taking photographs and then reconstructing actual transistors from the photos. The talk was given by Michael Steil who extensively contributed to documenting everything there is about MOS 6502 CPU and various types of BASIC it ran.
The people who reversed engineered the MOS 6502, Greg James, Brian and Barry Silverman also wrote a
JavaScript visualization of the inner workings of the 6502 as it chugs alone.

It turns out that Michael Steil implemented a C based simulation of the MOS 6502 and hooked it up to the Commodore BASIC emulator to see how it worked. And it worked indeed!

Prerequisites

  • Interest in this topic 🙂
  • Operating System: Linux or Windows 10 with Windows Subsystem For Linux 2 (WSL2)
  • Source control software: git (should come preinstalled on WSL) to be able to check out the implementation of the 6502 CPU and BASIC
  • make tool installed
  • C compiler like, gcc installed

What to expect?

Let’s begin

Install WSL and Ubuntu

Clone GitHub repository

Now, that we have Ubuntu installed let’s download (clone) the MOS 6502 repository from GitHub to be able to build it locally.

  • When you navigated to that repository in GitHub click on the code button in the right upper hand side,
  • and click on copy icon

Create directory to clone repository into

mkdir perfect6502
cd perfect6502
git clone https://github.com/mist64/perfect6502.git
Cloning into 'perfect6502'...
remote: Enumerating objects: 643, done.
remote: Total 643 (delta 0), reused 0 (delta 0), pack-reused 643
Receiving objects: 100% (643/643), 997.31 KiB | 4.96 MiB/s, done.
Resolving deltas: 100% (391/391), done.

Install make and gcc on Ubuntu

sudo apt install make
sudo apt install gcc
make
amc@MINE-LAPTOP-130JJTQ6:~/perfect6502$ make
cc -Werror -Wall -O3   -c -o perfect6502.o perfect6502.c
cc -Werror -Wall -O3   -c -o netlist_sim.o netlist_sim.c
netlist_sim.c: In function ‘getGroupValue’:
netlist_sim.c:390:1: error: control reaches end of non-void function [-Werror=return-type]

To fix this issue there is a need to apply Pull Request (PR) one of the users submitted.

git fetch origin pull/10/head:pr_number10
OBJS+=measure.o

Update Makefile using Windows notepad

explorer.exe .

amc@MINE-LAPTOP-130JJTQ6:~/perfect6502$ make
cc -Werror -Wall -O3   -c -o perfect6502.o perfect6502.c
cc -Werror -Wall -O3   -c -o netlist_sim.o netlist_sim.c
cc -Werror -Wall -O3   -c -o cbmbasic/cbmbasic.o cbmbasic/cbmbasic.c
cc -Werror -Wall -O3   -c -o cbmbasic/runtime.o cbmbasic/runtime.c
cc -Werror -Wall -O3   -c -o cbmbasic/runtime_init.o cbmbasic/runtime_init.c
cc -Werror -Wall -O3   -c -o cbmbasic/plugin.o cbmbasic/plugin.c
cc -Werror -Wall -O3   -c -o cbmbasic/console.o cbmbasic/console.c
cc -Werror -Wall -O3   -c -o cbmbasic/emu.o cbmbasic/emu.c
cc -o cbmbasic/cbmbasic perfect6502.o netlist_sim.o cbmbasic/cbmbasic.o cbmbasic/runtime.o cbmbasic/runtime_init.o cbmbasic/plugin.o cbmbasic/console.o cbmbasic/emu.o
cbmbasic/cbmbasic

What can you do now?

You can do even more pretty trick using BASIC to print “Hello, world!” in Assembly code. I saw this implementation in the “Hello World” on Commodore 64 in Assembly Language, Machine Code video.

You can watched how it worked in real time below

Some useful commands to know

PRINT CHR$(147)
NEW
SYS 64738
LIST

To update particular line there is a need to retype it in this emulator, while in other emulators you can edit them. As you can see on the C64 online emulator

SUMMARY

REFERENECES