Technical


20
May 09

How To: Get anti-aliased fonts in the Arduino and Processing IDE’s

Problem:

Arduino and Processing IDE’s both are java applications and don’t use anti-aliasing when displaying fonts on OS X.

Solution:

Add the Java Swing options to enable anti aliasing to the Info.plist file that OS X uses to launch the IDE’s.

Steps:
Right click the Arduino.app in the Finder and select ‘Show Package Contents’, double click the Contents directory and there you will find the Info.plist file. Open it in a text editor of your choice.
Add the following two lines under the Java option. See the screenshot for the exact location.

<key>VMOptions</key>
<string>-Dswing.aatext=true
</string>

UpdatePlistScreenShot

Now your code editor goes from looking like this crapness:

noaliasing

To this hotness:

withantialiasing

And even better you can use great looking fonts like Inconsolata and get an editor that looks this good:
inconsolasarduino


24
Jan 09

Networked Sound Board

Hi Everybody,

I’ve created a network sound board that you can use to have endless fun with co-workers.

In my office quad we have one OSX machine that is used to play music for everyone, it’s usually running last.fm, pandora or someones iTunes library as background music for everyone. Occasionally it gets cranked up when it’s time to get the led out. I was thinking that it’d be fun to be able to trigger sound effects on that machine from my machine, kind of like what happens on radio shows, expect that my co-workers wouldn’t really be able to change the channel.

So the itch was scratched and I’m proud to present the network sound board. It should run out of the box on any OSX machine with a recent installation of Python. If you’re on Windows or Linux it’ll work if you can find a command line audio player.  Anybody on the same network as the music machine will be able to trigger the sound effects from the comfort of their browsers. After you install there is a soundEffects folder that you can place sound files (.wav/mp3) into and they are instantly available, check the documentation for more info.

You can git the source from github at http://github.com/code128/networkedsoundboard/tree/master

It looks like this.

networked_soundboard

If you’re looking to extend it, adding the ability to upload new sounds from the flex interface would be sweet. If you do let me know.

Have fun.

P.S. If you can get samples of your co-workers saying things and add them to the server that would just be the icing on the comedy cake.


5
Jan 09

How To: Install Heated Handgrips on Your Motorcycle

The Parts

Hosted at instructables.com

Installing heated handgrips on a Suzuki Vstrom DL-1000


22
Dec 08

Just sitting here watching the logs go by.

Some times while working on remote servers I need to watch various log files. Typically for something like this I’ll create an extremely simple script that watches all the logs at once, since the next time I’m on that machine I’ll probably have forgotten the paths in question.

Something like this:

tail -f /var/www/apache/access.log /var/www/apache/error.log

The problem with that approach is really long lines wrap and I usually just care about the far left of the file, so I’ve been looking for a way to turn off wrapping in tail. Unfortunately that seems to be impossible. I tried messing with my shell to kill the extra characters with this:

echo -e "\e[?7l\c"

But that was messing up other things. The best solution I’ve found so far is to use less with these options

less +F -S /var/log/apache/access.log

+F puts it in a tail like mode and -S chops the line to the screen width, the only drawback is that it doesn’t intersperse the 2 files like tail does. I was hoping to pipe tails input into less in the this fashion but that didn’t seem to work right either.


10
Apr 08

Using Flexbuilder to edit and debug Flash Applications

The goal here is to use the excellent code editing and application debugging/profiling available in Flexbuilder and still have the rapid prototyping and layout ability that the Flash IDE gives to you.

To get started create a new “Actionscript Project” in Flexbuilder.

Now we will add some code to testDebug.as that traces out when the application is run:

package {
import flash.display.Sprite;
public class testDebug extends Sprite
{
public function testDebug()
{
trace("I am created")
}
}
}

With that code saved we will Debug this actionscript project and if everything is working correctly you should see something like this in your console window:

So far everything is working correctly in Flexbuilder, now lets get Flash into the action.

Open up flash and create a new Flash file, lets call it TestFlexBuilderIntegration.fla. Add some timeline animation or something so you know it’s coming from the Flash IDE, save this file into the root directory of your new Flex project.

Now set the document class of your Flash file to ‘testDebug.’ The AS class that we wrote in flexbuilder will now be the document class for your flash file as well.

Here come the tricks, under Publish Settings enable “Permit debugging”

Next in the Formats tab of Publish Settings change the .swf file to be published to the flexbuilder bin-debug folder.

The path will be something like

"/Users/YourName/Workspace/testDebug/bin-debug"

Now if you test the movie in Flash you should see your animation as well as the trace “I am created” in the flash IDE.

For the final steps we go back to Flexbuilder and under the html-template folder open index.template.html in a text editor. This is a template file that generates the index.html that is used to launch your app. We are going to update it so it points to the .swf generated by Flash IDE instead of Flexbuilder.

Replace all occurrences of ${swf} with the name of your Flash IDE generated swf file. In this case it would be TestFlexBuilderIntegration.

The moment of truth! In Flexbuilder Debug your project, it should launch the .swf in a browser for you and the animation you created should be playing, additionally the trace(”I am created”) line should show up in your console.

If Flexbuilder has trouble connecting to the debugger, right click in the swf in the browser and change the debugger connection to 127.0.0.1 and that should solve that issue.

Now you have the full power of Flexbuilder to code and debug and you still have the Flash IDE to layout movieclips and rapidly prototype things. Sweet.

Notes:

As you make changes to the code in Flexbuilder, you’ll need to go back to Flash and republish.

Profiling should probably work as well though I haven’t played with it yet.

You can set breakpoints in Flexbuilder without needing to republish.


21
Jan 08

Duplicate music file finder code.

I’ve been consolidating my music collection and found that there were lots of duplicate files.

Most of the dupes were named something like “Happy Birthday 1.mp3″ and “Happy Birthday.mp3″ would exist in the same directory. I’m not sure which program added these dupes, but removing 2500 or so of em by hand would not be fun.

Without further ado, here’s some python code that takes care of that problem for you. It only examines the filename, not the date or the bitrate or the actual file contents, etc. But you could of course extend it to do all those things.

Enjoy.

#-------------------------------------------------------------------------------
# Name:        cleanDuplicateMusicFiles.py
# Purpose:     Loops over a directory structure looking for 'duplicate' music files
#				and moving them to a safe directory for deletion.
#
# Author:      Joshua Bloom
#
# Created:     01/18/2008
#-------------------------------------------------------------------------------
#!/usr/bin/env python
 
import os
import sys
 
dupList = []
rootDirectory = "/Users/joshbloom/Music/iTunes/iTunes Music"
sequesteredFilesDirectory = "/Users/joshbloom"
 
def main():
    print "Starting search ..."
    checkDir(rootDirectory)
    print "Found %s dupes" % len(dupList)
 
def checkDir(path):
    print "Checking path '%s' for duplicates" % os.path.basename(path)
    for item in [ os.path.join(path, x) for x in os.listdir(path) ]:
        if os.path.isdir(item):
            checkDir(item)
        else:
            checkForDupe(item)
 
def checkForDupe(fName):
	'''Example: if we find 'Happy Birthday 1.mp3' and 'Happy Birthday.mp3' exists in the
	same directory we consider this a duplicate and send it for re-education. '''
    fileName = os.path.basename(fName)
    folderList = os.listdir(os.path.dirname(fName))
    if fileName.endswith("1.mp3"):
        for otherName in folderList:
            if otherName != fileName: #Make sure we aren't comparing with the current file
                if os.path.basename (otherName).startswith(fileName[:-6]):
                    #This is a duplicate
                    dupList.append(fName)
                    sequesterDup(fName)
 
def sequesterDup(fName):
    ''' Move em to a new folder, if you were confident you could change
 		this function to delete the file. '''
    try:
        print "Moving file: %s" % fName
        os.rename(fName, os.path.join(sequesteredFilesDirectory, os.path.basename(fName)) )
    except Exception, E:
        print E
 
if __name__ == '__main__':
    main()

20
Jul 07

Auto twitter SMS on/off

So I’ve spent a little more time thinking about this and have decided this utility would be better as a server utility that sits out in the cloud and monitors for my computer activity. If it doesn’t see activity for some set period it notifies twitter to re-enable SMS messages.
This takes care of any issues with me shutting down or closing my laptop/computer before my notifier can get its message out.

I’m thinking a python script, called by cron that checks for an indication that I’m active on my computer, if it doesn’t see the indication after some number of tries it turns SMS notifications on. That part seems pretty solid, what should I use on the laptop to signal my presence? If this was a Windows machine I’d be off and running but I’ve recently switched to a Mac and I don’t know the platform very well. Instant messenger sounds like something to tap into as it already has the concept of active/idle built into it, but I’m using Adium and it seems like Adium plug-ins are written in Objective-C which is totally foreign to me.

I think it’s time for some googling…


19
Jul 07

Auto update Twitter notifications to phone

I just started twittering and have found that getting alerts on my phone is great, just not when I’m also at the computer.
So being a good geek I thought I’d automate the process of turning mobile alerts on or off based on my laptop status.

So far I’ve scraped the HTTP headers and post variables so I know how to login and turn updates on or off. Next I need to package up a small utility to automatically decide when to send the commands.


6
Jun 07

Convert m4a to mp3

I’ve been moving a bunch of my brothers music out of iTunes for him so he can use it with portable players besides iPod. Unfortunately he encoded a lot of his cd’s in .m4a format. I found a decent utility for converting to mp3 (and other formats) http://www.bonkenc.org/

Unfortunately when you point Bonk at a directory full of m4a’s it crashes on certain files for some reason (encoding issues probably.) After the crash you need to setup all of your settings and add the files again, which is really time consuming and annoying.

To make this easier I whipped up a short python script that calls Bonk for you on each file, if it runs into a bad file it will rename the file for you so you don’t try to process it again.

Here’s the python code:

import os
import pprint
import subprocess
curDir = os.getcwd() # The current directory. This should contain your .m4a files
pathToBonk = "C:\\Program Files\\BonkEnc\\becmd.exe" #Where the becmd.exe file lives
problemFiles = [] #A list of files that failed conversion
#
for item in os.listdir(curDir):
	if item.upper().endswith('.M4A'):
		fullPath = os.path.join(curDir,item)
		cmd = '"%s" -e LAME -d "%s" "%s"' #The command to convert a single file
		cmd = cmd % (pathToBonk, curDir, fullPath)
		val = subprocess.call(cmd)
		if val == 0: #Successfull conversion, delete the original
			os.remove(fullPath)
		else:
			problemFiles.append(fullPath)
			print 'Problem converting %s' % item
			os.rename(fullPath, fullPath + ".BAD")
print 'These files had problems converting and have been renamed with .BAD extensions:'
pprint.pprint(problemFiles)

NOTES: This will delete the .m4a file after converting it. If you want to keep your old files for some reason make sure to run this on a copy of your files. IE in a different directory.


26
Feb 07

Primecondition.com

I saw Simon demo Primecondition.com at last months Refresh Phoenix meeting and I have to say that I was impressed.

The gist of it is you create your workouts. Input your exercises, sets, reps, times, etc and the app generates an audio track for you. The generated track has all the verbal cues that a personal trainer would have for you at a much lower cost :) You move the track onto your iPod or whatever device and hit the gym. It walks you through all the stuff that you have defined in your exercise while playing music to workout to.

This is a great application! The fact that its on the web just makes it easier to use and talk about and enables the sharing and community features that make apps so much more sticky.

Check it out if you need someone telling you what to do next at the gym.