Thursday, December 10, 2009

What a bunch of ...

... bullshit!

The developers count on the stackoverflow ad page is clearly increased at random.

The count is being increased in a recursively called function at random intervals. Here's the javascript:


$(function(){
       
        var visitors = 5373966;
        var updateVisitors = function()
            {
                visitors++;
                
                var vs = visitors.toString(), 
                     i = Math.floor(vs.length / 3),
                     l = vs.length % 3;
                while (i-->0) if (!(l==0&&i==0))
                    vs = vs.slice(0,i*3+l)
                       + ',' 
                       + vs.slice(i*3+l);
                $('#devCount').text(vs);
                setTimeout(updateVisitors, Math.random()*2000);
            };
        
        setTimeout(updateVisitors, Math.random()*2000);
        
    });

P.S. Posting this from google SideWiki - kinda cool

in reference to: http://inedomedia.com/stackoverflow.aspx (view on Google Sidewiki)

Friday, December 4, 2009

[WPF] How to programmatically add databound item to ListView

In this post I'll show how to programmatically add databound items to a WPF ListView - it's actually pretty straightforward but it's not the most intuitive task if you don't have a lot of experience with WPF.

Here's your xaml - pay attention to the bindings on the grid columns:

<ListView.View>
   <GridView>
      <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Path=Name}"/>
      <GridViewColumn Header="Value" DisplayMemberBinding="{Binding Path=Value}"/>
   </GridView>
</ListView.View>
We need to define a data class with Name and Value properties such as:

public class BoringData
{
    public string Name { get; set; }
    public string Value { get; set; }
}
And here comes the fun - how to programmatically add items to the ListView:

//utterly boring call to generate your data item
BoringData boredom = getBoringData(index);//<-- whatever
//add the item to the listView 
this.myListView.Items.Add(boredom);
If you're thinking I post boring stuff ... well, you're right. Posts like this I mainly post so that I won't forget how it's done (and hopefully will be helpful to some other occasional WPF hacker).

Tuesday, November 24, 2009

2 Obscure Javascript Features You Probably Don't Know About

I was going through the w3c javascript tutorial (I like the try it yourself sections ... yes - I am that kind of geek) and I spotted 2 pretty basic but obscure ECMAScript Javascript features I didn't know about.

Feature 1: the '===' operator!
That's right, that's a triple equal. What's it for? Well, you know javascript is not strongly typed, so you can cast a variable from a number to a string just assigning values to it. This triple = operator checks for equality of both value and type. Smart, uh? Also kinda horrible.

Feature 2: variable re-declaration!
Apparently you can re-declare a variable and the javascript interpreter couldn't care less. Moreover, if you re-declare a variable it will retain the same value as the previous homonymous variable had. Handy uh? Except it's plain twisted wrong.

Anyway, God bless ECMAScript Javascript, glorification of all sorts of butchers, and the genius dude who invented it.

Monday, November 16, 2009

[.NET] How to swallow warnings

Well aware this is against all best practices, here's how you suppress all warnings coming from a given region of code:

#pragma warning disable

//All the warnings in here are swallowed!

#pragma warning restore

This is way beyond cool - and might help you out when you can't change your code but you're being hovered by a frustrating policy of ZERO WARNING TOLERANCE.

Go forth and get it done.

Tuesday, November 3, 2009

Quick and Dirty WPF ListView Customization

When in need of customizing a WPF ListView without much WPF experience, chances are you'll hit the wall soon enough on pretty trivial tasks.

This is a collection of recent posts appeared on this blog on the topic. I think the list covers most of the common basic ListView customization tasks.
Hope this'll spare a good share of frustration to some of you cheap guys out there, pulling your hair trying to write xaml by hand rather than using some version of Expression Blend or the likes (as I did myself 'cause the 30-days trial expired and the boss wouldn't show the money).

kick it on DotNetKicks.com