Self-signed certs with secure WebSockets in Node.js

First generate your self-signed certs:

Then create your httpsServer from an express app using node’s built-in https server:

Then setup your websocket server (ironically this will use the same port as the http server, I didn’t know this but I guess protocols can share ports? — this had me going for awhile).

Now browse to server and accept the self-signed cert in Chrome. Then websockets should now work isnide the browser.

Open a chrome devtools console and type:

Dumping a mysql or mongo database for offsite backups

If you’re doing offsite backups of your file system, AS YOU SHOULD BE, you should also dump your database periodically and include those in your offsite backups.

Here is a simple bash script that will create a timestamped sql/gzip file of all your databases using mysqldump. You can use this file to import back into a database should you need to restore later.

First you need to install the mysql client libraries (debian):

…this should provide the mysqldump binary we will be using in the script below:

What to do if you see your PHP script relies on session side-effect error message.

I came across this error a few times, enough to where I dug around and finally found the real fix to suppress the error completely.

Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively in Unknown on line 0

I was able to suppress the error by properly upsetting a session variable:

Google Code Search Released

Finally, Google has released a code search that enables you to search through source code.

Similar to and others.

I haven’t seen too much of my own publical GPL code in here, but it’s a start.

The question is: Can I search for special characters?

Sleeping Between API Requests

I spent a few minutes today debugging the reason why one of my “rake” tasks was getting 503 connections (Service Unavailable) from Yahoo’s API.

I had mistakenly thought this was due to the fact that Yahoo limits the number of requests to their API in a given day. I decided to put a “sleep” call in my code to be sure it wasn’t being denied access due to server-side throttling. Sure enough — all requests succeeded after adding a brief call to the “sleep” function.