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
188,184
<p>Here I have:</p> <pre><code>Public Structure MyStruct Public Name as String Public Content as String End Structure Dim oStruct as MyStruct = New MyStruct() oStruct.Name = ... oStruct.Content = ... Dim alList as ArrayList = new ArrayList() alList.Add(oStruct) </code></pre> <p>I'd like to convert the ArrayLi...
[ { "answer_id": 188196, "author": "Bill the Lizard", "author_id": 1288, "author_profile": "https://Stackoverflow.com/users/1288", "pm_score": 2, "selected": false, "text": "<p>You have to cast the result of <code>ToArray</code></p>\n\n<pre><code>MyStruct[] structs = (MyStruct[]) alList.To...
2008/10/09
[ "https://Stackoverflow.com/questions/188184", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1508/" ]
Here I have: ``` Public Structure MyStruct Public Name as String Public Content as String End Structure Dim oStruct as MyStruct = New MyStruct() oStruct.Name = ... oStruct.Content = ... Dim alList as ArrayList = new ArrayList() alList.Add(oStruct) ``` I'd like to convert the ArrayList to a static strongly-ty...
I assume that since you are using ArrayList, you are using 1.1? In which case, I suspect the following would work: ``` ArrayList list = new ArrayList(); MyStruct[] array = new MyStruct[list.Count]; list.CopyTo(array); ``` (edit - Bill's ToArray usage is more convenient - I didn't know about that one, but then, I v...
188,188
<p>We recently upgraded an application that that contained web services using the WSE 2.0 to .NET 3.5. When we converted the project in Visual Studio 2008, It did not mention anything about the removing and/or modifying the WSE 2.0 namespaces. Here is the basic architecture of the web services in the .NET 1.1 project...
[ { "answer_id": 198808, "author": "Ricardo Villamil", "author_id": 19314, "author_profile": "https://Stackoverflow.com/users/19314", "pm_score": 0, "selected": false, "text": "<p>the biggest problem I've found is in Javascript that had hardcoded the names of some of my server controls. i...
2008/10/09
[ "https://Stackoverflow.com/questions/188188", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26327/" ]
We recently upgraded an application that that contained web services using the WSE 2.0 to .NET 3.5. When we converted the project in Visual Studio 2008, It did not mention anything about the removing and/or modifying the WSE 2.0 namespaces. Here is the basic architecture of the web services in the .NET 1.1 project. We...
As I [answered](https://stackoverflow.com/questions/185420/issues-with-client-consuming-a-net-web-service-upgraded-from-net-11-to-35#198806) to the original question: WCF (.net 3.5) is said to be compatible with WSE3 (.net 2.0+), but not with WSE2 (.net 1.1+). So if you don't want to change the client, but want it to...
188,208
<p>There seem to be two bash idioms for redirecting STDOUT and STDERR to a file:</p> <pre><code>fooscript &amp;&gt; foo </code></pre> <p>... and ...</p> <pre><code>fooscript &gt; foo 2&gt;&amp;1 </code></pre> <p>What's the difference? It seems to me that the first one is just a shortcut for the second one, but my ...
[ { "answer_id": 188217, "author": "J.J.", "author_id": 21204, "author_profile": "https://Stackoverflow.com/users/21204", "pm_score": 1, "selected": false, "text": "<pre><code>&amp;&gt; foo # Will take all and redirect all output to foo.\n\n2&gt;&amp;1 # will redirect stderr to stdout.\n</...
2008/10/09
[ "https://Stackoverflow.com/questions/188208", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16034/" ]
There seem to be two bash idioms for redirecting STDOUT and STDERR to a file: ``` fooscript &> foo ``` ... and ... ``` fooscript > foo 2>&1 ``` What's the difference? It seems to me that the first one is just a shortcut for the second one, but my coworker contends that the second one will produce no output even i...
From the [bash manual](http://www.gnu.org/software/bash/manual/bashref.html#Redirections): > > There are two formats for redirecting standard output and standard error: > > > > ``` > &>word > > ``` > > and > > > > ``` > >&word > > ``` > > Of the two forms, the first is preferred. This is semantically equiva...
188,225
<p>I use Visual C++ 2008 in Visual Studio 2008. I frequently use the following command to diff an open file against its most recent checked-in version:</p> <pre><code>File | Source Control | Compare... </code></pre> <p>I can also do the same thing by clicking on an icon in the Source Control toolbar.</p> <p>I'm not...
[ { "answer_id": 188256, "author": "Nescio", "author_id": 14484, "author_profile": "https://Stackoverflow.com/users/14484", "pm_score": 3, "selected": true, "text": "<p>Tools -> Options -> Keyboard -> Commands Containing \"Compare\"</p>\n" }, { "answer_id": 188528, "author": "j...
2008/10/09
[ "https://Stackoverflow.com/questions/188225", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10559/" ]
I use Visual C++ 2008 in Visual Studio 2008. I frequently use the following command to diff an open file against its most recent checked-in version: ``` File | Source Control | Compare... ``` I can also do the same thing by clicking on an icon in the Source Control toolbar. I'm not certain, but I believe this comma...
Tools -> Options -> Keyboard -> Commands Containing "Compare"
188,241
<p>If I want to have a case-insensitive string-keyed dictionary, which version of StringComparer should I use given these constraints:</p> <ul> <li>The keys in the dictionary come from either C# code or config files written in english locale only (either US, or UK)</li> <li>The software is internationalized and will r...
[ { "answer_id": 188264, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 1, "selected": false, "text": "<p>Since the keys are your known fixed values, then either InvariantCultureIgnoreCase or OrdinalIgnoreCase should wor...
2008/10/09
[ "https://Stackoverflow.com/questions/188241", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16501/" ]
If I want to have a case-insensitive string-keyed dictionary, which version of StringComparer should I use given these constraints: * The keys in the dictionary come from either C# code or config files written in english locale only (either US, or UK) * The software is internationalized and will run in different local...
[This MSDN article](http://msdn.microsoft.com/en-us/library/ms973919.aspx#stringsinnet20_topic4) covers everything you could possibly want to know in great depth, including the Turkish-I problem. It's been a while since I read it, so I'm off to do so again. See you in an hour!
188,250
<p>I believe there is a discussion on this very topic somewhere on the net but I lost the url and I am unable to find it via googling.</p> <p>What I might try right now would be:</p> <pre><code>ISessionFactoryHolder factoryHolder = ActiveRecordMediator&lt;EntityClass&gt;.GetSessionFactoryHolder(); ISession session = ...
[ { "answer_id": 301079, "author": "okcodemonkey", "author_id": 38825, "author_profile": "https://Stackoverflow.com/users/38825", "pm_score": 1, "selected": false, "text": "<p>The blog I used when implementing stored procedures in my ActiveRecord code was this post by Rodj (<a href=\"http:...
2008/10/09
[ "https://Stackoverflow.com/questions/188250", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15396/" ]
I believe there is a discussion on this very topic somewhere on the net but I lost the url and I am unable to find it via googling. What I might try right now would be: ``` ISessionFactoryHolder factoryHolder = ActiveRecordMediator<EntityClass>.GetSessionFactoryHolder(); ISession session = factoryHolder.CreateSession...
This works for me (stored procedure with params and dynamic result table): ``` // get Connection System.Data.IDbConnection con = ActiveRecordMediator.GetSessionFactoryHolder() .GetSessionFactory(typeof(Autocomplete)) ...
188,281
<p>In Delphi 2009 I'm finding that any time I use TThread.CurrentThread in an application, I'll get an error message like the following when the application closes:</p> <pre><code>Exception EAccessViolation in module ntdll.dll at 0003DBBA. Access violation at address 7799DBBA in module 'ntdll.dll'. Write of address 0...
[ { "answer_id": 188421, "author": "Toon Krijthe", "author_id": 18061, "author_profile": "https://Stackoverflow.com/users/18061", "pm_score": 0, "selected": false, "text": "<p>I think CurrentThread is added in 2009 (or 2007). I have 2006 at home. But are you sure it is a class property?</p...
2008/10/09
[ "https://Stackoverflow.com/questions/188281", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11961/" ]
In Delphi 2009 I'm finding that any time I use TThread.CurrentThread in an application, I'll get an error message like the following when the application closes: ``` Exception EAccessViolation in module ntdll.dll at 0003DBBA. Access violation at address 7799DBBA in module 'ntdll.dll'. Write of address 00000014. ``` ...
Unfortunately it seems like a bug linked to the call order of the finalization section in the Classes unit: `DoneThreadSynchronization` clears the `ThreadLock` structure, then `FreeExternalThreads` wants to destroy the Thread object you just created when calling `CurrentThread`, and that requires the ThreadLock...
188,299
<p>I have the following struct in C++:</p> <pre><code>#define MAXCHARS 15 typedef struct { char data[MAXCHARS]; int prob[MAXCHARS]; } LPRData; </code></pre> <p>And a function that I'm p/invoking into to get an array of 3 of these structures:</p> <pre><code>void GetData(LPRData *data); </code></pre> <p>In ...
[ { "answer_id": 188396, "author": "JaredPar", "author_id": 23283, "author_profile": "https://Stackoverflow.com/users/23283", "pm_score": 4, "selected": false, "text": "<p>One trick when dealing with pointers is to just use an IntPtr. You can then use Marshal.PtrToStructure on the pointer...
2008/10/09
[ "https://Stackoverflow.com/questions/188299", "https://Stackoverflow.com", "https://Stackoverflow.com/users/194/" ]
I have the following struct in C++: ``` #define MAXCHARS 15 typedef struct { char data[MAXCHARS]; int prob[MAXCHARS]; } LPRData; ``` And a function that I'm p/invoking into to get an array of 3 of these structures: ``` void GetData(LPRData *data); ``` In C++ I would just do something like this: ``` LPR...
I would try adding some attributes to your struct decloration ``` [StructLayout(LayoutKind.Sequential, Size=TotalBytesInStruct),Serializable] public struct LPRData { /// char[15] [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 15)] public string data; /// int[15] [MarshalAsAttribute(UnmanagedType.ByValArray,...
188,327
<p>My question is on the ASP.NET GridView control. I am using a CommandField in the Columns tag as seen below.</p> <pre><code>&lt;asp:CommandField ShowEditButton="True" HeaderStyle-Width="40px" UpdateText="Save" ButtonType="Link" HeaderStyle-Wrap="true" ItemStyle-Wrap="true" ItemStyle-Width="40px"/&gt; </code></pre> ...
[ { "answer_id": 188343, "author": "Bryant", "author_id": 10893, "author_profile": "https://Stackoverflow.com/users/10893", "pm_score": 0, "selected": false, "text": "<p>Don't use a command field, use a <a href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.templatefie...
2008/10/09
[ "https://Stackoverflow.com/questions/188327", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26573/" ]
My question is on the ASP.NET GridView control. I am using a CommandField in the Columns tag as seen below. ``` <asp:CommandField ShowEditButton="True" HeaderStyle-Width="40px" UpdateText="Save" ButtonType="Link" HeaderStyle-Wrap="true" ItemStyle-Wrap="true" ItemStyle-Width="40px"/> ``` What renders is the shown in ...
If you use a template field it will give you complete control over the look of your page, but it requires that you use the CommandName and possible CommandArgument properties, and also using the GridView's OnRowCommand. The aspx page: ``` <asp:GridView id="gvGrid" runat="server" OnRowCommand="gvGrid_Command"> <Colum...
188,334
<p>I'm attempting to create a custom calendar control that inherits from ASP.Net's built in calendar user control. </p> <p>the code-behind file for my control looks like this:</p> <pre><code>public partial class WeeklyEventsCalendar : Calendar { protected void Page_Load(object sender, EventArgs e) { } } ...
[ { "answer_id": 188402, "author": "Bryant", "author_id": 10893, "author_profile": "https://Stackoverflow.com/users/10893", "pm_score": 3, "selected": false, "text": "<p>I think the problem is that you're attempting to inherit the Calendar control (which is a server control) from a user co...
2008/10/09
[ "https://Stackoverflow.com/questions/188334", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17917/" ]
I'm attempting to create a custom calendar control that inherits from ASP.Net's built in calendar user control. the code-behind file for my control looks like this: ``` public partial class WeeklyEventsCalendar : Calendar { protected void Page_Load(object sender, EventArgs e) { } } ``` and compiles fi...
Bryant hit on it. One thing you might consider if all you're doing is customizing the existing control is embedding an instance of the calendar on your user control and exposing the properties you need from it. This way your user control can handle all of the requisite customizations, and also provide only a limited in...
188,349
<p>I need to knock out a quick animation in C#/Windows Forms for a Halloween display. Just some 2D shapes moving about on a solid background. Since this is just a quick one-off project I <strong><em>really</em></strong> don't want to install and learn an entire new set of tools for this. (DirectX dev kits, Silverlig...
[ { "answer_id": 188377, "author": "Nick", "author_id": 1490, "author_profile": "https://Stackoverflow.com/users/1490", "pm_score": 5, "selected": true, "text": "<p>Set off a timer at your desired frame rate. At each timer firing twiddle the internal representation of the shapes on the sc...
2008/10/09
[ "https://Stackoverflow.com/questions/188349", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8173/" ]
I need to knock out a quick animation in C#/Windows Forms for a Halloween display. Just some 2D shapes moving about on a solid background. Since this is just a quick one-off project I ***really*** don't want to install and learn an entire new set of tools for this. (DirectX dev kits, Silverlight, Flash, etc..) I also h...
Set off a timer at your desired frame rate. At each timer firing twiddle the internal representation of the shapes on the screen (your model) per the animation motion you want to achieve, then call `Invalidate(true)`. Inside the OnPaint just draw the model on the screen. Oh yeah, and you probably want to turn Double B...
188,366
<p>I am trying to run a query that will give time averages but when I do... some duplicate records are in the calculation. how can I remove duplicates?</p> <p>ex.</p> <p>Column 1 / 07-5794 / 07-5794 / 07-5766 / 07-8423 / 07-4259</p> <p>Column 2 / 00:59:59 / 00:48:22 / 00:42:48/ 00:51:47 ...
[ { "answer_id": 188380, "author": "Dave DuPlantis", "author_id": 8174, "author_profile": "https://Stackoverflow.com/users/8174", "pm_score": 1, "selected": false, "text": "<p>To get the average of the minimum values for each incnum, you could write this SQL</p>\n\n<pre><code>select avg(mi...
2008/10/09
[ "https://Stackoverflow.com/questions/188366", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I am trying to run a query that will give time averages but when I do... some duplicate records are in the calculation. how can I remove duplicates? ex. Column 1 / 07-5794 / 07-5794 / 07-5766 / 07-8423 / 07-4259 Column 2 / 00:59:59 / 00:48:22 / 00:42:48/ 00:51:47 / 00:52:12 I can get the average of the column 2 but...
To get the average of the minimum values for each incnum, you could write this SQL ``` select avg(min_time) as avg_time from (select incnum, min(col2) as min_time from inc group by incnum) ``` using the correct average function for your brand of SQL. If you're doing this in Access, you'll want to paste this int...
188,373
<p>I'd like to re-brand (and send error emails) for all of the SSRS default error pages (picture below) when you access reports via /ReportServer/. I'm already handling the ASP OnError event and <em>some</em> of the default SSRS errors appear to catch their own exceptions and then render this page cancel the response ...
[ { "answer_id": 188380, "author": "Dave DuPlantis", "author_id": 8174, "author_profile": "https://Stackoverflow.com/users/8174", "pm_score": 1, "selected": false, "text": "<p>To get the average of the minimum values for each incnum, you could write this SQL</p>\n\n<pre><code>select avg(mi...
2008/10/09
[ "https://Stackoverflow.com/questions/188373", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15050/" ]
I'd like to re-brand (and send error emails) for all of the SSRS default error pages (picture below) when you access reports via /ReportServer/. I'm already handling the ASP OnError event and *some* of the default SSRS errors appear to catch their own exceptions and then render this page cancel the response all before ...
To get the average of the minimum values for each incnum, you could write this SQL ``` select avg(min_time) as avg_time from (select incnum, min(col2) as min_time from inc group by incnum) ``` using the correct average function for your brand of SQL. If you're doing this in Access, you'll want to paste this int...
188,389
<p>I try to define a schema for XML documents I receive.</p> <p>The documents look like:</p> <pre><code>&lt;root&gt; &lt;items&gt; &lt;group name="G-1"&gt; &lt;item name="I-1"/&gt; &lt;item name="I-2"/&gt; &lt;item name="I-3"/&gt; &lt;item name="I-4"/&gt; ...
[ { "answer_id": 188430, "author": "Peter Meyer", "author_id": 1875, "author_profile": "https://Stackoverflow.com/users/1875", "pm_score": 3, "selected": true, "text": "<p>Yes, XSD can handle this. I generated this schema from Visual Studio 2008 (much faster than doing it by hand) and it ...
2008/10/09
[ "https://Stackoverflow.com/questions/188389", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23772/" ]
I try to define a schema for XML documents I receive. The documents look like: ``` <root> <items> <group name="G-1"> <item name="I-1"/> <item name="I-2"/> <item name="I-3"/> <item name="I-4"/> </group> </items> <data> <group name="G-1...
Yes, XSD can handle this. I generated this schema from Visual Studio 2008 (much faster than doing it by hand) and it will do what you're looking for: ``` <?xml version="1.0" encoding="utf-8"?> <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <x...
188,444
<p>Is it possible to read and write Word (2003 and 2007) files in Python without using a COM object?<br /> I know that I can:</p> <pre><code>f = open('c:\file.doc', "w") f.write(text) f.close() </code></pre> <p>but Word will read it as an HTML file not a native .doc file.</p>
[ { "answer_id": 188608, "author": "fuentesjr", "author_id": 10708, "author_profile": "https://Stackoverflow.com/users/10708", "pm_score": 2, "selected": false, "text": "<p>doc (Word 2003 in this case) and docx (Word 2007) are different formats, where the latter is usually just an archive ...
2008/10/09
[ "https://Stackoverflow.com/questions/188444", "https://Stackoverflow.com", "https://Stackoverflow.com/users/115/" ]
Is it possible to read and write Word (2003 and 2007) files in Python without using a COM object? I know that I can: ``` f = open('c:\file.doc', "w") f.write(text) f.close() ``` but Word will read it as an HTML file not a native .doc file.
I'd look into [IronPython](http://ironpython.net/) which intrinsically has access to windows/office APIs because it runs on .NET runtime.
188,452
<p>Is it possible to read and write Word (2003 and 2007) files in PHP without using a COM object? I know that I can:</p> <pre><code>$file = fopen('c:\file.doc', 'w+'); fwrite($file, $text); fclose(); </code></pre> <p>but Word will read it as an HTML file not a native .doc file.</p>
[ { "answer_id": 189683, "author": "Joe Lencioni", "author_id": 18986, "author_profile": "https://Stackoverflow.com/users/18986", "pm_score": 3, "selected": false, "text": "<p>I don't know about reading native Word documents in PHP, but if you want to write a Word document in PHP, <a href=...
2008/10/09
[ "https://Stackoverflow.com/questions/188452", "https://Stackoverflow.com", "https://Stackoverflow.com/users/115/" ]
Is it possible to read and write Word (2003 and 2007) files in PHP without using a COM object? I know that I can: ``` $file = fopen('c:\file.doc', 'w+'); fwrite($file, $text); fclose(); ``` but Word will read it as an HTML file not a native .doc file.
Reading binary Word documents would involve creating a parser according to the published file format specifications for the DOC format. I think this is no real feasible solution. You could use the [Microsoft Office XML formats](http://en.wikipedia.org/wiki/Microsoft_Office_XML_formats#Word_XML_Format_example) for read...
188,461
<p>For as long as I can remember I have avoided using switch statement fall-through. Actually, I can't remember it ever entering my consciousness as a possible way to do things as it was drilled into my head early on that it was nothing more than a bug in the switch statement. However, today I ran across some code that...
[ { "answer_id": 188477, "author": "Lucas Oman", "author_id": 6726, "author_profile": "https://Stackoverflow.com/users/6726", "pm_score": 5, "selected": false, "text": "<p>Fall-through is really a handy thing, depending on what you're doing. Consider this neat and understandable way to arr...
2008/10/09
[ "https://Stackoverflow.com/questions/188461", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16524/" ]
For as long as I can remember I have avoided using switch statement fall-through. Actually, I can't remember it ever entering my consciousness as a possible way to do things as it was drilled into my head early on that it was nothing more than a bug in the switch statement. However, today I ran across some code that us...
It may depend on what you consider fallthrough. I'm ok with this sort of thing: ```js switch (value) { case 0: result = ZERO_DIGIT; break; case 1: case 3: case 5: case 7: case 9: result = ODD_DIGIT; break; case 2: case 4: case 6: case 8: result = EVEN_DIGIT; break; } ...
188,473
<p>I have a C# object with a critical resource that needs to be flushed very specific points in time making it a bad candidate to leave around for the garbage collector to take care of whenever it gets around to it, how should I handle this? Is there something like C++'s delete operator that will let me manually kill...
[ { "answer_id": 188501, "author": "David", "author_id": 26144, "author_profile": "https://Stackoverflow.com/users/26144", "pm_score": 2, "selected": false, "text": "<p>This is precisely what the <a href=\"http://msdn.microsoft.com/en-us/library/system.idisposable.aspx\" rel=\"nofollow nor...
2008/10/09
[ "https://Stackoverflow.com/questions/188473", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have a C# object with a critical resource that needs to be flushed very specific points in time making it a bad candidate to leave around for the garbage collector to take care of whenever it gets around to it, how should I handle this? Is there something like C++'s delete operator that will let me manually kill the ...
You are looking for [`IDisposable`](http://msdn.microsoft.com/en-us/library/system.idisposable.aspx). Here is an example class that implements this. ``` class MyDisposableObject : IDisposable { public MyDisposableObject() { } ~MyDisposableObject() { Dispose(false); } private bool disposed;...
188,488
<p>The problem is following: I want to automate the way my emacs starts. It has to be split in two buffers and the slime-repl has to be started in the smallest (bottom) buffer. Plus, I want my file to be opened in the bigger (upper) buffer. In my .emacs there are lines:</p> <pre><code>(slime) ... (split-window-vertica...
[ { "answer_id": 188641, "author": "EfForEffort", "author_id": 14113, "author_profile": "https://Stackoverflow.com/users/14113", "pm_score": 0, "selected": false, "text": "<p>Try:</p>\n\n<pre><code>(other-window 1)\n(find-file \"g:/Private/pa/pa2.lsp\")\n</code></pre>\n\n<p>instead of your...
2008/10/09
[ "https://Stackoverflow.com/questions/188488", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20514/" ]
The problem is following: I want to automate the way my emacs starts. It has to be split in two buffers and the slime-repl has to be started in the smallest (bottom) buffer. Plus, I want my file to be opened in the bigger (upper) buffer. In my .emacs there are lines: ``` (slime) ... (split-window-vertically -6) (switc...
Instead of `switch-to-buffer`, use function `pop-to-buffer`. > > `(pop-to-buffer BUFFER-OR-NAME &optional OTHER-WINDOW NORECORD)` > > > Select buffer `BUFFER-OR-NAME` in some window, preferably a different one. > > >
188,503
<p>How do you detect the number of physical processors/cores in .net?</p>
[ { "answer_id": 188516, "author": "Tsvetomir Tsonev", "author_id": 25449, "author_profile": "https://Stackoverflow.com/users/25449", "pm_score": 2, "selected": false, "text": "<p>System.Environment.ProcessorCount is what you need</p>\n" }, { "answer_id": 188522, "author": "lig...
2008/10/09
[ "https://Stackoverflow.com/questions/188503", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1952/" ]
How do you detect the number of physical processors/cores in .net?
``` System.Environment.ProcessorCount ``` returns the number of logical processors > > <http://msdn.microsoft.com/en-us/library/system.environment.processorcount.aspx> > > > For physical processor count you'd probably need to use WMI - the following metadata is supported in XP/Win2k3 upwards (Functionality enab...
188,510
<p>I have a string "1112224444' it is a telephone number. I want to format as 111-222-4444 before I store it in a file. It is on a datarecord and I would prefer to be able to do this without assigning a new variable.</p> <p>I was thinking:</p> <pre><code>String.Format("{0:###-###-####}", i["MyPhone"].ToString() ); </...
[ { "answer_id": 188543, "author": "mattruma", "author_id": 1768, "author_profile": "https://Stackoverflow.com/users/1768", "pm_score": 5, "selected": false, "text": "<p>As far as I know you can't do this with string.Format ... you would have to handle this yourself. You could just strip ...
2008/10/09
[ "https://Stackoverflow.com/questions/188510", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3208/" ]
I have a string "1112224444' it is a telephone number. I want to format as 111-222-4444 before I store it in a file. It is on a datarecord and I would prefer to be able to do this without assigning a new variable. I was thinking: ``` String.Format("{0:###-###-####}", i["MyPhone"].ToString() ); ``` but that does not...
I prefer to use regular expressions: ``` Regex.Replace("1112224444", @"(\d{3})(\d{3})(\d{4})", "$1-$2-$3"); ```
188,532
<p>I want to make sure that a set of functions have the same signature in some C code. Ideally I would be able to define a new type that described the return value and arguments of a function and then declare my set of functions using this new type. </p> <p>Additionally, is there a way to specify default values for th...
[ { "answer_id": 188559, "author": "Michael Burr", "author_id": 12711, "author_profile": "https://Stackoverflow.com/users/12711", "pm_score": 5, "selected": true, "text": "<pre><code>/* define a typedef for function_t - functions that return void */\n/* and take an int and char param...
2008/10/09
[ "https://Stackoverflow.com/questions/188532", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26551/" ]
I want to make sure that a set of functions have the same signature in some C code. Ideally I would be able to define a new type that described the return value and arguments of a function and then declare my set of functions using this new type. Additionally, is there a way to specify default values for the argument...
``` /* define a typedef for function_t - functions that return void */ /* and take an int and char parameter */ typedef void function_t( int param1, char param2); /* declare some functions that use that signature */ function_t foo; function_t bar; ``` Now when you define the functions there will be an error ...
188,545
<p>I was looking for a way to remove text from and RTF string and I found the following regex:</p> <pre><code>({\\)(.+?)(})|(\\)(.+?)(\b) </code></pre> <p>However the resulting string has two right angle brackets "}"</p> <p><strong>Before:</strong> <code>{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fc...
[ { "answer_id": 188667, "author": "Paige Ruten", "author_id": 813, "author_profile": "https://Stackoverflow.com/users/813", "pm_score": 2, "selected": false, "text": "<p>According to <a href=\"http://regexpal.com\" rel=\"nofollow noreferrer\">RegexPal</a>, the two }'s are the ones bolded ...
2008/10/09
[ "https://Stackoverflow.com/questions/188545", "https://Stackoverflow.com", "https://Stackoverflow.com/users/324/" ]
I was looking for a way to remove text from and RTF string and I found the following regex: ``` ({\\)(.+?)(})|(\\)(.+?)(\b) ``` However the resulting string has two right angle brackets "}" **Before:** `{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 MS Shell Dlg 2;}{\f1\fnil MS Shell Dlg 2;}}...
In RTF, { and } marks a group. Groups can be nested. \ marks beginning of a control word. Control words end with either a space or a non alphabetic character. A control word can have a numeric parameter following, without any delimiter in between. Some control words also take text parameters, separated by ';'. Those co...
188,547
<p>Is it possible for Eclipse to read stdin from a file?</p>
[ { "answer_id": 188654, "author": "Michael Myers", "author_id": 13531, "author_profile": "https://Stackoverflow.com/users/13531", "pm_score": 6, "selected": false, "text": "<h3>Pure Java</h3>\n<p>You can redirect System.in with a single line of code:</p>\n<pre><code>System.setIn(new FileI...
2008/10/09
[ "https://Stackoverflow.com/questions/188547", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Is it possible for Eclipse to read stdin from a file?
### Pure Java You can redirect System.in with a single line of code: ``` System.setIn(new FileInputStream(filename)); ``` See [System.setIn()](http://docs.oracle.com/javase/8/docs/api/java/lang/System.html#setIn-java.io.InputStream-). ### Eclipse config In Eclipse 4.5 or later, the launch configuration dialog can...
188,569
<p>Just starting out in asp.net. Have just created a login.aspx page in my site and stuck on a asp login control - that's all I did. Now my Welcome.aspx page won't show as the start page of my site when I debug - even though it is set as this. Plus I have even edited my web.config - (see below) - and it still does the...
[ { "answer_id": 188577, "author": "Stephen Wrighton", "author_id": 7516, "author_profile": "https://Stackoverflow.com/users/7516", "pm_score": 2, "selected": false, "text": "<p>that's because you're accessing the site with a user that has not been authenticated-- so the framework is redir...
2008/10/09
[ "https://Stackoverflow.com/questions/188569", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5175/" ]
Just starting out in asp.net. Have just created a login.aspx page in my site and stuck on a asp login control - that's all I did. Now my Welcome.aspx page won't show as the start page of my site when I debug - even though it is set as this. Plus I have even edited my web.config - (see below) - and it still does the sam...
If you want users to access welcome.aspx without being authenticated, put welcome.aspx in a separate folder, and set up a new web.config in that sub folder. fill out the authorization section in that web.config so that the files in that folder and subfolders will be accessible by anonymous users, like this: ``` <autho...
188,584
<p>In c#, how can I check to see if a link button has been clicked in the page load method? </p> <p>I need to know if it was clicked before the click event is fired.</p>
[ { "answer_id": 188603, "author": "tvanfosson", "author_id": 12950, "author_profile": "https://Stackoverflow.com/users/12950", "pm_score": 2, "selected": false, "text": "<p>Check the value of the request parameter __EVENTTARGET to see if it is the id of the link button in question.</p>\n"...
2008/10/09
[ "https://Stackoverflow.com/questions/188584", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13053/" ]
In c#, how can I check to see if a link button has been clicked in the page load method? I need to know if it was clicked before the click event is fired.
``` if( IsPostBack ) { // get the target of the post-back, will be the name of the control // that issued the post-back string eTarget = Request.Params["__EVENTTARGET"].ToString(); } ```
188,625
<p>I have an object of class F. I want to output the contents of the object using Console.WriteLine for quick and dirty status updates like this:</p> <p>Console.WriteLine(objectF);</p> <p>This prints out only the name of the class to the console:</p> <pre><code>F </code></pre> <p>I want to overload this somehow so...
[ { "answer_id": 188630, "author": "driis", "author_id": 13627, "author_profile": "https://Stackoverflow.com/users/13627", "pm_score": 4, "selected": true, "text": "<p>Console.WriteLine(objectF)</p>\n\n<p>Should work, if you overloaded <code>ToString</code>. When the framework needs to con...
2008/10/09
[ "https://Stackoverflow.com/questions/188625", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18542/" ]
I have an object of class F. I want to output the contents of the object using Console.WriteLine for quick and dirty status updates like this: Console.WriteLine(objectF); This prints out only the name of the class to the console: ``` F ``` I want to overload this somehow so that I can instead print out some useful...
Console.WriteLine(objectF) Should work, if you overloaded `ToString`. When the framework needs to convert an object to a string representation, it invokes `ToString`. ``` public override string ToString() { // replace the line below with your code return base.ToString(); } ```
188,628
<p>I’m getting an intermittent false negative on the following line of code in an ASP.NET 2 <a href="http://www.BugTracker.net" rel="nofollow noreferrer">web site</a>:</p> <pre><code>if (!System.IO.Directory.Exists(folder)) </code></pre> <p>The folder clearly exists, and even contains a log file that is written to wh...
[ { "answer_id": 188648, "author": "Jeffrey L Whitledge", "author_id": 10174, "author_profile": "https://Stackoverflow.com/users/10174", "pm_score": 4, "selected": true, "text": "<p>Exists() returns false, rather than throwing an error, if any sort of IO error occurs. One thing to watch ou...
2008/10/09
[ "https://Stackoverflow.com/questions/188628", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8741/" ]
I’m getting an intermittent false negative on the following line of code in an ASP.NET 2 [web site](http://www.BugTracker.net): ``` if (!System.IO.Directory.Exists(folder)) ``` The folder clearly exists, and even contains a log file that is written to when the CLR doesn’t lie about the folder’s existence. Any help w...
Exists() returns false, rather than throwing an error, if any sort of IO error occurs. One thing to watch out for is security errors. Exists does not perform network authentication, so it requires being pre-authenticated if your accessing a network share, at least according to the docs. I haven't tried it myself.
188,631
<p>How can I tell if an assembly is in use by any process?</p>
[ { "answer_id": 188640, "author": "driis", "author_id": 13627, "author_profile": "https://Stackoverflow.com/users/13627", "pm_score": 0, "selected": false, "text": "<p>If you want to know if your application has loaded the assembly, you can inspect the AppDomain for loaded assemblies. If ...
2008/10/09
[ "https://Stackoverflow.com/questions/188631", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26553/" ]
How can I tell if an assembly is in use by any process?
Here's an answer in PowerShell ``` if ( Get-Process | ? { $_.Modules | ? {$_.ModuleName -eq "AssemblyName.dll" } }) { "in use" } ```
188,636
<p>I'm trying to find a way to force Windows to reboot, and I am running into issues. I've tried </p> <p><pre><code><code>Set OpSysSet = GetObject("winmgmts:{authenticationlevel=Pkt," _ &amp; "(Shutdown)}").ExecQuery("select * from Win32_OperatingSystem where "_ &amp; "Primary=true") for each OpSys in OpSy...
[ { "answer_id": 188796, "author": "Mike L", "author_id": 12085, "author_profile": "https://Stackoverflow.com/users/12085", "pm_score": 2, "selected": false, "text": "<p>Well, this uses VBScript -- although truthfully it invokes the same command line shutdown that you're trying to do. I'v...
2008/10/09
[ "https://Stackoverflow.com/questions/188636", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14092/" ]
I'm trying to find a way to force Windows to reboot, and I am running into issues. I've tried ``` `Set OpSysSet = GetObject("winmgmts:{authenticationlevel=Pkt," _ & "(Shutdown)}").ExecQuery("select * from Win32_OperatingSystem where "_ & "Primary=true") for each OpSys in OpSysSet retVal = OpSys.Reboot() next` ``` ...
Try replacing: ``` retVal = OpSys.Reboot() ``` With: ``` retVal = OpSys.Win32Shutdown(6) ```
188,663
<p>I'm curious as to if there are any best practices relating to JQuery when constructing encapsulated code blocks.</p> <p>Generally, when I construct a page I like to encapsulate the functions used within that page inside an object. This allows me some encapsulation when building applications. There's nothing I hate ...
[ { "answer_id": 188713, "author": "Tsvetomir Tsonev", "author_id": 25449, "author_profile": "https://Stackoverflow.com/users/25449", "pm_score": 1, "selected": false, "text": "<p>I usually follow the prototype pattern:</p>\n\n<pre><code>MyFunction = function(param1, param2)\n{\n this.pr...
2008/10/09
[ "https://Stackoverflow.com/questions/188663", "https://Stackoverflow.com", "https://Stackoverflow.com/users/769/" ]
I'm curious as to if there are any best practices relating to JQuery when constructing encapsulated code blocks. Generally, when I construct a page I like to encapsulate the functions used within that page inside an object. This allows me some encapsulation when building applications. There's nothing I hate more than ...
Since I've been working with jQuery for a while now, I've decided on a standard pattern that works well for me. It's a combination of the YUI module pattern with a bit of jQuery plugin pattern mixed in.. We ended up using the self executing closure pattern. This is beneficial in a few ways: 1. It keeps code to a mini...
188,687
<p>Is there a way to change the way asp.net generates elements in the WSDL generated from a .asmx file? Specifically, it seems to mark all elements minoccurs="0" and there are some elements that I want to be minoccurs="1" (aka required fields). </p> <p>One of these is an argument to the web service (e.g. foo(arg1, a...
[ { "answer_id": 189160, "author": "Panos", "author_id": 8049, "author_profile": "https://Stackoverflow.com/users/8049", "pm_score": 3, "selected": false, "text": "<p>I think that the <code>XmlElement(IsNullable = true)</code> attribute will do the job:</p>\n\n<pre><code>using System.Xml.S...
2008/10/09
[ "https://Stackoverflow.com/questions/188687", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7243/" ]
Is there a way to change the way asp.net generates elements in the WSDL generated from a .asmx file? Specifically, it seems to mark all elements minoccurs="0" and there are some elements that I want to be minoccurs="1" (aka required fields). One of these is an argument to the web service (e.g. foo(arg1, arg2) where I...
I think that the `XmlElement(IsNullable = true)` attribute will do the job: ``` using System.Xml.Serialization; [WebMethod] public string MyService([XmlElement(IsNullable = true)] string arg) { return "1"; } ``` --- EDIT [VB version] ``` Imports System.Xml.Serialization Public Function MyService(<XmlElement(Is...
188,688
<p>I am looking at some code and it has this statement: </p> <pre><code>~ConnectionManager() { Dispose(false); } </code></pre> <p>The class implements the <code>IDisposable</code> interface, but I do not know if that is part of that the tilde(~) is used for.</p>
[ { "answer_id": 188698, "author": "torial", "author_id": 13990, "author_profile": "https://Stackoverflow.com/users/13990", "pm_score": 3, "selected": false, "text": "<p>It is used to indicate the destructor for the class.</p>\n" }, { "answer_id": 188699, "author": "Santiago Pa...
2008/10/09
[ "https://Stackoverflow.com/questions/188688", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1048/" ]
I am looking at some code and it has this statement: ``` ~ConnectionManager() { Dispose(false); } ``` The class implements the `IDisposable` interface, but I do not know if that is part of that the tilde(~) is used for.
**~ is the destructor** 1. Destructors are invoked automatically, and cannot be invoked explicitly. 2. Destructors cannot be overloaded. Thus, a class can have, at most, one destructor. 3. Destructors are not inherited. Thus, a class has no destructors other than the one, which may be declared in it. 4. Destructors ca...
188,691
<p>I want to write something that acts just like confirm() in javascript, but I want to write it myself so I can skin the dialog box. In having trouble thinking through how I would basically force the javascript thread to wait until the user responds and then return true or false.</p>
[ { "answer_id": 188708, "author": "Chris Marasti-Georg", "author_id": 96, "author_profile": "https://Stackoverflow.com/users/96", "pm_score": 4, "selected": true, "text": "<p>If I were you, I would look at one of the popular javascript libraries. Most contain some sort of modal dialog.</...
2008/10/09
[ "https://Stackoverflow.com/questions/188691", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2484/" ]
I want to write something that acts just like confirm() in javascript, but I want to write it myself so I can skin the dialog box. In having trouble thinking through how I would basically force the javascript thread to wait until the user responds and then return true or false.
If I were you, I would look at one of the popular javascript libraries. Most contain some sort of modal dialog. A couple I found for JQuery are [jqModal](http://dev.iceburg.net/jquery/jqModal/) and [SimpleModal](http://www.ericmmartin.com/projects/simplemodal/). When you build the modal dialog, you will have to tie e...
188,692
<p>I recall reading, on multiple occasions and in multiple locations, that when firing the typical event:</p> <pre><code>protected virtual OnSomethingHappened() { this.SomethingHappened(this, EventArgs.Empty); } </code></pre> <p>e should be EventArgs.Empty if there are no interesting event args, not null.</p> <p...
[ { "answer_id": 188723, "author": "Mitchel Sellers", "author_id": 13279, "author_profile": "https://Stackoverflow.com/users/13279", "pm_score": 6, "selected": true, "text": "<p>I believe the reasoning behind the NOT NULL is that when passed as a parameter, it is not expected for the metho...
2008/10/09
[ "https://Stackoverflow.com/questions/188692", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6932/" ]
I recall reading, on multiple occasions and in multiple locations, that when firing the typical event: ``` protected virtual OnSomethingHappened() { this.SomethingHappened(this, EventArgs.Empty); } ``` e should be EventArgs.Empty if there are no interesting event args, not null. I've followed the guidance in my...
I believe the reasoning behind the NOT NULL is that when passed as a parameter, it is not expected for the method to need to potentially handle a null reference exception. If you pass null, and the method tries to do something with e it will get a null reference exception, with EventArgs.Empty it will not.
188,693
<p>Looking for an answer for C# and C++. (in C#, replace 'destructor' with 'finalizer')</p>
[ { "answer_id": 188722, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 6, "selected": false, "text": "<p>It does for C# (see code below) but not for C++.</p>\n\n<pre><code>using System;\n\nclass Test\n{\n Test()\n {\...
2008/10/09
[ "https://Stackoverflow.com/questions/188693", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22820/" ]
Looking for an answer for C# and C++. (in C#, replace 'destructor' with 'finalizer')
Preamble: Herb Sutter has a great article on the subject: <http://herbsutter.wordpress.com/2008/07/25/constructor-exceptions-in-c-c-and-java/> C++ : Yes and No ---------------- While an object destructor won't be called if its constructor throws (the object "never existed"), the destructors of its internal objects c...
188,719
<p>A friend and I are about to embark on creating a machine that performs some image comparison for sorting. I know about histogram comparison and am generally confident that a small grid of histograms per image precalculated and stored in columns in a database table will generally give us pretty good matches on the f...
[ { "answer_id": 188722, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 6, "selected": false, "text": "<p>It does for C# (see code below) but not for C++.</p>\n\n<pre><code>using System;\n\nclass Test\n{\n Test()\n {\...
2008/10/09
[ "https://Stackoverflow.com/questions/188719", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5645/" ]
A friend and I are about to embark on creating a machine that performs some image comparison for sorting. I know about histogram comparison and am generally confident that a small grid of histograms per image precalculated and stored in columns in a database table will generally give us pretty good matches on the first...
Preamble: Herb Sutter has a great article on the subject: <http://herbsutter.wordpress.com/2008/07/25/constructor-exceptions-in-c-c-and-java/> C++ : Yes and No ---------------- While an object destructor won't be called if its constructor throws (the object "never existed"), the destructors of its internal objects c...
188,720
<p>Is there any way in the SQL language or in MySQL (or other DBMA) to transfer a value from one cell to another? For example, say there is a table called user_cars with the following structure:</p> <pre><code>|id| |user_name| |num_cars| </code></pre> <p>Bob has 5 cars, and John has 3 cars. Is there any way to in one...
[ { "answer_id": 188744, "author": "Thorsten", "author_id": 25320, "author_profile": "https://Stackoverflow.com/users/25320", "pm_score": 1, "selected": false, "text": "<p>That's what transactions are for ...</p>\n" }, { "answer_id": 188747, "author": "KernelM", "author_id"...
2008/10/09
[ "https://Stackoverflow.com/questions/188720", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26603/" ]
Is there any way in the SQL language or in MySQL (or other DBMA) to transfer a value from one cell to another? For example, say there is a table called user\_cars with the following structure: ``` |id| |user_name| |num_cars| ``` Bob has 5 cars, and John has 3 cars. Is there any way to in one query subtract 2 cars fr...
For Oracle you could do this. Don't know if there is an equivalent in mysql. Obviously this particular statement is very specific to the example you stated. ``` UPDATE user_cars SET num_cars = num_cars + CASE WHEN user_name='Bob' THEN -2 WHEN user_name='John' THEN +2 ...
188,738
<p>People keep giving me examples with carp instead of warn. Why? What makes carp better than warn?</p>
[ { "answer_id": 188752, "author": "jvasak", "author_id": 5840, "author_profile": "https://Stackoverflow.com/users/5840", "pm_score": 4, "selected": false, "text": "<p>carp works better for debugging within modules. If you are only writing a simple script, there is no benefit. From <a hr...
2008/10/09
[ "https://Stackoverflow.com/questions/188738", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12448/" ]
People keep giving me examples with carp instead of warn. Why? What makes carp better than warn?
carp gives you more info as to where the message comes from (context) ``` #!/usr/bin/perl use Carp; foo(); bar(); baz(); sub foo { warn "foo"; } sub bar { carp "bar"; } sub baz { foo(); bar(); } ``` produces ``` foo at ./foo.pl line 9. bar at ./foo.pl line 13 main::bar() called at ./foo.pl lin...
188,769
<p>I'm trying to show someone a use for interfaces in a crazy situation they've created. They have several unrelated objects in lists, and need to perform an operation on two string properties in each object. I'm pointing out that if they define the properties as part of an interface, they can use the interface objec...
[ { "answer_id": 188797, "author": "James Curran", "author_id": 12725, "author_profile": "https://Stackoverflow.com/users/12725", "pm_score": 4, "selected": true, "text": "<p>The problem is with the method, not with how it's called.....</p>\n\n<pre><code>void PrintProperties&lt;SP&gt;(IEnu...
2008/10/09
[ "https://Stackoverflow.com/questions/188769", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2547/" ]
I'm trying to show someone a use for interfaces in a crazy situation they've created. They have several unrelated objects in lists, and need to perform an operation on two string properties in each object. I'm pointing out that if they define the properties as part of an interface, they can use the interface object as ...
The problem is with the method, not with how it's called..... ``` void PrintProperties<SP>(IEnumerable<SP> list) where SP: ISpecialProperties { foreach (var item in list) { Console.WriteLine("{0} {1}", item.Prop1, item.Prop2); } } ```
188,787
<p>I need to find occurrences of "(+)" in my sql scripts, (i.e., Oracle outer join expressions). Realizing that "+", "(", and ")" are all special regex characters, I tried:</p> <pre> grep "\(\+\)" * </pre> <p>Now this does return occurrences of "(+)", but other lines as well. (Seemingly anything with open and close p...
[ { "answer_id": 188795, "author": "KernelM", "author_id": 22328, "author_profile": "https://Stackoverflow.com/users/22328", "pm_score": 1, "selected": false, "text": "<p>You probably need to add some backslashes because the shell is swallowing them.</p>\n\n<p>ETA: Actually, I just tried o...
2008/10/09
[ "https://Stackoverflow.com/questions/188787", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14749/" ]
I need to find occurrences of "(+)" in my sql scripts, (i.e., Oracle outer join expressions). Realizing that "+", "(", and ")" are all special regex characters, I tried: ``` grep "\(\+\)" * ``` Now this does return occurrences of "(+)", but other lines as well. (Seemingly anything with open and close parens on the ...
GNU grep (which is included in Cygwin) supports two syntaxes for regular expressions: basic and extended. `grep` uses basic regular expressions and `egrep` or `grep -E` uses extended regular expressions. The basic difference, from the [grep manual](http://www.gnu.org/software/grep/doc/grep_12.html#SEC12), is the follow...
188,793
<p>What I'm trying to do is encode a gif file, to include in an XML document. This is what I have now, but it doesn't seem to work.</p> <pre><code>Function gifToBase64(strGifFilename) On Error Resume Next Dim strBase64 Set inputStream = WScript.CreateObject("ADODB.Stream") inputStream.LoadFromFile strGifFilename ...
[ { "answer_id": 188807, "author": "Tomalak", "author_id": 18771, "author_profile": "https://Stackoverflow.com/users/18771", "pm_score": 1, "selected": false, "text": "<p>Take a look here: <a href=\"http://www.robvanderwoude.com/vbstech_files_encode_base64.html\" rel=\"nofollow noreferrer\...
2008/10/09
[ "https://Stackoverflow.com/questions/188793", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
What I'm trying to do is encode a gif file, to include in an XML document. This is what I have now, but it doesn't seem to work. ``` Function gifToBase64(strGifFilename) On Error Resume Next Dim strBase64 Set inputStream = WScript.CreateObject("ADODB.Stream") inputStream.LoadFromFile strGifFilename strBase64 = in...
I recently wrote a post about this very subject for implementations in [JScript](http://cwestblog.com/2013/09/18/jscript-convert-image-to-base64/) and [VBScript](http://cwestblog.com/2013/09/23/vbscript-convert-image-to-base-64/). Here is the solution I have for VBScript: ```vb Public Function convertImageToBase64(fil...
188,808
<p>I have a Winform application built with C# and .Net 2.0. I have a textbox set with the MultiLine property.</p> <p>The problem is when someone writes text with multiple lines (press few enters), presses the save button, and then closes and loads the form again, all the new lines disappear (the text is there at least...
[ { "answer_id": 188838, "author": "Geoff", "author_id": 1097, "author_profile": "https://Stackoverflow.com/users/1097", "pm_score": 3, "selected": true, "text": "<p>If I recall correctly, the textbox is really a string array.</p>\n\n<p>I think you can do this:</p>\n\n<pre><code>textBox1.L...
2008/10/09
[ "https://Stackoverflow.com/questions/188808", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13913/" ]
I have a Winform application built with C# and .Net 2.0. I have a textbox set with the MultiLine property. The problem is when someone writes text with multiple lines (press few enters), presses the save button, and then closes and loads the form again, all the new lines disappear (the text is there at least). For ex...
If I recall correctly, the textbox is really a string array. I think you can do this: ``` textBox1.Lines = foo.Split(new String[] {"\n"},StringSplitOptions.RemoveEmptyEntries); ``` Edit again: If you want to keep the blank lines, the change to StringSplitOptions.None
188,828
<p>I've just learned ( yesterday ) to use "exists" instead of "in".</p> <pre><code> BAD select * from table where nameid in ( select nameid from othertable where otherdesc = 'SomeDesc' ) GOOD select * from table t where exists ( select nameid from othertable o where t.nameid = o.nameid ...
[ { "answer_id": 188849, "author": "Milan Babuškov", "author_id": 14690, "author_profile": "https://Stackoverflow.com/users/14690", "pm_score": 3, "selected": true, "text": "<p>It's specific to each DBMS and depends on the query optimizer. Some optimizers detect IN clause and translate it....
2008/10/09
[ "https://Stackoverflow.com/questions/188828", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20654/" ]
I've just learned ( yesterday ) to use "exists" instead of "in". ``` BAD select * from table where nameid in ( select nameid from othertable where otherdesc = 'SomeDesc' ) GOOD select * from table t where exists ( select nameid from othertable o where t.nameid = o.nameid and otherdesc ...
It's specific to each DBMS and depends on the query optimizer. Some optimizers detect IN clause and translate it. In all DBMSes I tested, alias is only valid inside the ( ) BTW, you can rewrite the query as: ``` select t.* from table t join othertable o on t.nameid = o.nameid and o.otherdesc in ('SomeDesc','...
188,833
<p>Why am I getting a textbox that returns undefined list of variables?</p> <p>When I run this code:</p> <pre><code>var query = (from tisa in db.TA_Info_Step_Archives where tisa.ta_Serial.ToString().StartsWith(prefixText) select tisa.TA_Serial.ToString()).Distinct().Take(Convert.ToIn...
[ { "answer_id": 188907, "author": "ForCripeSake", "author_id": 14833, "author_profile": "https://Stackoverflow.com/users/14833", "pm_score": 0, "selected": false, "text": "<p>It sounds like the problem isn't with the method, but with the way you are hooking up the autocomplete to the meth...
2008/10/09
[ "https://Stackoverflow.com/questions/188833", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7644/" ]
Why am I getting a textbox that returns undefined list of variables? When I run this code: ``` var query = (from tisa in db.TA_Info_Step_Archives where tisa.ta_Serial.ToString().StartsWith(prefixText) select tisa.TA_Serial.ToString()).Distinct().Take(Convert.ToInt32(count)); return ...
updated my ajax kit to version 1.0.10920 then changed my code to the following: ``` foreach (DataRow dr in dt.Rows) { items.SetValue("\"" + dr["somenumber"].ToString() + "\"", i); i++; } ``` Late friday nights with .net is not fun. I have no life. :-P
188,834
<p>I need to dynamically construct an XPath query for an element attribute, where the attribute value is provided by the user. I'm unsure how to go about cleaning or sanitizing this value to prevent the XPath equivalent of a SQL injection attack. For example (in PHP):</p> <pre><code>&lt;?php function xPathQuery($att...
[ { "answer_id": 188858, "author": "Chris Marasti-Georg", "author_id": 96, "author_profile": "https://Stackoverflow.com/users/96", "pm_score": -1, "selected": false, "text": "<pre><code>function xPathQuery($attr) {\n $xml = simplexml_load_file('example.xml');\n $to_encode = array('&a...
2008/10/09
[ "https://Stackoverflow.com/questions/188834", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I need to dynamically construct an XPath query for an element attribute, where the attribute value is provided by the user. I'm unsure how to go about cleaning or sanitizing this value to prevent the XPath equivalent of a SQL injection attack. For example (in PHP): ``` <?php function xPathQuery($attr) { $xml = sim...
XPath does actually include a method of doing this safely, in that it permits [variable references](http://www.w3.org/TR/xpath#section-Expressions) in the form `$varname` in expressions. The library on which PHP's SimpleXML is based [provides an interface to supply variables](http://xmlsoft.org/html/libxml-xpathInterna...
188,839
<p>I use a structure of function pointers to implement an interface for different backends. The signatures are very different, but the return values are almost all void, void * or int.</p> <pre><code> struct my_interface { void (*func_a)(int i); void *(*func_b)(const char *bla); ... int (*func_z)(ch...
[ { "answer_id": 188855, "author": "Ferruccio", "author_id": 4086, "author_profile": "https://Stackoverflow.com/users/4086", "pm_score": 0, "selected": false, "text": "<p>It should be fine. Since the caller is responsible for cleaning up the stack after a call, it shouldn't leave anything ...
2008/10/09
[ "https://Stackoverflow.com/questions/188839", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18687/" ]
I use a structure of function pointers to implement an interface for different backends. The signatures are very different, but the return values are almost all void, void \* or int. ``` struct my_interface { void (*func_a)(int i); void *(*func_b)(const char *bla); ... int (*func_z)(char foo); }; ...
By the C specification, casting a function pointer results in undefined behavior. In fact, for a while, GCC 4.3 prereleases would return NULL whenever you casted a function pointer, perfectly valid by the spec, but they backed out that change before release because it broke lots of programs. Assuming GCC continues doi...
188,850
<p>I would like a batch file to launch two separate programs then have the command line window close. Actually, to clarify, I am launching Internet Explorer with two different URLs.</p> <p>So far I have something like this:</p> <pre><code>start "~\iexplore.exe" "url1" start "~\iexplore.exe" "url2" </code></pre> <p>W...
[ { "answer_id": 188914, "author": "Daniel Plaisted", "author_id": 1509, "author_profile": "https://Stackoverflow.com/users/1509", "pm_score": 0, "selected": false, "text": "<p>There is a setting in the IE options that controls whether it should open new links in an existing window or in a...
2008/10/09
[ "https://Stackoverflow.com/questions/188850", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10552/" ]
I would like a batch file to launch two separate programs then have the command line window close. Actually, to clarify, I am launching Internet Explorer with two different URLs. So far I have something like this: ``` start "~\iexplore.exe" "url1" start "~\iexplore.exe" "url2" ``` What I get is one instance of Inte...
Try this in your batch file: ``` @echo off start /d "C:\Program Files\Internet Explorer" IEXPLORE.EXE www.google.com start /d "C:\Program Files\Internet Explorer" IEXPLORE.EXE www.yahoo.com ```
188,886
<p>After my <code>form.Form</code> validates the user input values I pass them to a separate (external) process for further processing. This external process can potentially find further errors in the values.</p> <p>Is there a way to inject these errors into the already validated form so they can be displayed via the ...
[ { "answer_id": 188904, "author": "Jonny Buchanan", "author_id": 6760, "author_profile": "https://Stackoverflow.com/users/6760", "pm_score": 4, "selected": false, "text": "<p>You can add additional error details to the form's <code>_errors</code> attribute directly:</p>\n\n<p><a href=\"ht...
2008/10/09
[ "https://Stackoverflow.com/questions/188886", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13055/" ]
After my `form.Form` validates the user input values I pass them to a separate (external) process for further processing. This external process can potentially find further errors in the values. Is there a way to inject these errors into the already validated form so they can be displayed via the usual form error disp...
`Form._errors` can be treated like a standard dictionary. It's considered good form to use the `ErrorList` class, and to append errors to the existing list: ``` from django.forms.utils import ErrorList errors = form._errors.setdefault("myfield", ErrorList()) errors.append(u"My error here") ``` And if you want to add...
188,889
<p>how do I pass additional information to the service method returning the collection of items? I'll attempt to explain what I mean, I have 2 text boxes on a form, I need to fill out names, based of a specific account id in a database. so, I need to pass an integer to the getNamesForDropDown method. I couldn't figu...
[ { "answer_id": 188903, "author": "azamsharp", "author_id": 3797, "author_profile": "https://Stackoverflow.com/users/3797", "pm_score": 2, "selected": false, "text": "<p>If you like you can use a separator with the prefixText. So, you can pass \"1:bcd\" and on the service end you can spli...
2008/10/09
[ "https://Stackoverflow.com/questions/188889", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18893/" ]
how do I pass additional information to the service method returning the collection of items? I'll attempt to explain what I mean, I have 2 text boxes on a form, I need to fill out names, based of a specific account id in a database. so, I need to pass an integer to the getNamesForDropDown method. I couldn't figure out...
azam has the right idea- but the signature of the autocomplete method can also have a third parameter: public string[] yourmethod(string prefixText, int count, string **contextKey**) you can Split up the results of the contextKey string using Azam's method- but this way you do not have to worry about sanatizing the u...
188,892
<p>Is there a built-in mechanism in .NET to match patterns other than Regular Expressions? I'd like to match using UNIX style (glob) wildcards (* = any number of any character). </p> <p>I'd like to use this for a end-user facing control. I fear that permitting all RegEx capabilities will be very confusing.</p>
[ { "answer_id": 188924, "author": "Ferruccio", "author_id": 4086, "author_profile": "https://Stackoverflow.com/users/4086", "pm_score": 1, "selected": false, "text": "<p>I don't know if the .NET framework has glob matching, but couldn't you replace the * with .*? and use regexes?</p>\n" ...
2008/10/09
[ "https://Stackoverflow.com/questions/188892", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1807/" ]
Is there a built-in mechanism in .NET to match patterns other than Regular Expressions? I'd like to match using UNIX style (glob) wildcards (\* = any number of any character). I'd like to use this for a end-user facing control. I fear that permitting all RegEx capabilities will be very confusing.
I found the actual code for you: ``` Regex.Escape( wildcardExpression ).Replace( @"\*", ".*" ).Replace( @"\?", "." ); ```
188,894
<p>I have a .NET WinForms textbox for a phone number field. After allowing free-form text, I'd like to format the text as a "more readable" phone number after the user leaves the textbox. (Outlook has this feature for phone fields when you create/edit a contact)</p> <ul> <li>1234567 becomes 123-4567</li> <li>12345678...
[ { "answer_id": 188935, "author": "Davy8", "author_id": 23822, "author_profile": "https://Stackoverflow.com/users/23822", "pm_score": 0, "selected": false, "text": "<p>I don't know of any way other than doing it yourself by possibly making some masks and checking which one it matches and ...
2008/10/09
[ "https://Stackoverflow.com/questions/188894", "https://Stackoverflow.com", "https://Stackoverflow.com/users/247/" ]
I have a .NET WinForms textbox for a phone number field. After allowing free-form text, I'd like to format the text as a "more readable" phone number after the user leaves the textbox. (Outlook has this feature for phone fields when you create/edit a contact) * 1234567 becomes 123-4567 * 1234567890 becomes (123) 456-7...
A fairly simple-minded approach would be to use a regular expression. Depending on which type of phone numbers you're accepting, you could write a regular expression that looks for the digits (for US-only, you know there can be 7 or 10 total - maybe with a leading '1') and potential separators between them (period, das...
188,942
<p>I'm writing some cross-platform code between Windows and Mac.</p> <p>If list::end() "returns an iterator that addresses the location succeeding the last element in a list" and can be checked when traversing a list forward, what is the best way to traverse backwards?</p> <p>This code workson the Mac but not on Win...
[ { "answer_id": 188948, "author": "Ferruccio", "author_id": 4086, "author_profile": "https://Stackoverflow.com/users/4086", "pm_score": 7, "selected": true, "text": "<p>Use <code>reverse_iterator</code> instead of <code>iterator</code>.\nUse <code>rbegin()</code> &amp; <code>rend()</code>...
2008/10/09
[ "https://Stackoverflow.com/questions/188942", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8761/" ]
I'm writing some cross-platform code between Windows and Mac. If list::end() "returns an iterator that addresses the location succeeding the last element in a list" and can be checked when traversing a list forward, what is the best way to traverse backwards? This code workson the Mac but not on Windows (can't decrem...
Use `reverse_iterator` instead of `iterator`. Use `rbegin()` & `rend()` instead of `begin()` & `end()`. Another possibility, if you like using the [`BOOST_FOREACH`](http://www.boost.org/doc/libs/1_36_0/doc/html/foreach.html) macro is to use the `BOOST_REVERSE_FOREACH` macro introduced in Boost 1.36.0.
188,967
<p>I want to do this in code, not with ALT+F1.</p>
[ { "answer_id": 188981, "author": "Patrick McElhaney", "author_id": 437, "author_profile": "https://Stackoverflow.com/users/437", "pm_score": 5, "selected": false, "text": "<pre><code>sp_help tablename \n</code></pre>\n\n<p>In the output look for something like this:</p>\n\n<pre><code> Id...
2008/10/09
[ "https://Stackoverflow.com/questions/188967", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2484/" ]
I want to do this in code, not with ALT+F1.
You can also do it this way: ``` select columnproperty(object_id('mytable'),'mycolumn','IsIdentity') ``` Returns 1 if it's an identity, 0 if not.
188,968
<p>I would like a constraint on a SQL Server 2000 table column that is sort of a combination of a foreign key and a check constraint. The value of my column must exist in the other table, but I am only concerned with values in the other table where one of its columns equal a specified value. The simplified tables are...
[ { "answer_id": 188981, "author": "Patrick McElhaney", "author_id": 437, "author_profile": "https://Stackoverflow.com/users/437", "pm_score": 5, "selected": false, "text": "<pre><code>sp_help tablename \n</code></pre>\n\n<p>In the output look for something like this:</p>\n\n<pre><code> Id...
2008/10/09
[ "https://Stackoverflow.com/questions/188968", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23976/" ]
I would like a constraint on a SQL Server 2000 table column that is sort of a combination of a foreign key and a check constraint. The value of my column must exist in the other table, but I am only concerned with values in the other table where one of its columns equal a specified value. The simplified tables are: ``...
You can also do it this way: ``` select columnproperty(object_id('mytable'),'mycolumn','IsIdentity') ``` Returns 1 if it's an identity, 0 if not.
188,977
<p>I have a method running in a seperate thread. The thread is created and started from a form in a windows application. If an exception is thrown from inside the thread, what is the best way to pass it back to the main application. Right now, I'm passing a reference to the main form into the thread, then invoking t...
[ { "answer_id": 188992, "author": "Dror Helper", "author_id": 11361, "author_profile": "https://Stackoverflow.com/users/11361", "pm_score": 1, "selected": false, "text": "<p>Throwing exceptions between threads is not easy and probably not desired. instead you can pass the exception using ...
2008/10/09
[ "https://Stackoverflow.com/questions/188977", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9266/" ]
I have a method running in a seperate thread. The thread is created and started from a form in a windows application. If an exception is thrown from inside the thread, what is the best way to pass it back to the main application. Right now, I'm passing a reference to the main form into the thread, then invoking the met...
So you're using Invoke to marshall back to the UI thread, by the looks of it - which is exactly what you need to do. I'd personally use an Action<Exception> for simplicity's sake, and possibly BeginInvoke instead of Invoke, but basically you're doing the right thing.
189,019
<p>I found an example of implementing the repository pattern in NHibernate on the web, and one of the methods uses this code to get the first result of a query:</p> <pre><code>public IEnumerable&lt;T&gt; FindAll(DetachedCriteria criteria, int firstResult, int numberOfResults, params Order[] orders) { criteria.Set...
[ { "answer_id": 188992, "author": "Dror Helper", "author_id": 11361, "author_profile": "https://Stackoverflow.com/users/11361", "pm_score": 1, "selected": false, "text": "<p>Throwing exceptions between threads is not easy and probably not desired. instead you can pass the exception using ...
2008/10/09
[ "https://Stackoverflow.com/questions/189019", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1284/" ]
I found an example of implementing the repository pattern in NHibernate on the web, and one of the methods uses this code to get the first result of a query: ``` public IEnumerable<T> FindAll(DetachedCriteria criteria, int firstResult, int numberOfResults, params Order[] orders) { criteria.SetFirstResult(firstRes...
So you're using Invoke to marshall back to the UI thread, by the looks of it - which is exactly what you need to do. I'd personally use an Action<Exception> for simplicity's sake, and possibly BeginInvoke instead of Invoke, but basically you're doing the right thing.
189,055
<p>Typically you will find STL code like this:</p> <pre><code>for (SomeClass::SomeContainer::iterator Iter = m_SomeMemberContainerVar.begin(); Iter != m_SomeMemberContainerVar.end(); ++Iter) { } </code></pre> <p>But we actually have the recommendation to write it like this:</p> <pre><code>SomeClass::SomeContainer::i...
[ { "answer_id": 189060, "author": "Ferruccio", "author_id": 4086, "author_profile": "https://Stackoverflow.com/users/4086", "pm_score": 3, "selected": false, "text": "<p>The first form (inside the for loop) is better if the iterator is not needed after the for loop. It limits its scope to...
2008/10/09
[ "https://Stackoverflow.com/questions/189055", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15328/" ]
Typically you will find STL code like this: ``` for (SomeClass::SomeContainer::iterator Iter = m_SomeMemberContainerVar.begin(); Iter != m_SomeMemberContainerVar.end(); ++Iter) { } ``` But we actually have the recommendation to write it like this: ``` SomeClass::SomeContainer::iterator Iter = m_SomeMemberContainerV...
If you wrap your code into lines properly, the inline form would be equally readable. Besides, you should always do the `iterEnd = container.end()` as an optimization: ``` for (SomeClass::SomeContainer::iterator Iter = m_SomeMemberContainerVar.begin(), IterEnd = m_SomeMemberContainerVar.end(); Iter != IterEnd;...
189,062
<p>When I navigate on a website utilizing MasterPages, does the application know what page I am on? If so, does it store it in an object I can access?</p> <p>The reason I am asking is so I can replace this:</p> <pre><code>//masterpage &lt;div id="nav_main"&gt; &lt;ul&gt;&lt;asp:ContentPlaceHolder ID="navigation"...
[ { "answer_id": 189085, "author": "Jared", "author_id": 1980, "author_profile": "https://Stackoverflow.com/users/1980", "pm_score": 0, "selected": false, "text": "<p>You should be able to get the page by accessing the Page property. IE:</p>\n\n<pre><code>string type = this.Page.GetType()....
2008/10/09
[ "https://Stackoverflow.com/questions/189062", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25515/" ]
When I navigate on a website utilizing MasterPages, does the application know what page I am on? If so, does it store it in an object I can access? The reason I am asking is so I can replace this: ``` //masterpage <div id="nav_main"> <ul><asp:ContentPlaceHolder ID="navigation" runat="server"> ...
I'd concur with Chris: use a control to handle display of this menu and make it aware of what link should be highlighted. Here's a method I use regularly. It may become more complex if you've got multiple pages that would need the same link styled differently, but you get the idea. ``` Dim thisURL As String = Request....
189,079
<p>I'm having some minor problems with some animations I'm trying to set up. I have a couple divs stacked on top of each other kind of like this.</p> <pre><code>&lt;div id="div1"&gt; Stuff... &lt;/div&gt; &lt;div id="div2"&gt; More Stuff... &lt;/div&gt; </code></pre> <p>Each of these divs has a drop shadow app...
[ { "answer_id": 189438, "author": "Till", "author_id": 2859, "author_profile": "https://Stackoverflow.com/users/2859", "pm_score": 0, "selected": false, "text": "<p>Ok, I still don't know how you animate, but I give you another example:</p>\n\n<pre><code>$('#foo').slideToggle().ready(func...
2008/10/09
[ "https://Stackoverflow.com/questions/189079", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17881/" ]
I'm having some minor problems with some animations I'm trying to set up. I have a couple divs stacked on top of each other kind of like this. ``` <div id="div1"> Stuff... </div> <div id="div2"> More Stuff... </div> ``` Each of these divs has a drop shadow applied to it via jQuery plugin (jquery.dropshadow.js)...
I would suggest using **CSS** for your drop shadows, and **not JS**. I have dealt with this exact problem in the past and I have completely stopped using JS for drop shadows. I have never seen animations with JS shadows look as smooth as pure CSS. Also, using too much JS to alter the page elements can cause performanc...
189,087
<p>If I'm making a simple grid based game, for example, I might have a few 2d lists. One might be for terrain, another might be for objects, etc. Unfortunately, when I need to iterate over the lists and have the contents of a square in one list affect part of another list, I have to do something like this.</p> <pre><c...
[ { "answer_id": 189096, "author": "Haoest", "author_id": 10088, "author_profile": "https://Stackoverflow.com/users/10088", "pm_score": -1, "selected": false, "text": "<pre><code>for d1 in alist\n for d2 in d1\n if d2 = \"whatever\"\n do_my_thing()\n</code></pre>\n" }, ...
2008/10/09
[ "https://Stackoverflow.com/questions/189087", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25680/" ]
If I'm making a simple grid based game, for example, I might have a few 2d lists. One might be for terrain, another might be for objects, etc. Unfortunately, when I need to iterate over the lists and have the contents of a square in one list affect part of another list, I have to do something like this. ``` for i in r...
I'd start by writing a generator method: ``` def grid_objects(alist, blist): for i in range(len(alist)): for j in range(len(alist[i])): yield(alist[i][j], blist[i][j]) ``` Then whenever you need to iterate over the lists your code looks like this: ``` for (a, b) in grid_objects(alist, blist)...
189,094
<p>How can I get list all the files within a folder recursively in Java? </p>
[ { "answer_id": 189108, "author": "OscarRyz", "author_id": 20654, "author_profile": "https://Stackoverflow.com/users/20654", "pm_score": 5, "selected": false, "text": "<pre><code>import java.io.File;\npublic class Test {\n public static void main( String [] args ) {\n File actua...
2008/10/09
[ "https://Stackoverflow.com/questions/189094", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8418/" ]
How can I get list all the files within a folder recursively in Java?
Not sure how you want to represent the tree? Anyway here's an example which scans the entire subtree using recursion. Files and directories are treated alike. Note that [File.listFiles()](http://docs.oracle.com/javase/6/docs/api/java/io/File.html#listFiles%28%29) returns null for non-directories. ``` public static voi...
189,113
<p>I moved a <a href="http://en.wikipedia.org/wiki/WordPress" rel="noreferrer">WordPress</a> installation to a new folder on a Windows/<a href="http://en.wikipedia.org/wiki/Internet_Information_Services" rel="noreferrer">IIS</a> server. I'm setting up 301 redirects in PHP, but it doesn't seem to be working. My post URL...
[ { "answer_id": 189123, "author": "Greg", "author_id": 24181, "author_profile": "https://Stackoverflow.com/users/24181", "pm_score": 4, "selected": false, "text": "<p><code>$_SERVER['REQUEST_URI']</code> doesn't work on IIS, but I did find this: <a href=\"http://neosmart.net/blog/2006/100...
2008/10/09
[ "https://Stackoverflow.com/questions/189113", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19487/" ]
I moved a [WordPress](http://en.wikipedia.org/wiki/WordPress) installation to a new folder on a Windows/[IIS](http://en.wikipedia.org/wiki/Internet_Information_Services) server. I'm setting up 301 redirects in PHP, but it doesn't seem to be working. My post URLs have the following format: ```none http:://www.example.c...
Maybe, because you are under IIS, ``` $_SERVER['PATH_INFO'] ``` is what you want, based on the URLs you used to explain. For Apache, you'd use `$_SERVER['REQUEST_URI']`.
189,121
<p>using MVP, what is the normal order of construction and dependency injection.</p> <p>normally you create a presenter for each view and pass the view into the presenter on constructor. But what if you have:</p> <ol> <li>A Service that multiple views need to listen to events on.</li> <li>Multiple views all pointing...
[ { "answer_id": 191182, "author": "Romain Verdier", "author_id": 4687, "author_profile": "https://Stackoverflow.com/users/4687", "pm_score": 5, "selected": true, "text": "<p>Here is what I do:</p>\n\n<p>First, I define theses interfaces:</p>\n\n<pre><code>public interface IView&lt;TPresen...
2008/10/09
[ "https://Stackoverflow.com/questions/189121", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4653/" ]
using MVP, what is the normal order of construction and dependency injection. normally you create a presenter for each view and pass the view into the presenter on constructor. But what if you have: 1. A Service that multiple views need to listen to events on. 2. Multiple views all pointing to the same data model cac...
Here is what I do: First, I define theses interfaces: ``` public interface IView<TPresenter> { TPresenter Presenter { get; set; } } public interface IPresenter<TView, TPresenter> where TView : IView<TPresenter> where TPresenter : IPresenter<TView, TPresenter> { TView View { get; set; } } ``` Then t...
189,148
<p>(See related question: <a href="https://stackoverflow.com/questions/162917/how-do-i-report-an-error-midway-through-a-chunked-http-repsonse-without-closing">How do I report an error midway through a chunked http repsonse without closing the connection?</a>)</p> <p>In my case, the #1 desire is for the browser to disp...
[ { "answer_id": 189285, "author": "davr", "author_id": 14569, "author_profile": "https://Stackoverflow.com/users/14569", "pm_score": 0, "selected": false, "text": "<p>I think you're going about it the wrong way. It seems like it would be simpler to not actually start sending the data unti...
2008/10/09
[ "https://Stackoverflow.com/questions/189148", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22704/" ]
(See related question: [How do I report an error midway through a chunked http repsonse without closing the connection?](https://stackoverflow.com/questions/162917/how-do-i-report-an-error-midway-through-a-chunked-http-repsonse-without-closing)) In my case, the #1 desire is for the browser to display an error message....
My own answer, after research. Part one: There seems to be no way to convince the application servers that I tested to put an error onto the wire past the "committed" phase. The following Servlet code results in legal HTTP Chunked Transfer headers on the socket. Interestingly, in the case of WebSphere an error message...
189,156
<p>Running FxCop on my code, I get this warning:</p> <blockquote> <p>Microsoft.Maintainability : 'FooBar.ctor is coupled with 99 different types from 9 different namespaces. Rewrite or refactor the method to decrease its class coupling, or consider moving the method to one of the other types it is tightl...
[ { "answer_id": 189164, "author": "NotMe", "author_id": 2424, "author_profile": "https://Stackoverflow.com/users/2424", "pm_score": 0, "selected": false, "text": "<p>Perhaps instead of having a different class for each message, use a flag that identifies the message.</p>\n\n<p>That would ...
2008/10/09
[ "https://Stackoverflow.com/questions/189156", "https://Stackoverflow.com", "https://Stackoverflow.com/users/536/" ]
Running FxCop on my code, I get this warning: > > Microsoft.Maintainability : > 'FooBar.ctor is coupled with 99 > different types from 9 different > namespaces. Rewrite or refactor the > method to decrease its class coupling, > or consider moving the method to one > of the other types it is tightly > coupled w...
Have the classes that do the work register for events they're interested in...an [event broker](http://msforge.net/blogs/paki/archive/2007/11/20/EventBroker-implementation-in-C_2300_-full-source-code.aspx) pattern. ``` class EventBroker { private Dictionary<Type, Action<EventArgs>> messageHandlers; void Registe...
189,172
<p>I'm told that the template system in C++ is Turing-complete at compile time. This is mentioned in <a href="https://stackoverflow.com/questions/75538/hidden-features-of-c#75627">this post</a> and also on <a href="http://en.wikipedia.org/wiki/C%2B%2B" rel="noreferrer">wikipedia</a>.</p> <p>Can you provide a nontrivia...
[ { "answer_id": 189187, "author": "Rob Walker", "author_id": 3631, "author_profile": "https://Stackoverflow.com/users/3631", "pm_score": 5, "selected": false, "text": "<p>\"<a href=\"http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.14.3670\" rel=\"noreferrer\">C++ Templates Are Tur...
2008/10/09
[ "https://Stackoverflow.com/questions/189172", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18770/" ]
I'm told that the template system in C++ is Turing-complete at compile time. This is mentioned in [this post](https://stackoverflow.com/questions/75538/hidden-features-of-c#75627) and also on [wikipedia](http://en.wikipedia.org/wiki/C%2B%2B). Can you provide a nontrivial example of a computation that exploits this pro...
Example ``` #include <iostream> template <int N> struct Factorial { enum { val = Factorial<N-1>::val * N }; }; template<> struct Factorial<0> { enum { val = 1 }; }; int main() { // Note this value is generated at compile time. // Also note that most compilers have a limit on the depth of the recursi...
189,213
<p>Using the following query and results, I'm looking for the most recent entry where the ChargeId and ChargeType are unique.</p> <pre><code>select chargeId, chargeType, serviceMonth from invoice CHARGEID CHARGETYPE SERVICEMONTH 1 101 R 8/1/2008 2 161 N 2/1/2008 3 101 ...
[ { "answer_id": 189221, "author": "Mitchel Sellers", "author_id": 13279, "author_profile": "https://Stackoverflow.com/users/13279", "pm_score": 8, "selected": true, "text": "<p>You can use a <strong>GROUP BY</strong> to group items by type and id. Then you can use the <strong>MAX()</stro...
2008/10/09
[ "https://Stackoverflow.com/questions/189213", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16345/" ]
Using the following query and results, I'm looking for the most recent entry where the ChargeId and ChargeType are unique. ``` select chargeId, chargeType, serviceMonth from invoice CHARGEID CHARGETYPE SERVICEMONTH 1 101 R 8/1/2008 2 161 N 2/1/2008 3 101 R ...
You can use a **GROUP BY** to group items by type and id. Then you can use the **MAX()** Aggregate function to get the most recent service month. The below returns a result set with ChargeId, ChargeType, and MostRecentServiceMonth ``` SELECT CHARGEID, CHARGETYPE, MAX(SERVICEMONTH) AS "MostRecentServiceMonth" FRO...
189,228
<p>When writing async method implementations using the BeginInvoke/EndInvoke pattern the code might look something like the following (and to save you guessing this is an async wrapper around a cache):</p> <pre><code>IAsyncResult BeginPut(string key, object value) { Action&lt;string, object&gt; put = this.cache.Pu...
[ { "answer_id": 189266, "author": "Mark Brackett", "author_id": 2199, "author_profile": "https://Stackoverflow.com/users/2199", "pm_score": 0, "selected": false, "text": "<p>Why not avoid the problem by just going back to the more general overload:</p>\n\n<pre><code>IAsyncResult BeginPut(...
2008/10/09
[ "https://Stackoverflow.com/questions/189228", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13552/" ]
When writing async method implementations using the BeginInvoke/EndInvoke pattern the code might look something like the following (and to save you guessing this is an async wrapper around a cache): ``` IAsyncResult BeginPut(string key, object value) { Action<string, object> put = this.cache.Put; return put.Be...
I was wrong, there is a cleaner way. You create `Action( IAsyncResult )` delegates for the specific `EndInvoke()` method in the same context where you already know the specific type of the delegate, passing it as the AsyncState. I'm passing `EndPut()` as the callback for convenience. ``` IAsyncResult BeginPut( string...
189,239
<p>What I'm trying to do with <code>FileStream</code> in C#/.NET is to open two streams: one appending to a file and the other reading those writes asynchronously (for unit testing some network connection handling code). I can't figure out how to get the <em>writer</em> stream to open the file in non-exlusive locking ...
[ { "answer_id": 189245, "author": "Rob Walker", "author_id": 3631, "author_profile": "https://Stackoverflow.com/users/3631", "pm_score": 4, "selected": true, "text": "<p>See this question: <a href=\"https://stackoverflow.com/questions/124946/c-file-readwrite-fileshare-doesnt-appear-to-wor...
2008/10/09
[ "https://Stackoverflow.com/questions/189239", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9642/" ]
What I'm trying to do with `FileStream` in C#/.NET is to open two streams: one appending to a file and the other reading those writes asynchronously (for unit testing some network connection handling code). I can't figure out how to get the *writer* stream to open the file in non-exlusive locking mode and thus the code...
See this question: [C# file read/write fileshare doesn’t appear to work](https://stackoverflow.com/questions/124946/c-file-readwrite-fileshare-doesnt-appear-to-work) In short, your freader has to specify FileShare.Write to allow for the fact that there is already a writer on the file.
189,280
<p>I use NHibernate for my dataacess, and for awhile not I've been using SQLite for local integration tests. I've been using a file, but I thought I would out the :memory: option. When I fire up any of the integration tests, the database seems to be created (NHibernate spits out the table creation sql) but interfacti...
[ { "answer_id": 192084, "author": "chills42", "author_id": 23855, "author_profile": "https://Stackoverflow.com/users/23855", "pm_score": 0, "selected": false, "text": "<p>Just a wild guess, but is the sql output by NHibernate using a command unsupported by sqlite?</p>\n\n<p>Also, What hap...
2008/10/09
[ "https://Stackoverflow.com/questions/189280", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5802/" ]
I use NHibernate for my dataacess, and for awhile not I've been using SQLite for local integration tests. I've been using a file, but I thought I would out the :memory: option. When I fire up any of the integration tests, the database seems to be created (NHibernate spits out the table creation sql) but interfacting wi...
A SQLite memory database only exists as long as the connection to it remains open. To use it in unit tests with NHibernate: 1. Open an ISession at the beginning of your test (maybe in a [SetUp] method). 2. Use the connection from that session in your SchemaExport call. 3. Use that same session in your tests. ...
189,293
<p>I have a subroutine that takes a filehandle as an argument. How do I make a filehandle from a file path specified on the command line? I don't want to do any processing of this file myself, I just want to pass it off to this other subroutine, which returns an array of hashes with all the parsed data from the file....
[ { "answer_id": 189314, "author": "bmdhacks", "author_id": 14032, "author_profile": "https://Stackoverflow.com/users/14032", "pm_score": -1, "selected": false, "text": "<p>Am I missing something or are you just looking for the open() call?</p>\n\n<pre><code>open($fh, \"&lt;$ARGV[0]\") or ...
2008/10/09
[ "https://Stackoverflow.com/questions/189293", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6406/" ]
I have a subroutine that takes a filehandle as an argument. How do I make a filehandle from a file path specified on the command line? I don't want to do any processing of this file myself, I just want to pass it off to this other subroutine, which returns an array of hashes with all the parsed data from the file. Her...
Command line arguments are available in the predefined `@ARGV` array. You can get the file name from there and use `open` to open a filehandle to it. Assuming that you want read-only access to the file, you would do it this way: ``` my $file = shift @ARGV; open(my $fh, '<', $file) or die "Can't read file '$file' [$!]\...
189,308
<h2>Problem</h2> <p>Our web host provider is changing the IP address of one of the servers we are on. We have been given a time frame for when the switch will take place, but no exact details. Therefore, our current <em>poor man's</em> check requires a periodic page refresh on a browser to see if our website is still t...
[ { "answer_id": 189653, "author": "aphoria", "author_id": 2441, "author_profile": "https://Stackoverflow.com/users/2441", "pm_score": 0, "selected": false, "text": "<p>This will list the IP Address for each network adapter in your system.</p>\n\n<pre><code>Get-WmiObject -Class Win32_Netwo...
2008/10/09
[ "https://Stackoverflow.com/questions/189308", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4916/" ]
Problem ------- Our web host provider is changing the IP address of one of the servers we are on. We have been given a time frame for when the switch will take place, but no exact details. Therefore, our current *poor man's* check requires a periodic page refresh on a browser to see if our website is still there. Que...
If you can alert if the page is gone or does not have an expected value, you could use a script like ``` $ip = 192.168.1.1 $webclient = new-object System.Net.WebClient $regex = 'regular expression to match something on your page' $ping = new-object System.Net.NetworkInformation.Ping do { $result = $ping.Send($ip) ...
189,339
<p>I've just got a fresh Drupal 6 install. The CSS didn't work. Then I realized that a "?U" was appended, and Drupal couldn't find it. Does anyone know where to unset this? </p> <pre><code>&lt;link type="text/css" rel="stylesheet" media="all" href="/modules/node/node.css?U" /&gt; &lt;link type="text/css" rel="styl...
[ { "answer_id": 189394, "author": "Owen", "author_id": 4853, "author_profile": "https://Stackoverflow.com/users/4853", "pm_score": 3, "selected": false, "text": "<p>the ?U (or really any alphabet) is just a method drupal uses to cache information. it has no relevance to the location of th...
2008/10/09
[ "https://Stackoverflow.com/questions/189339", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11927/" ]
I've just got a fresh Drupal 6 install. The CSS didn't work. Then I realized that a "?U" was appended, and Drupal couldn't find it. Does anyone know where to unset this? ``` <link type="text/css" rel="stylesheet" media="all" href="/modules/node/node.css?U" /> <link type="text/css" rel="stylesheet" media="all" href="/...
the ?U (or really any alphabet) is just a method drupal uses to cache information. it has no relevance to the location of the file (ie, node.css and node.css?U is in the same location to drupal). it sounds like you may have a different issue. perhaps you enabled your cache and moved things around? you may need to clea...
189,363
<p>How do I write a regular expression to find all lines containing 665 and not having .pdf</p> <p>I can't seem to find how to do not in regex. This is for Notepad++ syntax if it matters.</p> <p>Thanks</p>
[ { "answer_id": 189383, "author": "John Nilsson", "author_id": 24243, "author_profile": "https://Stackoverflow.com/users/24243", "pm_score": 2, "selected": false, "text": "<p>The feature you'r looking for is look ahead patterns</p>\n\n<pre><code>665(?!.*\\.pdf)\n</code></pre>\n" }, { ...
2008/10/09
[ "https://Stackoverflow.com/questions/189363", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13009/" ]
How do I write a regular expression to find all lines containing 665 and not having .pdf I can't seem to find how to do not in regex. This is for Notepad++ syntax if it matters. Thanks
If `.pdf` will only occur after `665`, the negative lookahead assertion `665(?!.*\.pdf)` should work fine. Otherwise, I prefer to use two regexs, one to match, one to fail. In Perl syntax that would be: ``` /665/ && !/\.pdf/ ```
189,368
<p>Here's my situation - I want to create a resized jpeg image from a user uploaded image, and then send it to S3 for storage, but am looking to avoid writing the resized jpeg to the disk and then reloading it for the S3 request.</p> <p>Is there a way to do this completely in memory, with the image data JPEG formatted...
[ { "answer_id": 189381, "author": "moonshadow", "author_id": 11834, "author_profile": "https://Stackoverflow.com/users/11834", "pm_score": 2, "selected": false, "text": "<p>The Imagemagick library will let you do that. There are plenty of PHP wrappers like <a href=\"http://uk.php.net/imag...
2008/10/09
[ "https://Stackoverflow.com/questions/189368", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24694/" ]
Here's my situation - I want to create a resized jpeg image from a user uploaded image, and then send it to S3 for storage, but am looking to avoid writing the resized jpeg to the disk and then reloading it for the S3 request. Is there a way to do this completely in memory, with the image data JPEG formatted, saved in...
Most people using PHP choose either [ImageMagick](http://www.php.net/manual/en/book.imagick.php) or [Gd2](http://www.php.net/manual/en/ref.image.php) I've never used Imagemagick; the Gd2 method: ``` <?php // assuming your uploaded file was 'userFileName' if ( ! is_uploaded_file(validateFilePath($_FILES[$userFileNam...
189,375
<p>With a view to avoiding the construction of further barriers to migration whilst enhancing an existing vb6 program. Is there a way to achieve the same functionality as control arrays in vb6 without using them?</p>
[ { "answer_id": 190443, "author": "onedaywhen", "author_id": 15354, "author_profile": "https://Stackoverflow.com/users/15354", "pm_score": 0, "selected": false, "text": "<p>Well, you could always create your own array of controls in code :) Perhaps a better container, though, is a Collect...
2008/10/09
[ "https://Stackoverflow.com/questions/189375", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6164/" ]
With a view to avoiding the construction of further barriers to migration whilst enhancing an existing vb6 program. Is there a way to achieve the same functionality as control arrays in vb6 without using them?
In .NET you have a tag property. You can also have the same delegate handle events raised by multiple controls. Set the Tag property of the new control to the Index. ``` Private Sub MyButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click,Button2.Click Dim Btn As Butto...
189,392
<p>I'm trying to return a transparent GIF from an .aspx page for display within a web page. I am trying to get the image to have transparency, but I just keep getting Black being where the image should be Transparent.</p> <p>Does anyone know what I'm doing wrong?</p> <pre><code>Protected Sub Page_Load(ByVal sender As...
[ { "answer_id": 189447, "author": "Jérôme Laban", "author_id": 26346, "author_profile": "https://Stackoverflow.com/users/26346", "pm_score": 4, "selected": true, "text": "<p>Unfortunately, there is no easy way to create a transparent Gif using a Bitmap object. (See <a href=\"http://suppor...
2008/10/09
[ "https://Stackoverflow.com/questions/189392", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7831/" ]
I'm trying to return a transparent GIF from an .aspx page for display within a web page. I am trying to get the image to have transparency, but I just keep getting Black being where the image should be Transparent. Does anyone know what I'm doing wrong? ``` Protected Sub Page_Load(ByVal sender As Object, ByVal e As S...
Unfortunately, there is no easy way to create a transparent Gif using a Bitmap object. (See [this KB article](http://support.microsoft.com/default.aspx?scid=kb%3bEN-US%3bQ319061)) You can alternatively use the PNG format that supports transparency with the code you are using.
189,415
<p>I have the following string:</p> <p><code>$_='364*84252';</code></p> <p>The question is: how to replace <code>*</code> in the string with something else? I've tried <code>s/\*/$i/</code>, but there is an error: <code>Quantifier follows nothing in regex</code>. On the other hand <code>s/'*'/$i/</code> doesn't caus...
[ { "answer_id": 189428, "author": "Vinko Vrsalovic", "author_id": 5190, "author_profile": "https://Stackoverflow.com/users/5190", "pm_score": 3, "selected": false, "text": "<p>Something else is weird here...</p>\n\n<pre><code>~&gt; cat test.pl\n$a = \"234*343\";\n$i = \"FOO\";\n\n$a =~ s/...
2008/10/09
[ "https://Stackoverflow.com/questions/189415", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have the following string: `$_='364*84252';` The question is: how to replace `*` in the string with something else? I've tried `s/\*/$i/`, but there is an error: `Quantifier follows nothing in regex`. On the other hand `s/'*'/$i/` doesn't cause any errors, but it also doesn't seem to have any effect at all.
Something else is weird here... ``` ~> cat test.pl $a = "234*343"; $i = "FOO"; $a =~ s/\*/$i/; print $a; ~> perl test.pl 234FOO343 ``` Found something: ``` ~> cat test.pl $a = "234*343"; $i = "*4"; $a =~ m/$i/; print $a; ~> perl test.pl Quantifier follows nothing in regex; marked by <-- HERE in m/* <-- HERE 4/ ...
189,422
<p>I need to do a join across two different database servers (IPs 10.0.0.50 and 10.0.0.51). What's the best way?</p>
[ { "answer_id": 189431, "author": "Ben Hoffstein", "author_id": 4482, "author_profile": "https://Stackoverflow.com/users/4482", "pm_score": 5, "selected": true, "text": "<p>You need to use sp_linkedserver to create a linked server.</p>\n\n<pre><code>sp_addlinkedserver [ @server= ] 'server...
2008/10/09
[ "https://Stackoverflow.com/questions/189422", "https://Stackoverflow.com", "https://Stackoverflow.com/users/109/" ]
I need to do a join across two different database servers (IPs 10.0.0.50 and 10.0.0.51). What's the best way?
You need to use sp\_linkedserver to create a linked server. ``` sp_addlinkedserver [ @server= ] 'server' [ , [ @srvproduct= ] 'product_name' ] [ , [ @provider= ] 'provider_name' ] [ , [ @datasrc= ] 'data_source' ] [ , [ @location= ] 'location' ] [ , [ @provstr= ] 'provider_string' ] [ , [ @catalog= ] 'catalog...
189,433
<p>I am running Visual Studio Team Edition 2008. <br /> <br /> <br /> When I create a new website, I get a new file I've never seen before: <em>vwd.webinfo</em>.</p> <p>The contents of this file is as follows:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;VisualWebDeveloper&gt; &lt;!-- Visual St...
[ { "answer_id": 189466, "author": "mannu", "author_id": 15858, "author_profile": "https://Stackoverflow.com/users/15858", "pm_score": 3, "selected": true, "text": "<p>It is created because you are using a file system web site. Read more about it here:\n<a href=\"http://msdn.microsoft.com/...
2008/10/09
[ "https://Stackoverflow.com/questions/189433", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20946/" ]
I am running Visual Studio Team Edition 2008. When I create a new website, I get a new file I've never seen before: *vwd.webinfo*. The contents of this file is as follows: ``` <?xml version="1.0" encoding="UTF-8"?> <VisualWebDeveloper> <!-- Visual Studio global web project settings. --> <StartupServices> ...
It is created because you are using a file system web site. Read more about it here: <http://msdn.microsoft.com/en-us/library/e5x4xz73.aspx> What do you mean with "bloat" ? Can you please paste the bloat?
189,436
<p>When I try to test the AutoLotWCFService using "wcftestclient", I get the following error. What am I doing wrong? Any insight will help. This is a simple Web Service that has wshttpbinding with interface contract and the implementation in the service. Here is the long error message: The Web.Config file has 2 endpoin...
[ { "answer_id": 189459, "author": "Craig Wilson", "author_id": 25333, "author_profile": "https://Stackoverflow.com/users/25333", "pm_score": 0, "selected": false, "text": "<p>you need to make sure that the service behaviour configuration enables has a metadata tag with httpGetEnabled=\"tr...
2008/10/09
[ "https://Stackoverflow.com/questions/189436", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
When I try to test the AutoLotWCFService using "wcftestclient", I get the following error. What am I doing wrong? Any insight will help. This is a simple Web Service that has wshttpbinding with interface contract and the implementation in the service. Here is the long error message: The Web.Config file has 2 endpoints ...
I recently had this problem whilst trying to host WCF on my Windows Vista Laptop under IIS7. I first recieved the following error : "HTTP Error 404.3 - Not Found" and one of the resolutions suggested was to "Ensure that the expected handler for the current page is mapped." So I added a handler for the .svc file manua...
189,468
<p>I've had nothing but good luck from SO, so why not try again?</p> <p>I have an application that needs to show a different image based on the season of the year (spring, summer, winter, fall). I have very specific start and end dates for these seasons.</p> <p>What I would like from you geniuses is a method called...
[ { "answer_id": 189504, "author": "nsayer", "author_id": 13757, "author_profile": "https://Stackoverflow.com/users/13757", "pm_score": 1, "selected": false, "text": "<p>Well, it could be as simple as</p>\n\n<pre><code>String getSeason(int month) {\n switch(month) {\n case 11:\...
2008/10/09
[ "https://Stackoverflow.com/questions/189468", "https://Stackoverflow.com", "https://Stackoverflow.com/users/172/" ]
I've had nothing but good luck from SO, so why not try again? I have an application that needs to show a different image based on the season of the year (spring, summer, winter, fall). I have very specific start and end dates for these seasons. What I would like from you geniuses is a method called GetSeason that tak...
Seems like just checking the month would do: ``` private static final String seasons[] = { "Winter", "Winter", "Spring", "Spring", "Summer", "Summer", "Summer", "Summer", "Fall", "Fall", "Winter", "Winter" }; public String getSeason( Date date ) { return seasons[ date.getMonth() ]; } // As stated above, getMo...
189,479
<p>When I created the project I'm trying to deploy I selected that I wanted to target .NET Framework 2.0. After deploying the project I try to brows to it and get and error page that shows:</p> <pre><code>&lt;compilation debug="true"&gt; &lt;assemblies&gt; &lt;add assembly="System.Web.Entity, Version=3.5.0...
[ { "answer_id": 189487, "author": "Jimmy", "author_id": 4435, "author_profile": "https://Stackoverflow.com/users/4435", "pm_score": 1, "selected": false, "text": "<p>remove those references from your project and redeploy. if your project started as 3.5 it will still have references to som...
2008/10/09
[ "https://Stackoverflow.com/questions/189479", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4491/" ]
When I created the project I'm trying to deploy I selected that I wanted to target .NET Framework 2.0. After deploying the project I try to brows to it and get and error page that shows: ``` <compilation debug="true"> <assemblies> <add assembly="System.Web.Entity, Version=3.5.0.0, Culture=neutral, PublicKe...
You are referencing assemblies of the .NET Framework 3.5, are you using EntityDataSources?? Remove those 3.5 references... You also need the AJAX Extensions (System.Web.Extensions) for .NET 2.0 on the server.
189,522
<p>any thoughts on this would be appreciated:</p> <pre><code>std::string s1 = "hello"; std::string s2 = std::string(s1); </code></pre> <p>I'd now expect these two strings to be independent, i.e. I could append ", world" to s2 and s1 would still read "hello". This is what I find on windows and linux but running the co...
[ { "answer_id": 189538, "author": "Jim Buck", "author_id": 2666, "author_profile": "https://Stackoverflow.com/users/2666", "pm_score": 2, "selected": false, "text": "<p>This must be a bug. std::string could do reference-counted strings as its implementation, but once it gets changed, it's...
2008/10/09
[ "https://Stackoverflow.com/questions/189522", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26665/" ]
any thoughts on this would be appreciated: ``` std::string s1 = "hello"; std::string s2 = std::string(s1); ``` I'd now expect these two strings to be independent, i.e. I could append ", world" to s2 and s1 would still read "hello". This is what I find on windows and linux but running the code on a HP\_UX machine it ...
Although I could not reproduce the exact bug of the OP, I came across a similar bug in the HP-UX aCC compilers. I posted about it on the [HP boards](http://forums12.itrc.hp.com/service/forums/questionanswer.do?admit=109447627+1223649583692+28353475&threadId=1108413), and eventually got a response from HP. Basically the...
189,523
<p>I have already extracted the tag from the source document using grep but, now I cant seem to figure out how to easily extract the properties from the string. Also I want to avoid having to use any programs that would not usually be present on a standard installation. </p> <pre><code>$tag='&lt;img src="http://imgs...
[ { "answer_id": 189735, "author": "GameFreak", "author_id": 26659, "author_profile": "https://Stackoverflow.com/users/26659", "pm_score": 1, "selected": false, "text": "<p>I went with dacracot's suggestion of using sed although I would have prefered if he had given me some sample code </p...
2008/10/09
[ "https://Stackoverflow.com/questions/189523", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26659/" ]
I have already extracted the tag from the source document using grep but, now I cant seem to figure out how to easily extract the properties from the string. Also I want to avoid having to use any programs that would not usually be present on a standard installation. ``` $tag='<img src="http://imgs.xkcd.com/comics/ba...
You can use [xmlstarlet](http://xmlstar.sourceforge.net/). Then, you don't even have to extract the element yourself: ``` $ echo $tag|xmlstarlet sel -t --value-of '//img/@src' http://imgs.xkcd.com/comics/barrel_cropped_(1).jpg ``` You can even turn this into a function ``` $ get_attribute() { echo $1 | xmlstarlet...
189,549
<p>Is it possible to embed a pre-existing DLL into a compiled C# executable (so that you only have one file to distribute)? If it is possible, how would one go about doing it?</p> <p>Normally, I'm cool with just leaving the DLLs outside and having the setup program handle everything, but there have been a couple of pe...
[ { "answer_id": 189554, "author": "MusiGenesis", "author_id": 14606, "author_profile": "https://Stackoverflow.com/users/14606", "pm_score": 3, "selected": false, "text": "<p>You could add the DLLs as embedded resources, and then have your program unpack them into the application directory...
2008/10/09
[ "https://Stackoverflow.com/questions/189549", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5133/" ]
Is it possible to embed a pre-existing DLL into a compiled C# executable (so that you only have one file to distribute)? If it is possible, how would one go about doing it? Normally, I'm cool with just leaving the DLLs outside and having the setup program handle everything, but there have been a couple of people at wo...
I highly recommend to use [Costura.Fody](https://github.com/Fody/Costura) - by far the best and easiest way to embed resources in your assembly. It's available as NuGet package. ``` Install-Package Costura.Fody ``` After adding it to the project, it will automatically embed all references that are copied to the outp...
189,555
<p>I want to download and parse webpage using python, but to access it I need a couple of cookies set. Therefore I need to login over https to the webpage first. The login moment involves sending two POST params (username, password) to /login.php. During the login request I want to retrieve the cookies from the respons...
[ { "answer_id": 189580, "author": "Harley Holcombe", "author_id": 1057, "author_profile": "https://Stackoverflow.com/users/1057", "pm_score": 8, "selected": true, "text": "<pre><code>import urllib, urllib2, cookielib\n\nusername = 'myuser'\npassword = 'mypassword'\n\ncj = cookielib.Cookie...
2008/10/09
[ "https://Stackoverflow.com/questions/189555", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26668/" ]
I want to download and parse webpage using python, but to access it I need a couple of cookies set. Therefore I need to login over https to the webpage first. The login moment involves sending two POST params (username, password) to /login.php. During the login request I want to retrieve the cookies from the response h...
``` import urllib, urllib2, cookielib username = 'myuser' password = 'mypassword' cj = cookielib.CookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) login_data = urllib.urlencode({'username' : username, 'j_password' : password}) opener.open('http://www.example.com/login.php', login_data) resp =...
189,559
<p>Conditions: do not modify the original lists; JDK only, no external libraries. Bonus points for a one-liner or a JDK 1.3 version.</p> <p>Is there a simpler way than:</p> <pre class="lang-java prettyprint-override"><code>List&lt;String&gt; newList = new ArrayList&lt;String&gt;(); newList.addAll(listOne); newList.addA...
[ { "answer_id": 189568, "author": "Tim", "author_id": 5284, "author_profile": "https://Stackoverflow.com/users/5284", "pm_score": 5, "selected": false, "text": "<p>Slightly simpler:</p>\n\n<pre><code>List&lt;String&gt; newList = new ArrayList&lt;String&gt;(listOne);\nnewList.addAll(listTw...
2008/10/09
[ "https://Stackoverflow.com/questions/189559", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17294/" ]
Conditions: do not modify the original lists; JDK only, no external libraries. Bonus points for a one-liner or a JDK 1.3 version. Is there a simpler way than: ```java List<String> newList = new ArrayList<String>(); newList.addAll(listOne); newList.addAll(listTwo); ```
In Java 8: ``` List<String> newList = Stream.concat(listOne.stream(), listTwo.stream()) .collect(Collectors.toList()); ``` Java 16+: ``` List<String> newList = Stream.concat(listOne.stream(), listTwo.stream()).toList(); ```
189,562
<p>There are many ways of doing debugging, using a debugger is one, but the simple one for the humble, lazy, programmer is to just add a bunch of print statements to your code.</p> <p>i.e.</p> <pre><code> def foo(x): print 'Hey wow, we got to foo!', x ... print 'foo is returning:', bar return ba...
[ { "answer_id": 189570, "author": "Shog9", "author_id": 811, "author_profile": "https://Stackoverflow.com/users/811", "pm_score": 7, "selected": true, "text": "<p>Yes - it's known as <strong><code>printf()</code> debugging</strong>, named after the ubiquitous C function:</p>\n\n<blockquot...
2008/10/09
[ "https://Stackoverflow.com/questions/189562", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14648/" ]
There are many ways of doing debugging, using a debugger is one, but the simple one for the humble, lazy, programmer is to just add a bunch of print statements to your code. i.e. ``` def foo(x): print 'Hey wow, we got to foo!', x ... print 'foo is returning:', bar return bar ``` Is there a pr...
Yes - it's known as **`printf()` debugging**, named after the ubiquitous C function: > > Used > to describe debugging work done by > inserting commands that output more or > less carefully chosen status > information at key points in the > program flow, observing that > information and deducing what's wrong > ...
189,588
<p>I've been led to believe that for single variable assignment in T-SQL, <code>set</code> is the best way to go about things, for two reasons:</p> <ul> <li>it's the ANSI standard for variable assignment</li> <li>it's actually faster than doing a SELECT (for a single variable)</li> </ul> <p>So...</p> <pre><code>SELE...
[ { "answer_id": 189597, "author": "Mark", "author_id": 26310, "author_profile": "https://Stackoverflow.com/users/26310", "pm_score": 0, "selected": false, "text": "<p>Take a look at the \"execution plan\", it should tell you the cost of each line of your statement</p>\n" }, { "ans...
2008/10/09
[ "https://Stackoverflow.com/questions/189588", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1030/" ]
I've been led to believe that for single variable assignment in T-SQL, `set` is the best way to go about things, for two reasons: * it's the ANSI standard for variable assignment * it's actually faster than doing a SELECT (for a single variable) So... ``` SELECT @thingy = 'turnip shaped' ``` becomes ``` SET @thin...
SET is faster on single runs. You can prove this easily enough. Whether or not it makes a difference is up to you, but I prefer SET, since I don't see the point of SELECT if all the code is doing is an assignment. I prefer to keep SELECT confined to SELECT statements from tables, views, etc. Here is a sample script, w...
189,610
<p>Imagine I have a chunk of initialisation code at the top of a stored procedure with a number of variable assignments:</p> <pre><code>SET @proc = 'sp_madeupname' SET @magic_number = 42 SET @tomorrows_date = DATEADD(dd, 1, GETDATE()) ... </code></pre> <p>Clearly doing all of the above as one SELECT would be faster:<...
[ { "answer_id": 189626, "author": "Cade Roux", "author_id": 18255, "author_profile": "https://Stackoverflow.com/users/18255", "pm_score": 0, "selected": false, "text": "<p>I've thought about it but never tested it.</p>\n\n<p>In my experience, the optimizer is pretty good, so I would think...
2008/10/09
[ "https://Stackoverflow.com/questions/189610", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1030/" ]
Imagine I have a chunk of initialisation code at the top of a stored procedure with a number of variable assignments: ``` SET @proc = 'sp_madeupname' SET @magic_number = 42 SET @tomorrows_date = DATEADD(dd, 1, GETDATE()) ... ``` Clearly doing all of the above as one SELECT would be faster: ``` SELECT @proc = '...
In this case, SELECT wins, performance-wise, when performing multiple assignments. Here is some more information about it: [SELECT vs. SET: Optimizing Loops](http://www.sqlmag.com/Articles/ArticleID/94555/94555.html)
189,622
<p>I frequently encounter some definitions for Win32API structures (but not limited to it) that have a <code>cbSize</code> member as in the following example.</p> <pre><code>typedef struct _TEST { int cbSize; // other members follow } TEST, *PTEST; </code></pre> <p>And then we use it like this:</p> <pre><cod...
[ { "answer_id": 189628, "author": "Michael Burr", "author_id": 12711, "author_profile": "https://Stackoverflow.com/users/12711", "pm_score": 5, "selected": true, "text": "<blockquote>\n <p>My initial guess is that this could\n potentially be used for versioning.</p>\n</blockquote>\n\n<p...
2008/10/09
[ "https://Stackoverflow.com/questions/189622", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6508/" ]
I frequently encounter some definitions for Win32API structures (but not limited to it) that have a `cbSize` member as in the following example. ``` typedef struct _TEST { int cbSize; // other members follow } TEST, *PTEST; ``` And then we use it like this: ``` TEST t = { sizeof(TEST) }; ... ``` or ``` T...
> > My initial guess is that this could > potentially be used for versioning. > > > That's one reason. I think it's the more usual one. Another is for structures that have variable length data. I don't think that checking for correct packing or bugs in the caller are a particular reasoning behind it, but it wou...
189,645
<p>Given the following code (that doesn't work):</p> <pre><code>while True: # Snip: print out current state while True: ok = get_input(&quot;Is this ok? (y/n)&quot;) if ok.lower() == &quot;y&quot;: break 2 # This doesn't work :( if ok.lower() == &quot;n&quot;: break # Do more proces...
[ { "answer_id": 189664, "author": "S.Lott", "author_id": 10661, "author_profile": "https://Stackoverflow.com/users/10661", "pm_score": 7, "selected": false, "text": "<p>First, ordinary logic is helpful. </p>\n\n<p>If, for some reason, the terminating conditions can't be worked out, excep...
2008/10/10
[ "https://Stackoverflow.com/questions/189645", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15537/" ]
Given the following code (that doesn't work): ``` while True: # Snip: print out current state while True: ok = get_input("Is this ok? (y/n)") if ok.lower() == "y": break 2 # This doesn't work :( if ok.lower() == "n": break # Do more processing with menus and stuff ``` Is there a ...
My first instinct would be to refactor the nested loop into a function and use `return` to break out.
189,680
<p>i am looking for opinions if the following problem maybe has a better/different/common solution:</p> <hr> <p>I have a database for products which contains the names of the products in english (the default language of this application) and i need translations of the names if available.</p> <p>Currently i have this...
[ { "answer_id": 189693, "author": "Daniel Spiewak", "author_id": 9815, "author_profile": "https://Stackoverflow.com/users/9815", "pm_score": 4, "selected": true, "text": "<p>Looks good to me. The one thing I might change is the way you handle languages: that should probably be a separate...
2008/10/10
[ "https://Stackoverflow.com/questions/189680", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21566/" ]
i am looking for opinions if the following problem maybe has a better/different/common solution: --- I have a database for products which contains the names of the products in english (the default language of this application) and i need translations of the names if available. Currently i have this setup: A product...
Looks good to me. The one thing I might change is the way you handle languages: that should probably be a separate table. Thus, you would have: ``` CREATE TABLE products_l10n ( product_id serial NOT NULL, language_id int NOT NULL, "name" character varying(255) NOT NULL, CONSTRAINT products_l10n_pkey PRIMARY KE...
189,725
<p>During recent discussions at work, someone referred to a trampoline function.</p> <p>I have read the description at <a href="http://en.wikipedia.org/wiki/Trampoline_(computers)" rel="noreferrer">Wikipedia</a>. It is enough to give a general idea of the functionality, but I would like something a bit more concrete....
[ { "answer_id": 189749, "author": "Gerald", "author_id": 19404, "author_profile": "https://Stackoverflow.com/users/19404", "pm_score": 5, "selected": false, "text": "<p>I'll give you an example that I used in an anti-cheat patch for an online game.</p>\n\n<p>I needed to be able to scan al...
2008/10/10
[ "https://Stackoverflow.com/questions/189725", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10703/" ]
During recent discussions at work, someone referred to a trampoline function. I have read the description at [Wikipedia](http://en.wikipedia.org/wiki/Trampoline_(computers)). It is enough to give a general idea of the functionality, but I would like something a bit more concrete. Do you have a simple snippet of code ...
There is also the LISP sense of 'trampoline' as described on Wikipedia: > > Used in some LISP implementations, a > trampoline is a loop that iteratively > invokes thunk-returning functions. A > single trampoline is sufficient to > express all control transfers of a > program; a program so expressed is > trampol...
189,751
<p>I've setup a static website on GAE using hints found elsewhere, but can't figure out how to return a 404 error. My app.yaml file looks like</p> <pre><code>- url: (.*)/ static_files: static\1/index.html upload: static/index.html - url: / static_dir: static </code></pre> <p>with all the static html/jpg files ...
[ { "answer_id": 189935, "author": "Alexander Kojevnikov", "author_id": 712, "author_profile": "https://Stackoverflow.com/users/712", "pm_score": 6, "selected": true, "text": "<p>You need to register a catch-all script handler. Append this at the end of your app.yaml:</p>\n\n<pre><code>- u...
2008/10/10
[ "https://Stackoverflow.com/questions/189751", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26683/" ]
I've setup a static website on GAE using hints found elsewhere, but can't figure out how to return a 404 error. My app.yaml file looks like ``` - url: (.*)/ static_files: static\1/index.html upload: static/index.html - url: / static_dir: static ``` with all the static html/jpg files stored under the static di...
You need to register a catch-all script handler. Append this at the end of your app.yaml: ``` - url: /.* script: main.py ``` In main.py you will need to put this code: ``` from google.appengine.ext import webapp from google.appengine.ext.webapp.util import run_wsgi_app class NotFoundPageHandler(webapp.RequestHan...
189,765
<p>I have a query that ran fine on SQL2005 but moving the database to SQL2008 gives me the error from the title.</p> <p>The code that is the problem is a call to CONTAINS, CONTAINSTABLE or FREETEXT with an empty parameter. However I'm trying to only call or join when there is a value like such</p> <pre><code>where (@...
[ { "answer_id": 347232, "author": "NotMe", "author_id": 2424, "author_profile": "https://Stackoverflow.com/users/2424", "pm_score": 6, "selected": false, "text": "<p>I found the answer to this today when converting my own database from SQL 2005 to SQL 2008.</p>\n\n<p>Pass <code>\"\"</code...
2008/10/10
[ "https://Stackoverflow.com/questions/189765", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6084/" ]
I have a query that ran fine on SQL2005 but moving the database to SQL2008 gives me the error from the title. The code that is the problem is a call to CONTAINS, CONTAINSTABLE or FREETEXT with an empty parameter. However I'm trying to only call or join when there is a value like such ``` where (@search_term = '' or (...
I found the answer to this today when converting my own database from SQL 2005 to SQL 2008. Pass `""` for your search term and change the @search\_term = `''` test to be `@search_term = '""'` SQL server will ignore the double quotes and not throw an error. For example, the following would actually returns all records...
189,770
<p>How would you go about retrieving the @@IDENTITY value for each row when the SQLDataAdapater.Update is executed on a table?</p> <p>eg. Is it possible to modify/intercept the InsertCommand, generated by the SQLCommandBuilder, to say add an output parameter, and then retrieve its value in the da.RowUpdated event???</...
[ { "answer_id": 347232, "author": "NotMe", "author_id": 2424, "author_profile": "https://Stackoverflow.com/users/2424", "pm_score": 6, "selected": false, "text": "<p>I found the answer to this today when converting my own database from SQL 2005 to SQL 2008.</p>\n\n<p>Pass <code>\"\"</code...
2008/10/10
[ "https://Stackoverflow.com/questions/189770", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1885/" ]
How would you go about retrieving the @@IDENTITY value for each row when the SQLDataAdapater.Update is executed on a table? eg. Is it possible to modify/intercept the InsertCommand, generated by the SQLCommandBuilder, to say add an output parameter, and then retrieve its value in the da.RowUpdated event???
I found the answer to this today when converting my own database from SQL 2005 to SQL 2008. Pass `""` for your search term and change the @search\_term = `''` test to be `@search_term = '""'` SQL server will ignore the double quotes and not throw an error. For example, the following would actually returns all records...
189,787
<p>I have never seen a way to do this nicely, i would be interested in seeing how others do it. Currently i format it like this:</p> <pre><code>public Booking createVehicleBooking(Long officeId, Long start, Long end, ...
[ { "answer_id": 189793, "author": "John Millikin", "author_id": 3560, "author_profile": "https://Stackoverflow.com/users/3560", "pm_score": 4, "selected": false, "text": "<pre><code>public Booking createVehicleBooking(\n Long officeId, \n Long start, \n Long end,\n String orig...
2008/10/10
[ "https://Stackoverflow.com/questions/189787", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24390/" ]
I have never seen a way to do this nicely, i would be interested in seeing how others do it. Currently i format it like this: ``` public Booking createVehicleBooking(Long officeId, Long start, Long end, String...
A large set of parameters like this is often (but not always) an indicator that you could be using an object to represent the parameter set. This is especially true if either: * There are several methods with similar large parameter sets, that can be replaced with a single method taking a parameter object. * The metho...