In March 2013 Twitter plans to retire version 1 of their REST API, however it’s replacement requires all requests to use OAuth signed headers. As a result if you’re using JavaScript to pull in a twitter feed to show on your website, you might be in for a spot of bother. However I’ve put together a little script which will allow you to remain using your JavaScript implementation, until you have time to move to the Twitter API 1.1 completely.
The Code
Create a file called twitter-proxy.php and place it somewhere publicly accessible on your server.
Be sure to update the $config variable with the tokens, keys and secrets provided by Twitter when you create an app on their developer site (this is free).
Usage
Usage is pretty simple, instead of pointing your JavaScript XML request to Twitter just point it to the file you created instead. For example:
This is a handy little terminal script I’ve used a lot recently which lists the current active connections on OSX. It’s really handy for seeing if Apache / Node.js / Ruby stuff is running on ports correctly.
Git is a really powerful piece of version control software. Here is a short crash course on how to get started on it, I presented at the University of Portsmouth in April 2012.
I am a big fan of podcasts, here is a handful of really good podcasts that I’ve been listening to over the last month on my commute to work. If you use Google Reader (With Google Listen), you can quickly subscribe to this via the bundle I created.
MySQL always surprises me in the sheer amount of stuff you can do in it. For example I recently found it has a bunch of String Functions. The main one I found to be useful was the REPLACE function, which works like this:
Fast loading times are a really important factor when it comes to website ranking, so it’s important to remove as much unnecessary data as possible. A good method to do this is via cookieless domains.
Cookieless domains are (as the name suggests) are domains, in which the user will not send cookies (Which can add quite a few kilobytes to a request). For example, say I want a user to load a static image it would be silly of them to also send me the cookie data. Luckily they are super easy to set up.
It may surprise you to hear, that using the mysql_connect() function in PHP has recently be marked as “old hat” coding because it’s slow in comparison with newer methods. A better alternative is PDO (PHP Data Objects), a lightweight method for accessing databases. Here is a quick overview to help you get started with PDO.
Reasons to use PDO
It’s Fast - it talks to the database via a database specific PDO-driver.
It’s Object Oriented – The methods within the class are the same for each database driver, so you can easily change your database driver without lots of extra coding.
It’s Flexible- You can easily change between such database drivers as PostgreSQL, MySQL or SQLite by pretty much just changing your construct statement.
It’s Safer – PDO encourages you to bind parameters to your SQL query’s, meaning that it’s significantly less likely your website will suffer from a SQL injection based attack.
I was recently introduced a group of really funky new HTML5 JavaScript methods, which make me seriously think we can avoid having to include the jQuery library in lots of small websites. These methods are querySelectorAll() and querySelector().
In a nutshell, these methods behave exactly the same as the jQuery selector but comes integrated into the browser, meaning you input the CSS selector (e.g. “#myDiv” or “.MyClass”) and out pops the first element in the tree, or a StaticNodeList of the elements (depending on whether you use the All part) .
A few days ago I was researching methods of validating alphanumeric strings and I was shown PHPs Ctype Functions by Sebastian Roming.
In a nutshell they are a group of PHP functions why can be used to check strings to see if they are alphanumeric, numeric etc without using regex (So they are fast!). The key thing to remember is that they return TRUE or FALSE, unlike filter_var which returns FALSE or the string. Here is the code example:
Validating an email address is a great way to reduce spam on your website, but there are several methods to do it. You could use a messy regex approach or alternatively you could also use PHP built in functions, it’s really up to you. Here is the function I use: