GitHub Gist Shortcode WordPress Plugin Update
If you use the GitHub Gist Shortcode WordPress plugin, which I do, to embed your gists in your blog you’ll want to update the code to the latests.
I noticed the other day that all requests were getting permanently redirected from http to https. The fix is very minor.
Quicktip: Simple File Based Cache Mechanism in PHP
Simple, yet effective enough, this is all the code I used to create caching for a feed retrieval to speed up subsequent requests.
Enjoy!
function _getFromCache($uniqID, $expireSeconds) {
$uniq = '/
if (file_exists($uniq) && time() – filemtime($uniq) < = $expireSeconds) {
return '
}
$somethingToCache = ‘
file_put_contents($uniq, $somethingToCache); //You will want to implement __toString() if this is an object or maybe you can just serialize it
return $somethingToCache;
}
Using jQuery to rewrite relative urls to absolute urls – [revisited]
After scanning my site stats and realizing that an old post about how to rewrite all the relative urls on a page with jQuery was one of my most visited, I decided to review the code and noticed it could be improved. My knowledge of JavaScript and jQuery has improved immensely since that previous post and this revisit is an attempt to improve upon it.
Problem: Need to change all the relative urls on a page and replace with an absolute url.
Different from my other post I’m going to separate the concerns of this problem: 1 being selecting only the links that are relative and not inline or mailto: links; 2 modifying the href.
Selecting the links on a page
The jQuery standard $(‘a’) will only solve half our problem because we only want links that are relative. There are several different methods we can use with jQuery to get exactly what you need, however first take into context what your page actually looks like. You may be able to save some time if your page has relatively few links, on the other hand if you have a page with hundreds of links you will need to chose your selectors wisely. To make the best and most informed decision, I suggest you test your various use cases @ http://jsperf.com/.
Here are three that I came up with:
$('a').not('[href^="http"],[href^="https"],[href^="mailto:"],[href^="#"]');
$('a:not([href^="http:"],[href^="https:"],[href^="mailto:"],[href^="#"])');
$('a:not([href*="://"],[href^="mailto:"],[href^="#"])');

