soderlind.no

I code for fun

13.11.2008
by PerS
0 comments

Ex Libris

Ex Libris is a “this book I’ve read” application targeting the Norwegian Facebook community. On Ex Libris you can search for books written in and translated to Norwegian. You can add them to your book list, comment, recommend and rate books.

Coding Ex Libris was fun. It’s written in PHP and uses FBML, FBJS, Ajax, PHP MySQL wrapper, CSS The Star Matrix Pre-loaded and Bayesian Rating

As I said, it’s targeting the Norwegian Facebook community and hence in Norwegian. You’ll find it at http://apps.new.facebook.com/exlibris/

15.10.2008
by PerS
0 comments

Microsoft Hyper-V gotcha

..i.e. lack of documentation.

Today I installed Microsoft Hyper-V on our new test server, a HP DL380 with 32GB memory and plenty of disk (800GB in RAID 5 and a hot spare). The install was quick and easy, but getting it on net was not. With a new router/firewall, configuration new to us, we thought it was causing all the “pain” and struggled for hours until we decided enough is enough, let’s continue tomorrow.

Luckily, surfing the net, I stumbled upon the solution to our grieve. Microsoft Hyper-V has its firewall enabled per default (yes, I know, I should have known it was). To managed the hidden features of Microsoft Hyper-V, you have to use netsh from the command prompt, and to disable the firewall (remember I said, we’re using an external firewall, and hence we don’t need the on-board firewall) all you have to do is:

netsh firewall set opmode disable

Hopefully this information will help you when you install your Hyper-V, and hopefully Microsoft will add this to their FAQ.

9.10.2008
by PerS
2 Comments

Facebook ajax rating in php

I’ve written an ajax rating snippet, you’ll find a demo at http://apps.new.facebook.com/ajaxrating/

It is based on Paul OB’s CSS Star Matrix Pre-loaded

The source code below, should be self explanatory, but if you need input on how to do fbjs ajax, you’ll find documentation and examples over at the facebook development site

< ?php
// the $callbackroot MUST point to your server, if you point it to your app.new.facebook.com/APPLICATION, ajax will fail.
$callbackroot='http://[PLACE_YOUR_CALLBACK_URL_HERE]'; // do not add a trailing slash e.g.: http://myserver.domain.com
//AJAX Response (should be first php or in a separate php file):
if (isset($_REQUEST['rate'])) {
    //do something and return "ok" if things are fine
    echo "ok";
    exit; //Important! Stops remaining php after AJAX request is processed
} 

//what ever apicall you use to authenticate, this one is from smiley: http://svn.facebook.com/svnroot/platform/samples/packages/smiley.tar.gz
$fb = get_fb();
$user = $fb->require_login();

?>
<!--  see rate.css below -->
<link rel="stylesheet" type="text/css" href="<?=$callbackroot?>/rate.css" />
<script type="text/javascript">
function save_rating(rate) {
    // array with the class names, used when you add the new class
    var ratings = [ "nostar", "onestar", "twostar", "threestar", "fourstar", "fivestar" ];
    var ajax = new Ajax();
    ajax.responseType = Ajax.RAW;
    ajax.ondone = function(data) {
        if (data == "ok") {
            // remove old class names (I don't know which one, so I remove all of them), and add the new
            document.getElementById('rating_1').removeClassName('nostar').removeClassName('onestar').removeClassName('twostar').removeClassName('threestar').removeClassName('fourstar').removeClassName('fivestar').addClassName(ratings[rate]);
        } else {
            new Dialog().showMessage('Dialog', 'set rating failed');
        }
    }
    ajax.onerror = function() {
        new Dialog().showMessage('Dialog', 'set rating failed');
    };
    ajax.requireLogin = 1;
    var params={"rate":rate };
    ajax.post('< ?=$callbackroot?>/rate.php',params);
}
</script>

<ul id="rating_1" class="rating nostar">
<li class="one"><a href="#" title="1" onclick="save_rating(1); return false;">1</a></li>
<li class="two"><a href="#" title="2" onclick="save_rating(2); return false;">2</a></li>
<li class="three"><a href="#" title="3" onclick="save_rating(3); return false;">3</a></li>
<li class="four"><a href="#" title="4" onclick="save_rating(4); return false;">4</a></li>
<li class="five"><a href="#" title="5" onclick="save_rating(5); return false;">5</a></li>
</ul>

A how-to and the rate.css are located at http://forum.developers.facebook.com/viewtopic.php?id=22547

11.4.2008
by PerS
0 comments

Last night I became a jQuery fan

You know how it’s like. You start to use a javascript library and you tend to stick with it. I’ve been drifting between Prototype.js and Moo. I’ve looked at jQuery but stuck to Prototype/Moo since I “knew it”.

Last night I decided to rewrite my old check for new ImageManager version routine. Being a script junkie, I thought I give jQuery a chance. It was a joy .. I really like jQuery!

BTW, here’s the result:

<pre><script type="text/javascript">
/**
* @desc ImageManager check for new version script
* @author Per Soderlind - soderlind.no
*/
jQuery(document).ready(function() {
    jQuery.get('http://soderlind.no/imagemanagerversion.txt', function(newversion){
        if (251 < newversion) { // 251 is the version number for the installed plugin, I set number this using PHP
            jQuery('#plugins td.name').filter(':contains(ImageManager)').append('<small>new version available').css('color','red');
        }
    });
});
</script></pre>

Explained:

jQuery(document).ready(function() {
Wait until the DOM is loaded
jQuery.get(‘http://soderlind.no/imagemanagerversion.txt’, function(newversion){
Get http://soderlind.no/imagemanagerversion.txt, and put its content into the variable newversion
jQuery(‘#plugins td.name’).filter(‘:contains(ImageManager)’).append(‘<small>new version available</small>’).css(‘color’,'red’);
In the <div id=plugins>, find <td class=name> which contains the text ImageManager
and append <small>new version available</small>. Using css, set the text color to red.

5.4.2008
by PerS
1 Comment

ImageManager and WordPress 2.5

ImageManager supporting WordPress 2.5 will hopefully be ready by the end of next week.

Update 8.4.2008: ImageManager 2.5 is “working” in WordPress 2.5, but you’ll have to give me a couple of days to get rid of bugs (mainly javascript errors). I’ve been firebugging all night, now I’m off to my day job. I will continue debugging ImageManager later today (i.e. tonight .. this is a midnight hack) .

Update 9.4.2008: All javascript errors are found (according to Firebug) and fixed. Tomorrow night I will do testing.

10.4.2008: ImageManager 2.5.0 is released, you’ll find it at http://soderlind.no/ImageManager

16.4.2008: ImageManager 2.5.2 supporting WPMU 1.3.3 is almost done (should also support WPMU 1.5 when it’s released). I will also test it against WordPress 2.3.x prior to release. The plan is to release it by the end of this week

17.4.2008: I just released v2.5.2 which supports WP 2.5, WP 2.3.3 and WPMU 1.3.3

Note: This is a maintenance release (i.e. no new features are added). It’s only tested with WordPress 2.5 , WordPress 2.3.3 and WPMU 1.3.3, and in IE 7 / Firefox 2.x

PLEASE REPORT BUGS AT: http://soderlind.no/forum

Rodney's 404 Handler Plugin plugged in.