qid int64 4 19.1M | question stringlengths 18 48.3k | answers list | date stringlengths 10 10 | metadata list |
|---|---|---|---|---|
314,466 | <p>Is there an easy way to generate an array containing the letters of the alphabet in C#? It's not too hard to do it by hand, but I was wondering if there was a built in way to do this. </p>
| [
{
"answer_id": 314475,
"author": "Bob",
"author_id": 45,
"author_profile": "https://Stackoverflow.com/users/45",
"pm_score": 9,
"selected": true,
"text": " char[] alpha = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\".ToCharArray();\n"
},
{
"answer_id": 314499,
"author": "xan",
"author_id": 15667,
"author_profile": "https://Stackoverflow.com/users/15667",
"pm_score": 3,
"selected": false,
"text": "char[26] alphabet;\n\nfor(int i = 0; i <26; i++)\n{\n alphabet[i] = (char)(i+65); //65 is the offset for capital A in the ascaii table\n}\n alphabet[i] = (char)(i+(int)('A'));\n"
},
{
"answer_id": 314501,
"author": "rp.",
"author_id": 2536,
"author_profile": "https://Stackoverflow.com/users/2536",
"pm_score": 4,
"selected": false,
"text": " for ( int i = 0; i < 26; i++ )\n {\n Console.WriteLine( Convert.ToChar( i + 65 ) );\n }\n Console.WriteLine( \"Press any key to continue.\" );\n Console.ReadKey();\n"
},
{
"answer_id": 314508,
"author": "Pop Catalin",
"author_id": 4685,
"author_profile": "https://Stackoverflow.com/users/4685",
"pm_score": 7,
"selected": false,
"text": "char[] az = Enumerable.Range('a', 'z' - 'a' + 1).Select(i => (Char)i).ToArray();\nforeach (var c in az)\n{\n Console.WriteLine(c);\n}\n"
},
{
"answer_id": 314745,
"author": "James Curran",
"author_id": 12725,
"author_profile": "https://Stackoverflow.com/users/12725",
"pm_score": 3,
"selected": false,
"text": "IEnumerable<char> string alpha = \"ABCDEFGHIJKLMNOPQRSTUVQXYZ\";\nfor (int i =0; i < 26; ++i)\n{ \n Console.WriteLine(alpha[i]);\n}\n\nforeach(char c in alpha)\n{ \n Console.WriteLine(c);\n}\n"
},
{
"answer_id": 1591512,
"author": "aa.",
"author_id": 192731,
"author_profile": "https://Stackoverflow.com/users/192731",
"pm_score": 0,
"selected": false,
"text": "char alphaStart = Char.Parse(\"A\");\nchar alphaEnd = Char.Parse(\"Z\");\nfor(char i = alphaStart; i <= alphaEnd; i++) {\n string anchorLetter = i.ToString();\n}\n"
},
{
"answer_id": 3264397,
"author": "rjdmello",
"author_id": 171351,
"author_profile": "https://Stackoverflow.com/users/171351",
"pm_score": 0,
"selected": false,
"text": "//generate a list of alphabet using csharp\n//this recurcive function will return you\n//a string with position of passed int\n//say if pass 0 will return A ,1-B,2-C,.....,26-AA,27-AB,....,701-ZZ,702-AAA,703-AAB,...\n\nstatic string CharacterIncrement(int colCount)\n{\n int TempCount = 0;\n string returnCharCount = string.Empty;\n\n if (colCount <= 25)\n {\n TempCount = colCount;\n char CharCount = Convert.ToChar((Convert.ToInt32('A') + TempCount));\n returnCharCount += CharCount;\n return returnCharCount;\n }\n else\n {\n var rev = 0;\n\n while (colCount >= 26)\n {\n colCount = colCount - 26;\n rev++;\n }\n\n returnCharCount += CharacterIncrement(rev-1);\n returnCharCount += CharacterIncrement(colCount);\n return returnCharCount;\n }\n}\n\n//--------this loop call this function---------//\nint i = 0;\nwhile (i <>\n {\n string CharCount = string.Empty;\n CharCount = CharacterIncrement(i);\n\n i++;\n }\n"
},
{
"answer_id": 5271891,
"author": "Nyerguds",
"author_id": 395685,
"author_profile": "https://Stackoverflow.com/users/395685",
"pm_score": 5,
"selected": false,
"text": "column--; public static String getColumnNameFromIndex(int column)\n{\n column--;\n String col = Convert.ToString((char)('A' + (column % 26)));\n while (column >= 26)\n {\n column = (column / 26) -1;\n col = Convert.ToString((char)('A' + (column % 26))) + col;\n }\n return col;\n}\n"
},
{
"answer_id": 7020965,
"author": "Simon",
"author_id": 53158,
"author_profile": "https://Stackoverflow.com/users/53158",
"pm_score": 6,
"selected": false,
"text": "for (char letter = 'A'; letter <= 'Z'; letter++)\n{\n Debug.WriteLine(letter);\n}\n"
},
{
"answer_id": 13931746,
"author": "weston",
"author_id": 360211,
"author_profile": "https://Stackoverflow.com/users/360211",
"pm_score": 3,
"selected": false,
"text": "public static IEnumerable<char> Alphabet()\n{\n for (char letter = 'A'; letter <= 'Z'; letter++)\n {\n yield return letter;\n }\n}\n foreach (var c in Alphabet())\n{\n Console.Write(c);\n}\n"
},
{
"answer_id": 21770002,
"author": "Rezo Megrelidze",
"author_id": 2204040,
"author_profile": "https://Stackoverflow.com/users/2204040",
"pm_score": 6,
"selected": false,
"text": "char[] alphabet = Enumerable.Range('A', 26).Select(x => (char)x).ToArray();\n"
},
{
"answer_id": 52518490,
"author": "Pradeep T M",
"author_id": 4600145,
"author_profile": "https://Stackoverflow.com/users/4600145",
"pm_score": 3,
"selected": false,
"text": "var alphabets = Enumerable.Range('A', 26).Select((num) => ((char)num).ToString()).ToList();\n"
},
{
"answer_id": 58150142,
"author": "Paul Alexeev",
"author_id": 10391572,
"author_profile": "https://Stackoverflow.com/users/10391572",
"pm_score": 0,
"selected": false,
"text": "public void ShowEnglishAlphabet()\n{\n var firstLetter = 'a';\n var endLetter = 'z';\n for (var letter = firstLetter; letter <= endLetter; letter++)\n {\n Console.WriteLine($\"{letter}-{letter.ToString().ToUpper()}\");\n }\n}\n\npublic void ShowEnglishAlphabetFromUnicodeTableDecNumber()\n{\n var firstLetter = 97;\n var endLetter = 122;\n for (var letterNumberUnicodeTable = firstLetter; \n letterNumberUnicodeTable <= endLetter; letterNumberUnicodeTable++)\n {\n Console.WriteLine($\"{(char)letterNumberUnicodeTable}- \n {((char)letterNumberUnicodeTable).ToString().ToUpper()}\");\n }\n}\n\npublic void ShowEnglishAlphabetUnicodeTableEscapeSequence()\n{\n var firstLetter = '\\u0061';\n var endLetter = '\\u007A';\n for (var letterNumberUnicodeTable = firstLetter; \n letterNumberUnicodeTable <= endLetter; letterNumberUnicodeTable++)\n {\n Console.WriteLine($\"{letterNumberUnicodeTable}- \n {letterNumberUnicodeTable.ToString().ToUpper()}\");\n }\n} \n\npublic void ShowEnglishAlphabetUnicodeTableLinq()\n{\n var alphabets = Enumerable.Range('a', 26).Select(letter => \n ((char)letter).ToString()).ToList();\n foreach (var letter in alphabets)\n {\n Console.WriteLine($\"{letter}-{letter.ToUpper()}\");\n }\n}\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314466",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13028/"
] |
314,467 | <p>I'm looking for articles, forum or blog posts dealing with SharePoint and thread safety? I'm quite sure there are some special aspects regarding thread safety that have to be considered when working with the SharePoint object model.</p>
<p>Actually I didn't find many information about this, yet.</p>
<p>So I'm looking forward to your answers. </p>
<p>Bye,
Flo</p>
| [
{
"answer_id": 314534,
"author": "x0n",
"author_id": 6920,
"author_profile": "https://Stackoverflow.com/users/6920",
"pm_score": 3,
"selected": false,
"text": "var list = web.List[\"MyList\"]\nlist.Items[0][\"Field1\"] = \"foo\"\nlist.Items[0][\"Field2\"] = \"bar\"\nlist.Items[0].Update() // nothing is updated!\n SPListItem item = list.Items[0]\nitem[\"Field1\"] = \"foo\"\nitem[\"Field2\"] = \"bar\"\nitem.Update() // updated!\n"
},
{
"answer_id": 314576,
"author": "vitule",
"author_id": 1287,
"author_profile": "https://Stackoverflow.com/users/1287",
"pm_score": 2,
"selected": false,
"text": "ItemAdded()"
},
{
"answer_id": 341583,
"author": "Flo",
"author_id": 19601,
"author_profile": "https://Stackoverflow.com/users/19601",
"pm_score": 1,
"selected": true,
"text": "web11.Update() SPSite siteCol1 = new SPSite(\"http://localhost\"); \n\nSPWeb web11 = siteCol1.OpenWeb();\nSPWeb web12 = siteCol1.OpenWeb(); \n\nweb12.Title = \"web12\";\nweb12.Update();\n\nweb11.Title = \"web11\";\nweb11.Update();\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314467",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19601/"
] |
314,468 | <p>For some reason the system admin changed my user name from XxXx to XxXx1 in the source control system. Then the problems started. I had to delete all local files and re-download them from source control just to open the project.</p>
<p>And after I had rebooted the computer, I can't do much to my files. Whenever I try to undo a checkout I get the following message:</p>
<blockquote>
<p>TF14098: Access Denied: User DOMAIN\XxXx needs UndoOther permission(s) for $/blablabla</p>
</blockquote>
<p>So it is still trying to use my old user name. The user name and password is stored somewhere because I don't ever have to enter it when starting VS2008. Maybe through Explorer (I think I used it to browse to the tfs server and saved the user name and password).</p>
<p>Any tips?</p>
| [
{
"answer_id": 319821,
"author": "JB Brown",
"author_id": 21360,
"author_profile": "https://Stackoverflow.com/users/21360",
"pm_score": 2,
"selected": false,
"text": "tf undo \"$/MyProject/VersionX/Utils/file.cs\" /WORKSPACE:MaorDev;Domain\\User /server:MyServerName /recursive\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314468",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3397/"
] |
314,481 | <p>I am fetching data in from an SQL table using a DataSet in VB.Net. When there is data in table, it displays the data properly in the grid, but when there is no data in the table, it only shows the UltraGrid's basic view.</p>
<p>How can I display the column names of the table as headings of the UltraGrid even when there is no data in Table?</p>
<hr>
<p>Thanks for the reply, but I think the problem that JD is having is a bit different from mine - in my application the data got fetched properly from SQL Server. My problem is that when there is no data in the table, I want to display the columns of the table as the headings of the grid with 0 rows. This is not happening.</p>
<p>It just shows a message box saying that no data is found, and the UltraGrid shows as it does by default in the application.</p>
| [
{
"answer_id": 319821,
"author": "JB Brown",
"author_id": 21360,
"author_profile": "https://Stackoverflow.com/users/21360",
"pm_score": 2,
"selected": false,
"text": "tf undo \"$/MyProject/VersionX/Utils/file.cs\" /WORKSPACE:MaorDev;Domain\\User /server:MyServerName /recursive\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314481",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40293/"
] |
314,492 | <p>I've got an array of <code>char*</code> in a file.
The company I work for stores data in flat files.. Sometimes the data is sorted, but sometimes it's not.
I'd like to sort the data in the files.</p>
<p>Now I could write the code to do this, from scratch.
Is there an easier way? </p>
<p>Of course an in-place sort would be the best option. I'm working on large files and have little RAM. But I'll consider all options. </p>
<p>All strings are the same length. </p>
<p>This is some sample data:</p>
<pre><code>the data is of fixed length
the Data is of fixed length
thIS data is of fixed lengt
</code></pre>
<p>This would represent three records of length 28. The app knows the length. Each record ends with CRLF (<code>\r\n</code>), though it shouldn't matter for this sort. </p>
| [
{
"answer_id": 314527,
"author": "Leon Timmermans",
"author_id": 4727,
"author_profile": "https://Stackoverflow.com/users/4727",
"pm_score": 5,
"selected": true,
"text": "template<size_t length> int less(const char* left, const char* right) {\n return memcmp(left, right, length) < 0;\n}\n\nstd::sort(array, array + array_length, less<buffer_length>);\n"
},
{
"answer_id": 314533,
"author": "Ralf",
"author_id": 39645,
"author_profile": "https://Stackoverflow.com/users/39645",
"pm_score": 2,
"selected": false,
"text": "qsort( array, num_elements, sizeof( char* ), strcmp )\n"
},
{
"answer_id": 314556,
"author": "John Dibling",
"author_id": 241536,
"author_profile": "https://Stackoverflow.com/users/241536",
"pm_score": 3,
"selected": false,
"text": "struct string_lt : public std::binary_function<bool, char, char>\n{\n bool operator()(const char* lhs, const char* rhs)\n {\n int ret = strcmp(lhs, rhs);\n return ret < 0;\n }\n};\n\nint _tmain(int argc, _TCHAR* argv[])\n{\n char* strings [] = {\"Hello\", \"World\", \"Alpha\", \"Beta\", \"Omega\"};\n size_t numStrings = sizeof(strings)/sizeof(strings[0]);\n\n std::sort(&strings[0], &strings[numStrings], string_lt());\n\n return 0;\n}\n"
},
{
"answer_id": 314606,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 2,
"selected": false,
"text": "boost::bind // ascending\nstd::sort(c, c + size, boost::bind(std::strcmp, _1, _2) < 0); \n\n// descending\nstd::sort(c, c + size, boost::bind(std::strcmp, _1, _2) > 0); \n // ascending\nstd::sort(c, c + array_size, boost::bind(std::memcmp, _1, _2, size) < 0); \n\n// descending\nstd::sort(c, c + array_size, boost::bind(std::memcmp, _1, _2, size) > 0); \n"
},
{
"answer_id": 314827,
"author": "Jonathan Leffler",
"author_id": 15168,
"author_profile": "https://Stackoverflow.com/users/15168",
"pm_score": 0,
"selected": false,
"text": "strcmp() static int qsort_strcmp(const void *v1, const void *v2)\n{\n const char *s1 = *(char * const *)v1;\n const char *s2 = *(char * const *)v2;\n return(strcmp(s1, s2));\n}\n\nstatic void somefunc(void) // Or omit the parameter altogether in C++\n{\n char **array = ...assignment...\n size_t num_in_array = ...number of char pointers in array...\n ...\n qsort(array, num_in_array, sizeof(char *), qsort_strcmp);\n ...more code...\n}\n"
},
{
"answer_id": 317382,
"author": "Tom",
"author_id": 40620,
"author_profile": "https://Stackoverflow.com/users/40620",
"pm_score": 0,
"selected": false,
"text": "std::sort qsort str[0] str[K-1]"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314492",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31325/"
] |
314,493 | <p>I have an xml web service which I use at work to make a request to. This request, an xml document, includes information such as recipients, subject, body, etc (as a newsletter would contain).</p>
<p>I have an ASP.NET form to enter the above information to, to form the Xml document, and I can type foreign characters (non latin - Japanese, Chinese, Russian etc).</p>
<p>If I step through my code, the foreign characters are displayed ok. The xml has an encoding of utf-8 and I load the strings into the attributes of my xml document so I shouldn't need to do anything at a string level with encoding.</p>
<p>I am on webmail because of an unrelated technical matter, but my boss has Outlook 2007 Pro and hasn't got an email with a foreign text subject line. However, if the xml is manually posted via the internal test harness, as opposed to the .NET way of methods/variables (OOP) etc, it will work. So there is a failing in .NET somewhere.</p>
<p>Any ideas?</p>
| [
{
"answer_id": 314527,
"author": "Leon Timmermans",
"author_id": 4727,
"author_profile": "https://Stackoverflow.com/users/4727",
"pm_score": 5,
"selected": true,
"text": "template<size_t length> int less(const char* left, const char* right) {\n return memcmp(left, right, length) < 0;\n}\n\nstd::sort(array, array + array_length, less<buffer_length>);\n"
},
{
"answer_id": 314533,
"author": "Ralf",
"author_id": 39645,
"author_profile": "https://Stackoverflow.com/users/39645",
"pm_score": 2,
"selected": false,
"text": "qsort( array, num_elements, sizeof( char* ), strcmp )\n"
},
{
"answer_id": 314556,
"author": "John Dibling",
"author_id": 241536,
"author_profile": "https://Stackoverflow.com/users/241536",
"pm_score": 3,
"selected": false,
"text": "struct string_lt : public std::binary_function<bool, char, char>\n{\n bool operator()(const char* lhs, const char* rhs)\n {\n int ret = strcmp(lhs, rhs);\n return ret < 0;\n }\n};\n\nint _tmain(int argc, _TCHAR* argv[])\n{\n char* strings [] = {\"Hello\", \"World\", \"Alpha\", \"Beta\", \"Omega\"};\n size_t numStrings = sizeof(strings)/sizeof(strings[0]);\n\n std::sort(&strings[0], &strings[numStrings], string_lt());\n\n return 0;\n}\n"
},
{
"answer_id": 314606,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 2,
"selected": false,
"text": "boost::bind // ascending\nstd::sort(c, c + size, boost::bind(std::strcmp, _1, _2) < 0); \n\n// descending\nstd::sort(c, c + size, boost::bind(std::strcmp, _1, _2) > 0); \n // ascending\nstd::sort(c, c + array_size, boost::bind(std::memcmp, _1, _2, size) < 0); \n\n// descending\nstd::sort(c, c + array_size, boost::bind(std::memcmp, _1, _2, size) > 0); \n"
},
{
"answer_id": 314827,
"author": "Jonathan Leffler",
"author_id": 15168,
"author_profile": "https://Stackoverflow.com/users/15168",
"pm_score": 0,
"selected": false,
"text": "strcmp() static int qsort_strcmp(const void *v1, const void *v2)\n{\n const char *s1 = *(char * const *)v1;\n const char *s2 = *(char * const *)v2;\n return(strcmp(s1, s2));\n}\n\nstatic void somefunc(void) // Or omit the parameter altogether in C++\n{\n char **array = ...assignment...\n size_t num_in_array = ...number of char pointers in array...\n ...\n qsort(array, num_in_array, sizeof(char *), qsort_strcmp);\n ...more code...\n}\n"
},
{
"answer_id": 317382,
"author": "Tom",
"author_id": 40620,
"author_profile": "https://Stackoverflow.com/users/40620",
"pm_score": 0,
"selected": false,
"text": "std::sort qsort str[0] str[K-1]"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314493",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32484/"
] |
314,503 | <p>I have a combobox at the top of a form that loads editable data into fields below. If the user has made changes, but not saved, and tries to select a different option from the combobox, I want to warn them and give them a chance to cancel or save.</p>
<p>I am in need of a "BeforeValueChange" event with a cancelable event argument. </p>
<p>Any advice on how to accomplish?</p>
| [
{
"answer_id": 314536,
"author": "Vincent Van Den Berghe",
"author_id": 39259,
"author_profile": "https://Stackoverflow.com/users/39259",
"pm_score": 2,
"selected": false,
"text": "Enter BeforeValueChange ValueChanged ValueChanged return BeforeValuechange"
},
{
"answer_id": 314538,
"author": "configurator",
"author_id": 9536,
"author_profile": "https://Stackoverflow.com/users/9536",
"pm_score": 1,
"selected": false,
"text": "public void Combobox_ValueChanged(object sender, EventArgs e) {\n if (!AskUserIfHeIsSureHeWantsToChangeTheValue())\n {\n // Set previous value\n return;\n }\n\n // perform rest of onChange code\n}\n"
},
{
"answer_id": 1370717,
"author": "Denis Biondic",
"author_id": 155666,
"author_profile": "https://Stackoverflow.com/users/155666",
"pm_score": 4,
"selected": false,
"text": "cbx_Example.Enter += cbx_Example_Enter;\ncbx_Example.SelectionChangeCommitted += cbx_Example_SelectionChangeCommitted;\n\n...\n\nprivate int prevExampleIndex = 0;\nprivate void cbx_Example_Enter(object sender, EventArgs e)\n{\n prevExampleIndex = cbx_Example.SelectedIndex;\n}\n\nprivate void cbx_Example_SelectionChangeCommitted(object sender, EventArgs e)\n{\n // some custom flag to determine Edit mode\n if (mode == FormModes.EDIT) \n {\n cbx_Example.SelectedIndex = prevExampleIndex;\n }\n}\n"
},
{
"answer_id": 5733214,
"author": "Kushal Waikar",
"author_id": 212823,
"author_profile": "https://Stackoverflow.com/users/212823",
"pm_score": 3,
"selected": false,
"text": " bool isSelectionHandled = true;\n\n void CmbBx_SelectionChanged(object sender, SelectionChangedEventArgs e)\n {\n if (isSelectionHandled)\n {\n MessageBoxResult result = MessageBox.Show(\"Do you wish to continue selection change?\", this.Title, MessageBoxButton.YesNo, MessageBoxImage.Question);\n if (result == MessageBoxResult.No)\n {\n ComboBox combo = (ComboBox)sender;\n isSelectionHandled = false;\n if (e.RemovedItems.Count > 0)\n combo.SelectedItem = e.RemovedItems[0];\n return;\n }\n }\n isSelectionHandled = true;\n }\n"
},
{
"answer_id": 51364821,
"author": "Tates",
"author_id": 7616883,
"author_profile": "https://Stackoverflow.com/users/7616883",
"pm_score": 0,
"selected": false,
"text": "private SomeObject = selectedSomeObject=null;\n\nprivate void cbxTemplates_SelectionChangeCommitted(object sender, EventArgs e)\n{\n if (!(sender is ComboBox cb)) return;\n if (!(cb.SelectedItem is SomeObject tem)) return;\n if (MessageBox.Show(\"You sure?\", \"??.\",\n MessageBoxButtons.OKCancel) != DialogResult.OK)\n cb.SelectedItem = selectedSomeObject;\n else\n {\n selectedSomeObject = tem;\n }\n}\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314503",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
314,505 | <blockquote>
<p><strong>Possible Duplicate:</strong><br>
<a href="https://stackoverflow.com/questions/1759352/how-do-i-mark-a-method-as-obsolete-deprecated-c-sharp">How do I mark a method as Obsolete/Deprecated? - C#</a> </p>
</blockquote>
<p>How do you mark a class as deprecated? I do not want to use a class any more in my project, but do not want to delete it before a period of 2 weeks.</p>
| [
{
"answer_id": 314507,
"author": "Patrick Desjardins",
"author_id": 13913,
"author_profile": "https://Stackoverflow.com/users/13913",
"pm_score": 10,
"selected": true,
"text": "[Obsolete] [Obsolete(\"Not used any more\", true)]\npublic class MyDeprecatedClass\n{\n //...\n}\n"
},
{
"answer_id": 7739028,
"author": "Rebecca",
"author_id": 119624,
"author_profile": "https://Stackoverflow.com/users/119624",
"pm_score": 6,
"selected": false,
"text": "[Obsolete(\"Not used any more\", false)]\npublic class MyDeprecatedClass\n{\n //...\n}\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314505",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14441/"
] |
314,515 | <p>What options are there for installing Django such that multiple users (each with an "Account") can each have their own database?</p>
<p>The semantics are fairly intuitive. There may be more than one User for an Account. An Account has a unique database (and a database corresponds to an account). Picture WordpressMU. :)</p>
<p>I've considered this:</p>
<ol>
<li><p><strong>External solution - Multiplex to multiple servers/daemons</strong></p>
<p>Multiple Django installations, with each Django installation / project corresponding to an account that sets its own DATABASE_NAME, e.g.</p>
<p>File system:</p>
<pre><code>/bob
/settings.py (contains DATABASE_NAME="bob")
/sue
/settings.py (contains DATABASE_NAME="sue")
</code></pre>
<p>Then having a Django instance running for each of bob and sue. I don't like this methodology- it feels brutish and it smells foul. But I'm confident it would work, and based on the suggestions it might be the cleanest, smartest way to do it.</p>
<p>The apps can be stored elsewhere; the only thing that need be unique to the django configuration is the settings.py (and even there, only DATABASE_NAME, etc. need be different, the rest can be imported).</p>
<p>(Incidentally, I'm using lighttpd and FastCGI.)</p></li>
<li><p><strong>Internal solution - Django multiplexing database settings</strong></p>
<p>On the other hand, I've thought of having one single Django installation, and</p>
<p>(a) Adding a "prefix_" to each database table, corresponding to account of the logged-in user; or</p>
<p>(b) Changing the database according to the account of the User that is logged in.</p>
<p>I'd be particularly interested in seeing the "Django way" to do these (hoping that it's something dead-simple). For example, middleware that takes a Request's User and changes the django.conf.SETTINGS['DATABASE_NAME'] to the database for this user's account.</p>
<p>This raises red flags, viz. Is this thread-safe? i.e. Does changing django.conf.SETTINGS affect other processes? Is there just an inherent danger in changing django.conf.SETTINGS -- would the DB connection be setup already? Is restarting the DB connection part of the public API? -- I'm going to have a look at the Django source when I look to this problem again.</p>
<p>I'm conscious that 2(a) and (b) could require User authentication to be stored and accessed in a different mechanism that the core.</p></li>
</ol>
<p>For now, I'm going to go with the external mapping at the webserver layer- it's simplest and cleanest for now. However, I don't like the idea of FastCGI daemons running for every account- it seems to needlessly waste memory, particularly if there will be 2000+ accounts. However, I'd like to keep this discussion open as it's an interesting problem and the solution doesn't seem ideal for certain cases.</p>
<p>Comments duly appreciated.
Cheers</p>
| [
{
"answer_id": 314869,
"author": "Gabriel Ross",
"author_id": 10751,
"author_profile": "https://Stackoverflow.com/users/10751",
"pm_score": 3,
"selected": true,
"text": "<VirtualHost 1.2.3.4>\n DocumentRoot /www/site1\n ServerName site1.com\n <Location />\n SetHandler python-program\n SetEnv DJANGO_SETTINGS_MODULE site1.settings\n PythonPath \"['/www'] + sys.path\"\n PythonDebug On\n PythonInterpreter site1\n </Location>\n</VirtualHost>\n\n<VirtualHost 1.2.3.4>\n DocumentRoot /www/site2\n ServerName site2.com\n <Location />\n SetHandler python-program\n SetEnv DJANGO_SETTINGS_MODULE site2.settings\n PythonPath \"['/www'] + sys.path\"\n PythonDebug On\n PythonInterpreter site2\n </Location>\n</VirtualHost>\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314515",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19212/"
] |
314,531 | <p>When obtaining the DPI for the screen under Windows (by using ::GetDeviceCaps) will the horizontal value always be the same as the vertical? For example:</p>
<pre><code>HDC dc = ::GetDC(NULL);
const int xDPI = ::GetDeviceCaps(dc, LOGPIXELSX);
const int yDPI - ::GetDeviceCaps(dc, LOGPIXELSY);
assert(xDPI == yDPI);
::ReleaseDC(NULL, dc);
</code></pre>
<p>Are these values ever different?</p>
| [
{
"answer_id": 314732,
"author": "John Dibling",
"author_id": 241536,
"author_profile": "https://Stackoverflow.com/users/241536",
"pm_score": 1,
"selected": false,
"text": " int nHorz = dc.GetDeviceCaps(LOGPIXELSX);\n int nVert = dc.GetDeviceCaps(LOGPIXELSY);\n\n // almost always the same in both directions, but sometimes not!\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314531",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9236/"
] |
314,540 | <p>I'm code reviewing a change one of my co-workers just did, and he added a bunch of calls to <code>Date.toMonth()</code>, <code>Date.toYear()</code> and other deprecated <code>Date</code> methods. All these methods were deprecated in JDK 1.1, but he insists that it's ok to use them because they haven't gone away yet (we're using JDK 1.5) and I'm saying they might go away any day now and he should use <code>Calendar</code> methods.</p>
<p>Has Sun/Oracle actually said when these things are going away, or does <code>@deprecated</code> just mean you lose style points?</p>
| [
{
"answer_id": 314577,
"author": "VonC",
"author_id": 6309,
"author_profile": "https://Stackoverflow.com/users/6309",
"pm_score": 6,
"selected": true,
"text": "forRemoval=true forRemoval=true"
},
{
"answer_id": 315617,
"author": "user38748",
"author_id": 38748,
"author_profile": "https://Stackoverflow.com/users/38748",
"pm_score": 2,
"selected": false,
"text": "Calendar java.util.Date Calendar Date toString Date Calendar Calendar Datetime"
},
{
"answer_id": 50445603,
"author": "Jens Bannmann",
"author_id": 7641,
"author_profile": "https://Stackoverflow.com/users/7641",
"pm_score": 3,
"selected": false,
"text": "java.util.Date @Deprecated(forRemoval=true) forRemoval Thread.stop() forRemoval forRemoval SecurityManager Runtime java.security.acl finalize() Thread.destroy() Thread.stop() Policy java.util.jar.Pack200 finalize() Runtime.traceInstructions() Runtime.traceMethodCalls() javax.security.cert java.lang.String java.security.acl java.util.jar.Pack200 Thread.resume() Thread.suspend() ThreadGroup ConstantBootstraps() Modifier() ToolProvider() ConstantBootstraps() Modifier() java.rmi.activation ToolProvider() Integer Double Boolean ThreadGroup destroy() stop() isDaemon() URLDecoder() finalize() java.rmi.activation URLDecoder() java.applet java.lang.SecurityManager checkAccess() Thread ThreadGroup"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314540",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3333/"
] |
314,549 | <p>In C#</p>
<p>I have a processing time number data column in the database which is in in this format "###" or "##" ( eg: "813" or "67")</p>
<p>When I bind it to the grid view I wanted to display it in this format "0.###" (eg: "0.813" or "0.067")</p>
<p>I tried using {0:0.000} and other formatings. But none seem to work. Can anyone tell me how to write the format string?</p>
| [
{
"answer_id": 314697,
"author": "Mark Brackett",
"author_id": 2199,
"author_profile": "https://Stackoverflow.com/users/2199",
"pm_score": 2,
"selected": false,
"text": "{0:0.000} {0:0\\\\.000}"
},
{
"answer_id": 314726,
"author": "Greg",
"author_id": 12601,
"author_profile": "https://Stackoverflow.com/users/12601",
"pm_score": 0,
"selected": false,
"text": "// Handle the grid's RowDataBound event\nMyGridView.RowDataBound += new GridViewRowEventHandler(MyGridView_RowDataBound);\n\n// Set the value to x / 1000 in the RowDataBound event\nprotected void MyGridView_RowDataBound( object sender, GridViewRowEventArgs e )\n{\n if( e.Row.RowType != DataControlRowType.DataRow )\n return;\n\n // Cast e.Row.DataItem to whatever type you're binding to\n BindingObject bindingObject = (BindingObject)e.Row.DataItem;\n\n // Set the text of the correct column. Replace 0 with the position of the correct column\n e.Row.Cells[0].Text = bindingObject.ProcessingTime / 1000M;\n}\n"
},
{
"answer_id": 314828,
"author": "avgbody",
"author_id": 8737,
"author_profile": "https://Stackoverflow.com/users/8737",
"pm_score": 0,
"selected": false,
"text": "String.Format(\"{0:0.000}\", test/1000);\n"
},
{
"answer_id": 418590,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "GridView.DataSource = .... \n\nBoundField total = new BoundField();\ntotal.DataField = \"Total\";\ntotal.HeaderText = \"Total Amount\";\ntotal.DataFormatString = \"{0:C}\";\ndonations.Columns.Add(total);\n\n......\n"
},
{
"answer_id": 3071024,
"author": "Vinod Kumar",
"author_id": 370441,
"author_profile": "https://Stackoverflow.com/users/370441",
"pm_score": 1,
"selected": false,
"text": "try\n{\n if (e.Row.RowType == DataControlRowType.DataRow)\n {\n if (((DataRowView)(e.Row.DataItem))[\"Columnname\"].ToString().Equals(\"Total\", StringComparison.OrdinalIgnoreCase))\n {\n e.Row.Font.Bold = true;\n //-----or ant thing you want to do------\n }\n }\n}\ncatch (Exception ex)\n{\n\n}\n"
},
{
"answer_id": 9239055,
"author": "Joe",
"author_id": 13087,
"author_profile": "https://Stackoverflow.com/users/13087",
"pm_score": 1,
"selected": false,
"text": "{0:0,.000} 0.813 {0:0,,.0M} 1.8M"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314549",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
314,553 | <p>I heard a lot about makefiles and how they simplify the compilation process. I'm using VS2008. Can somebody please suggest some online references or books where I can find out more about how to deal with them?</p>
| [
{
"answer_id": 315863,
"author": "Jon Trauntvein",
"author_id": 19674,
"author_profile": "https://Stackoverflow.com/users/19674",
"pm_score": 3,
"selected": false,
"text": "debug: coratools_debug\n devenv coralib.vcproj /build debug\n\ncoratools_debug: nothing\n cd ../coratools\n nmake debug\n cd $(MAKEDIR)\n debug: coratools_debug\n msbuild coralib.vcxproj /p:Configuration=debug\n\ncoratools_debug: nothing\n cd ../coratools\n nmake debug\n cd $(MAKEDIR)\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314553",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28298/"
] |
314,555 | <p>In Linqtosql how do I show items from multiple rows in a single field.</p>
<p>eg I have a 3 table setup for tagging(entity, tag, entitytag) all linked via foreign keys.</p>
<p>For each entity I would like to return the name in one field and then all relevant tags in 2nd field.</p>
<p>eg Item1, tag1; tag2; tag3
Item2, tag4, tag5....</p>
<p>VB statements preferred.</p>
<p>Thanks
Geoff</p>
| [
{
"answer_id": 314795,
"author": "Geoff Appleford",
"author_id": 7793,
"author_profile": "https://Stackoverflow.com/users/7793",
"pm_score": 2,
"selected": true,
"text": "Dim dc As New DataContext\n\nDim query = From i In dc.Items _\n Let tags = (From t In dc.ItemTags _\n Where t.ItemID = i.ID _\n Select t.Tag.Name).ToArray _\n Select i.ItemName, Tags = String.Join(\" | \", tags)\n"
},
{
"answer_id": 314912,
"author": "David",
"author_id": 39552,
"author_profile": "https://Stackoverflow.com/users/39552",
"pm_score": 0,
"selected": false,
"text": "var entityTags = from ent in theEntities\n from enttags in ent.EntityTags\n group enttags by enttags.AnEntity into entityGroup\n select new { TheEntity = entityGroup.Key, TheTags = \n from t in entityGroup\n select t.ATag.TagName };\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314555",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7793/"
] |
314,558 | <p>I'm trying to use route constraints in an Asp.Net MVC Application. </p>
<pre><code>routes.MapRoute(
"theRoute",
"MyAction/{page}",
new { controller = "TheController", action = "MyAction", page = 1 },
new { page = @"[0-9]" });
</code></pre>
<p>When I enter an url like ~/MyAction/aString, an YSOD is shown with an invalid operation exception. What can I do to redirect invalid url to the 404 page?</p>
<p>I know I can solve the issue with a string parameter in the controller action and int.TryParse, but then the route constaint is useless.</p>
<p>How can I choose the exceptiontype that is thrown by the route constraints?</p>
| [
{
"answer_id": 330049,
"author": "Matthew",
"author_id": 20162,
"author_profile": "https://Stackoverflow.com/users/20162",
"pm_score": 3,
"selected": true,
"text": "routes.MapRoute(\n \"Default\", // Route name\n \"{controller}/{action}/{id}\", // URL with parameters\n new { controller = \"Home\", action = \"Index\", id = 0 },\n new { id = \"[0-9]\" }// Parameter defaults\n);\nroutes.MapRoute(\n \"Default2\", // Route name\n \"{controller}/{action2}/{sid}\", // URL with parameters\n new { controller = \"Home\", action = \"Index2\", sid = \"\" } // Parameter defaults\n);\n public ActionResult Index(int id)\n {\n ViewData[\"Title\"] = \"Home Page\";\n ViewData[\"Message\"] = \"Welcome to ASP.NET MVC! Your id is: \"+ id.ToString();\n\n return View();\n }\n\n public ActionResult Index2(string sid)\n {\n ViewData[\"Title\"] = \"Home Page 2.\"+sid.ToString();\n ViewData[\"Message\"] = \"Welcome to ASP.NET MVC! \\\"\" + sid.ToString() +\"\\\" is an invalid id\";\n\n return View(\"index\");\n }\n"
},
{
"answer_id": 8327671,
"author": "Galled",
"author_id": 529689,
"author_profile": "https://Stackoverflow.com/users/529689",
"pm_score": 0,
"selected": false,
"text": "<system.web>\n ...\n ...\n <customErrors mode=\"On\">\n <error \n statusCode=\"404\" \n redirect=\"/Home/MyCustomError\" /> \n <!-- Is not necessary that the \n view MyCustomError.aspx are inside the \n Home folder, you can put that \n view in the Shared folder.\n -->\n </customErrors>\n ...\n ...\n</system.web>\n ActionResult MyCustomError public class HomeController : Controller\n{\n ...\n ...\n\n public ActionResult MyCustomError(string aspxerrorpath) \n /* the var aspxerrorpath \n * is that MVC generated by\n * default */\n {\n ViewData[\"messageError\"] = aspxerrorpath;\n return View();\n }\n}\n <%@ Page Language=\"C#\" \n MasterPageFile=\"~/Views/Shared/Site.Master\" \n Inherits=\"System.Web.Mvc.ViewPage<System.Web.Mvc.HandleErrorInfo>\" %>\n\n<asp:Content ID=\"errorTitle\" ContentPlaceHolderID=\"TitleContent\" runat=\"server\">\n Error\n</asp:Content>\n\n<asp:Content ID=\"errorContent\" ContentPlaceHolderID=\"MainContent\" runat=\"server\">\n <h2>Shit happends</h2>\n <p> <%: ViewData[\"messageError\"]%></p>\n <p>aaaaaaaaaaaaaaa!!!!!!!!!!!!!!!!!!!!</p>\n</asp:Content>\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314558",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13376/"
] |
314,572 | <p>The following code</p>
<pre><code>public class GenericsTest2 {
public static void main(String[] args) throws Exception {
Integer i = readObject(args[0]);
System.out.println(i);
}
public static <T> T readObject(String file) throws Exception {
return readObject(new ObjectInputStream(new FileInputStream(file)));
// closing the stream in finally removed to get a small example
}
@SuppressWarnings("unchecked")
public static <T> T readObject(ObjectInputStream stream) throws Exception {
return (T)stream.readObject();
}
}
</code></pre>
<p>compiles in eclipse, but not with javac (type parameters of T cannot be determined; no unique maximal instance exists for type variable T with upper bounds T,java.lang.Object). </p>
<p>When I change readObject(String file) to </p>
<pre><code> @SuppressWarnings("unchecked")
public static <T> T readObject(String file) throws Exception {
return (T)readObject(new ObjectInputStream(new FileInputStream(file)));
}
</code></pre>
<p>it compiles in eclipse and with javac. Who is correct, the eclipse compiler or javac?</p>
| [
{
"answer_id": 314743,
"author": "C. K. Young",
"author_id": 13,
"author_profile": "https://Stackoverflow.com/users/13",
"pm_score": 4,
"selected": false,
"text": "readObject T public static <T> T readObject(String file) throws Exception {\n return GenericsTest2.<T>readObject(new ObjectInputStream(new FileInputStream(file)));\n}\n"
},
{
"answer_id": 335836,
"author": "Fabian Steeg",
"author_id": 18154,
"author_profile": "https://Stackoverflow.com/users/18154",
"pm_score": 7,
"selected": true,
"text": "return GenericsTest2.<T>readObject(new ObjectInputStream(new FileInputStream(file)));\n"
},
{
"answer_id": 9993653,
"author": "OndroMih",
"author_id": 784594,
"author_profile": "https://Stackoverflow.com/users/784594",
"pm_score": 0,
"selected": false,
"text": "public static <T> T readObject(String file, Class<T> type) throws Exception {\n return type.cast(readObject(new ObjectInputStream(new FileInputStream(file))));\n}\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314572",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/969/"
] |
314,578 | <p>Can somebody please give me an example of a unidirectional @OneToOne primary-key mapping in Hibernate ? I've tried numerous combinations, and so far the best thing I've gotten is this :</p>
<pre><code>@Entity
@Table(name = "paper_cheque_stop_metadata")
@org.hibernate.annotations.Entity(mutable = false)
public class PaperChequeStopMetadata implements Serializable, SecurityEventAware {
private static final long serialVersionUID = 1L;
@Id
@JoinColumn(name = "paper_cheque_id")
@OneToOne(cascade = {}, fetch = FetchType.EAGER, optional = false, targetEntity = PaperCheque.class)
private PaperCheque paperCheque;
}
</code></pre>
<p>Whenever Hibernate tries to automatically generate the schema for the above mapping, it tries to create the primary key as a blob, instead of as a long, which is the id type of PaperCheque. Can somebody please help me ? If I can't get an exact solution, something close would do, but I'd appreciate any response.</p>
| [
{
"answer_id": 314660,
"author": "activout.se",
"author_id": 20444,
"author_profile": "https://Stackoverflow.com/users/20444",
"pm_score": 3,
"selected": false,
"text": "@Entity\n@Table(name = \"message\")\npublic class Message implements java.io.Serializable\n{\n @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)\n @PrimaryKeyJoinColumn(name = \"id\", referencedColumnName = \"message_id\")\n public MessageContent getMessageContent()\n {\n return messageContent;\n }\n}\n\n@Entity\n@Table(name = \"message_content\")\n@GenericGenerator(name = \"MessageContent\", strategy = \"foreign\",\n parameters =\n {\n @org.hibernate.annotations.Parameter\n (\n name = \"property\", value = \"message\"\n )\n }\n)\npublic class MessageContent implements java.io.Serializable\n{\n @Id\n @Column(name = \"message_id\", unique = true, nullable = false)\n // See http://forum.hibernate.org/viewtopic.php?p=2381079\n @GeneratedValue(generator = \"MessageContent\")\n public Integer getMessageId()\n {\n return this.messageId;\n }\n}\n"
},
{
"answer_id": 314903,
"author": "Alex Marshall",
"author_id": 32232,
"author_profile": "https://Stackoverflow.com/users/32232",
"pm_score": 1,
"selected": false,
"text": "@Entity\n@Table(name = \"paper_cheque_stop_metadata\")\n@org.hibernate.annotations.Entity(mutable = false)\npublic class PaperChequeStopMetadata implements Serializable, SecurityEventAware {\n\nprivate static final long serialVersionUID = 1L;\n\n@SuppressWarnings(\"unused\")\n@Id\n@Column(name = \"paper_cheque_id\")\n@AccessType(\"property\")\nprivate long id;\n\n@OneToOne(cascade = {}, fetch = FetchType.EAGER, optional = false, targetEntity = PaperCheque.class)\n@PrimaryKeyJoinColumn(name = \"paper_cheque_id\")\n@JoinColumn(name = \"paper_cheque_id\", insertable = true)\n@NotNull\nprivate PaperCheque paperCheque;\n\n@XmlAttribute(namespace = XMLNS, name = \"paper-cheque-id\", required = true)\npublic final long getId() {\n return this.paperCheque.getId();\n}\n\npublic final void setId(long id) {\n //this.id = id;\n //NOOP, this is essentially a pseudo-property\n}\n}\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314578",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32232/"
] |
314,580 | <p><b>Executive Summary:</b> When assertion errors are thrown in the threads, the unit test doesn't die. This makes sense, since one thread shouldn't be allowed to crash another thread. The question is how do I either 1) make the whole test fail when the first of the helper threads crashes or 2) loop through and determine the state of each thread after they have all completed (see code below). One way of doing the latter is by having a per thread status variable, e.g., "boolean[] statuses" and have "statuses[i] == false" mean that the thread failed (this could be extended to capture more information). However, that is not what I want: I want it to fail just like any other unit test when the assertion errors are thrown. Is this even possible? Is it desirable?</p>
<p>I got bored and I decided to spawn a bunch of threads in my unit test and then have them call a service method, just for the heck of it. The code looks approximately like:</p>
<pre><code>Thread[] threads = new Thread[MAX_THREADS];
for( int i = 0; i < threads.length; i++ ) {
threads[i] = new Thread( new Runnable() {
private final int ID = threadIdSequenceNumber++;
public void run() {
try {
resultRefs[ID] = runTest( Integer.toString( ID ) ); // returns an object
}
catch( Throwable t ) {
// this code is EVIL - it catches even
// Errors - don't copy it - more on this below
final String message = "error testing thread with id => "
+ ID;
logger.debug( message, t );
throw new IllegalStateException( message, t );
// need to wrap throwable in a
// run time exception so it will compile
}
}
} );
}
</code></pre>
<p>After this, we will loop through the array of threads and start each one. After that we will wait for them all to finish. Finally, we will perform some checks on the result references.</p>
<pre><code>for( Thread thread : threads )
thread.start();
logger.debug( "waiting for threads to finish ..." );
boolean done = false;
while( !done ) {
done = true;
for( Thread thread : threads )
if( thread.isAlive() )
done = false;
}
for( int i = 0; i < resultRefs.length; i++ ) {
assertTrue( "you've got the world messed, dawg!",
myCondition(resultRefs[i]) );
</code></pre>
<p>Here's the problem. Did you notice that nasty try-catch-throwable block? I just added that as a temporary hack so I could see what was going on. In runTest( String ) a few assertions are made, e.g., assertNotNull( null ), but since it is in a different thread, it doesn't cause the unit test to fail!!!!</p>
<p>My guess is that we will need to somehow iterate over the threads array, check the status of each, and manually cause an assertion error if the thread terminated in a nasty way. What's the name of the method that gives this information (the stack trace of the dead thread).</p>
| [
{
"answer_id": 20326363,
"author": "Lital Kolog",
"author_id": 3056745,
"author_profile": "https://Stackoverflow.com/users/3056745",
"pm_score": 0,
"selected": false,
"text": " @Test\n public void testAwait_InnerThreadExternalizeException() {\n\n final int CONTEXT = 1;\n final String EXCEPTION_MESSAGE = \"test inner thread exception message\";\n\n // release will occur sometime in the future - simulate exception in the releaser thread\n ExecutorServiceFactory.getCachedThreadPoolExecutor().submit(new Callable<void>() {\n\n @Override\n public Void call() throws Exception {\n\n Sprinkler.getInstance().release(CONTEXT, new RuntimeException(EXCEPTION_MESSAGE));\n\n return null;\n }\n\n });\n\n Throwable thrown = null;\n try {\n Sprinkler.getInstance().await(CONTEXT, 10000);\n } catch (Throwable t) {\n // if the releaser thread delivers exception it will be externelized to this thread\n thrown = t;\n }\n Assert.assertTrue(thrown instanceof SprinklerException);\n Assert.assertEquals(EXCEPTION_MESSAGE, thrown.getCause().getMessage());\n }\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314580",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39489/"
] |
314,583 | <p>I'm new to Python and am running to a problem I can't google my way out of. I've built a GUI using wxPython and ObjectiveListView. In its very center, the GUI has a list control displaying data in X rows (the data is loaded by the user) and in five columns.</p>
<p>When the user selects multiple entries from the list control (pressing CTRL or shift while clicking), the ObjectiveListView module gives me a list of dictionaries, the dictionaries containing the data in the rows of the list control. This is exactly what I want, good!</p>
<p>The returned list looks something like this:</p>
<pre><code>print MyList
[{'id':1023, 'type':'Purchase', 'date':'23.8.2008', 'sum':'-21,90', 'target':'Apple Store'}, {'id':1024, 'type':'Purchase', 'date':'24.8.2008', 'sum':'-21,90', 'target':'Apple Store'}, {'id':23, 'type':'Purchase', 'date':'2.8.2008', 'sum':'-21,90', 'target':'Apple Store'}]
</code></pre>
<p>All the dictionaries have the same keys, but the values change. The 'id' value is unique. Here the problems start. I want to get the common values for all the items the user selected. In the above list they would be 'sum':'-21,90' and 'target':'Apple Store'.</p>
<p>I don't know how to properly compare the dicts in the list. One big problem is that I don't know beforehand how many dicts the list contains, since it's decided by the user.</p>
<p>I have a vague idea that list comprehensions would be the way to go, but I only know how to compare two lists with list comprehensions, not n lists. Any help would be appreciated.</p>
| [
{
"answer_id": 314633,
"author": "Matthew Trevor",
"author_id": 11265,
"author_profile": "https://Stackoverflow.com/users/11265",
"pm_score": 3,
"selected": false,
"text": ">>> mysets = (set(x.items()) for x in MyList)\n>>> reduce(lambda a,b: a.intersection(b), mysets)\nset([('sum', '-21,90'), ('type', 'Purchase'), ('target', 'Apple Store')])\n >>> mysets = (set(x.items()) for x in MyList)\n>>> find_common = lambda a,b: a.intersection(b)\n>>> reduce(find_common, mysets)\nset([('sum', '-21,90'), ('type', 'Purchase'), ('target', 'Apple Store')])\n >>> dict(reduce(find_common, mysets))\n{'sum': '-21,90', 'type': 'Purchase', 'target': 'Apple Store'}\n"
},
{
"answer_id": 314751,
"author": "atzz",
"author_id": 23252,
"author_profile": "https://Stackoverflow.com/users/23252",
"pm_score": 2,
"selected": false,
"text": "def IntersectDicts( d1, d2 ) :\n return dict(filter(lambda (k,v) : k in d2 and d2[k] == v, d1.items()))\n result = reduce(IntersectDicts, MyList)\n"
},
{
"answer_id": 314834,
"author": "Claudiu",
"author_id": 15055,
"author_profile": "https://Stackoverflow.com/users/15055",
"pm_score": 3,
"selected": false,
"text": ">>> mysets = (set(x.items()) for x in MyList)\n>>> reduce(set.intersection, mysets)\nset([('sum', '-21,90'), ('type', 'Purchase'), ('target', 'Apple Store')])\n set.intersection set.intersection >>> mysets = (set(x.items()) for x in MyList)\n>>> result = reduce(set.intersection, mysets)\n>>> values = [r[1] for r in result]\n>>> values\n['-21,90', 'Purchase', 'Apple Store']\n >>> [r[1] for r in reduce(set.intersection, (set(x.items()) for x in myList))]\n['-21,90', 'Purchase', 'Apple Store']\n"
},
{
"answer_id": 315424,
"author": "Parand",
"author_id": 13055,
"author_profile": "https://Stackoverflow.com/users/13055",
"pm_score": 1,
"selected": false,
"text": "common = {}\nfor k in MyList[0]:\n for i in xrange(1,len(MyList)):\n if MyList[0][k] != MyList[i][k]: continue\n common[k] = MyList[0][k]\n\n>>> common\n{'sum': '-21,90', 'type': 'Purchase', 'target': 'Apple Store'}\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314583",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
314,584 | <p>I am thinking it is a best practice to declare them as static, as it makes them invisible outside of the module.</p>
<p>What are your thoughts on this?</p>
| [
{
"answer_id": 314630,
"author": "KeithB",
"author_id": 2298,
"author_profile": "https://Stackoverflow.com/users/2298",
"pm_score": 5,
"selected": false,
"text": "namespace {\nvoid myLocalFunction() {\n// stuff\n}\n}\n"
},
{
"answer_id": 314637,
"author": "Piotr Lesnicki",
"author_id": 38796,
"author_profile": "https://Stackoverflow.com/users/38796",
"pm_score": 1,
"selected": false,
"text": "static"
},
{
"answer_id": 314641,
"author": "peterchen",
"author_id": 31317,
"author_profile": "https://Stackoverflow.com/users/31317",
"pm_score": 2,
"selected": false,
"text": "// foo.cpp\nnamespace\n{\n class Core { ... };\n void InternalFandango(Core *);\n}\n\nvoid SomeGloballyVisibleFunction()\n{\n InternalFandango(&core);\n}\n"
},
{
"answer_id": 353115,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": -1,
"selected": false,
"text": "class MyClass\n{ \npublic: \nvoid publiclyAccessibleFunction(); \nprivate: \n void onlyAccesibleFromWithinTheClass();\nint some_member_parameter; \n};\n onlyAccesibleFromWithinTheClass()"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314584",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7734/"
] |
314,591 | <p>I have an Air application with a main window. I would like to have a new window fly out from the side of the main window when the user clicks on a button in the main window. The window that appears needs to display information based on value passed from the main form. How can I achieve this with Flex Builder 3?</p>
<p>Target platform: any version of Flash/Flex/Air.</p>
| [
{
"answer_id": 314630,
"author": "KeithB",
"author_id": 2298,
"author_profile": "https://Stackoverflow.com/users/2298",
"pm_score": 5,
"selected": false,
"text": "namespace {\nvoid myLocalFunction() {\n// stuff\n}\n}\n"
},
{
"answer_id": 314637,
"author": "Piotr Lesnicki",
"author_id": 38796,
"author_profile": "https://Stackoverflow.com/users/38796",
"pm_score": 1,
"selected": false,
"text": "static"
},
{
"answer_id": 314641,
"author": "peterchen",
"author_id": 31317,
"author_profile": "https://Stackoverflow.com/users/31317",
"pm_score": 2,
"selected": false,
"text": "// foo.cpp\nnamespace\n{\n class Core { ... };\n void InternalFandango(Core *);\n}\n\nvoid SomeGloballyVisibleFunction()\n{\n InternalFandango(&core);\n}\n"
},
{
"answer_id": 353115,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": -1,
"selected": false,
"text": "class MyClass\n{ \npublic: \nvoid publiclyAccessibleFunction(); \nprivate: \n void onlyAccesibleFromWithinTheClass();\nint some_member_parameter; \n};\n onlyAccesibleFromWithinTheClass()"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314591",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/636/"
] |
314,593 | <p>I have written a program in C to parse large XML files and then create files with insert statements. Some other process would ingest the files into a MySQL database.
This data will serve as a indexing service so that users can find documents easily.</p>
<p>I have chosen InnoDB for the ability of row-level locking. The C program will be generating any where from 500 to 5 million insert statements on a given invocation.</p>
<p>What is the best way to get all this data into the database as quickly as possible? The other thing to note is that the DB is on a separate server. Is it worth moving the files over to that server to speed up inserts?</p>
<p>EDIT: This table won't really be updated, but rows will be deleted. </p>
| [
{
"answer_id": 314629,
"author": "Kent Fredric",
"author_id": 15614,
"author_profile": "https://Stackoverflow.com/users/15614",
"pm_score": 1,
"selected": false,
"text": "INSERT INTO TableName(Col1,Col2) VALUES (1,1),(1,2),(1,3) \n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314593",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28714/"
] |
314,594 | <p>I have a web service that acts as an interface between a farm of websites and some analytics software. Part of the analytics tracking requires harvesting the page title. Rather than passing it from the webpage to the web service, I would like to use <code>HTTPWebRequest</code> to call the page. </p>
<p>I have code that will get the entire page and parse out the html to grab the title tag but I don't want to have to download the entire page to just get information that's in the head.</p>
<p>I've started with </p>
<pre><code>HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("url");
request.Method = "HEAD";
</code></pre>
| [
{
"answer_id": 314691,
"author": "Andy Brudtkuhl",
"author_id": 12442,
"author_profile": "https://Stackoverflow.com/users/12442",
"pm_score": -1,
"selected": false,
"text": "HttpWebRequest req = (HttpWebRequest)WebRequest.Create(URL);\nHttpWebResponse resp = (HttpWebResponse)req.GetResponse();\nStream st = resp.GetResponseStream();\nStreamReader sr = new StreamReader(st);\nstring buffer = sr.ReadToEnd();\nint startPos, endPos;\nstartPos = buffer.IndexOf(\"<title>\",\nStringComparison.CurrentCultureIgnoreCase) + 7;\nendPos = buffer.IndexOf(\"</title>\",\nStringComparison.CurrentCultureIgnoreCase);\nstring title = buffer.Substring(startPos, endPos - startPos);\nConsole.WriteLine(\"Response code from {0}: {1}\", s,\n resp.StatusCode);\nConsole.WriteLine(\"Page title: {0}\", title);\nsr.Close();\nst.Close();\n"
},
{
"answer_id": 6091937,
"author": "The Mask",
"author_id": 447979,
"author_profile": "https://Stackoverflow.com/users/447979",
"pm_score": 2,
"selected": false,
"text": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Net;\nusing System.IO;\nusing System.Text.RegularExpressions;\n\nnamespace ConsoleApplication2\n{\n class Program\n {\n static void Main(string[] args)\n {\n string page = @\"http://stackoverflow.com/\";\n HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(page);\n StreamReader SR = new StreamReader(req.GetResponse().GetResponseStream());\n\n Char[] buf = new Char[256];\n int count = SR.Read(buf, 0, 256);\n while (count > 0)\n {\n String outputData = new String(buf, 0, count);\n Match match = Regex.Match(outputData, @\"<title>([^<]+)\", RegexOptions.IgnoreCase);\n if (match.Success)\n {\n Console.WriteLine(match.Groups[1].Value);\n }\n count = SR.Read(buf, 0, 256);\n }\n }\n\n }\n}\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314594",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12442/"
] |
314,600 | <p>I have a bunch of generic interfaces and classes</p>
<pre><code>public interface IElement {
// omited
}
class Element implements IElement {
// omited
}
public interface IElementList<E extends IElement> extends Iterable {
public Iterator<E> iterator();
}
class ElementList implements IElementList<Element> {
public Iterator<Element> iterator() {
// omited
}
}
public interface IElementListGroup<E extends IElementList<? extends IElement>> {
public E getChosenElementList();
}
class ElementListGroup implements IElementListGroup<ElementList> {
public ElementList getChosenElementList() {
// omited
}
}
</code></pre>
<p>And then a simple code</p>
<pre><code>ElementListGroup group;
for(Element e : group.getChosenElementList())
{
// omited
}
</code></pre>
<p>And the line with for keyword throwe a "cannot convert from element type Object to Element" compiler error.</p>
<p>Thanks in advance.</p>
| [
{
"answer_id": 314635,
"author": "Michael Myers",
"author_id": 13531,
"author_profile": "https://Stackoverflow.com/users/13531",
"pm_score": 4,
"selected": true,
"text": "IElementList Iterable<E> Iterator iterator() Iterator<E> iterator() Object"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314600",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24028/"
] |
314,607 | <p>I have a class which looks something like this:</p>
<pre><code>public class Test {
private static final Object someObject = new Object();
public void doSomething()
{
synchronized (someObject) {
System.out.println(someObject.toString());
}
}
}
</code></pre>
<p>Can I consider the object to be synchronized, or is there a problem since it is a static member?</p>
<p><strong>Edit:</strong> note that different threads might be accessing doSomething() and the object <strong>must</strong> be accessed in a thread-safe manner in that case.</p>
| [
{
"answer_id": 315483,
"author": "Alex Miller",
"author_id": 7671,
"author_profile": "https://Stackoverflow.com/users/7671",
"pm_score": 1,
"selected": false,
"text": "public class Test {\n public void doSomething() {\n synchronized (Test.class) {\n // something\n }\n }\n}\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314607",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24545/"
] |
314,616 | <p>Do all php include files have to be in an include directory, or is that just an organizational convenience?
Can I include files from any directory using the path to that directory?
Do html files that contain php includes have to have a php extension?
If so, I guess that would mean all of my html docs would be php if they all have the menus I am planning to "include". Is that acceptable protocol to have every file on your site be a php file?</p>
<p>A bow in humble reverence...</p>
<p>p.s. is there a good bible on this topic!?</p>
| [
{
"answer_id": 318769,
"author": "Hugh Bothwell",
"author_id": 33258,
"author_profile": "https://Stackoverflow.com/users/33258",
"pm_score": 0,
"selected": false,
"text": "Extension Call method PHP runs\n .html browser no\n .html Apache #include no\n .html PHP include() yes\n .php browser yes\n .php Apache #include yes\n .php PHP include() yes\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314616",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40091/"
] |
314,636 | <p>If you know the Index, Value or Text. also if you don't have an ID for a direct reference.</p>
<p><a href="https://stackoverflow.com/questions/149573/check-if-option-is-selected-with-jquery-if-not-select-a-default#149820">This</a>, <a href="https://stackoverflow.com/questions/196684/jquery-get-select-option-text#196687">this</a> and <a href="https://stackoverflow.com/questions/47824/using-core-jquery-how-do-you-remove-all-the-options-of-a-select-box-then-add-on#47829">this</a> are all helpful answers.</p>
<p>Example markup</p>
<pre><code><div class="selDiv">
<select class="opts">
<option selected value="DEFAULT">Default</option>
<option value="SEL1">Selection 1</option>
<option value="SEL2">Selection 2</option>
</select>
</div>
</code></pre>
| [
{
"answer_id": 314644,
"author": "Jay Corbett",
"author_id": 2755,
"author_profile": "https://Stackoverflow.com/users/2755",
"pm_score": 3,
"selected": false,
"text": "<html>\n<head>\n<script language=\"Javascript\" src=\"javascript/jquery-1.2.6.min.js\"></script>\n<script type=\"text/JavaScript\">\n\n$(function() {\n $(\".update\").bind(\"click\", // bind the click event to a div\n function() {\n var selectOption = $('.selDiv').children('.opts') ;\n var _this = $(this).next().children(\".opts\") ;\n\n $(selectOption).find(\"option[index='0']\").attr(\"selected\",\"selected\");\n// $(selectOption).find(\"option[value='DEFAULT']\").attr(\"selected\",\"selected\");\n// $(selectOption).find(\"option[text='Default']\").attr(\"selected\",\"selected\");\n\n\n// $(_this).find(\"option[value='DEFAULT']\").attr(\"selected\",\"selected\");\n// $(_this).find(\"option[text='Default']\").attr(\"selected\",\"selected\");\n// $(_this).find(\"option[index='0']\").attr(\"selected\",\"selected\");\n\n }); // END Bind\n}); // End eventlistener\n\n</script>\n</head>\n<body>\n<div class=\"update\" style=\"height:50px; color:blue; cursor:pointer;\">Update</div>\n<div class=\"selDiv\">\n <select class=\"opts\">\n <option selected value=\"DEFAULT\">Default</option>\n <option value=\"SEL1\">Selection 1</option>\n <option value=\"SEL2\">Selection 2</option>\n </select>\n </div>\n</body>\n</html>\n"
},
{
"answer_id": 1835350,
"author": "Leandro Ardissone",
"author_id": 42565,
"author_profile": "https://Stackoverflow.com/users/42565",
"pm_score": 7,
"selected": false,
"text": "val() $('select').val('the_value');\n"
},
{
"answer_id": 6068322,
"author": "Grastveit",
"author_id": 470022,
"author_profile": "https://Stackoverflow.com/users/470022",
"pm_score": 11,
"selected": true,
"text": "$('.selDiv option[value=\"SEL1\"]')\n $('.selDiv option:eq(1)')\n $('.selDiv option:contains(\"Selection 1\")')\n $('.selDiv option:eq(1)').prop('selected', true)\n $('.selDiv option:eq(1)').attr('selected', 'selected')\n $('.selDiv option')\n .filter(function(i, e) { return $(e).text() == \"Selection 1\"})\n $(e).text() </option> <select ...>\n<option value=\"1\">Selection 1\n<option value=\"2\">Selection 2\n :\n</select>\n e.text"
},
{
"answer_id": 8335332,
"author": "user1074546",
"author_id": 1074546,
"author_profile": "https://Stackoverflow.com/users/1074546",
"pm_score": 7,
"selected": false,
"text": "$('#element option[value=\"no\"]').attr(\"selected\", \"selected\");\n"
},
{
"answer_id": 9100455,
"author": "Sandro",
"author_id": 1183339,
"author_profile": "https://Stackoverflow.com/users/1183339",
"pm_score": 4,
"selected": false,
"text": "$(\"select[name='theNameYouChose']\").find(\"option[value='theValueYouWantSelected']\").attr(\"selected\",true);\n"
},
{
"answer_id": 15159735,
"author": "Andrej Gaspar",
"author_id": 2123829,
"author_profile": "https://Stackoverflow.com/users/2123829",
"pm_score": 2,
"selected": false,
"text": "$('#yourElement option[value=\"'+yourValue+'\"]').attr('selected', 'selected');\n$('#editLocationCity').chosen().change();\n$('#editLocationCity').trigger('liszt:updated');\n"
},
{
"answer_id": 16421275,
"author": "someone",
"author_id": 1434265,
"author_profile": "https://Stackoverflow.com/users/1434265",
"pm_score": 6,
"selected": false,
"text": "$('#id option[value=theOptionValue]').prop('selected', 'selected').change();\n"
},
{
"answer_id": 18226271,
"author": "user2606817",
"author_id": 2606817,
"author_profile": "https://Stackoverflow.com/users/2606817",
"pm_score": 3,
"selected": false,
"text": "$(\"select#my-select option\") .each(function() { this.selected = (this.text == myVal); });\n"
},
{
"answer_id": 19319810,
"author": "Miguel",
"author_id": 1834212,
"author_profile": "https://Stackoverflow.com/users/1834212",
"pm_score": 3,
"selected": false,
"text": "$(\"#yourlist :nth(1)\").prop(\"selected\",\"selected\").change();\n"
},
{
"answer_id": 27511288,
"author": "João Paulo Oliveira",
"author_id": 3941714,
"author_profile": "https://Stackoverflow.com/users/3941714",
"pm_score": 4,
"selected": false,
"text": " $(elem).find('option[value=\"' + value + '\"]').attr(\"selected\", \"selected\");\n"
},
{
"answer_id": 33717455,
"author": "Jitesh Sojitra",
"author_id": 4859833,
"author_profile": "https://Stackoverflow.com/users/4859833",
"pm_score": 2,
"selected": false,
"text": "$('select').val('the_value'); $row.find('#component').val('All');\n"
},
{
"answer_id": 34614692,
"author": "raddevus",
"author_id": 255243,
"author_profile": "https://Stackoverflow.com/users/255243",
"pm_score": 4,
"selected": false,
"text": "$('#MySelectionBox').val(123).change();\n $('#MySelectionBox').val(\"extra thing\").change();\n"
},
{
"answer_id": 35191211,
"author": "FLICKER",
"author_id": 1017065,
"author_profile": "https://Stackoverflow.com/users/1017065",
"pm_score": 2,
"selected": false,
"text": "document.getElementById(\"mySelect\").selectedIndex = \"2\";\n"
},
{
"answer_id": 37519273,
"author": "Pratik Kamani",
"author_id": 4723750,
"author_profile": "https://Stackoverflow.com/users/4723750",
"pm_score": 3,
"selected": false,
"text": "/* This will reset your select box with \"-- Please Select --\" */ \n <script>\n $(document).ready(function() {\n $(\"#gate option[value='']\").prop('selected', true);\n });\n </script>\n"
},
{
"answer_id": 39348359,
"author": "Gone Coding",
"author_id": 201078,
"author_profile": "https://Stackoverflow.com/users/201078",
"pm_score": 5,
"selected": false,
"text": "val() $select <select> var $select = $('.selDiv .opts');\n val() $select.val(\"SEL2\");\n .val() select selected option value prop attr boolean selected $option.prop('selected', true); // Will add selected=\"selected\" to the tag\n val() <option> $select.val() null var $select = $('.selDiv .opts');\n$select.val(\"SEL2\");\nif ($select.val() == null) {\n $select.val(\"DEFAULT\");\n}\n filter var $select = $('.selDiv .opts');\n$select.children().filter(function(){\n return this.text == \"Selection 2\";\n}).prop('selected', true);\n return $.trim(this.text) == \"some value to match\";\n var $select = $('.selDiv .opts');\nvar index = 2;\n$select.children()[index].selected = true;\n var $select = $('.selDiv .opts');\nvar index = 2;\n$select.children().eq(index).prop('selected', true);\n .change() select var $select = $('.selDiv .opts');\n$select.val(\"SEL2\").change();\n [value=\"SEL2\"]"
},
{
"answer_id": 40199437,
"author": "Md. Russel Hussain",
"author_id": 4295653,
"author_profile": "https://Stackoverflow.com/users/4295653",
"pm_score": 2,
"selected": false,
"text": "var val = $(\"select.opts:visible option:selected \").val();\n"
},
{
"answer_id": 44382285,
"author": "Nick Tsai",
"author_id": 4767939,
"author_profile": "https://Stackoverflow.com/users/4767939",
"pm_score": 3,
"selected": false,
"text": "$('select.opts').val('SEL1').change();\n $('.selDiv option[value=\"SEL1\"]')\n .attr('selected', 'selected')\n .change();\n attr() change() selected"
},
{
"answer_id": 46371087,
"author": "perumal N",
"author_id": 7444996,
"author_profile": "https://Stackoverflow.com/users/7444996",
"pm_score": 3,
"selected": false,
"text": " <script>\n $(document).ready(function() {\n$(\"#id option[value='option value']\").attr('selected',true);\n });\n </script>\n"
},
{
"answer_id": 48838048,
"author": "perumal N",
"author_id": 7444996,
"author_profile": "https://Stackoverflow.com/users/7444996",
"pm_score": 4,
"selected": false,
"text": "<script> \n $(document).ready(function() {\n $(\"#id\").val('select value here');\n });\n </script>\n <script> \n $(document).ready(function() {\n $(\"#id\").val('select value here').trigger('change');\n });\n </script>\n"
},
{
"answer_id": 56953082,
"author": "Yoel Duran",
"author_id": 11695036,
"author_profile": "https://Stackoverflow.com/users/11695036",
"pm_score": 3,
"selected": false,
"text": " $('#select option[data-id-estado=\"3\"]').prop(\"selected\",true).trigger(\"change\");\n\n// or\n\n $('#select option[value=\"myValue\"]').prop(\"selected\",true).trigger(\"change\");\n"
},
{
"answer_id": 63432600,
"author": "Richard",
"author_id": 6514318,
"author_profile": "https://Stackoverflow.com/users/6514318",
"pm_score": 1,
"selected": false,
"text": "prop attr. prop attr select select $(\"#country\").on(\"change\", function() {\n //get continent\n var originLocationRegion = $(this).find(\":selected\").data(\"origin-region\");\n\n //select continent correctly with prop\n $('#continent option[value=\"' + originLocationRegion + '\"]').prop('selected', true);\n});\n\n\n\n$(\"#country2\").on(\"change\", function() {\n //get continent\n var originLocationRegion = $(this).find(\":selected\").data(\"origin-region\");\n\n //select continent wrongly with attr\n $('#continent2 option[value=\"' + originLocationRegion + '\"]').attr('selected', true);\n}); <link href=\"https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css\" rel=\"stylesheet\" />\n<script src=\"https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js\"></script>\n\n<div class=\"container\">\n <form>\n <h4 class=\"text-success\">Props to the good stuff ;) </h4>\n <div class=\"form-row\">\n <div class=\"form-group col-md-6 col-sm-6\">\n <label>Conuntries</label>\n <select class=\"custom-select country\" id=\"country\">\n <option disabled selected>Select Country </option>\n <option data-origin-region=\"Asia\" value=\"Afghanistan\">Afghanistan</option>\n <option data-origin-region=\"Antartica\" value=\"Antartica\">Antartica</option>\n <option data-origin-region=\"Australia\" value=\"Australia\">Australia</option>\n <option data-origin-region=\"Europe\" value=\"Austria\">Austria</option>\n <option data-origin-region=\"Asia\" value=\"Bangladesh\">Bangladesh</option>\n <option data-origin-region=\"South America\" value=\"Brazil\">Brazil</option>\n <option data-origin-region=\"Africa\" value=\"Cameroon\">Cameroon</option>\n <option data-origin-region=\"North America\" value=\"Canada\">Canada</option>\n <option data-origin-region=\"South America\" value=\"Chile\">Chile</option>\n <option data-origin-region=\"Asia\" value=\"China\">China</option>\n <option data-origin-region=\"South America\" value=\"Ecuador\">Ecuador</option>\n <option data-origin-region=\"Australia\" value=\"Fiji\">Fiji</option>\n <option data-origin-region=\"North America\" value=\"Mexico\">Mexico</option>\n <option data-origin-region=\"Australia\" value=\"New Zealand\">New Zealand</option>\n <option data-origin-region=\"Africa\" value=\"Nigeria\">Nigeria</option>\n <option data-origin-region=\"Europe\" value=\"Portugal\">Portugal</option>\n <option data-origin-region=\"Africa\" value=\"Seychelles\">Seychelles</option>\n <option data-origin-region=\"North America\" value=\"United States\">United States</option>\n <option data-origin-region=\"Europe\" value=\"United Kingdom\">United Kingdom</option>\n </select>\n </div>\n <div class=\"form-group col-md-6 col-sm-6\">\n <label>Continent</label>\n <select class=\"custom-select\" id=\"continent\">\n <option disabled selected>Select Continent</option>\n <option disabled value=\"Africa\">Africa</option>\n <option disabled value=\"Antartica\">Antartica</option>\n <option disabled value=\"Asia\">Asia</option>\n <option disabled value=\"Europe\">Europe</option>\n <option disabled value=\"North America\">North America</option>\n <option disabled value=\"Australia\">Australia</option>\n <option disabled value=\"South America\">South America</option>\n </select>\n </div>\n </div>\n </form>\n <hr>\n\n <form>\n <h4 class=\"text-danger\"> Attributing the bad stuff to attr </h4>\n <div class=\"form-row\">\n <div class=\"form-group col-md-6 col-sm-6\">\n <label>Conuntries</label>\n <select class=\"custom-select country-2\" id=\"country2\">\n <option disabled selected>Select Country </option>\n <option data-origin-region=\"Asia\" value=\"Afghanistan\">Afghanistan</option>\n <option data-origin-region=\"Antartica\" value=\"Antartica\">Antartica</option>\n <option data-origin-region=\"Australia\" value=\"Australia\">Australia</option>\n <option data-origin-region=\"Europe\" value=\"Austria\">Austria</option>\n <option data-origin-region=\"Asia\" value=\"Bangladesh\">Bangladesh</option>\n <option data-origin-region=\"South America\" value=\"Brazil\">Brazil</option>\n <option data-origin-region=\"Africa\" value=\"Cameroon\">Cameroon</option>\n <option data-origin-region=\"North America\" value=\"Canada\">Canada</option>\n <option data-origin-region=\"South America\" value=\"Chile\">Chile</option>\n <option data-origin-region=\"Asia\" value=\"China\">China</option>\n <option data-origin-region=\"South America\" value=\"Ecuador\">Ecuador</option>\n <option data-origin-region=\"Australia\" value=\"Fiji\">Fiji</option>\n <option data-origin-region=\"North America\" value=\"Mexico\">Mexico</option>\n <option data-origin-region=\"Australia\" value=\"New Zealand\">New Zealand</option>\n <option data-origin-region=\"Africa\" value=\"Nigeria\">Nigeria</option>\n <option data-origin-region=\"Europe\" value=\"Portugal\">Portugal</option>\n <option data-origin-region=\"Africa\" value=\"Seychelles\">Seychelles</option>\n <option data-origin-region=\"North America\" value=\"United States\">United States</option>\n <option data-origin-region=\"Europe\" value=\"United Kingdom\">United Kingdom</option>\n </select>\n </div>\n <div class=\"form-group col-md-6 col-sm-6\">\n <label>Continent</label>\n <select class=\"custom-select\" id=\"continent2\">\n <option disabled selected>Select Continent</option>\n <option disabled value=\"Africa\">Africa</option>\n <option disabled value=\"Antartica\">Antartica</option>\n <option disabled value=\"Asia\">Asia</option>\n <option disabled value=\"Europe\">Europe</option>\n <option disabled value=\"North America\">North America</option>\n <option disabled value=\"Australia\">Australia</option>\n <option disabled value=\"South America\">South America</option>\n </select>\n </div>\n </div>\n </form>\n</div> prop attr prop attr"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314636",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2755/"
] |
314,639 | <p>I'm trying to get a regex that will match:</p>
<pre><code>somefile_1.txt
somefile_2.txt
somefile_{anything}.txt
</code></pre>
<p>but not match:</p>
<pre><code>somefile_16.txt
</code></pre>
<p>I tried</p>
<pre><code>somefile_[^(16)].txt
</code></pre>
<p>with no luck (it includes even the "16" record)</p>
| [
{
"answer_id": 314650,
"author": "phihag",
"author_id": 35070,
"author_profile": "https://Stackoverflow.com/users/35070",
"pm_score": 5,
"selected": true,
"text": "somefile(?!16\\.txt$).*?\\.txt\n somefile([^1].|1[^6]|.|.{3,})\\.txt\n somefile([^1].|1[^6]|.|....*)\\.txt\n [^(16)]"
},
{
"answer_id": 314669,
"author": "Julien Hoarau",
"author_id": 12248,
"author_profile": "https://Stackoverflow.com/users/12248",
"pm_score": 2,
"selected": false,
"text": "somefile_(?!16).*\\.txt\n"
},
{
"answer_id": 314703,
"author": "Douglas Mayle",
"author_id": 8458,
"author_profile": "https://Stackoverflow.com/users/8458",
"pm_score": 3,
"selected": false,
"text": "somefile_(?!16\\.txt$).*\\.txt\n somefile_(?!16)[^?%*:|\"<>]*\\.txt\n somefile_(1[^6]|[^1]).*\\.txt\n somefile_(16.|1[^6]|[^1]).*\\.txt\n somefile_((16[^?%*:|\"<>]|1[^6?%*:|\"<>]|[^1?%*:|\"<>])[^?%*:|\"<>]*|1)\\.txt\nsomefile_((1[^6?%*:|\"<>]|[^1?%*:|\"<>])[^?%*:|\"<>]*|1)\\.txt\n somefile_((16.|1[^6]|[^1).*|1)\\.txt\nsomefile_((1[^6]|[^1]).*|1)\\.txt\n"
},
{
"answer_id": 314708,
"author": "Piotr Lesnicki",
"author_id": 38796,
"author_profile": "https://Stackoverflow.com/users/38796",
"pm_score": 2,
"selected": false,
"text": "^somefile_(?!16\\.txt$).*\\.txt$\n ls | grep -e 'somefile_.*\\.txt' | grep -v -e 'somefile_16\\.txt'\n"
},
{
"answer_id": 314724,
"author": "Pierre",
"author_id": 24449,
"author_profile": "https://Stackoverflow.com/users/24449",
"pm_score": 1,
"selected": false,
"text": "somefile_(|.|[^1].+|10|11|12|13|14|15|17|18|19|.{3,}).txt\n somefile_ 1 10 19 16 .txt"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314639",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18941/"
] |
314,647 | <p>I have this rewrite rule</p>
<pre><code>RewriteEngine On
RewriteBase /location/
RewriteRule ^(.+)/?$ index.php?franchise=$1
</code></pre>
<p>Which is suppose to change this URL</p>
<pre><code>http://example.com/location/kings-lynn
</code></pre>
<p>Into this one</p>
<pre><code>http://example.com/location/index.php?franchise=kings-lynn
</code></pre>
<p>But instead I am getting this</p>
<pre><code>http://example.com/location/index.php?franchise=index.php
</code></pre>
<p>Also, adding a railing slash breaks it. I get index.php page showing but none of the style sheets or javascript are loading.</p>
<p>I'm clearly doing something very wrong but I have no idea what despite spending all day R'ingTFM and many online primers and tutorials and questions on here. </p>
| [
{
"answer_id": 314653,
"author": "Kent Fredric",
"author_id": 15614,
"author_profile": "https://Stackoverflow.com/users/15614",
"pm_score": 4,
"selected": true,
"text": "'location/index.php' ^(.+)/?$ RewriteEngine on\nRewriteBase /location/\nRewriteCond %{REQUEST_FILENAME} !-f # ignore existing files\nRewriteCond %{REQUEST_FILENAME} !-d # ignore existing directories\nRewriteRule ^(.+)/?$ index.php?franchise=$1 [L,QSA]\n location/foobar/?baz=quux ==> index.php?franchise=$1&baz=quux\n"
},
{
"answer_id": 314659,
"author": "enricopulatzo",
"author_id": 9883,
"author_profile": "https://Stackoverflow.com/users/9883",
"pm_score": 2,
"selected": false,
"text": "RewriteRule ^(.+)/?$ index.php?franchise=$1 [L]\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314647",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/319/"
] |
314,664 | <p>I have a class which constructor takes a <a href="http://commons.apache.org/lang/api-2.3/org/apache/commons/lang/enums/Enum.html" rel="nofollow noreferrer">Jakarta enums</a>. I'm trying to find how I can easily inject it via an <a href="http://www.springframework.org/" rel="nofollow noreferrer">Spring</a> XML aplicationContext.</p>
<p>For example :</p>
<p>The enum :</p>
<pre><code>public class MyEnum extends org.apache.commons.lang.enums.Enum {
public static final MyEnum MY_FIRST_VALUE = new MyEnum("MyFirstValue");
public static final MyEnum MY_SECOND_VALUE = new MyEnum("MySecondValue");
public static MyEnum getEnum(String name) {
return (MyEnum) getEnum(MyEnum.class, name);
}
[...other standard enum methods]
}
</code></pre>
<p>The class in which to inject :</p>
<pre><code>public class MyService {
private final MyEnum status;
public MyService(MyEnum status) {
this.status = status;
}
}
</code></pre>
<p>The application context :</p>
<pre><code><bean id="myService" class="MyService">
<constructor-arg index="0" value="MyFirstValue" />
</bean>
</code></pre>
<p>Of course, with this I have a <code>no matching editors or conversion strategy found</code> error. Is there an easy integration between Spring and the Jakarta enums ? Or should I write my own PropertyEditor ?</p>
| [
{
"answer_id": 314720,
"author": "Guillaume",
"author_id": 23704,
"author_profile": "https://Stackoverflow.com/users/23704",
"pm_score": 1,
"selected": false,
"text": "<bean id=\"myService\" class=\"MyService\">\n <constructor-arg index=\"0\">\n <bean class=\"MyEnum\" factory-method=\"getEnum\">\n <constructor-arg value=\"MyFirstValue\" />\n </bean>\n </constructor-arg>\n</bean>\n"
},
{
"answer_id": 318148,
"author": "Spencer Kormos",
"author_id": 8528,
"author_profile": "https://Stackoverflow.com/users/8528",
"pm_score": 3,
"selected": true,
"text": "<util:constant> <bean id=\"myService\" class=\"MyService\">\n <constructor-arg index=\"0\">\n <util:constant static-field=\"MyEnum.MY_FIRST_VALUE\"/>\n </constructor-arg>\n</bean>\n"
},
{
"answer_id": 7126289,
"author": "Tony R",
"author_id": 12838,
"author_profile": "https://Stackoverflow.com/users/12838",
"pm_score": 0,
"selected": false,
"text": "<bean id=\"myService\" class=\"MyService\">\n<constructor-arg index=\"0\" type=\"com.package.MyEnum\" value=\"MyFirstValue\" />\n</bean>\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314664",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23704/"
] |
314,675 | <p>Is it possible to redirect all of the output of a Bourne shell script to somewhere, but with shell commands inside the script itself?</p>
<p>Redirecting the output of a single command is easy, but I want something more like this:</p>
<pre><code>#!/bin/sh
if [ ! -t 0 ]; then
# redirect all of my output to a file here
fi
# rest of script...
</code></pre>
<p>Meaning: if the script is run non-interactively (for example, cron), save off the output of everything to a file. If run interactively from a shell, let the output go to stdout as usual.</p>
<p>I want to do this for a script normally run by the FreeBSD periodic utility. It's part of the daily run, which I don't normally care to see every day in email, so I don't have it sent. However, if something inside this one particular script fails, that's important to me and I'd like to be able to capture and email the output of this one part of the daily jobs.</p>
<p>Update: Joshua's answer is spot-on, but I also wanted to save and restore stdout and stderr around the entire script, which is done like this:</p>
<pre><code># save stdout and stderr to file
# descriptors 3 and 4,
# then redirect them to "foo"
exec 3>&1 4>&2 >foo 2>&1
# ...
# restore stdout and stderr
exec 1>&3 2>&4
</code></pre>
| [
{
"answer_id": 314678,
"author": "Joshua",
"author_id": 14768,
"author_profile": "https://Stackoverflow.com/users/14768",
"pm_score": 8,
"selected": false,
"text": "exec > file\n exec > file \nexec 2>&1\n exec >> file\nexec 2>&1\n exec exec"
},
{
"answer_id": 314731,
"author": "dbguy",
"author_id": 40319,
"author_profile": "https://Stackoverflow.com/users/40319",
"pm_score": 5,
"selected": false,
"text": "main_function() {\n do_things_here\n}\n if [ -z $TERM ]; then\n # if not run via terminal, log everything into a log file\n main_function 2>&1 >> /var/log/my_uber_script.log\nelse\n # run via terminal, only output to screen\n main_function\nfi\n # log everything, but also output to stdout\nmain_function 2>&1 | tee -a /var/log/my_uber_script.log\n"
},
{
"answer_id": 315113,
"author": "Jonathan Leffler",
"author_id": 15168,
"author_profile": "https://Stackoverflow.com/users/15168",
"pm_score": 9,
"selected": true,
"text": "#...part of script without redirection...\n\n{\n #...part of script with redirection...\n} > file1 2>file2 # ...and others as appropriate...\n\n#...residue of script without redirection...\n"
},
{
"answer_id": 11226576,
"author": "Dimitar",
"author_id": 1485687,
"author_profile": "https://Stackoverflow.com/users/1485687",
"pm_score": 2,
"selected": false,
"text": "[ -t <&0 ] || exec >> test.log\n"
},
{
"answer_id": 29660580,
"author": "Eyal leshem",
"author_id": 3382861,
"author_profile": "https://Stackoverflow.com/users/3382861",
"pm_score": 3,
"selected": false,
"text": "exec [fd number]<&1 \nexec [fd number]<&2\n a.txt #!/bin/bash\n\nexec 5<&1\nexec 6<&2\n\nexec 1> ~/a.txt 2>&1\n\necho \"walla1\"\necho \"walla2\" >&2\necho \"walla3\" >&5\necho \"walla4\" >&6\n"
},
{
"answer_id": 73867255,
"author": "George Chalhoub",
"author_id": 2922834,
"author_profile": "https://Stackoverflow.com/users/2922834",
"pm_score": 0,
"selected": false,
"text": "main_function if [ $? -eq 0 ] #! /bin/sh -\n\nmain_function() {\n python command.py\n}\n\nmain_function > >(tee -a \"/var/www/logs/output.txt\") 2>&1\n\nif [ $? -eq 0 ]\nthen\n echo 'Success!'\nelse\n echo 'Failure!'\nfi\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314675",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40307/"
] |
314,682 | <p>Given a collection of user specified tags how do I determine which ones <strong>are not</strong> in the tags table with 1 SQL Statement?</p>
<p>Assuming a table schema <code>tags (id, tag)</code> and I'm using mysql, if there's an optimization I'm unaware of.</p>
<p>thanks</p>
| [
{
"answer_id": 314693,
"author": "Unsliced",
"author_id": 2902,
"author_profile": "https://Stackoverflow.com/users/2902",
"pm_score": 1,
"selected": false,
"text": "select * from canonical_list_of_tags where tag not in (select tag from used_tags) \n canonical_list_of_tags"
},
{
"answer_id": 314767,
"author": "kristof",
"author_id": 3241,
"author_profile": "https://Stackoverflow.com/users/3241",
"pm_score": 0,
"selected": false,
"text": "select\n utt.tagName\nfrom\n userTypedTags utt\n left join tag t on utt.tagName = t.tag\nwhere\n t.ID is null\n and utt.userID = <ID of the User in question>\n userTypedTags(userID, tagName)\n"
},
{
"answer_id": 314840,
"author": "Chris Roberts",
"author_id": 475,
"author_profile": "https://Stackoverflow.com/users/475",
"pm_score": 3,
"selected": true,
"text": "\nSELECT Tag\nFROM UserSpecifiedTags\n LEFT OUTER JOIN AllTags ON UserSpecifiedTags.Tag = AllTags.Tag\nWHERE AllTags.Tag IS NULL\n IN"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314682",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2443/"
] |
314,683 | <p>How do I make an instance of gwtext.client.widgets.Window appear at specific DIV in my html ? I tried window.anchorTo(DOM.getElementById("Some_Div"),"left", new int[]{0,0}), thinking the window will anchor itself to div id="Some_Div" in my html. it didnt. </p>
| [
{
"answer_id": 320763,
"author": "bikesandcode",
"author_id": 40112,
"author_profile": "https://Stackoverflow.com/users/40112",
"pm_score": 1,
"selected": false,
"text": "RootPanel.get(\"Some_Div_Id\").add( someWidget )\n"
},
{
"answer_id": 348819,
"author": "Saravanan M",
"author_id": 27784,
"author_profile": "https://Stackoverflow.com/users/27784",
"pm_score": 0,
"selected": false,
"text": "window.alignTo(DOM.getElementById(\"Some_Div\"),\"tl-tl\", new int[]{0,0});\n Value Description\n----- -----------------------------\ntl The top left corner (default)\nt The center of the top edge\ntr The top right corner\nl The center of the left edge\nc In the center of the element\nr The center of the right edge\nbl The bottom left corner\nb The center of the bottom edge\nbr The bottom right corner\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314683",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
314,684 | <p>How would you handle cross database queries in different environments. For example, db1-development and db2-development, db1-production and db2-production. </p>
<p>If I want to do a cross-database query in development from db2 to db1 I could use the fully qualified name, [db1-development].[schema].[table]. But how do I maintain the queries and stored procedures between the different environments? [db1-development].[schema].[table] will not work in production because the database names are different.</p>
<p>I can see search and replace as a possible solution but I am hoping there is a more elegant way to solve this problem. If there are db specific solutions, I am using SQL Server 2005.</p>
| [
{
"answer_id": 314757,
"author": "user39603",
"author_id": 39603,
"author_profile": "https://Stackoverflow.com/users/39603",
"pm_score": 0,
"selected": false,
"text": "declare @environment varchar(10)\nset @environment = 'db-dev' -- input parameter, comes from app layer\n\ndeclare @sql varchar(8000)\nset @sql = 'select * from ' + @environment + '.dbo.view'\nexecute(@sql)\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314684",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24279/"
] |
314,700 | <p>I need help finding resources that would help me or at least point me in the right direction in building a Flash media server/PHP application. I basically want to improve my current application by instead of progressive download using flash media server so that the videos will not only stream well but they can't be downloaded by the end user.</p>
<p>What the current application does is show a login form on the homepage and then when logged in the user can then navigate the site by choosing videos from a particular video category or video uploaded by a specific user. All this is done with PHP. The video page uses progressive download to display the video after the video ID has been passed using PHP.</p>
<p>I need to know how PHP and flash media server work together. Are there any resources out there where I can find a good application example (really simple) that demonstrates how PHP and flash media server can be used to stream videos dynamically such that PHP checks for the login, video ID, video channels, and video category information while the flash media server streams the video.</p>
| [
{
"answer_id": 318739,
"author": "Willem",
"author_id": 15447,
"author_profile": "https://Stackoverflow.com/users/15447",
"pm_score": 1,
"selected": false,
"text": "<OBJECT>"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314700",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
314,713 | <p>I have an application for which log4j logging is configured in a log4j.properties file. Currently, this application runs on UNIX and creates a log file in /tmp. This application needs to run on Windows, and on that platform I would like for it to select the correct temporary directory, which I believe is C:\temp.</p>
<p>How can I change my log4j.properties file to make this happen? Do I need to switch to using an XML configuration file?</p>
| [
{
"answer_id": 314730,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 6,
"selected": true,
"text": "${java.io.tmpdir}"
},
{
"answer_id": 1870702,
"author": "Matthew McCullough",
"author_id": 56039,
"author_profile": "https://Stackoverflow.com/users/56039",
"pm_score": 1,
"selected": false,
"text": "<appender name=\"rolling_file_appender_ourapp\" class=\"org.apache.log4j.RollingFileAppender\">\n <param name=\"File\" value=\"${user.home}/.mycompany/OurApp.log\" />\n <param name=\"Append\" value=\"false\" />\n <param name=\"MaxFileSize\" value=\"10MB\" />\n <param name=\"MaxBackupIndex\" value=\"3\" />\n <layout class=\"org.apache.log4j.PatternLayout\">\n <param name=\"ConversionPattern\" value=\"%d | %-5p | %c | %m | %t | %x %n\" />\n </layout>\n</appender>\n log4j.appender.rfile=org.apache.log4j.FileAppender\nlog4j.appender.rfile.layout=org.apache.log4j.PatternLayout\nlog4j.appender.rfile.Append=false\nlog4j.appender.rfile.layout.ConversionPattern=%d [%p] %c %m%n\nlog4j.appender.rfile.File=${user.home}/.mycompany/OurApp.log\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314713",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18103/"
] |
314,736 | <p>I have an ASP.NET GridView which has columns that look like this:</p>
<pre><code>| Foo | Bar | Total1 | Total2 | Total3 |
</code></pre>
<p>Is it possible to create a header on two rows that looks like this?</p>
<pre><code>| | Totals |
| Foo | Bar | 1 | 2 | 3 |
</code></pre>
<p>The data in each row will remain unchanged as this is just to pretty up the header and decrease the horizontal space that the grid takes up. </p>
<p>The entire GridView is sortable in case that matters. I don't intend for the added "Totals" spanning column to have any sort functionality.</p>
<p><strong>Edit:</strong></p>
<p>Based on one of the articles given below, I created a class which inherits from GridView and adds the second header row in.</p>
<pre><code>namespace CustomControls
{
public class TwoHeadedGridView : GridView
{
protected Table InnerTable
{
get
{
if (this.HasControls())
{
return (Table)this.Controls[0];
}
return null;
}
}
protected override void OnDataBound(EventArgs e)
{
base.OnDataBound(e);
this.CreateSecondHeader();
}
private void CreateSecondHeader()
{
GridViewRow row = new GridViewRow(0, -1, DataControlRowType.Header, DataControlRowState.Normal);
TableCell left = new TableHeaderCell();
left.ColumnSpan = 3;
row.Cells.Add(left);
TableCell totals = new TableHeaderCell();
totals.ColumnSpan = this.Columns.Count - 3;
totals.Text = "Totals";
row.Cells.Add(totals);
this.InnerTable.Rows.AddAt(0, row);
}
}
}
</code></pre>
<p>In case you are new to ASP.NET like I am, I should also point out that you need to:</p>
<p>1) Register your class by adding a line like this to your web form:</p>
<pre><code><%@ Register TagPrefix="foo" NameSpace="CustomControls" Assembly="__code"%>
</code></pre>
<p>2) Change asp:GridView in your previous markup to foo:TwoHeadedGridView. Don't forget the closing tag.</p>
<p><strong>Another edit:</strong></p>
<p>You can also do this without creating a custom class.</p>
<p>Simply add an event handler for the DataBound event of your grid like this:</p>
<pre><code>protected void gvOrganisms_DataBound(object sender, EventArgs e)
{
GridView grid = sender as GridView;
if (grid != null)
{
GridViewRow row = new GridViewRow(0, -1,
DataControlRowType.Header, DataControlRowState.Normal);
TableCell left = new TableHeaderCell();
left.ColumnSpan = 3;
row.Cells.Add(left);
TableCell totals = new TableHeaderCell();
totals.ColumnSpan = grid.Columns.Count - 3;
totals.Text = "Totals";
row.Cells.Add(totals);
Table t = grid.Controls[0] as Table;
if (t != null)
{
t.Rows.AddAt(0, row);
}
}
}
</code></pre>
<p>The advantage of the custom control is that you can see the extra header row on the design view of your web form. The event handler method is a bit simpler, though.</p>
| [
{
"answer_id": 2113663,
"author": "Brian Webster",
"author_id": 127880,
"author_profile": "https://Stackoverflow.com/users/127880",
"pm_score": 2,
"selected": false,
"text": " If grid.HeaderRow Is Nothing Then\n"
},
{
"answer_id": 4206372,
"author": "MaC",
"author_id": 510989,
"author_profile": "https://Stackoverflow.com/users/510989",
"pm_score": 4,
"selected": false,
"text": "/*Create header row above generated header row*/\n\n//create row \nGridViewRow row = new GridViewRow(0, -1, DataControlRowType.Header, DataControlRowState.Normal);\n\n//spanned cell that will span the columns I don't want to give the additional header \nTableCell left = new TableHeaderCell();\nleft.ColumnSpan = 6;\nrow.Cells.Add(left);\n\n//spanned cell that will span the columns i want to give the additional header\nTableCell totals = new TableHeaderCell();\ntotals.ColumnSpan = myGridView.Columns.Count - 3;\ntotals.Text = \"Additional Header\";\nrow.Cells.Add(totals);\n\n//Add the new row to the gridview as the master header row\n//A table is the only Control (index[0]) in a GridView\n((Table)myGridView.Controls[0]).Rows.AddAt(0, row);\n\n/*fin*/\n"
},
{
"answer_id": 5789835,
"author": "Ron",
"author_id": 725303,
"author_profile": "https://Stackoverflow.com/users/725303",
"pm_score": 1,
"selected": false,
"text": "t.EnableViewState = false; Dim t As Table = TryCast(grid.Controls(0), Table)\nIf t IsNot Nothing Then\n t.Rows.AddAt(0, row)\nEnd If\n\nt.EnableViewState = false;\n"
},
{
"answer_id": 9382743,
"author": "aked",
"author_id": 1060656,
"author_profile": "https://Stackoverflow.com/users/1060656",
"pm_score": 0,
"selected": false,
"text": "public class GridViewPlus : GridView\n{\n\n public event EventHandler<CustomHeaderEventArgs> CustomHeaderTableCellCreated;\n\n private GridViewPlusCustomHeaderRows _rows;\n\n public GridViewPlus() : base ()\n {\n _rows = new GridViewPlusCustomHeaderRows();\n }\n\n /// <summary>\n /// Allow Custom Headers\n /// </summary>\n public bool ShowCustomHeader { get; set; }\n\n\n [PersistenceMode(PersistenceMode.InnerDefaultProperty)]\n [MergableProperty(false)]\n public GridViewPlusCustomHeaderRows CustomHeaderRows\n {\n get {return _rows; }\n\n }\n\n protected virtual void OnCustomHeaderTableCellCreated(CustomHeaderEventArgs e)\n {\n EventHandler<CustomHeaderEventArgs> handler = CustomHeaderTableCellCreated;\n\n // Event will be null if there are no subscribers\n if (handler != null)\n {\n // Use the () operator to raise the event.\n handler(this, e);\n }\n\n }\n\n protected override void OnRowCreated(GridViewRowEventArgs e)\n {\n if (ShowCustomHeader && e.Row.RowType == DataControlRowType.Header) return;\n base.OnRowCreated(e);\n }\n\n\n protected override void PrepareControlHierarchy()\n {\n //Do not show the Gridview header if show custom header is ON\n if (ShowCustomHeader) this.ShowHeader = false;\n\n\n base.PrepareControlHierarchy();\n //Safety Check\n if (this.Controls.Count == 0)\n return;\n bool controlStyleCreated = this.ControlStyleCreated;\n Table table = (Table)this.Controls[0];\n\n int j = 0;\n if (CustomHeaderRows ==null )return ;\n\n foreach (TableRow tr in CustomHeaderRows)\n {\n OnCustomHeaderTableCellCreated(new CustomHeaderEventArgs(tr,j));\n table.Rows.AddAt(j, tr);\n tr.ApplyStyle(this.HeaderStyle);\n j++;\n }\n\n\n }\n}\n\npublic class GridViewPlusCustomHeaderRows : System.Collections.CollectionBase\n{\n public GridViewPlusCustomHeaderRows()\n {\n }\n\n public void Add(TableRow aGridViewCustomRow)\n {\n List.Add(aGridViewCustomRow);\n }\n\n public void Remove(int index)\n {\n // Check to see if there is a widget at the supplied index.\n if (index > Count - 1 || index < 0)\n // If no widget exists, a messagebox is shown and the operation \n // is cancelled.\n {\n throw (new Exception(\"Index not valid\"));\n }\n else\n {\n List.RemoveAt(index);\n }\n }\n\n public TableRow Item(int Index)\n {\n // The appropriate item is retrieved from the List object and\n // explicitly cast to the Widget type, then returned to the \n // caller.\n return (TableRow)List[Index];\n }\n\n}\n\n\npublic class CustomHeaderEventArgs : EventArgs\n{\n public CustomHeaderEventArgs(TableRow tr ,int RowNumber )\n {\n tRow = tr;\n _rownumber = RowNumber;\n }\n private TableRow tRow;\n private int _rownumber = 0;\n\n\n public int RowNumber { get { return _rownumber; } }\n\n public TableRow HeaderRow\n {\n get { return tRow; }\n set { tRow = value; }\n }\n\n\n}\n\n\npublic partial class _Default : System.Web.UI.Page\n{\n protected void Page_Load(object sender, EventArgs e)\n {\n Example1();\n GridViewExtension1.CustomHeaderTableCellCreated += new EventHandler<CustomHeaderEventArgs>(GridViewExtension1_CustomHeaderTableCellCreated);\n }\n\n void GridViewExtension1_CustomHeaderTableCellCreated(object sender, CustomHeaderEventArgs e)\n {\n TableRow tc = (TableRow)e.HeaderRow;\n\n tc.BackColor = System.Drawing.Color.AliceBlue;\n }\n\n private void Example1()\n {\n System.Data.DataTable dtSample = new DataTable();\n DataColumn dc1 = new DataColumn(\"Column1\",typeof(string));\n DataColumn dc2 = new DataColumn(\"Column2\",typeof(string));\n DataColumn dc3 = new DataColumn(\"Column3\",typeof(string));\n DataColumn dc4 = new DataColumn(\"Column4\",typeof(string));\n // DataColumn dc5 = new DataColumn(\"Column5\",typeof(string));\n dtSample.Columns.Add(dc1);\n dtSample.Columns.Add(dc2);\n dtSample.Columns.Add(dc3);\n dtSample.Columns.Add(dc4);\n // dtSample.Columns.Add(dc5);\n dtSample.AcceptChanges();\n\n for (int i = 0; i < 25; i++)\n {\n DataRow dr = dtSample.NewRow();\n\n for (int j = 0; j < dtSample.Columns.Count; j++)\n {\n dr[j] = j;\n }\n dtSample.Rows.Add(dr);\n }\n dtSample.AcceptChanges();\n //GridViewExtension1.ShowHeader = false;\n GridViewExtension1.ShowCustomHeader = true;\n\n /*\n *=======================================================================\n * |Row 1 Cell 1 | Row 1 Col 2 (Span=2) | Row 1 Col 3 |\n * | | | |\n *======================================================================= \n * |Row 2 Cell 1 | | | |\n * | | Row 2 Col 2 | Row 2 Col 3 |Row 2 Col 4 |\n *=======================================================================\n * \n * \n * \n * \n * */\n\n // SO we have to make 2 header row as shown above\n\n TableRow TR1 = new TableRow();\n TableCell tcR1C1 = new TableCell();\n tcR1C1.Text = \"Row 1 Cell 1\";\n tcR1C1.ColumnSpan = 1;\n TR1.Cells.Add(tcR1C1); \n\n TableCell tcR1C2 = new TableCell();\n tcR1C2.Text = \"Row 1 Cell 2\";\n tcR1C2.ColumnSpan = 2;\n TR1.Cells.Add(tcR1C2); \n\n TableCell tcR1C3 = new TableCell();\n tcR1C3.Text = \"Row 1 Cell 3\";\n tcR1C3.ColumnSpan = 1;\n TR1.Cells.Add(tcR1C3);\n\n\n GridViewExtension1.CustomHeaderRows.Add(TR1);\n\n TableRow TR2 = new TableRow();\n TableCell tcR2C1 = new TableCell();\n tcR2C1.Text = \"Row 2 Cell 1\";\n tcR2C1.ColumnSpan = 1;\n TR2.Cells.Add(tcR2C1);\n\n TableCell tcR2C2 = new TableCell();\n tcR2C2.Text = \"Row 2 Cell 2\";\n tcR2C2.ColumnSpan = 1;\n TR2.Cells.Add(tcR2C2);\n\n TableCell tcR2C3 = new TableCell();\n tcR2C3.Text = \"Row 2 Cell 3\";\n tcR2C3.ColumnSpan = 1;\n TR2.Cells.Add(tcR2C3);\n\n TableCell tcR2C4 = new TableCell();\n tcR2C4.Text = \"Row 2 Cell 4\";\n tcR2C4.ColumnSpan = 1;\n TR2.Cells.Add(tcR2C4);\n\n GridViewExtension1.CustomHeaderRows.Add(TR2);\n\n\n GridViewExtension1.DataSource = dtSample;\n GridViewExtension1.DataBind();\n\n }\n}\n"
},
{
"answer_id": 21731593,
"author": "Phil Kermeen",
"author_id": 1050150,
"author_profile": "https://Stackoverflow.com/users/1050150",
"pm_score": 0,
"selected": false,
"text": "<asp:TemplateField >\n <HeaderTemplate>\n <div>\n <div style=\"text-align: center;padding-bottom: 5px;\">\n text\n </div>\n <div>\n <asp:Button ID=\"Button1\" runat=\"server\" Text=\"Apply to all\" ToolTip=\"Apply to all - Special Bolt On\" CssClass=\"sub_button input_btn_5\" OnClick=\"ApplyButton1_Click\" />\n </div>\n </div>\n </HeaderTemplate>\n <ItemTemplate>....\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314736",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3161/"
] |
314,737 | <p>I have some strings that I am pulling out of a database and I would like to use Template Toolkit on them, but I can't seem to figure out how to use strings as TT input. Any tips?</p>
<p>Thanks!</p>
<p>-fREW</p>
| [
{
"answer_id": 314902,
"author": "oeuftete",
"author_id": 7674,
"author_profile": "https://Stackoverflow.com/users/7674",
"pm_score": 5,
"selected": true,
"text": " # text reference\n $tt->process(\\$text)\n || die $tt->error(), \"\\n\"\n"
},
{
"answer_id": 314919,
"author": "Mr. Muskrat",
"author_id": 2657951,
"author_profile": "https://Stackoverflow.com/users/2657951",
"pm_score": 2,
"selected": false,
"text": "# text reference\n$text = \"[% INCLUDE header %]\\nHello world!\\n[% INCLUDE footer %]\";\n$tt->process(\\$text)\n || die $tt->error(), \"\\n\";\n"
},
{
"answer_id": 315224,
"author": "draegtun",
"author_id": 12195,
"author_profile": "https://Stackoverflow.com/users/12195",
"pm_score": 2,
"selected": false,
"text": "use String::TT qw/tt strip/;\n\nsub foo {\n my $self = shift;\n return tt 'my name is [% self.name %]!';\n}\n\nsub bar {\n my @args = @_;\n return strip tt q{\n Args: [% args_a.join(\",\") %]\n }\n}\n my $scalar = 'scalar';\nmy @array = qw/array goes here/;\nmy %hash = ( hashes => 'are fun' );\n\ntt '[% scalar %] [% scalar_s %] [% array_a %] [% hash_h %]';\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314737",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12448/"
] |
314,739 | <p>I'm running Xorg and my (Qt) program daemonises itself. Now I log out and restart the X server. When I log in again my process is still running fine, but I can't see it.</p>
<p>Is there a way of attatching the new incarnation of the X server to the old process?
If I don't restart the whole server, but log out and in again, is there a way to look at the old process?</p>
<p>Thanks</p>
| [
{
"answer_id": 8634958,
"author": "totaam",
"author_id": 428751,
"author_profile": "https://Stackoverflow.com/users/428751",
"pm_score": 0,
"selected": false,
"text": "xpra start :10 --start-child=/bin/YOURAPP xpra attach :10 xpra attach ssh://THESERVERHOSTNAMEORIP/10"
},
{
"answer_id": 34338620,
"author": "sanshi_leilei",
"author_id": 2869827,
"author_profile": "https://Stackoverflow.com/users/2869827",
"pm_score": 2,
"selected": false,
"text": "xpra start :100 --start-child=xterm --bind-tcp=0.0.0.0:10000\n xpra attach tcp:SERVERHOST:10000\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314739",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40317/"
] |
314,765 | <p>I am trying to implement performance testing on ActiveMQ, so have setup a basic producer and consumer to send and receive messages across a queue. I have created a producer with no problems, getting it to write a specific number of messages to the queue:</p>
<pre><code> for(int i = 0; i < numberOfMessages; i++){
try{
String message = generateText(sizeOfMessage);
produceMessage(message);
}
catch (Exception e) {
logger.error("Caught exception while sending message", e);
}
}
</code></pre>
<p>This continues to completion with no problems and I have confirmed this with checks on the admin website, that have the correct number of messages pending.</p>
<p>The problem occurs when I try to receive the messages from the queue. Using a simple consumer to read from the queue, it will read a various number of messages from the queue, but then will stop when trying to receive one of the messages. I can see that there are still messages in the queue to be read, but the client will not progress passed one of the messages.
I am using a simple method to receive the messages:</p>
<pre><code>Message message = jmsTemplate.receive();
</code></pre>
<p>and it works for some messages(about 20-30) but then just locks. It was suggested to me that some of the characters in the message may be an escape character (I was using a random string of varying length, due to this just being a performance test, not actually sending over any content) so I changed all messages to the same string, which is a repetition of the char '2' and still no luck.
I am using Spring configuration to load all of the components needed to access the ActiveMQ queue, and the queue is running on my localhost.</p>
| [
{
"answer_id": 314857,
"author": "Richard",
"author_id": 16759,
"author_profile": "https://Stackoverflow.com/users/16759",
"pm_score": 3,
"selected": true,
"text": "<systemUsage>\n <systemUsage>\n <memoryUsage>\n <memoryUsage limit=\"20 mb\"/>\n </memoryUsage>\n <storeUsage>\n <storeUsage limit=\"1 gb\" name=\"foo\"/>\n </storeUsage>\n <tempUsage>\n <tempUsage limit=\"100 mb\"/>\n </tempUsage>\n </systemUsage>\n </systemUsage>\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314765",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16759/"
] |
314,774 | <p>So, I'd like to be able to set the max log file size to 64M, but after doing so with <code>innodb_log_file_size=64M</code> MySQL starts OK, but nothing seems to work properly. </p>
<p><strong>EDIT:</strong> and by properly I mean not at all. Setting other InnoDB variables aren't causing any problems.</p>
<p>How should I go about troubleshooting this one?</p>
| [
{
"answer_id": 315360,
"author": "Kornel",
"author_id": 27009,
"author_profile": "https://Stackoverflow.com/users/27009",
"pm_score": 3,
"selected": true,
"text": "ib_logfile* /var/lib/mysql/ show table status hostname.err"
},
{
"answer_id": 17496681,
"author": "Jonathan",
"author_id": 297015,
"author_profile": "https://Stackoverflow.com/users/297015",
"pm_score": 2,
"selected": false,
"text": "service mysql stop # Stop MySQL\nrm /var/lib/mysql/ib_logfile0 # Delete log file 1\nrm /var/lib/mysql/ib_logfile1 # Delete log file 2\nvim my.conf # Change innodb_log_file_size = 64M\nservice mysql start # Start MySQL\n"
},
{
"answer_id": 17496788,
"author": "RolandoMySQLDBA",
"author_id": 491757,
"author_profile": "https://Stackoverflow.com/users/491757",
"pm_score": 1,
"selected": false,
"text": "mysql -ANe\"SET GLOBAL innodb_fast_shutdown = 2\"\nvi /etc/my.cnf # Change innodb_log_file_size = 64M\nservice mysql stop # Stop MySQL\nrm /var/lib/mysql/ib_logfile0 # Delete log file 1\nrm /var/lib/mysql/ib_logfile1 # Delete log file 2\nservice mysql start # Start MySQL\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314774",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21716/"
] |
314,779 | <p>while writing a custom attribute in C# i was wondering if there are any guidelines or best practices regarding exceptions in attributes.
Should the attribute check the given parameters for validity? Or is this the task of the user of the property?</p>
<p>In a simple test I did the exception was not thrown until i used GetCustomAttributes on a type with an exception throwing attribute.
I just think it's a bit awkward to get an exception from an Attribute only when explicitly asking for them.</p>
<hr>
<p>Example Attribute with exception:</p>
<pre><code>[AttributeUsage(AttributeTargets.Interface, AllowMultiple = false, Inherited = false)]
sealed public class MyAttribute : Attribute
{
public string SomeValue { get; private set; }
public MyAttribute(string someValue)
{
if(string.IsNullOrEmpty(someValue))
{
throw new ArgumentNullException("path");
}
if(!someOtherCheck(someValue))
{
throw MyAttributeException("An other error occured");
}
SomeValue = someValue;
}
}
</code></pre>
| [
{
"answer_id": 315276,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 2,
"selected": false,
"text": "[PrincipalPermission]"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314779",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21566/"
] |
314,781 | <p>I am working on a windows form application. How do i use the find method of a datatable to find a row if the datatable has a compound key?</p>
<p>Table Structure
Col A, Col B, Col C</p>
<p>Col A and Col B make up the compound key.
I want to find the row where the value in Col A is 6 and Col B is 5</p>
| [
{
"answer_id": 314805,
"author": "Charles Bretana",
"author_id": 32632,
"author_profile": "https://Stackoverflow.com/users/32632",
"pm_score": 4,
"selected": false,
"text": "dt.PrimaryKey = new DataColumn[] {dt.Columns[\"ColA\"], dt.Columns[\"ColB\"]};\n object[] keyVals = new object[] {6, 5};\nDataRow dr = dt.Rows.Find(keyVals);\n DataRow dr = dt.Rows.Find(new object[] {6, 5});\n"
},
{
"answer_id": 314815,
"author": "Mitchel Sellers",
"author_id": 13279,
"author_profile": "https://Stackoverflow.com/users/13279",
"pm_score": 4,
"selected": true,
"text": "DataTable.Rows.Find(6,5)\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314781",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14780/"
] |
314,783 | <p>I have two SQL scripts which get called within a loop that accept a number parameter. Here is what I'm currently using:</p>
<pre><code>for /l %%i in (1, 1, 51) do (
sqlplus u/p@name @script.sql a%%i.html %%i
sqlplus u/p@name @script.sql b%%i.html %%i
)
</code></pre>
<p>Everything works fine, but it seems like a waste of time and resources to connect twice for each pass through. Is there a way I could simply log into sqlplus, run the for loop, then exit? I tried many alternatives such as putting</p>
<pre><code>sqlplus u/p@name
</code></pre>
<p>before the for loop, but then it would simply hang at the SQL> prompt without executing any of my two scripts.</p>
<p>Thank you.</p>
| [
{
"answer_id": 314813,
"author": "Brian Schmitt",
"author_id": 30492,
"author_profile": "https://Stackoverflow.com/users/30492",
"pm_score": 3,
"selected": true,
"text": "@@script1.sql\n@@script2.sql\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314783",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25371/"
] |
314,786 | <p>I have library code that overrides Ar's find method. I also include the module for all Association classes so both MyModel.find and @parent.my_models.find work and apply the correct scope.</p>
<p>I based my code off of will_paginate's:</p>
<pre><code>a = ActiveRecord::Associations
returning([ a::AssociationCollection ]) { |classes|
# detect http://dev.rubyonrails.org/changeset/9230
unless a::HasManyThroughAssociation.superclass == a::HasManyAssociation
classes << a::HasManyThroughAssociation
end
}.each do |klass|
klass.send :include, Finder::ClassMethods
klass.class_eval { alias_method_chain :method_missing, :paginate }
end
</code></pre>
<p>My problem is, I only want to override the finders for some models. Currently I need to extend all association collection classes which are shared by all models. I know I can extend associations per model by passing a module:</p>
<pre><code>has_many :things, :extend => SomeCustomMethods
</code></pre>
<p>But my library is basically am ActiveRecord plugin, so I'd like a clean convention for plugable finder extensions that apply to both the model and scoped collections without affecting all models in the application.</p>
| [
{
"answer_id": 315092,
"author": "gtd",
"author_id": 8376,
"author_profile": "https://Stackoverflow.com/users/8376",
"pm_score": 3,
"selected": false,
"text": "def self.find(*args)\n super\nend\n"
},
{
"answer_id": 316407,
"author": "Pedro",
"author_id": 16882,
"author_profile": "https://Stackoverflow.com/users/16882",
"pm_score": 3,
"selected": false,
"text": "find_every find_by_sql find module MyPlugin\n def self.included(base)\n class << base\n alias_method :find_every_without_my_plugin, :find_every\n def find_every(*args)\n # do whatever you need ...\n find_every_without_my_plugin(*args)\n end\n end\n end\nend\n\nActiveRecord::Base.send :include, MyPlugin\n class User < ActiveRecord::Base\n my_plugin\nend\n class << base base self module MyPlugin\n def self.included(base)\n class << base\n base.extend ClassMethods\n end\n end\n\n module ClassMethods\n def my_plugin\n class << self\n alias_method :find_every_without_my_plugin, :find_every\n # ...\n end\n end\n end\nend\n"
},
{
"answer_id": 2068872,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "def self.included(base)\n class << base\n base.extend ClassMethods\n end\nend\n def self.included(base)\n base.extend ClassMethods\nend\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314786",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21702/"
] |
314,792 | <p>Can I export multiple calendar events into a single iCalendar file? </p>
| [
{
"answer_id": 314812,
"author": "Paul Fisher",
"author_id": 39808,
"author_profile": "https://Stackoverflow.com/users/39808",
"pm_score": 2,
"selected": true,
"text": "BEGIN:VCALENDAR\nBEGIN:VEVENT\nDESCRIPTION:\nDTEND:20071202T220000Z\nDTSTAMP:20081124T220920Z\nDTSTART:20071202T200000Z\nLOCATION:Wherever\nSTATUS:CONFIRMED\nSUMMARY:An event\nUID:event-the-first\nEND:VEVENT\nBEGIN:VEVENT\nDESCRIPTION:Doing whatever, because for no good reason.\nDTEND:20071209T210000Z\nDTSTAMP:20081124T220920Z\nDTSTART:20071207T190000Z\nLOCATION:A specific place\nSTATUS:CONFIRMED\nSUMMARY:Something, somewhere\nUID:event-the-second\nEND:VEVENT\nEND:VCALENDAR\n"
},
{
"answer_id": 36192034,
"author": "Michael DiStefano",
"author_id": 2533208,
"author_profile": "https://Stackoverflow.com/users/2533208",
"pm_score": 0,
"selected": false,
"text": "File > Export > Export... {calendar name}.ics"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314792",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/37759/"
] |
314,800 | <p>If you have a situation where you need to know where a boolean value wasn't set (for example if that unset value should inherit from a parent value) the Java boolean primitive (and the equivalent in other languages) is clearly not adequate.</p>
<p>What's the best practice to achieve this? Define a new simple class that is capable of expressing all three states or use the Java Boolean class and use null to indicate the unset state?</p>
| [
{
"answer_id": 314809,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 7,
"selected": true,
"text": "Boolean a = true;\nBoolean b = false;\nBoolean c = null;\n public enum ThreeState {\n TRUE,\n FALSE,\n TRALSE\n};\n true false null public static final Boolean tralse = null;"
},
{
"answer_id": 314810,
"author": "John Rudy",
"author_id": 14048,
"author_profile": "https://Stackoverflow.com/users/14048",
"pm_score": 3,
"selected": false,
"text": "null"
},
{
"answer_id": 314816,
"author": "Chris Simpson",
"author_id": 28896,
"author_profile": "https://Stackoverflow.com/users/28896",
"pm_score": 3,
"selected": false,
"text": "Boolean"
},
{
"answer_id": 314818,
"author": "Claudiu",
"author_id": 15055,
"author_profile": "https://Stackoverflow.com/users/15055",
"pm_score": 1,
"selected": false,
"text": "Parent a { \n boolean val = true;\n boolean val2 = false; \n}\nChild b {\n boolean val = false;\n //here val2 should be unset!\n}\n"
},
{
"answer_id": 314822,
"author": "Hates_",
"author_id": 3410,
"author_profile": "https://Stackoverflow.com/users/3410",
"pm_score": 3,
"selected": false,
"text": "if(state == null) {\n doSomething();\n}\n if(state.awaitingSet()) {\n doSomething();\n}\n"
},
{
"answer_id": 314980,
"author": "WolfmanDragon",
"author_id": 13491,
"author_profile": "https://Stackoverflow.com/users/13491",
"pm_score": -1,
"selected": false,
"text": "private Boolean a = null;\n\npublic void setA(Boolean a) {\n this.a = a;\n}\n\n\npublic Boolean getA() {\n return a;\n}\n if (a == true)\n{\ndothis;\n}\nelse if (a == false)\n{\ndothat;\n}\nelse\n{\nassert false : \"Boolean a has not been set\";\n}\n"
},
{
"answer_id": 34508429,
"author": "voho",
"author_id": 2019710,
"author_profile": "https://Stackoverflow.com/users/2019710",
"pm_score": 4,
"selected": false,
"text": "public static final Optional<Boolean> TRI_TRUE = Optional.of(true);\npublic static final Optional<Boolean> TRI_FALSE = Optional.of(false);\npublic static final Optional<Boolean> TRI_UNKNOWN = Optional.empty();\n"
},
{
"answer_id": 51736697,
"author": "John Coker",
"author_id": 5844925,
"author_profile": "https://Stackoverflow.com/users/5844925",
"pm_score": 1,
"selected": false,
"text": "public class Node {\n private Node parent;\n private Optional<Boolean> something = Optional.empty();\n\n public boolean isSomething() {\n return something.orElseGet(() -> {\n if (parent != null)\n return parent.isSomething();\n return false;\n });\n }\n\n public void setSomething(boolean v) {\n this.something = Optional.of(v);\n }\n}\n public class Node {\n private Node parent;\n private Boolean something;\n\n public boolean isSomething() {\n if (something != null)\n return something;\n if (parent != null)\n return parent.isSomething();\n return false;\n }\n\n public void setSomething(boolean v) {\n this.something = v;\n }\n}\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314800",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5303/"
] |
314,804 | <p>I have an application in which HttpRuntime.AppDomainAppPath returns the correct path with the wrong casing.</p>
<p>I am then trying to use this in a String.Replace and it does not find the path in the filename due to casing.</p>
<p>I am aware that I can use Regex.Replace but would prefer not to.</p>
<p>I have this problem only on the production machine even though the folder in question has the same casing in dev.</p>
<p>I have just noticed that Server.MapPath also returns the wrong casing.</p>
<p>Any ideas?</p>
| [
{
"answer_id": 314859,
"author": "Brian Schmitt",
"author_id": 30492,
"author_profile": "https://Stackoverflow.com/users/30492",
"pm_score": 0,
"selected": false,
"text": "Dim path As String = HttpRuntime.AppDomainAppPath.ToUpper\nDim newpath As String = Replace(path, \"fnd\", \"rplc\")\n"
},
{
"answer_id": 314867,
"author": "Kev",
"author_id": 419,
"author_profile": "https://Stackoverflow.com/users/419",
"pm_score": 0,
"selected": false,
"text": "string newpath = somepath.Replace(s1.ToLower(), s2.ToLower());\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314804",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3821/"
] |
314,824 | <blockquote>
<p><strong>Possible Duplicate:</strong><br>
<a href="https://stackoverflow.com/questions/2647/split-string-in-sql">Split string in SQL</a> </p>
</blockquote>
<p>I have seen <a href="https://stackoverflow.com/questions/tagged/concatenation+sql">a couple of questions related to string concatenation</a> in SQL.
I wonder how would you approach the opposite problem: splitting coma delimited string into rows of data:</p>
<p>Lets say I have tables:</p>
<pre><code>userTypedTags(userID,commaSeparatedTags) 'one entry per user
tags(tagID,name)
</code></pre>
<p>And want to insert data into table</p>
<pre><code>userTag(userID,tagID) 'multiple entries per user
</code></pre>
<p>Inspired by <a href="https://stackoverflow.com/questions/314682/which-tags-are-not-in-the-database">Which tags are not in the database?</a> question</p>
<p><strong>EDIT</strong></p>
<p>Thanks for the answers, actually more then one deserves to be accepted but I can only pick one, and the <a href="https://stackoverflow.com/questions/314824/t-sql-opposite-to-string-concatenation-how-to-split-string-into-multiple-records#314917">solution presented by Cade Roux</a> with recursions seems pretty clean to me. It works on SQL Server 2005 and above. </p>
<p>For earlier version of SQL Server the solution <a href="https://stackoverflow.com/questions/314824/t-sql-opposite-to-string-concatenation-how-to-split-string-into-multiple-records#314833">provided by miies</a> can be used.
For working with text data type <a href="https://stackoverflow.com/questions/314824/t-sql-opposite-to-string-concatenation-how-to-split-string-into-multiple-records#314866">wcm answer</a> will be helpful. Thanks again.</p>
| [
{
"answer_id": 314833,
"author": "user39603",
"author_id": 39603,
"author_profile": "https://Stackoverflow.com/users/39603",
"pm_score": 4,
"selected": false,
"text": "create function [dbo].[Split]\n(\n @string nvarchar(4000),\n @delimiter nvarchar(10)\n)\nreturns @table table\n(\n [Value] nvarchar(4000)\n)\nbegin\n declare @nextString nvarchar(4000)\n declare @pos int, @nextPos int\n\n set @nextString = ''\n set @string = @string + @delimiter\n\n set @pos = charindex(@delimiter, @string)\n set @nextPos = 1\n while (@pos <> 0)\n begin\n set @nextString = substring(@string, 1, @pos - 1)\n\n insert into @table\n (\n [Value]\n )\n values\n (\n @nextString\n )\n\n set @string = substring(@string, @pos + len(@delimiter), len(@string))\n set @nextPos = @pos\n set @pos = charindex(@delimiter, @string)\n end\n return\nend\n"
},
{
"answer_id": 314866,
"author": "wcm",
"author_id": 2173,
"author_profile": "https://Stackoverflow.com/users/2173",
"pm_score": 2,
"selected": false,
"text": "ALTER Function [dbo].[SplitStr] ( \n @txt text \n) \nReturns @tmp Table \n ( \n value varchar(127)\n ) \nas \nBEGIN \n declare @str varchar(8000) \n , @Beg int \n , @last int \n , @size int \n\n set @size=datalength(@txt) \n set @Beg=1 \n\n\n set @str=substring(@txt,@Beg,8000) \n IF len(@str)<8000 set @Beg=@size \n ELSE BEGIN \n set @last=charindex(',', reverse(@str)) \n set @str=substring(@txt,@Beg,8000-@last) \n set @Beg=@Beg+8000-@last+1 \n END \n\n declare @workingString varchar(25) \n , @stringindex int \n\n\n\n while @Beg<=@size Begin \n WHILE LEN(@str) > 0 BEGIN \n SELECT @StringIndex = CHARINDEX(',', @str) \n\n SELECT \n @workingString = CASE \n WHEN @StringIndex > 0 THEN SUBSTRING(@str, 1, @StringIndex-1) \n ELSE @str \n END \n\n INSERT INTO \n @tmp(value)\n VALUES \n (cast(rtrim(ltrim(@workingString)) as varchar(127)))\n SELECT @str = CASE \n WHEN CHARINDEX(',', @str) > 0 THEN SUBSTRING(@str, @StringIndex+1, LEN(@str)) \n ELSE '' \n END \n END \n set @str=substring(@txt,@Beg,8000) \n\n if @Beg=@size set @Beg=@Beg+1 \n else IF len(@str)<8000 set @Beg=@size \n ELSE BEGIN \n set @last=charindex(',', reverse(@str)) \n set @str=substring(@txt,@Beg,8000-@last) \n set @Beg=@Beg+8000-@last+1 \n\n END \n END \n\n return\nEND \n"
},
{
"answer_id": 314905,
"author": "Yann Semet",
"author_id": 5788,
"author_profile": "https://Stackoverflow.com/users/5788",
"pm_score": 3,
"selected": false,
"text": "SELECT substring(commaSeparatedTags,0,charindex(',',commaSeparatedTags))\n"
},
{
"answer_id": 314917,
"author": "Cade Roux",
"author_id": 18255,
"author_profile": "https://Stackoverflow.com/users/18255",
"pm_score": 8,
"selected": true,
"text": "CREATE FUNCTION dbo.Split (@sep char(1), @s varchar(512))\nRETURNS table\nAS\nRETURN (\n WITH Pieces(pn, start, stop) AS (\n SELECT 1, 1, CHARINDEX(@sep, @s)\n UNION ALL\n SELECT pn + 1, stop + 1, CHARINDEX(@sep, @s, stop + 1)\n FROM Pieces\n WHERE stop > 0\n )\n SELECT pn,\n SUBSTRING(@s, start, CASE WHEN stop > 0 THEN stop-start ELSE 512 END) AS s\n FROM Pieces\n )\n"
},
{
"answer_id": 1582640,
"author": "Rory",
"author_id": 8479,
"author_profile": "https://Stackoverflow.com/users/8479",
"pm_score": 3,
"selected": false,
"text": "create FUNCTION dbo.fn_Split2 (@sep nvarchar(10), @s nvarchar(4000))\nRETURNS table\nAS\nRETURN (\n WITH Pieces(pn, start, stop) AS (\n SELECT 1, 1, CHARINDEX(@sep, @s)\n UNION ALL\n SELECT pn + 1, stop + (datalength(@sep)/2), CHARINDEX(@sep, @s, stop + (datalength(@sep)/2))\n FROM Pieces\n WHERE stop > 0\n )\n SELECT pn,\n SUBSTRING(@s, start, CASE WHEN stop > 0 THEN stop-start ELSE 4000 END) AS s\n FROM Pieces\n )\n"
},
{
"answer_id": 2837662,
"author": "Nathan Wheeler",
"author_id": 193939,
"author_profile": "https://Stackoverflow.com/users/193939",
"pm_score": 6,
"selected": false,
"text": "create FUNCTION [dbo].[Split] (@sep VARCHAR(32), @s VARCHAR(MAX))\nRETURNS TABLE\nAS\n RETURN\n (\n SELECT r.value('.','VARCHAR(MAX)') as Item\n FROM (SELECT CONVERT(XML, N'<root><r>' + REPLACE(REPLACE(REPLACE(@s,'& ','& '),'<','<'), @sep, '</r><r>') + '</r></root>') as valxml) x\n CROSS APPLY x.valxml.nodes('//root/r') AS RECORDS(r)\n )\n SELECT * FROM dbo.Split(' ', 'I hate bunnies')\n -----------\n|I |\n|---------|\n|hate |\n|---------|\n|bunnies |\n-----------\n CREATE FUNCTION [dbo].[Split] (@sep VARCHAR(32), @s VARCHAR(MAX))\nRETURNS TABLE\nAS\n RETURN\n (\n SELECT r.value('.','VARCHAR(MAX)') as Item\n FROM (SELECT CONVERT(XML, N'<root><r>' + REPLACE(@s, @sep, '</r><r>') + '</r></root>') as valxml) x\n CROSS APPLY x.valxml.nodes('//root/r') AS RECORDS(r)\n )\n"
},
{
"answer_id": 3378057,
"author": "Martin Smith",
"author_id": 73226,
"author_profile": "https://Stackoverflow.com/users/73226",
"pm_score": 4,
"selected": false,
"text": "with testTable AS\n(\nSELECT 1 AS Id, N'how now brown cow' AS txt UNION ALL\nSELECT 2, N'she sells sea shells upon the sea shore' UNION ALL\nSELECT 3, N'red lorry yellow lorry' UNION ALL\nSELECT 4, N'the quick brown fox jumped over the lazy dog'\n)\n\nSELECT display_term, COUNT(*) As Cnt\n FROM testTable\nCROSS APPLY sys.dm_fts_parser('\"' + txt + '\"', 1033, 0,0)\nGROUP BY display_term\nHAVING COUNT(*) > 1\nORDER BY Cnt DESC\n display_term Cnt\n------------------------------ -----------\nthe 3\nbrown 2\nlorry 2\nsea 2\n"
},
{
"answer_id": 5423208,
"author": "Tomalak",
"author_id": 18771,
"author_profile": "https://Stackoverflow.com/users/18771",
"pm_score": 3,
"selected": false,
"text": "Split CREATE FUNCTION dbo.Split(@data nvarchar(4000), @delimiter nvarchar(100)) \nRETURNS @result table (Id int identity(1,1), Data nvarchar(4000)) \nAS \nBEGIN \n DECLARE @pos INT\n DECLARE @start INT\n DECLARE @len INT\n DECLARE @end INT\n\n SET @len = LEN('.' + @delimiter + '.') - 2\n SET @end = LEN(@data) + 1\n SET @start = 1\n SET @pos = 0\n\n WHILE (@pos < @end)\n BEGIN\n SET @pos = CHARINDEX(@delimiter, @data, @start)\n IF (@pos = 0) SET @pos = @end\n\n INSERT @result (data) SELECT SUBSTRING(@data, @start, @pos - @start)\n SET @start = @pos + @len\n END\n\n RETURN\nEND\n"
},
{
"answer_id": 6788789,
"author": "sayap",
"author_id": 422321,
"author_profile": "https://Stackoverflow.com/users/422321",
"pm_score": 3,
"selected": false,
"text": "using System;\nusing System.Collections;\nusing System.Data.SqlTypes;\nusing System.Text.RegularExpressions;\nusing Microsoft.SqlServer.Server;\n\npublic class UDF\n{\n [SqlFunction(FillRowMethodName=\"FillRow\")]\n public static IEnumerable RegexSplit(SqlString s, SqlString delimiter)\n {\n return Regex.Split(s.Value, delimiter.Value);\n }\n\n public static void FillRow(object row, out SqlString str)\n {\n str = new SqlString((string) row);\n }\n}\n regexp_split_to_table"
},
{
"answer_id": 9714484,
"author": "Darren",
"author_id": 329367,
"author_profile": "https://Stackoverflow.com/users/329367",
"pm_score": 2,
"selected": false,
"text": "CREATE FUNCTION [dbo].Split\n(\n @sep VARCHAR(32), \n @s VARCHAR(MAX)\n)\nRETURNS \n @result TABLE (\n Id INT NULL\n ) \nAS\nBEGIN\n DECLARE @xml XML\n SET @XML = N'<root><r>' + REPLACE(@s, @sep, '</r><r>') + '</r></root>'\n\n INSERT INTO @result(Id)\n SELECT DISTINCT r.value('.','int') as Item\n FROM @xml.nodes('//root//r') AS RECORDS(r)\n\n RETURN\nEND\n"
},
{
"answer_id": 10298045,
"author": "Marek",
"author_id": 619799,
"author_profile": "https://Stackoverflow.com/users/619799",
"pm_score": 0,
"selected": false,
"text": "create function [dbo].[Split](@string varchar(max), @separator varchar(10))\nreturns @splited table ( stringPart varchar(max) )\nwith execute as caller\nas\nbegin\n declare @stringPart varchar(max);\n set @stringPart = '';\n\n while charindex(@separator, @string) > 0\n begin\n set @stringPart = substring(@string, 0, charindex(@separator, @string));\n insert into @splited (stringPart) values (@stringPart);\n set @string = substring(@string, charindex(@separator, @string) + len(@separator), len(@string) + 1);\n end\n\n return;\nend\ngo\n declare @example varchar(max);\nset @example = 'one;string;to;rule;them;all;;';\n\nselect * from [dbo].[Split](@example, ';');\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314824",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3241/"
] |
314,843 | <p>Is it possible to have a post-mortem ( or post-exception ) debugging session in Java ? What would the workarounds be ( if there isn't a solution for this already ) ?</p>
| [
{
"answer_id": 314898,
"author": "Mario Ortegón",
"author_id": 2309,
"author_profile": "https://Stackoverflow.com/users/2309",
"pm_score": 3,
"selected": true,
"text": "-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=XXXX\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314843",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31610/"
] |
314,844 | <p>Here's a simple (hopefully) L10N question:</p>
<p>Do all locales want this format: </p>
<p><em>Sunday, Nov 23, 2008</em></p>
<p>with the weekday before the date, or do some locales want it after the date like this?</p>
<p><em>Nov 23, 2008, Sunday</em></p>
| [
{
"answer_id": 314873,
"author": "PhiLho",
"author_id": 15459,
"author_profile": "https://Stackoverflow.com/users/15459",
"pm_score": 2,
"selected": false,
"text": "\"ahh'\\u6642'mm'\\u5206'ss'\\u79D2' z\", \n\"ahh'\\u6642'mm'\\u5206'ss'\\u79D2'\", \n\"a hh:mm:ss\", \n\"a h:mm\", \n\"yyyy'\\u5E74'M'\\u6708'd'\\u65E5' EEEE\", \n\"yyyy'\\u5E74'M'\\u6708'd'\\u65E5'\", \n\"yyyy/M/d\", \n\"yyyy/M/d\", \n\"{1} {0}\"\n \"h:mm:ss a z\", // full time pattern\n\"h:mm:ss a z\", // long time pattern\n\"h:mm:ss a\", // medium time pattern\n\"h:mm a\", // short time pattern\n\"EEEE, MMMM d, yyyy\", // full date pattern\n\"MMMM d, yyyy\", // long date pattern\n\"MMM d, yyyy\", // medium date pattern\n\"M/d/yy\", // short date pattern\n\"{1} {0}\" // date-time pattern\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314844",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17188/"
] |
314,853 | <p>Wanting to deploy my project on different servers I would prefer to be able to specify a connect string using a relative path. I can't seem to get that to work and want to know if there is some trick to it...?</p>
| [
{
"answer_id": 314951,
"author": "AJ.",
"author_id": 7211,
"author_profile": "https://Stackoverflow.com/users/7211",
"pm_score": 3,
"selected": false,
"text": "database string relativePath = @\"database\\myfile.s3db\";\n string currentPath;\n string absolutePath;\n string connectionString;\n\n currentPath = System.Reflection.Assembly.GetExecutingAssembly().Location;\n absolutePath = System.IO.Path.Combine(currentPath,relativePath);\n\n connectionString = string.Format(\"DataSource={0}\", absolutePath);\n\n SQLiteConnection cnn = new SQLiteConnection(connectionString);\n"
},
{
"answer_id": 396111,
"author": "trendl",
"author_id": 49240,
"author_profile": "https://Stackoverflow.com/users/49240",
"pm_score": 3,
"selected": false,
"text": "\"Data Source=|DataDirectory|mydb.db;...\"\n |DataDirectory| <add key=\"hibernate.connection.connection_string\"\n value=\"Data Source=|DataDirectory|mydb.db;Version=3;Compress=False;synchronous=OFF;\" >\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314853",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4491/"
] |
314,858 | <p>I have a string</p>
<pre><code>var s:String = "This is a line \n This is another line.";
this.txtHolder.text = s; //.text has \n, not a new line
</code></pre>
<p>and i want to put it into a text area, but the new line character is ignored. How can i ensure that the text breaks where i want it to when its assigned?</p>
| [
{
"answer_id": 314964,
"author": "Hates_",
"author_id": 3410,
"author_profile": "https://Stackoverflow.com/users/3410",
"pm_score": 2,
"selected": false,
"text": "\"This is a line {\\n} This is another line.\"\n \"This is a line <br> This is another line.\" \n"
},
{
"answer_id": 728055,
"author": "nevets1219",
"author_id": 82952,
"author_profile": "https://Stackoverflow.com/users/82952",
"pm_score": 0,
"selected": false,
"text": "txt.replace(\"\\\\n\", \"<br/>\");\n"
},
{
"answer_id": 818783,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 6,
"selected": true,
"text": "\\n mxml xml &#13; lazy&#13;fox\n lazy<br />\nfox\n"
},
{
"answer_id": 1009362,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<mx:WindowedApplication xmlns:mx=\"http://www.adobe.com/2006/mxml\"\n creationComplete=\"onComplete();\">\n <mx:Script>\n <![CDATA[\n private function onComplete():void {\n var s:String = \"This is a line \\n This is another line.\";\n this.txtHolder.text = s;\n }\n ]]>\n </mx:Script>\n <mx:TextArea id=\"txtHolder\" />\n</mx:WindowedApplication>\n <?xml version=\"1.0\" encoding=\"utf-8\"?>\n<mx:WindowedApplication xmlns:mx=\"http://www.adobe.com/2006/mxml\"\n creationComplete=\"onComplete();\">\n <mx:Script>\n <![CDATA[\n private function onComplete():void {\n var s:String = \"This is a line \\n This is another line.\";\n this.txtHolder.text = s;\n }\n ]]>\n </mx:Script>\n <mx:Text id=\"txtHolder\" />\n</mx:WindowedApplication>\n"
},
{
"answer_id": 3791590,
"author": "noobular",
"author_id": 298270,
"author_profile": "https://Stackoverflow.com/users/298270",
"pm_score": 3,
"selected": false,
"text": "<mx:TextArea text=\"This is a new line\" />\n"
},
{
"answer_id": 20756162,
"author": "Anuj Sharma",
"author_id": 2022000,
"author_profile": "https://Stackoverflow.com/users/2022000",
"pm_score": 0,
"selected": false,
"text": "var line:String=\"Hello\";\ntextarea1.text += line;\n"
},
{
"answer_id": 30763991,
"author": "Kans",
"author_id": 4659858,
"author_profile": "https://Stackoverflow.com/users/4659858",
"pm_score": 0,
"selected": false,
"text": "protected function addToTextArea(array:Array):void\n {\n textArea.text = \"Array Elements are:\";\n for(var k:int = 0; k < array.length; k=k+1)\n {\n textArea.text = textArea.text +\"\\n\"+ array[k];\n }\n }\n"
},
{
"answer_id": 40706262,
"author": "Jameel",
"author_id": 7185875,
"author_profile": "https://Stackoverflow.com/users/7185875",
"pm_score": 0,
"selected": false,
"text": "var s:String = \"This is a line\" + \"\\n\" + \"This is another line.\";\nthis.txtHolder.text = s;\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314858",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1748529/"
] |
314,864 | <p>Learning a little about T-SQL, and thought an interesting exercise would be to generate a Mandelbrot set with it.</p>
<p>Turns out someone already has (and recently, it appears). I'll let someone else post it as an answer, but I'm curious what optimizations can be made.</p>
<p>Alternately, what would you do to make the code more readable?</p>
<p>I'll select the most readable (yet reasonably compact) version as the accepted answer (too bad we don't have rep bounties yet!) unless someone really comes along with a great optimization.</p>
<p>Bonus points to those answers that teach me a little something about T-SQL.</p>
<p>-Adam</p>
| [
{
"answer_id": 314875,
"author": "Elie",
"author_id": 23249,
"author_profile": "https://Stackoverflow.com/users/23249",
"pm_score": 4,
"selected": false,
"text": "-- AUTHOR: GRAEME JOB\n-- CREATED: 12-OCT-2008\n-- BECAUSE: SINGLE SQL COMMAND < 50 LINES. JUST BECAUSE.\nWITH \n XGEN(X, IX) AS ( -- X DIM GENERATOR\n SELECT CAST(-2.2 AS FLOAT) AS X, 0 AS IX UNION ALL\n SELECT CAST(X + 0.031 AS FLOAT) AS X, IX + 1 AS IX\n FROM XGEN\n WHERE IX < 100\n ),\n YGEN(Y, IY) AS ( -- Y DIM GENERATOR\n SELECT CAST(-1.5 AS FLOAT) AS Y, 0 AS IY UNION ALL\n SELECT CAST(Y + 0.031 AS FLOAT) AS Y, IY + 1 AS IY\n FROM YGEN\n WHERE IY < 100\n ),\n Z(IX, IY, CX, CY, X, Y, I) AS ( -- Z POINT ITERATOR\n SELECT IX, IY, X, Y, X, Y, 0\n FROM XGEN, YGEN \n UNION ALL\n SELECT IX, IY, CX, CY, X * X - Y * Y + CX AS X, Y * X * 2 + CY, I + 1\n FROM Z\n WHERE X * X + Y * Y < 16\n AND I < 100\n )\nSELECT REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(\n REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(\n REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(\n (X0+X1+X2+X3+X4+X5+X6+X7+X8+X9+X10+X11+X12+X13+X14+X15+X16+X17+X18+X19+\n X20+X21+X22+X23+X24+X25+X26+X27+X28+X29+X30+X31+X32+X33+X34+X35+X36+X37+X38+X39+\n X40+X41+X42+X43+X44+X45+X46+X47+X48+X49+X50+X51+X52+X53+X54+X55+X56+X57+X58+X59+\n X60+X61+X62+X63+X64+X65+X66+X67+X68+X69+X70+X71+X72+X73+X74+X75+X76+X77+X78+X79+\n X80+X81+X82+X83+X84+X85+X86+X87+X88+X89+X90+X91+X92+X93+X94+X95+X96+X97+X98+X99),\n 'A',' '), 'B','.'), 'C',','), 'D',','), 'E',','), 'F','-'), 'G','-'),\n 'H','-'), 'I','-'), 'J','-'), 'K','+'), 'L','+'), 'M','+'), 'N','+'),\n 'O','%'), 'P','%'), 'Q','%'), 'R','%'), 'S','@'), 'T','@'), 'U','@'),\n 'V','@'), 'W','#'), 'X','#'), 'Y','#'), 'Z',' ')\nFROM (\n SELECT 'X' + CAST(IX AS VARCHAR) AS IX,\n IY, SUBSTRING('ABCDEFGHIJKLMNOPQRSTUVWXYZ', ISNULL(NULLIF(I, 0), 1), 1) AS I\n FROM Z) ZT\nPIVOT (\n MAX(I) FOR IX IN (\n X0,X1,X2,X3,X4,X5,X6,X7,X8,X9,X10,X11,X12,X13,X14,X15,X16,X17,X18,X19,\n X20,X21,X22,X23,X24,X25,X26,X27,X28,X29,X30,X31,X32,X33,X34,X35,X36,X37,X38,X39,\n X40,X41,X42,X43,X44,X45,X46,X47,X48,X49,X50,X51,X52,X53,X54,X55,X56,X57,X58,X59,\n X60,X61,X62,X63,X64,X65,X66,X67,X68,X69,X70,X71,X72,X73,X74,X75,X76,X77,X78,X79,\n X80,X81,X82,X83,X84,X85,X86,X87,X88,X89,X90,X91,X92,X93,X94,X95,X96,X97,X98,X99)\n) AS PZT\n"
},
{
"answer_id": 315007,
"author": "Charles Bretana",
"author_id": 32632,
"author_profile": "https://Stackoverflow.com/users/32632",
"pm_score": 4,
"selected": true,
"text": "Create PROCEDURE dbo.mandlebrot\n@left float,\n@right float,\n@Top float,\n@Bottom float,\n@Res float,\n@MaxIterations Integer = 500\nAs\nSet NoCount On\n\nDeclare @Grid Table (\n X float Not Null, \n Y float Not Null,\n InSet Bit\n Primary Key (X, Y))\n\nDeclare @Xo float, @Yo float, @Abs float\nDeclare @PtX Float, @PtY Float\nDeclare @Iteration Integer Set @Iteration = 0\nSelect @Xo = @Left, @Yo = @Bottom\n\nWhile @Yo <= @Top Begin\n While @Xo <= @Right Begin\n Select @PtX = @Xo, @PtY = @Yo\n While @Iteration < @MaxIterations \n And (Square(@PtX) + Square(@PtY)) < 4.0 Begin\n Select @PtX = Square(@PtX) - Square(@PtY) + @Xo,\n @PtY = 2* @PtX * @PtY + @Yo\n Select @Iteration, @PtX, @PtY\n Set @Iteration = @Iteration + 1\n End\n Insert @Grid(X, Y, InSet) \n Values(@Xo, @Yo, Case \n When @Iteration < @MaxIterations\n Then 1 Else 0 End)\n Set @Xo = @Xo + @res\n Set @Iteration = 0\n End\n Select @Xo = @Left, \n @Yo = @Yo + @Res\nEnd\n\nSelect * From @Grid\n"
},
{
"answer_id": 522187,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "SET NOCOUNT ON;\n\n--populate\n;WITH Numbers ([row]) AS\n(\n SELECT TOP 100 CAST(ROW_NUMBER() OVER (ORDER BY NEWID()) AS FLOAT) [row]\n FROM sys.columns\n)\nSELECT A.row AS x, \n B.row AS y, \n 0 AS iter, \n A.row AS iterx, \n B.row AS itery, \n '.' AS symbol\nINTO #GRID\nFROM Numbers A, Numbers B\nWHERE B.[row] <= 24\nGO\n\n-- scale\nUPDATE #GRID\nSET x = x * 3.0 / 100.0 - 2,\n y = y * 2.0 / 24.0 - 1,\n iterx = x * 3.0 / 100.0 - 2,\n itery = y * 2.0 / 24.0 - 1\nGO\n\n--iterate\nUPDATE #GRID\nSET iterx = iterx*iterx - itery*itery + x,\n itery = 2*iterx*itery + y,\n iter = iter+1\nWHERE iterx*iterx+itery*itery <= 2*2\nGO 257\n\nUPDATE #GRID SET symbol = CHAR(64+(iter%26)) WHERE NOT iter = 257\nGO\n\n--print\nWITH concatenated (y, c) AS \n(\n SELECT G2.y,\n (SELECT SUBSTRING(G.symbol, 1, 1) AS [data()] FROM #GRID G WHERE G.y = G2.y FOR XML PATH('')) c\n FROM (SELECT DISTINCT y FROM #GRID) AS G2\n)\nSELECT REPLACE(c, ' ', '') FROM concatenated ORDER BY y\nGO\n\n\nDROP TABLE #GRID\n"
},
{
"answer_id": 7221327,
"author": "Peter Aylett",
"author_id": 916464,
"author_profile": "https://Stackoverflow.com/users/916464",
"pm_score": 2,
"selected": false,
"text": "with points (x1,y1,x2,y2,depth) as\n(\n select convert(float,-2.40), convert(float,-2.40), convert(float,2.40), convert(float,2.40), 8\n union all select x1,y1,(x1+x2)/2,(y1+y2)/2,depth-1 from points where depth>0\n union all select (x1+x2)/2,y1,x2,(y1+y2)/2,depth-1 from points where depth>0\n union all select x1,(y1+y2)/2,(x1+x2)/2,y2,depth-1 from points where depth>0\n union all select (x1+x2)/2,(y1+y2)/2,x2,y2,depth-1 from points where depth>0\n),\nmandelbrot(x1,y1,x2,y2,x,y,depth) as\n(\n select x1,y1,x2,y2,convert(float,0),convert(float,0),20 from points where depth=0\n union all\n select x1,y1,x2,y2, x*x-y*y+x1, 2*x*y+y1,depth-1 from mandelbrot where depth > 0 and (x*x+y*y<4)\n)\nselect geometry::STGeomFromText('POLYGON((' +\n convert(varchar,x1) + ' ' + convert(varchar,y1) + ',' +\n convert(varchar,x1) + ' ' + convert(varchar,y2) + ',' +\n convert(varchar,x2) + ' ' + convert(varchar,y2) + ',' +\n convert(varchar,x2) + ' ' + convert(varchar,y1) + ',' +\n convert(varchar,x1) + ' ' + convert(varchar,y1) + '))',0)\n from mandelbrot where depth = 0\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314864",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2915/"
] |
314,872 | <p>There doesn't seem to be much info on this topic so I'm going to outline my specific problem then maybe we can shape the question and the answer into something a bit more universal.</p>
<p>I have this rewrite rule</p>
<pre><code>RewriteEngine On
RewriteBase /bookkeepers/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/?$ index.php?franchise=$1
</code></pre>
<p>Which is changes this URL</p>
<pre><code>http://example.com/location/kings-lynn
</code></pre>
<p>Into this one</p>
<pre><code>http://example.com/location/index.php?franchise=kings-lynn
</code></pre>
<p>The problem I am having is that if I add a trailing slash</p>
<pre><code>http://example.com/location/kings-lynn/
</code></pre>
<p>then the query string is returned as</p>
<pre><code>franchise=kings-lynn/
</code></pre>
<p>and for some reason none of my CSS and Javascript files are being loaded.</p>
<p>Any ideas?</p>
| [
{
"answer_id": 314877,
"author": "Paul Tomblin",
"author_id": 3333,
"author_profile": "https://Stackoverflow.com/users/3333",
"pm_score": 3,
"selected": false,
"text": "RewriteRule ^(.+[^/])/?$ index.php?franchise=$1\n"
},
{
"answer_id": 314895,
"author": "Greg",
"author_id": 24181,
"author_profile": "https://Stackoverflow.com/users/24181",
"pm_score": 4,
"selected": true,
"text": "^(.+[^/])/?$"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314872",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/319/"
] |
314,926 | <p>I have populated a Datatable, from 2 different servers. I am able to make adjustments where my length>0, what I want to do is remove the rows that does not hit. Here is a summary of what I have</p>
<pre><code>DataRow[] dr = payments.dtPayments.Select(myselect);
if (dr.Length > 0)
{
for (int a = 0; a < dr.Length; a++)
{
if (thisOption == true)
dr[0].Delete();
else if (otherOption == true)
{
dr[0]["Date"] = myDataReader["date"].ToString().Trim();
dr[0]["Pay"] = payTypeName(myDataReader["ccdsrc"].ToString()
.Trim());
}
}
}
if (dr.Length == 0)
{
if (LastOption == true)
{
//DataRow should be removed
}
}
</code></pre>
| [
{
"answer_id": 314991,
"author": "Yona",
"author_id": 40007,
"author_profile": "https://Stackoverflow.com/users/40007",
"pm_score": 4,
"selected": false,
"text": "DataRow[] dr = payments.dtPayments.Select(myselect);\nList<DataRow> rowsToRemove = new List<DataRow>();\n\nfor (int a = 0; a < dr.Length; a++) {\n if(/* You want to delete this row */) {\n rowsToRemove.Add(dr[a]);\n }\n}\n\nforeach(var dr in rowsToRemove) {\n payments.dtPayments.Rows.Remove(dr);\n}\n"
},
{
"answer_id": 315005,
"author": "Chris Lees",
"author_id": 1398981,
"author_profile": "https://Stackoverflow.com/users/1398981",
"pm_score": 2,
"selected": false,
"text": "DataRow r = null;\nforeach(DataRow row in table.Rows)\n{\n if(condition==true)\n {\n r = row;\n break;\n }\n}\n\ntable.Rows.Remove(r);\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314926",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
314,933 | <p>How do I do the above? I've started using MVC and I'm having issues passing data around.</p>
<p>My specific problem is to do with a list of objects I have in my Model which I need to access in a View and iterate through.</p>
<p>Thanks in advance.</p>
| [
{
"answer_id": 314992,
"author": "Dave Weaver",
"author_id": 11991,
"author_profile": "https://Stackoverflow.com/users/11991",
"pm_score": 2,
"selected": false,
"text": "Function List() As ViewResult\n ' pass other information in the viewdata dictionary\n ViewData(\"Title\") = \"All Items\"\n ' get our item list from the Model classes\n Dim items = Model.ItemRepository.GetAllItems()\n ' return as part of result\n Return View(items)\nEnd Function\n <% For Each item In ViewData.Model %>\n <%=item.Name%>\n<% End If %>\n <%=ViewData(\"Title\")%>\n"
},
{
"answer_id": 315059,
"author": "Todd Smith",
"author_id": 31624,
"author_profile": "https://Stackoverflow.com/users/31624",
"pm_score": 2,
"selected": false,
"text": "public ActionResult List()\n{\n ViewData[\"MyList\"] = new List<string> () {\"test1\", \"test2\"};\n\n return View ();\n}\n <ul>\n<% foreach (string item in (List<string>)ViewData[\"MyList\"]) { %>\n <li><%= item %></li>\n<% }%>\n</ul>\n"
},
{
"answer_id": 315137,
"author": "Rune",
"author_id": 40348,
"author_profile": "https://Stackoverflow.com/users/40348",
"pm_score": 4,
"selected": true,
"text": "public ActionResult List()\n{\n List<string> myList = database.GetListOfStrings();\n (...)\n}\n public ActionResult List()\n{\n List<string> myList = database.GetListOfStrings();\n (...)\n return View(\"List\", myList);\n}\n public partial class List : ViewPage<string>\n{\n (...)\n}\n <ul>\n <% foreach(var s in this.ViewData.Model){ %>\n <li> <%= s %> </li>\n <% } %>\n</ul>\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314933",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29445/"
] |
314,945 | <p>I'm new using makefiles and I have some makefiles. One of them has these statements I tried to understand but I can't.</p>
<h3>What is this makefile doing?</h3>
<pre><code># debugging support
ifeq ($(DEBUG), true)
CFLAGS+=-DDEBUG -g
endif
ifeq ($(DEBUG), gdb)
CFLAGS+=-g
endif
ifeq ($(PROFILING), true)
CFLAGS+=-p
endif
# symbolic names debugging
ifeq ($(DEBUG_NAMES), true)
CFLAGS+=-DDEBUG_NAMES
endif
# architecture TODO: add others
ifeq ($(ARCH), unix)
CFLAGS+=-DUNIX
endif
# TODO: GC settings
ifeq ($(HEAP), malloc)
CFLAGS+=-DHEAP_MALLOC
endif
ifeq ($(STACK), malloc)
CFLAGS+=-DSTACK_MALLOC
endif
# class loading method
ifeq ($(CLASS), external)
CFLAGS+=-DEXTERNAL_TUK
endif
# monitor allocation
ifeq ($(MONITORS), ondemand)
CFLAGS+=-DON_DEMAND_MONITORS
endif
</code></pre>
<p>Amri</p>
| [
{
"answer_id": 314959,
"author": "Alan",
"author_id": 37843,
"author_profile": "https://Stackoverflow.com/users/37843",
"pm_score": 3,
"selected": false,
"text": "ifeq ($(DEBUG), true)\n\nCFLAGS+=-DDEBUG -g\n\nendif\n"
},
{
"answer_id": 315376,
"author": "Dave Costa",
"author_id": 6568,
"author_profile": "https://Stackoverflow.com/users/6568",
"pm_score": 2,
"selected": false,
"text": "man cc\nman gcc\ncc --help\ngcc --help\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314945",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40341/"
] |
314,958 | <p>I'm looking for an image editor that I can embed easily into an ASP.NET website. I need to be able to draw rectangles, lines and add some text. Additionally, images must not be uploaded to third-party servers.</p>
<p>I've checked sites of the main ISVs that develop .NET controls but none of them provides a standalone image editor that offers all the functionally I mentioned. Most of them let you rotate, flip, resize images and set some filters, that's it. There is one editor <a href="http://pixlr.com/app/" rel="nofollow noreferrer">http://pixlr.com/app/</a>) that is nearly there. Unfortunately all images have to be uploaded to Pixlr servers which is a deal breaker from my perspective. It can bee anything (JavaScript, Flash, Silverlight, etc) that integrates with ASP.NET.</p>
<p>thanks</p>
<p>Pawel</p>
| [
{
"answer_id": 1842096,
"author": "444",
"author_id": 224168,
"author_profile": "https://Stackoverflow.com/users/224168",
"pm_score": 0,
"selected": false,
"text": "if (sense == 1) //Rotate 90 to right\n {\n img.RotateFlip(RotateFlipType.Rotate270FlipXY);\n }\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314958",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3323/"
] |
314,966 | <p>This question is a follow-up to a question I asked the other day <a href="https://stackoverflow.com/questions/302022/sql-need-to-find-duplicate-records-but-exclude-reversed-transactions">("Need to find duplicate records but exclude reversed transactions")</a>.</p>
<p>I have a Crystal Report which displays customers' fuel transactions. There are occasions when a duplicate transaction will be imported erroneously. If/when this error is discovered, the admin will reverse transaction, thus leaving the two original duplicates and a "negative" transaction for the reversal. Example:</p>
<pre><code>Date; Qty; Value; Reversal
1/14/08 5 20 N
1/14/08 5 20 N
1/14/08 -5 -20 Y
1/20/08 8 56 N
1/22/08 9 62 N
1/22/08 9 62 N
</code></pre>
<p>Ideally, the customer will only see SINGLE transactions (or a duplicate transaction which has not been reversed yet). If the transaction has been reversed, we only want them to see the original unique record. Example (based on data above):</p>
<pre><code>Date; Qty; Value;
1/14/08 5 20
1/20/08 8 56
1/22/08 9 62
1/22/08 9 62
</code></pre>
<p>I already have a <strong><em>query</em></strong> which will return the data in the way I just described, but I need to integrate it with a crystal report which requires joins to other tables. Performance is TERRIBLE if I use the sql that I already have, so I'm trying to see if it would be possible to hide duplicate (reversed) transactions within Crystal's formulas instead of using a SQL command as a table joined to other tables.</p>
<p>Please let me know if I am being unclear. I appreciate your wisdom in advance!</p>
| [
{
"answer_id": 315871,
"author": "DJ.",
"author_id": 10492,
"author_profile": "https://Stackoverflow.com/users/10492",
"pm_score": 2,
"selected": false,
"text": "( {Reversal} = \"Y\" ) OR \n( {Date} = Next({Date}) AND {QTY} = Next({QTY}}) * -1 AND \n {Value} = Next({Value}) * -1 AND Next({Reversal}) = \"Y\" )\n ( {Reversal} = \"Y\" ) OR \n( Next({Reversal}) = \"Y\" )\n"
},
{
"answer_id": 316984,
"author": "Tony Andrews",
"author_id": 18747,
"author_profile": "https://Stackoverflow.com/users/18747",
"pm_score": 0,
"selected": false,
"text": "AND rec_type = 'C'\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314966",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/38949/"
] |
314,983 | <p>I know it makes little difference to a project but, assuming you use #defined header guards for your C++ code, what format do you use? e.g. assuming a header called <code>foo.hpp</code>:</p>
<pre><code>#ifndef __FOO_HPP__
...
#ifndef INCLUDED_FOO_HPP
...
#ifndef SOME_OTHER_FORMAT
</code></pre>
<p>I'm sold on the idea of upper-case #defines but cannot settle on a format for these guards.</p>
| [
{
"answer_id": 314989,
"author": "Zebra North",
"author_id": 17440,
"author_profile": "https://Stackoverflow.com/users/17440",
"pm_score": 4,
"selected": false,
"text": "INCLUDED_FOO_HPP"
},
{
"answer_id": 314996,
"author": "James Curran",
"author_id": 12725,
"author_profile": "https://Stackoverflow.com/users/12725",
"pm_score": 2,
"selected": false,
"text": " #if !defined(FOO_HPP_INCLUDED)\n defined #ifndef __FOO_HPP__\n"
},
{
"answer_id": 314999,
"author": "Scott",
"author_id": 68043,
"author_profile": "https://Stackoverflow.com/users/68043",
"pm_score": 1,
"selected": false,
"text": "#ifndef FOOBAR_CPP\n"
},
{
"answer_id": 315008,
"author": "JaredPar",
"author_id": 23283,
"author_profile": "https://Stackoverflow.com/users/23283",
"pm_score": 2,
"selected": false,
"text": "#pragma once\n"
},
{
"answer_id": 315010,
"author": "Martin Cote",
"author_id": 9936,
"author_profile": "https://Stackoverflow.com/users/9936",
"pm_score": 4,
"selected": false,
"text": "#ifndef GUARD_8D419A5B_4AC2_4C34_B16E_2E5199F262ED\n"
},
{
"answer_id": 315018,
"author": "efotinis",
"author_id": 12320,
"author_profile": "https://Stackoverflow.com/users/12320",
"pm_score": 2,
"selected": false,
"text": "#ifndef FOO_HPP\n#define FOO_HPP\n\n/* ... */\n\n#endif // FOO_HPP\n MYLIB_FOO_HPP"
},
{
"answer_id": 315020,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 3,
"selected": false,
"text": "17.4.3.1.2/1"
},
{
"answer_id": 315022,
"author": "Fionn",
"author_id": 21566,
"author_profile": "https://Stackoverflow.com/users/21566",
"pm_score": 5,
"selected": true,
"text": "/myproject/module1/misc.h\n/myproject/module2/misc.h\n _MISC_HPP__ MYPROJECT_MODULE1_MISC_H_\nMYPROJECT_MODULE2_MISC_H_\n"
},
{
"answer_id": 315208,
"author": "Rob Wells",
"author_id": 2974,
"author_profile": "https://Stackoverflow.com/users/2974",
"pm_score": 1,
"selected": false,
"text": "#ifndef FOO_HPP\n#define FOO_HPP 1\n\n...\n\n#endif\n"
},
{
"answer_id": 315225,
"author": "Evan Teran",
"author_id": 13430,
"author_profile": "https://Stackoverflow.com/users/13430",
"pm_score": 0,
"selected": false,
"text": "#ifndef FILE_DATE_H_\n #ifndef SOMEFILE_20082411_H_\n"
},
{
"answer_id": 316158,
"author": "Steve Jessop",
"author_id": 13005,
"author_profile": "https://Stackoverflow.com/users/13005",
"pm_score": 1,
"selected": false,
"text": "#ifndef path_to_file_h\n#define path_to_file_h\n #pragma once"
},
{
"answer_id": 8521430,
"author": "Sebastian Mach",
"author_id": 76722,
"author_profile": "https://Stackoverflow.com/users/76722",
"pm_score": 0,
"selected": false,
"text": "<FILENAME_IN_ALL_CAPS>_<YYYYMMDD>\n <FILENAME_IN_ALL_CAPS>_INCLUDED_<YYYYMMDD>\n <FILENAME_IN_ALL_CAPS>_<YYYYMMDD>a\n<FILENAME_IN_ALL_CAPS>_<YYYYMMDD>b\n<FILENAME_IN_ALL_CAPS>_<YYYYMMDD>...\n"
},
{
"answer_id": 24479819,
"author": "nonsensation",
"author_id": 3087952,
"author_profile": "https://Stackoverflow.com/users/3087952",
"pm_score": 0,
"selected": false,
"text": "_INCLUDED #pragma once <snippet>\n <content><![CDATA[\n#ifndef ${1:${TM_FILEPATH/(.*\\/(include|src))*([^a-zA-Z0-9_]+)*([a-zA-Z0-9_]+)([.])*([a-zA-Z0-9_]+)*/\\U$4_$6/ig}_INCLUDED}\n#define $1\n#pragma once\n\n\n$0\n\n\n#endif // $1\n]]></content>\n <tabTrigger>incguard</tabTrigger>\n <description>include guard</description>\n</snippet>\n yourproject/include/yourlib/yourfile.hpp YOURLIB_YOURFILE_HPP_INCLUDED"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314983",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9236/"
] |
314,994 | <p>I'm reading through K&R and came to the small section on register variables, and was wondering if people here have some good examples of this put into practice.</p>
<p>From section 4.7 in K&R:</p>
<blockquote>
<p>The register declaration looks like<br>
register int x;<br>
register char c;</p>
</blockquote>
<p>To be clear, I'm just hoping to see some cool code samples. I (am pretty sure that I) understand the subject matter so don't feel the need to type up a verbose explanation (unless you want to).</p>
| [
{
"answer_id": 17119028,
"author": "Rafael",
"author_id": 2487874,
"author_profile": "https://Stackoverflow.com/users/2487874",
"pm_score": 2,
"selected": false,
"text": "inline void max_heapify(int *H, int i){\n char OK = FALSE;\n register int l, r, max, hI;\n while(!OK){\n OK = TRUE;\n l = left(i);\n r = right(i);\n max = i;\n if(l <= H[SIZE] && H[l] > H[i]){\n max = l;\n }\n if(r <= H[SIZE] && H[r] > H[max]){\n max = r;\n }\n if(max != i){\n OK = FALSE;\n hI = H[i];\n H[i] = H[max];\n H[max] = hI;\n i = max;\n }\n }\n}\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314994",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25664/"
] |
314,998 | <p>I have a column with a "DEFAULT" constraint. I'd like to create a script that drops that column.</p>
<p>The problem is that it returns this error:</p>
<pre><code>Msg 5074, Level 16, State 1, Line 1
The object 'DF__PeriodSce__IsClo__4BCC3ABA' is dependent on column 'IsClosed'.
Msg 4922, Level 16, State 9, Line 1
ALTER TABLE DROP COLUMN IsClosed failed because one or more objects access this column.
</code></pre>
<p>I couldn't find an easy way to drop a column and all its associated constraints (only found big scripts that look into the system table... there MUST (!!) be a "nice" way to do it.)</p>
<p>And as the DEFAULT constraint's name has been randomly generated, I can't drop it by name.</p>
<hr>
<p><strong>Update</strong> :<br>
The constraint type is "DEFAULT".</p>
<p>I saw the solutions that you all proposed but I find them all really "dirty"... Don't you think?
I don't know if it's with Oracle or MySQL but it's possible to do something like:</p>
<pre><code>DROP COLUMN xxx CASCADE CONSTRAINTS
</code></pre>
<p>And it drops all related constraints...
Or at least it automatically drops the constraints mapped to that column (at least CHECK constraints!)</p>
<p>Is there nothing like that in MSSQL?</p>
| [
{
"answer_id": 315049,
"author": "Steve Sheldon",
"author_id": 30513,
"author_profile": "https://Stackoverflow.com/users/30513",
"pm_score": 2,
"selected": false,
"text": "select CONSTRAINT_NAME from INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE WHERE TABLE_NAME = '<tablename>' AND COLUMN_NAME = 'IsClosed'\n"
},
{
"answer_id": 317396,
"author": "Julien N",
"author_id": 28544,
"author_profile": "https://Stackoverflow.com/users/28544",
"pm_score": 3,
"selected": false,
"text": "> select CONSTRAINT_NAME from INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE\n> WHERE TABLE_NAME = '<tablename>' AND COLUMN_NAME = 'IsClosed'\n select \n t_obj.name as TABLE_NAME\n ,c_obj.name as CONSTRAINT_NAME\n ,col.name as COLUMN_NAME\n\nfrom sysobjects c_obj\njoin sysobjects t_obj on c_obj.parent_obj = t_obj.id \njoin sysconstraints con on c_obj.id = con.constid\njoin syscolumns col on t_obj.id = col.id\n and con.colid = col.colid\nwhere\n c_obj.xtype = 'D'\n"
},
{
"answer_id": 362431,
"author": "edosoft",
"author_id": 6399,
"author_profile": "https://Stackoverflow.com/users/6399",
"pm_score": 6,
"selected": true,
"text": "select \n col.name, \n col.column_id, \n col.default_object_id, \n OBJECTPROPERTY(col.default_object_id, N'IsDefaultCnst') as is_defcnst, \n dobj.name as def_name\nfrom sys.columns col \n left outer join sys.objects dobj \n on dobj.object_id = col.default_object_id and dobj.type = 'D' \nwhere col.object_id = object_id(N'dbo.test') \nand dobj.name is not null\n"
},
{
"answer_id": 1171895,
"author": "Jeremy Stein",
"author_id": 9702,
"author_profile": "https://Stackoverflow.com/users/9702",
"pm_score": 6,
"selected": false,
"text": "MYTABLENAME MYCOLUMNNAME declare @constraint_name sysname, @sql nvarchar(max)\n\nselect @constraint_name = name \nfrom sys.default_constraints \nwhere parent_object_id = object_id('MYTABLENAME')\nAND type = 'D'\nAND parent_column_id = (\n select column_id \n from sys.columns \n where object_id = object_id('MYTABLENAME')\n and name = 'MYCOLUMNNAME'\n )\n\nset @sql = N'alter table MYTABLENAME drop constraint ' + @constraint_name\nexec sp_executesql @sql\n\nalter table MYTABLENAME drop column MYCOLUMNNAME\n\ngo\n"
},
{
"answer_id": 3326657,
"author": "jjroman",
"author_id": 173835,
"author_profile": "https://Stackoverflow.com/users/173835",
"pm_score": 4,
"selected": false,
"text": "declare @tablename nvarchar(200)\ndeclare @colname nvarchar(200)\ndeclare @default sysname, @sql nvarchar(max)\n\nset @tablename = 'your table'\nset @colname = 'column to drop'\n\nselect @default = name \nfrom sys.default_constraints \nwhere parent_object_id = object_id(@tablename)\nAND type = 'D'\nAND parent_column_id = (\n select column_id \n from sys.columns \n where object_id = object_id(@tablename)\n and name = @colname \n )\n\nset @sql = N'alter table ' + @tablename + ' drop constraint ' + @default\nexec sp_executesql @sql\n\nset @sql = N'alter table ' + @tablename + ' drop column ' + @colname\nexec sp_executesql @sql\n"
},
{
"answer_id": 4117406,
"author": "pvolders",
"author_id": 480421,
"author_profile": "https://Stackoverflow.com/users/480421",
"pm_score": 3,
"selected": false,
"text": "CREATE PROCEDURE DropColumnCascading @tablename nvarchar(500), @columnname nvarchar(500)\nAS\n\nSELECT CONSTRAINT_NAME, 'C' AS type\nINTO #dependencies\nFROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE WHERE TABLE_NAME = @tablename AND COLUMN_NAME = @columnname\n\nINSERT INTO #dependencies\nselect d.name, 'C'\nfrom sys.default_constraints d\njoin sys.columns c ON c.column_id = d.parent_column_id AND c.object_id = d.parent_object_id\njoin sys.objects o ON o.object_id = d.parent_object_id\nWHERE o.name = @tablename AND c.name = @columnname\n\nINSERT INTO #dependencies\nSELECT i.name, 'I'\nFROM sys.indexes i\nJOIN sys.index_columns ic ON ic.index_id = i.index_id and ic.object_id=i.object_id\nJOIN sys.columns c ON c.column_id = ic.column_id and c.object_id=i.object_id\nJOIN sys.objects o ON o.object_id = i.object_id\nwhere o.name = @tableName AND i.type=2 AND c.name = @columnname AND is_unique_constraint = 0\n\nDECLARE @dep_name nvarchar(500)\nDECLARE @type nchar(1)\n\nDECLARE dep_cursor CURSOR\nFOR SELECT * FROM #dependencies\n\nOPEN dep_cursor\n\nFETCH NEXT FROM dep_cursor \nINTO @dep_name, @type;\n\nDECLARE @sql nvarchar(max)\n\nWHILE @@FETCH_STATUS = 0\nBEGIN\n SET @sql = \n CASE @type\n WHEN 'C' THEN 'ALTER TABLE [' + @tablename + '] DROP CONSTRAINT [' + @dep_name + ']'\n WHEN 'I' THEN 'DROP INDEX [' + @dep_name + '] ON dbo.[' + @tablename + ']'\n END\n print @sql\n EXEC sp_executesql @sql\n FETCH NEXT FROM dep_cursor \n INTO @dep_name, @type;\nEND\n\nDEALLOCATE dep_cursor\n\nDROP TABLE #dependencies\n\nSET @sql = 'ALTER TABLE [' + @tablename + '] DROP COLUMN [' + @columnname + ']'\n\nprint @sql\nEXEC sp_executesql @sql\n"
},
{
"answer_id": 7251546,
"author": "Steve",
"author_id": 634027,
"author_profile": "https://Stackoverflow.com/users/634027",
"pm_score": 3,
"selected": false,
"text": "DECLARE @tablename nvarchar(500), \n @columnname nvarchar(500)\n\nSELECT @tablename = 'tblProject',\n @columnname = 'CountyKey'\n\n\nSELECT CONSTRAINT_NAME, 'C' AS type\nINTO #dependencies\nFROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE WHERE TABLE_NAME = @tablename AND COLUMN_NAME = @columnname\n\nINSERT INTO #dependencies\nselect d.name, 'C'\nfrom sys.default_constraints d\njoin sys.columns c ON c.column_id = d.parent_column_id AND c.object_id = d.parent_object_id\njoin sys.objects o ON o.object_id = d.parent_object_id\nWHERE o.name = @tablename AND c.name = @columnname\n\nINSERT INTO #dependencies\nSELECT i.name, 'I'\nFROM sys.indexes i\nJOIN sys.index_columns ic ON ic.index_id = i.index_id and ic.object_id=i.object_id\nJOIN sys.columns c ON c.column_id = ic.column_id and c.object_id=i.object_id\nJOIN sys.objects o ON o.object_id = i.object_id\nwhere o.name = @tableName AND i.type=2 AND c.name = @columnname AND is_unique_constraint = 0\n\nINSERT INTO #dependencies\nSELECT s.NAME, 'S'\nFROM sys.stats AS s\nINNER JOIN sys.stats_columns AS sc \n ON s.object_id = sc.object_id AND s.stats_id = sc.stats_id\nINNER JOIN sys.columns AS c \n ON sc.object_id = c.object_id AND c.column_id = sc.column_id\nWHERE s.object_id = OBJECT_ID(@tableName)\nAND c.NAME = @columnname\nAND s.NAME LIKE '_dta_stat%'\n\nDECLARE @dep_name nvarchar(500)\nDECLARE @type nchar(1)\n\nDECLARE dep_cursor CURSOR\nFOR SELECT * FROM #dependencies\n\nOPEN dep_cursor\n\nFETCH NEXT FROM dep_cursor \nINTO @dep_name, @type;\n\nDECLARE @sql nvarchar(max)\n\nWHILE @@FETCH_STATUS = 0\nBEGIN\n SET @sql = \n CASE @type\n WHEN 'C' THEN 'ALTER TABLE [' + @tablename + '] DROP CONSTRAINT [' + @dep_name + ']'\n WHEN 'I' THEN 'DROP INDEX [' + @dep_name + '] ON dbo.[' + @tablename + ']'\n WHEN 'S' THEN 'DROP STATISTICS [' + @tablename + '].[' + @dep_name + ']'\n END\n print @sql\n EXEC sp_executesql @sql\n FETCH NEXT FROM dep_cursor \n INTO @dep_name, @type;\nEND\n\nDEALLOCATE dep_cursor\n\nDROP TABLE #dependencies\n\nSET @sql = 'ALTER TABLE [' + @tablename + '] DROP COLUMN [' + @columnname + ']'\n\nprint @sql\nEXEC sp_executesql @sql\n"
},
{
"answer_id": 11669702,
"author": "Stealth Rabbi",
"author_id": 680268,
"author_profile": "https://Stackoverflow.com/users/680268",
"pm_score": 2,
"selected": false,
"text": "CREATE PROCEDURE [dbo].[RemoveColumnWithDefaultConstraints] \n -- Add the parameters for the stored procedure here\n @tableName nvarchar(max), \n @columnName nvarchar(max)\nAS\nBEGIN\n -- SET NOCOUNT ON added to prevent extra result sets from\n -- interfering with SELECT statements.\n SET NOCOUNT ON;\n\n DECLARE @ConstraintName nvarchar(200)\n SELECT @ConstraintName = Name \n FROM SYS.DEFAULT_CONSTRAINTS \n WHERE PARENT_OBJECT_ID = OBJECT_ID(@tableName) \n AND PARENT_COLUMN_ID = (SELECT column_id FROM sys.columns WHERE NAME = (@columnName) \n AND object_id = OBJECT_ID(@tableName))\n IF @ConstraintName IS NOT NULL\n EXEC('ALTER TABLE ' + @tableName + ' DROP CONSTRAINT ' + @ConstraintName)\n\n IF EXISTS(SELECT * FROM sys.columns WHERE Name = @columnName \n AND Object_ID = Object_ID(@tableName))\n EXEC('ALTER TABLE ' + @tableName + ' DROP COLUMN ' + @columnName) \nEND\nGO\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/314998",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28544/"
] |
315,009 | <p>Question for anyone who's used Mechanical Turk: Is it possible to take an HTML template created on Mechanical Turk's website, and then create more HITs based on that template from the command line tools or API? </p>
<hr>
<p>According to the API docs, it's not possible to create new HTML and add it...from the API. However, what I want to do here is use a HIT template I already created. It would seem like there should be a way to use that template (and load up new data in the API), since Amazon already approved it and I'm using it for HITs already. But I haven't seen a way in the documentation to do so.</p>
<hr>
<p>The main reason I want the HTML is so I can apply styles that I can't apply by using a questions file. If there was some sort of "rich" question file, that might solve the problem.</p>
| [
{
"answer_id": 16437637,
"author": "Thomas",
"author_id": 2338862,
"author_profile": "https://Stackoverflow.com/users/2338862",
"pm_score": 2,
"selected": true,
"text": "HITLayout"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/315009",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40352/"
] |
315,011 | <p>Is there a command, or a set of tables I can look at to determine which tables, stored procedures and views in SQL Server server 2005 have a certain user defined data type?</p>
| [
{
"answer_id": 315055,
"author": "ConcernedOfTunbridgeWells",
"author_id": 15401,
"author_profile": "https://Stackoverflow.com/users/15401",
"pm_score": 2,
"selected": true,
"text": "select s.name\n ,o.name\n ,c.name\n ,t.name\n from sys.schemas s\n join sys.objects o\n on o.schema_id = s.schema_id\n join sys.columns c\n on c.object_id = o.object_id\n join sys.types t\n on c.user_type_id = t.user_type_id\n where t.name = 'Foo'\n select s.name\n ,o.name\n ,p.name\n ,t.name\n from sys.schemas s\n join sys.objects o\n on o.schema_id = s.schema_id\n join sys.parameters p\n on p.object_id = o.object_id\n join sys.types t\n on p.user_type_id = t.user_type_id\n where t.name = 'Foo'\n"
},
{
"answer_id": 315057,
"author": "George Mastros",
"author_id": 1408129,
"author_profile": "https://Stackoverflow.com/users/1408129",
"pm_score": 2,
"selected": false,
"text": "Select * \nFrom Information_Schema.Columns \nWhere DOMAIN_NAME = 'YourUserDefinedTypeName'\n Select * \nFrom Information_Schema.PARAMETERS \nWhere USER_DEFINED_TYPE_NAME = 'YourUserDefinedTypeName'\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/315011",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1942/"
] |
315,017 | <p>I will explain problem with an example:</p>
<p>There is two table in my database, named entry, tags</p>
<p>There is a column named ID_ENTRY in both table. When I add a record to table, entry, I have to take the ID_ENTRY of last added record and add it to table, tags. How can I do it?</p>
| [
{
"answer_id": 315079,
"author": "Joel Coehoorn",
"author_id": 3043,
"author_profile": "https://Stackoverflow.com/users/3043",
"pm_score": 2,
"selected": false,
"text": "\"DECLARE @ID int;INSERT INTO [Entry] (...) VALUES ...; SELECT @ID = scope_identity();INSERT INTO [TAGS] (ID_ENTRY) VALUES (@ID);\"\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/315017",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/439507/"
] |
315,051 | <p>I have a dll that was written in c++, I need to use this dll in my c# code. After searching I found that using P/Invoke would give me access to the function I need, but these functions are defined with in a class and use non-static private member variables. So I need to be able to create an instance of this class to properly use the functions. How can I gain access to this class so that I can create an instance? I have been unable to find a way to do this. </p>
<p>I guess I should note that the c++ dll is not my code.</p>
| [
{
"answer_id": 315064,
"author": "JaredPar",
"author_id": 23283,
"author_profile": "https://Stackoverflow.com/users/23283",
"pm_score": 8,
"selected": true,
"text": "class Foo {\npublic:\n int Bar();\n};\nextern \"C\" Foo* Foo_Create() { return new Foo(); }\nextern \"C\" int Foo_Bar(Foo* pFoo) { return pFoo->Bar(); }\nextern \"C\" void Foo_Delete(Foo* pFoo) { delete pFoo; }\n [DllImport(\"Foo.dll\")]\npublic static extern IntPtr Foo_Create();\n\n[DllImport(\"Foo.dll\")]\npublic static extern int Foo_Bar(IntPtr value);\n\n[DllImport(\"Foo.dll\")]\npublic static extern void Foo_Delete(IntPtr value);\n"
},
{
"answer_id": 36574077,
"author": "Amir Touitou",
"author_id": 938956,
"author_profile": "https://Stackoverflow.com/users/938956",
"pm_score": 5,
"selected": false,
"text": "class __declspec(dllexport) CClassName\n{\n public:\n CClassName();\n ~CClassName();\n void function();\n\n};\n CClassName::CClassName()\n{\n}\n\nCClassName::~CClassName()\n{\n}\n\nvoid CClassName::function()\n{\n std::cout << \"Bla bla bla\" << std::endl;\n\n}\n #include \"ClassName.h\" \n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\nextern __declspec(dllexport) CClassName* CreateClassName();\n\nextern __declspec(dllexport) void DisposeClassName(CClassName* a_pObject);\n\nextern __declspec(dllexport) void function(CClassName* a_pObject);\n\n\n#ifdef __cplusplus\n}\n#endif\n #include \"ClassNameCaller.h\"\n\n\nCClassName* CreateClassName()\n{\n return new CClassName();\n}\n\nvoid DisposeClassName(CClassName* a_pObject)\n{\n if(a_pObject!= NULL)\n {\n delete a_pObject;\n a_pObject= NULL;\n }\n}\n\nvoid function(CClassName* a_pObject)\n{\n if(a_pObject!= NULL)\n {\n a_pObject->function();\n }\n}\n [DllImport(\"ClassNameDll.dll\")]\nstatic public extern IntPtr CreateClassName();\n\n[DllImport(\"ClassNameDll.dll\")]\nstatic public extern void DisposeClassName(IntPtr pClassNameObject);\n\n[DllImport(\"ClassNameDll.dll\")]\nstatic public extern void CallFunction(IntPtr pClassNameObject);\n\n//use the functions\nIntPtr pClassName = CreateClassName();\n\nCallFunction(pClassName);\n\nDisposeClassName(pClassName);\n\npClassName = IntPtr.Zero; \n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/315051",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/55638/"
] |
315,053 | <p>The [x] button in the top bar of a window that normally closes the window in standard Windows, appears to do a minimise instead on Windows Compact.</p>
<p>How do it make it close instead? I need to also be able to raise an event when this happens as I want to preform some logic on window close.</p>
| [
{
"answer_id": 316242,
"author": "Shane Powell",
"author_id": 23235,
"author_profile": "https://Stackoverflow.com/users/23235",
"pm_score": 0,
"selected": false,
"text": "SHDB_HIDE SHDB_SHOW SHDB_SHOWCANCEL SHDB_SHOWCANCEL"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/315053",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/230/"
] |
315,073 | <p>I'm building a JSF+Facelets web app, one piece of which is a method that scans a directory every so often and indexes any changes. This method is part of a bean which is in application scope. I have built a subclass of TimerTask to call the method every X milliseconds. My problem is getting the bean initialized. I can reference the bean on a page, and when I go to the page, the bean is initialized, and works as directed; what I would like instead is for the bean to be initialized when the web context is initialized, so that it doesn't require a page visit to start the indexing method. Google has shown a few people that want this functionality, but no real solutions outside of integrating with Spring, which I really don't want to do just to get this piece of functionality.</p>
<p>I've tried playing around with both the servlets that have "load-on-startup" set, and a ServletContextListener to get things going, and haven't been able to get the set up right, either because there isn't a FacesContext available, or because I can't reference the bean from the JSF environment.</p>
<p>Is there any way to get a JSF bean initialized on web app startup?</p>
| [
{
"answer_id": 322621,
"author": "McDowell",
"author_id": 304,
"author_profile": "https://Stackoverflow.com/users/304",
"pm_score": 5,
"selected": true,
"text": "<listener>\n <listener-class>appobj.MyApplicationContextListener</listener-class>\n</listener>\n public class MyApplicationContextListener implements ServletContextListener {\n\n private static final String FOO = \"foo\";\n\n public void contextInitialized(ServletContextEvent event) {\n MyObject myObject = new MyObject();\n event.getServletContext().setAttribute(FOO, myObject);\n }\n\n public void contextDestroyed(ServletContextEvent event) {\n MyObject myObject = (MyObject) event.getServletContext().getAttribute(\n FOO);\n try {\n event.getServletContext().removeAttribute(FOO);\n } finally {\n myObject.dispose();\n }\n }\n\n}\n <f:view>\n <h:outputText value=\"#{applicationScope.foo.value}\" />\n <h:outputText value=\"#{foo.value}\" />\n</f:view>\n FacesContext.getCurrentInstance()\n .getExternalContext().getApplicationMap().get(\"foo\");\n"
},
{
"answer_id": 11476860,
"author": "John Yeary",
"author_id": 160361,
"author_profile": "https://Stackoverflow.com/users/160361",
"pm_score": 0,
"selected": false,
"text": "SystemEventListener PostConstructApplicationEvent <system-event-listener>\n <system-event-listener-class>\n listeners.SystemEventListenerImpl\n </system-event-listener-class>\n <system-event-class>\n javax.faces.event.PostConstructApplicationEvent\n </system-event-class> \n</system-event-listener>\n public class SystemEventListenerImpl implements SystemEventListener {\n\n @Override\n public void processEvent(SystemEvent event) throws AbortProcessingException {\n Application application = (Application) event.getSource();\n //TODO\n }\n\n @Override\n public boolean isListenerForSource(Object source) {\n return (source instanceof Application);\n }\n}\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/315073",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1322/"
] |
315,074 | <p>I'm designing a system which is receiving data from a number of partners in the form of CSV files. The files may differ in the number and ordering of columns. For the most part, I will want to choose a subset of the columns, maybe reorder them, and hand them off to a parser. I would obviously prefer to be able to transform the incoming data into some canonical format so as to make the parser as simple as possible.</p>
<p>Ideally, I would like to be able to generate a transformation for each incoming data format using some graphical tool and store the transformation as a document in a database or on disk. Upon receival of data, I would apply the correct transformation (never mind how I determine the correct transformation) to get an XML document in a canonical format. If the incoming files had contained XML I would just have created an XSLT document for each format and been on my way.</p>
<p>I've used BizTalk's Flat File XSLT Extensions (or whatever they are called) for something similar in the past, but I don't want the hassle of BizTalk (and I can't afford it either) on this project.</p>
<p>Does anyone know if there are alternative technologies and/or XSLT extensions which would enable me to achieve my goal in an elegant way?</p>
<p>I'm developing my app in C# on .NET 3.5 SP1 (thus would prefer technologies supported by .NET).</p>
| [
{
"answer_id": 1533079,
"author": "Robert Rossney",
"author_id": 19403,
"author_profile": "https://Stackoverflow.com/users/19403",
"pm_score": 0,
"selected": false,
"text": "XmlReader"
},
{
"answer_id": 3366658,
"author": "Jeremiah Jahn",
"author_id": 350068,
"author_profile": "https://Stackoverflow.com/users/350068",
"pm_score": 0,
"selected": false,
"text": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n <xsl:output method=\"xml\" indent=\"yes\" />\n\n<xsl:template match=\"@*|node()\">\n <xsl:copy>\n <xsl:apply-templates select=\"@*|node()\" />\n </xsl:copy>\n</xsl:template>\n\n<xsl:template match=\"//output\">\n <!-- split things up for each new line -->\n <xsl:variable name=\"line\" select=\"tokenize(.,'\\n')\"/>\n <xsl:for-each select=\"$line\"> \n <!-- split each line into peices based on space -->\n <xsl:variable name=\"split\" select=\"tokenize(.,' +')\"/>\n <xsl:if test=\"count($split) > 1\">\n <xsl:element name=\"route\"> \n <xsl:for-each select=\"$split\">\n <xsl:choose>\n <xsl:when test=\"position() = 1\">\n <xsl:attribute name=\"address\" select=\".\"/>\n </xsl:when>\n <xsl:otherwise>\n <xsl:variable name=\"index\" select=\"position()\"/>\n <xsl:variable name=\"fieldName\" select=\".\"/>\n <xsl:if test=\"$fieldName and position() mod 2 = 0\">\n <xsl:attribute name=\"{$fieldName}\" select=\"$split[$index + 1]\"/>\n </xsl:if>\n </xsl:otherwise>\n </xsl:choose>\n </xsl:for-each>\n </xsl:element>\n </xsl:if>\n </xsl:for-each>\n</xsl:template>\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/315074",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40348/"
] |
315,078 | <p>What is the most recommended/best way to stop multiple instances of a setTimeout function from being created (in javascript)?</p>
<p>An example (psuedo code):</p>
<pre><code>function mouseClick()
{
moveDiv("div_0001", mouseX, mouseY);
}
function moveDiv(objID, destX, destY)
{
//some code that moves the div closer to destination
...
...
...
setTimeout("moveDiv(objID, destX, destY)", 1000);
...
...
...
}
</code></pre>
<p>My issue is that if the user clicks the mouse multiple times, I have multiple instances of moveDiv() getting called.</p>
<p>The option I have seen is to create a flag, that only allows the timeout to be called if no other instance is available...is that the best way to go?</p>
<p>I hope that makes it clear....</p>
| [
{
"answer_id": 315107,
"author": "Daniel Schaffer",
"author_id": 2596,
"author_profile": "https://Stackoverflow.com/users/2596",
"pm_score": 2,
"selected": false,
"text": "var timeout1 = window.setTimeout('doSomething();', 1000);\nvar timeout2 = window.setTimeout('doSomething();', 1000);\nvar timeout3 = window.setTimeout('doSomething();', 1000);\n\n// to cancel:\nwindow.clearTimeout(timeout1);\nwindow.clearTimeout(timeout2);\nwindow.clearTimeout(timeout3);\n"
},
{
"answer_id": 315120,
"author": "Már Örlygsson",
"author_id": 16271,
"author_profile": "https://Stackoverflow.com/users/16271",
"pm_score": 1,
"selected": false,
"text": "objID var moving = {};\n\nfunction mouseClick()\n{\n var objID = \"div_0001\";\n if (!moving[objID])\n {\n moving[objID] = true;\n moveDiv(\"div_0001\", mouseX, mouseY);\n }\n}\n"
},
{
"answer_id": 315124,
"author": "Jared",
"author_id": 1980,
"author_profile": "https://Stackoverflow.com/users/1980",
"pm_score": 0,
"selected": false,
"text": "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"UTF-8\">\n<head>\n <title>Javascript example</title>\n <script type=\"text/javascript\"> \n var count = 0;\n function annoy() {\n document.getElementById('testa').onclick = function() { return false; };\n\n setTimeout(function() {\n alert('isn\\'t this annoying? ' + count++);\n document.getElementById('testa').onclick = window.annoy;\n }, 1000);\n\n }\n </script>\n</head>\n<body>\n <h2>Javascript example</h2>\n <a href=\"#\" onClick=\"annoy()\" id=\"testa\">Should Only Fire Once</a><br />\n</body>\n</html>\n"
},
{
"answer_id": 315133,
"author": "hasen",
"author_id": 35364,
"author_profile": "https://Stackoverflow.com/users/35364",
"pm_score": 6,
"selected": true,
"text": "clearTimeout( handle )\n handle = setTimeout( ... )\n var timeout_handles = [] \nfunction set_time_out( id, code, time ) /// wrapper\n{\n if( id in timeout_handles )\n {\n clearTimeout( timeout_handles[id] )\n }\n\n timeout_handles[id] = setTimeout( code, time )\n}\n"
},
{
"answer_id": 315175,
"author": "splattne",
"author_id": 6461,
"author_profile": "https://Stackoverflow.com/users/6461",
"pm_score": 2,
"selected": false,
"text": "// declare an array for all the timeOuts\nvar timeOuts = new Array(); \n\n// then instead of a normal timeOut call do this\ntimeOuts[\"uniqueId\"] = setTimeout('whateverYouDo(\"fooValue\")', 1000); \n\n// to clear them all, just call this\nfunction clearTimeouts() { \n for (key in timeOuts) { \n clearTimeout(timeOuts[key]); \n } \n} \n\n// clear just one of the timeOuts this way\nclearTimeout(timeOuts[\"uniqueId\"]); \n"
},
{
"answer_id": 316593,
"author": "Kent Fredric",
"author_id": 15614,
"author_profile": "https://Stackoverflow.com/users/15614",
"pm_score": 2,
"selected": false,
"text": "var Timeout = { \n _timeouts: {}, \n set: function(name, func, time){ \n this.clear(name); \n this._timeouts[name] = {pending: true, func: func}; \n var tobj = this._timeouts[name];\n tobj.timeout = setTimeout(function()\n { \n/* setTimeout normally passes an accuracy report on some browsers, this just forwards that. */\n tobj.func.call(arguments); \n tobj.pending = false;\n }, time); \n },\n hasRun: function(name)\n { \n if( this._timeouts[name] ) \n {\n return !this._timeouts[name].pending; \n }\n return -1; /* Whut? */ \n },\n runNow: function(name)\n {\n if( this._timeouts[name] && this.hasRun(name)===false )\n {\n this._timeouts[name].func(-1); /* fake time. *shrug* */\n this.clear(name);\n }\n } \n clear: function(name)\n {\n if( this._timeouts[name] && this._timeouts[name].pending ) \n {\n clearTimeout(this._timeouts[name].timeout); \n this._timeouts[name].pending = false; \n }\n }\n};\n\nTimeout.set(\"doom1\", function(){ \n if( Timeout.hasRun(\"doom2\") === true )\n {\n alert(\"OMG, it has teh run\"); \n }\n}, 2000 ); \nTimeout.set(\"doom2\", function(){ \n /* NooP! */\n}, 1000 ); \n"
},
{
"answer_id": 6310934,
"author": "RudiBR",
"author_id": 621572,
"author_profile": "https://Stackoverflow.com/users/621572",
"pm_score": 1,
"selected": false,
"text": "function set_time_out( id, code, time ) /// wrapper\n{\n if(typeof this.timeout_handles == 'undefined') this.timeout_handles = [];\n\n if( id in this.timeout_handles )\n {\n clearTimeout( this.timeout_handles[id] )\n }\n\n this.timeout_handles[id] = setTimeout( code, time )\n}\n"
},
{
"answer_id": 14968132,
"author": "Bruce",
"author_id": 2088907,
"author_profile": "https://Stackoverflow.com/users/2088907",
"pm_score": 0,
"selected": false,
"text": "var TopObjList = new Array();\nfunction ColorCycle( theId, theIndex, RefPoint ) {\n ...\n ...\n ...\n TopObjList.push(setTimeout( function() { ColorCycle( theId, theIndex ,CCr ); },CC_speed));\n TO_l = TopObjList.length;\n if (TO_l > 8888) {\n for (CCl=4777; CCl<TO_l; CCl++) {\n clearTimeout(TopObjList.shift());\n }\n }\n }\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/315078",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2490/"
] |
315,084 | <p>I am the .Net specialist in a consultancy with many difference flavors of developers using many different languages and frameworks. Because everyone is pretty much trying to push their own agendas with our different clients in terms of what technology to propose, I'm constantly finding myself in the classic arguments with them all about "why" .Net may be a better technology solution for a given clients requirements. </p>
<p>Often time here, the debate comes down to the issue of performance. Usually the areas that are argued about here consist of costs, maintainability, and performance. I have a hard time arguing about cost because in general open-source technologies are usually cheaper, and although and can usual put a good word in for .Net in terms of total cost of ownership (It seems to be pretty easy to convince people that .Net applications have relative low costs for maintainability if the application architecture has been thoughtfully designed), we will really only push .Net here if the client understands and is indifferent about the costs associated with Microsoft licensing. In terms of maintainability, like I mentioned before, the other developers here realize how much a difference it can make when an application is thoughtfully designed. I have had around 8 years of experience programming .Net solutions and I'm pretty confident in my ability to present to a client all the features and tool sets that .Net provides to give an application a long, and easy to maintain life span.</p>
<p>So again, what it usually boils down to is an argument over performance. Up until now, I have worked for companies that already used Microsoft development technologies to developer their applications so while I have <em>discussed</em> performance with others in the past I have never been a position where I have had to <em>convince</em> performance. My other co-workers are always boasting about these different website that they go to that show improved performance for open-source web applications. This all being said, what I would like to know from everybody here is where do you usually go to get your information about how may some .Net web applications have out performed other technologies?</p>
<p>Thanks in advance for the advice,</p>
<p>-Matt</p>
| [
{
"answer_id": 315107,
"author": "Daniel Schaffer",
"author_id": 2596,
"author_profile": "https://Stackoverflow.com/users/2596",
"pm_score": 2,
"selected": false,
"text": "var timeout1 = window.setTimeout('doSomething();', 1000);\nvar timeout2 = window.setTimeout('doSomething();', 1000);\nvar timeout3 = window.setTimeout('doSomething();', 1000);\n\n// to cancel:\nwindow.clearTimeout(timeout1);\nwindow.clearTimeout(timeout2);\nwindow.clearTimeout(timeout3);\n"
},
{
"answer_id": 315120,
"author": "Már Örlygsson",
"author_id": 16271,
"author_profile": "https://Stackoverflow.com/users/16271",
"pm_score": 1,
"selected": false,
"text": "objID var moving = {};\n\nfunction mouseClick()\n{\n var objID = \"div_0001\";\n if (!moving[objID])\n {\n moving[objID] = true;\n moveDiv(\"div_0001\", mouseX, mouseY);\n }\n}\n"
},
{
"answer_id": 315124,
"author": "Jared",
"author_id": 1980,
"author_profile": "https://Stackoverflow.com/users/1980",
"pm_score": 0,
"selected": false,
"text": "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"UTF-8\">\n<head>\n <title>Javascript example</title>\n <script type=\"text/javascript\"> \n var count = 0;\n function annoy() {\n document.getElementById('testa').onclick = function() { return false; };\n\n setTimeout(function() {\n alert('isn\\'t this annoying? ' + count++);\n document.getElementById('testa').onclick = window.annoy;\n }, 1000);\n\n }\n </script>\n</head>\n<body>\n <h2>Javascript example</h2>\n <a href=\"#\" onClick=\"annoy()\" id=\"testa\">Should Only Fire Once</a><br />\n</body>\n</html>\n"
},
{
"answer_id": 315133,
"author": "hasen",
"author_id": 35364,
"author_profile": "https://Stackoverflow.com/users/35364",
"pm_score": 6,
"selected": true,
"text": "clearTimeout( handle )\n handle = setTimeout( ... )\n var timeout_handles = [] \nfunction set_time_out( id, code, time ) /// wrapper\n{\n if( id in timeout_handles )\n {\n clearTimeout( timeout_handles[id] )\n }\n\n timeout_handles[id] = setTimeout( code, time )\n}\n"
},
{
"answer_id": 315175,
"author": "splattne",
"author_id": 6461,
"author_profile": "https://Stackoverflow.com/users/6461",
"pm_score": 2,
"selected": false,
"text": "// declare an array for all the timeOuts\nvar timeOuts = new Array(); \n\n// then instead of a normal timeOut call do this\ntimeOuts[\"uniqueId\"] = setTimeout('whateverYouDo(\"fooValue\")', 1000); \n\n// to clear them all, just call this\nfunction clearTimeouts() { \n for (key in timeOuts) { \n clearTimeout(timeOuts[key]); \n } \n} \n\n// clear just one of the timeOuts this way\nclearTimeout(timeOuts[\"uniqueId\"]); \n"
},
{
"answer_id": 316593,
"author": "Kent Fredric",
"author_id": 15614,
"author_profile": "https://Stackoverflow.com/users/15614",
"pm_score": 2,
"selected": false,
"text": "var Timeout = { \n _timeouts: {}, \n set: function(name, func, time){ \n this.clear(name); \n this._timeouts[name] = {pending: true, func: func}; \n var tobj = this._timeouts[name];\n tobj.timeout = setTimeout(function()\n { \n/* setTimeout normally passes an accuracy report on some browsers, this just forwards that. */\n tobj.func.call(arguments); \n tobj.pending = false;\n }, time); \n },\n hasRun: function(name)\n { \n if( this._timeouts[name] ) \n {\n return !this._timeouts[name].pending; \n }\n return -1; /* Whut? */ \n },\n runNow: function(name)\n {\n if( this._timeouts[name] && this.hasRun(name)===false )\n {\n this._timeouts[name].func(-1); /* fake time. *shrug* */\n this.clear(name);\n }\n } \n clear: function(name)\n {\n if( this._timeouts[name] && this._timeouts[name].pending ) \n {\n clearTimeout(this._timeouts[name].timeout); \n this._timeouts[name].pending = false; \n }\n }\n};\n\nTimeout.set(\"doom1\", function(){ \n if( Timeout.hasRun(\"doom2\") === true )\n {\n alert(\"OMG, it has teh run\"); \n }\n}, 2000 ); \nTimeout.set(\"doom2\", function(){ \n /* NooP! */\n}, 1000 ); \n"
},
{
"answer_id": 6310934,
"author": "RudiBR",
"author_id": 621572,
"author_profile": "https://Stackoverflow.com/users/621572",
"pm_score": 1,
"selected": false,
"text": "function set_time_out( id, code, time ) /// wrapper\n{\n if(typeof this.timeout_handles == 'undefined') this.timeout_handles = [];\n\n if( id in this.timeout_handles )\n {\n clearTimeout( this.timeout_handles[id] )\n }\n\n this.timeout_handles[id] = setTimeout( code, time )\n}\n"
},
{
"answer_id": 14968132,
"author": "Bruce",
"author_id": 2088907,
"author_profile": "https://Stackoverflow.com/users/2088907",
"pm_score": 0,
"selected": false,
"text": "var TopObjList = new Array();\nfunction ColorCycle( theId, theIndex, RefPoint ) {\n ...\n ...\n ...\n TopObjList.push(setTimeout( function() { ColorCycle( theId, theIndex ,CCr ); },CC_speed));\n TO_l = TopObjList.length;\n if (TO_l > 8888) {\n for (CCl=4777; CCl<TO_l; CCl++) {\n clearTimeout(TopObjList.shift());\n }\n }\n }\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/315084",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39086/"
] |
315,091 | <p>Suppose you have a GridView with a few columns like:</p>
<p>| Foo | Bar | Total |</p>
<p>and you use a style sheet to make the alternating rows different colors, say light blue and white.</p>
<p>Is there a good way to make a particular column alternate in a different color? For example, I might want the Total column to alternate in medium and light red to bring attention to it in a large grid.</p>
<p>BTW, I know you can programmatically change the color of a cell. I'd like to stick to CSS if it all possible, however, so all my style stuff is in one place. I also don't see an easy way to tell if I'm in an alternating row when I'm inside the event handler.</p>
| [
{
"answer_id": 315123,
"author": "Ben Scheirman",
"author_id": 3381,
"author_profile": "https://Stackoverflow.com/users/3381",
"pm_score": 2,
"selected": false,
"text": "$(\"table#myTable col:odd\").css(\"background-color:#ffe\");\n :odd"
},
{
"answer_id": 315193,
"author": "Jimmy",
"author_id": 4435,
"author_profile": "https://Stackoverflow.com/users/4435",
"pm_score": 0,
"selected": false,
"text": "Row.RowState == RowState.Alternating\n"
},
{
"answer_id": 355469,
"author": "David Schmitt",
"author_id": 4918,
"author_profile": "https://Stackoverflow.com/users/4918",
"pm_score": 0,
"selected": false,
"text": "ListView GridView StyleSelector public class ListViewItemStyleSelector : StyleSelector\n{\n private int i = 0;\n public override Style SelectStyle(object item, DependencyObject container)\n {\n // makes sure the first item always gets the first style, even when restyling\n ItemsControl ic = ItemsControl.ItemsControlFromItemContainer(container);\n if (item == ic.Items[0])\n {\n i = 0;\n }\n string styleKey;\n if (i % 2 == 0)\n {\n styleKey = “ListViewItemStyle1″;\n }\n else\n {\n styleKey = “ListViewItemStyle2″;\n }\n i++;\n return (Style)(ic.FindResource(styleKey));\n }\n}\n CellTemplate Style"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/315091",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3161/"
] |
315,093 | <p>I have a directory to which a process uploads some <code>.pdf</code> files. This process is out of my control.</p>
<p>I need to make those files available through the website using Tomcat.</p>
<p>I have a directory <code>/var/lib/tomcat5/webapps/test1</code> available to the web and I can see the files in it with a browser.</p>
<p>So, I created a symbolic link pointing at the directory with the <code>.pdf</code> files:
<code>/var/lib/tomcat5/webapps/test1/files/</code>, but I can't see anything in that directory.</p>
<p>How can I enable symlinks in the <code>test1</code> directory only? I don't want to enable symlinks everywhere, just so that directory with <code>.pdf</code> files is available to the web.</p>
| [
{
"answer_id": 315145,
"author": "Loki",
"author_id": 39057,
"author_profile": "https://Stackoverflow.com/users/39057",
"pm_score": 4,
"selected": false,
"text": "META-INF <?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n<Context path=\"/myapp\" allowLinking=\"true\">\n\n</Context>\n"
},
{
"answer_id": 322706,
"author": "netjeff",
"author_id": 41191,
"author_profile": "https://Stackoverflow.com/users/41191",
"pm_score": 7,
"selected": true,
"text": "META-INF/context.xml <Context path=\"/myapp\" allowLinking=\"true\"> conf/context.xml allowLinking <Context> <Context> META-INF/context.xml conf/context.xml allowLinking allowLinking=\"false\" <Context override=\"true\" allowLinking=\"true\" ...> path=\"/myapp\" META-INF/context.xml path <Context> server.xml <Context> server.xml myapp/META-INF/context.xml conf/Catalina/localhost/myapp.xml META-INF"
},
{
"answer_id": 30367867,
"author": "Alberto Perez",
"author_id": 2752595,
"author_profile": "https://Stackoverflow.com/users/2752595",
"pm_score": 1,
"selected": false,
"text": "<Context path=\"/data\" docBase=\"C:\\datos\" debug=\"0\" reloadable=\"true\" crossContext=\"false\"/>\n"
},
{
"answer_id": 43673455,
"author": "Nare",
"author_id": 7113974,
"author_profile": "https://Stackoverflow.com/users/7113974",
"pm_score": 2,
"selected": false,
"text": "<Context>\n<WatchedResource>WEB-INF/web.xml</WatchedResource>\n<WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>\n <Resources allowLinking=\"true\" cachingAllowed=\"true\" cacheMaxSize=\"100000\" />\n</Context>\n"
},
{
"answer_id": 48962762,
"author": "weberjn",
"author_id": 503025,
"author_profile": "https://Stackoverflow.com/users/503025",
"pm_score": 3,
"selected": false,
"text": "<Resources allowLinking=\"true\" />\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/315093",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28351/"
] |
315,115 | <p>I'm pretty sure that I'm not understanding something about JPA (I'm using OpenJPA) and it's causing this problem. I want to make a copy of a Job entity.</p>
<pre><code>@Entity
@Table(name="Job")
public class Job implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;
@ManyToOne
private Job job;
@OneToMany(fetch = FetchType.EAGER)
private Set<Job> jobCollection;
...
public Job getJob() {
return this.job;
}
public void setJob(Job job) {
this.job = job;
}
public Set<Job> getCopies() {
return this.jobCollection;
}
public void setCopies(Set<Job> jobCollection) {
this.jobCollection = jobCollection;
}
}
</code></pre>
<p>Running the following code works as I would expect when creating the first copy.</p>
<pre><code>public void testCopyJob(){
Job job = jobManager.findJobById(100);
Job jobWithCopies = null;
try {
jobWithCopies = jobManager.copyJob(job, "test copy");
} catch (Exception e) {
fail(e.getMessage());
}
Set<Job> copies = jobWithCopies.getCopies();
assertEquals("num copies", 1, copies.size());
//make a second copy
Job jobWithCopies2 = null;
try {
jobWithCopies2 = jobManager.copyJob(jobWithCopies, "test copy");
assertEquals("multiple copies", 2, jobWithCopies2.getCopies().size());
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
</code></pre>
<p>Attempting to create a second copy fails with...</p>
<pre><code>[11/25/08 8:46:56:546 EST] 00000018 SystemErr R <openjpa-1.2.1-SNAPSHOT-r422266:686069 fatal general error> org.apache.openjpa.persistence.PersistenceException: null
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1688)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at org.apache.openjpa.kernel.StateManagerImpl.assignObjectId(StateManagerImpl.java:523)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at org.apache.openjpa.kernel.StateManagerImpl.assignField(StateManagerImpl.java:608)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at org.apache.openjpa.kernel.StateManagerImpl.beforeAccessField(StateManagerImpl.java:1494)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at org.apache.openjpa.kernel.StateManagerImpl.accessingField(StateManagerImpl.java:1477)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at entities.Job.pcGetid(Job.java)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at entities.Job.hashCode(Job.java:402)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at java.util.HashMap.putImpl(Unknown Source)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at java.util.HashMap.put(Unknown Source)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at java.util.HashSet.add(Unknown Source)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at org.apache.openjpa.util.java$util$HashSet$proxy.add(Unknown Source)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at entities.controller.JobManager.copyJob(JobManager.java:140)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at entities.controller.JobManagerTest.testCopyJob(JobManagerTest.java:55)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:45)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at java.lang.reflect.Method.invoke(Method.java:599)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at junit.framework.TestCase.runTest(TestCase.java:154)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at junit.framework.TestCase.runBare(TestCase.java:127)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at junit.framework.TestResult$1.protect(TestResult.java:106)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at junit.framework.TestResult.runProtected(TestResult.java:124)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at junit.framework.TestResult.run(TestResult.java:109)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at junit.framework.TestCase.run(TestCase.java:118)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at junit.framework.TestSuite.runTest(TestSuite.java:208)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at junit.framework.TestSuite.run(TestSuite.java:203)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at org.apache.cactus.server.runner.ServletTestRunner.run(ServletTestRunner.java:309)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at org.apache.cactus.server.runner.ServletTestRunner.doGet_aroundBody0(ServletTestRunner.java:187)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at org.apache.cactus.server.runner.ServletTestRunner.doGet_aroundBody1$advice(ServletTestRunner.java:225)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at org.apache.cactus.server.runner.ServletTestRunner.doGet(ServletTestRunner.java:1)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at javax.servlet.http.HttpServlet.service(HttpServlet.java:718)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1449)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:790)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:443)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:175)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3610)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:274)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:926)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1557)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:173)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:455)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:384)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:272)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:202)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:766)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:896)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1527)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R Caused by: java.lang.UnsupportedOperationException
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at org.apache.openjpa.kernel.DetachedStateManager.getMetaData(DetachedStateManager.java:696)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at org.apache.openjpa.jdbc.meta.strats.UntypedPCValueHandler.toRelationDataStoreValue(UntypedPCValueHandler.java:121)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at org.apache.openjpa.jdbc.sql.RowImpl.setRelationId(RowImpl.java:327)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at org.apache.openjpa.jdbc.sql.SecondaryRow.setRelationId(SecondaryRow.java:106)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at org.apache.openjpa.jdbc.meta.strats.HandlerStrategies.set(HandlerStrategies.java:150)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at org.apache.openjpa.jdbc.meta.strats.HandlerStrategies.set(HandlerStrategies.java:104)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at org.apache.openjpa.jdbc.meta.strats.HandlerCollectionTableFieldStrategy.insert(HandlerCollectionTableFieldStrategy.java:154)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at org.apache.openjpa.jdbc.meta.strats.HandlerCollectionTableFieldStrategy.insert(HandlerCollectionTableFieldStrategy.java:130)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at org.apache.openjpa.jdbc.meta.FieldMapping.insert(FieldMapping.java:579)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.insert(AbstractUpdateManager.java:197)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.populateRowManager(AbstractUpdateManager.java:139)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at com.ibm.ws.persistence.jdbc.kernel.ConstraintUpdateManager.flush(ConstraintUpdateManager.java:73)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at com.ibm.ws.persistence.jdbc.kernel.ConstraintUpdateManager.flush(ConstraintUpdateManager.java:60)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.flush(JDBCStoreManager.java:655)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at org.apache.openjpa.kernel.DelegatingStoreManager.flush(DelegatingStoreManager.java:130)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:2010)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:1908)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1679)
[11/25/08 8:46:56:546 EST] 00000018 SystemErr R ... 52 more
</code></pre>
<p>This exception is thrown in the JobManager.copyJob() method (at line: attachedJob.getCopies().add(newJob);)...</p>
<pre><code>@JPAManager(targetEntity=entities.Job.class)
public class JobManager {
private EntityManager getEntityManager() {
EntityManagerFactory emf = Persistence
.createEntityManagerFactory("import");
return emf.createEntityManager();
}
@Action(Action.ACTION_TYPE.FIND)
public Job findJobById(int id) {
EntityManager em = getEntityManager();
Job job = null;
try {
job = (Job) em.find(Job.class, id);
} finally {
em.close();
}
return job;
}
public Job copyJob(Job job, String newJobName) throws Exception {
EntityManager em = getEntityManager();
Job attachedJob = null;
try {
em.getTransaction().begin();
//merge any changes made to job
attachedJob = em.merge(job);
//copy the job and establish bi-directional relationship
Job newJob = new Job(job);
newJob.setName(newJobName);
newJob.setJob(attachedJob);
em.persist(newJob);
attachedJob.getCopies().add(newJob);
em.getTransaction().commit(); //commit changes to original job
} catch (Exception ex) {
try {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
} catch (Exception e) {
ex.printStackTrace();
throw e;
}
throw ex;
} finally {
em.close();
}
return attachedJob;
}
}
</code></pre>
<p>This is the generated DB schema I'm using...</p>
<pre><code>CREATE TABLE Job (id INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY, JOB_ID INTEGER, PRIMARY KEY (id));
CREATE TABLE Job_jobCollection (JOB_ID INTEGER, element VARCHAR(254));
ALTER TABLE Job ADD FOREIGN KEY (JOB_ID) REFERENCES Job (id);
ALTER TABLE Job_jobCollection ADD FOREIGN KEY (JOB_ID) REFERENCES Job (id);
</code></pre>
<p>Looking at the OpenJPA 1.2 source code shows that the DetachedStateManager.getMetaData() method is not implemented so I'm wondering why it's being called. Any tips??</p>
| [
{
"answer_id": 315888,
"author": "yclian",
"author_id": 36397,
"author_profile": "https://Stackoverflow.com/users/36397",
"pm_score": -1,
"selected": false,
"text": "DetachedStateManager.getMetaData()"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/315115",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1294/"
] |
315,132 | <p>I need to share SSO information between two different domains with a cookie, can this be done in PHP and how?</p>
| [
{
"answer_id": 315168,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": ".yourdomain.com"
},
{
"answer_id": 315269,
"author": "KDrewiske",
"author_id": 32134,
"author_profile": "https://Stackoverflow.com/users/32134",
"pm_score": 1,
"selected": false,
"text": "# in httpd.conf (or equivalent)\nphp_value session.cookie_domain mydomain.com\n"
},
{
"answer_id": 914647,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "settings.php ini_set('session.cookie_domain', '.EXAMPLE.com');\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/315132",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/37019/"
] |
315,139 | <p>I want to start using Nunit (finally), I am using Visual Studio 2008.</p>
<p>Is it as simple as importing Nunit into my test project?</p>
<p>I remember seeing a GUI for NUnit, does that do the exact same thing that a separate test project would do, except show you the pass/fail visually?</p>
| [
{
"answer_id": 315246,
"author": "Noaki",
"author_id": 40284,
"author_profile": "https://Stackoverflow.com/users/40284",
"pm_score": 5,
"selected": true,
"text": "Title: &NUnit\nCommand: <path to nunit>\nArguments $(ProjectFileName) /run\nInitial directory: $(ProjectDir)\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/315139",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39677/"
] |
315,142 | <p>I'm wondering if I'm missing something about Java Beans. I like my objects to do as much initialization in the constructor as possible and have a minimum number of mutators. Beans seem to go directly against this and generally feel clunky. What capabilities am I missing out on by not building my objects as Beans?</p>
| [
{
"answer_id": 315179,
"author": "Dónal",
"author_id": 2648,
"author_profile": "https://Stackoverflow.com/users/2648",
"pm_score": 3,
"selected": false,
"text": "Collection<Person> myCollection = // initialise and populate the collection\nComparator nameCompare = new BeanComparator(\"name\");\nCollections.sort(myCollection, nameCompare);\n interface Nameable {\n public String getName();\n public void setName(String name);\n}\n public ModelAndView searchUsers(UserSearchCriteria criteria) {\n // implementation omitted\n}\n maxItems=6 void setMaxItems(int maxItems);\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/315142",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40310/"
] |
315,146 | <p>Is there anything to use, to determine if a type is actually a anonymous type? For example an interface, etc?</p>
<p>The goal is to create something like the following...</p>
<pre><code>//defined like...
public static T Get<T>(this IAnonymous obj, string prop) {
return (T)obj.GetType().GetProperty(prop).GetValue(obj, null);
}
//...
//And then used like...
var something = new { name = "John", age = 25 };
int age = something.Get<int>("age");
</code></pre>
<p>Or is that just the beauty of an anonymous type? Nothing to identify it self because it takes a new shape?</p>
<p><strong>Note</strong> - I realize that you can write an extension method for the <strong>object</strong> class, but that seems like a little overkill, in my opinion.</p>
| [
{
"answer_id": 315152,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 2,
"selected": false,
"text": "[CompilerGenerated] static void Main()\n {\n var foo = new { name = \"John\", age = 25 };\n var func = Get(foo, x => x.age);\n var bar = new { name = \"Marc\", age = 30 };\n int age = func(bar);\n }\n // template here is just for type inference...\n static Func<TSource, TValue> Get<TSource, TValue>(\n TSource template, Func<TSource, TValue> lambda)\n {\n return lambda;\n }\n var foo = new { A = \"B\" };\n Type type = foo.GetType();\n\n CompilerGeneratedAttribute attrib = (CompilerGeneratedAttribute) Attribute.GetCustomAttribute(\n type, typeof(CompilerGeneratedAttribute)); // non-null, therefore is compiler-generated\n"
},
{
"answer_id": 315186,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 7,
"selected": true,
"text": "object"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/315146",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17091/"
] |
315,164 | <p>I'm trying to use the FolderBrowserDialog from my WPF application - nothing fancy. I don't much care that it has the Windows Forms look to it.</p>
<p>However, when I call ShowDialog, I want to pass the owner window which is an IWin32Window. How do I get this from my WPF control?</p>
<p>Actually, does it matter? If I run this code and use the ShowDialog overload with no parameters it works fine. Under what circumstances do I need to pass the owner window?</p>
<p>Thanks,</p>
<p>Craig</p>
| [
{
"answer_id": 315172,
"author": "Jobi Joy",
"author_id": 8091,
"author_profile": "https://Stackoverflow.com/users/8091",
"pm_score": 4,
"selected": false,
"text": " public class OldWindow : System.Windows.Forms.IWin32Window\n{\n IntPtr _handle;\n\n public OldWindow(IntPtr handle)\n {\n _handle = handle;\n }\n\n #region IWin32Window Members\n\n IntPtr System.Windows.Forms.IWin32Window.Handle\n {\n get { return _handle; }\n }\n\n #endregion\n}\n IntPtr mainWindowPtr = new WindowInteropHelper(this).Handle; // 'this' means WPF Window\n folderBrowserDialog.ShowDialog(new OldWindow(mainWindowPtr));\n"
},
{
"answer_id": 315341,
"author": "Craig Shearer",
"author_id": 14537,
"author_profile": "https://Stackoverflow.com/users/14537",
"pm_score": 2,
"selected": false,
"text": "private class OldWindow : System.Windows.Forms.IWin32Window\n{ \n IntPtr _handle; \n public OldWindow(IntPtr handle)\n {\n _handle = handle;\n } \n\n #region IWin32Window Members \n IntPtr System.Windows.Forms.IWin32Window.Handle\n {\n get { return _handle; }\n } \n #endregion\n}\n System.Windows.Forms.FolderBrowserDialog dlg = new FolderBrowserDialog();\n HwndSource source = PresentationSource.FromVisual(this) as HwndSource;\n System.Windows.Forms.IWin32Window win = new OldWindow(source.Handle);\n System.Windows.Forms.DialogResult result = dlg.ShowDialog(win);\n"
},
{
"answer_id": 315436,
"author": "Craig Shearer",
"author_id": 14537,
"author_profile": "https://Stackoverflow.com/users/14537",
"pm_score": 7,
"selected": true,
"text": "public static class MyWpfExtensions\n{\n public static System.Windows.Forms.IWin32Window GetIWin32Window(this System.Windows.Media.Visual visual)\n {\n var source = System.Windows.PresentationSource.FromVisual(visual) as System.Windows.Interop.HwndSource;\n System.Windows.Forms.IWin32Window win = new OldWindow(source.Handle);\n return win;\n }\n\n private class OldWindow : System.Windows.Forms.IWin32Window\n {\n private readonly System.IntPtr _handle;\n public OldWindow(System.IntPtr handle)\n {\n _handle = handle;\n }\n\n #region IWin32Window Members\n System.IntPtr System.Windows.Forms.IWin32Window.Handle\n {\n get { return _handle; }\n }\n #endregion\n }\n}\n var dlg = new FolderBrowserDialog();\nSystem.Windows.Forms.DialogResult result = dlg.ShowDialog(this.GetIWin32Window());\n"
},
{
"answer_id": 3345557,
"author": "Bruno",
"author_id": 378491,
"author_profile": "https://Stackoverflow.com/users/378491",
"pm_score": 2,
"selected": false,
"text": "//add a reference to System.Windows.Forms.dll\n\npublic partial class MainWindow : Window, System.Windows.Forms.IWin32Window\n{\n public MainWindow()\n {\n InitializeComponent();\n }\n\n private void button_Click(object sender, RoutedEventArgs e)\n {\n var fbd = new FolderBrowserDialog();\n fbd.ShowDialog(this);\n }\n\n IntPtr System.Windows.Forms.IWin32Window.Handle\n {\n get\n {\n return ((HwndSource)PresentationSource.FromVisual(this)).Handle;\n }\n }\n}\n"
},
{
"answer_id": 22983261,
"author": "user2307482",
"author_id": 2307482,
"author_profile": "https://Stackoverflow.com/users/2307482",
"pm_score": 1,
"selected": false,
"text": "Module MyWpfExtensions\n\nPublic Function GetIWin32Window(this As Object, visual As System.Windows.Media.Visual) As System.Windows.Forms.IWin32Window\n\n Dim source As System.Windows.Interop.HwndSource = System.Windows.PresentationSource.FromVisual(Visual)\n Dim win As System.Windows.Forms.IWin32Window = New OldWindow(source.Handle)\n Return win\nEnd Function\n\nPrivate Class OldWindow\n Implements System.Windows.Forms.IWin32Window\n\n Public Sub New(handle As System.IntPtr)\n _handle = handle\n End Sub\n\n\n Dim _handle As System.IntPtr\n Public ReadOnly Property Handle As IntPtr Implements Forms.IWin32Window.Handle\n Get\n\n End Get\n End Property\n\n\nEnd Class\n\nEnd Module\n"
},
{
"answer_id": 37111153,
"author": "Branko Dimitrijevic",
"author_id": 533120,
"author_profile": "https://Stackoverflow.com/users/533120",
"pm_score": 2,
"selected": false,
"text": "using System;\nusing System.Windows;\nusing System.Windows.Forms;\n\n// ...\n\n/// <summary>\n/// Utilities for easier integration with WinForms.\n/// </summary>\npublic static class WinFormsCompatibility {\n\n /// <summary>\n /// Gets a handle of the given <paramref name=\"window\"/> and wraps it into <see cref=\"IWin32Window\"/>,\n /// so it can be consumed by WinForms code, such as <see cref=\"FolderBrowserDialog\"/>.\n /// </summary>\n /// <param name=\"window\">\n /// The WPF window whose handle to get.\n /// </param>\n /// <returns>\n /// The handle of <paramref name=\"window\"/> is returned as <see cref=\"IWin32Window.Handle\"/>.\n /// </returns>\n public static IWin32Window GetIWin32Window(this Window window) {\n return new Win32Window(new System.Windows.Interop.WindowInteropHelper(window).Handle);\n }\n\n /// <summary>\n /// Implementation detail of <see cref=\"GetIWin32Window\"/>.\n /// </summary>\n class Win32Window : IWin32Window { // NOTE: This is System.Windows.Forms.IWin32Window, not System.Windows.Interop.IWin32Window!\n\n public Win32Window(IntPtr handle) {\n Handle = handle; // C# 6 \"read-only\" automatic property.\n }\n\n public IntPtr Handle { get; }\n\n }\n\n}\n public partial class MainWindow : Window {\n\n void Button_Click(object sender, RoutedEventArgs e) {\n using (var dialog = new FolderBrowserDialog()) {\n if (dialog.ShowDialog(this.GetIWin32Window()) == System.Windows.Forms.DialogResult.OK) {\n // Use dialog.SelectedPath.\n }\n }\n }\n\n}\n"
},
{
"answer_id": 55601819,
"author": "Shangwu",
"author_id": 6079057,
"author_profile": "https://Stackoverflow.com/users/6079057",
"pm_score": 1,
"selected": false,
"text": "System.Windows.Forms.NativeWindow winForm; \n\npublic MainWindow()\n{\n winForm = new System.Windows.Forms.NativeWindow();\n winForm.AssignHandle(new WindowInteropHelper(this).Handle);\n ...\n}\n\npublic showDialog()\n{\n dlgFolderBrowser.ShowDialog(winForm);\n}\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/315164",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14537/"
] |
315,165 | <p>Is it possible?
By debug I mean setting breakpoints, inspect values and advance step by step.</p>
| [
{
"answer_id": 315318,
"author": "Ned Batchelder",
"author_id": 14343,
"author_profile": "https://Stackoverflow.com/users/14343",
"pm_score": 3,
"selected": false,
"text": "import pdb; pdb.set_trace() \n"
},
{
"answer_id": 53567278,
"author": "Craig",
"author_id": 1856922,
"author_profile": "https://Stackoverflow.com/users/1856922",
"pm_score": 0,
"selected": false,
"text": "from gluon.debug import dbg\ndbg.set_trace()\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/315165",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4264/"
] |
315,177 | <p>I'm relatively new to Javascript and was wondering if there's a quick way to shuffle content that is contained in multiple <code><div></code> tags. For example</p>
<pre><code><div id='d1'>
<span>alpha</span>
<img src='alpha.jpg'>
</div>
<div id='d2'>
<span>beta</span>
<img src='beta.jpg'>
</div>
<div id='d3'>
<span>gamma</span>
<img src='gamma.jpg'>
</div>
<button onclick='shuffle_content();'>Shuffle</button>
</code></pre>
<p>After clicking on the button, I'd like the content in d1, d2, d3 to change places (for example maybe d3 would be first, then d1, then d2).</p>
<p>A quick way to kind of move things around is to copy the first div element (d1), then put it at the very end (after d3), and then delete the original d1. But that doesn't really randomize things. It just makes things go in the cycle (which might be ok).</p>
<p>Any suggestions would be appreciated. Thanks.</p>
| [
{
"answer_id": 315275,
"author": "Rob Allen",
"author_id": 149,
"author_profile": "https://Stackoverflow.com/users/149",
"pm_score": -1,
"selected": false,
"text": "<script type=\"text/javascript\">\n function ajaxManager(){\n var args = ajaxManager.arguments;\n\n if (document.getElementById) {\n var x = (window.ActiveXObject) ? new ActiveXObject(\"Microsoft.XMLHTTP\") : new XMLHttpRequest();\n }\n if (x){ \n switch (args[0]){\n case \"load_page\":\n if (x)\n {\n x.onreadystatechange = function()\n {\n if (x.readyState == 4 && x.status == 200){\n el = document.getElementById(args[2]);\n el.innerHTML = x.responseText;\n }\n }\n x.open(\"GET\", args[1], true);\n x.send(null);\n }\n break;\n\n case \"random_content\":\n ajaxManager('load_page', args[1], args[2]); /* args[1] is the content page, args[2] is the id of the div you want to populate with it. */ \n break;\n } //END SWITCH\n } //END if(x)\n } //END AjaxManager\n\n</script>\n"
},
{
"answer_id": 315353,
"author": "Owen",
"author_id": 4853,
"author_profile": "https://Stackoverflow.com/users/4853",
"pm_score": 5,
"selected": true,
"text": "<div id=\"shuffle\">\n <div id='d1'>...</div>\n <div id='d2'>...</div>\n <div id='d3'>...</div>\n</div>\n function shuffle(e) { // pass the divs to the function\n var replace = $('<div>');\n var size = e.size();\n\n while (size >= 1) {\n var rand = Math.floor(Math.random() * size);\n var temp = e.get(rand); // grab a random div from our set\n replace.append(temp); // add the selected div to our new set\n e = e.not(temp); // remove our selected div from the main set\n size--;\n }\n $('#shuffle').html(replace.html() ); // update our container div with the\n // new, randomized divs\n}\n\nshuffle( $('#shuffle div') );\n"
},
{
"answer_id": 315368,
"author": "hasen",
"author_id": 35364,
"author_profile": "https://Stackoverflow.com/users/35364",
"pm_score": 2,
"selected": false,
"text": "c1 = document.getElementById('div1').innerHTML\nc2 = document.getElementById('div2').innerHTML\nc3 = document.getElementById('div3').innerHTML\n c1_div = 'div2'\nc2_div = 'div1'\nc3_div = 'div3'\n document.getElementById(c1_div).innerHTML = c1\ndocument.getElementById(c2_div).innerHTML = c2\ndocument.getElementById(c3_div).innerHTML = c3\n"
},
{
"answer_id": 315503,
"author": "dlamblin",
"author_id": 459,
"author_profile": "https://Stackoverflow.com/users/459",
"pm_score": 0,
"selected": false,
"text": "function shuffle_content() {\n var divA = new Array(3);\n for(var i=0; i < 3; i++) {\n divA[i] = document.getElementById('d'+(i+1));\n document.body.removeChild(divA[i]);\n }\n while (divA.length > 0)\n document.body.appendChild(divA.splice(Math.floor(Math.random() * divA.length),1)[0]);\n}\n <html>\n<div id=\"cards\">\n<div id=\"card0\">Card0</div><div id=\"card1\">Card1</div>\n<div id=\"card2\">Card2</div><div id=\"card3\">Card3</div>\n<div id=\"card4\">Card4</div><div id=\"card5\">Card5</div>\n<div id=\"card6\">Card6</div><div id=\"card7\">Card7</div>\n<div id=\"card8\">Card8</div><div id=\"card9\">Card9</div>\n</div>\n<button id=\"shuffle\">Shuffle</button>\n<script language=\"javascript\">\n<!--\ndocument.getElementById('shuffle').onclick = function () {\nvar divCards = document.getElementById('cards');\nvar divCardsArray = new Array(\n document.getElementById('card0'),\n document.getElementById('card1'),\n document.getElementById('card2'),\n document.getElementById('card3'),\n document.getElementById('card4'),\n document.getElementById('card5'),\n document.getElementById('card6'),\n document.getElementById('card7'),\n document.getElementById('card8'),\n document.getElementById('card9')\n );\nreturn function() {\n var mDivCardsArray=divCardsArray.slice();\n while (divCards.childNodes.length > 0) {\n divCards.removeChild(divCards.firstChild);\n }\n while (mDivCardsArray.length > 0) {\n var i = Math.floor(Math.random() * mDivCardsArray.length);\n divCards.appendChild(mDivCardsArray[i]);\n mDivCardsArray.splice(i,1);\n }\n return false;\n}\n}()\n//-->\n</script>\n</html>\n while (mDivCardsArray.length > 0) {\n divCards.appendChild(\n mDivCardsArray.splice(\n Math.floor(Math.random() * mDivCardsArray.length)\n ,1)[0]\n );\n }\n cards divCardsArray divCardsArray <html>\n...\n<style>\nhtml,body{height:100%;width:100%;text-align:center;font-family:sans-serif;}\n#cards,#cards div{padding:5px;margin:5px auto 5px auto;width:100px;}\n</style>\n...\n<div id=\"cardA\">CardA</div><div id=\"cardB\">CardB</div>\n...\nvar colorCardsArray = new Array(\n '#f00', '#f80', '#ff0', '#8f0', '#0f0', '#0f8',\n '#0ff', '#08f', '#00f', '#80f', '#f0f', '#f08' );\nfor(var i=0;i<divCardsArray.length;i++)\n divCardsArray[i].style.backgroundColor=colorCardsArray[i];\n...\n</html>\n"
},
{
"answer_id": 9641564,
"author": "gilly3",
"author_id": 361684,
"author_profile": "https://Stackoverflow.com/users/361684",
"pm_score": 4,
"selected": false,
"text": "var parent = $(\"#shuffle\");\nvar divs = parent.children();\nwhile (divs.length) {\n parent.append(divs.splice(Math.floor(Math.random() * divs.length), 1)[0]);\n}\n var parent = document.getElementById(\"shuffle\");\nvar divs = parent.children;\nvar frag = document.createDocumentFragment();\nwhile (divs.length) {\n frag.appendChild(divs[Math.floor(Math.random() * divs.length)]);\n}\nparent.appendChild(frag);\n // Create a document fragment to hold the shuffled elements\nvar frag = document.createDocumentFragment();\n\n// Loop until every element is moved out of the parent and into the document fragment\nwhile (divs.length) {\n\n // select one random child element and move it into the document fragment\n frag.appendChild(divs[Math.floor(Math.random() * divs.length)]);\n}\n\n// appending the document fragment appends all the elements, in the shuffled order\nparent.appendChild(frag);\n"
},
{
"answer_id": 56027518,
"author": "Riccardo Porreca",
"author_id": 11465909,
"author_profile": "https://Stackoverflow.com/users/11465909",
"pm_score": 1,
"selected": false,
"text": "divs sort div append $(function() {\n var parent = $(\"#shuffle\");\n var divs = parent.children();\n divs.sort(function(a, b) {\n return 0.5 - Math.random();\n });\n parent.append(divs);\n});\n sort"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/315177",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5073/"
] |
315,178 | <p>Greetings!</p>
<p>I'm still learning about the GridView control and I have one bound to an ObjectDataSource. My Web form looks like this:</p>
<pre><code><asp:GridView ID="ourGrid" runat="server" DataSourceID="ourDataSource" onrowdatabound="ourGrid_RowDataBound"
HeaderStyle-CssClass="header_style" AlternatingRowStyle-CssClass="altrow_style"
ShowFooter="true">
<columns>
<asp:BoundField DataField="Name" HeaderText="Full Name" />
<asp:BoundField DataField="Gender" HeaderText="Gender" />
<asp:BoundField DataField="BirthYear" HeaderText="Year of Birth" />
<asp:BoundField DataField="JoinDate" HeaderText="Date Joined" HtmlEncode="false" DataFormatString="{0:d}" />
</columns>
</asp:GridView>
<asp:ObjectDataSource ID="ourDataSource" runat="server" SelectMethod="GetTopUsers" TypeName="Acme.Model.OurNewObject">
</asp:ObjectDataSource>
</code></pre>
<p>It currently generates the following markup:</p>
<pre><code><table cellpadding="0" cellspacing="0" summary="">
<thead>
<tr style="header_style">
<th scope="col">Full Name</th>
<th scope="col">Gender</th>
<th scope="col">Year of Birth</th>
<th scope="col">Date Joined</th>
</tr>
</thead>
<tfoot>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</tfoot>
<tbody>
<tr>
<td>John Smith</td>
<td>Male</td>
<td>1967</td>
<td>17-6-2007</td>
</tr>
<tr class="AspNet-GridView-Alternate altrow_style">
<td>Mary Kay</td>
<td>Female</td>
<td>1972</td>
<td>15-11-2007</td>
</tr>
<tr>
<td>Bill Jones</td>
<td>Male</td>
<td>1970</td>
<td>23-2-2007</td>
</tr>
</tbody>
</table>
</code></pre>
<p>There are a few more HTML elements that I'd like to add to the table markup that this GridView control will generate. For starters, I need the TFOOT to look like this:</p>
<pre><code><tfoot>
<tr>
<td colspan="4">
<div>
<a class="footerlink_style" title="Newest Members" href="#">Newest Members</a>
<a class="footerlink_style" title="Top Posters" href="#">Top Posters</a>
</div>
</td>
</tr>
</tfoot>
</code></pre>
<p>The links will not contain databound information, but will likely be Hyperlink controls. Is there a way I can specify this at design-time?</p>
<p>Also, for the THEAD, is it possible to specify separate styles for each column header like this in the GridView?</p>
<pre><code><thead>
<tr style="header_style">
<th scope="col" style="col1_style">Full Name</th>
<th scope="col" style="col2_style">Gender</th>
<th scope="col" style="col3_style">Year of Birth</th>
<th scope="col" style="col4_style">Date Joined</th>
</tr>
</thead>
</code></pre>
<p>Finally, is it possible to specifiy the summary attribute of the table like this?</p>
<pre><code><table cellpadding="0" cellspacing="0" summary="Here is a list of users">
</code></pre>
<p>Thanks in advance.</p>
| [
{
"answer_id": 315264,
"author": "Gavin Miller",
"author_id": 33226,
"author_profile": "https://Stackoverflow.com/users/33226",
"pm_score": -1,
"selected": false,
"text": "if (e.Row.Type == DataControlRowType.Footer)\n{\n// Do Work\n}\n <Columns>\n <asp:BoundField DataField=\"PrimaryKey\" HeaderText=\"TheKey\">\n <headerstyle cssclass=\"Header1\" />\n </asp:BoundField>\n <asp:BoundField DataField=\"Value\" HeaderText=\"AValue\">\n <HeaderStyle cssclass=\"Header2\" />\n </asp:BoundField>\n <%-- ... --%>\n</Columns>\n <asp:GridView id=\"theGrid\" runat=\"server\" summary=\"The Summary\" >\n...\n</asp:GridView>\n"
},
{
"answer_id": 315300,
"author": "Kev",
"author_id": 419,
"author_profile": "https://Stackoverflow.com/users/419",
"pm_score": 1,
"selected": false,
"text": "protected void OurGrid_RowCreated(object sender, GridViewRowEventArgs e)\n{\n if(e.Row.RowType == DataControlRowType.Footer)\n {\n int colSpan = e.Row.Cells.Count;\n\n for(int i = (e.Row.Cells.Count - 1); i >= 1; i -= 1)\n {\n e.Row.Cells.RemoveAt(i);\n e.Row.Cells[0].ColumnSpan = colSpan;\n } \n\n HtmlAnchor link1 = new HtmlAnchor();\n link1.HRef = \"#\";\n link1.InnerText = \"Newest Members\"; \n\n HtmlAnchor link2 = new HtmlAnchor(); \n link2.HRef = \"#\";\n link2.InnerText = \"Top Posters\"; \n\n // Add a non-breaking space...remove the space between & and nbsp;\n // I just can't seem to get it to render in\n LiteralControl space = new LiteralControl(\"& nbsp;\");\n\n Panel p = new Panel();\n p.Controls.Add(link1);\n p.Controls.Add(space);\n p.Controls.Add(link2);\n\n e.Row.Cells[0].Controls.Add(p);\n }\n}\n <asp:GridView ID=\"ourGrid\" onrowcreated=\"OurGrid_RowCreated\" ...\n <asp:BoundField headerstyle-cssclass=\"col1_style1\" DataField=\"Name\" HeaderText=\"Full Name\" /> \n<asp:BoundField headerstyle-cssclass=\"col1_style2\" DataField=\"Gender\" HeaderText=\"Gender\" />\n <asp:GridView ID=\"ourGrid\" summary=\"blah\" ...\n <%@ Page Language=\"C#\" %>\n<%@ Import Namespace=\"System.Data\"%>\n\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n\n<script runat=\"server\">\n protected void Page_Load(object sender, EventArgs e)\n {\n DataSet ds = CreateDataSet();\n this.gv.DataSource = ds.Tables[0];\n\n this.gv.DataBind();\n this.gv.HeaderRow.TableSection = TableRowSection.TableHeader;\n this.gv.FooterRow.TableSection = TableRowSection.TableFooter;\n }\n\n protected void OurGrid_RowCreated(object sender, GridViewRowEventArgs e)\n {\n if (e.Row.RowType == DataControlRowType.Footer)\n {\n int colSpan = e.Row.Cells.Count;\n\n for (int i = (e.Row.Cells.Count - 1); i >= 1; i -= 1)\n {\n e.Row.Cells.RemoveAt(i);\n e.Row.Cells[0].ColumnSpan = colSpan;\n }\n\n HtmlAnchor link1 = new HtmlAnchor();\n link1.HRef = \"#\";\n link1.InnerText = \"Newest Members\";\n\n HtmlAnchor link2 = new HtmlAnchor();\n link2.HRef = \"#\";\n link2.InnerText = \"Top Posters\";\n\n LiteralControl l = new LiteralControl(\" \");\n\n Panel p = new Panel();\n p.Controls.Add(link1);\n p.Controls.Add(l);\n p.Controls.Add(link2);\n\n e.Row.Cells[0].Controls.Add(p);\n\n }\n }\n\n private DataSet CreateDataSet()\n {\n DataTable table = new DataTable(\"tblLinks\");\n DataColumn col;\n DataRow row;\n\n col = new DataColumn();\n col.DataType = Type.GetType(\"System.Int32\");\n col.ColumnName = \"ID\";\n col.ReadOnly = true;\n col.Unique = true;\n table.Columns.Add(col);\n\n col = new DataColumn();\n col.DataType = Type.GetType(\"System.DateTime\");\n col.ColumnName = \"Date\";\n col.ReadOnly = true;\n col.Unique = false;\n table.Columns.Add(col);\n\n col = new DataColumn();\n col.DataType = Type.GetType(\"System.String\");\n col.ColumnName = \"Url\";\n col.ReadOnly = true;\n col.Unique = false;\n table.Columns.Add(col);\n\n DataColumn[] primaryKeysColumns = new DataColumn[1];\n primaryKeysColumns[0] = table.Columns[\"ID\"];\n table.PrimaryKey = primaryKeysColumns;\n\n DataSet ds = new DataSet();\n ds.Tables.Add(table);\n\n row = table.NewRow();\n row[\"ID\"] = 1;\n row[\"Date\"] = new DateTime(2008, 11, 1);\n row[\"Url\"] = \"www.bbc.co.uk/newsitem1.html\";\n table.Rows.Add(row);\n\n row = table.NewRow();\n row[\"ID\"] = 2;\n row[\"Date\"] = new DateTime(2008, 11, 1);\n row[\"Url\"] = \"www.bbc.co.uk/newsitem2.html\";\n table.Rows.Add(row);\n\n return ds;\n }\n</script>\n\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<head runat=\"server\">\n <title></title>\n <style type=\"text/css\">\n .red\n {\n color: red;\n }\n .olive\n {\n color:Olive;\n }\n .teal\n {\n color:Teal;\n }\n </style>\n</head>\n<body>\n <form id=\"form1\" runat=\"server\">\n <div>\n <asp:gridview \n id=\"gv\" \n autogeneratecolumns=\"false\"\n showheader=\"true\" \n showfooter=\"true\"\n summary=\"Here is the news!\"\n caption=\"The Caption\"\n captionalign=\"Top\"\n alternatingrowstyle-cssclass=\"alt_row\" \n useaccessibleheader=\"true\"\n onrowcreated=\"OurGrid_RowCreated\" \n runat=\"server\">\n <columns>\n <asp:boundfield \n headertext=\"ID\" \n headerstyle-cssclass=\"olive\" \n datafield=\"id\" />\n <asp:hyperlinkfield \n headertext=\"Link\" \n headerstyle-cssclass=\"red\" \n datanavigateurlfields=\"Url\" \n datanavigateurlformatstring=\"http://{0}\" \n datatextfield=\"Url\" \n datatextformatstring=\"http://{0}\" />\n <asp:boundfield \n headertext=\"Date\" \n headerstyle-cssclass=\"teal\" \n datafield=\"Date\"/>\n </columns>\n </asp:gridview>\n </div>\n </form>\n</body>\n</html>\n <table cellspacing=\"0\" \n rules=\"all\" \n summary=\"Here is the news!\" \n border=\"1\" \n id=\"gv\" \n style=\"border-collapse:collapse;\">\n\n <caption align=\"Top\">\n The Caption\n </caption>\n <thead>\n <tr>\n <th class=\"olive\" scope=\"col\">ID</th>\n <th class=\"red\" scope=\"col\">Link</th>\n <th class=\"teal\" scope=\"col\">Date</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <td>1</td>\n <td>\n <a href=\"http://www.bbc.co.uk/newsitem1.html\">\n http://www.bbc.co.uk/newsitem1.html\n </a>\n </td>\n <td>01/11/2008 00:00:00</td>\n </tr>\n <tr class=\"alt_row\">\n <td>2</td>\n <td>\n <a href=\"http://www.bbc.co.uk/newsitem2.html\">\n http://www.bbc.co.uk/newsitem2.html\n </a>\n </td>\n <td>01/11/2008 00:00:00</td>\n </tr>\n </tbody>\n <tfoot>\n <tr>\n <td colspan=\"3\">\n <div>\n <a href=\"#\">Newest Members</a> <a href=\"#\">Top Posters</a>\n </div>\n </td>\n </tr>\n </tfoot>\n</table>\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/315178",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27870/"
] |
315,183 | <p>We are developing large ASP.NET applications with lot of dynmically created pages containing ASCX controls. We use a lot of jQuery everywhere.</p>
<p>I have been reading that it would make sense to move the inline JavaScript code to the bottom of the page as it could delay the loading of the page when it's included "too early".</p>
<p>My question is now: <strong>Does this still make sense when working with jQuery?</strong> </p>
<p>Most of the code is executed in the ready handler, so I would expect that is does not slow down the loading of the page.
In my case the multiple Usercontrols <strong>ASCX have all their own jQuery</strong> bits and pieces, and it would not be easy to move that all down in the rendered page.</p>
| [
{
"answer_id": 315869,
"author": "Már Örlygsson",
"author_id": 16271,
"author_profile": "https://Stackoverflow.com/users/16271",
"pm_score": 4,
"selected": false,
"text": "<script>"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/315183",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36546/"
] |
315,185 | <p>I have a large db with many tables and sprocs, and I want to find and see, for example, if there is a table with a name that has "setting" as part of it. I'm not very familiar with SqlServer's System Databases like master, msdb etc., I know there is a way to query one of those dbs to get what I need back, does someone know how to do it?</p>
<p>Thank you,
Ray.</p>
| [
{
"answer_id": 315190,
"author": "Steven A. Lowe",
"author_id": 9345,
"author_profile": "https://Stackoverflow.com/users/9345",
"pm_score": 1,
"selected": false,
"text": "SELECT * \nFROM sys.objects\n"
},
{
"answer_id": 315195,
"author": "ahockley",
"author_id": 8209,
"author_profile": "https://Stackoverflow.com/users/8209",
"pm_score": 0,
"selected": false,
"text": "SELECT * FROM sysobjects WHERE xtype = 'U' AND NAME LIKE '%setting%'\n"
},
{
"answer_id": 315199,
"author": "Joel Coehoorn",
"author_id": 3043,
"author_profile": "https://Stackoverflow.com/users/3043",
"pm_score": 2,
"selected": false,
"text": "SELECT * FROM INFORMATION_SCHEMA.tables where table_name LIKE '%Settings%'\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/315185",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32240/"
] |
315,196 | <p>I have a SQL challenge that is wracking my brain. I am trying to reconcile two reports for licenses of an application. </p>
<p>The first report is an access database table. It has been created and maintained by hand by my predecessors. Whenever they installed or uninstalled the application they would manually update the table, more or less. It has a variety of columns of inconsistent data, including Name(displayName) Network ID(SAMAccountName) and Computer Name. Each record has a value for at least one of these fields. Most only have 1 or 2 of the values, though. </p>
<p>The second report is based on an SMS inventory. It has three columns: NetbiosName for the computer name, SAMAccountName, and displayName. Every record has a NetbiosName, but there are some nulls in SAMAccountName and displayName. </p>
<p>I have imported both of these as tables in an MS SQL Server 2005 database.</p>
<p>What I need to do is get a report of each record in the Access table that is not in the SMS table and vice versa. I think it can be done with a properly formed join and where clause, but I can't see how to do it. </p>
<p><em>Edit to add more detail:</em><br>
If the records match for at least one of the three columns, it is a match. So I need the records form the Access table where the Name, NetworkID, and ComputerName are all missing from the SMS table. I can do it for anyone column, but I can't see how to combine all three columns.</p>
| [
{
"answer_id": 315203,
"author": "Noah Goodrich",
"author_id": 20178,
"author_profile": "https://Stackoverflow.com/users/20178",
"pm_score": 0,
"selected": false,
"text": "SELECT displayName, 'report_1' as type\nFROM report_1 r1 \nLEFT OUTER JOIN report_2 r2 ON r1.SAMAccountName = r2.SAMAccountName\nWHERE r2.SAMAccountName IS NULL\nUNION\nSELECT displayName, 'report_2' as type\nFROM report_1 r1\nRIGHT OUTER JOIN report_2 r2 ON r1.SAMAccountName = r2.SAMAccountName\nWHERE r1.SAMAccountName IS NULL\n"
},
{
"answer_id": 315309,
"author": "Jonas Lincoln",
"author_id": 17436,
"author_profile": "https://Stackoverflow.com/users/17436",
"pm_score": 1,
"selected": false,
"text": "SELECT *\nFROM report_1 r1 \nFULL OUTER JOIN report_2 r2 ON r1.SAMAccountName = r2.SAMAccountName\nWHERE r2.SAMAccountName IS NULL OR r1.SAMAccountName IS NULL\n"
},
{
"answer_id": 315856,
"author": "devio",
"author_id": 21336,
"author_profile": "https://Stackoverflow.com/users/21336",
"pm_score": 3,
"selected": true,
"text": "SELECT *\nFROM report_1 r1 \nFULL OUTER JOIN report_2 r2 \n ON r1.SAMAccountName = r2.SAMAccountName\n OR r1.NetbiosName = r2.NetbiosName\n OR r1.DisplayName = r2.DisplayName\nWHERE r2.NetbiosName IS NULL OR r1.NetbiosName IS NULL\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/315196",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8007/"
] |
315,209 | <p>I've got Postscript code/data (?) in memory (in a Java Tomcat webapp) that I'd like to send directly to a networked PS printer. Is there an easy way (i.e. just popping open a port and sending the text) to print this, bypassing all of the O/S-specific drivers and stuff (and hopefully not even requiring extra jars)? A link to example code showing how to do this?</p>
<p>Thanks,
Dave</p>
| [
{
"answer_id": 315238,
"author": "VonC",
"author_id": 6309,
"author_profile": "https://Stackoverflow.com/users/6309",
"pm_score": 0,
"selected": false,
"text": "import com.adobe.livecycle.output.client.*;\nimport java.util.*; \nimport java.io.File; \nimport java.io.FileInputStream; \nimport com.adobe.idp.Document; \nimport com.adobe.idp.dsc.clientsdk.ServiceClientFactory;\n\npublic class SendToPrinter {\n\n public static void main(String[] args) {\n try{\n //Set LiveCycle ES service connection properties \n Properties ConnectionProps = new Properties();\n ConnectionProps.setProperty(\"DSC_DEFAULT_EJB_ENDPOINT\", \"jnp://localhost:1099\");\n ConnectionProps.setProperty(\"DSC_TRANSPORT_PROTOCOL\",\"EJB\"); \n ConnectionProps.setProperty(\"DSC_SERVER_TYPE\", \"JBoss\");\n ConnectionProps.setProperty(\"DSC_CREDENTIAL_USERNAME\", \"administrator\");\n ConnectionProps.setProperty(\"DSC_CREDENTIAL_PASSWORD\", \"password\");\n //Create a ServiceClientFactory object\n ServiceClientFactory myFactory = ServiceClientFactory.createInstance(ConnectionProps);\n //Create an OutputClient object\n OutputClient outClient = new OutputClient(myFactory); \n //Reference XML data that represents form data\n FileInputStream fileInputStream = new FileInputStream(\"C:\\\\Adobe\\\\Loan_data.xml\"); \n Document inputXML = new Document(fileInputStream);\n //Set print run-time options\n PrintedOutputOptionsSpec printOptions = new PrintedOutputOptionsSpec(); \n printOptions.setPrinterURI(\"\\\\\\\\Printer1\\\\Printer\");\n printOptions.setCopies(2);\n\n //Send a PostScript print stream to printer\n OutputResult outputDocument = outClient.generatePrintedOutput(\n PrintFormat.PostScript,\n \"Loan.xdp\",\n \"C:\\\\Adobe\",\n \"C:\\\\Adobe\",\n printOptions,\n inputXML); \n\n //Write the results of the operation to OutputLog.xml\n Document resultData = outputDocument.getStatusDoc();\n File myFile = new File(\"C:\\\\Adobe\\\\OutputLog.xml\");\n resultData.copyToFile(myFile);\n }\n catch (Exception ee)\n {\n ee.printStackTrace();\n }\n }\n}\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/315209",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40373/"
] |
315,210 | <p>I've got a Visual Studio 2008 solution with a WCF service, and a client.</p>
<p>When I run my client, and call a method from my service I get a message saying "Unable to automatically debug 'Home.Service'. The remote procedure could not be debugged. This usually indicates that debugging has not been enabled on the server."</p>
<p>I've googled around, and have tried the following.</p>
<pre><code><system.web>
<compilation debug="true" />
</system.web>
</code></pre>
<p>has been added in app.config on both the client and the server.</p>
<p>I have also made sure that the project is being compiled in Debug mode.</p>
<p>What else could be causing this message?</p>
<p>Edit: Added more info based on feedback questions</p>
<ul>
<li>It is using wsHttpBinding</li>
<li><p>I have set</p>
<pre><code><serviceDebug includeExceptionDetailInFaults="true"/>
</code></pre></li>
<li><p>I am using</p>
<pre><code>var service = new HomeReference.HomeServiceClient();
service.ClientCredentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
</code></pre></li>
</ul>
<p>Unfortunately the error shows up the first time I call a method on my Service. I can dismiss the messagebox, and the application continues working. Any Exceptions thrown on the server at not propagated back to the client though (I assume it should?)</p>
| [
{
"answer_id": 315216,
"author": "Ta01",
"author_id": 7280,
"author_profile": "https://Stackoverflow.com/users/7280",
"pm_score": 0,
"selected": false,
"text": " <serviceBehaviors>\n\n <serviceDebug includeExceptionDetailInFaults=\"true\"/>\n </behavior>\n </serviceBehaviors>\n"
},
{
"answer_id": 315255,
"author": "Michael Kniskern",
"author_id": 26327,
"author_profile": "https://Stackoverflow.com/users/26327",
"pm_score": -1,
"selected": false,
"text": "MyWCFService.IService _proxy = new MyWCFService.IService();\n_proxy.ClientCredentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;\n"
},
{
"answer_id": 1142572,
"author": "Samuel Jack",
"author_id": 1727,
"author_profile": "https://Stackoverflow.com/users/1727",
"pm_score": 5,
"selected": true,
"text": "<customBinding>\n <binding name=\"AuthorisedBinaryHttpsBinding\" receiveTimeout=\"00:03:00\" sendTimeout=\"00:03:00\">\n <!-- this next element caused the problem: -->\n <security authenticationMode=\"UserNameOverTransport\">\n </security>\n <binaryMessageEncoding>\n <readerQuotas maxDepth=\"100\" maxStringContentLength=\"1000000\"\n maxArrayLength=\"655360000\" />\n </binaryMessageEncoding>\n <httpsTransport />\n </binding>\n </customBinding>\n var binding = new CustomBinding(\n binaryEncoding,\n SecurityBindingElement.CreateUserNameOverTransportBindingElement(),\n new HttpsTransportBindingElement { MaxReceivedMessageSize = MaxMessageSize, });\n"
},
{
"answer_id": 15094582,
"author": "Jorge Garcia",
"author_id": 1883876,
"author_profile": "https://Stackoverflow.com/users/1883876",
"pm_score": 3,
"selected": false,
"text": "<system.web>\n <compilation debug=\"true\" />\n</system.web>\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/315210",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33431/"
] |
315,218 | <p>My C++ framework has Buttons. A Button derives from Control. So a function accepting a Control can take a Button as its argument. So far so good.</p>
<p>I also have List<code><</code>T>. However, List<code><</code>Button> doesn't derive from List<code><</code>Control>, which means a function accepting a list of Controls can't take a list of Buttons as its argument. This is unfortunate.</p>
<p>Maybe this is a stupid question, but I don't see how can I solve this :( List<code><</code>Button<code>></code> should derive from List<code><</code>Control<code>></code>, but I don't see a way to make this happen "automatically".</p>
| [
{
"answer_id": 315232,
"author": "Zebra North",
"author_id": 17440,
"author_profile": "https://Stackoverflow.com/users/17440",
"pm_score": 3,
"selected": false,
"text": "list<Control*>"
},
{
"answer_id": 315248,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 3,
"selected": false,
"text": "vector<Apple*> vector<Fruit*> Control List<Control*> List<Button> List<Control> class MyWindow {\n template<typename T>\n void doSomething(List<T> & l) {\n // do something with the list...\n if(boost::is_same<Control, T>::value) {\n // special casing Control\n\n } else if(boost::is_same<Button, T>::value) {\n // special casing Button\n\n }\n\n }\n};\n doSomething List<derived from Control> enable_if doSomething"
},
{
"answer_id": 315278,
"author": "Michel",
"author_id": 31122,
"author_profile": "https://Stackoverflow.com/users/31122",
"pm_score": 4,
"selected": true,
"text": "list<button*> list<control*> list<control*> list<button*> template <class TControl>\nvoid doSomething( const std::list<TControl*>& myControls ) {\n ... whatever the function is currently doing ...\n}\n\nvoid doSomethingElse() {\n std::list<Button*> buttons;\n std::list<Control*> controls;\n doSomething( buttons );\n doSomething( controls );\n}\n"
},
{
"answer_id": 316839,
"author": "Pieter",
"author_id": 5822,
"author_profile": "https://Stackoverflow.com/users/5822",
"pm_score": 0,
"selected": false,
"text": "template < class iterator >\ndoSomething(iterator beg, iterator end);\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/315218",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39301/"
] |
315,227 | <p>So my goal is to be able to add a user from one Active Directory Domain to another group in a separate Active Directory Domain.</p>
<p>I'd like to do this in C#. I know there is a System.DirectoryServices namespace with classes to communicate with AD, but I can't find any information on adding users across domains.</p>
<p>In the environment there are two domain controllers with the same parent forest. There is a transient trust between the 2 domains, let's call them domains A and B.</p>
<p>I'm able to add a user from B to a Domain Local or Universal group inside of domain A with the Active Directory tool.</p>
<p>Does anyone know how I can do this programmatically using C#?</p>
| [
{
"answer_id": 392491,
"author": "barneytron",
"author_id": 48988,
"author_profile": "https://Stackoverflow.com/users/48988",
"pm_score": 1,
"selected": false,
"text": "DirectoryEntry group = new DirectoryEntry(@\"LDAP://CN=foo,DC=domainA\");\nstring memberADsPath = @\"LDAP://CN=bar,DC=domainB\";\ngroup.Invoke(\"Add\", new Object[] {memberADsPath});\n"
},
{
"answer_id": 394795,
"author": "Steve Evans",
"author_id": 46420,
"author_profile": "https://Stackoverflow.com/users/46420",
"pm_score": 0,
"selected": false,
"text": "DirectoryEntry group = new DirectoryEntry(\"LDAP://child.domain.com/cn=group,ou=sample,dc=child,dc=domain,dc=com\");\n\nstring userDN = \"cn=user,ou=sample,dc=domain,dc=com\";\n\ngroup.Properties[\"member\"].Add(userDN);\ngroup.CommitChanges();\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/315227",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26861/"
] |
315,231 | <p>How can I use reflection to create a generic List with a custom class (List<CustomClass>)? I need to be able to add values and use
<code>propertyInfo.SetValue(..., ..., ...)</code> to store it. Would I be better off storing these List<>'s as some other data structure?</p>
<p>Edit:</p>
<p>I should have specified that the object is more like this, but Marc Gravell's answer works still.</p>
<pre><code>class Foo
{
public List<string> Bar { get; set; }
}
</code></pre>
| [
{
"answer_id": 315265,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 5,
"selected": true,
"text": "class Foo\n{\n public string Bar { get; set; }\n}\nclass Program\n{\n static void Main()\n {\n Type type = typeof(Foo); // possibly from a string\n IList list = (IList) Activator.CreateInstance(\n typeof(List<>).MakeGenericType(type));\n\n object obj = Activator.CreateInstance(type);\n type.GetProperty(\"Bar\").SetValue(obj, \"abc\", null);\n list.Add(obj);\n }\n}\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/315231",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/37344/"
] |
315,237 | <p>I filled up a combobox with the values from an Enum.</p>
<p>Now a combobox is text right? So I'm using a getter and a setter. I'm having problems reading the text.</p>
<p>Here's the code:</p>
<pre><code>public BookType type
{
get
{
return (BookType)Enum.Parse(typeof(BookType), this.typeComboBox.Text);
}
set
{
this.typeComboBox.Text = value.ToString();
}
}
</code></pre>
<p>For some reason, <code>this.typeComboBox.Text</code> always returns an empty string when I select an item on the combobox.</p>
<p>Does someone see what I'm doing wrong?</p>
<p>EDIT: I have come to the conclusion that the problem lies in timing.
The point in time at which I summon the text is indeed after I changed the combobox, but still before that value is parsed as a value.
Problem fixed in a different way now, thanks for all the ideas.</p>
| [
{
"answer_id": 315292,
"author": "Howler",
"author_id": 2871,
"author_profile": "https://Stackoverflow.com/users/2871",
"pm_score": 1,
"selected": false,
"text": "this.typeComboBox.SelectedItem.ToString()\n"
},
{
"answer_id": 315293,
"author": "Dylan Beattie",
"author_id": 5017,
"author_profile": "https://Stackoverflow.com/users/5017",
"pm_score": 1,
"selected": false,
"text": "this.typeComboBox.SelectedText typeComboBox.Text"
},
{
"answer_id": 315296,
"author": "Rohan West",
"author_id": 38686,
"author_profile": "https://Stackoverflow.com/users/38686",
"pm_score": 1,
"selected": true,
"text": "public enum Test\n{\n One, Two, Three\n}\n\npublic partial class Form1 : Form\n{\n public Form1()\n {\n InitializeComponent();\n\n this.comboBox1.DataSource = Enum.GetNames(typeof(Test));\n }\n\n public Test Test\n {\n get \n {\n return (Test)Enum.Parse(typeof(Test), this.comboBox1.Text);\n }\n set\n {\n this.comboBox1.Text = value.ToString();\n }\n }\n\n private void button1_Click(object sender, EventArgs e)\n {\n MessageBox.Show(this.Test.ToString());\n\n this.Test = Test.Two;\n\n MessageBox.Show(this.Test.ToString());\n }\n}\n"
},
{
"answer_id": 315307,
"author": "Rune Grimstad",
"author_id": 30366,
"author_profile": "https://Stackoverflow.com/users/30366",
"pm_score": 2,
"selected": false,
"text": "DropDownStyle DropDownList Enum.GetValues(typeof(BookType)) typeComboBox.SelectedItem BookType"
},
{
"answer_id": 3414171,
"author": "Muhammedh",
"author_id": 57416,
"author_profile": "https://Stackoverflow.com/users/57416",
"pm_score": 5,
"selected": false,
"text": "string selectedText = this.ComboBox.GetItemText(this.ComboBox.SelectedItem);\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/315237",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11795/"
] |
315,242 | <p>I thought I'd get myself a Subversion setup at home for my hobby projects, and I'm trying to do it right, first time (my work's source control control policies or lack of them are, well, not perfect).</p>
<p>The thing I'm struggling with is this: I'd like to version entire Eclipse projects. This will be good from Eclipse's point of view - I'll just let it do its thing, and should just mean I need to ignore a few binaries / whole build directories and set up these ignores just once when I set up the project (right?). Anyway, I've tried it a couple of times and svn seems to get confused and ignore my ignore settings. What should be the correct procedure?</p>
<p>Thanks.</p>
<p>PS I'm doing the svn bits from command line, trying to avoid a GUI till I'm happy with it.</p>
| [
{
"answer_id": 315367,
"author": "rmeador",
"author_id": 10861,
"author_profile": "https://Stackoverflow.com/users/10861",
"pm_score": 1,
"selected": false,
"text": "svn add svn status"
},
{
"answer_id": 315375,
"author": "Carl Serrander",
"author_id": 40272,
"author_profile": "https://Stackoverflow.com/users/40272",
"pm_score": 2,
"selected": false,
"text": "svn propedit svn:ignore myDirectory\n bin\nobj\n*.bak\n"
},
{
"answer_id": 318827,
"author": "Devrin",
"author_id": 5269,
"author_profile": "https://Stackoverflow.com/users/5269",
"pm_score": 0,
"selected": false,
"text": "svn:ignore .foo ./bar ./bar/abc"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/315242",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
315,243 | <p>In our Flex AIR app, we have the problem that our main app window is fairly narrow. This means Alert dialog boxes are chopped on both side, while the right click menu is cropped. How can we get these windows to not get cropped by our main window?</p>
| [
{
"answer_id": 356667,
"author": "Eric Belair",
"author_id": 31298,
"author_profile": "https://Stackoverflow.com/users/31298",
"pm_score": 1,
"selected": false,
"text": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<mx:WindowedApplication xmlns:mx=\"http://www.adobe.com/2006/mxml\" \n creationComplete=\"creationCompleteHandler();\">\n <mx:Script>\n <![CDATA[\n import mx.controls.Alert;\n import mx.managers.PopUpManager;\n\n private function creationCompleteHandler():void\n {\n var alert:Alert = new Alert();\n\n alert.width = 100;\n\n alert.text = \"this Alert is\\n100px wide\";\n\n PopUpManager.addPopUp(alert, this);\n\n PopUpManager.centerPopUp(alert);\n\n Alert.show(\"this Alert uses the default width\");\n }\n ]]>\n </mx:Script>\n</mx:WindowedApplication>\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/315243",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7099/"
] |
315,261 | <p>I'm using the <code>QMdiArea</code> in Qt 4.4.</p>
<p>If a new project is created, I add a number of sub windows to a <code>QMdiArea</code>. I'd like to disallow the user to close a sub window during runtime. The sub windows should only be closed if the whole application is closed or if a new project is created.</p>
<p>How can I do this?</p>
| [
{
"answer_id": 4498486,
"author": "sorush-r",
"author_id": 275221,
"author_profile": "https://Stackoverflow.com/users/275221",
"pm_score": 3,
"selected": true,
"text": "subWindow QMdiSubWindow closeEvent(QCloseEvent *closeEvent) void ChildWindow::closeEvent(QCloseEvent *closeEvent)\n{\n if(/*condition C*/)\n closeEvent->accept();\n else\n closeEvent->ignore(); // you can do something else, like \n // writing a string in status bar ...\n}\n QMdiArea QMdiArea::closeAllSubWindows () class MainWindowArea : public QMdiArea\n{\n Q_OBJECT\npublic:\n explicit MainWindowArea(QWidget *parent = 0);\n\nsignals:\n void closeAllSubWindows();\npublic slots:\n\n};\n// Implementation:\nMainWindowArea::closeAllSubWindows()\n{\n // set close condition (new project is creating, C = true)\n foreach(QMdiSubWindow* sub,this->subWindowList())\n {\n (qobject_cast<ChildWindow*>(sub))->close();\n }\n} \n close"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/315261",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5334/"
] |
315,285 | <p>I'm using two commercial libraries that are produced by the same vendor, called VendorLibA and VendorLibB. The libraries are distributed as many DLLs that depend on the compiler version (e.g. VC7, VC8). Both libraries depend on a another library, produced by this vendor, called VendorLibUtils and contained in one DLL.</p>
<p>The problem: VendorLibA uses a different version of VendorLibUtils than VendorLibB. The two versions are not binary compatible, and even if they were it would be a bad idea to use the wrong version.</p>
<p>Is there any way I could use the two libraries under the same process?</p>
<p><strong>Note:</strong> LoadLibrary can't solve this since my process is not that one that's importing VendorLibUtils.</p>
<p><strong>EDIT:</strong> Forgot to mention the obvious, I don't have to source code for any of the commercial libraries and probably I will never have (<em>sigh</em>).</p>
<p><strong>EDIT:</strong> The alternative btw, is to do this: <a href="https://stackoverflow.com/questions/312569/how-to-combine-gui-applications-in-windows">How to combine GUI applications in Windows</a></p>
| [
{
"answer_id": 315374,
"author": "Andreas Magnusson",
"author_id": 5811,
"author_profile": "https://Stackoverflow.com/users/5811",
"pm_score": 2,
"selected": false,
"text": "LoadLibrary() GetProcAddress() HMODULE v1 = LoadLibrary(_T(\"libv1_0.dll\"));\nlibv1_0::fun_in_lib = reinterpret_cast<FUNTYPE>(GetProcAddress(v1, _T(\"fun_in_lib\"));\n HMODULE v2 = LoadLibrary(_T(\"libv2_0.dll\"));\nlibv2_0::fun_in_lib = reinterpret_cast<FUNTYPE>(GetProcAddress(v2, _T(\"fun_in_lib\"));\n"
},
{
"answer_id": 316136,
"author": "DarthPingu",
"author_id": 37199,
"author_profile": "https://Stackoverflow.com/users/37199",
"pm_score": 2,
"selected": false,
"text": "LoadLibrary GetProcAddress LoadLibrary"
},
{
"answer_id": 12935288,
"author": "cdiggins",
"author_id": 184528,
"author_profile": "https://Stackoverflow.com/users/184528",
"pm_score": 3,
"selected": false,
"text": "ImportError: DLL load failed: The specified procedure could not be found.\n from PyQt4 import QtGui\n QtGui4.dll QtGuiX.dll QtCore4.dll QtCoreX.dll QtGui.pyd QtGui4.dll QtGuiX.dll QtCore4.dll QtCoreX.dll QtCore.pyd QtGuiX.dll QtCoreX.dll"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/315285",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33982/"
] |
315,301 | <p>At the moment I'm creating a <code>DateTime</code> for each month and formatting it to only include the month.<br>
Is there another or any better way to do this?</p>
| [
{
"answer_id": 315319,
"author": "Rohan West",
"author_id": 38686,
"author_profile": "https://Stackoverflow.com/users/38686",
"pm_score": 4,
"selected": false,
"text": "System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.MonthNames\n"
},
{
"answer_id": 315321,
"author": "Yona",
"author_id": 40007,
"author_profile": "https://Stackoverflow.com/users/40007",
"pm_score": 8,
"selected": true,
"text": "DateTimeFormatInfo // Will return January\nstring name = DateTimeFormatInfo.CurrentInfo.GetMonthName(1);\n string[] names = DateTimeFormatInfo.CurrentInfo.MonthNames;\n DateTimeFormatInfo CultureInfo DateTimeFormatInfo.GetInstance CultureInfo.DateTimeFormat var dateFormatInfo = CultureInfo.GetCultureInfo(\"en-GB\").DateTimeFormat;\n"
},
{
"answer_id": 315322,
"author": "Greg",
"author_id": 12601,
"author_profile": "https://Stackoverflow.com/users/12601",
"pm_score": 3,
"selected": false,
"text": "Thread.CurrentThread.CurrentCulture.DateTimeFormat.MonthNames DateTimeFormatInfo.InvariantInfo.MonthNames string[] localizedMonths = Thread.CurrentThread.CurrentCulture.DateTimeFormat.MonthNames;\nstring[] invariantMonths = DateTimeFormatInfo.InvariantInfo.MonthNames;\n\nfor( int month = 0; month < 12; month++ )\n{\n ListItem monthListItem = new ListItem( localizedMonths[month], invariantMonths[month] );\n monthsDropDown.Items.Add( monthListItem );\n}\n"
},
{
"answer_id": 315323,
"author": "Zachary Yates",
"author_id": 8360,
"author_profile": "https://Stackoverflow.com/users/8360",
"pm_score": 3,
"selected": false,
"text": "for( int i = 1; i <= 12; i++ ){\n combo.Items.Add(CultureInfo.CurrentCulture.DateTimeFormat.MonthNames[i]);\n}\n"
},
{
"answer_id": 315338,
"author": "Dylan Beattie",
"author_id": 5017,
"author_profile": "https://Stackoverflow.com/users/5017",
"pm_score": 4,
"selected": false,
"text": "using System.Globalization;\n\nfor (int i = 0; i < 12; i++) {\n Console.WriteLine(CultureInfo.CurrentUICulture.DateTimeFormat.MonthNames[i]);\n}\n"
},
{
"answer_id": 14717491,
"author": "Jeevan Moses",
"author_id": 2044794,
"author_profile": "https://Stackoverflow.com/users/2044794",
"pm_score": 0,
"selected": false,
"text": "List<string> mnt = new List<string>(); \nint monthCount = Convert.ToInt32(cbYear.Text) == DateTime.Now.Year ? DateTime.Now.Month : 12; \n for (int i = 0; i < monthCount; i++) \n { \n mnt.Add(CultureInfo.CurrentUICulture.DateTimeFormat.MonthNames[i]); \n } \n cbMonth.DataSource = mnt;\n"
},
{
"answer_id": 17053179,
"author": "mmmeff",
"author_id": 549503,
"author_profile": "https://Stackoverflow.com/users/549503",
"pm_score": 5,
"selected": false,
"text": "int var months = Enumerable.Range(1, 12).Select(i => new { I = i, M = DateTimeFormatInfo.CurrentInfo.GetMonthName(i) });\n // <asp:DropDownList runat=\"server\" ID=\"ddlMonths\" />\nddlMonths.DataSource = months;\nddlMonths.DataTextField = \"M\";\nddlMonths.DataValueField = \"I\";\nddlMonths.DataBind();\n"
},
{
"answer_id": 18089538,
"author": "WebDev07",
"author_id": 1840063,
"author_profile": "https://Stackoverflow.com/users/1840063",
"pm_score": 3,
"selected": false,
"text": "public IEnumerable<SelectListItem> Months\n{\n get\n {\n return Enumerable.Range(1, 12).Select(x => new SelectListItem\n {\n Value = x.ToString(),\n Text = DateTimeFormatInfo.CurrentInfo.GetMonthName(x)\n });\n }\n}\n"
},
{
"answer_id": 23222667,
"author": "Maher Ben Issa",
"author_id": 1709751,
"author_profile": "https://Stackoverflow.com/users/1709751",
"pm_score": 2,
"selected": false,
"text": "ComboBoxName.ItemsSource= \nSystem.Globalization.CultureInfo.\nCurrentCulture.DateTimeFormat.MonthNames.\nTakeWhile(m => m != String.Empty).ToList();\n var months = CultureInfo.CurrentCulture.DateTimeFormat.MonthNames\n .TakeWhile(m => m != String.Empty)\n .Select((m,i) => new \n { \n Month = i+1, \n MonthName = m\n }) \n .ToList();\n"
},
{
"answer_id": 24009014,
"author": "George Filippakos",
"author_id": 961333,
"author_profile": "https://Stackoverflow.com/users/961333",
"pm_score": 0,
"selected": false,
"text": " Dim currentCulture As CultureInfo = CultureInfo.CurrentUICulture\n Dim monthName, monthNumber As String\n\n For x As Integer = 0 To 11\n monthNumber = (x + 1).ToString(\"D2\")\n monthName = currentCulture.DateTimeFormat.MonthNames(x)\n Dim month As New ListItem(String.Format(\"{0} - {1}\", monthNumber, monthName),\n x.ToString(\"D2\"))\n ddl_expirymonth.Items.Add(month)\n Next\n 01 - January\n02 - February\netc.\n"
},
{
"answer_id": 28307675,
"author": "DivineOps",
"author_id": 1443022,
"author_profile": "https://Stackoverflow.com/users/1443022",
"pm_score": 2,
"selected": false,
"text": "var monthOptions = DateTimeFormatInfo.CurrentInfo.MonthNames\n .Where(p=>!string.IsNullOrEmpty(p))\n .Select((item, index) => new { Id = index + 1, Name = item });\n"
},
{
"answer_id": 52912313,
"author": "Yogi",
"author_id": 943435,
"author_profile": "https://Stackoverflow.com/users/943435",
"pm_score": 0,
"selected": false,
"text": "model.Controls = new\n{\n FiscalMonths = new\n {\n Value = DateTime.Now.Month,\n Options = (new List<int> { 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9 }).Select(p => new\n {\n Value = p,\n Text = DateTimeFormatInfo.CurrentInfo.GetMonthName(p)\n })\n }\n};\n \"FiscalMonths\": {\n \"Value\": 10,\n \"Options\": [\n {\n \"Value\": 10,\n \"Text\": \"October\"\n },\n {\n \"Value\": 11,\n \"Text\": \"November\"\n },\n {\n \"Value\": 12,\n \"Text\": \"December\"\n },\n {\n \"Value\": 1,\n \"Text\": \"January\"\n },\n {\n \"Value\": 2,\n \"Text\": \"February\"\n },\n etc ....\n"
},
{
"answer_id": 54658629,
"author": "SeanH",
"author_id": 1483738,
"author_profile": "https://Stackoverflow.com/users/1483738",
"pm_score": 2,
"selected": false,
"text": "Dictionary<int, string> Months = Enumerable.Range(1, 12).Select(i => new KeyValuePair<int, string>(i, System.Globalization.DateTimeFormatInfo.CurrentInfo.GetMonthName(i))).ToDictionary(x => x.Key, x => x.Value);\n Key Value\n1 January\n2 February\n3 March\n4 April\n5 May\n6 June\n7 July\n8 August\n9 September\n10 October\n11 November\n12 December\n"
},
{
"answer_id": 56632473,
"author": "Tiago Ávila",
"author_id": 4056487,
"author_profile": "https://Stackoverflow.com/users/4056487",
"pm_score": 1,
"selected": false,
"text": "var months = Enumerable.Range(1, 12).Select(i => \n new\n {\n Index = i,\n MonthName = new CultureInfo(\"en-US\").DateTimeFormat.GetAbbreviatedMonthName(i)\n })\n .ToDictionary(x => x.Index, x => x.MonthName);\n"
},
{
"answer_id": 59866483,
"author": "CaptainTurk",
"author_id": 5199957,
"author_profile": "https://Stackoverflow.com/users/5199957",
"pm_score": 0,
"selected": false,
"text": "var Months = new SelectList((DateTimeFormatInfo.CurrentInfo.MonthNames).Take(12));\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/315301",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8741/"
] |
315,306 | <p>I can't, for the life of me, remember what exactly our teacher said that day and I'm hoping you would probably know.</p>
<p>The module is "Data Structures and Algorithms" and he told us something along the lines of:</p>
<blockquote>
<p>The <code>if</code> statement is the most expensive
[something]. [something] registers
[something].</p>
</blockquote>
<p>Yes, I do have a horrible memory and I'm really really sorry, but I've been googling for hours and nothing has come up. Any ideas?</p>
| [
{
"answer_id": 315327,
"author": "Joel Coehoorn",
"author_id": 3043,
"author_profile": "https://Stackoverflow.com/users/3043",
"pm_score": 5,
"selected": false,
"text": "if if"
},
{
"answer_id": 315337,
"author": "Michael Burr",
"author_id": 12711,
"author_profile": "https://Stackoverflow.com/users/12711",
"pm_score": 2,
"selected": false,
"text": "if"
},
{
"answer_id": 315346,
"author": "Marcin",
"author_id": 3105,
"author_profile": "https://Stackoverflow.com/users/3105",
"pm_score": 3,
"selected": false,
"text": "if if"
},
{
"answer_id": 315372,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 3,
"selected": false,
"text": "if if if if branch misprediction noop if switch && ||"
},
{
"answer_id": 315382,
"author": "Adam Rosenfield",
"author_id": 9530,
"author_profile": "https://Stackoverflow.com/users/9530",
"pm_score": 9,
"selected": true,
"text": "if for while break continue goto if switch abs() min() max()"
},
{
"answer_id": 70837866,
"author": "E L",
"author_id": 13365362,
"author_profile": "https://Stackoverflow.com/users/13365362",
"pm_score": 0,
"selected": false,
"text": "If else: if should be more likely and if there is a return that should be in else.\n\nFor and While should be replace by: do while -> except if there is a continue.\n\nThat continue should then become an: if do while -> in that order.\n\nIf it absolutely necessary to test at beginning use: if do while\n\nIf there is less than 5 cases switch to if else from most likely to least likely\n\nCases should be of relative likelihood, otherwise should be expressed as if else before switch.\n\nBitwise operators and better logical operators\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/315306",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2644/"
] |
315,331 | <p>I have a database that i'm dealing with which is updated every few hours remotely (not on any specific time span) and i have no control over the administration of it. I have web clients connecting to it to view information contained within it. These clients (coded using PHP and Javascript) might be checking the database very often (impatient users) even though there may not be any change to the database itself and the check will involve quite a lengthy query involving lots of lookups and cross referencing, etc.</p>
<p>So in order to cut down on database queries and to keep things snappy what would be the best way to limit the number of times the clients will actually run the whole query on the database?</p>
<p>To make things crystal clear, i have no way of altering the database, i can only query it. But i have full control over the source of the web client.</p>
| [
{
"answer_id": 321729,
"author": "Dieseltime",
"author_id": 41108,
"author_profile": "https://Stackoverflow.com/users/41108",
"pm_score": 2,
"selected": false,
"text": "$query = \"SELECT * FROM really_big_table\";\n$cache_query = md5($query);\nif(!$result = $cache->load($cache_query))\n{\n $result = $db->fetchAll($query);\n $cache->save($result, $cache_query);\n}\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/315331",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13227/"
] |
315,336 | <p>sorry about the title :)</p>
<p>Here is my basic problem, I trying to implement an SEO type query for a location.</p>
<p>Here are my examples</p>
<ul>
<li>/Leeds</li>
<li>/Leeds_England</li>
<li>/Hampshire_England</li>
<li>/England_Leeds</li>
<li>/Europe_England</li>
</ul>
<p>I am trying to get the location, now I am splitting on the '_', then doing a LINQ lookup through my List's for each part.
Location has</p>
<p>City
Province
Region
Country
Continent</p>
<p>If I find one with a greater count, I set a variable as "cityFound" and append the results to a range of locations. </p>
<p>I then check again using LINQ on these results on the split to see what I've got, to try and work out if each split part is in the same location.</p>
<p>Now I feel I am doing it wrong, but I can't figure out the way to do it "nicely". I think I could create a recursive method, or I'm looking at it totally wrong.</p>
<p>How would you guys tackle this problem? Pseudo code is fine, it's the logic I'm getting stumped on!</p>
<p>Cheers, Sarkie.</p>
| [
{
"answer_id": 332881,
"author": "Frank Krueger",
"author_id": 338,
"author_profile": "https://Stackoverflow.com/users/338",
"pm_score": 0,
"selected": false,
"text": "class LocationResolver {\n private IEnumerable<Location> locations;\n private Map<String, Location> memory = new Map<String, Location>();\n\n public LocationResolver(IEnumerable<Location> locs) {\n locations = locs;\n //\n // Add any locations that need disambiguation\n //\n memory[\"/Las Vegas\"] = FromUrl(\"/Las Vegas_Nevada\");\n memory[\"/Phoenix\"] = FromUrl(\"/Phoenix_Arizona\");\n }\n\n public Location Resolve(string url) {\n Location result;\n if (memory.TryGet(url, out result)) {\n result = FindWithParts(url.Substring(1).Split('_'));\n memory[url] = result;\n }\n return result;\n }\n\n private Location FindWithParts(string[] parts) {\n string[] locParts = new string[5];\n for (Location l in locations) {\n locParts[0] = l.City;\n locParts[1] = l.Province;\n locParts[2] = l.Region;\n locParts[3] = l.Country;\n locParts[4] = l.Continent;\n bool found = true;\n for (int i = 0; i < parts.Length && found; i++)\n found = Array.IndexOf(locParts, parts[i]) >= 0;\n }\n if (found) {\n return l;\n }\n }\n return null;\n }\n}\n"
}
] | 2008/11/24 | [
"https://Stackoverflow.com/questions/315336",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25531/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.