qid
int64
4
19.1M
question
stringlengths
18
48.3k
answers
list
date
stringlengths
10
10
metadata
list
330,622
<p>In C# language when you refer to an array element you can write:</p> <p>myclass.my_array['element_name'] = new Point(1,1);</p> <p>I think about refering to a element with name element_name by using dot in place of backets:</p> <p>myclass.my_array.element_name = new Point(1,1);</p> <p>Do you know any language where exists similar syntax to the example above?</p> <p>What do you think about this example of refering to a array element? Is this good or is it as bad as my writing in english skills?</p> <p>Kind regards</p>
[ { "answer_id": 330640, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 3, "selected": true, "text": "XElement author = doc.Root.Posts.Author;\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/330622", "https://Stackoverflow.com", "https://Stackoverflow.com/users/38940/" ]
330,625
<p>We have implemented a popup window as a modal dialog using the IE method:</p> <pre><code>window.showModalDialog('...aspx') </code></pre> <p>The target of the popup window is itself an ASP.Net web page.</p> <p>Assume for the following steps that the popup has never been launched:</p> <ol> <li>Launch popup.</li> <li>Page_Load event handler executes on server side.</li> <li>Close popup.</li> <li>Immediately launch popup again.</li> <li>This time Page_Load event handler doesn't execute.</li> </ol> <p>It's clear that the popup content is being cached because if at Step 4 we clear the temporary internet files the Page_Load event handler is executed the second time.</p> <p>We have experimented with adding the following to the Head of the web page (as recommended by several other sources) but none of it seems to work. </p> <pre><code>&lt;meta http-equiv="Cache-Control" content="no-cache" /&gt; &lt;meta http-equiv="Pragma" content="no-cache" /&gt; &lt;meta http-equiv="Expires" content="-1" /&gt; </code></pre> <p>We have also seen places where the use of these is <a href="http://code.google.com/webstats/2005-12/metadata.html" rel="nofollow noreferrer">discouraged</a></p> <p>Can anyone help?</p>
[ { "answer_id": 333451, "author": "Andy McCluggage", "author_id": 3362, "author_profile": "https://Stackoverflow.com/users/3362", "pm_score": 2, "selected": false, "text": "url = \"<Some url with query string>\"\nvar date = new Date();\nwindow.showModalDialog(url + “&” + date.getTime(), ... );\n" }, { "answer_id": 421065, "author": "user43332", "author_id": 43332, "author_profile": "https://Stackoverflow.com/users/43332", "pm_score": 0, "selected": false, "text": "<html>\n <head><title>Blah</title></head>\n <body>Contents</body>\n</html>\n<html>\n <head>\n <meta http-equiv=\"Cache-Control\" content=\"no-cache\" />\n <meta http-equiv=\"Pragma\" content=\"no-cache\" />\n <meta http-equiv=\"Expires\" content=\"-1\" />\n </head>\n</html>\n" }, { "answer_id": 2342906, "author": "F. Dobon", "author_id": 282177, "author_profile": "https://Stackoverflow.com/users/282177", "pm_score": 3, "selected": false, "text": "Response.Cache.SetCacheability(HttpCacheability.NoCache);\n" }, { "answer_id": 4873329, "author": "André", "author_id": 599836, "author_profile": "https://Stackoverflow.com/users/599836", "pm_score": 1, "selected": false, "text": "<base target=\"_top\" />\n <meta http-equiv=\"Expires\" content=\"0\" />\n<meta http-equiv=\"Cache-Control\" content=\"no-cache, must-revalidate\" />\n<meta http-equiv=\"Pragma\" content=\"no-cache\" />\n<base target=\"_top\" />\n" }, { "answer_id": 7651215, "author": "Kamalakar Dandu", "author_id": 978899, "author_profile": "https://Stackoverflow.com/users/978899", "pm_score": 2, "selected": false, "text": "meta http-equiv=\"Cache-Control\" content=\"no-cache\" \nmeta http-equiv=\"Pragma\" content=\"no-cache\" \nmeta http-equiv=\"Expires\" content=\"-1\" \n vat time = new Date().getTime();\n\nurl?queryString&time=time\n" }, { "answer_id": 11876563, "author": "Abey", "author_id": 984999, "author_profile": "https://Stackoverflow.com/users/984999", "pm_score": 0, "selected": false, "text": "<%@ OutputCache Location=\"None\" %>\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/330625", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3362/" ]
330,630
<p>I have written a database application using a binary file as storage. it is accessed via powershell cmdlets.</p> <p>You can put information into the database using the put- and you can read information using get-.</p> <p>The problem is synchronisation. What is the best way to ensure that the cmdlets don't access the file at the same time?</p> <p>The put- must have exclusive access ie no other writers or readers can access the file. The get- doesn't need exclusive access or readers can access the database at the same time.</p> <p>Am I best using a file based locking mechanism or a .NET based synchronisation mechanism?</p>
[ { "answer_id": 333451, "author": "Andy McCluggage", "author_id": 3362, "author_profile": "https://Stackoverflow.com/users/3362", "pm_score": 2, "selected": false, "text": "url = \"<Some url with query string>\"\nvar date = new Date();\nwindow.showModalDialog(url + “&” + date.getTime(), ... );\n" }, { "answer_id": 421065, "author": "user43332", "author_id": 43332, "author_profile": "https://Stackoverflow.com/users/43332", "pm_score": 0, "selected": false, "text": "<html>\n <head><title>Blah</title></head>\n <body>Contents</body>\n</html>\n<html>\n <head>\n <meta http-equiv=\"Cache-Control\" content=\"no-cache\" />\n <meta http-equiv=\"Pragma\" content=\"no-cache\" />\n <meta http-equiv=\"Expires\" content=\"-1\" />\n </head>\n</html>\n" }, { "answer_id": 2342906, "author": "F. Dobon", "author_id": 282177, "author_profile": "https://Stackoverflow.com/users/282177", "pm_score": 3, "selected": false, "text": "Response.Cache.SetCacheability(HttpCacheability.NoCache);\n" }, { "answer_id": 4873329, "author": "André", "author_id": 599836, "author_profile": "https://Stackoverflow.com/users/599836", "pm_score": 1, "selected": false, "text": "<base target=\"_top\" />\n <meta http-equiv=\"Expires\" content=\"0\" />\n<meta http-equiv=\"Cache-Control\" content=\"no-cache, must-revalidate\" />\n<meta http-equiv=\"Pragma\" content=\"no-cache\" />\n<base target=\"_top\" />\n" }, { "answer_id": 7651215, "author": "Kamalakar Dandu", "author_id": 978899, "author_profile": "https://Stackoverflow.com/users/978899", "pm_score": 2, "selected": false, "text": "meta http-equiv=\"Cache-Control\" content=\"no-cache\" \nmeta http-equiv=\"Pragma\" content=\"no-cache\" \nmeta http-equiv=\"Expires\" content=\"-1\" \n vat time = new Date().getTime();\n\nurl?queryString&time=time\n" }, { "answer_id": 11876563, "author": "Abey", "author_id": 984999, "author_profile": "https://Stackoverflow.com/users/984999", "pm_score": 0, "selected": false, "text": "<%@ OutputCache Location=\"None\" %>\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/330630", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42109/" ]
330,649
<p>I have followed the suggestion in this question...</p> <p>[<a href="https://stackoverflow.com/questions/220020/how-to-handle-checkboxes-in-aspnet-mvc-forms][1]">How to handle checkboxes in ASP.NET MVC forms?</a></p> <p>...to setup multiple checkboxes with the same name="..." attribute and the form behaves as expected the FIRST time its submitted. Subsequent submissions of the form use the original array of Guid values instead of properly sending the new array of checked item values.</p> <p>Relevant code in the view...</p> <pre><code> &lt;% foreach (ItemType itemType in ViewData.Model.ItemTypes) %&gt; &lt;%{ %&gt; &lt;li&gt; &lt;input id="selectedItems" name="selectedItems" type="checkbox" value="&lt;%= itemType.Id%&gt;" /&gt; &lt;%= itemType.Description %&gt;&lt;/li&gt; &lt;%} %&gt; </code></pre> <p>This produces a series of checkboxes, one each for each item with the value="..." attribute set to the Id of the item.</p> <p>Then in my controller action, the method signature is...</p> <pre><code>[AcceptVerbs(HttpVerbs.Post)] public ActionResult SelectItems(Guid[] selectedItems) {...} </code></pre> <p>The first time thru the method, the selectedItems array properly holds the Guid of each item selected. But subsequent submits of the form will <em>always</em> still contain whatever was first selected in the initial submit action, no matter what changes you make to what it checked before you submit the form. This doesn't seem to have anything to do with my code, as inspecting the selectedItems array that the MVC framework passes to the method evidences that the framework seems to always be submitting the same value over and over again.</p> <p>Close browser, start again, selecet different initial checkbox on submit and the process starts all over again (the initially-selected checkbox ids are <em>always</em> what's in the selectedItems argument).</p> <p>Assume I must be thick and overlooking some kind of caching of form values by the framework, but I would swear this didn't behave this way in Preview 5.</p> <p>Driving me nuts and probably simple issue; any ideas????</p>
[ { "answer_id": 330682, "author": "leppie", "author_id": 15541, "author_profile": "https://Stackoverflow.com/users/15541", "pm_score": 2, "selected": true, "text": " // please MS, stop screwing around!!!!!!!!!!!!!!!\n string r = Request.Form[\"r\"];\n" }, { "answer_id": 330771, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "[AcceptVerbs(HttpVerbs.Post)]\npublic ActionResult SelectItems(Guid[] selectedItems)\n{\n /* lol snip */\n return RedirectToAction(\"WhateverActionIsTheGetVersionOfThisPostAction\");\n}\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/330649", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23208/" ]
330,662
<p>I am downloading a text string from a web service into an RBuf8 using this kind of code (it works..)</p> <pre><code>void CMyApp::BodyReceivedL( const TDesC8&amp; data ) { int newLength = iTextBuffer.Length() + data.Length(); if (iTextBuffer.MaxLength() &lt; newLength) { iTextBuffer.ReAllocL(newLength); } iTextBuffer.Append(data); } </code></pre> <p>I want to then convert the RBuf8 into a char* string I can display in a label or whatever.. or for the purposes of debug, display in</p> <pre><code>RDebug::Printf("downloading text %S", charstring); </code></pre> <p><strong>edit</strong> for clarity..</p> <p>My conversion function looks like this..</p> <p>void CMyApp::DownloadCompleteL() { { RBuf16 buf; buf.CreateL(iTextBuffer.Length()); buf.Copy(iTextBuffer);</p> <pre><code> RDebug::Printf("downloaded text %S", buf); iTextBuffer.SetLength(0); iTextBuffer.ReAlloc(0); } </code></pre> <p>But this still causes a crash. I am using S60 3rd Edition FP2 v1.1</p>
[ { "answer_id": 330718, "author": "adam", "author_id": 33604, "author_profile": "https://Stackoverflow.com/users/33604", "pm_score": 0, "selected": false, "text": "void CMyApp::DownloadCompleteL() {\n {\n RBuf16 buf;\n buf.CreateL(iTextBuffer.Length());\n buf.Copy(iTextBuffer);\n\n RDebug::Printf(\"downloaded text %S\", buf);\n iTextBuffer.SetLength(0);\n iTextBuffer.ReAlloc(0); \n }\n" }, { "answer_id": 330788, "author": "Mark Cheeseborough", "author_id": 13570, "author_profile": "https://Stackoverflow.com/users/13570", "pm_score": -1, "selected": false, "text": "RDebug::Printf(\"downloaded text %S\", &buf); //note the address-of operator RBuf8 TDes8" }, { "answer_id": 330790, "author": "ayaz", "author_id": 23191, "author_profile": "https://Stackoverflow.com/users/23191", "pm_score": 2, "selected": true, "text": "RDebug::Print( _L( \"downloaded text %S\" ), &buf );\n" }, { "answer_id": 334389, "author": "Dynite", "author_id": 16177, "author_profile": "https://Stackoverflow.com/users/16177", "pm_score": 0, "selected": false, "text": "RDebug::Print(_L(\"downloaded text %S\"), &buf);\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/330662", "https://Stackoverflow.com", "https://Stackoverflow.com/users/33604/" ]
330,666
<p>What does ::Base part mean in Person &lt; ActiveRecord::Base class declaration? I'm new to ruby and from what I've gathered so far, Person &lt; ActiveRecord should be used. Thank you.</p>
[ { "answer_id": 330712, "author": "Dan Vinton", "author_id": 21849, "author_profile": "https://Stackoverflow.com/users/21849", "pm_score": 3, "selected": false, "text": ":: ActiveRecord::Base ActiveRecord Base ActiveRecord" }, { "answer_id": 39137919, "author": "Sarvnashak", "author_id": 3354384, "author_profile": "https://Stackoverflow.com/users/3354384", "pm_score": 3, "selected": false, "text": ":: ActiveRecord::Base module ActiveRecord\n class Base\n end\nend\n Base ActiveRecord ActiveRecord::Base MR_COUNT = 0 # constant defined on main Object class\nmodule Foo\n MR_COUNT = 0\n ::MR_COUNT = 1 # set global count to 1\n MR_COUNT = 2 # set local count to 2\nend\nputs MR_COUNT # this is the global constant\nputs Foo::MR_COUNT # this is the local \"Foo\" constant\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/330666", "https://Stackoverflow.com", "https://Stackoverflow.com/users/430254/" ]
330,685
<p>I want to make a schedule for many pastors. The conditions are:</p> <ol> <li>Every month, each pastor must must go to another church, </li> <li>The pastor must not go to same church where he came</li> <li>In 1 year he must go to 12 different churches</li> <li>There is 13 churches and 13 pastors and every church accepts only 1 pastor every month</li> </ol> <p>I can't use random(1 to 12) because there is a chance the pastor could go to the same church (8,3% chance he goes to the same church).</p> <p>I want to make the chance small (around 3% or less) that he goes to same church.</p>
[ { "answer_id": 330894, "author": "Nick Johnson", "author_id": 12030, "author_profile": "https://Stackoverflow.com/users/12030", "pm_score": 1, "selected": false, "text": "def knuth_shuffle(l):\n for i in range(len(l)):\n j = random.randint(i, len(l))\n l[i], l[j] = l[j], l[i]\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/330685", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41780/" ]
330,688
<p>I'm using the following query, but I currently have to enter a value in every parameter for the query to work. Is there a way of making the parameters optional, so that 1 or more values will return a result?</p> <pre><code>SELECT * FROM film WHERE day LIKE '%day%' AND month LIKE '%month%' AND year LIKE '%year%' </code></pre> <hr> <p>something like</p> <pre><code> function queryData(year,month,day) declare Y if year == nothing Y = '%' else Y = '%' + year + '%' declare M if month == nothing M = '%' else M = '%' + month + '%' declare D if day == nothing D = '%' else D = '%' + day + '%' return result of : SELECT * FROM film WHERE day LIKE D OR month LIKE M OR year LIKE Y </code></pre>
[ { "answer_id": 330703, "author": "adam", "author_id": 33604, "author_profile": "https://Stackoverflow.com/users/33604", "pm_score": 0, "selected": false, "text": "SELECT * FROM film\nWHERE day LIKE '%day%'\nOR month LIKE '%month%'\nOR year LIKE '%year%'\n" }, { "answer_id": 330781, "author": "Samiksha", "author_id": 29515, "author_profile": "https://Stackoverflow.com/users/29515", "pm_score": 1, "selected": false, "text": "string query = \"SELECT * FROM film\";\nstring paramenters = string.empty;\n\nif(day!= string.empty)\n parameters = \" Where day LIKE '%day%'\";\n\nif(month != string.empty)\n{\n if(parameters != string.empty)\n parameters += \"AND month LIKE '%month%'\";\n else\n parameters = \"WHERE month LIKE '%month%'\";\n}\n OR" }, { "answer_id": 330814, "author": "foxy", "author_id": 30119, "author_profile": "https://Stackoverflow.com/users/30119", "pm_score": 0, "selected": false, "text": "day = \"\"\nmonth = \"dec\"\nyear = \"2008\"\n SELECT * FROM film\nWHERE day LIKE '%%'\nAND month LIKE '%dec%'\nAND year LIKE '%2008%'\n '%%'" }, { "answer_id": 330928, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "if year == nothing\n Y = ''\nelse\n Y = '%' + year + '%'\n" }, { "answer_id": 7725875, "author": "Maarten van Leunen", "author_id": 415848, "author_profile": "https://Stackoverflow.com/users/415848", "pm_score": 0, "selected": false, "text": "SELECT * FROM film\nWHERE (:daysearch is null or day LIKE :daysearch)\nAND (:monthsearch is null or month LIKE :monthsearch)\nAND (:yearsearch is null or year LIKE :yearsearch)\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/330688", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
330,707
<p>I'm using an SqlCommand object to insert a record into a table with an autogenerated primary key. How can I write the command text so that I get the newly created ID when I use the ExecuteScalar() method?</p>
[ { "answer_id": 330721, "author": "JoshBerke", "author_id": 26160, "author_profile": "https://Stackoverflow.com/users/26160", "pm_score": 4, "selected": false, "text": "insert into Yourtable() \nvalues() \nSELECT SCOPE_IDENTITY()\n" }, { "answer_id": 330723, "author": "Treb", "author_id": 22114, "author_profile": "https://Stackoverflow.com/users/22114", "pm_score": 1, "selected": false, "text": "@@IDENTITY SCOPE_IDENTITY SCOPE_IDENTITY @@IDENTITY SCOPE_IDENTITY @@IDENTITY" }, { "answer_id": 330728, "author": "Dave Markle", "author_id": 24995, "author_profile": "https://Stackoverflow.com/users/24995", "pm_score": 7, "selected": true, "text": "INSERT INTO YourTable(val1, val2, val3 ...) \nVALUES(@val1, @val2, @val3...);\nSELECT SCOPE_IDENTITY();\n" }, { "answer_id": 330739, "author": "Andy McCluggage", "author_id": 3362, "author_profile": "https://Stackoverflow.com/users/3362", "pm_score": 5, "selected": false, "text": "SELECT SCOPE_IDENTITY()\n var rowCount = command.ExecuteScalar()\n" }, { "answer_id": 330749, "author": "Samiksha", "author_id": 29515, "author_profile": "https://Stackoverflow.com/users/29515", "pm_score": 2, "selected": false, "text": "SELECT CAST(scope_identity() AS bigint) ---- incase you have a return result as int64\n" }, { "answer_id": 330893, "author": "Kezzer", "author_id": 39693, "author_profile": "https://Stackoverflow.com/users/39693", "pm_score": 2, "selected": false, "text": "SELECT SCOPE_IDENTITY()\n" }, { "answer_id": 331239, "author": "Matt", "author_id": 34550, "author_profile": "https://Stackoverflow.com/users/34550", "pm_score": 3, "selected": false, "text": "@ID AS INT OUTPUT\n\n[Insert Command]\n\nSET @ID = SCOPE_IDENTITY()\n cmd.CommandText = \"stored_procedure\";\n\nSqlParameter pID = new SqlParameter(\"ID\", DBType.Int32, 4);\n\npID.Direction = ParameterDirection.Output;\n\ncmd.ExecuteScalar();\n\nint id = Convert.ToInt32(cmd.Parameters[\"ID\"].Value.ToString());\n" }, { "answer_id": 331413, "author": "Russ", "author_id": 32772, "author_profile": "https://Stackoverflow.com/users/32772", "pm_score": 2, "selected": false, "text": "@\"DECLARE @tmp AS TABLE ( id int )\n INSERT INTO case\n (\n caseID,\n partID,\n serialNumber,\n hardware,\n software,\n firmware\n )\n OUTPUT Inserted.ID into @tmp\n VALUES\n (\n @caseID,\n @partItemID,\n @serialNumber,\n @hardware,\n @software,\n @firmware\n )\n Select ID from @tmp\" )\n" }, { "answer_id": 42002866, "author": "Zymotik", "author_id": 314472, "author_profile": "https://Stackoverflow.com/users/314472", "pm_score": 2, "selected": false, "text": "INSERT INTO YourTable (val1, val2, val3) \nOUTPUT inserted.id \nVALUES (@val1, @val2, @val3)\n internal static Guid InsertNote(Note note)\n {\n Guid id;\n\n using (\n var connection =\n new SqlConnection(ConfigurationManager.ConnectionStrings[\"dbconn\"].ConnectionString))\n {\n connection.Open();\n using (\n var command =\n new SqlCommand(\n \"INSERT INTO Notes ([Title],[Text]) \" +\n \"OUTPUT inserted.id \" +\n $\"VALUES ('{title}','{text}');\", connection))\n {\n command.CommandType = CommandType.Text;\n var reader = command.ExecuteReader();\n reader.Read();\n id = reader.GetGuid(reader.GetOrdinal(\"id\"));\n }\n connection.Close();\n }\n\n return id;\n }\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/330707", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16440/" ]
330,709
<p>I just had some basic php questions to further my understanding as I learn, that I could not find easy answers to</p> <ol> <li><p>I have a php ajax application that generates a table of mysql rows. I would like to know if there is a way to get php to generate neat html, as it seems neat enough as I echo it out, but when "viewing source" the html is a huge jumbled block with no line breaks or anything. Is there a trick to doing this?</p></li> <li><p>What is the best way to limit table output for a mysql database, so only the first 10 records or so are displayed, and there are automatically generated next and previous links to go between records?</p></li> <li><p>When outputting information with php from a mysql database, what is the best way to handle booleans? What is the easiest way to display the words "yes" or "no" or a tick or a cross? edit: I do not mean should I use words or pictures, but rather how to show either in response to a boolean</p></li> </ol>
[ { "answer_id": 330729, "author": "adam", "author_id": 33604, "author_profile": "https://Stackoverflow.com/users/33604", "pm_score": 0, "selected": false, "text": "select * from table limit 10, 10;" }, { "answer_id": 330745, "author": "nickf", "author_id": 9021, "author_profile": "https://Stackoverflow.com/users/9021", "pm_score": 1, "selected": false, "text": "SELECT * FROM mytable LIMIT 20,10 var_dump($myBool) bool(true) echo $myBool ? \"True\" : \"False\"; echo $myBool ? 1 : 0; echo (int)$myBool;" }, { "answer_id": 330829, "author": "e-satis", "author_id": 9951, "author_profile": "https://Stackoverflow.com/users/9951", "pm_score": 3, "selected": true, "text": "my_tab_template.php my_tab_template.php if ($my_bool) \n echo \"True\";\nelse\n echo \"False\";\n echo $my_bool ? \"True\" : \"False\" ;\n" }, { "answer_id": 30098969, "author": "uzi", "author_id": 4874473, "author_profile": "https://Stackoverflow.com/users/4874473", "pm_score": 1, "selected": false, "text": "$amir <table>\n <?php foreach ($amir as $yasir) : ?>\n <tr>\n <?php foreach ($yasir as $shah) : ?>\n <td>\n <?php echo $shah?>\n </td>\n <?php endforeach; ?>\n </tr>\n <?PHP endforeach; ?>\n</table>\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/330709", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1246613/" ]
330,725
<p>I had created the xml document with xml version="1.0".</p> <p>In that document I need to use the greater than symbol <code>&gt;</code> and less than symbol <code>&lt;</code>.</p> <p>How should I include those symbols? It's not working.</p> <p><code>&amp;gt;</code> and <code>&amp;lt;</code> are not working for me.</p> <p>Is there any special encoder for this?</p>
[ { "answer_id": 330734, "author": "tonys", "author_id": 35439, "author_profile": "https://Stackoverflow.com/users/35439", "pm_score": 4, "selected": false, "text": "&gt; &lt;" }, { "answer_id": 330736, "author": "Greg", "author_id": 24181, "author_profile": "https://Stackoverflow.com/users/24181", "pm_score": 7, "selected": false, "text": "< = &lt; > = &gt;" }, { "answer_id": 330746, "author": "Patrick Desjardins", "author_id": 13913, "author_profile": "https://Stackoverflow.com/users/13913", "pm_score": 5, "selected": false, "text": "<![CDATA[\nfunction matchwo(a,b) {\n if (a < b && a < 0) {\n return 1;\n } else {\n return 0;\n }\n}\n]]>\n &lt; &gt;" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/330725", "https://Stackoverflow.com", "https://Stackoverflow.com/users/38172/" ]
330,737
<p>I am using the jQuery Datepicker widget with two input boxes, one for the <strong>"From"</strong> date and the second with the <strong>"To"</strong> date. I am using the <a href="http://jqueryui.com/datepicker/" rel="noreferrer">jQuery Datepicker functional demo</a> as a basis for getting the two input boxes to work with each other, but I need to be able to add these additional restrictions:</p> <ol> <li><p>Date range can be no earlier than 01 December 2008 </p></li> <li><p><strong>"To"</strong> date can be no later than today</p></li> <li><p>Once a <strong>"From"</strong> date is selected, the <strong>"To"</strong> date can only be within a range of 7 days after the <strong>"From"</strong> date</p></li> <li><p>If a <strong>"To"</strong> date is selected first, then the <strong>"From"</strong> date can only be within the range of 7 days before the <strong>"To"</strong> date (with the limit of 01 December being the first selectable date)</p></li> </ol> <p>I can't seem to get all of the above working together.</p> <p>In summary, I would like to be able to select a range of up to 7 days between 01 December and today (I realise I am posting this on 1st December so will only get today for the moment).</p> <p>My code so far</p> <pre><code>$(function () { $('#txtStartDate, #txtEndDate').datepicker( { showOn: "both", beforeShow: customRange, dateFormat: "dd M yy", firstDay: 1, changeFirstDay: false }); }); function customRange(input) { return { minDate: (input.id == "txtStartDate" ? new Date(2008, 12 - 1, 1) : null), minDate: (input.id == "txtEndDate" ? $("#txtStartDate").datepicker("getDate") : null), maxDate: (input.id == "txtStartDate" ? $("#txtEndDate").datepicker("getDate") : null) }; } </code></pre> <p>I'm missing the 7 day range restriction and also preventing a <strong>"To"</strong> date selection before 01 December 2008 or after today. Any help would be much appreciated, Thanks.</p>
[ { "answer_id": 330859, "author": "kgiannakakis", "author_id": 24054, "author_profile": "https://Stackoverflow.com/users/24054", "pm_score": 2, "selected": false, "text": "datepicker( \"option\", settings )" }, { "answer_id": 331026, "author": "Ben Koehler", "author_id": 11996, "author_profile": "https://Stackoverflow.com/users/11996", "pm_score": 2, "selected": false, "text": " function customRange(input) \n{ \n var mDate = (input.id == \"txtStartDate\" ? new Date(2008, 12 - 1, 1) : $(\"#txtStartDate\").datepicker(\"getDate\"));\n return {\n minDate: mDate, \n maxDate: (input.id == \"txtEndDate\" ? $(\"#txtStartDate\").datepicker(\"getDate\").getDate() + 5 : null)\n }; \n}\n" }, { "answer_id": 332258, "author": "Ben Koehler", "author_id": 11996, "author_profile": "https://Stackoverflow.com/users/11996", "pm_score": 4, "selected": false, "text": "function customRange(input) \n{ \n var min = new Date(2008, 12 - 1, 1);\n var dateMin = min;\n var dateMax = null;\n\n if (input.id == \"txtStartDate\" && $(\"#txtEndDate\").datepicker(\"getDate\") != null)\n {\n dateMax = $(\"#txtEndDate\").datepicker(\"getDate\");\n dateMin = $(\"#txtEndDate\").datepicker(\"getDate\");\n dateMin.setDate(dateMin.getDate() - 7);\n if (dateMin < min)\n {\n dateMin = min;\n } \n }\n else if (input.id == \"txtEndDate\")\n {\n dateMax = new Date();\n if ($(\"#txtStartDate\").datepicker(\"getDate\") != null)\n {\n dateMin = $(\"#txtStartDate\").datepicker(\"getDate\");\n dateMax = $(\"#txtStartDate\").datepicker(\"getDate\");\n dateMax.setDate(dateMax.getDate() + 7); \n }\n }\n return {\n minDate: dateMin, \n maxDate: dateMax\n }; \n\n}\n" }, { "answer_id": 333585, "author": "Russ Cam", "author_id": 1831, "author_profile": "https://Stackoverflow.com/users/1831", "pm_score": 7, "selected": true, "text": "$(function () \n{ \n $('#txtStartDate, #txtEndDate').datepicker({\n showOn: \"both\",\n beforeShow: customRange,\n dateFormat: \"dd M yy\",\n firstDay: 1, \n changeFirstDay: false\n });\n\n});\n\nfunction customRange(input) { \n var min = new Date(2008, 11 - 1, 1), //Set this to your absolute minimum date\n dateMin = min,\n dateMax = null,\n dayRange = 6; // Set this to the range of days you want to restrict to\n\n if (input.id === \"txtStartDate\") {\n if ($(\"#txtEndDate\").datepicker(\"getDate\") != null) {\n dateMax = $(\"#txtEndDate\").datepicker(\"getDate\");\n dateMin = $(\"#txtEndDate\").datepicker(\"getDate\");\n dateMin.setDate(dateMin.getDate() - dayRange);\n if (dateMin < min) {\n dateMin = min;\n }\n }\n else {\n dateMax = new Date; //Set this to your absolute maximum date\n } \n }\n else if (input.id === \"txtEndDate\") {\n dateMax = new Date; //Set this to your absolute maximum date\n if ($(\"#txtStartDate\").datepicker(\"getDate\") != null) {\n dateMin = $(\"#txtStartDate\").datepicker(\"getDate\");\n var rangeMax = new Date(dateMin.getFullYear(), dateMin.getMonth(),dateMin.getDate() + dayRange);\n\n if(rangeMax < dateMax) {\n dateMax = rangeMax; \n }\n }\n }\n return {\n minDate: dateMin, \n maxDate: dateMax\n }; \n}\n" }, { "answer_id": 2271675, "author": "gaby", "author_id": 274211, "author_profile": "https://Stackoverflow.com/users/274211", "pm_score": 2, "selected": false, "text": "function customRange(input)\n{\n var min = new Date();\n return {\n minDate: ((input.id == \"txtStartDate\") ? min : (input.id == \"txtEndDate\" ? $(\"#txtStartDate\").datepicker(\"getDate\") : null)),\n maxDate: (input.id == \"txtStartDate\" ? $(\"#txtEndDate\").datepicker(\"getDate\") : null)\n };\n}\n" }, { "answer_id": 3015844, "author": "Robin Duckett", "author_id": 280515, "author_profile": "https://Stackoverflow.com/users/280515", "pm_score": 4, "selected": false, "text": "jQuery(function() {\n jQuery('#calendardatetime_required_to, #calendardatetime_required_from').datepicker('option', {\n beforeShow: customRange\n });\n});\n\nfunction customRange(input) {\n if (input.id == 'calendardatetime_required_to') {\n return {\n minDate: jQuery('#calendardatetime_required_from').datepicker(\"getDate\")\n };\n } else if (input.id == 'calendardatetime_required_from') {\n return {\n maxDate: jQuery('#calendardatetime_required_to').datepicker(\"getDate\")\n };\n }\n}\n" }, { "answer_id": 3843482, "author": "David Bigelow", "author_id": 464299, "author_profile": "https://Stackoverflow.com/users/464299", "pm_score": 2, "selected": false, "text": "\n$(\"#startdate\").datepicker({\n minDate: '+5', \n maxDate: '+3M',\n changeMonth: true,\n showAnim: 'blind',\n onSelect: function(dateText, inst){ \n\n // Capture the Date from User Selection\n var oldDate = new Date(dateText);\n var newDate = new Date(dateText);\n\n // Compute the Future Limiting Date\n newDate.setDate(newDate.getDate()+5);\n\n\n // Set the Widget Properties\n $(\"#enddate\").datepicker('option', 'minDate', oldDate);\n $(\"#enddate\").datepicker('option', 'maxDate', newDate);\n\n }\n });\n\n $(\"#enddate\").datepicker({\n minDate: '+5',\n maxDate: '+3M',\n changeMonth: true,\n showAnim: 'blind', \n onSelect: function(dateText, inst){ \n\n // Capture the Date from User Selection\n var endDate = new Date(dateText);\n var startDate = new Date(dateText);\n\n // Compute the Future Limiting Date\n startDate.setDate(startDate.getDate()-5);\n\n // Set the Widget Properties\n $(\"#startdate\").datepicker('option', 'minDate', startDate);\n $(\"#startdate\").datepicker('option', 'maxDate', endDate);\n\n }\n\n });\n" }, { "answer_id": 9680704, "author": "escist", "author_id": 1242061, "author_profile": "https://Stackoverflow.com/users/1242061", "pm_score": 0, "selected": false, "text": "$(document).ready(function ()\n{ \n var dates = $('#StartDate, #EndDate').datepicker({\n minDate: new Date(2008, 11, 1), \n maxDate: \"+0D\",\n dateFormat: \"dd M yy\",\n changeMonth: true,\n changeYear: true,\n onSelect: function (selectedDate)\n {\n var option = this.id == \"StartDate\" ? \"minDate\" : \"maxDate\",\n instance = $(this).data(\"datepicker\"),\n date = $.datepicker.parseDate(\n instance.settings.dateFormat ||\n $.datepicker._defaults.dateFormat,\n selectedDate, instance.settings);\n var edate;\n var otherOption;\n var d;\n if (option == \"minDate\")\n {\n otherOption = \"maxDate\";\n d = date.getDate() + 7;\n }\n else if (option == \"maxDate\")\n {\n otherOption = \"minDate\";\n d = date.getDate() - 7;\n }\n\n var m = date.getMonth();\n var y = date.getFullYear();\n edate = new Date(y, m, d);\n\n dates.not(this).datepicker(\"option\", option, date);\n dates.not(this).datepicker(\"option\", otherOption, edate);\n }\n });\n});\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/330737", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1831/" ]
330,750
<p>I wish to display a list of letters from a through z on a form. Each letter needs to be clickable with that value being passed as a click argument. Aside from creating 26 letters and using the click event of each letter does anyone know of a quick way to do this? I know how to load dynamic controls etc and how to do it that way. Just wondering if anyone knew of a clever way to do this?</p> <p>Cheers</p>
[ { "answer_id": 330811, "author": "Stefan", "author_id": 19307, "author_profile": "https://Stackoverflow.com/users/19307", "pm_score": 1, "selected": false, "text": "Public Class Form1\n\n Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load\n Dim ButtonSize As New Size(20, 20)\n Dim ButtonLocation As New Point(10, 20)\n\n For p As Integer = Asc(\"A\") To Asc(\"Z\")\n Dim newButton As New Button \n If ButtonLocation.X + ButtonSize.Width > Me.Width Then\n ButtonLocation.X = 10\n ButtonLocation.Y += ButtonSize.Height\n End If\n newButton.Size = ButtonSize\n newButton.Location = ButtonLocation\n newButton.Text = Chr(p)\n ButtonLocation.X += newButton.Width + 5\n AddHandler newButton.Click, AddressOf ButtonClicked\n Me.Controls.Add(newButton)\n Next\n\n End Sub\n\n Sub ButtonClicked(ByVal sender As Object, ByVal e As System.EventArgs)\n MsgBox(CType(sender, Button).Text)\n End Sub\nEnd Class\n" }, { "answer_id": 330856, "author": "Tomalak", "author_id": 18771, "author_profile": "https://Stackoverflow.com/users/18771", "pm_score": 2, "selected": true, "text": "private void button1_Click(object sender, EventArgs e)\n{\n flowLayoutPanel1.FlowDirection = FlowDirection.LeftToRight;\n flowLayoutPanel1.AutoSize = true;\n flowLayoutPanel1.WrapContents = false; //or true, whichever you like\n flowLayoutPanel1.Controls.Clear();\n\n for (char c = 'A'; c <= 'Z'; c++)\n {\n Label letter = new Label();\n letter.Text = c.ToString();\n letter.AutoSize = true;\n letter.Click += new EventHandler(letter_Click);\n flowLayoutPanel1.Controls.Add(letter);\n\n }\n}\n\nprivate void letter_Click(object sender, EventArgs e)\n{\n MessageBox.Show(\"You clicked on \" + ((Label)sender).Text);\n}\n" }, { "answer_id": 330950, "author": "Binary Worrier", "author_id": 18797, "author_profile": "https://Stackoverflow.com/users/18797", "pm_score": 0, "selected": false, "text": "Public Class Form1\n\n Const LETTERS As String = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"\n Private letterRects(25) As System.Drawing.RectangleF\n Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click\n Dim index As Integer = -1\n Dim mouseP As Point = Me.PointToClient(MousePosition)\n For i As Integer = 0 To 25\n If letterRects(i).Contains(mouseP.X, mouseP.Y) Then\n index = i\n Exit For\n End If\n Next\n If index >= 0 Then\n MessageBox.Show(\"Letter = \" + LETTERS(index).ToString())\n End If\n End Sub\n\n Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint\n ' Set up string.\n Dim stringFont As New Font(\"Times New Roman\", 16.0F)\n\n ' Set character ranges \n Dim characterRanges(26) As CharacterRange\n For i As Integer = 0 To 25\n characterRanges(i) = New CharacterRange(i, 1)\n Next\n\n ' Create rectangle for layout, measurements below are not exact, these are \"magic numbers\"\n Dim x As Single = 50.0F\n Dim y As Single = 50.0F\n Dim width As Single = 400.0F \n Dim height As Single = 40.0F\n Dim layoutRect As New RectangleF(x, y, width, height)\n\n ' Set string format.\n Dim stringFormat As New StringFormat\n stringFormat.FormatFlags = StringFormatFlags.FitBlackBox\n stringFormat.SetMeasurableCharacterRanges(characterRanges)\n\n ' Draw string to screen.\n e.Graphics.DrawString(letters, stringFont, Brushes.Black, _\n x, y, stringFormat)\n Dim stringRegions() As [Region]\n ' Measure two ranges in string.\n stringRegions = e.Graphics.MeasureCharacterRanges(letters, _\n stringFont, layoutRect, stringFormat)\n For i As Integer = 0 To 25\n letterRects(i) = stringRegions(i).GetBounds(e.Graphics)\n Next\n End Sub\nEnd Class\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/330750", "https://Stackoverflow.com", "https://Stackoverflow.com/users/35441/" ]
330,752
<p>I have a COM <code>.dll</code> registered successfully with <code>regsvr32</code> but somehow <code>CoCreateInstance()</code> fails to create one of its interfaces. Is there a freeware tool which can determine the reason for the failure?</p>
[ { "answer_id": 357156, "author": "Jason S", "author_id": 44330, "author_profile": "https://Stackoverflow.com/users/44330", "pm_score": 0, "selected": false, "text": "COM_INTERFACE_ENTRY(I____) BEGIN_COM_MAP(CFileHelper)\n COM_INTERFACE_ENTRY(IFileHelper)\n COM_INTERFACE_ENTRY(IDispatch)\n COM_INTERFACE_ENTRY(IStream)\n COM_INTERFACE_ENTRY(ISupportErrorInfo)\nEND_COM_MAP()\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/330752", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
330,757
<p>I tried to write a <code>TransformMesh</code> function. The function accepts a <code>Mesh</code> object and a <code>Matrix</code> object. The idea is to transform the mesh using the matrix. To do this, I locked the vertex buffer, and called Vector3::TransformCoordinate on each vertex. It did <em>not</em> produce expected results. The resulting mesh was unrecognizable.</p> <p>What am I doing wrong?</p> <pre><code>// C++/CLI code. My apologies. int n = verts-&gt;Length; for(int i = 0; i &lt; n; i++){ verts[i].Position = DX::Vector3::TransformCoordinate(verts[i].Position, matrix); } </code></pre>
[ { "answer_id": 784888, "author": "avp", "author_id": 20514, "author_profile": "https://Stackoverflow.com/users/20514", "pm_score": 2, "selected": true, "text": " // Clear the backbuffer to a Blue color.\n device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Blue, \n 1.0f, 0);\n\n // Begin the scene.\n device.BeginScene();\n\n device.Lights[0].Enabled = true;\n\n // Setup the world, view, and projection matrices.\n Matrix m = new Matrix();\n\n if( destination.Y != 0 )\n y += DXUtil.Timer(DirectXTimer.GetElapsedTime) * (destination.Y \n * 25);\n\n if( destination.X != 0 )\n x += DXUtil.Timer(DirectXTimer.GetElapsedTime) * (destination.X \n * 25);\n\n m = Matrix.RotationY(y);\n m *= Matrix.RotationX(x);\n\n device.Transform.World = m;\n device.Transform.View = Matrix.LookAtLH(\n new Vector3( 0.0f, 3.0f,-5.0f ),\n new Vector3( 0.0f, 0.0f, 0.0f ),\n new Vector3( 0.0f, 1.0f, 0.0f ) ); \n device.Transform.Projection = Matrix.PerspectiveFovLH(\n (float)Math.PI / 4, 1.0f, 1.0f, 100.0f );\n\n // Render the teapot.\n teapot.DrawSubset(0);\n\n // End the scene.\n device.EndScene();\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/330757", "https://Stackoverflow.com", "https://Stackoverflow.com/users/45603/" ]
330,793
<p>I want to initialize a struct element, split in declaration and initialization. This is what I have:</p> <pre><code>typedef struct MY_TYPE { bool flag; short int value; double stuff; } MY_TYPE; void function(void) { MY_TYPE a; ... a = { true, 15, 0.123 } } </code></pre> <p>Is this the way to declare and initialize a local variable of <code>MY_TYPE</code> in accordance with C programming language standards (C89, C90, C99, C11, etc.)? Or is there anything better or at least working?</p> <p><strong>Update</strong> I ended up having a static initialization element where I set every subelement according to my needs.</p>
[ { "answer_id": 330802, "author": "robert", "author_id": 32805, "author_profile": "https://Stackoverflow.com/users/32805", "pm_score": 2, "selected": false, "text": "void function(void) {\n MY_TYPE a;\n a.flag = true;\n a.value = 15;\n a.stuff = 0.123;\n}\n" }, { "answer_id": 330808, "author": "Kieveli", "author_id": 15852, "author_profile": "https://Stackoverflow.com/users/15852", "pm_score": 5, "selected": false, "text": "MY_TYPE a = { true, 15, 0.123 };\n" }, { "answer_id": 330824, "author": "qrdl", "author_id": 28494, "author_profile": "https://Stackoverflow.com/users/28494", "pm_score": 6, "selected": false, "text": "a = (MYTYPE){ true, 15, 0.123 };" }, { "answer_id": 330828, "author": "CesarB", "author_id": 28258, "author_profile": "https://Stackoverflow.com/users/28258", "pm_score": 8, "selected": false, "text": "MY_TYPE a;\n\na = (MY_TYPE) { .flag = true, .value = 123, .stuff = 0.456 };\n...\na = (MY_TYPE) { .value = 234, .stuff = 1.234, .flag = false };\n a = (MY_TYPE) { true, 123, 0.456 };\n...\na = (MY_TYPE) { false, 234, 1.234 };\n" }, { "answer_id": 330867, "author": "philant", "author_id": 18804, "author_profile": "https://Stackoverflow.com/users/18804", "pm_score": 11, "selected": true, "text": "MY_TYPE a = { .flag = true, .value = 123, .stuff = 0.456 };\n" }, { "answer_id": 17006240, "author": "Ron Nuni", "author_id": 2304136, "author_profile": "https://Stackoverflow.com/users/2304136", "pm_score": 7, "selected": false, "text": "typedef struct Item {\n int a;\n float b;\n char* name;\n} Item;\n\nint main(void) {\n Item item = { 5, 2.2, \"George\" };\n return 0;\n}\n" }, { "answer_id": 18610323, "author": "r_goyal", "author_id": 2720591, "author_profile": "https://Stackoverflow.com/users/2720591", "pm_score": 4, "selected": false, "text": "typedef struct Item {\n int a;\n float b;\n char* name;\n} Item;\n\nint main(void) {\n Item item = {5, 2.2, \"George\"};\n return 0;\n}\n variable.members variable.members 0 '\\0' char 0 char NULL" }, { "answer_id": 23186781, "author": "eddyq", "author_id": 215779, "author_profile": "https://Stackoverflow.com/users/215779", "pm_score": 2, "selected": false, "text": "MY_TYPE a = { true,15,0.123 };" }, { "answer_id": 34080308, "author": "4t8dds", "author_id": 1109065, "author_profile": "https://Stackoverflow.com/users/1109065", "pm_score": 2, "selected": false, "text": "typedef struct test {\n int num;\n char* str;\n} test;\n test tt = {\n num: 42,\n str: \"nice\"\n};\n" }, { "answer_id": 37193443, "author": "Alan Corey", "author_id": 4548383, "author_profile": "https://Stackoverflow.com/users/4548383", "pm_score": 3, "selected": false, "text": "// in a header:\ntypedef unsigned char uchar;\n\nstruct fields {\n uchar num;\n uchar lbl[35];\n};\n\n// in an actual c file (I have 2 in this case)\nstruct fields labels[] = {\n {0, \"Package\"},\n {1, \"Version\"},\n {2, \"Apport\"},\n {3, \"Architecture\"},\n {4, \"Bugs\"},\n {5, \"Description-md5\"},\n {6, \"Essential\"},\n {7, \"Filename\"},\n {8, \"Ghc-Package\"},\n {9, \"Gstreamer-Version\"},\n {10, \"Homepage\"},\n {11, \"Installed-Size\"},\n {12, \"MD5sum\"},\n {13, \"Maintainer\"},\n {14, \"Modaliases\"},\n {15, \"Multi-Arch\"},\n {16, \"Npp-Description\"},\n {17, \"Npp-File\"},\n {18, \"Npp-Name\"},\n {19, \"Origin\"}\n};\n" }, { "answer_id": 37701574, "author": "PF4Public", "author_id": 427898, "author_profile": "https://Stackoverflow.com/users/427898", "pm_score": 5, "selected": false, "text": "MY_TYPE a = { .stuff = 0.456, .flag = true, .value = 123 };\n paragraph 7 6.7.8 Initialization paragraph 9 Initializing unions and structs 6.7.9 Initialization paragraph 9 6.7.9 Initialization paragraph 9" }, { "answer_id": 46082201, "author": "Ajay", "author_id": 8570545, "author_profile": "https://Stackoverflow.com/users/8570545", "pm_score": 1, "selected": false, "text": "typedef struct book\n{\n char title[10];\n char author[10];\n float price;\n} book;\n\nint main() {\n book b1={\"DS\", \"Ajay\", 250.0};\n\n printf(\"%s \\t %s \\t %f\", b1.title, b1.author, b1.price);\n\n return 0;\n}\n" }, { "answer_id": 51809604, "author": "Hartmut Schorrig", "author_id": 6771814, "author_profile": "https://Stackoverflow.com/users/6771814", "pm_score": 0, "selected": false, "text": "{...} = {0}; typedef MyStruct_t{ int x, int a, int b; } MyStruct;\ndefine INIT_MyStruct(A,B) { 0, A, B} void init_MyStruct(MyStruct* thiz, int a, int b) {\n thiz->a = a; thiz->b = b; }\n thiz this MyStruct data = {0}; //all is zero!\ninit_MyStruct(&data, 3, 456);\n" }, { "answer_id": 53582950, "author": "div0man", "author_id": 10499346, "author_profile": "https://Stackoverflow.com/users/10499346", "pm_score": -1, "selected": false, "text": "typedef struct {\n char *str;\n size_t len;\n jsmntok_t *tok;\n int tsz;\n} jsmn_ts;\n\n#define jsmn_ts_default (jsmn_ts){NULL, 0, NULL, 0}\n jsmn_ts mydata = jsmn_ts_default; /* initialization of a single struct */\n\njsmn_ts myarray[10] = {jsmn_ts_default, jsmn_ts_default}; /* initialization of\n first 2 structs in the array */\n" }, { "answer_id": 63392261, "author": "dev", "author_id": 2456048, "author_profile": "https://Stackoverflow.com/users/2456048", "pm_score": 3, "selected": false, "text": "MY_TYPE a = { true, 1, 0.1 };\n\nMY_TYPE a = { .stuff = 0.1, .flag = true, .value = 1 }; //designated initializer, not available in c++\n\nMY_TYPE a;\na = (MY_TYPE) { true, 1, 0.1 };\n\nMY_TYPE m (true, 1, 0.1); //works in C++, not available in C\n #include <stdio.h>\n\nstruct MY_TYPE\n{\n int a;\n int b;\n}m = {5,6};\n\nint main()\n{\n printf(\"%d %d\\n\",m.a,m.b); \n return 0;\n}\n" }, { "answer_id": 65546721, "author": "Federico Baù", "author_id": 13903942, "author_profile": "https://Stackoverflow.com/users/13903942", "pm_score": 4, "selected": false, "text": "struct point \n{\n double x;\n double y;\n double z;\n}\n\np = {1.2, 1.3}; \n struct union array int a[6] = { 0, 0, 15, 0, 29, 0 };\n int a[6] = {[4] = 29, [2] = 15 }; // or\nint a[6] = {[4]29 , [2]15 }; // or\nint widths[] = { [0 ... 9] = 1, [10 ... 99] = 2, [100] = 3 };\n struct point { int x, y; };\n struct point p = { .y = 2, .x = 3 }; or\nstruct point p = { y: 2, x: 3 };\n int a[6] = { 0, v1, v2, 0, v4, 0 };\n int a[6] = { [1] = v1, v2, [4] = v4 };\n int whitespace[256] = { [' '] = 1, ['\\t'] = 1, ['\\h'] = 1,\n ['\\f'] = 1, ['\\n'] = 1, ['\\r'] = 1 };\n struct point ptarray[10] = { [2].y = yv2, [2].x = xv2, [0].x = xv0 };\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/330793", "https://Stackoverflow.com", "https://Stackoverflow.com/users/834/" ]
330,832
<p>How do I call the correct overloaded function given a reference to an object based on the actual type of the object. For example...</p> <pre><code>class Test { object o1 = new object(); object o2 = new string("ABCD"); MyToString(o1); MyToString(o2);//I want this to call the second overloaded function void MyToString(object o) { Console.WriteLine("MyToString(object) called."); } void MyToString(string str) { Console.WriteLine("MyToString(string) called."); } } </code></pre> <p>what I mean is there a better option than the following?</p> <pre><code>if(typeof(o) == typeof(string)) { MyToString((string)o); } else { MyToString(o); } </code></pre> <p>May be this can be done using reflection?</p>
[ { "answer_id": 330833, "author": "Sandeep Datta", "author_id": 39648, "author_profile": "https://Stackoverflow.com/users/39648", "pm_score": 3, "selected": true, "text": "var methInfo = typeof(Test).GetMethod(\"MyToString\", new Type[] {o.GetType()});\nmethInfo.Invoke(this, new object[] {o});\n" }, { "answer_id": 340538, "author": "mbillard", "author_id": 810, "author_profile": "https://Stackoverflow.com/users/810", "pm_score": 1, "selected": false, "text": "MyToString(o is string ? (string)o : o);\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/330832", "https://Stackoverflow.com", "https://Stackoverflow.com/users/39648/" ]
330,836
<p>How do I uninstall a Windows Service when there is no executable for it left on the system? I can not run <code>installutil -u</code> since there is not executable left on the system. I can still see an entry for the service in the Services console. </p> <p>The reason for this state is probably because of a problem in the msi package that does not remove the service correctly, but how do I fix it once the service is in this state?</p>
[ { "answer_id": 330852, "author": "Fredou", "author_id": 40868, "author_profile": "https://Stackoverflow.com/users/40868", "pm_score": 4, "selected": false, "text": " Deleting services in Windows Server 2003\n\n We can use sc.exe in the Windows Server 2003 to control services, create services and delete services. Since some people thought they must directly modify the registry to delete a service, I would like to share how to use sc.exe to delete a service without directly modifying the registry so that decreased the possibility for system failures.\n\n To delete a service: \n\n Click “start“ - “run“, and then enter “cmd“ to open Microsoft Command Console.\n\n Enter command:\n\n sc servername delete servicename\n\n For instance, sc \\\\dc delete myservice\n\n (Note: In this example, dc is my Domain Controller Server name, which is not the local machine, myservice is the name of the service I want to delete on the DC server.)\n\n Below is the official help of all sc functions:\n\n DESCRIPTION:\n SC is a command line program used for communicating with the\n NT Service Controller and services. \n USAGE:\n sc\n" }, { "answer_id": 330879, "author": "Treb", "author_id": 22114, "author_profile": "https://Stackoverflow.com/users/22114", "pm_score": 9, "selected": true, "text": "sc.exe delete <service name>\n <service name>" }, { "answer_id": 38769219, "author": "Nima Soroush", "author_id": 1952158, "author_profile": "https://Stackoverflow.com/users/1952158", "pm_score": 4, "selected": false, "text": "foo $foo= Get-WmiObject -Class Win32_Service -Filter \"Name='foo'\"\n$foo.delete()\n" }, { "answer_id": 51293772, "author": "JoeRod", "author_id": 2497681, "author_profile": "https://Stackoverflow.com/users/2497681", "pm_score": 2, "selected": false, "text": "Remove-Service -Name \"TestService\"\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/330836", "https://Stackoverflow.com", "https://Stackoverflow.com/users/966/" ]
330,853
<p>I have the following requirements:</p> <p>I need a api that works on CE (x86) + .NET Compact Framework to play videos (Similar to CorePlayer API... Just free)?</p> <p>Is their anything else available or must I use CorePlayer?</p>
[ { "answer_id": 330915, "author": "atzz", "author_id": 23252, "author_profile": "https://Stackoverflow.com/users/23252", "pm_score": 0, "selected": false, "text": "IGraphBuilder" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/330853", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5147/" ]
330,878
<p>Consider the following code and its output:</p> <h3>Code</h3> <pre><code>#!/usr/bin/perl -w use strict; use Data::Dumper; my $HOURS_PER_DAY = 24.0 * 1.0; my $BSA = 1.7 * 1.0; my $MCG_PER_MG = 1000.0 * 1.0; my $HOURS_DURATION = 20.0 * $HOURS_PER_DAY; my $dummy = $HOURS_PER_DAY * $BSA * $MCG_PER_MG * $HOURS_DURATION; print Dumper($HOURS_PER_DAY); print Dumper( $BSA); print Dumper( $MCG_PER_MG); print Dumper( $HOURS_DURATION ); </code></pre> <h3>Output</h3> <pre><code>$VAR1 = 24; $VAR1 = '1.7'; $VAR1 = 1000; $VAR1 = 480; </code></pre> <hr> <p>As you can see, the second variable is treated as strings, while the first and the forth ones are treated as numbers. Anybody has any idea what is the underlying logic?</p> <p><strong>Edit</strong> arithmetic calculations that were added do not completely solve the problem (see the $BSA variable).</p> <hr> <pre><code>$ perl -v This is perl, v5.10.0 built for cygwin-thread-multi-64int (with 6 registered patches, see perl -V for more detail) Copyright 1987-2007, Larry Wall </code></pre>
[ { "answer_id": 330885, "author": "Robert Gamble", "author_id": 25222, "author_profile": "https://Stackoverflow.com/users/25222", "pm_score": 3, "selected": false, "text": "...\nelsif ($val =~ /^(?:0|-?[1-9]\\d{0,8})\\z/) { # safe decimal number\n $out .= $val;\n}\nelse { # string\n...\n" }, { "answer_id": 331263, "author": "converter42", "author_id": 28974, "author_profile": "https://Stackoverflow.com/users/28974", "pm_score": 4, "selected": true, "text": "#!/usr/bin/perl\n\nuse warnings;\nuse strict;\nuse Devel::Peek;\n\nmy $HOURS_PER_DAY = 24.0 * 1.0;\nmy $BSA = 1.7 * 1.0;\nmy $MCG_PER_MG = 1000.0 * 1.0;\nmy $HOURS_DURATION = 20.0 * $HOURS_PER_DAY;\nmy $dummy = $HOURS_PER_DAY * $BSA * $MCG_PER_MG * $HOURS_DURATION;\n\nDump($HOURS_PER_DAY);\nDump($BSA);\nDump($MCG_PER_MG);\nDump($HOURS_DURATION);\n\n__END__\nSV = PVNV(0xd71ff0) at 0xd87f90\n REFCNT = 1\n FLAGS = (PADBUSY,PADMY,IOK,NOK,pIOK,pNOK)\n IV = 24\n NV = 24\n PV = 0\nSV = PVNV(0xd71fc8) at 0xd87f60\n REFCNT = 1\n FLAGS = (PADBUSY,PADMY,NOK,pIOK,pNOK)\n IV = 1\n NV = 1.7\n PV = 0\nSV = PVNV(0xd72040) at 0xd87f40\n REFCNT = 1\n FLAGS = (PADBUSY,PADMY,IOK,NOK,pIOK,pNOK)\n IV = 1000\n NV = 1000\n PV = 0\nSV = IV(0xd8b408) at 0xd87f30\n REFCNT = 1\n FLAGS = (PADBUSY,PADMY,IOK,pIOK)\n IV = 480\n# compare the above output to output without the assignment to $dummy:\nSV = IV(0x7b0eb8) at 0x7adf90\n REFCNT = 1\n FLAGS = (PADBUSY,PADMY,IOK,pIOK)\n IV = 24\nSV = NV(0x7c7c90) at 0x7adf60\n REFCNT = 1\n FLAGS = (PADBUSY,PADMY,NOK,pNOK)\n NV = 1.7\nSV = IV(0x7b13d8) at 0x7adf40\n REFCNT = 1\n FLAGS = (PADBUSY,PADMY,IOK,pIOK)\n IV = 1000\nSV = IV(0x7b1408) at 0x7adf30\n REFCNT = 1\n FLAGS = (PADBUSY,PADMY,IOK,pIOK)\n IV = 480\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/330878", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17523/" ]
330,900
<p>If I want to split a list of words separated by a delimiter character, I can use</p> <pre><code>&gt;&gt;&gt; 'abc,foo,bar'.split(',') ['abc', 'foo', 'bar'] </code></pre> <p>But how to easily and quickly do the same thing if I also want to handle quoted-strings which can contain the delimiter character ?</p> <pre><code>In: 'abc,"a string, with a comma","another, one"' Out: ['abc', 'a string, with a comma', 'another, one'] </code></pre> <p>Related question: <a href="https://stackoverflow.com/questions/118096/how-can-i-parse-a-comma-delimited-string-into-a-list-caveat">How can i parse a comma delimited string into a list (caveat)?</a></p>
[ { "answer_id": 330924, "author": "Tomalak", "author_id": 18771, "author_profile": "https://Stackoverflow.com/users/18771", "pm_score": 6, "selected": true, "text": "import csv\n\ninput = ['abc,\"a string, with a comma\",\"another, one\"']\nparser = csv.reader(input)\n\nfor fields in parser:\n for i,f in enumerate(fields):\n print i,f # in Python 3 and up, print is a function; use: print(i,f)\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/330900", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42127/" ]
330,918
<p>Does hibernate HQL queries support using select min, max, count and other sql functions?</p> <p>like:</p> <p><code>select min(p.age) from person p</code></p> <p>Thanks</p>
[ { "answer_id": 330930, "author": "Galwegian", "author_id": 3201, "author_profile": "https://Stackoverflow.com/users/3201", "pm_score": 5, "selected": true, "text": "min() max() count()" }, { "answer_id": 3155549, "author": "Saher Ahwal", "author_id": 367319, "author_profile": "https://Stackoverflow.com/users/367319", "pm_score": 3, "selected": false, "text": "public long getNextId(){\nlong appId; \ntry{\n Session session = HibernateUtil.getAdmSessionFactory().getCurrentSession();\n Transaction t = session.beginTransaction();\n String sequel = \"Select max(JAdmAppExemptionId) from JAdmAppExemption\";\n Query q = session.createQuery(sequel);\n List currentSeq = q.list();\n if(currentSeq == null){\n return appId;\n }else{\n appId = (Long)currentSeq.get(0);\n return appId+1;\n }\n\n }catch(Exception exc){\n System.out.print(\"Unable to get latestID\");\n exc.printStackTrace();\n\n }\n return 0;\n\n }\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/330918", "https://Stackoverflow.com", "https://Stackoverflow.com/users/37650/" ]
330,922
<p>I have seen <a href="https://stackoverflow.com/questions/295579/fastest-way-to-determine-if-an-integers-square-root-is-an-integer">this topic here</a> about John Carmack's magical way to calculate square root, which refers to this article: <a href="http://www.codemaestro.com/reviews/9" rel="nofollow noreferrer">http://www.codemaestro.com/reviews/9</a>. This surprised me a lot, I just didn't ever realized that calculating sqrt could be so faster. </p> <p>I was just wondering what other examples of "magic" exist out there that computer games use to run faster.</p> <p><strong>UPDATE</strong>: John Carmack is not the author of the magic code. <a href="http://www.beyond3d.com/content/articles/8/" rel="nofollow noreferrer">This article</a> tells more. Thanks @moocha.</p>
[ { "answer_id": 331037, "author": "VonC", "author_id": 6309, "author_profile": "https://Stackoverflow.com/users/6309", "pm_score": 3, "selected": false, "text": "public class Example {\n public static void main(String[] args) {\n System.out.println(\n MCMLXXVII + XXIV\n );\n }\n}\n class Transform extends TreeTranslator Transform public class Transform extends TreeTranslator {\n @Override\n public void visitIdent(JCIdent tree) {\n String name = tree.getName().toString();\n if (isRoman(name)) {\n result = make.Literal(numberize(name));\n result.pos = tree.pos;\n } else {\n super.visitIdent(tree);\n }\n }\n}\n" }, { "answer_id": 334278, "author": "Federico A. Ramponi", "author_id": 18770, "author_profile": "https://Stackoverflow.com/users/18770", "pm_score": 2, "selected": false, "text": "import math\n\ndef dayOfWeek(dayOfMonth, month, year):\n yearOfCentury = year%100\n century = year // 100\n\n h = int(dayOfMonth + math.floor(26.0*(month + 1)/10) + yearOfCentury \\\n + math.floor(float(yearOfCentury)/4) + math.floor(float(century)/4) \\\n + 5*century) % 7\n return ['Saturday', 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'][h]\n\ndef easter(year):\n a = year%19\n b = year%4\n c = year%7\n k = int(math.floor(float(year)/100))\n p = int(math.floor((13 + 8.0*k)/25))\n q = int(math.floor(float(k)/4))\n M = (15 - p + k - q)%30\n N = (4 + k - q)%7\n d = (19*a + M)%30\n e = (2*b + 4*c + 6*d + N)%7\n day1 = 22 + d + e \n if day1 <= 31: return \"March %d\"%day1\n day2 = d + e - 9\n if day2 == 26: return \"April 19\"\n if day2 == 25 and (11*M + 11)%30 < 19: return \"April 18\"\n return \"April %d\"%day2 \n\nprint dayOfWeek(2, 12, 2008) # 'Tuesday'\nprint easter(2008) # 'March 23'\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/330922", "https://Stackoverflow.com", "https://Stackoverflow.com/users/33857/" ]
330,927
<p>I'm learning DI, and made my first project recently.</p> <p>In this project I've implement the repository pattern. I have the interfaces and the concrete implementations. I wonder if is possible to build the implementation of my interfaces as "plugins", dlls that my program will load dynamically.</p> <p>So the program could be improved over time without having to rebuild it, you just place the dll on the "plugins" folder, change settings and voilá! </p> <p>Is this possible? Can Ninject help with this?</p>
[ { "answer_id": 330932, "author": "Grzenio", "author_id": 5363, "author_profile": "https://Stackoverflow.com/users/5363", "pm_score": 2, "selected": false, "text": "ass = Assembly.Load(name);\n ObjType = ass.GetType(typename);\nIPlugin plugin = (IPlugin)Activator.CreateInstance(ObjType);\n" }, { "answer_id": 330934, "author": "Patrick Desjardins", "author_id": 13913, "author_profile": "https://Stackoverflow.com/users/13913", "pm_score": -1, "selected": false, "text": "BaseAuto auto = kernel.Get<BaseAuto>();//Get from the NInjector kernel your object. You get your concrete objet and the object \"auto\" will be filled up (interface inside him) with the kernel.\n\n//Somewhere else:\n\npublic class BaseModule : StandardModule\n{\n public override void Load(){\n Bind<BaseAuto>().ToSelf();\n Bind<IEngine>().To<FourCylinder>();//Bind the interface\n } \n }\n" }, { "answer_id": 488023, "author": "Ruben Bartelink", "author_id": 11635, "author_profile": "https://Stackoverflow.com/users/11635", "pm_score": 0, "selected": false, "text": "IKernel k = ...\nvar o = Activator.CreateInstance(...);\nk.Inject( o );\n" }, { "answer_id": 1733373, "author": "Sean Chambers", "author_id": 2993, "author_profile": "https://Stackoverflow.com/users/2993", "pm_score": 4, "selected": false, "text": "var kernel = new StandardKernel();\nkernel.Load( Assembly.Load(\"yourpath_to_assembly.dll\");\n public void Load(IEnumerable<Assembly> assemblies)\n{\n foreach (Assembly assembly in assemblies)\n {\n this.Load(assembly.GetNinjectModules());\n }\n}\n" }, { "answer_id": 8482260, "author": "ungood", "author_id": 559492, "author_profile": "https://Stackoverflow.com/users/559492", "pm_score": 5, "selected": false, "text": "public static IKernel CreateKernel()\n{\n var kernel = new StandardKernel();\n\n kernel.Scan(scanner => {\n scanner.FromAssembliesInPath(@\"Path\\To\\Plugins\");\n scanner.AutoLoadModules();\n scanner.WhereTypeInheritsFrom<IPlugin>();\n scanner.BindWith<PluginBindingGenerator<IPlugin>>();\n });\n\n return kernel;\n}\n\nprivate class PluginBindingGenerator<TPluginInterface> : IBindingGenerator\n{\n private readonly Type pluginInterfaceType = typeof (TPluginInterface);\n\n public void Process(Type type, Func<IContext, object> scopeCallback, IKernel kernel)\n {\n if(!pluginInterfaceType.IsAssignableFrom(type))\n return;\n if (type.IsAbstract || type.IsInterface)\n return;\n kernel.Bind(pluginInterfaceType).To(type);\n }\n}\n kernel.GetAll<IPlugin>()" }, { "answer_id": 9719925, "author": "Pablonete", "author_id": 73130, "author_profile": "https://Stackoverflow.com/users/73130", "pm_score": 4, "selected": false, "text": "var kernel = new StandardKernel();\nkernel.Bind(scanner => scanner.FromAssembliesInPath(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location))\n .SelectAllClasses()\n .InheritedFrom<IPlugin>()\n .BindToAllInterfaces());\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/330927", "https://Stackoverflow.com", "https://Stackoverflow.com/users/32415/" ]
330,937
<p>I am using in the first part of my program</p> <p><code>On Error GoTo start</code></p> <p>Suppose in my second part I am again using</p> <p><code>On Error Resume Next</code></p> <p>This second error trap will not get activated as the first one will still be active. Is there any way to de-activate the first error handler after it has been used?</p> <pre class="lang-vb prettyprint-override"><code>Set objexcel = CreateObject(&quot;excel.Application&quot;) objexcel.Visible = True On Error GoTo Openwb wbExists = False Set wbexcel = objexcel.Workbooks.Open(&quot;C:\REPORT3.xls&quot;) Set objSht = wbexcel.Worksheets(&quot;Sheet1&quot;) objSht.Activate wbExists = True Openwb: On Error GoTo 0 If Not wbExists Then objexcel.Workbooks.Add Set wbexcel = objexcel.ActiveWorkbook Set objSht = wbexcel.Worksheets(&quot;Sheet1&quot;) End If On Error GoTo 0 Set db = DBEngine.opendatabase(&quot;C:\book.mdb&quot;) Set rs = db.OpenRecordset(&quot;records&quot;) Set rs2 = CreateObject(&quot;ADODB.Recordset&quot;) rs2.ActiveConnection = CurrentProject.Connection For Each tdf In CurrentDb.TableDefs If Left(tdf.Name, 4) &lt;&gt; &quot;MSys&quot; Then rs.MoveFirst strsql = &quot;SELECT * From [&quot; &amp; tdf.Name &amp; &quot;] WHERE s=15 &quot; Do While Not rs.EOF On Error Resume Next rs2.Open strsql </code></pre> <p>Upon execution of the last statement I want to ignore the error and move on to the next table but error handling does not seem to work.</p>
[ { "answer_id": 330947, "author": "Dirk Vollmar", "author_id": 40347, "author_profile": "https://Stackoverflow.com/users/40347", "pm_score": 1, "selected": false, "text": "On Error Goto 0\n" }, { "answer_id": 331054, "author": "Jason Z", "author_id": 2470, "author_profile": "https://Stackoverflow.com/users/2470", "pm_score": 3, "selected": false, "text": "If Err.Number > 0 Then\n Err.Clear\nEnd If\n" }, { "answer_id": 331096, "author": "Fionnuala", "author_id": 2548, "author_profile": "https://Stackoverflow.com/users/2548", "pm_score": 3, "selected": true, "text": "Set objexcel = CreateObject(\"excel.Application\")\nobjexcel.Visible = True\n\n'On Error GoTo Openwb '\n'wbExists = False '\n\nIf Dir(\"C:\\REPORT3.xls\") = \"\" Then\n objexcel.Workbooks.Add\n Set wbexcel = objexcel.ActiveWorkbook\n Set objSht = wbexcel.Worksheets(\"Sheet1\")\nElse\n Set wbexcel = objexcel.Workbooks.Open(\"C:\\REPORT3.xls\")\n Set objSht = wbexcel.Worksheets(\"Sheet1\")\nEnd If\n\nobjSht.Activate\n'wbExists = True '\n" }, { "answer_id": 331386, "author": "Philippe Grondier", "author_id": 11436, "author_profile": "https://Stackoverflow.com/users/11436", "pm_score": 4, "selected": false, "text": "On error goto 0 On error goto label On error resume next Resume next On Error goto 0\n ...\n On Error goto 0\n Do While Not rs.EOF\n \n On Error Resume Next\n rs2.Open strsql\n On error Goto 0\n\n rs2.moveNext\n\n Loop\n On error goto label\n ...\n ...\n On error goto 0\n exit sub (or function)\n\n label:\n ....\n resume next\n end function\n\n Set objexcel = CreateObject(\"excel.Application\")\n objexcel.Visible = True\n\n On Error GoTo error_Treatment\n wbExists = False\n Set wbexcel = objexcel.Workbooks.Open(\"C:\\REPORT3.xls\")\n Set objSht = wbexcel.Worksheets(\"Sheet1\")\n objSht.Activate\n wbExists = True\n On error GoTo 0\n\n Set db = DBEngine.opendatabase(\"C:\\book.mdb\")\n Set rs = db.OpenRecordset(\"records\")\n\n Set rs2 = CreateObject(\"ADODB.Recordset\")\n rs2.ActiveConnection = CurrentProject.Connection\n\n For Each tdf In CurrentDb.TableDefs\n ....\n 'there are a number of potential errors here in your code'\n 'you should make sure that rs2 is closed before reopening it with a new instruction'\n 'etc.'\n Next tdf\n\n Exit sub\n\n error_treatment:\n SELECT Case err.number\n Case **** '(the err.number raised when the file is not found)'\n objexcel.Workbooks.Add\n Set wbexcel = objexcel.ActiveWorkbook\n Set objSht = wbexcel.Worksheets(\"Sheet1\")\n Resume next 'go back to the code'\n Case **** '(the recordset cannot be opened)'\n ....\n ....\n Resume next 'go back to the code'\n Case **** '(whatever other error to treat)'\n ....\n ....\n Resume next 'go back to the code'\n Case Else\n debug.print err.number, err.description '(check if .description is a property of the error object)'\n 'your error will be displayed in the immediate windows of VBA.' \n 'You can understand it and correct your code until it runs'\n End select\n End sub\n Public function fileExists (myFileName) as Boolean\n if fileExists(\"C:\\REPORT3.xls\") Then\n Set wbexcel = objexcel.Workbooks.Open(\"C:\\REPORT3.xls\")\n Else\n objexcel.Workbooks.Add\n Set wbexcel = objexcel.ActiveWorkbook\n Endif \n Set objSht = wbexcel.Worksheets(\"Sheet1\")\n objSht.Activate\n If rs.EOF and rs.BOF then\n Else\n rs.moveFirst\n Do while not rs.EOF\n rs.moveNext\n Loop\n End If\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/330937", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31132/" ]
330,951
<p>Is there a simple way to remove a leading zero (as in 01 becoming 1)?</p>
[ { "answer_id": 330962, "author": "Tomalak", "author_id": 18771, "author_profile": "https://Stackoverflow.com/users/18771", "pm_score": 3, "selected": false, "text": "$str = \"01\";\necho intval($str);\n" }, { "answer_id": 330969, "author": "J.D. Fitz.Gerald", "author_id": 11542, "author_profile": "https://Stackoverflow.com/users/11542", "pm_score": -1, "selected": false, "text": "echo \"01\"*1\n" }, { "answer_id": 330973, "author": "annakata", "author_id": 13018, "author_profile": "https://Stackoverflow.com/users/13018", "pm_score": 0, "selected": false, "text": "/^0*/ <?php\n $string_number = '000304';\n echo preg_replace('/^0*/', '', $string_number);\n?>\n" }, { "answer_id": 331015, "author": "Matt", "author_id": 42135, "author_profile": "https://Stackoverflow.com/users/42135", "pm_score": 4, "selected": false, "text": "ltrim ltrim($str,\"0\");\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/330951", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
330,971
<p>I have create a form class for editing deleting and add users to a database. If I want to edit a user how can I simply supply the information of the user to the form.</p> <p>I use a Zend_Db_Table to get the data from the database.</p> <p>This is the userForm class:</p> <pre><code>class UsersForm extends Zend_Form { public function init () { $username = new Zend_Form_Element_Text('username',array( 'validatrors' =&gt; array( 'alpha', array('stringLength',5,10) ), 'filters' =&gt; array( 'StringToLower' ), 'required' =&gt; true, 'label' =&gt; 'Gebruikersnaam:' )); $password = new Zend_Form_Element_Password('password', array( 'validators'=&gt; array( 'Alnum', array('StringLength', array(6,20)) ), 'filters' =&gt; array('StringTrim'), 'required' =&gt; true, 'label' =&gt; 'Wachtwoord:' )); $actif = new Zend_Form_Element_Checkbox('actif', array( 'label' =&gt; 'actif')); $this-&gt;addElements(array($username,$password,$actif)); $this-&gt;setDecorators(array( 'FormElements', array('HtmlTag', array('tag' =&gt; 'dl', 'class' =&gt; 'zend_form')), array('Description',array('placement' =&gt; 'prepand')), 'Form' )); } } </code></pre> <p>Thank you,</p> <p>Ivo Trompert</p>
[ { "answer_id": 331591, "author": "markus", "author_id": 11995, "author_profile": "https://Stackoverflow.com/users/11995", "pm_score": 3, "selected": true, "text": "$form->populate($data);\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/330971", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42111/" ]
330,978
<p>Something I do often if I'm storing a bunch of string values and I want to be able to find them in O(1) time later is:</p> <pre><code>foreach (String value in someStringCollection) { someDictionary.Add(value, String.Empty); } </code></pre> <p>This way, I can comfortably perform <strong>constant-time</strong> lookups on these string values later on, such as:</p> <pre><code>if (someDictionary.containsKey(someKey)) { // etc } </code></pre> <p>However, I feel like I'm cheating by making the value <strong>String.Empty</strong>. Is there a more appropriate .NET Collection I should be using?</p>
[ { "answer_id": 331014, "author": "user7116", "author_id": 7116, "author_profile": "https://Stackoverflow.com/users/7116", "pm_score": 4, "selected": true, "text": "HashSet<string> stringSet = new HashSet<string>(someStringCollection);\n\nif (stringSet.Contains(someString))\n{\n ...\n}\n" }, { "answer_id": 331017, "author": "leppie", "author_id": 15541, "author_profile": "https://Stackoverflow.com/users/15541", "pm_score": 2, "selected": false, "text": "HashSet<T> Dictionary<string,bool>" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/330978", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2273/" ]
330,993
<p>I'm new to ruby and started to create my *nd toy app. I:</p> <ol> <li>Created controller 'questions'</li> <li>Created model 'question'</li> <li>Created controller action 'new'</li> <li>Added 'New.html.erb' file</li> </ol> <p>in erb file I use <code>form_for</code> helper and and <code>new</code> controller action where I instantiate <code>@question</code> instance variable. When I try to run this I get <code>'undefined method: questions_path for #&lt;ActionView::Base:0x5be5e24&gt;'</code> error. Below is my new.html.erb:</p> <pre><code>&lt;%form_for @question do |f| %&gt; &lt;%=f.text_field :title %&gt; &lt;%end%&gt; </code></pre> <p>Please advise how to fix this and also help me with aliasing this controller action. What I mean is I would like to type <a href="http://mysite/questions/ask" rel="nofollow noreferrer">http://mysite/questions/ask</a>, instead of /questions/create</p>
[ { "answer_id": 331085, "author": "Michael Sepcot", "author_id": 6033, "author_profile": "https://Stackoverflow.com/users/6033", "pm_score": 4, "selected": true, "text": "config/routes.rb map.resources :questions\n /questions/ask routes.rb map.ask_question '/questions/ask', :controller => 'questions', :action => 'create'\n ask_question_path" }, { "answer_id": 331108, "author": "mwilliams", "author_id": 23909, "author_profile": "https://Stackoverflow.com/users/23909", "pm_score": 0, "selected": false, "text": ">ruby script/generate scaffold question question:string answer:string votes:integer\n exists app/models/\n exists app/controllers/\n exists app/helpers/\n create app/views/questions\n exists app/views/layouts/\n exists test/functional/\n exists test/unit/\n exists public/stylesheets/\n create app/views/questions/index.html.erb\n create app/views/questions/show.html.erb\n create app/views/questions/new.html.erb\n create app/views/questions/edit.html.erb\n create app/views/layouts/questions.html.erb\n create public/stylesheets/scaffold.css\n create app/controllers/questions_controller.rb\n create test/functional/questions_controller_test.rb\n create app/helpers/questions_helper.rb\n route map.resources :questions\n dependency model\n exists app/models/\n exists test/unit/\n exists test/fixtures/\n create app/models/question.rb\n create test/unit/question_test.rb\n create test/fixtures/questions.yml\n create db/migrate\n create db/migrate/20081201150131_create_questions.rb\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/330993", "https://Stackoverflow.com", "https://Stackoverflow.com/users/430254/" ]
331,000
<p>A couple of years ago, we had a graphic designer revamp our website. His results looked great, but he unfortunately introduced a new unsupported font by the web browser. </p> <p>At first I was like, "What!?!"... since most of our content is dynamic and there was no real way to pre-make all of the images. There was also the issue of multiple languages (since we knew Spanish was on the horizon).</p> <p>Anyway, I decided to create some classes to auto-generate images via GDI+ and programatically cache them as needed. This solved most of our initial problems. However, now that our load has increased dramatically, there has been a drain on our UI server.</p> <p>Now to the question... I am looking to replace most of the dynamic GDI+ images with a standard web browser font. I am thinking of keeping some of the rendered GDI+ images and putting them in a resx file, but plan to replace most of them with Tahoma or Arial fonts via asp:Labels. </p> <p>Which have you found to be a better localized image solution? </p> <ul> <li>Embedding images into the resx</li> <li>Only adding the image url into the resx</li> <li>Some other solution</li> </ul> <p>My main concern is to limit the processing on the UI server. If that is the case, would adding the image url to the resx be a better solution compared to actually embedding the image into the resx?</p>
[ { "answer_id": 331099, "author": "Jack Ryan", "author_id": 28882, "author_profile": "https://Stackoverflow.com/users/28882", "pm_score": 2, "selected": false, "text": "/images/\n /en/\n header1.gif\n /es/\n header1.gif\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331000", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4481/" ]
331,002
<p>I need to change the date format from US (mm/dd/YYYY) to UK (dd/mm/YYYY) on a single database on a SQL server machine.</p> <p>How can this be done?</p> <p>I've seen statements that do this for the whole system, and ones that do it for the session, but I can't change the code now as it will have to go through QA again, so I need a quick fix to change the date time format.</p> <p><strong>Update</strong></p> <p>I realize that the date time has nothing to do with how SQL Server stores the data, but it does have a lot to do with how it parses queries.</p> <p>I'm chucking raw data from an XML file into a database. The dates in the XML file are in UK date format.</p>
[ { "answer_id": 331031, "author": "Mladen Prajdic", "author_id": 31345, "author_profile": "https://Stackoverflow.com/users/31345", "pm_score": -1, "selected": false, "text": "set dateformat" }, { "answer_id": 331046, "author": "Nick Berardi", "author_id": 17, "author_profile": "https://Stackoverflow.com/users/17", "pm_score": 3, "selected": false, "text": "set language 'british english'\n" }, { "answer_id": 333680, "author": "kristof", "author_id": 3241, "author_profile": "https://Stackoverflow.com/users/3241", "pm_score": 6, "selected": true, "text": "declare @dates table (orig varchar(50) ,parsed datetime)\n\nSET DATEFORMAT ydm;\n\ninsert into @dates\nselect '2008-09-01','2008-09-01'\n\nSET DATEFORMAT ymd;\ninsert into @dates\nselect '2008-09-01','2008-09-01'\n\nselect * from @dates\n" }, { "answer_id": 507364, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": -1, "selected": false, "text": "select * from mytest\nEXEC sp_rename 'mytest.eid', 'id', 'COLUMN'\nalter table mytest add id int not null identity(1,1)\nupdate mytset set eid=id\nALTER TABLE mytest DROP COLUMN eid\n\nALTER TABLE [dbo].[yourtablename] ADD DEFAULT (getdate()) FOR [yourfieldname]\n" }, { "answer_id": 1099246, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": -1, "selected": false, "text": "EXEC sp_defaultlanguage 'username', 'british'\n" }, { "answer_id": 28366861, "author": "SergeyT", "author_id": 1336856, "author_profile": "https://Stackoverflow.com/users/1336856", "pm_score": 3, "selected": false, "text": "ALTER LOGIN your_login WITH DEFAULT_LANGUAGE=British\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331002", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20400/" ]
331,007
<p>I have a TextBox control on my Form. I use the Leave event on the control to process user input. It works fine if the user clicks on some other control on the form, but the even doesn't get fired when the user goes straight to the main menu. Any ideas which event should I use to get it fired everytime?</p>
[ { "answer_id": 331035, "author": "TcKs", "author_id": 20382, "author_profile": "https://Stackoverflow.com/users/20382", "pm_score": 2, "selected": false, "text": "private void menuStrip1_MenuActivate( object sender, EventArgs e ) {\n bool ret = this.Validate( false );\n if ( false == ret ) {\n // user's input is wrong\n }\n}\n" }, { "answer_id": 331098, "author": "Grzenio", "author_id": 5363, "author_profile": "https://Stackoverflow.com/users/5363", "pm_score": 4, "selected": true, "text": " private void menuStrip1_MenuActivate( object sender, EventArgs e )\n {\n menuStrip1.Focus();\n }\n" }, { "answer_id": 331253, "author": "Fredou", "author_id": 40868, "author_profile": "https://Stackoverflow.com/users/40868", "pm_score": -1, "selected": false, "text": "Private Sub TextBox1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Leave\n MsgBox(\"yes\")\nEnd Sub\n\nPrivate Sub MenuStrip1_MenuActivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles MenuStrip1.MenuActivate\n CType(sender, MenuStrip).Tag = ActiveControl\n Label1.Focus()\nEnd Sub\n\nPrivate Sub MenuStrip1_MenuDeactivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles MenuStrip1.MenuDeactivate\n If CType(sender, MenuStrip).Tag Is Control AndAlso CType(CType(sender, MenuStrip).Tag, Control).CanFocus Then\n CType(CType(sender, MenuStrip).Tag, Control).Focus()\n End If\n CType(sender, MenuStrip).Tag = Nothing\nEnd Sub\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331007", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5363/" ]
331,013
<p>I'm refactoring some objects that are serialized to XML but need to keep a few properties for backwards compatibility, I've got a method that converts the old object into the new one for me and nulls the obsolete property. I want to use the <code>Obsolete</code> attribute to tell other developers not to use this property but it is causing the property to be ignored by the <code>XmlSerializer</code>.</p> <p>Similar Code:</p> <pre><code>[Serializable] public class MySerializableObject { private MyObject _oldObject; private MyObject _anotherOldObject; private MyObject _newBetterObject; [Obsolete("Use new properties in NewBetterObject to prevent duplication")] public MyObject OldObject { get { return _oldObject; } set { _oldObject = value; } } [Obsolete("Use new properties in NewBetterObject to prevent duplication")] public MyObject AnotherOldObject { get { return _anotherOldObject; } set { _anotherOldObject = value; } } public MyObject NewBetterObject { get { return _anotherOldObject; } set { _anotherOldObject = value; } } } </code></pre> <p>Any ideas on a workaround? My best solution is to write obsolete in the XML comments...</p> <p><strong>Update: I'm using .NET 2.0</strong></p>
[ { "answer_id": 331062, "author": "Bluenuance", "author_id": 33111, "author_profile": "https://Stackoverflow.com/users/33111", "pm_score": 0, "selected": false, "text": "ShouldSerializeOldObject ()\n{\n return true;\n}\n\nShouldSerializeAnotherOldObject ()\n{\n return true\n}\n" }, { "answer_id": 6919084, "author": "Rolf Kristensen", "author_id": 193178, "author_profile": "https://Stackoverflow.com/users/193178", "pm_score": 4, "selected": false, "text": "static void serializer_UnknownElement(object sender, XmlElementEventArgs e)\n{\n if( e.Element.Name != \"Hobbies\")\n {\n return;\n }\n\n var target = (MyData) e.ObjectBeingDeserialized;\n foreach(XmlElement hobby in e.Element.ChildNodes)\n {\n target.Hobbies.Add(hobby.InnerText);\n target.HobbyData.Add(new Hobby{Name = hobby.InnerText});\n }\n}\n" }, { "answer_id": 17819730, "author": "georgiosd", "author_id": 165656, "author_profile": "https://Stackoverflow.com/users/165656", "pm_score": 2, "selected": false, "text": "Obsolete Foo ObsoleteFoo" }, { "answer_id": 36038264, "author": "David Homer", "author_id": 847786, "author_profile": "https://Stackoverflow.com/users/847786", "pm_score": 2, "selected": false, "text": "/// <summary>\n/// Determines the swap file location for a cluster.\n/// </summary>\n/// <remarks>This enum contains the original text based values for backwards compatibility with versions previous to \"8.1\".</remarks>\npublic enum VMwareClusterSwapFileLocation\n{\n\n /// <summary>\n /// The swap file location is unknown.\n /// </summary>\n Unknown = 0,\n\n /// <summary>\n /// The swap file is stored in the virtual machine directory.\n /// </summary>\n VmDirectory = 1,\n\n /// <summary>\n /// The swap file is stored in the datastore specified by the host.\n /// </summary>\n HostLocal = 2,\n\n /// <summary>\n /// The swap file is stored in the virtual machine directory. This value is obsolete and used for backwards compatibility.\n /// </summary>\n [XmlElement(\"vmDirectory\")]\n ObseleteVmDirectory = 3,\n\n /// <summary>\n /// The swap file is stored in the datastore specified by the host. This value is obsolete and used for backwards compatibility.\n /// </summary>\n [XmlElement(\"hostLocal\")]\n ObseleteHostLocal = 4,\n\n\n\n\n}\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331013", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4950/" ]
331,045
<p>This question is related to <a href="https://stackoverflow.com/questions/232926/how-to-make-consistent-dll-binaries-across-vs-versions">"How to make consistent dll binaries across VS versions ?"</a></p> <ul> <li>We have applications and DLLs built with VC6 and a new application built with VC9. The VC9-app has to use DLLs compiled with VC6, most of which are written in C and one in C++.</li> <li>The C++ lib is problematic due to name decoration/mangling issues.</li> <li>Compiling everything with VC9 is currently not an option as there appear to be some side effects. Resolving these would be quite time consuming.</li> <li>I can modify the C++ library, however it must be compiled with VC6.</li> <li>The C++ lib is essentially an OO-wrapper for another C library. The VC9-app uses some static functions as well as some non-static.</li> </ul> <p>While the static functions can be handled with something like</p> <pre><code>// Header file class DLL_API Foo { int init(); } extern "C" { int DLL_API Foo_init(); } // Implementation file int Foo_init() { return Foo::init(); } </code></pre> <p>it's not that easy with the non-static methods.</p> <p>As I understand it, <a href="https://stackoverflow.com/questions/232926/how-to-make-consistent-dll-binaries-across-vs-versions#232959">Chris Becke's</a> suggestion of using a COM-like interface won't help me because the interface member names will still be decorated and thus inaccessible from a binary created with a different compiler. <em>Am I right there?</em></p> <p>Would the only solution be to write a C-style DLL interface using handlers to the objects or am I missing something? In that case, I guess, I would probably have less effort with directly using the wrapped C-library.</p>
[ { "answer_id": 331064, "author": "Roger Lipscombe", "author_id": 8446, "author_profile": "https://Stackoverflow.com/users/8446", "pm_score": 3, "selected": true, "text": "struct IFoo {\n int Init() = 0;\n};\n class CFoo : public IFoo { /* ... */ };\nextern \"C\" IFoo * __stdcall GetFoo() { return new CFoo(); }\n" }, { "answer_id": 331088, "author": "Roger Lipscombe", "author_id": 8446, "author_profile": "https://Stackoverflow.com/users/8446", "pm_score": 3, "selected": false, "text": "new malloc delete free IFoo::Release MyDllFree() delete free() LocalAlloc" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331045", "https://Stackoverflow.com", "https://Stackoverflow.com/users/27596/" ]
331,052
<p>I have a canvas element defined statically in the html with a width and height. If I attempt to use JavaScript to resize it dynamically (setting a new width and height - either on the attributes of the canvas or via the style properties) I get the following error in Firefox:</p> <blockquote> <p>uncaught exception: [Exception... "Illegal operation on WrappedNative prototype object" nsresult: "0x8057000c (NS_ERROR_XPC_BAD_OP_ON_WN_PROTO)" location: "JS frame :: file:///home/russh/Desktop/test.html :: onclick :: line 1" data: no]</p> </blockquote> <p>Is it possible to resize this element or do I have to destroy it and create a new element on the fly? </p>
[ { "answer_id": 331462, "author": "Eugene Lazutkin", "author_id": 26394, "author_profile": "https://Stackoverflow.com/users/26394", "pm_score": 6, "selected": false, "text": "canvasNode.width = 200; // in pixels\ncanvasNode.height = 100; // in pixels\n interface HTMLCanvasElement : HTMLElement {\n attribute unsigned long width;\n attribute unsigned long height;\n\n DOMString toDataURL();\n DOMString toDataURL(in DOMString type, [Variadic] in any args);\n\n DOMObject getContext(in DOMString contextId);\n};\n width height unsigned long" }, { "answer_id": 331472, "author": "Kent Brewster", "author_id": 1151280, "author_profile": "https://Stackoverflow.com/users/1151280", "pm_score": 2, "selected": false, "text": "<canvas id=\"c\" height=\"100\" width=\"100\" style=\"border:1px solid red\"></canvas>\n<script>\nvar c = document.getElementById('c');\nalert(c.height + ' ' + c.width);\nc.height = 200;\nc.width = 200;\nalert(c.height + ' ' + c.width);\n</script>\n" }, { "answer_id": 5523976, "author": "john", "author_id": 689013, "author_profile": "https://Stackoverflow.com/users/689013", "pm_score": 4, "selected": false, "text": "var oldCanvas = canvas.toDataURL(\"image/png\");\nvar img = new Image();\nimg.src = oldCanvas;\nimg.onload = function (){\n canvas.height += 100;\n ctx.drawImage(img, 0, 0);\n}\n" }, { "answer_id": 8143267, "author": "Gezim", "author_id": 32495, "author_profile": "https://Stackoverflow.com/users/32495", "pm_score": 1, "selected": false, "text": "<canvas width=\"100\" height=\"100\"></canvas>\n var $canvas = $('canvas'),\n oldCanvas,\n context = $canvas[0].getContext('2d');\n\nfunction drawRects(x, y, width, height)\n{\n if (($canvas.width() < x+width) || $canvas.height() < y+height)\n {\n oldCanvas = $canvas[0].toDataURL(\"image/png\")\n $canvas[0].width = x+width;\n $canvas[0].height = y+height;\n\n var img = new Image();\n img.src = oldCanvas;\n img.onload = function (){\n context.drawImage(img, 0, 0);\n };\n }\n context.strokeRect(x, y, width, height);\n}\n\n\ndrawRects(5,5, 10, 10);\ndrawRects(15,15, 20, 20);\ndrawRects(35,35, 40, 40);\ndrawRects(75, 75, 80, 80);\n" }, { "answer_id": 8349409, "author": "sam hocevar", "author_id": 111461, "author_profile": "https://Stackoverflow.com/users/111461", "pm_score": 5, "selected": false, "text": "width height <canvas id=\"c\" height=\"100\" width=\"100\" style=\"border:1px\"></canvas>\n<script>\n document.getElementById('c').width = 200;\n</script>\n <canvas id=\"c\" style=\"width: 100px; height: 100px; border:1px\"></canvas>\n<script>\n document.getElementById('c').width = 200;\n</script>\n" }, { "answer_id": 14329897, "author": "Braden Best", "author_id": 1175714, "author_profile": "https://Stackoverflow.com/users/1175714", "pm_score": 0, "selected": false, "text": "_PROTO HTMLCanvasElement.prototype.width <canvas></canvas>\n<canvas></canvas>\n<canvas></canvas>\n<script type=\"text/javascript\">\n ...\n</script>\n $$ = function(){\n return document.querySelectorAll.apply(document,arguments);\n}\nfor(var i in $$('canvas')){\n canvas = $$('canvas')[i];\n canvas.width = canvas.width+100;\n canvas.height = canvas.height+100;\n}\n" }, { "answer_id": 14682877, "author": "Jignesh Variya", "author_id": 1365663, "author_profile": "https://Stackoverflow.com/users/1365663", "pm_score": 3, "selected": false, "text": "<div id=\"canvasdiv\" style=\"margin: 5px; height: 100%; width: 100%;\">\n <canvas id=\"mycanvas\" style=\"border: 1px solid red;\"></canvas>\n</div>\n<script>\n$(function(){\n InitContext();\n});\nfunction InitContext()\n{\nvar $canvasDiv = $('#canvasdiv');\n\nvar canvas = document.getElementById(\"mycanvas\");\ncanvas.height = $canvasDiv.innerHeight();\ncanvas.width = $canvasDiv.innerWidth();\n}\n</script>\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331052", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42145/" ]
331,068
<p>I have been using anonymous namespaces to store local data and functions and wanted to know when the data is initialized? Is it when the application starts in the same way as static data or is it compiler dependent? For example:</p> <pre><code>// foo.cpp #include "foo.h" namespace { const int SOME_VALUE = 42; } void foo::SomeFunc(int n) { if (n == SOME_VALUE) { ... } } </code></pre> <p>The question arises out of making some code thread-safe. In the above example I need to be certain that <code>SOME_VALUE</code> is initialized before SomeFunc is called for the first time.</p>
[ { "answer_id": 331078, "author": "Mathieu Pagé", "author_id": 5861, "author_profile": "https://Stackoverflow.com/users/5861", "pm_score": 2, "selected": false, "text": "void foo::SomeFunc(int n)\n{\n if (n == 42)\n {\n ...\n }\n}\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331068", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9236/" ]
331,069
<p>I'm working on an existing j2ee app and am required to remove some vendor specific method calls from the code.</p> <p>The daos behind a session facade make calls into the ejb container to get the user's id and password - in order to connect to the database. The user id and password part of the initialContext used to connect to the server.</p> <p>I am able to get the userid using <code>sessionContext.getCallerPrincipal()</code></p> <p>Is there anyway to get to the <code>SECURITY_CREDENTIALS</code> used on the server connection or, is there a way to pass information from the server connection into the ejbs (they are all stateless session beans).</p> <p>This is a large app with both a rich-client and web front end, and in a perfect world I'd be happy to go back and re-architect the entire solution to use J2EE security etc - but unfortunately, that is not realistic.</p>
[ { "answer_id": 331664, "author": "Robin", "author_id": 21925, "author_profile": "https://Stackoverflow.com/users/21925", "pm_score": 1, "selected": false, "text": "getCallerPrincipal() JDBCServiceLocator" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331069", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42152/" ]
331,070
<p>I've got a website running under ASP .NET 2/IIS7/Vista. I have a URL rewriting module which allows me to have extensionless URLs. To get this to work I have configured the system.webServer section of the config file such that all requests are forwarded to the aspnet_isapi.dll. I have also added the URL rewrite module to the modules section and set runAllManagedModulesForAllRequests to true.</p> <p>When I start up the website and visit one of the pages that uses the URL rewriting, the page is rendered correctly. However if I then visit another page the site stops working and I get a 404 not found. I also find that my breakpoint in the URL rewriting module is not getting hit. It's almost as if IIS forwards the first request to the rewriter, but subsequent ones go somewhere else - the error page mentions Notification as being MapRequestHandler and Handler as being StaticFile.</p> <p>If I then make a small change to the web.config file and save it, triggering the website to restart, I can then reload the page in the browser and it all works. Then I click another link and it's broken again.</p> <p>For the record, here's a couple of snippets from the config file. First, under system.web:</p> <pre><code>&lt;httpModules&gt; &lt;add name="UrlRewriteModule" type="Arcs.CoopFurniture.TelesalesWeb.UrlRewriteModule, Arcs.CoopFurniture.TelesalesWeb" /&gt; &lt;/httpModules&gt; </code></pre> <p>and then, under system.webServer:</p> <pre><code>&lt;system.webServer&gt; &lt;modules runAllManagedModulesForAllRequests="true"&gt; &lt;add name="UrlRewriteModule" type="Arcs.CoopFurniture.TelesalesWeb.UrlRewriteModule, Arcs.CoopFurniture.TelesalesWeb" preCondition="managedHandler" /&gt; &lt;/modules&gt; &lt;handlers&gt; &lt;add name="AspNet" path="*" verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="None" preCondition="classicMode,runtimeVersionv2.0,bitness32" /&gt; &lt;/handlers&gt; &lt;validation validateIntegratedModeConfiguration="false" /&gt; &lt;/system.web&gt; </code></pre> <p>The site is running under classic rather than integrated pipeline mode.</p> <p>Does anyone out there have any ideas? I suspect my configuration is wrong somewhere but I can't seem to find where.</p>
[ { "answer_id": 331664, "author": "Robin", "author_id": 21925, "author_profile": "https://Stackoverflow.com/users/21925", "pm_score": 1, "selected": false, "text": "getCallerPrincipal() JDBCServiceLocator" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331070", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12277/" ]
331,082
<p>I find this very strange, must be something I'm doing wrong, but still... I'm working on a page using PHP and TPL files. In my TPL file, there's a place in the footer for some extra lines if needed.</p> <p>For instance, formchecking with Javascript.</p> <p>so in PHP I did this:</p> <pre><code>$foot = "&lt;script type=\"text/javascript\"&gt;if(document.getElementById){loadEvents();}&lt;/script&gt;"; </code></pre> <p>the $foot variable is then parsed and the result in HTML is this:</p> <pre><code>&lt;script type="text/javascript"&gt;if(document.getElementById)&lt;/script&gt; </code></pre> <p>So <code>{loadEvents();}</code> went missing.</p> <p>Does anybody see what I'm missing here... I'm seriously not finding it. Did I forget to escape a character or something?</p>
[ { "answer_id": 331092, "author": "Tomalak", "author_id": 18771, "author_profile": "https://Stackoverflow.com/users/18771", "pm_score": 4, "selected": true, "text": "$foot = \"{literal}<script type=\\\"text/javascript\\\">if(document.getElementById){loadEvents();}</script>{/literal}\";\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331082", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11795/" ]
331,105
<p>I have set the <code>itemRollOver</code> and <code>itemRollOut</code> event listeners on a List component, but whenever I roll the mouse over a list item, both the over and out events of the same list item fire in succession right after each other. My list uses a custom itemRenderer.</p> <p>Any ideas why this might be? The Adobe documentation doesn't provide much insight into this (not surprisingly...).</p>
[ { "answer_id": 1179514, "author": "RJ Regenold", "author_id": 144682, "author_profile": "https://Stackoverflow.com/users/144682", "pm_score": 0, "selected": false, "text": "import mx.core.mx_internal;\n\nuse namespace mx_internal;\n\npublic class List extends mx.controls.List\n{\n public function List()\n {\n super();\n }\n\n override mx_internal function clearHighlight( item:IListItemRenderer ):void\n {\n var uid:String = itemToUID( item.data );\n\n drawItem( UIDToItemRenderer( uid ), isItemSelected( item.data ), false, uid == caretUID );\n\n var pt:Point = itemRendererToIndices( item );\n\n if( pt )\n {\n var listEvent:ListEvent = new ListEvent( ListEvent.ITEM_ROLL_OUT );\n\n listEvent.columnIndex = item.x;\n listEvent.rowIndex = item.y;\n listEvent.itemRenderer = item;\n\n dispatchEvent( listEvent );\n }\n }\n}\n <mx:Canvas xmlns:mx=\"http://www.adobe.com/2006/mxml\" xmlns:controls=\"com.example.controls.*\">\n\n [ other code ... ]\n\n <controls:List itemRollOver=\"onItemRollOver( event )\" itemRollOut=\"onItemRollOut( event )\" />\n\n</mx:Canvas>\n" }, { "answer_id": 2373771, "author": "sofajazz", "author_id": 285588, "author_profile": "https://Stackoverflow.com/users/285588", "pm_score": 0, "selected": false, "text": "listEvent.columnIndex = item.x;\nlistEvent.rowIndex = item.y;\n listEvent.columnIndex = pt.x;\nlistEvent.rowIndex = pt.y;\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331105", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36817/" ]
331,109
<p>I have a simple model called <code>Party</code> with a corresponding table called <code>parties</code>. There's also a controller with all the usual CRUD actions and so on. This model is used in a website and only one admin user is allowed to edit the parties - everyone else is allowed to call GET actions (index, show). Nothing special so far.</p> <p>Now I need to do the following: The admin would like to choose a single Party at a time for special presentation (the selected Party is showing up on the start page of the application). The most important thing is, that there's only ONE party at time selected.</p> <p>How would you solve this problem? Boolean Flag in Party model? Save the selection (id of the party) somewhere outside the database? Implement a new model with a has_one relation to Party (seems like overkill to me)?</p> <p>I hope my explanation is good enough to understand the issue.</p>
[ { "answer_id": 331134, "author": "Milan Novota", "author_id": 26123, "author_profile": "https://Stackoverflow.com/users/26123", "pm_score": 2, "selected": false, "text": "set_promoted_party and get_promoted_party actions PUT /parties/promoted/:party_id # to set the promoted party\nGET /parties/promoted/:party_id # to get the promoted_party\n" }, { "answer_id": 331140, "author": "mwilliams", "author_id": 23909, "author_profile": "https://Stackoverflow.com/users/23909", "pm_score": 3, "selected": true, "text": "require 'singleton'\n\nclass Master < ActiveRecord::Base\n include Singleton\n def initialize(args=nil) super(args) if record = Master.find(:first) \n self.attributes = record.attributes end end def next_tracking_number increment!\n (:current_tracking_number) current_tracking_number end def \n self.next_tracking_number instance.next_tracking_number \n end\nend\n" }, { "answer_id": 331211, "author": "Ryan McGeary", "author_id": 8985, "author_profile": "https://Stackoverflow.com/users/8985", "pm_score": 0, "selected": false, "text": "promoted_party.yml --- \nparty_id: 123\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331109", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20467/" ]
331,115
<p>How do you specify the Fill Factor when creating an index in MySql?</p>
[ { "answer_id": 44022337, "author": "Nameless One", "author_id": 2420536, "author_profile": "https://Stackoverflow.com/users/2420536", "pm_score": 1, "selected": false, "text": "innodb_fill_factor 100" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331115", "https://Stackoverflow.com", "https://Stackoverflow.com/users/383/" ]
331,131
<p>What we are looking for is: while compiling the same configuration, say Release|Win32, is there a way to only do the postbuild steps sometimes. Like, if I am on a dev machine do all the post-build steps or if I am on a build server then don't do them. Or is the only way to accomplish this is by implementing a new configuration?</p> <p>Commenters: Thanks for the ideas, we do not want to use scripts as they would be one more thing to maintain, and going to MSBuild proj files would be a lot of headache at this point as well. Thanks for trying though.</p>
[ { "answer_id": 331175, "author": "Lurker Indeed", "author_id": 16951, "author_profile": "https://Stackoverflow.com/users/16951", "pm_score": 5, "selected": true, "text": "if NOT %ComputerName% == DEVMACHINENAME GOTO end\nc:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727\\ngen \"$(TargetPath)\"\n:end\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331131", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26564/" ]
331,146
<p>How do I pass an array I have created on the server side onto the client side for manipulation by Javascript?</p> <p>Any pseudo code will help</p>
[ { "answer_id": 18609470, "author": "fonsIT", "author_id": 1960661, "author_profile": "https://Stackoverflow.com/users/1960661", "pm_score": 2, "selected": false, "text": " private string buttonarray = \"'but1','but2','but3','but4'\";\n\n public string Buttonarray\n {\n get { return buttonarray; }\n }\n var buttonarray = new Array(<%=Buttonarray%>);\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331146", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13370/" ]
331,148
<p>In C the following horror is valid:</p> <pre><code>myFunc() { return 42; // return type defaults to int. } </code></pre> <p>But, what about in C++? I can't find a reference to it either way...</p> <p>My compiler (Codegear C++Builder 2007) currently accepts it without warning, but I've had comments that this <strong><em>is</em></strong> an error in C++.</p>
[ { "answer_id": 332312, "author": "tfinniga", "author_id": 9042, "author_profile": "https://Stackoverflow.com/users/9042", "pm_score": 1, "selected": false, "text": "error C4430: missing type specifier - int assumed. Note: C++ does not support default-int\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331148", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1737/" ]
331,152
<p>I have an external stylesheet that has specific IE-hacks. Every so often my site will fail to build due to these hacks (it is the hash-hack; for example <strong><code>#margin-top:-2px;</code></strong>). This is the error:</p> <blockquote> <p>Unexpected character sequence. Expected a property name for the " : " declaration</p> </blockquote> <p>I haven't found out a concrete way to get the errors to stop, VS2008 just seems to stop caring after a while. I found <a href="http://www.carlj.ca/2008/01/05/adding-css-colors-to-visual-studio-2005/" rel="nofollow noreferrer">this article</a>, but I am unsure of how to edit the files properly so this "error" (since it is legal syntax) will not pop up again.</p>
[ { "answer_id": 331189, "author": "annakata", "author_id": 13018, "author_profile": "https://Stackoverflow.com/users/13018", "pm_score": 4, "selected": true, "text": " Tools | Options | Text Editor | CSS | CSS Specific \n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331152", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25515/" ]
331,157
<p>Does SQL Server CheckSum calculate a CRC? If not how can I get SQL Server to calculate a CRC on an arbitrary varchar column?</p>
[ { "answer_id": 331412, "author": "Andrew Rollings", "author_id": 40410, "author_profile": "https://Stackoverflow.com/users/40410", "pm_score": 4, "selected": true, "text": "DECLARE @input VARCHAR(50)\nSET @input = 'test'\n\nSET NOCOUNT ON\nDECLARE @tblLookup TABLE (ID INT IDENTITY(0,1) NOT NULL, Value BIGINT)\nINSERT INTO @tblLookup VALUES (0)\nINSERT INTO @tblLookup VALUES (1996959894)\nINSERT INTO @tblLookup VALUES (3993919788)\nINSERT INTO @tblLookup VALUES (2567524794)\nINSERT INTO @tblLookup VALUES (124634137)\nINSERT INTO @tblLookup VALUES (1886057615)\nINSERT INTO @tblLookup VALUES (3915621685)\nINSERT INTO @tblLookup VALUES (2657392035)\nINSERT INTO @tblLookup VALUES (249268274)\nINSERT INTO @tblLookup VALUES (2044508324)\nINSERT INTO @tblLookup VALUES (3772115230)\nINSERT INTO @tblLookup VALUES (2547177864)\nINSERT INTO @tblLookup VALUES (162941995)\nINSERT INTO @tblLookup VALUES (2125561021)\nINSERT INTO @tblLookup VALUES (3887607047)\nINSERT INTO @tblLookup VALUES (2428444049)\nINSERT INTO @tblLookup VALUES (498536548)\nINSERT INTO @tblLookup VALUES (1789927666)\nINSERT INTO @tblLookup VALUES (4089016648)\nINSERT INTO @tblLookup VALUES (2227061214)\nINSERT INTO @tblLookup VALUES (450548861)\nINSERT INTO @tblLookup VALUES (1843258603)\nINSERT INTO @tblLookup VALUES (4107580753)\nINSERT INTO @tblLookup VALUES (2211677639)\nINSERT INTO @tblLookup VALUES (325883990)\nINSERT INTO @tblLookup VALUES (1684777152)\nINSERT INTO @tblLookup VALUES (4251122042)\nINSERT INTO @tblLookup VALUES (2321926636)\nINSERT INTO @tblLookup VALUES (335633487)\nINSERT INTO @tblLookup VALUES (1661365465)\nINSERT INTO @tblLookup VALUES (4195302755)\nINSERT INTO @tblLookup VALUES (2366115317)\nINSERT INTO @tblLookup VALUES (997073096)\nINSERT INTO @tblLookup VALUES (1281953886)\nINSERT INTO @tblLookup VALUES (3579855332)\nINSERT INTO @tblLookup VALUES (2724688242)\nINSERT INTO @tblLookup VALUES (1006888145)\nINSERT INTO @tblLookup VALUES (1258607687)\nINSERT INTO @tblLookup VALUES (3524101629)\nINSERT INTO @tblLookup VALUES (2768942443)\nINSERT INTO @tblLookup VALUES (901097722)\nINSERT INTO @tblLookup VALUES (1119000684)\nINSERT INTO @tblLookup VALUES (3686517206)\nINSERT INTO @tblLookup VALUES (2898065728)\nINSERT INTO @tblLookup VALUES (853044451)\nINSERT INTO @tblLookup VALUES (1172266101)\nINSERT INTO @tblLookup VALUES (3705015759)\nINSERT INTO @tblLookup VALUES (2882616665)\nINSERT INTO @tblLookup VALUES (651767980)\nINSERT INTO @tblLookup VALUES (1373503546)\nINSERT INTO @tblLookup VALUES (3369554304)\nINSERT INTO @tblLookup VALUES (3218104598)\nINSERT INTO @tblLookup VALUES (565507253)\nINSERT INTO @tblLookup VALUES (1454621731)\nINSERT INTO @tblLookup VALUES (3485111705)\nINSERT INTO @tblLookup VALUES (3099436303)\nINSERT INTO @tblLookup VALUES (671266974)\nINSERT INTO @tblLookup VALUES (1594198024)\nINSERT INTO @tblLookup VALUES (3322730930)\nINSERT INTO @tblLookup VALUES (2970347812)\nINSERT INTO @tblLookup VALUES (795835527)\nINSERT INTO @tblLookup VALUES (1483230225)\nINSERT INTO @tblLookup VALUES (3244367275)\nINSERT INTO @tblLookup VALUES (3060149565)\nINSERT INTO @tblLookup VALUES (1994146192)\nINSERT INTO @tblLookup VALUES (31158534)\nINSERT INTO @tblLookup VALUES (2563907772)\nINSERT INTO @tblLookup VALUES (4023717930)\nINSERT INTO @tblLookup VALUES (1907459465)\nINSERT INTO @tblLookup VALUES (112637215)\nINSERT INTO @tblLookup VALUES (2680153253)\nINSERT INTO @tblLookup VALUES (3904427059)\nINSERT INTO @tblLookup VALUES (2013776290)\nINSERT INTO @tblLookup VALUES (251722036)\nINSERT INTO @tblLookup VALUES (2517215374)\nINSERT INTO @tblLookup VALUES (3775830040)\nINSERT INTO @tblLookup VALUES (2137656763)\nINSERT INTO @tblLookup VALUES (141376813)\nINSERT INTO @tblLookup VALUES (2439277719)\nINSERT INTO @tblLookup VALUES (3865271297)\nINSERT INTO @tblLookup VALUES (1802195444)\nINSERT INTO @tblLookup VALUES (476864866)\nINSERT INTO @tblLookup VALUES (2238001368)\nINSERT INTO @tblLookup VALUES (4066508878)\nINSERT INTO @tblLookup VALUES (1812370925)\nINSERT INTO @tblLookup VALUES (453092731)\nINSERT INTO @tblLookup VALUES (2181625025)\nINSERT INTO @tblLookup VALUES (4111451223)\nINSERT INTO @tblLookup VALUES (1706088902)\nINSERT INTO @tblLookup VALUES (314042704)\nINSERT INTO @tblLookup VALUES (2344532202)\nINSERT INTO @tblLookup VALUES (4240017532)\nINSERT INTO @tblLookup VALUES (1658658271)\nINSERT INTO @tblLookup VALUES (366619977)\nINSERT INTO @tblLookup VALUES (2362670323)\nINSERT INTO @tblLookup VALUES (4224994405)\nINSERT INTO @tblLookup VALUES (1303535960)\nINSERT INTO @tblLookup VALUES (984961486)\nINSERT INTO @tblLookup VALUES (2747007092)\nINSERT INTO @tblLookup VALUES (3569037538)\nINSERT INTO @tblLookup VALUES (1256170817)\nINSERT INTO @tblLookup VALUES (1037604311)\nINSERT INTO @tblLookup VALUES (2765210733)\nINSERT INTO @tblLookup VALUES (3554079995)\nINSERT INTO @tblLookup VALUES (1131014506)\nINSERT INTO @tblLookup VALUES (879679996)\nINSERT INTO @tblLookup VALUES (2909243462)\nINSERT INTO @tblLookup VALUES (3663771856)\nINSERT INTO @tblLookup VALUES (1141124467)\nINSERT INTO @tblLookup VALUES (855842277)\nINSERT INTO @tblLookup VALUES (2852801631)\nINSERT INTO @tblLookup VALUES (3708648649)\nINSERT INTO @tblLookup VALUES (1342533948)\nINSERT INTO @tblLookup VALUES (654459306)\nINSERT INTO @tblLookup VALUES (3188396048)\nINSERT INTO @tblLookup VALUES (3373015174)\nINSERT INTO @tblLookup VALUES (1466479909)\nINSERT INTO @tblLookup VALUES (544179635)\nINSERT INTO @tblLookup VALUES (3110523913)\nINSERT INTO @tblLookup VALUES (3462522015)\nINSERT INTO @tblLookup VALUES (1591671054)\nINSERT INTO @tblLookup VALUES (702138776)\nINSERT INTO @tblLookup VALUES (2966460450)\nINSERT INTO @tblLookup VALUES (3352799412)\nINSERT INTO @tblLookup VALUES (1504918807)\nINSERT INTO @tblLookup VALUES (783551873)\nINSERT INTO @tblLookup VALUES (3082640443)\nINSERT INTO @tblLookup VALUES (3233442989)\nINSERT INTO @tblLookup VALUES (3988292384)\nINSERT INTO @tblLookup VALUES (2596254646)\nINSERT INTO @tblLookup VALUES (62317068)\nINSERT INTO @tblLookup VALUES (1957810842)\nINSERT INTO @tblLookup VALUES (3939845945)\nINSERT INTO @tblLookup VALUES (2647816111)\nINSERT INTO @tblLookup VALUES (81470997)\nINSERT INTO @tblLookup VALUES (1943803523)\nINSERT INTO @tblLookup VALUES (3814918930)\nINSERT INTO @tblLookup VALUES (2489596804)\nINSERT INTO @tblLookup VALUES (225274430)\nINSERT INTO @tblLookup VALUES (2053790376)\nINSERT INTO @tblLookup VALUES (3826175755)\nINSERT INTO @tblLookup VALUES (2466906013)\nINSERT INTO @tblLookup VALUES (167816743)\nINSERT INTO @tblLookup VALUES (2097651377)\nINSERT INTO @tblLookup VALUES (4027552580)\nINSERT INTO @tblLookup VALUES (2265490386)\nINSERT INTO @tblLookup VALUES (503444072)\nINSERT INTO @tblLookup VALUES (1762050814)\nINSERT INTO @tblLookup VALUES (4150417245)\nINSERT INTO @tblLookup VALUES (2154129355)\nINSERT INTO @tblLookup VALUES (426522225)\nINSERT INTO @tblLookup VALUES (1852507879)\nINSERT INTO @tblLookup VALUES (4275313526)\nINSERT INTO @tblLookup VALUES (2312317920)\nINSERT INTO @tblLookup VALUES (282753626)\nINSERT INTO @tblLookup VALUES (1742555852)\nINSERT INTO @tblLookup VALUES (4189708143)\nINSERT INTO @tblLookup VALUES (2394877945)\nINSERT INTO @tblLookup VALUES (397917763)\nINSERT INTO @tblLookup VALUES (1622183637)\nINSERT INTO @tblLookup VALUES (3604390888)\nINSERT INTO @tblLookup VALUES (2714866558)\nINSERT INTO @tblLookup VALUES (953729732)\nINSERT INTO @tblLookup VALUES (1340076626)\nINSERT INTO @tblLookup VALUES (3518719985)\nINSERT INTO @tblLookup VALUES (2797360999)\nINSERT INTO @tblLookup VALUES (1068828381)\nINSERT INTO @tblLookup VALUES (1219638859)\nINSERT INTO @tblLookup VALUES (3624741850)\nINSERT INTO @tblLookup VALUES (2936675148)\nINSERT INTO @tblLookup VALUES (906185462)\nINSERT INTO @tblLookup VALUES (1090812512)\nINSERT INTO @tblLookup VALUES (3747672003)\nINSERT INTO @tblLookup VALUES (2825379669)\nINSERT INTO @tblLookup VALUES (829329135)\nINSERT INTO @tblLookup VALUES (1181335161)\nINSERT INTO @tblLookup VALUES (3412177804)\nINSERT INTO @tblLookup VALUES (3160834842)\nINSERT INTO @tblLookup VALUES (628085408)\nINSERT INTO @tblLookup VALUES (1382605366)\nINSERT INTO @tblLookup VALUES (3423369109)\nINSERT INTO @tblLookup VALUES (3138078467)\nINSERT INTO @tblLookup VALUES (570562233)\nINSERT INTO @tblLookup VALUES (1426400815)\nINSERT INTO @tblLookup VALUES (3317316542)\nINSERT INTO @tblLookup VALUES (2998733608)\nINSERT INTO @tblLookup VALUES (733239954)\nINSERT INTO @tblLookup VALUES (1555261956)\nINSERT INTO @tblLookup VALUES (3268935591)\nINSERT INTO @tblLookup VALUES (3050360625)\nINSERT INTO @tblLookup VALUES (752459403)\nINSERT INTO @tblLookup VALUES (1541320221)\nINSERT INTO @tblLookup VALUES (2607071920)\nINSERT INTO @tblLookup VALUES (3965973030)\nINSERT INTO @tblLookup VALUES (1969922972)\nINSERT INTO @tblLookup VALUES (40735498)\nINSERT INTO @tblLookup VALUES (2617837225)\nINSERT INTO @tblLookup VALUES (3943577151)\nINSERT INTO @tblLookup VALUES (1913087877)\nINSERT INTO @tblLookup VALUES (83908371)\nINSERT INTO @tblLookup VALUES (2512341634)\nINSERT INTO @tblLookup VALUES (3803740692)\nINSERT INTO @tblLookup VALUES (2075208622)\nINSERT INTO @tblLookup VALUES (213261112)\nINSERT INTO @tblLookup VALUES (2463272603)\nINSERT INTO @tblLookup VALUES (3855990285)\nINSERT INTO @tblLookup VALUES (2094854071)\nINSERT INTO @tblLookup VALUES (198958881)\nINSERT INTO @tblLookup VALUES (2262029012)\nINSERT INTO @tblLookup VALUES (4057260610)\nINSERT INTO @tblLookup VALUES (1759359992)\nINSERT INTO @tblLookup VALUES (534414190)\nINSERT INTO @tblLookup VALUES (2176718541)\nINSERT INTO @tblLookup VALUES (4139329115)\nINSERT INTO @tblLookup VALUES (1873836001)\nINSERT INTO @tblLookup VALUES (414664567)\nINSERT INTO @tblLookup VALUES (2282248934)\nINSERT INTO @tblLookup VALUES (4279200368)\nINSERT INTO @tblLookup VALUES (1711684554)\nINSERT INTO @tblLookup VALUES (285281116)\nINSERT INTO @tblLookup VALUES (2405801727)\nINSERT INTO @tblLookup VALUES (4167216745)\nINSERT INTO @tblLookup VALUES (1634467795)\nINSERT INTO @tblLookup VALUES (376229701)\nINSERT INTO @tblLookup VALUES (2685067896)\nINSERT INTO @tblLookup VALUES (3608007406)\nINSERT INTO @tblLookup VALUES (1308918612)\nINSERT INTO @tblLookup VALUES (956543938)\nINSERT INTO @tblLookup VALUES (2808555105)\nINSERT INTO @tblLookup VALUES (3495958263)\nINSERT INTO @tblLookup VALUES (1231636301)\nINSERT INTO @tblLookup VALUES (1047427035)\nINSERT INTO @tblLookup VALUES (2932959818)\nINSERT INTO @tblLookup VALUES (3654703836)\nINSERT INTO @tblLookup VALUES (1088359270)\nINSERT INTO @tblLookup VALUES (936918000)\nINSERT INTO @tblLookup VALUES (2847714899)\nINSERT INTO @tblLookup VALUES (3736837829)\nINSERT INTO @tblLookup VALUES (1202900863)\nINSERT INTO @tblLookup VALUES (817233897)\nINSERT INTO @tblLookup VALUES (3183342108)\nINSERT INTO @tblLookup VALUES (3401237130)\nINSERT INTO @tblLookup VALUES (1404277552)\nINSERT INTO @tblLookup VALUES (615818150)\nINSERT INTO @tblLookup VALUES (3134207493)\nINSERT INTO @tblLookup VALUES (3453421203)\nINSERT INTO @tblLookup VALUES (1423857449)\nINSERT INTO @tblLookup VALUES (601450431)\nINSERT INTO @tblLookup VALUES (3009837614)\nINSERT INTO @tblLookup VALUES (3294710456)\nINSERT INTO @tblLookup VALUES (1567103746)\nINSERT INTO @tblLookup VALUES (711928724)\nINSERT INTO @tblLookup VALUES (3020668471)\nINSERT INTO @tblLookup VALUES (3272380065)\nINSERT INTO @tblLookup VALUES (1510334235)\nINSERT INTO @tblLookup VALUES (755167117)\n\nDECLARE @crc BIGINT, @len INT, @i INT, @index INT\nDECLARE @tblval BIGINT\nSET @crc = 0xFFFFFFFF\nSET @len = LEN(@input)\nSET @i = 1\n\nWHILE @i <= @len\nBEGIN\n SET @index = ((@crc & 0xff) ^ ASCII(SUBSTRING(@input, @i, 1))) \n SET @tblval = (SELECT Value FROM @tblLookup WHERE ID = @Index)\n SET @crc = (@crc / 256) ^ @tblval \n SET @i = @i + 1 \nEND\nSET @crc = ~@crc\n\nSELECT @crc as CRC32, CONVERT(VARBINARY(4), @crc) as CRC32Hex\n" }, { "answer_id": 3048282, "author": "Jim M", "author_id": 689173, "author_profile": "https://Stackoverflow.com/users/689173", "pm_score": 1, "selected": false, "text": "Declare @input as varchar(1000) \nSet @input='This is the CRC test' \nDeclare @CRCtable as varchar(3080) --Location of Edit\nDeclare @Index as int \nDeclare @crc as BIGINT \nDeclare @length as INT \nDeclare @i as INT \nDeclare @tblval as BIGINT \nDeclare @CTindex as int \nDeclare @ans as varchar(25) \n\nSet @CRCtable='0000000000, 1996959894, 3993919788, 2567524794, 0124634137, 1886057615, 3915621685, 2657392035, 0249268274, 2044508324, 3772115230, 2547177864, 0162941995, 2125561021, 3887607047, 2428444049, 0498536548, 1789927666, 4089016648, 2227061214, 0450548861, 1843258603, 4107580753, 2211677639, 0325883990, 1684777152, 4251122042, 2321926636, 0335633487, 1661365465, 4195302755, 2366115317, 0997073096, 1281953886, 3579855332, 2724688242, 1006888145, 1258607687, 3524101629, 2768942443, 0901097722, 1119000684, 3686517206, 2898065728, 0853044451, 1172266101, 3705015759, 2882616665, 0651767980, 1373503546, 3369554304, 3218104598, 0565507253, 1454621731, 3485111705, 3099436303, 0671266974, 1594198024, 3322730930, 2970347812, 0795835527, 1483230225, 3244367275, 3060149565, 1994146192, 0031158534, 2563907772, 4023717930, 1907459465, 0112637215, 2680153253, 3904427059, 2013776290, 0251722036, 2517215374, 3775830040, 2137656763, 0141376813, 2439277719, 3865271297, 1802195444, 0476864866, 2238001368, 4066508878, 1812370925, 0453092731, 2181625025, 4111451223, 1706088902, 0314042704, 2344532202, 4240017532, 1658658271, 0366619977, 2362670323, 4224994405, 1303535960, 0984961486, 2747007092, 3569037538, 1256170817, 1037604311, 2765210733, 3554079995, 1131014506, 0879679996, 2909243462, 3663771856, 1141124467, 0855842277, 2852801631, 3708648649, 1342533948, 0654459306, 3188396048, 3373015174, 1466479909, 0544179635, 3110523913, 3462522015, 1591671054, 0702138776, 2966460450, 3352799412, 1504918807, 0783551873, 3082640443, 3233442989, 3988292384, 2596254646, 0062317068, 1957810842, 3939845945, 2647816111, 0081470997, 1943803523, 3814918930, 2489596804, 0225274430, 2053790376, 3826175755, 2466906013, 0167816743, 2097651377, 4027552580, 2265490386, 0503444072, 1762050814, 4150417245, 2154129355, 0426522225, 1852507879, 4275313526, 2312317920, 0282753626, 1742555852, 4189708143, 2394877945, 0397917763, 1622183637, 3604390888, 2714866558, 0953729732, 1340076626, 3518719985, 2797360999, 1068828381, 1219638859, 3624741850, 2936675148, 0906185462, 1090812512, 3747672003, 2825379669, 0829329135, 1181335161, 3412177804, 3160834842, 0628085408, 1382605366, 3423369109, 3138078467, 0570562233, 1426400815, 3317316542, 2998733608, 0733239954, 1555261956, 3268935591, 3050360625, 0752459403, 1541320221, 2607071920, 3965973030, 1969922972, 0040735498, 2617837225, 3943577151, 1913087877, 0083908371, 2512341634, 3803740692, 2075208622, 0213261112, 2463272603, 3855990285, 2094854071, 0198958881, 2262029012, 4057260610, 1759359992, 0534414190, 2176718541, 4139329115, 1873836001, 0414664567, 2282248934, 4279200368, 1711684554, 0285281116, 2405801727, 4167216745, 1634467795, 0376229701, 2685067896, 3608007406, 1308918612, 0956543938, 2808555105, 3495958263, 1231636301, 1047427035, 2932959818, 3654703836, 1088359270, 0936918000, 2847714899, 3736837829, 1202900863, 0817233897, 3183342108, 3401237130, 1404277552, 0615818150, 3134207493, 3453421203, 1423857449, 0601450431, 3009837614, 3294710456, 1567103746, 0711928724, 3020668471, 3272380065, 1510334235, 0755167117, '\nSet @crc = 0xFFFFFFFF \nSet @length = LEN(@input) \nSet @i = 1 \n\nWhile @i <= @length \n Begin \n Set @index = ((@crc & 0xff) ^ ASCII(SUBSTRING(@input, @i, 1))) \n Set @CTindex = (@index * 12) + 1\n Set @ans=substring(@CRCtable,@CTindex,10 ) \n Set @tblval = convert(bigint,@ans) \n Set @crc = (@crc / 256) ^ @tblval \n Set @i = @i + 1 \n End \nSet @crc = ~@crc \n\nSELECT @crc as CRC32, CONVERT(VARBINARY(4), @crc) as CRC32Hex\n" }, { "answer_id": 8336025, "author": "Ken", "author_id": 1074644, "author_profile": "https://Stackoverflow.com/users/1074644", "pm_score": 1, "selected": false, "text": "CHECKSUM CHECKSUM_AGG CHECKSUM(*)" }, { "answer_id": 11043513, "author": "ErikE", "author_id": 57611, "author_profile": "https://Stackoverflow.com/users/57611", "pm_score": 3, "selected": false, "text": "DECLARE @input VARCHAR(50)\nSET @input = 'test'\n\nSET NOCOUNT ON\nDECLARE\n @crc bigint = 0xFFFFFFFF,\n @Lookup varbinary(2048) = 0x0000000077073096EE0E612C990951BA076DC419706AF48FE963A5359E6495A30EDB883279DCB8A4E0D5E91E97D2D98809B64C2B7EB17CBDE7B82D0790BF1D911DB710646AB020F2F3B9714884BE41DE1ADAD47D6DDDE4EBF4D4B55183D385C7136C9856646BA8C0FD62F97A8A65C9EC14015C4F63066CD9FA0F3D638D080DF53B6E20C84C69105ED56041E4A26771723C03E4D14B04D447D20D85FDA50AB56B35B5A8FA42B2986CDBBBC9D6ACBCF94032D86CE345DF5C75DCD60DCFABD13D5926D930AC51DE003AC8D75180BFD0611621B4F4B556B3C423CFBA9599B8BDA50F2802B89E5F058808C60CD9B2B10BE9242F6F7C8758684C11C1611DABB6662D3D76DC419001DB710698D220BCEFD5102A71B1858906B6B51F9FBFE4A5E8B8D4337807C9A20F00F9349609A88EE10E98187F6A0DBB086D3D2D91646C97E6635C016B6B51F41C6C6162856530D8F262004E6C0695ED1B01A57B8208F4C1F50FC45765B0D9C612B7E9508BBEB8EAFCB9887C62DD1DDF15DA2D498CD37CF3FBD44C654DB261583AB551CEA3BC0074D4BB30E24ADFA5413DD895D7A4D1C46DD3D6F4FB4369E96A346ED9FCAD678846DA60B8D044042D7333031DE5AA0A4C5FDD0D7CC95005713C270241AABE0B1010C90C20865768B525206F85B3B966D409CE61E49F5EDEF90E29D9C998B0D09822C7D7A8B459B33D172EB40D81B7BD5C3BC0BA6CADEDB883209ABFB3B603B6E20C74B1D29AEAD547399DD277AF04DB261573DC1683E3630B1294643B840D6D6A3E7A6A5AA8E40ECF0B9309FF9D0A00AE277D079EB1F00F93448708A3D21E01F2686906C2FEF762575D806567CB196C36716E6B06E7FED41B7689D32BE010DA7A5A67DD4ACCF9B9DF6F8EBEEFF917B7BE4360B08ED5D6D6A3E8A1D1937E38D8C2C44FDFF252D1BB67F1A6BC57673FB506DD48B2364BD80D2BDAAF0A1B4C36034AF641047A60DF60EFC3A867DF55316E8EEF4669BE79CB61B38CBC66831A256FD2A05268E236CC0C7795BB0B4703220216B95505262FC5BA3BBEB2BD0B282BB45A925CB36A04C2D7FFA7B5D0CF312CD99E8B5BDEAE1D9B64C2B0EC63F226756AA39C026D930A9C0906A9EB0E363F720767850500571395BF4A82E2B87A147BB12BAE0CB61B3892D28E9BE5D5BE0D7CDCEFB70BDBDF2186D3D2D4F1D4E24268DDB3F81FDA836E81BE16CDF6B9265B6FB077E118B7477788085AE6FF0F6A7066063BCA11010B5C8F659EFFF862AE69616BFFD3166CCF45A00AE278D70DD2EE4E0483543903B3C2A7672661D06016F74969474D3E6E77DBAED16A4AD9D65ADC40DF0B6637D83BF0A9BCAE53DEBB9EC547B2CF7F30B5FFE9BDBDF21CCABAC28A53B3933024B4A3A6BAD03605CDD7069354DE572923D967BFB3667A2EC4614AB85D681B022A6F2B94B40BBE37C30C8EA15A05DF1B2D02EF8D;\n\nSELECT @crc = (@crc / 256) ^ Substring(@Lookup, ((@crc & 0xFF) ^ Ascii(Substring(@input, V.Number, 1))) * 4 + 1, 4)\nFROM master.dbo.spt_values V\nWHERE V.type = 'P' AND V.number BETWEEN 1 AND Len(@input)\n\nSET @crc = ~@crc;\nSELECT @crc CRC32, Convert(VARBINARY(4), @crc) CRC32Hex;\n" }, { "answer_id": 17386832, "author": "Michael Erickson", "author_id": 577087, "author_profile": "https://Stackoverflow.com/users/577087", "pm_score": 2, "selected": false, "text": "CREATE FUNCTION dbo.IndexTable\n(\n @FirstIndex bigint\n , @LastIndex bigint\n)\nRETURNS @Result table\n(\n Id BIGINT PRIMARY KEY\n)\nWITH SCHEMABINDING\nAS\n/***************************************************************************************************\n DESCRIPTION:\n Create an one column table of indexes starting with first specified index and \n ending with last specified index.\n\n INPUT PARAMETERS:\n @FirstIndex: First index to start the list of indexes with.\n @LastIndex: Last index to end the list of indexes with.\n\n RETURN VALUE:\n Table with list of specified indexes.\n\n EXAMPLES:\n SELECT * FROM dbo.IndexTable(1, 20)\n SELECT * FROM dbo.IndexTable(1, 16)\n SELECT * FROM dbo.IndexTable(1, 17)\n SELECT * FROM dbo.IndexTable(1, 18)\n SELECT * FROM dbo.IndexTable(1, 1)\n SELECT * FROM dbo.IndexTable(1, 0)\n***************************************************************************************************/\nBEGIN\n DECLARE @max bigint\n , @offset bigint\n ;\n IF @LastIndex IS NULL RETURN ;\n IF @FirstIndex IS NULL RETURN ;\n INSERT INTO @Result \n VALUES (@FirstIndex+0), (@FirstIndex+1), (@FirstIndex+2), (@FirstIndex+3), (@FirstIndex+4)\n , (@FirstIndex+5), (@FirstIndex+6), (@FirstIndex+7), (@FirstIndex+8), (@FirstIndex+9)\n ;\n SELECT @max= MAX(Id) FROM @Result\n ;\n WHILE @max < @LastIndex\n BEGIN\n SET @offset = (1 + @max - @FirstIndex)\n ;\n INSERT\n INTO @Result\n SELECT Id = Id + @offset\n FROM @Result\n WHERE Id <= (@LastIndex - @offset)\n ;\n SELECT @max= MAX(Id) FROM @Result\n ;\n END\n DELETE FROM @Result WHERE Id > @LastIndex\n ;\n RETURN\nEND\nGO\n\nCREATE FUNCTION dbo.CRC32calc\n/***************************************************************************************************\n DESCRIPTION\n Add a byte value to a CRC calculation.\n\n INPUT PARAMETERS:\n @crc Current CRC value.\n @byteval Byte value to add to CRC value.\n\n RETURN VALUE:\n Resulting CRC with bytevalue added.\n\n USAGE:\n Used by functions dbo.CRC32 and dbo.NCRC32\n***************************************************************************************************/\n(\n @crc bigint,\n @byteval int\n)\nRETURNS bigint\nWITH SCHEMABINDING\nAS\nBEGIN\n DECLARE @Lookup varbinary(2048) = 0x0000000077073096EE0E612C990951BA076DC419706AF48FE963A5359E6495A30EDB883279DCB8A4E0D5E91E97D2D98809B64C2B7EB17CBDE7B82D0790BF1D911DB710646AB020F2F3B9714884BE41DE1ADAD47D6DDDE4EBF4D4B55183D385C7136C9856646BA8C0FD62F97A8A65C9EC14015C4F63066CD9FA0F3D638D080DF53B6E20C84C69105ED56041E4A26771723C03E4D14B04D447D20D85FDA50AB56B35B5A8FA42B2986CDBBBC9D6ACBCF94032D86CE345DF5C75DCD60DCFABD13D5926D930AC51DE003AC8D75180BFD0611621B4F4B556B3C423CFBA9599B8BDA50F2802B89E5F058808C60CD9B2B10BE9242F6F7C8758684C11C1611DABB6662D3D76DC419001DB710698D220BCEFD5102A71B1858906B6B51F9FBFE4A5E8B8D4337807C9A20F00F9349609A88EE10E98187F6A0DBB086D3D2D91646C97E6635C016B6B51F41C6C6162856530D8F262004E6C0695ED1B01A57B8208F4C1F50FC45765B0D9C612B7E9508BBEB8EAFCB9887C62DD1DDF15DA2D498CD37CF3FBD44C654DB261583AB551CEA3BC0074D4BB30E24ADFA5413DD895D7A4D1C46DD3D6F4FB4369E96A346ED9FCAD678846DA60B8D044042D7333031DE5AA0A4C5FDD0D7CC95005713C270241AABE0B1010C90C20865768B525206F85B3B966D409CE61E49F5EDEF90E29D9C998B0D09822C7D7A8B459B33D172EB40D81B7BD5C3BC0BA6CADEDB883209ABFB3B603B6E20C74B1D29AEAD547399DD277AF04DB261573DC1683E3630B1294643B840D6D6A3E7A6A5AA8E40ECF0B9309FF9D0A00AE277D079EB1F00F93448708A3D21E01F2686906C2FEF762575D806567CB196C36716E6B06E7FED41B7689D32BE010DA7A5A67DD4ACCF9B9DF6F8EBEEFF917B7BE4360B08ED5D6D6A3E8A1D1937E38D8C2C44FDFF252D1BB67F1A6BC57673FB506DD48B2364BD80D2BDAAF0A1B4C36034AF641047A60DF60EFC3A867DF55316E8EEF4669BE79CB61B38CBC66831A256FD2A05268E236CC0C7795BB0B4703220216B95505262FC5BA3BBEB2BD0B282BB45A925CB36A04C2D7FFA7B5D0CF312CD99E8B5BDEAE1D9B64C2B0EC63F226756AA39C026D930A9C0906A9EB0E363F720767850500571395BF4A82E2B87A147BB12BAE0CB61B3892D28E9BE5D5BE0D7CDCEFB70BDBDF2186D3D2D4F1D4E24268DDB3F81FDA836E81BE16CDF6B9265B6FB077E118B7477788085AE6FF0F6A7066063BCA11010B5C8F659EFFF862AE69616BFFD3166CCF45A00AE278D70DD2EE4E0483543903B3C2A7672661D06016F74969474D3E6E77DBAED16A4AD9D65ADC40DF0B6637D83BF0A9BCAE53DEBB9EC547B2CF7F30B5FFE9BDBDF21CCABAC28A53B3933024B4A3A6BAD03605CDD7069354DE572923D967BFB3667A2EC4614AB85D681B022A6F2B94B40BBE37C30C8EA15A05DF1B2D02EF8D\n ;\n RETURN (@crc / 256) ^ Substring(@Lookup, ((@crc & 0xFF) ^ @byteval) * 4 + 1, 4)\n ;\nEND\nGO\n\nCREATE FUNCTION dbo.CRC32\n/***************************************************************************************************\n DESCRIPTION\n Compute 32-bit CRC from an ASCII character array.\n\n INPUT PARAMETERS:\n @input ASCII text to compute CRC for.\n\n RETURN VALUE:\n Resulting 32-bit CRC value.\n\n EXAMPLES:\n SELECT t.input, csum = CHECKSUM(t.input), t.crc, crchex = CONVERT(VARBINARY(8), t.crc)\n FROM ( SELECT t.input, crc = dbo.CRC32(t.input)\n FROM ( SELECT input = 'test'\n UNION SELECT input = 'x'\n UNION SELECT input = ''\n UNION SELECT input = NULL\n UNION SELECT input = 'stop'\n UNION SELECT input = 'pots'\n UNION SELECT input = 'System.IO.Stream'\n UNION SELECT input = 'SYSTEM.IO.Stream'\n UNION SELECT input = 'Test.fqn.data'\n UNION SELECT input = 'Test.fqn.datax'\n ) AS t\n ) AS t\n***************************************************************************************************/\n(\n @input varchar(max)\n)\nRETURNS int\nWITH SCHEMABINDING\nAS\nBEGIN\n DECLARE @crc bigint = 0xFFFFFFFF\n , @result int\n ;\n SELECT @crc = dbo.CRC32calc(@crc, Ascii(Substring(@input, v.id, 1)))\n FROM dbo.IndexTable(1, LEN(@input)) AS v\n ORDER\n BY v.Id\n ;\n SET @result = CONVERT(int, CONVERT(VARBINARY(4), ~@crc)) ;\n RETURN @result ;\nEND\nGO\n\nCREATE FUNCTION dbo.NCRC32\n/***************************************************************************************************\n DESCRIPTION\n Compute 32-bit CRC from a UNICODE character array.\n\n INPUT PARAMETERS:\n @input ASCII text to compute CRC for.\n\n RETURN VALUE:\n Resulting 32-bit CRC value.\n\n EXAMPLES:\n SELECT t.input, csum = CHECKSUM(t.input), t.crc, crchex = CONVERT(VARBINARY(8), t.crc)\n FROM ( SELECT t.input, crc = dbo.NCRC32(t.input)\n FROM ( SELECT input = N'test'\n UNION SELECT input = N'x'\n UNION SELECT input = N''\n UNION SELECT input = NULL\n UNION SELECT input = 'stop'\n UNION SELECT input = 'pots'\n UNION SELECT input = N'System.IO.Stream'\n UNION SELECT input = N'SYSTEM.IO.Stream'\n UNION SELECT input = N'Test.fqn.data'\n UNION SELECT input = N'Test.fqn.datax'\n ) AS t\n ) AS t\n***************************************************************************************************/\n(\n @input nvarchar(max)\n)\nRETURNS int\nWITH SCHEMABINDING\nAS\nBEGIN\n DECLARE @crc bigint = 0xFFFFFFFF\n , @result int\n ;\n SELECT @crc = dbo.CRC32calc( dbo.CRC32calc(@crc, (cval / 256)), cval & 0xFF)\n FROM ( SELECT v.id, cval = UNICODE(SUBSTRING(@input, v.id, 1))\n FROM dbo.IndexTable(1, LEN(@input)) AS v\n ) AS t\n ORDER\n BY t.Id\n ;\n SET @result = CONVERT(int, CONVERT(VARBINARY(4), ~@crc)) ;\n RETURN @result ;\nEND\nGO\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331157", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3153/" ]
331,185
<p>I have a div tag in the view that I'd like to update with a graph that I generate via Gruff.</p> <p>I have the following controller action which does this at the end</p> <pre><code>send_data g.to_blob, :disposition=&gt;'inline', :type=&gt;'image/png', :filename=&gt;'top_n.pdf' </code></pre> <p>Now if I directly invoke this action, I can see the graph. (More details <a href="http://madcoderspeak.blogspot.com/2008/12/graphs-in-ruby-on-rails.html" rel="nofollow noreferrer">here</a> if reqd.)</p> <p>If I add a <code>link_to_remote_tag</code> that calls the above action via AJAX passing in specific input, generates this graph and tries to update a placeholder div tag... I see gibberish. </p> <p>I think I can write the graph to a png file with <code>g.write(filename.png)</code> how do I embed the graph within the div tag in the view at run-time?</p>
[ { "answer_id": 331565, "author": "ARemesal", "author_id": 36599, "author_profile": "https://Stackoverflow.com/users/36599", "pm_score": 2, "selected": true, "text": ":complete => \"updateImg(id_of_div, request.responseText)\"\n function updateImg(id, img)\n{\n $(id).innerHTML = '<img src=\"' + img + '\" />';\n}\n" }, { "answer_id": 331614, "author": "Stein G. Strindhaug", "author_id": 26115, "author_profile": "https://Stackoverflow.com/users/26115", "pm_score": 0, "selected": false, "text": "img def graph\n # get the relevant data for 'g' here\n respond_to do |format|\n format.html #uses the default view if relevant (good for debugging)\n format.png do \n send_data g.to_blob, \n :disposition=>'inline', \n :type=>'image/png', \n :filename=>'top_n.pdf' \n end\n end\nend\n <img src=\"controller/graph.png\" alt=\"Something\"/>\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331185", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1695/" ]
331,205
<p>I'm creating a KVC/KVO-compliant mutable array on one of my objects the recommended way:</p> <pre><code>@interface Factory { NSMutableArray *widgets; } - (NSArray *)widgets; - (void)insertObject:(id)obj inWidgetsAtIndex:(NSUInteger)idx; - (void)removeObjectFromWidgetsAtIndex:(NSUInteger)idx; @end </code></pre> <p>Clearly this is a tricky thread-safety issue. In the <code>insert</code> and <code>remove</code> methods I'm locking around array access to prevent concurrent modification, as <a href="http://developer.apple.com/documentation/Cocoa/Conceptual/Multithreading/ThreadSafetySummary/chapter_950_section_2.html#//apple_ref/doc/uid/20000736-126010" rel="nofollow noreferrer">recommended</a>.</p> <p>My question is, what is the proper way to implement the <code>widgets</code> accessor? Here's my implementation:</p> <pre><code>- (NSArray *)widgets { [widgetLock lock]; NSArray *a = [[widgets copy] autorelease]; [widgetLock unlock]; return a; } </code></pre> <p>Is it threadsafe?</p>
[ { "answer_id": 332294, "author": "Alex", "author_id": 35999, "author_profile": "https://Stackoverflow.com/users/35999", "pm_score": 3, "selected": true, "text": "widgets [[[myFactory widgets] objectAtIndex:7] setName:@\"mildred\"];\n [myTextField setStringValue:[[[myFactory widgets] objectAtIndex:7] name]]; // mildred? or something else?\n objectInWidgetsAtIndex: countOfWidgets widgets [myFactory mutableArrayValueForKey:@\"widgets\"] widgets" }, { "answer_id": 332516, "author": "Matt Gallagher", "author_id": 36103, "author_profile": "https://Stackoverflow.com/users/36103", "pm_score": 2, "selected": false, "text": "- (NSArray *)widgets {\n @synchronized(widgets)\n {\n NSArray *a = [[widgets copy] autorelease];\n return a;\n }\n}\n widgets widgets @synchronized" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331205", "https://Stackoverflow.com", "https://Stackoverflow.com/users/79/" ]
331,215
<p>I am trying to unit test my WPF databindings using the test suit provided by Microsoft Team System. I would like to be able to test the bindings without showing the window because most of my tests will be for user controls and not actually on a window. Is this possible or is there a better way to do it? The code below works if I show the window, but if I don't, the bindings don't update. </p> <pre><code> Window1_Accessor target = new Window1_Accessor(); UnitTestingWPF.Window1_Accessor.Person p = new UnitTestingWPF.Window1_Accessor.Person() { FirstName = "Shane" }; Window1 window = (target.Target as Window1); window.DataContext = p; //window.Show(); //Only Works when I actually show the window //Is it possible to manually update the binding here, maybe? Is there a better way? Assert.AreEqual("Shane", target.textBoxFirstName.Text); //Fails if I don't Show() the window because the bindings aren't updated </code></pre>
[ { "answer_id": 331654, "author": "Gishu", "author_id": 1695, "author_profile": "https://Stackoverflow.com/users/1695", "pm_score": 2, "selected": false, "text": "Assert.AreEqual(\"FirstName\", txtBoxToProbe.GetBindingExpression(TextBox.TextProperty).ParentBinding.Path.Path);\n [Test]\npublic void TestTextBoxBinding()\n{\n MyWindow w = new MyWindow();\n TextBox txtBoxToProbe = w.TextBox1;\n Object obDataSource = w; // use 'real' data source \n\n BindingExpression bindingExpr = BindingOperations.GetBindingExpression(txtBoxToProbe, TextBox.TextProperty);\n Binding newBind = new Binding(bindingExpr.ParentBinding.Path.Path);\n newBind.Source = obDataSource;\n txtBoxToProbe.SetBinding(TextBox.TextProperty, newBind);\n\n Assert.AreEqual(\"Go ahead. Change my value.\", txtBoxToProbe.Text);\n} \n Window.Show() // before show\nbindingExpr.DataItem => null\nbindingExpr.Status => BindingStatus.Unattached\n\n// after show\nbindingExpr.DataItem => {Actual Data Source}\nbindingExpr.Status => BindingStatus.Active\n txtBoxToProbe.GetBindingExpression(TextBox.TextProperty).UpdateTarget();\n" }, { "answer_id": 4100340, "author": "treze", "author_id": 383243, "author_profile": "https://Stackoverflow.com/users/383243", "pm_score": 0, "selected": false, "text": " [TestMethod]\n public void SimpleTest()\n {\n var viewModel = new SimpleControlViewModel() {TextBoxText = \"Some Text\"};\n\n customControl = CustomControl.Start<SimpleUserControl>((control) => control.DataContext = viewModel);\n\n Assert.AreEqual(\"Some Text\", customControl.Get<TextBox>(\"textbox1\").Value);\n\n customControl.Stop();\n }\n" }, { "answer_id": 11467551, "author": "chillitom", "author_id": 56679, "author_profile": "https://Stackoverflow.com/users/56679", "pm_score": 1, "selected": false, "text": "public static class WpfBindingTester\n{\n /// <summary>load a view in a hidden window and monitor it for binding errors</summary>\n /// <param name=\"view\">a data-bound view to load and monitor for binding errors</param>\n public static void AssertBindings(object view)\n {\n using (InternalTraceListener listener = new InternalTraceListener())\n {\n ManualResetEventSlim mre = new ManualResetEventSlim(false);\n\n Window window = new Window\n {\n Width = 0,\n Height = 0,\n WindowStyle = WindowStyle.None,\n ShowInTaskbar = false,\n ShowActivated = false,\n Content = view\n };\n\n window.Loaded += (_, __) => mre.Set();\n window.Show();\n\n mre.Wait();\n\n window.Close();\n\n Assert.That(listener.ErrorMessages, Is.Empty, listener.ErrorMessages);\n }\n }\n\n /// <summary>Is the test running in an interactive session. Use with Assume.That(WpfBindingTester.IsAvailable) to make sure tests only run where they're able to</summary>\n public static bool IsAvailable { get { return Environment.UserInteractive && Process.GetCurrentProcess().SessionId != 0; } }\n\n\n private class InternalTraceListener : TraceListener\n {\n private readonly StringBuilder _errors = new StringBuilder();\n private readonly SourceLevels _originalLevel;\n public string ErrorMessages { get { return _errors.ToString(); } }\n\n static InternalTraceListener() { PresentationTraceSources.Refresh(); }\n\n public InternalTraceListener()\n {\n _originalLevel = PresentationTraceSources.DataBindingSource.Switch.Level;\n PresentationTraceSources.DataBindingSource.Switch.Level = SourceLevels.Error;\n PresentationTraceSources.DataBindingSource.Listeners.Add(this);\n }\n\n public override void Write(string message) {}\n\n public override void WriteLine(string message) { _errors.AppendLine(message); }\n\n protected override void Dispose(bool disposing)\n {\n PresentationTraceSources.DataBindingSource.Listeners.Remove(this);\n PresentationTraceSources.DataBindingSource.Switch.Level = _originalLevel;\n base.Dispose(disposing);\n }\n }\n}\n" }, { "answer_id": 19610515, "author": "Benoit Blanchon", "author_id": 1164966, "author_profile": "https://Stackoverflow.com/users/1164966", "pm_score": 3, "selected": false, "text": "TraceListener PresentationTraceSources.DataBindingSource" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331215", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3291/" ]
331,224
<p>So my question is if I can somehow send data to my program and then send the same data AND its result to another program without having to create a temporary file (in my case ouputdata.txt). Preferably using linux pipes/bash.</p> <p>I currently do the following:</p> <p>cat inputdata.txt | ./MyProg > outputdata.txt</p> <p>cat inputdata.txt outputdata.txt | ./MyProg2</p>
[ { "answer_id": 331246, "author": "S.Lott", "author_id": 10661, "author_profile": "https://Stackoverflow.com/users/10661", "pm_score": 5, "selected": true, "text": "MyProg ./MyProg <inputdata.txt | ./MyProg2\n MyProg ./MyProg <inputdata.txt | cat inputdata.txt - | ./MyProg2\n" }, { "answer_id": 331298, "author": "derobert", "author_id": 27727, "author_profile": "https://Stackoverflow.com/users/27727", "pm_score": 5, "selected": false, "text": "( Prog1; Prog2; Prog3; ... ) | ProgN\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331224", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17500/" ]
331,231
<p>When I click on a row in my GridView, I want to go to a other page with the ID I get from the database. </p> <p>In my RowCreated event I have the following line:</p> <pre><code>e.Row.Attributes.Add( "onClick", ClientScript.GetPostBackClientHyperlink( this.grdSearchResults, "Select$" + e.Row.RowIndex)); </code></pre> <p>To prevent error messages i have this code:</p> <pre><code>protected override void Render(HtmlTextWriter writer) { // .NET will refuse to accept "unknown" postbacks for security reasons. // Because of this we have to register all possible callbacks // This must be done in Render, hence the override for (int i = 0; i &lt; grdSearchResults.Rows.Count; i++) { Page.ClientScript.RegisterForEventValidation( new System.Web.UI.PostBackOptions( grdSearchResults, "Select$" + i.ToString())); } // Do the standard rendering stuff base.Render(writer); } </code></pre> <p>How can I give a row a unique ID (from the DB) and when I click the row, another page is opened (like clicking on a href) and that page can read the ID.</p>
[ { "answer_id": 331662, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 5, "selected": true, "text": "if(e.Row.RowType == DataControlRowType.DataRow)\n{\n e.Row.Attributes[\"onClick\"] = \"location.href='view.aspx?id=\" + DataBinder.Eval(e.Row.DataItem, \"id\") + \"'\";\n}\n" }, { "answer_id": 546787, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": " protected void gvSearch_RowDataBound(object sender, GridViewRowEventArgs e)\n {\n if (e.Row.RowType == DataControlRowType.DataRow)\n {\n string abc = ((GridView)sender).DataKeys[e.Row.RowIndex].Value.ToString();\n e.Row.Attributes[\"onClick\"] = \"location.href='Default.aspx?id=\" + abc + \"'\";\n }\n }\n" }, { "answer_id": 546793, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "protected void gvSearch_RowDataBound(object sender, GridViewRowEventArgs e)\n{\n if (e.Row.RowType == DataControlRowType.DataRow)\n {\n string abc = ((GridView)sender).DataKeys[e.Row.RowIndex].Value.ToString();\n e.Row.Attributes[\"onClick\"] = \"location.href='Default.aspx?id=\" + abc + \"'\"; \n }\n}\n" }, { "answer_id": 2582351, "author": "JohnB", "author_id": 287311, "author_profile": "https://Stackoverflow.com/users/287311", "pm_score": 4, "selected": false, "text": "protected void gvSearch_RowDataBound(object sender, GridViewRowEventArgs e)\n{\n if (e.Row.RowType == DataControlRowType.DataRow)\n {\n e.Row.Attributes.Add(\"onmouseover\", \"this.style.backgroundColor='#ceedfc'\");\n e.Row.Attributes.Add(\"onmouseout\", \"this.style.backgroundColor=''\");\n e.Row.Attributes.Add(\"style\", \"cursor:pointer;\");\n e.Row.Attributes.Add(\"onclick\", \"location='patron_detail.aspx?id=\" + e.Row.Cells[0].Text + \"'\");\n }\n} <asp:GridView ID=\"gvSearch\" runat=\"server\" OnRowDataBound=\"gvSearch_RowDataBound\" AutoGenerateColumns=\"false\">\n <Columns>\n <asp:BoundField DataField=\"id\" Visible=\"false\" />\n <asp:BoundField DataField=\"first_name\" HeaderText=\"First\" />\n <asp:BoundField DataField=\"last_name\" HeaderText=\"Last\" />\n <asp:BoundField DataField=\"email\" HeaderText=\"Email\" />\n <asp:BoundField DataField=\"state_name\" HeaderText=\"State\" />\n </Columns>\n</asp:GridView> <asp:BoundField DataField=\"id\" ItemStyle-CssClass=\"hide\" /> <head>\n <style type=\"text/css\">\n .hide{\n display:none;\n }\n </style>\n<head> if (e.Row.RowType == DataControlRowType.Header)\n{\n e.Row.Cells[0].CssClass = \"hide\";\n} e.Row.Cells[0].Attributes.Add(\"style\", \"display:none;\");\ne.Row.Attributes.Add(\"style\", \"cursor:pointer;\");" }, { "answer_id": 3195491, "author": "mohan", "author_id": 385610, "author_profile": "https://Stackoverflow.com/users/385610", "pm_score": 1, "selected": false, "text": "protected void gvSearch_RowDataBound(object sender, GridViewRowEventArgs e) \n{ \n if (e.Row.RowType == DataControlRowType.DataRow) \n { \n string abc = ((GridView)sender).DataKeys[e.Row.RowIndex].Value.ToString(); \n e.Row.Attributes[\"onClick\"] = \"location.href='Default.aspx?id=\" + abc + \"'\"; \n } \n} \n" }, { "answer_id": 5178343, "author": "sh4", "author_id": 386930, "author_profile": "https://Stackoverflow.com/users/386930", "pm_score": 0, "selected": false, "text": "e.Row.Attributes.Add(\"onmouseout\", \"this.style.backgroundColor=''\");\n e.Row.Attributes.Add(\"onmouseout\", \"if(\" + e.Row.RowIndex + \"% 2 == 0) { this.style.backgroundColor=''; } else { this.style.backgroundColor = '#E8F7EA'; }\");\n" }, { "answer_id": 6355841, "author": "Jyoti Nagda", "author_id": 799320, "author_profile": "https://Stackoverflow.com/users/799320", "pm_score": 1, "selected": false, "text": "protected void gvSearch_RowDataBound(object sender, GridViewRowEventArgs e) \n{ \n if (e.Row.RowType == DataControlRowType.DataRow)\n {\n GridViewRow gvr = e.Row;\n string abc = ((GridView)sender).DataKeys[e.Row.RowIndex].Value.ToString(); \n gvr.Attributes.Add(\"OnClick\", \"javascript:location.href='Default.aspx?id=\" + abc + \"'\");\n } \n\n } \n} \n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331231", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40676/" ]
331,240
<p>I have a problem with classic ASP. The encoding is wrong when I send data with <code>XMLHttp.send</code>. The response is a PDF file, but the “ÆØÅ” gets wrong, the “Ø” is read as “øy” for example. It’s like it’s a converting mistake from UTF-8 to ISO-8859-1, but it should be ISO-8859-1 now. I have <code>&lt;%@CODEPAGE="28591"%&gt;</code> at the top at the page and <code>ISO-8859-1</code> as encoding in the XML file, I have checked the file so it’s valid ISO-8859-1. I don’t have access to the server I am sending this data to, but I fixed it in a VB6 program which use the same logic with:</p> <pre><code>aPostBody = StrConv(strBody, vbFromUnicode) WinHttpReq.SetTimeouts 100000, 100000, 100000, 1000000 WinHttpReq.Send aPostBody </code></pre> <p>And in a C# program that also uses the same logic with</p> <pre><code>// ISO-8859-1 byte[] bytes = Encoding.GetEncoding(28591).GetBytes(data); </code></pre> <p>But in ASP classic I need some help to find a way to change the encoding on a string to ISO-8859-1.</p>
[ { "answer_id": 331275, "author": "D'Arcy Rittich", "author_id": 39430, "author_profile": "https://Stackoverflow.com/users/39430", "pm_score": 2, "selected": false, "text": "Session.CodePage = 28591\n" }, { "answer_id": 331391, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "<% Response.Charset=\"ISO-8859-1\"%>\n" }, { "answer_id": 332396, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "meta Response.Write(\"<meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-1' />\")\n Response.Write" }, { "answer_id": 333694, "author": "Eduardo Molteni", "author_id": 2385, "author_profile": "https://Stackoverflow.com/users/2385", "pm_score": 2, "selected": false, "text": "#include" }, { "answer_id": 32461678, "author": "Dorathoto", "author_id": 3241689, "author_profile": "https://Stackoverflow.com/users/3241689", "pm_score": 0, "selected": false, "text": "Response.AddHeader \"Content-Type\", \"text/html;charset=UTF-8\"\nResponse.CodePage = 65001\nResponse.CharSet = \"UTF-8\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331240", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
331,254
<p>I want to pixelate and/or blur an image. I've found the command for the blurring:</p> <pre><code>$convert image.jpg -blur 18,5 newimage.jpg </code></pre> <p>to work but I cannot blur the image any more. And how do I pixelate the image? I couldn't find a sound example around the net.</p> <p>Thx</p>
[ { "answer_id": 331294, "author": "Colin Pickard", "author_id": 12744, "author_profile": "https://Stackoverflow.com/users/12744", "pm_score": 4, "selected": true, "text": "convert -resize 10% image.jpg newimage.jpg\nconvert -resize 1000% newimage.jpg newimage.jpg\n" }, { "answer_id": 506662, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 6, "selected": false, "text": "convert -scale 10% -scale 1000% original.jpg pixelated.jpg\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331254", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42153/" ]
331,262
<p>In the past I have needed to create custom SOAP headers in a C# project that was using an imported WSDL web reference. I found a way to do it but I was never happy with it and I have sense wondered if there was a better way. What I did was create a header that derives from SoapHeader:</p> <pre><code>[System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://model.test.net")] [System.Xml.Serialization.XmlRootAttribute("securitytoken", Namespace = "http://model.test.net", IsNullable = false)] public class SpecialHeader : SoapHeader { [System.Xml.Serialization.XmlTextAttribute()] public string aheadervalue; } </code></pre> <p>I then had to modify the code that was generated from the WSDL and add a referen ce to an instance of the new header and the following before each web call that I wanted to contain the custom header:</p> <pre><code>[System.Web.Services.Protocols.SoapHeaderAttribute("instancename", Direction=System.Web.Services.Protocols.SoapHeaderDirection.InOut)] </code></pre> <p>Where "instancename" is the custom header's instance variable name in the generated class.</p> <p>This works fine except that any change in the WSDL requires that it all be done over again since it regenerates the class. In other languages the headers can be added outside of the generated code so maybe I'm missing the way that is done in C#. Are there better ways of doing this?</p>
[ { "answer_id": 6531621, "author": "vardars", "author_id": 394624, "author_profile": "https://Stackoverflow.com/users/394624", "pm_score": 2, "selected": false, "text": "public partial class SampleService\n{\n public string MessageID { get; set; }\n\n protected override System.Xml.XmlWriter GetWriterForMessage(System.Web.Services.Protocols.SoapClientMessage message, int bufferSize)\n {\n message.Headers.Add(new UsernameSoapHeader(\"Username\"));\n message.Headers.Add(new PasswordSoapHeader(\"Password\"));\n message.Headers.Add(new MessageIDSoapHeader(MessageID));\n return base.GetWriterForMessage(message, bufferSize);\n }\n}\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331262", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25343/" ]
331,265
<p>How do I perform a join between two DataTables in a Dataset?</p> <p>I created a DataRelation between two tables….then what?</p> <p>I'm looking at one explanation on how to do it (<a href="http://www.emmet-gray.com/Articles/DataTableJoins.htm" rel="nofollow noreferrer">http://www.emmet-gray.com/Articles/DataTableJoins.htm</a>) which involves copying rows from tables to a result table? </p> <p>Is there a better way to do this?</p>
[ { "answer_id": 331920, "author": "Rohan West", "author_id": 38686, "author_profile": "https://Stackoverflow.com/users/38686", "pm_score": 2, "selected": false, "text": "DataTable person = new DataTable();\nperson.Columns.Add(\"Id\");\nperson.Columns.Add(\"Name\");\n\nDataTable pet = new DataTable();\npet.Columns.Add(\"Id\");\npet.Columns.Add(\"Name\");\npet.Columns.Add(\"OwnerId\");\n\nDataSet ds = new DataSet();\nds.Tables.AddRange(new[] { person, pet });\n\nds.Relations.Add(\"PersonPet\",person.Columns[\"Id\"], pet.Columns[\"OwnerId\"]);\n\nDataRow p = person.NewRow();\np[\"Id\"] = 1;\np[\"Name\"] = \"Peter\";\nperson.Rows.Add(p);\n\np = person.NewRow();\np[\"Id\"] = 2;\np[\"Name\"] = \"Alex\";\nperson.Rows.Add(p);\n\np = pet.NewRow();\np[\"Id\"] = 1;\np[\"Name\"] = \"Dog\";\np[\"OwnerId\"] = 1;\npet.Rows.Add(p);\n\np = pet.NewRow();\np[\"Id\"] = 2;\np[\"Name\"] = \"Cat\";\np[\"OwnerId\"] = 2;\npet.Rows.Add(p);\n\n\nforeach (DataRow personRow in person.Rows)\n{\n Console.WriteLine(\"{0} - {1}\",personRow[\"Id\"], personRow[\"Name\"]);\n foreach (DataRow petRow in personRow.GetChildRows(\"PersonPet\"))\n {\n Console.WriteLine(\"{0} - {1}\", petRow[\"Id\"], petRow[\"Name\"]);\n }\n}\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331265", "https://Stackoverflow.com", "https://Stackoverflow.com/users/37759/" ]
331,271
<p>I have a piece of code in ANSI C which uses the time.h library and time_h structures to (amongst other date-related calculations) work out the interval between two given dates. This works fine but this limits my code to input between 1970 and 2038. I would now like to make my code more general.</p> <p>Is there a common C library (ANSI or C99 standard) which implements date calculations on ranges larger than time.h, on a granularity of 1 day (i.e. I need to-the-day resolution but hour resolution is not necessary)?</p> <p>(I'm adapting the code to deal with historical events hence it would be nice if it could also deal with dates in B.C. ....)</p>
[ { "answer_id": 418798, "author": "Schwern", "author_id": 14660, "author_profile": "https://Stackoverflow.com/users/14660", "pm_score": 3, "selected": true, "text": "gmtime() localtime() mktime() gmtime()" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331271", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22654/" ]
331,273
<p>Is it possible to deploy a WPF windows application in such a way that the xaml files can be manipulated at run-time? If possible, I would imagine this would work similar to an asp.net application that can deploy the .aspx pages as content, which are then compiled just-in-time at run-time.</p> <p>I'd like to allow the simple layout of a screen to be edited at run-time by editing the XAML. Does anyone know if this is possible?</p> <p><strong>Edit:</strong> When I refer to xaml files, I mean the corresponding xaml to my UIElement classes. In other words, I have defined UserControl classes using Xaml and code-behind, inheritance, event handlers, assembly references, etc. When deployment time comes, I'd like to be able to keep the code-behind functionality but still allow the xaml to be edited.</p>
[ { "answer_id": 331471, "author": "Jobi Joy", "author_id": 8091, "author_profile": "https://Stackoverflow.com/users/8091", "pm_score": 0, "selected": false, "text": "UIElement documentRoot = (UIElement)System.Windows.Markup.XamlReader.Load(xmlReader);\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331273", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1300/" ]
331,276
<p>The callstack shows the following:</p> <pre><code>[MissingMethodException: No parameterless constructor defined for this object.] System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean&amp; canBeCached, RuntimeMethodHandle&amp; ctor, Boolean&amp; bNeedSecurityCheck) +0 System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache) +86 System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache) +230 System.Activator.CreateInstance(Type type, Boolean nonPublic) +67 System.Activator.CreateInstance(Type type) +6 System.Web.Mvc.DefaultModelBinder.CreateModel(ModelBindingContext bindingContext, Type modelType) +277 System.Web.Mvc.&lt;&gt;c__DisplayClass1.&lt;BindModel&gt;b__0() +98 System.Web.Mvc.ModelBindingContext.get_Model() +51 System.Web.Mvc.DefaultModelBinder.BindModelCore(ModelBindingContext bindingContext) +2600 System.Web.Mvc.DefaultModelBinder.BindModel(ModelBindingContext bindingContext) +1067 System.Web.Mvc.DefaultModelBinder.BindProperty(ModelBindingContext parentContext, Type propertyType, Func`1 propertyValueProvider, String propertyName) +208 System.Web.Mvc.DefaultModelBinder.BindModelCore(ModelBindingContext bindingContext) +1787 System.Web.Mvc.DefaultModelBinder.BindModel(ModelBindingContext bindingContext) +1067 System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ParameterInfo parameterInfo) +355 System.Web.Mvc.ControllerActionInvoker.GetParameterValues(MethodInfo methodInfo) +439 System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +288 System.Web.Mvc.Controller.ExecuteCore() +180 System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +96 System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +36 System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) +377 System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +71 System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) +36 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +75 </code></pre> <p>I have a tiny form with a bunch of hidden fields and one submit button. When I press it, I never even hit the requested method.</p> <p>How do I go on and debug this? It would be a great start if I knew WHAT object didn't have a parameterless constructor. Where is this object? How can I solve this? I know the question is rather vague, but currently it's all I've got..</p> <p><strong>--EDIT--</strong><br> In my form I added Html.Hidden() inputs. Depending on previous actions, these can have a value of "". The action makes use of ModelBinding. Whenever the value is "" and the datatype is a SelectList, the modelbinder goes berzerk on me.</p> <p>I feel more and more uncomfortable with how the SelectList is doing it's thing... The idea is good, but there are some issues with it.</p>
[ { "answer_id": 1329974, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "\n[Bind(Exclude = \"Countries\")]\npublic class MyViewModel \n{\n ... \n\npublic SelectList Countries { get; set; }\n\n\n public SelectList Countries { get; set; }\n }\n" }, { "answer_id": 8086303, "author": "jbierling", "author_id": 356395, "author_profile": "https://Stackoverflow.com/users/356395", "pm_score": 0, "selected": false, "text": "<%: Html.DropDownListFor(m => Model.Destinations, Model.Destinations)%>\n <%: Html.DropDownListFor(m => Model.Destination, Model.Destinations)%>\n" }, { "answer_id": 15296477, "author": "Josh Mouch", "author_id": 127175, "author_profile": "https://Stackoverflow.com/users/127175", "pm_score": 3, "selected": false, "text": "public class MyDefaultModelBinder : System.Web.Mvc.DefaultModelBinder\n{\n protected override object CreateModel(System.Web.Mvc.ControllerContext controllerContext, System.Web.Mvc.ModelBindingContext bindingContext, Type modelType)\n {\n return base.CreateModel(controllerContext, bindingContext, modelType);\n }\n}\n public class MvcApplication : System.Web.HttpApplication\n{\n...\n protected void Application_Start(object sender, EventArgs e)\n {\n ModelBinders.Binders.DefaultBinder = new MyDefaultModelBinder();\n }\n}\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331276", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11333/" ]
331,277
<p>Doing a refresh after certain action in asp.net seems to make them happen again even when that action doesn't make sense (think double delete). The web way to deal with this situation is to redirect after a post to get a clean version of the page that can be refreshed without reposting an action to the webserver. How can I do this with ASP.NET</p>
[ { "answer_id": 331338, "author": "Cristian Libardo", "author_id": 16526, "author_profile": "https://Stackoverflow.com/users/16526", "pm_score": 3, "selected": false, "text": "// the post handling logic, e.g. the click event code\nResponse.Redirect(Request.RawUrl);\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331277", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4491/" ]
331,278
<p>I've got some directories that have been moved or renamed. The Linux command line SVN client ignores these directories. The TortoiseSVN plugin for Explorer shows them. If I delete them and update, they come back.</p> <p>All of the file movement and deletion has been done using the Linux SVN CLI tools. When doing an 'svn update' or even a fresh 'svn co' on a Linux system, these empty directories are not shown.</p> <p>When doing a fresh checkout using TortoiseSVN, the empty directories are created, even though they don't exist in the HEAD revision anymore. </p> <p>How can I make them go away?</p>
[ { "answer_id": 331338, "author": "Cristian Libardo", "author_id": 16526, "author_profile": "https://Stackoverflow.com/users/16526", "pm_score": 3, "selected": false, "text": "// the post handling logic, e.g. the click event code\nResponse.Redirect(Request.RawUrl);\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331278", "https://Stackoverflow.com", "https://Stackoverflow.com/users/39933/" ]
331,279
<p>I've found a answer how to remove diacritic characters on stackoverflow, but could you please tell me if it is possible to change diacritic characters to non-diacritic ones?</p> <p>Oh.. and I think about .NET (or other if not possible)</p>
[ { "answer_id": 420613, "author": "Chris James", "author_id": 3193, "author_profile": "https://Stackoverflow.com/users/3193", "pm_score": 2, "selected": false, "text": "string newString = myDiacriticsString.Normalize(NormalizationForm.FormD);\n" }, { "answer_id": 3314310, "author": "dan", "author_id": 197605, "author_profile": "https://Stackoverflow.com/users/197605", "pm_score": 5, "selected": false, "text": " // \\p{Mn} or \\p{Non_Spacing_Mark}: \n // a character intended to be combined with another \n // character without taking up extra space \n // (e.g. accents, umlauts, etc.). \n private readonly static Regex nonSpacingMarkRegex = \n new Regex(@\"\\p{Mn}\", RegexOptions.Compiled);\n\n public static string RemoveDiacritics(string text)\n {\n if (text == null)\n return string.Empty;\n\n var normalizedText = \n text.Normalize(NormalizationForm.FormD);\n\n return nonSpacingMarkRegex.Replace(normalizedText, string.Empty);\n }\n" }, { "answer_id": 8885159, "author": "happytrails", "author_id": 1151096, "author_profile": "https://Stackoverflow.com/users/1151096", "pm_score": 0, "selected": false, "text": " using System.Text;\n using System.Text.RegularExpressions;\n\n internal static string SanitizeString(string source)\n {\n return Regex.Replace(source.Normalize(NormalizationForm.FormD), @\"[^A-Za-z 0-9 \\.,\\?'\"\"!@#\\$%\\^&\\*\\(\\)-_=\\+;:<>\\/\\\\\\|\\}\\{\\[\\]`~]*\", string.Empty).Trim(); \n }\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331279", "https://Stackoverflow.com", "https://Stackoverflow.com/users/38940/" ]
331,287
<p>Try to commit my first iPhone application to Subversion found that there's "code signing identity" section in my xcode project.pbxproj file.</p> <pre><code>CODE_SIGN_IDENTITY = "iPhone Developer: my username here...; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: above..."; </code></pre> <p>The issue is, in our team we use different provisioning which bound to our device. So when other want to run the code on device, they have to change this line. We can share one provisioning to across this, but that way have several downside. Is there any other way to solve it? i.e. include code signing section to another file which not commit to SVN?</p>
[ { "answer_id": 333168, "author": "Chris Hanson", "author_id": 714, "author_profile": "https://Stackoverflow.com/users/714", "pm_score": 1, "selected": false, "text": "$(USER) CODE_SIGN_IDENTITY = \"iPhone Developer: $(USER)\";\n USER CODE_SIGN_IDENTITY" }, { "answer_id": 333177, "author": "Chris Hanson", "author_id": 714, "author_profile": "https://Stackoverflow.com/users/714", "pm_score": 4, "selected": false, "text": "xcconfig xcconfig DeveloperSettings.xcconfig CODE_SIGN_IDENTITY = \"iPhone Developer: favoyang\"\n CODE_SIGN_IDENTITY = \"iPhone Developer: cmh\"\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331287", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42170/" ]
331,295
<p>What is the Worst Case Time Complexity t(n) :- I'm reading this book about algorithms and as an example how to get the T(n) for .... like the selection Sort Algorithm</p> <hr> <p>Like if I'm dealing with the selectionSort(A[0..n-1])</p> <pre><code>//sorts a given array by selection sort //input: An array A[0..n - 1] of orderable elements. //output: Array A[0..n-1] sorted in ascending order </code></pre> <p>let me write a pseudocode</p> <pre><code>for i &lt;----0 to n-2 do min&lt;--i for j&lt;--i+1 to n-1 do ifA[j]&lt;A[min] min &lt;--j swap A[i] and A[min] </code></pre> <p>--------I will write it in C# too---------------</p> <pre><code>private int[] a = new int[100]; // number of elements in array private int x; // Selection Sort Algorithm public void sortArray() { int i, j; int min, temp; for( i = 0; i &lt; x-1; i++ ) { min = i; for( j = i+1; j &lt; x; j++ ) { if( a[j] &lt; a[min] ) { min = j; } } temp = a[i]; a[i] = a[min]; a[min] = temp; } } </code></pre> <p>==================</p> <p>Now how to get the t(n) or as its known the worst case time complexity</p>
[ { "answer_id": 331463, "author": "Gavin Miller", "author_id": 33226, "author_profile": "https://Stackoverflow.com/users/33226", "pm_score": 2, "selected": true, "text": "for(j=0 ; j<n ; j++)\n{\n //... \n}\n if(STudID == A[j]) \n return true;\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331295", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
331,297
<p>Calling through to my Silverlight Enabled WCF-Service in my silverlight application, occasionally users get timeouts. Whats the easiest way to boost the time allowed by the service client for a response?</p> <p>The exact exception thrown is: System.TimeoutException: [HttpRequestTimedOutWithoutDetail]</p> <p>Thanks</p>
[ { "answer_id": 2481876, "author": "Rick Arthur", "author_id": 224531, "author_profile": "https://Stackoverflow.com/users/224531", "pm_score": 2, "selected": false, "text": "using System;\nusing System.Net;\nusing System.Windows;\nusing System.Windows.Controls;\nusing System.Windows.Documents;\nusing System.Windows.Ink;\nusing System.Windows.Input;\nusing System.Windows.Media;\nusing System.Windows.Media.Animation;\nusing System.Windows.Shapes;\n\nnamespace RecipeManager.PrintReportsService \n{\n public partial class PrintReportsClient : System.ServiceModel.ClientBase<RecipeManager.PrintReportsService.PrintReports>, RecipeManager.PrintReportsService.PrintReports \n {\n public void SetOperationTimeout(TimeSpan timeout)\n {\n ((System.ServiceModel.IContextChannel)base.Channel).OperationTimeout = timeout;\n }\n\n\n }\n}\n PrintReportsService.PrintReportsClient client = new RecipeManager.PrintReportsService.PrintReportsClient();\n client.SetOperationTimeout(new TimeSpan(0, 4, 0));\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331297", "https://Stackoverflow.com", "https://Stackoverflow.com/users/39643/" ]
331,322
<p>I have read numerous articles now and it's not clear and there's lots of versions and this that and the other and I have been piecing things together and have got so far, my problem is the 'rar' command doesn't seem to accept my substition variable and instead reads it as a string.</p> <p>But this is what I have</p> <pre><code>@echo off SETLOCAL set path=%path%;"C:\TEMP\Output" set _sourcedir=C:\TEMP\Output set _logfile=c:\temp\Output\zip_log.txt set _rarpath=C:\Program Files (x86)\WinRAR echo Starting rar batch &gt; %_logfile% :: Set default directory pushd %_sourcedir% echo Scan Directory is %_sourcedir% FOR %%f IN (*.txt) DO ( echo %%f %_rarpath\rar.exe a test ) popd ENDLOCAL @echo on </code></pre> <p>I have cut some out and chopped it so you only get the essence, I haven't omitted any commands though.</p> <p>I am trying to loop through the directory and locate all <code>.txt</code> files and zip them into a <code>.rar</code> file.</p> <p>The echo writes out the correct filenames.</p> <p>Any ideas?</p>
[ { "answer_id": 331337, "author": "Patrick Cuff", "author_id": 7903, "author_profile": "https://Stackoverflow.com/users/7903", "pm_score": 3, "selected": true, "text": "set _rarpath=C:\\Program Files (x86)\\WinRAR\n _rarpath C:\\Program set _rarpath=\"C:\\Program Files (x86)\\WinRAR\"\n %_rarpath\\rar.exe a test\n %_rarpath%\\rar.exe a test\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331322", "https://Stackoverflow.com", "https://Stackoverflow.com/users/27412/" ]
331,326
<p>Does anyone know of a good, extensible source code analyzer that examines JavaScript files? </p>
[ { "answer_id": 10136658, "author": "Thomas Schmitt", "author_id": 1330934, "author_profile": "https://Stackoverflow.com/users/1330934", "pm_score": 2, "selected": false, "text": "JSAnalysis javascript JSAnalyse Visual Studio Layer Diagramm" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331326", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28540/" ]
331,334
<p>I am using NHibernate on a new ASP.NET project, and am running into what I believe to be strange behavior. I am attempting to manage my session by using an HttpModule to catch the EndRequest event and close the session. This is working fine, however, after the EndRequest event fires, I am getting an exception in the OnLoad event of one of my custom controls that is attempting to read a Property from my object that is lazy loaded. I get an exception stating 'failed to lazily initialize a collection, no session or session was closed'. Turning lazy load off for these properties does fix the problem, and is an acceptable solution. But this seems to be going against what I always thought to be true.</p> <p>I would assume that the OnLoad event and all server side processing would be done at the point that EndRequest is fired. This is also the first time that I have used IIS 7 on a project. Is this a reason for the behavior? What is the expected behavior?</p>
[ { "answer_id": 342309, "author": "yfeldblum", "author_id": 12349, "author_profile": "https://Stackoverflow.com/users/12349", "pm_score": 1, "selected": false, "text": "RequestContainer ISession ISession IDisposable RequestContainer ISession" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331334", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6146/" ]
331,345
<p>I have a linq to sql database. Very simplified we have 3 tables, Projects and Users. There is a joining table called User_Projects which joins them together. </p> <p>I already have a working method of getting <code>IEnumberable&lt;Project&gt;</code> for a given user. </p> <pre><code>from up in User_Projects select up.Project; </code></pre> <p>Now I want to get the projects the user <em>isn't</em> involved with. I figured the except method of IEnumerable would be pretty good here:</p> <pre><code>return db.Projects.Except(GetProjects()); </code></pre> <p>That compiles, however I get a runtime error: "Local sequence cannot be used in LINQ to SQL implementation of query operators except the Contains() operator."</p> <p>Is there any way to get around this?</p> <hr> <h2>Update:</h2> <p>A few views but no answers :p</p> <p>I have tried this: </p> <pre><code> IEnumerable&lt;Project&gt; allProjects = db.Projects; IEnumerable&lt;Project&gt; userProjects = GetProjects(); return allProjects.Except(GetProjects()); </code></pre> <p>I know it's essentially the same as the original statement - but now i dont get a runtime error. Unfortunately, it doesn't really do the except part and just returns all the projects, for some reason</p>
[ { "answer_id": 331454, "author": "technophile", "author_id": 23029, "author_profile": "https://Stackoverflow.com/users/23029", "pm_score": 0, "selected": false, "text": "var userProjects = GetProjects();\nreturn db.Projects.Except(userProjects.ToArray());\n" }, { "answer_id": 331466, "author": "Bryan Watts", "author_id": 37815, "author_profile": "https://Stackoverflow.com/users/37815", "pm_score": 4, "selected": true, "text": "var userProjectIds =\n from project in GetProjects()\n select project.ProjectId;\n\nvar nonUserProjects =\n from project in db.Projects\n where !userProjectIds.Contains(project.ProjectId)\n select project;\n" }, { "answer_id": 331479, "author": "Agies", "author_id": 333860, "author_profile": "https://Stackoverflow.com/users/333860", "pm_score": 2, "selected": false, "text": "User u = SomeUser;\n\nfrom up in User_Projects\nwhere up.User != u\nselect up.Project;\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331345", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3193/" ]
331,367
<p>Say I have 2 tables: Customers and Orders. A Customer can have many Orders.</p> <p>Now, I need to show any Customers with his latest Order. This means if a Customer has more than one Orders, show only the Order with the latest Entry Time.</p> <p>This is how far I managed on my own:</p> <pre><code>SELECT a.*, b.Id FROM Customer a INNER JOIN Order b ON b.CustomerID = a.Id ORDER BY b.EntryTime DESC </code></pre> <p>This of course returns all Customers with one or more Orders, showing the latest Order first for each Customer, which is not what I wanted. My mind was stuck in a rut at this point, so I hope someone can point me in the right direction.</p> <p>For some reason, I <i>think</i> I need to use the MAX syntax somewhere, but it just escapes me right now.</p> <p><b>UPDATE:</b> After going through a few answers here (there's a lot!), I realized I made a mistake: I meant <b>any</b> Customer with his latest record. That means if he does not have an Order, then I do not need to list him. </p> <p><b>UPDATE2:</b> Fixed my own SQL statement, which probably caused no end of confusion to others.</p>
[ { "answer_id": 331392, "author": "devio", "author_id": 21336, "author_profile": "https://Stackoverflow.com/users/21336", "pm_score": 1, "selected": false, "text": "SELECT Cust.*, Ord.*\nFROM Customers cust INNER JOIN Orders ord ON cust.ID = ord.CustID\nWHERE ord.OrderID = \n (SELECT MAX(OrderID) FROM Orders WHERE Orders.CustID = cust.ID)\n" }, { "answer_id": 331397, "author": "xahtep", "author_id": 42184, "author_profile": "https://Stackoverflow.com/users/42184", "pm_score": 3, "selected": false, "text": "SELECT X.*, Y.LatestOrderId\nFROM Customer X\nLEFT JOIN (\n SELECT A.Customer, MAX(A.OrderID) LatestOrderId\n FROM Order A\n JOIN (\n SELECT Customer, MAX(EntryTime) MaxEntryTime FROM Order GROUP BY Customer\n ) B ON A.Customer = B.Customer AND A.EntryTime = B.MaxEntryTime\n GROUP BY Customer\n) Y ON X.Customer = Y.Customer\n MAX(OrderID) Y LEFT JOIN NULL SELECT A.Customer, MAX(A.OrderID) LatestOrderId\nFROM Order A\nJOIN (\n SELECT Customer, MAX(EntryTime) MaxEntryTime FROM Order GROUP BY Customer\n) B ON A.Customer = B.Customer AND A.EntryTime = B.MaxEntryTime\nGROUP BY Customer\n" }, { "answer_id": 331414, "author": "Benny Wong", "author_id": 2999, "author_profile": "https://Stackoverflow.com/users/2999", "pm_score": 0, "selected": false, "text": "SELECT\n a.*\nFROM\n Customer a\n INNER JOIN Order b\n ON a.OrderID = b.Id\n INNER JOIN (SELECT Id, max(EntryTime) as EntryTime FROM Order b GROUP BY Id) met\n ON\n b.EntryTime = met.EntryTime and b.Id = met.Id\n" }, { "answer_id": 331503, "author": "Martin Brown", "author_id": 20553, "author_profile": "https://Stackoverflow.com/users/20553", "pm_score": 5, "selected": true, "text": "select * \nfrom Customers \n inner join Orders \n on Customers.CustomerID = Orders.CustomerID\n and OrderID = (\n SELECT TOP 1 subOrders.OrderID \n FROM Orders subOrders \n WHERE subOrders.CustomerID = Orders.CustomerID \n ORDER BY subOrders.OrderDate DESC\n )\n" }, { "answer_id": 331682, "author": "Patrick Harrington", "author_id": 41165, "author_profile": "https://Stackoverflow.com/users/41165", "pm_score": 3, "selected": false, "text": "select a.*\n ,b.Id\n \nfrom customer a\n \ninner join Order b\non b.CustomerID = a.Id\n \nwhere b.EntryTime = ( select max(EntryTime)\n from Order\n where a.Id = b.CustomerId\n );\n a.Id = b.CustomerId EntryTime b a.Id order by max(EntryTime)" }, { "answer_id": 331692, "author": "user34850", "author_id": 34850, "author_profile": "https://Stackoverflow.com/users/34850", "pm_score": 2, "selected": false, "text": "SELECT *\n FROM (SELECT a.*, b.*,\n ROW_NUMBER () OVER (PARTITION BY a.ID ORDER BY b.orderdate DESC,\n b.ID DESC) rn\n FROM customer a, ORDER b\n WHERE a.ID = b.custid)\n WHERE rn = 1\n" }, { "answer_id": 331694, "author": "Tom H", "author_id": 5696608, "author_profile": "https://Stackoverflow.com/users/5696608", "pm_score": 0, "selected": false, "text": "SELECT\n C.*,\n O1.ID\nFROM\n dbo.Customers C\nINNER JOIN dbo.Orders O1 ON\n O1.CustomerID = C.ID\nLEFT OUTER JOIN dbo.Orders O2 ON\n O2.CustomerID = C.ID AND\n O2.EntryTime > O1.EntryTime\nWHERE\n O2.ID IS NULL\n" }, { "answer_id": 49112726, "author": "Saad Achemlal", "author_id": 2470795, "author_profile": "https://Stackoverflow.com/users/2470795", "pm_score": 2, "selected": false, "text": "SELECT c.id as customer_id, \n (SELECT co.id FROM customer_order co WHERE \n co.customer_id=c.id \n ORDER BY some_date_column DESC limit 1) as last_order_id\n FROM customer c\n" }, { "answer_id": 70428923, "author": "Amrinder Arora", "author_id": 298742, "author_profile": "https://Stackoverflow.com/users/298742", "pm_score": 0, "selected": false, "text": "select c.customer_id, max(o.order_date)\nfrom customers c\ninner join orders o on o.customer_id = c.customer_id\ngroup by c.customer_id;\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331367", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19582/" ]
331,376
<p>I have a class and I want to be able to iterate over a certain array member. I did a quick search and found <code>IteratorAggregate</code>:</p> <pre><code>class foo implements IteratorAggregate { protected $_array = array('foo'=&gt;'bar', 'baz'=&gt;'quux'); public function getIterator() { return new ArrayIterator($this-&gt;_array); } } </code></pre> <p>which works great, but doesn't that create a new <code>ArrayIterator</code> instance every time <code>foreach</code> is used on it?</p> <p>So I thought I should store the iterator instance in a member:</p> <pre><code> protected $_iterator; public function getIterator() { if (!$this-&gt;_iterator instanceof ArrayIterator) { $this-&gt;_iterator = new ArrayIterator($this-&gt;_array); } return $this-&gt;_iterator; } </code></pre> <p>The problem is that the iterator uses a copy of <code>$this->_array</code> during the first call of <code>getIterator()</code>, so changes to the member aren't reflected on subsequent <code>foreach</code> constructs.</p> <p>I was thinking I should subclass <code>ArrayIterator</code>, add a <code>setArray($array)</code> method and call it before returning it in <code>getIterator()</code>, but I don't know the member name of the array it uses internally and whether or not it's overwriteable by a subclass.</p> <p>The question is: is this a premature and/or unnecessary optimization? If no, what's the best way to achieve this?</p>
[ { "answer_id": 331392, "author": "devio", "author_id": 21336, "author_profile": "https://Stackoverflow.com/users/21336", "pm_score": 1, "selected": false, "text": "SELECT Cust.*, Ord.*\nFROM Customers cust INNER JOIN Orders ord ON cust.ID = ord.CustID\nWHERE ord.OrderID = \n (SELECT MAX(OrderID) FROM Orders WHERE Orders.CustID = cust.ID)\n" }, { "answer_id": 331397, "author": "xahtep", "author_id": 42184, "author_profile": "https://Stackoverflow.com/users/42184", "pm_score": 3, "selected": false, "text": "SELECT X.*, Y.LatestOrderId\nFROM Customer X\nLEFT JOIN (\n SELECT A.Customer, MAX(A.OrderID) LatestOrderId\n FROM Order A\n JOIN (\n SELECT Customer, MAX(EntryTime) MaxEntryTime FROM Order GROUP BY Customer\n ) B ON A.Customer = B.Customer AND A.EntryTime = B.MaxEntryTime\n GROUP BY Customer\n) Y ON X.Customer = Y.Customer\n MAX(OrderID) Y LEFT JOIN NULL SELECT A.Customer, MAX(A.OrderID) LatestOrderId\nFROM Order A\nJOIN (\n SELECT Customer, MAX(EntryTime) MaxEntryTime FROM Order GROUP BY Customer\n) B ON A.Customer = B.Customer AND A.EntryTime = B.MaxEntryTime\nGROUP BY Customer\n" }, { "answer_id": 331414, "author": "Benny Wong", "author_id": 2999, "author_profile": "https://Stackoverflow.com/users/2999", "pm_score": 0, "selected": false, "text": "SELECT\n a.*\nFROM\n Customer a\n INNER JOIN Order b\n ON a.OrderID = b.Id\n INNER JOIN (SELECT Id, max(EntryTime) as EntryTime FROM Order b GROUP BY Id) met\n ON\n b.EntryTime = met.EntryTime and b.Id = met.Id\n" }, { "answer_id": 331503, "author": "Martin Brown", "author_id": 20553, "author_profile": "https://Stackoverflow.com/users/20553", "pm_score": 5, "selected": true, "text": "select * \nfrom Customers \n inner join Orders \n on Customers.CustomerID = Orders.CustomerID\n and OrderID = (\n SELECT TOP 1 subOrders.OrderID \n FROM Orders subOrders \n WHERE subOrders.CustomerID = Orders.CustomerID \n ORDER BY subOrders.OrderDate DESC\n )\n" }, { "answer_id": 331682, "author": "Patrick Harrington", "author_id": 41165, "author_profile": "https://Stackoverflow.com/users/41165", "pm_score": 3, "selected": false, "text": "select a.*\n ,b.Id\n \nfrom customer a\n \ninner join Order b\non b.CustomerID = a.Id\n \nwhere b.EntryTime = ( select max(EntryTime)\n from Order\n where a.Id = b.CustomerId\n );\n a.Id = b.CustomerId EntryTime b a.Id order by max(EntryTime)" }, { "answer_id": 331692, "author": "user34850", "author_id": 34850, "author_profile": "https://Stackoverflow.com/users/34850", "pm_score": 2, "selected": false, "text": "SELECT *\n FROM (SELECT a.*, b.*,\n ROW_NUMBER () OVER (PARTITION BY a.ID ORDER BY b.orderdate DESC,\n b.ID DESC) rn\n FROM customer a, ORDER b\n WHERE a.ID = b.custid)\n WHERE rn = 1\n" }, { "answer_id": 331694, "author": "Tom H", "author_id": 5696608, "author_profile": "https://Stackoverflow.com/users/5696608", "pm_score": 0, "selected": false, "text": "SELECT\n C.*,\n O1.ID\nFROM\n dbo.Customers C\nINNER JOIN dbo.Orders O1 ON\n O1.CustomerID = C.ID\nLEFT OUTER JOIN dbo.Orders O2 ON\n O2.CustomerID = C.ID AND\n O2.EntryTime > O1.EntryTime\nWHERE\n O2.ID IS NULL\n" }, { "answer_id": 49112726, "author": "Saad Achemlal", "author_id": 2470795, "author_profile": "https://Stackoverflow.com/users/2470795", "pm_score": 2, "selected": false, "text": "SELECT c.id as customer_id, \n (SELECT co.id FROM customer_order co WHERE \n co.customer_id=c.id \n ORDER BY some_date_column DESC limit 1) as last_order_id\n FROM customer c\n" }, { "answer_id": 70428923, "author": "Amrinder Arora", "author_id": 298742, "author_profile": "https://Stackoverflow.com/users/298742", "pm_score": 0, "selected": false, "text": "select c.customer_id, max(o.order_date)\nfrom customers c\ninner join orders o on o.customer_id = c.customer_id\ngroup by c.customer_id;\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331376", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31003/" ]
331,377
<p>How to pack python libs I'm using so I can distribute them with my app and have as few dependencies as possible and also not to conflict with different lib/version that is already on my system.</p> <p>L.E.: Sorry i forgot to specify. I will be doing this on linux. And I'm not referring in making my app a installable file like deb/rpm, etc but how to organize my files so like for example I'll be using cherrypy and sqlalchemy I'll ship those with my app and not put the user through the pain of installing all the dependencies by himself.</p>
[ { "answer_id": 331489, "author": "xahtep", "author_id": 42184, "author_profile": "https://Stackoverflow.com/users/42184", "pm_score": 2, "selected": false, "text": "freeze.py" }, { "answer_id": 331846, "author": "orip", "author_id": 37020, "author_profile": "https://Stackoverflow.com/users/37020", "pm_score": 3, "selected": true, "text": "# startproj.sh\nscript_path=`dirname $0`\nexport PYTHONPATH=${script_path}/external;${PYTHONPATH}\nexec ${script_path}/projstartup.py\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331377", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9789/" ]
331,388
<p><strong>What is the best way to make one of the branches of a subversion repository the new trunk?</strong> </p> <p>There has been a major rewrite for the entire system: things have been moved around, rewritten, replaces, removed, renamed etc. The rewritten code has been tested and is ready to replace the old trunk.</p> <p>Basically, the the old mainline (Trunk 5) is tagged and will end here. The rewritten branch (Branch 6) is to become the new mainline (Trunk 7):</p> <pre> Trunk(1) --> Trunk(2) --> Trunk(5) --> &times; +--> new Trunk(7) \ \ | fork merge ??? \ \ | +--> Branch(3) --> Branch(4) --> Branch(6) --+ </pre> <p>All ongoing changes from the old 'Trunk' are already incorporated in the 'Rewritten branch'</p> <p><strong>How can I do this?</strong></p>
[ { "answer_id": 331395, "author": "Aaron Digulla", "author_id": 34088, "author_profile": "https://Stackoverflow.com/users/34088", "pm_score": 8, "selected": true, "text": "svn move" }, { "answer_id": 331574, "author": "Ken Gentle", "author_id": 8709, "author_profile": "https://Stackoverflow.com/users/8709", "pm_score": 2, "selected": false, "text": "svnadmin dump svndumpfilter svndumpfilter svndumpfilter svndumpfilter svndumpfilter" }, { "answer_id": 339274, "author": "Ryan Cook", "author_id": 43029, "author_profile": "https://Stackoverflow.com/users/43029", "pm_score": 6, "selected": false, "text": "<FeatureBranchName>-Merged <FeatureBranchName>-Merged svn move https://SVNUrl/svn/Repo/trunk https://SVNUrl/svn/Repo/tags/AnyName\n\nsvn move https://SVNUrl/svn/Repo/branches/BranchName-Merged https://SVNUrl/svn/Repo/trunk\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331388", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22674/" ]
331,394
<p>I know this is probably on the Internet somewhere but I can't find the answer here on Stackoverflow so I thought I may boost up the knowledge base here a little.</p> <p>I'm a newbie to Ruby and Rails but my company is getting pretty invested in it so I'm trying to get to know it in a little more detail.</p> <p>It's been difficult for me to change my mindset to designing an application from the "model" rather the from the database, so I'm trying to figure out how would do all of the design work that I have classically done in the Database in the Rails model instead.</p> <p>So the most recent task that I have given myself is to figure out how to configure a Rails database model to do cascading deletes? Is there an easy way of doing this? Or would I have to go into the MySql and set this up?</p>
[ { "answer_id": 331408, "author": "danmayer", "author_id": 27738, "author_profile": "https://Stackoverflow.com/users/27738", "pm_score": 6, "selected": false, "text": "has_many :memberships, dependent: :destroy\n" }, { "answer_id": 331436, "author": "Sean McMains", "author_id": 2041950, "author_profile": "https://Stackoverflow.com/users/2041950", "pm_score": 3, "selected": false, "text": "create_table :orders do |t|\n t.column :customer_id, :integer, :on_delete => :set_null, :on_update => :cascade\n ...\nend\n" }, { "answer_id": 331626, "author": "Mike Breen", "author_id": 22346, "author_profile": "https://Stackoverflow.com/users/22346", "pm_score": 8, "selected": true, "text": "has_many :memberships, dependent: :delete_all\n" }, { "answer_id": 38655056, "author": "Hendrik", "author_id": 788652, "author_profile": "https://Stackoverflow.com/users/788652", "pm_score": 5, "selected": false, "text": "has_many :memberships, dependent: :delete_all\n foreign_key add_foreign_key :users, :memberships, on_delete: :nullify\n add_foreign_key :users, :memberships, on_delete: :cascade\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331394", "https://Stackoverflow.com", "https://Stackoverflow.com/users/39086/" ]
331,398
<p>I have an http module on a sharepoint site and this module instantiates a custom class and add it to the session and does other initial things for my site. However, I'm noticing that the http module is being called for all request types (.aspx, .js, .png, .jpg).</p> <p>Is there any way to have an http module only be called for .net specific page types?</p>
[ { "answer_id": 331408, "author": "danmayer", "author_id": 27738, "author_profile": "https://Stackoverflow.com/users/27738", "pm_score": 6, "selected": false, "text": "has_many :memberships, dependent: :destroy\n" }, { "answer_id": 331436, "author": "Sean McMains", "author_id": 2041950, "author_profile": "https://Stackoverflow.com/users/2041950", "pm_score": 3, "selected": false, "text": "create_table :orders do |t|\n t.column :customer_id, :integer, :on_delete => :set_null, :on_update => :cascade\n ...\nend\n" }, { "answer_id": 331626, "author": "Mike Breen", "author_id": 22346, "author_profile": "https://Stackoverflow.com/users/22346", "pm_score": 8, "selected": true, "text": "has_many :memberships, dependent: :delete_all\n" }, { "answer_id": 38655056, "author": "Hendrik", "author_id": 788652, "author_profile": "https://Stackoverflow.com/users/788652", "pm_score": 5, "selected": false, "text": "has_many :memberships, dependent: :delete_all\n foreign_key add_foreign_key :users, :memberships, on_delete: :nullify\n add_foreign_key :users, :memberships, on_delete: :cascade\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331398", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
331,400
<p>I'm trying to understand a particular Perl code from <a href="http://sourceforge.net/projects/vcake" rel="nofollow noreferrer">vcake</a>. Usually I find my way around in Perl but the following statement baffles me. I suspect that this is simply an error but I'm not completely sure. The statement is:</p> <pre><code>foreach my $seq (keys %$set) { if( (defined $set-&gt;{$seq}) and (my $numReads &gt;= ($coverage)) ) { do something; } ... } </code></pre> <p><code>$coverage</code> has been defined at the beginning of the file as a scalar integer (e.g. 10) and is never again written to. <code>$numReads</code> is only used in the line above, <em>nowhere else</em>!</p> <p><code>$set</code>, on the other hand, is modified inside the loop so the first part of the condition makes perfect sense. What I don't understand is the second part because as I see it, this will always evaluate to the same value and <strong>I don't understand the significance of <code>$numReads</code> or <code>&gt;=</code> here</strong>. Can someone please enlighten me? Are there perhaps invisible automatic variables involved?</p>
[ { "answer_id": 331425, "author": "Aaron Digulla", "author_id": 34088, "author_profile": "https://Stackoverflow.com/users/34088", "pm_score": 5, "selected": true, "text": "my $numReads foreach undef 0 if ((...) and (0 >= ($coverage)) ) {\n}\n" }, { "answer_id": 333611, "author": "Altreus", "author_id": 2386199, "author_profile": "https://Stackoverflow.com/users/2386199", "pm_score": 2, "selected": false, "text": "foreach my $seq (keys %set)\n defined $set->{$seq}\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331400", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1968/" ]
331,407
<p>I am using the following code to set a tray icon in Windows and Linux. It works wonderful in Windows and works okay in Linux. In Linux (Ubuntu) I have my panel set to be (somewhat) transparent and when I add a GIF (with a transparent background) the background of the icon shows up all grey and ugly (see image, green diamond "!")....Any ideas on how to make the GIF image I am adding "keep" its transparent background?</p> <p><a href="http://unarm.org/stackoverflow/panel_task.jpg">alt text http://unarm.org/stackoverflow/panel_task.jpg</a></p> <p>and the image I am using, if you'd like to test:</p> <p><a href="http://unarm.org/stackoverflow/green_info.gif">alt text http://unarm.org/stackoverflow/green_info.gif</a></p> <pre><code>import java.awt.*; import java.awt.event.*; public class TrayFun { static class ShowMessageListener implements ActionListener { TrayIcon trayIcon; String title; String message; TrayIcon.MessageType messageType; ShowMessageListener( TrayIcon trayIcon, String title, String message, TrayIcon.MessageType messageType) { this.trayIcon = trayIcon; this.title = title; this.message = message; this.messageType = messageType; } public void actionPerformed(ActionEvent e) { trayIcon.displayMessage(title, message, messageType); } } public static void main(String args[]) { Runnable runner = new Runnable() { public void run() { if (SystemTray.isSupported()) { final SystemTray tray = SystemTray.getSystemTray(); Image image = Toolkit.getDefaultToolkit().getImage("green_info.png"); PopupMenu popup = new PopupMenu(); final TrayIcon trayIcon = new TrayIcon(image, "The Tip Text", popup); trayIcon.setImageAutoSize(true); MenuItem item = new MenuItem("Close"); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { tray.remove(trayIcon); } }); popup.add(item); try { tray.add(trayIcon); } catch (AWTException e) { System.err.println("Can't add to tray"); } } else { System.err.println("Tray unavailable"); } } }; EventQueue.invokeLater(runner); } } </code></pre>
[ { "answer_id": 3882028, "author": "Falkster", "author_id": 469123, "author_profile": "https://Stackoverflow.com/users/469123", "pm_score": 4, "selected": false, "text": "public void paint(Graphics g) {\n if (g != null && curW > 0 && curH > 0) {\n BufferedImage bufImage = new BufferedImage(curW, curH, BufferedImage.TYPE_INT_ARGB);\n Graphics2D gr = bufImage.createGraphics();\n if (gr != null) {\n try {\n gr.setColor(getBackground());\n gr.fillRect(0, 0, curW, curH);\n gr.drawImage(image, 0, 0, curW, curH, observer);\n gr.dispose();\n\n g.drawImage(bufImage, 0, 0, curW, curH, null);\n } finally {\n gr.dispose();\n }\n }\n }\n}\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331407", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24998/" ]
331,419
<p>When working with WCF services, is it better to create a new instance of the service every time you use it? Or is it better to create one and re-use it? Why is either approach better? Is it the same for asynchronous proxies? </p>
[ { "answer_id": 1812967, "author": "andrey.tsykunov", "author_id": 108317, "author_profile": "https://Stackoverflow.com/users/108317", "pm_score": 3, "selected": false, "text": "IMyContract proxy = new MyContractClient( );\ntry\n{\n proxy.MyMethod( );\n}\ncatch\n{}\n\n//Throws CommunicationObjectFaultedException\nproxy.MyMethod( );\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331419", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36687/" ]
331,428
<p>I realize that this question is impossible to answer absolutely, but I'm only after ballpark figures:</p> <p>Given a reasonably sized C-program (thousands of lines of code), on average, how many ASM-instructions would be generated. In other words, what's a realistic C-to-ASM instruction ratio? Feel free to make assumptions, such as 'with current x86 architectures'.</p> <p>I tried to Google about this, but I couldn't find anything.</p> <p><strong>Addendum</strong>: noticing how much confusion this question brought, I feel some need for an explanation: What I wanted to know by this answer, is to know, in practical terms, what "3GHz" means. I am fully aware of that the throughput per Herz varies tremendously depending on the architecture, your hardware, caches, bus speeds, and the position of the moon.</p> <p>I am not after a precise and scientific answer, but rather an empirical answer that could be put into fathomable scales. </p> <p>This isn't a trivial answer to place (as I became to notice), and this was my best effort at it. I know that the amount of resulting lines of ASM per lines of C varies depending on what you are doing. <code>i++</code> is not in the same neighborhood as <code>sqrt(23.1)</code> - I know this. Additionally, no matter what ASM I get out of the C, the ASM is interpreted into various sets of microcode within the processor, which, again, depends on whether you are running AMD, Intel or something else, and their respective generations. I'm aware of this aswell.</p> <p>The ballpark answers I've got so far are what I have been after: A project large enough averages at about 2 lines of x86 ASM per 1 line of ANSI-C. Today's processors probably would average at about one ASM command per clock cycle, once the pipelines are filled, and given a sample big enough.</p>
[ { "answer_id": 331457, "author": "Bill", "author_id": 14547, "author_profile": "https://Stackoverflow.com/users/14547", "pm_score": 2, "selected": false, "text": "i++; INC AX NOP" }, { "answer_id": 331474, "author": "Johannes Schaub - litb", "author_id": 34509, "author_profile": "https://Stackoverflow.com/users/34509", "pm_score": 5, "selected": false, "text": "int a; a = call_is_inlined(); objdump -Sd ./a.out int get_int(int c);\nint main(void) {\n int a = 1, b = 2;\n return getCode(a) + b;\n}\n gcc -c -g test.c objdump -Sd ./test.o 00000000 <main>:\nint get_int(int c);\nint main(void) { /* here, the prologue creates the frame for main */\n 0: 8d 4c 24 04 lea 0x4(%esp),%ecx\n 4: 83 e4 f0 and $0xfffffff0,%esp\n 7: ff 71 fc pushl -0x4(%ecx)\n a: 55 push %ebp\n b: 89 e5 mov %esp,%ebp\n d: 51 push %ecx\n e: 83 ec 14 sub $0x14,%esp\n int a = 1, b = 2; /* setting up space for locals */\n 11: c7 45 f4 01 00 00 00 movl $0x1,-0xc(%ebp)\n 18: c7 45 f8 02 00 00 00 movl $0x2,-0x8(%ebp)\n return getCode(a) + b;\n 1f: 8b 45 f4 mov -0xc(%ebp),%eax\n 22: 89 04 24 mov %eax,(%esp)\n 25: e8 fc ff ff ff call 26 <main+0x26>\n 2a: 03 45 f8 add -0x8(%ebp),%eax\n} /* the epilogue runs, returning to the previous frame */\n 2d: 83 c4 14 add $0x14,%esp\n 30: 59 pop %ecx\n 31: 5d pop %ebp\n 32: 8d 61 fc lea -0x4(%ecx),%esp\n 35: c3 ret\n" }, { "answer_id": 331477, "author": "Robert Gamble", "author_id": 25222, "author_profile": "https://Stackoverflow.com/users/25222", "pm_score": 5, "selected": true, "text": "gcc -S" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331428", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2238/" ]
331,455
<p>I am working on cleaning up a bug in a large code base where no one was paying attention to local time vs. UTC time. </p> <p>What we want is a way of globally ignoring time zone information on DateTime objects sent to and from our ASP.NET web services. I've got a solution for retrieve operations. Data is only returned in datasets, and I can look for DateTime columns and set the DateTimeMode to Unspecified. That solves my problem for all data passed back and forth inside a data set.</p> <p>However DateTime objects are also often passed directly as parameters to the web methods. I'd like to strip off any incoming time zone information. Rather than searching through our client code and using DateTime.SpecifyKind(..) to set all DateTime vars to Undefined, I'd like to do some sort of global ASP.NET override to monitor incoming parameters and strip out the time zone information.</p> <p>Is such a thing possible? Or is there another easier way to do what I want to do?</p> <p>Just to reiterate -- I don't care about time zones, everyone is in the same time zone. But a couple of users have machines badly configured, wrong time zones, etc. So when they send in July 1, 2008, I'm getting June 30, 2008 22:00:00 on the server side where it's automatically converting it from their local time to the server's local time.</p> <p><strong>Update:</strong> One other possibility would be if it were possible to make a change on the client side .NET code to alter the way DateTime objects with Kind 'Undefined' are serialized.</p>
[ { "answer_id": 334679, "author": "Clyde", "author_id": 945, "author_profile": "https://Stackoverflow.com/users/945", "pm_score": 2, "selected": false, "text": "<XmlElement(DataType:=\"date\")> \n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331455", "https://Stackoverflow.com", "https://Stackoverflow.com/users/945/" ]
331,460
<p>I am getting a " Thread was being aborted " Exception in an ASP.NET page.I am not at all using any Response.Redirect/Server.Transfer method.Can any one help me to solve this ?</p>
[ { "answer_id": 331498, "author": "dr. evil", "author_id": 40322, "author_profile": "https://Stackoverflow.com/users/40322", "pm_score": 1, "selected": false, "text": "Response.Redirect(URL, False)\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331460", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40521/" ]
331,468
<p>I need a standard, Microsoft delivered, encryption library that works for both .NET 2.0 and C++. What would you suggest?</p> <p>We find that AES is only offered in .NET 3.5 (and available in C++)</p> <p>We find that Rijndael is used in .NET 2.0 but not available in the standard C++ libraries.</p> <p>If I am wrong (very good chance), can you point me in the right direction?</p> <p>Worst case scenario, I suppose I can call the Rijndael algorithm from .NET using PInvoke but I would rather have a native solution.</p>
[ { "answer_id": 331932, "author": "Scott Saad", "author_id": 4916, "author_profile": "https://Stackoverflow.com/users/4916", "pm_score": 3, "selected": true, "text": "MS_ENHANCED_PROV CALG_3DES" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331468", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16794/" ]
331,488
<p>Is there an elegantish way in Swing to find out if there are any tooltips currently being displayed in my frame?</p> <p>I'm using custom tooltips, so it would be very easy to set a flag in my <code>createToolTip()</code> method, but I can't see a way to find out when the tooltip is gone.</p> <p><code>ToolTipManager</code> has a nice flag for this, tipShowing, but of course it's <code>private</code> and they don't seem to offer a way to get to it. <code>hideWindow()</code> doesn't call out to the tooltip component (that I can tell), so I don't see a way there.</p> <p>Anyone have any good ideas?</p> <p>Update: I went with reflection. You can see the code here:</p> <pre><code>private boolean isToolTipVisible() { // Going to do some nasty reflection to get at this private field. Don't try this at home! ToolTipManager ttManager = ToolTipManager.sharedInstance(); try { Field f = ttManager.getClass().getDeclaredField("tipShowing"); f.setAccessible(true); boolean tipShowing = f.getBoolean(ttManager); return tipShowing; } catch (Exception e) { // We'll keep silent about this for now, but obviously we don't want to hit this // e.printStackTrace(); return false; } } </code></pre>
[ { "answer_id": 331530, "author": "James Van Huis", "author_id": 31828, "author_profile": "https://Stackoverflow.com/users/31828", "pm_score": 3, "selected": true, "text": "public boolean isTooltipShowing(JComponent component) {\n AbstractAction hideTipAction = (AbstractAction) component.getActionMap().get(\"hideTip\");\n return hideTipAction.isEnabled();\n }\n ToolTipManager showTipWindow() hideTipWindow()" }, { "answer_id": 332268, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "public JToolTip createToolTip() {\n JToolTip tip = super.createToolTip();\n tip.addAncestorListener( new AncestorListener() {\n public void ancestorAdded( AncestorEvent event ) {\n System.out.println( \"I'm Visible!...\" );\n }\n\n public void ancestorRemoved( AncestorEvent event ) {\n System.out.println( \"...now I'm not.\" );\n }\n\n public void ancestorMoved( AncestorEvent event ) { \n // ignore\n }\n } );\n return tip;\n}\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331488", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34360/" ]
331,502
<p>I've got 2 Questions:</p> <p>1. I've sarted working around with Linq to XML and i'm wondering if it is possible to change an XML document via Linq. I mean, is there someting like </p> <pre><code>XDocument xmlDoc = XDocument.Load("sample.xml"); update item in xmlDoc.Descendants("item") where (int)item .Attribute("id") == id ... </code></pre> <p>2. I already know how to create and add a new XMLElement by simply using </p> <pre><code>xmlDoc.Element("items").Add(new XElement(......); </code></pre> <p>but how can I remove a single entry?</p> <p>XML sample data:</p> <pre><code>&lt;items&gt; &lt;item id="1" name="sample1" info="sample1 info" web="" /&gt; &lt;item id="2" name="sample2" info="sample2 info" web="" /&gt; &lt;/itmes&gt; </code></pre>
[ { "answer_id": 335418, "author": "Robert Rossney", "author_id": 19403, "author_profile": "https://Stackoverflow.com/users/19403", "pm_score": 3, "selected": false, "text": "using System;\nusing System.Linq;\nusing System.Xml.Linq;\n\nstatic void Main(string[] args)\n{\n string xml = @\"<data><record id='1'/><record id='2'/><record id='3'/></data>\";\n StringReader sr = new StringReader(xml);\n XDocument d = XDocument.Load(sr);\n\n // the verbose way, if you will be removing many elements (though in\n // this case, we're only removing one)\n var list = from XElement e in d.Descendants(\"record\")\n where e.Attribute(\"id\").Value == \"2\" \n select e;\n\n // convert the list to an array so that we're not modifying the\n // collection that we're iterating over\n foreach (XElement e in list.ToArray())\n {\n e.Remove();\n }\n\n // the concise way, which only works if you're removing a single element\n // (and will blow up if the element isn't found)\n d.Descendants(\"record\").Where(x => x.Attribute(\"id\").Value == \"3\").Single().Remove();\n\n XmlWriter xw = XmlWriter.Create(Console.Out);\n d.WriteTo(xw);\n xw.Flush();\n Console.ReadLine();\n}\n" }, { "answer_id": 341076, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 4, "selected": false, "text": "string xml = @\"<data><record id='1' info='sample Info'/><record id='2' info='sample Info'/><record id='3' info='sample Info'/></data>\";\nStringReader sr = new StringReader(xml);\nXDocument d = XDocument.Load(sr);\n\n\nd.Descendants(\"record\").Where(x => x.Attribute(\"id\").Value == \"2\").Single().SetAttributeValue(\"info\", \"new sample info\");\n" }, { "answer_id": 2847171, "author": "Ajay JIlakara", "author_id": 342820, "author_profile": "https://Stackoverflow.com/users/342820", "pm_score": -1, "selected": false, "text": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Web;\nusing System.Web.UI;\nusing System.Web.UI.WebControls;\nusing System.Xml.Linq;\n\nnamespace LinqToXmlTest\n{\npublic partial class _Default : System.Web.UI.Page\n{\n protected void Page_Load(object sender, EventArgs e)\n {\n\n }\n protected void ReadXml()\n {\n XDocument xdocument = XDocument.Load(Server.MapPath(\"People.xml\"));\n var persons = from person in xdocument.Descendants(\"Person\")\n select new\n {\n Name = person.Element(\"Name\").Value,\n City = person.Element(\"City\").Value,\n Age = person.Element(\"Age\").Value\n };\n litResults.Text = \"\";\n foreach (var person in persons)\n {\n litResults.Text = litResults.Text + \"Name: \" + person.Name + \"<br/>\";\n litResults.Text = litResults.Text + \"City: \" + person.City + \"<br/>\";\n litResults.Text = litResults.Text + \"Age: \" + person.Age + \"<br/><br/>\";\n }\n if (litResults.Text == \"\")\n litResults.Text = \"No Results...\";\n }\n\n protected void butAdd_Click(object sender, EventArgs e)\n {\n try\n {\n if (txtName.Text == \"\" || txtCity.Text == \"\" || txtAge.Text == \"\")\n {\n lblStatus.ForeColor = System.Drawing.Color.Red;\n lblStatus.Text = \"Please Complete the form\";\n }\n else\n {\n XDocument xdocumnet = XDocument.Load(Server.MapPath(\"People.xml\"));\n xdocumnet.Element(\"Persons\").Add(new XElement(\"Person\",\n new XElement(\"Name\", txtName.Text),\n new XElement(\"City\", txtCity.Text),\n new XElement(\"Age\", txtAge.Text)));\n xdocumnet.Save(Server.MapPath(\"People.xml\"));\n lblStatus.ForeColor = System.Drawing.Color.Green;\n lblStatus.Text = \"Data Successfully loaded to xml file\";\n txtName.Text = \"\";\n txtCity.Text = \"\";\n txtAge.Text = \"\";\n ReadXml();\n }\n }\n catch\n {\n lblStatus.ForeColor = System.Drawing.Color.Red;\n lblStatus.Text = \"Sorry unable to precess request.Please try again\";\n }\n\n\n }\n\n protected void butRead_Click(object sender, EventArgs e)\n {\n ReadXml();\n lblStatus.Text = \"\";\n }\n\n protected void btnUpdate_Click(object sender, EventArgs e)\n {\n try\n {\n if (txtName.Text == \"\" || txtCity.Text == \"\" || txtAge.Text == \"\")\n {\n lblStatus.ForeColor = System.Drawing.Color.Red;\n lblStatus.Text = \"Please enter all details in the form\";\n }\n else\n {\n XDocument xdocument = XDocument.Load(Server.MapPath(\"People.xml\"));\n var persondata = (from person in xdocument.Descendants(\"Person\")\n where person.Element(\"Name\").Value.Equals(txtName.Text)\n select person).Single();\n\n\n persondata.Element(\"City\").Value = txtCity.Text;\n persondata.Element(\"Age\").Value = txtAge.Text;\n\n xdocument.Save(Server.MapPath(\"People.xml\"));\n lblStatus.ForeColor = System.Drawing.Color.Green;\n lblStatus.Text = \"The data updated successfully\";\n ReadXml();\n }\n }\n catch(Exception ex)\n {\n lblStatus.ForeColor = System.Drawing.Color.Red;\n lblStatus.Text = ex.Message;\n }\n }\n\n protected void btnDelete_Click(object sender, EventArgs e)\n {\n try\n {\n if (txtName.Text == \"\")\n {\n lblStatus.ForeColor = System.Drawing.Color.Red;\n lblStatus.Text = \"Please enter the name of the person to delete...\"; \n }\n else\n {\n XDocument xdocument = XDocument.Load(Server.MapPath(\"People.xml\"));\n var persondata = (from person in xdocument.Descendants(\"Person\")\n where person.Element(\"Name\").Value.Equals(txtName.Text)\n select person).Single();\n\n\n persondata.Remove();\n xdocument.Save(Server.MapPath(\"People.xml\"));\n lblStatus.ForeColor = System.Drawing.Color.Green;\n lblStatus.Text = \"The data deleted successfully...\";\n txtName.Text = \"\";\n txtCity.Text = \"\";\n txtAge.Text = \"\";\n ReadXml();\n }\n }\n catch (Exception ex)\n {\n lblStatus.ForeColor = System.Drawing.Color.Red;\n lblStatus.Text = ex.Message;\n }\n }\n}\n}\n" }, { "answer_id": 4866075, "author": "karthikeyan", "author_id": 598840, "author_profile": "https://Stackoverflow.com/users/598840", "pm_score": -1, "selected": false, "text": "static void Main(string[] args)\n {\n\n //XmlDocument doc = new XmlDocument();\n //XmlElement newBook=doc.CreateElement(\"BookParticipant\");\n //newBook.SetAttribute(\"Author\");\n\n //Using Functional Construction to Create an XML Schema\n XElement xBookParticipant = new XElement(\"BookParticipant\",\n new XElement(\"FirstName\", \"Joe\"),\n new XElement(\"LastName\", \"Rattz\"));\n Console.WriteLine(xBookParticipant.ToString());\n\n\n //Creates the Same XML Tree as Listing 6-1 but with Far Less Code\n XElement xBookParticipants = new XElement(\"BookParticipants\",\n new XElement(\"BookParticipant\",\n new XAttribute(\"type\", \"Author\"),\n new XElement(\"FirstName\", \"Joe\"),\n new XElement(\"LastName\", \"Rattz\")),\n new XElement(\"BookParticipant\",\n new XAttribute(\"type\", \"Editor\"),\n new XElement(\"FirstName\", \"Ewan\"),\n new XElement(\"LastName\", \"Buckingham\")));\n Console.WriteLine(xBookParticipants.ToString());\n\n\n //-- Disadvatages of XML document\n //System.Xml.XmlElement xmlBookParticipant = new System.Xml.XmlElement(\"BookParticipant\");\n XElement xeBookParticipant = new XElement(\"BookParticipant\");\n\n\n XDocument xDocument = new XDocument(new XElement(\"BookParticipants\",\n new XElement(\"BookParticipant\",\n new XAttribute(\"type\", \"Author\"),\n new XElement(\"FirstName\", \"Joe\"),\n new XElement(\"LastName\", \"Rattz\"))));\n Console.WriteLine(xDocument.ToString());\n\n\n //--Calling the ToString Method on an Element Produces the XML Tree\n XElement name = new XElement(\"Name\", \"Joe\");\n Console.WriteLine(name.ToString());\n\n //--Console.WriteLine Implicitly Calling the ToString Method on an Element to Produce an XML Tree\n\n\n XElement name1 = new XElement(\"Person\",\n new XElement(\"FirstName\", \"Joe\"),\n new XElement(\"LastName\", \"Rattz\"));\n Console.WriteLine(name1);\n\n //-- Casting an Element to Its Value’s Data Type Outputs the Value\n Console.WriteLine(name);\n Console.WriteLine((string)name);\n\n //--Different Node Value Types Retrieved via Casting to the Node Value’s Type\n XElement count = new XElement(\"Count\", 12);\n Console.WriteLine(count);\n Console.WriteLine((int)count);\n\n XElement smoker = new XElement(\"Smoker\", false);\n Console.WriteLine(smoker);\n Console.WriteLine((bool)smoker);\n\n XElement pi = new XElement(\"Pi\", 3.1415926535);\n Console.WriteLine(pi);\n Console.WriteLine((double)pi);\n\n\n DeferredQryProblem();\n\n\n GenerateXMlFromLinqQry();\n\n\n\n }\n\n private static void DeferredQryProblem()\n {\n XDocument xDocument = new XDocument(\n new XElement(\"BookParticipants\",\n new XElement(\"BookParticipant\",\n new XAttribute(\"type\", \"Author\"),\n new XElement(\"FirstName\", \"Joe\"),\n new XElement(\"LastName\", \"Rattz\")),\n new XElement(\"BookParticipant\",\n new XAttribute(\"type\", \"Editor\"),\n new XElement(\"FirstName\", \"Ewan\"),\n new XElement(\"LastName\", \"Buckingham\"))));\n IEnumerable<XElement> elements =\n xDocument.Element(\"BookParticipants\").Elements(\"BookParticipant\");\n foreach (XElement element in elements)\n {\n Console.WriteLine(\"Source element: {0} : value = {1}\",\n element.Name, element.Value);\n }\n foreach (XElement element in elements)\n {\n Console.WriteLine(\"Removing {0} = {1} ...\", element.Name, element.Value);\n element.Remove();\n }\n Console.WriteLine(xDocument);\n\n\n foreach (XElement element in elements)\n {\n Console.WriteLine(\"Source element: {0} : value = {1}\",\n element.Name, element.Value);\n }\n foreach (XElement element in elements.ToArray())\n {\n Console.WriteLine(\"Removing {0} = {1} ...\", element.Name, element.Value);\n element.Remove();\n }\n Console.WriteLine(xDocument);\n }\n\n //-- Creating an Attribute and Adding It to Its Element\n private static void CreatingAttribute()\n {\n XElement xBookParticipant = new XElement(\"BookParticipant\", new XAttribute(\"type\", \"Author\"));\n Console.WriteLine(xBookParticipant);\n }\n\n //--Creating a Comment with Functional Construction\n private static void CreatingComment()\n {\n XElement xBookParticipant = new XElement(\"BookParticipant\",\n new XComment(\"This person is retired.\"));\n Console.WriteLine(xBookParticipant);\n }\n\n //--Creating a Declaration with Functional Construction\n private static void CreateXmlDeclaration()\n {\n XDocument xDocument = new XDocument(new XDeclaration(\"1.0\", \"UTF-8\", \"yes\"),\nnew XElement(\"BookParticipant\"));\n Console.WriteLine(xDocument);\n }\n\n private static void GenerateXMlFromLinqQry()\n {\n BookParticipant[] bookParticipants = new[] {new BookParticipant {FirstName = \"Joe\", LastName = \"Rattz\",\n ParticipantType = ParticipantTypes.Author},\n new BookParticipant {FirstName = \"Ewan\", LastName = \"Buckingham\",\n ParticipantType = ParticipantTypes.Editor}\n };\n XElement xBookParticipants =\n new XElement(\"BookParticipants\",\n bookParticipants.Select(p =>\n new XElement(\"BookParticipant\",\n new XAttribute(\"type\", p.ParticipantType),\n new XElement(\"FirstName\", p.FirstName),\n new XElement(\"LastName\", p.LastName))));\n\n\n Console.WriteLine(xBookParticipants);\n }\n\n //-- Obtaining Elements Without Reaching\n private static void WithoutReaching()\n {\n XDocument xDocument = new XDocument(new XElement(\"BookParticipants\",\n new XElement(\"BookParticipant\",\n new XAttribute(\"type\", \"Author\"),\n new XElement(\"FirstName\", \"Joe\"),\n new XElement(\"LastName\", \"Rattz\")),\n new XElement(\"BookParticipant\",\n new XAttribute(\"type\", \"Editor\"),\n new XElement(\"FirstName\", \"Ewan\"),\n new XElement(\"LastName\", \"Buckingham\"))));\n IEnumerable<XElement> elements = xDocument.Descendants(\"BookParticipant\");\n foreach (XElement element in elements)\n {\n Console.WriteLine(\"Element: {0} : value = {1}\",\n element.Name, element.Value);\n }\n\n\n IEnumerable<XElement> elements1 = xDocument.Descendants(\"BookParticipant\")\n .Where(e => ((string)e.Element(\"FirstName\")) == \"Ewan\");\n foreach (XElement element1 in elements1)\n {\n Console.WriteLine(\"Element: {0} : value = {1}\",\n element1.Name, element1.Value);\n }\n\n }\n" }, { "answer_id": 4877913, "author": "karthikeyan", "author_id": 598840, "author_profile": "https://Stackoverflow.com/users/598840", "pm_score": 0, "selected": false, "text": " //XmlDocument doc = new XmlDocument();\n //XmlElement newBook=doc.CreateElement(\"BookParticipant\");\n //newBook.SetAttribute(\"Author\");\n\n //Using Functional Construction to Create an XML Schema\n XElement xBookParticipant = new XElement(\"BookParticipant\",\n new XElement(\"FirstName\", \"Joe\"),\n new XElement(\"LastName\", \"Rattz\"));\n Console.WriteLine(xBookParticipant.ToString());\n\n\n //Creates the Same XML Tree as Listing 6-1 but with Far Less Code\n XElement xBookParticipants = new XElement(\"BookParticipants\",\n new XElement(\"BookParticipant\",\n new XAttribute(\"type\", \"Author\"),\n new XElement(\"FirstName\", \"Joe\"),\n new XElement(\"LastName\", \"Rattz\")),\n new XElement(\"BookParticipant\",\n new XAttribute(\"type\", \"Editor\"),\n new XElement(\"FirstName\", \"Ewan\"),\n new XElement(\"LastName\", \"Buckingham\")));\n Console.WriteLine(xBookParticipants.ToString());\n\n\n //-- Disadvatages of XML document\n //System.Xml.XmlElement xmlBookParticipant = new System.Xml.XmlElement(\"BookParticipant\");\n XElement xeBookParticipant = new XElement(\"BookParticipant\");\n\n\n XDocument xDocument = new XDocument(new XElement(\"BookParticipants\",\n new XElement(\"BookParticipant\",\n new XAttribute(\"type\", \"Author\"),\n new XElement(\"FirstName\", \"Joe\"),\n new XElement(\"LastName\", \"Rattz\"))));\n Console.WriteLine(xDocument.ToString());\n\n\n //--Calling the ToString Method on an Element Produces the XML Tree\n XElement name = new XElement(\"Name\", \"Joe\");\n Console.WriteLine(name.ToString());\n\n //--Console.WriteLine Implicitly Calling the ToString Method on an Element to Produce an XML Tree\n\n\n XElement name1 = new XElement(\"Person\",\n new XElement(\"FirstName\", \"Joe\"),\n new XElement(\"LastName\", \"Rattz\"));\n Console.WriteLine(name1);\n\n //-- Casting an Element to Its Value’s Data Type Outputs the Value\n Console.WriteLine(name);\n Console.WriteLine((string)name);\n\n //--Different Node Value Types Retrieved via Casting to the Node Value’s Type\n XElement count = new XElement(\"Count\", 12);\n Console.WriteLine(count);\n Console.WriteLine((int)count);\n\n XElement smoker = new XElement(\"Smoker\", false);\n Console.WriteLine(smoker);\n Console.WriteLine((bool)smoker);\n\n XElement pi = new XElement(\"Pi\", 3.1415926535);\n Console.WriteLine(pi);\n Console.WriteLine((double)pi);\n\n\n DeferredQryProblem();\n\n\n GenerateXMlFromLinqQry();\n\n WithoutReaching();\n\n Ancestors();\n\n\n AncestorsAndSelf();\n\n SortSample();\n\n FindElementwithSpecificChild();\n\n }\n\n private static void DeferredQryProblem()\n {\n XDocument xDocument = new XDocument(\n new XElement(\"BookParticipants\",\n new XElement(\"BookParticipant\",\n new XAttribute(\"type\", \"Author\"),\n new XElement(\"FirstName\", \"Joe\"),\n new XElement(\"LastName\", \"Rattz\")),\n new XElement(\"BookParticipant\",\n new XAttribute(\"type\", \"Editor\"),\n new XElement(\"FirstName\", \"Ewan\"),\n new XElement(\"LastName\", \"Buckingham\"))));\n IEnumerable<XElement> elements =\n xDocument.Element(\"BookParticipants\").Elements(\"BookParticipant\");\n foreach (XElement element in elements)\n {\n Console.WriteLine(\"Source element: {0} : value = {1}\",\n element.Name, element.Value);\n }\n foreach (XElement element in elements)\n {\n Console.WriteLine(\"Removing {0} = {1} ...\", element.Name, element.Value);\n element.Remove();\n }\n Console.WriteLine(xDocument);\n\n\n foreach (XElement element in elements)\n {\n Console.WriteLine(\"Source element: {0} : value = {1}\",\n element.Name, element.Value);\n }\n foreach (XElement element in elements.ToArray())\n {\n Console.WriteLine(\"Removing {0} = {1} ...\", element.Name, element.Value);\n element.Remove();\n }\n Console.WriteLine(xDocument);\n }\n\n //-- Creating an Attribute and Adding It to Its Element\n private static void CreatingAttribute()\n {\n XElement xBookParticipant = new XElement(\"BookParticipant\", new XAttribute(\"type\", \"Author\"));\n Console.WriteLine(xBookParticipant);\n }\n\n //--Creating a Comment with Functional Construction\n private static void CreatingComment()\n {\n XElement xBookParticipant = new XElement(\"BookParticipant\",\n new XComment(\"This person is retired.\"));\n Console.WriteLine(xBookParticipant);\n }\n\n //--Creating a Declaration with Functional Construction\n private static void CreateXmlDeclaration()\n {\n XDocument xDocument = new XDocument(new XDeclaration(\"1.0\", \"UTF-8\", \"yes\"),\n private static void GenerateXMlFromLinqQry()\n {\n BookParticipant[] bookParticipants = new[] {new BookParticipant {FirstName = \"Joe\", LastName = \"Rattz\",\n ParticipantType = ParticipantTypes.Author},\n new BookParticipant {FirstName = \"Ewan\", LastName = \"Buckingham\",\n ParticipantType = ParticipantTypes.Editor}\n };\n XElement xBookParticipants =\n new XElement(\"BookParticipants\",\n bookParticipants.Select(p =>\n new XElement(\"BookParticipant\",\n new XAttribute(\"type\", p.ParticipantType),\n new XElement(\"FirstName\", p.FirstName),\n new XElement(\"LastName\", p.LastName))));\n\n\n Console.WriteLine(xBookParticipants);\n }\n\n //-- Obtaining Elements Without Reaching\n private static void WithoutReaching()\n {\n XDocument xDocument = new XDocument(new XElement(\"BookParticipants\",\n new XElement(\"BookParticipant\",\n new XAttribute(\"type\", \"Author\"),\n new XElement(\"FirstName\", \"Joe\"),\n new XElement(\"LastName\", \"Rattz\")),\n new XElement(\"BookParticipant\",\n new XAttribute(\"type\", \"Editor\"),\n new XElement(\"FirstName\", \"Ewan\"),\n new XElement(\"LastName\", \"Buckingham\"))));\n\n //-- Simple Descendants\n IEnumerable<XElement> elements = xDocument.Descendants(\"BookParticipant\");\n\n\n foreach (XElement element in elements)\n {\n Console.WriteLine(\"Element: {0} : value = {1}\",\n element.Name, element.Value);\n }\n\n\n //-- Descendants with Where Clause\n IEnumerable<XElement> elements1 = xDocument.Descendants(\"BookParticipant\")\n .Where(e => ((string)e.Element(\"FirstName\")) == \"Ewan\");\n foreach (XElement element1 in elements1)\n {\n Console.WriteLine(\"Element: {0} : value = {1}\",\n element1.Name, element1.Value);\n }\n\n }\n\n\n //-- Ancestors Prototype\n private static void Ancestors()\n {\n XDocument xDocument = new XDocument(new XElement(\"BookParticipants\",\n new XElement(\"BookParticipant\",\n new XAttribute(\"type\", \"Author\"),\n new XElement(\"FirstName\", \"Joe\"),\n new XElement(\"LastName\", \"Rattz\")),\n new XElement(\"BookParticipant\",\n new XAttribute(\"type\", \"Editor\"),\n new XElement(\"FirstName\", \"Ewan\"),\n new XElement(\"LastName\", \"Buckingham\"))));\n\n IEnumerable<XElement> elements = xDocument.Element(\"BookParticipants\").Descendants(\"FirstName\");\n // First, I will display the source elements.\n foreach (XElement element in elements)\n {\n Console.WriteLine(\"Source element: {0} : value = {1}\",\n element.Name, element.Value);\n }\n // Now, I will display the ancestor elements for each source element.\n foreach (XElement element in elements.Ancestors())\n {\n Console.WriteLine(\"Ancestor element: {0}\", element.Name);\n }\n\n\n // Now, I will display the ancestor elements for each source element.\n foreach (XElement element in elements.Ancestors(\"BookParticipant\"))\n {\n Console.WriteLine(\"Ancestor element: {0}\", element.Name);\n }\n\n }\n\n\n //-- AncestorsAndSelf\n private static void AncestorsAndSelf()\n {\n XDocument xDocument = new XDocument(\n new XElement(\"BookParticipants\",\n new XElement(\"BookParticipant\",\n new XAttribute(\"type\", \"Author\"),\n new XElement(\"FirstName\", \"Joe\"),\n new XElement(\"LastName\", \"Rattz\")),\n new XElement(\"BookParticipant\",\n new XAttribute(\"type\", \"Editor\"),\n new XElement(\"FirstName\", \"Ewan\"),\n new XElement(\"LastName\", \"Buckingham\"))));\n IEnumerable<XElement> elements =\n xDocument.Element(\"BookParticipants\").Descendants(\"FirstName\");\n // First, I will display the source elements.\n foreach (XElement element in elements)\n {\n Console.WriteLine(\"Source element: {0} : value = {1}\",\n element.Name, element.Value);\n }\n // Now, I will display the ancestor elements for each source element.\n foreach (XElement element in elements.AncestorsAndSelf())\n {\n Console.WriteLine(\"Ancestor element: {0}\", element.Name);\n }\n\n\n // Now, I will display the ancestor elements for each source element.\n foreach (XElement element in elements.AncestorsAndSelf(\"BookParticipant\"))\n {\n Console.WriteLine(\"Ancestor element: {0}\", element.Name);\n }\n\n }\n\n\n //-- Sort Smaple\n\n private static void SortSample()\n {\n XElement root = XElement.Load(\"Data.xml\");\n IEnumerable<decimal> prices =\n from el in root.Elements(\"Data\")\n let price = (decimal)el.Element(\"Price\")\n orderby price\n select price;\n foreach (decimal el in prices)\n Console.WriteLine(el);\n }\n\n //-- Find an Element with a Specific Child \n private static void FindElementwithSpecificChild()\n {\n XElement root = XElement.Load(\"data.xml\");\n IEnumerable<XElement> tests =\n from el in root.Elements(\"Data\")\n where (int)el.Element(\"Quantity\") > 3\n select el;\n foreach (XElement el in tests)\n Console.WriteLine((string)el.Attribute(\"TestId\");\n }\n}\n" }, { "answer_id": 19817822, "author": "ctb", "author_id": 512629, "author_profile": "https://Stackoverflow.com/users/512629", "pm_score": 1, "selected": false, "text": "<tagName attributeName=\"some value\">another value</tagName>\n d.Descendants(\"record\").Where(x => x.Attribute(\"id\").Value == \"2\").Single().SetAttributeValue(\"info\", \"new sample info\");\n persondata.Element(\"City\").Value = txtCity.Text;\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331502", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
331,505
<p>Let say I have a sheet in with columns Customer and CreatedDate with lots of row with data. Anyone who knows how to setup (through VBA or Formula) a second sheet that displays rows from the first sheet based on certain where statements, i.e. all rows with customers "created this month." (similar to a select ... where query against a SQL database).</p> <p>Thanks! /Niels</p>
[ { "answer_id": 331547, "author": "e.James", "author_id": 33686, "author_profile": "https://Stackoverflow.com/users/33686", "pm_score": 1, "selected": true, "text": "select ... where VLOOKUP \nDim DataRange as Range\nDim RowNum as Integer\nDim NewRow as Integer\nDim TestMonth as Integer\nDim ThisMonth as Integer\n\nSet DataRange = Range(Sheet1.Cells(1,1), Sheet1.Cells(100,2))\n\nThisMonth = Application.WorksheetFunction.Month(Application.WorksheetFunction.Today())\n\nNewRow = 1\nFor RowNum from 1 to DataRange.Rows.Count\n TestMonth = Application.WorksheetFunction.Month(DataRange.Cells(RowNum, 1).Value)\n if TestMonth = ThisMonth Then\n Sheet2.Cells(NewRow, 1).Value = DataRange.Cells(RowNum, 2).Value\n NewRow = NewRow + 1\n End If\nNext RowNum" }, { "answer_id": 331563, "author": "xahtep", "author_id": 42184, "author_profile": "https://Stackoverflow.com/users/42184", "pm_score": 2, "selected": false, "text": "=Sheet1!A1" }, { "answer_id": 331622, "author": "Fionnuala", "author_id": 2548, "author_profile": "https://Stackoverflow.com/users/2548", "pm_score": 2, "selected": false, "text": "Dim cn As Object\nDim rs As Object\n\nstrFile = Workbooks(1).FullName\nstrCon = \"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\" & strFile _\n & \";Extended Properties=\"\"Excel 8.0;HDR=Yes;IMEX=1\"\";\"\n\nSet cn = CreateObject(\"ADODB.Connection\")\nSet rs = CreateObject(\"ADODB.Recordset\")\n\ncn.Open strCon\n\nstrSQL = \"SELECT * FROM [Sheet1$] WHERE CourseKey=484\"\n\nrs.Open strSQL, cn\n\nWorksheets(2).Cells(2, 1).CopyFromRecordset rs\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331505", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40939/" ]
331,520
<p>I've added a weakly named assembly to my <a href="http://en.wikipedia.org/wiki/Microsoft_Visual_Studio#Visual_Studio_2005" rel="noreferrer">Visual Studio 2005</a> project (which is strongly named). I'm now getting the error:</p> <blockquote> <p>&quot;Referenced assembly 'xxxxxxxx' does not have a strong name&quot;</p> </blockquote> <p>Do I need to sign this third-party assembly?</p>
[ { "answer_id": 331555, "author": "Dirk Vollmar", "author_id": 40347, "author_profile": "https://Stackoverflow.com/users/40347", "pm_score": 9, "selected": true, "text": "ildasm.exe ildasm /all /out=thirdPartyLib.il thirdPartyLib.dll \n ilasm /dll /key=myKey.snk thirdPartyLib.il\n sn -Tp B.dll \n Microsoft (R) .NET Framework Strong Name Utility Version 4.0.30319.33440\nCopyright (c) Microsoft Corporation. All rights reserved.\n\nPublic key (hash algorithm: sha1):\n002400000480000094000000060200000024000052534131000400000100010093d86f6656eed3\nb62780466e6ba30fd15d69a3918e4bbd75d3e9ca8baa5641955c86251ce1e5a83857c7f49288eb\n4a0093b20aa9c7faae5184770108d9515905ddd82222514921fa81fff2ea565ae0e98cf66d3758\ncb8b22c8efd729821518a76427b7ca1c979caa2d78404da3d44592badc194d05bfdd29b9b8120c\n78effe92\n\nPublic key token is a8a7ed7203d87bc9\n .assembly extern /*23000003*/ MyAssemblyName\n{\n .publickeytoken = (A8 A7 ED 72 03 D8 7B C9 ) \n .ver 10:0:0:0\n}\n" }, { "answer_id": 11408513, "author": "MrOli3000", "author_id": 1514004, "author_profile": "https://Stackoverflow.com/users/1514004", "pm_score": 7, "selected": false, "text": ".snk <Browse> .snk" }, { "answer_id": 24129749, "author": "mateuscb", "author_id": 461958, "author_profile": "https://Stackoverflow.com/users/461958", "pm_score": 5, "selected": false, "text": "For example, my DLL is located in D:/hiren/Test.dll D:/hiren> ildasm /all /out=Test.il Test.dll D:/hiren> sn -k mykey.snk ilasm D:/hiren> ilasm /dll /key=mykey.snk Test.il" }, { "answer_id": 28991126, "author": "Pabinator", "author_id": 1933253, "author_profile": "https://Stackoverflow.com/users/1933253", "pm_score": 1, "selected": false, "text": "\"C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v7.0A\\bin\\signtool.exe\" sign /f \"$(ProjectDir)\\YourPfxFileNameHere.pfx\" /p YourPfxFilePasswordHere /d \"Your software title here\" /du http://www.yourWebsiteHere.com /t http://timestamp.verisign.com/scripts/timstamp.dll /v \"$(BaseOutputPath)$(TargetFileName)\"\n" }, { "answer_id": 30150904, "author": "Martin Devillers", "author_id": 546967, "author_profile": "https://Stackoverflow.com/users/546967", "pm_score": 4, "selected": false, "text": "sn ildasm ilasm sn –k Cool.Library.snk ildasm Cool.Library.dll /out:Cool.Library.il move Cool.Library.dll Cool.Library.unsigned.dll ilasm Cool.Library.il /dll /resource=Cool.Library.res /key=Cool.Library.snk powershell -command \"& {[System.Reflection.AssemblyName]::GetAssemblyName($args).FullName} Cool.Library.dll\"" }, { "answer_id": 46631067, "author": "Jahmic", "author_id": 573927, "author_profile": "https://Stackoverflow.com/users/573927", "pm_score": 2, "selected": false, "text": "PM> Install-Package ilmerge\n ilmerge assembly.dll /keyfile:key.snk /out:assembly.dll /targetplatform:v4,C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319 /ndebug\n sn sn -k key.snk\n" }, { "answer_id": 58877916, "author": "Markus", "author_id": 1573670, "author_profile": "https://Stackoverflow.com/users/1573670", "pm_score": 0, "selected": false, "text": "Update-Package -reinstall\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331520", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36860/" ]
331,536
<p>What's a better way to start a thread, <code>_beginthread</code>, <code>_beginthreadx</code> or <code>CreateThread</code>?</p> <p>I'm trying to determine what are the advantages/disadvantages of <code>_beginthread</code>, <code>_beginthreadex</code> and <code>CreateThread</code>. All of these functions return a thread handle to a newly created thread, I already know that CreateThread provides a little extra information when an error occurs (it can be checked by calling <code>GetLastError</code>)... but what are some things I should consider when I'm using these functions?</p> <p>I'm working with a windows application, so cross-platform compatibility is already out of the question.</p> <p>I have gone through the msdn documentation and I just can't understand, for example, why anybody would decide to use _beginthread instead of CreateThread or vice versa.</p> <p>Cheers!</p> <p>Update: OK, thanks for all the info, I've also read in a couple of places that I can't call <code>WaitForSingleObject()</code> if I used <code>_beginthread()</code>, but if I call <code>_endthread()</code> in the thread shouldn't that work? What's the deal there?</p>
[ { "answer_id": 331567, "author": "Drew Hall", "author_id": 23934, "author_profile": "https://Stackoverflow.com/users/23934", "pm_score": 8, "selected": true, "text": "CreateThread() _beginthread() _beginthreadex() CreateThread() CreateThread() _beginthread/ex() _beginthreadex()" }, { "answer_id": 331711, "author": "Jaywalker", "author_id": 382974, "author_profile": "https://Stackoverflow.com/users/382974", "pm_score": 3, "selected": false, "text": "CreateThread() _beginthreadex() CreateThread() _beginthread() _beginthreadex()" }, { "answer_id": 331748, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "beginthreadex HANDLE WaitForSingleObject beginthread CloseHandle() boost::thread" }, { "answer_id": 331749, "author": "Constantin", "author_id": 20310, "author_profile": "https://Stackoverflow.com/users/20310", "pm_score": 4, "selected": false, "text": "_beginthreadex crt\\src\\threadex.c /*\n * Create the new thread using the parameters supplied by the caller.\n */\n if ( (thdl = (uintptr_t)\n CreateThread( (LPSECURITY_ATTRIBUTES)security,\n stacksize,\n _threadstartex,\n (LPVOID)ptd,\n createflag,\n (LPDWORD)thrdaddr))\n == (uintptr_t)0 )\n {\n err = GetLastError();\n goto error_return;\n }\n _beginthreadex _beginthread*" }, { "answer_id": 331754, "author": "Michael Burr", "author_id": 12711, "author_profile": "https://Stackoverflow.com/users/12711", "pm_score": 5, "selected": false, "text": "_beginthread() _beginthreadex() _beginthreadex() CreateThread() _beginthread() _beginthreadex() CreateThread() CreateThread() _beginthread() _beginthreadex() _beginthread() _beginthreadex() Differences between _beginthread/_endthread and the \"ex\" versions:\n\n1) _beginthreadex takes the 3 extra parameters to CreateThread\n which are lacking in _beginthread():\n A) security descriptor for the new thread\n B) initial thread state (running/asleep)\n C) pointer to return ID of newly created thread\n\n2) The routine passed to _beginthread() must be __cdecl and has\n no return code, but the routine passed to _beginthreadex()\n must be __stdcall and returns a thread exit code. _endthread\n likewise takes no parameter and calls ExitThread() with a\n parameter of zero, but _endthreadex() takes a parameter as\n thread exit code.\n\n3) _endthread implicitly closes the handle to the thread, but\n _endthreadex does not!\n\n4) _beginthread returns -1 for failure, _beginthreadex returns\n 0 for failure (just like CreateThread).\n _beginthreadex() GetCurrentPackageId()" }, { "answer_id": 331931, "author": "Michael Burr", "author_id": 12711, "author_profile": "https://Stackoverflow.com/users/12711", "pm_score": 3, "selected": false, "text": "WaitForSingleObject() _beginthread() _endthread() WaitForSingleObject() _beginthread() _endthread() WaitForSingleObject()" }, { "answer_id": 5634633, "author": "jarcher7", "author_id": 703985, "author_profile": "https://Stackoverflow.com/users/703985", "pm_score": 4, "selected": false, "text": "_beginthread _beginthreadex _beginthread CloseHandle _beginthread _beginthread _beginthreadex CloseHandle _beginthreadex CloseHandle" }, { "answer_id": 6220176, "author": "bobobobo", "author_id": 111307, "author_profile": "https://Stackoverflow.com/users/111307", "pm_score": 3, "selected": false, "text": "CreateThread _beginthreadex _beginthread _beginthreadx CreateThread HANDLE WINAPI CreateThread(\n __in_opt LPSECURITY_ATTRIBUTES lpThreadAttributes,\n __in SIZE_T dwStackSize,\n __in LPTHREAD_START_ROUTINE lpStartAddress,\n __in_opt LPVOID lpParameter,\n __in DWORD dwCreationFlags,\n __out_opt LPDWORD lpThreadId\n);\n\nuintptr_t _beginthread( \n void( *start_address )( void * ),\n unsigned stack_size,\n void *arglist \n);\n\nuintptr_t _beginthreadex( \n void *security,\n unsigned stack_size,\n unsigned ( *start_address )( void * ),\n void *arglist,\n unsigned initflag,\n unsigned *thrdaddr \n);\n _beginthread __cdecl __clrcall _beginthreadex __stdcall __clrcall CreateThread _beginthread* CreateThread C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\crt\\src // From ~line 180 of beginthreadex.c\n/*\n * Create the new thread using the parameters supplied by the caller.\n */\nif ( (thdl = (uintptr_t)\n CreateThread( (LPSECURITY_ATTRIBUTES)security,\n stacksize,\n _threadstartex,\n (LPVOID)ptd,\n createflag,\n (LPDWORD)thrdaddr))\n == (uintptr_t)0 )\n{\n err = GetLastError();\n goto error_return;\n}\n" }, { "answer_id": 7527492, "author": "Vishal", "author_id": 796017, "author_profile": "https://Stackoverflow.com/users/796017", "pm_score": 2, "selected": false, "text": "_beginthread _beginthreadex OpenThread CloseHandle _beginthreadex CreateThread _beginthreadex _endthreadex CreateThread ExitThread CreateThread" }, { "answer_id": 10606154, "author": "SKV", "author_id": 1396869, "author_profile": "https://Stackoverflow.com/users/1396869", "pm_score": 2, "selected": false, "text": "CreateThread() _beginthreadex() CreateThread() CreateThread() _beginthreadex()" }, { "answer_id": 12858840, "author": "Serge Wautier", "author_id": 12379, "author_profile": "https://Stackoverflow.com/users/12379", "pm_score": 2, "selected": false, "text": "CreateThread() CreateThread() CreateThread() signal() _beginthreadex()" }, { "answer_id": 12955131, "author": "alecov", "author_id": 259543, "author_profile": "https://Stackoverflow.com/users/259543", "pm_score": 2, "selected": false, "text": "CreateThread() Kernel32.dll _beginthread() _beginthreadex() msvcrt.dll _beginthread() errno _beginthread() _beginthread() _beginthreadex() CreateThread() CreateThread() _beginthreadex() _beginthread() _endthread()" }, { "answer_id": 12965511, "author": "MSN", "author_id": 6210, "author_profile": "https://Stackoverflow.com/users/6210", "pm_score": 5, "selected": false, "text": "_beginthread()/_endthread() ex() DllMain DLL_THREAD_ATTACH DLL_THREAD_DETACH CreateThread() ExitThread() DllMain" }, { "answer_id": 21803364, "author": "Ehsan Samani", "author_id": 2962724, "author_profile": "https://Stackoverflow.com/users/2962724", "pm_score": 1, "selected": false, "text": "_beginthreadex CreateThread _beginthread _beginthreadex _beginthreadex CreateThread CreateThread _begingthreadex" }, { "answer_id": 39525760, "author": "Andon M. Coleman", "author_id": 2423205, "author_profile": "https://Stackoverflow.com/users/2423205", "pm_score": 0, "selected": false, "text": "_beginthread{ex} _beginthread* DllMain _beginthreadex (...) CreateThread (...) DllMain DllMain" }, { "answer_id": 63314006, "author": "testhaha", "author_id": 14065085, "author_profile": "https://Stackoverflow.com/users/14065085", "pm_score": -1, "selected": false, "text": "#include<stdio.h>\n#include<stdlib.h>\n#include<windows.h>\n#include<process.h>\n\nUINT __stdcall Staff(PVOID lp){\n printf(\"The Number is %d\\n\", GetCurrentThreadId());\n return 0;\n}\n\nINT main(INT argc, PCHAR argv[])\n{\n\n const INT Staff_Number = 5;\n HANDLE hd[Staff_Number];\n for(INT i=0; i < Staff_Number; i++){\n hd[i] = (HANDLE)_beginthreadex(NULL, 0, Staff, NULL, 0, NULL);\n }\n\n WaitForMultipleObjects(Staff_Number, Staff, TRUE, NULL);\n for(INT i=0; i < Staff_Number; i++)\n {\n CloseHandle(hd[i]);\n }\n system(\"pause\");\n return 0;\n}\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331536", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28760/" ]
331,538
<p>My code is like the following:</p> <pre><code>URLConnection cnx = address.openConnection(); cnx.setAllowUserInteraction(false); cnx.setDoOutput(true); cnx.addRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); InputStream is = cnx.getInputStream(); </code></pre> <p>Is it ok if I set the headers before I get the <code>InputStream</code>? Will my header be sent, or will the server see the default <code>URLConnection</code>'s user-agent ( if any ) ?</p>
[ { "answer_id": 331633, "author": "Ken Gentle", "author_id": 8709, "author_profile": "https://Stackoverflow.com/users/8709", "pm_score": 5, "selected": true, "text": "InputStream IllegalStateException User-Agent" }, { "answer_id": 6956618, "author": "Leif Ashley", "author_id": 425376, "author_profile": "https://Stackoverflow.com/users/425376", "pm_score": 2, "selected": false, "text": "User-Agent: Java/1.6.0_24 (varies depending on your java version)\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331538", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31610/" ]
331,549
<p>I have an existing htaccess that works fine:</p> <pre><code>RewriteEngine On RewriteCond %{SCRIPT_FILENAME} !-f RewriteCond %{SCRIPT_FILENAME} !-d RewriteRule (.*) /default.php DirectoryIndex index.php /default.php </code></pre> <p>I wish to modify this so that all urls that start with /test/ go to /test/default.php, <strong>while keeping all other URLs with the existing /default.php</strong>.</p> <p>Example: <a href="http://www.x.com/hello.php" rel="nofollow noreferrer">http://www.x.com/hello.php</a> -- > <a href="http://www.x.com/default.php" rel="nofollow noreferrer">http://www.x.com/default.php</a> Example: <a href="http://www.x.com/test/hello.php" rel="nofollow noreferrer">http://www.x.com/test/hello.php</a> -- > <a href="http://www.x.com/test/default.php" rel="nofollow noreferrer">http://www.x.com/test/default.php</a></p>
[ { "answer_id": 331593, "author": "xahtep", "author_id": 42184, "author_profile": "https://Stackoverflow.com/users/42184", "pm_score": 1, "selected": false, "text": "[L]" }, { "answer_id": 331649, "author": "Nick Berardi", "author_id": 17, "author_profile": "https://Stackoverflow.com/users/17", "pm_score": 0, "selected": false, "text": "RewriteEngine On\nRewriteCond %{SCRIPT_FILENAME} !-f\nRewriteCond %{SCRIPT_FILENAME} !-d\nRewriteRule (/test/)?(.*) $1/default.php \nDirectoryIndex index.php /default.php\n" }, { "answer_id": 331675, "author": "Stepan Mazurov", "author_id": 40786, "author_profile": "https://Stackoverflow.com/users/40786", "pm_score": 0, "selected": false, "text": "RewriteEngine On\nRewriteCond %{SCRIPT_FILENAME} !-f\nRewriteCond %{SCRIPT_FILENAME} !-d\nRewriteRule (test/)?(.*) $1default.php [L]\nDirectoryIndex index.php /default.php\n" }, { "answer_id": 1039858, "author": "Louis W", "author_id": 107763, "author_profile": "https://Stackoverflow.com/users/107763", "pm_score": 0, "selected": false, "text": "RewriteEngine On\nRewriteCond %{SCRIPT_FILENAME} !-f\nRewriteCond %{SCRIPT_FILENAME} !-d\n\nRewriteRule /test/.* /test/default.php \nRewriteRule .* /default.php \n\nDirectoryIndex index.php /default.php\n" }, { "answer_id": 1039887, "author": "Andrew Moore", "author_id": 26210, "author_profile": "https://Stackoverflow.com/users/26210", "pm_score": 0, "selected": false, "text": "RewriteEngine On\nRewriteCond %{SCRIPT_FILENAME} !-f\nRewriteCond %{SCRIPT_FILENAME} !-d\nRewriteRule .* default.php [L]\nDirectoryIndex index.php default.php\n ./test/ .htaccess / .htaccess .htaccess ./test/.htaccess ./.htaccess" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331549", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
331,553
<p>I have a control which the user can resize with the mouse. When they move the right side, I just change the width, and everything works fine.</p> <p>However, when they move the left size, I have to change the Left and Width properties. The right hand side of the control visibly twitches, showing the old width in the new position. </p> <p>It still twitches if I set both left and width at once using Bounds; whether or not I use SetStyle with any of UserPaint, Opaque, OptimizedDoubleBuffer, AllPaintingInWmPaint or ResizeRedraw; and whether or not it's double buffered. It still twitches if I call SuspendLayout()/ResumeLayout() on either the control or its parent.</p> <p>How do I stop controls from twitching when I change their left positions and their widths?</p>
[ { "answer_id": 331617, "author": "Zachary Yates", "author_id": 8360, "author_profile": "https://Stackoverflow.com/users/8360", "pm_score": 3, "selected": false, "text": "Control.SuspendLayout() Control.ResumeLayout()" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331553", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15371/" ]
331,564
<p>I have a class Customer in app_code folder in asp.net web site, how can I create an instance using reflection, for example using Activator.CreateInstance(assemblyName, typeName)? Because the app_code is dynamically compiled, I don't know the assembly in design time?</p> <p>Thanks Fred</p> <p>The question is should be how get a full name of type in design time, I want to put it in web.config. I have ConfigSection type, it is in app_code folder, I need to declare it in configSection. Thanks</p>
[ { "answer_id": 2688879, "author": "Flatlineato", "author_id": 184353, "author_profile": "https://Stackoverflow.com/users/184353", "pm_score": 1, "selected": false, "text": "Type[] appCodeTypes = System.Reflection.Assembly.Load(\"App_Code\").GetTypes();\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331564", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
331,566
<p>The other day I decided to write an implementation of <a href="http://en.wikipedia.org/wiki/Radix_sort" rel="nofollow noreferrer">radix sort</a> in Java. Radix sort is supposed to be O(k*N) but mine ended up being O(k^2*N) because of the process of breaking down each digit to one number. I broke down each digit by modding (%) the preceding digits out and dividing by ten to eliminate the succeeding digits. I asked my professor if there would be a more efficient way of doing this and he said to use bit operators. Now for my questions: Which method would be the fastest at breaking down each number in Java, 1) Method stated above. 2) Convert number to String and use substrings. 3) Use bit operations. </p> <p>If 3) then how would that work?</p>
[ { "answer_id": 331584, "author": "Lou Franco", "author_id": 3937, "author_profile": "https://Stackoverflow.com/users/3937", "pm_score": 2, "selected": false, "text": "int key = (a[p] & mask) >> rshift;\n & >>" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331566", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29299/" ]
331,568
<p>I need to create an <code>XmlDocument</code> with a root element containing multiple namespaces. Am using C# 2.0 or 3.0</p> <p>Here is my code:</p> <pre><code>XmlDocument doc = new XmlDocument(); XmlElement root = doc.CreateElement("JOBS", "http://www.example.com"); doc.AppendChild(root); XmlElement job = doc.CreateElement("JOB", "http://www.example.com"); root.AppendChild(job); XmlElement docInputs = doc.CreateElement("JOB", "DOCINPUTS", "http://www.example.com"); job.AppendChild(docInputs); XmlElement docInput = doc.CreateElement("JOB", "DOCINPUT", "http://www.example.com"); docInputs.AppendChild(docInput); XmlElement docOutput = doc.CreateElement("JOB", "DOCOUTPUT", "http://www.example.com"); docOutputs.AppendChild(docOutput); </code></pre> <p>The current output:</p> <pre><code>&lt;JOBS xmlns="http://www.example.com"&gt; &lt;JOB&gt; &lt;JOB:DOCINPUTS xmlns:JOB="http://www.example.com"&gt; &lt;JOB:DOCINPUT /&gt; &lt;/JOB:DOCINPUTS&gt; &lt;JOB:DOCOUTPUTS xmlns:JOB="http://www.example.com"&gt; &lt;JOB:DOCOUTPUT /&gt; &lt;/JOB:DOCOUTPUTS&gt; &lt;/JOB&gt; &lt;/JOBS&gt; </code></pre> <p>However, my desired output is:</p> <pre><code>&lt;JOBS xmlns:JOBS="http://www.example.com" xmlns:JOB="http://www.example.com"&gt; &lt;JOB&gt; &lt;JOB:DOCINPUTS&gt; &lt;JOB:DOCINPUT /&gt; &lt;/JOB:DOCINPUTS&gt; &lt;JOB:DOCOUTPUTS&gt; &lt;JOB:DOCOUTPUT /&gt; &lt;/JOB:DOCOUTPUTS&gt; &lt;/JOB&gt; &lt;/JOBS&gt; </code></pre> <p>My question: how do I create an <code>XmlDocument</code> that contains a root element with multiple namespaces?</p>
[ { "answer_id": 331645, "author": "Dirk Vollmar", "author_id": 40347, "author_profile": "https://Stackoverflow.com/users/40347", "pm_score": 0, "selected": false, "text": " XmlDocument doc = new XmlDocument();\n\n XmlElement root = doc.CreateElement(\"JOBS\", \"http://www.example.com\");\n root.SetAttribute(\"xmlns:JOB\", \"http://www.example.com\"); \n\n doc.AppendChild(root);\n\n XmlElement job = doc.CreateElement(\"JOB\", \"http://www.example.com\");\n root.AppendChild(job);\n\n XmlElement docInputs = doc.CreateElement(\"JOB\", \"DOCINPUTS\", \"http://www.example.com\");\n job.AppendChild(docInputs);\n\n XmlElement docInput = doc.CreateElement(\"JOB\", \"DOCINPUT\", \"http://www.example.com\");\n docInputs.AppendChild(docInput);\n\n XmlElement docOutput = doc.CreateElement(\"JOB\", \"DOCOUTPUT\", \"http://www.example.com\");\n root.AppendChild(docOutput); \n" }, { "answer_id": 332204, "author": "Robert Rossney", "author_id": 19403, "author_profile": "https://Stackoverflow.com/users/19403", "pm_score": 3, "selected": false, "text": " using System;\n using System.Xml;\n\n static void Main(string[] args)\n {\n XmlDocument d = new XmlDocument();\n XmlElement e = d.CreateElement(\"elm\");\n\n d.AppendChild(e);\n\n d.DocumentElement.SetAttribute(\"xmlns:a\", \"my_namespace\");\n\n e = d.CreateElement(\"a\", \"bar\", \"my_namespace\");\n d.DocumentElement.AppendChild(e);\n e = d.CreateElement(\"a\", \"baz\", \"other_namespace\");\n d.DocumentElement.AppendChild(e);\n e = d.CreateElement(\"b\", \"bar\", \"my_namespace\");\n d.DocumentElement.AppendChild(e);\n\n d.Save(Console.Out);\n\n Console.ReadLine();\n }\n" }, { "answer_id": 332444, "author": "Oppositional", "author_id": 2029, "author_profile": "https://Stackoverflow.com/users/2029", "pm_score": 6, "selected": true, "text": "XmlDocument doc = new XmlDocument();\n\nXmlElement root = doc.CreateElement(\"JOBS\");\nroot.SetAttribute(\"xmlns:JOBS\", \"http://www.example.com\");\nroot.SetAttribute(\"xmlns:JOB\", \"http://www.example.com\");\ndoc.AppendChild(root);\n\nXmlElement job = doc.CreateElement(\"JOB\");\n\nXmlElement docInputs = doc.CreateElement(\"JOB\", \"DOCINPUTS\", \"http://www.example.com\");\nXmlElement docInput = doc.CreateElement(\"JOB\", \"DOCINPUT\", \"http://www.example.com\");\ndocInputs.AppendChild(docInput);\njob.AppendChild(docInputs);\n\nXmlElement docOutputs = doc.CreateElement(\"JOB\", \"DOCOUTPUTS\", \"http://www.example.com\");\nXmlElement docOutput = doc.CreateElement(\"JOB\", \"DOCOUTPUT\", \"http://www.example.com\");\ndocOutputs.AppendChild(docOutput);\njob.AppendChild(docOutputs);\n\ndoc.DocumentElement.AppendChild(job);\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331568", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9664/" ]
331,569
<p>When trying to kill a buffer that contains changes in Emacs, the message: " Buffer [buffer] modified; kill anyway? (yes or no)" is displayed. </p> <p>Instead of this I'd like to have Emacs ask me if I want to: 1. View a diff of what changed, 2. Save the buffer, 3. Kill the buffer.</p> <p>How?</p>
[ { "answer_id": 334600, "author": "Trey Jackson", "author_id": 6148, "author_profile": "https://Stackoverflow.com/users/6148", "pm_score": 6, "selected": true, "text": " (defadvice kill-buffer (around my-kill-buffer-check activate)\n \"Prompt when a buffer is about to be killed.\"\n (let* ((buffer-file-name (buffer-file-name))\n backup-file)\n ;; see 'backup-buffer\n (if (and (buffer-modified-p)\n buffer-file-name\n (file-exists-p buffer-file-name)\n (setq backup-file (car (find-backup-file-name buffer-file-name))))\n (let ((answer (completing-read (format \"Buffer modified %s, (d)iff, (s)ave, (k)ill? \" (buffer-name))\n '(\"d\" \"s\" \"k\") nil t)))\n (cond ((equal answer \"d\")\n (set-buffer-modified-p nil)\n (let ((orig-buffer (current-buffer))\n (file-to-diff (if (file-newer-than-file-p buffer-file-name backup-file)\n buffer-file-name\n backup-file)))\n (set-buffer (get-buffer-create (format \"%s last-revision\" (file-name-nondirectory file-to-diff))))\n (buffer-disable-undo)\n (insert-file-contents file-to-diff nil nil nil t)\n (set-buffer-modified-p nil)\n (setq buffer-read-only t)\n (ediff-buffers (current-buffer) orig-buffer)))\n ((equal answer \"k\")\n (set-buffer-modified-p nil)\n ad-do-it)\n (t\n (save-buffer)\n ad-do-it)))\n ad-do-it)))\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331569", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41829/" ]
331,594
<p>Has anybody had any success ever attaching a debugger to a tethered device? I am able to debug my j2me application in the emulator, but have a lot of trouble sorting out phone-specific problems when they come up. The phone I'm using is a Nokia N95, but ideally the debug process would work on any phone.</p> <p>Is this possible? If so does anyone have steps they've used to set it up?</p>
[ { "answer_id": 8032802, "author": "Megha", "author_id": 645937, "author_profile": "https://Stackoverflow.com/users/645937", "pm_score": 0, "selected": false, "text": "Log.p(\"Log statement.....\"); LogMidlet.java \n// Add the following line in the startup method of this midlet.\n Log.getInstance().showLog();\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331594", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8207/" ]
331,599
<p>I am using a nested html unordered list styled as a drop down. When the a tag within the inner lists list item is clicked it trigger some javascript which is supposed to set the value of a hidden field to the text for the link that was clicked.</p> <p>The javascript seems to work - I used an alert to read the value from the hidden field but then when I try to put that value in the querystring in my asp.net c# code behind - it pulls the initial value - not the javascript set value.</p> <p>I guess this is because the javascript is client side not server side but has anyone any idea how i can get this working</p> <p><strong>HTML</strong></p> <pre><code> &lt;div class="dropDown accomodation"&gt; &lt;label for="accomodationList"&gt;Type of accomodation&lt;/label&gt; &lt;ul class="quicklinks" id="accomodationList"&gt; &lt;li&gt;&lt;a href="#" title="Quicklinks" id="accomodationSelectList"&gt;All types &lt;!--[if IE 7]&gt;&lt;!--&gt;&lt;/a&gt;&lt;!--&lt;![endif]--&gt; &lt;!--[if lte IE 6]&gt;&lt;table&gt;&lt;tr&gt;&lt;td&gt;&lt;![endif]--&gt; &lt;ul id="sub" onclick="dropDownSelected(event,'accomodation');"&gt; &lt;li&gt;&lt;a href="#" id="val=-1$#$All types" &gt;All types&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#" id="val=1$#$Villa" &gt;Villa&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#" id="val=2$#$Studio" &gt;Studio&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#" id="val=3$#$Apartment" &gt;Apartment&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a class="last" href="#" id="val=4$#$Rustic Properties" &gt;Rustic Properties&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;!--[if lte IE 6]&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/a&gt;&lt;![endif]--&gt; &lt;/li&gt;&lt;/ul&gt; &lt;/div&gt; &lt;input type="hidden" ID="accomodationAnswer" runat="server" /&gt; </code></pre> <p><strong>javascript</strong></p> <pre><code> if(isChildOf(document.getElementById(parentList),document.getElementById(targ.id)) == true) { document.getElementById(parentLi).innerHTML = tname; document.getElementById(hiddenFormFieldName).Value = targ.id; alert('selected id is ' + targ.id + ' value in hidden field is ' + document.getElementById(hiddenFormFieldName).Value); } </code></pre> <p><strong>C# code</strong></p> <pre><code>String qstr = "accom=" + getValFromLiId(accomodationAnswer.Value) + "&amp;sleeps=" + getValFromLiId(sleepsAnswer.Value) + "&amp;nights=" + getValFromLiId(nightsAnswer.Value) + "&amp;region=" + getValFromLiId(regionAnswer.Value) + "&amp;price=" + Utilities.removeCurrencyFormatting(priceAnswer.Value); </code></pre>
[ { "answer_id": 331756, "author": "Jason Bunting", "author_id": 1790, "author_profile": "https://Stackoverflow.com/users/1790", "pm_score": 4, "selected": false, "text": "runat='server' <input type=\"hidden\" id=\"accomodationAnswer\" />\n string accomodationAnswer = Request.Form[\"accomodationAnswer\"];\n\n// now use accomodationAnswer instead of accomodationAnswer.Value \n// in the C# code that you indicated you are using\n" }, { "answer_id": 13305120, "author": "Raj", "author_id": 1386684, "author_profile": "https://Stackoverflow.com/users/1386684", "pm_score": 3, "selected": false, "text": "ClientIDMode=\"Static\"\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331599", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40623/" ]
331,607
<p>I don't have too much experience with C# so if someone could point me in the right direction I would greatly appreciate it. I have a foreach loop that references a variable of an object. I wish to make another foreach loop inside the main one that compares (or performs actions on) the current variable to the rest of the variables in the array of the object. I have the following code:</p> <pre><code>// Integrate forces for each body. foreach (RigidBodyBase body in doc.Bodies) { // Don't move background-anchored bodies. if (body.anchored) continue; // This is where we will add Each Body's gravitational force // to the total force exerted on the object. // For each other body, get it's point and it's mass. // Find the gravitational force exterted between target body and looped body. // Find distance between bodies. // vector addition // Force = G*mass1*mass2/distance^2 // Find vector of that force. // Add Force to TotalGravityForce // loop until there are no more bodies. // Add TotalGravityForce to body.totalForce } </code></pre>
[ { "answer_id": 331632, "author": "Vilx-", "author_id": 41360, "author_profile": "https://Stackoverflow.com/users/41360", "pm_score": 2, "selected": false, "text": "int l = doc.Bodies.Count;\nfor ( int i = 0; i < l; i++ )\n for ( int j = i + 1; j < l; j++ )\n // Do stuff \n" }, { "answer_id": 331640, "author": "Charles Bretana", "author_id": 32632, "author_profile": "https://Stackoverflow.com/users/32632", "pm_score": 5, "selected": true, "text": " foreach( RigidBodyBase body in doc.Bodies)\n foreach ( RigidBodyBase otherBody in doc.Bodies)\n if (!otherBody.Anchored && otherBody != body) // or otherBody.Id != body.Id -- whatever is required... \n // then do the work here\n foreach (RigidBodyBase body in doc.Bodies)\n body.TotalForce += body.GravityForce; \n" }, { "answer_id": 331653, "author": "Charles Graham", "author_id": 7705, "author_profile": "https://Stackoverflow.com/users/7705", "pm_score": 1, "selected": false, "text": "foreach (RigidBodyBase body in doc.Bodies) \n{ \n Integrateforces(ref body, Bodies);\n}\n\n...\n\npublic void Integrateforces(RigidBodyBase out body, RigidBodyBase[] Bodies)\n{\n //Put your integration logic here\n}\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331607", "https://Stackoverflow.com", "https://Stackoverflow.com/users/33523/" ]
331,615
<p>I am currently starting my Java VM with the <strong><code>com.sun.management.jmxremote.*</code></strong> properties so that I can connect to it via JConsole for management and monitoring. Unfortunately, it listens on all interfaces (IP addresses) on the machine.</p> <p>In our environment, there are often cases where there is more than one Java VM running on a machine at the same time. While it's possible to tell JMX to listen on different TCP ports (using <code>com.sun.management.jmxremote.port</code>), it would be nice to instead have JMX use the standard JMX port and just bind to a specific IP address (rather than all of them).</p> <p>This would make it much easier to figure out which VM we're connecting to via JConsole (since each VM effectively "owns" its own IP address). Has anyone figured out how to make JMX listen on a single IP address or hostname?</p>
[ { "answer_id": 25855193, "author": "sosiouxme", "author_id": 262768, "author_profile": "https://Stackoverflow.com/users/262768", "pm_score": -1, "selected": false, "text": "-Djava.rmi.server.hostname=<YOUR_IP>\n -Dcom.sun.management.jmxremote.host=<YOUR_IP>\n" }, { "answer_id": 38859202, "author": "Niranjan", "author_id": 5869572, "author_profile": "https://Stackoverflow.com/users/5869572", "pm_score": 0, "selected": false, "text": "package sun.rmi.transport.proxy;\n\nimport java.io.IOException;\nimport java.net.InetAddress;\nimport java.net.ServerSocket;\nimport java.net.Socket;\nimport java.rmi.server.RMISocketFactory;\n\npublic class RMIDirectSocketFactory extends RMISocketFactory {\n\n public Socket createSocket(String host, int port) throws IOException\n {\n return new Socket(host, port);\n }\n\n public ServerSocket createServerSocket(int port) throws IOException\n {\n String jmx_host = System.getProperty(\"com.sun.management.jmxremote.host\");\n String jmx_port = System.getProperty(\"com.sun.management.jmxremote.port\");\n\n // Allow JMX to bind to specific address\n if (jmx_host != null && jmx_port != null && port != 0 && integer.toString(port).equals(jmx_port)) {\n InetAddress[] inetAddresses = InetAddress.getAllByName(jmx_host);\n if (inetAddresses.length > 0) {\n return new ServerSocket(port, 50, inetAddresses[0]);\n }\n}\n\n return new ServerSocket(port);\n }\n" }, { "answer_id": 39345042, "author": "Gašper", "author_id": 1199358, "author_profile": "https://Stackoverflow.com/users/1199358", "pm_score": 6, "selected": true, "text": "-Dcom.sun.management.jmxremote.host" }, { "answer_id": 68507412, "author": "Ivan", "author_id": 2075565, "author_profile": "https://Stackoverflow.com/users/2075565", "pm_score": 0, "selected": false, "text": "com.sun.management.jmxremote.host com.sun.management.jmxremote.ssl true com.sun.management.jmxremote.registry.ssl false com.sun.management.jmxremote.port com.sun.management.jmxremote.host com.sun.management.jmxremote.rmi.port jmxremote.ssl jmxremote.registry.ssl jmxremote.host -Dcom.sun.management.jmxremote.authenticate=false\n -Dcom.sun.management.jmxremote.port=1234\n -Dcom.sun.management.jmxremote.host=interface1\n \n 1234 interface1 jmxremote.rmi.port jmxremote.port jmxremote.rmi.port jmxremote.host jmxremote.port" }, { "answer_id": 71298285, "author": "RubenLaguna", "author_id": 90580, "author_profile": "https://Stackoverflow.com/users/90580", "pm_score": 0, "selected": false, "text": "com.sun.management.jmxremote.{host,port,ssl} com.sun.management.jmxremote.host java.rmi.server.hostname java.rmi.server.hostname /usr/lib/jvm/java-8-openjdk-amd64//bin/java \\\n-Dcom.sun.management.jmxremote.host=127.0.0.1 \\\n-Djava.rmi.server.hostname=127.0.0.1 \\\n-Dcom.sun.management.jmxremote.port=2222 \\\n-Dcom.sun.management.jmxremote.ssl=false \\\n-Dcom.sun.management.jmxremote.registry.ssl=false \\\n-Dcom.sun.management.jmxremote.authenticate=false \\\n-Djava.net.preferIPv4Stack=true \\\n-jar your-uber.jar\n \n netstat -plnt|grep 2222\nActive Internet connections (only servers)\nProto Recv-Q Send-Q Local Address Foreign Address State PID/Program name\ntcp 0 0 127.0.0.1:2222 0.0.0.0:* LISTEN 15390/java\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331615", "https://Stackoverflow.com", "https://Stackoverflow.com/users/27020/" ]
331,620
<p>Okay I have this RewriteRule which is supposed to redirect any request for the file base.css to {folder of .htacces file}/include/style/base.css, but is just keeps redirecting in an infinite loop, I thought the L parameter would make sure that wouldn't happen.</p> <pre><code>RewriteRule (.*)/base.css$ include/style/base.css [L,NC,R=301] </code></pre> <p>Also it redirects to <a href="http://localhost/C:/somemaps/include/style/base.css" rel="nofollow noreferrer">http://localhost/C:/somemaps/include/style/base.css</a> which it isn't really supposed to do either.</p> <p>Can anyone tell me how to fix this?<br> Also I would like to have the RewriteRule so it would redirect any file.css to {folder of .htacces file}/include/style/file.css<br> BTW the .htacces file is in the root of the website (which is not the root of the server!)</p>
[ { "answer_id": 331625, "author": "Nick Berardi", "author_id": 17, "author_profile": "https://Stackoverflow.com/users/17", "pm_score": 3, "selected": true, "text": "RewriteRule (.*)/(.*).css$ /include/style/$2.css [L,NC]\n RewriteBase /my-virtual-folder-path-where-htaccess-is-stored\n" }, { "answer_id": 331647, "author": "Eli", "author_id": 5958, "author_profile": "https://Stackoverflow.com/users/5958", "pm_score": 2, "selected": false, "text": "RewriteRule ([^/]+).css$ /include/style/$1.css [L,NC]\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331620", "https://Stackoverflow.com", "https://Stackoverflow.com/users/35197/" ]
331,635
<p>There is an executable that is dynamically linked to number of shared objects. How can I determine, to which of them some symbol (imported into executable) belongs ?</p> <p>If there are more than one possibility, could I silmulate ld and see from where it is being taken ?</p>
[ { "answer_id": 339806, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "ld -y $ cat t.c\nint main() { printf(\"Hello\\n\"); return 0; } \n\n$ gcc t.c -Wl,-yprintf \n/lib/libc.so.6: definition of printf\n ldd 'nm -D' grep" }, { "answer_id": 555674, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "$LD_DEBUG=bindings my_program\n" } ]
2008/12/01
[ "https://Stackoverflow.com/questions/331635", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18174/" ]