instruction
stringlengths
0
30k
Derive from Exception or ApplicationException in .NET
|.net|exception|
What is best practice when creating your exception classes in a .NET solution. To derive from System.Exception or from System.ApplicationException?
Wrap the DataContext, then mock the wrapper. Its the fastest way to get it done, tho it requires coding for testing, which some people think smells. But sometimes, when you have dependencies that cannot be (easily) mocked, its the only way.
Count a list of cells with the same background color
|excel|
Each cell contains some text and a background color. So I have some cells that are blue and some that are red. What function do I use to count the number of red cells? I have tried =COUNTIF(D3:D9,CELL("color",D3)) with no success (Where D3 is red).
|excel|vba|
|excel|vba|
Just as an aside, the STL shipped with MS Visual Studio C++ (Dinkumware IIRC) provides a map implementation with an <code>erase</code> function returning an iterator to the next element. They do note it's not standards conforming.
[`ApplicationException` considered useless](http://blogs.msdn.com/kcwalina/archive/2006/06/23/644822.aspx) – a strong, and critical, argument.
The authors of the framework themselves consider ApplicationException worthless: <http://blogs.msdn.com/kcwalina/archive/2006/06/23/644822.aspx> with a nice follow-up here: <http://blogs.msdn.com/kcwalina/archive/2006/07/05/657268.aspx> When in doubt, I follow their book Framework Design Guidelines. http...
You've got three choices: 1. Create a [server side proxy script][1]. 2. Create a remote script to read in remote dynamic HTML. Use a library like [jQuery][2] to make this easier. You can use the [load function][3] to inject HTML where needed. 3. Use a [client side Flash proxy][4] and setup a [crossdomain.xml][5] f...
According to Jeffery Richter in the Framework Design Guidelines book: > `System.ApplicationException` is a class that should not be part of the .NET framework. It was intended to have some meaning in that you could potentially catch "all" the application exceptions, but the pattern was not followed and so it has ...
I try to stick to my keyboard as well. I frequently use... - Win+L to Lock my system - Alt+F4 to close a program - Win+R to launch from the Run Window (Used for frequent programs instead of going through QuickLaunch) - F2 to rename a file - Win+D to go to Desktop - Alt+Tab and Alt+Tab+Shift to cycle...
I've set up Passenger in development (Mac OS X) and it works flawlessly. The only problem came later: now I have a custom `GEM_HOME` path and ImageMagick binaries installed in `"/usr/local"`. I can put them in one of the shell rc files that get sourced and this solves the environment variables for processes spawned fro...
You can display the 'reason' in the status bar. Or even better, use a text that describes the action and contains information when such action is possible. For example, for 'Copy' menu item, the text in status bar would be: Copy the selected text. Note the 'selected' part, which tells the user that he needs to select t...
What's the correct term for "number of std deviations" away from a mean
|statistics|
I've computed the mean & variance of a set of values, and I want to pass along the value that represents the # of std deviations away from mean for each number in the set. Is there a better term for this, or should I just call it num_of_std_devs_from_mean ...
At a minimum you want to know that the system is healthy. This is subjective in what defines your system is healthy. Is it computers are up, the needed resources exist, the data is flowing through the system, the data is properly producing results, etc, etc. In my project we do monitoring of most of this and then so...
This is by no means an easy problem. I'll try to give you an overview only. What you could do is something like the following: 1. Compute the average (root-mean-square) loudness of the signal over blocks of, say, 5 milliseconds. (Having never done this before, I don't know what a good block size would be.) 2. ...
If it's solely for stackoverflow, you can use this : http://stackoverflow.com/feeds/tag/silverlight%20wpf For a more general solution, I don't know. You'd probably have to manually iterate the elements of the two feeds and join them together. You can compare the &lt;id> elements of &lt;entry>s to see if they are du...
Unsigned integers are not CLS compliant because they're not interoperable between certain languages.
I think it also might have to do with simplifying things on a lower level, since Array.Length will of course be added to a negative number at some point, if Array.Length were unsigned, and added to a negative int (two's complement), there could be messy results.
I would be wary of the impression of randomness: there have been many experiments where people would choose the less random distribution. It seems the mind is not very good at producing or estimating randomness. There are good articles on randomness at [Fourmilab][1], including another [true random generator][2]. Ma...
Not all languages have the concept of unsigned ints. For example VB 6 had no concept of unsigned ints which I suspect drove the decision of the designers of VB7/7.1 not to implement as well (it's implemented now in VB8). To quote - [http://msdn.microsoft.com/en-us/library/12a7a7h3.aspx][1] *"The CLS was design...
Not all languages have the concept of unsigned ints. For example VB 6 had no concept of unsigned ints which I suspect drove the decision of the designers of VB7/7.1 not to implement as well (it's implemented now in VB8). To quote - [http://msdn.microsoft.com/en-us/library/12a7a7h3.aspx][1] *"The CLS was design...
1. If you don't have Visual C++ Express Edition (VCEE), download and install [VCEE][1]. 2. The default install of Visual C++ Express Edition builds for the .Net platform. We'll need to build for the Windows platform since OpenGL and GLUT are not yet fully supported under .Net. For this we need the Microsoft Platform S...
I think it doesn't matter really, because the ftp is also transparent nowdays. You don't have to know anything special, the browser handles all. I suggest that if they are downloading one file at one time, you can go to http. However if they have to download several files with one go, I prefer ftp, because it's m...
I did something similar to your idea once and it was very successful, though I suspect it is really more of a system test than a unit test. As you suggest your random number generator must be seeded with the same value, and must produce an identical sequence each time. The game ran on 50hz cycles, so timing was not an...
1. Warning about the Wp64 setting. >Turn off the **/Wp64** setting which is set by default. You can find it in *Project Properties -> C/C++ -> General*. 2. Warning about the compiler version. > Go to the Boost trunk (online) and get the latest **boost\boost\config\compiler\visualc.hpp** header file. Diff it with t...
If it's solely for stackoverflow, you can use this : http://stackoverflow.com/feeds/tag/silverlight%20wpf This **will** do an union of the two tags. For a more general solution, I don't know. You'd probably have to manually iterate the elements of the two feeds and join them together. You can compare the &lt;i...
How do I use transactions with Stomp and ActiveMQ (and Perl)?
|perl|activemq-classic|stomp|
I'm trying to replace some bespoke message queues with ActiveMQ, and I need to talk to them (a lot) from Perl. ActiveMQ provides a Stomp interface and Perl has Net::Stomp, so this seems like it should be fine, but it's not. Even if I send a BEGIN command over Stomp, messages sent with SEND are immediately published...
It looks like the aspect parameter on your gluPerspective call need tweaking. See [The Man Page][1]. If your window were physically square, the aspect ratio would be 1 and your problem would go away. However, your window is rectangular, so the viewing frustum needs to be non-square. Set the aspect ratio to window...
That is normalizing your values. You could just refer to it as the normalized value. Maybe norm_val would be more appropriate.
I believe you first have to change a setting in umbracosettings.config: <useDomainPrefixes>true</useDomainPrefixes> Then I think you also have to right click on each top node and click 'Manage Hostnames', then add the appropriate host name for that top node. It already sounds like you have IIS configured c...
The standard deviation is usually denoted with the letter σ (sigma). Personally, I think more people will understand what you mean if you do say number of standard deviations. As for a variable name, as long as you comment the declaration you could shorten it to std_devs.
[http://weblogs.asp.net/scottgu/archive/2008/05/12/visual-studio-2008-and-net-framework-3-5-service-pack-1-beta.aspx][1] [1]: http://weblogs.asp.net/scottgu/archive/2008/05/12/visual-studio-2008-and-net-framework-3-5-service-pack-1-beta.aspx There is a section in there on the improvements for web development....
Qt - Event handler
|c++|events|qt|problem-solving|
Does any one know how the event handler manages the posted events? In my app i have two threads(1:guiThread and 2:computationThread). After an exception is thrown I call postEvent(..)to an existing dialog. The Qt-Event-Handler holds this one back until the dialog is closed.
My personal favourite is WinKey, U, Enter - shuts Windows down! ;-)
Do not hold me to this but I am pretty sure it depends on the application it self. I know many always open on the main monitor, some will reopen to the same monitor they were previously run in, and some you can set. I know for example I have shortcuts to open command windows to particular directories, and each has an o...
[CairoPlot][1] [1]: http://linil.wordpress.com/2008/06/14/cairoplot-plotting-graphics-using-python-and-cairo/
WCF: WTF! Does WCF raise the bar or just the complexity level?
|web-services|wcf|
I understand the value of the three-part service/host/client model offered by WCF. But is it just me or does it seem like WCF took something pretty direct and straightforward (the ASMX model) and made a mess out of it? Is there an alternative to using SvcUtil's command line step back in time to generate the proxy? ...
We saw this in our environment, and traced part of it down to the "NOLOCK" hint in our queries. We removed the NOLOCK hint and set our servers to use Snapshot Isolation mode, and the frequency of these errors was reduced quite a bit.
How do I add a div and pick it up later
|javascript|dhtml|dynamic-css|
I think this is specific to IE 6.0 but... In javascript I add a div to the dom...I assign an ID attribute. When I later try to pick up the Div by the ID all I get is null??? Any suggestions? Example: var newDiv = document.createElement("DIV"); newDiv.setAttribute("ID", "obj_1000"); document.appendChild(ne...
Stack Overflow uses jQuery if that matters. Scriptaculous tries pretty hard to do everything that you can do in Flash. Dojo has an SVG abstraction that lets you do things that are not directly supported in JavaScript.
Short list: ASP.NET: Dynamic Data now included in .Net 3.5 and all necessary project templates for VS also available ASP.NET: History support added. Now we can control AJAX pages behavior on Back/Forward buttons pressed in very simple manner that was shown previously on MS demos ASP.NET: Script Combining feature a...
[sigma][1] is what you want, I think. [1]: http://en.wikipedia.org/wiki/Standard_deviation
How do I use a vendor Apache with a self-compiled Perl and mod_perl?
|perl|apache|mod-perl|
I want to use Apple's or RedHat's built-in Apache but I want to use Perl 5.10 and mod\_perl. What's the least intrusive way to accomplish this? I want the advantage of free security patching for the vendor's Apache, dav, php, etc., but I care a lot about which version of Perl I use and what's in my @INC path. I don'...
When talking about Agile, you could do both, but in a general way, you will do [spikes][1] (prototypes) only to try specific issues, learn about them and be able to do better estimates. Throw away when you are doing a simple spike and refactoring when you are really coding the application. Kind Regards [1]: h...
Not all RDBMS support IF (or DECODE in Oracle) statements. If not you could use a subquery to define table "a" and search for all employee's named JO SMITH or a combination. SELECT a.employee_id, a.surname, sum(a.counter) FROM (SELECT employee_id, surname, ...
Unable to receive JSON from JQuery ajax call
|jquery|ajax|json|
I have determined that my JSON, coming from the server, is valid (making the ajax call manually), but I would really like to use JQuery. I have also determined that the "post" url, being sent to the server, is correct, using firebug. However, the error callback is still being triggered (parsererror). I also tried datat...
Regardless of the persisted format, using a Regex would be the fastest way of parsing. In ruby it'd probably be a few lines of code. \[KEY:(.*)\] \[SUBKEY:(.*)\] These two would get you the Value and SubValue in the first group. Check out MSDN on how to match a regex against a string. This is someth...
How to load plugins in .NET?
|.net|windows|plugins|
I'd like to provide some way of creating dynamically lodable plugins in my software. Typicial way to do this is using the <a href="http://msdn.microsoft.com/en-us/library/ms684175(VS.85).aspx">LoadLibrary</a> WinAPI fuction to load a dll and calling <a href="http://msdn.microsoft.com/en-us/library/ms683212(VS.85).aspx...
Is there a python module for regex match in zip files
|python|zip|text-processing|
I have over a million text files compressed into 40 zip files. I also have a list of about 500 model names of phones. I want to find out the number of times a particular model was mentioned in the text files. Is there any python module which can do a regex match on the files without unzipping it. Is there a simple ...
Basically you can do it in two ways. The first is to import kernel32.dll and use LoadLibrary and GetProcAddress as you used it before: [DllImport("kernel32.dll")] internal static extern IntPtr LoadLibrary(String dllname); [DllImport("kernel32.dll")] internal static extern IntPtr GetProcAd...
There doesn't seem to be a solution. The resolution can be increased to **640x480** using [this hack][1] shared by *lifebelt77*. Here are the details reproduced: Add to **highgui.h**: #define CV_CAP_PROP_DIALOG_DISPLAY 8 #define CV_CAP_PROP_DIALOG_FORMAT 9 #define CV_CAP_PROP_DIALOG_SOURCE 10 #...
I ran the code here, and the error message showed (and it is right!) that you are setting *id* field twice as primary key.
I've been successfully using it on Vista x64 for some light Java work. Nothing too involved and no extra plugins, but basic Java coding has been working without any issues. I'm using the 3.4M7 build but it looks like the [3.4 stable build](http://download.eclipse.org/eclipse/downloads/drops/R-3.4-200806172000/index.p...
I tend to follow the design of JDK libraries, especially Collections and Concurrency (Joshua Bloch, Doug Lea, those guys know how to design solid APIs). Anyway, many APIs in the JDK pro-actively throws NullPointerException. For example, the Javadoc for Map.containsKey states: > @throws NullPointerException if the ...
All HTTP's and MAILTO's (["'])(mailto:|http:).*?\1 All links, including relative ones, that are called by href or src. ((?<=href=")|(?<=src=")).*?(?=") The second one will only get you links that use double quotes, however.
All HTTP's and MAILTO's (["'])(mailto:|http:).*?\1 All links, including relative ones, that are called by href or src. #Matches things in double quotes, but not the quotes themselves ((?<=href=")|(?<=src=")).*?(?=") #Maches thing in either double or single quotes, including the quotes. ...
All HTTP's and MAILTO's (["'])(mailto:|http:).*?\1 All links, including relative ones, that are called by href or src. #Matches things in single or double quotes, but not the quotes themselves (?<=(["']))((?<=href=['"])|(?<=src=['"])).*?(?=\1) #Maches thing in either double or single qu...
I've written hooks in [Python](http://python.org) on Windows since there are a lot of examples on the net (usually for Linux but the differences are small). We also use [Trac](http://trac.edgewall.org) integrated with SVN and there is a Trac API accessible via Python which lets us automatically create/modify Trac tick...
You defined the primary key twice. Try: > CREATE TABLE SHIPPING_GRID( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'Unique ID for each row', shipping_vendor_no INT(6) NOT NULL COMMENT 'Foreign key to VENDOR.no for the shipping vendor (vendors_type must be 3)', start_vendor_no INT(6) NOT NU...
I prefer to make and test builds on my local machine/environment before committing or promoting any changes. For your specific example, I would have checked out a clean copy of the source before starting task ABC, and after implementing ABC, created a build locally with that in it.
Something like that: git stash && ./bootstrap.sh && make tests :)
You have to add the div to the dom. // Create the Div var oDiv = document.createElement('div'); document.body.appendChild(oDiv);
The div needs to be added to an element for it to be part of the document. document.appendChild(newDiv); alert( document.getElementById("obj_1000") );
newDiv.setAttribute( "ID", "obj_1000" ); should be newDiv.id = "obj_1000";
Determine file type in Ruby
|ruby|content-type|file-type|mime-types|
How does one reliably determine a file's type? There must be a rubyesque tool similar to the UNIX file(1) command? This is regarding MIME or content type, not file system classifications, such as directory, file, or socket.
|ruby|mime-types|content-type|file-type|
How does one **reliably** determine a file's type? File extension analysis is not acceptable. There must be a rubyesque tool similar to the UNIX file(1) command? This is regarding MIME or content type, not file system classifications, such as directory, file, or socket.
I'm fairly sure the primary monitor is the default. If the app was coded decently, when it's closed, it'll remember where it was last at and will reopen there, but -- as you've noticed -- it isn't a default behavior. -- Kevin Fairchild
I'm fairly sure the primary monitor is the default. If the app was coded decently, when it's closed, it'll remember where it was last at and will reopen there, but -- as you've noticed -- it isn't a default behavior.
I'm fairly sure the primary monitor is the default. If the app was coded decently, when it's closed, it'll remember where it was last at and will reopen there, but -- as you've noticed -- it isn't a default behavior. EDIT: The way I usually do it is to have the location stored in the app's settings. On load, if th...
Get UltraMon. Quickly. <http://realtimesoft.com/ultramon/> It doesn't let you specify what monitor an app starts on, but it lets you move an app to the another monitor, and keep its aspect ratio intact, with one mouse click. It is a very handy utility. Most programs will start where you last left them. So if...
Also remember the thread will most likely need its own database connection. I believe what is needed here is a multi-threaded "holding" object to load the data from the thread into (write only) which is then read only from the main VCL thread. Before reading use some sort of syncronization method to insure that your ...
Here's a one Liner: [*ProfileResource.search(params)].collect { |profile| profile.to_hash } The trick is the splat (*) that turns both individual elements and enumerables into arguments lists (in this case to the new array operator)
i dont think this information is saved between reboots. if shutting down properly you could run a command on shutdown that saves the uptime, that way you could read it back after booting back up.
If the collection is an Array you could use this technique profiles = [*ProfileResource.search(params)] output = profiles.collect do | profile | profile.to_hash end That would guaranteed your profiles is always an array.