qid
int64
4
8.14M
question
stringlengths
20
48.3k
answers
list
date
stringlengths
10
10
metadata
list
input
stringlengths
12
45k
output
stringlengths
2
31.8k
20,952
<p>I'm trying to unit test a custom ConfigurationSection I've written, and I'd like to load some arbitrary configuration XML into a <a href="http://msdn.microsoft.com/en-us/library/system.configuration.configuration.aspx" rel="noreferrer">System.Configuration.Configuration</a> for each test (rather than put the test co...
[ { "answer_id": 21005, "author": "TheSmurf", "author_id": 1975282, "author_profile": "https://Stackoverflow.com/users/1975282", "pm_score": 0, "selected": false, "text": "<p>Looking at the members of the class, I'd say the answer is probably no*. I'm not sure why you'd want to do this any...
2008/08/21
[ "https://Stackoverflow.com/questions/20952", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2338/" ]
I'm trying to unit test a custom ConfigurationSection I've written, and I'd like to load some arbitrary configuration XML into a [System.Configuration.Configuration](http://msdn.microsoft.com/en-us/library/system.configuration.configuration.aspx) for each test (rather than put the test configuration xml in the Tests.dl...
There is actually a way I've discovered.... You need to define a new class inheriting from your original configuration section as follows: ``` public class MyXmlCustomConfigSection : MyCustomConfigSection { public MyXmlCustomConfigSection (string configXml) { XmlTextReader reader = new XmlTextReader(n...
20,959
<p>How can I determine all of the assemblies that my .NET desktop application has loaded? I'd like to put them in the about box so I can query customers over the phone to determine what version of XYZ they have on their PC.</p> <p>It would be nice to see both managed and unmanaged assemblies. I realize the list will...
[ { "answer_id": 20970, "author": "Nick", "author_id": 1490, "author_profile": "https://Stackoverflow.com/users/1490", "pm_score": 0, "selected": false, "text": "<p>Looks like <code>AppDomain.CurrentDomain.GetAssemblies();</code> will do the trick :)</p>\n" }, { "answer_id": 20974,...
2008/08/21
[ "https://Stackoverflow.com/questions/20959", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1490/" ]
How can I determine all of the assemblies that my .NET desktop application has loaded? I'd like to put them in the about box so I can query customers over the phone to determine what version of XYZ they have on their PC. It would be nice to see both managed and unmanaged assemblies. I realize the list will get long bu...
``` using System; using System.Reflection; using System.Windows.Forms; public class MyAppDomain { public static void Main(string[] args) { AppDomain ad = AppDomain.CurrentDomain; Assembly[] loadedAssemblies = ad.GetAssemblies(); Console.WriteLine("Here are the assemblies loaded in this appdomain\n"); ...
20,998
<p>When I try to create a SQL Server Login by saying</p> <pre><code>CREATE LOGIN [ourdomain\SQLAccessGroup] FROM WINDOWS; </code></pre> <p>I get this error</p> <blockquote> <p>The server principal 'ourdomain\SQLAccessGroup' already exists.</p> </blockquote> <p>However, when I try this code</p> <pre><code>DROP LO...
[ { "answer_id": 21074, "author": "Pete", "author_id": 76, "author_profile": "https://Stackoverflow.com/users/76", "pm_score": 4, "selected": true, "text": "<p>We are still struggling to understand the <em>HOW</em> of this issue, but it seems that [ourdomain\\SQLAccessGroup] was aliased by...
2008/08/21
[ "https://Stackoverflow.com/questions/20998", "https://Stackoverflow.com", "https://Stackoverflow.com/users/76/" ]
When I try to create a SQL Server Login by saying ``` CREATE LOGIN [ourdomain\SQLAccessGroup] FROM WINDOWS; ``` I get this error > > The server principal 'ourdomain\SQLAccessGroup' already exists. > > > However, when I try this code ``` DROP LOGIN [ourdomain\SQLAccessGroup] ``` I get this error > > Cannot...
We are still struggling to understand the *HOW* of this issue, but it seems that [ourdomain\SQLAccessGroup] was aliased by a consultant to a different user name (this is part of an MS CRM installation). We finally were able to use some logic and some good old SID comparisons to determine who was playing the imposter ga...
21,052
<p>When I'm working with DataBound controls in ASP.NET 2.0 such as a Repeater, I know the fastest way to retrieve a property of a bound object (instead of using Reflection with the Eval() function) is to cast the DataItem object to the type it is and then use that object natively, like the following:</p> <pre><code>&l...
[ { "answer_id": 21056, "author": "Shawn", "author_id": 26, "author_profile": "https://Stackoverflow.com/users/26", "pm_score": 7, "selected": true, "text": "<p>I believe you can add something like:</p>\n\n<pre><code>&lt;%@ Import Namespace=\"RootNamespace.SubNamespace1\" %&gt; \n</code></...
2008/08/21
[ "https://Stackoverflow.com/questions/21052", "https://Stackoverflow.com", "https://Stackoverflow.com/users/392/" ]
When I'm working with DataBound controls in ASP.NET 2.0 such as a Repeater, I know the fastest way to retrieve a property of a bound object (instead of using Reflection with the Eval() function) is to cast the DataItem object to the type it is and then use that object natively, like the following: ``` <%#((MyType)Cont...
I believe you can add something like: ``` <%@ Import Namespace="RootNamespace.SubNamespace1" %> ``` At the top of the page.
21,060
<p>I'm tired of being in the middle of typing something, having a pop-up with a question appear, and hitting enter before reading it... (it also happens with some windows that are not pop-ups)</p> <p>Do you know if there's some setting I could touch for this not to happen?</p>
[ { "answer_id": 21056, "author": "Shawn", "author_id": 26, "author_profile": "https://Stackoverflow.com/users/26", "pm_score": 7, "selected": true, "text": "<p>I believe you can add something like:</p>\n\n<pre><code>&lt;%@ Import Namespace=\"RootNamespace.SubNamespace1\" %&gt; \n</code></...
2008/08/21
[ "https://Stackoverflow.com/questions/21060", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1782/" ]
I'm tired of being in the middle of typing something, having a pop-up with a question appear, and hitting enter before reading it... (it also happens with some windows that are not pop-ups) Do you know if there's some setting I could touch for this not to happen?
I believe you can add something like: ``` <%@ Import Namespace="RootNamespace.SubNamespace1" %> ``` At the top of the page.
21,078
<p>What's the most efficient way to concatenate strings?</p>
[ { "answer_id": 21084, "author": "TheSmurf", "author_id": 1975282, "author_profile": "https://Stackoverflow.com/users/1975282", "pm_score": 2, "selected": false, "text": "<p>The most efficient is to use StringBuilder, like so:</p>\n\n<pre><code>StringBuilder sb = new StringBuilder();\nsb....
2008/08/21
[ "https://Stackoverflow.com/questions/21078", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2358/" ]
What's the most efficient way to concatenate strings?
The `StringBuilder.Append()` method is much better than using the `+` operator. But I've found that, when executing 1000 concatenations or less, `String.Join()` is even more efficient than `StringBuilder`. ``` StringBuilder sb = new StringBuilder(); sb.Append(someString); ``` The only problem with `String.Join` is t...
21,133
<p>What's the easiest way to profile a PHP script?</p> <p>I'd love tacking something on that shows me a dump of all function calls and how long they took but I'm also OK with putting something around specific functions.</p> <p>I tried experimenting with the <a href="http://php.net/microtime" rel="noreferrer">microtim...
[ { "answer_id": 21139, "author": "Eric Lamb", "author_id": 538, "author_profile": "https://Stackoverflow.com/users/538", "pm_score": 3, "selected": false, "text": "<p>I like to use phpDebug for profiling.\n<a href=\"http://phpdebug.sourceforge.net/www/index.html\" rel=\"noreferrer\">http:...
2008/08/21
[ "https://Stackoverflow.com/questions/21133", "https://Stackoverflow.com", "https://Stackoverflow.com/users/305/" ]
What's the easiest way to profile a PHP script? I'd love tacking something on that shows me a dump of all function calls and how long they took but I'm also OK with putting something around specific functions. I tried experimenting with the [microtime](http://php.net/microtime) function: ``` $then = microtime(); myF...
The [PECL APD](http://www.php.net/apd) extension is used as follows: ``` <?php apd_set_pprof_trace(); //rest of the script ?> ``` After, parse the generated file using `pprofp`. Example output: ``` Trace for /home/dan/testapd.php Total Elapsed Time = 0.00 Total System Time = 0.00 Total User Time = 0.00 Real ...
21,184
<p>I've got a System.Generic.Collections.List(Of MyCustomClass) type object.</p> <p>Given integer varaibles pagesize and pagenumber, how can I query only any single page of MyCustomClass objects?</p>
[ { "answer_id": 21389, "author": "Espo", "author_id": 2257, "author_profile": "https://Stackoverflow.com/users/2257", "pm_score": 6, "selected": true, "text": "<p>If you have your linq-query that contains all the rows you want to display, this code can be used:</p>\n\n<pre><code>var pageN...
2008/08/21
[ "https://Stackoverflow.com/questions/21184", "https://Stackoverflow.com", "https://Stackoverflow.com/users/83/" ]
I've got a System.Generic.Collections.List(Of MyCustomClass) type object. Given integer varaibles pagesize and pagenumber, how can I query only any single page of MyCustomClass objects?
If you have your linq-query that contains all the rows you want to display, this code can be used: ``` var pageNum = 3; var pageSize = 20; query = query.Skip((pageNum - 1) * pageSize).Take(pageSize); ``` You can also make an extension method on the object to be able to write ``` query.Page(2,50) ``` to get the fi...
21,207
<p>I'm currently trying out db4o (the java version) and I pretty much like what I see. But I cannot help wondering how it does perform in a real live (web-)environment. Does anyone have any experiences (good or bad) to share about running db4o? </p>
[ { "answer_id": 24499, "author": "Judah Gabriel Himango", "author_id": 536, "author_profile": "https://Stackoverflow.com/users/536", "pm_score": 7, "selected": true, "text": "<p>We run DB40 .NET version in a large client/server project.</p>\n\n<p>Our experiences is that you can potentiall...
2008/08/21
[ "https://Stackoverflow.com/questions/21207", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1562/" ]
I'm currently trying out db4o (the java version) and I pretty much like what I see. But I cannot help wondering how it does perform in a real live (web-)environment. Does anyone have any experiences (good or bad) to share about running db4o?
We run DB40 .NET version in a large client/server project. Our experiences is that you can potentially get much better performance than typical relational databases. However, you really have to tweak your objects to get this kind of performance. For example, if you've got a list containing a lot of objects, DB4O acti...
21,232
<p>I've got a System.Generic.Collections.List(Of MyCustomClass) type object.</p> <p>Given integer varaibles pagesize and pagenumber, how can I collect only any single page of <code>MyCustomClass</code> objects?</p> <p>This is what I've got. How can I improve it?</p> <pre><code>'my given collection and paging parame...
[ { "answer_id": 21267, "author": "FlySwat", "author_id": 1965, "author_profile": "https://Stackoverflow.com/users/1965", "pm_score": 1, "selected": false, "text": "<p>You use GetRange on your IEnuramble implementing collection:</p>\n\n<pre><code>List&lt;int&gt; lolInts = new List&lt;int&g...
2008/08/21
[ "https://Stackoverflow.com/questions/21232", "https://Stackoverflow.com", "https://Stackoverflow.com/users/83/" ]
I've got a System.Generic.Collections.List(Of MyCustomClass) type object. Given integer varaibles pagesize and pagenumber, how can I collect only any single page of `MyCustomClass` objects? This is what I've got. How can I improve it? ``` 'my given collection and paging parameters Dim AllOfMyCustomClassObjects As Sy...
Generic.List should provide the Skip() and Take() methods, so you could do this: ``` Dim PageObjects As New System.Collections.Generic.List(Of MyCustomClass) PageObjects = AllOfMyCustomClassObjects.Skip(pagenumber * pagesize).Take(pagesize) ``` --- If by "without Linq" you meant on the 2.0 Framework, I don't believ...
21,265
<p>What is the best method for comparing IEEE floats and doubles for equality? I have heard of several methods, but I wanted to see what the community thought.</p>
[ { "answer_id": 21277, "author": "DrPizza", "author_id": 2131, "author_profile": "https://Stackoverflow.com/users/2131", "pm_score": 4, "selected": true, "text": "<p>The best approach I think is to compare <a href=\"http://en.wikipedia.org/wiki/Unit_in_the_last_place\" rel=\"noreferrer\">...
2008/08/21
[ "https://Stackoverflow.com/questions/21265", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2328/" ]
What is the best method for comparing IEEE floats and doubles for equality? I have heard of several methods, but I wanted to see what the community thought.
The best approach I think is to compare [ULPs](http://en.wikipedia.org/wiki/Unit_in_the_last_place). ``` bool is_nan(float f) { return (*reinterpret_cast<unsigned __int32*>(&f) & 0x7f800000) == 0x7f800000 && (*reinterpret_cast<unsigned __int32*>(&f) & 0x007fffff) != 0; } bool is_finite(float f) { return (*rei...
21,280
<p>I seem to be missing something about LINQ. To me, it looks like it's taking some of the elements of SQL that I like the least and moving them into the C# language and using them for other things.</p> <p>I mean, I could see the benefit of using SQL-like statements on things other than databases. But if I wanted to...
[ { "answer_id": 21287, "author": "TheSmurf", "author_id": 1975282, "author_profile": "https://Stackoverflow.com/users/1975282", "pm_score": 2, "selected": false, "text": "<p>The point is that LINQ integrates your queries into your primary programming language, allowing your IDE to provide...
2008/08/21
[ "https://Stackoverflow.com/questions/21280", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2147/" ]
I seem to be missing something about LINQ. To me, it looks like it's taking some of the elements of SQL that I like the least and moving them into the C# language and using them for other things. I mean, I could see the benefit of using SQL-like statements on things other than databases. But if I wanted to write SQL, ...
LINQ is not about SQL. LINQ is about being apply functional programming paradigmns on objects. LINQ to SQL is an ORM built ontop of the LINQ foundation, but LINQ is much more. I don't use LINQ to SQL, yet I use LINQ all the time. Take the task of finding the intersection of two lists: Before LINQ, this tasks require...
21,294
<p>How can you reliably and dynamically load a JavaScript file? This will can be used to implement a module or component that when 'initialized' the component will dynamically load all needed JavaScript library scripts on demand.</p> <p>The client that uses the component isn't required to load all the library script ...
[ { "answer_id": 21297, "author": "Adam", "author_id": 1341, "author_profile": "https://Stackoverflow.com/users/1341", "pm_score": 3, "selected": false, "text": "<p>Here is some example code I've found... does anyone have a better way?</p>\n\n<pre><code> function include(url)\n {\n va...
2008/08/21
[ "https://Stackoverflow.com/questions/21294", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1341/" ]
How can you reliably and dynamically load a JavaScript file? This will can be used to implement a module or component that when 'initialized' the component will dynamically load all needed JavaScript library scripts on demand. The client that uses the component isn't required to load all the library script files (and ...
You may create a script element dynamically, using [Prototypes](http://www.prototypejs.org/): ``` new Element("script", {src: "myBigCodeLibrary.js", type: "text/javascript"}); ``` The problem here is that we do not know *when* the external script file is fully loaded. We often want our dependant code on the very ne...
21,303
<p>VC++ makes functions which are implemented within the class declaration inline functions.</p> <p>If I declare a class <code>Foo</code> as follows, then are the CONSTRUCTOR and DESTRUCTOR inline functions?</p> <pre><code>class Foo { int* p; public: Foo() { p = new char[0x00100000]; } ~Foo() { delete []...
[ { "answer_id": 21322, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 7, "selected": true, "text": "<p>Defining the body of the constructor INSIDE the class has the same effect as placing the function OUTSIDE the class with the ...
2008/08/21
[ "https://Stackoverflow.com/questions/21303", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1556/" ]
VC++ makes functions which are implemented within the class declaration inline functions. If I declare a class `Foo` as follows, then are the CONSTRUCTOR and DESTRUCTOR inline functions? ``` class Foo { int* p; public: Foo() { p = new char[0x00100000]; } ~Foo() { delete [] p; } }; { Foo f; (f); ...
Defining the body of the constructor INSIDE the class has the same effect as placing the function OUTSIDE the class with the "inline" keyword. In both cases it's a hint to the compiler. An "inline" function doesn't necessarily mean the function will be inlined. That depends on the complexity of the function and other ...
21,448
<p>I have an SSIS package that exports data to a couple of Excel files for transfer to a third party. To get this to run as a scheduled job on a 64-bit server I understand that I need to set the step as a CmdExec type and call the 32-bit version of DTExec. But I don't seem to be able to get the command right to pass in...
[ { "answer_id": 22093, "author": "Marek Grzenkowicz", "author_id": 95, "author_profile": "https://Stackoverflow.com/users/95", "pm_score": 2, "selected": false, "text": "<p>Unless it's a business requirement, I suggest you move the connection string from the command line to the package an...
2008/08/21
[ "https://Stackoverflow.com/questions/21448", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2375/" ]
I have an SSIS package that exports data to a couple of Excel files for transfer to a third party. To get this to run as a scheduled job on a 64-bit server I understand that I need to set the step as a CmdExec type and call the 32-bit version of DTExec. But I don't seem to be able to get the command right to pass in th...
This step-by-step example is for others who might stumble upon this question. This example uses *SSIS 2005* and uses *SQL Server 2005 64-bit edition server* to run the job. The answer here concentrates only on fixing the error message mentioned in the question. The example will demonstrate the steps to recreate the is...
21,449
<p>What is the difference between the following types of endianness?</p> <ul> <li>byte (8b) invariant big and little endianness</li> <li>half-word (16b) invariant big and little endianness</li> <li>word (32b) invariant big and little endianness</li> <li>double-word (64b) invariant big and little endianness</li> </ul> ...
[ { "answer_id": 21455, "author": "James A. Rosen", "author_id": 1190, "author_profile": "https://Stackoverflow.com/users/1190", "pm_score": -1, "selected": false, "text": "<p>the basic concept is the ordering of bits:</p>\n\n<pre><code>1010 0011\n</code></pre>\n\n<p>in little-endian is th...
2008/08/21
[ "https://Stackoverflow.com/questions/21449", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2045/" ]
What is the difference between the following types of endianness? * byte (8b) invariant big and little endianness * half-word (16b) invariant big and little endianness * word (32b) invariant big and little endianness * double-word (64b) invariant big and little endianness Are there other types/variations?
There are two approaches to endian mapping: *address invariance* and *data invariance*. Address Invariance ------------------ In this type of mapping, the address of bytes is always preserved between big and little. This has the side effect of reversing the order of significance (most significant to least significant...
21,454
<p>How do I go about specifying and using an ENUM in a Django model?</p>
[ { "answer_id": 21468, "author": "fulmicoton", "author_id": 446497, "author_profile": "https://Stackoverflow.com/users/446497", "pm_score": 7, "selected": false, "text": "<p>From the <a href=\"https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.Field.choices\" rel=\"...
2008/08/21
[ "https://Stackoverflow.com/questions/21454", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2019/" ]
How do I go about specifying and using an ENUM in a Django model?
From the [Django documentation](https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.Field.choices): ``` MAYBECHOICE = ( ('y', 'Yes'), ('n', 'No'), ('u', 'Unknown'), ) ``` And you define a charfield in your model : ``` married = models.CharField(max_length=1, choices=MAYBECHOICE) `...
21,461
<pre><code>#if SYMBOL //code #endif </code></pre> <p>what values does C# predefine for use?</p>
[ { "answer_id": 21467, "author": "Nick", "author_id": 1490, "author_profile": "https://Stackoverflow.com/users/1490", "pm_score": 2, "selected": false, "text": "<p>Depends on what /define compiler options you use. <code>Visual Studio</code> puts the <code>DEBUG</code> symbol in there for...
2008/08/21
[ "https://Stackoverflow.com/questions/21461", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1343/" ]
``` #if SYMBOL //code #endif ``` what values does C# predefine for use?
To add to what Nick said, the MSDN documentation does not list any pre-defined names. It would seem that all need to come from `#define` and `/define`. [#if on MSDN](http://msdn.microsoft.com/en-us/library/4y6tbswk.aspx)
21,489
<p>SQL Experts,</p> <p>Is there an efficient way to group runs of data together using SQL?<br> Or is it going to be more efficient to process the data in code. </p> <p>For example if I have the following data:</p> <pre><code>ID|Name 01|Harry Johns 02|Adam Taylor 03|John Smith 04|John Smith 05|Bill Manning 06|John S...
[ { "answer_id": 21492, "author": "Matt Hamilton", "author_id": 615, "author_profile": "https://Stackoverflow.com/users/615", "pm_score": 0, "selected": false, "text": "<p>For this particular case, all you need to do is group by the name and ask for the count, like this:</p>\n\n<pre><code>...
2008/08/22
[ "https://Stackoverflow.com/questions/21489", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2281/" ]
SQL Experts, Is there an efficient way to group runs of data together using SQL? Or is it going to be more efficient to process the data in code. For example if I have the following data: ``` ID|Name 01|Harry Johns 02|Adam Taylor 03|John Smith 04|John Smith 05|Bill Manning 06|John Smith ``` I need to display t...
Try this: ``` select n.name, (select count(*) from myTable n1 where n1.name = n.name and n1.id >= n.id and (n1.id <= ( select isnull(min(nn.id), (select max(id) + 1 from myTable)) from myTable nn where nn.id > n.id and nn.name <> n.name ) )) from myTable n w...
21,547
<p>I've spent a good amount of time coming up with solution to this problem, so in the spirit of <a href="https://stackoverflow.com/questions/21245/questions-vs-conveying-information">this post</a>, I'm posting it here, since I think it might be useful to others. </p> <p>If anyone has a better script, or anything to a...
[ { "answer_id": 21551, "author": "Blorgbeard", "author_id": 369, "author_profile": "https://Stackoverflow.com/users/369", "pm_score": 5, "selected": false, "text": "<p>Here's the script that I came up with. It handles Identity columns, default values, and primary keys. It does not handle ...
2008/08/22
[ "https://Stackoverflow.com/questions/21547", "https://Stackoverflow.com", "https://Stackoverflow.com/users/369/" ]
I've spent a good amount of time coming up with solution to this problem, so in the spirit of [this post](https://stackoverflow.com/questions/21245/questions-vs-conveying-information), I'm posting it here, since I think it might be useful to others. If anyone has a better script, or anything to add, please post it. ...
I've modified the version above to run for all tables and support new SQL 2005 data types. It also retains the primary key names. Works only on SQL 2005 (using cross apply). ``` select 'create table [' + so.name + '] (' + o.list + ')' + CASE WHEN tc.Constraint_Name IS NULL THEN '' ELSE 'ALTER TABLE ' + so.Name + ' A...
21,558
<p>I want to know what a "<em>virtual base class</em>" is and what it means.</p> <p>Let me show an example:</p> <pre><code>class Foo { public: void DoSomething() { /* ... */ } }; class Bar : public virtual Foo { public: void DoSpecific() { /* ... */ } }; </code></pre>
[ { "answer_id": 21598, "author": "wilhelmtell", "author_id": 456, "author_profile": "https://Stackoverflow.com/users/456", "pm_score": 1, "selected": false, "text": "<p>It means a call to a virtual function will be forwarded to the \"right\" class.</p>\n\n<p>C++ <a href=\"https://isocpp.o...
2008/08/22
[ "https://Stackoverflow.com/questions/21558", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1556/" ]
I want to know what a "*virtual base class*" is and what it means. Let me show an example: ``` class Foo { public: void DoSomething() { /* ... */ } }; class Bar : public virtual Foo { public: void DoSpecific() { /* ... */ } }; ```
Virtual base classes, used in virtual inheritance, is a way of preventing multiple "instances" of a given class appearing in an inheritance hierarchy when using multiple inheritance. Consider the following scenario: ``` class A { public: void Foo() {} }; class B : public A {}; class C : public A {}; class D : public ...
21,564
<p>I ended up writing a quick little script for this in Python, but I was wondering if there was a utility you could feed text into which would prepend each line with some text -- in my specific case, a timestamp. Ideally, the use would be something like:</p> <pre><code>cat somefile.txt | prepend-timestamp </code></p...
[ { "answer_id": 21602, "author": "jj33", "author_id": 430, "author_profile": "https://Stackoverflow.com/users/430", "pm_score": 5, "selected": false, "text": "<p>How about this?</p>\n\n<pre><code>cat somefile.txt | perl -pne 'print scalar(localtime()), \" \";'\n</code></pre>\n\n<p>Judging...
2008/08/22
[ "https://Stackoverflow.com/questions/21564", "https://Stackoverflow.com", "https://Stackoverflow.com/users/156/" ]
I ended up writing a quick little script for this in Python, but I was wondering if there was a utility you could feed text into which would prepend each line with some text -- in my specific case, a timestamp. Ideally, the use would be something like: ``` cat somefile.txt | prepend-timestamp ``` (Before you answer ...
Could try using `awk`: ``` <command> | awk '{ print strftime("%Y-%m-%d %H:%M:%S"), $0; fflush(); }' ``` You may need to make sure that `<command>` produces line buffered output, i.e. it flushes its output stream after each line; the timestamp `awk` adds will be the time that the end of the line appeared on its input...
21,574
<p>I'm not clear on the differences between the "current" version of Ruby (1.8) and the "new" version (1.9). Is there an "easy" or a "simple" explanation of the differences and why it is so different?</p>
[ { "answer_id": 21621, "author": "Tim Sullivan", "author_id": 722, "author_profile": "https://Stackoverflow.com/users/722", "pm_score": 8, "selected": true, "text": "<p>Sam Ruby has a <a href=\"http://slideshow.rubyforge.org/ruby19.html\" rel=\"noreferrer\">cool slideshow that outline the...
2008/08/22
[ "https://Stackoverflow.com/questions/21574", "https://Stackoverflow.com", "https://Stackoverflow.com/users/757/" ]
I'm not clear on the differences between the "current" version of Ruby (1.8) and the "new" version (1.9). Is there an "easy" or a "simple" explanation of the differences and why it is so different?
Sam Ruby has a [cool slideshow that outline the differences](http://slideshow.rubyforge.org/ruby19.html). In the interest of bringing this information inline for easier reference, and in case the link goes dead in the abstract future, here's an overview of Sam's slides. The slideshow is less overwhelming to review, bu...
21,589
<p>I did some tests a while ago and never figured out how to make this work. </p> <p><strong>The ingredients:</strong></p> <ul> <li>COM+ transactional object (developed in VB6) </li> <li>.Net web application (with transaction) in IIS that...<br> makes a call to the COM+ component<br> updates a row in a SQL database...
[ { "answer_id": 21599, "author": "Eric Z Beard", "author_id": 1219, "author_profile": "https://Stackoverflow.com/users/1219", "pm_score": 1, "selected": false, "text": "<p>How are you implementing this? If you are using EnterpriseServices to manage the .NET transaction, then both transac...
2008/08/22
[ "https://Stackoverflow.com/questions/21589", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1328/" ]
I did some tests a while ago and never figured out how to make this work. **The ingredients:** * COM+ transactional object (developed in VB6) * .Net web application (with transaction) in IIS that... makes a call to the COM+ component updates a row in a SQL database **Testing:** Run the .Net application and ...
Because VB and .NET will use different SQL connections (and there is no way to make ADO and ADO.NET share the same connection), your only possibility is to enlist the DTC (Distributed Transaction Coordinator). The DTC will coordinates the two independent transactions so they commit or are rolled-back together. **From ...
21,640
<p>Is there a simple way in .NET to quickly get the current protocol, host, and port? For example, if I'm on the following URL:</p> <p><code>http://www.mywebsite.com:80/pages/page1.aspx</code></p> <p>I need to return:</p> <p><code>http://www.mywebsite.com:80</code></p> <p>I know I can use <code>Request.Url.Absolute...
[ { "answer_id": 21653, "author": "Dale Ragan", "author_id": 1117, "author_profile": "https://Stackoverflow.com/users/1117", "pm_score": 5, "selected": false, "text": "<p>Request.Url will return you the <a href=\"http://msdn.microsoft.com/en-us/library/system.uri.aspx\" rel=\"noreferrer\">...
2008/08/22
[ "https://Stackoverflow.com/questions/21640", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2076253/" ]
Is there a simple way in .NET to quickly get the current protocol, host, and port? For example, if I'm on the following URL: `http://www.mywebsite.com:80/pages/page1.aspx` I need to return: `http://www.mywebsite.com:80` I know I can use `Request.Url.AbsoluteUri` to get the complete URL, and I know I can use `Reques...
The following (C#) code should do the trick ``` Uri uri = new Uri("http://www.mywebsite.com:80/pages/page1.aspx"); string requested = uri.Scheme + Uri.SchemeDelimiter + uri.Host + ":" + uri.Port; ```
21,647
<p>The following <strong>C++</strong> code uses a <strong>ifstream</strong> object to read integers from a text file (which has one number per line) until it hits <strong>EOF</strong>. Why does it read the integer on the last line twice? How to fix this?</p> <p><strong>Code:</strong></p> <pre><code>#include &lt;iostr...
[ { "answer_id": 21656, "author": "wilhelmtell", "author_id": 456, "author_profile": "https://Stackoverflow.com/users/456", "pm_score": 8, "selected": true, "text": "<p>Just follow closely the chain of events.</p>\n\n<ul>\n<li>Grab 10</li>\n<li>Grab 20</li>\n<li>Grab 30</li>\n<li>Grab EOF<...
2008/08/22
[ "https://Stackoverflow.com/questions/21647", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1630/" ]
The following **C++** code uses a **ifstream** object to read integers from a text file (which has one number per line) until it hits **EOF**. Why does it read the integer on the last line twice? How to fix this? **Code:** ``` #include <iostream> #include <fstream> using namespace std; int main() { ifstream iFil...
Just follow closely the chain of events. * Grab 10 * Grab 20 * Grab 30 * Grab EOF Look at the second-to-last iteration. You grabbed 30, then carried on to check for EOF. You haven't reached EOF because the EOF mark hasn't been read yet ("binarically" speaking, its conceptual location is just after the 30 line). There...
21,651
<p>I have a script that retrieves objects from a remote server through an Ajax call. The server returns objects in JSON notation.­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­...
[ { "answer_id": 21716, "author": "jsight", "author_id": 1432, "author_profile": "https://Stackoverflow.com/users/1432", "pm_score": 2, "selected": false, "text": "<p>Have you looked at <a href=\"http://code.google.com/p/as3corelib/\" rel=\"nofollow noreferrer\">as3corelib</a>? It appears...
2008/08/22
[ "https://Stackoverflow.com/questions/21651", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2504504/" ]
I have a script that retrieves objects from a remote server through an Ajax call. The server returns objects in JSON notation.­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­...
You can find a [JSON parser written in JavaScript here](http://www.JSON.org/js.html) ([source code here](https://github.com/douglascrockford/JSON-js/blob/master/json2.js)). You can also use the as3corelib JSON parser from JavaScript, there's [a description of how to access ActionScript libraries from JavaScript here](h...
21,652
<p>I have some code that gives a user id to a utility that then send email to that user.</p> <pre><code>emailUtil.sendEmail(userId, "foo"); public void sendEmail(String userId, String message) throws MailException { /* ... logic that could throw a MailException */ } </code></pre> <p><code>MailException</code> co...
[ { "answer_id": 21667, "author": "stimms", "author_id": 361, "author_profile": "https://Stackoverflow.com/users/361", "pm_score": 1, "selected": false, "text": "<p>It depends on what your application is doing. You might want to throw individual exceptions in cases like </p>\n\n<ul>\n<li>...
2008/08/22
[ "https://Stackoverflow.com/questions/21652", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1666/" ]
I have some code that gives a user id to a utility that then send email to that user. ``` emailUtil.sendEmail(userId, "foo"); public void sendEmail(String userId, String message) throws MailException { /* ... logic that could throw a MailException */ } ``` `MailException` could be thrown for a number of reasons...
I usually start with a general exception and subclass it as needed. I always can catch the general exception (and with it all subclassed exceptions) if needed, but also the specific. An example from the Java-API is IOException, that has subclasses like FileNotFoundException or EOFException (and much more). This way y...
21,697
<p>I'm currently writing an ASP.Net app from the UI down. I'm implementing an MVP architecture because I'm sick of Winforms and wanted something that had a better separation of concerns.</p> <p>So with MVP, the Presenter handles events raised by the View. Here's some code that I have in place to deal with the creation...
[ { "answer_id": 22043, "author": "Cheekysoft", "author_id": 1820, "author_profile": "https://Stackoverflow.com/users/1820", "pm_score": 5, "selected": true, "text": "<p>That sounds just right to me. Exceptions are preferable as they can be thrown up to the top of the service layer from an...
2008/08/22
[ "https://Stackoverflow.com/questions/21697", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1894/" ]
I'm currently writing an ASP.Net app from the UI down. I'm implementing an MVP architecture because I'm sick of Winforms and wanted something that had a better separation of concerns. So with MVP, the Presenter handles events raised by the View. Here's some code that I have in place to deal with the creation of users:...
That sounds just right to me. Exceptions are preferable as they can be thrown up to the top of the service layer from anywhere inside the service layer, no matter how deeply nested inside the service method implementation it is. This keeps the service code clean as you know the calling presenter will always get notific...
21,715
<p>Prior to C# generics, everyone would code collections for their business objects by creating a collection base that implemented IEnumerable</p> <p>IE:</p> <pre><code>public class CollectionBase : IEnumerable </code></pre> <p>and then would derive their Business Object collections from that.</p> <pre><code>public...
[ { "answer_id": 21720, "author": "Matt Hamilton", "author_id": 615, "author_profile": "https://Stackoverflow.com/users/615", "pm_score": 2, "selected": false, "text": "<p>I generally only derive my own collection classes if I need to \"add value\". Like, if the collection itself needed to...
2008/08/22
[ "https://Stackoverflow.com/questions/21715", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1965/" ]
Prior to C# generics, everyone would code collections for their business objects by creating a collection base that implemented IEnumerable IE: ``` public class CollectionBase : IEnumerable ``` and then would derive their Business Object collections from that. ``` public class BusinessObjectCollection : Collection...
I am generally in the camp of just using a List directly, unless for some reason I need to encapsulate the data structure and provide a limited subset of its functionality. This is mainly because if I don't have a specific need for encapsulation then doing it is just a waste of time. However, with the aggregate initia...
21,749
<p>I have a Delphi 7 application that has two views of a document (e.g. a WYSIWYG HTML edit might have a WYSIWYG view and a source view - not my real application). They can be opened in separate windows, or docked into tabs in the main window.</p> <p>If I open a modal dialog from one of the separate forms, the main fo...
[ { "answer_id": 21809, "author": "Ryan Farley", "author_id": 1627, "author_profile": "https://Stackoverflow.com/users/1627", "pm_score": 0, "selected": false, "text": "<p>First of all, I am not completely sure I follow, you might need to provide some additional details to help us understa...
2008/08/22
[ "https://Stackoverflow.com/questions/21749", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2219/" ]
I have a Delphi 7 application that has two views of a document (e.g. a WYSIWYG HTML edit might have a WYSIWYG view and a source view - not my real application). They can be opened in separate windows, or docked into tabs in the main window. If I open a modal dialog from one of the separate forms, the main form is brou...
I'd use this code... (Basically what Lars said) ``` dialog := TDialogForm.Create( parentForm ); dialog.PopupParent := parentForm; dialog.PopupMode := pmExplicit; dialog.ShowModal(); ```
21,817
<p>The topic says the most of it - what is the reason for the fact that static methods can't be declared in an interface?</p> <pre><code>public interface ITest { public static String test(); } </code></pre> <p>The code above gives me the following error (in Eclipse, at least): "Illegal modifier for the interface ...
[ { "answer_id": 21819, "author": "Ryan Farley", "author_id": 1627, "author_profile": "https://Stackoverflow.com/users/1627", "pm_score": 3, "selected": false, "text": "<p>Static methods are not instance methods. There's no instance context, therefore to implement it from the interface mak...
2008/08/22
[ "https://Stackoverflow.com/questions/21817", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2238/" ]
The topic says the most of it - what is the reason for the fact that static methods can't be declared in an interface? ``` public interface ITest { public static String test(); } ``` The code above gives me the following error (in Eclipse, at least): "Illegal modifier for the interface method ITest.test(); only ...
There are a few issues at play here. The first is the issue of declaring a static method without defining it. This is the difference between ``` public interface Foo { public static int bar(); } ``` and ``` public interface Foo { public static int bar() { ... } } ``` The first is impossible for the reas...
21,848
<p>There may be more than one way to ask this question, so here's a desciption of the problem. I was working on master and committed some stuff and then decided I wanted to put that work on hold. I backed up a few commits and then branched from before I started my crap work. Practically this works fine, I just now have...
[ { "answer_id": 21897, "author": "olliej", "author_id": 784, "author_profile": "https://Stackoverflow.com/users/784", "pm_score": 3, "selected": false, "text": "<p>This is relatively easy:</p>\n\n<pre><code>git checkout -b fake_master master # fake_master now points to the same commit as ...
2008/08/22
[ "https://Stackoverflow.com/questions/21848", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2427/" ]
There may be more than one way to ask this question, so here's a desciption of the problem. I was working on master and committed some stuff and then decided I wanted to put that work on hold. I backed up a few commits and then branched from before I started my crap work. Practically this works fine, I just now have a ...
In addition to the other comments, you may find the -m (move) switch to git-branch helpful. You could rename your old master to something else, then rename your new branch to master: ``` git branch -m master crap_work git branch -m previous_master master ```
21,877
<p>What I want to achieve is this. I want to give the user the ability to upload an image file, store the image in BLOB in SQL Server, and then use this image as a logo in other pages of the site. </p> <p>I have done this by using </p> <pre><code> Response.Clear(); Response.ContentType = "image/pjpeg"; Respo...
[ { "answer_id": 21883, "author": "Brad Wilson", "author_id": 1554, "author_profile": "https://Stackoverflow.com/users/1554", "pm_score": 0, "selected": false, "text": "<p>We actually just released some classes that help with exactly this kind of thing:</p>\n\n<p><a href=\"http://www.codep...
2008/08/22
[ "https://Stackoverflow.com/questions/21877", "https://Stackoverflow.com", "https://Stackoverflow.com/users/932/" ]
What I want to achieve is this. I want to give the user the ability to upload an image file, store the image in BLOB in SQL Server, and then use this image as a logo in other pages of the site. I have done this by using ``` Response.Clear(); Response.ContentType = "image/pjpeg"; Response.BinaryWrite(imageC...
Add a 'Generic Handler' to your web project, name it something like Image.ashx. Implement it like this: ``` public class ImageHandler : IHttpHandler { public void ProcessRequest(HttpContext context) { using(Image image = GetImage(context.Request.QueryString["ID"])) { context.Re...
21,879
<p>I'm trying to reteach myself some long forgotten math skills. This is part of a much larger project to effectively "teach myself software development" from the ground up (the details are <a href="http://www.appscanadian.ca/archives/cs-101-introduction-to-computer-science/" rel="noreferrer">here</a> if you're interes...
[ { "answer_id": 21962, "author": "Mark Harrison", "author_id": 116, "author_profile": "https://Stackoverflow.com/users/116", "pm_score": 4, "selected": true, "text": "<p>Here's how my school did it:</p>\n\n<pre><code>base:\n algebra\n trigonometry\n analytic geometry\n\ntrack 1 ...
2008/08/22
[ "https://Stackoverflow.com/questions/21879", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1588/" ]
I'm trying to reteach myself some long forgotten math skills. This is part of a much larger project to effectively "teach myself software development" from the ground up (the details are [here](http://www.appscanadian.ca/archives/cs-101-introduction-to-computer-science/) if you're interested in helping out). My bigge...
Here's how my school did it: ``` base: algebra trigonometry analytic geometry track 1 track 2 track 3 calc 1 linear algebra statistics calc 2 discrete math 1 calc 3 (multivariable) discrete math 2 ...
21,938
<p>Whilst analysing some legacy code with FXCop, it occurred to me is it really that bad to catch a general exception error within a try block or should you be looking for a specific exception. Thoughts on a postcard please.</p>
[ { "answer_id": 21942, "author": "Philippe", "author_id": 920, "author_profile": "https://Stackoverflow.com/users/920", "pm_score": 3, "selected": false, "text": "<p>Well, I don't see any difference between catching a general exception or a specific one, except that when having multiple c...
2008/08/22
[ "https://Stackoverflow.com/questions/21938", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1731/" ]
Whilst analysing some legacy code with FXCop, it occurred to me is it really that bad to catch a general exception error within a try block or should you be looking for a specific exception. Thoughts on a postcard please.
Obviously this is one of those questions where the only real answer is "it depends." The main thing it depends on is where your are catching the exception. In general libraries should be more conservative with catching exceptions whereas at the top level of your program (e.g. in your main method or in the top of the a...
21,961
<pre><code>&gt;&gt;&gt; import time &gt;&gt;&gt; time.strptime("01-31-2009", "%m-%d-%Y") (2009, 1, 31, 0, 0, 0, 5, 31, -1) &gt;&gt;&gt; time.mktime((2009, 1, 31, 0, 0, 0, 5, 31, -1)) 1233378000.0 &gt;&gt;&gt; 60*60*24 # seconds in a day 86400 &gt;&gt;&gt; 1233378000.0 / 86400 14275.208333333334 </code></pre> <p><code>...
[ { "answer_id": 21973, "author": "Anders Eurenius", "author_id": 1421, "author_profile": "https://Stackoverflow.com/users/1421", "pm_score": 2, "selected": false, "text": "<pre><code>mktime(...)\n mktime(tuple) -&gt; floating point number\n\n Convert a time tuple in local time to se...
2008/08/22
[ "https://Stackoverflow.com/questions/21961", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2427/" ]
``` >>> import time >>> time.strptime("01-31-2009", "%m-%d-%Y") (2009, 1, 31, 0, 0, 0, 5, 31, -1) >>> time.mktime((2009, 1, 31, 0, 0, 0, 5, 31, -1)) 1233378000.0 >>> 60*60*24 # seconds in a day 86400 >>> 1233378000.0 / 86400 14275.208333333334 ``` `time.mktime` should return the number of seconds since the epoch. Sin...
Short answer: Because of timezones. The Epoch is in UTC. For example, I'm on IST (Irish Standard Time) or UTC+1. [`time.mktime()`](https://docs.python.org/3/library/time.html#time.gmtime) is relative to my timezone, so on my system this refers to ``` >>> time.mktime((2009, 1, 31, 0, 0, 0, 5, 31, -1)) 1233360000.0 `...
21,987
<p>I am developing an application that controls an Machine.<br/> When I receive an error from the Machine the users should be able to directly notice it, one way that is done is Flashing the tray on the taskbar. When the machine clears the error the tray should stop flashing.</p> <p>There's one little annoyance using t...
[ { "answer_id": 23285, "author": "TheSmurf", "author_id": 1975282, "author_profile": "https://Stackoverflow.com/users/1975282", "pm_score": 4, "selected": true, "text": "<p>Behaviour is the same when a window finishes flashing for as long as it's supposed to: the taskbar button stays colo...
2008/08/22
[ "https://Stackoverflow.com/questions/21987", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2090/" ]
I am developing an application that controls an Machine. When I receive an error from the Machine the users should be able to directly notice it, one way that is done is Flashing the tray on the taskbar. When the machine clears the error the tray should stop flashing. There's one little annoyance using the `FlashWi...
Behaviour is the same when a window finishes flashing for as long as it's supposed to: the taskbar button stays coloured. I don't think this is a bug. If you think about it, when you use `FLASHW_STOP`, the flashing does in fact stop, but the point of the flashing is to get the user's attention. The button stays coloure...
22,001
<p>I'm learning objective-C and Cocoa. In the Apple tutorial I'm working through there's a side note that says: </p> <blockquote> <p><code>IBOutlet</code> is a null-defined macro, which the C preprocessor removes at compile time.</p> </blockquote> <p>I'm curious - what's a null-defined macro?</p>
[ { "answer_id": 22003, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 3, "selected": false, "text": "<pre><code>#define IBOutlet\n</code></pre>\n\n<p>Whenever IBOutlet is used in program text, it will be replaced with nothi...
2008/08/22
[ "https://Stackoverflow.com/questions/22001", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I'm learning objective-C and Cocoa. In the Apple tutorial I'm working through there's a side note that says: > > `IBOutlet` is a null-defined macro, which the C preprocessor removes at compile time. > > > I'm curious - what's a null-defined macro?
``` #define IBOutlet ``` Whenever IBOutlet is used in program text, it will be replaced with nothing at all.
22,012
<p>My application dynamically loads assemblies at runtime from specific subfolders. These assemblies are compiled with dependencies to other assemblies. The runtime trys to load these from the application directory. But I want to put them into the modules directory.</p> <p>Is there a way to tell the runtime that the d...
[ { "answer_id": 22022, "author": "samjudson", "author_id": 1908, "author_profile": "https://Stackoverflow.com/users/1908", "pm_score": 2, "selected": false, "text": "<p>You can use the <code>&lt;probing&gt;</code> element in a manifest file to tell the Runtime to look in different directo...
2008/08/22
[ "https://Stackoverflow.com/questions/22012", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2374/" ]
My application dynamically loads assemblies at runtime from specific subfolders. These assemblies are compiled with dependencies to other assemblies. The runtime trys to load these from the application directory. But I want to put them into the modules directory. Is there a way to tell the runtime that the dlls are in...
One nice approach I've used lately is to add an event handler for the AppDomain's AssemblyResolve event. ``` AppDomain currentDomain = AppDomain.CurrentDomain; currentDomain.AssemblyResolve += new ResolveEventHandler(MyResolveEventHandler); ``` Then in the event handler method you can load the assembly that was atte...
22,135
<p>I am trying to implement NTLM authentication on one of our internal sites and everything is working. The one piece of the puzzle I do not have is how to take the information from NTLM and authenticate with Active Directory.</p> <p>There is a <a href="http://www.innovation.ch/personal/ronald/ntlm.html" rel="nofollow...
[ { "answer_id": 22185, "author": "Portman", "author_id": 1690, "author_profile": "https://Stackoverflow.com/users/1690", "pm_score": 0, "selected": false, "text": "<p>Hm, I'm not sure what you're trying to accomplish.</p>\n\n<p>Usually implementing NTLM on an internal site is as simple as...
2008/08/22
[ "https://Stackoverflow.com/questions/22135", "https://Stackoverflow.com", "https://Stackoverflow.com/users/309844/" ]
I am trying to implement NTLM authentication on one of our internal sites and everything is working. The one piece of the puzzle I do not have is how to take the information from NTLM and authenticate with Active Directory. There is a [good description of NTLM](http://www.innovation.ch/personal/ronald/ntlm.html) and t...
What you're really asking is: Is there any way to validate the "WWW-Authenticate: NTLM" tokens submitted by IE and other HTTP clients when doing Single Sign-On (SSO). SSO is when the user enters their password a "single" time when they do Ctrl-Alt-Del and the workstation remembers and uses it as necessary to transparen...
22,181
<p>I have a very simple mapping function called "BuildEntity" that does the usual boring "left/right" coding required to dump my reader data into my domain object. (shown below) My question is this - If I don't bring back every column in this mapping as is, I get the "System.IndexOutOfRangeException" exception and want...
[ { "answer_id": 22186, "author": "Slavo", "author_id": 1801, "author_profile": "https://Stackoverflow.com/users/1801", "pm_score": 0, "selected": false, "text": "<p>Why don't you use LinqToSql - everything you need is done automatically. For the sake of being general you can use any other...
2008/08/22
[ "https://Stackoverflow.com/questions/22181", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have a very simple mapping function called "BuildEntity" that does the usual boring "left/right" coding required to dump my reader data into my domain object. (shown below) My question is this - If I don't bring back every column in this mapping as is, I get the "System.IndexOutOfRangeException" exception and wanted ...
Although connection.GetSchema("Tables") does return meta data about the tables in your database, it won't return everything in your sproc if you define any custom columns. For example, if you throw in some random ad-hoc column like \*SELECT ProductName,'Testing' As ProductTestName FROM dbo.Products" you won't see 'Pr...
22,187
<p>What libraries exist for other programming languages to provide an Erlang-style concurrency model (processes, mailboxes, pattern-matching receive, etc.)?</p> <p>Note: I am specifically interested in things that are intended to be similar to Erlang, not just any threading or queueing library.</p>
[ { "answer_id": 22197, "author": "Frank Krueger", "author_id": 338, "author_profile": "https://Stackoverflow.com/users/338", "pm_score": 3, "selected": false, "text": "<p>Microsoft <a href=\"http://msdn.microsoft.com/en-us/library/bb648752.aspx\" rel=\"noreferrer\">Concurrency and Coordin...
2008/08/22
[ "https://Stackoverflow.com/questions/22187", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1175/" ]
What libraries exist for other programming languages to provide an Erlang-style concurrency model (processes, mailboxes, pattern-matching receive, etc.)? Note: I am specifically interested in things that are intended to be similar to Erlang, not just any threading or queueing library.
Message Passing Interface (MPI) (<http://www-unix.mcs.anl.gov/mpi/>) is a highly scalable and robust library for parallel programming, geared original towards C but now available in several flavors <http://en.wikipedia.org/wiki/Message_Passing_Interface#Implementations>. While the library doesn't introduce new syntax, ...
22,239
<p>(I'm using Visual C++ 2008) I've always heard that main() is <em>required</em> to return an integer, but here I didn't put in <code>return 0;</code> and and it compiled with 0 errors and 0 warnings! In the debug window it says the program has exited with code 0. If this function is named anything other than main()...
[ { "answer_id": 22251, "author": "bradtgmurray", "author_id": 1546, "author_profile": "https://Stackoverflow.com/users/1546", "pm_score": 2, "selected": false, "text": "<p>I'm pretty sure VC++ just inserts a return 0 if you don't include one in main functions. The same thing can happen wi...
2008/08/22
[ "https://Stackoverflow.com/questions/22239", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2222/" ]
(I'm using Visual C++ 2008) I've always heard that main() is *required* to return an integer, but here I didn't put in `return 0;` and and it compiled with 0 errors and 0 warnings! In the debug window it says the program has exited with code 0. If this function is named anything other than main(), the compiler complain...
> > 3.6.1 Main function > =================== > > > .... > > > 2 An implementation shall not predefine the `main` function. This function shall not be overloaded. It shall have a return type of type `int`, but otherwise its type is implementation-defined. All implementations shall allow both of the following defin...
22,259
<p>I want to allow users to upload avatar-type images in a variety of formats (<strong>GIF, JPEG, and PNG at least</strong>), but to save them all as <strong>PNG database BLOBs</strong>. If the images are oversized, pixelwise, I want to resize them before DB-insertion.</p> <p><strong>What is the best way to use GD to ...
[ { "answer_id": 22267, "author": "tslocum", "author_id": 1662, "author_profile": "https://Stackoverflow.com/users/1662", "pm_score": 0, "selected": false, "text": "<p><a href=\"http://www.phpit.net/article/image-manipulation-php-gd-part2/\" rel=\"nofollow noreferrer\">This article</a> see...
2008/08/22
[ "https://Stackoverflow.com/questions/22259", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1820/" ]
I want to allow users to upload avatar-type images in a variety of formats (**GIF, JPEG, and PNG at least**), but to save them all as **PNG database BLOBs**. If the images are oversized, pixelwise, I want to resize them before DB-insertion. **What is the best way to use GD to do the resizing and PNG conversion?** Edi...
``` <?php /* Resizes an image and converts it to PNG returning the PNG data as a string */ function imageToPng($srcFile, $maxSize = 100) { list($width_orig, $height_orig, $type) = getimagesize($srcFile); // Get the aspect ratio $ratio_orig = $width_or...
22,269
<p>I'm trying to build a C# console application to automate grabbing certain files from our website, mostly to save myself clicks and - frankly - just to have done it. But I've hit a snag that for which I've been unable to find a working solution.</p> <p>The website I'm trying to which I'm trying to connect uses ASP....
[ { "answer_id": 22267, "author": "tslocum", "author_id": 1662, "author_profile": "https://Stackoverflow.com/users/1662", "pm_score": 0, "selected": false, "text": "<p><a href=\"http://www.phpit.net/article/image-manipulation-php-gd-part2/\" rel=\"nofollow noreferrer\">This article</a> see...
2008/08/22
[ "https://Stackoverflow.com/questions/22269", "https://Stackoverflow.com", "https://Stackoverflow.com/users/111/" ]
I'm trying to build a C# console application to automate grabbing certain files from our website, mostly to save myself clicks and - frankly - just to have done it. But I've hit a snag that for which I've been unable to find a working solution. The website I'm trying to which I'm trying to connect uses ASP.Net forms a...
``` <?php /* Resizes an image and converts it to PNG returning the PNG data as a string */ function imageToPng($srcFile, $maxSize = 100) { list($width_orig, $height_orig, $type) = getimagesize($srcFile); // Get the aspect ratio $ratio_orig = $width_or...
22,322
<p>I've got a problem similar to,but subtly different from, that described <a href="https://stackoverflow.com/questions/22012/loading-assemblies-and-its-dependencies">here</a> (Loading assemblies and their dependencies).</p> <p>I have a C++ DLL for 3D rendering that is what we sell to customers. For .NET users we will...
[ { "answer_id": 22347, "author": "Ishmaeel", "author_id": 227, "author_profile": "https://Stackoverflow.com/users/227", "pm_score": 1, "selected": false, "text": "<p>I encountered a similar scenario a while back. A toolkit I was using did not behave well in a 64-bit environment and I wasn...
2008/08/22
[ "https://Stackoverflow.com/questions/22322", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2102/" ]
I've got a problem similar to,but subtly different from, that described [here](https://stackoverflow.com/questions/22012/loading-assemblies-and-its-dependencies) (Loading assemblies and their dependencies). I have a C++ DLL for 3D rendering that is what we sell to customers. For .NET users we will have a CLR wrapper a...
I finally have an answer for this that appears to work. Compile both 32 & 64 bit versions - both managed & unmanaged - into separate folders. Then have the .NET app choose at run time which directory to load the assemblies from. The problem with using the ResolveEvent is that it only gets called if assemblies aren't ...
22,326
<p>I am trying to <strong>replace the current selection in Word (2003/2007)</strong> by some <strong>RTF string</strong> stored in a variable.</p> <p>Here is the current code:</p> <pre><code>Clipboard.SetText(strRTFString, TextDataFormat.Rtf) oWord.ActiveDocument.ActiveWindow.Selection.PasteAndFormat(0) </code></pre>...
[ { "answer_id": 22335, "author": "samjudson", "author_id": 1908, "author_profile": "https://Stackoverflow.com/users/1908", "pm_score": -1, "selected": false, "text": "<p>You can use a RichTextbox to convert RTF to text or vice versa.</p>\n\n<pre><code>RichTextBox r = new RichTextBox();\nr...
2008/08/22
[ "https://Stackoverflow.com/questions/22326", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1508/" ]
I am trying to **replace the current selection in Word (2003/2007)** by some **RTF string** stored in a variable. Here is the current code: ``` Clipboard.SetText(strRTFString, TextDataFormat.Rtf) oWord.ActiveDocument.ActiveWindow.Selection.PasteAndFormat(0) ``` Is there any way to do the same thing without going th...
Put the RTF in a file instead of the clipboard, then insert from the file, e.g. > > `Selection.InsertFile FileName:="myfile.rtf", Range :="", _ > ConfirmConversions:=False, Link:=False, Attachment:=False` > > >
22,354
<p>I am working on a SharePoint application that supports importing multiple documents in a single operation. I also have an ItemAdded event handler that performs some basic maintenance of the item metadata. This event fires for both imported documents and manually created ones. The final piece of the puzzle is a ba...
[ { "answer_id": 22703, "author": "vitule", "author_id": 1287, "author_profile": "https://Stackoverflow.com/users/1287", "pm_score": 1, "selected": false, "text": "<p>Sometimes I see the <code>ItemAdded</code> or <code>ItemUpdated</code> firing twice for a single operation. \nYou can try t...
2008/08/22
[ "https://Stackoverflow.com/questions/22354", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2470/" ]
I am working on a SharePoint application that supports importing multiple documents in a single operation. I also have an ItemAdded event handler that performs some basic maintenance of the item metadata. This event fires for both imported documents and manually created ones. The final piece of the puzzle is a batch op...
Sometimes I see the `ItemAdded` or `ItemUpdated` firing twice for a single operation. You can try to put a breakpoint in the `ItemAdded()` method to confirm that. The solution in my case was to single thread the `ItemAdded()` method: ``` private static object myLock = new object(); public override void ItemAdded(SPI...
22,356
<p>I find that the .NET event model is such that I'll often be raising an event on one thread and listening for it on another thread. I was wondering what the cleanest way to marshal an event from a background thread onto my UI thread is.</p> <p>Based on the community suggestions, I've used this:</p> <pre><code>// e...
[ { "answer_id": 22387, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 4, "selected": false, "text": "<p>I shun redundant delegate declarations.</p>\n\n<pre><code>private void mCoolObject_CoolEvent(object sender, CoolObj...
2008/08/22
[ "https://Stackoverflow.com/questions/22356", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1490/" ]
I find that the .NET event model is such that I'll often be raising an event on one thread and listening for it on another thread. I was wondering what the cleanest way to marshal an event from a background thread onto my UI thread is. Based on the community suggestions, I've used this: ``` // earlier in the code mCo...
A couple of observations: * Don't create simple delegates explicitly in code like that unless you're pre-2.0 so you could use: ```cs BeginInvoke(new EventHandler<CoolObjectEventArgs>(mCoolObject_CoolEvent), sender, args); ``` * Also you don't need to create and populate the object...
22,379
<p>I'm wondering how you can implement a program similar to <code>tail -f</code> in C/C++, a program that watches for and processes new lines added to a log file?</p>
[ { "answer_id": 22384, "author": "Adam Haile", "author_id": 194, "author_profile": "https://Stackoverflow.com/users/194", "pm_score": 0, "selected": false, "text": "<p><a href=\"https://stackoverflow.com/questions/18632/how-to-monitor-a-text-file-in-realtime#18635\">See here</a></p>\n\n<p...
2008/08/22
[ "https://Stackoverflow.com/questions/22379", "https://Stackoverflow.com", "https://Stackoverflow.com/users/486/" ]
I'm wondering how you can implement a program similar to `tail -f` in C/C++, a program that watches for and processes new lines added to a log file?
You can use fseek() to clear the eof condition on the stream. Essentially, read to the end of the file, sleep for a while, fseek() (without changing your position) to clear eof, the read to end of file again. wash, rinse, repeat. man fseek(3) for details. Here's what it looks like in perl. perl's seek() is essentially...
22,409
<p>I have a need to convert images from CMYK to RGB - not necessarily back again, but hey, if it can be done...</p> <p>With the release of ColdFusion 8, we got the <a href="http://cfquickdocs.com/cf8/?getDoc=cfimage" rel="nofollow noreferrer">CFImage</a> tag, but it doesn't support this conversion; and nor does <a hre...
[ { "answer_id": 23577, "author": "Michał Piaskowski", "author_id": 1534, "author_profile": "https://Stackoverflow.com/users/1534", "pm_score": 4, "selected": false, "text": "<p>A very simple formula for converting from CMYK to RGB ignoring all color profiles is:</p>\n\n<pre>\n R = ( (2...
2008/08/22
[ "https://Stackoverflow.com/questions/22409", "https://Stackoverflow.com", "https://Stackoverflow.com/users/751/" ]
I have a need to convert images from CMYK to RGB - not necessarily back again, but hey, if it can be done... With the release of ColdFusion 8, we got the [CFImage](http://cfquickdocs.com/cf8/?getDoc=cfimage) tag, but it doesn't support this conversion; and nor does [Image.cfc](http://x.com), or [Alagad's Image Compone...
I use the Java ImageIO libraries (<https://jai-imageio.dev.java.net>). They aren't perfect, but can be simple and get the job done. As far as converting from CMYK to RGB, here is the best I have been able to come up with. Download and install the ImageIO JARs and native libraries for your platform. The native librarie...
22,417
<p>Say I have a Student table, it's got an int ID. I have a fixed set of 10 multiple choice questions with 5 possible answers. I have a normalized answer table that has the question id, the Student.answer (1-5) and the Student.ID</p> <p>I'm trying to write a single query that will return all scores over a certain pe...
[ { "answer_id": 22421, "author": "Bryan Roth", "author_id": 299, "author_profile": "https://Stackoverflow.com/users/299", "pm_score": 1, "selected": false, "text": "<p>I would probably leave it up to your application to perform the scoring. Check out <a href=\"http://www.codinghorror.com...
2008/08/22
[ "https://Stackoverflow.com/questions/22417", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1975/" ]
Say I have a Student table, it's got an int ID. I have a fixed set of 10 multiple choice questions with 5 possible answers. I have a normalized answer table that has the question id, the Student.answer (1-5) and the Student.ID I'm trying to write a single query that will return all scores over a certain pecentage. To ...
If I understand your schema and question correctly, how about something like this: ``` select student_name, score from students join (select student_answers.student_id, count(*) as score from student_answers, answer_key group by student_id where student_answers.question_id = answer_key.questi...
22,429
<p>Is it possible to embed an inline search box into a web page which provides similar functionality to the <a href="http://www.ie7pro.com/inline-search.html" rel="noreferrer">IE7Pro Inline Search</a> or similar plugins for Firefox/Safari?</p>
[ { "answer_id": 22421, "author": "Bryan Roth", "author_id": 299, "author_profile": "https://Stackoverflow.com/users/299", "pm_score": 1, "selected": false, "text": "<p>I would probably leave it up to your application to perform the scoring. Check out <a href=\"http://www.codinghorror.com...
2008/08/22
[ "https://Stackoverflow.com/questions/22429", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2418/" ]
Is it possible to embed an inline search box into a web page which provides similar functionality to the [IE7Pro Inline Search](http://www.ie7pro.com/inline-search.html) or similar plugins for Firefox/Safari?
If I understand your schema and question correctly, how about something like this: ``` select student_name, score from students join (select student_answers.student_id, count(*) as score from student_answers, answer_key group by student_id where student_answers.question_id = answer_key.questi...
22,444
<p>I have this gigantic ugly string:</p> <pre class="lang-none prettyprint-override"><code>J0000000: Transaction A0001401 started on 8/22/2008 9:49:29 AM J0000010: Project name: E:\foo.pf J0000011: Job name: MBiek Direct Mail Test J0000020: Document 1 - Completed successfully </code></pre> <p>I'm trying to extract piec...
[ { "answer_id": 22449, "author": "jj33", "author_id": 430, "author_profile": "https://Stackoverflow.com/users/430", "pm_score": 8, "selected": true, "text": "<p>Make <code>.*</code> non-greedy by adding '<code>?</code>' after it:</p>\n\n<pre><code>Project name:\\s+(.*?)\\s+J[0-9]{7}:\n</c...
2008/08/22
[ "https://Stackoverflow.com/questions/22444", "https://Stackoverflow.com", "https://Stackoverflow.com/users/305/" ]
I have this gigantic ugly string: ```none J0000000: Transaction A0001401 started on 8/22/2008 9:49:29 AM J0000010: Project name: E:\foo.pf J0000011: Job name: MBiek Direct Mail Test J0000020: Document 1 - Completed successfully ``` I'm trying to extract pieces from it using regex. In this case, I want to grab everyt...
Make `.*` non-greedy by adding '`?`' after it: ``` Project name:\s+(.*?)\s+J[0-9]{7}: ```
22,459
<p>I'm getting some strange, intermittent, data aborts (&lt; 5% of the time) in some of my code, when calling <code>memset()</code>. The problem is that is usually doesn't happen unless the code is running for a couple days, so it's hard to catch it in the act.</p> <p>I'm using the following code:</p> <pre><code>cha...
[ { "answer_id": 22464, "author": "Doug", "author_id": 1618, "author_profile": "https://Stackoverflow.com/users/1618", "pm_score": 0, "selected": false, "text": "<p>Have you tried using Valgrind? That is usually the fastest and easiest way to debug these sorts of errors. If you are reading...
2008/08/22
[ "https://Stackoverflow.com/questions/22459", "https://Stackoverflow.com", "https://Stackoverflow.com/users/194/" ]
I'm getting some strange, intermittent, data aborts (< 5% of the time) in some of my code, when calling `memset()`. The problem is that is usually doesn't happen unless the code is running for a couple days, so it's hard to catch it in the act. I'm using the following code: ``` char *msg = (char*)malloc(sizeof(char)*...
`malloc` can return `NULL` if no memory is available. You're not checking for that.
22,474
<p>How do I select all records that contain "LCS" within the title column in sql.</p>
[ { "answer_id": 22476, "author": "Owen", "author_id": 2109, "author_profile": "https://Stackoverflow.com/users/2109", "pm_score": 3, "selected": true, "text": "<pre><code>SELECT * FROM TABLE WHERE TABLE.TITLE LIKE '%LCS%';\n</code></pre>\n\n<p>% is the wild card matcher.</p>\n" }, { ...
2008/08/22
[ "https://Stackoverflow.com/questions/22474", "https://Stackoverflow.com", "https://Stackoverflow.com/users/453046/" ]
How do I select all records that contain "LCS" within the title column in sql.
``` SELECT * FROM TABLE WHERE TABLE.TITLE LIKE '%LCS%'; ``` % is the wild card matcher.
22,503
<p>I have a form view, in the edit template I have two drop downs. Drop down 1 is explicitly set with a list of allowed values. It is also set to autopostback. Drop down 2 is databound to an objectdatasource, this objectdatasource uses the first dropdown as one of it's parameters. (The idea is that drop down 1 limits ...
[ { "answer_id": 22797, "author": "Joel Meador", "author_id": 1976, "author_profile": "https://Stackoverflow.com/users/1976", "pm_score": 0, "selected": false, "text": "<p>Sounds like the controls aren't being databound properly after the postback.</p>\n\n<p>Are you databinding the first d...
2008/08/22
[ "https://Stackoverflow.com/questions/22503", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2496/" ]
I have a form view, in the edit template I have two drop downs. Drop down 1 is explicitly set with a list of allowed values. It is also set to autopostback. Drop down 2 is databound to an objectdatasource, this objectdatasource uses the first dropdown as one of it's parameters. (The idea is that drop down 1 limits wha...
I had a similar problem with bound dropdownlists in a FormView. I worked around it by setting the selected value manually in the formview's "OnDataBound". (don't know where you get ConnectToProject\_ID from) ``` FormView fv = (FormView)sender; DropDownList ddl = (DropDownList)fv.FindControl("ProjectList"); ddl.Selec...
22,509
<p>I have an ASP.NET webforms application (3.5 SP1) that I'm working on, and attempting to enable gzip fpr HTML and CSS that comes down the pipe. I'm using <a href="http://www.stardeveloper.com/articles/display.html?article=2007110401&amp;page=1" rel="nofollow noreferrer">this implementation</a> (and tried a few others...
[ { "answer_id": 22563, "author": "Sean Carpenter", "author_id": 729, "author_profile": "https://Stackoverflow.com/users/729", "pm_score": 0, "selected": false, "text": "<p>If you will be deploying on IIS 6 or IIS 7, just use the built-in IIS compression. We're using it on production site...
2008/08/22
[ "https://Stackoverflow.com/questions/22509", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1212/" ]
I have an ASP.NET webforms application (3.5 SP1) that I'm working on, and attempting to enable gzip fpr HTML and CSS that comes down the pipe. I'm using [this implementation](http://www.stardeveloper.com/articles/display.html?article=2007110401&page=1) (and tried a few others that hook into Application\_BeginRequest), ...
Is it only CSS files that get corrupted? Do JS files (or any other static text files) come through ok? Also can you duplicate the behavior if you browse directly to the CSS file? I've only enabled compression on Windows 2003 server's IIS using this approach: 1. IIS → Web Sites → Properties → Service tab, check both ...
22,552
<p>I have a regex that is going to end up being a bit long and it'd make it much easier to read to have it across multiple lines.</p> <p>I tried this but it just barfs.</p> <pre><code>preg_match( '^J[0-9]{7}:\s+ (.*?) #Extract the Transaction Start Date msg \s+J[0-9]{7}:\s+Project\sname:\s+ ...
[ { "answer_id": 22572, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 4, "selected": true, "text": "<p>You can use the extended syntax:</p>\n\n<pre><code>preg_match(\"/\n test\n/x\", $foo, $bar);\n</code></pre>\n" ...
2008/08/22
[ "https://Stackoverflow.com/questions/22552", "https://Stackoverflow.com", "https://Stackoverflow.com/users/305/" ]
I have a regex that is going to end up being a bit long and it'd make it much easier to read to have it across multiple lines. I tried this but it just barfs. ``` preg_match( '^J[0-9]{7}:\s+ (.*?) #Extract the Transaction Start Date msg \s+J[0-9]{7}:\s+Project\sname:\s+ (.*?) #...
You can use the extended syntax: ``` preg_match("/ test /x", $foo, $bar); ```
22,566
<p>How do I get Perl to read the contents of a given directory into an array?</p> <p><a href="https://en.wikipedia.org/wiki/Grave_accent#Use_in_programming" rel="noreferrer">Backticks</a> can do it, but is there some method using 'scandir' or a similar term?</p>
[ { "answer_id": 22573, "author": "jj33", "author_id": 430, "author_profile": "https://Stackoverflow.com/users/430", "pm_score": 7, "selected": true, "text": "<pre><code>opendir(D, \"/path/to/directory\") || die \"Can't open directory: $!\\n\";\nwhile (my $f = readdir(D)) {\n print \"\\...
2008/08/22
[ "https://Stackoverflow.com/questions/22566", "https://Stackoverflow.com", "https://Stackoverflow.com/users/277/" ]
How do I get Perl to read the contents of a given directory into an array? [Backticks](https://en.wikipedia.org/wiki/Grave_accent#Use_in_programming) can do it, but is there some method using 'scandir' or a similar term?
``` opendir(D, "/path/to/directory") || die "Can't open directory: $!\n"; while (my $f = readdir(D)) { print "\$f = $f\n"; } closedir(D); ``` EDIT: Oh, sorry, missed the "into an array" part: ``` my $d = shift; opendir(D, "$d") || die "Can't open directory $d: $!\n"; my @list = readdir(D); closedir(D); foreach...
22,570
<p>Here is the issue I am having: I have a large query that needs to compare datetimes in the where clause to see if two dates are on the same day. My current solution, which sucks, is to send the datetimes into a UDF to convert them to midnight of the same day, and then check those dates for equality. When it comes ...
[ { "answer_id": 22579, "author": "jason saldo", "author_id": 1293, "author_profile": "https://Stackoverflow.com/users/1293", "pm_score": 3, "selected": false, "text": "<pre><code>where\nyear(date1) = year(date2)\nand month(date1) = month(date2)\nand day(date1) = day(date2)\n</code></pre>\...
2008/08/22
[ "https://Stackoverflow.com/questions/22570", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1219/" ]
Here is the issue I am having: I have a large query that needs to compare datetimes in the where clause to see if two dates are on the same day. My current solution, which sucks, is to send the datetimes into a UDF to convert them to midnight of the same day, and then check those dates for equality. When it comes to th...
This is much more concise: ``` where datediff(day, date1, date2) = 0 ```
22,617
<p>I need to find out how to format numbers as strings. My code is here:</p> <pre><code>return str(hours)+":"+str(minutes)+":"+str(seconds)+" "+ampm </code></pre> <p>Hours and minutes are integers, and seconds is a float. the str() function will convert all of these numbers to the tenths (0.1) place. So instead of ...
[ { "answer_id": 22624, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 8, "selected": true, "text": "<p>Starting with Python 3.6, formatting in Python can be done using <a href=\"https://docs.python.org/3/whatsnew/3.6.ht...
2008/08/22
[ "https://Stackoverflow.com/questions/22617", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2504/" ]
I need to find out how to format numbers as strings. My code is here: ``` return str(hours)+":"+str(minutes)+":"+str(seconds)+" "+ampm ``` Hours and minutes are integers, and seconds is a float. the str() function will convert all of these numbers to the tenths (0.1) place. So instead of my string outputting "5:30:5...
Starting with Python 3.6, formatting in Python can be done using [formatted string literals](https://docs.python.org/3/whatsnew/3.6.html#whatsnew36-pep498) or *f-strings*: ``` hours, minutes, seconds = 6, 56, 33 f'{hours:02}:{minutes:02}:{seconds:02} {"pm" if hours > 12 else "am"}' ``` or the [`str.format`](https://...
22,623
<p>What are the best practices to consider when catching exceptions and re-throwing them? I want to make sure that the <code>Exception</code> object's <code>InnerException</code> and stack trace are preserved. Is there a difference between the following code blocks in the way they handle this?</p> <pre><code>try { ...
[ { "answer_id": 22628, "author": "Darren Kopp", "author_id": 77, "author_profile": "https://Stackoverflow.com/users/77", "pm_score": 9, "selected": true, "text": "<p>The way to preserve the stack trace is through the use of the <code>throw;</code> This is valid as well</p>\n\n<pre><code>t...
2008/08/22
[ "https://Stackoverflow.com/questions/22623", "https://Stackoverflow.com", "https://Stackoverflow.com/users/357/" ]
What are the best practices to consider when catching exceptions and re-throwing them? I want to make sure that the `Exception` object's `InnerException` and stack trace are preserved. Is there a difference between the following code blocks in the way they handle this? ``` try { //some code } catch (Exception ex) ...
The way to preserve the stack trace is through the use of the `throw;` This is valid as well ``` try { // something that bombs here } catch (Exception ex) { throw; } ``` `throw ex;` is basically like throwing an exception from that point, so the stack trace would only go to where you are issuing the `throw ex;...
22,676
<p>I have a small utility that I use to download an MP3 file from a website on a schedule and then builds/updates a podcast XML file which I've added to iTunes.</p> <p>The text processing that creates/updates the XML file is written in Python. However, I use wget inside a Windows <code>.bat</code> file to download the...
[ { "answer_id": 22682, "author": "Corey", "author_id": 1595, "author_profile": "https://Stackoverflow.com/users/1595", "pm_score": 10, "selected": true, "text": "<p>Use <a href=\"https://docs.python.org/3/library/urllib.request.html#urllib.request.urlopen\" rel=\"noreferrer\"><code>urllib...
2008/08/22
[ "https://Stackoverflow.com/questions/22676", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2109/" ]
I have a small utility that I use to download an MP3 file from a website on a schedule and then builds/updates a podcast XML file which I've added to iTunes. The text processing that creates/updates the XML file is written in Python. However, I use wget inside a Windows `.bat` file to download the actual MP3 file. I w...
Use [`urllib.request.urlopen()`](https://docs.python.org/3/library/urllib.request.html#urllib.request.urlopen): ``` import urllib.request with urllib.request.urlopen('http://www.example.com/') as f: html = f.read().decode('utf-8') ``` This is the most basic way to use the library, minus any error handling. You c...
22,697
<p>What's the best framework for creating mock objects in Java? Why? What are the pros and cons of each framework?</p>
[ { "answer_id": 23048, "author": "Brian Laframboise", "author_id": 1557, "author_profile": "https://Stackoverflow.com/users/1557", "pm_score": 9, "selected": true, "text": "<p>I've had good success using <a href=\"https://github.com/mockito/mockito\" rel=\"noreferrer\">Mockito</a>.</p>\n\...
2008/08/22
[ "https://Stackoverflow.com/questions/22697", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2030/" ]
What's the best framework for creating mock objects in Java? Why? What are the pros and cons of each framework?
I've had good success using [Mockito](https://github.com/mockito/mockito). When I tried learning about JMock and EasyMock, I found the learning curve to be a bit steep (though maybe that's just me). I like Mockito because of its simple and clean syntax that I was able to grasp pretty quickly. The minimal syntax is de...
22,708
<p>How would you determine the column name (e.g. "AQ" or "BH") of the nth column in Excel?</p> <p>Edit: A language-agnostic algorithm to determine this is the main goal here.</p>
[ { "answer_id": 22715, "author": "Joseph Sturtevant", "author_id": 317, "author_profile": "https://Stackoverflow.com/users/317", "pm_score": 6, "selected": true, "text": "<p>I once wrote this function to perform that exact task:</p>\n\n<pre><code>public static string Column(int column)\n{...
2008/08/22
[ "https://Stackoverflow.com/questions/22708", "https://Stackoverflow.com", "https://Stackoverflow.com/users/940/" ]
How would you determine the column name (e.g. "AQ" or "BH") of the nth column in Excel? Edit: A language-agnostic algorithm to determine this is the main goal here.
I once wrote this function to perform that exact task: ``` public static string Column(int column) { column--; if (column >= 0 && column < 26) return ((char)('A' + column)).ToString(); else if (column > 25) return Column(column / 26) + Column(column % 26 + 1); else throw new Exc...
22,720
<p>I have a listening port on my server that I'm connecting to using a Java class and the <code>Socket</code> interface, i.e.</p> <pre><code>Socket mySocket = new Socket(host,port); </code></pre> <p>I then grab an <code>OutputStream</code>, decorate with a <code>PrintWriter</code> in autoflush mode and I'm laughing -...
[ { "answer_id": 22803, "author": "James A. Rosen", "author_id": 1190, "author_profile": "https://Stackoverflow.com/users/1190", "pm_score": 2, "selected": true, "text": "<p>Set a short timeout?</p>\n\n<p>Does <code>isOutputShutdown()</code> not get you what you want?</p>\n\n<p>You could a...
2008/08/22
[ "https://Stackoverflow.com/questions/22720", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2362/" ]
I have a listening port on my server that I'm connecting to using a Java class and the `Socket` interface, i.e. ``` Socket mySocket = new Socket(host,port); ``` I then grab an `OutputStream`, decorate with a `PrintWriter` in autoflush mode and I'm laughing - except if the listening port closes. Then I get ``` tcp4...
Set a short timeout? Does `isOutputShutdown()` not get you what you want? You could always build a `SocketWatcher` class that spins up in its own `Thread` and repeatedly tries to write empty strings to the `Socket` until that raises a `SocketClosedException`.
22,732
<p>I am trying to do some string concatenation/formatting, but it's putting all the parameters into the first placeholder.</p> <p><strong>Code</strong></p> <pre><code>function CreateAppPoolScript([string]$AppPoolName, [string]$AppPoolUser, [string]$AppPoolPass) { # Command to create an IIS application pool $A...
[ { "answer_id": 22770, "author": "Paul Roub", "author_id": 1324, "author_profile": "https://Stackoverflow.com/users/1324", "pm_score": 7, "selected": true, "text": "<p>Lose the parentheses and commas. </p>\n\n<p>Calling your function as:</p>\n\n<pre><code>$s = CreateAppPoolScript \"name\...
2008/08/22
[ "https://Stackoverflow.com/questions/22732", "https://Stackoverflow.com", "https://Stackoverflow.com/users/636/" ]
I am trying to do some string concatenation/formatting, but it's putting all the parameters into the first placeholder. **Code** ``` function CreateAppPoolScript([string]$AppPoolName, [string]$AppPoolUser, [string]$AppPoolPass) { # Command to create an IIS application pool $AppPoolScript = "cscript adsutil.vb...
Lose the parentheses and commas. Calling your function as: ``` $s = CreateAppPoolScript "name" "user" "pass" ``` gives: ```none cscript adsutil.vbs CREATE "w3svc/AppPools/name" IIsApplicationPool cscript adsutil.vbs SET "w3svc/AppPools/name/WamUserName" "user" cscript adsutil.vbs SET "w3svc/AppPools/name/WamUserP...
22,764
<p>In Ruby 1.8 and earlier,</p> <pre><code>Foo </code></pre> <p>is a constant (a Class, a Module, or another constant). Whereas</p> <pre><code>foo </code></pre> <p>is a variable. The key difference is as follows:</p> <pre><code>module Foo bar = 7 BAZ = 8 end Foo::BAZ # =&gt; 8 Foo::bar # NoMethodError: und...
[ { "answer_id": 23945, "author": "Orion Edwards", "author_id": 234, "author_profile": "https://Stackoverflow.com/users/234", "pm_score": 2, "selected": false, "text": "<p>I don't know what ruby would do if you used extended UTF8 characters as identifiers in your source code, but I know wh...
2008/08/22
[ "https://Stackoverflow.com/questions/22764", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1190/" ]
In Ruby 1.8 and earlier, ``` Foo ``` is a constant (a Class, a Module, or another constant). Whereas ``` foo ``` is a variable. The key difference is as follows: ``` module Foo bar = 7 BAZ = 8 end Foo::BAZ # => 8 Foo::bar # NoMethodError: undefined method 'bar' for Foo:Module ``` That's all well and good...
I can't get IRB to accept UTF-8 characters, so I used a test script (`/tmp/utf_test.rb`). "λ" works fine as a variable name: ``` # encoding: UTF-8 λ = 'foo' puts λ # from the command line: > ruby -KU /tmp/utf_test.rb foo ``` "λ" also works fine as a method name: ``` # encoding: UTF-8 Kernel.class_eval do alias_...
22,801
<p>It's about PHP but I've no doubt many of the same comments will apply to other languages.</p> <p>Simply put, what are the differences in the different types of loop for PHP? Is one faster/better than the others or should I simply put in the most readable loop?</p> <pre><code>for ($i = 0; $i &lt; 10; $i++) { # ...
[ { "answer_id": 22806, "author": "Thomas Owens", "author_id": 572, "author_profile": "https://Stackoverflow.com/users/572", "pm_score": 0, "selected": false, "text": "<p>I use the first loop when iterating over a conventional (indexed?) array and the foreach loop when dealing with an asso...
2008/08/22
[ "https://Stackoverflow.com/questions/22801", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1384652/" ]
It's about PHP but I've no doubt many of the same comments will apply to other languages. Simply put, what are the differences in the different types of loop for PHP? Is one faster/better than the others or should I simply put in the most readable loop? ``` for ($i = 0; $i < 10; $i++) { # code... } foreach ($arr...
For loop and While loops are entry condition loops. They evaluate condition first, so the statement block associated with the loop won't run even once if the condition fails to meet The statements inside this for loop block will run 10 times, the value of $i will be 0 to 9; ``` for ($i = 0; $i < 10; $i++) { ...
22,807
<p>Wondering if there is a better why in the WHERE clause of choosing records when you need to look at effective start and end dates?</p> <p>Currently this how I've done it in the past on MS SQL Server. Just worried about the date and not the time. I'm using SQL Server 2005.</p> <pre><code>AND Convert(datetime, Conv...
[ { "answer_id": 22809, "author": "Darren Kopp", "author_id": 77, "author_profile": "https://Stackoverflow.com/users/77", "pm_score": -1, "selected": false, "text": "<p>try</p>\n\n<pre><code>ep.EffectiveStartDate BETWEEN @date1 AND @date2\n</code></pre>\n\n<p>where you would do something l...
2008/08/22
[ "https://Stackoverflow.com/questions/22807", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2526/" ]
Wondering if there is a better why in the WHERE clause of choosing records when you need to look at effective start and end dates? Currently this how I've done it in the past on MS SQL Server. Just worried about the date and not the time. I'm using SQL Server 2005. ``` AND Convert(datetime, Convert(char(10), ep.Effec...
That is terrible, take a look at [Only In A Database Can You Get 1000% + Improvement By Changing A Few Lines Of Code](http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/only-in-a-database-can-you-get-1000-impr) to see how you can optimize this since that is not sargable Also check out [Get Datetime Without Tim...
22,816
<p>I know the following libraries for drawing charts in an SWT/Eclipse RCP application:</p> <ul> <li><a href="http://www.eclipse.org/articles/article.php?file=Article-BIRTChartEngine/index.html" rel="noreferrer">Eclipse BIRT Chart Engine</a> (Links to an article on how to use it)</li> <li><a href="http://www.jfree.org...
[ { "answer_id": 22830, "author": "FreeMemory", "author_id": 2132, "author_profile": "https://Stackoverflow.com/users/2132", "pm_score": 0, "selected": false, "text": "<p>There's also JGraph, but I'm not sure if that's only for graphs (i.e. nodes and edges), or if it does charts also.</p>\...
2008/08/22
[ "https://Stackoverflow.com/questions/22816", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1793/" ]
I know the following libraries for drawing charts in an SWT/Eclipse RCP application: * [Eclipse BIRT Chart Engine](http://www.eclipse.org/articles/article.php?file=Article-BIRTChartEngine/index.html) (Links to an article on how to use it) * [JFreeChart](http://www.jfree.org/jfreechart/) Which other libraries are ther...
I have not used BIRT or JGraph, however I use JFreeChart in my SWT application. I have found the best way to use JFreeChart in SWT is by making a composite an AWT frame and using the AWT functionality for JFreeChart. The way to do this is by creating a composite ``` Composite comp = new Composite(parent, SWT.NONE | S...
22,836
<p>In Perl, what is a good way to perform a replacement on a string using a regular expression and store the value in a different variable, without changing the original?</p> <p>I usually just copy the string to a new variable then bind it to the <code>s///</code> regex that does the replacement on the new string, but...
[ { "answer_id": 22896, "author": "John Siracusa", "author_id": 164, "author_profile": "https://Stackoverflow.com/users/164", "pm_score": 9, "selected": true, "text": "<p>This is the idiom I've always used to get a modified copy of a string without changing the original:</p>\n<pre><code>(m...
2008/08/22
[ "https://Stackoverflow.com/questions/22836", "https://Stackoverflow.com", "https://Stackoverflow.com/users/277/" ]
In Perl, what is a good way to perform a replacement on a string using a regular expression and store the value in a different variable, without changing the original? I usually just copy the string to a new variable then bind it to the `s///` regex that does the replacement on the new string, but I was wondering if t...
This is the idiom I've always used to get a modified copy of a string without changing the original: ``` (my $newstring = $oldstring) =~ s/foo/bar/g; ``` In perl 5.14.0 or later, you can use the new `/r` [non-destructive substitution modifier](https://metacpan.org/pod/release/FLORA/perl-5.14.2/pod/perl5140delta.pod#...
22,879
<p>I'm able to connect to and read an excel file no problem. But when importing data such as zipcodes that have leading zeros, how do you prevent excel from guessing the datatype and in the process stripping out leading zeros?</p>
[ { "answer_id": 22891, "author": "Stu", "author_id": 414, "author_profile": "https://Stackoverflow.com/users/414", "pm_score": 1, "selected": false, "text": "<p>Prefix with '</p>\n" }, { "answer_id": 22897, "author": "Owen", "author_id": 2109, "author_profile": "https:...
2008/08/22
[ "https://Stackoverflow.com/questions/22879", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1874/" ]
I'm able to connect to and read an excel file no problem. But when importing data such as zipcodes that have leading zeros, how do you prevent excel from guessing the datatype and in the process stripping out leading zeros?
I believe you have to set the option in your connect string to force textual import rather than auto-detecting it. ``` Provider=Microsoft.ACE.OLEDB.12.0; Data Source=c:\path\to\myfile.xlsx; Extended Properties=\"Excel 12.0 Xml;IMEX=1\"; ``` Your milage may vary depending on the version you have installed. Th...
22,935
<p>Does anyone have a technique for generating SQL table create (and data insert) commands pragmatically from a CSV (or sheet in a .xls) file? </p> <p>I've got a third party database system which I'd like to populate with data from a csv file (or sheet in a xls file) but the importer supplied can't create the table s...
[ { "answer_id": 22948, "author": "SQLMenace", "author_id": 740, "author_profile": "https://Stackoverflow.com/users/740", "pm_score": 2, "selected": true, "text": "<p>In SQL server it is as easy as</p>\n\n<pre><code>SELECT * INTO NewTablenNmeHere\nFROM OPENROWSET( 'Microsoft.Jet.OLEDB.4.0'...
2008/08/22
[ "https://Stackoverflow.com/questions/22935", "https://Stackoverflow.com", "https://Stackoverflow.com/users/39040/" ]
Does anyone have a technique for generating SQL table create (and data insert) commands pragmatically from a CSV (or sheet in a .xls) file? I've got a third party database system which I'd like to populate with data from a csv file (or sheet in a xls file) but the importer supplied can't create the table structure au...
In SQL server it is as easy as ``` SELECT * INTO NewTablenNmeHere FROM OPENROWSET( 'Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=C:\testing.xls','SELECT * FROM [Sheet1$]') ```
22,976
<p>I've got a JavaScript "object", built this way:</p> <pre><code>function foo() { this.length = 0; } foo.prototype.getLength = function() { return this.length; } ... </code></pre> <p>I know how to emulate namespaces with singleton JavaScript objects, but what is the best way to "namepace" an object such as...
[ { "answer_id": 22998, "author": "Nickolay", "author_id": 1026, "author_profile": "https://Stackoverflow.com/users/1026", "pm_score": 2, "selected": false, "text": "<p>Shouldn't be much different:</p>\n\n<pre><code>namespace.foo = function foo() {...}\nnamespace.foo.prototype.getLength = ...
2008/08/22
[ "https://Stackoverflow.com/questions/22976", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2536/" ]
I've got a JavaScript "object", built this way: ``` function foo() { this.length = 0; } foo.prototype.getLength = function() { return this.length; } ... ``` I know how to emulate namespaces with singleton JavaScript objects, but what is the best way to "namepace" an object such as that above that will inta...
Simple: ``` if(!MyNamespace) MyNamespace = {}; MyNamespace.foo = function() { this.length = 0; }; MyNamespace.foo.prototype.getLength = function() { return this.length; }; ```
23,027
<p>While setting up CruiseControl, I added a buildpublisher block to the publisher tasks:</p> <pre><code>&lt;buildpublisher&gt; &lt;sourceDir&gt;C:\MyBuild\&lt;/sourceDir&gt; &lt;publishDir&gt;C:\MyBuildPublished\&lt;/publishDir&gt; &lt;alwaysPublish&gt;false&lt;/alwaysPublish&gt; &lt;/buildpublisher&gt; </code...
[ { "answer_id": 23060, "author": "TheSmurf", "author_id": 1975282, "author_profile": "https://Stackoverflow.com/users/1975282", "pm_score": 3, "selected": true, "text": "<p>I set up a task to do this. I'm not aware of any way to make CruiseControl be that specific. I usually just chain a ...
2008/08/22
[ "https://Stackoverflow.com/questions/23027", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1965/" ]
While setting up CruiseControl, I added a buildpublisher block to the publisher tasks: ``` <buildpublisher> <sourceDir>C:\MyBuild\</sourceDir> <publishDir>C:\MyBuildPublished\</publishDir> <alwaysPublish>false</alwaysPublish> </buildpublisher> ``` This works, but it copies the entire file contents of the buil...
I set up a task to do this. I'm not aware of any way to make CruiseControl be that specific. I usually just chain a batch file to do the copy to the CC.net task.
23,064
<p>I'm creating an application that will store a hierarchical collection of items in an XML file and I'm wondering about the industry standard for storing collections in XML. Which of the following two formats is preferred? (If there is another option I'm not seeing, please advise.)</p> <p><strong>Option A</strong></p...
[ { "answer_id": 23067, "author": "Thomas Owens", "author_id": 572, "author_profile": "https://Stackoverflow.com/users/572", "pm_score": 3, "selected": true, "text": "<p>I'm no XML expert, but I find Option B to be more human readable, and I think it's just as machine readable as Option A....
2008/08/22
[ "https://Stackoverflow.com/questions/23064", "https://Stackoverflow.com", "https://Stackoverflow.com/users/317/" ]
I'm creating an application that will store a hierarchical collection of items in an XML file and I'm wondering about the industry standard for storing collections in XML. Which of the following two formats is preferred? (If there is another option I'm not seeing, please advise.) **Option A** ``` <School> <Studen...
I'm no XML expert, but I find Option B to be more human readable, and I think it's just as machine readable as Option A. I believe that XML is designed to be both human and machine readable, so I would go for Option B myself. --- I just realized something else after Ryan Farley's post. If the Students or Classes sect...
23,083
<p>In the Windows applications I work on, we have a custom framework that sits directly above Win32 (don't ask). When we create a window, our normal practice is to put <code>this</code> in the window's user data area via <code>SetWindowLong(hwnd, GWL_USERDATA, this)</code>, which allows us to have an MFC-like callback...
[ { "answer_id": 23101, "author": "Chris", "author_id": 2134, "author_profile": "https://Stackoverflow.com/users/2134", "pm_score": 6, "selected": true, "text": "<p><a href=\"http://msdn.microsoft.com/en-us/library/ms644898%28VS.85%29.aspx\" rel=\"noreferrer\">SetWindowLongPtr</a> was crea...
2008/08/22
[ "https://Stackoverflow.com/questions/23083", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2354/" ]
In the Windows applications I work on, we have a custom framework that sits directly above Win32 (don't ask). When we create a window, our normal practice is to put `this` in the window's user data area via `SetWindowLong(hwnd, GWL_USERDATA, this)`, which allows us to have an MFC-like callback or a tightly integrated `...
[SetWindowLongPtr](http://msdn.microsoft.com/en-us/library/ms644898%28VS.85%29.aspx) was created to replace [SetWindowLong](http://msdn.microsoft.com/en-us/library/ms633591%28VS.85%29.aspx) in these instances. It's LONG\_PTR parameter allows you to store a pointer for 32-bit or 64-bit compilations. ``` LONG_PTR SetWin...
23,094
<p>What's the best way to handle a user going back to a page that had cached items in an asp.net app? Is there a good way to capture the back button (event?) and handle the cache that way?</p>
[ { "answer_id": 23104, "author": "TheSmurf", "author_id": 1975282, "author_profile": "https://Stackoverflow.com/users/1975282", "pm_score": 0, "selected": false, "text": "<p>The best way to deal with it is to probably put a no-cache directive in your ASP.NET pages (or a master page if you...
2008/08/22
[ "https://Stackoverflow.com/questions/23094", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1874/" ]
What's the best way to handle a user going back to a page that had cached items in an asp.net app? Is there a good way to capture the back button (event?) and handle the cache that way?
You can try using the [HttpResponse.Cache property](http://msdn.microsoft.com/en-us/library/system.web.httpresponse.cache.aspx) if that would help: ``` Response.Cache.SetExpires(DateTime.Now.AddSeconds(60)); Response.Cache.SetCacheability(HttpCacheability.Public); Response.Cache.SetValidUntilExpires(false); Response.C...
23,124
<p>As the title mentions, I have a timeout callback handler on an ajax call, and I want to be able to test that condition but nothing is coming to mind immediately on ways I can force my application to hit that state, any suggestions?</p>
[ { "answer_id": 23131, "author": "Andy", "author_id": 1993, "author_profile": "https://Stackoverflow.com/users/1993", "pm_score": 2, "selected": false, "text": "<p>You could always run a server-side script that keeps running for a period of time. \nFor example:</p>\n\n<pre><code>&lt;?php\...
2008/08/22
[ "https://Stackoverflow.com/questions/23124", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2272/" ]
As the title mentions, I have a timeout callback handler on an ajax call, and I want to be able to test that condition but nothing is coming to mind immediately on ways I can force my application to hit that state, any suggestions?
First off, I think you need to be clearer in your question - what technology are you using and where is this process that is timing out - server-side or client-side? If you want to have the server-side code take a long time and you are using .NET, place this line in the method you call server-side: ``` System.Threadi...
23,169
<p>When using Groovy <code>MarkupBuilder</code>, I have places where I need to output text into the document, or call a function which outputs text into the document. Currently, I'm using the undefined tag <em>"text"</em> to do the output. Is there a better way to write this code?</p> <pre><code>li { text("${type.g...
[ { "answer_id": 23734, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "<p>Include a method:</p>\n\n<pre><code>void text(n){\n builder.yield n\n}\n</code></pre>\n\n<p>Most likely you (I) copied th...
2008/08/22
[ "https://Stackoverflow.com/questions/23169", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
When using Groovy `MarkupBuilder`, I have places where I need to output text into the document, or call a function which outputs text into the document. Currently, I'm using the undefined tag *"text"* to do the output. Is there a better way to write this code? ``` li { text("${type.getAlias()} blah blah ") functio...
Actually, the recommended way now is to use `mkp.yield`, e.g., ``` src.p { mkp.yield 'Some element that has a ' strong 'child element' mkp.yield ' which seems pretty basic.' } ``` to produce ``` <p>Some element that has a <strong>child element</strong> which seems pretty basic.</p> ```
23,175
<p>This is mostly geared toward desktop application developers. <br />How do I design a caching block which plays nicely with the GC? <br />How do I tell the GC that I have just done a cache sweep and it is time to do a GC? <br />How do I get an accurate measure of when it is time to do a cache sweep?</p> <p>Are th...
[ { "answer_id": 23734, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "<p>Include a method:</p>\n\n<pre><code>void text(n){\n builder.yield n\n}\n</code></pre>\n\n<p>Most likely you (I) copied th...
2008/08/22
[ "https://Stackoverflow.com/questions/23175", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1490/" ]
This is mostly geared toward desktop application developers. How do I design a caching block which plays nicely with the GC? How do I tell the GC that I have just done a cache sweep and it is time to do a GC? How do I get an accurate measure of when it is time to do a cache sweep? Are there any prebuilt cachi...
Actually, the recommended way now is to use `mkp.yield`, e.g., ``` src.p { mkp.yield 'Some element that has a ' strong 'child element' mkp.yield ' which seems pretty basic.' } ``` to produce ``` <p>Some element that has a <strong>child element</strong> which seems pretty basic.</p> ```
23,178
<p>Is there a .NET variable that returns the "All Users" directory?</p>
[ { "answer_id": 23194, "author": "Kibbee", "author_id": 1862, "author_profile": "https://Stackoverflow.com/users/1862", "pm_score": 4, "selected": true, "text": "<p>You'll want to use the <code>system.environment</code> variables.<br>\nMost of the predefined ones are <a href=\"http://msdn...
2008/08/22
[ "https://Stackoverflow.com/questions/23178", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1632/" ]
Is there a .NET variable that returns the "All Users" directory?
You'll want to use the `system.environment` variables. Most of the predefined ones are [shown here](http://msdn.microsoft.com/en-us/library/system.environment.getenvironmentvariable.aspx). For the "**All Users**" you would use: ``` System.Environment.GetEnvironmentVariable("ALLUSERSPROFILE") ``` I know I got a ...
23,190
<p>I am working on a function to establish the entropy of a distribution. It uses a copula, if any are familiar with that. I need to sum up the values in the array based on which dimensions are &quot;cared about.&quot;</p> <p>Example: Consider the following example...</p> <pre> Dimension 0 (across) _ _ _ _ _ _ _ _ _...
[ { "answer_id": 23196, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 0, "selected": false, "text": "<p>Actually, by colllapsing the colums you already summed them, so the dimension doesn't matter at all for your exampl...
2008/08/22
[ "https://Stackoverflow.com/questions/23190", "https://Stackoverflow.com", "https://Stackoverflow.com/users/522/" ]
I am working on a function to establish the entropy of a distribution. It uses a copula, if any are familiar with that. I need to sum up the values in the array based on which dimensions are "cared about." Example: Consider the following example... ``` Dimension 0 (across) _ _ _ _ _ _ _ _ _ _ _ _ _ |_ 0 _|_ 0 _|_ 0 ...
This could have applications. Lets say you implemented a 2D Conway's Game of Life (which defines a 2D plane, 1 for 'alive', 0 for 'dead') and you stored the Games history for every iteration (which then defines a 3D cube). If you wanted to know how many bacteria there was alive over history, you would use the above alg...
23,197
<p>I have a library that reads/writes to a USB-device using CreateFile() API. The device happens to implement the HID-device profile, such that it's compatible with Microsoft's HID class driver.</p> <p>Some other application installed on the system is opening the device in read/write mode with no share mode. Which pre...
[ { "answer_id": 23219, "author": "Eric Z Beard", "author_id": 1219, "author_profile": "https://Stackoverflow.com/users/1219", "pm_score": 1, "selected": false, "text": "<p>This is what I use to read from a Magtek card reader:</p>\n\n<pre><code>//Open file on the device\ndeviceHandle = \n ...
2008/08/22
[ "https://Stackoverflow.com/questions/23197", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2146/" ]
I have a library that reads/writes to a USB-device using CreateFile() API. The device happens to implement the HID-device profile, such that it's compatible with Microsoft's HID class driver. Some other application installed on the system is opening the device in read/write mode with no share mode. Which prevents my l...
Have you tried the tool called [handle](http://technet.microsoft.com/en-us/sysinternals/bb896655.aspx) from sysinternals? Anyway, neither windows does this (display the name of the application that locked the device): when you try to eject an USB device, Windows just says that the device is currently in use and cannot...
23,209
<p>I'm building an application against some legacy, third party libraries, and having problems with the linking stage. I'm trying to compile with Visual Studio 9. My compile command is:</p> <pre><code>cl -DNT40 -DPOMDLL -DCRTAPI1=_cdecl -DCRTAPI2=cdecl -D_WIN32 -DWIN32 -DWIN32_LEAN_AND_MEAN -DWNT -DBYPASS_FLEX -D_IN...
[ { "answer_id": 23212, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 2, "selected": false, "text": "<p>These are standard library references. Make sure that all libraries (including the standard library) are using the ...
2008/08/22
[ "https://Stackoverflow.com/questions/23209", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1322/" ]
I'm building an application against some legacy, third party libraries, and having problems with the linking stage. I'm trying to compile with Visual Studio 9. My compile command is: ``` cl -DNT40 -DPOMDLL -DCRTAPI1=_cdecl -DCRTAPI2=cdecl -D_WIN32 -DWIN32 -DWIN32_LEAN_AND_MEAN -DWNT -DBYPASS_FLEX -D_INTEL=1 -DIPLIB=no...
After trying to get this stuff to compile under VS 2008, I tried earlier versions of VS - 2005 worked with warnings, and 2003 just worked. I double checked the linkages and couldn't find any problems, so either I just couldn't find it, or that wasn't the problem. So to reiterate, downgrading to VS 2003 fixed it.
23,217
<p>I've been making a concerted effort to improve my javascript skills lately by reading as much javascript code as I can. In doing this I've sometimes seen the <code>javascript:</code> prefix appended to the front of event handler attributes in HTML element tags. What's the purpose of this prefix? Basically, is there ...
[ { "answer_id": 23222, "author": "TheSmurf", "author_id": 1975282, "author_profile": "https://Stackoverflow.com/users/1975282", "pm_score": 5, "selected": true, "text": "<p>Probably nothing in your example. My understanding is that <code>javascript:</code> is for anchor tags (in place of ...
2008/08/22
[ "https://Stackoverflow.com/questions/23217", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1680/" ]
I've been making a concerted effort to improve my javascript skills lately by reading as much javascript code as I can. In doing this I've sometimes seen the `javascript:` prefix appended to the front of event handler attributes in HTML element tags. What's the purpose of this prefix? Basically, is there any appreciabl...
Probably nothing in your example. My understanding is that `javascript:` is for anchor tags (in place of an actual `href`). You'd use it so that your script can execute when the user clicks the link, but without initiating a navigation back to the page (which a blank `href` coupled with an `onclick` will do). For exam...
23,228
<p>Compare</p> <pre><code>String.Format("Hello {0}", "World"); </code></pre> <p>with</p> <pre><code>"Hello {0}".Format("World"); </code></pre> <p>Why did the .Net designers choose a static method over an instance method? What do you think?</p>
[ { "answer_id": 23234, "author": "Thomas Owens", "author_id": 572, "author_profile": "https://Stackoverflow.com/users/572", "pm_score": 3, "selected": false, "text": "<p>I think it's because it's a creator method (not sure if there's a better name). All it does is take what you give it an...
2008/08/22
[ "https://Stackoverflow.com/questions/23228", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2361/" ]
Compare ``` String.Format("Hello {0}", "World"); ``` with ``` "Hello {0}".Format("World"); ``` Why did the .Net designers choose a static method over an instance method? What do you think?
I don't actually know the answer but I suspect that it has something to do with the aspect of invoking methods on string literals directly. If I recall correctly (I didn't actually verify this because I don't have an old IDE handy), early versions of the C# IDE had trouble detecting method calls against string literal...
23,250
<p>I was curious about how other people use the <strong>this</strong> keyword. I tend to use it in constructors, but I may also use it throughout the class in other methods. Some examples:</p> <p>In a constructor:</p> <pre><code>public Light(Vector v) { this.dir = new Vector(v); } </code></pre> <p>Elsewhere</p> ...
[ { "answer_id": 23257, "author": "Thomas Owens", "author_id": 572, "author_profile": "https://Stackoverflow.com/users/572", "pm_score": 5, "selected": false, "text": "<p>I use it every time I refer to an instance variable, even if I don't need to. I think it makes the code more clear.</p>...
2008/08/22
[ "https://Stackoverflow.com/questions/23250", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2016/" ]
I was curious about how other people use the **this** keyword. I tend to use it in constructors, but I may also use it throughout the class in other methods. Some examples: In a constructor: ``` public Light(Vector v) { this.dir = new Vector(v); } ``` Elsewhere ``` public void SomeMethod() { Vector vec = n...
There are several usages of [this](http://msdn.microsoft.com/en-us/library/dk1507sz.aspx) keyword in C#. 1. [To qualify members hidden by similar name](http://msdn.microsoft.com/en-us/library/vstudio/dk1507sz%28v=vs.100%29.aspx) 2. [To have an object pass itself as a parameter to other methods](http://msdn.microsoft.c...
23,372
<p>What would be the best method for getting a custom element (that is using J2ME native Graphics) painted on LWUIT elements?</p> <p>The custom element is an implementation from mapping library, that paints it's content (for example Google map) to Graphics object. How would it be possible to paint the result directly ...
[ { "answer_id": 48945, "author": "John Meagher", "author_id": 3535, "author_profile": "https://Stackoverflow.com/users/3535", "pm_score": 0, "selected": false, "text": "<p>Based on the javadoc for LWUIT and J2ME and guessing that the custom J2ME class is a <a href=\"http://java.sun.com/ja...
2008/08/22
[ "https://Stackoverflow.com/questions/23372", "https://Stackoverflow.com", "https://Stackoverflow.com/users/706/" ]
What would be the best method for getting a custom element (that is using J2ME native Graphics) painted on LWUIT elements? The custom element is an implementation from mapping library, that paints it's content (for example Google map) to Graphics object. How would it be possible to paint the result directly on LWUIT e...
I do not think any hacking is necessary. You can subclass the LWTUI Component class and then you can pain whatever you want on to the graphic context of the component. You do not get the native lcdui.Graphics object but an object with a same interface that is easy to use. If you really need to pass a lcdui.Graphics to...
23,399
<p>I've got an interesting design question. I'm designing the security side of our project, to allow us to have different versions of the program for different costs and also to allow Manager-type users to grant or deny access to parts of the program to other users. Its going to web-based and hosted on our servers.</...
[ { "answer_id": 23413, "author": "Kibbee", "author_id": 1862, "author_profile": "https://Stackoverflow.com/users/1862", "pm_score": 1, "selected": false, "text": "<p>I would vote for Option B. If you go with Option A and the assumption that if a user exists, they can get in, then you'll ...
2008/08/22
[ "https://Stackoverflow.com/questions/23399", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1470/" ]
I've got an interesting design question. I'm designing the security side of our project, to allow us to have different versions of the program for different costs and also to allow Manager-type users to grant or deny access to parts of the program to other users. Its going to web-based and hosted on our servers. I'm u...
If it's only going to be Allow/Deny, then a simple linking table between Users and Resources would work fine. If there is an entry keyed to the User-Resource in the linking table, allow access. ``` UserResources ------------- UserId FK->Users ResourceId FK->Resources ``` and the sql would be something like ``` if ...
23,603
<p>I'm developing a library alongside several projects that use it, and I've found myself frequently modifying the library at the same time as a project (e.g., adding a function to the library and immediately using it in the project).<br> As a result, the project would no longer compile with previous versions of the li...
[ { "answer_id": 23624, "author": "thelsdj", "author_id": 163, "author_profile": "https://Stackoverflow.com/users/163", "pm_score": 0, "selected": false, "text": "<p>One option is to use a single subversion repository and check-in changes that effect both library and project at the same ti...
2008/08/22
[ "https://Stackoverflow.com/questions/23603", "https://Stackoverflow.com", "https://Stackoverflow.com/users/112/" ]
I'm developing a library alongside several projects that use it, and I've found myself frequently modifying the library at the same time as a project (e.g., adding a function to the library and immediately using it in the project). As a result, the project would no longer compile with previous versions of the librar...
I think if I were going to do this, I would use tags. It would be pretty easy to write a script that would tag both repositories with the same ID each time you upgraded the library and used it in the project. Then, if you need to roll back to a previous version, you just see what its most recent tag was, and roll the l...
23,610
<p>I'm looking for a way to find a the windows login associated with a specific group. I'm trying to add permissions to a tool that only allows names formatted like:</p> <pre><code>DOMAIN\USER DOMAIN\GROUP </code></pre> <p>I have a list of users in active directory format that I need to add:</p> <pre><code>ou=group...
[ { "answer_id": 23611, "author": "Michael Stum", "author_id": 91, "author_profile": "https://Stackoverflow.com/users/91", "pm_score": 0, "selected": false, "text": "<p>OU is an Organizational Unit (sort of like a Subfolder in Explorer), not a Group, Hence group1, 2 and 3 are not actually ...
2008/08/22
[ "https://Stackoverflow.com/questions/23610", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1580/" ]
I'm looking for a way to find a the windows login associated with a specific group. I'm trying to add permissions to a tool that only allows names formatted like: ``` DOMAIN\USER DOMAIN\GROUP ``` I have a list of users in active directory format that I need to add: ``` ou=group1;ou=group2;ou=group3 ``` I have tr...
Programatically or Manually? Manually, i prefer [AdExplorer](http://technet.microsoft.com/en-us/sysinternals/bb963907.aspx), which is a nice Active directory Browser. You just connect to your domain controller and then you can look for the user and see all the details. Of course, you need permissions on the Domain Con...
23,620
<p>I'm using TinyMCE in an ASP.Net project, and I need a spell check. The only TinyMCE plugins I've found use PHP on the server side, and I guess I could just break down and install PHP on my server and do that, but quite frankly, what a pain. I don't want to do that.</p> <p>As it turns out, Firefox's built-in spell c...
[ { "answer_id": 23655, "author": "Espo", "author_id": 2257, "author_profile": "https://Stackoverflow.com/users/2257", "pm_score": 0, "selected": false, "text": "<p>I know at least <a href=\"http://developer.yahoo.com/yui/editor/\" rel=\"nofollow noreferrer\">yahoo!'s Rich Text Editor</a> ...
2008/08/22
[ "https://Stackoverflow.com/questions/23620", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2527/" ]
I'm using TinyMCE in an ASP.Net project, and I need a spell check. The only TinyMCE plugins I've found use PHP on the server side, and I guess I could just break down and install PHP on my server and do that, but quite frankly, what a pain. I don't want to do that. As it turns out, Firefox's built-in spell check will ...
TinyMCE only goes out of its way to disable spell-checking when you don't specify the `gecko_spellcheck` option (i verified this with their example code). Might want to double-check your `tinyMCE.init()` call - it should look something like this: ``` tinyMCE.init({ mode : "textareas", theme : "simple", gec...
23,715
<p>Has anyone had any success running two different web servers -- such as Apache and CherryPy -- alongside each other on the same machine? I am experimenting with other web servers right now, and I'd like to see if I can do my experiments while keeping my other sites up and running. You could say that this isn't so ...
[ { "answer_id": 23718, "author": "Ishmaeel", "author_id": 227, "author_profile": "https://Stackoverflow.com/users/227", "pm_score": 0, "selected": false, "text": "<p>Your best bet would be putting Apache httpd in front of port 80 and relay requests meant for other servers through Apache b...
2008/08/22
[ "https://Stackoverflow.com/questions/23715", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2321/" ]
Has anyone had any success running two different web servers -- such as Apache and CherryPy -- alongside each other on the same machine? I am experimenting with other web servers right now, and I'd like to see if I can do my experiments while keeping my other sites up and running. You could say that this isn't so much ...
You can't have two processes bound to the same port on the same IP address. You can add another IP address to the box and have each server listen on one. Another option is to proxy pass one server to the other. With Apache, you could do something like: ``` NameVirtualHost * <virtualhost *> ServerName other.site.com...
23,755
<p>When implementing a needle search of a haystack in an object-oriented way, you essentially have three alternatives:</p> <pre><code>1. needle.find(haystack) 2. haystack.find(needle) 3. searcher.find(needle, haystack)</code></pre> <p>Which do you prefer, and why?</p> <p>I know some people prefer the second altern...
[ { "answer_id": 23756, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 3, "selected": false, "text": "<p>This entirely depends on what varies and what stays the same.</p>\n\n<p>For example, I am working on a (non-OOP) <a...
2008/08/22
[ "https://Stackoverflow.com/questions/23755", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1709/" ]
When implementing a needle search of a haystack in an object-oriented way, you essentially have three alternatives: ``` 1. needle.find(haystack) 2. haystack.find(needle) 3. searcher.find(needle, haystack) ``` Which do you prefer, and why? I know some people prefer the second alternative because it avoids introduci...
Usually actions should be applied to what you are doing the action on... in this case the haystack, so I think option 2 is the most appropriate. You also have a fourth alternative that I think would be better than alternative 3: ``` haystack.find(needle, searcher) ``` In this case, it allows you to provide the mann...
23,763
<p>I'm working on some code to colorize an image in Java. Basically what I'd like to do is something along the lines of GIMP's colorize command, so that if I have a BufferedImage and a Color, I can colorize the Image with the given color. Anyone got any ideas? My current best guess at doing something like this is to ge...
[ { "answer_id": 23795, "author": "Nick", "author_id": 1490, "author_profile": "https://Stackoverflow.com/users/1490", "pm_score": 3, "selected": false, "text": "<p>Let <code>Y = 0.3*R + 0.59*G + 0.11*B</code> for each pixel in the image, then set them to be</p>\n\n<p><code>((R1+Y)/2,(G1+Y...
2008/08/22
[ "https://Stackoverflow.com/questions/23763", "https://Stackoverflow.com", "https://Stackoverflow.com/users/85/" ]
I'm working on some code to colorize an image in Java. Basically what I'd like to do is something along the lines of GIMP's colorize command, so that if I have a BufferedImage and a Color, I can colorize the Image with the given color. Anyone got any ideas? My current best guess at doing something like this is to get t...
I have never used GIMP's colorize command. However, if your getting the RGB value of each pixel and adding RGB value to it you should really use a **[LookupOp](http://docs.oracle.com/javase/7/docs/api/java/awt/image/LookupOp.html).** Here is some code that I wrote to apply a BufferedImageOp to a BufferedImage. Using N...
23,787
<p>What is the best way to find something in a list? I know LINQ has some nice tricks, but let's also get suggestions for C# 2.0. Lets get the best refactorings for this common code pattern.</p> <p>Currently I use code like this:</p> <pre><code>// mObjList is a List&lt;MyObject&gt; MyObject match = null; foreach (M...
[ { "answer_id": 23794, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 1, "selected": false, "text": "<p>Put the code in a method and you save a temporary and a <code>break</code> (and you recycle code, as a bonus):</p>\...
2008/08/23
[ "https://Stackoverflow.com/questions/23787", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1490/" ]
What is the best way to find something in a list? I know LINQ has some nice tricks, but let's also get suggestions for C# 2.0. Lets get the best refactorings for this common code pattern. Currently I use code like this: ``` // mObjList is a List<MyObject> MyObject match = null; foreach (MyObject mo in mObjList) { ...
> > @ Konrad: So how do you use it? Let's say I want to match mo.ID to magicNumber. > > > In C# 2.0 you'd write: ``` result = mObjList.Find(delegate(int x) { return x.ID == magicNumber; }); ``` 3.0 knows lambdas: ``` result = mObjList.Find(x => x.ID == magicNumber); ```