A while back, I started playing around with Google App Engine (Java) and the lightweight, Groovy , Gaelyk. There’s also a great library written for using the low level datastore in App Engine called Objectify.
I decided to write a little Groovified wrapper for Objectify (which already does most of the work) and turn it into a plugin for Gaelyk. It adds a little syntactic sugar, and although it doesn’t have everything, it is working nicely for me so far. Check out the Obgaektify site to learn more.Archive for the ‘Coding’ Category
Audacity SoundFinder Plugin
I modified the Silence Finder plugin that comes with Audacity, and turned it into a Sound Finder plugin. The original plugin let you specify the minimum time period and volume level needed to count as a silence, and then inserted a label at some point during the silence. This new Sound Finder plugin creates a label that stretches the length of each sound segment.
I’ve now used this to help me add text transcriptions to about 80 audio files in 4 languages (Beembe, Bekwel, Mbochi, and Teke). The default parameters have worked pretty well for me, but you may need to adjust them depending on your recording.
This is the Sound Finder dialog:
This is an example of the resulting labels. You can replace the labels with your own text. In my case, I will replace the numbers with a text transcription.
Finally, here’s the plugin file that you can download. Put it in the Plug-Ins folder inside your Audacity folder. After restarting Audacity, you should be able to access the plugin from the Analyze menu.
Directory Recursing Thumbnail Generator
Put this script in a particular directory (or change the directory specified in startDir variable
and it will recurse through all sub-directories, creating thumbnails of the images (jpg, png, gif, or bmp).
If you change the deleteOriginal variable to true, it will delete the original image for you afterwards.
import javax.imageio.*
import java.awt.*;
import java.awt.image.*;
def startDir = new File(".")
def deleteOriginal = false
def thumbWidth = 200
def thumbHeight = 150
startDir.eachFileRecurse{file->
if(file.name =~ /\.(JPG|jpg|PNG|png|GIF|gif|BMP|bmp)$/)
{
def imgType = file.name.replaceAll(/[^\.]*\.(JPG|jpg|PNG|png|GIF|gif|BMP|bmp)$/, "\$1")
def imgPath = file.getCanonicalPath().replaceAll(/\.(JPG|jpg|PNG|png|GIF|gif|BMP|bmp)$/, "_Thumb.\$1")
println("$imgType, $imgPath")
//load each image
img = ImageIO.read(file)
println (file.name + " " + img.width + "x" + img.height)
//output scaled thumbnail image
width = thumbWidth
height = thumbHeight
if(img.width < img.height){width = thumbHeight; height = thumbWidth;}
BufferedImage thumbImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D gThumbImg = thumbImg.createGraphics();
gThumbImg.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
gThumbImg.drawImage(img, 0, 0, width, height, null);
ImageIO.write(thumbImg, "$imgType", new File(imgPath))
if(deleteOriginal)
{
file.delete()
}
}
}
Unicode Files in Groovy
It took a little while for me to track down how to read and write Unicode-encoded files using Groovy. Here’s the answer:
/*
Given a file called test.txt that's filled with text in UTF-8 format,
here's how to use Groovy to read it in, preserve the encoding, and
output it to a file called testout.txt, also in UTF-8 formatting.
*/
def inF = new File("test.txt")
def reader = inF.newReader("UTF-8")
def outF = new File("testout.txt")
outF.withWriter("UTF-8"){writer->
reader.eachLine{line->
writer.write(line)
}
}
Dynamic Swing
//Groovy script that demonstrates dynamically adding and removing text fields from a Swing form
import groovy.swing.SwingBuilder
swing = new SwingBuilder()
addButton = swing.button(text: 'Add Field', actionPerformed: {addField()})
remButton = swing.button(text: 'Remove Field', actionPerformed: {removeField()})
frame = swing.frame(title:"Test Dynamic Fields", size: [200,400], defaultCloseOperation:javax.swing.WindowConstants.EXIT_ON_CLOSE)
{
panel = panel()
{
vbox = vbox(id:'vbox')
{
hbox()
{
widget(addButton)
widget(remButton)
}
}
}
}
fields = []
fields << swing.textField(text: fields.size())
vbox.add(fields[0])
//frame.pack()
frame.show()
def addField()
{
field = swing.textField(text: fields.size())
fields << field
vbox.add(field)
vbox.revalidate()
}
def removeField()
{
if(fields.size() > 0)
{
field = fields[-1]
vbox.remove(field)
fields.remove(fields.size() - 1)
}
vbox.revalidate()
}
Virtual Board Games
I’m currently working on a virtual board game engine written in Java. The idea is to represent game tokens with images (.png or .svg mostly), and allow the players to manipulate these tokens (flipping cards, rolling dice, moving pawns, spinning dials, etc.).
I’m using Ryan Gordon’s ManyMouse library to allow players to each have their own mouse which controls their own cursor. Permissions set on each token will determine what operations a given player can perform - moving, rotating, flipping, etc.
So far, the basics are coming along well. You can load in tokens, change between token images, rotate tokens, move tokens, and use multiple cursors to affect the environment. I’ll post more details as I make progress.
New Site
Every once in a while, I visit register.com to see if any good domain names with my name are available. I discovered recently that jeremy-brown.com was available, so I decided to snatch it up.
I installed this nice WordPress theme Dark LiquidCard, created by the French artist and designer Jori Avlis. Thanks Jori! With a few tweaks to the code, I was able to enable WordPress widgets in the sidebar. Now the site is up and looking good.





