Create and secure your own proxy with cURL and MCrypt

JavaScript’s same-origin policy can be a pain. Of course it’s very necessary for security reasons, but sometimes you want to access a remote web service client-side, or manipulate the display of remote content in an iframe. There’s a still a way to do these things of course, and it’s to build a server-side interface for the remote site and attach your JavaScript to that. Building a generic proxy-style interface is tempting, but can be dangerous if it’s not properly secured. Luckily, securing such a system is possible and relatively simple. See it in action

Tagged with: , ,
Posted in HTML & CSS, PHP, Server Administration, Server Side Code, Try It

Get query string values from JavaScript

I found this code a while ago, probably somewhere on Stack Overflow, and it’s served me well ever since. It returns a data object filled with the key-value pairs of the query string. Try it!

Tagged with:
Posted in Custom Library Functions, JavaScript, Try It

Rounding prototypes for JavaScript

JavaScript does include some standard methods for rounding numbers, but if you’re working on a project that involves calling them frequently, it can get a little tiring. Especially if you need to round to a certain number of decimal places as opposed to an integer. I haven’t encountered this situation much, but I though it would be a neat exercise for some new Number.prototype methods. Try it!

Tagged with:
Posted in Custom Library Functions, JavaScript, Try It

A better JavaScript random number generator

Every time I needed a random number in JavaScript, I always ended up building some weird, difficult to read manipulation of the Math.random() method to get a value in the range I needed. After doing this a few times on a few different projects, I decided it would be a worthwhile effort to concoct an all-in-one JavaScript random number generator. Try it!

Tagged with:
Posted in Custom Library Functions, JavaScript, Try It