Friday, April 29, 2011

Good way to convert VB.Net to C#?

Are there any good conversion tools out there to convert VB.Net code to C#?


FREE


PAID

From stackoverflow

Using multiple listboxes in python tkinter

from Tkinter import *

master = Tk()

listbox = Listbox(master)
listbox.pack()

listbox.insert(END, "a list entry")

for item in ["one", "two", "three", "four"]:
    listbox.insert(END, item)

listbox2 = Listbox(master)
listbox2.pack()

listbox2.insert(END, "a list entry")

for item in ["one", "two", "three", "four"]:
    listbox2.insert(END, item)

mainloop()

The code above creates a tkinter window with two listboxes. But there's a problem if you want to retrieve the values from both, because as soon as you select a value in one, it deselects whatever you selected in the other. Is this just a limitation developers have to live with?

From stackoverflow
  • exportselection=0 when defining a listbox seems to take care of this issue

  • From the documentation:

    By default, the selection is exported to the X selection mechanism. If you have more than one listbox on the screen, this really messes things up for the poor user. If he selects something in one listbox, and then selects something in another, the original selection is cleared. It is usually a good idea to disable this mechanism in such cases. In the following example, three listboxes are used in the same dialog:

    b1 = Listbox(exportselection=0)
    for item in families:
        b1.insert(END, item)
    b2 = Listbox(exportselection=0)
    for item in fonts:
        b2.insert(END, item)
    b3 = Listbox(exportselection=0)
    for item in styles:
        b3.insert(END, item)
    
  • Thanks!!! You help me a lot :D:D:D

What is the maximum length of a table name in Oracle?

What is the maximum length of a table name in Oracle? For bonus points, what is the maximum length of a column name?

From stackoverflow
  • In the 10g database I'm dealing with, I know table names are maxed at 30 characters. Couldn't tell you what the column name length is (but I know it's > 30).

    Justin Cave : Column names are limited to 30 characters as well, not > 30
    Harper Shelby : Ah, I see that (in Mark Brady's answer). I could've sworn I saw one longer, but obviously I was wrong.
  • I believe the maximum name size is 30 characters, because all table/index names must be stored in the data dictionary and that storage is only allocated for 30 characters

    EDIT-

    The same goes for the column name

    TStamper : why the downvote, for the correct answer?
    TStamper : Wow...lol..sorry been a member for a few months now and only gave one downvote and it was to spam
    TStamper : I never assumed you downvoted me,the comment was for all, I didnt comment on your answer, so I never suspected you. sorry you took it that way
  • Teach a man to fish

    Notice the data-type and size

    >describe all_tab_columns
    
    VIEW all_tab_columns
    
    Name                                      Null?    Type                        
     ----------------------------------------- -------- ----------------------------
     OWNER                                     NOT NULL VARCHAR2(30)                
     TABLE_NAME                                NOT NULL VARCHAR2(30)                
     COLUMN_NAME                               NOT NULL VARCHAR2(30)                
     DATA_TYPE                                          VARCHAR2(106)               
     DATA_TYPE_MOD                                      VARCHAR2(3)                 
     DATA_TYPE_OWNER                                    VARCHAR2(30)                
     DATA_LENGTH                               NOT NULL NUMBER                      
     DATA_PRECISION                                     NUMBER                      
     DATA_SCALE                                         NUMBER                      
     NULLABLE                                           VARCHAR2(1)                 
     COLUMN_ID                                          NUMBER                      
     DEFAULT_LENGTH                                     NUMBER                      
     DATA_DEFAULT                                       LONG                        
     NUM_DISTINCT                                       NUMBER                      
     LOW_VALUE                                          RAW(32)                     
     HIGH_VALUE                                         RAW(32)                     
     DENSITY                                            NUMBER                      
     NUM_NULLS                                          NUMBER                      
     NUM_BUCKETS                                        NUMBER                      
     LAST_ANALYZED                                      DATE                        
     SAMPLE_SIZE                                        NUMBER                      
     CHARACTER_SET_NAME                                 VARCHAR2(44)                
     CHAR_COL_DECL_LENGTH                               NUMBER                      
     GLOBAL_STATS                                       VARCHAR2(3)                 
     USER_STATS                                         VARCHAR2(3)                 
     AVG_COL_LEN                                        NUMBER                      
     CHAR_LENGTH                                        NUMBER                      
     CHAR_USED                                          VARCHAR2(1)                 
     V80_FMT_IMAGE                                      VARCHAR2(3)                 
     DATA_UPGRADED                                      VARCHAR2(3)                 
     HISTOGRAM                                          VARCHAR2(15)
    
  • The schema object naming rules may also be of some use:

    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/sql_elements008.htm#sthref723

  • DESCRIBE all_tab_columns

    will show a TABLE_NAME VARCHAR2(30)

    Note VARCHAR2(30) means a 30 byte limitation, not a 30 character limitation, and therefore may be different if your database is configured/setup to use a multibyte character set.

    Mike

  • Right, but as long as you use ASCII characters even a multibyte character set would still give a limitation of exactly 30 characters... so unless you want to put hearts and smiling cats in you're DB names your fine...

    Maarten

    Ed Daniel : I can DO that? Cool! *shoots self*

How do I make jQuery wait for an Ajax call to finish before it returns?

I have a server side function that requires login. If the user is logged in the function will return 1 on success. If not, the function will return the login-page.

I want to call the function using Ajax and jQuery. What I do is submit the request with an ordinary link, with a click-function applied on it. If the user is not logged in or the function fails, I want the Ajax-call to return true, so that the href triggers.

However, when I use the following code, the function exits before the Ajax call is done.

How can I redirect the user gracefully to the loginpage?

$(".my_link").click(
    function(){
    $.ajax({
        url: $(this).attr('href'),
        type: 'GET',
        cache: false,
        timeout: 30000,
        error: function(){
            return true;
        },
        success: function(msg){ 
            if (parseFloat(msg)){
                return false;
            } else {
                return true;
            }
        }
    });
});
From stackoverflow
  • If you don't want the $.ajax() function to return immediately, set the async option to false:

    $(".my_link").click(
        function(){
        $.ajax({
            url: $(this).attr('href'),
            type: 'GET',
            async: false,
            cache: false,
            timeout: 30000,
            error: function(){
                return true;
            },
            success: function(msg){ 
                if (parseFloat(msg)){
                    return false;
                } else {
                    return true;
                }
            }
        });
    });
    

    But, I would note that this would be counter to the point of ajax also, and you should be handling the response in the error and success functions. Those functions will only be called when the response is received from the server.

    veggerby : You mean false :) I guess?
    altCognito : Hah! Yes, thanks.
    rizzle : +1 right answer, -1 judging :)
  • The underlying XMLHttpRequest object (used by jQuery to make the request) supports the asynchronous property. Set it to false. Like

    async: false
    
  • From jQuery documentation

    "$.ajax() returns the XMLHttpRequest that it creates. In most cases you won't need that object to manipulate directly, but it is available if you need to abort the request manually."

    So you have to use it like that

    var xhr = $.ajax({....});
    

    then look at XMLHttpRequest documentation ( https://developer.mozilla.org/en/XmlHttpRequest ) . It has readyState attribute. Try to set up interval (setInterval) to check this value, and when it will be 4, check responseText attribute for response.

    Do it

    $(".my_link").click(
        function(){
            var xhr = $.ajax({
                // not here
            });
            // here...
        };
    );
    

    Try to find something like that for IE.

Programming Challenge using jQuery

This is a follow up to a previous question which seems to have confused people so I'll purify it a bit. Here is some markup.

<div class="button width120 height30 iconLeft colorRed"></div>
<div class="button width180 height20 iconPlus colorBlue"></div>
<div class="button width200 height10 iconStar colorGreen"></div>
<div class="button width110 height60 iconBack colorOrange"></div>

The challenge is to fill in the code in the following.

$(".button").each(function(){

    // Get the width from the class

    // Get the height from the class

    // Get the icon from the class

    // Get the color from the class

});

Now, I know that you shouldn't use classes this way so I'm not looking for alternative ways of doing it, this is an experiment and I'm interested to know if it's possible to do it this way.

From stackoverflow
  • Something like:

    $(".button").each(function(){
        var classNames = $(this).attr('class').split(' ');
        var width, height;
        for(int i = 0; i < classNames.length; i++) {
            var className = classNames[i];
            if(className.indexOf('width') > -1) {
                width = className.substring(5, className.length - 1);
            } else if(className.indexOf('height') > -1) {
                height = className.substring(6, className.length - 1);
            } // etc. etc.
        }
    });
    

    Or have I misunderstood what you were asking?

    Ólafur Waage : Substr wont quite work, since the height and width could be longer
    roryf : eh? it uses className.length - 1, so the value can be of any length.
    jonhobbs : I think you have understood the question :) Would this still work if the width wasn't there when the page loaded but I added it using $(".button").addClass("width250"); Would the new class have been added to the class attribute?
    moff : @jonhobbs: Yes it would, at least if you run this code *after* you add the class. When you call addClass, jQuery simply modifies the className property of the element.
  • I found this answer which looks very robust...

    $(".button").each(function(el){
        classStr = el.className;
        classes = classStr.split(' ');
    
        // Loop through classes and find the one that starts with icon
    
    });
    
  • I like to solve some challenges in silly ways. :D This is a very unelegant, inefficient and not very safe solution. But i had fun writing it.

    <!doctype html>
    <html>
    
      <head>
    
        <script src="jquery/jquery-1.3.2.min.js"></script>
        <script>
          $(function () {
            $(".button").each(function(){
              var div = $(this)
              div.css({"border":"1px solid black"});
              var classes = div.attr('class').split(' ').slice(1);
              classes.forEach( function (element) {
                div.append(/(width|height)(\d+)|(icon|color)(\S+)/.exec(element).filter(function (element) {return !!element} ).slice(1).join(": ").concat("<br>" ) )
              })
            })
          });
    
        </script>
      </head>
      <body>
        <div class="button width120 height30 iconLeft colorRed"></div>
        <div class="button width180 height20 iconPlus colorBlue"></div>
        <div class="button width200 height10 iconStar colorGreen"></div>
        <div class="button width110 height60 iconBack colorOrange"></div>
    
    
      </body>
    
    </html>
    

    Ohh, and it doesn't work in every browser. ;)

  • This is a terrible idea, but since you seem to already know that, here's the code:

    $(".button").each( function() {
      var width, height, color, icon;
      $.each( $(this).attr('class').split(), function( cls ) {
        if( cls.match("^width") ) { width = cls.split('width').pop(); }
        else if( cls.match("^height") ) { height = cls.split('height').pop(); }
        else if( cls.match("^icon") ) { icon = cls.split('icon').pop(); }
        else if( cls.match("^color") ) { color = cls.split('color').pop(); }
      } );
      console.log( "width: " + width );
      console.log( "height: " + height );
      console.log( "icon: " + icon );
      console.log( "color: " + color );
    });
    
    roryf : Nice :) (10 chars? what if all I want is a smiley!)
  • $(".button").each( function() {
        var classStr = this.className;
        var classes = {}
        classStr.replace( /(width|height|icon|color)([a-z0-9]+)/gi,
            function( str, key, val ) {
                classes[key] = val;
            }
        );
        console.log( classes );
    });
    
    /*
     * {
     *     width:  '120',
     *     height: '30',
     *     icon:   'Left',
     *     color:  'Red'
     * }
     */
    
    KyleFarris : Nice work, but you didn't extract out just the values. I'm pretty sure that's what he wanted. So, you're like halfway there.
  • Why do you have such a class in a div?

Findbugs filter file for ignoring JUnits

Hi guys,

I need to set up a filter file for my findbugs ant script that scans only the src/* files and not the test/* files.

What is the syntax for checking all classes while ignoring any filename or package name with 'test' in the name?

Thanks

From stackoverflow
  • FindBugs is actually scanning the compiled class files, not the sourcePath. If you are compiling your src/* and test/* files to the different directories, you could just use the nested <class...> element.

    <findbugs home="${findbugs.dir}" output="xml:withMessages" 
        outputFile="${findbugs.report.xml}" jvmargs="-Xmx256M" 
        effort="max" projectName="${ant.project.name}" 
        auxClasspathRef="findbugs.classpath" 
        sourcePath="${src.dir}">
      <class location="${src.classes.dir}"/>
    </findbugs>
    

    That won't work if src/* and test/* are both compiled to a single directory. In that case, use a filter file and exclude the packages or class names that correspond to tests.

    <findbugs home="${findbugs.dir}" output="xml:withMessages" 
        outputFile="${findbugs.report.xml}" jvmargs="-Xmx256M" 
        effort="max" projectName="${ant.project.name}" 
        auxClasspathRef="findbugs.classpath" 
        sourcePath="${src.dir}"
        excludefilter="exclude.xml">
      <class location="${classes.dir}"/>
    </findbugs>
    

    where exclude.xml looks like:

    <FindBugsFilter>
      <Match>
        <Class name="~.*Test$"/>
      </Match>
      <Match>
        <Package name="~test\..*"/>
      </Match>
    </FindBugsFilter>
    
    TofuBeer : good explanation... apparently I need to start drinking coffee or something. Deleted my answer, which well correct is misleading.
  • By the way, it is a good idea to cover unit tests with FindBugs as well. There is no reason for using lower quality standards towards tests. Bugs in test are just that, bugs.

    Sure, if you run FindBugs first time, there might be many bug reports, but the bug count will come down overtime if you pay any attention to them.

Automated GUI testing of legacy non-MFC application?

We have a system that was originally developed decades ago and has increased in code base over the years. This is a fairly major system, with configuration that our department maintains (the vendor does not allow us access to the source or underlying database). The client software is a proprietry developed application which is basically a fancy terminal application connecting to the main database.

I want to be able to write unit testing to automate testing the various functional components of the system. I have attempted using AutoIT and AutoHotkey with no luck, my problem is I cannot read the data from the window as it is a custom class (the window finder comes up blank). I have even tried using an OCR API with AutoIT with no success (its not reliable). I have also tried using a terminal emulator like CRT and putty with limited success as the normal client software sends specific non-terminal-standard data when pressing keys etc.

It seems that all testing suites really only apply to web based applications or more standardised applications.

Has anyone else had a similar problem?

From stackoverflow
  • Try "Automated QA: Test Complete". We've been using it for a major application for while now, and it's the only product that can test WPF, Win32, .NET, Java, etc. etc. applications with almost no hassle. Once you create the test scenarios you can re-run it later as a regression test.

  • For automated GUI testing of thick and/or terminal clients on Windows, you might also consider IBM Rational Functional Tester, IBM Rational Robot, HP QTP, Compuware TestPartner, Borland SilkTest.

    More specifically, it sounds like you might need to use the old copy-paste work around. Does the terminal window have the equivalent of Edit->Select All, Edit->Copy menus? If so, you can code it to click the GUI menus to select all text and copy to the clipboard. Once the text is on the clipboard, you can use the clipboard API to access and parse the text.

    Mrgreen : Unfortunately no, the software does not have any kind of copy/paste, we cannot even highlight text. But I will still look into the products you mentioned!
    Tom E : That's odd, usually even for terminal or green screen apps you can at least do a select-all, copy, as the terminal window itself can allow you to copy all the text in the buffer. For example, in a Windows command prompt, you can automate Edit->Select All, Edit->Copy to get the text from the command prompt onto the clipboard buffer.
    Mrgreen : Yeah it is odd, the vendor has deliberately disabled it. I believe it was due to confidentiality reasons (the data is very sensitive). There is no ability to highlight, copy, paste and really have anything to do with the clipboard. This is probably my main hurdle in testing.
  • I ended up using a combination of AutoIT and TextCaptureX. The solutions suggested above are good products, but don't really work in this case. TextCaptureX actually hooks in to the Windows GDI to grab text.

    I have since developed test scripts that perform GUI testing on our application very well.