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
400,655
<p>What exactly is a "Format String Vulnerability" in a Windows System, how does it work, and how can I protect against it?</p>
[ { "answer_id": 400722, "author": "some", "author_id": 36866, "author_profile": "https://Stackoverflow.com/users/36866", "pm_score": 2, "selected": false, "text": "<p>In this pseudo code the user enters some characters to be printed, like \"hello\"</p>\n\n<pre><code>string s=getUserInput(...
2008/12/30
[ "https://Stackoverflow.com/questions/400655", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50216/" ]
What exactly is a "Format String Vulnerability" in a Windows System, how does it work, and how can I protect against it?
In this pseudo code the user enters some characters to be printed, like "hello" ``` string s=getUserInput(); write(s) ``` That works as intended. But since the write can format strings, for example ``` int i=getUnits(); write("%02d units",i); ``` outputs: "03 units". What about if the user in the first place wrot...
400,666
<p>I using SiteMapPath with an xml file for data. I would like to use the same file for another menu, but I need to have more information attached to each node.</p> <pre><code>&lt;siteMapNode target="_blank" url="~/Default.aspx" title="Home" description="Home Page" &gt; VS &lt;siteMapNode url="~/Default.aspx" title="...
[ { "answer_id": 400754, "author": "Todd Smith", "author_id": 31624, "author_profile": "https://Stackoverflow.com/users/31624", "pm_score": 2, "selected": true, "text": "<p>Doubtfull you'll run into any problems. Whatever is consuming your sitemap file is only going to parse known attribut...
2008/12/30
[ "https://Stackoverflow.com/questions/400666", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50018/" ]
I using SiteMapPath with an xml file for data. I would like to use the same file for another menu, but I need to have more information attached to each node. ``` <siteMapNode target="_blank" url="~/Default.aspx" title="Home" description="Home Page" > VS <siteMapNode url="~/Default.aspx" title="Home" description="Hom...
Doubtfull you'll run into any problems. Whatever is consuming your sitemap file is only going to parse known attributes. Extra attributes will go ignored.
400,691
<p>I'm struggling to create an OU for Active Directory using the code below.</p> <pre><code>strPath = "OU=TestOU,DC=Internal,DC=Com" DirectoryEntry objOU; objOU = ADentry.Children.Add(strPath, "OrganizationalUnit"); objOU.CommitChanges(); </code></pre> <p>The problem is strPath contains the full path 'OU=TestOU,DC=...
[ { "answer_id": 400787, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 4, "selected": false, "text": "<p>try this</p>\n\n<pre><code>using System;\nusing System.DirectoryServices;\n\nnamespace ADAM_Examples\n{\n class CreateOU...
2008/12/30
[ "https://Stackoverflow.com/questions/400691", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I'm struggling to create an OU for Active Directory using the code below. ``` strPath = "OU=TestOU,DC=Internal,DC=Com" DirectoryEntry objOU; objOU = ADentry.Children.Add(strPath, "OrganizationalUnit"); objOU.CommitChanges(); ``` The problem is strPath contains the full path 'OU=TestOU,DC=Internal,DC=net' so using ...
try this ``` using System; using System.DirectoryServices; namespace ADAM_Examples { class CreateOU { /// <summary> /// Create AD LDS Organizational Unit. /// </summary> [STAThread] static void Main() { DirectoryEntry objADAM; // Binding object. ...
400,712
<p>How can I limit a result set to <em>n</em> distinct values of a given column(s), where the actual number of rows may be higher?</p> <p>Input table:</p> <pre><code>client_id, employer_id, other_value 1, 2, abc 1, 3, defg 2, 3, dkfjh 3, 1, ldkfjkj 4, 4, dlkfjk 4, 5, 342 4, 6, dkj 5, 1, dlkfj 6, 1, 34kjf 7, 7, 34kjf ...
[ { "answer_id": 400721, "author": "Vinko Vrsalovic", "author_id": 5190, "author_profile": "https://Stackoverflow.com/users/5190", "pm_score": 5, "selected": true, "text": "<p>You can use a subselect</p>\n\n<pre><code>select * from table where client_id in \n(select distinct client_id from...
2008/12/30
[ "https://Stackoverflow.com/questions/400712", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41613/" ]
How can I limit a result set to *n* distinct values of a given column(s), where the actual number of rows may be higher? Input table: ``` client_id, employer_id, other_value 1, 2, abc 1, 3, defg 2, 3, dkfjh 3, 1, ldkfjkj 4, 4, dlkfjk 4, 5, 342 4, 6, dkj 5, 1, dlkfj 6, 1, 34kjf 7, 7, 34kjf 8, 6, lkjkj 8, 7, 23kj ``` ...
You can use a subselect ``` select * from table where client_id in (select distinct client_id from table order by client_id limit 5) ```
400,728
<p>I'm working with a jQuery dialog that contains a form. In ie6, there are a couple unexplained inches of padding above the form. When I eliminate the form from the markup, the most serious layout problems go away. I've tried it with no theme (default), Flora, and my themeroller theme and they all seem to have the sam...
[ { "answer_id": 402551, "author": "Soviut", "author_id": 46914, "author_profile": "https://Stackoverflow.com/users/46914", "pm_score": 3, "selected": true, "text": "<p>Whenever I have to create a CSS theme for an existing site, forum, widget, etc. I always start by stripping out all the s...
2008/12/30
[ "https://Stackoverflow.com/questions/400728", "https://Stackoverflow.com", "https://Stackoverflow.com/users/47096/" ]
I'm working with a jQuery dialog that contains a form. In ie6, there are a couple unexplained inches of padding above the form. When I eliminate the form from the markup, the most serious layout problems go away. I've tried it with no theme (default), Flora, and my themeroller theme and they all seem to have the same p...
Whenever I have to create a CSS theme for an existing site, forum, widget, etc. I always start by stripping out all the stylesheets and normalizing all my margins and padding to 0 for every major html DOM element. This is especially important when it comes to inline css. What you should try is removing any inline CSS ...
400,732
<p>How do you determine the length of a string of text in Arial Bold font, and then center it in VB6?</p> <p>We are not using a "label" or "picture box" to print the text to the screen. We are sizing the text on the fly, and allowing the user to scale the size of our application to their liking. We write the text to s...
[ { "answer_id": 400760, "author": "Neil Barnwell", "author_id": 26414, "author_profile": "https://Stackoverflow.com/users/26414", "pm_score": 1, "selected": false, "text": "<p>I can't remember the specifics (it's been about 3 years since I last used VB 6), but there's a method on Form cal...
2008/12/30
[ "https://Stackoverflow.com/questions/400732", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40091/" ]
How do you determine the length of a string of text in Arial Bold font, and then center it in VB6? We are not using a "label" or "picture box" to print the text to the screen. We are sizing the text on the fly, and allowing the user to scale the size of our application to their liking. We write the text to screen usin...
One way is to have a hidden picture box and setup the font specs of that picture box the way you want. Then use the TextHeight and TextWidth methods of the PictureBox to take your measurements. The Units will be in whatever scalemode the Picture Box is set to. If you are printing directly to the printer or form the...
400,733
<p>I want to get the ASCII value of characters in a string in C#.</p> <p>If my string has the value "9quali52ty3", I want an array with the ASCII values of each of the 11 characters.</p> <p>How can I get ASCII values in C#?</p>
[ { "answer_id": 400738, "author": "LeppyR64", "author_id": 16592, "author_profile": "https://Stackoverflow.com/users/16592", "pm_score": 6, "selected": false, "text": "<pre><code>string s = \"9quali52ty3\";\nforeach(char c in s)\n{\n Console.WriteLine((int)c);\n}\n</code></pre>\n" }, ...
2008/12/30
[ "https://Stackoverflow.com/questions/400733", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14299/" ]
I want to get the ASCII value of characters in a string in C#. If my string has the value "9quali52ty3", I want an array with the ASCII values of each of the 11 characters. How can I get ASCII values in C#?
From [MSDN](http://msdn.microsoft.com/en-us/library/system.text.encoding.convert(VS.71).aspx) ``` string value = "9quali52ty3"; // Convert the string into a byte[]. byte[] asciiBytes = Encoding.ASCII.GetBytes(value); ``` You now have an array of the ASCII value of the bytes. I got the following: 57 113 117 97 108 ...
400,739
<p>Does * have a special meaning in Python as it does in C? I saw a function like this in the Python Cookbook:</p> <pre><code>def get(self, *a, **kw) </code></pre> <p>Would you please explain it to me or point out where I can find an answer (Google interprets the * as wild card character and thus I cannot find a sati...
[ { "answer_id": 400753, "author": "S.Lott", "author_id": 10661, "author_profile": "https://Stackoverflow.com/users/10661", "pm_score": 9, "selected": true, "text": "<p>See <a href=\"https://docs.python.org/2.7/reference/compound_stmts.html#function-definitions\" rel=\"noreferrer\">Functio...
2008/12/30
[ "https://Stackoverflow.com/questions/400739", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8203/" ]
Does \* have a special meaning in Python as it does in C? I saw a function like this in the Python Cookbook: ``` def get(self, *a, **kw) ``` Would you please explain it to me or point out where I can find an answer (Google interprets the \* as wild card character and thus I cannot find a satisfactory answer).
See [Function Definitions](https://docs.python.org/2.7/reference/compound_stmts.html#function-definitions) in the Language Reference. > > If the form `*identifier` is > present, it is initialized to a tuple > receiving any excess positional > parameters, defaulting to the empty > tuple. If the form `**identifier`...
400,759
<p>Is there an easy way to do a <code>GROUP BY DATE(timestamp)</code> that includes all days in a period of time, regardless of whether there are any records associated with that date?</p> <p>Basically, I need to generate a report like this:</p> <pre><code>24 Dec - 0 orders 23 Dec - 10 orders 22 Dec - 8 orders 21 Dec...
[ { "answer_id": 400770, "author": "LeppyR64", "author_id": 16592, "author_profile": "https://Stackoverflow.com/users/16592", "pm_score": 2, "selected": false, "text": "<p>One method is to create a calendar table and join against it.</p>\n\n<p>I would create it permanently, and then create...
2008/12/30
[ "https://Stackoverflow.com/questions/400759", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1902010/" ]
Is there an easy way to do a `GROUP BY DATE(timestamp)` that includes all days in a period of time, regardless of whether there are any records associated with that date? Basically, I need to generate a report like this: ``` 24 Dec - 0 orders 23 Dec - 10 orders 22 Dec - 8 orders 21 Dec - 2 orders 20 Dec - 0 orders `...
Instead of using GROUP BY, make a table (perhaps a temporary table) which contains the specific dates you want, for example: ``` 24 Dec 23 Dec 22 Dec 21 Dec 20 Dec ``` Then, join that table to the Orders table.
400,772
<p>I want to improve integration tests methods where I work and I would like to know how this process happens in other places.<br> Things like:<br> - When test plans writing begin<br> - Proportion between testers, developers and stuff (entire applications or modifications) to be tested<br> - What kind of methods are...
[ { "answer_id": 400770, "author": "LeppyR64", "author_id": 16592, "author_profile": "https://Stackoverflow.com/users/16592", "pm_score": 2, "selected": false, "text": "<p>One method is to create a calendar table and join against it.</p>\n\n<p>I would create it permanently, and then create...
2008/12/30
[ "https://Stackoverflow.com/questions/400772", "https://Stackoverflow.com", "https://Stackoverflow.com/users/37650/" ]
I want to improve integration tests methods where I work and I would like to know how this process happens in other places. Things like: - When test plans writing begin - Proportion between testers, developers and stuff (entire applications or modifications) to be tested - What kind of methods are used f...
Instead of using GROUP BY, make a table (perhaps a temporary table) which contains the specific dates you want, for example: ``` 24 Dec 23 Dec 22 Dec 21 Dec 20 Dec ``` Then, join that table to the Orders table.
400,778
<p>I'm trying to create a UserControl that inherits from a generic class. It does not directly inherit from a generic class, but through an intermediate class that does not use generics. This compiles and works at runtime, but I get an error at design time.</p> <p>Here's my generic parent class:</p> <pre><code>Publ...
[ { "answer_id": 400795, "author": "AnthonyWJones", "author_id": 17516, "author_profile": "https://Stackoverflow.com/users/17516", "pm_score": 0, "selected": false, "text": "<p>Despite being at 2.0 silverlight (and especially the VS2008 tweaks for silverlight) are still very young. There ...
2008/12/30
[ "https://Stackoverflow.com/questions/400778", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16625/" ]
I'm trying to create a UserControl that inherits from a generic class. It does not directly inherit from a generic class, but through an intermediate class that does not use generics. This compiles and works at runtime, but I get an error at design time. Here's my generic parent class: ``` Public Class GenericParent(...
We've received word from Microsoft that this is not likely to be fixed in future versions. After they bounced the problem around trying to find the responsible group, it appears that this problem belongs to their WPF developer group, which is where the 'not going to fix it' answer came from. In the meantime, we've upd...
400,788
<p>I need to resize jpg images with Python without losing the original image's EXIF data (metadata about date taken, camera model etc.). All google searches about python and images point to the PIL library which I'm currently using, but doesn't seem to be able to retain the metadata. The code I have so far (using PIL) ...
[ { "answer_id": 400838, "author": "jfs", "author_id": 4279, "author_profile": "https://Stackoverflow.com/users/4279", "pm_score": 5, "selected": true, "text": "<pre><code>import jpeg\njpeg.setExif(jpeg.getExif('foo.jpg'), 'foo-resized.jpg') \n</code></pre>\n\n<p><a href=\"http://www.emila...
2008/12/30
[ "https://Stackoverflow.com/questions/400788", "https://Stackoverflow.com", "https://Stackoverflow.com/users/35716/" ]
I need to resize jpg images with Python without losing the original image's EXIF data (metadata about date taken, camera model etc.). All google searches about python and images point to the PIL library which I'm currently using, but doesn't seem to be able to retain the metadata. The code I have so far (using PIL) is ...
``` import jpeg jpeg.setExif(jpeg.getExif('foo.jpg'), 'foo-resized.jpg') ``` <http://www.emilas.com/jpeg/>
400,799
<p>I'm having a major issue trying to configure a new install of BizTalk Server 2006 (not R2). The server had BizTalk installed on it before, and it was working fine. I've uninstalled BizTalk, removed the databases and jobs from the SQL server, which is a separate machine, and re-installed BizTalk. The install was s...
[ { "answer_id": 400846, "author": "Perpetualcoder", "author_id": 37494, "author_profile": "https://Stackoverflow.com/users/37494", "pm_score": 6, "selected": true, "text": "<p>All your needs will be satisfied in the following articles from MSDN:</p>\n\n<p><a href=\"http://msdn.microsoft.c...
2008/12/30
[ "https://Stackoverflow.com/questions/400799", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16683/" ]
I'm having a major issue trying to configure a new install of BizTalk Server 2006 (not R2). The server had BizTalk installed on it before, and it was working fine. I've uninstalled BizTalk, removed the databases and jobs from the SQL server, which is a separate machine, and re-installed BizTalk. The install was success...
All your needs will be satisfied in the following articles from MSDN: [Implementing an Async Service Operation](http://msdn.microsoft.com/en-us/library/ms731177.aspx) [Calling WCF Service Async](http://msdn.microsoft.com/en-us/library/ms730059.aspx) [Designing Service Contracts](http://msdn.microsoft.com/en-us/libra...
400,819
<p>I would like to call a sql statement such as:</p> <pre><code>Select * From Table Where Column in ('value1', 'value2', 'value3') </code></pre> <p>Is it as simple as setting a command parameter's value equal to "<code>('value1', 'value2', 'value3')</code>"?</p>
[ { "answer_id": 400831, "author": "JoshBerke", "author_id": 26160, "author_profile": "https://Stackoverflow.com/users/26160", "pm_score": 0, "selected": false, "text": "<p>if you only have three parameters for the in clause then yes you can use the parameters. Otherwise you can build dyna...
2008/12/30
[ "https://Stackoverflow.com/questions/400819", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9150/" ]
I would like to call a sql statement such as: ``` Select * From Table Where Column in ('value1', 'value2', 'value3') ``` Is it as simple as setting a command parameter's value equal to "`('value1', 'value2', 'value3')`"?
@Charles: You're going into the right direction, but we're using parametrized queries to mainly prevent SQL injections. Putting 'external' values (`params string[] args`) hardcoded in queries is asking for trouble. You can iterate the arguments, but you still have to use parameters like this: ``` string[] values = ...
400,822
<p>I've got some shell stuff set up that dynamically defines aliases depending on what sort of VC repo the CWD contains -- so, for example, 'd' runs 'svn diff' or 'git diff', depending. (Based on <a href="http://muness.blogspot.com/2008/06/stop-presses-bash-said-to-embrace.html" rel="nofollow noreferrer">this blog post...
[ { "answer_id": 400932, "author": "codelogic", "author_id": 43427, "author_profile": "https://Stackoverflow.com/users/43427", "pm_score": 3, "selected": false, "text": "<p>You can probably use the output of the <code>git config</code> command to differentiate between a git and git-svn rep...
2008/12/30
[ "https://Stackoverflow.com/questions/400822", "https://Stackoverflow.com", "https://Stackoverflow.com/users/39933/" ]
I've got some shell stuff set up that dynamically defines aliases depending on what sort of VC repo the CWD contains -- so, for example, 'd' runs 'svn diff' or 'git diff', depending. (Based on [this blog post](http://muness.blogspot.com/2008/06/stop-presses-bash-said-to-embrace.html), if anybody is interested...) I'd ...
You should be a bit careful when deciding which repositories exactly are git-svn repositories. A repository may contain more than one svn repository. Kafka's solution will only work if the svn repository was cloned with the -s or --std-layout option, in which there actually *is* a branch `trunk`. Codelogic's answer w...
400,834
<p>I am loading a Microsoft CRM 4.0 window from an Intranet page using window.open(...).</p> <p>When the window closes, I need it to programmatically press a button on the page that opened it. I can do this from my own form by getting the button (whose name is passed in the querystring) and executing its click method ...
[ { "answer_id": 402666, "author": "user39603", "author_id": 39603, "author_profile": "https://Stackoverflow.com/users/39603", "pm_score": 0, "selected": false, "text": "<p>Aren't the errors caused by cross-site-scripting prevention? Unless the intranet app and CRM reside on the same serve...
2008/12/30
[ "https://Stackoverflow.com/questions/400834", "https://Stackoverflow.com", "https://Stackoverflow.com/users/44938/" ]
I am loading a Microsoft CRM 4.0 window from an Intranet page using window.open(...). When the window closes, I need it to programmatically press a button on the page that opened it. I can do this from my own form by getting the button (whose name is passed in the querystring) and executing its click method in JavaScr...
You could do something like use a basic javascript window.opener call. Page 1 opens a CRM window. In the OnSave of that CRM window you call something like this: ``` if(window.opener.DoSomeFunction != null) { window.opener.DoSomeFunction; } ``` Where DoSomeFunction() is a defined javascript function in Page...
400,849
<p>Say I have two script controls and one control has the other as a child control:</p> <pre><code>ParentControl : ScriptControl { ChildControl childControl; } </code></pre> <p>The script for the Child Control:</p> <pre><code>ChildControl = function(element) { ChildControl.initializeBase(this, [element]); } C...
[ { "answer_id": 401429, "author": "Robert C. Barth", "author_id": 9209, "author_profile": "https://Stackoverflow.com/users/9209", "pm_score": 1, "selected": false, "text": "<p>The problem is the \"this.\" This, in javaScript, refers to the DOM object. You need to do something similar to w...
2008/12/30
[ "https://Stackoverflow.com/questions/400849", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21691/" ]
Say I have two script controls and one control has the other as a child control: ``` ParentControl : ScriptControl { ChildControl childControl; } ``` The script for the Child Control: ``` ChildControl = function(element) { ChildControl.initializeBase(this, [element]); } ChildControl.prototype = { callMet...
On the client, you're using a field of your parent control object called \_childControlID by passing it into $get. There's a few problems with this: 1. How did \_childControlID get set? I would guess by adding it as a property in the parent control's descriptor on the server, but you don't show that code and you don't...
400,861
<p>I have to write a program that read from a file that contains the folowing:</p> <pre><code>toto, M, 50 fifi, F, 60 soso, F, 70 lolo, M, 60 fifi, F, 60 </code></pre> <hr /> <p>And then find the following:</p> <p>Which mark is most repeated, and how many times is it repeated?</p> <ul> <li>average all students</li> <li...
[ { "answer_id": 400871, "author": "Gant", "author_id": 12460, "author_profile": "https://Stackoverflow.com/users/12460", "pm_score": 3, "selected": true, "text": "<p>I haven't test it. But you should call <code>SW.close()</code> after finished writing stuffs.</p>\n" }, { "answer_i...
2008/12/30
[ "https://Stackoverflow.com/questions/400861", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have to write a program that read from a file that contains the folowing: ``` toto, M, 50 fifi, F, 60 soso, F, 70 lolo, M, 60 fifi, F, 60 ``` --- And then find the following: Which mark is most repeated, and how many times is it repeated? * average all students * average all male * average all female How many ...
I haven't test it. But you should call `SW.close()` after finished writing stuffs.
400,862
<p>i need to see the <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.control.clientrectangle.aspx" rel="noreferrer">ClientRectangle</a> of a form as i'm designing it. This particular property is tagged as &quot;<a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.editorbrowsables...
[ { "answer_id": 401000, "author": "w4g3n3r", "author_id": 36745, "author_profile": "https://Stackoverflow.com/users/36745", "pm_score": 0, "selected": false, "text": "<p>The answer is in the <a href=\"http://msdn.microsoft.com/en-us/library/system.componentmodel.editorbrowsableattribute.a...
2008/12/30
[ "https://Stackoverflow.com/questions/400862", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12597/" ]
i need to see the [ClientRectangle](http://msdn.microsoft.com/en-us/library/system.windows.forms.control.clientrectangle.aspx) of a form as i'm designing it. This particular property is tagged as "[Advanced](http://msdn.microsoft.com/en-us/library/system.componentmodel.editorbrowsablestate.aspx)", and by default is hid...
Hans Passant's answer at [Finding and using hidden properties(such as DisplayRectangle)](https://stackoverflow.com/questions/3708771/finding-and-using-hidden-propertiessuch-as-displayrectangle/3708900#3708900) cleared this for me: it can't be done. The EditorBrowsable is only for the TEXT editor, and the attribute that...
400,872
<p>I'm using the following code on Windows Vista Ultimate SP1 to query our active directory server to check the user name and password of a user on a domain.</p> <pre><code>public Object IsAuthenticated() { String domainAndUsername = strDomain + "\\" + strUser; DirectoryEntry entry = new DirectoryEntry(_path, ...
[ { "answer_id": 400917, "author": "Steven Robbins", "author_id": 26507, "author_profile": "https://Stackoverflow.com/users/26507", "pm_score": 0, "selected": false, "text": "<p>Does binding to LDAP require elevated privs (UAC)? You could try running Visual Studio and/or the app as Admini...
2008/12/30
[ "https://Stackoverflow.com/questions/400872", "https://Stackoverflow.com", "https://Stackoverflow.com/users/33082/" ]
I'm using the following code on Windows Vista Ultimate SP1 to query our active directory server to check the user name and password of a user on a domain. ``` public Object IsAuthenticated() { String domainAndUsername = strDomain + "\\" + strUser; DirectoryEntry entry = new DirectoryEntry(_path, domainAndUsern...
If you're using .net 3.5 use this code instead. To authenticate a user: ``` PrincipalContext adContext = new PrincipalContext(ContextType.Domain); using (adContext) { return adContext.ValidateCredentials(UserName, Password); } ``` If you need to find the user to R/W attributes to the object do this: ``` Prin...
400,881
<p>When using the latest Microsoft jdbc driver for SQL Server 2005/2008 how do prepared statements, views, and stored procedures compare regarding performance? </p> <p>If I have a plain old select statement with some dynamic where clauses will I see benefits from moving from straight SQL in a prepared statement to a v...
[ { "answer_id": 400889, "author": "duffymo", "author_id": 37213, "author_profile": "https://Stackoverflow.com/users/37213", "pm_score": 0, "selected": false, "text": "<p>depends on the sql and your application. i don't believe there's a blanket answer, and it probably doesn't depend on t...
2008/12/30
[ "https://Stackoverflow.com/questions/400881", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5885/" ]
When using the latest Microsoft jdbc driver for SQL Server 2005/2008 how do prepared statements, views, and stored procedures compare regarding performance? If I have a plain old select statement with some dynamic where clauses will I see benefits from moving from straight SQL in a prepared statement to a view or eve...
You are not likely to see a significant performance difference due to the cached execution plans for SPs, as execution plans are also cached in SQL Server 2005 and up even for ad hoc SQL. In the case where parameter sniffing can adversely affect performance due to erroneous cardinality estimates for certain values of ...
400,895
<p>A simple expression like</p> <pre><code>(x) - y </code></pre> <p>is interpreted differently depending on whether <code>x</code> is a type name or not. If <code>x</code> is not a type name, <code>(x) - y</code> just subtracts <code>y</code> from <code>x</code>. But if <code>x</code> is a type name, <code>(x) - y</c...
[ { "answer_id": 400934, "author": "Michael Myers", "author_id": 13531, "author_profile": "https://Stackoverflow.com/users/13531", "pm_score": 2, "selected": false, "text": "<p>I just tested it out, and this code:</p>\n\n<pre><code>Double y = new Double(0.1);\nSystem.out.println((Double)-y...
2008/12/30
[ "https://Stackoverflow.com/questions/400895", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19725/" ]
A simple expression like ``` (x) - y ``` is interpreted differently depending on whether `x` is a type name or not. If `x` is not a type name, `(x) - y` just subtracts `y` from `x`. But if `x` is a type name, `(x) - y` computes the negative of `y` and casts the resulting value to type `x`. In a typical C or C++ com...
I think I've found the solution that satisfies me. Thanks to mmyers, I realized that I needed to check the formal spec of the syntax for type casts. The ambiguity is caused by `+` and `-` being both unary and binary operators. Java solves the problem by this grammar: ``` CastExpression: ( PrimitiveType Dimsop...
400,900
<p>I'm trying to deserialize an array of an type unknown at compile time. At runtime I've discovered the type, but I don't know how to create an instance.</p> <p>Something like:</p> <pre><code>Object o = Activator.CreateInstance(type); </code></pre> <p>which doesn't work because there is no parameterless constructor...
[ { "answer_id": 400908, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 7, "selected": true, "text": "<p>Use <a href=\"http://msdn.microsoft.com/en-us/library/system.array.createinstance.aspx\" rel=\"noreferrer\">Array.Crea...
2008/12/30
[ "https://Stackoverflow.com/questions/400900", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16260/" ]
I'm trying to deserialize an array of an type unknown at compile time. At runtime I've discovered the type, but I don't know how to create an instance. Something like: ``` Object o = Activator.CreateInstance(type); ``` which doesn't work because there is no parameterless constructor, Array doesn't seem to have any ...
Use [Array.CreateInstance](http://msdn.microsoft.com/en-us/library/system.array.createinstance.aspx).
400,909
<p>I need to be able to check what the "current" value of a variable is inside a redeclaration of that same variable in a different xslt that includes the other.</p> <p>main.xslt:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transfo...
[ { "answer_id": 400925, "author": "annakata", "author_id": 13018, "author_profile": "https://Stackoverflow.com/users/13018", "pm_score": 0, "selected": false, "text": "<p>You can't do what you want directly, you'd have to set a second variable. </p>\n\n<p>But I can't understand the intent...
2008/12/30
[ "https://Stackoverflow.com/questions/400909", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34211/" ]
I need to be able to check what the "current" value of a variable is inside a redeclaration of that same variable in a different xslt that includes the other. main.xslt: ``` <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:import href="oth...
**As others have noted, adding a default to a global variable that is defined in an imported stylesheet, cannot be done using the same variable name**. This is because the variable with that name that is defined in the current xslt stylesheet has higher precedence than the one in the imported stylesheet and only the fo...
400,916
<p>Is there any way to check if a particular plugin is available?</p> <p>Imagine that you are developing a plugin that depends on another plugin being loaded.</p> <p>For example I want the jQuery Validation plugin to use the dateJS library to check if a given date is valid. What would be the best way to detect, in th...
[ { "answer_id": 400940, "author": "ceejayoz", "author_id": 1902010, "author_profile": "https://Stackoverflow.com/users/1902010", "pm_score": -1, "selected": false, "text": "<p>This sort of approach should work.</p>\n\n<pre><code>var plugin_exists = true;\n\ntry {\n // some code that requ...
2008/12/30
[ "https://Stackoverflow.com/questions/400916", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1842864/" ]
Is there any way to check if a particular plugin is available? Imagine that you are developing a plugin that depends on another plugin being loaded. For example I want the jQuery Validation plugin to use the dateJS library to check if a given date is valid. What would be the best way to detect, in the jQuery Valdatio...
Generally speaking, jQuery plugins are namespaces on the jQuery scope. You could run a simple check to see if the namespace exists: ``` if(jQuery().pluginName) { //run plugin dependent code } ``` dateJs however is not a jQuery plugin. It modifies/extends the javascript date object, and is not added as a jQuer...
400,935
<p>I have several web pages on several different sites that I want to mirror completely. This means that I will need images, CSS, etc, and the links need to be converted. This functionality would be similar to using Firefox to "Save Page As" and selecting "Web Page, complete". I'd like to name the files and correspo...
[ { "answer_id": 400947, "author": "Bobby Borszich", "author_id": 35585, "author_profile": "https://Stackoverflow.com/users/35585", "pm_score": 0, "selected": false, "text": "<p>In most modern websites the front end only tells a small part of the story. Regardless of tools for stripping ht...
2008/12/30
[ "https://Stackoverflow.com/questions/400935", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have several web pages on several different sites that I want to mirror completely. This means that I will need images, CSS, etc, and the links need to be converted. This functionality would be similar to using Firefox to "Save Page As" and selecting "Web Page, complete". I'd like to name the files and corresponding ...
If your just looking to run a command and get a copy of a web site, use the tools that others have suggested, such as [wget](http://www.gnu.org/software/wget/), [curl](http://curl.haxx.se/), or some of the GUI tools. I use my own personal tool that I call [webreaper](http://search.cpan.org/~bdfoy/webreaper-0.31/) (that...
400,941
<p>I have written a VBA app that opens a folder in outlook and then iterates through the messages. I need to write the message bodies (with some tweaking) to a single flat file. My code is as follows...</p> <pre><code>Private Sub btnGo_Click() Dim objOutlook As New Outlook.Application Dim objNameSpace As Out...
[ { "answer_id": 400999, "author": "Eric Ness", "author_id": 18891, "author_profile": "https://Stackoverflow.com/users/18891", "pm_score": 2, "selected": false, "text": "<p>If you don't mind re-opening the output file each time you append some text, then this should work.</p>\n\n<pre><code...
2008/12/30
[ "https://Stackoverflow.com/questions/400941", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2894/" ]
I have written a VBA app that opens a folder in outlook and then iterates through the messages. I need to write the message bodies (with some tweaking) to a single flat file. My code is as follows... ``` Private Sub btnGo_Click() Dim objOutlook As New Outlook.Application Dim objNameSpace As Outlook.NameSpace ...
You can get away with writing to a file without using any objects, just using the built in VBA file tools: ``` Open "C:\file.txt" for append as 1 Print #1, SomeStringVar Close #1 ```
400,945
<p>First off, let’s agree that namespace should match folder structure and that each language artefact should be in its own file. </p> <p>(see <a href="https://stackoverflow.com/questions/4664/should-the-folders-in-a-solution-match-the-namespace">Should the folders in a solution match the namespace?</a> ). </p> <p>...
[ { "answer_id": 400963, "author": "duffymo", "author_id": 37213, "author_profile": "https://Stackoverflow.com/users/37213", "pm_score": 2, "selected": false, "text": "<p>\"First off, let’s agree that namespace should match folder structure and that each language artifact [sic] should be i...
2008/12/30
[ "https://Stackoverflow.com/questions/400945", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50241/" ]
First off, let’s agree that namespace should match folder structure and that each language artefact should be in its own file. (see [Should the folders in a solution match the namespace?](https://stackoverflow.com/questions/4664/should-the-folders-in-a-solution-match-the-namespace) ). The next question is how the f...
I'm not a big fan of nested projects, since it buries projects deep inside a structure and if you need to reuse that project in another application then what do you do, copy/paste the code? I like to follow somewhat of a flat structure but organized by namespace. This is how I do it: ``` - DataHelpers\ ---Factory\ -...
400,951
<p>Almost all languages have a <a href="https://en.wikipedia.org/wiki/Foreach_loop" rel="noreferrer"><code>foreach</code> loop</a> or something similar. Does C have one? Can you post some example code?</p>
[ { "answer_id": 400958, "author": "Adam Peck", "author_id": 26658, "author_profile": "https://Stackoverflow.com/users/26658", "pm_score": 3, "selected": false, "text": "<p>There is no foreach in C.</p>\n\n<p>You can use a for loop to loop through the data but the length needs to be know o...
2008/12/30
[ "https://Stackoverflow.com/questions/400951", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50216/" ]
Almost all languages have a [`foreach` loop](https://en.wikipedia.org/wiki/Foreach_loop) or something similar. Does C have one? Can you post some example code?
C doesn't have a foreach, but macros are frequently used to emulate that: ``` #define for_each_item(item, list) \ for(T * item = list->head; item != NULL; item = item->next) ``` And can be used like ``` for_each_item(i, processes) { i->wakeup(); } ``` Iteration over an array is also possible: ``` #define...
400,965
<p>I would like to customize both the background and the border color of a grouped-style UITableView.</p> <p>I was able to customize the background color by using the following:</p> <pre><code>tableView.contentView.backgroundColor = [UIColor greenColor]; </code></pre> <p>But the border color is still something I don...
[ { "answer_id": 401271, "author": "Mike Akers", "author_id": 17188, "author_profile": "https://Stackoverflow.com/users/17188", "pm_score": 8, "selected": true, "text": "<p><strong>UPDATE:</strong> In iPhone OS 3.0 and later <code>UITableViewCell</code> now has a <code>backgroundColor</cod...
2008/12/30
[ "https://Stackoverflow.com/questions/400965", "https://Stackoverflow.com", "https://Stackoverflow.com/users/35478/" ]
I would like to customize both the background and the border color of a grouped-style UITableView. I was able to customize the background color by using the following: ``` tableView.contentView.backgroundColor = [UIColor greenColor]; ``` But the border color is still something I don't know how to change. How do I ...
**UPDATE:** In iPhone OS 3.0 and later `UITableViewCell` now has a `backgroundColor` property that makes this really easy (especially in combination with the `[UIColor colorWithPatternImage:]` initializer). But I'll leave the 2.0 version of the answer here for anyone that needs it… --- It's harder than it really shou...
400,968
<p>I want all buttons to perform an action before and after their normal onclick event. So I came up with the "brilliant" idea of looping through all those elements and creating a wrapper function.</p> <p>This appeared to work pretty well when I tested it, but when I integrated it into our app, it fell apart. I trac...
[ { "answer_id": 400979, "author": "Hank Gay", "author_id": 4203, "author_profile": "https://Stackoverflow.com/users/4203", "pm_score": 1, "selected": false, "text": "<p>Your problem is the way closures work in JavaScript. Honestly, I'd recommend using a framework. Any of them should make ...
2008/12/30
[ "https://Stackoverflow.com/questions/400968", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29043/" ]
I want all buttons to perform an action before and after their normal onclick event. So I came up with the "brilliant" idea of looping through all those elements and creating a wrapper function. This appeared to work pretty well when I tested it, but when I integrated it into our app, it fell apart. I traced it down t...
Like [Paul Dixon](https://stackoverflow.com/users/6521/) said, you could use [call](http://msdn.microsoft.com/en-us/library/wt1h2e5c.aspx) but I suggest you use [apply](http://msdn.microsoft.com/en-us/library/4zc42wh1(VS.85).aspx) instead. However, the reason I am answering is that I found a disturbing bug: **You are ...
400,989
<p>Here is my issue. I have an array containing the name of cities that I need to lookup the weather for. So I'm looping through each city and performing an AJAX request to retrieve the weather.</p> <pre><code>var LOCATION = 'http://www.google.com/ig/api?weather='; $( document ).ready( function() { for( var cityI...
[ { "answer_id": 401007, "author": "Adam Peck", "author_id": 26658, "author_profile": "https://Stackoverflow.com/users/26658", "pm_score": 1, "selected": false, "text": "<p>The simplest thing to do would have your AJAX request return the name of the city.</p>\n" }, { "answer_id": 4...
2008/12/30
[ "https://Stackoverflow.com/questions/400989", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25371/" ]
Here is my issue. I have an array containing the name of cities that I need to lookup the weather for. So I'm looping through each city and performing an AJAX request to retrieve the weather. ``` var LOCATION = 'http://www.google.com/ig/api?weather='; $( document ).ready( function() { for( var cityIdx = 0; cityId...
I suspect that your problem is similar to the example at <http://ejohn.org/apps/learn/>. The index variable cityIdx is updated in the closure you create as the for loop is processed, so by the time your function on success is run cityIdx will point to the last element in the array. The solution is to use an evaluated a...
400,991
<p>In Silverlight 2 I have the following class declaration for a control:</p> <pre><code>public partial class ClassX : UserControl </code></pre> <p>I wish to replace UserControl with ClassXBase which derives from UserControl but I'm getting the reasonable error "Partial declarations of 'ClassX' must not specify diffe...
[ { "answer_id": 401137, "author": "Michael S. Scherotter", "author_id": 27306, "author_profile": "https://Stackoverflow.com/users/27306", "pm_score": 2, "selected": false, "text": "<p>The UserControl's partial class is defined by the XAML and the framework expects it to be derived from Us...
2008/12/30
[ "https://Stackoverflow.com/questions/400991", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1463/" ]
In Silverlight 2 I have the following class declaration for a control: ``` public partial class ClassX : UserControl ``` I wish to replace UserControl with ClassXBase which derives from UserControl but I'm getting the reasonable error "Partial declarations of 'ClassX' must not specify different base classes" Howeve...
If you include the namespace of your base class of UserControl, you can do it as long as you use the namespace. For example: ``` public abstract class MyBaseUserControl : UserControl { // ... } ``` Then you have to use this class in the XAML (Note the my namespace and then using the new namespace as the root of t...
400,993
<p>I've been extensively using smart pointers (boost::shared_ptr to be exact) in my projects for the last two years. I understand and appreciate their benefits and I generally like them a lot. But the more I use them, the more I miss the deterministic behavior of C++ with regarding to memory management and RAII that I ...
[ { "answer_id": 401019, "author": "Greg Rogers", "author_id": 5963, "author_profile": "https://Stackoverflow.com/users/5963", "pm_score": 1, "selected": false, "text": "<p>In your example, it would be better if the System held a <code>vector&lt;Subsystem&gt;</code> rather than a <code>vec...
2008/12/30
[ "https://Stackoverflow.com/questions/400993", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50251/" ]
I've been extensively using smart pointers (boost::shared\_ptr to be exact) in my projects for the last two years. I understand and appreciate their benefits and I generally like them a lot. But the more I use them, the more I miss the deterministic behavior of C++ with regarding to memory management and RAII that I se...
Problem Summary --------------- There are two competing concerns in this question. 1. Life-cycle management of `Subsystem`s, allowing their removal at the right time. 2. Clients of `Subsystem`s need to know that the `Subsystem` they are using is valid. Handling #1 ----------- `System` owns the `Subsystem`s and shou...
400,994
<p>What is the correct way to separate between <kbd>F1</kbd> and i.e. <kbd>CTRL</kbd>+<kbd>F1</kbd> respective <kbd>SHIFT</kbd>-<kbd>CTRL</kbd>+<kbd>F1</kbd> within an KeyListener registered behind i.e. a JButton?</p> <pre><code>public void keyPressed(KeyEvent event) { int key = event.getKeyCode(); logger.deb...
[ { "answer_id": 401013, "author": "Midhat", "author_id": 9425, "author_profile": "https://Stackoverflow.com/users/9425", "pm_score": 3, "selected": true, "text": "<p>The Solution lies in the parent of KeyEvent (InputEvent)</p>\n\n<ol>\n<li>Use the isAltDown,isControlDown,isShiftDown metho...
2008/12/30
[ "https://Stackoverflow.com/questions/400994", "https://Stackoverflow.com", "https://Stackoverflow.com/users/33429/" ]
What is the correct way to separate between `F1` and i.e. `CTRL`+`F1` respective `SHIFT`-`CTRL`+`F1` within an KeyListener registered behind i.e. a JButton? ``` public void keyPressed(KeyEvent event) { int key = event.getKeyCode(); logger.debug("KeyBoard pressed char(" + event.getKeyChar() + ") code (" + key ...
The Solution lies in the parent of KeyEvent (InputEvent) 1. Use the isAltDown,isControlDown,isShiftDown methods or 2. Use the getModifiers method
400,997
<p>Trying to redirect a URL on one webserver on my LAN to another webserver on my LAN. I assumed that all I needed was a .htaccess file in my /var/www directory whose contents are the following 3 lines only:</p> <p>Options +FollowSymLinks</p> <p>RewriteEngine on</p> <p>RewriteMatch newsite\.level2\.level1\.com <a hr...
[ { "answer_id": 402271, "author": "genehack", "author_id": 39933, "author_profile": "https://Stackoverflow.com/users/39933", "pm_score": 1, "selected": false, "text": "<p>Rewrite rules apply against the path part of the URL, not the host part. You control the host part of the matching by ...
2008/12/30
[ "https://Stackoverflow.com/questions/400997", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Trying to redirect a URL on one webserver on my LAN to another webserver on my LAN. I assumed that all I needed was a .htaccess file in my /var/www directory whose contents are the following 3 lines only: Options +FollowSymLinks RewriteEngine on RewriteMatch newsite\.level2\.level1\.com <http://192.168.0.250:8080> ...
Rewrite rules apply against the path part of the URL, not the host part. You control the host part of the matching by putting the rewrite rules inside appropriate `<VirtualHost>` containers. You can redirect to another host, but the rule you've got is never going to match. If you want to redirect all requests, try so...
401,025
<p>Assume I have a form</p> <pre><code>class SampleClass(forms.Form): name = forms.CharField(max_length=30) age = forms.IntegerField() django_hacker = forms.BooleanField(required=False) </code></pre> <p>Is there a way for me to define css classes on each field such that I can then use jQuery based on clas...
[ { "answer_id": 401030, "author": "ashchristopher", "author_id": 22306, "author_profile": "https://Stackoverflow.com/users/22306", "pm_score": 8, "selected": true, "text": "<p>Answered my own question. <em>Sigh</em></p>\n\n<p><a href=\"http://docs.djangoproject.com/en/dev/ref/forms/widget...
2008/12/30
[ "https://Stackoverflow.com/questions/401025", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22306/" ]
Assume I have a form ``` class SampleClass(forms.Form): name = forms.CharField(max_length=30) age = forms.IntegerField() django_hacker = forms.BooleanField(required=False) ``` Is there a way for me to define css classes on each field such that I can then use jQuery based on class in my rendered page? I ...
Answered my own question. *Sigh* <http://docs.djangoproject.com/en/dev/ref/forms/widgets/#django.forms.Widget.attrs> I didn't realize it was passed into the widget constructor.
401,056
<p>Preface: I have jQuery and jQuery UI included on a page.</p> <p>I have this function defined:</p> <pre><code> function swap(sel) { if (1 == 1) { $(sel).hide('drop',{direction:'left'}); } } </code></pre> <p>How do I fix the (1 == 1) part to test to see if the element is already hi...
[ { "answer_id": 401063, "author": "Christian C. Salvadó", "author_id": 5445, "author_profile": "https://Stackoverflow.com/users/5445", "pm_score": 2, "selected": false, "text": "<p>Why you don't use <a href=\"http://docs.jquery.com/Effects/toggle\" rel=\"nofollow noreferrer\">toggle()</a>...
2008/12/30
[ "https://Stackoverflow.com/questions/401056", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36590/" ]
Preface: I have jQuery and jQuery UI included on a page. I have this function defined: ``` function swap(sel) { if (1 == 1) { $(sel).hide('drop',{direction:'left'}); } } ``` How do I fix the (1 == 1) part to test to see if the element is already hidden and then bring it back if it...
if you don't like `toggle`, then this may help you: ``` function swap(sel) { if($(sel).is(':visible')) { $(sel).hide('drop',{direction:'left'}); } else { $(sel).show('drop',{direction:'left'}); } } ```
401,075
<p>I've come up with the call that gets the user's UI font preference (as opposed to Borland's hard-coded choice of "MS Sans Serif").</p> <p>Let's pretend the user's font preference is:</p> <pre><code>Segoe Print, 15pt </code></pre> <p>I set the font of all items, on all forms, in all applications to:</p> <pre><co...
[ { "answer_id": 401115, "author": "Nick Hodges", "author_id": 2044, "author_profile": "https://Stackoverflow.com/users/2044", "pm_score": 3, "selected": false, "text": "<p>First, just so we are clear, Borland doesn't own Delphi anymore. Embarcadero now owns Delphi, and we are in safe, se...
2008/12/30
[ "https://Stackoverflow.com/questions/401075", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12597/" ]
I've come up with the call that gets the user's UI font preference (as opposed to Borland's hard-coded choice of "MS Sans Serif"). Let's pretend the user's font preference is: ``` Segoe Print, 15pt ``` I set the font of all items, on all forms, in all applications to: ``` Segoe Print, 15pt ``` Problem is that t...
First, just so we are clear, Borland doesn't own Delphi anymore. Embarcadero now owns Delphi, and we are in safe, secure hands now. Okay, on to your question. The trick is to set TForm.AutoScroll to False AND make sure that your development machine is set to Small fonts. Leaving TForm.Scaled alone (it's default value...
401,079
<p>I have a stored procedure in Oracle that returns a select statement cursor reference. I want to be able to pass column names and sort direction (example: 'CompanyName DESC') and be able to sort the results, or pass a filter such as 'CompanyID > 400' and be able to apply that to the select statement. what is the...
[ { "answer_id": 401223, "author": "tuinstoel", "author_id": 43901, "author_profile": "https://Stackoverflow.com/users/43901", "pm_score": 1, "selected": false, "text": "<p>See here: <a href=\"http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1288401763279\" rel=\"nofollo...
2008/12/30
[ "https://Stackoverflow.com/questions/401079", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18893/" ]
I have a stored procedure in Oracle that returns a select statement cursor reference. I want to be able to pass column names and sort direction (example: 'CompanyName DESC') and be able to sort the results, or pass a filter such as 'CompanyID > 400' and be able to apply that to the select statement. what is the best wa...
I think you want a cursor with an `OPEN-FOR` and `USING`. ``` CREATE OR REPLACE FUNCTION sort_table ( p_sort VARCHAR2 ) IS TYPE cursor_type IS REF_CURSOR; cur_out cursor_type; lv_cursor_txt VARCHAR2(300); BEGIN lv_cursor_txt = 'SELECT * FROM table :sort'; OPEN cur_out FOR lv_cursor_txt USIN...
401,090
<p>I've always been one to err on the side of preventing exception conditions by never taking an action unless I am certain that there will be no errors. I learned to program in C and this was the only way to really do things.</p> <p>Working with C# I frequently see more reactive programing - try to do something and ...
[ { "answer_id": 401094, "author": "Jon B", "author_id": 27414, "author_profile": "https://Stackoverflow.com/users/27414", "pm_score": 3, "selected": true, "text": "<p>You can certainly misuse exceptions is c#. In my view, you should never get an ArgumentNullException, since you should alw...
2008/12/30
[ "https://Stackoverflow.com/questions/401090", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40284/" ]
I've always been one to err on the side of preventing exception conditions by never taking an action unless I am certain that there will be no errors. I learned to program in C and this was the only way to really do things. Working with C# I frequently see more reactive programing - try to do something and handle exce...
You can certainly misuse exceptions is c#. In my view, you should never get an ArgumentNullException, since you should always test for null first. However, there are also many cases where you can't range check your way out of an exception. Anything that interacts with "the outside world" (connecting to a web server, da...
401,114
<p>Right now I have a JSP page that allows to sort some items, when is ready and a link is clicked a JavaScript function converts all the info into XML (text in a variable), after this i need to send this XML to the JSP page again, i tried putting the info in a hidden input and submitting the form, sending with $.post ...
[ { "answer_id": 401123, "author": "Adam Peck", "author_id": 26658, "author_profile": "https://Stackoverflow.com/users/26658", "pm_score": 1, "selected": false, "text": "<p>You could always use an XMLHttpRequest to send the data. This can be done with our without user interaction on an el...
2008/12/30
[ "https://Stackoverflow.com/questions/401114", "https://Stackoverflow.com", "https://Stackoverflow.com/users/43304/" ]
Right now I have a JSP page that allows to sort some items, when is ready and a link is clicked a JavaScript function converts all the info into XML (text in a variable), after this i need to send this XML to the JSP page again, i tried putting the info in a hidden input and submitting the form, sending with $.post and...
You're probably going the wrong way here. You didn't provide the html code, but I assume it is something like this: ``` <form method="POST" id="form"> <input type="hidden" id="data" /> </form> ``` If that is correct, then you should say `$("#data").val(xml);` instead of `text()` or `html()` as those change the m...
401,118
<p>I'm using Django to write a blog app, and I'm trying to implement a hierarchical category structure. Each category has a "parent" ForeignKey pointing back to the same Category model. I want to allow admins to add categories, and I want the interface to allow them to select a category's parent category. However, I...
[ { "answer_id": 401186, "author": "S.Lott", "author_id": 10661, "author_profile": "https://Stackoverflow.com/users/10661", "pm_score": 0, "selected": false, "text": "<p>\"Is there any better way to do this?\" Not really. Hierarchies are hard in the relational model. Nothing makes the e...
2008/12/30
[ "https://Stackoverflow.com/questions/401118", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50272/" ]
I'm using Django to write a blog app, and I'm trying to implement a hierarchical category structure. Each category has a "parent" ForeignKey pointing back to the same Category model. I want to allow admins to add categories, and I want the interface to allow them to select a category's parent category. However, I want ...
If I understand your predicament correctly, the problem itself lies with the way you're dealing with which categories can be parents and which ones can't. One option to avoid these problems is to actually limit the level of categories which can become parents. For example, let's say you have the following categories: ...
401,174
<p>Here's a simple syntax question (I hope), I know how to constrain one generic type using the where clause, but how to constrain two generic types?</p> <p>Maybe the easiest way is to write down what my best guess as to the syntax was.</p> <pre><code>public class GenericDaoGetByIdTests&lt;TDao, TComponent&gt; : Base...
[ { "answer_id": 401190, "author": "ChrisW", "author_id": 49942, "author_profile": "https://Stackoverflow.com/users/49942", "pm_score": 6, "selected": true, "text": "<p>Use two 'where' keywords, for example I have a declaration like this:</p>\n\n<pre><code>public interface IParentNodeT&lt;...
2008/12/30
[ "https://Stackoverflow.com/questions/401174", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5056/" ]
Here's a simple syntax question (I hope), I know how to constrain one generic type using the where clause, but how to constrain two generic types? Maybe the easiest way is to write down what my best guess as to the syntax was. ``` public class GenericDaoGetByIdTests<TDao, TComponent> : BaseDaoTests where TDao : ID...
Use two 'where' keywords, for example I have a declaration like this: ``` public interface IParentNodeT<TChild, TSelf> where TChild : IChildNodeT<TSelf, TChild>, INodeT<TChild> where TSelf : IParentNodeT<TChild, TSelf> { TChild childRoot { get; set; } } ```
401,183
<p>I want to create a header file for C, C++ which is specific to help in randomization.</p>
[ { "answer_id": 401216, "author": "ChrisW", "author_id": 49942, "author_profile": "https://Stackoverflow.com/users/49942", "pm_score": 1, "selected": false, "text": "<p>I'm still not sure that I understand your question (I posted a comment to your question), but an answer might be this:</...
2008/12/30
[ "https://Stackoverflow.com/questions/401183", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20730/" ]
I want to create a header file for C, C++ which is specific to help in randomization.
Header files are C files, except that they *shouldn't* contain any code implementation (only declarations). For example, suppose the C file "dummy.c": ``` int dummy_function(int x){ return x+1; } ``` A good C header file would be: ``` #ifndef _DUMMY_HEADER_H_ #define _DUMMY_HEADER_H_ //This helps solve some pos...
401,184
<p>What's the best method for handling a situation where you have an ASP.Net Dropdownlist that is used to link to another URL</p> <p><em>edited for clarity</em></p> <p>Here's the basic scenario:</p> <p>Dropdownlist with 5 cities bound to it</p> <p>Selecting one of the cities should send me to a URL based on the cit...
[ { "answer_id": 401263, "author": "Robert C. Barth", "author_id": 9209, "author_profile": "https://Stackoverflow.com/users/9209", "pm_score": 2, "selected": false, "text": "<p>Set the autopostback to false, and add this to the onchange client-side event (assuming the value has the entire ...
2008/12/30
[ "https://Stackoverflow.com/questions/401184", "https://Stackoverflow.com", "https://Stackoverflow.com/users/32806/" ]
What's the best method for handling a situation where you have an ASP.Net Dropdownlist that is used to link to another URL *edited for clarity* Here's the basic scenario: Dropdownlist with 5 cities bound to it Selecting one of the cities should send me to a URL based on the city Right now I am posting back using t...
You can add a client-side handler for the selection changed event and then redirect to the desired page based on the selected value: ``` <asp:DropDownList ID="ddl" runat="server" onchange="document.location.href = this.value;" > <asp:ListItem Text="a" Value="http://url1"></asp:ListItem> <asp:ListItem Text="b...
401,191
<p>My design exposes two kinds of resources:</p> <ol> <li>Images</li> <li>Tags</li> </ol> <p>I would like clients to be able to request random images by their tag(s). For example: Give me random images that are tagged with "New York" and "Winter". What would a RESTful design look like in this case?</p>
[ { "answer_id": 401229, "author": "S.Lott", "author_id": 10661, "author_profile": "https://Stackoverflow.com/users/10661", "pm_score": 2, "selected": false, "text": "<p>Multi-dimensional resource identification is challenging. </p>\n\n<p>Your resource is an image, so that's your URI. Fu...
2008/12/30
[ "https://Stackoverflow.com/questions/401191", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14731/" ]
My design exposes two kinds of resources: 1. Images 2. Tags I would like clients to be able to request random images by their tag(s). For example: Give me random images that are tagged with "New York" and "Winter". What would a RESTful design look like in this case?
To sum up all the discussion in the comments, and not to change my initial proposal, this is what I'd come up finally: You want to access images via tags; each tag relates to a set of images. As a given tag may be used a lot more than another (say, New York photos used a lot more than Chicago's), you should use a REST...
401,231
<p>I have a set of data protected by 16bit checksums that I need to correct. The checksum locations are known, the exact areas they are calculated on and the exact algorithm used to calculate them are not. 16bit, LSB first. I suspect it's some sort of 16bit CRC, but I have not been able to find the code that's actua...
[ { "answer_id": 401607, "author": "Judge Maygarden", "author_id": 1491, "author_profile": "https://Stackoverflow.com/users/1491", "pm_score": 3, "selected": true, "text": "<p>The code you posted from loc_34FA6 down is basically the following:</p>\n\n<pre><code>unsigned short\ncrc16_update...
2008/12/30
[ "https://Stackoverflow.com/questions/401231", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50259/" ]
I have a set of data protected by 16bit checksums that I need to correct. The checksum locations are known, the exact areas they are calculated on and the exact algorithm used to calculate them are not. 16bit, LSB first. I suspect it's some sort of 16bit CRC, but I have not been able to find the code that's actually ca...
The code you posted from loc\_34FA6 down is basically the following: ``` unsigned short crc16_update(unsigned short crc, unsigned char nextByte) { crc ^= nextByte; for (int i = 0; i < 8; ++i) { if (crc & 1) crc = (crc >> 1) ^ 0xA001; else crc = (crc >> 1); } re...
401,232
<p>Why are static indexers disallowed in C#? I see no reason why they should not be allowed and furthermore they could be very useful.</p> <p>For example:</p> <pre><code>public static class ConfigurationManager { public object this[string name] { get =&gt; ConfigurationManager.getProperty...
[ { "answer_id": 401255, "author": "ChrisW", "author_id": 49942, "author_profile": "https://Stackoverflow.com/users/49942", "pm_score": 3, "selected": false, "text": "<p>As a work-around, you can define an instance indexer on a singleton/static object (say that ConfigurationManager is a si...
2008/12/30
[ "https://Stackoverflow.com/questions/401232", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12243/" ]
Why are static indexers disallowed in C#? I see no reason why they should not be allowed and furthermore they could be very useful. For example: ``` public static class ConfigurationManager { public object this[string name] { get => ConfigurationManager.getProperty(name); set ...
Indexer notation requires a reference to `this`. Since static methods don't have a reference to any particular instance of the class, you can't use `this` with them, and consequently you can't use indexer notation on static methods. The solution to your problem is using a singleton pattern as follows: ``` public clas...
401,240
<p>I'm working on a Cocoa Mac app where I need to display a window/view on a secondary monitor, full-screen.</p> <p>I know how to create a window that could be dragged onto the secondary monitor, but I was wanting to programmatically create the window and make it full screen on the external monitor.</p>
[ { "answer_id": 401409, "author": "sbooth", "author_id": 31520, "author_profile": "https://Stackoverflow.com/users/31520", "pm_score": 5, "selected": true, "text": "<p>First, determine which screen you want to use by iterating over <code>[NSScreen screens]</code>.</p>\n<p>Create a full sc...
2008/12/30
[ "https://Stackoverflow.com/questions/401240", "https://Stackoverflow.com", "https://Stackoverflow.com/users/32854/" ]
I'm working on a Cocoa Mac app where I need to display a window/view on a secondary monitor, full-screen. I know how to create a window that could be dragged onto the secondary monitor, but I was wanting to programmatically create the window and make it full screen on the external monitor.
First, determine which screen you want to use by iterating over `[NSScreen screens]`. Create a full screen window with: ``` NSScreen *screen = /* from [NSScreen screens] */ NSRect screenRect = [screen frame]; NSWindow *window = [[NSWindow alloc] initWithContentRect:screenRect styleMask:NSBorderlessWindowMask ...
401,241
<p>I am new to Ruby on Rails, I have completed the <a href="http://guides.rubyonrails.org/getting_started_with_rails.html" rel="noreferrer">Blog Tutorial</a>.</p> <p>I am now trying to add an additional action to the controller, called 'start'.</p> <pre><code>def start end </code></pre> <p>I have added a view page "...
[ { "answer_id": 401335, "author": "zenazn", "author_id": 46848, "author_profile": "https://Stackoverflow.com/users/46848", "pm_score": 6, "selected": true, "text": "<p>Your routing isn't set up to allow that route. Assuming you're using the default scaffolding, put this line <em>before</e...
2008/12/30
[ "https://Stackoverflow.com/questions/401241", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50262/" ]
I am new to Ruby on Rails, I have completed the [Blog Tutorial](http://guides.rubyonrails.org/getting_started_with_rails.html). I am now trying to add an additional action to the controller, called 'start'. ``` def start end ``` I have added a view page "app/views/posts/start.html.erb" containing nothing but simple...
Your routing isn't set up to allow that route. Assuming you're using the default scaffolding, put this line *before* the `map.resources :posts` line in config/routes.rb: ``` map.connect "posts/:action", :controller => 'posts', :action => /[a-z]+/i ``` The regex for `:action` restricts it to just a-z (to avoid catchi...
401,277
<p>In Django, I've got loggers all over the place, currently with hard-coded names.</p> <p>For module-level logging (i.e., in a module of view functions) I have the urge to do this.</p> <pre><code>log = logging.getLogger(__name__) </code></pre> <p>For class-level logging (i.e., in a class <code>__init__</code> metho...
[ { "answer_id": 401352, "author": "Steve Losh", "author_id": 13498, "author_profile": "https://Stackoverflow.com/users/13498", "pm_score": 2, "selected": false, "text": "<p>That looks like it will work, except that <code>self</code> won't have a <code>__module__</code> attribute; its clas...
2008/12/30
[ "https://Stackoverflow.com/questions/401277", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10661/" ]
In Django, I've got loggers all over the place, currently with hard-coded names. For module-level logging (i.e., in a module of view functions) I have the urge to do this. ``` log = logging.getLogger(__name__) ``` For class-level logging (i.e., in a class `__init__` method) I have the urge to do this. ``` self.log...
I typically don't use or find a need for class-level loggers, but I keep my modules at a few classes at most. A simple: ``` import logging LOG = logging.getLogger(__name__) ``` At the top of the module and subsequent: ``` LOG.info('Spam and eggs are tasty!') ``` from anywhere in the file typically gets me to wher...
401,284
<p>I've been working on a ASP.NET project that is going to save uploaded files to a network share. I figured I could just use a virtual directory and be fine, but I have been struggling with permissions for Directory.CreateDirectory.</p> <p>I was able to upload files so I decided to change my code to place everything...
[ { "answer_id": 401298, "author": "ChrisW", "author_id": 49942, "author_profile": "https://Stackoverflow.com/users/49942", "pm_score": 2, "selected": false, "text": "<p>Perhaps your code which is running (i.e. ASP.NET server code) is running as a user (e.g. the IIS user) which doesn't hav...
2008/12/30
[ "https://Stackoverflow.com/questions/401284", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10420/" ]
I've been working on a ASP.NET project that is going to save uploaded files to a network share. I figured I could just use a virtual directory and be fine, but I have been struggling with permissions for Directory.CreateDirectory. I was able to upload files so I decided to change my code to place everything in a singl...
I just recently worked on a very similar project where I am saving files to a network share. The two computers are on the same subnet, but are not controlled by domain controller, so each computer has it's own users. I created a user with the same username and password on both computers. Then I created a network share...
401,304
<p>My path is <code>\\server\folderName1\another name\something\another folder\</code></p> <p>How do I extract each folder name into a string if I don't know how many folders there are in the path and I don't know the folder names?</p> <p>Many thanks</p>
[ { "answer_id": 401312, "author": "Mark A Johnson", "author_id": 45720, "author_profile": "https://Stackoverflow.com/users/45720", "pm_score": 2, "selected": false, "text": "<p>The quick answer is to use the .Split('\\\\') method.</p>\n" }, { "answer_id": 401321, "author": "Br...
2008/12/30
[ "https://Stackoverflow.com/questions/401304", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
My path is `\\server\folderName1\another name\something\another folder\` How do I extract each folder name into a string if I don't know how many folders there are in the path and I don't know the folder names? Many thanks
``` string mypath = @"..\folder1\folder2\folder2"; string[] directories = mypath.Split(Path.DirectorySeparatorChar); ``` Edit: This returns each individual folder in the directories array. You can get the number of folders returned like this: ``` int folderCount = directories.Length; ```
401,306
<p>Is there any way to access the <code>&lt;compilation /&gt;</code> tag in a web.config file?</p> <p>I want to check if the "<em>debug</em>" attribute is set to "<em>true</em>" in the file, but I can't seem to figure out how to do it. I've tried using the <code>WebConfigurationManager</code>, but that doesn't seem to...
[ { "answer_id": 401320, "author": "mmx", "author_id": 33708, "author_profile": "https://Stackoverflow.com/users/33708", "pm_score": 2, "selected": false, "text": "<p>After all, you can always load up the <code>Web.config</code> file into an <code>XmlDocument</code> and use an <code>XPath<...
2008/12/30
[ "https://Stackoverflow.com/questions/401306", "https://Stackoverflow.com", "https://Stackoverflow.com/users/392/" ]
Is there any way to access the `<compilation />` tag in a web.config file? I want to check if the "*debug*" attribute is set to "*true*" in the file, but I can't seem to figure out how to do it. I've tried using the `WebConfigurationManager`, but that doesn't seem to allow me to get to the `<compilation />` section. ...
Use: ``` using System.Configuration; using System.Web.Configuration; ``` ... ``` CompilationSection configSection = (CompilationSection) ConfigurationManager.GetSection( "system.web/compilation" ); ``` You can then check the `configSection.Debug` property. **TIP:** if you need to know how to get a va...
401,326
<p>I have lots of home directories under /ifshome on Linux. I want to see which users have not logged in for the past 6 months, and my solution is to parse the /ifshome/user/.lastlogin file. Each .lastlogin file has the same format, 1 line:</p> <pre><code>Last Login: Fri Mar 09 18:06:27 PST 2001 </code></pre> <p>I ne...
[ { "answer_id": 401368, "author": "xtofl", "author_id": 6610, "author_profile": "https://Stackoverflow.com/users/6610", "pm_score": 1, "selected": false, "text": "<p>Am I correct to assume that the latest time should more or less equal the change time of the file? If so, you can easily u...
2008/12/30
[ "https://Stackoverflow.com/questions/401326", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18406/" ]
I have lots of home directories under /ifshome on Linux. I want to see which users have not logged in for the past 6 months, and my solution is to parse the /ifshome/user/.lastlogin file. Each .lastlogin file has the same format, 1 line: ``` Last Login: Fri Mar 09 18:06:27 PST 2001 ``` I need to build a shell script...
Ok, here is my silly way (untested!) using a pure shell script parsing your file. The `date` command can parse a date string, and output the seconds since 1970. Subtract them from the current seconds, and divide by the amount of seconds one month takes. Print that value together with the users path. ``` for i in /ifs...
401,331
<p>If I delete a file in Subversion, how can I look at it's history and contents? If I try to do <code>svn cat</code> or <code>svn log</code> on a nonexistent file, it complains that the file doesn't exist.</p> <p>Also, if I wanted to resurrect the file, should I just <code>svn add</code> it back?</p> <p>(I asked spe...
[ { "answer_id": 401344, "author": "Jack M.", "author_id": 3421, "author_profile": "https://Stackoverflow.com/users/3421", "pm_score": 1, "selected": false, "text": "<p>You would need to specify a revision.</p>\n\n<pre><code>svn log -r &lt;revision&gt; &lt;deleted file&gt;\n</code></pre>\n...
2008/12/30
[ "https://Stackoverflow.com/questions/401331", "https://Stackoverflow.com", "https://Stackoverflow.com/users/33795/" ]
If I delete a file in Subversion, how can I look at it's history and contents? If I try to do `svn cat` or `svn log` on a nonexistent file, it complains that the file doesn't exist. Also, if I wanted to resurrect the file, should I just `svn add` it back? (I asked specifically about Subversion, but I'd also like to h...
To get the log of a deleted file, use ``` svn log -r lastrevisionthefileexisted ``` If you want to resurrect the file and keep its version history, use ``` svn copy url/of/file@lastrevisionthefileexisted -r lastrevisionthefileexisted path/to/workingcopy/file ``` If you just want the file content but unversioned (...
401,338
<p>Is it possible to progmatically or dynamically create a project in VS2005 using c#? If so could someone provide some ideas or links on how to accomplish this?</p>
[ { "answer_id": 401386, "author": "Gavin Miller", "author_id": 33226, "author_profile": "https://Stackoverflow.com/users/33226", "pm_score": 0, "selected": false, "text": "<p>Visual Studio Projects are \"simply\" XML files. I say simply because there is a lot going on in them. To get an ...
2008/12/30
[ "https://Stackoverflow.com/questions/401338", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Is it possible to progmatically or dynamically create a project in VS2005 using c#? If so could someone provide some ideas or links on how to accomplish this?
You can also create and edit msbuild files programatically using the msbuild api. See here for details: <http://msdn.microsoft.com/en-us/library/microsoft.build.buildengine.project.aspx> Here's an example that creates a project that compiles a single .cs file and references an external assembly: ``` Engine engine=new...
401,339
<p>I am using the Microsoft.Practices.EnterpriseLibrary Database tools and I'm having trouble creating a new database using <em>just</em> the connection string information.</p> <p>Ideally I would like to do the following:</p> <pre><code>Database dbEngine = DatabaseFactory.CreateDatabase( "Data Source=myServerAddr...
[ { "answer_id": 404265, "author": "Paul Lalonde", "author_id": 5782, "author_profile": "https://Stackoverflow.com/users/5782", "pm_score": 0, "selected": false, "text": "<p>Er... That's because CreateDatabase expects the <em>name</em> of a connection string (as specified in your app's con...
2008/12/30
[ "https://Stackoverflow.com/questions/401339", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I am using the Microsoft.Practices.EnterpriseLibrary Database tools and I'm having trouble creating a new database using *just* the connection string information. Ideally I would like to do the following: ``` Database dbEngine = DatabaseFactory.CreateDatabase( "Data Source=myServerAddress;Initial Catalog=myDataBa...
You can also do ``` Database mydb = new EnterpriseLibrary.Data.Sql.SqlDatabase("connection string here"); ``` and you'll retain the versatility of the Database object, but create it with a connection string.
401,342
<p>Is there any recommended solutions when an embedding a script that will make a callback to the originating source but the js resides in a different domain. Sometimes other clients would be in a different domain and I can't rely on getting the document or window location.</p> <p>Currently, I've been using this but ...
[ { "answer_id": 401407, "author": "Diodeus - James MacFarlane", "author_id": 12579, "author_profile": "https://Stackoverflow.com/users/12579", "pm_score": 1, "selected": false, "text": "<p>You'd be better off passing this information from the server and populating it in a JavaScript varia...
2008/12/30
[ "https://Stackoverflow.com/questions/401342", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50261/" ]
Is there any recommended solutions when an embedding a script that will make a callback to the originating source but the js resides in a different domain. Sometimes other clients would be in a different domain and I can't rely on getting the document or window location. Currently, I've been using this but not too hap...
You'd be better off passing this information from the server and populating it in a JavaScript variable when the page is served.
401,346
<p>I have the following structure: message (message table) may have multiple fields (fields table), and each field may have multiple subfields (stored in the same "fields" table with the only difference that fields dont have values in the "ParentField" column). Subfields may have subsubfields, etc., but this is not imp...
[ { "answer_id": 401418, "author": "Esko", "author_id": 44523, "author_profile": "https://Stackoverflow.com/users/44523", "pm_score": 1, "selected": true, "text": "<p>Note: This answer comes from my friend who knows a lot more about these things.</p>\n\n<hr>\n\n<p>As this <a href=\"http://...
2008/12/30
[ "https://Stackoverflow.com/questions/401346", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50290/" ]
I have the following structure: message (message table) may have multiple fields (fields table), and each field may have multiple subfields (stored in the same "fields" table with the only difference that fields dont have values in the "ParentField" column). Subfields may have subsubfields, etc., but this is not import...
Note: This answer comes from my friend who knows a lot more about these things. --- As this [J2ME FAQ](http://www.j2meforums.com/wiki/index.php/FAQ#Can_I_access_the_phone.27s_j2me.3F_.28memory.2C_phone_book.2C_inbox.2C_pictures....29_.3F) states, > > **Can I access the phone's j2me?** > **(memory, phone book, inbox...
401,348
<p>I have a common code of serializing a class object in my 3-4 methods ,So I am thinking to create a common function for that code and call function in all the methods </p> <p>I am doingn this from the following code </p> <pre><code>DataContractJsonSerializer ser = new DataContractJsonSerializer(this.GetType()); Me...
[ { "answer_id": 401354, "author": "JaredPar", "author_id": 23283, "author_profile": "https://Stackoverflow.com/users/23283", "pm_score": -1, "selected": false, "text": "<p>Try using Type instead of class</p>\n\n<pre><code>public string GenerateJsonString(Type t1)\n</code></pre>\n" }, ...
2008/12/30
[ "https://Stackoverflow.com/questions/401348", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14299/" ]
I have a common code of serializing a class object in my 3-4 methods ,So I am thinking to create a common function for that code and call function in all the methods I am doingn this from the following code ``` DataContractJsonSerializer ser = new DataContractJsonSerializer(this.GetType()); MemoryStream ms = new Me...
You are confusing a "class" with an "object". You serialize an object, which is an instance of a particular class (aka "Type"). You can create a method taking a parameter of the .NET base type for all objects, "object", like this: ``` public static string GenerateJsonString(object o) { DataContractJsonSerializer...
401,376
<p>I'm just learning asp.net mvc and I'm trying to figure out how to move my controllers into a separate project. Typically when I have designed asp.net web apps before, I created one project for my models, another for my logic, and then there was the web. </p> <p>Now that I'm learning asp.net mvc I was hoping to fo...
[ { "answer_id": 401481, "author": "Craig Stuntz", "author_id": 7714, "author_profile": "https://Stackoverflow.com/users/7714", "pm_score": 8, "selected": true, "text": "<p>First of all, it is certainly a good idea to put your model into a separate project. As you've discovered, this is tr...
2008/12/30
[ "https://Stackoverflow.com/questions/401376", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24908/" ]
I'm just learning asp.net mvc and I'm trying to figure out how to move my controllers into a separate project. Typically when I have designed asp.net web apps before, I created one project for my models, another for my logic, and then there was the web. Now that I'm learning asp.net mvc I was hoping to follow a simil...
First of all, it is certainly a good idea to put your model into a separate project. As you've discovered, this is trivial. Regarding Controllers and Views, I don't see any obvious advantage to separating them for most basic projects, although you may have a particular need to do so in a particular application. If yo...
401,389
<p>I'm using a UINavigationController and I'm having trouble releasing objects when I push a new view. I want to set an object on the new controller before pushing it. The way I'm currently doing this is:</p> <pre><code>OpenPageViewController *varOpenPageController = [[OpenPageViewController alloc] initWithNibName:@"O...
[ { "answer_id": 401481, "author": "Craig Stuntz", "author_id": 7714, "author_profile": "https://Stackoverflow.com/users/7714", "pm_score": 8, "selected": true, "text": "<p>First of all, it is certainly a good idea to put your model into a separate project. As you've discovered, this is tr...
2008/12/30
[ "https://Stackoverflow.com/questions/401389", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29941/" ]
I'm using a UINavigationController and I'm having trouble releasing objects when I push a new view. I want to set an object on the new controller before pushing it. The way I'm currently doing this is: ``` OpenPageViewController *varOpenPageController = [[OpenPageViewController alloc] initWithNibName:@"OpenPageViewCon...
First of all, it is certainly a good idea to put your model into a separate project. As you've discovered, this is trivial. Regarding Controllers and Views, I don't see any obvious advantage to separating them for most basic projects, although you may have a particular need to do so in a particular application. If yo...
401,415
<p>Hullo all,</p> <p>Wondering if there are any Java hackers who can clue me in at to why the following doesn't work:</p> <pre><code>public class Parent { public Parent copy() { Parent aCopy = new Parent(); ... return aCopy; } } public class ChildN extends Parent { ... } public clas...
[ { "answer_id": 401419, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 3, "selected": false, "text": "<p>The cast is effectively trying to do this:</p>\n\n<pre><code>ChildN copy = (ChildN) orig.copy();\n</code></pre>\n\n<p...
2008/12/30
[ "https://Stackoverflow.com/questions/401415", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50264/" ]
Hullo all, Wondering if there are any Java hackers who can clue me in at to why the following doesn't work: ``` public class Parent { public Parent copy() { Parent aCopy = new Parent(); ... return aCopy; } } public class ChildN extends Parent { ... } public class Driver { publi...
(Can't add code in a comment, so I'll add here) Regarding Cloneable: if you're implementing Cloneable, implement it as follows; much cleaner to call... ``` public class Foo implements Cloneable { public Foo clone() { try { return (Foo) super.clone(); } catch (CloneNotSupportedException...
401,432
<p>I'm trying to figure out how to implement a function in a tree node which returns all its descendant leaves (whether direct or indirect). However, I don't want to pass a container in which the leaf nodes will be put recursively (the tree could be huge), instead I'd like to use a generator to iterate through the tree...
[ { "answer_id": 401435, "author": "Lasse V. Karlsen", "author_id": 267, "author_profile": "https://Stackoverflow.com/users/267", "pm_score": 4, "selected": true, "text": "<p>Here's how you should implement Branch.EnumerateLeaves:</p>\n\n<pre><code>public IEnumerable&lt;ITreeNode&gt; Enume...
2008/12/30
[ "https://Stackoverflow.com/questions/401432", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7839/" ]
I'm trying to figure out how to implement a function in a tree node which returns all its descendant leaves (whether direct or indirect). However, I don't want to pass a container in which the leaf nodes will be put recursively (the tree could be huge), instead I'd like to use a generator to iterate through the tree. I...
Here's how you should implement Branch.EnumerateLeaves: ``` public IEnumerable<ITreeNode> EnumerateLeaves() { foreach( var node in m_treeNodes ) { if( node is Leaf ) yield return node; else { foreach (ITreeNode childNode in node.EnumerateLeaves()) ...
401,463
<p>I am trying to figure out the location of the script tag the current javascript is running in. What is really going on is that I need to determine from <em>inside</em> a src'd, dynamically inserted javascript file where it is located in the DOM. These are dynamically generated tags; code snippet: </p> <pre><code>...
[ { "answer_id": 401473, "author": "sammich", "author_id": 50276, "author_profile": "https://Stackoverflow.com/users/50276", "pm_score": 3, "selected": false, "text": "<p>You could give the script an id tag, <a href=\"http://www.thespanner.co.uk/2008/01/09/dom-for-hackers/\" rel=\"noreferr...
2008/12/30
[ "https://Stackoverflow.com/questions/401463", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50301/" ]
I am trying to figure out the location of the script tag the current javascript is running in. What is really going on is that I need to determine from *inside* a src'd, dynamically inserted javascript file where it is located in the DOM. These are dynamically generated tags; code snippet: ``` <html> <head> <meta...
You could give the script an id tag, [like this dude does](http://www.thespanner.co.uk/2008/01/09/dom-for-hackers/)...
401,467
<p><em>edit: many thanks for all the answers. Here are the results after applying the optimisations so far:</em></p> <ul> <li><em>Switching to sorting the characters and run length encoding - new DB size 42M</em></li> <li><em>Dropping the indexes on the booleans - new DB size 33M</em></li> </ul> <p><em>The really nic...
[ { "answer_id": 401487, "author": "Eran Galperin", "author_id": 10585, "author_profile": "https://Stackoverflow.com/users/10585", "pm_score": 1, "selected": false, "text": "<p>Your best bet is to use compression, which unfortunately SQLite does not support natively at this point. Luckily,...
2008/12/30
[ "https://Stackoverflow.com/questions/401467", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42404/" ]
*edit: many thanks for all the answers. Here are the results after applying the optimisations so far:* * *Switching to sorting the characters and run length encoding - new DB size 42M* * *Dropping the indexes on the booleans - new DB size 33M* *The really nice part is this hasn't required any changes in the iphone co...
I'm not clear on all the use cases for the signature field but it seems like storing an alphabetized version of the word instead would be beneficial.
401,482
<p>I'm working with a code base where lists need to be frequently searched for a single element. </p> <p>Is it faster to use a Predicate and Find() than to manually do an enumeration on the List?</p> <p>for example:</p> <pre><code>string needle = "example"; FooObj result = _list.Find(delegate(FooObj foo) { retur...
[ { "answer_id": 401505, "author": "JaredPar", "author_id": 23283, "author_profile": "https://Stackoverflow.com/users/23283", "pm_score": 4, "selected": true, "text": "<p>They are not equivalent in performance. The Find() method requires a method (in this case delegate) invocation for eve...
2008/12/30
[ "https://Stackoverflow.com/questions/401482", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50299/" ]
I'm working with a code base where lists need to be frequently searched for a single element. Is it faster to use a Predicate and Find() than to manually do an enumeration on the List? for example: ``` string needle = "example"; FooObj result = _list.Find(delegate(FooObj foo) { return foo.Name == needle; }); `...
They are not equivalent in performance. The Find() method requires a method (in this case delegate) invocation for every item in the list. Method invocation is not free and is **relatively** expensive as compared to an inline comparison. The foreach version requires no extra method invocation per object. That being sa...
401,511
<p>Ruby 1.9.1 RC1 was released today so I quickly moved to install it (a test version of course using a suffix of 19). I install Rails and Rack for the 1.9 RubyGems and then create a new Rails site using edge... when I execute:</p> <pre><code>ruby19 ./script/server </code></pre> <p>I watch as the processor usage goes...
[ { "answer_id": 402671, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": true, "text": "<p>The same thing for me.</p>\n\n<p>I'm running the latest edge rails under webrik and just see the blank screen and no respons...
2008/12/30
[ "https://Stackoverflow.com/questions/401511", "https://Stackoverflow.com", "https://Stackoverflow.com/users/43043/" ]
Ruby 1.9.1 RC1 was released today so I quickly moved to install it (a test version of course using a suffix of 19). I install Rails and Rack for the 1.9 RubyGems and then create a new Rails site using edge... when I execute: ``` ruby19 ./script/server ``` I watch as the processor usage goes up to 99.8 and the termin...
The same thing for me. I'm running the latest edge rails under webrik and just see the blank screen and no response to Ctrl-C. Rails 2.2 isn't working at all. Also, I've tried run edge under thin (with eventmachine from github fixed to build on ruby 1.9.1, except one broken ruby test - I've just added empty one with ...
401,513
<p>Consider the following example structure</p> <pre><code>- Project - www - files + documents + html + images + scripts - WEB-INF * web.xml </code></pre> <p>The documents folder needs to be a symlink or in some other way external from the war fi...
[ { "answer_id": 401529, "author": "duffymo", "author_id": 37213, "author_profile": "https://Stackoverflow.com/users/37213", "pm_score": 1, "selected": false, "text": "<p>If it's static content, maybe you'd be better off fronting your app server with a web server and putting the static con...
2008/12/30
[ "https://Stackoverflow.com/questions/401513", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31518/" ]
Consider the following example structure ``` - Project - www - files + documents + html + images + scripts - WEB-INF * web.xml ``` The documents folder needs to be a symlink or in some other way external from the war file because users will add ...
If it's static content, maybe you'd be better off fronting your app server with a web server and putting the static content there. You relieve the app server of having to serve up static data and save a network roundtrip to boot.
401,521
<p>In the ASP.NET ajax library, there is a line that makes me confused.</p> <pre><code>Type.prototype.registerClass = function Type$registerClass(typeName, baseType, interfaceTypes) { //.. this.prototype.constructor = this; //.. } </code></pre> <p>I know that <code>(this.prototype.constructor === this) == true</co...
[ { "answer_id": 401527, "author": "Bramha Ghosh", "author_id": 3268, "author_profile": "https://Stackoverflow.com/users/3268", "pm_score": 2, "selected": false, "text": "<p>As far as I can tell, there's no way to automatically test before doing a submit. You can however infer it and prog...
2008/12/30
[ "https://Stackoverflow.com/questions/401521", "https://Stackoverflow.com", "https://Stackoverflow.com/users/33090/" ]
In the ASP.NET ajax library, there is a line that makes me confused. ``` Type.prototype.registerClass = function Type$registerClass(typeName, baseType, interfaceTypes) { //.. this.prototype.constructor = this; //.. } ``` I know that `(this.prototype.constructor === this) == true`, so what is significance of this ...
I use a similar approach during development and I can ensure that the synchronization between the development and production databases can easily become a daunting task if you modify too many tables at once. I realized that the best approach would be to forget about doing this synchronization manually, it's simply too...
401,555
<p>I have a Perl script running on UNIX that uses DBI to connect to and retrieve data from a SQL Server database. The script looks like the following:</p> <pre><code>$dbh = DBI-&gt;connect("dbi:Sybase:server=$connect;charset=UTF-8", $login, $password) or die("Couldn't connect to $connect as $login/$password: $DBI::err...
[ { "answer_id": 401567, "author": "Vinko Vrsalovic", "author_id": 5190, "author_profile": "https://Stackoverflow.com/users/5190", "pm_score": 0, "selected": false, "text": "<p>I've connected Perl to SQL Server <a href=\"https://stackoverflow.com/questions/149395/what-are-some-ways-of-acce...
2008/12/30
[ "https://Stackoverflow.com/questions/401555", "https://Stackoverflow.com", "https://Stackoverflow.com/users/324/" ]
I have a Perl script running on UNIX that uses DBI to connect to and retrieve data from a SQL Server database. The script looks like the following: ``` $dbh = DBI->connect("dbi:Sybase:server=$connect;charset=UTF-8", $login, $password) or die("Couldn't connect to $connect as $login/$password: $DBI::errstr"); $sql = "u...
Your code looks OK. I've no reason to believe that what you're putting into the database and subsequently retrieving isn't still in UTF-8 encoding. Have you confirmed that the terminal on which your printing the data is actually in UTF-8 mode?
401,556
<p>Is it a good idea to quote keys when using a hash in Perl?</p> <p>I am working on an extremely large legacy Perl code base and trying to adopt a lot of the best practices suggested by Damian Conway in <a href="http://oreilly.com/catalog/9780596001735/" rel="noreferrer">Perl Best Practices</a>. I know that best pra...
[ { "answer_id": 401576, "author": "ForYourOwnGood", "author_id": 48728, "author_profile": "https://Stackoverflow.com/users/48728", "pm_score": 5, "selected": false, "text": "<p>Without quotes is better. It's in {} so it's obvious that you are not using barewords, plus it is both easier to...
2008/12/30
[ "https://Stackoverflow.com/questions/401556", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6406/" ]
Is it a good idea to quote keys when using a hash in Perl? I am working on an extremely large legacy Perl code base and trying to adopt a lot of the best practices suggested by Damian Conway in [Perl Best Practices](http://oreilly.com/catalog/9780596001735/). I know that best practices are *always* a touchy subject wi...
When specifying constant string hash keys, you should always use (single) quotes. E.g., `$hash{'key'}` This is the best choice because it obviates the need to think about this issue and results in consistent formatting. If you leave off the quotes sometimes, you have to remember to add them when your key contains inter...
401,561
<pre><code>Image.FromFile(@"path\filename.tif") </code></pre> <p>or</p> <pre><code>Image.FromStream(memoryStream) </code></pre> <p>both produce image objects with only one frame even though the source is a multi-frame TIFF file. <strong>How do you load an image file that retains these frames?</strong> The tiffs are ...
[ { "answer_id": 401579, "author": "Otávio Décio", "author_id": 48684, "author_profile": "https://Stackoverflow.com/users/48684", "pm_score": 6, "selected": true, "text": "<p>Here's what I use:</p>\n\n<pre><code>private List&lt;Image&gt; GetAllPages(string file)\n{\n List&lt;Image&gt; i...
2008/12/30
[ "https://Stackoverflow.com/questions/401561", "https://Stackoverflow.com", "https://Stackoverflow.com/users/35286/" ]
``` Image.FromFile(@"path\filename.tif") ``` or ``` Image.FromStream(memoryStream) ``` both produce image objects with only one frame even though the source is a multi-frame TIFF file. **How do you load an image file that retains these frames?** The tiffs are saved using the Image.SaveAdd methods frame by frame. T...
Here's what I use: ``` private List<Image> GetAllPages(string file) { List<Image> images = new List<Image>(); Bitmap bitmap = (Bitmap)Image.FromFile(file); int count = bitmap.GetFrameCount(FrameDimension.Page); for (int idx = 0; idx < count; idx++) { // save each frame to a bytestream ...
401,598
<p>JTextField has a keyTyped event but it seems that at the time it fires the contents of the cell have not yet changed.</p> <p>Because of that .length() is always wrong if read here.</p> <p>There must be a simple way of getting the length as it appears to the user after a key stroke?</p>
[ { "answer_id": 401613, "author": "Sean Bright", "author_id": 21926, "author_profile": "https://Stackoverflow.com/users/21926", "pm_score": 4, "selected": true, "text": "<p>This is probably not the optimal way (and it's been a while), but in the past, I have added a DocumentListener to th...
2008/12/30
[ "https://Stackoverflow.com/questions/401598", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2443/" ]
JTextField has a keyTyped event but it seems that at the time it fires the contents of the cell have not yet changed. Because of that .length() is always wrong if read here. There must be a simple way of getting the length as it appears to the user after a key stroke?
This is probably not the optimal way (and it's been a while), but in the past, I have added a DocumentListener to the JTextField and on any of the events (insert, update, remove) I: ``` evt.getDocument().getLength() ``` Which returns the total length of text field's contents.
401,600
<p>I have a custom template for an expander that is close to the code below. I had to change some of the code to take out custom classes, brushes, etc..</p> <pre><code>&lt;Style TargetType="{x:Type Expander}"&gt; &lt;Setter Property="HorizontalContentAlignment" Value="Stretch" /&gt; &lt;Setter Property="...
[ { "answer_id": 401612, "author": "Matt Hamilton", "author_id": 615, "author_profile": "https://Stackoverflow.com/users/615", "pm_score": 7, "selected": true, "text": "<p>You need to use the FontWeight property to specify a bold font. However, you've probably noticed that ContentPresenter...
2008/12/30
[ "https://Stackoverflow.com/questions/401600", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1514/" ]
I have a custom template for an expander that is close to the code below. I had to change some of the code to take out custom classes, brushes, etc.. ``` <Style TargetType="{x:Type Expander}"> <Setter Property="HorizontalContentAlignment" Value="Stretch" /> <Setter Property="VerticalContentAlignment" ...
You need to use the FontWeight property to specify a bold font. However, you've probably noticed that ContentPresenter doesn't have that property. So you'll need to use the [TextBlock.FontWeight](http://msdn.microsoft.com/en-us/library/system.windows.controls.textblock.fontweight.aspx) attached property to tell the Con...
401,602
<p>I am using <a href="http://spritegen.website-performance.org/" rel="nofollow noreferrer">CSS Sprite Generator</a> to create sprites for a web page I am working on, but it doesn't seem to work, and I don't know why...I guess it's something obvious but..!</p> <p>So, I picked up 3 images, zipped, generated the PNG fil...
[ { "answer_id": 401615, "author": "Doug McClean", "author_id": 11173, "author_profile": "https://Stackoverflow.com/users/11173", "pm_score": 2, "selected": false, "text": "<p>Your <code>.sprite-bg</code> rule for <code>background-position</code>, set as part of the composite rule for <cod...
2008/12/30
[ "https://Stackoverflow.com/questions/401602", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I am using [CSS Sprite Generator](http://spritegen.website-performance.org/) to create sprites for a web page I am working on, but it doesn't seem to work, and I don't know why...I guess it's something obvious but..! So, I picked up 3 images, zipped, generated the PNG file (I checked out the result it is seems fine) a...
Don't use a generator. Take the time to do it yourself from scratch. Then next time you use this method, you'll know what to look for when something has gone wrong and you'll answer your own question, and heck, maybe someone else's on Stack Overflow. This generator isn't producing any meaningful class names for your s...
401,616
<p>Just wondering which is faster:</p> <pre><code>DELETE FROM table_name WHERE X='1' DELETE FROM table_name WHERE X='2' DELETE FROM table_name WHERE X='3' </code></pre> <p>or</p> <pre><code>DELETE FROM table_name WHERE X IN ('1', '2', '3') </code></pre> <p>Any ideas, hints, or references where to read?</p> <p>Than...
[ { "answer_id": 401626, "author": "Otávio Décio", "author_id": 48684, "author_profile": "https://Stackoverflow.com/users/48684", "pm_score": 2, "selected": false, "text": "<p>A single delete is faster, there is only one plan to create and execute.</p>\n" }, { "answer_id": 401638, ...
2008/12/30
[ "https://Stackoverflow.com/questions/401616", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49881/" ]
Just wondering which is faster: ``` DELETE FROM table_name WHERE X='1' DELETE FROM table_name WHERE X='2' DELETE FROM table_name WHERE X='3' ``` or ``` DELETE FROM table_name WHERE X IN ('1', '2', '3') ``` Any ideas, hints, or references where to read? Thank you all!
The single delete will be faster for a few reasons: 1. Only one plan will need to be generated 2. Only one transaction will be involved (if you are using them) 3. If you are running these from code, then there is less overhead with ODBC calls and network traffic 4. Any indexes will need to be refreshed just once, not ...
401,621
<p>Suppose I have some per-class data: (AandB.h)</p> <pre><code>class A { public: static Persister* getPersister(); } class B { public: static Persister* getPersister(); } </code></pre> <p>... and lots and lots more classes. And I want to do something like:</p> <pre><code>persistenceSystem::registerPersistabl...
[ { "answer_id": 401761, "author": "Judge Maygarden", "author_id": 1491, "author_profile": "https://Stackoverflow.com/users/1491", "pm_score": 2, "selected": false, "text": "<p>Register each template at run-time in the constructor. Use a static variable per template to check if the type ha...
2008/12/30
[ "https://Stackoverflow.com/questions/401621", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48956/" ]
Suppose I have some per-class data: (AandB.h) ``` class A { public: static Persister* getPersister(); } class B { public: static Persister* getPersister(); } ``` ... and lots and lots more classes. And I want to do something like: ``` persistenceSystem::registerPersistableType( A::getPersister() ); persisten...
You can execute something before main once if a instantiation of a template is made. The trick is to put a static data member into a class template, and reference that from outside. The side effect that static data member triggers can be used to call the register function: ``` template<typename D> struct automatic_reg...
401,623
<p>I'm looking for any suggestion/rules/guides on making a decent print css for when a webpage is printed. Do you have any to offer?</p>
[ { "answer_id": 401636, "author": "JoshBerke", "author_id": 26160, "author_profile": "https://Stackoverflow.com/users/26160", "pm_score": 1, "selected": false, "text": "<p>Watch out for background images and colors. I think IE's default behavior is not to printout background images or col...
2008/12/30
[ "https://Stackoverflow.com/questions/401623", "https://Stackoverflow.com", "https://Stackoverflow.com/users/396/" ]
I'm looking for any suggestion/rules/guides on making a decent print css for when a webpage is printed. Do you have any to offer?
Here are some general print styles to use to get better print outs: ``` /* Print styles */ @media print { tr, td, th {page-break-inside:avoid} thead {display:table-header-group} .NoPrint {visibility:hidden; display:none} a {color:#000000} } ``` The top one prevents page breaks inside of a table row ...
401,637
<p>The technique for adding a reference to the COM interop of Office in Visual Studio is to go to:</p> <ol> <li>References</li> <li>Add Reference</li> <li>Select the <strong>COM</strong> tab</li> <li>Select <strong>Microsoft Office 11.0 Object Library</strong></li> </ol> <p>And magically named reference appears:</p> ...
[ { "answer_id": 401662, "author": "Roni Schwarts", "author_id": 50197, "author_profile": "https://Stackoverflow.com/users/50197", "pm_score": 1, "selected": false, "text": "<p>do you use VSTO (Visual studio tools for office)?</p>\n\n<p><a href=\"http://msdn.microsoft.com/en-us/office/aa90...
2008/12/30
[ "https://Stackoverflow.com/questions/401637", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12597/" ]
The technique for adding a reference to the COM interop of Office in Visual Studio is to go to: 1. References 2. Add Reference 3. Select the **COM** tab 4. Select **Microsoft Office 11.0 Object Library** And magically named reference appears: ``` Microsoft.Office.Core ``` The `Project.csproj` file shows the detail...
The answer is to "Copy Local" whatever assembly dll you get for the interop. Once you have the assembly dll in your output folder, add a reference to it, and check it into source control. Now everyone has the referenced assembly dll.
401,659
<p>In .NET framework, is it possible to set some of the items in the <code>CheckedListBox</code> as "uncheckable" ? I don't want to allow user to check the same items again and add them to a another existing list. </p> <p>I hope I am clear. Thanks in advance.</p>
[ { "answer_id": 401678, "author": "Matt Hamilton", "author_id": 615, "author_profile": "https://Stackoverflow.com/users/615", "pm_score": 4, "selected": true, "text": "<p>I would set those items as \"Indeterminate\" in code, and then overwrite the \"NewValue\" property from the ItemCheck ...
2008/12/30
[ "https://Stackoverflow.com/questions/401659", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49057/" ]
In .NET framework, is it possible to set some of the items in the `CheckedListBox` as "uncheckable" ? I don't want to allow user to check the same items again and add them to a another existing list. I hope I am clear. Thanks in advance.
I would set those items as "Indeterminate" in code, and then overwrite the "NewValue" property from the ItemCheck event when the user attempts to check/uncheck them: ``` public Form1() { InitializeComponent(); checkedListBox1.Items.Add("Can't check me", CheckState.Indeterminate); } private void checkedListBox...
401,668
<p>I am wondering how I can read CSS comments out of a linked stylesheet.</p> <p>I have this sample CSS loaded via:</p> <pre><code>&lt;link rel="stylesheet" type="text/css" media="all" href="test.css" /&gt; </code></pre> <p>&nbsp;</p> <pre><code>#test1{ border:1px solid #000; } #test2{ border:1px solid #000; } #tes...
[ { "answer_id": 401672, "author": "Adam Peck", "author_id": 26658, "author_profile": "https://Stackoverflow.com/users/26658", "pm_score": 2, "selected": false, "text": "<p>Comments will almost always be ignored by an interpreter and therefor will not be available.</p>\n" }, { "ans...
2008/12/30
[ "https://Stackoverflow.com/questions/401668", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I am wondering how I can read CSS comments out of a linked stylesheet. I have this sample CSS loaded via: ``` <link rel="stylesheet" type="text/css" media="all" href="test.css" /> ``` ``` #test1{ border:1px solid #000; } #test2{ border:1px solid #000; } #test3{/* sample comment text I'm trying to read */} ``` I'm...
You could retrieve the stylesheet's contents and use regex to parse the comments. This example uses jQuery to get the stylesheet text and a regular expression to find the comments: ``` jQuery.get("test.css", null, function(data) { var comments = data.match(/\/\*.*\*\//g); for each (var c in comments) ...
401,681
<p>I am working on code generation and ran into a snag with generics. Here is a "simplified" version of what is causing me issues.</p> <pre><code>Dictionary&lt;string, DateTime&gt; dictionary = new Dictionary&lt;string, DateTime&gt;(); string text = dictionary.GetType().FullName; </code></pre> <p>With the above code ...
[ { "answer_id": 401697, "author": "Vilx-", "author_id": 41360, "author_profile": "https://Stackoverflow.com/users/41360", "pm_score": 0, "selected": false, "text": "<p>I don't think .NET has anything built-in that would do this, so you will have to do it yourself. I think that the reflect...
2008/12/30
[ "https://Stackoverflow.com/questions/401681", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30099/" ]
I am working on code generation and ran into a snag with generics. Here is a "simplified" version of what is causing me issues. ``` Dictionary<string, DateTime> dictionary = new Dictionary<string, DateTime>(); string text = dictionary.GetType().FullName; ``` With the above code snippet the value of `text` is as foll...
There is no built-in way to get this representation in the .Net Framework. Namely because there is no way to get it correct. There are a good number of constructs that are not representable in C# style syntax. For instance "<>foo" is a valid type name in IL but cannot be represented in C#. However, if you're looking ...
401,720
<p>In a project that I've been involved with for many years, I've gradually evolved a design pattern that's proven to be extremely useful for me. I sometimes feel I should get a bit evangelical with it, but I'd be a bit embarrassed if I tried and found out that it was just my version of somebody's old hat. I've dug t...
[ { "answer_id": 401734, "author": "duffymo", "author_id": 37213, "author_profile": "https://Stackoverflow.com/users/37213", "pm_score": 1, "selected": false, "text": "<p>Sounds like a combination of GoF Builder, Prototype, and maybe Featherweight to me.</p>\n" }, { "answer_id": 40...
2008/12/30
[ "https://Stackoverflow.com/questions/401720", "https://Stackoverflow.com", "https://Stackoverflow.com/users/47529/" ]
In a project that I've been involved with for many years, I've gradually evolved a design pattern that's proven to be extremely useful for me. I sometimes feel I should get a bit evangelical with it, but I'd be a bit embarrassed if I tried and found out that it was just my version of somebody's old hat. I've dug throug...
SingletonRegistry ----------------- Believe me or not. I was thinking the very same thing this morning. I have used this pattern before but I've never found a reference for it nor know how to name it. I think is a kind of "Keyed" singleton, where the instances are stored somewhere and they are obtained using a key....
401,740
<p>I'm currently using SMO and C# to traverse databases to create a tree of settings representing various aspects of the two databases, then comparing these trees to see where and how they are different.</p> <p>The problem is, for 2 reasonably sized database, it takes almost 10mins to crawl them locally and collect ta...
[ { "answer_id": 401769, "author": "Sam", "author_id": 37379, "author_profile": "https://Stackoverflow.com/users/37379", "pm_score": 2, "selected": false, "text": "<p>Use the system views in each database and query conventionally.</p>\n\n<p><a href=\"http://www.microsoft.com/downloads/deta...
2008/12/30
[ "https://Stackoverflow.com/questions/401740", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5965/" ]
I'm currently using SMO and C# to traverse databases to create a tree of settings representing various aspects of the two databases, then comparing these trees to see where and how they are different. The problem is, for 2 reasonably sized database, it takes almost 10mins to crawl them locally and collect table/column...
Try to force SMO to read all the required fields at once, instead of querying on access. See [this blog](http://davidhayden.com/blog/dave/archive/2006/03/29/2894.aspx) for more information --- EDIT: Link is dead but I found [the page](http://web.archive.org/web/20100102060107/http://davidhayden.com/blog/dave/archive/...
401,744
<p>I am using shared hosting with IIS7 and support for PHP. I am trying to run a wordpress blog with "pretty urls" (removing index.php). The hosting provider doesn't want to install the URLRewrite module, so that option isn't available to me. I found a plugin for wordpress that will remove the index.php from permalink ...
[ { "answer_id": 404252, "author": "Rob Boek", "author_id": 27179, "author_profile": "https://Stackoverflow.com/users/27179", "pm_score": 3, "selected": false, "text": "<p>I'm using the <strong><a href=\"http://www.managedfusion.com/products/url-rewriter/\" rel=\"nofollow noreferrer\" titl...
2008/12/30
[ "https://Stackoverflow.com/questions/401744", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8087/" ]
I am using shared hosting with IIS7 and support for PHP. I am trying to run a wordpress blog with "pretty urls" (removing index.php). The hosting provider doesn't want to install the URLRewrite module, so that option isn't available to me. I found a plugin for wordpress that will remove the index.php from permalink URL...
Thank you all for the suggestions. My host ended up installing [IIRF](http://www.codeplex.com/IIRF/Thread/View.aspx?ThreadId=39606) and it worked like a charm. There is a file called IsapiRewrite4.ini for the rewrite rules. In order to get my Wordpress install running without the index.php in the URL, all I had to do ...
401,747
<p>I got some legacy code that has this:</p> <pre><code>&lt;?PHP if(isset($_GET['pagina'])=="homepage") { ?&gt; HtmlCode1 &lt;?php } else { ?&gt; HtmlCode2 &lt;?php } ?&gt; </code></pre> <p>I don't know exactly why but this seems to be working. The htmlcode1 is loaded when I have ?pagina=homepage and the html...
[ { "answer_id": 401757, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "<p><code>isset()</code> returns true or false. In a boolean comparison, <code>\"homepage\"</code> would evaluate to <code>true...
2008/12/30
[ "https://Stackoverflow.com/questions/401747", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8715/" ]
I got some legacy code that has this: ``` <?PHP if(isset($_GET['pagina'])=="homepage") { ?> HtmlCode1 <?php } else { ?> HtmlCode2 <?php } ?> ``` I don't know exactly why but this seems to be working. The htmlcode1 is loaded when I have ?pagina=homepage and the htmlcode2 is loaded when the pagina var doesn't ...
The problem is that "==" isn't a type-sensitive comparison. Any (non-empty) string is "equal" to boolean true, but not **identical** to it (for that you need to use the "===" operator). A quick example, why you're seeing this behavior: [<http://codepad.org/aNh1ahu8>](http://codepad.org/aNh1ahu8) And for more detai...
401,748
<p>This problem seems to happen inconsistently. We are using a java applet to download a file from our site, which we store temporarily on the client's machine. </p> <p>Here is the code that we are using to save the file:</p> <pre><code>URL targetUrl = new URL(urlForFile); InputStream content = (InputStream)targetUr...
[ { "answer_id": 401785, "author": "Paul Tomblin", "author_id": 3333, "author_profile": "https://Stackoverflow.com/users/3333", "pm_score": 2, "selected": false, "text": "<p>I'm guessing that the operations you've done with getContent and BufferedInputStream have treated the file like an a...
2008/12/30
[ "https://Stackoverflow.com/questions/401748", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
This problem seems to happen inconsistently. We are using a java applet to download a file from our site, which we store temporarily on the client's machine. Here is the code that we are using to save the file: ``` URL targetUrl = new URL(urlForFile); InputStream content = (InputStream)targetUrl.getContent(); Buffer...
I'm guessing that the operations you've done with getContent and BufferedInputStream have treated the file like an ascii file which has converted newlines or carriage returns into carriage return + newline (0x0d0a), which has confused ObjectInputStream (which expects serialized data objects.
401,756
<p>I'm trying to parse some JSON using the JSon.Net library. The documentation seems a little sparse and I'm confused as to how to accomplish what I need. Here is the format for the JSON I need to parse through.</p> <pre><code>{ "displayFieldName" : "OBJECT_NAME", "fieldAliases" : { "OBJECT_NAME" : ...
[ { "answer_id": 401976, "author": "jarrodn", "author_id": 15273, "author_profile": "https://Stackoverflow.com/users/15273", "pm_score": 3, "selected": false, "text": "<p><strong>Edit:</strong> Thanks Marc, read up on the struct vs class issue and you're right, thank you!</p>\n\n<p>I tend ...
2008/12/30
[ "https://Stackoverflow.com/questions/401756", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49294/" ]
I'm trying to parse some JSON using the JSon.Net library. The documentation seems a little sparse and I'm confused as to how to accomplish what I need. Here is the format for the JSON I need to parse through. ``` { "displayFieldName" : "OBJECT_NAME", "fieldAliases" : { "OBJECT_NAME" : "OBJECT_NAME", ...
I don't know about JSON.NET, but it works fine with `JavaScriptSerializer` from `System.Web.Extensions.dll` (.NET 3.5 SP1): ``` using System.Collections.Generic; using System.Web.Script.Serialization; public class NameTypePair { public string OBJECT_NAME { get; set; } public string OBJECT_TYPE { get; set; } } ...
401,771
<p>I'm working with a MySQL database that has some data imported from <a href="http://en.wikipedia.org/wiki/Microsoft_Excel" rel="noreferrer">Excel</a>. The data contains non-<a href="http://en.wikipedia.org/wiki/ASCII" rel="noreferrer">ASCII</a> characters (em dashes, etc.) as well as hidden carriage returns or line f...
[ { "answer_id": 401819, "author": "Chad Birch", "author_id": 41665, "author_profile": "https://Stackoverflow.com/users/41665", "pm_score": 7, "selected": true, "text": "<p>It depends exactly what you're defining as \"ASCII\", but I would suggest trying a variant of a query like this:</p>\...
2008/12/30
[ "https://Stackoverflow.com/questions/401771", "https://Stackoverflow.com", "https://Stackoverflow.com/users/47166/" ]
I'm working with a MySQL database that has some data imported from [Excel](http://en.wikipedia.org/wiki/Microsoft_Excel). The data contains non-[ASCII](http://en.wikipedia.org/wiki/ASCII) characters (em dashes, etc.) as well as hidden carriage returns or line feeds. Is there a way to find these records using MySQL?
It depends exactly what you're defining as "ASCII", but I would suggest trying a variant of a query like this: ``` SELECT * FROM tableName WHERE columnToCheck NOT REGEXP '[A-Za-z0-9]'; ``` That query will return all rows where columnToCheck contains any non-alphanumeric characters. If you have other characters that ...
401,783
<p>Given the following Java code for generating a binary file:</p> <pre><code>DataOutputStream out = new DataOutputStream(new FileOutputStream("foo.dat")); out.writeInt(1234); out.writeShort(30000); out.writeFloat(256.384f); </code></pre> <p>I'm using the following Objective-C code and manage to parse the int and the...
[ { "answer_id": 401837, "author": "Kendall Helmstetter Gelner", "author_id": 6330, "author_profile": "https://Stackoverflow.com/users/6330", "pm_score": 2, "selected": false, "text": "<p>Sorry I can't provide the whole answer, but I can say the Java float is saved into the file as a four-...
2008/12/30
[ "https://Stackoverflow.com/questions/401783", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50335/" ]
Given the following Java code for generating a binary file: ``` DataOutputStream out = new DataOutputStream(new FileOutputStream("foo.dat")); out.writeInt(1234); out.writeShort(30000); out.writeFloat(256.384f); ``` I'm using the following Objective-C code and manage to parse the int and the short values: ``` NSStri...
Just us the functions and types provided by `<Foundation/Foundation.h>`. ``` NSSwappedFloat bigEndianFloat; memcpy(&bigEndianFloat, [[file readDataOfLength:4] bytes], 4); float floatValue = NSSwapBigFloatToHost(bigEndianFloat); ``` Note that they use a special type to hold the float before the bytes are swapped. Thi...
401,787
<p>How to scale the y-axis with <a href="http://matplotlib.sourceforge.net/" rel="nofollow noreferrer">Matplotlib</a>? I don't want to change the y-limit, I just want to extend the physical space.</p> <pre><code>^ ^ | | | | +----&gt; | Before +----&gt; After </code></pre>
[ { "answer_id": 401823, "author": "Autoplectic", "author_id": 49994, "author_profile": "https://Stackoverflow.com/users/49994", "pm_score": 4, "selected": true, "text": "<p>Just use a larger height value when you instantiate the figure:</p>\n\n<pre><code>from pylab import *\nx = linspace(...
2008/12/30
[ "https://Stackoverflow.com/questions/401787", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2007483/" ]
How to scale the y-axis with [Matplotlib](http://matplotlib.sourceforge.net/)? I don't want to change the y-limit, I just want to extend the physical space. ``` ^ ^ | | | | +----> | Before +----> After ```
Just use a larger height value when you instantiate the figure: ``` from pylab import * x = linspace(0, 10*pi, 2**10) y = sin(x) figure(figsize=(5, 10)) plot(x, y) show() ``` Where `figsize=(width, height)` and defaults to `(8, 6)`. Values are in inches (the `dpi` keyword arg can be used to define the [DPI](http://e...
401,812
<p>What is the proper way to cast from an 'OLE_HANDLE' to an 'HICON' for an x64 target build?</p> <p>In particular with a normal C-Style cast, I get this warning when compiling with an x64 config:</p> <p>warning C4312: 'type cast' : conversion from 'OLE_HANDLE' to 'HICON' of greater size</p> <p>Here is the offending...
[ { "answer_id": 401857, "author": "chaos", "author_id": 47529, "author_profile": "https://Stackoverflow.com/users/47529", "pm_score": 0, "selected": false, "text": "<pre><code>HICON hSomeIcon = (HICON) hSomeOLEHandle;\n</code></pre>\n\n<p>i.e. they're interchangeable.</p>\n" }, { ...
2008/12/30
[ "https://Stackoverflow.com/questions/401812", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3153/" ]
What is the proper way to cast from an 'OLE\_HANDLE' to an 'HICON' for an x64 target build? In particular with a normal C-Style cast, I get this warning when compiling with an x64 config: warning C4312: 'type cast' : conversion from 'OLE\_HANDLE' to 'HICON' of greater size Here is the offending code: ``` imgList.Ad...
The H gives it away, in this case the library code has created a distinct type to give you a little more type safety (in the days of old C APIs). They are actually both HANDLEs, which is a kernel object that doesn't really care what the resource is, just that you have a 'handle' to it. Remember the API is a C one, so ...
401,816
<p>How can I make a Click-once deployed app run a startup?</p> <p>The best option I found by searching was to set the Publisher on the app to Startup, so the Start menu shortcut would be placed in the Startup folder, but that seems like a huge hack and I would like there to be a Start menu icon people can find.</p> <...
[ { "answer_id": 401835, "author": "JaredPar", "author_id": 23283, "author_profile": "https://Stackoverflow.com/users/23283", "pm_score": 1, "selected": false, "text": "<p>In terms of actually getting the application to launch at startup, having a link in the startup folder is your best be...
2008/12/30
[ "https://Stackoverflow.com/questions/401816", "https://Stackoverflow.com", "https://Stackoverflow.com/users/100/" ]
How can I make a Click-once deployed app run a startup? The best option I found by searching was to set the Publisher on the app to Startup, so the Start menu shortcut would be placed in the Startup folder, but that seems like a huge hack and I would like there to be a Start menu icon people can find. What options do...
I feel that adding your application to the startup folder is unprofessional. I strongly recommend using a startup registry key to launch your application. Contrary to what a lot of the material on this topic says, it is extremely simple to setup a key to launch a click once application and does not require setting up...
401,820
<p>Is it possible not to use web service for ASP.net ajax instead call code-behind function to fetch data?</p> <p>any example or link is much appericate.</p>
[ { "answer_id": 401835, "author": "JaredPar", "author_id": 23283, "author_profile": "https://Stackoverflow.com/users/23283", "pm_score": 1, "selected": false, "text": "<p>In terms of actually getting the application to launch at startup, having a link in the startup folder is your best be...
2008/12/30
[ "https://Stackoverflow.com/questions/401820", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28647/" ]
Is it possible not to use web service for ASP.net ajax instead call code-behind function to fetch data? any example or link is much appericate.
I feel that adding your application to the startup folder is unprofessional. I strongly recommend using a startup registry key to launch your application. Contrary to what a lot of the material on this topic says, it is extremely simple to setup a key to launch a click once application and does not require setting up...
401,834
<p>Arising out of <a href="https://stackoverflow.com/questions/401467/how-to-reduce-the-size-of-an-sqlite3-database-for-iphone">this</a> question, I'm looking for an elegant (ruby) way to compute the word signature suggested in <a href="https://stackoverflow.com/questions/401467/how-to-reduce-the-size-of-an-sqlite3-dat...
[ { "answer_id": 401848, "author": "Robert Simmons", "author_id": 18951, "author_profile": "https://Stackoverflow.com/users/18951", "pm_score": 4, "selected": true, "text": "<p>I'm not much of a Ruby person either, but as I noted on the other comment this seems to work for the algorithm de...
2008/12/30
[ "https://Stackoverflow.com/questions/401834", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42404/" ]
Arising out of [this](https://stackoverflow.com/questions/401467/how-to-reduce-the-size-of-an-sqlite3-database-for-iphone) question, I'm looking for an elegant (ruby) way to compute the word signature suggested in [this](https://stackoverflow.com/questions/401467/how-to-reduce-the-size-of-an-sqlite3-database-for-iphone...
I'm not much of a Ruby person either, but as I noted on the other comment this seems to work for the algorithm described. ``` s = "mississippi" s.split('').sort.join.gsub(/(.)\1{2,}/) { |s| s.length.to_s + s[0,1] } ``` Of course, you'll want to make sure the word is lowercase, doesn't contain numbers, etc. As requ...
401,847
<p>How can I tell whether a circle and a rectangle intersect in 2D Euclidean space? (i.e. classic 2D geometry)</p>
[ { "answer_id": 401859, "author": "ForYourOwnGood", "author_id": 48728, "author_profile": "https://Stackoverflow.com/users/48728", "pm_score": -1, "selected": false, "text": "<p>Assuming you have the four edges of the rectangle check the distance from the edges to the center of the circle...
2008/12/30
[ "https://Stackoverflow.com/questions/401847", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1088/" ]
How can I tell whether a circle and a rectangle intersect in 2D Euclidean space? (i.e. classic 2D geometry)
There are only two cases when the circle intersects with the rectangle: * Either the circle's centre lies inside the rectangle, or * One of the edges of the rectangle has a point in the circle. Note that this does not require the rectangle to be axis-parallel. [![Some different ways a circle and rectangle may inter...
401,851
<p>I'm working with a group of other programmers on an open source project built using C++ and Qt.</p> <p>Now, we need a naming convention for widgets (and other variables generally) to use it as a standard in all of our code so that, the code gets better readability and we get better coordination between programmers....
[ { "answer_id": 402347, "author": "Mark Beckwith", "author_id": 45799, "author_profile": "https://Stackoverflow.com/users/45799", "pm_score": 1, "selected": false, "text": "<p>I would just use the same naming convention that Qt uses. Make it easy for yourself. </p>\n\n<p>Their naming co...
2008/12/30
[ "https://Stackoverflow.com/questions/401851", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49217/" ]
I'm working with a group of other programmers on an open source project built using C++ and Qt. Now, we need a naming convention for widgets (and other variables generally) to use it as a standard in all of our code so that, the code gets better readability and we get better coordination between programmers. Any advi...
As long as you are thinking along these lines, I'd start by reading this QtQuarterly article from start-to-finish. [Designing Qt-Style C++ APIs](https://doc.qt.io/archives/qq/qq13-apis.html) That said, one thing that we do is to put the "use" of the instance as the first part and the last full word of the class as th...