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
322,333
<p>I've got an NSColor, and I really want the 32-bit RGBA value that it represents. Is there any easy way to get this, besides extracting the float components, then multiplying and ORing and generally doing gross, endian-dependent things?</p> <p>Edit: Thanks for the help. Really, what I was hoping for was a Cocoa fu...
[ { "answer_id": 322360, "author": "Sparr", "author_id": 13675, "author_profile": "https://Stackoverflow.com/users/13675", "pm_score": 1, "selected": false, "text": "<p>Converting the 4 floats to their integer representation, however you want to accomplish that, is the only way.</p>\n" }...
2008/11/26
[ "https://Stackoverflow.com/questions/322333", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3830/" ]
I've got an NSColor, and I really want the 32-bit RGBA value that it represents. Is there any easy way to get this, besides extracting the float components, then multiplying and ORing and generally doing gross, endian-dependent things? Edit: Thanks for the help. Really, what I was hoping for was a Cocoa function that ...
Another more brute force approach would be to create a temporary CGBitmapContext and fill with the color. ``` NSColor *someColor = {whatever}; uint8_t data[4]; CGContextRef ctx = CGBitmapContextCreate((void*)data, 1, 1, 8, 4, colorSpace, kCGImageAlphaFirst | kCGBitmapByteOrder32Big); CGContextSetRGBFillColor(ctx, [...
322,361
<p>In an ActionScript 2 project I can create a new MovieClip, right-click on it on the library and select "Component Definition" to add parameters that can be referenced inside the MovieClip. This parameters can be easily changed in the MovieClips's properties.</p> <p>Now, I'm working on an ActionScript 3 project but ...
[ { "answer_id": 323237, "author": "grapefrukt", "author_id": 914, "author_profile": "https://Stackoverflow.com/users/914", "pm_score": 0, "selected": false, "text": "<p>I haven't used this specific functionality, but likely you will need to define a custom class for that MovieClip (just s...
2008/11/26
[ "https://Stackoverflow.com/questions/322361", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
In an ActionScript 2 project I can create a new MovieClip, right-click on it on the library and select "Component Definition" to add parameters that can be referenced inside the MovieClip. This parameters can be easily changed in the MovieClips's properties. Now, I'm working on an ActionScript 3 project but haven't be...
In as3 you have to create an external class file with one or more `public var` declarations that you will use (you can also use public `get`/`set` functions). Google this if you're not sure how. In your external file, use the `[Inspectable]` metadata tag just before your `var`, like this: ``` package myPackage { im...
322,364
<p>I have a .NET 3.5 C# library that uses OleDb to pull data from an Excel file and return it in a DataRowCollection which is used by a CLR Table-Valued Function in SQL Server 2005.</p> <p>I deployed the <code>ASSEMBLY</code> in SQL Server as sa and used <code>PERMISSION_SET = EXTERNAL_ACCESS</code>. The sa login has...
[ { "answer_id": 322920, "author": "shahkalpesh", "author_id": 23574, "author_profile": "https://Stackoverflow.com/users/23574", "pm_score": 0, "selected": false, "text": "<p>I am sorry that I am not providing a solution to the exact problem here.</p>\n\n<p>But, you can use OPENROWSET func...
2008/11/26
[ "https://Stackoverflow.com/questions/322364", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22355/" ]
I have a .NET 3.5 C# library that uses OleDb to pull data from an Excel file and return it in a DataRowCollection which is used by a CLR Table-Valued Function in SQL Server 2005. I deployed the `ASSEMBLY` in SQL Server as sa and used `PERMISSION_SET = EXTERNAL_ACCESS`. The sa login has `EXTERNAL ACCESS ASSEMBLY` and t...
Solved it! PERMISSION\_SET = EXTERNAL\_ACCESS was not enough. I had to go all the way down to PERMISSION\_SET = UNSAFE and then it started working. I can't believe I didn't try that before.
322,378
<p>Is there a way to detect if a mouse button is currently down in JavaScript?</p> <p>I know about the "mousedown" event, but that's not what I need. Some time AFTER the mouse button is pressed, I want to be able to detect if it is still pressed down.</p> <p>Is this possible?</p>
[ { "answer_id": 322399, "author": "rogeriopvl", "author_id": 28388, "author_profile": "https://Stackoverflow.com/users/28388", "pm_score": -1, "selected": false, "text": "<p>Well, you can't check if it's down after the event, but you can check if it's Up... If it's up.. it means that no l...
2008/11/26
[ "https://Stackoverflow.com/questions/322378", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12983/" ]
Is there a way to detect if a mouse button is currently down in JavaScript? I know about the "mousedown" event, but that's not what I need. Some time AFTER the mouse button is pressed, I want to be able to detect if it is still pressed down. Is this possible?
Regarding [Pax' solution](https://stackoverflow.com/a/322650/2750743): it doesn't work if user clicks more than one button intentionally or accidentally. Don't ask me how I know :-(. The correct code should be like that: ``` var mouseDown = 0; document.body.onmousedown = function() { ++mouseDown; } document.body.o...
322,379
<p>I am about to define an interface in my application that plug-in writers can implement to provide user-defined "export" capabilities. It'll look something like this:</p> <pre><code>public interface IFooExporter { void ExportFoo(Foo foo, string path); } </code></pre> <p>However, I need to let the plug-in writer...
[ { "answer_id": 322399, "author": "rogeriopvl", "author_id": 28388, "author_profile": "https://Stackoverflow.com/users/28388", "pm_score": -1, "selected": false, "text": "<p>Well, you can't check if it's down after the event, but you can check if it's Up... If it's up.. it means that no l...
2008/11/26
[ "https://Stackoverflow.com/questions/322379", "https://Stackoverflow.com", "https://Stackoverflow.com/users/615/" ]
I am about to define an interface in my application that plug-in writers can implement to provide user-defined "export" capabilities. It'll look something like this: ``` public interface IFooExporter { void ExportFoo(Foo foo, string path); } ``` However, I need to let the plug-in writers know (explicitly, not ju...
Regarding [Pax' solution](https://stackoverflow.com/a/322650/2750743): it doesn't work if user clicks more than one button intentionally or accidentally. Don't ask me how I know :-(. The correct code should be like that: ``` var mouseDown = 0; document.body.onmousedown = function() { ++mouseDown; } document.body.o...
322,390
<p>I want to examine the contents of a std::vector in gdb but I don't have access to _M_impl because I'm using icc, not gcc, how do I do it? Let's say it's a std::vector for the sake of simplicity.</p> <p>There is a very nice answer <a href="https://stackoverflow.com/questions/253099/how-do-i-print-the-elements-of-a-c...
[ { "answer_id": 322417, "author": "Max Lybbert", "author_id": 10593, "author_profile": "https://Stackoverflow.com/users/10593", "pm_score": 0, "selected": false, "text": "<p>The <code>std::vector</code> template <a href=\"http://herbsutter.wordpress.com/2008/04/07/cringe-not-vectors-are-g...
2008/11/26
[ "https://Stackoverflow.com/questions/322390", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26261/" ]
I want to examine the contents of a std::vector in gdb but I don't have access to \_M\_impl because I'm using icc, not gcc, how do I do it? Let's say it's a std::vector for the sake of simplicity. There is a very nice answer [here](https://stackoverflow.com/questions/253099/how-do-i-print-the-elements-of-a-c-vector-in...
Not sure this will work with your vector, but it worked for me. ``` #include <string> #include <vector> int main() { std::vector<std::string> vec; vec.push_back("Hello"); vec.push_back("world"); vec.push_back("!"); return 0; } ``` gdb: ``` (gdb) break source.cpp:8 (gdb) run (gdb) p vec.begin() ...
322,392
<p>I'm looking for a regular expression that will match all strings EXCEPT those that contain a certain string within. Can someone help me construct it?</p> <p>For example, looking for all strings that <em>do not</em> have a, b, and c in them in that order.</p> <p>So <br /> abasfaf3 would match, whereas <br /> asasd...
[ { "answer_id": 322400, "author": "Alan", "author_id": 37843, "author_profile": "https://Stackoverflow.com/users/37843", "pm_score": 3, "selected": true, "text": "<p>in perl:</p>\n\n<pre><code>if($str !~ /a.*?b.*?.*c/g)\n{\n print \"match\";\n}\n</code></pre>\n\n<p>should work.</p>\n" ...
2008/11/26
[ "https://Stackoverflow.com/questions/322392", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40866/" ]
I'm looking for a regular expression that will match all strings EXCEPT those that contain a certain string within. Can someone help me construct it? For example, looking for all strings that *do not* have a, b, and c in them in that order. So abasfaf3 would match, whereas asasdfbasc would not
in perl: ``` if($str !~ /a.*?b.*?.*c/g) { print "match"; } ``` should work.
322,401
<p>I feel that it should be something very simple and obvious but just stuck on this for the last half an hour and can't move on.</p> <p>All I need is to split an array of elements into N groups based on element index.</p> <p>For example we have an array of 30 elements [e1,e2,...e30], that has to be divided into N=3 ...
[ { "answer_id": 322427, "author": "Adam Liss", "author_id": 29157, "author_profile": "https://Stackoverflow.com/users/29157", "pm_score": 1, "selected": false, "text": "<pre><code> const int g = 3; // number of groups\n const int n = (array_size + g - 1)/g; // element...
2008/11/26
[ "https://Stackoverflow.com/questions/322401", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20128/" ]
I feel that it should be something very simple and obvious but just stuck on this for the last half an hour and can't move on. All I need is to split an array of elements into N groups based on element index. For example we have an array of 30 elements [e1,e2,...e30], that has to be divided into N=3 groups like this:...
What about something like this? ``` for(i=0;i<array_size;i++) { print "group" + (Math.floor(i/(array_size/N)) + 1) } ```
322,418
<p>I've been always thinking that DOMNodeInsertedIntoDocument/DOMNodeRemovedFromDocument events should not bubble, and for me that made enough sence. However, just recently I looked into specification once again and found out that in one location it says these events should not bubble (<a href="http://www.w3.org/TR/DOM...
[ { "answer_id": 322427, "author": "Adam Liss", "author_id": 29157, "author_profile": "https://Stackoverflow.com/users/29157", "pm_score": 1, "selected": false, "text": "<pre><code> const int g = 3; // number of groups\n const int n = (array_size + g - 1)/g; // element...
2008/11/26
[ "https://Stackoverflow.com/questions/322418", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23815/" ]
I've been always thinking that DOMNodeInsertedIntoDocument/DOMNodeRemovedFromDocument events should not bubble, and for me that made enough sence. However, just recently I looked into specification once again and found out that in one location it says these events should not bubble ([Complete list of event types](http:...
What about something like this? ``` for(i=0;i<array_size;i++) { print "group" + (Math.floor(i/(array_size/N)) + 1) } ```
322,423
<p>I'm having some trouble uploading and getting my web app on the net with my chosen host. I built a war file in Net Beans and asked my host to deploy it for me. This worked fine but to access it I had to point my browser to:</p> <pre><code>www.myDomain.co.uk/explodedWar </code></pre> <p>What of course I wanted wa...
[ { "answer_id": 322437, "author": "digitalsanctum", "author_id": 22436, "author_profile": "https://Stackoverflow.com/users/22436", "pm_score": 0, "selected": false, "text": "<p>This is a question you need to ask your host about since they are deploying it for you.</p>\n" }, { "ans...
2008/11/26
[ "https://Stackoverflow.com/questions/322423", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16684/" ]
I'm having some trouble uploading and getting my web app on the net with my chosen host. I built a war file in Net Beans and asked my host to deploy it for me. This worked fine but to access it I had to point my browser to: ``` www.myDomain.co.uk/explodedWar ``` What of course I wanted was to be able to access it ju...
If you name your war ROOT.war (in Tomcat) it should do what you want.
322,441
<p>How can I ignore accents (like ´, `, ~) in queries made to a SQL Server database using LINQ to SQL?</p> <p><strong>UPDATE:</strong></p> <p>Still haven't figured out how to do it in LINQ (or even if it's possible) but I managed to change the database to solve this issue. Just had to change the collation on the fiel...
[ { "answer_id": 322476, "author": "JasonTrue", "author_id": 13433, "author_profile": "https://Stackoverflow.com/users/13433", "pm_score": 3, "selected": true, "text": "<p>In SQL queries (Sql Server 2000+, as I recall), you do this by doing something like select MyString, MyId from MyTable...
2008/11/26
[ "https://Stackoverflow.com/questions/322441", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2841/" ]
How can I ignore accents (like ´, `, ~) in queries made to a SQL Server database using LINQ to SQL? **UPDATE:** Still haven't figured out how to do it in LINQ (or even if it's possible) but I managed to change the database to solve this issue. Just had to change the collation on the fields I wanted to search on. The ...
In SQL queries (Sql Server 2000+, as I recall), you do this by doing something like select MyString, MyId from MyTable where MyString collate Latin1\_General\_CI\_AI ='aaaa'. I'm not sure if this is possible in Linq, but someone more cozy with Linq can probably translate. If you are ok with sorting and select/where q...
322,470
<h3>Background:</h3> <p>I have a module which declares a number of instance methods</p> <pre><code>module UsefulThings def get_file; ... def delete_file; ... def format_text(x); ... end </code></pre> <p>And I want to call some of these methods from within a class. How you normally do this in ruby is like this...
[ { "answer_id": 322501, "author": "Dustin", "author_id": 39975, "author_profile": "https://Stackoverflow.com/users/39975", "pm_score": 3, "selected": false, "text": "<p>Firstly, I'd recommend breaking the module up into the useful things you need. But you can always create a class extend...
2008/11/26
[ "https://Stackoverflow.com/questions/322470", "https://Stackoverflow.com", "https://Stackoverflow.com/users/234/" ]
### Background: I have a module which declares a number of instance methods ``` module UsefulThings def get_file; ... def delete_file; ... def format_text(x); ... end ``` And I want to call some of these methods from within a class. How you normally do this in ruby is like this: ``` class UsefulWorker inc...
If a method on a module is turned into a module function you can simply call it off of Mods as if it had been declared as ``` module Mods def self.foo puts "Mods.foo(self)" end end ``` The module\_function approach below will avoid breaking any classes which include all of Mods. ``` module Mods def foo ...
322,484
<p>I am looking for a bells and whistles CSS framework. I have found a number online that deal with "grids", and some that deal with "typography" and others that deal with "resetting".</p> <p>What I have not found is something that will give my web applications a consistent reusable style or theme.</p> <p>I guess it ...
[ { "answer_id": 322489, "author": "TravisO", "author_id": 35116, "author_profile": "https://Stackoverflow.com/users/35116", "pm_score": 2, "selected": false, "text": "<p>Just use <a href=\"http://developer.yahoo.com/yui/grids/\" rel=\"nofollow noreferrer\">YUI Grids</a>, it's as good as i...
2008/11/26
[ "https://Stackoverflow.com/questions/322484", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28380/" ]
I am looking for a bells and whistles CSS framework. I have found a number online that deal with "grids", and some that deal with "typography" and others that deal with "resetting". What I have not found is something that will give my web applications a consistent reusable style or theme. I guess it would have to hav...
[Compass](http://acts-as-architect.blogspot.com/2008/11/introducing-compass.html) really changes things for you. In addition to providing everything from grids to mixins like horizontal-list, it's built on top of SASS so you get stuff like reuse and variables and other such things. It makes things you don't even real...
322,493
<p>What can I do to comprehensively validate an Australian Phone Number? I need this for an application I'm writing. You can assume it is dialed from within Australia. I want to use a white-list approach.</p> <p>Here are my rules so far (after removing any whitespace):-</p> <ol> <li>Starts with 13 and is 6 digits l...
[ { "answer_id": 322514, "author": "Matt Hamilton", "author_id": 615, "author_profile": "https://Stackoverflow.com/users/615", "pm_score": 0, "selected": false, "text": "<p>I'd be tempted to remove the parentheses as well. I still see phone numbers written like \"(0212) 34 5678\" every onc...
2008/11/26
[ "https://Stackoverflow.com/questions/322493", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14663/" ]
What can I do to comprehensively validate an Australian Phone Number? I need this for an application I'm writing. You can assume it is dialed from within Australia. I want to use a white-list approach. Here are my rules so far (after removing any whitespace):- 1. Starts with 13 and is 6 digits long 2. Starts with 130...
I did a similar thing a while ago. The Wikipedia page that unthinkableMayhem mentioned was a great starting point. As of a year ago, my rules looked something like: ``` 02[3-9]\d{7} NSW/ACT 03[4-9]\d{7} VIC/TAS 07[3-9]\d{7} QLD 08\d{8} SA/NT/WA 04[\d]{8} Moblies 04x[123] = Optus, 04x[456] = Voda, 04x[...
322,496
<p>Short version: </p> <p>Could anyone suggest or provide a sample in LINQ to XML for VB, or in an XSLT of how to change one XML element into another (without hardcoding an element-by-element copy of all the unchanged elements)?</p> <p>Background:</p> <p>I have an XML file, that I think is properly formed, that cont...
[ { "answer_id": 322520, "author": "seanb", "author_id": 3354, "author_profile": "https://Stackoverflow.com/users/3354", "pm_score": 0, "selected": false, "text": "<p>Are you looking for something like this:</p>\n\n<pre><code> &lt;xsl:template match=\"Tag\"&gt;\n &lt;xsl:element name=\"...
2008/11/26
[ "https://Stackoverflow.com/questions/322496", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41188/" ]
Short version: Could anyone suggest or provide a sample in LINQ to XML for VB, or in an XSLT of how to change one XML element into another (without hardcoding an element-by-element copy of all the unchanged elements)? Background: I have an XML file, that I think is properly formed, that contains a root entry that i...
Using one of the most fundamental and powerful XSLT design patterns: overriding the [**identity template**](http://www.w3.org/TR/xslt#copying), one will write this very simple transformation to replace every "Genres" element with a "Topics" element: ``` <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999...
322,498
<p>I noticed methods marked optional in several protocols defined in the iPhone SDK, such as the <code>UIActionSheetDelegate</code> protocol for example.</p> <p>How can I define a protocol of my own, and set a few of the methods as optional?</p>
[ { "answer_id": 322511, "author": "e.James", "author_id": 33686, "author_profile": "https://Stackoverflow.com/users/33686", "pm_score": 4, "selected": false, "text": "<p>Use the <code>@optional</code> keyword before your method declaration to make it optional. Simple as that!</p>\n\n<pre>...
2008/11/26
[ "https://Stackoverflow.com/questions/322498", "https://Stackoverflow.com", "https://Stackoverflow.com/users/35478/" ]
I noticed methods marked optional in several protocols defined in the iPhone SDK, such as the `UIActionSheetDelegate` protocol for example. How can I define a protocol of my own, and set a few of the methods as optional?
From the Apple page on "[Formal Protocols](https://developer.apple.com/library/ios/documentation/cocoa/conceptual/ProgrammingWithObjectiveC/WorkingwithProtocols/WorkingwithProtocols.html)": > > Optional Protocol > methods can be marked as optional > using the @optional keyword. > Corresponding to the @optional mod...
322,510
<p>I have been working on a script with PHP4 that relies on NuSOAP. Now, I'm trying to move this to PHP5, and use the buildin support for SOAP there.</p> <pre><code>$wsdlPath = ""; // I have obviously set these variables to something meaningful, just hidden for the sake of security $apiPath = ""; $username = ""; $p...
[ { "answer_id": 329366, "author": "Dan Soap", "author_id": 25253, "author_profile": "https://Stackoverflow.com/users/25253", "pm_score": 1, "selected": false, "text": "<p>Without testing it, I have two suggestions:</p>\n\n<p>First, put your error_reporting to the highest possible (before ...
2008/11/26
[ "https://Stackoverflow.com/questions/322510", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have been working on a script with PHP4 that relies on NuSOAP. Now, I'm trying to move this to PHP5, and use the buildin support for SOAP there. ``` $wsdlPath = ""; // I have obviously set these variables to something meaningful, just hidden for the sake of security $apiPath = ""; $username = ""; $password = ""; ...
Make sure NuSoap and PHPv5-SOAP are running on the same server. If I'm not totally wrong, both libraries uses the same class-name. Maybe it will work better if you make sure none NuSopa-files are included? And also verify that the SOAP-library are loaded: ``` if(!extension_loaded('soap')){ dl('soap.so'); // Actually...
322,597
<p>It is to my understanding that one should use a forward-class declaration in the event ClassA needs to include a ClassB header, and ClassB needs to include a ClassA header to avoid any circular inclusions. I also understand that an <code>#import</code> is a simple <code>ifndef</code> so that an include only happens ...
[ { "answer_id": 322626, "author": "Marc Charbonneau", "author_id": 35136, "author_profile": "https://Stackoverflow.com/users/35136", "pm_score": 6, "selected": false, "text": "<p>Use a forward declaration in the header file if needed, and <code>#import</code> the header files for any clas...
2008/11/27
[ "https://Stackoverflow.com/questions/322597", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40882/" ]
It is to my understanding that one should use a forward-class declaration in the event ClassA needs to include a ClassB header, and ClassB needs to include a ClassA header to avoid any circular inclusions. I also understand that an `#import` is a simple `ifndef` so that an include only happens once. My inquiry is this...
If you see this warning: > > warning: receiver 'MyCoolClass' is a forward class and corresponding @interface may not exist > > > you need to `#import` the file, but you can do that in your implementation file (.m), and use the `@class` declaration in your header file. `@class` does not (usually) remove the need...
322,601
<p>This seems to me to be the kind of issue that would crop up all the time with SQL/database development, but then I'm new to all this, so forgive my ignorance.</p> <p>I have 2 tables:</p> <pre><code>CREATE TABLE [dbo].[Tracks]( [TrackStringId] [bigint] NOT NULL, [Id] [bigint] IDENTITY(1,1) NOT NULL, [Ti...
[ { "answer_id": 322616, "author": "Bill Karwin", "author_id": 20860, "author_profile": "https://Stackoverflow.com/users/20860", "pm_score": 5, "selected": true, "text": "<p>First, insert into <code>TrackStrings</code>, omitting the primary key column from the column list. This invokes it...
2008/11/27
[ "https://Stackoverflow.com/questions/322601", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14357/" ]
This seems to me to be the kind of issue that would crop up all the time with SQL/database development, but then I'm new to all this, so forgive my ignorance. I have 2 tables: ``` CREATE TABLE [dbo].[Tracks]( [TrackStringId] [bigint] NOT NULL, [Id] [bigint] IDENTITY(1,1) NOT NULL, [Time] [datetime] NOT NU...
First, insert into `TrackStrings`, omitting the primary key column from the column list. This invokes its `IDENTITY` column which generates a value automatically. ``` INSERT INTO [dbo].[TrackStrings] ([String]) VALUES ('some string'); ``` Second, insert into `Tracks` and specify as its `TrackStringId` the functio...
322,606
<p>I'm managing an established site which is currently in the process of being upgraded (completely replaced anew), but I'm worried that I'll lose all my Google indexing (that is, there will be a lot of pages in Google's index which won't exist in that place any more).</p> <p>The last time I upgraded a (different) sit...
[ { "answer_id": 322629, "author": "Federico A. Ramponi", "author_id": 18770, "author_profile": "https://Stackoverflow.com/users/18770", "pm_score": 2, "selected": false, "text": "<p>You can tune Google's view of your site, and probably notify its changes, from within <a href=\"http://www....
2008/11/27
[ "https://Stackoverflow.com/questions/322606", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9021/" ]
I'm managing an established site which is currently in the process of being upgraded (completely replaced anew), but I'm worried that I'll lose all my Google indexing (that is, there will be a lot of pages in Google's index which won't exist in that place any more). The last time I upgraded a (different) site, someone...
You need to put some rewrite rules in an .htaccess file. You can find lots of good information [here](http://httpd.apache.org/docs/1.3/misc/rewriteguide.html). It's for Apache 1.3, but it works for Apache 2, too. From that article, a sample for redirecting to files that have moved directories: ``` RewriteEngine on R...
322,607
<p>I run a small browser MMO, and I have a problem where a couple users are embedding scripts into their profile images, and using them to make attacks against said users, and my game in general. Is there a way to protect against this, or do I need to start blocking people from being able to use their own custom image...
[ { "answer_id": 322628, "author": "John T", "author_id": 36457, "author_profile": "https://Stackoverflow.com/users/36457", "pm_score": 0, "selected": false, "text": "<p>Some of the most common practices for validating image integrity include checking the <a href=\"http://en.wikipedia.org/...
2008/11/27
[ "https://Stackoverflow.com/questions/322607", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2227/" ]
I run a small browser MMO, and I have a problem where a couple users are embedding scripts into their profile images, and using them to make attacks against said users, and my game in general. Is there a way to protect against this, or do I need to start blocking people from being able to use their own custom images? ...
Most likely what is hapening is they are giving you a link to a script that is building the image and returning it on the fly, there is nothing aside from no allowing users to use external images, that you can do about it, one option to prevent it is to download and store the image on your server as opposed to linking ...
322,614
<p>I have the following Linq to SQL query, in which I'm trying to do a multi-column GROUP BY:</p> <pre><code>return from revision in dataContext.Revisions where revision.BranchID == sourceBranch.BranchID-1 &amp;&amp; !revision.HasBeenMerged group revision by new Task(revision.TaskSourceCo...
[ { "answer_id": 322636, "author": "Ana Betts", "author_id": 5728, "author_profile": "https://Stackoverflow.com/users/5728", "pm_score": 0, "selected": false, "text": "<p>I think you need a select before your group by - you want to convert objects to Tasks, then order by something else (Ta...
2008/11/27
[ "https://Stackoverflow.com/questions/322614", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41110/" ]
I have the following Linq to SQL query, in which I'm trying to do a multi-column GROUP BY: ``` return from revision in dataContext.Revisions where revision.BranchID == sourceBranch.BranchID-1 && !revision.HasBeenMerged group revision by new Task(revision.TaskSourceCode.ToUpper(), ...
Looks like you already have your solution, but just FYI LINQ to SQL does support `.ToUpper()`. For instance: ``` NorthwindDataContext dc = new NorthwindDataContext(); Product product = dc.Products.Single(p => p.ProductName.ToUpper() == "CHAI"); ``` Is translated into: ``` exec sp_executesql N'SELECT [t0].[Product...
322,657
<p>In jQuery, how do you select the <code>&lt;a&gt;</code> which href is pointing to the current URL</p> <p>For example:<br> URL = <a href="http://server/dir/script.aspx?id=1" rel="nofollow noreferrer">http://server/dir/script.aspx?id=1</a></p> <p>I want to select this <code>&lt;a&gt;</code><br> <code>&lt;a href="/di...
[ { "answer_id": 322667, "author": "Danny", "author_id": 26630, "author_profile": "https://Stackoverflow.com/users/26630", "pm_score": 1, "selected": false, "text": "<p>I do not know the answer to your question but is that selector syntax valid?</p>\n\n<pre><code>'#ulTopMenu a[\"http://www...
2008/11/27
[ "https://Stackoverflow.com/questions/322657", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36036/" ]
In jQuery, how do you select the `<a>` which href is pointing to the current URL For example: URL = <http://server/dir/script.aspx?id=1> I want to select this `<a>` `<a href="/dir/script.aspx">...</a>` I tried this but it doesn't work: ``` var url = window.location.href; $('#ulTopMenu a["'+url+'"*=href]').add...
Thanks Remy, it didn't really work but it's close. Here is my final code ``` var scriptname = GetUrlScriptname(); $('#ulTopMenu a[href$="' + scriptname + '"]').parent().addClass('selected'); function GetUrlScriptname() { var rex = new RegExp("\\/[^\\/]+\\.\\w+($|\\?)"); var match = rex.exec(location.pathna...
322,699
<p>Given an array of items, each of which has a <code>value</code> and <code>cost</code>, <strong>what's the best algorithm determine the items required to reach a minimum value at the minimum cost?</strong> eg:</p> <pre><code>Item: Value -&gt; Cost ------------------- A 20 -&gt; 11 B 7 -&gt; 5 C 1 ...
[ { "answer_id": 322714, "author": "ShreevatsaR", "author_id": 4958, "author_profile": "https://Stackoverflow.com/users/4958", "pm_score": 4, "selected": true, "text": "<p>This is the knapsack problem. (That is, the decision version of this problem is the same as the decision version of th...
2008/11/27
[ "https://Stackoverflow.com/questions/322699", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9021/" ]
Given an array of items, each of which has a `value` and `cost`, **what's the best algorithm determine the items required to reach a minimum value at the minimum cost?** eg: ``` Item: Value -> Cost ------------------- A 20 -> 11 B 7 -> 5 C 1 -> 2 MinValue = 30 naive solution: A + B + C + C + C. Va...
This is the knapsack problem. (That is, the decision version of this problem is the same as the decision version of the knapsack problem, although the optimization version of the knapsack problem is usually stated differently.) It is NP-hard (which means no algorithm is known that is polynomial in the "size" -- number ...
322,702
<p>sorry but I do not have the actual code with me, but I will try to explain:</p> <p>I have a servlet mapped to the following: </p> <pre><code>/admin/* </code></pre> <p>So, this goes to a servlet: </p> <pre><code>public class AdminController extends MainController { public void doPost(HttpServletRequest reque...
[ { "answer_id": 322735, "author": "carson", "author_id": 25343, "author_profile": "https://Stackoverflow.com/users/25343", "pm_score": 4, "selected": true, "text": "<p>The <a href=\"http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/http/HttpServlet.html#service(javax.servlet....
2008/11/27
[ "https://Stackoverflow.com/questions/322702", "https://Stackoverflow.com", "https://Stackoverflow.com/users/37190/" ]
sorry but I do not have the actual code with me, but I will try to explain: I have a servlet mapped to the following: ``` /admin/* ``` So, this goes to a servlet: ``` public class AdminController extends MainController { public void doPost(HttpServletRequest request, HttpServletResponse response) { ...
The [HttpServlet.service](http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/http/HttpServlet.html#service(javax.servlet.http.HttpServletRequest,%20javax.servlet.http.HttpServletResponse)) method gets called for all request types and what you are seeing is a HEAD request and then a GET or POST request. Inst...
322,715
<p>I've always been one to simply use:</p> <pre><code>List&lt;String&gt; names = new ArrayList&lt;&gt;(); </code></pre> <p>I use the interface as the type name for <em>portability</em>, so that when I ask questions such as this, I can rework my code.</p> <p>When should <a href="https://docs.oracle.com/javase/9/docs/api...
[ { "answer_id": 322722, "author": "dgtized", "author_id": 34450, "author_profile": "https://Stackoverflow.com/users/34450", "pm_score": 6, "selected": false, "text": "<p>It's an efficiency question. <code>LinkedList</code> is fast for adding and deleting elements, but slow to access a spe...
2008/11/27
[ "https://Stackoverflow.com/questions/322715", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41200/" ]
I've always been one to simply use: ``` List<String> names = new ArrayList<>(); ``` I use the interface as the type name for *portability*, so that when I ask questions such as this, I can rework my code. When should [`LinkedList`](https://docs.oracle.com/javase/9/docs/api/java/util/LinkedList.html) be used over [`...
**Summary** `ArrayList` with `ArrayDeque` are preferable in *many* more use-cases than `LinkedList`. If you're not sure — just start with `ArrayList`. --- TLDR, in `ArrayList` accessing an element takes constant time [O(1)] and adding an element takes O(n) time [worst case]. In `LinkedList` inserting an element takes...
322,749
<pre><code>public class doublePrecision { public static void main(String[] args) { double total = 0; total += 5.6; total += 5.8; System.out.println(total); } } </code></pre> <p>The above code prints:</p> <pre class="lang-none prettyprint-override"><code>11.399999999999 </code>...
[ { "answer_id": 322756, "author": "Paul Tomblin", "author_id": 3333, "author_profile": "https://Stackoverflow.com/users/3333", "pm_score": 2, "selected": false, "text": "<p>Multiply everything by 100 and store it in a long as cents.</p>\n" }, { "answer_id": 322758, "author": "...
2008/11/27
[ "https://Stackoverflow.com/questions/322749", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5219/" ]
``` public class doublePrecision { public static void main(String[] args) { double total = 0; total += 5.6; total += 5.8; System.out.println(total); } } ``` The above code prints: ```none 11.399999999999 ``` How would I get this to just print (or be able to use it as) 11.4?
As others have mentioned, you'll probably want to use the [`BigDecimal`](https://docs.oracle.com/javase/8/docs/api/java/math/BigDecimal.html) class, if you want to have an exact representation of 11.4. Now, a little explanation into why this is happening: The `float` and `double` primitive types in Java are [floating...
322,769
<p>Imagine you have an executable foo.rb, with libraries bar.rb layed out in the following manner:</p> <pre><code>&lt;root&gt;/bin/foo.rb &lt;root&gt;/lib/bar.rb </code></pre> <p>In the header of foo.rb you place the following require to bring in functionality in bar.rb:</p> <pre><code>require File.dirname(__FILE__)...
[ { "answer_id": 323455, "author": "Phil Ross", "author_id": 5981, "author_profile": "https://Stackoverflow.com/users/5981", "pm_score": 2, "selected": false, "text": "<p>You can use this function to follow any symlinks and return the full path of the real file:</p>\n\n<pre><code>def follo...
2008/11/27
[ "https://Stackoverflow.com/questions/322769", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34450/" ]
Imagine you have an executable foo.rb, with libraries bar.rb layed out in the following manner: ``` <root>/bin/foo.rb <root>/lib/bar.rb ``` In the header of foo.rb you place the following require to bring in functionality in bar.rb: ``` require File.dirname(__FILE__)+"../lib/bar.rb" ``` This works fine so long as...
I know this is ages old, but I just found this: ``` require 'pathname' APP_ROOT = File.join(File.dirname(Pathname.new(__FILE__).realpath),'..') ```
322,772
<p>I have following foreach-loop:</p> <pre><code>using System.IO; //... if (Directory.Exists(path)) { foreach(string strFile in Directory.GetFiles(path, "*.txt")) { // do something, possibly delete the file named strFile } } </code></pre> <p>Could there be side effects when deleting files in th...
[ { "answer_id": 322778, "author": "tvanfosson", "author_id": 12950, "author_profile": "https://Stackoverflow.com/users/12950", "pm_score": 4, "selected": true, "text": "<p>GetFiles returns an array, not an iterator so the operation is complete by the time you reference the first file. Al...
2008/11/27
[ "https://Stackoverflow.com/questions/322772", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26070/" ]
I have following foreach-loop: ``` using System.IO; //... if (Directory.Exists(path)) { foreach(string strFile in Directory.GetFiles(path, "*.txt")) { // do something, possibly delete the file named strFile } } ``` Could there be side effects when deleting files in the directory that is curren...
GetFiles returns an array, not an iterator so the operation is complete by the time you reference the first file. Also it only returns the file names, not a File handle so you should be completely safe doing any operation on it.
322,784
<p>I'm playing with Java for the first time and need to be able to replace some words in a template. example template - </p> <p>"Dear PUT_THEIR_NAME_HERE,</p> <p>I'm contacting you ..... bla bla bla</p> <p>Regards,</p> <p>PUT_COMPANY_NAME_HERE"</p> <p>What's the simplest way (preferably using the standard library)...
[ { "answer_id": 322793, "author": "Dustin", "author_id": 39975, "author_profile": "https://Stackoverflow.com/users/39975", "pm_score": 0, "selected": false, "text": "<p>I wrote a class for this when I ported an app to java ~10 years ago:</p>\n\n<p><a href=\"http://github.com/dustin/spyjar...
2008/11/27
[ "https://Stackoverflow.com/questions/322784", "https://Stackoverflow.com", "https://Stackoverflow.com/users/37196/" ]
I'm playing with Java for the first time and need to be able to replace some words in a template. example template - "Dear PUT\_THEIR\_NAME\_HERE, I'm contacting you ..... bla bla bla Regards, PUT\_COMPANY\_NAME\_HERE" What's the simplest way (preferably using the standard library) to make a copy of this template...
You're looking for java.text.MessageFormat: Here are some examples of usage (from JavaDoc): ``` Object[] arguments = { new Integer(7), new Date(System.currentTimeMillis()), "a disturbance in the Force" }; String result = MessageFormat.format( "At {1,time} on {1,date}, there was {2} on planet {...
322,792
<p>I've been working on a program to read a dbf file, mess around with the data, and save it back to dbf. The problem that I am having is specifically to do with the writing portion.</p> <pre><code> private const string constring = "Driver={Microsoft dBASE Driver (*.dbf)};" + "Sou...
[ { "answer_id": 325744, "author": "Eyvind", "author_id": 25746, "author_profile": "https://Stackoverflow.com/users/25746", "pm_score": 2, "selected": false, "text": "<p>What kind of dbf file are you working with? (There are several, e.g. dBase, FoxPro etc that are not 100% compatible.) I ...
2008/11/27
[ "https://Stackoverflow.com/questions/322792", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41223/" ]
I've been working on a program to read a dbf file, mess around with the data, and save it back to dbf. The problem that I am having is specifically to do with the writing portion. ``` private const string constring = "Driver={Microsoft dBASE Driver (*.dbf)};" + "SourceType=DBF;" ...
For people coming here in the future: I wrote this today and it works well. The filename is without the extension (.dbf). The path (used for connection) is the directory path only (no file). You can add your datatable to a dataset and pass it in. Also, some of my datatypes are foxpro data types and may not be compatibl...
322,837
<p>I want to do this, but haven't figured it quite out yet...</p> <pre><code> $(document).ready(function() { $("a.whateverclass").click(function() { $("div.whateverclass").show(); return false; }); </code></pre> <p>Basically when a link with a certain class is clicked all di...
[ { "answer_id": 322844, "author": "Eran Galperin", "author_id": 10585, "author_profile": "https://Stackoverflow.com/users/10585", "pm_score": 1, "selected": false, "text": "<pre><code>$(\"a\").click(function() {\n $(\"div.\" + $(this).attr('class')).show();\n});\n</code></pre>\n" ...
2008/11/27
[ "https://Stackoverflow.com/questions/322837", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34133/" ]
I want to do this, but haven't figured it quite out yet... ``` $(document).ready(function() { $("a.whateverclass").click(function() { $("div.whateverclass").show(); return false; }); ``` Basically when a link with a certain class is clicked all divs with that class are sho...
I like @Eran's answer, but in event that you have some links that don't fit this pattern, you may want to make sure that you only apply this to links that do. ``` $('a[class]').click(function() { $('div.' + $(this).attr('class')).show(); return false; }); ``` And in the case where links may have other classe...
322,839
<p>How to query to get count of matching words in a field, specifically in MySQL. simply i need to get how many times a "search terms"appear in the field value.</p> <p>for example, the value is "one two one onetwo" so when i search for word "one" it should give me 3</p> <p>is it possible? because currently i just ext...
[ { "answer_id": 322851, "author": "Wobin", "author_id": 15010, "author_profile": "https://Stackoverflow.com/users/15010", "pm_score": 2, "selected": false, "text": "<p>Are you looking to find a query that, given a list of words, returns the number of matching words in a database field?</p...
2008/11/27
[ "https://Stackoverflow.com/questions/322839", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19463/" ]
How to query to get count of matching words in a field, specifically in MySQL. simply i need to get how many times a "search terms"appear in the field value. for example, the value is "one two one onetwo" so when i search for word "one" it should give me 3 is it possible? because currently i just extract the value ou...
You could create a function to be used directly within SQL, in order to do it all in one step. Here is [a function which I found on the MySQL website](http://dev.mysql.com/doc/refman/5.0/en/string-functions.html) : ``` delimiter || DROP FUNCTION IF EXISTS substrCount|| CREATE FUNCTION substrCount(s VARCHAR(255), ss ...
322,842
<p>OK, this is an odd request, and it might not even be fully true... but I'm upgrading someone's system ... and they are using OSCommerce (from a long time ago).</p> <p>It appears their variables are referrenced without a dollar sign in front of them (which is new to me). I haven't done PHP in about 7 years, and I've...
[ { "answer_id": 322847, "author": "Christian C. Salvadó", "author_id": 5445, "author_profile": "https://Stackoverflow.com/users/5445", "pm_score": 0, "selected": false, "text": "<p>You can use <a href=\"http://www.php.net/constant\" rel=\"nofollow noreferrer\">constants</a>.</p>\n" }, ...
2008/11/27
[ "https://Stackoverflow.com/questions/322842", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11917/" ]
OK, this is an odd request, and it might not even be fully true... but I'm upgrading someone's system ... and they are using OSCommerce (from a long time ago). It appears their variables are referrenced without a dollar sign in front of them (which is new to me). I haven't done PHP in about 7 years, and I've always us...
I believe OSCommerce actually DEFINES these values, so the usage is correct (without the $). Look for ``` define("DB_SERVER", "localhost"); ``` or something similar. In other words, do *not* go through and update these with a $ before if they're actually defined constants.
322,866
<p>I'm getting the following error when trying to compile C++ projects using intel compiler version 10.0.025 on vista business edition (sp1) in vs2008:</p> <pre><code>unable to obtain mapped memory (see pch_diag.txt) </code></pre> <p>There is no such file as pch_diag, so that's a bit disheartening. </p> <p>If I try...
[ { "answer_id": 322915, "author": "bk1e", "author_id": 8090, "author_profile": "https://Stackoverflow.com/users/8090", "pm_score": 0, "selected": false, "text": "<p>It sounds like you are running the compiler as a standard user (good for you!), and the errors you get with the Microsoft co...
2008/11/27
[ "https://Stackoverflow.com/questions/322866", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21981/" ]
I'm getting the following error when trying to compile C++ projects using intel compiler version 10.0.025 on vista business edition (sp1) in vs2008: ``` unable to obtain mapped memory (see pch_diag.txt) ``` There is no such file as pch\_diag, so that's a bit disheartening. If I try to just use the microsoft compil...
Here's the answer: Run icl in xp sp2 compatibility mode. It won't work in vista mode. Which is a bit odd, but there it is.
322,912
<p>Using jQuery, <strong>how do you match elements that are prior to the current element in the DOM tree?</strong> Using <code>prevAll()</code> only matches previous siblings.</p> <p>eg:</p> <pre><code>&lt;table&gt; &lt;tr&gt; &lt;td class="findme"&gt;find this one&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt...
[ { "answer_id": 322928, "author": "tvanfosson", "author_id": 12950, "author_profile": "https://Stackoverflow.com/users/12950", "pm_score": 1, "selected": false, "text": "<p>Presumably you are doing this inside an onclick handler so you have access to the element that was clicked. What I ...
2008/11/27
[ "https://Stackoverflow.com/questions/322912", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9021/" ]
Using jQuery, **how do you match elements that are prior to the current element in the DOM tree?** Using `prevAll()` only matches previous siblings. eg: ``` <table> <tr> <td class="findme">find this one</td> </tr> <tr> <td><a href="#" class="myLinks">find the previous .findme</a></td> ...
Ok, here's what I've come up with - hopefully it'll be useful in many different situations. It's 2 extensions to jQuery that I call `prevALL` and `nextALL`. While the standard `prevAll()` matches previous siblings, `prevALL()` matches ALL previous elements all the way up the DOM tree, similarly for `nextAll()` and `nex...
322,926
<p>How would you get a reference to an executing class several stack frames above the current one? For example, if you have:</p> <pre><code>Class a { foo() { new b().bar(); } } Class b { bar() { ... } } </code></pre> <p> Is there a way to get the value that would be retrieved by usi...
[ { "answer_id": 322930, "author": "matt b", "author_id": 4249, "author_profile": "https://Stackoverflow.com/users/4249", "pm_score": 0, "selected": false, "text": "<p><code>this</code> is always a reference to the current instance of the object. So any usage of <code>this</code> in <code>...
2008/11/27
[ "https://Stackoverflow.com/questions/322926", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41241/" ]
How would you get a reference to an executing class several stack frames above the current one? For example, if you have: ``` Class a { foo() { new b().bar(); } } Class b { bar() { ... } } ``` Is there a way to get the value that would be retrieved by using 'this' in foo() while the...
No, you can't. In all the languages that use a stack that I know of, the contents of other stack frames are hidden from you. There are a few things you can do to get it, beyond the obvious passing it as a parameter. One of the aspect oriented frameworks might get you something. Also, you can get a bit of debugging info...
322,929
<p>I'm looking for a cross-browser way of wrapping long portions of text that have no breaking spaces (e.g. long URLs) inside of divs with pre-determined widths.</p> <p>Here are some solutions I've found around the web and why they <strong>don't</strong> work for me:</p> <ul> <li><strong>overflow : hidden / auto / sc...
[ { "answer_id": 322956, "author": "seanb", "author_id": 3354, "author_profile": "https://Stackoverflow.com/users/3354", "pm_score": 1, "selected": false, "text": "<p>There was a loosely related problem here <a href=\"https://stackoverflow.com/questions/33933/textarea-with-100-width-ignore...
2008/11/27
[ "https://Stackoverflow.com/questions/322929", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20689/" ]
I'm looking for a cross-browser way of wrapping long portions of text that have no breaking spaces (e.g. long URLs) inside of divs with pre-determined widths. Here are some solutions I've found around the web and why they **don't** work for me: * **overflow : hidden / auto / scroll** - I need the entire text to be vi...
I've typically handled this using a combination of `word-wrap` and the `<wbr>` idea. note there are a few [variants](http://www.quirksmode.org/oddsandends/wbr.html). as you can see, `&#8203;` is probably your best bet for compatibility. `word-wrap` browser support isn't *terrible*, all things considered, Safari, Inter...
322,936
<p>I'm trying to consolidate some build information by using a common makefile. My problem is that I want to use that makefile from different subdirectory levels, which makes the working directory value (<code>pwd</code>) unpredictable. For example:</p> <pre><code># Makefile.common TOP := $(shell pwd) COMPONENT_DIR :=...
[ { "answer_id": 322946, "author": "tvanfosson", "author_id": 12950, "author_profile": "https://Stackoverflow.com/users/12950", "pm_score": 2, "selected": false, "text": "<p>Have you tried doing:</p>\n\n<pre><code># Makefile.common\nTOP ?= $(shell pwd)\nCOMPONENT_DIR := $(TOP)/component\nC...
2008/11/27
[ "https://Stackoverflow.com/questions/322936", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3594/" ]
I'm trying to consolidate some build information by using a common makefile. My problem is that I want to use that makefile from different subdirectory levels, which makes the working directory value (`pwd`) unpredictable. For example: ``` # Makefile.common TOP := $(shell pwd) COMPONENT_DIR := $(TOP)/component COMPONE...
You should be able to use the [MAKEFILE\_LIST variable](http://www.gnu.org/software/make/manual/html_node/Special-Variables.html#Special-Variables), like this: ``` # This must be the first line in Makefile.common TOP := $(dir $(firstword $(MAKEFILE_LIST))) ``` From the documentation: > > As make reads various mak...
322,938
<p>I need a 'good' way to initialize the pseudo-random number generator in C++. I've found <a href="http://www.cplusplus.com/reference/clibrary/cstdlib/srand.html" rel="noreferrer">an article</a> that states:</p> <blockquote> <p>In order to generate random-like numbers, srand is usually initialized to some disti...
[ { "answer_id": 322961, "author": "Evan Teran", "author_id": 13430, "author_profile": "https://Stackoverflow.com/users/13430", "pm_score": 4, "selected": false, "text": "<p>if you need a better random number generator, don't use the libc rand. Instead just use something like <code>/dev/ra...
2008/11/27
[ "https://Stackoverflow.com/questions/322938", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2506/" ]
I need a 'good' way to initialize the pseudo-random number generator in C++. I've found [an article](http://www.cplusplus.com/reference/clibrary/cstdlib/srand.html) that states: > > In order to generate random-like > numbers, srand is usually initialized > to some distinctive value, like those > related with the e...
The best answer is to use [`<random>`](http://en.cppreference.com/w/cpp/header/random). If you are using a pre C++11 version, you can look at the Boost random number stuff. But if we are talking about `rand()` and `srand()` The best simplest way is just to use `time()`: ``` int main() { srand(time(nullptr)); ...
322,941
<p>Is there a particular scenario where a <code>WriteOnly</code> property makes more sense then a method? The method approach feels much more natural to me. </p> <p>What is the right approach?</p> <p><strong>Using Properties</strong>:</p> <pre class="lang-vb prettyprint-override"><code>Public WriteOnly Property MyPr...
[ { "answer_id": 322950, "author": "Andrew Kennan", "author_id": 22506, "author_profile": "https://Stackoverflow.com/users/22506", "pm_score": 5, "selected": true, "text": "<p>I think a property indicates something that can be read-only or read/write. The behaviour of a write-only property...
2008/11/27
[ "https://Stackoverflow.com/questions/322941", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17744/" ]
Is there a particular scenario where a `WriteOnly` property makes more sense then a method? The method approach feels much more natural to me. What is the right approach? **Using Properties**: ```vb Public WriteOnly Property MyProperty As String Set(ByVal value as String) m_myField = value End Set End P...
I think a property indicates something that can be read-only or read/write. The behaviour of a write-only property is not obvious so I avoid creating them. As an example, setting a list of values in a drop-down on a view and accessing the selected item: ``` public interface IWidgetSelector { void SetAvailableWidget...
322,971
<p>I want to cast both MenuItem objects and Button control objects to an object type of whose "Tag" property I can reference.</p> <p>Is there such an object type?</p> <p>E.g.</p> <pre><code>void itemClick(object sender, EventArgs e) { Control c = (Control)sender; MethodInvoker method = new MethodInvoker(c.Ta...
[ { "answer_id": 322982, "author": "ChrisPelatari", "author_id": 5485, "author_profile": "https://Stackoverflow.com/users/5485", "pm_score": 0, "selected": false, "text": "<p>Control is what you're looking for.</p>\n" }, { "answer_id": 322996, "author": "Tim Jarvis", "autho...
2008/11/27
[ "https://Stackoverflow.com/questions/322971", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5019/" ]
I want to cast both MenuItem objects and Button control objects to an object type of whose "Tag" property I can reference. Is there such an object type? E.g. ``` void itemClick(object sender, EventArgs e) { Control c = (Control)sender; MethodInvoker method = new MethodInvoker(c.Tag.ToString(), "Execute"); ...
Use "as" operator. ``` object tag; Button button; MenuItem menuItem = sender as MenuItem; if (menuItem != null) { tag = menuItem.Tag; } else if( (button = sender as Button) != null ) { tag = button.Tag; } else { //not button nor MenuItem } ```
323,019
<p>I'm at step 8 of the authentication overview found here: <a href="http://wiki.developers.facebook.com/index.php/How_Connect_Authentication_Works" rel="noreferrer">http://wiki.developers.facebook.com/index.php/How_Connect_Authentication_Works</a></p> <p>In particular, the user has logged into facebook via Facebook C...
[ { "answer_id": 333267, "author": "ckarbass", "author_id": 67719, "author_profile": "https://Stackoverflow.com/users/67719", "pm_score": 4, "selected": false, "text": "<p>Facebook Connect actually isn't too difficult, there's just a lack of documentation.</p>\n\n<p>Put the necessary javas...
2008/11/27
[ "https://Stackoverflow.com/questions/323019", "https://Stackoverflow.com", "https://Stackoverflow.com/users/67719/" ]
I'm at step 8 of the authentication overview found here: <http://wiki.developers.facebook.com/index.php/How_Connect_Authentication_Works> In particular, the user has logged into facebook via Facebook Connect and their web session has been created. How do I use the facebook developer toolkit v2.0 (from clarity) to retr...
I had a lot of trouble figuring out how to make server side calls once a user logged in with Facebook Connect. The key is that the Facebook Connect javascript sets cookies on the client once there's a successful login. You use the values of these cookies to perform API calls on the server. The confusing part was looki...
323,032
<p>I want to generate a list in C#. I am missing python's list comprehensions. Is there a C# way to create collections on the fly like list comprehensions or generator expressions do in python?</p>
[ { "answer_id": 323039, "author": "Matt Campbell", "author_id": 41110, "author_profile": "https://Stackoverflow.com/users/41110", "pm_score": 6, "selected": true, "text": "<p>If you are using C# 3.0 (VS2008) then LINQ to Objects can do very similar things:</p>\n\n<pre><code>List&lt;Foo&gt...
2008/11/27
[ "https://Stackoverflow.com/questions/323032", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4491/" ]
I want to generate a list in C#. I am missing python's list comprehensions. Is there a C# way to create collections on the fly like list comprehensions or generator expressions do in python?
If you are using C# 3.0 (VS2008) then LINQ to Objects can do very similar things: ``` List<Foo> fooList = new List<Foo>(); IEnumerable<Foo> extract = from foo in fooList where foo.Bar > 10 select Foo.Name.ToUpper(); ```
323,063
<p>I have this html...</p> <pre><code>&lt;select id="View" name="View"&gt; &lt;option value="1"&gt;With issue covers&lt;/option&gt; &lt;option value="0"&gt;No issue covers&lt;/option&gt; &lt;/select&gt; </code></pre> <p>It won't let me insert code like this...</p> <pre><code>&lt;select id="View" name="View"&g...
[ { "answer_id": 323164, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 3, "selected": false, "text": "<p>The \"best\" approach is probably to <em>use</em> the helpers:</p>\n\n<pre><code>var selectList = new SelectList(d...
2008/11/27
[ "https://Stackoverflow.com/questions/323063", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1231/" ]
I have this html... ``` <select id="View" name="View"> <option value="1">With issue covers</option> <option value="0">No issue covers</option> </select> ``` It won't let me insert code like this... ``` <select id="View" name="View"> <option value="1" <% ..logic code..%> >With issue covers</option> <opt...
I would agree with Marc on using helpers but if you must avoid them then you could try something like the following: ``` <select id="View" name="View"> <option value="1" <% if (something) { %> selected <% } %> >With issue covers</option> <option value="0" <% if (!something) { %> selected <% } %> >No issue covers...
323,064
<p>I am using <code>GridView</code> in my application for populating datas. </p> <p>Is there any easy way to copy a gridview to datatable ?</p> <p>Actually, in my <code>GridView</code> one of the control is textbox.<br> So I can edit that control at any time... What I need is on the button click whatever changes I ma...
[ { "answer_id": 323615, "author": "Sergiu Damian", "author_id": 41345, "author_profile": "https://Stackoverflow.com/users/41345", "pm_score": 1, "selected": false, "text": "<p>The preferable way would be to use data binding. If you manage to get bidirectional data binding to work, your Da...
2008/11/27
[ "https://Stackoverflow.com/questions/323064", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41014/" ]
I am using `GridView` in my application for populating datas. Is there any easy way to copy a gridview to datatable ? Actually, in my `GridView` one of the control is textbox. So I can edit that control at any time... What I need is on the button click whatever changes I made in `GridView` has to copy in one data...
html page look like, ``` <asp:GridView ID="Grid1" runat="server" AutoGenerateColumns="False" GridLines="None"> <Columns> <asp:TemplateField HeaderText="ID"> <ItemTemplate> ...
323,073
<p>In Vc++ 6.0 mscomm control,please any body explain this function How it works ,what it does</p> <pre><code>if (m_comm.GetCommEvent()==2 ) { VARIANT in_dat; in_dat = m_comm.GetInput(); CString strInput(in_dat.bstrVal); m_input = m_input + strInput; ...
[ { "answer_id": 323186, "author": "HS.", "author_id": 1398, "author_profile": "https://Stackoverflow.com/users/1398", "pm_score": 1, "selected": false, "text": "<p>The code checks whether a comm event occured. If it did, then the input data is obtained from the control and appended to m_i...
2008/11/27
[ "https://Stackoverflow.com/questions/323073", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
In Vc++ 6.0 mscomm control,please any body explain this function How it works ,what it does ``` if (m_comm.GetCommEvent()==2 ) { VARIANT in_dat; in_dat = m_comm.GetInput(); CString strInput(in_dat.bstrVal); m_input = m_input + strInput; UpdateData...
The code checks whether a comm event occured. If it did, then the input data is obtained from the control and appended to m\_input. Afterwards, the data is updated. The code does not offer much more insight.
323,079
<p>First time posting to a questions site, but I sort of have a complex problem i've been looking at for a few days.</p> <p><b>Background</b> At work we're implementing a new billing system. However, we want to take the unprecedented move of actually auditing the new billing system against the old one which is signifi...
[ { "answer_id": 323084, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 1, "selected": false, "text": "<p>Actually, for the above type of query, the <a href=\"http://code.msdn.microsoft.com/Project/Download/FileDownload....
2008/11/27
[ "https://Stackoverflow.com/questions/323079", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
First time posting to a questions site, but I sort of have a complex problem i've been looking at for a few days. **Background** At work we're implementing a new billing system. However, we want to take the unprecedented move of actually auditing the new billing system against the old one which is significantly more r...
Actually, for the above type of query, the [dynamic LINQ](http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=csharpsamples&DownloadId=51) stuff is quite a good fit. Otherwise you'll have to write pretty-much the same anyway - a parser, and a mechanism for mapping that to attributes. Unfortuna...
323,088
<p>I have the following code in my Site.Master page of an almost empty ASP.NET MVC Project. </p> <pre><code>&lt;li&gt; &lt;%= Html.ActionLink("Home", "Index", "Home")%&gt; &lt;/li&gt; &lt;li&gt; &lt;%= Html.ActionLink("Feed List", "FeedList", "Home")%&gt; &lt;/li&gt; &lt;li&gt; &lt;%= Html.ActionLink("Mon...
[ { "answer_id": 323100, "author": "Franck", "author_id": 38072, "author_profile": "https://Stackoverflow.com/users/38072", "pm_score": 3, "selected": false, "text": "<p>Your controller is called \"Home\", therefore your views should be in the Views/Home folder, not in Views/Feeds.</p>\n\n...
2008/11/27
[ "https://Stackoverflow.com/questions/323088", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29345/" ]
I have the following code in my Site.Master page of an almost empty ASP.NET MVC Project. ``` <li> <%= Html.ActionLink("Home", "Index", "Home")%> </li> <li> <%= Html.ActionLink("Feed List", "FeedList", "Home")%> </li> <li> <%= Html.ActionLink("Monitored Feeds", "MonitoredFeeds", "Home")%> </li> <li> <%...
Create a FeedsController.cs and move these to that controller ``` public ActionResult FeedList() { ViewData["Title"] = "Feed List"; return View(); } public ActionResult MonitoredFeeds() { ViewData["Title"] = "Monitored Feeds"; return View(); } ``` Then fix these to use the Feeds controller ``` <li>...
323,126
<p>I have a gdi+ bitmap, and I want to convert bitmap into HBitmap. I write the following code.</p> <pre><code> HBITMAP temp; Color color; img-&gt;GetHBITMAP(color, &amp;temp); </code></pre> <p>But It do not work, How can I get a HBitmap?</p>
[ { "answer_id": 323185, "author": "Jeroen Heijmans", "author_id": 30748, "author_profile": "https://Stackoverflow.com/users/30748", "pm_score": 0, "selected": false, "text": "<p>This is of course a subjective question, but I have good experiences on with <a href=\"http://script.aculo.us/\...
2008/11/27
[ "https://Stackoverflow.com/questions/323126", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25749/" ]
I have a gdi+ bitmap, and I want to convert bitmap into HBitmap. I write the following code. ``` HBITMAP temp; Color color; img->GetHBITMAP(color, &temp); ``` But It do not work, How can I get a HBitmap?
I like the [Yahoo UI Autocomplete widget](http://developer.yahoo.com/yui/autocomplete/). It does not provide the dropdown natively, but a dropdown button can be added with [a few lines of code](http://tech.groups.yahoo.com/group/ydn-javascript/message/30178).
323,131
<p>I am using C# and trying to read a <code>CSV</code> by using this connection string;</p> <blockquote> <pre><code>Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\rajesh.yadava\Desktop\orcad;Extended Properties="Text;HDR=YES;IMEX=1;FMT=Delimited" </code></pre> </blockquote> <p>This works for ...
[ { "answer_id": 323152, "author": "bob", "author_id": 23805, "author_profile": "https://Stackoverflow.com/users/23805", "pm_score": 2, "selected": false, "text": "<p>Is the <a href=\"http://filehelpers.sourceforge.net/\" rel=\"nofollow noreferrer\">filehelpers</a> library an option?</p>\n...
2008/11/27
[ "https://Stackoverflow.com/questions/323131", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I am using C# and trying to read a `CSV` by using this connection string; > > > ``` > Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\rajesh.yadava\Desktop\orcad;Extended Properties="Text;HDR=YES;IMEX=1;FMT=Delimited" > > ``` > > This works for tab delimited data. I want a connection str...
Is the [filehelpers](http://filehelpers.sourceforge.net/) library an option?
323,133
<p>Searched stackoverflow for this and found no answer</p> <p>Coming from Ruby On Rails and Rspec, I need a tool like rspec (easier transition). Installed it through PEAR and tried to run it but it's not working (yet)</p> <p>Just wanna ask around if anyone's using it have the same problem, since it's not running at a...
[ { "answer_id": 323995, "author": "Wieczo", "author_id": 4195, "author_profile": "https://Stackoverflow.com/users/4195", "pm_score": 0, "selected": false, "text": "<p>I also couldn't get it to run, but you can also use BDD with PHPUnit. Check the <a href=\"http://www.phpunit.de/manual/3.3...
2008/11/27
[ "https://Stackoverflow.com/questions/323133", "https://Stackoverflow.com", "https://Stackoverflow.com/users/33552/" ]
Searched stackoverflow for this and found no answer Coming from Ruby On Rails and Rspec, I need a tool like rspec (easier transition). Installed it through PEAR and tried to run it but it's not working (yet) Just wanna ask around if anyone's using it have the same problem, since it's not running at all tried running...
Development on PHPSpec has restarted since August 2010, after a 2 years break. The code base looks more stable now. I would give another try. The website is now located at www.phpspec.net You can find the documentation at <http://www.phpspec.net/documentation>. It is basically an update of the first version. Should ...
323,147
<p>In Flex I'm using the following code to allow sorting in a DataGrid (the data is paged and sorted serverside).</p> <pre> private function headerReleaseHandler(event:DataGridEvent):void { var column:DataGridColumn = DataGridColumn(event.currentTarget.columns[event.columnIndex]); ...
[ { "answer_id": 387846, "author": "shadenite", "author_id": 47130, "author_profile": "https://Stackoverflow.com/users/47130", "pm_score": 4, "selected": true, "text": "<p>There is an example here if this is what you are looking for:\n<a href=\"http://blog.flexexamples.com/2008/02/28/displ...
2008/11/27
[ "https://Stackoverflow.com/questions/323147", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40939/" ]
In Flex I'm using the following code to allow sorting in a DataGrid (the data is paged and sorted serverside). ``` private function headerReleaseHandler(event:DataGridEvent):void { var column:DataGridColumn = DataGridColumn(event.currentTarget.columns[event.columnIndex]); if(t...
There is an example here if this is what you are looking for: <http://blog.flexexamples.com/2008/02/28/displaying-the-sort-arrow-in-a-flex-datagrid-control-without-having-to-click-a-column/> It looks like you need to refresh the collection used by your dataprovider.
323,148
<p>I have a site with over 100 pages. We need to go live with products that are soon available, however, many site pages will not be prepared at the time of release.</p> <p>In order to move forward, I would like to reference a "coming soon" page with links to pages that are current and available.</p> <p>Is there an e...
[ { "answer_id": 323166, "author": "Henrik Paul", "author_id": 2238, "author_profile": "https://Stackoverflow.com/users/2238", "pm_score": 2, "selected": false, "text": "<p>Perhaps a better or \"more correct way\" would be to do the redirection at the header level. Using PHP, you would cal...
2008/11/27
[ "https://Stackoverflow.com/questions/323148", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40091/" ]
I have a site with over 100 pages. We need to go live with products that are soon available, however, many site pages will not be prepared at the time of release. In order to move forward, I would like to reference a "coming soon" page with links to pages that are current and available. Is there an easy way to forwar...
Perhaps a better or "more correct way" would be to do the redirection at the header level. Using PHP, you would call ``` <?php header("Location: http://www.yourdomain.com/index.html"); ``` There's also ways to do this in Apache (assuming you are using it) and `.htaccess`-files. See <http://www.webweaver.nu/html-tips...
323,161
<p>I've implemented an object factory to lookup LDAP objects, but the supplied context does not return the DN (via nameCtx.getNameInNamespace()) from the LDAP. Am i doing it wrong in some way?</p> <pre><code>public class LdapPersonFactory implements DirObjectFactory { @Override public Object getObjectI...
[ { "answer_id": 323188, "author": "cagcowboy", "author_id": 19629, "author_profile": "https://Stackoverflow.com/users/19629", "pm_score": 0, "selected": false, "text": "<p>Maybe?</p>\n\n<pre><code>String dn = (String) attrs.get(\"dn\").get();\n</code></pre>\n\n<p>It should be an attribute...
2008/11/27
[ "https://Stackoverflow.com/questions/323161", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20297/" ]
I've implemented an object factory to lookup LDAP objects, but the supplied context does not return the DN (via nameCtx.getNameInNamespace()) from the LDAP. Am i doing it wrong in some way? ``` public class LdapPersonFactory implements DirObjectFactory { @Override public Object getObjectInstance(Object...
``` String dn = (String) attrs.get("dn").get(); ``` this throws a `NamingException` only. I don't think that the distinguished name (DN) is an attribute of the LDAP object, it's more like an identity key in the LDAP-world.
323,163
<p>Please, I am new to webparts and I need help!!</p> <p>I have a custom web part that I created. I added MS Ajax to it using an UpdatePanel which works fine. I add all my controls to the CreateChildControls method. As soon as I add a UpdateProgress control my page breaks with the following error:</p> <p>Script contr...
[ { "answer_id": 324414, "author": "Pedrin", "author_id": 36183, "author_profile": "https://Stackoverflow.com/users/36183", "pm_score": 1, "selected": false, "text": "<p>You might have forgotten to call the base method of an overrided event, which is not necessarily the OnPreRender event.<...
2008/11/27
[ "https://Stackoverflow.com/questions/323163", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Please, I am new to webparts and I need help!! I have a custom web part that I created. I added MS Ajax to it using an UpdatePanel which works fine. I add all my controls to the CreateChildControls method. As soon as I add a UpdateProgress control my page breaks with the following error: Script controls may not be re...
I encountered similar problem before, try to call EnsureChildControls method inside your on init method override. It should be called by system automatically, but sharepoint likes to forget about it from time to time. Like this: ``` protected override void OnInit(EventArgs e) { base.OnInit(e); ...
323,179
<p>I have set up a cruisecontrol.net build server. When running it in console mode it works fine, but when trying to run it as a windows service it doesn't work. The log file shows the following message:</p> <pre><code>ThoughtWorks.CruiseControl.Core.CruiseControlException: Source control operation failed: No VSS dat...
[ { "answer_id": 323253, "author": "David A Gibson", "author_id": 982, "author_profile": "https://Stackoverflow.com/users/982", "pm_score": 4, "selected": true, "text": "<p>Not sure if it's applicable but when I had problems switching between the Console version and the Service version it ...
2008/11/27
[ "https://Stackoverflow.com/questions/323179", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41276/" ]
I have set up a cruisecontrol.net build server. When running it in console mode it works fine, but when trying to run it as a windows service it doesn't work. The log file shows the following message: ``` ThoughtWorks.CruiseControl.Core.CruiseControlException: Source control operation failed: No VSS database (srcsafe...
Not sure if it's applicable but when I had problems switching between the Console version and the Service version it was down to access rights for the user I was starting the service as. Perhaps the Service does not have access rights to the srcsafe.ini file and your account does(assuming that's what your using to ru...
323,189
<p>I'm making a simple IRC Bot in C. And I finally got the bot connecting and receiving information. My code is supposed to be sending as well, but the server is acting as if it is not sending anything. When The bot connects, I receive this:</p> <blockquote> <p>Recieved: :roc.esper.net NOTICE AUTH :*** Looking up ...
[ { "answer_id": 323195, "author": "schnaader", "author_id": 34065, "author_profile": "https://Stackoverflow.com/users/34065", "pm_score": 1, "selected": false, "text": "<p>From the tutorials I looked at (like <a href=\"http://www.haskell.org/haskellwiki/Roll_your_own_IRC_bot\" rel=\"nofol...
2008/11/27
[ "https://Stackoverflow.com/questions/323189", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2128/" ]
I'm making a simple IRC Bot in C. And I finally got the bot connecting and receiving information. My code is supposed to be sending as well, but the server is acting as if it is not sending anything. When The bot connects, I receive this: > > Recieved: :roc.esper.net NOTICE AUTH > :\*\*\* Looking up your hostname......
Try sending the USER command before the NICK command. What IRC network are you trying to connect to? ``` " > telnet irc.freenode.net 6667 NOTICE AUTH :*** Looking up your hostname... NOTICE AUTH :*** Checking ident NOTICE AUTH :*** No identd (auth) response NOTICE AUTH :*** Couldn't look up your hostname USER x x x x ...
323,226
<p>Two ways to normalize a Vector3 object; by calling Vector3.Normalize() and the other by normalizing from scratch:</p> <pre><code>class Tester { static Vector3 NormalizeVector(Vector3 v) { float l = v.Length(); return new Vector3(v.X / l, v.Y / l, v.Z / l); } public static void Main(...
[ { "answer_id": 323228, "author": "schnaader", "author_id": 34065, "author_profile": "https://Stackoverflow.com/users/34065", "pm_score": 0, "selected": false, "text": "<p>Don't care about this. There's always some error involved when using floats. If you're curious, try changing to doubl...
2008/11/27
[ "https://Stackoverflow.com/questions/323226", "https://Stackoverflow.com", "https://Stackoverflow.com/users/45603/" ]
Two ways to normalize a Vector3 object; by calling Vector3.Normalize() and the other by normalizing from scratch: ``` class Tester { static Vector3 NormalizeVector(Vector3 v) { float l = v.Length(); return new Vector3(v.X / l, v.Y / l, v.Z / l); } public static void Main(string[] args)...
Look how they implemented it (e.g. in asm). Maybe they wanted to be faster and produced something like: ``` l = 1 / v.length(); return new Vector3(v.X * l, v.Y * l, v.Z * l); ``` to trade 2 divisions against 3 multiplications (because they thought mults were faster than divs (which is for modern fpus most often n...
323,230
<p>We have a JavaEE server and servlets providing data to mobile clients (first JavaME, now soon iPhone). The servlet writes out data using the following code:</p> <pre><code>DataOutputStream dos = new DataOutputStream(out); dos.writeInt(someInt); dos.writeUTF(someString); </code></pre> <p>... and so on</p> <p>Thi...
[ { "answer_id": 323239, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 1, "selected": false, "text": "<p>The main thing is to understand the binary data format itself. It doesn't matter what's written it, so long as you kn...
2008/11/27
[ "https://Stackoverflow.com/questions/323230", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
We have a JavaEE server and servlets providing data to mobile clients (first JavaME, now soon iPhone). The servlet writes out data using the following code: ``` DataOutputStream dos = new DataOutputStream(out); dos.writeInt(someInt); dos.writeUTF(someString); ``` ... and so on This data is returned to the client ...
You'll have to do the demarshalling yourself; fortunately, it's fairly straightforward. Java's `DataOutputStream` class writes integers in big-endian (network) format. So, to demarshall the integer, we grab 4 bytes and unpack them into a 4-byte integer. For UTF-8 strings, `DataOutputStream` first writes a 2-byte value...
323,260
<p>Please let me know how can I remove default banner of web server from response - Apache http1.1 coyote</p>
[ { "answer_id": 323364, "author": "Pierre-Yves Gillier", "author_id": 2692, "author_profile": "https://Stackoverflow.com/users/2692", "pm_score": 2, "selected": false, "text": "<p>If you're talking about the generated line at the bottom of apache generated pages, you have to update your h...
2008/11/27
[ "https://Stackoverflow.com/questions/323260", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Please let me know how can I remove default banner of web server from response - Apache http1.1 coyote
If you're talking about the generated line at the bottom of apache generated pages, you have to update your httpd.conf with this command: ``` ServerSignature Off ``` See <http://httpd.apache.org/docs/2.2/mod/core.html#serversignature> Be careful, theses informations are also sent through HTTP headers. You can alter...
323,264
<p>Is it possible (and if yes, how) to bypass DNS when doing a HTTP request ?</p> <p>I want to hit directly a front-end with an HTTP request, without getting through NLB but with the correct host header. As I have the IP of my server, I just need to bypass the DNS.</p> <p>I tried to use WebRequest, replacing the URL...
[ { "answer_id": 323555, "author": "Martin Brown", "author_id": 20553, "author_profile": "https://Stackoverflow.com/users/20553", "pm_score": 3, "selected": false, "text": "<p>At the time this question was asked this was not possible to do with the WebRequest class. However following a Mic...
2008/11/27
[ "https://Stackoverflow.com/questions/323264", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22970/" ]
Is it possible (and if yes, how) to bypass DNS when doing a HTTP request ? I want to hit directly a front-end with an HTTP request, without getting through NLB but with the correct host header. As I have the IP of my server, I just need to bypass the DNS. I tried to use WebRequest, replacing the URL with the IP and ...
I manage to do what I need setting the proxy to the IP address of the remote server : ``` request.Proxy = new WebProxy(ip.ToString()); ``` It doesn't work in all scenarios, but it did in my case.
323,265
<p>I try <code>Request.Form.Set(k, v)</code> but it's throwing exception </p> <blockquote> <p>Collection is read-only</p> </blockquote>
[ { "answer_id": 323297, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 1, "selected": false, "text": "<p>The form is a representation of what the client sent in the request. What is it you want to do? Personally, I woul...
2008/11/27
[ "https://Stackoverflow.com/questions/323265", "https://Stackoverflow.com", "https://Stackoverflow.com/users/441493/" ]
I try `Request.Form.Set(k, v)` but it's throwing exception > > Collection is read-only > > >
This is exactly the same as modifying `Request.Querystring`. Both are internally complicated by private properties and what could be deemed a bug, however there are two possible solutions I'm aware of (I'll dismiss the response.redirect plan out of hand - that's terrible). Method one is to use reflection to modify the...
323,284
<p>currently i am forcing my WPF app to use the luna theme no matter what, with this XAML code</p> <pre><code>&lt;Application.Resources&gt; &lt;ResourceDictionary&gt; &lt;ResourceDictionary.MergedDictionaries&gt; &lt;ResourceDictionary Source="Styles.xaml" /&gt; &lt;ResourceDictiona...
[ { "answer_id": 324176, "author": "Jobi Joy", "author_id": 8091, "author_profile": "https://Stackoverflow.com/users/8091", "pm_score": 1, "selected": false, "text": "<p>Try </p>\n\n<pre><code>&lt;Style x:Key=\"{x:Type TextBox}\" TargetType=\"{x:Type TextBox}\"&gt;\n</code></pre>\n" }, ...
2008/11/27
[ "https://Stackoverflow.com/questions/323284", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12406/" ]
currently i am forcing my WPF app to use the luna theme no matter what, with this XAML code ``` <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="Styles.xaml" /> <ResourceDictionary Source="NavigationCommands.xaml" /> ...
Try ``` <Style x:Key="{x:Type TextBox}" TargetType="{x:Type TextBox}"> ```
323,294
<p>I'm having a bit of a problem with converting the result of a MySQL query to a Java class when using SUM.</p> <p>When performing a simple SUM in MySQL</p> <pre><code>SELECT SUM(price) FROM cakes WHERE ingredient = 'chocolate'; </code></pre> <p>with <code>price</code> being an integer, it appears that the <code>SU...
[ { "answer_id": 323307, "author": "Vinko Vrsalovic", "author_id": 5190, "author_profile": "https://Stackoverflow.com/users/5190", "pm_score": 4, "selected": true, "text": "<p>This is just a guess, but maybe casting to integer will force MySQL to always tell it is an integer.</p>\n\n<pre><...
2008/11/27
[ "https://Stackoverflow.com/questions/323294", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5822/" ]
I'm having a bit of a problem with converting the result of a MySQL query to a Java class when using SUM. When performing a simple SUM in MySQL ``` SELECT SUM(price) FROM cakes WHERE ingredient = 'chocolate'; ``` with `price` being an integer, it appears that the `SUM` sometimes returns a string and sometimes an in...
This is just a guess, but maybe casting to integer will force MySQL to always tell it is an integer. ``` SELECT CAST(SUM(price) AS SIGNED) FROM cakes WHERE ingredient = 'marshmallows'; ```
323,314
<p>What is the best way to convert from Pascal Case (upper Camel Case) to a sentence.</p> <p>For example starting with</p> <pre><code>"AwaitingFeedback" </code></pre> <p>and converting that to</p> <pre><code>"Awaiting feedback" </code></pre> <p>C# preferable but I could convert it from Java or similar.</p>
[ { "answer_id": 323324, "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>NewString = \"\";\nLoop through every char of the string (skip the first one)\n If c...
2008/11/27
[ "https://Stackoverflow.com/questions/323314", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6369/" ]
What is the best way to convert from Pascal Case (upper Camel Case) to a sentence. For example starting with ``` "AwaitingFeedback" ``` and converting that to ``` "Awaiting feedback" ``` C# preferable but I could convert it from Java or similar.
``` public static string ToSentenceCase(this string str) { return Regex.Replace(str, "[a-z][A-Z]", m => m.Value[0] + " " + char.ToLower(m.Value[1])); } ``` In versions of visual studio after 2015, you can do ``` public static string ToSentenceCase(this string str) { return Regex.Replace(str, "[a-z][A-Z]", m ...
323,323
<p>Can someone tell me what Strong typing and weak typing means and which one is better?</p>
[ { "answer_id": 323334, "author": "wvdschel", "author_id": 2018, "author_profile": "https://Stackoverflow.com/users/2018", "pm_score": -1, "selected": false, "text": "<p>Weak typing means that you don't specify what type a variable is, and strong typing means you give a strict type to eac...
2008/11/27
[ "https://Stackoverflow.com/questions/323323", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30234/" ]
Can someone tell me what Strong typing and weak typing means and which one is better?
That'll be the theory answers taken care of, but the practice side seems to have been neglected... Strong-typing means that you can't use one type of variable where another is expected (or have restrictions to doing so). Weak-typing means you can mix different types. In PHP for example, you can mix numbers and strings...
323,325
<p>I'm quickly falling in love with ASP.NET MVC beta, and one of the things I've decided I won't sacrifice in deploying to my IIS 6 hosting environment is the extensionless URL. Therefore, I'm weighing the consideration of adding a wildcard mapping, but everything I read suggests a potential performance hit when using ...
[ { "answer_id": 324651, "author": "Hrvoje Hudo", "author_id": 1407, "author_profile": "https://Stackoverflow.com/users/1407", "pm_score": 1, "selected": false, "text": "<p>I was looking for benchmark like this for a long time. Thanx! </p>\n\n<p>In my company we did wildcard mapping on sev...
2008/11/27
[ "https://Stackoverflow.com/questions/323325", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34942/" ]
I'm quickly falling in love with ASP.NET MVC beta, and one of the things I've decided I won't sacrifice in deploying to my IIS 6 hosting environment is the extensionless URL. Therefore, I'm weighing the consideration of adding a wildcard mapping, but everything I read suggests a potential performance hit when using thi...
Chris, very handy post. Many who suggest a performance disadvantage infer that the code processed in a web application is some how different/inferior to code processed in the standard workflow. The base code type maybe different, and sure you'll be needing the MSIL interpreter, but MS has shown in many cases you'll ac...
323,342
<p>I'd like to sort on a column in the result of a stored procedure without having to add the Order By clause in the stored procedure. I don't want the data to be sorted after I have executed the query, sorting should be part of the query if possible. I have the following code:</p> <pre><code>public static DataTable R...
[ { "answer_id": 323374, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 1, "selected": false, "text": "<p>To be honest, since you are using DataTable, you might as well just sort at the client.</p>\n\n<p>Dynamic sorting ...
2008/11/27
[ "https://Stackoverflow.com/questions/323342", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40939/" ]
I'd like to sort on a column in the result of a stored procedure without having to add the Order By clause in the stored procedure. I don't want the data to be sorted after I have executed the query, sorting should be part of the query if possible. I have the following code: ``` public static DataTable RunReport(Repor...
Get the DataTable you are populating in the dataSet ("Result"). Now - there's no way to sort the DataTable, except via the Query, View, or Stored Procedure that populates it. Since you don't wanna do it in the SP, you can sort the DefaultView of the DataTable, or any DataView that is associated with the DataTable....
323,363
<pre><code>&gt;rails -v Rails 1.2.6 &gt;ruby -v ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-mswin32] </code></pre> <p>When I run a test fixture (that tests a rails model class) like this, it takes 20-30 secs to start executing these tests (show the "Loaded suite..."). What gives?</p> <pre><code>&gt;ruby test\unit\cat...
[ { "answer_id": 323386, "author": "schnaader", "author_id": 34065, "author_profile": "https://Stackoverflow.com/users/34065", "pm_score": 0, "selected": false, "text": "<p>It seems like Test::Unit is the simplest, but also one of the slowest ways to do unit testing with Ruby. One of alter...
2008/11/27
[ "https://Stackoverflow.com/questions/323363", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1695/" ]
``` >rails -v Rails 1.2.6 >ruby -v ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-mswin32] ``` When I run a test fixture (that tests a rails model class) like this, it takes 20-30 secs to start executing these tests (show the "Loaded suite..."). What gives? ``` >ruby test\unit\category_test.rb require File.dirname(__F...
When starting any tests, Rails first loads any fixtures you have (in test/fixtures) and recreates the database with them. 20-30 seconds sounds *very* slow though. Do you have a lot of fixtures that need to be loaded before your tests run, or is your database running slow?
323,397
<p>Part of my application maps resources stored in a number of locations onto web URLs like this:</p> <pre><code>http://servername/files/path/to/my/resource/ </code></pre> <p>The resources location is modelled after file paths and as a result there can be an unlimited level of nesting. Is it possible to construct an ...
[ { "answer_id": 323460, "author": "Garry Shutler", "author_id": 6369, "author_profile": "https://Stackoverflow.com/users/6369", "pm_score": 6, "selected": true, "text": "<p>A route like</p>\n\n<pre><code>\"Files/{*path}\"\n</code></pre>\n\n<p>will get the path as a single string. The <cod...
2008/11/27
[ "https://Stackoverflow.com/questions/323397", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28882/" ]
Part of my application maps resources stored in a number of locations onto web URLs like this: ``` http://servername/files/path/to/my/resource/ ``` The resources location is modelled after file paths and as a result there can be an unlimited level of nesting. Is it possible to construct an MVC route that matches thi...
A route like ``` "Files/{*path}" ``` will get the path as a single string. The `*` designates it as a wildcard mapping and it will consume the whole URL after `"Files/"`.
323,405
<p>I try to migrate a Windows SVN Server to Linux.<br> I have configured Apache to validate against AD for Useraccess so only AD Users can logon.<br> Now i have to set permissions for repositories with authz files.<br> When i set permission with AD username it works, but AD groups it doesn't.</p> <p>The authz file loo...
[ { "answer_id": 323431, "author": "Davide Gualano", "author_id": 28582, "author_profile": "https://Stackoverflow.com/users/28582", "pm_score": 2, "selected": false, "text": "<p>You can't automatically use AD groups inside the authz files.</p>\n\n<p>A possibile solution could be writing a ...
2008/11/27
[ "https://Stackoverflow.com/questions/323405", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I try to migrate a Windows SVN Server to Linux. I have configured Apache to validate against AD for Useraccess so only AD Users can logon. Now i have to set permissions for repositories with authz files. When i set permission with AD username it works, but AD groups it doesn't. The authz file looks like the f...
You can't automatically use AD groups inside the authz files. A possibile solution could be writing a script that query the AD for the groups and their member users and writes the correct authz file, defining also the groups themselves. The final output shuold be something like: ``` [groups] usergroup = user1, user2...
323,413
<p>I have an app that needs to handle very large strings between a SQL Server database and .NET code. I have a LINQ query that generates the strings when saving them <i>to</i> the database, but when trying to create the strings <i>from</i> the database, the app crashes with an OutOfMemoryException because of the size o...
[ { "answer_id": 323425, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 2, "selected": true, "text": "<p>What do you call \"very large\"? And what is the string? CLOB? BLOB? xml?</p>\n\n<p>I suspect you should be using t...
2008/11/27
[ "https://Stackoverflow.com/questions/323413", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41304/" ]
I have an app that needs to handle very large strings between a SQL Server database and .NET code. I have a LINQ query that generates the strings when saving them *to* the database, but when trying to create the strings *from* the database, the app crashes with an OutOfMemoryException because of the size of the strings...
What do you call "very large"? And what is the string? CLOB? BLOB? xml? I suspect you should be using things like `ExecuteReader()`, which (via `IDataReader`) exposes methods for reading such columns in chunks: ``` using (var reader = cmd.ExecuteReader( CommandBehavior.SequentialAccess)) { ...
323,419
<p>Do you know a simple script to count NLOCs (netto lines of code). The script should count lines of C Code. It should not count empty lines or lines with just braces. But it doesn't need to be overly exact either.</p>
[ { "answer_id": 323427, "author": "Tim Ring", "author_id": 3685, "author_profile": "https://Stackoverflow.com/users/3685", "pm_score": 1, "selected": false, "text": "<p>Check out DPack plugin for Visual Studio. It has a stats report for any solution/project.</p>\n" }, { "answer_id...
2008/11/27
[ "https://Stackoverflow.com/questions/323419", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20668/" ]
Do you know a simple script to count NLOCs (netto lines of code). The script should count lines of C Code. It should not count empty lines or lines with just braces. But it doesn't need to be overly exact either.
I would do that using **awk** & **cpp** (preprocessor) & **wc** . awk removes all braces and blanks, the preprocessor removes all comments and wc counts the lines: ``` find . -name \*.cpp -o -name \*.h | xargs -n1 cpp -fpreprocessed -P | awk '!/^[{[:space:]}]*$/' | wc -l ``` If you want to have comments include...
323,424
<p>I am using python 2.6 on XP. I have just installed py2exe, and I can successfully create a simple hello.exe from a hello.py. However, when I try using py2exe on my real program, py2exe produces a few information messages but fails to generate anything in the dist folder. </p> <p>My setup.py looks like this:</p> <...
[ { "answer_id": 325135, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "<p>The output says you're using WX. Try running py2exe with your script specified as a GUI app instead of console. If I'm not ...
2008/11/27
[ "https://Stackoverflow.com/questions/323424", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11677/" ]
I am using python 2.6 on XP. I have just installed py2exe, and I can successfully create a simple hello.exe from a hello.py. However, when I try using py2exe on my real program, py2exe produces a few information messages but fails to generate anything in the dist folder. My setup.py looks like this: ```py from distu...
I've discovered that py2exe works just fine if I comment out the part of my program that uses wxPython. Also, when I use py2exe on the 'simple' sample that comes with its download (i.e. in Python26\Lib\site-packages\py2exe\samples\simple), I get this error message: ``` *** finding dlls needed *** error: MSVCP90.dll: N...
323,426
<p>I would like to provide the raw text referring to an environment variable to a command instead of evaluating the environment variable.</p> <p>I need this to configure BizTalk from the command line, for example:</p> <p>BTSTask.exe AddResource -ApplicationName:App1 -Type:System.BizTalk:BizTalkAssembly -Overwrite -...
[ { "answer_id": 323433, "author": "Mikeage", "author_id": 41308, "author_profile": "https://Stackoverflow.com/users/41308", "pm_score": 2, "selected": false, "text": "<p>Try ^% instead of %.</p>\n" }, { "answer_id": 323464, "author": "Sandeep Datta", "author_id": 39648, ...
2008/11/27
[ "https://Stackoverflow.com/questions/323426", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23940/" ]
I would like to provide the raw text referring to an environment variable to a command instead of evaluating the environment variable. I need this to configure BizTalk from the command line, for example: BTSTask.exe AddResource -ApplicationName:App1 -Type:System.BizTalk:BizTalkAssembly -Overwrite -Source:..\Schemas...
Did you try: ``` %%BTAD_InstallDir%% ``` in your script ? That should prevent the script to interpret the variable, and it would pass `%BTAD_InstallDir%` to the program.
323,458
<p>I'm learning ASP.NET MVC and bugged by one issue.</p> <p>In the HomeController, the Index action has OutputCache attribute, but it seems doesn't work.</p> <pre><code>[HandleError] public class HomeController : Controller { [OutputCache(Duration=5, VaryByParam="none")] public ActionResult Index() { ...
[ { "answer_id": 325255, "author": "Eilon", "author_id": 31668, "author_profile": "https://Stackoverflow.com/users/31668", "pm_score": 4, "selected": true, "text": "<p>I think this is a bug in ASP.NET MVC. We have logged the issue in our database and will investigate a fix for this issue.<...
2008/11/27
[ "https://Stackoverflow.com/questions/323458", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26349/" ]
I'm learning ASP.NET MVC and bugged by one issue. In the HomeController, the Index action has OutputCache attribute, but it seems doesn't work. ``` [HandleError] public class HomeController : Controller { [OutputCache(Duration=5, VaryByParam="none")] public ActionResult Index() { ViewData["Title"]...
I think this is a bug in ASP.NET MVC. We have logged the issue in our database and will investigate a fix for this issue. Thanks, Eilon
323,462
<p>This is driving me nuts so any advice from fellow users would be welcome. I am using Subversion, with a copy of VisualSVN 1.6.1 installed on a Windows server. On my PC I am using a combination of TortoiseSVN and the wonderful AnkhSVN Visual Studio plugin. Everything works like a dream, but now I am trying use the...
[ { "answer_id": 323468, "author": "schnaader", "author_id": 34065, "author_profile": "https://Stackoverflow.com/users/34065", "pm_score": 1, "selected": false, "text": "<p>If you want to be sure you've picked the correct config file, use TortoiseSVN's edit button: <a href=\"http://www.med...
2008/11/27
[ "https://Stackoverflow.com/questions/323462", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9236/" ]
This is driving me nuts so any advice from fellow users would be welcome. I am using Subversion, with a copy of VisualSVN 1.6.1 installed on a Windows server. On my PC I am using a combination of TortoiseSVN and the wonderful AnkhSVN Visual Studio plugin. Everything works like a dream, but now I am trying use the `svn:...
You're right, the issue lies with AnkhSVN. The keywords properties will not be automatically added if the new file is added in Visual Studio (with AnkhSVN 2.0.5250). It will only be added if you add the file using Tortoisvn. I downloaded a trial version of VisualSVN (plugins to Visual Studio). It does not have this is...
323,503
<p>I've got a DataTable containing a sitemap hierarchy with the following columns:</p> <ul> <li>ItemId</li> <li>ParentId</li> <li>Name</li> <li>Url</li> </ul> <p>I need to generate a set of nested lists in HTML (left the anchor elements out for clarity):</p> <pre><code>&lt;ul&gt; &lt;li&gt;Item 1&lt;/li&gt; &lt;li&g...
[ { "answer_id": 323550, "author": "martinlund", "author_id": 1808, "author_profile": "https://Stackoverflow.com/users/1808", "pm_score": 0, "selected": false, "text": "<p>I made something similar, it might not be that efficient but its easy to debug.</p>\n\n<ol>\n<li>Find path to selected...
2008/11/27
[ "https://Stackoverflow.com/questions/323503", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14072/" ]
I've got a DataTable containing a sitemap hierarchy with the following columns: * ItemId * ParentId * Name * Url I need to generate a set of nested lists in HTML (left the anchor elements out for clarity): ``` <ul> <li>Item 1</li> <li>Item 2</li> <ul> <li>Sub Item 1</li> <li class="current">Sub Item 2</l...
Here's some pseudocode. The idea is simple: Start with all the nodes unmarked, and mark your current node's parent, *its* parent, and so on till you reach the root. By doing this, you'll have marked exactly the nodes on the path from your current node to the root. Then you can simply print all the nodes in another pass...
323,515
<p>I'm trying to store in a variable the name of the current file that I've opened from a folder.</p> <p>How can I do that? I've tried <code>cwd = os.getcwd()</code> but this only gives me the path of the folder, and I need to store the name of the opened file.</p> <p>Can you please help me?</p>
[ { "answer_id": 323522, "author": "Vinko Vrsalovic", "author_id": 5190, "author_profile": "https://Stackoverflow.com/users/5190", "pm_score": 6, "selected": false, "text": "<pre><code>Python 2.5.1 (r251:54863, Jul 31 2008, 22:53:39)\n[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2\nType \"h...
2008/11/27
[ "https://Stackoverflow.com/questions/323515", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I'm trying to store in a variable the name of the current file that I've opened from a folder. How can I do that? I've tried `cwd = os.getcwd()` but this only gives me the path of the folder, and I need to store the name of the opened file. Can you please help me?
``` Python 2.5.1 (r251:54863, Jul 31 2008, 22:53:39) [GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> f = open('generic.png','r') >>> f.name 'generic.png' ```
323,517
<p>We need to see what methods/fields an object has in Javascript.</p>
[ { "answer_id": 323529, "author": "Ken", "author_id": 20074, "author_profile": "https://Stackoverflow.com/users/20074", "pm_score": 7, "selected": false, "text": "<p>If you are using firefox then the <a href=\"http://getfirebug.com/\" rel=\"noreferrer\">firebug plug-in</a> console is an e...
2008/11/27
[ "https://Stackoverflow.com/questions/323517", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30759/" ]
We need to see what methods/fields an object has in Javascript.
As the others said, you can use Firebug, and that will sort you out no worries on Firefox. Chrome & Safari both have a built-in developer console which has an almost identical interface to Firebug's console, so your code should be portable across those browsers. For other browsers, there's [Firebug Lite](http://getfire...
323,521
<p>in windows I am able to use winmerge as the external diff tool for hg using <i>mercurial.ini</i>,etc. <br> Using some options switch that you can find in web(I think it's a japanese website) Anyway, here for example:</p> <pre>hg winmerge -r1 -r2</pre> <p>will list file(s) change(s) between rev1 and rev2 in winme...
[ { "answer_id": 499666, "author": "mrrage", "author_id": 8631, "author_profile": "https://Stackoverflow.com/users/8631", "pm_score": 2, "selected": false, "text": "<p>I had to add the following to make it work on my machine:</p>\n\n<pre><code>[extensions]\nextdiff =\n\n[extdiff]\ncmd.bc3 ...
2008/11/27
[ "https://Stackoverflow.com/questions/323521", "https://Stackoverflow.com", "https://Stackoverflow.com/users/38515/" ]
in windows I am able to use winmerge as the external diff tool for hg using *mercurial.ini*,etc. Using some options switch that you can find in web(I think it's a japanese website) Anyway, here for example: ``` hg winmerge -r1 -r2 ``` will list file(s) change(s) between rev1 and rev2 in winmerge. I can just click w...
Beyond-Compare-3 is an amazing tool. I recommend a few tweaks to the setup: ``` [extensions] extdiff = [extdiff] cmd.bcomp = C:\Program Files\Beyond Compare 3\BCompare.exe opts.bcomp = /leftreadonly [merge-tools] bcomp.executable = C:\Program Files\Beyond Compare 3\BComp bcomp.args = /leftreadonly /centerreadonly $l...
323,536
<p>How can I get a full list of Groups in my Active Directory?</p>
[ { "answer_id": 323573, "author": "splattne", "author_id": 6461, "author_profile": "https://Stackoverflow.com/users/6461", "pm_score": 1, "selected": false, "text": "<p>Microsoft .NET Framework provides a standard library for working with Active Directory: <strong><a href=\"http://msdn.mi...
2008/11/27
[ "https://Stackoverflow.com/questions/323536", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36026/" ]
How can I get a full list of Groups in my Active Directory?
Check out System.DirectoryServices (An ASP.NET 2.0 reference): C#-example to get groups: ``` using System.DirectoryServices; public class test { private void main() { foreach (string @group in GetGroups()) { Debug.Print(@group); } } public List<string> GetGroup...
323,551
<p>I have a WCF service with the following configuration:</p> <pre><code>&lt;system.serviceModel&gt; &lt;behaviors&gt; &lt;serviceBehaviors&gt; &lt;behavior name="MetadataEnabled"&gt; &lt;serviceDebug includeExceptionDetailInFaults="true" /&gt; &lt;serviceMetadat...
[ { "answer_id": 323574, "author": "Enrico Campidoglio", "author_id": 26396, "author_profile": "https://Stackoverflow.com/users/26396", "pm_score": 5, "selected": true, "text": "<p>I think I found out what the problem is.</p>\n\n<p>If I browse to the URL:</p>\n\n<blockquote>\n <p><a href=...
2008/11/27
[ "https://Stackoverflow.com/questions/323551", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26396/" ]
I have a WCF service with the following configuration: ``` <system.serviceModel> <behaviors> <serviceBehaviors> <behavior name="MetadataEnabled"> <serviceDebug includeExceptionDetailInFaults="true" /> <serviceMetadata httpGetEnabled="true" /> </behavi...
I think I found out what the problem is. If I browse to the URL: > > <http://localhost/myservice/contract> > > > with the **WcfTestClient** application I can successfully retrieve the service metadata. So the error really only occurs when I request the URL through a web browser. The **HTTP Bad Request** erro...
323,556
<pre><code>A.Event1 := nil; A.Event2 := nil; try ... finally A.Event1 := MyEvent1; A.Event2 := MyEvent2; end; </code></pre> <p>Can something go wrong with it?</p> <p><strong>EDIT:</strong></p> <p>I've accepted Barry's answer because it answered exactly what I asked, but Vegar's answer is also correct depending...
[ { "answer_id": 323570, "author": "Barry Kelly", "author_id": 3712, "author_profile": "https://Stackoverflow.com/users/3712", "pm_score": 3, "selected": true, "text": "<p>It entirely depends on what happens in the bit of code marked '...'. If it e.g. starts up a background thread and trie...
2008/11/27
[ "https://Stackoverflow.com/questions/323556", "https://Stackoverflow.com", "https://Stackoverflow.com/users/727/" ]
``` A.Event1 := nil; A.Event2 := nil; try ... finally A.Event1 := MyEvent1; A.Event2 := MyEvent2; end; ``` Can something go wrong with it? **EDIT:** I've accepted Barry's answer because it answered exactly what I asked, but Vegar's answer is also correct depending on the scenario, sadly I can't accept both.
It entirely depends on what happens in the bit of code marked '...'. If it e.g. starts up a background thread and tries to invoke Event1 or Event2 after execution has continued into the finally block, you may get unexpected results. If the code is entirely single-threaded, then yes, neither Event1 nor Event2 should be...
323,558
<p>Here's a relatively common task for me, and, I think, for many a .NET programmer:<br> I want to use the .NET ThreadPool for scheduling worker threads that need to process a given type of tasks.</p> <p>As a refresher, the signatures for the queueing method of the ThreadPool and its associated delegate are:</p> <pre...
[ { "answer_id": 323565, "author": "Barry Kelly", "author_id": 3712, "author_profile": "https://Stackoverflow.com/users/3712", "pm_score": 3, "selected": false, "text": "<p>Since it's trivial to package whatever state you like by passing an anonymous delegate or lambda to the threadpool (t...
2008/11/27
[ "https://Stackoverflow.com/questions/323558", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11545/" ]
Here's a relatively common task for me, and, I think, for many a .NET programmer: I want to use the .NET ThreadPool for scheduling worker threads that need to process a given type of tasks. As a refresher, the signatures for the queueing method of the ThreadPool and its associated delegate are: ``` public static b...
It sounds like you are talking about a work queue? (and I sound like clippy...) For the record, thread-pool threads should typically be used for short pieces of work. You should ideally create your own threads for a long-lived queue. Note that .NET 4.0 may be adopting the CCR/TPL libraries, so we'll get some inbuilt w...
323,561
<p>I know how to disable <a href="https://stackoverflow.com/questions/303488/in-php-how-can-you-clear-a-wsdl-cache">WSDL-cache</a> in PHP, but what about force a re-caching of the WSDL? </p> <p>This is what i tried: I run my code with caching set to disabled, and the new methods showed up as espected. Then I activated...
[ { "answer_id": 323582, "author": "Greg", "author_id": 24181, "author_profile": "https://Stackoverflow.com/users/24181", "pm_score": 1, "selected": false, "text": "<p>I'd try </p>\n\n<pre><code>$limit = ini_get('soap.wsdl_cache_limit');\nini_set('soap.wsdl_cache_limit', 0);\nini_set('soap...
2008/11/27
[ "https://Stackoverflow.com/questions/323561", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36975/" ]
I know how to disable [WSDL-cache](https://stackoverflow.com/questions/303488/in-php-how-can-you-clear-a-wsdl-cache) in PHP, but what about force a re-caching of the WSDL? This is what i tried: I run my code with caching set to disabled, and the new methods showed up as espected. Then I activated caching, but of some...
I guess when you disable caching it will also stop writing to the cache. So when you re-enable the cache the old cached copy will still be there and valid. You could try (with caching enabled) ``` ini_set('soap.wsdl_cache_ttl', 1); ``` I put in a time-to-live of one second in because I think if you put zero in it wi...
323,562
<p>I have the following code in Visual Studio 2005.</p> <pre><code> Dim OutFile As System.IO.StreamWriter Try OutFile = New System.IO.StreamWriter(Filename) // Do stuff with OutFile Catch Ex As Exception // Handle Exception Finally If OutFile IsNot Nothing Then OutFile.Close...
[ { "answer_id": 323566, "author": "tvanfosson", "author_id": 12950, "author_profile": "https://Stackoverflow.com/users/12950", "pm_score": 5, "selected": true, "text": "<pre><code>Dim OutFile As System.IO.StreamWriter\nOutFile = Nothing\nTry\n OutFile = New System.IO.StreamWriter(Filen...
2008/11/27
[ "https://Stackoverflow.com/questions/323562", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41338/" ]
I have the following code in Visual Studio 2005. ``` Dim OutFile As System.IO.StreamWriter Try OutFile = New System.IO.StreamWriter(Filename) // Do stuff with OutFile Catch Ex As Exception // Handle Exception Finally If OutFile IsNot Nothing Then OutFile.Close() End Try...
``` Dim OutFile As System.IO.StreamWriter OutFile = Nothing Try OutFile = New System.IO.StreamWriter(Filename) // Do stuff with OutFile Catch Ex As Exception // Handle Exception Finally If OutFile IsNot Nothing Then OutFile.Close() End Try ``` **Similar to [C# error: Use of unassigned local variable](htt...
323,567
<p>From index.jsp code, </p> <pre><code>statement.executeQuery("select * from fus where tester_num like 'hf60' ") ; </code></pre> <p>Example I want "hf60" to be a variable(userinput), wherein USER must input/write data from input text then submit and get the data so that the result will be </p> <pre><code>("select ...
[ { "answer_id": 323587, "author": "carson", "author_id": 25343, "author_profile": "https://Stackoverflow.com/users/25343", "pm_score": 2, "selected": false, "text": "<p>You have access to the request in a <code>JSP</code>. So if your <code>JSP</code> were to be accessed like this:</p>\n\n...
2008/11/27
[ "https://Stackoverflow.com/questions/323567", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28607/" ]
From index.jsp code, ``` statement.executeQuery("select * from fus where tester_num like 'hf60' ") ; ``` Example I want "hf60" to be a variable(userinput), wherein USER must input/write data from input text then submit and get the data so that the result will be ``` ("select * from fus where tester_num like 'use...
You have access to the request in a `JSP`. So if your `JSP` were to be accessed like this: ``` test.jsp?q=userinput ``` You could get to it like this in the `JSP`: ``` request.getParameter('userinput'); ``` You should convert your `JSP` code to at least use a `preparedStatement` when you do this: ``` PreparedSta...
323,572
<p>I have the following route defined</p> <pre><code> routes.MapRoute( "ItemName", "{controller}/{action}/{projectName}/{name}", new { controller = "Home", action = "Index", name = "", projectName = "" } ); </code></pre> <p>This route actually works, so if I ...
[ { "answer_id": 324537, "author": "idursun", "author_id": 5984, "author_profile": "https://Stackoverflow.com/users/5984", "pm_score": 0, "selected": false, "text": "<p>You can try </p>\n\n<pre><code>Html.RouteLink(\"Edit\",\"ItemName\", new {name=m.name, projectName=m.Project.title});\n</...
2008/11/27
[ "https://Stackoverflow.com/questions/323572", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3193/" ]
I have the following route defined ``` routes.MapRoute( "ItemName", "{controller}/{action}/{projectName}/{name}", new { controller = "Home", action = "Index", name = "", projectName = "" } ); ``` This route actually works, so if I type in the browser ``` /...
When constructing and matching routes in ASP.NET routing (which is what ASP.NET MVC uses), the first appropriate match is used, not the greediest, and order is important. So if you have two routes: ``` "{controller}/{action}/{id}" "{controller}/{action}/{projectName}/{name}" ``` in that given order, then the first ...
323,585
<p>I'm using WCF and want to upload a large file from the client to the server. I have investigated and decided to follow the chunking approach outlined at <a href="http://msdn.microsoft.com/en-us/library/aa717050.aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/aa717050.aspx</a></p> <p>However, this app...
[ { "answer_id": 323666, "author": "JacobE", "author_id": 30056, "author_profile": "https://Stackoverflow.com/users/30056", "pm_score": 2, "selected": false, "text": "<p>You could make your service session-ful and have an initialization method in the contract with the IsInitiating property...
2008/11/27
[ "https://Stackoverflow.com/questions/323585", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I'm using WCF and want to upload a large file from the client to the server. I have investigated and decided to follow the chunking approach outlined at <http://msdn.microsoft.com/en-us/library/aa717050.aspx> However, this approach (just like streaming) restricts the contract to limited method signitures: ``` [Operat...
[This article](http://www2.zdo.com/archives/27-Windows-Communication-Foundation-WCF-Notes.html) explains how to use the MessageHeader attribute to force things to be passed in the header, and therefore not count as a parameter. So, instead of passing a stream and other meta data, create a class that has the attribute M...
323,599
<p>I haven't played with CSS for too long a time and am without references at the moment. My question should be fairly easy but googling isn't bringing up a sufficient answer. So, adding to the collective knowledge...</p> <pre><code>|#header---------------------------------------------------------------| | ...
[ { "answer_id": 323617, "author": "Jack Ryan", "author_id": 28882, "author_profile": "https://Stackoverflow.com/users/28882", "pm_score": -1, "selected": false, "text": "<p>Something like this perhaps...</p>\n\n<pre><code>&lt;!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www...
2008/11/27
[ "https://Stackoverflow.com/questions/323599", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10583/" ]
I haven't played with CSS for too long a time and am without references at the moment. My question should be fairly easy but googling isn't bringing up a sufficient answer. So, adding to the collective knowledge... ``` |#header---------------------------------------------------------------| | ...
Its quite a common misconception that you need a `clear:both` div at the bottom, when you really don't. While foxy's answer is correct, you don't need that non-semantic, useless clearing div. All you need to do is stick an `overflow:hidden` onto the container: ``` #sub-title { overflow:hidden; } ```
323,608
<p>Can anyone please help me to get all the domains in Active Directory. I have tried many times, but all the programs are listing only the current working domain. </p> <p>How can I do this?</p>
[ { "answer_id": 323631, "author": "Sergiu Damian", "author_id": 41345, "author_profile": "https://Stackoverflow.com/users/41345", "pm_score": 1, "selected": false, "text": "<p>Using DirectorySearcher you can connect and read the structure of one Active Directory, including the structure (...
2008/11/27
[ "https://Stackoverflow.com/questions/323608", "https://Stackoverflow.com", "https://Stackoverflow.com/users/201406/" ]
Can anyone please help me to get all the domains in Active Directory. I have tried many times, but all the programs are listing only the current working domain. How can I do this?
``` Domain domain = Domain.GetDomain(new DirectoryContext(DirectoryContextType.Domain, "yourDomain", "username", "password")); Forest forest = domain.Forest; DomainCollection domains = forest.Domains; ``` The above uses the System.DirectoryServices.ActiveDirectory namespace. It'll give you a domain collection conta...
323,613
<p>This is more of an academic inquiry than a practical question. Are there any language or framework features that can, or will in future, allow a heterogeneous typed dcitionary, e.g. </p> <pre><code>myDict.Add("Name", "Bill"); myDict.Add("Height", 1.2); </code></pre> <p>where myDict now contains not two <code>ob...
[ { "answer_id": 323628, "author": "Ali Ersöz", "author_id": 4215, "author_profile": "https://Stackoverflow.com/users/4215", "pm_score": 1, "selected": false, "text": "<p>You can use Generic <code>Dictionary&lt;object, object&gt;</code>; object type for key and object type for value. C# co...
2008/11/27
[ "https://Stackoverflow.com/questions/323613", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8741/" ]
This is more of an academic inquiry than a practical question. Are there any language or framework features that can, or will in future, allow a heterogeneous typed dcitionary, e.g. ``` myDict.Add("Name", "Bill"); myDict.Add("Height", 1.2); ``` where myDict now contains not two `object` types as values, but one `...
The only way you'll be able to do this if you have a custom collection with generic overloads for Add and Get methods. But that would mean you can ask for the wrong type when reading the key out, so it doesn't gain you much (if anything) over doing the cast yourself when you call your Get method. However, if you can p...
323,640
<p>In C#, can I convert a string value to a string literal, the way I would see it in code? I would like to replace tabs, newlines, etc. with their escape sequences.</p> <p>If this code:</p> <pre><code>Console.WriteLine(someString); </code></pre> <p>produces:</p> <pre><code>Hello World! </code></pre> <p>I want this cod...
[ { "answer_id": 323664, "author": "Nelson Reis", "author_id": 29544, "author_profile": "https://Stackoverflow.com/users/29544", "pm_score": 3, "selected": false, "text": "<p>Interesting question.</p>\n\n<p>If you can't find a better method, you can always replace.<br>\nIn case you're opti...
2008/11/27
[ "https://Stackoverflow.com/questions/323640", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15454/" ]
In C#, can I convert a string value to a string literal, the way I would see it in code? I would like to replace tabs, newlines, etc. with their escape sequences. If this code: ``` Console.WriteLine(someString); ``` produces: ``` Hello World! ``` I want this code: ``` Console.WriteLine(ToLiteral(someString)); ...
There's a method for this in [Roslyn](https://en.wikipedia.org/wiki/.NET_Compiler_Platform)'s [Microsoft.CodeAnalysis.CSharp](https://www.nuget.org/packages/Microsoft.CodeAnalysis.CSharp/) package on NuGet: ```cs private static string ToLiteral(string valueTextForCompiler) { return Microsoft.CodeAnalysis.CSharp.Sy...
323,650
<p>I have this code</p> <pre><code>while($row = mysql_fetch_row($result)) { echo '&lt;tr&gt;'; $pk = $row[0]['ARTICLE_NO']; foreach($row as $key =&gt; $value) { echo '&lt;td&gt;&lt;a href="#" onclick="GetAuctionData(\''.$pk.'\')"&gt;' . $value . '&lt;/a&gt;&lt;/td&gt;'; } </code></pre> <p>which gets pk. pk is then p...
[ { "answer_id": 323676, "author": "troelskn", "author_id": 18180, "author_profile": "https://Stackoverflow.com/users/18180", "pm_score": 0, "selected": false, "text": "<p>I don't think this does what you expect:</p>\n\n<pre><code>$pk = $row[0]['ARTICLE_NO'];\n</code></pre>\n\n<p>Try with:...
2008/11/27
[ "https://Stackoverflow.com/questions/323650", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1246613/" ]
I have this code ``` while($row = mysql_fetch_row($result)) { echo '<tr>'; $pk = $row[0]['ARTICLE_NO']; foreach($row as $key => $value) { echo '<td><a href="#" onclick="GetAuctionData(\''.$pk.'\')">' . $value . '</a></td>'; } ``` which gets pk. pk is then passed on to the axjax part with this: ``` function GetAuct...
mysql\_fetch\_row [link](http://no.php.net/manual/en/function.mysql-fetch-row.php) does not have subarrays. It will return the first field as 0, next as 1, etc. Try with ``` $pk = $row[0]; ``` This can easily be used with your foreach ``` while($row = mysql_fetch_assoc($result)) $pk = $row['ARTICLE_NO']; ``` o...
323,668
<p>The title is a bit abstract so maybe it is easier to explain with a specific example:</p> <p>I find it useful to have my exception classes take an enum parameter instead of a string message. </p> <pre><code>throw new SpecificException(SpecificExceptionCode.ThisThingWentWrong); </code></pre> <p>There are few reaso...
[ { "answer_id": 323687, "author": "Grzenio", "author_id": 5363, "author_profile": "https://Stackoverflow.com/users/5363", "pm_score": 0, "selected": false, "text": "<p>Why does it have to be a static property? You can make the Resources normal property:</p>\n\n<pre><code>protected abstrac...
2008/11/27
[ "https://Stackoverflow.com/questions/323668", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24770/" ]
The title is a bit abstract so maybe it is easier to explain with a specific example: I find it useful to have my exception classes take an enum parameter instead of a string message. ``` throw new SpecificException(SpecificExceptionCode.ThisThingWentWrong); ``` There are few reasons for this, including: * I can ...
Your current code is broken... there is only one static field; the last static ctor to execute wins. Re using a non-static method - note that calling virtual/abstract methods in a constructor is a bit dangerous - the concrete class won't have initialized yet, so the override could attempt to use data that isn't yet av...
323,689
<p>I occasionally see the list slice syntax used in Python code like this:</p> <pre><code>newList = oldList[:] </code></pre> <p>Surely this is just the same as:</p> <pre><code>newList = oldList </code></pre> <p>Or am I missing something?</p>
[ { "answer_id": 323698, "author": "ConcernedOfTunbridgeWells", "author_id": 15401, "author_profile": "https://Stackoverflow.com/users/15401", "pm_score": 6, "selected": false, "text": "<p><code>[:]</code> <a href=\"http://en.wikipedia.org/wiki/Deep_copy#Shallow_copy\" rel=\"noreferrer\">S...
2008/11/27
[ "https://Stackoverflow.com/questions/323689", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11677/" ]
I occasionally see the list slice syntax used in Python code like this: ``` newList = oldList[:] ``` Surely this is just the same as: ``` newList = oldList ``` Or am I missing something?
Like NXC said, Python variable names actually point to an object, and not a specific spot in memory. `newList = oldList` would create two different variables that point to the same object, therefore, changing `oldList` would also change `newList`. However, when you do `newList = oldList[:]`, it "slices" the list, and...
323,693
<p>In a ASP.NET application that I am writing I need to use connections to a specific server (something like a DB but... different). The connections are quite expensive to establish (a few seconds, literally) so I'm trying to write a pool to improve scalability. </p> <p>Everything is pretty simple, up to one point - r...
[ { "answer_id": 323717, "author": "Chris Simpson", "author_id": 28896, "author_profile": "https://Stackoverflow.com/users/28896", "pm_score": 0, "selected": false, "text": "<p>You could write a WCF service that wrappers the service you are trying to call and then communicate with this mys...
2008/11/27
[ "https://Stackoverflow.com/questions/323693", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41360/" ]
In a ASP.NET application that I am writing I need to use connections to a specific server (something like a DB but... different). The connections are quite expensive to establish (a few seconds, literally) so I'm trying to write a pool to improve scalability. Everything is pretty simple, up to one point - recycling o...
You would not need to wrapper every class and function, just the actions that you need to perform. So you might need a method to fetch some data and a method to update some data, this would translate in the service as a series of calls to the various functions as required. The front-end logic would be simplified and th...
323,697
<p>I need to test a url that it <strong>does not</strong> end with <code>.asp</code></p> <p>So <code>test</code>, <code>test.html</code> and <code>test.aspx</code> should match, but <code>test.asp</code> should not match.</p> <p>Normally you'd test if the url <strong>does</strong> end with .asp and negate the fact th...
[ { "answer_id": 323723, "author": "Winston Smith", "author_id": 35086, "author_profile": "https://Stackoverflow.com/users/35086", "pm_score": 2, "selected": false, "text": "<p>Try this</p>\n\n<pre><code>^((?!\\.asp$).)*$\n</code></pre>\n" }, { "answer_id": 323756, "author": "J...
2008/11/27
[ "https://Stackoverflow.com/questions/323697", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4830/" ]
I need to test a url that it **does not** end with `.asp` So `test`, `test.html` and `test.aspx` should match, but `test.asp` should not match. Normally you'd test if the url **does** end with .asp and negate the fact that it matched using the NOT operator in code: ``` if(!regex.IsMatch(url)) { // Do something } ``...
The trick is to use [negative lookbehind](http://www.regular-expressions.info/lookaround.html). If you need just a yes/no answer: ``` (?<!\.asp)$ ``` If you need to match the whole URL: ``` ^.*(?<!\.asp)$ ``` These regexes will work with any URL where the file name occurs at the end of the URL (i.e. URLs without...