Blog posts


  • Get Facebook profile picture using API and jQuery

    January 12, 2011 | Tags: Javascript, Facebook, jQuery, Snippet
    This shows how to fetch the users profile information directly to your web page using the Facebook API and jQuery (for updating the HTML).

    First step is to register your web site as a Facebook app. You will need a Facebook account in order to access the development features.



    If you're doing local development be sure to set the URL to your local path, otherwise you'll get an error saying: API Error Code: 191
    API Error Description: The specified URL is not owned by the application


    Once signed up your new Facebook app will get an App ID assigned. You need to copy that into the script below where it says xxxxxxxxxxxxxxxxx.

    Most of the code below should be self explaining, but this is what it does:
    1) Init a connection to Facebook with your app id
    2) Get login status and..
    3a) Show connect button if not connected
    3b) Show profile information if connected

    <div id="fb-root"></div>
    <script src="http://connect.facebook.net/en_US/all.js"></script>

    <h2>Profile</h2>
    <div id="account-info"></div>

    <script>
    function showAccountInfo() {
    FB.api({
    method: 'fql.query',
    query: 'SELECT name, pic FROM user WHERE uid=' + FB.getSession().uid
    },
    function(response) {
    $('#account-info').html('<img src="' + response[0].pic + '">' +
    response[0].name + ' <img onclick="FB.logout()" style="cursor: pointer;" ' +
    'src="https://s-static.ak.fbcdn.net/rsrc.php/z2Y31/hash/cxrz4k7j.gif">');
    }
    );
    }

    function showLoginButton() {
    $('#account-info').html('<img onclick="FB.login()" style="cursor: pointer;" ' +
    'src="https://s-static.ak.fbcdn.net/rsrc.php/zB6N8/hash/4li2k73z.gif">');
    }

    // Called when Facebook login status change
    function onStatus(response) {
    if (response.session) {
    showAccountInfo();
    } else {
    showLoginButton();
    }
    }
    FB.init({
    appId: 'xxxxxxxxxxxxxxxxx',
    cookie: true,
    status: true,
    xfbml: true
    });

    FB.getLoginStatus(function(response) {
    onStatus(response); // once on page load
    FB.Event.subscribe('auth.statusChange', onStatus); // every status change
    });

    </script>

    You can access other profile information as well. You'll find all properties on the user object over at Facebook Query Language (FQL) Reference.

    If you're getting an unspecified error when trying to connect a user to your web page, the most likely issue is that you're app is in sandbox mode which blocks the app for other users than the developer. You can turn it off under settings over at your Facebook app page.

  • Photoshop: Copy to new color problem

    December 09, 2010 | Tags: Photoshop, Troubleshooting
    A rather bizarre problem occured today. After recieving a layered PSD-file from an Art Director and trying to copy a single coloured layer into a new image I ended up with a layer with a different color but not only that. It seemed to be dithered as well! Looking into settings, nothing appeared wrong. After some trouble shooting I finally found it: The color profile embeded with the PSD-file was missing or didn't match the once I've installed, but Photoshop didn't say a word about it.

    This is how to fix it:
    1) Goto the menu and Edit / Color Settings...
    2) Check all boxes for Profile Mismatches and Missing Profiles
    3) Done!

    Now you can copy and paste as new AND get a warning when the profile mismatch instead of just getting the layer with all the colors wrong.

  • Randomize a list of strings in .net

    December 09, 2010 | Tags: C#, Snippet
    Need to randomize your list or array? Well, here's a snippet for you that will return the list with the items in a random order. It can easily be changed to sort other types of lists (or arrays) as well.
    private static Random rng = new Random();

    public static List<string> Randomize(List<string> list) {
    byte[] order = new byte[list.Count];
    rng.NextBytes(order);
    string[] tmp = list.ToArray();

    Array.Sort(order, tmp);

    return tmp.ToList<string>();
    }

  • Copy text to clipboard AS3 / Flash

    November 29, 2010 | Tags: AS3, Flash, Snippet
    Here's a usefull little snippet which allows copies a text into the global clipboard from Flash/AS3:
    System.setClipboard("This will be placed in the clipboard");

  • Great web hosting 50% off today!

    November 26, 2010 | Tags: Off-topic, Web hosting, ASP.NET
    Arvixe is a great web host, especially when it comes to features and price for their Windows / ASP.NET platform, which not many other hosting companies can offer at the same price.

    For today only they offer 50% off life-time for new hosting accounts. So if you're looking for a great host for your ASP.NET (or UNIX/PHP/WordPress or whatever you're into) then you should definitley check them out.

    My own experience has so far been great. I've contacted their "live chat" support one time, and they solved my rather technical problem instantly. Something I've not experienced with two many other budget web hosts I've come in contact with.