Profile cover photo
Profile photo
Guy McArthur
I enjoy 2pi.
I enjoy 2pi.

Guy's posts

#Java8 Sorting a map by value in descending order and printing out the top ten key-value pairs (with the Streams API and a judicious static import):

.forEachOrdered(e -> System.out.printf("%.1f %s%n", e.getValue(), e.getKey()));

I use Maps AKA hashes all the freaking time. Often, to store numerical values and increment them in a loop. Like this:

Map <String, Float> map = new HashMap <> ();

And something like this code that has to be repeated every time, say to add a loop variable num to the value in the hash, if it exists:

Float val = map.get(str);

if (val == null)
map.put(str, num);
map.put(str, num + val.floatValue());

Now, in Java 8, that can be simplified to a 1-liner:

map.compute(str, (key, val) -> val == null ? num : num + val);

Post has attachment
Dystopian Dreamland... progressive sci-fi rock by Porcupine Tree.

Post has attachment
I've been using the HTML framework Bootstrap (originally from Twitter) in a new web app and to update some pages (e.g.  I like the default clean look (many 3rd party themes are available) and component ["widget"] set that meets most of my needs. I like that you can do most everything via markup or via API (JavaScript). I like that you can do a responsive layout to handle all device screen sizes. I like that it uses jQuery because I already always use jQuery for any sort of DOM work.

Upgraded from Kubuntu 12.04 to 14.04, another Long Term Support release. Really really great; many small improvements from what was an already solid base. Some of the highlights for me are:

* with the 3.13 kernel, I no longer need the ATI/AMD proprietary driver, which they stopped supported anyways. Great 3D support (WebGL finally works, can use the latest Google Earth) and dynamic power management (before the open source drivers ran the card at max, not good for a laptop)

* wifi reconnect on wake is noticeably faster

* bluetooth audio works (not just kinda/sorta)

* the chat app (Kopete) worked straight away with our [work] encrypted Jabber setup

Post has attachment
I had a set of data to investigate, database output as tab-delimited.
I decided to get a little groovier, and make a re-usable method that could create either a time series or regular scatter plot, for multiple data series, creating the interactive app from which the screenshot is saved. I also wanted it to default to a larger size, so used the Java API to get the screen size.

That file is available here.

The code that calls it, specific to this set of data, is pretty simple:

import java.text.SimpleDateFormat

fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")

@Grab(group='jfree', module='jcommon', version='1.0.16')
@Grab(group='jfree', module='jfreechart', version='1.0.13')


ts = new TimeSeries("values")
dataset = new TimeSeriesCollection()
    row = it.split "\t+"
    if (row[1] != "NULL") {
       ts.add new Second(fmt.parse(row[0])), row[1] as double

import charts

Post has attachment

Correct me if wrong: there is no #android   or #Google equivalent to #iTunesU   or the #iTunes podcast directory for browsing and syncing free educational content.

Isaac Asimov would read a newspaper and then fold it back up so perfectly that it looked brand new (a skill honed working in his parent's Brooklyn candy store/mart). He also became known at his publisher's offices (in Mad Men era Manhattan) as "the man with a thousand hands" for his habit of pinching secretaries' bottoms). He would have been 93 next week.

Comparing a folder of files versus those in a checked-out copy:

find . -name '*.ext' -exec diff -I ID -I Revision -qw {} "/Folder/{}" \;
Wait while more posts are being loaded