Get nested object properties using string path

Another take on a minimalistic implementation to get nested object properties by using a string path in JavaScript.

Validate Swedish Personal Identity Number (personnummer) using JavaScript

Put together a function to validate Swedish Personal Identity Numbers (personnummer) using JavaScript for use in client-side form input validation.

Use Apple TV without remote, without WiFi and without Home Sharing enabled

If you managed to lose your Apple TV remote, not have it connected to WiFi, Bluetooth is off and Home Sharing is not enabled so you can’t use the Remote App on your iPhone even if you use a network cable – there is still a way!

The key is that when you do a factory restore of your Apple TV, it enables Bluetooth and allow you to connect a remote keyboard. Get the OSX App 1Keyboard to have your Mac act as an Bluetooth keyboard and the connect the Apple TV to your Mac using a micro-USB cable and perform a factory restore.

After the factory restore is done, hook it up to your TV and use 1Keyboard to connect. Mission accomplished!

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).