qid
int64
4
8.14M
question
stringlengths
20
48.3k
answers
list
date
stringlengths
10
10
metadata
list
input
stringlengths
12
45k
output
stringlengths
2
31.8k
408,133
<p>I am wondering if someone can help me figure out the best approach to the following problem. I'm building a web application which uses Django templating to construct its web UI component. There are a number of common HTML elements such as the header / footer, HTML head, masthead etc. I'd like to code these once a...
[ { "answer_id": 408176, "author": "S.Lott", "author_id": 10661, "author_profile": "https://Stackoverflow.com/users/10661", "pm_score": 3, "selected": false, "text": "<p>Try the <code>{% include %}</code> tag. </p>\n\n<p><a href=\"http://docs.djangoproject.com/en/dev/ref/templates/builtin...
2009/01/02
[ "https://Stackoverflow.com/questions/408133", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26241/" ]
I am wondering if someone can help me figure out the best approach to the following problem. I'm building a web application which uses Django templating to construct its web UI component. There are a number of common HTML elements such as the header / footer, HTML head, masthead etc. I'd like to code these once and "in...
You can use django's `extends` tag. Say you had a header and footer. You could make a template, called, say, foo.django: ``` <h1>My HTML Header</h1> <!-- an so on --> {% block content %} {% endblock %} <!-- html footer --> ``` Then, you can make another template, say, bar.django: ``` {% extends "foo.django" %} {...
408,139
<p>Now I must be missing something here, as this seems a very basic issue that would be addressed in any "Getting started with Flex charting" tutorial. However, all that I could find was hints that the chart should update automatically whenever the dataProvider changes. Mind you, hints.</p> <p>This is my markup:</p> ...
[ { "answer_id": 408173, "author": "rmeador", "author_id": 10861, "author_profile": "https://Stackoverflow.com/users/10861", "pm_score": 4, "selected": true, "text": "<p>Take a look at <a href=\"http://livedocs.adobe.com/flex/3/langref/mx/collections/ArrayCollection.html\" rel=\"noreferrer...
2009/01/02
[ "https://Stackoverflow.com/questions/408139", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2077/" ]
Now I must be missing something here, as this seems a very basic issue that would be addressed in any "Getting started with Flex charting" tutorial. However, all that I could find was hints that the chart should update automatically whenever the dataProvider changes. Mind you, hints. This is my markup: ``` <?xml vers...
Take a look at [this](http://livedocs.adobe.com/flex/3/langref/mx/collections/ArrayCollection.html). In Flex, all of the data structure classes (such as `Array`) have corresponding Collection (or CollectionView) classes that act as wrappers. When you use the wrapper functions such as `addItem()`, it dispatches an event...
408,159
<p>Documentation simply states that setting <code>setAutosavingDelay</code> to anything > 0 on the shared doc controller should do it, but after calling </p> <pre><code>[[NSDocumentController sharedDocumentController] setAutosavingDelay:2.0]; </code></pre> <p>in my controller, autosave doesn't seem to work: I neither...
[ { "answer_id": 409441, "author": "Mike Abdullah", "author_id": 28768, "author_profile": "https://Stackoverflow.com/users/28768", "pm_score": 4, "selected": true, "text": "<p>Have you overridden -updateChangeCount: at all? I'm pretty certain that Apple's implementation is the code that st...
2009/01/02
[ "https://Stackoverflow.com/questions/408159", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6559/" ]
Documentation simply states that setting `setAutosavingDelay` to anything > 0 on the shared doc controller should do it, but after calling ``` [[NSDocumentController sharedDocumentController] setAutosavingDelay:2.0]; ``` in my controller, autosave doesn't seem to work: I neither see anything in `~/Library/Autosave ...
Have you overridden -updateChangeCount: at all? I'm pretty certain that Apple's implementation is the code that starts up the autosave timer. Also, what if you experiment with a longer timer?
408,192
<p>When trying to compile my class I get an error: </p> <blockquote> <p>The constant <code>'NamespaceName.ClassName.CONST_NAME'</code> cannot be marked static.</p> </blockquote> <p>at the line:</p> <pre><code>public static const string CONST_NAME = "blah"; </code></pre> <p>I could do this all of the time in Java...
[ { "answer_id": 408197, "author": "Joel Coehoorn", "author_id": 3043, "author_profile": "https://Stackoverflow.com/users/3043", "pm_score": 11, "selected": true, "text": "<p>A <code>const</code> object is always <code>static</code>.</p>\n" }, { "answer_id": 408201, "author": "...
2009/01/02
[ "https://Stackoverflow.com/questions/408192", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2598/" ]
When trying to compile my class I get an error: > > The constant `'NamespaceName.ClassName.CONST_NAME'` cannot be marked static. > > > at the line: ``` public static const string CONST_NAME = "blah"; ``` I could do this all of the time in Java. What am I doing wrong? And why doesn't it let me do this?
A `const` object is always `static`.
408,196
<p>The problem I'm running into is that as far as I know the delete operator should be a static function but sometimes the compiler (VC++) seems to be treating it as dynamic. </p> <p>Given:</p> <pre><code>class Base { public: void* operator new(size_t size) { /* allocate from custom heap */ } void operator delet...
[ { "answer_id": 408213, "author": "Johannes Schaub - litb", "author_id": 34509, "author_profile": "https://Stackoverflow.com/users/34509", "pm_score": 4, "selected": true, "text": "<p>It is certainly Standard Behavior. If the derived class's operator new was used, <em>its</em> operator de...
2009/01/02
[ "https://Stackoverflow.com/questions/408196", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26983/" ]
The problem I'm running into is that as far as I know the delete operator should be a static function but sometimes the compiler (VC++) seems to be treating it as dynamic. Given: ``` class Base { public: void* operator new(size_t size) { /* allocate from custom heap */ } void operator delete(void *p) { customFre...
It is certainly Standard Behavior. If the derived class's operator new was used, *its* operator delete will also be used (also note even though you do not explicitly tell the compiler those functions are static, they *are* implicitly declared so). There might be the naughty case where you have an operator new in the de...
408,207
<p>We have a ASP.NET application that uses the Exception Handling Application block to log our exception to a database (using logging block indirectly). This all working perfect. However, since it is using the exception handling block to log data, everytime we wanted to log, we'll have to new'd a System.Exception obj...
[ { "answer_id": 408251, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "<p>I wouldn't say so. Its an exception handling block, not a logging block. Perhaps you should have used the EL's LAB instea...
2009/01/02
[ "https://Stackoverflow.com/questions/408207", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31206/" ]
We have a ASP.NET application that uses the Exception Handling Application block to log our exception to a database (using logging block indirectly). This all working perfect. However, since it is using the exception handling block to log data, everytime we wanted to log, we'll have to new'd a System.Exception object. ...
You can define a logging policy independently from an exception handling policy, they do not have to be used together. Exception handling and logging are many times used together through chaining of listeners. For example, you could catch a specific error in a catch block and reference your exception handling policy,...
408,225
<p>On my page I have a drop-down select box, with a default value of (empty). When the user selects an entry, the appropriate form for that entry type is displayed.</p> <p>Couple of problems..</p> <ol> <li>The code is not DRY and seems more verbose than it needs to be, so not easily maintainable / extensible.</li> <l...
[ { "answer_id": 408231, "author": "Eran Galperin", "author_id": 10585, "author_profile": "https://Stackoverflow.com/users/10585", "pm_score": 4, "selected": true, "text": "<p>Instead of the multiple IF clauses, you can iterate over an array of values. But in this case, if there are no oth...
2009/01/02
[ "https://Stackoverflow.com/questions/408225", "https://Stackoverflow.com", "https://Stackoverflow.com/users/39539/" ]
On my page I have a drop-down select box, with a default value of (empty). When the user selects an entry, the appropriate form for that entry type is displayed. Couple of problems.. 1. The code is not DRY and seems more verbose than it needs to be, so not easily maintainable / extensible. 2. When a user selects some...
Instead of the multiple IF clauses, you can iterate over an array of values. But in this case, if there are no other requirements then simply: ``` $(document).ready(function(){ var select = $('#select_type'); $('#' + select.val()).toggle(); // Toggle the preset value select.change(function () { ...
408,265
<p>I have a form that is dynamically generated, and has dynamically generated id's (and potentially classes). The forms are the same but they have the related id tacked on to the end.</p> <p>How can I select each set of inputs and apply code to each one?</p> <p>I was experimenting with $('input[id^=@id_airline_for_]'...
[ { "answer_id": 408272, "author": "Sophie Alpert", "author_id": 49485, "author_profile": "https://Stackoverflow.com/users/49485", "pm_score": 2, "selected": false, "text": "<p>You can use <code>$(\"input#id_airline_for\" + id)</code> (where <code>id</code> is your number, e.g., 8), but it...
2009/01/02
[ "https://Stackoverflow.com/questions/408265", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22306/" ]
I have a form that is dynamically generated, and has dynamically generated id's (and potentially classes). The forms are the same but they have the related id tacked on to the end. How can I select each set of inputs and apply code to each one? I was experimenting with $('input[id^=@id\_airline\_for\_]') but could no...
``` $("input[id^='id_airline_for_']").each(function() { var id = parseInt(this.id.replace("id_airline_for_", ""), 10); var airline = $("#id_airline_for_" + id); var flightNumber = $("#id_flight_number_for_" + id); // do stuff with airline and flightNumber <input>s }); ```
408,286
<p>I'm trying to do what I think is a simple thing under Linux. I have a bash script which runs various test programs, and I want to determine which files in the current directory were created by the test programs. So I am doing something like this:</p> <pre> touch timestamp-file run the test find -newer timestamp-fil...
[ { "answer_id": 408311, "author": "paxdiablo", "author_id": 14860, "author_profile": "https://Stackoverflow.com/users/14860", "pm_score": 2, "selected": false, "text": "<p>You can actually use touch to force the timestamps of all current files in the directory to far in the past, such as:...
2009/01/02
[ "https://Stackoverflow.com/questions/408286", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51048/" ]
I'm trying to do what I think is a simple thing under Linux. I have a bash script which runs various test programs, and I want to determine which files in the current directory were created by the test programs. So I am doing something like this: ``` touch timestamp-file run the test find -newer timestamp-file -type ...
Take the filenames of all the files before the run, but include their timestamps: ``` find -printf '%p %T@\n' | sort > file1 ``` If you haven't got that find option available, you can use stat for that job too: ``` find -print0 | xargs -0 stat -c "%n %Y" | sort > file1 ``` And after the run to `file2`. Then use ...
408,310
<p>I've got some code that looks like this:</p> <pre><code>using (DBDataContext dc = new DBDataContext(ConnectionString)) { Main main = new Main { ClientTime = clientTime }; dc.Mains.InsertOnSubmit(main); dc.SubmitChanges(); return main.ID; } </code></pre> <p>If I return from inside a ...
[ { "answer_id": 408313, "author": "Otávio Décio", "author_id": 48684, "author_profile": "https://Stackoverflow.com/users/48684", "pm_score": 6, "selected": true, "text": "<p>Yes, and that's one of the big advantages of <code>using</code> it.</p>\n" }, { "answer_id": 408315, "a...
2009/01/02
[ "https://Stackoverflow.com/questions/408310", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1463/" ]
I've got some code that looks like this: ``` using (DBDataContext dc = new DBDataContext(ConnectionString)) { Main main = new Main { ClientTime = clientTime }; dc.Mains.InsertOnSubmit(main); dc.SubmitChanges(); return main.ID; } ``` If I return from inside a "using", will the using st...
Yes, and that's one of the big advantages of `using` it.
408,316
<p>Has anything useful come out of Intentional or "Language Oriented" Programming?</p> <p>This isn't a rhetorical question. I'm looking for people who've tried these tools (ie. representing programs in some "higher level" format than mere text and using different editors for different domain specific subsets) and have...
[ { "answer_id": 408371, "author": "OscarRyz", "author_id": 20654, "author_profile": "https://Stackoverflow.com/users/20654", "pm_score": 3, "selected": true, "text": "<p>One very useful usage it to make test cases clearer, not only for the business analyst but for yourself/your team. </p>...
2009/01/02
[ "https://Stackoverflow.com/questions/408316", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8482/" ]
Has anything useful come out of Intentional or "Language Oriented" Programming? This isn't a rhetorical question. I'm looking for people who've tried these tools (ie. representing programs in some "higher level" format than mere text and using different editors for different domain specific subsets) and have some comm...
One very useful usage it to make test cases clearer, not only for the business analyst but for yourself/your team. When time passes and you've forgotten what the exact test case was all about, having LOP is very helpful. You can have the spec at hand, and even document the rules in source code comments, but those art...
408,320
<p>I am adding items to a <code>ListBox</code> like so:</p> <pre><code>myListBox.Items.addRange(myObjectArray); </code></pre> <p>and I also want to select some of the items I add by the following:</p> <pre><code>foreach(MyObject m in otherListOfMyObjects) { int index = myListBox.Items.IndexOf(m); myListBox....
[ { "answer_id": 408327, "author": "Neil Barnwell", "author_id": 26414, "author_profile": "https://Stackoverflow.com/users/26414", "pm_score": 4, "selected": true, "text": "<p>You should make sure that <code>MyObject</code> overrides <code>Equals()</code>, <code>GetHashCode()</code> and <c...
2009/01/02
[ "https://Stackoverflow.com/questions/408320", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2598/" ]
I am adding items to a `ListBox` like so: ``` myListBox.Items.addRange(myObjectArray); ``` and I also want to select some of the items I add by the following: ``` foreach(MyObject m in otherListOfMyObjects) { int index = myListBox.Items.IndexOf(m); myListBox.SelectedIndices.Add(index); } ``` however `ind...
You should make sure that `MyObject` overrides `Equals()`, `GetHashCode()` and `ToString()` so that the `IndexOf()` method can find the object properly. Technically, `ToString()` doesn't need to be overridden for equality testing, but it is useful for debugging.
408,336
<p>I have the following use case , lot of code which was tightly coupled on a concrete type (say Concrete1). Later figured out the concrete type needs to be changed, so defined an interface . E.g</p> <pre><code>Class ABC { virtual int foo() = 0; virtual int getType() = 0; } class Concrete1 : public ABC { int...
[ { "answer_id": 408351, "author": "Beau Simensen", "author_id": 50453, "author_profile": "https://Stackoverflow.com/users/50453", "pm_score": 0, "selected": false, "text": "<p>Can you move the places that you are detecting object types outside of the class into the class? That way the fun...
2009/01/02
[ "https://Stackoverflow.com/questions/408336", "https://Stackoverflow.com", "https://Stackoverflow.com/users/43756/" ]
I have the following use case , lot of code which was tightly coupled on a concrete type (say Concrete1). Later figured out the concrete type needs to be changed, so defined an interface . E.g ``` Class ABC { virtual int foo() = 0; virtual int getType() = 0; } class Concrete1 : public ABC { int foo() { ....
the entire point of using interfaces is so that you can use polymorphism which means you should never have to check what type an instance is. doing so is a very big code smell (see Fowlers Refacotring). move the conditional logic to the concrete classes and add te function that will handle it to the interface EDIT (Ad...
408,342
<p>I'm creating a website for my church and I'm having problems making it display right in IE. It seems that my div "sidebox" is having its background position overridden by the "margin: 0 auto;" as the background displays centered rather than on the right, which is shifting the site to the right.</p> <p>Here's the c...
[ { "answer_id": 408368, "author": "Abram Simon", "author_id": 46204, "author_profile": "https://Stackoverflow.com/users/46204", "pm_score": 2, "selected": false, "text": "<p>I would take an entirely different approach to how you chopped up the background image. </p>\n\n<ol>\n<li>Create a...
2009/01/02
[ "https://Stackoverflow.com/questions/408342", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16437/" ]
I'm creating a website for my church and I'm having problems making it display right in IE. It seems that my div "sidebox" is having its background position overridden by the "margin: 0 auto;" as the background displays centered rather than on the right, which is shifting the site to the right. Here's the code: ``` ....
Looking at it through IE developer toolbar, it gives .sidebox an alignment of center. Changing that to left seems to fix it. ``` .sidebox { ... text-align: left; } ```
408,358
<p>I'm coding a game, and I'd like to be able to find the center of mass of an arbitrary shape on a black and white bitmap such as this:</p> <pre> 012345678 0.XX...... 1..XXX.... 2...XXX... 3..XXXXXXX 4...XXX... </pre> <p>All "cells" have the same weight. Diagonally adjacent cells are not considered to be connected,...
[ { "answer_id": 408376, "author": "Yuval Adam", "author_id": 24545, "author_profile": "https://Stackoverflow.com/users/24545", "pm_score": 5, "selected": true, "text": "<p>How about this algorithm (psuedo-code) based on a boolean matrix like in your example :</p>\n\n<pre><code>xSum = 0\ny...
2009/01/03
[ "https://Stackoverflow.com/questions/408358", "https://Stackoverflow.com", "https://Stackoverflow.com/users/914/" ]
I'm coding a game, and I'd like to be able to find the center of mass of an arbitrary shape on a black and white bitmap such as this: ``` 012345678 0.XX...... 1..XXX.... 2...XXX... 3..XXXXXXX 4...XXX... ``` All "cells" have the same weight. Diagonally adjacent cells are not considered to be connected, and the shap...
How about this algorithm (psuedo-code) based on a boolean matrix like in your example : ``` xSum = 0 ySum = 0 points = 0 for point in matrix if point is marked xSum += pointX ySum += pointY points++ return (xSum/points, ySum/points) ``` Nothing too complicated, calculate where X is the ...
408,401
<p>I'm looking for a drop in solution for caching large-ish amounts of data.</p> <p>related questions but for different languages:</p> <ul> <li><a href="https://stackoverflow.com/questions/226693/python-disk-based-dictionary">Python Disk-Based Dictionary</a></li> <li><a href="https://stackoverflow.com/questions/14948...
[ { "answer_id": 408438, "author": "leora", "author_id": 4653, "author_profile": "https://Stackoverflow.com/users/4653", "pm_score": 0, "selected": false, "text": "<p>you can use the <a href=\"http://www.codeproject.com/KB/database/MS_Application_Blocks.aspx\" rel=\"nofollow noreferrer\">M...
2009/01/03
[ "https://Stackoverflow.com/questions/408401", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1343/" ]
I'm looking for a drop in solution for caching large-ish amounts of data. related questions but for different languages: * [Python Disk-Based Dictionary](https://stackoverflow.com/questions/226693/python-disk-based-dictionary) * [Disk-backed STL container classes?](https://stackoverflow.com/questions/149488/disk-back...
Disclaimer - I am about to point you at a product that I am involved in. I'm still working on the web site side of things, so there is not a lot of info, but [Serial Killer](http://www.thinkbottomup.com.au/site/Products/SerialKiller) would be a good fit for this. I have examples that use .Net serialization (can supply...
408,405
<p>I'm teaching myself some basic scraping and I've found that sometimes the URL's that I feed into my code return 404, which gums up all the rest of my code.</p> <p>So I need a test at the top of the code to check if the URL returns 404 or not.</p> <p>This would seem like a pretty straightfoward task, but Google's n...
[ { "answer_id": 408414, "author": "Ross", "author_id": 29173, "author_profile": "https://Stackoverflow.com/users/29173", "pm_score": 3, "selected": false, "text": "<p>I found this answer <a href=\"http://robert.arlesnet.com/2008/01/20/betwittered-php-and-file_get_contents/\" rel=\"norefer...
2009/01/03
[ "https://Stackoverflow.com/questions/408405", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I'm teaching myself some basic scraping and I've found that sometimes the URL's that I feed into my code return 404, which gums up all the rest of my code. So I need a test at the top of the code to check if the URL returns 404 or not. This would seem like a pretty straightfoward task, but Google's not giving me any ...
If you are using PHP's [`curl` bindings](http://us3.php.net/manual/en/ref.curl.php), you can check the error code using [`curl_getinfo`](http://us3.php.net/manual/en/function.curl-getinfo.php) as such: ``` $handle = curl_init($url); curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE); /* Get the HTML or whatever is l...
408,415
<p>I recently implemented a class like:</p> <pre><code>class TestClass : IDisposable { RegistryKey m_key; public TestClass() { m_key = Registry.CurrentUser.OpenSubKey("Software", false); } public void Dispose() { // m_key.Dispose(); IDisposable disp = m_key; dis...
[ { "answer_id": 408424, "author": "Mark A. Nicolosi", "author_id": 1103052, "author_profile": "https://Stackoverflow.com/users/1103052", "pm_score": 5, "selected": true, "text": "<p>This is called <strong>explicit interface implementation</strong>. In your example since you define the Dis...
2009/01/03
[ "https://Stackoverflow.com/questions/408415", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10558/" ]
I recently implemented a class like: ``` class TestClass : IDisposable { RegistryKey m_key; public TestClass() { m_key = Registry.CurrentUser.OpenSubKey("Software", false); } public void Dispose() { // m_key.Dispose(); IDisposable disp = m_key; disp.Dispose(); ...
This is called **explicit interface implementation**. In your example since you define the Dispose() method as "void IDisposable.Dispose()" you are explicitly implementing the IDisposable interface as well. This is normally done to avoid collisions. If Microsoft ever wanted to add another Dispose() method that did som...
408,437
<p>In our site, users can have many private files. We are thinking what could be the best distribution so as to avoid destroying the server's performance, These files are served through Apache and should be listed each time the user needs to manage them.</p> <p>Our first approach right now is:</p> <pre><code>var firs...
[ { "answer_id": 408466, "author": "Charlie Martin", "author_id": 35092, "author_profile": "https://Stackoverflow.com/users/35092", "pm_score": 0, "selected": false, "text": "<p>not quite sure what you're trying to ask. the server cert is sent to you, the client; you validate the cert by ...
2009/01/03
[ "https://Stackoverflow.com/questions/408437", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
In our site, users can have many private files. We are thinking what could be the best distribution so as to avoid destroying the server's performance, These files are served through Apache and should be listed each time the user needs to manage them. Our first approach right now is: ``` var first_level = (int) $user...
Just to make sure we have our terminology straight, an "SSL certificate" in common parlance is really composed of two components: * A public certificate * A private key The public certificate component is signed by your chosen CA (certificate authority), after which it can be freely distributed. It does not need to b...
408,444
<p>I have noticed that my geocoder is inconsistent in the code shown below because before the "getLatLng" method is called I show 10 valid locations, but after this line of code the number of points that actually show up is different each time I search (same search criteria - fyi) Between 5 and 10 at random .. very str...
[ { "answer_id": 408458, "author": "Saif Khan", "author_id": 23667, "author_profile": "https://Stackoverflow.com/users/23667", "pm_score": 1, "selected": false, "text": "<p>I've seen this in my ASP.NET app. My issue was that I was validating the addresses before displaying them and </p>\n\...
2009/01/03
[ "https://Stackoverflow.com/questions/408444", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2701/" ]
I have noticed that my geocoder is inconsistent in the code shown below because before the "getLatLng" method is called I show 10 valid locations, but after this line of code the number of points that actually show up is different each time I search (same search criteria - fyi) Between 5 and 10 at random .. very strang...
I actually found that it wasn't the "verify address" code that was causing this inconsistency, but instead - just the fact that the maps api didn't want a ton of geocoder calls so I added a simple 225ms timeout between each request and this did the trick ``` function preGeoCodeLookup(_xaddr, _xid, _xindex, _xhtml, _xs...
408,452
<p>The code below is checking performance of three different ways to do same solution.</p> <pre><code> public static void Main(string[] args) { // for loop { Stopwatch sw = Stopwatch.StartNew(); int accumulator = 0; for (int i = 1; i &lt;= 100000000; ++i) ...
[ { "answer_id": 408486, "author": "Rob Walker", "author_id": 3631, "author_profile": "https://Stackoverflow.com/users/3631", "pm_score": 2, "selected": false, "text": "<p>Assuming this is a release build running, otherwise all comparisons are off as the JIT will not be working flat out.</...
2009/01/03
[ "https://Stackoverflow.com/questions/408452", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26349/" ]
The code below is checking performance of three different ways to do same solution. ``` public static void Main(string[] args) { // for loop { Stopwatch sw = Stopwatch.StartNew(); int accumulator = 0; for (int i = 1; i <= 100000000; ++i) { ...
Why should `Enumerable.Range` be any slower than your self-made `GetIntRange`? In fact, if `Enumerable.Range` were defined as ``` public static class Enumerable { public static IEnumerable<int> Range(int start, int count) { var end = start + count; for(var current = start; current < end; ++current)...
408,456
<p>I'm using Hibernate's implementation of JPA and am seeing poor performance as multiple SQL queries are issued for each entity that is fetched. If I use a joined JPA query it generates just one SQL query but doesn't find rows will null relationship.</p> <p>Example, consider this simple schema. A person lives at an a...
[ { "answer_id": 408518, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": true, "text": "<p>My guess is that you'd need a left join, i.e.,</p>\n\n<pre><code>SELECT p FROM Person p LEFT JOIN p.address a LEFT JOIN p.em...
2009/01/03
[ "https://Stackoverflow.com/questions/408456", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24396/" ]
I'm using Hibernate's implementation of JPA and am seeing poor performance as multiple SQL queries are issued for each entity that is fetched. If I use a joined JPA query it generates just one SQL query but doesn't find rows will null relationship. Example, consider this simple schema. A person lives at an address and...
My guess is that you'd need a left join, i.e., ``` SELECT p FROM Person p LEFT JOIN p.address a LEFT JOIN p.employer e WHERE... ``` See [this blog entry for an example](http://depressedprogrammer.wordpress.com/2007/11/20/performing-a-left-outer-join-using-jpql-and-jpa/) Note that I haven't actually tried this with ...
408,467
<p>The MySQL documentation isn't very clear on this. I want to add an index to an existing table. The table is a user table with the login id and password and I want to create an index for this to optimize logging in.</p> <p>This is how I thought I would try it: </p> <pre><code>mysql&gt; ALTER TABLE `users` ADD INDEX...
[ { "answer_id": 408479, "author": "Bill Karwin", "author_id": 20860, "author_profile": "https://Stackoverflow.com/users/20860", "pm_score": 4, "selected": true, "text": "<p>Yes, this achieved creating an index. The index is named \"<code>name</code>\" (if you don't give the index a name,...
2009/01/03
[ "https://Stackoverflow.com/questions/408467", "https://Stackoverflow.com", "https://Stackoverflow.com/users/66475/" ]
The MySQL documentation isn't very clear on this. I want to add an index to an existing table. The table is a user table with the login id and password and I want to create an index for this to optimize logging in. This is how I thought I would try it: ``` mysql> ALTER TABLE `users` ADD INDEX(`name`,`password`); ``...
Yes, this achieved creating an index. The index is named "`name`" (if you don't give the index a name, it tries to use the first column you specify in the index). The index is a composite of two columns: `name` in position 1, and `password` in position 2. As for whether or not this will optimize logging it, that depen...
408,480
<p>Ever since Microsoft has introduced the application blocks, I've been bumping into people who use the <a href="http://msdn.microsoft.com/en-us/library/dd203116.aspx" rel="noreferrer">Exception Handling Application Block</a>. I've recently had a closer look myself and would summarize the basic functionality as follow...
[ { "answer_id": 408487, "author": "Mark Brittingham", "author_id": 15592, "author_profile": "https://Stackoverflow.com/users/15592", "pm_score": 1, "selected": false, "text": "<p>Quite simply: if you want different exception handling in your release code than in your debug code, then it w...
2009/01/03
[ "https://Stackoverflow.com/questions/408480", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Ever since Microsoft has introduced the application blocks, I've been bumping into people who use the [Exception Handling Application Block](http://msdn.microsoft.com/en-us/library/dd203116.aspx). I've recently had a closer look myself and would summarize the basic functionality as follows (skip the following block if ...
If you use exceptions for control flow, then you would want to stay away from policy-based exception handling. But in the case of exceptions which you want to treat as non-recoverable (a background task failed, the socket was disconnected, the file was deleted, etc.), you may want to have configurable, policy-based ex...
408,482
<p>I'm stuck on a RegEx problem that's seemingly very simple and yet I can't get it working.</p> <p>Suppose I have input like this:</p> <pre><code>Some text %interestingbit% lots of random text lots and lots more %anotherinterestingbit% Some text %interestingbit% lots of random text OPTIONAL_THING lots and lots more ...
[ { "answer_id": 408524, "author": "strager", "author_id": 39992, "author_profile": "https://Stackoverflow.com/users/39992", "pm_score": 0, "selected": false, "text": "<p>Why do you have the extra set of parentheses?</p>\n\n<p>Try this:</p>\n\n<pre><code>%interestingbit%.+?(?&lt;OptionalCa...
2009/01/03
[ "https://Stackoverflow.com/questions/408482", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20336/" ]
I'm stuck on a RegEx problem that's seemingly very simple and yet I can't get it working. Suppose I have input like this: ``` Some text %interestingbit% lots of random text lots and lots more %anotherinterestingbit% Some text %interestingbit% lots of random text OPTIONAL_THING lots and lots more %anotherinterestingbi...
My thoughts are along similar lines to Niko's idea. However, I would suggest placing the 2nd .+? inside the optional group instead of the first, as follows: ``` %interestingbit%.+?(?:(?<optionalCapture>OPTIONAL_THING).+?)?%anotherinterestingbit% ``` This avoids unnecessary backtracking. If the first .+? is inside th...
408,501
<p>I need to do this.</p> <pre><code>public class MyClass{ private static IDictionary&lt;String, Type&gt; databaseAccessClasses = new Dictionary&lt;String, Type&gt;(); private static IDictionary&lt;String, Type&gt; DatabaseAccessClasses { get { return DataAccessFacto...
[ { "answer_id": 411001, "author": "mmmmmmmm", "author_id": 44086, "author_profile": "https://Stackoverflow.com/users/44086", "pm_score": 3, "selected": false, "text": "<p>Use the following code:</p>\n\n<pre><code>CSharpCodeProvider codeProvider = new CSharpCodeProvider();\nCodeCompileUnit...
2009/01/03
[ "https://Stackoverflow.com/questions/408501", "https://Stackoverflow.com", "https://Stackoverflow.com/users/45481/" ]
I need to do this. ``` public class MyClass{ private static IDictionary<String, Type> databaseAccessClasses = new Dictionary<String, Type>(); private static IDictionary<String, Type> DatabaseAccessClasses { get { return DataAccessFactory.databaseAccessClasses; } ...
Use the following code: ``` CSharpCodeProvider codeProvider = new CSharpCodeProvider(); CodeCompileUnit compileUnit = new CodeCompileUnit(); CodeNamespace nameSpace = new CodeNamespace("xy"); compileUnit.Namespaces.Add(nameSpace); CodeTypeDeclaration myClass = new CodeTypeDeclaration("MyClass"); nameSpace.Types.Add(...
408,530
<p>I'm trying to learn some C# over the weekend and am following the 15 exercises found here: <a href="http://www.jobsnake.com/seek/articles/index.cgi?openarticle&amp;8533" rel="nofollow noreferrer">http://www.jobsnake.com/seek/articles/index.cgi?openarticle&amp;8533</a></p> <p>Yesterday I asked a similar question for...
[ { "answer_id": 408540, "author": "Charles Bretana", "author_id": 32632, "author_profile": "https://Stackoverflow.com/users/32632", "pm_score": 2, "selected": false, "text": "<p>Using the C# ternary operator, </p>\n\n<pre><code> static string Reynolds(int d, int v, int rho, int mu)\n ...
2009/01/03
[ "https://Stackoverflow.com/questions/408530", "https://Stackoverflow.com", "https://Stackoverflow.com/users/37196/" ]
I'm trying to learn some C# over the weekend and am following the 15 exercises found here: <http://www.jobsnake.com/seek/articles/index.cgi?openarticle&8533> Yesterday I asked a similar question for the Fibonacci sequence and received some great responses which introduced me to elements of C# which I'd not encountered...
I think there is an error in your code but I made an assumption. Your second "if" would never evaluate tree as number < 2000 already makes the first branch true. I would create an ENUM: ``` enum FlowType { Laminar , Transient , Turbulent }; static FlowType Reynolds(int d, int v, int rho, int mu) { in...
408,541
<p>Last couple of days we were discussing at <a href="https://stackoverflow.com/questions/401191/how-to-return-random-items-restfully">another question</a> the best to manage randomness in a RESTful way; today I went to play a little bit with some ideas in Django only to find that there is no easy standard way of retur...
[ { "answer_id": 408549, "author": "gak", "author_id": 11125, "author_profile": "https://Stackoverflow.com/users/11125", "pm_score": 6, "selected": true, "text": "<p>You could just override HttpResponse, like the other Responses do:</p>\n\n<pre><code>class HttpResponseSeeOther(HttpResponse...
2009/01/03
[ "https://Stackoverflow.com/questions/408541", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34479/" ]
Last couple of days we were discussing at [another question](https://stackoverflow.com/questions/401191/how-to-return-random-items-restfully) the best to manage randomness in a RESTful way; today I went to play a little bit with some ideas in Django only to find that there is no easy standard way of returning a 303 res...
You could just override HttpResponse, like the other Responses do: ``` class HttpResponseSeeOther(HttpResponseRedirect): status_code = 303 return HttpResponseSeeOther('/other-url/') ```
408,570
<p>I'm trying to parse an array of JSON objects into an array of strings in C#. I can extract the array from the JSON object, but I can't split the array string into an array of individual objects.</p> <p>What I have is this test string:</p> <pre><code>string json = "{items:[{id:0,name:\"Lorem Ipsum\"},{id:1,name" ...
[ { "answer_id": 408579, "author": "casperOne", "author_id": 50776, "author_profile": "https://Stackoverflow.com/users/50776", "pm_score": 3, "selected": false, "text": "<p>Are you using .NET 3.5? If so, you can use the <a href=\"http://msdn.microsoft.com/en-us/library/system.runtime.seri...
2009/01/03
[ "https://Stackoverflow.com/questions/408570", "https://Stackoverflow.com", "https://Stackoverflow.com/users/392/" ]
I'm trying to parse an array of JSON objects into an array of strings in C#. I can extract the array from the JSON object, but I can't split the array string into an array of individual objects. What I have is this test string: ``` string json = "{items:[{id:0,name:\"Lorem Ipsum\"},{id:1,name" + ":\"Lore...
Balanced parentheses are literally a textbook example of a language that cannot be processed with regular expressions. JSON is essentially balanced parentheses plus a bunch of other stuff, with the braces replaced by parens. In the [hierarchy of formal languages](http://en.wikipedia.org/wiki/Chomsky_hierarchy), JSON is...
408,582
<p>I have to call domain A.com (which sets the cookies with http) from domain B.com. All I do on domain B.com is (javascript): </p> <pre><code>var head = document.getElementsByTagName("head")[0]; var script = document.createElement("script"); script.src = "A.com/setCookie?cache=1231213123"; head.appendChild(script); <...
[ { "answer_id": 408942, "author": "roenving", "author_id": 23142, "author_profile": "https://Stackoverflow.com/users/23142", "pm_score": -1, "selected": false, "text": "<p>It isn't the missing type-attribute thats annoying you ?-)</p>\n\n<pre><code>&lt;script type=\"text/javascript\"&gt;\...
2009/01/03
[ "https://Stackoverflow.com/questions/408582", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50394/" ]
I have to call domain A.com (which sets the cookies with http) from domain B.com. All I do on domain B.com is (javascript): ``` var head = document.getElementsByTagName("head")[0]; var script = document.createElement("script"); script.src = "A.com/setCookie?cache=1231213123"; head.appendChild(script); ``` This sets...
From the [`Safari Developer FAQ`](http://developer.apple.com/internet/safari/faq.html#anchor6): > > Safari ships with a conservative cookie policy which limits cookie writes to only the pages chosen ("navigated to") by the user. This default conservative policy may confuse frame based sites that attempt to write cook...
408,592
<p>Is it possible to write a C function that does the following?</p> <ol> <li>Allocate a bunch of memory in the heap</li> <li>Writes machine code in it</li> <li>Executes those machines instructions</li> </ol> <p>Of course, I would have to restore the state of the stack to what it was prior to the execution of those m...
[ { "answer_id": 408597, "author": "Foredecker", "author_id": 18256, "author_profile": "https://Stackoverflow.com/users/18256", "pm_score": 2, "selected": false, "text": "<p>This is very similar to <a href=\"https://stackoverflow.com/questions/397064/calling-code-stored-in-the-heap-from-vc...
2009/01/03
[ "https://Stackoverflow.com/questions/408592", "https://Stackoverflow.com", "https://Stackoverflow.com/users/46571/" ]
Is it possible to write a C function that does the following? 1. Allocate a bunch of memory in the heap 2. Writes machine code in it 3. Executes those machines instructions Of course, I would have to restore the state of the stack to what it was prior to the execution of those machine instructions manually, but I wan...
It's certainly *possible*. For various reasons, we've spent a lot of effort of the last 30-40 years trying to make it as difficult as possible, but it is possible. In most systems now, there are hardware and software mechanisms that attempt to protect data space from being executed. The basics, though, are fairly stra...
408,618
<p>I would like to know that i have an excel file with 18 sheets and it should be opend with any other versions.</p> <p>for example if i right click on the file and select open with open office the same is being opened. i would like to lock this.</p>
[ { "answer_id": 408597, "author": "Foredecker", "author_id": 18256, "author_profile": "https://Stackoverflow.com/users/18256", "pm_score": 2, "selected": false, "text": "<p>This is very similar to <a href=\"https://stackoverflow.com/questions/397064/calling-code-stored-in-the-heap-from-vc...
2009/01/03
[ "https://Stackoverflow.com/questions/408618", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I would like to know that i have an excel file with 18 sheets and it should be opend with any other versions. for example if i right click on the file and select open with open office the same is being opened. i would like to lock this.
It's certainly *possible*. For various reasons, we've spent a lot of effort of the last 30-40 years trying to make it as difficult as possible, but it is possible. In most systems now, there are hardware and software mechanisms that attempt to protect data space from being executed. The basics, though, are fairly stra...
408,627
<p>I didn't give a lot of info in my last question.</p> <p>I've built llv8call from <a href="http://code.google.com/p/llv8call/" rel="nofollow noreferrer">http://code.google.com/p/llv8call/</a>, v0.4. I've gotten the known dependencies installed, being libxml-2.0 and libreadline. My dev system is Mac OS X 10.5. llv8ca...
[ { "answer_id": 408649, "author": "Paul", "author_id": 51102, "author_profile": "https://Stackoverflow.com/users/51102", "pm_score": 2, "selected": true, "text": "<p>Your intuition seems right. Doing a grep:</p>\n\n<pre><code>grep -r \"org.coderepos\" *|less\n</code></pre>\n\n<p>I see it ...
2009/01/03
[ "https://Stackoverflow.com/questions/408627", "https://Stackoverflow.com", "https://Stackoverflow.com/users/68788/" ]
I didn't give a lot of info in my last question. I've built llv8call from <http://code.google.com/p/llv8call/>, v0.4. I've gotten the known dependencies installed, being libxml-2.0 and libreadline. My dev system is Mac OS X 10.5. llv8call is built with Scons. When I attempt to run llv8call via ./llv8call, I get this ...
Your intuition seems right. Doing a grep: ``` grep -r "org.coderepos" *|less ``` I see it checks for many "libraries" under org.coderepos. Furthermore, in src/main.cc in the preload\_builtin\_classes function, we see: ``` Handle<Value> args[1]; args[0] = String::New("org.coderepos.fs"); loadBinary->Call(v8ext, 1, a...
408,646
<p>I have the following XAML code, which displays a <em>picture</em> (image inside borders) and a logo. Right now, the logo appears below the picture. This is expected, however <strong>my goal is to have the logo on top of the picture</strong> (precisely at the bottom-right corner). <strong>Does someone has an idea how...
[ { "answer_id": 408650, "author": "David Brown", "author_id": 31516, "author_profile": "https://Stackoverflow.com/users/31516", "pm_score": 1, "selected": false, "text": "<p>Put your picture and logo in a Canvas element and position them (Canvas.Top, Canvas.Left, etc) as needed.</p>\n" ...
2009/01/03
[ "https://Stackoverflow.com/questions/408646", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42024/" ]
I have the following XAML code, which displays a *picture* (image inside borders) and a logo. Right now, the logo appears below the picture. This is expected, however **my goal is to have the logo on top of the picture** (precisely at the bottom-right corner). **Does someone has an idea how to do that?** Do we have lay...
You should be able to do something along the lines of: ``` <WrapPanel> <Grid> <Border BorderBrush="Gray" BorderThickness="1" Margin="3"> <Border BorderBrush="White" BorderThickness="3"> <Border BorderBrush="LightGray" BorderThickness="0.5"> <Image Source="htt...
408,652
<p>In eclipse, when I want to document a function (in java or javascript source) I can just type /**, then hit enter, and I get a comment like this</p> <pre><code> /** * * Fluctuates all variables to more compatibly foo all the bars * * @PARAM {int} foo */ function flucvar (foo) { } </code></pre> <p>When hi...
[ { "answer_id": 408714, "author": "mipadi", "author_id": 28804, "author_profile": "https://Stackoverflow.com/users/28804", "pm_score": 1, "selected": false, "text": "<p>I took a look at TextMate's Java bundle, and I didn't see anything about inserting JavaDoc comments. However, it shouldn...
2009/01/03
[ "https://Stackoverflow.com/questions/408652", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51101/" ]
In eclipse, when I want to document a function (in java or javascript source) I can just type /\*\*, then hit enter, and I get a comment like this ``` /** * * Fluctuates all variables to more compatibly foo all the bars * * @PARAM {int} foo */ function flucvar (foo) { } ``` When hitting enter inside the c...
You need to create two snippets (I have them in the Source bundle). First create a snippet for inserting JavaDoc comments. The snippet contains the following: ``` /** * $0 */ ``` I have the snippet Activation set to *Tab Trigger*, using `/**` as the activation string. Every time I write `/**` and press Tab, I get a...
408,659
<pre><code>typeof(int).Name </code></pre> <p>Will return System.Int32 does anyone know of a way to return "int"</p>
[ { "answer_id": 408667, "author": "ChrisW", "author_id": 49942, "author_profile": "https://Stackoverflow.com/users/49942", "pm_score": 4, "selected": true, "text": "<p>There aren't many types that are C# keywords (int, double, string) ... so perhaps you can write your own mapping function...
2009/01/03
[ "https://Stackoverflow.com/questions/408659", "https://Stackoverflow.com", "https://Stackoverflow.com/users/45909/" ]
``` typeof(int).Name ``` Will return System.Int32 does anyone know of a way to return "int"
There aren't many types that are C# keywords (int, double, string) ... so perhaps you can write your own mapping function, from the System type name to the corresonding C# keyword.
408,661
<p>When the Java compiler autoboxes a primitive to the wrapper class, what code does it generate behind the scenes? I imagine it calls:</p> <ul> <li>The valueOf() method on the wrapper</li> <li>The wrapper's constructor</li> <li>Some other magic?</li> </ul>
[ { "answer_id": 408668, "author": "Adam Rosenfield", "author_id": 9530, "author_profile": "https://Stackoverflow.com/users/9530", "pm_score": 7, "selected": true, "text": "<p>You can use the <code>javap</code> tool to see for yourself. Compile the following code:</p>\n\n<pre><code>public...
2009/01/03
[ "https://Stackoverflow.com/questions/408661", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23572/" ]
When the Java compiler autoboxes a primitive to the wrapper class, what code does it generate behind the scenes? I imagine it calls: * The valueOf() method on the wrapper * The wrapper's constructor * Some other magic?
You can use the `javap` tool to see for yourself. Compile the following code: ``` public class AutoboxingTest { public static void main(String []args) { Integer a = 3; int b = a; } } ``` To compile and disassemble: ``` javac AutoboxingTest.java javap -c AutoboxingTest ``` The output is...
408,670
<p>I've searched, but I've not understood very well these three concepts. When do I have to use dynamic allocation (in the heap) and what's its real advantage? What are the problems of static and stack? Could I write an entire application without allocating variables in the heap? </p> <p>I heard that others language...
[ { "answer_id": 408688, "author": "Chris Smith", "author_id": 322, "author_profile": "https://Stackoverflow.com/users/322", "pm_score": 3, "selected": false, "text": "<p>The main difference is speed and size.</p>\n<h3>Stack</h3>\n<p>Dramatically faster to allocate. It is done in O(1), sin...
2009/01/03
[ "https://Stackoverflow.com/questions/408670", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50754/" ]
I've searched, but I've not understood very well these three concepts. When do I have to use dynamic allocation (in the heap) and what's its real advantage? What are the problems of static and stack? Could I write an entire application without allocating variables in the heap? I heard that others languages incorporat...
[A similar question](https://stackoverflow.com/questions/79923/what-and-where-are-the-stack-and-heap) was asked, but it didn't ask about statics. Summary of what static, heap, and stack memory are: --------------------------------------------------- * A static variable is basically a global variable, even if you cann...
408,713
<p>I have Used in cocos2d game engine. this is my code:</p> <pre><code>-(void)timed1: (id)sender { UIAlertView *dialog = [[[UIAlertView alloc] init] retain]; [dialog setDelegate:self]; [dialog setTitle:@"Enter Time:"]; [dialog setMessage:@" "]; UITextField *nameField = [[UITextField alloc] initWith...
[ { "answer_id": 408723, "author": "Sophie Alpert", "author_id": 49485, "author_profile": "https://Stackoverflow.com/users/49485", "pm_score": 0, "selected": false, "text": "<p>Release nameField later, and get the text property from there.</p>\n" }, { "answer_id": 408783, "auth...
2009/01/03
[ "https://Stackoverflow.com/questions/408713", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51108/" ]
I have Used in cocos2d game engine. this is my code: ``` -(void)timed1: (id)sender { UIAlertView *dialog = [[[UIAlertView alloc] init] retain]; [dialog setDelegate:self]; [dialog setTitle:@"Enter Time:"]; [dialog setMessage:@" "]; UITextField *nameField = [[UITextField alloc] initWithFrame:CGRectMa...
The reason you cannot get a value is that the function will exit BEFORE the user types anything! When you call [dialog show] the dialog is displayed to the user where they may then enter text. You should wait until the user selects a button, which will trigger your delegate function, and THEN access the text field pr...
408,734
<p>I need a very quick fix in a mod_rewrite expression for drupal we have</p> <pre><code> RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !=/favicon.ico RewriteRule ^(.*)$ index.php?...
[ { "answer_id": 408737, "author": "gnud", "author_id": 27204, "author_profile": "https://Stackoverflow.com/users/27204", "pm_score": 0, "selected": false, "text": "<p>You don't really need the subdomain in the query string.</p>\n\n<p>The subdomain can be found in PHP in $_SERVER['SERVER_N...
2009/01/03
[ "https://Stackoverflow.com/questions/408734", "https://Stackoverflow.com", "https://Stackoverflow.com/users/47846/" ]
I need a very quick fix in a mod\_rewrite expression for drupal we have ``` RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !=/favicon.ico RewriteRule ^(.*)$ index.php?q=$1 [L,QSA] ...
Trying this again, for some reason my code isn't rendering properly. ``` RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !=/favicon.ico RewriteCond %{HTTP_HOST} ^(.*)\.mydomain\.com$ RewriteRu...
408,744
<p>F12 is a wonder for tracking down UI blocking operations, but I can't figure out how to make it work with VS 2008 and managed code.</p> <p>Help! Or not...</p> <p>Edit: turns out it doesn't work in VS 2005 either on Vista x64, so I guess that either widens or narrows it down, depending on your perspective :(</p> <...
[ { "answer_id": 443763, "author": "Milan Gardian", "author_id": 23843, "author_profile": "https://Stackoverflow.com/users/23843", "pm_score": 0, "selected": false, "text": "<p>While I did not know about the F12 functionality in x86 Windows XP, the following instructions describe how I'm b...
2009/01/03
[ "https://Stackoverflow.com/questions/408744", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6210/" ]
F12 is a wonder for tracking down UI blocking operations, but I can't figure out how to make it work with VS 2008 and managed code. Help! Or not... Edit: turns out it doesn't work in VS 2005 either on Vista x64, so I guess that either widens or narrows it down, depending on your perspective :( MSN
This is an alternative solution that preserves the convenience of hitting F12 at any time, even if the application "bites", without having to switch to Visual Studio and invoke "Break all" command as per my first answer. Unfortunately, this solution requires one to add some extra code to the application we want to bre...
408,749
<p>Is it possible to enforce uniqueness across two tables in MySQL?</p> <p>I have two tables, both describing users. The users in these tables were for two different systems previously, however now we're merging our authentication systems and I need to make sure that there are unique usernames across these two tables....
[ { "answer_id": 408755, "author": "cliff.meyers", "author_id": 41754, "author_profile": "https://Stackoverflow.com/users/41754", "pm_score": 0, "selected": false, "text": "<p>Obviously if there are already duplicates in the two tables you will have to solve that problem by hand. Moving f...
2009/01/03
[ "https://Stackoverflow.com/questions/408749", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9021/" ]
Is it possible to enforce uniqueness across two tables in MySQL? I have two tables, both describing users. The users in these tables were for two different systems previously, however now we're merging our authentication systems and I need to make sure that there are unique usernames across these two tables. (it's too...
You can't declare a UNIQUE constraint across multiple tables. MySQL 8.0 supports CHECK constraints, but those constraints cannot reference other tables. But you can design a trigger to search for the matching value in the other table. Here's a test SQL script: ``` DROP TABLE IF EXISTS foo; CREATE TABLE FOO (username V...
408,779
<p>I have 2 tables which in simplified form look like this:</p> <pre><code>Products( id: int, name: varchar ); ProductSpecs( product_id: int, spec_name: varchar, spec_value: int ); </code></pre> <p>Now I need to sort products (in linq to sql) by value of some specification item (eg. "price"). So I do ...
[ { "answer_id": 408806, "author": "Jonathan Leffler", "author_id": 15168, "author_profile": "https://Stackoverflow.com/users/15168", "pm_score": 0, "selected": false, "text": "<p>In ordinary SQL, you'd use an LEFT OUTER JOIN. This preserves rows that appear in the left-hand table (the on...
2009/01/03
[ "https://Stackoverflow.com/questions/408779", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19546/" ]
I have 2 tables which in simplified form look like this: ``` Products( id: int, name: varchar ); ProductSpecs( product_id: int, spec_name: varchar, spec_value: int ); ``` Now I need to sort products (in linq to sql) by value of some specification item (eg. "price"). So I do something like this ``` v...
First, I would recommend that you either do this in pure SQL as a function or Stored Procedure and then access this through linq, or add a price column to your product table. It seems like price would be a normal attribute to add to all of your products even if that price is NULL. SQL: ``` select p.* from products p ...
408,810
<p>I have a wxPython application that relies on an external config file. I want provide friendly message dialogs that show up if there are any config errors. I've tried to make this work by wrapping my app.MainLoop() call in a try/except statement.</p> <p>The code below works for the init code in my MainWindow frame...
[ { "answer_id": 409266, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "<p>Don't know if this will work for a wxPython application, but in the sys module you can overwrite the excepthook attribute, ...
2009/01/03
[ "https://Stackoverflow.com/questions/408810", "https://Stackoverflow.com", "https://Stackoverflow.com/users/46914/" ]
I have a wxPython application that relies on an external config file. I want provide friendly message dialogs that show up if there are any config errors. I've tried to make this work by wrapping my app.MainLoop() call in a try/except statement. The code below works for the init code in my MainWindow frame class, but ...
I coded something like this for [Chandler](http://chandlerproject.org/), where any unhandled exceptions pop up a window with the stack and other info, and users can put in additional comments (what did they do when it happened etc.) and submit it for Chandler developers. A bit like the [Mozilla Talkback](https://wiki.m...
408,815
<p>I have an <code>ItemsControl</code> whose <code>ItemsSource</code> gets bound to an <code>ObservableCollection&lt;Component&gt;</code> at run time. I have defined a data template for type <code>Component</code> which works fine.</p> <p>Now <code>Component</code> has a <code>ObservableCollection&lt;Control&gt;</code>...
[ { "answer_id": 408857, "author": "Ray Booysen", "author_id": 42124, "author_profile": "https://Stackoverflow.com/users/42124", "pm_score": 0, "selected": false, "text": "<p>In the line where you bind the nested ItemsControl, is the Path correct? It is currently \"Contrls\", should it be...
2009/01/03
[ "https://Stackoverflow.com/questions/408815", "https://Stackoverflow.com", "https://Stackoverflow.com/users/47660/" ]
I have an `ItemsControl` whose `ItemsSource` gets bound to an `ObservableCollection<Component>` at run time. I have defined a data template for type `Component` which works fine. Now `Component` has a `ObservableCollection<Control>` and I want to add another `ItemsControl` inside my `Component` `Datatemplate` to rende...
I'm guessing this doesn't work with a StaticResource as the Resource is inside the ItemsControl which probably has not been created at load time when StaticResources are evaluated. DynamicResources at load time are evaluated to an expression at load time and then evaluated to the correct value when requested. Try mov...
408,821
<p>I've seen this questions <a href="https://stackoverflow.com/questions/159366/is-there-a-best-coding-style-for-identations-same-line-next-line">here</a>. I'm wondering if there exists an official name for the following indent style:</p> <pre><code>void fooBar(String s) { while (true) { // ... do some...
[ { "answer_id": 408826, "author": "Jesse Pepper", "author_id": 43058, "author_profile": "https://Stackoverflow.com/users/43058", "pm_score": 5, "selected": true, "text": "<p>Allman style (bsd in Emacs) see wikipedia article <a href=\"http://en.wikipedia.org/wiki/Indent_style\" rel=\"noref...
2009/01/03
[ "https://Stackoverflow.com/questions/408821", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49786/" ]
I've seen this questions [here](https://stackoverflow.com/questions/159366/is-there-a-best-coding-style-for-identations-same-line-next-line). I'm wondering if there exists an official name for the following indent style: ``` void fooBar(String s) { while (true) { // ... do something } } ``` When ...
Allman style (bsd in Emacs) see wikipedia article <http://en.wikipedia.org/wiki/Indent_style>
408,834
<p>I have a form with checkboxes, each one has a value. When the registered user select any checkbox the value is incremented (the summation) and then then registred user save his</p> <p>selection of checkbox if he satisfied with the result of summation into database all this work fine ...i want to enable the regis...
[ { "answer_id": 408837, "author": "kmkaplan", "author_id": 50902, "author_profile": "https://Stackoverflow.com/users/50902", "pm_score": 1, "selected": false, "text": "<p>To save the settings into the database you have to use <code>UPDATE</code>, not <code>INSERT</code>. First you must k...
2009/01/03
[ "https://Stackoverflow.com/questions/408834", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have a form with checkboxes, each one has a value. When the registered user select any checkbox the value is incremented (the summation) and then then registred user save his selection of checkbox if he satisfied with the result of summation into database all this work fine ...i want to enable the registred user to...
In the html form, instead of having ``` <input type="checkbox" name="choice" value="123"> ``` Do: ``` <input type="checkbox" name="choice[]" value="123"> ``` This will make the choices available as an array to you. Then change your php code for inserting the choices into the databse to this: ``` <?php $str='';...
408,855
<p>I have a database populated with 1 million objects. Each object has a 'tags' field - set of integers.</p> <p>For example:</p> <pre><code>object1: tags(1,3,4) object2: tags(2) object3: tags(3,4) object4: tags(5) </code></pre> <p>and so on.</p> <p>Query parameter is a set on integers, lets try q(3,4,5)</p> <pre><...
[ { "answer_id": 408864, "author": "Razor", "author_id": 17211, "author_profile": "https://Stackoverflow.com/users/17211", "pm_score": 0, "selected": false, "text": "<p>You haven't stated weather you'd like to use SQL or if your reading the data into an application before doing so. From so...
2009/01/03
[ "https://Stackoverflow.com/questions/408855", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21152/" ]
I have a database populated with 1 million objects. Each object has a 'tags' field - set of integers. For example: ``` object1: tags(1,3,4) object2: tags(2) object3: tags(3,4) object4: tags(5) ``` and so on. Query parameter is a set on integers, lets try q(3,4,5) ``` object1 does not match ('1' not in '3,4,5') ob...
You're making a common mistake in database design, by storing a comma-separated list of tag id's. It's not a surprise that performing efficient queries against this is a blocker for you. What you need is to model the mapping between objects and tags in a separate table. ``` CREATE TABLE Tagged ( object_id INT NOT ...
408,866
<p>I need to store Python structures made of lists / dictionaries, tuples into a human-readable format. The idea is like using something similar to <a href="http://docs.python.org/library/pickle.html" rel="nofollow noreferrer">pickle</a>, but pickle is not human-friendly. Other options that come to my mind are <a href=...
[ { "answer_id": 408889, "author": "PEZ", "author_id": 44639, "author_profile": "https://Stackoverflow.com/users/44639", "pm_score": 5, "selected": true, "text": "<p>For simple cases pprint() and eval() come to mind.</p>\n\n<p>Using your example:</p>\n\n<pre><code>&gt;&gt;&gt; d = {'age': ...
2009/01/03
[ "https://Stackoverflow.com/questions/408866", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42636/" ]
I need to store Python structures made of lists / dictionaries, tuples into a human-readable format. The idea is like using something similar to [pickle](http://docs.python.org/library/pickle.html), but pickle is not human-friendly. Other options that come to my mind are [YAML](http://en.wikipedia.org/wiki/Yaml) (throu...
For simple cases pprint() and eval() come to mind. Using your example: ``` >>> d = {'age': 27, ... 'name': 'Joe', ... 'numbers': [1, ... 2, ... 3, ... 4, ... 5], ... 'subdict': { ... 'first': 1, ... 'second': 2, ... 'thi...
408,872
<p>New to both Ruby and Rails but I'm book educated by now (which apparently means nothing, haha).</p> <p>I've got two models, Event and User joined through a table EventUser</p> <pre><code>class User &lt; ActiveRecord::Base has_many :event_users has_many :events, :through =&gt; :event_users end class EventUser ...
[ { "answer_id": 408913, "author": "Milan Novota", "author_id": 26123, "author_profile": "https://Stackoverflow.com/users/26123", "pm_score": 8, "selected": true, "text": "<p>How about adding something like this into your User model?</p>\n\n<pre><code>has_many :active_events, :through =&g...
2009/01/03
[ "https://Stackoverflow.com/questions/408872", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13257/" ]
New to both Ruby and Rails but I'm book educated by now (which apparently means nothing, haha). I've got two models, Event and User joined through a table EventUser ``` class User < ActiveRecord::Base has_many :event_users has_many :events, :through => :event_users end class EventUser < ActiveRecord::Base belo...
How about adding something like this into your User model? ``` has_many :active_events, :through => :event_users, :class_name => "Event", :source => :event, :conditions => ['event_users.active = ?',true] ``` After that you should be able to get active events for a user just by calli...
408,898
<p>intro: I am pretty sure this is my fault. But I just don't see it and before tearing my hair out, I thought I should ask here ;)</p> <p>I have a button which looks like this in my ASPX:</p> <pre><code>&lt;input onClick="ELB_ClearSelection('DropDownList___00178');" type="Button" value="Clear" /&gt; </code></pre> <...
[ { "answer_id": 408921, "author": "OJ.", "author_id": 611, "author_profile": "https://Stackoverflow.com/users/611", "pm_score": 2, "selected": true, "text": "<p>Change this:</p>\n\n<pre><code>onClick='ELB_ClearSelection(\"DropDownList___00178\")'\n</code></pre>\n\n<p>To this:</p>\n\n<pre>...
2009/01/03
[ "https://Stackoverflow.com/questions/408898", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51127/" ]
intro: I am pretty sure this is my fault. But I just don't see it and before tearing my hair out, I thought I should ask here ;) I have a button which looks like this in my ASPX: ``` <input onClick="ELB_ClearSelection('DropDownList___00178');" type="Button" value="Clear" /> ``` The HTML that is generated says: ```...
Change this: ``` onClick='ELB_ClearSelection("DropDownList___00178")' ``` To this: ``` onClick="ELB_ClearSelection('DropDownList___00178')" ``` In your ASPX. I'll avoid commenting on having select queries and login information for your DB in your markup!
408,908
<p>Are there any preprocessor symbols which allow something like</p> <pre><code>#if CLR_AT_LEAST_3.5 // use ReaderWriterLockSlim #else // use ReaderWriterLock #endif </code></pre> <p>or some other way to do this?</p>
[ { "answer_id": 408918, "author": "Frederick The Fool", "author_id": 32688, "author_profile": "https://Stackoverflow.com/users/32688", "pm_score": 5, "selected": true, "text": "<p>I don't think there are any predefined 'preprocessor' symbols. However you can achieve what you want like thi...
2009/01/03
[ "https://Stackoverflow.com/questions/408908", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9204/" ]
Are there any preprocessor symbols which allow something like ``` #if CLR_AT_LEAST_3.5 // use ReaderWriterLockSlim #else // use ReaderWriterLock #endif ``` or some other way to do this?
I don't think there are any predefined 'preprocessor' symbols. However you can achieve what you want like this: 1. Create different configurations of your project, one for every version of CLR you want to support. 2. Choose a symbol like `VERSION2`, `VERSION3` etc. per CLR version. 3. In every configuration, define th...
408,917
<p>I am creating an application in iPhone and I have several UIViews and layers in it. I am doing some animations using CAKeyframeAnimation class and since the animations have to be chained, I have overridden the animationDidStop method in UIView.</p> <p>I am getting the callbacks properly, however I just couldn't fig...
[ { "answer_id": 409734, "author": "Brad Larson", "author_id": 19679, "author_profile": "https://Stackoverflow.com/users/19679", "pm_score": 4, "selected": false, "text": "<p>I know that you said that you're using CAKeyframeAnimations, but if you want simple animation of UIView properties ...
2009/01/03
[ "https://Stackoverflow.com/questions/408917", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51130/" ]
I am creating an application in iPhone and I have several UIViews and layers in it. I am doing some animations using CAKeyframeAnimation class and since the animations have to be chained, I have overridden the animationDidStop method in UIView. I am getting the callbacks properly, however I just couldn't figure out ho...
I know that you said that you're using CAKeyframeAnimations, but if you want simple animation of UIView properties (origin, bounds, alpha, etc.), you can wrap the change of the property or properties in a begin / commit block and specify a delegate method that is called upon completion of the animation. As long as the ...
408,975
<p>The following code gives </p> <blockquote> <p>[: -ge: unary operator expected</p> </blockquote> <p>when </p> <pre><code>i=0 if [ $i -ge 2 ] then #some code fi </code></pre> <p>why?</p>
[ { "answer_id": 408979, "author": "Fernando Miguélez", "author_id": 34880, "author_profile": "https://Stackoverflow.com/users/34880", "pm_score": 2, "selected": false, "text": "<p>Your piece of script works just great. Are you sure you are not assigning anything else before the if to \"i\...
2009/01/03
[ "https://Stackoverflow.com/questions/408975", "https://Stackoverflow.com", "https://Stackoverflow.com/users/39106/" ]
The following code gives > > [: -ge: unary operator expected > > > when ``` i=0 if [ $i -ge 2 ] then #some code fi ``` why?
Your problem arises from the fact that `$i` has a blank value when your statement fails. **Always quote** your variables when performing comparisons if there is the slightest chance that one of them may be empty, e.g.: ``` if [ "$i" -ge 2 ] ; then ... fi ``` This is because of how the shell treats variables. Assum...
408,985
<p>when i run this code :</p> <pre><code>CONADefinitions.CONAPI_FOLDER_INFO2 FolderInfo; int iResult = 0; IntPtr Buffer = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(CONADefinitions.CONAPI_FOLDER_INFO2))); iResult = CONAFileSystem.CONAFindNextFolder(hFindHandle, Buffer); while (iResult == PCCSErrors.CO...
[ { "answer_id": 409040, "author": "Leon Tayson", "author_id": 18413, "author_profile": "https://Stackoverflow.com/users/18413", "pm_score": 3, "selected": true, "text": "<p>I'm not sure what that error means but if you want to get the drive's size, you can use</p>\n\n<pre><code> Dr...
2009/01/03
[ "https://Stackoverflow.com/questions/408985", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42782/" ]
when i run this code : ``` CONADefinitions.CONAPI_FOLDER_INFO2 FolderInfo; int iResult = 0; IntPtr Buffer = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(CONADefinitions.CONAPI_FOLDER_INFO2))); iResult = CONAFileSystem.CONAFindNextFolder(hFindHandle, Buffer); while (iResult == PCCSErrors.CONA_OK ) { Fol...
I'm not sure what that error means but if you want to get the drive's size, you can use ``` DriveInfo di = new DriveInfo("f"); //Put your mobile drive name long totalBytes = di.TotalSize; long freeBytes = di.TotalFreeSpace; ```
408,989
<p>I want to build a dialog in Java with a List and a couple of buttons underneath it. The list ends up with the same height as the buttons (about one line) and the whole dialog is about two lines of height.</p> <p>However, I'd like the dialog to be taller (maybe 10 lines) and the JList to take up most of the space .....
[ { "answer_id": 409063, "author": "Thorsten", "author_id": 25320, "author_profile": "https://Stackoverflow.com/users/25320", "pm_score": 0, "selected": false, "text": "<p>I've done some more poling around, and apparently the behaviour is caused by the number of items in the ListModel of _...
2009/01/03
[ "https://Stackoverflow.com/questions/408989", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25320/" ]
I want to build a dialog in Java with a List and a couple of buttons underneath it. The list ends up with the same height as the buttons (about one line) and the whole dialog is about two lines of height. However, I'd like the dialog to be taller (maybe 10 lines) and the JList to take up most of the space .. I've play...
Found the problem .. and it has nothing to do with the layout code. I was adding a null to ListModel, and that seemed to confuse the LayoutManager. Would close the question, but not yet enough mojo ...
408,998
<p>I'm playing around with MCE, I was wondering if there was the possibility of letting the user enter source code into a post, much like the 101010 button in this form.</p>
[ { "answer_id": 409136, "author": "Eran Galperin", "author_id": 10585, "author_profile": "https://Stackoverflow.com/users/10585", "pm_score": 2, "selected": false, "text": "<p>The option exists. One of the optional buttons has 'html' written on it and can be used to go into HTML editing m...
2009/01/03
[ "https://Stackoverflow.com/questions/408998", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I'm playing around with MCE, I was wondering if there was the possibility of letting the user enter source code into a post, much like the 101010 button in this form.
You'll need to add plugins: "code" to the initialization code as follows: ``` tinymce.init({ plugins: "code" }); ``` <https://www.tinymce.com/docs/plugins/code/>
409,012
<p>i want to add tracking to my website. I saw google analytics which seems to track what i need. </p> <p>So do i stick the google analytics snippet in each page, in a master page, just in my default page? what is the best practice here to get the best metrics.</p>
[ { "answer_id": 409015, "author": "M4N", "author_id": 19635, "author_profile": "https://Stackoverflow.com/users/19635", "pm_score": 4, "selected": true, "text": "<p>The google analytics code snippet has to be on every page you want to track.</p>\n\n<p>Easiest is to put the code into the m...
2009/01/03
[ "https://Stackoverflow.com/questions/409012", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4653/" ]
i want to add tracking to my website. I saw google analytics which seems to track what i need. So do i stick the google analytics snippet in each page, in a master page, just in my default page? what is the best practice here to get the best metrics.
The google analytics code snippet has to be on every page you want to track. Easiest is to put the code into the master page(s) if you use them. Otherwise put it on every page, or put it into a user control which you can include on the relevant pages or include it using a server-side include, e.g: ``` <!-- #include ...
409,060
<p>(<em>Almost exact duplicate of <a href="https://stackoverflow.com/questions/408469/keeping-original-format-post-passing-through-awk">Keeping original format POST passing through AWK</a> submitted by same person.</em>)</p> <p>I have a simple question pertaining to <b>g</b>awk, illustrated below:</p> <pre><code> 1 ...
[ { "answer_id": 409090, "author": "Zsolt Botykai", "author_id": 11621, "author_profile": "https://Stackoverflow.com/users/11621", "pm_score": 2, "selected": false, "text": "<pre><code>awk '{sub(/^[ \\t]+/, \"\"); print}'\n</code></pre>\n\n<p>This is from the famous awk 1 liners list, can ...
2009/01/03
[ "https://Stackoverflow.com/questions/409060", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51078/" ]
(*Almost exact duplicate of [Keeping original format POST passing through AWK](https://stackoverflow.com/questions/408469/keeping-original-format-post-passing-through-awk) submitted by same person.*) I have a simple question pertaining to **g**awk, illustrated below: ``` 1 int blah (void) 2 { 3 if (foo)...
This works, but in the knowledge that you'll always want to strip 3 spaces. ``` vinko@parrot:~$ cat foo.c 1 int blah (void) 2 { 3 if (foo) { 4 printf ("blah\n"); 5 } 6 return 0; 7 } vinko@parrot:~$ gawk '{ print gensub(/^ /,"",1,gensub($1, "", 1)) }' foo.c ...
409,069
<p>How do I get the size (free, total) of any drive on a Windows Mobile phone using C#?</p> <p>I need to do this with code running on the device (not on a connected PC).</p>
[ { "answer_id": 409107, "author": "mdb", "author_id": 8562, "author_profile": "https://Stackoverflow.com/users/8562", "pm_score": 1, "selected": false, "text": "<p>Assuming the phone's drive is mounted as a regular volume in Windows (i.e., it has a drive letter in Windows Explorer), you c...
2009/01/03
[ "https://Stackoverflow.com/questions/409069", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42782/" ]
How do I get the size (free, total) of any drive on a Windows Mobile phone using C#? I need to do this with code running on the device (not on a connected PC).
I've rewritten the answer based on a better understanding of the question, but without losing any of my original answer for those who find this question. **Getting the size from code running on the device** The answer is simple: P/Invoke [GetDiskFreeSpaceEx](http://msdn.microsoft.com/en-us/library/aa912270.aspx) dire...
409,076
<p>I'm trying to create nested Organizational Units in Active Directory and I'm close to having this working. I have a problem line below that I need help with. I'm checking if an OU exists and if not I need to create it, strOUArray contains OU=Test OU=Test2 and OU=Test3. I need the code to create OU=Test first and the...
[ { "answer_id": 409278, "author": "ecoffey", "author_id": 37838, "author_profile": "https://Stackoverflow.com/users/37838", "pm_score": 1, "selected": false, "text": "<p>Seems like your <code>//PROBLEM LINE</code> is leaving <code>strOUArray[x]</code> out of the string concatenation. Was...
2009/01/03
[ "https://Stackoverflow.com/questions/409076", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I'm trying to create nested Organizational Units in Active Directory and I'm close to having this working. I have a problem line below that I need help with. I'm checking if an OU exists and if not I need to create it, strOUArray contains OU=Test OU=Test2 and OU=Test3. I need the code to create OU=Test first and then u...
Seems like your `//PROBLEM LINE` is leaving `strOUArray[x]` out of the string concatenation. Was that a typo when posting? Also this snippet: ``` DirectoryEntry parent = new DirectoryEntry(); parent = new DirectoryEntry("..."); ``` You're creating a `DirectoryEntry` and then immediately throwing away the reference ...
409,151
<p>I have a page where when some operation goes wrong i want to start the timer, wait 30 second, stop the timer and retry the operation. Every time the timer starts I need to inform the user about it by changing some label's text. </p> <p>How can I do it?</p>
[ { "answer_id": 409167, "author": "keithwarren7", "author_id": 40714, "author_profile": "https://Stackoverflow.com/users/40714", "pm_score": 1, "selected": false, "text": "<p>from the client side to force a postback you can directly call the __doPostBack method</p>\n\n<p>It takes two argu...
2009/01/03
[ "https://Stackoverflow.com/questions/409151", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40872/" ]
I have a page where when some operation goes wrong i want to start the timer, wait 30 second, stop the timer and retry the operation. Every time the timer starts I need to inform the user about it by changing some label's text. How can I do it?
If I understand correctly, the I think you should use a client-side (javascript) timer instead. You can not use a server-side timer for this. When you detect the error-condition, you update the label accordingly and display it to the user. At the same time you invoke a client-side timer which will postback after 30 se...
409,162
<p>When doing a simple performance measurement, I was astonished to see that calling <code>String.IndexOf(char)</code> was actually slower than doing it manually! Is this really true?! Here is my test code:</p> <pre><code>const string str = @"91023m lkajsdfl;jkasdf;piou-09324\\adf \asdf\45\ 65u\ 86\ 8\\\;"; static int...
[ { "answer_id": 409184, "author": "tuinstoel", "author_id": 43901, "author_profile": "https://Stackoverflow.com/users/43901", "pm_score": 2, "selected": false, "text": "<p>Isn't it possible to download the code of the .net framework and to see what str.IndexOf really does? </p>\n" }, ...
2009/01/03
[ "https://Stackoverflow.com/questions/409162", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41283/" ]
When doing a simple performance measurement, I was astonished to see that calling `String.IndexOf(char)` was actually slower than doing it manually! Is this really true?! Here is my test code: ``` const string str = @"91023m lkajsdfl;jkasdf;piou-09324\\adf \asdf\45\ 65u\ 86\ 8\\\;"; static int testIndexOf() { return s...
(updated) With your newly posted rig, I get the numbers below, which are in line with what I would expect: ``` String. IndexOf : (00:00:06.3134669, -994967296) MyString.PublicIndexOf : (00:00:07.0769368, -994967296) MyString.InternIndexOf : (00:00:08.3463652, -994967296) MyString.PublicIndexOf2: (00:00:12.004926...
409,173
<p>How do I import a CSV file using OpenOffice.org APIs? I want to do this using the same functionality that is also provided when I open the same file using "CVS text" filter.</p>
[ { "answer_id": 409184, "author": "tuinstoel", "author_id": 43901, "author_profile": "https://Stackoverflow.com/users/43901", "pm_score": 2, "selected": false, "text": "<p>Isn't it possible to download the code of the .net framework and to see what str.IndexOf really does? </p>\n" }, ...
2009/01/03
[ "https://Stackoverflow.com/questions/409173", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51162/" ]
How do I import a CSV file using OpenOffice.org APIs? I want to do this using the same functionality that is also provided when I open the same file using "CVS text" filter.
(updated) With your newly posted rig, I get the numbers below, which are in line with what I would expect: ``` String. IndexOf : (00:00:06.3134669, -994967296) MyString.PublicIndexOf : (00:00:07.0769368, -994967296) MyString.InternIndexOf : (00:00:08.3463652, -994967296) MyString.PublicIndexOf2: (00:00:12.004926...
409,213
<p>I want to create a view that has different displays according to the role the user is in. </p> <p>Should I create a different view for different roles or should I check the roles on the Veiw page itself rather than in the actions?</p> <p>How would I check the role on the view page?</p>
[ { "answer_id": 409237, "author": "IAmCodeMonkey", "author_id": 27613, "author_profile": "https://Stackoverflow.com/users/27613", "pm_score": 2, "selected": false, "text": "<p>without researching the exact mechanism asp.net mvc uses for roles i would scream no for putting any of your bus...
2009/01/03
[ "https://Stackoverflow.com/questions/409213", "https://Stackoverflow.com", "https://Stackoverflow.com/users/43838/" ]
I want to create a view that has different displays according to the role the user is in. Should I create a different view for different roles or should I check the roles on the Veiw page itself rather than in the actions? How would I check the role on the view page?
> > Or should i use check the roles on the > Veiw page its self rather than on > actions, if so can someone plz show me > how do check that on view page > > > You need to do both. Check roles on actions as a security measure and check roles on views to enable/disable specific controls. Within your view page th...
409,217
<p>First, let me say that I'm a complete beginner at Python. I've never learned the language, I just thought "how hard can it be" when Google turned up nothing but Python snippets to solve my problem. :)</p> <p>I have a bunch of mailboxes in Maildir format (a backup from the mail server on my old web host), and I need...
[ { "answer_id": 409237, "author": "IAmCodeMonkey", "author_id": 27613, "author_profile": "https://Stackoverflow.com/users/27613", "pm_score": 2, "selected": false, "text": "<p>without researching the exact mechanism asp.net mvc uses for roles i would scream no for putting any of your bus...
2009/01/03
[ "https://Stackoverflow.com/questions/409217", "https://Stackoverflow.com", "https://Stackoverflow.com/users/33213/" ]
First, let me say that I'm a complete beginner at Python. I've never learned the language, I just thought "how hard can it be" when Google turned up nothing but Python snippets to solve my problem. :) I have a bunch of mailboxes in Maildir format (a backup from the mail server on my old web host), and I need to extrac...
> > Or should i use check the roles on the > Veiw page its self rather than on > actions, if so can someone plz show me > how do check that on view page > > > You need to do both. Check roles on actions as a security measure and check roles on views to enable/disable specific controls. Within your view page th...
409,226
<p>is there any difference between:</p> <pre><code>lock((IDictionary) _collection).SyncRoot) </code></pre> <p>or</p> <pre><code>lock(_collection) </code></pre>
[ { "answer_id": 409234, "author": "ctacke", "author_id": 13154, "author_profile": "https://Stackoverflow.com/users/13154", "pm_score": 3, "selected": true, "text": "<p>Yes, the Monitor is take out on a different object in each, so the two are not functional equivalents. The SyncRoot is e...
2009/01/03
[ "https://Stackoverflow.com/questions/409226", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4653/" ]
is there any difference between: ``` lock((IDictionary) _collection).SyncRoot) ``` or ``` lock(_collection) ```
Yes, the Monitor is take out on a different object in each, so the two are not functional equivalents. The SyncRoot is exposed so you can lock on it for collection member access (and the collection internally uses the same for locking). This allows code in the collection and code external to it to agree upon a specific...
409,236
<p>I am getting back a "string[]" from a 3rd party library. I want to do a contains on it. what is the most efficient way of doing this?</p>
[ { "answer_id": 409238, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 4, "selected": true, "text": "<p>Array.IndexOf:</p>\n\n<pre><code>bool contains = Array.IndexOf(arr, value) &gt;= 0;\n</code></pre>\n\n<p>Or just us...
2009/01/03
[ "https://Stackoverflow.com/questions/409236", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4653/" ]
I am getting back a "string[]" from a 3rd party library. I want to do a contains on it. what is the most efficient way of doing this?
Array.IndexOf: ``` bool contains = Array.IndexOf(arr, value) >= 0; ``` Or just use LINQ: ``` bool contains = arr.Contains(value); ``` LINQ should be "fast enough" for most purposes.
409,256
<p>I have a byte array that represents a complete TCP/IP packet. For clarification, the byte array is ordered like this:</p> <p>(IP Header - 20 bytes)(TCP Header - 20 bytes)(Payload - X bytes)</p> <p>I have a <code>Parse</code> function that accepts a byte array and returns a <code>TCPHeader</code> object. It looks...
[ { "answer_id": 409265, "author": "Aistina", "author_id": 37472, "author_profile": "https://Stackoverflow.com/users/37472", "pm_score": 0, "selected": false, "text": "<p>I don't think you can do something like that in C#. You could either make the Parse() function use an offset, or create...
2009/01/03
[ "https://Stackoverflow.com/questions/409256", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51170/" ]
I have a byte array that represents a complete TCP/IP packet. For clarification, the byte array is ordered like this: (IP Header - 20 bytes)(TCP Header - 20 bytes)(Payload - X bytes) I have a `Parse` function that accepts a byte array and returns a `TCPHeader` object. It looks like this: ``` TCPHeader Parse( byte[] ...
A common practice you can see in the .NET framework, and that I recommend using here, is specifying the offset and length. So make your Parse function also accept the offset in the passed array, and the number of elements to use. Of course, the same rules apply as if you were to pass a pointer like in C++ - the array ...
409,258
<p>I'm trying to design a database for a sports meeting.</p> <p>I think I've got something good but I'm not quite sure.</p> <p>The situation is as follows.</p> <p>There is the meeting, several sportsclubs will each send a number of athletes: 1 or more. The athletes can enter in more then one event. There are several...
[ { "answer_id": 409307, "author": "MattBelanger", "author_id": 655, "author_profile": "https://Stackoverflow.com/users/655", "pm_score": 3, "selected": true, "text": "<p>Add a result field to the participation table</p>\n" }, { "answer_id": 409315, "author": "Alex UK", "au...
2009/01/03
[ "https://Stackoverflow.com/questions/409258", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11795/" ]
I'm trying to design a database for a sports meeting. I think I've got something good but I'm not quite sure. The situation is as follows. There is the meeting, several sportsclubs will each send a number of athletes: 1 or more. The athletes can enter in more then one event. There are several events: Marathon, pole-...
Add a result field to the participation table
409,259
<p>I'm trying to do that for a couple of days now, and after reading tons of messages of people trying to do that too, I'm still unable to have a fully working <code>UITextField</code> in some of my <code>UITableViewCells</code>, just like in this example: </p> <p><img src="https://i.stack.imgur.com/gD4cE.png" alt="Sc...
[ { "answer_id": 412583, "author": "lostInTransit", "author_id": 46297, "author_profile": "https://Stackoverflow.com/users/46297", "pm_score": 4, "selected": false, "text": "<p>This should not be difficult. When creating a cell for your table, add a UITextField object to the cell's content...
2009/01/03
[ "https://Stackoverflow.com/questions/409259", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50090/" ]
I'm trying to do that for a couple of days now, and after reading tons of messages of people trying to do that too, I'm still unable to have a fully working `UITextField` in some of my `UITableViewCells`, just like in this example: ![Screenshot](https://i.stack.imgur.com/gD4cE.png) Either I have the form working but...
Try this out. Works like a charm for me (on iPhone devices). I used this code for a login screen once. I configured the table view to have two sections. You can of course get rid of the section conditionals. ``` - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { U...
409,293
<p><strong>Exact Duplicate of:</strong> <a href="https://stackoverflow.com/questions/409069/getting-the-size-free-total-of-a-windows-mobile-phone-drive-using-c-not-solve">Getting the size (free,total) of a Windows Mobile phone drive using c#</a> <hr> dear all;</p> <p>i know my problem took alot of time and many of u h...
[ { "answer_id": 409322, "author": "casperOne", "author_id": 50776, "author_profile": "https://Stackoverflow.com/users/50776", "pm_score": 3, "selected": true, "text": "<p>Basically, you call it like any other static method, in your case, like this:</p>\n\n<pre><code>FolderInfo = (CONADefi...
2009/01/03
[ "https://Stackoverflow.com/questions/409293", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42782/" ]
**Exact Duplicate of:** [Getting the size (free,total) of a Windows Mobile phone drive using c#](https://stackoverflow.com/questions/409069/getting-the-size-free-total-of-a-windows-mobile-phone-drive-using-c-not-solve) --- dear all; i know my problem took alot of time and many of u helped me but i'm new in C# and th...
Basically, you call it like any other static method, in your case, like this: ``` FolderInfo = (CONADefinitions.CONAPI_FOLDER_INFO)Marshal.PtrToStructure(Buffer, typeof(CONADefinitions.CONAPI_FOLDER_INFO)); if (FolderInfo.pstrName[0].ToString() != "C" && level == 0) { ulong FreeBytesAvailable; ulong TotalNumberOf...
409,296
<p>I am quite on lost on why Javascript does certain things in this way, or maybe I coded something wrong. But how come the code after $.getJSON gets executed before the callback is complete?</p> <pre><code>window.ratingCallback = function(data){ if(data[0].code == 3){ ratingHTML = buildHTML(0); ...
[ { "answer_id": 409304, "author": "M4N", "author_id": 19635, "author_profile": "https://Stackoverflow.com/users/19635", "pm_score": 3, "selected": false, "text": "<p>The getJSON() call is asynchronous. </p>\n\n<p>It's even mentioned in the docs (<a href=\"http://docs.jquery.com/Ajax/jQuer...
2009/01/03
[ "https://Stackoverflow.com/questions/409296", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I am quite on lost on why Javascript does certain things in this way, or maybe I coded something wrong. But how come the code after $.getJSON gets executed before the callback is complete? ``` window.ratingCallback = function(data){ if(data[0].code == 3){ ratingHTML = buildHTML(0); console.lo...
The getJSON() call is asynchronous. It's even mentioned in the docs (<http://docs.jquery.com/Ajax/jQuery.getJSON>): > > Note: Keep in mind, that lines after > this function will be executed before > callback. > > >
409,300
<p>The v4 series of the <code>gcc</code> compiler can automatically vectorize loops using the <a href="http://en.wikipedia.org/wiki/SIMD" rel="noreferrer">SIMD</a> processor on some modern CPUs, such as the AMD Athlon or Intel Pentium/Core chips. How is this done?</p>
[ { "answer_id": 409302, "author": "casualcoder", "author_id": 10578, "author_profile": "https://Stackoverflow.com/users/10578", "pm_score": 6, "selected": true, "text": "<p>The original page offers details on getting gcc to automatically vectorize\nloops, including a few examples:</p>\n\n...
2009/01/03
[ "https://Stackoverflow.com/questions/409300", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10578/" ]
The v4 series of the `gcc` compiler can automatically vectorize loops using the [SIMD](http://en.wikipedia.org/wiki/SIMD) processor on some modern CPUs, such as the AMD Athlon or Intel Pentium/Core chips. How is this done?
The original page offers details on getting gcc to automatically vectorize loops, including a few examples: <http://gcc.gnu.org/projects/tree-ssa/vectorization.html> While the examples are great, it turns out the syntax for calling those options with latest GCC seems to have changed a bit, see now: * <https://gcc.gn...
409,321
<p>So I'm trying to build a simple forum. It'll be a list of topics in descending order by the date of either the topic (if no replies) or latest reply. Here's the DB structure:</p> <p><strong>forum_topic</strong></p> <blockquote> <p>id, name, email, body, date</p> </blockquote> <p><strong>forum_reply</strong></p>...
[ { "answer_id": 409345, "author": "Filip Ekberg", "author_id": 39106, "author_profile": "https://Stackoverflow.com/users/39106", "pm_score": 2, "selected": false, "text": "<p>Somewhat like this:</p>\n\n<pre><code>select * from forum_topic\ninner join forum_reply on forum_topic.id=topc_id\...
2009/01/03
[ "https://Stackoverflow.com/questions/409321", "https://Stackoverflow.com", "https://Stackoverflow.com/users/32881/" ]
So I'm trying to build a simple forum. It'll be a list of topics in descending order by the date of either the topic (if no replies) or latest reply. Here's the DB structure: **forum\_topic** > > id, name, email, body, date > > > **forum\_reply** > > id, email, body, date, topic\_id > > > The forum itself ...
First off, it seems to me noboody is actually answering your question, which was: > > What would the query or queries look like to produce such a structure? > > > with a requested structure of Topic, LastModified, # Replies. The SQL to produce a result table with that structure, given the table structures you ...
409,325
<p>How do I check if a file is already used by another process from Powerscript ?</p>
[ { "answer_id": 410218, "author": "Brody", "author_id": 17131, "author_profile": "https://Stackoverflow.com/users/17131", "pm_score": 0, "selected": false, "text": "<p>You could try to open it and if it errors then it is probably already locked.</p>\n" }, { "answer_id": 411672, ...
2009/01/03
[ "https://Stackoverflow.com/questions/409325", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25122/" ]
How do I check if a file is already used by another process from Powerscript ?
The best way that I found is to call the WinAPI CreateFile to open a given file in exclusive mode. First, declare the following Local External Function (PB10) ``` FUNCTION Long CreateFile(ref string lpszName, long fdwAccess, long fdwShareMode, long lpsa, & long fdwCreate, long fdwAttrsAndFlags, long hTemplateFile) L...
409,348
<p>What is the correct way of iterating over a vector in C++?</p> <p>Consider these two code fragments, this one works fine:</p> <pre><code>for (unsigned i=0; i &lt; polygon.size(); i++) { sum += polygon[i]; } </code></pre> <p>and this one:</p> <pre><code>for (int i=0; i &lt; polygon.size(); i++) { sum += p...
[ { "answer_id": 409356, "author": "Igor", "author_id": 44673, "author_profile": "https://Stackoverflow.com/users/44673", "pm_score": 4, "selected": false, "text": "<p>Use <code>size_t</code> :</p>\n<pre><code>for (size_t i=0; i &lt; polygon.size(); i++)\n</code></pre>\n<p>Quoting <a href=...
2009/01/03
[ "https://Stackoverflow.com/questions/409348", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24545/" ]
What is the correct way of iterating over a vector in C++? Consider these two code fragments, this one works fine: ``` for (unsigned i=0; i < polygon.size(); i++) { sum += polygon[i]; } ``` and this one: ``` for (int i=0; i < polygon.size(); i++) { sum += polygon[i]; } ``` which generates `warning: compa...
For iterating backwards see [this answer](https://stackoverflow.com/questions/275994/whats-the-best-way-to-do-a-backwards-loop-in-c-c-c#276053). Iterating forwards is almost identical. Just change the iterators / swap decrement by increment. You should prefer iterators. Some people tell you to use `std::size_t` as th...
409,370
<p>I have the following data structure (a list of lists)</p> <pre><code>[ ['4', '21', '1', '14', '2008-10-24 15:42:58'], ['3', '22', '4', '2somename', '2008-10-24 15:22:03'], ['5', '21', '3', '19', '2008-10-24 15:45:45'], ['6', '21', '1', '1somename', '2008-10-24 15:45:49'], ['7', '22', '3', '2somename', '200...
[ { "answer_id": 409394, "author": "Federico A. Ramponi", "author_id": 18770, "author_profile": "https://Stackoverflow.com/users/18770", "pm_score": 2, "selected": false, "text": "<p>If I understand your question correctly, the following code should do the job:</p>\n\n<pre><code>l = [\n ['...
2009/01/03
[ "https://Stackoverflow.com/questions/409370", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51181/" ]
I have the following data structure (a list of lists) ``` [ ['4', '21', '1', '14', '2008-10-24 15:42:58'], ['3', '22', '4', '2somename', '2008-10-24 15:22:03'], ['5', '21', '3', '19', '2008-10-24 15:45:45'], ['6', '21', '1', '1somename', '2008-10-24 15:45:49'], ['7', '22', '3', '2somename', '2008-10-24 15:45:...
For the first question, the first thing you should do is sort the list by the second field using [itemgetter](https://docs.python.org/3/library/operator.html#operator.itemgetter) from the operator module: ``` x = [ ['4', '21', '1', '14', '2008-10-24 15:42:58'], ['3', '22', '4', '2somename', '2008-10-24 15:22:03'], ...
409,385
<p>I have a VB6 application that I am converting to .net. I am doing this in phases so clients will have both VB6 and .net applications at the same. Part of the application caches ADO 2.8 COM recordsets to a table in SQL Server and retrieves them as needed. The .net application uses that same persisted recordsets. I ...
[ { "answer_id": 409437, "author": "Charles Bretana", "author_id": 32632, "author_profile": "https://Stackoverflow.com/users/32632", "pm_score": 0, "selected": false, "text": "<p>If you are saying that the entire COM recordset is being persisted to a single column in the database table as ...
2009/01/03
[ "https://Stackoverflow.com/questions/409385", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8219/" ]
I have a VB6 application that I am converting to .net. I am doing this in phases so clients will have both VB6 and .net applications at the same. Part of the application caches ADO 2.8 COM recordsets to a table in SQL Server and retrieves them as needed. The .net application uses that same persisted recordsets. I have ...
Generally speaking, you aren't taking enough advantage of the using statement and handling it all yourself. Unfortunately, you are doing it the wrong way, in that if you have an implementation of IDisposable which throws an exception on the call to Dispose, the other calls to Dispose do not take place. If you use the u...
409,434
<p>How can I automatically execute an Excel macro each time a value in a particular cell changes?</p> <p>Right now, my working code is:</p> <pre><code>Private Sub Worksheet_Change(ByVal Target As Range) If Not Intersect(Target, Range("H5")) Is Nothing Then Macro End Sub </code></pre> <p>where <code>"H5"</code> i...
[ { "answer_id": 409439, "author": "Joe", "author_id": 13087, "author_profile": "https://Stackoverflow.com/users/13087", "pm_score": 3, "selected": false, "text": "<p>Handle the <code>Worksheet_Change</code> event or the <code>Workbook_SheetChange</code> event.</p>\n\n<p>The event handlers...
2009/01/03
[ "https://Stackoverflow.com/questions/409434", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34596/" ]
How can I automatically execute an Excel macro each time a value in a particular cell changes? Right now, my working code is: ``` Private Sub Worksheet_Change(ByVal Target As Range) If Not Intersect(Target, Range("H5")) Is Nothing Then Macro End Sub ``` where `"H5"` is the particular cell being monitored and `M...
Your code looks pretty good. Be careful, however, for your call to `Range("H5")` is a shortcut command to `Application.Range("H5")`, which is equivalent to `Application.ActiveSheet.Range("H5")`. This could be fine, if the only changes are user-changes -- which is the most typical -- but it is possible for the workshe...
409,449
<p>I have a Python function in which I am doing some sanitisation of the input parameters:</p> <pre><code>def func(param1, param2, param3): param1 = param1 or '' param2 = param2 or '' param3 = param3 or '' </code></pre> <p>This caters for the arguments being passed as <em>None</em> rather than empty strin...
[ { "answer_id": 409467, "author": "llimllib", "author_id": 42559, "author_profile": "https://Stackoverflow.com/users/42559", "pm_score": -1, "selected": false, "text": "<pre><code>def func(x='', y='', z='hooray!'):\n print x, y, z\n\nIn [2]: f('test')\ntest hooray!\n\nIn [3]: f('test'...
2009/01/03
[ "https://Stackoverflow.com/questions/409449", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42974/" ]
I have a Python function in which I am doing some sanitisation of the input parameters: ``` def func(param1, param2, param3): param1 = param1 or '' param2 = param2 or '' param3 = param3 or '' ``` This caters for the arguments being passed as *None* rather than empty strings. Is there an easier/more conci...
This looks like a good job for a decorator. How about this: ``` def sanitized(func): def sfunc(*args, **kwds): return func(*[arg or '' for arg in args], **dict((k, v or '') for k,v in kwds.iteritems())) sfunc.func_name = func.func_name sfunc.func_doc = func.func_doc return s...
409,454
<p>On C# 3.0 and .NET 3.5, imagine there's an interface:</p> <pre><code>public interface INameable { string Name {get;} } </code></pre> <p>and many immutable classes that implement the interface.</p> <p>I would like to have a single extension method</p> <pre><code>public static T Rename&lt;T&gt;(this T obj) where...
[ { "answer_id": 409481, "author": "Lasse V. Karlsen", "author_id": 267, "author_profile": "https://Stackoverflow.com/users/267", "pm_score": 1, "selected": false, "text": "<p>Well, yes, it's possible, but it involves generating code in memory.</p>\n\n<p>You can look at <a href=\"http://ms...
2009/01/03
[ "https://Stackoverflow.com/questions/409454", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48722/" ]
On C# 3.0 and .NET 3.5, imagine there's an interface: ``` public interface INameable { string Name {get;} } ``` and many immutable classes that implement the interface. I would like to have a single extension method ``` public static T Rename<T>(this T obj) where T : INameable { ... } ``` that returns a wra...
No, this isn't possible, unless `T` is constrained to be an interface or to be a class with all members virtual, and this constraint isn't possible to specify at compile time (though you could write a runtime check if you're happy with that approach). The reason you cannot do it for arbitrary types is that if you take...
409,487
<p>I want to get the size of the phone drive. I'm using "Nokia-PC-Connectivity"., and with respect to File System API I found on CONADifinition function called CONA_Folder_Info but this function doens't support FreeSize and Total Size but there is CONA_Folder.Info2 and its instance support these variables.</p> <p>But ...
[ { "answer_id": 409620, "author": "ctacke", "author_id": 13154, "author_profile": "https://Stackoverflow.com/users/13154", "pm_score": 0, "selected": false, "text": "<p>I don't know anything about the Nokia API, but in general I see the following:</p>\n\n<ol>\n<li>Find APIs usually have a...
2009/01/03
[ "https://Stackoverflow.com/questions/409487", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42782/" ]
I want to get the size of the phone drive. I'm using "Nokia-PC-Connectivity"., and with respect to File System API I found on CONADifinition function called CONA\_Folder\_Info but this function doens't support FreeSize and Total Size but there is CONA\_Folder.Info2 and its instance support these variables. But when I ...
It is correct that you get the exception when you try and convert the data in the buffer to a different type of structure than was originally created by CONAFileSystem.CONAFindNextFolder. You are trying to force a data structure of type CONADefinitions.CONAPI\_FOLDER\_INFO into a structure of type CONADefinitions.CONA...
409,496
<p>I have a php file which I will be using as exclusively as an include. Therefore I would like to throw an error instead of executing it when it's accessed directly by typing in the URL instead of being included.</p> <p>Basically I need to do a check as follows in the php file:</p> <pre><code>if ( $REQUEST_URL == $U...
[ { "answer_id": 409503, "author": "Kyle Cronin", "author_id": 658, "author_profile": "https://Stackoverflow.com/users/658", "pm_score": 2, "selected": false, "text": "<p>The easiest way is to set some variable in the file that calls include, such as</p>\n\n<pre><code>$including = true;\n<...
2009/01/03
[ "https://Stackoverflow.com/questions/409496", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36848/" ]
I have a php file which I will be using as exclusively as an include. Therefore I would like to throw an error instead of executing it when it's accessed directly by typing in the URL instead of being included. Basically I need to do a check as follows in the php file: ``` if ( $REQUEST_URL == $URL_OF_CURRENT_PAGE ) ...
The easiest way for the generic "PHP app running on an Apache server that you may or may not fully control" situation is to put your includes in a directory and deny access to that directory in your .htaccess file. To save people the trouble of Googling, if you're using Apache, put this in a file called ".htaccess" in ...
409,512
<p>Is is possible to call a custom VB function, saved in the same Access Db, from a query written in that db, and if so, how?</p>
[ { "answer_id": 409534, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": true, "text": "<p>Yes, you can call a macro or function from an Access query. Make your function public. Then call it inside your SQL like s...
2009/01/03
[ "https://Stackoverflow.com/questions/409512", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51205/" ]
Is is possible to call a custom VB function, saved in the same Access Db, from a query written in that db, and if so, how?
Yes, you can call a macro or function from an Access query. Make your function public. Then call it inside your SQL like so: ``` CustomFunction([field]) ```
409,529
<p>This particular example relates to Django in Python, but should apply to any language supporting exceptions:</p> <pre><code>try: object = ModelClass.objects.get(search=value) except DoesNotExist: pass if object: # do stuff </code></pre> <p>The Django model class provides a simple method <em>get</em> w...
[ { "answer_id": 409538, "author": "Greg Beech", "author_id": 13552, "author_profile": "https://Stackoverflow.com/users/13552", "pm_score": 4, "selected": true, "text": "<p>The clue is in the name - exceptions should be exceptional.</p>\n\n<p>If you always expect the item will exist then u...
2009/01/03
[ "https://Stackoverflow.com/questions/409529", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42974/" ]
This particular example relates to Django in Python, but should apply to any language supporting exceptions: ``` try: object = ModelClass.objects.get(search=value) except DoesNotExist: pass if object: # do stuff ``` The Django model class provides a simple method *get* which allows me to search for *one...
The clue is in the name - exceptions should be exceptional. If you always expect the item will exist then use `get`, but if you expect it not to exist a reasonable proportion of the time (i.e. it not existing is an expected result rather than an exceptional result) then I'd suggest using `filter`. So, seeing as you i...
409,555
<p>I have three buttons and need to save some data. I have a idea, I have to set an ID to every button and then let the JS determinate witch button that has been pressed, like:</p> <pre><code>$("#mySpecifikButton").click(function() { ....some code here... }); </code></pre> <p>but then Im stuck. For example I have 9 u...
[ { "answer_id": 409567, "author": "Salty", "author_id": 50548, "author_profile": "https://Stackoverflow.com/users/50548", "pm_score": 3, "selected": true, "text": "<p>From what I can see, you can use Ajax to send the value of the button that has been pressed to the php script. Search the ...
2009/01/03
[ "https://Stackoverflow.com/questions/409555", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50896/" ]
I have three buttons and need to save some data. I have a idea, I have to set an ID to every button and then let the JS determinate witch button that has been pressed, like: ``` $("#mySpecifikButton").click(function() { ....some code here... }); ``` but then Im stuck. For example I have 9 users. All they have an ID ...
From what I can see, you can use Ajax to send the value of the button that has been pressed to the php script. Search the [jQuery site](http://jquery.com) for documentation on $.get and $.post. :) Edit: Now that I'm not on my iPod, it'll be much easier to type. :P Here's what I mean: ``` <input type="button" value="...
409,563
<p>I'm stuck deciding how to handle exceptions in my application. </p> <p>Much if my issues with exceptions comes from 1) accessing data via a remote service or 2) deserializing a JSON object. Unfortunately I can't guarantee success for either of these tasks (cut network connection, malformed JSON object that is out o...
[ { "answer_id": 409571, "author": "Brian Rasmussen", "author_id": 38206, "author_profile": "https://Stackoverflow.com/users/38206", "pm_score": 7, "selected": true, "text": "<p>It seems odd to me that you want to catch exceptions and turn them into error codes. Why do you think the caller...
2009/01/03
[ "https://Stackoverflow.com/questions/409563", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51211/" ]
I'm stuck deciding how to handle exceptions in my application. Much if my issues with exceptions comes from 1) accessing data via a remote service or 2) deserializing a JSON object. Unfortunately I can't guarantee success for either of these tasks (cut network connection, malformed JSON object that is out of my contr...
It seems odd to me that you want to catch exceptions and turn them into error codes. Why do you think the caller would prefer error codes over exceptions when the latter is the default in both Java and C#? As for your questions: 1. You should only catch exceptions that you can actually handle. Just catching exceptio...
409,599
<p>[EDIT] Hmm. Perhaps this question should be titled "what is the default user-input dialog view called in CocoaTouch?" I realize that I can create an entire view that is exactly what I want, and wrap it in a view controller and presentModalView -- but I was sort of hoping that there was a standard, normal user-inpu...
[ { "answer_id": 409714, "author": "Stephen Darlington", "author_id": 2998, "author_profile": "https://Stackoverflow.com/users/2998", "pm_score": 3, "selected": false, "text": "<p>Even if you can get this working it's not going to be very iPhone-y. The <code>UIAlertView</code> really is no...
2009/01/03
[ "https://Stackoverflow.com/questions/409599", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34820/" ]
[EDIT] Hmm. Perhaps this question should be titled "what is the default user-input dialog view called in CocoaTouch?" I realize that I can create an entire view that is exactly what I want, and wrap it in a view controller and presentModalView -- but I was sort of hoping that there was a standard, normal user-input "di...
The simplest (and most proper way) to move the text view down is to add a message ``` [find setMessage:@"\n"]; ``` Also, the reason your frame isn't taking effect is that `-show` sets the frame and creates the view hierarchy before starting the animation. You should also make the text view the first responder so the...
409,619
<p>Does anyone know how to monitor long-running server-side processes in GWT, other than polling the server? We need to do some time-consuming, multiple-step, I/O-bound processing on the server, and it would be nice to display the progress of this processing in the browser.</p>
[ { "answer_id": 409706, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "<p>I think it depends on your process but if you are going to do something like Data Streaming you can use Server Push (Or Com...
2009/01/03
[ "https://Stackoverflow.com/questions/409619", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49642/" ]
Does anyone know how to monitor long-running server-side processes in GWT, other than polling the server? We need to do some time-consuming, multiple-step, I/O-bound processing on the server, and it would be nice to display the progress of this processing in the browser.
This is fairly easy to handle in GWT. The long-running process is either triggered by a GWT RPC call, in which case you have your entry point, or it isn't, in which case you need to start this off manually. Remember that GWT RPC calls are asynchronous so they don't need to return immediately. You need an RPC call lik...
409,648
<p>is there a way to make the datatextfield property of a dropdownlist in asp.net via c# composed of more than one property of an object?</p> <pre><code>public class MyObject { public int Id { get; set; } public string Name { get; set; } public string FunkyValue { get; set; } public int Zip { get; set; } } pr...
[ { "answer_id": 409681, "author": "M4N", "author_id": 19635, "author_profile": "https://Stackoverflow.com/users/19635", "pm_score": 6, "selected": true, "text": "<p>Add another property to the MyObject class and bind to that property :</p>\n\n<pre><code>public string DisplayValue\n{\n get...
2009/01/03
[ "https://Stackoverflow.com/questions/409648", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49034/" ]
is there a way to make the datatextfield property of a dropdownlist in asp.net via c# composed of more than one property of an object? ``` public class MyObject { public int Id { get; set; } public string Name { get; set; } public string FunkyValue { get; set; } public int Zip { get; set; } } protected void P...
Add another property to the MyObject class and bind to that property : ``` public string DisplayValue { get { return string.Format("{0} ({1})", Name, Zip); } } ``` Or if you can not modify MyObject, create a wrapper object in the presentation layer (just for displaying). This can also be done using some LINQ: ``` ...
409,705
<p>Ok, here is my dilemma I have a database set up with about 5 tables all with the exact same data structure. The data is separated in this manner for localization purposes and to split up a total of about 4.5 million records.</p> <p>A majority of the time only one table is needed and all is well. However, sometimes ...
[ { "answer_id": 409720, "author": "Mihai Limbășan", "author_id": 14444, "author_profile": "https://Stackoverflow.com/users/14444", "pm_score": 8, "selected": true, "text": "<p>I think you're looking for the <a href=\"http://dev.mysql.com/doc/refman/5.1/en/union.html\" rel=\"noreferrer\">U...
2009/01/03
[ "https://Stackoverflow.com/questions/409705", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24802/" ]
Ok, here is my dilemma I have a database set up with about 5 tables all with the exact same data structure. The data is separated in this manner for localization purposes and to split up a total of about 4.5 million records. A majority of the time only one table is needed and all is well. However, sometimes data is ne...
I think you're looking for the [UNION](http://dev.mysql.com/doc/refman/5.1/en/union.html) clause, a la ``` (SELECT * from us_music where `genre` = 'punk') UNION (SELECT * from de_music where `genre` = 'punk') ```
409,727
<p>I just finished transferring as much link-structure data concerning wikipedia (English) as I could. Basically, I downloaded a bunch of SQL dumps from wikipedia's <a href="http://download.wikimedia.org/enwiki/latest/" rel="nofollow noreferrer">latest dump repository</a>. Since I am using PostgreSQL instead of MySQL, ...
[ { "answer_id": 409760, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 1, "selected": false, "text": "<p>What <em>exactly</em> is claiming that it's only taking 9.5MB of RAM? That sounds unlikely to me - the shared memory ...
2009/01/03
[ "https://Stackoverflow.com/questions/409727", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49985/" ]
I just finished transferring as much link-structure data concerning wikipedia (English) as I could. Basically, I downloaded a bunch of SQL dumps from wikipedia's [latest dump repository](http://download.wikimedia.org/enwiki/latest/). Since I am using PostgreSQL instead of MySQL, I decided to load all these dumps into m...
It's probably the GROUP BY that's causing the problem. In order to do grouping, the database has to sort the rows to put duplicate items together. An index probably won't help. A back-of-the-envelope calculation: Assuming each row takes 100 bytes of space, that's 29,500,000,000 bytes, or about 30GB of storage. It can'...
409,732
<p>I have a list of booleans where occasionally I reset them all to false. After first writing the reset as:</p> <pre><code>for b in bool_list: b = False </code></pre> <p>I found it doesn't work. I spent a moment scratching my head, then remembered that of course it won't work since I'm only changing a reference ...
[ { "answer_id": 409744, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 4, "selected": false, "text": "<p>If you only have one reference to the list, the following may be easier:</p>\n\n<pre><code>bool_list = [False] * len(b...
2009/01/03
[ "https://Stackoverflow.com/questions/409732", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22897/" ]
I have a list of booleans where occasionally I reset them all to false. After first writing the reset as: ``` for b in bool_list: b = False ``` I found it doesn't work. I spent a moment scratching my head, then remembered that of course it won't work since I'm only changing a reference to the bool, not its value...
``` bool_list[:] = [False] * len(bool_list) ``` or ``` bool_list[:] = [False for item in bool_list] ```
409,769
<p>I am using google's appengine api</p> <pre><code>from google.appengine.api import urlfetch </code></pre> <p>to fetch a webpage. The result of</p> <pre><code>result = urlfetch.fetch("http://www.example.com/index.html") </code></pre> <p>is a string of the html content (in result.content). The problem is the data...
[ { "answer_id": 409780, "author": "Jimmy2Times", "author_id": 51184, "author_profile": "https://Stackoverflow.com/users/51184", "pm_score": 2, "selected": false, "text": "<p>Only suggestion I can think of is to parse it as if it has fixed width columns. Newlines are not taken into consid...
2009/01/03
[ "https://Stackoverflow.com/questions/409769", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40619/" ]
I am using google's appengine api ``` from google.appengine.api import urlfetch ``` to fetch a webpage. The result of ``` result = urlfetch.fetch("http://www.example.com/index.html") ``` is a string of the html content (in result.content). The problem is the data that I want to parse is not really in HTML form, s...
I understand that the format of the document is the one you have posted. In that case, I agree that a parser like [Beautiful Soup](http://www.crummy.com/software/BeautifulSoup/) may not be a good solution. I assume that you are already getting the interesting data (between the BODY tags) with a regular expression like...
409,783
<p>I recently saw a bit of code that looked like this (with sock being a socket object of course):</p> <pre><code>sock.shutdown(socket.SHUT_RDWR) sock.close() </code></pre> <p>What exactly is the purpose of calling shutdown on the socket and then closing it? If it makes a difference, this socket is being used for no...
[ { "answer_id": 409843, "author": "Bob Nadler", "author_id": 2514, "author_profile": "https://Stackoverflow.com/users/2514", "pm_score": 7, "selected": true, "text": "<p>Here's one <a href=\"http://publib.boulder.ibm.com/infocenter/systems/index.jsp?topic=/com.ibm.aix.progcomm/doc/progcom...
2009/01/03
[ "https://Stackoverflow.com/questions/409783", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2147/" ]
I recently saw a bit of code that looked like this (with sock being a socket object of course): ``` sock.shutdown(socket.SHUT_RDWR) sock.close() ``` What exactly is the purpose of calling shutdown on the socket and then closing it? If it makes a difference, this socket is being used for non-blocking IO.
Here's one [explanation](http://publib.boulder.ibm.com/infocenter/systems/index.jsp?topic=/com.ibm.aix.progcomm/doc/progcomc/skt_shutdn.htm): > > Once a socket is no longer required, > the calling program can discard the > socket by applying a close subroutine > to the socket descriptor. If a > reliable delivery ...
409,784
<p>In Java, arrays don't override <code>toString()</code>, so if you try to print one directly, you get the <code>className</code> + '@' + the hex of the <a href="https://en.wikipedia.org/wiki/Java_hashCode()" rel="nofollow noreferrer"><code>hashCode</code></a> of the array, as defined by <code>Object.toString()</code>...
[ { "answer_id": 409795, "author": "Esko", "author_id": 44523, "author_profile": "https://Stackoverflow.com/users/44523", "pm_score": 13, "selected": true, "text": "<p>Since Java 5 you can use <a href=\"https://docs.oracle.com/javase/9/docs/api/java/util/Arrays.html#toString-int:A-\" rel=\...
2009/01/03
[ "https://Stackoverflow.com/questions/409784", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12149/" ]
In Java, arrays don't override `toString()`, so if you try to print one directly, you get the `className` + '@' + the hex of the [`hashCode`](https://en.wikipedia.org/wiki/Java_hashCode()) of the array, as defined by `Object.toString()`: ```java int[] intArray = new int[] {1, 2, 3, 4, 5}; System.out.println(intArray);...
Since Java 5 you can use [`Arrays.toString(arr)`](https://docs.oracle.com/javase/9/docs/api/java/util/Arrays.html#toString-int:A-) or [`Arrays.deepToString(arr)`](https://docs.oracle.com/javase/9/docs/api/java/util/Arrays.html#deepToString-java.lang.Object:A-) for arrays within arrays. Note that the `Object[]` version ...
409,799
<p>I am trying to setup roles in a dynamic data website.. the problem is that i cant set it by simpy doing this. </p> <pre><code> &lt;location path="List.aspx"&gt; &lt;system.web&gt; &lt;authorization&gt; &lt;allow roles="Administrators" /&gt; &lt;deny users="*" /&gt; &lt;/authorizat...
[ { "answer_id": 409964, "author": "LastBye", "author_id": 50506, "author_profile": "https://Stackoverflow.com/users/50506", "pm_score": 0, "selected": false, "text": "<p>Your question as my friend said , needs more details ,\nanyway </p>\n\n<ol>\n<li><p>at first try to check whether you <...
2009/01/03
[ "https://Stackoverflow.com/questions/409799", "https://Stackoverflow.com", "https://Stackoverflow.com/users/43838/" ]
I am trying to setup roles in a dynamic data website.. the problem is that i cant set it by simpy doing this. ``` <location path="List.aspx"> <system.web> <authorization> <allow roles="Administrators" /> <deny users="*" /> </authorization> </system.web> </location> ``` so eve...
Dynamic Data pages ignores all that jazz. Look at the Secure Dynamic Data Project here: <http://www.codeplex.com/aspnet/Release/ProjectReleases.aspx?ReleaseId=14473> ... Or there is another way which worked for me. Change your location path to: ``` <location path="Admin/<TableName>/List.aspx"> <system.web>...
409,827
<p>I'm trying to get my head around tuples (thanks @litb), and the common suggestion for their use is for functions returning > 1 value. </p> <p>This is something that I'd normally use a struct for , and I can't understand the advantages to tuples in this case - it seems an error-prone approach for the terminally lazy...
[ { "answer_id": 409838, "author": "Anteru", "author_id": 39912, "author_profile": "https://Stackoverflow.com/users/39912", "pm_score": 3, "selected": false, "text": "<p>With tuples, you can use <code>tie</code>, which is sometimes quite useful: <code>std::tr1::tie (quotient, remainder) = ...
2009/01/03
[ "https://Stackoverflow.com/questions/409827", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1737/" ]
I'm trying to get my head around tuples (thanks @litb), and the common suggestion for their use is for functions returning > 1 value. This is something that I'd normally use a struct for , and I can't understand the advantages to tuples in this case - it seems an error-prone approach for the terminally lazy. [Borrow...
### tuples I think i agree with you that the issue with what position corresponds to what variable can introduce confusion. But i think there are two sides. One is the *call-side* and the other is the *callee-side*: ``` int remainder; int quotient; tie(quotient, remainder) = div(10, 3); ``` I think it's crystal cl...
409,849
<p>I am trying to select 100s of rows at a DB that contains 100000s of row and update those rows afters.</p> <p>the problem is I don't want to go to DB twice for this purpose since update only marks those rows as "read".</p> <p>is there any way I can do this in java using simple jdbc libraries? (hopefully without usi...
[ { "answer_id": 409859, "author": "recursive", "author_id": 44743, "author_profile": "https://Stackoverflow.com/users/44743", "pm_score": 0, "selected": false, "text": "<p>Can't you just use the same connection without closing it?</p>\n" }, { "answer_id": 409872, "author": "Br...
2009/01/03
[ "https://Stackoverflow.com/questions/409849", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51238/" ]
I am trying to select 100s of rows at a DB that contains 100000s of row and update those rows afters. the problem is I don't want to go to DB twice for this purpose since update only marks those rows as "read". is there any way I can do this in java using simple jdbc libraries? (hopefully without using stored procedu...
It seems to me there might be more than one way to interpret the question here. 1. You are selecting the rows for the sole purpose of updating them and not reading them. 2. You are selecting the rows to show to somebody, and marking them as read either one at a time or all as a group. 3. You want to select the rows a...