qid
int64
4
19.1M
question
stringlengths
18
48.3k
answers
list
date
stringlengths
10
10
metadata
list
132,358
<p>In order to improve performance reading from a file, I'm trying to read the entire content of a big (several MB) file into memory and then use a istringstream to access the information.</p> <p>My question is, which is the best way to read this information and "import it" into the string stream? A problem with this approach (see bellow) is that when creating the string stream the buffers gets copied, and memory usage doubles.</p> <pre><code>#include &lt;fstream&gt; #include &lt;sstream&gt; using namespace std; int main() { ifstream is; is.open (sFilename.c_str(), ios::binary ); // get length of file: is.seekg (0, std::ios::end); long length = is.tellg(); is.seekg (0, std::ios::beg); // allocate memory: char *buffer = new char [length]; // read data as a block: is.read (buffer,length); // create string stream of memory contents // NOTE: this ends up copying the buffer!!! istringstream iss( string( buffer ) ); // delete temporary buffer delete [] buffer; // close filestream is.close(); /* ================================== * Use iss to access data */ } </code></pre>
[ { "answer_id": 132394, "author": "Luc Touraille", "author_id": 20984, "author_profile": "https://Stackoverflow.com/users/20984", "pm_score": 7, "selected": true, "text": "std::ifstream rdbuf() filebuf filebuf stringstream #include <fstream>\n#include <sstream>\n\nint main()\n{\n std::ifstream file( \"myFile\" );\n\n if ( file )\n {\n std::stringstream buffer;\n\n buffer << file.rdbuf();\n\n file.close();\n\n // operations on the buffer...\n }\n}\n stringstream operator<< ifstream read stringstream" }, { "answer_id": 138645, "author": "Martin York", "author_id": 14065, "author_profile": "https://Stackoverflow.com/users/14065", "pm_score": 5, "selected": false, "text": "#include <fstream>\n#include <sstream>\n#include <vector>\n\nint main()\n{\n std::ifstream file(\"Plop\");\n if (file)\n {\n /*\n * Get the size of the file\n */\n file.seekg(0,std::ios::end);\n std::streampos length = file.tellg();\n file.seekg(0,std::ios::beg);\n\n /*\n * Use a vector as the buffer.\n * It is exception safe and will be tidied up correctly.\n * This constructor creates a buffer of the correct length.\n *\n * Then read the whole file into the buffer.\n */\n std::vector<char> buffer(length);\n file.read(&buffer[0],length);\n\n /*\n * Create your string stream.\n * Get the stringbuffer from the stream and set the vector as it source.\n */\n std::stringstream localStream;\n localStream.rdbuf()->pubsetbuf(&buffer[0],length);\n\n /*\n * Note the buffer is NOT copied, if it goes out of scope\n * the stream will be reading from released memory.\n */\n }\n}\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132358", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20317/" ]
132,367
<p>How would I invert .NET regex matches? I want to extract only the matched text, e.g. I want to extract all IMG tags from an HTML file, but only the image tags.</p>
[ { "answer_id": 133480, "author": "ZeroBugBounce", "author_id": 11314, "author_profile": "https://Stackoverflow.com/users/11314", "pm_score": 1, "selected": false, "text": "static void Main(string[] args)\n{\n Regex re = new Regex(@\"\\sthe\\s\", RegexOptions.IgnoreCase);\n\n string text = \"this is the text that the regex will use to process the answer\";\n\n MatchCollection matches = re.Matches(text);\n foreach(Match m in matches)\n {\n Console.Write(m);\n Console.Write(\"\\t\");\n }\n\n Console.WriteLine();\n\n string[] split = re.Split(text);\n foreach (string s in split)\n {\n Console.Write(s);\n Console.Write(\"\\t\");\n }\n}\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132367", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8741/" ]
132,397
<p>When I do an "os.execute" in Lua, a console quickly pops up, executes the command, then closes down. But is there some way of getting back the console output only using the standard Lua libraries?</p>
[ { "answer_id": 132453, "author": "paxdiablo", "author_id": 14860, "author_profile": "https://Stackoverflow.com/users/14860", "pm_score": 1, "selected": false, "text": "comd >comd.txt 2>&1\n" }, { "answer_id": 326715, "author": "Norman Ramsey", "author_id": 41661, "author_profile": "https://Stackoverflow.com/users/41661", "pm_score": 6, "selected": false, "text": "gsub $(...)" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132397", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12291/" ]
132,409
<p>I have a web application that uses <a href="https://javaee.github.io/jaxb-v2/" rel="nofollow noreferrer">JAXB 2</a>. When deployed on an <a href="https://www.oracle.com/technetwork/middleware/ias/overview/index.html" rel="nofollow noreferrer">Oracle 10g Application Server</a>, I get errors as soon as I try to marshal an XML file. It turns out that Oracle includes <a href="https://github.com/javaee/jaxb-v1" rel="nofollow noreferrer">JAXB 1</a> in a jar sneakily renamed "xml.jar". </p> <p>How I can force my webapp to use the version of the jaxb jars that I deployed in <code>WEB-INF/lib</code> over that which Oracle has forced into the classpath, ideally through configuration rather than having to mess about with classloaders in my code?</p>
[ { "answer_id": 132434, "author": "NR.", "author_id": 11701, "author_profile": "https://Stackoverflow.com/users/11701", "pm_score": 2, "selected": false, "text": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE weblogic-web-app PUBLIC \"-//BEA Systems, Inc.//DTD Web Application 8.1//EN\" \"http://www.bea.com/servers/wls810/dtd/weblogic810-web-jar.dtd\">\n<weblogic-web-app>\n <container-descriptor>\n <prefer-web-inf-classes>true</prefer-web-inf-classes>\n </container-descriptor>\n</weblogic-web-app>\n" }, { "answer_id": 547641, "author": "dacracot", "author_id": 13930, "author_profile": "https://Stackoverflow.com/users/13930", "pm_score": 1, "selected": false, "text": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<orion-application>\n <imported-shared-libraries>\n <remove-inherited name=\"skip.this.package\"/>\n </imported-shared-libraries>\n</orion-application>\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132409", "https://Stackoverflow.com", "https://Stackoverflow.com/users/998/" ]
132,411
<p>I would like to translate some C code to Python code or bytecode. The C code in question is what i'd call purely algorithmic: platform independent, no I/O, just algorithms and in-memory data structures.</p> <p>An example would be a regular expression library. Translation tool would process library source code and produce a functionally equivalent Python module that can be run in a <strong>sandboxed</strong> environment.</p> <p>What specific approaches, tools and techniques can you recommend?</p> <hr> <p><em>Note: Python C extension or ctypes is <strong>not an option</strong> because the environment is sandboxed.</em></p> <p><em>Another note</em>: looks like there is a <a href="http://www.axiomsol.com/" rel="nofollow noreferrer">C-to-Java-bytecode compiler</a>, they even compiled libjpeg to Java. Is Java bytecode+VM too different from CPython bytecode+VM?</p>
[ { "answer_id": 6857972, "author": "John S", "author_id": 867314, "author_profile": "https://Stackoverflow.com/users/867314", "pm_score": 2, "selected": false, "text": "x * 1,000,000 = a\ny * 1,000,000 = b\na {function} b = result\nresult / 1,000,000 = z\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132411", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20310/" ]
132,437
<p>In an asp.net application, i would like to use a webservice to return the username associated with the session id passed as a parameter. We're currently using InProc session store.</p> <p>Is it possible to do this ?</p> <p>Edit: what i'm trying to do is get information about another session than the current one. I'm not trying to get the SessionID, i've already got it. I'm trying to get the user information <b>associated with</b> a given SessionID.</p> <p>Thanks,</p> <p>Mathieu G.</p>
[ { "answer_id": 6857972, "author": "John S", "author_id": 867314, "author_profile": "https://Stackoverflow.com/users/867314", "pm_score": 2, "selected": false, "text": "x * 1,000,000 = a\ny * 1,000,000 = b\na {function} b = result\nresult / 1,000,000 = z\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132437", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22078/" ]
132,444
<p>There is a UNIQUE database constraint on an index which doesn't allow more than one record having identical columns.</p> <p>There is a piece of code, managed by Hibernate (v2.1.8), doing two DAO <BR> <code>getHibernateTemplate().save( theObject )</code><BR> calls which results two records entered into the table mentioned above.</p> <p>If this code is executed without transactions, it results INSERT, UPDATE, then another INSERT and another UPDATE SQL statements and works fine. Apparently, the sequence is to insert the record containing DB NULL first, and then update it with the proper data.</p> <p>If this code is executed under Spring (v2.0.5) wrapped in a single Spring transaction, it results two INSERTS, followed by immediate exception due to UNIQUE constraint mentioned above.</p> <p>This problem only manifests itself on <a href="http://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=299229" rel="nofollow noreferrer">MS SQL</a> due to its incompatibility with ANSI SQL. It works fine on MySQL and Oracle. Unfortunately, our solution is cross-platform and must support all databases.</p> <p>Having this stack of technologies, what would be your preferred workaround for given problem?</p>
[ { "answer_id": 138209, "author": "Giacomo Degli Esposti", "author_id": 20796, "author_profile": "https://Stackoverflow.com/users/20796", "pm_score": 0, "selected": false, "text": "alter table MyTable Add MyCalcField as \ncase when MyUniqueField is NULL \n then cast(Myprimarykey as MyUniqueFieldType) \n else MyUniqueField end\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132444", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7345/" ]
132,445
<p>Consider the following code:</p> <pre><code>void Handler(object o, EventArgs e) { // I swear o is a string string s = (string)o; // 1 //-OR- string s = o as string; // 2 // -OR- string s = o.ToString(); // 3 } </code></pre> <p>What is the difference between the three types of casting (okay, the 3rd one is not a casting, but you get the intent). Which one should be preferred?</p>
[ { "answer_id": 132464, "author": "Sergio Acosta", "author_id": 2954, "author_profile": "https://Stackoverflow.com/users/2954", "pm_score": 3, "selected": false, "text": "string s = o as string;\n if(o is string) \n s = o;\nelse\n s = null;\n // I swear i is an int\nint number = i as int;\n" }, { "answer_id": 132467, "author": "Sander", "author_id": 2928, "author_profile": "https://Stackoverflow.com/users/2928", "pm_score": 11, "selected": true, "text": "string s = (string)o; // 1\n o string o s o null string s = o as string; // 2\n null s o string o null null o s string s = o.ToString(); // 3\n o null o.ToString() s o" }, { "answer_id": 132471, "author": "Blair Conrad", "author_id": 1199, "author_profile": "https://Stackoverflow.com/users/1199", "pm_score": 5, "selected": false, "text": "o o (string)o as o s null s string s = o as string;\nif ( s == null )\n{\n // well that's not good!\n gotoPlanB();\n}\n s as ToString o ToString" }, { "answer_id": 132513, "author": "Quibblesome", "author_id": 1143, "author_profile": "https://Stackoverflow.com/users/1143", "pm_score": 9, "selected": false, "text": "string s = (string)o; string s = o as string; string s = o.ToString();" }, { "answer_id": 132515, "author": "Joel in Gö", "author_id": 6091, "author_profile": "https://Stackoverflow.com/users/6091", "pm_score": 3, "selected": false, "text": "b = a as Badger;\nc = a as Cow;\n\nif (b != null)\n b.EatSnails();\nelse if (c != null)\n c.EatGrass();\n" }, { "answer_id": 132552, "author": "Mark Cidade", "author_id": 1659, "author_profile": "https://Stackoverflow.com/users/1659", "pm_score": 3, "selected": false, "text": "var o = (string) iKnowThisIsAString; \n var s = o as string;\nif (s != null) return s.Replace(\"_\",\"-\");\n\n//or for early return:\nif (s==null) return;\n" }, { "answer_id": 132631, "author": "Chris S", "author_id": 21574, "author_profile": "https://Stackoverflow.com/users/21574", "pm_score": 2, "selected": false, "text": "string s = o as string; // 2\n" }, { "answer_id": 132683, "author": "Glenn Slaven", "author_id": 2975, "author_profile": "https://Stackoverflow.com/users/2975", "pm_score": 3, "selected": false, "text": "Hyperlink link = this.FindControl(\"linkid\") as Hyperlink;\nif (link != null)\n{\n ...\n}\n object object linkObj = this.FindControl(\"linkid\");\nif (link != null)\n{\n Hyperlink link = (Hyperlink)linkObj;\n}\n" }, { "answer_id": 11166096, "author": "xtrem", "author_id": 943019, "author_profile": "https://Stackoverflow.com/users/943019", "pm_score": 0, "selected": false, "text": "String s = String.Concat(o);\n" }, { "answer_id": 22840744, "author": "BornToCode", "author_id": 1057791, "author_profile": "https://Stackoverflow.com/users/1057791", "pm_score": 2, "selected": false, "text": "(string)o.ToLower(); // won't compile\n ((string)o).ToLower();\n (o as string).ToLower();\n as" }, { "answer_id": 33111910, "author": "Bennett Yeo", "author_id": 2756489, "author_profile": "https://Stackoverflow.com/users/2756489", "pm_score": 0, "selected": false, "text": "obj.GetType().IsInstanceOfType(otherObj)\n" }, { "answer_id": 39683498, "author": "Lucas Teixeira", "author_id": 1698917, "author_profile": "https://Stackoverflow.com/users/1698917", "pm_score": 2, "selected": false, "text": " class TypeA\n {\n public int value;\n }\n\n class TypeB\n {\n public int number;\n\n public static explicit operator TypeB(TypeA v)\n {\n return new TypeB() { number = v.value };\n }\n }\n\n class TypeC : TypeB { }\n interface IFoo { }\n class TypeD : TypeA, IFoo { }\n\n void Run()\n {\n TypeA customTypeA = new TypeD() { value = 10 };\n long longValue = long.MaxValue;\n int intValue = int.MaxValue;\n\n // Casting \n TypeB typeB = (TypeB)customTypeA; // custom explicit casting -- IL: call class ConsoleApp1.Program/TypeB ConsoleApp1.Program/TypeB::op_Explicit(class ConsoleApp1.Program/TypeA)\n IFoo foo = (IFoo)customTypeA; // is-a reference -- IL: castclass ConsoleApp1.Program/IFoo\n\n int loseValue = (int)longValue; // explicit -- IL: conv.i4\n long dontLose = intValue; // implict -- IL: conv.i8\n\n // AS \n int? wraps = intValue as int?; // nullable wrapper -- IL: call instance void valuetype [System.Runtime]System.Nullable`1<int32>::.ctor(!0)\n object o1 = intValue as object; // box -- IL: box [System.Runtime]System.Int32\n TypeD d1 = customTypeA as TypeD; // reference conversion -- IL: isinst ConsoleApp1.Program/TypeD\n IFoo f1 = customTypeA as IFoo; // reference conversion -- IL: isinst ConsoleApp1.Program/IFoo\n\n //TypeC d = customTypeA as TypeC; // wouldn't compile\n }\n" }, { "answer_id": 45477717, "author": "Dmitry", "author_id": 5148662, "author_profile": "https://Stackoverflow.com/users/5148662", "pm_score": 1, "selected": false, "text": "string s = (string) o; string InvalidCastException as string s = o as string; null is if(o is string s)\n{\n // Use string variable s\n}\n\nor\n\nswitch (o)\n{\n case int i:\n // Use int variable i\n break;\n case string s:\n // Use string variable s\n break;\n }\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132445", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6621/" ]
132,449
<p>I'm running a strange problem sending emails. I'm getting this exception:</p> <pre><code>ArgumentError (wrong number of arguments (1 for 0)): /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/base.rb:642:in `initialize' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/base.rb:642:in `new' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/base.rb:642:in `create' /usr/lib/ruby/gems/1.8/gems/ar_mailer-1.3.1/lib/action_mailer/ar_mailer.rb:92:in `perform_delivery_activerecord' /usr/lib/ruby/gems/1.8/gems/ar_mailer-1.3.1/lib/action_mailer/ar_mailer.rb:91:in `each' /usr/lib/ruby/gems/1.8/gems/ar_mailer-1.3.1/lib/action_mailer/ar_mailer.rb:91:in `perform_delivery_activerecord' /usr/lib/ruby/gems/1.8/gems/actionmailer-2.1.1/lib/action_mailer/base.rb:508:in `__send__' /usr/lib/ruby/gems/1.8/gems/actionmailer-2.1.1/lib/action_mailer/base.rb:508:in `deliver!' /usr/lib/ruby/gems/1.8/gems/actionmailer-2.1.1/lib/action_mailer/base.rb:383:in `method_missing' /app/controllers/web_reservations_controller.rb:29:in `test_email' </code></pre> <p>In my web_reservations_controller I have a simply method calling </p> <pre><code>TestMailer.deliver_send_email </code></pre> <p>And my TesMailer is something like:</p> <pre><code>class TestMailer &lt; ActionMailer::ARMailer def send_email @recipients = "xxx@example.com" @from = "xxx@example.com" @subject = "TEST MAIL SUBJECT" @body = "&lt;br&gt;TEST MAIL MESSAGE" @content_type = "text/html" end end </code></pre> <p>Do you have any idea?</p> <p>Thanks! Roberto</p>
[ { "answer_id": 133082, "author": "Dave Nolan", "author_id": 9474, "author_profile": "https://Stackoverflow.com/users/9474", "pm_score": 0, "selected": false, "text": "class TestMailer < ActionMailer::ARMailer\n def send_email\n recipients \"roberto.druetto@gmail.com\"\n from \"roberto.druetto@gmail.com\"\n subject \"TEST MAIL SUBJECT\"\n content_type \"text/html\"\n end\nend\n body :user => User.find(1)\n @user" }, { "answer_id": 138103, "author": "dan-manges", "author_id": 20072, "author_profile": "https://Stackoverflow.com/users/20072", "pm_score": 2, "selected": true, "text": "class Email < ActiveRecord::Base\n def initialize(attributes)\n super\n # whatever you want to do\n end\nend\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132449", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22083/" ]
132,465
<p>The file upload control in asp.net does not allow me to select a folder and enables me to select only the files. Is there any way in which I can select a folder (obviously without using the file upload control).</p> <p>Why I want to select the folder is basically to store its entire path in a database table. </p>
[ { "answer_id": 132500, "author": "jop", "author_id": 11830, "author_profile": "https://Stackoverflow.com/users/11830", "pm_score": 2, "selected": false, "text": "<input type=file>" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132465", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4021/" ]
132,478
<p>I need to perform Diffs between Java strings. I would like to be able to rebuild a string using the original string and diff versions. Has anyone done this in Java? What library do you use?</p> <pre><code>String a1; // This can be a long text String a2; // ej. above text with spelling corrections String a3; // ej. above text with spelling corrections and an additional sentence Diff diff = new Diff(); String differences_a1_a2 = Diff.getDifferences(a,changed_a); String differences_a2_a3 = Diff.getDifferences(a,changed_a); String[] diffs = new String[]{a,differences_a1_a2,differences_a2_a3}; String new_a3 = Diff.build(diffs); a3.equals(new_a3); // this is true </code></pre>
[ { "answer_id": 132484, "author": "Paul Whelan", "author_id": 3050, "author_profile": "https://Stackoverflow.com/users/3050", "pm_score": 5, "selected": false, "text": "StringUtils.difference(\"foobar\", \"foo\");\n" }, { "answer_id": 132560, "author": "Paul Whelan", "author_id": 3050, "author_profile": "https://Stackoverflow.com/users/3050", "pm_score": 2, "selected": false, "text": "System.err.println(StringUtils.getLevenshteinDistance(\"foobar\", \"bar\"));\n" }, { "answer_id": 40873183, "author": "Sandeep Raj Urs", "author_id": 7221637, "author_profile": "https://Stackoverflow.com/users/7221637", "pm_score": -1, "selected": false, "text": "public class Stringdiff {\npublic static void main(String args[]){\nSystem.out.println(strcheck(\"sum\",\"sumsum\"));\n}\npublic static String strcheck(String str1,String str2){\n if(Math.abs((str1.length()-str2.length()))==-1){\n return \"Invalid\";\n }\n int num=diffcheck1(str1, str2);\n if(num==-1){\n return \"Empty\";\n }\n if(str1.length()>str2.length()){\n return str1.substring(num);\n }\n else{\n return str2.substring(num);\n }\n\n}\n\npublic static int diffcheck1(String str1,String str2)\n{\n int i;\n String str;\n String strn;\n if(str1.length()>str2.length()){\n str=str1;\n strn=str2;\n }\n else{\n str=str2;\n strn=str1;\n }\n for(i=0;i<str.length() && i<strn.length();i++){\n if(str1.charAt(i)!=str2.charAt(i)){\n return i;\n }\n }\n if(i<str1.length()||i<str2.length()){\n return i;\n }\n\n return -1;\n\n }\n }\n" }, { "answer_id": 60191154, "author": "Ahmed Ashour", "author_id": 184201, "author_profile": "https://Stackoverflow.com/users/184201", "pm_score": 0, "selected": false, "text": "StringsComparator c = new StringsComparator(s1, s2);\nc.getScript().visit(new CommandVisitor<Character>() {\n\n @Override\n public void visitKeepCommand(Character object) {\n System.out.println(\"k: \" + object);\n }\n\n @Override\n public void visitInsertCommand(Character object) {\n System.out.println(\"i: \" + object);\n }\n\n @Override\n public void visitDeleteCommand(Character object) {\n System.out.println(\"d: \" + object);\n }\n});\n" }, { "answer_id": 74463656, "author": "Joshua Goldberg", "author_id": 411282, "author_profile": "https://Stackoverflow.com/users/411282", "pm_score": 0, "selected": false, "text": "assertj java-diff-utils" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132478", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2138/" ]
132,488
<p>I want a regex which can match conditional comments in a HTML source page so I can remove only those. I want to preserve the regular comments.</p> <p>I would also like to avoid using the .*? notation if possible. </p> <p>The text is </p> <pre><code>foo &lt;!--[if IE]&gt; &lt;style type="text/css"&gt; ul.menu ul li{ font-size: 10px; font-weight:normal; padding-top:0px; } &lt;/style&gt; &lt;![endif]--&gt; bar </code></pre> <p>and I want to remove everything in <code>&lt;!--[if IE]&gt;</code> and <code>&lt;![endif]--&gt;</code></p> <p><strong>EDIT:</strong> It is because of BeautifulSoup I want to remove these tags. BeautifulSoup fails to parse and gives an incomplete source</p> <p><strong>EDIT2:</strong> [if IE] isn't the only condition. There are lots more and I don't have any list of all possible combinations.</p> <p><strong>EDIT3:</strong> Vinko Vrsalovic's solution works, but the actual problem why beautifulsoup failed was because of a rogue comment within the conditional comment. Like</p> <pre><code>&lt;!--[if lt IE 7.]&gt; &lt;script defer type="text/javascript" src="pngfix_253168.js"&gt;&lt;/script&gt;&lt;!--png fix for IE--&gt; &lt;![endif]--&gt; </code></pre> <p>Notice the <code>&lt;!--png fix for IE--&gt;</code> comment?</p> <p>Though my problem was solve, I would love to get a regex solution for this.</p>
[ { "answer_id": 132519, "author": "Nescio", "author_id": 14484, "author_profile": "https://Stackoverflow.com/users/14484", "pm_score": 1, "selected": false, "text": " \"<!--\\[if IE\\]>.*?<!\\[endif\\]-->\"\n" }, { "answer_id": 132521, "author": "Lev", "author_id": 7224, "author_profile": "https://Stackoverflow.com/users/7224", "pm_score": 0, "selected": false, "text": "\\<!--\\[if IE\\]\\>{.|\\n}*\\<!\\[endif\\]--\\>" }, { "answer_id": 132532, "author": "Vinko Vrsalovic", "author_id": 5190, "author_profile": "https://Stackoverflow.com/users/5190", "pm_score": 3, "selected": false, "text": ">>> from BeautifulSoup import BeautifulSoup, Comment\n>>> html = '<html><!--[if IE]> bloo blee<![endif]--></html>'\n>>> soup = BeautifulSoup(html)\n>>> comments = soup.findAll(text=lambda text:isinstance(text, Comment) \n and text.find('if') != -1) #This is one line, of course\n>>> [comment.extract() for comment in comments]\n[u'[if IE]> bloo blee<![endif]']\n>>> print soup.prettify()\n<html>\n</html>\n>>> \n from bs4 import BeautifulSoup, Comment\nhtml = '<html><!--[if IE]> bloo blee<![endif]--></html>'\nsoup = BeautifulSoup(html, \"html.parser\")\ncomments = soup.findAll(text=lambda text:isinstance(text, Comment) \n and text.find('if') != -1) #This is one line, of course\n[comment.extract() for comment in comments]\n[u'[if IE]> bloo blee<![endif]']\nprint (soup.prettify())\n" }, { "answer_id": 132561, "author": "Huppie", "author_id": 1830, "author_profile": "https://Stackoverflow.com/users/1830", "pm_score": 2, "selected": false, "text": "<!(|--)\\[[^\\]]+\\]>.+?<!\\[endif\\](|--)>\n <!--[if anything]>\n ...\n<[endif]-->\n <![if ! IE 6]>\n ...\n<![endif]>\n (<!(|--)\\[[^\\]]+\\]>.*?)(<!--.+?-->)(.*?<!\\[endif\\](|--)>)\n" }, { "answer_id": 135916, "author": "e-satis", "author_id": 9951, "author_profile": "https://Stackoverflow.com/users/9951", "pm_score": 2, "selected": false, "text": "import re\n\nhtml = \"\"\"fjlk<wb>dsqfjqdsmlkf fdsijfmldsqjfl fjdslmfkqsjf<---- fdjslmjkqfs---><!--[if lt IE 7.]>\\\n<script defer type=\"text/javascript\" src=\"pngfix_253168.js\"></script><!--png fix for IE-->\\\n<![endif]-->fjlk<wb>dsqfjqdsmlkf fdsijfmldsqjfl fjdslmfkqsjf<---- fdjslmjkqfs--->\"\"\"\n\n# here the black magic occurs (whithout '.')\nclean_html = ''.join(re.split(r'<!--\\[[^¤]+?endif]-->', html))\n\nprint clean_html\n\n'fjlk<wb>dsqfjqdsmlkf fdsijfmldsqjfl fjdslmfkqsjf<---- fdjslmjkqfs--->fjlk<wb>dsqfjqdsmlkf fdsijfmldsqjfl fjdslmfkqsjf<---- fdjslmjkqfs--->'\n" }, { "answer_id": 137831, "author": "Alan Moore", "author_id": 20938, "author_profile": "https://Stackoverflow.com/users/20938", "pm_score": 2, "selected": false, "text": "<!-- if \"<!--\\[if\\s(?:[^<]+|<(?!!\\[endif\\]-->))*<!\\[endif\\]-->\"\n .*? .*? (?s:...) \"(?s:<!--\\[if\\s.*?<!\\[endif\\]-->)\"\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132488", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1448/" ]
132,501
<p>How to sort list of values using only one variable?</p> <p>EDIT: according to @Igor's comment, I retitled the question.</p>
[ { "answer_id": 132783, "author": "Nils Pipenbrinck", "author_id": 15955, "author_profile": "https://Stackoverflow.com/users/15955", "pm_score": 2, "selected": false, "text": "// define a compare and swap macro \n#define order(a,b) if ((a)<(b)) { temp=(a); (a) = (b); (b) = temp; }\n\nstatic void sort2 (int *data)\n// sort-network for two numbers\n{\n int temp;\n order (data[0], data[1]);\n}\n\nstatic void sort3 (int *data)\n// sort-network for three numbers\n{\n int temp;\n order (data[0], data[1]);\n order (data[0], data[2]);\n order (data[1], data[2]);\n}\n\nstatic void sort4 (int *data)\n// sort-network for four numbers\n{\n int temp;\n order (data[0], data[2]);\n order (data[1], data[3]);\n order (data[0], data[1]);\n order (data[2], data[3]);\n order (data[1], data[2]);\n}\n\nvoid sort (int *data, int n)\n{\n switch (n)\n {\n case 0:\n case 1:\n break;\n case 2:\n sort2 (data);\n break;\n case 3:\n sort3 (data);\n break;\n case 4:\n sort4 (data);\n break;\n default:\n // Sorts for n>4 are left as an exercise for the reader\n abort();\n }\n}\n" }, { "answer_id": 133080, "author": "Hugh Allen", "author_id": 15069, "author_profile": "https://Stackoverflow.com/users/15069", "pm_score": 2, "selected": false, "text": "procedure mysort(thelist)\n local n # the one integer variable\n every n := (1 to *thelist & 1 to *thelist-1) do\n if thelist[n] > thelist[n+1] then thelist[n] :=: thelist[n+1]\n return thelist\nend\n\nprocedure main(args)\n every write(!mysort([4,7,2,4,1,10,3]))\nend\n 1\n2\n3\n4\n4\n7\n10\n" }, { "answer_id": 133290, "author": "Hugh Allen", "author_id": 15069, "author_profile": "https://Stackoverflow.com/users/15069", "pm_score": 4, "selected": true, "text": "#include <stdio.h>\n\nint main()\n{\n int list[]={4,7,2,4,1,10,3};\n int n; // the one int variable\n \n startsort:\n for (n=0; n< sizeof(list)/sizeof(int)-1; ++n)\n if (list[n] > list[n+1]) {\n list[n] ^= list[n+1];\n list[n+1] ^= list[n];\n list[n] ^= list[n+1];\n goto startsort;\n }\n \n for (n=0; n< sizeof(list)/sizeof(int); ++n)\n printf(\"%d\\n\",list[n]);\n return 0;\n}\n" }, { "answer_id": 133359, "author": "Bill Michell", "author_id": 7938, "author_profile": "https://Stackoverflow.com/users/7938", "pm_score": 1, "selected": false, "text": "import java.util.Arrays;\n\n/**\n * Does a bubble sort without allocating extra memory\n *\n */\npublic class Sort {\n // Implements bubble sort very inefficiently for CPU but with minimal variable declarations\n public static void sort(int[] array) {\n int index=0;\n while(true) {\n next:\n {\n // Scan for correct sorting. Wasteful, but avoids using a boolean parameter\n for (index=0;index<array.length-1;index++) {\n if (array[index]>array[index+1]) break next;\n }\n // Array is now correctly sorted\n return;\n }\n // Now swap. We don't need to rescan from the start\n for (;index<array.length-1;index++) {\n if (array[index]>array[index+1]) {\n // use xor trick to avoid using an extra integer\n array[index]^=array[index+1];\n array[index+1]^=array[index];\n array[index]^=array[index+1];\n }\n }\n }\n }\n\n public static void main(final String argv[]) {\n int[] array=new int[] {4,7,2,4,1,10,3};\n sort(array);\n System.out.println(Arrays.toString(array));\n }\n}\n" }, { "answer_id": 268433, "author": "Svante", "author_id": 31615, "author_profile": "https://Stackoverflow.com/users/31615", "pm_score": 0, "selected": false, "text": "(1 5 3 7 4 2) v v v v" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132501", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4235/" ]
132,507
<p>I'm creating a UI that allows the user the select a date range, and tick or un-tick the days of the week that apply within the date range.</p> <p>The date range controls are <code>DateTimePickers</code>, and the Days of the Week are <code>CheckBoxes</code></p> <p>Here's a mock-up of the UI:</p> <p><code>From Date: (dtpDateFrom)</code><br/> <code>To Date: (dtpDateTo)</code></p> <p><code>[y] Monday, [n] Tuesday, [y] Wednesday, (etc)</code></p> <p>What's the best way to show a total count the number of days, based not only on the date range, but the ticked (or selected) days of the week?</p> <p>Is looping through the date range my only option?</p>
[ { "answer_id": 132541, "author": "Blair Conrad", "author_id": 1199, "author_profile": "https://Stackoverflow.com/users/1199", "pm_score": 2, "selected": false, "text": "#weeks * skipped days in a week" }, { "answer_id": 132557, "author": "ravenspoint", "author_id": 16582, "author_profile": "https://Stackoverflow.com/users/16582", "pm_score": 4, "selected": true, "text": " moved = start + end_dow - start_dow\n extras = count included days between start and moved\n weeks = ( end - moved ) / 7\n days = days_of_week_included * weeks + extras\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132507", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5662/" ]
132,544
<p>I have a .NET application which has different configuration files for Debug and Release builds. E.g. the debug app.config file points to a development <a href="http://en.wikipedia.org/wiki/Microsoft_SQL_Server" rel="noreferrer">SQL Server</a> which has debugging enabled and the release target points to the live SQL Server. There are also other settings, some of which are different in debug/release.</p> <p>I currently use two separate configuration files (debug.app.config and release.app.config). I have a build event on the project which says if this is a release build then copy release.app.config to app.config, else copy debug.app.config to app.config.</p> <p>The problem is that the application seems to get its settings from the settings.settings file, so I have to open settings.settings in Visual Studio which then prompts me that the settings have changed so I accept the changes, save settings.settings and have to rebuild to make it use the correct settings.</p> <p>Is there a better/recommended/preferred method for achieving a similar effect? Or equally, have I approached this completely wrong and is there a better approach?</p>
[ { "answer_id": 132600, "author": "Eric Z Beard", "author_id": 1219, "author_profile": "https://Stackoverflow.com/users/1219", "pm_score": 5, "selected": false, "text": "<appSettings file=\"Local.config\">\n configSource=\"Local.config\"\n" }, { "answer_id": 132655, "author": "Steven Williams", "author_id": 3294, "author_profile": "https://Stackoverflow.com/users/3294", "pm_score": 4, "selected": false, "text": "<target name=\"build\">\n <property name=\"config.type\" value=\"Release\" />\n\n <msbuild project=\"${filename}\" target=\"Build\" verbose=\"true\" failonerror=\"true\">\n <property name=\"Configuration\" value=\"${config.type}\" />\n </msbuild>\n\n <if test=\"${config.type == 'Debug'}\">\n <copy file=${debug.app.config}\" tofile=\"${app.config}\" />\n </if>\n\n <if test=\"${config.type == 'Release'}\">\n <copy file=${release.app.config}\" tofile=\"${app.config}\" />\n </if>\n\n</target>\n" }, { "answer_id": 132668, "author": "Adam Vigh", "author_id": 1613872, "author_profile": "https://Stackoverflow.com/users/1613872", "pm_score": 3, "selected": false, "text": "<Target Name=\"AfterBuild\">\n <!--Web.config -->\n <Copy Condition=\" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' \" SourceFiles=\"$(SourceWebPhysicalPath)\\Web.Release.config\" DestinationFiles=\"$(OutputPath)\\Web.config\" />\n <Copy Condition=\" '$(Configuration)|$(Platform)' == 'Staging|AnyCPU' \" SourceFiles=\"$(SourceWebPhysicalPath)\\Web.Staging.config\" DestinationFiles=\"$(OutputPath)\\Web.config\" />\n <!--Delete extra files -->\n <Delete Files=\"$(OutputPath)\\Web.Release.config\" />\n <Delete Files=\"$(OutputPath)\\Web.Staging.config\" />\n <Delete Files=\"@(ProjFiles)\" />\n </Target>\n" }, { "answer_id": 132748, "author": "jasondoucette", "author_id": 19794, "author_profile": "https://Stackoverflow.com/users/19794", "pm_score": 3, "selected": false, "text": " <xmlpoke\n file=\"${stagingTarget}/web.config\"\n xpath=\"/configuration/system.web/compilation/@debug\"\n value=\"true\"\n />\n" }, { "answer_id": 590376, "author": "Tony Trembath-Drake", "author_id": 61868, "author_profile": "https://Stackoverflow.com/users/61868", "pm_score": 2, "selected": false, "text": "<appSettings> <add key = \"Env\" value = \"[Local] \"/>" }, { "answer_id": 1015359, "author": "Punit Vora", "author_id": 125422, "author_profile": "https://Stackoverflow.com/users/125422", "pm_score": 2, "selected": false, "text": " <!-- Actual Config File -->\n <appSettings>\n <add key=\"ApplicationName\" value=\"NameInDev\"/>\n <add key=\"ThisDoesNotChange\" value=\"Do not put in substitution file\" />\n </appSettings>\n\n <!-- Substitutions.xml -->\n <configuration xmlns:xmu=\"urn:msbuildcommunitytasks-xmlmassupdate\">\n <substitutions>\n <QA>\n <appSettings>\n <add xmu:key=\"key\" key=\"ApplicationName\" value=\"NameInQA\"/>\n </appSettings> \n </QA>\n <Prod>\n <appSettings>\n <add xmu:key=\"key\" key=\"ApplicationName\" value=\"NameInProd\"/>\n </appSettings> \n </Prod>\n </substitutions>\n </configuration>\n\n\n<!-- Build.xml file-->\n\n <Target Name=\"UpdateConfigSections\">\n <XmlMassUpdate ContentFile=\"Path\\of\\copy\\of\\latest web.config\" SubstitutionsFile=\"path\\of\\substitutionFile\" ContentRoot=\"/configuration\" SubstitutionsRoot=\"/configuration/substitutions/$(Environment)\" />\n </Target>\n" }, { "answer_id": 6114524, "author": "Prisoner ZERO", "author_id": 312317, "author_profile": "https://Stackoverflow.com/users/312317", "pm_score": 0, "selected": false, "text": "public enum ConfigurationSection\n{\n AppSettings\n}\n\npublic static class Utility\n{\n #region \"Common.Configuration.Configurations\"\n\n private static Cache cache = System.Web.HttpRuntime.Cache;\n\n public static String GetAppSetting(String key)\n {\n return GetConfigurationValue(ConfigurationSection.AppSettings, key);\n }\n\n public static String GetConfigurationValue(ConfigurationSection section, String key)\n {\n Configurations config = null;\n\n if (!cache.TryGetItemFromCache<Configurations>(out config))\n {\n config = new Configurations();\n config.List(SNCLavalin.US.Common.Enumerations.ConfigurationSection.AppSettings);\n cache.AddToCache<Configurations>(config, DateTime.Now.AddMinutes(15));\n }\n\n var result = (from record in config\n where record.Key == key\n select record).FirstOrDefault();\n\n return (result == null) ? null : result.Value;\n }\n\n #endregion\n}\n\nnamespace Common.Configuration\n{\n public class Configurations : List<Configuration>\n {\n #region CONSTRUCTORS\n\n public Configurations() : base()\n {\n initialize();\n }\n public Configurations(int capacity) : base(capacity)\n {\n initialize();\n }\n public Configurations(IEnumerable<Configuration> collection) : base(collection)\n {\n initialize();\n }\n\n #endregion\n\n #region PROPERTIES & FIELDS\n\n private Crud _crud; // Db-Access layer\n\n #endregion\n\n #region EVENTS\n #endregion\n\n #region METHODS\n\n private void initialize()\n {\n _crud = new Crud(Utility.ConnectionName);\n }\n\n /// <summary>\n /// Lists one-to-many records.\n /// </summary>\n public Configurations List(ConfigurationSection section)\n {\n using (DbCommand dbCommand = _crud.Db.GetStoredProcCommand(\"spa_LIST_MyConfiguration\"))\n {\n _crud.Db.AddInParameter(dbCommand, \"@Section\", DbType.String, section.ToString());\n\n _crud.List(dbCommand, PopulateFrom);\n }\n\n return this;\n }\n\n public void PopulateFrom(DataTable table)\n {\n this.Clear();\n\n foreach (DataRow row in table.Rows)\n {\n Configuration instance = new Configuration();\n instance.PopulateFrom(row);\n this.Add(instance);\n }\n }\n\n #endregion\n }\n\n public class Configuration\n {\n #region CONSTRUCTORS\n\n public Configuration()\n {\n initialize();\n }\n\n #endregion\n\n #region PROPERTIES & FIELDS\n\n private Crud _crud;\n\n public string Section { get; set; }\n public string Key { get; set; }\n public string Value { get; set; }\n\n #endregion\n\n #region EVENTS\n #endregion\n\n #region METHODS\n\n private void initialize()\n {\n _crud = new Crud(Utility.ConnectionName);\n Clear();\n }\n\n public void Clear()\n {\n this.Section = \"\";\n this.Key = \"\";\n this.Value = \"\";\n }\n public void PopulateFrom(DataRow row)\n {\n Clear();\n\n this.Section = row[\"Section\"].ToString();\n this.Key = row[\"Key\"].ToString();\n this.Value = row[\"Value\"].ToString();\n }\n\n #endregion\n }\n}\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132544", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8354/" ]
132,564
<p>I'm working in Java with XML and I'm wondering; what's the difference between an element and a node?</p>
[ { "answer_id": 132572, "author": "mmaibaum", "author_id": 12213, "author_profile": "https://Stackoverflow.com/users/12213", "pm_score": 5, "selected": false, "text": "<foo> This is Text </foo>" }, { "answer_id": 132635, "author": "fenomas", "author_id": 10651, "author_profile": "https://Stackoverflow.com/users/10651", "pm_score": 4, "selected": false, "text": "element <foo> stuff </foo>\n<foo bar=\"baz\"></foo>\n<foo baz=\"qux\" />\n" }, { "answer_id": 297810, "author": "Dimitre Novatchev", "author_id": 36305, "author_profile": "https://Stackoverflow.com/users/36305", "pm_score": 6, "selected": false, "text": "Document Element ProcessingInstruction Comment DocumentType DocumentFragment Element ProcessingInstruction Comment Text CDATASection EntityReference DocumentType EntityReference Element ProcessingInstruction Comment Text CDATASection EntityReference Element Element Text Comment ProcessingInstruction CDATASection EntityReference Attr Text EntityReference ProcessingInstruction Comment Text CDATASection Entity Element ProcessingInstruction Comment Text CDATASection EntityReference Notation An element is a type of node. Many other types of nodes exist and serve different purposes." }, { "answer_id": 15792639, "author": "Colonel Panic", "author_id": 284795, "author_profile": "https://Stackoverflow.com/users/284795", "pm_score": 3, "selected": false, "text": "<body> </body> <br/> <p class=\"rant\">" }, { "answer_id": 39285160, "author": "Sabique A Khan", "author_id": 4374818, "author_profile": "https://Stackoverflow.com/users/4374818", "pm_score": -1, "selected": false, "text": "<a>Lorem Ipsum</a> //This is a node\n\n<a id=\"sample\">Lorem Ipsum</a> //This is an element\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132564", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21709/" ]
132,566
<p>Despite my most convincing cries to the contrary, I was recently forced to implement a horizontal drop-down navigation system, so I opted for the friendliest one I could find - <a href="http://www.htmldog.com/articles/suckerfish/dropdowns/" rel="nofollow noreferrer">Son of Suckerfish</a>.</p> <p>I tested in various browsers on my machine and all appeared to be fine. However, some (but not all!) IE7 users are experiencing an issue where sub menus do not close after they have been hovered over. The most annoying thing is that the affected users are using the exact version of IE7 that I am (7.0.5730.13), with the same privacy and security settings (I even had them send screenshots of the tabs in Internet Options) on the same OS (XP). I cannot verify if Vista is affected or not.</p> <p>Obviously trying to debug this issue is a nightmare since I cannot replicate it, so I am wondering if anyone here can and might know how to solve it. I have set up an example page here:</p> <blockquote> <p><a href="http://x01.co.uk/menu_test/" rel="nofollow noreferrer">http://x01.co.uk/menu_test/</a></p> </blockquote> <p>Additionally, there's an annoying flicker on rollover of the sub items which I have also tried to solve with no success, so any help with that would also be appreciated.</p>
[ { "answer_id": 133110, "author": "Bryan M.", "author_id": 4636, "author_profile": "https://Stackoverflow.com/users/4636", "pm_score": 3, "selected": true, "text": "#nav li:hover {\n position: static;\n}\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132566", "https://Stackoverflow.com", "https://Stackoverflow.com/users/192/" ]
132,590
<p>I've been writing a little application that will let people upload &amp; download files to me. I've added a web service to this applciation to provide the upload/download functionality that way but I'm not too sure on how well my implementation is going to cope with large files.</p> <p>At the moment the definitions of the upload &amp; download methods look like this (written using Apache CXF):</p> <pre><code>boolean uploadFile(@WebParam(name = "username") String username, @WebParam(name = "password") String password, @WebParam(name = "filename") String filename, @WebParam(name = "fileContents") byte[] fileContents) throws UploadException, LoginException; byte[] downloadFile(@WebParam(name = "username") String username, @WebParam(name = "password") String password, @WebParam(name = "filename") String filename) throws DownloadException, LoginException; </code></pre> <p>So the file gets uploaded and downloaded as a byte array. But if I have a file of some stupid size (e.g. 1GB) surely this will try and put all that information into memory and crash my service.</p> <p>So my question is - is it possible to return some kind of stream instead? I would imagine this isn't going to be terribly OS independent though. Although I know the theory behind web services, the practical side is something that I still need to pick up a bit of information on.</p> <p>Cheers for any input, Lee</p>
[ { "answer_id": 132603, "author": "Guvante", "author_id": 16800, "author_profile": "https://Stackoverflow.com/users/16800", "pm_score": 4, "selected": true, "text": "boolean uploadFile(String username, String password, String fileName, int currentChunk, int totalChunks, byte[] chunk);\n" }, { "answer_id": 6984685, "author": "nont", "author_id": 104887, "author_profile": "https://Stackoverflow.com/users/104887", "pm_score": 0, "selected": false, "text": " @RequestMapping(value = \"/stream\")\n public void hellostreamer(HttpServletRequest request, HttpServletResponse response) throws CopyStreamException, IOException \n{\n\n response.setContentType(\"text/xml\");\n OutputStreamWriter writer = new OutputStreamWriter (response.getOutputStream());\n writer.write(\"this is streaming\");\n writer.close();\n\n }\n" }, { "answer_id": 9982252, "author": "Rodney Barbati", "author_id": 1269507, "author_profile": "https://Stackoverflow.com/users/1269507", "pm_score": 0, "selected": false, "text": "class MyServlet extends HttpServlet\n{\n public void doGet(HttpServletRequest request, HttpServletResponse response)\n {\n response.getOutputStream().println(\"Hello World!\");\n }\n}\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132590", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1900/" ]
132,592
<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/114149/const-correctness-in-c-sharp">&ldquo;const correctness&rdquo; in C#</a> </p> </blockquote> <p>I have programmed C++ for many years but am fairly new to C#. While learning C# I found that the use of the <a href="http://en.csharp-online.net/const,_static_and_readonly" rel="nofollow noreferrer">const</a> keyword is much more limited than in C++. AFAIK, there is, <a href="http://andymcm.com/csharpfaq.htm#6.8" rel="nofollow noreferrer">for example</a>, no way to declare arguments to a function const. I feel uncomfortable with the idea that I may make inadvertent changes to my function arguments (which may be complex data structures) that I can only detect by testing. </p> <p>How do you deal with this situation?</p>
[ { "answer_id": 132603, "author": "Guvante", "author_id": 16800, "author_profile": "https://Stackoverflow.com/users/16800", "pm_score": 4, "selected": true, "text": "boolean uploadFile(String username, String password, String fileName, int currentChunk, int totalChunks, byte[] chunk);\n" }, { "answer_id": 6984685, "author": "nont", "author_id": 104887, "author_profile": "https://Stackoverflow.com/users/104887", "pm_score": 0, "selected": false, "text": " @RequestMapping(value = \"/stream\")\n public void hellostreamer(HttpServletRequest request, HttpServletResponse response) throws CopyStreamException, IOException \n{\n\n response.setContentType(\"text/xml\");\n OutputStreamWriter writer = new OutputStreamWriter (response.getOutputStream());\n writer.write(\"this is streaming\");\n writer.close();\n\n }\n" }, { "answer_id": 9982252, "author": "Rodney Barbati", "author_id": 1269507, "author_profile": "https://Stackoverflow.com/users/1269507", "pm_score": 0, "selected": false, "text": "class MyServlet extends HttpServlet\n{\n public void doGet(HttpServletRequest request, HttpServletResponse response)\n {\n response.getOutputStream().println(\"Hello World!\");\n }\n}\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132592", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19863/" ]
132,607
<p>We're reviewing one of the company's system's exception handling and found a couple of interesting things.</p> <p>Most of the code blocks (if not all of them) are inside a try/catch block, and inside the catch block a new BaseApplicationException is being thrown - which seems to be coming from the Enterprise Libraries. I'm in a bit of a trouble here as I don't see the benefits off doing this. (throwing another exception anytime one occurs) One of the developers who's been using the system for a while said it's because that class's in charge of publishing the exception (sending emails and stuff like that) but he wasn't too sure about it. After spending some time going through the code I'm quite confident to say, that's all it does is collecting information about the environment and than publishing it.</p> <p>My question is: - Is it reasonable to wrap all the code inside try { } catch { } blocks and than throw a new exception? And if it is, why? What's the benefit?</p> <p>My personal opinion is that it would be much easier to use an HttpModule, sign up for the Error event of the Application event, and do what's necessary inside the module. If we'd go down this road, would we miss something? Any drawbacks?</p> <p>Your opinion's much appreciated.</p>
[ { "answer_id": 133044, "author": "Christoffer Lette", "author_id": 11808, "author_profile": "https://Stackoverflow.com/users/11808", "pm_score": 4, "selected": true, "text": "catch (Exception ex) System.AppDomain.CurrentDomain.UnhandledException Threading System.Windows.Forms.Application.ThreadException. System.Web.HttpApplication.Error throw new MyBaseException(ex); Exception ex" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132607", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1613872/" ]
132,612
<p>I have found that when I execute the show() method for a contextmenustrip (a right click menu), if the position is outside that of the form it belongs to, it shows up on the taskbar also.</p> <p>I am trying to create a right click menu for when clicking on the notifyicon, but as the menu hovers above the system tray and not inside the form (as the form can be minimised when right clicking) it shows up on the task bar for some odd reason</p> <p>Here is my code currently:</p> <pre><code>private: System::Void notifyIcon1_MouseClick(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) { if(e-&gt;Button == System::Windows::Forms::MouseButtons::Right) { this-&gt;sysTrayMenu-&gt;Show(Cursor-&gt;Position); } } </code></pre> <p>What other options do I need to set so it doesn't show up a blank process on the task bar.</p>
[ { "answer_id": 7433813, "author": "Dicu Alexandru", "author_id": 947202, "author_profile": "https://Stackoverflow.com/users/947202", "pm_score": 2, "selected": false, "text": "ContextMenuLeft ContextMenuRight Left Button Click NotifyIcon.ContextMenuStrip = ContextMenuLeft; //let's asign the other one\nMethodInfo mi = typeof(NotifyIcon).GetMethod(\"ShowContextMenu\", BindingFlags.Instance | BindingFlags.NonPublic);\nmi.Invoke(NotifyIcon, null);\nNotifyIcon.ContextMenuStrip = ContextMenuRight; //switch back to the default one\n" }, { "answer_id": 11242454, "author": "MaratSh", "author_id": 925008, "author_profile": "https://Stackoverflow.com/users/925008", "pm_score": 3, "selected": false, "text": "{\n UnsafeNativeMethods.SetForegroundWindow(new HandleRef(notifyIcon.ContextMenuStrip, notifyIcon.ContextMenuStrip.Handle));\n notifyIcon.ContextMenuStrip.Show(Cursor.Position);\n}\n public static class UnsafeNativeMethods\n{\n [DllImport(\"user32.dll\", CharSet = CharSet.Auto, ExactSpelling = true)]\n public static extern bool SetForegroundWindow(HandleRef hWnd);\n}\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132612", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15087/" ]
132,620
<p>Here's the scenario:</p> <p>You have a Windows server that users remotely connect to via RDP. You want your program (which runs as a service) to know who is currently connected. This may or may not include an interactive console session.</p> <p>Please note that this is the <strong>not</strong> the same as just retrieving the current interactive user.</p> <p>I'm guessing that there is some sort of API access to Terminal Services to get this info?</p>
[ { "answer_id": 132711, "author": "Nescio", "author_id": 14484, "author_profile": "https://Stackoverflow.com/users/14484", "pm_score": 1, "selected": false, "text": "using System;\nusing System.Collections.Generic;\nusing System.Text;\nusing System.Runtime.InteropServices;\n\nnamespace TerminalServices\n{\n class TSManager\n {\n [DllImport(\"wtsapi32.dll\")]\n static extern IntPtr WTSOpenServer([MarshalAs(UnmanagedType.LPStr)] String pServerName);\n\n [DllImport(\"wtsapi32.dll\")]\n static extern void WTSCloseServer(IntPtr hServer);\n\n [DllImport(\"wtsapi32.dll\")]\n static extern Int32 WTSEnumerateSessions(\n IntPtr hServer, \n [MarshalAs(UnmanagedType.U4)] Int32 Reserved,\n [MarshalAs(UnmanagedType.U4)] Int32 Version, \n ref IntPtr ppSessionInfo,\n [MarshalAs(UnmanagedType.U4)] ref Int32 pCount);\n\n [DllImport(\"wtsapi32.dll\")]\n static extern void WTSFreeMemory(IntPtr pMemory);\n\n [StructLayout(LayoutKind.Sequential)]\n private struct WTS_SESSION_INFO\n {\n public Int32 SessionID;\n\n [MarshalAs(UnmanagedType.LPStr)]\n public String pWinStationName;\n\n public WTS_CONNECTSTATE_CLASS State;\n }\n\n public enum WTS_CONNECTSTATE_CLASS\n {\n WTSActive,\n WTSConnected,\n WTSConnectQuery,\n WTSShadow,\n WTSDisconnected,\n WTSIdle,\n WTSListen,\n WTSReset,\n WTSDown,\n WTSInit\n } \n\n public static IntPtr OpenServer(String Name)\n {\n IntPtr server = WTSOpenServer(Name);\n return server;\n }\n public static void CloseServer(IntPtr ServerHandle)\n {\n WTSCloseServer(ServerHandle);\n }\n public static List<String> ListSessions(String ServerName)\n {\n IntPtr server = IntPtr.Zero;\n List<String> ret = new List<string>();\n server = OpenServer(ServerName);\n\n try\n {\n IntPtr ppSessionInfo = IntPtr.Zero;\n\n Int32 count = 0;\n Int32 retval = WTSEnumerateSessions(server, 0, 1, ref ppSessionInfo, ref count);\n Int32 dataSize = Marshal.SizeOf(typeof(WTS_SESSION_INFO));\n\n Int32 current = (int)ppSessionInfo;\n\n if (retval != 0)\n {\n for (int i = 0; i < count; i++)\n {\n WTS_SESSION_INFO si = (WTS_SESSION_INFO)Marshal.PtrToStructure((System.IntPtr)current, typeof(WTS_SESSION_INFO));\n current += dataSize;\n\n ret.Add(si.SessionID + \" \" + si.State + \" \" + si.pWinStationName);\n }\n\n WTSFreeMemory(ppSessionInfo);\n }\n }\n finally\n {\n CloseServer(server);\n }\n\n return ret;\n }\n }\n}\n" }, { "answer_id": 132774, "author": "Magnus Johansson", "author_id": 3584, "author_profile": "https://Stackoverflow.com/users/3584", "pm_score": 6, "selected": true, "text": "using System;\nusing System.Collections.Generic;\nusing System.Runtime.InteropServices;\n\nnamespace EnumerateRDUsers\n{\n class Program\n {\n [DllImport(\"wtsapi32.dll\")]\n static extern IntPtr WTSOpenServer([MarshalAs(UnmanagedType.LPStr)] string pServerName);\n\n [DllImport(\"wtsapi32.dll\")]\n static extern void WTSCloseServer(IntPtr hServer);\n\n [DllImport(\"wtsapi32.dll\")]\n static extern Int32 WTSEnumerateSessions(\n IntPtr hServer,\n [MarshalAs(UnmanagedType.U4)] Int32 Reserved,\n [MarshalAs(UnmanagedType.U4)] Int32 Version,\n ref IntPtr ppSessionInfo,\n [MarshalAs(UnmanagedType.U4)] ref Int32 pCount);\n\n [DllImport(\"wtsapi32.dll\")]\n static extern void WTSFreeMemory(IntPtr pMemory);\n\n [DllImport(\"wtsapi32.dll\")]\n static extern bool WTSQuerySessionInformation(\n IntPtr hServer, int sessionId, WTS_INFO_CLASS wtsInfoClass, out IntPtr ppBuffer, out uint pBytesReturned);\n\n [StructLayout(LayoutKind.Sequential)]\n private struct WTS_SESSION_INFO\n {\n public Int32 SessionID;\n\n [MarshalAs(UnmanagedType.LPStr)]\n public string pWinStationName;\n\n public WTS_CONNECTSTATE_CLASS State;\n }\n\n public enum WTS_INFO_CLASS\n {\n WTSInitialProgram,\n WTSApplicationName,\n WTSWorkingDirectory,\n WTSOEMId,\n WTSSessionId,\n WTSUserName,\n WTSWinStationName,\n WTSDomainName,\n WTSConnectState,\n WTSClientBuildNumber,\n WTSClientName,\n WTSClientDirectory,\n WTSClientProductId,\n WTSClientHardwareId,\n WTSClientAddress,\n WTSClientDisplay,\n WTSClientProtocolType\n }\n\n public enum WTS_CONNECTSTATE_CLASS\n {\n WTSActive,\n WTSConnected,\n WTSConnectQuery,\n WTSShadow,\n WTSDisconnected,\n WTSIdle,\n WTSListen,\n WTSReset,\n WTSDown,\n WTSInit\n }\n\n static void Main(string[] args)\n {\n ListUsers(Environment.MachineName);\n }\n\n public static void ListUsers(string serverName)\n {\n IntPtr serverHandle = IntPtr.Zero;\n List<string> resultList = new List<string>();\n serverHandle = WTSOpenServer(serverName);\n\n try\n {\n IntPtr sessionInfoPtr = IntPtr.Zero;\n IntPtr userPtr = IntPtr.Zero;\n IntPtr domainPtr = IntPtr.Zero;\n Int32 sessionCount = 0;\n Int32 retVal = WTSEnumerateSessions(serverHandle, 0, 1, ref sessionInfoPtr, ref sessionCount);\n Int32 dataSize = Marshal.SizeOf(typeof(WTS_SESSION_INFO));\n IntPtr currentSession = sessionInfoPtr;\n uint bytes = 0;\n\n if (retVal != 0)\n {\n for (int i = 0; i < sessionCount; i++)\n {\n WTS_SESSION_INFO si = (WTS_SESSION_INFO)Marshal.PtrToStructure((System.IntPtr)currentSession, typeof(WTS_SESSION_INFO));\n currentSession += dataSize;\n\n WTSQuerySessionInformation(serverHandle, si.SessionID, WTS_INFO_CLASS.WTSUserName, out userPtr, out bytes);\n WTSQuerySessionInformation(serverHandle, si.SessionID, WTS_INFO_CLASS.WTSDomainName, out domainPtr, out bytes);\n\n Console.WriteLine(\"Domain and User: \" + Marshal.PtrToStringAnsi(domainPtr) + \"\\\\\" + Marshal.PtrToStringAnsi(userPtr));\n\n WTSFreeMemory(userPtr); \n WTSFreeMemory(domainPtr);\n }\n\n WTSFreeMemory(sessionInfoPtr);\n }\n }\n finally\n {\n WTSCloseServer(serverHandle);\n }\n\n }\n\n }\n}\n" }, { "answer_id": 809906, "author": "Dan Ports", "author_id": 88885, "author_profile": "https://Stackoverflow.com/users/88885", "pm_score": 5, "selected": false, "text": "using System;\nusing System.Security.Principal;\nusing Cassia;\n\nnamespace CassiaSample\n{\n public static class Program\n {\n public static void Main(string[] args)\n {\n ITerminalServicesManager manager = new TerminalServicesManager();\n using (ITerminalServer server = manager.GetRemoteServer(\"your-server-name\"))\n {\n server.Open();\n foreach (ITerminalServicesSession session in server.GetSessions())\n {\n NTAccount account = session.UserAccount;\n if (account != null)\n {\n Console.WriteLine(account);\n }\n }\n }\n }\n }\n}\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132620", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7837/" ]
132,643
<p>I have a this aspx-code: (sample)</p> <pre><code>&lt;asp:DropDownList runat="server" ID="ddList1"&gt;&lt;/asp:DropDownList&gt; </code></pre> <p>With this codebehind:</p> <pre><code>List&lt;System.Web.UI.WebControls.ListItem&gt; colors = new List&lt;System.Web.UI.WebControls.ListItem&gt;(); colors.Add(new ListItem("Select Value", "0")); colors.Add(new ListItem("Red", "1")); colors.Add(new ListItem("Green", "2")); colors.Add(new ListItem("Blue", "3")); ddList1.DataSource = colors; ddList1.DataBind(); </code></pre> <p>The output looks like this:</p> <pre><code>&lt;select name="ddList1" id="ddList1"&gt; &lt;option value="Select Value"&gt;Select Value&lt;/option&gt; &lt;option value="Red"&gt;Red&lt;/option&gt; &lt;option value="Green"&gt;Green&lt;/option&gt; &lt;option value="Blue"&gt;Blue&lt;/option&gt; &lt;/select&gt; </code></pre> <p>My question is: Why did my values (numbers) disappear and the text used as the value AND the text? I know that it works if I use the <code>ddList1.Items.Add(New ListItem("text", "value"))</code> method, but I need to use a generic list as the datasource for other reasons.</p>
[ { "answer_id": 132731, "author": "Serhat Ozgel", "author_id": 31505, "author_profile": "https://Stackoverflow.com/users/31505", "pm_score": 2, "selected": false, "text": "protected internal override void PerformDataBinding(IEnumerable dataSource)\n{\n base.PerformDataBinding(dataSource);\n if (dataSource != null)\n {\n bool flag = false;\n bool flag2 = false;\n string dataTextField = this.DataTextField;\n string dataValueField = this.DataValueField;\n string dataTextFormatString = this.DataTextFormatString;\n if (!this.AppendDataBoundItems)\n {\n this.Items.Clear();\n }\n ICollection is2 = dataSource as ICollection;\n if (is2 != null)\n {\n this.Items.Capacity = is2.Count + this.Items.Count;\n }\n if ((dataTextField.Length != 0) || (dataValueField.Length != 0))\n {\n flag = true;\n }\n if (dataTextFormatString.Length != 0)\n {\n flag2 = true;\n }\n foreach (object obj2 in dataSource)\n {\n ListItem item = new ListItem();\n if (flag)\n {\n if (dataTextField.Length > 0)\n {\n item.Text = DataBinder.GetPropertyValue(obj2, dataTextField, dataTextFormatString);\n }\n if (dataValueField.Length > 0)\n {\n item.Value = DataBinder.GetPropertyValue(obj2, dataValueField, null);\n }\n }\n else\n {\n if (flag2)\n {\n item.Text = string.Format(CultureInfo.CurrentCulture, dataTextFormatString, new object[] { obj2 });\n }\n else\n {\n item.Text = obj2.ToString();\n }\n item.Value = obj2.ToString();\n }\n this.Items.Add(item);\n }\n }\n if (this.cachedSelectedValue != null)\n {\n int num = -1;\n num = this.Items.FindByValueInternal(this.cachedSelectedValue, true);\n if (-1 == num)\n {\n throw new ArgumentOutOfRangeException(\"value\", SR.GetString(\"ListControl_SelectionOutOfRange\", new object[] { this.ID, \"SelectedValue\" }));\n }\n if ((this.cachedSelectedIndex != -1) && (this.cachedSelectedIndex != num))\n {\n throw new ArgumentException(SR.GetString(\"Attributes_mutually_exclusive\", new object[] { \"SelectedIndex\", \"SelectedValue\" }));\n }\n this.SelectedIndex = num;\n this.cachedSelectedValue = null;\n this.cachedSelectedIndex = -1;\n }\n else if (this.cachedSelectedIndex != -1)\n {\n this.SelectedIndex = this.cachedSelectedIndex;\n this.cachedSelectedIndex = -1;\n }\n}\n" }, { "answer_id": 132741, "author": "Filini", "author_id": 21162, "author_profile": "https://Stackoverflow.com/users/21162", "pm_score": 2, "selected": false, "text": "\n\nddList1.Items.Add(new ListItem(\"Select Value\", \"0\"));\nddList1.Items.Add(new ListItem(\"Red\", \"1\"));\nddList1.Items.Add(new ListItem(\"Green\", \"2\"));\nddList1.Items.Add(new ListItem(\"Blue\", \"3\"));\n\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132643", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2257/" ]
132,649
<p>What is the difference between overflow:hidden and display:none?</p>
[ { "answer_id": 132677, "author": "Vincent McNabb", "author_id": 16299, "author_profile": "https://Stackoverflow.com/users/16299", "pm_score": 1, "selected": false, "text": "div overflow: hidden; display: none div div display: none; overflow: hidden; div div display: none; overflow: hidden; height: 0; width" }, { "answer_id": 132679, "author": "ConroyP", "author_id": 2287, "author_profile": "https://Stackoverflow.com/users/2287", "pm_score": 3, "selected": false, "text": "display: none overflow: hidden overflow: hidden" }, { "answer_id": 132681, "author": "PhiLho", "author_id": 15459, "author_profile": "https://Stackoverflow.com/users/15459", "pm_score": 6, "selected": true, "text": ".oh\n{\n height: 50px;\n width: 200px;\n overflow: hidden;\n}\n display: none; visibility: hidden;" }, { "answer_id": 132686, "author": "kemiller2002", "author_id": 1942, "author_profile": "https://Stackoverflow.com/users/1942", "pm_score": 1, "selected": false, "text": "<span>test</span> | <span>Appropriate style in this tag</span> | <span>test</span>\n" }, { "answer_id": 134713, "author": "Paul D. Waite", "author_id": 20578, "author_profile": "https://Stackoverflow.com/users/20578", "pm_score": 2, "selected": false, "text": "<p>This is an example paragraph. It has some text in it to try and give it a reasonable height. In a separate style sheet, we’re going to give it a blue background and a fixed height. If we add overflow: hidden, we won’t see any text that extends beyond the fixed height of the paragraph. Until then, the text will “overflow” the paragraph, extending beyond the blue background.</p>\n\np {\n background-color: #ccf;\n height: 20px;\n}\n overflow overflow: hidden p {\n background-color: #ccf;\n height: 20px;\n overflow: hidden;\n}\n display: none" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132649", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21067/" ]
132,667
<p>While developing a C++ application, I had to use a third-party library which produced a huge amount of warnings related with a harmless #pragma directive being used.</p> <pre class="lang-none prettyprint-override"><code>../File.hpp:1: warning: ignoring #pragma ident In file included from ../File2.hpp:47, from ../File3.hpp:57, from File4.h:49, </code></pre> <p>Is it possible to disable this kind of warnings, when using the GNU C++ compiler?</p>
[ { "answer_id": 132730, "author": "Adam Wright", "author_id": 1200, "author_profile": "https://Stackoverflow.com/users/1200", "pm_score": 8, "selected": true, "text": "-Wno-unknown-pragmas\n" }, { "answer_id": 132732, "author": "Mike Dimmick", "author_id": 6970, "author_profile": "https://Stackoverflow.com/users/6970", "pm_score": 4, "selected": false, "text": "-Wall -Wunknown-pragmas" }, { "answer_id": 133521, "author": "Airsource Ltd", "author_id": 18017, "author_profile": "https://Stackoverflow.com/users/18017", "pm_score": 5, "selected": false, "text": "#pragma warning (disable : 4068 ) /* disable unknown pragma warnings */\n" }, { "answer_id": 11686608, "author": "pamplemousse_mk2", "author_id": 796054, "author_profile": "https://Stackoverflow.com/users/796054", "pm_score": 3, "selected": false, "text": "QMAKE_CXXFLAGS_WARN_ON += -Wno-unknown-pragmas\n" }, { "answer_id": 49834787, "author": "nemequ", "author_id": 501126, "author_profile": "https://Stackoverflow.com/users/501126", "pm_score": 4, "selected": false, "text": "-Wno-unknown-pragmas #pragma GCC diagnostic ignored \"-Wunknown-pragmas\" -Wno-unknown-pragmas #pragma clang diagnostic ignored \"-Wunknown-pragmas\" -diag-disable 161 #pragma warning(disable:161) #pragma diag_suppress 1675 -wd4068 #pragma warning(disable:4068) --diag_suppress,-pds=163 #pragma diag_suppress 163 --diag_suppress Pe161 #pragma diag_suppress=Pe161 -w17 -h nomessage=1234 HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS #if HEDLEY_HAS_WARNING(\"-Wunknown-pragmas\")\n# define HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma(\"clang diagnostic ignored \\\"-Wunknown-pragmas\\\"\")\n#elif HEDLEY_INTEL_VERSION_CHECK(16,0,0)\n# define HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma(\"warning(disable:161)\")\n#elif HEDLEY_PGI_VERSION_CHECK(17,10,0)\n# define HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma(\"diag_suppress 1675\")\n#elif HEDLEY_GNUC_VERSION_CHECK(4,3,0)\n# define HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma(\"GCC diagnostic ignored \\\"-Wunknown-pragmas\\\"\")\n#elif HEDLEY_MSVC_VERSION_CHECK(15,0,0)\n# define HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:4068))\n#elif HEDLEY_TI_VERSION_CHECK(8,0,0)\n# define HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma(\"diag_suppress 163\")\n#elif HEDLEY_IAR_VERSION_CHECK(8,0,0)\n# define HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma(\"diag_suppress=Pe161\")\n#else\n# define HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS\n#endif\n HEDLEY_DIAGNOSTIC_PUSH HEDLEY_DIAGNOSTIC_POP" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132667", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20317/" ]
132,685
<p>When setting the size of fonts in CSS, should I be using a percent value (<code>%</code>) or <code>em</code>? Can you explain the advantage?</p>
[ { "answer_id": 1723471, "author": "DA.", "author_id": 172279, "author_profile": "https://Stackoverflow.com/users/172279", "pm_score": 3, "selected": false, "text": "px % em % px em" }, { "answer_id": 13840233, "author": "user743436", "author_id": 743436, "author_profile": "https://Stackoverflow.com/users/743436", "pm_score": 0, "selected": false, "text": "% em em 100 em % \"Liam, answered Sep 25 '08 at 11:21\"" }, { "answer_id": 51404023, "author": "Björn Tantau", "author_id": 2695799, "author_profile": "https://Stackoverflow.com/users/2695799", "pm_score": 4, "selected": false, "text": "padding 1em 100% em %" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132685", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16440/" ]
132,719
<p>I have a Visual Studio (2008) solution consisting of several projects, not all in the same namespace. When I build the solution, all the DLL files used by the top level project, <strong>TopProject</strong>, are copied into the <em>TopProject\bin\debug</em> folder. However, the corresponding .pdb files are only copied for some of the other projects. This is a pain, for example when using <a href="http://www.ndepend.com/" rel="nofollow noreferrer">NDepend</a>.</p> <p>How does Visual Studio decide which .pdb files to copy into higher level bin\debug folders? How can I get Visual Studio to copy the others too?</p> <hr> <p>References are as follows: all the DLL files are copied to a central location, without their PDB files. <strong>TopProject</strong> <em>only</em> has references to these copied DLL files; the DLL files themselves, however, evidently know where their PDB files are, and (most of them) get copied to the <code>debug</code> folder correctly.</p>
[ { "answer_id": 132899, "author": "Code Trawler", "author_id": 22073, "author_profile": "https://Stackoverflow.com/users/22073", "pm_score": 2, "selected": false, "text": "bin\\debug bin\\debug" }, { "answer_id": 132909, "author": "Dean Hill", "author_id": 3106, "author_profile": "https://Stackoverflow.com/users/3106", "pm_score": 2, "selected": false, "text": "xcopy /r /y $(TargetPath) $(ProjectDir)..\\$(OutDir)\nif $(ConfigurationName) == Debug xcopy /r /y $(TargetDir)$(TargetName).pdb $(ProjectDir)..\\$(OutDir)\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132719", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6091/" ]
132,720
<p>We have consumed a third party web service and are trying to invoke it from an ASP.NET web application. However when I instantiate the web service the following System.InvalidOperationException exception is thrown:</p> <blockquote> <p>Method 'ABC.XYZ' can not be reflected. System.InvalidOperationException: Method 'ABC.XYZ' can not be reflected. ---> System.InvalidOperationException: The XML element 'MyDoc' from namespace '<a href="http://mysoftware.com/ns" rel="noreferrer">http://mysoftware.com/ns</a>' references a method and a type. Change the method's message name using WebMethodAttribute or change the type's root element using the XmlRootAttribute.</p> </blockquote> <p>From what I can gather there appears to be some ambiguity between a method and a type in the web service. Can anyone clarify the probably cause of this exception and is there anything I can do to rectify this or should I just go to the web service owners to rectify?</p> <p>Edit: Visual Studio 2008 has created the proxy class. Unfortunately I can't provide a link to the wsdl as it is a web service for a locally installed thrid party app.</p>
[ { "answer_id": 17563323, "author": "Has AlTaiar", "author_id": 1570662, "author_profile": "https://Stackoverflow.com/users/1570662", "pm_score": 0, "selected": false, "text": "WebMethod interface VS disco" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132720", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1762/" ]
132,725
<p>I'm new to Delphi, and I've been running some tests to see what object variables and stack variables are initialized to by default:</p> <pre><code>TInstanceVariables = class fBoolean: boolean; // always starts off as false fInteger: integer; // always starts off as zero fObject: TObject; // always starts off as nil end; </code></pre> <p>This is the behaviour I'm used to from other languages, but I'm wondering if it's safe to rely on it in Delphi? For example, I'm wondering if it might depend on a compiler setting, or perhaps work differently on different machines. Is it normal to rely on default initialized values for objects, or do you explicitly set all instance variables in the constructor?</p> <p>As for stack (procedure-level) variables, my tests are showing that unitialized booleans are true, unitialized integers are 2129993264, and uninialized objects are just invalid pointers (i.e. not nil). I'm guessing the norm is to always set procedure-level variables before accessing them?</p>
[ { "answer_id": 132770, "author": "Giacomo Degli Esposti", "author_id": 20796, "author_profile": "https://Stackoverflow.com/users/20796", "pm_score": 8, "selected": true, "text": "string, variant, interface record" }, { "answer_id": 495493, "author": "Heinrich Ulbricht", "author_id": 56658, "author_profile": "https://Stackoverflow.com/users/56658", "pm_score": 4, "selected": false, "text": "var myGlobal:integer=99;\n" }, { "answer_id": 63266758, "author": "Jacek Krawczyk", "author_id": 1960514, "author_profile": "https://Stackoverflow.com/users/1960514", "pm_score": 2, "selected": false, "text": "procedure TestInlineVariable;\nbegin\n var index: Integer := 345;\n ShowMessage(index.ToString);\nend;\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132725", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11961/" ]
132,738
<p>I'm a C/C++ developer, and here are a couple of questions that always baffled me.</p> <ul> <li>Is there a big difference between "regular" code and inline code?</li> <li>Which is the main difference?</li> <li>Is inline code simply a "form" of macros?</li> <li>What kind of tradeoff must be done when choosing to inline your code?</li> </ul> <p>Thanks</p>
[ { "answer_id": 132759, "author": "Charles Duffy", "author_id": 14122, "author_profile": "https://Stackoverflow.com/users/14122", "pm_score": 1, "selected": false, "text": "inline" }, { "answer_id": 132776, "author": "QBziZ", "author_id": 11572, "author_profile": "https://Stackoverflow.com/users/11572", "pm_score": 0, "selected": false, "text": "CPoint\n{\n public:\n\n inline int x() const { return m_x ; }\n inline int y() const { return m_y ; }\n\n private:\n int m_x ;\n int m_y ;\n\n};\n" }, { "answer_id": 132915, "author": "Luc Touraille", "author_id": 20984, "author_profile": "https://Stackoverflow.com/users/20984", "pm_score": 6, "selected": true, "text": "#define unsafe(i) ( (i) >= 0 ? (i) : -(i) )\n\n[...]\nunsafe(x++); // x is incremented twice!\nunsafe(f()); // f() is called twice!\n[...]\n" }, { "answer_id": 133426, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 5, "selected": false, "text": "inline inline inline inline static inline // header.hpp\n#ifndef HEADER_HPP\n#define HEADER_HPP\n\n#include <cmath>\n#include <numeric>\n#include <vector>\n\nusing vec = std::vector<double>;\n\n/*inline*/ double mean(vec const& sample) {\n return std::accumulate(begin(sample), end(sample), 0.0) / sample.size();\n}\n\n#endif // !defined(HEADER_HPP)\n // test.cpp\n#include \"header.hpp\"\n\n#include <iostream>\n#include <iomanip>\n\nvoid print_mean(vec const& sample) {\n std::cout << \"Sample with x̂ = \" << mean(sample) << '\\n';\n}\n // main.cpp\n#include \"header.hpp\"\n\nvoid print_mean(vec const&); // Forward declaration.\n\nint main() {\n vec x{4, 3, 5, 4, 5, 5, 6, 3, 8, 6, 8, 3, 1, 7};\n print_mean(x);\n}\n .cpp mean ⟩⟩⟩ g++ -std=c++11 -pedantic main.cpp test.cpp\n mean inline" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132738", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20317/" ]
132,750
<p>I'm a jQuery novice, so the answer to this may be quite simple:</p> <p>I have an image, and I would like to do several things with it. When a user clicks on a 'Zoom' icon, I'm running the 'imagetool' plugin (<a href="http://code.google.com/p/jquery-imagetool/" rel="nofollow noreferrer">http://code.google.com/p/jquery-imagetool/</a>) to load a larger version of the image. The plugin creates a new div around the image and allows the user to pan around.</p> <p>When a user clicks on an alternative image, I'm removing the old one and loading in the new one.</p> <p>The problem comes when a user clicks an alternative image, and then clicks on the zoom button - the imagetool plugin creates the new div, but the image appears after it...</p> <p>The code is as follows:</p> <pre><code>// Product Zoom (jQuery) $(document).ready(function(){ $("#productZoom").click(function() { // Set new image src var imageSrc = $("#productZoom").attr("href"); $("#productImage").attr('src', imageSrc); // Run the imagetool plugin on the image $(function() { $("#productImage").imagetool({ viewportWidth: 300, viewportHeight: 300, topX: 150, topY: 150, bottomX: 450, bottomY: 450 }); }); return false; }); }); // Alternative product photos (jQuery) $(document).ready(function(){ $(".altPhoto").click(function() { $('#productImageDiv div.viewport').remove(); $('#productImage').remove(); // Set new image src var altImageSrc = $(this).attr("href"); $("#productZoom").attr('href', altImageSrc); var img = new Image(); $(img).load(function () { $(this).hide(); $('#productImageDiv').append(this); $(this).fadeIn(); }).error(function () { // notify the user that the image could not be loaded }).attr({ src: altImageSrc, id: "productImage" }); return false; }); }); </code></pre> <p>It seems to me, that the imagetool plugin can no longer see the #productImage image once it has been replaced with a new image... So I think this has something to do with binding? As in because the new image is added to the dom after the page has loaded, the iamgetool plugin can no longer use it correctly... is this right? If so, any ideas how to deal with it?</p>
[ { "answer_id": 132795, "author": "Adam Bellaire", "author_id": 21632, "author_profile": "https://Stackoverflow.com/users/21632", "pm_score": 1, "selected": false, "text": "// Product Zoom (jQuery)\n$(document).ready(function(){\n$(\"#productZoom\").click(bindZoom);\n\n// Alternative product photos (jQuery)\n$(\".altPhoto\").click(function() {\n\n $('#productImageDiv div.viewport').remove();\n $('#productImage').remove();\n\n // Set new image src\n var altImageSrc = $(this).attr(\"href\");\n\n $(\"#productZoom\").attr('href', altImageSrc);\n\n var img = new Image();\n $(img).load(function () {\n $(this).hide();\n $('#productImageDiv').append(this);\n $(this).fadeIn();\n }).error(function () {\n // notify the user that the image could not be loaded\n }).attr({\n src: altImageSrc,\n id: \"productImage\"\n });\n $(\"#productZoom\").click(bindZoom);\n return false;\n\n}); \n});\n\nfunction bindZoom() {\n // Set new image src\n var imageSrc = $(\"#productZoom\").attr(\"href\");\n $(\"#productImage\").attr('src', imageSrc); \n\n // Run the imagetool plugin on the image\n $(function() {\n $(\"#productImage\").imagetool({\n viewportWidth: 300,\n viewportHeight: 300,\n topX: 150,\n topY: 150,\n bottomX: 450,\n bottomY: 450\n });\n });\n return false;\n}\n" }, { "answer_id": 132916, "author": "Juan", "author_id": 550, "author_profile": "https://Stackoverflow.com/users/550", "pm_score": 0, "selected": false, "text": "var altImageSrc = $(this).attr(\"href\");\n var altImageSrc = $(this).attr(\"src\");\n" }, { "answer_id": 133579, "author": "Gary Stanton", "author_id": 22113, "author_profile": "https://Stackoverflow.com/users/22113", "pm_score": 4, "selected": true, "text": "$(document).ready(function(){\n\n // Product Zoom (jQuery)\n $(\"#productZoom\").click(function() {\n\n $('#productImage').remove();\n $('#productImageDiv').html('<img src=\"\" id=\"productImage\">');\n\n // Set new image src\n var imageSrc = $(\"#productZoom\").attr(\"href\");\n $(\"#productImage\").attr('src', imageSrc); \n\n // Run the imagetool plugin on the image\n $(function() {\n $(\"#productImage\").imagetool({\n viewportWidth: 300,\n viewportHeight: 300,\n topX: 150,\n topY: 150,\n bottomX: 450,\n bottomY: 450\n });\n });\n\n return false;\n });\n\n\n // Alternative product photos (jQuery)\n $(\".altPhoto\").click(function() {\n\n $('#productImageDiv div.viewport').remove();\n $('#productImage').remove();\n\n // Set new image src\n var altImageSrc = $(this).attr(\"href\");\n\n // Set new image Zoom link (from the ID... is that messy?)\n var altZoomLink = $(this).attr(\"id\");\n\n $(\"#productZoom\").attr('href', altZoomLink);\n\n var img = new Image();\n $(img).load(function () {\n $(this).hide();\n $('#productImageDiv').append(this);\n $(this).fadeIn();\n }).error(function () {\n // notify the user that the image could not be loaded\n }).attr({\n src: altImageSrc,\n id: \"productImage\"\n });\n\n return false; \n });\n});\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132750", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22113/" ]
132,754
<p>I have a bunch of JSP files and backend in Tomcat. I have 3 different versions of JSP with same logic inside but with different layouts. So if I change some logic I have three JSP file to fix.</p> <p>What is the proper soution for such a scenario? I thought of some XML and XSLT stack: backend gives only data in XML and than for each layout I have XSLT that does some magic. </p> <p>Just imagine that you need to provide stackoverflow in various languages in JSP. Logic the same but layout different.</p> <p>Could you point me into some direction?</p>
[ { "answer_id": 132862, "author": "kosoant", "author_id": 15114, "author_profile": "https://Stackoverflow.com/users/15114", "pm_score": 1, "selected": false, "text": " <jsp-property-group>\n <url-pattern>/customers/*</url-pattern>\n <include-prelude>/shared/layout/_layout_customers_top.jsp</include-prelude>\n <include-coda>/shared/layout/_layout_customers_bottom.jsp</include-coda>\n </jsp-property-group>\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132754", "https://Stackoverflow.com", "https://Stackoverflow.com/users/501/" ]
132,764
<p>In our CMS, we have a place in which we enable users to play around with their site hierarchy - move pages around, add and remove pages, etc.</p> <p>We use drag &amp; drop to implement moving pages around. </p> <p>Each move has to saved in th DB, and exported to many HTML files. If we do that in every move, it will slow down the users. Therefore we thought that it's preferable to let the users play around as much as they want, saving each change to the DB, but only when they leave the page - to export their changes to the HTML files. </p> <p>We thought of making the user click a "publish" button when they're ready to commit their changes, but we're afraid users won't remember to do that, because from their stand point once they've moved a page to a new place - the action is done. Another problem with the button is that it's inconsistent with the behavior of the other parts of the site (for example, when a user moves a text inside a page, the changes are saved automatically, as there is only 1 HTML file to update)</p> <p>So how can we automatically save user changes on leaving the page?</p>
[ { "answer_id": 132775, "author": "Espo", "author_id": 2257, "author_profile": "https://Stackoverflow.com/users/2257", "pm_score": 3, "selected": true, "text": "<SCRIPT LANGUAGE=\"JavaScript1.2\" TYPE=\"text/javascript\">\n<!--\nfunction unloadMess(){\n mess = \"Wait! You haven't finished.\"\n return mess;\n}\n\nfunction setBunload(on){\n window.onbeforeunload = (on) ? unloadMess : null;\n}\n\nsetBunload(true);\n//-->\n</SCRIPT>\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132764", "https://Stackoverflow.com", "https://Stackoverflow.com/users/278/" ]
132,799
<p>How can you you insert a newline from your batch file output?</p> <p>I want to do something like:</p> <pre class="lang-bat prettyprint-override"><code>echo hello\nworld </code></pre> <p>Which would output:</p> <pre class="lang-bat prettyprint-override"><code>hello world </code></pre>
[ { "answer_id": 132804, "author": "Matt Lacey", "author_id": 1755, "author_profile": "https://Stackoverflow.com/users/1755", "pm_score": 9, "selected": false, "text": "echo hello\necho:\necho world\n" }, { "answer_id": 132811, "author": "Grimtron", "author_id": 17378, "author_profile": "https://Stackoverflow.com/users/17378", "pm_score": 10, "selected": true, "text": "echo hello & echo.world & echo. \\n" }, { "answer_id": 269819, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 7, "selected": false, "text": "@echo off\nREM Creating a Newline variable (the two blank lines are required!)\nset NLM=^\n\n\nset NL=^^^%NLM%%NLM%^%NLM%%NLM%\nREM Example Usage:\necho There should be a newline%NL%inserted here.\n\necho.\npause\n There should be a newline\ninserted here.\n\nPress any key to continue . . .\n" }, { "answer_id": 2388384, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 4, "selected": false, "text": "@echo off\nset newline=^& echo.\necho hello %newline%world\n C:\\>test.bat\nhello\nworld\n" }, { "answer_id": 2959200, "author": "NahuelGQ", "author_id": 356604, "author_profile": "https://Stackoverflow.com/users/356604", "pm_score": 1, "selected": false, "text": "@echo off\n(\necho ^<html^> \necho ^<body^>\necho Hello\necho ^</body^>\necho ^</html^>\n)\npause\n <html>\n<body>\nHello\n</body>\n</html>\nPress any key to continue . . .\n" }, { "answer_id": 3123194, "author": "macropas", "author_id": 40220, "author_profile": "https://Stackoverflow.com/users/40220", "pm_score": 7, "selected": false, "text": "echo: @echo off\necho line1\necho:\necho line2\n @echo line1 & echo: & echo line2\n line1\n\nline2\n" }, { "answer_id": 6379940, "author": "jeb", "author_id": 463115, "author_profile": "https://Stackoverflow.com/users/463115", "pm_score": 6, "selected": false, "text": "setlocal EnableDelayedExpansion\n(set \\n=^\n%=Do not remove this line=%\n)\n\necho Line1!\\n!Line2\necho Works also with quotes \"!\\n!line2\"\n echo Line1%LF%Line2 echo. echo echo. echo. ECHO echo,\necho;\necho(\necho/\necho+\necho=\n echo. echo\\ echo:" }, { "answer_id": 7488943, "author": "albert", "author_id": 623740, "author_profile": "https://Stackoverflow.com/users/623740", "pm_score": 3, "selected": false, "text": "(for %i in (a b \"c d\") do @echo %~i)\n a\nb\nc d\n (for %%i in (a b \"c d\") do @echo %%~i)\n" }, { "answer_id": 16139681, "author": "Wayne Uroda", "author_id": 588476, "author_profile": "https://Stackoverflow.com/users/588476", "pm_score": 3, "selected": false, "text": "@cmd /c echo. echo. process_begin: CreateProcess(NULL, echo., ...) failed." }, { "answer_id": 17724688, "author": "johan d", "author_id": 1774001, "author_profile": "https://Stackoverflow.com/users/1774001", "pm_score": 0, "selected": false, "text": "@echo" }, { "answer_id": 24792710, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 6, "selected": false, "text": "echo. & echo Line 1 & echo. & echo line 3\n Line 1\n\nline 3\n set n=^&echo.\necho hello %n% world\n hello\nworld\n %n% \\n set n= n ^ & && echo. set t=^&echo. ::there are spaces up to the double colon\n" }, { "answer_id": 25614175, "author": "test30", "author_id": 781312, "author_profile": "https://Stackoverflow.com/users/781312", "pm_score": 4, "selected": false, "text": "(echo a & echo: & echo b) > file_containing_multiple_lines.txt\n" }, { "answer_id": 39794980, "author": "otaviodecampos", "author_id": 2588819, "author_profile": "https://Stackoverflow.com/users/2588819", "pm_score": 2, "selected": false, "text": "TYPE file.txt | FIND \"\" /V > file_win.txt\ndel file.txt\nrename file_win.txt file.txt\n" }, { "answer_id": 41192035, "author": "PryroTech", "author_id": 6890856, "author_profile": "https://Stackoverflow.com/users/6890856", "pm_score": 2, "selected": false, "text": "echo Hi!\necho[\necho Hello!\n" }, { "answer_id": 48682383, "author": "Tomator", "author_id": 8214796, "author_profile": "https://Stackoverflow.com/users/8214796", "pm_score": 2, "selected": false, "text": "@echo off\nset input=%1\nif defined input (\n set answer=Hi!\\nWhy did you call me a %input%?\n) else (\n set answer=Hi!\\nHow are you?\\nWe are friends, you know?\\nYou can call me by name.\n)\n\nsetlocal enableDelayedExpansion\nset newline=^\n\n\nrem Two empty lines above are essential\necho %answer:\\n=!newline!%\n call:mlecho Hi\\nI'm your comuter :mlecho\nsetlocal enableDelayedExpansion\nset text=%*\nset nl=^\n\n\necho %text:\\n=!nl!%\ngoto:eof\n" }, { "answer_id": 64208278, "author": "Io-oI", "author_id": 8177207, "author_profile": "https://Stackoverflow.com/users/8177207", "pm_score": 2, "selected": false, "text": "echo; set \"_line=hello world\"\necho\\%_line: =&echo;%\n hello\nworld\n echo; set \"_line=hello\\nworld\"\necho\\%_line:\\n=&echo;%\n" }, { "answer_id": 67328035, "author": "Pear", "author_id": 15782472, "author_profile": "https://Stackoverflow.com/users/15782472", "pm_score": 0, "selected": false, "text": "set nl=.\necho hello\necho%nl%\nREM without space ^^^\necho World\n hello\nworld\n" }, { "answer_id": 67876469, "author": "T3RR0R", "author_id": 12343998, "author_profile": "https://Stackoverflow.com/users/12343998", "pm_score": 2, "selected": false, "text": "@Echo off\n For /f %%a in ('echo prompt $E^| cmd')Do set \\E=%%a\n <nul set /p \"=Hello%\\E%[EWorld\"\n n n <nul set /p \"=%\\E%[nE\"\n" }, { "answer_id": 69789865, "author": "Vopel", "author_id": 11777065, "author_profile": "https://Stackoverflow.com/users/11777065", "pm_score": 0, "selected": false, "text": "<ESC> :: Replace <ESC> with the 0x1b escape character or copy from this Pastebin:\n:: https://pastebin.com/xLWKTQZQ\n\necho Hello<ESC>[Eworld!\n\n:: OR\n\nset \"\\n=<ESC>[E\"\necho Hello%\\n%world!\n" }, { "answer_id": 70119385, "author": "Gerold Broser", "author_id": 1744774, "author_profile": "https://Stackoverflow.com/users/1744774", "pm_score": 2, "selected": false, "text": "CR CRLF" }, { "answer_id": 70122012, "author": "Gerold Broser", "author_id": 1744774, "author_profile": "https://Stackoverflow.com/users/1744774", "pm_score": 2, "selected": false, "text": "= ^ :: Sets newline variables in the current CMD session\nset \\n=​^&echo:\nset nl=​^&echo:\n ␣ ^ :: Sets newline variables for the current user [HKEY_CURRENT_USER\\Environment]\nsetx \\n ​^&echo:\nsetx nl ​^&echo:\n ␣ ^ :: Sets newline variables for the local machine [HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment]\nsetx \\n ​^&echo: /m \nsetx nl ​^&echo: /m \n \"\"echo %\\n%...after \"newline\". Before \"newline\"...%\\n%...after \"newline\" echo %\\n%...after newline. Before newline...%\\n%...after newline\" echo \"%\\n%...after newline. Before newline...%\\n%...after newline\" set BEGIN_QUOTE=echo ^| set /p !=\"\"\"\n...\n%BEGIN_QUOTE%\necho %\\n%...after newline. Before newline...%\\n%...after newline\"\n echo '%\\n%...after newline. Before newline...%\\n%...after newline'\n = :: Escape character - useful for color codes when 'echo'ing\n:: See https://learn.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences#text-formatting\nset ESC=\n set NLM=^\n\n\nset NL=^^^%NLM%%NLM%^%NLM%%NLM%\n = ^ set nl=^&echo:\nset \\n=^&echo:\n echo > echo %\\n%Hello%\\n%World!\necho & echo:Hello & echo:World!\necho is ON.\nHello\nWorld\n echo echo set \\n=^&echo: E2 80 8A E2 80 8B \\n" }, { "answer_id": 70933083, "author": "RLH", "author_id": 1742115, "author_profile": "https://Stackoverflow.com/users/1742115", "pm_score": 0, "selected": false, "text": "@echo off\nSETLOCAL ENABLEDELAYEDEXPANSION\n:: the two blank lines are required!\nset NLM=^\n\n\nset NL=^^^%NLM%%NLM%^%NLM%%NLM%\n:: Example Usage:\n\nSet ErrMsg=Start Reporting:\n:: some logic here finds an error condition and appends the error report\nset ErrMsg=!ErrMsg!!NL!Error Title1!NL!Description!NL!Summary!NL!\n\n:: some logic here finds another error condition and appends the error report\nset ErrMsg=!ErrMsg!!NL!Error Title2!NL!Description!NL!Summary!NL!\n\n:: some logic here finds another error condition and appends the error report\nset ErrMsg=!ErrMsg!!NL!Error Title3!NL!Description!NL!Summary!NL!\n\necho %ErrMsg%\npause\necho %ErrMsg% > MyLogFile.log\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132799", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3153/" ]
132,812
<p>I created a report model using SSRS (2005) and published to the local server. But when I tried to run the report for the model I published using report builder I get the following error. </p> <blockquote> <p>Report execution error:The permissions granted to user are insufficient for performing this operation. (rsAccessDenied) </p> </blockquote>
[ { "answer_id": 1325291, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "rs.accessdenied" }, { "answer_id": 22348375, "author": "Ajay", "author_id": 3410149, "author_profile": "https://Stackoverflow.com/users/3410149", "pm_score": 2, "selected": false, "text": "Open localhost/reports\nGo to properties tab (SSRS 2008)\nSecurity->New Role Assignment\nAdd DOMAIN/USERNAME or DOMAIN/USERGROUP\nCheck Report builder\n" }, { "answer_id": 24647247, "author": "Atur", "author_id": 347652, "author_profile": "https://Stackoverflow.com/users/347652", "pm_score": 3, "selected": false, "text": "http://machinename/reportservername" }, { "answer_id": 40221010, "author": "Dhruv Patel", "author_id": 2198089, "author_profile": "https://Stackoverflow.com/users/2198089", "pm_score": 2, "selected": false, "text": " public class ReportServerCredentials : IReportServerCredentials \n{\n #region Class Members\n private string username;\n private string password;\n private string domain;\n #endregion\n\n #region Constructor\n public ReportServerCredentials()\n {}\n public ReportServerCredentials(string username)\n {\n this.Username = username;\n }\n public ReportServerCredentials(string username, string password)\n {\n this.Username = username;\n this.Password = password;\n }\n public ReportServerCredentials(string username, string password, string domain)\n {\n this.Username = username;\n this.Password = password;\n this.Domain = domain;\n }\n #endregion\n\n #region Properties\n public string Username\n {\n get { return this.username; }\n set { this.username = value; }\n }\n public string Password\n {\n get { return this.password; }\n set { this.password = value; }\n }\n public string Domain\n {\n get { return this.domain; }\n set { this.domain = value; }\n }\n public WindowsIdentity ImpersonationUser\n {\n get { return null; }\n }\n public ICredentials NetworkCredentials\n {\n get\n {\n return new NetworkCredential(Username, Password, Domain);\n }\n }\n #endregion\n\n bool IReportServerCredentials.GetFormsCredentials(out System.Net.Cookie authCookie, out string userName, out string password, out string authority)\n {\n authCookie = null;\n userName = password = authority = null;\n return false;\n }\n}\n ReportViewer rptViewer = new ReportViewer();\n string RptUserName = Convert.ToString(ConfigurationManager.AppSettings[\"SSRSReportUser\"]);\n string RptUserPassword = Convert.ToString(ConfigurationManager.AppSettings[\"SSRSReportUserPassword\"]);\n string RptUserDomain = Convert.ToString(ConfigurationManager.AppSettings[\"SSRSReportUserDomain\"]);\n string SSRSReportURL = Convert.ToString(ConfigurationManager.AppSettings[\"SSRSReportURL\"]);\n string SSRSReportFolder = Convert.ToString(ConfigurationManager.AppSettings[\"SSRSReportFolder\"]);\n\n IReportServerCredentials reportCredentials = new ReportServerCredentials(RptUserName, RptUserPassword, RptUserDomain);\n rptViewer.ServerReport.ReportServerCredentials = reportCredentials;\n rptViewer.ServerReport.ReportServerUrl = new Uri(SSRSReportURL);\n" }, { "answer_id": 54182957, "author": "MovGP0", "author_id": 601990, "author_profile": "https://Stackoverflow.com/users/601990", "pm_score": 2, "selected": false, "text": "http://REPORTSERVERNAME/Reports/Pages/Folder.aspx?ItemPath=%2fDataSources http://REPORTSERVERNAME/Reports/Pages/Folder.aspx?ItemPath=%2fDataSets Folder Settings DataSource DataSet Security Browser" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132812", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14752/" ]
132,857
<p>I have the following layout for my test suite:</p> <p>TestSuite1.cmd:</p> <ol> <li>Run my program</li> <li>Check its return result</li> <li>If the return result is not 0, convert the error to textual output and abort the script. If it succeeds, write out success.</li> </ol> <p>In my single .cmd file, I call my program about 10 times with different input.</p> <p>The problem is that the program that I run 10 times takes several hours to run each time. </p> <p>Is there a way for me to parallelize all of these 10 runnings of my program while still somehow checking the return result and providing a proper output file and while still using a <strong>single</strong> .cmd file and to a single output file?</p>
[ { "answer_id": 132880, "author": "grapefrukt", "author_id": 914, "author_profile": "https://Stackoverflow.com/users/914", "pm_score": 0, "selected": false, "text": "testthingie.cmd >> output.txt\n" }, { "answer_id": 132892, "author": "paxdiablo", "author_id": 14860, "author_profile": "https://Stackoverflow.com/users/14860", "pm_score": 3, "selected": true, "text": ":: intercept sub-calls.\n if \"%1\"==\"test2\" then goto :test2\n\n:: start sub-calls.\n start test1.cmd test2 1\n start test1.cmd test2 2\n start test1.cmd test2 3\n\n:: wait for sub-calls to complete.\n:loop1\n if not exist test2_1.flg goto :loop1\n:loop2\n if not exist test2_2.flg goto :loop2\n:loop3\n if not exist test2_3.flg goto :loop3\n\n:: output results sequentially\n type test2_1.out >test1.out\n del /s test2_1.out\n del /s test2_1.flg\n type test2_2.out >test1.out\n del /s test2_2.out\n del /s test2_2.flg\n type test2_3.out >test1.out\n del /s test2_3.out\n del /s test2_3.flg\n\n goto :eof\n:test2\n\n:: Generate one output file\n echo %1 >test2_%1.out\n ping -n 31 127.0.0.1 >nul: 2>nul:\n\n:: generate flag file to indicate finished\n echo x >test2_%1.flg\n" }, { "answer_id": 132894, "author": "Martin", "author_id": 22121, "author_profile": "https://Stackoverflow.com/users/22121", "pm_score": 1, "selected": false, "text": "start TestSuite1.cmd [TestParams1]\nstart TestSuite1.cmd [TestParams2]\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132857", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3153/" ]
132,867
<p>The question I'm really asking is why require does not take the name of the gem. Also, In the case that it doesn't, what's the easiest way to find the secret incantation to require the damn thing!?</p> <p>As an example if I have <code>memcache-client</code> installed then I have to require it using</p> <pre><code>require 'rubygems' require 'memcache' </code></pre>
[ { "answer_id": 132889, "author": "Kyle Burton", "author_id": 19784, "author_profile": "https://Stackoverflow.com/users/19784", "pm_score": 3, "selected": false, "text": "kburton@hypothesisf:~$ gem environment\nRubyGems Environment:\n - RUBYGEMS VERSION: 1.2.0\n - RUBY VERSION: 1.8.7 (2008-08-08 patchlevel 71) [i686-linux]\n - INSTALLATION DIRECTORY: /usr/local/ruby/lib/ruby/gems/1.8\n - RUBY EXECUTABLE: /usr/local/ruby/bin/ruby\n - EXECUTABLE DIRECTORY: /usr/local/ruby/bin\n - RUBYGEMS PLATFORMS:\n - ruby\n - x86-linux\n - GEM PATHS:\n - /usr/local/ruby/lib/ruby/gems/1.8\n - GEM CONFIGURATION:\n - :update_sources => true\n - :verbose => true\n - :benchmark => false\n - :backtrace => false\n - :bulk_threshold => 1000\n - REMOTE SOURCES:\n - http://gems.rubyforge.org/\nkburton@editconf:~$ \n kburton@hypothesis:~$ irb\nirb(main):001:0> $:\n=> [\"/usr/local/ruby/lib/ruby/site_ruby/1.8\", \"/usr/local/ruby/lib/ruby/site_ruby/1.8/i686-linux\", \"/usr/local/ruby/lib/ruby/site_ruby\", \"/usr/local/ruby/lib/ruby/vendor_ruby/1.8\", \"/usr/local/ruby/lib/ruby/vendor_ruby/1.8/i686-linux\", \"/usr/local/ruby/lib/ruby/vendor_ruby\", \"/usr/local/ruby/lib/ruby/1.8\", \"/usr/local/ruby/lib/ruby/1.8/i686-linux\", \".\"]\nirb(main):002:0>\n" }, { "answer_id": 132970, "author": "Laurie Young", "author_id": 7473, "author_profile": "https://Stackoverflow.com/users/7473", "pm_score": 6, "selected": true, "text": "require mygem #{gemname}/lib gem environment | grep INSTALLATION | awk '{print $4}'" }, { "answer_id": 136325, "author": "Orion Edwards", "author_id": 234, "author_profile": "https://Stackoverflow.com/users/234", "pm_score": 2, "selected": false, "text": "rdoc gemname" }, { "answer_id": 144363, "author": "Atiaxi", "author_id": 2555346, "author_profile": "https://Stackoverflow.com/users/2555346", "pm_score": 6, "selected": false, "text": "require 'rubygems'\nrequire 'gem-name-here'\n ruby -r rubygems script.rb\n export RUBYOPT=rubygems\n" }, { "answer_id": 6901318, "author": "Matthew O'Riordan", "author_id": 139607, "author_profile": "https://Stackoverflow.com/users/139607", "pm_score": 0, "selected": false, "text": "require 'rubygems' require 'nokogiri'" }, { "answer_id": 29887291, "author": "Gerry", "author_id": 109561, "author_profile": "https://Stackoverflow.com/users/109561", "pm_score": 1, "selected": false, "text": "files" }, { "answer_id": 39932080, "author": "Artem P", "author_id": 712308, "author_profile": "https://Stackoverflow.com/users/712308", "pm_score": 0, "selected": false, "text": "lib rb rb require 'dir/subdir/file'\n /lib/dir/subdir/file.rb" }, { "answer_id": 62294176, "author": "Hahn", "author_id": 3113949, "author_profile": "https://Stackoverflow.com/users/3113949", "pm_score": 1, "selected": false, "text": "dummy-spi-0.1.1/lib/spi.rb dummy-spi-0.1.1/lib/dummy-spi.rb require 'dummy-spi'\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132867", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18751/" ]
132,885
<p>I need to switch among 3 different environments when developing my web app - Development, UAT, and Prod. I have different database connections in my configuration files for all 3. I have seen switching these settings done manually by changing all references and then rebuilding the solution, and also done with preprocessor directives. Is there an easy way to do this based on some variable so that the configuration doesn't have to be revised when deploying to a new environment every time?</p>
[ { "answer_id": 132934, "author": "Aaron Powell", "author_id": 11388, "author_profile": "https://Stackoverflow.com/users/11388", "pm_score": 2, "selected": false, "text": "<Target Name=\"Configs\">\n<Xslt RootTag=\"\" Inputs=\"web.config\" Output=\"Web.$(COMPUTERNAME).config\" Xsl=\"web.config.$(COMPUTERNAME).xslt\" Condition=\"Exists('web.config.$(COMPUTERNAME).xslt')\" />\n <?xml version=\"1.0\" encoding=\"utf-8\"?>\n <!-- Dev -->\n<xsl:template match=\"/configuration/connectionStrings/add[@name='MyConnectionString']/@connectionString\">\n <xsl:attribute name=\"connectionString\">Data Source=MyServer;Initial Catalog=MyBD;User ID=user;password=pwd</xsl:attribute>\n</xsl:template>\n<xsl:template match=\"node()\">\n <xsl:copy>\n <xsl:apply-templates select=\"@*\"/>\n <xsl:apply-templates/>\n </xsl:copy>\n</xsl:template>\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132885", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1284/" ]
132,902
<p>I need to move entire tables from one MySQL database to another. I don't have full access to the second one, only phpMyAdmin access. I can only upload (compressed) sql files smaller than 2MB. But the compressed output from a mysqldump of the first database's tables is larger than 10MB.</p> <p>Is there a way to split the output from mysqldump into smaller files? I cannot use split(1) since I cannot cat(1) the files back on the remote server.</p> <p>Or is there another solution I have missed?</p> <p><strong>Edit</strong></p> <p>The --extended-insert=FALSE option to mysqldump suggested by the first poster yields a .sql file that can then be split into importable files, provided that split(1) is called with a suitable --lines option. By trial and error I found that bzip2 compresses the .sql files by a factor of 20, so I needed to figure out how many lines of sql code correspond roughly to 40MB.</p>
[ { "answer_id": 132939, "author": "Vinko Vrsalovic", "author_id": 5190, "author_profile": "https://Stackoverflow.com/users/5190", "pm_score": 6, "selected": true, "text": "mysqldump -d --all-databases \n mysqldump --all-databases --extended-insert=FALSE --no-create-info=TRUE\n" }, { "answer_id": 132957, "author": "skoob", "author_id": 20708, "author_profile": "https://Stackoverflow.com/users/20708", "pm_score": 1, "selected": false, "text": "mysqldump database table1 table2 ... tableN" }, { "answer_id": 134296, "author": "Giuseppe Maxia", "author_id": 18535, "author_profile": "https://Stackoverflow.com/users/18535", "pm_score": 4, "selected": false, "text": "for T in `mysql -N -B -e 'show tables from dbname'`; \\\n do echo $T; \\\n mysqldump [connecting_options] dbname $T \\\n | gzip -c > dbname_$T.dump.gz ; \\\n done mysqldump [connecting options] --tab=directory_name dbname " }, { "answer_id": 4766022, "author": "Lee Haskings", "author_id": 585326, "author_profile": "https://Stackoverflow.com/users/585326", "pm_score": 3, "selected": false, "text": "for I in $(mysql -e 'show databases' -s --skip-column-names); do mysqldump $I | gzip > \"$I.sql.gz\"; done\n" }, { "answer_id": 9949414, "author": "rubo77", "author_id": 1069083, "author_profile": "https://Stackoverflow.com/users/1069083", "pm_score": 6, "selected": false, "text": "#!/bin/bash\n\n####\n# Split MySQL dump SQL file into one file per table\n# based on https://gist.github.com/jasny/1608062\n####\n\n#adjust this to your case:\nSTART=\"/-- Table structure for table/\"\n# or \n#START=\"/DROP TABLE IF EXISTS/\"\n\n\nif [ $# -lt 1 ] || [[ $1 == \"--help\" ]] || [[ $1 == \"-h\" ]] ; then\n echo \"USAGE: extract all tables:\"\n echo \" $0 DUMP_FILE\"\n echo \"extract one table:\"\n echo \" $0 DUMP_FILE [TABLE]\"\n exit\nfi\n\nif [ $# -ge 2 ] ; then\n #extract one table $2\n csplit -s -ftable $1 \"/-- Table structure for table/\" \"%-- Table structure for table \\`$2\\`%\" \"/-- Table structure for table/\" \"%40103 SET TIME_ZONE=@OLD_TIME_ZONE%1\"\nelse\n #extract all tables\n csplit -s -ftable $1 \"$START\" {*}\nfi\n \n[ $? -eq 0 ] || exit\n \nmv table00 head\n \nFILE=`ls -1 table* | tail -n 1`\nif [ $# -ge 2 ] ; then\n # cut off all other tables\n mv $FILE foot\nelse\n # cut off the end of each file\n csplit -b '%d' -s -f$FILE $FILE \"/40103 SET TIME_ZONE=@OLD_TIME_ZONE/\" {*}\n mv ${FILE}1 foot\nfi\n \nfor FILE in `ls -1 table*`; do\n NAME=`head -n1 $FILE | cut -d$'\\x60' -f2`\n cat head $FILE foot > \"$NAME.sql\"\ndone\n \nrm head foot table*\n" }, { "answer_id": 13408815, "author": "Gadelkareem", "author_id": 280512, "author_profile": "https://Stackoverflow.com/users/280512", "pm_score": 0, "selected": false, "text": "#!/bin/sh\n\n#edit these\nUSER=\"\"\nPASSWORD=\"\"\nMYSQLDIR=\"/path/to/backupdir\"\n\nMYSQLDUMP=\"/usr/bin/mysqldump\"\nMYSQL=\"/usr/bin/mysql\"\n\necho - Dumping tables for each DB\ndatabases=`$MYSQL --user=$USER --password=$PASSWORD -e \"SHOW DATABASES;\" | grep -Ev \"(Database|information_schema)\"`\nfor db in $databases; do\n echo - Creating \"$db\" DB\n mkdir $MYSQLDIR/$db\n chmod -R 777 $MYSQLDIR/$db\n for tb in `$MYSQL --user=$USER --password=$PASSWORD -N -B -e \"use $db ;show tables\"`\n do \n echo -- Creating table $tb\n $MYSQLDUMP --opt --delayed-insert --insert-ignore --user=$USER --password=$PASSWORD $db $tb | bzip2 -c > $MYSQLDIR/$db/$tb.sql.bz2\n done\n echo\ndone\n" }, { "answer_id": 26697782, "author": "zalex", "author_id": 3725361, "author_profile": "https://Stackoverflow.com/users/3725361", "pm_score": 2, "selected": false, "text": "cat dump.sql | awk 'BEGIN {output = \"comments\"; }\n$data ~ /^CREATE TABLE/ {close(output); output = substr($3,2,length($3)-2); }\n{ print $data >> output }';\n cat backup.sql | awk 'BEGIN {output=\"comments\";} $data ~ /Current Database/ {close(output);output=$4;} {print $data>>output}';\n" }, { "answer_id": 28719465, "author": "mysql_user", "author_id": 4412921, "author_profile": "https://Stackoverflow.com/users/4412921", "pm_score": 4, "selected": false, "text": "sh mysqldumpsplitter.sh --source filename --extract DB --match_str\n database-name sh mysqldumpsplitter.sh --source filename --extract TABLE --match_str\n table-name sh mysqldumpsplitter.sh --source filename --extract REGEXP\n --match_str regular-expression sh mysqldumpsplitter.sh --source filename --extract ALLDBS sh mysqldumpsplitter.sh --source filename --extract ALLTABLES sh mysqldumpsplitter.sh --source filename --extract REGEXP\n --match_str '(table1|table2|table3)' sh mysqldumpsplitter.sh --source filename.sql.gz --extract DB\n --match_str 'dbname' --decompression gzip sh mysqldumpsplitter.sh --source filename.sql.gz --extract DB\n --match_str 'dbname' --decompression gzip --compression none sh mysqldumpsplitter.sh --source filename --extract ALLTABLES\n --output_dir /path/to/extracts/ sh mysqldumpsplitter.sh --source filename\n --extract DB --match_str DBNAME --compression none sh mysqldumpsplitter.sh --source out/DBNAME.sql\n --extract REGEXP --match_str \"(tbl1|tbl2)\" sh mysqldumpsplitter.sh --source filename --extract DBTABLE\n --match_str \"DBNAME.(tbl1|tbl2)\" --compression none sh mysqldumpsplitter.sh --source filename --extract DBTABLE\n --match_str \"DBNAME.(tbl1)\" --compression none mysqldumpsplitter.sh --source filename --extract DBTABLE --match_str\n \"DBNAME.*\" --compression none mysqldumpsplitter.sh --source filename --desc split -l 10000 filename.sql" }, { "answer_id": 30988416, "author": "Alisa", "author_id": 2961878, "author_profile": "https://Stackoverflow.com/users/2961878", "pm_score": 0, "selected": false, "text": "- In Eclipse, Right click on your project --> Import\n- Select \"File System\" and then \"Next\"\n- Browse the path of the jar file and press \"Ok\"\n- Select (thick) the \"MySQLDumpSplitter.jar\" file and then \"Finish\"\n- It will be added to your project and shown in the project folder in Package Explorer in Eclipse\n- Double click on the jar file in Eclipse (in Package Explorer)\n- The \"MySQL Dump file splitter\" window opens which you can specify the address of your dump file and proceed with split.\n" }, { "answer_id": 58242476, "author": "kloddant", "author_id": 5626341, "author_profile": "https://Stackoverflow.com/users/5626341", "pm_score": 1, "selected": false, "text": "import sys, re, os\n\nif sys.version_info[0] < 3:\n raise Exception(\"\"\"Must be using Python 3. Try running \"C:\\\\Program Files (x86)\\\\Python37-32\\\\python.exe\" split_sql_dump_file.py\"\"\")\n\nsqldump_path = input(\"Enter the path to the sql dump file: \")\n\nif not os.path.exists(sqldump_path):\n raise Exception(\"Invalid sql dump path. {sqldump_path} does not exist.\".format(sqldump_path=sqldump_path))\n\noutput_folder_path = input(\"Enter the path to the output folder: \") or sqldump_path.rstrip('.sql')\n\nif not os.path.exists(output_folder_path):\n os.makedirs(output_folder_path)\n\ntable_name = None\noutput_file_path = None\nsmallfile = None\n\nwith open(sqldump_path, 'rb') as bigfile:\n for line_number, line in enumerate(bigfile):\n line_string = line.decode(\"utf-8\")\n if 'CREATE TABLE' in line_string.upper():\n match = re.match(r\"^CREATE TABLE (?:IF NOT EXISTS )?`(?P<table>\\w+)` \\($\", line_string)\n if match:\n table_name = match.group('table')\n print(table_name)\n output_file_path = \"{output_folder_path}/{table_name}.sql\".format(output_folder_path=output_folder_path.rstrip('/'), table_name=table_name)\n if smallfile:\n smallfile.close()\n smallfile = open(output_file_path, 'wb')\n if not table_name:\n continue\n smallfile.write(line)\n smallfile.close()\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132902", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1428/" ]
132,921
<p>I was wondering how i can force a user who has requested a page using Http to use the secure https version?</p> <p>I am using Websphere 6.1 as my application server and Rad 7 as my development environment</p> <p>Thanks Damien</p>
[ { "answer_id": 133116, "author": "matt b", "author_id": 4249, "author_profile": "https://Stackoverflow.com/users/4249", "pm_score": 3, "selected": true, "text": "ServletRequest.getScheme() HttpServletResponse.sendRedirect(String url)" }, { "answer_id": 141407, "author": "fnCzar", "author_id": 15053, "author_profile": "https://Stackoverflow.com/users/15053", "pm_score": 0, "selected": false, "text": "public void doFilter(ServletRequest servletRequest,\n ServletResponse servletResponse, FilterChain filterChain)\n throws IOException, ServletException {\n\n HttpServletRequest httpRequest = (HttpServletRequest) servletRequest;\n HttpServletResponse httpResponse = (HttpServletResponse) servletResponse;\n\n String requestWrapperClassName = (String) (httpRequest\n .getAttribute(LoadBalancerRequestWrapper.class.getName()));\n\n String initiatingServerName = httpRequest.getServerName();\n\n if (requestWrapperClassName == null\n && initiatingServerName.equals(loadBalancerHostName)) {\n\n httpRequest = new LoadBalancerRequestWrapper(AuthenticationUtil\n .getHttpServletRequest(httpRequest));\n }\n\n filterChain.doFilter(httpRequest, httpResponse);\n}\n /**\n * The custom implementation of the request wrapper. It simply overrides the\n * getScheme() and getServerPort() methods to perform the redirect\n * filtering.\n * \n * \n */\nprivate static class LoadBalancerRequestWrapper extends\n HttpServletRequestWrapper {\n\n /**\n * Default Constructor. Simply declares the Wrapper as injected.\n * \n * @param httpServletRequest\n * the app-server HttpServletRequest.\n * \n */\n public LoadBalancerRequestWrapper(HttpServletRequest httpServletRequest) {\n super(httpServletRequest);\n }\n\n /**\n * The overridden scheme.\n * \n */\n public final String getScheme() {\n if (loadBalancerHttpScheme.equals(EMPTY_STRING)) {\n return super.getScheme();\n }\n\n return loadBalancerHttpScheme;\n }\n}\n" }, { "answer_id": 17447328, "author": "Srisudhir T", "author_id": 1061643, "author_profile": "https://Stackoverflow.com/users/1061643", "pm_score": 1, "selected": false, "text": "<!--********************************\n *** SSL Security Constraint ***\n *****************************-->\n <security-constraint>\n <web-resource-collection>\n <web-resource-name>SSL</web-resource-name>\n <url-pattern>/*</url-pattern>\n </web-resource-collection>\n <user-data-constraint>\n <transport-guarantee>CONFIDENTIAL</transport-guarantee>\n </user-data-constraint>\n </security-constraint>\n\n<!--********************************* -->\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132921", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11612/" ]
132,940
<p>Recently I noticed my application appears to be eating memory that never gets released. After profiling with CLRProfiler I've found that the Castle Windsor container I'm using is holding onto objects. These objects are declared with the lifestyle="transient" attribute in the config xml.</p> <p>I've found if I put an explicit call to <code>IWindsorContainer.Release(hangingObject)</code>, that it will drop its references.</p> <p>This is causing a problem though, I wasn't expecting that with a transient lifestyle object CastleWindsor would keep a reference and effectively create a leak. It's going to be a rather mundane and error prone task going around inserting explicit Release calls in all the appropriate places.</p> <p>Have you seen this problem, and do you have any suggestions for how to get around it?</p>
[ { "answer_id": 133058, "author": "Scott Langham", "author_id": 11898, "author_profile": "https://Stackoverflow.com/users/11898", "pm_score": 1, "selected": false, "text": "ILifestyleManager ReallyTransient" }, { "answer_id": 166523, "author": "Bittercoder", "author_id": 4843, "author_profile": "https://Stackoverflow.com/users/4843", "pm_score": 5, "selected": true, "text": "NoTrackingReleasePolicy" }, { "answer_id": 682681, "author": "Craig Vermeer", "author_id": 8802, "author_profile": "https://Stackoverflow.com/users/8802", "pm_score": 2, "selected": false, "text": "LifecycledComponentsReleasePolicy" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132940", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11898/" ]
132,955
<p>How do I have a script run every, say 30 minutes? I assume there are different ways for different OSs. I'm using OS X.</p>
[ { "answer_id": 133425, "author": "Mecki", "author_id": 15809, "author_profile": "https://Stackoverflow.com/users/15809", "pm_score": 8, "selected": true, "text": "launchd init cron at init.d inetd upstart systemd /Library/LaunchDaemons/\n /Library/LaunchAgents/\n ~/Library/LaunchAgents/\n /System/Library/LaunchDaemons /System/Library/LaunchAgents /System launchd launchd com.example.my-fancy-task.plist\n <?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n <key>Label</key>\n <string>com.example.my-fancy-task</string>\n <key>OnDemand</key>\n <true/>\n <key>ProgramArguments</key>\n <array>\n <string>/bin/sh</string>\n <string>/usr/local/bin/my-script.sh</string>\n </array>\n <key>StartInterval</key>\n <integer>1800</integer>\n</dict>\n</plist>\n OnDemand KeepAlive OnDemand false OnDemand true launchctl <command> <parameter>\n load unload start stop com.example.my-fancy-task load unload start stop bootstrap bootout enable disable disable kickstart launctl com.example.my-fancy-task system/com.example.my-fancy-task user/501/com.example.my-fancy-task launchctl" }, { "answer_id": 58543077, "author": "webcpu", "author_id": 2442765, "author_profile": "https://Stackoverflow.com/users/2442765", "pm_score": 3, "selected": false, "text": "crontab -e\n * * * * * command to execute\n│ │ │ │ │\n│ │ │ │ └─── day of week (0 - 6) (0 to 6 are Sunday to Saturday, or use names; 7 is Sunday, the same as 0)\n│ │ │ └──────── month (1 - 12)\n│ │ └───────────── day of month (1 - 31)\n│ └────────────────── hour (0 - 23)\n└─────────────────────── min (0 - 59)\n 0 12 * * * cd ~/backupfolder && ./backup.sh\n sudo crontab -e\n crontab -l\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132955", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1615/" ]
132,971
<p>A <a href="http://www.google.com/search?ie=UTF-8&amp;oe=UTF-8&amp;sourceid=navclient&amp;gfns=1&amp;q=windows+cron" rel="noreferrer">Google search</a> turned up software that performs the same functions as cron, but nothing built into Windows.</p> <p>I'm running Windows XP Professional, but advice for any version of Windows would be potentially helpful to someone.</p> <p>Is there also a way to invoke this feature (which based on answers is called the Task Scheduler) programatically or via the command line?</p>
[ { "answer_id": 133053, "author": "enobrev", "author_id": 14651, "author_profile": "https://Stackoverflow.com/users/14651", "pm_score": 3, "selected": false, "text": "Supported systems\n\n* Windows 2000 (any version) works\n* Windows XP (SP 2) works\n* Windows Server 2003 works\n* Windows NT 4 (SP 6) should work but not tested\n* Windows 3.11, Windows 95,\n Windows 98, Windows ME,\n Windows XP beneath SP2 not supported by design\n" }, { "answer_id": 6485553, "author": "user816347", "author_id": 816347, "author_profile": "https://Stackoverflow.com/users/816347", "pm_score": 4, "selected": false, "text": "1 Minute (0-59)\n2 Hour (2-24)\n3 Day of month (1-31)\n4 Month (1-12, Jan, Feb, etc)\n5 Day of week (0-6) 0 = Sunday, 1 = Monday etc or Sun, Mon, etc)\n6 User that the command will run as\n7 Command to execute\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132971", "https://Stackoverflow.com", "https://Stackoverflow.com/users/572/" ]
132,976
<p>I have a MOJO I would like executed once, and once only after the test phase of the last project in the reactor to run.</p> <p>Using:</p> <pre><code>if (!getProject().isExecutionRoot()) { return ; } </code></pre> <p>at the start of the execute() method means my mojo gets executed once, however at the very beginning of the build - before all other child modules. </p>
[ { "answer_id": 137318, "author": "npellow", "author_id": 2767300, "author_profile": "https://Stackoverflow.com/users/2767300", "pm_score": 3, "selected": false, "text": "/**\n * The projects in the reactor.\n *\n * @parameter expression=\"${reactorProjects}\"\n * @readonly\n */\nprivate List reactorProjects;\n\npublic void execute() throws MojoExecutionException {\n\n // only execute this mojo once, on the very last project in the reactor\n final int size = reactorProjects.size();\n MavenProject lastProject = (MavenProject) reactorProjects.get(size - 1);\n if (lastProject != getProject()) {\n return;\n }\n // do work\n ...\n}\n" }, { "answer_id": 1193729, "author": "Rich Seller", "author_id": 123582, "author_profile": "https://Stackoverflow.com/users/123582", "pm_score": 2, "selected": false, "text": "boolean result = mavenSession.getExecutionRootDirectory().equalsIgnoreCase(basedir.toString());\n" }, { "answer_id": 4284240, "author": "Cornel Masson", "author_id": 234391, "author_profile": "https://Stackoverflow.com/users/234391", "pm_score": 0, "selected": false, "text": "/**\n * The Maven Project Object\n *\n * @parameter expression=\"${project}\"\n * @required\n * @readonly\n */\nprotected MavenProject project;\n\n\n/**\n * The Maven Session.\n *\n * @parameter expression=\"${session}\"\n * @required\n * @readonly\n */\nprotected MavenSession session;\n\n...\n\n\n@Override\npublic void execute() throws MojoExecutionException, MojoFailureException\n{\n //Register the event handler right at the start only\n if (project.isExecutionRoot())\n registerEventMonitor();\n ...\n}\n\n\n/**\n * Register an {@link EventMonitor} with Maven so that we can respond to certain lifecycle events\n */\nprotected void registerEventMonitor()\n{\n session.getEventDispatcher().addEventMonitor(\n new EventMonitor() {\n\n @Override\n public void endEvent(String eventName, String target, long arg2) {\n if (eventName.equals(\"reactor-execute\"))\n printSummary();\n }\n\n @Override\n public void startEvent(String eventName, String target, long arg2) {}\n\n @Override\n public void errorEvent(String eventName, String target, long arg2, Throwable arg3) {}\n\n\n }\n );\n}\n\n\n/**\n * Print summary at end\n */\nprotected void printSummary()\n{\n ...\n}\n" }, { "answer_id": 40015872, "author": "Konrad Windszus", "author_id": 5155923, "author_profile": "https://Stackoverflow.com/users/5155923", "pm_score": 2, "selected": false, "text": "org.apache.maven.AbstractMavenLifecycleParticipant afterSessionEnd" }, { "answer_id": 68263892, "author": "jingxuansd", "author_id": 15526795, "author_profile": "https://Stackoverflow.com/users/15526795", "pm_score": 0, "selected": false, "text": "public boolean isThisTheLastProject() {\n return session.getProjectDependencyGraph().getSortedProjects().\n get(session.getProjectDependencyGraph().getSortedProjects().size()-1).getArtifactId().equalsIgnoreCase(project.getArtifactId());\n }\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132976", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2767300/" ]
132,988
<p>My <a href="https://english.stackexchange.com/questions/19967/what-does-google-fu-mean">Google-fu</a> has failed me.</p> <p>In Python, are the following two tests for equality equivalent?</p> <pre><code>n = 5 # Test one. if n == 5: print 'Yay!' # Test two. if n is 5: print 'Yay!' </code></pre> <p>Does this hold true for objects where you would be comparing instances (a <code>list</code> say)?</p> <p>Okay, so this kind of answers my question:</p> <pre><code>L = [] L.append(1) if L == [1]: print 'Yay!' # Holds true, but... if L is [1]: print 'Yay!' # Doesn't. </code></pre> <p>So <code>==</code> tests value where <code>is</code> tests to see if they are the same object?</p>
[ { "answer_id": 133017, "author": "stephenbayer", "author_id": 18893, "author_profile": "https://Stackoverflow.com/users/18893", "pm_score": 6, "selected": false, "text": "== is" }, { "answer_id": 133022, "author": "mmaibaum", "author_id": 12213, "author_profile": "https://Stackoverflow.com/users/12213", "pm_score": 4, "selected": false, "text": "is ==" }, { "answer_id": 133024, "author": "Torsten Marek", "author_id": 9567, "author_profile": "https://Stackoverflow.com/users/9567", "pm_score": 11, "selected": true, "text": "is True == >>> a = [1, 2, 3]\n>>> b = a\n>>> b is a \nTrue\n>>> b == a\nTrue\n\n# Make a new copy of list `a` via the slice operator, \n# and assign it to variable `b`\n>>> b = a[:] \n>>> b is a\nFalse\n>>> b == a\nTrue\n >>> 1000 is 10**3\nFalse\n>>> 1000 == 10**3\nTrue\n >>> \"a\" is \"a\"\nTrue\n>>> \"aa\" is \"a\" * 2\nTrue\n>>> x = \"a\"\n>>> \"aa\" is x * 2\nFalse\n>>> \"aa\" is intern(x*2)\nTrue\n" }, { "answer_id": 133035, "author": "David Webb", "author_id": 3171, "author_profile": "https://Stackoverflow.com/users/3171", "pm_score": 3, "selected": false, "text": "is == __cmp__ __eq__" }, { "answer_id": 134631, "author": "Dan Lenski", "author_id": 20789, "author_profile": "https://Stackoverflow.com/users/20789", "pm_score": 4, "selected": false, "text": "is == is >>> \"foo\" + \"bar\" == \"foobar\"\nTrue\n>>> \"foo\" + \"bar\" is \"foobar\"\nTrue\n>>> \"foo\"[:] + \"bar\" == \"foobar\"\nTrue\n>>> \"foo\"[:] + \"bar\" is \"foobar\"\nFalse\n" }, { "answer_id": 1085652, "author": "cobbal", "author_id": 73681, "author_profile": "https://Stackoverflow.com/users/73681", "pm_score": 3, "selected": false, "text": "is" }, { "answer_id": 1085656, "author": "John Feminella", "author_id": 75170, "author_profile": "https://Stackoverflow.com/users/75170", "pm_score": 9, "selected": false, "text": "== is == is == == x is >>> a = 500\n>>> b = 500\n>>> a == b\nTrue\n>>> a is b\nFalse\n a b >>> c = 200\n>>> d = 200\n>>> c == d\nTrue\n>>> c is d\nTrue\n >>> for i in range(250, 260): a = i; print \"%i: %s\" % (i, a is int(str(i)));\n... \n250: True\n251: True\n252: True\n253: True\n254: True\n255: True\n256: True\n257: False\n258: False\n259: False\n is" }, { "answer_id": 1086066, "author": "John Machin", "author_id": 84270, "author_profile": "https://Stackoverflow.com/users/84270", "pm_score": 2, "selected": false, "text": "foo == None foo is None is foo is None foo bar foo == True foo is True" }, { "answer_id": 48120163, "author": "Russia Must Remove Putin", "author_id": 541136, "author_profile": "https://Stackoverflow.com/users/541136", "pm_score": 6, "selected": false, "text": "== is == is is is not x is y x y id() x is not y a is b\n id(a) == id(b)\n id help(id) a b is == is is None == == is None is is not if x if x is not None None is __eq__ == != x is y x == y >>> class Object(object): pass\n>>> obj = Object()\n>>> obj2 = Object()\n>>> obj == obj, obj is obj\n(True, True)\n>>> obj == obj2, obj is obj2\n(False, False)\n nan >>> nan = float('nan')\n>>> nan\nnan\n>>> nan is nan\nTrue\n>>> nan == nan # !!!!!\nFalse\n nan >>> [nan] == [nan]\nTrue\n>>> (nan,) == (nan,)\nTrue\n is is" }, { "answer_id": 48350377, "author": "MSeifert", "author_id": 5393381, "author_profile": "https://Stackoverflow.com/users/5393381", "pm_score": 5, "selected": false, "text": "is == == is == is value1 value2 int 1000 value1 = 1000\nvalue2 = value1\n value2 is == True >>> value1 == value2\nTrue\n>>> value1 is value2\nTrue\n value1 value2 int >>> value1 = 1000\n>>> value2 = 1000\n == True is False >>> value1 == value2\nTrue\n>>> value1 is value2\nFalse\n is is None True False NotImplemented Ellipsis __debug__ int is int int is float np.ma.masked == == __eq__ class MyClass(object):\n def __init__(self, val):\n self._value = val\n\n def __eq__(self, other):\n print('__eq__ method called')\n try:\n return self._value == other._value\n except AttributeError:\n raise TypeError('Cannot compare {0} to objects of type {1}'\n .format(type(self), type(other)))\n >>> MyClass(10) == MyClass(10)\n__eq__ method called\nTrue\n __eq__ __eq__ is class AClass(object):\n def __init__(self, value):\n self._value = value\n\n>>> a = AClass(10)\n>>> b = AClass(10)\n>>> a == b\nFalse\n>>> a == a\n __eq__ is __eq__ True False == >>> import numpy as np\n>>> np.arange(10) == 2\narray([False, False, True, False, False, False, False, False, False, False], dtype=bool)\n is True False is True is False if is True True False == Yes: if greeting:\nNo: if greeting == True:\nWorse: if greeting is True:\n" }, { "answer_id": 48566846, "author": "imanzabet", "author_id": 1361125, "author_profile": "https://Stackoverflow.com/users/1361125", "pm_score": 2, "selected": false, "text": "== is is == == is str = 'hello'\nif (str is 'hello'):\n print ('str is hello')\nif (str == 'hello'):\n print ('str == hello')\n str is hello\nstr == hello\n == is str2 = 'hello sam'\n if (str2 is 'hello sam'):\n print ('str2 is hello sam')\n if (str2 == 'hello sam'):\n print ('str2 == hello sam')\n str2 == hello sam\n is is id is str = 'hello'\nid('hello')\n> 140039832615152\nid(str)\n> 140039832615152\n str2 = 'hello sam'\nid('hello sam')\n> 140039832615536\nid(str2)\n> 140039832615792\n" }, { "answer_id": 49146910, "author": "Sandeep", "author_id": 2497039, "author_profile": "https://Stackoverflow.com/users/2497039", "pm_score": 2, "selected": false, "text": "list1 = [1,2,3,4]\ntuple1 = (1,2,3,4)\n\nprint(list1)\nprint(tuple1)\nprint(id(list1))\nprint(id(tuple1))\n\nprint(list1 == tuple1)\nprint(list1 is tuple1)\n" }, { "answer_id": 51584206, "author": "suvojit_007", "author_id": 8071889, "author_profile": "https://Stackoverflow.com/users/8071889", "pm_score": 3, "selected": false, "text": "is == a=[1,2,3]\nb=a #a and b point to the same object\nc=list(a) #c points to different object \n\nif a==b:\n print('#') #output:#\nif a is b:\n print('##') #output:## \nif a==c:\n print('###') #output:## \nif a is c:\n print('####') #no output as c and a point to different object \n" }, { "answer_id": 51746826, "author": "Projesh Bhoumik", "author_id": 3547000, "author_profile": "https://Stackoverflow.com/users/3547000", "pm_score": 2, "selected": false, "text": ">>> a = b = [1,2,3]\n>>> c = [1,2,3]\n>>> a == b\nTrue\n>>> a == c\nTrue\n>>> a is b\nTrue\n>>> a is c\nFalse\n>>> a = [1,2,3]\n>>> b = [1,2]\n>>> a == b\nFalse\n>>> a is b\nFalse\n>>> del a[2]\n>>> a == b\nTrue\n>>> a is b\nFalse\n Tip: Avoid using is operator for immutable types such as strings and numbers, the result is unpredictable.\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/132988", "https://Stackoverflow.com", "https://Stackoverflow.com/users/61/" ]
133,002
<p>I am using Flex to connect to a Rest service. To access order #32, for instance, I can call the URL <a href="http://[service]/orders/32" rel="nofollow noreferrer">http://[service]/orders/32</a>. The URL <em>must</em> be configured as a destination - since the client will connect to different instances of the service. All of this is using the Blaze Proxy, since it involves GET, PUT, DELETE and POST calls. The problem is:- how do I append the "32" to the end of a destination when using HttpService? All I do is set the destination, and at some point this is converted into a URL. I have traced the code, but I don't know where this is done, so can't replace it.</p> <p>Options are: 1. Resolve the destination to a URL within the Flex client, and then set the URL (with the appended data) as the URL. 2. Write my own java Flex Adapter that overrides the standard Proxy, and map parameters to the url like the following: <a href="http://[service]/order/" rel="nofollow noreferrer">http://[service]/order/</a>{id}?id=32 to <a href="http://[service]/order/32" rel="nofollow noreferrer">http://[service]/order/32</a></p> <p>Has anyone come across this problem before, and are there any simple ways to resolve this?</p>
[ { "answer_id": 134260, "author": "defmeta", "author_id": 10875, "author_profile": "https://Stackoverflow.com/users/10875", "pm_score": 0, "selected": false, "text": "<mx:HTTPService\n id=\"UCService\"\n result=\"UCServiceHandler(event)\" \n showBusyCursor=\"true\"\n resultFormat=\"e4x\"\n />\n private function UCmainHandler(UCurl:String) {\n\n UCService.url = UCurl;\n UCService.send();\n\n }\n <mx:Button label=\"add to cart\" click=\"UCmainHandler('http://sampleurl.com/cart/add/p18_q1?destination=cart')\" />\n" }, { "answer_id": 140282, "author": "Verdant", "author_id": 450527, "author_profile": "https://Stackoverflow.com/users/450527", "pm_score": 1, "selected": false, "text": "public MyHTTPProxyAdapter extends flex.messaging.services.http.HTTPProxyAdapter {\n\npublic Object invoke(Message message) {\n // modify the message - if required\n process(message);\n return super.invoke(message);\n}\n\nprivate void process(Message message) {\n HTTPMessage http = (HTTPMessage)message;\n if(http != null) {\n String url = http.getUrl();\n ASObject o = (ASObject)http.getBody();\n if(o != null) {\n Set keys = o.keySet();\n Iterator it = keys.iterator();\n while(it.hasNext()) {\n String key = (String)it.next();\n String token = \"[\" + key +\"]\";\n if(url.contains(token)) {\n url = url.replace(token, o.get(key).toString());\n o.remove(key);\n }\n\n }\n http.setUrl(url);\n }\n }\n }\n}\n <destination id=\"user-getbytoken\">\n <properties>\n <url>http://localhost:8080/myapp/public/client/users/token/[id]</url>\n </properties>\n</destination>\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133002", "https://Stackoverflow.com", "https://Stackoverflow.com/users/450527/" ]
133,008
<p>What is Big O notation? Do you use it?</p> <p>I missed this university class I guess :D</p> <p>Does anyone use it and give some real life examples of where they used it?</p> <hr /> <h3>See also:</h3> <p><a href="https://stackoverflow.com/questions/107165/big-o-for-eight-year-olds">Big-O for Eight Year Olds?</a><br /> <a href="https://stackoverflow.com/questions/3255/big-o-how-do-you-calculateapproximate-it">Big O, how do you calculate/approximate it?</a><br /> <a href="https://stackoverflow.com/questions/111426/did-you-apply-computational-complexity-theory-in-real-life">Did you apply computational complexity theory in real life?</a></p>
[ { "answer_id": 133128, "author": "Steve g", "author_id": 12092, "author_profile": "https://Stackoverflow.com/users/12092", "pm_score": 3, "selected": false, "text": "/** Takes an array of strings and concatenates them\n * This is a silly way of doing things but it gets the \n * point across hopefully\n * @param strings the array of strings to concatenate\n * @returns a string that is a result of the concatenation of all the strings\n * in the array\n */\npublic static String badConcat(String[] Strings){\n String totalString = \"\";\n for(String s : strings) {\n for(int i = 0; i < s.length(); i++){\n totalString += s.charAt(i);\n }\n }\n return totalString;\n}\n n-1 (n-1)(n/2) (n^2-n)/2 O(n^2) StringBuilder StringBuilder O(n) StringBuilder StringBuilder setCapacity O(n)" }, { "answer_id": 133162, "author": "Mecki", "author_id": 15809, "author_profile": "https://Stackoverflow.com/users/15809", "pm_score": 6, "selected": true, "text": "A O(n^2) B O(log n) A B A B A n^2 B log n A B A B B A B A A" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133008", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3208/" ]
133,031
<p>I need to add a specific column if it does not exist. I have something like the following, but it always returns false:</p> <pre><code>IF EXISTS(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'myTableName' AND COLUMN_NAME = 'myColumnName') </code></pre> <p>How can I check if a column exists in a table of the SQL Server database?</p>
[ { "answer_id": 133041, "author": "Leon Tayson", "author_id": 18413, "author_profile": "https://Stackoverflow.com/users/18413", "pm_score": 6, "selected": false, "text": "IF NOT EXISTS(\n SELECT TOP 1 1\n FROM INFORMATION_SCHEMA.COLUMNS\n WHERE \n [TABLE_NAME] = 'Employees'\n AND [COLUMN_NAME] = 'EmployeeID')\nBEGIN\n ALTER TABLE [Employees]\n ADD [EmployeeID] INT NULL\nEND\n" }, { "answer_id": 133046, "author": "Luke Bennett", "author_id": 17602, "author_profile": "https://Stackoverflow.com/users/17602", "pm_score": 7, "selected": false, "text": "if not exists (select\n column_name\n from\n INFORMATION_SCHEMA.columns\n where\n table_name = 'MyTable'\n and column_name = 'MyColumn')\n alter table MyTable add MyColumn int\n" }, { "answer_id": 133052, "author": "mdb", "author_id": 8562, "author_profile": "https://Stackoverflow.com/users/8562", "pm_score": 5, "selected": false, "text": "table column id name dbo.syscolumns ALTER TABLE IF NOT EXISTS ( SELECT *\n FROM syscolumns\n WHERE id = OBJECT_ID('Client')\n AND name = 'Name' ) \nALTER TABLE Client\nADD Name VARCHAR(64) NULL\n" }, { "answer_id": 133055, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 5, "selected": false, "text": "SELECT *\n FROM INFORMATION_SCHEMA.COLUMNS\n WHERE TABLE_NAME = 'yourTableName'\n ORDER BY ORDINAL_POSITION\n" }, { "answer_id": 133056, "author": "Matt Lacey", "author_id": 1755, "author_profile": "https://Stackoverflow.com/users/1755", "pm_score": 5, "selected": false, "text": "CREATE FUNCTION ColumnExists(@TableName varchar(100), @ColumnName varchar(100))\nRETURNS varchar(1) AS\nBEGIN\nDECLARE @Result varchar(1);\nIF EXISTS (SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = @TableName AND COLUMN_NAME = @ColumnName)\nBEGIN\n SET @Result = 'T'\nEND\nELSE\nBEGIN\n SET @Result = 'F'\nEND\nRETURN @Result;\nEND\nGO\n\nGRANT EXECUTE ON [ColumnExists] TO [whoever]\nGO\n IF ColumnExists('xxx', 'yyyy') = 'F'\nBEGIN\n ALTER TABLE xxx\n ADD yyyyy varChar(10) NOT NULL\nEND\nGO\n" }, { "answer_id": 133057, "author": "Mitch Wheat", "author_id": 16076, "author_profile": "https://Stackoverflow.com/users/16076", "pm_score": 12, "selected": true, "text": "IF EXISTS(SELECT 1 FROM sys.columns \n WHERE Name = N'columnName'\n AND Object_ID = Object_ID(N'schemaName.tableName'))\nBEGIN\n -- Column Exists\nEND\n IF COL_LENGTH('schemaName.tableName', 'columnName') IS NOT NULL\nBEGIN\n -- Column Exists\nEND\n" }, { "answer_id": 1048093, "author": "Christian Hayter", "author_id": 115413, "author_profile": "https://Stackoverflow.com/users/115413", "pm_score": 6, "selected": false, "text": "INFORMATION_SCHEMA.COLUMNS dbo.syscolumns" }, { "answer_id": 5183067, "author": "Tuomo Kämäräinen", "author_id": 643270, "author_profile": "https://Stackoverflow.com/users/643270", "pm_score": 5, "selected": false, "text": "declare @myColumn as nvarchar(128)\nset @myColumn = 'myColumn'\nif not exists (\n select 1\n from information_schema.columns columns \n where columns.table_catalog = 'myDatabase'\n and columns.table_schema = 'mySchema' \n and columns.table_name = 'myTable' \n and columns.column_name = @myColumn\n )\nbegin\n exec('alter table myDatabase.mySchema.myTable add'\n +' ['+@myColumn+'] bigint null')\nend\n" }, { "answer_id": 5369176, "author": "Martin Smith", "author_id": 73226, "author_profile": "https://Stackoverflow.com/users/73226", "pm_score": 10, "selected": false, "text": "IF COL_LENGTH('table_name','column_name') IS NULL\nBEGIN\n/* Column does not exist or caller does not have permission to view the object */\nEND\n COL_LENGTH COL_LENGTH('AdventureWorks2012.HumanResources.Department','ModifiedDate')\n COL_LENGTH" }, { "answer_id": 6917787, "author": "Joe M", "author_id": 429903, "author_profile": "https://Stackoverflow.com/users/429903", "pm_score": 5, "selected": false, "text": "IF EXISTS\n(\n SELECT *\n FROM INFORMATION_SCHEMA.COLUMNS\n WHERE table_name = 'table_name'\n AND column_name = 'column_name'\n)\nBEGIN\n...\nEND\n" }, { "answer_id": 7610830, "author": "Douglas Tondo", "author_id": 973130, "author_profile": "https://Stackoverflow.com/users/973130", "pm_score": 4, "selected": false, "text": "SELECT COLUMNS.*\nFROM INFORMATION_SCHEMA.COLUMNS COLUMNS,\n INFORMATION_SCHEMA.TABLES TABLES\nWHERE COLUMNS.TABLE_NAME = TABLES.TABLE_NAME\n AND Upper(COLUMNS.COLUMN_NAME) = Upper('column_name') \n" }, { "answer_id": 10450604, "author": "FrostbiteXIII", "author_id": 152617, "author_profile": "https://Stackoverflow.com/users/152617", "pm_score": 4, "selected": false, "text": "if exists (\n select *\n from\n sysobjects, syscolumns\n where\n sysobjects.id = syscolumns.id\n and sysobjects.name = 'table'\n and syscolumns.name = 'column')\n" }, { "answer_id": 15536006, "author": "brazilianldsjaguar", "author_id": 1245766, "author_profile": "https://Stackoverflow.com/users/1245766", "pm_score": 5, "selected": false, "text": "IF OBJECT_ID COLUMNPROPERTY IF (OBJECT_ID(N'[dbo].[myTable]') IS NOT NULL AND\n COLUMNPROPERTY( OBJECT_ID(N'[dbo].[myTable]'), 'ThisColumnDoesNotExist', 'ColumnId') IS NULL)\nBEGIN\n SELECT 'Column does not exist -- You can add TSQL to add the column here'\nEND\n" }, { "answer_id": 16711468, "author": "Nishad", "author_id": 418003, "author_profile": "https://Stackoverflow.com/users/418003", "pm_score": 3, "selected": false, "text": "select distinct object_name(sc.id)\nfrom syscolumns sc,sysobjects so \nwhere sc.name like '%col_name%' and so.type='U'\n" }, { "answer_id": 18764333, "author": "Na30m", "author_id": 2323395, "author_profile": "https://Stackoverflow.com/users/2323395", "pm_score": 4, "selected": false, "text": "IF NOT EXISTS(SELECT NULL\n FROM INFORMATION_SCHEMA.COLUMNS\n WHERE table_name = 'TableName'\n AND table_schema = 'SchemaName'\n AND column_name = 'ColumnName') BEGIN\n\n ALTER TABLE [SchemaName].[TableName] ADD [ColumnName] int(1) NOT NULL default '0';\n\nEND;\n" }, { "answer_id": 23535175, "author": "BYRAKUR SURESH BABU", "author_id": 3592264, "author_profile": "https://Stackoverflow.com/users/3592264", "pm_score": 4, "selected": false, "text": "if exists (\n select * \n from INFORMATION_SCHEMA.COLUMNS \n where TABLE_NAME = '<table_name>' \n and COLUMN_NAME = '<column_name>'\n) begin\n print 'Column you have specified exists'\nend else begin\n print 'Column does not exist'\nend\n" }, { "answer_id": 24674846, "author": "Manuel Alves", "author_id": 251674, "author_profile": "https://Stackoverflow.com/users/251674", "pm_score": 2, "selected": false, "text": "SELECT \n Count(*) AS existFlag \nFROM \n sys.columns \nWHERE \n [name] = N 'ColumnName' \n AND [object_id] = OBJECT_ID(N 'TableName')\n" }, { "answer_id": 27830814, "author": "crokusek", "author_id": 538763, "author_profile": "https://Stackoverflow.com/users/538763", "pm_score": 3, "selected": false, "text": "if (exists(select 1\n from tempdb.sys.columns\n where Name = 'columnName'\n and Object_ID = object_id('tempdb..#tableName')))\nbegin\n...\nend\n" }, { "answer_id": 29285309, "author": "Daniel Barbalace", "author_id": 4076267, "author_profile": "https://Stackoverflow.com/users/4076267", "pm_score": 3, "selected": false, "text": "select *\nfrom Information_Schema.Columns\nwhere Table_Catalog = 'DatabaseName'\n and Table_Schema = 'SchemaName'\n and Table_Name = 'TableName'\n and Column_Name = 'ColumnName'\n" }, { "answer_id": 35418740, "author": "Ali Elmi", "author_id": 1804116, "author_profile": "https://Stackoverflow.com/users/1804116", "pm_score": 3, "selected": false, "text": "INFORMATION_SCHEMA.COLUMNS sys.objects\n sys.columns\n system catalog. SELECT * NULL value IF EXISTS(\n SELECT NULL \n FROM INFORMATION_SCHEMA.COLUMNS\n WHERE\n TABLE_NAME = 'myTableName'\n AND COLUMN_NAME = 'myColumnName'\n ) \n" }, { "answer_id": 36963155, "author": "Pரதீப்", "author_id": 3349551, "author_profile": "https://Stackoverflow.com/users/3349551", "pm_score": 6, "selected": false, "text": "IF ALTER TABLE Table_name DROP COLUMN IF EXISTS Column_name\n" }, { "answer_id": 40632066, "author": "UJS", "author_id": 3373795, "author_profile": "https://Stackoverflow.com/users/3373795", "pm_score": 3, "selected": false, "text": "IF NOT EXISTS (\n SELECT *\n FROM sys.Columns\n WHERE Name = N'QbId'\n AND Object_Id = Object_Id(N'Driver')\n )\nBEGIN\n ALTER TABLE Driver ADD QbId NVARCHAR(20) NULL\nEND\nELSE\nBEGIN\n PRINT 'QbId is already added on Driver'\nEND\n Name ColumnName Object_Id TableName" }, { "answer_id": 44151515, "author": "Arsman Ahmad", "author_id": 6733426, "author_profile": "https://Stackoverflow.com/users/6733426", "pm_score": 4, "selected": false, "text": "IF COL_LENGTH('Table_Name','Column_Name') IS NULL\n BEGIN\n -- Column Not Exists, implement your logic\n END\nELSE\n BEGIN\n -- Column Exists, implement your logic\n END\n" }, { "answer_id": 53066626, "author": "Suraj Kumar", "author_id": 10532500, "author_profile": "https://Stackoverflow.com/users/10532500", "pm_score": 2, "selected": false, "text": "IF EXISTS (SELECT 'Y' FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = <YourTableName> AND COLUMN_NAME = <YourColumnName>)\n BEGIN\n SELECT 'Column Already Exists.'\n END\n ELSE\n BEGIN\n ALTER TABLE <YourTableName> ADD <YourColumnName> <DataType>[Size]\n END\n" }, { "answer_id": 55492045, "author": "Ilangeeran", "author_id": 2223350, "author_profile": "https://Stackoverflow.com/users/2223350", "pm_score": -1, "selected": false, "text": "IF EXISTS(SELECT 1 FROM sys.columns\n WHERE Name = N'columnName'\n AND Object_ID = Object_ID(N'schemaName.tableName'))\n" }, { "answer_id": 56362057, "author": "S Krishna", "author_id": 5850848, "author_profile": "https://Stackoverflow.com/users/5850848", "pm_score": 0, "selected": false, "text": "IF(SELECT COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = 'TableName' AND COLUMN_NAME = 'ColumnName') IS NOT NULL\nPRINT 'Column Exists in the given table';\n" }, { "answer_id": 56933460, "author": "Mohammad Reza Shahrestani", "author_id": 6174449, "author_profile": "https://Stackoverflow.com/users/6174449", "pm_score": 0, "selected": false, "text": "IF EXISTS (\nSELECT *\nFROM INFORMATION_SCHEMA.COLUMNS\nWHERE TABLE_CATALOG = 'Database Name'\nand TABLE_SCHEMA = 'Schema Name'\nand TABLE_NAME = 'Table Name'\nand COLUMN_NAME = 'Column Name'\nand DATA_TYPE = 'Column Type') -- Where statement lines can be deleted.\n\nBEGIN\n -- Column exists in table\nEND\n\nELSE BEGIN\n -- Column does not exist in table\nEND\n" }, { "answer_id": 56998423, "author": "Simone Spagna", "author_id": 2630519, "author_profile": "https://Stackoverflow.com/users/2630519", "pm_score": 3, "selected": false, "text": " USE [Northwind]\n GO\n\n IF NOT EXISTS(SELECT * FROM INFORMATION_SCHEMA.COLUMNS\n WHERE TABLE_NAME = 'Categories'\n AND COLUMN_NAME = 'Note')\n BEGIN\n\n ALTER TABLE Categories ADD Note NVARCHAR(800) NULL\n\n END\n GO\n" }, { "answer_id": 58658810, "author": "Jagjit Singh", "author_id": 7167678, "author_profile": "https://Stackoverflow.com/users/7167678", "pm_score": 3, "selected": false, "text": "BEGIN\n IF (COL_LENGTH('[dbo].[Table]', 'Column ') IS NULL)\n BEGIN\n // Do something\n END\nEND;\n BEGIN\n IF (COL_LENGTH('[dbo].[Table]', 'Column ') IS NOT NULL)\n BEGIN\n // Do something\n END\nEND;\n" }, { "answer_id": 69807248, "author": "Mostafa Bouzari", "author_id": 4575197, "author_profile": "https://Stackoverflow.com/users/4575197", "pm_score": 2, "selected": false, "text": "IF EXISTS\n (\n SELECT *\n FROM INFORMATION_SCHEMA.COLUMNS\n WHERE TABLE_NAME = 'Table Name'\n AND(COLUMN_NAME = 'column 1'\n or COLUMN_NAME = 'column 2'\n or COLUMN_NAME = 'column 3'\n or COLUMN_NAME = 'column 4')\n )\n SELECT 'Column exists in table' AS[Status];\n ELSE\n SELECT 'Column does not exist in table' AS[Status];\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133031", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2631856/" ]
133,051
<p>The CSS rules <code>visibility:hidden</code> and <code>display:none</code> both result in the element not being visible. Are these synonyms?</p>
[ { "answer_id": 133059, "author": "mmaibaum", "author_id": 12213, "author_profile": "https://Stackoverflow.com/users/12213", "pm_score": 7, "selected": false, "text": "display:none visibility:hidden" }, { "answer_id": 133064, "author": "kemiller2002", "author_id": 1942, "author_profile": "https://Stackoverflow.com/users/1942", "pm_score": 12, "selected": true, "text": "display:none visibility:hidden display:none test | <span style=\"[style-tag-value]\">Appropriate style in this tag</span> | test\n [style-tag-value] display:none test | | test\n [style-tag-value] visibility:hidden test |                        | test\n" }, { "answer_id": 133068, "author": "wcm", "author_id": 2173, "author_profile": "https://Stackoverflow.com/users/2173", "pm_score": 4, "selected": false, "text": "display: none Visibility: hidden" }, { "answer_id": 133070, "author": "ConroyP", "author_id": 2287, "author_profile": "https://Stackoverflow.com/users/2287", "pm_score": 4, "selected": false, "text": "display: none visibility: hidden" }, { "answer_id": 133072, "author": "Steven Williams", "author_id": 3294, "author_profile": "https://Stackoverflow.com/users/3294", "pm_score": 4, "selected": false, "text": "visibility:hidden display:none display:none" }, { "answer_id": 133078, "author": "slashnick", "author_id": 21030, "author_profile": "https://Stackoverflow.com/users/21030", "pm_score": 3, "selected": false, "text": "display:none visibility:hidden" }, { "answer_id": 133465, "author": "user22151", "author_id": 22151, "author_profile": "https://Stackoverflow.com/users/22151", "pm_score": 8, "selected": false, "text": "display:none visibility:hidden display:none visibility:hidden" }, { "answer_id": 1511884, "author": "Kip", "author_id": 18511, "author_profile": "https://Stackoverflow.com/users/18511", "pm_score": 7, "selected": false, "text": "1st <a href=\"http://example.com\" style=\"display: none;\">unseen</a> link.<br />\n2nd <a href=\"http://example.com\" style=\"visibility: hidden;\">unseen</a> link.<br />\n3rd <a href=\"http://example.com\" style=\"opacity: 0;\">unseen</a> link. 1st link.\n2nd link.\n3rd unseen link.\n" }, { "answer_id": 8641464, "author": "Shubelal Kumar", "author_id": 1117102, "author_profile": "https://Stackoverflow.com/users/1117102", "pm_score": 3, "selected": false, "text": "\"hidden\" \"display:none\" <div style=\"display:none\">\nContent not display on screen and even space not taken.\n</div>\n\n<div style=\"visibility:hidden\">\nContent not display on screen but it will take space on screen.\n</div>\n" }, { "answer_id": 15748496, "author": "szeryf", "author_id": 7202, "author_profile": "https://Stackoverflow.com/users/7202", "pm_score": 3, "selected": false, "text": "display:none visibility:hidden" }, { "answer_id": 16815684, "author": "Pearl", "author_id": 1920827, "author_profile": "https://Stackoverflow.com/users/1920827", "pm_score": 3, "selected": false, "text": "visibility:hidden display:none" }, { "answer_id": 16815733, "author": "Ramesh", "author_id": 1616992, "author_profile": "https://Stackoverflow.com/users/1616992", "pm_score": 3, "selected": false, "text": "visibility:hidden display:none" }, { "answer_id": 27939784, "author": "Govinda", "author_id": 1037124, "author_profile": "https://Stackoverflow.com/users/1037124", "pm_score": 6, "selected": false, "text": "<div id=\"parent\" style=\"display:none;\">\n <div id=\"child\" style=\"display:block;\"></div>\n</div>\n <div id=\"parent\" style=\"visibility:hidden;\">\n <div id=\"child\" style=\"visibility:visible;\"></div>\n</div>\n" }, { "answer_id": 46508167, "author": "Dave Burton", "author_id": 562862, "author_profile": "https://Stackoverflow.com/users/562862", "pm_score": 2, "selected": false, "text": "visibility:hidden display:none" }, { "answer_id": 48495293, "author": "Anu", "author_id": 7635131, "author_profile": "https://Stackoverflow.com/users/7635131", "pm_score": 3, "selected": false, "text": "display: none; \n visibility: hidden; \n visibility: hidden display: none" }, { "answer_id": 48605686, "author": "Pritam Bohra", "author_id": 5924007, "author_profile": "https://Stackoverflow.com/users/5924007", "pm_score": 1, "selected": false, "text": "display:none; visibility:hidden;" }, { "answer_id": 56656570, "author": "Adam Jagosz", "author_id": 6805143, "author_profile": "https://Stackoverflow.com/users/6805143", "pm_score": 2, "selected": false, "text": "display: none clientWidth clientHeight offsetWidth offsetHeight scrollWidth scrollHeight getBoundingClientRect() getComputedStyle() 0 visibility: hidden innerText innerHTML" }, { "answer_id": 60529804, "author": "cleaver", "author_id": 544887, "author_profile": "https://Stackoverflow.com/users/544887", "pm_score": 3, "selected": false, "text": "display: none; visibility: hidden; text-indent: -9999px; text-indent {\n clip: rect(1px, 1px, 1px, 1px);\n clip-path: inset(50%);\n height: 1px;\n width: 1px;\n margin: -1px;\n overflow: hidden;\n padding: 0;\n position: absolute;\n}\n" }, { "answer_id": 65146086, "author": "Seshu Vuggina", "author_id": 2752905, "author_profile": "https://Stackoverflow.com/users/2752905", "pm_score": 3, "selected": false, "text": "#element {\n z-index: -11111;\n}\n #element {\n position: absolute; \n top: -9999em;\n left: -9999em;\n}\n visibility: hidden display: none opacity: 0 visibility: hidden visibility: hidden visibility: visible display: none display: block visibility: hidden opacity: 0" }, { "answer_id": 69533380, "author": "cmcnphp", "author_id": 15392319, "author_profile": "https://Stackoverflow.com/users/15392319", "pm_score": 1, "selected": false, "text": "visibility:hidden display:none visibility:hidden display:none display: block | flex | inline | grid | inline-block" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133051", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14749/" ]
133,081
<p>In MS SQL 2000 and 2005, given a datetime such as '2008-09-25 12:34:56' what is the most efficient way to get a datetime containing only '2008-09-25'?</p> <p>Duplicated <a href="https://stackoverflow.com/questions/2775/whats-the-best-way-to-remove-the-time-portion-of-a-datetime-value-sql-server">here</a>.</p>
[ { "answer_id": 133101, "author": "George Mastros", "author_id": 1408129, "author_profile": "https://Stackoverflow.com/users/1408129", "pm_score": 5, "selected": false, "text": "Select DateAdd(Day, DateDiff(Day, 0, GetDate()), 0)\n Select DateAdd(Year, DateDiff(Year, 0, GetDate()), 0)\nSelect DateAdd(Quarter, DateDiff(Quarter, 0, GetDate()), 0)\nSelect DateAdd(Month, DateDiff(Month, 0, GetDate()), 0)\nSelect DateAdd(Day, DateDiff(Day, 0, GetDate()), 0)\nSelect DateAdd(Hour, DateDiff(Hour, 0, GetDate()), 0)\nSelect DateAdd(Second, DateDiff(Second, '20000101', GetDate()), '20000101')\n" }, { "answer_id": 133104, "author": "Matt Howells", "author_id": 16881, "author_profile": "https://Stackoverflow.com/users/16881", "pm_score": 4, "selected": false, "text": "select cast(floor(cast(@datetime as float)) as datetime)\n" }, { "answer_id": 133126, "author": "Erick B", "author_id": 1373, "author_profile": "https://Stackoverflow.com/users/1373", "pm_score": 0, "selected": false, "text": "select convert(varchar(10), getdate(), 120)\n select convert(datetime, convert(varchar(10), getdate(), 120) , 120)\n" }, { "answer_id": 133144, "author": "Turnkey", "author_id": 13144, "author_profile": "https://Stackoverflow.com/users/13144", "pm_score": -1, "selected": false, "text": "CONVERT(VARCHAR(10), GETDATE(), 120) AS [YYYY-MM-DD]\n" }, { "answer_id": 150722, "author": "Tomas", "author_id": 23360, "author_profile": "https://Stackoverflow.com/users/23360", "pm_score": 8, "selected": true, "text": "SELECT TOP 1000000 CRETS FROM tblMeasureLogv2 \nSELECT TOP 1000000 CAST(FLOOR(CAST(CRETS AS FLOAT)) AS DATETIME) FROM tblMeasureLogv2\nSELECT TOP 1000000 CONVERT(DATETIME, CONVERT(VARCHAR(10), CRETS, 120) , 120) FROM tblMeasureLogv2 \nSELECT TOP 1000000 DATEADD(DAY, DATEDIFF(DAY, 0, CRETS), 0) FROM tblMeasureLogv2\n Pure-Select: 422\nFloor-cast: 625\nString-conv: 1953\nDateAdd: 531 \n" }, { "answer_id": 309178, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "select cast(getdate()as varchar(11))as datetime\n" }, { "answer_id": 4426027, "author": "Andrew dh", "author_id": 210985, "author_profile": "https://Stackoverflow.com/users/210985", "pm_score": 0, "selected": false, "text": "CAST(FLOOR(CAST(yourdate AS DECIMAL(12, 5))) AS DATETIME)" }, { "answer_id": 8414809, "author": "Rafael", "author_id": 1085537, "author_profile": "https://Stackoverflow.com/users/1085537", "pm_score": -1, "selected": false, "text": "SELECT CAST(CASt(GETDATE() AS int) AS DATETIME)" }, { "answer_id": 29262113, "author": "BrianMichaels", "author_id": 2048219, "author_profile": "https://Stackoverflow.com/users/2048219", "pm_score": 3, "selected": false, "text": "select cast(getdate() as date)\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133081", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16881/" ]
133,087
<p>Note: not ASP.NET.</p> <p>I've read about various methods including using SOAPClient (is this part of the standard Windows 2003 install?), ServerXMLHTTP, and building up the XML from scratch and parsing the result manually.</p> <p>Has anyone ever done this? What did you use and would you recommend it?</p>
[ { "answer_id": 133366, "author": "pdavis", "author_id": 7819, "author_profile": "https://Stackoverflow.com/users/7819", "pm_score": 2, "selected": false, "text": "<% \n SoapUrl = \"http://www.yourdomain.com/yourwebservice.asmx\" \n set xmlhttp = CreateObject(\"MSXML2.ServerXMLHTTP\") \n xmlhttp.open \"GET\", SoapUrl, false \n xmlhttp.send()\n Response.write xmlhttp.responseText \n set xmlhttp = nothing \n%>\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133087", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9825/" ]
133,092
<p>I have an XPath expression which provides me a sequence of values like the one below:</p> <p><code>1 2 2 3 4 5 5 6 7</code></p> <p>This is easy to convert to a sequence of unique values <code>1 2 3 4 5 6 7</code> using <code>distinct-values()</code>. However, what I want to extract is the list of duplicate values = <code>2 5</code>. I can't think of an easy way to do this. Can anyone help?</p>
[ { "answer_id": 134986, "author": "JeniT", "author_id": 6739, "author_profile": "https://Stackoverflow.com/users/6739", "pm_score": 2, "selected": false, "text": "distinct-values(\n for $item in $seq\n return if (count($seq[. eq $item]) > 1)\n then $item\n else ())\n distinct-values()" }, { "answer_id": 146713, "author": "mike", "author_id": 19217, "author_profile": "https://Stackoverflow.com/users/19217", "pm_score": 0, "selected": false, "text": " <xsl:for-each select=\"/r/a\">\n <xsl:variable name=\"cur\" select=\".\" />\n <xsl:if test=\"count(./preceding-sibling::a[. = $cur]) > 0 and count(./following-sibling::a[. = $cur]) = 0\">\n <xsl:value-of select=\".\" />\n </xsl:if>\n </xsl:for-each>\n" }, { "answer_id": 287360, "author": "Dimitre Novatchev", "author_id": 36305, "author_profile": "https://Stackoverflow.com/users/36305", "pm_score": 5, "selected": false, "text": "$vSeq[index-of($vSeq,.)[2]]\n $vSeq $vSeq = 1, 2, 3, 2, 4, 5, 6, 7, 5, 7, 5\n 2, 5, 7" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133092", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
133,111
<p>I need to increment a number in a source file from an Ant build script. I can use the <code><a href="http://ant.apache.org/manual/Tasks/replaceregexp.html" rel="nofollow noreferrer">ReplaceRegExp</a></code> task to find the number I want to increment, but how do I then increment that number within the <code>replace</code> attribute?</p> <p>Heres what I've got so far:</p> <pre><code>&lt;replaceregexp file="${basedir}/src/path/to/MyFile.java" match="MY_PROPERTY = ([0-9]{1,});" replace="MY_PROPERTY = \1;"/&gt; </code></pre> <p>In the replace attribute, how would I do </p> <pre><code>replace="MY_PROPERTY = (\1 + 1);" </code></pre> <p>I can't use the <code>buildnumber</code> task to store the value in a file since I'm already using that within the same build target. Is there another ant task that will allow me to increment a property?</p>
[ { "answer_id": 133159, "author": "Yuval F", "author_id": 1702, "author_profile": "https://Stackoverflow.com/users/1702", "pm_score": 3, "selected": true, "text": "<propertyfile file=\"${version-file}\">\n <entry key=\"revision\" type=\"string\" operation=\"=\" value=\"${revision}\" />\n <entry key=\"build\" type=\"int\" operation=\"+\" value=\"1\" />" }, { "answer_id": 134535, "author": "bsanders", "author_id": 22200, "author_profile": "https://Stackoverflow.com/users/22200", "pm_score": 2, "selected": false, "text": " <property name=\"propertiesFile\" location=\"test-file.txt\"/>\n\n <script language=\"javascript\">\n regex = /.*MY_PROPERTY = (\\d+).*/;\n\n t = java.io.File.createTempFile('test-file', 'txt');\n w = new java.io.PrintWriter(t);\n f = new java.io.File(propertiesFile);\n r = new java.io.BufferedReader(new java.io.FileReader(f));\n line = r.readLine();\n while (line != null) {\n m = regex.exec(line);\n if (m) {\n val = parseInt(m[1]) + 1;\n line = 'MY_PROPERTY = ' + val;\n }\n w.println(line);\n line = r.readLine();\n }\n r.close();\n w.close();\n\n f.delete();\n t.renameTo(f);\n </script>\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133111", "https://Stackoverflow.com", "https://Stackoverflow.com/users/270/" ]
133,122
<p>I want to make a .NET Form as a TopMost Form for another external App (not .NET related, pure Win32) so it stays above that Win32App, but not the rest of the apps running.</p> <p>I Have the handle of the Win32App (provided by the Win32App itself), and I've tried <a href="http://msdn.microsoft.com/en-us/library/ms633541(VS.85).aspx" rel="noreferrer">Win32 SetParent() function</a>, via <a href="http://www.pinvoke.net/default.aspx/user32/SetParent.html" rel="noreferrer">P/Invoke in C#</a>, but then my .NET Form gets confined into the Win32App and that's not what I want.</p>
[ { "answer_id": 133415, "author": "Joel Lucsy", "author_id": 645, "author_profile": "https://Stackoverflow.com/users/645", "pm_score": 5, "selected": true, "text": "SetWindowLongPtr(win32window, GWLP_HWNDPARENT, formhandle)" }, { "answer_id": 133496, "author": "Ricardo Amores", "author_id": 10136, "author_profile": "https://Stackoverflow.com/users/10136", "pm_score": 2, "selected": false, "text": "SetWindowLongPtr(childHdl, -8, OwnerHdl)\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133122", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10136/" ]
133,129
<p>I use <em>Eclipse 3.3</em> in my daily work, and have also used <em>Eclipse 3.2</em> extensively as well. In both versions, sometimes the Search options (Java Search, File Search, etc) in the menu get disabled, seemingly at random times. However, with <kbd>Ctrl</kbd>+<kbd>H</kbd>, I am able to access the search functionality. Does anyone know why this happens? Has it been fixed in <em>Eclipse 3.4</em>?</p>
[ { "answer_id": 12950138, "author": "mehmet", "author_id": 1755622, "author_profile": "https://Stackoverflow.com/users/1755622", "pm_score": 3, "selected": false, "text": "org.eclipse.search workspace/metadata/plugins" }, { "answer_id": 18730989, "author": "Eric L.", "author_id": 1007619, "author_profile": "https://Stackoverflow.com/users/1007619", "pm_score": 3, "selected": false, "text": "Window -> Close All Perspectives -clean" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133129", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8026/" ]
133,154
<p>While normally it's good to always choose the right language for the job, it can sometimes be instructive to try and do something in a language which is wildly inappropriate.</p> <ol> <li>It can help you understand the problem better. Maybe you don't <em>have</em> to solve it the way you thought you did.</li> <li>It can help you understand the language better. Maybe it supports more features than you realized.</li> </ol> <p>And pushing this idea to it's illogical conclusion...how would you implement quicksort in a batch file? Is it even possible?</p>
[ { "answer_id": 133155, "author": "Cody Hatch", "author_id": 17086, "author_profile": "https://Stackoverflow.com/users/17086", "pm_score": 6, "selected": true, "text": "@echo off\nSETLOCAL ENABLEDELAYEDEXPANSION\n\ncall :qSort %*\nfor %%i in (%return%) do set results=!results! %%i\necho Sorted result: %results%\nENDLOCAL\ngoto :eof\n\n:qSort\nSETLOCAL\n set list=%*\n set size=0\n set less=\n set greater=\n for %%i in (%*) do set /a size=size+1\n if %size% LEQ 1 ENDLOCAL & set return=%list% & goto :eof\n for /f \"tokens=2* delims== \" %%i in ('set list') do set p=%%i & set body=%%j\n for %%x in (%body%) do (if %%x LEQ %p% (set less=%%x !less!) else (set greater=%%x !greater!))\n call :qSort %less%\n set sorted=%return%\n call :qSort %greater%\n set sorted=%sorted% %p% %return%\nENDLOCAL & set return=%sorted%\ngoto :eof\n C:\\dev\\sorting>qsort.bat 1 3 5 1 12 3 47 3\nSorted result: 1 1 3 3 3 5 12 47\n" }, { "answer_id": 4965421, "author": "Thought", "author_id": 117095, "author_profile": "https://Stackoverflow.com/users/117095", "pm_score": 3, "selected": false, "text": "@echo off\n\necho Sorting: %*\n\nset sorted=\n\n:sort\n:: If we've only got one left, we're done.\nif \"%2\"==\"\" (\n set sorted=%sorted% %1\n :: We have to do this so that sorted gets actually set before we print it.\n goto :finalset\n)\n:: Check if it's in order.\nif %1 LEQ %2 (\n :: Add the first value to sorted.\n set sorted=%sorted% %1\n shift /1\n goto :sort\n)\n:: Out of order.\n:: Reverse them and recursively resort.\nset redo=%sorted% %2 %1\nset sorted=\nshift /1\nshift /1\n:loop\nif \"%1\"==\"\" goto :endloop\nset redo=%redo% %1\nshift /1\ngoto :loop\n:endloop\ncall :sort %redo%\n:: When we get here, we'll have already echod our result.\ngoto :eof\n\n:finalset\necho Final Sort: %sorted%\ngoto :eof\n C:\\Path> sort 19 zebra blah 1 interesting 21 bleh 14 think 2 ninety figure it out\n Sorting: 19 zebra blah 1 interesting 21 bleh 14 think 2 ninety figure it out\nFinal Sort: 1 2 14 19 21 blah bleh figure interesting it ninety out think zebra\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133154", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17086/" ]
133,173
<p>In a previous job we had a classic ASP application that no one wanted to migrate to ASP.NET. The things that it did, it did very well. </p> <p>However there was some new functionality that needed to be added that just seemed best suited to ASP.NET. The decision was made to allow the system to become a weird hybrid of ASP and ASP.NET. </p> <p>Our biggest sticking point was session management and we hacked together a solution to pass session values through form variables. I've talked to others that handled this same problem through cookies.</p> <p>Both methods seem a horrible kluge (in addition to being terribly insecure). </p> <p>Is there a better or cleaner way or is this just such a bad idea to begin with that discussion on the topic is pointless?</p>
[ { "answer_id": 69920723, "author": "eliteproxy", "author_id": 2948862, "author_profile": "https://Stackoverflow.com/users/2948862", "pm_score": 1, "selected": false, "text": " <system.webServer>\n <modules>\n <remove name=\"FormsAuthenticationModule\" />\n <add name=\"FormsAuthenticationModule\" type=\"System.Web.Security.FormsAuthenticationModule\" />\n <remove name=\"UrlAuthorization\" />\n <add name=\"UrlAuthorization\" type=\"System.Web.Security.UrlAuthorizationModule\" />\n <remove name=\"DefaultAuthentication\" />\n <add name=\"DefaultAuthentication\" type=\"System.Web.Security.DefaultAuthenticationModule\" />\n <remove name=\"Session\" />\n <add name=\"Session\" type=\"Microsoft.AspNet.SessionState.SessionStateModuleAsync, Microsoft.AspNet.SessionState.SessionStateModule, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35\" preCondition=\"integratedMode\" />\n </modules>\n </system.webServer> \n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133173", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2173/" ]
133,194
<p>I am trying to make an Outlook 2003 add-in using Visual Studio 2008 on Windows XP SP3 and Internet Explorer 7.</p> <p>My add-in is using custom Folder Home Page which displays my custom form, which wraps Outlook View Control.</p> <p>I get COM Exception with 'Exception from HRESULT: 0xXXXXXXXX' description every time when I try to set Folder property of the OVC. Error code is a random number, every time is different. It is not the first access to control's properties, before that, View and ViewXML properties are set already. Control is marked as Safe for Scripting.</p> <p>I am using value of the CurrentFolder.FolderPath property of the active explorer, which seems to be a right one:</p> <pre><code>Outlook.Explorer currentExplorer = app.ActiveExplorer(); if (currentExplorer != null) { ovcWrapper.Folder = currentExplorer.CurrentFolder.FolderPath; } </code></pre> <p>This is top of the stack trace:</p> <pre><code>System.Runtime.InteropServices.COMException (0xXXXXXXXX): Exception from HRESULT: 0xXXXXXXXX at Microsoft.Office.Interop.OutlookViewCtl.ViewCtlClass.set_Folder(String pVal) at AxMicrosoft.Office.Interop.OutlookViewCtl.AxViewCtl.set_Folder(String value).. </code></pre> <p>This is happening only if the folder is located in non-default PST file. Changing to folder inside default PST file will produce no exception.</p> <p>I must underline that everything worked just fine before I went to holiday :). It seems that Windows XP installed some updates which changed default security of Internet Explorer or Outlook 2003 while I was absent.</p> <p>On the other (virtual machine) with Office 2007 and Internet Explorer 6, without any updates, everything is working just fine.</p>
[ { "answer_id": 139934, "author": "BKimmel", "author_id": 13776, "author_profile": "https://Stackoverflow.com/users/13776", "pm_score": 1, "selected": false, "text": "app.Session.Logon() \n app.ActiveExplorer()" }, { "answer_id": 158035, "author": "Nenad Dobrilovic", "author_id": 22062, "author_profile": "https://Stackoverflow.com/users/22062", "pm_score": 3, "selected": true, "text": "session.AddStore(\"C:\\\\test.pst\"); // loads existing or creates a new one, if there is none.\nstorage = session.Folders.GetLast(); // grabs root folder of the new fileStorage.\n\nif (storage.Name != storageName) // if fileStorage is brand new, it has default name.\n{\n storage.Name = \"Documents\";\n session.RemoveStore(storage); // to apply new fileStorage name, it have to be removed and added again.\n session.AddStore(storagePath);\n }\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133194", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22062/" ]
133,204
<p>How do I get a list of the files checked out by users (including the usernames) using P4V or P4? </p> <p>I want to provide a depot location and see a list of any files under that location (including sub folders) that are checked out.</p>
[ { "answer_id": 133222, "author": "Iain", "author_id": 20457, "author_profile": "https://Stackoverflow.com/users/20457", "pm_score": 5, "selected": false, "text": "p4 opened -a //depot/Your/Location/...\n" }, { "answer_id": 133249, "author": "Mark", "author_id": 4405, "author_profile": "https://Stackoverflow.com/users/4405", "pm_score": 4, "selected": false, "text": "p4 opened -C <client-spec> //depot/...\n p4 opened //depot/...\n" }, { "answer_id": 9526051, "author": "ForceMagic", "author_id": 62921, "author_profile": "https://Stackoverflow.com/users/62921", "pm_score": 3, "selected": false, "text": "p4 opened -a //myP4Path/dev_project\n p4 opened -a //myP4Path/dev_project/...\n" }, { "answer_id": 11683080, "author": "eeerahul", "author_id": 976554, "author_profile": "https://Stackoverflow.com/users/976554", "pm_score": 3, "selected": false, "text": "p4 opened -u the_user_name\n p4 opened -u the_user_name -c cl_number\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133204", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20457/" ]
133,214
<p>We need to implement a simple state machine in <strong>C</strong>.<br> Is a standard switch statement the best way to go?<br> We have a current state (state) and a trigger for the transition.</p> <pre><code> switch(state) { case STATE_1: state = DoState1(transition); break; case STATE_2: state = DoState2(transition); break; } ... DoState2(int transition) { // Do State Work ... if(transition == FROM_STATE_2) { // New state when doing STATE 2 -> STATE 2 } if(transition == FROM_STATE_1) { // New State when moving STATE 1 -> STATE 2 } return new_state; } </code></pre> <p>Is there a better way <strong>for simple state machines</strong></p> <p>EDIT: For C++, I think the Boost <a href="http://www.boost.org/doc/libs/1_36_0/libs/statechart/doc/index.html" rel="noreferrer">Statechart</a> library might be the way to go. However, it does <strong>not</strong> help with C. Lets concentrate on the C use case.</p>
[ { "answer_id": 133301, "author": "Mark", "author_id": 4405, "author_profile": "https://Stackoverflow.com/users/4405", "pm_score": 2, "selected": false, "text": "static int current_state; // should always hold current state -- and probably be an enum or something\n\nvoid state_leave(int new_state) {\n // do processing on what it means to enter the new state\n // which might be dependent on the current state\n}\n\nvoid state_enter(int new_state) {\n // do processing on what is means to leave the current state\n // might be dependent on the new state\n\n current_state = new_state;\n}\n\nvoid state_process() {\n // switch statement to handle current state\n}\n \n" }, { "answer_id": 133361, "author": "Frank Szczerba", "author_id": 8964, "author_profile": "https://Stackoverflow.com/users/8964", "pm_score": 8, "selected": true, "text": "typedef enum { STATE_INITIAL, STATE_FOO, STATE_BAR, NUM_STATES } state_t;\ntypedef struct instance_data instance_data_t;\ntypedef state_t state_func_t( instance_data_t *data );\n\nstate_t do_state_initial( instance_data_t *data );\nstate_t do_state_foo( instance_data_t *data );\nstate_t do_state_bar( instance_data_t *data );\n\nstate_func_t* const state_table[ NUM_STATES ] = {\n do_state_initial, do_state_foo, do_state_bar\n};\n\nstate_t run_state( state_t cur_state, instance_data_t *data ) {\n return state_table[ cur_state ]( data );\n};\n\nint main( void ) {\n state_t cur_state = STATE_INITIAL;\n instance_data_t data;\n\n while ( 1 ) {\n cur_state = run_state( cur_state, &data );\n\n // do other program logic, run other state machines, etc\n }\n}\n typedef void transition_func_t( instance_data_t *data );\n\nvoid do_initial_to_foo( instance_data_t *data );\nvoid do_foo_to_bar( instance_data_t *data );\nvoid do_bar_to_initial( instance_data_t *data );\nvoid do_bar_to_foo( instance_data_t *data );\nvoid do_bar_to_bar( instance_data_t *data );\n\ntransition_func_t * const transition_table[ NUM_STATES ][ NUM_STATES ] = {\n { NULL, do_initial_to_foo, NULL },\n { NULL, NULL, do_foo_to_bar },\n { do_bar_to_initial, do_bar_to_foo, do_bar_to_bar }\n};\n\nstate_t run_state( state_t cur_state, instance_data_t *data ) {\n state_t new_state = state_table[ cur_state ]( data );\n transition_func_t *transition =\n transition_table[ cur_state ][ new_state ];\n\n if ( transition ) {\n transition( data );\n }\n\n return new_state;\n};\n" }, { "answer_id": 133363, "author": "Remo.D", "author_id": 16827, "author_profile": "https://Stackoverflow.com/users/16827", "pm_score": 5, "selected": false, "text": "FSM {\n STATE(x) {\n ...\n NEXTSTATE(y);\n }\n\n STATE(y) {\n ...\n if (x == 0) \n NEXTSTATE(y);\n else \n NEXTSTATE(x);\n }\n}\n #define FSM\n#define STATE(x) s_##x :\n#define NEXTSTATE(x) goto s_##x\n FSMFILE #define FSM\n#define STATE(x) s_##x : FSMCHR = fgetc(FSMFILE); sn_##x :\n#define NEXTSTATE(x) goto s_##x\n#define NEXTSTATE_NR(x) goto sn_##x\n #define STATE(x) s_##x : if ((FSMCHR = fgetc(FSMFILE) == EOF)\\\n goto sx_endfsm;\\\n sn_##x :\n\n#define ENDFSM sx_endfsm:\n state" }, { "answer_id": 135505, "author": "jsl4980", "author_id": 21756, "author_profile": "https://Stackoverflow.com/users/21756", "pm_score": 3, "selected": false, "text": "typedef enum\n{\n STATE_1 = 0,\n STATE_2,\n STATE_3\n} my_state_t;\n\nmy_state_t state = STATE_1;\n\nvoid foo(char input)\n{\n ...\n switch(state)\n {\n case STATE_1:\n if(input)\n state = STATE_2;\n break;\n case STATE_2:\n if(input)\n state = STATE_3;\n else\n state = STATE_1;\n break;\n case STATE_3:\n ...\n break;\n }\n ...\n}\n" }, { "answer_id": 136055, "author": "Commodore Jaeger", "author_id": 4659, "author_profile": "https://Stackoverflow.com/users/4659", "pm_score": 2, "selected": false, "text": "/* Implement each state as a function with the same prototype */\nvoid state_one(int set, int reset);\nvoid state_two(int set, int reset);\n\n/* Store a pointer to the next state */\nvoid (*next_state)(int set, int reset) = state_one;\n\n/* Users should call next_state(set, reset). This could\n also be wrapped by a real function that validated input\n and dealt with output rather than calling the function\n pointer directly. */\n\n/* State one transitions to state one if set is true */\nvoid state_one(int set, int reset) {\n if(set)\n next_state = state_two;\n}\n\n/* State two transitions to state one if reset is true */\nvoid state_two(int set, int reset) {\n if(reset)\n next_state = state_one;\n}\n" }, { "answer_id": 9322528, "author": "Josh Petitt", "author_id": 1131254, "author_profile": "https://Stackoverflow.com/users/1131254", "pm_score": 4, "selected": false, "text": "struct state;\ntypedef void (*state_func_t)( struct state* );\n\ntypedef struct state\n{\n state_func_t function;\n\n // other stateful data\n\n} state_t;\n\nvoid do_state_initial( state_t* );\nvoid do_state_foo( state_t* );\nvoid do_state_bar( state_t* );\n\nvoid run_state( state_t* i ) {\n i->function(i);\n};\n\nint main( void ) {\n state_t state = { do_state_initial };\n\n while ( 1 ) {\n run_state( state );\n\n // do other program logic, run other state machines, etc\n }\n}\n #define RUN_STATE(state_ptr_) ((state_ptr_)->function(state_ptr_))\n" }, { "answer_id": 16756582, "author": "Phileo99", "author_id": 923920, "author_profile": "https://Stackoverflow.com/users/923920", "pm_score": 2, "selected": false, "text": "#define STATE (void *)\ntypedef enum fsmSignal\n{\n eEnter =0,\n eNormal,\n eExit\n}FsmSignalT;\n\ntypedef struct fsm \n{\n FsmSignalT signal;\n // StateT is an enum that you can define any which way you want\n StateT currentState;\n}FsmT;\nextern int STATECTXT_Init(void);\n/* optionally allow client context to set the target state */\nextern STATECTXT_Set(StateT stateID);\nextern void STATECTXT_Handle(void *pvEvent);\n #include \"stateCtxt.h\"\n#include \"statehandlers.h\"\n\ntypedef STATE (*pfnStateT)(FsmSignalT signal, void *pvEvent);\n\nstatic FsmT fsm;\nstatic pfnStateT UsbState ;\n\nint STATECTXT_Init(void)\n{ \n UsbState = State1;\n fsm.signal = eEnter;\n // use an enum for better maintainability\n fsm.currentState = '1';\n (*UsbState)( &fsm, pvEvent);\n return 0;\n}\n\nstatic void ChangeState( FsmT *pFsm, pfnStateT targetState )\n{\n // Check to see if the state has changed\n if (targetState != NULL)\n {\n // Call current state's exit event\n pFsm->signal = eExit;\n STATE dummyState = (*UsbState)( pFsm, pvEvent);\n\n // Update the State Machine structure\n UsbState = targetState ;\n\n // Call the new state's enter event\n pFsm->signal = eEnter; \n dummyState = (*UsbState)( pFsm, pvEvent);\n }\n}\n\nvoid STATECTXT_Handle(void *pvEvent)\n{\n pfnStateT newState;\n\n if (UsbState != NULL)\n {\n fsm.signal = eNormal;\n newState = (*UsbState)( &fsm, pvEvent );\n ChangeState( &fsm, newState );\n } \n}\n\n\nvoid STATECTXT_Set(StateT stateID)\n{\n prevState = UsbState;\n switch (stateID) \n {\n case '1': \n ChangeState( State1 );\n break;\n case '2':\n ChangeState( State2);\n break;\n case '3':\n ChangeState( State3);\n break;\n }\n}\n /* define state handlers */\nextern STATE State1(void);\nextern STATE State2(void);\nextern STATE State3(void);\n #include \"stateCtxt.h:\"\n\n/* Define behaviour to given set of inputs */\nSTATE State1(FsmT *fsm, void *pvEvent)\n{ \n STATE nextState;\n /* do some state specific behaviours \n * here\n */\n /* fsm->currentState currently contains the previous state\n * just before it gets updated, so you can implement behaviours \n * which depend on previous state here\n */\n fsm->currentState = '1';\n /* Now, specify the next state\n * to transition to, or return null if you're still waiting for \n * more stuff to process. \n */\n switch (fsm->signal)\n {\n case eEnter:\n nextState = State2;\n break;\n case eNormal:\n nextState = null;\n break;\n case eExit:\n nextState = State2;\n break;\n }\n\n return nextState;\n}\n\nSTATE State3(FsmT *fsm, void *pvEvent)\n{\n /* do some state specific behaviours \n * here\n */\n fsm->currentState = '2';\n /* Now, specify the next state\n * to transition to\n */\n return State1;\n}\n\nSTATE State2(FsmT *fsm, void *pvEvent)\n{ \n /* do some state specific behaviours \n * here\n */\n fsm->currentState = '3';\n /* Now, specify the next state\n * to transition to\n */\n return State3;\n}\n" }, { "answer_id": 29162318, "author": "Seb", "author_id": 4693156, "author_profile": "https://Stackoverflow.com/users/4693156", "pm_score": 1, "selected": false, "text": "__COUNTER__ #define START 0 \n #define END 1000\n\n int run = 1;\n state = START; \n while(run)\n {\n switch (state)\n {\n case __COUNTER__:\n //do something\n state++;\n break;\n case __COUNTER__:\n //do something\n if (input)\n state = END;\n else\n state++;\n break;\n .\n .\n .\n case __COUNTER__:\n //do something\n if (input)\n state = START;\n else\n state++;\n break;\n case __COUNTER__:\n //do something\n state++;\n break;\n case END:\n //do something\n run = 0;\n state = START;\n break;\n default:\n state++;\n break;\n } \n } \n __COUNTER__ __COUNTER__ __LINE__" }, { "answer_id": 29933134, "author": "user153222", "author_id": 1974188, "author_profile": "https://Stackoverflow.com/users/1974188", "pm_score": 2, "selected": false, "text": "struct State {\n unsigned long Out; // 6-bit pattern to output\n unsigned long Time; // delay in 10ms units \n unsigned long Next[4]; // next state for inputs 0,1,2,3\n}; \n\ntypedef const struct State STyp;\n\n//this example has 4 states, defining constants/symbols using #define\n#define goN 0\n#define waitN 1\n#define goE 2\n#define waitE 3\n\n\n//this is the full FSM logic coded into one large array of output values, delays, \n//and next states (indexed by values of the inputs)\nSTyp FSM[4]={\n {0x21,3000,{goN,waitN,goN,waitN}}, \n {0x22, 500,{goE,goE,goE,goE}},\n {0x0C,3000,{goE,goE,waitE,waitE}},\n {0x14, 500,{goN,goN,goN,goN}}};\nunsigned long currentState; // index to the current state \n\n//super simple controller follows\nint main(void){ volatile unsigned long delay;\n//embedded micro-controller configuration omitteed [...]\n currentState = goN; \n while(1){\n LIGHTS = FSM[currentState].Out; // set outputs lines (from FSM table)\n SysTick_Wait10ms(FSM[currentState].Time);\n currentState = FSM[currentState].Next[INPUT_SENSORS]; \n }\n}\n" }, { "answer_id": 44955234, "author": "Fuhrmanator", "author_id": 1168342, "author_profile": "https://Stackoverflow.com/users/1168342", "pm_score": 4, "selected": false, "text": "public void HandleEvent(PhoneEvent anEvent) {\n switch (CurrentState) {\n case PhoneState.ScreenOff:\n switch (anEvent) {\n case PhoneEvent.PressButton:\n if (powerLow) { // guard condition\n DisplayLowPowerMessage(); // action\n // CurrentState = PhoneState.ScreenOff;\n } else {\n CurrentState = PhoneState.ScreenOn;\n }\n break;\n case PhoneEvent.PlugPower:\n CurrentState = PhoneState.ScreenCharging;\n break;\n }\n break;\n case PhoneState.ScreenOn:\n switch (anEvent) {\n case PhoneEvent.PressButton:\n CurrentState = PhoneState.ScreenOff;\n break;\n case PhoneEvent.PlugPower:\n CurrentState = PhoneState.ScreenCharging;\n break;\n }\n break;\n case PhoneState.ScreenCharging:\n switch (anEvent) {\n case PhoneEvent.UnplugPower:\n CurrentState = PhoneState.ScreenOff;\n break;\n }\n break;\n }\n}\n" }, { "answer_id": 57513584, "author": "Nandkishor Biradar", "author_id": 2857369, "author_profile": "https://Stackoverflow.com/users/2857369", "pm_score": 1, "selected": false, "text": "state_machine_t //! Abstract state machine structure\nstruct state_machine_t\n{\n uint32_t Event; //!< Pending Event for state machine\n const state_t* State; //!< State of state machine.\n};\n state_t state_t typedef struct finite_state_t state_t;\n\n// finite state structure\ntypedef struct finite_state_t{\n state_handler Handler; //!< State handler function (function pointer)\n state_handler Entry; //!< Entry action for state (function pointer)\n state_handler Exit; //!< Exit action for state (function pointer)\n}finite_state_t;\n dispatch_event state_machine_result_t dispatch_event(state_machine_t* const pState_Machine[], uint32_t quantity);\n state_machine_result_t switch_state(state_machine_t* const, const state_t*);\n\nstate_machine_result_t traverse_state(state_machine_t* const, const state_t*);\n" }, { "answer_id": 68776259, "author": "SaTa", "author_id": 10161091, "author_profile": "https://Stackoverflow.com/users/10161091", "pm_score": 0, "selected": false, "text": "switch /*Demo implementations of State Machines\n *\n * This demo leverages a table driven approach and function pointers\n *\n * Example state machine to be implemented\n *\n * +-----+ Event1 +-----+ Event2 +-----+\n * O---->| A +------------------->| B +------------------->| C |\n * +-----+ +-----+ +-----+\n * ^ |\n * | Event3 |\n * +-----------------------------------------------------+\n *\n * States: A, B, C\n * Events: NoEvent (not shown, holding current state), Event1, Event2, Event3\n *\n * Partly leveraged the example here: http://web.archive.org/web/20160808120758/http://www.gedan.net/2009/03/18/finite-state-machine-matrix-style-c-implementation-function-pointers-addon/\n *\n * This sample code can be compiled and run using GCC.\n * >> gcc -o demo_state_machine demo_state_machine.c\n * >> ./demo_state_machine\n */\n\n#include <stdio.h>\n#include <assert.h>\n\n// Definitions of state id's, event id's, and function pointer\n#define N_STATES 3\n#define N_EVENTS 4\n\ntypedef enum {\n STATE_A,\n STATE_B,\n STATE_C,\n} StateId;\n\ntypedef enum {\n NOEVENT,\n EVENT1,\n EVENT2,\n EVENT3,\n} Event;\ntypedef void (*StateRoutine)();\n\n// Assert on number of states and events defined\nstatic_assert(STATE_C==N_STATES-1,\n \"Number of states does not match defined number of states\");\nstatic_assert(EVENT3==N_EVENTS-1,\n \"Number of events does not match defined number of events\");\n\n// Defining State, holds both state id and state routine\ntypedef struct {\n StateId id;\n StateRoutine routine;\n} State;\n\n// General functions\nvoid evaluate_state(Event e);\n\n// State routines to be executed at each state\nvoid state_routine_a(void);\nvoid state_routine_b(void);\nvoid state_routine_c(void);\n\n// Defining each state with associated state routine\nconst State state_a = {STATE_A, state_routine_a};\nconst State state_b = {STATE_B, state_routine_b};\nconst State state_c = {STATE_C, state_routine_c};\n\n// Defning state transition matrix as visualized in the header (events not\n// defined, result in mainting the same state)\nState state_transition_mat[N_STATES][N_EVENTS] = {\n { state_a, state_b, state_a, state_a},\n { state_b, state_b, state_c, state_b},\n { state_c, state_c, state_c, state_a}};\n\n// Define current state and initialize\nState current_state = state_a;\n\nint main()\n{\n while(1) {\n // Event to receive from user\n int ev;\n\n printf(\"----------------\\n\");\n printf(\"Current state: %c\\n\", current_state.id + 65);\n printf(\"Event to occur: \");\n // Receive event from user\n scanf(\"%u\", &ev);\n evaluate_state((Event) ev); // typecast to event enumeration type\n printf(\"-----------------\\n\");\n };\n return (0);\n}\n\n/*\n * Determine state based on event and perform state routine\n */\nvoid evaluate_state(Event ev)\n{\n //Determine state based on event\n current_state = state_transition_mat[current_state.id][ev];\n printf(\"Transitioned to state: %c\\n\", current_state.id + 65);\n // Run state routine\n (*current_state.routine)();\n}\n\n/*\n * State routines\n */\nvoid state_routine_a() {\n printf(\"State A routine ran. \\n\");\n\n}\nvoid state_routine_b() {\n printf(\"State B routine ran. \\n\");\n}\nvoid state_routine_c() {\n printf(\"State C routine ran. \\n\");\n}\n\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133214", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10703/" ]
133,226
<p>how do i implement an eval script in a sever side control?</p> <p>eg. <code>&lt;a runat="server" href="?id=&lt;%= Eval("Id") %&gt;"&gt;hello world&lt;/a&gt;</code></p>
[ { "answer_id": 133252, "author": "Forgotten Semicolon", "author_id": 1960, "author_profile": "https://Stackoverflow.com/users/1960", "pm_score": 2, "selected": false, "text": "<%# Eval(\"Id\") %>" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133226", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11528/" ]
133,229
<p>I want to discover all xml files that my ClassLoader is aware of using a wildcard pattern. Is there any way to do this?</p>
[ { "answer_id": 133280, "author": "Steve B.", "author_id": 19479, "author_profile": "https://Stackoverflow.com/users/19479", "pm_score": -1, "selected": false, "text": "jar -tvf jarname | grep xml$" }, { "answer_id": 133450, "author": "corlettk", "author_id": 69224, "author_profile": "https://Stackoverflow.com/users/69224", "pm_score": 1, "selected": false, "text": "\nZipSearcher searcher = new ZipSearcher(new ZipInputStream(new FileInputStream(\"my.jar\")));\nList xmlFilenames = searcher.search(new RegexFilenameFilter(\".xml$\"));\n" }, { "answer_id": 138923, "author": "flicken", "author_id": 12880, "author_profile": "https://Stackoverflow.com/users/12880", "pm_score": 3, "selected": false, "text": "ApplicationContext ApplicationContext context = new ClassPathXmlApplicationContext(\"applicationConext.xml\");\n Resource[] xmlResources = context.getResources(\"classpath:/**/*.xml\");\n" }, { "answer_id": 16639899, "author": "Serhat", "author_id": 2399852, "author_profile": "https://Stackoverflow.com/users/2399852", "pm_score": 3, "selected": false, "text": " List<URL> resources = CPScanner.scanResources(new PackageNameFilter(\"net.sf.corn.cps.sample\"), new ResourceNameFilter(\"A*.xml\"));\n <dependency>\n <groupId>net.sf.corn</groupId>\n <artifactId>corn-cps</artifactId>\n <version>1.0.1</version>\n</dependency>\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133229", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
133,236
<p>I am wanting to store the "state" of some actions the user is performing in a series of different ASP.Net webforms. What are my choices for persisting state, and what are the pros/cons of each solution?</p> <p>I have been using Session objects, and using some helper methods to strongly type the objects:</p> <pre><code> public static Account GetCurrentAccount(HttpSessionState session) { return (Account)session[ACCOUNT]; } public static void SetCurrentAccount(Account obj, HttpSessionState session) { session[ACCOUNT] = obj; } </code></pre> <p>I have been told by numerous sources that "Session is evil", so that is really the root cause of this question. I want to know what you think "best practice", and why.</p>
[ { "answer_id": 133259, "author": "Kamiel Wanrooij", "author_id": 4174, "author_profile": "https://Stackoverflow.com/users/4174", "pm_score": 3, "selected": false, "text": "Session" }, { "answer_id": 133274, "author": "Kamiel Wanrooij", "author_id": 4174, "author_profile": "https://Stackoverflow.com/users/4174", "pm_score": 1, "selected": false, "text": "ViewState ViewState" }, { "answer_id": 133298, "author": "Kamiel Wanrooij", "author_id": 4174, "author_profile": "https://Stackoverflow.com/users/4174", "pm_score": 3, "selected": false, "text": "ThreadStatic static Class ThreadStatic System.Web id ThreadStatic Session static" }, { "answer_id": 133368, "author": "Alexander Prokofyev", "author_id": 11256, "author_profile": "https://Stackoverflow.com/users/11256", "pm_score": 2, "selected": false, "text": "public static Account GetCurrentAccount(HttpSessionState session)\n{\n if (Session[ACCOUNT]!=null)\n return (Account)Session[ACCOUNT];\n else\n throw new Exception(\"Can't get current account. Session expired.\");\n}\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133236", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10589/" ]
133,243
<p>I want to have a <code>UIScrollView</code> with a set of subviews where each of these subviews has a <code>UITextView</code> with a different text. For this task, I have modified the <code>PageControl</code> example from the apple "iphone dev center" in order to add it a simple <code>UITextView</code> to the view which is used to generate the subviews of the scroll view. When I run the app (both on the simulator and the phone), NO Text is seen but if i activate the "user interaction" and click on it, the text magically appears (as well as the keyboard).</p> <p>Does anyone has a solution or made any progress with <code>UITextView</code> inside a <code>UIScrollView</code>? Thanks.</p>
[ { "answer_id": 156210, "author": "benzado", "author_id": 10947, "author_profile": "https://Stackoverflow.com/users/10947", "pm_score": 2, "selected": false, "text": "UITextView UIScrollView UIScrollViews" }, { "answer_id": 750977, "author": "filmore", "author_id": 91015, "author_profile": "https://Stackoverflow.com/users/91015", "pm_score": -1, "selected": false, "text": "...\n@interface myRootUIViewController : UIViewController <UIScrollViewDelegate>\n...\n - (void)viewDidLoad {\n ... whatever is created before and/or after...\n\n NSString * text = @\"Lorem ipsum dolor sit amet, consectetur adipiscing elit. \n Nunc semper lacus quis erat. Cras sapien magna, porta non, \n suscipit nec, egestas in, arcu. Maecenas sit amet est. \n Quisque felis risus, tempor eu, dictum ac, volutpat id, \n libero. Ut gravida, purus vitae interdum elementum, tortor \n justo porttitor nisi, id rhoncus massa.\";\n\n // calculate the required frame height according to defined font size and\n // given text\n CGRect frame = CGRectMake(0.0, 500.0, self.view.bounds.size.width, 1000.0); \n CGSize calcSize = [text sizeWithFont:[UIFont systemFontOfSize:13.0]\n constrainedToSize:frame.size lineBreakMode: UILineBreakModeWordWrap];\n // for whatever reasons, contraintedToSize seem only be able to\n // calculate an appropriate height if the input frame height is larger\n // than required. Means: if your text requires height=250 and input\n // frame height=100, then this method won't give you the expected\n // result.\n\n frame.size = calcSize;\n frame.size.height += 0; // calcSize might be not pixel-precise, \n // so add here additional padding pixels\n UITextView * tmpTextView = [[UITextView alloc]initWithFrame:frame];\n\n // do whatever adjustments\n tmpTextView.backgroundColor = [UIColor blueColor]; // show area explicitly (dev \n // purpose)\n self.myTextView = tmpTextView;\n self.myTextView.editable = NO;\n self.myTextView.scrollEnabled = NO;\n self.myTextView.multipleTouchEnabled = NO;\n self.myTextView.userInteractionEnabled = NO; // pass on events to parentview\n self.myTextView.font = [UIFont systemFontOfSize:13.0];\n [tmpTextView release];\n [self.scrollView addSubview:self.myTextView];\n}\n\n...\n\n- (void)scrollViewDidScroll:(UIScrollView *)sender {\n // for simplicity text is repeated again, of course it can be a member var/etc...\n NSString * text = @\"Lorem ipsum dolor sit amet, consectetur adipiscing elit. \n Nunc semper lacus quis erat. Cras sapien magna, porta non, \n suscipit nec, egestas in, arcu. Maecenas sit amet est. \n Quisque felis risus, tempor eu, dictum ac, volutpat id, \n libero. Ut gravida, purus vitae interdum elementum, tortor \n justo porttitor nisi, id rhoncus massa.\";\n self.myTextView.text = text; // assign value within this method and it is\n // painted as expected.\n }\n" }, { "answer_id": 751220, "author": "Rog", "author_id": 9827379, "author_profile": "https://Stackoverflow.com/users/9827379", "pm_score": 0, "selected": false, "text": "UIScrollViews userInteractionEnabled UILabel UITextView UILabel UIScrollView UITextView" }, { "answer_id": 5898942, "author": "Dzamir", "author_id": 149306, "author_profile": "https://Stackoverflow.com/users/149306", "pm_score": 3, "selected": false, "text": "textView.contentOffset = CGPointMake(0, 1);\ntextView.contentOffset = CGPointMake(0, 0);\n" }, { "answer_id": 20297485, "author": "woutercx", "author_id": 1009472, "author_profile": "https://Stackoverflow.com/users/1009472", "pm_score": 0, "selected": false, "text": "[scrollView setAutoresizesSubviews:NO];\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133243", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22154/" ]
133,270
<p>I would like to code a little program which visually illustrates the behavior of the <code>volatile</code> keyword. Ideally, it should be a program which performs concurrent access to a non volatile static field and which gets incorrect behavior because of that. </p> <p>Adding the volatile keyword in the same program should fix the problem.</p> <p>That something I didn't manage to achieve. Even trying several times, enabling optimization, etc., I always get a correct behavior without the 'volatile' keyword.</p> <p>Do you have any idea about this topic? Do you know how to simulate such a problem in a simple demo app? Does it depend on hardware?</p>
[ { "answer_id": 1284007, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 8, "selected": true, "text": "while (test.foo != 255) volatile class Test\n{\n /*volatile*/ int foo;\n\n static void Main()\n {\n var test = new Test();\n\n new Thread(delegate() { Thread.Sleep(500); test.foo = 255; }).Start();\n\n while (test.foo != 255) ;\n Console.WriteLine(\"OK\");\n }\n}\n" }, { "answer_id": 13300755, "author": "corlettk", "author_id": 69224, "author_profile": "https://Stackoverflow.com/users/69224", "pm_score": 2, "selected": false, "text": "using System;\nusing System.Threading;\n\nnamespace VolatileTest\n{\n class VolatileTest \n {\n private volatile int _volatileInt;\n public void Run() {\n new Thread(delegate() { Thread.Sleep(500); _volatileInt = 1; }).Start();\n while ( _volatileInt != 1 ) \n ; // Do nothing\n Console.WriteLine(\"_volatileInt=\"+_volatileInt);\n }\n }\n\n class NormalTest \n {\n private int _normalInt;\n public void Run() {\n new Thread(delegate() { Thread.Sleep(500); _normalInt = 1; }).Start();\n // NOTE: Program hangs here in Release mode only (not Debug mode).\n // See: http://stackoverflow.com/questions/133270/illustrating-usage-of-the-volatile-keyword-in-c-sharp\n // for an explanation of why. The short answer is because the\n // compiler optimisation caches _normalInt on a register, so\n // it never re-reads the value of the _normalInt variable, so\n // it never sees the modified value. Ergo: while ( true )!!!!\n while ( _normalInt != 1 ) \n ; // Do nothing\n Console.WriteLine(\"_normalInt=\"+_normalInt);\n }\n }\n\n class Program\n {\n static void Main() {\n#if DEBUG\n Console.WriteLine(\"You must run this program in Release mode to reproduce the problem!\");\n#endif\n new VolatileTest().Run();\n Console.WriteLine(\"This program will now hang!\");\n new NormalTest().Run();\n }\n\n }\n}\n volatile volatile lock" }, { "answer_id": 21556395, "author": "Martijn B", "author_id": 234417, "author_profile": "https://Stackoverflow.com/users/234417", "pm_score": 2, "selected": false, "text": "volatile class Program\n{\n public static volatile bool complete = false;\n\n private static void Main()\n { \n var t = new Thread(() =>\n {\n bool toggle = false;\n while (!complete) toggle = !toggle;\n });\n\n t.Start();\n Thread.Sleep(1000); //let the other thread spin up\n complete = true;\n t.Join(); // Blocks indefinitely when you remove volatile\n }\n}\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133270", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4687/" ]
133,277
<p>I am moving from classic ASP to ASP.NET and have encountered what many of you already know as "viewstate". I might be jumping the gun with my assumption, but it looks highly cumbersome. I have developed many ASP forms in the past and never had issues with keeping state. Is there another way OR am I going to have to learn this Viewstate thing in ASP.NET? I am using Visual Studio 2008, VB.NET as the code behind language and Framework v3.5 with SQL Server 2005.</p>
[ { "answer_id": 133342, "author": "CodeRedick", "author_id": 17145, "author_profile": "https://Stackoverflow.com/users/17145", "pm_score": 2, "selected": false, "text": "Viewstate[\"Key\"] = value;\n" }, { "answer_id": 20393875, "author": "Abdallah Daragmeh", "author_id": 2906104, "author_profile": "https://Stackoverflow.com/users/2906104", "pm_score": 0, "selected": false, "text": "'<%@ Control Language=\"C#\" AutoEventWireup=\"true\" CodeFile=\"HomePage.ascx.cs\" Inherits=\"HomePage\" %>\n<script runat=\"server\">\n void testHF_ValueChanged(object sender, EventArgs e)\n {\n this.HFvalue.Text = this.testHF.Value ;\n\n }\n</script>\n<asp:Label ID=\"UserNamelbl\" runat=\"server\" Text=\"User Name : \" Visible=\"false\"></asp:Label>\n<asp:TextBox ID=\"UserNametxt\" runat=\"server\" Visible=\"false\" ></asp:TextBox>\n <asp:Label ID=\"HFvalue\" Text=\"......\" runat=\"server\"></asp:Label>\n <asp:HiddenField ID=\"testHF\"\nOnValueChanged=\"testHF_ValueChanged\"\nvalue=\"\" \nrunat=\"server\" ></asp:HiddenField>\n<input type=\"submit\" name=\"SubmitButton\" value=\"Submit\" onclick=\"CL()\" />\n\n<script type=\"text/javascript\">\n function CL() \n {\n this.testHF.Value = this.UserNametxt.Text; \n }\n</script>\n'\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133277", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14728/" ]
133,281
<p>Has anyone tried the ActiveRecord <a href="http://www.castleproject.org/activerecord/gettingstarted/index.html" rel="nofollow noreferrer">Intro Sample</a> with C# 3.5? I somehow have the feeling that the sample is completely wrong or just out of date. The XML configuration is just plain wrong:</p> <pre><code>&lt;add key="connection.connection_string" value="xxx" /&gt; </code></pre> <p>should be :</p> <pre><code>&lt;add key="hibernate.connection.connection_string" value="xxx" /&gt; </code></pre> <p>(if I understand the nhibernate config syntax right..)</p> <p>I am wondering what I'm doing wrong. I get a "Could not perform ExecuteQuery for User" Exception when calling Count() on the User Model. </p> <p>No idea what this can be. The tutorial source differs strongly from the source on the page (most notably in the XML configuration), and it's a VS2003 sample with different syntax on most things (no generics etc).</p> <p>Any suggestions? ActiveRecord looks awesome..</p>
[ { "answer_id": 133305, "author": "Gilligan", "author_id": 12356, "author_profile": "https://Stackoverflow.com/users/12356", "pm_score": 0, "selected": false, "text": "hibernate." }, { "answer_id": 133324, "author": "Paul Batum", "author_id": 48281, "author_profile": "https://Stackoverflow.com/users/48281", "pm_score": 1, "selected": false, "text": "<add key=\"connection.connection_string\" value=\"xxx\" />\n" }, { "answer_id": 133399, "author": "Gilligan", "author_id": 12356, "author_profile": "https://Stackoverflow.com/users/12356", "pm_score": 2, "selected": true, "text": "[ActiveRecord] [PrimaryKey] PluralizeTableNames virtual" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133281", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21699/" ]
133,287
<p>I have a simple function that sends out emails, how would I go about using threads to speed email delivery?</p> <p>Sample code would be ideal.</p>
[ { "answer_id": 133321, "author": "Wolfwyrd", "author_id": 15570, "author_profile": "https://Stackoverflow.com/users/15570", "pm_score": 1, "selected": false, "text": "using System;\nusing System.Threading;\n\nclass Test\n{\n static void Main() \n {\n Thread newThread = new Thread(new ThreadStart(Work.DoWork));\n newThread.Start();\n }\n}\n\nclass Work \n{\n Work() {}\n public static void DoWork() {}\n}\n" }, { "answer_id": 133355, "author": "Eduardo Campañó", "author_id": 12091, "author_profile": "https://Stackoverflow.com/users/12091", "pm_score": 2, "selected": false, "text": "ThreadPool.QueueUserWorkItem(delegate { SendMail(message); });\n" }, { "answer_id": 14602418, "author": "Yasser Shaikh", "author_id": 1182982, "author_profile": "https://Stackoverflow.com/users/1182982", "pm_score": 2, "selected": false, "text": "new Thread(x => SendMail(message)).Start();\n public static void SendEmail(MailMessage message)\n{\n using (SmtpClient client = new SmtpClient(\"smtp.XXXXXX.com\"))\n {\n client.Send(message);\n }\n}\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133287", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
133,308
<p>I'm new to CodeIgniter, and I need some help. I'd like to implement the following:</p> <ul> <li><p>View a user's profile via: http://localhost/profile/johndoe</p> </li> <li><p>Administrate a user's profile via: http://localhost/admin/profile/johndoe</p> </li> <li><p>Be able to accomplish even further processing via: http://localhost/admin/profile/create ...and... http://localhost/admin/profile/edit/johndoe</p> </li> </ul> <p>I've already created the admin object and secured it. Do I have to create a profile function under admin, and work with the URI to process accordingly? Is there a better way?</p>
[ { "answer_id": 133976, "author": "Christian Davén", "author_id": 12534, "author_profile": "https://Stackoverflow.com/users/12534", "pm_score": 4, "selected": true, "text": "index profile profile show edit create add" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133308", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18334/" ]
133,310
<p>I have a JavaScript widget which provides standard extension points. One of them is the <code>beforecreate</code> function. It should return <code>false</code> to prevent an item from being created. </p> <p>I've added an Ajax call into this function using jQuery:</p> <pre><code>beforecreate: function (node, targetNode, type, to) { jQuery.get('http://example.com/catalog/create/' + targetNode.id + '?name=' + encode(to.inp[0].value), function (result) { if (result.isOk == false) alert(result.message); }); } </code></pre> <p>But I want to prevent my widget from creating the item, so I should return <code>false</code> in the mother-function, not in the callback. Is there a way to perform a synchronous AJAX request using jQuery or any other in-browser API?</p>
[ { "answer_id": 133327, "author": "Adam Bellaire", "author_id": 21632, "author_profile": "https://Stackoverflow.com/users/21632", "pm_score": 11, "selected": true, "text": "beforecreate: function (node, targetNode, type, to) {\n jQuery.ajax({\n url: 'http://example.com/catalog/create/' + targetNode.id + '?name=' + encode(to.inp[0].value),\n success: function (result) {\n if (result.isOk == false) alert(result.message);\n },\n async: false\n });\n}\n" }, { "answer_id": 2592780, "author": "James in Indy", "author_id": 488063, "author_profile": "https://Stackoverflow.com/users/488063", "pm_score": 7, "selected": false, "text": "function getWhatever() {\n // strUrl is whatever URL you need to call\n var strUrl = \"\", strReturn = \"\";\n\n jQuery.ajax({\n url: strUrl,\n success: function(html) {\n strReturn = html;\n },\n async:false\n });\n\n return strReturn;\n}\n" }, { "answer_id": 5641995, "author": "Sydwell", "author_id": 344050, "author_profile": "https://Stackoverflow.com/users/344050", "pm_score": 8, "selected": false, "text": "jQuery.ajaxSetup({async:false});\n jQuery.get( ... ); jQuery.ajaxSetup({async:true});\n jQuery.get() jQuery.post() jQuery.ajax()" }, { "answer_id": 10318912, "author": "Carcione", "author_id": 1356638, "author_profile": "https://Stackoverflow.com/users/1356638", "pm_score": 6, "selected": false, "text": "function getURL(url){\n return $.ajax({\n type: \"GET\",\n url: url,\n cache: false,\n async: false\n }).responseText;\n}\n\n\n//example use\nvar msg=getURL(\"message.php\");\nalert(msg);\n" }, { "answer_id": 10365952, "author": "BishopZ", "author_id": 901379, "author_profile": "https://Stackoverflow.com/users/901379", "pm_score": 7, "selected": false, "text": "beforecreate: function(node,targetNode,type,to) {\n\n Frame(function(next)){\n\n jQuery.get('http://example.com/catalog/create/', next);\n });\n\n Frame(function(next, response)){\n\n alert(response);\n next();\n });\n\n Frame.init();\n}\n" }, { "answer_id": 25340568, "author": "searching9x", "author_id": 1522438, "author_profile": "https://Stackoverflow.com/users/1522438", "pm_score": 3, "selected": false, "text": "$.ajax({\n url: \"test.html\",\n async: false\n}).done(function(data) {\n // Todo something..\n}).fail(function(xhr) {\n // Todo something..\n});\n" }, { "answer_id": 26945353, "author": "paulo62", "author_id": 2043271, "author_profile": "https://Stackoverflow.com/users/2043271", "pm_score": 4, "selected": false, "text": " function getUrlJsonSync(url){\n\n var jqxhr = $.ajax({\n type: \"GET\",\n url: url,\n dataType: 'json',\n cache: false,\n async: false\n });\n\n // 'async' has to be 'false' for this to work\n var response = {valid: jqxhr.statusText, data: jqxhr.responseJSON};\n\n return response;\n} \n\nfunction testGetUrlJsonSync()\n{\n var reply = getUrlJsonSync(\"myurl\");\n\n if (reply.valid == 'OK')\n {\n console.dir(reply.data);\n }\n else\n {\n alert('not valid');\n } \n}\n function postUrlJsonSync(url, postdata){\n\n var jqxhr = $.ajax({\n type: \"POST\",\n url: url,\n data: postdata,\n dataType: 'json',\n cache: false,\n async: false\n });\n\n // 'async' has to be 'false' for this to work\n var response = {valid: jqxhr.statusText, data: jqxhr.responseJSON};\n\n return response;\n}\n" }, { "answer_id": 30148405, "author": "Serge Shultz", "author_id": 1785164, "author_profile": "https://Stackoverflow.com/users/1785164", "pm_score": 5, "selected": false, "text": "async $.ajax({\n url: \"testserver.php\",\n dataType: 'jsonp', // jsonp\n async: false //IGNORED!!\n});\n" }, { "answer_id": 39058130, "author": "Spenhouet", "author_id": 2230045, "author_profile": "https://Stackoverflow.com/users/2230045", "pm_score": 4, "selected": false, "text": "async: false beforecreate: function (node, targetNode, type, to) {\n co(function*(){ \n let result = yield jQuery.get('http://example.com/catalog/create/' + targetNode.id + '?name=' + encode(to.inp[0].value));\n //Just use the result here\n });\n}\n beforecreate: function (node, targetNode, type, to) {\n (async function(){\n let result = await jQuery.get('http://example.com/catalog/create/' + targetNode.id + '?name=' + encode(to.inp[0].value));\n //Just use the result here\n })(); \n}\n" }, { "answer_id": 41121687, "author": "Endless", "author_id": 1008999, "author_profile": "https://Stackoverflow.com/users/1008999", "pm_score": 5, "selected": false, "text": "async: false async function foo() {\n var res = await fetch(url)\n console.log(res.ok)\n var json = await res.json()\n console.log(json)\n}\n" }, { "answer_id": 46541790, "author": "Sheo Dayal Singh", "author_id": 5736534, "author_profile": "https://Stackoverflow.com/users/5736534", "pm_score": 3, "selected": false, "text": "$.ajax({\n url: url,\n data: data,\n success: success,\n dataType: dataType\n});\n $.ajax({\n type: 'GET',\n url: url,\n data: data,\n success: success,\n dataType: dataType,\n async:false\n });\n" }, { "answer_id": 48815237, "author": "Felipe Marques", "author_id": 856730, "author_profile": "https://Stackoverflow.com/users/856730", "pm_score": 3, "selected": false, "text": "var queueUrlsForRemove = [\n 'http://dev-myurl.com/image/1', \n 'http://dev-myurl.com/image/2',\n 'http://dev-myurl.com/image/3',\n];\n\nvar queueImagesDelete = function(){\n\n deleteImage( queueUrlsForRemove.splice(0,1), function(){\n if (queueUrlsForRemove.length > 0) {\n queueImagesDelete();\n }\n });\n\n}\n\nvar deleteImage = function(url, callback) {\n $.ajax({\n url: url,\n method: 'DELETE'\n }).done(function(response){\n typeof(callback) == 'function' ? callback(response) : null;\n });\n}\n\nqueueImagesDelete();\n" }, { "answer_id": 50085745, "author": "Geoffrey", "author_id": 637874, "author_profile": "https://Stackoverflow.com/users/637874", "pm_score": 3, "selected": false, "text": "XMLHttpReponse XMLHttpRequest /* wrap XMLHttpRequest for synchronous operation */\nvar XHRQueue = [];\nvar _XMLHttpRequest = XMLHttpRequest;\nXMLHttpRequest = function()\n{\n var xhr = new _XMLHttpRequest();\n var _send = xhr.send;\n\n xhr.send = function()\n {\n /* queue the request, and if it's the first, process it */\n XHRQueue.push([this, arguments]);\n if (XHRQueue.length == 1)\n this.processQueue();\n };\n\n xhr.processQueue = function()\n {\n var call = XHRQueue[0];\n var xhr = call[0];\n var args = call[1];\n\n /* you could also set a CSRF token header here */\n\n /* send the request */\n _send.apply(xhr, args);\n };\n\n xhr.addEventListener('load', function(e)\n {\n /* you could also retrieve a CSRF token header here */\n\n /* remove the completed request and if there is more, trigger the next */\n XHRQueue.shift();\n if (XHRQueue.length)\n this.processQueue();\n });\n\n return xhr;\n};\n" }, { "answer_id": 59696697, "author": "Anupam", "author_id": 1526703, "author_profile": "https://Stackoverflow.com/users/1526703", "pm_score": 1, "selected": false, "text": "jQuery.get async: false $.get() XMLHTTPRequest $.get({\n url: url,// mandatory\n data: data,\n success: success,\n dataType: dataType,\n async:false // to make it synchronous\n});\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133310", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2313/" ]
133,313
<p>I'm trying to design some tables to store some data, which has to be converted to different languages later. Can anybody provide some "best practices" or guidelines for this?</p> <p>Thanks</p>
[ { "answer_id": 133351, "author": "Ben Scheirman", "author_id": 3381, "author_profile": "https://Stackoverflow.com/users/3381", "pm_score": 5, "selected": true, "text": "Products\n----------\nid\nprice\n\nProducts_Translations\n----------------------\nproduct_id\nlocale\nname\ndescription\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133313", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22016/" ]
133,325
<p>Is there a way to Minimize an external application that I don't have control over from with-in my Delphi application?</p> <p>for example notepad.exe, except the application I want to minimize will only ever have one instance.</p>
[ { "answer_id": 133530, "author": "Germán Estévez -Neftalí-", "author_id": 17487, "author_profile": "https://Stackoverflow.com/users/17487", "pm_score": 4, "selected": true, "text": "var \n Indicador :Integer;\nbegin \n // Find the window by Classname\n Indicador := FindWindow(PChar('notepad'), nil);\n // if finded\n if (Indicador <> 0) then begin\n // Minimize\n ShowWindow(Indicador,SW_MINIMIZE);\n end;\nend;\n" }, { "answer_id": 134011, "author": "Re0sless", "author_id": 2098, "author_profile": "https://Stackoverflow.com/users/2098", "pm_score": 2, "selected": false, "text": "FindWindow(PChar('notepad'), nil);\n function FindWindowByTitle(WindowTitle: string): Hwnd;\n var\n NextHandle: Hwnd;\n NextTitle: array[0..260] of char;\nbegin\n // Get the first window\n NextHandle := GetWindow(Application.Handle, GW_HWNDFIRST);\n while NextHandle > 0 do\n begin\n // retrieve its text\n GetWindowText(NextHandle, NextTitle, 255);\n if Pos(WindowTitle, StrPas(NextTitle)) <> 0 then\n begin\n Result := NextHandle;\n Exit;\n end\n else\n // Get the next window\n NextHandle := GetWindow(NextHandle, GW_HWNDNEXT);\n end;\n Result := 0;\nend;\n\nprocedure hideExWindow()\nvar Indicador:Hwnd;\nbegin\n // Find the window by Classname\n Indicador := FindWindowByTitle('MyApp'); \n // if finded\n if (Indicador <> 0) then\n begin\n // Minimize\n ShowWindow(Indicador,SW_HIDE); //SW_MINIMIZE\n end;\nend;\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133325", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2098/" ]
133,328
<p>I have been asked to develop some usercontrols in ASP.NET that will at a later point be pulled into a SharePoint site as web parts. I am new to SharePoint and will not have access to a SharePoint server during the time I need to prototype these parts.</p> <p>Does anyone know of any reasons that this approach will not work? If this approach is not recommended, what would other options be? Any suggestions on a resource/tutorial on what to consider when developing an ASP.NET web part with SharePoint in mind?</p> <p>Thanks</p> <p><strong>Edit: 12/31/2008</strong> I finally marked an answer to this one. It took me a while to realize that going the SharePoint route right away, though painful at first, is the best way to go about it. The free VPC image makes getting set up to develop relatively painless. </p> <p>While you can, as I did, develop web parts in ASP.NET without SharePoint, when it comes to developing and deploying SharePoint applications you haven't learned a thing, only pushed the learning curve off into a time when you think you are done, (and have probably informed stakeholders to that effect). To delay the SharePoint learning curve doesn't do you or your project any favors, and your final product will better for the expertise you gain along the way.</p>
[ { "answer_id": 133438, "author": "Chris Cudmore", "author_id": 18907, "author_profile": "https://Stackoverflow.com/users/18907", "pm_score": 0, "selected": false, "text": "<SafeControl Assembly=\"MyControl, Version=1.0.0.0, Culture=neutral, PublicKeyToken=975cc42deafbee31\" Namespace=\"MyNamespace\" TypeName=\"*\" Safe=\"True\" AllowRemoteDesigner=\"True\" />\n <%@ Register Namespace=\"MyNamespace\" Assembly=\"MyControl, Version=1.0.0.0, Culture=Neutral, PublicKeyToken=975cc42deafbee31\" TagPrefix=\"XXXX\" %>\n <XXXX:ClassName runat=\"server\" Field1=\"Value1\" Field2=\"Value2\" ....></XXXX:Classname>\n" }, { "answer_id": 135194, "author": "ashwnacharya", "author_id": 1909, "author_profile": "https://Stackoverflow.com/users/1909", "pm_score": 0, "selected": false, "text": "* Connections between web parts that are outside of a Web Part zone\n\n* Cross page connections\n\n* A data caching infrastructure that allows caching to the content database\n\n* Client-side connections (Web Part Page Services Component)\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133328", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10552/" ]
133,357
<p>How do I find the name of the namespace or module 'Foo' in the filter below?</p> <pre><code>class ApplicationController &lt; ActionController::Base def get_module_name @module_name = ??? end end class Foo::BarController &lt; ApplicationController before_filter :get_module_name end </code></pre>
[ { "answer_id": 133396, "author": "Daniel Lucraft", "author_id": 11951, "author_profile": "https://Stackoverflow.com/users/11951", "pm_score": 4, "selected": false, "text": " def get_module_name\n @module_name = self.class.to_s.split(\"::\").first\n end\n" }, { "answer_id": 133417, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "class ApplicationController < ActionController::Base\n def get_module_name\n @module_name = self.class.name.split(\"::\").first\n end\nend\n" }, { "answer_id": 133529, "author": "Steropes", "author_id": 21872, "author_profile": "https://Stackoverflow.com/users/21872", "pm_score": 3, "selected": false, "text": "class ApplicationController < ActionController::Base\n def get_module_name\n @module_name = self.class.name.split(\"::\").first\n end\nend\n class ApplicatioNController < ActionController::Base\n def get_module_name\n my_class_name = self.class.name\n if my_class_name.index(\"::\").nil? then\n @module_name = nil\n else\n @module_name = my_class_name.split(\"::\").first\n end\n end\nend\n" }, { "answer_id": 2779504, "author": "Dave Hollingworth", "author_id": 185553, "author_profile": "https://Stackoverflow.com/users/185553", "pm_score": 2, "selected": false, "text": "<%= render \"#{controller.class.name[/^(\\w*)::\\w*$/, 1].try(:downcase)}/nav\" %>\n app/views/_nav.html.erb\n app/views/admin/_nav.html.erb\n" }, { "answer_id": 14145660, "author": "Jason Harrelson", "author_id": 1946579, "author_profile": "https://Stackoverflow.com/users/1946579", "pm_score": 8, "selected": true, "text": "A::B::C\n \"A::B::C\".deconstantize #=> \"A::B\"\n constant_name = \"A::B::C\"\nconstant_name.gsub( \"::#{constant_name.demodulize}\", '' )\n \"A::B::C\".demodulize #=> \"C\"\n constant_name = \"A::B::C\"\nconstant_name.split( '::' )[0,constant_name.split( '::' ).length-1]\n" }, { "answer_id": 17800438, "author": "Pablo Cantero", "author_id": 464685, "author_profile": "https://Stackoverflow.com/users/464685", "pm_score": 1, "selected": false, "text": "gsub split split class ApplicationController < ActionController::Base\n def get_module_name\n @module_name = self.class.to_s.gsub(/::.*/, '')\n end\nend\n" }, { "answer_id": 22868300, "author": "sandstrom", "author_id": 118007, "author_profile": "https://Stackoverflow.com/users/118007", "pm_score": 2, "selected": false, "text": "my_class.name.underscore.split('/').slice(0..-2) my_class.name.split('::').slice(0..-2)" }, { "answer_id": 27856939, "author": "Hettomei", "author_id": 1614763, "author_profile": "https://Stackoverflow.com/users/1614763", "pm_score": 5, "selected": false, "text": "self.class.parent\n" }, { "answer_id": 33892600, "author": "Cyril", "author_id": 3359291, "author_profile": "https://Stackoverflow.com/users/3359291", "pm_score": 2, "selected": false, "text": "module ApplicationHelper\n def namespace\n controller.class.name.gsub(/(::)?\\w+Controller$/, '')\n end\nend\n Foo::Bar::BazController Foo::Bar" }, { "answer_id": 59346110, "author": "CRandER", "author_id": 12477795, "author_profile": "https://Stackoverflow.com/users/12477795", "pm_score": 2, "selected": false, "text": "rpartition const_name = 'A::B::C'\nnamespace, _sep, module_name = const_name.rpartition('::')\n# or if you just need the namespace\nnamespace = const_name.rpartition('::').first\n" }, { "answer_id": 62095599, "author": "Horacio", "author_id": 3043906, "author_profile": "https://Stackoverflow.com/users/3043906", "pm_score": 4, "selected": false, "text": "self.class.module_parent Module#parent module_parent parent" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133357", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21872/" ]
133,364
<p>Which is your favorite way to go with strings in C++? A C-style array of <code>char</code>s? Or <code>wchar_t</code>? <code>CString</code>, <code>std::basic_string</code>, <code>std::string</code>, <code>BSTR</code> or <code>CComBSTR</code>?</p> <p>Certainly each of these has its own area of application, but anyway, which is your favorite and why?</p>
[ { "answer_id": 133422, "author": "xtofl", "author_id": 6610, "author_profile": "https://Stackoverflow.com/users/6610", "pm_score": 2, "selected": false, "text": "std::string basic_string<TCHAR> CStringT printf" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133364", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19024/" ]
133,374
<p>When trying to call Close or Dispose on an SqlDataReader i get a timeout expired exception. If you have a DbConnection to SQL Server, you can reproduce it yourself with:</p> <pre><code>String CRLF = "\r\n"; String sql = "SELECT * " + CRLF + "FROM (" + CRLF + " SELECT (a.Number * 256) + b.Number AS Number" + CRLF + " FROM master..spt_values a," + CRLF + " master..spt_values b" + CRLF + " WHERE a.Type = 'p'" + CRLF + " AND b.Type = 'p') Numbers1" + CRLF + " FULL OUTER JOIN (" + CRLF + " SELECT (print("code sample");a.Number * 256) + b.Number AS Number" + CRLF + " FROM master..spt_values a," + CRLF + " master..spt_values b" + CRLF + " WHERE a.Type = 'p'" + CRLF + " AND b.Type = 'p') Numbers2" + CRLF + " ON 1=1"; DbCommand cmd = connection.CreateCommand(); cmd.CommandText = sql; DbDataReader rdr = cmd.ExecuteReader(); rdr.Close(); </code></pre> <p>If you call reader.Close() or reader.Dispose() it will throw a System.Data.SqlClient.SqlException:</p> <ul> <li>ErrorCode: -2146232060 (0x80131904)</li> <li>Message: "Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding."</li> </ul>
[ { "answer_id": 133433, "author": "MADMap", "author_id": 17558, "author_profile": "https://Stackoverflow.com/users/17558", "pm_score": 0, "selected": false, "text": "DbDataReader rdr = cmd.ExecuteReader();\nwhile(rdr.Read())\n{\n int index = rdr.GetInt32(0);\n}\n" }, { "answer_id": 133492, "author": "Ian Boyd", "author_id": 12597, "author_profile": "https://Stackoverflow.com/users/12597", "pm_score": 2, "selected": false, "text": "using (DbCommand cmd = connection.CreateCommand())\n{\n cmd.CommandText = sql;\n using (DbDataReader rdr = cmd.ExecuteReader())\n {\n while (rdr.Read())\n {\n if (WeShouldCancelTheOperation())\n {\n cmd.Cancel();\n break;\n }\n }\n } \n}\n DbCommand cmd = connection.CreateCommand();\ntry\n{\n cmd.CommandText = sql;\n DbDataReader rdr = cmd.ExecuteReader();\n try\n {\n while (rdr.Read())\n {\n if (WeShouldCancelTheOperation())\n break;\n }\n cmd.Cancel();\n } \n finally\n {\n rdr.Dispose();\n }\n}\nfinally\n{\n cmd.Dispose();\n}\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133374", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12597/" ]
133,379
<p>I'm trying to install a service using InstallUtil.exe but invoked through <code>Process.Start</code>. Here's the code:</p> <pre><code>ProcessStartInfo startInfo = new ProcessStartInfo (m_strInstallUtil, strExePath); System.Diagnostics.Process.Start (startInfo); </code></pre> <p>where <code>m_strInstallUtil</code> is the fully qualified path and exe to "InstallUtil.exe" and <code>strExePath</code> is the fully qualified path/name to my service.</p> <p>Running the command line syntax from an elevated command prompt works; running from my app (using the above code) does not. I assume I'm dealing with some process elevation issue, so how would I run my process in an elevated state? Do I need to look at <code>ShellExecute</code> for this?</p> <p>This is all on Windows Vista. I am running the process in the VS2008 debugger elevated to admin privilege.</p> <p>I also tried setting <code>startInfo.Verb = "runas";</code> but it didn't seem to solve the problem.</p>
[ { "answer_id": 133478, "author": "Vijesh VP", "author_id": 22016, "author_profile": "https://Stackoverflow.com/users/22016", "pm_score": 1, "selected": false, "text": "WindowsIdentity identity = new WindowsIdentity(accessToken);\nWindowsImpersonationContext context = identity.Impersonate();\n" }, { "answer_id": 133500, "author": "mdb", "author_id": 8562, "author_profile": "https://Stackoverflow.com/users/8562", "pm_score": 9, "selected": true, "text": "startInfo.Verb = \"runas\";\n" }, { "answer_id": 232024, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 5, "selected": false, "text": "ShellExecute CreateProcess" }, { "answer_id": 8832162, "author": "hB0", "author_id": 452090, "author_profile": "https://Stackoverflow.com/users/452090", "pm_score": 3, "selected": false, "text": "[PrincipalPermission(SecurityAction.Demand, Role = @\"BUILTIN\\Administrators\")]\n" }, { "answer_id": 10905713, "author": "Curtis Yallop", "author_id": 854342, "author_profile": "https://Stackoverflow.com/users/854342", "pm_score": 6, "selected": false, "text": "if (IsAdministrator() == false)\n{\n // Restart program and run as admin\n var exeName = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;\n ProcessStartInfo startInfo = new ProcessStartInfo(exeName);\n startInfo.Verb = \"runas\";\n System.Diagnostics.Process.Start(startInfo);\n Application.Current.Shutdown();\n return;\n}\n\nprivate static bool IsAdministrator()\n{\n WindowsIdentity identity = WindowsIdentity.GetCurrent();\n WindowsPrincipal principal = new WindowsPrincipal(identity);\n return principal.IsInRole(WindowsBuiltInRole.Administrator);\n}\n\n\n// To run as admin, alter exe manifest file after building.\n// Or create shortcut with \"as admin\" checked.\n// Or ShellExecute(C# Process.Start) can elevate - use verb \"runas\".\n// Or an elevate vbs script can launch programs as admin.\n// (does not work: \"runas /user:admin\" from cmd-line prompts for admin pass)\n" }, { "answer_id": 70599487, "author": "Jhollman", "author_id": 2000656, "author_profile": "https://Stackoverflow.com/users/2000656", "pm_score": 2, "selected": false, "text": "System.Diagnostics.ProcessStartInfo StartInfo = new System.Diagnostics.ProcessStartInfo\n{\n UseShellExecute = true, //<- for elevation\n Verb = \"runas\", //<- for elevation\n WorkingDirectory = Environment.CurrentDirectory,\n FileName = \"EDHM_UI_Patcher.exe\",\n Arguments = @\"\\D -FF\"\n};\nSystem.Diagnostics.Process p = System.Diagnostics.Process.Start(StartInfo);\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133379", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1683/" ]
133,390
<p>I want to use forms authentication in my asp.net mvc site.</p> <p>Can I use an already existing sql db (on a remote server) for it? How do I configure the site to use this db for authentication? Which tables do I need/are used for authentication?</p>
[ { "answer_id": 133432, "author": "Biri", "author_id": 968, "author_profile": "https://Stackoverflow.com/users/968", "pm_score": 3, "selected": true, "text": "aspnet_regsql.exe sqlexportonly <connectionStrings>\n <add name=\"MyLocalSQLServer\" connectionString=\"Initial Catalog=aspnetdb;data source=servername;uid=whatever;pwd=whatever;\"/>\n </connectionStrings>\n\n<authentication mode=\"Forms\">\n <forms name=\"SqlAuthCookie\" timeout=\"10\" loginUrl=\"Login.aspx\"/>\n</authentication>\n<authorization>\n <deny users=\"?\"/>\n <allow users=\"*\"/>\n</authorization>\n<membership defaultProvider=\"MySqlMembershipProvider\">\n <providers>\n <clear/>\n <add name=\"MySqlMembershipProvider\" connectionStringName=\"MyLocalSQLServer\" applicationName=\"MyAppName\" type=\"System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a\"/>\n </providers>\n</membership>\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133390", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9632/" ]
133,394
<p>I am developing a Joomla component and one of the views needs to render itself as PDF. In the view, I have tried setting the content-type with the following line, but when I see the response, it is text/html anyways.</p> <pre><code>header('Content-type: application/pdf'); </code></pre> <p>If I do this in a regular php page, everything works as expected. It seems that I need to tell Joomla to use application/pdf instead of text/html. How can I do it?</p> <p>Note: Setting other headers, such as <code>Content-Disposition</code>, works as expected.</p>
[ { "answer_id": 134827, "author": "Tomalak", "author_id": 18771, "author_profile": "https://Stackoverflow.com/users/18771", "pm_score": 5, "selected": true, "text": "$doc =& JFactory::getDocument();\n$doc->setMimeEncoding('application/pdf');\n" }, { "answer_id": 13920887, "author": "john Ames", "author_id": 1910979, "author_profile": "https://Stackoverflow.com/users/1910979", "pm_score": 0, "selected": false, "text": ".mov" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133394", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2680/" ]
133,430
<p>I have created a web reference (Add Web Reference) from Visual Studio 2008 and strangely, I need to set the <em>propertyNameField</em>Specified to true for all the fields I want to submit. Failure to do that and values are not passed back to the WCF Service. </p> <p>I have read at several places that this was fixed in the RTM version of Visual Studio. Why does it still occurring?</p> <p>My data contracts are all valid with nothing else than properties and lists. Any ideas?</p>
[ { "answer_id": 133498, "author": "Sebastien Lachance", "author_id": 201997, "author_profile": "https://Stackoverflow.com/users/201997", "pm_score": 0, "selected": false, "text": "[DataContract]\npublic class BrowserBase : IBrowser\n{\n\n [DataMember]\n public BrowserType BrowserType { get; set; }\n\n [DataMember]\n public IList<ResolutionBase> Resolutions { get; set; }\n\n}\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133430", "https://Stackoverflow.com", "https://Stackoverflow.com/users/201997/" ]
133,436
<p>I'm using Java 6, Tomcat 6, and Metro. I use WebService and WebMethod annotations to expose my web service. I would like to obtain information about the request. I tried the following code, but wsCtxt is always null. What step must I take to <em>not</em> get null for the WebServiceContext.</p> <p>In other words: how can I execute the following line to get a non-null value for wsCtxt?</p> <p>MessageContext msgCtxt = wsCtxt.getMessageContext();</p> <pre><code>@WebService public class MyService{ @Resource WebServiceContext wsCtxt; @WebMethod public void myWebMethod(){ MessageContext msgCtxt = wsCtxt.getMessageContext(); HttpServletRequest req = (HttpServletRequest)msgCtxt.get(MessageContext.SERVLET_REQUEST); String clientIP = req.getRemoteAddr(); } </code></pre>
[ { "answer_id": 133565, "author": "James A Wilson", "author_id": 13892, "author_profile": "https://Stackoverflow.com/users/13892", "pm_score": 5, "selected": true, "text": "@Resource(name=\"wsContext\") WebServiceContext wsCtxt;" }, { "answer_id": 139169, "author": "Steve McLeod", "author_id": 2959, "author_profile": "https://Stackoverflow.com/users/2959", "pm_score": 2, "selected": false, "text": "import javax.servlet.ServletRequest;\nimport javax.servlet.ServletRequestEvent;\nimport javax.servlet.ServletRequestListener;\n\npublic class SDMXRequestListener implements ServletRequestListener {\n\n public SDMXRequestListener() {\n }\n\n public void requestDestroyed(ServletRequestEvent event) {\n }\n\n public void requestInitialized(ServletRequestEvent event) {\n final ServletRequest request = event.getServletRequest();\n ServletRequestStore.setServletRequest(request);\n }\n\n}\n import javax.servlet.ServletRequest;\n\npublic class ServletRequestStore {\n\n private final static ThreadLocal<ServletRequest> servletRequests = new ThreadLocal<ServletRequest>();\n\n public static void setServletRequest(ServletRequest request) {\n servletRequests.set(request);\n }\n\n public static ServletRequest getServletRequest() {\n return servletRequests.get();\n }\n\n}\n <listener>\n <listener-class>ecb.sdw.webservices.SDMXRequestListener</listener-class>\n </listener>\n" }, { "answer_id": 139608, "author": "Garth Gilmour", "author_id": 2635682, "author_profile": "https://Stackoverflow.com/users/2635682", "pm_score": 2, "selected": false, "text": "@WebService\npublic class Sample {\n @WebMethod\n public void sample() {\n HttpSession session = findSession();\n //Stuff\n\n }\n private HttpSession findSession() {\n MessageContext mc = wsContext.getMessageContext();\n HttpServletRequest request = (HttpServletRequest)mc.get(MessageContext.SERVLET_REQUEST);\n return request.getSession();\n }\n @Resource\n private WebServiceContext wsContext;\n}\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133436", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2959/" ]
133,442
<p>Our server application is listening on a port, and after a period of time it no longer accepts incoming connections. (And while I'd love to solve this issue, it's not what I'm asking about here;)</p> <p>The strange this is that when our app stops accepting connections on port 44044, so does IIS (on port 8080). Killing our app fixes everything - IIS starts responding again.</p> <p>So the question is, can an application mess up the entire TCP/IP stack? Or perhaps, how can an application do that?</p> <p>Senseless detail: Our app is written in C#, under .Net 2.0, on XP/SP2.</p> <p>Clarification: IIS is not "refusing" the attempted connections. It is never seeing them. Clients are getting a "server did not respond in a timely manner" message (using the .Net TCP Client.)</p>
[ { "answer_id": 133466, "author": "RichS", "author_id": 6247, "author_profile": "https://Stackoverflow.com/users/6247", "pm_score": 2, "selected": false, "text": "netstat -a" }, { "answer_id": 134548, "author": "stephbu", "author_id": 12702, "author_profile": "https://Stackoverflow.com/users/12702", "pm_score": 4, "selected": true, "text": "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\n\nTcpTimedWaitDelay = 30\nMaxUserPort = 65534 \nMaxHashTableSize = 65536 \nMaxFreeTcbs = 16000 \n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133442", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16662/" ]
133,453
<p>Does IPsec in Windows XP Sp3 support AES-256 encryption?</p> <p><strong>Update:</strong></p> <ol> <li>Windows IPsec FAQ says that it's not supported in Windows XP, but maybe they changed it in Service Pack 3?<br> http://www.microsoft.com/technet/network/ipsec/ipsecfaq.mspx<br> Question: <em>Is Advanced Encryption Standard (AES) encryption supported?</em><br><br> </li> <li>origamigumby, please specify where, because I cannot find it.</li> </ol>
[ { "answer_id": 133466, "author": "RichS", "author_id": 6247, "author_profile": "https://Stackoverflow.com/users/6247", "pm_score": 2, "selected": false, "text": "netstat -a" }, { "answer_id": 134548, "author": "stephbu", "author_id": 12702, "author_profile": "https://Stackoverflow.com/users/12702", "pm_score": 4, "selected": true, "text": "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\n\nTcpTimedWaitDelay = 30\nMaxUserPort = 65534 \nMaxHashTableSize = 65536 \nMaxFreeTcbs = 16000 \n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133453", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22174/" ]
133,487
<p>I have a LinkedList, where Entry has a member called id. I want to remove the Entry from the list where id matches a search value. What's the best way to do this? I don't want to use Remove(), because Entry.Equals will compare other members, and I only want to match on id. I'm hoping to do something kind of like this:</p> <pre><code>entries.RemoveWhereTrue(e =&gt; e.id == searchId); </code></pre> <p>edit: Can someone re-open this question for me? It's NOT a duplicate - the question it's supposed to be a duplicate of is about the List class. List.RemoveAll won't work - that's part of the List class.</p>
[ { "answer_id": 133577, "author": "Matt Howells", "author_id": 16881, "author_profile": "https://Stackoverflow.com/users/16881", "pm_score": 3, "selected": true, "text": "list.Remove(list.First(e => e.id == searchId));\n" }, { "answer_id": 133946, "author": "munificent", "author_id": 9457, "author_profile": "https://Stackoverflow.com/users/9457", "pm_score": 2, "selected": false, "text": "list.Remove(list.First((node) => node.id == searchId));\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133487", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2348/" ]
133,493
<p>How can you check if a string is a valid GUID in vbscript? Has anyone written an IsGuid method?</p>
[ { "answer_id": 1042813, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": -1, "selected": false, "text": "try\n{\n Guid g = new Guid(stringGuid);\n safeUseGuid(stringGuid); //this statement will execute only if guid is correct\n}catch(Exception){}\n" }, { "answer_id": 6058272, "author": "Conding Strategist", "author_id": 761007, "author_profile": "https://Stackoverflow.com/users/761007", "pm_score": 0, "selected": false, "text": "Function isGUID(byval strGUID)\n if isnull(strGUID) then\n isGUID = false\n exit function\n end if\n dim regEx\n set regEx = New RegExp\n regEx.Pattern = \"{[0-9A-Fa-f-]+}\"\n isGUID = regEx.Test(strGUID)\n set RegEx = nothing\nEnd Function\n" }, { "answer_id": 12320009, "author": "samiup", "author_id": 1654975, "author_profile": "https://Stackoverflow.com/users/1654975", "pm_score": 2, "selected": false, "text": "Function isGUID(byval strGUID)\n if isnull(strGUID) then\n isGUID = false\n exit function\n end if\n dim regEx\n set regEx = New RegExp\n regEx.Pattern = \"^({|\\()?[A-Fa-f0-9]{8}-([A-Fa-f0-9]{4}-){3}[A-Fa-f0-9]{12}(}|\\))?$\"\n isGUID = regEx.Test(strGUID)\n set RegEx = nothing\nEnd Function\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133493", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10023/" ]
133,515
<p>I am using <a href="http://msdn.microsoft.com/en-us/library/bb386987.aspx" rel="noreferrer">SqlMetal</a> to general my DataContext.dbml class for my ASP.net application using LinqToSql. When I initially created the DataContext.dbml file, Visual Studio used this to create a related DataContext.designer.cs file. This designer file contains the DataContext class in C# that is used throughout the app (and is derived from the XML in the dbml file) and is essential to bridging the gap between the output of SqlMetal and using the DataContext with LinqToSql.</p> <p>However, when I make a change to the database and recreate the dbml file, the designer file never gets regenerated in my website. Instead, the old designer file is maintained (and therefore none of the changes to the DBML file are accessible through the LinqToSql DataContext class).</p> <p>The only process I have been able to use so far to regenerate the designer file is</p> <ol> <li>Go to Windows Explorer and delete both the dbml and designer.cs files</li> <li>Go to Visual Studio and hit Refresh in the Solution Explorer. The dbml and designer.cs files now disappear from the project.</li> <li>Regenerate the dbml file using SqlMetal</li> <li>Go to Visual Studio and hit Refresh in the Solution Explorer. Now the designer.cs file is recreated.</li> </ol> <p>It seems that Visual Studio will only generate the designer.cs file when a new dbml file is detected that does not yet have a designer.cs file. This process is pretty impractical, since it involves several manual steps and messes things up with source control.</p> <p>Does anyone know how I can get the designer.cs file automatically regenerated without having to follow the manual delete/refresh/regenerate/delete process outlined above?</p>
[ { "answer_id": 134670, "author": "DamienG", "author_id": 5720, "author_profile": "https://Stackoverflow.com/users/5720", "pm_score": 4, "selected": true, "text": "sqlmetal /code:DataContext.designer.cs /language:csharp DataContext.dbml\n" }, { "answer_id": 7165688, "author": "Doug", "author_id": 908287, "author_profile": "https://Stackoverflow.com/users/908287", "pm_score": 2, "selected": false, "text": "<Compile Include=\"db.designer.cs\">\n <AutoGen>True</AutoGen>\n <DesignTime>True</DesignTime>\n <DependentUpon>db.dbml</DependentUpon>\n</Compile>\n\n ... \n\n<LastGenOutput>db.designer.cs</LastGenOutput>\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133515", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51/" ]
133,558
<p>I want to log user's actions in my Ruby on Rails application.</p> <p>So far, I have a model observer that inserts logs to the database after updates and creates. In order to store which user performed the action that was logged, I require access to the session but that is problematic.</p> <p>Firstly, it breaks the MVC model. Secondly, techniques range from the hackish to the outlandish, perhaps maybe even tying the implementation to the Mongrel server.</p> <p>What is the right approach to take?</p>
[ { "answer_id": 136389, "author": "Orion Edwards", "author_id": 234, "author_profile": "https://Stackoverflow.com/users/234", "pm_score": 3, "selected": false, "text": "class MyObserverClass < ActiveRecord::Observer\n cattr_accessor :current_user # GLOBAL VARIABLE. RELIES ON RAILS BEING SINGLE THREADED\n\n # other logging code goes here\nend\n\nclass ApplicationController\n before_filter :set_current_user_for_observer\n\n def set_current_user_for_observer\n MyObserverClass.current_user = session[:user]\n end\nend\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133558", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6291/" ]
133,559
<p>I am writing a Windows service that pulls messages from an MSMQ and posts them to a legacy system (Baan). If the post fails or the machine goes down during the post, I don't want to loose the message. I am therefore using MSMQ transactions. I abort on failure, and I commit on success.</p> <p>When working against a local queue, this code works well. But in production I will want to separate the machine (or machines) running the service from the queue itself. When I test against a remote queue, an System.Messaging.MessageQueueException is thrown: "The transaction usage is invalid."</p> <p>I have verified that the queue in question is transactional.</p> <p>Here's the code that receives from the queue:</p> <pre><code>// Begin a transaction. _currentTransaction = new MessageQueueTransaction(); _currentTransaction.Begin(); Message message = queue.Receive(wait ? _queueTimeout : TimeSpan.Zero, _currentTransaction); _logger.Info("Received a message on queue {0}: {1}.", queue.Path, message.Label); WORK_ITEM item = (WORK_ITEM)message.Body; return item; </code></pre> <h2>Answer</h2> <p>I have since switched to <a href="http://www.developer.com/db/article.php/3640771" rel="noreferrer">SQL Service Broker</a>. It supports remote transactional receive, whereas MSMQ 3.0 does not. And, as an added bonus, it already uses the SQL Server instance that we cluster and back up.</p>
[ { "answer_id": 133654, "author": "Maurice", "author_id": 19676, "author_profile": "https://Stackoverflow.com/users/19676", "pm_score": 2, "selected": false, "text": "MessageQueue queue = new MessageQueue(\"myqueue\");\nusing (TransactionScope tx = new TransactionScope()) {\n Message message = queue.Receive(MessageQueueTransactionType.Automatic);\n tx.Complete();\n}\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133559", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7668/" ]
133,569
<p>I usually use C++ stdlib map whenever I need to store some data associated with a specific type of value (a key value - e.g. a string or other object). The stdlib map implementation is based on trees which provides better performance (O(log n)) than the standard array or stdlib vector.</p> <p>My questions is, do you know of any C++ "standard" hashtable implementation that provides even better performance (O(1))? Something similar to what is available in the Hashtable class from the Java API.</p>
[ { "answer_id": 133591, "author": "C. K. Young", "author_id": 13, "author_profile": "https://Stackoverflow.com/users/13", "pm_score": 7, "selected": true, "text": "<unordered_map> <unordered_set> std::unordered_map std::unordered_set std::tr1::unordered_map std::tr1::unordered_set <tr1/unordered_map> <tr1/unordered_set> unordered_multimap unordered_multiset" }, { "answer_id": 133605, "author": "Adam Rosenfield", "author_id": 9530, "author_profile": "https://Stackoverflow.com/users/9530", "pm_score": 2, "selected": false, "text": "stdext::hash_map <hash_map> __gnu_cxx::hash_map" }, { "answer_id": 681982, "author": "rlbond", "author_id": 72631, "author_profile": "https://Stackoverflow.com/users/72631", "pm_score": 2, "selected": false, "text": "<unordered_map> <boost/unordered_map.hpp>" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133569", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20317/" ]
133,571
<p>Wanted to convert</p> <pre><code>&lt;br/&gt; &lt;br/&gt; &lt;br/&gt; &lt;br/&gt; &lt;br/&gt; </code></pre> <p>into</p> <pre><code>&lt;br/&gt; </code></pre>
[ { "answer_id": 133593, "author": "mdec", "author_id": 15534, "author_profile": "https://Stackoverflow.com/users/15534", "pm_score": 2, "selected": false, "text": "<br/> <br/>" }, { "answer_id": 133600, "author": "levik", "author_id": 4465, "author_profile": "https://Stackoverflow.com/users/4465", "pm_score": 6, "selected": true, "text": "preg_replace(\"/(<br\\s*\\/?>\\s*)+/\", \"<br/>\", $input);\n" }, { "answer_id": 133641, "author": "Adam Ness", "author_id": 21973, "author_profile": "https://Stackoverflow.com/users/21973", "pm_score": 1, "selected": false, "text": "$text = preg_replace( \"/(<br\\s?\\/?>)+/i\",\"<br />\", $text );\n" }, { "answer_id": 133659, "author": "enobrev", "author_id": 14651, "author_profile": "https://Stackoverflow.com/users/14651", "pm_score": 4, "selected": false, "text": "preg_replace('/(<br[^>]*>\\s*){2,}/', '<br/>', $sInput);\n" }, { "answer_id": 133683, "author": "mike", "author_id": 19217, "author_profile": "https://Stackoverflow.com/users/19217", "pm_score": 2, "selected": false, "text": "$a = '<br /><br /><br /><br /><br />';\nwhile(($a = str_ireplace('<br /><br />', '<br />', $a, $count)) && $count > 0)\n{}\n// $a becomes '<br />'\n" }, { "answer_id": 133795, "author": "Jake McGraw", "author_id": 302, "author_profile": "https://Stackoverflow.com/users/302", "pm_score": 3, "selected": false, "text": "preg_replace('{(<br[^>]*>\\s*)+}', '<br/>', $input);\n" }, { "answer_id": 1846062, "author": "AndrewC", "author_id": 224646, "author_profile": "https://Stackoverflow.com/users/224646", "pm_score": 3, "selected": false, "text": "{(<br[^>]*>\\s*)+}i\n" }, { "answer_id": 2302821, "author": "Emanuil Rusev", "author_id": 200145, "author_profile": "https://Stackoverflow.com/users/200145", "pm_score": 1, "selected": false, "text": "while(strstr($input, \"<br/><br/>\"))\n{\n $input = str_replace(\"<br/><br/>\", \"<br/>\", $input);\n}\n" }, { "answer_id": 29391913, "author": "vigenist", "author_id": 4701956, "author_profile": "https://Stackoverflow.com/users/4701956", "pm_score": 1, "selected": false, "text": "<br>\n<br/>\n< br />\n<br >\n<BR>\n<BR>< br>\n $str = preg_replace('/(<[^>]*?br[^>]*?>\\s*){2,}/i', '<br>', $str);\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133571", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20907/" ]
133,596
<p>Is there a way to make a Radio Button enabled/disabled (not checked/unchecked) via CSS? </p> <p>I've need to toggle some radio buttons on the client so that the values can be read on the server, but setting the 'enabled' property to 'false' then changing this on the client via javascript seems to prevent me from posting back any changes to the radio button after it's been enabled.</p> <p>See: <a href="https://stackoverflow.com/questions/130165/aspnet-not-seeing-radio-button-value-change">ASP.NET not seeing Radio Button value change</a></p> <p>It was recommended that I use control.style.add("disabled", "true") instead, but this does not seem to disable the radio button for me.</p> <p>Thanks!</p>
[ { "answer_id": 133617, "author": "neuroguy123", "author_id": 12529, "author_profile": "https://Stackoverflow.com/users/12529", "pm_score": 3, "selected": false, "text": "$('#radiobuttonname').attr('disabled', 'true');\n document.getElementById(id).disabled = true;\n" }, { "answer_id": 133636, "author": "JoshReedSchramm", "author_id": 7018, "author_profile": "https://Stackoverflow.com/users/7018", "pm_score": 3, "selected": true, "text": "<script>document.getElementById('<%=CONTROLID%>').disabled=true;</script>\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133596", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6624/" ]
133,601
<p>Is it possible to write a regular expression that matches a nested pattern that occurs an unknown number of times? For example, can a regular expression match an opening and closing brace when there are an unknown number of open/close braces nested within the outer braces?</p> <p>For example:</p> <pre><code>public MyMethod() { if (test) { // More { } } // More { } } // End </code></pre> <p>Should match:</p> <pre><code>{ if (test) { // More { } } // More { } } </code></pre>
[ { "answer_id": 133771, "author": "Zsolt Botykai", "author_id": 11621, "author_profile": "https://Stackoverflow.com/users/11621", "pm_score": 5, "selected": false, "text": "my $NesteD ;\n$NesteD = qr/ \\{( [^{}] | (??{ $NesteD }) )* \\} /x ;\n\nif ( $Stringy =~ m/\\b( \\w+$NesteD )/x ) {\n print \"Found: $1\\n\" ;\n }\n" }, { "answer_id": 133882, "author": "Remo.D", "author_id": 16827, "author_profile": "https://Stackoverflow.com/users/16827", "pm_score": 4, "selected": false, "text": "%b() %b{} {#}" }, { "answer_id": 133968, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "/(?>[^{}]*){(?>[^{}]*)(?R)*(?>[^{}]*)}/sm" }, { "answer_id": 2563520, "author": "Sean Huber", "author_id": 144063, "author_profile": "https://Stackoverflow.com/users/144063", "pm_score": 0, "selected": false, "text": "/(\\{(?:\\{.*\\}|[^\\{])*\\})/m" }, { "answer_id": 3851098, "author": "Michael", "author_id": 215384, "author_profile": "https://Stackoverflow.com/users/215384", "pm_score": 5, "selected": false, "text": "'/(\\((?>[^()]+|(?1))*\\))/'\n" }, { "answer_id": 12455760, "author": "Pete B", "author_id": 263643, "author_profile": "https://Stackoverflow.com/users/263643", "pm_score": 3, "selected": false, "text": "$patt = '!\\( (?: (?: (?>[^()]+) | (?R) )* ) \\)!x';\n\npreg_match_all( $patt, $str, $m );\n matchBrackets( $str );\n\nfunction matchBrackets ( $str, $offset = 0 ) {\n\n $matches = array();\n\n list( $opener, $closer ) = array( '(', ')' );\n\n // Return early if there's no match\n if ( false === ( $first_offset = strpos( $str, $opener, $offset ) ) ) {\n return $matches;\n }\n\n // Step through the string one character at a time storing offsets\n $paren_score = -1;\n $inside_paren = false;\n $match_start = 0;\n $offsets = array();\n\n for ( $index = $first_offset; $index < strlen( $str ); $index++ ) {\n $char = $str[ $index ];\n\n if ( $opener === $char ) {\n if ( ! $inside_paren ) {\n $paren_score = 1;\n $match_start = $index;\n }\n else {\n $paren_score++;\n }\n $inside_paren = true;\n }\n elseif ( $closer === $char ) {\n $paren_score--;\n }\n\n if ( 0 === $paren_score ) {\n $inside_paren = false;\n $paren_score = -1;\n $offsets[] = array( $match_start, $index + 1 );\n }\n }\n\n while ( $offset = array_shift( $offsets ) ) {\n\n list( $start, $finish ) = $offset;\n\n $match = substr( $str, $start, $finish - $start );\n $matches[] = $match;\n }\n\n return $matches;\n}\n" }, { "answer_id": 49533163, "author": "awwsmm", "author_id": 2925434, "author_profile": "https://Stackoverflow.com/users/2925434", "pm_score": 3, "selected": false, "text": "(* This is a comment (* this is nested inside (* another level! *) hey *) yo *)\n m{1} = \\(+\\*+(?:[^*(]|(?:\\*+[^)*])|(?:\\(+[^*(]))*\\*+\\)+\n \\(+\\*+ \\*+\\)+ { } [^{}] p{1} = \\{(?:[^{}])*\\}\n p{2} = \\{(?:(?:p{1})|(?:[^{}]))*\\}\n ...or...\np{2} = \\{(?:(?:\\{(?:[^{}])*\\})|(?:[^{}]))*\\}\n p{3} = \\{(?:(?:p{2})|(?:[^{}]))*\\}\n ...or...\np{3} = \\{(?:(?:\\{(?:(?:\\{(?:[^{}])*\\})|(?:[^{}]))*\\})|(?:[^{}]))*\\}\n N p{N} = \\{(?:(?:p{N-1})|(?:[^{}]))*\\}\n\n where N > 1 and\n p{1} = \\{(?:[^{}])*\\}\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133601", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1199234/" ]
133,610
<p>Ok, this is another one in the theory realm for the CS guys around.</p> <p>In the 90's I did fairly well in implementing BST's. The only thing I could never get my head around was the intricacy of the algorithm to balance a Binary Tree (AVL).</p> <p>Can you guys help me on this?</p>
[ { "answer_id": 267453, "author": "mscccc", "author_id": 2510, "author_profile": "https://Stackoverflow.com/users/2510", "pm_score": 2, "selected": false, "text": "IF tree is right heavy\n{\n IF tree's right subtree is left heavy\n {\n Perform Double Left rotation \n }\n ELSE\n {\n Perform Single Left rotation\n }\n}\nELSE IF tree is left heavy\n{\n IF tree's left subtree is right heavy\n {\n Perform Double Right rotation\n }\n ELSE\n {\n Perform Single Right rotation\n }\n}\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133610", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8167/" ]
133,626
<p>I am using Vim for windows installed in Unix mode. Thanks to this site I now use the <code>gf</code> command to go to a file under the cursor.</p> <p>I'm looking for a command to either:</p> <ol> <li>return to the previous file (similar to <kbd>Ctrl</kbd>+<kbd>T</kbd> for ctags), or </li> <li>remap <code>gf</code> to automatically launch the new file in a new window.</li> </ol>
[ { "answer_id": 133634, "author": "tzot", "author_id": 6899, "author_profile": "https://Stackoverflow.com/users/6899", "pm_score": 4, "selected": false, "text": ":e#↲" }, { "answer_id": 133661, "author": "paxdiablo", "author_id": 14860, "author_profile": "https://Stackoverflow.com/users/14860", "pm_score": 4, "selected": false, "text": ":e#" }, { "answer_id": 133895, "author": "codebunny", "author_id": 13667, "author_profile": "https://Stackoverflow.com/users/13667", "pm_score": 3, "selected": false, "text": ":e#\n :buffers\n nmap `<F2> :e#<CR>`\n" }, { "answer_id": 138214, "author": "Oli", "author_id": 22035, "author_profile": "https://Stackoverflow.com/users/22035", "pm_score": 2, "selected": false, "text": "nmap <M-LEFT> :bN<cr>\nnmap <M-RIGHT> :bn<cr>\n :help map.txt\n" }, { "answer_id": 138499, "author": "Roman Odaisky", "author_id": 21055, "author_profile": "https://Stackoverflow.com/users/21055", "pm_score": 6, "selected": false, "text": "CTRL-W gf :bd CTRL-6" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133626", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5823/" ]
133,648
<p>I want to insert say 50,000 records into sql server database 2000 at a time. How to accomplish this?</p>
[ { "answer_id": 133687, "author": "Galwegian", "author_id": 3201, "author_profile": "https://Stackoverflow.com/users/3201", "pm_score": 0, "selected": false, "text": "declare @index integer\nset @index = 0\nwhile @index < 50000\nbegin\n insert into table\n values (x,y,z)\n set @index = @index + 1\nend\n BULK INSERT bcp" }, { "answer_id": 133852, "author": "Giacomo Degli Esposti", "author_id": 20796, "author_profile": "https://Stackoverflow.com/users/20796", "pm_score": 4, "selected": true, "text": "begin\ndeclare @n int, @rows int\n\n select @rows = count(*) from sourcetable\n\n select @n=0\n\n while @n < @rows\n begin\n\n insert into desttable\n select top 2000 * \n from sourcetable\n where id_sourcetable not in (select top (@n) id_sourcetable \n from sourcetable \n order by id_sourcetable)\n order by id_sourcetable\n\n select @n=@n+2000\n end\nend\n" }, { "answer_id": 133975, "author": "HLGEM", "author_id": 9034, "author_profile": "https://Stackoverflow.com/users/9034", "pm_score": 0, "selected": false, "text": "insert mytable (field1, field2, field3)\nselect top 2000 pa.field1, pa.field2, pa.field3 \nfrom table1 pa (nolock) \nleft join mytable ta (nolock)on ta.field2 = pa.feild2\n and ta.field3 = pa.field3 and ta.field1 = pa.field1\nwhere ta.field1 is null\norder by pa.field1\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133648", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1688440/" ]
133,660
<p>I need to create a directory on a mapped network drive. I am using a code:</p> <pre><code>DirectoryInfo targetDirectory = new DirectoryInfo(path); if (targetDirectory != null) { targetDirectory.Create(); } </code></pre> <p>If I specify the path like "\\\\ServerName\\Directory", it all goes OK. If I map the "\\ServerName\Directory" as, say drive Z:, and specify the path like "Z:\\", it fails.</p> <p>After the creating the targetDirectory object, VS shows (in the debug mode) that targetDirectory.Exists = false, and trying to do targetDirectory.Create() throws an exception:</p> <pre><code>System.IO.DirectoryNotFoundException: "Could not find a part of the path 'Z:\'." </code></pre> <p>However, the same code works well with local directories, e.g. C:.</p> <p>The application is a Windows service (WinXP Pro, SP2, .NET 2) running under the same account as the user that mapped the drive. Qwinsta replies that the user's session is the session 0, so it is the same session as the service's.</p>
[ { "answer_id": 23087325, "author": "IAmGroot", "author_id": 940834, "author_profile": "https://Stackoverflow.com/users/940834", "pm_score": 4, "selected": false, "text": "R:/ \\\\myserver\\files\\myapp\\ \"R:/\" + \"photos\" \"\\\\myserver\\files\\myapp\\\" + \"photos\"" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133660", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
133,671
<p>In my ASP.net MVC app I have a view that looks like this:</p> <pre><code>... &lt;label&gt;Due Date&lt;/label&gt; &lt;%=Html.TextBox("due")%&gt; ... </code></pre> <p>I am using a <code>ModelBinder</code> to bind the post to my model (the due property is of <code>DateTime</code> type). The problem is when I put "01/01/2009" into the textbox, and the post does not validate (due to other data being input incorrectly). The binder repopulates it with the date <strong>and time</strong> "01/01/2009 <strong>00:00:00</strong>". </p> <p><strong>Is there any way to tell the binder to format the date correctly (i.e. <code>ToShortDateString()</code>)?</strong></p>
[ { "answer_id": 134097, "author": "Switters", "author_id": 1860358, "author_profile": "https://Stackoverflow.com/users/1860358", "pm_score": 1, "selected": false, "text": "public partial class SomethingView : ViewPage<T>\n{\n}\n public ActionResult Something(){\n T myObject = new T();\n T.Property = DateTime.Today();\n\n Return View(\"Something\", myObject);\n}\n <label>My Property</label>\n<%=Html.TextBox(ViewData.Model.Property.ToShortDateString())%>\n" }, { "answer_id": 134613, "author": "Switters", "author_id": 1860358, "author_profile": "https://Stackoverflow.com/users/1860358", "pm_score": 0, "selected": false, "text": "public class SomeTypeBinder : IModelBinder\n{\n public object GetValue(ControllerContext controllerContext, string modelName,\n Type modelType, ModelStateDictionary modelState)\n {\n SomeType temp = new SomeType();\n //assign values normally\n //If an error then add formatted date to ViewState\n controllerContext.Controller.ViewData.Add(\"FormattedDate\",\n temp.Date.ToShortDateString());\n }\n}\n <%= Html.TextBox(\"FormattedDate\") %>\n" }, { "answer_id": 138338, "author": "Casper", "author_id": 18729, "author_profile": "https://Stackoverflow.com/users/18729", "pm_score": 2, "selected": false, "text": "<% =Html.TextBox(\"due\", Model.due.ToShortDateString()) %>\n" }, { "answer_id": 1276477, "author": "Craig M", "author_id": 156239, "author_profile": "https://Stackoverflow.com/users/156239", "pm_score": 2, "selected": false, "text": "<%= Html.TextBox(String.Format(\"{0:d}\", Model.Property)) %>\n" }, { "answer_id": 1544389, "author": "Ollie", "author_id": 4453, "author_profile": "https://Stackoverflow.com/users/4453", "pm_score": 1, "selected": false, "text": "ModelState.SetModelValue(\"due\", new ValueProviderResult(\n due.ToShortDateString(), \n due.ToShortDateString(), \n null));\n" }, { "answer_id": 2282294, "author": "Serhiy", "author_id": 246719, "author_profile": "https://Stackoverflow.com/users/246719", "pm_score": 2, "selected": false, "text": "public static class ExpressionParseHelper\n{\n public static string GetPropertyPath<TEntity, TProperty>(Expression<Func<TEntity, TProperty>> property)\n { \n Match match = Regex.Match(property.ToString(), @\"^[^\\.]+\\.([^\\(\\)]+)$\");\n return match.Groups[1].Value;\n }\n}\n public static MvcHtmlString DateBoxFor<TEntity>(\n this HtmlHelper helper,\n TEntity model,\n Expression<Func<TEntity, DateTime?>> property,\n object htmlAttributes)\n {\n DateTime? date = property.Compile().Invoke(model);\n var value = date.HasValue ? date.Value.ToShortDateString() : string.Empty;\n var name = ExpressionParseHelper.GetPropertyPath(property);\n\n return helper.TextBox(name, value, htmlAttributes);\n }\n $(function() {\n $(\"input.datebox\").datepicker();\n});\n <%= Html.DateBoxFor(Model, (x => x.Entity.SomeDate), new { @class = \"datebox\" }) %>\n" }, { "answer_id": 2315136, "author": "Cephas", "author_id": 29814, "author_profile": "https://Stackoverflow.com/users/29814", "pm_score": 3, "selected": false, "text": "<%= Html.TextBoxFor(model => model.SomeDate,\n new Dictionary<string, object> { { \"Value\", Model.SomeDate.ToShortDateString() } })%>\n" }, { "answer_id": 2341671, "author": "Nick Chadwick", "author_id": 282033, "author_profile": "https://Stackoverflow.com/users/282033", "pm_score": 6, "selected": false, "text": " <%=Html.LabelFor(m => m.due) %>\n <%=Html.EditorFor(m => m.due)%>\n <%@ Control Language=\"C#\" Inherits=\"System.Web.Mvc.ViewUserControl<System.DateTime?>\" %>\n<%=Html.TextBox(\"\", (Model.HasValue ? Model.Value.ToShortDateString() : string.Empty), new { @class = \"datePicker\" }) %>\n" }, { "answer_id": 4058891, "author": "Qerim Shahini", "author_id": 63786, "author_profile": "https://Stackoverflow.com/users/63786", "pm_score": 5, "selected": false, "text": "DataType Date DateTime public class Model {\n [DataType(DataType.Date)]\n public DateTime? Due { get; set; }\n}\n EditorFor TextBoxFor @Html.EditorFor(m => m.Due)\n" }, { "answer_id": 8438301, "author": "RayLoveless", "author_id": 462971, "author_profile": "https://Stackoverflow.com/users/462971", "pm_score": 0, "selected": false, "text": "<%: Html.TextBoxFor(m => m.myDate, new { @value = Model.myDate.ToShortDateString()}) %>" }, { "answer_id": 14576512, "author": "Krushna", "author_id": 2020523, "author_profile": "https://Stackoverflow.com/users/2020523", "pm_score": 0, "selected": false, "text": "<%:Html.TextBoxFor(m => m.FromDate, new { @Value = (String.Format(\"{0:dd/MM/yyyy}\", Model.FromDate)) }) %>\n" }, { "answer_id": 20672790, "author": "user2887440", "author_id": 2887440, "author_profile": "https://Stackoverflow.com/users/2887440", "pm_score": 0, "selected": false, "text": "ViewModel.SEnd = DateTime.Now //preload todays date \nreturn View(ViewModel) //pass to view\n @Html.EditedFor(item.SEnd) //allow edit\n <td>\n @Html.DisplyFor(item.SEnd) //show no edit\n </td>\n @Html.HiddenFor(model => model.SEnd) //preserve value for passback.\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133671", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1736/" ]
133,675
<p>I need to implement red eye reduction for an application I am working on.</p> <p>Googling mostly provides links to commercial end-user products.</p> <p>Do you know a good red eye reduction algorithm, which could be used in a GPL application?</p>
[ { "answer_id": 718648, "author": "Benry", "author_id": 28408, "author_profile": "https://Stackoverflow.com/users/28408", "pm_score": 6, "selected": true, "text": "//Value of red divided by average of blue and green:\nPixel pixel = image.getPixel(x,y);\nfloat redIntensity = ((float)pixel.R / ((pixel.G + pixel.B) / 2));\nif (redIntensity > 1.5f) // 1.5 because it gives the best results\n{\n // reduce red to the average of blue and green\n bm.SetPixel(i, j, Color.FromArgb((pixel.G + pixel.B) / 2, pixel.G, pixel.B));\n}\n" }, { "answer_id": 5954111, "author": "Ademir Constantino", "author_id": 377336, "author_profile": "https://Stackoverflow.com/users/377336", "pm_score": 2, "selected": false, "text": "public void corrigirRedEye(int posStartX, int maxX, int posStartY, int maxY, BufferedImage image) {\n for(int x = posStartX; x < maxX; x++) {\n for(int y = posStartY; y < maxY; y++) {\n\n int c = image.getRGB(x,y);\n int red = (c & 0x00ff0000) >> 16;\n int green = (c & 0x0000ff00) >> 8;\n int blue = c & 0x000000ff;\n\n float redIntensity = ((float)red / ((green + blue) / 2));\n if (redIntensity > 2.2) {\n Color newColor = new Color(90, green, blue);\n image.setRGB(x, y, newColor.getRGB());\n }\n\n\n }\n }\n}\n int posStartY = (int) leftEye.getY();\n\n int maxX = (int) (leftEye.getX() + leftEye.getWidth());\n int maxY = (int) (leftEye.getY() + leftEye.getHeight());\n\n this.corrigirRedEye(posStartX, maxX, posStartY, maxY, image);\n\n // right eye\n\n posStartX = (int) rightEye.getX();\n posStartY = (int) rightEye.getY();\n\n maxX = (int) (rightEye.getX() + rightEye.getWidth());\n maxY = (int) (rightEye.getY() + rightEye.getHeight());\n\n this.corrigirRedEye(posStartX, maxX, posStartY, maxY, image);\n" }, { "answer_id": 12573060, "author": "charles young", "author_id": 604608, "author_profile": "https://Stackoverflow.com/users/604608", "pm_score": 2, "selected": false, "text": " using SD = System.Drawing;\n\n public static SD.Image ReduceRedEye(SD.Image img, SD.Rectangle eyesRect)\n {\n if ( (eyesRect.Height > 0)\n && (eyesRect.Width > 0)) {\n SD.Bitmap bmpImage = new SD.Bitmap(img);\n for (int x=eyesRect.X;x<(eyesRect.X+eyesRect.Width);x++) {\n for (int y=eyesRect.Y;y<(eyesRect.Y+eyesRect.Height);y++) {\n //Value of red divided by average of blue and green:\n SD.Color pixel = bmpImage.GetPixel(x,y);\n float redIntensity = ((float)pixel.R / ((pixel.G + pixel.B) / 2));\n if (redIntensity > 2.2f)\n {\n // reduce red to the average of blue and green\n bmpImage.SetPixel(x, y, SD.Color.FromArgb((pixel.G + pixel.B) / 2, pixel.G, pixel.B));\n pixel = bmpImage.GetPixel(x,y); // for debug\n }\n }\n }\n return (SD.Image)(bmpImage);\n }\n return null;\n }\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133675", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20107/" ]
133,680
<p>When I am using Bitvise Tunnelier and I spawn a new xterm window connecting to our sun station everything works nicely. We have visual slick edit installed on the sun station and I have been instructed to open it using the command vs&amp;. When I do this I get the following:</p> <pre><code>fbm240-1:/home/users/ajahn 1 % vs&amp; [1] 4716 fbm240-1:/home/users/ajahn 2 % Visual SlickEdit: Can't open connection to X. DIS PLAY='&lt;Default Display&gt;' </code></pre> <p>I would rather not go jumping through hoops ftping my material back and forth to the server. Advice?</p>
[ { "answer_id": 133736, "author": "tzot", "author_id": 6899, "author_profile": "https://Stackoverflow.com/users/6899", "pm_score": 0, "selected": false, "text": "xhost +" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133680", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5831/" ]
133,686
<p>I'd like to find a way to determine how long each function in PHP, and each file in PHP is taking to run. I've got an old legacy PHP application that I'm trying to find the "rough spots" in and so I'd like to locate which routines and pages are taking a very long time to load, objectively. </p> <p>Are there any pre-made tools that allow for this, or am I stuck using microtime, and building my own profiling framework?</p>
[ { "answer_id": 3356079, "author": "petsagouris", "author_id": 140734, "author_profile": "https://Stackoverflow.com/users/140734", "pm_score": 3, "selected": false, "text": "javascript:if(document.URL.indexOf('XDEBUG_PROFILE')<1){var%20sep=document.URL.indexOf('?');sep%20=%20(sep<1)?'?':'&';window.location.href=document.URL+sep+'XDEBUG_PROFILE';}\n" } ]
2008/09/25
[ "https://Stackoverflow.com/questions/133686", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21973/" ]