Scala, Java, Unix, MacOS tutorials (page 312)

If you want to connect to the NeuroSky ThinkGear API -- what they call the ThinkGear Socket Protocol -- this code shows you how to do it, at least in Scala. It consists of a few pieces of code I pulled from this GitHub repo. I wrote this code to help debug a problem I was seeing with the data.

The RawReader class does all the work. It opens a socket on the right port, then sends the necessary JSON to that socket to get things started. After that I just read the raw data that the API writes to the socket.

This is the fifth in a series of tests using the NeuroSky MindWave headset, their ThinkGear software, and my own custom software to record brainwaves over time, and graph them. I intentionally tried to focus/concentrate very hard at the beginning of this test, and then transitioned into meditation. I continued to meditate throughout the session, but according to their software/hardware, I tailed off at the end. In my opinion, this is a problem with their hardware -- it becomes less accurate as you use the system longer.

Wow, this is just wicked. I lived in Talkeetna, Wasilla, and Palmer, Alaska, and never had air conditioning the entire time. I hope everyone finds a way to stay cool.

Here’s an example of how to create an X/Y graph in Scala using JFreeChart and Scala Swing:

Yesterday I shared a simple first example of using ShadajL’s NeuroSky MindWave Scala library. Today I’m taking that a little further to share some code for a simple brainwave data recorder.

The premise is this: You put on a MindWave headset, start the recorder, and then do whatever you want to do -- work, meditate, sleep, whatever -- and the recorder records your brainwaves while you do those things. It writes the data in a CSV format so you can graph it, or do anything else you want with it.

After hearing about ShadajL’s presentation at Scala Days 2013 using a MindWave headset, I decided to buy a headset to see how if it really works. After a little while I got the hang of using the headset, so I decided to try ShadajL’s NeuroSky Scala library (named neuro-thinkgear) to see how it works as well.

If you ever wanted to get access to global operating system keystrokes from a Java or Scala Swing application, you can do it with the jnativehook library. Here’s a short demo:

Here’s the full Scala source code for the demo. I put a few comments in the code to highlight the important areas:

Is Swing dead? I don’t know. I’ve written several Swing apps that I use every day, but I can’t speak for the rest of the world.

What I can say is that I really like Scala Swing. How I wish it was available ten years ago ... you’ll never know.

But getting to the point, after working with Scala Swing a little bit, I decided to see if I could write a web browser with it. The short answer is that here’s what the browser looks like:

To center a window/frame in a Scala Swing application, add this line to your frame definition:

peer.setLocationRelativeTo(null)

Here’s what this looks like in the top method definition inside a SimpleSwingApplication:

As a quick note, to use the Scala Swing library (scala.swing.*) with an SBT project, all I had to do today was add this line to my SBT build.sbt file:

libraryDependencies += "org.scala-lang" % "scala-swing" % "2.10+"

Once I did that, I was able to compile the Scala Swing project normally with the sbt compile command.

I ordered one of these Brainwave Starter Kits today. It includes something called a MindWave Mobile device, which is supposed to provide some brainwave biofeedback. I did this out of curiosity after learning that a young developer created a Scala game that he can play with biofeedback.

The Scala Cookbook is coming soon ... August 21, 2013, to be exact. It’s available for pre-order on Amazon.com now, so I thought I’d share some information about the book here today.

I woke up this morning (June 7, 2013) thinking it must be about 200 days to Christmas. Foregoing any simple ways to determine that, I decided it would be a good time to use the nscala-time library, a Scala wrapper around Joda Time.

Sticking with the time theme, I haven’t much free time today, so without further ado, here is some Scala code that determines the number of days between today and Christmas:

I recently bought the old Kung Fu tv series on DVD, and was frustrated that I couldn't create screen captures of it with tools like SnapNDrag. All I wanted to do was create one Kung Fu ’grasshopper’ comic strip.

So I wrote a Scala script (shell script) to create a screen capture. Here’s the source code: