Wednesday, January 23, 2008

Add post randomizer for blogger

When your blog post came up to the hundreds or even thousands, one day you'd want to let people click on random post. Or, maybe if your blog is a personal blog, and not a spam blog that aims only to suck traffic, you might one day want to flip thru your blog randomly, just like when you speed read thru your personal diary.

There are many ways to add this capabilities to blogger. One popular way is by adding a random I'm feeling lucky widget to your blog. However, I find that these clickable links are best put near your navigation buttons, not somewhere in your sidebar. In blogger, that is the older post, newer post and home button. Besides, it looks horrible to see a lone navigation button hovering in the middle of those stuff on the right.

So, what other ways can we use to achieve this? The most obvious is a blogger hack. I have sampled several blogger hacks that allowed this, however, some would get deleted if you change some layout and stuff on blogger. This hack has survived several blogger changes.

So, what you do, is, edit your templat HTML, make sure that expand widgets is selected, then add the following right before the </head> tag.

<script type="text/javascript">
//<![CDATA[
var _yourBlogUrl = "http://insertblogurl.blogspot.com";
function randomPost() {
var script = document.createElement("script");
script.setAttribute("type", "text/javascript");
var theUrl = _yourBlogUrl
+"/feeds/posts/summary?alt=json-in-script&callback=getTotalPostsCallback&start-index=1&max-results=1";
script.setAttribute("src", theUrl);
document.documentElement.firstChild.appendChild(script);
};

function getTotalPostsCallback(json) {
var totalResults = json.feed.openSearch$totalResults.$t;
if (totalResults > 0) {
getRandomPostNumber(totalResults);
}
};

function getRandomPostNumber(totalResults) {
var randomNumber = Math.floor((Math.random() * totalResults)
+ 1);
getRandomUrl(randomNumber);
};

function getRandomUrl(randomNumber) {
var script = document.createElement("script");
script.setAttribute("type", "text/javascript");
var theUrl = _yourBlogUrl
+"/feeds/posts/summary?alt=json-in-script&callback=getTheUrlCallback&start-index="
+ randomNumber + "&max-results=1";
script.setAttribute("src", theUrl);
document.documentElement.firstChild.appendChild(script);
};

function getTheUrlCallback(json) {
var theUrl = json.feed.entry[0].link[0].href;
window.location.href = theUrl;
}
//]]>
</script>
And then, add the following where you'd like the random link to appear in your blog.
<a href="javascript:randomPost();">View Random Post</a>
In my blog, I put it under
<div class='blog-pager' id='blog-pager'>
Please thank Purple Moggy for creating this code. :)

Read the full article......

Wii Remote as 3D Peripheral



Using the infrared camera in the Wii remote and a head mounted sensor bar (two IR LEDs), you can accurately track the location of your head and render view dependent images on the screen. This effectively transforms your display into a portal to a virtual environment. The display properly reacts to head and body movement as if it were a real window creating a realistic illusion of depth and space. By Johnny Chung Lee, Carnegie Mellon University. For more information and software visit http://johnnylee.net

This was posted over at penny arcade today, and I think it's really interesting. Nintendo itself has demonstrated an astounding variety of ways to use the wii remote like in the game Wii Sports, Wii Play and Wario Ware. It even changed the landscape of 2D gaming as demonstrated in Super Paper Mario.
The catch is, Nintendo meant for the Wii for gameplay only. And that is correct for the Wii Remote. (it's not Wiimote, you morons) But, wouldn't it be great, if you can use it on a PC? Especially after seeing that video, don't you wish you have that capability on a 3D program? You'd only need to move your head a little to see the 3D-ishness of your objects. Or perhaps, use a Wii remote to edit your mesh?

What Johnny Lee has demonstrated is only a proof of concept. It has not been implemented to a practical everyday use. I hope someday someone with a good programming skill can connect the Wii remote to Maya or Blender.

Read the full article......