Tuesday, November 30, 2010

Why is ListBox.Items.IsReadOnly=true? (F#/Silverlight)

Programmer Question

I'm trying to remove some objects from a ListBox that I have created, and for some reason ListBox.Items.IsReadOnly is true.



The following calls don't work:



myListBox.Items.Add("whatever")
myListBox.Items.Add("stuff")
myListBox.Items.Remove("whatever")


I get an exception:



{System.InvalidOperationException: Operation not supported on read-only collection.
at System.Windows.Controls.ItemCollection.RemoveImpl(Object value)
at System.Windows.Controls.ItemCollection.RemoveInternal(Object value)
at System.Windows.PresentationFrameworkCollection`1.Remove(T value)


I can set ListBox.ItemsSource, but working with .Items is much easier. I'm creating the ListBox like this:



let mutable myListBox= new ListBox()


Any ideas/suggestions would be greatly appreciated. Thanks.



Find the answer here

Getting number of common terms in two tables where there are duplicates.

Programmer Question

Consider the following two tables in SQL Server 2008:



Table1 which has just one int field: Term1



Table2 which also just has one int field: Term2. (Yeah, I know - I lack imagination.)



.



Let's say that I insert the following values in Term1: 1, 2, 5, 5, 6, 7



And I insert the following values in Term 2: 3, 4, 5, 5, 7, 8



.



I want to run a query where I find the terms that are common to both tables, and I want these paired off. So when there are duplicates (as there are in this case - 5 and 5), I want there to be a single row for each pair found. In other words, I would like two pairs of 5s returned as the two terms that are common.



How do I do this? If I do a simple inner join on Table1 and Table2, I get four pairs of 5's returned.



Find the answer here

Monday, November 29, 2010

Best way to provide charts on the web? Server-side or client-side library? HTML5?

Programmer Question

Hello



What would you sugges to provide a chart (line-based) on the web? I need to make something similar to a burn-down chart or stocks over time. The server side is django and using jquery for the client stuff.



What are the advantages to using something like pychart or some other python plot library which can produce an svg or png and display it?



Or providing the data in tables and using visualize or highchart for jquery to make generate the chart using javascript?



I would like to put points on the chart which are clickable, or which show more information on the specific turn.



What options are available with HTML5, does it come with builtin support for charts or do I have to do it with canvas only?



Thanks for your help.



Edit/Update. Thanks all for the suggestions.



Find the answer here

Should I catch all my exceptions in the global.asax?

Programmer Question

If I am just logging exception details in my web app, do I really need to put in exception handling logic for each tier? Why not just let them all bubble up the stack trace to the global.asax and log them there?



Find the answer here

how to convert soap response to object

Programmer Question

hi



i got xml file and i have matching object to it



how can i fill the object with the xml data



?



Find the answer here

Is there any shortcut for array size / length in C?

Programmer Question

Is there any way to speed up getting an array size in C?



Typing out sizeof(array)/sizeof(int) every time gets old. Do any C libraries have something like .length or is there some way I can define sizeof(array)/sizeof(int) as a shorter constant of some sort (possible also using dot notation)?



Find the answer here

Using variable outside of ajax callback function

Programmer Question

What is the best to use global variables outside of a callback function?



    var icon; 
$(function(){

$.get('data.xml', function(xml){

icon = xml.documentElement.getElementsByTagName("icon");
//this outputs a value
console.log(icon);
});
//this is null
//How can this maintain the value set above?
console.log(icon);
});


Find the answer here

Sunday, November 28, 2010

Merge povray's partial images of arbitrary size

Programmer Question

Starting situation:




Using povray I create 4 partial images of a scene.




povray +SR1 +ER200 +SC0 +EC200 +W400 +H400 +OPART1 povray.pov
povray +SR1 +ER200 +SC201 +EC400 +W400 +H400 +OPART11 povray.pov
povray +SR201 +ER400 +SC0 +EC200 +W400 +H400 +OPART2 povray.pov
povray +SR201 +ER400 +SC201 +EC400 +W400 +H400 +OPART22 povray.pov


Problem to solve:




  • Merge the 4 images programmatically.



Things to take in consideration:




  • Most of the partial images are NOT valid images and cannot be opened. For example, the first partial image can be opened, showing a rectangle with the image at the top left and everything else is black. But the rest of the images contain only the information regarding his zone. We could say that those images are broken.

  • The output format is set with the +F and could be PPM, PNG, Uncompressed and Compressed Targa. A valid solution could use any of those formats.

  • Focus on how to merge the images. You know the rectangle that each partial image have.



Things that have been tried:




  • Concatenating the images with Tail as described in http://povray.tashcorp.net/tutorials/qd_multicpu_render/ . It only works if the partial images are complete on the width axis, that is if PART1 is a set of lines, PART2 another set of lines...and no column division. But we have column division.

  • Use ImageMagick. It cannot open the partial images. It says they are broken.



Find the answer here

Alternative to Code Complete 2nd Edition

Programmer Question

Hello



I've looked at What is the single most influential book every programmer should read? to find some books to read. The books are needed for my train trip each day to/from work and having a book on 960 pages is just a bit over kill in my opinion. Therefore i'm looking for an alternative to code complete which is just a bit smaller and maybe something like 2-300 pages.



Does anyone have a suggestion? Thanks.



Find the answer here

Saturday, November 27, 2010

Reading c file line by line using fgetc()

Programmer Question

This is how I done it but I'm not sure this is the preferred idiom:



FILE *fp = fopen(argv[0], "r");
// handle fopen() returning NULL

while (!feof(fp)) {
char buffer[80]; // statically allocated, may replace this later with some more sophisticated approach
int num_chars = 0;

for (int ch = fgetc(fp); ch != EOF && ch != '\n'; ch = fgetc()) {
buffer[num_chars++] = ch;
}

// null-terminate the string
buffer[num_chars] = '\0';

printf("%s\n", buffer);
}


Is this okay, any suggestions to improve this?



Find the answer here

Can I call Perl from within python?

Programmer Question

I have searched a lot and I have understood that there exists inline::Python for putting in python code within Perl..
But I am looking for some means by which I can access modules and functions written in Perl by not writing any Perl code, through a python code.



Maybe, I am asking for too much?



Find the answer here

.Net Installer repair option

Programmer Question

Hi,



I am working on a project, where I need to give a repair/remove option to my installer [which will be shown at installation time] if the program previously installed. And I need to do it with VS 2008. Please help me on that.



EDIT: Actually for some security reason I removing registry entry for previous installation. So that I can uninstall it from my application only, which is password protected. So thats why I need to customize that repair/remove option. So that it will appear by seeing some specific registry value. How can I do that ?



Thanks.



Find the answer here

Only support for landscape Interface orientation

Programmer Question

I have application that uses landscape right orientation.
In view controllers I use:



- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}


But, If user locks iphone or ipad to portrait orientation, screen is displayed
as portrait, not landscape. Also, in info.plist file I defined only Landscape orientation as
supported one.



Find the answer here

Bind ComboBox To DataGridView Column

Programmer Question

Hi people.
How can i bind combobox1 to dgv.Columns["cLoadName"] ? so my combobos always be above the column header text



Find the answer here

Friday, November 26, 2010

how to find my errors in the xml file

Programmer Question

hi!!sometimes when i m trying to run my code the eclipse console say Error in an XML file: aborting build.that means that i have a mistake in my main.xml file.is there any way to find my mistake without making guess and erasing some xml code in order to see where is the problem?something like validation of my xml file!!thanks



Find the answer here

"Extend" webpages to fit a sticky footer

Programmer Question

I'm building a plugin that injects an HTML iframe "toolbar" onto the bottom of every web page. I've achieved "sticky footer" behavior by injecting the following: