qid
int64
4
19.1M
question
stringlengths
18
48.3k
answers
list
date
stringlengths
10
10
metadata
list
384,634
<p>I'm trying to load an image from the Firefox cache as the title suggests. I'm running Ubuntu, so the location of my cache is /home/me/.mozilla/firefox/xxxxxx.default/Cache</p> <p>However, in the Cache (and this is on Mac, too) the filenames are just ridiculous combinations of letters and numbers. Is there a way to pinpoint a certain file?</p>
[ { "answer_id": 1882960, "author": "Jason Orendorff", "author_id": 94977, "author_profile": "https://Stackoverflow.com/users/94977", "pm_score": 1, "selected": false, "text": "img src= Expires: Cache-control:" } ]
2008/12/21
[ "https://Stackoverflow.com/questions/384634", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
384,639
<p>The task seems to be pretty easy: how to include a Javascript file in xml-document so that at least Opera and Firefox could actually parse it and execute the code?</p>
[ { "answer_id": 1451526, "author": "Tim Babych", "author_id": 176270, "author_profile": "https://Stackoverflow.com/users/176270", "pm_score": 5, "selected": false, "text": "<xhtml:script xmlns:xhtml=\"http://www.w3.org/1999/xhtml\"\n src=\"file.js\"\n type=\"...
2008/12/21
[ "https://Stackoverflow.com/questions/384639", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34134/" ]
384,690
<pre><code> TMyDataList&lt;T: TBaseDatafile, constructor&gt; = class(TObjectList&lt;TBaseDatafile&gt;) public constructor Create; procedure upload(db: TDataSet); end; </code></pre> <p>I read in a blog post (I don't remember where now) that this is the way to declare a generic-based class with a specific base type for the generic object. And the compiler will accept it just fine. But when I try to use it, it decides not to cooperate.</p> <pre><code>type TDescendantList = TMyDataList&lt;TDescendantDatafile&gt;; </code></pre> <p>This gives me a compiler error.</p> <p>[DCC Error] my_database.pas(1145): E2010 Incompatible types: 'TDescendantDatafile' and 'TBaseDatafile'</p> <p>Thing is, 1145 isn't even a valid line. The file in question ends at #1142, and the type declaration that it's complaining about is on line #20. This makes me wonder if it's a compiler glitch. Or do I just not quite have the syntax right? Does anyone know a way to make this work?</p> <p>EDIT: Jim pointed out that it compiles fine when he tried it. A bit more information: I have the base datafile type and the generic list declared in the same unit, while TDescendantDatafile is in a second unit and TDescendantList is defined in a third one. I've already found and reported one bug in D2009's compiler involving generics screwing up types across multiple units. This may be related. Can anyone confirm this?</p>
[ { "answer_id": 384822, "author": "Toon Krijthe", "author_id": 18061, "author_profile": "https://Stackoverflow.com/users/18061", "pm_score": 2, "selected": false, "text": "TObjectList<T: class> = class(TList<T>)\n TMyDataList<T: TBaseDatafile> = class(TObjectList<T>)\n TMyDataList<T: clas...
2008/12/21
[ "https://Stackoverflow.com/questions/384690", "https://Stackoverflow.com", "https://Stackoverflow.com/users/32914/" ]
384,737
<p>Lambda syntax in C# 3 makes it really convenient to create one-liner anonymous methods. They're a definite improvement over the wordier anonymous delegate syntax that C# 2 gave us. The convenience of lambdas, however, brings with it a temptation to use them in places where we don't necessarily need the functional programming semantics they provide.</p> <p>For instance, I frequently find that my event handlers are (or at least <em>start out as</em>) simple one-liners that set a state value, or call another function, or set a property on another object, etc. For these, should I clutter my class with yet another simple function, or should I just stuff a lambda into the event in my constructor?</p> <p>There are some obvious disadvantages to lambdas in this scenario:</p> <ul> <li>I can't call my event handler directly; it can only be triggered by the event. Of course, in the case of these simple event handlers, <em>there's hardly a time I would need to call them directly</em>.</li> <li>I can't unhook my handler from the event. On the other hand, <em>rarely do I ever need to unhook event handlers, so this isn't much of issue, anyway</em>.</li> </ul> <p>These two things don't bother me much, for the reasons stated. And I <em>could</em> solve both of those problems, if they really were problems, by storing the lambda in a member delegate, but that would kind of defeat the purposes of using lambdas for their convenience and of keeping the class clean of clutter.</p> <p>There are two other things, though, that I think are maybe not so obvious, but possibly more problematic.</p> <ul> <li><p>Each lambda function forms a <em>closure</em> over its containing scope. This could mean that temporary objects created earlier in the constructor stay alive for much longer than they need to due to the closures maintaining references to them. Now hopefully, the compiler is smart enough to exclude objects from the closure that the lambda doesn't use, but I'm not sure. Does anybody know?</p> <p>Luckily again, this isn't always an issue, as I don't often create temporary objects in my constructors. I can imagine a scenario where I did, though, and where I couldn't easily scope it outside of the lambda.</p></li> <li>Maintainability might suffer. Big time. If I have some event handlers defined as functions, and some defined as lambdas, I worry it might make it more difficult to track down bugs, or to just understand the class. And later, if and when my event handlers end up expanding, I'll either have to move them to class-level functions, or deal with the fact that my constructor now contains a significant amount of the code that implements the functionality of my class.</li> </ul> <p>So I want to draw on the advice and experience of others, perhaps those with experience in other languages with functional programming features. Are there any established best practices for this kind of thing? Would you avoid using lambdas in event handlers or in other cases where the lambda significantly outlives its enclosing scope? If not, at what threshold would you decide to use a real function instead of a lambda? Have any of the above pitfalls significantly bitten anybody? Are there any pitfalls I haven't thought of?</p>
[ { "answer_id": 23081744, "author": "nerophon", "author_id": 2000762, "author_profile": "https://Stackoverflow.com/users/2000762", "pm_score": 0, "selected": false, "text": "public class UserIsUnhappy : Notification { public int unhappiness; }\n" } ]
2008/12/21
[ "https://Stackoverflow.com/questions/384737", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36388/" ]
384,743
<p>There are times when I want to test new code from the forums or when I need to help my friends with specific C# problem. The problem is I don't want to create new "project" in Visual Studio each time just to code/run only this small code.</p> <p>Java &amp; Eclipse IDE comes up with "Scrapbook" feature which allows the execution of arbitrary Java expressions. What are the choices for C# programmers?</p>
[ { "answer_id": 26877712, "author": "twasbrillig", "author_id": 2213647, "author_profile": "https://Stackoverflow.com/users/2213647", "pm_score": 4, "selected": false, "text": "Project Type: MVC" }, { "answer_id": 38698819, "author": "Richard Bos", "author_id": 1900305, ...
2008/12/21
[ "https://Stackoverflow.com/questions/384743", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12460/" ]
384,755
<p>I use LINQ-to-SQL to load data from a database that has two tables in a one-to-many relationship (one Recipe has many Ingredients).</p> <p>I load a Recipe and LINQ retrieves Ingredient objects into an EntitySet that is binded into a ListBox.</p> <p>If I want to delete some Ingredients off a Recipe, I get a "An attempt was made to remove a relationship between a Recipe and a Ingredient. However, one of the relationship's foreign keys (Ingredient.RecipeID) cannot be set to null. </p> <p>I SOLVED this problem using the well known solution by adding 'DeleteOnNull="true"' to the DBML file. But adding this setting only removes the problem when we are deleting Ingredient objects that were retrieved from the DB.</p> <p>The problem is with the Ingredient objects that were created in code (added to a Recipe) and added to the EntitySet collection of Ingredients and then deleted BEFORE SubmitUpdates is called. Then, the same exception happens again. This usually happens on a new, unsaved recipe when user is adding ingredients to it, makes a mistake and erases an ingredient off a recipe. I added the DeleteOnNull to both 'Association Name="Recipe_Ingredient"' lines in DBML.</p> <p>How am I supposed to remove such objects? The only solution I see at the moment is that I would load the ingredients into a collection not under the DataContext and then when saving, delete all ingredients off a recipe and add then again from that cache..</p>
[ { "answer_id": 388239, "author": "mjwills", "author_id": 34092, "author_profile": "https://Stackoverflow.com/users/34092", "pm_score": 3, "selected": false, "text": " try\n {\n // Needed for existing records, but will fail for new records\n yourLINQDat...
2008/12/21
[ "https://Stackoverflow.com/questions/384755", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48159/" ]
384,759
<p>How do I convert a PIL <code>Image</code> back and forth to a NumPy array so that I can do faster pixel-wise transformations than PIL's <code>PixelAccess</code> allows? I can convert it to a NumPy array via:</p> <pre><code>pic = Image.open(&quot;foo.jpg&quot;) pix = numpy.array(pic.getdata()).reshape(pic.size[0], pic.size[1], 3) </code></pre> <p>But how do I load it back into the PIL <code>Image</code> after I've modified the array? <code>pic.putdata()</code> isn't working well.</p>
[ { "answer_id": 384926, "author": "dF.", "author_id": 3002, "author_profile": "https://Stackoverflow.com/users/3002", "pm_score": 10, "selected": true, "text": "putdata() >>> pic.putdata(a)\nTraceback (most recent call last):\n File \"...blablabla.../PIL/Image.py\", line 1185, in putdata...
2008/12/21
[ "https://Stackoverflow.com/questions/384759", "https://Stackoverflow.com", "https://Stackoverflow.com/users/145/" ]
384,762
<p>I used MySQL Workbench to generate a database and now I inserted it into the command-line client using:</p> <blockquote> <p>mysql> . C:\Documents and Settings\kdegroote\My Documents\School\2008-2009\ICT2 \Gegevensbanken\Labo\Hoofdstuk 3 oef 6\pizzasecondtry.sql</p> </blockquote> <p>For some reason, the last table won't be accepted. "Cannot create table" is the error message.</p> <p>I manually editted the data to basically be the same, just without the special options Workbench adds to it and it worked like that.</p> <p>I've been studying the original but I don't understand why it won't show me the tables. So I was wondering if anybody here could have a look at it. Maybe someone else will see what I'm overlooking.</p> <pre><code>SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0; SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0; SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL'; CREATE SCHEMA IF NOT EXISTS `PizzaDelivery` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; USE `PizzaDelivery`; CREATE TABLE IF NOT EXISTS `PizzaDelivery`.`Visitors` ( `visitor_id` INT NOT NULL AUTO_INCREMENT , `name` VARCHAR(45) NOT NULL , `adres` VARCHAR(45) NOT NULL , `telephone` MEDIUMBLOB NOT NULL , `email` VARCHAR(45) NOT NULL , PRIMARY KEY (`visitor_id`))ENGINE=InnoDB; CREATE TABLE IF NOT EXISTS `PizzaDelivery`.`Employees` ( `employee_id` INT NOT NULL AUTO_INCREMENT , `name` VARCHAR(45) NOT NULL , PRIMARY KEY (`employee_id`))ENGINE=InnoDB; CREATE TABLE IF NOT EXISTS `PizzaDelivery`.`Orders` ( `order_id` INT NOT NULL AUTO_INCREMENT , `pizza` VARCHAR(45) NOT NULL , `extra` VARCHAR(45) NULL , `kind` VARCHAR(45) NOT NULL , `amount` VARCHAR(45) NOT NULL , `visitor_id` INT NOT NULL , `employee_id` INT NOT NULL , `order_time` TIME NOT NULL , PRIMARY KEY (`order_id`) , INDEX `visitor_id` (`visitor_id` ASC) , INDEX `employee_id` (`employee_id` ASC) , CONSTRAINT `visitor_id` FOREIGN KEY (`visitor_id` ) REFERENCES `PizzaDelivery`.`Visitors` (`visitor_id` ) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `employee_id` FOREIGN KEY (`employee_id` ) REFERENCES `PizzaDelivery`.`Employees` (`employee_id` ) ON DELETE NO ACTION ON UPDATE NO ACTION)ENGINE=InnoDB; CREATE TABLE IF NOT EXISTS `PizzaDelivery`.`Deliveries` ( `employee_id` INT NOT NULL , `order_id` INT NOT NULL , `voertuig_id` INT NOT NULL , `deliverytime` TIME NOT NULL , PRIMARY KEY (`employee_id`, `order_id`) , INDEX `employee_id` (`employee_id` ASC) , INDEX `order_id` (`order_id` ASC) , CONSTRAINT `employee_id` FOREIGN KEY (`employee_id` ) REFERENCES `PizzaDelivery`.`Employees` (`employee_id` ) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `order_id` FOREIGN KEY (`order_id` ) REFERENCES `PizzaDelivery`.`Orders` (`order_id` ) ON DELETE NO ACTION ON UPDATE NO ACTION)ENGINE=InnoDB; SET SQL_MODE=@OLD_SQL_MODE; SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS; SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS; </code></pre>
[ { "answer_id": 384768, "author": "derobert", "author_id": 27727, "author_profile": "https://Stackoverflow.com/users/27727", "pm_score": 1, "selected": false, "text": "use PizzaDelivery PizzaDelivery $ mysql -h <db-host> -u <username> -p <schema-name>\n" }, { "answer_id": 384884, ...
2008/12/21
[ "https://Stackoverflow.com/questions/384762", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11795/" ]
384,771
<p>for writing an offline client to the Google Reader service I would like to know how to best sync with the service. </p> <p>There doesn't seem to be official documentation yet and the best source I found so far is this: <a href="http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI" rel="noreferrer">http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI</a></p> <p>Now consider this: With the information from above I can download all unread items, I can specify how many items to download and using the atom-id I can detect duplicate entries that I already downloaded.</p> <p>What's missing for me is a way to specify that I just want the updates since my last sync. I can say give me the 10 (parameter <em>n</em>=10) latest (parameter <em>r</em>=d) entries. If I specify the parameter <em>r</em>=o (date ascending) then I can also specify parameter <em>ot</em>=[last time of sync], but only then and the ascending order doesn't make any sense when I just want to read some items versus all items.</p> <p>Any idea how to solve that without downloading all items again and just rejecting duplicates? Not a very economic way of polling.</p> <p>Someone proposed that I can specify that I only want the unread entries. But to make that solution work in the way that Google Reader will not offer this entries again, I would need to mark them as read. In turn that would mean that I need to keep my own read/unread state on the client <em>and</em> that the entries are already marked as read when the user logs on to the online version of Google Reader. That doesn't work for me.</p> <p>Cheers, Mariano </p>
[ { "answer_id": 1023109, "author": "cjs", "author_id": 107294, "author_profile": "https://Stackoverflow.com/users/107294", "pm_score": 4, "selected": true, "text": "<gr:continuation>CArhxxjRmNsC</gr:continuation>`\n c http://www.google.com/reader/atom/user/-/state/com.google/reading-list?...
2008/12/21
[ "https://Stackoverflow.com/questions/384771", "https://Stackoverflow.com", "https://Stackoverflow.com/users/45867/" ]
384,775
<p>I'm learning iPhone programming from Erica Sadun's The iPhone Developer's Cookbook. When I run the app I created by following the steps in the Temperature Conversion Example starting on page 81 in the simulator, it terminates due to an uncaught exception. (See <a href="http://groups.google.com/group/iphonesdk/browse_frm/thread/6f44a90fdb8da28a?hl=en" rel="nofollow noreferrer">http://groups.google.com/group/iphonesdk/browse_frm/thread/6f44a90fdb8da28a?hl=en</a> for the question I posted to the iPhoneSDK Google Group.)</p> <p>The exception is thrown after calling UIApplicationMain() from my main(). If I look through the stack trace in the debugger, all I see is (of course) assembly. How do I find out what kind of exception was thrown? </p> <p><strong>Update</strong>:<br> Learning the details of the exception from the Debugger Console was enough to help me solve the problem. (See <a href="http://groups.google.com/group/iphonesdk/browse_frm/thread/6f44a90fdb8da28a?hl=en" rel="nofollow noreferrer">http://groups.google.com/group/iphonesdk/browse_frm/thread/6f44a90fdb8da28a?hl=en</a>.) I verified that I could set a symbolic breakpoint on <code>objc_exception_throw</code>, but I didn't look to see if the backtrace from there would have been helpful.</p>
[ { "answer_id": 384795, "author": "Lily Ballard", "author_id": 582, "author_profile": "https://Stackoverflow.com/users/582", "pm_score": 7, "selected": true, "text": "objc_exception_throw" }, { "answer_id": 9138988, "author": "samwize", "author_id": 242682, "author_pro...
2008/12/21
[ "https://Stackoverflow.com/questions/384775", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4766/" ]
384,776
<p>I've seen on the internet quite a few examples of binding a boolean to the Visibility property of a control in XAML. Most of the good examples use a BooleanToVisibiliy converter.</p> <p>I'd like to just set the Visible property on the control to bind to a System.Windows.Visibility property in the code-behind, but it doesn't seem to want to work.</p> <p>This is my XAML:</p> <pre><code>&lt;Grid x:Name="actions" Visibility="{Binding Path=ActionsVisible, UpdateSourceTrigger=PropertyChanged}" /&gt; </code></pre> <p>This is the code for the property:</p> <pre><code>private Visibility _actionsVisible; public Visibility ActionsVisible { get { return _actionsVisible; } set { _actionsVisible = value; } } </code></pre> <p>In the constructor of the Window, I also have this call:</p> <pre><code>base.DataContext = this; </code></pre> <p>When I update either ActionsVisible or this.actions.Visibility, the state doesn't transfer. Any ideas to what might be going wrong?</p>
[ { "answer_id": 384952, "author": "NR.", "author_id": 48142, "author_profile": "https://Stackoverflow.com/users/48142", "pm_score": 3, "selected": false, "text": " public Visibility ActionsVisible\n {\n get { return (Visibility)GetValue(ActionsVisibleProperty); }\n ...
2008/12/21
[ "https://Stackoverflow.com/questions/384776", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24841/" ]
384,789
<p>I've got few files in resources (xsd files) that i use for validating received xml messages. The resource file i use is named <strong>AppResources.resx</strong> and it contains a file called <strong>clientModels.xsd</strong>. When i try to use the file like this: AppResources.clientModels, i get a string with the file's content. i would like to get a stream instead. i do not wish to use assembly.GetManifestResourceStream as i had bad experiences with it (using these streams to archive files with SharpZipLib didn't work for some reason). is there any other way to do it? i've heard about ResourceManager - is it anything that could help me?</p>
[ { "answer_id": 401620, "author": "dbones", "author_id": 47642, "author_profile": "https://Stackoverflow.com/users/47642", "pm_score": 1, "selected": false, "text": "//Namespace reference\nusing System;\nusing System.Resources;\n\n\n#region ReadResourceFile\n/// <summary>\n/// method for ...
2008/12/21
[ "https://Stackoverflow.com/questions/384789", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40872/" ]
384,797
<p>Firstly, <em>Real World Haskell</em>, which I am reading, says to never use <code>foldl</code> and instead use <code>foldl'</code>. So I trust it. </p> <p>But I'm hazy on when to use <code>foldr</code> vs. <code>foldl'</code>. Though I can see the structure of how they work differently laid out in front of me, I'm too stupid to understand when "which is better." I guess it seems to me like it shouldn't really matter which is used, as they both produce the same answer (don't they?). In fact, my previous experience with this construct is from Ruby's <code>inject</code> and Clojure's <code>reduce</code>, which don't seem to have "left" and "right" versions. (Side question: which version do they use?) </p> <p>Any insight that can help a smarts-challenged sort like me would be much appreciated!</p>
[ { "answer_id": 384802, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 5, "selected": false, "text": "foldl foldr" }, { "answer_id": 384803, "author": "mattiast", "author_id": 8272, "author_profile":...
2008/12/21
[ "https://Stackoverflow.com/questions/384797", "https://Stackoverflow.com", "https://Stackoverflow.com/users/38803/" ]
384,809
<p>I have a mac with a custom PHP 5 install that built from about a year ago. I remember it took all Sunday and I had to compile about 20 times to get it right. The MySQL I have is from entropy and was precompiled.</p> <p>Now I need to get PDO with the MySQL driver working and the driver is not installed. I tried the "pecl install pdo_mysql" and it dies at a point where it can't find some mysql files. Any ideas how I can fix this quickly?</p> <pre><code>checking for mysql_config... not found configure: error: Cannot find MySQL header files under ERROR: `/private/tmp/pear/temp/PDO_MYSQL/configure' failed </code></pre> <p>I'll post whatever paths or messages you need to help me troubleshoot this. Will I have to compile PHP all over again, or can I just compile the pdo_mysql extension? </p> <p>I hope I don't seem lazy, I just have a lot of code to write and not a lot of time to fight with my PHP configuration.</p>
[ { "answer_id": 384893, "author": "ieure", "author_id": 45224, "author_profile": "https://Stackoverflow.com/users/45224", "pm_score": 4, "selected": true, "text": "/usr/local/mysql $ pecl download pdo_mysql\n$ tar xzf PDO_MYSQL-1.0.2.tgz\n$ cd PDO_MYSQL-1.0.2\n$ phpize\n$ ./configure --wi...
2008/12/21
[ "https://Stackoverflow.com/questions/384809", "https://Stackoverflow.com", "https://Stackoverflow.com/users/577/" ]
384,811
<p>I'm trying to choose a hash algorithm for comparing about max 20 different text data. </p> <p>Which hash is better for these requirements?</p> <ul> <li>Less CPU Consumption</li> <li>Small footprint (&lt;=32 bytes)</li> <li>Collision is not a big deal</li> <li>Can be generated from .NET Framework 2 (shouldn't be a 3rd party library)</li> </ul> <p><em>I'm using hash for less memory footprint and comparison performance</em></p>
[ { "answer_id": 384915, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 0, "selected": false, "text": "GetHashCode() GetHashCode() Dictionary<string,Something>" } ]
2008/12/21
[ "https://Stackoverflow.com/questions/384811", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40322/" ]
384,820
<p>Is there a way to specify some JavaScript to execute on the OnBlur event of an ASP.NET text box? It seems to me like if I add any event handlers to the TextBox object they will just cause postbacks to the server isntead of doing what I want. Basically, I just want to be able to have the textbox be rendered in this HTML:</p> <pre><code>&lt;INPUT type="text" onblur="alert('1234')" /&gt; </code></pre> <p>Thanks!</p>
[ { "answer_id": 384826, "author": "FlySwat", "author_id": 1965, "author_profile": "https://Stackoverflow.com/users/1965", "pm_score": 4, "selected": false, "text": "myTextBox.Attributes.Add(\"onblur\",\"alert('1234');\");\n" }, { "answer_id": 384848, "author": "Tom Jelen", ...
2008/12/21
[ "https://Stackoverflow.com/questions/384820", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14101/" ]
384,851
<p>I've been tasked with designing a very simple SSO (single sign-on) process. My employer has specified that it should be implemented in SAML. I'd like to create messages that are absolutely as simple as possible while confirming to the SAML spec. </p> <p>I'd be really grateful if some of you would look at my request and response messages and tell me if they make sense for my purpose, if they include anything that <em>doesn't</em> need to be there, and if they are missing anything that <em>does</em> need to be there. </p> <p>Additionally, I'd like to know where in the response I should put additional information about the subject; in particular, the subject's email address.</p> <p>The interaction needs to work as follows:</p> <ol> <li>User requests service from service provider at this point, the service provider knows nothing about the user. </li> <li>Service provider requests authentication for user from identity provider</li> <li>User is authenticated/registered by identity provider</li> <li>Identity provider responds to Service provider with authentication success message, PLUS user's email address.</li> </ol> <p>Here's what I think the request should be:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;samlp:AuthnRequest xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" ID="abc" IssueInstant="1970-01-01T00:00:00.000Z" Version="2.0" AssertionConsumerServiceURL="http://www.IdentityProvider.com/loginPage"&gt; &lt;saml:Issuer xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"&gt; http://www.serviceprovider.com &lt;/saml:Issuer&gt; &lt;saml:Subject&gt; &lt;saml:NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:transient"&gt;3f7b3dcf-1674-4ecd-92c8-1544f346baf8&lt;/saml:NameID&gt; &lt;/saml:Subject&gt; </code></pre> <p>Here's what I think the response should be:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" Destination="http://www.serviceprovider.com/desitnationURL" ID="123" IssueInstant="2008-11-21T17:13:42.872Z" Version="2.0"&gt; &lt;samlp:Status&gt; &lt;samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success"/&gt; &lt;/samlp:Status&gt; &lt;saml:Assertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" Version="2.0"&gt; &lt;saml:Subject&gt; &lt;saml:NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:transient"&gt;3f7b3dcf-1674-4ecd-92c8-1544f346baf8&lt;/saml:NameID&gt; &lt;saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:profiles:SSO:browser"&gt; &lt;saml:SubjectConfirmationData InResponseTo="abc"/&gt; &lt;/saml:SubjectConfirmation&gt; &lt;/saml:Subject&gt; &lt;saml:AuthnStatement AuthnInstant="2008-11-21T17:13:42.899Z"&gt; &lt;saml:AuthnContext&gt; &lt;saml:AuthnContextClassRef&gt;urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport&lt;/saml:AuthnContextClassRef&gt; &lt;/saml:AuthnContext&gt; &lt;/saml:AuthnStatement&gt; &lt;/saml:Assertion&gt; &lt;/samlp:Response&gt; </code></pre> <p>So, again, my questions are:</p> <ol> <li><p>Is this a valid SAML interaction?</p></li> <li><p>Can either the request or response XML be simplified?</p></li> <li><p>Where in the response should I put the subject's email address?</p></li> </ol> <p>I really appreciate your help. Thanks so much!</p> <p>-Morgan</p>
[ { "answer_id": 419221, "author": "metadaddy", "author_id": 33905, "author_profile": "https://Stackoverflow.com/users/33905", "pm_score": 4, "selected": false, "text": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<samlp:AuthnRequest xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\"\n ...
2008/12/21
[ "https://Stackoverflow.com/questions/384851", "https://Stackoverflow.com", "https://Stackoverflow.com/users/44683/" ]
384,862
<p>My web site is hosted at Dreamhost and there they only get zlib installed along with PHP. I couldn't figure out how to unzip files with the commom methods from this extension as described here : <a href="http://php.net/zlib" rel="nofollow noreferrer">http://php.net/zlib</a></p> <p>Does anyone knows how can I unzip a .gz or .gzip file with zlib extension on PHP? That would save my life!</p>
[ { "answer_id": 384872, "author": "strager", "author_id": 39992, "author_profile": "https://Stackoverflow.com/users/39992", "pm_score": 2, "selected": false, "text": "fopen compress.zlib://" } ]
2008/12/21
[ "https://Stackoverflow.com/questions/384862", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
384,871
<p>I need to build an assembler for a CPU architecture that I've built. The architecture is similar to MIPS, but this is of no importance.</p> <p>I started using C#, although C++ would be more appropriate. (C# means faster development time for me).</p> <p>My only problem is that I can't come with a good design for this application. I am building a 2 pass assembler. I know what I need to do in each pass.\</p> <p>I've implemented the first pass and I realised that if I have to lines assembly code on the same line ...no error is thrown.This means only one thing poor parsing techniques.</p> <p>So almighty programmers, fathers of assembler enlighten me how should I proceed. I just need to support symbols and data declaration. Instructions have fixed size.</p> <p>Please let me know if you need more information.</p>
[ { "answer_id": 384896, "author": "plinth", "author_id": 20481, "author_profile": "https://Stackoverflow.com/users/20481", "pm_score": 5, "selected": true, "text": "nothing\n[label] [instruction] [comment]\n[label] [directive] [comment]\n" } ]
2008/12/21
[ "https://Stackoverflow.com/questions/384871", "https://Stackoverflow.com", "https://Stackoverflow.com/users/47117/" ]
384,873
<p>I am looking at some javascript code and it has this in a function:</p> <pre><code>$$('.CssClass').each(function(x) { .... } ) </code></pre> <p>I get that the intent is to apply the anonymous function to each element with a class of CssClass, but I can't work what the $$ refers to ... and can't google for $$!</p> <p><strong>Update</strong>: thanks for the hints. The javascript comes from the iPhone look-alike library: <a href="http://www.journyx.com/jpint/" rel="nofollow noreferrer">jPint</a> which includes the <a href="http://www.prototypejs.com/" rel="nofollow noreferrer">prototypejs</a> library, and does define $$ as:</p> <pre><code>function $$() { return Selector.findChildElements(document, $A(arguments)); } </code></pre>
[ { "answer_id": 384878, "author": "Johannes Schaub - litb", "author_id": 34509, "author_profile": "https://Stackoverflow.com/users/34509", "pm_score": 1, "selected": false, "text": "$ $$ .CssClass each $" }, { "answer_id": 384885, "author": "Tom Haigh", "author_id": 22224,...
2008/12/21
[ "https://Stackoverflow.com/questions/384873", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3631/" ]
384,874
<p>My problem is very similar to eight queens puzzle.</p> <p>I've got 2-dimensional array (N x N) that for example, looks like this:</p> <pre><code>0,0,0,0,1 y 0,0,0,0,0 | 0,0,0,0,0 V 0,0,0,1,0 0,0,0,0,0 x-&gt; </code></pre> <p>I'm checking horizontally, vertically and diagonally for occurrences of 1</p> <pre><code>\,0,|,0,/ 0,\,|,/,0 -,-,1,-,- 0,/,|,\,0 /,0,|,0,\ </code></pre> <p>I'm thinking about storing only the (x,y) postions of "1"'s in a list </p> <pre><code>[[4,0],[3,3]] </code></pre> <p>and solving it mathematically, check every position of "1" with another (x1,y1)&lt;->(x2,y2),</p> <p>if <code>x1 == x2</code> or <code>y1 == y2</code> <code>we have a collision!</code> if not check:</p> <pre><code>x2 == x1 + z; y2 == y1 + z; x2 == x1 - z; y2 == y1 - z; </code></pre> <p>(???)</p> <p>where z is +/- that <code>( x1+z in 0..N ) and ( y1+z in 0..N ) .......</code></p> <p><strong><em>My problem is checking for diagonal collision, is there a better way to do it???</em></strong></p>
[ { "answer_id": 384887, "author": "dF.", "author_id": 3002, "author_profile": "https://Stackoverflow.com/users/3002", "pm_score": 5, "selected": true, "text": "def collision(x1, y1, x2, y2):\n return x1 == x2 or y1 == y2 or abs(x1-x2) == abs(y1-y2)\n" }, { "answer_id": 384908, ...
2008/12/21
[ "https://Stackoverflow.com/questions/384874", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9099/" ]
384,898
<p>I have read that private variables in a base class are technically inherited by child classes, but are not accessible.</p> <p>If this is correct, why do we say they are inherited when presumably they can only be accessed by reflection?</p>
[ { "answer_id": 384906, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 5, "selected": true, "text": "Foo BinaryFormatter" } ]
2008/12/21
[ "https://Stackoverflow.com/questions/384898", "https://Stackoverflow.com", "https://Stackoverflow.com/users/38522/" ]
384,900
<p>I'm looking to stream some audio files I have on my server to an iPhone-client application I'm writing. Some of the audio files can be rather large in size, even after compression. My question is, is there a Cocoa framework that helps me with buffering the audio so it becomes available to the user while the rest is being brought down the pipes? If not, can anyone point me in the right direction to learn more about the technologies required to make such a thing happen using Objective-C/Cocoa?</p> <p>A definitive resource on buffering and compression of audio from a server&lt;->client infrastructure would be ideal.</p>
[ { "answer_id": 8765033, "author": "Hivebrain", "author_id": 149898, "author_profile": "https://Stackoverflow.com/users/149898", "pm_score": 3, "selected": false, "text": "NSURL *theURL = [NSURL urlWithString:@\"http://yourdomain.com/yourmediafile.mp3\"];\n\nMPMoviePlayerController* yourP...
2008/12/21
[ "https://Stackoverflow.com/questions/384900", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40882/" ]
384,913
<p>I need to work with array from several threads, so I use CRITICAL SECTION to give it an exclusive access to the data.<br> Here is my template:<br></p> <pre><code>#include "stdafx.h" #ifndef SHAREDVECTOR_H #define SHAREDVECTOR_H #include &lt;vector&gt; #include &lt;windows.h&gt; template&lt;class T&gt; class SharedVector { std::vector&lt;T&gt; vect; CRITICAL_SECTION cs; SharedVector(const SharedVector&lt;T&gt;&amp; rhs) {} public: SharedVector(); explicit SharedVector(const CRITICAL_SECTION&amp; CS); void PushBack(const T&amp; value); void PopBack(); unsigned int size() const; T&amp; operator[](int index); virtual ~SharedVector(); }; template&lt;class T&gt; SharedVector&lt;T&gt;::SharedVector() { InitializeCriticalSection(&amp;cs); } template&lt;class T&gt; SharedVector&lt;T&gt;::SharedVector(const CRITICAL_SECTION&amp; r): cs(r) { InitializeCriticalSection(&amp;cs); } template&lt;class T&gt; void SharedVector&lt;T&gt;::PushBack(const T&amp; value) { EnterCriticalSection(&amp;cs); vect.push_back(value); LeaveCriticalSection(&amp;cs); } template&lt;class T&gt; void SharedVector&lt;T&gt;::PopBack() { EnterCriticalSection(&amp;cs); vect.pop_back(); LeaveCriticalSection(&amp;cs); } template&lt;class T&gt; unsigned int SharedVector&lt;T&gt;::size() const { EnterCriticalSection(&amp;cs); unsigned int result = vect.size(); LeaveCriticalSection(&amp;cs); return result; } template&lt;class T&gt; T&amp; SharedVector&lt;T&gt;::operator[](int index) { EnterCriticalSection(&amp;cs); T result = vect[index]; LeaveCriticalSection(&amp;cs); return result; } template&lt;class T&gt; SharedVector&lt;T&gt;::~SharedVector() { DeleteCriticalSection(&amp;cs); } </code></pre> <p>While compiling I have such a problem for calling <code>EnterCriticalSection(&amp;cs)</code> and <code>LeaveCriticalSection(&amp;cs)</code>:</p> <pre> 'EnterCriticalSection' : cannot convert parameter 1 from 'const CRITICAL_SECTION *' to 'LPCRITICAL_SECTION' </pre> <p>I do not know what is wrong. May be you can see. Just because I always used it this way and it was alright. <code>windows.h</code> is included</p>
[ { "answer_id": 384922, "author": "Arnout", "author_id": 3496, "author_profile": "https://Stackoverflow.com/users/3496", "pm_score": 1, "selected": false, "text": "EnterCriticalSection InitializeCriticalSection" }, { "answer_id": 384924, "author": "Eclipse", "author_id": 8...
2008/12/21
[ "https://Stackoverflow.com/questions/384913", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28298/" ]
384,916
<p>I'm setting up a site where users have their own "profile". I'm using routes for neat URLs and I wondered what are the pros/cons to the following:</p> <pre><code>example.com/:username </code></pre> <p>Or should I include a static route to filter that it's a profile page request?</p> <pre><code>example.com/u/:username example.com/something-static/:username </code></pre> <p>Which is best?</p>
[ { "answer_id": 384921, "author": "DanSingerman", "author_id": 43965, "author_profile": "https://Stackoverflow.com/users/43965", "pm_score": 2, "selected": false, "text": "example.com/:username\n profiles.example.com/:username\n" } ]
2008/12/21
[ "https://Stackoverflow.com/questions/384916", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31399/" ]
384,918
<p>The following method does not compile. Visual Studio warns "An out parameter may not be used within an anonymous method". The <code>WithReaderLock(Proc action)</code> method takes a <code>delegate void Proc()</code>.</p> <pre><code>public Boolean TryGetValue(TKey key, out TValue value) { Boolean got = false; WithReaderLock(delegate { got = dictionary.TryGetValue(key, out value); }); return got; } </code></pre> <p>What's the best way to get this behavior? (Please refrain from providing advice on threadsafe dictionaries, this question is intended to solve the out parameter problem in general).</p>
[ { "answer_id": 384920, "author": "Anthony Mastrean", "author_id": 3619, "author_profile": "https://Stackoverflow.com/users/3619", "pm_score": 1, "selected": false, "text": "public Boolean TryGetValue(TKey key, out TValue value)\n{\n internalLock.AcquireReaderLock(Timeout.Infine);\n ...
2008/12/21
[ "https://Stackoverflow.com/questions/384918", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3619/" ]
384,923
<p>I have the below query, which basically it retrieves the 5 top most books sold:</p> <pre><code> select top 5 count(id_book_orddetails) 'books_sold', bk.* from orderdetails_orddetails ord inner join books_book bk on ord.id_book_orddetails = bk.id_book group by id_book, name_book,author_book,desc_book,id_ctg_book,qty_book,image_book,isdeleted order by 'books_sold' desc </code></pre> <p>The problem is that I am receiving this error:</p> <blockquote> <p>The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator.</p> </blockquote> <p>In the <code>books_book</code> table, the field <code>desc_book</code> is of type <code>ntext</code>, and I'm sure that the problem is coming from there.</p> <p>This is because before I changed the <code>desc_book</code> to <code>ntext</code>, it was of type <code>nvarchar</code> and it worked perfectly.</p> <p>The reason I changed the data type of this field is because somehow in PHP website, when I was displaying the book description (a different sp), the description was being truncated to about 200-255 characters, thus I changed it to <code>ntext</code> and it 'solved my problem' (ie, the whole <code>desc_book</code> was finally being displayed).</p> <p>So basically these are my questions :</p> <ol> <li><strong>Why is the <code>desc_book</code> (nvarchar) field being truncated when displayed in a PHP page?</strong></li> <li><strong>How can i fix the SQL query to accommodate for grouping by an <code>ntext</code> field?</strong></li> </ol> <p>Just for the record (which I don't think is very relevant), I am using <em>MS SQL Server 2005</em></p> <p><strong>[UPDATE]</strong></p> <p>I tried and tested both of <a href="https://stackoverflow.com/questions/384923/sql-query-grouping-by-an-ntext-field#384957">Bill Karwin</a>'s proposed solutions and they both work perfectly. I thus decided in grouping the count aggregate result into a subquery...ie's Karwin's latter solution.</p> <p>So here is my updated (fully working) statement:</p> <pre><code>SELECT bk.*, bc.books_sold FROM books_book bk INNER JOIN ( SELECT bk2.id_book, COUNT(*) books_sold FROM books_book bk2 INNER JOIN orderdetails_orddetails ord ON (bk2.id_book = ord.id_book_orddetails) GROUP BY bk2.id_book ) bc ON (bk.id_book = bc.id_book) ORDER BY books_sold desc; </code></pre>
[ { "answer_id": 384951, "author": "Jonas Lincoln", "author_id": 17436, "author_profile": "https://Stackoverflow.com/users/17436", "pm_score": 0, "selected": false, "text": "desc_book CAST(desc_book AS NVARCHAR(2000)) AS desc_book" }, { "answer_id": 384957, "author": "Bill Karw...
2008/12/21
[ "https://Stackoverflow.com/questions/384923", "https://Stackoverflow.com", "https://Stackoverflow.com/users/44084/" ]
384,931
<p>I'm creating an WPF app, so I'm mostly working with the ImageSource class for icons. However, the system tray icon has to be of type <code>System.Drawing.Icon</code>. Is it possible to create such an object from a png image?</p> <p>I have tried the following:</p> <pre><code>private static System.Drawing.Icon _pngIcon; public static System.Drawing.Icon PngIcon { get { if (_pngIcon == null) { //16x16 png image (24 bit or 32bit color) System.Drawing.Bitmap icon = global::BookyPresentation.Properties.Resources.star16; MemoryStream iconStream = new MemoryStream(); icon.Save(iconStream, System.Drawing.Imaging.ImageFormat.Png); iconStream.Seek(0, SeekOrigin.Begin); _pngIcon = new System.Drawing.Icon(iconStream); //Throws exception } return _pngIcon; } } </code></pre> <p>The Icon constructor throws an exception with the following message: "Argument 'picture' must be a picture that can be used as a Icon."</p> <p>I figured it might be something with the bit depth of the image color as I had some issues with this earlier, but both 32bit and 24bit images didn't work. Is it possible what I'm trying to do?</p>
[ { "answer_id": 385000, "author": "Vilx-", "author_id": 41360, "author_profile": "https://Stackoverflow.com/users/41360", "pm_score": 2, "selected": false, "text": "public void Convert(string pngPath, string icoPath)\n{\n MultiIcon mIcon = new MultiIcon();\n SingleIcon sIcon = mIcon...
2008/12/21
[ "https://Stackoverflow.com/questions/384931", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4055/" ]
384,935
<p>On a recent episode of <a href="http://www.dotnetrocks.com/about.aspx" rel="nofollow noreferrer">.NET Rocks</a> (<a href="http://www.dotnetrocks.com/default.aspx?showNum=404" rel="nofollow noreferrer">episode 404)</a>, they mentioned that a lot of Visual Studio issues could be reduced if you set the platform target to be x86 instead of 'Any CPU'. I did a few Google searches and couldn't find anything about it. </p> <p>At my company we have a mix of 32-bit (x86) and 64-bit (x64) developer machines. There are some issues with losing references of third-party components installed under 'Program Files (x86)' vs 'Program Files' when switching back and forth between the developers on different machines. </p> <p>Would switching to target x86 machines fix this issue with 'Program Files (x86)'?</p> <p>Also, are there sites or posts I can read more about this (I couldn't find any!)? </p>
[ { "answer_id": 385094, "author": "Colby Africa", "author_id": 47164, "author_profile": "https://Stackoverflow.com/users/47164", "pm_score": 2, "selected": false, "text": "/platform: /platform:anycpu" } ]
2008/12/21
[ "https://Stackoverflow.com/questions/384935", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1632/" ]
384,939
<p>In Javascript, I want my onmouseout event to sleep/pause/wait/ (not sure of the proper terminology here) for three seconds before taking effect. How is that accomplished?</p> <p>thanks</p>
[ { "answer_id": 384946, "author": "Georg Schölly", "author_id": 24587, "author_profile": "https://Stackoverflow.com/users/24587", "pm_score": 3, "selected": true, "text": "function outfunction(event) {\n var that = this; // to be able to use this later.\n window.setTimeout(function(...
2008/12/21
[ "https://Stackoverflow.com/questions/384939", "https://Stackoverflow.com", "https://Stackoverflow.com/users/45429/" ]
384,955
<p>Which method do you think is the "best".</p> <ul> <li>Use the <code>System.IO.Packaging</code> namespace?</li> <li>Use interop with the Shell?</li> <li>Third party library for .NET?</li> <li>Interop with open source unmanaged DLL?</li> </ul> <p>[I can target Framework 3.5; best = easiest to design, implement, and maintain.]</p> <p>I am mostly interested in why you think the chosen approach is best.</p>
[ { "answer_id": 384963, "author": "configurator", "author_id": 9536, "author_profile": "https://Stackoverflow.com/users/9536", "pm_score": 1, "selected": false, "text": "System.IO.Packaging SharpZipLib" }, { "answer_id": 410404, "author": "Cheeso", "author_id": 48082, ...
2008/12/21
[ "https://Stackoverflow.com/questions/384955", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17595/" ]
384,962
<p>I have an iPhone app that's shipping (<em>vConqr</em> - you should go and buy it :-) ). I build the project on several different machines, including a colleague's, and it's been working fine. However, just recently, on my second dev machine my build fails every time with the error:</p> <p><code> /Developer/Library/Xcode/Plug-ins/CoreBuildTasks.xcplugin/Contents/Resources/copyplist Entitlements.plist --outdir /Code/iPhone/VirtualConquest/build/Debug-iphonesimulator/VirtualConquest.app </code></p> <p><code> error: can't exec '/Developer/Library/Xcode/Plug-ins/CoreBuildTasks.xcplugin/Contents/Resources/copyplist' (No such file or directory) </code></p> <p>I've reinstalled XCode - twice! (the second time I deleted the files under /Developer/Library/Xcode first). I've deleted my source tree and checked out of source control fresh. The error persists.</p> <p>The Entitlements.plist file has been there for a couple of weeks, since I started my last beta programme. I can't be sure, but I suspect I had not compiled on my second dev machine since it was added. However, as well as my primary dev machine, it also all builds fine on my colleagues machine, so I'm baffled what the difference can be.</p> <p>I've Googled for the error, but either my Google-Fu is bunk or this is not a common error - I've found no relevant hits.</p> <p>This is really frustrating, not least because I use my second machine as a soak test/ continuous integration machine.</p> <p>Anyone come across the same thing, or have any other suggestions?</p>
[ { "answer_id": 5970680, "author": "grumpit", "author_id": 325187, "author_profile": "https://Stackoverflow.com/users/325187", "pm_score": 1, "selected": false, "text": "#!/usr/bin/ruby\n #!/usr/local/bin/bash\n" } ]
2008/12/21
[ "https://Stackoverflow.com/questions/384962", "https://Stackoverflow.com", "https://Stackoverflow.com/users/32136/" ]
384,969
<p>I have an object not written by myself that I need to clone in memory. The object is not tagged <code>ICloneable</code> or <code>Serializable</code> so deep cloning through the interface or serialization will not work. Is there anyway to deep clone this object? A non-safe win32 API call maybe?</p>
[ { "answer_id": 384983, "author": "JoshBerke", "author_id": 26160, "author_profile": "https://Stackoverflow.com/users/26160", "pm_score": 4, "selected": true, "text": "ICloneable ICloneable ISerializable Serializable XmlSerializer XmlSerialized IDictionary" } ]
2008/12/21
[ "https://Stackoverflow.com/questions/384969", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4244/" ]
384,974
<p>Folks,</p> <p>I have a webservice that returns data in ISO-8859-1 encoding - since it's not mine, I can't change that :-(</p> <p>For auditing purposes, I'd like to store the resulting XML from these calls into a SQL Server 2005 table, in which I have a field of type "XML NULL".</p> <p>From my C# code, I try to store this XML content into the XML field using a parametrized query, something like</p> <pre><code>SqlCommand _cmd = new SqlCommand("INSERT INTO dbo.AuditTable(XmlField) VALUES(@XmlContents)", _connection); _cmd.Parameters.Add("@XmlContents", SqlDbType.Xml); _cmd.Parameters["@XmlContents"].Value = (my XML response); _cmd.ExecuteNonQuery(); </code></pre> <p>Trouble is - when I run this code, I get back an error:</p> <blockquote> <p>Msg 9402, Level 16, State 1, Line 1<br> XML parsing: line 1, character xy, unable to switch the encoding</p> </blockquote> <p>?? I was trying to figure out where and how I could possibly "switch" the encoding - no luck so far. What does this really mean? I cannot store XML with ISO-8859-1 encoding in SQL Server 2005?? Or is there a trick to a) tell SQL Server 2005 to just accept this encoding, or b) to automagically convert the webservice response to UTF encoding before storing in SQL Server?</p> <p>Thanks for any hints, pointers, tips! Marc</p>
[ { "answer_id": 384985, "author": "Nathan Koop", "author_id": 18821, "author_profile": "https://Stackoverflow.com/users/18821", "pm_score": 1, "selected": false, "text": "_cmd.Parameters.Add(\"@XmlContents\", SqlDbType.Xml);\n _cmd.Parameters.Add(\"@XmlContents\", System.Data.SqlTypes.Sql...
2008/12/21
[ "https://Stackoverflow.com/questions/384974", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13302/" ]
384,981
<p>I want put a div by iframe over a video containing an active player</p> <p>is it possible ?</p>
[ { "answer_id": 384985, "author": "Nathan Koop", "author_id": 18821, "author_profile": "https://Stackoverflow.com/users/18821", "pm_score": 1, "selected": false, "text": "_cmd.Parameters.Add(\"@XmlContents\", SqlDbType.Xml);\n _cmd.Parameters.Add(\"@XmlContents\", System.Data.SqlTypes.Sql...
2008/12/21
[ "https://Stackoverflow.com/questions/384981", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48193/" ]
384,991
<p>I want to find out which algorithm is the best that can be used for downsizing a raster picture. With best I mean the one that gives the nicest-looking results. I know of bicubic, but is there something better yet? For example, I've heard from some people that Adobe Lightroom has some kind of proprietary algorithm which produces better results than standard bicubic that I was using. Unfortunately I would like to use this algorithm myself in my software, so Adobe's carefully guarded trade secrets won't do.</p> <p><b>Added:</b></p> <p>I checked out Paint.NET and to my surprise it seems that Super Sampling is better than bicubic when downsizing a picture. That makes me wonder if interpolation algorithms are the way to go at all.</p> <p>It also reminded me of an algorithm I had "invented" myself, but never implemented. I suppose it also has a name (as something this trivial cannot be the idea of me alone), but I couldn't find it among the popular ones. Super Sampling was the closest one.</p> <p>The idea is this - for every pixel in target picture, calculate where it would be in the source picture. It would probably overlay one or more other pixels. It would then be possible to calculate the areas and colors of these pixels. Then, to get the color of the target pixel, one would simply calculate the average of these colors, adding their areas as "weights". So, if a target pixel would cover 1/3 of a yellow source pixel, and 1/4 of a green source pixel, I'd get (1/3*yellow + 1/4*green)/(1/3+1/4).</p> <p>This would naturally be computationally intensive, but it should be as close to the ideal as possible, no?</p> <p>Is there a name for this algorithm?</p>
[ { "answer_id": 60584355, "author": "tav", "author_id": 2692494, "author_profile": "https://Stackoverflow.com/users/2692494", "pm_score": 0, "selected": false, "text": "void area_averaging_image_scale(uint32_t *dst, int dst_width, int dst_height, const uint32_t *src, int src_width, int sr...
2008/12/21
[ "https://Stackoverflow.com/questions/384991", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41360/" ]
385,023
<p>I haven't written any C++ in years and now I'm trying to get back into it. I then ran across this and thought about giving up:</p> <pre><code>typedef enum TokenType { blah1 = 0x00000000, blah2 = 0X01000000, blah3 = 0X02000000 } TokenType; </code></pre> <p>What is this? Why is the <code>typedef</code> keyword used here? Why does the name <code>TokenType</code> appear twice in this declaration? How are the semantics different from this:</p> <pre><code>enum TokenType { blah1 = 0x00000000, blah2=0x01000000, blah3=0x02000000 }; </code></pre>
[ { "answer_id": 385033, "author": "Ryan Fox", "author_id": 55, "author_profile": "https://Stackoverflow.com/users/55", "pm_score": 7, "selected": false, "text": "TokenType my_type;\n enum TokenType my_type;\n" }, { "answer_id": 385045, "author": "mat", "author_id": 42083, ...
2008/12/21
[ "https://Stackoverflow.com/questions/385023", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36706/" ]
385,039
<p>Bjarne Stroustrup writes in his <a href="http://www.research.att.com/~bs/bs_faq2.html#finally" rel="nofollow noreferrer">C++ Style and Technique FAQ</a>, emphasis mine:</p> <blockquote> <p>Because C++ supports an alternative that is <strong><em>almost always better</em></strong>: The "resource acquisition is initialization" technique (TC++PL3 section 14.4). The basic idea is to represent a resource by a local object, so that the local object's destructor will release the resource. That way, the programmer cannot forget to release the resource. For example:</p> <pre><code>class File_handle { FILE* p; public: File_handle(const char* n, const char* a) { p = fopen(n,a); if (p==0) throw Open_error(errno); } File_handle(FILE* pp) { p = pp; if (p==0) throw Open_error(errno); } ~File_handle() { fclose(p); } operator FILE*() { return p; } // ... }; void f(const char* fn) { File_handle f(fn,"rw"); // open fn for reading and writing // use file through f } </code></pre> <p>In a system, we need a "resource handle" class for each resource. However, we don't have to have an "finally" clause for each acquisition of a resource. In realistic systems, there are far more resource acquisitions than kinds of resources, so the "resource acquisition is initialization" technique leads to less code than use of a "finally" construct.</p> </blockquote> <p>Note that Bjarne writes "almost always better" and not "always better". Now for my question: What situation would a <code>finally</code> construct be better than using the alternative construct (RAII) in C++?</p>
[ { "answer_id": 385076, "author": "Matthew Crumley", "author_id": 2214, "author_profile": "https://Stackoverflow.com/users/2214", "pm_score": 4, "selected": true, "text": "class RAII_Wrapper\n{\n Resource *resource;\n\npublic:\n RAII_Wrapper() : resource(aquire_resource()) {}\n\n ...
2008/12/21
[ "https://Stackoverflow.com/questions/385039", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19100/" ]
385,042
<p>I'm a MySQL guy working on a SQL Server project, trying to get a datetime field to show the current time. In MySQL I'd use NOW() but it isn't accepting that.</p> <pre><code>INSERT INTO timelog (datetime_filed) VALUES (NOW()) </code></pre>
[ { "answer_id": 385051, "author": "Daniel Schaffer", "author_id": 2596, "author_profile": "https://Stackoverflow.com/users/2596", "pm_score": 9, "selected": true, "text": "getdate() getutcdate()" }, { "answer_id": 385133, "author": "Ian Varley", "author_id": 37539, "au...
2008/12/21
[ "https://Stackoverflow.com/questions/385042", "https://Stackoverflow.com", "https://Stackoverflow.com/users/428190/" ]
385,052
<p>Hi I need some help with the following scenario in php. I have a db with users every user has an ID, have_card and want_card. I know how to make a direct match (one user trades with another user). But if there is no direct match but there is a circular swap like:</p> <p>User #1 has card A wants card B</p> <p>User #2 has card B wants card C</p> <p>User #3 has card C wants card A</p> <p>In this scenario there is no direct match between two users. But if:</p> <p>User #1 gives his card to User #3</p> <p>User #3 gives his card to User #2</p> <p>User #2 gives his card to User #1</p> <p>Every ones happy.</p> <p>All the info I have to start with is User #1 how do I find User #2 and User #3? </p> <p>Thanks to everyone for your answers.</p>
[ { "answer_id": 385062, "author": "Alex Renz", "author_id": 48188, "author_profile": "https://Stackoverflow.com/users/48188", "pm_score": 1, "selected": false, "text": "- if user two wants, what user one has, everything is fine an we're done\n- if not, continue\n - if user three wants, wh...
2008/12/21
[ "https://Stackoverflow.com/questions/385052", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
385,061
<p>I have an NSAttributedString <code>s</code> and an integer <code>i</code> and I'd like a function that takes <code>s</code> and <code>i</code> and returns a new NSAttributedString that has a (stringified) <code>i</code> prepended to <code>s</code>.</p> <p>It looks like some combination of <code>-stringWithFormat:</code>, <code>-initWithString:</code>, and <code>-insertAttributedString:</code> would do it but I'm having trouble piecing it together without a lot of convolution and temporary variables.</p> <p>More generally, pointers to guides on making sense of NSAttributedString and NSMutableAttributedString would be awesome.</p>
[ { "answer_id": 385211, "author": "Georg Schölly", "author_id": 24587, "author_profile": "https://Stackoverflow.com/users/24587", "pm_score": 3, "selected": false, "text": "// convert it to a mutable string\nNSMutableAttributedString *newString;\nnewString = [[NSMutableAttributedString al...
2008/12/21
[ "https://Stackoverflow.com/questions/385061", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4234/" ]
385,082
<p>I was working on a project that missbehaved, for some reasons no exception was thrown even when it should have. Deep down I have found this kind of error handling:</p> <pre><code>try { m.invoke(parentObject, paramObj); } catch (IllegalArgumentException e) { new CaseLibException(e); } catch (IllegalAccessException e) { new CaseLibException(e); } catch (InvocationTargetException e) { new CaseLibException(e); } </code></pre> <p>My brain recognized that several exceptions were wrapped into another one, so that's not so bad. But I had to stumble over this code at least 3 times to see what's missing...</p> <p>What is your most stupid bug you could not find?</p>
[ { "answer_id": 385101, "author": "Ed S.", "author_id": 1053, "author_profile": "https://Stackoverflow.com/users/1053", "pm_score": 4, "selected": false, "text": "if (x = 0) {\n...\n}\n" }, { "answer_id": 385159, "author": "Tom Hawtin - tackline", "author_id": 4725, "a...
2008/12/21
[ "https://Stackoverflow.com/questions/385082", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48181/" ]
385,088
<p>Are there any good tools available to track memory usage In a tomcat java webapp? I'm looking for something that can give a breakdown by class or package.</p> <p>Thanks, J</p>
[ { "answer_id": 385210, "author": "Kire Haglin", "author_id": 2049208, "author_profile": "https://Stackoverflow.com/users/2049208", "pm_score": 2, "selected": false, "text": "jrcmd <pid> print_object_summary 31.8% 3198k 41907 -137k [C\n11.9% 1196k 300 +0k [B\n11.4% 1151k ...
2008/12/21
[ "https://Stackoverflow.com/questions/385088", "https://Stackoverflow.com", "https://Stackoverflow.com/users/44721/" ]
385,095
<p>I have a samba network share on a FreeBSD box that I use for development.</p> <p>I have it set up as a shared drive on my WinXP box, and it works fine.</p> <p>However, if I reboot the xp box, the shared drive will not be accessible until I click on it and enter the password, even though I have set it to use the correct username and password and to connect at startup.</p> <p>Does anyone know offhand what might be the issue? I can get version data, etc. if necessary, but wanted to hang this out there briefly to see if it might be a common samba issue.</p> <p>Thanks!</p> <p>EDIT:</p> <p>So Sorry! I thought I had said I have XP Pro. I actually have the auth stored in the mapped drive, where it says "authenticate using user." I also use the same username for the samba share as the xp login, though not the same pw.</p>
[ { "answer_id": 386212, "author": "Grey Panther", "author_id": 1265, "author_profile": "https://Stackoverflow.com/users/1265", "pm_score": 2, "selected": false, "text": "NET USE \\\\computer\\share \"password\" /USER:user\n" }, { "answer_id": 386236, "author": "Alnitak", "...
2008/12/21
[ "https://Stackoverflow.com/questions/385095", "https://Stackoverflow.com", "https://Stackoverflow.com/users/27580/" ]
385,098
<p>I am trying to read CSS selectors in my stylesheets with the <code>document.styleSheets</code> array. It works fine with <code>&lt;link&gt;</code> and <code>&lt;style&gt;</code> tags, but when I use <code>@import</code> inside a <code>&lt;style&gt;</code> it doesn't show up in the array - only as a cssRule (style is "Undefined" in Safari 3 and FF 3).</p> <p>So: How can I parse the css in an @imported file? </p>
[ { "answer_id": 385104, "author": "Christoph", "author_id": 48015, "author_profile": "https://Stackoverflow.com/users/48015", "pm_score": 5, "selected": true, "text": "document.styleSheets[0].cssRules[0].styleSheet.cssRules;\n document.styleSheets[0].imports[0].rules;\n @import for..in" ...
2008/12/21
[ "https://Stackoverflow.com/questions/385098", "https://Stackoverflow.com", "https://Stackoverflow.com/users/27741/" ]
385,099
<p>I'm building an app that pulls data in from an excel .csv file and applying various levels of formatting, moving and mapping. Most everything is figured out except for one hitch with cleaning the data. Here is an example of the data from Excel:</p> <ol> <li>GREAT PERFORMANCES,GREAT PERFORMANCES,57744 ROUND LAKE RD,NEW YORK,NY</li> <li>"GUASTAVINO'S, INC",GUASTAVINO'S,8250 WESTHEIMER RD,NEW YORK,NY</li> <li>THE CLARKES GROUP LLC,HUGO'S FROG BAR,915 3RD AVE,CHICAGO,IL</li> <li>TRIOMPHE RESTAURANT CORP,"GEORGE'S,JEAN",1309 E PUTNAM AVE,NEW YORK,NY</li> </ol> <p>I can't do a straight explode() because of line 3's 2 and 4. There is a "string, string" on both of those lines and I have no control over the data exporting, just cleaning on import.</p> <p>I've tried a number of non-graceful options and it's killing the processing time. Can anyone think of an elegant solution?</p> <p>I can't use the MySQL IMPORT functionality, it has to be handled via PHP unfortunately.</p>
[ { "answer_id": 385113, "author": "Bill Karwin", "author_id": 20860, "author_profile": "https://Stackoverflow.com/users/20860", "pm_score": 3, "selected": false, "text": "LOAD DATA INFILE 'mydata.csv'\n FIELDS TERMINATED BY ','\n OPTIONALLY ENCLOSED BY '\"';\n" } ]
2008/12/21
[ "https://Stackoverflow.com/questions/385099", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42979/" ]
385,132
<p>In a system level programming language like C, C++ or D, what is the best type/encoding for storing latitude and longitude?</p> <p>The options I see are:</p> <ul> <li>IEEE-754 FP as degrees or radians</li> <li>degrees or radians stored as a fixed point value in an 32 or 64 bit int</li> <li>mapping of an integer range to the degree range: -> <code>deg = (360/2^32)*val</code></li> <li>degrees, minutes, seconds and fractional seconds stored as bit fields in an int</li> <li>a struct of some kind.</li> </ul> <p>The easy solution (FP) has the major down side that it has highly non uniform resolution (somewhere in England it can measure in microns, over in Japan, it can't). Also this has all the issues of FP comparison and whatnot. The other options require extra effort in different parts of the data's life cycle. (generation, presentation, calculations etc.)</p> <p>One interesting option is a floating precision type that where as the Latitude increase it gets more bits and the Longitude gets less (as they get closer together towards the poles).</p> <p>Related questions that don't quite cover this:</p> <ul> <li><a href="https://stackoverflow.com/questions/159255/">What is the ideal data type to use when storing latitude / longitudes in a MySQL</a></li> <li><a href="https://stackoverflow.com/questions/120283/">Working with latitude/longitude values in Java</a></li> </ul> <hr> <p>BTW: 32 bits gives you an E/W resolution at the equator of about 0.3 in. This is close to the scale that high grade GPS setups can work at (IIRC they can get down to about 0.5 in in some modes).</p> <p>OTOH if the 32 bits is uniformly distributed over the earth's surface, you can index squares of about 344m on a side, 5 Bytes give 21m, 6B->1.3m and 8B->5mm.</p> <p>I don't have a specific use in mind right now but have worked with this kind of thing before and expect to again, at some point.</p>
[ { "answer_id": 9059066, "author": "Pykler", "author_id": 742390, "author_profile": "https://Stackoverflow.com/users/742390", "pm_score": 4, "selected": false, "text": "0 decimal places, 1.0 = 111 km\n...\n7 decimal places, 0.0000001 = 1.11 cm\n8 decimal places, 0.00000001 = 1.11 mm\n" ...
2008/12/21
[ "https://Stackoverflow.com/questions/385132", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1343/" ]
385,141
<p>I have a WPF application that is using a custom style. In it I have a set of buttons that each have a custom background image. For each button, I'm supplying a normal and a mouse down image. Is there a simple way to do this with a single style (and customize each button on a case by case basis)? </p> <p>Currently I'm creating a new style for each button, and that can't be the best way to do this surely?</p>
[ { "answer_id": 385671, "author": "justin.m.chase", "author_id": 12958, "author_profile": "https://Stackoverflow.com/users/12958", "pm_score": 0, "selected": false, "text": "<Style x:Key=\"imageButton\" ControlType=\"{x:Type Button}\">\n ...\n</Style>\n\n<Button Style=\"{DynamicResourc...
2008/12/21
[ "https://Stackoverflow.com/questions/385141", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10086/" ]
385,150
<p>I have here a piece of PHP code that deletes a directory and all files in it if present. However, I'm not too sure about it, it looks to me like it'll delete all sub-maps too and then files in those and so on...</p> <p>I basically want to give and optional true/false parameter to select wheter or not to delete sub directories. Or would it be better practice to make 2 functions? The first to completely empty the folder and the seconds the delete both the folder and everything in it.</p> <p>Here's the code:</p> <pre><code>function delete_directory($dirname) { if (is_dir($dirname)) { $dir_handle = opendir($dirname); if (!$dir_handle) return false; while($file = readdir($dir_handle)) { if ($file != "." &amp;&amp; $file != "..") { if (!is_dir($dirname."/".$file)){ @unlink($dirname."/".$file); }else { delete_directory($dirname.'/'.$file); } } } closedir($dir_handle); } @rmdir($dirname) or die("Could not remove directory."); return true; } </code></pre> <p>And what I'm basically wondering is: what can go wrong here? Is there a situation where this piece of code can seriously screw up? I've been debugging it with Netbeans for a few hours now, and tried a lot of different scenarios. Now I'm kinda stuck and wondering if the guys at StackoverFlow can find a flaw in the code?</p>
[ { "answer_id": 385169, "author": "troelskn", "author_id": 18180, "author_profile": "https://Stackoverflow.com/users/18180", "pm_score": 4, "selected": true, "text": "realpath" }, { "answer_id": 385172, "author": "nickf", "author_id": 9021, "author_profile": "https://S...
2008/12/21
[ "https://Stackoverflow.com/questions/385150", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11795/" ]
385,193
<p>I previously <a href="https://stackoverflow.com/questions/322659/sendmail-and-mx-records-when-mail-server-is-not-on-web-host">asked a question regarding MX records</a> (and appreciate the thoughtful answers I received from SO'ers). Now that that problem is resolved, I want to step back and ask why there are MX records in the first place.</p> <p>Specifically: Why does SMTP get special treatment by DNS?</p> <p>We don't have HX records for HTTP or FX records for FTP. It seems like every other Internet protocol gets along just fine with DNS' A record. Indeed, the <a href="http://en.wikipedia.org/wiki/MX_record" rel="nofollow noreferrer">Wikipedia article on MX records</a> states that the current SMTP spec says that if an MX record does not exist for a receiver, the server should fall back on an A record. It also mentions some accommodations SMTP made in a pre-DNS world, but that was 25 years ago. Do we really need MX records any more?</p>
[ { "answer_id": 385280, "author": "Alnitak", "author_id": 6782, "author_profile": "https://Stackoverflow.com/users/6782", "pm_score": 6, "selected": true, "text": "MX user@domain SRV http://example.com/ www $ORIGIN example.com\n@ IN A 192.168.1.1\n IN MX mail.example.com\...
2008/12/21
[ "https://Stackoverflow.com/questions/385193", "https://Stackoverflow.com", "https://Stackoverflow.com/users/32168/" ]
385,195
<p>We've licensed a commercial product (product not important in this context), which is limited by the number of concurrent users. Users access this product by going through a Spring Controller.</p> <p>We have N licenses for this product, and if N+1 users access it, they get a nasty error message about needing to buy more licenses. I want to make sure users don't see this message, and would prefer that requests to the product simply "queue up", rather than having N+1 users actually access it. Of course, they would prefer that I purchase the licenses, so their tool won't let us do this natively.</p> <p>In lieu of being able to control the tool, I'd like to limit the number of concurrent sessions to the controller to never be more than N. Everyone else can wait.</p> <p>We're using Spring MVC.</p> <p>Any ideas?</p>
[ { "answer_id": 385689, "author": "TRF", "author_id": 48230, "author_profile": "https://Stackoverflow.com/users/48230", "pm_score": 4, "selected": true, "text": "public class CommercialObjectFactory extends BasePoolableObjectFactory { \n // for makeObject we'll simply return a new comm...
2008/12/21
[ "https://Stackoverflow.com/questions/385195", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48208/" ]
385,203
<p>I've read a few posts where people have stated (not suggested, not discussed, not offered) that PHP should not be used for large projects.</p> <p>Being a primarily PHP developer, I ask two questions:</p> <ol> <li>What defines a "large project"?</li> <li>Why not? What are the pitfalls of using PHP</li> </ol> <p>I run a small development team and I know from experience the quality construction, organization, documentation, commenting and encapsulation are our highest priority. We are able to develop great projects using our own framework and approach but still, I don't want to invest further if I'm wasting my time.</p> <p>Thoughts?</p>
[ { "answer_id": 385224, "author": "cletus", "author_id": 18393, "author_profile": "https://Stackoverflow.com/users/18393", "pm_score": 4, "selected": false, "text": "function get_users($surname) {\n mysql_query(\"select * from users where surname = '$surname'\");\n ...\n}\n mysql_escape...
2008/12/21
[ "https://Stackoverflow.com/questions/385203", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42979/" ]
385,219
<p>I have this code..</p> <pre><code> Models.Person p = new testmvc.Models.Person { Firstname = "yongeks", Lastname = "ucab" }; Models.Person p2 = new testmvc.Models.Person { Firstname = "lyn", Lastname = "torreon" }; string q = JavaScriptConvert.SerializeObject(new String[] { JavaScriptConvert.SerializeObject(p), JavaScriptConvert.SerializeObject(p2) }); Console.WriteLine(q); return q; </code></pre> <p>i need to parse this code into jquery.. using json request.. can somebody help me..</p>
[ { "answer_id": 385232, "author": "Mike Scott", "author_id": 43649, "author_profile": "https://Stackoverflow.com/users/43649", "pm_score": 3, "selected": false, "text": "Models.Person p2 = new testmvc.Models.Person { Firstname = \"lyn\", Lastname = \"torreon\" };\nreturn Json( p2 );\n" ...
2008/12/21
[ "https://Stackoverflow.com/questions/385219", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31445/" ]
385,237
<p>I know this is a simple question, I'm just curious.</p>
[ { "answer_id": 385232, "author": "Mike Scott", "author_id": 43649, "author_profile": "https://Stackoverflow.com/users/43649", "pm_score": 3, "selected": false, "text": "Models.Person p2 = new testmvc.Models.Person { Firstname = \"lyn\", Lastname = \"torreon\" };\nreturn Json( p2 );\n" ...
2008/12/22
[ "https://Stackoverflow.com/questions/385237", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2484/" ]
385,238
<blockquote> <p>Edit again: I think I get it now. All I need to do then is use the current class colon the class I want to be able to access? Person : Student, or person : teacher Is that correct?</p> </blockquote> <p>I'm currently trying to learn the ins and outs of object oriented programming. Currently I have a new object that's something like the following:</p> <pre><code>class student { int grade; //0 - 100 as opposed to the characters A, B, C, etc. string teacher; //For the teacher of the class the student is in. } class teacher { int courseAverage; string name; //teacher.name would correspond to the teacher in the student class. } class Program { student Jim; Jim = new student(); teacher John; John = new teacher(); } static void grades() { Jim.grade = 100; } static void teacher() { Jim.teacher = "John Smith"; } static void average() { int average; //For the sake of simplicity I'll leave the average at an int. average = (Jim.grade + Sue.grade + Sally.grade + Robert.grade) / 4; /*A loop would be set before the average variable to ensure that only students of John would be counted in this.*/ } static void teacheraverage() { John.courseAverage = average;//from the average method. } </code></pre> <blockquote> <p>EDIT:</p> <p>What I would like to do is modify the information from another class. However, I would like to modify the information from the Jim student in a method from within the program class. A method to compute the average of grades for the students who have the given teacher. </p> <p>Also, the only reason I use static in these is because that is the only way I have managed to access variables across methods. I tried using static methods to use the methods across classes with no success. Is there another way to do this?</p> </blockquote> <p>I would like to use the Jim student in multiple methods. One that will set Jim's grade, and another that will set the teacher. I would like to use different methods in this case so that I can learn how it is done. </p> <p>Okay, it looks like my understanding wasn't correct. I am going to try the methods within the class approach. </p>
[ { "answer_id": 385247, "author": "Lasse V. Karlsen", "author_id": 267, "author_profile": "https://Stackoverflow.com/users/267", "pm_score": 2, "selected": false, "text": "public class Student\n{\n int grade; //0 - 100 as opposed to the characters A, B, C, etc.\n string teacher; //F...
2008/12/22
[ "https://Stackoverflow.com/questions/385238", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48214/" ]
385,253
<p>I know this is supposed to output what kind of shell I'm using, which I think it does, because it outputs "bash-3.2", but it doesn't quite do that, because it actually changes my prompt to "bash-3.2$". What else is going on? When I do Ctrl+D, I go back to my original prompt. Is this starting the bash shell? I thought by opening a terminal window (I'm in Mac OS X), I was opening a shell program.</p> <p>I tried to Google, but I couldn't get any good results for $SHELL. As an aside, how do I get Google to include the "$" in my search?</p>
[ { "answer_id": 385263, "author": "Charlie Martin", "author_id": 35092, "author_profile": "https://Stackoverflow.com/users/35092", "pm_score": 2, "selected": false, "text": "$ $SHELL\n $ bash-3.2\n $ echo $SHELL\n $ FRED=\"My name is Fred\"\n $ echo $FRED\n $ echo FRED\nMy name is Fred.\n...
2008/12/22
[ "https://Stackoverflow.com/questions/385253", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2484/" ]
385,262
<p>I want to send a custom "Accept" header in my request when using urllib2.urlopen(..). How do I do that?</p>
[ { "answer_id": 385411, "author": "pantsgolem", "author_id": 9261, "author_profile": "https://Stackoverflow.com/users/9261", "pm_score": 8, "selected": true, "text": "Request Read() read() Request urlopen() import urllib2\nrequest = urllib2.Request(\"http://www.google.com\", headers={\"Ac...
2008/12/22
[ "https://Stackoverflow.com/questions/385262", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16432/" ]
385,269
<p>I have tried to use some of the widgets in <code>JQuery UI</code> on an <code>Asp.Net MVC</code> site without luck.</p> <p>For example the basic datepicker from <a href="http://ui.jquery.com/repository/tags/latest/demos/functional/#ui.datepicker" rel="nofollow noreferrer">jQuery UI - functional demos</a>.</p> <p>I have created a simple MVC project and added the script references in <code>Site.Master</code> like this:</p> <pre><code>&lt;script src="../../Scripts/jquery-1.2.6.min.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="../../Scripts/jquery-ui-personalized-1.5.3.min.js" type="text/javascript"&gt;&lt;/script&gt; &lt;link href="../../Content/Site.css" rel="stylesheet" type="text/css" /&gt; &lt;link href="../../Content/ui.datepicker.css" rel="stylesheet" type="text/css" /&gt;" </code></pre> <p>In the <code>Index.aspx</code> file I have cleared all default content and added the following:</p> <pre><code>&lt;script type="text/javascript"&gt; $("#basics").datepicker(); &lt;/script&gt; &lt;input type="text" size="10" value="click here" id="basics"/&gt; </code></pre> <p>The core jQuery works fine. Any clues?</p>
[ { "answer_id": 385283, "author": "Andy Hume", "author_id": 46460, "author_profile": "https://Stackoverflow.com/users/46460", "pm_score": 2, "selected": false, "text": "#basics id=\"basics\" script input $(document).ready(function() {\n $(\"#basics\").datepicker();\n});\n" }, { ...
2008/12/22
[ "https://Stackoverflow.com/questions/385269", "https://Stackoverflow.com", "https://Stackoverflow.com/users/459417/" ]
385,272
<p>I have a simple structured XML file like this:</p> <pre><code>&lt;ttest ID="ttest00001", NickName="map00001"/&gt; &lt;ttest ID="ttest00002", NickName="map00002"/&gt; &lt;ttest ID="ttest00003", NickName="map00003"/&gt; &lt;ttest ID="ttest00004", NickName="map00004"/&gt; </code></pre> <p>..... This xml file can be around 2.5MB.</p> <p>In my source code I will have a loop to get nicknames</p> <p>In each loop, I have something like this:</p> <pre><code>nickNameLoopNum = MyXmlDoc.SelectSingleNode("//ttest[@ID=' + testloopNum + "']").Attributes["NickName"].Value </code></pre> <p>This single line will cost me 30 to 40 millisecond. </p> <p>I searched some old articles (dated back to 2002) saying, use some sort of compiled "xpath" can help the situation, but that was 5 years ago. I wonder is there a mordern practice to make it faster? (I'm using .NET 3.5) </p>
[ { "answer_id": 385289, "author": "Eric Rosenberger", "author_id": 41624, "author_profile": "https://Stackoverflow.com/users/41624", "pm_score": 0, "selected": false, "text": "var nicknames = new Dictionary<string, string>();\n\nforeach (XmlNode node in MyXmlDoc.ChildNodes)\n{\n if (no...
2008/12/22
[ "https://Stackoverflow.com/questions/385272", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
385,292
<p>Ive install wamp server on my PC(it has no internet or intranet connection, Windows XP -OS). But when I access MYSQL this error popup. Can you give any idea on how can i resolve this error. thank you very much.</p> <p>Cant connect to MYSQL server on 'localhost' (10061)</p>
[ { "answer_id": 385460, "author": "Wouter van Nifterick", "author_id": 38813, "author_profile": "https://Stackoverflow.com/users/38813", "pm_score": 3, "selected": false, "text": "telnet localhost 3306\n sc query mysql\n SERVICE_NAME: mysql\n TYPE : 10 WIN32_OWN_PROC...
2008/12/22
[ "https://Stackoverflow.com/questions/385292", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
385,298
<p>I want to overload operators &lt; and > to allow the searching of an int value inside a BST (which ain't designed to store ints but rather words).</p> <p>For those who are wondering why is this overload being done on the first place please check <a href="https://stackoverflow.com/questions/384587/c-im-stuck-filling-this-bst-with-its-proper-values">C++ I&#39;m stuck filling this BST with its proper values</a> </p> <p>I need two search functions to be able to properly fill in the words of the dictionary and later define its synonyms/antonyms.</p> <p>This is the search function:</p> <pre><code>//--- Definition of findId() template &lt;typename DataType&gt; DataType&amp; BST&lt;DataType&gt;::findId(const int id ) const { typename BST&lt;DataType&gt;::BinNodePointer locptr = myRoot; typename BST&lt;DataType&gt;::BinNodePointer parent =0; bool found = false; while (!found &amp;&amp; locptr != 0) { if (locptr-&gt;data &gt; id) // descend left locptr = locptr-&gt;left; else if (locptr-&gt;data &lt; id) // descend right locptr = locptr-&gt;right; else // item found found = true; } return found ? locptr-&gt;data : NULL; } </code></pre> <p>And my attempt so far.. </p> <pre><code>template &lt;typename DataType&gt; bool BST&lt;DataType&gt;::operator &gt;(const int anotherId)const { typename BST&lt;DataType&gt;::BinNodePointer locptr; //undefined pointer, what should I make it point at? return (locptr-&gt;data &gt; anotherId); } </code></pre> <p>The whole template:</p> <pre><code>#include &lt;iostream&gt; #include &lt;iomanip&gt; #include &lt;stdlib.h&gt; #ifndef BINARY_SEARCH_TREE #define BINARY_SEARCH_TREE template &lt;typename DataType&gt; class BST { public: /***** Function Members *****/ BST(); bool empty() const; DataType&amp; findId (const int id)const; bool operator &gt;(const int anotherId)const; bool operator &lt; (const int anotherId)const; bool search(const DataType &amp; item) const; void insert(const DataType &amp; item); void remove(const DataType &amp; item); void inorder(std::ostream &amp; out) const; void graph(std::ostream &amp; out) const; private: /***** Node class *****/ class BinNode { public: DataType data; BinNode * left; BinNode * right; // BinNode constructors // Default -- data part is default DataType value; both links are null. BinNode() : left(0), right(0) {} // Explicit Value -- data part contains item; both links are null. BinNode(DataType item) : data(item), left(0), right(0) {} }; //end inner class typedef BinNode * BinNodePointer; /***** Private Function Members *****/ void search2(const DataType &amp; item, bool &amp; found, BinNodePointer &amp; locptr, BinNodePointer &amp; parent) const; /*------------------------------------------------------------------------ Locate a node containing item and its parent. Precondition: None. Postcondition: locptr points to node containing item or is null if not found, and parent points to its parent.#include &lt;iostream&gt; ------------------------------------------------------------------------*/ void inorderAux(std::ostream &amp; out, BST&lt;DataType&gt;::BinNodePointer subtreePtr) const; /*------------------------------------------------------------------------ Inorder traversal auxiliary function. Precondition: ostream out is open; subtreePtr points to a subtree of this BST. Postcondition: Subtree with root pointed to by subtreePtr has been output to out. ------------------------------------------------------------------------*/ void graphAux(std::ostream &amp; out, int indent, BST&lt;DataType&gt;::BinNodePointer subtreeRoot) const; /*------------------------------------------------------------------------ Graph auxiliary function. Precondition: ostream out is open; subtreePtr points to a subtree of this BST. Postcondition: Graphical representation of subtree with root pointed to by subtreePtr has been output to out, indented indent spaces. ------------------------------------------------------------------------*/ /***** Data Members *****/ BinNodePointer myRoot; }; // end of class template declaration //--- Definition of constructor template &lt;typename DataType&gt; inline BST&lt;DataType&gt;::BST() : myRoot(0) {} //--- Definition of empty() template &lt;typename DataType&gt; inline bool BST&lt;DataType&gt;::empty() const { return myRoot == 0; } //--- Definition of findId() template &lt;typename DataType&gt; DataType&amp; BST&lt;DataType&gt;::findId(const int id ) const { typename BST&lt;DataType&gt;::BinNodePointer locptr = myRoot; typename BST&lt;DataType&gt;::BinNodePointer parent =0; bool found = false; while (!found &amp;&amp; locptr != 0) { if (locptr-&gt;data &gt; id) // descend left locptr = locptr-&gt;left; else if (locptr-&gt;data &lt; id) // descend right locptr = locptr-&gt;right; else // item found found = true; } return found ? locptr-&gt;data : NULL; } template &lt;typename DataType&gt; bool BST&lt;DataType&gt;::operator &gt;(const int anotherId)const { typename BST&lt;DataType&gt;::BinNodePointer locptr; return (locptr-&gt;data &gt; anotherId); } template &lt;typename DataType&gt; bool BST&lt;DataType&gt;::operator &lt; (const int anotherId)const { typename BST&lt;DataType&gt;::BinNodePointer locptr; return (locptr-&gt;data &lt; anotherId); } //--- Definition of search() template &lt;typename DataType&gt; bool BST&lt;DataType&gt;::search(const DataType &amp; item) const { typename BST&lt;DataType&gt;::BinNodePointer locptr = myRoot; typename BST&lt;DataType&gt;::BinNodePointer parent =0; /* BST&lt;DataType&gt;::BinNodePointer locptr = myRoot; parent = 0; */ //falta el typename en la declaracion original bool found = false; while (!found &amp;&amp; locptr != 0) { if (item &lt; locptr-&gt;data) // descend left locptr = locptr-&gt;left; else if (locptr-&gt;data &lt; item) // descend right locptr = locptr-&gt;right; else // item found found = true; } return found; } //--- Definition of insert() template &lt;typename DataType&gt; inline void BST&lt;DataType&gt;::insert(const DataType &amp; item) { typename BST&lt;DataType&gt;::BinNodePointer locptr = myRoot, // search pointer parent = 0; // pointer to parent of current node bool found = false; // indicates if item already in BST while (!found &amp;&amp; locptr != 0) { parent = locptr; if (item &lt; locptr-&gt;data) // descend left locptr = locptr-&gt;left; else if (locptr-&gt;data &lt; item) // descend right locptr = locptr-&gt;right; else // item found found = true; } if (!found) { // construct node containing item locptr = new typename BST&lt;DataType&gt;::BinNode(item); if (parent == 0) // empty tree myRoot = locptr; else if (item &lt; parent-&gt;data ) // insert to left of parent parent-&gt;left = locptr; else // insert to right of parent parent-&gt;right = locptr; } else std::cout &lt;&lt; "Item already in the tree\n"; } //--- Definition of remove() template &lt;typename DataType&gt; void BST&lt;DataType&gt;::remove(const DataType &amp; item) { bool found; // signals if item is found typename BST&lt;DataType&gt;::BinNodePointer x, // points to node to be deleted parent; // " " parent of x and xSucc search2(item, found, x, parent); if (!found) { std::cout &lt;&lt; "Item not in the BST\n"; return; } //else if (x-&gt;left != 0 &amp;&amp; x-&gt;right != 0) { // node has 2 children // Find x's inorder successor and its parent typename BST&lt;DataType&gt;::BinNodePointer xSucc = x-&gt;right; parent = x; while (xSucc-&gt;left != 0) // descend left { parent = xSucc; xSucc = xSucc-&gt;left; } // Move contents of xSucc to x and change x // to point to successor, which will be removed. x-&gt;data = xSucc-&gt;data; x = xSucc; } // end if node has 2 children // Now proceed with case where node has 0 or 2 child typename BST&lt;DataType&gt;::BinNodePointer subtree = x-&gt;left; // pointer to a subtree of x if (subtree == 0) subtree = x-&gt;right; if (parent == 0) // root being removed myRoot = subtree; else if (parent-&gt;left == x) // left child of parent parent-&gt;left = subtree; else // right child of parent parent-&gt;right = subtree; delete x; } //--- Definition of inorder() template &lt;typename DataType&gt; inline void BST&lt;DataType&gt;::inorder(std::ostream &amp; out) const { inorderAux(out, myRoot); } //--- Definition of graph() template &lt;typename DataType&gt; inline void BST&lt;DataType&gt;::graph(std::ostream &amp; out) const { graphAux(out, 0, myRoot); } //--- Definition of search2() template &lt;typename DataType&gt; void BST&lt;DataType&gt;::search2(const DataType &amp; item, bool &amp; found, BST&lt;DataType&gt;::BinNodePointer &amp; locptr, BST&lt;DataType&gt;::BinNodePointer &amp; parent) const { locptr = myRoot; parent = 0; found = false; while (!found &amp;&amp; locptr != 0) { if (item &lt; locptr-&gt;data) // descend left { parent = locptr; locptr = locptr-&gt;left; } else if (locptr-&gt;data &lt; item) // descend right { parent = locptr; locptr = locptr-&gt;right; } else // item found found = true; } } //--- Definition of inorderAux() template &lt;typename DataType&gt; void BST&lt;DataType&gt;::inorderAux(std::ostream &amp; out, BST&lt;DataType&gt;::BinNodePointer subtreeRoot) const { if (subtreeRoot != 0) { inorderAux(out, subtreeRoot-&gt;left); // L operation out &lt;&lt; subtreeRoot-&gt;data &lt;&lt; " "; // V operation inorderAux(out, subtreeRoot-&gt;right); // R operation } } //--- Definition of graphAux() template &lt;typename DataType&gt; void BST&lt;DataType&gt;::graphAux(std::ostream &amp; out, int indent, BST&lt;DataType&gt;::BinNodePointer subtreeRoot) const { if (subtreeRoot != 0) { graphAux(out, indent + 8, subtreeRoot-&gt;right); out &lt;&lt; std::setw(indent) &lt;&lt; " " &lt;&lt; subtreeRoot-&gt;data &lt;&lt; std::endl; graphAux(out, indent + 8, subtreeRoot-&gt;left); } } #endif </code></pre>
[ { "answer_id": 385432, "author": "e.James", "author_id": 33686, "author_profile": "https://Stackoverflow.com/users/33686", "pm_score": 2, "selected": true, "text": "DataType DataType class DataType\n{\n private:\n mutable int internalID;\n // ...\n public:\n co...
2008/12/22
[ "https://Stackoverflow.com/questions/385298", "https://Stackoverflow.com", "https://Stackoverflow.com/users/45963/" ]
385,300
<p>I'm trying to create a route for the following urls: www.mysite.com/user/username www.mysite.com/user/username/pictures</p> <p>I tried doing that with the following code:</p> <pre><code>routes.MapRoute( "UserProfile", "user/{sn}/{action}", new { controller = "User", action = "Index", sn = "" } ); </code></pre> <p>So if an action is not specified, you go to the index action.</p> <p>However, it's not working and I'm not sure what I'm doing wrong. </p> <p>Thanks for any help. </p>
[ { "answer_id": 385432, "author": "e.James", "author_id": 33686, "author_profile": "https://Stackoverflow.com/users/33686", "pm_score": 2, "selected": true, "text": "DataType DataType class DataType\n{\n private:\n mutable int internalID;\n // ...\n public:\n co...
2008/12/22
[ "https://Stackoverflow.com/questions/385300", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23695/" ]
385,305
<p>For a game I am developing I need an algorithm that can calculate intersections. I have solved the problem, but the way I have done it is really nasty and I am hoping someone here might have a more elegant solution.</p> <p>A pair of points represent the end points of a line drawn between them. Given two pairs of points, do the drawn lines intersect, and if so, at what point? </p> <p>So for example call the lines (A.x, A.y)-(B.x, B.y) and (C.x, C.y)-(D.x, D.y)</p> <p>Can anyone think of a solution? A solution in any language will do.</p> <p><b>Edit:</b> A point I should have made clearer, the algorithm must return false if the point of intersection is beyond the lengths of the line segments.</p>
[ { "answer_id": 385319, "author": "Graviton", "author_id": 3834, "author_profile": "https://Stackoverflow.com/users/3834", "pm_score": 2, "selected": false, "text": "public struct PointD\n{\n public double X { get; set; }\n public double Y { get; set; }\n}\n\n/// <summary>\n/// Find...
2008/12/22
[ "https://Stackoverflow.com/questions/385305", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
385,306
<p>I've got a very strange bug cropping up in some PHP code I've got. The page is managing student enrolments in courses. On the page is a table of the student's courses, and each row has a number of dates: when they enrolled, when they completed, when they passed the assessment and when they picked up their certificate.</p> <p>The table data is generated by PHP (drawing the data from the DB), and Javascript actually renders the table. The output from PHP is JS code which looks something like this:</p> <pre><code>var e = new Enrolment(); e.contactId = 5801; e.enrolId = 14834; e.courseId = 3; e.dateEnrolled = new Date(1219672800000); e.dateCompleted = new Date(-1000); // magic value meaning they haven't completed. e.resultDate = new Date(1223647200000); e.certDate = new Date(1223560800000); e.result = 95; e.passed = true; enrolments[14834] = e; </code></pre> <p>In the database, all the date fields are stored as <code>DATE</code> (not <code>DATETIME</code>) fields.</p> <p>The bug is that the dates are being displayed as one day off. I would suspect that this has a lot to do with the server being in an area which has daylight saving, whereas here there isn't any (meaning the server time is one hour off). This explains a lot, especially how the data preparation and rendering is being done in two different timezones. That is: the server is saying to the client that the person completed at midnight on the 15th August, and the client is interpreting that as 11pm on the 14th and therefore displaying 14th August.</p> <p>But here's the confusing part: it's only doing that for the resultDate and certDate fields! I've copied the data to my local server and have found that the production server is actually sending a different timestamp (one which is off by 1 hour) just for those two fields, whereas the dateEnrolled field is the same.</p> <p>Here's the output using the exact same code and data from the database:</p> <pre><code>// local server (timezone GMT+1000) e.dateEnrolled = new Date(1219672800000); // 26 Aug 2008 00:00 +10:00 e.dateCompleted = new Date(-1000); e.resultDate = new Date(1223647200000); // 11 Oct 2008 00:00 +10:00 e.certDate = new Date(1223560800000); // 10 Oct 2008 00:00 +10:00 // production server (timezone GMT+1100) e.dateEnrolled = new Date(1219672800000); // 26 Aug 2008 00:00 +10:00 e.dateCompleted = new Date(-1000); e.resultDate = new Date(1223643600000); // 10 Oct 2008 23:00 +10:00 ** e.certDate = new Date(1223557200000); // 09 Oct 2008 23:00 +10:00 ** </code></pre> <p>I can understand if this was a problem with Daylight Saving not being accounted for, but notice how the dateEnrolled is the same?</p> <p>The PHP code which converts the MySQL date to a unix timestamp is this: </p> <pre><code>list ($year, $month, $day) = explode ('-', $mysqlDT); $timestamp = mktime (0,0,0, $month, $day, $year); </code></pre> <p>Any ideas about how to fix this?</p>
[ { "answer_id": 385453, "author": "OIS", "author_id": 36175, "author_profile": "https://Stackoverflow.com/users/36175", "pm_score": 3, "selected": true, "text": "e.resultDate = new Date(year, month - 1, day);\n" } ]
2008/12/22
[ "https://Stackoverflow.com/questions/385306", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9021/" ]
385,325
<p>I'm looking for a way to convert numbers to string format, dropping any redundant '.0' </p> <p>The input data is a mix of floats and strings. Desired output:</p> <p>0 --> '0'</p> <p>0.0 --> '0'</p> <p>0.1 --> '0.1'</p> <p>1.0 --> '1'</p> <p>I've come up with the following generator expression, but I wonder if there's a faster way:</p> <pre><code>(str(i).rstrip('.0') if i else '0' for i in lst) </code></pre> <p>The truth check is there to prevent 0 from becoming an empty string.</p> <p>EDIT: The more or less acceptable solution I have for now is this:</p> <pre><code>('%d'%i if i == int(i) else '%s'%i for i in lst) </code></pre> <p>It just seems strange that there is no elegant way to handle this (fairly straightforward) case in python.</p>
[ { "answer_id": 385360, "author": "Daniel Naab", "author_id": 32638, "author_profile": "https://Stackoverflow.com/users/32638", "pm_score": 2, "selected": false, "text": "from decimal import Decimal\n\ndef format_number(i):\n return '%g' % (Decimal(str(i)))\n" }, { "answer_id":...
2008/12/22
[ "https://Stackoverflow.com/questions/385325", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22893/" ]
385,327
<p>I recently started using vim 7 (previously vim 6) and the <code>smartindent</code> setting. For the most part, it works well, though I'm so used to typing a tab after an open brace that it is almost counter-productive.</p> <p>However, there is one piece of maniacal behaviour. When editing a shell script, I try to create a comment at the current indent level, but <code>smartindent</code> will have nothing to do with it. It insists that the comment must be at level 0 (no indent). What's worse, it breaks shift-right ('<code>&gt;&gt;</code>' and friends) so that they do not work. This is outright insubordination, and I'd like to know what's the best way to fix it?</p> <p>(I'm also not keen on <code>smartindent</code>'s ideas about indenting <code>then</code> after <code>if</code>.)</p> <p>Preferred solutions will save me manual bashing - I'm being lazy. One option would be 'turn off <code>smartindent</code> when editing shell scripts (leave it on for the rest)'. Another option would be guidelines on how to find the control script for <code>smartindent</code> and what to edit to change the characteristics I don't like. The final option (which I don't need advice on how to do - just the hint that it is the best, or only, way to restore sanity) is to leave <code>smartindent</code> unset.</p> <p>I saw the vaguely related question on "<a href="https://stackoverflow.com/questions/313359/annoying-vim-unindent-rules">(PHP and) annoying vim unindent rules</a>"; it doesn't provide me with the direct answer, though maybe the <code>cindent</code> and related items mentioned in there are in fact part of the answer.</p>
[ { "answer_id": 385694, "author": "Jonathan Leffler", "author_id": 15168, "author_profile": "https://Stackoverflow.com/users/15168", "pm_score": 2, "selected": false, "text": ":set cindent :set smartindent :set autoindent autoindent smartindent >i}\n>a}\n i a % :make %:r.o\n %:r .o somefi...
2008/12/22
[ "https://Stackoverflow.com/questions/385327", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15168/" ]
385,332
<p>I am writing a simple application that lets a user upload images. After the upload, the user can tag them or remove them.</p> <p>I figured out how to upload the files and save them once the files are uploaded. I am keeping tracking of a global path where images are kept. In the database I keep the meta data about the images like file name, tags, etc.</p> <p>I am using Java/JSP (specifically Stripes framework but my problem is generic).</p> <p>My question is where do I keep these image files once they are uploaded?</p> <p>Right now I have two web applications deployed on a Tomcat server. One main web application and other one is the where I upload the images.</p> <p>But this does not work as I can not see the uploaded images in the main application until I redeploy/restart Tomcat.</p> <p>It seems like Tomcat does not pick newly uploaded images automatically.</p> <p>Does anyone have any solutions?</p> <p>This is a simple project, so I do not want to store them in a database or use Apache for images. That is all just too complicated for this small project.</p> <p>Thanks.</p>
[ { "answer_id": 385500, "author": "TRF", "author_id": 48230, "author_profile": "https://Stackoverflow.com/users/48230", "pm_score": 0, "selected": false, "text": "import java.io.BufferedInputStream;\nimport java.io.BufferedOutputStream;\nimport java.io.File;\nimport java.io.FileInputStrea...
2008/12/22
[ "https://Stackoverflow.com/questions/385332", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48230/" ]
385,345
<p>How would you access the cache from a jQuery ajax call? </p> <p>I'm using jquery to do some data verification and quick data access. I have a static web-method that jquery is calling via json to return a value. I don't want to call to the database everytime so I'd like to cache the data I'm hitting, but I can't determine how to call the asp.net cache from within javascript, or a static method.</p> <p>I'd like to send the page object through to the static method, which would allow me to access page.cache, but don't know how. Barring that, maybe a way to access the cache from javascript itself?</p>
[ { "answer_id": 385383, "author": "Mark Brackett", "author_id": 2199, "author_profile": "https://Stackoverflow.com/users/2199", "pm_score": 6, "selected": true, "text": "System.Web.HttpContext.Current.Cache" } ]
2008/12/22
[ "https://Stackoverflow.com/questions/385345", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7870/" ]
385,361
<p>What are the different types of encapsulation?</p> <p>Am I right in thinking this basically refers to central OO concepts such as Abstraction, Polymorphism and Inheritance?</p> <p>My understanding of encapsulation is that it is a method of hiding data / functionality, but I never really considered Polymorphism or Inheritance a form of encapsulation, although I can see how polymorphism could be considered encapsulation as it can hide the exact type of the object you are interacting with.</p> <p>So, would you say that's about it, or am I missing some core concepts?</p> <p><em>edit</em> I just noticed in the comments someone mentioned it could refer to private / public methods, perhaps I'm thinking in to the question too much and expecting a more complicated answer than it really is?</p>
[ { "answer_id": 38035733, "author": "Abhijeet", "author_id": 452708, "author_profile": "https://Stackoverflow.com/users/452708", "pm_score": 0, "selected": false, "text": "class Person {\n String name;\n int age;\n\n void talk() {\n }\n\n void think() {\n }\n\n void w...
2008/12/22
[ "https://Stackoverflow.com/questions/385361", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40848/" ]
385,367
<p>Is there a standard for what actions <kbd>F5</kbd> and <kbd>Ctrl</kbd>+<kbd>F5</kbd> trigger in web browsers?</p> <p>I once did experiment in IE6 and Firefox 2.x. The <kbd>F5</kbd> refresh would trigger a HTTP request sent to the server with an <code>If-Modified-Since</code> header, while <kbd>Ctrl</kbd>+<kbd>F5</kbd> would not have such a header. In my understanding, <kbd>F5</kbd> will try to utilize cached content as much as possible, while <kbd>Ctrl</kbd>+<kbd>F5</kbd> is intended to abandon all cached content and just retrieve all content from the servers again.</p> <p>But today, I noticed that in some of the latest browsers (Chrome, IE8) it doesn't work in this way anymore. Both <kbd>F5</kbd> and <kbd>Ctrl</kbd>+<kbd>F5</kbd> send the <code>If-Modified-Since</code> header.</p> <p>So how is this supposed to work, or (if there is no standard) how do the major browsers differ in how they implement these refresh features?</p>
[ { "answer_id": 385491, "author": "some", "author_id": 36866, "author_profile": "https://Stackoverflow.com/users/36866", "pm_score": 9, "selected": false, "text": "Cache-Control: max-age=0 Cache-Control: no-cache Pragma: No-cache Pragma: No-cache ┌───────────┬──────────────┬─────┬────────...
2008/12/22
[ "https://Stackoverflow.com/questions/385367", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26349/" ]
385,370
<p>I have some code in MS VC++ 6.0 that I am debugging. For some reason, at this certain point where I am trying to delete some dynamically allocated memory, it breaks and I get a pop up message box saying "User Breakpoint called from code at blah blah".. then the Disassembly window pops up and I see</p> <pre><code>*memory address* int 3 </code></pre> <p>The odd thing is, there is NOWHERE in the code that I am calling an assembly instruction like this (I think asm int 3 is a hardware break command for x86?).. </p> <p>what could be causing this?</p> <p>EDIT: ANSWER: My code was "walking off the end" of an array, but only in the locations marked by Visual Studio debug with 0xFDFDFDFD, which is called a NoMan'sLand fence.. I think its also called an Off-by-one error.. This array was unrelated to the point where i was freeing the memory when the error was occuring. Which made it harder to spot.. :(</p>
[ { "answer_id": 385373, "author": "Michael Burr", "author_id": 12711, "author_profile": "https://Stackoverflow.com/users/12711", "pm_score": 4, "selected": true, "text": "_CrtIsValidHeapPointer() /*\n * If this ASSERT fails, a bad pointer has been passed in. It may be\n * tota...
2008/12/22
[ "https://Stackoverflow.com/questions/385370", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29482/" ]
385,394
<p>I have a small project I want to try porting to Python 3 - how do I go about this?</p> <p>I have made made the code run without warnings using <code>python2.6 -3</code> (mostly removing <code>.has_key()</code> calls), but I am not sure of the best way to use the 2to3 tool.</p> <blockquote> <p>Use the 2to3 tool to convert this source code to 3.0 syntax. Do not manually edit the output!</p> </blockquote> <p>Running <code>2to3 something.py</code> outputs a diff, which isn't useful on it's own. Using the <code>--write</code> flag overwrites something.py and creates a backup.. It seems like I have to do..</p> <pre><code>2to3 something.py python3.0 something.py mv something.py.bak something.py vim something.py # repeat </code></pre> <p>..which is a bit round-a-bout - ideally I could do something like..</p> <pre><code>mv something.py py2.6_something.py # once 2to3 py2.6_something.py --write-file something.py vim py2.6_something.py # repeat </code></pre>
[ { "answer_id": 385397, "author": "dbr", "author_id": 745, "author_profile": "https://Stackoverflow.com/users/745", "pm_score": 4, "selected": true, "text": "patch mv something.py py2.6_something.py\n2to3 py2.6_something.py | patch -o something.py\n" } ]
2008/12/22
[ "https://Stackoverflow.com/questions/385394", "https://Stackoverflow.com", "https://Stackoverflow.com/users/745/" ]
385,401
<p>What would you suggest as a replacement to the Maven Java build toolset? Just plain Ant scripts? SCons?</p>
[ { "answer_id": 385498, "author": "Limbic System", "author_id": 1274957, "author_profile": "https://Stackoverflow.com/users/1274957", "pm_score": 4, "selected": true, "text": "maven-ant-plugin src/main/java <import>" } ]
2008/12/22
[ "https://Stackoverflow.com/questions/385401", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18741/" ]
385,403
<p>I come from classes object orientation languages and recently I have been learning those fancy dynamic languages (JavaScript, Python and Lua) and I want some tips about how to use OO in those languages. It would be useful to know the pitfalls and the shortcomings of such approach and the advantages compared to traditional OO.</p> <p>The general notion that I got is that prototype based OO is basically programming with objects but no standard on how to use them whereas in normal OO there is a fixed predefined way to make and use objects.</p> <p>In summary, what is the good, the bad and the ugly parts of such approach?</p>
[ { "answer_id": 385467, "author": "Eugene Lazutkin", "author_id": 26394, "author_profile": "https://Stackoverflow.com/users/26394", "pm_score": 3, "selected": false, "text": "var foo = {\n property: 42,\n inc: function(){\n ++this.counter;\n },\n dec: function(){\n ...
2008/12/22
[ "https://Stackoverflow.com/questions/385403", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3485/" ]
385,408
<p>I want to execute something in a linux shell under a few different conditions, and be able to output the execution time of each execution.</p> <p>I know I could write a perl or python script that would do this, but is there a way I can do it in the shell? (which happens to be bash)</p>
[ { "answer_id": 385418, "author": "Robert Gamble", "author_id": 25222, "author_profile": "https://Stackoverflow.com/users/25222", "pm_score": 10, "selected": true, "text": "time $ time sleep 2\n" }, { "answer_id": 385422, "author": "grepsedawk", "author_id": 14388, "au...
2008/12/22
[ "https://Stackoverflow.com/questions/385408", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41613/" ]
385,420
<p>Does PHP have the ability to watch a variable (or object property) and run a function when its value changes, similar to <a href="https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Global_Objects/Object/Watch" rel="nofollow noreferrer">Gecko's Javascript <code>watch</code> function</a>?</p>
[ { "answer_id": 385450, "author": "ieure", "author_id": 45224, "author_profile": "https://Stackoverflow.com/users/45224", "pm_score": 1, "selected": false, "text": "public function __set($var, $val)\n{\n if ($var == 'interesting') {\n echo \"$var set to: \";\n var_dump($v...
2008/12/22
[ "https://Stackoverflow.com/questions/385420", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9021/" ]
385,441
<p>This is a sql newbie question.</p> <p>Basically, I want an extra column to return with my select statement to number the rows. I'm using mysql.</p> <p>Eg: </p> <pre><code>select * from friends David Steve Joe </code></pre> <p>What is the syntax to get:</p> <pre><code>1 David 2 Steve 3 Joe </code></pre>
[ { "answer_id": 385448, "author": "Eugene Yokota", "author_id": 3827, "author_profile": "https://Stackoverflow.com/users/3827", "pm_score": 0, "selected": false, "text": "CREATE TABLE #Foo (\n [FooId] [int] IDENTITY(1,1) NOT NULL,\n [Name] varchar(255)\n)\n\nSELECT *\nFROM F...
2008/12/22
[ "https://Stackoverflow.com/questions/385441", "https://Stackoverflow.com", "https://Stackoverflow.com/users/45066/" ]
385,451
<p>I have a WCF RESTFul service declared thus:</p> <pre><code>[ServiceContract] public interface IGasPriceService { [OperationContract] [WebGet (ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "/GetGasPrice/For/ZipCode/{zipCode}" )] GasPriceData GetPriceData(string zipCode); [OperationContract] [WebGet (RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "/GetGasPrice/For/City/{city}" )] GasPriceData GetPriceDataForCity(string city); [OperationContract] [WebInvoke (Method = "POST", RequestFormat = WebMessageFormat.Xml, UriTemplate = "/SetGasPrice/For/ZipCode/{zipCode}/Price/{price}" )] void SetPriceDataForZipCode(string zipCode, string price); } </code></pre> <p>The methods GetPriceData and GetPriceDataforCity work, but the SetPriceDataForZipCode does not work. Can any one let me know why this dows not work. </p> <p>When I issue a request like:</p> <p><a href="http://localhost:7002/SetGasPrice/For/ZipCode/45678/7.80" rel="nofollow noreferrer">http://localhost:7002/SetGasPrice/For/ZipCode/45678/7.80</a></p> <p>the message that I get is:</p> <pre><code>EndPoint Not Found </code></pre> <p>Any ideas how to fix this?</p> <hr> <p>I changed it to</p> <p><a href="http://localhost:7002/SetGasPrice/For/ZipCode/54568/5.788" rel="nofollow noreferrer">http://localhost:7002/SetGasPrice/For/ZipCode/54568/5.788</a></p> <p>and</p> <pre><code> [OperationContract] [WebInvoke (Method = "POST", RequestFormat = WebMessageFormat.Xml, UriTemplate = "/SetGasPrice/For/ZipCode/{zipCode}/{price}" )] void SetPriceDataForZipCode(string zipCode, string price); </code></pre> <p>That gives me the message:</p> <p>Method not allowed.</p> <p>Any ideas how to resolve this?</p>
[ { "answer_id": 385458, "author": "tvanfosson", "author_id": 12950, "author_profile": "https://Stackoverflow.com/users/12950", "pm_score": 3, "selected": false, "text": " http://localhost:7002/SetGasPrice/For/ZipCode/45678/Price/7.80\n \"/SetGasPrice/For/ZipCode/{zipCode}/{price}\"\n" }...
2008/12/22
[ "https://Stackoverflow.com/questions/385451", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
385,497
<p>My situation is as follow:</p> <ol> <li>I have an application that can be started only a fixed number of times (less than 50).</li> <li>A separate central process to manage other processes is not allowed due to business requirement. (ie. if a nice solution that involves ONLY the application processes is still acceptable)</li> <li>I am using C# for developing the application and therefore managed solution is preferred.</li> <li>I have to deal with "unexpected" cases such as the processes can be terminated by using TaskManager.</li> </ol> <p>I am thinking of solution that make use of system-wide mutex. However, it doesn't survive the "Unexpected" cases very well in the way that it leaves "abandoned" mutex. If this is a good way, may I ask what is the catch of "ignoring" the mutex abandoned?</p>
[ { "answer_id": 385662, "author": "gimel", "author_id": 6491, "author_profile": "https://Stackoverflow.com/users/6491", "pm_score": 0, "selected": false, "text": "using System;\nusing System.Collections.Generic;\nusing System.Collections.Specialized;\nusing System.Text;\nusing System.Mana...
2008/12/22
[ "https://Stackoverflow.com/questions/385497", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48254/" ]
385,506
<p>As Knuth said,</p> <blockquote> <p>We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil.</p> </blockquote> <p>This is something which often comes up in Stack Overflow answers to questions like "which is the most efficient loop mechanism", "SQL optimisation techniques?" (<a href="http://www.google.com/search?q=site%3Astackoverflow.com+%22premature+optimization%22" rel="noreferrer">and so on</a>). The standard answer to these optimisation-tips questions is to profile your code and see if it's a problem first, and if it's not, then therefore your new technique is unneeded.</p> <p>My question is, if a particular technique is different but not particularly obscure or obfuscated, can that really be considered a premature optimisation?</p> <p>Here's a related article by Randall Hyde called <em><a href="http://ubiquity.acm.org/article.cfm?id=1513451" rel="noreferrer">The Fallacy of Premature Optimization</a></em>.</p>
[ { "answer_id": 385529, "author": "Norman Ramsey", "author_id": 41661, "author_profile": "https://Stackoverflow.com/users/41661", "pm_score": 8, "selected": true, "text": "for (p = q; p < lim; p++)\n local table, io, string, math\n = table, io, string, math\n" }, { "answer_id":...
2008/12/22
[ "https://Stackoverflow.com/questions/385506", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9021/" ]
385,530
<p><code>AVFoundation.framework</code> is not where the documentation says it should be. I have iPhone SDK 2.2 installed (never had previous sdk versions installed) and I can't find that folder under <code>/System/Library/Frameworks</code></p> <p>I did find it under</p> <pre><code> /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.2.sdk/System/Library/Frameworks/ </code></pre> <p>folder but if I add it from that location, then the compiler can't find the header files. I tried copying the entire <code>AVFoundation.framework</code> folder to <code>/System/Library/Framework</code>, but it still can't find the header files.</p> <p>How can I use <code>AVFoundation</code> classes?</p> <p>Thanks, Alex</p>
[ { "answer_id": 385820, "author": "rustyshelf", "author_id": 6044, "author_profile": "https://Stackoverflow.com/users/6044", "pm_score": 5, "selected": true, "text": "#import <AVFoundation/AVAudioPlayer.h>\n" }, { "answer_id": 580736, "author": "user70242", "author_id": 70...
2008/12/22
[ "https://Stackoverflow.com/questions/385530", "https://Stackoverflow.com", "https://Stackoverflow.com/users/44091/" ]
385,531
<p>I have several functions that I wrote and I use regularly on my servers, is there a way I can add them to the core so I don't have to include them from external files?</p> <p>I am running PHP5</p>
[ { "answer_id": 385701, "author": "OIS", "author_id": 36175, "author_profile": "https://Stackoverflow.com/users/36175", "pm_score": 0, "selected": false, "text": "use My\\Functions\\Math as Math;\nMath::calcThis($i);\n" } ]
2008/12/22
[ "https://Stackoverflow.com/questions/385531", "https://Stackoverflow.com", "https://Stackoverflow.com/users/115/" ]
385,532
<p>Is there a way to set up a second persistence.xml file in a Maven project such that it is used for testing instead of the normal one that is used for deployment?</p> <p>I tried putting a persistence.xml into src/test/resources/META-INF, which gets copied into target/test-classes/META-INF, but it seems target/classes/META-INF (the copy from the src/main/resources) gets preferred, despite <code>mvn -X test</code> listing the classpath entries in the right order:</p> <pre><code>[DEBUG] Test Classpath : [DEBUG] /home/uqpbecke/dev/NetBeansProjects/UserManager/target/test-classes [DEBUG] /home/uqpbecke/dev/NetBeansProjects/UserManager/target/classes [DEBUG] /home/uqpbecke/.m2/repository/junit/junit/4.5/junit-4.5.jar ... </code></pre> <p>I would like to be able to run tests against a simple hsqldb configuration without having to change the deployment version of the JPA configuration, ideally straight after project checkout without any need for local tweaking.</p>
[ { "answer_id": 1158769, "author": "macbutch", "author_id": 141923, "author_profile": "https://Stackoverflow.com/users/141923", "pm_score": 1, "selected": false, "text": "final Thread currentThread = Thread.currentThread();\nfinal ClassLoader saveClassLoader = currentThread.getContextClas...
2008/12/22
[ "https://Stackoverflow.com/questions/385532", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19820/" ]
385,539
<p>Mostly for my amusement, I created a <code>makefile</code> in my <code>$HOME/bin</code> directory called <code>rebuild.mk</code>, and made it executable, and the first lines of the file read:</p> <pre><code>#!/bin/make -f # # Comments on what the makefile is for ... all: ${SCRIPTS} ${LINKS} ... ... </code></pre> <p>I can now type:</p> <pre><code>rebuild.mk </code></pre> <p>and this causes <code>make</code> to execute.</p> <p>What are the reasons for not exploiting this on a permanent basis, other than this:</p> <ul> <li>The makefile is tied to a single directory, so it really isn't appropriate in my main <code>bin</code> directory.</li> </ul> <p>Has anyone ever seen the trick exploited before?</p> <hr> <p>Collecting some comments, and providing a bit more background information.</p> <ol> <li>Norman Ramsey reports that this technique is used in Debian; that is interesting to know. Thank you.</li> <li>I agree that typing 'make' is more idiomatic.</li> <li>However, the scenario (previously unstated) is that my $HOME/bin directory already has a cross-platform main makefile in it that is the primary maintenance tool for the 500+ commands in the directory.</li> <li>However, on one particular machine (only), I wanted to add a makefile for building a special set of tools. So, those tools get a special makefile, which I called <code>rebuild.mk</code> for this question (it has another name on my machine).</li> <li>I do get to save typing '<code>make -f rebuild.mk</code>' by using '<code>rebuild.mk</code>' instead.</li> <li>Fixing the position of the <code>make</code> utility is problematic across platforms.</li> <li>The <code>#!/usr/bin/env make -f</code> technique is likely to work, though I believe the official rules of engagement are that the line must be less than 32 characters and may only have one argument to the command.</li> <li>@dF comments that the technique might prevent you passing arguments to make. That is not a problem on my Solaris machine, at any rate. The three different versions of 'make' I tested (Sun, GNU, mine) all got the extra command line arguments that I type, including options ('-u' on my home-brew version) and targets 'someprogram' and macros CC='cc' WFLAGS=-v (to use a different compiler and cancel the GCC warning flags which the Sun compiler does not understand).</li> </ol> <h3>I would not advocate this as a general technique.</h3> <p>As stated, it was mostly for my amusement. I may keep it for this particular job; it is most unlikely that I'd use it in distributed work. And if I did, I'd supply and apply a '<code>fixin</code>' script to fix the pathname of the interpreter; indeed, I did that already on my machine. That script is a relic from the first edition of the Camel book ('Programming Perl' by Larry Wall).</p>
[ { "answer_id": 385548, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 4, "selected": true, "text": "make gmake" }, { "answer_id": 385557, "author": "dF.", "author_id": 3002, "author_profile": "https://S...
2008/12/22
[ "https://Stackoverflow.com/questions/385539", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15168/" ]
385,551
<p>This is a purely theoretical question.</p> <p>Given three simple classes:</p> <pre><code>class Base { } class Sub extends Base { } class SubSub extends Sub { } </code></pre> <p>And a function meant to operate on these classes:</p> <pre><code>public static void doSomething(Base b) { System.out.println("BASE CALLED"); } public static void doSomething(Sub b) { System.out.println("SUB CALLED"); } </code></pre> <p>It seems that the followign code:</p> <pre><code>SubSub ss = new SubSub(); doSomething(ss); </code></pre> <p>could legitimately result in printing either BASE CALLED, or SUB CALLED, since SubSub can be casted to both of those. In fact, removing the Sub version of the function causes BASE CALLED to be printed. What actually happens is that "SUB CALLED" is printed. This seems to mean that which function is called doesn't depend on the order the functions are defined in, as the Base version was called first. </p> <p>Does Java just look at all the different versions of the function and pick the one which requires the smallest traversal up the inheritance stack? Is this standardized? Is it written out in any documentation?</p>
[ { "answer_id": 385615, "author": "Peter Becker", "author_id": 19820, "author_profile": "https://Stackoverflow.com/users/19820", "pm_score": 4, "selected": true, "text": "method(Base, Sub) method(Sub, Base) method(Sub, Sub) ss" } ]
2008/12/22
[ "https://Stackoverflow.com/questions/385551", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15055/" ]
385,556
<p>Say I have three classes:</p> <pre><code>class X{}; class Y{}; class Both : public X, public Y {}; </code></pre> <p>I mean to say I have two classes, and then a third class which extends both (multiple-inheritance).</p> <p>Now say I have a function defined in another class:</p> <pre><code>void doIt(X *arg) { } void doIt(Y *arg) { } </code></pre> <p>and I call this function with an instance of both:</p> <pre><code>doIt(new Both()); </code></pre> <p>This causes a compile-time error, stating that the function call is ambiguous. </p> <p>What are the cases, besides this one, where the C++ compiler decides the call is ambiguous and throws an error, if any? How does the compiler determine what these cases are?</p>
[ { "answer_id": 385565, "author": "Paige Ruten", "author_id": 813, "author_profile": "https://Stackoverflow.com/users/813", "pm_score": 3, "selected": false, "text": "jeremy@jeremy-desktop:~/Desktop$ g++ -o test test.cpp\ntest.cpp: In function ‘int main(int, char**)’:\ntest.cpp:18: error:...
2008/12/22
[ "https://Stackoverflow.com/questions/385556", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15055/" ]
385,558
<p>How do I extract a double value from a string using regex.</p> <pre><code>import re pattr = re.compile(???) x = pattr.match("4.5") </code></pre>
[ { "answer_id": 385597, "author": "jfs", "author_id": 4279, "author_profile": "https://Stackoverflow.com/users/4279", "pm_score": 6, "selected": false, "text": "perldoc perlretut import re\nre_float = re.compile(\"\"\"(?x)\n ^\n [+-]?\\ * # first, match an optional sign *and s...
2008/12/22
[ "https://Stackoverflow.com/questions/385558", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10522/" ]
385,572
<p>I need to convert strings in Python to other types such as unsigned and signed 8, 16, 32, and 64 bit ints, doubles, floats, and strings.</p> <p>How can I do this?</p>
[ { "answer_id": 385580, "author": "Paige Ruten", "author_id": 813, "author_profile": "https://Stackoverflow.com/users/813", "pm_score": 2, "selected": false, "text": "int int int() >>> str = '123'\n>>> num = int(str)\n>>> num\n123\n float()" }, { "answer_id": 385583, "author":...
2008/12/22
[ "https://Stackoverflow.com/questions/385572", "https://Stackoverflow.com", "https://Stackoverflow.com/users/46646/" ]
385,605
<p>If a form in Access DB is set as hidden. Then how to unhide it? so that we can manipulate the form programmentically using vb.net.</p> <p>Thank you.</p>
[ { "answer_id": 385929, "author": "Fionnuala", "author_id": 2548, "author_profile": "https://Stackoverflow.com/users/2548", "pm_score": 1, "selected": false, "text": "Sub FormHidden()\nDim frm\n\n For Each frm In CurrentProject.AllForms\n SetHiddenAttribute acForm, frm.Name, Fal...
2008/12/22
[ "https://Stackoverflow.com/questions/385605", "https://Stackoverflow.com", "https://Stackoverflow.com/users/45255/" ]
385,614
<p>We have a data entry portlet that occassionally generates urls in excess of the 2k limit enforced by Internet Explorer. </p> <p>Is there any way to stop these excessively long urls from being generated without loss of functionality?</p>
[ { "answer_id": 385929, "author": "Fionnuala", "author_id": 2548, "author_profile": "https://Stackoverflow.com/users/2548", "pm_score": 1, "selected": false, "text": "Sub FormHidden()\nDim frm\n\n For Each frm In CurrentProject.AllForms\n SetHiddenAttribute acForm, frm.Name, Fal...
2008/12/22
[ "https://Stackoverflow.com/questions/385614", "https://Stackoverflow.com", "https://Stackoverflow.com/users/33889/" ]
385,620
<p>I'm programming in PHP and would like to create web pages which have email addresses that are easily read by humans but not easily harvested by spammers. The email addresses are coming from user input, and I think I can identify an address by using a regular expression, but I'm not clear exactly how I should replace the email addresses or with what, in order to keep most automated spam bots from harvesting them.</p> <p>Here's one idea: (pseudo code)</p> <pre><code>(email)@(domain.com) $1&lt;span class="remove"&gt;DELETE&lt;/span&gt;$2 .remove { display: none; } </code></pre> <p>Hopefully the bot will trip up on the span tag.</p> <p>Finally, I'm looking for a solution that will not disturb email addresses that are inside of <code>mailto:</code> tags.</p> <p><strong>Duplicate of</strong> <a href="https://stackoverflow.com/questions/311555/how-can-i-prevent-prevent-bots-from-collecting-e-mail-addresses#311629" title="How can I prevent prevent bots from collecting e-mail addresses?">How can I prevent prevent bots from collecting e-mail addresses?</a> which is duplicate of <a href="https://stackoverflow.com/questions/308772/what-are-some-ways-to-protect-emails-on-websites-from-spambots#309147" title="What are some ways to protect emails on websites from spambots?">What are some ways to protect emails on websites from spambots?</a> and maybe some others...</p>
[ { "answer_id": 385663, "author": "M.N", "author_id": 18615, "author_profile": "https://Stackoverflow.com/users/18615", "pm_score": 3, "selected": false, "text": "<?php\n header(\"Content-type: image/png\");\n $im = @imagecreate(110, 20)or die(\"Cannot Initialize new GD image stream\");...
2008/12/22
[ "https://Stackoverflow.com/questions/385620", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31671/" ]
385,629
<p>I am rendering an OpenGL scene that include some bitmap text. It is my understanding the order I draw things in will determine which items are on top.</p> <p>However, my bitmap text, even though I draw it last, is not on top!</p> <p>For instance, I am drawing:</p> <p>1) Background<br> 2) Buttons<br> 3) Text</p> <p>All at the same z depth. Buttons are above the background, but text is invisible. It I change the z depth of the text, I can see it, but I then have other problems.</p> <p>I am using the bitmap text method from Nehe's Tutorials.</p> <p>How can I make the text visible without changing the z depth?</p>
[ { "answer_id": 385643, "author": "Nils Pipenbrinck", "author_id": 15955, "author_profile": "https://Stackoverflow.com/users/15955", "pm_score": 4, "selected": true, "text": " glDisable (GL_DEPTH_TEST); // or something related..\n" } ]
2008/12/22
[ "https://Stackoverflow.com/questions/385629", "https://Stackoverflow.com", "https://Stackoverflow.com/users/407725/" ]
385,632
<p>I'm working a piece of code to turn phone numbers into links for mobile phone - I've got it but it feels really dirty.</p> <pre><code>import re from string import digits PHONE_RE = re.compile('([(]{0,1}[2-9]\d{2}[)]{0,1}[-_. ]{0,1}[2-9]\d{2}[-_. ]{0,1}\d{4})') def numbers2links(s): result = "" last_match_index = 0 for match in PHONE_RE.finditer(s): raw_number = match.group() number = ''.join(d for d in raw_number if d in digits) call = '&lt;a href="tel:%s"&gt;%s&lt;/a&gt;' % (number, raw_number) result += s[last_match_index:match.start()] + call last_match_index = match.end() result += s[last_match_index:] return result &gt;&gt;&gt; numbers2links("Ghost Busters at (555) 423-2368! How about this one: 555 456 7890! 555-456-7893 is where its at.") 'Ghost Busters at &lt;a href="tel:5554232368"&gt;(555) 423-2368&lt;/a&gt;! How about this one: &lt;a href="tel:5554567890"&gt;555 456 7890&lt;/a&gt;! &lt;a href="tel:5554567893"&gt;555-456-7893&lt;/a&gt; is where its at.' </code></pre> <p>Is there anyway I could restructure the regex or the the regex method I'm using to make this cleaner?</p> <p><strong>Update</strong></p> <p>To clarify, my question is not about the correctness of my regex - I realize that it's limited. Instead I'm wondering if anyone had any comments on the method of substiting in links for the phone numbers - is there anyway I could use <code>re.replace</code> or something like that instead of the string hackery that I have?</p>
[ { "answer_id": 385869, "author": "Tomalak", "author_id": 18771, "author_profile": "https://Stackoverflow.com/users/18771", "pm_score": 1, "selected": false, "text": "((00|\\+)?1)? [2-9][0-8][0-9] \\(?[2-9](00|[2-9]{2})\\)? (?!0{4})\\d{4} ([x#-]\\d+)? [. -]? ((00|\\+)?1[. -]?)?\\(?[2-9][0...
2008/12/22
[ "https://Stackoverflow.com/questions/385632", "https://Stackoverflow.com", "https://Stackoverflow.com/users/37522/" ]
385,656
<p>We have a table, name <em>'employeeReg'</em> with fields</p> <pre><code>employeeNo | employeeName | Registered_on </code></pre> <p>Here <em>Registered_on</em> is a timestamp.</p> <p>We require an hourly pattern of registrations, over a period of days. eg.</p> <blockquote> <p>01 Jan 08 : 12 - 01 PM : 1592 registrations</p> <p>01 Jan 08 : 01 - 02 PM : 1020 registrations</p> </blockquote> <p>Can someone please suggest a query for this.</p> <hr> <p>We are using Oracle 10gR2 as our DB server.</p>
[ { "answer_id": 385669, "author": "Jonathan Leffler", "author_id": 15168, "author_profile": "https://Stackoverflow.com/users/15168", "pm_score": 3, "selected": true, "text": "TO_CHAR() SELECT TO_CHAR(Registered_on, \"YYYY-MM-DD HH24\") AS TimeSlot,\n COUNT(*) AS Registrations\n F...
2008/12/22
[ "https://Stackoverflow.com/questions/385656", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18615/" ]
385,658
<p>I have a page, where I want to dynamically add asp.net user controls. The scenario is that we want that on specific event of a control, It disposes itself and loads another control in the page.</p> <p>I am not able to have solution about how to do this?</p> <p>Anyone have decent idea?</p>
[ { "answer_id": 385669, "author": "Jonathan Leffler", "author_id": 15168, "author_profile": "https://Stackoverflow.com/users/15168", "pm_score": 3, "selected": true, "text": "TO_CHAR() SELECT TO_CHAR(Registered_on, \"YYYY-MM-DD HH24\") AS TimeSlot,\n COUNT(*) AS Registrations\n F...
2008/12/22
[ "https://Stackoverflow.com/questions/385658", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
385,661
<p>Notepad++ has a convenient feature: if you select a word in your text (not necessarily a keyword), the word is highlighted throughout the text. Can this be done in Emacs as well? And if so, how? </p> <p>It doesn't necessarily have to work exactly like Notepad++ (i.e., via selection); ideally, I would like to set up a key binding that causes all occurrences of the word under cursor to be highlighted.</p> <p>It would be great if the highlights were permanent, i.e., moving point away from a highlighted word should <em>not</em> cause the highlight to be removed.</p> <p>Also, it would be useful if there was a solution that made it possible to navigate between highlights (using custom key bindings).</p>
[ { "answer_id": 385673, "author": "dancavallaro", "author_id": 42891, "author_profile": "https://Stackoverflow.com/users/42891", "pm_score": 3, "selected": false, "text": "(global-hi-lock-mode 1)\n .emacs C-x w h REGEX <RET> <RET> REGEX C-x w r REGEX <RET>" }, { "answer_id": 38581...
2008/12/22
[ "https://Stackoverflow.com/questions/385661", "https://Stackoverflow.com", "https://Stackoverflow.com/users/45269/" ]
385,681
<p>I am developing a web app. which will generate a random link pointing to an image on my server. something like -<a href="http://dummy.com/Images/Image1.jpg?id=19234" rel="nofollow noreferrer">http://dummy.com/Images/Image1.jpg?id=19234</a></p> <p>Here this link can then be used by anybody on their site, now I just want to know how many sites are using my links, without anybody clicking on those links.</p> <p>Can It be done using HTTPModule ?? </p>
[ { "answer_id": 385686, "author": "Oddthinking", "author_id": 8014, "author_profile": "https://Stackoverflow.com/users/8014", "pm_score": 2, "selected": false, "text": "link:http://dummy.com/Images/Image1.jpg?id=19234\n" }, { "answer_id": 385948, "author": "Zhaph - Ben Duguid"...
2008/12/22
[ "https://Stackoverflow.com/questions/385681", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
385,688
<h1>Background</h1> <p>In a C# command-line app I'm writing, several of the parameters have "yes" and "no" as the possible values.</p> <p>I am storing their input using the Enum type shown below.</p> <pre><code>enum YesNo { Yes, No } </code></pre> <p>Which is fine - the code works. No problem there. </p> <p>NOTE: Yes, I could store these as bool (that's how it used to work). My design choice is to be explicit about the Yes/No choice made by the user because they will see this printed in other contexts and I'd like it to be more obvious what the choice was. </p> <h1>My Question</h1> <ul> <li>It just seems odd to have an enum called "YesNo" - what are some suggestions for better names for an enum for "yes" and "no" values.</li> </ul> <h1>So Finally</h1> <p>I asked this question relatively early in StackOverflow's life. It wasn't fake question - I really did have this situation. I just thought it would be nice to use it see what the community would do. Because it is, I admit a somewhat odd question. </p> <p>First, thanks to all who spent the time replying. I'm trying to pay that back with a thoughtful conclusion.</p> <p>Comments on the answers</p> <p><strong>switching to bool</strong>. I understand your motivation, but I feel I need to point out that having a <strong>binary</strong> choice (and by that I mean a choice between any two values - alive/dead, married/unmarried, etc.) is not the same as <strong>boolean</strong> choice between true and false. We find as programmers switching between yes/no and true/false easy - fair enough. Had my choice in this case been for example "Democrat" or "Replication"" (contrived example, I know) then you can see possibilities for confusion or at least awkwardness. I do think the bool option is valid in this case, but less so in other binary choices. </p> <p><strong>localization</strong> - great point. In my specific case it didn't matter - this was not and is never going to be localized, but for other situations it is something to consider.</p> <p><strong>more than three options</strong> - In fact, later on I had to add a third value called to represent the valid (in my application) condition of a user specifically <em>not</em> making the choice.</p> <p>There were a lot of good comments, thank you all! </p>
[ { "answer_id": 385751, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 2, "selected": false, "text": "public enum UserWtf\n{\n No,\n Yes,\n FileNotFound\n}\n" }, { "answer_id": 385934, "author": "Danie...
2008/12/22
[ "https://Stackoverflow.com/questions/385688", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13477/" ]
385,707
<p>How can I tell unix "find" to include in it's recursive search a folder which is softlinked? </p>
[ { "answer_id": 385779, "author": "Jonathan Leffler", "author_id": 15168, "author_profile": "https://Stackoverflow.com/users/15168", "pm_score": 0, "selected": false, "text": "-L -H -follow -L -L" } ]
2008/12/22
[ "https://Stackoverflow.com/questions/385707", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4038/" ]
385,709
<p>When an application is launched, I need to know for certain methods when they are fired. How to do this using attributes and AOP techniques?</p> <p>The simplest way is to record the time in the event method such as this:</p> <pre><code>private void Page_load() { DateTime dt = DateTime.Now; } </code></pre> <p>And save the Datetime into a database. But this is definitely not desirable as doing this will leave the method will a lot of cross cutting functions, making the maintenance job harder. I am thinking about using attributes to solve this problem. PostSharp seems to be a good candidates here as it can intercept method calls and do whatever pre and post processing you want. But one thing that is clearly lacking is that it can't handle events without me writing a lot of custom code.</p> <p>Is there any framework that can handle events naturally?</p>
[ { "answer_id": 385747, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 1, "selected": false, "text": "public static void LogEventRaised(string event)\n{\n ...\n}\n Load += delegate { LogEventRaised(\"Load\") };\n" } ]
2008/12/22
[ "https://Stackoverflow.com/questions/385709", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3834/" ]