qid int64 4 22.2M | question stringlengths 18 48.3k | answers list | date stringlengths 10 10 | metadata list |
|---|---|---|---|---|
337,856 | <p>I have an Asp.net Mvc site where I want to give a separate access and user interface to different clients like:
<a href="http://company1.mysite.com" rel="nofollow noreferrer">http://company1.mysite.com</a><br>
<a href="http://company2.mysite.com" rel="nofollow noreferrer">http://company2.mysite.com</a><br>
<a href="http://company3.mysite.com" rel="nofollow noreferrer">http://company3.mysite.com</a> </p>
<p>Each client will have a different ui but practically same functionality (or with some features disabled).<br>
I'd like to separate graphics for each client like logo, css and images.</p>
<p>How would be the the best way to implement that?</p>
| [
{
"answer_id": 337862,
"author": "Eduardo Molteni",
"author_id": 2385,
"author_profile": "https://Stackoverflow.com/users/2385",
"pm_score": 0,
"selected": false,
"text": "If Company = A then\n UseFunctionX = true\nelse\n UseFunctionX = false\n\n//later in the code\nIf UseFunctionX t... | 2008/12/03 | [
"https://Stackoverflow.com/questions/337856",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1929/"
] |
337,863 | <p>I run a subprocess using:</p>
<pre><code> p = subprocess.Popen("subprocess",
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=subprocess.PIPE)
</code></pre>
<p>This subprocess could either exit immediately with an error on stderr, or keep running. I want to detect either of these conditions - the latter by waiting for several seconds.</p>
<p>I tried this:</p>
<pre><code> SECONDS_TO_WAIT = 10
select.select([],
[p.stdout, p.stderr],
[p.stdout, p.stderr],
SECONDS_TO_WAIT)
</code></pre>
<p>but it just returns:</p>
<pre><code> ([],[],[])
</code></pre>
<p>on either condition. What can I do?</p>
| [
{
"answer_id": 337912,
"author": "grieve",
"author_id": 34329,
"author_profile": "https://Stackoverflow.com/users/34329",
"pm_score": 4,
"selected": false,
"text": "p = subprocess.Popen(\"subprocess\", \n stdout=subprocess.PIPE, \n stderr=subprocess.PI... | 2008/12/03 | [
"https://Stackoverflow.com/questions/337863",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
337,868 | <p>In short, I'd like to learn/develop an elegant method to save a binary tree to disk (a general tree, not necessarily a BST). Here is the description of my problem:</p>
<p>I'm implementing a game of "20-questions". I've written a binary tree whose internal nodes are questions and leaves are answers. The left child of a node is the path you'd follow if somebody answered "yes" to your current question, while the right child is a "no" answer. Note this is not a binary <em>search</em> tree, just a binary tree whose left child is "yes" and right is "no".</p>
<p>The program adds a node to a tree if it encounters a leaf that is null by asking the user to distinguish her answer from the one the computer was thinking of.</p>
<p>This is neat, because the tree builds itself up as the user plays. What's not neat is that I don't have a good way of saving the tree to disk.</p>
<p>I've thought about saving the tree as an array representation (for node i, left child is 2i+1, and 2i+2 right, (i-1)/2 for parent), but it's not clean and I end up with a lot of wasted space.</p>
<p>Any ideas for an elegant solution to saving a sparse binary tree to disk?</p>
| [
{
"answer_id": 337874,
"author": "Brian R. Bondy",
"author_id": 3153,
"author_profile": "https://Stackoverflow.com/users/3153",
"pm_score": 3,
"selected": false,
"text": "F\n"
},
{
"answer_id": 337921,
"author": "Skizz",
"author_id": 1898,
"author_profile": "https://S... | 2008/12/03 | [
"https://Stackoverflow.com/questions/337868",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42897/"
] |
337,870 | <p>I have some Python code that works correctly when I use python.exe to run it, but fails if I use pythonw.exe.</p>
<pre>
def runStuff(commandLine):
outputFileName = 'somefile.txt'
outputFile = open(outputFileName, "w")
try:
result = subprocess.call(commandLine, shell=True, stdout=outputFile)
except:
print 'Exception thrown:', str(sys.exc_info()[1])
myThread = threading.Thread(None, target=runStuff, commandLine=['whatever...'])
myThread.start()
</pre>
<p>The message I get is:</p>
<pre>
Exception thrown: [Error 6] The handle is invalid
</pre>
<p>However, if I don't specify the 'stdout' parameter, subprocess.call() starts okay.</p>
<p>I can see that pythonw.exe might be redirecting output itself, but I can't see why I'm blocked from specifying stdout for a new thread.</p>
| [
{
"answer_id": 337990,
"author": "Piotr Lesnicki",
"author_id": 38796,
"author_profile": "https://Stackoverflow.com/users/38796",
"pm_score": 4,
"selected": true,
"text": "sys.stdin"
},
{
"answer_id": 386343,
"author": "Charles Anderson",
"author_id": 11677,
"author_p... | 2008/12/03 | [
"https://Stackoverflow.com/questions/337870",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11677/"
] |
337,878 | <p>Using instance methods as callbacks for event handlers changes the scope of <code>this</code> from <em>"My instance"</em> to <em>"Whatever just called the callback"</em>. So my code looks like this</p>
<pre><code>function MyObject() {
this.doSomething = function() {
...
}
var self = this
$('#foobar').bind('click', function(){
self.doSomethng()
// this.doSomething() would not work here
})
}
</code></pre>
<p>It works, but is that the best way to do it? It looks strange to me.</p>
| [
{
"answer_id": 337923,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "doSomething"
},
{
"answer_id": 337926,
"author": "BenAlabaster",
"author_id": 40650,
"author_profile": "ht... | 2008/12/03 | [
"https://Stackoverflow.com/questions/337878",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/407880/"
] |
337,891 | <p>I've a couple of extension methods I've been developing for a couple of projects, they currently rely heavily on some AJAX to make bits and pieces work. The problem is that they require copying and pasting JavaScript files to the project you want to use it in.</p>
<p>As this JavaScript file only needs to be used once (all instances of the rendered control use the same file) I'd like to do something like add the script element to the headers collection of the page it's used on via a web-resource (embedding the file as a resource in the assembly). In Web-forms this wasn't a problem - you could add a script block to the headers with a specific ID and simply check for it on page load.</p>
<p>What's the MVC equivalent - is there an equivalent?</p>
<p>I'd like a solution that doesn't require the consumer to copy and paste/ add lines to pages or config...any thoughts?</p>
| [
{
"answer_id": 337923,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "doSomething"
},
{
"answer_id": 337926,
"author": "BenAlabaster",
"author_id": 40650,
"author_profile": "ht... | 2008/12/03 | [
"https://Stackoverflow.com/questions/337891",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5791/"
] |
337,903 | <p>exampl:</p>
<pre><code>new Thread(new Runnable() {
public void run() {
while(condition) {
*code that must not be interrupted*
*some more code*
}
}
}).start();
SomeOtherThread.start();
YetAntherThread.start();
</code></pre>
<p>How can you ensure that <em>code that must not be interrupted</em> won't be interrupted?</p>
| [
{
"answer_id": 338015,
"author": "Chris Conway",
"author_id": 1412,
"author_profile": "https://Stackoverflow.com/users/1412",
"pm_score": 2,
"selected": false,
"text": "ReadWriteLock"
},
{
"answer_id": 338694,
"author": "OscarRyz",
"author_id": 20654,
"author_profile"... | 2008/12/03 | [
"https://Stackoverflow.com/questions/337903",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
337,918 | <p>I have a nightly batch job that can tell if it has failed. I want it to send me an email, possibly with an attachment when it does. </p>
<p>How can I send an email from a Windows Batch (.bat) file?</p>
| [
{
"answer_id": 337955,
"author": "Svante Svenson",
"author_id": 19707,
"author_profile": "https://Stackoverflow.com/users/19707",
"pm_score": 3,
"selected": true,
"text": "echo From: test@example.com>tmp.txt\necho To: test@example.com>>tmp.txt\necho Subject: hello>>tmp.txt\necho.>>tmp.tx... | 2008/12/03 | [
"https://Stackoverflow.com/questions/337918",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20553/"
] |
337,925 | <p>I'm just wondering how other developers tackle this issue of getting 2 or 3 answers from a method.</p>
<p>1) return a object[]<br>
2) return a custom class<br>
3) use an out or ref keyword on multiple variables<br>
4) write or borrow (F#) a simple Tuple<> generic class<br>
<a href="http://slideguitarist.blogspot.com/2008/02/whats-f-tuple.html" rel="nofollow noreferrer">http://slideguitarist.blogspot.com/2008/02/whats-f-tuple.html</a> </p>
<p>I'm working on some code now that does data refreshes. From the method that does the refresh I would like to pass back (1) Refresh Start Time and (2) Refresh End Time.<br>
At a later date I may want to pass back a third value.</p>
<p>Thoughts? Any good practices from open source .NET projects on this topic?</p>
| [
{
"answer_id": 338528,
"author": "Daniel Earwicker",
"author_id": 27423,
"author_profile": "https://Stackoverflow.com/users/27423",
"pm_score": 1,
"selected": false,
"text": "KeyValuePair"
}
] | 2008/12/03 | [
"https://Stackoverflow.com/questions/337925",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36590/"
] |
337,942 | <p>It should be easy, right?
Have a listview, add an imagelist, add images to the imagelist, assign image index to the column you want.<br>
But, it doesn't work.<br>
<a href="http://support.microsoft.com/kb/314933" rel="nofollow noreferrer">Microsoft article</a> states that it is a known problem in .NET 1.1.<br>
But has it been fixed since?</p>
| [
{
"answer_id": 338528,
"author": "Daniel Earwicker",
"author_id": 27423,
"author_profile": "https://Stackoverflow.com/users/27423",
"pm_score": 1,
"selected": false,
"text": "KeyValuePair"
}
] | 2008/12/03 | [
"https://Stackoverflow.com/questions/337942",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28098/"
] |
337,986 | <p>I am from a c# background and am converting a vb.net windows forms app to c#.
I have a windows form called associateForm.
In code the developer references associate form like so:-</p>
<pre><code>Private Sub NotifyIcon1_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles EMS.MouseDoubleClick
If e.Button = Windows.Forms.MouseButtons.Left Then
If associateForm.WindowState = FormWindowState.Normal And associateForm.Visible = True Then
associateForm.WindowState = FormWindowState.Minimized
Else
associateForm.WindowState = FormWindowState.Normal
End If
associateForm.Show()
associateForm.Focus()
'bring to front of other windows
associateForm.Activate()
End If
End Sub
</code></pre>
<p>But the thing is that associateForm is not instantiated within the class where the method is being executed. Nor is the class static. Nor does there seem to be an instance of the class anywhere in code. Can anyone shine any light on why this seems to work but when i try this in C# it is not having any of it.</p>
| [
{
"answer_id": 338383,
"author": "Konrad Rudolph",
"author_id": 1968,
"author_profile": "https://Stackoverflow.com/users/1968",
"pm_score": 2,
"selected": false,
"text": "My.Forms.Formname"
}
] | 2008/12/03 | [
"https://Stackoverflow.com/questions/337986",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35441/"
] |
337,987 | <p>I'm still fairly new to ASP.NET development so bear with me.</p>
<p>I'm going to start development on an updated version of an ASP.NET 1.1 website, which I will develop in ASP.NET 3.5. Currently, my development server allows me to run web sites on 1.1 and 2.0. I've had the 3.5 framework installed, but is there any other configuring/issues I should know about? This server will need to keep running the ASP.NET 1.1 web site alongside the 3.5 one I will be developing.</p>
<p>Thanks in advance.</p>
<p>EDIT: Although I have .NET 3.5 framework installed, when I go into IIS and create a new Virtual Directory, it only gives me the options of 1.1 or 2.0.</p>
| [
{
"answer_id": 338383,
"author": "Konrad Rudolph",
"author_id": 1968,
"author_profile": "https://Stackoverflow.com/users/1968",
"pm_score": 2,
"selected": false,
"text": "My.Forms.Formname"
}
] | 2008/12/03 | [
"https://Stackoverflow.com/questions/337987",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32432/"
] |
337,995 | <p>I often find that I do a less than complete work on a feature, especially in the Design phase. I detect several reasons:</p>
<ol>
<li>I'm over-optimistic</li>
<li>I feel the need to provide quick solutions, so sometimes I fool myself into thinking the design is fool-proof when in fact it's still full of holes, just to get the job done faster. Of course I end up paying dearly later.</li>
</ol>
<p>I'm aware of this behavior of mine for some time, yet I still find I don't manage to compensate. Have you encountered similar problems? How do you approach solving them?</p>
| [
{
"answer_id": 338094,
"author": "BIBD",
"author_id": 685,
"author_profile": "https://Stackoverflow.com/users/685",
"pm_score": 0,
"selected": false,
"text": "for (i=1; i<=10; i++) {} \n"
}
] | 2008/12/03 | [
"https://Stackoverflow.com/questions/337995",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11236/"
] |
338,024 | <p>I can remember <em>Convert</em> class in .net which is named not in accordance with the guide lines. Any more examples?</p>
| [
{
"answer_id": 338042,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 3,
"selected": true,
"text": "java.lang.System.arraycopy"
},
{
"answer_id": 338096,
"author": "Chris Cudmore",
"author_id": 18907,
... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338024",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/38807/"
] |
338,026 | <p>I want to read a string value from the registry and concatenate it with another certain string. I'm calling RegQueryValueEx() , like this: </p>
<pre><code>Dim lResult As Long
Dim sLength As Long
Dim sString As String
sString = Space$(256)
sLength = 256
lResult = RegQueryValueEx(hKey, "MyKey", 0, REG_SZ, ByVal sString, sLength)
MsgBox sString & "blah-blah-blah"
</code></pre>
<p>RegQueryValueEx() works fine, I'm getting the needed string in sString and even can display it with MsgBox. But when I try to concat it with "some_string" I get only sString showed. Plz, help me.</p>
<p>Thanks</p>
| [
{
"answer_id": 338055,
"author": "nobody",
"author_id": 19405,
"author_profile": "https://Stackoverflow.com/users/19405",
"pm_score": 1,
"selected": false,
"text": "MsgBox(sString & \"blah-blah-blah\")\n"
},
{
"answer_id": 338127,
"author": "Will Rickards",
"author_id": 2... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338026",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
338,037 | <p>I know that using <code>ls -l "directory/directory/filename"</code> tells me the permissions of a file. How do I do the same on a directory?</p>
<p>I could obviously use <code>ls -l</code> on the directory higher in the hierarchy and then just scroll till I find it but it's such a pain. If I use <code>ls -l</code> on the actual directory, it gives the permissions/information of the files inside of it, and not of the actual directory.</p>
<p>I tried this in the terminal of both Mac OS X 10.5 and Linux (Ubuntu Gutsy Gibbon), and it's the same result. Is there some sort of flag I should be using?</p>
| [
{
"answer_id": 338041,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 9,
"selected": false,
"text": "$ ls -ld directory\n"
},
{
"answer_id": 338062,
"author": "Piotr Lesnicki",
"author_id": 38... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338037",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42228/"
] |
338,044 | <p>Say I have two tables, a master list of students containing personal info, and a list of student enrollments in classes. The two tables share a common column, which is a string uniquely identifying the student, but it is not the primary key. </p>
<p>Say I want to display all the enrollments on a page, along with some of the personal data from the student (say perhaps hometown). </p>
<p>I understand that it would be a has_many relationship. The master list record has many enrollments. An enrollment belongs to a student.</p>
<pre><code>class Student < ActiveRecord::Base
has_many :enrollments
end
class Enrollment < ActiveRecord::Base
belongs_to :student
end
</code></pre>
<p>Is this the correct relationship between the two, and if so, how do I do a join query against the shared column?</p>
| [
{
"answer_id": 338165,
"author": "mwilliams",
"author_id": 23909,
"author_profile": "https://Stackoverflow.com/users/23909",
"pm_score": 3,
"selected": false,
"text": "Student table:\n- id\n\nEnrollment table:\n- student_id\n"
},
{
"answer_id": 339291,
"author": "Tim Knight",... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338044",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42914/"
] |
338,056 | <p>I have resource dictionary files (MenuTemplate.xaml, ButtonTemplate.xaml, etc) that I want to use in multiple separate applications. I could add them to the applications' assemblies, but it's better if I compile these resources in one single assembly and have my applications reference it, right? </p>
<p>After the resource assembly is built, how can I reference it in the App.xaml of my applications? Currently I use ResourceDictionary.MergedDictionaries to merge the individual dictionary files. If I have them in an assembly, how can I reference them in xaml?</p>
| [
{
"answer_id": 338546,
"author": "Kent Boogaart",
"author_id": 5380,
"author_profile": "https://Stackoverflow.com/users/5380",
"pm_score": 10,
"selected": true,
"text": "<ResourceDictionary Source=\"pack://application:,,,/YourAssembly;component/Subfolder/YourResourceFile.xaml\"/>\n"
},... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338056",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28029/"
] |
338,063 | <p>I have PDF documents from a scanner. This PDF contain forms filled out and signed by staff for a days work. I want to place a bar code or standard area for OCR text on every form type so the batch scan can be programatically broken apart into separate PDF document based on form type. </p>
<p>I would like to do this in Microsoft .net 2.0</p>
<p>I can purchase the require Adobe or other namespaces/dll need to accomplish the task if there are no open source namespaces/dll's available.</p>
| [
{
"answer_id": 338411,
"author": "joshperry",
"author_id": 30587,
"author_profile": "https://Stackoverflow.com/users/30587",
"pm_score": 1,
"selected": false,
"text": "string filePath = @\"c:\\file.pdf\";\n\nusing (PdfDocument ipdf = PdfReader.Open(filePath, PdfDocumentOpenMode.ReadOnly)... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338063",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
338,075 | <p>Why would the following query return "Error converting data type varchar to bigint"? Doesn't IsNumeric make the CAST safe? I've tried every numeric datatype in the cast and get the same "Error converting..." error. I don't believe the size of the resulting number is a problem because overflow is a different error.</p>
<p>The interesting thing is, in management studio, the results actually show up in the results pane for a split second before the error comes back.</p>
<pre><code>SELECT CAST(myVarcharColumn AS bigint)
FROM myTable
WHERE IsNumeric(myVarcharColumn) = 1 AND myVarcharColumn IS NOT NULL
GROUP BY myVarcharColumn
</code></pre>
<p>Any thoughts?</p>
| [
{
"answer_id": 338098,
"author": "Kevin Fairchild",
"author_id": 3743,
"author_profile": "https://Stackoverflow.com/users/3743",
"pm_score": 3,
"selected": false,
"text": "SELECT CAST(CASE \n WHEN IsNumeric(myVarcharColumn) = 0\n THEN 0\n ELSE myVarch... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338075",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22355/"
] |
338,101 | <p>Not many are aware of this feature, but Python's functions (and methods) can have <a href="http://www.python.org/dev/peps/pep-0232/" rel="noreferrer">attributes</a>. Behold:</p>
<pre><code>>>> def foo(x):
... pass
...
>>> foo.score = 10
>>> dir(foo)
['__call__', '__class__', '__delattr__', '__dict__', '__doc__', '__get__', '__getattribute__', '__hash__', '__init__', '__module__', '__name__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', 'func_closure', 'func_code', 'func_defaults', 'func_dict', 'func_doc', 'func_globals', 'func_name', 'score']
>>> foo.score
10
>>> foo.score += 1
>>> foo.score
11
</code></pre>
<p>What are the possible uses and abuses of this feature in Python ? One good use I'm aware of is <a href="http://www.dabeaz.com/ply/" rel="noreferrer">PLY</a>'s usage of the docstring to associate a syntax rule with a method. But what about custom attributes ? Are there good reasons to use them ?</p>
| [
{
"answer_id": 338145,
"author": "Martin v. Löwis",
"author_id": 33006,
"author_profile": "https://Stackoverflow.com/users/33006",
"pm_score": 8,
"selected": true,
"text": "class Foo(WebService):\n @webmethod\n def bar(self, arg1, arg2):\n ...\n"
},
{
"answer_id": 3... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338101",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8206/"
] |
338,103 | <p>I'm running Emacs 22.1.1 and IPython 0.9.1 on OS X and I'd like to be able to run lines/methods/snippets of Python code from my current buffer on demand inside an IPython interpreter.</p>
<p>What do I need to do to get this working?</p>
| [
{
"answer_id": 26383574,
"author": "yeeking",
"author_id": 1240660,
"author_profile": "https://Stackoverflow.com/users/1240660",
"pm_score": 2,
"selected": false,
"text": "(setq package-archives '((\"gnu\" . \"http://elpa.gnu.org/packages/\")\n (\"marmalade\" . \"http... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338103",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1512/"
] |
338,110 | <p>My users are presented a basically a stripped down version of a spreadsheet. There are textboxes in each row in the grid. When they change a value in a textbox, I'm performing validation on their input, updating the collection that's driving the grid, and redrawing the subtotals on the page. This is all handled by the <code>OnChange</code> event of each textbox.</p>
<p>When they click the <kbd>Save</kbd> button, I'm using the button's <code>OnClick</code> event to perform some final validation on the amounts, and then send their entire input to a web service, saving it.</p>
<p>At least, that's what happens if they tab through the form to the <kbd>Submit</kbd> button.</p>
<p>The problem is, if they enter a value, then immediately click the save button, <code>SaveForm()</code> starts executing before <code>UserInputChanged()</code> completes -- a race condition. My code does not use <code>setTimeout</code>, but I'm using it to simulate the sluggish <code>UserInputChanged</code> validation code:</p>
<pre><code> <script>
var amount = null;
var currentControl = null;
function UserInputChanged(control) {
currentControl = control;
// use setTimeout to simulate slow validation code
setTimeout(ValidateAmount, 100);
}
function SaveForm() {
// call web service to save value
document.getElementById("SavedAmount").innerHTML = amount;
}
function ValidateAmount() {
// various validationey functions here
amount = currentControl.value; // save value to collection
document.getElementById("Subtotal").innerHTML = amount;
}
</script>
Amount: <input type="text" onchange="UserInputChanged(this)">
Subtotal: <span id="Subtotal"></span>
<button onclick="SaveForm()">Save</button>
Saved amount: <span id="SavedAmount"></span>
</code></pre>
<p>I don't think I can speed up the validation code -- it's pretty lightweight, but apparently, slow enough that code tries to call the web service before the validation is complete.</p>
<p>On my machine, ~95ms is the magic number between whether the validation code executes before the save code begins. This may be higher or lower depending on the users' computer speed.</p>
<p>Does anyone have any ideas how to handle this condition? A coworker suggested using a semaphore while the validation code is running and a busy loop in the save code to wait until the semaphore unlocks - but I'd like to avoid using any sort of busy loop in my code.</p>
| [
{
"answer_id": 338151,
"author": "zaratustra",
"author_id": 39702,
"author_profile": "https://Stackoverflow.com/users/39702",
"pm_score": 6,
"selected": true,
"text": "function UserInputChanged(control) {\n StillNeedsValidating = true;\n // do validation\n StillNeedsValidating =... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338110",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13412/"
] |
338,111 | <p>The <a href="http://msdn.microsoft.com/en-us/vcsharp/aa336809.aspx" rel="nofollow noreferrer">C# 3.0 spec</a> has the following code example in section 10.6.1.3 "Output parameters":</p>
<pre><code>using System;
class Test
{
static void SplitPath(string path, out string dir, out string name) {
int i = path.Length;
while (i > 0) {
char ch = path[i – 1];
if (ch == '\\' || ch == '/' || ch == ':') break;
i--;
}
dir = path.Substring(0, i);
name = path.Substring(i);
}
static void Main() {
string dir, name;
SplitPath("c:\\Windows\\System\\hello.txt", out dir, out name);
Console.WriteLine(dir);
Console.WriteLine(name);
}
}
</code></pre>
<p>I cannot get this code to compile in VS2005/C#2.0. Did the behavior of strings in C# 3.0 change so that a string can be referred as a char[] array without explicitly converting it (the statement "ch = path[i - 1]")?</p>
| [
{
"answer_id": 338138,
"author": "BenAlabaster",
"author_id": 40650,
"author_profile": "https://Stackoverflow.com/users/40650",
"pm_score": 0,
"selected": false,
"text": "char ch = path[i - 1];\n"
}
] | 2008/12/03 | [
"https://Stackoverflow.com/questions/338111",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42439/"
] |
338,156 | <p>Academia has it that table names should be the singular of the entity that they store attributes of. </p>
<p>I dislike any T-SQL that requires square brackets around names, but I have renamed a <code>Users</code> table to the singular, forever sentencing those using the table to sometimes have to use brackets. </p>
<p>My gut feel is that it is more correct to stay with the singular, but my gut feel is also that brackets indicate undesirables like column names with spaces in them etc.</p>
<p>Should I stay, or should I go?</p>
| [
{
"answer_id": 338421,
"author": "stephbu",
"author_id": 12702,
"author_profile": "https://Stackoverflow.com/users/12702",
"pm_score": 4,
"selected": false,
"text": "SELECT [Name] FROM [dbo].[Customer] WHERE [Location] = 'WA'\n"
},
{
"answer_id": 338431,
"author": "Eugene Yok... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338156",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8741/"
] |
338,164 | <p>When running get svn fetch to pull the latest new branches from the upstream svn repository I got this error:</p>
<pre><code>$ git svn fetch
fatal: failed to unpack tree object 5ecb324e8b8fcb918acb253f33edc6ce49e49e0d
read-tree 5ecb324e8b8fcb918acb253f33edc6ce49e49e0d: command returned error: 128
</code></pre>
<p>Now every attempt at git svn on that local repo results in the same error. Originally I was running git version 1.5.6.4_0 and after the error I tried updating to 1.6.0.2_2 and the problem still persists.</p>
<p>Is there any way to clean up this corruption? A fresh git svn clone of the upstream repository is fine, but I'd like to preserve my existing setup. I've looked through the docs and googled for the problem with no luck.</p>
| [
{
"answer_id": 344837,
"author": "Paul",
"author_id": 23356,
"author_profile": "https://Stackoverflow.com/users/23356",
"pm_score": 2,
"selected": false,
"text": "git fsck --unreachable HEAD $(cat .git/refs/heads/*)\n"
},
{
"answer_id": 4504577,
"author": "David Ammouial",
... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338164",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42927/"
] |
338,166 | <p>In a sorted table, it's common to have an up or a down arrow indicating the sort style. However, I'm having some trouble determining which direction the arrow should point. In an ASC sort, characters are sorted 1-9A-Za-z. Should the arrow point up or down?</p>
<p>I've found implementations of both on the web, so that didn't help me much: <a href="http://yoast.com/articles/sortable-table/" rel="noreferrer">Up</a> and <a href="http://www.frequency-decoder.com/demo/table-sort-revisited/dynamic/" rel="noreferrer">Down</a> (you have to create the table first).</p>
<p>Is there a hard and fast rule for this? I find myself able to justify both implementations. Which method do you use? Which is more intuitive to you and why?</p>
<p><strong>Edit:</strong> Some of you have suggested alternate implementations like rising bars or having letters with an arrow indicating sort direction. Great suggestions. I'm definitely open to other options. The less ambiguous, the better. It might be picky, but I'd really like there to be minimal or no confusion on the part of the user.</p>
<p><strong>Edit:</strong> I ended up going with the rising and falling bars for now. It's not standard, but seems less ambiguous than the triangles. The current sort column shows three bars, small to large (left to right) for ASC, the opposite for DESC. Other sortable columns have no bars by default, but hovering over any sortable column heading (including the current) shows bars depicting how the table will be sorted if that column heading is clicked.</p>
| [
{
"answer_id": 338272,
"author": "Coderer",
"author_id": 26286,
"author_profile": "https://Stackoverflow.com/users/26286",
"pm_score": 3,
"selected": false,
"text": "A |\nZ V\n"
}
] | 2008/12/03 | [
"https://Stackoverflow.com/questions/338166",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13281/"
] |
338,185 | <p>I have an Excel table with several items 1, 2, 3..., each of which has subitems 1.1, 1.2, etc. I'm using the list of subitems as my key column and populating the main items using vlookups, but only showing each main item once.</p>
<pre><code>/| A | B | C |
-+---------+----------+----------+
1| Item1 | 1.Note | Item1.1 |
2| | | Item1.2 |
3| | | Item1.3 |
4| Item2 | 2.Note | Item2.1 |
5| | | Item2.2 |
6| | | Item2.3 |
7| | | Item2.4 |
8| Item3 | 3.Note | Item3.1 |
9| | | Item3.2 |
0| | | Item3.3 |
</code></pre>
<p>Column <code>C</code> is raw data; <code>A</code> and <code>B</code> are formulas.</p>
<p>Column <code>B</code> has notes, so the text may be long. I want to wrap the notes to take up all the rows available. I can do this manually by selecting <code>B1:B3</code> and merging them, but then it won't update if I add items to column <code>C</code>.</p>
<p>I don't care if the cells are merged or just wrapped and overlapping.</p>
<p>Can this be done in formulas or VBA?</p>
| [
{
"answer_id": 338564,
"author": "Jon Fournier",
"author_id": 5106,
"author_profile": "https://Stackoverflow.com/users/5106",
"pm_score": 0,
"selected": false,
"text": "Private Sub AutoMerge()\n\nDim LastRowToMergeTo As Long\nDim i As Long\nDim LastRow As Long\n\nLastRow = Range(\"C\" & ... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338185",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
338,195 | <p>According to <em>Cocoa Programming for Mac OS X, 3rd Edition,</em> on page 202 (chapter 13):</p>
<blockquote>
<p>You will be registering, reading, and
setting defaults in several classes in
your application. To make sure that
you always use the same name, you
should declare those strings in a
single file and then simply #import
that file into any file in which you
use the names. There are several ways
to do this. For example, you could use
the C preprocessor’s #define command,
but most Cocoa programmers use global
variables for this purpose.</p>
</blockquote>
<p>Is this really the correct best practice? Global variables? That seems insane to me – counter to everything I’ve ever been taught.</p>
<p>Would a better design be a simple Singleton class with these defined? Or is it really the correct best practice to go global? Is there a better pattern than either, given that many people consider Singletons to be globals in a pretty dress?</p>
| [
{
"answer_id": 338214,
"author": "Grant Limberg",
"author_id": 27314,
"author_profile": "https://Stackoverflow.com/users/27314",
"pm_score": 5,
"selected": true,
"text": "[myArray setObject:theObject forKey:MyGlobalVariableKeyName];\n"
},
{
"answer_id": 339153,
"author": "Mat... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338195",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14048/"
] |
338,206 | <p>Is this functionality going to be put into a later Java version?</p>
<p>Can someone explain why I can't do this, as in, the technical way Java's <code>switch</code> statement works?</p>
| [
{
"answer_id": 338230,
"author": "erickson",
"author_id": 3474,
"author_profile": "https://Stackoverflow.com/users/3474",
"pm_score": 11,
"selected": true,
"text": "String"
},
{
"answer_id": 338284,
"author": "JeeBee",
"author_id": 17832,
"author_profile": "https://St... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338206",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14007/"
] |
338,212 | <p>I've got an array of objects in json format: </p>
<pre><code>[
{
"name": "obj1",
"list": [
"elem1",
"elem2",
"elem3"
]
},
{
"name": "obj2",
"list": [
"elem4",
"elem5",
"elem6"
]
}
]
</code></pre>
<p>Now I'd like to construct regexp to remove quotation marks from around elements in the "list" using javascript.<br/></p>
<p>Desirable result:<br/></p>
<pre><code>[{"name":"obj1", "list":[elem1, elem2, elem3]},
{"name":"obj2", "list":[elem4, elem5, elem6]}]
</code></pre>
| [
{
"answer_id": 338585,
"author": "user37125",
"author_id": 37125,
"author_profile": "https://Stackoverflow.com/users/37125",
"pm_score": 1,
"selected": false,
"text": "var str = '[{\"name\":\"obj1\", \"list\":[\"elem1\", \"elem2\", \"elem3\"]},'\n + '{\"name\":\"obj2\", \"list\":[... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338212",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
338,217 | <p>I have a <code>TextCtrl</code> in my wxPython program and I'd like to set its width to exactly 3 characters. However, the only way to set its size manually accepts only numbers of pixels. Is there any way to specify characters instead of pixels?</p>
| [
{
"answer_id": 338287,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 2,
"selected": false,
"text": "wxWindow::GetTextExtent"
}
] | 2008/12/03 | [
"https://Stackoverflow.com/questions/338217",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1694/"
] |
338,225 | <p>everybody; I have this problem in asp.net, I have a page where I insert and modify data, before saving I make a validation if it passes I save the data but if not I raise an exception and show it, the function goes like this;</p>
<pre><code>protected void btnSave_Click(object sender, EventArgs e)
{
try
{
...
if(ValidData())
//Save
...
else
throw new Exception("Invalid data");
}
catch(Exception ex)
{
// Javascript alert
JSLiteral.Text = Utilities.JSAlert(ex.Message);
}
}
</code></pre>
<p>The problem is that after I raise the exception and fix the data in the page I click again the save button and it saves but before it shows me again the exception message and its annoying. Even when the data is saved I click again and it shows the message from the exception again.</p>
<p>Do you know the answer for this issue?</p>
| [
{
"answer_id": 338249,
"author": "James Curran",
"author_id": 12725,
"author_profile": "https://Stackoverflow.com/users/12725",
"pm_score": 0,
"selected": false,
"text": "if(ValidData())\n{\n //Save\n}\n else\n{ // Javascript alert\n JSLiteral.Text = Utilities.JSAlert(ex.Message);\n}\... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338225",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1130097/"
] |
338,242 | <p>I'd like to store a simple key/value string dictionary in my web config file. Visual Studio makes it easy to store a string collection(see sample below) but I'm not sure how to do it with a dictionary collection.</p>
<pre><code> <ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<string>value1</string>
<string>value2</string>
<string>value2</string>
</ArrayOfString>
</code></pre>
| [
{
"answer_id": 338248,
"author": "Maxime Rouiller",
"author_id": 24975,
"author_profile": "https://Stackoverflow.com/users/24975",
"pm_score": 3,
"selected": false,
"text": "<MyDictionary>\n <add name=\"Something1\" value=\"something else\"/>\n <add name=\"Something2\" value=\"somethin... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338242",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25121/"
] |
338,251 | <p>I am trying to port some data over from my production database to my sandbox using a query like this:</p>
<pre><code>INSERT `dbsandbox`.`SomeTable`(Field1, Field2, Field3)
SELECT t.Field1, t.Field2, t.Field3
FROM `dbprod`.`SomeTable` t;
</code></pre>
<p>When I attempt this cross-database join I get the following error:</p>
<p>ERROR 1142 (42000): SELECT command denied to user 'myusername'@'server.domain.tdl' for table 'SomeTable'</p>
<p>The user in question has permission to the tables in question for both databases. I have tried this in both the unix mysql client and the windows MySQL Query Browser application with the same result.</p>
<p>What am I missing?</p>
| [
{
"answer_id": 338319,
"author": "Rob Prouse",
"author_id": 30827,
"author_profile": "https://Stackoverflow.com/users/30827",
"pm_score": 3,
"selected": false,
"text": "SELECT t.Field1, t.Field2, t.Field3\nFROM `dbprod`.`SomeTable` t;\n"
},
{
"answer_id": 360471,
"author": "C... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338251",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42937/"
] |
338,258 | <p>I've got two sizing issue regarding a Window I've got. The basic layout is like this</p>
<pre><code><Window MaxHeight="{DynamicResource {x:Static SystemParameters.VirtualScreenHeight}}"
MaxWidth="{DynamicResource {x:Static SystemParameters.VirtualScreenWidth}}"
>
<StackPanel>
<DockPanel LastChildFill="False">
<StackPanel DockPanel.Dock="Left"
Orientation="Horizontal">
<!--Some buttons-->
</StackPanel>
<StackPanel DockPanel.Dock="Right"
Orientation="Horizontal">
<!--Some buttons-->
</StackPanel>
</DockPanel>
<ScrollViewer>
<WrapPanel x:Name="Container">
</WrapPanel>
</ScrollViewer>
</StackPanel>
</Window>
</code></pre>
<p>1) How do I made the Window not get smaller horizontally than the DockPanel's width?</p>
<p>2) How do I make the ScrollViewer be restricted to the limits of the Window? It is sizing itself to its contents, extending past the bounds of the Window.<br>
It sort of used to work when I had </p>
<pre><code><Window><ScrollViewer/></Window>
</code></pre>
<p>, but I really don't want the DockPanel inside the scroller. In the current form, it is even forcing the Window to break its MaxHeight.</p>
| [
{
"answer_id": 338538,
"author": "Kent Boogaart",
"author_id": 5380,
"author_profile": "https://Stackoverflow.com/users/5380",
"pm_score": 1,
"selected": false,
"text": "StackPanel"
}
] | 2008/12/03 | [
"https://Stackoverflow.com/questions/338258",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9970/"
] |
338,262 | <p>Today I discovered something that makes me sad: objects of type System.Generic.Collections.List don't have a number of the useful extension methods I've come to love, such as Find, FindAll, FindIndex, Exists, RemoveAll, etc. </p>
<p>The object browser in VS2008 shows that those methods exist in the mscorlib version I'm using, but if I look at the assembly in ildasm they're not there.</p>
<p>Am I missing something obvious here or is there some way to make them available to my Silverlight app?</p>
<p>Also, I wonder if there's a good reference out there for what's different between Silverlight's runtime and the "real" one.</p>
<p>Thanks!</p>
| [
{
"answer_id": 338339,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 1,
"selected": false,
"text": "Find"
},
{
"answer_id": 1032960,
"author": "herzmeister",
"author_id": 90742,
"author_profile": "htt... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338262",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22152/"
] |
338,267 | <p>My application needs to set cookies for specific paths in the application. For example (in php):</p>
<pre><code>setcookie(*cookie_name*,*value*,*date*,"/subpath/subpath/unique_name");
setcookie(*cookie_name*,*value*,*date*,"/subpath/subpath/another unique name");
</code></pre>
<p>Oddly enough, the first setcookie works fine. The second doesn't generate an error and when I view my cookies in Firefox the cookie is there with the correct values. However, I can't access it in my code. I believe the whitespaces are causing the trouble but I haven't found any documentation or specs on how cookie paths should be encoded. </p>
<p>Has anyone encountered this problem before? Does anyone know how to deal with special characters in cookie paths?</p>
| [
{
"answer_id": 338581,
"author": "OIS",
"author_id": 36175,
"author_profile": "https://Stackoverflow.com/users/36175",
"pm_score": 0,
"selected": false,
"text": "setcookie(*cookie_name*,*value*,*date*, \"/subpath/subpath/another unique name/\");\nsetcookie(*cookie_name*,*value*,*date*, u... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338267",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
338,269 | <p>I have an app that display's the current time when a page opens. I would like that time to update every 30 seconds. I've read about prototype's Ajax.PeriodicalUpdater and it seems to be an answer. This is how I achieve the static time display on page load with php: </p>
<pre><code> <tr>
<td>
<input class="standard" type="text" name="start_time"
value="<?php echo prev_end();?>">
<!--prev_end is last end time from database-->
</td>
<td>
<input class="standard" type="text" name="end_time"
value="<?php echo $now;?>">
<!--$now = date("G:i");-->
</td>
</code></pre>
<p>This is what I've attempted with prototype:</p>
<pre><code><script type="javascript">
new Ajax.PeriodicalUpdater("updater", "unow.php", {frequency : 30});
</script>
...
<tr>
<td>
<input class="standard" type="text" name="start_time"
value="<?php echo prev_end();?>">
</td>
<td>
<input id="updater" class="standard" type="text" name="end_time"
value="">
</td>
</code></pre>
<p>Where "unow.php" does this</p>
<pre><code><?php
$unow=date("G:i");
echo $unow;
?>
</code></pre>
<p>It seems that I don't need a callback to put the value from unow.php into the input "updater" since PeriodicalUpdater calls for an element id. What am I missing?</p>
| [
{
"answer_id": 338364,
"author": "James Orr",
"author_id": 41457,
"author_profile": "https://Stackoverflow.com/users/41457",
"pm_score": 3,
"selected": true,
"text": "<html>\n<body onload=\"init();\">\n <div id=time></div>\n</body>\n</html>\n<script type=text/javascript>\n\nfunction ini... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338269",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1149/"
] |
338,271 | <pre><code>
class C {
public
T x;
};
</code></pre>
<p>Is there an elegant way for the constructor of x to know <strong>implicitly</strong> in what instance of C it is constructing?
<hr>
I've implemented such behavior with some dirty inelegant machinery. I need this for my sqlite3 wrapper. I don't like all wrappers I've seen, their API IMO ugly and inconvenient. I want something like this:</p>
<pre><code>
class TestRecordset: public Recordset {
public:
// The order of fields declarations specifies column index of the field.
// There is TestRecordset* pointer inside Field class,
// but it goes here indirectly so I don't have to
// re-type all the fields in the constructor initializer list.
Field<__int64> field1;
Field<wstring> field2;
Field<double> field3;
// have TestRecordset* pointer too so only name of parameter is specified
// in TestRecordset constructor
Param<wstring> param;
virtual string get_sql() {
return "SELECT 1, '1', NULL FROM test_table WHERE param=:PARAM";
}
// try & unlock are there because of my dirty tricks.
// I want to get rid of them.
TestRecordset(wstring param_value)
try : Recordset(open_database(L"test.db")), param("PARAM") {
param = param_value;
// I LOVE RAII but i cant use it here.
// Lock is set in Recordset constructor,
// not in TestRecordset constructor.
unlock(this);
fetch();
} catch(...) {
unlock(this);
throw;
}
};
<code></pre>
<p>I want to clarify the fact - it is a part of the <i>working</i> code. You <i>can</i> do this in C++. I just want to do it in a more nice way.
<hr>
I've found a way to get rid of unlock and try block. I've remembered there is such a thing as thread local storage. Now I can write constructor as simple as that:</p>
<pre>
TestRecordset(wstring param_value):
Recordset(open_database(L"test.db")), param("PARAM") {
param = param_value;
fetch();
}
</code></pre>
<p><hr>
to dribeas:
My objective is to avoid redundant and tedious typing. Without some tricks behind the scene I will have to type for each Field and Param:</p>
<pre>
TestRecordset(wstring param_value): Recordset(open_database(L"test.db")), param(this, "PARAM"),
field1(this, 0), field2(this, 1), field3(this, 2) { ... }
</code></pre>
<p>It is redundant, ugly and inconvenient. For example, if I'll have to add new field in the
middle of SELECT I'll have to rewrite all the column numbers.
Some notes on your post:</p>
<ol>
<li>Fields and Params <i>are</i> initialized by their default constructors.</li>
<li>Order of initializers in constructor is irrelevant. Fields are always initialized in order of their declaration. I've used this fact to track down column index for fields</li>
<li>Base classes are constructed first. So when Fields are constructed internal field list in Recordset are ready to use by Filed default constructor.</li>
<li>I CAN'T use RAII here. I need to acquire lock in Recorset constructor and release it obligatory in TestRecordset constructor <i>after all Fields are constructed</i>.</li>
</ol>
| [
{
"answer_id": 338297,
"author": "Steve Jessop",
"author_id": 13005,
"author_profile": "https://Stackoverflow.com/users/13005",
"pm_score": 3,
"selected": false,
"text": "#define INIT_FIELDS field1(this), field2(this), field3(this)\n"
}
] | 2008/12/03 | [
"https://Stackoverflow.com/questions/338271",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12151/"
] |
338,273 | <p>I'm just learning C with Kernighan and Ritchie's book; I'm in the basics of the fourth chapter ("Functions and Program Structure"). The other day I became curious about the <code>sleep()</code> function, so tried to use it like this:</p>
<pre><code>#include <stdio.h>
#include <unistd.h>
int main(void)
{
printf(" I like cows.");
sleep(5);
return 0;
}
</code></pre>
<p>The problem is the output of the program, it looks like it does the <code>sleep()</code> first and then the <code>printf()</code>, in other words, it waits five seconds and then prints the string. So I thought, maybe the program gets to <code>sleep()</code> so fast that it doesn't let <code>printf()</code> have his work done like I want, that is print the string and then sleep.</p>
<p>How can I show the string and then put the program to sleep?
The compiler is GCC 3.3.5 (propolice) in OpenBSD 4.3.</p>
| [
{
"answer_id": 338290,
"author": "Paul Tomblin",
"author_id": 3333,
"author_profile": "https://Stackoverflow.com/users/3333",
"pm_score": 3,
"selected": false,
"text": "fflush(stdout);"
},
{
"answer_id": 338295,
"author": "Robert Gamble",
"author_id": 25222,
"author_p... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338273",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
338,274 | <p>Ok, I have the following structure. Basically a plugin architecture</p>
<pre><code>// assembly 1 - Base Class which contains the contract
public class BaseEntity {
public string MyName() {
// figure out the name of the deriving class
// perhaps via reflection
}
}
// assembly 2 - contains plugins based on the Base Class
public class BlueEntity : BaseEntity {}
public class YellowEntity : BaseEntity {}
public class GreenEntity : BaseEntity {}
// main console app
List<BaseEntity> plugins = Factory.GetMePluginList();
foreach (BaseEntity be in plugins) {
Console.WriteLine(be.MyName);
}
</code></pre>
<p>I'd like the statement</p>
<pre><code>be.MyName
</code></pre>
<p>to tell me whether the object is BlueEntity, YellowEntity or GreenEntity. The important thing is that the MyName property should be in the base class, because I don't want to reimplement the property in every plugin.</p>
<p>Is this possible in C#?</p>
| [
{
"answer_id": 338298,
"author": "JaredPar",
"author_id": 23283,
"author_profile": "https://Stackoverflow.com/users/23283",
"pm_score": -1,
"selected": false,
"text": "class BaseEntity {\n private readonly m_name as string;\n public Name { get { return m_name; } }\n protected BaseEnti... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338274",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9382/"
] |
338,285 | <p>I'm trying to prevent <code>bash</code> from saving duplicate commands to my history. Here's what I've got:</p>
<pre><code>shopt -s histappend
export HISTIGNORE='&:ls:cd ~:cd ..:[bf]g:exit:h:history'
export HISTCONTROL=erasedups
export PROMPT_COMMAND='history -a'
</code></pre>
<p>This works fine while I'm logged in and <code>.bash_history</code> is in memory. For example:</p>
<pre><code>$ history
1 vi .bashrc
2 vi .alias
3 cd /cygdrive
4 cd ~jplemme
5 vi .bashrc
6 vi .alias
$ vi .bashrc
$ history
1 vi .alias
2 cd /cygdrive
3 cd ~jplemme
4 vi .alias
5 vi .bashrc
$ vi .alias
$ history
1 cd /cygdrive
2 cd ~jplemme
3 vi .bashrc
4 vi .alias
$ exit
</code></pre>
<p>But when I log back in, my history file looks like this:</p>
<pre><code>$ history
1 vi .bashrc
2 vi .alias
3 cd /cygdrive
4 cd ~jplemme
5 vi .bashrc
6 vi .alias
7 vi .bashrc
8 vi .alias
</code></pre>
<p>What am I doing wrong?</p>
<p>EDIT: Removing the <code>shopt</code> and <code>PROMPT_COMMAND</code> lines from <code>.bashrc</code> does not fix the problem.</p>
| [
{
"answer_id": 338399,
"author": "Robert Gamble",
"author_id": 25222,
"author_profile": "https://Stackoverflow.com/users/25222",
"pm_score": 3,
"selected": false,
"text": "export HISTCONTROL=ignoreboth\n"
},
{
"answer_id": 338593,
"author": "Community",
"author_id": -1,
... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338285",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1019/"
] |
338,317 | <p>I'm trying to build GNU grep, and when I run make, I get:</p>
<pre><code>[snip]
/bin/bash: line 9: makeinfo: command not found
</code></pre>
<p>What is makeinfo, and how do I get it?</p>
<p>(This is Ubuntu, if it makes a difference)</p>
| [
{
"answer_id": 338384,
"author": "Tuminoid",
"author_id": 40657,
"author_profile": "https://Stackoverflow.com/users/40657",
"pm_score": 10,
"selected": true,
"text": "bash"
},
{
"answer_id": 19904417,
"author": "kevinarpe",
"author_id": 257299,
"author_profile": "http... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338317",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/91385/"
] |
338,347 | <p>I've never managed to move from unit-testing to integration-testing in any graceful or automated way when it comes to network code.</p>
<p><strong>So my question is</strong>: Given a simple single-threaded client/server based network application, how would you go about integrating both client and server into your currently favorite testing suite (I currently use <a href="http://check.sourceforge.net/" rel="nofollow noreferrer">check</a>).</p>
<p>I am of course willing to change unit-test suite to accomplish my goal.</p>
<p><strong>Edit</strong>: While I appreciate the answers, I was more looking for some magical way of integrating integration-testing into my unit-test framework (if it's possible at all). Like if <em>fork</em>() or something could be applied without getting too many side effects.</p>
| [
{
"answer_id": 338932,
"author": "qrdl",
"author_id": 28494,
"author_profile": "https://Stackoverflow.com/users/28494",
"pm_score": 1,
"selected": false,
"text": "netcat"
}
] | 2008/12/03 | [
"https://Stackoverflow.com/questions/338347",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40668/"
] |
338,366 | <p>Is there a way to have different application settings per each build configuration?</p>
<p>I would like to be able to batch build a few configurations with different settings, instead of having to change the settings and build, rinse repeat.</p>
<p>Thanks in advance!</p>
| [
{
"answer_id": 343406,
"author": "Miral",
"author_id": 43534,
"author_profile": "https://Stackoverflow.com/users/43534",
"pm_score": 3,
"selected": true,
"text": "public static readonly"
}
] | 2008/12/03 | [
"https://Stackoverflow.com/questions/338366",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42931/"
] |
338,379 | <p>I need to take in a Date Range from the UI, retrieve the records within that range and plot a graph. This is the relevant section in my Rails view.</p>
<pre><code><span>
<%= check_box_tag :applyRange, @params[:applyRange]%>
From
<%= select_date Time.now, :prefix=>"fromDate" %>
To
<%= select_date Time.now, :prefix=>"toDate" %>
</span>
</code></pre>
<p>Back on the controller/action side, this is what I had to do to reconstruct the date values back (hack hack puts hack puts hack...)</p>
<pre><code>fromDate = Date.civil params[:fromDate]["year"].to_i, params[:fromDate]["month"].to_i, params[:fromDate]["day"].to_i
</code></pre>
<p><strong>This just feels wrong</strong>. I'll probably have the fields have blanks too.. in which case to_i is bound to barf. This looks like something that must have been done a zillion times before.. So looking for a good recipe for this. I spent the better part of the last hour trying to figure out this quirky rails helper.</p>
| [
{
"answer_id": 343406,
"author": "Miral",
"author_id": 43534,
"author_profile": "https://Stackoverflow.com/users/43534",
"pm_score": 3,
"selected": true,
"text": "public static readonly"
}
] | 2008/12/03 | [
"https://Stackoverflow.com/questions/338379",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1695/"
] |
338,385 | <p>Trying to make a <a href="http://en.wikipedia.org/wiki/Web_service" rel="noreferrer">web service</a> call to an <a href="http://en.wikipedia.org/wiki/HTTP_Secure" rel="noreferrer">HTTPS</a> endpoint in my <a href="http://en.wikipedia.org/wiki/Microsoft_Silverlight" rel="noreferrer">Silverlight</a> application results in this error: "Could not find a base address that matches scheme https for the endpoint with binding WSHttpBinding. Registered base address schemes are [http]"</p>
<p>The same problem as was posted here:</p>
<p><a href="http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/4c19271a-f5e6-4659-9e06-b556dbdcaf82/" rel="noreferrer">http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/4c19271a-f5e6-4659-9e06-b556dbdcaf82/</a></p>
<p>So, one of the suggestions was this: "The other issue might be that the cert name and the machine name don't agree, and this is causing <a href="http://en.wikipedia.org/wiki/Windows_Communication_Foundation" rel="noreferrer">WCF</a> to have fits. If this is the case, you can tell WCF to skip verification of the cert."</p>
<p>Well, I <strong>do</strong> get a certificate error because this is just a demo server.</p>
<p>Here's how I set up my client:</p>
<pre><code>BasicHttpBinding binding = new BasicHttpBinding();
binding.Security.Mode = BasicHttpSecurityMode.Transport;
_ws = new AnnotationService.AnnotationClient(binding, new EndpointAddress(myAddress));
</code></pre>
<p>How can I tell WCF to skip the verification?</p>
| [
{
"answer_id": 338575,
"author": "joshperry",
"author_id": 30587,
"author_profile": "https://Stackoverflow.com/users/30587",
"pm_score": 2,
"selected": false,
"text": "<bindings>\n <basicHttpBinding>\n <binding name=\"SecureTransport\">\n <security mode=\"Transport\">\n <... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338385",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28643/"
] |
338,398 | <p>Every now and then, I bump into syntax that I've seen before, but never used. This is one of those times.</p>
<p>Can someone explain the purpose of ":this" or ":base" following a C# constructor method?</p>
<p>For example:</p>
<pre><code>public MyClass(SomeArg arg) : this(new SomethingElse(), arg)
{
}
</code></pre>
<p>My gut feeling is that it is used to map a default argument onto another constructor method.</p>
| [
{
"answer_id": 338402,
"author": "MrKurt",
"author_id": 35296,
"author_profile": "https://Stackoverflow.com/users/35296",
"pm_score": 5,
"selected": true,
"text": "this()"
},
{
"answer_id": 338409,
"author": "Lasse V. Karlsen",
"author_id": 267,
"author_profile": "htt... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338398",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1965/"
] |
338,400 | <p>Compiling this lines</p>
<pre><code> long int sz;
char tmpret[128];
//take substring of c, translate in c string, convert to int,
//and multiply with 1024
sz=atoi(c.substr(0,pos).c_str())*1024;
snprintf(tmpret,128,"%l",sz);
</code></pre>
<p>I read two warning on snprintf line:</p>
<pre><code> warning: conversion lacks type at end of format
warning: too many arguments for format
</code></pre>
<p>Why? The type is specified (long int sz, and %l in snprintf) and the argument in snprintf is only one. Can anybody help me? Thanks.</p>
| [
{
"answer_id": 338437,
"author": "Matt Cruikshank",
"author_id": 8643,
"author_profile": "https://Stackoverflow.com/users/8643",
"pm_score": 1,
"selected": false,
"text": "boost::lexical_cast<string>(sz)"
}
] | 2008/12/03 | [
"https://Stackoverflow.com/questions/338400",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39796/"
] |
338,406 | <p>So I'm trying to run my first hello world prog written in C. I compiled it in eclipse and get no errors, but when I try to run it I get:</p>
<p>"This application has failed to start because cygwin1.dll was not found."</p>
<p>I found <a href="http://dev.eclipse.org/newslists/news.eclipse.tools.cdt/msg08271.html" rel="noreferrer">this post</a> which seems to indicate I should add it to Windows PATH, and I used <a href="http://www.computerhope.com/issues/ch000549.htm" rel="noreferrer">this</a> to do that. So now "Path" in my environment variables has ";C:\cygwin\bin\cygwin1.dll" appended to the end. Still no worky. Anyone have a clue what I might be doing wrong? My 'program' just looks like this: </p>
<pre><code>#include <stdio.h>
main()
{
printf("hello, world\n");
}
</code></pre>
| [
{
"answer_id": 338412,
"author": "Adam Rosenfield",
"author_id": 9530,
"author_profile": "https://Stackoverflow.com/users/9530",
"pm_score": 5,
"selected": true,
"text": "\"C:\\cygwin\\bin\""
},
{
"answer_id": 338462,
"author": "Mihai Limbășan",
"author_id": 14444,
"a... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338406",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
338,427 | <p>[This is for PC/Visual C++ specifically (although any other answers would be quite illuminating :))]</p>
<p>How can you tell if a pointer comes from an object in the stack? For example:</p>
<pre><code>int g_n = 0;
void F()
{
int *pA = &s_n;
ASSERT_IS_POINTER_ON_STACK(pA);
int i = 0;
int *pB = &i;
ASSERT_IS_POINTER_ON_STACK(pB);
}
</code></pre>
<p>so only the second assert <em>(pB)</em> should trip. I'm thinking using some inline assembly to figure out if it's within the SS segment register or something like that. Does anybody know if there's any built in functions for this, or a simple way to do this?</p>
<p>Thanks!
RC</p>
| [
{
"answer_id": 338446,
"author": "Adam Rosenfield",
"author_id": 9530,
"author_profile": "https://Stackoverflow.com/users/9530",
"pm_score": 2,
"selected": false,
"text": "%esp"
},
{
"answer_id": 338448,
"author": "Rob Walker",
"author_id": 3631,
"author_profile": "ht... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338427",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13004/"
] |
338,428 | <p>Is there a way to query against exchange 2007 to distinguish who is either an active sync or blackberry user using powershell exchange addin? </p>
| [
{
"answer_id": 359962,
"author": "phill",
"author_id": 18853,
"author_profile": "https://Stackoverflow.com/users/18853",
"pm_score": 0,
"selected": false,
"text": "'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''\n''\n'' DISABLEEAS.VBS\n''\n'' Disables Exch... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338428",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18853/"
] |
338,436 | <p>Is there a command in Git to see (either dumped to stdout, or in <code>$PAGER</code> or <code>$EDITOR</code>) a particular version of a particular file?</p>
| [
{
"answer_id": 338470,
"author": "mipadi",
"author_id": 28804,
"author_profile": "https://Stackoverflow.com/users/28804",
"pm_score": 11,
"selected": false,
"text": "git show"
},
{
"answer_id": 13958640,
"author": "Trausti Kristjansson",
"author_id": 1602016,
"author_... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338436",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/91385/"
] |
338,445 | <p>Please can someone explain what the following statement does in SQL Server 2005:</p>
<pre><code>GRANT ALL TO pax_writer
</code></pre>
<p>pax_writer is a database role previously created using the statement</p>
<pre><code>CREATE ROLE pax_writer AUTHORIZATION dbo
</code></pre>
| [
{
"answer_id": 338470,
"author": "mipadi",
"author_id": 28804,
"author_profile": "https://Stackoverflow.com/users/28804",
"pm_score": 11,
"selected": false,
"text": "git show"
},
{
"answer_id": 13958640,
"author": "Trausti Kristjansson",
"author_id": 1602016,
"author_... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338445",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3012/"
] |
338,450 | <p>I am trying to implement the python logging handler <code>TimedRotatingFileHandler</code>.</p>
<p>When it rolls over to midnight it appends the current day in the form <code>YYYY-MM-DD</code>.</p>
<pre><code>LOGGING_MSG_FORMAT = '%(name)-14s > [%(levelname)s] [%(asctime)s] : %(message)s'
LOGGING_DATE_FORMAT = '%Y-%m-%d %H:%M:%S'
logging.basicConfig(
level=logging.DEBUG,
format=LOGGING_MSG_FORMAT,
datefmt=LOGGING_DATE_FORMAT
)
root_logger = logging.getLogger('')
logger = logging.handlers.TimedRotatingFileHandler("C:\\logs\\Rotate_Test",'midnight',1)
root_logger.addHandler(logger)
while True:
daemon_logger = logging.getLogger('TEST')
daemon_logger.info("SDFKLDSKLFFJKLSDD")
time.sleep(60)
</code></pre>
<p>The first log file created is named <code>Rotate_Test</code>, then once it rolls over to the next day it changes the file name to <code>Rotate_Test.YYYY-MM-DD</code> where <code>YYYY-MM-DD</code> is the current day.</p>
<p>How can I change how it alters the filename?</p>
| [
{
"answer_id": 338566,
"author": "S.Lott",
"author_id": 10661,
"author_profile": "https://Stackoverflow.com/users/10661",
"pm_score": 7,
"selected": true,
"text": "logging/handlers.py"
},
{
"answer_id": 340429,
"author": "UberJumper",
"author_id": 34395,
"author_profi... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338450",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34395/"
] |
338,463 | <p>I would like to compare two dates in javascript. I have been doing some research, but all I can find is how to return the current date. I want to compare 2 separate dates, not related to today. How do I do that. </p>
<pre><code>var startDate = Date(document.form1.Textbox2);
</code></pre>
| [
{
"answer_id": 338474,
"author": "matt b",
"author_id": 4249,
"author_profile": "https://Stackoverflow.com/users/4249",
"pm_score": 9,
"selected": true,
"text": "if (date1.getTime() > date2.getTime()) {\n alert(\"The first date is after the second date!\");\n}\n"
},
{
"answer_... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338463",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
338,472 | <p>I have a list box control:</p>
<pre>
<code>
<asp:ListBox runat="server" id="lbox" autoPostBack="true" />
</code>
</pre>
<p>The code behind resembles:</p>
<pre>
<code>
private void Page_Load(object sender, System.EventArgs e)
{
lbox.SelectedIndexChanged+=new EventHandler(lbox_SelectedIndexChanged);
if(!Page.IsPostBack)
{
LoadData();
}
}
private LoadData()
{
lbox.DataSource = foo();
lbox.DataBind();
}
protected void lboxScorecard_SelectedIndexChanged(object sender, EventArgs e)
{
int index = (sender as ListBox).selectedIndex;
}
</code>
</pre>
<p>My problem is that when my page receives a post back (when a user makes a selection in the listbox), the selection always "jumps" to the first item in the listbox, so that the index variable in my callback function is always 0.</p>
<p>Seems like this may be a viewstate problem? How can I fix it so that the selection index remains through the postback?</p>
<p>There is no ajax going on, this is .NET 1.0.</p>
<p>Thanks.</p>
<p><strong>EDIT 1</strong> JohnIdol has gotten me a step closer, If I switch the datasource from my original DataTable to an ArrayList, then everything work properly...what would cause this?</p>
<p><strong>Edit 2</strong> It turns out that my DataTable had multiple values that were the same, so that the indexes were treated as the same as all items with the same value...thanks to those who helped!</p>
| [
{
"answer_id": 338513,
"author": "Briggie Smalls",
"author_id": 9559,
"author_profile": "https://Stackoverflow.com/users/9559",
"pm_score": -1,
"selected": false,
"text": "<asp:ListBox runat=\"server\" id=\"lbox\" autoPostBack=\"true\" OnSelectedIndexChanged=\"lboxScorecard_SelectedIndex... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338472",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1638/"
] |
338,482 | <p>Is there a way to do your timezone offsets on the server side, by reading something in the request over http, instead of sending everything to the client and letting it deal with it?</p>
| [
{
"answer_id": 388219,
"author": "devstuff",
"author_id": 41321,
"author_profile": "https://Stackoverflow.com/users/41321",
"pm_score": 6,
"selected": true,
"text": "\n<script type=\"text/javascript\" language=\"JavaScript\">\nvar offset = new Date();\ndocument.write('<input type=\"hidde... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338482",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1220/"
] |
338,483 | <p>I'm on Windows Vista and IE7.</p>
<p>Here's what I'd like to do:</p>
<ol>
<li>I have two flash files: <code>page1.swf</code> and <code>page2.swf</code>. They are just page from a magazine.</li>
<li>Display <code>page1.swf</code></li>
<li>Have a button that says "Change page"</li>
<li>When I click the button; display <code>page2.swf</code> instead of <code>page1.swf</code> (only <code>page2.swf</code>, not both pages)
That's it. </li>
</ol>
<p>If anyone can give me a script to do that I would greatly appreciate it.</p>
| [
{
"answer_id": 388219,
"author": "devstuff",
"author_id": 41321,
"author_profile": "https://Stackoverflow.com/users/41321",
"pm_score": 6,
"selected": true,
"text": "\n<script type=\"text/javascript\" language=\"JavaScript\">\nvar offset = new Date();\ndocument.write('<input type=\"hidde... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338483",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39973/"
] |
338,499 | <p>I would (as the question states) like to make an asynchronous call, preferably using ASP.net AJAX.</p>
<p>The code for the WebMethod looks like this:</p>
<pre><code>[WebMethod]
public void SendMail(string name, string email, string subject, string body)
{
MailMessage toSend = new MailMessage(email, address@domain.com, subject, body);
var smtp = new SmtpClient();
smtp.Send(toSend);
}
</code></pre>
<p>The fields on the view are, not surprisingly: name, email, subject, body.</p>
<p>In my attempts to do this I haven't been able to get to the WebMethod. The service reference is in place, so at least I didn't screw that up. </p>
<p>Thanks for the help...</p>
| [
{
"answer_id": 338572,
"author": "mapache",
"author_id": 41422,
"author_profile": "https://Stackoverflow.com/users/41422",
"pm_score": 1,
"selected": true,
"text": "<% using (Ajax.Form(\"SendMail\", new AjaxOptions { UpdateTargetId = \"resultDiv\" })) { %>\n\n <!-- Your form elements h... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338499",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13139/"
] |
338,516 | <p>I am living on the other side of the world from my home (GMT+1 now, GMT+13 is home), and I miss my old terrestrial radio station. It has a Shoutcast stream, and I would like to simply delay it by 12 hours so that it is always available when I want to listen to it, in a way that would make its timezone be synchronised to my timezone.</p>
<p>I envision this as a script being run on my server host.</p>
<p>A naive approach would simply be to allocate enough ram in a ringbuffer to store the entire 12 hour delay, and pipe in the output from streamripper. But the stream is a 128kbps mp3, which would mean (128/8) * 60 * 60 = ~56MB per hour, or 675MB for the whole 12 hour buffer, which isn't really so practical. Plus, i might have to deal with my server host just killing the process after a certain timeout.</p>
<p>So, what are some strategies that might actually be practical?</p>
| [
{
"answer_id": 340750,
"author": "damian",
"author_id": 42961,
"author_profile": "https://Stackoverflow.com/users/42961",
"pm_score": 0,
"selected": false,
"text": "#!/usr/bin/python\nimport time\nimport urllib\nimport datetime\nimport os\nimport socket\n\n# number of seconds for each fi... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338516",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42961/"
] |
338,518 | <p>In my JSP I need to test two objects using the <code>equals()</code> method. Is there a way to do this using EL, JSTL, or another tag library? I am not allowed to use scriptlets due to team rules.</p>
<p>I tried to use the JSTL <code><c:if></code> tag, but it only seems to use the <code>==</code> operator.</p>
| [
{
"answer_id": 338671,
"author": "erickson",
"author_id": 3474,
"author_profile": "https://Stackoverflow.com/users/3474",
"pm_score": 4,
"selected": true,
"text": "=="
}
] | 2008/12/03 | [
"https://Stackoverflow.com/questions/338518",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42962/"
] |
338,537 | <p>Is there a way to specify a one dimensional array in a ini file. </p>
<p>so in my ini I would like to do</p>
<p>someproperty = [array of something]</p>
<p>I am using <code>Zend_Config_Ini</code> config adapter (I prefer ini for base configuration). </p>
| [
{
"answer_id": 338568,
"author": "Alister Bulman",
"author_id": 6216,
"author_profile": "https://Stackoverflow.com/users/6216",
"pm_score": 6,
"selected": true,
"text": "someproperty[] = a\nsomeproperty[] = b\nsomeproperty[] = c\nsomeproperty[] = d\nsomeproperty[] = e\n"
},
{
"an... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338537",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35505/"
] |
338,541 | <p>I'm extending the Gridview Web Control as my first attempt at creating a custom control.</p>
<p>As part of the extension I am encapsulating the localization of the grid column headers within the control. Among others, I'm exposing a couple of properties to enable this feature:</p>
<p>bool AutoLocalizeColumnHeaders - enables the feature</p>
<p>string HeaderResourceFile - identifies a strongly typed resource class from which to get the header text</p>
<p>I'm overriding the OnRowDataBound handler and getting the appropriate ResourceManager using Reflection to populate the header text. This is all working nicely but I would like to display a list of the available Strongly Typed Resource Classes in the Property window for the user to choose from, rather than them having to type in the name manually.</p>
<p>I've created a TypeConverter for displaying a dropdown in which to display the available classes but can't work out how to get the list of available class names to display?</p>
<p>I've been trying for quite a while now without success and am at the point of losing my sanity. I'm assuming that there must be some way to achieve this using Reflection?</p>
| [
{
"answer_id": 344898,
"author": "Graham Watson",
"author_id": 42964,
"author_profile": "https://Stackoverflow.com/users/42964",
"pm_score": 1,
"selected": false,
"text": "String[] resourceClassNames = (from type in assembly.GetTypes()\n where type.IsClass && type.Namespace.Equals(\"Re... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338541",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42964/"
] |
338,559 | <p>I want to build a toolchain from gnuarm.org from sources. I don't want to use binary version because i'm running x64 linux. Can you point me to some kind of tutorial?</p>
| [
{
"answer_id": 344187,
"author": "Tuminoid",
"author_id": 40657,
"author_profile": "https://Stackoverflow.com/users/40657",
"pm_score": 2,
"selected": true,
"text": "sudo apt-get install libx11-dev\n"
}
] | 2008/12/03 | [
"https://Stackoverflow.com/questions/338559",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42968/"
] |
338,561 | <p>I have a Visual Studio 2005 solution (.sln) with a mix of .NET and C++ projects. What is the best way to generate the .build file I will need to run my build process with NAnt. I'm new to using NAnt, and I'm not sure how to set it up. Will I have to update the .build file manually every time there is a new source file in any of the projects? Is there a tool that will generate the files for NAnt from the .sln and studio project files?</p>
| [
{
"answer_id": 338599,
"author": "Mike Marshall",
"author_id": 29798,
"author_profile": "https://Stackoverflow.com/users/29798",
"pm_score": 3,
"selected": true,
"text": "msbuild.exe /p:Configuration=Debug /t:rebuild MySolution.sln\n"
}
] | 2008/12/03 | [
"https://Stackoverflow.com/questions/338561",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1363/"
] |
338,563 | <p>I have a Javascript that changes the host in links to match the current development/test server.</p>
<p>Here's an example:</p>
<pre><code>var ndomain = document.domain;
var mydomain = 'www.foo.com';
var alink = document.getElementsByTagName('a');
for (var i = 0; i < alink.length; i++) {
if (alink[i].href.length > 0){
if (alink[i].host.substr(0, mydomain.length) == mydomain){
alink[i].host = ndomain;
}
}
}
</code></pre>
<p>This changes references to <em><a href="http://www.foo.com/page.html" rel="nofollow noreferrer">http://www.foo.com/page.html</a></em> to <em><a href="http://level1.test.foo.com/page.html" rel="nofollow noreferrer">http://level1.test.foo.com/page.html</a></em>.</p>
<p>This works in every browser I've tested except Safari (Mac or Win). I've searched and searched for information as to why and the closest reason I've come up with is the "same-origin policy".</p>
<p>Based upon my understanding of the same-origin policy, this should work because everything is under the <em>foo.com</em> domain. Could Safari be more strict in the fact that I'm going to a two level subdomain (e.g.<em>level1.test</em>)?</p>
<p>Can someone advise as to why this process doesn't work in Safari or how I can get it to work in Safari?</p>
<p>TIA!</p>
| [
{
"answer_id": 338599,
"author": "Mike Marshall",
"author_id": 29798,
"author_profile": "https://Stackoverflow.com/users/29798",
"pm_score": 3,
"selected": true,
"text": "msbuild.exe /p:Configuration=Debug /t:rebuild MySolution.sln\n"
}
] | 2008/12/03 | [
"https://Stackoverflow.com/questions/338563",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42969/"
] |
338,567 | <p>I currently have a gridview that has an asp:ButtonField as one of the columns. The event handler for the command extracts the row id of the gridview from the command argument and uses that to perform some logic. I now need to switch to using a template field for this column, and want to do something like this:</p>
<pre><code><asp:TemplateField HeaderText="Action">
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:LinkButton CommandName="myaction" CommandArgument="<%#Eval("id")%>" Text="do action" runat="server"/>
</ItemTemplate>
</asp:TemplateField>
</code></pre>
<p>My problem is with the CommandArgument attribute - I don't know how to get it to be the row id from the GridView. Eval("id") doesn't work - does anyone know what the name of the row id property is? Or a better way to do this?</p>
| [
{
"answer_id": 6610819,
"author": "Cla",
"author_id": 833151,
"author_profile": "https://Stackoverflow.com/users/833151",
"pm_score": 1,
"selected": false,
"text": "CommandArgument=\"<%# CType(Container, GridViewRow).RowIndex %>\"\n"
}
] | 2008/12/03 | [
"https://Stackoverflow.com/questions/338567",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2327/"
] |
338,598 | <p>I have a couple of lines of trivial code such as the following:</p>
<pre><code>NSData *dataReply;
NSString *stringReply;
dataReply = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
stringReply = [[NSString alloc] initWithData:dataReply encoding:NSUTF8StringEncoding];
</code></pre>
<p>The problem here is, initWithData:encoding: does not return an instance of NSString as the documentation claims it does. I've tried doing an explicit cast using (NSString *) as well without much luck. This is giving me compiler warnings when I try to pass the stringReply to a method I've written with type mismatches. Given I treat all warnings as errors, I'd really like to understand what stringReply is being returned as and how I can enforce it to be of type NSString.</p>
| [
{
"answer_id": 338646,
"author": "Max Stewart",
"author_id": 18338,
"author_profile": "https://Stackoverflow.com/users/18338",
"pm_score": 0,
"selected": false,
"text": "const char* os = \"12345\";\nNSString* str = [[NSString alloc] initWithData:[NSData dataWithBytes:os length:5 ] encodi... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338598",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40882/"
] |
338,616 | <p>i have a link to a media file such as an mp3, and i want it to get downloaded when the user clicks on it, instead of just having the file get played. the page i have in mind is just a plain static html page.</p>
<p>any ideas?</p>
| [
{
"answer_id": 338632,
"author": "Stepan Mazurov",
"author_id": 40786,
"author_profile": "https://Stackoverflow.com/users/40786",
"pm_score": 3,
"selected": false,
"text": "Content-disposition: attachment; filename=fname.ext"
},
{
"answer_id": 338644,
"author": "mapache",
... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338616",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4444/"
] |
338,624 | <p>I am making an HTTP connection to an IIS web server and sending a POST request with the data encoded using Transfer-Encoding: chunked. When I do this, IIS simply closes the connection, with no error message or status code. According to the <a href="https://www.rfc-editor.org/rfc/rfc2616#section-3.6.1" rel="nofollow noreferrer">HTTP 1.1 spec</a>,</p>
<blockquote>
<p>All HTTP/1.1 applications MUST be able to receive and decode the "chunked" transfer-coding</p>
</blockquote>
<p>so I don't understand why it's (a) not handling that encoding and (b) it's not sending back a status code. If I change the request to send the Content-Length rather than Transfer-Encoding, the query succeeds, but that's not always possible.</p>
<p>When I try the same thing against Apache, I get a "411 Length required" status and a message saying "chunked Transfer-Encoding forbidden".</p>
<p>Why do these servers not support this encoding?</p>
| [
{
"answer_id": 1208775,
"author": "rupello",
"author_id": 635,
"author_profile": "https://Stackoverflow.com/users/635",
"pm_score": 3,
"selected": false,
"text": "curl <upload-url> --form \"upfile=@<local_file>\" --header \"Transfer-Encoding: chunked\"\n"
}
] | 2008/12/03 | [
"https://Stackoverflow.com/questions/338624",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1821/"
] |
338,628 | <p>I'm trying to write a TCustomDBGrid descendant that's designed to feel like a TListBox. One of the things I want to change is the Options property's defaults. TCustomDBGrid defines Options as:</p>
<pre><code>property Options: TDBGridOptions read FOptions write SetOptions
default [dgEditing, dgTitles, dgIndicator, dgColumnResize, dgColLines,
dgRowLines, dgTabs, dgConfirmDelete, dgCancelOnExit];
</code></pre>
<p>Trying to override that in my class with</p>
<pre><code> property Options: TDBGridOptions default
[dgTitles, dgTabs, dgRowSelect, dgAlwaysShowSelection, dgCancelOnExit];
</code></pre>
<p>doesn't work; the compiler expects <strong>read</strong> or <strong>write</strong> after the type, not <strong>default</strong>. Problem is, FOptions and SetOptions are both defined as private, not protected, in TCustomDBGrid.</p>
<p>Do I have to write my own get and set methods that invoke "<strong>inherited</strong> Options", or is there a simpler way to do this?</p>
| [
{
"answer_id": 338640,
"author": "Lars Truijens",
"author_id": 1242,
"author_profile": "https://Stackoverflow.com/users/1242",
"pm_score": 4,
"selected": true,
"text": "property Options default [dgTitles, dgTabs, dgRowSelect, dgAlwaysShowSelection, dgCancelOnExit];\n"
},
{
"answe... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338628",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32914/"
] |
338,657 | <p>I'm working on a web app that needs an ActiveX control to function. It installs just fine when the user has admin privileges, but fails to load otherwise. Is this by design and if so, is this documented somewhere? (preferably MSDN)</p>
| [
{
"answer_id": 7473437,
"author": "taxilian",
"author_id": 229998,
"author_profile": "https://Stackoverflow.com/users/229998",
"pm_score": 3,
"selected": true,
"text": "AtlSetPerUserRegistration(perUser);\n"
}
] | 2008/12/03 | [
"https://Stackoverflow.com/questions/338657",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4086/"
] |
338,658 | <p>Can you round a .NET <code>TimeSpan</code> object?</p>
<p>I have a <code>Timespan</code> value of: 00:00:00.6193789</p>
<p>Is there a simple way to keep it a <code>TimeSpan</code> object but round it to something like<br>
00:00:00.62?</p>
| [
{
"answer_id": 338699,
"author": "mapache",
"author_id": 41422,
"author_profile": "https://Stackoverflow.com/users/41422",
"pm_score": 2,
"selected": false,
"text": "new TimeSpan(tmspan.Hours, tmspan.Minutes, tmspan.Seconds, (int)Math.Round(Convert.ToDouble(tmspan.Milliseconds / 10)));\n... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338658",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36590/"
] |
338,667 | <p>I have to maintain a large number of classic ASP pages, many of which have tabular data with no sort capabilities at all. Whatever order the original developer used in the database query is what you're stuck with.</p>
<p>I want to to tack on some basic sorting to a bunch of these pages, and I'm doing it all client side with javascript. I already have the basic script done to sort a given table on a given column in a given direction, and it works well as long as the table is limited by certain conventions we follow here.</p>
<p>What I want to do for the UI is just indicate sort direction with the caret character ( <code>^</code> ) and ... what? Is there a special character that is the direct opposite of a caret? The letter <code>v</code> won't quite cut it. Alternatively, is there another character pairing I can use?</p>
| [
{
"answer_id": 338686,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 6,
"selected": false,
"text": "ˇ"
},
{
"answer_id": 338695,
"author": "Max Lybbert",
"author_id": 10593,
"author_profile": ... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338667",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3043/"
] |
338,701 | <p>Due to a weird request, I can't put <code>null</code> in a database if there is no value. I'm wondering what can I put in the store procedure for nothing instead of <code>null</code>.</p>
<p>For example: </p>
<pre><code>insert into blah (blah1) values (null)
</code></pre>
<p>Is there something like nothing or empty for "blah1" instead using <code>null</code>?</p>
| [
{
"answer_id": 338720,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 4,
"selected": true,
"text": "NULL"
}
] | 2008/12/03 | [
"https://Stackoverflow.com/questions/338701",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28647/"
] |
338,702 | <h2>How is it possible to call a client side javascript method after a <em>specific</em> update panel has been loaded?</h2>
<p><strong><code>Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler)</code></strong> does not work for me because this will fire after ANY update panel finishes loading, and I can find no client side way to find which is the one</p>
<p><strong><code>ScriptManager.GetCurrent(Page).AsyncPostBackSourceElementID AsyncPostBackSourceElementID</code></strong> does not work for me as this is a server side object, and i want Client Side</p>
<p>The ClientSide .Net framework must know which UpdatePanel it is updating in order to update the correct content. Surely there is a way to hook into this event?</p>
<p>Any help would be appreciated. </p>
| [
{
"answer_id": 338818,
"author": "CountCet",
"author_id": 2636656,
"author_profile": "https://Stackoverflow.com/users/2636656",
"pm_score": 1,
"selected": false,
"text": "string scriptText = \"alert('Bar!');\";\n\nScriptManager.RegisterStartupScript(this.Page, this.GetType(), \"foo\", sc... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338702",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
338,712 | <p>I have a Queue object that I need to ensure is thread-safe. Would it be better to use a lock object like this:</p>
<pre><code>lock(myLockObject)
{
//do stuff with the queue
}
</code></pre>
<p>Or is it recommended to use Queue.Synchronized like this:</p>
<pre><code>Queue.Synchronized(myQueue).whatever_i_want_to_do();
</code></pre>
<p>From reading the MSDN docs it says I should use Queue.Synchronized to make it thread-safe, but then it gives an example using a lock object. From the MSDN article:</p>
<blockquote>
<p>To guarantee the thread safety of the
Queue, all operations must be done
through this wrapper only.</p>
<p>Enumerating through a collection is
intrinsically not a thread-safe
procedure. Even when a collection is
synchronized, other threads can still
modify the collection, which causes
the enumerator to throw an exception.
To guarantee thread safety during
enumeration, you can either lock the
collection during the entire
enumeration or catch the exceptions
resulting from changes made by other
threads.</p>
</blockquote>
<p>If calling Synchronized() doesn't ensure thread-safety what's the point of it? Am I missing something here?</p>
| [
{
"answer_id": 338857,
"author": "Greg Beech",
"author_id": 13552,
"author_profile": "https://Stackoverflow.com/users/13552",
"pm_score": 5,
"selected": false,
"text": "Synchronized"
},
{
"answer_id": 338989,
"author": "Leonidius",
"author_id": 43014,
"author_profile"... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338712",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/343/"
] |
338,719 | <p>Can I write to the end of a 5GB file in Java? This question came up in my office and no one is sure what the answer is.</p>
| [
{
"answer_id": 338747,
"author": "Greg Case",
"author_id": 462,
"author_profile": "https://Stackoverflow.com/users/462",
"pm_score": 5,
"selected": true,
"text": "String filename;\n\nRandomAccessFile myFile = new RandomAccessFile(filename, \"rw\");\n\n// Set write pointer to the end of t... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338719",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1447/"
] |
338,732 | <p>I want to be able to apply a style at runtime to an object <strong>ONLY</strong> if the current style is the default style. I don't want to override any user defined styles. Anyone know how to do this?</p>
| [
{
"answer_id": 338900,
"author": "Jobi Joy",
"author_id": 8091,
"author_profile": "https://Stackoverflow.com/users/8091",
"pm_score": -1,
"selected": false,
"text": "string styleKeyName = DefaultStyleKeyProperty.Name;\n"
},
{
"answer_id": 338949,
"author": "Ryan Lundy",
"... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338732",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17744/"
] |
338,734 | <p>I'm looking to be able to reference certain state/objects through anywhere in my application. For instance, a user logs in to their application, I need to call a web service and retrieve the users information. Then I want to be able to access this information from anywhere in the application with something like the following:</p>
<pre><code>myAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
user = delegate.u;
</code></pre>
<p>Is setting an instance variable as a User object in the app delegate and referencing it from there when needed a poor way of going about it? I typically set it there upon the user's login.</p>
<p>Wanted to hear how the pros handle this one.</p>
| [
{
"answer_id": 338832,
"author": "e.James",
"author_id": 33686,
"author_profile": "https://Stackoverflow.com/users/33686",
"pm_score": 4,
"selected": false,
"text": "// MyCommon.h:\n@interface MyCommon\nclass MyCommon : NSObject\n{\n int user;\n};\n\n@property(assign) int user;\n\n+ (... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338734",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40882/"
] |
338,739 | <p>I have a MySQL table containing domain names:</p>
<pre><code>+----+---------------+
| id | domain |
+----+---------------+
| 1 | amazon.com |
| 2 | google.com |
| 3 | microsoft.com |
| | ... |
+----+---------------+
</code></pre>
<p>I'd like to be able to search through this table for a full hostname (i.e. 'www.google.com'). If it were the other way round where the table contained the full URL I'd use:</p>
<pre><code>SELECT * FROM table WHERE domain LIKE '%google.com%'
</code></pre>
<p>But the inverse is not so straightforward. My current thinking is to search for the full hostname, then progressively strip off each part of the domain, and search again. (i.e. search for 'www.google.com' then 'google.com')</p>
<p>This is not particular efficient or clever, there must be a better way. I am sure it is a common problem, and no doubt easy to solve!</p>
| [
{
"answer_id": 338755,
"author": "Greg",
"author_id": 24181,
"author_profile": "https://Stackoverflow.com/users/24181",
"pm_score": 5,
"selected": true,
"text": "SELECT domain FROM table WHERE 'www.google.com' LIKE CONCAT('%', domain);\n"
},
{
"answer_id": 338770,
"author": "... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338739",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42974/"
] |
338,740 | <p>Currently I have the function CreateLog() for creating a a log4net Log with name after the constructing instance's class.
Typically used as in:</p>
<pre><code>class MessageReceiver
{
protected ILog Log = Util.CreateLog();
...
}
</code></pre>
<p>If we remove lots of error handling the implementation boils down to:
[EDIT: Please read the longer version of CreateLog further on in this post.]</p>
<pre><code>public ILog CreateLog()
{
System.Diagnostics.StackFrame stackFrame = new System.Diagnostics.StackFrame(1);
System.Reflection.MethodBase method = stackFrame.GetMethod();
return CreateLogWithName(method.DeclaringType.FullName);
}
</code></pre>
<p>Problem is that if we inheirit MessageReceiver into sub classes the log will still take its name from MessageReceiver since this is the declaring class of the method (constructor) which calls CreateLog.</p>
<pre><code>class IMReceiver : MessageReceiver
{ ... }
class EmailReceiver : MessageReceiver
{ ... }
</code></pre>
<p>Instances of both these classes would get Logs with name "MessageReceiver" while I would like them to be given names "IMReceiver" and "EmailReceiver".</p>
<p>I know this can easily be done (and is done) by passing a reference to the object in creation when calling CreateLog since the GetType() method on object does what I want.</p>
<p>There are some minor reasons to prefer not adding the parameter and personally I feel disturbed by not finding a solution with no extra argument.</p>
<p>Is there anyone who can show me how to implement a zero argument CreateLog() that gets the name from the subclass and not the declaring class?</p>
<p>EDIT:</p>
<p>The CreateLog function does more than mentioned above. The reason for having one log per instance is to be able to differ between different instances in the logfile. This is enforced by the CreateLog/CreateLogWithName pair.</p>
<p>Expanding on the functionality of CreateLog() to motivate its existence.</p>
<pre><code>public ILog CreateLog()
{
System.Diagnostics.StackFrame stackFrame = new System.Diagnostics.StackFrame(1);
System.Reflection.MethodBase method = stackFrame.GetMethod();
Type type = method.DeclaringType;
if (method.IsStatic)
{
return CreateLogWithName(type.FullName);
}
else
{
return CreateLogWithName(type.FullName + "-" + GetAndInstanceCountFor(type));
}
}
</code></pre>
<p>Also I prefer writing ILog Log = Util.CreateLog(); rather than copying in some long cryptic line from an other file whenever I write a new class. I am aware that the reflection used in Util.CreateLog is not guaranteed to work though - is System.Reflection.MethodBase.GetCurrentMethod() guaranteed to work?</p>
| [
{
"answer_id": 338760,
"author": "Orion Edwards",
"author_id": 234,
"author_profile": "https://Stackoverflow.com/users/234",
"pm_score": 2,
"selected": true,
"text": "IMReceiver"
},
{
"answer_id": 338904,
"author": "Mike Two",
"author_id": 23659,
"author_profile": "ht... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338740",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41884/"
] |
338,762 | <p>How do you calculate the angle between two normals in glsl? I am trying to add the fresnel effect to the outer edges of an object (combining that effect with phong shading), and I think that the angle is the only thing I am missing.</p>
<p>Fragment Shader:</p>
<pre><code>varying vec3 N;
varying vec3 v;
void main(void) {
v = vec3(gl_ModelViewMatrix * gl_Vertex);
N = normalize(gl_NormalMatrix * gl_Normal);
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
</code></pre>
<p>Vertex Shader:</p>
<pre><code>varying vec3 N;
varying vec3 v;
void main(void) {
vec3 L = normalize(gl_LightSource[0].position.xyz - v);
vec3 E = normalize(-v);
vec3 R = normalize(-reflect(L,N));
vec4 Iamb = gl_FrontLightProduct[0].ambient
vec4 Idiff = gl_FrontLightProduct[0].diffuse * max(dot(N,L), 0.0);
vec4 Ispec = gl_FrontLightProduct[0].specular * pow(max(dot(R,E),0.0), gl_FrontMaterial.shininess);
vec4 Itot = gl_FrontLightModelProduct.sceneColor + Iamb + Idiff + Ispec;
vec3 A = //calculate the angle between the lighting direction and the normal//
float F = 0.33 + 0.67*(1-cos(A))*(1-cos(A))*(1-cos(A))*(1-cos(A))*(1-cos(A));
vec4 white = {1.0, 1.0, 1.0, 1.0};
gl_FragColor = F*white + (1.0-F)*Itot;
}
</code></pre>
<p>varying vec3</p>
| [
{
"answer_id": 338801,
"author": "David Norman",
"author_id": 34502,
"author_profile": "https://Stackoverflow.com/users/34502",
"pm_score": 3,
"selected": false,
"text": "cos A = DotProduct(v1, v2) / (Length(v1) * Length(v2))\n"
},
{
"answer_id": 340248,
"author": "NeARAZ",
... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338762",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
338,767 | <p>I have a some .py files that use spaces for indentation, and I'd like to convert them to tabs.</p>
<p>I could easily hack together something using regexes, but I can think of several edge cases where this approach could fail. Is there a tool that does this by parsing the file and determining the indentation level the same way the python interpreter does?</p>
| [
{
"answer_id": 338791,
"author": "wimh",
"author_id": 33499,
"author_profile": "https://Stackoverflow.com/users/33499",
"pm_score": 4,
"selected": false,
"text": ":retab"
},
{
"answer_id": 338929,
"author": "Greg",
"author_id": 13009,
"author_profile": "https://Stacko... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338767",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1595/"
] |
338,768 | <p>Python is installed in a local directory. </p>
<p>My directory tree looks like this:</p>
<pre><code>(local directory)/site-packages/toolkit/interface.py
</code></pre>
<p>My code is in here:</p>
<pre><code>(local directory)/site-packages/toolkit/examples/mountain.py
</code></pre>
<p>To run the example, I write <code>python mountain.py</code>, and in the code I have:</p>
<pre><code>from toolkit.interface import interface
</code></pre>
<p>And I get the error:</p>
<pre><code>Traceback (most recent call last):
File "mountain.py", line 28, in ?
from toolkit.interface import interface
ImportError: No module named toolkit.interface
</code></pre>
<p>I have already checked <code>sys.path</code> and there I have the directory <code>/site-packages</code>. Also, I have the file <code>__init__.py.bin</code> in the toolkit folder to indicate to Python that this is a package. I also have a <code>__init__.py.bin</code> in the examples directory.</p>
<p>I do not know why Python cannot find the file when it is in <code>sys.path</code>. Any ideas? Can it be a permissions problem? Do I need some execution permission?</p>
| [
{
"answer_id": 338790,
"author": "orip",
"author_id": 37020,
"author_profile": "https://Stackoverflow.com/users/37020",
"pm_score": 4,
"selected": false,
"text": "__init__.py"
},
{
"answer_id": 338858,
"author": "igorgue",
"author_id": 29253,
"author_profile": "https:... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338768",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39160/"
] |
338,772 | <p>I saw this sentence in some matrials:</p>
<p>"In Java, simple data types such as int and char operate just as in C."</p>
<p>I am wondering that actually they are different in Java & C++?</p>
<p>In C++, simple variables like the primitives in Java are assigned a memory address as well, so these primitive types in C++ can have a pointer as well. However primitives in Java are not assigned a memory address like Objects are. </p>
<p>Am I correct?</p>
<p>Thanks!</p>
| [
{
"answer_id": 338797,
"author": "Richard Walton",
"author_id": 15075,
"author_profile": "https://Stackoverflow.com/users/15075",
"pm_score": -1,
"selected": false,
"text": "int x = 5;\nint y = x;\n\ny++;\n\n// y = 6\n// x = 5\n"
}
] | 2008/12/03 | [
"https://Stackoverflow.com/questions/338772",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36064/"
] |
338,776 | <p>I'm trying to convert an Excel document into a table in SQL 2005. I found the link below and am wondering if it looks like a solution. If so, what would the @excel_full_file_name syntax be and where would the path be relative to? </p>
<p><a href="http://www.siccolo.com/Articles/SQLScripts/how-to-create-sql-to-convert-Excel_to_table.html" rel="nofollow noreferrer">http://www.siccolo.com/Articles/SQLScripts/how-to-create-sql-to-convert-Excel_to_table.html</a></p>
| [
{
"answer_id": 343345,
"author": "Coolcoder",
"author_id": 42434,
"author_profile": "https://Stackoverflow.com/users/42434",
"pm_score": 4,
"selected": true,
"text": "BULK \nINSERT YourDestinationTable\n FROM 'D:\\YourFile.csv'\n WITH\n (\n FIELDTERMIN... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338776",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13954/"
] |
338,809 | <p>Tip me plase, how to insert a null value into table using Trolltech Qt 4.x SQL classes? <code>QSqlQuery</code>, I guess, or something else from QtNetwork.
As analog of it, in .NET there is the <code>System.DbNull</code> class, which represents sql NULL.</p>
<p>And what type should I use for some object's property, that can hold both null-value and <code>QString</code>? In C# I could use <code>System.Object</code>.</p>
| [
{
"answer_id": 338819,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 6,
"selected": true,
"text": "QSqlQuery::addBindValue"
},
{
"answer_id": 19008310,
"author": "0xF",
"author_id": 2032514,
... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338809",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41956/"
] |
338,813 | <p>I need a small, portable framework for logging on embedded linux. Ideally it would output to a file or a socket, and having some sort of log rotation/compression would also be nice.</p>
<p>So far, I've found a lot of frameworks, but almost all of them have daunting build procedures or require the use of application frameworks (e.g. log4cxx requires the Apache Portable Runtime, which I'd rather not bother with...).</p>
<p>Just looking for something simple and robust, but everything I seem to find is complicated or requires lots of secondary junk just to run.</p>
<p>Suggestions? (and if the answer is roll my own, that's fine, but...it's be great to avoid that)</p>
| [
{
"answer_id": 338863,
"author": "Ilya",
"author_id": 6807,
"author_profile": "https://Stackoverflow.com/users/6807",
"pm_score": 0,
"selected": false,
"text": "DBG_E DBG_W DBG_TRACE"
}
] | 2008/12/03 | [
"https://Stackoverflow.com/questions/338813",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
338,816 | <p>The controllers in my ASP.NET MVC web app are starting to get a bit bloated with business logic. The examples on the web all show simple controller actions that simply pull data out of a repository and pass it to the view. But what if you also need to support business logic on top of that? </p>
<p>Say, for instance, an action that fulfills an order also needs to send an e-mail out. Do I stick this in the controller and copy/paste this logic to any other actions that also fulfill orders? My first intuition would be to create a service like OrderFulfillerService that would take care of all this logic and have the controller action call that. However, for simple operations like retrieving a list of users or orders from the database, I would like to interact directly with the repository instead of having that call wrapped by a service.</p>
<p>Is this an acceptable design pattern? Controller actions call services when they need business logic and repositories when they just need data access?</p>
| [
{
"answer_id": 339234,
"author": "Tim Scott",
"author_id": 29493,
"author_profile": "https://Stackoverflow.com/users/29493",
"pm_score": 1,
"selected": false,
"text": "public Customer GetCustomer(int id)\n{\n return customerRepository.Get(id);\n}\n"
},
{
"answer_id": 339359,
... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338816",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1574/"
] |
338,817 | <p>I'm generating a menu with a Repeater control bound to an XmlDataSource. </p>
<pre><code><asp:Repeater ID="myRepeater" runat="server"
DataSourceID="myDataSource"
onitemdatabound="myRepeater_ItemDataBound"
onitemcreated="myRepeater_ItemCreated">
<HeaderTemplate>
<ul class="menu_list">
</HeaderTemplate>
<ItemTemplate>
<li id="liMenu" runat="server"><asp:HyperLink ID="hrefMenuItem" runat="server" Text='<%# XPath("@text")%>' NavigateUrl='<%# XPath("@href")%>'></asp:HyperLink></li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
<asp:XmlDataSource runat="server" ID ="myDataSource" XPath="Menu/Items/*" EnableCaching="False" />
</code></pre>
<p>I'd like to be able to set the style of the containing LI based on mouseover events and currently selected menu item. I tried via the HtmlGenericControl, but I receive an error that it's readonly.</p>
<pre><code>protected void myRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
HyperLink hrefCurrentMenuLink = e.Item.FindControl("hrefMenuItem") as HyperLink;
HtmlGenericControl l_genericControl = e.Item.FindControl("liMenu") as HtmlGenericControl;
if ((hrefCurrentMenuLink != null) && (l_genericControl != null))
{
string l_currentPage = GetCurrentWebPage();
if (String.Compare(Path.GetFileNameWithoutExtension(hrefCurrentMenuLink.NavigateUrl), l_currentPage, StringComparison.OrdinalIgnoreCase) == 0)
l_genericControl.Style = "on-nav";
else
l_genericControl.Style = "off-nav";
l_genericControl.Attributes.Add("onmouseover", "navOn(this)");
l_genericControl.Attributes.Add("onmouseout", "navOff(this)");
}
}
}
</code></pre>
<p>Is there any way to accomplish this?</p>
| [
{
"answer_id": 338843,
"author": "Michael Haren",
"author_id": 29,
"author_profile": "https://Stackoverflow.com/users/29",
"pm_score": 4,
"selected": true,
"text": "l_genericControl.Style.Add(\"css-name\", \"css-value\")\n"
},
{
"answer_id": 338939,
"author": "Jimmy",
"au... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338817",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27870/"
] |
338,824 | <p>Subversion lets you embed working copies of other repositories using <a href="http://svnbook.red-bean.com/en/1.1/ch07s04.html" rel="nofollow noreferrer">externals</a>, allowing easy version control of third-party library software in your project.</p>
<p>While these seem ideal for the reuse of libraries and version control of <a href="http://svnbook.red-bean.com/en/1.1/ch07s05.html" rel="nofollow noreferrer">vendor software</a>, they aren't without <a href="https://stackoverflow.com/questions/222827/how-do-you-organize-your-version-control-repository#304036">their critics</a>:</p>
<blockquote>
<p>Please don't use Subversion externals (or similar in other tools), they are an anti-pattern and, therefore, unnecessary</p>
</blockquote>
<p>Are there hidden risks in using externals? Please explain why they would they be considered an antipattern.</p>
| [
{
"answer_id": 345404,
"author": "Rob Williams",
"author_id": 26682,
"author_profile": "https://Stackoverflow.com/users/26682",
"pm_score": 7,
"selected": true,
"text": "svn:external"
}
] | 2008/12/03 | [
"https://Stackoverflow.com/questions/338824",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20074/"
] |
338,836 | <p>I have a GridView with several fields, one of which can potentially have a crazy wide value in it like this:</p>
<p>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</p>
<p>If <em>that</em> sort of thing is in the field, I want it to wrap.</p>
<p>I can easily insert a character in code every 50 characters or so...but what character? If I use <strong>\r\n</strong> or a <strong>space</strong> or the like, then sometimes the setting doesn't wrap (because a different row's 50 chars is wider), and I get something like this:</p>
<p>mmmmmmmmmm<br>
mmmmm<br>
llllllllll llllllllll llll</p>
<p>I don't want those spaces to show up; I just want the line to wrap there if it can, but otherwise to show nothing:</p>
<p>mmmmmmmmmm<br>
mmmmm<br>
llllllllllllllllllllllll</p>
<p>Also, I'd rather leave HtmlEncode <em>on</em> if possible. Is there a way to do this?</p>
| [
{
"answer_id": 338901,
"author": "Matt Briggs",
"author_id": 10771,
"author_profile": "https://Stackoverflow.com/users/10771",
"pm_score": 2,
"selected": false,
"text": "white-space: -moz-pre-wrap; /* Mozilla, supported since 1999 */\nwhite-space: -pre-wrap; /* Opera 4 - 6 */ \nwhite-spa... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338836",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5486/"
] |
338,856 | <p>Is there a way that I can do a select as such</p>
<pre><code>select * from attributes where product_id = 500
</code></pre>
<p>would return </p>
<pre><code>id name description
1 wheel round and black
2 horn makes loud noise
3 window solid object you can see through
</code></pre>
<p>and the query</p>
<pre><code>select * from attributes where product_id = 234
</code></pre>
<p>would return the same results as would any query to this table.</p>
<p>Now obviously I could just remove the where clause and go about my day. But this involves editing code that I don't really want to modify so i'm trying to fix this at the database level. </p>
<p>So is there a "magical" way to ignore what is in the where clause and return whatever I want using a view or something ?</p>
| [
{
"answer_id": 339049,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 1,
"selected": false,
"text": "SELECT ordinal_position, column_name, column_comment\nFROM INFORMATION_SCHEMA.columns\nWHERE table_name = 'products' A... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338856",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5261/"
] |
338,887 | <p>I'm looking at some GXT code for GWT and I ran across this use of Generics that I can't find another example of in the Java tutorials. The class name is <a href="http://extjs.com/deploy/gxtdocs/com/extjs/gxt/ui/client/data/BaseModelData.html" rel="noreferrer"><code>com.extjs.gxt.ui.client.data.BaseModelData</code></a> if you want to look at all of the code. Here are the important parts:</p>
<pre><code>private RpcMap map;
public <X> X get(String property) {
if (allowNestedValues && NestedModelUtil.isNestedProperty(property)) {
return (X)NestedModelUtil.getNestedValue(this, property);
}
return map == null ? null : (X) map.get(property);
}
</code></pre>
<p><code>X</code> is defined nowhere else in the class or anywhere in the hierarchy, and when I hit "go to declaration" in eclipse it just goes to the <code><X></code> in the public method signature.</p>
<p>I've tried to call this method with the following two examples to see what happens:</p>
<pre><code>public Date getExpiredate() {
return get("expiredate");
}
public String getSubject() {
return get("subject");
}
</code></pre>
<p>They compile and show no errors or warnings. I would think at the very least I would have to do a cast to get this to work.</p>
<p>Does this mean that Generics allow a magic return value that can be anything and will just blow up at runtime? This seems counter to what generics are supposed to do. Can anyone explain this to me and possibly give me a link to some documentation that explains this a little better? I've went through Sun's 23 page pdf on generics and every example of a return value is defined either at the class level or is in one of the parameters passed in.</p>
| [
{
"answer_id": 338906,
"author": "sblundy",
"author_id": 4893,
"author_profile": "https://Stackoverflow.com/users/4893",
"pm_score": 5,
"selected": false,
"text": "<X>"
},
{
"answer_id": 338913,
"author": "Rich",
"author_id": 42897,
"author_profile": "https://Stackove... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338887",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42994/"
] |
338,895 | <p>In earlier versions of MS-DOS - I want to say version 7, but I could be wrong - there was a <code>deltree</code> command, which recursively deleted all subdirectories and files from a given path. </p>
<p><code>deltree</code> no longer exists, but <code>del</code> didn't seem to inherit the ability to delete a tree. <code>del /s</code> deletes files, but not folders.</p>
<p>How to you easily (i.e., in one command) delete a tree from a batch file?</p>
| [
{
"answer_id": 338905,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 3,
"selected": false,
"text": "rmdir /s /q directory\n"
},
{
"answer_id": 338921,
"author": "Jeremiah",
"author_id": 34183,
"author... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338895",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2197/"
] |
338,927 | <p>Given the following Flash method:</p>
<pre><code>function sendToJava(name:String, ... args)
{
ExternalInterface.call("sendCommand", name, args);
}
</code></pre>
<p>How do I ensure that ExternalInterface.call() interprets args in its expanded form? Right now, if I pass a list into "args", that list gets interpreted as a single argument of type "Object[]" by ExternalInterface.call(). When the arguments reach Java, I have no way of differentiating between multiple arguments separated by commas versus a single argument containing commas as part of its value.</p>
| [
{
"answer_id": 339001,
"author": "Gili",
"author_id": 14731,
"author_profile": "https://Stackoverflow.com/users/14731",
"pm_score": 1,
"selected": false,
"text": "function sendToJava(name:String, ... args)\n{\n // See Array.unshift()\n args.unshift(\"sendCommand\", name);\n\n // See F... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338927",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14731/"
] |
338,928 | <p>I have a php script which accesses a MSSQL2005 database, reads some data from it and sends the results in a mail. </p>
<p>There are special characters in both some column names and in the fields itself. </p>
<p>When I access the script through my browser (webserver iis), the query is executed correctly and the contents of the mail are correctly (for my audience) encoded.
However, when I execute php from the console, the query fails (due to the special characters in the column names). If I replace the special characters in the query with calls to chr() and the character code in latin-1, the query gets executed correctly, but the results are also encoded in latin-1 and therefore not displayed correctly in the mail.
Why is PHP/the MSSQL driver/… using a different encoding in the two scenarios? Is there a way around it? </p>
<p>If you wonder, I need the console because I want to schedule the script using SQLAgent (or taskmanager or whatever).</p>
| [
{
"answer_id": 364615,
"author": "david",
"author_id": 27600,
"author_profile": "https://Stackoverflow.com/users/27600",
"pm_score": 1,
"selected": false,
"text": "$send_string = base64_encode(utf8_decode($database_string));\n"
},
{
"answer_id": 364738,
"author": "lpfavreau",... | 2008/12/03 | [
"https://Stackoverflow.com/questions/338928",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5218/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.