Solve upload error in grunt-s3

Using grunt-s3 to upload files to AWS S3 on a CNAME’d bucket using Grunt I ran into getting upload errors including Fatal error: write EPIPE.

After digging around in the grunt-s3 source code and debugging it turned out to be caused by AWS responding with 301 (Permanent Redirect). To solve this, explicitly set the region in the grunt-s3 options according to AWS’s table over regions.

Command-line base64 encoding of file into clipboard

Often I find myself in the need to base64 encode a file. Typically an image to inline in a CSS file. I added the following to my ~/.bash_profile (OSX) for convenience:

function base64() {
openssl base64 < $1 | tr -d '\n' | pbcopy

Now I simply run base64 <filename> from the terminal to get the base64 encoded file in the clipboard for easy pasting into wherever I want to.

Simple Mantis JSON API

Mantis has a SOAP API, but I wanted JSON to display the most recent tickets on a web page using JavaScript. Hence I wrote a simple wrapper in PHP that does a SOAP call and returns the result as JSON to be conveniently digested by JavaScript.

Put the mantisconnect_json.php file wherever you want, it doesn’t need to be on the same server or have the same domain as the Mantis installation. Edit the MANTISCONNECT_URL and your Mantis username and password.

The query string parameter name defines what SOAP action to call, the rest of the query string parameters are passed as arguments in the SOAP call. Note that the Mantis username/password is inserted automatically as arguments by the PHP code to avoid having you expose it publicly in JavaScript (but they may be overridden if desired).

Please note that this is a very simple wrapper for read-only purpose (e.g. it will not work to create new issues).

Wipe and shutdown remote Linux server over SSH

Wiping and shutting down a headless linux server over SSH.

Copies zeros over the whole disk.

dd if=/dev/zero of=/dev/sdaX

Where sdaX is the device you want to wipe. Read discussion at security.stackexchange.

Since the shutdown command will be trashed by the wiping, we need to force shutdown in another way.

echo 1 > /proc/sys/kernel/sysrq
echo o > /proc/sysrq-trigger

Don’t try this at home.

Fix Tab Indenting in Coda

Since I’ve got a Swedish keyboard on my MacBook Pro tab-indenting using “Shift Left ⌘[" and "Shift Right ⌘]” does not work (or actually only Shift Right works).

The reason for this is that you must use the Alt-key to get a bracket [, and apparently Command-Alt-[ is already taken by toggling zoom on/off.

To make tab-indenting work in Coda, open System Preferences, Keyboard, click Keyboard Shortcuts tab, select Universal Access and finally uncheck the box for Turn zoom on or off.

Developing Large-Scale JavaScript Web Sites – SWDC2010 slides

Being very humbled to be part of the star struck lineup at The Scandinavian Web Developer Conference 2010 I did a talk about Developing Large-Scale JavaScript Web Sites (slides available here as PDF).

The presentation is basically a quick high-level overview of some of the main points I’ve encountered after several workshops at different clients wanting to take the step from a legacy server centric web site architecture to a modern rich client side implementation.