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
456,807
<p>I have a ASP MVC App with some seemingly simple code to save and retrieve cookies but for some reason they won't persist. The code in the controller is :</p> <pre><code>if (System.Web.HttpContext.Current.Response.Cookies["CountryPreference"] == null) { HttpCookie cookie = new HttpCookie("CountryPreference"); ...
[ { "answer_id": 590258, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 8, "selected": true, "text": "<p>The problem lies in following code:</p>\n\n<pre><code>if (System.Web.HttpContext.Current.Response.Cookies[\"CountryPreferenc...
2009/01/19
[ "https://Stackoverflow.com/questions/456807", "https://Stackoverflow.com", "https://Stackoverflow.com/users/27294/" ]
I have a ASP MVC App with some seemingly simple code to save and retrieve cookies but for some reason they won't persist. The code in the controller is : ``` if (System.Web.HttpContext.Current.Response.Cookies["CountryPreference"] == null) { HttpCookie cookie = new HttpCookie("CountryPreference"); cookie.Value...
The problem lies in following code: ``` if (System.Web.HttpContext.Current.Response.Cookies["CountryPreference"] == null) ``` When you try to check existence of a cookie using Response object rather than Request, ASP.net automatically creates a cookie. Check this detailed post here: <http://chwe.at/blog/post/2009/...
456,808
<p>I'd really like some help with this as I have hardly any idea where to start.</p> <p>I'm fed up of not having somewhere to properly test any web code and the free hosting sites I've found only support half of what I want.</p> <p><strong>I want to setup my own server capable of dishing out webpages, running a datab...
[ { "answer_id": 590258, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 8, "selected": true, "text": "<p>The problem lies in following code:</p>\n\n<pre><code>if (System.Web.HttpContext.Current.Response.Cookies[\"CountryPreferenc...
2009/01/19
[ "https://Stackoverflow.com/questions/456808", "https://Stackoverflow.com", "https://Stackoverflow.com/users/398/" ]
I'd really like some help with this as I have hardly any idea where to start. I'm fed up of not having somewhere to properly test any web code and the free hosting sites I've found only support half of what I want. **I want to setup my own server capable of dishing out webpages, running a database and handling WCF se...
The problem lies in following code: ``` if (System.Web.HttpContext.Current.Response.Cookies["CountryPreference"] == null) ``` When you try to check existence of a cookie using Response object rather than Request, ASP.net automatically creates a cookie. Check this detailed post here: <http://chwe.at/blog/post/2009/...
456,815
<p>Actually I am trying to move some box alternatively with in another box. I made it work, but both the blocks do not interrupt each other. What should I do? How can I make the blocks cross each other? I try using style:position, but it is not working.</p> <p>Here is the code I have been using:</p> <pre><code>&lt;ma...
[ { "answer_id": 456823, "author": "Baishampayan Ghose", "author_id": 8024, "author_profile": "https://Stackoverflow.com/users/8024", "pm_score": 6, "selected": false, "text": "<p>Please don't use the marquee tag, it's non-standard and deprecated. Use some JavaScript library like <a href=\...
2009/01/19
[ "https://Stackoverflow.com/questions/456815", "https://Stackoverflow.com", "https://Stackoverflow.com/users/38172/" ]
Actually I am trying to move some box alternatively with in another box. I made it work, but both the blocks do not interrupt each other. What should I do? How can I make the blocks cross each other? I try using style:position, but it is not working. Here is the code I have been using: ``` <marquee direction="down" b...
Oh, dear Lord! Well. They don't cross because they're positioned statically one above the other. The second marquee cannot go above the first. You can solve\* this problem by ungluing the marquees from each other using absolute positioning. Then doubly-nest each one with different horizontal and vertical motion: ```...
456,839
<p>I am in the middle of moving over a large body of code to Castle Trunk which includes the new fluent interface for configuring the container. Since the project has a huge windsorConfig xml file that is beyond maintainable, I thought I would start to take advantage of this new feature. I know other containers (e.g. S...
[ { "answer_id": 458572, "author": "Dan Fitch", "author_id": 27614, "author_profile": "https://Stackoverflow.com/users/27614", "pm_score": 1, "selected": false, "text": "<p>Tricky questions [and I'm no IoC expert] but keep in mind that any \"monolithic static function\" should not be <em>n...
2009/01/19
[ "https://Stackoverflow.com/questions/456839", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2281/" ]
I am in the middle of moving over a large body of code to Castle Trunk which includes the new fluent interface for configuring the container. Since the project has a huge windsorConfig xml file that is beyond maintainable, I thought I would start to take advantage of this new feature. I know other containers (e.g. Stru...
Take a deeper look at StructureMap 2.5. It offers several features to dramatically reduce the work to bootstrap the IOC container. It offers a convention over configuration technique (see the blog entries below) See the following recent blog posts from Jeremy Miller (author of StructureMap) [Create your own Auto Regi...
456,841
<p>I want to detect whether the browser is refreshed or not using PHP, and if the browser is refreshed, what particular PHP code should execute.</p>
[ { "answer_id": 456851, "author": "Bjorn", "author_id": 66475, "author_profile": "https://Stackoverflow.com/users/66475", "pm_score": 1, "selected": false, "text": "<p>If you mean that you want to distinguish between when a user first comes to the page from when they reload the page check...
2009/01/19
[ "https://Stackoverflow.com/questions/456841", "https://Stackoverflow.com", "https://Stackoverflow.com/users/54128/" ]
I want to detect whether the browser is refreshed or not using PHP, and if the browser is refreshed, what particular PHP code should execute.
If the page was refreshed then you'd expect two requests following each other to be for the same URL (path, filename, query string), and the same form content (if any) (POST data). This could be quite a lot of data, so it may be best to hash it. So ... ``` <?php session_start(); //The second parameter on print_r ret...
456,859
<p>I have a number of tables with the same columns and it would look a lot nicer if they shared the same column widths. Is such a thing possible? Putting them in the same table with some rows with no borders between them isn't an option.</p> <p><strong>Edit:</strong> Yeah I'm aware I can fix the widths myself but I ...
[ { "answer_id": 456875, "author": "Ken Browning", "author_id": 53162, "author_profile": "https://Stackoverflow.com/users/53162", "pm_score": 5, "selected": true, "text": "<p>It's only possible if you can fix-width the columns. If you can set a fixed width then some css like this should w...
2009/01/19
[ "https://Stackoverflow.com/questions/456859", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18393/" ]
I have a number of tables with the same columns and it would look a lot nicer if they shared the same column widths. Is such a thing possible? Putting them in the same table with some rows with no borders between them isn't an option. **Edit:** Yeah I'm aware I can fix the widths myself but I was hoping for something ...
It's only possible if you can fix-width the columns. If you can set a fixed width then some css like this should work: ``` td { width: 25%; } ``` You can customize each columns width like this: ``` <table> <tr> <td class="col1">...</td> <td class="col2">...</td> </tr> </table> ... <table> <tr> ...
456,867
<p>Can anyone help me please to solve this..</p> <pre><code>from django.db import models # Create your models here. class Poll(models.model): question = models.CharField(max_length=200) pub_date = models.DateTimeField('date published') class Choice(models.Model): poll = models.ForeignKey(Poll) choice...
[ { "answer_id": 456880, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "<p>As the error message says in the last line: the module <code>models</code> in the file <code>c:\\projects\\mysite..\\mysite...
2009/01/19
[ "https://Stackoverflow.com/questions/456867", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14752/" ]
Can anyone help me please to solve this.. ``` from django.db import models # Create your models here. class Poll(models.model): question = models.CharField(max_length=200) pub_date = models.DateTimeField('date published') class Choice(models.Model): poll = models.ForeignKey(Poll) choice = models.Char...
It's called models.Model and not models.model (case sensitive). Fix your Poll model like this - ``` class Poll(models.Model): question = models.CharField(max_length=200) pub_date = models.DateTimeField('date published') ```
456,873
<p>In general I use exceptions to deal with errors, however the problem I have here is that the error applies to a different thread than the one that caused it.</p> <p>Basicly the window has its own thread, and the direct3d device must be created and reset by the same thread that created the window. However creating t...
[ { "answer_id": 456968, "author": "jpalecek", "author_id": 51831, "author_profile": "https://Stackoverflow.com/users/51831", "pm_score": 0, "selected": false, "text": "<p>Well, the answer is that you can't. A viable alternative would be to do only necessary work that can't fail, like extr...
2009/01/19
[ "https://Stackoverflow.com/questions/456873", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6266/" ]
In general I use exceptions to deal with errors, however the problem I have here is that the error applies to a different thread than the one that caused it. Basicly the window has its own thread, and the direct3d device must be created and reset by the same thread that created the window. However creating the device ...
I see you call `PostMessage` from `Callback` then actively wait using a loop and `Sleep`. Replace `PostMessage` by [`SendMessage`](http://msdn.microsoft.com/en-us/library/ms644950(VS.85).aspx), which will wait for the message processing to complete. That way the processor-intensive loop is gone. Moreover, you can use t...
456,874
<p>Yo.</p> <p>I need to scan a directory and its sub-folders, I used FindFirst and FindNext procedures, but the TSearchRec's Name property is a string, thus unicode folder names (hebrew, arabic etc) are '?????' in the Name property.</p> <p>I tried using TntComponent, with WideFindFirst, WideFindNext and TSearchRecW. ...
[ { "answer_id": 456947, "author": "Toon Krijthe", "author_id": 18061, "author_profile": "https://Stackoverflow.com/users/18061", "pm_score": 3, "selected": true, "text": "<p>Delphi versions prior to 2009 have very limited unicode support. So if you really want unicode, then I strongly adv...
2009/01/19
[ "https://Stackoverflow.com/questions/456874", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25316/" ]
Yo. I need to scan a directory and its sub-folders, I used FindFirst and FindNext procedures, but the TSearchRec's Name property is a string, thus unicode folder names (hebrew, arabic etc) are '?????' in the Name property. I tried using TntComponent, with WideFindFirst, WideFindNext and TSearchRecW. But I still get ?...
Delphi versions prior to 2009 have very limited unicode support. So if you really want unicode, then I strongly advise you to upgrade to 2009. In 2009 the default string is unicode. You say that you still got garbage characters with the wide versions. Have you tried to inspect the values with the debugger? The vcl of...
456,887
<p>Here is my Json data:</p> <pre><code>[{"ok" : false, "details" : [{"n" : "Email", "v" : "The email address you entered is not correct."}, {"n" : "NameFull", "v" : "Please enter your full name."}] }] </code></pre> <p>I found read sigle-level Json data is super-easy ...
[ { "answer_id": 456903, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "<p>Sorry, maybe I don't understand your question. This doesn't work for you?</p>\n\n<p><code>var data = eval('(' + strJson + '...
2009/01/19
[ "https://Stackoverflow.com/questions/456887", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Here is my Json data: ``` [{"ok" : false, "details" : [{"n" : "Email", "v" : "The email address you entered is not correct."}, {"n" : "NameFull", "v" : "Please enter your full name."}] }] ``` I found read sigle-level Json data is super-easy but for multi-level data l...
**The data is inside an array** Note the square brackets around your data. You will have to index into the array in the above set of data. This should let you access the email value: ``` var json = '[{"ok":false,"details":[{"n":"Email","v":"The email address you entered is not correct."},{"n":"NameFull","v":"Please ...
456,895
<p>in my data layer class I have created a function to manually refresh the data source.</p> <pre><code>Public Sub DiscardAllChanges() _Context.Refresh(RefreshMode.OverwriteCurrentValues) End Sub </code></pre> <p>The problem is that the context <strong>ChangeSet</strong> after this operation still trace the pre...
[ { "answer_id": 456917, "author": "Spence", "author_id": 53771, "author_profile": "https://Stackoverflow.com/users/53771", "pm_score": 1, "selected": false, "text": "<p>Sounds like your trying to deal with concurrency issues? This is where when you submit, the database has already change...
2009/01/19
[ "https://Stackoverflow.com/questions/456895", "https://Stackoverflow.com", "https://Stackoverflow.com/users/52879/" ]
in my data layer class I have created a function to manually refresh the data source. ``` Public Sub DiscardAllChanges() _Context.Refresh(RefreshMode.OverwriteCurrentValues) End Sub ``` The problem is that the context **ChangeSet** after this operation still trace the previous operation of Insertion, Deletion ...
The easiest way to handle this is to treat the `DataContext` as your unit of work. Perform an atomic set of related operations on a single `DataContext`, then after either success or failure, `Dispose()` it (ideally via `using`) and throw it away. Start you next set of operations on a new `DataContext`. Likewise, you ...
456,914
<p>I try to find methods that have expression createNamedQuery</p> <p>I try</p> <pre><code>public[\d\D]*?createNamedQuery </code></pre> <p>but it finds the first method, but i want the method that has expression createNamedQuery</p>
[ { "answer_id": 456963, "author": "Evan Fosmark", "author_id": 49701, "author_profile": "https://Stackoverflow.com/users/49701", "pm_score": 1, "selected": false, "text": "<p>I'm guessing that your problem is that you cannot find all of them, but rather just the first one. The way to retr...
2009/01/19
[ "https://Stackoverflow.com/questions/456914", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I try to find methods that have expression createNamedQuery I try ``` public[\d\D]*?createNamedQuery ``` but it finds the first method, but i want the method that has expression createNamedQuery
I'm guessing that your problem is that you cannot find all of them, but rather just the first one. The way to retreive all of them is different from language to language. For instance, in Python, one would do something similar to the following: ``` import re my_data = "some long piece of data that may or may not cont...
456,919
<p>Dev-cpp comes with an example program Jackpot, which has a GetResults function in it:</p> <pre><code>void GetResults () { . . . else if (i&gt;j) { cout &lt;&lt; "Too BIG\n"; life = life - 1; // -1 to the user's "life" cout &lt;&lt; "Number of remaining life: " &lt;&lt;...
[ { "answer_id": 456925, "author": "schnaader", "author_id": 34065, "author_profile": "https://Stackoverflow.com/users/34065", "pm_score": 3, "selected": true, "text": "<p>This will lead to a Stack Overflow for sure, so it shouldn't be done this way! Depends on the stack size how often you...
2009/01/19
[ "https://Stackoverflow.com/questions/456919", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23684/" ]
Dev-cpp comes with an example program Jackpot, which has a GetResults function in it: ``` void GetResults () { . . . else if (i>j) { cout << "Too BIG\n"; life = life - 1; // -1 to the user's "life" cout << "Number of remaining life: " << life << "\n\n"; GetResults...
This will lead to a Stack Overflow for sure, so it shouldn't be done this way! Depends on the stack size how often you can do it, but it sure will crash. In your example, recursion depth is prevented by the number of lives, so that seems OK as this won't get bigger than 1000 or even 100, but you shouldn't use it in gen...
456,926
<p>Please tell me C++/Java code which utilize memory more than 70% .</p> <p>For Example we have 3 Virtual machine and in memory resources we want to test the<br> memory utilization as per memory resources allocated by user.</p>
[ { "answer_id": 456943, "author": "Spence", "author_id": 53771, "author_profile": "https://Stackoverflow.com/users/53771", "pm_score": 2, "selected": false, "text": "<pre><code>#include malloc.h\n#DEFINE MB 512\nvoid main(int argc, char **argv)\n{\n int i;\n for (i = 0; i &lt; MB; i...
2009/01/19
[ "https://Stackoverflow.com/questions/456926", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Please tell me C++/Java code which utilize memory more than 70% . For Example we have 3 Virtual machine and in memory resources we want to test the memory utilization as per memory resources allocated by user.
``` #include malloc.h #DEFINE MB 512 void main(int argc, char **argv) { int i; for (i = 0; i < MB; i++) { malloc(1024* 1024); } getchar(); } ``` Hit enter to release the memory, set the MB constant to how much memory you want your program to take. My C is a little rusty so if someone come...
456,932
<p>I am using a hash table in JavaScript, and I want to show the values of the following in a hash table</p> <pre><code>one -[1,10,5] two -[2] three -[3, 30, 300, etc.] </code></pre> <p>I have found the following code. It works for the following data.</p> <pre><code> one -[1] two -[2] three-[3] </code>...
[ { "answer_id": 457035, "author": "roryf", "author_id": 270, "author_profile": "https://Stackoverflow.com/users/270", "pm_score": 7, "selected": true, "text": "<p>Using the function above, you would do:</p>\n\n<pre><code>var myHash = new Hash('one',[1,10,5],'two', [2], 'three',[3,30,300])...
2009/01/19
[ "https://Stackoverflow.com/questions/456932", "https://Stackoverflow.com", "https://Stackoverflow.com/users/44984/" ]
I am using a hash table in JavaScript, and I want to show the values of the following in a hash table ``` one -[1,10,5] two -[2] three -[3, 30, 300, etc.] ``` I have found the following code. It works for the following data. ``` one -[1] two -[2] three-[3] ``` How do I assign one-[1,2] values to a ...
Using the function above, you would do: ``` var myHash = new Hash('one',[1,10,5],'two', [2], 'three',[3,30,300]); ``` Of course, the following would also work: ``` var myHash = {}; // New object myHash['one'] = [1,10,5]; myHash['two'] = [2]; myHash['three'] = [3, 30, 300]; ``` since all objects in JavaScript are ...
456,935
<p>In java a class can implement Iterable which lets you use the foreach() statement and the iteration syntatic sugar:</p> <pre><code>for(T t:ts) ... </code></pre> <p>However, this does not allow you to throw exceptions on the construction for an Iterator. If you were iterating off a network, file, database etc it wo...
[ { "answer_id": 456954, "author": "Tom", "author_id": 8969, "author_profile": "https://Stackoverflow.com/users/8969", "pm_score": 0, "selected": false, "text": "<p>I'd say you can't, even if you could you probably shouldn't. You get bytes from these things, if they were used in a for loop...
2009/01/19
[ "https://Stackoverflow.com/questions/456935", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5346/" ]
In java a class can implement Iterable which lets you use the foreach() statement and the iteration syntatic sugar: ``` for(T t:ts) ... ``` However, this does not allow you to throw exceptions on the construction for an Iterator. If you were iterating off a network, file, database etc it would be nice to be able to ...
Unfortunately you can't. There are two problems: * The Iterator API doesn't declare any exceptions to be thrown, so you'd have to throw RuntimeExceptions (or non-Exception throwables) * The enhanced for loop doesn't do anything to try to release resources at the end of the loop This is very annoying. In C#, for insta...
456,936
<p>I'm trying to configure my Terminal and I would like to insert <strong>@{}</strong> at one key-stroke. This works with the following code</p> <pre><code># .inputrc "\e\"": "@{}" </code></pre> <p>But I also want the cursor to end up inside the braces. How can I do this? The following doesn't work.</p> <pre><code>#...
[ { "answer_id": 457186, "author": "ELLIOTTCABLE", "author_id": 31897, "author_profile": "https://Stackoverflow.com/users/31897", "pm_score": 0, "selected": false, "text": "<p>My immediate way to fix your overall goal (not really answering your question, but hopefully helping you anyway): ...
2009/01/19
[ "https://Stackoverflow.com/questions/456936", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1740/" ]
I'm trying to configure my Terminal and I would like to insert **@{}** at one key-stroke. This works with the following code ``` # .inputrc "\e\"": "@{}" ``` But I also want the cursor to end up inside the braces. How can I do this? The following doesn't work. ``` # .inputrc "\e\"": "@{}": backward-char ```
Try: ``` "\e\"": "@{}\e[D" ```
456,942
<p>I have a quite simple question, I think. I've got this problem, which can be solved very easily with a recursive function, but which I wasn't able to solve iteratively.</p> <p>Suppose you have any boolean matrix, like:</p> <p>M:</p> <pre><code>111011111110 110111111100 001111111101 100111111101 110011111001 11111...
[ { "answer_id": 456955, "author": "schnaader", "author_id": 34065, "author_profile": "https://Stackoverflow.com/users/34065", "pm_score": 1, "selected": false, "text": "<p>Pseudo-code:</p>\n\n<pre><code>Input: Startpoint (x,y), Array[w][h], Fillcolor f\n\nArray[x][y] = f\nbool hasChanged ...
2009/01/19
[ "https://Stackoverflow.com/questions/456942", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have a quite simple question, I think. I've got this problem, which can be solved very easily with a recursive function, but which I wasn't able to solve iteratively. Suppose you have any boolean matrix, like: M: ``` 111011111110 110111111100 001111111101 100111111101 110011111001 111111110011 111111100111 1111100...
There is a standard technique for converting particular types of recursive algorithms into iterative ones. It is called [tail-recursion](http://en.wikipedia.org/wiki/Tail_recursion). The recursive version of this code would look like (pseudo code - without bounds checking): ``` paint(cells, i, j) { if(cells[i][j] ...
456,964
<p>I need to do user validation of a date field, it should be in the format <em>yyyyMMdd</em> and should not be more than one year in the future. How would I go about doing this? Currently I only have a crude regexp which is insufficient.</p> <pre><code>function VerifyDate(source, args) { var regexp = /^([1-2]{1}[...
[ { "answer_id": 457007, "author": "Tomalak", "author_id": 18771, "author_profile": "https://Stackoverflow.com/users/18771", "pm_score": 4, "selected": true, "text": "<p>Take the regex to check the format only. You can stay simple:</p>\n\n<pre><code>^(\\d{4})(\\d{2})(\\d{2})$\n</code></pre...
2009/01/19
[ "https://Stackoverflow.com/questions/456964", "https://Stackoverflow.com", "https://Stackoverflow.com/users/54626/" ]
I need to do user validation of a date field, it should be in the format *yyyyMMdd* and should not be more than one year in the future. How would I go about doing this? Currently I only have a crude regexp which is insufficient. ``` function VerifyDate(source, args) { var regexp = /^([1-2]{1}[0-9]{1})\d{2}([0][1-9...
Take the regex to check the format only. You can stay simple: ``` ^(\d{4})(\d{2})(\d{2})$ ``` Then parse the date and check the range: ``` function VerifyDate(source, args) { args.IsValid = false; var regexp = /^(\d{4})(\d{2})(\d{2})$/; var daysInMonth = function (y, m) {return 32-new Date(y, m, 32).getDate()...
456,966
<p>I've got a select with two 'special' options, a bit like this:</p> <pre><code>&lt;select&gt; &lt;option value="????"&gt;Choose one:&lt;/option&gt; &lt;option value="1"&gt;option1&lt;/option&gt; &lt;option value="2"&gt;option2&lt;/option&gt; .... &lt;option value="????"&gt;Free input&lt;/option&gt; &lt;/selec...
[ { "answer_id": 456973, "author": "Boris Pavlović", "author_id": 32090, "author_profile": "https://Stackoverflow.com/users/32090", "pm_score": 3, "selected": true, "text": "<p>I would use something that will be understandable to the next developer who will be reading the code. Therefore s...
2009/01/19
[ "https://Stackoverflow.com/questions/456966", "https://Stackoverflow.com", "https://Stackoverflow.com/users/909/" ]
I've got a select with two 'special' options, a bit like this: ``` <select> <option value="????">Choose one:</option> <option value="1">option1</option> <option value="2">option2</option> .... <option value="????">Free input</option> </select> ``` When the user selects nothing, I should ignore the input. When...
I would use something that will be understandable to the next developer who will be reading the code. Therefore something like 'freeInput' or 'textFieldLookupValue' could be appropriate
456,967
<p>I have a pretty good understanding of Javascript, except that I can't figure out a nice way to set the "this" variable. Consider:</p> <pre><code>var myFunction = function(){ alert(this.foo_variable); } var someObj = document.body; //using body as example object someObj.foo_variable = "hi"; //set foo_variable ...
[ { "answer_id": 456989, "author": "sth", "author_id": 56338, "author_profile": "https://Stackoverflow.com/users/56338", "pm_score": 6, "selected": false, "text": "<p>I think you're looking for <a href=\"https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/call\" r...
2009/01/19
[ "https://Stackoverflow.com/questions/456967", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have a pretty good understanding of Javascript, except that I can't figure out a nice way to set the "this" variable. Consider: ``` var myFunction = function(){ alert(this.foo_variable); } var someObj = document.body; //using body as example object someObj.foo_variable = "hi"; //set foo_variable so it alerts v...
There are two methods defined for all functions in JavaScript, [`call()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call), and [`apply()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply). The function syntax looks like: ``...
456,978
<p>I'm developing a Flex 2 application, and I noticed that part of the library which is responsible for moving GUI windows (<code>TitleWindow</code>s) around when you drag them with the mouse gets confused if there is a clickable (<code>buttonMode = true</code>) sprite beneath them. When I say confused, I mean that the...
[ { "answer_id": 456989, "author": "sth", "author_id": 56338, "author_profile": "https://Stackoverflow.com/users/56338", "pm_score": 6, "selected": false, "text": "<p>I think you're looking for <a href=\"https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/call\" r...
2009/01/19
[ "https://Stackoverflow.com/questions/456978", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42136/" ]
I'm developing a Flex 2 application, and I noticed that part of the library which is responsible for moving GUI windows (`TitleWindow`s) around when you drag them with the mouse gets confused if there is a clickable (`buttonMode = true`) sprite beneath them. When I say confused, I mean that the window is moved around n...
There are two methods defined for all functions in JavaScript, [`call()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call), and [`apply()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply). The function syntax looks like: ``...
457,003
<p>I have a rather large project which contains a number of third-party dependencies which are linked via svn:externals. These include tomcat and blazeDS, which are packaged by our installer via ant. The problem is that these projects contain dozens of sample JSP pages, and eclipse chokes on them when trying to build...
[ { "answer_id": 457008, "author": "Michael Borgwardt", "author_id": 16883, "author_profile": "https://Stackoverflow.com/users/16883", "pm_score": 1, "selected": false, "text": "<p>It could be that your eclipse project is configured to have extra Builders. You can check that in the project...
2009/01/19
[ "https://Stackoverflow.com/questions/457003", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14302/" ]
I have a rather large project which contains a number of third-party dependencies which are linked via svn:externals. These include tomcat and blazeDS, which are packaged by our installer via ant. The problem is that these projects contain dozens of sample JSP pages, and eclipse chokes on them when trying to build the ...
I usually have this kind of issue with CheckStyle plugin, where you need to specify in its properties (right-click on project -> Properties -> CheckStyle): "Exclude from check Files non located in a source directory" Otherwise it does analyze (and reports warning/errors on) files which are not candidate to be compile...
457,014
<p>One thing that's always confused me is input escaping and whether or not you're protected from attacks like SQL injection.</p> <p>Say I have a form which sends data using HTTP POST to a PHP file. I type the following in an input field and submit the form:</p> <pre><code>"Hello", said Jimmy O'Toole. </code></pre> ...
[ { "answer_id": 457018, "author": "chakrit", "author_id": 3055, "author_profile": "https://Stackoverflow.com/users/3055", "pm_score": 0, "selected": false, "text": "<p>Obvious is the keyword for a hacker.</p>\n\n<p>I think escaping normally should be enough, but protecting against <em>jus...
2009/01/19
[ "https://Stackoverflow.com/questions/457014", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21709/" ]
One thing that's always confused me is input escaping and whether or not you're protected from attacks like SQL injection. Say I have a form which sends data using HTTP POST to a PHP file. I type the following in an input field and submit the form: ``` "Hello", said Jimmy O'Toole. ``` If you print/echo the input on...
Ah, the wonders of [magic quotes](http://php.net/magic_quotes). It is making those unnecessary escapes from your POST forms. You should disable (or neutralize) them, and many of your headaches go away. Here's an exemplary article of the subject: <http://www.sitepoint.com/blogs/2005/03/02/magic-quotes-headaches/> Reca...
457,036
<p>One of Steve McConnell's checklist items is that <a href="http://www.matthewjmiller.net/files/cc2e_checklists.pdf" rel="nofollow noreferrer">you should not monkey with the loop index</a> (Chapter 16, page 25, <em>Loop Indexes</em>, PDF format).</p> <p>This makes intuitive sense and is a practice I've always followe...
[ { "answer_id": 457046, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 5, "selected": false, "text": "<p>Well, this adds confusion for little purpose - you could just as easily write:</p>\n\n<pre><code>while(MyControl.T...
2009/01/19
[ "https://Stackoverflow.com/questions/457036", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4200/" ]
One of Steve McConnell's checklist items is that [you should not monkey with the loop index](http://www.matthewjmiller.net/files/cc2e_checklists.pdf) (Chapter 16, page 25, *Loop Indexes*, PDF format). This makes intuitive sense and is a practice I've always followed except maybe as I learned how to program back in the...
I think your articulation is great. Maybe it can be worded like so: > > Since the logic can be expressed much > clearer, it should. > > >
457,040
<pre><code>string strLine;//not constant int index = 0; while(index &lt; strLine.length()){//strLine is not modified}; </code></pre> <p>how many times <code>strLine.length()</code> is evaluated</p> <p>do we need to put use <code>nLength</code> with <code>nLength</code> assigned to <code>strLine.length()</code> just b...
[ { "answer_id": 457049, "author": "Greg", "author_id": 24181, "author_profile": "https://Stackoverflow.com/users/24181", "pm_score": -1, "selected": false, "text": "<p><code>strLine.length()</code> will be evaluated every time you go around the loop.</p>\n\n<p>You're correct in that it wo...
2009/01/19
[ "https://Stackoverflow.com/questions/457040", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22076/" ]
``` string strLine;//not constant int index = 0; while(index < strLine.length()){//strLine is not modified}; ``` how many times `strLine.length()` is evaluated do we need to put use `nLength` with `nLength` assigned to `strLine.length()` just before loop
`length` will be evaluated every time you go via the loop, however since `length` is constant time (`O(1)`) it doesn't make much difference and adding a variable for storing this value will probably have a negligible effect with a small hit on code readability (as well as breaking the code if the string is ever changed...
457,044
<p>I want to seal of classes in a namespace. I was looking at the "internal" access modifier, but this only seems to seal of classes in an assembly. Can I seal of classes in a namespace?</p> <p>Or do I have to move stuff into an seperate assembly? But then I will have the problem of visual studio refusing circular as...
[ { "answer_id": 457061, "author": "Patrik Svensson", "author_id": 936, "author_profile": "https://Stackoverflow.com/users/936", "pm_score": 0, "selected": false, "text": "<p>You can still use the internal keyword and expose the internal classes to another assembly via the <a href=\"http:/...
2009/01/19
[ "https://Stackoverflow.com/questions/457044", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I want to seal of classes in a namespace. I was looking at the "internal" access modifier, but this only seems to seal of classes in an assembly. Can I seal of classes in a namespace? Or do I have to move stuff into an seperate assembly? But then I will have the problem of visual studio refusing circular assembly refe...
It is not possible with C#. **Namespace-level members can only be either `public` or `internal`** You can however, use nested class in C# ``` namespace A { public class B { protected class C { } } public class D { void E() { var F = new A.B(); // ok! var G = ...
457,050
<p>Trying to create a small monitor application that displays current internet usage as percentage in system tray in C using win32 API. </p> <p>Also wanting to use colour background or colour text based on how much is used relative to days left in month.</p> <p><strong>EDIT:</strong> To clarify I am wanting the syste...
[ { "answer_id": 457072, "author": "João Augusto", "author_id": 6909, "author_profile": "https://Stackoverflow.com/users/6909", "pm_score": 2, "selected": false, "text": "<p>By text you mean \"Tips\" ?</p>\n\n<p>Assuming you have your icon on the System Tray</p>\n\n<pre><code>NOTIFYICONDAT...
2009/01/19
[ "https://Stackoverflow.com/questions/457050", "https://Stackoverflow.com", "https://Stackoverflow.com/users/486/" ]
Trying to create a small monitor application that displays current internet usage as percentage in system tray in C using win32 API. Also wanting to use colour background or colour text based on how much is used relative to days left in month. **EDIT:** To clarify I am wanting the system tray icon to be dynamic. As ...
Okay here is my win32 solution: ``` HICON CreateSmallIcon( HWND hWnd ) { static TCHAR *szText = TEXT ( "100" ); HDC hdc, hdcMem; HBITMAP hBitmap = NULL; HBITMAP hOldBitMap = NULL; HBITMAP hBitmapMask = NULL; ICONINFO iconInfo; HFONT hFont; HICON hIcon; hdc = GetDC ( hWnd ); hdc...
457,054
<p>I have to disable chinese, japanese, cyrillic (and so on) alphabets to be entered by users in my website, at validation time (only server side validation). At the same time I want all latin accented characters to be allowed. I use symfony 1.1 and PHP 5.2, using utf-8, of course. Any hint?</p>
[ { "answer_id": 457219, "author": "troelskn", "author_id": 18180, "author_profile": "https://Stackoverflow.com/users/18180", "pm_score": 1, "selected": false, "text": "<p>You can always convert to latin1 and then back again. That would discard any non latin1 characters. Eg.:</p>\n\n<pre><...
2009/01/19
[ "https://Stackoverflow.com/questions/457054", "https://Stackoverflow.com", "https://Stackoverflow.com/users/56620/" ]
I have to disable chinese, japanese, cyrillic (and so on) alphabets to be entered by users in my website, at validation time (only server side validation). At the same time I want all latin accented characters to be allowed. I use symfony 1.1 and PHP 5.2, using utf-8, of course. Any hint?
You can always convert to latin1 and then back again. That would discard any non latin1 characters. Eg.: ``` $str = utf8_encode(utf8_decode($str)); ``` I wonder why you want this in the first place though?
457,069
<p>How do I get the current GLOBAL mouse cursor type (hourglass/arrow/..)? In Windows.</p> <p>Global - I need it <strong>even if the mouse is ouside of my application</strong> or even if my program is windlowless.</p> <p>In C#, Delphi or pure winapi, nevermind...</p> <p>Thank you very much in advance!!</p>
[ { "answer_id": 457083, "author": "Toon Krijthe", "author_id": 18061, "author_profile": "https://Stackoverflow.com/users/18061", "pm_score": 2, "selected": false, "text": "<p>Use (in Delphi)</p>\n\n<pre><code>Screen.MouseCursor.\n</code></pre>\n\n<p>For the current mouse cursor.</p>\n\n<p...
2009/01/19
[ "https://Stackoverflow.com/questions/457069", "https://Stackoverflow.com", "https://Stackoverflow.com/users/56621/" ]
How do I get the current GLOBAL mouse cursor type (hourglass/arrow/..)? In Windows. Global - I need it **even if the mouse is ouside of my application** or even if my program is windlowless. In C#, Delphi or pure winapi, nevermind... Thank you very much in advance!!
After thee years its time to answer my own question. Here's how you check if the current global cursor is hourglass in C# (extend the code for you own needs if you need): ``` private static bool IsWaitCursor() { var h = Cursors.WaitCursor.Handle; CURSORINFO pci; pci.cbSize = Marshal.SizeOf(typeof(CURSORIN...
457,070
<p>I am using <code>&lt;a&gt;</code> tags for links on a web page. How do I disable the <kbd>Tab</kbd> key from selecting either of them?</p>
[ { "answer_id": 457075, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "<p>Try</p>\n\n<pre><code>&lt;a onfocus=\"this.blur();\" href = \"bla\"&gt;Bla&lt;/a&gt;\n</code></pre>\n" }, { "answer...
2009/01/19
[ "https://Stackoverflow.com/questions/457070", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50851/" ]
I am using `<a>` tags for links on a web page. How do I disable the `Tab` key from selecting either of them?
**EDIT:** Hi, original author of this answer here. Don't use this one. Scroll down. StackOverflow won't let me remove this answer since it was accepted. --- You could do something like this for those links: ``` <a href="http://foo.bar" onfocus="this.blur()">Can't focus on this!</a> ``` You should use the answer b...
457,120
<p>The question is as simple as stated in the title: What's the difference between the following two expressions?</p> <pre><code>$(...) `...` </code></pre> <p>For example, are the two variables <code>test1</code> and <code>test2</code> different?</p> <pre><code>test1=$(ls) test2=`ls` </code></pre>
[ { "answer_id": 457135, "author": "unwind", "author_id": 28169, "author_profile": "https://Stackoverflow.com/users/28169", "pm_score": 4, "selected": true, "text": "<p>The result is the same, but the newer $() syntax is far clearer and easier to read. At least doubly so when trying to nes...
2009/01/19
[ "https://Stackoverflow.com/questions/457120", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51634/" ]
The question is as simple as stated in the title: What's the difference between the following two expressions? ``` $(...) `...` ``` For example, are the two variables `test1` and `test2` different? ``` test1=$(ls) test2=`ls` ```
The result is the same, but the newer $() syntax is far clearer and easier to read. At least doubly so when trying to nest. Nesting is not easy with the old syntax, but works fine with the new. Compare: ``` $ echo $(ls $(pwd)) ``` versus: ``` $ echo `ls \`pwd\`` ``` You need to escape the embedded backticks, so ...
457,134
<p>I encountered a, at least to my expectations, strange behavior in the binary serialization of .NET.</p> <p>All items of a <code>Dictionary</code> that are loaded are added to their parent AFTER the <code>OnDeserialization</code> callback. In contrast <code>List</code> does the other way. This can be really annoying...
[ { "answer_id": 457203, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 2, "selected": false, "text": "<p>Interesting... for info, I tried it with the attribute-based approach (below), and it behaves the same... very cur...
2009/01/19
[ "https://Stackoverflow.com/questions/457134", "https://Stackoverflow.com", "https://Stackoverflow.com/users/47694/" ]
I encountered a, at least to my expectations, strange behavior in the binary serialization of .NET. All items of a `Dictionary` that are loaded are added to their parent AFTER the `OnDeserialization` callback. In contrast `List` does the other way. This can be really annoying in real world repository code, for example...
I can reproduce the problem. Had a look around Google and found this: <http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=94265> although I'm not sure it's the exact same problem, it seems pretty similar. EDIT: I think that adding this code may have fixed the problem? ``` public void...
457,153
<p>My question is best phrase as: <a href="https://stackoverflow.com/questions/262351/remove-a-child-with-a-specific-attribute-in-simplexml-for-php">Remove a child with a specific attribute, in SimpleXML for PHP</a></p> <p>except I'm not using simpleXML.</p> <p>I'm new to XML for PHP so I may not be doing the best wa...
[ { "answer_id": 457197, "author": "Gumbo", "author_id": 53114, "author_profile": "https://Stackoverflow.com/users/53114", "pm_score": 1, "selected": false, "text": "<p>So you want to remove the <code>category</code> node with a specific <code>id</code>? </p>\n\n<pre><code>$node = $xmlDoc...
2009/01/19
[ "https://Stackoverflow.com/questions/457153", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
My question is best phrase as: [Remove a child with a specific attribute, in SimpleXML for PHP](https://stackoverflow.com/questions/262351/remove-a-child-with-a-specific-attribute-in-simplexml-for-php) except I'm not using simpleXML. I'm new to XML for PHP so I may not be doing the best way I have a xml created usin...
Ok, let’s try this complete example of use: ``` function CatRemove($myXML, $id) { $xmlDoc = new DOMDocument(); $xmlDoc->load($myXML); $xpath = new DOMXpath($xmlDoc); $nodeList = $xpath->query('//category[@id="'.(int)$id.'"]'); if ($nodeList->length) { $node = $nodeList->item(0); $no...
457,157
<p>I'm looking for a calendar control (<a href="http://en.wiktionary.org/wiki/AKA" rel="nofollow noreferrer">AKA</a> date-picker) that works on mobile devices. The problem is most devices are without JavaScript, or with poor JavaScript support.</p> <p><a href="http://en.wikipedia.org/wiki/ASP.NET" rel="nofollow norefe...
[ { "answer_id": 457197, "author": "Gumbo", "author_id": 53114, "author_profile": "https://Stackoverflow.com/users/53114", "pm_score": 1, "selected": false, "text": "<p>So you want to remove the <code>category</code> node with a specific <code>id</code>? </p>\n\n<pre><code>$node = $xmlDoc...
2009/01/19
[ "https://Stackoverflow.com/questions/457157", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6827/" ]
I'm looking for a calendar control ([AKA](http://en.wiktionary.org/wiki/AKA) date-picker) that works on mobile devices. The problem is most devices are without JavaScript, or with poor JavaScript support. [ASP.NET](http://en.wikipedia.org/wiki/ASP.NET)'s built-in control uses JavaScript to do post-backs. ASP.NET has a...
Ok, let’s try this complete example of use: ``` function CatRemove($myXML, $id) { $xmlDoc = new DOMDocument(); $xmlDoc->load($myXML); $xpath = new DOMXpath($xmlDoc); $nodeList = $xpath->query('//category[@id="'.(int)$id.'"]'); if ($nodeList->length) { $node = $nodeList->item(0); $no...
457,160
<p>Input:</p> <p>1) A huge sorted array of string SA;</p> <p>2) A prefix string P;</p> <p>Output:</p> <p>The index of the first string matching the input prefix if any. If there is no such match, then output will be -1.</p> <p>Example:</p> <pre><code>SA = {"ab", "abd", "abdf", "abz"} P = "abd" </code></pre> <p>T...
[ { "answer_id": 457163, "author": "Keltia", "author_id": 16143, "author_profile": "https://Stackoverflow.com/users/16143", "pm_score": 1, "selected": false, "text": "<p>The FreeBSD kernel use a <a href=\"http://en.wikipedia.org/wiki/Radix_tree\" rel=\"nofollow noreferrer\">Radix tree</a> ...
2009/01/19
[ "https://Stackoverflow.com/questions/457160", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26349/" ]
Input: 1) A huge sorted array of string SA; 2) A prefix string P; Output: The index of the first string matching the input prefix if any. If there is no such match, then output will be -1. Example: ``` SA = {"ab", "abd", "abdf", "abz"} P = "abd" ``` The output should be 1 (index starting from 0). What's the mo...
If you only want to do this once, use [binary search](http://en.wikipedia.org/wiki/Binary_search), if on the other hand you need to do it for many different prefixes but on the same string array, building a [radix tree](http://en.wikipedia.org/wiki/Radix_tree) can be a good idea, after you've built the tree each look u...
457,166
<p>I have problem compilin this code..can anyone tell whats wrong with the syntax</p> <pre><code>CREATE PROCEDURE spGenericInsert ( @insValueStr nvarchar(200) @tblName nvarchar(10) ) AS BEGIN DECLARE @insQueryStr nvarchar(400) DECLARE @insPrimaryKey nvarchar(10) DECLARE @rowCo...
[ { "answer_id": 457178, "author": "Jonathan Lonowski", "author_id": 15031, "author_profile": "https://Stackoverflow.com/users/15031", "pm_score": 2, "selected": false, "text": "<p>Take your pick:</p>\n\n<ul>\n<li><code>@TableName</code> isn't defined</li>\n<li><code>@tblName</code> vs. <c...
2009/01/19
[ "https://Stackoverflow.com/questions/457166", "https://Stackoverflow.com", "https://Stackoverflow.com/users/56631/" ]
I have problem compilin this code..can anyone tell whats wrong with the syntax ``` CREATE PROCEDURE spGenericInsert ( @insValueStr nvarchar(200) @tblName nvarchar(10) ) AS BEGIN DECLARE @insQueryStr nvarchar(400) DECLARE @insPrimaryKey nvarchar(10) DECLARE @rowCountVal integer...
I cannot immediately see what's wrong with the syntax ([the sharp eye of Jonathan Lonowski has solved that already](https://stackoverflow.com/questions/457166/problem-with-code-syntax-stored-procedure-for-generic-insert#457178)), but there are some things wrong with the code: 1. You create dynamic SQL, so your code is...
457,176
<p>I have an application written in c# that cannot run on a public holiday or a weekend. I've looked around a bit and haven't found anywhere (official) that provides all the public holidays for the next say 50 years. </p> <p>If I can get these, I will simply bulk insert them into my sql server Holidays table and use...
[ { "answer_id": 457182, "author": "Yuval Adam", "author_id": 24545, "author_profile": "https://Stackoverflow.com/users/24545", "pm_score": 3, "selected": false, "text": "<p>Isn't a public holiday very dependent of locale?</p>\n\n<p>Programatically, there is no way to <em>compute</em> this...
2009/01/19
[ "https://Stackoverflow.com/questions/457176", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11989/" ]
I have an application written in c# that cannot run on a public holiday or a weekend. I've looked around a bit and haven't found anywhere (official) that provides all the public holidays for the next say 50 years. If I can get these, I will simply bulk insert them into my sql server Holidays table and use that. Howev...
I just gather information over the internet and I come with this easy way to calculate the US Bank Holidays. --- US Bank Holidays ---------------- =========================== --------------------------- ``` DECLARE @Year char(4) , @Date datetime , @Holiday datetime SET @Year = 2010 ---- New Years Day SET @Date=CO...
457,183
<p>I am trying to implement the code given for "jQuery Autocomplete and ASP.NET", but unable to integrate it because you are using subsonic to query database.</p> <p>So can you tell me how to query sqldatabase and bind the query result to the plugin from webservice in asp.net using C#?</p>
[ { "answer_id": 457224, "author": "mP.", "author_id": 56524, "author_profile": "https://Stackoverflow.com/users/56524", "pm_score": -1, "selected": false, "text": "<p>I am not fluent in asp.net but fundamentally like most web coding questions this involves breaking your problem into small...
2009/01/19
[ "https://Stackoverflow.com/questions/457183", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I am trying to implement the code given for "jQuery Autocomplete and ASP.NET", but unable to integrate it because you are using subsonic to query database. So can you tell me how to query sqldatabase and bind the query result to the plugin from webservice in asp.net using C#?
This is a pretty easy task, the catch is that the jQuery autocomplete extender expects an array of values. Here is example of how I parse the standard XML results from a ASMX web serivce to use with the jQuery autocomplete extender. Since ASP.NET likes to rewrite your ID's, you can pass in the ClientID to get the dyna...
457,193
<p>I need to create a database column which will store a string encrypted using Triple DES. How do I determine the length of the encrypted string column?</p> <p>(Answers for algorithms other than Triple DES are also welcome.)</p>
[ { "answer_id": 457202, "author": "Yuval Adam", "author_id": 24545, "author_profile": "https://Stackoverflow.com/users/24545", "pm_score": 1, "selected": false, "text": "<p><a href=\"http://en.wikipedia.org/wiki/Triple_DES\" rel=\"nofollow noreferrer\">Triple DES</a> uses three 56-bit DES...
2009/01/19
[ "https://Stackoverflow.com/questions/457193", "https://Stackoverflow.com", "https://Stackoverflow.com/users/45603/" ]
I need to create a database column which will store a string encrypted using Triple DES. How do I determine the length of the encrypted string column? (Answers for algorithms other than Triple DES are also welcome.)
Block-ciphers such as DES, 3DES and AES can only operate on blocks of bytes. DES and 3DES operate on block of 8 bytes and AES on blocks of 16 bytes. To handle this, you usually apply a reversible padding to your plaintext before encrypting it. It will mostly always be "PKCS"-padding (also called PKCS5- or PKCS7-paddin...
457,207
<p>I was wondering if anyone had any experience in working programmatically with .pdf files. I have a .pdf file and I need to crop every page down to a certain size.</p> <p>After a quick Google search I found the pyPdf library for python but my experiments with it failed. When I changed the cropBox and trimBox attribu...
[ { "answer_id": 458189, "author": "Ned Batchelder", "author_id": 14343, "author_profile": "https://Stackoverflow.com/users/14343", "pm_score": 1, "selected": false, "text": "<p>You are probably looking for a free solution, but if you have money to spend, <a href=\"http://pdflib.com\" rel=...
2009/01/19
[ "https://Stackoverflow.com/questions/457207", "https://Stackoverflow.com", "https://Stackoverflow.com/users/367099/" ]
I was wondering if anyone had any experience in working programmatically with .pdf files. I have a .pdf file and I need to crop every page down to a certain size. After a quick Google search I found the pyPdf library for python but my experiments with it failed. When I changed the cropBox and trimBox attributes on a p...
[pyPdf](https://pypi.org/project/pyPdf/) does what I expect in this area. Using the following script: ``` #!/usr/bin/python # from pyPdf import PdfFileWriter, PdfFileReader with open("in.pdf", "rb") as in_f: input1 = PdfFileReader(in_f) output = PdfFileWriter() numPages = input1.getNumPages() print ...
457,215
<p>If I have sequence of sequences (maybe a list of tuples) I can use itertools.chain() to flatten it. But sometimes I feel like I would rather write it as a comprehension. I just can't figure out how to do it. Here's a very construed case:</p> <p>Let's say I want to swap the elements of every pair in a sequence. I us...
[ { "answer_id": 457227, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "<p>You could use reduce to achive your goal:</p>\n\n<pre><code>In [6]: import operator\nIn [7]: a = [(1, 2), (2,3), (4,5)]\nIn...
2009/01/19
[ "https://Stackoverflow.com/questions/457215", "https://Stackoverflow.com", "https://Stackoverflow.com/users/44639/" ]
If I have sequence of sequences (maybe a list of tuples) I can use itertools.chain() to flatten it. But sometimes I feel like I would rather write it as a comprehension. I just can't figure out how to do it. Here's a very construed case: Let's say I want to swap the elements of every pair in a sequence. I use a string...
With a comprehension? Well... ``` >>> seq = '012345' >>> swapped_pairs = zip(seq[1::2], seq[::2]) >>> ''.join(item for pair in swapped_pairs for item in pair) '103254' ```
457,225
<p>It is possible to generate a C++ header file from a C# interface?</p> <p>Example:</p> <h3>C# Interface:</h3> <pre><code>public interface A { void M( ushort u ); } </code></pre> <h3>C++ header:</h3> <pre><code>public ref class B : A { void M( unsigned short u ); } </code></pre> <p>Returns "Error C3...
[ { "answer_id": 457226, "author": "Kent Boogaart", "author_id": 5380, "author_profile": "https://Stackoverflow.com/users/5380", "pm_score": 2, "selected": true, "text": "<p>If you map the .xaml extension to the standard XML editor this problem will be solved along with others such as the ...
2009/01/19
[ "https://Stackoverflow.com/questions/457225", "https://Stackoverflow.com", "https://Stackoverflow.com/users/45320/" ]
It is possible to generate a C++ header file from a C# interface? Example: ### C# Interface: ``` public interface A { void M( ushort u ); } ``` ### C++ header: ``` public ref class B : A { void M( unsigned short u ); } ``` Returns "Error C3766".
If you map the .xaml extension to the standard XML editor this problem will be solved along with others such as the poor performance of the XAML editor. Tools / Options / Text Editor / File Extension
457,229
<p>I have a cache which has soft references to the cached objects. I am trying to write a functional test for behavior of classes which use the cache specifically for what happens when the cached objects are cleared.</p> <p>The problem is: I can't seem to reliably get the soft references to be cleared. Simply using up...
[ { "answer_id": 457269, "author": "mP.", "author_id": 56524, "author_profile": "https://Stackoverflow.com/users/56524", "pm_score": 1, "selected": false, "text": "<p>Garbage collection and other references like soft references are non deterministic this it's not really possible to reliabl...
2009/01/19
[ "https://Stackoverflow.com/questions/457229", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6583/" ]
I have a cache which has soft references to the cached objects. I am trying to write a functional test for behavior of classes which use the cache specifically for what happens when the cached objects are cleared. The problem is: I can't seem to reliably get the soft references to be cleared. Simply using up a bunch o...
> > The problem is: I can't seem to > reliably get the soft references to be > cleared. > > > This is not unique to SoftReferences. Due to the nature of garbage collection in Java, there is no guarantee that anything that is garbage-collectable will actually be collected at any point in time. Even with a simple ...
457,237
<p>I currently trying to write a component where some parts of it should run on the UI thread (explanation would be to long). So the easiest way would be to pass a control to it, and use InvokeRequired/Invoke on it. But I don't think that it is a good design to pass a control reference to a "data/background"-component,...
[ { "answer_id": 462896, "author": "Dour High Arch", "author_id": 22437, "author_profile": "https://Stackoverflow.com/users/22437", "pm_score": 2, "selected": false, "text": "<p>You are right, it is not good to pass controls to threads. Winforms controls are single-threaded, passing them t...
2009/01/19
[ "https://Stackoverflow.com/questions/457237", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24756/" ]
I currently trying to write a component where some parts of it should run on the UI thread (explanation would be to long). So the easiest way would be to pass a control to it, and use InvokeRequired/Invoke on it. But I don't think that it is a good design to pass a control reference to a "data/background"-component, so...
There's a better, more abstract way to do this that works on both WinForms and WPF: ``` System.Threading.SynchronizationContext.Current.Post(theMethod, state); ``` This works because WindowsForms installs a [`WindowsFormsSynchronizationContext`](http://msdn.microsoft.com/en-us/library/system.windows.forms.windowsfor...
457,239
<p>For example, if I have a user model and I need to validate login only (which can happen when validating a form via ajax), it would be great if I use the same model validations defined in the User model without actually instantiating a User instance.</p> <p>So in the controller I'd be able to write code like</p> <p...
[ { "answer_id": 457313, "author": "Milan Novota", "author_id": 26123, "author_profile": "https://Stackoverflow.com/users/26123", "pm_score": 5, "selected": true, "text": "<p>Since validations operate on instances (and they use the errors attribute of an instance as a container for error m...
2009/01/19
[ "https://Stackoverflow.com/questions/457239", "https://Stackoverflow.com", "https://Stackoverflow.com/users/56640/" ]
For example, if I have a user model and I need to validate login only (which can happen when validating a form via ajax), it would be great if I use the same model validations defined in the User model without actually instantiating a User instance. So in the controller I'd be able to write code like ``` User.valid_a...
Since validations operate on instances (and they use the errors attribute of an instance as a container for error messages), you can't use them without having the object instantiated. Having said that, you can hide this needed behaviour into a class method: ``` class User < ActiveRecord::Base def self.valid_attribut...
457,243
<p>How do I do this in linq?</p> <pre><code>var p = new pmaker(); foreach (var item in itemlist) { var dlist = new List&lt;Dummy&gt;(); foreach (var example in item.examples) { dlist.Add(example.GetDummy()); } p.AddStuff(item.X,item.Y,dlist); } // .. do stuff with p </code></pre>
[ { "answer_id": 457264, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 4, "selected": true, "text": "<p>How about:</p>\n\n<pre><code>var qry = from item in itemlist\n select new {item.X, item.Y,\n ...
2009/01/19
[ "https://Stackoverflow.com/questions/457243", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17413/" ]
How do I do this in linq? ``` var p = new pmaker(); foreach (var item in itemlist) { var dlist = new List<Dummy>(); foreach (var example in item.examples) { dlist.Add(example.GetDummy()); } p.AddStuff(item.X,item.Y,dlist); } // .. do stuff with p ```
How about: ``` var qry = from item in itemlist select new {item.X, item.Y, Dummies = item.examples.Select( ex => ex.GetDummy()) }; foreach (var item in qry) { p.AddStuff(item.X, item.Y, item.Dummies.ToList()); } ``` Not sure it is much clearer like this, though.....
457,246
<p>I would like to show a real time graph with one or two curves an up to 50 samples per second using Python and wxPython. The widget should support both Win32 and Linux platforms.</p> <p>Any hints are welcome.</p> <p>Edited to add:</p> <p>I don't need to update the display at 50 fps, but up need to show up to 50 s...
[ { "answer_id": 457310, "author": "nikow", "author_id": 11992, "author_profile": "https://Stackoverflow.com/users/11992", "pm_score": 0, "selected": false, "text": "<p>Maybe <a href=\"http://code.enthought.com/chaco/\" rel=\"nofollow noreferrer\">Chaco</a>? I don't know if it can do 50 fr...
2009/01/19
[ "https://Stackoverflow.com/questions/457246", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11527/" ]
I would like to show a real time graph with one or two curves an up to 50 samples per second using Python and wxPython. The widget should support both Win32 and Linux platforms. Any hints are welcome. Edited to add: I don't need to update the display at 50 fps, but up need to show up to 50 samples of data on both cu...
If you want high performance with a minimal code footprint, look no farther than Python's built-in plotting library tkinter. No need to write special C / C++ code or use a large plotting package to get performance much better than 50 fps. ![Screenshot](https://i.stack.imgur.com/CGK8y.png) The following code scrolls a...
457,257
<p>I've been struggling with this one SQL query requirement today that I was wondering if someone could help me with.</p> <p>I have a table of sports questions. One of the columns is the team related to the question. My requirement is to return a set number of random questions where the teams are unique.</p> <p>So le...
[ { "answer_id": 457285, "author": "William", "author_id": 52486, "author_profile": "https://Stackoverflow.com/users/52486", "pm_score": 1, "selected": false, "text": "<p>This should do what you need, in oracle; for a different database you'll need to use their random number source, obviou...
2009/01/19
[ "https://Stackoverflow.com/questions/457257", "https://Stackoverflow.com", "https://Stackoverflow.com/users/202/" ]
I've been struggling with this one SQL query requirement today that I was wondering if someone could help me with. I have a table of sports questions. One of the columns is the team related to the question. My requirement is to return a set number of random questions where the teams are unique. So lets say we have th...
for sql 2005 you can do this: ``` select top 5 * from ( select ROW_NUMBER() over(partition by team order by team) as RN, * from @t ) t where RN = 1 order by NEWID() ```
457,263
<p>I know it's generally a bad idea to do queries like this:</p> <pre><code>SELECT * FROM `group_relations` </code></pre> <p>But when I just want the count, should I go for this query since that allows the table to change but still yields the same results.</p> <pre><code>SELECT COUNT(*) FROM `group_relations` </code...
[ { "answer_id": 457270, "author": "Sebastian Dietz", "author_id": 52837, "author_profile": "https://Stackoverflow.com/users/52837", "pm_score": 5, "selected": false, "text": "<p>If I remember it right, in MYSQL COUNT(*) counts all rows, whereas COUNT(column_name) counts only the rows that...
2009/01/19
[ "https://Stackoverflow.com/questions/457263", "https://Stackoverflow.com", "https://Stackoverflow.com/users/914/" ]
I know it's generally a bad idea to do queries like this: ``` SELECT * FROM `group_relations` ``` But when I just want the count, should I go for this query since that allows the table to change but still yields the same results. ``` SELECT COUNT(*) FROM `group_relations` ``` Or the more specfic ``` SELECT COUNT...
If the column in question is NOT NULL, both of your queries are equivalent. When group\_id contains null values, ``` select count(*) ``` will count all rows, whereas ``` select count(group_id) ``` will only count the rows where group\_id is not null. Also, some database systems, like MySQL employ an optimizatio...
457,276
<p>How do I create test suites with JUnit 4?</p> <p>All the documentation I've seen doesn't seem to be working for me. And if I use the Eclipse wizard it doesn't give me an option to select any of the test classes I have created.</p>
[ { "answer_id": 457291, "author": "duffymo", "author_id": 37213, "author_profile": "https://Stackoverflow.com/users/37213", "pm_score": 3, "selected": false, "text": "<p>I think TestSuite has fallen out of favor. That might have been the style before 4.x, but it's not now as far as I kno...
2009/01/19
[ "https://Stackoverflow.com/questions/457276", "https://Stackoverflow.com", "https://Stackoverflow.com/users/52116/" ]
How do I create test suites with JUnit 4? All the documentation I've seen doesn't seem to be working for me. And if I use the Eclipse wizard it doesn't give me an option to select any of the test classes I have created.
``` import org.junit.runners.Suite; import org.junit.runner.RunWith; @RunWith(Suite.class) @Suite.SuiteClasses({TestClass1.class, TestClass2.class}) public class TestSuite { //nothing } ```
457,290
<p>Is there any possible way to convert the MySQL object into criteria object? I tried this query:</p> <pre><code>select p.disrepid, p.subject, p.body, c.disrepid as disrepid1, c.subject as subject1, c.body as body1 from discusreply as p, discusreply as c where p.distopid=' . $this-&gt;id . ' and (...
[ { "answer_id": 458196, "author": "sig11", "author_id": 3269, "author_profile": "https://Stackoverflow.com/users/3269", "pm_score": 2, "selected": false, "text": "<p><a href=\"http://propel.jondh.me.uk/\" rel=\"nofollow noreferrer\">This site</a> will help a lot for learning to write crit...
2009/01/19
[ "https://Stackoverflow.com/questions/457290", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Is there any possible way to convert the MySQL object into criteria object? I tried this query: ``` select p.disrepid, p.subject, p.body, c.disrepid as disrepid1, c.subject as subject1, c.body as body1 from discusreply as p, discusreply as c where p.distopid=' . $this->id . ' and (c.disrepid = p.pa...
You can use your own SQL do perform a query, but there is no automated way to turn sql into a Criteria object. ``` $con = Propel::getConnection(DATABASE_NAME); $sql = "SELECT books.* FROM books WHERE NOT EXISTS (SELECT id FROM review WHERE book_id = book.id)"; $stmt = $con->createStatement(); $rs = $stmt->execut...
457,307
<p>I am trying to progamrtaiclly allow write access to ASPNET account on a directory. I am using the following code to do this: (Please note that I want the "write access allowed" for ASPNET to be propagated to the child objects as well:</p> <pre><code>static void Main(string[] args) { Fi...
[ { "answer_id": 457504, "author": "coder_bro", "author_id": 46279, "author_profile": "https://Stackoverflow.com/users/46279", "pm_score": 4, "selected": true, "text": "<p>Got the solution, apparently I would have to do it this way:</p>\n\n<pre><code>DirectoryInfo dirInfo = new DirectoryIn...
2009/01/19
[ "https://Stackoverflow.com/questions/457307", "https://Stackoverflow.com", "https://Stackoverflow.com/users/46279/" ]
I am trying to progamrtaiclly allow write access to ASPNET account on a directory. I am using the following code to do this: (Please note that I want the "write access allowed" for ASPNET to be propagated to the child objects as well: ``` static void Main(string[] args) { FileSecurity file...
Got the solution, apparently I would have to do it this way: ``` DirectoryInfo dirInfo = new DirectoryInfo("C:\\TestDir2"); DirectorySecurity dirSecurity = dirInfo.GetAccessControl(); dirSecurity.AddAccessRule(new FileSystemAccessRule("ASPNET", FileSystemRights.Write|FileSystemRights.DeleteSub...
457,316
<p>I have two expressions of type <code>Expression&lt;Func&lt;T, bool&gt;&gt;</code> and I want to take to OR, AND or NOT of these and get a new expression of the same type</p> <pre><code>Expression&lt;Func&lt;T, bool&gt;&gt; expr1; Expression&lt;Func&lt;T, bool&gt;&gt; expr2; ... //how to do this (the code below wi...
[ { "answer_id": 457328, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 10, "selected": true, "text": "<p>Well, you can use <code>Expression.AndAlso</code> / <code>OrElse</code> etc to combine logical expressions, but th...
2009/01/19
[ "https://Stackoverflow.com/questions/457316", "https://Stackoverflow.com", "https://Stackoverflow.com/users/56648/" ]
I have two expressions of type `Expression<Func<T, bool>>` and I want to take to OR, AND or NOT of these and get a new expression of the same type ``` Expression<Func<T, bool>> expr1; Expression<Func<T, bool>> expr2; ... //how to do this (the code below will obviously not work) Expression<Func<T, bool>> andExpressio...
Well, you can use `Expression.AndAlso` / `OrElse` etc to combine logical expressions, but the problem is the parameters; are you working with the same `ParameterExpression` in expr1 and expr2? If so, it is easier: ``` var body = Expression.AndAlso(expr1.Body, expr2.Body); var lambda = Expression.Lambda<Func<T,bool>>(b...
457,317
<p>Sorry if this is a comp-sci 101 question. I'm just unsure if I'm missing something obvious.</p> <p>So let's say some user input throws an error, and I want to catch it and return some feedback. The error will be a number, 0 - 8. 0 means "No Error". I want to give the user very specific feedback if the error is 3 (N...
[ { "answer_id": 457331, "author": "wvanbergen", "author_id": 42431, "author_profile": "https://Stackoverflow.com/users/42431", "pm_score": 2, "selected": false, "text": "<p>Performance-wise, keep in mind that that the evaluation will be lazy in most languages. Using OR, if the first condi...
2009/01/19
[ "https://Stackoverflow.com/questions/457317", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49478/" ]
Sorry if this is a comp-sci 101 question. I'm just unsure if I'm missing something obvious. So let's say some user input throws an error, and I want to catch it and return some feedback. The error will be a number, 0 - 8. 0 means "No Error". I want to give the user very specific feedback if the error is 3 (No numbers ...
logically the following are identical ( excuse my pseudo code ) ``` (! expression_one || ! expression_two) /** this is the same as the one below **/ ! (expression_one && expression_two) ``` Functionally which one is more optimal? They are both as optimal as each other. Both ways (&& and ||) allow short circuiting if...
457,330
<p>Can anyone tell how correct the following code below. Iam tryin to create a stored procedure that returns the rowcount of a table whose name is passed to it.</p> <pre><code>CREATE PROCEDURE spROWCOUNTER ( @tablename nvarchar(20) @rowCountVal int OUTPUT ) AS DECLARE @strQuery nvarchar(300) SET @strQuery =...
[ { "answer_id": 457347, "author": "splattne", "author_id": 6461, "author_profile": "https://Stackoverflow.com/users/6461", "pm_score": 1, "selected": false, "text": "<p>The syntax problem is easy to solve. There is a <strong>missing comma</strong> (\",\") between your parameters. Insert t...
2009/01/19
[ "https://Stackoverflow.com/questions/457330", "https://Stackoverflow.com", "https://Stackoverflow.com/users/56631/" ]
Can anyone tell how correct the following code below. Iam tryin to create a stored procedure that returns the rowcount of a table whose name is passed to it. ``` CREATE PROCEDURE spROWCOUNTER ( @tablename nvarchar(20) @rowCountVal int OUTPUT ) AS DECLARE @strQuery nvarchar(300) SET @strQuery = 'SELECT @rowC...
``` CREATE PROCEDURE spROWCOUNTER @tablename nvarchar(20), @rowCountVal int OUTPUT AS SELECT @rowCountVal = ISNULL(SUM(spart.rows), 0) FROM sys.partitions spart WHERE spart.object_id = object_id(@tablename) AND spart.index_id < 2 RETURN @rowCountVal ```
457,338
<pre><code>public class WrapperTest { static { print(10); } static void print(int x) { System.out.println(x); System.exit(0); } } </code></pre> <p>In the above code <code>System.exit(0)</code> is used to stop the program. What argument does that method take? Why do we gave it a...
[ { "answer_id": 457348, "author": "Joachim Sauer", "author_id": 40342, "author_profile": "https://Stackoverflow.com/users/40342", "pm_score": 3, "selected": false, "text": "<p>It's the return value that the Java process will report to the calling process.</p>\n\n<p>It hasn't really got a ...
2009/01/19
[ "https://Stackoverflow.com/questions/457338", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40933/" ]
``` public class WrapperTest { static { print(10); } static void print(int x) { System.out.println(x); System.exit(0); } } ``` In the above code `System.exit(0)` is used to stop the program. What argument does that method take? Why do we gave it as `0`. Can anyone explain the ...
From the [JAVA Documentation](http://java.sun.com/javase/6/docs/api/java/lang/System.html#exit(int)): > > The argument serves as a status code; > by convention, a nonzero status code > indicates abnormal termination. > > > And [Wikipedia](http://en.wikipedia.org/wiki/Exitcode) adds additional information.
457,363
<p>When using Delphi IDE, it will silently change SQLConnection.Connected to "true" when populating field or table lists in various properties. </p> <p>Since I don't want to release with Connected = true, I need my dunit test to fail when TSQLConnection.Connected is left true in dfm.</p>
[ { "answer_id": 457421, "author": "mj2008", "author_id": 5544, "author_profile": "https://Stackoverflow.com/users/5544", "pm_score": 3, "selected": true, "text": "<p>I solve this in another way. I wrote a little utility that loads a DFM file, and looks for properties that should not be pr...
2009/01/19
[ "https://Stackoverflow.com/questions/457363", "https://Stackoverflow.com", "https://Stackoverflow.com/users/39233/" ]
When using Delphi IDE, it will silently change SQLConnection.Connected to "true" when populating field or table lists in various properties. Since I don't want to release with Connected = true, I need my dunit test to fail when TSQLConnection.Connected is left true in dfm.
I solve this in another way. I wrote a little utility that loads a DFM file, and looks for properties that should not be present. Including the database.connected = true values. This can be modified to work with any appropriate properties. I have put the core of the code here too. To make this really useful, you shou...
457,366
<p>I want to suppress the web browser's default tooltip display when a user hovers over certain links and elements. I know it's possible but I don't know how. Can anyone help?</p> <p>The reason for this is to suppress the tooltip for microformatted date-times. The BBC dropped support for hCalendar because the appeara...
[ { "answer_id": 457382, "author": "Aron Rotteveel", "author_id": 11568, "author_profile": "https://Stackoverflow.com/users/11568", "pm_score": 6, "selected": true, "text": "<p><strong>As far as I know it is not possible to actually <em>suppress</em> showing the title tag.</strong></p>\n\...
2009/01/19
[ "https://Stackoverflow.com/questions/457366", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42147/" ]
I want to suppress the web browser's default tooltip display when a user hovers over certain links and elements. I know it's possible but I don't know how. Can anyone help? The reason for this is to suppress the tooltip for microformatted date-times. The BBC dropped support for hCalendar because the appearane of the m...
**As far as I know it is not possible to actually *suppress* showing the title tag.** There are some workarounds however. Assuming you mean you want to preserve the title property on your links and elements, you could use Javascript to remove the title property at `onmouseover()` and set it again at `onmouseout()`. ...
457,370
<p>How can I convert a BITMAP in byte array format to JPEG format using .net 2.0?</p>
[ { "answer_id": 457380, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 6, "selected": true, "text": "<p>What type of <code>byte[]</code> do you mean? The raw file-stream data? In which case, how about something like (us...
2009/01/19
[ "https://Stackoverflow.com/questions/457370", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34022/" ]
How can I convert a BITMAP in byte array format to JPEG format using .net 2.0?
What type of `byte[]` do you mean? The raw file-stream data? In which case, how about something like (using `System.Drawing.dll` in a client application): ``` using(Image img = Image.FromFile("foo.bmp")) { img.Save("foo.jpg", ImageFormat.Jpeg); } ``` Or use `FromStream` with a `new MemoryStream(a...
457,399
<p>How do I disable downlevel rendering of my ASP.NET 2.0 site?</p> <p>I have a single master-page that all the other pages inherit from, and do not want "downlevel"-versions of the server-controls to be sendt to Google and W3C-validators. The best thing would be if this feature could be disabled for all users on all ...
[ { "answer_id": 457416, "author": "annakata", "author_id": 13018, "author_profile": "https://Stackoverflow.com/users/13018", "pm_score": 1, "selected": false, "text": "<p>There's a native component and some config possibilities for this.</p>\n\n<p>Googling \"browser capabilities\" or \"br...
2009/01/19
[ "https://Stackoverflow.com/questions/457399", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2257/" ]
How do I disable downlevel rendering of my ASP.NET 2.0 site? I have a single master-page that all the other pages inherit from, and do not want "downlevel"-versions of the server-controls to be sendt to Google and W3C-validators. The best thing would be if this feature could be disabled for all users on all pages on m...
There are a number of ways to do this. At the page level (either declaratively or in code) you can use the [ClientTarget](http://msdn.microsoft.com/en-us/library/system.web.ui.page.clienttarget.aspx) property of the page: ``` ClientTarget="Uplevel" // Will force to IE6 capabilities. ``` Alternatively as Annakata's ...
457,441
<p>Just wondering: When I add restrict to a pointer, I tell the compiler that the pointer is not an alias for another pointer. Let's assume I have a function like:</p> <pre><code>// Constructed example void foo (float* result, const float* a, const float* b, const size_t size) { for (size_t i = 0; i &lt; size; ++...
[ { "answer_id": 457451, "author": "falstro", "author_id": 46991, "author_profile": "https://Stackoverflow.com/users/46991", "pm_score": 5, "selected": true, "text": "<p>Your pointer is const, telling anyone calling your function that you won't touch the data which is pointed at through th...
2009/01/19
[ "https://Stackoverflow.com/questions/457441", "https://Stackoverflow.com", "https://Stackoverflow.com/users/39912/" ]
Just wondering: When I add restrict to a pointer, I tell the compiler that the pointer is not an alias for another pointer. Let's assume I have a function like: ``` // Constructed example void foo (float* result, const float* a, const float* b, const size_t size) { for (size_t i = 0; i < size; ++i) { ...
Your pointer is const, telling anyone calling your function that you won't touch the data which is pointed at through that variable. Unfortunately, the compiler still won't know if result is an alias of the const pointers. You can always use a non-const pointer as a const-pointer. For example, a lot of functions take a...
457,447
<p>I'm running two mongrels under an Nginx server. I keep getting requests for a nonexistent file. The IP addresses change frequently but the referring URL stays the same. I'd like to resolve this.</p>
[ { "answer_id": 457474, "author": "Oli", "author_id": 12870, "author_profile": "https://Stackoverflow.com/users/12870", "pm_score": 1, "selected": false, "text": "<p>I've been in a similar situation before where I needed to block people based on behaviour instead of other arbitrary rules ...
2009/01/19
[ "https://Stackoverflow.com/questions/457447", "https://Stackoverflow.com", "https://Stackoverflow.com/users/33287/" ]
I'm running two mongrels under an Nginx server. I keep getting requests for a nonexistent file. The IP addresses change frequently but the referring URL stays the same. I'd like to resolve this.
**<https://calomel.org/nginx.html>** Block most "referrer spam" -- "more of an annoyance than a problem" **nginx.conf** ``` ## Deny certain Referers (case insensitive) ## The ~* makes it case insensitive as opposed to just a ~ if ($http_referer ~* (babes|click|diamond|forsale|girl|jewelry|love|nudit|organic...
457,453
<p>I have an array of Foo objects. How do I remove the second element of the array?</p> <p>I need something similar to <code>RemoveAt()</code> but for a regular array.</p>
[ { "answer_id": 457465, "author": "Paul Mitchell", "author_id": 38966, "author_profile": "https://Stackoverflow.com/users/38966", "pm_score": 1, "selected": false, "text": "<p>Here's how I did it...</p>\n\n<pre><code> public static ElementDefinitionImpl[] RemoveElementDefAt(\n E...
2009/01/19
[ "https://Stackoverflow.com/questions/457453", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4653/" ]
I have an array of Foo objects. How do I remove the second element of the array? I need something similar to `RemoveAt()` but for a regular array.
If you don't want to use List: ``` var foos = new List<Foo>(array); foos.RemoveAt(index); return foos.ToArray(); ``` You could try this extension method that I haven't actually tested: ``` public static T[] RemoveAt<T>(this T[] source, int index) { T[] dest = new T[source.Length - 1]; if( index > 0 ) ...
457,460
<p>How can I generate hash value for a byte array, in J2ME?</p> <p>It doesn't have to be very very secure but it should be fast.</p>
[ { "answer_id": 457476, "author": "Hilton Campbell", "author_id": 50175, "author_profile": "https://Stackoverflow.com/users/50175", "pm_score": -1, "selected": false, "text": "<p>If you already have a dependency on <a href=\"http://commons.apache.org/lang/\" rel=\"nofollow noreferrer\">Ap...
2009/01/19
[ "https://Stackoverflow.com/questions/457460", "https://Stackoverflow.com", "https://Stackoverflow.com/users/38918/" ]
How can I generate hash value for a byte array, in J2ME? It doesn't have to be very very secure but it should be fast.
As suggested by Josh Bloch in his Effective Java book: ``` public int hashCode() { int result = 17; for (int i = 0; i < array.length; i++) { result = 31*result + (int)array[i]; } return result; } ```
457,463
<p>I want to put individual JComboBoxes into each cells of a JTable. ie. The JComboBox content is not identical for each cell. </p> <p>I basically would like to be able to just call the following code to add a row of JComboBox into the JTable. Anyone has any idea? Thanks</p> <pre><code>JComboBox cb1 = new JComboBox(....
[ { "answer_id": 457552, "author": "Luke Woodward", "author_id": 48503, "author_profile": "https://Stackoverflow.com/users/48503", "pm_score": 0, "selected": false, "text": "<p><a href=\"http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#combobox\" rel=\"nofollow norefer...
2009/01/19
[ "https://Stackoverflow.com/questions/457463", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9774/" ]
I want to put individual JComboBoxes into each cells of a JTable. ie. The JComboBox content is not identical for each cell. I basically would like to be able to just call the following code to add a row of JComboBox into the JTable. Anyone has any idea? Thanks ``` JComboBox cb1 = new JComboBox(...); JComboBox cb2 = ...
The easiest way is to implement your own [TableModel](http://java.sun.com/javase/6/docs/api/javax/swing/table/TableModel.html) ``` public class MyModel extends AbstractTableModel { List rows; public int getRowCount() { return rows.size(); } public int getColumnCount() { return 4; ...
457,482
<p>In my application I am running the same winform in different contexts to control visibility of buttons, enabeling of text fields and the winform header text. The way I decided to do this is simply by passing a string to the form constructor and check it with a couple of if statements that in turn contain the desired...
[ { "answer_id": 457506, "author": "mookid8000", "author_id": 6560, "author_profile": "https://Stackoverflow.com/users/6560", "pm_score": 4, "selected": true, "text": "<p>A virtual member call in the base class ctor <em>could</em> cause some logic to run in the subclass before the subclass...
2009/01/19
[ "https://Stackoverflow.com/questions/457482", "https://Stackoverflow.com", "https://Stackoverflow.com/users/45704/" ]
In my application I am running the same winform in different contexts to control visibility of buttons, enabeling of text fields and the winform header text. The way I decided to do this is simply by passing a string to the form constructor and check it with a couple of if statements that in turn contain the desired wi...
A virtual member call in the base class ctor *could* cause some logic to run in the subclass before the subclass' ctor is called (and thus before the object gets a chance to initialize itself to a consistent state). It's just a nice reminder so you know you are doing something that could potentially cause some nasty u...
457,485
<p>I am using C# to write a method that returns the following information about a table: column names, column types, column sizes, foreign keys.</p> <p>Can someone point me in the right direction on how to accomplish this ? </p>
[ { "answer_id": 457492, "author": "cgreeno", "author_id": 6088, "author_profile": "https://Stackoverflow.com/users/6088", "pm_score": 4, "selected": true, "text": "<p>To get the FK and Schema you should be able to use:</p>\n\n<pre><code>DA.FillSchema() \n\nDS.Table(\"Name\").PrimaryKey \n...
2009/01/19
[ "https://Stackoverflow.com/questions/457485", "https://Stackoverflow.com", "https://Stackoverflow.com/users/56663/" ]
I am using C# to write a method that returns the following information about a table: column names, column types, column sizes, foreign keys. Can someone point me in the right direction on how to accomplish this ?
To get the FK and Schema you should be able to use: ``` DA.FillSchema() DS.Table("Name").PrimaryKey ``` OR calling **sp\_fkey** using the method demonstrated below Code Snippet [from](http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/fad53def-d4d3-4a46-9fe2-f7d2f1251b42/) AND [Another Lin...
457,494
<p>I need to use a query which will pull data from a field when it is less then 4 words, is this possible and if so could you give some pointers? I suppose if not possible it could cycle through the results until it found one which was 3 words and then end the while statement when it has found one.</p>
[ { "answer_id": 457542, "author": "Luis Melgratti", "author_id": 17032, "author_profile": "https://Stackoverflow.com/users/17032", "pm_score": 4, "selected": true, "text": "<pre><code>SELECT column FROM table where LENGTH(column) - LENGTH(REPLACE(column, ' ', ''))+1 &lt; 4\n</code></pre>\...
2009/01/19
[ "https://Stackoverflow.com/questions/457494", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26823/" ]
I need to use a query which will pull data from a field when it is less then 4 words, is this possible and if so could you give some pointers? I suppose if not possible it could cycle through the results until it found one which was 3 words and then end the while statement when it has found one.
``` SELECT column FROM table where LENGTH(column) - LENGTH(REPLACE(column, ' ', ''))+1 < 4 ``` [Credits and full explanation](http://www.mwasif.com/2008/12/count-number-of-words-in-a-mysql-column/) Here [Regexp Solution](http://www.experts-exchange.com/Database/MySQL/Q_22682620.html). ``` select * from TABLE where ...
457,549
<p>In JavaScript, I know that a closure is can be defined as a nested function that has access to its containing function's variables. For example:</p> <pre><code>function outerFunction(x, y) { function innerFunction() { return x + y + 10; } return innerFunction; } </code></pre> <p>Now, the follow...
[ { "answer_id": 457557, "author": "Andrew Hare", "author_id": 34211, "author_profile": "https://Stackoverflow.com/users/34211", "pm_score": 3, "selected": true, "text": "<p>Yes, you are correct in assuming that it is a closure by definition.</p>\n\n<p>It sounds like you know your stuff bu...
2009/01/19
[ "https://Stackoverflow.com/questions/457549", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20/" ]
In JavaScript, I know that a closure is can be defined as a nested function that has access to its containing function's variables. For example: ``` function outerFunction(x, y) { function innerFunction() { return x + y + 10; } return innerFunction; } ``` Now, the following code is wiring up a ca...
Yes, you are correct in assuming that it is a closure by definition. It sounds like you know your stuff but [here is a good, extensive article on javascript closures](http://www.jibbering.com/faq/faq_notes/closures.html).
457,551
<p>The following code generates the primaey key for the new record to be inserted and inserts the record into a table, whose name and the values to be inserted are given as parameters to the stored procedure. I am getting a runtime error. I am using Visual Studio 2005 to work with SQL Server 2005 Express Edition</p> <...
[ { "answer_id": 457558, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 3, "selected": true, "text": "<p>You are going to have to concatenate the table name directly into the string, as this cannot be parameterized:</p>\...
2009/01/19
[ "https://Stackoverflow.com/questions/457551", "https://Stackoverflow.com", "https://Stackoverflow.com/users/56631/" ]
The following code generates the primaey key for the new record to be inserted and inserts the record into a table, whose name and the values to be inserted are given as parameters to the stored procedure. I am getting a runtime error. I am using Visual Studio 2005 to work with SQL Server 2005 Express Edition ``` ALTE...
You are going to have to concatenate the table name directly into the string, as this cannot be parameterized: ``` SELECT @sql = N' INSERT INTO [' + @tblName + '] VALUES ' + N' ( @PrimaryKey , @ValueStr )' SELECT @params = N'@PrimaryKey nvarchar(10), ' + N'@ValueStr nvarchar(300)' ``` ...
457,565
<p>I was trying to <a href="http://en.wikipedia.org/wiki/Test-driven_development" rel="nofollow noreferrer">TDD</a> using SubSonic 2.1, MySQL and C# and when I got to testing updating an existing record using the code below,</p> <pre><code>public void Test2() { User.Insert("jmarcus1", "jmarcus1", "jackass", "marcu...
[ { "answer_id": 458774, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "<p>It looks to me like your args are out of order. The PK should be the first thing - are you sure they are lining up correctl...
2009/01/19
[ "https://Stackoverflow.com/questions/457565", "https://Stackoverflow.com", "https://Stackoverflow.com/users/389/" ]
I was trying to [TDD](http://en.wikipedia.org/wiki/Test-driven_development) using SubSonic 2.1, MySQL and C# and when I got to testing updating an existing record using the code below, ``` public void Test2() { User.Insert("jmarcus1", "jmarcus1", "jackass", "marcus", 3, false); User users = new User(); int...
apparently the solution was, following Robs excellent advice above, to ``` User u = User.FetchByID(2); u.Ulevel = ulevel; u.save(); ``` i was not too sure that the snippet above would work for updates until you specify the record you wish to update. my question to Rob however is, why does "u.Update(2, "jmarcus",......
457,572
<p>I've created a custom thread pool utility, but there seems to be a problem that I cannot find.</p> <pre><code>using System; using System.Collections; using System.Collections.Generic; using System.Threading; namespace iWallpaper.S3Uploader { public class QueueManager&lt;T&gt; { private readonly Queue queue = Q...
[ { "answer_id": 457615, "author": "JoshBerke", "author_id": 26160, "author_profile": "https://Stackoverflow.com/users/26160", "pm_score": 1, "selected": false, "text": "<p>You should probally use the built in thread pool. When running your code I noticed that your spining up a bunch of th...
2009/01/19
[ "https://Stackoverflow.com/questions/457572", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41483/" ]
I've created a custom thread pool utility, but there seems to be a problem that I cannot find. ``` using System; using System.Collections; using System.Collections.Generic; using System.Threading; namespace iWallpaper.S3Uploader { public class QueueManager<T> { private readonly Queue queue = Queue.Synchronized(ne...
Writing robust threaded code is not trivial. There are numerous thread-pools around that you might look at for reference, but also note that Parallel Extensions (available as [CTP](http://www.microsoft.com/downloads/details.aspx?FamilyId=348F73FD-593D-4B3C-B055-694C50D2B0F3&displaylang=en), or later in .NET 4.0) includ...
457,577
<p>Example</p> <pre><code>int *ptr; *ptr = 1000; </code></pre> <p>can I catch memory access violation exception using standard C++ without using any microsoft specific.</p>
[ { "answer_id": 457583, "author": "unwind", "author_id": 28169, "author_profile": "https://Stackoverflow.com/users/28169", "pm_score": 7, "selected": true, "text": "<p>Nope. C++ does not throw an exception when you do something bad, that would incur a performance hit. Things like access v...
2009/01/19
[ "https://Stackoverflow.com/questions/457577", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42749/" ]
Example ``` int *ptr; *ptr = 1000; ``` can I catch memory access violation exception using standard C++ without using any microsoft specific.
Nope. C++ does not throw an exception when you do something bad, that would incur a performance hit. Things like access violations or division by zero errors are more like "machine" exceptions, rather than language-level things that you can catch.
457,590
<p>I want to implement an efficient mechanism to throttle login attemps in my Java web application, to prevent brute-force attacks on user accounts.</p> <p><a href="http://www.codinghorror.com/blog/archives/001206.html" rel="noreferrer">Jeff explained the why, but not the how.</a></p> <p>Simon Willison showed an <a h...
[ { "answer_id": 457606, "author": "tddmonkey", "author_id": 51577, "author_profile": "https://Stackoverflow.com/users/51577", "pm_score": 1, "selected": false, "text": "<p>I've just completed the web security course run by aspect security and one of the suggestions that came out of that w...
2009/01/19
[ "https://Stackoverflow.com/questions/457590", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2671/" ]
I want to implement an efficient mechanism to throttle login attemps in my Java web application, to prevent brute-force attacks on user accounts. [Jeff explained the why, but not the how.](http://www.codinghorror.com/blog/archives/001206.html) Simon Willison showed an [implementation in Python for Django](http://simo...
I think even EHCache is killing a fly with a napalm bomb. The problem is simple and so is the implementation. I suggest using a servlet filter a the top level so that as little processing as possible is done. Create a class to store the following: * The number of attempts (count) * The time Now, the code is simple ...
457,595
<p>I was playing around with Boost.Regex to parse strings for words and numbers. This is what I have so far:</p> <pre><code>#include &lt;iostream&gt; #include &lt;string&gt; #include &lt;boost/foreach.hpp&gt; #include &lt;boost/regex.hpp&gt; #include &lt;boost/range.hpp&gt; using namespace std; using namespace boost;...
[ { "answer_id": 457953, "author": "Harper Shelby", "author_id": 21196, "author_profile": "https://Stackoverflow.com/users/21196", "pm_score": 2, "selected": false, "text": "<p>The regex_iterator constructor requires BidirectionalIterators, but std::istream_iterator is only an InputIterato...
2009/01/19
[ "https://Stackoverflow.com/questions/457595", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4086/" ]
I was playing around with Boost.Regex to parse strings for words and numbers. This is what I have so far: ``` #include <iostream> #include <string> #include <boost/foreach.hpp> #include <boost/regex.hpp> #include <boost/range.hpp> using namespace std; using namespace boost; int main() { regex re ( "(...
Boost.IOStreams has a [regex\_filter](http://www.boost.org/doc/libs/1_55_0/libs/iostreams/doc/classes/regex_filter.html) allowing one to perform the equivalent of a regex\_replace on a stream. However, looking at the implementation, it seems to "cheat" in that it simply loads the whole stream into a buffer and then cal...
457,605
<p>I'm doing some real quick and dirty benchmarking on a single line of C# code using DateTime:</p> <pre><code>long lStart = DateTime.Now.Ticks; // do something long lFinish = DateTime.Now.Ticks; </code></pre> <p>The problem is in the results:</p> <pre> Start Time [633679466564559902] Finish Time [633679466564559902...
[ { "answer_id": 457610, "author": "Joachim Sauer", "author_id": 40342, "author_profile": "https://Stackoverflow.com/users/40342", "pm_score": 4, "selected": false, "text": "<p>Execute your code repeatedly. The problem seems to be that your code executes a lot faster than the granularity o...
2009/01/19
[ "https://Stackoverflow.com/questions/457605", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1683/" ]
I'm doing some real quick and dirty benchmarking on a single line of C# code using DateTime: ``` long lStart = DateTime.Now.Ticks; // do something long lFinish = DateTime.Now.Ticks; ``` The problem is in the results: ``` Start Time [633679466564559902] Finish Time [633679466564559902] Start Time [6336794665645699...
The `Stopwatch` class, available since .NET 2.0, is the best way to go for this. It is a very high performance counter accurate to fractions of a millisecond. Take a look at the [MSDN documentation](http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx), which is pretty clear. EDIT: As previously s...
457,609
<p>Imagine a standard diamond inheritance. Class A defines pure virtual function fx, class B defines implementation for fx, classes C and D do nothing with fx. When trying to call fx on instance of class D you'll get 'ambiguous function call' error although there is only one implementation of fx. This can be solved by ...
[ { "answer_id": 457646, "author": "ChrisW", "author_id": 49942, "author_profile": "https://Stackoverflow.com/users/49942", "pm_score": 2, "selected": false, "text": "<blockquote>\n <p>Is it a <em>correct</em> solution for the problem?</p>\n</blockquote>\n\n<p>\"Diamond\" inheritance is p...
2009/01/19
[ "https://Stackoverflow.com/questions/457609", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Imagine a standard diamond inheritance. Class A defines pure virtual function fx, class B defines implementation for fx, classes C and D do nothing with fx. When trying to call fx on instance of class D you'll get 'ambiguous function call' error although there is only one implementation of fx. This can be solved by B a...
... Note, Herb Sutter wrote 3 excellent articles about multiple inheritance [(1) here](http://www.gotw.ca/gotw/037.htm), [(2) here](http://www.gotw.ca/gotw/038.htm) and [(3) here](http://www.gotw.ca/gotw/039.htm) . He wrote a whole other bunch of useful articles in guru-of-the-week [here](http://www.gotw.ca/gotw/). Hig...
457,629
<p>I want to return two objects from a Java method and was wondering what could be a good way of doing so?</p> <p>The possible ways I can think of are: return a <code>HashMap</code> (since the two Objects are related) or return an <code>ArrayList</code> of <code>Object</code> objects.</p> <p>To be more precise, the t...
[ { "answer_id": 457642, "author": "Joachim Sauer", "author_id": 40342, "author_profile": "https://Stackoverflow.com/users/40342", "pm_score": 7, "selected": false, "text": "<p>If you want to return two objects you usually want to return a single object that encapsulates the two objects in...
2009/01/19
[ "https://Stackoverflow.com/questions/457629", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4406/" ]
I want to return two objects from a Java method and was wondering what could be a good way of doing so? The possible ways I can think of are: return a `HashMap` (since the two Objects are related) or return an `ArrayList` of `Object` objects. To be more precise, the two objects I want to return are (a) `List` of obje...
If you want to return two objects you usually want to return a single object that encapsulates the two objects instead. You could return a List of `NamedObject` objects like this: ``` public class NamedObject<T> { public final String name; public final T object; public NamedObject(String name, T object) { ...
457,636
<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/15828/reading-excel-files-from-c-sharp">Reading Excel files from C#</a> </p> </blockquote> <p>What is the fastest way to read large sets of data from excel from Csharp. Example code would be great . . </p>
[ { "answer_id": 457680, "author": "GvS", "author_id": 11492, "author_profile": "https://Stackoverflow.com/users/11492", "pm_score": 2, "selected": false, "text": "<p>In our desktop environment, I have reached the best mix between performance, flexibility and stability by using Excel via C...
2009/01/19
[ "https://Stackoverflow.com/questions/457636", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4653/" ]
> > **Possible Duplicate:** > > [Reading Excel files from C#](https://stackoverflow.com/questions/15828/reading-excel-files-from-c-sharp) > > > What is the fastest way to read large sets of data from excel from Csharp. Example code would be great . .
In our desktop environment, I have reached the best mix between performance, flexibility and stability by using Excel via COM. Access to Excel is always via the same thread. I use late-binding (in VB.Net) to make my app version independent. The rest of the application is developed in C#, only this part and some oth...
457,637
<p>I have an action in my PostsController named 'tagged', which I want to return all posts tagged with whatever term.</p> <p>In my routes.rb I have the following (at the top):</p> <pre><code>map.connect 'posts/tagged/:tag', { :controller =&gt; 'posts', :action =&gt; 'tagged', :tag =&gt; /[a-z\-]+/ } </code></pre> <p...
[ { "answer_id": 457680, "author": "GvS", "author_id": 11492, "author_profile": "https://Stackoverflow.com/users/11492", "pm_score": 2, "selected": false, "text": "<p>In our desktop environment, I have reached the best mix between performance, flexibility and stability by using Excel via C...
2009/01/19
[ "https://Stackoverflow.com/questions/457637", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have an action in my PostsController named 'tagged', which I want to return all posts tagged with whatever term. In my routes.rb I have the following (at the top): ``` map.connect 'posts/tagged/:tag', { :controller => 'posts', :action => 'tagged', :tag => /[a-z\-]+/ } ``` Yet navigating to posts/tagged/yes return...
In our desktop environment, I have reached the best mix between performance, flexibility and stability by using Excel via COM. Access to Excel is always via the same thread. I use late-binding (in VB.Net) to make my app version independent. The rest of the application is developed in C#, only this part and some oth...
457,641
<p>I have a python sgi script that attempts to extract an rss items that is posted to it and store the rss in a sqlite3 db. I am using flup as the WSGIServer.<br> To obtain the posted content: postData = environ["wsgi.input"].read(int(environ["CONTENT_LENGTH"]))</p> <p>To attempt to store in the db:</p> <pre><co...
[ { "answer_id": 457663, "author": "Deestan", "author_id": 6848, "author_profile": "https://Stackoverflow.com/users/6848", "pm_score": 1, "selected": false, "text": "<p>Regarding the insertion encoding - in any decent database API, you should insert <code>unicode</code> strings and <code>u...
2009/01/19
[ "https://Stackoverflow.com/questions/457641", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24907/" ]
I have a python sgi script that attempts to extract an rss items that is posted to it and store the rss in a sqlite3 db. I am using flup as the WSGIServer. To obtain the posted content: postData = environ["wsgi.input"].read(int(environ["CONTENT\_LENGTH"])) To attempt to store in the db: ``` from pysqlite2 import ...
Before the SQL insertion you should to convert the string to unicode compatible strings. If you raise an UnicodeError exception, then encode the string.encode("utf-8"). Or , you can autodetect encoding and encode it , on his encode schema. [Auto detect encoding](http://code.activestate.com/recipes/52257)
457,655
<p>I have a Java program that runs msinfo32.exe (system information)in an external process and then reads the file content produced by msinfo32.exe. When the Java program loads the file content into a String, the String characters are unreadable. For the String to be readable I have to create the String using String(by...
[ { "answer_id": 457674, "author": "Bombe", "author_id": 43582, "author_profile": "https://Stackoverflow.com/users/43582", "pm_score": 1, "selected": false, "text": "<p>You can’t really know what character encoding has been used (unless you created the tool that created the output you’re p...
2009/01/19
[ "https://Stackoverflow.com/questions/457655", "https://Stackoverflow.com", "https://Stackoverflow.com/users/46779/" ]
I have a Java program that runs msinfo32.exe (system information)in an external process and then reads the file content produced by msinfo32.exe. When the Java program loads the file content into a String, the String characters are unreadable. For the String to be readable I have to create the String using String(byte[...
Some Microsoft applications use a [byte-order mark](http://en.wikipedia.org/wiki/Byte_Order_Mark) to indicate Unicode files and their endianness. I can see on my Windows XP machine that the exported .NFO file starts with 0xFFFE, so it is little-endian. ``` FF FE 3C 00 3F 00 78 00 6D 00 6C 00 20 00 76 00 __<_?_...
457,669
<p>My onclick function works beautifully when i pass one variable and doesn't respond once i try to pass two variables. is something wrong with my syntax?</p> <p>everything supporting this code has been tested and works fine so i'm certain something is wrong with the syntax the onclick line of code. any help would be ...
[ { "answer_id": 457735, "author": "Dror", "author_id": 48317, "author_profile": "https://Stackoverflow.com/users/48317", "pm_score": 0, "selected": false, "text": "<p>Could it be a problem in the javascript deleteRecordAtt function?<br>\nmaybe the second parameter is treated as a variable...
2009/01/19
[ "https://Stackoverflow.com/questions/457669", "https://Stackoverflow.com", "https://Stackoverflow.com/users/56327/" ]
My onclick function works beautifully when i pass one variable and doesn't respond once i try to pass two variables. is something wrong with my syntax? everything supporting this code has been tested and works fine so i'm certain something is wrong with the syntax the onclick line of code. any help would be awesome. ...
> > onclick=""deleteRecordAtt(" & AttID &","& StoredPath & " )"" > > > Concatenating strings without escaping - never a good idea. Presumably AttID is an integer which is why you get away with that one argument, but StoredPath is a string. As you haven't escaped or wrapped that string, your Write above will end up...
457,671
<p>I am allowing the users to be able to make their own font choices for a listview. What would you consider the best approach for this. Should I save it to the registry or to a file in the application folder, and what properties should be saved to make sure that the font is redisplayed properly when the application is...
[ { "answer_id": 457685, "author": "StingyJack", "author_id": 16391, "author_profile": "https://Stackoverflow.com/users/16391", "pm_score": 0, "selected": false, "text": "<p>You could also use <a href=\"http://msdn.microsoft.com/en-us/library/3ak841sy(VS.80).aspx\" rel=\"nofollow noreferre...
2009/01/19
[ "https://Stackoverflow.com/questions/457671", "https://Stackoverflow.com", "https://Stackoverflow.com/users/54009/" ]
I am allowing the users to be able to make their own font choices for a listview. What would you consider the best approach for this. Should I save it to the registry or to a file in the application folder, and what properties should be saved to make sure that the font is redisplayed properly when the application is re...
Regarding where/how to save application settings see [this answer](https://stackoverflow.com/questions/453161/best-pratice-to-save-application-settings-in-windows-application#453230) You can save your font as a string and load it later using following code: ``` Font font1 = new Font("Arial", 12, FontStyle.Italic); Ty...
457,676
<p>I have a generic class in my project with derived classes.</p> <pre><code>public class GenericClass&lt;T&gt; : GenericInterface&lt;T&gt; { } public class Test : GenericClass&lt;SomeType&gt; { } </code></pre> <p>Is there any way to find out if a <code>Type</code> object is derived from <code>GenericClass</code>?</...
[ { "answer_id": 457708, "author": "JaredPar", "author_id": 23283, "author_profile": "https://Stackoverflow.com/users/23283", "pm_score": 10, "selected": true, "text": "<p>Try this code</p>\n\n<pre><code>static bool IsSubclassOfRawGeneric(Type generic, Type toCheck) {\n while (toCheck !...
2009/01/19
[ "https://Stackoverflow.com/questions/457676", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3056/" ]
I have a generic class in my project with derived classes. ``` public class GenericClass<T> : GenericInterface<T> { } public class Test : GenericClass<SomeType> { } ``` Is there any way to find out if a `Type` object is derived from `GenericClass`? ``` t.IsSubclassOf(typeof(GenericClass<>)) ``` does not work.
Try this code ``` static bool IsSubclassOfRawGeneric(Type generic, Type toCheck) { while (toCheck != null && toCheck != typeof(object)) { var cur = toCheck.IsGenericType ? toCheck.GetGenericTypeDefinition() : toCheck; if (generic == cur) { return true; } toCheck = toChec...
457,677
<p>In a Windows Forms app I set the ContextMenuStrip property on a TabControl.</p> <ol> <li>How can I tell the user clicked a tab other then the one that is currently selected?</li> <li>How can I restrict the context menu from showing only when the top Tab portion with the label is clicked, and not elsewhere in the ta...
[ { "answer_id": 457747, "author": "BFree", "author_id": 15861, "author_profile": "https://Stackoverflow.com/users/15861", "pm_score": 5, "selected": true, "text": "<p>Don't bother setting the contextMenuStrip property on the TabControl. Rather do it this way. Hook up to the tabControl's M...
2009/01/19
[ "https://Stackoverflow.com/questions/457677", "https://Stackoverflow.com", "https://Stackoverflow.com/users/54612/" ]
In a Windows Forms app I set the ContextMenuStrip property on a TabControl. 1. How can I tell the user clicked a tab other then the one that is currently selected? 2. How can I restrict the context menu from showing only when the top Tab portion with the label is clicked, and not elsewhere in the tab?
Don't bother setting the contextMenuStrip property on the TabControl. Rather do it this way. Hook up to the tabControl's MouseClick event, and then manually show the context menu. This will only fire if the tab itself on top is clicked on, not the actual page. If you click on the page, then the tabControl doesn't recei...
457,688
<p>I am writing a Silverlight client that interacts with an SQL database via ASP.NET 2.0 web services, which I am also developing. One of the services needs to return the results of a stored procedure and it works well. However, one parameter of the stored procedure needs to be retrieved from a different location befor...
[ { "answer_id": 457715, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 3, "selected": true, "text": "<p>Well, it could be something like:</p>\n\n<pre><code> cmd.CommandType = CommandType.Text;\n cmd.Parameters.Add...
2009/01/19
[ "https://Stackoverflow.com/questions/457688", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23234/" ]
I am writing a Silverlight client that interacts with an SQL database via ASP.NET 2.0 web services, which I am also developing. One of the services needs to return the results of a stored procedure and it works well. However, one parameter of the stored procedure needs to be retrieved from a different location before t...
Well, it could be something like: ``` cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@id", ...); // your id arg cmd.Parameters.AddWithValue(... , ...); // your other args... cmd.CommandText = @" DECLARE @TaskType int -- or whatever SELECT @TaskType = // some existing query based on @...
457,694
<p>I have setup an empty svn on a server and I have been working on locally making commits along the way. Now I wish to commit my repo to an svn server. For this I tried:</p> <pre><code>git-svn checkout http://remote.svn.server.com git-svn dcommit </code></pre> <p>Git complains that:</p> <pre><code>Use of uninitiali...
[ { "answer_id": 459719, "author": "tcurdt", "author_id": 33165, "author_profile": "https://Stackoverflow.com/users/33165", "pm_score": 4, "selected": true, "text": "<p>Here is what I would do:</p>\n\n<pre><code>git-svn clone http://remote.svn.server.com otherdir\n</code></pre>\n\n<p>Then ...
2009/01/19
[ "https://Stackoverflow.com/questions/457694", "https://Stackoverflow.com", "https://Stackoverflow.com/users/370899/" ]
I have setup an empty svn on a server and I have been working on locally making commits along the way. Now I wish to commit my repo to an svn server. For this I tried: ``` git-svn checkout http://remote.svn.server.com git-svn dcommit ``` Git complains that: ``` Use of uninitialized value in concatenation (.) or str...
Here is what I would do: ``` git-svn clone http://remote.svn.server.com otherdir ``` Then in other dir pull the changes locally from your previous dir. Then you should have a git repo that is "connected" via git-svn and you should be able to use dcommit on it. [This](http://wiki.apache.org/general/GitAtApache) migh...
457,698
<p>I would like to position three items in CSS using float. </p> <ol> <li>In the top left--logo</li> <li>To the right of the logo, the navigation, which is an unordered list, ie floating left.</li> <li>In the top right, a 2 line sign up for newsletter field--copy top row and form field with submit bottom in the second...
[ { "answer_id": 457728, "author": "Ulrik Rasmussen", "author_id": 56647, "author_profile": "https://Stackoverflow.com/users/56647", "pm_score": 0, "selected": false, "text": "<p>If I've understood it correctly, maybe you could set the first and second element to float: left, and then set ...
2009/01/19
[ "https://Stackoverflow.com/questions/457698", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I would like to position three items in CSS using float. 1. In the top left--logo 2. To the right of the logo, the navigation, which is an unordered list, ie floating left. 3. In the top right, a 2 line sign up for newsletter field--copy top row and form field with submit bottom in the second I've given each it's ow...
What about the following? ``` .floatleft_logo { float: left; width: 200px; } .floatleft_nav { float: left; width: 600px; } .floatright_email { float: right; width: 300px; margin-left:-250px; } ``` Put all three in a 850px-wi...
457,701
<p>I've got data in SQL Server 2005 that contains HTML tags and I'd like to strip all that out, leaving just the text between the tags. Ideally also replacing things like <code>&amp;lt;</code> with <code>&lt;</code>, etc.</p> <p>Is there an easy way to do this or has someone already got some sample T-SQL code?</p> <p>I...
[ { "answer_id": 457725, "author": "D'Arcy Rittich", "author_id": 39430, "author_profile": "https://Stackoverflow.com/users/39430", "pm_score": 9, "selected": true, "text": "<p>There is a UDF that will do that described here: </p>\n\n<p><a href=\"http://blog.sqlauthority.com/2007/06/16/sql...
2009/01/19
[ "https://Stackoverflow.com/questions/457701", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8479/" ]
I've got data in SQL Server 2005 that contains HTML tags and I'd like to strip all that out, leaving just the text between the tags. Ideally also replacing things like `&lt;` with `<`, etc. Is there an easy way to do this or has someone already got some sample T-SQL code? I don't have the ability to add extended stor...
There is a UDF that will do that described here: [User Defined Function to Strip HTML](http://blog.sqlauthority.com/2007/06/16/sql-server-udf-user-defined-function-to-strip-html-parse-html-no-regular-expression/) ``` CREATE FUNCTION [dbo].[udf_StripHTML] (@HTMLText VARCHAR(MAX)) RETURNS VARCHAR(MAX) AS BEGIN DEC...
457,705
<p>Can I get Visual Studio to transform the <a href="http://msdn.microsoft.com/en-us/library/ya5y69ds.aspx" rel="noreferrer">built-in aliases</a> into the System types? For example, if I define the following interface</p> <pre><code>public interface IExample { Int32 DoWork(String input); } </code></pre> <p>and us...
[ { "answer_id": 457737, "author": "Ed Guiness", "author_id": 4200, "author_profile": "https://Stackoverflow.com/users/4200", "pm_score": 1, "selected": false, "text": "<p>I recommend <a href=\"http://www.red-gate.com/Products/ants_profiler/index.htm\" rel=\"nofollow noreferrer\">ANTS prof...
2009/01/19
[ "https://Stackoverflow.com/questions/457705", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3619/" ]
Can I get Visual Studio to transform the [built-in aliases](http://msdn.microsoft.com/en-us/library/ya5y69ds.aspx) into the System types? For example, if I define the following interface ``` public interface IExample { Int32 DoWork(String input); } ``` and use VS to automatically generate the interface, I get th...
[EQATEC profiler](http://www.eqatec.com/tools/profiler) is pretty simple to use. Free too. Started life targetting Compact Framework but since 2.00 is now geared more towards Desktop too.
457,719
<p>Earlier I asked why this is considered bad:</p> <pre><code>class Example { public: Example(void); ~Example(void); void f() {} } int main(void) { Example ex(); // &lt;&lt;&lt;&lt;&lt;&lt; what is it called to call it like this? return(0); } </code></pre> <p>Now, I understand that it's creating a functio...
[ { "answer_id": 457738, "author": "yesraaj", "author_id": 22076, "author_profile": "https://Stackoverflow.com/users/22076", "pm_score": 2, "selected": true, "text": "<p>this <a href=\"https://stackoverflow.com/questions/420099/is-this-type-variableoftype-function-or-object#420225\">questi...
2009/01/19
[ "https://Stackoverflow.com/questions/457719", "https://Stackoverflow.com", "https://Stackoverflow.com/users/55133/" ]
Earlier I asked why this is considered bad: ``` class Example { public: Example(void); ~Example(void); void f() {} } int main(void) { Example ex(); // <<<<<< what is it called to call it like this? return(0); } ``` Now, I understand that it's creating a function prototype instead that returns a type Exam...
this [question](https://stackoverflow.com/questions/420099/is-this-type-variableoftype-function-or-object#420225) will be helpful to understand this behavior
457,724
<p>I'm trying to compile a very old verion of slapd (the LDAP server) on cygwin. Previously this ran on a Linux box, but for reasons beyond my control it must be made to work on a Windows server. It has been suggested that we might use cygwin to compile up the source-code.</p> <p>Unfortunately the build fails during "...
[ { "answer_id": 457756, "author": "David Schmitt", "author_id": 4918, "author_profile": "https://Stackoverflow.com/users/4918", "pm_score": 1, "selected": false, "text": "<p>The root cause seems to be </p>\n\n<blockquote>\n <p>/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/...
2009/01/19
[ "https://Stackoverflow.com/questions/457724", "https://Stackoverflow.com", "https://Stackoverflow.com/users/46411/" ]
I'm trying to compile a very old verion of slapd (the LDAP server) on cygwin. Previously this ran on a Linux box, but for reasons beyond my control it must be made to work on a Windows server. It has been suggested that we might use cygwin to compile up the source-code. Unfortunately the build fails during "configure"...
After much trial & error I found the correct answer for this problem: The reason for this error is that the Cygwin environment was not set up correctly. The login-user on a domain, and so the /etc/passwd & /etc/group files were not set up correctly by default. The solution was to make a local user-account and then re-...
457,763
<p>first time SO user :)</p> <p>I know that I can format a number like this:</p> <pre><code>format-number($value, '###,###.00') </code></pre> <p>But I would like to remove the dot and the zeroes if $value is zero.</p> <p>So, </p> <pre><code>37368 -&gt; 37,368 2.666667 -&gt; 2.66 </code></pre> <p>Is this possible ...
[ { "answer_id": 457829, "author": "annakata", "author_id": 13018, "author_profile": "https://Stackoverflow.com/users/13018", "pm_score": 0, "selected": false, "text": "<p>xpath 2.0 contains conditional logic <a href=\"http://www.xml.com/lpt/a/1573\" rel=\"nofollow noreferrer\">if..then..e...
2009/01/19
[ "https://Stackoverflow.com/questions/457763", "https://Stackoverflow.com", "https://Stackoverflow.com/users/56699/" ]
first time SO user :) I know that I can format a number like this: ``` format-number($value, '###,###.00') ``` But I would like to remove the dot and the zeroes if $value is zero. So, ``` 37368 -> 37,368 2.666667 -> 2.66 ``` Is this possible using just number formatting (doesn't seem like it) or do I have to d...
``` format-number($value, '###,###.##') ```
457,774
<p>(I've tried posting this on YUI message group but without any luck)</p> <p>Can anyone tell me how to retrieve the checked state of a yui Button? I've tried by creating the Button in code, which is then outputted as a HTML button but this only changes the title attribute.</p> <p>When I use checkboxes instead, none ...
[ { "answer_id": 457920, "author": "Crescent Fresh", "author_id": 45433, "author_profile": "https://Stackoverflow.com/users/45433", "pm_score": 4, "selected": true, "text": "<p>Sorry are you talking about <a href=\"http://developer.yahoo.com/yui/examples/button/btn_example03.html\" rel=\"n...
2009/01/19
[ "https://Stackoverflow.com/questions/457774", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21574/" ]
(I've tried posting this on YUI message group but without any luck) Can anyone tell me how to retrieve the checked state of a yui Button? I've tried by creating the Button in code, which is then outputted as a HTML button but this only changes the title attribute. When I use checkboxes instead, none of the checkboxes...
Sorry are you talking about [checkbox buttons](http://developer.yahoo.com/yui/examples/button/btn_example03.html)? Use: ``` myButton.get("checked") ``` where myButton is an instance of `YAHOO.widget.Button`.
457,777
<p>How can I access Class object for Generics?</p> <p>Currently, I am doing it this way:</p> <pre><code>List&lt;String&gt; list= new ArrayList&lt;String&gt;(); list.getClass(); </code></pre> <p>Is this OK? Or, what should be the way?</p>
[ { "answer_id": 457794, "author": "Joao da Silva", "author_id": 46329, "author_profile": "https://Stackoverflow.com/users/46329", "pm_score": 4, "selected": true, "text": "<p>That will return the same as ArrayList.class. Java generics erase the generic type at runtime; in other words, fro...
2009/01/19
[ "https://Stackoverflow.com/questions/457777", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4406/" ]
How can I access Class object for Generics? Currently, I am doing it this way: ``` List<String> list= new ArrayList<String>(); list.getClass(); ``` Is this OK? Or, what should be the way?
That will return the same as ArrayList.class. Java generics erase the generic type at runtime; in other words, from "list" you'll never know the element type is String. There's a great FAQ on this at <http://www.angelikalanger.com/GenericsFAQ/JavaGenericsFAQ.html>
457,778
<p>I have been making a threaded comment system as a way to learn php and javascript/jquery properly. Ive done bits and bobs in the past but ive made a new years resolution to learn it properly.</p> <p>Im having trouble inserting a reply form into the comment tree below the comment being replied to. I know this is pro...
[ { "answer_id": 457807, "author": "roborourke", "author_id": 42147, "author_profile": "https://Stackoverflow.com/users/42147", "pm_score": 1, "selected": false, "text": "<p>To add to rodbv's answer you'll be adding the text \"the html blah blah\" <strong>inside</strong> the link that was ...
2009/01/19
[ "https://Stackoverflow.com/questions/457778", "https://Stackoverflow.com", "https://Stackoverflow.com/users/56696/" ]
I have been making a threaded comment system as a way to learn php and javascript/jquery properly. Ive done bits and bobs in the past but ive made a new years resolution to learn it properly. Im having trouble inserting a reply form into the comment tree below the comment being replied to. I know this is probably pret...
If none of the other suggestions are working, it could be your selector for the link is not working properly. In the example you provided you appear to be looking for a link like this: ``` <a id='reply' href='#'>add comment</a> ``` Is that correct? You didn't mention how you were generating the html, but I know with...
457,792
<p>I'm writing a conferencing portal using the open-source OpenMeetings, which is a Flash app that is compiled with OpenLaszlo. So, I have access to the SWF source code which is a mix of Laszlo markup and JavaScript, but not ActionScript.</p> <p>The problem I am having is that when users navigate away from the app in ...
[ { "answer_id": 457892, "author": "scunliffe", "author_id": 6144, "author_profile": "https://Stackoverflow.com/users/6144", "pm_score": 0, "selected": false, "text": "<p>Are there any JavaScript references to the object that remain?</p>\n\n<pre><code> //e.g.\n var conf = document.getEleme...
2009/01/19
[ "https://Stackoverflow.com/questions/457792", "https://Stackoverflow.com", "https://Stackoverflow.com/users/56701/" ]
I'm writing a conferencing portal using the open-source OpenMeetings, which is a Flash app that is compiled with OpenLaszlo. So, I have access to the SWF source code which is a mix of Laszlo markup and JavaScript, but not ActionScript. The problem I am having is that when users navigate away from the app in Internet E...
The option covered here seems to work best for us: <http://blog.vokle.com/index.php/2009/03/10/why-ie-doesnt-drop-flash-netconnections-netstreams-and-how-to-fix-it/> We also use the "removeSWF" function from SWFObject like so: ``` <!--[if IE]> <script type="text/javascript"> function cleanupForIE() {...
457,797
<p>What's the best way to discover a file's filetype within php? I heard that the browser may be tricked, so what's a better way of doing this?</p>
[ { "answer_id": 457818, "author": "Luis Melgratti", "author_id": 17032, "author_profile": "https://Stackoverflow.com/users/17032", "pm_score": 3, "selected": false, "text": "<p>i think you mean <a href=\"http://ar.php.net/manual/en/function.finfo-file.php\" rel=\"nofollow noreferrer\">fin...
2009/01/19
[ "https://Stackoverflow.com/questions/457797", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36532/" ]
What's the best way to discover a file's filetype within php? I heard that the browser may be tricked, so what's a better way of doing this?
You can use [finfo\_file](http://www.php.net/manual/en/function.finfo-file.php) ``` <?php echo finfo_file(finfo_open(FILEINFO_MIME), "foo.png"); ?> ```