qid int64 4 19.1M | question stringlengths 18 48.3k | answers list | date stringlengths 10 10 | metadata list |
|---|---|---|---|---|
340,943 | <p>How would I go about dynamically allocating a multi-dimensional array?</p>
| [
{
"answer_id": 340970,
"author": "eplawless",
"author_id": 1370,
"author_profile": "https://Stackoverflow.com/users/1370",
"pm_score": 2,
"selected": false,
"text": "int int width = 10, height = 10, totalSize = width*height;\nint **myArray = new int*[width];\nint *data = new int[totalSize];\n\nfor ( int i = 0; i < height; ++i )\n{\n myArray[i] = data + (i*width);\n}\n\n// do some things here\n\ndelete[] data;\ndelete[] myArray;\n"
},
{
"answer_id": 340990,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 6,
"selected": true,
"text": "typedef int dimensions[3][4];\n\ndimensions * dim = new dimensions[10];\ndim[/* from 0 to 9 */][/* from 0 to 2 */][/* from 0 to 3 */] = 42;\ndelete [] dim;\n 10"
},
{
"answer_id": 341008,
"author": "e.James",
"author_id": 33686,
"author_profile": "https://Stackoverflow.com/users/33686",
"pm_score": 2,
"selected": false,
"text": "myArray int width = 10;\nint height = 10;\nint ** myArray = new int*[width];\nint * data = new int[width*height];\nint * index = data;\nfor (int i = 0; i < width; i++)\n{\n myArray[i] = index;\n index += height;\n}\n\n// ...\n\ndelete[] data;\ndelete[] myArray;"
},
{
"answer_id": 341081,
"author": "MSalters",
"author_id": 15416,
"author_profile": "https://Stackoverflow.com/users/15416",
"pm_score": 2,
"selected": false,
"text": "std::vector<std::vector<int> > std::vector<int>"
},
{
"answer_id": 341193,
"author": "e.James",
"author_id": 33686,
"author_profile": "https://Stackoverflow.com/users/33686",
"pm_score": 3,
"selected": false,
"text": "template<typename T, int width, int height>\nclass MultiArray\n{\n private:\n typedef T cols[height];\n cols * data;\n public:\n T& operator() (int x, int y) { return data[x][y]; }\n MultiArray() { data = new cols[width]; }\n ~MultiArray() { delete [] data; }\n}; MultiArray<int, 10, 10> myArray;\nmyArray(2, 3) = 4;\ncout << myArray(2, 3); template<typename T>\nclass Array2D\n{\n private:\n const int width;\n T * data;\n public:\n T& operator() (int x, int y) { return data[y*width + x]; }\n Array2D(const int w, const int h) : width(w) { data = new T[w*h]; }\n ~Array2D() { delete [] data; }\n}; Array2D myArray(10, 10);\nmyArray(3, 4) = 42;\ncout << myArray(3, 4);"
},
{
"answer_id": 341404,
"author": "Rich",
"author_id": 42897,
"author_profile": "https://Stackoverflow.com/users/42897",
"pm_score": 0,
"selected": false,
"text": "int *matrix = new int[n*m];\n\n//set element (3,7) to 10\nmatrix[3*m+7] = 10;\n\n//print the matrix\nfor (int i = 0; i < n; i++) {\n for (int j = 0; j < m; j++) {\n cout << matrix[i*m+j] << ' ';\n }\n cout << '\\n';\n}\n"
},
{
"answer_id": 341528,
"author": "Head Geek",
"author_id": 12193,
"author_profile": "https://Stackoverflow.com/users/12193",
"pm_score": 2,
"selected": false,
"text": "boost::multi_array"
},
{
"answer_id": 345668,
"author": "Benoît",
"author_id": 31640,
"author_profile": "https://Stackoverflow.com/users/31640",
"pm_score": 3,
"selected": false,
"text": " #include < boost/multi_array.hpp >\n\n #include < cassert >\n\nint main () \n\n{\n\n // Create a 3D array that is 3 x 4 x 2\n\n typedef boost::multi_array< double, 3 > array_type;\n\n typedef array_type::index index;\n\n array_type A(boost::extents[3][4][2]);\n\n\n // Assign values to the elements\n\n int values = 0;\n\n for(index i = 0; i != 3; ++i) \n\n for(index j = 0; j != 4; ++j)\n\n for(index k = 0; k != 2; ++k)\n\n A[i][j][k] = values++;\n\n // Verify values\n\n int verify = 0;\n\n for(index i = 0; i != 3; ++i) \n\n for(index j = 0; j != 4; ++j)\n\n for(index k = 0; k != 2; ++k)\n\n assert(A[i][j][k] == verify++);\n\n return 0;\n\n}\n"
},
{
"answer_id": 15226405,
"author": "v.chaplin",
"author_id": 2116670,
"author_profile": "https://Stackoverflow.com/users/2116670",
"pm_score": 0,
"selected": false,
"text": "template <class T> T ***Create3D(int N1, int N2, int N3)\n{\n T *** array = new T ** [N1];\n\n array[0] = new T * [N1*N2];\n\n array[0][0] = new T [N1*N2*N3];\n\n int i,j,k;\n\n for( i = 0; i < N1; i++) {\n\n if (i < N1 -1 ) {\n\n array[0][(i+1)*N2] = &(array[0][0][(i+1)*N3*N2]);\n\n array[i+1] = &(array[0][(i+1)*N2]);\n\n }\n\n for( j = 0; j < N2; j++) { \n if (j > 0) array[i][j] = array[i][j-1] + N3;\n }\n\n }\n\n cout << endl;\n return array;\n};\n\ntemplate <class T> void Delete3D(T ***array) {\n delete[] array[0][0]; \n delete[] array[0];\n delete[] array;\n};\n int *** array3d;\nint N1=4, N2=3, N3=2;\n\nint elementNumber = 0;\n\narray3d = Create3D<int>(N1,N2,N3);\n\n//equivalently, a 'flat' array could be obtained with\n//int * array = array3d[0][0];\n\ncout << \"{\" << endl;\nfor (i=0; i<N1; i++) {\n cout << \"{\";\n for (j=0; j<N2; j++) {\n cout << \"{\";\n for (k=0; k<N3; k++) {\n array3d[i][j][k] = elementNumber++;\n cout << setw(4) << array3d[i][j][k] << \" \";\n\n //or if you're using the flat array:\n //array[i*N2*N3 + j*N3 + k] = elementNumber++;\n\n }\n cout << \"}\";\n }\n cout << \"}\";\n cout << endl ;\n}\ncout << \"}\" << endl;\n\nDelete3D(array3d);\n {\n{{ 0 1 }{ 2 3 }{ 4 5 }}\n{{ 6 7 }{ 8 9 }{ 10 11 }}\n{{ 12 13 }{ 14 15 }{ 16 17 }}\n{{ 18 19 }{ 20 21 }{ 22 23 }}\n}\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/340943",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1370/"
] |
340,959 | <p>I am using ubuntu 8.04 and windows xp. I mount the fat32 disk which contains eclipse workspace to ubuntu. but I find I could not use the workspace, maybe I have no right to use it.</p>
<p>the fat32 disk I mounted has the 755 right,I try to use chmod to change it to 777 but failed. I try to mount it to 777 mode, but I find there is nothing about mode in vfat option.</p>
<p>How should I do next ? how could I share the workspace? Help me. thanks. </p>
| [
{
"answer_id": 341763,
"author": "jamesh",
"author_id": 4737,
"author_profile": "https://Stackoverflow.com/users/4737",
"pm_score": 1,
"selected": false,
"text": "rw /etc/mtab plugins features config.ini eclipse.ini -install -configuration rsync"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/340959",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41940/"
] |
340,972 | <p>Py3k <a href="http://mail.python.org/pipermail/python-list/2008-December/518408.html" rel="nofollow noreferrer">just came out</a> and has gobs of <a href="http://docs.python.org/3.0/whatsnew/3.0.html" rel="nofollow noreferrer">neat new stuff</a>! I'm curious, what are SO pythonistas most excited about? What features are going to affect the way you write code on a daily basis, or have you been looking forward to?</p>
| [
{
"answer_id": 342448,
"author": "S.Lott",
"author_id": 10661,
"author_profile": "https://Stackoverflow.com/users/10661",
"pm_score": 2,
"selected": false,
"text": "<sniff> print logging.debug print"
},
{
"answer_id": 348832,
"author": "shsmurfy",
"author_id": 2188962,
"author_profile": "https://Stackoverflow.com/users/2188962",
"pm_score": 2,
"selected": false,
"text": "{k: v for k, v in list} dict(list)"
},
{
"answer_id": 349027,
"author": "dbr",
"author_id": 745,
"author_profile": "https://Stackoverflow.com/users/745",
"pm_score": 2,
"selected": false,
"text": "unicode() u\"\" urllib urllib2 httplib except TypeError, something: TypeError something TypeError"
},
{
"answer_id": 349101,
"author": "Rafał Dowgird",
"author_id": 12166,
"author_profile": "https://Stackoverflow.com/users/12166",
"pm_score": 3,
"selected": false,
"text": "try:\n doSomething( someObject)\nexcept:\n someCleanup()\n\n # Thanks for passing the error-causing object,\n # but the original stack trace is lost :-(\n\n raise MyError(\"Bad, bad object!\", someObject)\n raise MyError(\"Bad, bad object!\", someObject) from original_exception\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/340972",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41457/"
] |
340,981 | <p>Is it possible to just send a JPanel or any other component to the printer? Or do I have to implement all the drawing to the graphics object by hand?</p>
<p>I have tried to use the Print* functions of the JPanel to print to the graphics object but the page that gets printed is blank.</p>
| [
{
"answer_id": 341070,
"author": "Michael Myers",
"author_id": 13531,
"author_profile": "https://Stackoverflow.com/users/13531",
"pm_score": 1,
"selected": false,
"text": "Graphics"
},
{
"answer_id": 342821,
"author": "Lawrence Dol",
"author_id": 8946,
"author_profile": "https://Stackoverflow.com/users/8946",
"pm_score": 3,
"selected": true,
"text": "import java.awt.*;\nimport java.awt.print.*;\nimport javax.swing.*;\n\n/**\n * Generic component printer. This object allows any AWT or Swing component (or DCT system)\n * to be printed by performing it pre and post print responsibilities.\n * <p>\n * When printing components, the role of the print method is nothing more than to scale the Graphics, turn off double\n * buffering, and call paint. There is no particular reason to put that print method in the component being printed. A\n * better approach is to build a generic printComponent method to which you simply pass the component you want printed.\n * <p>\n * With Swing, almost all components have double buffering turned on by default. In general, this is a great benefit,\n * making for convenient and efficient painting. However, in the specific case of printing, it can is a huge problem.\n * First, since printing components relies on scaling the coordinate system and then simply calling the component's\n * paint method, if double buffering is enabled printing amounts to little more than scaling up the buffer (off-screen\n * image) which results in ugly low-resolution printing like you already had available. Secondly, sending these huge\n * buffers to the printer results in huge print spooler files which take a very long time to print. Consequently this\n * object globally turns off double buffering before printing and turns it back on afterwards.\n * <p>\n * Threading Design : [x] Single Threaded [ ] Threadsafe [ ] Immutable [ ] Isolated\n */\n\npublic class ComponentPrinter\nextends Object\nimplements Printable\n{\n\n// *****************************************************************************\n// INSTANCE PROPERTIES\n// *****************************************************************************\n\nprivate Component component; // the component to print\n\n// *****************************************************************************\n// INSTANCE CREATE/DELETE\n// *****************************************************************************\n\npublic ComponentPrinter(Component com) {\n component=com;\n }\n\n// *****************************************************************************\n// INSTANCE METHODS\n// *****************************************************************************\n\npublic void print() throws PrinterException {\n PrinterJob printJob=PrinterJob.getPrinterJob();\n\n printJob.setPrintable(this);\n if(printJob.printDialog()) {\n printJob.print();\n }\n }\n\npublic int print(Graphics gc, PageFormat pageFormat, int pageIndex) {\n if(pageIndex>0) {\n return NO_SUCH_PAGE;\n }\n\n RepaintManager mgr=RepaintManager.currentManager(component);\n Graphics2D g2d=(Graphics2D)gc;\n\n g2d.translate(pageFormat.getImageableX(),pageFormat.getImageableY());\n mgr.setDoubleBufferingEnabled(false); // only for swing components\n component.paint(g2d);\n mgr.setDoubleBufferingEnabled(true); // only for swing components\n return PAGE_EXISTS;\n }\n\n// *****************************************************************************\n// STATIC METHODS\n// *****************************************************************************\n\nstatic public void printComponent(Component com) throws PrinterException {\n new ComponentPrinter(com).print();\n }\n\n} // END PUBLIC CLASS\n"
},
{
"answer_id": 49378625,
"author": "ArchLinuxTux",
"author_id": 1273555,
"author_profile": "https://Stackoverflow.com/users/1273555",
"pm_score": 0,
"selected": false,
"text": "Component import java.awt.Component;\nimport java.awt.Dimension;\nimport java.awt.Graphics;\nimport java.awt.Graphics2D;\nimport java.awt.print.*;\n\nimport javax.swing.RepaintManager;\n\npublic class PrintMultiPageUtil implements Printable, Pageable {\n private Component componentToBePrinted;\n private PageFormat format;\n private int numPages;\n\n public PrintMultiPageUtil(Component componentToBePrinted) {\n this.componentToBePrinted = componentToBePrinted;\n\n // get total space from component \n Dimension totalSpace = this.componentToBePrinted.getPreferredSize();\n\n // calculate for DIN A4\n format = PrinterJob.getPrinterJob().defaultPage();\n numPages = (int) Math.ceil(totalSpace .height/format.getImageableHeight());\n }\n\n public void print() {\n PrinterJob printJob = PrinterJob.getPrinterJob();\n\n // show page-dialog with default DIN A4\n format = printJob.pageDialog(printJob.defaultPage());\n\n printJob.setPrintable(this);\n printJob.setPageable(this);\n\n if (printJob.printDialog())\n try {\n printJob.print();\n } catch(PrinterException pe) {\n System.out.println(\"Error printing: \" + pe);\n }\n }\n\n public int print(Graphics g, PageFormat pageFormat, int pageIndex) {\n if ((pageIndex < 0) | (pageIndex >= numPages)) {\n return(NO_SUCH_PAGE);\n } else {\n Graphics2D g2d = (Graphics2D)g;\n g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY() - pageIndex * pageFormat.getImageableHeight());\n disableDoubleBuffering(componentToBePrinted);\n componentToBePrinted.paint(g2d);\n enableDoubleBuffering(componentToBePrinted);\n return(PAGE_EXISTS);\n }\n }\n\n public static void disableDoubleBuffering(Component c) {\n RepaintManager currentManager = RepaintManager.currentManager(c);\n currentManager.setDoubleBufferingEnabled(false);\n }\n\n public static void enableDoubleBuffering(Component c) {\n RepaintManager currentManager = RepaintManager.currentManager(c);\n currentManager.setDoubleBufferingEnabled(true);\n }\n\n @Override\n public int getNumberOfPages() {\n // TODO Auto-generated method stub\n return numPages;\n }\n\n @Override\n public PageFormat getPageFormat(int arg0) throws IndexOutOfBoundsException {\n return format;\n }\n\n @Override\n public Printable getPrintable(int arg0) throws IndexOutOfBoundsException {\n // TODO Auto-generated method stub\n return this;\n }\n}\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/340981",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34145/"
] |
340,983 | <p>Is there a better, more jQuery-ish way of handling this image substitution?</p>
<pre><code>var image = $(obj).children("img");
if ($(image).attr("src") == "Images/TreeCollapse.gif")
$(image).attr("src", "Images/TreeExpand.gif");
else
$(image).attr("src", "Images/TreeCollapse.gif");
</code></pre>
| [
{
"answer_id": 341052,
"author": "BigJump",
"author_id": 8542,
"author_profile": "https://Stackoverflow.com/users/8542",
"pm_score": 2,
"selected": false,
"text": "var image = $(obj).children(\"img\");\n$(image).toggle(\n function () { $(image).attr(\"src\", \"Images/TreeExpand.gif\");},\n function () { $(image).attr(\"src\", \"Images/TreeCollapse.gif\");}\n);\n"
},
{
"answer_id": 341071,
"author": "redsquare",
"author_id": 6440,
"author_profile": "https://Stackoverflow.com/users/6440",
"pm_score": 1,
"selected": false,
"text": "$(function()\n {\n $(obj)\n .children(\"img\")\n .attr('src', swapImage ); \n });\n\nfunction swapImage(){\n return ( \n $(this).attr('src') == \"Images/TreeCollapse.gif\" ?\n \"Images/TreeExpand.gif\" :\n \"Images/TreeCollapse.gif\");\n}\n"
},
{
"answer_id": 341078,
"author": "duckyflip",
"author_id": 7370,
"author_profile": "https://Stackoverflow.com/users/7370",
"pm_score": 1,
"selected": false,
"text": "var $image = $(obj).children(\"img\");\nif ($image.attr(\"src\") == \"Images/TreeCollapse.gif\")\n $image.attr(\"src\", \"Images/TreeExpand.gif\");\nelse\n $image.attr(\"src\", \"Images/TreeCollapse.gif\");\n"
},
{
"answer_id": 341088,
"author": "Cirieno",
"author_id": 17615,
"author_profile": "https://Stackoverflow.com/users/17615",
"pm_score": 0,
"selected": false,
"text": "image.setAttribute(\"src\", \"Images/Tree\" + ((image.getAttribute(\"src\").indexOf(\"Collapse\")>0) ? \"Expand\" : \"Collapse\") + \".gif\");\n"
},
{
"answer_id": 341095,
"author": "Josh Delsman",
"author_id": 40644,
"author_profile": "https://Stackoverflow.com/users/40644",
"pm_score": 6,
"selected": true,
"text": "$(obj).children(\"img\").toggle(\n function(){ $(this).attr(\"src\", \"Images/TreeExpand.gif\"); },\n function(){ $(this).attr(\"src\", \"Images/TreeCollapse.gif\"); }\n);\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/340983",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/343/"
] |
340,984 | <p>Here is a simple overview of my directory layout for my views:</p>
<p>Project</p>
<ul>
<li>Page 1</li>
<li>Page 2</li>
<li>RSS</li>
</ul>
<p>Issues</p>
<ul>
<li>Page 1</li>
<li>Page 2</li>
<li>RSS</li>
</ul>
<p>I am using forms authentication to deny access to all unauthenticated users, that works fine. However, I want to be able to grant access to the RSS views to everyone (so they can subscribe via google reader and stuff)</p>
<p>I understand that you can grant access to pages by adding the following page to your web.config</p>
<pre><code> <location path="TOURPAGE.aspx">
<system.web>
<authorization>
<allow users="*" />
<allow users="?" />
</authorization>
</system.web>
</code></pre>
<p></p>
<p>However, how would I do this with my dynamically made URL's, such as:</p>
<pre><code>Issues/RSS/chrisj
</code></pre>
<ul>
<li>That path maps to a controller in issues called RSS, which takes a username and spits out an RSS of thier issues...</li>
</ul>
<p><strong>EDIT</strong></p>
<p>Some answers I thought had fixed it, but:</p>
<p>It seems that, in my case at least, you still need the authentication cookie in order to see the page. You can be logged out and view it, so long as you have the cookie.</p>
<p>That is no good to me, I need the page to be completely public, as it is an RSS feed.</p>
| [
{
"answer_id": 341023,
"author": "Chris James",
"author_id": 3193,
"author_profile": "https://Stackoverflow.com/users/3193",
"pm_score": 2,
"selected": false,
"text": " <location path=\"Issues/RSS\">\n<system.web>\n <authorization>\n <allow users=\"*\" />\n <allow users=\"?\" />\n </authorization>\n</system.web>\n"
},
{
"answer_id": 341028,
"author": "Timothy Khouri",
"author_id": 11917,
"author_profile": "https://Stackoverflow.com/users/11917",
"pm_score": 1,
"selected": false,
"text": "<location path=\"/Issues/RSS/\">\n<system.web>\n<authorization>\n<allow users=\"*\" />\n</authorization>\n</system.web>\n</location>\n"
},
{
"answer_id": 633426,
"author": "Bryan",
"author_id": 72162,
"author_profile": "https://Stackoverflow.com/users/72162",
"pm_score": 0,
"selected": false,
"text": "HttpContext.Current.User.Identity.IsAuthenticated"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/340984",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3193/"
] |
340,998 | <p>I need to update a group of cells by inserting the same two characters into all of them, but I'm just drawing a blank on how to do this. Could someone point me in the right direction?</p>
<p><b>Old Cells</b><br>
HI.1 <br>
HI.2<br>
HII.1</p>
<p><b>New Cells</b><br>
H08I.1<br>
H08I.2<br>
H08II.1</p>
| [
{
"answer_id": 341013,
"author": "Tony Andrews",
"author_id": 18747,
"author_profile": "https://Stackoverflow.com/users/18747",
"pm_score": 2,
"selected": false,
"text": "update cells\nset cell = Replace(cell,'H','H08');\n"
},
{
"answer_id": 341016,
"author": "Michael Haren",
"author_id": 29,
"author_profile": "https://Stackoverflow.com/users/29",
"pm_score": 4,
"selected": true,
"text": "UPDATE Cells SET Cell = LEFT(Cell, 1) + '08' + SUBSTRING(Cell, 1, LEN(Cell)-1)\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/340998",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21717/"
] |
341,005 | <p>Suppose you're maintaining an API that was originally released years ago (before java gained <code>enum</code> support) and it defines a class with enumeration values as ints:</p>
<pre><code>public class VitaminType {
public static final int RETINOL = 0;
public static final int THIAMIN = 1;
public static final int RIBOFLAVIN = 2;
}
</code></pre>
<p>Over the years the API has evolved and gained Java 5-specific features (generified interfaces, etc). Now you're about to add a new enumeration:</p>
<pre><code>public enum NutrientType {
AMINO_ACID, SATURATED_FAT, UNSATURATED_FAT, CARBOHYDRATE;
}
</code></pre>
<p>The 'old style' int-enum pattern has no type safety, no possibility of adding behaviour or data, etc, <em>but it's published and in use</em>. I'm concerned that mixing two styles of enumeration is inconsistent for users of the API.</p>
<p>I see three possible approaches:</p>
<ul>
<li><p>Give up and define the new enum (<code>NutrientType</code> in my fictitious example) as a series of ints like the <code>VitaminType</code> class. You get consistency but you're not taking advantage of type safety and other modern features.</p></li>
<li><p>Decide to live with an inconsistency in a published API: keep <code>VitaminType</code> around as is, and add <code>NutrientType</code> as an <code>enum</code>. Methods that take a <code>VitaminType</code> are still declared as taking an int, methods that take a <code>NutrientType</code> are declared as taking such.</p></li>
<li><p>Deprecate the <code>VitaminType</code> class and introduce a new <code>VitaminType2</code> enum. Define the new <code>NutrientType</code> as an enum. <br/> Congratulations, for the next 2-3 years until you can kill the deprecated type, you're going to deal with deprecated versions of every single method that took a <code>VitaminType</code> as an int and adding a new <code>foo(VitaminType2 v)</code> version of each. You also need to write tests for each deprecated <code>foo(int v)</code> method as well as its corresponding <code>foo(VitaminType2 v)</code> method, so you just multiplied your QA effort.</p></li>
</ul>
<p>What is the best approach?</p>
| [
{
"answer_id": 341066,
"author": "Steve B.",
"author_id": 19479,
"author_profile": "https://Stackoverflow.com/users/19479",
"pm_score": 3,
"selected": true,
"text": "class A\n {\n public static final int MY_CONSTANT=1\n }\n\n class B\n {\n ....\n i+=A.MY_CONSTANT; \n }\n i+=1\n"
},
{
"answer_id": 341368,
"author": "McDowell",
"author_id": 304,
"author_profile": "https://Stackoverflow.com/users/304",
"pm_score": 3,
"selected": false,
"text": "public enum Vitamin {\n\n RETINOL(0), THIAMIN(1), RIBOFLAVIN(2);\n\n private final int intValue;\n\n Vitamin(int n) {\n intValue = n;\n }\n\n public int getVitaminType() {\n return intValue;\n }\n\n public static Vitamin asVitamin(int intValue) {\n for (Vitamin vitamin : Vitamin.values()) {\n if (intValue == vitamin.getVitaminType()) {\n return vitamin;\n }\n }\n throw new IllegalArgumentException();\n }\n\n}\n\n/** Use foo.Vitamin instead */\n@Deprecated\npublic class VitaminType {\n\n public static final int RETINOL = Vitamin.RETINOL.getVitaminType();\n public static final int THIAMIN = Vitamin.THIAMIN.getVitaminType();\n public static final int RIBOFLAVIN = Vitamin.RIBOFLAVIN.getVitaminType();\n\n}\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341005",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24173/"
] |
341,018 | <p>Is there a way to make a DataGridView have no cell selected? I notice even when it loses focus() it has a at least one active cell. Is there another mode that allows this? or some other trick? </p>
| [
{
"answer_id": 380161,
"author": "David Hall",
"author_id": 2660,
"author_profile": "https://Stackoverflow.com/users/2660",
"pm_score": 3,
"selected": false,
"text": "DataGridView.CurrentCell = null private void dgvMyGrid_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)\n {\n if (dgvMyGrid.SelectedRows.Count > 0)\n {\n dgvMyGrid.SelectedRows[0].Selected = false;\n }\n\n dgvMyGrid.SelectionChanged += dgvMyGrid_SelectionChanged;\n }\n DataBindingComplete SelectionChanged"
},
{
"answer_id": 431529,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load\n\nDim dgvRow(17) As DataGridViewRow\nDim i As Integer\nFor i = 0 To dgvRow.Length - 1\n dgvRow(i) = New DataGridViewRow()\n dgvRow(i).Height = 16\n dgvRow(i).Selected = False\n dgvRow(i).ReadOnly = True\n DataGridView1.Rows.Add(dgvRow(i))\n DataGridView1.CurrentRow.Selected = False\nNext\nEnd Sub\n DataGridView1.CurrentRow.Selected = False\n"
},
{
"answer_id": 9040440,
"author": "J. Ouwehand",
"author_id": 1174450,
"author_profile": "https://Stackoverflow.com/users/1174450",
"pm_score": 3,
"selected": false,
"text": "RowsDefaultCellStyle.SelectionBackColor = BackgroundColor;\nRowsDefaultCellStyle.SelectionForeColor = ForeColor;\n"
},
{
"answer_id": 14050056,
"author": "KbManu",
"author_id": 1530713,
"author_profile": "https://Stackoverflow.com/users/1530713",
"pm_score": 2,
"selected": false,
"text": "void dataGridView_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)\n\n{\n\n DataGridView dgv = sender as DataGridView;\n\n dgv.ClearSelection();\n\n}\n"
},
{
"answer_id": 26942134,
"author": "Jaans",
"author_id": 351511,
"author_profile": "https://Stackoverflow.com/users/351511",
"pm_score": 1,
"selected": false,
"text": "CurrentCell DataGridView /// <summary>\n/// Responsible for hiding the selection of a DataGridView row when the control loses focus.\n/// </summary>\npublic class DataGridViewHideSelection : IDisposable\n{\n private readonly DataGridView _dataGridView;\n\n private Color _alternatingRowSelectionBackColor = Color.Empty;\n private Color _alternatingRowSelectionForeColor = Color.Empty;\n private Color _rowSelectionBackColor = Color.Empty;\n private Color _rowSelectionForeColor = Color.Empty;\n\n /// <summary>\n /// Initializes a new instance of the <see cref=\"DataGridViewHideSelection\"/> class.\n /// </summary>\n /// <param name=\"dataGridView\">The data grid view.</param>\n public DataGridViewHideSelection( DataGridView dataGridView )\n {\n if ( dataGridView == null )\n throw new ArgumentNullException( \"dataGridView\" );\n\n _dataGridView = dataGridView;\n _dataGridView.Enter += DataGridView_Enter;\n _dataGridView.Leave += DataGridView_Leave;\n }\n\n /// <summary>\n /// Handles the Enter event of the DataGridView control.\n /// </summary>\n /// <param name=\"sender\">The source of the event.</param>\n /// <param name=\"e\">The <see cref=\"EventArgs\"/> instance containing the event data.</param>\n private void DataGridView_Enter( object sender, EventArgs e )\n {\n // Restore original colour\n if ( _rowSelectionBackColor != Color.Empty )\n _dataGridView.RowsDefaultCellStyle.SelectionBackColor = _rowSelectionBackColor;\n\n if ( _rowSelectionForeColor != Color.Empty )\n _dataGridView.RowsDefaultCellStyle.SelectionForeColor = _rowSelectionForeColor;\n\n if ( _alternatingRowSelectionBackColor != Color.Empty )\n _dataGridView.AlternatingRowsDefaultCellStyle.SelectionBackColor = _alternatingRowSelectionBackColor;\n\n if ( _alternatingRowSelectionForeColor != Color.Empty )\n _dataGridView.AlternatingRowsDefaultCellStyle.SelectionForeColor = _alternatingRowSelectionForeColor;\n }\n\n /// <summary>\n /// Handles the Leave event of the DataGridView control.\n /// </summary>\n /// <param name=\"sender\">The source of the event.</param>\n /// <param name=\"e\">The <see cref=\"EventArgs\"/> instance containing the event data.</param>\n private void DataGridView_Leave( object sender, EventArgs e )\n {\n // Backup original colour\n _rowSelectionBackColor = _dataGridView.RowsDefaultCellStyle.SelectionBackColor;\n _rowSelectionForeColor = _dataGridView.RowsDefaultCellStyle.SelectionForeColor;\n _alternatingRowSelectionBackColor = _dataGridView.RowsDefaultCellStyle.SelectionBackColor;\n _alternatingRowSelectionForeColor = _dataGridView.RowsDefaultCellStyle.SelectionForeColor;\n\n // Change to \"blend\" in\n _dataGridView.RowsDefaultCellStyle.SelectionBackColor = _dataGridView.RowsDefaultCellStyle.BackColor;\n _dataGridView.RowsDefaultCellStyle.SelectionForeColor = _dataGridView.RowsDefaultCellStyle.ForeColor;\n _dataGridView.AlternatingRowsDefaultCellStyle.SelectionBackColor = _dataGridView.AlternatingRowsDefaultCellStyle.BackColor;\n _dataGridView.AlternatingRowsDefaultCellStyle.SelectionForeColor = _dataGridView.AlternatingRowsDefaultCellStyle.ForeColor;\n }\n\n #region IDisposable implementation (for root base class)\n\n private bool _disposed;\n\n /// <summary>\n /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.\n /// </summary>\n /// <remarks>\n /// Called by consumers.\n /// </remarks>\n public void Dispose()\n {\n Dispose( true );\n GC.SuppressFinalize( this );\n }\n\n /// <summary>\n /// Disposes this instance, with an indication whether it is called from managed code or the GC's finalization of this instance.\n /// </summary>\n /// <remarks>\n /// Overridden by inheritors.\n /// </remarks>\n /// <param name=\"disposingFromManagedCode\">if set to <c>true</c> disposing from managed code.</param>\n protected virtual void Dispose( Boolean disposingFromManagedCode )\n {\n if ( _disposed )\n return;\n\n // Clean up managed resources here\n if ( disposingFromManagedCode )\n {\n if ( _dataGridView != null )\n {\n _dataGridView.Enter -= DataGridView_Enter;\n _dataGridView.Leave -= DataGridView_Leave;\n }\n }\n\n // Clean up any unmanaged resources here\n\n // Signal disposal has been done.\n _disposed = true;\n }\n\n /// <summary>\n /// Finalize an instance of the <see cref=\"DataGridViewHideSelection\"/> class.\n /// </summary>\n ~DataGridViewHideSelection()\n {\n Dispose( false );\n }\n\n #endregion\n}\n\n\n/// <summary>\n/// Extends data grid view capabilities with additional extension methods.\n/// </summary>\npublic static class DataGridViewExtensions\n{\n /// <summary>\n /// Attaches the hide selection behaviour to the specified DataGridView instance.\n /// </summary>\n /// <param name=\"dataGridView\">The data grid view.</param>\n /// <returns></returns>\n /// <exception cref=\"System.ArgumentNullException\">dataGridView</exception>\n public static DataGridViewHideSelection AttachHideSelectionBehaviour( this DataGridView dataGridView )\n {\n if ( dataGridView == null )\n throw new ArgumentNullException( \"dataGridView\" );\n\n return new DataGridViewHideSelection( dataGridView );\n }\n}\n var hideSelection = new DataGridViewHideSelection( myGridView );\n\n// ...\n\n/// When no longer needed\nhideSelection.Dispose();\n AttachHideSelectionBehaviour() myDataGrid.AttachHideSelectionBehaviour();\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341018",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36590/"
] |
341,039 | <p>In <a href="http://msdn.microsoft.com/en-us/library/ms462365.aspx" rel="nofollow noreferrer">CAML</a> I can query SharePoint Listitems using the "Contains"-element, but there is no "does not contain"-element I could use.</p>
<p>So what is the best way to get the items that do not contain a string? Is there a better way than to loop through each and every item?</p>
| [
{
"answer_id": 2382575,
"author": "Alex Nolasco",
"author_id": 65694,
"author_profile": "https://Stackoverflow.com/users/65694",
"pm_score": 2,
"selected": false,
"text": "=ISNUMBER(FIND(\"Critical\"), [Title])\n <Query>\n<Where>\n <Eq>\n <FieldRef Name='IsCritical'/>\n <Value Type='Boolean'>0</Value>\n </Eq>\n</Where>\n</Query>\n"
},
{
"answer_id": 32076800,
"author": "Daniel",
"author_id": 1291353,
"author_profile": "https://Stackoverflow.com/users/1291353",
"pm_score": 0,
"selected": false,
"text": "<NotIncludes>\n<FieldRef Name='FileLeafRef' />\n <Value Type='Text'>stringvalue</Value>\n </NotIncludes>\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341039",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4531/"
] |
341,059 | <p>We have a process that needs to run every two hours. It's a process that needs to run on it's own thread so as to not interrupt normal processing.</p>
<p>When it runs, it will download 100k records and verify them against a database. The framework to run this has a lot of objects managing this process. These objects only need to be around when the process is running.</p>
<p>What's a better standard?</p>
<ol>
<li><p>Keep the thread in wait mode by letting it sleep until I need it again. Or,</p></li>
<li><p>Delete it when it is done and create it the next time I need it? (System Timer Events.)</p></li>
</ol>
| [
{
"answer_id": 341135,
"author": "Pierre",
"author_id": 24449,
"author_profile": "https://Stackoverflow.com/users/24449",
"pm_score": 4,
"selected": true,
"text": "thread_join"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341059",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34183/"
] |
341,067 | <p>I have an existing database that has some testing data into and I'm interested in turning it into a set of DDL, DML, and DCL files so that I could run it against other database systems and create the same schema and such. The database is MS Access 2003.</p>
<p>Thoughts?</p>
| [
{
"answer_id": 12285392,
"author": "Eric G",
"author_id": 268977,
"author_profile": "https://Stackoverflow.com/users/268977",
"pm_score": 2,
"selected": false,
"text": "```cscript\n\n' ddl.vbs\n' Usage:\n' CScript //Nologo ddl.vbs <input mdb file> > <output>\n'\n' Outputs DDL statements for tables, indexes, and relations from Access file \n' (.mdb, .accdb) <input file> to stdout. \n' Requires Microsoft Access.\n'\n' NOTE: Adapted from code from \"polite person\" + Kevin Chambers - see:\n' http://www.mombu.com/microsoft/comp-databases-ms-access/t-exporting-jet-table-metadata-as-text-119667.html\n'\n' (c) 2012 Eric Gjertsen \n' ericgj72@gmail.com\n'\n'Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n'\n' The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n'\n' THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n'\nOption Explicit\nDim stdout, fso\nDim strFile\nDim appAccess, db, tbl, idx, rel\n\nSet stdout = WScript.StdOut\nSet fso = CreateObject(\"Scripting.FileSystemObject\")\n\n' Parse args\nIf (WScript.Arguments.Count = 0) then\n MsgBox \"Usage: cscript //Nologo ddl.vbs access-file\", vbExclamation, \"Error\"\n Wscript.Quit()\nEnd if\nstrFile = fso.GetAbsolutePathName(WScript.Arguments(0))\n\n' Open mdb file\nSet appAccess = CreateObject(\"Access.Application\")\nappAccess.OpenCurrentDatabase strFile\nSet db = appAccess.DBEngine(0)(0)\n\n' Iterate over tables\n ' create table statements\nFor Each tbl In db.TableDefs\n If Not isSystemTable(tbl) And Not isHiddenTable(tbl) Then\n stdout.WriteLine getTableDDL(tbl)\n stdout.WriteBlankLines(1)\n\n ' Iterate over indexes\n ' create index statements\n For Each idx In tbl.Indexes\n stdout.WriteLine getIndexDDL(tbl, idx)\n Next\n\n stdout.WriteBlankLines(2)\n End If\nNext\n\n' Iterate over relations\n ' alter table add constraint statements\nFor Each rel In db.Relations\n Set tbl = db.TableDefs(rel.Table)\n If Not isSystemTable(tbl) And Not isHiddenTable(tbl) Then\n stdout.WriteLine getRelationDDL(rel)\n stdout.WriteBlankLines(1)\n End If\nNext\n\nFunction getTableDDL(tdef)\nConst dbBoolean = 1\nConst dbByte = 2\nConst dbCurrency = 5\nConst dbDate = 8\nConst dbDouble = 7\nConst dbInteger = 3\nConst dbLong = 4\nConst dbDecimal = 20\nConst dbFloat = 17\nConst dbMemo = 12\nConst dbSingle = 6\nConst dbText = 10\nConst dbGUID = 15\nConst dbAutoIncrField = 16\n\nDim fld\nDim sql\nDim ln, a\n\n sql = \"CREATE TABLE \" & QuoteObjectName(tdef.name) & \" (\"\n ln = vbCrLf\n\n For Each fld In tdef.fields\n sql = sql & ln & \" \" & QuoteObjectName(fld.name) & \" \"\n Select Case fld.Type\n Case dbBoolean 'Boolean\n a = \"BIT\"\n Case dbByte 'Byte\n a = \"BYTE\"\n Case dbCurrency 'Currency\n a = \"MONEY\"\n Case dbDate 'Date / Time\n a = \"DATETIME\"\n Case dbDouble 'Double\n a = \"DOUBLE\"\n Case dbInteger 'Integer\n a = \"INTEGER\"\n Case dbLong 'Long\n 'test if counter, doesn't detect random property if set\n If (fld.Attributes And dbAutoIncrField) Then\n a = \"COUNTER\"\n Else\n a = \"LONG\"\n End If\n Case dbDecimal 'Decimal\n a = \"DECIMAL\"\n Case dbFloat 'Float\n a = \"FLOAT\"\n Case dbMemo 'Memo\n a = \"MEMO\"\n Case dbSingle 'Single\n a = \"SINGLE\"\n Case dbText 'Text\n a = \"VARCHAR(\" & fld.Size & \")\"\n Case dbGUID 'Text\n a = \"GUID\"\n Case Else\n '>>> raise error\n MsgBox \"Field \" & tdef.name & \".\" & fld.name & _\n \" of type \" & fld.Type & \" has been ignored!!!\"\n End Select\n\n sql = sql & a\n\n If fld.Required Then _\n sql = sql & \" NOT NULL \"\n If Len(fld.DefaultValue) > 0 Then _\n sql = sql & \" DEFAULT \" & fld.DefaultValue\n\n ln = \", \" & vbCrLf\n Next\n\n sql = sql & vbCrLf & \");\"\n getTableDDL = sql\n\nEnd Function\n\nFunction getIndexDDL(tdef, idx)\nDim sql, ln, myfld\n\n If Left(idx.name, 1) = \"{\" Then\n 'ignore, GUID-type indexes - bugger them\n ElseIf idx.Foreign Then\n 'this index was created by a relation. recreating the\n 'relation will create this for us, so no need to do it here\n Else\n ln = \"\"\n sql = \"CREATE \"\n If idx.Unique Then\n sql = sql & \"UNIQUE \"\n End If\n sql = sql & \"INDEX \" & QuoteObjectName(idx.name) & \" ON \" & _\n QuoteObjectName(tdef.name) & \"( \"\n For Each myfld In idx.fields\n sql = sql & ln & QuoteObjectName(myfld.name)\n ln = \", \"\n Next\n sql = sql & \" )\"\n If idx.Primary Then\n sql = sql & \" WITH PRIMARY\"\n ElseIf idx.IgnoreNulls Then\n sql = sql & \" WITH IGNORE NULL\"\n ElseIf idx.Required Then\n sql = sql & \" WITH DISALLOW NULL\"\n End If\n sql = sql & \";\"\n End If\n getIndexDDL = sql\n\nEnd Function\n\n' Returns the SQL DDL to add a relation between two tables.\n' Oddly, DAO will not accept the ON DELETE or ON UPDATE\n' clauses, so the resulting sql must be executed through ADO\nFunction getRelationDDL(myrel)\nConst dbRelationUpdateCascade = 256\nConst dbRelationDeleteCascade = 4096\nDim mytdef\nDim myfld\nDim sql, ln\n\n\n With myrel\n sql = \"ALTER TABLE \" & QuoteObjectName(.ForeignTable) & _\n \" ADD CONSTRAINT \" & QuoteObjectName(.name) & \" FOREIGN KEY ( \"\n ln = \"\"\n For Each myfld In .fields 'ie fields of the relation\n sql = sql & ln & QuoteObjectName(myfld.ForeignName)\n ln = \",\"\n Next\n sql = sql & \" ) \" & \"REFERENCES \" & _\n QuoteObjectName(.table) & \"( \"\n ln = \"\"\n For Each myfld In .fields\n sql = sql & ln & QuoteObjectName(myfld.name)\n ln = \",\"\n Next\n sql = sql & \" )\"\n If (myrel.Attributes And dbRelationUpdateCascade) Then _\n sql = sql & \" ON UPDATE CASCADE\"\n If (myrel.Attributes And dbRelationDeleteCascade) Then _\n sql = sql & \" ON DELETE CASCADE\"\n sql = sql & \";\"\n End With\n getRelationDDL = sql\nEnd Function\n\n\nFunction isSystemTable(tbl)\nDim nAttrib\nConst dbSystemObject = -2147483646\n isSystemTable = False\n nAttrib = tbl.Attributes\n isSystemTable = (nAttrib <> 0 And ((nAttrib And dbSystemObject) <> 0))\nEnd Function\n\nFunction isHiddenTable(tbl)\nDim nAttrib\nConst dbHiddenObject = 1\n isHiddenTable = False\n nAttrib = tbl.Attributes\n isHiddenTable = (nAttrib <> 0 And ((nAttrib And dbHiddenObject) <> 0))\nEnd Function\n\nFunction QuoteObjectName(str)\n QuoteObjectName = \"[\" & str & \"]\"\nEnd Function\n\n```\n ```cscript\n\n' dump.vbs\n' Usage:\n' CScript //Nologo dump.vbs access-file [table] > <output>\n'\n' Outputs INSERT SQL statements for all data in specified table of Access \n' file (.mdb, .accdb) to stdout. If no table specified, then statements are\n' generated for all tables in Access file.\n'\n' Requires Microsoft Access.\n'\n' (c) 2012 Eric Gjertsen \n' ericgj72@gmail.com\n'\n'Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n'\n' The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n'\n' THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n'\n\nOption Explicit\nDim stdout, stderr, fso\nDim strFile, strTbl\nDim appAccess, db, tbl, rst\n\nSet stdout = WScript.StdOut\nSet stderr = WScript.StdErr\n\nSet fso = CreateObject(\"Scripting.FileSystemObject\")\n\n' Parse args\nIf (WScript.Arguments.Count = 0) then\n MsgBox \"Usage: cscript //Nologo dump.vbs access-file [table]\", vbExclamation, \"Error\"\n Wscript.Quit()\nEnd if\nstrFile = fso.GetAbsolutePathName(WScript.Arguments(0))\nstrTbl = \"\"\nIf WScript.Arguments.Count = 2 Then\n strTbl = WScript.Arguments(1)\nEnd If\n\n' Open mdb file\nSet appAccess = CreateObject(\"Access.Application\")\nappAccess.OpenCurrentDatabase strFile\nSet db = appAccess.DBEngine(0)(0)\n\n' Iterate over tables\n ' dump records as INSERT INTO statements\nFor Each tbl In db.TableDefs\n If (Len(strTbl)>0 And UCase(tbl.Name) = UCase(strTbl)) Or _\n (Len(strTbl)=0 And Not isSystemTable(tbl) And Not isHiddenTable(tbl)) Then\n Set rst = tbl.OpenRecordset\n If Not rst.EOF And Not rst.BOF Then\n rst.MoveFirst\n stderr.WriteLine \"Dumping table \" + tbl.Name\n While Not rst.EOF\n stdout.WriteLine getRecSQL(tbl, rst)\n rst.MoveNext\n Wend\n stdout.WriteBlankLines(1)\n End If\n stdout.WriteBlankLines(1)\n End if\nNext\n\n\nFunction getRecSQL(tdef, rst)\n\n Dim fld, sql\n Dim flds, vals, i\n\n ReDim flds(tdef.Fields.count - 1)\n ReDim vals(tdef.Fields.count - 1)\n i = -1\n For Each fld In tdef.fields\n i = i + 1\n flds(i) = QuoteObjectName(fld.name)\n vals(i) = serializeValue(rst.Fields(fld.name).Value, fld.Type)\n Next\n\n sql = \"INSERT INTO \" & QuoteObjectName(tdef.Name) & \" (\" & Join(flds,\",\") & \") \" & _\n \"VALUES (\" & Join(vals,\",\") & \");\"\n\n getRecSQL = sql\n\nEnd Function\n\nFunction serializeValue( val, fldType )\n Const dbBoolean = 1\n Const dbByte = 2\n Const dbCurrency = 5\n Const dbDate = 8\n Const dbDouble = 7\n Const dbInteger = 3\n Const dbLong = 4\n Const dbDecimal = 20\n Const dbFloat = 17\n Const dbMemo = 12\n Const dbSingle = 6\n Const dbText = 10\n Const dbGUID = 15\n Const dbAutoIncrField = 16\n\n Dim a, ln\n ln = Chr(13) + Chr(10)\n\n If IsNull(val) Then \n a = \"Null\"\n Else\n Select Case fldType\n Case dbBoolean, dbByte, dbCurrency, dbDouble, dbInteger, dbLong, dbDecimal, dbFloat, dbSingle, dbGUID\n a = CStr(val)\n Case dbDate\n a = \"#\" & CStr(val) & \"#\"\n Case dbMemo, dbText\n a = Chr(34) + Replace(Replace(val, Chr(34), Chr(34) + Chr(34)), ln, \" \") + Chr(34) \n Case Else\n '>>> raise error\n a = \"Null\"\n End Select\n End If\n\n serializeValue = a\n\nEnd Function\n\n\n\nFunction isSystemTable(tbl)\nDim nAttrib\nConst dbSystemObject = -2147483646\n isSystemTable = False\n nAttrib = tbl.Attributes\n isSystemTable = (nAttrib <> 0 And ((nAttrib And dbSystemObject) <> 0))\nEnd Function\n\nFunction isHiddenTable(tbl)\nDim nAttrib\nConst dbHiddenObject = 1\n isHiddenTable = False\n nAttrib = tbl.Attributes\n isHiddenTable = (nAttrib <> 0 And ((nAttrib And dbHiddenObject) <> 0))\nEnd Function\n\nFunction QuoteObjectName(str)\n QuoteObjectName = \"[\" & str & \"]\"\nEnd Function\n```\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341067",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16562/"
] |
341,074 | <p>Without using plpgsql, I'm trying to urlencode a given text within a pgsql SELECT statement.</p>
<p>The problem with this approach:</p>
<pre><code>select regexp_replace('héllo there','([^A-Za-z0-9])','%' || encode(E'\\1','hex'),'g')
</code></pre>
<p>...is that the encode function is not passed the regexp parameter, unless there's another way to call functions from within the replacement expression that actually works. So I'm wondering if there's a replacement expression that, by itself, can encode matches into hex values.</p>
<p>There may be other combinations of functions. I thought there would be a clever regex (and that may still be the answer) out there, but I'm having trouble finding it.</p>
| [
{
"answer_id": 341240,
"author": "Kev",
"author_id": 16777,
"author_profile": "https://Stackoverflow.com/users/16777",
"pm_score": 4,
"selected": true,
"text": "select regexp_replace(encode('héllo there','hex'),'(..)',E'%\\\\1','g');\n"
},
{
"answer_id": 33616365,
"author": "Paul Christmann",
"author_id": 4765151,
"author_profile": "https://Stackoverflow.com/users/4765151",
"pm_score": 1,
"selected": false,
"text": "CREATE OR REPLACE FUNCTION oseberg.encode_uri(input text)\n RETURNS text\n LANGUAGE plpgsql\n IMMUTABLE STRICT\nAS $function$\nDECLARE\n parsed text;\n safePattern text;\nBEGIN\n safePattern = 'a-zA-Z0-9_~/\\-\\.';\n IF input ~ ('[^' || safePattern || ']') THEN\n SELECT STRING_AGG(fragment, '')\n INTO parsed\n FROM (\n SELECT prefix || encoded AS fragment\n FROM (\n SELECT COALESCE(match[1], '') AS prefix,\n COALESCE('%' || encode(match[2]::bytea, 'hex'), '') AS encoded\n FROM (\n SELECT regexp_matches(\n input,\n '([' || safePattern || ']*)([^' || safePattern || '])?',\n 'g') AS match\n ) matches\n ) parsed\n ) fragments;\n RETURN parsed;\n ELSE\n RETURN input;\n END IF;\nEND;\n$function$\n"
},
{
"answer_id": 40121098,
"author": "Nick",
"author_id": 4677351,
"author_profile": "https://Stackoverflow.com/users/4677351",
"pm_score": 2,
"selected": false,
"text": "create or replace function urlencode(in_str text, OUT _result text) returns text as $$\n select\n string_agg(\n case\n when ol>1 or ch !~ '[0-9a-za-z:/@._?#-]+' \n then regexp_replace(upper(substring(ch::bytea::text, 3)), '(..)', E'%\\\\1', 'g')\n else ch\n end,\n ''\n )\n from (\n select ch, octet_length(ch) as ol\n from regexp_split_to_table($1, '') as ch\n ) as s;\n$$ language sql immutable strict;\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341074",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16777/"
] |
341,080 | <p>I am attempting to get a DropDownList to AutoPostBack via an UpdatePanel when the selected item is changed. I'm going a little stir-crazy as to why this isn't working.</p>
<p>Does anyone have any quick ideas?</p>
<p>ASPX page:</p>
<pre><code><asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always" ChildrenAsTriggers="true" >
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" onselectedindexchanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>item 1</asp:ListItem>
<asp:ListItem>item 2</asp:ListItem>
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
</code></pre>
<p>Code-behind (I put a breakpoint on the string assignment to capture the postback):</p>
<pre><code>protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string s = "";
}
</code></pre>
<p><strong>Edit:</strong></p>
<p><strong>OK, I have it working now. Very weird. All it took was a restart of Visual Studio. This is the kind of thing that frightens me as a developer ;) I think I've seen similar before, where VS gets "out of sync" wrt the assembly it's running.</strong></p>
<p><strong>FYI I am running VS 2008 Web Developer Express.</strong></p>
<p><strong>Thanks to those that answered.</strong></p>
| [
{
"answer_id": 341147,
"author": "Programmin Tool",
"author_id": 21691,
"author_profile": "https://Stackoverflow.com/users/21691",
"pm_score": 4,
"selected": true,
"text": " <asp:ScriptManager ID=\"smMain\" runat=\"server\" />\n\n <asp:UpdatePanel ID=\"UpdatePanel1\" runat=\"server\" UpdateMode=\"Always\" ChildrenAsTriggers=\"true\" > \n <ContentTemplate>\n <asp:DropDownList ID=\"DropDownList1\" runat=\"server\" AutoPostBack=\"True\" onselectedindexchanged=\"DropDownList1_SelectedIndexChanged\">\n <asp:ListItem>item 1</asp:ListItem>\n <asp:ListItem>item 2</asp:ListItem>\n </asp:DropDownList>\n </ContentTemplate>\n </asp:UpdatePanel>\n\n\n\n protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)\n {\n throw new NotImplementedException();\n }\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341080",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/38522/"
] |
341,086 | <p>I need advice regarding subselect performance in MySQL. For a reason that I can't change, I am not able to use JOIN to create quesry filter, I can only add another AND clause in WHERE.</p>
<p>What is the peformance of:</p>
<pre><code>select tasks.*
from tasks
where
some criteria
and task.project_id not in (select id from project where project.is_template = 1);
</code></pre>
<p>compared to:</p>
<pre><code>select tasks.*
from tasks, project
where
some criteria
and task.project_id = project.id and project.is_template <> 1;
</code></pre>
<p>Note that there is relatively small number of projects whete is_template = 1, and there could be large number of projects where is_template <> 1.</p>
<p>Is there other way to achieve the same result without subselects if I can't change anything but and filter?</p>
| [
{
"answer_id": 341124,
"author": "Rob Prouse",
"author_id": 30827,
"author_profile": "https://Stackoverflow.com/users/30827",
"pm_score": 4,
"selected": true,
"text": "EXPLAIN select tasks.*\nfrom tasks\nwhere \n some criteria\n and task.project_id not in (select id from project where project.is_template = 1);\n\nEXPLAIN select tasks.*\nfrom tasks, project\nwhere\n some criteria\n and task.project_id = project.id and project.is_template <> 1;\n"
},
{
"answer_id": 341167,
"author": "ysth",
"author_id": 17389,
"author_profile": "https://Stackoverflow.com/users/17389",
"pm_score": 1,
"selected": false,
"text": "select tasks.*\nfrom tasks\nwhere \n some criteria\n and task.project_id in (select id from project where project.is_template <> 1);\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341086",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31141/"
] |
341,103 | <p>I have this C# extension method that will extend any dictionary where the <em>Value</em> type is an <em>IList</em>. When I write the equivalent code in VB.Net I get the following compile error:</p>
<blockquote>
<p><em>"Extension method 'Add' has some type constraints that can never be satisfied".</em></p>
</blockquote>
<p>I find this really puzzling as the <strong>same</strong> type constraints <strong>can</strong> be satisfied in C#.</p>
<p>So my question is this: Why does this not work in VB? Is there a way to make these same type constraints work in VB? Have I made a mistake converting the code? I hope somebody can shed some light on this as I have been scratching my head on this one for a while. :)</p>
<p><em>(Incase you are curious the extension method is intended to make it simple to add multiple values into a dictionary under a <strong>single</strong> key (such as multiple orders under one customer). But this is unimportant, I am solely concerned about the puzzling behaviour I am observing in VB).</em></p>
<p><strong>Here is the C# Version that works:</strong></p>
<pre><code>/// <summary>
/// Adds the specified value to the multi value dictionary.
/// </summary>
/// <param name="key">The key of the element to add.</param>
/// <param name="value">The value of the element to add. The value can be null for reference types.</param>
public static void Add<KeyType, ListType, ValueType>(this Dictionary<KeyType, ListType> thisDictionary,
KeyType key, ValueType value)
where ListType : IList<ValueType>, new()
{
//if the dictionary doesn't contain the key, make a new list under the key
if (!thisDictionary.ContainsKey(key))
{
thisDictionary.Add(key, new ListType());
}
//add the value to the list at the key index
thisDictionary[key].Add(value);
}
</code></pre>
<p><strong>Here is the VB version that doesn't compile:</strong></p>
<pre class="lang-vb prettyprint-override"><code>''' <summary>
''' Adds the specified value to the multi value dictionary.
''' </summary>
''' <param name="key">The key of the element to add.</param>
''' <param name="value">The value of the element to add. The value can be null for reference types.</param>
<System.Runtime.CompilerServices.Extension()> _
Public Sub Add(Of KeyType, ListType As {IList(Of ValueType), New}, ValueType) _
(ByVal thisDictionary As Dictionary(Of KeyType, ListType), ByVal key As KeyType, ByVal value As ValueType)
'if the dictionary doesn't contain the key, make a new list under the key
If Not thisDictionary.ContainsKey(key) Then
thisDictionary.Add(key, New ListType())
End If
'add the value to the list at the key index
thisDictionary(key).Add(value)
End Sub
</code></pre>
| [
{
"answer_id": 341565,
"author": "configurator",
"author_id": 9536,
"author_profile": "https://Stackoverflow.com/users/9536",
"pm_score": 4,
"selected": true,
"text": "<System.Runtime.CompilerServices.Extension()> Dictionary(Of KeyType, ListType) ValueType IList(Of TValue)"
},
{
"answer_id": 5090485,
"author": "Mark Hurd",
"author_id": 256431,
"author_profile": "https://Stackoverflow.com/users/256431",
"pm_score": 1,
"selected": false,
"text": "''' <summary> \n''' Adds the specified value to the multi value dictionary. \n''' </summary> \n''' <param name=\"key\">The key of the element to add.</param> \n''' <param name=\"value\">The value of the element to add. The value can be null for reference types.</param> \n<System.Runtime.CompilerServices.Extension()> _\nPublic Sub Add(Of KeyType, ListType As {New, IList(Of ValueType)}, ValueType) _\n (ByVal thisDictionary As Dictionary(Of KeyType, IList(Of ValueType)), ByVal key As KeyType, ByVal value As ValueType)\n 'if the dictionary doesn't contain the key, make a new list under the key \n If Not thisDictionary.ContainsKey(key) Then\n thisDictionary.Add(key, New ListType())\n End If\n\n 'add the value to the list at the key index \n thisDictionary(key).Add(value)\nEnd Sub\n Dictionary ListType (Of ..., IList(Of ...))"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341103",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39277/"
] |
341,109 | <p>I'm using reflection to get the Authorize Attributes from controllers and methods.</p>
<p>Since I will need to get this information over and over I'm wondering if it is faster to cache it or to simply continue to use reflection to get it.</p>
<p>Any thoughts?</p>
| [
{
"answer_id": 341565,
"author": "configurator",
"author_id": 9536,
"author_profile": "https://Stackoverflow.com/users/9536",
"pm_score": 4,
"selected": true,
"text": "<System.Runtime.CompilerServices.Extension()> Dictionary(Of KeyType, ListType) ValueType IList(Of TValue)"
},
{
"answer_id": 5090485,
"author": "Mark Hurd",
"author_id": 256431,
"author_profile": "https://Stackoverflow.com/users/256431",
"pm_score": 1,
"selected": false,
"text": "''' <summary> \n''' Adds the specified value to the multi value dictionary. \n''' </summary> \n''' <param name=\"key\">The key of the element to add.</param> \n''' <param name=\"value\">The value of the element to add. The value can be null for reference types.</param> \n<System.Runtime.CompilerServices.Extension()> _\nPublic Sub Add(Of KeyType, ListType As {New, IList(Of ValueType)}, ValueType) _\n (ByVal thisDictionary As Dictionary(Of KeyType, IList(Of ValueType)), ByVal key As KeyType, ByVal value As ValueType)\n 'if the dictionary doesn't contain the key, make a new list under the key \n If Not thisDictionary.ContainsKey(key) Then\n thisDictionary.Add(key, New ListType())\n End If\n\n 'add the value to the list at the key index \n thisDictionary(key).Add(value)\nEnd Sub\n Dictionary ListType (Of ..., IList(Of ...))"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341109",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3396/"
] |
341,112 | <p>How to call a javascript file (.js) via Excel VBA?</p>
<hr>
<p>So as i am opposed to the same kind of problem i'll try to submit you guys my case.</p>
<p>I am trying to automate datas extraction from valeo's catalogue using excel vba macro.</p>
<p>I have a list of références attached to valeo's automotive products (huge list, as more than 3000 thousands items). And i would like to import directly informations from the catalogue wich seems to run under javascript.</p>
<p>The datas i need is the list of every vehicules attached to a reference.</p>
<p>Here is the url: <a href="http://outcat-cs.tecdoc.net/ows/en/7FA2A0C501BC34CA4BECB04095663CF1.ows_cs2.srv?view=VIndexFramesetJsp" rel="nofollow noreferrer">http://outcat-cs.tecdoc.net/ows/en/7FA2A0C501BC34CA4BECB04095663CF1.ows_cs2.srv?view=VIndexFramesetJsp</a></p>
<p>I'd like to access to the "Direct Article Search" tab, in order to copy a reference directly from an excel tab's cell and then simulate a clic on the reference in order to display the "linked vehicules section" and then to copy them in a new excel sheet.</p>
<p>I already succeede in doing this with html pure programmed webpage (oscaro.com) using the following code :</p>
<pre><code>Set maPageHtml = IE.document
Set Helem = maPageHtml.getElementsByTagName("input")
For i = 0 To Helem.Length - 1
If Helem(i).getAttribute("name") = "toFind" Then Helem(i).Value = "819971" '819971 is the valeo reference searched
If Helem(i).getAttribute("name") = "submit" Then Set Monbouton = Helem(i)
Next
Monbouton.Click 'this does the click on my button Monbouton
</code></pre>
<p>But this technique can't be used with valeo website since I am not able (or at least I don't know yet how to do it) to select/click a button when the page is made on javascript, since it doesn't have a name, value or id for the button.</p>
<p>Also it seems that the url in the address field is the same before clicking on the "Direct Article Search" button and after having clicked....</p>
<p>Hope i am clear enought in spite of my english...</p>
<p>Greetings</p>
| [
{
"answer_id": 341160,
"author": "Dirk Vollmar",
"author_id": 40347,
"author_profile": "https://Stackoverflow.com/users/40347",
"pm_score": 0,
"selected": false,
"text": "oIE.Document.frmMain.param1.Value = 5\noIE.Document.frmMain.param2.Value = \"6\"\noIE.Document.frmMain.submit.click ' this line will call the JavaScript function\n <div id=\"submit\" > <a href=\"javascript:doAction();\">Do Action</a></div>\n\n<script>\nfunction doAction()\n{\n // do whatever the code should do\n}\n</script>\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341112",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
341,118 | <p>In order to reference a member of a class in XML comments/documentation, you have to use the following tag:</p>
<pre><code><see cref="member"/>
</code></pre>
<p>It is better explained <a href="http://msdn.microsoft.com/en-us/library/acd0tfbe.aspx" rel="noreferrer">here</a>.</p>
<p><strong>How do you reference an <em>indexer</em>?</strong></p>
<p>I mean, a member like this one:</p>
<pre><code>internal object this[ int index ] {
...
}
</code></pre>
<p>Thanks in advance.</p>
| [
{
"answer_id": 341149,
"author": "leppie",
"author_id": 15541,
"author_profile": "https://Stackoverflow.com/users/15541",
"pm_score": 5,
"selected": true,
"text": "<see cref=\"P:System.Collections.ArrayList.Item(System.Int32)\" />\n"
},
{
"answer_id": 341242,
"author": "jyoung",
"author_id": 14841,
"author_profile": "https://Stackoverflow.com/users/14841",
"pm_score": 3,
"selected": false,
"text": "<see cref=\"this[int]\" />\n"
},
{
"answer_id": 6234624,
"author": "user492238",
"author_id": 492238,
"author_profile": "https://Stackoverflow.com/users/492238",
"pm_score": 1,
"selected": false,
"text": "</member>\n<member name=\"P:My.Namespace.Class1.Item(System.String)\">\n <summary>\n retrieve a single item of the given name from this instance\n </summary>\n <param name=\"name\">name of the item</param>\n <returns>the item</returns>\n</member>\n<member name=\"M:My.Namespace.Class1.Function1(System.Int32[])\">\n <summary> \n ... \n <member name=\"M:My.Namespace.Class1.Get``1(System.String)\">\n <summary>\n retrieve an named item of the given type\n </summary>\n <typeparam name=\"T\">the type of the item to retrieve</typeparam>\n ...\n cref /// <seealso cref=\"M:My.Namespace.Class1.Get{T}(System.String)\"/> \n\n/// <seealso cref=\"M:My.Namespace.Class1.Get<T>(System.String)\"/> \n"
},
{
"answer_id": 35013550,
"author": "Qny",
"author_id": 4973073,
"author_profile": "https://Stackoverflow.com/users/4973073",
"pm_score": 2,
"selected": false,
"text": "<see cref=\"P:System.Collections.ArrayList.Item(System.Int32)\" /> <seealso cref=\"M:My.Namespace.Class1.Get{T}(System.String)\"/> <seealso cref=\"M:My.Namespace.Class1.Get<T>(System.String)\"/> <see cref=\"P:System.Collections.Generic.Dictionary`2.Item(`0)\" />\n Dictionary<TKey, TValue>.this[TKey]\n"
},
{
"answer_id": 44431936,
"author": "tm1",
"author_id": 806690,
"author_profile": "https://Stackoverflow.com/users/806690",
"pm_score": 2,
"selected": false,
"text": "<see cref=\"ReadOnlyCollection{T}.this[int]\" />\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341118",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1679/"
] |
341,143 | <p>Say I have a Rails Model called Thing. Thing has a url attribute that can <strong>optionally</strong> be set to a URL somewhere on the Internet. In view code, I need logic that does the following:</p>
<pre><code><% if thing.url.blank? %>
<%= link_to('Text', thing_path(thing)) %>
<% else %>
<%= link_to('Text', thing.url) %>
<% end %>
</code></pre>
<p>This conditional logic in the view is ugly. Of course, I could build a helper function, which would change the view to this:</p>
<pre><code><%= thing_link('Text', thing) %>
</code></pre>
<p>That solves the verbosity problem, but I would really prefer having the functionality in the model itself. In which case, the view code would be:</p>
<pre><code><%= link_to('Text', thing.link) %>
</code></pre>
<p>This, obviously, would require a link method on the model. Here's what it would need to contain:</p>
<pre><code>def link
(self.url.blank?) ? thing_path(self) : self.url
end
</code></pre>
<p>To the point of the question, thing_path() is an undefined method inside Model code. I'm assuming it's possible to "pull in" some helper methods into the model, but how? And is there a real reason that routing only operates at the controller and view layers of the app? I can think of lots of cases where model code may need to deal with URLs (integrating with external systems, etc).</p>
| [
{
"answer_id": 341166,
"author": "Josh Delsman",
"author_id": 40644,
"author_profile": "https://Stackoverflow.com/users/40644",
"pm_score": 4,
"selected": false,
"text": "# In the helper...\n\ndef link_to_thing(text, thing)\n (thing.url?) ? link_to(text, thing_path(thing)) : link_to(text, thing.url)\nend\n\n# In the view...\n\n<%= link_to_thing(\"text\", @thing) %>\n"
},
{
"answer_id": 341172,
"author": "Stein G. Strindhaug",
"author_id": 26115,
"author_profile": "https://Stackoverflow.com/users/26115",
"pm_score": 0,
"selected": false,
"text": "<modelname>sController"
},
{
"answer_id": 341254,
"author": "Aaron Longwell",
"author_id": 32137,
"author_profile": "https://Stackoverflow.com/users/32137",
"pm_score": 8,
"selected": false,
"text": "include ActionController::UrlWriter\n include Rails.application.routes.url_helpers\n thing_path(self) other_model_path(self.association_to_other_model)"
},
{
"answer_id": 5456103,
"author": "Paul Horsfall",
"author_id": 99265,
"author_profile": "https://Stackoverflow.com/users/99265",
"pm_score": 10,
"selected": false,
"text": "Rails.application.routes.url_helpers\n Rails.application.routes.url_helpers.posts_path\nRails.application.routes.url_helpers.posts_url(:host => \"example.com\")\n"
},
{
"answer_id": 7169083,
"author": "matthuhiggins",
"author_id": 462610,
"author_profile": "https://Stackoverflow.com/users/462610",
"pm_score": 7,
"selected": false,
"text": "class Thing\n delegate :url_helpers, to: 'Rails.application.routes' \n\n def url\n url_helpers.thing_path(self)\n end\nend\n"
},
{
"answer_id": 54542949,
"author": "Swar Shah",
"author_id": 2835167,
"author_profile": "https://Stackoverflow.com/users/2835167",
"pm_score": 3,
"selected": false,
"text": "class Router\n include Rails.application.routes.url_helpers\n\n def self.default_url_options\n ActionMailer::Base.default_url_options\n end\nend\n\nrouter = Router.new\nrouter.posts_url # http://localhost:3000/posts\nrouter.posts_path # /posts\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341143",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32137/"
] |
341,156 | <p>Is there an EF equivalent to LINQ to SQL's OnCreated partial? </p>
<p>Several of my objects have XML fields that I would like to parse whenever the object is loaded from the db - I'd like to put the XML data into more friendly strongly-typed collections. I've already marked the XML field as private and hooked the SavingChanges event to re-build the XML before the item is committed back to the db, but I can't figure out how to populate the collections whenever the object is loaded.</p>
<p>I've thought of using the OnFieldChanged partial for my XML field, but that would run again whenever the XML field is re-built during SavingChanges, so it seems like there should be a better way.</p>
| [
{
"answer_id": 341301,
"author": "David Schmitt",
"author_id": 4918,
"author_profile": "https://Stackoverflow.com/users/4918",
"pm_score": 3,
"selected": true,
"text": "OnLoaded private List<SomeData> _parsedDataCache;\npublic IList<SomeData> ParsedData {\n get {\n if (_parsedDataCache == null)\n ParseData();\n return _parsedDataCache;\n }\n}\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341156",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/521/"
] |
341,168 | <p>My installer build "signs" a DLL using a Code Signing certificate during the build process. </p>
<p>I've noticed that if I try to build twice in succession, the second build fails because the DLL is already signed so signcode chokes. Obviously I can fix this by signing a copy of the DLL in the build, but the problem intrigued me: </p>
<p>Is it possible to "unsign" a DLL, and if not, why not...?</p>
| [
{
"answer_id": 40173109,
"author": "vine'th",
"author_id": 478028,
"author_profile": "https://Stackoverflow.com/users/478028",
"pm_score": 6,
"selected": true,
"text": "signtool remove /s C:\\path\\to.exe.or.dll\n remove"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341168",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1737/"
] |
341,175 | <p>I have a datetime coming back from an XML file in the format:</p>
<blockquote>
<p>20080916 11:02</p>
</blockquote>
<p>as in </p>
<blockquote>
<p>yyyymm hh:ss</p>
</blockquote>
<p>How can i get the datetime.parse function to pick up on this? Ie parse it without erroring?
Cheers</p>
| [
{
"answer_id": 341200,
"author": "Blair Conrad",
"author_id": 1199,
"author_profile": "https://Stackoverflow.com/users/1199",
"pm_score": 9,
"selected": true,
"text": "DateTime.ParseExact(input,\"yyyyMMdd HH:mm\",null);\n"
},
{
"answer_id": 23805955,
"author": "bert",
"author_id": 995067,
"author_profile": "https://Stackoverflow.com/users/995067",
"pm_score": 4,
"selected": false,
"text": "DateTime dt = DateTime.MinValue;\n\nDateTime.TryParseExact(\"20071122\", \"yyyyMMdd\", null,System.Globalization.DateTimeStyles.None, out dt);\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341175",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35441/"
] |
341,184 | <p>I'm running Windows and the shell/OS automatically runs Python based on the registry settings when you run a program on the command line. Will this break if I install a 2.x and 3.x version of Python on the same machine?</p>
<p>I want to play with Python 3 while still being able to run 2.x scripts on the same machine.</p>
| [
{
"answer_id": 341218,
"author": "Patrick Desjardins",
"author_id": 13913,
"author_profile": "https://Stackoverflow.com/users/13913",
"pm_score": 5,
"selected": false,
"text": "#!/bin/env python2.7\n #!/bin/env python3.6\n #!c:/Python/python3_6.exe -u\n"
},
{
"answer_id": 436455,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": ":: The @ symbol at the start turns off the prompt from displaying the command.\n:: The % represents an argument, while the * means all of them.\n@c:\\programs\\pythonX.Y\\python.exe %*\n pythonX.Y.bat pythonX.bat copy python2.6.bat python2.bat python2 file.py #!"
},
{
"answer_id": 604714,
"author": "Craig McQueen",
"author_id": 60075,
"author_profile": "https://Stackoverflow.com/users/60075",
"pm_score": 2,
"selected": false,
"text": ".py .pyw .pyc python scriptname.py scriptname.py HKEY_CLASSES_ROOT\\Python.File\\shell\\open\\command\nHKEY_CLASSES_ROOT\\Python.NoConFile\\shell\\open\\command\nHKEY_CLASSES_ROOT\\Python.CompiledFile\\shell\\open\\command\n .py .pyw"
},
{
"answer_id": 762725,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "#\n# Looks for a directive in the form: #! C:\\Python30\\python.exe\n# The directive must start with #! and contain \".exe\".\n# This will be assumed to be the correct python interpreter to\n# use to run the script ON WINDOWS. If no interpreter is\n# found then the script will be run with 'python.exe'.\n# ie: whatever one is found on the path.\n# For example, in a script which is saved as utf-8 and which\n# runs on Linux and Windows and uses the Python 2.6 interpreter...\n#\n# #!/usr/bin/python\n# #!C:\\Python26\\python.exe\n# # -*- coding: utf-8 -*-\n#\n# When run on Linux, Linux uses the /usr/bin/python. When run\n# on Windows using winpylaunch.py it uses C:\\Python26\\python.exe.\n#\n# To set up the association add this to the registry...\n#\n# HKEY_CLASSES_ROOT\\Python.File\\shell\\open\\command\n# (Default) REG_SZ = \"C:\\Python30\\python.exe\" S:\\usr\\bin\\winpylaunch.py \"%1\" %*\n#\n# NOTE: winpylaunch.py itself works with either 2.6 and 3.0. Once\n# this entry has been added python files can be run on the\n# commandline and the use of winpylaunch.py will be transparent.\n#\n\nimport subprocess\nimport sys\n\nUSAGE = \"\"\"\nUSAGE: winpylaunch.py <script.py> [arg1] [arg2...]\n\"\"\"\n\nif __name__ == \"__main__\":\n if len(sys.argv) > 1:\n script = sys.argv[1]\n args = sys.argv[2:]\n if script.endswith(\".py\"):\n interpreter = \"python.exe\" # Default to wherever it is found on the path.\n lines = open(script).readlines()\n for line in lines:\n if line.startswith(\"#!\") and line.find(\".exe\") != -1:\n interpreter = line[2:].strip()\n break\n process = subprocess.Popen([interpreter] + [script] + args)\n process.wait()\n sys.exit()\n print(USAGE)\n"
},
{
"answer_id": 13297878,
"author": "Nick T",
"author_id": 194586,
"author_profile": "https://Stackoverflow.com/users/194586",
"pm_score": 6,
"selected": false,
"text": "py.exe pyw.exe %SYSTEMROOT% C:\\Windows py pyw py -3 mypy2script.py #!C:\\Python33\\python.exe #!python3 #!/usr/bin/env python3 #! notepad.exe"
},
{
"answer_id": 32195996,
"author": "Alistair Martin",
"author_id": 5200859,
"author_profile": "https://Stackoverflow.com/users/5200859",
"pm_score": 6,
"selected": false,
"text": "C:\\Python34 C:\\Python27\\;C:\\Python27\\Scripts\\;C:\\Python34\\;C:\\Python34\\Scripts\\; python python3"
},
{
"answer_id": 42745811,
"author": "Shreyaa Sridhar",
"author_id": 5878581,
"author_profile": "https://Stackoverflow.com/users/5878581",
"pm_score": 1,
"selected": false,
"text": "[ENVIRONMENT]::SETENVIRONMENTVARIABLE(\"PATH\", \"$ENV:PATH;C:\\PYTHONx\", \"USER\")\n python3.6/Scripts/\n pip --version\n pip3 install \n"
},
{
"answer_id": 44009923,
"author": "Cale Sweeney",
"author_id": 2242045,
"author_profile": "https://Stackoverflow.com/users/2242045",
"pm_score": 3,
"selected": false,
"text": "conda create --name snakes python=3\n"
},
{
"answer_id": 46825584,
"author": "Charif DZ",
"author_id": 6089852,
"author_profile": "https://Stackoverflow.com/users/6089852",
"pm_score": 3,
"selected": false,
"text": "python.exe python3.exe python python.exe python3 python3.exe"
},
{
"answer_id": 50731824,
"author": "FearlessFuture",
"author_id": 2482605,
"author_profile": "https://Stackoverflow.com/users/2482605",
"pm_score": 0,
"selected": false,
"text": "py -2.7 py py -3.6 pip2 pip pip pip"
},
{
"answer_id": 58285774,
"author": "Manjeet",
"author_id": 1513779,
"author_profile": "https://Stackoverflow.com/users/1513779",
"pm_score": 4,
"selected": false,
"text": "C:\\Python27;C:\\Python27\\Scripts python2 --version python --version"
},
{
"answer_id": 61849573,
"author": "Mandar Sadye",
"author_id": 6321700,
"author_profile": "https://Stackoverflow.com/users/6321700",
"pm_score": 1,
"selected": false,
"text": ":: This batch file is used to switch between python 2 and 3.\n@ECHO OFF\n\nset /p choice= \"Please enter '27' for python 2.7 , '38' for python 3.8 : \"\n\nIF %choice%==27 (\nsetx PYTHON_ACTIVE %HOME_PYTHON27%\n)\n\nIF %choice%==38 (\nsetx PYTHON_ACTIVE %HOME_PYTHON38%\n)\n\n\nPAUSE\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341184",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4491/"
] |
341,192 | <p>OK - I have an interesting one here. I'm working on a tetris clone (basically to "level-up" my skills). I was trying to refactor my code to get it abstracted the way I wanted it. While it was working just fine before, now I get a segmentation fault before any images can be blitted. I've tried debugging it to no avail.</p>
<p>I have posted my SVN working copy of the project <a href="http://www.andrews.edu/~sajo/downloads/Tetris-clone.tar.gz" rel="nofollow noreferrer">here</a>.</p>
<p>It's just a small project and someone with more knowledge than me and a good debugger will probably figure it out in a snap. The only dependency is <a href="http://www.libsdl.org" rel="nofollow noreferrer">SDL</a>. Kudos to the person that can tell me what I'm doing wrong.</p>
<p>Edit: As far as I can tell, what I have now and what I had before are logically the same, so I wouldn't think that what I have now would cause a segmentation fault. Just run an svn revert on the working copy, recompile and you can see that it was working...</p>
| [
{
"answer_id": 341302,
"author": "UberJumper",
"author_id": 34395,
"author_profile": "https://Stackoverflow.com/users/34395",
"pm_score": 0,
"selected": false,
"text": "display = new Surface();\n display->surface = SDL_SetVideoMode( 800, 600, 32, SDL_HWSURFACE | SDL_DOUBLEBUF );\n"
},
{
"answer_id": 341833,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": true,
"text": " surface = SDL_DisplayFormatAlpha( tempSurface );\n surface = tempSurface;\n}\nSDL_FreeSurface( tempSurface );\n surface = tempSurface;\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341192",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3831/"
] |
341,208 | <p>The catch is this is a .NET 1.0 project and there is no hidden field control...</p>
<p>So this is out of the question:</p>
<pre>
<code>
<asp HiddenField Runat="server" ID="hdn" />
</code>
</pre>
<p>I vaguely remember some type of HtmlHiddenInput class that allowed similar functionality...does anybody know how to do this?</p>
<p>Thanks.</p>
| [
{
"answer_id": 341222,
"author": "Cristian Libardo",
"author_id": 16526,
"author_profile": "https://Stackoverflow.com/users/16526",
"pm_score": 3,
"selected": false,
"text": "<input type=\"hidden\" runat=\"server\" />\n"
},
{
"answer_id": 15241207,
"author": "Nitin Khachane",
"author_id": 2138795,
"author_profile": "https://Stackoverflow.com/users/2138795",
"pm_score": 1,
"selected": false,
"text": "<input type=\"hidden\" Name=\"HiddenControl\" runat=\"server\" /> protected System.Web.UI.HtmlControls.HtmlInputHidden HiddenControl; HiddenControl.value=\"Your value\";"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341208",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1638/"
] |
341,221 | <p>Here is some sample VBA code:</p>
<pre><code>Sub Macro1()
Dim pt As PivotTable
Set pt = ActiveSheet.PivotTables("SomePivotTable")
'Set colOfFields = pt.PivotFields
End Sub
</code></pre>
<p>The third line is incomplete/broken. What is the correct way to get access to collection of all the fields in a PivotTable? I need to be able to loop over them. Actual coding is being done in C# VSTO Project.</p>
| [
{
"answer_id": 341495,
"author": "Patrick Cuff",
"author_id": 7903,
"author_profile": "https://Stackoverflow.com/users/7903",
"pm_score": 3,
"selected": true,
"text": "Sub Macro1()\n Dim pt As PivotTable\n Dim col As PivotFields\n Dim c As PivotField\n\n ' Name of the pivot table comes from right clicking on the pivot table,\n ' Table Options..., Name field.\n Set pt = ActiveSheet.PivotTables(\"PivotTable1\")\n Set col = pt.PivotFields\n For Each c In col\n Debug.Print c.Name\n Next\nEnd Sub\n"
},
{
"answer_id": 341605,
"author": "BuddyJoe",
"author_id": 36590,
"author_profile": "https://Stackoverflow.com/users/36590",
"pm_score": 1,
"selected": false,
"text": "// pvtTable is an Excel.PivotTable set earlier in the code\nExcel.PivotFields pflds = \n (Excel.PivotFields)pvtTable.PivotFields(System.Type.Missing);\n foreach (Excel.PivotField pf in pflds)\n {\n //some code here\n }\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341221",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36590/"
] |
341,232 | <p>In postgres you can do a comparison against multiple items like so:</p>
<pre><code> SELECT 'test' IN ('not','in','here');
</code></pre>
<p>Which is the same as doing:</p>
<pre><code> SELECT ('test' = 'not' OR 'test' = 'in' OR 'test' = 'here');
</code></pre>
<p>Is there a functional equivalent for SQL Server ?</p>
| [
{
"answer_id": 341278,
"author": "Scott Ivey",
"author_id": 36297,
"author_profile": "https://Stackoverflow.com/users/36297",
"pm_score": 0,
"selected": false,
"text": "select case \n when 'test' IN ('not', 'in', 'here') then 1\n else 0\n end;\n"
},
{
"answer_id": 341279,
"author": "xahtep",
"author_id": 42184,
"author_profile": "https://Stackoverflow.com/users/42184",
"pm_score": 4,
"selected": true,
"text": "case select case when 'test' in ('not','in','here') then 1 else 0 end\n\n----------- \n0\n\n(1 row(s) affected)\n where select * from T where C in (1,3,5,7,9)\n"
},
{
"answer_id": 341280,
"author": "Andrew Rollings",
"author_id": 40410,
"author_profile": "https://Stackoverflow.com/users/40410",
"pm_score": 0,
"selected": false,
"text": "SELECT CAST(COUNT(*) AS BIT) as IsItHere WHERE 'test' IN('not','in','here')\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341232",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/43278/"
] |
341,233 | <p>I am trying to implement Autocomplete in a text area (similar to <a href="http://www.pengoworks.com/workshop/jquery/autocomplete.htm" rel="nofollow noreferrer">http://www.pengoworks.com/workshop/jquery/autocomplete.htm</a>).</p>
<p>What I am trying to do is when a user enters a specific set of characters (say insert:) they will get an AJAX filled div with possible selectable matches.</p>
<p>In a regular text box, this is of course simple, but in a text area I need to be able to popup the div in the correct location on the screen based on the cursor.</p>
<p>Can anyone provide any direction?</p>
<p>Thanks,
-M</p>
| [
{
"answer_id": 1028003,
"author": "Popara",
"author_id": 83910,
"author_profile": "https://Stackoverflow.com/users/83910",
"pm_score": 1,
"selected": false,
"text": " function getCursor(nBox){\n var cursorPos = 0;\n if (document.selection){ \n nBox.focus();\n var tmpRange = document.selection.createRange();\n tmpRange.moveStart('character',-nBox.value.length);\n cursorPos = tmpRange.text.length;\n }\n else{\n if (nBox.selectionStart || nBox.selectionStart == '0'){\n cursorPos = nBox.selectionStart;\n }\n }\n\n return cursorPos;\n}\n\nfunction detectLine(nBox,lines){\n var cursorPos = getCursor(nBox);\n var z = 0; //Sum of characters in lines\n var lineNumber = 1;\n for (var i=1; i<=lines.length; i++){\n z = sumLines(i)+i; // +i because cursorPos is taking in account endcharacters of each line.\n if (z >= cursorPos){\n lineNumber = i;\n break;\n }\n }\n\n return lineNumber;\n\n function sumLines(arrayLevel){\n sumLine = 0;\n for (var k=0; k<arrayLevel; k++){\n sumLine += lines[k].length;\n }\n return sumLine;\n }\n}\n\n\n\nfunction detectWord(lineString, area, currentLine, linijeKoda){\n function sumWords(arrayLevel){\n var sumLine = 0;\n for (var k=0; k<arrayLevel; k++){\n sumLine += words[k].length;\n } \n return sumLine;\n }\n\n\n var cursorPos = getCursor(area);\n var sumOfPrevChars =0;\n for (var i=1; i<currentLine; i++){\n sumOfPrevChars += linijeKoda[i].length;\n }\n\n var cursorLinePos = cursorPos - sumOfPrevChars;\n\n var words = lineString.split(\" \");\n var word;\n var y = 0;\n\n\n for(var i=1; i<=words.length; i++){\n y = sumWords(i) + i;\n if(y >= cursorLinePos){\n word = i;\n break;\n }\n }\n\n return word;\n}\n\nvar area = document.getElementById(\"area\");\nvar linijeKoda = area.value.split(\"\\n\");\nvar currentLine = detectLine(area,linijeKoda);\nvar lineString = linijeKoda[currentLine-1];\nvar activeWord = detectWord(lineString, area, currentLine, linijeKoda);\nvar words = lineString.split(\" \");\nif(words.length > 1){\n var possibleString = words[activeWord-1];\n}\nelse{\n var possibleString = words[0];\n}\n"
},
{
"answer_id": 1238296,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "<html>\n<style>\npre.studentCodeColor{\n position:absolute;\n margin:0;\n padding:0;\n border:1px solid blue;\n z-index:2;\n}\ntextarea.studentCode{\n position:relative;\n margin:0; \n padding:0;\n border:1px solid silver; \n z-index:3;\n overflow:visible;\n opacity:0.5;\n filter:alpha(opacity=50);\n}\n</style>\n\nhello world<br/>\nhow are you<br/>\n<pre class=\"studentCodeColor\" id=\"preBehindMyTextarea\">\n</pre>\n<textarea id=\"myTextarea\" class=\"studentCode\" cols=\"100\" rows=\"30\" onkeyup=\"document.selection?ieTaKeyUp():taKeyUp();\">\n</textarea>\n\n<div \n style=\"width:100px;height:60px;position:absolute;border:1px solid red;background-color:yellow\"\n id=\"autoCompleteSelector\"> \nautocomplete contents\n</div>\n\n<script>\nvar myTextarea = document.getElementById('myTextarea');\nvar preBehindMyTextarea = document.getElementById('preBehindMyTextarea');\nvar autoCompleteSelector = document.getElementById('autoCompleteSelector');\n\nfunction ieTaKeyUp(){\n var r = document.selection.createRange();\n autoCompleteSelector.style.top = r.offsetTop;\n autoCompleteSelector.style.left = r.offsetLeft;\n}\nfunction taKeyUp(){\n taSelectionStart = myTextarea.selectionStart; \n preBehindMyTextarea.innerHTML = myTextarea.value.substr(0,taSelectionStart)+'<span id=\"cursorPos\">';\n cp = document.getElementById('cursorPos');\n leftTop = findPos(cp);\n\n autoCompleteSelector.style.top = leftTop[1];\n autoCompleteSelector.style.left = leftTop[0];\n}\nfunction findPos(obj) {\n var curleft = curtop = 0;\n if (obj.offsetParent) {\n do {\n curleft += obj.offsetLeft;\n curtop += obj.offsetTop;\n } while (obj = obj.offsetParent);\n }\n return [curleft,curtop];\n}\n//myTextarea.selectionStart \n</script>\n</html>\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341233",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
341,237 | <p>There's a lot of great information on MSDN dealing with creating Visual Studio templates. I've been specifically working through a Multi-Project Solution (<a href="http://msdn.microsoft.com/en-us/library/ms185308(VS.80,printer).aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/ms185308(VS.80,printer).aspx</a>) </p>
<p>I have everything working in my template (4 projects + 2 Solution Folders - 1 for Tests, and 1 for Libraries that I'm referencing). I have no problem adding projects, or solution folders through the template, but I've hit a wall trying to add dll's and other resources that are not in a specific project, they are just solution level items.</p>
<p>Has anyone dealt with this before? Thanks,</p>
| [
{
"answer_id": 44795874,
"author": "ajawad987",
"author_id": 106397,
"author_profile": "https://Stackoverflow.com/users/106397",
"pm_score": 0,
"selected": false,
"text": "<Link Include=\"..\\_SharedFiles\\GlobalAssemblyInfo.cs\" />\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341237",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13199/"
] |
341,239 | <p>I'm a newbie in the great world of NHibernate. I'm using version 2.0.1.GA. Here's my question. I have a table <code>Cars</code> with column <code>Manufacturer(nvarchar(50))</code> and a primary key <code>ID(int)</code>. My .NET class is:</p>
<pre><code>public class Car
{
public virtual int ID { get; set; }
public virtual string Manufacturer { get; set; }
}
</code></pre>
<p>Now if I want to retrieve all cars made by Mercedes I have to type this:</p>
<pre><code>using (var session = OpenSession())
{
var cars = session
.CreateCriteria(typeof(Car))
.Add(Restrictions.Like("Manufacturer", "Mercedes"))
.List();
// ...
}
</code></pre>
<p>I don't like the fact that I need to specify the property name as a string :(
Is it possible to have something more refactor friendly probably (it's only a suggestion)?</p>
<pre><code>var ms = session
.CreateCriteria<Car>()
.Add(c => c.Manufacturer, Restrictions.Like("Mercedes")
.List();
</code></pre>
<p>Anything like thins in the current version (2.0.1.GA) or in a future version?</p>
| [
{
"answer_id": 341771,
"author": "Bruno Lopes",
"author_id": 42926,
"author_profile": "https://Stackoverflow.com/users/42926",
"pm_score": 4,
"selected": true,
"text": "session.Linq<Car>.Where(c => c.Manufacturer == \"Mercedes\").ToList() session.Query<Car>.Where(c => c.Manufacturer == \"Mercedes\").ToList()"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341239",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42377/"
] |
341,243 | <p>Does anyone know how to get the Video Ram of a PC from a WMI call?</p>
<p>I've seen calls to the Win32_VideoController management object's AdapterRAM property, but that only gives the system memory, and is not representative of the video RAM at all.</p>
| [
{
"answer_id": 341270,
"author": "Dan Esparza",
"author_id": 19020,
"author_profile": "https://Stackoverflow.com/users/19020",
"pm_score": 2,
"selected": false,
"text": "On Error Resume Next\n\nstrComputer = \".\"\nSet objWMIService = GetObject(\"winmgmts:\\\\\" & strComputer & \"\\root\\cimv2\")\n\nSet colItems = objWMIService.ExecQuery _\n (\"Select * from Win32_VideoController\")\n\nFor Each objItem in colItems\n For Each strCapability in objItem.AcceleratorCapabilities\n Wscript.Echo \"Accelerator Capability: \" & strCapability\n Next\n Wscript.Echo \"Adapter Compatibility: \" & objItem.AdapterCompatibility\n Wscript.Echo \"Adapter DAC Type: \" & objItem.AdapterDACType\n Wscript.Echo \"Adapter RAM: \" & objItem.AdapterRAM\n Wscript.Echo \"Availability: \" & objItem.Availability\n Wscript.Echo \"Color Table Entries: \" & objItem.ColorTableEntries\n Wscript.Echo \"Current Bits Per Pixel: \" & objItem.CurrentBitsPerPixel\n Wscript.Echo \"Current Horizontal Resolution: \" & _\n objItem.CurrentHorizontalResolution\n Wscript.Echo \"Current Number of Colors: \" & objItem.CurrentNumberOfColors\n Wscript.Echo \"Current Number of Columns: \" & objItem.CurrentNumberOfColumns\n Wscript.Echo \"Current Number of Rows: \" & objItem.CurrentNumberOfRows\n Wscript.Echo \"Current Refresh Rate: \" & objItem.CurrentRefreshRate\n Wscript.Echo \"Current Scan Mode: \" & objItem.CurrentScanMode\n Wscript.Echo \"Current Vertical Resolution: \" & _\n objItem.CurrentVerticalResolution\n Wscript.Echo \"Description: \" & objItem.Description\n Wscript.Echo \"Device ID: \" & objItem.DeviceID\n Wscript.Echo \"Device Specific Pens: \" & objItem.DeviceSpecificPens\n Wscript.Echo \"Dither Type: \" & objItem.DitherType\n Wscript.Echo \"Driver Date: \" & objItem.DriverDate\n Wscript.Echo \"Driver Version: \" & objItem.DriverVersion\n Wscript.Echo \"ICM Intent: \" & objItem.ICMIntent\n Wscript.Echo \"ICM Method: \" & objItem.ICMMethod\n Wscript.Echo \"INF Filename: \" & objItem.InfFilename\n Wscript.Echo \"INF Section: \" & objItem.InfSection\n Wscript.Echo \"Installed Display Drivers: \" & _\n objItem.InstalledDisplayDrivers\n Wscript.Echo \"Maximum Memory Supported: \" & objItem.MaxMemorySupported\n Wscript.Echo \"Maximum Number Controlled: \" & objItem.MaxNumberControlled\n Wscript.Echo \"Maximum Refresh Rate: \" & objItem.MaxRefreshRate\n Wscript.Echo \"Minimum Refresh Rate: \" & objItem.MinRefreshRate\n Wscript.Echo \"Monochrome: \" & objItem.Monochrome\n Wscript.Echo \"Name: \" & objItem.Name\n Wscript.Echo \"Number of Color Planes: \" & objItem.NumberOfColorPlanes\n Wscript.Echo \"Number of Video Pages: \" & objItem.NumberOfVideoPages\n Wscript.Echo \"PNP Device ID: \" & objItem.PNPDeviceID\n Wscript.Echo \"Reserved System Palette Entries: \" & _\n objItem.ReservedSystemPaletteEntries\n Wscript.Echo \"Specification Version: \" & objItem.SpecificationVersion\n Wscript.Echo \"System Palette Entries: \" & objItem.SystemPaletteEntries\n Wscript.Echo \"Video Architecture: \" & objItem.VideoArchitecture\n Wscript.Echo \"Video Memory Type: \" & objItem.VideoMemoryType\n Wscript.Echo \"Video Mode: \" & objItem.VideoMode\n Wscript.Echo \"Video Mode Description: \" & objItem.VideoModeDescription\n Wscript.Echo \"Video Processor: \" & objItem.VideoProcessor\nNext\n"
},
{
"answer_id": 342549,
"author": "Lee Roth",
"author_id": 43284,
"author_profile": "https://Stackoverflow.com/users/43284",
"pm_score": 4,
"selected": true,
"text": "int _ram = 0;\n\nManagementObjectSearcher searcher = new ManagementObjectSearcher(\"select AdapterRAM from Win32_VideoController\");\n\nforeach (ManagementObject mo in searcher.Get())\n{\n var ram = mo.Properties[\"AdapterRAM\"].Value as UInt32?;\n\n if (ram.HasValue)\n {\n _ram = ((int)ram/1048576);\n }\n}\n"
},
{
"answer_id": 13277619,
"author": "jolly",
"author_id": 915201,
"author_profile": "https://Stackoverflow.com/users/915201",
"pm_score": 1,
"selected": false,
"text": "ManagementObjectSearcher searcher = new ManagementObjectSearcher(\"select AdapterRAM from \n\n Win32_VideoController\");\n\n foreach (ManagementObject mo in searcher.Get())\n { \n\n double MemorySize = Convert.ToDouble(mo.Properties[\"AdapterRAM\"].Value) / 1048576;\n\n return MemorySize.ToString();\n }\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341243",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12497/"
] |
341,256 | <p>I'm having trouble resizing a tableHeaderView. It simple doesn't work.</p>
<p>1) Create a UITableView and UIView (100 x 320 px);</p>
<p>2) Set the UIView as tableHeaderView of the UITableView;</p>
<p>3) Build and Go. Everything is ok.</p>
<p>Now, I want to resizing the tableHeaderView, so I add this code in viewDidLoad:</p>
<pre><code>self.tableView.autoresizesSubviews = YES;
self.tableView.tableHeaderView = myHeaderView;
self.tableView.tableFooterView = myFooterView;
CGRect newFrame = self.tableView.tableHeaderView.frame;
newFrame.size.height = newFrame.size.height + 100;
self.tableView.tableHeaderView.frame = newFrame;
</code></pre>
<p>The height of the tableHeaderView should appear with 200, but appears with 100.</p>
<p>If I write:</p>
<pre><code>self.tableView.autoresizesSubviews = YES;
CGRect newFrame = myHeaderView.frame;
newFrame.size.height = newFrame.size.height + 100;
myHeaderView.frame = newFrame;
self.tableView.tableHeaderView = myHeaderView;
self.tableView.tableFooterView = myFooterView;
</code></pre>
<p>Then it starts with 200 of height, as I want. But I want to be able to modify it in runtime.</p>
<p>I've also tried this, without success:</p>
<pre><code>self.tableView.autoresizesSubviews = YES;
self.tableView.tableHeaderView = myHeaderView;
self.tableView.tableFooterView = myFooterView;
CGRect newFrame = self.tableView.tableHeaderView.frame;
newFrame.size.height = newFrame.size.height + 100;
self.tableView.tableHeaderView.frame = newFrame;
[self.tableView.tableHeaderView setNeedsLayout];
[self.tableView.tableHeaderView setNeedsDisplay];
[self.tableView setNeedsLayout];
[self.tableView setNeedsDisplay];
</code></pre>
<p>The point here is: <strong>How do we resize a tableHeaderView in runtime ???</strong></p>
<p>Have anyone able to do this?</p>
<p>Thanks</p>
<p>iMe</p>
| [
{
"answer_id": 342605,
"author": "codelogic",
"author_id": 43427,
"author_profile": "https://Stackoverflow.com/users/43427",
"pm_score": -1,
"selected": false,
"text": "[self.tableView reloadData]"
},
{
"answer_id": 419115,
"author": "Greg Martin",
"author_id": 50808,
"author_profile": "https://Stackoverflow.com/users/50808",
"pm_score": 3,
"selected": false,
"text": "CGRect newFrame = myHeaderView.frame;\nnewFrame.size.height = newFrame.size.height + 100;\nmyHeaderView.frame = newFrame;\n\nself.tableView.tableHeaderView = myHeaderView;\n"
},
{
"answer_id": 526825,
"author": "kubi",
"author_id": 28422,
"author_profile": "https://Stackoverflow.com/users/28422",
"pm_score": 8,
"selected": false,
"text": "[webView sizeToFit];\nCGRect newFrame = headerView.frame;\nnewFrame.size.height = newFrame.size.height + webView.frame.size.height;\nheaderView.frame = newFrame;\n[self.tableView setTableHeaderView:headerView];\n"
},
{
"answer_id": 2179148,
"author": "garrettmoon",
"author_id": 262648,
"author_profile": "https://Stackoverflow.com/users/262648",
"pm_score": 4,
"selected": false,
"text": "- (void)adjustTableHeaderHeight:(NSUInteger)newHeight{\n NSUInteger oldHeight = self.frame.size.height;\n NSInteger originChange = oldHeight - newHeight;\n\n [UIView beginAnimations:nil context:nil];\n\n [UIView setAnimationDuration:1.0f];\n [UIView setAnimationDelegate:self];\n [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];\n\n self.frame = CGRectMake(self.frame.origin.x, \n self.frame.origin.y, \n self.frame.size.width, \n newHeight);\n\n for (UIView *view in [(UITableView *)self.superview subviews]) {\n if ([view isKindOfClass:[self class]]) {\n continue;\n }\n view.frame = CGRectMake(view.frame.origin.x, \n view.frame.origin.y - originChange, \n view.frame.size.width, \n view.frame.size.height);\n }\n\n [UIView commitAnimations];\n}\n\n- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context{\n [(UITableView *)self.superview setTableHeaderView:self];\n}\n"
},
{
"answer_id": 4359842,
"author": "Harald Schubert",
"author_id": 531311,
"author_profile": "https://Stackoverflow.com/users/531311",
"pm_score": 0,
"selected": false,
"text": " - (id)initWithFrame:(CGRect)aRect {\n\n CGRect frame = [[UIScreen mainScreen] applicationFrame];\n\n if ((self = [super initWithFrame:CGRectZero])) {\n\n // Ugly initialization behavior - initWithFrame will not properly honor the frame we pass\n self.frame = CGRectMake(0, 0, frame.size.width, 200);\n\n // ...\n }\n}\n"
},
{
"answer_id": 15416193,
"author": "Besi",
"author_id": 784318,
"author_profile": "https://Stackoverflow.com/users/784318",
"pm_score": 4,
"selected": false,
"text": "- (void) showHeader:(BOOL)show animated:(BOOL)animated{\n\n CGRect closedFrame = CGRectMake(0, 0, self.view.frame.size.width, 0);\n CGRect newFrame = show?self.initialFrame:closedFrame;\n\n if(animated){\n // The UIView animation block handles the animation of our header view\n [UIView beginAnimations:nil context:nil];\n [UIView setAnimationDuration:0.3];\n [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];\n\n // beginUpdates and endUpdates trigger the animation of our cells\n [self.tableView beginUpdates];\n }\n\n self.headerView.frame = newFrame;\n [self.tableView setTableHeaderView:self.headerView];\n\n if(animated){\n [self.tableView endUpdates];\n [UIView commitAnimations];\n }\n}\n tableHeaderView beginUpdates endUpdates UIView animationCurve UIViewAnimationCurveEaseInOut 0.3 ResizeTableHeaderViewAnimated"
},
{
"answer_id": 18986515,
"author": "Avishay Cohen",
"author_id": 893809,
"author_profile": "https://Stackoverflow.com/users/893809",
"pm_score": 3,
"selected": false,
"text": "- (void)adjustTableHeaderHeight:(NSUInteger)newHeight animated:(BOOL)animated {\n\n [UIView beginAnimations:nil context:nil];\n\n [UIView setAnimationDuration:[CATransaction animationDuration]];\n [UIView setAnimationDelegate:self];\n [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];\n\n self.frame = CGRectMake(self.frame.origin.x,\n self.frame.origin.y,\n self.frame.size.width,\n newHeight);\n\n [(UITableView *)self.superview setTableHeaderView:self];\n\n [UIView commitAnimations];\n}\n\n- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context{\n [(UITableView *)self.superview setTableHeaderView:self];\n}\n"
},
{
"answer_id": 25961159,
"author": "Alexander Volkov",
"author_id": 2022586,
"author_profile": "https://Stackoverflow.com/users/2022586",
"pm_score": 0,
"selected": false,
"text": "// Swift\n@IBAction func tapped(sender: UITapGestureRecognizer) {\n\n self.tableView.beginUpdates() // Required to update cells. \n\n // Collapse table header to original height\n if isHeaderExpandedToFullScreen { \n\n UIView.animateWithDuration(0.5, animations: { () -> Void in\n self.scrollView.frame.size.height = 110 // original height in my case is 110\n })\n\n }\n // Expand table header to overall screen \n else { \n let screenSize = self.view.frame // \"screen\" size\n\n UIView.animateWithDuration(0.5, animations: { () -> Void in\n self.scrollView.frame.size.height = screenSize.height\n })\n }\n\n self.tableView.endUpdates() // Required to update cells. \n\n isHeaderExpandedToFullScreen= !isHeaderExpandedToFullScreen // Toggle\n}\n"
},
{
"answer_id": 27161223,
"author": "Darcy Rayner",
"author_id": 814164,
"author_profile": "https://Stackoverflow.com/users/814164",
"pm_score": 3,
"selected": false,
"text": "[UIView animateWithDuration:0.3 animations:^{\n CGRect oldFrame = self.headerView.frame;\n self.headerView.frame = CGRectMake(oldFrame.origin.x, oldFrame.origin.y, oldFrame.size.width, newHeight);\n [self.tableView setTableHeaderView:self.headerView];\n}];\n"
},
{
"answer_id": 30682805,
"author": "Cameron Lowell Palmer",
"author_id": 410867,
"author_profile": "https://Stackoverflow.com/users/410867",
"pm_score": 0,
"selected": false,
"text": "UITableView UISearchBar UITableView\n |\n |--> UIView\n | |--> UISearchBar\n |\n |--> UITableViewCells\n - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar\n{\n searchBar.showsScopeBar = YES;\n [UIView animateWithDuration:0.2f animations:^{\n [searchBar sizeToFit];\n CGFloat height = CGRectGetHeight(searchBar.frame);\n\n CGRect frame = self.tableView.tableHeaderView.frame;\n frame.size.height = height;\n self.tableHeaderView.frame = frame;\n self.tableView.tableHeaderView = self.tableHeaderView;\n }];\n\n [searchBar setShowsCancelButton:YES animated:YES];\n return YES;\n}\n\n- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar\n{\n searchBar.showsScopeBar = NO;\n [UIView animateWithDuration:0.f animations:^{\n [searchBar sizeToFit];\n\n CGFloat height = CGRectGetHeight(searchBar.frame);\n\n CGRect frame = self.tableView.tableHeaderView.frame;\n frame.size.height = height;\n self.tableHeaderView.frame = frame;\n self.tableView.tableHeaderView = self.tableHeaderView;\n }];\n\n [searchBar setShowsCancelButton:NO animated:YES];\n return YES;\n}\n"
},
{
"answer_id": 37653713,
"author": "Rafat touqir Rafsun",
"author_id": 1575165,
"author_profile": "https://Stackoverflow.com/users/1575165",
"pm_score": 1,
"selected": false,
"text": "//to reload your cell data\nself.tableView.reloadData()\nDispatchQueue.main.async {\n// this is needed to update a specific tableview's headerview layout on main queue otherwise it's won't update perfectly cause reloaddata() is called\n self.tableView.beginUpdates()\n self.tableView.endUpdates()\n}\n"
},
{
"answer_id": 37663540,
"author": "Eneko Alonso",
"author_id": 422288,
"author_profile": "https://Stackoverflow.com/users/422288",
"pm_score": 2,
"selected": false,
"text": "viewDidLoad var frame = headerView.frame\nframe.size.height = 11 // New size\nheaderView.frame = frame\n headerView @IBOutlet var headerView: UIView!"
},
{
"answer_id": 41755288,
"author": "Enix",
"author_id": 2717397,
"author_profile": "https://Stackoverflow.com/users/2717397",
"pm_score": 1,
"selected": false,
"text": "tableView.tableHeaderView viewDidLoad - (void)didMoveToParentViewController:(UIViewController *)parent - (void)didMoveToParentViewController:(UIViewController *)parent {\n [super didMoveToParentViewController:parent];\n\n if ( _tableView.tableHeaderView == nil ) {\n UIView *header = [[[UINib nibWithNibName:@\"your header view\" bundle:nil] instantiateWithOwner:self options:nil] firstObject];\n\n header.frame = CGRectMake(0, 0, CGRectGetWidth([UIScreen mainScreen].bounds), HeaderViewHeight);\n\n [_tableView setTableHeaderView:header];\n }\n}\n"
},
{
"answer_id": 41806588,
"author": "klaudz",
"author_id": 897222,
"author_profile": "https://Stackoverflow.com/users/897222",
"pm_score": 2,
"selected": false,
"text": "tableHeaderView self.tableView.tableHeaderView = self.tableView.tableHeaderView;\n"
},
{
"answer_id": 48035093,
"author": "digitaldaemon",
"author_id": 6700978,
"author_profile": "https://Stackoverflow.com/users/6700978",
"pm_score": 0,
"selected": false,
"text": "CGSize s = [ self systemLayoutSizeFittingSize : UILayoutFittingCompressedSize ];\nCGRect f = [ self frame ];\n\nf.size = s;\n\n[ self setFrame : f ];\n"
},
{
"answer_id": 52533911,
"author": "无夜之星辰",
"author_id": 6144118,
"author_profile": "https://Stackoverflow.com/users/6144118",
"pm_score": 0,
"selected": false,
"text": "[self.webView.scrollView addObserver:self forKeyPath:@\"contentSize\" options:NSKeyValueObservingOptionNew context:nil];\n\n- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {\n self.webView.height = self.webView.scrollView.contentSize.height;\n self.tableView.tableHeaderView = self.webView;\n}\n"
},
{
"answer_id": 53420902,
"author": "Ryan",
"author_id": 1215715,
"author_profile": "https://Stackoverflow.com/users/1215715",
"pm_score": 2,
"selected": false,
"text": "translatesAutoresizingMaskIntoConstraints = false intrinsicContentSize UITableView intrinsicContentSize intrinsicContentSize invalidateIntrinsicContentSize() tableView.setNeedsLayout() tableView.layoutIfNeeded() UITableView UITableView.tableHeaderView .tableFooterView UIStackView arrangedSubviews UIStackView UIView UIView intrinsicContentSize"
},
{
"answer_id": 59082566,
"author": "Hardik Thakkar",
"author_id": 3418556,
"author_profile": "https://Stackoverflow.com/users/3418556",
"pm_score": 2,
"selected": false,
"text": "override func viewDidLayoutSubviews() {\n super.viewDidLayoutSubviews()\n\n guard let headerView = self.tblProfile.tableHeaderView else {\n return\n }\n\n let size = headerView.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize)\n\n if headerView.frame.size.height != size.height {\n headerView.frame.size.height = size.height\n self.tblProfile.tableHeaderView = headerView\n self.tblProfile.layoutIfNeeded()\n }\n }\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341256",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/43282/"
] |
341,258 | <p>I'm trying to use VBA to write a formula into a cell in Excel.
My problem is that when I use a semicolon (<code>;</code>) in my formula, I get an error:</p>
<blockquote>
<p><strong><code>Run-time error 1004</code></strong></p>
</blockquote>
<p>My macro is the following : </p>
<pre><code>Sub Jours_ouvres()
Dim Feuille_Document As String
Feuille_Document = "DOCUMENT"
Application.Worksheets(Feuille_Document).Range("F2").Formula = "=SUM(D2;E2)"
End Sub
</code></pre>
| [
{
"answer_id": 341276,
"author": "e.James",
"author_id": 33686,
"author_profile": "https://Stackoverflow.com/users/33686",
"pm_score": 3,
"selected": false,
"text": ": ;"
},
{
"answer_id": 341286,
"author": "Treb",
"author_id": 22114,
"author_profile": "https://Stackoverflow.com/users/22114",
"pm_score": -1,
"selected": false,
"text": "(...)Formula = \"=SUM(D2,E2)\"\n Range(\"F2\").Formula"
},
{
"answer_id": 352698,
"author": "KnomDeGuerre",
"author_id": 24233,
"author_profile": "https://Stackoverflow.com/users/24233",
"pm_score": 3,
"selected": false,
"text": ", :"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341258",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/43277/"
] |
341,264 | <p>What is the best way to get the Max value from a LINQ query that may return no rows? If I just do</p>
<pre><code>Dim x = (From y In context.MyTable _
Where y.MyField = value _
Select y.MyCounter).Max
</code></pre>
<p>I get an error when the query returns no rows. I could do</p>
<pre><code>Dim x = (From y In context.MyTable _
Where y.MyField = value _
Select y.MyCounter _
Order By MyCounter Descending).FirstOrDefault
</code></pre>
<p>but that feels a little obtuse for such a simple request. Am I missing a better way to do it?</p>
<p>UPDATE: Here's the back story: I'm trying to retrieve the next eligibility counter from a child table (legacy system, don't get me started...). The first eligibility row for each patient is always 1, the second is 2, etc. (obviously this is not the primary key of the child table). So, I'm selecting the max existing counter value for a patient, and then adding 1 to it to create a new row. When there are no existing child values, I need the query to return 0 (so adding 1 will give me a counter value of 1). Note that I don't want to rely on the raw count of child rows, in case the legacy app introduces gaps in the counter values (possible). My bad for trying to make the question too generic.</p>
| [
{
"answer_id": 341313,
"author": "David Schmitt",
"author_id": 4918,
"author_profile": "https://Stackoverflow.com/users/4918",
"pm_score": 5,
"selected": false,
"text": "Double.MinValue Max Concat FirstOrDefault Take(1) double x = context.MyTable\n .Where(y => y.MyField == value)\n .Select(y => y.MyCounter)\n .Concat(new double[]{Double.MinValue})\n .Max();\n"
},
{
"answer_id": 341560,
"author": "Jacob Proffitt",
"author_id": 1336,
"author_profile": "https://Stackoverflow.com/users/1336",
"pm_score": 6,
"selected": false,
"text": "DefaultIfEmpty Dim x = (From y In context.MyTable _\n Where y.MyField = value _\n Select y.MyCounter).DefaultIfEmpty.Max\n"
},
{
"answer_id": 341570,
"author": "Rex Miller",
"author_id": 4296,
"author_profile": "https://Stackoverflow.com/users/4296",
"pm_score": 3,
"selected": false,
"text": "from y in context.MyTable\ngroup y.MyCounter by y.MyField into GrpByMyField\nwhere GrpByMyField.Key == value\nselect GrpByMyField.Max()\n SELECT [t1].[MaxValue]\nFROM (\n SELECT MAX([t0].[MyCounter) AS [MaxValue], [t0].[MyField]\n FROM [MyTable] AS [t0]\n GROUP BY [t0].[MyField]\n ) AS [t1]\nWHERE [t1].[MyField] = @p0\n"
},
{
"answer_id": 341716,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 3,
"selected": false,
"text": "Try\n Dim x = (From y In context.MyTable _\n Where y.MyField = value _\n Select y.MyCounter).Max\n ... continue working with x ...\nCatch ex As SqlException\n ... do error processing ...\nEnd Try\n"
},
{
"answer_id": 342246,
"author": "Jacob Proffitt",
"author_id": 1336,
"author_profile": "https://Stackoverflow.com/users/1336",
"pm_score": 9,
"selected": true,
"text": "DefaultIfEmpty Dim x = (From y In context.MyTable _\n Where y.MyField = value _\n Select CType(y.MyCounter, Integer?)).Max\n var x = (from y in context.MyTable\n where y.MyField == value\n select (int?)y.MyCounter).Max();\n"
},
{
"answer_id": 1200211,
"author": "Dom Ribaut",
"author_id": 147110,
"author_profile": "https://Stackoverflow.com/users/147110",
"pm_score": 3,
"selected": false,
"text": "(From y In context.MyTable _\n Where y.MyField = value _\n Select y.MyCounter)\n var max = new[]{0}\n .Concat((From y In context.MyTable _\n Where y.MyField = value _\n Select y.MyCounter))\n .Max();\n"
},
{
"answer_id": 2380740,
"author": "Nix",
"author_id": 256793,
"author_profile": "https://Stackoverflow.com/users/256793",
"pm_score": 1,
"selected": false,
"text": "var max = new[]{0}\n .Concat((From y In context.MyTable _\n Where y.MyField = value _\n Select y.MyCounter))\n .Max();\n (From y In context.MyTable _\n Where y.MyField = value _\n Select y.MyCounter))\n .OrderByDescending(x=>x).FirstOrDefault());\n FirstOrDefault"
},
{
"answer_id": 2593092,
"author": "Eddie Deyo",
"author_id": 9323,
"author_profile": "https://Stackoverflow.com/users/9323",
"pm_score": 7,
"selected": false,
"text": "int max = list.Max(i => (int?)i.MyCounter) ?? 0;\n"
},
{
"answer_id": 5870709,
"author": "legal",
"author_id": 736285,
"author_profile": "https://Stackoverflow.com/users/736285",
"pm_score": 2,
"selected": false,
"text": "Dim x = context.MyTable.Max(Function(DataItem) DataItem.MyField = Value)\n"
},
{
"answer_id": 8738890,
"author": "jong su.",
"author_id": 1131546,
"author_profile": "https://Stackoverflow.com/users/1131546",
"pm_score": 1,
"selected": false,
"text": "decimal Max = (decimal?)(context.MyTable.Select(e => e.MyCounter).Max()) ?? 0;\n"
},
{
"answer_id": 14747930,
"author": "beastieboy",
"author_id": 2615413,
"author_profile": "https://Stackoverflow.com/users/2615413",
"pm_score": 4,
"selected": false,
"text": "int max = list.Any() ? list.Max(i => i.MyCounter) : 0;\n"
},
{
"answer_id": 17613739,
"author": "Seb",
"author_id": 758940,
"author_profile": "https://Stackoverflow.com/users/758940",
"pm_score": -1,
"selected": false,
"text": "var requiredDataQuery = _dataRepo.Select(x => new { x.NullableDate1, .NullableDate2 }); \nvar requiredData.ToList();\nvar maxDate1 = dates.Max(x => x.NullableDate1);\nvar maxDate2 = dates.Max(x => x.NullableDate2);\n"
},
{
"answer_id": 27824792,
"author": "Fernando Brustolin",
"author_id": 1178385,
"author_profile": "https://Stackoverflow.com/users/1178385",
"pm_score": 4,
"selected": false,
"text": "int max = (from e in context.Table where e.Year == year select e.RecordNumber).DefaultIfEmpty(0).Max();\nDateTime maxDate = (from e in context.Table where e.Year == year select e.StartDate ?? DateTime.MinValue).DefaultIfEmpty(DateTime.MinValue).Max();\n"
},
{
"answer_id": 33018483,
"author": "Stephen Kennedy",
"author_id": 397817,
"author_profile": "https://Stackoverflow.com/users/397817",
"pm_score": 1,
"selected": false,
"text": "MaxOrDefault Max public static TResult MaxOrDefault<TSource, TResult>(this \n IQueryable<TSource> source, Expression<Func<TSource, TResult?>> selector,\n TResult defaultValue = default (TResult)) where TResult : struct\n {\n return source.Max(selector) ?? defaultValue;\n }\n"
},
{
"answer_id": 37708738,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "Expression IQueryable<T>.Max(...) static class Extensions\n{\n public static TResult MaxOrDefault<T, TResult>(this IQueryable<T> source, \n Expression<Func<T, TResult>> selector)\n where TResult : struct\n {\n UnaryExpression castedBody = Expression.Convert(selector.Body, typeof(TResult?));\n Expression<Func<T, TResult?>> lambda = Expression.Lambda<Func<T,TResult?>>(castedBody, selector.Parameters);\n return source.Max(lambda) ?? default(TResult);\n }\n}\n int maxId = dbContextInstance.Employees.MaxOrDefault(employee => employee.Id);\n// maxId is equal to 0 if there is no records in Employees table\n IQueryable<T>.Max(...)"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341264",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23935/"
] |
341,271 | <p>My previous job involved maintenance and programming for a very large database with massive amounts of data. Users viewed this data primarily through an intranet web interface. Instead of having a table of user accounts, each user account was a real first-class account in the RDBMS, which permitted them to connect with their own query tools, etc., as well as permitting us to control access through the RDBMS itself instead of using our own application logic.</p>
<p>Is this a good setup, assuming you're not on the public intranet and dealing with potentially millions of (potentially malicious) users or something? Or is it always better to define your own means of handling user accounts, your own permissions, your own application security logic, and only hand out RDBMS accounts to power users with special needs?</p>
| [
{
"answer_id": 33647108,
"author": "H S Raju",
"author_id": 2963452,
"author_profile": "https://Stackoverflow.com/users/2963452",
"pm_score": 1,
"selected": false,
"text": "Manager_Role_Account Manager_Role_Account Manager_Role_Account"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341271",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18103/"
] |
341,273 | <p>I can read the <em>MySQL</em> documentation and it's pretty clear. But, how does one decide which character set to use? On what data does collation have an effect?</p>
<p>I'm asking for an explanation of the two and how to choose them.</p>
| [
{
"answer_id": 341352,
"author": "mat",
"author_id": 42083,
"author_profile": "https://Stackoverflow.com/users/42083",
"pm_score": 8,
"selected": false,
"text": "e é è ê f e f é ê è e é è ê f"
},
{
"answer_id": 42625088,
"author": "simhumileco",
"author_id": 4217744,
"author_profile": "https://Stackoverflow.com/users/4217744",
"pm_score": 2,
"selected": false,
"text": "utf8mb4_unicode_ci"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341273",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2172/"
] |
341,274 | <p>We are upgrading our servers to SQL Server 2005 from SQL Server 2000. We currently use the jtds drivers.</p>
<p>I'm interested to know what peoples opinions are of the different jdbc drivers available (in particular the latest Microsoft driver), how they perform with SQL Server 2005 and any other lessons from your collective experience.</p>
| [
{
"answer_id": 927623,
"author": "Rohit Agarwal",
"author_id": 108955,
"author_profile": "https://Stackoverflow.com/users/108955",
"pm_score": 0,
"selected": false,
"text": "declare @P1 int\nset @P1=1\nexec sp_prepexec @P1 output, N'@P0 int', N'EXEC getEmployeeManagers @P0', 50\nselect @P1\n sp_prepexec sp_unprepare exec getEmployeeManagers @P0=50\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341274",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42491/"
] |
341,282 | <p>I'm trying to create a function which takes an array as an argument, adds values to it (increasing its size if necessary) and returns the count of items.
So far I have:</p>
<pre><code>int main(int argc, char** argv) {
int mSize = 10;
ent a[mSize];
int n;
n = addValues(a,mSize);
for(i=0;i<n;i++) {
//Print values from a
}
}
int addValues(ent *a, int mSize) {
int size = mSize;
i = 0;
while(....) { //Loop to add items to array
if(i>=size-1) {
size = size*2;
a = realloc(a, (size)*sizeof(ent));
}
//Add to array
i++;
}
return i;
}
</code></pre>
<p>This works if mSize is large enough to hold all the potential elements of the array, but if it needs resizing, I get a Segmentation Fault.</p>
<p>I have also tried:</p>
<pre><code>int main(int argc, char** argv) {
...
ent *a;
...
}
int addValues(ent *a, int mSize) {
...
a = calloc(1, sizeof(ent);
//usual loop
...
}
</code></pre>
<p>To no avail.</p>
<p>I assume this is because when I call realloc, the copy of 'a' is pointed elsewhere - how is it possible to modify this so that 'a' always points to the same location?</p>
<p>Am I going about this correctly? Are there better ways to deal with dynamic structures in C? Should I be implementing a linked list to deal with these?</p>
| [
{
"answer_id": 341293,
"author": "xahtep",
"author_id": 42184,
"author_profile": "https://Stackoverflow.com/users/42184",
"pm_score": 3,
"selected": false,
"text": "ent **a"
},
{
"answer_id": 341294,
"author": "Todd Gamblin",
"author_id": 9122,
"author_profile": "https://Stackoverflow.com/users/9122",
"pm_score": 5,
"selected": true,
"text": "ent a[mSize];\n ent *a = (ent*)malloc(mSize * sizeof(ent));\n typedef struct dynarray {\n elt *data;\n int size;\n} dynarray;\n // malloc a dynarray and its data and returns a pointer to the dynarray \ndynarray *dynarray_create(); \n\n// add an element to dynarray and adjust its size if necessary\nvoid dynarray_add_elt(dynarray *arr, elt value);\n\n// return a particular element in the dynarray\nelt dynarray_get_elt(dynarray *arr, int index);\n\n// free the dynarray and its data.\nvoid dynarray_free(dynarray *arr);\n"
},
{
"answer_id": 341308,
"author": "Skizz",
"author_id": 1898,
"author_profile": "https://Stackoverflow.com/users/1898",
"pm_score": 1,
"selected": false,
"text": "int main(int argc, char** argv) {\n ...\n ent *a; // This...\n ...\n}\n\nint addValues(ent *a, int mSize) {\n ...\n a = calloc(1, sizeof(ent); // ...is not the same as this\n //usual loop\n ...\n}\n addValues addValues addValues int addValues (int **a, int mSize)\n int main(int argc, char** argv) {\n ...\n ent *a; // This...\n ...\n addValues (&a, mSize);\n}\n addValues (*a)[element]\n (*a) = calloc (...);\n"
},
{
"answer_id": 342056,
"author": "ctuffli",
"author_id": 26683,
"author_profile": "https://Stackoverflow.com/users/26683",
"pm_score": 1,
"selected": false,
"text": "ent *a = NULL;\n int addValues(ent **a, int mSize)\n while(....) { //Loop to add items to array\n tmp = realloc(*a, size*sizeof(ent));\n if (tmp) {\n *a = tmp;\n } else {\n // allocation failed. either free *a or keep *a and\n // return an error\n }\n //Add to array\n i++;\n}\n size = size * 2;\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341282",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23746/"
] |
341,303 | <p>All this originated from me poking at a compiler warning message (C4267) when attempting the following line:</p>
<pre><code>const unsigned int nSize = m_vecSomeVec.size();
</code></pre>
<p><code>size()</code> returns a size_t which although typedef'd to unsigned int, is not actually a unsigned int. This I believe have to do with 64 bit portability issues, however can someone explain it a bit better for me? ( I don't just want to disable 64bit warnings.)</p>
| [
{
"answer_id": 341341,
"author": "unwind",
"author_id": 28169,
"author_profile": "https://Stackoverflow.com/users/28169",
"pm_score": 2,
"selected": false,
"text": "size_t unsigned int unsigned int unsigned int"
},
{
"answer_id": 341344,
"author": "James Hopkin",
"author_id": 11828,
"author_profile": "https://Stackoverflow.com/users/11828",
"pm_score": 2,
"selected": false,
"text": "size_t size_t int size_t __w64 __w64 unsigned int"
},
{
"answer_id": 341349,
"author": "MSN",
"author_id": 6210,
"author_profile": "https://Stackoverflow.com/users/6210",
"pm_score": 1,
"selected": false,
"text": "int"
},
{
"answer_id": 341383,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 4,
"selected": true,
"text": "std::size_t const std::vector<T>::size_type nSize = m_vecSomeVec.size();\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341303",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18664/"
] |
341,310 | <p>Is it possible to get a list of all files modified/added/deleted by a particular user?</p>
<p>The goal is to get an idea of what a user did for the day (or date range).</p>
| [
{
"answer_id": 341457,
"author": "shek",
"author_id": 40618,
"author_profile": "https://Stackoverflow.com/users/40618",
"pm_score": 7,
"selected": true,
"text": "svn log | sed -n '/blankman/,/-----$/ p'\n"
},
{
"answer_id": 4439780,
"author": "l0b0",
"author_id": 96588,
"author_profile": "https://Stackoverflow.com/users/96588",
"pm_score": 0,
"selected": false,
"text": "#!/bin/bash\n# @param $1: Start revision\n# @param $2: End revision\n# @param $3: User\n#\n# Example: svn_scapegoat.sh 1000:HEAD jdoe\n\nsvn_changed()\n{\n svn blame --revision $1:$2 -- $4 | grep -E \"^ [0-9]* *${3} \"\n}\n\nsvn diff --revision $1:$2 --summarize | \\\ncut -c9- | \\\nwhile read path\ndo\n if [ -n \"$(svn_changed $1 $2 $3 $path)\" ]\n then\n echo \"$3 changed $path\"\n else\n echo \"Someone else changed $path\"\n fi\ndone\n"
},
{
"answer_id": 7070784,
"author": "user890155",
"author_id": 890155,
"author_profile": "https://Stackoverflow.com/users/890155",
"pm_score": 3,
"selected": false,
"text": "svn log | sed -n '/ | blankman | /,/-----$/ p'\n"
},
{
"answer_id": 12039917,
"author": "Tadej Mali",
"author_id": 1010666,
"author_profile": "https://Stackoverflow.com/users/1010666",
"pm_score": 2,
"selected": false,
"text": "svn log -v -r{2012-08-01}:HEAD \n| awk '/^r[0-9]+ / {user=$3} /./ {if (user==\"username\") {print}}'\n| grep -E \"^ M|^ G|^ A|^ D|^ C|^ U\" \n| awk '{print $2}'\n| sort | uniq\n"
},
{
"answer_id": 16842367,
"author": "Brad Parks",
"author_id": 26510,
"author_profile": "https://Stackoverflow.com/users/26510",
"pm_score": 2,
"selected": false,
"text": "svn log | grep YOUR_USERNAME_HERE | awk '{print $1}' | sed s/r//g | xargs -I $ svn diff --summarize -c $ | sort | uniq\n"
},
{
"answer_id": 20398202,
"author": "bahrep",
"author_id": 761095,
"author_profile": "https://Stackoverflow.com/users/761095",
"pm_score": 4,
"selected": false,
"text": "grep sed --search svn log svn:author svn:date svn:log svn log"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341310",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39677/"
] |
341,315 | <p>I tried to make the title as clear as possible... here is my scenario:</p>
<p>I have 2 tables (let's call them table A and table B) that have a similar schema. I would like write a stored procedure that would select specific columns of data out of table A, and insert this data as a new record in table B.</p>
<p>Can someone point me in the write direction to make such a query? I am unsure how to "Hold" the values from the first query, so that I may then perform the insert.</p>
<p>I am trying to avoid making a query, processing it with C# and then making another query...</p>
<p>Thanks.</p>
| [
{
"answer_id": 341323,
"author": "John Stauffer",
"author_id": 5874,
"author_profile": "https://Stackoverflow.com/users/5874",
"pm_score": 2,
"selected": false,
"text": "Insert into tableB (col1, col2, col3) select col1, col2, col3 from tableA where ...\n"
},
{
"answer_id": 341324,
"author": "Keith Walton",
"author_id": 22448,
"author_profile": "https://Stackoverflow.com/users/22448",
"pm_score": 4,
"selected": true,
"text": "INSERT INTO B (Col1, Col2) SELECT Col1, Col2 FROM A\n"
},
{
"answer_id": 341336,
"author": "Jared",
"author_id": 1980,
"author_profile": "https://Stackoverflow.com/users/1980",
"pm_score": 0,
"selected": false,
"text": "SELECT\n [Col1],\n [COl2]\nINTO TableA\nFROM TableB\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341315",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1638/"
] |
341,338 | <p>How do you make a field in a sql select statement all upper or lower case?</p>
<p>Example:</p>
<p>select firstname from Person</p>
<p>How do I make firstname always return upper case and likewise always return lower case?</p>
| [
{
"answer_id": 341342,
"author": "Stephen Wrighton",
"author_id": 7516,
"author_profile": "https://Stackoverflow.com/users/7516",
"pm_score": 4,
"selected": false,
"text": "SELECT UCASE(MyColumn) AS Upper, LCASE(MyColumn) AS Lower\nFROM MyTable\n"
},
{
"answer_id": 341346,
"author": "Cirieno",
"author_id": 17615,
"author_profile": "https://Stackoverflow.com/users/17615",
"pm_score": 3,
"selected": false,
"text": "print upper('hello');\nprint lower('HELLO');\n"
},
{
"answer_id": 341356,
"author": "Jared",
"author_id": 1980,
"author_profile": "https://Stackoverflow.com/users/1980",
"pm_score": 8,
"selected": true,
"text": "SELECT UPPER(firstname) FROM Person\n\nSELECT LOWER(firstname) FROM Person\n"
},
{
"answer_id": 31282838,
"author": "Xyed Xain Haider",
"author_id": 4571990,
"author_profile": "https://Stackoverflow.com/users/4571990",
"pm_score": 0,
"selected": false,
"text": "SELECT lower(FIRST NAME) ABC\nFROM PERSON\n ABC"
},
{
"answer_id": 38939912,
"author": "Muhammad Awais",
"author_id": 3901944,
"author_profile": "https://Stackoverflow.com/users/3901944",
"pm_score": 2,
"selected": false,
"text": "LOWER function UPPER function SELECT LOWER('THIS IS TEST STRING')\n this is test string\n SELECT UPPER('this is test string')\n THIS IS TEST STRING\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341338",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6232/"
] |
341,347 | <p>How do I grab the controls inside of a UserControl tag?</p>
<p>So if this is on a Page:</p>
<pre><code><ME:NewControl ID="tblCustomList" runat="server">
// ... these controls will be used in my UserControl.aspx
</ME:NewControl>
</code></pre>
<p>How do I access those controls in my UserControl?</p>
<p>For instance, the Table class does this:</p>
<pre><code><asp:Table ID="tblNormal" runat="server">
<asp:TableRow>
<asp:TableCell>Thing 1</asp:TableCell>
<asp:TableCell>Thing 2</asp:TableCell>
</asp:TableRow>
</asp:Table>
</code></pre>
<p>I get an error saying my UserControl "does not have a public property named 'TableRow', when I do this:</p>
<pre><code><ME:NewControl ID="tblCustomList" runat="server">
<asp:TableRow>
<asp:TableCell>Thing 1</asp:TableCell>
<asp:TableCell>Thing 2</asp:TableCell>
</asp:TableRow>
</ME:NewControl>
</code></pre>
<p>I found <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.table.createcontrolcollection.aspx" rel="nofollow noreferrer">this sample</a> to help extend the Table class, but it's not <em>exactly</em> what I want to do.</p>
<p>I also found <a href="http://msdn.microsoft.com/en-us/library/36574bf6.aspx" rel="nofollow noreferrer">this description</a> of how to use Templated Controls, which I'm not sure if I can use.</p>
| [
{
"answer_id": 344815,
"author": "Gavin Miller",
"author_id": 33226,
"author_profile": "https://Stackoverflow.com/users/33226",
"pm_score": 0,
"selected": false,
"text": "using System.Web;\nusing System.Web.UI;\nusing System.Web.UI.WebControls;\nusing System.Security.Permissions;\n\nnamespace Samples.AspNet.CS.Controls\n{\n [AspNetHostingPermission(SecurityAction.Demand, \n Level = AspNetHostingPermissionLevel.Minimal)]\n public sealed class CustomTableCreateControlCollection : Table\n {\n protected override ControlCollection CreateControlCollection()\n {\n // Return a new ControlCollection\n return new ControlCollection(this);\n }\n }\n}\n"
},
{
"answer_id": 344978,
"author": "Jon Smock",
"author_id": 25538,
"author_profile": "https://Stackoverflow.com/users/25538",
"pm_score": 1,
"selected": false,
"text": "public TableRow DTHeader { get; set; }\n\nprotected override void OnInit(EventArgs e)\n{\n tblCollection.Rows.Add(DTHeader);\n base.OnInit(e);\n}\n <ME:NewControl ID=\"tblCustomList\" runat=\"server\">\n <DTHeader>\n <asp:TableCell></asp:TableCell>\n //...\n </DTHeader>\n</ME:NewControl>\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341347",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25538/"
] |
341,348 | <p>I have a DSL Tools solution.</p>
<p>I need to add a weak-named reference to this project.
Because the DSL Tools project DLL is strong-named i cannot used the weak-named DLL.</p>
<p>I cannot make the DLL strong-named because i cannot recompile it.</p>
<p>I tried to make my DSL Tools project DLL weak-named by going to the Dsl and DslPackage project properties and unchecked the option "Sign the assembly" in the Sigining tab.</p>
<p>Then i compile it.
The error list gives the following error</p>
<pre><code>"gacutil.exe" exited with code 1
</code></pre>
<p>Looking at the VS2005 output window i see gacutil is being called </p>
<pre><code>C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\bin\gacutil.exe -nologo -i "C:\Academy\ResearchAndDevelopment\FrontendGenerator\DslPackage\bin\Debug\vantyx.FEGenerator.DslPackage.dll"
</code></pre>
<p>After that i used the command prompt and the gacutil.exe error displays as this:</p>
<pre><code>Z:\>"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\bin\gacutil.exe" -nologo -i "C:\Academy\ResearchAndDevelopment\FrontendGenerator\DslPackage\bin\Debug\vantyx.FEGenerator.DslPackage.dll"
Failure adding assembly to the cache: Attempt to install an assembly without a strong name
</code></pre>
<p>I don't know why and how gacutil.exe is being called.
I looked at the project and solution properties and there is no option configured to call gacutil.exe.
I even looked inside every file for "gacutil.exe" but i found nothing.</p>
<p>What i really want is to be able to use the weak-named DLL that i cannot make strong-named.
As a result of this, i've been trying to make my DSL Tools DLL weak-named but i can't.</p>
<p>Any help on how i can workaround this?</p>
<p>Many thanks in advance,
Luís Filipe </p>
| [
{
"answer_id": 344815,
"author": "Gavin Miller",
"author_id": 33226,
"author_profile": "https://Stackoverflow.com/users/33226",
"pm_score": 0,
"selected": false,
"text": "using System.Web;\nusing System.Web.UI;\nusing System.Web.UI.WebControls;\nusing System.Security.Permissions;\n\nnamespace Samples.AspNet.CS.Controls\n{\n [AspNetHostingPermission(SecurityAction.Demand, \n Level = AspNetHostingPermissionLevel.Minimal)]\n public sealed class CustomTableCreateControlCollection : Table\n {\n protected override ControlCollection CreateControlCollection()\n {\n // Return a new ControlCollection\n return new ControlCollection(this);\n }\n }\n}\n"
},
{
"answer_id": 344978,
"author": "Jon Smock",
"author_id": 25538,
"author_profile": "https://Stackoverflow.com/users/25538",
"pm_score": 1,
"selected": false,
"text": "public TableRow DTHeader { get; set; }\n\nprotected override void OnInit(EventArgs e)\n{\n tblCollection.Rows.Add(DTHeader);\n base.OnInit(e);\n}\n <ME:NewControl ID=\"tblCustomList\" runat=\"server\">\n <DTHeader>\n <asp:TableCell></asp:TableCell>\n //...\n </DTHeader>\n</ME:NewControl>\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341348",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20335/"
] |
341,370 | <p>It seems it is general accepted that exception specifications are not helping as much as one thinks. But I wonder if a specification which only uses std::exception might be a good compromise:</p>
<pre><code>void someFunction()
throw ( std::exception );
</code></pre>
<ul>
<li><p>It documents the fact that this method/function might throw an exception.</p></li>
<li><p>It would make sure that only exceptions derived from std::exception are thrown and not some exotic classes like std::string or int.</p></li>
</ul>
<p>So, would this be better then not having any specification at all?</p>
<p><strong>Update:</strong></p>
<p>Regarding the Runtime-Overhead: Think of it like the usage of asserts. You are using asserts regardless of the runtime-overhead, right? I know you usually can disable them for a release-build, so maybe a better approach would be to wrap the exception specification in a macro so you can disable it for a release build. Something like:</p>
<pre><code>#ifdef DEBUG
#define THROW( exception ) throw ( exception )
#else
#define THROW( exception )
#endif
void someFunction()
THROW( std::exception );
</code></pre>
| [
{
"answer_id": 341388,
"author": "James Hopkin",
"author_id": 11828,
"author_profile": "https://Stackoverflow.com/users/11828",
"pm_score": 2,
"selected": false,
"text": "someFunction std::exception std::unexpected"
},
{
"answer_id": 343223,
"author": "Paolo Tedesco",
"author_id": 15622,
"author_profile": "https://Stackoverflow.com/users/15622",
"pm_score": 1,
"selected": false,
"text": "void someFunction() /* throw (std::exception) */;\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341370",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
341,372 | <p>I've heard powershell 2.0 CTP has modules, but I can't find much example code or instructions. I've read what little help there seems to be online...</p>
<p>But I just keep getting "The term 'Add-Module' is not recognized as a cmdlet..." when I try and load a module.</p>
<p>Any help would be gratefully received!</p>
<p><strong><em>Edit</em></strong> (July 2010)
Please note this question is based on powershell 2.0 CTP and is therefore a year and half out of date! Please see Samuel Jack's answer for help with the powershell 2.0 RTM.</p>
| [
{
"answer_id": 3264564,
"author": "Samuel Jack",
"author_id": 1727,
"author_profile": "https://Stackoverflow.com/users/1727",
"pm_score": 2,
"selected": false,
"text": "Export-ModuleMember -Function * -Alias * Import-Module MyModule Set-ExecutionPolicy Unrestricted"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341372",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32055/"
] |
341,373 | <p>I need to prompt an alert message when a user selects a particular option in a select menu. Is there a way to do this using jQuery?</p>
| [
{
"answer_id": 341398,
"author": "Neil Aitken",
"author_id": 13803,
"author_profile": "https://Stackoverflow.com/users/13803",
"pm_score": 3,
"selected": true,
"text": "$(\"#myselect\").change(function() {\n if($(this).val() == \"myval\")\n {\n alert('message');\n }\n});\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341373",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6050/"
] |
341,377 | <p>Did you know that :</p>
<pre><code>Map<Object,Object> m1 = new HashMap<Object, Object>();
Map<Object,Object> m2 = new HashMap<Object, Object>();
System.out.println("m1.equals(m2) = "+m1.equals(m2));
System.out.println("m1.keySet().equals(m2.keySet()) = "
+m1.keySet().equals(m2.keySet()));
System.out.println("m1.entrySet().equals(m2.entrySet()) = "
+m1.entrySet().equals(m2.entrySet()));
System.out.println("m1.values().equals(m2.values()) = "
+m1.values().equals(m2.values()));
</code></pre>
<p>would output :</p>
<pre><code>m1.equals(m2) = true
m1.keySet().equals(m2.keySet()) = true
m1.entrySet().equals(m2.entrySet()) = true
m1.values().equals(m2.values()) = false
</code></pre>
<p>This is caused by the fact that <code>AbstractCollection</code> (which <code>HashMap$Values</code> inherits from) does not overrides <code>#equals()</code>.</p>
<p>Do you have an idea why this is so ?</p>
| [
{
"answer_id": 341436,
"author": "Greg Case",
"author_id": 462,
"author_profile": "https://Stackoverflow.com/users/462",
"pm_score": 4,
"selected": true,
"text": "Collection#equals() Collection AbstractCollection HashMap$Values equals()"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341377",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7198/"
] |
341,379 | <p>As an example:</p>
<pre><code>def get_booking(f=None):
print "Calling get_booking Decorator"
def wrapper(request, **kwargs):
booking = _get_booking_from_session(request)
if booking == None:
# we don't have a booking in our session.
return HttpRedirect('/')
else:
return f(request=request, booking=booking, **kwargs)
return wrapper
@get_booking
def do_stuff(request, booking):
# do stuff here
</code></pre>
<p>The problem I am having is, the <code>@get_booking decorator</code> is being called even before I called the function that I am decorating.</p>
<p>Output on start:</p>
<pre class="lang-none prettyprint-override"><code>Calling get_booking Decorator
Calling get_booking Decorator
Calling get_booking Decorator
Calling get_booking Decorator
Calling get_booking Decorator
Calling get_booking Decorator
Calling get_booking Decorator
Calling get_booking Decorator
Calling get_booking Decorator
Calling get_booking Decorator
[26/Oct/2008 19:54:04] "GET /onlinebooking/?id=1,2 HTTP/1.1" 302 0
[26/Oct/2008 19:54:05] "GET /onlinebooking/ HTTP/1.1" 200 2300
[26/Oct/2008 19:54:05] "GET /site-media/css/style.css HTTP/1.1" 200 800
[26/Oct/2008 19:54:05] "GET /site-media/css/jquery-ui-themeroller.css HTTP/1.1" 200 25492
</code></pre>
<p>I haven't even made a call to a function that is decorated at this point.</p>
<p>I am just getting started with decorators, so maybe I am missing something.</p>
| [
{
"answer_id": 341389,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 6,
"selected": true,
"text": "@foo\ndef bar ():\n pass\n def bar ():\n pass\nbar = foo(bar)\n"
},
{
"answer_id": 341391,
"author": "David Schmitt",
"author_id": 4918,
"author_profile": "https://Stackoverflow.com/users/4918",
"pm_score": 0,
"selected": false,
"text": "def __do_stuff(...):\n ...\n\ndo_stuff = get_booking(__do_stuff)\n"
},
{
"answer_id": 341406,
"author": "Piotr Lesnicki",
"author_id": 38796,
"author_profile": "https://Stackoverflow.com/users/38796",
"pm_score": 0,
"selected": false,
"text": "@my_decorator\ndef function (): ...\n def function():...\nfunction = my_decorator(function)\n def get_booking(f=None):\n def wrapper(request, **kwargs):\n print \"Calling get_booking Decorator\"\n booking = _get_booking_from_session(request)\n if booking == None:\n # we don't have a booking in our session.\n return HttpRedirect('/')\n else:\n return f(request=request, booking=booking, **kwargs)\n return wrapper\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341379",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22306/"
] |
341,384 | <p>I need to add some intervals and use the result in Excel. </p>
<p>Since </p>
<pre><code>sum(time.endtime-time.starttime)
</code></pre>
<p>returns the interval as "1 day 01:30:00" and this format breaks my Excel sheet, I thought it'd be nice to have the output like "25:30:00" but found no way to do it in the PostgreSQL documentation. </p>
<p>Can anyone here help me out?</p>
| [
{
"answer_id": 341439,
"author": "mat",
"author_id": 42083,
"author_profile": "https://Stackoverflow.com/users/42083",
"pm_score": 4,
"selected": false,
"text": "mat=> select date_part('epoch', '01 day 1:30:00'::interval);\n date_part \n-----------\n 91800\n(1 row)\n"
},
{
"answer_id": 341454,
"author": "slim",
"author_id": 7512,
"author_profile": "https://Stackoverflow.com/users/7512",
"pm_score": 4,
"selected": false,
"text": "EXTRACT SELECT EXTRACT(EPOCH FROM INTERVAL '5 days 3 hours');\nResult: 442800\n"
},
{
"answer_id": 341501,
"author": "Jonathan Leffler",
"author_id": 15168,
"author_profile": "https://Stackoverflow.com/users/15168",
"pm_score": 0,
"selected": false,
"text": "SUM(time.endtime - time.starttime)::INTERVAL HOUR(3) TO SECOND\n\nCAST(SUM(time.endtime - time.starttime) AS INTERVAL HOUR(3) TO SECOND)\n"
},
{
"answer_id": 351317,
"author": "dland",
"author_id": 18625,
"author_profile": "https://Stackoverflow.com/users/18625",
"pm_score": -1,
"selected": false,
"text": "select\n to_char(floor(extract(epoch from ti)/3600),'FM00')\n || ':' || to_char(floor(cast(extract(epoch from ti) as integer) % 3600 / 60), 'FM00')\n || ':' || to_char(cast(extract(epoch from ti) as integer) % 60,'FM00')\n as hourstamp\nfrom whatever;\n select to_char(ti,'HH24:MI:SS') as hourstamp from t\n"
},
{
"answer_id": 6377456,
"author": "pilcrow",
"author_id": 132382,
"author_profile": "https://Stackoverflow.com/users/132382",
"pm_score": 4,
"selected": false,
"text": "SELECT SUM(EXTRACT(EPOCH FROM time.endtime) - EXTRACT(EPOCH FROM time.starttime))\n * INTERVAL '1 SECOND' AS hhmmss\n"
},
{
"answer_id": 24363177,
"author": "neshkeev",
"author_id": 3686755,
"author_profile": "https://Stackoverflow.com/users/3686755",
"pm_score": 6,
"selected": true,
"text": "=> SELECT date_part('epoch', INTERVAL '1 day 01:30:00') * INTERVAL '1 second' hours;\n hours\n-----------\n 25:30:00\n(1 row)\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341384",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/43289/"
] |
341,387 | <p>Hello I would like to ask you, If someone knows how can I add a directory for the header files in the Makefile to avoid the error *.h not found, I have tried this option but does not work:</p>
<pre><code>INC_PATH := -I /directory/to/add
</code></pre>
| [
{
"answer_id": 341396,
"author": "unwind",
"author_id": 28169,
"author_profile": "https://Stackoverflow.com/users/28169",
"pm_score": 5,
"selected": false,
"text": "CFLAGS CFLAGS=-I/directory/to/add\n"
},
{
"answer_id": 341486,
"author": "Jonathan Leffler",
"author_id": 15168,
"author_profile": "https://Stackoverflow.com/users/15168",
"pm_score": 5,
"selected": true,
"text": "CC = gcc -g\nXFLAGS = -Wall -Wshadow -Wstrict-prototypes -Wmissing-prototypes \\\n -DDEBUG -Wredundant-decls\n#CC = cc -g\n#XFLAGS =\nUFLAGS = # Always overrideable on the command line\n\nDEPEND.mk = sqlcmd-depend.mk\nINSTALL.mk = sqlcmd-install.mk\n\nESQLC_VERSION = `esqlcver`\nOFLAGS = # -DDEBUG_MALLOC -g\nOFLAGS = -g -DDEBUG -O4\nPFLAGS = -DHAVE_CONFIG_H\nOFILES.o = # rfnmanip.o # malloc.o # strdup.o # memmove.o\nVERSION = -DESQLC_VERSION=${ESQLC_VERSION}\n#INC1 = <defined in sqlcmd-depend.mk>\n#INC2 = <defined in sqlcmd-depend.mk>\nINC3 = /usr/gnu/include\nINC4 = ${INFORMIXDIR}/incl/esql\nINC5 = . #${INFORMIXDIR}/incl\nINCDIRS = -I${INC3} -I${INC1} -I${INC2} -I${INC4} -I${INC5}\nLIBSQLCMD = libsqlcmd.a\nSTRIP = #-s\nLIBC = #-lc_s\nLIBMALLOC = #-lefence\nLIBRDLN = -lreadline\nLIBCURSES = -lcurses\nLIBPOSIX4 = -lposix4\nLIBG = #-lg\nLIBDIR1 = ${HOME}/lib\nLIBDIR2 = /usr/gnu/lib\nLIBJL1 = ${LIBDIR1}/libjl.a\nLIBJL2 = ${LIBDIR1}/libjlss-${ESQLC_VERSION}.a\nLIBTOOLS = ${LIBJL2} ${LIBJL1}\nLDFLAGS = ${LIBSQLCMD} ${LIBTOOLS} -L${LIBDIR2} ${LIBG} ${LIBMALLOC} \\\n ${LIBPOSIX4} ${LIBC} ${STRIP}\nCFLAGS = ${VERSION} ${INCDIRS} ${OFLAGS} ${XFLAGS} ${PFLAGS} ${UFLAGS}\n sqlcmd make ${CC} ${CFLAGS} -c $*.c\n ${CC} ${CFLAGS} -o $@ ${OBJECTS} ${LDFLAGS}\n esqlcver make configure autoconf"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341387",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39160/"
] |
341,393 | <p>This is an extension of a question I had yesterday.</p>
<p>I am trying to make a little php calculator that will show how much people can save on their phone bills if they switch to VoIP, and how much they can save with each service.</p>
<p>I have a form that will spit out the right amount for a monthly bill here:</p>
<p><a href="http://www.nextadvisor.com/voip_services/voip_calculator.php?monthlybill=50&Submit=Submit" rel="nofollow noreferrer">http://www.nextadvisor.com/voip_services/voip_calculator.php?monthlybill=50&Submit=Submit</a></p>
<p>But now I need to integrate that with some other data and put in a table. The prices for each of the different services are in another file called "values.php". The values are:</p>
<pre><code> $offer1calcsavings="24.99";
$offer2calcsavings="20.00";
$offer3calcsavings="21.95";
$offer4calcsavings="23.95";
$offer5calcsavings="19.95";
$offer6calcsavings="23.97";
$offer7calcsavings="24.99";
</code></pre>
<p>I want each of the seven rows of the table to have one of the offercalcsavings values subtracted from the monthlybill value. </p>
<p>The php code currently looks like this:</p>
<pre><code> <?php $monthlybill = $_GET['monthlybill']; ?>
Your monthly bill was <?php echo "$monthlybill"; ?>
<?php
$monthybill="monthlybill";
$re=1;
$offer ='offer'.$re.'name';
$offername= ${$offer};
while($offername!=""){
$offerlo ='offer'.$re.'logo';
$offerlogo=${$offerlo};
$offerli ='offer'.$re.'link';
$offerlink=${$offerli};
$offeran ='offer'.$re.'anchor';
$offeranchor=${$offeran};
$offerst ='offer'.$re.'star1';
$offerstar=${$offerst};
$offerbot='offer'.$re.'bottomline';
$offerbottomline=${$offerbot};
$offerca ='offer'.$re.'calcsavings';
$offercalcsavings=${$offerca};
echo '<tr >
<td >
<a href="'.$offerlink.'" target="blank">
<img src="http://www.nextadvisor.com'.$offerlogo.'" alt="'.$offername.'" />
</a>
</td>
<td ><span class="rating_text">Rating:</span>
<span class="star_rating1">
<img src="http://www.nextadvisor.com'.$offerstar.'" alt="" />
</span><br />
<div style="margin-top:5px; color:#0000FF;">
<a href="'.$offerlink.'" target="blank">Go to Site</a>
<span style="margin:0px 7px 0px 7px;">|</span>
<a href="'.$offeranchor.'">Review</a>
</div> </td>
<td >'.$offercalcsavings.'</td>
</tr>';
$re=$re+1;
$offer ='offer'.$re.'name';
$offername= ${$offer};
}
?>
</code></pre>
| [
{
"answer_id": 341396,
"author": "unwind",
"author_id": 28169,
"author_profile": "https://Stackoverflow.com/users/28169",
"pm_score": 5,
"selected": false,
"text": "CFLAGS CFLAGS=-I/directory/to/add\n"
},
{
"answer_id": 341486,
"author": "Jonathan Leffler",
"author_id": 15168,
"author_profile": "https://Stackoverflow.com/users/15168",
"pm_score": 5,
"selected": true,
"text": "CC = gcc -g\nXFLAGS = -Wall -Wshadow -Wstrict-prototypes -Wmissing-prototypes \\\n -DDEBUG -Wredundant-decls\n#CC = cc -g\n#XFLAGS =\nUFLAGS = # Always overrideable on the command line\n\nDEPEND.mk = sqlcmd-depend.mk\nINSTALL.mk = sqlcmd-install.mk\n\nESQLC_VERSION = `esqlcver`\nOFLAGS = # -DDEBUG_MALLOC -g\nOFLAGS = -g -DDEBUG -O4\nPFLAGS = -DHAVE_CONFIG_H\nOFILES.o = # rfnmanip.o # malloc.o # strdup.o # memmove.o\nVERSION = -DESQLC_VERSION=${ESQLC_VERSION}\n#INC1 = <defined in sqlcmd-depend.mk>\n#INC2 = <defined in sqlcmd-depend.mk>\nINC3 = /usr/gnu/include\nINC4 = ${INFORMIXDIR}/incl/esql\nINC5 = . #${INFORMIXDIR}/incl\nINCDIRS = -I${INC3} -I${INC1} -I${INC2} -I${INC4} -I${INC5}\nLIBSQLCMD = libsqlcmd.a\nSTRIP = #-s\nLIBC = #-lc_s\nLIBMALLOC = #-lefence\nLIBRDLN = -lreadline\nLIBCURSES = -lcurses\nLIBPOSIX4 = -lposix4\nLIBG = #-lg\nLIBDIR1 = ${HOME}/lib\nLIBDIR2 = /usr/gnu/lib\nLIBJL1 = ${LIBDIR1}/libjl.a\nLIBJL2 = ${LIBDIR1}/libjlss-${ESQLC_VERSION}.a\nLIBTOOLS = ${LIBJL2} ${LIBJL1}\nLDFLAGS = ${LIBSQLCMD} ${LIBTOOLS} -L${LIBDIR2} ${LIBG} ${LIBMALLOC} \\\n ${LIBPOSIX4} ${LIBC} ${STRIP}\nCFLAGS = ${VERSION} ${INCDIRS} ${OFLAGS} ${XFLAGS} ${PFLAGS} ${UFLAGS}\n sqlcmd make ${CC} ${CFLAGS} -c $*.c\n ${CC} ${CFLAGS} -o $@ ${OBJECTS} ${LDFLAGS}\n esqlcver make configure autoconf"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341393",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/43035/"
] |
341,397 | <p>My computer often produces a "ding" sound, and I can't associate it with anything. Is it possible to programmatically determine the source of the beeps? For example can I hook the sound driver? If so, can you point out some examples or references?</p>
| [
{
"answer_id": 375218,
"author": "Adam Rosenfield",
"author_id": 9530,
"author_profile": "https://Stackoverflow.com/users/9530",
"pm_score": 0,
"selected": false,
"text": "lsof(8) lsof | grep -E '/dev/(snd|dsp)'\n fuser(1) lsof"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341397",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
341,417 | <p>How do you handle the Web User Control event? I notice my custom web user control have a event call OnError but it never fire when i tweak the control to fail. The control is basically a custom gridview control. I search for web user control event handling over the net but i haven't find a article that address what i looking for. Can someone do a quick explanation or point me to the right direction?</p>
<p>thank</p>
| [
{
"answer_id": 342921,
"author": "BenAlabaster",
"author_id": 40650,
"author_profile": "https://Stackoverflow.com/users/40650",
"pm_score": 1,
"selected": false,
"text": "Public Event MyEvent(ByVal Sender As Object, ByVal e As EventArgs)\n\nPrivate Sub SomeMethodThatRaisesMyEvent()\n RaiseEvent MyEvent(Me, New EventArgs)\nEnd Sub\n Private WithEvents MyUserControl1 As System.Web.UI.UserControls.MyUserControl\n Private Sub MyUserControlEventHandler(ByVal Sender As Object, ByVal e As EventArgs) _\n Handles MyUserControl.MyEvent\n\n Response.Write(\"My event handled\")\n\nEnd Sub\n"
},
{
"answer_id": 1386588,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "Error try..catch Error Error <script runat=\"server\">\n void MyCustomControl_Error(object source, EventArgs e)\n {\n MyCustomControl c = source as MyCustomControl;\n\n if (c != null)\n {\n // Notice that you cannot retrieve the Exception\n // using Server.GetLastError() as it will return null\n\n Server.ClearError();\n c.Visible = false;\n\n // All I wanted to do in this case was to hide the control\n }\n }\n</script>\n\n<sd:MyCustomControl OnError=\"MyCustomControl_Error\" runat=\"server\" />\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341417",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28647/"
] |
341,422 | <p>I'm writing a Linux module and getting:</p>
<pre><code>Unable to handle kernel NULL pointer dereference
</code></pre>
<p>What does it mean?</p>
| [
{
"answer_id": 341432,
"author": "Nathan",
"author_id": 41158,
"author_profile": "https://Stackoverflow.com/users/41158",
"pm_score": 4,
"selected": true,
"text": "int x = 5;\nint * x_ptr = NULL;\n\nx_ptr = &x; // this line may be missing in your code\n\n*x_ptr += 5; //can't dereference x_ptr here if x_ptr is still NULL\n"
},
{
"answer_id": 341446,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 2,
"selected": false,
"text": "0"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341422",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1100/"
] |
341,423 | <p>The setTimeout function always seems to give me trouble. Right now I have a function that is recursive (calls itself through setTimeout) and changes the elements height.</p>
<p>The function is sent two arguments: the element to be altered and that elements maximum height. The purpose of the function is to unfold the element, or "slide down" at a constant pace. I'm aware I could probably solve this problem with jQuery, but I'm trying my own function.</p>
<pre><code>function slide_down(element, max_height)
{
if(element.clientHeight < max_height)
{
var factor = 10;
var new_height = (element.clientHeight + factor >= max_height) ? max_height : (element.clientHeight + factor);
element.style.height = new_height + 'px';
var func_call = 'slide_down(' + element + ', ' + max_height + ');';
window.setTimeout(func_call, 10);
}
}
</code></pre>
<p>I have tested the arguments when the function is initially called. max_height is set to 20 because it is the elements desired height (I got this value from .scrollHeight).</p>
<p>When the function is done, I want to have it call itself until max_height is the element's height. I do that with this setTimeout call:</p>
<pre><code>var func_call = 'slide_down(' + element + ', ' + max_height + ');';
window.setTimeout(func_call, 10);
</code></pre>
<p>And it is not working. THIS does work:</p>
<pre><code>var func_call = 'alert(1);';
window.setTimeout(func_call, 10);
</code></pre>
<p>I have also tried putting the function call directly into the setTimeout statement, still does not work.</p>
<p>Note that the element's height DOES change the first iteration, the function just never calls itself. So the element variable is set correctly, and I used alert() to display the max_height which is also correct.</p>
<pre><code>alert(func_call);
</code></pre>
<p>Alerts this:</p>
<pre><code>slide_down([object HTMLParagraphElement], 20);
</code></pre>
| [
{
"answer_id": 341452,
"author": "matt b",
"author_id": 4249,
"author_profile": "https://Stackoverflow.com/users/4249",
"pm_score": 0,
"selected": false,
"text": "setTimeout() setTimeout() var func_call = 'slide_down(' + element + ', ' + max_height + ');';\nwindow.setTimeout(func_call, 10);\n window.setTimeout(slide_down, 10, element, max_height); \n setTimeout() setTimeout() window.setInterval()"
},
{
"answer_id": 341460,
"author": "Greg",
"author_id": 24181,
"author_profile": "https://Stackoverflow.com/users/24181",
"pm_score": 5,
"selected": true,
"text": "var func_call = 'slide_down(' + element + ', ' + max_height + ');';\n slide_down(\"[Object]\", 100);\n function slide_down(element, max_height)\n{ \n if(element.clientHeight < max_height)\n {\n var factor = 10;\n var new_height = (element.clientHeight + factor >= max_height) ? max_height : (element.clientHeight + factor);\n element.style.height = new_height + 'px';\n\n var func = function()\n {\n slide_down(element, max_height);\n }\n\n window.setTimeout(func, 10);\n }\n}\n"
},
{
"answer_id": 7964477,
"author": "Tokimon",
"author_id": 351835,
"author_profile": "https://Stackoverflow.com/users/351835",
"pm_score": 2,
"selected": false,
"text": "function slide_down(element, max_height)\n{ \n if(element.clientHeight < max_height)\n { return; }\n\n var factor = 10,\n new_height = element.clientHeight + factor,\n f = arguments.callee;\n\n if( new_height > max_height )\n { new_height = max_height; }\n\n element.style.height = new_height + 'px';\n\n window.setTimeout(function() { f(element, max_height); }, 10);\n}\n arguments.callee new_height element.clientHeight + factor"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341423",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29595/"
] |
341,429 | <p>I am trying to use the SGI STL implementation I have downloaded from their site. I want to use a hashmap, because I have to store around 5.000.000 records, but it should be good: I need to be able to access it very quickly. I've tried <code>stedext::hash_map</code>, but it was very slow because I couldn't set the initial size. By the way, is it possible to do that?
If I add the additional path to my MS Visual Studio, I can't even compile the example from the SGI site. I get an error message: </p>
<pre><code>error C2061: syntax error : identifier 'T'.
</code></pre>
<p>Has anyone else faced such problems?</p>
| [
{
"answer_id": 341459,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "void resize(size_type n)\n #include <hash_map>\n#include <iostream>\n\nstruct eqstr\n{\n bool operator()(const char* s1, const char* s2) const\n {\n return strcmp(s1, s2) == 0;\n }\n};\n\nint main()\n{\n std::hash_map<const char*, int, hash<const char*>, eqstr> months;\n\n months[\"january\"] = 31;\n months[\"february\"] = 28;\n months[\"march\"] = 31;\n months[\"april\"] = 30;\n months[\"may\"] = 31;\n months[\"june\"] = 30;\n months[\"july\"] = 31;\n months[\"august\"] = 31;\n months[\"september\"] = 30;\n months[\"october\"] = 31;\n months[\"november\"] = 30;\n months[\"december\"] = 31;\n\n std::cout << \"september -> \" << months[\"september\"] << endl;\n std::cout << \"april -> \" << months[\"april\"] << endl;\n std::cout << \"june -> \" << months[\"june\"] << endl;\n std::cout << \"november -> \" << months[\"november\"] << endl;\n}\n std::hash_map<std::string, int, hash<std::string>, eqstr> months;\n"
},
{
"answer_id": 341984,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "/Od /I \"C:\\SGI\" /D \"_MBCS\" Gm /EHsc /RTC1 /MDd /Fo\"Debug\\\\\"/Fd\"Debug\\vc90.pdb\" /W3 /nologo /c /ZI /TP /errorReport:prompt\n"
},
{
"answer_id": 344082,
"author": "Rob Segal",
"author_id": 7285,
"author_profile": "https://Stackoverflow.com/users/7285",
"pm_score": 0,
"selected": false,
"text": "#include \"hash_map\"\n #include <hash_map>\n"
},
{
"answer_id": 344689,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "#include <tr1/unordered_map>\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341429",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
341,438 | <p>I have built a simple WCF Service and deployed it to IIS6, and I'm noticing that it works in my Dev and Staging environments, but not Production. Every time I try to hit the service metadata link, I get a 404 page.</p>
<p>I've checked IIS config everywhere I can think of and they're identical, so the only difference I can think of is that the Production environment is load balanced.</p>
<p>Does anyone know of any issues with running a WCF service behind a load balancer, and how can I get around that? Am I on the wrong track, is there another common problem I should look into? </p>
| [
{
"answer_id": 31576142,
"author": "Jeremy Thompson",
"author_id": 495455,
"author_profile": "https://Stackoverflow.com/users/495455",
"pm_score": 0,
"selected": false,
"text": "aspnet_regiis -i -enable"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341438",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/43250/"
] |
341,462 | <p>Can anyone explain the difference between the types mentioned above and some sample usage to clearly explain the difference between the two?</p>
<p>Any help would be highly appreciated!
Note: this question is a spin-off from <a href="https://stackoverflow.com/questions/324168/msxml2ixmldomdocument2ptr-getxml-messing-up-my-string">this other question</a></p>
| [
{
"answer_id": 341545,
"author": "efotinis",
"author_id": 12320,
"author_profile": "https://Stackoverflow.com/users/12320",
"pm_score": 4,
"selected": false,
"text": "_bstr_t"
},
{
"answer_id": 343590,
"author": "Khalid Salomão",
"author_id": 40248,
"author_profile": "https://Stackoverflow.com/users/40248",
"pm_score": 6,
"selected": true,
"text": "BSTR _bstr_t _bstr_t _bstr_t BSTR CComBSTR BSTR"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341462",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1311500/"
] |
341,470 | <p>I'm using Office Automation in .NET. It is leaving behind the excel.exe program. I know the fix - it is all about explicitely defining the variables. Once defined, I can properly de-allocate the ram and the GC will clean them up.</p>
<p>The problem is, I have literally thousands of lines of code to go through. So I'm wondering: Is there some sort of a utility in .net (or 3rd party) that is capable of showing me a list of variables for which I have ram allocated still? If so, I would be able to target those items and specificially de-allocate them.</p>
<p>Thanks</p>
<p>Ryan</p>
| [
{
"answer_id": 341765,
"author": "Jason Jackson",
"author_id": 13103,
"author_profile": "https://Stackoverflow.com/users/13103",
"pm_score": 0,
"selected": false,
"text": "Excel.ApplicationClass excel = new Excel.ApplicationClass();\n//do some work with Excel\nexcel.Quit();\n Excel.ApplicationClass excel = null;\n\ntry\n{\n excel = new Excel.ApplicationClass();\n //do some Excel work\n}\ncatch(Exception ex)\n{\n //log exception\n throw;\n}\nfinally\n{\n if(excel != null)\n excel.Quit();\n}\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341470",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36620/"
] |
341,471 | <p>I'm attempting to eliminate leading any leading zeroes in my date when I run the get-date cmdlet by trying: </p>
<pre><code>$filedate = get-date -uformat "%m-%d-%Y"
$filedate = $filedate.ToString().Replace("0", "")
</code></pre>
<p>this returns "01-04-2008"</p>
<p>I want to the output to be "1-4-2008"</p>
<p>any ideas on another way of doing this?</p>
<p>thanks in advance</p>
| [
{
"answer_id": 341524,
"author": "Gordon Bell",
"author_id": 16473,
"author_profile": "https://Stackoverflow.com/users/16473",
"pm_score": 5,
"selected": true,
"text": "$filedate = get-date -format \"M-d-yyyy\"\n"
},
{
"answer_id": 40612221,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "get-date -format yyyy/M/d\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341471",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18853/"
] |
341,474 | <p>Although I know how to build a DOM the long, arduous way using the DOM API, I'd like to do something a bit better than that. Is there a nice, tidy way to build hierarchical documents with, say, an API that works something like Hibernate's Criteria API? So that I can chain calls together like this, for example:</p>
<pre><code>Document doc = createDocumentSomehow ();
doc.createElement ("root").createElements (
doc.newElement ("subnode")
.createElement ("sub-subnode")
.setText("some element text")
.addAttribute ("attr-name","attr-value"),
doc.newElement ("other_subnode"));
</code></pre>
<p>Ideally, this would result in XML like this:</p>
<pre><code><root>
<subnode>
<sub-subnode attr-name = "attr-value">some element text</sub-subnode>
<other_subnode />
</root>
</code></pre>
<p>Basically, I'd like something where the Java itself isn't nearly four times longer than the document I'm generating. Does it exist?</p>
| [
{
"answer_id": 341509,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 3,
"selected": true,
"text": "JDom this <adressbuch aktualisiert=\"1.4.2008\">\n <adresse>\n <vorname> Hugo </vorname>\n <nachname> Meier </nachname>\n <telefon typ=\"mobil\">0160/987654 </telefon>\n </adresse>\n</adressbuch>\n new Document(\n new Element (\"adressbuch\")\n .setAttribute(\"aktualisiert\", \"1.4.2008\")\n .addContent(\n (Element) new Element(\"adresse\")\n .addContent(\n (Element) new Element(\"vorname\")\n .addContent(\"Hugo\"))\n .addContent(\n (Element) new Element(\"nachname\")\n .addContent(\"Meier\"))\n .addContent(\n (Element) new Element(\"telefon\")\n .setAttribute(\"typ\", \"mobil\")\n .addContent(\"0160/987654\"))));\n"
},
{
"answer_id": 341573,
"author": "Joe Liversedge",
"author_id": 4552,
"author_profile": "https://Stackoverflow.com/users/4552",
"pm_score": 0,
"selected": false,
"text": "import org.dom4j.Document;\nimport org.dom4j.DocumentHelper;\nimport org.dom4j.Element;\n\npublic class Foo {\n\n public Document createDocument() {\n Document document = DocumentHelper.createDocument();\n Element root = document.addElement( \"root\" );\n\n Element author1 = root.addElement( \"author\" )\n .addAttribute( \"name\", \"James\" )\n .addAttribute( \"location\", \"UK\" )\n .addText( \"James Strachan\" );\n\n Element author2 = root.addElement( \"author\" )\n .addAttribute( \"name\", \"Bob\" )\n .addAttribute( \"location\", \"US\" )\n .addText( \"Bob McWhirter\" );\n\n return document;\n }\n}\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341474",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23309/"
] |
341,477 | <p>I want to create a <strong>List</strong> of <strong>KeyValuePair</strong>s in a managed C++ project. Here is the syntax I'm using</p>
<pre><code>List<KeyValuePair<String^, String^>^>^ thing;
</code></pre>
<p>but I'm getting the following error:</p>
<blockquote>
<p>error C3225: generic type argument for 'T' cannot be 'System::Collections::Generic::KeyValuePair ^', it must be a value type or a handle to a reference type</p>
</blockquote>
<p>I basically want to do this (C#)</p>
<pre><code>List<KeyValuePair<string, string>> thing;
</code></pre>
<p>but in managed C++. Oh and in .Net 2.0. Any takers?</p>
| [
{
"answer_id": 341679,
"author": "Brian",
"author_id": 2831,
"author_profile": "https://Stackoverflow.com/users/2831",
"pm_score": 2,
"selected": false,
"text": "List<KeyValuePair<String^, String^>>^ thing;\n"
},
{
"answer_id": 341694,
"author": "Konrad Rudolph",
"author_id": 1968,
"author_profile": "https://Stackoverflow.com/users/1968",
"pm_score": 3,
"selected": true,
"text": "struct class"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341477",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2831/"
] |
341,484 | <p>in Perl, when I do <code>use <module name> <ver>;</code>, the system finds the <code>.pm</code> file for the library somewhere in the <code>@INC</code> path.</p>
<p>Is there a reliable way to which file was actually loaded?</p>
| [
{
"answer_id": 341529,
"author": "John",
"author_id": 13895,
"author_profile": "https://Stackoverflow.com/users/13895",
"pm_score": 2,
"selected": false,
"text": "perl -le 'print foreach @INC'\n"
},
{
"answer_id": 341572,
"author": "mikegrb",
"author_id": 13462,
"author_profile": "https://Stackoverflow.com/users/13462",
"pm_score": 3,
"selected": false,
"text": "use strict;\nuse warnings;\nuse Module::Locate qw/locate/;\n\nmy $to_find = \"Some::Module\";\n\nprint \"Perl would use: \", scalar locate($to_find), \"\\n\";\n"
},
{
"answer_id": 341574,
"author": "derobert",
"author_id": 27727,
"author_profile": "https://Stackoverflow.com/users/27727",
"pm_score": 7,
"selected": true,
"text": "%INC $ perl -M'Data::Dump qw(pp)' -e 'pp(\\%INC)'\n{\n \"Data/Dump.pm\" => \"/usr/share/perl5/Data/Dump.pm\",\n \"Exporter.pm\" => \"/usr/share/perl/5.10/Exporter.pm\",\n \"List/Util.pm\" => \"/usr/lib/perl/5.10/List/Util.pm\",\n \"Scalar/Util.pm\" => \"/usr/lib/perl/5.10/Scalar/Util.pm\",\n \"XSLoader.pm\" => \"/usr/lib/perl/5.10/XSLoader.pm\",\n \"overload.pm\" => \"/usr/share/perl/5.10/overload.pm\",\n \"strict.pm\" => \"/usr/share/perl/5.10/strict.pm\",\n \"vars.pm\" => \"/usr/share/perl/5.10/vars.pm\",\n \"warnings.pm\" => \"/usr/share/perl/5.10/warnings.pm\",\n \"warnings/register.pm\" => \"/usr/share/perl/5.10/warnings/register.pm\",\n}\n"
},
{
"answer_id": 341607,
"author": "Hudson",
"author_id": 14105,
"author_profile": "https://Stackoverflow.com/users/14105",
"pm_score": 1,
"selected": false,
"text": "perl -MModule::Mapper -MData::Dumper \\\n-e 'print Dumper( find_sources( UseINC => 1, Modules => [ @ARGV ] ) )' \\\nlist-of-modules-to-locate\n"
},
{
"answer_id": 342054,
"author": "brian d foy",
"author_id": 2766176,
"author_profile": "https://Stackoverflow.com/users/2766176",
"pm_score": 3,
"selected": false,
"text": "%INC do require use"
},
{
"answer_id": 344122,
"author": "skiphoppy",
"author_id": 18103,
"author_profile": "https://Stackoverflow.com/users/18103",
"pm_score": 3,
"selected": false,
"text": "perldoc -l ModuleName\n"
},
{
"answer_id": 3008063,
"author": "Russell Jungwirth",
"author_id": 362696,
"author_profile": "https://Stackoverflow.com/users/362696",
"pm_score": 3,
"selected": false,
"text": "#!/bin/bash\nperl -M${1} -le \"\\$mname=\\\"${1}.pm\\\";\\$mname=~s#::#/#g;print \\\"$1 INSTALLED AT \\$INC{\\$mname}\\\";\" 2>/dev/null || echo \"${1} NOT INSTALLED\"\n ./find_perl_module Font::Metrics::Courier\n"
},
{
"answer_id": 8672753,
"author": "user1121750",
"author_id": 1121750,
"author_profile": "https://Stackoverflow.com/users/1121750",
"pm_score": 3,
"selected": false,
"text": " 'LWP.pm' => '/usr/lib/perl5/5.10.0/LWP.pm',\n 'LWP/Protocol.pm' => '/usr/lib/perl5/5.10.0/LWP/Protocol.pm',\n 'LWP/UserAgent.pm' => '/usr/lib/perl5/5.10.0/LWP/UserAgent.pm',\n"
},
{
"answer_id": 9127427,
"author": "Alexx Roche",
"author_id": 1153645,
"author_profile": "https://Stackoverflow.com/users/1153645",
"pm_score": 0,
"selected": false,
"text": "#!/bin/sh\n\nif [ ! $1 ];then echo \"Which perl module should I look for?\"; exit; fi\n\necho -n \"You are using: \"\nperldoc -l $1\necho \"which I found by looking in:\"\nperl -MData::Dump=pp -e 'unshift @INC, '$1'; pp(\\@INC)'\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341484",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23630/"
] |
341,512 | <p>I have the following code in WCF service to throw a custom fault based on certain situations. I am getting a "The creator of this fault did not specify a Reason" exception. What am I doing wrong?</p>
<pre><code>//source code
if(!DidItPass)
{
InvalidRoutingCodeFault fault = new InvalidRoutingCodeFault("Invalid Routing Code - No Approval Started");
throw new FaultException<InvalidRoutingCodeFault>(fault);
}
//operation contract
[OperationContract]
[FaultContract(typeof(InvalidRoutingCodeFault))]
bool MyMethod();
//data contract
[DataContract(Namespace="http://myuri.org/Simple")]
public class InvalidRoutingCodeFault
{
private string m_ErrorMessage = string.Empty;
public InvalidRoutingCodeFault(string message)
{
this.m_ErrorMessage = message;
}
[DataMember]
public string ErrorMessage
{
get { return this.m_ErrorMessage; }
set { this.m_ErrorMessage = value; }
}
}
</code></pre>
| [
{
"answer_id": 341580,
"author": "Chris Porter",
"author_id": 13495,
"author_profile": "https://Stackoverflow.com/users/13495",
"pm_score": 0,
"selected": false,
"text": "<serviceDebug includeExceptionDetailInFaults=\"true\" />\n"
},
{
"answer_id": 341702,
"author": "Michael Kniskern",
"author_id": 26327,
"author_profile": "https://Stackoverflow.com/users/26327",
"pm_score": 7,
"selected": true,
"text": "if(!DidItPass)\n{ \n InvalidRoutingCodeFault fault = new InvalidRoutingCodeFault(\"Invalid Routing Code - No Approval Started\"); \n throw new FaultException<InvalidRoutingCodeFault>(fault, new FaultReason(\"Invalid Routing Code - No Approval Started\"));\n}\n"
},
{
"answer_id": 487315,
"author": "SO User",
"author_id": 39289,
"author_profile": "https://Stackoverflow.com/users/39289",
"pm_score": 3,
"selected": false,
"text": "serviceDebug includeExceptionDetailInFaults=\"true\"\n serviceDebug includeExceptionDetailInFaults=\"false\" // data contract \n\n[DataContract]\npublic class FormatFault\n{\n private string additionalDetails;\n\n [DataMember]\n public string AdditionalDetails\n {\n get { return additionalDetails; }\n set { additionalDetails = value; }\n }\n}\n\n// interface method declaration\n\n [OperationContract]\n [FaultContract(typeof(FormatFault))]\n void DoWork2();\n\n// service method implementation\n\n public void DoWork2()\n {\n try\n {\n int i = int.Parse(\"Abcd\");\n }\n catch (FormatException ex)\n {\n FormatFault fault = new FormatFault();\n fault.AdditionalDetails = ex.Message;\n throw new FaultException<FormatFault>(fault);\n }\n }\n\n// client calling code\n\n private static void InvokeWCF2()\n {\n ServiceClient service = new ServiceClient();\n\n try\n {\n service.DoWork2();\n }\n catch (FaultException<FormatFault> e)\n {\n // This is a strongly typed try catch instead of the weakly typed where we need to do -- if (e.Code.Name == \"Format_Error\")\n Console.WriteLine(\"Handling format exception: \" + e.Detail.AdditionalDetails); \n }\n }\n"
},
{
"answer_id": 3202127,
"author": "user386451",
"author_id": 386451,
"author_profile": "https://Stackoverflow.com/users/386451",
"pm_score": 3,
"selected": false,
"text": "// service method implementation\n\n throw new FaultException<FormatFault>(fault,new FaultReason(fault.CustomFaultMassage)); \n"
},
{
"answer_id": 12358743,
"author": "Daniel Davis",
"author_id": 1660997,
"author_profile": "https://Stackoverflow.com/users/1660997",
"pm_score": 4,
"selected": false,
"text": "System.ServiceModel.FaultException<InvalidRoutingCodeFault> InvalidRoutingCodeFault .detail private static void InvokeMyMethod() \n{ \n ServiceClient service = new MyService.ServiceClient(); \n\n try \n { \n service.MyMethod(); \n } \n catch (System.ServiceModel.FaultException<InvalidRoutingCodeFault> ex) \n { \n // This will output the \"Message\" property of the System.ServiceModel.FaultException\n // 'The creator of this fault did not specify a Reason' if not specified when thrown\n Console.WriteLine(\"faultException Message: \" + ex.Message); \n // This will output the ErrorMessage property of your InvalidRoutingCodeFault type\n Console.WriteLine(\"InvalidRoutingCodeFault Message: \" + ex.Detail.ErrorMessage); \n } \n}\n InvalidRoutingCodeFault fault = new InvalidRoutingCodeFault(\"Invalid Routing Code - No Approval Started\"); \nthrow new FaultException<InvalidRoutingCodeFault>(fault, new FaultReason(fault.ErrorMessage)); \n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341512",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26327/"
] |
341,516 | <p>I've always wondered about when and where is the best time to cache a property value... Some of them seem pretty simple, like the one below...</p>
<pre><code>public DateTime FirstRequest {
get {
if (this.m_FirstRequest == null) {
this.m_FirstRequest = DateTime.Now;
}
return (DateTime)this.m_FirstRequest;
}
}
private DateTime? m_FirstRequest;
</code></pre>
<p><strong>But what about some more complicated situations?</strong></p>
<ol>
<li>A value that comes from a database, but remains true after it's been selected.</li>
<li>A value that is stored in a built-in cache and might expire from time to time.</li>
<li>A value that has to be calculated first? </li>
<li>A value that requires some time to initialize. 0.001s, 0.1s, 1s, <strong>5s</strong>???</li>
<li>A value that is set, but something else may come and set it to null to flag that it should be repopulated.</li>
<li><strong>???</strong> There seems to be limitless situations.</li>
</ol>
<p><strong>What do you think is the point that a property can no longer take care of itself and instead require something to populate its value?</strong></p>
<hr>
<p><strong>[EDIT]</strong></p>
<p>I see suggestions that I'm optimizing too early, etc. But my question is for when it is time to optimize. Caching everything isn't what I'm asking, but when it is time to cache, whose responsibility should it be?</p>
| [
{
"answer_id": 341640,
"author": "Jeff Yates",
"author_id": 23234,
"author_profile": "https://Stackoverflow.com/users/23234",
"pm_score": 1,
"selected": false,
"text": "ISupportInitialize"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341516",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17091/"
] |
341,520 | <p>Somebody used libapt or libept to list packages and get informations about package in a debian-like system?</p>
<p>Libapt is not well-documented at all, and i've found few examples and tutorials about libept. Can someone explain me best methods to</p>
<ol>
<li>get a list of every packages in the apt-system</li>
<li>get informations about single packages (like name, version, dependences, description, etc.</li>
<li>get list of files installed by a single package</li>
</ol>
<p>Work directly with apt internal files is quite simple, but i want to use a library to respect apt specifications.</p>
| [
{
"answer_id": 341588,
"author": "joveha",
"author_id": 40668,
"author_profile": "https://Stackoverflow.com/users/40668",
"pm_score": 3,
"selected": false,
"text": "# apt-get source apt\n cmdline/apt-cache.cc DumpPackage()"
},
{
"answer_id": 23970130,
"author": "eyelash",
"author_id": 799849,
"author_profile": "https://Stackoverflow.com/users/799849",
"pm_score": 4,
"selected": false,
"text": "libapt-pkg-doc #include <apt-pkg/cachefile.h>\n#include <apt-pkg/pkgcache.h>\n\nint main() {\n // _config and _system are defined in the libapt header files\n pkgInitConfig(*_config);\n pkgInitSystem(*_config, _system);\n\n pkgCacheFile cache_file;\n pkgCache* cache = cache_file.GetPkgCache();\n\n for (pkgCache::PkgIterator package = cache->PkgBegin(); !package.end(); package++) {\n std::cout << package.Name() << std::endl;\n }\n\n return 0;\n}\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341520",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39796/"
] |
341,531 | <p>I have the following snippet where I would like to extract code between the <code>{foreach}</code> and <code>{/foreach}</code> using a regular expression:</p>
<pre><code>{foreach (...)}
Some random HTML content <div class="">aklakdls</div> and some {$/r/template} markup inside.
{/foreach}
</code></pre>
<p>I already have:</p>
<pre><code>{foreach [^}]*}
</code></pre>
<p>but I am unable to match anything after that. Is there any way to match anything BUT {/foreach} as a whole token? Please note that the content between {foreach}{/foreach} can also contain "{$" tokens.</p>
<p><strong>Edit</strong>: BaileyP's & Tomalak's answers are correct, but I have chosen BaileyP's answer for simplicity sake.</p>
| [
{
"answer_id": 341582,
"author": "Tomalak",
"author_id": 18771,
"author_profile": "https://Stackoverflow.com/users/18771",
"pm_score": 2,
"selected": false,
"text": "\\{foreach [^}]*\\}((?:.(?!\\{/foreach\\}))*[^{]?)\n"
},
{
"answer_id": 341603,
"author": "Peter Bailey",
"author_id": 8815,
"author_profile": "https://Stackoverflow.com/users/8815",
"pm_score": 4,
"selected": true,
"text": "/(?:{foreach .*?})(.*?)(?:{\\/foreach})/gis\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341531",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1508/"
] |
341,550 | <p>I came across a c library for opening files given a Unicode filename. Before opening the file, it first converts the filename to a path by prepending "\\?\". Is there any reason to do this other than to increase the maximum number of characters allowed in the path, per <a href="http://msdn.microsoft.com/en-us/library/aa365247.aspx" rel="noreferrer">this msdn article</a>? </p>
<p>It looks like these "\\?\" paths require the Unicode versions of the Windows API and standard library.</p>
| [
{
"answer_id": 341575,
"author": "Head Geek",
"author_id": 12193,
"author_profile": "https://Stackoverflow.com/users/12193",
"pm_score": 1,
"selected": false,
"text": "MAX_PATH"
},
{
"answer_id": 352205,
"author": "itsadok",
"author_id": 7581,
"author_profile": "https://Stackoverflow.com/users/7581",
"pm_score": 3,
"selected": false,
"text": "path_length > MAX_PATH H:\\myfile.txt H:\\users\\username\\myfile.txt MAX_PATH MAX_PATH+len(\"users\\username\")"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341550",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21784/"
] |
341,571 | <p>How can I render after executing an action in a restful controller instead of redirecting.</p>
<p>I have a controller with standard actions, and I added a special action that adds data to the resource in question, via a form on the #show page (Think comments on a post). I am validating the input from the form and want to re-render the show action on error and redirect to the show action on success.</p>
<p>I want to render to save the user from inputting their info twice, but when I try to render the show action with an error in the flash[:notice] I get an error saying that I am not specifying an ID. When I do specify an ID, it tries to render a new template that doesn't exist yet.</p>
<p>I am thinking that it should be a as simple as:</p>
<pre><code>def add_comment
if my_validation?
save the object
redirect_to :action => "show", :id => params[:id]
else
render :action => "show", :id => params[:id]
end
end
</code></pre>
<p>This is not my actual code, just something I put together just now as an example.</p>
| [
{
"answer_id": 341631,
"author": "dsimard",
"author_id": 42866,
"author_profile": "https://Stackoverflow.com/users/42866",
"pm_score": 3,
"selected": true,
"text": "def create\n @obj = TheObject.new(params[:object])\n render :action => :new unless @obj.save\nend\n <% form_for :obj, \n :url => object_url(@obj), :html => {:method => :post} do |f| %>\n\n <%= f.text_field :name %>\n<% end %>\n"
},
{
"answer_id": 341642,
"author": "Stein G. Strindhaug",
"author_id": 26115,
"author_profile": "https://Stackoverflow.com/users/26115",
"pm_score": 0,
"selected": false,
"text": ".new?"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341571",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24559/"
] |
341,578 | <p>Our solution has a lot of todo comments, but unfortunately it seems the only way to sort them is by file. Sorting by project would give me a much better overview of what I'm actually responsible for. Just wondering if there's any way to do this or any add-ins that provide better functionality.</p>
| [
{
"answer_id": 421344,
"author": "Luke",
"author_id": 327,
"author_profile": "https://Stackoverflow.com/users/327",
"pm_score": 1,
"selected": false,
"text": "todo:"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341578",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/327/"
] |
341,594 | <p>I'm trying to get information like OS version, hard disk space, disk space available, and installed RAM on a Linux system in C++. I know I can use <code>system()</code> to run different Linux commands and capture their output (which is what I'm currently doing) but I was wondering if there's a better way? Is there something in the C++ standard library that I can use to get information from the operating system?</p>
| [
{
"answer_id": 341610,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 3,
"selected": false,
"text": "libhal /proc /sys lshal"
},
{
"answer_id": 341613,
"author": "Martin York",
"author_id": 14065,
"author_profile": "https://Stackoverflow.com/users/14065",
"pm_score": 5,
"selected": true,
"text": "Example: man uname:\nSEE ALSO\n uname(2), getdomainname(2), gethostname(2)\n\n\nExplanation of numbers:\n\n(1): User UNIX Command\n(2): Unix and C system calls\n(3): C Library routines\n(4): Special file names\n(5): File formats\n(6): \n(7):\n(8): System admin commands\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341594",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1288/"
] |
341,602 | <p>How do you implement a last-modified column in SQL?</p>
<p>I know for a date-created column you can just set the default value to <code>getdate()</code>. For last-modified I have always used triggers, but it seems like there must be a better way.</p>
<p>Thanks.</p>
| [
{
"answer_id": 341657,
"author": "gbn",
"author_id": 27535,
"author_profile": "https://Stackoverflow.com/users/27535",
"pm_score": 2,
"selected": false,
"text": "UPDATE\n table\nSET\n blah,\n LastUpdatedDateTime = DEFAULT\nWHERE\n foo = bar\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341602",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26/"
] |
341,608 | <p>What is the default location for the MySQL configuration file on a redhat linux box?</p>
| [
{
"answer_id": 8635575,
"author": "Nugatu",
"author_id": 1116282,
"author_profile": "https://Stackoverflow.com/users/1116282",
"pm_score": 4,
"selected": false,
"text": "/etc/mysql/my.cnf"
},
{
"answer_id": 10001648,
"author": "ThinkingMonkey",
"author_id": 858515,
"author_profile": "https://Stackoverflow.com/users/858515",
"pm_score": 6,
"selected": false,
"text": "mysql --help\n mysqld --help --verbose\n mysql --help | grep Default -A 1\n (Defaults to on; use --skip-auto-rehash to disable.)\n -A, --no-auto-rehash \n--\n (Defaults to on; use --skip-line-numbers to disable.)\n -L, --skip-line-numbers \n--\n (Defaults to on; use --skip-column-names to disable.)\n -N, --skip-column-names \n--\n (Defaults to on; use --skip-reconnect to disable.)\n -s, --silent Be more silent. Print results with a tab as separator,\n--\n --default-auth=name Default authentication client-side plugin to use.\n --binary-mode By default, ASCII '\\0' is disallowed and '\\r\\n' is\n--\nDefault options are read from the following files in the given order:\n/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf \n"
},
{
"answer_id": 31455946,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "/etc/mysql/my.cnf \n/etc/my.cnf \n~/.my.cnf \n"
},
{
"answer_id": 32931741,
"author": "Nullpointer",
"author_id": 1261959,
"author_profile": "https://Stackoverflow.com/users/1261959",
"pm_score": 3,
"selected": false,
"text": "/etc/my.cnf\n/etc/mysql/my.cnf\n/var/lib/mysql/my.cnf\n...\n server ~ # ps ax | grep '[m]ysqld'\n 10801 ? Ssl 0:27 /usr/sbin/mysqld --defaults-file=/etc/mysql/my.cnf --basedir=/usr --datadir=/var/lib/mysql --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock\n which mysqld\n/usr/sbin/mysqld\n /usr/sbin/mysqld --verbose --help | grep -A 1 \"Default options\"\n\n/etc/mysql/my.cnf ~/.my.cnf /usr/etc/my.cnf\n"
},
{
"answer_id": 36956454,
"author": "divandc",
"author_id": 3216341,
"author_profile": "https://Stackoverflow.com/users/3216341",
"pm_score": 1,
"selected": false,
"text": "MariaDB programs look for option files in a set of\nlocations which depend on the deployment platform.\n[...] For information about these locations, do:\n'my_print_defaults --help' and see what is printed under\n\"Default options are read from the following files in the given order:\"\nMore information at: http://dev.mysql.com/doc/mysql/en/option-files.html\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341608",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42931/"
] |
341,619 | <p>I'm using MS Sql 2005.</p>
<p>Why does this give me the correct results (returns 169 rows)...</p>
<pre><code>select
*
from
[import_Data]
where
[import_Data].name not in
(
select
[import_Data].name
from
[import_Data]
inner join [resource] on [import_Data].name = [resource].name
where
[import_Data].ProviderTypeID = 4
and [resource].IsDeleted = 0
)
and [import_Data].ProviderTypeID = 4
</code></pre>
<p>But this doesn't (returns 0 rows)...</p>
<pre><code>select
*
from
[import_Data]
where
[import_Data].name not in
(
select
[resource].name
from
[resource]
where
IsDeleted = 0
)
and [import_Data].ProviderTypeID = 4
</code></pre>
<p>The only difference between the <code>name</code> columns is that <code>[resource].name</code> is <code>varchar(500)</code> and <code>[import_Data].name</code> is <code>varchar(300)</code>. </p>
| [
{
"answer_id": 341659,
"author": "xahtep",
"author_id": 42184,
"author_profile": "https://Stackoverflow.com/users/42184",
"pm_score": 2,
"selected": false,
"text": "null name [resource] = not in select * from [resource] where name is null and IsDeleted = 0\n select * from [import_Data]\nwhere \n [import_Data].name not in (\n select name from [resource] where IsDeleted = 0 and name is not null\n ) \n and [import_Data].ProviderTypeID = 4\n"
},
{
"answer_id": 341667,
"author": "Tomalak",
"author_id": 18771,
"author_profile": "https://Stackoverflow.com/users/18771",
"pm_score": 2,
"selected": false,
"text": "IN = select \n * \nfrom \n [import_Data] \nwhere \n not exists \n (\n select 1 \n from [resource] \n where name = [import_Data].Name and IsDeleted = 0\n ) \n and [import_Data].ProviderTypeID = 4\n"
},
{
"answer_id": 341676,
"author": "Will Rickards",
"author_id": 290835,
"author_profile": "https://Stackoverflow.com/users/290835",
"pm_score": 4,
"selected": true,
"text": "SELECT *\nFROM [import_Data] \nWHERE NOT EXISTS(\n select [resource].name from [resource] where IsDeleted = 0 AND [resource].name = [import_Data].name\n )\n AND [import_Data].ProviderTypeID = 4\n"
},
{
"answer_id": 341677,
"author": "Stanislas Biron",
"author_id": 43311,
"author_profile": "https://Stackoverflow.com/users/43311",
"pm_score": 2,
"selected": false,
"text": "[import_Data].name <> 'Resource1' and [import_Data].name <> 'Resource2' \nand [import_Data].name <> null\n select * from [import_Data] where [import_Data].name <> null\n select * from [import_Data] \nwhere [import_Data].name not in (\n select [resource].name from [resource] where IsDeleted = 0 \n and [resource].name is not null\n) and [import_Data].ProviderTypeID = 4\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341619",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24908/"
] |
341,624 | <p>I have a Spring web application which is configured to use JDK proxying for AOP. The AOP annotations (such as @Transactional) are declared on the interfaces, rather than the implementation classes.</p>
<p>The application itself works fine, but when I run the unit tests, it seems to be attempting to use CGLIB for the AOP functionality (instead of JDK proxying). This causes the tests to fail - I've appended the stack trace below.</p>
<p>I don't understand why CGLIB is being used when I run the tests, because the Spring configuration is largely the same as when the application is running. One possibly significant difference is that the test configuration uses a <a href="http://static.springframework.org/spring/docs/2.5.0/api/org/springframework/jdbc/datasource/DataSourceTransactionManager.html" rel="noreferrer">DataSourceTransactionManager</a> instead of a JTA transaction manager. The test classes themselves all extend <a href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/test/context/junit4/AbstractJUnit4SpringContextTests.html" rel="noreferrer">AbstractJUnit4SpringContextTests</a>, could it be that this class is somehow hard-wired to use CGLIB?</p>
<pre><code>Caused by: org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class $Proxy25]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Cannot subclass final class class $Proxy25
at org.springframework.aop.framework.Cglib2AopProxy.getProxy(Cglib2AopProxy.java:213)
at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:110)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.createProxy(AbstractAutoProxyCreator.java:488)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:363)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:324)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:361)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1343)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
... 79 more
Caused by: java.lang.IllegalArgumentException: Cannot subclass final class class $Proxy25
at net.sf.cglib.proxy.Enhancer.generateClass(Enhancer.java:446)
at net.sf.cglib.transform.TransformingClassGenerator.generateClass(TransformingClassGenerator.java:33)
at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)
at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:285)
at org.springframework.aop.framework.Cglib2AopProxy.getProxy(Cglib2AopProxy.java:201)
... 86 more
</code></pre>
<p><strong>EDIT: One of the commentators requested that I post the Spring configuration</strong>. I've included it below in abbreviated form (i.e. irrelevant beans and XML namespaces omitted).</p>
<p><strong>spring-servlet.xml</strong></p>
<pre><code><?xml version="1.0" encoding="UTF-8"?>
<beans>
<!-- ANNOTATION SUPPORT -->
<!-- Include basic annotation support -->
<context:annotation-config/>
<!-- CONTROLLERS -->
<!-- Controllers, force scanning -->
<context:component-scan base-package="com.onebigplanet.web.controller,com.onebigplanet.web.ws.*"/>
<!-- Post-processor for @Aspect annotated beans, which converts them into AOP advice -->
<bean class="org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator">
<property name="proxyTargetClass" value="true"/>
</bean>
<!-- An @Aspect bean that converts exceptions thrown in POJO service implementation classes to runtime exceptions -->
<bean id="permissionAdvisor" class="com.onebigplanet.web.advisor.PermissionAdvisor"/>
<bean id="businessIntelligenceAdvisor" class="com.onebigplanet.web.advisor.bi.BusinessIntelligenceAdvisor"/>
<!-- Finds the controllers and sets an interceptor on each one -->
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="interceptors">
<list>
<bean class="com.onebigplanet.web.interceptor.PortalInterceptor"/>
</list>
</property>
</bean>
<!-- METHOD HANDLER ADAPTER -->
<!-- Finds mapping of url through annotation on methods of Controller -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="cacheSeconds" value="0"/>
<property name="webBindingInitializer">
<bean class="com.onebigplanet.web.binder.WebBindingInitializer"/>
</property>
</bean>
</beans>
</code></pre>
<p><strong>applicationContext-service.xml</strong></p>
<pre><code><?xml version="1.0" encoding="UTF-8"?>
<beans>
<!-- Declares a bunch of bean post-processors -->
<context:annotation-config/>
<context:component-scan base-package="com.onebigplanet.service.impl,com.onebigplanet.dao.impl.mysql" annotation-config="false"/>
<!-- Property configurer -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="/WEB-INF/obp-service.properties" />
</bean>
<!-- Post-processor for @Aspect annotated beans, which converts them into AOP advice -->
<bean class="org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator"/>
<!-- An @Aspect bean that converts exceptions thrown in service implementation classes to runtime exceptions -->
<bean id="exceptionAdvisor" class="com.onebigplanet.service.advisor.ExceptionAdvisor"/>
<bean id="cachingAdvisor" class="com.onebigplanet.service.advisor.CacheAdvisor"/>
<bean id="businessIntelligenceAffiliateAdvisor" class="com.onebigplanet.service.advisor.BusinessIntelligenceAffiliateAdvisor"/>
<!-- Writable datasource -->
<jee:jndi-lookup id="dataSource" jndi-name="java:/ObpDS"/>
<!-- ReadOnly datasource -->
<jee:jndi-lookup id="readOnlyDataSource" jndi-name="java:/ObpReadOnlyDS"/>
<!-- Map the transaction manager to allow easy lookup of a UserTransaction -->
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"/>
<!-- Annotation driven transaction management -->
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>
</code></pre>
<p><strong>applicationContext-test.xml</strong> This is only included when running the unit tests. It's purpose is to overwrite some of the beans declared in the other config files.</p>
<pre><code><?xml version="1.0" encoding="UTF-8"?>
<beans>
<!-- Overwrite the property configurer bean such that it reads the test properties file instead -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="/obp-test.properties"/>
</bean>
<!-- All DAOs should use the test datasource -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${testDataSource.driverClassName}"/>
<property name="url" value="${testDataSource.url}"/>
<property name="username" value="${testDataSource.username}"/>
<property name="password" value="${testDataSource.password}"/>
</bean>
<bean id="readOnlyDataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${testDataSource.driverClassName}"/>
<property name="url" value="${testDataSource.url}"/>
<property name="username" value="${testDataSource.username}"/>
<property name="password" value="${testDataSource.password}"/>
</bean>
<!--
Overwrite the JTA transaction manager bean defined in applicationContent-service.xml with this one because
the implementation of the former is provided by JBoss
-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<beans>
</code></pre>
| [
{
"answer_id": 345984,
"author": "jonathan.cone",
"author_id": 42344,
"author_profile": "https://Stackoverflow.com/users/42344",
"pm_score": 2,
"selected": false,
"text": "Caused by: java.lang.IllegalArgumentException: Cannot subclass final class class $Proxy25"
},
{
"answer_id": 2143942,
"author": "Rishik Dhar",
"author_id": 259707,
"author_profile": "https://Stackoverflow.com/users/259707",
"pm_score": 2,
"selected": false,
"text": "<!-- Post-processor for @Aspect annotated beans, which converts them into AOP advice --> \n<bean class=\"org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator\">\n <property name=\"proxyTargetClass\" value=\"true\"/>\n</bean>\n <property name=\"proxyTargetClass\" value=\"false\"/>\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341624",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
341,649 | <p>is there anyway to have an image act as an ajax actionlink? I can only get it to work using text. Thanks for your help!</p>
| [
{
"answer_id": 451091,
"author": "frantisek",
"author_id": 53332,
"author_profile": "https://Stackoverflow.com/users/53332",
"pm_score": 0,
"selected": false,
"text": "DecodeLinkContent(Html.ActionLink<Home>(c => c.Delete(item.ID), \"<span class=\\\"redC\\\">X</span>\",new { Class = \"none left\"})) \n"
},
{
"answer_id": 451122,
"author": "frantisek",
"author_id": 53332,
"author_profile": "https://Stackoverflow.com/users/53332",
"pm_score": 3,
"selected": false,
"text": "ActionLink<TController>(this HtmlHelper helper, Expression<Action<TController>> action, string linkText, object htmlAttributes, LinkOptions options)\n [Flags]\npublic enum LinkOptions\n{\n PlainContent = 0,\n EncodeContent = 1,\n}\n Html.ActionLink<Car>(\n c => c.Delete(item.ID), \"<span class=\\\"redC\\\">X</span>\",\n new { Class = \"none left\" }, \n LinkOptions.PlainContent)\n"
},
{
"answer_id": 780252,
"author": "Neal Stublen",
"author_id": 74764,
"author_profile": "https://Stackoverflow.com/users/74764",
"pm_score": 5,
"selected": false,
"text": "<%= Ajax.ActionLink(\"[replacethis]\", ...).Replace(\"[replacethis]\", \"<img src=\\\"/images/test.gif\\\" ... />\" %>\n"
},
{
"answer_id": 1658065,
"author": "Black Horus",
"author_id": 20709,
"author_profile": "https://Stackoverflow.com/users/20709",
"pm_score": 6,
"selected": false,
"text": " public static class ImageActionLinkHelper\n{\n\n public static string ImageActionLink(this AjaxHelper helper, string imageUrl, string altText, string actionName, object routeValues, AjaxOptions ajaxOptions)\n {\n var builder = new TagBuilder(\"img\");\n builder.MergeAttribute(\"src\", imageUrl);\n builder.MergeAttribute(\"alt\", altText);\n var link = helper.ActionLink(\"[replaceme]\", actionName, routeValues, ajaxOptions);\n return link.Replace(\"[replaceme]\", builder.ToString(TagRenderMode.SelfClosing));\n }\n\n}\n <%= Ajax.ImageActionLink(\"../../Content/Delete.png\", \"Delete\", \"Delete\", new { id = item.Id }, new AjaxOptions { Confirm = \"Delete contact?\", HttpMethod = \"Delete\", UpdateTargetId = \"divContactList\" })%> \n"
},
{
"answer_id": 6201224,
"author": "Arjan Einbu",
"author_id": 19594,
"author_profile": "https://Stackoverflow.com/users/19594",
"pm_score": 5,
"selected": false,
"text": "using System.Web;\nusing System.Web.Mvc;\nusing System.Web.Mvc.Ajax;\n\npublic static class ImageActionLinkHelper\n{\n public static IHtmlString ImageActionLink(this AjaxHelper helper, string imageUrl, string altText, string actionName, object routeValues, AjaxOptions ajaxOptions, object htmlAttributes = null)\n {\n var builder = new TagBuilder(\"img\");\n builder.MergeAttribute(\"src\", imageUrl);\n builder.MergeAttribute(\"alt\", altText);\n builder.MergeAttributes(new RouteValueDictionary(htmlAttributes));\n var link = helper.ActionLink(\"[replaceme]\", actionName, routeValues, ajaxOptions).ToHtmlString();\n return MvcHtmlString.Create(link.Replace(\"[replaceme]\", builder.ToString(TagRenderMode.SelfClosing)));\n }\n\n}\n @Ajax.ImageActionLink(\"../../Content/Delete.png\", \"Delete\", \"Delete\", new { id = item.Id }, new AjaxOptions { Confirm = \"Delete contact?\", HttpMethod = \"Delete\", UpdateTargetId = \"divContactList\" })\n @Ajax.ImageActionLink(\"../../Content/Delete.png\", \"Delete\", \"Delete\", new { id = item.Id }, new AjaxOptions { Confirm = \"Delete contact?\", HttpMethod = \"Delete\", UpdateTargetId = \"divContactList\" }, new{ style=\"border: none;\" })\n"
},
{
"answer_id": 6687671,
"author": "Valamas",
"author_id": 511438,
"author_profile": "https://Stackoverflow.com/users/511438",
"pm_score": 2,
"selected": false,
"text": "public static MvcHtmlString ActionImageLink(this HtmlHelper helper, string imageUrl, string altText, string actionName, string controller, object routeValues)\n{\n var builder = new TagBuilder(\"img\");\n builder.MergeAttribute(\"src\", imageUrl);\n builder.MergeAttribute(\"alt\", altText);\n var link = helper.ActionLink(\"[replaceme]\", actionName, controller, routeValues);\n return new MvcHtmlString(link.ToHtmlString().Replace(\"[replaceme]\", builder.ToString(TagRenderMode.SelfClosing)));\n}\npublic static MvcHtmlString ActionImageLink(this AjaxHelper helper, string imageUrl, string altText, string actionName, string controller, object routeValues, AjaxOptions ajaxOptions)\n{\n var builder = new TagBuilder(\"img\");\n builder.MergeAttribute(\"src\", imageUrl);\n builder.MergeAttribute(\"alt\", altText);\n var link = helper.ActionLink(\"[replaceme]\", actionName, controller, routeValues, ajaxOptions);\n return new MvcHtmlString(link.ToHtmlString().Replace(\"[replaceme]\", builder.ToString(TagRenderMode.SelfClosing)));\n}\n"
},
{
"answer_id": 8391335,
"author": "Maslow",
"author_id": 57883,
"author_profile": "https://Stackoverflow.com/users/57883",
"pm_score": 0,
"selected": false,
"text": " public static HelperResult WrapInActionLink(this AjaxHelper helper,ActionResult result, Func<object,HelperResult> template,AjaxOptions options)\n {\n var link=helper.ActionLink(\"[replaceme]\",result,options);\n var asString=link.ToString();\n var replaced=asString.Replace(\"[replaceme]\",template(null).ToString());\n\n return new HelperResult(writer =>\n {\n writer.Write(replaced);\n });\n }\n @Ajax.WrapInActionLink(MVC.Deal.Details(deal.ID.Value),@<img alt='Edit deal details' src='@Links.Content.Images.edit_16_gif'/>, new AjaxOptions() { UpdateTargetId=\"indexDetails\" })\n"
},
{
"answer_id": 10112337,
"author": "Ali Adravi",
"author_id": 586227,
"author_profile": "https://Stackoverflow.com/users/586227",
"pm_score": 1,
"selected": false,
"text": "@Html.ActionLink( \" \", \"Index\", \"Countries\", null, new\n{\n style = \"background: url('../../Content/Images/icon.png') no-repeat center right;display:block; height:24px; width:24px;margin-top:-2px;text-decoration:none;\"\n} )\n"
},
{
"answer_id": 15342133,
"author": "Mithat CAN",
"author_id": 2157386,
"author_profile": "https://Stackoverflow.com/users/2157386",
"pm_score": -1,
"selected": false,
"text": "actionName+\"/\"+routeValues Proje/ControlName/ActionName/Id\n\n\n\n\n using System.Web;\n using System.Web.Mvc;\n using System.Web.Mvc.Ajax;\n\n namespace MithatCanMvc.AjaxHelpers\n{\n\n public static class ImageActionLinkHelper\n {\n public static IHtmlString ImageActionLink(this AjaxHelper helper, string imageUrl, string altText, string actionName, string routeValues, AjaxOptions ajaxOptions)\n {\n var builder = new TagBuilder(\"img\");\n builder.MergeAttribute(\"src\", imageUrl);\n builder.MergeAttribute(\"alt\", altText);\n var link = helper.ActionLink(\"[replaceme]\", actionName+\"/\"+routeValues, ajaxOptions).ToHtmlString();\n return MvcHtmlString.Create(link.Replace(\"[replaceme]\", builder.ToString(TagRenderMode.SelfClosing)));\n\n }\n\n }\n\n}\n"
},
{
"answer_id": 17151675,
"author": "JotaBe",
"author_id": 1216612,
"author_profile": "https://Stackoverflow.com/users/1216612",
"pm_score": 2,
"selected": false,
"text": "public static IHtmlString ActionLink<T>(this AjaxHelper ajaxHelper,\n T item, Func<T,HelperResult> template, string action,\n string controller, object routeValues, AjaxOptions options)\n{\n string rawContent = template(item).ToHtmlString();\n MvcHtmlString a = ajaxHelper.ActionLink(\"$$$\", action, \n controller, routeValues, options);\n return MvcHtmlString.Create(a.ToString().Replace(\"$$$\", rawContent));\n}\n @Ajax.ActionLink(car, \n @<div>\n <h1>@car.Maker</h1>\n <p>@car.Description</p>\n <p>Price: @string.Format(\"{0:C}\",car.Price)</p>\n </div>, ...\n public static IHtmlString ActionLink<T>(this AjaxHelper ajaxHelper, T item,\n Func<T, HelperResult> template, \n [AspMvcAction] string action, [AspMvcController] string controller, \n object routeValues, AjaxOptions options)\n"
},
{
"answer_id": 18062863,
"author": "samai",
"author_id": 604621,
"author_profile": "https://Stackoverflow.com/users/604621",
"pm_score": 0,
"selected": false,
"text": "<li class=\"li_inbox\" >\n @Ajax.ActionLink(\"Inbox\", \"inbox\",\"Home\", new { },\n new AjaxOptions\n {\n UpdateTargetId = \"MainContent\",\n InsertionMode = InsertionMode.Replace,\n HttpMethod = \"GET\"\n })\n"
},
{
"answer_id": 18396311,
"author": "peter",
"author_id": 2709911,
"author_profile": "https://Stackoverflow.com/users/2709911",
"pm_score": 0,
"selected": false,
"text": "@Html.Raw(HttpUtility.HtmlDecode(Ajax.ActionLink( \"<img src=\\\"/images/sjt.jpg\\\" title=\\\"上一月\\\" border=\\\"0\\\" alt=\\\"上一月\\\" />\", \"CalendarPartial\", new { strThisDate = Model.dtCurrentDate.AddMonths(-1).ToString(\"yyyy-MM-dd\") }, new AjaxOptions { @UpdateTargetId = \"calendar\" }).ToString()))\n"
},
{
"answer_id": 19302438,
"author": "Jeroen Visscher",
"author_id": 961139,
"author_profile": "https://Stackoverflow.com/users/961139",
"pm_score": 0,
"selected": false,
"text": " @using (Ajax.BeginForm(\"Action\", \"Controler\", ajaxOptions))\n { \n <button type=\"submit\">\n <img src=\"image.png\" /> \n </button>\n }\n"
},
{
"answer_id": 22443615,
"author": "Silvio",
"author_id": 3426880,
"author_profile": "https://Stackoverflow.com/users/3426880",
"pm_score": 0,
"selected": false,
"text": "replace {\n var url = new UrlHelper(helper.ViewContext.RequestContext);\n\n // build the <img> tag\n var imgBuilder = new TagBuilder(\"img\");\n imgBuilder.MergeAttribute(\"src\", url.Content(imageUrl));\n imgBuilder.MergeAttribute(\"alt\", altText);\n string imgHtml = imgBuilder.ToString(TagRenderMode.SelfClosing);\n\n //build the <a> tag\n var anchorBuilder = new TagBuilder(\"a\");\n anchorBuilder.MergeAttribute(\"href\", url.Action(actionName, controller, routeValues));\n anchorBuilder.InnerHtml = imgHtml; // include the <img> tag inside \n anchorBuilder.MergeAttributes<string, object>(ajaxOptions.ToUnobtrusiveHtmlAttributes());\n string anchorHtml = anchorBuilder.ToString(TagRenderMode.Normal);\n\n return MvcHtmlString.Create(anchorHtml);\n}\n url.Content(imageUrl)"
},
{
"answer_id": 23656271,
"author": "James Pusateri",
"author_id": 2667818,
"author_profile": "https://Stackoverflow.com/users/2667818",
"pm_score": 0,
"selected": false,
"text": "@using (Ajax.BeginForm( \"LoadTest\",\"Home\" , new System.Web.Mvc.Ajax.AjaxOptions { UpdateTargetId = \"[insert your target tag's id here]\" }))\n {\n <input type=\"image\" class=\"[css style class here]\" src=\"[insert image link here]\">\n }\n"
},
{
"answer_id": 26833157,
"author": "TotPeRo",
"author_id": 2327332,
"author_profile": "https://Stackoverflow.com/users/2327332",
"pm_score": 0,
"selected": false,
"text": " /// <summary>\n /// Create an Ajax.ActionLink with an associated glyphicon\n /// </summary>\n /// <param name=\"ajaxHelper\"></param>\n /// <param name=\"linkText\"></param>\n /// <param name=\"actionName\"></param>\n /// <param name=\"controllerName\"></param>\n /// <param name=\"glyphicon\"></param>\n /// <param name=\"ajaxOptions\"></param>\n /// <param name=\"routeValues\"></param>\n /// <param name=\"htmlAttributes\"></param>\n /// <returns></returns>\n public static MvcHtmlString ImageActionLink(this AjaxHelper ajaxHelper, string linkText, string actionName, string controllerName, string glyphicon, AjaxOptions ajaxOptions, RouteValueDictionary routeValues = null, object htmlAttributes = null)\n {\n //Example of result: \n //<a id=\"btnShow\" href=\"/Customers/ShowArtworks?customerId=1\" data-ajax-update=\"#pnlArtworks\" data-ajax-success=\"jsSuccess\"\n //data-ajax-mode=\"replace\" data-ajax-method=\"POST\" data-ajax-failure=\"jsFailure\" data-ajax-confirm=\"confirm\" data-ajax-complete=\"jsComplete\"\n //data-ajax-begin=\"jsBegin\" data-ajax=\"true\">\n // <i class=\"glyphicon glyphicon-pencil\"></i>\n // <span>Edit</span>\n //</a>\n\n var builderI = new TagBuilder(\"i\");\n builderI.MergeAttribute(\"class\", \"glyphicon \" + glyphicon);\n string iTag = builderI.ToString(TagRenderMode.Normal);\n\n string spanTag = \"\";\n if (!string.IsNullOrEmpty(linkText))\n {\n var builderSpan = new TagBuilder(\"span\") { InnerHtml = \" \" + linkText };\n spanTag = builderSpan.ToString(TagRenderMode.Normal);\n }\n\n //Create the \"a\" tag that wraps\n var builderA = new TagBuilder(\"a\");\n\n var requestContext = HttpContext.Current.Request.RequestContext;\n var uh = new UrlHelper(requestContext);\n\n builderA.MergeAttribute(\"href\", uh.Action(actionName, controllerName, routeValues));\n\n builderA.MergeAttributes(HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes));\n builderA.MergeAttributes((ajaxOptions).ToUnobtrusiveHtmlAttributes());\n\n builderA.InnerHtml = iTag + spanTag;\n\n return new MvcHtmlString(builderA.ToString(TagRenderMode.Normal));\n }\n"
},
{
"answer_id": 28395226,
"author": "user1972111",
"author_id": 1972111,
"author_profile": "https://Stackoverflow.com/users/1972111",
"pm_score": 0,
"selected": false,
"text": "<a data-ajax=\"true\" data-ajax-begin=\"...\" data-ajax-success=\"...\" href=\"@Url.Action(\"Delete\")\">\n<i class=\"halflings-icon remove\"></i>\n</a>\n <i class=\"halflings-icon remove\"></i>"
},
{
"answer_id": 46825406,
"author": "Jplum",
"author_id": 8799957,
"author_profile": "https://Stackoverflow.com/users/8799957",
"pm_score": 0,
"selected": false,
"text": "@MvcHtmlString.Create(Ajax.ActionLink(\"Spag\", \"Edit\", new { id = item.x0101EmployeeID }, new AjaxOptions() { UpdateTargetId = \"selectDiv\", InsertionMode = InsertionMode.Replace, HttpMethod = \"GET\" }).ToHtmlString().Replace(\"Spag\", \"<img src=\\\"\" + Url.Content(\"../../Images/edit.png\") + \"\\\" />\"))\n"
},
{
"answer_id": 54888104,
"author": "John Coder",
"author_id": 10739875,
"author_profile": "https://Stackoverflow.com/users/10739875",
"pm_score": -1,
"selected": false,
"text": " <a href=\"@Url.Action(\"index\", \"home\")\">\n <img src=\"~/Images/rocket.png\" width=\"25\" height=\"25\" title=\"Launcher\" />\n </a>\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341649",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
341,668 | <p>All objects in my program inherit from a Container class. The Container class has a <code>virtual BaseNode* getParent() const;</code> method and a <code>virtual void setParent(BaseNode *p);</code> method. </p>
<p>I have a <code>Set</code> class (Set in a tennis match, not a data structure) which has the <code>Match</code> class as it's parent (via <code>setParent()</code>) but since <code>Set</code> inherits from <code>Container</code>, The program creates a tree structure from the top down and the <code>Set</code> class is a child, it doesn't need to have methods to track and maintain information about it's parent beyond what <code>Container</code> provides. </p>
<p>The error <code>C++: invalid conversion from ‘BaseNode*’ to ‘Match*’</code> shows up in the method below when I try to compile my program. (<code>Player* getPlayer1() const;</code> only exists in the <code>Match</code> class)</p>
<pre><code>Player* Set::getPlayer1() const{
return getParent()->getPlayer1();
}
</code></pre>
<p>This is my inheritance structure for Match. (Note that <code>TreeNode</code> is a template)</p>
<pre><code>Match -> TreeNode<Set> -> BaseNode -> Container
</code></pre>
<p>I don't understand why I'm getting a conversation error. I have tried reading my textbook but it's a rather poor reference. Google just provided too much irrelevant information.</p>
<p><strong>Edit</strong></p>
<pre><code>Player* Set::getPlayer1() const{
return dynamic_cast<Match>(getParent())->getPlayer1();
}
</code></pre>
<p>causes</p>
<pre><code>error: cannot dynamic_cast ‘#‘obj_type_ref’ not supported by dump_expr#<expression error>((&((const Set*)this)->Set::<anonymous>))’ (of type ‘class BaseNode*’) to type ‘class Match’ (target is not pointer or reference)
</code></pre>
<p><strong>Edit 2</strong></p>
<p>I just realized I need <code>dynamic_cast<Match*></code> which works.</p>
| [
{
"answer_id": 341686,
"author": "Adam Rosenfield",
"author_id": 9530,
"author_profile": "https://Stackoverflow.com/users/9530",
"pm_score": 3,
"selected": true,
"text": "getParent() BaseNode* BaseNode BaseNode Match Match* getPlayer() Player* Set::getPlayer1() const{\n return dynamic_cast<Match*>(getParent())->getPlayer1();\n}\n Match dynamic_cast"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341668",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16204/"
] |
341,682 | <p>My hosting provider (pairNetworks) has certain rules for scripts run on the server. I'm trying to compress a file for backup purposes, and would ideally like to use bzip2 to take advantage of its AWESOME compression rate. However, when trying to compress this 90 MB file, the process sometimes runs upwards of 1.5 minutes. One of the resource rules is that a script may only execute for 30 CPU seconds.</p>
<p>If I use the nice command to 'nicefy' the process, does that break up the amount of total CPU processing time? Is there a different command I could use in place of nice? Or will I have to use a different compression utility that doesn't take as long?</p>
<p>Thanks!</p>
<hr>
<p><em>EDIT: This is what their support page says:</em></p>
<ul>
<li>Run any process that requires more
than 16MB of memory space. </li>
<li>Run any
program that requires more than 30
CPU seconds to complete.</li>
</ul>
<p><em>EDIT: I run this in a bash script from the command line</em></p>
| [
{
"answer_id": 341688,
"author": "bzlm",
"author_id": 7724,
"author_profile": "https://Stackoverflow.com/users/7724",
"pm_score": 3,
"selected": false,
"text": "nice"
},
{
"answer_id": 341690,
"author": "Rich",
"author_id": 42897,
"author_profile": "https://Stackoverflow.com/users/42897",
"pm_score": 1,
"selected": false,
"text": "nice"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341682",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42135/"
] |
341,691 | <p>I'm trying to pick a perforamnce analyzer to use. I'm a beginner developer and not sure what to look for in a performance analyzer. What are the most important features?</p>
| [
{
"answer_id": 341768,
"author": "Konrad Rudolph",
"author_id": 1968,
"author_profile": "https://Stackoverflow.com/users/1968",
"pm_score": 2,
"selected": false,
"text": "valgrind"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341691",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
341,695 | <p>I need to write some code to analyze whether or not a given user on our site is a bot. If it's a bot, we'll take some specific action. Looking at the User Agent is not something that is successful for anything but friendly bots, as you can specify any user agent you want in a bot. I'm after behaviors of unfriendly bots. Various ideas I've had so far are:</p>
<ul>
<li>If you don't have a browser ID</li>
<li>If you don't have a session ID</li>
<li>Unable to write a cookie</li>
</ul>
<p>Obviously, there are some cases where a legitimate user will look like a bot, but that's ok. Are there other programmatic ways to detect a bot, or either detect something that looks like a bot? </p>
| [
{
"answer_id": 341710,
"author": "Greg",
"author_id": 24181,
"author_profile": "https://Stackoverflow.com/users/24181",
"pm_score": 2,
"selected": false,
"text": "<script type=\"text/javascript\">\ndocument.write('<img src=\"/not-a-bot.' + 'php\" style=\"display: none;\">');\n</script>\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341695",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
341,696 | <p>I work with a number of new tech support folks. Sometimes, they like to fix small issues which may not be a high priority for our developers. This requires teaching SVN basics to non-programmers, which I've found can get a little tricky.</p>
<p>What resources have you found useful? Are there diagrams you typically utilize to teach SVN?</p>
| [
{
"answer_id": 341772,
"author": "Piotr Lesnicki",
"author_id": 38796,
"author_profile": "https://Stackoverflow.com/users/38796",
"pm_score": 1,
"selected": false,
"text": ".bak"
},
{
"answer_id": 342113,
"author": "NewCom",
"author_id": 33154,
"author_profile": "https://Stackoverflow.com/users/33154",
"pm_score": 1,
"selected": false,
"text": "http://www.slideshare.net/secret/wBsLzZb3O7cXCU\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341696",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13348/"
] |
341,708 | <p>I'm an email n00b but I am working on an application that sends HTML email with Unicode characters (as my friend noted "enjoy encoding hell").</p>
<p>The <code>Subject:</code> header comes from user input and therefore may contain Unicode characters. Some mail clients (like GMail and Outlook 2007) are OK with this, but from my reading it seems the right way to do this is to use <a href="http://en.wikipedia.org/wiki/MIME#Encoded-Word" rel="noreferrer">MIME Encoded-Word encoding</a> for the headers.</p>
<p>I cannot find a Ruby library to do this. Is there one?</p>
<p>Also, is there a header to add that will tell mail clients to use UTF-8 when displaying the message? We are sending multipart email so our <code>Content-Type</code> is <code>multipart/mixed</code>. Apple Mail.app in particular is not using the right encoding, even though it's specified in the individual parts as being UTF-8.</p>
| [
{
"answer_id": 341849,
"author": "Tomalak",
"author_id": 18771,
"author_profile": "https://Stackoverflow.com/users/18771",
"pm_score": 3,
"selected": false,
"text": "require \"base64\"\n\nvalue = Base64.encode64(\"Your UTF-8 string\")\nheader = \"=?UTF-8?B?\" + value + \"?=\"\n \"=\" + ByteCodeAsHex .gsub(/%/, \"=\")"
},
{
"answer_id": 341902,
"author": "Luke Francl",
"author_id": 17965,
"author_profile": "https://Stackoverflow.com/users/17965",
"pm_score": 4,
"selected": true,
"text": "ActionMailer::Quoting quoted_printable def my_email(foo)\n ...\n @subject = quoted_printable(foo.some_subject_with_accented_chars, 'utf-8')\n ...\nend\n"
},
{
"answer_id": 7416760,
"author": "Smar",
"author_id": 345959,
"author_profile": "https://Stackoverflow.com/users/345959",
"pm_score": 2,
"selected": false,
"text": "Net::SMTP.start(\"localhost\") do |smtp|\n smtp.open_message_stream opts[:sender_address], opts[:receiver_address] do |f|\n\n f.puts \"Content-type: text/plain; charset=UTF-8\"\n f.puts from\n f.puts to\n f.puts subject\n f.puts message\n end\nend\n From: Name here <address@here.fi> From: address@here.fi From: To: subject = \"Subject: =?UTF-8?B?\" + Base64.strict_encode64(subject) + \"?=\"\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341708",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17965/"
] |
341,723 | <p>I'm working with a bit of html and Javascript code that I've taken over from someone else. The page reloads a table of data (via an asynchronous request) every ten seconds, and then re-builds the table using some DOM code. The code in question looks something like this:</p>
<pre><code>var blah = xmlres.getElementsByTagName('blah');
for(var i = 0; i < blah.length; i++) {
var td = document.createElement('td');
var select = document.createElement('select');
select.setAttribute("...", "...");
select.onchange = function() {
onStatusChanged(select, callid, anotherid);
};
td.appendChild(select);
}
</code></pre>
<p>When the <code>onchange</code> event is fired for a <code><select></code> element however, it seems like the same values are being passed to the <code>onStatusChanged()</code> method for every <code><select></code> in the table (I've verified that in each iteration of the loop, <code>callid</code> and <code>anotherid</code> are being given new, distinct values). </p>
<p>I suspect this is occuring because of the nature of how I am setting the event handler, with the <code>select.onchange = function()</code> syntax. If I understand how this is working correctly, this syntax sets a closure for the onchange event to be a function which refers to these two references, which end up having a final value of whatever they are set to on the last iteration of the loop. When the event fires, the value referenced by <code>callid</code> and <code>anotherid</code> is the value set in the last iteration, not the value set at the individual iteration.</p>
<p>Is there a way that I can copy the value of the parameters I am passing to <code>onStatusChanged()</code>?</p>
<p><em>I've changed the title to better reflect the question and the accepted answer.</em></p>
| [
{
"answer_id": 341759,
"author": "Peter Bailey",
"author_id": 8815,
"author_profile": "https://Stackoverflow.com/users/8815",
"pm_score": 7,
"selected": true,
"text": "var blah = xmlres.getElementsByTagName('blah');\nfor(var i = 0; i < blah.length; i++) {\n var td = document.createElement('td');\n var select = document.createElement('select');\n select.setAttribute(\"...\", \"...\");\n select.onchange = function(s,c,a)\n {\n return function()\n {\n onStatusChanged(s,c,a);\n }\n }(select, callid, anotherid);\n td.appendChild(select);\n}\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341723",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4249/"
] |
341,734 | <p>I've got no experience with this, so i suspect my logic is overly complicated, or perhaps not complete enough to do what I want. </p>
<p>I have a basic tile based system, but want to move units over the terrain in a coninuous fashion. Right now they are "teleporting" from one tile to another.</p>
<p>I already have a lot of the game logic set up on the tile system,for things like path-finding, cover, terrain type, etc.</p>
<p>My first guess it to have a floating point x/y offset from the center of the unit and the center of a tile, having 0.0 being in the center, and 1.0 being on an edge. This would be for each tile a unit overlaps. Then i can do math to figure out which tile the unit is "most" on, and use that tile for the path-finding logic. </p>
<p>To make it nice, as the unit moves I'd have it adjust the ofset so that he gradually will position himself with the tile line, and not make a bunch of 90* turns to hit the path'd tiles. I could then do some fancy stuff to make him curve gracefully around corners.</p>
<p>For things like wepon distances, i could use the x/y tile distance, then subract out the x/y offsets to get a simple pathagorean distance.</p>
<p>What would be a sucessful way to decouple the movement from the tile, and still be able to "link" the unit to the tile? </p>
| [
{
"answer_id": 341803,
"author": "Markus Jarderot",
"author_id": 22364,
"author_profile": "https://Stackoverflow.com/users/22364",
"pm_score": 1,
"selected": false,
"text": "(3.141592, 2.718282) -> (3, 3)\n (3.141592, 2.718282) -> (0.141592, 0.718282) -> (14, 72)\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341734",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42082/"
] |
341,737 | <p>I have the following query which works except that I would like it to behave differently. Now it looks for all the duplicate rows on <code>url</code> and returns it in the order of number of duplicate urls. I use GROUP_ CONCAT to seperate all the different screen_name's. </p>
<p>However there can be multiple rows with the same url and same screen_name. How do I make it so that it only retreives the rows where screen_name is distinct.</p>
<pre><code>SELECT url, title, GROUP_CONCAT( screen_name ) , COUNT( t_uid )
FROM `twl_links`
WHERE twl_uid =3
AND timestamp >= NOW( ) - INTERVAL 24 HOUR
GROUP BY (
url
)
ORDER BY COUNT( t_uid ) DESC
</code></pre>
| [
{
"answer_id": 341793,
"author": "derobert",
"author_id": 27727,
"author_profile": "https://Stackoverflow.com/users/27727",
"pm_score": 2,
"selected": false,
"text": "t_uid url title screen_name\n1 http://google.com/ Google bob\n2 http://google.com/ Google Search bob\n3 http://google.com/ Google tom\n http://www.google.com '???' 'bob,tom' 2\n SELECT DISTINCT FROM twl_links http://www.google.com '???' 'bob,tom' 3\n GROUP_CONCAT(DISTINCT screen_name)"
},
{
"answer_id": 341874,
"author": "cpm",
"author_id": 3674,
"author_profile": "https://Stackoverflow.com/users/3674",
"pm_score": 2,
"selected": false,
"text": "SELECT t1.url, GROUP_CONCAT( t1.screen_name ) , COUNT( * ) \nFROM (\n SELECT DISTINCT url, screen_name\n FROM mytable\n) AS t1\nGROUP BY t1.url\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341737",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
341,743 | <p>I'm used to passing around string like this in my C++ applications:</p>
<pre><code>void foo(const std::string& input)
{
std::cout << input.size() << std::endl;
}
void bar()
{
foo("stackoverflow");
}
</code></pre>
<p>Now I have a case where I want the string to be NULL:</p>
<pre><code>void baz()
{
foo("stackoverflow");
foo(NULL); // very bad with foo implementation above
}
</code></pre>
<p>I could change <code>foo</code> to:</p>
<pre><code>void foo(const std::string* input)
{
// TODO: support NULL input
std::cout << input->size() << std::endl;
}
</code></pre>
<p>But to pass a string literal or copy a <code>char*</code> to that implementation of <code>foo</code> I need to write something like this:</p>
<pre><code>void bar()
{
string input("hi"); // annoying temporary
foo(&input);
foo(NULL); // will work as long as foo handles NULL properly
}
</code></pre>
<p>I started thinking about inheriting from <code>std::string</code> and adding a <code>null</code> property, but I'm not so sure it's a good idea. Maybe it is better to simply use a <code>const char*</code> string for parameters that can be NULL, but what if I want to save a copy of the string (or NULL) without having to manage its memory myself? (See <a href="https://stackoverflow.com/questions/312570/what-are-some-of-the-drawbacks-to-using-c-style-strings">What are some of the drawbacks to using C-style strings?</a> etc.)</p>
<p>Any clever solution around?</p>
| [
{
"answer_id": 341751,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 1,
"selected": false,
"text": "void foo(const char *xinput)\n{\n if (xinput == NULL) {\n // do something exceptional with this\n return;\n }\n std::string input(xinput);\n // remainder of code as usual\n}\n .c_str()"
},
{
"answer_id": 341766,
"author": "Max Lybbert",
"author_id": 10593,
"author_profile": "https://Stackoverflow.com/users/10593",
"pm_score": 3,
"selected": false,
"text": "void foo(const std::string& input)\n{\n if (!input.empty())\n std::cout << input.size() << std::endl;\n}\n\nvoid bar()\n{\n foo(\"\");\n}\n"
},
{
"answer_id": 341778,
"author": "Konrad Rudolph",
"author_id": 1968,
"author_profile": "https://Stackoverflow.com/users/1968",
"pm_score": 2,
"selected": false,
"text": "std::string void foo_impl(string const* pstr) { … }\n\nvoid foo(string const& str) {\n foo_impl(&str);\n}\n\nvoid foo() {\n foo_impl(0);\n}\n"
},
{
"answer_id": 341799,
"author": "eplawless",
"author_id": 1370,
"author_profile": "https://Stackoverflow.com/users/1370",
"pm_score": 4,
"selected": false,
"text": "void foo( const std::string& input )\n{\n std::cout << input << std::endl;\n\n // do more things ...\n}\n\nvoid foo( const char* input )\n{\n if ( input != NULL ) foo( std::string(input) );\n}\n"
},
{
"answer_id": 341888,
"author": "Matt McClellan",
"author_id": 35218,
"author_profile": "https://Stackoverflow.com/users/35218",
"pm_score": 2,
"selected": false,
"text": "void fooImpl( const char* input )\n{\n if ( input != NULL )\n std::cout << input << std::endl;\n}\n\nvoid foo( const std::string& input )\n{\n fooImpl(input.c_str()); \n}\n\nvoid foo( const char* input )\n{\n fooImpl(input);\n}\n"
},
{
"answer_id": 342792,
"author": "Tom",
"author_id": 40620,
"author_profile": "https://Stackoverflow.com/users/40620",
"pm_score": 2,
"selected": false,
"text": "std::string const char* std::string *"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341743",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20444/"
] |
341,781 | <p>Does anybody know how I can close all modal dialogs created by Dojo ? Apparently there used to be a dojo.popup.closeAll function, but this is no longer available in the latest version of the Dojo API that comes with Spring JS.</p>
| [
{
"answer_id": 394987,
"author": "user49360",
"author_id": 49360,
"author_profile": "https://Stackoverflow.com/users/49360",
"pm_score": 2,
"selected": false,
"text": "dijit.registry.filter(function(w){ \n return w && w.declaredClass == \"dijit.Dialog\" \n}).forEach(function(w){ \n w.hide(); \n});\n"
},
{
"answer_id": 564233,
"author": "pierdeux",
"author_id": 53747,
"author_profile": "https://Stackoverflow.com/users/53747",
"pm_score": 0,
"selected": false,
"text": "href title"
},
{
"answer_id": 31318175,
"author": "widecr0w",
"author_id": 5098628,
"author_profile": "https://Stackoverflow.com/users/5098628",
"pm_score": 0,
"selected": false,
"text": "define(['dijit/registry'], ...\n\nregistery.toArray().filter(function(w){ \n return w && w.declaredClass == \"dijit.Dialog\" \n}).forEach(function(w){ \n w.hide(); \n});\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341781",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32232/"
] |
341,792 | <p>If my domain objects implement IDataErrorInfo, and I am using M-V-VM, how do I propagate errors through the ViewModel into the View? If i was binding directly to the model, I would set the "ValidateOnExceptons" and "ValidateOnErrors" properties to true on my binding. But my ViewModel doesn't implement IDataErrorInfo. Only my model. What do I do?</p>
<p><strong>Clarification</strong>
I am dealing with an existing codebase that implements IDataErrorInfo in the domain objects. I can't just implement IDataErrorInfo in the my view model.</p>
| [
{
"answer_id": 1591410,
"author": "artur02",
"author_id": 13937,
"author_profile": "https://Stackoverflow.com/users/13937",
"pm_score": 2,
"selected": false,
"text": "<TextBox x:Name=\"title\" VerticalAlignment=\"Top\" TextWrapping=\"Wrap\" Grid.Column=\"1\" MinWidth=\"20\">\n <TextBox.Text>\n <Binding Path=\"Title\" UpdateSourceTrigger=\"LostFocus\">\n <Binding.ValidationRules>\n <Validators:StringRangeValidationRule MinimumLength=\"1\" MaximumLength=\"30\" \n ErrorMessage=\"Address is required and must be less than 30 letters.\" />\n </Binding.ValidationRules>\n </Binding>\n </TextBox.Text>\n</TextBox>\n <Application.Resources>\n <Style TargetType=\"{x:Type TextBox}\">\n <Setter Property=\"Validation.ErrorTemplate\">\n <Setter.Value>\n <ControlTemplate>\n <DockPanel LastChildFill=\"True\">\n <Image Source=\"/Images/error.png\" Width=\"25\" Height=\"25\" ToolTip=\"{Binding ElementName=MyAdorner, Path=AdornedElement.(Validation.Errors)[0].ErrorContent}\" />\n <TextBlock DockPanel.Dock=\"Right\"\n Foreground=\"Orange\"\n Margin=\"5\" \n FontSize=\"12pt\"\n Text=\"{Binding ElementName=MyAdorner, Path=AdornedElement.(Validation.Errors)[0].ErrorContent}\">\n </TextBlock>\n\n <Border BorderBrush=\"Red\" BorderThickness=\"3\">\n <AdornedElementPlaceholder Name=\"MyAdorner\" />\n </Border>\n </DockPanel>\n </ControlTemplate>\n </Setter.Value>\n</Setter>\n<Style.Triggers>\n <Trigger Property=\"Validation.HasError\" Value=\"true\">\n <Setter Property=\"ToolTip\"\n Value=\"{Binding RelativeSource={RelativeSource Self}, \n Path=(Validation.Errors)[0].ErrorContent}\"/>\n </Trigger>\n</Style.Triggers>\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341792",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17744/"
] |
341,807 | <p>How do I bind a CheckBoxField in my GridView to an underlying db field that is a string. The string is either "1" or "0" but all the same the GridView won't willingly bind to it. What do I do. What is the best way to have a checkbox in the GridView and have it get and set the string in the database (or the underlying datasource).</p>
| [
{
"answer_id": 341819,
"author": "BenAlabaster",
"author_id": 40650,
"author_profile": "https://Stackoverflow.com/users/40650",
"pm_score": 3,
"selected": false,
"text": "Checked='<%# DataBinder.Eval(Container.DataItem, \"MyStringField\") = \"1\" %>'\n"
},
{
"answer_id": 7343120,
"author": "sougata mukherjee",
"author_id": 934029,
"author_profile": "https://Stackoverflow.com/users/934029",
"pm_score": 1,
"selected": false,
"text": "<asp:checkbox runat=\"server\" id=\"chkCastCool\" enabled=\"false\" \n checked='<%CType(DataBinder.Eval(Container.DataItem,\"Cast_Cool\").ToString().Replace(\"Y\",\"True\").Replace(\"N\",\"False\"),Boolean)%>'/>\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341807",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4491/"
] |
341,810 | <p>Suppose you have output like this:</p>
<pre><code>Word1 Word2 Word3 Word4
</code></pre>
<p>Where the number of spaces between words is arbitrary. I want to break it into an array of words.</p>
<p>I used the following code:</p>
<pre><code>string[] tokens =
new List<String>(input.Split(' '))
.FindAll
(
delegate(string token)
{
return token != String.Empty;
}
).ToArray();
</code></pre>
<p>Not exactly efficient, but does the job nicely.</p>
<p>How would you do it?</p>
| [
{
"answer_id": 341828,
"author": "Joel Coehoorn",
"author_id": 3043,
"author_profile": "https://Stackoverflow.com/users/3043",
"pm_score": 5,
"selected": true,
"text": "string[] tokens = input.Split(new char[] { ' ' },\n StringSplitOptions.RemoveEmptyEntries); \n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341810",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1965/"
] |
341,817 | <p>I'm porting a relatively simple console program written for Unix to the Windows platform (<a href="http://en.wikipedia.org/wiki/Visual_C++#32-bit_versions" rel="noreferrer">Visual C++ 8.0</a>). All the source files include "unistd.h", which doesn't exist. Removing it, I get complaints about misssing prototypes for 'srandom', 'random', and 'getopt'.
I know I can replace the random functions, and I'm pretty sure I can find/hack-up a getopt implementation. </p>
<p>But I'm sure others have run into the same challenge.
My question is: is there a port of "unistd.h" to Windows? At least one containg those functions which do have a native Windows implementation - I don't need pipes or forking.</p>
<p><strong>EDIT</strong>:</p>
<p>I know I can create my very own "unistd.h" which contains replacements for the things I need - especially in this case, since it is a limited set. But since it seems like a common problem, I was wondering if someone had done the work already for a bigger subset of the functionality.</p>
<p>Switching to a different compiler or environment isn't possible at work - I'm stuck with Visual Studio.</p>
| [
{
"answer_id": 341941,
"author": "e.James",
"author_id": 33686,
"author_profile": "https://Stackoverflow.com/users/33686",
"pm_score": 5,
"selected": false,
"text": "unistd.h"
},
{
"answer_id": 826027,
"author": "AShelly",
"author_id": 10396,
"author_profile": "https://Stackoverflow.com/users/10396",
"pm_score": 9,
"selected": true,
"text": "#ifndef _UNISTD_H\n#define _UNISTD_H 1\n\n/* This is intended as a drop-in replacement for unistd.h on Windows.\n * Please add functionality as neeeded.\n * https://stackoverflow.com/a/826027/1202830\n */\n\n#include <stdlib.h>\n#include <io.h>\n#include <getopt.h> /* getopt at: https://gist.github.com/ashelly/7776712 */\n#include <process.h> /* for getpid() and the exec..() family */\n#include <direct.h> /* for _getcwd() and _chdir() */\n\n#define srandom srand\n#define random rand\n\n/* Values for the second argument to access.\n These may be OR'd together. */\n#define R_OK 4 /* Test for read permission. */\n#define W_OK 2 /* Test for write permission. */\n//#define X_OK 1 /* execute permission - unsupported in windows*/\n#define F_OK 0 /* Test for existence. */\n\n#define access _access\n#define dup2 _dup2\n#define execve _execve\n#define ftruncate _chsize\n#define unlink _unlink\n#define fileno _fileno\n#define getcwd _getcwd\n#define chdir _chdir\n#define isatty _isatty\n#define lseek _lseek\n/* read, write, and close are NOT being #defined here, because while there are file handle specific versions for Windows, they probably don't work for sockets. You need to look at your app and consider whether to call e.g. closesocket(). */\n\n#ifdef _WIN64\n#define ssize_t __int64\n#else\n#define ssize_t long\n#endif\n\n#define STDIN_FILENO 0\n#define STDOUT_FILENO 1\n#define STDERR_FILENO 2\n/* should be in some equivalent to <sys/types.h> */\ntypedef __int8 int8_t;\ntypedef __int16 int16_t; \ntypedef __int32 int32_t;\ntypedef __int64 int64_t;\ntypedef unsigned __int8 uint8_t;\ntypedef unsigned __int16 uint16_t;\ntypedef unsigned __int32 uint32_t;\ntypedef unsigned __int64 uint64_t;\n\n#endif /* unistd.h */\n"
},
{
"answer_id": 1759731,
"author": "anonymous",
"author_id": 214168,
"author_profile": "https://Stackoverflow.com/users/214168",
"pm_score": 7,
"selected": false,
"text": "io.h unistd.h"
},
{
"answer_id": 8243548,
"author": "Eelke Spaak",
"author_id": 1062071,
"author_profile": "https://Stackoverflow.com/users/1062071",
"pm_score": 4,
"selected": false,
"text": "getpid() unistd.h process.h"
},
{
"answer_id": 15893895,
"author": "Agi Hammerthief",
"author_id": 2225787,
"author_profile": "https://Stackoverflow.com/users/2225787",
"pm_score": 1,
"selected": false,
"text": "\\MinGW\\include \\MinGW\\include\\sys \\MinGW\\lib\\gcc\\mingw32\\4.6.2\\include\\ssp /*\n * unistd.h\n *\n * Standard header file declaring MinGW's POSIX compatibility features.\n *\n * $Id: unistd.h,v c3ebd36f8211 2016/02/16 16:05:39 keithmarshall $\n *\n * Written by Rob Savoye <rob@cygnus.com>\n * Modified by Earnie Boyd <earnie@users.sourceforge.net>\n * Danny Smith <dannysmith@users.sourceforge.net>\n * Ramiro Polla <ramiro@lisha.ufsc.br>\n * Gregory McGarry <gregorymcgarry@users.sourceforge.net>\n * Keith Marshall <keithmarshall@users.sourceforge.net>\n * Copyright (C) 1997, 1999, 2002-2004, 2007-2009, 2014-2016,\n * MinGW.org Project.\n *\n *\n * Permission is hereby granted, free of charge, to any person obtaining a\n * copy of this software and associated documentation files (the \"Software\"),\n * to deal in the Software without restriction, including without limitation\n * the rights to use, copy, modify, merge, publish, distribute, sublicense,\n * and/or sell copies of the Software, and to permit persons to whom the\n * Software is furnished to do so, subject to the following conditions:\n *\n * The above copyright notice, this permission notice, and the following\n * disclaimer shall be included in all copies or substantial portions of\n * the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF OR OTHER\n * DEALINGS IN THE SOFTWARE.\n *\n */\n#ifndef _UNISTD_H\n#define _UNISTD_H 1\n#pragma GCC system_header\n\n/* All MinGW headers MUST include _mingw.h before anything else,\n * to ensure proper initialization of feature test macros.\n */\n#include <_mingw.h>\n\n/* unistd.h maps (roughly) to Microsoft's <io.h>\n * Other headers included by <unistd.h> may be selectively processed;\n * __UNISTD_H_SOURCED__ enables such selective processing.\n */\n#define __UNISTD_H_SOURCED__ 1\n\n#include <io.h>\n#include <process.h>\n#include <getopt.h>\n\n/* These are defined in stdio.h. POSIX also requires that they\n * are to be consistently defined here; don't guard against prior\n * definitions, as this might conceal inconsistencies.\n */\n#define SEEK_SET 0\n#define SEEK_CUR 1\n#define SEEK_END 2\n\n#if _POSIX_C_SOURCE\n/* POSIX process/thread suspension functions; all are supported by a\n * common MinGW API in libmingwex.a, providing for suspension periods\n * ranging from mean values of ~7.5 milliseconds, (see the comments in\n * <time.h>), extending up to a maximum of ~136 years.\n *\n * Note that, whereas POSIX supports early wake-up of any suspended\n * process/thread, in response to a signal, this implementation makes\n * no attempt to emulate this signalling behaviour, (since signals are\n * not well supported by Windows); thus, unless impeded by an invalid\n * argument, this implementation always returns an indication as if\n * the sleeping period ran to completion.\n */\n_BEGIN_C_DECLS\n\n__cdecl __MINGW_NOTHROW\nint __mingw_sleep( unsigned long, unsigned long );\n\n/* The nanosleep() function provides the most general purpose API for\n * process/thread suspension; it is declared in <time.h>, (where it is\n * accompanied by an in-line implementation), rather than here, and it\n * provides for specification of suspension periods in the range from\n * ~7.5 ms mean, (on WinNT derivatives; ~27.5 ms on Win9x), extending\n * up to ~136 years, (effectively eternity).\n *\n * The usleep() function, and its associated useconds_t type specifier\n * were made obsolete in POSIX.1-2008; declared here, only for backward\n * compatibility, its continued use is not recommended. (It is limited\n * to specification of suspension periods ranging from ~7.5 ms mean up\n * to a maximum of 999,999 microseconds only).\n */\ntypedef unsigned long useconds_t __MINGW_ATTRIB_DEPRECATED;\nint __cdecl __MINGW_NOTHROW usleep( useconds_t )__MINGW_ATTRIB_DEPRECATED;\n\n#ifndef __NO_INLINE__\n__CRT_INLINE __LIBIMPL__(( FUNCTION = usleep ))\nint usleep( useconds_t period ){ return __mingw_sleep( 0, 1000 * period ); }\n#endif\n\n/* The sleep() function is, perhaps, the most commonly used of all the\n * process/thread suspension APIs; it provides support for specification\n * of suspension periods ranging from 1 second to ~136 years. (However,\n * POSIX recommends limiting the maximum period to 65535 seconds, to\n * maintain portability to platforms with only 16-bit ints).\n */\nunsigned __cdecl __MINGW_NOTHROW sleep( unsigned );\n\n#ifndef __NO_INLINE__\n__CRT_INLINE __LIBIMPL__(( FUNCTION = sleep ))\nunsigned sleep( unsigned period ){ return __mingw_sleep( period, 0 ); }\n#endif\n\n\n/* POSIX ftruncate() function.\n *\n * Microsoft's _chsize() function is incorrectly described, on MSDN,\n * as a preferred replacement for the POSIX chsize() function. There\n * never was any such POSIX function; the actual POSIX equivalent is\n * the ftruncate() function.\n */\nint __cdecl ftruncate( int, off_t );\n\n#ifndef __NO_INLINE__\n__CRT_INLINE __JMPSTUB__(( FUNCTION = ftruncate, REMAPPED = _chsize ))\nint ftruncate( int __fd, off_t __length ){ return _chsize( __fd, __length ); }\n#endif\n\n_END_C_DECLS\n\n#endif /* _POSIX_C_SOURCE */\n\n#undef __UNISTD_H_SOURCED__\n#endif /* ! _UNISTD_H: $RCSfile: unistd.h,v $: end of file */\n _mingw.h #ifndef __MINGW_H\n/*\n * _mingw.h\n *\n * MinGW specific macros included by ALL mingwrt include files; (this file\n * is part of the MinGW32 runtime library package).\n *\n * $Id: _mingw.h.in,v 7daa0459f602 2016/05/03 17:40:54 keithmarshall $\n *\n * Written by Mumit Khan <khan@xraylith.wisc.edu>\n * Copyright (C) 1999, 2001-2011, 2014-2016, MinGW.org Project\n *\n *\n * Permission is hereby granted, free of charge, to any person obtaining a\n * copy of this software and associated documentation files (the \"Software\"),\n * to deal in the Software without restriction, including without limitation\n * the rights to use, copy, modify, merge, publish, distribute, sublicense,\n * and/or sell copies of the Software, and to permit persons to whom the\n * Software is furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice (including the next\n * paragraph) shall be included in all copies or substantial portions of the\n * Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\n * DEALINGS IN THE SOFTWARE.\n *\n */\n#define __MINGW_H\n\n/* In previous versions, __MINGW32_VERSION was expressed as a dotted\n * numeric pair, representing major.minor; unfortunately, this doesn't\n * adapt well to the inclusion of a patch-level component, since the\n * major.minor.patch dotted triplet representation is not valid as a\n * numeric entity. Thus, for this version, we adopt a representation\n * which encodes the version as a long integer value, expressing:\n *\n * __MINGW32_VERSION = 1,000,000 * major + 1,000 * minor + patch\n *\n * DO NOT EDIT these package version assignments manually; they are\n * derived from the package version specification within configure.ac,\n * whence they are propagated automatically, at package build time.\n */\n#define __MINGW32_VERSION 3022001L\n#define __MINGW32_MAJOR_VERSION 3\n#define __MINGW32_MINOR_VERSION 22\n#define __MINGW32_PATCHLEVEL 1\n\n#if __GNUC__ >= 3 && ! defined __PCC__\n#pragma GCC system_header\n#endif\n\n#ifndef _MSVCRTVER_H\n/* Legacy versions of mingwrt use the macro __MSVCRT_VERSION__ to\n * enable evolving features of different MSVCRT.DLL versions. This\n * usage is no longer recommended, but the __MSVCRT_VERSION__ macro\n * remains useful when a non-freely distributable MSVCRxx.DLL is to\n * be substituted for MSVCRT.DLL; for such usage, the substitute\n * MSVCRxx.DLL may be identified as specified in...\n */\n# include <msvcrtver.h>\n#endif\n\n/* A better inference than __MSVCRT_VERSION__, of the capabilities\n * supported by the operating system default MSVCRT.DLL, is provided\n * by the Windows API version identification macros.\n */\n#include <w32api.h>\n\n/* The following are defined by the user (or by the compiler), to specify how\n * identifiers are imported from a DLL. All headers should include this first,\n * and then use __DECLSPEC_SUPPORTED to choose between the old ``__imp__name''\n * style or the __MINGW_IMPORT style for declarations.\n *\n * __DECLSPEC_SUPPORTED Defined if dllimport attribute is supported.\n * __MINGW_IMPORT The attribute definition to specify imported\n * variables/functions.\n * _CRTIMP As above. For MS compatibility.\n *\n * Macros to enable MinGW features which deviate from standard MSVC\n * compatible behaviour; these may be specified directly in user code,\n * activated implicitly, (e.g. by specifying _POSIX_C_SOURCE or such),\n * or by inclusion in __MINGW_FEATURES__:\n *\n * __USE_MINGW_ANSI_STDIO Select a more ANSI C99 compatible\n * implementation of printf() and friends;\n * (users should not set this directly).\n *\n * Other macros:\n *\n * __int64 define to be long long. Using a typedef\n * doesn't work for \"unsigned __int64\"\n *\n *\n * Manifest definitions for flags to control globbing of the command line\n * during application start up, (before main() is called). The first pair,\n * when assigned as bit flags within _CRT_glob, select the globbing algorithm\n * to be used; (the MINGW algorithm overrides MSCVRT, if both are specified).\n * Prior to mingwrt-3.21, only the MSVCRT option was supported; this choice\n * may produce different results, depending on which particular version of\n * MSVCRT.DLL is in use; (in recent versions, it seems to have become\n * definitively broken, when globbing within double quotes).\n */\n#define __CRT_GLOB_USE_MSVCRT__ 0x0001\n\n/* From mingwrt-3.21 onward, this should be the preferred choice; it will\n * produce consistent results, regardless of the MSVCRT.DLL version in use.\n */\n#define __CRT_GLOB_USE_MINGW__ 0x0002\n\n/* When the __CRT_GLOB_USE_MINGW__ flag is set, within _CRT_glob, the\n * following additional options are also available; they are not enabled\n * by default, but the user may elect to enable any combination of them,\n * by setting _CRT_glob to the boolean sum (i.e. logical OR combination)\n * of __CRT_GLOB_USE_MINGW__ and the desired options.\n *\n * __CRT_GLOB_USE_SINGLE_QUOTE__ allows use of single (apostrophe)\n * quoting characters, analogously to\n * POSIX usage, as an alternative to\n * double quotes, for collection of\n * arguments separated by white space\n * into a single logical argument.\n *\n * __CRT_GLOB_BRACKET_GROUPS__ enable interpretation of bracketed\n * character groups as POSIX compatible\n * globbing patterns, matching any one\n * character which is either included\n * in, or excluded from the group.\n *\n * __CRT_GLOB_CASE_SENSITIVE__ enable case sensitive matching for\n * globbing patterns; this is default\n * behaviour for POSIX, but because of\n * the case insensitive nature of the\n * MS-Windows file system, it is more\n * appropriate to use case insensitive\n * globbing as the MinGW default.\n *\n */\n#define __CRT_GLOB_USE_SINGLE_QUOTE__ 0x0010\n#define __CRT_GLOB_BRACKET_GROUPS__ 0x0020\n#define __CRT_GLOB_CASE_SENSITIVE__ 0x0040\n\n/* The MinGW globbing algorithm uses the ASCII DEL control code as a marker\n * for globbing characters which were embedded within quoted arguments; (the\n * quotes are stripped away BEFORE the argument is globbed; the globbing code\n * treats the marked character as immutable, and strips out the DEL markers,\n * before storing the resultant argument). The DEL code is mapped to this\n * function here; DO NOT change it, without rebuilding the runtime.\n */\n#define __CRT_GLOB_ESCAPE_CHAR__ (char)(127)\n\n\n/* Manifest definitions identifying the flag bits, controlling activation\n * of MinGW features, as specified by the user in __MINGW_FEATURES__.\n */\n#define __MINGW_ANSI_STDIO__ 0x0000000000000001ULL\n/*\n * The following three are not yet formally supported; they are\n * included here, to document anticipated future usage.\n */\n#define __MINGW_LC_EXTENSIONS__ 0x0000000000000050ULL\n#define __MINGW_LC_MESSAGES__ 0x0000000000000010ULL\n#define __MINGW_LC_ENVVARS__ 0x0000000000000040ULL\n\n\n/* Try to avoid problems with outdated checks for GCC __attribute__ support.\n */\n#undef __attribute__\n\n#if defined (__PCC__)\n# undef __DECLSPEC_SUPPORTED\n# ifndef __MINGW_IMPORT\n# define __MINGW_IMPORT extern\n# endif\n# ifndef _CRTIMP\n# define _CRTIMP\n# endif\n# ifndef __cdecl\n# define __cdecl _Pragma(\"cdecl\")\n# endif\n# ifndef __stdcall\n# define __stdcall _Pragma(\"stdcall\")\n# endif\n# ifndef __int64\n# define __int64 long long\n# endif\n# ifndef __int32\n# define __int32 long\n# endif\n# ifndef __int16\n# define __int16 short\n# endif\n# ifndef __int8\n# define __int8 char\n# endif\n# ifndef __small\n# define __small char\n# endif\n# ifndef __hyper\n# define __hyper long long\n# endif\n# ifndef __volatile__\n# define __volatile__ volatile\n# endif\n# ifndef __restrict__\n# define __restrict__ restrict\n# endif\n# define NONAMELESSUNION\n#elif defined(__GNUC__)\n# ifdef __declspec\n# ifndef __MINGW_IMPORT\n /* Note the extern. This is needed to work around GCC's\n limitations in handling dllimport attribute. */\n# define __MINGW_IMPORT extern __attribute__((__dllimport__))\n# endif\n# ifndef _CRTIMP\n# ifdef __USE_CRTIMP\n# define _CRTIMP __attribute__((dllimport))\n# else\n# define _CRTIMP\n# endif\n# endif\n# define __DECLSPEC_SUPPORTED\n# else /* __declspec */\n# undef __DECLSPEC_SUPPORTED\n# undef __MINGW_IMPORT\n# ifndef _CRTIMP\n# define _CRTIMP\n# endif\n# endif /* __declspec */\n/*\n * The next two defines can cause problems if user code adds the\n * __cdecl attribute like so:\n * void __attribute__ ((__cdecl)) foo(void);\n */\n# ifndef __cdecl\n# define __cdecl __attribute__((__cdecl__))\n# endif\n# ifndef __stdcall\n# define __stdcall __attribute__((__stdcall__))\n# endif\n# ifndef __int64\n# define __int64 long long\n# endif\n# ifndef __int32\n# define __int32 long\n# endif\n# ifndef __int16\n# define __int16 short\n# endif\n# ifndef __int8\n# define __int8 char\n# endif\n# ifndef __small\n# define __small char\n# endif\n# ifndef __hyper\n# define __hyper long long\n# endif\n#else /* ! __GNUC__ && ! __PCC__ */\n# ifndef __MINGW_IMPORT\n# define __MINGW_IMPORT __declspec(dllimport)\n# endif\n# ifndef _CRTIMP\n# define _CRTIMP __declspec(dllimport)\n# endif\n# define __DECLSPEC_SUPPORTED\n# define __attribute__(x) /* nothing */\n#endif\n\n#if defined (__GNUC__) && defined (__GNUC_MINOR__)\n#define __MINGW_GNUC_PREREQ(major, minor) \\\n (__GNUC__ > (major) \\\n || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))\n#else\n#define __MINGW_GNUC_PREREQ(major, minor) 0\n#endif\n\n#ifdef __cplusplus\n# define __CRT_INLINE inline\n#else\n# if __GNUC_STDC_INLINE__\n# define __CRT_INLINE extern inline __attribute__((__gnu_inline__))\n# else\n# define __CRT_INLINE extern __inline__\n# endif\n#endif\n\n# ifdef __GNUC__\n /* A special form of __CRT_INLINE is provided; it will ALWAYS request\n * inlining when possible. Originally specified as _CRTALIAS, this is\n * now deprecated in favour of __CRT_ALIAS, for syntactic consistency\n * with __CRT_INLINE itself.\n */\n# define _CRTALIAS __CRT_INLINE __attribute__((__always_inline__))\n# define __CRT_ALIAS __CRT_INLINE __attribute__((__always_inline__))\n# else\n# define _CRTALIAS __CRT_INLINE /* deprecated form */\n# define __CRT_ALIAS __CRT_INLINE /* preferred form */\n# endif\n/*\n * Each function which is implemented as a __CRT_ALIAS should also be\n * accompanied by an externally visible interface. The following pair\n * of macros provide a mechanism for implementing this, either as a stub\n * redirecting to an alternative external function, or by compilation of\n * the normally inlined code into free standing object code; each macro\n * provides a way for us to offer arbitrary hints for use by the build\n * system, while remaining transparent to the compiler.\n */\n#define __JMPSTUB__(__BUILD_HINT__)\n#define __LIBIMPL__(__BUILD_HINT__)\n\n#ifdef __cplusplus\n# define __UNUSED_PARAM(x)\n#else\n# ifdef __GNUC__\n# define __UNUSED_PARAM(x) x __attribute__((__unused__))\n# else\n# define __UNUSED_PARAM(x) x\n# endif\n#endif\n\n#ifdef __GNUC__\n#define __MINGW_ATTRIB_NORETURN __attribute__((__noreturn__))\n#define __MINGW_ATTRIB_CONST __attribute__((__const__))\n#else\n#define __MINGW_ATTRIB_NORETURN\n#define __MINGW_ATTRIB_CONST\n#endif\n\n#if __MINGW_GNUC_PREREQ (3, 0)\n#define __MINGW_ATTRIB_MALLOC __attribute__((__malloc__))\n#define __MINGW_ATTRIB_PURE __attribute__((__pure__))\n#else\n#define __MINGW_ATTRIB_MALLOC\n#define __MINGW_ATTRIB_PURE\n#endif\n\n/* Attribute `nonnull' was valid as of gcc 3.3. We don't use GCC's\n variadiac macro facility, because variadic macros cause syntax\n errors with --traditional-cpp. */\n#if __MINGW_GNUC_PREREQ (3, 3)\n#define __MINGW_ATTRIB_NONNULL(arg) __attribute__((__nonnull__(arg)))\n#else\n#define __MINGW_ATTRIB_NONNULL(arg)\n#endif /* GNUC >= 3.3 */\n\n#if __MINGW_GNUC_PREREQ (3, 1)\n#define __MINGW_ATTRIB_DEPRECATED __attribute__((__deprecated__))\n#else\n#define __MINGW_ATTRIB_DEPRECATED\n#endif /* GNUC >= 3.1 */\n\n#if __MINGW_GNUC_PREREQ (3, 3)\n#define __MINGW_NOTHROW __attribute__((__nothrow__))\n#else\n#define __MINGW_NOTHROW\n#endif /* GNUC >= 3.3 */\n\n\n/* TODO: Mark (almost) all CRT functions as __MINGW_NOTHROW. This will\nallow GCC to optimize away some EH unwind code, at least in DW2 case. */\n\n/* Activation of MinGW specific extended features:\n */\n#ifndef __USE_MINGW_ANSI_STDIO\n/* Users should not set this directly; rather, define one (or more)\n * of the feature test macros (tabulated below), or specify any of the\n * compiler's command line options, (e.g. -posix, -ansi, or -std=c...),\n * which cause _POSIX_SOURCE, or __STRICT_ANSI__ to be defined.\n *\n * We must check this BEFORE we specifiy any implicit _POSIX_C_SOURCE,\n * otherwise we would always implicitly choose __USE_MINGW_ANSI_STDIO,\n * even if none of these selectors are specified explicitly...\n */\n# if defined __STRICT_ANSI__ || defined _ISOC99_SOURCE \\\n || defined _POSIX_SOURCE || defined _POSIX_C_SOURCE \\\n || defined _XOPEN_SOURCE || defined _XOPEN_SOURCE_EXTENDED \\\n || defined _GNU_SOURCE || defined _BSD_SOURCE \\\n || defined _SVID_SOURCE\n /*\n * but where any of these source code qualifiers are specified,\n * then assume ANSI I/O standards are preferred over Microsoft's...\n */\n# define __USE_MINGW_ANSI_STDIO 1\n# else\n /* otherwise use whatever __MINGW_FEATURES__ specifies...\n */\n# define __USE_MINGW_ANSI_STDIO (__MINGW_FEATURES__ & __MINGW_ANSI_STDIO__)\n# endif\n#endif\n\n#ifndef _POSIX_C_SOURCE\n /* Users may define this, either directly or indirectly, to explicitly\n * enable a particular level of visibility for the subset of those POSIX\n * features which are supported by MinGW; (notice that this offers no\n * guarantee that any particular POSIX feature will be supported).\n */\n# if defined _XOPEN_SOURCE\n /* Specifying this is the preferred method for setting _POSIX_C_SOURCE;\n * (POSIX defines an explicit relationship to _XOPEN_SOURCE). Note that\n * any such explicit setting will augment the set of features which are\n * available to any compilation unit, even if it seeks to be strictly\n * ANSI-C compliant.\n */\n# if _XOPEN_SOURCE < 500\n# define _POSIX_C_SOURCE 1L /* POSIX.1-1990 / SUSv1 */\n\n# elif _XOPEN_SOURCE < 600\n# define _POSIX_C_SOURCE 199506L /* POSIX.1-1996 / SUSv2 */\n\n# elif _XOPEN_SOURCE < 700\n# define _POSIX_C_SOURCE 200112L /* POSIX.1-2001 / SUSv3 */\n\n# else\n# define _POSIX_C_SOURCE 200809L /* POSIX.1-2008 / SUSv4 */\n# endif\n\n# elif defined _GNU_SOURCE || defined _BSD_SOURCE || ! defined __STRICT_ANSI__\n /*\n * No explicit level of support has been specified; implicitly grant\n * the most comprehensive level to any compilation unit which requests\n * either GNU or BSD feature support, or does not seek to be strictly\n * ANSI-C compliant.\n */\n# define _POSIX_C_SOURCE 200809L\n\n# elif defined _POSIX_SOURCE\n /* Now formally deprecated by POSIX, some old code may specify this;\n * it will enable a minimal level of POSIX support, in addition to the\n * limited feature set enabled for strict ANSI-C conformity.\n */\n# define _POSIX_C_SOURCE 1L\n# endif\n#endif\n\n#ifndef _ISOC99_SOURCE\n /* libmingwex.a provides free-standing implementations for many of the\n * functions which were introduced in C99; MinGW headers do not expose\n * prototypes for these, unless this feature test macro is defined, by\n * the user, or implied by other standards...\n */\n# if __STDC_VERSION__ >= 199901L || _POSIX_C_SOURCE >= 200112L\n# define _ISOC99_SOURCE 1\n# endif\n#endif\n\n#if ! defined _MINGW32_SOURCE_EXTENDED && ! defined __STRICT_ANSI__\n/*\n * Enable mingw32 extensions by default, except when __STRICT_ANSI__\n * conformity mode has been enabled.\n */\n# define _MINGW32_SOURCE_EXTENDED 1\n#endif\n\n#endif /* __MINGW_H: $RCSfile: _mingw.h.in,v $: end of file */\n"
},
{
"answer_id": 59693355,
"author": "Kader DJEHAF",
"author_id": 12512282,
"author_profile": "https://Stackoverflow.com/users/12512282",
"pm_score": 2,
"selected": false,
"text": "unistd.h windows.h"
},
{
"answer_id": 60439303,
"author": "Marduk",
"author_id": 3534491,
"author_profile": "https://Stackoverflow.com/users/3534491",
"pm_score": 2,
"selected": false,
"text": "path\\to\\libunistd\\unistd INCLUDE"
},
{
"answer_id": 68686145,
"author": "senithdeelaka",
"author_id": 15599397,
"author_profile": "https://Stackoverflow.com/users/15599397",
"pm_score": -1,
"selected": false,
"text": "#define stdin (__acrt_iob_func(0)) #define stdout (__acrt_iob_func(1)) #define stderr (__acrt_iob_func(2))"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341817",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10396/"
] |
341,831 | <p>I need a tool to automatically convert simple HTML into an image. I will be controlling the HTML input which will consist of simple text formatting tags and possibly image links--I don't need to be able to render arbitrary HTML. Is there a simple way to do this? </p>
<p>I've looked at the HTML layout engines like Gecko and Webkit, but frankly I'm overwhelmed by the number of options they have--I don't need a complete web browser! Is it possible to use these engines in this way? Can someone steer me in the right direction?</p>
<p>Other possibilities like browsershots, rely on screenshots of real browsers, but I'm going to be running this application on a web server with potentially many users so performance is important and I'm afraid this kind of solution won't scale.</p>
<p>Ideas?</p>
<p>EDIT: Sorry forget to mention that my server is running Linux, so Windows solutions won't help. :)</p>
| [
{
"answer_id": 29313585,
"author": "Brandon Rhodes",
"author_id": 85360,
"author_profile": "https://Stackoverflow.com/users/85360",
"pm_score": 1,
"selected": false,
"text": "wkhtmltoimage wkhtmltopdf wkhtmltoimage tmp.html tmp.png\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341831",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27478/"
] |
341,844 | <p>Our company has for many years had multiple domain names to protect our product name. When our webiste was first set up we had all these domain names resolving to on IP address which worked fine until now. We rewrote the site with ASP.NET MVC and now use Recaptcha. The Recaptcha keys are registered to "www.example.com" which is our main domain. We have other domains like "www.examples.com" and "www.ex-ample.com" that points to the same IP address. when someone comes to our site from the alternate domains, Recaptcha doesn't work because the keys aren't registered for that alternate domain. We would like to redirect eveything that comes in from "www.examples.com" to "www.example.com".</p>
<p>I have read that you can set up the sites in IIS and use a permanent redirect, but will this work if the domains all point to the same IP address?</p>
<p>We also have installed the Rewrite Module for IIS 7 because a lot of our pages moved when we switched to MVC. Is it possible to write a rule and if so how?</p>
<p>Is there a better alternative we should be using?</p>
<p>Any help to shine some light on this is greatly appreciated.</p>
<hr>
<p>I have no problem setting up the domains in IIS, will this work if the domains all point to the same IP address? If I go to www.example.com (192.168.1.1) will it ever end up at www.examples.com (192.168.1.1) which redirects to www.example.com and cause an infinate loop because they are on the same IP address?</p>
<hr>
<p>How would CNAME be done in a Windows 2003 DNS Server?</p>
| [
{
"answer_id": 341901,
"author": "Adam",
"author_id": 13320,
"author_profile": "https://Stackoverflow.com/users/13320",
"pm_score": 1,
"selected": true,
"text": "127.0.0.1 A example.com\nwww.exmaple.com CNAME example.com\nexamples.com CNAME example.com\nwww.examples.com CNAME example.com\n"
},
{
"answer_id": 403777,
"author": "alex",
"author_id": 50564,
"author_profile": "https://Stackoverflow.com/users/50564",
"pm_score": 0,
"selected": false,
"text": "IIS URL Rewrite <rule name=\"WWW Redirect\" stopProcessing=\"true\">\n <match url=\".*\" />\n <conditions>\n <add input=\"{HTTP_HOST}\" pattern=\"^examples.com$\" />\n </conditions>\n <action type=\"Redirect\" url=\"http://www.example.com/{R:0}\" redirectType=\"Permanent\" />\n </rule>\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341844",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36383/"
] |
341,847 | <p>I am working on a course leaflet system for the college I work at, leaflets are stored in a database with primary key course_code. I would like the leaflets ideally to get indexed by google how would I achieve this assuming i develop the system in asp.net 2.0. </p>
<p>I understand part of getting it indexed is to pass the variables around in the link in my case the course_code, this obviously also allows bookmarking of course leaflets which is nice. What are the specifics of getting the googlebot to trawl the system best.</p>
| [
{
"answer_id": 343348,
"author": "Liam",
"author_id": 18333,
"author_profile": "https://Stackoverflow.com/users/18333",
"pm_score": 0,
"selected": false,
"text": "wget -r www.example.com\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341847",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16989/"
] |
341,848 | <p>Given that Decimal.MaxValue = 79228162514264337593543950335m</p>
<p>Why does the next line give me 7922816251426433759354395034M in the Local window instead of 7922816251426433759354395033.5m as expected?</p>
<p>Decimal target = Decimal.MaxValue / 10m;</p>
| [
{
"answer_id": 341865,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 4,
"selected": true,
"text": "using System;\n\nclass Test\n{\n static void Main()\n {\n decimal constant = decimal.MaxValue / 10m;\n decimal calculated = decimal.MaxValue;\n calculated /= 10m;\n\n Console.WriteLine (constant);\n Console.WriteLine (calculated); \n }\n}\n 7922816251426433759354395034\n7922816251426433759354395033.5\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341848",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13266/"
] |
341,852 | <p>By default when viewing an account in edit mode you have access to Opportunities, Invoices, and Quotes which contain the products being shopped by the account and/or the sales department.</p>
<p>I'm trying to determine where to store, display, and use the products that an account has a subscription too. </p>
<p>I may not understand the implementation but it seems that there should be "Products" option directly off the root Account management window that will show the user all the products the account has purchased.</p>
<p>We are trying to integrate this with our production tracking system where product sales can originate from other channels that will not flow through CRM first. This product subscription does not fit into the Opportunity, Quote, or Invoice model because they are confirmed recurring sales that were automatically purchased via tools like a Public Website, Portal, etc. </p>
<p>By enabling this tracking in CRM we can use the advanced find feature to facilitate follow up sales and marketing efforts.</p>
<p>Example: Find everyone who is subscribed to model A, so we can notify them of a new holiday campaign where they can get 10% off on all add-ons.</p>
<p>It's my assumption that this is a common scenario, however I'd like to better understand how to approach this within the world of Microsoft CRM.</p>
<p>Thank you in advance.</p>
| [
{
"answer_id": 341865,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 4,
"selected": true,
"text": "using System;\n\nclass Test\n{\n static void Main()\n {\n decimal constant = decimal.MaxValue / 10m;\n decimal calculated = decimal.MaxValue;\n calculated /= 10m;\n\n Console.WriteLine (constant);\n Console.WriteLine (calculated); \n }\n}\n 7922816251426433759354395034\n7922816251426433759354395033.5\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341852",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
341,872 | <p>I'm starting a project that will be public facing using asp.net mvc. I know there are about a billion php, python, and ruby html sanitizers out there, but does anyone have some pointers to anything good in .net? What are your experiences with what is out there? I know stackoverflow is a site done in asp.net that allows freeform HTML, what does it use?</p>
| [
{
"answer_id": 8470031,
"author": "Brandon Joyce",
"author_id": 54050,
"author_profile": "https://Stackoverflow.com/users/54050",
"pm_score": 2,
"selected": false,
"text": "var cleanHtml = Sanitizer.GetSafeHtml(unsafeHtml);\n"
},
{
"answer_id": 50871492,
"author": "Sheo Dayal Singh",
"author_id": 5736534,
"author_profile": "https://Stackoverflow.com/users/5736534",
"pm_score": 1,
"selected": false,
"text": " string mal = \"<IMG NAME = 'myPic' SRC = 'images / myPic.gif' onerror='alert(1)' onerror='alert(1) ><div bottommargin = 150 ondblclick = 'alert('double clicked!')' >< p > Double - click anywhere in the page.</p> </div> \";\n var cleanHtml = Sanitizer.GetSafeHtmlFragment(mal);\n Console.Write(cleanHtml);\n Console.Read(); \n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341872",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10771/"
] |
341,891 | <p>I am designing a system which will at some point require to send email notifications. So I am looking for a simple way to do this. Some background: the system will be running on Linux platform, there will be a working SMTP server somewhere on the network, the operator will configure its address, server credentials if required and a list of target email addresses (no, I am NOT working on a mass email system ;-). The process which will need to send the emails will be probably written in C, but super performance is not really a requirement, there won't be a lot of mails to send, so invoking some command-line tool is an acceptable option. Basically, what I tried in the past for similar tasks:</p>
<ul>
<li>Invoking local sendmail in command-line mode. This is a nightmare, because of the necessity to support the cryptic sendmail config. This is what I would really like to avoid.</li>
<li>Talking to SMTP server port directly (EHLO, etc). This IS an option, but a bit too low-level for year 2008 ;-).</li>
<li>Using some MUA which talks to local sendmail daemon acting as a mail relay. This is not nice exactly because it requires having local sendmail up and configured. </li>
</ul>
<p>So what I need is basically some library for C language or a simple command-line MUA which should be able to talk to remote sendmail (i.e. to talk to SMTP server that I tell it to), <b>but not requiring a local mail relay</b>. </p>
<p>Any ideas are welcome!</p>
| [
{
"answer_id": 342081,
"author": "Hudson",
"author_id": 14105,
"author_profile": "https://Stackoverflow.com/users/14105",
"pm_score": 0,
"selected": false,
"text": "use Mail::Mailer;\n\nmy $mailer = Mail::Mailer->new();\n$mailer->open({\n From => $from_address,\n To => $to_address,\n Subject => $subject,\n}) or die \"Can’t open: $!\\n\";\nprint $mailer $body;\n$mailer->close();\n"
}
] | 2008/12/04 | [
"https://Stackoverflow.com/questions/341891",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40548/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.