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
147,468
<p><a href="https://pmd.github.io/" rel="noreferrer">PMD</a> would report a violation for:</p> <pre><code>ArrayList&lt;Object&gt; list = new ArrayList&lt;Object&gt;(); </code></pre> <p>The violation was "Avoid using implementation types like 'ArrayList'; use the interface instead".</p> <p>The following line would co...
[ { "answer_id": 147472, "author": "AdamC", "author_id": 16476, "author_profile": "https://Stackoverflow.com/users/16476", "pm_score": 5, "selected": false, "text": "<p>This is preferred because you decouple your code from the implementation of the list. Using the interface lets you easil...
2008/09/29
[ "https://Stackoverflow.com/questions/147468", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22807/" ]
[PMD](https://pmd.github.io/) would report a violation for: ``` ArrayList<Object> list = new ArrayList<Object>(); ``` The violation was "Avoid using implementation types like 'ArrayList'; use the interface instead". The following line would correct the violation: ``` List<Object> list = new ArrayList<Object>(); `...
Using interfaces over concrete types is the key for good encapsulation and for loose coupling your code. It's even a good idea to follow this practice when writing your own APIs. If you do, you'll find later that it's easier to add unit tests to your code (using Mocking techniques), and to change the underlying implem...
147,486
<p>Given the following XML structure</p> <pre><code>&lt;html&gt; &lt;body&gt; &lt;div&gt; &lt;span&gt;Test: Text2&lt;/span&gt; &lt;/div&gt; &lt;div&gt; &lt;span&gt;Test: Text3&lt;/span&gt; &lt;/div&gt; &lt;div&gt; &lt;span&gt;Test: Text5&lt;/span&gt; &lt;/div&gt; &lt;/body...
[ { "answer_id": 147497, "author": "A. Rex", "author_id": 3508, "author_profile": "https://Stackoverflow.com/users/3508", "pm_score": 6, "selected": true, "text": "<pre><code>//span[starts-with(.,'Test')]\n</code></pre>\n\n<p><br>References:</p>\n\n<p><a href=\"http://www.w3.org/TR/xpath/#...
2008/09/29
[ "https://Stackoverflow.com/questions/147486", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10673/" ]
Given the following XML structure ``` <html> <body> <div> <span>Test: Text2</span> </div> <div> <span>Test: Text3</span> </div> <div> <span>Test: Text5</span> </div> </body> </html> ``` What is the best XPath query to locate any `span` with text that starts with `Test`?
``` //span[starts-with(.,'Test')] ``` References: <http://www.w3.org/TR/xpath/#function-starts-with> <https://developer.mozilla.org/en-US/docs/Web/XPath/Functions/starts-with>
147,491
<p>I have the function below ENCRYPT.</p> <pre><code>Public Function Encrypt(ByVal plainText As String) As Byte() Dim key() As Byte = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24} Dim iv() As Byte = {65, 110, 68, 26, 69, 178, 200, 219} ' Declare a UTF8Encoding object s...
[ { "answer_id": 147502, "author": "aku", "author_id": 1196, "author_profile": "https://Stackoverflow.com/users/1196", "pm_score": 2, "selected": false, "text": "<p>You can use <a href=\"http://msdn.microsoft.com/en-us/library/system.text.encoding.aspx\" rel=\"nofollow noreferrer\">Encodin...
2008/09/29
[ "https://Stackoverflow.com/questions/147491", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21963/" ]
I have the function below ENCRYPT. ``` Public Function Encrypt(ByVal plainText As String) As Byte() Dim key() As Byte = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24} Dim iv() As Byte = {65, 110, 68, 26, 69, 178, 200, 219} ' Declare a UTF8Encoding object so we may use the...
You can use [Encoding](http://msdn.microsoft.com/en-us/library/system.text.encoding.aspx) class. To convert array of bytes to a string you can use [Encoding.GetString](http://msdn.microsoft.com/en-us/library/system.text.encoding.getstring.aspx) method There is a special version for UTF8: [UTF8Encoding.GetString](htt...
147,500
<p>Is it possible to include one CSS file in another?</p>
[ { "answer_id": 147508, "author": "Kevin Read", "author_id": 23303, "author_profile": "https://Stackoverflow.com/users/23303", "pm_score": 11, "selected": true, "text": "<p>Yes:</p>\n\n<pre><code>@import url(\"base.css\");\n</code></pre>\n\n<p>Note:</p>\n\n<ul>\n<li>The <a href=\"https://...
2008/09/29
[ "https://Stackoverflow.com/questions/147500", "https://Stackoverflow.com", "https://Stackoverflow.com/users/460927/" ]
Is it possible to include one CSS file in another?
Yes: ``` @import url("base.css"); ``` Note: * The [`@import`](https://developer.mozilla.org/en-US/docs/Web/CSS/@import) rule [must precede](https://drafts.csswg.org/css-cascade-3/#at-import) all other rules (except `@charset`). * Additional `@import` statements require additional server requests. As an alternative,...
147,505
<p>I am trying to get a Flex application to communicate with a custom python webserver I have developed. </p> <p>I am noticing that I cannot read the postdata received because Flex does not seem to include the Content-Length in the HTTP headers. (My webserver work when posted to from plain HTML)</p> <p>Is this a know...
[ { "answer_id": 147540, "author": "A. Rex", "author_id": 3508, "author_profile": "https://Stackoverflow.com/users/3508", "pm_score": 0, "selected": false, "text": "<p>I don't believe this is a known problem.</p>\n\n<p>Are you sure no Content-Length is being sent? You've posted the reques...
2008/09/29
[ "https://Stackoverflow.com/questions/147505", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1638/" ]
I am trying to get a Flex application to communicate with a custom python webserver I have developed. I am noticing that I cannot read the postdata received because Flex does not seem to include the Content-Length in the HTTP headers. (My webserver work when posted to from plain HTML) Is this a known problem? any id...
It should, so long as you set your HTTPService's method property to POST. If you omit it, it will default to GET, and the parameters will be sent as part of the query string, not as POST data. I set up this scenario using this Flex code: ``` <?xml version="1.0" encoding="utf-8"?> <mx:Application layout="absolute" ...
147,507
<p>Given a string with a module name, how do you import everything in the module as if you had called:</p> <pre><code>from module import * </code></pre> <p>i.e. given string S="module", how does one get the equivalent of the following:</p> <pre><code>__import__(S, fromlist="*") </code></pre> <p>This doesn't seem to...
[ { "answer_id": 147541, "author": "John Millikin", "author_id": 3560, "author_profile": "https://Stackoverflow.com/users/3560", "pm_score": 6, "selected": true, "text": "<p>Please reconsider. The only thing worse than <code>import *</code> is <em>magic</em> <code>import *</code>.</p>\n\n<...
2008/09/29
[ "https://Stackoverflow.com/questions/147507", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19212/" ]
Given a string with a module name, how do you import everything in the module as if you had called: ``` from module import * ``` i.e. given string S="module", how does one get the equivalent of the following: ``` __import__(S, fromlist="*") ``` This doesn't seem to perform as expected (as it doesn't import anythi...
Please reconsider. The only thing worse than `import *` is *magic* `import *`. If you really want to: ``` m = __import__ (S) try: attrlist = m.__all__ except AttributeError: attrlist = dir (m) for attr in attrlist: globals()[attr] = getattr (m, attr) ```
147,515
<p>How do you calculate the least common multiple of multiple numbers?</p> <p>So far I've only been able to calculate it between two numbers. But have no idea how to expand it to calculate 3 or more numbers.</p> <p>So far this is how I did it </p> <pre><code>LCM = num1 * num2 / gcd ( num1 , num2 ) </code></pre> <...
[ { "answer_id": 147523, "author": "A. Rex", "author_id": 3508, "author_profile": "https://Stackoverflow.com/users/3508", "pm_score": 9, "selected": true, "text": "<p>You can compute the LCM of more than two numbers by iteratively computing the LCM of two numbers, i.e.</p>\n\n<pre><code>lc...
2008/09/29
[ "https://Stackoverflow.com/questions/147515", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2976/" ]
How do you calculate the least common multiple of multiple numbers? So far I've only been able to calculate it between two numbers. But have no idea how to expand it to calculate 3 or more numbers. So far this is how I did it ``` LCM = num1 * num2 / gcd ( num1 , num2 ) ``` With gcd is the function to calculate t...
You can compute the LCM of more than two numbers by iteratively computing the LCM of two numbers, i.e. ``` lcm(a,b,c) = lcm(a,lcm(b,c)) ```
147,528
<p>In the markup shown below, I'm trying to get the content div to stretch all the way to the bottom of the page but it's only stretching if there's content to display. The reason I want to do this is so the vertical border still appears down the page even if there isn't any content to display.</p> <p>Here is my <stron...
[ { "answer_id": 147537, "author": "Owen", "author_id": 4853, "author_profile": "https://Stackoverflow.com/users/4853", "pm_score": 3, "selected": false, "text": "<p>you can kinda hack it with the <a href=\"http://www.w3schools.com/CSS/pr_dim_min-height.asp\" rel=\"noreferrer\">min-height<...
2008/09/29
[ "https://Stackoverflow.com/questions/147528", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17211/" ]
In the markup shown below, I'm trying to get the content div to stretch all the way to the bottom of the page but it's only stretching if there's content to display. The reason I want to do this is so the vertical border still appears down the page even if there isn't any content to display. Here is my **DEMO**: ```c...
Your problem is not that the div is not at 100% height, but that the container around it is not.This will help in the browser I suspect you are using: ``` html,body { height:100%; } ``` You may need to adjust padding and margins as well, but this will get you 90% of the way there.If you need to make it work with all...
147,557
<p>I am making my switch from coding in C++ to C#. I need to replace my C++ error logging/reporting macro system with something similar in C#.</p> <p>In my C++ source I can write</p> <p>LOGERR("Some error"); or LOGERR("Error with inputs %s and %d", stringvar, intvar);</p> <p>The macro &amp; supporting library code ...
[ { "answer_id": 147574, "author": "Ben Hoffstein", "author_id": 4482, "author_profile": "https://Stackoverflow.com/users/4482", "pm_score": 3, "selected": false, "text": "<p>Even though I personally hate it, <a href=\"http://logging.apache.org/log4net/index.html\" rel=\"nofollow noreferre...
2008/09/29
[ "https://Stackoverflow.com/questions/147557", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6188/" ]
I am making my switch from coding in C++ to C#. I need to replace my C++ error logging/reporting macro system with something similar in C#. In my C++ source I can write LOGERR("Some error"); or LOGERR("Error with inputs %s and %d", stringvar, intvar); The macro & supporting library code then passes the (possibly var...
Lots of log4net advocates here so I'm sure this will be ignored, but I'll add my own preference: ``` System.Diagnostics.Trace ``` This includes listeners that listen for your `Trace()` methods, and then write to a log file/output window/event log, ones in the framework that are included are `DefaultTraceListener`, `...
147,572
<pre><code>class someclass {}; class base { int a; int *pint; someclass objsomeclass; someclass* psomeclass; public: base() { objsomeclass = someclass(); psomeclass = new someclass(); pint = new int(); throw "constructor failed"; a = 43; } } int mai...
[ { "answer_id": 147578, "author": "Colen", "author_id": 13500, "author_profile": "https://Stackoverflow.com/users/13500", "pm_score": -1, "selected": false, "text": "<p>Everything you \"new\" needs to be deleted, or you'll cause a memory leak. So these two lines:</p>\n\n<pre><code>psomecl...
2008/09/29
[ "https://Stackoverflow.com/questions/147572", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22076/" ]
``` class someclass {}; class base { int a; int *pint; someclass objsomeclass; someclass* psomeclass; public: base() { objsomeclass = someclass(); psomeclass = new someclass(); pint = new int(); throw "constructor failed"; a = 43; } } int main() { ...
Yes it will leak memory. When the constructor throws, no destructor will be called (in this case you don't show a destructor that frees the dynamically allocated objects, but lets assume you had one). This is a major reason to use smart pointers - since the smart poitners are full fledged objects, they will get destr...
147,626
<p>in Javascript, the following:</p> <pre><code>var test = '"the quick" "brown fox" "jumps over" "the lazy dog"'; var result = test.match(/".*?"/g); alert(result); </code></pre> <p>yields "the quick","brown fox","jumps over","the lazy dog"</p> <p>I want each matched element to be unquoted: the quick,brown fox,jumps ...
[ { "answer_id": 147644, "author": "Mark Biek", "author_id": 305, "author_profile": "https://Stackoverflow.com/users/305", "pm_score": 0, "selected": false, "text": "<p>You can use the <a href=\"http://www.w3schools.com/jsref/jsref_replace.asp\" rel=\"nofollow noreferrer\">Javascript repla...
2008/09/29
[ "https://Stackoverflow.com/questions/147626", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11397/" ]
in Javascript, the following: ``` var test = '"the quick" "brown fox" "jumps over" "the lazy dog"'; var result = test.match(/".*?"/g); alert(result); ``` yields "the quick","brown fox","jumps over","the lazy dog" I want each matched element to be unquoted: the quick,brown fox,jumps over,the lazy dog what regexp wi...
This seems to work: ``` var test = '"the quick" "brown fox" "jumps over" "the lazy dog"'; var result = test.match(/[^"]+(?=(" ")|"$)/g); alert(result); ``` Note: This doesn't match empty elements (i.e. ""). Also, it won't work in browsers that don't support JavaScript 1.5 (lookaheads are a 1.5 feature). See <http:/...
147,646
<p>What would I do if I want to have a generic method that only accepts types that have overloaded an operator, for instance the subtraction operator. I tried using an interface as a constraint but interfaces can't have operator overloading. </p> <p>What is the best way to achieve this?</p>
[ { "answer_id": 147656, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 7, "selected": true, "text": "<p>There is no immediate answer; operators are static, and cannot be expressed in constraints - and the existing prima...
2008/09/29
[ "https://Stackoverflow.com/questions/147646", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9107/" ]
What would I do if I want to have a generic method that only accepts types that have overloaded an operator, for instance the subtraction operator. I tried using an interface as a constraint but interfaces can't have operator overloading. What is the best way to achieve this?
There is no immediate answer; operators are static, and cannot be expressed in constraints - and the existing primatives don't implement any specific interface (contrast to IComparable[<T>] which can be used to emulate greater-than / less-than). However; if you just want it to work, then in .NET 3.5 there are some opt...
147,649
<p>I am using a very intrinsic database with a CakePHP application and so far my multi-models views and controllers are working fine. I have a singular table (<code>Entity</code>) that have it's <code>id</code> on several other tables as the Foreign Key <code>entity_id</code></p> <p>Some tables are one to one relation...
[ { "answer_id": 147788, "author": "Jacob", "author_id": 22107, "author_profile": "https://Stackoverflow.com/users/22107", "pm_score": 0, "selected": false, "text": "<p>The problem with saveAll() and HABTM associations is a known CakePHP <a href=\"https://trac.cakephp.org/ticket/4389\" rel...
2008/09/29
[ "https://Stackoverflow.com/questions/147649", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2274/" ]
I am using a very intrinsic database with a CakePHP application and so far my multi-models views and controllers are working fine. I have a singular table (`Entity`) that have it's `id` on several other tables as the Foreign Key `entity_id` Some tables are one to one relations (Like a `Company` is one `Entity`) and so...
This is fixed if you download the [nightly](http://cakephp.org/downloads/index/nightly/1.2.x.x). Be careful though, something else might break.
147,657
<p>According to MSDN </p> <pre><code>form.RightToLeftLayout = True; form.RightToLeft = ifWeWantRTL() ? RightToLeft.True : RightToLeft.False; </code></pre> <p>is enough to mirrow the form content for RTL languages.</p> <p>But controls placement gets mirrowed only for controls immediately on the form,<br> those inside...
[ { "answer_id": 148001, "author": "eugensk", "author_id": 17495, "author_profile": "https://Stackoverflow.com/users/17495", "pm_score": 1, "selected": false, "text": "<p>According to the article \n<a href=\"http://www.microsoft.com/middleeast/msdn/WinFormsAndArabic.aspx#_Toc136842131\" re...
2008/09/29
[ "https://Stackoverflow.com/questions/147657", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17495/" ]
According to MSDN ``` form.RightToLeftLayout = True; form.RightToLeft = ifWeWantRTL() ? RightToLeft.True : RightToLeft.False; ``` is enough to mirrow the form content for RTL languages. But controls placement gets mirrowed only for controls immediately on the form, those inside a GroupBox or a Panel **are not m...
It does seen that you have quite a nasty problem on your hands. Have played with it for a while and come up with the following: Making use of a little recursion you can run though all the controls and do the manaul RTL conversion for those controls trapped in Pannels and GroupBoxes. This is a *quick* little mock of c...
147,659
<p>How can I get the list of available databases on a SQL Server instance? I'm planning to make a list of them in a combo box in VB.NET.</p>
[ { "answer_id": 147662, "author": "Ben Hoffstein", "author_id": 4482, "author_profile": "https://Stackoverflow.com/users/4482", "pm_score": 11, "selected": true, "text": "<p>Execute: </p>\n\n<p><code>SELECT name FROM master.sys.databases</code> </p>\n\n<p>This the preferred approach now, ...
2008/09/29
[ "https://Stackoverflow.com/questions/147659", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21963/" ]
How can I get the list of available databases on a SQL Server instance? I'm planning to make a list of them in a combo box in VB.NET.
Execute: `SELECT name FROM master.sys.databases` This the preferred approach now, rather than `dbo.sysdatabases`, which has been deprecated for some time. --- Execute this query: ``` SELECT name FROM master.dbo.sysdatabases ``` or if you prefer ``` EXEC sp_databases ```
147,669
<p>I've got a c# assembly which I'm invoking via COM from a Delphi (win32 native) application.</p> <p>This works on all the machines I've tested it on, except one.</p> <p>The problem is that the Delphi application gets "Class not registered" when trying to create the COM object.</p> <p>Now, when I look in the regist...
[ { "answer_id": 147730, "author": "1800 INFORMATION", "author_id": 3146, "author_profile": "https://Stackoverflow.com/users/3146", "pm_score": 1, "selected": false, "text": "<p>Maybe you have an old version of the assembly somewhere? Maybe in the GAC? Regasm is probably picking that up an...
2008/09/29
[ "https://Stackoverflow.com/questions/147669", "https://Stackoverflow.com", "https://Stackoverflow.com/users/369/" ]
I've got a c# assembly which I'm invoking via COM from a Delphi (win32 native) application. This works on all the machines I've tested it on, except one. The problem is that the Delphi application gets "Class not registered" when trying to create the COM object. Now, when I look in the registry under `HKEY_CLASSES_R...
The GUID in AssemblyInfo becomes the "Type-Library" GUID and usually is not what you'd be looking for. I'm going to assume you're trying to access a class, and you need to define a Guid attribute and ComVisible for the class. For example: ``` [Guid("00001111-2222-3333-4444-555566667777"), ComVisible(true)] public ...
147,670
<p>How can I extract the list of available SQL servers in an SQL server group? I'm planning to put that list in a combo box in VB.NET.</p>
[ { "answer_id": 147680, "author": "Ben Hoffstein", "author_id": 4482, "author_profile": "https://Stackoverflow.com/users/4482", "pm_score": 4, "selected": true, "text": "<p>The only way I knew to do it was using the command line:</p>\n\n<pre><code>osql -L\n</code></pre>\n\n<p>But I found ...
2008/09/29
[ "https://Stackoverflow.com/questions/147670", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21963/" ]
How can I extract the list of available SQL servers in an SQL server group? I'm planning to put that list in a combo box in VB.NET.
The only way I knew to do it was using the command line: ``` osql -L ``` But I found the below article which seems to solve your specific goal filling a combobox: <http://www.sqldbatips.com/showarticle.asp?ID=45>
147,684
<p>I have a page which is largely created by DOM script, which generates a table of images (normal img elements) from several webcams (helping out a friend with a pet boarding and my HTML/DOM is a bit rusty).</p> <p>It works fine in FF3 or Chrome, but not in IE7, In fact, the whole table is not visible in IE (but the...
[ { "answer_id": 147690, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 1, "selected": false, "text": "<p>The gotcha that always gets me is IE's mishandling of the <code>&lt;script&gt;</code> tag when it's used like <code>&l...
2008/09/29
[ "https://Stackoverflow.com/questions/147684", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18255/" ]
I have a page which is largely created by DOM script, which generates a table of images (normal img elements) from several webcams (helping out a friend with a pet boarding and my HTML/DOM is a bit rusty). It works fine in FF3 or Chrome, but not in IE7, In fact, the whole table is not visible in IE (but the body backg...
One gotcha I found is that in IE, if you dynamically create tables using `document.createElement()`, you need `table(tbody(tr(tds)))`. Without a `tbody`, the table will not show.
147,703
<p>I have a generic list, i.e. <code>List&lt;myclass&gt;</code>. Here <code>myclass</code> contains two string properties. </p> <p>How can I assign a datasource to the list collection?</p>
[ { "answer_id": 147717, "author": "Jon Limjap", "author_id": 372, "author_profile": "https://Stackoverflow.com/users/372", "pm_score": 0, "selected": false, "text": "<p>You got it the other way around. Databound objects like grids and the like could set generic lists as their data source....
2008/09/29
[ "https://Stackoverflow.com/questions/147703", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have a generic list, i.e. `List<myclass>`. Here `myclass` contains two string properties. How can I assign a datasource to the list collection?
Mirmal, I guess English is not your first language, this question is not very clear. I think that what you are asking is given a list of your class how do you then bind that list to something (a listbox or combobox etc) Here is a simple code snippet of how to do this... ``` private void button2_Click(object sender, E...
147,713
<p>In C I could, for example, zero out bit #10 in a 32 bit unsigned value like so:</p> <pre><code>unsigned long value = 0xdeadbeef; value &amp;= ~(1&lt;&lt;10); </code></pre> <p>How do I do that in Python ?</p>
[ { "answer_id": 147716, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 4, "selected": false, "text": "<pre><code>value = 0xdeadbeef\nvalue &amp;= ~(1&lt;&lt;10)\n</code></pre>\n" }, { "answer_id": 147718, "autho...
2008/09/29
[ "https://Stackoverflow.com/questions/147713", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16144/" ]
In C I could, for example, zero out bit #10 in a 32 bit unsigned value like so: ``` unsigned long value = 0xdeadbeef; value &= ~(1<<10); ``` How do I do that in Python ?
Bitwise operations on Python ints work much like in C. The `&`, `|` and `^` operators in Python work just like in C. The `~` operator works as for a signed integer in C; that is, `~x` computes `-x-1`. You have to be somewhat careful with left shifts, since Python integers aren't fixed-width. Use bit masks to obtain th...
147,714
<p>I would like to refer HTML templates designed/developed especially for form based Web Applications.</p> <p>I have been searching them but am not able to find out which I find better.</p> <p>Regards, Jatan</p>
[ { "answer_id": 147770, "author": "Brian Matthews", "author_id": 1969, "author_profile": "https://Stackoverflow.com/users/1969", "pm_score": 1, "selected": false, "text": "<p>Here are a few catalogs of template designs:</p>\n\n<ul>\n<li><a href=\"http://www.opendesigns.org/\" rel=\"nofoll...
2008/09/29
[ "https://Stackoverflow.com/questions/147714", "https://Stackoverflow.com", "https://Stackoverflow.com/users/959/" ]
I would like to refer HTML templates designed/developed especially for form based Web Applications. I have been searching them but am not able to find out which I find better. Regards, Jatan
Much of the choice in this sort of thing is going to be defined by your choice of server tech / platform, e.g. .NET has in built widgets you can use, as do many web application frameworks. The django admin layouts are extremely well designed, you could download [Django](http://www.djangoproject.com/) and check it out....
147,719
<p>Is there a Delphi equivalent of the C# #if(DEBUG) compiler directive?</p>
[ { "answer_id": 147725, "author": "Lasse V. Karlsen", "author_id": 267, "author_profile": "https://Stackoverflow.com/users/267", "pm_score": 6, "selected": true, "text": "<p>Use this:</p>\n\n<pre><code>{$IFDEF DEBUG}\n...\n{$ENDIF}\n</code></pre>\n" }, { "answer_id": 147855, "...
2008/09/29
[ "https://Stackoverflow.com/questions/147719", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11333/" ]
Is there a Delphi equivalent of the C# #if(DEBUG) compiler directive?
Use this: ``` {$IFDEF DEBUG} ... {$ENDIF} ```
147,741
<p>In a text file, there is a string "I don't like this".</p> <p>However, when I read it into a string, it becomes "I don\xe2\x80\x98t like this". I understand that \u2018 is the unicode representation of "'". I use </p> <pre><code>f1 = open (file1, "r") text = f1.read() </code></pre> <p>command to do the reading.</...
[ { "answer_id": 147751, "author": "John Millikin", "author_id": 3560, "author_profile": "https://Stackoverflow.com/users/3560", "pm_score": 1, "selected": false, "text": "<p>Actually, U+2018 is the Unicode representation of the special character ‘ . If you want, you can convert instances ...
2008/09/29
[ "https://Stackoverflow.com/questions/147741", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3834/" ]
In a text file, there is a string "I don't like this". However, when I read it into a string, it becomes "I don\xe2\x80\x98t like this". I understand that \u2018 is the unicode representation of "'". I use ``` f1 = open (file1, "r") text = f1.read() ``` command to do the reading. Now, is it possible to read the s...
Ref: <http://docs.python.org/howto/unicode> *Reading Unicode from a file is therefore simple:* ``` import codecs with codecs.open('unicode.rst', encoding='utf-8') as f: for line in f: print repr(line) ``` *It's also possible to open files in update mode, allowing both reading and writing:* ``` with cod...
147,747
<p>OK, probably best to give an example here of what I mean.</p> <p>Imagine a web based forum system, where the user authentication is done by some external method, which the system is aware of.</p> <p>Now, say for example, a user enters the URL for a thread that they do not have access to. For this should I return a...
[ { "answer_id": 147754, "author": "1800 INFORMATION", "author_id": 3146, "author_profile": "https://Stackoverflow.com/users/3146", "pm_score": 1, "selected": false, "text": "<p>No website in the world does what you are suggesting, so by this example we see that it is probably best to foll...
2008/09/29
[ "https://Stackoverflow.com/questions/147747", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20010/" ]
OK, probably best to give an example here of what I mean. Imagine a web based forum system, where the user authentication is done by some external method, which the system is aware of. Now, say for example, a user enters the URL for a thread that they do not have access to. For this should I return a 403 (Forbidden),...
Above everything else, **comply with HTTP spec.** Returning 403 in place of 404 is not a good thing. Returning 404 in place of 403 probably is ok (or not a big blunder), but I would just **let the software tell the truth**. If user only knows the ID of a topic, it's not much anyway. And he could try *timing attacks* to...
147,752
<p>In the admin interface and newforms there is the brilliant helper of being able to define choices. You can use code like this:</p> <pre><code>APPROVAL_CHOICES = ( ('yes', 'Yes'), ('no', 'No'), ('cancelled', 'Cancelled'), ) client_approved = models.CharField(choices=APPROVAL_CHOICES) </code></pre> <p>t...
[ { "answer_id": 147793, "author": "Jonny Buchanan", "author_id": 6760, "author_profile": "https://Stackoverflow.com/users/6760", "pm_score": 7, "selected": true, "text": "<p>In terms of the forms library, you would use the <a href=\"http://docs.djangoproject.com/en/dev/ref/forms/fields/#m...
2008/09/29
[ "https://Stackoverflow.com/questions/147752", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23366/" ]
In the admin interface and newforms there is the brilliant helper of being able to define choices. You can use code like this: ``` APPROVAL_CHOICES = ( ('yes', 'Yes'), ('no', 'No'), ('cancelled', 'Cancelled'), ) client_approved = models.CharField(choices=APPROVAL_CHOICES) ``` to create a drop down box i...
In terms of the forms library, you would use the [MultipleChoiceField](http://docs.djangoproject.com/en/dev/ref/forms/fields/#multiplechoicefield) field with a [CheckboxSelectMultiple](http://docs.djangoproject.com/en/dev/ref/forms/widgets/#django.forms.CheckboxSelectMultiple) widget to do that. You could validate the ...
147,816
<p>Suppose I have written a decorator that does something very generic. For example, it might convert all arguments to a specific type, perform logging, implement memoization, etc.</p> <p>Here is an example:</p> <pre><code>def args_as_ints(f): def g(*args, **kwargs): args = [int(x) for x in args] ...
[ { "answer_id": 147835, "author": "Brian", "author_id": 9493, "author_profile": "https://Stackoverflow.com/users/9493", "pm_score": 3, "selected": false, "text": "<p>Take a look at the <a href=\"http://www.phyast.pitt.edu/~micheles/python/documentation.html\" rel=\"noreferrer\">decorator<...
2008/09/29
[ "https://Stackoverflow.com/questions/147816", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1163767/" ]
Suppose I have written a decorator that does something very generic. For example, it might convert all arguments to a specific type, perform logging, implement memoization, etc. Here is an example: ``` def args_as_ints(f): def g(*args, **kwargs): args = [int(x) for x in args] kwargs = dict((k, int...
1. Install [decorator](http://www.phyast.pitt.edu/~micheles/python/documentation.html#the-solution) module: ``` $ pip install decorator ``` 2. Adapt definition of `args_as_ints()`: ``` import decorator @decorator.decorator def args_as_ints(f, *args, **kwargs): args = [int(x) for x in args] kwargs = dict((k,...
147,824
<p>To be more precise, I need to know whether (and if possible, how) I can find whether a given string has double byte characters or not. Basically, I need to open a pop-up to display a given text which can contain double byte characters, like Chinese or Japanese. In this case, we need to adjust the window size than it...
[ { "answer_id": 147854, "author": "Oli", "author_id": 12870, "author_profile": "https://Stackoverflow.com/users/12870", "pm_score": 0, "selected": false, "text": "<p>Why not let the window resize itself based on the runtime height/width?</p>\n\n<p>Run something like this in your pop-up:</...
2008/09/29
[ "https://Stackoverflow.com/questions/147824", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23373/" ]
To be more precise, I need to know whether (and if possible, how) I can find whether a given string has double byte characters or not. Basically, I need to open a pop-up to display a given text which can contain double byte characters, like Chinese or Japanese. In this case, we need to adjust the window size than it wo...
JavaScript holds text internally as UCS-2, which can encode a fairly extensive subset of Unicode. But that's not really germane to your question. One solution might be to loop through the string and examine the character codes at each position: ``` function isDoubleByte(str) { for (var i = 0, n = str.length; i < ...
147,837
<p>I am already excited about document databases and especially about CouchDB's simplicity. But I have a hard time understanding if such databases are a viable option for multi user systems. Since those systems require some kind of relations between records which document databases do not provide.</p> <p>Is it complet...
[ { "answer_id": 147932, "author": "micahwittman", "author_id": 11181, "author_profile": "https://Stackoverflow.com/users/11181", "pm_score": 2, "selected": false, "text": "<p>Multi-user systems do not <em>require</em> relational databases, though RDBMSs are a staple technology for data st...
2008/09/29
[ "https://Stackoverflow.com/questions/147837", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3812/" ]
I am already excited about document databases and especially about CouchDB's simplicity. But I have a hard time understanding if such databases are a viable option for multi user systems. Since those systems require some kind of relations between records which document databases do not provide. Is it completely the wr...
There was a discussion on the [mailing list](http://couchdb.markmail.org/search/?q=twitter%20follower#query:twitter%20follower+page:1+mid:l4ibup6xoftffvrs+state:results) awhile back that fits this question fairly well. The rule of thumb was to only store data in a document that is likely to change vs. grow. If the data...
147,850
<p>I have the problem that an specific step in Ant can only be executed when we have Java 1.5 installed in the build computer. The task definition uses uses a jar file that was compiled using 1.5, so running with a 1.4 virtual machine will throw an IncompatibleClassVersion exception.</p> <p>I have to find a solution...
[ { "answer_id": 147890, "author": "McDowell", "author_id": 304, "author_profile": "https://Stackoverflow.com/users/304", "pm_score": 4, "selected": true, "text": "<p>The Java version is exposed via the <em>ant.java.version</em> property. Use a <em>condition</em> to set a property and exec...
2008/09/29
[ "https://Stackoverflow.com/questions/147850", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2309/" ]
I have the problem that an specific step in Ant can only be executed when we have Java 1.5 installed in the build computer. The task definition uses uses a jar file that was compiled using 1.5, so running with a 1.4 virtual machine will throw an IncompatibleClassVersion exception. I have to find a solution meanwhile t...
The Java version is exposed via the *ant.java.version* property. Use a *condition* to set a property and execute the task only if it is true. ``` <?xml version="1.0" encoding="UTF-8"?> <project name="project" default="default"> <target name="default" depends="javaCheck" if="isJava6"> <echo message="Hello...
147,891
<p>In Firefox I can get the stack trace of an exception by using <code>exception.stack</code>.</p> <p>Is there a way to get that in other browsers, too?</p> <p><b>Edit:</b> I actually want to save the stack trace automatically (if possible) and not debug it at the time (i.e. I know how to get the stack trace in a deb...
[ { "answer_id": 147895, "author": "levik", "author_id": 4465, "author_profile": "https://Stackoverflow.com/users/4465", "pm_score": 0, "selected": false, "text": "<p>Not really, at least not easily.</p>\n\n<p>In IE, you can debug the browser process with MS Script Debugger (which for some...
2008/09/29
[ "https://Stackoverflow.com/questions/147891", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4936/" ]
In Firefox I can get the stack trace of an exception by using `exception.stack`. Is there a way to get that in other browsers, too? **Edit:** I actually want to save the stack trace automatically (if possible) and not debug it at the time (i.e. I know how to get the stack trace in a debugger).
Place this line where you want to print the stack trace: ``` console.log(new Error().stack); ``` **Note:** tested by me on **Chrome 24** and **Firefox 18** May be worth taking a look at [this tool](https://github.com/ebobby/tracing.js) as well.
147,897
<p>I want to generate some XML in a stored procedure based on data in a table.</p> <p>The following insert allows me to add many nodes but they have to be hard-coded or use variables (sql:variable):</p> <pre><code>SET @MyXml.modify(' insert &lt;myNode&gt; {sql:variable("@MyVariable")} ...
[ { "answer_id": 148113, "author": "kristof", "author_id": 3241, "author_profile": "https://Stackoverflow.com/users/3241", "pm_score": 0, "selected": false, "text": "<p>Can you tell a bit more about what exactly you are planning to do.\nIs it simply generating XML data based on a content o...
2008/09/29
[ "https://Stackoverflow.com/questions/147897", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18107/" ]
I want to generate some XML in a stored procedure based on data in a table. The following insert allows me to add many nodes but they have to be hard-coded or use variables (sql:variable): ``` SET @MyXml.modify(' insert <myNode> {sql:variable("@MyVariable")} </myNode> into (/...
Have you tried **nesting** FOR XML PATH scalar valued functions? With the nesting technique, you can brake your SQL into very managable/readable elemental pieces Disclaimer: the following, while adapted from a working example, has not itself been literally tested Some reference links for the general audience * <htt...
147,908
<p>Under the View-Model-ViewModel pattern for WPF, I am trying to databind the Heights and Widths of various definitions for grid controls, so I can store the values the user sets them to after using a GridSplitter. However, the normal pattern doesn't seem to work for these particular properties.</p> <p><em>Note: I'm ...
[ { "answer_id": 147928, "author": "Nidonocu", "author_id": 483, "author_profile": "https://Stackoverflow.com/users/483", "pm_score": 6, "selected": true, "text": "<p>There were a number of gotchas I discovered:</p>\n\n<ol>\n<li>Although it may appear like a double in XAML, the actual valu...
2008/09/29
[ "https://Stackoverflow.com/questions/147908", "https://Stackoverflow.com", "https://Stackoverflow.com/users/483/" ]
Under the View-Model-ViewModel pattern for WPF, I am trying to databind the Heights and Widths of various definitions for grid controls, so I can store the values the user sets them to after using a GridSplitter. However, the normal pattern doesn't seem to work for these particular properties. *Note: I'm posting this ...
There were a number of gotchas I discovered: 1. Although it may appear like a double in XAML, the actual value for a \*Definition's Height or Width is a 'GridLength' struct. 2. All the properties of GridLength are readonly, you have to create a new one each time you change it. 3. Unlike every other property in WPF, Wi...
147,920
<p>I miss it so much (used it a lot in C#). can you do it in C++?</p>
[ { "answer_id": 147954, "author": "Matt Hanson", "author_id": 5473, "author_profile": "https://Stackoverflow.com/users/5473", "pm_score": 5, "selected": true, "text": "<p>Yes, you can. See <a href=\"http://msdn.microsoft.com/en-us/library/b6xkz944(VS.80).aspx\" rel=\"noreferrer\">here</a>...
2008/09/29
[ "https://Stackoverflow.com/questions/147920", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18426/" ]
I miss it so much (used it a lot in C#). can you do it in C++?
Yes, you can. See [here](http://msdn.microsoft.com/en-us/library/b6xkz944(VS.80).aspx). ``` #pragma region Region_Name //Your content. #pragma endregion Region_Name ```
147,924
<p>Can share with me any of this script?</p>
[ { "answer_id": 147963, "author": "Till", "author_id": 2859, "author_profile": "https://Stackoverflow.com/users/2859", "pm_score": 2, "selected": false, "text": "<p>The default one is called commit-email.pl and is included when you install Subversion. But <a href=\"http://blog.hungrymachi...
2008/09/29
[ "https://Stackoverflow.com/questions/147924", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17147/" ]
Can share with me any of this script?
The default one is called commit-email.pl and is included when you install Subversion. But [here](http://blog.hungrymachine.com/2007/11/5/pretty-svn-commit-emails) is one in ruby: ``` #!/usr/bin/ruby -w # A Subversion post-commit hook. Edit the configurable stuff below, and # copy into your repository's hooks/ direct...
147,929
<p>I've been searching around, and I haven't found how I would do this from C#.</p> <p>I was wanting to make it so I could tell Google Chrome to go <strong>Forward</strong>, <strong>Back</strong>, <strong>Open New Tab</strong>, <strong>Close Tab</strong>, <strong>Open New Window</strong>, and <strong>Close Window</str...
[ { "answer_id": 147950, "author": "VVS", "author_id": 21038, "author_profile": "https://Stackoverflow.com/users/21038", "pm_score": 4, "selected": true, "text": "<p>Start your research at <a href=\"http://dev.chromium.org/developers\" rel=\"noreferrer\">http://dev.chromium.org/developers<...
2008/09/29
[ "https://Stackoverflow.com/questions/147929", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13713/" ]
I've been searching around, and I haven't found how I would do this from C#. I was wanting to make it so I could tell Google Chrome to go **Forward**, **Back**, **Open New Tab**, **Close Tab**, **Open New Window**, and **Close Window** from my C# application. I did something similar with WinAmp using ``` [DllImport(...
Start your research at <http://dev.chromium.org/developers> --- **EDIT**: Sending a message to a window is only half of the work. The window has to respond to that message and act accordingly. If that window doesn't know about a message or doesn't care at all you have no chance to control it by sending window message...
147,941
<p>I am trying to read an Http response stream twice via the following:</p> <pre><code>HttpWebResponse response = (HttpWebResponse)request.GetResponse(); stream = response.GetResponseStream(); RssReader reader = new RssReader(stream); do { element = reader.Read(); if (element is RssChannel) { feed.Channels.A...
[ { "answer_id": 147948, "author": "Joachim Kerschbaumer", "author_id": 20227, "author_profile": "https://Stackoverflow.com/users/20227", "pm_score": -1, "selected": false, "text": "<p>have you tried resetting the stream position?\nif this does not work you can copy the stream to a MemoryS...
2008/09/29
[ "https://Stackoverflow.com/questions/147941", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10505/" ]
I am trying to read an Http response stream twice via the following: ``` HttpWebResponse response = (HttpWebResponse)request.GetResponse(); stream = response.GetResponseStream(); RssReader reader = new RssReader(stream); do { element = reader.Read(); if (element is RssChannel) { feed.Channels.Add((RssChannel...
Copy it into a new MemoryStream first. Then you can re-read the MemoryStream as many times as you like: ``` Stream responseStream = CopyAndClose(resp.GetResponseStream()); // Do something with the stream responseStream.Position = 0; // Do something with the stream again private static Stream CopyAndClose(Stream input...
147,953
<p>In an OLAP database I work with there is a 'Location' hierarchy consisting of the levels Company, Region, Area, Site, Room, Till. For a particular company I need to write some MDX that lists all regions, areas and sites (but not any levels below Site). Currently I am achieving this with the following MDX</p> <pre><...
[ { "answer_id": 147978, "author": "Magnus Smith", "author_id": 11461, "author_profile": "https://Stackoverflow.com/users/11461", "pm_score": 2, "selected": false, "text": "<p>The command you want is DESCENDANTS. Keep the 'family tree' analogy in mind, and you can see that this will list t...
2008/09/29
[ "https://Stackoverflow.com/questions/147953", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7585/" ]
In an OLAP database I work with there is a 'Location' hierarchy consisting of the levels Company, Region, Area, Site, Room, Till. For a particular company I need to write some MDX that lists all regions, areas and sites (but not any levels below Site). Currently I am achieving this with the following MDX ``` HIERARCHI...
``` DESCENDANTS([Location].[Test Company],[Location].[Site], SELF_AND_BEFORE) ```
147,962
<p>I have a big load of documents, text-files, that I want to search for relevant content. I've seen a searching tool, can't remeber where, that implemented a nice method as I describe in my requirement below.</p> <p>My requirement is as follows:</p> <ul> <li>I need an optimised search function: I supply this search ...
[ { "answer_id": 147989, "author": "Sklivvz", "author_id": 7028, "author_profile": "https://Stackoverflow.com/users/7028", "pm_score": 0, "selected": false, "text": "<p>Not sure about the syntax (this is sql server syntax), but:</p>\n\n<pre><code>-- N is the number of elements in the list\...
2008/09/29
[ "https://Stackoverflow.com/questions/147962", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15161/" ]
I have a big load of documents, text-files, that I want to search for relevant content. I've seen a searching tool, can't remeber where, that implemented a nice method as I describe in my requirement below. My requirement is as follows: * I need an optimised search function: I supply this search function with a list ...
What you're talking about is known as an [inverted index](http://en.wikipedia.org/wiki/Inverted_index) or posting list, and operates similary to what you propose and what Mecki proposes. There's a lot of literature about inverted indexes out there; the Wikipedia article is a good place to start. Better, rather than tr...
147,969
<p>I'm expanding my Ruby understanding by coding an equivalent of Kent Beck's xUnit in Ruby. Python (which Kent writes in) has an assert() method in the language which is used extensively. Ruby does not. I think it should be easy to add this but is Kernel the right place to put it?</p> <p>BTW, <em>I know of the exi...
[ { "answer_id": 148938, "author": "Christoph Schiessl", "author_id": 20467, "author_profile": "https://Stackoverflow.com/users/20467", "pm_score": 4, "selected": false, "text": "<p>What's your reason for adding the assert method to the Kernel module? Why not just use another module called...
2008/09/29
[ "https://Stackoverflow.com/questions/147969", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2455/" ]
I'm expanding my Ruby understanding by coding an equivalent of Kent Beck's xUnit in Ruby. Python (which Kent writes in) has an assert() method in the language which is used extensively. Ruby does not. I think it should be easy to add this but is Kernel the right place to put it? BTW, *I know of the existence of the va...
No it's not a best practice. The best analogy to assert() in Ruby is just raising ``` raise "This is wrong" unless expr ``` and you can implement your own exceptions if you want to provide for more specific exception handling
147,976
<p>I'm making a simple jquery command:</p> <p><code>element.html("&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;");</code></p> <p>using the attributes/html method: <a href="http://docs.jquery.com/Attributes/html" rel="nofollow noreferrer">http://docs.jquer...
[ { "answer_id": 148387, "author": "Sugendran", "author_id": 22466, "author_profile": "https://Stackoverflow.com/users/22466", "pm_score": 1, "selected": false, "text": "<p>Have you tried using <code>&amp;nbsp;</code> instead of spaces? The <code>html()</code> method just pumps the string ...
2008/09/29
[ "https://Stackoverflow.com/questions/147976", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9106/" ]
I'm making a simple jquery command: `element.html("&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;");` using the attributes/html method: <http://docs.jquery.com/Attributes/html> It works on my local app engine server, but it doesn't work once I push to the Google server. The element empties but d...
You could try generating the space during run-time, so it won't be trimmed or whatever happens during transport: ``` element.html(String.fromCharCode(32)); ```
147,988
<p>I want to split an arithmetic expression into tokens, to convert it into RPN.</p> <p>Java has the StringTokenizer, which can optionally keep the delimiters. That way, I could use the operators as delimiters. Unfortunately, I need to do this in PHP, which has strtok, but that throws away the delimiters, so I need to...
[ { "answer_id": 148014, "author": "Shoan", "author_id": 17404, "author_profile": "https://Stackoverflow.com/users/17404", "pm_score": 2, "selected": false, "text": "<p>This might help.</p>\n\n<p><a href=\"http://c7y.phparch.com/c/entry/1/art,practical_uses_tokenizer\" rel=\"nofollow noref...
2008/09/29
[ "https://Stackoverflow.com/questions/147988", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2077/" ]
I want to split an arithmetic expression into tokens, to convert it into RPN. Java has the StringTokenizer, which can optionally keep the delimiters. That way, I could use the operators as delimiters. Unfortunately, I need to do this in PHP, which has strtok, but that throws away the delimiters, so I need to brew some...
As often, I would just use a regular expression to do this: ``` $expr = '(5*(7 + 2 * -9.3) - 8 )/ 11'; $tokens = preg_split('/([*\/^+-]+)\s*|([\d.]+)\s*/', $expr, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); $tts = print_r($tokens, true); echo "<pre>x=$tts</pre>"; ``` It needs a little more work to a...
147,995
<p>When using the paginator helper in cakephp views, it doesnt remember parts of the url that are custom for my useage.</p> <p>For example: </p> <pre><code>http://example.org/users/index/moderators/page:2/sort:name/dir:asc </code></pre> <p>here <strong>moderators</strong> is a parameter that helps me filter by that ...
[ { "answer_id": 147998, "author": "Alexander Morland", "author_id": 4013, "author_profile": "https://Stackoverflow.com/users/4013", "pm_score": 4, "selected": false, "text": "<p>The secret is adding this line to your view:</p>\n\n<p><strong>$paginator->options(array('url'=>$this->passedAr...
2008/09/29
[ "https://Stackoverflow.com/questions/147995", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4013/" ]
When using the paginator helper in cakephp views, it doesnt remember parts of the url that are custom for my useage. For example: ``` http://example.org/users/index/moderators/page:2/sort:name/dir:asc ``` here **moderators** is a parameter that helps me filter by that type. But pressing a paginator link will not i...
To add to Alexander Morland's answer above, it's worth remembering that the syntax has changed in CakePHP 1.3 and is now: ``` $this->Paginator->options(array('url' => $this->passedArgs)); ``` This is described further in the [pagination in views](http://book.cakephp.org/1.3/en/The-Manual/Common-Tasks-With-CakePHP/Pa...
148,003
<p>I have an array of a few million numbers.</p> <pre><code>double* const data = new double (3600000); </code></pre> <p>I need to iterate through the array and find the range (the largest value in the array minus the smallest value). However, there is a catch. I only want to find the range where the smallest and larg...
[ { "answer_id": 148030, "author": "Drakosha", "author_id": 19868, "author_profile": "https://Stackoverflow.com/users/19868", "pm_score": 4, "selected": true, "text": "<p>The algorithm you describe is really O(N), but i think the constant is too high. Another solution which looks reasonabl...
2008/09/29
[ "https://Stackoverflow.com/questions/148003", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3175/" ]
I have an array of a few million numbers. ``` double* const data = new double (3600000); ``` I need to iterate through the array and find the range (the largest value in the array minus the smallest value). However, there is a catch. I only want to find the range where the smallest and largest values are within 1,00...
The algorithm you describe is really O(N), but i think the constant is too high. Another solution which looks reasonable is to use O(N\*log(N)) algorithm the following way: ``` * create sorted container (std::multiset) of first 1000 numbers * in loop (j=1, j<(3600000-1000); ++j) - calculate range - remove from t...
148,005
<p>In SQL, how do update a table, setting a column to a different value for each row?</p> <p>I want to update some rows in a PostgreSQL database, setting one column to a number from a sequence, where that column has a unique constraint. I hoped that I could just use:</p> <pre><code>update person set unique_number = (...
[ { "answer_id": 148017, "author": "Grey Panther", "author_id": 1265, "author_profile": "https://Stackoverflow.com/users/1265", "pm_score": 6, "selected": true, "text": "<p>Don't use a subselect, rather use the nextval function directly, like this:</p>\n\n<pre><code>update person set uniqu...
2008/09/29
[ "https://Stackoverflow.com/questions/148005", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2670/" ]
In SQL, how do update a table, setting a column to a different value for each row? I want to update some rows in a PostgreSQL database, setting one column to a number from a sequence, where that column has a unique constraint. I hoped that I could just use: ``` update person set unique_number = (select nextval('numbe...
Don't use a subselect, rather use the nextval function directly, like this: ``` update person set unique_number = nextval('number_sequence'); ```
148,024
<p>I have got a C function in a static library, let's call it A, with the following interface :</p> <pre><code>int A(unsigned int a, unsigned long long b, unsigned int *y, unsigned char *z); </code></pre> <p>This function will change the value of y an z (this is for sure). I use it from within a dynamic C++ library, ...
[ { "answer_id": 148041, "author": "quinmars", "author_id": 18687, "author_profile": "https://Stackoverflow.com/users/18687", "pm_score": 1, "selected": false, "text": "<p>As far as I know, long long is not part of standard C++, maybe that is the source of your problem.</p>\n" }, { ...
2008/09/29
[ "https://Stackoverflow.com/questions/148024", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20986/" ]
I have got a C function in a static library, let's call it A, with the following interface : ``` int A(unsigned int a, unsigned long long b, unsigned int *y, unsigned char *z); ``` This function will change the value of y an z (this is for sure). I use it from within a dynamic C++ library, using extern "C". Now, he...
First of all, I am very grateful to everyone for your help. Thanks to the numerous ideas and clues you gave me, I have been able to finally sort out this problem. Your advices helped me to question what I took for granted. Short answer to my problem : The problem was that my C++ library used an old version of the C li...
148,042
<p>When using IF statements in Python, you have to do the following to make the "cascade" work correctly.</p> <pre><code>if job == "mechanic" or job == "tech": print "awesome" elif job == "tool" or job == "rock": print "dolt" </code></pre> <p>Is there a way to make Python accept multiple values when c...
[ { "answer_id": 148048, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 6, "selected": true, "text": "<pre><code>if job in (\"mechanic\", \"tech\"):\n print \"awesome\"\nelif job in (\"tool\", \"rock\"):\n print \"dolt...
2008/09/29
[ "https://Stackoverflow.com/questions/148042", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18676/" ]
When using IF statements in Python, you have to do the following to make the "cascade" work correctly. ``` if job == "mechanic" or job == "tech": print "awesome" elif job == "tool" or job == "rock": print "dolt" ``` Is there a way to make Python accept multiple values when checking for "equals to"? F...
``` if job in ("mechanic", "tech"): print "awesome" elif job in ("tool", "rock"): print "dolt" ``` The values in parentheses are a tuple. The `in` operator checks to see whether the left hand side item occurs somewhere inside the right handle tuple. Note that when Python searches a tuple or list using the `i...
148,056
<p>I have created my own Tree implementation for <a href="https://stackoverflow.com/questions/144642/tree-directed-acyclic-graph-implementation">various reasons</a> and have come up with two classes, a 'base' class that is a generic tree node that is chock full of logic and another class that extends that one which is ...
[ { "answer_id": 148072, "author": "mitchnull", "author_id": 18645, "author_profile": "https://Stackoverflow.com/users/18645", "pm_score": 0, "selected": false, "text": "<p>I don't think there's a better approach. Just be careful not to call these hooks from the constructor.</p>\n" }, ...
2008/09/29
[ "https://Stackoverflow.com/questions/148056", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1666/" ]
I have created my own Tree implementation for [various reasons](https://stackoverflow.com/questions/144642/tree-directed-acyclic-graph-implementation) and have come up with two classes, a 'base' class that is a generic tree node that is chock full of logic and another class that extends that one which is more specialis...
So, after getting my copy of [Design Patterns](https://rads.stackoverflow.com/amzn/click/com/0201633612) and opening it for what I'm fairly sure is the first time ever I discovered what I want. It's called the [Factory Method](http://en.wikipedia.org/wiki/Factory_method) and it's mostly a perfect fit. It's still a bit...
148,057
<p>If you have Mathematica code in foo.m, Mathematica can be invoked with <code>-noprompt</code> and with <code>-initfile foo.m</code> (or <code>-run "&lt;&lt;foo.m"</code>) and the command line arguments are available in <code>$CommandLine</code> (with extra junk in there) but is there a way to just have some mathemat...
[ { "answer_id": 148085, "author": "Lev", "author_id": 7224, "author_profile": "https://Stackoverflow.com/users/7224", "pm_score": 2, "selected": false, "text": "<p>Try<br>\n-initfile <em>filename</em><br>\nAnd put the exit command into your program</p>\n" }, { "answer_id": 151656,...
2008/09/29
[ "https://Stackoverflow.com/questions/148057", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4234/" ]
If you have Mathematica code in foo.m, Mathematica can be invoked with `-noprompt` and with `-initfile foo.m` (or `-run "<<foo.m"`) and the command line arguments are available in `$CommandLine` (with extra junk in there) but is there a way to just have some mathematica code like ``` #!/usr/bin/env MathKernel x = 2+2;...
MASH -- Mathematica Scripting Hack -- will do this. Since Mathematica version 6, the following perl script suffices: <http://ai.eecs.umich.edu/people/dreeves/mash/mash.pl> For previous Mathematica versions, a C program is needed: <http://ai.eecs.umich.edu/people/dreeves/mash/pre6> UPDATE: At long last, Mathematica...
148,078
<p>I have a method which should be executed in an exclusive fashion. Basically, it's a multi threaded application where the method is invoked periodically by a timer, but which could also be manually triggered by a user action.</p> <p>Let's take an example :</p> <ol> <li><p>The timer elapses, so the method is called....
[ { "answer_id": 148104, "author": "Mats Fredriksson", "author_id": 2973, "author_profile": "https://Stackoverflow.com/users/2973", "pm_score": 3, "selected": true, "text": "<p>This looks reasonable if you are just interested in not having the method run in parallel. There's nothing to sto...
2008/09/29
[ "https://Stackoverflow.com/questions/148078", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4687/" ]
I have a method which should be executed in an exclusive fashion. Basically, it's a multi threaded application where the method is invoked periodically by a timer, but which could also be manually triggered by a user action. Let's take an example : 1. The timer elapses, so the method is called. The task could take a ...
This looks reasonable if you are just interested in not having the method run in parallel. There's nothing to stop it from running immediately after each other, say that you pushed the button half a microsecond after the timer executed the Monitor.Exit(). And having the lock object as readonly static also make sense.
148,116
<p>So, In a Flex app I add a new GUI component by creating it and calling <code>parent.addChild()</code>. However in some cases, this causes an error in the bowels of Flex. Turns out, addChild actually does:</p> <pre><code>return addChildAt(child, numChildren); </code></pre> <p>In the cases where it breaks, somehow t...
[ { "answer_id": 148250, "author": "user23405", "author_id": 23405, "author_profile": "https://Stackoverflow.com/users/23405", "pm_score": 1, "selected": false, "text": "<p>I have noticed that it most often occurs when re-parenting a UIComponent that is already on the display list. Are yo...
2008/09/29
[ "https://Stackoverflow.com/questions/148116", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13220/" ]
So, In a Flex app I add a new GUI component by creating it and calling `parent.addChild()`. However in some cases, this causes an error in the bowels of Flex. Turns out, addChild actually does: ``` return addChildAt(child, numChildren); ``` In the cases where it breaks, somehow the numChildren is off by one. Leading...
I have noticed that it most often occurs when re-parenting a UIComponent that is already on the display list. Are you re-parenting in this situation?
148,130
<p>Should be pretty simple: I have an InputStream where I want to peek at (not read) the first two bytes, i.e. I want the "current position" of the InputStream to stil be at 0 after my peeking. What is the best and safest way to do this?</p> <p><strong>Answer</strong> - As I had suspected, the solution was to wrap it ...
[ { "answer_id": 148135, "author": "Rasmus Faber", "author_id": 5542, "author_profile": "https://Stackoverflow.com/users/5542", "pm_score": 7, "selected": true, "text": "<p>For a general InputStream, I would wrap it in a BufferedInputStream and do something like this:</p>\n\n<pre><code>Buf...
2008/09/29
[ "https://Stackoverflow.com/questions/148130", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6583/" ]
Should be pretty simple: I have an InputStream where I want to peek at (not read) the first two bytes, i.e. I want the "current position" of the InputStream to stil be at 0 after my peeking. What is the best and safest way to do this? **Answer** - As I had suspected, the solution was to wrap it in a BufferedInputStrea...
For a general InputStream, I would wrap it in a BufferedInputStream and do something like this: ``` BufferedInputStream bis = new BufferedInputStream(inputStream); bis.mark(2); int byte1 = bis.read(); int byte2 = bis.read(); bis.reset(); // note: you must continue using the BufferedInputStream instead of the inputStre...
148,136
<p>I'm currently generating SQL insert statements from more than one tables, and in the generated data I need to use a CASE statement, like this:</p> <pre><code>select 'INSERT INTO TABLE1 (f1, f2, f3, f4 ...) values (' ||t.f1||',' ||CASE WHEN t.f2 &gt; 0 THEN '1' ELSE '0' ...
[ { "answer_id": 148150, "author": "Walter Mitty", "author_id": 19937, "author_profile": "https://Stackoverflow.com/users/19937", "pm_score": 1, "selected": false, "text": "<p>For some similar situations, the \"decode\" function works quite well. </p>\n\n<p>You might be able to feed the e...
2008/09/29
[ "https://Stackoverflow.com/questions/148136", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11621/" ]
I'm currently generating SQL insert statements from more than one tables, and in the generated data I need to use a CASE statement, like this: ``` select 'INSERT INTO TABLE1 (f1, f2, f3, f4 ...) values (' ||t.f1||',' ||CASE WHEN t.f2 > 0 THEN '1' ELSE '0' END CASE fro...
Use END instead of END CASE ``` select 'INSERT INTO TABLE1 (f1, f2, f3, f4 ...) values (' ||t.f1||',' ||CASE WHEN t.f2 > 0 THEN '1' ELSE '0' END||','||t.f2 from table2 t , table3 t3 ```
148,143
<p>When you open a solution in Visual Studio 2008 (or ealier versions for that matter), it opens all the documents that you did not close before you closed Visual Studio. Is there anyway to turn this functionality off, or a plugin that fixes this behavior? It takes forever to load a solution with 50 files open?</p>
[ { "answer_id": 148166, "author": "Galwegian", "author_id": 3201, "author_profile": "https://Stackoverflow.com/users/3201", "pm_score": 4, "selected": false, "text": "<p>Have you tried deleting the <strong>.suo</strong> file?</p>\n\n<p>It's a hidden file that lives beside your solution (s...
2008/09/29
[ "https://Stackoverflow.com/questions/148143", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11559/" ]
When you open a solution in Visual Studio 2008 (or ealier versions for that matter), it opens all the documents that you did not close before you closed Visual Studio. Is there anyway to turn this functionality off, or a plugin that fixes this behavior? It takes forever to load a solution with 50 files open?
You can automate the process of closing all the files prior to closing a solution by adding a handler for the BeforeClosing event of EnvDTE.SolutionEvents -- this will get invoked when VS is exiting. In VS2005, adding the following to the EnvironmentEvents macro module will close all open documents: ``` Private ...
148,157
<p>I am working on a Sharepoint Server 2007 State machine Workflow. Until now I have a few states and a custom Association/InitiationForm which I created with InfoPath 2007. In Addition I have a few modification forms. I have a Problem with the removing of the modification link in the state-page of my workflow. </p> <...
[ { "answer_id": 148166, "author": "Galwegian", "author_id": 3201, "author_profile": "https://Stackoverflow.com/users/3201", "pm_score": 4, "selected": false, "text": "<p>Have you tried deleting the <strong>.suo</strong> file?</p>\n\n<p>It's a hidden file that lives beside your solution (s...
2008/09/29
[ "https://Stackoverflow.com/questions/148157", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21729/" ]
I am working on a Sharepoint Server 2007 State machine Workflow. Until now I have a few states and a custom Association/InitiationForm which I created with InfoPath 2007. In Addition I have a few modification forms. I have a Problem with the removing of the modification link in the state-page of my workflow. I have a...
You can automate the process of closing all the files prior to closing a solution by adding a handler for the BeforeClosing event of EnvDTE.SolutionEvents -- this will get invoked when VS is exiting. In VS2005, adding the following to the EnvironmentEvents macro module will close all open documents: ``` Private ...
148,178
<p>I've got a really odd error message that only occurs when I add the following line to my project:</p> <pre><code>std::list&lt;CRect&gt; myVar; </code></pre> <p>It's worth noting that it doesn't have to be a std::list, it can be std::vector or any other STL container I assume.</p> <p>Here is the error message:</p>...
[ { "answer_id": 148899, "author": "jeffm", "author_id": 1544, "author_profile": "https://Stackoverflow.com/users/1544", "pm_score": 0, "selected": false, "text": "<p>This doesn't sound like the exact symptom, but to be sure you should check that your main project and all your included lib...
2008/09/29
[ "https://Stackoverflow.com/questions/148178", "https://Stackoverflow.com", "https://Stackoverflow.com/users/986/" ]
I've got a really odd error message that only occurs when I add the following line to my project: ``` std::list<CRect> myVar; ``` It's worth noting that it doesn't have to be a std::list, it can be std::vector or any other STL container I assume. Here is the error message: > > Error 1 error LNK2005: "public: > \...
I recently stumbled across this error again in our project and decided to have a more thorough investigation compared to just patching it up with a hack like last time (swap std::list for CArray). It turns out that one of our low level libraries was inheriting from std::list, e.g. ``` class LIB_EXPORT CRectList : publ...
148,185
<p>C++ preprocessor <code>#define</code> is totally different.</p> <p>Is the PHP <code>define()</code> any different than just creating a var?</p> <pre><code>define("SETTING", 0); $something = SETTING; </code></pre> <p>vs</p> <pre><code>$setting = 0; $something = $setting; </code></pre>
[ { "answer_id": 148191, "author": "Paul Dixon", "author_id": 6521, "author_profile": "https://Stackoverflow.com/users/6521", "pm_score": 2, "selected": false, "text": "<p>Here are the differences, from the <a href=\"http://uk3.php.net/manual/en/language.constants.php\" rel=\"nofollow nore...
2008/09/29
[ "https://Stackoverflow.com/questions/148185", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21240/" ]
C++ preprocessor `#define` is totally different. Is the PHP `define()` any different than just creating a var? ``` define("SETTING", 0); $something = SETTING; ``` vs ``` $setting = 0; $something = $setting; ```
'define' operation itself is rather slow - confirmed by xdebug profiler. Here is benchmarks from <http://t3.dotgnu.info/blog/php/my-first-php-extension.html>: * pure 'define' 380.785 fetches/sec 14.2647 mean msecs/first-response * constants defined with 'hidef' extension 930.783 fetches/sec 6.30279 mean ...
148,202
<p>Microsoft <a href="http://weblogs.asp.net/scottgu/archive/2008/09/28/jquery-and-microsoft.aspx" rel="nofollow noreferrer">recently announced</a> that the Javascript/HTML DOM library <strong>jQuery will be integrated</strong> into the ASP.NET MVC framework and into ASP.NET / Visual Studio.</p> <p>What is the best pr...
[ { "answer_id": 148241, "author": "Aaron Powell", "author_id": 11388, "author_profile": "https://Stackoverflow.com/users/11388", "pm_score": 1, "selected": false, "text": "<p>There's a small issue which is mentioned by David Ward here: <a href=\"http://encosia.com/2008/09/28/avoid-this-tr...
2008/09/29
[ "https://Stackoverflow.com/questions/148202", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6461/" ]
Microsoft [recently announced](http://weblogs.asp.net/scottgu/archive/2008/09/28/jquery-and-microsoft.aspx) that the Javascript/HTML DOM library **jQuery will be integrated** into the ASP.NET MVC framework and into ASP.NET / Visual Studio. What is the best practice or strategy adopting jQuery using **ASP.NET 2.0**? I'...
For me, problems arise when using UpdatePanels and jQuery (no problem with MVC, which doesn't have a Page Life-Cycle and is truly stateless). For instance, the useful jQuery idiom ``` $(function() { // some actions }); ``` used to enhance your DOM or attach events to the DOM elements may not interact very well w...
148,225
<p>Suppose I have one long long int and want to take its bits and construct four unsigned short ints out of it.</p> <p>Particular order doesn't matter much here.</p> <p>I generally know that I need to shift bits and truncate to the size of unsigned short int. But I think I may make some weird mistake somewhere, so I...
[ { "answer_id": 148230, "author": "C. K. Young", "author_id": 13, "author_profile": "https://Stackoverflow.com/users/13", "pm_score": 5, "selected": true, "text": "<pre><code>#include &lt;stdint.h&gt;\n#include &lt;stdio.h&gt;\n\nunion ui64 {\n uint64_t one;\n uint16_t four[4];\n};\...
2008/09/29
[ "https://Stackoverflow.com/questions/148225", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9403/" ]
Suppose I have one long long int and want to take its bits and construct four unsigned short ints out of it. Particular order doesn't matter much here. I generally know that I need to shift bits and truncate to the size of unsigned short int. But I think I may make some weird mistake somewhere, so I ask.
``` #include <stdint.h> #include <stdio.h> union ui64 { uint64_t one; uint16_t four[4]; }; int main() { union ui64 number = {0x123456789abcdef0}; printf("%x %x %x %x\n", number.four[0], number.four[1], number.four[2], number.four[3]); return 0; } ```
148,251
<p>My favorite equation for centering an xhtml element using only CSS is as follows:</p> <pre><code>display: block; position: absolute; width: _insert width here_; left: 50%; margin-left: _insert width divided by two &amp; multiplied by negative one here_ </code></pre> <p>There's also the simpler margin:auto method i...
[ { "answer_id": 148265, "author": "Oli", "author_id": 12870, "author_profile": "https://Stackoverflow.com/users/12870", "pm_score": 3, "selected": false, "text": "<p>Well that seems like massive overkill, I've got to say. I tend to set the container to <code>text-align:center;</code> for ...
2008/09/29
[ "https://Stackoverflow.com/questions/148251", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14026/" ]
My favorite equation for centering an xhtml element using only CSS is as follows: ``` display: block; position: absolute; width: _insert width here_; left: 50%; margin-left: _insert width divided by two & multiplied by negative one here_ ``` There's also the simpler margin:auto method in browsers that support it. Do...
Stick with Margin: 0 auto; for horizontal alignment; If you need vertical alignment as well use position: absolute; top: 50%; margin-top: -(width/2)px; Be aware though, If your container has more width than your screen a part of it will fall off screen on the left side using the Position: absolute method.
148,262
<p>In Oracle, I have set the <code>log_archive_dest1='D:\app\administrator\orcl\archive'</code> parameter and shutdown the database. When I tried to start up the db, I got the following error:</p> <pre><code>SQL&gt; startup mount; ORA-16032: parameter LOG_ARCHIVE_DEST_1 destination string cannot be translated ORA-09...
[ { "answer_id": 148285, "author": "sparklewhiskers", "author_id": 23402, "author_profile": "https://Stackoverflow.com/users/23402", "pm_score": 1, "selected": false, "text": "<p>I've never used Oracle but some things you might try are</p>\n\n<ul>\n<li>Make sure the permissions on the file...
2008/09/29
[ "https://Stackoverflow.com/questions/148262", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
In Oracle, I have set the `log_archive_dest1='D:\app\administrator\orcl\archive'` parameter and shutdown the database. When I tried to start up the db, I got the following error: ``` SQL> startup mount; ORA-16032: parameter LOG_ARCHIVE_DEST_1 destination string cannot be translated ORA-09291: sksachk: invalid device...
You probably need a trailing \ on the dir name ie D:\app\administrator\orcl\archive\
148,275
<p>I want to draw DirectX content so that it appears to be floating over top of the desktop and any other applications that are running. I also need to be able to make the directx content semi-transparent, so other things show through. Is there a way of doing this?</p> <p>I am using Managed DX with C#.</p>
[ { "answer_id": 148288, "author": "OregonGhost", "author_id": 20363, "author_profile": "https://Stackoverflow.com/users/20363", "pm_score": 2, "selected": false, "text": "<p>I guess that will be hard without using the Desktop Window Manager, i.e. if you want to support Windows XP. With th...
2008/09/29
[ "https://Stackoverflow.com/questions/148275", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23407/" ]
I want to draw DirectX content so that it appears to be floating over top of the desktop and any other applications that are running. I also need to be able to make the directx content semi-transparent, so other things show through. Is there a way of doing this? I am using Managed DX with C#.
I found a solution which works on Vista, starting from the link provided by OregonGhost. This is the basic process, in C# syntax. This code is in a class inheriting from Form. It doesn't seem to work if in a UserControl: ``` //this will allow you to import the necessary functions from the .dll using System.Runtime.Int...
148,281
<p>The output we get when printing C++ sources from Eclipse is rather ugly. </p> <p>Is there are way/a plugin to pretty print C++ source code like e.g. with a2ps (which is probably using yet another filter for C source code)?</p>
[ { "answer_id": 148313, "author": "epatel", "author_id": 842, "author_profile": "https://Stackoverflow.com/users/842", "pm_score": 2, "selected": false, "text": "<p>See this <a href=\"http://www.ddj.com/cpp/197002115?pgno=4\" rel=\"nofollow noreferrer\">DDJ</a> article which uses <em>ensc...
2008/09/29
[ "https://Stackoverflow.com/questions/148281", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19734/" ]
The output we get when printing C++ sources from Eclipse is rather ugly. Is there are way/a plugin to pretty print C++ source code like e.g. with a2ps (which is probably using yet another filter for C source code)?
I also use `enscript` for this. Here's an alias I often use: ``` alias cpp2ps='enscript --color --pretty-print=cpp --language=PostScript' ``` and I use it like this: ``` cpp2ps -P main.ps main.cpp ``` There are several other great options in `enscript` including rotating, 2-column output, line numbers, headers/...
148,298
<p>Okay, we know that the following two lines are equivalent - </p> <ol> <li><code>(0 == i)</code></li> <li><code>(i == 0)</code></li> </ol> <p>Also, the first method was encouraged in the past because that would have allowed the compiler to give an error message if you accidentally used '=' instead of '=='.</p> <p>...
[ { "answer_id": 148299, "author": "Hans Sjunnesson", "author_id": 8683, "author_profile": "https://Stackoverflow.com/users/8683", "pm_score": 2, "selected": false, "text": "<p>I think it's just a matter of style. And it does help with accidentally using assignment operator.</p>\n\n<p>I ab...
2008/09/29
[ "https://Stackoverflow.com/questions/148298", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6621/" ]
Okay, we know that the following two lines are equivalent - 1. `(0 == i)` 2. `(i == 0)` Also, the first method was encouraged in the past because that would have allowed the compiler to give an error message if you accidentally used '=' instead of '=='. My question is - in today's generation of pretty slick IDE's a...
I prefer the second one, (i == 0), because it feel much more natural when reading it. You ask people, "Are you 21 or older?", not, "Is 21 less than or equal to your age?"
148,305
<p>I'm working on a SaaS application where each customer will have different configurations depending on the edition they have purchased, additional features they have purchased, etc. For example, a customer might have a limit of 3 custom reports.</p> <p>Obviously I want to store this configuration in the database, bu...
[ { "answer_id": 148331, "author": "Vinko Vrsalovic", "author_id": 5190, "author_profile": "https://Stackoverflow.com/users/5190", "pm_score": 1, "selected": false, "text": "<p>The key value pair table, but with everything is stored as a string and with another column (if necessary) saying...
2008/09/29
[ "https://Stackoverflow.com/questions/148305", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4048/" ]
I'm working on a SaaS application where each customer will have different configurations depending on the edition they have purchased, additional features they have purchased, etc. For example, a customer might have a limit of 3 custom reports. Obviously I want to store this configuration in the database, but I am uns...
I think this would depend on how your product was sold to the customer. If you only sell it in packages... ``` PACKAGE 1 -> 3 reports, date entry, some other stuff. PACKAGE 2 -> 6 reports, more stuff PACKAGE 3 -> 12 reports, almost all the stuff UBER PACKAGE -> everything ``` I would think it would be easier to set...
148,314
<p>I have integrated SRM 5.0 into Portal. Most of the iviews are IAC i.e., all are ITS based services.</p> <p>The issue is that the Portal Theme does not get reflected on these services after integration.</p> <p>When a BSP or Webdynpro is integrated then the application reflects the Portal Theme when executed from Port...
[ { "answer_id": 148331, "author": "Vinko Vrsalovic", "author_id": 5190, "author_profile": "https://Stackoverflow.com/users/5190", "pm_score": 1, "selected": false, "text": "<p>The key value pair table, but with everything is stored as a string and with another column (if necessary) saying...
2008/09/29
[ "https://Stackoverflow.com/questions/148314", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have integrated SRM 5.0 into Portal. Most of the iviews are IAC i.e., all are ITS based services. The issue is that the Portal Theme does not get reflected on these services after integration. When a BSP or Webdynpro is integrated then the application reflects the Portal Theme when executed from Portal but the ITS ...
I think this would depend on how your product was sold to the customer. If you only sell it in packages... ``` PACKAGE 1 -> 3 reports, date entry, some other stuff. PACKAGE 2 -> 6 reports, more stuff PACKAGE 3 -> 12 reports, almost all the stuff UBER PACKAGE -> everything ``` I would think it would be easier to set...
148,350
<p>I want to be able to access custom URLs with apache httpclient. Something like this:</p> <pre><code>HttpClient client = new HttpClient(); HttpMethod method = new GetMethod("media:///squishy.jpg"); int statusCode = client.executeMethod(method); </code></pre> <p>Can I somehow register a custom URL handler? Or should...
[ { "answer_id": 148390, "author": "WMR", "author_id": 2844, "author_profile": "https://Stackoverflow.com/users/2844", "pm_score": 1, "selected": true, "text": "<p>I don't think there's a way to do this in commons httpclient. It doesn't make a whole lot of sense either, after all it is a H...
2008/09/29
[ "https://Stackoverflow.com/questions/148350", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11384/" ]
I want to be able to access custom URLs with apache httpclient. Something like this: ``` HttpClient client = new HttpClient(); HttpMethod method = new GetMethod("media:///squishy.jpg"); int statusCode = client.executeMethod(method); ``` Can I somehow register a custom URL handler? Or should I just register one with ...
I don't think there's a way to do this in commons httpclient. It doesn't make a whole lot of sense either, after all it is a HTTP client and "media:///squishy.jpg" is not HTTP, so all the code to implement the HTTP protocol probably couldn't be used anyways. ``` URL.setURLStreamHandlerFactory(...) ``` could be the w...
148,361
<p>I am building an application where I want to be able to click a rectangle represented by a DIV, and then use the keyboard to move that DIV by listing for keyboard events.</p> <p>Rather than using an event listener for those keyboard events at the document level, can I listen for keyboard events at the DIV level, pe...
[ { "answer_id": 148444, "author": "Paul Dixon", "author_id": 6521, "author_profile": "https://Stackoverflow.com/users/6521", "pm_score": 8, "selected": true, "text": "<p>Sorted - I added tabindex attribute to the target DIV, which causes it to pick up keyboard events, for example</p>\n\n<...
2008/09/29
[ "https://Stackoverflow.com/questions/148361", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6521/" ]
I am building an application where I want to be able to click a rectangle represented by a DIV, and then use the keyboard to move that DIV by listing for keyboard events. Rather than using an event listener for those keyboard events at the document level, can I listen for keyboard events at the DIV level, perhaps by g...
Sorted - I added tabindex attribute to the target DIV, which causes it to pick up keyboard events, for example ``` <div id="inner" tabindex="0"> this div can now have focus and receive keyboard events </div> ``` Information gleaned from <http://www.w3.org/WAI/GL/WCAG20/WD-WCAG20-TECHS/SCR29.html>
148,373
<p>I wrote a sample program at <a href="http://codepad.org/ko8vVCDF" rel="noreferrer">http://codepad.org/ko8vVCDF</a> that uses a template function.</p> <p>How do I retrict the template function to only use numbers? (int, double etc.)</p> <pre><code>#include &lt;vector&gt; #include &lt;iostream&gt; using namespace s...
[ { "answer_id": 148377, "author": "C. K. Young", "author_id": 13, "author_profile": "https://Stackoverflow.com/users/13", "pm_score": 1, "selected": false, "text": "<p>Why would you want to restrict the types in this case? Templates allow \"static duck typing\", so anything allowed by wha...
2008/09/29
[ "https://Stackoverflow.com/questions/148373", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22040/" ]
I wrote a sample program at <http://codepad.org/ko8vVCDF> that uses a template function. How do I retrict the template function to only use numbers? (int, double etc.) ``` #include <vector> #include <iostream> using namespace std; template <typename T> T sum(vector<T>& a) { T result = 0; int size = a.si...
The only way to restrict a template is to make it so that it uses something from the types that you want, that other types don't have. So, you construct with an int, use + and +=, call a copy constructor, etc. Any type that has all of these will work with your function -- so, if I create a new type that has these fea...
148,403
<p>Is it possible to convert UTF8 string in a std::string to std::wstring and vice versa in a platform independent manner? In a Windows application I would use MultiByteToWideChar and WideCharToMultiByte. However, the code is compiled for multiple OSes and I'm limited to standard C++ library.</p>
[ { "answer_id": 148419, "author": "C. K. Young", "author_id": 13, "author_profile": "https://Stackoverflow.com/users/13", "pm_score": 2, "selected": false, "text": "<p>You can use the <a href=\"http://en.cppreference.com/w/cpp/locale/codecvt\" rel=\"nofollow noreferrer\"><code>codecvt</co...
2008/09/29
[ "https://Stackoverflow.com/questions/148403", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22764/" ]
Is it possible to convert UTF8 string in a std::string to std::wstring and vice versa in a platform independent manner? In a Windows application I would use MultiByteToWideChar and WideCharToMultiByte. However, the code is compiled for multiple OSes and I'm limited to standard C++ library.
I've asked this question 5 years ago. This thread was very helpful for me back then, I came to a conclusion, then I moved on with my project. It is funny that I needed something similar recently, totally unrelated to that project from the past. As I was researching for possible solutions, I stumbled upon my own questio...
148,407
<p>Why does the code below return true only for a = 1?</p> <pre><code>main(){ int a = 10; if (true == a) cout&lt;&lt;"Why am I not getting executed"; } </code></pre>
[ { "answer_id": 148411, "author": "OregonGhost", "author_id": 20363, "author_profile": "https://Stackoverflow.com/users/20363", "pm_score": 2, "selected": false, "text": "<p>Because true is 1. If you want to test a for a non-zero value, just write if(a).</p>\n" }, { "answer_id": 1...
2008/09/29
[ "https://Stackoverflow.com/questions/148407", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22076/" ]
Why does the code below return true only for a = 1? ``` main(){ int a = 10; if (true == a) cout<<"Why am I not getting executed"; } ```
When a Bool true is converted to an int, it's always converted to 1. Your code is thus, equivalent to: ``` main(){ int a = 10; if (1 == a) cout<<"y i am not getting executed"; } ``` This is part of the [C++ standard](http://www.bond.id.au/~gnb/wp/cd2/conv.html), so it's something you would expect to h...
148,421
<p>I have a button on an ASP.NET wep application form and when clicked goes off and posts information a third party web service. </p> <p>I have an UpdateProgress associated with the button. </p> <p>how do disable/hide the button while the progress is visible (i.e. the server has not completed the operation) </p> <p>...
[ { "answer_id": 148426, "author": "Lou Franco", "author_id": 3937, "author_profile": "https://Stackoverflow.com/users/3937", "pm_score": 1, "selected": false, "text": "<p>Easiest way it to put a semi-transparent png over the entire page -- then they can't send events to the page below. I...
2008/09/29
[ "https://Stackoverflow.com/questions/148421", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11802/" ]
I have a button on an ASP.NET wep application form and when clicked goes off and posts information a third party web service. I have an UpdateProgress associated with the button. how do disable/hide the button while the progress is visible (i.e. the server has not completed the operation) I am looking at doing th...
You'll have to hook a javascript method to the page request manager (Sys.WebForms.PageRequestManager.getInstance().add\_initializeRequest). Here is the code I would use to hide the buttons, I would prefer the disable them (see how that's done in the link at the bottom). ASP.NET ------- ``` <div id="ButtonBar"> <asp...
148,441
<p>If I have a script tag like this:</p> <pre><code>&lt;script id = "myscript" src = "http://www.example.com/script.js" type = "text/javascript"&gt; &lt;/script&gt; </code></pre> <p>I would like to get the content of the "script.js" file. I'm thinking about something like <code>document.getElementById("my...
[ { "answer_id": 148447, "author": "Lasar", "author_id": 9438, "author_profile": "https://Stackoverflow.com/users/9438", "pm_score": 5, "selected": true, "text": "<p>Do you want to get the contents of the file <a href=\"http://www.example.com/script.js\" rel=\"nofollow noreferrer\">http://...
2008/09/29
[ "https://Stackoverflow.com/questions/148441", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23423/" ]
If I have a script tag like this: ``` <script id = "myscript" src = "http://www.example.com/script.js" type = "text/javascript"> </script> ``` I would like to get the content of the "script.js" file. I'm thinking about something like `document.getElementById("myscript").text` but it doesn't work in this ...
Do you want to get the contents of the file <http://www.example.com/script.js>? If so, you could turn to AJAX methods to fetch its content, assuming it resides on the same server as the page itself.
148,451
<p>I would like to update a large number of C++ source files with an extra include directive before any existing #includes. For this sort of task, I normally use a small bash script with sed to re-write the file. </p> <p>How do I get <code>sed</code> to replace just the first occurrence of a string in a file rather th...
[ { "answer_id": 148473, "author": "Ben Hoffstein", "author_id": 4482, "author_profile": "https://Stackoverflow.com/users/4482", "pm_score": 8, "selected": true, "text": "<pre><code> # sed script to change \"foo\" to \"bar\" only on the first occurrence\n 1{x;s/^/first/;x;}\n 1,/foo/{x;/fi...
2008/09/29
[ "https://Stackoverflow.com/questions/148451", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5022/" ]
I would like to update a large number of C++ source files with an extra include directive before any existing #includes. For this sort of task, I normally use a small bash script with sed to re-write the file. How do I get `sed` to replace just the first occurrence of a string in a file rather than replacing every oc...
``` # sed script to change "foo" to "bar" only on the first occurrence 1{x;s/^/first/;x;} 1,/foo/{x;/first/s///;x;s/foo/bar/;} #---end of script--- ``` or, if you prefer: Editor's note: works with *GNU* `sed` only. ```sh sed '0,/foo/s//bar/' file ``` [Source](http://www.linuxtopia.org/online_books/linux_tool_...
148,503
<p>I am trying to upload a file using to Flickr using JQuery. I have a form (which works if I dont use JQuery) which I am submitting using the Form Plugin. My code is as follows:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;Test Upload&lt;/title&gt; &lt;script type="text/javascript" src="jquery-1.2.6.js"&gt;...
[ { "answer_id": 148534, "author": "Devon", "author_id": 13850, "author_profile": "https://Stackoverflow.com/users/13850", "pm_score": 0, "selected": false, "text": "<p>You will not be able to upload a file via AJAX this way.</p>\n\n<p>A pure AJAX file upload system is not possible because...
2008/09/29
[ "https://Stackoverflow.com/questions/148503", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I am trying to upload a file using to Flickr using JQuery. I have a form (which works if I dont use JQuery) which I am submitting using the Form Plugin. My code is as follows: ``` <html> <head> <title>Test Upload</title> <script type="text/javascript" src="jquery-1.2.6.js"></script> <script type="text/javascript" src...
See this other thread about uploading files with AJAX: [How can I upload files asynchronously?](https://stackoverflow.com/questions/166221/how-to-upload-file-jquery) I've never tried it, but it seems that you can't get the server response (not easily, anyway)
148,511
<p>Suppose I have a LimitedValue class which holds a value, and is parameterized on int types 'min' and 'max'. You'd use it as a container for holding values which can only be in a certain range. You could use it such:</p> <pre><code>LimitedValue&lt; float, 0, 360 &gt; someAngle( 45.0 ); someTrigFunction( someAngle ...
[ { "answer_id": 148539, "author": "workmad3", "author_id": 16035, "author_profile": "https://Stackoverflow.com/users/16035", "pm_score": 1, "selected": false, "text": "<p>At the moment, that is impossible in a portable manner due to the C++ rules on how methods (and by extension, construc...
2008/09/29
[ "https://Stackoverflow.com/questions/148511", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23434/" ]
Suppose I have a LimitedValue class which holds a value, and is parameterized on int types 'min' and 'max'. You'd use it as a container for holding values which can only be in a certain range. You could use it such: ``` LimitedValue< float, 0, 360 > someAngle( 45.0 ); someTrigFunction( someAngle ); ``` so that 'some...
You can do this using templates -- try something like this: ``` template< typename T, int min, int max >class LimitedValue { template< int min2, int max2 >LimitedValue( const LimitedValue< T, min2, max2 > &other ) { static_assert( min <= min2, "Parameter minimum must be >= this minimum" ); static_assert( m...
148,513
<p>Using <a href="http://en.wikipedia.org/wiki/Apache_Ant" rel="nofollow noreferrer">Ant</a> I could unzip an archive before proceeding with the build per-se ... Is this possible using nmake? Could I call an external application? Or even a batch script?</p>
[ { "answer_id": 148560, "author": "akauppi", "author_id": 14455, "author_profile": "https://Stackoverflow.com/users/14455", "pm_score": 0, "selected": false, "text": "<p>You can call an external application from nmake Makefiles, just as from any other Makefile.</p>\n\n<p>However, what to ...
2008/09/29
[ "https://Stackoverflow.com/questions/148513", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11234/" ]
Using [Ant](http://en.wikipedia.org/wiki/Apache_Ant) I could unzip an archive before proceeding with the build per-se ... Is this possible using nmake? Could I call an external application? Or even a batch script?
Any variant on make has the ability to perform any task that can be done from the command line. Indeed, most of the build functionality of any makefile is going to depend upon the onvocation of external processes such as the compiler, linker, librarian, etc. The only downside to make is that there are so many variation...
148,518
<p>It seems the .NET Regex.Replace method automatically replaces all matching occurrences. I could provide a MatchEvaluator delegate that returns the matched string after the first replacement, rendering no change, but that sounds very inefficient to me.</p> <p>What is the most efficient way to stop after the first r...
[ { "answer_id": 148526, "author": "bzlm", "author_id": 7724, "author_profile": "https://Stackoverflow.com/users/7724", "pm_score": 6, "selected": true, "text": "<p>From <a href=\"http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex.replace.aspx\" rel=\"noreferrer\"...
2008/09/29
[ "https://Stackoverflow.com/questions/148518", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3347/" ]
It seems the .NET Regex.Replace method automatically replaces all matching occurrences. I could provide a MatchEvaluator delegate that returns the matched string after the first replacement, rendering no change, but that sounds very inefficient to me. What is the most efficient way to stop after the first replacement?
From [MSDN](http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex.replace.aspx): ``` Replace(String, String, Int32) ``` > > Within a specified input string, replaces a specified maximum number of strings that > match a regular expression pattern with a specified replacement string. > > ...
148,587
<p>I am currently getting exceptions when modifying an IBindingList on multiple threads. Does anyone have a threadsafe version before I write my own?</p>
[ { "answer_id": 148639, "author": "Ben Straub", "author_id": 1319, "author_profile": "https://Stackoverflow.com/users/1319", "pm_score": 2, "selected": false, "text": "<p>I think you'll find this an incredibly difficult task. The easier path would be to prevent multiple-thread access with...
2008/09/29
[ "https://Stackoverflow.com/questions/148587", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23385/" ]
I am currently getting exceptions when modifying an IBindingList on multiple threads. Does anyone have a threadsafe version before I write my own?
I think you'll find this an incredibly difficult task. The easier path would be to prevent multiple-thread access with a `lock`: ``` void AddItemToList(object o) { lock(myBindingList) { myBindingList.Add(o); } } ``` Look at the [lock statement docs](http://msdn.microsoft.com/en-us/library/c5kehkc...
148,594
<p>Suppose I have a non-recurring event that needs to be raised X seconds from now such as a timeout. Intuitively it would make sense to create a System.Timers.Timer, set its interval to X*1000, wire its tick up to the event and start it. Since this is a non-recurring event and you only want it raised once you would ...
[ { "answer_id": 148602, "author": "Joachim Kerschbaumer", "author_id": 20227, "author_profile": "https://Stackoverflow.com/users/20227", "pm_score": 3, "selected": false, "text": "<p>just use a normal timer and disable it after it has elapsed once.\nthat should solve your problem.</p>\n\n...
2008/09/29
[ "https://Stackoverflow.com/questions/148594", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5056/" ]
Suppose I have a non-recurring event that needs to be raised X seconds from now such as a timeout. Intuitively it would make sense to create a System.Timers.Timer, set its interval to X\*1000, wire its tick up to the event and start it. Since this is a non-recurring event and you only want it raised once you would then...
This [constructor](http://msdn.microsoft.com/en-us/library/ah1h85ch.aspx) for the System.Threading.Timer allows you to specify a **period**. If you set this parameter to -1, it will disable periodic signaling and only execute once. ``` public Timer( TimerCallback callback, Object state, TimeSpan dueTime, ...
148,601
<p>Is it possible to access a constant value (i.e. a public static final variable defined in a Java class) from a Velocity template?</p> <p>I would like to be able to write something like this:</p> <pre><code>#if ($a lt Long.MAX_VALUE) </code></pre> <p>but this is apparently not the right syntax.</p>
[ { "answer_id": 148650, "author": "Angelo van der Sijpt", "author_id": 19144, "author_profile": "https://Stackoverflow.com/users/19144", "pm_score": 3, "selected": false, "text": "<p>Velocity can only use anything it finds in its context, after e.g.</p>\n\n<pre><code>context.put(\"MaxLong...
2008/09/29
[ "https://Stackoverflow.com/questions/148601", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4728/" ]
Is it possible to access a constant value (i.e. a public static final variable defined in a Java class) from a Velocity template? I would like to be able to write something like this: ``` #if ($a lt Long.MAX_VALUE) ``` but this is apparently not the right syntax.
There are a number of ways. 1) You can put the values directly in the context. 2) You can use the [FieldMethodizer](http://velocity.apache.org/engine/devel/apidocs/org/apache/velocity/app/FieldMethodizer.html) to make all public static fields in a class available. 3) You can use a custom Uberspect implementation th...
148,662
<p>Suppose I have one list:</p> <pre><code>IList&lt;int&gt; originalList = new List&lt;int&gt;(); originalList.add(1); originalList.add(5); originalList.add(10); </code></pre> <p>And another list... </p> <pre><code>IList&lt;int&gt; newList = new List&lt;int&gt;(); newList.add(1); newList.add(5); newList.add(7); ne...
[ { "answer_id": 148684, "author": "James Curran", "author_id": 12725, "author_profile": "https://Stackoverflow.com/users/12725", "pm_score": 3, "selected": false, "text": "<pre><code>originalList = newList;\n</code></pre>\n\n<p>Or if you prefer them being distinct lists:</p>\n\n<pre><code...
2008/09/29
[ "https://Stackoverflow.com/questions/148662", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6350/" ]
Suppose I have one list: ``` IList<int> originalList = new List<int>(); originalList.add(1); originalList.add(5); originalList.add(10); ``` And another list... ``` IList<int> newList = new List<int>(); newList.add(1); newList.add(5); newList.add(7); newList.add(11); ``` How can I update originalList so that: ...
Sorry, wrote my first response before I saw your last paragraph. ``` for(int i = originalList.length-1; i >=0; --i) { if (!newList.Contains(originalList[i]) originalList.RemoveAt(i); } foreach(int n in newList) { if (!originaList.Contains(n)) originalList.Add(n); } ```
148,669
<p>This <strike>is clearly not</strike> appears like it wouldn't be a best practice. Can someone explain why it would not be a best practice or how this works? Any books or articles providing an explanation would be appreciated.</p> <pre><code>//The constructor public Page_Index() { //create a local value st...
[ { "answer_id": 148688, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 6, "selected": true, "text": "<p>currentValue is no longer a local variable: it is a <em>captured</em> variable. This compiles to something like:</p...
2008/09/29
[ "https://Stackoverflow.com/questions/148669", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17091/" ]
This is clearly not appears like it wouldn't be a best practice. Can someone explain why it would not be a best practice or how this works? Any books or articles providing an explanation would be appreciated. ``` //The constructor public Page_Index() { //create a local value string currentValue = "This is the...
currentValue is no longer a local variable: it is a *captured* variable. This compiles to something like: ``` class Foo { public string currentValue; // yes, it is a field public void SomeMethod(object sender, EventArgs e) { Response.Write(currentValue); } } ... public Page_Index() { Foo foo = new Foo(); ...
148,704
<p>I've got the following user control:</p> <pre><code>&lt;TabItem x:Name="Self" x:Class="App.MyTabItem" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:app="clr-namespace:App" &gt; &lt;TabItem.Header&gt; ...
[ { "answer_id": 184582, "author": "Bob King", "author_id": 6897, "author_profile": "https://Stackoverflow.com/users/6897", "pm_score": 1, "selected": false, "text": "<p>Try this. I'm not sure if it will work or not, but </p>\n\n<pre><code>&lt;TabItem \n x:Name=\"Self\"\n x:Class=\"A...
2008/09/29
[ "https://Stackoverflow.com/questions/148704", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4918/" ]
I've got the following user control: ``` <TabItem x:Name="Self" x:Class="App.MyTabItem" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:app="clr-namespace:App" > <TabItem.Header> <!-- This works --> ...
What appears to be the problem is that you are using a ContentTemplate without actualy using the content property. The default DataContext for the ContentTemplate's DataTemplate is the Content property of TabItem. However, none of what I said actually explains **why** the binding doesn't work. Unfortunately I can't giv...
148,729
<p>I have a couple of buttons of which I modified how they look. I have set them as flat buttons with a background and a custom border so they look all pretty and nothing like normal buttons anymore (actually, they look like Office 2003 buttons now ;-). The buttons have a border of one pixel.</p> <p>However when the b...
[ { "answer_id": 148774, "author": "Orion Adrian", "author_id": 7756, "author_profile": "https://Stackoverflow.com/users/7756", "pm_score": 0, "selected": false, "text": "<p>Certainly you can draw the button yourself. One of the state flags is focused.</p>\n\n<p>So on the draw event if the...
2008/09/29
[ "https://Stackoverflow.com/questions/148729", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have a couple of buttons of which I modified how they look. I have set them as flat buttons with a background and a custom border so they look all pretty and nothing like normal buttons anymore (actually, they look like Office 2003 buttons now ;-). The buttons have a border of one pixel. However when the button gets...
Is this the effect you are looking for? ``` public class NoFocusCueButton : Button { protected override bool ShowFocusCues { get { return false; } } } ``` You can use this custom button class just like a regular button, but it won't give you an extra rectangle on focus...
148,742
<p>In C# how do you detect is a specific drive is a Hard Drive, Network Drive, CDRom, or floppy?</p>
[ { "answer_id": 148753, "author": "GEOCHET", "author_id": 5640, "author_profile": "https://Stackoverflow.com/users/5640", "pm_score": 2, "selected": false, "text": "<p><a href=\"http://msdn.microsoft.com/en-us/library/system.io.driveinfo.drivetype.aspx\" rel=\"nofollow noreferrer\">DriveI...
2008/09/29
[ "https://Stackoverflow.com/questions/148742", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13341/" ]
In C# how do you detect is a specific drive is a Hard Drive, Network Drive, CDRom, or floppy?
The method GetDrives() returns a DriveInfo class which has a property DriveType that corresponds to the enumeration of System.IO.DriveType: ``` public enum DriveType { Unknown, // The type of drive is unknown. NoRootDirectory, // The drive does not have a root directory. Removable, // The...
148,764
<p>In the vxWorks shell, there are a number of routines you can use to display information about the system. </p> <p>These routines are usually referred to as <strong>show</strong> routines because they tend to have the form of "xxxShow".</p> <p>Is there a list of these routines available?</p>
[ { "answer_id": 148773, "author": "Benoit", "author_id": 10703, "author_profile": "https://Stackoverflow.com/users/10703", "pm_score": 2, "selected": false, "text": "<p>There is no comprehensive list of all the show routines available. This will depend on your kernel configuration and wh...
2008/09/29
[ "https://Stackoverflow.com/questions/148764", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10703/" ]
In the vxWorks shell, there are a number of routines you can use to display information about the system. These routines are usually referred to as **show** routines because they tend to have the form of "xxxShow". Is there a list of these routines available?
I work with VxWorks 5.5 and use the symbol lookup function "lkup" to find functions and/or variables that I may be interested in. Execute the following command where ">" is the VxWorks shell prompt. ``` > lkup "Show" ``` This will output a list of symbols that include the "Show" in their name, including all of the ...
148,795
<p>Selecting the union:</p> <pre><code>select * from table1 union select * from table1_backup </code></pre> <p>What is the query to select the intersection?</p>
[ { "answer_id": 148803, "author": "Tom Ritter", "author_id": 8435, "author_profile": "https://Stackoverflow.com/users/8435", "pm_score": 3, "selected": false, "text": "<p>In SQL Server <a href=\"http://msdn.microsoft.com/en-us/library/ms188055.aspx\" rel=\"noreferrer\">intersect</a></p>\n...
2008/09/29
[ "https://Stackoverflow.com/questions/148795", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1765/" ]
Selecting the union: ``` select * from table1 union select * from table1_backup ``` What is the query to select the intersection?
In SQL Server [intersect](http://msdn.microsoft.com/en-us/library/ms188055.aspx) > > > ``` > select * from table1 > intersect > select * from table1_backup > > ``` > >
148,817
<p>Is there a component available list FileUpload which shows files on the server, not the client? </p> <p>I am basically looking for a clean dialog box to select server side files, like the one used in FileUpload.</p>
[ { "answer_id": 148913, "author": "Stephen Wrighton", "author_id": 7516, "author_profile": "https://Stackoverflow.com/users/7516", "pm_score": 1, "selected": false, "text": "<p>Nope. There's not. That said, you can use a listbox, and load the files into it.</p>\n\n<pre><code>public sub f...
2008/09/29
[ "https://Stackoverflow.com/questions/148817", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5836/" ]
Is there a component available list FileUpload which shows files on the server, not the client? I am basically looking for a clean dialog box to select server side files, like the one used in FileUpload.
Nope. There's not. That said, you can use a listbox, and load the files into it. ``` public sub file_DatabindListbox(directoryPath as string) for each fName as string in io.directory(directorypath).getfilenames() dim li as new listitem li.text = io.path.getfilename(fName) li.value = fName myFil...
148,828
<p>There are situations, where it is practical to have a type-cast return a null value instead of throwing a ClassCastException. C# has the <code>as</code> operator to do this. Is there something equivalent available in Java so you don't have to explicitly check for the ClassCastException?</p>
[ { "answer_id": 148841, "author": "Chris Marasti-Georg", "author_id": 96, "author_profile": "https://Stackoverflow.com/users/96", "pm_score": 4, "selected": false, "text": "<p>You can use the <code>instanceof</code> keyword in place of C#'s <code>is</code>, but there is nothing like <code...
2008/09/29
[ "https://Stackoverflow.com/questions/148828", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23424/" ]
There are situations, where it is practical to have a type-cast return a null value instead of throwing a ClassCastException. C# has the `as` operator to do this. Is there something equivalent available in Java so you don't have to explicitly check for the ClassCastException?
Here's an implementation of as, as suggested by @Omar Kooheji: ``` public static <T> T as(Class<T> clazz, Object o){ if(clazz.isInstance(o)){ return clazz.cast(o); } return null; } as(A.class, new Object()) --> null as(B.class, new B()) --> B ```
148,838
<p>I'm trying to get started writing some Ruby on Rails apps and have been successful with Mongrel but, I'd like to deploy my apps to my Apache 2.2 instance on Windows? All the tutorials I've found seem out of date and are for older versions of Apache/Rails.</p> <p>Does anyone know of a good, current tutorial for con...
[ { "answer_id": 148947, "author": "Dave Nolan", "author_id": 9474, "author_profile": "https://Stackoverflow.com/users/9474", "pm_score": 5, "selected": true, "text": "<p><strong>EDIT:</strong> At least until there's a Phusion Passenger for Win, Apache + Mongrel is the way to go. You can u...
2008/09/29
[ "https://Stackoverflow.com/questions/148838", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2109/" ]
I'm trying to get started writing some Ruby on Rails apps and have been successful with Mongrel but, I'd like to deploy my apps to my Apache 2.2 instance on Windows? All the tutorials I've found seem out of date and are for older versions of Apache/Rails. Does anyone know of a good, current tutorial for configuring Ap...
**EDIT:** At least until there's a Phusion Passenger for Win, Apache + Mongrel is the way to go. You can use Apache + FastCGI without Mongrel, but under real loads you will get (more) zombie processes and (more) memory leaks. You could also look at proxying to [Thin](http://code.macournoyer.com/thin/) in the same way ...
148,853
<p>Is there an easy way to cache things when using urllib2 that I am over-looking, or do I have to roll my own?</p>
[ { "answer_id": 148891, "author": "danivovich", "author_id": 17583, "author_profile": "https://Stackoverflow.com/users/17583", "pm_score": 3, "selected": false, "text": "<p>This ActiveState Python recipe might be helpful:\n<a href=\"http://code.activestate.com/recipes/491261/\" rel=\"nofo...
2008/09/29
[ "https://Stackoverflow.com/questions/148853", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17865/" ]
Is there an easy way to cache things when using urllib2 that I am over-looking, or do I have to roll my own?
You could use a decorator function such as: ``` class cache(object): def __init__(self, fun): self.fun = fun self.cache = {} def __call__(self, *args, **kwargs): key = str(args) + str(kwargs) try: return self.cache[key] except KeyError: self.cac...
148,854
<p>I have a <code>DataGridView</code> with several created columns. I've add some rows and they get displayed correctly; however, when I click on a cell, the content disappears.</p> <p>What am I doing wrong?</p> <p>The code is as follows:</p> <pre><code>foreach (SaleItem item in this.Invoice.SaleItems) { DataGri...
[ { "answer_id": 887025, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "<p><em>Edit: oops! made a mistake on the second line of code. - fixed it.</em></p>\n\n<p>Sometimes, I hate defining the dataso...
2008/09/29
[ "https://Stackoverflow.com/questions/148854", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3086/" ]
I have a `DataGridView` with several created columns. I've add some rows and they get displayed correctly; however, when I click on a cell, the content disappears. What am I doing wrong? The code is as follows: ``` foreach (SaleItem item in this.Invoice.SaleItems) { DataGridViewRow row = new DataGridViewRow(); ...
Just to extend this question, there's also another way to add a row to a `DataGridView`, especially if the columns are always the same: ``` object[] buffer = new object[5]; List<DataGridViewRow> rows = new List<DataGridViewRow>(); foreach (SaleItem item in this.Invoice.SaleItems) { buffer[0] = item.Quantity; b...
148,856
<p>I need to call an external dll from c#. This is the header definition:</p> <pre><code>enum WatchMode { WATCH_MODE_SYSTEM = 0, WATCH_MODE_APPLICATION = 1 }; LONG ADS_API WDT_GetMode ( LONG i_hHandle, WatchMode * o_pWatchMode ); </code></pre> <p>I've added the enum and the call in C#:</p> <pre>...
[ { "answer_id": 150019, "author": "JaredPar", "author_id": 23283, "author_profile": "https://Stackoverflow.com/users/23283", "pm_score": 4, "selected": true, "text": "<p>You're running into a parameter size problem difference between C# and C++. In the C++/windows world LONG is a 4 byte ...
2008/09/29
[ "https://Stackoverflow.com/questions/148856", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6399/" ]
I need to call an external dll from c#. This is the header definition: ``` enum WatchMode { WATCH_MODE_SYSTEM = 0, WATCH_MODE_APPLICATION = 1 }; LONG ADS_API WDT_GetMode ( LONG i_hHandle, WatchMode * o_pWatchMode ); ``` I've added the enum and the call in C#: ``` public enum WatchMode { WAT...
You're running into a parameter size problem difference between C# and C++. In the C++/windows world LONG is a 4 byte signed integer. In the C# world long is a 8 byte signed integer. You should change your C# signature to take an int. ffpf is wrong in saying that you should use an IntPtr here. It will fix this particu...
148,867
<p>I have been googling for a good time on how to move a file with c# using the TFS API. The idea is to have a folder on which the developers drop database upgrade scripts and the build process get's to the folder creates a build script and moves all the files on the folder to a new folder with the database build versi...
[ { "answer_id": 149071, "author": "TcKs", "author_id": 20382, "author_profile": "https://Stackoverflow.com/users/20382", "pm_score": 4, "selected": false, "text": "<p>Its pretty simple :).</p>\n\n<pre><code>Microsoft.TeamFoundation.VersionControl.Client.Workspace workspace = GetMyTfsWorks...
2008/09/29
[ "https://Stackoverflow.com/questions/148867", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23460/" ]
I have been googling for a good time on how to move a file with c# using the TFS API. The idea is to have a folder on which the developers drop database upgrade scripts and the build process get's to the folder creates a build script and moves all the files on the folder to a new folder with the database build version ...
Its pretty simple :). ``` Microsoft.TeamFoundation.VersionControl.Client.Workspace workspace = GetMyTfsWorkspace(); workspace.PendRename( oldPath, newPath ); ``` Then you need CheckIn it of course. Use a "workspace.GetPendingChanges()" and "workspace.CheckIn()" methods to do it.
148,875
<p>In an OLAP database I work with there is a 'Location' hierarchy consisting of the levels Company -> Region -> Area -> Site -> Room. I am using the following MDX to get all the descendants of a particular member at company level.</p> <pre><code>DESCENDANTS([Location].[Test Company],[Location].[Site], SELF_AND_BEFORE...
[ { "answer_id": 148897, "author": "Magnus Smith", "author_id": 11461, "author_profile": "https://Stackoverflow.com/users/11461", "pm_score": 6, "selected": true, "text": "<p>The EXCEPT function will take a set, and remove the members you dont want. In your case you need to say:</p>\n\n<pr...
2008/09/29
[ "https://Stackoverflow.com/questions/148875", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7585/" ]
In an OLAP database I work with there is a 'Location' hierarchy consisting of the levels Company -> Region -> Area -> Site -> Room. I am using the following MDX to get all the descendants of a particular member at company level. ``` DESCENDANTS([Location].[Test Company],[Location].[Site], SELF_AND_BEFORE) ``` I now ...
The EXCEPT function will take a set, and remove the members you dont want. In your case you need to say: ``` EXCEPT( {DESCENDANTS([Location].[Test Company],[Location].[Site], SELF_AND_BEFORE)}, {DESCENDANTS([Location].[Whatever].[Redundant],[Location].[Site], SELF_AND_BEFORE)} ) ``` This gives you everything in the ...
148,879
<p>My .NET application fails when run from a network drive even when the very same executable runs perfectly fine from a local hard drive?</p> <p>I tried checking for "Full trust" like so:</p> <pre><code>try { // Demand full trust permissions PermissionSet fullTrust = new PermissionSet( PermissionState.Unrest...
[ { "answer_id": 148886, "author": "Gulzar Nazim", "author_id": 4337, "author_profile": "https://Stackoverflow.com/users/4337", "pm_score": 4, "selected": false, "text": "<p>Did you try Using <a href=\"http://blogs.msdn.com/shawnfa/archive/2004/12/30/344554.aspx\" rel=\"noreferrer\">CasPol...
2008/09/29
[ "https://Stackoverflow.com/questions/148879", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23461/" ]
My .NET application fails when run from a network drive even when the very same executable runs perfectly fine from a local hard drive? I tried checking for "Full trust" like so: ``` try { // Demand full trust permissions PermissionSet fullTrust = new PermissionSet( PermissionState.Unrestricted ); fullTru...
It indeed has to do with the fact the apps on a network location are less trusted then on your local hdd (due to the default policy of the .NET framework). If I'm not mistaken Microsoft finally corrected this annoyance in .NET 3.5 SP1 (after a lot of developers complaining). I google'd it: [.NET Framework 3.5 SP1 Al...
148,882
<p>I'm working on some code that uses a pattern in its business and data tiers that uses events to signal errors e.g. </p> <pre><code>resource = AllocateLotsOfMemory(); if (SomeCondition()) { OnOddError(new OddErrorEventArgs(resource.StatusProperty)); resource.FreeLotsOfMemory(); return; } </code><...
[ { "answer_id": 148892, "author": "Joel Coehoorn", "author_id": 3043, "author_profile": "https://Stackoverflow.com/users/3043", "pm_score": 2, "selected": false, "text": "<p>If you think in terms of \"Errors\" and \"Warnings\", I've had lots of luck when reserving events for the \"Warning...
2008/09/29
[ "https://Stackoverflow.com/questions/148882", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3546/" ]
I'm working on some code that uses a pattern in its business and data tiers that uses events to signal errors e.g. ``` resource = AllocateLotsOfMemory(); if (SomeCondition()) { OnOddError(new OddErrorEventArgs(resource.StatusProperty)); resource.FreeLotsOfMemory(); return; } ``` This looked supe...
Take a look at [this post](http://www.udidahan.com/2008/08/25/domain-events-take-2/) by Udi Dahan. Its an elegant approach for dispatching domain events. The previous poster is correct in saying that you should not be using an event mechanism to recover from fatal errors, but it is a very useful pattern for notificatio...
148,901
<p>I've always handled optional parameters in JavaScript like this:</p> <pre><code>function myFunc(requiredArg, optionalArg){ optionalArg = optionalArg || 'defaultValue'; // Do stuff } </code></pre> <p>Is there a better way to do it?</p> <p>Are there any cases where using <code>||</code> like that is going to f...
[ { "answer_id": 148918, "author": "Paul Dixon", "author_id": 6521, "author_profile": "https://Stackoverflow.com/users/6521", "pm_score": 11, "selected": true, "text": "<p>Your logic fails if optionalArg is passed, but evaluates as false - try this as an alternative</p>\n\n<pre><code>if (t...
2008/09/29
[ "https://Stackoverflow.com/questions/148901", "https://Stackoverflow.com", "https://Stackoverflow.com/users/305/" ]
I've always handled optional parameters in JavaScript like this: ``` function myFunc(requiredArg, optionalArg){ optionalArg = optionalArg || 'defaultValue'; // Do stuff } ``` Is there a better way to do it? Are there any cases where using `||` like that is going to fail?
Your logic fails if optionalArg is passed, but evaluates as false - try this as an alternative ``` if (typeof optionalArg === 'undefined') { optionalArg = 'default'; } ``` Or an alternative idiom: ``` optionalArg = (typeof optionalArg === 'undefined') ? 'default' : optionalArg; ``` Use whichever idiom communicate...
148,902
<p>I have some commits that I've decided, after the fact, are going to be more branch work then trunk work. How do I create the branch and revert the trunk while still ensuring merging isn't painful later?</p> <p>Is it as simple as copying the current trunk to a branch and reverting the trunk? Or will this create head...
[ { "answer_id": 148922, "author": "Sam Hasler", "author_id": 2541, "author_profile": "https://Stackoverflow.com/users/2541", "pm_score": 2, "selected": false, "text": "<p>There's nothing wrong with following Philip's method, other than it leaves some \"cruft\" in the revision history. If ...
2008/09/29
[ "https://Stackoverflow.com/questions/148902", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1946/" ]
I have some commits that I've decided, after the fact, are going to be more branch work then trunk work. How do I create the branch and revert the trunk while still ensuring merging isn't painful later? Is it as simple as copying the current trunk to a branch and reverting the trunk? Or will this create headaches late...
I think Philips method would be something like the following, assuming the last "good" revision was at 100 and you are now at 130, to create the new branch: ``` svn copy -r100 svn://repos/trunk svn://repos/branches/newbranch svn merge -r 100:130 svn://repos/trunk svn://repos/branches/newbranch ``` Note the idea is t...
148,945
<p>We let users create ad-hoc queries in our website. We would like to have the user select their criteria, then click submit and have the results streamed automatically to Excel. I have the application populating a DataTable, then using the datatable to create a tab delimited string. The problem is getting that to ...
[ { "answer_id": 148962, "author": "Stephen Wrighton", "author_id": 7516, "author_profile": "https://Stackoverflow.com/users/7516", "pm_score": 4, "selected": true, "text": "<p>Change the page's file type to excel, and only stream the HTML necessary to build a table to the page. code from ...
2008/09/29
[ "https://Stackoverflow.com/questions/148945", "https://Stackoverflow.com", "https://Stackoverflow.com/users/681/" ]
We let users create ad-hoc queries in our website. We would like to have the user select their criteria, then click submit and have the results streamed automatically to Excel. I have the application populating a DataTable, then using the datatable to create a tab delimited string. The problem is getting that to excel....
Change the page's file type to excel, and only stream the HTML necessary to build a table to the page. code from [here](http://www.eggheadcafe.com/tutorials/aspnet/6e1ae1a8-8285-4b2a-a89b-fafc7668a782/aspnet-download-as-wor.aspx) ``` //for demo purpose, lets create a small datatable & populate it with dummy data Syst...