Speech Synthesis and Bluetooth with Node.js

The next two modules I will be building for Node.js are a speech synthesis and a Bluetooth wrapper. No, they won’t be doing the super low level stuff like talking directly to Bluetooth hardware or generating audio from english text. Instead they will be wrappers for existing open source programs.

The Bluetooth module will work with hcitool and Bluez programs to provide similar functionality as my wireless module, e.g. trigger an event when a device is near, pairing, mounting filesystems.

The second module will be really simple. It will handle speech synthesis thanks to the Festival program. The voice will be as configurable as Festival will allow, and there will be callbacks for when a string has finished being spoken, to prevent messages from overlapping.

Both modules (as soon as I make them) will be available in npm.

Suppressing SSH MOTD Messages

There are two popular ways for supressing Message of the Day banners on SSH servers.

The first is probably the most correct, and is done on the remote server. Simply create a file named .hushlogin, and the SSH daemon should suppress the MOTD message.

touch .hushlogin

The second method might accidentally hide some SSH connection errors, but is a little more aggressive than the first, working to suppress MOTD’s from servers which ignore the .hushlogin file. This is simply adding the -q argument to the ssh connection command.

ssh -q USER@SERVER

Why would someone want to suppress a MOTD message? If you are running a non-interactive command, and want to parse the results locally, this is a must.

Re-Map Caps Lock key to Esc in OS X

If you are a VIM user, you probably find yourself stretching your poor little pinkey to the upper-left corner of your keyboard all of the time. How annoying! You probably also find yourself never hitting the Caps Lock key, which is totally useless since one can hold the shift key for the same effect, and annoying as heck because it is right on the home row!

Luckily, there is help. Download the PC Keyboard Hack application, and install it. This is a pretty cool app that lets us change what signals the OS interprets from key presses. It adds an entry to your System Preferences for configuring it.

To get the Caps Lock sending the escape code, you’ll want to set it to 53:

PC Keyboard Hack

PC Keyboard Hack

Now that that is done, pressing Caps Lock will now send the escape code. Go ahead, try it out! You’ll notice that the light on the key no longer toggles either.

But, we can do a little better. If you were to tap each key on your keyboard very quickly, you would notice that each of them sends their code. Even pressing the normal escape key really quickly still sends the escape code. However, if you quickly tap the caps lock key, you’ll notice that it doesn’t send the escape code, you actually need to hold it down maybe 100ms for the keypress to be acknowledged.

To fix this, go back to System Preferences, and go to Keyboard, then click the Modifier Keys button. On the dialog that pops up, change the Caps Lock key to perform No Action and press OK. After doing this, your Caps Lock key will be as quick as the rest of them.

Keyboard Preferences Modifier Keys

Keyboard Preferences Modifier Keys

PHP Social Network Bot

PHP Social Network Bot on GitHub

This is a script I threw together back in 2009. The code is really shoddy, but it is a decent proof of concept for building AJAX applications in PHP and displaying a status bar of updates throughout the execution of a long running PHP task.

The main guts of the script is bot.php, which uses an often overlooked PHP feature:

ignore_user_abort(TRUE);  # Closing browser will not kill script
set_time_limit(0);        # Script will run indefinitely

Notice the ignore_user_abort() function. Normally, when a browser window is closed, it tells the server to abort the request, even when we set the time limit to 0 (infinity). This function prevents the server from halting the execution of the script when this happens.

Why Android should switch to Go

I’m sure you’ve heard about the recent situation where Oracle is suing Google for using Java in their Android operating system. Which is pretty ridiculous, since Java’s popularity is supposedly due to it being open source. (This isn’t the first time Oracle has sued someone, btw).

Why did Google pick Java for Android, anyway? There are plenty of nicer languages out there. Google ultimately picked Java because of its popularity and being a systems programming language, meaning it can do some low-level hardcore stuff (like C), while higher level languages (such as JavaScript) don’t have that sort of control (or efficiency). Since Google picked such a popular language, it was easier for new Android developers to write applications.

Android is a very popular mobile platform these days. But, iOS is very close in market share. And you know what language they chose? Objective-C, which is about as proprietary as can be. Nobody uses Objective-C outside of development for Apple products. So, it is reasonably safe to say that Apple chose an unpopular language for its platform; a language controlled and “created” by Apple itself (or, at least NEXTStep, the predecessor of OS X).

Google really needs to pick a different language for Android, a language it will have more control of, a system programming language, where popularity doesn’t matter (as proven by Apple iOS). Google should use Go. From golang.org:

Go is an open source project developed by a team at Google and many contributors from the open source community.

Go is distributed under a BSD-style license.

What more can you ask for? Go is new and doesn’t have a lot of followers yet, but Objective-C wasn’t exactly a favorite among programmers either. Google is the primary developer of Go. Google has control over Go. Go is open source (BSD) and can be used for anything, meaning developers who learn Go can use it wherever they want. Go is a system programming language.

Here’s some more information about Go, e.g., why it was created in the first place:

Go was born out of frustration with existing languages and environments for systems programming. Programming had become too difficult and the choice of languages was partly to blame. One had to choose either efficient compilation, efficient execution, or ease of programming; all three were not available in the same mainstream language. Programmers who could were choosing ease over safety and efficiency by moving to dynamically typed languages such as Python and JavaScript rather than C++ or, to a lesser extent, Java.

Go is an attempt to combine the ease of programming of an interpreted, dynamically typed language with the efficiency and safety of a statically typed, compiled language. It also aims to be modern, with support for networked and multicore computing. Finally, it is intended to be fast: it should take at most a few seconds to build a large executable on a single computer. To meet these goals required addressing a number of linguistic issues: an expressive but lightweight type system; concurrency and garbage collection; rigid dependency specification; and so on. These cannot be addressed well by libraries or tools; a new language was called for.

Just for kicks, here are some syntax comparisons between the three languages I’ve mentioned:

Hello World in Go:

package main
import "fmt"
func main() {
    fmt.Println("Hello, World!")
}

Hello World in Java:

Notice the arbitrary class name, I think the entry point is defined in a manifest file, although I am not sure.

class ArbitraryClassName {
    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

Hello World in Objective-C:

#import <stdio.h>
int main( int argc, const char *argv[] ) {
    printf("Hello World!");
    return 0;
}
1 2 3 22  Scroll to top