qid int64 4 19.1M | question stringlengths 18 48.3k | answers list | date stringlengths 10 10 | metadata list |
|---|---|---|---|---|
406,667 | <p>I'm teaching myself Objective-C from a book (<em>Cocoa programming for mac OS X</em>) and am about halfway through however I have two questions that aren't answered or defined in the book.</p>
<ol>
<li><p>When defining class methods what is the difference between (assuming there in a .h file):</p>
<p>- (int) population;</p>
<p>+ (int) population;</p></li>
</ol>
<p>The way I see it at the moment is that <code>-</code> methods require the class to be allocated and initialized first however <code>+</code> can be called statically without requiring allocation and initialization. E.g. (in a function in another class)</p>
<pre><code>// Using -
Earth *world = [[Earth alloc] init];
int population = [world population];
// Using +
int population = [Earth population];
</code></pre>
<p>If that is correct, when should I use static methods and are they're any disadvantages with doing so.</p>
<ol start="2">
<li><p>When defining a var in either a function paramater or as an actual var in a function, does the use of * mean the var will be an object? e.g. (again in a header file.)</p>
<p>- (void) setPopulation: (NSNumber *) population; //Use of * as population is of NSNumber</p>
<p>- (void) setPopulation: (int) population; // population isn't a class so doesn't need *</p></li>
</ol>
<p>Sorry if any of my terms don't make sense in the land of Objective-C such as static methods, etc. I'm a PHP and Ruby Programmer.</p>
| [
{
"answer_id": 406698,
"author": "Jason Coco",
"author_id": 34218,
"author_profile": "https://Stackoverflow.com/users/34218",
"pm_score": 5,
"selected": true,
"text": "@interface MyObject : NSObject\n-(void)myInstanceMethod;\n+(void)myClassMethod;\n@end\n\n// ...\n\nMyObject* obj = [[MyO... | 2009/01/02 | [
"https://Stackoverflow.com/questions/406667",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/313002/"
] |
406,682 | <p>I'm having a little problem with the following:</p>
<p>When I execute this line:</p>
<pre><code>echo exec(createDir($somevariable));
</code></pre>
<p>I get this error:</p>
<pre><code>Warning: exec() [function.exec]: Cannot execute a blank command in /home/mydir/myfile.inc.php on line 32
</code></pre>
<p>Any ideas.</p>
<p>Thanks.</p>
| [
{
"answer_id": 406688,
"author": "Max",
"author_id": 50023,
"author_profile": "https://Stackoverflow.com/users/50023",
"pm_score": -1,
"selected": false,
"text": "exec(\"mkdir $somevariable\");"
},
{
"answer_id": 406691,
"author": "okoman",
"author_id": 35903,
"author... | 2009/01/02 | [
"https://Stackoverflow.com/questions/406682",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1071/"
] |
406,695 | <p>I want to (quickly) put a program/script together to read the fileset from a .torrent file. I want to then use that set to delete any files from a specific directory that do not belong to the torrent.</p>
<p>Any recommendations on a handy library for reading this index from the .torrent file? Whilst I don't object to it, I don't want to be digging deep into the bittorrent spec and rolling a load of code from scratch for this simple purpose.</p>
<p>I have no preference on language.</p>
| [
{
"answer_id": 406809,
"author": "Benedikt Waldvogel",
"author_id": 4308,
"author_profile": "https://Stackoverflow.com/users/4308",
"pm_score": 5,
"selected": false,
"text": "import libtorrent\ninfo = libtorrent.torrent_info('test.torrent')\nfor f in info.files():\n print \"%s - %s\" ... | 2009/01/02 | [
"https://Stackoverflow.com/questions/406695",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1820/"
] |
406,731 | <p>I've been trying to push my mentallity when developing at home to be geared more towards TDD and a bit DDD. </p>
<p>One thing I don't understand though is why you would create a fake repository to test against? I haven't really looked into it much but surely the idea of testing is to help decouple your code (giving you more flexability), trim down code needed and bring down the number of bugs.</p>
<p>So can someone fill in my foolish brain as to why some like to test fake repositories? I would have thought testing against a real database is a much better alternative to creating a fake one because then you KNOW that it works against your real world data store.</p>
| [
{
"answer_id": 406910,
"author": "joel.neely",
"author_id": 3525,
"author_profile": "https://Stackoverflow.com/users/3525",
"pm_score": 2,
"selected": false,
"text": "HashMap"
}
] | 2009/01/02 | [
"https://Stackoverflow.com/questions/406731",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26081/"
] |
406,760 | <p>This is definitely subjective, but I'd like to try to avoid it becoming argumentative. I think it could be an interesting question if people treat it appropriately.</p>
<p>The idea for this question came from the comment thread from <a href="https://stackoverflow.com/questions/282329/what-are-five-things-you-hate-about-your-favorite-language#282342">my answer</a> to the <a href="https://stackoverflow.com/questions/282329">"What are five things you hate about your favorite language?" question</a>. I contended that classes in C# should be sealed by default - I won't put my reasoning in the question, but I might write a fuller explanation as an answer to this question. I was surprised at the heat of the discussion in the comments (25 comments currently).</p>
<p>So, what contentious opinions do <em>you</em> hold? I'd rather avoid the kind of thing which ends up being pretty religious with relatively little basis (e.g. brace placing) but examples might include things like "unit testing isn't actually terribly helpful" or "public fields are okay really". The important thing (to me, anyway) is that you've got reasons behind your opinions.</p>
<p>Please present your opinion and reasoning - I would encourage people to vote for opinions which are well-argued and interesting, whether or not you happen to agree with them.</p>
| [
{
"answer_id": 406807,
"author": "Pablo Fernandez",
"author_id": 7595,
"author_profile": "https://Stackoverflow.com/users/7595",
"pm_score": 9,
"selected": false,
"text": "private fields + public accessors == encapsulation"
},
{
"answer_id": 406930,
"author": "fizzer",
"a... | 2009/01/02 | [
"https://Stackoverflow.com/questions/406760",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22656/"
] |
406,776 | <p><em>Removed link, problem solved</em></p>
<p>The menu at the top is supposed to be a dropdown menu, but it expands to the right instead. </p>
<p>My CSS is this (I believe this is the relevant bit anyway)</p>
<pre><code>#primary-nav, #primary-nav ul { list-style: none; margin: 0px; padding: 0px; }
#primary-nav ul { position: absolute; top: auto; display: none; }
#primary-nav ul ul { left: 100%; top: 0px; }
#primary-nav li { float: left; }
#primary-nav li li { float: none; position: relative; }
#primary-nav ul, #primary-nav li:hover ul, #primary-nav li:hover ul ul,
#primary-nav li.menuparenth ul, #primary-nav li.menuparenth ul ul { display: none; }
#primary-nav li:hover ul, #primary-nav ul li:hover ul, #primary-nav ul ul li:hover ul,
#primary-nav li.menuparenth ul, #primary-nav ul li.menuparenth ul,
#primary-nav ul ul li.menuparenth ul { display: block; }
</code></pre>
<p>I have no clue where exactly the direction for the menu is set.</p>
| [
{
"answer_id": 406784,
"author": "stuartloxton",
"author_id": 313002,
"author_profile": "https://Stackoverflow.com/users/313002",
"pm_score": 2,
"selected": false,
"text": "position: absolute; #primary-nav ul"
},
{
"answer_id": 408663,
"author": "Community",
"author_id": ... | 2009/01/02 | [
"https://Stackoverflow.com/questions/406776",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42389/"
] |
406,791 | <p>I'm having a problem with the following code snippet:</p>
<pre><code>using System;
using System.Collections.Generic;
using System.Text;
namespace trees_by_firas
{
class Program
{
static void Main(string[] args)
{
BinarySearchTree t = new BinarySearchTree();
t.insert(ref t.root, 10);
t.insert(ref t.root, 5);
t.insert(ref t.root, 6);
t.insert(ref t.root, 17);
t.insert(ref t.root, 2);
t.insert(ref t.root, 3);
BinarySearchTree.print(t.root);
Console.WriteLine("--------------------");
Console.WriteLine(t.FindMax());
Console.WriteLine(t.FindMin());
Console.WriteLine("--------------------");
Console.WriteLine(t.CountLeaves());
Console.WriteLine(t.CountNodes());
}
public class TreeNode
{
public int n;
public TreeNode _left;
public TreeNode _right;
public TreeNode(int n, TreeNode _left, TreeNode _right)
{
this.n = n;
this._left = _left;
this._right = _right;
}
public void DisplayNode()
{
Console.Write(n);
}
}
public class BinarySearchTree
{
public TreeNode root;
public BinarySearchTree()
{
root = null;
}
public void insert(ref TreeNode root, int x)
{
if (root == null)
{
root = new TreeNode(x, null, null);
}
else
if (x < root.n)
insert(ref root._left, x);
else
insert(ref root._right, x);
}
public int FindMin()
{
TreeNode current = root;
while (current._left != null)
current = current._left;
return current.n;
}
public int FindMax()
{
TreeNode current = root;
while (current._right != null)
current = current._right;
return current.n;
}
public TreeNode Find(int key)
{
TreeNode current = root;
while (current.n != key)
{
if (key < current.n)
current = current._left;
else
current = current._right;
if (current == null)
return null;
}
return current;
}
public void InOrder(ref TreeNode root)
{
if (root != null)
{
InOrder(ref root._left);
root.DisplayNode();
InOrder(ref root._right);
}
}
public int CountNodes()
{
int count = 1; // me!
if (root._left != null)
count += _left.CountNodes();
if (root._right != null)
count += _right.CountNodes();
return count;
}
public int CountLeaves()
{
int count = (root._left == null && root._right == null) ? 1 : 0;
if (root._left != null)
count += _left.CountLeaves();
if (root._right != null)
count += _right.CountLeaves();
return count;
}
public static void print(TreeNode root)
{
if (root != null)
{
print(root._left);
Console.WriteLine(root.n.ToString());
print(root._right);
}
}
}
}
}
</code></pre>
<hr>
<p>I get the following errors:</p>
<pre><code>Error 1 The name '_left' does not exist in the current context
// on the countnodes & countleaves
Error 2 The name '_right' does not exist in the current context
// on the countnodes & countleaves
</code></pre>
<p>Any thoughts on how I can fix these errors?</p>
| [
{
"answer_id": 406796,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 2,
"selected": false,
"text": "root. public int CountNodes()\n{\n int count = 1; // me! \n if (root._left != null)\n count += root.... | 2009/01/02 | [
"https://Stackoverflow.com/questions/406791",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
406,810 | <p>I have a html page A and a link in the page which opens up page B in a new window. How to reload the page A on clicking and opening this link ? </p>
<p><strong>EDIT:</strong></p>
<p>I should have been more clear. Page B opens in a new window and not as a popup. The hyperlink in question has its target attribute set to _blank. Taking a clue from the answers that I got (Thanks guys !), I tried setting onclick = "window.location.reload()" and it works perfectly fine.</p>
<p>However I have a problem. In fact another question altogether. How to make sure that the reload of page A waits until the page opened in the new window (page B) loads ?</p>
| [
{
"answer_id": 406817,
"author": "Mark Davidson",
"author_id": 50866,
"author_profile": "https://Stackoverflow.com/users/50866",
"pm_score": 1,
"selected": false,
"text": "<a href=\"# \" onClick=\"window.open('newPage.htm','window','width=400,height=200')\">link</a>\n"
},
{
"answ... | 2009/01/02 | [
"https://Stackoverflow.com/questions/406810",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27474/"
] |
406,813 | <p>I have a contactbook, and a form close to it... For the form, one of the requirements is to fill in the receiver for the message. So when the user clicks on a contact from the contactbook, automaticly the username from the titel-tag should appear in the receiver inpunt in the form.</p>
<p>All help with this is appreciated!!</p>
| [
{
"answer_id": 406839,
"author": "stuartloxton",
"author_id": 313002,
"author_profile": "https://Stackoverflow.com/users/313002",
"pm_score": 1,
"selected": false,
"text": "<title> jQuery(function() {\n jQuery('a.addTitleTag').click(function() {\n titleText = document.title; //... | 2009/01/02 | [
"https://Stackoverflow.com/questions/406813",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/50896/"
] |
406,830 | <p>Is there a way in Java to declare an enumeration whose values can be used together? For example:</p>
<pre><code>enum FileAccess { Read, Write, ReadWrite }
</code></pre>
<p>Is it possible to define ReadWrite as <code>Read | Write</code> (or anything that would yield the same result)?</p>
| [
{
"answer_id": 406841,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 6,
"selected": true,
"text": "EnumSet<FileAccess> readWrite = EnumSet.of(FileAccess.Read, FileAccess.Write);\n"
},
{
"answer_id": 406845,
"... | 2009/01/02 | [
"https://Stackoverflow.com/questions/406830",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41283/"
] |
406,866 | <p>I'm calling a SSIS package using LoadPackage(...).</p>
<p>Is it possible to make this call an Asynchronous call?</p>
| [
{
"answer_id": 406974,
"author": "JaredPar",
"author_id": 23283,
"author_profile": "https://Stackoverflow.com/users/23283",
"pm_score": 0,
"selected": false,
"text": "using System.Threading.Tasks;\n...\nvar future = Future.Create(()=>LoadPackage); // Starts loading the package\n// Do oth... | 2009/01/02 | [
"https://Stackoverflow.com/questions/406866",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39677/"
] |
406,880 | <p>I've used the following code to map <a href="https://live.example.com" rel="nofollow noreferrer">https://live.example.com</a> on to <a href="http://example.com/api" rel="nofollow noreferrer">http://example.com/api</a></p>
<pre><code>Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTPS} =on
RewriteCond %{HTTP_HOST} ^live\.example\.com [NC]
RewriteRule (.+)$ "http://example.com/api/$1" [L,P]
</code></pre>
<p>The following url:</p>
<pre><code>https://live.example.com/userlinks/xml/John%20James/MvPjeUTo15/
</code></pre>
<p>Is suppose to map onto:</p>
<pre><code>http://example.com/api/userlinks/xml/John%20James/MvPjeUTo15/
</code></pre>
<p>Instead it maps it to:</p>
<pre><code>http://example.com/api/userlinks/xml/John
</code></pre>
<p>So it seems to cut it at the space. I am using the Codeigniter framework but I am not sure if the problem lies there.</p>
<p>Also using <code>%20</code> or just a space in the url bar produces no different results.</p>
<p>Anyone any idea and/or solution why this happens?</p>
<p>Thank you very much,</p>
<p>Ice</p>
| [
{
"answer_id": 406983,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "RewriteMap escapemap int:escape \n Options +FollowSymLinks\n\nRewriteEngine On \n\nRewriteCond %{HTTPS} =on\nRewriteCond \"%{H... | 2009/01/02 | [
"https://Stackoverflow.com/questions/406880",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
406,903 | <p>I need a template like this, which work perfectly</p>
<pre><code>template <typename container> void mySuperTempalte (const container myCont)
{
//do something here
}
</code></pre>
<p>then i want to specialize the above template for std::string so i came up with</p>
<pre><code>template <typename container> void mySuperTempalte (const container<std::string> myCont)
{
//check type of container
//do something here
}
</code></pre>
<p>which doesnt't work, and throws an error. I would like to make the second example work and then IF possible i would like to add some code in the template to check if a std::vector/std::deque/std::list was used, to do something differently in each case.
So i used templates because 99% of the code is the same for both vectors and deques etc.</p>
| [
{
"answer_id": 406935,
"author": "sep",
"author_id": 30333,
"author_profile": "https://Stackoverflow.com/users/30333",
"pm_score": 3,
"selected": false,
"text": "template<> void mySuperTempalte<std:string>(const std::string myCont)\n{\n //check type of container\n //do something he... | 2009/01/02 | [
"https://Stackoverflow.com/questions/406903",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28954/"
] |
406,912 | <p>I have 2 textbox in my asp.net page and also have one hiddenfield in my asp.net page , my hiddenfield will always have numeric value like 123.00 , and in my one textbox also I will always have numeric value like 20.00 now I want to add this hiddenfield value and textbox value and display it into second textbox thru javascript </p>
<p>I wrote the following code to do this </p>
<pre><code>var amt = document.getElementById("txtsecond");
var hiddenamt = document.getElementById("AmtHidden").value
var fee = document.getElementById("txtFirst").value;
amt.value = hiddenamt + fee;
</code></pre>
<p>this should give me result like 123.00+20.00 = 143.00 but this is concatnating hiddenamt value and fee value and giving me result like 12320.00 in my first textbox </p>
<p>can anybody suggest me what is wrong in my code and what is the right way to get desired value</p>
| [
{
"answer_id": 406920,
"author": "annakata",
"author_id": 13018,
"author_profile": "https://Stackoverflow.com/users/13018",
"pm_score": 2,
"selected": false,
"text": "parseFloat(foo)"
},
{
"answer_id": 406922,
"author": "epascarello",
"author_id": 14104,
"author_profi... | 2009/01/02 | [
"https://Stackoverflow.com/questions/406912",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14299/"
] |
406,915 | <p>Andreas Huber's answer to <a href="https://stackoverflow.com/questions/405600/detecting-that-a-threadpool-workitem-has-completed-waiting-for-completion">this question</a> gave me an idea to implement <code>Concurrent<T></code> with async delegates instead of the ThreadPool. However, I am finding it harder to understand what's going on when an <code>AsyncCallback</code> is passed to <code>BeginInvoke</code>, especially when several threads have access to <code>IAsyncResult</code>. Unfortunately, this case doesn't seem to be covered at MSDN or anywhere I could find. Moreover, all articles I could find were either written before closures and generics were available or just seem that way. There are several questions (and the answers which I hope are true, but I am ready to be disappointed):</p>
<p>1) Would using a closure as an AsyncCallback make any difference?<br>
(Hopefully not)<br>
2) If a thread waits on the <code>AsyncWaitHandle</code>, will it be signaled<br>
a) before the callback starts or
b) after it finishes?<br>
(Hopefully b)<br>
3) While the callback is running, what will <code>IsCompleted</code> return? Possibilities I can see:<br>
a) <code>true</code>;
b) <code>false</code>;
c) <code>false</code> before the callback calls EndInvoke, <code>true</code> after.<br>
(Hopefully b or c)<br>
4) Will <code>DisposedObjectException</code> be thrown if some thread waits on the <code>AsyncWaitHandle</code> after <code>EndInvoke</code> is called?<br>
(Hopefully not, but I expect yes).</p>
<p>Provided the answers are as I hope, this seems like it should work:</p>
<pre><code>public class Concurrent<T> {
private IAsyncResult _asyncResult;
private T _result;
public Concurrent(Func<T> f) { // Assume f doesn't throw exceptions
_asyncResult = f.BeginInvoke(
asyncResult => {
// Assume assignment of T is atomic
_result = f.EndInvoke(asyncResult);
}, null);
}
public T Result {
get {
if (!_asyncResult.IsCompleted)
// Is there a race condition here?
_asyncResult.AsyncWaitHandle.WaitOne();
return _result; // Assume reading of T is atomic
}
...
</code></pre>
<p>If the answers to the questions 1-3 are the ones I hope for, there should be no raace condition here, as far as I can see.</p>
| [
{
"answer_id": 406920,
"author": "annakata",
"author_id": 13018,
"author_profile": "https://Stackoverflow.com/users/13018",
"pm_score": 2,
"selected": false,
"text": "parseFloat(foo)"
},
{
"answer_id": 406922,
"author": "epascarello",
"author_id": 14104,
"author_profi... | 2009/01/02 | [
"https://Stackoverflow.com/questions/406915",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9204/"
] |
406,927 | <p>How can I detect if an application is not used for more than x minutes in DELPHI</p>
| [
{
"answer_id": 407070,
"author": "Charles Faiga",
"author_id": 17560,
"author_profile": "https://Stackoverflow.com/users/17560",
"pm_score": 2,
"selected": false,
"text": "procedure TUserActivity.AppMessage(var Msg: TMsg; var Handled: Boolean);\nbegin\n Handled := False;\n case Msg.mes... | 2009/01/02 | [
"https://Stackoverflow.com/questions/406927",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/48705/"
] |
406,939 | <p>I'm having difficulty getting widgets in a QDialog resized automatically when the dialog itself is resized.</p>
<p>In the following program, the textarea resizes automatically if you resize the main window. However, the textarea within the dialog stays the same size when the dialog is resized.</p>
<p>Is there any way of making the textarea in the dialog resize automatically? I've tried using <code>setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored)</code> on the dialog itself and the two widgets within, but that seems to have no effect.</p>
<p>I'm using Qt version 3.3.7 and PyQt version 3.5.5-29 on openSuSE 10.2, if that's relevant.</p>
<pre><code>import sys
from qt import *
# The numbers 1 to 1000 as a string.
NUMBERS = ("%d " * 1000) % (tuple(range(1,1001)))
# Add a textarea containing the numbers 1 to 1000 to the given
# QWidget.
def addTextArea(parent, size):
textbox = QTextEdit(parent)
textbox.setReadOnly(True)
textbox.setMinimumSize(QSize(size, size*0.75))
textbox.setText(NUMBERS)
class TestDialog(QDialog):
def __init__(self,parent=None):
QDialog.__init__(self,parent)
self.setCaption("Dialog")
everything = QVBox(self)
addTextArea(everything, 400)
everything.resize(everything.sizeHint())
class TestMainWindow(QMainWindow):
def __init__(self,parent=None):
QMainWindow.__init__(self,parent)
self.setCaption("Main Window")
everything = QVBox(self)
addTextArea(everything, 800)
button = QPushButton("Open dialog", everything)
self.connect(button, SIGNAL('clicked()'), self.openDialog)
self.setCentralWidget(everything)
self.resize(self.sizeHint())
self.dialog = TestDialog(self)
def openDialog(self):
self.dialog.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
mainwin = TestMainWindow(None)
app.setMainWidget(mainwin)
mainwin.show()
app.exec_loop()
</code></pre>
| [
{
"answer_id": 407309,
"author": "Luke Woodward",
"author_id": 48503,
"author_profile": "https://Stackoverflow.com/users/48503",
"pm_score": 2,
"selected": false,
"text": "dialog.setLayout(some_layout)\n layout = QVBoxLayout(self)\nlayout.add(everything)\n TestDialog.__init__"
},
{
... | 2009/01/02 | [
"https://Stackoverflow.com/questions/406939",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/48503/"
] |
406,954 | <p>Is there a database term for "table or view"?<br>
In my app, the table name I'm pulling data from is configurable using the configuration setting <code>UserTableName</code>
Now the DBA went and renamed the table but created a view using the original name.<br>
So nothing changed on my side but now I feel that <code>UserTableName</code> is misleading and I would like to change it to User<em>Whatever</em>Name where <em>Whatever</em> is a term for a table or view.<br>
Is there such a thing or am I just being an idiot? </p>
| [
{
"answer_id": 406961,
"author": "M4N",
"author_id": 19635,
"author_profile": "https://Stackoverflow.com/users/19635",
"pm_score": 0,
"selected": false,
"text": "UserDataSource"
}
] | 2009/01/02 | [
"https://Stackoverflow.com/questions/406954",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1287/"
] |
406,955 | <p>I've got an app which is using a WCF service. Now I'd like to add unit tests to the app.</p>
<p>For some cases I need to mock the WCF service, since getting the desired behaviour from the service sometimes is tough (e.g. service throws special exceptions).</p>
<p>I could add yet another interface to the wcf client, but this seems a bit silly, since the client calls already are using an interface.</p>
<p>Is there an easy way to mock a WCF service? Easier than creating another interface layer and redirecting every single WCF call inside it?</p>
<p>Edit: Most of the answers seem not to know much about WCF service using, so some clarification:<br>
To use a WCF service from a ViewModel, I have to manage the connection something like this:</p>
<pre><code>ChannelFactory<IMyWcfService> channelFactory = new ChannelFactory<IMyWcfService>("");
IMyWcfService proxy = channelFactory.CreateChannel();
proxy.CallMyStuff();
proxy.Close();
</code></pre>
<p>I can't just pass the ViewModel the proxy to the WCF, since the connection needs to be opened and closed for every transaction. For this reason using RhinoMock/NMock would not work, since they need a ViewModel which gets the proxy as a parameter, which can't be done like this if you use WCF.</p>
| [
{
"answer_id": 407240,
"author": "David Schmitt",
"author_id": 4918,
"author_profile": "https://Stackoverflow.com/users/4918",
"pm_score": 4,
"selected": true,
"text": "IMyWcfService ChannelFactory<IMyWcfService>"
},
{
"answer_id": 50390595,
"author": "Alex",
"author_id":... | 2009/01/02 | [
"https://Stackoverflow.com/questions/406955",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7021/"
] |
406,963 | <p>I'm probably missing something simple here, but I can't find the answer elsewhere. I just want to display an applet in my GWT code. </p>
<p>OS: Windows XP
Java: JDK 1.6.0_10
Other: GWT, GWT-Ext 2.0.5</p>
<p>Here is the applet (obviously simplified for testing):</p>
<pre><code>package foo.applet;
import javax.swing.JApplet;
import java.awt.Graphics;
public class HelloApplet extends JApplet
{
public void paint(Graphics g)
{
g.drawRect(0, 0,
getSize().width - 1,
getSize().height - 1);
g.drawString("Hello world!", 5, 15);
}
}
</code></pre>
<p>Here is the code calling it:</p>
<pre><code>
package foo.applet;
import com.google.gwt.user.client.ui.HTML;
import com.gwtext.client.widgets.Panel;
public class AppletPanel extends Panel
{
</code></pre>
<pre><code>public AppletPanel()
{
HTML applet = new HTML();
applet.setHTML("<applet name=\"HelloApplet\" code=\"HelloApplet.class\" width=\"300\" height=\"300\"" );
this.add(applet);
}
</code></pre>
<p>}</p>
<p>When I launch the app in hosted mode, the jvm crashes (filed incident 1425130 with Sun).</p>
<p>When I try to compile the GWT code for running in a browser, I get this:</p>
<pre><code> [ERROR] Errors in 'file:/C:/<blah>/applet/HelloApplet.java'
[ERROR] Line 3: The import javax.swing cannot be resolved
[ERROR] Line 4: The import java.awt cannot be resolved
[ERROR] Line 6: JApplet cannot be resolved to a type
[ERROR] Line 8: Graphics cannot be resolved to a type
[ERROR] Line 11: The method getSize() is undefined for the type HelloApplet
[ERROR] Line 12: The method getSize() is undefined for the type HelloApplet
</code></pre>
<p>Obviously I'm missing some applet library, but I've grepped through all the jars in the jdk and tried including all of the ones that list JApplet or awt (plugin.jar, resources.jar, rt.jar, deploy.jar, javaws.jar).</p>
<p>Also, I'm pretty sure once I solve this problem there's another one lurking right after it, but I'll save that for another question.</p>
<p>Thanks!</p>
<hr>
<p>The legacy app is not an applet - it is a thick-client Swing application. We've hacked it to run as an applet because our customers want a browser client and this is the fastest way to get that done.</p>
<p>I don't know if GWT would accept the JPanel solution - the app is not written in any way that GWT can parse - i.e. it's not using the GWT API, it's using the Swing API. AFAIK, the only way to mix Swing with GWT would be in an applet fashion. </p>
<p>Am I missing something?</p>
| [
{
"answer_id": 9639416,
"author": "Josh",
"author_id": 1260000,
"author_profile": "https://Stackoverflow.com/users/1260000",
"pm_score": 1,
"selected": false,
"text": "gwt gwt .jar jarsigner gwt gwt (applet MAYSCRIPT code = 'com.myapplet.MyApplet' id ='myApplet' jnlp_href = '/spplets/MyA... | 2009/01/02 | [
"https://Stackoverflow.com/questions/406963",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9945/"
] |
406,966 | <p>I have an application which had optional extras depending on if the user has the software installed.</p>
<p>On Linux what is the best way to determine if something like python and PyUsb is installed?</p>
<p>I am developing a C++ Qt application if that helps.</p>
| [
{
"answer_id": 406992,
"author": "Kris Kumler",
"author_id": 4281,
"author_profile": "https://Stackoverflow.com/users/4281",
"pm_score": 1,
"selected": false,
"text": "which"
},
{
"answer_id": 407038,
"author": "Fabio Ceconello",
"author_id": 8999,
"author_profile": "... | 2009/01/02 | [
"https://Stackoverflow.com/questions/406966",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24459/"
] |
406,985 | <p>I want to be able to predicate pattern matches on whether they occur after word characters or after non-word characters. In other words, I want to simulate the \b word break regex char at the beginning of the pattern which flex/lex does not support.</p>
<p>Here's my attempt below (which does not work as desired):</p>
<pre><code>%{
#include <stdio.h>
%}
%x inword
%x nonword
%%
[a-zA-Z] { BEGIN inword; yymore(); }
[^a-zA-Z] { BEGIN nonword; yymore(); }
<inword>a { printf("'a' in word\n"); }
<nonword>a { printf("'a' not in word\n"); }
%%
</code></pre>
<p>Input :</p>
<pre><code>a
ba
a
</code></pre>
<p>Expected output</p>
<pre><code>'a' not in word
'a' in word
'a' not in word
</code></pre>
<p>actual output:</p>
<pre><code>a
'a' in word
'a' in word
</code></pre>
<p>I'm doing this because I want to do something like <a href="http://www.rinkworks.com/dialect/" rel="nofollow noreferrer">the dialectizer</a> and I have always wanted to learn how to use a real lexer. Sometimes the patterns I want to replace need to be fragments of words, sometimes they need to be whole words only.</p>
| [
{
"answer_id": 408711,
"author": "user49117",
"author_id": 49117,
"author_profile": "https://Stackoverflow.com/users/49117",
"pm_score": 1,
"selected": false,
"text": "%%\n[a-zA-Z]+a[a-zA-Z]* {printf(\"a in word: %s\\n\", yytext);}\na[a-zA-Z]+ {printf(\"a in word: %s\\n\", yytext);}\na {... | 2009/01/02 | [
"https://Stackoverflow.com/questions/406985",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41613/"
] |
406,987 | <p>I've been using javascript to do lightweight functionality on sites for years - DOM manipulation etc - but just now im beginning to investigate using it to do a lot more of the heavy lifting (in combo with PHP). I've only just started getting into OO JS, and im still trying to get my head around the best-practices and design patterns that work well with it.</p>
<p>To be more specific - my question is, can anyone here suggest techniques for connecting a form to a javascript object? </p>
<p>In my current implementation I have an JS object that can be edited by a (fairly large) form. When I instantiate the object I attach an onchange observer to the form, whose callback syncs the form fields with the object parameters. I'm handling the form submitting through AJAX - there is also a periodic request that saves a temporary version of the form info to a mySQL DB. One thing I wonder is whether it is possible to easily handle syncing in the other direction - onchange of the object the form fields update (on form reset for instance).</p>
<p>I am interested to know if this approach is a correct/sensible one, and more generally I would be very interested to hear advice with regard to OOJS form handling.</p>
<p>Cheers in advance :)</p>
<p>(Im using Prototype btw)</p>
| [
{
"answer_id": 419243,
"author": "Luca Matteis",
"author_id": 50394,
"author_profile": "https://Stackoverflow.com/users/50394",
"pm_score": 2,
"selected": false,
"text": "$(\"form\").serialize(true);"
}
] | 2009/01/02 | [
"https://Stackoverflow.com/questions/406987",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
407,016 | <p>I have a Java application, to start it I use</p>
<blockquote>
<p>java -jar myapp.jar</p>
</blockquote>
<p>To stop it I use CTRL+C.</p>
<p>Now I need to convert that application to something that I can start with:</p>
<blockquote>
<p>/etc/init.d/myapp start</p>
</blockquote>
<p>And I can stop with:</p>
<blockquote>
<p>/etc/init.d/myapp stop</p>
</blockquote>
<p>The problem is all about saving the PID of the process, I think I saw somewhere a recipe for doing this, I don't remember where and I'm not able to find it.</p>
<p>I saw that there is a project called <a href="http://wrapper.tanukisoftware.org/doc/english/download.jsp" rel="noreferrer">Java Server Wrapper</a>, but I look for something free that does not limit memory usage. And I think that this work could be done in a single bash script.</p>
| [
{
"answer_id": 412175,
"author": "opyate",
"author_id": 51280,
"author_profile": "https://Stackoverflow.com/users/51280",
"pm_score": 3,
"selected": false,
"text": "$ ./yourprogram &\n$ echo $! > /var/run/yourpid\n #!/bin/bash\n# processname: yourprogram\n# pidfile: /var/run/yourpid\n\nc... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407016",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36131/"
] |
407,020 | <p>I wanna do a macro program for a game. But there is a problem with sending keys to only game application (game window). I am using <code>keybd_event</code> API for sending keys to game window. But I only want to send keys to the game window, not to explorer or any opened window while my macro program is running. When I changed windows its still sending keys. I tried to use <code>Interaction.App</code> with <code>Visual Basic.dll</code> reference. But <code>Interaction.App</code> only Focus the game window.</p>
<p>I couldn't find anything about my problem. Can anyone help me? Thanx</p>
| [
{
"answer_id": 407113,
"author": "Tom Anderson",
"author_id": 13502,
"author_profile": "https://Stackoverflow.com/users/13502",
"pm_score": 1,
"selected": false,
"text": "Private Const WM_KEYDOWN As Integer = &H100\nPrivate Const WM_KEYUP As Integer = &H101\n private static int WM_KEYDOW... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407020",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
407,026 | <p>I am a little confused here.</p>
<p>I would like to do something like this:</p>
<ol>
<li>create some kind of buffer I can write into</li>
<li>clear the buffer</li>
<li>use a printf()-like function several times to append a bunch of stuff into the buffer based on some complicated calculations I only want to do once</li>
<li>use the contents of the buffer and print it to several <code>PrintStream</code> objects</li>
<li>repeat steps 2-4 as necessary</li>
</ol>
<p>e.g.:</p>
<pre><code>SuperBuffer sb = new SuperBuffer();
/* SuperBuffer is not a real class, so I don't know what to use here */
PrintStream[] streams = new PrintStream[N];
/* ... initialize this array to several streams ... */
while (!done)
{
sb.clear();
sb.printf("something %d something %d something %d",
value1, value2, value3);
if (some_complicated_condition())
sb.printf("something else %d something else %d", value4, value5);
/* ... more printfs to sb ... */
for (PrintStream ps : streams)
ps.println(sb.getBuffer());
}
</code></pre>
<p>It looks like wrapping a <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/io/PrintWriter.html" rel="nofollow noreferrer">PrintWriter</a> around <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/io/StringWriter.html" rel="nofollow noreferrer">StringWriter</a> will do what I want for the <code>sb</code> object above, except there's no <code>clear()</code> method. I suppose I could create a new PrintWriter and StringWriter object each time through the loop, but that seems like a pain. (in my real code I do this in several places, not just once in one loop...)</p>
<p>I've also used <code>java.nio.CharBuffer</code> and other NIO buffers a lot, and that seems like a promising approach, but I'm not sure how I can wrap them with an object that will give me <code>printf()</code> functionality.</p>
<p>any advice?</p>
| [
{
"answer_id": 407084,
"author": "Jason S",
"author_id": 44330,
"author_profile": "https://Stackoverflow.com/users/44330",
"pm_score": 3,
"selected": true,
"text": "Formatter format() printf() Appendable CharBuffer Appendable clear() CharBuffer"
},
{
"answer_id": 408453,
"aut... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407026",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/44330/"
] |
407,027 | <p>We've a table with a <code>varchar2(100)</code> column, that occasionally contains carriage-return & line-feeds. We should like to remove those characters in the SQL query. We're using:</p>
<pre><code>REPLACE( col_name, CHR(10) )
</code></pre>
<p>which has <strong>no effect</strong>, however replacing 'CHR(10)' for a more conventional 'letter' character proves that the REPLACE function works otherwise. We have also found that </p>
<pre><code>REPLACE( col_name, CHR(10), '_' )
</code></pre>
<p>finds the <em>location</em> of the new-line, but <em>inserts</em> the underscore after it, rather than replacing it.</p>
<p>Running on Oracle8i. Upgrading is not an option.</p>
| [
{
"answer_id": 407050,
"author": "Cade Roux",
"author_id": 18255,
"author_profile": "https://Stackoverflow.com/users/18255",
"pm_score": 4,
"selected": false,
"text": "CHR(13) + CHR(10) CHR(13) + '_' REPLACE(col_name, CHR(13) + CHR(10), '')"
},
{
"answer_id": 407111,
"author"... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407027",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42429/"
] |
407,048 | <p>I've heard from a variety of places that global variables are inherently nasty and evil, but when doing some non-object oriented Javascript, I can't see how to avoid them. Say I have a function which generates a number using a complex algorithm using random numbers and stuff, but I need to keep using that particular number in some other function which is a callback or something and so can't be part of the same function. </p>
<p>If the originally generated number is a local variable, it won't be accessible from, there. If the functions were object methods, I could make the number a property but they're not and it seems somewhat overcomplicated to change the whole program structure to do this. Is a global variable really so bad?</p>
| [
{
"answer_id": 407076,
"author": "Paul Stephenson",
"author_id": 5536,
"author_profile": "https://Stackoverflow.com/users/5536",
"pm_score": 7,
"selected": true,
"text": "function A()\n{\n var rand_num = calculate_random_number();\n B(rand_num);\n}\n\nfunction B(r)\n{\n use_rand... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407048",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
407,069 | <p>Let me state first: I know that any user that wants to run a program (or even log in), has to have access to (probably at least) the Windows system directories and the shared libraries in <code>%ProgramFiles%</code>, but I'd like to be able to access Skype, for example, by running it with an unprivileged user and make sure that it can't access <em>any</em> unnecessary files.</p>
<p>I fear that the only way to do this would be to identify all of the gazillion directories where I store files that I don't want this user to access and then create a new user group that can access these directories, or run Skype and Azureus in a VM.</p>
<p>Is there a better way?</p>
| [
{
"answer_id": 407263,
"author": "Chris Smith",
"author_id": 9073,
"author_profile": "https://Stackoverflow.com/users/9073",
"pm_score": 3,
"selected": true,
"text": "C:\\Documents and Settings\\skype\\Program Files\\Skype"
}
] | 2009/01/02 | [
"https://Stackoverflow.com/questions/407069",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/50928/"
] |
407,074 | <p>We're looking for a way to include some sort of build ID automatically in our builds. This needs to be portable (VC++, g++ on Linux and Mac) and automatic. VC++ is what matters most, since in the other environments we use custom Python build scripts so I can do whatever I want.</p>
<p>We use SVN, so we were looking at using the output of svnversion to write the revision to a header and include it. This has problems : if we put the file in SVN, it will appear as modified every time, but it would be a superfluous commit and in a sense generate an infinite loop of increasing revisions. If we don't put the file in SVN and just create it as a pre-build step, the sources wouldn't be complete, as they'd need the pre-build step or Makefile to generate that file.</p>
<p>We could also use <code>__DATE__</code> but we can't guarantee the file that uses the <code>__DATE__</code> (ie writes it to a log file) will be compiled if some other file is modified - except if we "touch" it, but then we'd cause the project to be always out of date. We could touch it as the pre-build step, so it would get touched only if the rest of the project is out of date, thus not causing a spurious compile, but if VC++ computes the dependencies <em>before</em> the pre-build step, this wouldn't work (the file with <code>__DATE__</code> won't get compiled)</p>
<p>Any interesting ideas?</p>
| [
{
"answer_id": 407107,
"author": "Josh Kelley",
"author_id": 25507,
"author_profile": "https://Stackoverflow.com/users/25507",
"pm_score": 3,
"selected": false,
"text": "svnversion svnversion subwcrev"
},
{
"answer_id": 407134,
"author": "Paul Beckingham",
"author_id": 14... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407074",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39301/"
] |
407,080 | <p>I have read through the solutions to similar problems, but they all seem to involve scripts and extra tools. I'm hoping my problem simple enough to avoid that.</p>
<p>So the user uploads a csv of next week's data. It gets inserted into the DB, no problem.</p>
<p>BUT</p>
<p>an hour later he gets feedback from everyone, and must make updates accordingly. He updates the csv and goes to upload it to the DB.</p>
<p>Right now, the system I'm using checks to see if the data for that week is already there, and if it is, pulls all of that data from the DB, a script finds the differences and sends them out, and after all of this, the data the old data is deleted and replaced with the new data.</p>
<p>Obviously, it is a lot easier to just wipe it clean and reenter the data, but not the best method, especially if there are lots of changes or tons of data. But I have to know WHAT changes have been made to send out alerts. But I don't want a transaction log, as the alerts only need to be sent out the one time and after that, the old data is useless.</p>
<p>So! </p>
<p>Is there a smart way to compare the new data to the already existing data, get only the rows that are changed/deleted/added, and make those changes? Right now it seems like I could do an update, but then I won't get any response on what has changed...</p>
<p>Thanks!</p>
<p>Quick Edit:</p>
<p>No foreign keys are currently in use. This will soon change, but it shouldn't make a difference, because the foreign keys will only point to who the data effects and thus won't need to be changed. As far as primary keys go, that does present a bit of a dilemma:</p>
<p>The data in question is everyone's work schedule. So it would be nice (for specific applications of this schedule beyond simple output) for each shift to have a key. But the problem is, let's say that user1 was late on Monday. The tardiness is recorded in a separate table and is tied to the shift using the shift key. But if on Tuesday there is some need to make some changes to the week already in progress, my fear is that it will become too difficult to insure that all entries in the DB that have already happened (and thus may have associations that shouldn't be broken) will get re-keyed in the process. Unfortunately, it is not as simple as only updating all events occurring AFTER the current time, as this would add work (and thus make it less marketable) to the people who do the uploading. Basically, they make the schedule on one program, export it to a CSV, and then upload it on a web page for all of the webapps that need that data. So it is simply much easier for them (and less stressful for everyone involved) to do the same routine every time of exporting the entire week and uploading it.</p>
<p>So my biggest concern is to make the upload script as smart as possible on both ends. It doesn't get bloated trying to find the changes, it can find the changes no matter the input AND none of the data that is unchanged risks getting re-keyed.</p>
<p>Here's a related question:</p>
<pre><code>Suppose Joe User was schedule to wash dishes from 7:00 PM to 8:00 PM, but the new
data has him working 6:45 PM to 8:30 PM. Has the shift been changed? Or has the old
one been deleted and a new one added?
</code></pre>
<p>And another one:</p>
<pre><code>Say Jane was schedule to work 1:00 PM to 3:00 PM, but now everyone has a mandatory
staff meeting at 2:00 to 3:00. Has she lost one shift and gained two? Or has one
shift changed and she gained one?
</code></pre>
<p>I'm really interested in knowing how this kind of data is typically handled/approached, more than specific answers to the above.</p>
<p>Again, thank you.</p>
| [
{
"answer_id": 407107,
"author": "Josh Kelley",
"author_id": 25507,
"author_profile": "https://Stackoverflow.com/users/25507",
"pm_score": 3,
"selected": false,
"text": "svnversion svnversion subwcrev"
},
{
"answer_id": 407134,
"author": "Paul Beckingham",
"author_id": 14... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407080",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/49478/"
] |
407,100 | <p>I need to call a const function from a non-const object. See example</p>
<pre><code>struct IProcess {
virtual bool doSomeWork() const = 0L;
};
class Foo : public IProcess {
virtual bool doSomeWork() const {
...
}
};
class Bar
{
public:
const IProcess& getProcess() const {return ...;}
IProcess& getProcess() {return ...;}
void doOtherWork {
getProcess().doSomeWork();
}
};
</code></pre>
<p>Calling </p>
<pre><code>getProcess().doSomeWork();
</code></pre>
<p>will always results in a call to</p>
<pre><code>IProcess& getProcess()
</code></pre>
<p>Is there another way to call</p>
<pre><code>const IProcess& getProcess() const
</code></pre>
<p>from a non constant member function?
I have so far used</p>
<pre><code>const_cast<const Bar*>(this)->getProcess().doSomeWork();
</code></pre>
<p>which does the trick but seems overly complicated.</p>
<hr>
<p>Edit: I should mention that code is being refactored and eventually only one function will remain.</p>
<pre><code>const IProcess& getProcess() const
</code></pre>
<p>However, currently there is a side effect and the const call may return a different instance of IProcess some of the time.</p>
<p>Please keep on topic.</p>
| [
{
"answer_id": 407114,
"author": "Judge Maygarden",
"author_id": 1491,
"author_profile": "https://Stackoverflow.com/users/1491",
"pm_score": 1,
"selected": false,
"text": "const_cast<const IProcess&> (getProcess()).doSomeWork();\n"
},
{
"answer_id": 407122,
"author": "Communi... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407100",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/49145/"
] |
407,108 | <p>This is the SP...</p>
<pre><code>USE [EBDB]
GO
/****** Object: StoredProcedure [dbo].[delete_treatment_category] Script Date: 01/02/2009 15:18:12 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*
RETURNS 0 FOR SUCESS
1 FOR NO DELETE AS HAS ITEMS
2 FOR DELETE ERROR
*/
ALTER PROCEDURE [dbo].[delete_treatment_category]
(
@id INT
)
AS
SET NOCOUNT ON
IF EXISTS
(
SELECT id
FROM dbo.treatment_item
WHERE category_id = @id
)
BEGIN
RETURN 1
END
ELSE
BEGIN
BEGIN TRY
DELETE FROM dbo.treatment_category
WHERE id = @id
END TRY
BEGIN CATCH
RETURN 2
END CATCH
RETURN 0
END
</code></pre>
<p>And I'm trying to get the return value using the below code (sqlDataSource & Gridview combo in VB .NET</p>
<pre><code>Protected Sub dsTreatmentCats_Deleted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles dsTreatmentCats.Deleted
Select Case CInt(e.Command.Parameters(0).Value)
Case 0
'it worked so no action
lblError.Visible = False
Case 1
lblError.Text = "Unable to delete this category because it still has treatments associated with it."
lblError.Visible = True
Case 2
lblError.Text = "Unable to delete this category due to an unexpected error. Please try again later."
lblError.Visible = True
End Select
End Sub
</code></pre>
<p>The problem is that the line CInt(e.Command.Parameters(0).Value) returns a DBNull instead of the return value but only on deletes - this approach works fine with both updates and inserts.</p>
<p>Hopefully I'm just being a bit dense and have missed something obvious - any ideas?</p>
<p><strong>Edit</strong></p>
<p>I'm still having this problem and have tried all of the options below to no avail - I'm surprised no one else has had this problem?</p>
<p>Code for adding parameters:</p>
<pre><code><asp:SqlDataSource ID="dsTreatmentCats" runat="server"
ConnectionString="<%$ ConnectionStrings:EBDB %>"
DeleteCommand="delete_treatment_category" DeleteCommandType="StoredProcedure"
InsertCommand="add_treatment_category" InsertCommandType="StoredProcedure"
SelectCommand="get_treatment_categories" SelectCommandType="StoredProcedure"
UpdateCommand="update_treatment_category"
UpdateCommandType="StoredProcedure" ProviderName="System.Data.SqlClient">
<DeleteParameters>
<asp:Parameter Direction="ReturnValue" Name="RetVal" Type="Int32" />
<asp:Parameter Name="id" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Direction="ReturnValue" Name="RetVal" Type="Int32" />
<asp:Parameter Name="id" Type="Int32" />
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="additional_info" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Direction="ReturnValue" Name="RetVal" Type="Int32" />
<asp:ControlParameter ControlID="txtCat" Name="name" PropertyName="Text"
Type="String" />
<asp:ControlParameter ControlID="txtAddInfo" Name="additional_info"
PropertyName="Text" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
</code></pre>
| [
{
"answer_id": 415823,
"author": "gbn",
"author_id": 27535,
"author_profile": "https://Stackoverflow.com/users/27535",
"pm_score": 0,
"selected": false,
"text": "DECLARE @rtn int;\nEXEC @rtn = dbo.delete_treatment_category /*insert valid id here > 2*/;\nSELECT @rtn;\n cmd.CommandType = C... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407108",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/37381/"
] |
407,115 | <p>I have a combobox in WPF that I add items to at run-time (via a data binding to a List). I'd like to set the height of the dropdown box dynamically so that all (or most) of the items show. Unfortunately it seems that the height of the dropdown is set once and cannot be dynamically altered. It always seems to be the same size.</p>
<p>Is there some relatively straightforward to adjust the dropdown height?</p>
<hr>
<p>Yes, I've tried setting it after adding the items to the combobox. In the debugger it looks like the new value is there. However, when I open the dropdown, it drops down to a size of its own choosing. I've tried exaggerating the MaxDropDownHeight and have even set it to "Auto" to no avail.</p>
| [
{
"answer_id": 407439,
"author": "w4g3n3r",
"author_id": 36745,
"author_profile": "https://Stackoverflow.com/users/36745",
"pm_score": 4,
"selected": false,
"text": "MaxDropDownHeight MaxDropDownHeight=\"Auto\"\n"
},
{
"answer_id": 45017459,
"author": "kimmoli",
"author_i... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407115",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/50932/"
] |
407,130 | <p>From a web service (WCF), I want an endpoint to take 10 seconds to finish.</p>
<p>Is there a way I can do a <code>thread.sleep(10);</code> on the method?</p>
| [
{
"answer_id": 407148,
"author": "JaredPar",
"author_id": 23283,
"author_profile": "https://Stackoverflow.com/users/23283",
"pm_score": 4,
"selected": true,
"text": "Thread.Sleep(TimeSpan.FromSeconds(10))\n"
},
{
"answer_id": 407173,
"author": "missaghi",
"author_id": 467... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407130",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39677/"
] |
407,154 | <p>Not that it is seriously burdensome to type </p>
<pre><code>:My_custom_foobar()
</code></pre>
<p>instead of just </p>
<pre><code>:my_custom_foobar()
</code></pre>
<p>but it just feels odd considering how virtually every other aspect of Vim is so extensible. Some searching for an answer has not turned up much, but I know it's got to be possible without having to recompile Vim from source. Does anyone out there know a way to accomplish this?</p>
| [
{
"answer_id": 407224,
"author": "Yada",
"author_id": 45066,
"author_profile": "https://Stackoverflow.com/users/45066",
"pm_score": 3,
"selected": true,
"text": "nnoremap <Leader>f :call My_custom_foobar()<CR>\n"
}
] | 2009/01/02 | [
"https://Stackoverflow.com/questions/407154",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42223/"
] |
407,179 | <p>I have a PDF document that needs to be pulled up in the browser, edited, and saved. I can save via the embedded adobe toolbar, along with all the other acrobat functions. But, what I am trying to see is if there is a way to display the PDF in a webpage alongside web controls.</p>
<p>For example, in the top part of the webpage I have a dropdownlist. It has a list of PDFs. I select one and the bottom part of the webpage opens up with the PDF.</p>
<p>Thanks.</p>
| [
{
"answer_id": 407191,
"author": "Vilx-",
"author_id": 41360,
"author_profile": "https://Stackoverflow.com/users/41360",
"pm_score": 0,
"selected": false,
"text": "<object>"
}
] | 2009/01/02 | [
"https://Stackoverflow.com/questions/407179",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28045/"
] |
407,180 | <p>I am working with an object which has sub objects within (see example below). I am attempting to bind a <code>List<rootClass></code> to the datagrid. When I bind the <code>List<></code>, in the cell that contains the <code>subObject</code>, I see the following value <code>... "namespace.subObject" ...</code> the string values display correctly.</p>
<p>Ideally I would like to see the “Description” property of the <code>subObject</code> in the datacell. How can I map the <code>subObject.Description</code> to show in the datacell?</p>
<pre><code>public class subObject
{
int id;
string description;
public string Description
{ get { return description; } }
}
public class rootClass
{
string value1;
subObject value2;
string value3;
public string Value1
{ get { return value1; } }
public subObject Value2
{ get { return value2; } }
public string Value3
{ get { return value3; } }
}
</code></pre>
| [
{
"answer_id": 407197,
"author": "Lasse V. Karlsen",
"author_id": 267,
"author_profile": "https://Stackoverflow.com/users/267",
"pm_score": 4,
"selected": true,
"text": "List<rootClass> yourList = ...\nTypedListWrapper<rootClass> bindableList = new TypedListWrapper<rootClass>(yourList);\... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407180",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
407,184 | <p>I am writing a nightly build script in bash.<br>
Everything is fine and dandy except for one little snag:</p>
<pre><code>
#!/bin/bash
for file in "$PATH_TO_SOMEWHERE"; do
if [ -d $file ]
then
# do something directory-ish
else
if [ "$file" == "*.txt" ] # this is the snag
then
# do something txt-ish
fi
fi
done;
</code></pre>
<p>My problem is determining the file extension and then acting accordingly. I know the issue is in the if-statement, testing for a txt file. </p>
<p>How can I determine if a file has a .txt suffix?</p>
| [
{
"answer_id": 407229,
"author": "Paul Stephenson",
"author_id": 5536,
"author_profile": "https://Stackoverflow.com/users/5536",
"pm_score": 9,
"selected": true,
"text": ".txt if [ \"${file: -4}\" == \".txt\" ]\n file: -4"
},
{
"answer_id": 407271,
"author": "Eldelshell",
... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407184",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
407,202 | <p>The phrase was used as a warning that the code was pulling some serious stunts.
My google search for this is pulling up nada; but I remember someone doing a search of google source for the phrase quite a while back.</p>
<p>in lies dragons?</p>
<p>dragons sleep here... </p>
<p>Bah... </p>
| [
{
"answer_id": 13246586,
"author": "bwDraco",
"author_id": 681231,
"author_profile": "https://Stackoverflow.com/users/681231",
"pm_score": 3,
"selected": false,
"text": "// Here be dragons. Thou art forewarned\n :P"
}
] | 2009/01/02 | [
"https://Stackoverflow.com/questions/407202",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16260/"
] |
407,209 | <p>I want to make Visual Studio move the autocompleted closing tag a word (or more) to the right. For example, given the following HTML:</p>
<pre><code><p>I need to emphasize some text.</p>
</code></pre>
<p>If I type <code><em></code> before the word "emphasize", Visual Studio autocompletes like so:</p>
<pre><code><p>I need to <em></em>emphasize some text.</p>
</code></pre>
<p>Then I need to move the closing <code></em></code> to get what I want:</p>
<pre><code><p>I need to <em>emphasize</em> some text.</p>
</code></pre>
<p>Is there a way to make Visual Studio do that last step automatically?</p>
| [
{
"answer_id": 408356,
"author": "w4g3n3r",
"author_id": 36745,
"author_profile": "https://Stackoverflow.com/users/36745",
"pm_score": 4,
"selected": true,
"text": "Sub MoveClosingTag()\n Dim ts As EnvDTE.TextSelection = CType(DTE.ActiveDocument.Selection(), EnvDTE.TextSelection)\n ... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407209",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42685/"
] |
407,237 | <p>Is it possible to determine if an ASP.NET page is a postback from javascript?
So basically a javascript equivalent of C# Page.IsPostBack.</p>
<p>Thanks.</p>
| [
{
"answer_id": 407246,
"author": "Bob",
"author_id": 45,
"author_profile": "https://Stackoverflow.com/users/45",
"pm_score": 5,
"selected": true,
"text": "var isPostBack = <%= Page.IsPostBack ? \"true\" : \"false\" %>;\n"
}
] | 2009/01/02 | [
"https://Stackoverflow.com/questions/407237",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/47036/"
] |
407,238 | <p>I have an <code>IDictionary<TKey,TValue></code> implementation that internally holds n other <code>Dictionary<TKey, TValue></code> and distributes that insertions by the HashCode of the key to the invidual sub-dictionaries. With 16 sub-dictionaries, the number of collisions is pretty low on a 4-core machine.</p>
<p>For parallel insertions, i locked the Add-method with a <code>ReaderWriterLockSlim</code>, locking only the individual sub-dictionary:</p>
<pre><code> public void Add(TKey key, TValue value)
{
int poolIndex = GetPoolIndex(key);
this.locks[poolIndex].EnterWriteLock();
try
{
this.pools[poolIndex].Add(key, value);
}
finally
{
this.locks[poolIndex].ExitWriteLock();
}
}
</code></pre>
<p>When inserting items with four threads, i only got about 32% cpu usage and bad performance. So i replaced the ReaderWriterLockSlim by a Monitor (i.e., the <code>lock</code> keyword).
CPU usage was now at nearly 100% and the performance was more than doubled. </p>
<p>My question is: Why did the CPU usage increase? The number of collisions should not have changed. What makes ReaderWriterLock.EnterWriteLock wait so many times?</p>
| [
{
"answer_id": 407267,
"author": "Dmitri Nesteruk",
"author_id": 9476,
"author_profile": "https://Stackoverflow.com/users/9476",
"pm_score": 0,
"selected": false,
"text": "Monitor TimerLock Monitor.TryEnter"
}
] | 2009/01/02 | [
"https://Stackoverflow.com/questions/407238",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/48722/"
] |
407,255 | <p>I have always wondered if, in general, declaring a throw-away variable before a loop, as opposed to repeatedly inside the loop, makes any (performance) difference?
A <em>(quite pointless)</em> example in Java:</p>
<p><strong>a)</strong> declaration before loop:</p>
<pre><code>double intermediateResult;
for(int i=0; i < 1000; i++){
intermediateResult = i;
System.out.println(intermediateResult);
}
</code></pre>
<p><strong>b)</strong> declaration (repeatedly) inside loop:</p>
<pre><code>for(int i=0; i < 1000; i++){
double intermediateResult = i;
System.out.println(intermediateResult);
}
</code></pre>
<p>Which one is better, <strong>a</strong> or <strong>b</strong>? </p>
<p>I suspect that repeated variable declaration (example <strong>b</strong>) creates more overhead <em>in theory</em>, but that compilers are smart enough so that it doesn't matter. Example <strong>b</strong> has the advantage of being more compact and limiting the scope of the variable to where it is used. Still, I tend to code according example <strong>a</strong>.</p>
<p><strong><em>Edit:</em></strong> I am especially interested in the Java case.</p>
| [
{
"answer_id": 407294,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 6,
"selected": false,
"text": "using System;\nusing System.Collections.Generic;\n\nclass Test\n{\n static void Main()\n {\n List<Action> a... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407255",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/50899/"
] |
407,256 | <p>I am using a simple regex to replace break tags with newlines:</p>
<pre><code>br_regex = /<br>/;
input_content = input_content.replace(br_regex, "\n");
</code></pre>
<p>This only replaces the first instance of a break tag, but I need to replace all. <code>preg_match_all()</code> would do the trick in PHP, but I'd like to know the JavaScript equivalent.</p>
| [
{
"answer_id": 407264,
"author": "annakata",
"author_id": 13018,
"author_profile": "https://Stackoverflow.com/users/13018",
"pm_score": 8,
"selected": true,
"text": "g foo.replace(/<br>/g,\"\\n\")\n"
},
{
"answer_id": 408318,
"author": "bobince",
"author_id": 18936,
"... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407256",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/74552/"
] |
407,272 | <p>I am creating an HTML form with some radio button options. I'd like to have one option as "Other - please specify" and allow the user to type something in.</p>
<p>Two questions: </p>
<p>1) How can I make a "hybrid" input type of <code>radio/text</code>? </p>
<p>2) On the PHP back end, if the input has the same <code>name</code> attribute as the radio inputs, will the user's input be part of the same array?</p>
| [
{
"answer_id": 407356,
"author": "Piskvor left the building",
"author_id": 19746,
"author_profile": "https://Stackoverflow.com/users/19746",
"pm_score": 4,
"selected": true,
"text": "<input type=\"text\" ...> rboption=other rboption=some%20text rboption == 'other'"
},
{
"answer_i... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407272",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4376/"
] |
407,279 | <p>I have a skeleton text file with placeholder strings:</p>
<pre><code>blah blah blah
blah $PLACEHOLDER_1$
blah
$PLACEHOLDER_2$
</code></pre>
<p>and so on. Specific "form" of placeholders does not matter -- I may change them to whatever most comfortable for specific implementation.</p>
<p>I have a bash script where I know values for placeholders, and I need to generate a new file, with placeholders replaced with values.</p>
<pre><code>#! /bin/sh
PLACEHOLDER_1 = 'string 1'
PLACEHOLDER_2 = 'multiline
string
2'
# TODO: Generate file output.txt from file output.template
# using placeholders above.
</code></pre>
<p>I may do this in multiple passes with sed, but it is not fun. I do <strong>not</strong> want to use Perl. I want to use textutils and bash itself only.</p>
<p>What is the best way to do what I want in a single pass?</p>
| [
{
"answer_id": 407311,
"author": "Adam Peck",
"author_id": 26658,
"author_profile": "https://Stackoverflow.com/users/26658",
"pm_score": 4,
"selected": true,
"text": "sed -i 's/PLACEHOLDER_1/string 1/g;s/PLACEHOLDER_2/string 2/g' <file>\n"
},
{
"answer_id": 407486,
"author": ... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407279",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6236/"
] |
407,287 | <p>Title might be a bit confusing, so let me explain.</p>
<p>I have a website that has a side-panel, which contains information about the user, things the user can do, etc. When the user is not logged in, this side-panel becomes the area for logging in or registration.</p>
<p>The code for this is:</p>
<pre><code><?php
if($user->loggedIn)
{
?>
<!-- side-panel for logged in users here -->
<?php
}
else
{
?>
<!-- login/registration etc -->
<?php
}
?>
</code></pre>
<p>What I want to do is load this snippet of code again when the user clicks login with AJAX, and use a jQuery effect (probably fade) that smoothly makes the side-panel transition from login/registration to the shiny users-only panel.</p>
<p>I know I could do this if I put that code in another file, and loaded it through AJAX into the div for the side-panel... but I would rather not make a separate file for the side-panel only. Is this possible?</p>
| [
{
"answer_id": 407316,
"author": "Ionuț Staicu",
"author_id": 23810,
"author_profile": "https://Stackoverflow.com/users/23810",
"pm_score": 0,
"selected": false,
"text": "$.ajax({\n type: \"GET\",\n url: \"url\", // replace 'url' with your url\n cache: false,\n success: funct... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407287",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29595/"
] |
407,314 | <p>I want to create a quick application for people to resolve the name of a user stored in Active Directory from a set of credentials. Some applications only provide the user id and it is too much to expect an end user to fire up the Active Directory Users and Groups MMC snap-in.</p>
<p>Input would be something like "MYCORP\a_user" and output would be "Dave Smith" if that is what is stored in AD.</p>
<p>I want this to be able to run in my test domain and also in a multi-forest environment.</p>
<p>Can someone provide a sample that does this? Does retrieval of other attributes from AD such as telephone number follow the same pattern?</p>
<p>Target platform: .NET 2.0 and above.</p>
| [
{
"answer_id": 407401,
"author": "Adam Lassek",
"author_id": 1249,
"author_profile": "https://Stackoverflow.com/users/1249",
"pm_score": 2,
"selected": false,
"text": "string[] strUserName = username.Split(\"\\\\\".ToCharArray());\nusing (var entry = new DirectoryEntry(\"LDAP://\" + ADSe... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407314",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/636/"
] |
407,337 | <p>This is really stumping me today. I'm sure its not that hard, but I have a System.Reflection.PropertyInfo object. I want to set its value based on the result of a database lookup (think ORM, mapping a column back to a property).</p>
<p>My problem is if the DB returned value is DBNull, I just want to set the property value to its default, the same as calling:</p>
<pre><code>value = default(T); // where T is the type of the property.
</code></pre>
<p>However, the default() method won't compile if you give it a Type, which is what I have:</p>
<pre><code>object myObj = ???; // doesn't really matter. some arbitrary class.
PropertyInfo myPropInf = ???; // the reflection data for a property on the myObj object.
myPropInf.SetValue(myObj, default(myPropInf.PropertyType), null);
</code></pre>
<p>The above doesn't compile. default(Type) is invalid. I also thought about doing:</p>
<pre><code>object myObj = ???;
PropertyInfo myPropInf = ???;
myPropInf.SetValue(myObj, Activator.CreateInstance(myPropInf.PropertyType), null);
</code></pre>
<p>However, if the Type is string, that would assign the value "new String()", but I really want "null", which is what "default(string)" would return.</p>
<p>So what am I missing here?
I suppose a really hacky way would be to create a new instance of myObj's Type and copy the property over, but that just seems stupid...</p>
<pre><code>object myObj = ???;
PropertyInfo myPropInf = ???;
var blank = Activator.CreateInstance(myObj.GetType());
object defaultValue = myPropInf.GetValue(blank, null);
myPropInf.SetValue(myObj, defaultValue, null);
</code></pre>
<p>I'd rather not waste the memory to make a whole new instance, just to get the default for the property though. Seems very wasteful.</p>
<p>Any ideas?</p>
| [
{
"answer_id": 407345,
"author": "Darin Dimitrov",
"author_id": 29407,
"author_profile": "https://Stackoverflow.com/users/29407",
"pm_score": 6,
"selected": false,
"text": "object defaultValue = type.IsValueType ? Activator.CreateInstance(type) : null;\n"
},
{
"answer_id": 407364... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407337",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28278/"
] |
407,350 | <p>I need to do some processing on fairly large XML files ( large here being potentially upwards of a gigabyte ) in C# including performing some complex xpath queries. The problem I have is that the standard way I would normally do this through the System.XML libraries likes to load the whole file into memory before it does anything with it, which can cause memory problems with files of this size.</p>
<p>I don't need to be updating the files at all just reading them and querying the data contained in them. Some of the XPath queries are quite involved and go across several levels of parent-child type relationship - I'm not sure whether this will affect the ability to use a stream reader rather than loading the data into memory as a block.</p>
<p>One way I can see of making it work is to perform the simple analysis using a stream-based approach and perhaps wrapping the XPath statements into XSLT transformations that I could run across the files afterward, although it seems a little convoluted.</p>
<p>Alternately I know that there are some elements that the XPath queries will not run across, so I guess I could break the document up into a series of smaller fragments based on it's original tree structure, which could perhaps be small enough to process in memory without causing too much havoc.</p>
<p>I've tried to explain my objective here so if I'm barking up totally the wrong tree in terms of general approach I'm sure you folks can set me right...</p>
| [
{
"answer_id": 407485,
"author": "Dimitre Novatchev",
"author_id": 36305,
"author_profile": "https://Stackoverflow.com/users/36305",
"pm_score": 1,
"selected": false,
"text": "XPathDocument"
}
] | 2009/01/02 | [
"https://Stackoverflow.com/questions/407350",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15394/"
] |
407,362 | <p>A beginner's question. </p>
<p>I'm building a .swf with Flex Ant.</p>
<p>To my .swf I link a file, <code>target.as</code>, which I generate from file <code>source.txt</code> with command </p>
<pre><code>./tool.sh source.txt > target.as
</code></pre>
<p>How can I add what is described in the above sentence to my ant build process?</p>
| [
{
"answer_id": 407406,
"author": "Adam Peck",
"author_id": 26658,
"author_profile": "https://Stackoverflow.com/users/26658",
"pm_score": 2,
"selected": false,
"text": "exec <exec executable=\"tool.sh\" dir=\"toolshdir\" output=\"target.as\">\n <arg value=\"source.txt\" />\n</exec>\n"
... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407362",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6236/"
] |
407,367 | <p>I have a couple of inline SQL in many of our reports on the report manager.
Now I need to do some code change for all of them, is there a way to list all those reports based on the inline SQL and not any SP?</p>
<p>Thanks,<br />
D</p>
| [
{
"answer_id": 407406,
"author": "Adam Peck",
"author_id": 26658,
"author_profile": "https://Stackoverflow.com/users/26658",
"pm_score": 2,
"selected": false,
"text": "exec <exec executable=\"tool.sh\" dir=\"toolshdir\" output=\"target.as\">\n <arg value=\"source.txt\" />\n</exec>\n"
... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407367",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
407,405 | <p>We have 2 applications that run under JBoss. I am looking for a way to reduce the overhead of the server. The main app runs under Tomcat. The other app is made up of MBeans. Is there a way to run MBeans under Tomcat? </p>
<p>Alternative suggestions are appreciated.</p>
| [
{
"answer_id": 1161861,
"author": "utku.utkan",
"author_id": 127370,
"author_profile": "https://Stackoverflow.com/users/127370",
"pm_score": 2,
"selected": false,
"text": "-Dcom.sun.management.jmxremote\n-Dcom.sun.management.jmxremote.port=4444 (could be anything)\n-Dcom.sun.management.j... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407405",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6013/"
] |
407,407 | <p>What's the best way to read a fixed length record in Perl. I know to read a file like:</p>
<pre><code>ABCDE 302
DEFGC 876
</code></pre>
<p>I can do</p>
<pre><code>while (<FILE>) {
$key = substr($_, 0, 5);
$value = substr($_, 7, 3);
}
</code></pre>
<p>but isn't there a way to do this with read/unpack?</p>
| [
{
"answer_id": 407422,
"author": "Jonathan Leffler",
"author_id": 15168,
"author_profile": "https://Stackoverflow.com/users/15168",
"pm_score": 4,
"selected": false,
"text": "my($key, $value) = unpack \"A5 A3\"; # Original, but slightly dubious\n my($key, $value) = unpack \"A6A3\";\n ... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407407",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14167/"
] |
407,420 | <p>I understand that the goal of moving towards <code><div></code> tags from <code><table></code> makes sense since it is more semantic. However, I don't understand the benefit gained if you still need a clearing block to make column-based layouts work. For example:</p>
<pre><code><!-- Note: location-info & personal-info both float left. -->
<div class="contact">
<div class="personal-info">
<p>
Shawn, etc, etc
</p>
</div>
<div class="location-info">
<p><address>etc</address></p>
</div>
<br style="clear:both" /> <!-- clearing block -->
</div>
</code></pre>
<p>The extraneous <code><br></code> tag is used strictly to describe style, and is required to make the layout work. Doesn't this ruin all benefits gained from removing tables?</p>
| [
{
"answer_id": 407421,
"author": "annakata",
"author_id": 13018,
"author_profile": "https://Stackoverflow.com/users/13018",
"pm_score": 6,
"selected": true,
"text": ".clear-block:after {\n content: \".\";\n display: block;\n height: 0;\n clear: both;\n visibility: hidden;\... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407420",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26/"
] |
407,428 | <p>I'm trying to bind an ASP.net DropDownList to the results of an entity framework query, while still maintaining multi-tier separation. (i.e. I don't want my UI code to contain query details, nor my Data Layer code to have UI dependencies.) My code-behind in the Page_Load event handler looks like this:</p>
<pre><code> IEnumerable<Lookup> TypesLookup = Business.DocumentBO.GetDocumentTypes(_LookupTypeID);
DocTypeDropDownList.DataSource = TypesLookup;
DocTypeDropDownList.DataTextField = "Description";
DocTypeDropDownList.DataValueField = "LookupID";
DocTypeDropDownList.DataBind();
</code></pre>
<p>While my data code looks like this (there's an intermediate business layer as well, but there no processing there as yet -- just a pass-through.):</p>
<pre><code> public static IEnumerable<Lookup> GetLookups(int LookupTypeID)
{
using (VLFDocumentEntities context = new VLFDocumentEntities())
{
IEnumerable<Lookup> l = (from c in context.Lookup
where c.LookupTypeID == LookupTypeID
select c);
return l;
}
}
</code></pre>
<p>When I get to the DocTypeDropDownList.DataBind();, it throws an ObjectDisposedException with the message "DocTypeDropDownList.DataBind();". Can anyone advise me on the best way to tackle this?</p>
<p>Thanks,
Andy</p>
| [
{
"answer_id": 407441,
"author": "M4N",
"author_id": 19635,
"author_profile": "https://Stackoverflow.com/users/19635",
"pm_score": 3,
"selected": true,
"text": "IEnumerable<Lookup> l = (from c in context.Lookup\n where c.LookupTypeID == LookupTypeID\n ... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407428",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/46731/"
] |
407,452 | <p>Lets say you have inherited a MS SQL 2000 or 2005 database, and you know that some of the Tables, Views, Procs, and Functions are not actually used in the final product. </p>
<p>Is there some kind of internal logging or another mechanism that could tell me what objects are NOT being called? or have only been called a few times versus thousands of times. </p>
| [
{
"answer_id": 407656,
"author": "Timbo",
"author_id": 20992,
"author_profile": "https://Stackoverflow.com/users/20992",
"pm_score": 3,
"selected": false,
"text": "select \n id, \n name\nfrom\n sys.sysdepends sd\ninner join sys.sysobjects so\n on so.id = sd.id\nwhere \n no... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407452",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36590/"
] |
407,459 | <p>I'm building a Windows service and following <a href="http://msdn.microsoft.com/en-us/library/aa984464(VS.71).aspx" rel="noreferrer">this MSDN article</a>, but I'm stuck on step 3 under "Create an installer". I can't find the "Add Installer" link it's referring to. I've clicked everywhere, including following the instructions it gives exactly, but I can't seem to find it. A few people on Google have had the same problem, but never found a solution (other than adding the ServiceInstaller object and configuring it manually).</p>
<p>Has anybody else had this problem and found a reason? I'm using VS2008 and targeting .Net 2.0 if it matters.</p>
| [
{
"answer_id": 18963275,
"author": "Contango",
"author_id": 107409,
"author_profile": "https://Stackoverflow.com/users/107409",
"pm_score": 2,
"selected": false,
"text": "Add Installer"
},
{
"answer_id": 40409936,
"author": "Carol",
"author_id": 2763467,
"author_profi... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407459",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8114/"
] |
407,460 | <p>Can someone illustrate (or point me to a good tutorial) on how to add a Date Picker to a view programmatically (i.e., without using the interface editor)? </p>
| [
{
"answer_id": 407480,
"author": "Marc Charbonneau",
"author_id": 35136,
"author_profile": "https://Stackoverflow.com/users/35136",
"pm_score": 2,
"selected": false,
"text": "initWithFrame UIDatePicker *datePicker = [[UIDatePicker alloc] initWithFrame:[superview bounds]];\n[superview add... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407460",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
407,467 | <p>When WSDL importer wizard generates the interfaces, all properties have the Index option, but reading the code and the InvokeRegistry unit, I can't found what is that for, anyone know if it is really necessary?</p>
<p>Like this</p>
<pre><code> Login = class(TRemotable)
private
[...]
published
property User: string Index (IS_OPTN) read GetUser write SetUser stored User_Specified;
[...]
end;
</code></pre>
<p>I'm asking because I want to change this unit, adding some Interfaces to this classes, for integrate with MVP framework.</p>
| [
{
"answer_id": 408636,
"author": "Wouter van Nifterick",
"author_id": 38813,
"author_profile": "https://Stackoverflow.com/users/38813",
"pm_score": 2,
"selected": false,
"text": "function GetUser(Index:Integer):String;\nprocedure SetUser(Index:Integer;const value:string);\n MyString := M... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407467",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36875/"
] |
407,468 | <p>I'm currently trying to initiate a file upload with urllib2 and the <a href="http://fabien.seisen.org/python/urllib2_multipart.html" rel="nofollow noreferrer">urllib2_file</a> library. Here's my code:</p>
<pre><code>import sys
import urllib2_file
import urllib2
URL='http://aquate.us/upload.php'
d = [('uploaded', open(sys.argv[1:]))]
req = urllib2.Request(URL, d)
u = urllib2.urlopen(req)
print u.read()
</code></pre>
<p>I've placed this .py file in my My Documents directory and placed a shortcut to it in my Send To folder (the shortcut URL is ).</p>
<p>When I right click a file, choose Send To, and select Aquate (my python), it opens a command prompt for a split second and then closes it. Nothing gets uploaded.</p>
<p>I knew there was probably an error going on so I typed the code into CL python, line by line.
When I ran the <code>u=urllib2.urlopen(req)</code> line, I didn't get an error;
<a href="http://www.aquate.us/u/55245858877937182052.jpg" rel="nofollow noreferrer">alt text http://www.aquate.us/u/55245858877937182052.jpg</a></p>
<p>instead, the cursor simply started blinking on a new line beneath that line. I waited a couple of minutes to see if something would happen but it just stayed like that. To get it to stop, I had to press ctrl+break.</p>
<p>What's up with this script?</p>
<p>Thanks in advance!</p>
<p>[Edit]
Forgot to mention -- when I ran the script without the request data (the file) it ran like a charm. Is it a problem with urllib2_file?</p>
<p>[edit 2]:</p>
<pre><code>import MultipartPostHandler, urllib2, cookielib,sys
import win32clipboard as w
cookies = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookies),MultipartPostHandler.MultipartPostHandler)
params = {"uploaded" : open("c:/cfoot.js") }
a=opener.open("http://www.aquate.us/upload.php", params)
text = a.read()
w.OpenClipboard()
w.EmptyClipboard()
w.SetClipboardText(text)
w.CloseClipboard()
</code></pre>
<p>That code works like a charm if you run it through the command line.</p>
| [
{
"answer_id": 407545,
"author": "Ben Blank",
"author_id": 46387,
"author_profile": "https://Stackoverflow.com/users/46387",
"pm_score": 2,
"selected": false,
"text": "urllib2_file urllib2_file urllib2_file urllib2_file d = ['uploaded', open(sys.argv[1:])]\n## --OR-- ##\nd = {'uploaded':... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407468",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/50548/"
] |
407,491 | <p>Take the example classes below. I want to display the customer and two addresses (from a LIST) on a form. Does the model binder in MVC beta support this or will I have to write my own custom binder? </p>
<pre><code>public class Customer
{
public string FirstName { get; set; }
public string LastName { get; set; }
public List<Address> Addresses { get; set; }
public Customer()
{
Addresses = new List<Address>();
}
}
public class Address
{
public int Line1 { get; set; }
public int Line2 { get; set; }
public int City { get; set; }
public int State { get; set; }
public int Zip { get; set; }
}
</code></pre>
<p>How would you code the fields? Like this?</p>
<pre><code><!-- some HTML formatting -->
<%= Html.TextBox("customer.address.line1", ViewData.Customer.Address[0].Line1)%>
<!-- some more HTML formatting -->
<%= Html.TextBox("customer.address.line1", ViewData.Customer.Address[1].Line1)%>
<!-- end of HTML form formatting -->
</code></pre>
| [
{
"answer_id": 409216,
"author": "Tim Scott",
"author_id": 29493,
"author_profile": "https://Stackoverflow.com/users/29493",
"pm_score": 1,
"selected": false,
"text": "<%= Html.TextBox(\"Address[0].Line1\", ViewData.Model.Address[0].Line1)%>\n<%= Html.TextBox(\"Address[1].Line1\", ViewDa... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407491",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/50964/"
] |
407,518 | <p>I recently posted <a href="https://stackoverflow.com/questions/406760/whats-your-most-controversial-programming-opinion#406948">one of my favourite interview whiteboard coding questions</a> in "<a href="https://stackoverflow.com/questions/406760/whats-your-most-controversial-programming-opinion">What's your more controversial programming opinion</a>", which is to write a function that computes Pi using the <a href="http://en.wikipedia.org/wiki/Leibniz_formula_for_pi" rel="nofollow noreferrer">Leibniz formula</a>. </p>
<p>It can be approached in a number of different ways, and the exit condition takes a bit of thought, so I thought it might make an interesting code golf question. Shortest code wins!</p>
<blockquote>
<p>Given that Pi can be estimated using the function 4 * (1 - 1/3 + 1/5 - 1/7 + ...) with more terms giving greater accuracy, write a function that calculates Pi to within 0.00001.</p>
</blockquote>
<p><strong>Edit: 3 Jan 2008</strong></p>
<p>As suggested in the comments I changed the exit condition to be within 0.00001 as that's what I really meant (an accuracy 5 decimal places is much harder due to rounding and so I wouldn't want to ask that in an interview, whereas within 0.00001 is an easier to understand and implement exit condition).</p>
<p>Also, to answer the comments, I guess my intention was that the solution should compute the number of iterations, or check when it had done enough, but there's nothing to prevent you from pre-computing the number of iterations and using that number. I really asked the question out of interest to see what people would come up with.</p>
| [
{
"answer_id": 407530,
"author": "Greg Beech",
"author_id": 13552,
"author_profile": "https://Stackoverflow.com/users/13552",
"pm_score": 2,
"selected": false,
"text": "StackOverflowException IteratePi public static double CalculatePi()\n{\n return IteratePi(0.0, 1.0, true);\n}\n\npri... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407518",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13552/"
] |
407,521 | <p>The application I want to build using MS Visual C# Express (I'm willing to upgrade to Standard if that becomes required) that needs a database.</p>
<p>I was all psyched about the SQL Server Compact - because I don't want the folks who would be installing my application on their computers to have to install the whole of SQL Server or something like that. I want this to be as easy as possible for the end user to install.</p>
<p>So I was all psyched until it seems that there are limitations to what I can do with the columns in my tables. I created a new database, created a table and when I went to create columns it seems that there isn't a "text" datatype - just something called "ntext" that seems to be limited to 255 characters. "int" seems to be limited to 4 (I wanted 11). And there doesn't seem to be an "auto_increment" feature.</p>
<p>Are these the real limitations I would have to live with? (Or is it because I'm using "Express" and not "Standard"). If these are the real limitations, what are my other database options that meet my requirements? (easy installation for user being the biggie - I'm assuming that my end user is just an average user of computers and if it's complicated would get frustrated with my application)</p>
<p>-Adeena</p>
<p>PS: I also want my database data to be encrypted to the end user. I don't want them to be able to access the database tables directly.</p>
<p>PPS. I did read: <a href="http://www.microsoft.com/Sqlserver/2005/en/us/compact.aspx" rel="noreferrer">http://www.microsoft.com/Sqlserver/2005/en/us/compact.aspx</a> and didn't see a discussion on these particular limitations</p>
| [
{
"answer_id": 407539,
"author": "Anthony Mastrean",
"author_id": 3619,
"author_profile": "https://Stackoverflow.com/users/3619",
"pm_score": 1,
"selected": false,
"text": "TEXT INTEGER PRIMARY KEY"
},
{
"answer_id": 407584,
"author": "Joel Coehoorn",
"author_id": 3043,
... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407521",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/44004/"
] |
407,523 | <p>In my bash script I have an external (received from user) string, which I should use in sed pattern.</p>
<pre><code>REPLACE="<funny characters here>"
sed "s/KEYWORD/$REPLACE/g"
</code></pre>
<p>How can I escape the <code>$REPLACE</code> string so it would be safely accepted by <code>sed</code> as a literal replacement?</p>
<p><strong>NOTE:</strong> The <code>KEYWORD</code> is a dumb substring with no matches etc. It is not supplied by user.</p>
| [
{
"answer_id": 407563,
"author": "Alex",
"author_id": 30181,
"author_profile": "https://Stackoverflow.com/users/30181",
"pm_score": 0,
"selected": false,
"text": "ls | awk '{ print \"awk \" \"'\"'\"'\" \" {print $1,$2,$3} \" \"'\"'\"'\" \" \" $1 \".old_ext > \" $1 \".new_ext\" }' > fo... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407523",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6236/"
] |
407,550 | <p>I have a PHP application that makes extensive use of Javascript on the client side. I have a simple system on the PHP side for providing translators an easy way to provide new languages. But there are cases where javascript needs to display language elements to the user (maybe an OK or cancel button or "loading" or something). </p>
<p>With PHP, I just have a text file that is cached on the server side which contains phrase codes on one side and their translation on the other. A translator just needs to replace the english with their own language and send me the translated version which I integrate into the application.</p>
<p>I want something similar on the client side. It occurred to me to have a javascript include that is just a set of translated constants but then every page load is downloading a potentially large file most of which is unnecessary.</p>
<p>Has anyone had to deal with this? If so, what was your solution?</p>
<p><strong>EDIT</strong>: To be clear, I'm not referring to "on-the-fly" translations here. The translations have already been prepared and are ready to go, I just need them to be made available to the client in an efficient way.</p>
| [
{
"answer_id": 407568,
"author": "Pim Jager",
"author_id": 35197,
"author_profile": "https://Stackoverflow.com/users/35197",
"pm_score": 5,
"selected": true,
"text": " <script type='text/javascript' src='jsscript.js'></script>\n <script type='text/javascript' src='jsscript.php'></scrip... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407550",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2494/"
] |
407,571 | <p>I'm using VSS 2008 and Visual Studio 2008. When my source files are checked in, the VSS property dialog shows them as type "Unicode (UTF-8)". But if I check one out from within Visual Studio, then do a compare, it says "binary files differ". Is anyone else seeing this? Do I have a screwed up setting somewhere?</p>
<p>Thanks,
Andy</p>
<p>Update:
Thanks to VonC for some insight. In most cases, turning off the "Auto-detect encoding of local file" checkbox fixes it, although for at least one file, it didn't help. Also I haven't been able to find a way to do multiple files -- they have to each be changed, one at a time.
I'm still on the lookout for a more comprehensive solution.</p>
| [
{
"answer_id": 413438,
"author": "VonC",
"author_id": 6309,
"author_profile": "https://Stackoverflow.com/users/6309",
"pm_score": 3,
"selected": false,
"text": "auto binary files differ text"
}
] | 2009/01/02 | [
"https://Stackoverflow.com/questions/407571",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/46731/"
] |
407,579 | <p>HI i did this code with help of Marc Gravell in </p>
<p><a href="https://stackoverflow.com/questions/406791/">Why can't I find _left and _right in BinarySearchTree?</a><br>
&<br>
<a href="https://stackoverflow.com/questions/406402/bst-c-code-with-errors">How do I correct an implicit conversion error in BST C# Code?</a></p>
<p>, its Binary search tree , but now I'm having logical error the results coming are wrong the output of my code is the following:</p>
<pre><code>2
3
5
6
10
17
------------------------------------------------
17
2
------------------------------------------------
3
6
Press any key to continue . . .
</code></pre>
<p>the last two number must give the total of inserted elements 6 but its showing 9</p>
<p>and but the way How can i get the height of the tree ?!</p>
<hr>
<pre><code>using System;
using System.Collections.Generic;
using System.Text;
namespace errors
{
class Program
{
static void Main(string[] args)
{
BinarySearchTree t = new BinarySearchTree();
t.insert(ref t.root, 10);
t.insert(ref t.root, 5);
t.insert(ref t.root, 6);
t.insert(ref t.root, 17);
t.insert(ref t.root, 2);
t.insert(ref t.root, 3);
BinarySearchTree.print(t.root);
Console.WriteLine("------------------------------------------------");
Console.WriteLine(t.FindMax());
Console.WriteLine(t.FindMin());
Console.WriteLine("------------------------------------------------");
Console.WriteLine(t.CountLeaves(t.root));
Console.WriteLine(t.CountNodes(t.root));
}
public class TreeNode
{
public int n;
public TreeNode _left;
public TreeNode _right;
public TreeNode(int n, TreeNode _left, TreeNode _right)
{
this.n = n;
this._left = _left;
this._right = _right;
}
public void DisplayNode()
{
Console.Write(n);
}
}
public class BinarySearchTree
{
public TreeNode root;
public BinarySearchTree()
{
root = null;
}
public void insert(ref TreeNode root, int x)
{
if (root == null)
{
root = new TreeNode(x, null, null);
}
else
if (x < root.n)
insert(ref root._left, x);
else
insert(ref root._right, x);
}
public int FindMin()
{
TreeNode current = root;
while (current._left != null)
current = current._left;
return current.n;
}
public int FindMax()
{
TreeNode current = root;
while (current._right != null)
current = current._right;
return current.n;
}
public TreeNode Find(int key)
{
TreeNode current = root;
while (current.n != key)
{
if (key < current.n)
current = current._left;
else
current = current._right;
if (current == null)
return null;
}
return current;
}
public void InOrder(ref TreeNode root)
{
if (root != null)
{
InOrder(ref root._left);
root.DisplayNode();
InOrder(ref root._right);
}
}
public int CountNodes(TreeNode root)
{
int count=1;
if (root._left != null)
count += CountNodes(root._left);
if (root._right != null)
count += CountNodes(root._right);
return count;
}
public int CountLeaves(TreeNode root)
{
int count = (root._left == null && root._right == null) ? 1 : 0;
if (root._left != null)
count += CountLeaves(root._left);
if (root._right != null)
count += CountLeaves(root._right);
return count;
}
public static void print(TreeNode root)
{
if (root != null)
{
print(root._left);
Console.WriteLine(root.n.ToString());
print(root._right);
}
}
}
}
}
</code></pre>
<p>Thanx in advance and special thanx to Marc Gravell .</p>
| [
{
"answer_id": 407606,
"author": "R. Martinho Fernandes",
"author_id": 46642,
"author_profile": "https://Stackoverflow.com/users/46642",
"pm_score": 3,
"selected": true,
"text": "CountNodes int count=1;\n int count = (root._left == null && root._right == null) ? 0 : 1;\n CountLeaves publ... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407579",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
407,586 | <p>Can someone tell me what the code equivelant in VB.Net to this C# code is?</p>
<pre><code>new {name="value"}
</code></pre>
| [
{
"answer_id": 407594,
"author": "BFree",
"author_id": 15861,
"author_profile": "https://Stackoverflow.com/users/15861",
"pm_score": 3,
"selected": true,
"text": " New With {.Name = \"value\"}\n"
}
] | 2009/01/02 | [
"https://Stackoverflow.com/questions/407586",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13502/"
] |
407,587 | <p>Few blob's have been duplicated in my database(oracle 11g), performed XOR operations on the blob using UTL_RAW.BIT_XOR. After that i wanted to count the number of set bits in the binary string, so wrote the code above.</p>
<p>During a small experiment, i wanted to see what is the hex and the integer value produced and wrote this procedure..</p>
<pre><code>SQL> declare
2
3 vblob1 blob;
4
5 BEGIN
6
7 select leftiriscode INTO vblob1 FROM irisdata WHERE irisid=1;
8
9 dbms_output.put_line(rawtohex(vblob1));
10
11
12 dbms_output.put_line(UTL_RAW.CAST_TO_binary_integer(vblob1));
13
14
15 END;
16 /
</code></pre>
<p>OUTPUT: HEXVALUE:</p>
<pre><code>0F0008020003030D030C1D1C3C383C330A3311373724764C54496C0A6B029B84840547A341BBA83D
BB5FB9DE4CDE5EFE96E1FC6169438344D604681D409F9F9F3BC07EE0C4E0C033A23B37791F59F84F
F94E4F664E3072B0229DA09D9F0F1FC600C2E380D6988C198B39517D157E7D66FE675237673D3D28
3A016C01411003343C76740F710F0F4F8FE976E1E882C186D316A63C0C7D7D7D7D397F016101B043
0176C37E767C7E0C7D010C8302C2D3E4F2ACE42F8D3F3F367A46F54285434ABB61BDB53CBF6C7CC0
F4C1C3F349B3F7BEB30E4A0CFE1C85180DC338C2C1C6E7A5CE3104303178724CCC5F451F573F3B24
7F24052000202003291F130F1B0E070C0E0D0F0E0F0B0B07070F1E1B330F27073F3F272E2F2F6F7B
2F2E1F2E4F7EFF7EDF3EBF253F3D2F39BF3D7F7FFED72FF39FE7773DBE9DBFBB3FE7A76E777DF55C
5F5F7ADF7FBD7F6AFE7B7D1FBE7F7F7DD7F63FBFBF2D3B7F7F5F2F7F3D7F7D3B3F3B7FFF4D676F7F
5D9FAD7DD17F7F6F6F0B6F7F3F767F1779364737370F7D3F5F377F2F3D3F7F1F2FE7709FB7BCB77B
0B77CF1DF5BF1F7F3D3E4E7F197F571F7D7E3F7F7F7D7F6F4F75FF6F7ECE2FFF793EFFEDB7BDDD1F
FF3BCE3F7F3FBF3D6C7FFF7F7F4FAF7F6FFFFF8D7777BF3AE30FAEEEEBCF5FEEFEE75FFEACFFDF0F
DFFFF77FFF677F4FFF7F7F1B5F1F5F146F1F1E1B3B1F3F273303170F370E250B
INTEGER VALUE: 15
</code></pre>
<p>There was a variance between the hex code and the integer value produced, so used the following python code to check the actual integer value.</p>
<pre><code>print int("0F0008020003030D030C1D1C3C383C330A3311373724764C54496C0A6B029B84840547A341BBA83D
BB5FB9DE4CDE5EFE96E1FC6169438344D604681D409F9F9F3BC07EE0C4E0C033A23B37791F59F84F
F94E4F664E3072B0229DA09D9F0F1FC600C2E380D6988C198B39517D157E7D66FE675237673D3D28
3A016C01411003343C76740F710F0F4F8FE976E1E882C186D316A63C0C7D7D7D7D397F016101B043
0176C37E767C7E0C7D010C8302C2D3E4F2ACE42F8D3F3F367A46F54285434ABB61BDB53CBF6C7CC0
F4C1C3F349B3F7BEB30E4A0CFE1C85180DC338C2C1C6E7A5CE3104303178724CCC5F451F573F3B24
7F24052000202003291F130F1B0E070C0E0D0F0E0F0B0B07070F1E1B330F27073F3F272E2F2F6F7B
2F2E1F2E4F7EFF7EDF3EBF253F3D2F39BF3D7F7FFED72FF39FE7773DBE9DBFBB3FE7A76E777DF55C
5F5F7ADF7FBD7F6AFE7B7D1FBE7F7F7DD7F63FBFBF2D3B7F7F5F2F7F3D7F7D3B3F3B7FFF4D676F7F
5D9FAD7DD17F7F6F6F0B6F7F3F767F1779364737370F7D3F5F377F2F3D3F7F1F2FE7709FB7BCB77B
0B77CF1DF5BF1F7F3D3E4E7F197F571F7D7E3F7F7F7D7F6F4F75FF6F7ECE2FFF793EFFEDB7BDDD1F
FF3BCE3F7F3FBF3D6C7FFF7F7F4FAF7F6FFFFF8D7777BF3AE30FAEEEEBCF5FEEFEE75FFEACFFDF0F
DFFFF77FFF677F4FFF7F7F1B5F1F5F146F1F1E1B3B1F3F273303170F370E250B",16)
</code></pre>
<p>Answer:</p>
<pre><code>611951595100708231079693644541095422704525056339295086455197024065285448917042457
942011979060274412229909425184116963447100932992139876977824261789243946528467423
887840013630358158845039770703659333212332565531927875442166643379024991542726916
563271158141698128396823655639931773363878078933197184072343959630467756337300811
165816534945075483141582643531294791665590339000206551162697220540050652439977992
246472159627917169957822698172925680112854091876671868161705785698942483896808137
210721991100755736178634253569843464062494863175653771387230991126430841565373390
924951878267929443498220727531299945275045612499928105876210478958806304156695438
684335624641395635997624911334453040399012259638042898470872203581555352191122920
004010193837249388365999010692555403377045768493630826307316376698443166439386014
145858084176544890282148970436631175577000673079418699845203671050174181808397880
048734270748095682582556024378558289251964544327507321930196203199459115159756564
507340111030285226951393012863778670390172056906403480159339130447254293412506482
027099835944315172972281427649277354815211185293109925602315480350955479477144523
387689192243720928249121486221114300503766209279369960344185651810101969585926336
07333771272398091
</code></pre>
<p>To get the set-bit count I have written the following code in C:</p>
<pre><code>int bitsoncount(unsigned x)
{
unsigned int b=0;
if(x > 1)
b=1;
while(x &= (x - 1))
b++;
return b;
}
</code></pre>
<p>When I tried the same code in python it did not work. I am new to python through curiosity I'm experimenting, excuse me if am wrong.</p>
<pre><code>def bitsoncount(x):
b=0;
if(x>1):
b=1;
while(x &= (x-1)):
</code></pre>
<p>I get an error at the last line, need some help in resolving this and implementing the logic in python :-)</p>
<p>I was interested in checking out the set bits version in python after what i have seen!</p>
<p>Related question: <a href="https://stackoverflow.com/questions/109023/best-algorithm-to-count-the-number-of-set-bits-in-a-32-bit-integer">Best algorithm to count the number of set bits in a 32-bit integer?</a></p>
| [
{
"answer_id": 407619,
"author": "Alex",
"author_id": 30181,
"author_profile": "https://Stackoverflow.com/users/30181",
"pm_score": 2,
"selected": false,
"text": " def bitsoncount(x): \n b=0\n while(x > 0):\n x &= x - 1 \n b+=1\n return b\n"
},
{
... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407587",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1636/"
] |
407,596 | <p>Let's say I have the following jQuery AJAX call:</p>
<pre><code>$.ajax({
type: "POST",
url: "MyUrl",
data: "val1=test",
success: function(result){
// Do stuff
}
});
</code></pre>
<p>Now, when this AJAX call is made I want the server-side code to run through a few error handling checks (e.g. is the user still logged in, do they have permission to use this call, is the data valid, etc). If an error is detected, how do I bubble that error message back up to the client side?</p>
<p>My initial thought would be to return a JSON object with two fields: error and errorMessage. These fields would then be checked in the jQuery AJAX call:</p>
<pre><code>$.ajax({
type: "POST",
url: "MyUrl",
data: "val1=test",
success: function(result){
if (result.error == "true")
{
alert("An error occurred: " & result.errorMessage);
}
else
{
// Do stuff
}
}
});
</code></pre>
<p>This feels a bit clunky to me, but it works. Is there a better alternative?</p>
| [
{
"answer_id": 407608,
"author": "rodbv",
"author_id": 79101,
"author_profile": "https://Stackoverflow.com/users/79101",
"pm_score": 2,
"selected": false,
"text": "fail:function(...){..}"
},
{
"answer_id": 407636,
"author": "Salty",
"author_id": 50548,
"author_profile... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407596",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1574/"
] |
407,612 | <p>I have a Java application that I run from a console which in turn executes an another Java process. I want to get a thread/heap dump of that child process.</p>
<p>On Unix, I could do a <code>kill -3 <pid></code> but on Windows AFAIK the only way to get a thread dump is Ctrl-Break in the console. But that only gives me the dump of the parent process, not the child.</p>
<p>Is there another way to get that heap dump?</p>
| [
{
"answer_id": 407625,
"author": "krosenvold",
"author_id": 23691,
"author_profile": "https://Stackoverflow.com/users/23691",
"pm_score": 3,
"selected": false,
"text": "kill -3 <pid> ps"
},
{
"answer_id": 407685,
"author": "Steve Kuo",
"author_id": 24396,
"author_prof... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407612",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
407,614 | <p>I am currently undertaking a project that involves extensive use of Java RMI and I was wondering if anyone is aware of any good resources about it.</p>
<p>The problem I am having with the material I am finding currently is that its usually quite out of date (like Java 1.3) and / or half complete. I would even be happy to buy a book on it but looking on Amazon all the books are like 7 years old. </p>
<p>So if anyone is aware of any good resources, books or good example implementations I would be very interested to hear about them.</p>
| [
{
"answer_id": 37628026,
"author": "Nikita Koksharov",
"author_id": 764206,
"author_profile": "https://Stackoverflow.com/users/764206",
"pm_score": 0,
"selected": false,
"text": "YourServiceImpl YourService YourService yourService = new YourServiceImpl();\n\nRRemoteService remoteService ... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407614",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/50866/"
] |
407,646 | <p>Suppose I've got a table:</p>
<pre><code>Role
----
person_id company_id financial_year
</code></pre>
<p>How can I tell the following:</p>
<ol>
<li>Whether each person_id occurs at most once per company_id per financial_year in this table</li>
<li>If 1. is false, which person_id's and company_id's and financial_year's co-occur more than once</li>
</ol>
<p>Edit 1: Edited to add financial_year col</p>
<p>Edit 2: the RDBMS platform here happens to be MySQL, though I don't expect that this would require much vendor-specific SQL</p>
| [
{
"answer_id": 407660,
"author": "Harper Shelby",
"author_id": 21196,
"author_profile": "https://Stackoverflow.com/users/21196",
"pm_score": 0,
"selected": false,
"text": "select left.person_id, left.company_id, left.financial_year, count(*)\nfrom role left\ninner join role right\n on... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407646",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41613/"
] |
407,651 | <p>This is related to my question on <a href="https://stackoverflow.com/questions/407596/how-do-you-handle-errors-from-ajax-calls">how to handle errors from jQuery AJAX calls</a>. Several responses suggested that I use the "error" callback to display any errors from a jQuery AJAX call. I was wondering how to do that using ASP.NET MVC. Is there a way for my controller action to return an error that would be accessible from the "error" callback? The client side code would look something like this:</p>
<pre><code>$.ajax({
type: "POST",
url: "MyUrl",
data: "val1=test",
success: function(result){
// Do stuff
},
error: function(request,status,errorThrown) {
}
});
</code></pre>
| [
{
"answer_id": 407665,
"author": "John Sheehan",
"author_id": 1786,
"author_profile": "https://Stackoverflow.com/users/1786",
"pm_score": 1,
"selected": false,
"text": "throw new HttpException(500, \"Error message\");\n"
},
{
"answer_id": 407686,
"author": "Salty",
"autho... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407651",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1574/"
] |
407,658 | <p>Situation: I entered several functions while working with REPL in Emacs.
Problem: There is junk like "; Evaluation aborted" when I'm simply saving buffer.
What I want: clear descriptions of all the functions I entered in their latest revision.</p>
<p>Can I do that? Thanks.</p>
| [
{
"answer_id": 407750,
"author": "Charlie Martin",
"author_id": 35092,
"author_profile": "https://Stackoverflow.com/users/35092",
"pm_score": 2,
"selected": false,
"text": "C-x o C-x b C-x w C-x C-s"
},
{
"answer_id": 409281,
"author": "HD.",
"author_id": 6525,
"autho... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407658",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/47937/"
] |
407,687 | <p>How I insert my username, Password values to database using Zend framework. </p>
<p>And how I get the values from the database using zend framework.</p>
| [
{
"answer_id": 407745,
"author": "Thomaschaaf",
"author_id": 19929,
"author_profile": "https://Stackoverflow.com/users/19929",
"pm_score": 0,
"selected": false,
"text": "$db = new Zend_Db(....);\n$data = array('username'=>'thomaschaaf', 'password'= md5('secret'));\n$db->insert('field', $... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407687",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
407,688 | <p>I'm giving <a href="http://db.apache.org/derby/" rel="noreferrer">Apache Derby</a>, aka <a href="http://developers.sun.com/javadb/" rel="noreferrer">JavaDB</a> a spin. I can't seem to get around duplicate key issues when inserting records that may already exist. Is there a Derby equivalent to "<code>insert if not exists</code>", or "<code>merge</code>" ? </p>
<p>Similarly, is there a way to do something like "<code>drop table foo if exists</code>"?</p>
| [
{
"answer_id": 430929,
"author": "Snukker",
"author_id": 44721,
"author_profile": "https://Stackoverflow.com/users/44721",
"pm_score": 4,
"selected": false,
"text": "INSERT INTO foo ( \n SELECT 'a' as A, 'b' as B\n FROM foo \n WHERE \n A = 'a' AND B = 'b' \n HAVING count(*)=0 ... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407688",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1274957/"
] |
407,712 | <p>I am using the Entity framework to create a new order. The order contains a collection of contacts, a many to many relationship. I want to add a reference to an existing contact on the order on creation of the order. Both Order and Contact a Entity Objects.</p>
<pre><code> Order order = new Order();
//set details on order
Contact contact = new Contact();
EntityKey contactKey =
new EntityKey("OrderDetails.Contact",
"contact_id", contact.Key.Id);
contact.EntityKey = contactKey;
contact.contact_id = contact.Key.Id;
order.Contact.Attach(contact); // throws an exception!
OrderDetails ordTable = new OrderDetails();
ordTable.AddToOrder(order);
int result = orgTable.SaveChanges();
</code></pre>
<p>When I go to attach, this exception is thrown:</p>
<p>"Attach is not a valid operation when the source object associated with this related end is in an added, deleted, or detached state. Objects loaded using the NoTracking merge option are always detached."</p>
<p>I know I'm probably missing a step or not fully understanding how the entity framework handles many-to-many relationships.</p>
| [
{
"answer_id": 413516,
"author": "Craig Stuntz",
"author_id": 7714,
"author_profile": "https://Stackoverflow.com/users/7714",
"pm_score": 2,
"selected": false,
"text": "order.Contact.Add(contact);\n"
},
{
"answer_id": 1912464,
"author": "Michael L Perry",
"author_id": 766... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407712",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/46400/"
] |
407,713 | <p>Is there a recommended way to bounce an asp.net application besides touching web.config from inside the application? is <code>HttpRuntime.UnloadAppDomain()</code>; the preferred way to do this ? and if so where do you do this? In the unload of a page or some other place in the application?</p>
| [
{
"answer_id": 407778,
"author": "casperOne",
"author_id": 50776,
"author_profile": "https://Stackoverflow.com/users/50776",
"pm_score": 5,
"selected": false,
"text": "UnloadAppDomain SecurityException"
},
{
"answer_id": 17057662,
"author": "user2431693",
"author_id": 243... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407713",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10676/"
] |
407,720 | <p>I'm using LINQ to SQL to update my database. I'm inserting a lot of records, and when I call SubmitChanges(), LINQ to SQL executes an insert and a select statement for each object. I don't really care to update my objects after they are inserted into the database.</p>
<p>Do you know I can prevent LINQ to SQL from issuing the select statements after the insert statements? This should make my app much faster.</p>
| [
{
"answer_id": 407976,
"author": "Amy B",
"author_id": 8155,
"author_profile": "https://Stackoverflow.com/users/8155",
"pm_score": 3,
"selected": false,
"text": "INSERT INTO [dbo].[TableName]( fieldlist )\nVALUES (@p0, @p1, @p2, @p3, @p4)\n\nSELECT CONVERT(Int,SCOPE_IDENTITY()) AS [value... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407720",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/571/"
] |
407,729 | <p>Given two sets of values:</p>
<pre><code>var subset = new[] { 2, 4, 6, 8 };
var superset = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
</code></pre>
<p>how do I determine if <code>superset</code> contains all elements of <code>subset</code>?</p>
<p>I have come up with this:</p>
<pre><code>superset.Intersect(subset).Count() == subset.Count()
</code></pre>
<p>Is this the most logical and efficient method?</p>
| [
{
"answer_id": 407741,
"author": "leppie",
"author_id": 15541,
"author_profile": "https://Stackoverflow.com/users/15541",
"pm_score": 2,
"selected": false,
"text": "subset.Except(superset).Count() == 0\n"
},
{
"answer_id": 407748,
"author": "Amy B",
"author_id": 8155,
... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407729",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/37815/"
] |
407,731 | <p>The problem statement:</p>
<p>Given a set of integers that is known in advance, <strong>generate</strong> code to test if a single integer is in the set. The domain of the testing function is the integers in some consecutive range.</p>
<hr>
<p>Nothing in particular is known now about the range or the set to be tested. The range could be small or huge (but a solution can reject problems that are to big but higher limits are better). It could be that very few of the values in the allowed range are in the set or most of them are or anything in between. The set may be uniformly distributed or clustered. There may be large sections of only contained/not-contained values or there may be at least a few of each type of value in most swaths. (sort of like the assumption made about items to be sorted when analyzing sorting algorithms)</p>
<p>The objective is a procedure for generating effective code for running the test.</p>
<p>Partial solutions that come to mind include</p>
<ul>
<li>perfect hash function (costly for large sets)</li>
<li>range tests: <code>foreach(b in ranges) if(b.l <= v && v <= b.h) return true;</code></li>
<li>trees/indexes (more costly than others in some cases)</li>
<li>table lookup (costly for large sets)</li>
<li>the inverse of any of these these (kodos to <a href="https://stackoverflow.com/users/44330/jason-s">Jason S</a>)</li>
</ul>
<p>It seems that an ideal solution would be able to pick what option is best or if none work well, use a tree to break down the full range into sections and then switch to other options for subsection that are better suited to them.</p>
<p>Topic(s) that might be useful include:</p>
<ul>
<li><a href="http://en.wikipedia.org/wiki/Huffman_coding" rel="nofollow noreferrer">Huffman coding</a></li>
</ul>
<hr>
<p>Note: this is not homework. if it was issued as homework below the doctoral level the prof should be shot with a Nerf gun (if you don't get that then re-read the problem, it is very much non trivial)</p>
<p>Note: This is a problem that occurred to me a few days a go and I've been puzzling over it off and on. I have no direct use for this but thought it would be a cool problem to attack. The reason that I wan to generate the code is because generated code will be no slower than general code (it can be the same thing if needed) and might be faster in some/many cases.</p>
<p>I'm posting this question as much to clarify my thoughts as anything. If I can come up with any reasonable or cool solutions I plan on implementing them as a template meta program (the other reason for generated code)</p>
<p>some people have noted that the problem is very general. That is the point. I'm hoping to generate a system that would work an a very general domain: sets of integers in some range.</p>
| [
{
"answer_id": 407741,
"author": "leppie",
"author_id": 15541,
"author_profile": "https://Stackoverflow.com/users/15541",
"pm_score": 2,
"selected": false,
"text": "subset.Except(superset).Count() == 0\n"
},
{
"answer_id": 407748,
"author": "Amy B",
"author_id": 8155,
... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407731",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1343/"
] |
407,734 | <p>I need to use a priority queue in my Python code, and:</p>
<ul>
<li>am looking for any <strong>fast</strong> implementations for priority queues</li>
<li>optimally, I'd like the queue to be <strong>generic</strong> (i.e. work well for any object with a specified comparison operator).</li>
</ul>
<p>Looking around for something efficient, I came upon <a href="http://docs.python.org/library/heapq.html" rel="noreferrer">heapq</a>, but:</p>
<ul>
<li>I'm looking for something faster than <code>heapq</code>, which is implemented in native Python, so it's not fast.</li>
<li>It looks good, but seems to be specified only for integers. I suppose it works with any objects that have comparison operators, but it doesn't specify what comparison operators it needs. </li>
<li>Update: Re comparison in <code>heapq</code>, I can either use a <code>(priority, object)</code> as Charlie Martin suggests, or just implement <code>__cmp__</code> for my object. </li>
</ul>
| [
{
"answer_id": 407755,
"author": "Charlie Martin",
"author_id": 35092,
"author_profile": "https://Stackoverflow.com/users/35092",
"pm_score": 7,
"selected": true,
"text": "(priority, thing)"
},
{
"answer_id": 407922,
"author": "Eli Bendersky",
"author_id": 8206,
"auth... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407734",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8206/"
] |
407,737 | <p>I'm trying to build a query with hibernate criteria for the following scenario:</p>
<ul>
<li>Two entities: Indicator and report (each with their own tables, classes etc.)</li>
<li>an indicator can be used in zero to many reports</li>
<li>a report uses zero to many indicators</li>
<li>therefore, I have an intersection table to store the relationship</li>
<li>the relationship is defined in both classes and their hibernate mappings</li>
<li>in the UI, the user can select one or many reports (among other things), and I would like to query the DB for the Indicators used in these reports </li>
</ul>
<p>I've tried the following:</p>
<pre><code>criteria.add(Restrictions.in("Reports", selectedReports));
</code></pre>
<p>but all I get is a strange SQL Statement with</p>
<pre><code>where this_.Indicator_ID in (?)
</code></pre>
<p>and then a JDBC exception (missing parameter)</p>
<p>Any ideas? Thanks.</p>
<p>Note: I've looked into <a href="https://stackoverflow.com/questions/264339/querying-manytomany-relationship-with-hibernate-criteria">Querying ManyToManyrelationship with Hibernate Criteria</a>, but the accepted solution there is to build a custom sql-string ...</p>
| [
{
"answer_id": 407779,
"author": "zmf",
"author_id": 13285,
"author_profile": "https://Stackoverflow.com/users/13285",
"pm_score": 3,
"selected": true,
"text": " Criteria c = session.createCriteria(Indicator.class);\n c.add(Restrictions.eq(\"someField\", myObject).createCriteria(\"re... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407737",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25320/"
] |
407,739 | <p>With more and more projects under my belt I find that I am often repeating many common tasks from project to project, client to client. So I have started to assemble a "utility" library, a collection of these common elements that are often repeated from project to project.</p>
<p>So far I have utilities to resize images, export data grids to excel, send e-mails, and replace tokenized messages. </p>
<p>If you were building/using a .NET utility class library, what types of processes would you see as helpful? What namespaces/groups would you envision?</p>
<p><strong>Update</strong></p>
<p>I am talking about an actual class library, separated into namespaces to group common elements.</p>
| [
{
"answer_id": 407768,
"author": "Lasse V. Karlsen",
"author_id": 267,
"author_profile": "https://Stackoverflow.com/users/267",
"pm_score": 1,
"selected": false,
"text": "Tuple<..> Set<T> Heap<T>"
}
] | 2009/01/02 | [
"https://Stackoverflow.com/questions/407739",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13279/"
] |
407,763 | <p>Backdrop: There are two forms, the main application form and a form to edit various settings for the operations of main application.</p>
<p>What would be the proper way to show the frmSettings form and how to dispose it once clicked OK or Cancel in the actual frmSettings form?</p>
| [
{
"answer_id": 407785,
"author": "Austin Salonen",
"author_id": 4068,
"author_profile": "https://Stackoverflow.com/users/4068",
"pm_score": 0,
"selected": false,
"text": "using (frmSettings s = new frmSettings() )\n{\n if( s.ShowDialog() == DialogResult.OK )\n {\n //do work\n ... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407763",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
407,770 | <p>I have an application where I need the user to be able to update or delete rows of data from the database. The rows are displayed to the user using a foreach loop in the .aspx file of my view. Each row will have two text fields (txtName, txtDesc), an update button, and a delete button. What I'm not sure of, is how do I have the update button send the message to the controller for which row to update? I can see a couple way of doing this:</p>
<ol>
<li>Put each row within it's own form tag, then when the update button is clicked, it will submit the values for that row only (there will also be a hidden field with the rowId) and the controller class would take all the post values as parameters to the Update method on the controller.</li>
<li>Somehow, have the button be scripted in a way to send back only the values for that row with a POST to the controller.</li>
</ol>
<p>Is there a way of doing this? One thing I am concerned about is if each row has different names for it's controls assigned by ASP.NET (txtName1, txtDesc1, txtName2, txtDesc2), then how will their values get mapped to the correct parameters of the Controller method?</p>
| [
{
"answer_id": 408006,
"author": "rodbv",
"author_id": 79101,
"author_profile": "https://Stackoverflow.com/users/79101",
"pm_score": 5,
"selected": true,
"text": "<form method=\"post\" action=\"/YourController/YourAction/<%=rowId%>\">\n YourController/YourAction/1 YourController/YourActi... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407770",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14101/"
] |
407,771 | <p>How can one allow code snippets to be entered into an editor (as stackoverflow does) like FCKeditor or any other editor while preventing XSS, SQL injection, and related attacks.</p>
| [
{
"answer_id": 407836,
"author": "luiscubal",
"author_id": 32775,
"author_profile": "https://Stackoverflow.com/users/32775",
"pm_score": 0,
"selected": false,
"text": "$code = getTheCodeSnippet();\n$code = htmlentities($code);\n$code = str_ireplace(\"<br>\", \"<br>\", $code); //exa... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407771",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40376/"
] |
407,793 | <p>This should be a simple question, but I haven't been able to find a way to make it work.</p>
<p>Essentially, I have a silly localhost page that I use in my webdevelopment. When I am surfing between our development server and my local version of the C# code (redirected from the dev url via host file) I have been known to sometimes forget what 'dev.foo.com' points at - local or server.</p>
<p>So I created a page which will run locally as my default web page's default page, so I can easily identify my localhost from the server.</p>
<p>This page does a lot of things randomly (including generating a character's starting stats for D&D), including setting a random background color. I do this by generating 3 random numbers between 0 and 255, and setting them as the RGB value for the body background color in CSS.</p>
<p>Given the 3 ints R, G, and B, how do I determine R2, G2, and B2 such that the second color will have high contrast with the first? I like having the page have random background colors (it keeps me from getting used to the look of the landing page) but I also like to be able to read the text.</p>
| [
{
"answer_id": 407804,
"author": "bobwienholt",
"author_id": 24257,
"author_profile": "https://Stackoverflow.com/users/24257",
"pm_score": 2,
"selected": false,
"text": "R2 = ~R1;\nG2 = ~G1;\nB2 = ~B1;\n"
},
{
"answer_id": 407819,
"author": "mhenry1384",
"author_id": 2426... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407793",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23902/"
] |
407,854 | <p>When building a project I tag the source using the svn copy command. When viewing history for trunk I don't see a log message for those tags. I would like to see a log message for each of my release versions in trunk. </p>
<p>I want to be able to easily see which changes were in each release. Right now I need to go back and find the revision number for each tag and keep track of that number manually when looking at the log.</p>
<p>I would even be happy if I could run another command to add a log message to trunk after the tag took place. However, I can't find a way to get a message to show in the log for each file since no file changed after the tag.</p>
| [
{
"answer_id": 408992,
"author": "Bert Huijben",
"author_id": 2094,
"author_profile": "https://Stackoverflow.com/users/2094",
"pm_score": 1,
"selected": false,
"text": "svnmucc \\\n cp 1234 http://srv/svn/project/trunk http://srv/svn/project/tags/release \\\n propset last-tag ^/tags/re... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407854",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6174/"
] |
407,855 | <p>Hopefully a simple question. Take for instance a Circularly-linked list:</p>
<pre><code>class ListContainer
{
private listContainer next;
<..>
public void setNext(listContainer next)
{
this.next = next;
}
}
class List
{
private listContainer entry;
<..>
}
</code></pre>
<p>Now since it's a circularly-linked list, when a single elemnt is added, it has a reference to itself in it's next variable. When deleting the only element in the list, entry is set to null. Is there a need to set ListContainer.next to null as well for Garbage Collector to free it's memory or does it handle such self-references automagically?</p>
| [
{
"answer_id": 18350674,
"author": "Aniket Thakur",
"author_id": 2396539,
"author_profile": "https://Stackoverflow.com/users/2396539",
"pm_score": 2,
"selected": false,
"text": "How?\n"
}
] | 2009/01/02 | [
"https://Stackoverflow.com/questions/407855",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35685/"
] |
407,858 | <p>I have a Flex 3 app (player v9) which loads a Flash SWF (AS3, also player v9) and needs to dynamically pass it a collection of parameters which are known at run-time. These are parameters that are normally passed via the <code>flashvars</code> element in an HTML page. The embedded movie accesses these parameters via the <code>loaderInfo.parameters</code> object.</p>
<p>I've tried using <code>SWFLoader</code> and <code>Loader</code> classes with no success in param-passing.</p>
<p>Relevant details:</p>
<ul>
<li>It's a local program, and cannot rely on query string parameters.</li>
<li>I've mucked with setting <code>loaderInfo.parameters["foo"] = "123"</code> from the embedding code, but the parameter never seems to wind up in the embedded movie.</li>
<li>I cannot place extra parameter-passing machinery in the embedded movie(s), as they are created by third parties.</li>
</ul>
| [
{
"answer_id": 408859,
"author": "Theo",
"author_id": 1109,
"author_profile": "https://Stackoverflow.com/users/1109",
"pm_score": 0,
"selected": false,
"text": "file:///some/path/to/a.swf file:///some/path/to/a.swf?hello=world&foo=bar"
},
{
"answer_id": 447728,
"author": "ale... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407858",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26829/"
] |
407,881 | <p>I often want to define new 'Exception' classes, but need to have an appropriate constructor defined because constructors aren't inherited. </p>
<pre><code>class MyException : public Exception
{
public:
MyException (const UString Msg) : Exception(Msg)
{
};
}
</code></pre>
<p>Typedefs don't work for this, because they are simply aliases, not new classes. Currently, to avoid repeating this trivial boilerplate, I use a #define which does the donkeywork. </p>
<pre><code>#define TEXCEPTION(T) class T : public Exception \
{ \
public:\
T(const UString Msg) : Exception(Msg) {}; \
}
...
TEXCEPTION(MyException);
</code></pre>
<p>But I keep wondering if there's a better way of achieving this - maybe with templates, or some new C++0x feature </p>
| [
{
"answer_id": 407949,
"author": "Judge Maygarden",
"author_id": 1491,
"author_profile": "https://Stackoverflow.com/users/1491",
"pm_score": 1,
"selected": false,
"text": "#include <iostream>\n#include <string>\n\nusing namespace std;\n\nenum ExceptionId {\n EXCEPTION_FOO,\n EXCEPT... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407881",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1737/"
] |
407,904 | <p>I have a constantly growing database of keywords. I need to parse incoming text inputs (articles, feeds etc) and find which keywords from the database are present in the text. The database of keywords is much larger than the text.</p>
<p>Since the database is constantly growing (users add more and more keywords to watch for), I figure the best option will be to break the text input into words and compare those against the database. My main dilemma is implementing this comparison scheme (PHP and MySQL will be used for this project).</p>
<p>The most naive implementation would be to create a simple SELECT query against the keywords table, with a giant IN clause listing all the found keywords.</p>
<pre><code>SELECT user_id,keyword FROM keywords WHERE keyword IN ('keyword1','keyword2',...,'keywordN');
</code></pre>
<p>Another approach would be to create a hash-table in memory (using something like memcache) and to check against it in the same manner.</p>
<p>Does anyone has any experience with this kind of searching and has any suggestions on how to better implement this? I haven't tried yet any of those approaches, I'm just gathering ideas at this point.</p>
| [
{
"answer_id": 407972,
"author": "ʞɔıu",
"author_id": 41613,
"author_profile": "https://Stackoverflow.com/users/41613",
"pm_score": 0,
"selected": false,
"text": "inverted_index\n-----\ndocument_id keyword\n select document_id, count(*) from inverted_index\n where keyword in (keyword1, ... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407904",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10585/"
] |
407,929 | <p>By default <a href="http://en.wikipedia.org/wiki/Eclipse_%28software%29" rel="noreferrer">Eclipse</a> indents with a hard tab character. How do I change it to spaces?</p>
| [
{
"answer_id": 407933,
"author": "Brian Deacon",
"author_id": 409,
"author_profile": "https://Stackoverflow.com/users/409",
"pm_score": 5,
"selected": false,
"text": "Indentation"
},
{
"answer_id": 408449,
"author": "Dave Ray",
"author_id": 40310,
"author_profile": "h... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407929",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/409/"
] |
407,934 | <p>What's the best way to put the "debugger;" statement inside the __doPostBack method or a way to step in the method?</p>
| [
{
"answer_id": 407968,
"author": "mmx",
"author_id": 33708,
"author_profile": "https://Stackoverflow.com/users/33708",
"pm_score": 1,
"selected": true,
"text": "iexplore.exe"
}
] | 2009/01/02 | [
"https://Stackoverflow.com/questions/407934",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5232/"
] |
407,935 | <p>My kindergarten SQL Server taught me that a trigger may be fired with multiple rows in the inserted and deleted pseudo tables. I mostly write my trigger code with this in mind, often resulting in some cursor based cludge. Now I'm really only able to test them firing for a single row at a time. How can I generate a multirow trigger and will SQL Server actually ever send a multirow trigger? Can I set a flag so that SQL Server will only fire single row triggers??</p>
| [
{
"answer_id": 408381,
"author": "Mitch Wheat",
"author_id": 16076,
"author_profile": "https://Stackoverflow.com/users/16076",
"pm_score": 3,
"selected": false,
"text": "-- BAD Trigger code following:\n\nCREATE TRIGGER trg_Table1 \nON Table1 \nFor UPDATE\nAS\nDECLARE @var1 int, @var2 var... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407935",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13219/"
] |
407,947 | <p>I have seen different ways to retrieve a string field from SQL. Is there a "right" way, and what are the differences</p>
<pre><code> SqlDataReader rdr;
1. String field = (String) rdr["field"];
2. String field = rdr["field"].ToString();
3. String field = rdr["field"] As String;
</code></pre>
<p>Thanks!</p>
| [
{
"answer_id": 407997,
"author": "JoshBerke",
"author_id": 26160,
"author_profile": "https://Stackoverflow.com/users/26160",
"pm_score": 3,
"selected": false,
"text": "int ordinal=rdr.GetOrdinal(\"stringField\");\nif (rdr.IsDBNull(ordinal))\n{\n return string.Empty; //Or null or howev... | 2009/01/02 | [
"https://Stackoverflow.com/questions/407947",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/37955/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.