Yet another homework-inspired addition to the API – a clock face image generator. My son brought home a worksheet from school with badly-drawn clock faces on it. On some clock faces the minute hand was pointing to the “6” (half-past) while the hour hand pointed directly at the 3, when it should have pointed either half way between 2-3 or half way between 3-4.
The clock-face image URL creates a random clock face if no arguments are present. Query arguments are ‘time’ to specify time in milliseconds since midnight. A ‘resolution’ argument controls the resolution of randomly-generated times and also to hide the seconds hand for anything greater than second. Values for ‘resolution’ are one of [second, minute, fives, quarter, half, hour]. The ‘width’ argument is a 3-digit size in pixels of the generated image.
A .json API URL returns some data useful for embedding the clock face as an interactive test:
Another homework-inspired demo of generating JSON + images on the server. This kind of thing can also easily be done with client side scripting. The advantages of doing it on the server is simplified client-side code (for older / less powerful devices) and nothing valuable on the client side for pirates! Arrr.
A script embedded in the page source requests a JSON response containing a sum with two ‘hundred square’ images showing the summands. Also in the response is an URL for an image showing a method of working out the sum using tens-and-units partitioning.
This had me mystified for a few hours: converting some old C code that worked on BrickOS with the gcc toolchain to use the Not-eXactly-C from bricxcc. The c sources must be compiled with the Next Byte Code compiler nbc. The c source file must have the file extension .nxc. I could see in the NXC Programmer’s Guide that printf is listed as a “Standard-C API function“, that nxc has a ‘cstdio API‘ which contains printf and a #include preprocessor command, but I couldn’t find a ‘cstdio.h’ anywhere.
The solution is to check the nbc command line arguments with:
and see the ‘-EF’ switch for ‘Enhanced Firmware’. A command line like:
I use One-JAR to package a number of .jars from different project into a single jar file which is my distributable application. Within that jar file are a multitude of utility classes. To run my application I use
java -jar myonejar.jar
which launches my application’s main class com.firtl.MainClass just fine. I’d also like to be able to run some utility classes from the same jar like this:
This doesn’t work because One-JAR produces a jar file for an application class com.simontuffs.onejar.Boot – your own application’s jar file ends up in a /lib ‘directory’ in the jar file. You need to tell the Boot class to load and execute your utility class. You can pass command-line ‘switches’ to the Boot class via the Java system property facility. One-JAR supports a few, some useful help text is available by:
java -jar myonejar.jar --one-jar-help
The system property you need to set is one-jar.main.class – make sure you set the property before -jar: