Sunday, April 17, 2011

How to sort multi-row entries in Excel?

So I have a document with many entries that follow this general format.

Organization Name Title Address Phone Fax

Description line 1

Description line 2

Organization's website.

Organization Name Title Address Phone Fax

Description line 1

Description line 2

Organization's website.

Organization Name Title Address Phone Fax

Description line 1

Description line 2

Organization's website.

What I want to do is to sort them by organization and treat the first rows as one entry so excel essentially thinks:

Organization Name Title Address Phone Fax

Description line 1

Description line 2

Organization's website.

is one row. I should also add that the bottom 3 rows are merged across the cells that form the row above them. Essentially I need it to work as a database but for government workers who are so technically unsavvy they can't upgrade to Office 2007 because the whole ribbon thing is "too confusing." So I am stuck using Excel 2002. I need to be able to sort them and use the top few rows above the actual chart to include a header and sub-heading.

From stackoverflow
  • Do you need the description/website rows to remain merged? If not unmerge to make it easier. You've tagged it as VBA but if this is a one-time fix then is it OK to manually work on the sheet?

    As a starting point I would suggest adding an identifier to each group of rows, and depending on your data quality you could do this by checking the website cell, or simply by counting rows. For example, you could insert a new column before your data and put the following in cell A2:

    =IF(Left(Lower(B1),4)="http",B2,A1)
    

    Where B1 (the row above) could be Organization, Description 1, Description 2, Organization's website, and if it is a website, we assume that on this new row we're starting with a new block of data so we'll take the organization name. If it isn't a website, we'll use the organization name we were using previously (A1 will need to =B1). Then copy that formula down until the end and the 4 rows will at least now have a common key which you can then use to mash around the data.

    If there are URLs which just start www. then modify the formula or better, just search/replace "www." to be "http://www." so that your data quality has improved.

    Alistair Knock : Possibly, particularly if there's likelihood of duplicate organisation names. Start A1=1, then formula =IF(Left(Lower(B1),4)="http",A1+1,A1)
  • Can't you just try recording a macro daoing whatver sort operation you want using UI, and then alanyze the code, and get an idea of what you need to do?

Psexec and calling batch files.

I'm going to try and break this down as simple as I can.

There are three computers involved. Local machine (LM), compute node (CN), and data node (DN) will be their names from here on out.

I have a psexec command which calls a batch file on the compute node.

psexec \\"compute node" -w WorkingDirectory BatchFileName

This BatchFileName sets some local variables then an executable which is located in the WorkingDirectory. This executable loads, but it has a configuration file which points to a bunch of files located on the data node. This is where my operation breaks down. If I run the batch locally on the compute node everything works fine. I'm merely trying to call it from a local machine using psexec instead. The same account name and password are used for all computers in this case.

The error I get is that it can't open the file located on the data node.

Batch file:

@echo off
setlocal
set VALUATION_DATE=20090313
set LiTEShome=C:\LiTES
ServiceConsole.exe
endlocal
exit /b 0

ServiceConsole.exe.config contains:

<add key="SomeName" value="\\Data Node\\Directory\\FileName"/>

Any help with this would be greatly appreciated.

From stackoverflow
  • Try

    psexec \"compute node" -w WorkingDirectory BatchFileName -u UserName -p Password
    

    with an account that has permissions on both nodes.

C++ or C# to program mobile barcode device?

I will be developing some applications using mobile barcode scanners and need to choose between C++ and C# for coding on the scanners.

I am considering Intermec's CK31 or similar for the combination of wifi, scanning choices, programmability and user interface options. It runs Windows CE .NET 4.2 according to their spec sheet.

Intermec's Developer Library comes with .Net and C++ SDKs. My previous Win CE 2003 experience is in C++ (MFC GUI, sockets and serial comms). I'm comfortable in C# with WPF and can learn other GUI frameworks if I have to. That gives me freedom to choose a language - any recommendations one way or another?

I am NOT looking for answers advocating C++ over C# as languages in general - my productivity in either is similar and I have enough experience to be able to create complex, robust C++ solutions.

What I would appreciate are war stories or factors to put into our platform evaluation, about programming on these devices. eg: battery life of C# apps vs C++ apps, memory consumption or other environmental impacts of the language choice. If there are specific versions of .Net CE to avoid, that would be a good tip.

From stackoverflow
  • I've been developing for about 15 years. Approx 5 years in C++ and 3 years in C# (which currently is my language of choice). In C++ I always used stdlib, and sometimes boost.

    I have cut my development time with a third since I switched from c++ to c#. That was done because of a couple of things (nothing scientific, just my opinons):

    1. .Net is a more complete framework and easier to use than stdlib and boost combined.
    2. C# has a better structure which make easier to read others code and to code.
    3. Unit testing in .Net is light years from unit testing in C++, especially with Resharper and xUnit (xUnit got clean syntax, resharper let's you test specific test methods directly inside dev studio).

    I mostly code servers, GUI programming should be even faster.

    Andy Dent : thanks for bothering to answer but you explicitly ignored my instructions in the question - I don't care about language opinions, just want some facts about mobile development.
  • The answer to your question has to do with the type of your application. If your application is mainly around communicating with the hardware and only a thin layer of business logic and User Interface is needed, then C++ would be a better choice. To interact with the scanners you need to talk to a driver. This is better and faster achieved with C++. The .NET SDK will actually be a wrapper of C++ code using a ton of P/Invoke, which makes the code performing less faster.

    If on the other side your application requires a significant business layer and/or a User Interface, then .NET (and specifically C#) is a better option. In that case the productivity gains far out weight the performance gains of C++.

    Another important factor is the type of the devices the application is going to be deployed to. Are you targeting Windows Mobile devices only? Then .NET is a safe option. For Windows CE devices you need to investigate whether the compact framework is pre-installed or not. Also, some Windows CE devices may not support all .NET namespaces.

    Finally, I recommend reading Mobile Architecture Pocket Guide, which is a recent document about architectural decisions for mobile applications.

    Andy Dent : Based on my own experience using C++/CLI called from C#, I question your assertion about the P/Invoke use in the SDK. Do you actually know this about their SDK or are you assuming?
    kgiannakakis : This is a general remark - I don't know the specific SDK. However, to communicate with a device driver, you need P/Invoke. It is impossible to do it with managed code. P/Invokes are probably hidden in dlls that you are referencing.
    Andy Dent : You're partly wrong. Try searching on device driver c++/cli to see hundreds of examples - C++/CLI gives a good alternative to using P/Invoke. It's not managed code but allows smooth bridging to C++ to call pure C.
    Andy Dent : Thanks for the link to the Mobile Architecture Pocket Guide.
  • I've been designing and developing software for Windows Mobile and Windows CE in C, C++ and C# for quite a few years now. Moreover, I been doing so for Honeywell (formerly Hand Held Products, purchased by Honeywell in 2007) where I've worked on nearly all aspects of the devices, from drivers and services to Line of Business GUIs and utilities.

    First of all, I won't tell you one language is better than the other... I probably spend a 50/50 split of my time with each, and each platform definitely has their own place in the mobile development.

    I will however, give a suggestion that you likely stay away from any device that runs an OS as old as WinCE 4.2, especially if you are even considering .NET development. The reasoning for this is that 4.2 only has, at most, .NET CF 1.0 embedded in ROM (part of the OS ROM image), meaning that you would require a ~5MB CAB file to install at least .NET CF 2.0 Yes, you could develop with CF 1.0 but, truly, it's not worth the pain of using such an old framework. Most WinCE 5.0 devices these days come with CF (Compact Framework) 2.0 installed in the ROM so I would at least look for that.

    On that same vain, you may even want to consider using a device with Windows Mobile 6.0 or 6.1 as they are easy to program with and will always have CF 2.0 pre-installed. In case you're wondering why I have not mentioned CF 3.0 or CF 3.5, it's just because the first Mobile platform to be release with those versions will be Windows Mobile 6.5, which is not out yet. Though you can always install the framework if you want (~8MB CAB).

    Granted, WinCE definitely gives you a more "Windows" look and feel to its GUI over its Windows Mobile cousin, so that is all a matter of your programming preference and what your end users want and need.

    Regarding kgiannakakis's comments on SDKs being only a thing layer, this is just not true. If you have a proper SDK you should have all of the same access to any devices or drivers that you would in C++ but with the ease of C#. For example, Honeywell provides an extensive SDK for all of our devices in C++, VB and C# and the C# portion of the SDK actually has more functionality than the C++ portion. You will never have to do a P/Invoke with our code from C#.

    If you want to take a look at the SDK I'm talking about, it's freely available to download here and has some great examples. IMHO I would actually consider the provided SDK as more important than the hardware in many cases since, most of the time, the hardware for the devices is pretty much the same. They all have ARM CPUs, WiFi, Bluetooth, Laser or Image based scanners, etc. Though, I looked at the Intermec link you posted and it doesn't look like that unit actually has a built in scanner...are you using an external scanner hooked to the device? Take a look at the Honeywell offering if you want here. We've got devices with probably the best imager based bar code scanner in the business, built into all of our units. And we have a rock solid SDK (I should know, I wrote a lot of it). And the SDK provides .NET extremely access to all of the hardware on the device. Ok...I'll stop my sales pitch now.

    As for one language over the other...it really all depends on what exactly you want to do.

    Drivers and services cannot be written in anything but Native (Win32) C or C++. So .NET is out for anything like that. C and C++ can absolutely be your friend on mobile devices in terms of keeping things lightweight, since you don't need the whole .NET framework to run the add. Remember,

    Andy Dent : Thanks. I love seeing someone else's enthusiasm for their work coming out despite incredible self-restraint :-) Evaluating devices has been interesting and it's early days. I agree with picking based on SDK - I was looking for some device characteristics to narrow down the SDKs.
    Andy Dent : Re the Intermec CK31 - the features list "Integrated 1D (standard, long range) / 2D Intermec scanning technology"
  • First I'll strongly echo Adam's recommendation against running anything based on CE .NET 4.2 at this point for essentially the same reason. At this point it's an ancient version of the OS and unless you are getting the terminal for free it's not worth it and if you choose to do C# development the download of the CAB to run .NET 2 is just painful.

    We've developed a lot of applications for both Motorola(Symbol) and Intermec devices. The current set of APIs for both of them work reliably so I'd worry more about the suitability of the device than the specific APIs. They also both provide reasonable sample programs that make it easy to cut and paste a solution.

    I have noticed one other big difference between Motorola and Intermec. On the Intermec devices I've worked with (in C#), it takes about a second for the decoder for each symbology to be loaded. This typically isn't a big deal if you use a limited number of symbologies and setup the scanner at the start of the application, but can cause significant delays if you change the decoders(symbologies) within the application.

How can you move ASP.Net controls to different places on the Web form at runtime?

Is there an accepted way to "move" a control.

My client wants to place a certain chunk of markup (representing some visual element) in one of several different places on the page. The locations are different to the point that I can't effect the change on CSS along (by floating it or something).

I considered just putting the control in multiple spots with Visible set to "false," then displaying the one in the place they wanted for that particular page.

However, the code for this control is not trivial -- there's a couple template sections, for instance. Having to dupe this in multiple places would get unwieldy. Also, I don't want to have to work with this control strictly from the code-behind for the same reason.

So, I'd like to put it in one place on the Web form, the move it around based on where I want it. Could I put Placeholders in different spots, have the control in one spot, then remove and add it to the right spot? I suspect this would work.

Does someone have a better idea? Is there a best practice for this?

From stackoverflow
  • Do Web Parts do what you want to do?

    Or, you can change the parent programmatically of your controls to move them into a separate area.

  • You could always put panels in the pre-defined locations and add the control to the specific panel at runtime.. Here's an example adding a label (the label could be replaced with any control).

    Dim lblDisplay As Label = New Label()
    lblDisplay.ID = "myLabel"
    lblDisplay.Text = "Some Text"
    pnlDisplay.Controls.Add(lblDisplay)
    

    As far as...

    "Also, I don't want to have to work with this control strictly from the code-behind for the same reason."

    I think you're going to have to do most of your work in the code behind.

    PS.. a good example of the whole usercontrol setup can be downloaded here.. http://www.asp.net/downloads/starter-kits/time-tracker/

    Deane : I meant that I didn't want to create it from the code-behind. I don't have a problem manipulating it in some form from the code-behind, but I'd like the bulk of it's mark up in the Web form.
    madcolor : I'm suggesting you create a user-control with the markup that has properties you can get/set and load a panel. No good reason to have your markup sitting in the webform that I can see.
  • You can override the Render method and place the controls wherever you want in the html.

    You only need to add controls to the Controls collection that must interact on the server. The rest of your HTML can just be written to the response stream. If you override Render you can create the html anyway you see fit, placing the controls in any order.

    Below is an example of how to write out your html.

    protected override void Render(HtmlTextWriter writer)
    {
      AddAttributesToRender(writer);
      writer.RenderBeginTag(TagKey);
    
      writer.RenderBeginTag(HtmlTextWriterTag.Div);
      _control.RenderControl(writer);
      writer.RenderEndTag();
    
      writer.RenderEndTag();
    }
    
  • I'd recommend using a placeholder control, moving your markup into a separate user control, then loading this at runtime and adding it to the relevant placeholder.

    Eg.

    // Load a user control
    MyControl userCtrl = (MyControl) LoadControl("~/Controls/MyControl.ascx");
    
    // Or create an instance of your control
    SubclassedControl subclassedCtrl = new SubclassedControl();
    
    // Do stuff with controls here
    userCtrl.LoadData();
    subclassedCtrl.Text = "Hello World";
    
    // Check which placeholder to add controls to
    PlaceHolder placeHolder = (foo=="bar") ? placeHolder1 : placeHolder2;
    
    // Add the controls
    placeHolder.Controls.Add(userCtrl);
    placeHolder.Controls.Add(subclassedCtrl);
    

    This will avoid cluttering up your page with unnecessary markup, and loading it at runtime will also avoid unnecessary confusion later, when another developer looks at the code and can't immediately see why a control is in one place in the markup, but renders on a completely different part of the page.

    Deane : How would I do this if the control is a extension of a standard ASP.Net control, so it exists as a .cs file in App_Code? Would I need to "wrap" it in a User Control (a .ascx file)?
    madcolor : Yes, then you can either load it in a placeholder or a panel.. same diff, only the panel spits a div or span tag where the placeholder doesn't.
    Mun : If you're subclassing a standard ASP.NET control, then rather than loading a control, you could create an instance of your control instead, and then add it to the placeholder. I've updated the code sample above to reflect this.
  • An alternative (and one I've seen done many times before) is through javascript and the DOM. Render your control inside a hidden div tag. So you would render your content here:

    <div id='rendercontent' style='display:none'>
      .. control here ..
    </div>
    

    Then, lets say you wanted to move it all here (the span tag is inside because that's what we're going to replace):

    <div id='newlocation1'><span></span></div>
    

    You would define the following javascript:

    <script language="JavaScript">
    function replaceNode(newElementID, targetElementID)
    {
        var targetElement=document.getElementById(targetElementID);
        var newElement=document.getElementById(newElementID);
        targetElement.replaceChild(newElement, targetElement.firstChild);
    }
    </script>
    

    And when you want to move the content to the new location, call:

    <script language="JavaScript">
    replaceNode('rendercontent','newlocation1');
    </script>
    

What's the difference with buffered synchronous I/O and asynchronous I/O?

When using a synchronous I/O such as fread which is buffered, the read operations are postponed and combined, I think that isn't done synchronously.

So what's the difference between a buffered synchronous I/O and an asynchronous I/O?

From stackoverflow
  • My understanding of async I/O is that you're notified when it's done via an interrupt of some sort so you can do more I/O at that point. With buffered I/O, you do it and forget about it, you never hear about that particular I/O again.

    At least that's how it is with the huge intelligent disk arrays we deal with.

    The idea of async I/O is that you begin the I/O and return to doing other stuff. Then, when the I/O is finished, you're notified and can do more I/O - in other words, you're not waiting around for it to finish.

    Specifically for the synchronous read case: you request some input and then wait around while it's read from the device. Buffering there just involves reading more than you need so it's available on the next read without going out to the device to get it.

    Async reads, you simply start the process to read then you go off and do something else while it's happening. Whether by polling or an interrupt, you later discover that the read is finished and the data is available for you to use.

    For writes, I'm not sure I can see the advantage of one over the other. Buffered sync writes will return almost immediately unless the buffer is full (that's the only time when an async write may have an advantage).

  • From a programming point of view, synchronous IO would be handled in the same function/process eg.

    var data0 = synchronousRead();
    var data1 = synchronousRead();
    

    whereas asynchronous IO would be handled by a callback.

    asynchronousRead(callBack1);
    doOtherStuff();
    ...
    
    function callBack1(data)
    {
        data0 = data;
    }
    
  • Synchronous IO is the "normal" kind where you call a routine, and flow of control continues when the routine has read into your local variable (ignoring writes).

    Asynchronous IO involves setting up a buffer variable (static, global, or otherwise long lived / wide scope) and telling the system that you want data put into it when it eventually becomes available. Your program then continues. When the system has the data, it sends you a signal / event / message of some kind, telling you that you now have data in your buffer variable.

    Async IO is usually used by GUI programs to avoid stalling the user interface while IO completes.

  • Synchronous I/O works on a polling basis: you poll, data is returned (when available---if not available, then: for blocking I/O, your program blocks until data is available; for non-blocking I/O, a status code is returned saying no data is available, and you get to retry).

    Asynchronous I/O works on a callback basis: you pass in a callback function, and it gets called (from a different thread) when data becomes available.

  • Look here. Evrything you want to know is explained.

    link to wikipedia

Am I experiencing a memory leak, or just high memory usage in Firefox?

I'm loading some fairly big data sets in to firefox (500 k or so) and drawing tables with them. Firefox is using up to 400 megs of memory. How can I tell if Firefox is leaking memory, or is just using a lot of memory just because it can?

Is there another browser which will use less memory if it doesn't need it? I get the feeling that firefox grabs a bunch of memory for itself and doesn't release it unless it has to. It may be apparent that my understanding of memory management in general is very superficial.

From stackoverflow
  • There is a setting you can set in firefox that forces it to free as much memory as it can on minimise:

    1. On the website url toolbar type about:config
    2. A page full of words will come up. right click anywhere and choose New -> Boolean
    3. For the name input type "config.trim_on_minimize" Select True
    4. Restart FireFox.
    morgancodes : cool. thanks! what do you mean by "on minimize"? When you minimize the browser window?
    ck : Yes, when you physically minimise it (through Windows+M or clicking the minimise button, or right click on the task bar and minimise).
    John Rasch : +1 - This is great, I've been running into the same issue except it occurs when I use Pandora to listen to music. I've been below 100K constantly instead of the usual 500K+ since I added this setting.
  • If it is leaking memory, then the mem usage (number of K) in your Windows task manager will continue to grow. If this number is fairly consistent, then Firefox is behaving normally. It is my opinion that Firefox requires far too much memory to behave normally.

  • You can turn on Windows Performance Monitor and see if the firefox.exe process is growing memory over time to confirm if there is a memory leak.

  • How can I tell if Firefox is leaking memory, or is just using a lot of memory just because it can?

    Open another page in a different tab. Then close your 'big' tab and see if the memory is freed.

  • I get the feeling that firefox grabs a bunch of memory for itself and doesn't release it unless it has to. It may be apparent that my understanding of memory management in general is very superficial.

    well, at 1 point Firefox requires a lot of memory, say 400Mb. maybe after that, it doesn't require so many memory, BUT

    since your system do not need this memory, it does not reclaim it to Firefox, which keeps it.

    If ever you launch other processes that need a lot of memory, then your OS will claim back memory to other processes that are running with a high priority.

    To summarize my ideas : it's probably not a memory leak.

    Is there another browser which will use less memory if it doesn't need it?

    why don't you try them?

  • Memory Leak - memory which is not released when it should be

    If the memory Firefox is allocating to hold your data is released when you navigate away from your page, there is no memory leak. You can than argue if Firefox if using too much memory or not, but that is something beyond your scope.

    You do have a leak on your hands if that memory is not released. In that case you should check if it is something you can handle in your JS code, or a firefox bug. If it's the latter, go ahead to the mozilla bugzilla, and open a ticket.

jQuery Autocomplete in ASP.net MVC doesn't work when the control created in Ajax way

I am running an issue, could you help me out with your knowledge..?

Basically, this autocomplete extension of jQuery depends onto the ready method of the jQueryLibrary. (I am not 100% sure what it does actually, but I can guess it checks wheather the DOM has been loaded, if loaded it does something as an regular "onload" event handler).

Now, I have an ASP.net MVC application where I am using Ajax to render a partial view (an ascx file) and that file contains the autocomplete textbox.

As the DOM has been already loaded and I am now modified the DOM with the content of the ascx file in an Ajax fashion, my text boxes into the ascx are not doing anything autocompletion. What could be an alternate or workaround of this problem..? Even I am a bit curious why it's not working..?

Any idea would be greatly appreciated.

Have a nice day

From stackoverflow
  • you need to load the autocomplete function again as like you said the new items in the dom have come after the jquery already loaded. You can either put the jquery function in the ascx (simple way) or force the jquery to run on the DOM again which may cause unintended results.

  • Jeremy thanks for your reply. Here is my ascx code. I didn't understand what you said by ""..could you be so kind explaining a bit more..? thanks a lot!

    here is an image that shows my user controls code. http://img10.imageshack.us/img10/6845/75246857.jpg

"SAX2 driver class org.apache.crimson.parser.XMLReaderImpl not found" when using Batik in a webapp on Tomcat

This is possibly related to a classpath problem, but I'm really not sure at this point, since I don't get this error on some machines.

The error at the top of the stack is SAX2 driver class org.apache.crimson.parser.XMLReaderImpl not found. Why would I get this error only in some environments, but not others? How can I further investigate and/or fix this?

Environments:

  • Jetty on Mac or PC == OK
  • Tomcat 5 or 6 on Mac == OK
  • Tomcat 5 or 6 on Win XP == ERROR
  • Tomcat 6 on CentOS == ERROR

Versions in the POM:

  • batik:batik:jar:1.5:compile
  • net.sf.saxon:saxon:jar:8.7:compile
  • batik:batik-transcoder:jar:1.6-1:compile
    • batik:batik-bridge:jar:1.6-1:compile
    • batik:batik-gvt:jar:1.6-1:compile
    • batik:batik-awt-util:jar:1.6-1:compile
    • batik:batik-util:jar:1.6-1:compile
    • batik:batik-gui-util:jar:1.6-1:compile
    • batik:batik-ext:jar:1.6-1:compile
    • xml-apis:xmlParserAPIs:jar:2.0.2:compile
    • batik:batik-script:jar:1.6-1:compile
    • batik:batik-svg-dom:jar:1.6-1:compile
    • batik:batik-dom:jar:1.6-1:compile
    • batik:batik-css:jar:1.6-1:compile
    • batik:batik-xml:jar:1.6-1:compile
    • batik:batik-parser:jar:1.6-1:compile
    • fop:fop:jar:0.20.5:compile
    • batik:batik-1.5-fop:jar:0.20-5:compile
    • xml-apis:xml-apis:jar:1.0.b2:compile
    • xalan:xalan:jar:2.4.1:compile
    • xerces:xercesImpl:jar:2.2.1:compile
    • avalon-framework:avalon-framework:jar:4.0:compile
From stackoverflow
  • It turns out that Apache XML Graphics itself adds Crimson to the classpath, twice. Once in the Apache Batik transcoder, and once in Apache FOP.

    Since the libs are loaded alphabetically in Tomcat, FOP included Crimson, first, but then Batik also did the same.

    I excluded FOP from the project POM, and have resolved the classpath issue.

Images aren't being displayed as embedded in email sent by my application

I'm trying to send an email with embedded images through a delphi application using Indy, but somehow it isn't working.

I compared the contents of the email I sent with one sent from gmail, and everything seens fine, but I might be missing some little detail.

Gmail shows the attached image of my email as a normal attachment, but it is set correctly as inline.

EDIT

Solved using the TIdMessageBuilderHtml it worked perfectly on the first try.

From stackoverflow
  • Solved using the TIdMessageBuilderHtml it worked perfectly on the first try.

    Just a few lines of code:

      with TIdMessageBuilderHtml.Create do
        try
          Subject := 'example';
          Html.Text := 'HTML goes here';
          HtmlFiles.Add('c:\folder\image1.jpg');
          HtmlFiles.Add('c:\folder\image2.jpg');
          FillMessage(IdMessage1);
        finally
          Free;
        end;
    

Binding XML data to WPF treeview Control

I have spend a lot of time trying to figure out how to bind data in my XML file to the TreeView control but I do not know where to start. I even tried going through http://stackoverflow.com/questions/188001/two-way-binding-of-xml-data-to-the-wpf-treeview and Josh Smith's code sample on codeproject, but still can't understand how to begin!!!

I have XML in in a file "C:\SPDependencies.xml" (I can change the format if required)!!!:

  <node type="SPDependencies" Name="SPDependencies">
        <node type="StoredProc" Name="SP1">
                <node type="OperationType" Name="Type1">
                        <node type="TableName" Name="Table1"/>
                        <node type="TableName" Name="Table2"/>
                </node>
                <node type="OperationType" Name="Type2">
                         <node type="TableName" Name="Table1"/>
                        <node type="TableName" Name="Table2"/>
                </node>
                 .....
        </node>
        <node type="StoredProc" Name="SP2">
              <node type="OperationType" Name="Type1">
              ...
              ...
        </node>
</node>

I need to display this in the Treeview control in the following format:

<SP1>
   <Type1>
      <Table1>
      <Table2>
      <Table3>
   <Type2>
      <Table1>
      <Table2>
      <Table3>
<SP2>
    <Type1>
........

Thanks, Abhi.

From stackoverflow
  • Heres the tree:

    <Window.Resources>
        <HierarchicalDataTemplate DataType="node"
                                  ItemsSource="{Binding XPath=node}">
            <TextBox Width="Auto"
                     Text="{Binding XPath=@Name, UpdateSourceTrigger=PropertyChanged}" />
        </HierarchicalDataTemplate>
    
        <XmlDataProvider
            x:Key="xmlDataProvider"
            XPath="node" Source="C:\Data.XML">
        </XmlDataProvider>
    </Window.Resources>
    <Grid>
        <StackPanel>
            <Button Click="Button_Click">Save</Button>
                <TreeView
                    Width="Auto"
                    Height="Auto"
                    Name="treeview"
                    ItemsSource="{Binding Source={StaticResource xmlDataProvider}, XPath=.}"/>
         </StackPanel>
    </Grid>
    

    I've added a simple button to save changes. So for your Button_Click method in code behind:

    XmlDataProvider dataProvider = this.FindResource("xmlDataProvider") as XmlDataProvider;
    dataProvider.Document.Save(dataProvider.Source.LocalPath);
    

    See here for an article about data binding and WPF.

    Number8 : I'm interested in this topic, as well. Is there something missing in your answer? I can't get any data to display... Thanks.
    Crippeoblade : I suggest you create a new question and post your code so we can see what the problem is.

PROBLEM encountered visual studio 2008 installation

I installed visual studio 2008 package FULL option. It worked with out any problem. I installed Vstudio 2008 and MSDN in separate folder in the D drive. 2 days later in order to remove my projects i uninstalled every thing and also i deleted visual studio 2008, visual studio 2005 folders from C:\Documents and Settings\IRCTC\My Documents. (i believe these 2 folders were automatically created when we install visual studio) also i cleared %path% and path (c/windows/path). Again i installed VISUAL STUDIO 2008 but now i can't able to create window application (other web, vb also), what is the solution for this ... ERROR that shown is

c:/documents and settings/IRCTC/local settings/temp/g1zzsdl.bak/temp/windowsFormsApplication.csproj cannot be opened because project type (.csproj) is not supported by this version of visual studio.......please help....

whether any system file corrupted (windows temp or .net folber in windows)..... no other installation problem found in my system..... please help.....what are the files/folders required for the installation......

From stackoverflow
  • why didn't you use visual studio's uninstall function available from the control panel|add/remove programs?

    i would uninstall the latest installation as described above, and try again.

  • When you get that error is usually because:

    1. You are trying to open a project created with a previous version of Visual Studio (not your case)
    2. There was a bit of a screw-up during the installation (sounds like your case)

    I'd uninstall the thing and reinstall completely first thing.

    If it still doesn't work, it could be related to VS templates and you might wanna try and run from Visual Studio 2008 command prompt:

    devenv /InstallVSTemplates
    

    If it still doesn't work, open Visual Studio, in the menu, Open Tools->Options->Projects and Solutions->General. At this point you will notice the path of Project Templates is set to "C:\Documents and Settings[yourUserName]\My Documents\Visual Studio 9\Templates\ProjectTemplates" or something very similar to that. In order to fix it you gotta set that path to C:\Program Files\Microsoft Visual Studio 9\Common7\IDE\Project Templates or the same path according to wherever you installed Visual Studio

    I don't hitnk is related to VS project Templates though - see this link

    try and see what happens!

Simple (Dumb) LINQ Provider

Hi,

How easy would it be to write a dumb LINQ provider that can just use my class definitions (which don't have any object references as properties) and give me the translated SQL. It can assume the name of the properties and the columns to be same as well as the names of the classes and the underlying tables. Can you please give me some pointers.?

From stackoverflow
  • Give a look to the LINQExtender project, is a toolkit for creating custom LINQ providers.

  • It took me about 4 months of fulltime work (8 hours a day) to build a stable, working provider that implements the entire spec of linq. I would say I had a very simple, buggy and unstable version after about three weeks, so if you're just looking for something rough I would say you're probably looking at anything from a week up to two months depending on how good you are and what types of requiements you have.

    I must point you to the Wayward blog for this, Matt has written a really good walkthrough on how to implement a linq provider, and even if you're probably not going to be able to copy and paste, it will help you to get to grips with how to think when working. You can find Matt´s walkthrough here: http://blogs.msdn.com/mattwar/archive/2007/07/30/linq-building-an-iqueryable-provider-part-i.aspx . I recommend you go about it the same way Matt does, and extend the expression tree visitor Matt includes in the second part of his tutorial.

    Also, when I began working with this, I had so much help from the expression tree visualizer, it really made parsing a whole lot easier once you could see how linq parsed to queries.

    Building a provider is really a lot of fun, even if a bit frustrating at times. I wish you all the best of luck!

JPEG Quality when creating a JPEG in Carbon

I'm writing a Carbon application and we are creating JPEG files. I'm currently doing this by using Quartz CGImageDestinations and kCGImagePropertyJFIFDictionary. However, JFIF doesn't seem to have any entry for compression quality. Does anyone know how to set this?

thanks

From stackoverflow
  • This is separate from the JFIF options, since some other formats (including TIFF) support lossy compression. The key you use is kCGImageDestinationLossyCompressionQuality, and you put this option and the JFIF-options dictionary into the same dictionary; you don't put it into the JFIF-options dictionary.

    Brian Postow : Actually, the mac doesn't seem to support lossy TIFF... only LZW. but this works for JPEG! thanks
    Peter Hosey : Huh, you're (sort of) right. The relevant key is kCGImagePropertyTIFFCompression, and I found a blog post that suggests you use NSTIFFCompression constants with it, but the documentation of NSTIFFCompressionJPEG says that it's no longer supported. (OTOH, PackBits and CCITT fax are.) Weird.

Progressbar in listbox?

I have a listbox that contains a bunch of file downloads, i want to add a progress bar to the current download to let the user know the progress of the download. I cannot figure out how to do this.

From stackoverflow
  • You need to use owner drawn list box

    Use a normal ListBox and set DrawMode = DrawMode.OwnerDrawFixed and handle the two events MeasureItem and DrawItem.

    The downside is that you have to take care of all the drawing yourself, but at least text and a progress bar are easy to draw.

  • Why ListBox? Use ListView, with a simple Google you find ton of ListView+Progress Bars.

Process Explorer - How does the dragabble crosshair work?

There is a feature in sysinternal's process explorer that allows a crosshair to be dragged from the application to a control in any other application you are running and highlights said control. Does anyone know how this was achieved or if there is a .NET/C++ library out there that can be reused?

From stackoverflow
  • Using Win32 API

    • GetCursorPos: to get the cursor position (maybe .NET has its own function to do that)
    • WindowFromPoint: to get the handle of the window from a specific point in the screen

    more info

    John Dibling : That's all there is to it; I wonder why this hasn't been accepted yet.

What should a good technical design document contain?

When writing a technical design document of a yet non-existent application/system, what aspects would be most helpful for the developers - assuming that the person writing the document is not involved in the actual development? There are some obvious things, and standard structures, of course, like

  • system architecture
  • interfaces (external, internal)
  • infrastructure
  • component description
  • use cases

I would be interested in a broader viewpoint, and also knowing what are the most often missing elements from a technical design document from a developer point of view?

From stackoverflow
  • For me, a design document answers the questions: How is the software built? and Why is it built that way? (I mean architecture, not Makefile), whereas a specification document answers the question: What shall the software do?

    With this point of view, external interface should belong to specification document, not design document. This does not mean that there is no discussion about it during development phase, this means that developers of other modules want to get this information from general specification and not design of another component.

  • In terms of what someone not involved in development can contribute, I think a glossary is one of the most helpful. Ideally this section would be for definitions specific to the project, although it may help to have some more general definitions, depending on the document's audience (if this will be only read by the developers, or if you might have some others outside of the development team reading it).

    The idea is to keep the team consistent with semantics so as to prevent confusion later on. For example, when developing a shopping cart process, the team should know exactly what constitutes an "order": if some members of the team think an order is created the moment a user confirms their purchase, while others think an order is begun the moment a user begins adding items to their cart, there will be issues. Getting everybody on the same page with these details can save them lot of headaches in communicating about the project's design.

  • In an event of more than one technology platform involved it would be an idea to insert TECHNOLOGY Break-down as well. Just a thought... Regards, Andy

  • You should be sure to include a section on assumptions and dependencies to detail what will be the limitations and boundaries of your system, and what must be true in order for it to function (eg, other systems must provide data, etc). This is important also for more business-oriented documents, as it can protect your team from failures of outside systems.

    It is also helpful for the developers of the system, though, so they know exactly what their system must do, and where and how they will interact with other systems.

  • short, concise and useful.

    Ivan

  • what Would i used to make a software... is any software to be install in my personal computer to make a software... designing software...

Why Jython behaves inconsistently when tested with PyStone?

I've been playing recently with Jython and decided to do some quick and dirty benchmarking with pystone. In order to have a reference, I first tested cPython 2.6, with an increasing numbers of loops (I thought this may be relevant as Jython should start to profit from the JIT only after some time).

(richard garibaldi):/usr/local/src/pybench% python ~/tmp/pystone.py 
Pystone(1.1) time for 50000 passes = 1.04
This machine benchmarks at 48076.9 pystones/second

(richard garibaldi):/usr/local/src/pybench% python ~/tmp/pystone.py 500000 
Pystone(1.1) time for 500000 passes = 10.33
This machine benchmarks at 48402.7 pystones/second

(richard garibaldi):/usr/local/src/pybench% python ~/tmp/pystone.py 1000000 
Pystone(1.1) time for 1000000 passes = 19.6
This machine benchmarks at 51020.4 pystones/second

As you can see, cPython behaves consistently: the time it takes to complete the test increases linearly to the number of loops. Knowing this, I started testing Jython.

(richard garibaldi):/usr/local/src/pybench% jython ~/tmp/pystone.py 
Pystone(1.1) time for 50000 passes = 2.29807
This machine benchmarks at 21757.4 pystones/second

(richard garibaldi):/usr/local/src/pybench% jython ~/tmp/pystone.py 500000 
Pystone(1.1) time for 500000 passes = 10.931
This machine benchmarks at 45741.4 pystones/second


(richard garibaldi):/usr/local/src/pybench% jython ~/tmp/pystone.py 1000000
Pystone(1.1) time for 1000000 passes = 107.183
This machine benchmarks at 9329.86 pystones/second

During the first run Jython runs rather lousily in comparison to its C brother. When increased the number of loops it started feeling better, coming close to cPython, like my initial hypothesis predicted. Note that the number of loops increased 10 times, but it took Jython only about 5 times longer to complete them. So, as you imagine, I was expecting that Jython would really rock in the final test. To my great disappointment, however, it did really bad: more than twice slower than in the initial run.

What are your hypotheses: why does Jython behave such an inconsistent manner? Could it be that GC is kicking in at some moment, and taking a lot of time? I've looked at PyStone's code and garbage collection doesn't seem to be turned off, but I would expect Java's GC to be at least as good as Python's... Do you think this slowing down is permanent, or it will go away at some point after increasing the number of loops? How shall Jython behave in a really long running processes?

EDIT: unfortunately, I get java.lang.OutOfMemoryError if I increase the number of loops to 2 million...

(Of course, Jython is still beta, so it should get better in the final release.)

I am using Jython 2.5b1 (trunk:5903:5905, Jan 9 2009, 16:01:29), Java(TM) SE Runtime Environment (build 1.6.0_07-b06-153) and Java HotSpot(TM) 64-Bit Server VM (build 1.6.0_07-b06-57, mixed mode) on MacOS X 10.5.

Thanks for your answers.

From stackoverflow
  • I'm pretty sure that the results can be improved by tweaking the JVM configuration (JRuby is using quite a few interesting flags for doing it) and I'm also pretty sure that the garbage collection can be tuned. If you are very interested in this benchmark here is a good resource for configuring your VM: Tuning Garbage Collection. I'd also take a look at JRuby configuration.

    ./alex

  • This might be a bug in jython 2.5b1. You should consider reporting it back to the jython team. I have just run the pystone benchmark on my MacBook with the current stable release of jython (2.2.1) and I get slow but consistent results:

    mo$ ~/Coding/Jython/jython2.2.1/jython pystone.py 50000
    Pystone(1.1) time for 50000 passes = 2.365
    This machine benchmarks at 21141.6 pystones/second
    
    mo$ ~/Coding/Jython/jython2.2.1/jython pystone.py 500000
    Pystone(1.1) time for 500000 passes = 22.246
    This machine benchmarks at 22476 pystones/second
    
    mo$ ~/Coding/Jython/jython2.2.1/jython pystone.py 1000000
    Pystone(1.1) time for 1000000 passes = 43.94
    This machine benchmarks at 22758.3 pystones/second
    
    mo$ java -version
    java version "1.5.0_16"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_16-b06-275)
    Java HotSpot(TM) Client VM (build 1.5.0_16-132, mixed mode, sharing)
    

    The cPython results for me are more or less the same. I reran eacht test three times and got very similar results all the time.

    I also tried giving java a bigger initial and maximum Heap (-Xms256m -Xmx512m) without a noteworthy result

    However, setting the JVM to -server (slower startup, better long running performance, not so good for "interactive" work) turned the picture a bit:

    mo$ ~/Coding/Jython/jython2.2.1/jython pystone.py 50000
    Pystone(1.1) time for 50000 passes = 1.848
    This machine benchmarks at 27056.3 pystones/second
    
    mo$ ~/Coding/Jython/jython2.2.1/jython pystone.py 500000
    Pystone(1.1) time for 500000 passes = 9.998
    This machine benchmarks at 50010 pystones/second
    
    mo$ ~/Coding/Jython/jython2.2.1/jython pystone.py 1000000
    Pystone(1.1) time for 1000000 passes = 19.9
    This machine benchmarks at 50251.3 pystones/second
    

    I made one final run with (-server -Xms256m -Xmx512m):

    mo$ ~/Coding/Jython/jython2.2.1/jython pystone.py 5000000
    Pystone(1.1) time for 5000000 passes = 108.664
    This machine benchmarks at 46013.4 pystones/second
    

    My guess would be, that the slow first run is due to VM startup/JIT not yet having really kicked in. The results of the longer runs are more or less consitent and show the effects of hotspot/JIT

    Maybe you could rerun your last test with a bigger heap? To change the JVM switches, just edit the jython file in your Jython installation.

  • Hi, my bench on a XP_Win32_PC :

    C:\jython\jython2.5b1>bench "50000"
    
    C:\jython\jython2.5b1>jython Lib\test\pystone.py "50000"
    Pystone(1.1) time for 50000 passes = 1.73489
    This machine benchmarks at 28820.2 pystones/second
    
    C:\jython\jython2.5b1>bench "100000"
    
    C:\jython\jython2.5b1>jython Lib\test\pystone.py "100000"
    Pystone(1.1) time for 100000 passes = 3.36223
    This machine benchmarks at 29742.2 pystones/second
    
    C:\jython\jython2.5b1>bench "500000"
    
    C:\jython\jython2.5b1>jython Lib\test\pystone.py "500000"
    Pystone(1.1) time for 500000 passes = 15.8116
    This machine benchmarks at 31622.3 pystones/second
    
    C:\jython\jython2.5b1>bench "1000000"
    
    C:\jython\jython2.5b1>jython Lib\test\pystone.py "1000000"
    Pystone(1.1) time for 1000000 passes = 30.9763
    This machine benchmarks at 32282.8 pystones/second
    
    C:\jython\jython2.5b1>jython
    Jython 2.5b1 (trunk:5903:5905, Jan 9 2009, 16:01:29)
    [Java HotSpot(TM) Client VM (Sun Microsystems Inc.)] on java1.5.0_17
    

    It is not so fast, but ...

    no "special effects"

    Is it a java-vm 'problem' ?

    Add a comment if you want further infos to my benchmarking on this old Win32-PC

  • The same results from my laptop running Ubuntu Jaunty, with JRE 1.6.0_12-b04:

    nathell@breeze:/usr/lib/python2.5/test$ python pystone.py 500000
    Pystone(1.1) time for 500000 passes = 12.98
    This machine benchmarks at 38520.8 pystones/second
    
    nathell@breeze:/usr/lib/python2.5/test$ python pystone.py 1000000
    Pystone(1.1) time for 1000000 passes = 26.05
    This machine benchmarks at 38387.7 pystones/second
    
    nathell@breeze:/usr/lib/python2.5/test$ ~/jython/jython pystone.py
    Pystone(1.1) time for 50000 passes = 2.47788
    This machine benchmarks at 20178.6 pystones/second
    
    nathell@breeze:/usr/lib/python2.5/test$ ~/jython/jython pystone.py 500000
    Pystone(1.1) time for 500000 passes = 19.7294
    This machine benchmarks at 25342.9 pystones/second
    
    nathell@breeze:/usr/lib/python2.5/test$ ~/jython/jython pystone.py 1000000
    Pystone(1.1) time for 1000000 passes = 38.9272
    This machine benchmarks at 25689 pystones/second
    

    So perhaps this is related to the JRE rather than Jython version, after all. The problems the Armed Bear Common Lisp project has had with early versions of JRE 1.6 (see http://tiny.pl/b9r5) might also hint at this.

  • Benchmarking a runtime environment as complex as the JVM is hard. Even excluding the JIT and GC, you've got a big heap, memory layout and cache variation between runs.

    One thing that helps with Jython is simply running the benchmark more than once in a single VM session: once to warm up the JIT and one or more times you measure individually. I've done a lot of Jython benchmarking, and unfortunately it often takes 10-50 attempts to achieve a reasonable time

    You can use some JVM flags to observe GC and JIT behavior to get some idea how long the warmup period should be, though obviously you shouldn't benchmark with the debugging flags turned on. For example:

    % ./jython -J-XX:+PrintCompilation -J-verbose:gc
      1       java.lang.String::hashCode (60 bytes)
      2       java.lang.String::charAt (33 bytes)
      3       java.lang.String::lastIndexOf (156 bytes)
      4       java.lang.String::indexOf (151 bytes)
    [GC 1984K->286K(7616K), 0.0031513 secs]
    

    If you do all this, and use the HotSpot Server VM, you'll find Jython slightly faster than CPython on pystone, but this is in no way representative of Jython performance in general. The Jython developers are paying much more attention to correctness than performance for the 2.5 release; over the next year or so with a 2.6/2.7/3.0 release performance will be more emphasized. You can see a few of the pain points by looking at some microbenchmarks (originally derived from PyPy) I run.

How to "unbind" an event handler attached to an event in the base class when I'm in a derived class?

I had once a situation where I had to override the event handler in some derived class of mine. I could not unfortunately just "override" it since the implementation logic was bound strictly to that particular method implementation in the base class.

My natural idea was to first "unbind" the original event handler from the event and then to bind my own brand-new method. So I tried to use the "-=" operator like:

myObject.SomeEvent -= new EventHandler (BaseClass.SomeEventHandler)

at which point the compiler complainer that it had no access to the private method SomeEventHandler. Since the base class was a part of the library I did not really want to modify its implementation (though simply as it seems by just turning "private" into "protected");

It's so simple to attach an event handler to an event. Why is it so difficult to get rid of one?

Why I wanted it? Because the base implementation was casing some problems (just did not handle our particular case) so I wanted to redefine it. But even after I attached my event handler the base implementation was getting executed anyway. Since it was doing some kind of Redirect, my own implementation was never going to run since the request processing was being broken at server after redirect.

Is there anyway to get rid of an event handler in a base class from a library without modifying its implementation?

From stackoverflow
  • It would be just as easy to get rid of the handler if your code can officially see the handler. If absolutely necessary, it is possible to unsubscribe using reflection to get hold of the delegate, but this is messy. It would be a lot cleaner and safer to either a: avoid the requirement, or b: change the code to make the handler protected.


    Reflection approach (use at own risk); uncomment the block in the Bar.ctor() to see the change.

    using System;
    class Foo
    {
        public event EventHandler SomeEvent;
        public Foo()
        {
            SomeEvent += SecretHandler; // a bad idea, anyway
                                        //(self-subscribed events....)
        }
        protected virtual void OnSomeEvent()
        {
            EventHandler handler = SomeEvent;
            if (handler != null) handler(this, EventArgs.Empty);
        }
        private void SecretHandler(object sender, EventArgs args)
        {
            Console.WriteLine("suscribed");
        }
    }
    class Bar : Foo
    {
        public Bar()
        {
            /*
            MethodInfo method = typeof(Foo).GetMethod("SecretHandler",
                BindingFlags.NonPublic | BindingFlags.Instance);
            EventHandler handler = (EventHandler)Delegate.CreateDelegate(
                typeof(EventHandler), this, method);
            SomeEvent -= handler;
             */
        }
        public void Test()
        {
            OnSomeEvent();
        }
    }
    static class Program
    {
        static void Main()
        {
            Bar bar = new Bar();
            bar.Test();
        }
    }
    
    User : Isn't there a way to get rid of just all the attached handlers without having access to them? Just let the system secretly from you identify and unbind them all?
    User : Will you be so kind as to show how to do it using reflection?

How can I merge two mysql databases with identical schema?

I need to merge two two mysql databases with identical schema. I am looking for some tool that can read database meta-data (PK, FK) and automatically generate new PKs, updating all the FKs automatically.

From stackoverflow
  • Check out SqlYog - http://www.webyog.com/en/. There is a 30 day trial for the enterprise edition which includes a tool to synchtonise data between databases (among many other useful tools).

  • Not sure exactly what you mean, but if you got two databases and want to make them identifcal,try this tool - Database compare

    Christian Oudard : It seems that his databases are already identical, and he just wants to combine the data in them.

Referrals DB schema

I'm coding a new {monthly|yearly} paid site with the now typical "referral" system: when a new user signs up, they can specify the {username|referral code} of other user (this can be detected automatically if they came through a special URL), which will cause the referrer to earn a percentage of anything the new user pays.

Before reinventing the wheel, I'd like to know if any of you have experience with storing this kind of data in a relational DB. Currently I'm using MySQL, but I believe any good solution should be easily adapted to any RDBMS, right?

I'm looking to support the following features:

  • Online billing system - once each invoice is paid, earnings for referrals are calculated and they will be able to cash-out. This includes, of course, having the possibility of browsing invoices / payments online.

  • Paid options vary - they are different in nature and in costs (which will vary sometime), so commissions should be calculated based on each final invoice.

  • Keeping track of referrals (relationship between users, date in which it was referred, and any other useful information - any ideas?)

  • A simple way to access historical referring data (how much have been paid) or accrued commissions.

  • In the future, I might offer to exchange accrued cash for subscription renewal (covering the whole of the new subscription or just a part of it, having to pay the difference if needed)

  • Multiple levels - I'm thinking of paying something around 10% of direct referred earnings + 2% the next level, but this may change in the future (add more levels, change percentages), so I should be able to store historical data.

Note that I'm not planning to use this in any other project, so I'm not worried about it being "plug and play".

Have you done any work with similar requirements? If so, how did you handle all this stuff? Would you recommend any particular DB schema? Why?

Is there anything I'm missing that would help making this a more flexible implementation?

From stackoverflow
  • Rather marvellously, there's a library of database schemas. Although I can't see something specific to referrals, there may be something related. At least (hopefully) you should be able to get some ideas.