qid
int64 1
82.4k
| question
stringlengths 27
22.5k
| answers
stringlengths 509
252k
| date
stringlengths 10
10
| metadata
stringlengths 108
162
|
---|---|---|---|---|
73,319 | <p>How do I duplicate a whole line in <strong>Vim</strong> in a similar way to <kbd>Ctrl</kbd>+<kbd>D</kbd> in IntelliJ IDEA/ Resharper or <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>↑</kbd>/<kbd>↓</kbd> in <strong>Eclipse</strong>?</p>
| [{'answer_id': 73329, 'author': 'Eric Z Beard', 'author_id': 1219, 'author_profile': 'https://Stackoverflow.com/users/1219', 'pm_score': 6, 'selected': False, 'text': '<p>Do this: </p>\n\n<p>First, <kbd>y</kbd><kbd>y</kbd> to copy the current line, and then <kbd>p</kbd> to paste.</p>\n'}, {'answer_id': 73330, 'author': 'pjz', 'author_id': 8002, 'author_profile': 'https://Stackoverflow.com/users/8002', 'pm_score': 6, 'selected': False, 'text': '<p><kbd>y</kbd><kbd>y</kbd></p>\n\n<p>will yank the current line without deleting it</p>\n\n<p><kbd>d</kbd><kbd>d</kbd></p>\n\n<p>will delete the current line</p>\n\n<p><kbd>p</kbd></p>\n\n<p>will <code>put</code> a line grabbed by either of the previous methods</p>\n'}, {'answer_id': 73356, 'author': 'cori', 'author_id': 8151, 'author_profile': 'https://Stackoverflow.com/users/8151', 'pm_score': 2, 'selected': False, 'text': '<p>1 gotcha: when you use "p" to put the line, it puts it <em>after</em> the line your cursor is on, so if you want to add the line after the line you\'re yanking, don\'t move the cursor down a line before putting the new line.</p>\n'}, {'answer_id': 73357, 'author': 'Mark Biek', 'author_id': 305, 'author_profile': 'https://Stackoverflow.com/users/305', 'pm_score': 13, 'selected': True, 'text': '<p><kbd>y</kbd><kbd>y</kbd> or <kbd>Y</kbd> to copy the line (mnemonic: <strong><em>y</strong>ank</em>)\n<br />or\n<br /><kbd>d</kbd><kbd>d</kbd> to <strong><em>d</strong>elete</em> the line (Vim copies what you deleted into a clipboard-like "register", like a <em>cut</em> operation)</p>\n\n<p>then</p>\n\n<p><kbd>p</kbd> to <strong><em>p</strong>aste</em> the copied or deleted text <em>after</em> the current line\n<br />or\n<br /><kbd>P</kbd> to <strong><em>p</strong>aste</em> the copied or deleted text <em>before</em> the current line</p>\n'}, {'answer_id': 73362, 'author': 'Linulin', 'author_id': 12481, 'author_profile': 'https://Stackoverflow.com/users/12481', 'pm_score': 8, 'selected': False, 'text': '<p><code>YP</code> or <code>Yp</code> or <code>yyp</code>.</p>\n\n<p></p>\n'}, {'answer_id': 73440, 'author': 'theschmitzer', 'author_id': 2167252, 'author_profile': 'https://Stackoverflow.com/users/2167252', 'pm_score': 6, 'selected': False, 'text': '<p><kbd>y</kbd><kbd>y</kbd><kbd>p</kbd> - remember it with "yippee!"</p>\n\n<p>Multiple lines with a number in between:</p>\n\n<p><kbd>y</kbd><kbd>7</kbd><kbd>y</kbd><kbd>p</kbd></p>\n'}, {'answer_id': 73682, 'author': 'Kwondri', 'author_id': 7691, 'author_profile': 'https://Stackoverflow.com/users/7691', 'pm_score': 6, 'selected': False, 'text': '<p>If you want another way:</p>\n\n<p><code>"ayy</code>:\nThis will store the line in buffer <code>a</code>.</p>\n\n<p><code>"ap</code>:\nThis will put the contents of buffer <code>a</code> at the cursor.</p>\n\n<p>There are many variations on this.</p>\n\n<p><code>"a5yy</code>:\nThis will store the 5 lines in buffer <code>a</code>.</p>\n\n<p>See "<a href="https://vimhelp.org/" rel="noreferrer">Vim help files</a> for more fun.</p>\n'}, {'answer_id': 96605, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 4, 'selected': False, 'text': '<p>You can also try <C-x><C-l> which will repeat the last line from insert mode and brings you a completion window with all of the lines. It works almost like <C-p></p>\n'}, {'answer_id': 1123441, 'author': 'Rook', 'author_id': 62699, 'author_profile': 'https://Stackoverflow.com/users/62699', 'pm_score': 4, 'selected': False, 'text': '<p>Another option would be to go with:</p>\n\n<pre><code>nmap <C-d> mzyyp`z\n</code></pre>\n\n<p>gives you the advantage of preserving the cursor position.</p>\n'}, {'answer_id': 1123462, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 4, 'selected': False, 'text': '<p>I like:\n<kbd>Shift</kbd>+<kbd>v</kbd> (to select the whole line immediately and let you select other lines if you want), y, p</p>\n'}, {'answer_id': 10194014, 'author': 'Benoit', 'author_id': 457352, 'author_profile': 'https://Stackoverflow.com/users/457352', 'pm_score': 9, 'selected': False, 'text': '<p>Normal mode: see other answers.</p>\n\n<p>The <a href="https://en.wikipedia.org/wiki/Ex_%28text_editor%29" rel="noreferrer" title="text editor">Ex</a> way:</p>\n\n<ul>\n<li><code>:t.</code> will duplicate the line,</li>\n<li><code>:t 7</code> will copy it after line 7,</li>\n<li><code>:,+t0</code> will copy current and next line at the beginning of the file (<code>,+</code> is a synonym for the range <code>.,.+1</code>),</li>\n<li><code>:1,t$</code> will copy lines from beginning till cursor position to the end (<code>1,</code> is a synonym for the range <code>1,.</code>).</li>\n</ul>\n\n<p>If you need to move instead of copying, use <code>:m</code> instead of <code>:t</code>.</p>\n\n<p>This can be really powerful if you combine it with <code>:g</code> or <code>:v</code>: </p>\n\n<ul>\n<li><code>:v/foo/m$</code> will move all lines not matching the pattern “foo” to the end of the file.</li>\n<li><code>:+,$g/^\\s*class\\s\\+\\i\\+/t.</code> will copy all subsequent lines of the form <code>class xxx</code> right after the cursor.</li>\n</ul>\n\n<p>Reference: <code>:help range</code>, <code>:help :t</code>, <code>:help :g</code>, <code>:help :m</code> and <code>:help :v</code></p>\n'}, {'answer_id': 19337648, 'author': 'yemu', 'author_id': 2006977, 'author_profile': 'https://Stackoverflow.com/users/2006977', 'pm_score': 5, 'selected': False, 'text': '<p><kbd>y</kbd><kbd>y</kbd><kbd>p</kbd> - paste after</p>\n\n<p><kbd>y</kbd><kbd>y</kbd><kbd>P</kbd> - paste before</p>\n'}, {'answer_id': 21638849, 'author': 'Adam', 'author_id': 313211, 'author_profile': 'https://Stackoverflow.com/users/313211', 'pm_score': 8, 'selected': False, 'text': '<p><img src="https://i.stack.imgur.com/dz2pb.gif" alt="copy and paste in vim"></p>\n\n<p>Doesn\'t get any simpler than this! From normal mode:</p>\n\n<pre><code>yy\n</code></pre>\n\n<p>then move to the line you want to paste at and</p>\n\n<pre><code>p\n</code></pre>\n'}, {'answer_id': 29739390, 'author': 'Chris Penner', 'author_id': 3907685, 'author_profile': 'https://Stackoverflow.com/users/3907685', 'pm_score': 3, 'selected': False, 'text': '<p>Default is <kbd>y</kbd><kbd>y</kbd><kbd>p</kbd>, but I\'ve been using this rebinding for a year or so and love it:</p>\n\n<p><code>" set Y to duplicate lines, works in visual mode as well.\nnnoremap Y yyp\nvnoremap Y y`>pgv\n</code></p>\n'}, {'answer_id': 35316491, 'author': 'ap-osd', 'author_id': 3209308, 'author_profile': 'https://Stackoverflow.com/users/3209308', 'pm_score': 2, 'selected': False, 'text': '<p>For those starting to learn vi, here is a good introduction to vi by listing side by side vi commands to typical Windows GUI Editor cursor movement and shortcut keys. It lists all the basic commands including <kbd>yy</kbd> (copy line) and <kbd>p</kbd> (paste after) or <kbd>P</kbd>(paste before).</p>\n\n<p><a href="https://cognitivewaves.wordpress.com/vi-editor/" rel="nofollow">vi (Vim) for Windows Users</a></p>\n'}, {'answer_id': 37190575, 'author': 'Michael', 'author_id': 916379, 'author_profile': 'https://Stackoverflow.com/users/916379', 'pm_score': 3, 'selected': False, 'text': '<p>For someone who doesn\'t know vi, some answers from above might mislead him with phrases like "paste ... after/before <b><i>current line</b></i>".\n<br />It\'s actually "paste ... after/before <b><i>cursor</b></i>".\n<br /><br />\n<kbd>y</kbd><kbd>y</kbd> or <kbd>Y</kbd> to copy the line\n<br />or\n<br /><kbd>d</kbd><kbd>d</kbd> to delete the line</p>\n\n<p>then</p>\n\n<p><kbd>p</kbd> to paste the copied or deleted text <em>after</em> the <b>cursor</b>\n<br />or\n<br /><kbd>P</kbd> to paste the copied or deleted text <em>before</em> the <b>cursor</b></p>\n\n<p><br />\nFor more key bindings, you can visit this site: <a href="http://hea-www.harvard.edu/~fine/Tech/vi.html" rel="noreferrer">vi Complete Key Binding List</a></p>\n'}, {'answer_id': 48734229, 'author': 'jedi', 'author_id': 4741620, 'author_profile': 'https://Stackoverflow.com/users/4741620', 'pm_score': 2, 'selected': False, 'text': '<p>If you would like to duplicate a line and paste it right away below the current like, just like in Sublime <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>D</kbd>, then you can add this to your <code>.vimrc</code> file.</p>\n\n<p><code>nmap <S-C-d> <Esc>Yp</code></p>\n\n<p>Or, for Insert mode:</p>\n\n<p><code>imap <S-C-d> <Esc>Ypa</code></p>\n'}, {'answer_id': 49780313, 'author': 'yolenoyer', 'author_id': 3271687, 'author_profile': 'https://Stackoverflow.com/users/3271687', 'pm_score': 1, 'selected': False, 'text': '<p>I like to use this mapping:</p>\n\n<pre><code>:nnoremap yp Yp\n</code></pre>\n\n<p>because it makes it consistent to use alongside the native <code>YP</code> command.</p>\n'}, {'answer_id': 49811528, 'author': 'DarkWiiPlayer', 'author_id': 4984564, 'author_profile': 'https://Stackoverflow.com/users/4984564', 'pm_score': 3, 'selected': False, 'text': "<p>I know I'm late to the party, but whatever; I have this in my .vimrc:</p>\n\n<pre><code>nnoremap <C-d> :copy .<CR>\nvnoremap <C-d> :copy '><CR>\n</code></pre>\n\n<p>the <code>:copy</code> command just copies the selected line or the range (always whole lines) to below the line number given as its argument.</p>\n\n<p>In normal mode what this does is <code>copy .</code> <em>copy this line to just below this line</em>.</p>\n\n<p>And in visual mode it turns into <code>'<,'> copy '></code> <em>copy from start of selection to end of selection to the line below end of selection</em>.</p>\n"}, {'answer_id': 67353204, 'author': 'frfernandezdev', 'author_id': 9309561, 'author_profile': 'https://Stackoverflow.com/users/9309561', 'pm_score': 0, 'selected': False, 'text': '<p>I use this mapping, which is similar to vscode. I hope it is useful!!!.</p>\n<pre><code>nnoremap <A-d> :t. <CR>==\ninoremap <A-d> <Esc>:t. <CR>==gi\nvnoremap <A-d> :t$ <CR>gv=gv\n</code></pre>\n'}, {'answer_id': 68621271, 'author': 'Savrige', 'author_id': 2583490, 'author_profile': 'https://Stackoverflow.com/users/2583490', 'pm_score': 2, 'selected': False, 'text': '<p>I prefer to define a custom keymap <kbd>Ctrl</kbd>+<kbd>D</kbd> in <code>.vimrc</code> to duplicate the current line both in <em>normal</em> mode and <em>insert</em> mode:</p>\n<pre><code>" duplicate line in normal mode:\nnnoremap <C-D> Yp\n" duplicate line in insert mode:\ninoremap <C-D> <Esc> Ypi\n</code></pre>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73319', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/11439/'] |
73,320 | <p>How do I set the column which has the header sort glyph, and its direction, in a .NET 2.0 WinForms ListView?</p>
<h2>Bump</h2>
<p>The listview is .net is not a managed control, it is a very thin wrapper around the Win32 ListView common control. It's not even a very good wrapper - it doesn't expose all the features of the real listview.</p>
<p>The Win32 listview common control supports drawing itself with themes. One of the themed elements is the header sort arrow. Windows Explorer's listview common control knows how to draw one of its columns with that theme element.</p>
<ul>
<li>does the Win32 listview support specifying which column has what sort order? </li>
<li>does the Win32 header control that the listview internally uses support specifying which column has what sort order? </li>
<li>does the win32 header control support custom drawing, so I can draw the header sort glyph myself?</li>
<li>does the win32 listview control support custom header drawing, so I can draw the header sort glyph myself?</li>
<li>does the .NET ListView control support custom header drawing, so I can draw the header sort glyph myself?</li>
</ul>
| [{'answer_id': 73331, 'author': 'DevelopingChris', 'author_id': 1220, 'author_profile': 'https://Stackoverflow.com/users/1220', 'pm_score': 1, 'selected': False, 'text': '<p>I use unicode arrow characters in the title of the column and make the header a linkbutton.</p>\n'}, {'answer_id': 2072955, 'author': 't0mm13b', 'author_id': 206367, 'author_profile': 'https://Stackoverflow.com/users/206367', 'pm_score': 1, 'selected': False, 'text': '<p>There is a listview that I use that has that in-built into it. It\'s called <a href="http://www.codeproject.com/KB/list/XPTableListViewUpdate.aspx" rel="nofollow noreferrer">XPTable</a>..I am digging around my source code to find that helper class that will draw the glyph based on the sort order...This is the code that I have used <a href="http://www.codeproject.com/KB/list/lvsortmanager.aspx" rel="nofollow noreferrer">here</a>..</p>\n\n<p>Hope this helps,\nBest regards,\nTom.</p>\n'}, {'answer_id': 26857392, 'author': 'IlPADlI', 'author_id': 2430943, 'author_profile': 'https://Stackoverflow.com/users/2430943', 'pm_score': 1, 'selected': False, 'text': '<p>This article is helpful, uses SendMessage DllImport.</p>\n\n<p><a href="http://www.codeproject.com/Tips/734463/Sort-listview-Columns-and-Set-Sort-Arrow-Icon-on-C" rel="nofollow">http://www.codeproject.com/Tips/734463/Sort-listview-Columns-and-Set-Sort-Arrow-Icon-on-C</a></p>\n'}, {'answer_id': 36332488, 'author': 'Adam', 'author_id': 5250659, 'author_profile': 'https://Stackoverflow.com/users/5250659', 'pm_score': 2, 'selected': False, 'text': '<p>In case someone needs a quick solution (it draws up/down arrow at the beginning of column header text):</p>\n\n<p><strong>ListViewExtensions.cs:</strong></p>\n\n<pre><code>public static class ListViewExtensions\n{\n public static void DrawSortArrow(this ListView listView, SortOrder sortOrder, int colIndex)\n {\n string upArrow = "▲ ";\n string downArrow = "▼ ";\n\n foreach (ColumnHeader ch in listView.Columns)\n {\n if (ch.Text.Contains(upArrow))\n ch.Text = ch.Text.Replace(upArrow, string.Empty);\n else if (ch.Text.Contains(downArrow))\n ch.Text = ch.Text.Replace(downArrow, string.Empty);\n }\n\n if (sortOrder == SortOrder.Ascending)\n listView.Columns[colIndex].Text = listView.Columns[colIndex].Text.Insert(0, downArrow);\n else\n listView.Columns[colIndex].Text = listView.Columns[colIndex].Text.Insert(0, upArrow);\n }\n}\n</code></pre>\n\n<p><strong>Usage:</strong></p>\n\n<pre><code>private void lstOffers_ColumnClick(object sender, ColumnClickEventArgs e)\n{\n lstOffers.DrawSortArrow(SortOrder.Descending, e.Column);\n}\n</code></pre>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73320', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12597/'] |
73,335 | <p>I have an <a href="http://www.sencha.com" rel="nofollow noreferrer">ExtJS</a> grid on a web page and I'd like to save some of its state information back to the server when the users leaves the page.
Can I do this with an Ajax request onUnload?
If not, what's a better solution?</p>
| [{'answer_id': 73371, 'author': 'Jim', 'author_id': 8427, 'author_profile': 'https://Stackoverflow.com/users/8427', 'pm_score': 3, 'selected': True, 'text': "<p>You can use an Ajax request, but be sure to make it a synchronous request rather than an asychronous one. Alternatively, simply save state whenever the user makes a change, this also protects the data if the user's browser crashes.</p>\n"}, {'answer_id': 73441, 'author': 'Adam Hopkinson', 'author_id': 12280, 'author_profile': 'https://Stackoverflow.com/users/12280', 'pm_score': 0, 'selected': False, 'text': '<p>You could also set a cookie using javascript on unload. I think the advantage ajax has over cookies is that you have the data available to you for reporting and the user (if logged in) can utilise the data across different machines.</p>\n\n<p>The disadvantage of using ajax is that it might slow down the actual closing of the browser window, which could be annoying if the server is slow to respond.</p>\n'}, {'answer_id': 73595, 'author': 'Alexandre Victoor', 'author_id': 11897, 'author_profile': 'https://Stackoverflow.com/users/11897', 'pm_score': 0, 'selected': False, 'text': '<p>It depends on how the user leaves the page.\nIf there is a \'logoff\' button in your GUI, you can trigger an ajax request when the user clicks on this button.\nOtherwise I do not think it is a good idea to make a request in the onUnload. As said earlier you would have to make a synchronous request...\nAn alternative to the cookie solution would be an hidden text field. This is a technique usually used by tools such as <a href="http://code.google.com/p/reallysimplehistory/" rel="nofollow noreferrer">RSH</a> that deal with history issues that come with ajax.</p>\n'}, {'answer_id': 76129, 'author': 'Douglas Mayle', 'author_id': 8458, 'author_profile': 'https://Stackoverflow.com/users/8458', 'pm_score': 1, 'selected': False, 'text': '<p>There\'s an answer above that says to use a synchronous ajax call, and that is the best case scenario. The problem is that unload doesn\'t work everywhere. If you look <a href="http://blog.rd2inc.com/archives/2005/05/04/unload-events-in-safari/" rel="nofollow noreferrer">here</a> you\'ll find some tricks to help you get unload events in safari... You could also use Google Gears to save content user side for situations where the user will be coming back, but the only fully safe way to keep that information is to continuously send it as long as the user is on the page or making changes.</p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73335', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12559/'] |
73,359 | <p>What is the difference between Introspection and Reflection in .NET</p>
| [{'answer_id': 73424, 'author': 'Stephen Deken', 'author_id': 7154, 'author_profile': 'https://Stackoverflow.com/users/7154', 'pm_score': 4, 'selected': False, 'text': "<p>They're two parts of the same whole.</p>\n\n<p>Introspection refers to the ability of a class to look 'inside' itself and see, for example, what parameters a method takes, what the names of its members are, etc.</p>\n\n<p>Reflection is the specific name for how .NET implements introspection. Other languages may call it something different (C++ calls its limited introspection RTTI, for run-time type information).</p>\n"}, {'answer_id': 73770, 'author': 'Akselsson', 'author_id': 8862, 'author_profile': 'https://Stackoverflow.com/users/8862', 'pm_score': 4, 'selected': True, 'text': '<p>Introspection was introduced with <a href="http://msdn.microsoft.com/en-gb/magazine/cc188721.aspx" rel="noreferrer">FxCop in 2004 as an alternative to Reflection</a> :</p>\n\n<blockquote>\n <p>What\'s new in FxCop 1.30 is that it\n now performs analysis through a\n technique called Introspection. The\n use of the Introspection engine allows\n for much faster analysis and supports\n multithreaded analysis. Unlike the\n Reflection engine from previous\n versions, in the Introspection engine\n the assemblies you\'re analyzing are\n not locked so you won\'t need to shut\n down FxCop to do a fix and recompile\n of those assemblies. Finally, the\n Introspection engine offers a much\n richer analysis infrastructure\n compared to the Reflection engine.</p>\n</blockquote>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73359', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1909/'] |
73,366 | <p>What tools/websites do you use to read JavaDocs? </p>
<p>I currently use Firefox with 20+ tabs open when working on a J2EE project to have all the documentation available which is not very usable, is eating too much memory and is not searchable.</p>
<p>What I would expect from such a tool/website:</p>
<ul>
<li>Aggregate JavaDocs from different locations</li>
<li>Direct access to types like Ctrl+T in Eclipse or similar</li>
<li>Fulltext search</li>
<li>Cross referencing between all the Java libraries I've chosen</li>
<li>For a tool: offline support</li>
<li>Speed</li>
</ul>
<p>not mandatory: </p>
<ul>
<li>possibility to annotate things</li>
<li>support for different versions of a library (+ diffing ?)</li>
<li>IDE integration</li>
</ul>
<p>Edit:</p>
<p>Thanks for your answers. I knew most of the sites but gave them another try. Here is my judgement:</p>
<ul>
<li>built-in Eclipse/IDE features
<ul>
<li>tightly integrated</li>
<li>offline/online support</li>
</ul></li>
<li><a href="http://www.javadoconline.com" rel="noreferrer"><strike>javadoconline.com</strike></a> (no longer maintained)
<ul>
<li>works</li>
<li>clean looks</li>
<li>finds matches in more than one version of the api and allows easy switching</li>
<li>simple but working</li>
<li>fast</li>
</ul></li>
<li><a href="http://www.jdocs.com/" rel="noreferrer"><strike>jdocs</strike></a> (offline)
<ul>
<li>seems very sophisticated</li>
<li>sometimes slow</li>
<li>some recent versions of libraries seem to be missing (Seam 2.0.0, Hibernate Validators) but it looks like you can add them yourself</li>
<li>IDE integration (not tested)</li>
<li>wiki style comments to each item</li>
</ul></li>
<li><a href="http://www.docjar.com/" rel="noreferrer">docjar.com</a>
<ul>
<li>works</li>
<li>fast</li>
<li>cluttered UI</li>
</ul></li>
<li><a href="http://www.teria.com/~koseki/tools/gm/javadoc_isearch/" rel="noreferrer">javadoc_isearch</a>
<ul>
<li>greasemonkey script for firefox which makes navigating javadocs easier</li>
<li>works smooth and perfectly</li>
</ul></li>
</ul>
| [{'answer_id': 73391, 'author': 'Heath Borders', 'author_id': 9636, 'author_profile': 'https://Stackoverflow.com/users/9636', 'pm_score': 1, 'selected': False, 'text': '<p>Eclipse integrates well with Javadoc and has an HTML-like viewer for it. You can attach source and javadoc to binaries that will show up when you select a class.</p>\n'}, {'answer_id': 73399, 'author': 'mmattax', 'author_id': 1638, 'author_profile': 'https://Stackoverflow.com/users/1638', 'pm_score': 0, 'selected': False, 'text': '<p>Doxygen (<a href="http://www.doxygen.nl/" rel="nofollow noreferrer">http://www.doxygen.nl/</a>) might fit the bill. </p>\n\n<p>EDIT: I may have misread your question, doxygen is a tool to generate documentation and models based off your code and javadoc. </p>\n'}, {'answer_id': 73409, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>Something like this may be useful?</p>\n\n<p><a href="http://www.docjar.com/" rel="nofollow noreferrer">http://www.docjar.com/</a></p>\n'}, {'answer_id': 73431, 'author': 'Rob Dickerson', 'author_id': 7530, 'author_profile': 'https://Stackoverflow.com/users/7530', 'pm_score': 1, 'selected': False, 'text': "<p>Personally, I've never had a problem with the built-in javadoc browsing tools offered by my IDE.</p>\n\n<p>Currently, I use IntelliJ Idea -- Ctl-Q brings up the javadoc for the method under the cursor, with the hyperlinks to other parts of the documentation functional. </p>\n\n<p>I would imagine NetBeans and Eclipse offer similar functionality.</p>\n"}, {'answer_id': 73446, 'author': 'Swati', 'author_id': 12682, 'author_profile': 'https://Stackoverflow.com/users/12682', 'pm_score': 2, 'selected': False, 'text': '<p>I use <a href="http://www.teria.com/~koseki/tools/gm/javadoc_isearch/" rel="nofollow noreferrer" title="javadoc incremental search plugin">http://www.teria.com/~koseki/tools/gm/javadoc_isearch/</a> for FF. Lets me easily browse other libraries as well.</p>\n'}, {'answer_id': 76400, 'author': 'Michael', 'author_id': 13379, 'author_profile': 'https://Stackoverflow.com/users/13379', 'pm_score': 3, 'selected': False, 'text': '<p>If you use Eclipse, it offers support for Javadocs. For example, hovering your mouse over a method call will display a tooltip showing you the Javadoc for that method. Documentation for the core Java classes are supported out of the box. However, if your project uses any additional libraries (JAR files), some configuration is required in order to plug their Javadocs into Eclipse.</p>\n\n<ol>\n<li>Go to the "Java Build Path" section of your project properties.</li>\n<li>Go to the "Libraries" tab and click the "plus" icon next to the JAR file.</li>\n<li>Click "Javadoc location", then the "Edit..." button.</li>\n</ol>\n\n<p>This will let you specify where the Javadocs for that JAR are located. It will even let you specify a website URL, so you don\'t have to download the Javadocs yourself!</p>\n'}, {'answer_id': 789600, 'author': 'Léo Léopold Hertz 준영', 'author_id': 54964, 'author_profile': 'https://Stackoverflow.com/users/54964', 'pm_score': 2, 'selected': False, 'text': '<p>You can find Stanford University\'s JavaDoc <a href="http://www.stanford.edu/class/cs108/JavaDocFast.html" rel="nofollow noreferrer">here</a>.</p>\n'}, {'answer_id': 14937310, 'author': 'gavenkoa', 'author_id': 173149, 'author_profile': 'https://Stackoverflow.com/users/173149', 'pm_score': 1, 'selected': False, 'text': '<p>Hm... How about:</p>\n\n<ul>\n<li><a href="http://edu.netbeans.org/quicktour/javadoc.html" rel="nofollow">http://edu.netbeans.org/quicktour/javadoc.html</a> - NetBeans supports the Javadoc standard for Java documentation - both viewing it and generating it.</li>\n<li><a href="http://globaldocs.zeevbelkin.com/" rel="nofollow">http://globaldocs.zeevbelkin.com/</a> - This application allows to conveniently browse, over the Internet and local filesystem, multiple javadoc sets, using a single packages/classes hierarchy tree and a searchable index. The viewer supports local and remote docsets (the local docsets, packed to JAR/ZIP-files also are supported).</li>\n</ul>\n\n<p>I prefer NetBeans as it get <strong>JavaDoc</strong> from <strong>Maven</strong> <code>~/.m2</code> directory automatically...</p>\n'}, {'answer_id': 16096702, 'author': 'Rohit deol', 'author_id': 2297635, 'author_profile': 'https://Stackoverflow.com/users/2297635', 'pm_score': 0, 'selected': False, 'text': '<p>Eclipse is a best way to see the javadocs. Hovering the mouse on method or any declaration you will get automatically generated javadocs by eclipse.</p>\n'}, {'answer_id': 19849377, 'author': 'Glenn Lawrence', 'author_id': 857209, 'author_profile': 'https://Stackoverflow.com/users/857209', 'pm_score': 1, 'selected': False, 'text': '<p>This plug in for Firefox and Chrome is useful for quickly finding package and class names, though it\'s not a full text search: <a href="https://code.google.com/p/javadoc-search-frame/" rel="nofollow">https://code.google.com/p/javadoc-search-frame/</a></p>\n'}, {'answer_id': 24620136, 'author': 'Max', 'author_id': 2416526, 'author_profile': 'https://Stackoverflow.com/users/2416526', 'pm_score': 3, 'selected': False, 'text': '<p>JavaDoc jar can be unzipped directly. In theory any released javadocs can be downloaded and viewed offline. </p>\n\n<ol>\n<li><p>download directly from maven repository. For example: <a href="http://central.maven.org/maven2/com/googlecode/objectify/objectify/5.0.3/objectify-5.0.3-javadoc.jar" rel="noreferrer">http://central.maven.org/maven2/com/googlecode/objectify/objectify/5.0.3/objectify-5.0.3-javadoc.jar</a> </p></li>\n<li><p>Now you get <code>objectify-5.0.3-javadoc.jar</code>, rename the file to <code>objectify-5.0.3-javadoc.zip</code></p></li>\n<li><p>use your favourite unzip tool to extract it, now you have a folder <code>objectify-5.0.3-javadoc</code></p></li>\n<li><p>double click <code>index.html</code> will open the index page on your default browser. </p></li>\n</ol>\n'}, {'answer_id': 39899704, 'author': 'judovana', 'author_id': 3048996, 'author_profile': 'https://Stackoverflow.com/users/3048996', 'pm_score': 2, 'selected': False, 'text': '<p>I wrote my own tool for this. Acording to my colleagues it is best they seen.</p>\n\n<p>It indexes by lucene once, and run you small server on background, so yo browse javadocs (pydocs, perldocs..) like in browser. It allows also separate libraries per language so searchses like "biginteger" or simialr dont go wrong.</p>\n\n<p><a href="https://github.com/judovana/JavadocOfflineSearch/releases" rel="nofollow">https://github.com/judovana/JavadocOfflineSearch/releases</a></p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73366', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/7647/'] |
73,380 | <p>I'm running some c# .net pages with various gridviews. If I ever leave any of them alone in a web browser for an extended period of time (usually overnight), I get the following error when I click any element on the page.</p>
<p>I'm not really sure where to start dealing with the problem. I don't mind resetting the page if it's viewstate has expired, but throwing an error is unacceptable!</p>
<pre><code> Error: The state information is invalid for this page and might be corrupted.
Target: Void ThrowError(System.Exception, System.String, System.String, Boolean)
Data: System.Collections.ListDictionaryInternal
Inner: System.Web.UI.ViewStateException: Invalid viewstate. Client IP: 66.35.180.246 Port: 1799 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9) Gecko/2008052906 Firefox/3.0 ViewState: (**Very long Gibberish Omitted!**)
Offending URL: (**Omitted**)
Source: System.Web
Message: The state information is invalid for this page and might be corrupted.
Stack trace: at System.Web.UI.ViewStateException.ThrowError(Exception inner, String persistedState, String errorPageMessage, Boolean macValidationError) at System.Web.UI.ClientScriptManager.EnsureEventValidationFieldLoaded() at System.Web.UI.ClientScriptManager.ValidateEvent(String uniqueId, String argument) at System.Web.UI.Control.ValidateEvent(String uniqueID, String eventArgument) at System.Web.UI.WebControls.DropDownList.LoadPostData(String postDataKey, NameValueCollection postCollection) at System.Web.UI.WebControls.DropDownList.System.Web.UI.IPostBackDataHandler.LoadPostData(String postDataKey, NameValueCollection postCollection) at System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
</code></pre>
| [{'answer_id': 73402, 'author': 'MrHinsh - Martin Hinshelwood', 'author_id': 11799, 'author_profile': 'https://Stackoverflow.com/users/11799', 'pm_score': 1, 'selected': False, 'text': '<p>You can remove this error completely by saving your view state to a database and only cleaning within the duration you need to. This also sygnificantly improves the performance of your pages even shen using relatively small viewstates.</p>\n\n<p>At the very least you can inherit from the Page class and add your own ViewStateLoad routen that check to see if it has expired and reloads the default state.</p>\n\n<p>Check <a href="http://www.codeproject.com/KB/viewstate/ViewStateProvider.aspx" rel="nofollow noreferrer">ViewState Provider - an implementation using Provider Model Design Pattern</a> for providing a custom Viewstate provider.</p>\n'}, {'answer_id': 73450, 'author': 'Toby Mills', 'author_id': 12377, 'author_profile': 'https://Stackoverflow.com/users/12377', 'pm_score': 0, 'selected': False, 'text': '<p>Alternatively if you know the time-out length then you could add a bit of javascript to the page which redirects the user to an alternative page if there has been no activity on the page after a preset period of time. You can then extend this to warn the customer that their session / page is about to expire and provide them with a means to extend it (e.g. javascript server call back).</p>\n'}, {'answer_id': 73463, 'author': 'Gilligan', 'author_id': 12356, 'author_profile': 'https://Stackoverflow.com/users/12356', 'pm_score': 2, 'selected': False, 'text': '<p>That is odd as the ViewState is stored as a string in the webpage itself. So I do not see how an extended period of time would cause that error. Perhaps one or more objects on the page have been garbage collected or the application reset, so the viewstate is referencing old controls instead of the controls created when the application restarted. </p>\n\n<p>Whatever the case, I feel your pain, these errors are never pleasant to debug, and I have no easy answer as to how to find the problem other than perhaps studying <a href="http://weblogs.asp.net/infinitiesloop/archive/2006/08/03/Truly-Understanding-Viewstate.aspx" rel="nofollow noreferrer">how ViewState works</a></p>\n'}, {'answer_id': 73757, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>The above posts give you some answers on solving the problem. If just handling the ugly error in the interim is what you\'re looking for, custom errors are the easiest way to gracefully handle all your "ugly yellow errors"</p>\n\n<p><a href="http://msdn.microsoft.com/en-us/library/aa479319.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/aa479319.aspx</a></p>\n\n<p><a href="http://msdn.microsoft.com/en-us/library/h0hfz6fc.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/h0hfz6fc.aspx</a></p>\n'}, {'answer_id': 77377, 'author': 'Mitchel Sellers', 'author_id': 13279, 'author_profile': 'https://Stackoverflow.com/users/13279', 'pm_score': 0, 'selected': False, 'text': '<p>Another option is to add in a global error handler, that would capture the exception at the application level and redirect the user to a "Session Elapsed" page. </p>\n\n<p>If you want an idea of a general implementation of a global error handler, I have one available on my website, I can give you the code if needed - <a href="http://iowacomputergurus.com/free-products/asp.net-global-error-handler.aspx" rel="nofollow noreferrer">http://iowacomputergurus.com/free-products/asp.net-global-error-handler.aspx</a> </p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73380', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12382/'] |
73,385 | <p>Is there an easy way to convert a string from csv format into a string[] or list? </p>
<p>I can guarantee that there are no commas in the data.</p>
| [{'answer_id': 73390, 'author': 'DevelopingChris', 'author_id': 1220, 'author_profile': 'https://Stackoverflow.com/users/1220', 'pm_score': 0, 'selected': False, 'text': "<pre><code>CsvString.split(',');\n</code></pre>\n"}, {'answer_id': 73394, 'author': 'Timothy Carter', 'author_id': 4660, 'author_profile': 'https://Stackoverflow.com/users/4660', 'pm_score': 3, 'selected': True, 'text': "<pre>string[] splitString = origString.Split(',');</pre>\n\n<p><em>(Following comment not added by original answerer)</em>\n<strong>Please keep in mind that this answer addresses the SPECIFIC case where there are guaranteed to be NO commas in the data.</strong></p>\n"}, {'answer_id': 73404, 'author': 'John Sheehan', 'author_id': 1786, 'author_profile': 'https://Stackoverflow.com/users/1786', 'pm_score': 0, 'selected': False, 'text': '<p>Get a string[] of all the lines: </p>\n\n<pre><code>string[] lines = System.IO.File.ReadAllLines("yourfile.csv");\n</code></pre>\n\n<p>Then loop through and split those lines (this error prone because it doesn\'t check for commas in quote-delimited fields):</p>\n\n<pre><code>foreach (string line in lines)\n{\n string[] items = line.Split({\',\'}};\n}\n</code></pre>\n'}, {'answer_id': 73414, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<pre><code>string test = "one,two,three";\nstring[] okNow = test.Split(\',\');\n</code></pre>\n'}, {'answer_id': 73416, 'author': 'Bob King', 'author_id': 6897, 'author_profile': 'https://Stackoverflow.com/users/6897', 'pm_score': 0, 'selected': False, 'text': '<pre><code>string s = "1,2,3,4,5";\n\nstring myStrings[] = s.Split({\',\'}};\n</code></pre>\n\n<p>Note that Split() takes an <em>array</em> of characters to split on.</p>\n'}, {'answer_id': 73419, 'author': 'Paul van Brenk', 'author_id': 1837197, 'author_profile': 'https://Stackoverflow.com/users/1837197', 'pm_score': 0, 'selected': False, 'text': "<pre><code>separationChar[] = {';'}; // or '\\t' ',' etc.\nvar strArray = strCSV.Split(separationChar);\n</code></pre>\n"}, {'answer_id': 73426, 'author': 'Ryan Steckler', 'author_id': 12673, 'author_profile': 'https://Stackoverflow.com/users/12673', 'pm_score': 0, 'selected': False, 'text': '<pre><code>string[] splitStrings = myCsv.Split(",".ToCharArray());\n</code></pre>\n'}, {'answer_id': 73460, 'author': 'John Sheehan', 'author_id': 1786, 'author_profile': 'https://Stackoverflow.com/users/1786', 'pm_score': 3, 'selected': False, 'text': '<p>If you want robust CSV handling, check out <a href="http://www.filehelpers.com/" rel="nofollow noreferrer">FileHelpers</a></p>\n'}, {'answer_id': 73466, 'author': 'Eric Z Beard', 'author_id': 1219, 'author_profile': 'https://Stackoverflow.com/users/1219', 'pm_score': 1, 'selected': False, 'text': "<p>There isn't a simple way to do this well, if you want to account for quoted elements with embedded commas, especially if they are mixed with non-quoted fields.</p>\n\n<p>You will also probably want to convert the lines to a dictionary, keyed by the column name.</p>\n\n<p>My code to do this is several hundred lines long.</p>\n\n<p>I think there are some examples on the web, open source projects, etc.</p>\n"}, {'answer_id': 73526, 'author': 'Panos', 'author_id': 8049, 'author_profile': 'https://Stackoverflow.com/users/8049', 'pm_score': 2, 'selected': False, 'text': '<p>Try:</p>\n\n<pre><code>Regex rex = new Regex(",(?=([^\\"]*\\"[^\\"]*\\")*(?![^\\"]*\\"))");\nstring[] values = rex.Split( csvLine );\n</code></pre>\n\n<p>Source: <a href="http://weblogs.asp.net/prieck/archive/2004/01/16/59457.aspx" rel="nofollow noreferrer">http://weblogs.asp.net/prieck/archive/2004/01/16/59457.aspx</a></p>\n'}, {'answer_id': 73557, 'author': 'Sam', 'author_id': 9406, 'author_profile': 'https://Stackoverflow.com/users/9406', 'pm_score': 0, 'selected': False, 'text': '<p>Some CSV files have double quotes around the values along with a comma. Therefore sometimes you can split on this string literal: "," </p>\n'}, {'answer_id': 73609, 'author': 'claco', 'author_id': 91911, 'author_profile': 'https://Stackoverflow.com/users/91911', 'pm_score': 0, 'selected': False, 'text': '<p><del>A Csv file with Quoted fields, is not a Csv file. Far more things (Excel) output without quotes rather than with quotes when you select "Csv" in a save as.</del></p>\n\n<p>If you want one you can use, free, or commit to, here\'s mine that also does IDataReader/Record. It also uses DataTable to define/convert/enforce columns and DbNull.</p>\n\n<p><a href="http://github.com/claco/csvdatareader/" rel="nofollow noreferrer">http://github.com/claco/csvdatareader/</a></p>\n\n<p>It doesn\'t do quotes.. yet. I just tossed it together a few days ago to scratch an itch.</p>\n\n<p>Forgotten Semicolon: Nice link. Thanks.\ncfeduke: Thanks for the tip to Microsoft.VisualBasic.FileIO.TextFieldParser. Going into CsvDataReader tonight.</p>\n'}, {'answer_id': 73639, 'author': 'Philip Rieck', 'author_id': 12643, 'author_profile': 'https://Stackoverflow.com/users/12643', 'pm_score': 4, 'selected': False, 'text': '<p>String.Split is just not going to cut it, but a Regex.Split may - Try this one:</p>\n\n<pre><code>using System.Text.RegularExpressions;\n\nstring[] line;\nline = Regex.Split( input, ",(?=(?:[^\\"]*\\"[^\\"]*\\")*(?![^\\"]*\\"))");\n</code></pre>\n\n<p>Where \'input\' is the csv line. This will handle quoted delimiters, and should give you back an array of strings representing each field in the line.</p>\n'}, {'answer_id': 73980, 'author': 'cfeduke', 'author_id': 5645, 'author_profile': 'https://Stackoverflow.com/users/5645', 'pm_score': 2, 'selected': False, 'text': "<p>You can take a look at using the Microsoft.VisualBasic assembly with the</p>\n\n<pre><code>Microsoft.VisualBasic.FileIO.TextFieldParser\n</code></pre>\n\n<p>It handles CSV (or any delimiter) with quotes. I've found it quite handy recently.</p>\n"}, {'answer_id': 74093, 'author': 'Steve Cooper', 'author_id': 6722, 'author_profile': 'https://Stackoverflow.com/users/6722', 'pm_score': 1, 'selected': False, 'text': '<p>Try this; </p>\n\n<pre><code>static IEnumerable<string> CsvParse(string input)\n{\n // null strings return a one-element enumeration containing null.\n if (input == null)\n {\n yield return null;\n yield break;\n }\n\n // we will \'eat\' bits of the string until it\'s gone.\n String remaining = input;\n while (remaining.Length > 0)\n {\n\n if (remaining.StartsWith("\\"")) // deal with quotes\n {\n remaining = remaining.Substring(1); // pass over the initial quote.\n\n // find the end quote.\n int endQuotePosition = remaining.IndexOf("\\"");\n switch (endQuotePosition)\n {\n case -1:\n // unclosed quote.\n throw new ArgumentOutOfRangeException("Unclosed quote");\n case 0:\n // the empty quote\n yield return "";\n remaining = remaining.Substring(2);\n break;\n default:\n string quote = remaining.Substring(0, endQuotePosition).Trim();\n remaining = remaining.Substring(endQuotePosition + 1);\n yield return quote;\n break;\n }\n }\n else // deal with commas\n {\n int nextComma = remaining.IndexOf(",");\n switch (nextComma)\n {\n case -1:\n // no more commas -- read to end\n yield return remaining.Trim();\n yield break;\n\n case 0:\n // the empty cell\n yield return "";\n remaining = remaining.Substring(1);\n break;\n\n default:\n // get everything until next comma\n string cell = remaining.Substring(0, nextComma).Trim();\n remaining = remaining.Substring(nextComma + 1);\n yield return cell;\n break;\n }\n }\n }\n\n}\n</code></pre>\n'}, {'answer_id': 80025, 'author': 'claco', 'author_id': 91911, 'author_profile': 'https://Stackoverflow.com/users/91911', 'pm_score': 0, 'selected': False, 'text': '<p><a href="http://github.com/claco/csvdatareader/" rel="nofollow noreferrer">http://github.com/claco/csvdatareader/</a> updated using TextFieldParser suggested by cfeduke.</p>\n\n<p>Just a few props away from exposing separators/trimspaces/type ig you just need code to steal.</p>\n'}, {'answer_id': 84639, 'author': 'JohnOpincar', 'author_id': 16245, 'author_profile': 'https://Stackoverflow.com/users/16245', 'pm_score': 0, 'selected': False, 'text': '<p>I was already splitting on tabs so this did the trick for me:</p>\n\n<pre><code>public static string CsvToTabDelimited(string line) {\n var ret = new StringBuilder(line.Length);\n bool inQuotes = false;\n for (int idx = 0; idx < line.Length; idx++) {\n if (line[idx] == \'"\') {\n inQuotes = !inQuotes;\n } else {\n if (line[idx] == \',\') {\n ret.Append(inQuotes ? \',\' : \'\\t\');\n } else {\n ret.Append(line[idx]);\n }\n }\n }\n return ret.ToString();\n}\n</code></pre>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73385', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12653/'] |
73,432 | <p>Will I have to pay again? I have about 9 months left before renewal but my current provider doesn't offer many options / control panels.</p>
<p>Update: thanks for everyone's help - I've finally completed this now.</p>
<p>I had to:</p>
<ul>
<li>Ask my old registrar to "Unlock" the domain</li>
<li>Ask my old registrar to set the admin email address of the domain to my email</li>
<li>Ask my old registrar for the "authcode"</li>
<li>For the rest I just followed GoDaddy's instructions</li>
</ul>
<p>What a pain in the a**</p>
| [{'answer_id': 73453, 'author': 'Chris Upchurch', 'author_id': 2600, 'author_profile': 'https://Stackoverflow.com/users/2600', 'pm_score': 0, 'selected': False, 'text': '<p>There is a domain transfer procedure. It\'s kind of complex, since it\'s intended to keep people from stealing domains by transferring them to another registrar (like happened to <a href="http://en.wikipedia.org/wiki/Sex.com" rel="nofollow noreferrer">sex.com</a> back in the 90\'s). GoDaddy does a good job of talking you through it (I\'ve transferred a domain to them in the past). Of course, you\'re going to have to pay them to register the domain for you (though they occasionally offer discounts on domain transfers).</p>\n'}, {'answer_id': 73454, 'author': 'MrHinsh - Martin Hinshelwood', 'author_id': 11799, 'author_profile': 'https://Stackoverflow.com/users/11799', 'pm_score': 0, 'selected': False, 'text': '<p>You probably will have to pay. If you check with your current registrar and with your target registar and see what needs to be done with them and what the costs are.</p>\n\n<p>It is diferent for every registar, even though the actual process is the same.</p>\n'}, {'answer_id': 73459, 'author': 'ScaleOvenStove', 'author_id': 12268, 'author_profile': 'https://Stackoverflow.com/users/12268', 'pm_score': 0, 'selected': False, 'text': "<p>they charge you to transfer (like 6.99?), but godaddy will then renew it for a year. You usually need to contact your current hosting and have them release it for transfer, then follow godaddy's procedure for transferring a new domain in.</p>\n"}, {'answer_id': 73477, 'author': 'delux247', 'author_id': 5569, 'author_profile': 'https://Stackoverflow.com/users/5569', 'pm_score': 0, 'selected': False, 'text': '<p>You may need to pay, but when I switched from Register.com to goDaddy.com I paid a very small amount to transfer (like $10) and also renewed the domain for another 2 years. (This turned out to be much cheaper than renewing with Register.com) </p>\n'}, {'answer_id': 73490, 'author': 'Ram Prasad', 'author_id': 6361, 'author_profile': 'https://Stackoverflow.com/users/6361', 'pm_score': 3, 'selected': True, 'text': '<p>This is how it works\nLets say you have 9 more months for your current domain to expire\nyou transfer the domain to GoDaddy (or to any other decent Registrar)\nyou will be charged the price (little more or equal) to the price of booking a new domain\nBUT, you will have the domain for 9 months + one year (or the no. of years you paid godaddy for)</p>\n\n<p>So, you choose to transfer the domain and pay USD9.99 (for a year), you will have the domains for 1 year + 9 months</p>\n'}, {'answer_id': 73493, 'author': 'OwenP', 'author_id': 2547, 'author_profile': 'https://Stackoverflow.com/users/2547', 'pm_score': 1, 'selected': False, 'text': "<p>I did this when I had to switch hosts from awful, unreliable Fuitadnet. They managed the domain for me so I emailed them that I wanted to transfer my domain. (I transferred to GoDaddy.)</p>\n\n<p>I don't remember all of the details, but I seem to recall it was a multiple-handshake process. First, they had to get my current registrar to release the domain; this involved having an email sent to me so I could confirm I actually wanted to release the domain. Then, I got a confirmation code that I sent to the new registrar, who did something or the other and came back with a new confirmation code. Once I entered the final confirmation code, the domain belonged to the new registrar. It took a few days and for some reason my first set of codes didn't work, but I found GoDaddy was pretty good at explaining what was going on.</p>\n\n<p>I did have to pay a transfer fee, but the registration retained its length. I opted to renew it because there was a discount at the time.</p>\n\n<p>If you contact your current host/registrar and they should be able to help you out; this was one of the few times I actually got good service out of fuitadnet.</p>\n"}, {'answer_id': 73495, 'author': 'Shoban', 'author_id': 12178, 'author_profile': 'https://Stackoverflow.com/users/12178', 'pm_score': 0, 'selected': False, 'text': '<p>Yeah!! I was charged by my new registrar when I moved. Also remember you should have the secret key (transfer code) before you start your transfer process.</p>\n'}, {'answer_id': 73497, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': "<p>Depends on the host also. If you go with a company like BlueHost, for example, they'll give you free domain transfers from the losing registrar. I think, in fact, they may give you free transfers. They will and ask if you want to renew your domain with them which will cost you, though.</p>\n"}, {'answer_id': 73502, 'author': 'Dr. Bob', 'author_id': 12182, 'author_profile': 'https://Stackoverflow.com/users/12182', 'pm_score': 1, 'selected': False, 'text': '<p>You must have the domain unlocked with your current registrar and make sure that your contact information is up to date.</p>\n\n<p>You can then have the new registrar submit a transfer request. This will result in you being sent a notification (assuming your contact information is accurate).</p>\n\n<p>You will have to follow the directions in that transfer request email.</p>\n\n<p>The domain may take up to a few days to fully transfer to the new registrar.</p>\n\n<p>When you transfer a domain, you are effectively extending the registration for another year so you will be charged the standard transfer/registration fee.</p>\n\n<p>If you have any questions, you can always contact the company you would like to become the new registrar. I am sure they would be able to walk you through their process exactly.</p>\n'}, {'answer_id': 73565, 'author': 'George Mauer', 'author_id': 5056, 'author_profile': 'https://Stackoverflow.com/users/5056', 'pm_score': 1, 'selected': False, 'text': '<p>Just so you know, <a href="http://nodaddy.com/" rel="nofollow noreferrer">GoDaddy as a company has a somewhat dubious reputation</a>. I personally have never had any problems with them but I have only a few low-profile sites and have never done anything even remotely complicated with the DNS.</p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73432', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/11911/'] |
73,433 | <p>Does a caching-nameserver usually cache the negative DNS response SERVFAIL? </p>
<p>EDIT:
To clarify the question, I can see the caching nameserver caching negative responses NXDOMAIN, NODATA. But it does not do this for SERVFAIL responses. Is this intentional?</p>
| [{'answer_id': 73461, 'author': 'Alex M', 'author_id': 9652, 'author_profile': 'https://Stackoverflow.com/users/9652', 'pm_score': 0, 'selected': False, 'text': '<p>One of the timeout fields in the SOA is a "negative timeout". It is usually set to a short time, such as 30 or 60 seconds. So, yes, but for a shorter time than a "positive" response.</p>\n'}, {'answer_id': 73540, 'author': 'pobk', 'author_id': 7829, 'author_profile': 'https://Stackoverflow.com/users/7829', 'pm_score': 2, 'selected': False, 'text': '<p><a href="http://www.faqs.org/rfcs/rfc1034.html" rel="nofollow noreferrer">RFC 1034</a> describes how to cache negative responses but did not define a mechanism for returning those cache results to peer resolvers. <a href="http://www.faqs.org/rfcs/rfc2308.html" rel="nofollow noreferrer">RFC 2308</a> defines these attributes.</p>\n\n<p>Negative caching was an optional part of the DNS Specifications...</p>\n'}, {'answer_id': 115261, 'author': 'Alnitak', 'author_id': 6782, 'author_profile': 'https://Stackoverflow.com/users/6782', 'pm_score': 4, 'selected': True, 'text': "<p>SERVFAIL is covered by §7.1 of RFC2308:</p>\n\n<blockquote>\n <p>Server failures fall into two major\n classes. The first is where a \n server can determine that it has been\n misconfigured for a zone. This may\n be where it has been listed as a server, but not configured to be a\n server for the zone, or where it has\n been configured to be a server for\n the zone, but cannot obtain the zone\n data for some reason. This can\n occur either because the zone file\n does not exist or contains errors,\n or because another server from which\n the zone should have been available\n either did not respond or was unable\n or unwilling to supply the zone.</p>\n \n <p>The second class is where the\n server needs to obtain an answer from \n elsewhere, but is unable to do so, due\n to network failures, other servers\n that don't reply, or return server\n failure errors, or similar.</p>\n \n <p>In either case a resolver MAY cache\n a server failure response. If it \n does so it MUST NOT cache it for\n longer than five (5) minutes, and it \n MUST be cached against the specific\n query tuple <query name, type, \n class, server IP address>.</p>\n</blockquote>\n\n<p>So basically, it's dependent on the implementation of your name server.</p>\n"}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73433', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12658/'] |
73,447 | <p>What's the most efficient way to convert the output of this function from a varbinary() to a a varchar()?</p>
| [{'answer_id': 73503, 'author': 'Eric Z Beard', 'author_id': 1219, 'author_profile': 'https://Stackoverflow.com/users/1219', 'pm_score': 4, 'selected': True, 'text': '<p>How about this:</p>\n\n<pre><code>master.sys.fn_varbintohexstr(@binvalue)\n</code></pre>\n'}, {'answer_id': 887570, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>CONVERT(varchar, @binary)</p>\n'}, {'answer_id': 7979858, 'author': 'Cheburek', 'author_id': 311108, 'author_profile': 'https://Stackoverflow.com/users/311108', 'pm_score': 2, 'selected': False, 'text': '<p>For SQL Server 2008 use</p>\n\n<pre><code>CONVERT(varchar, @binary, 1)\n</code></pre>\n\n<p>1 - style 0x060D,\n2 - 060D</p>\n\n<p><a href="http://msdn.microsoft.com/en-gb/library/ms187928.aspx" rel="nofollow">http://msdn.microsoft.com/en-gb/library/ms187928.aspx</a></p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73447', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/366182/'] |
73,456 | <p>I have a weird problem with a dropdownbox selectedIndex always being set to 0 upon postback. I'm not accidentally rebinding it in my code. In fact I've placed a breakpoint at the very first line of the page_load event and the value is already set to zero. The dropdown is in the master page of my project, I don't know if that makes a difference. I'm not referencing the control in my content holder. </p>
<p>If I set my autoPostBack = 'true' the page works fine. I don't have to change any code and the selectedIndex is maintained. I have also tried setting enableViewState on and off and it doesn't make a difference. At this point I'm grasping at straws to figure out what's going on. I've never had this problem before.</p>
<p>Here is the code in my page_load event.</p>
<pre><code> If CartEstablished Then
txtCustNum.Visible = False
btnCustSearch.Visible = False
lblCustNum.Visible = True
ddlSalesType.Visible = False
lblSalesType.Visible = True
ddlTerms.Visible = False
lblTerms.Visible = True
lblTerms.Text = TermsDescription
Else
txtCustNum.Visible = True
btnCustSearch.Visible = True
lblCustNum.Visible = False
lblSalesType.Visible = False
ddlSalesType.Visible = True
lblTerms.Visible = False
ddlTerms.Visible = True
End If
If Page.IsPostBack Then
GetUIValues()
Else
LoadTermCodes()
End If
</code></pre>
<p>The LoadTermCodes is where I bind the dropdownlist that is causing me problems.</p>
| [{'answer_id': 73501, 'author': 'Gilligan', 'author_id': 12356, 'author_profile': 'https://Stackoverflow.com/users/12356', 'pm_score': 1, 'selected': False, 'text': '<p>Are you sure you are doing a postback and not a refresh? It is hard to help you without more context into the problem or a chunk of the code.</p>\n'}, {'answer_id': 73543, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>This may be barking up the wrong tree, but a couple of things that have bitten me in the past that left me scratching my head:</p>\n\n<ul>\n<li>Naming the input element a duplicated/reserved word (thinking "name", "method", "reset", etc.)</li>\n<li>having the form element physically outside of the form being submitted</li>\n</ul>\n\n<p>I find that when all the logical debugging turns up nothing, my own dumbness has created time-wasting "mystery" bugs like this on occasion.</p>\n'}, {'answer_id': 73627, 'author': 'derek lawless', 'author_id': 400464, 'author_profile': 'https://Stackoverflow.com/users/400464', 'pm_score': 0, 'selected': False, 'text': "<p>At what stage in the page lifecycle are you binding the dropdownlist? If you're binding in page_init it should work, if you're binding in page_load make sure you wrap a !IsPostBack around the binding commands.</p>\n\n<p>If you post the code in question it'd be easier to troubleshoot.</p>\n"}, {'answer_id': 74783, 'author': 'Gilligan', 'author_id': 12356, 'author_profile': 'https://Stackoverflow.com/users/12356', 'pm_score': -1, 'selected': False, 'text': "<p>This may simply be a syntax error, but shouldn't</p>\n\n<pre><code> If Page.IsPostBack Then\n GetUIValues()\n Else\n</code></pre>\n\n<p>Look like this</p>\n\n<pre><code> If NOT Page.IsPostBack Then\n GetUIValues()\n Else\n</code></pre>\n"}, {'answer_id': 264776, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': "<p>I'm finding the same problem... in my case, the dropdownlist is filled by a javascript function after another dropdownlist onchange client event. On PageLoad, the 2nd dropdownlist has lost all its items and so its selectedIndex turns to 0. Is there any way of preventing this?</p>\n"}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73456', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/288/'] |
73,467 | <p>I've got a custom handler applied to a class (using the Policy Injection Application Block in entlib 4) and I would like to know whether the input method is a property when Invoke is called. Following is what my handler looks like.</p>
<pre><code>[ConfigurationElementType(typeof(MyCustomHandlerData))]
public class MyCustomHandler : ICallHandler
{
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
if (input.MethodBase.IsPublic && (input.MethodBase.Name.Contains("get_") || input.MethodBase.Name.Contains("set_")))
{
Console.WriteLine("MyCustomHandler Invoke called with input of {0}", input.MethodBase.Name);
}
return getNext().Invoke(input, getNext);
}
public int Order { get; set; }
}
</code></pre>
<p>As you can see from my code sample, the best way I've thought of so far is by parsing the method name. Isn't there a better way to do this?</p>
| [{'answer_id': 73747, 'author': 'Fredrik Kalseth', 'author_id': 1710, 'author_profile': 'https://Stackoverflow.com/users/1710', 'pm_score': 0, 'selected': False, 'text': '<p>You could check the IsSpecialName property; it will be true for property getters and setters. However, it will also be true for other special methods, like operator overloads.</p>\n'}, {'answer_id': 73779, 'author': 'Nathan Baulch', 'author_id': 8799, 'author_profile': 'https://Stackoverflow.com/users/8799', 'pm_score': 0, 'selected': False, 'text': '<p>I\'m not familiar with that application block, but assuming that MethodBase property is of type System.Reflection.MethodBase, you could take a look at the IsSpecialName property.</p>\n\n<p><a href="http://msdn.microsoft.com/en-us/library/system.reflection.methodbase.isspecialname.aspx" rel="nofollow noreferrer">System.Reflection.MethodBase.IsSpecialName on MSDN</a></p>\n'}, {'answer_id': 73908, 'author': 'ShuggyCoUk', 'author_id': 12748, 'author_profile': 'https://Stackoverflow.com/users/12748', 'pm_score': 3, 'selected': True, 'text': "<p>You can also check IsSpecialName is true. this will be true in a property (amongst other things)</p>\n\n<p>At the il level the methods are exposed as follows (using Environment.ExitCode as example):</p>\n\n<pre><code>.method public hidebysig specialname static int32 get_ExitCode() cil managed\n.method public hidebysig specialname static void set_ExitCode(int32 'value') cil managed\n</code></pre>\n\n<p>If you wanted to get fancy you could verify after extracting the name that said property exists but to be honest </p>\n\n<pre><code>if (m.IsSpecialName && (m.Attributes & MethodAttributes.HideBySig) != 0)) \n</code></pre>\n\n<p>as well as starts with get_ or set_ then you should be good even for people using nasty names (faking the hidebysig is easy enough, faking the IsSpecialName would be very tricky)</p>\n\n<p>Nothing is guaranteed though. Someone could emit a class with a set_Foo method that looked just like a real set method but actually wasn't a set on a read only property.\nUnless you check whether the property CanRead/CanWrite as well.</p>\n\n<p>This strikes me as madness for you though you aren't expecting deliberate circumvention. \nA simple utility/extension method on MethodInfo which did this logic wouldn't be too hard and including IsSpecialName would almost certainly cover all your needs.</p>\n"}, {'answer_id': 24102577, 'author': 'Paul Easter', 'author_id': 3583929, 'author_profile': 'https://Stackoverflow.com/users/3583929', 'pm_score': 0, 'selected': False, 'text': '<p>A couple of you mentioned using the "IsSpecialName" property of the MethodBase type. While it is true that the will return true for property "gets" or "sets", it will also return true for operator overloads such as add_EventName or remove_EventName. So you will need to examine other attributes of the MethodBase instance to determine if its a property accessor. Unfortunately, if all you have is a reference to a MethodBase instance (which I believe is the case with intercepting behaviors in the Unity framework) there is not real "clean" way to determine if its a property setter or getter. The best way I\'ve found is as follows:</p>\n\n<p>C#:</p>\n\n<pre><code>bool IsPropertySetter(MethodBase methodBase){\n return methodBase.IsSpecialName && methodBase.Name.StartsWith("set_");\n}\n\nbool IsPropertyGetter(MethodBase methodBase){\n return methodBase.IsSpecialName && methodBase.Name.StartsWith("get_");\n}\n</code></pre>\n\n<p>VB:</p>\n\n<pre><code> Private Function IsPropertySetter(methodBase As MethodBase) As Boolean\n\n Return methodBase.IsSpecialName AndAlso methodBase.Name.StartsWith("set_")\n\n End Function\n\n Private Function IsPropertyGetter(methodBase As MethodBase) As Boolean\n\n Return methodBase.IsSpecialName AndAlso methodBase.Name.StartsWith("get_")\n\n End Function\n</code></pre>\n'}, {'answer_id': 40128143, 'author': 'Tomaz Stih', 'author_id': 6286989, 'author_profile': 'https://Stackoverflow.com/users/6286989', 'pm_score': 0, 'selected': False, 'text': '<p>It is a bit late but other people will read this too. In addition to IsSpecialName and checking for the set_ prefix (operators have op_, event subscr./remov. has add_,remove_) you can check if method is a match to any of properties methods like this:</p>\n\n<pre><code> bool isProperty = method.ReflectedType.GetProperties().FirstOrDefault(p => \n p.GetGetMethod().GetHashCode() == method.GetHashCode() \n || p.GetSetMethod().GetHashCode() == method.GetHashCode())!=null;\n</code></pre>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73467', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/6542/'] |
73,468 | <p>I'm coding the shutdown of a multithreaded server.If everything goes as it should all the threads exit by their own, but there's a small chance that a thread gets stuck.In this case it would be convenient to have a non-blocking join so I could do.</p>
<p><strong>Is there a way of doing a non-blocking pthread_join?
Some sort of timed join would be good too.</strong></p>
<p>something like this:</p>
<pre>
foreach thread do
nb_pthread_join();
if still running
pthread_cancel();
</pre>
<p>I can think more cases where a a non-bloking join would be useful.</p>
<p>As it seems there is no such a function so I have already coded a workaround, but it's not as simple as I would like.</p>
| [{'answer_id': 73481, 'author': 'Doug T.', 'author_id': 8123, 'author_profile': 'https://Stackoverflow.com/users/8123', 'pm_score': 0, 'selected': False, 'text': '<p>You could push a byte into a pipe opened as non-blocking to signal to the other thread when its done, then use a non-blocking read to check the status of the pipe.</p>\n'}, {'answer_id': 73535, 'author': 'raldi', 'author_id': 7598, 'author_profile': 'https://Stackoverflow.com/users/7598', 'pm_score': 1, 'selected': False, 'text': '<p>The answer really depends on why you want to do this. If you just want to clean up dead threads, for example, it\'s probably easiest just to have a "dead thread cleaner" thread that loops and joins.</p>\n'}, {'answer_id': 73821, 'author': 'Srikanth', 'author_id': 7205, 'author_profile': 'https://Stackoverflow.com/users/7205', 'pm_score': 1, 'selected': False, 'text': '<p>I\'m not sure what exactly you mean, but I\'m assuming that what you really need is a wait and notify mechanism.</p>\n\n<p>In short, here\'s how it works: You wait for a condition to satisfy with a timeout. Your wait will be over if:</p>\n\n<ul>\n<li>The timeout occurs, or</li>\n<li>If the condition is satisfied.</li>\n</ul>\n\n<p>You can have this in a loop and add some more intelligence to your logic. The best resource I\'ve found for this related to Pthreads is this tutorial:\nPOSIX Threads Programming (<a href="https://computing.llnl.gov/tutorials/pthreads/" rel="nofollow noreferrer">https://computing.llnl.gov/tutorials/pthreads/</a>).</p>\n\n<p>I\'m also very surprised to see that there\'s no API for timed join in Pthreads.</p>\n'}, {'answer_id': 81050, 'author': 'shodanex', 'author_id': 11589, 'author_profile': 'https://Stackoverflow.com/users/11589', 'pm_score': 1, 'selected': False, 'text': '<p>There is no timed <code>pthread_join</code>, but if you are waiting for other thread blocked on conditions, you can use timed <code>pthread_cond_timed_wait</code> instead of <code>pthread_cond_wait</code></p>\n'}, {'answer_id': 81261, 'author': 'dmityugov', 'author_id': 3232, 'author_profile': 'https://Stackoverflow.com/users/3232', 'pm_score': 2, 'selected': False, 'text': "<p>If you're developing for QNX, you can use pthread_timedjoin() function.</p>\n\n<p>Otherwise, you can create a separate thread that will perform pthread_join() and alert the parent thread, by signalling a semaphore for example, that the child thread completes. This separate thread can return what is gets from pthread_join() to let the parent thread determine not only when the child completes but also what value it returns.</p>\n"}, {'answer_id': 83788, 'author': 'Frosty', 'author_id': 7476, 'author_profile': 'https://Stackoverflow.com/users/7476', 'pm_score': 2, 'selected': True, 'text': '<p>As others have pointed out there is not a non-blocking pthread_join available in the standard pthread libraries.</p>\n\n<p>However, given your stated problem (trying to guarantee that all of your threads have exited on program shutdown) such a function is not needed. You can simply do this:</p>\n\n<pre><code>int killed_threads = 0;\nfor(i = 0; i < num_threads; i++) {\n int return = pthread_cancel(threads[i]);\n if(return != ESRCH)\n killed_threads++;\n}\nif(killed_threads)\n printf("%d threads did not shutdown properly\\n", killed_threads)\nelse\n printf("All threads exited successfully");\n</code></pre>\n\n<p>There is nothing wrong with calling pthread_cancel on all of your threads (terminated or not) so calling that for all of your threads will not block and will guarantee thread exit (clean or not).</p>\n\n<p>That should qualify as a \'simple\' workaround.</p>\n'}, {'answer_id': 1244687, 'author': 'yves Baumes', 'author_id': 83331, 'author_profile': 'https://Stackoverflow.com/users/83331', 'pm_score': 5, 'selected': False, 'text': '<p>If you are running your application on Linux, you may be interested to know that:</p>\n\n<pre><code>int pthread_tryjoin_np(pthread_t thread, void **retval);\n\nint pthread_timedjoin_np(pthread_t thread, void **retval,\n const struct timespec *abstime);\n</code></pre>\n\n<p>Be careful, as the suffix suggests it, "np" means "non-portable". They are not POSIX standard, gnu extensions, useful though.</p>\n\n<p><a href="http://www.kernel.org/doc/man-pages/online/pages/man3/pthread_tryjoin_np.3.html" rel="noreferrer">link to man page</a></p>\n'}, {'answer_id': 7535847, 'author': 'David Schwartz', 'author_id': 721269, 'author_profile': 'https://Stackoverflow.com/users/721269', 'pm_score': 4, 'selected': False, 'text': "<p>The 'pthread_join' mechanism is a convenience to be used if it happens to do exactly what you want. It doesn't do anything you couldn't do yourself, and where it's not exactly what you want, code exactly what you want.</p>\n\n<p>There is no real reason you should actually care whether a thread has terminated or not. What you care about is whether the work the thread was doing is completed. To tell that, have the thread do something to indicate that it is working. How you do that depends on what is ideal for your specific problem, which depends heavily on what the threads are doing.</p>\n\n<p>Start by changing your thinking. It's not a thread that gets stuck, it's what the thread was doing that gets stuck.</p>\n"}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73468', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12661/'] |
73,471 | <p>I have an editable DataGridView with SelectionMode set to FullRowSelect (so the whole row is highlighted when the user clicks on any cell). However I would like the cell that currently has focus to be highlighted with a different back color (so the user can clearly see what cell they are about to edit). How can I do this (I do not want to change the SelectionMode)?</p>
| [{'answer_id': 73636, 'author': 'Clinton Pierce', 'author_id': 8173, 'author_profile': 'https://Stackoverflow.com/users/8173', 'pm_score': 0, 'selected': False, 'text': '<p>You want to use the DataGridView RowPostPaint method. Let the framework draw the row, and afterwards go back and color in the cell you\'re interested in.</p>\n\n<p>An example is here at <a href="http://msdn.microsoft.com/en-us/library/85kxk29c.aspx" rel="nofollow noreferrer">MSDN</a></p>\n'}, {'answer_id': 74256, 'author': 'Phillip Wells', 'author_id': 3012, 'author_profile': 'https://Stackoverflow.com/users/3012', 'pm_score': 4, 'selected': True, 'text': '<p>I figured out a better way of doing this, using the CellFormatting event:</p>\n\n<pre><code>Private Sub uxContacts_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles uxContacts.CellFormatting\n If uxContacts.CurrentCell IsNot Nothing Then\n If e.RowIndex = uxContacts.CurrentCell.RowIndex And e.ColumnIndex = uxContacts.CurrentCell.ColumnIndex Then\n e.CellStyle.SelectionBackColor = Color.SteelBlue\n Else\n e.CellStyle.SelectionBackColor = uxContacts.DefaultCellStyle.SelectionBackColor\n End If\n End If\nEnd Sub\n</code></pre>\n'}, {'answer_id': 11961408, 'author': 'Henry Rodriguez', 'author_id': 8892051, 'author_profile': 'https://Stackoverflow.com/users/8892051', 'pm_score': 0, 'selected': False, 'text': '<p>Try this, the OnMouseMove method:</p>\n\n<pre><code>Private Sub DataGridView1_CellMouseMove(sender As Object, e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseMove\n If e.RowIndex >= 0 Then\n DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Style.SelectionBackColor = Color.Red\n End If\nEnd Sub\n\nPrivate Sub DataGridView1_CellMouseLeave(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellMouseLeave\n If e.RowIndex >= 0 Then\n DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Style.SelectionBackColor = DataGridView1.DefaultCellStyle.SelectionBackColor\n End If\nEnd Sub\n</code></pre>\n'}, {'answer_id': 32944008, 'author': 'Dennis Henry', 'author_id': 2790151, 'author_profile': 'https://Stackoverflow.com/users/2790151', 'pm_score': 1, 'selected': False, 'text': '<p>For me <code>CellFormatting</code> does the Trick. I have a set of columns that one can Edit (that I made to appear in a different color) and this is the code I used:</p>\n\n<pre><code>Private Sub Util_CellFormatting(ByVal Sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles dgvUtil.CellFormatting\n If dgvUtil.CurrentCell IsNot Nothing Then\n If e.RowIndex = dgvUtil.CurrentCell.RowIndex And e.ColumnIndex = dgvUtil.CurrentCell.ColumnIndex And (dgvUtil.CurrentCell.ColumnIndex = 10 Or dgvUtil.CurrentCell.ColumnIndex = 11 Or dgvUtil.CurrentCell.ColumnIndex = 13) Then\n e.CellStyle.SelectionBackColor = Color.SteelBlue\n Else\n e.CellStyle.SelectionBackColor = dgvUtil.DefaultCellStyle.SelectionBackColor\n End If\n End If\nEnd Sub\n</code></pre>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73471', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3012/'] |
73,474 | <p>I am having a frequent problems with my web hosting (its shared)</p>
<p>I am not able to delete or change permission for a particular directory. The response is,</p>
<pre><code>Cannot delete. Directory may not be empty
</code></pre>
<p>I checked the permissions and it looks OK. There are 100's of files in this folder which I don't want. </p>
<p>I contacted my support and they solved it saying it was permission issue. But it reappeared. Any suggestions?</p>
<p>The server is Linux.</p>
| [{'answer_id': 73529, 'author': 'Ram Prasad', 'author_id': 6361, 'author_profile': 'https://Stackoverflow.com/users/6361', 'pm_score': 0, 'selected': False, 'text': '<p>This could also be because your FTP client might not be showing the hidden files (like cache, or any hiddn files that your application might create), while the hidden files are preventing you from deleting the directory. (though, in your case, I am not sure if this is the cause .. .it could be permission issue with your hosting provider.. Webserver running as another user (like apache or www) combined with your directories having global write perms).</p>\n'}, {'answer_id': 73549, 'author': 'Jon Ericson', 'author_id': 1438, 'author_profile': 'https://Stackoverflow.com/users/1438', 'pm_score': 3, 'selected': True, 'text': "<p>You can't <strong>rmdir</strong> a directory with files in it. You must first <strong>rm</strong> all files and subdirectories. Many times, the easiest solution is:</p>\n\n<pre><code>$ rm -rf old_directory\n</code></pre>\n\n<p>It's entirely possible that some of the files or subdirectories have permission limitations that might prevent them from being removed. Occasionally, this can be solved with:</p>\n\n<pre><code>$ chmod -R +w old_directory\n</code></pre>\n\n<p>But I suspect that's what your support people did earlier.</p>\n"}, {'answer_id': 73584, 'author': 'chakrit', 'author_id': 3055, 'author_profile': 'https://Stackoverflow.com/users/3055', 'pm_score': 0, 'selected': False, 'text': "<p>I assume that's a response from an FTP server?</p>\n\n<p>Usually, a message from an FTP server really means it. If it says the directory is not empty, there might be certain files you cannot see that exists in the directory which maybe one of:</p>\n\n<ul>\n<li>Your PHP/JSP/ASP/whatever scripts may run under a different user account thus creating files which you may not be able to see/delete</li>\n<li>Is your hosting's web interface run under your FTP account? There might be conflicting permissions there if you manage some files from the web interface and then later via FTP.</li>\n<li>Hosting server/operating system files created unintentionally e.g. from the hosting's web interface</li>\n</ul>\n\n<p>If it comes from a script, write a one-time throw-away script that delete the files and that directory and then uploads and executes it.</p>\n\n<p>And just to be sure, some FTP server doesn't support direct directory deletion, you need all the files first, is that the case?</p>\n"}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73474', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12178/'] |
73,476 | <p>We use SAX to parse XML because it does not require the entire XML document to be read into memory in order to parse a single value. I read many articles that insisted SAX can only be used to parse/decode XML and not create it. Is this true?</p>
| [{'answer_id': 73483, 'author': 'Grant Wagner', 'author_id': 9254, 'author_profile': 'https://Stackoverflow.com/users/9254', 'pm_score': 3, 'selected': True, 'text': '<p>No, it isn\'t true, you can encode XML to any Writer in Java using something similar to:</p>\n\n<pre><code>char[] ch;\nAttributesImpl atts = new AttributesImpl();\nWriter writer = new StringWriter();\nStreamResult streamResult = new StreamResult(writer);\nSAXTransformerFactory tf = (SAXTransformerFactory) TransformerFactory.newInstance();\n\n// SAX2.0 ContentHandler\nTransformerHandler transformerHandler = tf.newTransformerHandler();\n\nTransformer serializer = transformerHandler.getTransformer();\n\nserializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");\n// serializer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "nodes.dtd");\nserializer.setOutputProperty(OutputKeys.INDENT, "yes");\n\ntransformerHandler.setResult(streamResult);\n\ntransformerHandler.startDocument();\n\natts.clear();\n// atts.addAttribute("", "", "xmlns", "CDATA", "http://www.example.com/nodes");\n// atts.addAttribute("", "", "xmlns:xsi", "CDATA", "http://www.w3.org/2001/XMLSchema-instance");\n// atts.addAttribute("", "", "xsi:schemaLocation", "CDATA", "/nodes.xsd");\ntransformerHandler.startElement("", "", "node_list", atts);\n\n// displayName element\nif (displayName != null) {\n transformerHandler.startElement("", "", "display_name", null);\n ch = displayName.toCharArray();\n transformerHandler.characters(ch, 0, ch.length);\n transformerHandler.endElement("", "", "display_name");\n}\n\n// nodes element\ntransformerHandler.startElement("", "", "nodes", null);\n\natts.clear();\natts.addAttribute("", "", "node_type", "CDATA", "sometype");\ntransformerHandler.startElement("", "", "node", atts);\n\nch = node.getValue().toCharArray();\ntransformerHandler.startElement("", "", "value", null);\ntransformerHandler.characters(ch, 0, ch.length);\ntransformerHandler.endElement("", "", "value");\n\ntransformerHandler.endElement("", "", "node");\n\ntransformerHandler.endElement("", "", "nodes");\n\ntransformerHandler.endElement("", "", "node_list");\n\ntransformerHandler.endDocument();\n\nString xml = writer.toString();\n</code></pre>\n'}, {'answer_id': 73936, 'author': 'Tom Hawtin - tackline', 'author_id': 4725, 'author_profile': 'https://Stackoverflow.com/users/4725', 'pm_score': 0, 'selected': False, 'text': "<p>The SAX handler interfaces were designed to be easy to implement. It's easy to write a class with similar (perhaps wrapping a SAX interface) to make it easy to call - chaining, remembering which element to close, easier attributes, etc.</p>\n"}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73476', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/9254/'] |
73,484 | <p>Basically I would like to find a way to ddo something like:</p>
<pre><code><asp:Label ID="lID" runat="server" AssociatedControlID="txtId" Text="<%# MyProperty %>"></asp:Label>
</code></pre>
<p>I know I could set it from code behind (writing lId.Text = MyProperty), but I'd prefer doing it in the markup and I just can't seem to find the solution.
(MyProperty is a string property)
cheers</p>
| [{'answer_id': 73507, 'author': 'Akselsson', 'author_id': 8862, 'author_profile': 'https://Stackoverflow.com/users/8862', 'pm_score': 0, 'selected': False, 'text': '<p>Call lID.Databind() from code-behind</p>\n'}, {'answer_id': 73513, 'author': 'John Sheehan', 'author_id': 1786, 'author_profile': 'https://Stackoverflow.com/users/1786', 'pm_score': 2, 'selected': False, 'text': '<p>Leave the markup as is and make a call to Page.DataBind(); in your code behind.</p>\n'}, {'answer_id': 73558, 'author': 'Serhat Ozgel', 'author_id': 31505, 'author_profile': 'https://Stackoverflow.com/users/31505', 'pm_score': 2, 'selected': False, 'text': '<pre><code><asp:Label id="lID" runat="server"><%= MyProperty %></asp:Label>\n</code></pre>\n\n<p>since asp.net tags do not allow <% %> constructs, you cannot use Text="<%= MyProperty %>".</p>\n'}, {'answer_id': 73585, 'author': 'DevelopingChris', 'author_id': 1220, 'author_profile': 'https://Stackoverflow.com/users/1220', 'pm_score': 0, 'selected': False, 'text': '<pre><code><div> <%=MyProperty"%></div>\n</code></pre>\n'}, {'answer_id': 74054, 'author': 'Mark S. Rasmussen', 'author_id': 12469, 'author_profile': 'https://Stackoverflow.com/users/12469', 'pm_score': 4, 'selected': False, 'text': '<p>You can do </p>\n\n<pre><code><asp:Label runat="server" Text=\'<%# MyProperty %>\' />\n</code></pre>\n\n<p>And then a Page.DataBind() in the codebehind.</p>\n'}, {'answer_id': 75080, 'author': 'Frederik Vig', 'author_id': 9819, 'author_profile': 'https://Stackoverflow.com/users/9819', 'pm_score': 0, 'selected': False, 'text': "<p>When you use <%# MyProperty %> declaration you need to databind it, but when using <%= MyProperty %> you don't (which is similar to just writing Response.Write(MyProperty).</p>\n"}, {'answer_id': 75235, 'author': 'mrflippy', 'author_id': 13292, 'author_profile': 'https://Stackoverflow.com/users/13292', 'pm_score': 4, 'selected': True, 'text': '<p>Code expressions are an option as well. These can be used inside of quotes in ASP tags, unlike standard <%= %> tags.</p>\n\n<p>The general syntax is:</p>\n\n<pre><code><%$ resources: ResourceKey %>\n</code></pre>\n\n<p>There is a built-in expression for appSettings:</p>\n\n<pre><code><%$ appSettings: AppSettingsKey %>\n</code></pre>\n\n<p>More info on this here: <a href="http://weblogs.asp.net/infinitiesloop/archive/2006/08/09/The-CodeExpressionBuilder.aspx" rel="noreferrer">http://weblogs.asp.net/infinitiesloop/archive/2006/08/09/The-CodeExpressionBuilder.aspx</a></p>\n'}, {'answer_id': 2968964, 'author': 'Brian', 'author_id': 357836, 'author_profile': 'https://Stackoverflow.com/users/357836', 'pm_score': 0, 'selected': False, 'text': '<p>You can do this: </p>\n\n<pre><code><asp:Label ID="lblCurrentTime" runat="server">\n Last update: <%=DateTime.Now.ToString()%>\n</asp:Label>\n</code></pre>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73484', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1613872/'] |
73,487 | <p>I'd like a dead simple explanation of policy injection for less-informed co-workers. Where is a good resource for this? I learned about policy injection from the entlib help files, which I'm sure aren't the best option.</p>
| [{'answer_id': 73648, 'author': 'Fredrik Kalseth', 'author_id': 1710, 'author_profile': 'https://Stackoverflow.com/users/1710', 'pm_score': 1, 'selected': False, 'text': '<p>What the EntLib calls Policy Injection, is really Aspect Oriented Programming. I wrote a post <a href="http://iridescence.no/post/Aspect-Oriented-Programming-A-Primer.aspx" rel="nofollow noreferrer">introducing the concepts of AOP on my blog</a> a while back, maybe it\'ll be helpful.</p>\n'}, {'answer_id': 253764, 'author': 'Robert S.', 'author_id': 7565, 'author_profile': 'https://Stackoverflow.com/users/7565', 'pm_score': 3, 'selected': True, 'text': '<p><a href="http://msdn.microsoft.com/en-us/library/cc309370.aspx" rel="nofollow noreferrer">The MSDN documentation for Policy Injection</a> has a pretty clear explanation:</p>\n\n<blockquote>\n <p>Applications include a mix of business\n logic and crosscutting concerns, and\n the two are typically\n intermingled—which can make the code\n harder to read and maintain. Each task\n or feature of an application is\n referred to as a "concern." Concerns\n that implement the features of an\n object within the application, such as\n the business logic, are core concerns.\n Crosscutting concerns are the\n necessary tasks, features, or\n processes that are common across\n different objects—for example,\n logging, authorization, validation,\n and instrumentation. The purpose of\n the Policy Injection Application Block\n is to separate the core concerns and\n crosscutting concerns.</p>\n</blockquote>\n\n<p>Simply put, the PI block lets developers define a set of policies that specify the behavior of objects in the system. So your core business logic, such as the code that calculates profit per unit in a fiscal year (one concern), is separated from the logging of that execution of logic (another, but more often used, concern). </p>\n\n<p>The same documentation says that the PI block is <em>not</em> AOP because:</p>\n\n<ul>\n<li>It uses interception to enable only pre-processing handlers and post-processing handlers. </li>\n<li>It does not insert code into methods. </li>\n<li>It does not provide interception for class constructors. </li>\n</ul>\n\n<p>So trying to look at PI from an AOP perspective can muddy the waters a bit.</p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73487', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/6542/'] |
73,491 | <p>I'm trying to use maven2 to build an axis2 project. My project is configured as a parent project with AAR, WAR, and EAR modules. When I run the parent project's package goal, the console shows a successful build and all of the files are created. However the AAR file generated by AAR project is not included in the generated WAR project. The AAR project is listed as a dependency of WAR project. When I explicitly run the WAR's package goal, the AAR file is then included in the WAR file.</p>
<p>Why would the parent's package goal not include the necessary dependency while running the child's package goal does?</p>
<p>I'm using the maven-war-plugin v2.1-alpha-2 in my war project.</p>
<p>Parent POM:</p>
<pre><code><parent>
<groupId>companyId</groupId>
<artifactId>build</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.nationwide.nf</groupId>
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<version>1.0.0-SNAPSHOT</version>
<modules>
<module>ws-war</module>
<module>ws-aar</module>
<module>ws-ear</module>
</modules>
</code></pre>
<p>AAR POM:</p>
<pre><code><parent>
<artifactId>parent</artifactId>
<groupId>companyId</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>companyId</groupId>
<artifactId>ws-aar</artifactId>
<version>1.0.0-SNAPSHOT</version>
<description/>
<packaging>aar</packaging>
<dependencies>...</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-wsdl2code-maven-plugin</artifactId>
<version>1.4</version>
<configuration>...</configuration>
<executions>
<execution>
<goals>
<goal>wsdl2code</goal>
</goals>
<id>axis2-gen-sources</id>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-aar-maven-plugin</artifactId>
<version>1.4</version>
<extensions>true</extensions>
<configuration>...</configuration>
</plugin>
</plugins>
</build>
</code></pre>
<p>WAR POM:</p>
<pre><code><parent>
<artifactId>parent</artifactId>
<groupId>companyId</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>companyId</groupId>
<artifactId>ws-war</artifactId>
<packaging>war</packaging>
<version>1.0.0-SNAPSHOT</version>
<description/>
<dependencies>
<dependency>
<groupId>companyId</groupId>
<artifactId>ws-aar</artifactId>
<type>aar</type>
<version>1.0.0-SNAPSHOT</version>
</dependency>
.
.
.
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1-alpha-2</version>
<configuration>
<warName>appName</warName>
</configuration>
</plugin>
</plugins>
</build>
</code></pre>
<p>Thanks,
Joe</p>
| [{'answer_id': 89868, 'author': 'user11087', 'author_id': 11087, 'author_profile': 'https://Stackoverflow.com/users/11087', 'pm_score': 0, 'selected': False, 'text': '<p>Have you tried using the "type" element in your dependencies? For example:</p>\n\n<pre><code><dependency>\n <groupId>group-a</groupId>\n <artifactId>artifact-b</artifactId>\n <version>1.0</version>\n <type>aar</type>\n</dependency>\n</code></pre>\n\n<p>Its hard to say for sure what your problem is without seeing your actual pom files.</p>\n\n<p>Update:</p>\n\n<p>What happens if, from the parent project, you run:</p>\n\n<pre><code> mvn clean install\n</code></pre>\n\n<ol>\n<li>Does "install" have any different behavior than "package" as far as your problem is concerned?</li>\n<li>Do you see the .aar file in your local maven repository (~/.m2/repository/com/mycompany/.../)?</li>\n</ol>\n\n<p>As a side note, i\'ve never been very happy with the maven war plugin. I\'ve always ended up using the maven assembly plugin. It just seems to work better and is more consistent. Also, make sure you are using the latest version of maven (2.0.9). I spent half a day fighting a similar problem which was fixed in the latest version.</p>\n'}, {'answer_id': 120938, 'author': 'Joe', 'author_id': 5313, 'author_profile': 'https://Stackoverflow.com/users/5313', 'pm_score': 3, 'selected': True, 'text': '<p>I was able to get my maven build working correctly by adding the following plugin to the ws-war pom file:</p>\n\n<pre><code> <plugin>\n <groupId>org.apache.maven.plugins</groupId>\n <artifactId>maven-dependency-plugin</artifactId>\n <executions>\n <execution>\n <phase>process-classes</phase>\n <goals>\n <goal>copy-dependencies</goal>\n </goals>\n <configuration>\n <outputDirectory>\n ${project.build.directory}/${project.build.finalName}/WEB-INF/services\n </outputDirectory>\n <includeArtifactIds>\n ws-aar\n </includeArtifactIds>\n </configuration>\n </execution>\n </executions>\n </plugin>\n</code></pre>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73491', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5313/'] |
73,498 | <p>When I'm initializing a dialog, I'd like to select one of the radio buttons on the form. I don't see a way to associate a Control variable using the Class Wizard, like you would typically do with CButtons, CComboBoxes, etc...</p>
<p>Further, it doesn't like a CRadioButton class even exists.</p>
<p>How can I select one of the several radio buttons?</p>
| [{'answer_id': 73531, 'author': 'moswald', 'author_id': 8368, 'author_profile': 'https://Stackoverflow.com/users/8368', 'pm_score': 4, 'selected': True, 'text': '<p>Radio buttons and check buttons are just buttons. Use a <code>CButton</code> control and use <code>GetCheck</code>/<code>SetCheck</code>.</p>\n'}, {'answer_id': 73559, 'author': 'Chris Karcher', 'author_id': 2773, 'author_profile': 'https://Stackoverflow.com/users/2773', 'pm_score': 3, 'selected': False, 'text': '<p>Going on what mos said, the following worked did the trick:</p>\n\n<pre><code>CButton* pButton = (CButton*)GetDlgItem(IDC_RADIOBUTTON);\npButton->SetCheck(true);\n</code></pre>\n'}, {'answer_id': 73588, 'author': 'ChrisN', 'author_id': 3853, 'author_profile': 'https://Stackoverflow.com/users/3853', 'pm_score': 4, 'selected': False, 'text': '<p>Use <a href="https://learn.microsoft.com/en-us/cpp/mfc/reference/cwnd-class?view=msvc-160#checkradiobutton" rel="nofollow noreferrer">CWnd::CheckRadioButton</a> to set select one button in a group and <a href="https://learn.microsoft.com/en-us/cpp/mfc/reference/cwnd-class?view=msvc-160#getcheckedradiobutton" rel="nofollow noreferrer">CWnd::GetCheckedRadioButton</a> to retrieve the ID of the selected button. Be sure to call these methods on your dialog object, and not any of the radio button objects.</p>\n'}, {'answer_id': 9307754, 'author': 'Gargo', 'author_id': 1213334, 'author_profile': 'https://Stackoverflow.com/users/1213334', 'pm_score': 1, 'selected': False, 'text': '<pre><code>void CMyDlg::DoDataExchange(CDataExchange* pDX)\n{\n ...\n DDX_Radio(pDX, IDC_RADIO1, m_Radio);\n ...\n}\n</code></pre>\n\n<p>but it is the same thing Wizard generates</p>\n'}, {'answer_id': 46086524, 'author': 'sailfish009', 'author_id': 7404323, 'author_profile': 'https://Stackoverflow.com/users/7404323', 'pm_score': 1, 'selected': False, 'text': '<p>You can use this one-liner:</p>\n\n<pre><code>::SendMessage(GetDlgItem(IDC_RADIO1)->m_hWnd, BM_SETCHECK, BST_CHECKED, NULL);\n</code></pre>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73498', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2773/'] |
73,499 | <p>I have a SharePoint virtual machine in one active directory domain (for example domain1) and I want to transfer all the sites it has to another active directory domain (domain2).
I don’t know which could be the best procedure to do this, if I detach and attach my virtual machine from domain1 to domain2 it probably didn’t work since all the accounts used by SharePoint are no longer valid. (Both domain are not in the same network and didn’t trust each other).
Additionally I could export the sites in domain1 and import them on domain2 using stsadm, but if I use this technique I have to manually install all the features, solutions and personalization I made on my original server.
Does anybody know the best approach to “move” the sites from one domain to another? </p>
| [{'answer_id': 73562, 'author': 'MrHinsh - Martin Hinshelwood', 'author_id': 11799, 'author_profile': 'https://Stackoverflow.com/users/11799', 'pm_score': 0, 'selected': False, 'text': "<p>You may have some sucess by adding a local account to the administrators group and joining the server to the new domain. Then manualy updateing all of the AD accounts that are used in the server. I sould note that all of your users will then have new accounts that are not related to the old ones.</p>\n\n<p>You sould ask your domain admins about an SID update to the new accounts so they also have the SID's from the old domain.</p>\n"}, {'answer_id': 80952, 'author': 'user4531', 'author_id': 4531, 'author_profile': 'https://Stackoverflow.com/users/4531', 'pm_score': 1, 'selected': False, 'text': '<p>There is a <a href="http://stsadm.blogspot.com/2007/09/move-web.html" rel="nofollow noreferrer">STSADM Custom Extension: move web</a> that should be what you are looking for:</p>\n\n<blockquote>\n <p>C:>stsadm -help gl-moveweb</p>\n \n <p>stsadm -o gl-moveweb</p>\n \n <p>Moves a web.</p>\n \n <p>Parameters:\n -url \n -parenturl \n [-haltonwarning (only considered if moving to a new site collection)]\n [-haltonfatalerror (only considered if moving to a new site collection)]\n [-includeusersecurity (only considered if moving to a new site collection)]\n [-retainobjectidentity (only considered if moving to a new site collection)]</p>\n</blockquote>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73499', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/'] |
73,515 | <p>I am getting some errors thrown in my code when I open a Windows Forms form in Visual Studio's designer. I would like to branch in my code and perform a different initialization if the form is being opened by designer than if it is being run for real. </p>
<p>How can I determine at run-time if the code is being executed as part of designer opening the form?</p>
| [{'answer_id': 73533, 'author': 'Bob King', 'author_id': 6897, 'author_profile': 'https://Stackoverflow.com/users/6897', 'pm_score': 2, 'selected': False, 'text': '<pre><code>System.Diagnostics.Debugger.IsAttached\n</code></pre>\n'}, {'answer_id': 73541, 'author': 'Adrian Anttila', 'author_id': 5988, 'author_profile': 'https://Stackoverflow.com/users/5988', 'pm_score': 1, 'selected': False, 'text': "<p>I'm not sure if running in debug mode counts as real, but an easy way is to include an <code>if</code> statement in your code that checkes for <code>System.Diagnostics.Debugger.IsAttached</code>.</p>\n"}, {'answer_id': 73553, 'author': 'Joel Coehoorn', 'author_id': 3043, 'author_profile': 'https://Stackoverflow.com/users/3043', 'pm_score': 2, 'selected': False, 'text': '<p>It\'s hack-ish, but if you\'re using <a href="http://en.wikipedia.org/wiki/Visual_Basic_.NET" rel="nofollow noreferrer">VB.NET</a> and when you\'re running from within Visual Studio <em>My.Application.Deployment.CurrentDeployment</em> will be Nothing, because you haven\'t deployed it yet. I\'m not sure how to check the equivalent value in C#.</p>\n'}, {'answer_id': 73568, 'author': 'Ryan Steckler', 'author_id': 12673, 'author_profile': 'https://Stackoverflow.com/users/12673', 'pm_score': 1, 'selected': False, 'text': "<p>You check the <code>DesignMode</code> property of your control:</p>\n\n<pre><code>if (!DesignMode)\n{\n//Do production runtime stuff\n}\n</code></pre>\n\n<p>Note that this won't work in your constructor because the components haven't been initialized yet.</p>\n"}, {'answer_id': 73582, 'author': 'Akselsson', 'author_id': 8862, 'author_profile': 'https://Stackoverflow.com/users/8862', 'pm_score': 0, 'selected': False, 'text': '<p>If you are in a form or control you can use the DesignMode property: </p>\n\n<pre><code>if (DesignMode)\n{\n DesignMode Only stuff\n}\n</code></pre>\n'}, {'answer_id': 73583, 'author': 'Roger Lipscombe', 'author_id': 8446, 'author_profile': 'https://Stackoverflow.com/users/8446', 'pm_score': 7, 'selected': True, 'text': '<p>To find out if you\'re in "design mode":</p>\n\n<ul>\n<li>Windows Forms components (and controls) have a <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.component.designmode.aspx" rel="noreferrer">DesignMode</a> property.</li>\n<li>Windows Presentation Foundation controls should use the <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.designerproperties.isindesignmode.aspx" rel="noreferrer">IsInDesignMode</a> attached property.</li>\n</ul>\n'}, {'answer_id': 73619, 'author': 'ShuggyCoUk', 'author_id': 12748, 'author_profile': 'https://Stackoverflow.com/users/12748', 'pm_score': 0, 'selected': False, 'text': '<pre><code>System.ComponentModel.Component.DesignMode == true\n</code></pre>\n'}, {'answer_id': 73659, 'author': 'JohnV', 'author_id': 4589, 'author_profile': 'https://Stackoverflow.com/users/4589', 'pm_score': 4, 'selected': False, 'text': '<p>The Control.DesignMode property is probably what you\'re looking for. It tells you if the control\'s parent is open in the designer. </p>\n\n<p>In most cases it works great, but there are instances where it doesn\'t work as expected. First, it doesn\'t work in the controls constructor. Second, DesignMode is false for "grandchild" controls. For example, DesignMode on controls hosted in a UserControl will return false when the UserControl is hosted in a parent.</p>\n\n<p>There is a pretty easy workaround. It goes something like this:</p>\n\n<pre><code>public bool HostedDesignMode\n{\n get \n {\n Control parent = Parent;\n while (parent!=null)\n {\n if(parent.DesignMode) return true;\n parent = parent.Parent;\n }\n return DesignMode;\n }\n}\n</code></pre>\n\n<p>I haven\'t tested that code, but it <em>should</em> work.</p>\n'}, {'answer_id': 353089, 'author': 'GWLlosa', 'author_id': 18071, 'author_profile': 'https://Stackoverflow.com/users/18071', 'pm_score': 4, 'selected': False, 'text': '<p>The most reliable approach is:</p>\n\n<pre><code>public bool isInDesignMode\n{\n get\n {\n System.Diagnostics.Process process = System.Diagnostics.Process.GetCurrentProcess();\n bool res = process.ProcessName == "devenv";\n process.Dispose();\n return res;\n }\n}\n</code></pre>\n'}, {'answer_id': 353111, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>We use the following code in UserControls and it does the work. Using only DesignMode will not work in your app that uses your custom user controls as pointed out by other members.</p>\n\n<pre><code> public bool IsDesignerHosted\n {\n get { return IsControlDesignerHosted(this); }\n }\n\n public bool IsControlDesignerHosted(System.Windows.Forms.Control ctrl)\n {\n if (ctrl != null)\n {\n if (ctrl.Site != null)\n {\n if (ctrl.Site.DesignMode == true)\n return true;\n else\n {\n if (IsControlDesignerHosted(ctrl.Parent))\n return true;\n else\n return false;\n }\n }\n else\n {\n if (IsControlDesignerHosted(ctrl.Parent))\n return true;\n else\n return false;\n }\n }\n else\n return false;\n }\n</code></pre>\n\n<p>Basically the logic above boils down to:</p>\n\n<pre><code> public bool IsControlDesignerHosted(System.Windows.Forms.Control ctrl)\n {\n if (ctrl == null) return false;\n if (ctrl.Site != null && ctrl.Site.DesignMode) return true;\n return IsControlDesignerHosted(ctrl.Parent);\n }\n</code></pre>\n'}, {'answer_id': 353162, 'author': 'Eyvind', 'author_id': 25746, 'author_profile': 'https://Stackoverflow.com/users/25746', 'pm_score': 0, 'selected': False, 'text': '<p>I found the DesignMode property to be buggy, at least in previous versions of Visual Studio. Hence, I made my own using the following logic:</p>\n\n<pre><code>Process.GetCurrentProcess().ProcessName.ToLower().Trim() == "devenv";\n</code></pre>\n\n<p>Kind of a hack, I know, but it works well.</p>\n'}, {'answer_id': 7801743, 'author': 'Marty', 'author_id': 184630, 'author_profile': 'https://Stackoverflow.com/users/184630', 'pm_score': 4, 'selected': False, 'text': '<p>The most reliable way to do this is to ignore the DesignMode property and use your own flag that gets set on application startup.</p>\n\n<p>Class:</p>\n\n<pre><code>public static class Foo\n{\n public static bool IsApplicationRunning { get; set; }\n}\n</code></pre>\n\n<p>Program.cs:</p>\n\n<pre><code>[STAThread]\nstatic void Main()\n{\n Foo.IsApplicationRunning = true;\n // ... code goes here ...\n}\n</code></pre>\n\n<p>Then just check the flag whever you need it.</p>\n\n<pre><code>if(Foo.IsApplicationRunning)\n{\n // Do runtime stuff\n}\nelse\n{\n // Do design time stuff\n}\n</code></pre>\n'}, {'answer_id': 10725662, 'author': 'NET3', 'author_id': 1289709, 'author_profile': 'https://Stackoverflow.com/users/1289709', 'pm_score': 6, 'selected': False, 'text': '<pre class="lang-cs prettyprint-override"><code>if (System.ComponentModel.LicenseManager.UsageMode == System.ComponentModel.LicenseUsageMode.Designtime)\n{\n // Design time logic\n}\n</code></pre>\n'}, {'answer_id': 11177035, 'author': 'Andy', 'author_id': 1477990, 'author_profile': 'https://Stackoverflow.com/users/1477990', 'pm_score': 1, 'selected': False, 'text': '<p>When running a project, its name is appended with ".vshost".</p>\n\n<p>So, I use this:</p>\n\n<pre><code> public bool IsInDesignMode\n {\n get\n {\n Process p = Process.GetCurrentProcess();\n bool result = false;\n\n if (p.ProcessName.ToLower().Trim().IndexOf("vshost") != -1)\n result = true;\n p.Dispose();\n\n return result;\n }\n }\n</code></pre>\n\n<p>It works for me.</p>\n'}, {'answer_id': 11477586, 'author': 'Bolek', 'author_id': 1524524, 'author_profile': 'https://Stackoverflow.com/users/1524524', 'pm_score': 1, 'selected': False, 'text': '<p>If you created a property that you don\'t need at all at design time, you can use the <strong>DesignerSerializationVisibility</strong> attribute and set it to Hidden. For example:</p>\n\n<pre><code>protected virtual DataGridView GetGrid()\n{\n throw new NotImplementedException("frmBase.GetGrid()");\n}\n\n[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]\npublic int ColumnCount { get { return GetGrid().Columns.Count; } set { /*Some code*/ } }\n</code></pre>\n\n<p>It stopped my Visual Studio crashing every time I made a change to the form with <code>NotImplementedException()</code> and tried to save. Instead, Visual Studio knows that I don\'t want to serialize this property, so it can skip it. It only displays some weird string in the properties box of the form, but it seems to be safe to ignore.</p>\n\n<p>Please note that this change does not take effect until you rebuild.</p>\n'}, {'answer_id': 12618972, 'author': 'Johny Skovdal', 'author_id': 222134, 'author_profile': 'https://Stackoverflow.com/users/222134', 'pm_score': 3, 'selected': False, 'text': '<p>The devenv approach stopped working in VS2012 as the designer now has its own process. Here is the solution I am currently using <em>(the \'devenv\' part is left there for legacy, but without VS2010 I am not able to test that though)</em>.</p>\n\n<pre><code>private static readonly string[] _designerProcessNames = new[] { "xdesproc", "devenv" };\n\nprivate static bool? _runningFromVisualStudioDesigner = null;\npublic static bool RunningFromVisualStudioDesigner\n{\n get\n {\n if (!_runningFromVisualStudioDesigner.HasValue)\n {\n using (System.Diagnostics.Process currentProcess = System.Diagnostics.Process.GetCurrentProcess())\n {\n _runningFromVisualStudioDesigner = _designerProcessNames.Contains(currentProcess.ProcessName.ToLower().Trim());\n }\n }\n\n return _runningFromVisualStudioDesigner.Value;\n }\n}\n</code></pre>\n'}, {'answer_id': 13894231, 'author': 'Martin', 'author_id': 419427, 'author_profile': 'https://Stackoverflow.com/users/419427', 'pm_score': 2, 'selected': False, 'text': '<pre><code>using (System.Diagnostics.Process process = System.Diagnostics.Process.GetCurrentProcess())\n{\n bool inDesigner = process.ProcessName.ToLower().Trim() == "devenv";\n return inDesigner;\n}\n</code></pre>\n\n<p>I tried the above code (added a using statement) and this would fail on some occasions for me. Testing in the constructor of a usercontrol placed directly in a form with the designer loading at startup. But would work in other places.</p>\n\n<p>What worked for me, in all locations is:</p>\n\n<pre><code>private bool isDesignMode()\n{\n bool bProcCheck = false;\n using (System.Diagnostics.Process process = System.Diagnostics.Process.GetCurrentProcess())\n {\n bProcCheck = process.ProcessName.ToLower().Trim() == "devenv";\n }\n\n bool bModeCheck = (System.ComponentModel.LicenseManager.UsageMode == System.ComponentModel.LicenseUsageMode.Designtime);\n\n return bProcCheck || DesignMode || bModeCheck;\n}\n</code></pre>\n\n<p>Maybe a bit overkill, but it works, so is good enough for me.</p>\n\n<p>The success in the example noted above is the bModeCheck, so probably the DesignMode is surplus.</p>\n'}, {'answer_id': 15224011, 'author': 'Ali Reza Kalantar', 'author_id': 2132827, 'author_profile': 'https://Stackoverflow.com/users/2132827', 'pm_score': 0, 'selected': False, 'text': '<p>To solve the problem, you can also code as below:</p>\n\n<pre><code>private bool IsUnderDevelopment\n{\n get\n {\n System.Diagnostics.Process process = System.Diagnostics.Process.GetCurrentProcess();\n if (process.ProcessName.EndsWith(".vshost")) return true;\n else return false;\n }\n\n}\n</code></pre>\n'}, {'answer_id': 15700675, 'author': 'Lozza', 'author_id': 2223846, 'author_profile': 'https://Stackoverflow.com/users/2223846', 'pm_score': -1, 'selected': False, 'text': '<pre><code> /// <summary>\n /// Whether or not we are being run from the Visual Studio IDE\n /// </summary>\n public bool InIDE\n {\n get\n {\n return Process.GetCurrentProcess().ProcessName.ToLower().Trim().EndsWith("vshost");\n }\n }\n</code></pre>\n'}, {'answer_id': 22781355, 'author': 'pintergabor', 'author_id': 3484286, 'author_profile': 'https://Stackoverflow.com/users/3484286', 'pm_score': 2, 'selected': False, 'text': '<pre><code>/// <summary>\n/// Are we in design mode?\n/// </summary>\n/// <returns>True if in design mode</returns>\nprivate bool IsDesignMode() {\n // Ugly hack, but it works in every version\n return 0 == String.CompareOrdinal(\n "devenv.exe", 0,\n Application.ExecutablePath, Application.ExecutablePath.Length - 10, 10);\n}\n</code></pre>\n'}, {'answer_id': 28432133, 'author': 'GeeC', 'author_id': 1287392, 'author_profile': 'https://Stackoverflow.com/users/1287392', 'pm_score': 3, 'selected': False, 'text': '<p>I had the same problem in Visual Studio Express 2013. I tried many of the solutions suggested here but the one that worked for me was <a href="https://stackoverflow.com/a/21054933/1287392">an answer to a different thread</a>, which I will repeat here in case the link is ever broken:</p>\n\n<pre><code>protected static bool IsInDesigner\n{\n get { return (Assembly.GetEntryAssembly() == null); }\n}\n</code></pre>\n'}, {'answer_id': 29023756, 'author': 'JWP', 'author_id': 1522548, 'author_profile': 'https://Stackoverflow.com/users/1522548', 'pm_score': 0, 'selected': False, 'text': "<p>Here's another one:</p>\n\n<pre><code> //Caters only to thing done while only in design mode\n if (App.Current.MainWindow == null){ // in design mode }\n\n //Avoids design mode problems\n if (App.Current.MainWindow != null) { //applicaiton is running }\n</code></pre>\n"}, {'answer_id': 30196577, 'author': 'Gary', 'author_id': 4892369, 'author_profile': 'https://Stackoverflow.com/users/4892369', 'pm_score': -1, 'selected': False, 'text': '<p>Here\'s a flexible way that is adaptable to where you compile from as well as whether or not you care which mode you\'re in.</p>\n\n<pre><code>string testString1 = "\\\\bin\\\\";\n//string testString = "\\\\bin\\\\Debug\\\\";\n//string testString = "\\\\bin\\\\Release\\\\";\n\nif (AppDomain.CurrentDomain.BaseDirectory.Contains(testString))\n{\n //Your code here\n}\n</code></pre>\n'}, {'answer_id': 36042135, 'author': 'Gpower2', 'author_id': 3235669, 'author_profile': 'https://Stackoverflow.com/users/3235669', 'pm_score': 0, 'selected': False, 'text': '<p>After testing most of the answers here, unfortunately nothing worked for me (VS2015). \nSo I added a little twist to <a href="https://stackoverflow.com/a/73659/3235669">JohnV\'s answer</a>, which didn\'t work out of the box, since DesignMode is a protected Property in the Control class.</p>\n\n<p>First I made an extension method which returns the DesignMode\'s Property value via Reflection:</p>\n\n<pre><code>public static Boolean GetDesignMode(this Control control)\n{\n BindingFlags bindFlags = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Static;\n PropertyInfo prop = control.GetType().GetProperty("DesignMode", bindFlags);\n return (Boolean)prop.GetValue(control, null);\n}\n</code></pre>\n\n<p>and then I made a function like JohnV:</p>\n\n<pre><code>public bool HostedDesignMode\n{\n get\n {\n Control parent = Parent;\n while (parent != null)\n {\n if (parent.GetDesignMode()) return true;\n parent = parent.Parent;\n }\n return DesignMode;\n }\n}\n</code></pre>\n\n<p>This is the only method that worked for me, avoiding all the ProcessName mess, and while reflection should not be used lightly, in this case it did all the difference! ;)</p>\n\n<p><strong>EDIT:</strong></p>\n\n<p>You can also make the second function an extension method like this:</p>\n\n<pre><code>public static Boolean IsInDesignMode(this Control control)\n{\n Control parent = control.Parent;\n while (parent != null)\n {\n if (parent.GetDesignMode())\n {\n return true;\n }\n parent = parent.Parent;\n }\n return control.GetDesignMode();\n}\n</code></pre>\n'}, {'answer_id': 72997523, 'author': 'NielW', 'author_id': 570206, 'author_profile': 'https://Stackoverflow.com/users/570206', 'pm_score': 0, 'selected': False, 'text': "<p>For WPF (hopefully this is useful for those WPF people stumbling upon this question):</p>\n<pre><code>if (System.ComponentModel.DesignerProperties.GetIsInDesignMode(new DependencyObject()))\n{\n}\n</code></pre>\n<p><code>GetIsInDesignMode</code> requires a DependencyObject. If you don't have one, just create one.</p>\n"}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73515', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12717/'] |
73,517 | <p>In a silverlight application, I want to access the page the silverlight .xap file from an HTTP subdomain, but have the web services access a different subdomain for sensitive information over HTTPS.</p>
<p>I set up clientaccesspolicy.xml at the root of the subdomain and it lets the silverlight app access its services over http, but not over https. It gives the cross domain access error that it would give normally without a clientaccesspolicy in place.</p>
<p>I know that browsers themselves have a lot of restrictions about mixing http and https. Am I trying to do something that is not allowed? </p>
| [{'answer_id': 73598, 'author': 'MrHinsh - Martin Hinshelwood', 'author_id': 11799, 'author_profile': 'https://Stackoverflow.com/users/11799', 'pm_score': 2, 'selected': False, 'text': '<p>Check out:<a href="http://silverlight.net/forums/t/12741.aspx" rel="nofollow noreferrer">http://silverlight.net/forums/t/12741.aspx</a></p>\n\n<blockquote>\n <p>You can either make https calls to the\n same domain or http cross-domain\n calls, but not https cross-domain\n calls.</p>\n \n <p>This is described in\n <a href="http://msdn2.microsoft.com/en-us/library/cc189008(VS.95).aspx" rel="nofollow noreferrer">http://msdn2.microsoft.com/en-us/library/cc189008(VS.95).aspx</a></p>\n \n <p>(see "If not HTTPS" in the matrix)\n By JohnSpurlock</p>\n</blockquote>\n'}, {'answer_id': 403616, 'author': 'Pete', 'author_id': 3059, 'author_profile': 'https://Stackoverflow.com/users/3059', 'pm_score': 2, 'selected': False, 'text': '<p>This is out of date since Silverlight 2.0 was released. You can now do most cross-domain scenarios with the appropriate configuration. <a href="http://msdn.microsoft.com/en-us/library/cc197955(VS.95).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/cc197955(VS.95).aspx</a></p>\n'}, {'answer_id': 1638953, 'author': 'degnome', 'author_id': 18218, 'author_profile': 'https://Stackoverflow.com/users/18218', 'pm_score': 0, 'selected': False, 'text': '<p>The important thing to note here that is not in the above information clearly is you must have access to the "ROOT" level of the domain request, and the clientaccesspolicy.xml must reside at that level.</p>\n\n<p>If for example you have a production environment that your application is behind a load balancer that directs traffic as most large companies do to your application via the URI, you then have a little bit of a problem.</p>\n\n<p>Example: <a href="http://mydomain.com/MyApplication/" rel="nofollow noreferrer">http://mydomain.com/MyApplication/</a>* goes to your server, where your app resides.\n <a href="http://mydomain.com/clientaccesspolicy.xml" rel="nofollow noreferrer">http://mydomain.com/clientaccesspolicy.xml</a> is where the policy exists.</p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73517', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3059/'] |
73,518 | <p>In Windows XP:</p>
<p>How do you direct traffic to/from a particular site to a specific NIC?</p>
<p>For Instance: How do I say, all connections to stackoverflow.com should use my wireless connection, while all other sites will use my ethernet?</p>
| [{'answer_id': 73545, 'author': 'Danimal', 'author_id': 2757, 'author_profile': 'https://Stackoverflow.com/users/2757', 'pm_score': 1, 'selected': False, 'text': '<p>you should be able to do it using the route command. Route add (ip address) (netmask) (gateway) metric 1</p>\n'}, {'answer_id': 73613, 'author': 'Jonathan Rupp', 'author_id': 12502, 'author_profile': 'https://Stackoverflow.com/users/12502', 'pm_score': 3, 'selected': True, 'text': "<p>I'm not sure if there's an easier way, but one way would be to add a route to the IP(s) of stackoverflow.com that explicitly specifies your wireless connection, using a lower metric (cost) than your default route.</p>\n\n<p>Running nslookup www.stackoverflow.com shows only one IP: 67.199.15.132, so the syntax would be:</p>\n\n<pre>route -p add 67.199.15.132 [your wireless gateway] metric [lower metric than default route] IF [wireless interface]</pre>\n\n<p>See the route command for more info.</p>\n"}, {'answer_id': 73621, 'author': 'Steve Moon', 'author_id': 3660, 'author_profile': 'https://Stackoverflow.com/users/3660', 'pm_score': 1, 'selected': False, 'text': "<p>Modify your routing table so that specific hosts go through the desired interface. </p>\n\n<p>You need to have a 'default' route, which would either be your ethernet or wireless. But to direct traffic through the other interface, use the command line 'route' command to add a route to the specific IP address you're wanting to redirect.</p>\n\n<p>For example, stackoverflow.com has the IP address 67.199.15.132 (you can find this by using nslookup or pinging it). Issue a route add 67.199.15.132 mask 255.255.255.255 a.b.c.d IF e\nwhere a.b.c.d == the IP address of the router on the other end of your wireless interface, and e is the interface number (a 'route print' command will list each interface and it's interface number).</p>\n\n<p>If you add the '-p' flag to the route command the route will be persistent between reboots.</p>\n"}, {'answer_id': 73670, 'author': 'Jay', 'author_id': 12479, 'author_profile': 'https://Stackoverflow.com/users/12479', 'pm_score': 1, 'selected': False, 'text': "<p>Within XP, I have often found that by adding/modifying static routes, I can typically\naccomplish what I need in such cases. </p>\n\n<p>Of course, there are other 'high level' COTS tools/firewalls that might provide you a better interface.</p>\n\n<p>One caveat with modifying routes - VPN tunnels are not too happy about chnages in static routes once the VPN is set up so be sure to set it up at Windows boot up after the NICs are initialized through some scripting.</p>\n\n<p>Static routes- these will work fine, unless you are using a VPN tunnel.</p>\n\n<p>Windows 'route' help</p>\n\n<p>Manipulates network routing tables.</p>\n\n<p>ROUTE [-f] [-p] [command [destination]\n [MASK netmask] [gateway] [METRIC metric] [IF interface]</p>\n\n<p>-f Clears the routing tables of all gateway entries. If this is\n used in conjunction with one of the commands, the tables are\n cleared prior to running the command.\n -p When used with the ADD command, makes a route persistent across\n boots of the system. By default, routes are not preserved\n when the system is restarted. Ignored for all other commands,\n which always affect the appropriate persistent routes. This\n option is not supported in Windows 95.\n command One of these:\n PRINT Prints a route\n ADD Adds a route\n DELETE Deletes a route\n CHANGE Modifies an existing route</p>\n"}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73518', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2744/'] |
73,519 | <p>Linux/Gcc/LD - Toolchain.</p>
<p>I would like to remove STL/Boost debug symbols from libraries and executable, for two reasons:</p>
<ol>
<li>Linking gets very slow for big programs</li>
<li>Debugging jumps into stl/boost code, which is annoying</li>
</ol>
<p>For 1. incremental linking would be a big improvement, but AFAIK ld does not support incremental linking. There is a workaround "pseudo incremental linking" in an 1999 dr.dobb's journal (not in the web any more, but at <a href="http://web.archive.org/web/20000131063231/www.ddj.com/articles/1999/9910/9910d/9910d.htm" rel="nofollow noreferrer">archive.org</a> (the idea is to put everything in a dynamic library and all updated object files in an second one that is loaded first) but this is not really a general solution.</p>
<p>For 2. there is a script <a href="http://ubuntuforums.org/showthread.php?p=4368377" rel="nofollow noreferrer">here</a>, but a) it did not work for me (it did not remove symbols), b) it is very slow as it works at the end of the pipe, while it would be more efficient to remove the symbols earlier.</p>
<p>Obviously, the other debug symbols should stay in place.</p>
| [{'answer_id': 73570, 'author': 'hatcat', 'author_id': 11483, 'author_profile': 'https://Stackoverflow.com/users/11483', 'pm_score': -1, 'selected': False, 'text': '<p>Which compiler are you using? For example, if I understand your question correctly, this is a trivial matter in MS Visual Studio.</p>\n'}, {'answer_id': 74075, 'author': 'Kris Kumler', 'author_id': 4281, 'author_profile': 'https://Stackoverflow.com/users/4281', 'pm_score': 1, 'selected': False, 'text': '<p>You probably don\'t want to strip the debug symbols from the shared libraries, as you may need that at some point.</p>\n\n<p>If you are using GDB or DDD to debug, you may be able to get away with removing the Boost source files from the Source Path so it can\'t trace into the functions. (Or just don\'t trace into them, trace over!)</p>\n\n<p>You can remove the option to compile the program with debug symbols, which will speed the link time.</p>\n\n<p>Like the script you link to, you can consult the strip program ("man strip") to remove all or certain symbols.</p>\n'}, {'answer_id': 74103, 'author': 'Leon Timmermans', 'author_id': 4727, 'author_profile': 'https://Stackoverflow.com/users/4727', 'pm_score': 1, 'selected': False, 'text': "<p>You may want to use strip.\nstrip --strip-unneeded --strip-debug libfoo.so</p>\n\n<p>Why don't you just build without debugging in the first place though?</p>\n"}, {'answer_id': 75676, 'author': 'Pieter', 'author_id': 5822, 'author_profile': 'https://Stackoverflow.com/users/5822', 'pm_score': 2, 'selected': False, 'text': "<p>As far as I know there's no real option to do what you want in gcc. The main problem being that all the code you want to strip debug symbols for is defined in headers.</p>\n\n<p>Otherwhise it would be possible to build a library separatly, strip that, and link with the stripped version.</p>\n\n<p>But only getting debug symbols from certain parts of a compilation unit, while building and linking (for your desired link time speedup) is not possible in gcc as far as I know.</p>\n"}, {'answer_id': 81654, 'author': 'MSalters', 'author_id': 15416, 'author_profile': 'https://Stackoverflow.com/users/15416', 'pm_score': 2, 'selected': False, 'text': "<p>GNU strip accepts regex arguments to --strip-symbols=\nThe STL and boost symbols are name-mangled because of the namespaces they're in. I don't have GCC binutils handy at this moment, but just peek at the name mangling used for namespaces and construct the regex for 'symbols from namespace X' and pass this to --strip-symbols=</p>\n"}, {'answer_id': 42669612, 'author': 'gospes', 'author_id': 2250406, 'author_profile': 'https://Stackoverflow.com/users/2250406', 'pm_score': 1, 'selected': False, 'text': '<p>This answer provides some specifics that I needed to make MSalters\' answer work for removing STL symbols. </p>\n\n<p>The STL symbol names are mangled. The trick is to find a regular expression that covers these names. I looked these symbols up with GNU\'s Binutils:</p>\n\n<pre><code>> nm --debug-syms <objectfile>\n</code></pre>\n\n<p>I basically searched on STL functions, like <code>resize</code>. If this is difficult, the output becomes readable when using the following command:</p>\n\n<pre><code>> nm --debug-syms --demangle <objectfile>\n</code></pre>\n\n<p>Look up a line number containing an STL function call, then look up it\'s mangled name on that same line number using the first provided command. This allowed me to see that all STL symbol names began with <strong>_ZNSt[0-9]+</strong> or <strong>_ZSt[0-9]+</strong>, etc.</p>\n\n<p>To allow GNU Strip to remove these symbols I used:</p>\n\n<pre><code>> strip --wildcard \\\n --strip-symbol=\'_ZNKSt*\' \\\n --strip-symbol=\'_ZNSt*\' \\\n --strip-symbol=\'_ZSt*\' \\\n --strip-symbol=\'_ZNSa*\' \\\n <objectfile>\n</code></pre>\n\n<p>I used these commands directly on the compiled/linked binary. I verified the removal of these symbols by comparing the output of <code>nm</code> before and after the removal (I wrote the output to files and used <code>vimdiff</code>). The <code>--wildcard</code> option allows the use of regular expressions. Although I would expect <strong>[0-9]*</strong> to mean 0 to an infinite amount of numbers, here it actually means 1 number followed by an infinite amount of anything (until the end of the line).</p>\n\n<p>If you are looking to <strong>not step into STL code</strong> this can be achieved by gdb\'s <code>skip file</code> command, as done <a href="https://stackoverflow.com/a/42721326/2250406">here</a>.</p>\n\n<p>Hope it helps</p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73519', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/11344/'] |
73,524 | <p>I have a list of addresses from a Database for which I'd like to put markers on a Yahoo Map. The <a href="http://developer.yahoo.com/maps/ajax/V3.8/index.html#YMap" rel="nofollow noreferrer"><code>addMarker()</code> method</a> on YMap takes a YGeoPoint, which requires a latitude and longitude. However, Yahoo Maps must know how to convert from addresses because <code>drawZoomAndCenter(LocationType,ZoomLevel)</code> can take an address. I could convert by using <code>drawZoomAndCenter()</code> then <code>getCenterLatLon()</code> but is there a better way, which doesn't require a draw?</p>
| [{'answer_id': 73625, 'author': 'Paul Reiners', 'author_id': 7648, 'author_profile': 'https://Stackoverflow.com/users/7648', 'pm_score': -1, 'selected': False, 'text': '<p>If you\'re working with U.S. addresses, you can use <a href="http://geocoder.us/" rel="nofollow noreferrer">geocoder.us</a>, which has <a href="http://geocoder.us/help/" rel="nofollow noreferrer">APIs</a>.</p>\n\n<p>Also, <em>Google Maps Hacks</em> has a hack, <a href="http://safari.oreilly.com/0596101619/googlemapshks-CHP-7-SECT-2" rel="nofollow noreferrer">"Hack 62. Find the Latitude and Longitude of a Street Address"</a>, for that.</p>\n'}, {'answer_id': 81551, 'author': 'David Bick', 'author_id': 4914, 'author_profile': 'https://Stackoverflow.com/users/4914', 'pm_score': 2, 'selected': True, 'text': '<p>You can ask the map object to do the geoCoding, and catch the callback:</p>\n\n<pre><code><script type="text/javascript"> \nvar map = new YMap(document.getElementById(\'map\'));\nmap.drawZoomAndCenter("Algeria", 17);\n\nmap.geoCodeAddress("Cambridge, UK");\n\nYEvent.Capture(map, EventsList.onEndGeoCode, function(geoCode) {\n if (geoCode.success)\n map.addOverlay(new YMarker(geoCode.GeoPoint));\n});\n</script>\n</code></pre>\n\n<p>One thing to beware of -- in this example the <code>drawAndZoom</code> call will itself make a geoCoding request, so you\'ll get the callback from that too. You might want to filter that out, or set the map\'s centre based on a GeoPoint.</p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73524', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5346/'] |
73,527 | <p>There are several plugin options for building a search engine into your Ruby on Rails application. Which of these is the best?</p>
<ul>
<li><a href="http://ts.freelancing-gods.com/" rel="noreferrer">Thinking Sphinx</a></li>
<li><a href="http://blog.evanweaver.com/files/doc/fauna/ultrasphinx/files/README.html" rel="noreferrer">UltraSphinx</a></li>
<li><a href="http://seattlerb.rubyforge.org/Sphincter/" rel="noreferrer">Sphincter</a></li>
<li><a href="http://www.datanoise.com/articles/2007/3/23/acts_as_sphinx-plugin" rel="noreferrer">acts_as_sphinx</a></li>
<li><a href="http://projects.jkraemer.net/acts_as_ferret/" rel="noreferrer">acts_as_ferret</a></li>
<li><a href="http://ferret.davebalmain.com/trac/" rel="noreferrer">Ferret</a></li>
<li><a href="http://locomotivation.com/2008/07/23/simple-ruby-on-rails-full-text-search-using-xapian" rel="noreferrer">acts_as_xapian</a></li>
<li><a href="http://github.com/railsfreaks/acts_as_solr/tree/master" rel="noreferrer">acts_as_solr</a></li>
<li><a href="http://hyperestraier.sourceforge.net/" rel="noreferrer">Hyper Estraier</a></li>
</ul>
| [{'answer_id': 73554, 'author': 'Otto', 'author_id': 9594, 'author_profile': 'https://Stackoverflow.com/users/9594', 'pm_score': 0, 'selected': False, 'text': "<p>I've used Thinking Sphinx and it seems pretty good, but I haven't had the time to evaluate all of the options.</p>\n"}, {'answer_id': 73573, 'author': 'ivan', 'author_id': 7039, 'author_profile': 'https://Stackoverflow.com/users/7039', 'pm_score': 0, 'selected': False, 'text': '<p>I recommend Thinking Sphinx. It is the fastest option in my opinion.</p>\n'}, {'answer_id': 73604, 'author': 'Kevin', 'author_id': 4599, 'author_profile': 'https://Stackoverflow.com/users/4599', 'pm_score': 0, 'selected': False, 'text': "<p>I've used Ferret and it worked well for my purposes, but I have not evaluated the other options.</p>\n"}, {'answer_id': 73618, 'author': 'squadette', 'author_id': 7754, 'author_profile': 'https://Stackoverflow.com/users/7754', 'pm_score': 5, 'selected': True, 'text': '<p>Thinking Sphinx has more concise syntax to define which fields and which models are indexed.</p>\n\n<p>Both UltraSphinx and Thinking Sphinx (recently) have ultra-cool feature which takes into account geographical proximity of objects. </p>\n\n<p>UltraSphinx has annoying problems with how it loads models (it does not load entire Rails stack, so you could get strange and hard to diagnose errors, which are handled by adding explicit <code>require</code> statements).</p>\n\n<p>We use Thinking Sphinx on new projects, and UltraSphinx on projects which use geo content.</p>\n'}, {'answer_id': 73712, 'author': 'webmat', 'author_id': 6349, 'author_profile': 'https://Stackoverflow.com/users/6349', 'pm_score': 2, 'selected': False, 'text': '<p>I have only used the Ferret/acts_as_ferret combo (legacy decision) on a client project. I strongly recommend looking at the <strong>other</strong> options first.</p>\n\n<p>aaf is very fragile and can bring your Rails app to a screeching halt if you make a mistake in the config or if for some reason you hit a bug in aaf. </p>\n\n<p>In such a case, instead of simply having the search functionality crapping out, any controller action touching an indexed model will completely fail and raise an exception. Which is baaad, hmkay?</p>\n'}, {'answer_id': 73735, 'author': 'webmat', 'author_id': 6349, 'author_profile': 'https://Stackoverflow.com/users/6349', 'pm_score': 0, 'selected': False, 'text': '<p>An option I haven\'t tried is the C++ based <a href="http://www.xapian.org/" rel="nofollow noreferrer">Xapian</a></p>\n'}, {'answer_id': 73766, 'author': 'Kevin Colyar', 'author_id': 1766771, 'author_profile': 'https://Stackoverflow.com/users/1766771', 'pm_score': 1, 'selected': False, 'text': '<p>I use the <em>acts_as_xapian</em> plugin. I followed this tutorial: </p>\n\n<p><a href="http://locomotivation.com/2008/07/23/simple-ruby-on-rails-full-text-search-using-xapian" rel="nofollow noreferrer">http://locomotivation.com/2008/07/23/simple-ruby-on-rails-full-text-search-using-xapian</a></p>\n\n<p>Works very well.</p>\n'}, {'answer_id': 73826, 'author': 'webmat', 'author_id': 6349, 'author_profile': 'https://Stackoverflow.com/users/6349', 'pm_score': 3, 'selected': False, 'text': '<p>A solid option used by one of my friends is <a href="http://lucene.apache.org/solr/" rel="noreferrer">Solr</a>, a search engine using the original Java-based Lucene. To use it with Rails, there\'s, of course an acts_as plugin, <a href="http://github.com/railsfreaks/acts_as_solr/tree/master" rel="noreferrer">acts_as_solr</a>.</p>\n\n<p>He presented the combo recently at <a href="http://www.montrealonrails.com/2008/08/20/10-was-a-success/" rel="noreferrer">Montreal on Rails</a> and gives a nice and thorough overview of <a href="http://hugofrappier.wordpress.com/2008/09/01/solr-presentation-at-montreal-on-rails/" rel="noreferrer">how to use acts_as_solr on his blog</a>.</p>\n\n<p>It apparently supports french accents very well, too.</p>\n'}, {'answer_id': 73903, 'author': 'user10864', 'author_id': 10864, 'author_profile': 'https://Stackoverflow.com/users/10864', 'pm_score': 0, 'selected': False, 'text': '<p>We\'re using <a href="http://hyperestraier.sourceforge.net/" rel="nofollow noreferrer">http://hyperestraier.sourceforge.net/</a>, which was inherited. Haven\'t looked into other engines, but hyperestraier provides all the hooks necessary. Setting up the search index is complicated though. Probably easier options available. </p>\n'}, {'answer_id': 79122, 'author': 'Brian Deterling', 'author_id': 14619, 'author_profile': 'https://Stackoverflow.com/users/14619', 'pm_score': 3, 'selected': False, 'text': "<p>I'm going through this exact process right now so while I don't have actual experience, I've spent many hours researching all the options. Here's what I've learned so far:</p>\n\n<ul>\n<li>*Sphinx - good reputation for speed and functionality but Sphinx needs integer keys and my model uses GUID; ThinkingSphinx recently announced support for GeoSpatial </li>\n<li>Acts_As_Solr - recommended by a friend with a high-volume site; original creators have stopped working on it and documentation is hard to find; requires a Java servlet</li>\n<li>Acts_As_Ferret - looks easy to use, but lots of detractors that say its unstable</li>\n<li>Two others with limited information are Acts_As_Indexed and Acts_As_Searchable</li>\n</ul>\n\n<p>I have a spreadsheet with my attempt at documenting the advantages and disadvantages of all of them. If anyone is interested in seeing it and/or helping me correct it, just contact me. I'll post it somewhere once I know its accurate.</p>\n\n<p>My recommendation would be to try UltraSphinx or Thinking Sphinx if you have normal primary keys. I'm going to try Acts_As_Xapian based on the good documentation, feature set, and how active the project seems to be.</p>\n"}, {'answer_id': 86590, 'author': 'Josh Schwartzman', 'author_id': 16447, 'author_profile': 'https://Stackoverflow.com/users/16447', 'pm_score': 1, 'selected': False, 'text': "<p>I'm using acts_as_ferret. It's easy to configure and generally fast. The built-in active record find functionality is quite useful: you can apply any conditions or join other models after your search finds the matching records. </p>\n\n<p>Unlike sphinx, you don't have to re-index ALL of your records when you add new data. There are after_save and after_update hooks that will insert your new record into the ferret db. This was one of the big selling points for me.</p>\n\n<p>When you do have to mass index your data, ferret is definitely slower than acts_as_sphinx (by a factor of 3). I ended up writing my own method to re-index models which works as fast as sphinx -- it basically preloads all the data from the DB instead of going record by record to create the new index.</p>\n\n<p>The ferret documentation is good for the basics, but it's a bit sparse once you get into more complex searches, sorts and using a dRb server to host a remote index. That being said, it feels a much more mature product than acts_as_sphinx, although I have limited experience with sphinx.</p>\n"}, {'answer_id': 121300, 'author': 'MattMcKnight', 'author_id': 8136, 'author_profile': 'https://Stackoverflow.com/users/8136', 'pm_score': 0, 'selected': False, 'text': "<p>It depends on what database you are using. I would recommend using Solr as it offers up a lot of nice options for fuzzy search and has a great query parser. The downside is you have to run a separate process for it. I have used Ferret as well, but found it to be less stable in terms of multi-threaded access to the index. I haven't tried Sphinx because it only works with MySQL and Postgres.</p>\n"}, {'answer_id': 439960, 'author': 'jshen', 'author_id': 46505, 'author_profile': 'https://Stackoverflow.com/users/46505', 'pm_score': 0, 'selected': False, 'text': "<p>I'm using a different option which was worked out amazingly well. I'm using jruby and talking to lucene directly. </p>\n\n<p>I've used acts_as_solr in the past and ran into some issues. mainly it makes a synchronous call for each AR save. This isn't too bad, but in my situation a save sometimes caused many synchronous calls to solr and would occasionally take longer than mongrel would allow and I'd get a mongrel timeout exception (or something like that)</p>\n"}, {'answer_id': 445769, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>Thinking Sphinx is a better alternative than Ultrasphinx, which seems abandoned, but, in general, Xapian has a more powerful engine than Sphinx and is easier for implementing realtime search.</p>\n'}, {'answer_id': 1351955, 'author': 'user116218', 'author_id': 116218, 'author_profile': 'https://Stackoverflow.com/users/116218', 'pm_score': 0, 'selected': False, 'text': '<p>I recommend acts_as_ferret. But though the tough part is to get it up and running successfully in your server, once done you hardly have any problem as ferret server will be running as separate background process to update your index every time there is any new update. Also, its working great in mongrel with apache for us.</p>\n'}, {'answer_id': 3049224, 'author': 'Pascal Lindelauf', 'author_id': 414376, 'author_profile': 'https://Stackoverflow.com/users/414376', 'pm_score': 0, 'selected': False, 'text': '<p>I\'ve been looking for the perfect solution as well. At first I went with Thinking Sphinx, which worked fine. But since I intent to host my webapp on <a href="http://www.heroku.com" rel="nofollow noreferrer">Heroku</a>, the only option is to use <a href="http://lucene.apache.org/solr/" rel="nofollow noreferrer">Solr</a>. The biggest drawback, however, is that development of the main <a href="http://github.com/railsfreaks/acts_as_solr" rel="nofollow noreferrer">acts_as_solr</a> gem seems to have stopped after May 2008. So that\'s too old for my taste. I just found <a href="http://outoftime.github.com/sunspot/" rel="nofollow noreferrer">Sunspot</a> as an advanced alternative and with recent updates, so that\'s one I\'m going to consider.</p>\n\n<p>Another option Heroku offers is to go for a hosted index server based on Solr, named <a href="http://www.websolr.com/" rel="nofollow noreferrer">Websolr</a>. The required gem <a href="http://github.com/onemorecloud/websolr-acts_as_solr" rel="nofollow noreferrer">websolr-acts_as_solr</a> is also luckily very much up-to-date. </p>\n'}, {'answer_id': 3618239, 'author': 'Leo', 'author_id': 436240, 'author_profile': 'https://Stackoverflow.com/users/436240', 'pm_score': 1, 'selected': False, 'text': "<p>If you are using a shared hosting service like me (Bluehost), your options may be limited to what the provider offers. In my case, I couldn't find a good and reliable way to start and keep a separate server running, such as Lucene or Solr.</p>\n\n<p>Therefore, I went with Xapian and it's been working well for me. There are 2 plugins for rails I've researched: acts_as_xapian and xapian_fu.\nThe first will get you going quickly, but it doesn't seem to be maintained anymore. I've just begun working with xapian_fu.</p>\n"}, {'answer_id': 28408790, 'author': 'udit mittal', 'author_id': 2116438, 'author_profile': 'https://Stackoverflow.com/users/2116438', 'pm_score': 1, 'selected': False, 'text': '<p>In case anyone is still interested, the latest thing to use now is <strong>elasticsearch</strong>. There are gems available for it like <strong>tire</strong> or <strong>elasticsearch-rails</strong>. It is also based on Lucene like Solr, Java-based. Solr is actually integrated with this project now... </p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73527', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/9594/'] |
73,536 | <p>I'm developing a client/server app that will communicate via rest. Some custom request data will be stored in the header of the request. Both the server sending the request and the receiving server have an SSL certificate - will the headers be encrypted, or just the content?</p>
| [{'answer_id': 73561, 'author': 'Ori Pessach', 'author_id': 9047, 'author_profile': 'https://Stackoverflow.com/users/9047', 'pm_score': 7, 'selected': True, 'text': "<p>SSL encrypts the entire communications path from the client to the server and back, so yes - the headers will be encrypted.</p>\n\n<p>By the way, if you develop networked applications and care about data security, the least you should do is read a book like Practical Cryptography, by Niels Ferguson and Bruce Schneier, and probably further reading that's more focused on web application security would be a good idea. If I may make an observation - and please, I don't mean that as a personal criticism - your question indicates a fundamental lack of understanding of very basic web security technologies, and that's never a good sign.</p>\n\n<p>Also, it's never a bad idea to confirm that data which is assumed to be encrypted is indeed encrypted. You can use a network analyzer to monitor traffic on the wire and watch out for anything sensitive being sent in the clear. I've used Wireshark to do this before - the results can be surprising, sometimes.</p>\n"}, {'answer_id': 73572, 'author': 'cjm', 'author_id': 8355, 'author_profile': 'https://Stackoverflow.com/users/8355', 'pm_score': 3, 'selected': False, 'text': '<p>Both headers and content are encrypted.</p>\n'}, {'answer_id': 73574, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': "<p>SSL..or rather HTTPS (HTTP over SSL) sends all HTTP content over SSL, and as HTTP content and headers are in fact the same thing, this means the headers are encrypted as well.\nSeeing as GET and POST data is sent via HTTP headers, then it only makes sense then when sending data securely you wouldn't just want the response code or content to be encrypted.</p>\n"}, {'answer_id': 73575, 'author': 'zigdon', 'author_id': 4913, 'author_profile': 'https://Stackoverflow.com/users/4913', 'pm_score': 3, 'selected': False, 'text': "<p>As long as you're communicating in the SSL tunnel, everything sent between the server and the client will be encrypted. The encryption is done before any data is sent or received.</p>\n"}, {'answer_id': 73635, 'author': 'Vinko Vrsalovic', 'author_id': 5190, 'author_profile': 'https://Stackoverflow.com/users/5190', 'pm_score': 2, 'selected': False, 'text': '<p>Having a certificate is not enough, you have to configure the web server to encrypt the connections (that is, to use the certificate) for that domain or virtual host. In addition, I think you would just need a single certificate, responses to requests will still be encrypted.</p>\n\n<p>And yes, HTTP headers are encrypted as well as the data.</p>\n'}, {'answer_id': 73722, 'author': 'ddaa', 'author_id': 11549, 'author_profile': 'https://Stackoverflow.com/users/11549', 'pm_score': 2, 'selected': False, 'text': '<p>You appear to think that REST is a distinct protocol.</p>\n\n<p>REST is not a protocol. It is a design style for HTTP-based applications.</p>\n\n<p>So, your a writing an HTTP application. Are the headers encrypted? Yes, if you are using the HTTPS (HTTP over SSL) protocol instead of plain HTTP.</p>\n\n<p>Having certificates on both sides is not directly relevant to your question. SSL certificates are used for authentication. They help in detecting man-in-the-middle attacks such as are possible using DNS cache poisoning.</p>\n'}, {'answer_id': 93089, 'author': 'Avi Flax', 'author_id': 7012, 'author_profile': 'https://Stackoverflow.com/users/7012', 'pm_score': 1, 'selected': False, 'text': '<p>The other answers are correct that headers are indeed encrypted, along with the body, when using SSL. But keep in mind that the URL, which can include query parameters, is <strong>never</strong> encrypted. So be careful to never put any sensitive information in URL query parameters.</p>\n\n<p><strong>Update:</strong> as @blowdart pointed out below, this is wrong. See the comment below.</p>\n'}, {'answer_id': 10306223, 'author': 'Jacob Toronto', 'author_id': 1354778, 'author_profile': 'https://Stackoverflow.com/users/1354778', 'pm_score': -1, 'selected': False, 'text': '<p>Not <em>everything</em> is encrypted: the request query string is not encrypted. Believe me, I\'ve seen requests like this:</p>\n\n<p><a href="https://mydomain.com/authenticate?user=username&password=MyStrongPasswordSentInTheClear" rel="nofollow">https://mydomain.com/authenticate?user=username&password=MyStrongPasswordSentInTheClear</a></p>\n\n<p>Please don\'t put sensitive data as parameters in the query string.</p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73536', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12280/'] |
73,538 | <p>Can anyone point to any websites or web applications that are using the <a href="http://www.dossier-andreas.net/software_architecture/pac.html" rel="noreferrer">Presentation-Abstraction-Control</a> design pattern rather than MVC? Desktop applications are easy to find like this (e.g.; GIMP) but I'm looking for something on the web.</p>
| [{'answer_id': 74470, 'author': 'Peter Ritchie', 'author_id': 5620, 'author_profile': 'https://Stackoverflow.com/users/5620', 'pm_score': 0, 'selected': False, 'text': '<p>The only example I\'ve seen is in <a href="https://rads.stackoverflow.com/amzn/click/com/0471958697" rel="nofollow noreferrer" rel="nofollow noreferrer">Pattern-Oriented Software Architecture Volume 1: A System Of Patterns</a>.</p>\n'}, {'answer_id': 78382, 'author': 'Patrick Desjardins', 'author_id': 13913, 'author_profile': 'https://Stackoverflow.com/users/13913', 'pm_score': 1, 'selected': False, 'text': "<p>You have difficulty to get Web application that use PAC because PAC inheritance pattern work well on custom component and custon dialog box that is not really present in the web.</p>\n\n<p>Many framwework use PAC that let you override the presentation, abstraction or control but when used in the web, mostly transform to MVC for it's simplicity (for example, you do not need to have a new level of PAC to change the appearance of a grid... you can use CSS file).</p>\n\n<p>This is the best answer that I can give you.</p>\n"}, {'answer_id': 83548, 'author': 'Matt Farina', 'author_id': 11910, 'author_profile': 'https://Stackoverflow.com/users/11910', 'pm_score': 3, 'selected': False, 'text': '<p>There are more sites using PAC than, I think, people realize. For example, <a href="http://drupal.org" rel="noreferrer">drupal</a> uses the PAC pattern and there are a lot of sites (and a lot of big sites) built with drupal. Many people confuse <a href="http://www.dossier-andreas.net/software_architecture/mvc.html" rel="noreferrer">MVC</a> and <a href="http://www.dossier-andreas.net/software_architecture/pac.html" rel="noreferrer">PAC</a>. <a href="http://www.garfieldtech.com/blog/mvc-vs-pac" rel="noreferrer">Larry Garfield does a good job explaining the difference and how drupal uses PAC</a>.</p>\n\n<p>In my research on this topic I found more than one open source app/framework that called themselves a MVC architecture when they more accurately fit the PAC pattern. Specifically in the way the model/abstraction, presentation/view, and controller interacted with each other.</p>\n'}, {'answer_id': 1767643, 'author': 'adub', 'author_id': 215100, 'author_profile': 'https://Stackoverflow.com/users/215100', 'pm_score': 2, 'selected': False, 'text': '<p>I suspect most sites written using what is called MVC are in fact using a version of PAC but with a single triad. MVC specifically requires the view to be able to communicate with the model directly without going via the controller. I think many web developers would expect this to always go via the controller regardless of the direction of communication. </p>\n'}, {'answer_id': 2624794, 'author': 'Rishav Rastogi', 'author_id': 66945, 'author_profile': 'https://Stackoverflow.com/users/66945', 'pm_score': 0, 'selected': False, 'text': '<p>Drupal is a PAC based web framework in written in PHP. :) </p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73538', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/11910/'] |
73,542 | <p>I have an List and I'd like to wrap it into an IQueryable.</p>
<p>Is this possible?</p>
| [{'answer_id': 73563, 'author': 'Paul van Brenk', 'author_id': 1837197, 'author_profile': 'https://Stackoverflow.com/users/1837197', 'pm_score': 8, 'selected': True, 'text': "<pre><code>List<int> list = new List<int>() { 1, 2, 3, 4, };\nIQueryable<int> query = list.AsQueryable();\n</code></pre>\n\n<p>If you don't see the <code>AsQueryable()</code> method, add a using statement for <code>System.Linq</code>.</p>\n"}, {'answer_id': 73564, 'author': 'Chris Shaffer', 'author_id': 6744, 'author_profile': 'https://Stackoverflow.com/users/6744', 'pm_score': 4, 'selected': False, 'text': '<p>Use the <code>AsQueryable<T>()</code> extension method.</p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73542', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/11835/'] |
73,544 | <p>Anyone know of a good, hopefully free FTP class for use in .NET that can actually work behind an HTTP proxy or FTP gateway? The FtpWebRequest stuff in .NET is horrible at best, and I really don't want to roll my own here.</p>
| [{'answer_id': 73566, 'author': 'Joel Coehoorn', 'author_id': 3043, 'author_profile': 'https://Stackoverflow.com/users/3043', 'pm_score': -1, 'selected': False, 'text': "<p>System.Net.WebClient can handle ftp urls, and it's a bit easier to work with. You can set credentials and proxy information with it, too.</p>\n"}, {'answer_id': 73630, 'author': 'Jakub Šturc', 'author_id': 2361, 'author_profile': 'https://Stackoverflow.com/users/2361', 'pm_score': 1, 'selected': False, 'text': '<p>I have no particular experience but <a href="http://sharptoolbox.com/" rel="nofollow noreferrer">sharptoolbox</a> offer <a href="http://sharptoolbox.com/search?ToolName%253dftp%2526Description%253dftp%2526Category%253d9d0e4330-f6ff-4ead-afd3-f77f1c06cdc8%2526Attribute%253d-800" rel="nofollow noreferrer">plenty implementations</a>.</p>\n'}, {'answer_id': 73637, 'author': 'Juanma', 'author_id': 3730, 'author_profile': 'https://Stackoverflow.com/users/3730', 'pm_score': 1, 'selected': False, 'text': '<p>You can give <a href="http://www.indyproject.org/index.en.aspx" rel="nofollow noreferrer" title="Indy.Sockets">"Indy.Sockets"</a> a try. It can handle a lot of high level network protocols, including ftp.</p>\n'}, {'answer_id': 74165, 'author': 'Brad Bruce', 'author_id': 5008, 'author_profile': 'https://Stackoverflow.com/users/5008', 'pm_score': 1, 'selected': False, 'text': '<p>The best one I\'ve run across is edtFTP.net <a href="http://www.enterprisedt.com/products/edtftpnet/overview.html" rel="nofollow noreferrer">http://www.enterprisedt.com/products/edtftpnet/overview.html</a> </p>\n\n<p>If offers flexibility you don\'t get in the built-in classes</p>\n'}, {'answer_id': 75069, 'author': 'Kearns', 'author_id': 6500, 'author_profile': 'https://Stackoverflow.com/users/6500', 'pm_score': 0, 'selected': False, 'text': '<p>I have used <a href="http://sourceforge.net/projects/dotnetftpclient/" rel="nofollow noreferrer">http://sourceforge.net/projects/dotnetftpclient/</a> for quite a while now, and it does the job nicely. If you use a PASV connection, you shouldn\'t have any firewall issues. Not sure what an FTP gateway is, but I don\'t see how the HTTP Proxy would affect any FTP connection.</p>\n'}, {'answer_id': 2327985, 'author': 'Martin Vobr', 'author_id': 16132, 'author_profile': 'https://Stackoverflow.com/users/16132', 'pm_score': 2, 'selected': False, 'text': '<p>Our <a href="http://www.rebex.net/ftp.net/" rel="nofollow noreferrer">Rebex FTP</a> works with proxies just fine. Following code shows how to connect to the FTP using HTTP proxy (code is taken from <a href="http://www.rebex.net/ftp.net/tutorial-ftp.aspx#proxy" rel="nofollow noreferrer">FTP tutorial page</a>).</p>\n\n<pre><code>// initialize FTP client \nFtp client = new Ftp();\n\n// setup proxy details \nclient.Proxy.ProxyType = FtpProxyType.HttpConnect;\nclient.Proxy.Host = proxyHostname;\nclient.Proxy.Port = proxyPort;\n\n// add proxy username and password when needed \nclient.Proxy.UserName = proxyUsername;\nclient.Proxy.Password = proxyPassword;\n\n// connect, login \nclient.Connect(hostname, port);\nclient.Login(username, password);\n\n// do some work \n// ... \n\n// disconnect \nclient.Disconnect();\n</code></pre>\n\n<p>You can download the trial at <a href="http://www.rebex.net/ftp.net/download.aspx" rel="nofollow noreferrer">www.rebex.net/ftp.net/download.aspx</a></p>\n'}, {'answer_id': 2328113, 'author': 'Rush Frisby', 'author_id': 266804, 'author_profile': 'https://Stackoverflow.com/users/266804', 'pm_score': 0, 'selected': False, 'text': '<p>I used this in my project recently and it worked great.</p>\n\n<p><a href="http://www.codeproject.com/KB/IP/ftplib.aspx" rel="nofollow noreferrer">http://www.codeproject.com/KB/IP/ftplib.aspxt</a></p>\n'}, {'answer_id': 8060892, 'author': 'Brady Moritz', 'author_id': 177242, 'author_profile': 'https://Stackoverflow.com/users/177242', 'pm_score': 0, 'selected': False, 'text': '<p>.Net 4.0+ now includes an ftp client class- see this msdn link for more info. </p>\n\n<p><a href="http://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest.aspx</a></p>\n\n<p>I see options for even using PASV mode etc, so it appears to be fully functional (or so I hope). </p>\n'}, {'answer_id': 12266161, 'author': 'freggel', 'author_id': 49788, 'author_profile': 'https://Stackoverflow.com/users/49788', 'pm_score': 0, 'selected': False, 'text': '<p>I had a simalor issue, create an client for FTPS (explicit) communcation through a Socks4 proxy.</p>\n\n<p>After some searching and testing I found .NET library Starksoftftps.\n<a href="http://starksoftftps.codeplex.com/" rel="nofollow">http://starksoftftps.codeplex.com/</a></p>\n\n<p>Here is my code sample:</p>\n\n<pre><code>Socks4ProxyClient socks = new Socks4ProxyClient("socksproxyhost",1010);\nFtpClient ftp = new FtpClient("ftpshost",2010,FtpSecurityProtocol.Tls1Explicit);\nftp.Proxy = socks;\nftp.Open("userid", "******");\nftp.PutFile(@"C:\\519ec30a-ae15-4bd5-8bcd-94ef3ca49165.xml");\nConsole.WriteLine(ftp.GetDirListAsText());\nftp.Close();\n</code></pre>\n'}, {'answer_id': 20353970, 'author': "A. 'Eradicator' Polyakov", 'author_id': 3061817, 'author_profile': 'https://Stackoverflow.com/users/3061817', 'pm_score': 0, 'selected': False, 'text': '<p>Here is my open source C# code that uploads file to FTP via HTTP proxy.</p>\n\n<pre><code>public bool UploadFile(string localFilePath, string remoteDirectory)\n{\n var fileName = Path.GetFileName(localFilePath);\n string content;\n using (var reader = new StreamReader(localFilePath))\n content = reader.ReadToEnd();\n\n var proxyAuthB64Str = Convert.ToBase64String(Encoding.ASCII.GetBytes(_proxyUserName + ":" + _proxyPassword));\n var sendStr = "PUT ftp://" + _ftpLogin + ":" + _ftpPassword\n + "@" + _ftpHost + remoteDirectory + fileName + " HTTP/1.1\\n"\n + "Host: " + _ftpHost + "\\n"\n + "User-Agent: Mozilla/4.0 (compatible; Eradicator; dotNetClient)\\n" + "Proxy-Authorization: Basic " + proxyAuthB64Str + "\\n"\n + "Content-Type: application/octet-stream\\n"\n + "Content-Length: " + content.Length + "\\n"\n + "Connection: close\\n\\n" + content;\n\n var sendBytes = Encoding.ASCII.GetBytes(sendStr);\n\n using (var proxySocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))\n {\n proxySocket.Connect(_proxyHost, _proxyPort);\n if (!proxySocket.Connected)\n throw new SocketException();\n proxySocket.Send(sendBytes);\n\n const int recvSize = 65536;\n var recvBytes = new byte[recvSize];\n proxySocket.Receive(recvBytes, recvSize, SocketFlags.Partial);\n\n var responseFirstLine = new string(Encoding.ASCII.GetChars(recvBytes)).Split("\\n".ToCharArray()).Take(1).ElementAt(0);\n var httpResponseCode = Regex.Replace(responseFirstLine, @"HTTP/1\\.\\d (\\d+) (\\w+)", "$1");\n var httpResponseDescription = Regex.Replace(responseFirstLine, @"HTTP/1\\.\\d (\\d+) (\\w+)", "$2");\n return httpResponseCode.StartsWith("2");\n }\n return false;\n}\n</code></pre>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73544', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/91911/'] |
73,576 | <p>Was wondering if there was a way to put a wildcard in the schema.ini for example
[*.txt]
FMT=TabDelimited</p>
<p>I've got an app that is imported tab delimited files and the only place I can seem to get the FMT="TabDelimited" is in the schema.ini (doesn't work in the connection string for some reason), but I will have no idea what the filenames are other than the txt extension.</p>
<p>BTW I'm connecting using an OdbcConnection and the Microsoft Text Driver.</p>
| [{'answer_id': 75632, 'author': 'Jeremy Coenen', 'author_id': 7798, 'author_profile': 'https://Stackoverflow.com/users/7798', 'pm_score': 2, 'selected': True, 'text': "<p>I guess I could potentially rename the file temporarily to match whatever I decide to put in the schema.ini or potentially modify the schema.ini on the fly and put the correct filename in there, but I'd love to do know if there was a better way.</p>\n"}, {'answer_id': 145807, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>A single schema.ini file can contain multiple\n[fileName.txt] entries and format \ndescriptions, (for all the files in the \nDirectory), so you might consider creating the .ini\nfile dynamically from the directory file names. </p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73576', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/7798/'] |
73,580 | <blockquote>
<p><strong>Possible Duplicate:</strong><br>
<a href="https://stackoverflow.com/questions/46663/how-do-you-send-email-from-a-java-app-using-gmail">How do you send email from a Java app using Gmail?</a> </p>
</blockquote>
<p>How do I send an SMTP Message from Java?</p>
| [{'answer_id': 73596, 'author': 'Mason', 'author_id': 8973, 'author_profile': 'https://Stackoverflow.com/users/8973', 'pm_score': 2, 'selected': False, 'text': '<p>See the <a href="http://www.oracle.com/technetwork/java/javamail/index.html" rel="nofollow noreferrer">JavaMail API</a> and associated javadocs.</p>\n'}, {'answer_id': 73599, 'author': 'Ryan Lanciaux', 'author_id': 1385358, 'author_profile': 'https://Stackoverflow.com/users/1385358', 'pm_score': 2, 'selected': False, 'text': '<p>Please see this post </p>\n\n<p><a href="https://stackoverflow.com/questions/46663/how-do-you-send-email-from-a-java-app-using-gmail">How can I send an email by Java application using GMail, Yahoo, or Hotmail?</a></p>\n\n<p>It is specific to gmail but you can substitute your smtp credentials.</p>\n'}, {'answer_id': 73600, 'author': 'Jorge Ferreira', 'author_id': 6508, 'author_profile': 'https://Stackoverflow.com/users/6508', 'pm_score': 2, 'selected': False, 'text': '<p>See the following tutorial at Java Practices.</p>\n\n<p><a href="http://www.javapractices.com/topic/TopicAction.do?Id=144" rel="nofollow noreferrer">http://www.javapractices.com/topic/TopicAction.do?Id=144</a></p>\n'}, {'answer_id': 73649, 'author': 'tovare', 'author_id': 12677, 'author_profile': 'https://Stackoverflow.com/users/12677', 'pm_score': 6, 'selected': True, 'text': '<p>Here\'s an example for Gmail smtp:</p>\n\n<pre><code>import java.io.*;\nimport java.net.InetAddress;\nimport java.util.Properties;\nimport java.util.Date;\n\nimport javax.mail.*;\n\nimport javax.mail.internet.*;\n\nimport com.sun.mail.smtp.*;\n\n\npublic class Distribution {\n\n public static void main(String args[]) throws Exception {\n Properties props = System.getProperties();\n props.put("mail.smtps.host","smtp.gmail.com");\n props.put("mail.smtps.auth","true");\n Session session = Session.getInstance(props, null);\n Message msg = new MimeMessage(session);\n msg.setFrom(new InternetAddress("[email protected]"));;\n msg.setRecipients(Message.RecipientType.TO,\n InternetAddress.parse("[email protected]", false));\n msg.setSubject("Heisann "+System.currentTimeMillis());\n msg.setText("Med vennlig hilsennTov Are Jacobsen");\n msg.setHeader("X-Mailer", "Tov Are\'s program");\n msg.setSentDate(new Date());\n SMTPTransport t =\n (SMTPTransport)session.getTransport("smtps");\n t.connect("smtp.gmail.com", "[email protected]", "<insert password here>");\n t.sendMessage(msg, msg.getAllRecipients());\n System.out.println("Response: " + t.getLastServerResponse());\n t.close();\n }\n}\n</code></pre>\n\n<p>Now, do it this way only if you would like to keep your project dependencies to a minimum, otherwise i can warmly recommend using classes from apache</p>\n\n<p><a href="http://commons.apache.org/email/" rel="noreferrer">http://commons.apache.org/email/</a> </p>\n\n<p>Regards</p>\n\n<p>Tov Are Jacobsen</p>\n'}, {'answer_id': 90001, 'author': 'Brad at Kademi', 'author_id': 17025, 'author_profile': 'https://Stackoverflow.com/users/17025', 'pm_score': 3, 'selected': False, 'text': '<p>Another way is to use aspirin (<a href="https://github.com/masukomi/aspirin" rel="nofollow noreferrer">https://github.com/masukomi/aspirin</a>) like this:</p>\n\n<pre><code>MailQue.queMail(MimeMessage message)\n</code></pre>\n\n<p>..after having constructed your mimemessage as above.</p>\n\n<p>Aspirin <strong>is</strong> an smtp \'server\' so you don\'t have to configure it. But note that sending email to a broad set of recipients isnt as simple as it appears because of the many different spam filtering rules receiving mail servers and client applications apply. </p>\n'}, {'answer_id': 4578893, 'author': 'user527619', 'author_id': 527619, 'author_profile': 'https://Stackoverflow.com/users/527619', 'pm_score': 1, 'selected': False, 'text': '<pre><code>import javax.mail.*;\nimport javax.mail.internet.*;\nimport java.util.*; \n\npublic void postMail(String recipients[], String subject,\n String message , String from) throws MessagingException {\n\n //Set the host smtp address\n Properties props = new Properties();\n props.put("mail.smtp.host", "smtp.jcom.net");\n\n // create some properties and get the default Session\n Session session = Session.getDefaultInstance(props, null);\n session.setDebug(false);\n\n // create a message\n Message msg = new MimeMessage(session);\n\n // set the from and to address\n InternetAddress addressFrom = new InternetAddress(from);\n msg.setFrom(addressFrom);\n\n InternetAddress[] addressTo = new InternetAddress[recipients.length]; \n for (int i = 0; i < recipients.length; i++) {\n addressTo[i] = new InternetAddress(recipients[i]);\n }\n msg.setRecipients(Message.RecipientType.TO, addressTo);\n\n // Optional : You can also set your custom headers in the Email if you Want\n msg.addHeader("MyHeaderName", "myHeaderValue");\n\n // Setting the Subject and Content Type\n msg.setSubject(subject);\n msg.setContent(message, "text/plain");\n Transport.send(msg);\n}\n</code></pre>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73580', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2443/'] |
73,586 | <p>How would one configurably set http-headers to cache files in IIS >= 6?</p>
<p>Example:</p>
<ul>
<li><code>*.cache.*</code> => cache nearly forever</li>
<li><code>*.nocache.*</code> => never cache</li>
</ul>
<p>An example framework using this naming would be the GWT framework.</p>
| [{'answer_id': 73957, 'author': 'betelgeuce', 'author_id': 366182, 'author_profile': 'https://Stackoverflow.com/users/366182', 'pm_score': 0, 'selected': False, 'text': '<p><a href="http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/23ea6f24-4b44-4fa0-a275-a1b907e1afb6.mspx?mfr=true" rel="nofollow noreferrer">http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/23ea6f24-4b44-4fa0-a275-a1b907e1afb6.mspx?mfr=true</a></p>\n\n<p>Explains the different methods of caching data in IIS.</p>\n'}, {'answer_id': 274940, 'author': 'The Archetypal Paul', 'author_id': 21755, 'author_profile': 'https://Stackoverflow.com/users/21755', 'pm_score': 1, 'selected': False, 'text': '<p>I think you\'re referring to setting the cache-control header.</p>\n\n<p>See here <a href="http://support.microsoft.com/kb/247404" rel="nofollow noreferrer">http://support.microsoft.com/kb/247404</a></p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73586', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12713/'] |
73,628 | <p>If you have a JSF <code><h:commandLink></code> (which uses the <code>onclick</code> event of an <code><a></code> to submit the current form), how do you execute JavaScript (such as asking for delete confirmation) prior to the action being performed?</p>
| [{'answer_id': 73644, 'author': 'Grant Wagner', 'author_id': 9254, 'author_profile': 'https://Stackoverflow.com/users/9254', 'pm_score': 4, 'selected': True, 'text': '<pre><code><h:commandLink id="myCommandLink" action="#{myPageCode.doDelete}">\n <h:outputText value="#{msgs.deleteText}" />\n</h:commandLink>\n<script type="text/javascript">\nif (document.getElementById) {\n var commandLink = document.getElementById(\'<c:out value="${myPageCode.myCommandLinkClientId}" />\');\n if (commandLink && commandLink.onclick) {\n var commandLinkOnclick = commandLink.onclick;\n commandLink.onclick = function() {\n var result = confirm(\'Do you really want to <c:out value="${msgs.deleteText}" />?\');\n if (result) {\n return commandLinkOnclick();\n }\n return false;\n }\n }\n}\n</script>\n</code></pre>\n\n<p>Other Javascript actions (like validating form input etc) could be performed by replacing the call to <code>confirm()</code> with a call to another function.</p>\n'}, {'answer_id': 73800, 'author': 'noah', 'author_id': 12034, 'author_profile': 'https://Stackoverflow.com/users/12034', 'pm_score': 1, 'selected': False, 'text': '<p>You can still use onclick. The JSF <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/renderkitdocs/HTML_BASIC/javax.faces.Commandjavax.faces.Link.html" rel="nofollow noreferrer">render kit specification</a> (see Encode Behavior) describes how the link should handle it. Here is the important part (what it renders for onclick):</p>\n\n<pre><code>var a=function(){/*your onclick*/}; var b=function(){/*JSF onclick*/}; return (a()==false) ? false : b();\n</code></pre>\n\n<p>So your function wont be passed the event object (which isn\'t reliable cross browser anyway), but returning true/false will short-circuit the submission.</p>\n'}, {'answer_id': 82125, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>In JSF 1.2 you can specify onclick events.</p>\n\n<p>Also, other libraries such as <a href="http://myfaces.apache.org/" rel="nofollow noreferrer">MyFaces</a> or <a href="http://www.icefaces.org" rel="nofollow noreferrer">IceFaces</a> implement the "onclick" handler.</p>\n\n<p>What you\'d need to do then is simply:</p>\n\n<pre><code><h:commandLink action="#{bean.action}" onclick="if(confirm(\'Are you sure?\')) return false;" />\n</code></pre>\n\n<p>Note: you can\'t just do <code>return confirm(...)</code> as this will block the rest of the JavaScript in the onClick event from happening, which would effectively stop your action from happening no matter what the user returned!</p>\n'}, {'answer_id': 82962, 'author': 'Victor', 'author_id': 14514, 'author_profile': 'https://Stackoverflow.com/users/14514', 'pm_score': 0, 'selected': False, 'text': '<p>If you want to execute something before the form is posted, for confirmation for example, try the form event onSubmit. Something like:</p>\n\n<pre><code>myform.onsubmit = function(){confirm("really really sure?")};\n</code></pre>\n'}, {'answer_id': 510671, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>This never worked for me, </p>\n\n<pre><code> onclick="if(confirm(\'Are you sure?\')) return false;" />\n</code></pre>\n\n<p>but this did</p>\n\n<pre><code>onclick="if(confirm(\\"Are you sure?\\"))return true; else return false;"\n</code></pre>\n'}, {'answer_id': 4542190, 'author': 'iordan', 'author_id': 555424, 'author_profile': 'https://Stackoverflow.com/users/555424', 'pm_score': 4, 'selected': False, 'text': '<p>Can be simplified like this</p>\n\n<pre><code>onclick="return confirm(\'Are you sure?\');"\n</code></pre>\n'}, {'answer_id': 4622401, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<pre><code>var deleteClick;\nvar mess="xxx";\nfunction assignDeleteClick(link) {\n if (link.onclick == confirmDelete) {\n return;\n }\n deleteClick = link.onclick;\n link.onclick = confirmDelete;\n}\n\n\nfunction confirmDelete() {\n var ans = confirm(mess);\n if (ans == true) {\n return deleteClick();\n } else {\n return false;\n }\n} \n</code></pre>\n\n<p>use this code for jsf 1.1.</p>\n'}, {'answer_id': 6113403, 'author': 'Hanynowsky', 'author_id': 754756, 'author_profile': 'https://Stackoverflow.com/users/754756', 'pm_score': 3, 'selected': False, 'text': '<p>This worked for me:</p>\n\n<pre><code><h:commandButton title="#{bundle.NewPatient}" action="#{identifController.prepareCreate}" \n id="newibutton" \n onclick="if(confirm(\'#{bundle.NewPatient}?\'))return true; else return false;" \n value="#{bundle.NewPatient}"/>\n</code></pre>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73628', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/9254/'] |
73,629 | <p>I have a string that is like below.</p>
<pre><code>,liger, unicorn, snipe
</code></pre>
<p>in other languages I'm familiar with I can just do a string.trim(",") but how can I do that in c#?</p>
<p>Thanks.</p>
<hr>
<p><em>There's been a lot of back and forth about the StartTrim function. As several have pointed out, the StartTrim doesn't affect the primary variable. However, given the construction of the data vs the question, I'm torn as to which answer to accept. True the question only wants the first character trimmed off not the last (if anny), however, there would never be a "," at the end of the data. So, with that said, I'm going to accept the first answer that that said to use StartTrim assigned to a new variable.</em></p>
| [{'answer_id': 73650, 'author': 'Bob King', 'author_id': 6897, 'author_profile': 'https://Stackoverflow.com/users/6897', 'pm_score': 0, 'selected': False, 'text': '<pre><code>if (s.StartsWith(",")) {\n s = s.Substring(1, s.Length - 1);\n}\n</code></pre>\n'}, {'answer_id': 73652, 'author': 'DevelopingChris', 'author_id': 1220, 'author_profile': 'https://Stackoverflow.com/users/1220', 'pm_score': 4, 'selected': False, 'text': '<pre><code>string s = ",liger, unicorn, snipe";\ns.TrimStart(\',\');\n</code></pre>\n'}, {'answer_id': 73656, 'author': 'Kieran Benton', 'author_id': 5777, 'author_profile': 'https://Stackoverflow.com/users/5777', 'pm_score': 0, 'selected': False, 'text': '<pre><code>string t = ",liger, unicorn, snipe".TrimStart(new char[] {\',\'});\n</code></pre>\n'}, {'answer_id': 73658, 'author': 'pilsetnieks', 'author_id': 6615, 'author_profile': 'https://Stackoverflow.com/users/6615', 'pm_score': 0, 'selected': False, 'text': '<p>The same way as everywhere else: <a href="http://msdn.microsoft.com/en-us/library/d4tt83f9.aspx" rel="nofollow noreferrer">string.trim</a></p>\n'}, {'answer_id': 73660, 'author': 'Matt Dawdy', 'author_id': 232, 'author_profile': 'https://Stackoverflow.com/users/232', 'pm_score': 0, 'selected': False, 'text': '<pre><code> string s = ",liger, tiger";\n\n if (s.Substring(0, 1) == ",")\n s = s.Substring(1);\n</code></pre>\n'}, {'answer_id': 73665, 'author': 'chakrit', 'author_id': 3055, 'author_profile': 'https://Stackoverflow.com/users/3055', 'pm_score': 0, 'selected': False, 'text': '<p>Did you mean trim all instances of "," in that string?</p>\n\n<p>In which case, you can do:</p>\n\n<pre><code>s = s.Replace(",", "");\n</code></pre>\n'}, {'answer_id': 73668, 'author': 'Akselsson', 'author_id': 8862, 'author_profile': 'https://Stackoverflow.com/users/8862', 'pm_score': 1, 'selected': False, 'text': '<p>",liger, unicorn, snipe".Trim(\',\') -> "liger, unicor, snipe"</p>\n'}, {'answer_id': 73671, 'author': 'Magus', 'author_id': 2188, 'author_profile': 'https://Stackoverflow.com/users/2188', 'pm_score': 1, 'selected': False, 'text': "<p>Try string.Trim(',') and see if that does what you want.</p>\n"}, {'answer_id': 73676, 'author': 'Clinton Pierce', 'author_id': 8173, 'author_profile': 'https://Stackoverflow.com/users/8173', 'pm_score': 0, 'selected': False, 'text': '<p>Just use Substring to ignore the first character (or assign it to another string);</p>\n\n<pre><code> string o = ",liger, unicorn, snipe";\n string s = o.Substring(1);\n</code></pre>\n'}, {'answer_id': 73681, 'author': 'Jay Bazuzi', 'author_id': 5314, 'author_profile': 'https://Stackoverflow.com/users/5314', 'pm_score': 2, 'selected': False, 'text': '<p>.net strings can do Trim() and TrimStart(). Because it takes <code>params</code>, you can write:</p>\n\n<pre><code>",liger, unicorn, snipe".TrimStart(\',\')\n</code></pre>\n\n<p>and if you have more than one character to trim, you can write:</p>\n\n<pre><code>",liger, unicorn, snipe".TrimStart(",; ".ToCharArray())\n</code></pre>\n'}, {'answer_id': 73708, 'author': 'bentford', 'author_id': 946, 'author_profile': 'https://Stackoverflow.com/users/946', 'pm_score': 0, 'selected': False, 'text': '<p>See: <a href="http://msdn.microsoft.com/en-us/library/d4tt83f9.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/d4tt83f9.aspx</a></p>\n\n<pre><code> string animals = ",liger, unicorn, snipe";\n\n //trimmed will contain "liger, unicorn, snipe"\n string trimmed = word.Trim(\',\');\n</code></pre>\n'}, {'answer_id': 73734, 'author': 'RickL', 'author_id': 7261, 'author_profile': 'https://Stackoverflow.com/users/7261', 'pm_score': 5, 'selected': True, 'text': '<pre><code>string sample = ",liger, unicorn, snipe";\nsample = sample.TrimStart(\',\'); // to remove just the first comma\n</code></pre>\n\n<p>Or perhaps:</p>\n\n<pre><code>sample = sample.Trim().TrimStart(\',\'); // to remove any whitespace and then the first comma\n</code></pre>\n'}, {'answer_id': 73749, 'author': 'hamishmcn', 'author_id': 3590, 'author_profile': 'https://Stackoverflow.com/users/3590', 'pm_score': 1, 'selected': False, 'text': '<p>Note, the <em>original</em> string is left untouched, Trim will return you a new string:</p>\n\n<pre><code>string s1 = ",abc,d";\nstring s2 = s1.TrimStart(",".ToCharArray());\nConsole.WriteLine("s1 = {0}", s1);\nConsole.WriteLine("s2 = {0}", s2);\n</code></pre>\n\n<p>prints:</p>\n\n<pre><code>s1 = ,abc,d\ns2 = abc,d\n</code></pre>\n'}, {'answer_id': 74536, 'author': 'justin.m.chase', 'author_id': 12958, 'author_profile': 'https://Stackoverflow.com/users/12958', 'pm_score': 2, 'selected': False, 'text': '<p>here is an easy way to not produce the leading comma to begin with:</p>\n\n<pre><code>string[] animals = { "liger", "unicorn", "snipe" };\nstring joined = string.Join(", ", animals);\n</code></pre>\n'}, {'answer_id': 79881, 'author': 'Wonko', 'author_id': 14842, 'author_profile': 'https://Stackoverflow.com/users/14842', 'pm_score': 1, 'selected': False, 'text': '<pre><code>string s = ",liger, unicorn, snipe";\ns = s.TrimStart(\',\');\n</code></pre>\n<p>It\'s important to assign the result of TrimStart to a variable. As it says on the <a href="http://msdn.microsoft.com/en-us/library/system.string.trimstart.aspx" rel="nofollow noreferrer">TrimStart page</a>, "This method does not modify the value of the current instance. Instead, it returns a new string...".</p>\n<p>In .NET, strings don\'t change.</p>\n'}, {'answer_id': 80283, 'author': 'abjbhat', 'author_id': 15048, 'author_profile': 'https://Stackoverflow.com/users/15048', 'pm_score': 1, 'selected': False, 'text': '<p>you can use this </p>\n\n<p>,liger, unicorn, snipe".TrimStart(\',\');</p>\n'}, {'answer_id': 80517, 'author': 'benPearce', 'author_id': 4490, 'author_profile': 'https://Stackoverflow.com/users/4490', 'pm_score': 2, 'selected': False, 'text': '<p>string.TrimStart(\',\') will remove the comma, however you will have trouble with a split operation due to the space after the comma. \nBest to join just on the single comma or use </p>\n\n<blockquote>\n <p>Split(", ".ToCharArray(),StringSplitOptions.RemoveEmptyEntries);</p>\n</blockquote>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73629', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/730/'] |
73,646 | <p>Has anyone implements Subversion with Siteminder as authentication provider ? If yes, would it be possible to provide an overview of how the whole setup is done ?</p>
<p>Since I am using only HTTP authentication, I think it would be easier to integrate with SM, but I am not able to find much help on this on the net.</p>
<p>Is there any pitfall with this setup ? is this even possible ?</p>
| [{'answer_id': 82401, 'author': 'Duncan Smart', 'author_id': 1278, 'author_profile': 'https://Stackoverflow.com/users/1278', 'pm_score': 1, 'selected': False, 'text': '<p>Look for information about <strong>Apache</strong> and Siteminder as Apache is responsible for the HTTP transport stuff in Subversion</p>\n'}, {'answer_id': 812821, 'author': 'Ram Prasad', 'author_id': 6361, 'author_profile': 'https://Stackoverflow.com/users/6361', 'pm_score': 3, 'selected': True, 'text': '<p>SVN with Siteminder has been implemented and is working now. Since there is not much of information out there on this, I would like to post the overview of steps followed:</p>\n\n<ol>\n<li>Cookie based authentcation was disabled on Siteminder end</li>\n<li>HTTP AUTH was enabled (in Siteminder) and all webdav methods were added to policy server to be handled by SiteMinder</li>\n<li>Authentication was disabled on apache end (HTTP Auth) for SVN</li>\n</ol>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73646', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/6361/'] |
73,651 | <p>I'm failing at finding the commands I need to send to authenticate to a SMTP server using NTLM. </p>
<p>I think it goes something like:</p>
<pre><code>AUTH NTLM <bae64encode something>
334
<bae64encode something>
235
</code></pre>
| [{'answer_id': 82401, 'author': 'Duncan Smart', 'author_id': 1278, 'author_profile': 'https://Stackoverflow.com/users/1278', 'pm_score': 1, 'selected': False, 'text': '<p>Look for information about <strong>Apache</strong> and Siteminder as Apache is responsible for the HTTP transport stuff in Subversion</p>\n'}, {'answer_id': 812821, 'author': 'Ram Prasad', 'author_id': 6361, 'author_profile': 'https://Stackoverflow.com/users/6361', 'pm_score': 3, 'selected': True, 'text': '<p>SVN with Siteminder has been implemented and is working now. Since there is not much of information out there on this, I would like to post the overview of steps followed:</p>\n\n<ol>\n<li>Cookie based authentcation was disabled on Siteminder end</li>\n<li>HTTP AUTH was enabled (in Siteminder) and all webdav methods were added to policy server to be handled by SiteMinder</li>\n<li>Authentication was disabled on apache end (HTTP Auth) for SVN</li>\n</ol>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73651', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4580/'] |
73,663 | <p>How do I exit a script early, like the <code>die()</code> command in PHP?</p>
| [{'answer_id': 73673, 'author': 'pjz', 'author_id': 8002, 'author_profile': 'https://Stackoverflow.com/users/8002', 'pm_score': 12, 'selected': True, 'text': '<pre><code>import sys\nsys.exit()\n</code></pre>\n<p>details from the <a href="https://docs.python.org/2/library/sys.html#sys.exit" rel="noreferrer"><code>sys</code> module documentation</a>:</p>\n<blockquote>\n<p><code>sys.<strong>exit</strong>([<em>arg</em>])</code></p>\n<p>Exit from Python. This is implemented by raising the\n<a href="https://docs.python.org/2/library/exceptions.html#SystemExit" rel="noreferrer" title="SystemExit"><code>SystemExit</code></a> exception, so cleanup actions specified by finally clauses\nof <a href="https://docs.python.org/2/reference/compound_stmts.html#try" rel="noreferrer" title="try"><code>try</code></a> statements are honored, and it is possible to intercept the\nexit attempt at an outer level.</p>\n<p>The optional argument <em>arg</em> can be an integer giving the exit status\n(defaulting to zero), or another type of object. If it is an integer,\nzero is considered “successful termination” and any nonzero value is\nconsidered “abnormal termination” by shells and the like. Most systems\nrequire it to be in the range 0-127, and produce undefined results\notherwise. Some systems have a convention for assigning specific\nmeanings to specific exit codes, but these are generally\nunderdeveloped; Unix programs generally use 2 for command line syntax\nerrors and 1 for all other kind of errors. If another type of object\nis passed, None is equivalent to passing zero, and any other object is\nprinted to <a href="https://docs.python.org/2/library/sys.html#sys.stderr" rel="noreferrer" title="sys.stderr"><code>stderr</code></a> and results in an exit code of 1. In particular,\n<code>sys.exit("some error message")</code> is a quick way to exit a program when\nan error occurs.</p>\n<p>Since <a href="https://docs.python.org/2/library/constants.html#exit" rel="noreferrer" title="exit"><code>exit()</code></a> ultimately “only” raises an exception, it will only exit\nthe process when called from the main thread, and the exception is not\nintercepted.</p>\n</blockquote>\n<p>Note that this is the \'nice\' way to exit. @<a href="https://stackoverflow.com/questions/73663/terminating-a-python-script#76374">glyphtwistedmatrix</a> below points out that if you want a \'hard exit\', you can use <code>os._exit(*errorcode*)</code>, though it\'s likely os-specific to some extent (it might not take an errorcode under windows, for example), and it definitely is less friendly since it doesn\'t let the interpreter do any cleanup before the process dies. On the other hand, it <em>does</em> kill the entire process, including all running threads, while <code>sys.exit()</code> (as it says in the docs) only exits if called from the main thread, with no other threads running.</p>\n'}, {'answer_id': 73680, 'author': 'Vhaerun', 'author_id': 11234, 'author_profile': 'https://Stackoverflow.com/users/11234', 'pm_score': 7, 'selected': False, 'text': '<p>Another way is:</p>\n\n<pre><code>raise SystemExit\n</code></pre>\n'}, {'answer_id': 73695, 'author': 'cleg', 'author_id': 29503, 'author_profile': 'https://Stackoverflow.com/users/29503', 'pm_score': 5, 'selected': False, 'text': '<pre><code>from sys import exit\nexit()\n</code></pre>\n\n<p>As a parameter you can pass an exit code, which will be returned to OS. Default is 0.</p>\n'}, {'answer_id': 76374, 'author': 'Glyph', 'author_id': 13564, 'author_profile': 'https://Stackoverflow.com/users/13564', 'pm_score': 6, 'selected': False, 'text': '<p>While you should generally prefer <code>sys.exit</code> because it is more "friendly" to other code, all it actually does is raise an exception.</p>\n\n<p>If you are sure that you need to exit a process immediately, and you might be inside of some exception handler which would catch <code>SystemExit</code>, there is another function - <code>os._exit</code> - which terminates immediately at the C level and does not perform any of the normal tear-down of the interpreter; for example, hooks registered with the "atexit" module are not executed.</p>\n'}, {'answer_id': 14836329, 'author': 'j.m.g.r', 'author_id': 2065348, 'author_profile': 'https://Stackoverflow.com/users/2065348', 'pm_score': 9, 'selected': False, 'text': '<p>A simple way to terminate a Python script early is to use the built-in <code>quit()</code> function. There is no need to import any library, and it is efficient and simple.</p>\n\n<p>Example:</p>\n\n<pre><code>#do stuff\nif this == that:\n quit()\n</code></pre>\n'}, {'answer_id': 16150238, 'author': 'Space cowboy', 'author_id': 1897240, 'author_profile': 'https://Stackoverflow.com/users/1897240', 'pm_score': 7, 'selected': False, 'text': '<p>You can also use simply <code>exit()</code>.</p>\n\n<p>Keep in mind that <code>sys.exit()</code>, <code>exit()</code>, <code>quit()</code>, and <code>os._exit(0)</code> <strong>kill</strong> the Python interpreter. Therefore, if it appears in a script called from another script by <code>execfile()</code>, it stops execution of both scripts. </p>\n\n<p>See "<a href="https://stackoverflow.com/a/1028632/1897240">Stop execution of a script called with execfile</a>" to avoid this.</p>\n'}, {'answer_id': 22504027, 'author': 'Floggedhorse', 'author_id': 2428737, 'author_profile': 'https://Stackoverflow.com/users/2428737', 'pm_score': 5, 'selected': False, 'text': '<p>I\'m a total novice but surely this is cleaner and more controlled</p>\n\n<pre><code>def main():\n try:\n Answer = 1/0\n print Answer\n except:\n print \'Program terminated\'\n return\n print \'You wont see this\'\n\nif __name__ == \'__main__\': \n main()\n</code></pre>\n\n<p>...</p>\n\n<blockquote>\n <p>Program terminated</p>\n</blockquote>\n\n<p>than</p>\n\n<pre><code>import sys\ndef main():\n try:\n Answer = 1/0\n print Answer\n except:\n print \'Program terminated\'\n sys.exit()\n print \'You wont see this\'\n\nif __name__ == \'__main__\': \n main()\n</code></pre>\n\n<p>...</p>\n\n<blockquote>\n <blockquote>\n <p>Program terminated Traceback (most recent call last): File "Z:\\Directory\\testdieprogram.py", line 12, in \n main() File "Z:\\Directory\\testdieprogram.py", line 8, in main\n sys.exit() SystemExit</p>\n </blockquote>\n</blockquote>\n\n<p>Edit</p>\n\n<p>The point being that the program ends smoothly and peacefully, rather than <strong>"I\'VE STOPPED !!!!"</strong></p>\n'}, {'answer_id': 40525942, 'author': 'eaydin', 'author_id': 1278994, 'author_profile': 'https://Stackoverflow.com/users/1278994', 'pm_score': 6, 'selected': False, 'text': '<p>I\'ve just found out that when writing a multithreadded app, <code>raise SystemExit</code> and <code>sys.exit()</code> both kills only the running thread. On the other hand, <code>os._exit()</code> exits the whole process. This was discussed in "<a href="https://stackoverflow.com/questions/905189/why-does-sys-exit-not-exit-when-called-inside-a-thread-in-python/5120178#5120178">Why does sys.exit() not exit when called inside a thread in Python?</a>".</p>\n\n<p>The example below has 2 threads. Kenny and Cartman. Cartman is supposed to live forever, but Kenny is called recursively and should die after 3 seconds. (recursive calling is not the best way, but I had other reasons)</p>\n\n<p>If we also want Cartman to die when Kenny dies, Kenny should go away with <code>os._exit</code>, otherwise, only Kenny will die and Cartman will live forever.</p>\n\n<pre><code>import threading\nimport time\nimport sys\nimport os\n\ndef kenny(num=0):\n if num > 3:\n # print("Kenny dies now...")\n # raise SystemExit #Kenny will die, but Cartman will live forever\n # sys.exit(1) #Same as above\n\n print("Kenny dies and also kills Cartman!")\n os._exit(1)\n while True:\n print("Kenny lives: {0}".format(num))\n time.sleep(1)\n num += 1\n kenny(num)\n\ndef cartman():\n i = 0\n while True:\n print("Cartman lives: {0}".format(i))\n i += 1\n time.sleep(1)\n\nif __name__ == \'__main__\':\n daemon_kenny = threading.Thread(name=\'kenny\', target=kenny)\n daemon_cartman = threading.Thread(name=\'cartman\', target=cartman)\n daemon_kenny.setDaemon(True)\n daemon_cartman.setDaemon(True)\n\n daemon_kenny.start()\n daemon_cartman.start()\n daemon_kenny.join()\n daemon_cartman.join()\n</code></pre>\n'}, {'answer_id': 41350119, 'author': 'David C.', 'author_id': 6036809, 'author_profile': 'https://Stackoverflow.com/users/6036809', 'pm_score': 4, 'selected': False, 'text': '<p>In Python 3.5, I tried to incorporate similar code without use of modules (e.g. sys, Biopy) other than what\'s built-in to stop the script and print an error message to my users. Here\'s my example:</p>\n\n<pre><code>## My example:\nif "ATG" in my_DNA: \n ## <Do something & proceed...>\nelse: \n print("Start codon is missing! Check your DNA sequence!")\n exit() ## as most folks said above\n</code></pre>\n\n<p>Later on, I found it is more succinct to just throw an error:</p>\n\n<pre><code>## My example revised:\nif "ATG" in my_DNA: \n ## <Do something & proceed...>\nelse: \n raise ValueError("Start codon is missing! Check your DNA sequence!")\n</code></pre>\n'}, {'answer_id': 60805367, 'author': 'Matthew', 'author_id': 12898298, 'author_profile': 'https://Stackoverflow.com/users/12898298', 'pm_score': 2, 'selected': False, 'text': "<p>My two cents.</p>\n\n<p>Python 3.8.1, Windows 10, 64-bit.</p>\n\n<p><code>sys.exit()</code> does not work directly for me.</p>\n\n<p>I have several nexted loops.</p>\n\n<p>First I declare a boolean variable, which I call <code>immediateExit</code>.</p>\n\n<p>So, in the beginning of the program code I write:</p>\n\n<pre><code>immediateExit = False\n</code></pre>\n\n<p>Then, starting from the most inner (nested) loop exception, I write:</p>\n\n<pre><code> immediateExit = True\n sys.exit('CSV file corrupted 0.')\n</code></pre>\n\n<p>Then I go into the immediate continuation of the outer loop, and before anything else being executed by the code, I write:</p>\n\n<pre><code> if immediateExit:\n sys.exit('CSV file corrupted 1.')\n</code></pre>\n\n<p>Depending on the complexity, sometimes the above statement needs to be repeated also in except sections, etc.</p>\n\n<pre><code> if immediateExit:\n sys.exit('CSV file corrupted 1.5.')\n</code></pre>\n\n<p>The custom message is for my personal debugging, as well, as the numbers are for the same purpose - to see where the script really exits. </p>\n\n<pre><code>'CSV file corrupted 1.5.'\n</code></pre>\n\n<p>In my particular case I am processing a CSV file, which I do not want the software to touch, if the software detects it is corrupted. Therefore for me it is very important to exit the whole Python script immediately after detecting the possible corruption.</p>\n\n<p>And following the gradual sys.exit-ing from all the loops I manage to do it.</p>\n\n<p>Full code: (some changes were needed because it is proprietory code for internal tasks):</p>\n\n<pre><code>immediateExit = False\nstart_date = '1994.01.01'\nend_date = '1994.01.04'\nresumedDate = end_date\n\n\nend_date_in_working_days = False\nwhile not end_date_in_working_days:\n try:\n end_day_position = working_days.index(end_date)\n\n end_date_in_working_days = True\n except ValueError: # try statement from end_date in workdays check\n print(current_date_and_time())\n end_date = input('>> {} is not in the list of working days. Change the date (YYYY.MM.DD): '.format(end_date))\n print('New end date: ', end_date, '\\n')\n continue\n\n\n csv_filename = 'test.csv'\n csv_headers = 'date,rate,brand\\n' # not real headers, this is just for example\n try:\n with open(csv_filename, 'r') as file:\n print('***\\nOld file {} found. Resuming the file by re-processing the last date lines.\\nThey shall be deleted and re-processed.\\n***\\n'.format(csv_filename))\n last_line = file.readlines()[-1]\n start_date = last_line.split(',')[0] # assigning the start date to be the last like date.\n resumedDate = start_date\n\n if last_line == csv_headers:\n pass\n elif start_date not in working_days:\n print('***\\n\\n{} file might be corrupted. Erase or edit the file to continue.\\n***'.format(csv_filename))\n immediateExit = True\n sys.exit('CSV file corrupted 0.')\n else:\n start_date = last_line.split(',')[0] # assigning the start date to be the last like date.\n print('\\nLast date:', start_date)\n file.seek(0) # setting the cursor at the beginnning of the file\n lines = file.readlines() # reading the file contents into a list\n count = 0 # nr. of lines with last date\n for line in lines: #cycling through the lines of the file\n if line.split(',')[0] == start_date: # cycle for counting the lines with last date in it.\n count = count + 1\n if immediateExit:\n sys.exit('CSV file corrupted 1.')\n for iter in range(count): # removing the lines with last date\n lines.pop()\n print('\\n{} lines removed from date: {} in {} file'.format(count, start_date, csv_filename))\n\n\n\n if immediateExit:\n sys.exit('CSV file corrupted 1.2.')\n with open(csv_filename, 'w') as file:\n print('\\nFile', csv_filename, 'open for writing')\n file.writelines(lines)\n\n print('\\nRemoving', count, 'lines from', csv_filename)\n\n fileExists = True\n\n except:\n if immediateExit:\n sys.exit('CSV file corrupted 1.5.')\n with open(csv_filename, 'w') as file:\n file.write(csv_headers)\n fileExists = False\n if immediateExit:\n sys.exit('CSV file corrupted 2.')\n\n</code></pre>\n"}, {'answer_id': 70811775, 'author': 'Artyom Vancyan', 'author_id': 12755187, 'author_profile': 'https://Stackoverflow.com/users/12755187', 'pm_score': 4, 'selected': False, 'text': "<h2>Problem</h2>\n<p>In my practice, there was even a case when it was necessary to kill an entire multiprocessor application from one of those processes.</p>\n<p>The following functions work well if your application uses the only main process. But no one of the following functions didn't work in my case as the application had many other alive processes.</p>\n<ul>\n<li><code>quit()</code></li>\n<li><code>exit(0)</code></li>\n<li><code>os._exit(0)</code></li>\n<li><code>sys.exit(0)</code></li>\n<li><code>os.kill(os.getppid(), 9)</code> - where <code>os.getppid()</code> is the <strong>pid</strong> of parent process</li>\n</ul>\n<p>The last one killed the main process and itself but the rest processes were still alive.</p>\n<h2>Solution</h2>\n<p>I had to kill it by external command and finally found the solution using <code>pkill</code>.</p>\n<pre><code>import os\n\n# This can be called even in process worker and will kill\n# whole application included correlated processes as well\nos.system(f"pkill -f {os.path.basename(__file__)}")\n</code></pre>\n"}, {'answer_id': 70824754, 'author': 'ChanceMeteor515', 'author_id': 18007782, 'author_profile': 'https://Stackoverflow.com/users/18007782', 'pm_score': 1, 'selected': False, 'text': '<p>Just put at the end of your code <code>quit()</code> and that should close a python script.</p>\n'}, {'answer_id': 72902963, 'author': 'jimh', 'author_id': 3705490, 'author_profile': 'https://Stackoverflow.com/users/3705490', 'pm_score': 2, 'selected': False, 'text': '<p>In Python 3.9, you can also use: <code>raise SystemExit("Because I said so")</code>.</p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73663', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1384652/'] |
73,667 | <p>How can I start an interactive console for Perl, similar to the <code>irb</code> command for Ruby or <code>python</code> for Python?</p>
| [{'answer_id': 73685, 'author': 'Brian Phillips', 'author_id': 7230, 'author_profile': 'https://Stackoverflow.com/users/7230', 'pm_score': 3, 'selected': False, 'text': '<p><code>perl -d</code> is your friend:</p>\n\n<pre><code>% perl -de 0</code></pre>\n'}, {'answer_id': 73689, 'author': 'Clinton Pierce', 'author_id': 8173, 'author_profile': 'https://Stackoverflow.com/users/8173', 'pm_score': 4, 'selected': False, 'text': '<p>You can always just drop into the built-in debugger and run commands from there.</p>\n\n<pre><code> perl -d -e 1\n</code></pre>\n'}, {'answer_id': 73698, 'author': 'Frank Wiles', 'author_id': 12568, 'author_profile': 'https://Stackoverflow.com/users/12568', 'pm_score': 4, 'selected': False, 'text': '<p>There isn\'t an interactive console for Perl built in like Python does. You can however use the Perl Debugger to do debugging related things. You turn it on with the -d option, but you might want to check out \'man perldebug\' to learn about it.</p>\n<p>After a bit of googling, there is a separate project that implements a Perl console which you can find at\n<a href="https://web.archive.org/web/20170726140417/http://www.sukria.net/perlconsole.html" rel="nofollow noreferrer">Perl Console - Perl code interactive evaluator with completion</a>.</p>\n<p>Hope this helps!</p>\n'}, {'answer_id': 73703, 'author': 'Daniel Papasian', 'author_id': 7548, 'author_profile': 'https://Stackoverflow.com/users/7548', 'pm_score': 9, 'selected': True, 'text': '<p>You can use the perl debugger on a trivial program, like so:</p>\n\n<pre><code>perl -de1\n</code></pre>\n\n<p>Alternatively there\'s <a href="http://search.cpan.org/~sukria/perlconsole-0.4/perlconsole" rel="noreferrer"><em>Alexis Sukrieh</em>\'s Perl Console</a> application, but I haven\'t used it.</p>\n'}, {'answer_id': 73742, 'author': 'Jon Ericson', 'author_id': 1438, 'author_profile': 'https://Stackoverflow.com/users/1438', 'pm_score': 4, 'selected': False, 'text': '<p>I use the command line as a console:</p>\n\n<pre><code>$ perl -e \'print "JAPH\\n"\'\n</code></pre>\n\n<p>Then I can use my <em>bash</em> history to get back old commands. This does not preserve state, however.</p>\n\n<p>This form is most useful when you want to test "one little thing" (like when answering Perl questions). Often, I find these commands get scraped verbatim into a shell script or makefile.</p>\n'}, {'answer_id': 73765, 'author': 'shelfoo', 'author_id': 3444, 'author_profile': 'https://Stackoverflow.com/users/3444', 'pm_score': 3, 'selected': False, 'text': '<p>You could look into psh here: <a href="http://gnp.github.io/psh/" rel="noreferrer">http://gnp.github.io/psh/</a></p>\n\n<p>It\'s a full on shell (you can use it in replacement of bash for example), but uses perl syntax.. so you can create methods on the fly etc.</p>\n'}, {'answer_id': 73780, 'author': 'Michael Carman', 'author_id': 8233, 'author_profile': 'https://Stackoverflow.com/users/8233', 'pm_score': 3, 'selected': False, 'text': '<p>Perl doesn\'t have a console but the debugger can be used as one. At a command prompt, type <code>perl -de 1</code>. (The value "1" doesn\'t matter, it\'s just a valid statement that does nothing.)</p>\n<p>There are also a couple of options for a Perl shell:<br />\n<a href="https://web.archive.org/web/20120522111043/http://perldoc.perl.org/perlfaq3.html#Is-there-a-Perl-shell%3f" rel="nofollow noreferrer">Archived "perlfaq3" page which contain question "Is there Perl Shell?"</a></p>\n<p>For more information read <a href="https://perldoc.perl.org/perlfaq3" rel="nofollow noreferrer">perlfaq3</a> (current version).</p>\n'}, {'answer_id': 73868, 'author': 'runrig', 'author_id': 10415, 'author_profile': 'https://Stackoverflow.com/users/10415', 'pm_score': 1, 'selected': False, 'text': '<p>Also look for ptkdb on CPAN:\n<a href="http://search.cpan.org/search?query=ptkdb&mode=all" rel="nofollow noreferrer">http://search.cpan.org/search?query=ptkdb&mode=all</a></p>\n'}, {'answer_id': 73896, 'author': 'amoore', 'author_id': 7573, 'author_profile': 'https://Stackoverflow.com/users/7573', 'pm_score': 5, 'selected': False, 'text': '<p>I think you\'re asking about a REPL (Read, Evaluate, Print, Loop) interface to perl. There are a few ways to do this:</p>\n<ul>\n<li>Matt Trout has <a href="https://web.archive.org/web/20100921094613/http://chainsawblues.vox.com/library/post/a-perl-read-excute-print-loop-repl.html" rel="nofollow noreferrer">an article</a> that describes how to write one</li>\n<li>Adriano Ferreira <a href="https://web.archive.org/web/20150905151804/http://use.perl.org/use.perl.org/articlea9a7.html?sid=07/08/30/1729255" rel="nofollow noreferrer">has described some options</a></li>\n<li>and finally, you can hop on IRC at irc.perl.org and try out one of the eval bots in many of the popular channels. They will evaluate chunks of perl that you pass to them.</li>\n</ul>\n'}, {'answer_id': 74119, 'author': 'Dave Rolsky', 'author_id': 9832, 'author_profile': 'https://Stackoverflow.com/users/9832', 'pm_score': 6, 'selected': False, 'text': '<p>Not only did Matt Trout write an article about a REPL, he actually wrote one - <a href="http://search.cpan.org/dist/Devel-REPL" rel="noreferrer">Devel::REPL</a></p>\n\n<p>I\'ve used it a bit and it works fairly well, and it\'s under active development.</p>\n\n<p>BTW, I have no idea why someone modded down the person who mentioned using "perl -e" from the console. This isn\'t really a REPL, true, but it\'s fantastically useful, and I use it all the time.</p>\n'}, {'answer_id': 76154, 'author': 'raldi', 'author_id': 7598, 'author_profile': 'https://Stackoverflow.com/users/7598', 'pm_score': 5, 'selected': False, 'text': '<p>I wrote a script I call "psh":</p>\n\n<pre><code>#! /usr/bin/perl\n\nwhile (<>) {\n chomp;\n my $result = eval;\n print "$_ = $result\\n";\n}\n</code></pre>\n\n<p>Whatever you type in, it evaluates in Perl:</p>\n\n<pre><code>> gmtime(2**30)\ngmtime(2**30) = Sat Jan 10 13:37:04 2004\n\n> $x = \'foo\'\n$x = \'foo\' = foo\n\n> $x =~ s/o/a/g\n$x =~ s/o/a/g = 2\n\n> $x\n$x = faa\n</code></pre>\n'}, {'answer_id': 80890, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': False, 'text': '<p>re.pl from Devel::REPL</p>\n'}, {'answer_id': 80900, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>Sepia and PDE have also own REPLs (for GNU Emacs).</p>\n'}, {'answer_id': 90390, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>See also <a href="https://web.archive.org/web/20090109221511/http://blog.jrock.us/articles/Stylish%20REPL.pod" rel="nofollow noreferrer">Stylish REPL (for GNU Emacs)</a></p>\n'}, {'answer_id': 91565, 'author': 'ysth', 'author_id': 17389, 'author_profile': 'https://Stackoverflow.com/users/17389', 'pm_score': 3, 'selected': False, 'text': "<p>I always did:</p>\n\n<pre><code>rlwrap perl -wlne'eval;print$@if$@'\n</code></pre>\n\n<p>With 5.10, I've switched to:</p>\n\n<pre><code>rlwrap perl -wnE'say eval()//$@'\n</code></pre>\n\n<p>(rlwrap is optional)</p>\n"}, {'answer_id': 18843800, 'author': 'KIM Taegyoon', 'author_id': 1941928, 'author_profile': 'https://Stackoverflow.com/users/1941928', 'pm_score': 3, 'selected': False, 'text': '<p>Read-eval-print loop:</p>\n\n<pre><code>$ perl -e\'while(<>){print eval,"\\n"}\'\n</code></pre>\n'}, {'answer_id': 22840242, 'author': 'Ján Sáreník', 'author_id': 1255163, 'author_profile': 'https://Stackoverflow.com/users/1255163', 'pm_score': 5, 'selected': False, 'text': '<p>If you want history, use <a href="https://linux.die.net/man/1/rlwrap" rel="noreferrer">rlwrap</a>. This could be your <code>~/bin/ips</code> for example:</p>\n<pre><code>#!/bin/sh\necho \'This is Interactive Perl shell\'\nrlwrap -A -pgreen -S"perl> " perl -wnE\'say eval()//$@\'\n</code></pre>\n<p>And this is how it looks like:</p>\n<pre><code>$ ips\nThis is Interactive Perl shell\nperl> 2**128\n3.40282366920938e+38\nperl> \n</code></pre>\n'}, {'answer_id': 28372724, 'author': 'Eric Johnson', 'author_id': 58089, 'author_profile': 'https://Stackoverflow.com/users/58089', 'pm_score': 4, 'selected': False, 'text': '<p>There are two popular Perl REPLs.</p>\n\n<ol>\n<li><a href="https://metacpan.org/pod/Devel::REPL" rel="noreferrer">Devel::REPL</a> is great.</li>\n<li>But IMO <a href="https://metacpan.org/pod/Reply" rel="noreferrer">Reply</a> is better. </li>\n</ol>\n'}, {'answer_id': 31283257, 'author': 'mklement0', 'author_id': 45375, 'author_profile': 'https://Stackoverflow.com/users/45375', 'pm_score': 3, 'selected': False, 'text': '<p><sup>Update: I\'ve since created a downloadable REPL - see <a href="https://stackoverflow.com/a/32798002/45375">my other answer</a>.</sup></p>\n\n<p>With the benefit of hindsight:</p>\n\n<ul>\n<li>The <strong>third-party solutions</strong> mentioned among the existing answers are either <strong>cumbersome to install and/or do not work without non-trivial, non-obvious additional steps</strong> - some solutions appear to be at least half-abandoned.</li>\n<li><strong>A usable REPL needs the readline library for command-line-editing keyboard support and history support</strong> - ensuring this is a trouble spot for many third-party solutions.</li>\n<li>If you install CLI <strong><code>rlwrap</code>, which provides readline support to any command, you can combine it with a simple Perl command to create a usable REPL</strong>, and thus make do without third-party REPL solutions.\n\n<ul>\n<li>On OSX, you can install <code>rlwrap</code> via <a href="http://brew.sh" rel="nofollow noreferrer">Homebrew</a> with <code>brew install rlwrap</code>.</li>\n<li>Linux distros should offer <code>rlwrap</code> via their respective package managers; e.g., on Ubuntu, use <code>sudo apt-get install rlwrap</code>.</li>\n<li><strong>See <a href="https://stackoverflow.com/a/22840242/45375">Ján Sáreník\'s answer</a> for said combination of <code>rlwrap</code> and a Perl command.</strong></li>\n</ul></li>\n</ul>\n\n<hr>\n\n<p><strong>What you do NOT get</strong> with Ján\'s answer:</p>\n\n<ul>\n<li>auto-completion</li>\n<li>ability to enter multi-line statements</li>\n</ul>\n\n<p>The only third-party solution that offers these (with non-trivial installation + additional, non-obvious steps), is <strong><a href="https://github.com/gnp/psh" rel="nofollow noreferrer">psh</a></strong>, but:</p>\n\n<ul>\n<li><p>it hasn\'t seen activity in around 2.5 years</p></li>\n<li><p>its focus is different in that it aims to be a full-fledged <em>shell replacement</em>, and thus works like a traditional shell, which means that it doesn\'t automatically evaluate a command as a <em>Perl</em> statement, and requires an explicit output command such as <code>print</code> to print the result of an expression.</p></li>\n</ul>\n\n<hr>\n\n<p><a href="https://stackoverflow.com/a/22840242/45375">Ján Sáreník\'s answer</a> can be improved in one way:</p>\n\n<ul>\n<li>By default, it <strong>prints arrays/lists/hashtables as <em>scalars</em></strong>, i.e., only prints their <em>element count</em>, whereas it would be handy to enumerate their elements instead.</li>\n</ul>\n\n<p>If you install the <strong><code>Data::Printer</code></strong> module with <code>[sudo] cpan Data::Printer</code> as a one-time operation, you can load it into the REPL for use of the <strong><code>p()</code> function, to which you can pass lists/arrays/hashtables for enumeration.</strong></p>\n\n<p>Here\'s an <strong>alias named <code>iperl</code> with readline and <code>Data::Printer</code> support</strong>, which can you put in your POSIX-like shell\'s initialization file (e.g., <code>~/.bashrc</code>):</p>\n\n<pre><code>alias iperl=\'rlwrap -A -S "iperl> " perl -MData::Printer -wnE \'\\\'\'BEGIN { say "# Use `p @<arrayOrList>` or `p %<hashTable>` to print arrays/lists/hashtables; e.g.: `p %ENV`"; } say eval()//$@\'\\\'\n</code></pre>\n\n<p>E.g., you can then do the following to print all environment variables via hashtable <code>%ENV</code>:</p>\n\n<pre><code>$ iperl # start the REPL\niperl> p %ENV # print key-value pairs in hashtable %ENV\n</code></pre>\n\n<p>As with Ján\'s answer, the <em>scalar</em> result of an expression is <em>automatically</em> printed; e.g.:</p>\n\n<pre><code>iperl> 22 / 7 # automatically print scalar result of expression: 3.14285714285714\n</code></pre>\n'}, {'answer_id': 32798002, 'author': 'mklement0', 'author_id': 45375, 'author_profile': 'https://Stackoverflow.com/users/45375', 'pm_score': 4, 'selected': False, 'text': '<p>I\'ve created <a href="https://github.com/mklement0/perli" rel="noreferrer"><code>perli</code></a>, a <strong>Perl REPL</strong> that runs on <strong>Linux, macOS, and Windows</strong>.</p>\n\n<p>Its focus is automatic result printing, convenient documentation lookups, and easy\ninspection of regular-expression matches.<br>\nYou can see screenshots <a href="https://github.com/mklement0/perli#examples" rel="noreferrer">here</a>.</p>\n\n<p>It works <strong>stand-alone</strong> (has no dependencies other than Perl itself), but <strong>installation of <a href="https://github.com/hanslub42/rlwrap" rel="noreferrer"><code>rlwrap</code></a> is strongly recommended</strong> so as to support command-line editing, persistent command history, and tab-completion - read more <a href="https://github.com/mklement0/perli#supported-platforms-and-prerequisites" rel="noreferrer">here</a>.</p>\n\n<p><strong>Installation</strong></p>\n\n<ul>\n<li><p>If you happen to have Node.js installed:</p>\n\n<pre><code>npm install -g perli\n</code></pre></li>\n<li><p>Otherwise:</p>\n\n<ul>\n<li><p><em>Unix</em>-like platforms: Download <a href="https://raw.githubusercontent.com/mklement0/perli/stable/bin/perli" rel="noreferrer">this script</a> as <code>perli</code> to a folder in your system\'s path and make it executable with <code>chmod +x</code>.</p></li>\n<li><p><em>Windows</em>: Download the <a href="https://raw.githubusercontent.com/mklement0/perli/stable/bin/perli" rel="noreferrer">this script</a> as <code>perli.pl</code> (note the <code>.pl</code> extension) to a folder in your system\'s path.<br>\nIf you don\'t mind invoking Perli as <code>perli.pl</code>, you\'re all set.<br>\nOtherwise, create a batch file named <code>perli.cmd</code> in the same folder with the following content: <code>@%~dpn.pl %*</code>; this enables invocation as just <code>perli</code>.</p></li>\n</ul></li>\n</ul>\n'}, {'answer_id': 35815564, 'author': 'gavenkoa', 'author_id': 173149, 'author_profile': 'https://Stackoverflow.com/users/173149', 'pm_score': 2, 'selected': False, 'text': '<p>Under Debian/Ubuntu:</p>\n\n<pre><code>$ sudo apt-get install libdevel-repl-perl\n$ re.pl\n\n$ sudo apt-get install libapp-repl-perl\n$ iperl\n</code></pre>\n'}, {'answer_id': 37551820, 'author': 'Davor Cubranic', 'author_id': 552683, 'author_profile': 'https://Stackoverflow.com/users/552683', 'pm_score': 2, 'selected': False, 'text': '<p>Matt Trout\'s <a href="http://shadow.cat/blog/matt-s-trout/mstpan-17/" rel="nofollow">overview</a> lists five choices, from <code>perl -de 0</code> onwards, and he recommends <a href="https://metacpan.org/pod/Reply" rel="nofollow"><code>Reply</code></a>, if extensibility via plugins is important, or <code>tinyrepl</code> from <a href="https://metacpan.org/pod/Eval::WithLexicals" rel="nofollow"><code>Eval::WithLexicals</code></a>, for a minimal, pure-perl solution that includes readline support and lexical persistence.</p>\n'}, {'answer_id': 61923730, 'author': 'Ross Attrill', 'author_id': 556644, 'author_profile': 'https://Stackoverflow.com/users/556644', 'pm_score': 0, 'selected': False, 'text': '<p>You can do it online (like many things in life) here:</p>\n\n<p><a href="https://www.tutorialspoint.com/execute_perl_online.php" rel="nofollow noreferrer">https://www.tutorialspoint.com/execute_perl_online.php</a></p>\n'}, {'answer_id': 67925304, 'author': 'HappyFace', 'author_id': 1410221, 'author_profile': 'https://Stackoverflow.com/users/1410221', 'pm_score': 0, 'selected': False, 'text': '<p>You can use <code>org-babel</code> in <code>emacs</code>; Open an <code>org-mode</code> file, i.e., <code>tmp.org</code>, and then you can do:</p>\n<pre><code>#+begin_src perl :results output\n@a = (1,5,9);\nprint ((join ", ", @a) . "\\n");\n$b = scalar @a;\nprint "$#a, $b\\n";\nprint "$#a, " . @a . "\\n";\nprint join ", ", 1..$#a; print "\\n";\nprint join ", ", @a[0..$#a]\n#+end_src\n</code></pre>\n<p>Pressing <code>CTRL-c CTRL-c</code> evals the block:</p>\n<pre><code>#+RESULTS:\n#+begin_example\n1, 5, 9\n2, 3\n2, 3\n1, 2\n1, 5, 9\n#+end_example\n</code></pre>\n<p>I am not sure what emacs config this needs to work, but I think you can just install <a href="https://github.com/hlissner/doom-emacs" rel="nofollow noreferrer">https://github.com/hlissner/doom-emacs</a> and enable its <code>perl</code> and <code>org-mode</code> modules.</p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73667', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5475/'] |
73,674 | <p>I talked to a friend of mine and he told me that it's possible to create an image in an image editor (gimp/photoshop) and then use it as a button . He said that's the way applications that have great GUIs do it. </p>
<p>He also said that there is a file describing which parts of the image make up the button.</p>
<p>Is this possible , or is he "crazy"? :)</p>
| [{'answer_id': 73690, 'author': 'ScottStonehouse', 'author_id': 2342, 'author_profile': 'https://Stackoverflow.com/users/2342', 'pm_score': 2, 'selected': False, 'text': '<p>You can do anything, especially since you have no constraints re language, environment, etc.</p>\n'}, {'answer_id': 73697, 'author': 'Loofer', 'author_id': 5552, 'author_profile': 'https://Stackoverflow.com/users/5552', 'pm_score': 0, 'selected': False, 'text': '<p>Imagemaps I guess.\nNo seperate file describes the map, it is all part of the html document.</p>\n\n<p><a href="http://www.w3schools.com/TAGS/tag_map.asp" rel="nofollow noreferrer">http://www.w3schools.com/TAGS/tag_map.asp</a></p>\n'}, {'answer_id': 73699, 'author': 'Joel Anair', 'author_id': 7441, 'author_profile': 'https://Stackoverflow.com/users/7441', 'pm_score': 1, 'selected': False, 'text': '<p>In HTML, you could do:</p>\n\n<pre><code><input type="button" src="/path/to/image.png" />\n</code></pre>\n\n<p>Alternately, assigning an onclick event to an image causes that image to work similarly to a button:</p>\n\n<pre><code><img src="/path/to/image.png" onclick="function(){doSomething();}" />\n</code></pre>\n'}, {'answer_id': 73715, 'author': 'user12770', 'author_id': 12770, 'author_profile': 'https://Stackoverflow.com/users/12770', 'pm_score': 2, 'selected': False, 'text': '<p>No he is not crazy, you can use images on almost all GUI tools instead of buttons, they are generally an image on the button, or in some cases you can put the image on the screen and have an onclick event assigned to it.</p>\n'}, {'answer_id': 73719, 'author': 'Chris Marasti-Georg', 'author_id': 96, 'author_profile': 'https://Stackoverflow.com/users/96', 'pm_score': 3, 'selected': True, 'text': '<p>This needs to be clarified with a language of choice, etc. In general, most languages (WinForms, Java AWT/SWT, etc) have an image or background image property that allows you to use images for buttons. There are even skinning frameworks that will let you use images for all controls in an easy-to-define manner.</p>\n\n<p>If you are talking about HTML, there is a button input type that can allow an image to be used as a button for a form.</p>\n\n<p>@Vhaerun<br/>\n<a href="http://www.codeproject.com" rel="nofollow noreferrer">CodeProject</a> is a good place to find lots of skinning libraries. I used <a href="http://www.codeproject.com/KB/library/SkinCtrl.aspx" rel="nofollow noreferrer">this one</a> a long time ago. <a href="http://www.winamp.com" rel="nofollow noreferrer">Winamp</a> is a great example of a skinned application, where users can actually create their own templates to completely change the look of the application without changing code whatsoever. Actually, most media players have some sort of skinning available.</p>\n'}, {'answer_id': 73731, 'author': 'Jacob', 'author_id': 8119, 'author_profile': 'https://Stackoverflow.com/users/8119', 'pm_score': 1, 'selected': False, 'text': '<p>If you\'re talking HTML you can use <input type="image" src="myfile.png" /></p>\n\n<p>Specifications <a href="http://www.w3.org/TR/html401/interact/forms.html" rel="nofollow noreferrer">here</a></p>\n'}, {'answer_id': 73802, 'author': 'TheXenocide', 'author_id': 8543, 'author_profile': 'https://Stackoverflow.com/users/8543', 'pm_score': 2, 'selected': False, 'text': '<p>You haven\'t been very specific with your question so nobody is able to give you a definitive answer, but here\'s an attempt to do so without demeaning you:</p>\n\n<p>It\'s quite common for graphics designers (using tools like photoshop, gimp, etc.) to participate alongside developers for both desktop and web based applications. Web based applications can easily capture information about when an image is clicked and frequently people will either design the button with the text in the image file itself, or use background pictures/borders with plain text on top. There is not standard, per se, on how this is accomplished on the web, but plenty of sites serve as an example (try using Firebug with FireFox to inspect other sites and see how they do things).</p>\n\n<p>If the circumstance at hand is desktop oriented then the answer becomes much more complicated. Skinning is accomplished in many way and, depending on platforms and libraries being used, implementation specifics vary greatly. In it\'s most simple terms, most GUI frameworks (like GTK, QT, Windows Forms, Windows Presentation Foundation) include a basic picture control, and this control can usually process a "Click" event, which would allow it to function as a button, but if you want different states (pressed, disabled, etc.) you will have to invest more effort in such a thing; you also won\'t find this method suitable for replacing the rendering of all buttons in an application, but rather something you would do manually for each one, or write your own custom button control that uses your assets specifically.</p>\n\n<p>In terms of a file describing different images that combine as described in the file to override the rendering of the button this would lead me to believe you are either working with an already existent application that is skinable (like Firefox or Winamp) or that he is speaking of some specific UI toolkit. I\'m not aware of this functionality being generally available in most of the common system-level UI toolkits.</p>\n\n<p>In the future you may wish to be more specific with your questions.</p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73674', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/11234/'] |
73,684 | <p>I've just finished reading Domain Driven Design and I'm enchanted with some of the ideas covered in it. Do you know any companies that implement ubiquitous language in their projects?</p>
| [{'answer_id': 73869, 'author': 'Gilligan', 'author_id': 12356, 'author_profile': 'https://Stackoverflow.com/users/12356', 'pm_score': 3, 'selected': True, 'text': '<p>The <a href="http://tech.groups.yahoo.com/group/domaindrivendesign/" rel="nofollow noreferrer">Domain Driven Design Yahoo Group</a> may be a better place to find an answer to your question.</p>\n'}, {'answer_id': 174104, 'author': 'Audun', 'author_id': 25477, 'author_profile': 'https://Stackoverflow.com/users/25477', 'pm_score': 2, 'selected': False, 'text': '<p>The Norwegian Oil and gas company Statoil uses it.</p>\n'}, {'answer_id': 271721, 'author': 'Skeve', 'author_id': 33104, 'author_profile': 'https://Stackoverflow.com/users/33104', 'pm_score': 2, 'selected': False, 'text': '<p>This is an indirect answer. You could find such projects by looking at software development companies who apply domain-driven design practices and seeing who their clients are.</p>\n\n<p>Three such companies are:<br></p>\n\n<ol>\n<li><p><a href="http://www.domainlanguage.com/" rel="nofollow noreferrer">Domain Language</a> - at which Eric Evans works, he wrote the Domain Driven Design book</p></li>\n<li><p><a href="http://factor10.com/" rel="nofollow noreferrer">Factor10</a> - at which Jimmy Nilsson works, he wrote "Applying Domain-Driven Design and Patterns"</p></li>\n<li><p><a href="http://www.omegapoint.se/" rel="nofollow noreferrer">OmegaPoint</a> - employee Dan Bergh Johnsson has given a number of talks on DDD</p></li>\n</ol>\n'}, {'answer_id': 335318, 'author': 'mbillard', 'author_id': 810, 'author_profile': 'https://Stackoverflow.com/users/810', 'pm_score': 0, 'selected': False, 'text': '<p>The company I work for uses Domain-Driven Design to its fullest and after a few very successful projects, we\'re sticking with the design philosophy.</p>\n\n<p>The company is <a href="http://www.hintinnovation.com" rel="nofollow noreferrer">Hint Innovation</a>, we are a relatively new company so the website is not done yet, but it should be by January, you might want to check back then.</p>\n\n<p>I don\'t know of any other company that uses the Domain-Driven Design approach for all of their projects.</p>\n'}, {'answer_id': 1252024, 'author': 'Mike Valenty', 'author_id': 124839, 'author_profile': 'https://Stackoverflow.com/users/124839', 'pm_score': 0, 'selected': False, 'text': '<p>We\'ve been using DDD at <a href="http://www.earnware.com/" rel="nofollow noreferrer">Earnware Corporation</a> for the last 2 years. Since we\'ve been around for 10+ years, we employ the "anti-corruption layer" pattern quite a bit to talk to legacy systems.</p>\n\n<p>DDD means a lot of things, but it also is something you can start doing right away with the next function you write (<a href="http://www.agileatwork.com/domain-driven-design-in-the-small/" rel="nofollow noreferrer">http://www.agileatwork.com/domain-driven-design-in-the-small/</a>). It\'s about closing the gap between business concepts and your code so that your code can bend in the right spots. The patterns like <a href="http://www.agileatwork.com/unit-of-work-with-unity-and-aspnet-mvc/" rel="nofollow noreferrer">unit of work</a> and <a href="http://www.agileatwork.com/this-could-have-been-a-stored-procedure/" rel="nofollow noreferrer">specification</a> help accomplish that end result.</p>\n'}, {'answer_id': 2146807, 'author': 'GloryDev', 'author_id': 260043, 'author_profile': 'https://Stackoverflow.com/users/260043', 'pm_score': 0, 'selected': False, 'text': '<p>Chillisoft has been doing Domain Driven Design for 10 years and have more recently developed <a href="http://www.habanerolabs.com/" rel="nofollow noreferrer">Habanero</a> an Enterprise Application Developement Framework that incorporporates many of the principles of Domain Driven Design and the many lessons learnt over the years.</p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73684', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/11439/'] |
73,686 | <pre><code>#include <iostream>
using namespace std;
int main()
{
double u = 0;
double w = -u;
cout << w << endl;
return 0;
}
</code></pre>
<p>Why does this great piece of code output <code>-0</code> and not <code>0</code>, as one would expect?</p>
| [{'answer_id': 73711, 'author': 'foxxtrot', 'author_id': 10369, 'author_profile': 'https://Stackoverflow.com/users/10369', 'pm_score': 5, 'selected': True, 'text': '<p>The IEEE 754 standard for floating-point numbers has the sign bit separate from the mantissa, which allows for zero to be negative. <a href="http://en.wikipedia.org/wiki/IEEE_754" rel="nofollow noreferrer">Wikipedia</a> should be able to help explain this.</p>\n'}, {'answer_id': 73717, 'author': 'Clinton Pierce', 'author_id': 8173, 'author_profile': 'https://Stackoverflow.com/users/8173', 'pm_score': 1, 'selected': False, 'text': '<p>Because "negative zero" is a valid number!</p>\n\n<p><a href="http://en.wikipedia.org/wiki/%E2%88%920_(number)" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/%E2%88%920_(number)</a></p>\n'}, {'answer_id': 73724, 'author': 'Trent', 'author_id': 9083, 'author_profile': 'https://Stackoverflow.com/users/9083', 'pm_score': 1, 'selected': False, 'text': '<p>Take a look at this article: <a href="http://en.wikipedia.org/wiki/Floating_point" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Floating_point</a>. Note that there is a sign bit, even if the value is zero.</p>\n'}, {'answer_id': 73728, 'author': 'Doug T.', 'author_id': 8123, 'author_profile': 'https://Stackoverflow.com/users/8123', 'pm_score': 2, 'selected': False, 'text': '<p>In IEEE floating point <code>0</code> and <code>-0</code> are both distinct values, from <a href="http://steve.hollasch.net/cgindex/coding/ieeefloat.html" rel="nofollow noreferrer">here</a> under "Special Values":</p>\n\n<blockquote>\n <p>Note that -0 and +0 are distinct\n values, though they both compare as\n equal.</p>\n</blockquote>\n'}, {'answer_id': 73740, 'author': 'Drealmer', 'author_id': 12291, 'author_profile': 'https://Stackoverflow.com/users/12291', 'pm_score': 2, 'selected': False, 'text': '<p>The IEEE 754 standard for floating point arithmetic makes a distinction between <code>+0</code> and <code>-0</code>, this can be used when dealing with very small numbers rounded to zero where the sign still has an importance.</p>\n'}, {'answer_id': 73743, 'author': 'Saulius Valatka', 'author_id': 12790, 'author_profile': 'https://Stackoverflow.com/users/12790', 'pm_score': 1, 'selected': False, 'text': '<p>Because a double can indeed have values -0, +0, -infinity, +infinity and NaN, which can be a result of various interesting expressions, like 0/0.</p>\n\n<p>Look <a href="http://en.wikipedia.org/wiki/%E2%88%920_(number)" rel="nofollow noreferrer">here</a> for more information.</p>\n'}, {'answer_id': 73814, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': "<p>Because your expectations are wrong.</p>\n\n<p>IEEE requires that positive and negative zero be represented seperately.</p>\n\n<p>That is what you're seeing here.</p>\n"}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73686', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/6922/'] |
73,713 | <p>The following will cause infinite recursion on the == operator overload method</p>
<pre><code> Foo foo1 = null;
Foo foo2 = new Foo();
Assert.IsFalse(foo1 == foo2);
public static bool operator ==(Foo foo1, Foo foo2) {
if (foo1 == null) return foo2 == null;
return foo1.Equals(foo2);
}
</code></pre>
<p>How do I check for nulls?</p>
| [{'answer_id': 73729, 'author': 'Andrew Jones', 'author_id': 12767, 'author_profile': 'https://Stackoverflow.com/users/12767', 'pm_score': 4, 'selected': False, 'text': '<p>Cast to object in the overload method:</p>\n\n<pre><code>public static bool operator ==(Foo foo1, Foo foo2) {\n if ((object) foo1 == null) return (object) foo2 == null;\n return foo1.Equals(foo2);\n}\n</code></pre>\n'}, {'answer_id': 73732, 'author': 'Abe Heidebrecht', 'author_id': 9268, 'author_profile': 'https://Stackoverflow.com/users/9268', 'pm_score': 8, 'selected': True, 'text': '<p>Use <code>ReferenceEquals</code>:</p>\n\n<pre><code>Foo foo1 = null;\nFoo foo2 = new Foo();\nAssert.IsFalse(foo1 == foo2);\n\npublic static bool operator ==(Foo foo1, Foo foo2) {\n if (object.ReferenceEquals(null, foo1))\n return object.ReferenceEquals(null, foo2);\n return foo1.Equals(foo2);\n}\n</code></pre>\n'}, {'answer_id': 73744, 'author': 'Santiago Palladino', 'author_id': 12791, 'author_profile': 'https://Stackoverflow.com/users/12791', 'pm_score': 2, 'selected': False, 'text': '<p>Try <code>Object.ReferenceEquals(foo1, null)</code></p>\n\n<p>Anyway, I wouldn\'t recommend overloading the <code>==</code>operator; it should be used for comparing references, and use <code>Equals</code> for "semantic" comparisons.</p>\n'}, {'answer_id': 73840, 'author': 'Jon Adams', 'author_id': 2291, 'author_profile': 'https://Stackoverflow.com/users/2291', 'pm_score': 3, 'selected': False, 'text': '<p>Use <code><a href="http://msdn.microsoft.com/en-us/library/system.object.referenceequals(VS.80).aspx" rel="noreferrer">ReferenceEquals</a></code>. From the <a href="http://social.msdn.microsoft.com/Forums/en-US/csharplanguage/thread/472d7dfe-9233-49d1-a545-de44069614b5/#ccef9e05-d609-4f01-9027-b84ea7f6a41d" rel="noreferrer">MSDN forums</a>:</p>\n\n<pre><code>public static bool operator ==(Foo foo1, Foo foo2) {\n if (ReferenceEquals(foo1, null)) return ReferenceEquals(foo2, null);\n if (ReferenceEquals(foo2, null)) return false;\n return foo1.field1 == foo2.field2;\n}\n</code></pre>\n'}, {'answer_id': 73915, 'author': 'The Digital Gabeg', 'author_id': 12782, 'author_profile': 'https://Stackoverflow.com/users/12782', 'pm_score': -1, 'selected': False, 'text': '<p>You can try to use an object property and catch the resulting NullReferenceException. If the property you try is inherited or overridden from Object, then this works for any class.</p>\n\n<pre><code>public static bool operator ==(Foo foo1, Foo foo2)\n{\n // check if the left parameter is null\n bool LeftNull = false;\n try { Type temp = a_left.GetType(); }\n catch { LeftNull = true; }\n\n // check if the right parameter is null\n bool RightNull = false;\n try { Type temp = a_right.GetType(); }\n catch { RightNull = true; }\n\n // null checking results\n if (LeftNull && RightNull) return true;\n else if (LeftNull || RightNull) return false;\n else return foo1.field1 == foo2.field2;\n}\n</code></pre>\n'}, {'answer_id': 81750, 'author': 'Hallgrim', 'author_id': 15454, 'author_profile': 'https://Stackoverflow.com/users/15454', 'pm_score': 2, 'selected': False, 'text': '<p>If I have overridden <code>bool Equals(object obj)</code> and I want the operator <code>==</code> and <code>Foo.Equals(object obj)</code> to return the same value, I usually implement the <code>!=</code> operator like this:</p>\n<pre><code>public static bool operator ==(Foo foo1, Foo foo2) {\n return object.Equals(foo1, foo2);\n}\npublic static bool operator !=(Foo foo1, Foo foo2) {\n return !object.Equals(foo1, foo2);\n}\n</code></pre>\n<p>The operator <code>==</code> will then after doing all the null checks for me end up calling <code>foo1.Equals(foo2)</code> that I have overridden to do the actual check if the two are equal.</p>\n'}, {'answer_id': 13899647, 'author': 'nawfal', 'author_id': 661933, 'author_profile': 'https://Stackoverflow.com/users/661933', 'pm_score': 1, 'selected': False, 'text': '<p>My approach is to do </p>\n\n<pre><code>(object)item == null\n</code></pre>\n\n<p>upon which I\'m relying on <code>object</code>\'s own equality operator which can\'t go wrong. Or a custom extension method (and an overload):</p>\n\n<pre><code>public static bool IsNull<T>(this T obj) where T : class\n{\n return (object)obj == null;\n}\n\npublic static bool IsNull<T>(this T? obj) where T : struct\n{\n return !obj.HasValue;\n}\n</code></pre>\n\n<p>or to handle more cases, may be:</p>\n\n<pre><code>public static bool IsNull<T>(this T obj) where T : class\n{\n return (object)obj == null || obj == DBNull.Value;\n}\n</code></pre>\n\n<p>The constraint prevents <code>IsNull</code> on value types. Now its as sweet as calling</p>\n\n<pre><code>object obj = new object();\nGuid? guid = null; \nbool b = obj.IsNull(); // false\nb = guid.IsNull(); // true\n2.IsNull(); // error\n</code></pre>\n\n<p>which means I have one consistent/not-error-prone style of checking for nulls throughout. I also have found <a href="https://stackoverflow.com/a/13899726/661933"><code>(object)item == null</code> is very very very slightly faster than <code>Object.ReferenceEquals(item, null)</code></a>, but only if it matters (I\'m currently working on something where I\'ve to micro-optimize everything!).</p>\n\n<p>To see a complete guide on implementing equality checks, see <a href="https://stackoverflow.com/questions/104158/what-is-best-practice-for-comparing-two-instances-of-a-reference-type">What is "Best Practice" For Comparing Two Instances of a Reference Type?</a></p>\n'}, {'answer_id': 40109060, 'author': 'Basheer AL-MOMANI', 'author_id': 4251431, 'author_profile': 'https://Stackoverflow.com/users/4251431', 'pm_score': -1, 'selected': False, 'text': '<blockquote>\n <p>A common error in overloads of operator == is to use <code>(a == b)</code>, <code>(a ==null)</code>, or <code>(b == null)</code> to check for reference equality. This instead\n <strong>results in</strong> a call to the overloaded operator ==, causing an <code>infinite loop</code>. Use <code>ReferenceEquals</code> or cast the type to Object, to avoid the\n loop.</p>\n</blockquote>\n\n<p>check out this</p>\n\n<pre><code>// If both are null, or both are same instance, return true.\nif (System.Object.ReferenceEquals(a, b))// using ReferenceEquals\n{\n return true;\n}\n\n// If one is null, but not both, return false.\nif (((object)a == null) || ((object)b == null))// using casting the type to Object\n{\n return false;\n}\n</code></pre>\n\n<p>reference <a href="https://msdn.microsoft.com/ru-ru/library/ms173147(v=vs.80).aspx#Anchor_1" rel="nofollow">Guidelines for Overloading Equals() and Operator ==</a></p>\n'}, {'answer_id': 44376857, 'author': 'jacekbe', 'author_id': 8116196, 'author_profile': 'https://Stackoverflow.com/users/8116196', 'pm_score': 3, 'selected': False, 'text': '<p>If you are using C# 7 or later you can use null constant pattern matching:</p>\n\n<pre><code>public static bool operator==(Foo foo1, Foo foo2)\n{\n if (foo1 is null)\n return foo2 is null;\n return foo1.Equals(foo2);\n}\n</code></pre>\n\n<p>This gives you slightly neater code than the one calling object.ReferenceEquals(foo1, null)</p>\n'}, {'answer_id': 45465996, 'author': 'Zach Posten', 'author_id': 2517147, 'author_profile': 'https://Stackoverflow.com/users/2517147', 'pm_score': 0, 'selected': False, 'text': '<p><a href="https://msdn.microsoft.com/en-us/library/w4hkze5k%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396" rel="nofollow noreferrer">The static <code>Equals(Object,\u2002Object)</code> method</a> indicates whether two objects, <code>objA</code> and <code>objB</code>, are equal. It also enables you to test objects whose value is <code>null</code> for equality. It compares <code>objA</code> and <code>objB</code> for equality as follows:</p>\n\n<ul>\n<li>It determines whether the two objects represent the same object reference. If they do, the method returns <code>true</code>. This test is equivalent to calling the <code>ReferenceEquals</code> method. In addition, if both <code>objA</code> and <code>objB</code> are <code>null</code>, the method returns <code>true</code>.</li>\n<li>It determines whether either <code>objA</code> or <code>objB</code> is <code>null</code>. If so, it returns <code>false</code>.\nIf the two objects do not represent the same object reference and neither is <code>null</code>, it calls <code>objA.Equals(objB)</code> and returns the result. This means that if <code>objA</code> overrides the <code>Object.Equals(Object)</code> method, this override is called.</li>\n</ul>\n\n<p>.</p>\n\n<pre><code>public static bool operator ==(Foo objA, Foo objB) {\n return Object.Equals(objA, objB);\n}\n</code></pre>\n'}, {'answer_id': 51354894, 'author': 'CCondron', 'author_id': 602408, 'author_profile': 'https://Stackoverflow.com/users/602408', 'pm_score': 0, 'selected': False, 'text': '<p>replying more to <a href="https://stackoverflow.com/questions/4219261/overriding-operator-how-to-compare-to-null">overriding operator how to compare to null</a> that redirects here as a duplicate.</p>\n\n<p>In the cases where this is being done to support Value Objects, I find the new notation to handy, and like to ensure there is only one place where the comparison is made. Also leveraging Object.Equals(A, B) simplifies the null checks.</p>\n\n<p>This will overload ==, !=, Equals, and GetHashCode</p>\n\n<pre><code> public static bool operator !=(ValueObject self, ValueObject other) => !Equals(self, other);\n public static bool operator ==(ValueObject self, ValueObject other) => Equals(self, other);\n public override bool Equals(object other) => Equals(other as ValueObject );\n public bool Equals(ValueObject other) {\n return !(other is null) && \n // Value comparisons\n _value == other._value;\n }\n public override int GetHashCode() => _value.GetHashCode();\n</code></pre>\n\n<p>For more complicated objects add additional comparisons in Equals and a richer GetHashCode.</p>\n'}, {'answer_id': 54576557, 'author': 'Reto Messerli', 'author_id': 9697734, 'author_profile': 'https://Stackoverflow.com/users/9697734', 'pm_score': 2, 'selected': False, 'text': "<p>There is actually a simpler way of checking against <code>null</code> in this case:</p>\n\n<pre><code>if (foo is null)\n</code></pre>\n\n<p>That's it! </p>\n\n<p>This feature was introduced in C# 7</p>\n"}, {'answer_id': 58195524, 'author': 'mr5', 'author_id': 2304737, 'author_profile': 'https://Stackoverflow.com/users/2304737', 'pm_score': 0, 'selected': False, 'text': '<p>For a modern and condensed syntax:</p>\n\n<pre><code>public static bool operator ==(Foo x, Foo y)\n{\n return x is null ? y is null : x.Equals(y);\n}\n\npublic static bool operator !=(Foo x, Foo y)\n{\n return x is null ? !(y is null) : !x.Equals(y);\n}\n</code></pre>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73713', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12767/'] |
73,736 | <p>There are <a href="http://java-source.net/open-source/web-frameworks" rel="noreferrer">zillions</a> of Java web application frameworks.</p>
<p>95% were designed before the modern era of AJAX/DHTML-based development, and that means these new methods are grafted on rather than designed in.</p>
<p>Has any framework been built from the ground up with e.g. <a href="http://extjs.com/products/gxt/" rel="noreferrer">GWT + Extjs</a> in mind?</p>
<p>If not, which framework has adapted best to the world of forms with dynamic numbers of fields and pages that morph client-side?</p>
| [{'answer_id': 73823, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>I use JSF and <a href="http://www.icefaces.org" rel="nofollow noreferrer">IceFaces</a>. Although JSF has a few limitations, IceFaces seems to work pretty well and has ironed out a few of the problems with JSF.</p>\n\n<p>I haven\'t used a really good AJAX Java framework as yet, although <a href="http://echo.nextapp.com/site/" rel="nofollow noreferrer">Echo2</a> looks interesting.</p>\n'}, {'answer_id': 73837, 'author': 'ScArcher2', 'author_id': 1310, 'author_profile': 'https://Stackoverflow.com/users/1310', 'pm_score': 2, 'selected': False, 'text': '<p>I like the <a href="http://www.stripesframework.org/" rel="nofollow noreferrer">stripes framework</a>. It lets you use whatever javascript toolkit you want.</p>\n\n<p>Here is their documentation on <a href="http://www.stripesframework.org/display/stripes/AJAX" rel="nofollow noreferrer">AJAX</a></p>\n'}, {'answer_id': 73870, 'author': 'Aidos', 'author_id': 12040, 'author_profile': 'https://Stackoverflow.com/users/12040', 'pm_score': 1, 'selected': False, 'text': '<p>I like the combination of JBoss Seam and Richfaces, especially with the JBoss tools that are extentions to Eclipse - makes building these sort of RIA\'s incredibly easy.</p>\n\n<p>Wikipedia contains some useful comparisons:</p>\n\n<p><a href="http://en.wikipedia.org/wiki/Comparison_of_JavaScript_frameworks" rel="nofollow noreferrer">Comparison of JavaScript frameworks</a>\n<a href="http://en.wikipedia.org/wiki/List_of_Ajax_frameworks" rel="nofollow noreferrer">List of AJAX Frameworks</a></p>\n\n<p>Your choice depends on several different factors including whether you want the "work" done client-side (most javascript frameworks) or server-side (echo2 etc.). Other things worth looking at are tools like OpenLaszlo that provide Flash (I think) out of the box, but drop back to DHTML if there is no Flash player present.</p>\n\n<p>Unfortunately I think the decision comes down to balancing several competing cocerns. Check out the comparisons and try them out - most come with online demo\'s for you to try.</p>\n'}, {'answer_id': 73914, 'author': 'Steve g', 'author_id': 12092, 'author_profile': 'https://Stackoverflow.com/users/12092', 'pm_score': 3, 'selected': False, 'text': '<p>If you\'re starting from scratch. I\'d have to say <a href="http://code.google.com/webtoolkit/" rel="noreferrer">Google Web Toolkit</a>. I have to say it is incredibly powerful. You get keep using most of your Java tools. Plus, you don\'t have to duplicate code that exists on both the server and the client, it just gets compiled differently for each area.</p>\n'}, {'answer_id': 74123, 'author': 'Tim Howland', 'author_id': 4276, 'author_profile': 'https://Stackoverflow.com/users/4276', 'pm_score': 3, 'selected': False, 'text': '<p>I\'d consider REST-style frameworks as well as the other recommendations here- <a href="http://restlet.org" rel="noreferrer">Restlet</a> or <a href="http://jersey.java.net/" rel="noreferrer">Jersey</a> may be good choices for the backend, while you use something like JQuery or GWT on the front end. Both frameworks can easily produce JSON, and the REST style provides a nice clean line of demarcation between your client application and your server source; I find that JSF can make that demarcation pretty muddy.</p>\n'}, {'answer_id': 75834, 'author': 'zmf', 'author_id': 13285, 'author_profile': 'https://Stackoverflow.com/users/13285', 'pm_score': 2, 'selected': False, 'text': '<p><a href="http://directwebremoting.org/" rel="nofollow noreferrer">DWR</a></p>\n\n<p>I use this to dynamically populate drop downs, and even filter them on the fly based on user input in other places on the form.</p>\n'}, {'answer_id': 82783, 'author': 'user14636', 'author_id': 14636, 'author_profile': 'https://Stackoverflow.com/users/14636', 'pm_score': 2, 'selected': False, 'text': '<p>GWT is quite powerful and easy to use (all Java, no Javascript/HTML/CSS coding). If Google has their way it will be a dominant framework/tool in web applications development, and for good reason. It already works with Google Gears (which allows offline access to web apps) - and more than likely will be optimized to work within Google Chrome.</p>\n'}, {'answer_id': 90615, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': False, 'text': "<p>Echo2 / Echo3 by Nextapp (www.nextapp.com) is totally awesome.</p>\n\n<p>Advantages over GWT:</p>\n\n<p>1) It is not limited to a sub-set of java like GWT\n2) It is easier (in my estimation) to learn\n3) Has extremely robust design studio for almost drag and drop designing.<br>\n4) It is very fast, and works very well on all platforms browsers\n5) You can write your application using either java script or java\n6) It has great and straight forward methods for handling events and actions.</p>\n\n<p>Personally I think that for any web-application in which you are trying to integrate java and speedy delivery I wouldn't hesitate to pick Echo3 or Echo2. </p>\n"}, {'answer_id': 814675, 'author': 'David Robbins', 'author_id': 19799, 'author_profile': 'https://Stackoverflow.com/users/19799', 'pm_score': 1, 'selected': False, 'text': '<p><a href="http://www.aptana.com" rel="nofollow noreferrer">Aptana</a> has a server side frame work called <a href="http://www.aptana.com/jaxer" rel="nofollow noreferrer">Jaxer</a>. This is from their site:</p>\n\n<blockquote>\n <p>Jaxer\'s core engine is based on the same Mozilla engine that you\'ll find in the popular Mozilla Firefox browser. This means that the execution environment you use on both the client and the server are the same. It\'s Ajax all the way through and through. That means you only need one set of languages -- the languages that are native to the browser -- to create entire applications.</p>\n</blockquote>\n\n<p>This framework is open source and has a very nice IDE based on Eclipse. Aptana is also working on a Javascript implementation for ActiveRecord called <a href="http://activerecordjs.org/" rel="nofollow noreferrer">ActiveRecordJS</a>. Potentially you could use this both client and server side with their framework.</p>\n'}, {'answer_id': 46215447, 'author': 'Kushal Jain', 'author_id': 2530851, 'author_profile': 'https://Stackoverflow.com/users/2530851', 'pm_score': 0, 'selected': False, 'text': '<p>GWT is one of the best AJAX framework that I used ever. Most important thing about this framework is that its maintained by Google. And Everyone know "Who is Google ?"</p>\n\n<pre><code>GWT is used by many products at Google, including Google AdWords and Google\nWallet. It\'s open source, completely free, and used by thousands of \nenthusiastic developers around the world.\n</code></pre>\n\n<p>GWT provide rich widgets that can be used to built any application. Almost all the widgets they have.</p>\n\n<p>Another important point is GWT is continuously developing and its also have stable release which is very good thing. Another thing Google has also released GWT-Material which is again a very good thing because everyone is moving toward material.</p>\n\n<p>I hope this will help you!!!</p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73736', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4926/'] |
73,745 | <p>I'm curious about keeping source code around reliably and securely for several years. From my research/experience:</p>
<ol>
<li><p>Optical media, such as burned DVD-R's lose bits of data over time. After a couple years, I don't get all the files off that I put on them. Read errors, etc.</p></li>
<li><p>Hard drives are mechanical and subject to failure/obsolescence with expensive data recovery fees, that hardly keep your data private (you send it away to some company).</p></li>
<li><p>Magnetic tape storage: see #2.</p></li>
<li><p>Online storage is subject to the whim of some data storage center, the security or lack of security there, and the possibility that the company folds, etc. Plus it's expensive, and you can't guarantee that they aren't peeking in.</p></li>
</ol>
<p>I've found over time that I've lost source code to old projects I've done due to these problems. Are there any other solutions?</p>
<p><em>Summary of answers:</em><br>
1. Use multiple methods for redundancy.<br>
2. Print out your source code either as text or barcode.<br>
3. RAID arrays are better for local storage.<br>
4. Open sourcing your project will make it last forever.<br>
5. Encryption is the answer to security.<br>
6. Magnetic tape storage is durable.<br>
7. Distributed/guaranteed online storage is cheap and reliable.<br>
8. Use source control to maintain history, and backup the repo.</p>
| [{'answer_id': 73758, 'author': 'Chris Upchurch', 'author_id': 2600, 'author_profile': 'https://Stackoverflow.com/users/2600', 'pm_score': 2, 'selected': False, 'text': '<p>Any data you want to keep should be stored in multiple places on multiple formats. While the odds of any one failing may be significant, the odds of all of them failing are pretty small.</p>\n'}, {'answer_id': 73768, 'author': 'Alex Fort', 'author_id': 12624, 'author_profile': 'https://Stackoverflow.com/users/12624', 'pm_score': 2, 'selected': False, 'text': "<p>If you want to archive something for a long time, I would go with a tape drive. They may not hold a whole lot, but they are reliable and pretty much the storage medium of choice for data archiving. I've never personally experienced dataloss on a tape drive, however.</p>\n"}, {'answer_id': 73771, 'author': 'deemer', 'author_id': 11192, 'author_profile': 'https://Stackoverflow.com/users/11192', 'pm_score': 3, 'selected': False, 'text': "<p>Based on your level of paranoia, I'd recommend a printer and a safe.</p>\n\n<p>More seriously, a RAID array isn't so expensive anymore, and so long as you continue to use and monitor it, a properly set-up array is virtually guaranteed never to lose data.</p>\n"}, {'answer_id': 73777, 'author': 'Frank Wiles', 'author_id': 12568, 'author_profile': 'https://Stackoverflow.com/users/12568', 'pm_score': 4, 'selected': True, 'text': '<p>The best answer is "in multiple places". If I were concerned about keeping my source code for as long as possible I would do: </p>\n\n<p>1) Backup to some optical media on a regular basis, say burn it to DVD once a month and archive it offsite. </p>\n\n<p>2) Back it up to multiple hard drives on my local machines </p>\n\n<p>3) Back it up to Amazon\'s S3 service. They have guarantees, it\'s a distributed system so no single points of failure and you can easily encrypt your data so they can\'t "peek" at it. </p>\n\n<p>With those three steps your chances of losing data are effectively zero. There is no such thing as too many backups for VERY important data. </p>\n'}, {'answer_id': 73788, 'author': 'Vinko Vrsalovic', 'author_id': 5190, 'author_profile': 'https://Stackoverflow.com/users/5190', 'pm_score': 2, 'selected': False, 'text': '<p>The best way to back up your projects is to make them open source and famous. That way there will always be people with a copy of it and able to send it to you.</p>\n\n<p>After that, just care of the magnetic/optical media, continued renewal of it and multiple copies (online as well, remember you can encrypt it) on multiple media (including, why not, RAID sets)</p>\n'}, {'answer_id': 73789, 'author': 'Jan Krüger', 'author_id': 12471, 'author_profile': 'https://Stackoverflow.com/users/12471', 'pm_score': 0, 'selected': False, 'text': '<p>One way would be to periodically recycle your storage media, i.e. read data off the decaying medium and write it to a fresh one. There exist programs to assist you with this, e.g. <a href="http://www.dvdisaster.com/" rel="nofollow noreferrer">dvdisaster</a>. In the end, nothing lasts forever. Just pick the least annoying solution.</p>\n\n<p>As for #2: you can store data in encrypted form to prevent data recovery experts from making sense of it.</p>\n'}, {'answer_id': 73790, 'author': 'Gilligan', 'author_id': 12356, 'author_profile': 'https://Stackoverflow.com/users/12356', 'pm_score': 0, 'selected': False, 'text': '<p>I think Option 2 works well enough if you have the write backup mechanisms in place. They need not be expensive ones involving a third-party, either (except for disaster recovery).\nA RAID 5 configured server would do the trick. If a hard drive fails, replace it. It is HIGHLY unlikely that all the hard drives will fail at the same time. Even a mirrored RAID 1 drive would be good enough in some cases.</p>\n\n<p>If option 2 still seems like a crappy solution, the only other thing I can think of is to print out hard-copies of the source code, which has many more problems than any of the above solutions. </p>\n'}, {'answer_id': 73796, 'author': 'Flint', 'author_id': 11877, 'author_profile': 'https://Stackoverflow.com/users/11877', 'pm_score': 0, 'selected': False, 'text': '<blockquote>\n <p>Online storage is subject to the whim of some data storage center, the security or lack of security there, and the possibility that the company folds, etc. Plus it\'s expensive,</p>\n</blockquote>\n\n<p>Not necessarily expensive (see <a href="http://www.rsync.net/" rel="nofollow noreferrer">rsync.net</a> for example), nor insecure. You can certainly encrypt your stuff too.</p>\n\n<blockquote>\n <p>and you can\'t guarantee that they aren\'t peeking in.</p>\n</blockquote>\n\n<p>True, but there\'s probably much more interesting stuff to peek at than your source-code. ;-)</p>\n\n<blockquote>\n <p>More seriously, a RAID array isn\'t so expensive anymore</p>\n</blockquote>\n\n<p>RAID is <em>not</em> backup.</p>\n'}, {'answer_id': 73808, 'author': 'pjz', 'author_id': 8002, 'author_profile': 'https://Stackoverflow.com/users/8002', 'pm_score': 1, 'selected': False, 'text': "<p>The best home-usable solution I've seen was printing out the backups using a 2D barcode - the data density was fairly high, it could be re-scanned fairly easily (presuming a sheet-feeding scanner), and it moved the problem from the digital domain back into the physical one - which is fairly easily met by something like a safe deposit box, or a company like Iron Mountain.</p>\n\n<p>The other answer is 'all of the above'. Redundancy always helps. </p>\n"}, {'answer_id': 73815, 'author': 'Jordan Mack', 'author_id': 9979, 'author_profile': 'https://Stackoverflow.com/users/9979', 'pm_score': 1, 'selected': False, 'text': '<p>For my projects, I use a combination of 1, 2, & 4. If it\'s really important data, you need to have multiple copies in multiple places. My important data is replicated to 3-4 locations every night.</p>\n\n<p>If you want a simpler solution, I recommend you get an online storage account from a well known provider which has an insured reliability guarantee. If you are worried about security, only upload data inside <a href="http://www.truecrypt.org/" rel="nofollow noreferrer">TrueCrypt</a> encrypted archives. As far as cost, it will probably be pricey... But if it\'s really that important the cost is nothing.</p>\n'}, {'answer_id': 73872, 'author': 'Adam Hopkinson', 'author_id': 12280, 'author_profile': 'https://Stackoverflow.com/users/12280', 'pm_score': 2, 'selected': False, 'text': '<p>I think you\'d be surprised how reasonably priced online storage is these days. Amazon S3 (simple storage solution) is $0.10 per gigabyte per month, with upload costs of $0.10 per GB and download costing $0.17 per GB maximum.</p>\n\n<p>Therefore, if you stored 20GB for a month, uploaded 20GB and downloaded 20GB it would cost you $8.40 (slightly more expensive in the European data center at $9).</p>\n\n<p>That\'s cheap enough to store your data in both US and EU data centers AND on dvd - the chances of losing all three are slim, to say the least.</p>\n\n<p>There are also front-ends available, such as JungleDisk.</p>\n\n<p><a href="http://aws.amazon.com" rel="nofollow noreferrer">http://aws.amazon.com</a><br>\n<a href="http://www.jungledisk.com/" rel="nofollow noreferrer">http://www.jungledisk.com/</a><br>\n<a href="http://www.google.co.uk/search?q=amazon%20s3%20clients" rel="nofollow noreferrer">http://www.google.co.uk/search?q=amazon%20s3%20clients</a></p>\n'}, {'answer_id': 73952, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>For regulatory mandated archival of electronic data, we keep the data on a RAID and on backup tapes in two separate locations (one of which is Iron Mountain). We also replace the tapes and RAID every few years.</p>\n'}, {'answer_id': 74627, 'author': 'skamradt', 'author_id': 9217, 'author_profile': 'https://Stackoverflow.com/users/9217', 'pm_score': 1, 'selected': False, 'text': '<p>If you need to keep it "forever" probably the safest way is to print out the code and stick that in a plastic envelope to keep it safe from the elements. I can\'t tell you how much code I\'ve lost to a backup means which are no longer reachable.... I don\'t have a paper card reader to read my old cobol deck, no drive for my 5 1/4" floppies, or my 3 1/2" floppies. but yet the print out that I made of my first big project still sits readable...even after my once 3 year old decided that it would make a good coloring book.</p>\n'}, {'answer_id': 74732, 'author': 'Tim', 'author_id': 387361, 'author_profile': 'https://Stackoverflow.com/users/387361', 'pm_score': 0, 'selected': False, 'text': "<p>I was just talking with a guy who is an expert in microfilm. While it is an old technology, for long term storage it is one of the most enduring forms of data storage if properly maintained. It doesn't require sophisticated equipment (magifying lens and a light) to read altough storing it may take some work.</p>\n\n<p>Then again, as was previously mentioned, if you are only talking in the spans of a few years instead of decades printing it off to paper and storing it in a controlled environment is probable the best way. If you want to get really creative you could laminate every sheet!</p>\n"}, {'answer_id': 74758, 'author': 'icelava', 'author_id': 2663, 'author_profile': 'https://Stackoverflow.com/users/2663', 'pm_score': 1, 'selected': False, 'text': '<p>When you state "back up source code", I hope you include in your meaning the backing up of your version control system too.</p>\n\n<p>Backing your current source code (to multiple places) is definitely critical, but backing up your history of changes as preseved by your VCS is paramount in my opinion. It may seem trivial especially when we are always "living in the present, looking towards the future". However, there have been way too many times when we have wanted to look backward to investigate an issue, review the chain of changes, see who did what, whether we can rollback to a previous build/version. All the more important if you practise heavy branching and merging. Archiving a single trunk <em>will not do</em>.</p>\n\n<p>Your version control system may come with documentation and suggestions on backup strategies.</p>\n'}, {'answer_id': 74792, 'author': 'Sleep Deprivation Ninja', 'author_id': 13002, 'author_profile': 'https://Stackoverflow.com/users/13002', 'pm_score': 2, 'selected': False, 'text': '<p>Don\'t forget to use Subversion (<a href="http://subversion.tigris.org/" rel="nofollow noreferrer">http://subversion.tigris.org/</a>). I subversion my whole life (it\'s awesome).</p>\n'}, {'answer_id': 77253, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>Drobo for local backup</p>\n\n<p>DVD for short-term local archiving </p>\n\n<p>Amazon S3 for off-site,long-term archiving</p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73745', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1892/'] |
73,748 | <p>I have a dropdownlist with the autopostback set to true. I want the
user to confirm if they really want to change the value,
which on post back fires a server side event (selectedindexchanged).</p>
<p>I have tried adding an onchange attribute "return confirm('Please click OK to change. Otherwise click CANCEL?';") but it will not postback regardless of the confirm
result and the value in the list does not revert back if cancel
selected. </p>
<p>When I remove the onchange attribute from the DropdownList tag, the page does postback. It does not when the onchange attribute is added. Do I still need to wire the event handler (I'm on C# .Net 2.0 ).</p>
<p>Any leads will be helpful.</p>
<p>Thanks!</p>
| [{'answer_id': 73860, 'author': 'Brian Liang', 'author_id': 5853, 'author_profile': 'https://Stackoverflow.com/users/5853', 'pm_score': 0, 'selected': False, 'text': '<p>Make sure your event is wired:</p>\n\n<pre><code>dropDown.SelectedIndexChanged += new EventHandler(dropDown_SelectedIndexChanged);\n</code></pre>\n\n<p>You can also apply a client-side attribute to return the confirmation. Set the index accordingly if cancelled.</p>\n\n<pre><code>dropDown.Attributes.Add("onchange", "javascript: return confirm(\'confirmation msg\')");\n</code></pre>\n'}, {'answer_id': 74027, 'author': 'Craig', 'author_id': 2047, 'author_profile': 'https://Stackoverflow.com/users/2047', 'pm_score': 3, 'selected': False, 'text': '<p>You can utilize the the CustomValidator control to "validate" dropdown by calling a javascript function in which you do the confirm():</p>\n\n<pre><code> <asp:DropDownList ID="TestDropDown" runat="server" AutoPostBack="true" CausesValidation="true"\n ValidationGroup="Group1"\n OnSelectedIndexChanged="TestDropDown_SelectedIndexChanged">\n <asp:ListItem Value="1" Text="One" />\n <asp:ListItem Value="2" Text="Two" />\n </asp:DropDownList>\n <script type="text/javascript">\n function ConfirmDropDownValueChange(source, arguments) {\n arguments.IsValid = confirm("Are you sure?");\n }\n </script>\n <asp:CustomValidator ID="ConfirmDropDownValidator" runat="server"\n ClientValidationFunction="ConfirmDropDownValueChange" Display="Dynamic" ValidationGroup="Group1" />\n</code></pre>\n'}, {'answer_id': 74251, 'author': 'Kyle B.', 'author_id': 6158, 'author_profile': 'https://Stackoverflow.com/users/6158', 'pm_score': 4, 'selected': True, 'text': '<p>Have you tried to set the onChange event to a javascript function and then inside the function display the javascript alert and utilize the __doPostback function if it passes?</p>\n\n<p>i.e.</p>\n\n<pre><code> \ndrpControl.Attributes("onChange") = "DisplayConfirmation();"\n\nfunction DisplayConfirmation() {\n if (confirm(\'Are you sure you want to do this?\')) {\n __doPostback(\'drpControl\',\'\');\n }\n}\n</code></pre>\n'}, {'answer_id': 74289, 'author': 'Billy Jo', 'author_id': 3447, 'author_profile': 'https://Stackoverflow.com/users/3447', 'pm_score': 1, 'selected': False, 'text': "<p>Currently, you're always returning the result of the <code>confirm()</code>, so even if it returns <code>true</code>, you'll still stop execution of the event before the postback can fire. Your <code>onchange</code> should <code>return false;</code> only when the <code>confirm()</code> does, too, like this:</p>\n\n<pre><code>if (!confirm('Please click OK to change. Otherwise click CANCEL?')) return false;\n</code></pre>\n"}, {'answer_id': 74444, 'author': 'Craig', 'author_id': 2047, 'author_profile': 'https://Stackoverflow.com/users/2047', 'pm_score': 1, 'selected': False, 'text': '<p>Overriding the onchange attribute will not work if you have have AutoPostBack set to true because ASP.NET will always append the following to the end of your onchange script:</p>\n\n<pre><code>;setTimeout(\'__doPostBack(\\\'YourDropDown\\\',\\\'\\\')\', 0)\n</code></pre>\n\n<p>If you set AutoPostBack to false, then overriding onchange with a "confirm and __doPostBack" type script (see above, err.. below) will work but you may have to manually create the __doPostBack function.</p>\n'}, {'answer_id': 2695583, 'author': 'JCallico', 'author_id': 143195, 'author_profile': 'https://Stackoverflow.com/users/143195', 'pm_score': 3, 'selected': False, 'text': '<p>The following works when the DropDownList is triggering partial postbacks:</p>\n\n<pre><code>// caching selected value at the time the control is clicked\nMyDropDownList.Attributes.Add(\n "onclick",\n "this.currentvalue = this.value;");\n\n// if the user chooses not to continue then restoring cached value and aborting by returning false\nMyDropDownList.Attributes.Add(\n "onchange",\n "if (!confirm(\'Do you want to continue?\')) {this.value = this.currentvalue; return false};");\n</code></pre>\n'}, {'answer_id': 3301127, 'author': 'NealB', 'author_id': 41114, 'author_profile': 'https://Stackoverflow.com/users/41114', 'pm_score': 1, 'selected': False, 'text': "<pre><code>if (!confirm('Please click OK to change. Otherwise click CANCEL?')) return false;\n</code></pre>\n\n<p>Always returns so dropdownlist's OnSelectedIndexChanged event fires whether user clicks OK or CANCEL.</p>\n"}, {'answer_id': 16061689, 'author': 'shailendra sharma', 'author_id': 2290912, 'author_profile': 'https://Stackoverflow.com/users/2290912', 'pm_score': 0, 'selected': False, 'text': '<pre><code>&lt;asp:DropDownList runat="server" ID="ddlShailendra" AutoPostBack="True" OnSelectedIndexChanged="ddlShailendra_SelectedIndexChanged" onchange="javascript: { if(confirm(\'Click ok to prevent post back, Cancel to make a postback\'))return true;} " &gt;\n &lt;asp:ListItem Text="tes" Value="1" >&lt;/asp:ListItem&gt;\n &lt;asp:ListItem Text="test" Value="-1"&gt;&lt;/asp:ListItem&gt;\n &lt;/asp:DropDownList&gt;\n</code></pre>\n\n<p>Write the function inline and dont have a "return" for the condition in which you want a post back. This works and is as per the standards.</p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73748', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/262613/'] |
73,751 | <p>I've heard people referring to this table and was not sure what it was about.</p>
| [{'answer_id': 73760, 'author': 'Jorge Ferreira', 'author_id': 6508, 'author_profile': 'https://Stackoverflow.com/users/6508', 'pm_score': 5, 'selected': False, 'text': '<p>I think this wikipedia article may help clarify.</p>\n\n<p><a href="http://en.wikipedia.org/wiki/DUAL_table" rel="noreferrer">http://en.wikipedia.org/wiki/DUAL_table</a></p>\n\n<blockquote>\n <p>The DUAL table is a special one-row\n table present by default in all Oracle\n database installations. It is suitable\n for use in selecting a pseudocolumn\n such as SYSDATE or USER The table has\n a single VARCHAR2(1) column called\n DUMMY that has a value of "X"</p>\n</blockquote>\n'}, {'answer_id': 73767, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': False, 'text': '<p>Kind of a pseudo table you can run commands against and get back results, such as sysdate. Also helps you to check if Oracle is up and check sql syntax, etc.</p>\n'}, {'answer_id': 73772, 'author': 'Sean McMains', 'author_id': 2041950, 'author_profile': 'https://Stackoverflow.com/users/2041950', 'pm_score': 9, 'selected': True, 'text': '<p>It\'s a sort of dummy table with a single record used for selecting when you\'re not actually interested in the data, but instead want the results of some system function in a select statement:</p>\n<p>e.g. <code>select sysdate from dual;</code></p>\n<p>See <a href="http://www.adp-gmbh.ch/ora/misc/dual.html" rel="nofollow noreferrer">http://www.adp-gmbh.ch/ora/misc/dual.html</a></p>\n<p>As of 23c, Oracle supports <code>select sysdate /* or other value */</code>, without <code>from dual</code>, as has been supported in MySQL for some time already.</p>\n'}, {'answer_id': 73787, 'author': 'Martin08', 'author_id': 8203, 'author_profile': 'https://Stackoverflow.com/users/8203', 'pm_score': 4, 'selected': False, 'text': "<p>It's the special table in Oracle. I often use it for calculations or checking system variables. For example:</p>\n\n<ul>\n<li><code>Select 2*4 from dual</code> prints out the result of the calculation</li>\n<li><code>Select sysdate from dual</code> prints the server current date. </li>\n</ul>\n"}, {'answer_id': 73793, 'author': 'mfx', 'author_id': 8015, 'author_profile': 'https://Stackoverflow.com/users/8015', 'pm_score': 7, 'selected': False, 'text': "<p>It is a dummy table with one element in it. It is useful because Oracle doesn't allow statements like</p>\n\n<pre><code> SELECT 3+4\n</code></pre>\n\n<p>You can work around this restriction by writing</p>\n\n<pre><code> SELECT 3+4 FROM DUAL\n</code></pre>\n\n<p>instead.</p>\n"}, {'answer_id': 73794, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': "<p>It's a object to put in the from that return 1 empty row. For example:\nselect 1 from dual;\nreturns 1</p>\n\n<p>select 21+44 from dual;\nreturns 65</p>\n\n<p>select [sequence].nextval from dual;\nreturns the next value from the sequence.</p>\n"}, {'answer_id': 73803, 'author': 'Sakin', 'author_id': 12818, 'author_profile': 'https://Stackoverflow.com/users/12818', 'pm_score': 2, 'selected': False, 'text': '<p>The DUAL table is a special one-row table present by default in all Oracle database installations. It is suitable for use in selecting a pseudocolumn such as SYSDATE or USER</p>\n\n<p>The table has a single VARCHAR2(1) column called DUMMY that has a value of "X"</p>\n\n<p>You can read all about it in <a href="http://en.wikipedia.org/wiki/DUAL_table" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/DUAL_table</a></p>\n'}, {'answer_id': 73816, 'author': 'Ivan Bosnic', 'author_id': 3221, 'author_profile': 'https://Stackoverflow.com/users/3221', 'pm_score': 6, 'selected': False, 'text': '<p>From <a href="http://en.wikipedia.org/wiki/DUAL_table" rel="noreferrer">Wikipedia</a></p>\n\n<p><strong>History</strong></p>\n\n<p>The DUAL table was created by Chuck Weiss of Oracle corporation to provide a table for joining in internal views:</p>\n\n<blockquote>\n <p><em>I created the DUAL table as an underlying object in the Oracle Data Dictionary. It was never meant to be seen itself, but instead used\n inside a view that was expected to be queried. The idea was that you\n could do a JOIN to the DUAL table and create two rows in the result\n for every one row in your table. Then, by using GROUP BY, the\n resulting join could be summarized to show the amount of storage for\n the DATA extent and for the INDEX extent(s). The name, DUAL, seemed\n apt for the process of creating a pair of rows from just one. <a href="http://en.wikipedia.org/wiki/DUAL_table" rel="noreferrer">1</a></em></p>\n</blockquote>\n\n<p>It may not be obvious from the above, but the original DUAL table had two rows in it (hence its name). Nowadays it only has one row.</p>\n\n<p><strong>Optimization</strong></p>\n\n<p>DUAL was originally a table and the database engine would perform disk IO on the table when selecting from DUAL. This disk IO was usually logical IO (not involving physical disk access) as the disk blocks were usually already cached in memory. This resulted in a large amount of logical IO against the DUAL table.</p>\n\n<p>Later versions of the Oracle database have been optimized and the database no longer performs physical or logical IO on the DUAL table even though the DUAL table still actually exists.</p>\n'}, {'answer_id': 73899, 'author': 'steevc', 'author_id': 1895, 'author_profile': 'https://Stackoverflow.com/users/1895', 'pm_score': 2, 'selected': False, 'text': '<p>DUAL is necessary in PL/SQL development for using functions that are only available in SQL</p>\n\n<p>e.g.</p>\n\n<pre><code>DECLARE\nx XMLTYPE;\nBEGIN\nSELECT xmlelement("hhh", \'stuff\')\nINTO x\nFROM dual;\nEND;\n</code></pre>\n'}, {'answer_id': 9077985, 'author': 'Venkataramesh Kommoju', 'author_id': 229608, 'author_profile': 'https://Stackoverflow.com/users/229608', 'pm_score': 2, 'selected': False, 'text': '<p>More Facts about the DUAL....</p>\n\n<p><a href="http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1562813956388" rel="nofollow">http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1562813956388</a></p>\n\n<p>Thrilling experiments done here, and more thrilling explanations by Tom</p>\n'}, {'answer_id': 19224594, 'author': 'AB01', 'author_id': 2568015, 'author_profile': 'https://Stackoverflow.com/users/2568015', 'pm_score': 3, 'selected': False, 'text': '<p>A utility table in Oracle with only 1 row and 1 column. It is used to perform a number of arithmetic operations and can be used generally where one needs to generate a known output.</p>\n\n<p>SELECT * FROM dual;</p>\n\n<p>will give a single row, with a single column named "DUMMY" and a value of "X" as shown here: </p>\n\n<blockquote>\n<pre><code>DUMMY\n----- \nX\n</code></pre>\n</blockquote>\n'}, {'answer_id': 25053187, 'author': 'Vishwa G', 'author_id': 3763015, 'author_profile': 'https://Stackoverflow.com/users/3763015', 'pm_score': 1, 'selected': False, 'text': "<p>DUAL we mainly used for getting the next number from the sequences.</p>\n\n<p>Syntax : SELECT 'sequence_name'.NEXTVAL FROM DUAL </p>\n\n<p>This will return the one row one column value(NEXTVAL column name).</p>\n"}, {'answer_id': 48305056, 'author': 'Newton fan 01', 'author_id': 5600260, 'author_profile': 'https://Stackoverflow.com/users/5600260', 'pm_score': 1, 'selected': False, 'text': "<p>another situation which requires <code>select ... from dual</code> is when we want to retrieve the code (data definition) for different database objects (like TABLE, FUNCTION, TRIGGER, PACKAGE), using the built in <code>DBMS_METADATA.GET_DDL</code> function:</p>\n\n<pre><code>select DBMS_METADATA.GET_DDL('TABLE','<table_name>') from DUAL;\n\nselect DBMS_METADATA.GET_DDL('FUNCTION','<function_name>') from DUAL;\n</code></pre>\n\n<p>in is true that nowadays the IDEs do offer the capability to view the DDL of a table, but in simpler environments like SQL Plus this can be really handy.</p>\n\n<p><strong>EDIT</strong></p>\n\n<p>a more general situation: basically, when we need to use any PL/SQL procedure inside a standard SQL statement, or when we want to call a procedure from the command line:</p>\n\n<pre><code>select my_function(<input_params>) from dual;\n</code></pre>\n\n<p>both recipes are taken from the book 'Oracle PL/SQL Recipes' by Josh Juneau and Matt Arena</p>\n"}, {'answer_id': 56107698, 'author': 'Manjunatha B', 'author_id': 3912972, 'author_profile': 'https://Stackoverflow.com/users/3912972', 'pm_score': 1, 'selected': False, 'text': '<p>The DUAL is special one row, one column table present by default in all Oracle databases. The owner of DUAL is SYS.</p>\n\n<p>DUAL is a table automatically created by Oracle Database along with the data functions. It is always used to get the operating systems functions(like date, time, arithmetic expression., etc.) </p>\n\n<pre><code>SELECT SYSDATE from dual; \n</code></pre>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73751', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3208/'] |
73,781 | <p>If I want to send mail not via SMTP, but rather via sendmail, is there a library for python that encapsulates this process?</p>
<p>Better yet, is there a good library that abstracts the whole 'sendmail -versus- smtp' choice?</p>
<p>I'll be running this script on a bunch of unix hosts, only some of which are listening on localhost:25; a few of these are part of embedded systems and can't be set up to accept SMTP.</p>
<p>As part of Good Practice, I'd really like to have the library take care of header injection vulnerabilities itself -- so just dumping a string to <code>popen('/usr/bin/sendmail', 'w')</code> is a little closer to the metal than I'd like.</p>
<p>If the answer is 'go write a library,' so be it ;-)</p>
| [{'answer_id': 73807, 'author': 'tovare', 'author_id': 12677, 'author_profile': 'https://Stackoverflow.com/users/12677', 'pm_score': 2, 'selected': False, 'text': '<p>It\'s quite common to just use the sendmail command from Python using os.popen</p>\n\n<p>Personally, for scripts i didn\'t write myself, I think just using the SMTP-protocol is better, since it wouldn\'t require installing say an sendmail clone to run on windows.</p>\n\n<p><a href="https://docs.python.org/library/smtplib.html" rel="nofollow noreferrer">https://docs.python.org/library/smtplib.html</a></p>\n'}, {'answer_id': 73811, 'author': 'Frank Wiles', 'author_id': 12568, 'author_profile': 'https://Stackoverflow.com/users/12568', 'pm_score': -1, 'selected': False, 'text': '<p>The easiest answer is the smtplib, you can find docs on it <a href="http://docs.python.org/lib/SMTP-example.html" rel="nofollow noreferrer">here</a>. </p>\n\n<p>All you need to do is configure your local sendmail to accept connection from localhost, which it probably already does by default. Sure, you\'re still using SMTP for the transfer, but it\'s the local sendmail, which is basically the same as using the commandline tool. </p>\n'}, {'answer_id': 73844, 'author': 'Pieter', 'author_id': 5822, 'author_profile': 'https://Stackoverflow.com/users/5822', 'pm_score': 5, 'selected': False, 'text': '<p>This is a simple python function that uses the unix sendmail to deliver a mail.</p>\n\n<pre><code>def sendMail():\n sendmail_location = "/usr/sbin/sendmail" # sendmail location\n p = os.popen("%s -t" % sendmail_location, "w")\n p.write("From: %s\\n" % "[email protected]")\n p.write("To: %s\\n" % "[email protected]")\n p.write("Subject: thesubject\\n")\n p.write("\\n") # blank line separating headers from body\n p.write("body of the mail")\n status = p.close()\n if status != 0:\n print "Sendmail exit status", status\n</code></pre>\n'}, {'answer_id': 74084, 'author': 'Jim', 'author_id': 8427, 'author_profile': 'https://Stackoverflow.com/users/8427', 'pm_score': 8, 'selected': True, 'text': '<p>Header injection isn\'t a factor in how you send the mail, it\'s a factor in how you construct the mail. Check the <a href="https://docs.python.org/2/library/email.html" rel="noreferrer">email</a> package, construct the mail with that, serialise it, and send it to <code>/usr/sbin/sendmail</code> using the <a href="https://docs.python.org/2/library/subprocess.html" rel="noreferrer">subprocess</a> module:</p>\n<pre><code>import sys\nfrom email.mime.text import MIMEText\nfrom subprocess import Popen, PIPE\n\n\nmsg = MIMEText("Here is the body of my message")\nmsg["From"] = "[email protected]"\nmsg["To"] = "[email protected]"\nmsg["Subject"] = "This is the subject."\np = Popen(["/usr/sbin/sendmail", "-t", "-oi"], stdin=PIPE)\n# Both Python 2.X and 3.X\np.communicate(msg.as_bytes() if sys.version_info >= (3,0) else msg.as_string()) \n\n# Python 2.X\np.communicate(msg.as_string())\n\n# Python 3.X\np.communicate(msg.as_bytes())\n</code></pre>\n'}, {'answer_id': 5545462, 'author': 'amcgregor', 'author_id': 211827, 'author_profile': 'https://Stackoverflow.com/users/211827', 'pm_score': 3, 'selected': False, 'text': '<p>This question is very old, but it\'s worthwhile to note that there is a message construction and e-mail delivery system called <a href="https://github.com/marrow/mailer" rel="nofollow noreferrer">Marrow Mailer</a> (previously TurboMail) which has been available since before this message was asked.</p>\n\n<p>It\'s now being ported to support Python 3 and updated as part of the <a href="https://github.com/marrow" rel="nofollow noreferrer">Marrow</a> suite.</p>\n'}, {'answer_id': 17345007, 'author': 'elec3647', 'author_id': 1842416, 'author_profile': 'https://Stackoverflow.com/users/1842416', 'pm_score': -1, 'selected': False, 'text': '<p>I was just searching around for the same thing and found a good example on the Python website: <a href="http://docs.python.org/2/library/email-examples.html" rel="nofollow">http://docs.python.org/2/library/email-examples.html</a></p>\n\n<p>From the site mentioned:</p>\n\n<pre><code># Import smtplib for the actual sending function\nimport smtplib\n\n# Import the email modules we\'ll need\nfrom email.mime.text import MIMEText\n\n# Open a plain text file for reading. For this example, assume that\n# the text file contains only ASCII characters.\nfp = open(textfile, \'rb\')\n# Create a text/plain message\nmsg = MIMEText(fp.read())\nfp.close()\n\n# me == the sender\'s email address\n# you == the recipient\'s email address\nmsg[\'Subject\'] = \'The contents of %s\' % textfile\nmsg[\'From\'] = me\nmsg[\'To\'] = you\n\n# Send the message via our own SMTP server, but don\'t include the\n# envelope header.\ns = smtplib.SMTP(\'localhost\')\ns.sendmail(me, [you], msg.as_string())\ns.quit()\n</code></pre>\n\n<p>Note that this requires that you have sendmail/mailx set up correctly to accept connections on "localhost". This works on my Mac, Ubuntu and Redhat servers by default, but you may want to double-check if you run into any issues.</p>\n'}, {'answer_id': 32673496, 'author': 'MEI', 'author_id': 5351807, 'author_profile': 'https://Stackoverflow.com/users/5351807', 'pm_score': 4, 'selected': False, 'text': '<p>Jim\'s answer did not work for me in Python 3.4. I had to add an additional <code>universal_newlines=True</code> argument to <code>subrocess.Popen()</code></p>\n\n<pre><code>from email.mime.text import MIMEText\nfrom subprocess import Popen, PIPE\n\nmsg = MIMEText("Here is the body of my message")\nmsg["From"] = "[email protected]"\nmsg["To"] = "[email protected]"\nmsg["Subject"] = "This is the subject."\np = Popen(["/usr/sbin/sendmail", "-t", "-oi"], stdin=PIPE, universal_newlines=True)\np.communicate(msg.as_string())\n</code></pre>\n\n<p>Without the <code>universal_newlines=True</code> I get</p>\n\n<pre><code>TypeError: \'str\' does not support the buffer interface\n</code></pre>\n'}, {'answer_id': 61923564, 'author': 'Robin Stewart', 'author_id': 7488171, 'author_profile': 'https://Stackoverflow.com/users/7488171', 'pm_score': 3, 'selected': False, 'text': '<p><strong>Python 3.5+</strong> version:</p>\n\n<pre><code>import subprocess\nfrom email.message import EmailMessage\n\ndef sendEmail(from_addr, to_addrs, msg_subject, msg_body):\n msg = EmailMessage()\n msg.set_content(msg_body)\n msg[\'From\'] = from_addr\n msg[\'To\'] = to_addrs\n msg[\'Subject\'] = msg_subject\n\n sendmail_location = "/usr/sbin/sendmail"\n subprocess.run([sendmail_location, "-t", "-oi"], input=msg.as_bytes())\n</code></pre>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73781', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12779/'] |
73,785 | <p>I need to simply go through all the cells in a Excel Spreadsheet and check the values in the cells. The cells may contain text, numbers or be blank. I am not very familiar / comfortable working with the concept of 'Range'. Therefore, any sample codes would be greatly appreciated. (I did try to google it, but the code snippets I found didn't quite do what I needed)</p>
<p>Thank you.</p>
| [{'answer_id': 73891, 'author': 'Martin08', 'author_id': 8203, 'author_profile': 'https://Stackoverflow.com/users/8203', 'pm_score': 0, 'selected': False, 'text': '<p>In Excel VBA, this function will give you the content of any cell in any worksheet.</p>\n\n<pre><code>Function getCellContent(Byref ws As Worksheet, ByVal rowindex As Integer, ByVal colindex As Integer) as String\n getCellContent = CStr(ws.Cells(rowindex, colindex))\nEnd Function\n</code></pre>\n\n<p>So if you want to check the value of cells, just put the function in a loop, give it the reference to the worksheet you want and the row index and column index of the cell. Row index and column index both start from 1, meaning that cell A1 will be ws.Cells(1,1) and so on.</p>\n'}, {'answer_id': 73900, 'author': 'betelgeuce', 'author_id': 366182, 'author_profile': 'https://Stackoverflow.com/users/366182', 'pm_score': 4, 'selected': True, 'text': '<pre><code>Sub CheckValues1()\n Dim rwIndex As Integer\n Dim colIndex As Integer\n For rwIndex = 1 To 10\n For colIndex = 1 To 5\n If Cells(rwIndex, colIndex).Value <> 0 Then _\n Cells(rwIndex, colIndex).Value = 0\n Next colIndex\n Next rwIndex\nEnd Sub\n</code></pre>\n\n<p>Found this snippet on <a href="http://www.java2s.com/Code/VBA-Excel-Access-Word/Excel/Checksvaluesinarange10rowsby5columns.htm" rel="noreferrer">http://www.java2s.com/Code/VBA-Excel-Access-Word/Excel/Checksvaluesinarange10rowsby5columns.htm</a> It seems to be quite useful as a function to illustrate the means to check values in cells in an ordered fashion.</p>\n\n<p>Just imagine it as being a 2d Array of sorts and apply the same logic to loop through cells.</p>\n'}, {'answer_id': 73907, 'author': 'theo', 'author_id': 7870, 'author_profile': 'https://Stackoverflow.com/users/7870', 'pm_score': 2, 'selected': False, 'text': '<p>You can use a For Each to iterate through all the cells in a defined range.</p>\n\n<pre><code>Public Sub IterateThroughRange()\n\nDim wb As Workbook\nDim ws As Worksheet\nDim rng As Range\nDim cell As Range\n\nSet wb = Application.Workbooks(1)\nSet ws = wb.Sheets(1)\nSet rng = ws.Range("A1", "C3")\n\nFor Each cell In rng.Cells\n cell.Value = cell.Address\nNext cell\n\nEnd Sub\n</code></pre>\n'}, {'answer_id': 73912, 'author': 'cori', 'author_id': 8151, 'author_profile': 'https://Stackoverflow.com/users/8151', 'pm_score': 6, 'selected': False, 'text': "<p>If you only need to look at the cells that are in use you can use:</p>\n\n<pre><code>sub IterateCells()\n\n For Each Cell in ActiveSheet.UsedRange.Cells\n 'do some stuff\n Next\n\nEnd Sub\n</code></pre>\n\n<p>that will hit everything in the range from A1 to the last cell with data (the bottom right-most cell)</p>\n"}, {'answer_id': 73946, 'author': 'TheXenocide', 'author_id': 8543, 'author_profile': 'https://Stackoverflow.com/users/8543', 'pm_score': 1, 'selected': False, 'text': '<p>There are several methods to accomplish this, each of which has advantages and disadvantages; First and foremost, you\'re going to need to have an instance of a Worksheet object, Application.ActiveSheet works if you just want the one the user is looking at.</p>\n\n<p>The Worksheet object has three properties that can be used to access cell data (Cells, Rows, Columns) and a method that can be used to obtain a block of cell data, (get_Range).</p>\n\n<p>Ranges can be resized and such, but you may need to use the properties mentioned above to find out where the boundaries of your data are. The advantage to a Range becomes apparent when you are working with large amounts of data because VSTO add-ins are hosted outside the boundaries of the Excel application itself, so all calls to Excel have to be passed through a layer with overhead; obtaining a Range allows you to get/set all of the data you want in one call which can have huge performance benefits, but it requires you to use explicit details rather than iterating through each entry.</p>\n\n<p><a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=767501&SiteID=1" rel="nofollow noreferrer">This MSDN forum post</a> shows a VB.Net developer asking a question about getting the results of a Range as an array</p>\n'}, {'answer_id': 74006, 'author': 'w4ik', 'author_id': 4232, 'author_profile': 'https://Stackoverflow.com/users/4232', 'pm_score': 1, 'selected': False, 'text': '<p>You basically can loop over a Range</p>\n\n<p>Get a sheet</p>\n\n<pre><code>myWs = (Worksheet)MyWb.Worksheets[1];\n</code></pre>\n\n<p>Get the Range you\'re interested in If you really want to check every cell use Excel\'s limits </p>\n\n<blockquote>\n <p>The Excel 2007 "Big Grid" increases\n the maximum number of rows per\n worksheet from 65,536 to over 1\n million, and the number of columns\n from 256 (IV) to 16,384 (XFD).\n from here <a href="http://msdn.microsoft.com/en-us/library/aa730921.aspx#Office2007excelPerf_BigGridIncreasedLimitsExcel" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/aa730921.aspx#Office2007excelPerf_BigGridIncreasedLimitsExcel</a></p>\n</blockquote>\n\n<p>and then loop over the range</p>\n\n<pre><code> Range myBigRange = myWs.get_Range("A1", "A256");\n\n string myValue;\n\n foreach(Range myCell in myBigRange )\n {\n myValue = myCell.Value2.ToString();\n }\n</code></pre>\n'}, {'answer_id': 74012, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>My VBA skills are a little rusty, but this is the general idea of what I\'d do.<br>\nThe easiest way to do this would be to iterate through a loop for every column:</p>\n\n<pre><code>public sub CellProcessing()\non error goto errHandler\n\n dim MAX_ROW as Integer \'how many rows in the spreadsheet\n dim i as Integer\n dim cols as String\n\n for i = 1 to MAX_ROW\n \'perform checks on the cell here\n \'access the cell with Range("A" & i) to get cell A1 where i = 1\n next i\n\nexitHandler:\n exit sub\nerrHandler:\n msgbox "Error " & err.Number & ": " & err.Description\n resume exitHandler\nend sub\n</code></pre>\n\n<p>it seems that the color syntax highlighting doesn\'t like vba, but hopefully this will help somewhat (at least give you a starting point to work from).</p>\n\n<ul>\n<li>Brisketeer</li>\n</ul>\n'}, {'answer_id': 74209, 'author': 'Cory Engebretson', 'author_id': 3406, 'author_profile': 'https://Stackoverflow.com/users/3406', 'pm_score': 2, 'selected': False, 'text': '<p>For a VB or C# app, one way to do this is by using Office Interop. This depends on which version of Excel you\'re working with.</p>\n\n<p>For Excel 2003, this MSDN article is a good place to start.\n<a href="http://msdn.microsoft.com/en-us/library/aa537184(office.11).aspx" rel="nofollow noreferrer">Understanding the Excel Object Model from a Visual Studio 2005 Developer\'s Perspective </a></p>\n\n<p>You\'ll basically need to do the following:</p>\n\n<ul>\n<li>Start the Excel application.</li>\n<li>Open the Excel workbook.</li>\n<li>Retrieve the worksheet from the workbook by name or index.</li>\n<li>Iterate through all the Cells in the worksheet which were retrieved as a range.</li>\n<li>Sample (untested) code excerpt below for the last step.</li>\n</ul>\n\n<pre><code>\n Excel.Range allCellsRng;\n string lowerRightCell = "IV65536";\n allCellsRng = ws.get_Range("A1", lowerRightCell).Cells;\n foreach (Range cell in allCellsRng)\n {\n if (null == cell.Value2 || isBlank(cell.Value2))\n {\n // Do something.\n }\n else if (isText(cell.Value2))\n {\n // Do something.\n }\n else if (isNumeric(cell.Value2))\n {\n // Do something.\n }\n }\n</code></pre>\n\n<p>For Excel 2007, try <a href="http://msdn.microsoft.com/en-us/library/bb979621.aspx" rel="nofollow noreferrer">this MSDN reference</a>.</p>\n'}, {'answer_id': 87577, 'author': 'Jon Fournier', 'author_id': 5106, 'author_profile': 'https://Stackoverflow.com/users/5106', 'pm_score': 3, 'selected': False, 'text': '<p>If you\'re just looking at values of cells you can store the values in an array of variant type. It seems that getting the value of an element in an array can be much faster than interacting with Excel, so you can see some difference in performance using an array of all cell values compared to repeatedly getting single cells.</p>\n\n<pre><code>Dim ValArray as Variant\nValArray = Range("A1:IV" & Rows.Count).Value\n</code></pre>\n\n<p>Then you can get a cell value just by checking ValArray( row , column )</p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73785', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5899/'] |
73,797 | <p>How do I tell Subversion (svn) to treat a file as a binary file?</p>
| [{'answer_id': 73820, 'author': 'Jan Krüger', 'author_id': 12471, 'author_profile': 'https://Stackoverflow.com/users/12471', 'pm_score': 3, 'selected': False, 'text': '<p>For example:</p>\n\n<pre><code>svn propset svn:mime-type image/png foo.png\n</code></pre>\n'}, {'answer_id': 73830, 'author': 'Adrian Petrescu', 'author_id': 12171, 'author_profile': 'https://Stackoverflow.com/users/12171', 'pm_score': 2, 'selected': False, 'text': '<p>As per the <a href="http://subversion.apache.org/faq.html#binary-files" rel="nofollow noreferrer">Subversion FAQ</a>, you can use svn propset to change the <strong>svn:mime-type</strong> property to <strong>application/octet-stream</strong></p>\n'}, {'answer_id': 73832, 'author': 'Paul Dixon', 'author_id': 6521, 'author_profile': 'https://Stackoverflow.com/users/6521', 'pm_score': 2, 'selected': False, 'text': '<p>svn looks for a mime-type property, guessing it is text if it doesn\'t exist. You can explicity set this property, see <a href="http://svnbook.red-bean.com/en/1.5/svn.forcvs.binary-and-trans.html" rel="nofollow noreferrer">http://svnbook.red-bean.com/en/1.5/svn.forcvs.binary-and-trans.html</a></p>\n'}, {'answer_id': 73834, 'author': 'KTamas', 'author_id': 6541, 'author_profile': 'https://Stackoverflow.com/users/6541', 'pm_score': 4, 'selected': False, 'text': '<p>Basically, you have to set the mime type to octet-stream:</p>\n\n<pre><code>svn propset svn:mime-type application/octet-stream <filename>\n</code></pre>\n'}, {'answer_id': 73852, 'author': 'Frank Wiles', 'author_id': 12568, 'author_profile': 'https://Stackoverflow.com/users/12568', 'pm_score': 0, 'selected': False, 'text': "<p>It usually does this by default for you, but if it isn't you need to look into file properties and propset. </p>\n"}, {'answer_id': 73863, 'author': 'Evil Andy', 'author_id': 4431, 'author_profile': 'https://Stackoverflow.com/users/4431', 'pm_score': 4, 'selected': False, 'text': '<p>From page 367 of the <a href="http://svnbook.red-bean.com/en/1.5/svn-book.pdf" rel="noreferrer">Subversion book</a></p>\n\n<blockquote>\n <p>In the most general sense, Subversion handles binary files more gracefully than CVS does.\n Because CVS uses RCS, it can only store successive full copies of a changing binary file.\n Subversion, however, expresses differences between files using a binary differencing algorithm,\n regardless of whether they contain textual or binary data. That means all files are\n stored differentially (compressed) in the repository.</p>\n \n <p>CVS users have to mark binary files with -kb flags to prevent data from being garbled (due\n to keyword expansion and line-ending translations). They sometimes forget to do this.</p>\n \n <p>Subversion takes the more paranoid route. First, it never performs any kind of keyword or\n line-ending translation unless you explicitly ask it to do so (see the section called “Keyword\n Substitution” and the section called “End-of-Line Character Sequences” for more details).\n By default, Subversion treats all file data as literal byte strings, and files are always stored\n in the repository in an untranslated state.</p>\n \n <p>Second, Subversion maintains an internal notion of whether a file is “text” or “binary” data,\n but this notion is only extant in the working copy. During an svn update, Subversion will\n perform contextual merges on locally modified text files, but will not attempt to do so for\n binary files.</p>\n \n <p>To determine whether a contextual merge is possible, Subversion examines the\n svn:mime-type property. If the file has no svn:mime-type property, or has a MIME\n type that is textual (e.g., text/*), Subversion assumes it is text. Otherwise, Subversion\n assumes the file is binary. Subversion also helps users by running a binary-detection algorithm\n in the svn import and svn add commands. These commands will make a good\n guess and then (possibly) set a binary svn:mime-type property on the file being added.\n (If Subversion guesses wrong, the user can always remove or hand-edit the property.)</p>\n</blockquote>\n\n<p>Hand editing would be done by</p>\n\n<pre><code>svn propset svn:mime-type some/type filename.extension\n</code></pre>\n'}, {'answer_id': 73864, 'author': 'Brian R. Bondy', 'author_id': 3153, 'author_profile': 'https://Stackoverflow.com/users/3153', 'pm_score': 2, 'selected': False, 'text': '<p>If using tortoise svn in Windows, right click on the file and go to properties. Click on new and add a new property of type svn:mime-type. For the value put: application/octet-stream</p>\n'}, {'answer_id': 73924, 'author': 'grammar31', 'author_id': 12815, 'author_profile': 'https://Stackoverflow.com/users/12815', 'pm_score': 2, 'selected': False, 'text': '<p>Although Subversion tries to <a href="http://subversion.apache.org/faq.html#binary-files" rel="nofollow noreferrer">automatically detect</a> whether a file is binary or not, you can override the mime-type using <a href="http://svnbook.red-bean.com/en/1.0/re23.html" rel="nofollow noreferrer">svn propset</a>.\nFor example, <code>svn propset svn:mime-type application/octet-stream example.txt</code>. This will make your file act as a collection of bytes rather than a text file. See also, the svn manual on <a href="http://svnbook.red-bean.com/nightly/en/svn.advanced.props.file-portability.html#svn.advanced.props.special.mime-type" rel="nofollow noreferrer">File Portability</a>.</p>\n'}, {'answer_id': 74017, 'author': 'stormlash', 'author_id': 12657, 'author_profile': 'https://Stackoverflow.com/users/12657', 'pm_score': 7, 'selected': True, 'text': '<p>It is possible to manually identify a file located within a repository as <em>binary</em> by using:</p>\n\n<pre><code>svn propset svn:mime-type application/octet-stream <filename>\n</code></pre>\n\n<p>This is generally not necessary, as Subversion will attempt to determine whether a file is binary when the file is first added. If Subversion is incorrectly tagging a certain type as "text" when it should be treated as binary, it is possible to configure Subversion\'s <a href="http://svnbook.red-bean.com/nightly/en/svn.advanced.props.html#svn.advanced.props.auto" rel="noreferrer">auto-props feature</a> to automatically tag that file with a non-text MIME type. Regardless of the properties configured on the file, Subversion still stores the file in a binary format within the repository.</p>\n\n<p>If Subversion identifies the MIME type as a "text" type, it enables certain features which are not available on binary files, such as <em>svn diff</em> and <em>svn blame</em>. It also allows for automatic line ending conversion, which is configurable on a client-by-client basis.</p>\n\n<p>For more information, see <a href="http://subversion.apache.org/faq.html#binary-files" rel="noreferrer">How does Subversion handle binary files?</a></p>\n'}, {'answer_id': 11020623, 'author': 'user1454388', 'author_id': 1454388, 'author_profile': 'https://Stackoverflow.com/users/1454388', 'pm_score': 4, 'selected': False, 'text': "<p>If 'svn add' guesses the incorrect type and gives you an error like the following:</p>\n\n<pre><code>svn: E200009: File 'qt/examples/dialogs/configdialog/images/config.png' has inconsistent newlines\nsvn: E135000: Inconsistent line ending style\n</code></pre>\n\n<p>then the workaround is to add the file without properties and then set the properties in a second step:</p>\n\n<pre><code>svn add --no-auto-props qt/examples/dialogs/configdialog/images/config.png\nsvn propset svn:mime-type image/png qt/examples/dialogs/configdialog/images/config.png\n</code></pre>\n"}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73797', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5222/'] |
73,825 | <p>This is about when a .NET remoting exception is thrown. If you take a look at MSDN, it will mention that a remoting exception is thrown when something goes wrong with remoting. If my server is not running, I get a socket exception which is fine.</p>
<p>What I am trying to figure out is: does getting a remoting exception indicate for sure that my server is up and running? If yes, that would solve the problem. If not: Is there a way to figure out if the remoting exception originated on the client side or the server side?</p>
<h3>Update:</h3>
<p>The problem I am trying to solve is that the server is down initially and then client sends some message to the server. Now I get a socket exception saying "No connection could be made..." which is fine.</p>
<p>There is a thread that is sending messages to the server at regular intervals to see if the server is available. Now, the server comes up, and at that point, you could get the response which is fine or you could get some exception and most probably it will be a remote exception. So, what I am trying to ask is that: in case I don't get a message and I get a remote exception is there a chance that the server is up and running and I am still getting this exception?</p>
<p>All I am doing is just calling a method on the remote object that does nothing and returns. If there is no exception then I am good. Now, if there is a remoting exception and if I knew the remoting exception occurred on the server then I know in spite getting the exception, I am connected to the server.</p>
| [{'answer_id': 73938, 'author': 'sumek', 'author_id': 11439, 'author_profile': 'https://Stackoverflow.com/users/11439', 'pm_score': 0, 'selected': False, 'text': '<p>Try assuring that you send the correct message and the messages received by the server are also correct, e.g. using assertions (it is called Design by Contract).\nIf you have such possibility, try debugging the server side and client side at the same time. (running two VS instances at the same time)</p>\n'}, {'answer_id': 74099, 'author': 'Rikalous', 'author_id': 4271, 'author_profile': 'https://Stackoverflow.com/users/4271', 'pm_score': 0, 'selected': False, 'text': "<p>I haven't got access to the source code of my last remoting application, but as far as I can remember we couldn't figure out a way of knowing for definite if the server was up from any of the exceptions we got.<br>\nWe did check to see if the network was present and warned the user if not (a method on the Environment class I think).</p>\n"}, {'answer_id': 74130, 'author': 'Thomee', 'author_id': 12825, 'author_profile': 'https://Stackoverflow.com/users/12825', 'pm_score': 2, 'selected': True, 'text': '<p>Getting a remoting exception does not guarantee that your server is up and running. If something else happens to be running and listening on that port, the connection will succeed, and you will not get a socket exception. What happens in this case depends on how the application which actually got your connection behaves, but it will probably wind up generating a remoting exception in your client.</p>\n\n<p>It would take a bit more investigation to verify this, but I believe the remoting exception indicates a problem in the communications between the client and the server, so there isn\'t a "client side" or "server side" that generated it. It means that the two weren\'t talking happily and it could have been caused by either one.</p>\n'}, {'answer_id': 74382, 'author': 'icelava', 'author_id': 2663, 'author_profile': 'https://Stackoverflow.com/users/2663', 'pm_score': 0, 'selected': False, 'text': '<p>If the server side application logic threw an exception, it should be able to marshal over to the client to let it know what happened. You can test this by deliberately throwing an exception in one of the remote object\'s methods. Then call that particular method from the client side expecting an exception:</p>\n\n<pre><code>HttpChannel channel = new HttpChannel();\nChannelServices.RegisterChannel(channel);\n\nIMyRemoteObject obj = (IMyRemoteObject) Activator.GetObject(\n typeof(IMyRemoteObject),\n "http://localhost:1234/MyRemoteObject.soap");\nConsole.WriteLine("Client.Main(): Reference to rem.obj. acquired");\n int tmp = obj.GetValue();\n Console.WriteLine("Client.Main(): Original server side value: {0}",tmp);\nConsole.WriteLine("Client.Main(): Will set value to 42");\n\ntry\n{\n // This method will throw an ApplicationException in the server-side code.\n obj.SetValue(42);\n}\ncatch (Exception ex)\n{\n Console.WriteLine("=====");\n Console.WriteLine("Exception type: " + ex.GetType().ToString());\n Console.WriteLine("Message: " + ex.Message);\n Console.WriteLine("Source: " + ex.Source);\n Console.WriteLine("Stack trace: " + ex.StackTrace);\n Console.WriteLine("=====");\n}\n</code></pre>\n\n<p>You can expect an exception received like this</p>\n\n<pre><code>=====\nException type: System.ApplicationException\nMessage: testing\nSource: Server\nStack trace:\nServer stack trace:\n at Server.MyRemoteObject.SetValue(Int32 newval) in i:\\projects\\remoting.net\\ch03\\01_singlecallobjects\\server\\server.cs:line 27\n at System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(MethodBase mb, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)\n at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)\n\nException rethrown at [0]:\n at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)\n at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)\n at General.IMyRemoteObject.SetValue(Int32 newval)\n at Client.Client.Main(String[] args) in i:\\projects\\remoting.net\\ch03\\01_singlecallobjects\\client\\client.cs:line 29\n=====\n</code></pre>\n\n<p>It should tell you the Source is at the server, with a server-side stack trace.</p>\n'}, {'answer_id': 74528, 'author': 'Steve Dinn', 'author_id': 12338, 'author_profile': 'https://Stackoverflow.com/users/12338', 'pm_score': 2, 'selected': False, 'text': '<p>If you are intending to use custom exception types to be thrown across the remoting boundray, be sure to mark these types as "[Serializable]". I can\'t remember the exact error message, but it perplexed me for the better part of a day the first time I saw it.</p>\n\n<p>Also, just a tip, TargetInvocationException often has the REAL exception embedded in its InnerException property. There is nothing more useless than "An exception was thrown by the target of an invocation."</p>\n'}, {'answer_id': 74630, 'author': 'icelava', 'author_id': 2663, 'author_profile': 'https://Stackoverflow.com/users/2663', 'pm_score': 0, 'selected': False, 'text': '<p>Ok now that you have put it that way, I assume you are use TCP for remoting, for if it was via HTTP, it would be a WebException thrown when failing to connect to the (TCP network port) server. When the server has not launched the application program to register the channel on that designated TCP port, you will get a SocketException. After all, the server is not listening/responding to that port, how can the client ever make a socket connection?</p>\n\n<p>But, if you get a RemotingException it need <em>not</em> necessarily mean the server has its proper Remoting application running fine. You could test by connecting to a wrong URI on a wrong port, like port 80 (IIS).</p>\n\n<pre><code>IMyRemoteObject obj = (IMyRemoteObject) Activator.GetObject(\n typeof(IMyRemoteObject),\n "tcp://localhost:80/MyRemoteObject.rem");\n</code></pre>\n\n<p>That would result in a RemotingException because while the client can make a TCP connection to port 80, it is IIS responding to the call and not the Remoting app; IIS cannot handle remoting calls directly. Having said that, a RemotingException can also jolly mean a problem at the client side. This blog article may help you understand better.</p>\n\n<p><a href="http://www.cookcomputing.com/blog/archives/000308.html" rel="nofollow noreferrer">http://www.cookcomputing.com/blog/archives/000308.html</a></p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73825', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/'] |
73,833 | <p>I want to search for files containing DOS line endings with grep on Linux. Something like this:</p>
<pre class="lang-sh prettyprint-override"><code>grep -IUr --color '\r\n' .
</code></pre>
<p>The above seems to match for literal <code>rn</code> which is not what is desired.</p>
<p>The output of this will be piped through xargs into todos to convert crlf to lf like this</p>
<pre><code>grep -IUrl --color '^M' . | xargs -ifile fromdos 'file'
</code></pre>
| [{'answer_id': 73886, 'author': 'pjz', 'author_id': 8002, 'author_profile': 'https://Stackoverflow.com/users/8002', 'pm_score': 7, 'selected': False, 'text': "<p>Use <kbd>Ctrl</kbd>+<kbd>V</kbd>, <kbd>Ctrl</kbd>+<kbd>M</kbd> to enter a literal Carriage Return character into your grep string. So:</p>\n<pre><code>grep -IUr --color "^M"\n</code></pre>\n<p>will work - if the <code>^M</code> there is a literal CR that you input as I suggested.</p>\n<p>If you want the list of files, you want to add the <code>-l</code> option as well.</p>\n<p><strong>Explanation</strong></p>\n<ul>\n<li><code>-I</code> ignore binary files</li>\n<li><code>-U</code> prevents grep from stripping CR characters. By default it does this it if it decides it's a text file.</li>\n<li><code>-r</code> read all files under each directory recursively.</li>\n</ul>\n"}, {'answer_id': 73969, 'author': 'Thomee', 'author_id': 12825, 'author_profile': 'https://Stackoverflow.com/users/12825', 'pm_score': 9, 'selected': True, 'text': '<p>grep probably isn\'t the tool you want for this. It will print a line for every matching line in every file. Unless you want to, say, run todos 10 times on a 10 line file, grep isn\'t the best way to go about it. Using find to run file on every file in the tree then grepping through that for "CRLF" will get you one line of output for each file which has dos style line endings:</p>\n\n<pre><code>find . -not -type d -exec file "{}" ";" | grep CRLF</code></pre>\n\n<p>will get you something like:</p>\n\n<pre><code>./1/dos1.txt: ASCII text, with CRLF line terminators\n./2/dos2.txt: ASCII text, with CRLF line terminators\n./dos.txt: ASCII text, with CRLF line terminators</code></pre>\n'}, {'answer_id': 74739, 'author': 'Linulin', 'author_id': 12481, 'author_profile': 'https://Stackoverflow.com/users/12481', 'pm_score': 4, 'selected': False, 'text': "<p>If your version of grep supports <strong>-P (--perl-regexp)</strong> option, then</p>\n\n<pre><code>grep -lUP '\\r$'\n</code></pre>\n\n<p>could be used.</p>\n"}, {'answer_id': 3184434, 'author': 'yabt', 'author_id': 384287, 'author_profile': 'https://Stackoverflow.com/users/384287', 'pm_score': 4, 'selected': False, 'text': '<pre><code># list files containing dos line endings (CRLF)\n\ncr="$(printf "\\r")" # alternative to ctrl-V ctrl-M\n\ngrep -Ilsr "${cr}$" . \n\ngrep -Ilsr $\'\\r$\' . # yet another & even shorter alternative\n</code></pre>\n'}, {'answer_id': 3773573, 'author': 'Peter Y', 'author_id': 455551, 'author_profile': 'https://Stackoverflow.com/users/455551', 'pm_score': 2, 'selected': False, 'text': '<p>The query was search... I have a similar issue... somebody submitted mixed line\nendings into the version control, so now we have a bunch of files with <code>0x0d</code>\n<code>0x0d</code> <code>0x0a</code> line endings. Note that</p>\n\n<pre><code>grep -P \'\\x0d\\x0a\'\n</code></pre>\n\n<p>finds all lines, whereas</p>\n\n<pre><code>grep -P \'\\x0d\\x0d\\x0a\'\n</code></pre>\n\n<p>and</p>\n\n<pre><code>grep -P \'\\x0d\\x0d\'\n</code></pre>\n\n<p>finds no lines so there may be something "else" going on inside grep\nwhen it comes to line ending patterns... unfortunately for me!</p>\n'}, {'answer_id': 7715813, 'author': 'MykennaC', 'author_id': 30818, 'author_profile': 'https://Stackoverflow.com/users/30818', 'pm_score': 1, 'selected': False, 'text': "<p>If, like me, your minimalist unix doesn't include niceties like the <strong>file</strong> command, and backslashes in your <strong>grep</strong> expressions just don't cooperate, try this:</p>\n\n<pre><code>$ for file in `find . -type f` ; do\n> dump $file | cut -c9-50 | egrep -m1 -q ' 0d| 0d'\n> if [ $? -eq 0 ] ; then echo $file ; fi\n> done\n</code></pre>\n\n<p>Modifications you may want to make to the above include:</p>\n\n<ul>\n<li>tweak the <strong>find</strong> command to locate only the files you want to scan</li>\n<li>change the <strong>dump</strong> command to <strong>od</strong> or whatever file dump utility you have</li>\n<li>confirm that the <strong>cut</strong> command includes both a leading and trailing space as well as just the hexadecimal character output from the <strong>dump</strong> utility</li>\n<li>limit the <strong>dump</strong> output to the first 1000 characters or so for efficiency</li>\n</ul>\n\n<p>For example, something like this may work for you using <strong>od</strong> instead of <strong>dump</strong>:</p>\n\n<pre><code> od -t x2 -N 1000 $file | cut -c8- | egrep -m1 -q ' 0d| 0d|0d$'\n</code></pre>\n"}, {'answer_id': 13643222, 'author': 'Zombo', 'author_id': 1002260, 'author_profile': 'https://Stackoverflow.com/users/1002260', 'pm_score': 6, 'selected': False, 'text': '<p>Using RipGrep (depending on your shell, you might need to quote the last argument):</p>\n<pre><code>rg -l \\r\n</code></pre>\n<pre><code>-l, --files-with-matches\nOnly print the paths with at least one match.\n</code></pre>\n<p><a href="https://github.com/BurntSushi/ripgrep" rel="nofollow noreferrer">https://github.com/BurntSushi/ripgrep</a></p>\n'}, {'answer_id': 47165349, 'author': 'Murali Krishna Parimi', 'author_id': 5943385, 'author_profile': 'https://Stackoverflow.com/users/5943385', 'pm_score': 2, 'selected': False, 'text': '<p>You can use file command in unix. It gives you the character encoding of the file along with line terminators.</p>\n\n<pre><code>$ file myfile\nmyfile: ISO-8859 text, with CRLF line terminators\n$ file myfile | grep -ow CRLF\nCRLF \n</code></pre>\n'}, {'answer_id': 61631159, 'author': 'dessert', 'author_id': 6164712, 'author_profile': 'https://Stackoverflow.com/users/6164712', 'pm_score': 2, 'selected': False, 'text': '<p><code>dos2unix</code> has a file information option which can be used to show the files that would be converted:</p>\n<pre class="lang-sh prettyprint-override"><code>dos2unix -ic /path/to/file\n</code></pre>\n<p>To do that recursively you can use <code>bash</code>’s <code>globstar</code> option, which for the current shell is enabled with <code>shopt -s globstar</code>:</p>\n<pre class="lang-sh prettyprint-override"><code>dos2unix -ic ** # all files recursively\ndos2unix -ic **/file # files called “file” recursively\n</code></pre>\n<p>Alternatively you can use <code>find</code> for that:</p>\n<pre class="lang-sh prettyprint-override"><code>find -type f -exec dos2unix -ic {} + # all files recursively (ignoring directories)\nfind -name file -exec dos2unix -ic {} + # files called “file” recursively\n</code></pre>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73833', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/10245/'] |
73,879 | <p>I have a small to medium project that is in C++/CLI. I really hate the syntax extensions of C++/CLI and I would prefer to work in C#. Is there a tool that does a decent job of translating one to the other?</p>
<p><strong>EDIT:</strong> When I said Managed c++ before I apparently meant c++/CLI</p>
| [{'answer_id': 73894, 'author': 'Jorge Ferreira', 'author_id': 6508, 'author_profile': 'https://Stackoverflow.com/users/6508', 'pm_score': 2, 'selected': False, 'text': '<p>.NET Managed C++ is like a train wreck. But have you looked into C++ CLI? I think Microsoft did a great job in this field to make C++ a first class .NET citizen.</p>\n\n<p><a href="http://msdn.microsoft.com/en-us/magazine/cc163852.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/magazine/cc163852.aspx</a></p>\n'}, {'answer_id': 74078, 'author': 'Rob Walker', 'author_id': 3631, 'author_profile': 'https://Stackoverflow.com/users/3631', 'pm_score': 1, 'selected': False, 'text': "<p>Back ~2004 Microsoft did have a tool that would convert managed C++ to C++/CLI ... sort of. We ran it on a couple of projects, but to be honest the amount of work left cleaning up the project was no less than the amount of work it would have been to do the conversion by hand in the first place. I don't think the tool ever made it out into a public release though (maybe for this reason).</p>\n\n<p>I don't know which version of Visual Studio you are using, but we have managed C++ code that will not compile with Visual Studio 2005/2008 using the /clr:oldSyntax switch and we still have a relic VS 2003 around for it. </p>\n\n<p>I don't know of any way of going from C++ to C# in a useful way ... you could try round tripping it through reflector :)</p>\n"}, {'answer_id': 74286, 'author': 'Vivek', 'author_id': 7418, 'author_profile': 'https://Stackoverflow.com/users/7418', 'pm_score': 2, 'selected': False, 'text': '<p>I\'m not sure if this will work, but try using <a href="http://www.red-gate.com/products/reflector/" rel="nofollow noreferrer">.Net Reflector</a> along with <a href="http://www.codeplex.com/reflectoraddins/Wiki/View.aspx?title=ReflectionEmitLanguage&referringTitle=Home" rel="nofollow noreferrer">ReflectionEmitLanguage</a> plug-in. The RelelectionEmitLanguage plug-in claims to convert your assembly to c# code.</p>\n'}, {'answer_id': 74356, 'author': 'Kevin', 'author_id': 6386, 'author_profile': 'https://Stackoverflow.com/users/6386', 'pm_score': 4, 'selected': True, 'text': "<p>You can only translate Managed C++ code (and C++/CLI code) to C# if the C++ code is pure managed. If it is not -- i.e. if there is native code included in the sources -- tools like .NET Reflector won't be able to translate the code for you.</p>\n\n<p>If you do have native C++ code mixed in, then I'd recommend trying to move the native code into a separate DLL, replace your calls to DLL functions by easily identifiable stub functions, compile your project as a pure .NET library, then use .NET reflector to de-compile into C# code. Then you can replace the calls to the stub functions by p-invoke calls to your native DLL.</p>\n\n<p>Good luck! I feel for you!</p>\n"}, {'answer_id': 74915, 'author': 'Assaf Lavie', 'author_id': 11208, 'author_profile': 'https://Stackoverflow.com/users/11208', 'pm_score': 0, 'selected': False, 'text': "<p>Such projects are often done in c++/cli because C# isn't really an elegant option for the task. e.g. if you have to interface with some native C++ libraries, or do very high performance stuff in low level C. So just make sure whoever chose c++/cli didn't have a good reason to do it before doing the switch.</p>\n\n<p>Having said that, I'm highly skeptical there's something that does what you ask, for the simple reason that not all C++/cli code is translatable to C# (and probably vice versa too).</p>\n"}, {'answer_id': 71609586, 'author': 'Shahin Dohan', 'author_id': 1469494, 'author_profile': 'https://Stackoverflow.com/users/1469494', 'pm_score': 1, 'selected': False, 'text': '<p>It has to be done manually unfortunately, but if the code is mostly C++/CLI (not native C++) then it can actually be done pretty quickly. I managed to port around 250,000 lines of C++/CLI code into C# in less than a couple of months, and I don\'t even know C++ very well at all.</p>\n<p>If preserving Git history is important, you might want to <code>git mv</code> your cpp file into a cs file, commit, then start porting. The reason for this is that Git will think your file is new if you modify it too much after renaming it.</p>\n<p>This was my approach when porting large amounts of code (so that it wouldn\'t take forever):</p>\n<ul>\n<li>Create another worktree / clone of the branch and keep it open at all times\n<ul>\n<li>This is extremely important as <strong>you will</strong> want to compare your C# to the old C++/CLI code</li>\n</ul>\n</li>\n<li>Rename cpp to cs, delete header file, commit\n<ul>\n<li>I chose to rename the cpp file since its git history is probably more important than the header file</li>\n</ul>\n</li>\n<li>Create namespace + class in cs file, add any base classes/interfaces (if abstract sealed, make static in C#)</li>\n<li>Copy fields first, then constructors, then properties, and finally functions</li>\n<li>Start replacing with <code>Ctrl+H</code>:\n<ul>\n<li><code>^</code> to empty</li>\n<li><code>::</code> to <code>.</code></li>\n<li><code>-></code> to <code>.</code></li>\n<li><code>nullptr</code> to <code>null</code></li>\n<li><code>for each</code> to <code>foreach</code></li>\n<li><code>gcnew</code> to <code>new</code></li>\n<li><code>L"</code> to <code>"</code>\n<ul>\n<li>Turn on case sensitivity to avoid accidental renames (for example <code>L"cool"</code> should become <code>"cool"</code>, not <code>"coo"</code></li>\n</ul>\n</li>\n<li>Prefixes like <code>ClassName::</code> to empty, so that <code>MyClass::MyMethod</code> becomes <code>MyMethod</code></li>\n<li>Go through the red code and port manually code that cannot be just replaced (e.g. some special C++ casts), unless you have some cool regex to do it fast</li>\n<li>Once code compiles, go through it again, compare to C++/CLI line by line, check for errors, clean it up, move on.</li>\n<li>If you encounter a dependency that needs to be ported, you could pause, port that, then come back. I did that, but it might not be so easy.</li>\n</ul>\n</li>\n</ul>\n<p>Properties were the most annoying to port, because I had to remove everything before and after the getters and setters. I could have maybe written a regex for it but didn\'t bother doing so.</p>\n<p>Once the porting is done, it\'s <strong>very important</strong> that you go through the changes line by line, read the code, and compare with C++/CLI code and fix possible errors.</p>\n<p>One problem with this approach is that you can introduce bugs in variable declarations, because in C++/CLI you can declare variables in 2 ways:</p>\n<ul>\n<li><code>MyType^ variable;</code> <- null</li>\n<li><code>MyType variable;</code> <- calls default constructor</li>\n</ul>\n<p>In the latter case, you want to actually do <code>MyType variable = new MyType();</code> but since you already removed all the <code>^</code> you have to just manually check and test which one is correct. You could of course just replace all <code>^</code>\'s manually, but for me it would have taken too long (plus laziness) so I just did it this way.</p>\n<p>Other recommendations:</p>\n<ul>\n<li>Have a dummy C++/CLI project and a tool like <a href="https://www.linqpad.net/" rel="nofollow noreferrer">LinqPad</a> or another C# project to test differences between C++/CLI and C# if you\'re unsure of a piece of ported code</li>\n<li>Install <a href="https://marketplace.visualstudio.com/items?itemName=VisualStudioPlatformTeam.MatchMargin" rel="nofollow noreferrer">Match Margin</a> to help highlight similar code (helped me when porting WinForms code)</li>\n<li>ReSharper! It helped with finding bugs and cleaning up the code a LOT. Truly worth the money.</li>\n</ul>\n<p>Some gotchas that I encountered while porting:</p>\n<ul>\n<li><p>Base classes can be called in C++/CLI like so: <code>BaseClass->DoStuff</code>, but in C# you would have to do <code>base.DoStuff</code> instead.</p>\n</li>\n<li><p>C++/CLI allows such statements: <code>if (foo)</code>, but in C# this has to be explicit. In the case of integers, it would be <code>if (foo != 0)</code> or for objects <code>if (foo != null)</code>.</p>\n</li>\n<li><p>Events in base classes can be invoked in C++/CLI, but in C# it\'s not possible. The solution is to create a method, like <code>OnSomeEvent</code>, in the base class, and inside that to invoke the event.</p>\n</li>\n<li><p>C++/CLI automatically generates null checks for event invocations, so in C# make sure to add an explicit null check: <code>MyEvent?.Invoke(this, EventArgs.Empty);</code>. Notice the question mark.</p>\n</li>\n<li><p><code>dynamic_cast</code> is equivalent to <code>as</code> cast in C#, the rest can be direct casts (<code>(int) something</code>).</p>\n</li>\n<li><p><code>gcnew</code> can be done without parentheses. In C# you must have them with <code>new</code>.</p>\n</li>\n<li><p>Pay attention to <code>virtual override</code> keywords in the header files, you can easily forget to mark the C# methods with <code>override</code> keyword.</p>\n</li>\n<li><p>Intefaces can have implementations! In this case, you might have to rethink the architecture a bit. One option is to pull the implementation into an abstract class and derive from it</p>\n</li>\n<li><p>Careful when replacing casts with <code>Convert</code> calls in C#</p>\n<ul>\n<li><code>Convert.ToInt32</code> rounds to the narest int, but casting always rounds down, so in this case we should not use the converter.</li>\n<li>Always try casting first, and if that doesn\'t work, use the <code>Convert</code> class.</li>\n</ul>\n</li>\n<li><p>Variables in C++/CLI can be re-declared in a local scope, but in C# you get naming conflicts. Code like this easily lead to hard to find bugs if not ported carefully.</p>\n<ul>\n<li>Example: An event handler can take a parameter <code>e</code>, but also has a try-catch like <code>catch (Exception e)</code> which means there are 2 <code>e</code> variables.</li>\n<li>Another example:</li>\n</ul>\n<pre class="lang-cpp prettyprint-override"><code>// number is 2\nint number = 2;\n\nfor (int number = 0; number < 5; number++)\n{\n // number is now 0, and goes up to 4\n}\n\n// number is again 2!\n</code></pre>\n<p>The above code is illegal in C#, because there is a naming conflict. Find out exactly how the code works in C++ and port it with the exact same logic, and obviously use different variable names.</p>\n</li>\n<li><p>In C++/CLI, it\'s possible to just write <code>throw;</code> which would create a generic C++ exception <code>SEHException</code>. Just replace it with a proper exception.</p>\n</li>\n<li><p>Be careful when porting code that uses the reference <code>%</code> sign, that usually means that you will have to use <code>ref</code> or <code>out</code> keywords in C#.</p>\n<ul>\n<li>Similarly, pay attention to pointers <code>*</code> and <code>&</code> references. You might have to write additional code to write changes back whereas in C++ you can just modify the data pointed to by the pointer.</li>\n</ul>\n</li>\n<li><p>It\'s possible to <strong>call methods on null object instances</strong> in C++/CLI. Yes seriously. So inside the function you could do <code>If (this == null) { return; }</code>.</p>\n<ul>\n<li>Port this type of code carefully. You might have to create an extension method that wraps over this type of method in order to avoid breaking the code.</li>\n</ul>\n</li>\n<li><p>Check and make sure everything in the old project file <code>vcxproj</code> was ported correctly. Did you miss any embedded resources?</p>\n</li>\n<li><p>Careful when porting directives like <code>#ifdef</code>, the "if not" (<code>#ifndef</code>) looks awfully similar but can have disastrous consequences.</p>\n</li>\n<li><p>C++/CLI classes automatically implement <code>IDisposable</code> when adding a destructor, so in C# you\'ll need to either implement that interface or override the Dispose method if it\'s available in the base class.</p>\n</li>\n</ul>\n<p>Other tips:</p>\n<ul>\n<li>If you need to call Win32 functions, just use P/Invoke instead of creating a C++/CLI wrapper</li>\n<li>For complex native C++ code, better create a C++/CLI project with managed wrappers</li>\n<li>Again, pay attention to pointers. I had forgotten to do <code>Marshal.StructureToPtr</code> in my P/Invoke code which wasn\'t necessary in the C++ version since we had the actual pointer and not a copy of its data.</li>\n</ul>\n<p>I have surely missed some things, but hopefully these tips will be of some help to people who are demoralized by the amount of code that needs to be ported, especially in a short period of time :)</p>\n<p>After porting is done, use VS/ReSharper to refactor and clean up the code. Not only is it nice for readability, which is my top priority when writing code, but it also forces you to interact with the code and possibly find bugs that you otherwise would have missed.</p>\n<p>Oh and one final FYI that could save you headaches: If you create a C++/CLI wrapper that exposes the native C++ pointer, and need to use that pointer in an external C++/CLI assembly, you MUST make the native type public by using <code>#pragma make_public</code> or else you\'ll get linker errors:</p>\n<pre class="lang-cpp prettyprint-override"><code>// put this at the top of the wrapper class, after includes\n#pragma make_public(SomeNamespace::NativeCppClass)\n</code></pre>\n<p>If you find a bug in the C++/CLI code, keep it. You want to port the code, not fix the code, so keep things in scope!</p>\n<p>For those wondering, we got maybe around 10 regressions after the port. Half were mistakes because I was already on autopilot mode and didn\'t pay attention to what I was doing.</p>\n<p>Happy porting!</p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73879', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/8508/'] |
73,881 | <p>Currently, I am working on a new version control system as part of a final year project at University. The idea is to make it highly adaptable and pluggable.</p>
<p>We're using the OSGi framework (Equinox implementation) to manage our plug ins. My problem is that I can't find a simple & easy to use method for testing OSGi bundles.</p>
<p>Currently, I have to build the bundle using Maven and then execute a test harness. I'm looking for something like the JUnit test runner for Eclipse, as it will save me a bunch of time.</p>
<p>Is there a quick and easy way to test OSGi bundles?</p>
<p>EDIT: I don't need something to test Eclipse plug ins or GUI components, just OSGi bundles.</p>
<p>EDIT2: Is there some framework that supports JUnit4?</p>
| [{'answer_id': 74114, 'author': 'flicken', 'author_id': 12880, 'author_profile': 'https://Stackoverflow.com/users/12880', 'pm_score': 4, 'selected': True, 'text': '<p>Spring Dynamic Modules has excellent support for <a href="http://static.springframework.org/osgi/docs/current/reference/html/testing.html" rel="noreferrer"> testing OSGi bundles</a>.</p>\n'}, {'answer_id': 112077, 'author': 'Rafael Chaves', 'author_id': 20033, 'author_profile': 'https://Stackoverflow.com/users/20033', 'pm_score': 2, 'selected': False, 'text': '<p>Eclipse has a launch configuration type for running JUnit tests in the context of an Eclipse (i.e. OSGi) application:</p>\n\n<p><a href="http://help.eclipse.org/stable/index.jsp?topic=/org.eclipse.pde.doc.user/guide/tools/launchers/junit_launcher.htm" rel="nofollow noreferrer">http://help.eclipse.org/stable/index.jsp?topic=/org.eclipse.pde.doc.user/guide/tools/launchers/junit_launcher.htm</a></p>\n'}, {'answer_id': 113217, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>If you need to test GUI components I\'ve found <a href="http://swtbot.org/" rel="nofollow noreferrer">SWTBot</a> gets the job done.</p>\n'}, {'answer_id': 152379, 'author': 'Toni Menzel', 'author_id': 1990802, 'author_profile': 'https://Stackoverflow.com/users/1990802', 'pm_score': 3, 'selected': False, 'text': '<p>There is a dedicated open source OSGi testing framework on OPS4J (ops4j.org) called <strong>Pax Drone</strong>.</p>\n\n<p>You might want to have a look at Pax Drone ([<a href="http://wiki.ops4j.org/confluence/x/KABo]" rel="noreferrer">http://wiki.ops4j.org/confluence/x/KABo]</a>) which enables you to use all Felix Versions as well as Equinox and Knopflerfish in your tests.</p>\n\n<p>Cheers,\nToni</p>\n'}, {'answer_id': 260261, 'author': 'user33790', 'author_id': 33790, 'author_profile': 'https://Stackoverflow.com/users/33790', 'pm_score': 1, 'selected': False, 'text': '<p><a href="http://code.google.com/p/treaty/" rel="nofollow noreferrer">Treaty</a> is a contract(testing) framework that is pretty academic but has some nice ideas. There are papers that are published on it, and the people currently working on improving it.</p>\n'}, {'answer_id': 7456623, 'author': 'Luca Geretti', 'author_id': 859596, 'author_profile': 'https://Stackoverflow.com/users/859596', 'pm_score': 4, 'selected': False, 'text': '<p>More recently, you should have a look at Pax Exam:\n<a href="http://team.ops4j.org/wiki/display/paxexam/Pax+Exam" rel="noreferrer">http://team.ops4j.org/wiki/display/paxexam/Pax+Exam</a></p>\n\n<p>This is the current effort at OPS4J related to testing.</p>\n'}, {'answer_id': 8128727, 'author': 'rescdsk', 'author_id': 88198, 'author_profile': 'https://Stackoverflow.com/users/88198', 'pm_score': 3, 'selected': False, 'text': '<p>Here are some tools not mentioned yet:</p>\n\n<ul>\n<li><p>I\'m using <a href="http://www.eclipse.org/tycho/" rel="noreferrer">Tycho</a>, which is a tool for using Maven to build Eclipse plugins. If you create tests inside their own plug-ins, or plug-in fragments, Tycho can run each set of tests inside its own OSGi instance, with all its required dependencies. <a href="http://wiki.eclipse.org/Tycho/Packaging_Types#eclipse-test-plugin" rel="noreferrer">Intro</a> and <a href="http://wiki.eclipse.org/Tycho/Reference_Card#Test_bundles" rel="noreferrer">further info</a>. This is working quite well for me.</p></li>\n<li><p><a href="http://felix.apache.org/site/apache-felix-ipojo-junit4osgi-tutorial.html" rel="noreferrer">jUnit4OSGI</a> looks straightforward. You make subclasses of OSGiTestCase, and you get methods like <code>getServiceReference()</code>, etc.</p></li>\n<li><p><a href="http://www.pluginbuilder.org/" rel="noreferrer">Pluginbuilder</a>, a headless build system for OSGi bundles / Eclipse plug-ins, has <a href="http://www.pluginbuilder.org/documentation/run-tests/" rel="noreferrer">a test-running framework</a> called <strong>Autotestsuite</strong>. It runs the tests in the context of the OSGi environment, after the build step. But, it doesn\'t seem to have been maintained for several years. I think that many Eclipse projects are migrating from Pluginbuilder to Tycho.</p></li>\n<li><p>Another option is to start an instance of <strong>an OSGi container <em>within</em> your unit test</strong>, which you run directly, as explained <a href="http://www.talios.com/osgi_based_integration_testing_with_testng_and_apache_felix.htm" rel="noreferrer">here</a>. </p></li>\n<li><p>Here\'s someone who\'s written <strong>a small <a href="http://rcpquickstart.com/2008/06/12/running-unit-tests-for-rcp-and-osgi-applications/" rel="noreferrer">bundle test collector</a></strong>, which searches for JUnit (3) tests and runs them.</p></li>\n</ul>\n'}, {'answer_id': 10686725, 'author': 'Basy', 'author_id': 1408061, 'author_profile': 'https://Stackoverflow.com/users/1408061', 'pm_score': 1, 'selected': False, 'text': '<p>For unit tests use the EasyMock framework or create your own implementations of the required interfaces for testing .</p>\n'}, {'answer_id': 10846924, 'author': 'pooh', 'author_id': 1417114, 'author_profile': 'https://Stackoverflow.com/users/1417114', 'pm_score': 1, 'selected': False, 'text': '<p>The <a href="http://dz.prosyst.com/pdoc/mBS_SDK/um/runtime/osgi/docs/tee/index.html" rel="nofollow">ProSyst Test Execution Environment</a> is a useful test tool for OSGi bundles. It also supports JUnit tests as one of the possible test models. </p>\n'}, {'answer_id': 12805716, 'author': 'Tonny Madsen', 'author_id': 796559, 'author_profile': 'https://Stackoverflow.com/users/796559', 'pm_score': 0, 'selected': False, 'text': '<p>During the last couple of years <a href="http://eclipse.org/tycho/" rel="nofollow">Tycho</a> - a new Maven based build system for OSGi - has become rather popular among the Eclipse Foundation. This framework also includes method to use Maven Surefire to test OSGi bundles in separate testbeds...</p>\n'}, {'answer_id': 12886337, 'author': 'Balazs Zsoldos', 'author_id': 1354879, 'author_profile': 'https://Stackoverflow.com/users/1354879', 'pm_score': 1, 'selected': False, 'text': '<p>I think we met the same issue and we made our own solution. There are different parts of the solution:</p>\n\n<ul>\n<li>A junit4runner that catches all OSGi services that has a special property defined. It runs these caught services with JUnit4 engine. JUnit annotations should be placed into interfaces that the services implement.</li>\n<li>A maven plugin that starts an OSGi framework (a custom framework can be created as maven dependency) and runs the unit tests inside the integration-test maven lifecycle.</li>\n<li>A deployer OSGi bundle. If this is dropped into your OSGi container a simple always-on-top window will be opened where you can drop your project folders (from total commander or from eclipse). This will then redeploy that bundle. </li>\n</ul>\n\n<p>With the tools you can do TDD and have the written tests always run inside the maven integration-phase as well. It is recommended to use eclipse with m2e and maven-bundle-plugin as in this case the target/classes/META-INF/MANIFEST.MF is regenerated as soon as you save a class in your source so you can drag the project and drop to the deployer window. The OSGi bundles you develop do not have to have any special feature (like being an eclipse plugin or something).</p>\n\n<p>The whole solution is OpenSource. You can find a tutorial at <a href="http://cookbook.everit.org" rel="nofollow">http://cookbook.everit.org</a></p>\n'}, {'answer_id': 51754780, 'author': 'Gadi', 'author_id': 148397, 'author_profile': 'https://Stackoverflow.com/users/148397', 'pm_score': -1, 'selected': False, 'text': '<p>How about bnd-testing-maven-plugin?</p>\n\n<p>It allow running JUnit inside a running container like Felix or Equinox.\nIf you used the BNDTools for eclipse this is very similar but just maven withpout eclipse and without a UI.</p>\n\n<p><a href="https://github.com/bndtools/bnd/tree/master/maven/bnd-testing-maven-plugin" rel="nofollow noreferrer">https://github.com/bndtools/bnd/tree/master/maven/bnd-testing-maven-plugin</a></p>\n\n<p>also look at the effectiveosgi archetype for maven. This will give you a good starting point to build your project or just add tests.</p>\n\n<p><a href="https://github.com/effectiveosgi" rel="nofollow noreferrer">https://github.com/effectiveosgi</a></p>\n'}, {'answer_id': 57672850, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': "<p>There are many ways to test OSGi components, I suppose. One way of doing the testing is to use Robot Framework. What I've done is made my tests with Robot Framework and have the remote libraries either installed in OSGi or have them talk to OSGi-test components through sockets and robot would talk to these modules and run tests through them.</p>\n\n<p>So, basically your OSGi-modules should have interfaces that do something and produce some output. So, in my setup I had a test components that would make service calls to the actual OSGi-component and then there would be a listening-service that would catch the events/service calls (made by the module under test) and those results could be asked by the robot. So basically this way you can split a massive system in small components and have the system run in production/production like enviroment and have it tested automatically on component level or have some of the real components be tested in unison.</p>\n"}, {'answer_id': 66651654, 'author': 'haltunbay', 'author_id': 1171506, 'author_profile': 'https://Stackoverflow.com/users/1171506', 'pm_score': 0, 'selected': False, 'text': '<p>Along with others mentioned mockito is very handy to mock plugin dependencies(references etc). see <a href="https://www.baeldung.com/mockito-annotations" rel="nofollow noreferrer">https://www.baeldung.com/mockito-annotations</a></p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73881', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12828/'] |
73,883 | <p>I understand the difference between <code>String</code> and <code>StringBuilder</code> (<code>StringBuilder</code> being mutable) but is there a large performance difference between the two? </p>
<p>The program I’m working on has a lot of case driven string appends (500+). Is using <code>StringBuilder</code> a better choice?</p>
| [{'answer_id': 73901, 'author': 'DevelopingChris', 'author_id': 1220, 'author_profile': 'https://Stackoverflow.com/users/1220', 'pm_score': -1, 'selected': False, 'text': '<p>StringBuilder will perform better, from a memory stand point. As for processing, the difference in time of execution may be negligible.</p>\n'}, {'answer_id': 73921, 'author': 'Gilligan', 'author_id': 12356, 'author_profile': 'https://Stackoverflow.com/users/12356', 'pm_score': 1, 'selected': False, 'text': '<p>I believe StringBuilder is faster if you have more than 4 strings you need to append together. Plus it can do some cool things like AppendLine.</p>\n'}, {'answer_id': 73925, 'author': 'Eric Z Beard', 'author_id': 1219, 'author_profile': 'https://Stackoverflow.com/users/1219', 'pm_score': 1, 'selected': False, 'text': "<p>In .NET, StringBuilder is still faster than appending strings. I'm pretty sure that in Java, they just create a StringBuffer under the hood when you append strings, so there's isn't really a difference. I'm not sure why they haven't done this in .NET yet.</p>\n"}, {'answer_id': 73929, 'author': 'Jay Bazuzi', 'author_id': 5314, 'author_profile': 'https://Stackoverflow.com/users/5314', 'pm_score': 9, 'selected': True, 'text': '<p>Yes, the performance difference is significant. See the KB article "<a href="http://support.microsoft.com/kb/306822" rel="noreferrer">How to improve string concatenation performance in Visual C#</a>".</p>\n\n<p>I have always tried to code for clarity first, and then optimize for performance later. That\'s much easier than doing it the other way around! However, having seen the enormous performance difference in my applications between the two, I now think about it a little more carefully. </p>\n\n<p>Luckily, it\'s relatively straightforward to run performance analysis on your code to see where you\'re spending the time, and then to modify it to use <code>StringBuilder</code> where needed.</p>\n'}, {'answer_id': 73942, 'author': 'deemer', 'author_id': 11192, 'author_profile': 'https://Stackoverflow.com/users/11192', 'pm_score': -1, 'selected': False, 'text': "<p>StringBuilder is probably preferable. The reason is that it allocates more space than currently needed (you set the number of characters) to leave room for future appends. Then those future appends that fit in the current buffer don't require any memory allocation or garbage collection, which can be expensive. In general, I use StringBuilder for complex string concatentation or multiple formatting, then convert to a normal String when the data is complete, and I want an immutable object again.</p>\n"}, {'answer_id': 73945, 'author': 'Alex Fort', 'author_id': 12624, 'author_profile': 'https://Stackoverflow.com/users/12624', 'pm_score': 0, 'selected': False, 'text': "<p>If you're doing a lot of string concatenation, use a StringBuilder. When you concatenate with a String, you create a new String each time, using up more memory.</p>\n\n<p>Alex</p>\n"}, {'answer_id': 73961, 'author': 'RichS', 'author_id': 6247, 'author_profile': 'https://Stackoverflow.com/users/6247', 'pm_score': 2, 'selected': False, 'text': '<p>Further to the previous answers, the first thing I always do when thinking of issues like this is to create a small test application. Inside this app, perform some timing test for both scenarios and see for yourself which is quicker.</p>\n\n<p>IMHO, appending 500+ string entries should definitely use StringBuilder.</p>\n'}, {'answer_id': 74028, 'author': 'Steve g', 'author_id': 12092, 'author_profile': 'https://Stackoverflow.com/users/12092', 'pm_score': 1, 'selected': False, 'text': "<p>Using strings for concatenation can lead to a runtime complexity on the order of <code>O(n^2)</code>.</p>\n\n<p>If you use a <code>StringBuilder</code>, there is a lot less copying of memory that has to be done. With the <code>StringBuilder(int capacity)</code> you can increase performance if you can estimate how large the final <code>String</code> is going to be. Even if you're not precise, you'll probably only have to grow the capacity of <code>StringBuilder</code> a couple of times which can help performance also.</p>\n"}, {'answer_id': 74053, 'author': 'moswald', 'author_id': 8368, 'author_profile': 'https://Stackoverflow.com/users/8368', 'pm_score': 3, 'selected': False, 'text': '<p>StringBuilder reduces the number of allocations and assignments, at a cost of extra memory used. Used properly, it can completely remove the need for the compiler to allocate larger and larger strings over and over until the result is found.</p>\n\n<pre><code>string result = "";\nfor(int i = 0; i != N; ++i)\n{\n result = result + i.ToString(); // allocates a new string, then assigns it to result, which gets repeated N times\n}\n</code></pre>\n\n<p>vs.</p>\n\n<pre><code>String result;\nStringBuilder sb = new StringBuilder(10000); // create a buffer of 10k\nfor(int i = 0; i != N; ++i)\n{\n sb.Append(i.ToString()); // fill the buffer, resizing if it overflows the buffer\n}\n\nresult = sb.ToString(); // assigns once\n</code></pre>\n'}, {'answer_id': 74055, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>My approach has always been to use StringBuilder when concatenating 4 or more strings \nOR\nWhen I don\'t know how may concatenations are to take place.</p>\n\n<p><a href="http://www.heikniemi.net/hc/archives/000124.html" rel="nofollow noreferrer">Good performance related article on it here</a></p>\n'}, {'answer_id': 74094, 'author': 'capgpilk', 'author_id': 11707, 'author_profile': 'https://Stackoverflow.com/users/11707', 'pm_score': 0, 'selected': False, 'text': '<p>String and StringBuilder are actually both immutable, the StringBuilder has built in buffers which allow its size to be managed more efficiently. When the StringBuilder needs to resize is when it is re-allocated on the heap. By default it is sized to 16 characters, you can set this in the constructor.</p>\n\n<p>eg.</p>\n\n<p>StringBuilder sb = new StringBuilder(50);</p>\n'}, {'answer_id': 74136, 'author': 'James Curran', 'author_id': 12725, 'author_profile': 'https://Stackoverflow.com/users/12725', 'pm_score': 6, 'selected': False, 'text': '<p>To clarify what Gillian said about 4 string, if you have something like this:</p>\n\n<pre><code>string a,b,c,d;\n a = b + c + d;\n</code></pre>\n\n<p>then it would be faster using strings and the plus operator. This is because (like Java, as Eric points out), it internally uses StringBuilder automatically (Actually, it uses a primitive that StringBuilder also uses)</p>\n\n<p>However, if what you are doing is closer to:</p>\n\n<pre><code>string a,b,c,d;\n a = a + b;\n a = a + c;\n a = a + d;\n</code></pre>\n\n<p>Then you need to explicitly use a StringBuilder. .Net doesn\'t automatically create a StringBuilder here, because it would be pointless. At the end of each line, "a" has to be an (immutable) string, so it would have to create and dispose a StringBuilder on each line. For speed, you\'d need to use the same StringBuilder until you\'re done building:</p>\n\n<pre><code>string a,b,c,d;\nStringBuilder e = new StringBuilder();\n e.Append(b);\n e.Append(c);\n e.Append(d);\n a = e.ToString();\n</code></pre>\n'}, {'answer_id': 74233, 'author': 'Matt Trunnell', 'author_id': 12894, 'author_profile': 'https://Stackoverflow.com/users/12894', 'pm_score': 5, 'selected': False, 'text': '<p>This benchmark shows that regular concatenation is faster when combining 3 or fewer strings.</p>\n\n<p><a href="http://www.chinhdo.com/20070224/stringbuilder-is-not-always-faster/" rel="noreferrer">http://www.chinhdo.com/20070224/stringbuilder-is-not-always-faster/</a></p>\n\n<p>StringBuilder can make a very significant improvement in memory usage, especially in your case of adding 500 strings together. </p>\n\n<p>Consider the following example:</p>\n\n<pre><code>string buffer = "The numbers are: ";\nfor( int i = 0; i < 5; i++)\n{\n buffer += i.ToString();\n}\nreturn buffer;\n</code></pre>\n\n<p>What happens in memory? The following strings are created:</p>\n\n<pre><code>1 - "The numbers are: "\n2 - "0"\n3 - "The numbers are: 0"\n4 - "1"\n5 - "The numbers are: 01"\n6 - "2"\n7 - "The numbers are: 012"\n8 - "3"\n9 - "The numbers are: 0123"\n10 - "4"\n11 - "The numbers are: 01234"\n12 - "5"\n13 - "The numbers are: 012345"\n</code></pre>\n\n<p>By adding those five numbers to the end of the string we created 13 string objects! And 12 of them were useless! Wow!</p>\n\n<p>StringBuilder fixes this problem. It is not a "mutable string" as we often hear (<em>all strings in .NET are immutable</em>). It works by keeping an internal buffer, an array of char. Calling Append() or AppendLine() adds the string to the empty space at the end of the char array; if the array is too small, it creates a new, larger array, and copies the buffer there. So in the example above, StringBuilder might only need a single array to contain all 5 additions to the string-- depending on the size of its buffer. You can tell StringBuilder how big its buffer should be in the constructor.</p>\n'}, {'answer_id': 74596, 'author': 'Jason Jackson', 'author_id': 13103, 'author_profile': 'https://Stackoverflow.com/users/13103', 'pm_score': 1, 'selected': False, 'text': '<p>I have seen significant performance gains from using the <code>EnsureCapacity(int capacity)</code> method call on an instance of <code>StringBuilder</code> before using it for any string storage. I usually call that on the line of code after instantiation. It has the same effect as if you instantiate the <code>StringBuilder</code> like this:</p>\n\n<pre><code>var sb = new StringBuilder(int capacity);\n</code></pre>\n\n<p>This call allocates needed memory ahead of time, which causes fewer memory allocations during multiple <code>Append()</code> operations. You have to make an educated guess on how much memory you will need, but for most applications this should not be too difficult. I usually err on the side of a little too much memory (we are talking 1k or so).</p>\n'}, {'answer_id': 75003, 'author': 'calebjenkins', 'author_id': 13199, 'author_profile': 'https://Stackoverflow.com/users/13199', 'pm_score': 5, 'selected': False, 'text': '<p>StringBuilder is preferable <em>IF</em> you are doing multiple loops, or forks in your code pass... however, for PURE performance, if you can get away with a <em>SINGLE</em> string declaration, then that is much more performant. </p>\n\n<p>For example: </p>\n\n<pre><code>string myString = "Some stuff" + var1 + " more stuff"\n + var2 + " other stuff" .... etc... etc...;\n</code></pre>\n\n<p>is more performant than</p>\n\n<pre><code>StringBuilder sb = new StringBuilder();\nsb.Append("Some Stuff");\nsb.Append(var1);\nsb.Append(" more stuff");\nsb.Append(var2);\nsb.Append("other stuff");\n// etc.. etc.. etc..\n</code></pre>\n\n<p>In this case, StringBuild could be considered more maintainable, but is not more performant than the single string declaration. </p>\n\n<p>9 times out of 10 though... use the string builder. </p>\n\n<p>On a side note: string + var is also more performant that the string.Format approach (generally) that uses a StringBuilder internally (when in doubt... check reflector!)</p>\n'}, {'answer_id': 75253, 'author': 'raffimd', 'author_id': 13128, 'author_profile': 'https://Stackoverflow.com/users/13128', 'pm_score': 0, 'selected': False, 'text': '<p>String concatenation will cost you more.\nIn Java, You can use either StringBuffer or StringBuilder based on your need.\nIf you want a synchronized, and thread safe implementation, go for StringBuffer. This will be faster than the String concatenation.</p>\n\n<p>If you do not need synchronized or Thread safe implementation, go for StringBuilder.\nThis will be faster than String concatenation and also faster than StringBuffer as their is no synchorization overhead.</p>\n'}, {'answer_id': 75301, 'author': 'user13288', 'author_id': 13288, 'author_profile': 'https://Stackoverflow.com/users/13288', 'pm_score': -1, 'selected': False, 'text': '<p>As a general rule of thumb, if I have to set the value of the string more than once, or if there are any appends to the string, then it needs to be a string builder. I have seen applications that I have written in the past before learning about string builders that have had a huge memory foot print that just seems to keep growing and growing. Changing these programs to use the string builder cut down the memory usage significantly. Now I swear by the string builder.</p>\n'}, {'answer_id': 76664, 'author': 'JasonTrue', 'author_id': 13433, 'author_profile': 'https://Stackoverflow.com/users/13433', 'pm_score': 2, 'selected': False, 'text': '<p><code>StringBuilder</code> is better for building up a string from many non-constant values.</p>\n\n<p>If you\'re building up a string from a lot of constant values, such as multiple lines of values in an HTML or XML document or other chunks of text, you can get away with just appending to the same string, because almost all compilers do "constant folding", a process of reducing the parse tree when you have a bunch of constant manipulation (it\'s also used when you write something like <code>int minutesPerYear = 24 * 365 * 60</code>). And for simple cases with non-constant values appended to each other, the .NET compiler will reduce your code to something similar to what <code>StringBuilder</code> does.</p>\n\n<p>But when your append can\'t be reduced to something simpler by the compiler, you\'ll want a <code>StringBuilder</code>. As fizch points out, that\'s more likely to happen inside of a loop.</p>\n'}, {'answer_id': 3070753, 'author': 'Jim G.', 'author_id': 109941, 'author_profile': 'https://Stackoverflow.com/users/109941', 'pm_score': 2, 'selected': False, 'text': '<p>Consider \'<a href="http://www.codinghorror.com/blog/2009/01/the-sad-tragedy-of-micro-optimization-theater.html" rel="nofollow noreferrer">The Sad Tragedy of Micro-Optimization Theater</a>\'.</p>\n'}, {'answer_id': 4019882, 'author': 'user487069', 'author_id': 487069, 'author_profile': 'https://Stackoverflow.com/users/487069', 'pm_score': 3, 'selected': False, 'text': '<blockquote>\n <p>The performance of a concatenation operation for a String or StringBuilder object depends on how often a memory allocation occurs. A String concatenation operation always allocates memory, whereas a StringBuilder concatenation operation only allocates memory if the StringBuilder object buffer is too small to accommodate the new data. Consequently, the String class is preferable for a concatenation operation if a fixed number of String objects are concatenated. In that case, the individual concatenation operations might even be combined into a single operation by the compiler. A StringBuilder object is preferable for a concatenation operation if an arbitrary number of strings are concatenated; for example, if a loop concatenates a random number of strings of user input.</p>\n</blockquote>\n\n<p>Source: <a href="http://msdn.microsoft.com/en-us/library/system.text.stringbuilder%28v=VS.90%29.aspx" rel="noreferrer">MSDN</a></p>\n'}, {'answer_id': 14567185, 'author': 'CathalMF', 'author_id': 1680271, 'author_profile': 'https://Stackoverflow.com/users/1680271', 'pm_score': 1, 'selected': False, 'text': "<p><code>StringBuilder</code> is significantly more efficient but you will not see that performance unless you are doing a large amount of string modification.</p>\n<p>Below is a quick chunk of code to give an example of the performance. As you can see you really only start to see a major performance increase when you get into large iterations.</p>\n<p>As you can see the 200,000 iterations took 22 seconds while the 1 million iterations using the <code>StringBuilder</code> was almost instant.</p>\n<pre><code>string s = string.Empty;\nStringBuilder sb = new StringBuilder();\n\nConsole.WriteLine("Beginning String + at " + DateTime.Now.ToString());\n\nfor (int i = 0; i <= 50000; i++)\n{\n s = s + 'A';\n}\n\nConsole.WriteLine("Finished String + at " + DateTime.Now.ToString());\nConsole.WriteLine();\n\nConsole.WriteLine("Beginning String + at " + DateTime.Now.ToString());\n\nfor (int i = 0; i <= 200000; i++)\n{\n s = s + 'A';\n}\n\nConsole.WriteLine("Finished String + at " + DateTime.Now.ToString());\nConsole.WriteLine();\nConsole.WriteLine("Beginning Sb append at " + DateTime.Now.ToString());\n\nfor (int i = 0; i <= 1000000; i++)\n{\n sb.Append("A");\n}\nConsole.WriteLine("Finished Sb append at " + DateTime.Now.ToString());\n\nConsole.ReadLine();\n</code></pre>\n<p>Result of the above code:</p>\n<blockquote>\n<p>Beginning String + at 28/01/2013 16:55:40.</p>\n<p>Finished String + at 28/01/2013 16:55:40.</p>\n<p>Beginning String + at 28/01/2013 16:55:40.</p>\n<p>Finished String + at 28/01/2013 16:56:02.</p>\n<p>Beginning Sb append at 28/01/2013 16:56:02.</p>\n<p>Finished Sb append at 28/01/2013 16:56:02.</p>\n</blockquote>\n"}, {'answer_id': 17940168, 'author': 'Diizzy', 'author_id': 1701599, 'author_profile': 'https://Stackoverflow.com/users/1701599', 'pm_score': 5, 'selected': False, 'text': '<p>A simple example to demonstrate the difference in speed when using <code>String</code> concatenation vs <code>StringBuilder</code>:</p>\n\n<pre><code>System.Diagnostics.Stopwatch time = new Stopwatch();\nstring test = string.Empty;\ntime.Start();\nfor (int i = 0; i < 100000; i++)\n{\n test += i;\n}\ntime.Stop();\nSystem.Console.WriteLine("Using String concatenation: " + time.ElapsedMilliseconds + " milliseconds");\n</code></pre>\n\n<p>Result:</p>\n\n<blockquote>\n <p>Using String concatenation: 15423 milliseconds</p>\n</blockquote>\n\n<pre><code>StringBuilder test1 = new StringBuilder();\ntime.Reset();\ntime.Start();\nfor (int i = 0; i < 100000; i++)\n{\n test1.Append(i);\n}\ntime.Stop();\nSystem.Console.WriteLine("Using StringBuilder: " + time.ElapsedMilliseconds + " milliseconds");\n</code></pre>\n\n<p>Result:</p>\n\n<blockquote>\n <p>Using StringBuilder: 10 milliseconds</p>\n</blockquote>\n\n<p>As a result, the first iteration took 15423 ms while the second iteration using <code>StringBuilder</code> took 10 ms.</p>\n\n<p>It looks to me that using <code>StringBuilder</code> is faster, a lot faster.</p>\n'}, {'answer_id': 28749377, 'author': 'Shamseer K', 'author_id': 4133590, 'author_profile': 'https://Stackoverflow.com/users/4133590', 'pm_score': 4, 'selected': False, 'text': '<p>Yes, <code>StringBuilder</code> gives better performance while performing repeated operation over a string. It is because all the changes are made to a single instance so it can save a lot of time instead of creating a new instance like <code>String</code>.</p>\n\n<h3>String Vs Stringbuilder</h3>\n\n<ul>\n<li><p><code>String</code></p>\n\n<ol>\n<li>under <code>System</code> namespace</li>\n<li>immutable (read-only) instance</li>\n<li>performance degrades when continuous change of value occures</li>\n<li>thread safe</li>\n</ol></li>\n<li><p><code>StringBuilder</code> (mutable string)</p>\n\n<ol>\n<li>under <code>System.Text</code> namespace</li>\n<li>mutable instance</li>\n<li>shows better performance since new changes are made to existing instance</li>\n</ol></li>\n</ul>\n\n<blockquote>\n <p>Strongly recommend dotnet mob article : <a href="http://codaffection.com/csharp-article/difference-string-and-stringbuilder-in-csharp/" rel="nofollow noreferrer">String Vs StringBuilder in C#</a>.</p>\n \n <p>Related Stack Overflow question: <a href="https://stackoverflow.com/questions/28511598/mutability-of-string-when-string-doesnt-change-in-c/28511709#28511709">Mutability of string when string\n doesn\'t change in C#?</a>.</p>\n</blockquote>\n'}, {'answer_id': 53795136, 'author': 'Rehan Shah', 'author_id': 10759317, 'author_profile': 'https://Stackoverflow.com/users/10759317', 'pm_score': 4, 'selected': False, 'text': '<p><strong>String Vs String Builder:</strong></p>\n\n<p>First thing you have to know that In which assembly these two classes lives?</p>\n\n<p>So,</p>\n\n<p><strong>string</strong> is present in <code>System</code> namespace.</p>\n\n<p>and </p>\n\n<p><strong>StringBuilder</strong> is present in <code>System.Text</code> namespace.</p>\n\n<p>For <strong>string</strong> declaration: </p>\n\n<p>You have to include the <code>System</code> namespace.\nsomething like this.\n<code>Using System;</code></p>\n\n<p>and </p>\n\n<p>For <strong>StringBuilder</strong> declaration: </p>\n\n<p>You have to include the <code>System.text</code> namespace.\nsomething like this.\n<code>Using System.text;</code></p>\n\n<p>Now Come the the actual Question.</p>\n\n<p>What is the differene between <strong>string</strong> & <strong>StringBuilder</strong>?</p>\n\n<p><strong><em>The main difference between these two is that:</em></strong></p>\n\n<p><strong>string</strong> is immutable.</p>\n\n<p>and</p>\n\n<p><strong>StringBuilder</strong> is mutable.</p>\n\n<p>So Now lets discuss the difference between <em>immutable</em> and <em>mutable</em></p>\n\n<p><strong>Mutable:</strong> : means Changable.</p>\n\n<p><strong>Immutable:</strong> : means Not Changable.</p>\n\n<p><strong>For example:</strong></p>\n\n<pre><code>using System;\n\nnamespace StringVsStrigBuilder\n{\n class Program\n {\n static void Main(string[] args)\n {\n // String Example\n\n string name = "Rehan";\n name = name + "Shah";\n name = name + "RS";\n name = name + "---";\n name = name + "I love to write programs.";\n\n // Now when I run this program this output will be look like this.\n // output : "Rehan Shah RS --- I love to write programs."\n }\n }\n}\n</code></pre>\n\n<p>So in this case we are going to changing same object 5-times.</p>\n\n<p>So the Obvious question is that ! What is actually happen under the hood, when we change the same string 5-times.</p>\n\n<p>This is What Happen when we change the same string 5-times.</p>\n\n<p>let look at the figure.</p>\n\n<p><a href="https://i.stack.imgur.com/Q3haP.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/Q3haP.jpg" alt="enter image description here"></a> </p>\n\n<p><strong>Explaination:</strong></p>\n\n<p>When we first initialize this variable "name" to "Rehan" i-e <code>string name = "Rehan"</code>\nthis variable get created on stack "name" and pointing to that "Rehan" value.\nafter this line is executed: "name = name + "Shah". the reference variable is no longer pointing to that object "Rehan" it now pointing to "Shah" and so on.</p>\n\n<p>So <code>string</code> is immutable meaning that once we create the object in the memory we can\'t change them.</p>\n\n<p>So when we concatinating the <code>name</code> variable the previous object remains there in the memory and another new string object is get created...</p>\n\n<p>So from the above figure we have five-objects the four-objects are thrown away they are not used at all. They stil remain in memory and they occuy the amount of memory.\n"Garbage Collector" is responsible for that so clean that resources from the memory.</p>\n\n<p>So in case of string anytime when we manipulate the string over and over again we have some many objects Created ans stay there at in the memory.</p>\n\n<p>So this is the story of string Variable.</p>\n\n<p>Now Let\'s look at toward StringBuilder Object.\n<strong>For Example:</strong> </p>\n\n<pre><code>using System;\nusing System.Text;\n\nnamespace StringVsStrigBuilder\n{\n class Program\n {\n static void Main(string[] args)\n {\n // StringBuilder Example\n\n StringBuilder name = new StringBuilder();\n name.Append("Rehan");\n name.Append("Shah");\n name.Append("RS");\n name.Append("---");\n name.Append("I love to write programs.");\n\n\n // Now when I run this program this output will be look like this.\n // output : "Rehan Shah Rs --- I love to write programs."\n }\n }\n}\n</code></pre>\n\n<p>So in this case we are going to changing same object 5-times.</p>\n\n<p>So the Obvious question is that ! What is actually happen under the hood, when we change the same StringBuilder 5-times.</p>\n\n<p>This is What Happen when we change the same StringBuilder 5-times.</p>\n\n<p>let look at the figure.\n<a href="https://i.stack.imgur.com/oqTua.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/oqTua.jpg" alt="enter image description here"></a></p>\n\n<p><strong>Explaination:</strong>\nIn case of StringBuilder object. you wouldn\'t get the new object. The same object will be change in memory so even if you change the object et say 10,000 times we will still have only one stringBuilder object.</p>\n\n<p>You don\'t have alot of garbage objects or non_referenced stringBuilder objects because why it can be change. It is mutable meaning it change over a time?</p>\n\n<p><strong>Differences:</strong></p>\n\n<ul>\n<li>String is present in System namespace where as Stringbuilder present\nin System.Text namespace.</li>\n<li>string is immutable where as StringBuilder is mutabe.</li>\n</ul>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73883', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12623/'] |
73,884 | <p>When Visual Studio (2005) has <em>Options -> Text Editor -> C/C++ -> Tabs -> Indenting</em> set to Smart it will automatically indent code blocks and line up squiggly brackets, {}, as expected. However, if you hit enter inside a code block, move the cursor to another line, and then move it back, the inserted tabs are gone and the cursor is positioned all the way to the left. Is there a way to set Visual Studio to keep these tabs?</p>
| [{'answer_id': 73916, 'author': 'moswald', 'author_id': 8368, 'author_profile': 'https://Stackoverflow.com/users/8368', 'pm_score': 3, 'selected': True, 'text': "<p>As far as I know, the only way to do that is to enter something (anything) on that line, then delete it. Or hit space and you'll never see it there until you return to that line.</p>\n\n<p>Once VS determines that you've edited a line of text, it won't automatically modify it for you (at least, not in that way that you've described).</p>\n"}, {'answer_id': 17349403, 'author': 'John Smith', 'author_id': 2411533, 'author_profile': 'https://Stackoverflow.com/users/2411533', 'pm_score': 1, 'selected': False, 'text': '<p>This is an annoyance to myself as well. Anytime the code is reformatted the blank lines are de-tabbed.\nYou might look at this: <a href="http://visualstudiogallery.msdn.microsoft.com/ac4d4d6b-b017-4a42-8f72-55f0ffe850d7" rel="nofollow">http://visualstudiogallery.msdn.microsoft.com/ac4d4d6b-b017-4a42-8f72-55f0ffe850d7</a> it\'s not exactly a solution but a step in the right direction</p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73884', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12776/'] |
73,885 | <p>How can I construct my ajaxSend call, this seems like the place to put it, to preview what is being passed back to the broker? also, can I stop the ajax call in ajaxSend?..so I can perfect my url string before dealing with errors from the broker?</p>
<p>This is the complete URL that, when passed to the broker, will return the JSON code I need:</p>
<pre><code>http://myServer/cgi-bin/broker?service=myService&program=myProgram&section=mySection&start=09/08/08&end=09/26/08
</code></pre>
<p>This is my $.post call (not sure it is creating the above url string)</p>
<pre><code>$(function() {
$("#submit").bind("click",
function() {
$.post({
url: "http://csewebprod/cgi-bin/broker" ,
datatype: "json",
data: {
'service' : myService,
'program' : myProgram,
'section' : mySection,
'start' : '09/08/08',
'end' : '09/26/08'
},
error: function(request){
$("#updateHTML").removeClass("hide") ;
$("#updateHTML").html(request.statusText);
},
success: function(request) {
$("#updateHTML").removeClass("hide") ;
$("#updateHTML").html(request) ;
}
}); // End post method
}); // End bind method
}); // End eventlistener
</code></pre>
<p>Thanks</p>
| [{'answer_id': 73916, 'author': 'moswald', 'author_id': 8368, 'author_profile': 'https://Stackoverflow.com/users/8368', 'pm_score': 3, 'selected': True, 'text': "<p>As far as I know, the only way to do that is to enter something (anything) on that line, then delete it. Or hit space and you'll never see it there until you return to that line.</p>\n\n<p>Once VS determines that you've edited a line of text, it won't automatically modify it for you (at least, not in that way that you've described).</p>\n"}, {'answer_id': 17349403, 'author': 'John Smith', 'author_id': 2411533, 'author_profile': 'https://Stackoverflow.com/users/2411533', 'pm_score': 1, 'selected': False, 'text': '<p>This is an annoyance to myself as well. Anytime the code is reformatted the blank lines are de-tabbed.\nYou might look at this: <a href="http://visualstudiogallery.msdn.microsoft.com/ac4d4d6b-b017-4a42-8f72-55f0ffe850d7" rel="nofollow">http://visualstudiogallery.msdn.microsoft.com/ac4d4d6b-b017-4a42-8f72-55f0ffe850d7</a> it\'s not exactly a solution but a step in the right direction</p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73885', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2755/'] |
73,889 | <p>What's the best framework for writing modules -- <a href="http://search.cpan.org/perldoc/ExtUtils::MakeMaker" rel="noreferrer">ExtUtils::MakeMaker</a> (h2xs) or <a href="http://search.cpan.org/perldoc/Module::Build" rel="noreferrer">Module::Build</a>?</p>
| [{'answer_id': 73911, 'author': 'Frank Wiles', 'author_id': 12568, 'author_profile': 'https://Stackoverflow.com/users/12568', 'pm_score': 2, 'selected': False, 'text': '<p>There are pros and cons to both. These days I use and recommend Module::Build and Module::Starter.</p>\n'}, {'answer_id': 73931, 'author': 'amoore', 'author_id': 7573, 'author_profile': 'https://Stackoverflow.com/users/7573', 'pm_score': 0, 'selected': False, 'text': '<p>EU::MM still seems to be the most widely supported and popular one, but Module::Build is catching up. Also, check out <a href="http://search.cpan.org/dist/Module-Starter/" rel="nofollow noreferrer">Module::Starter</a> for a module that will help you get started.</p>\n'}, {'answer_id': 74090, 'author': 'cjm', 'author_id': 8355, 'author_profile': 'https://Stackoverflow.com/users/8355', 'pm_score': 2, 'selected': False, 'text': '<p>I also recommend Module::Build and Module::Starter (with the <a href="http://search.cpan.org/perldoc?Module::Starter::Plugin::TT2" rel="nofollow noreferrer">TT2 plugin</a>).</p>\n'}, {'answer_id': 74133, 'author': 'Leon Timmermans', 'author_id': 4727, 'author_profile': 'https://Stackoverflow.com/users/4727', 'pm_score': 2, 'selected': False, 'text': "<p>Module::Build is better by any means, but it is less widely supported than ExtUtils::MakeMaker (more specifically, older versions of Perl don't support it out of the box). It depends on your needs.</p>\n"}, {'answer_id': 74216, 'author': 'Dave Rolsky', 'author_id': 9832, 'author_profile': 'https://Stackoverflow.com/users/9832', 'pm_score': 5, 'selected': False, 'text': '<p>There are two questions here.</p>\n\n<p>First, never use h2xs. It\'s old outdated nastiness, though I suppose if you\'re actually trying to turn a header file into XS code, it might be useful (never done that myself).</p>\n\n<p><strong>2011 update: I strongly recommend taking a look at <a href="http://dzil.org" rel="noreferrer">Dist::Zilla</a>, especially if you think you\'ll be maintaining more than one module.</strong></p>\n\n<p>For creating a new module, use Module::Starter. It works great, and has some nice plugins for customizing the output.</p>\n\n<p>Second, you\'re asking what build system you should use. The three contenders are ExtUtils::MakeMaker (EUMM), Module::Build (MB), and Module::Install (MI).</p>\n\n<p>EUMM is a horrid nasty piece of work, but it works, and if you\'re not customizing your build process at all, works just fine.</p>\n\n<p>MB is the new kid, and it has its detractors. It\'s big plus is that if you want to heavily customize your install and build process, it\'s quite possible to do this sanely (and in a cross-platform manner) using MB. It\'s really not possible using EUMM.</p>\n\n<p>Finally, MI is basically a declarative wrapper on top of EUMM. It also packages itself along with your distro, in an attempt to work around problems with users trying to install modules with old toolchain modules. The downside of the "package self" trick is that if there\'s a bug in MI itself, you have to re-release all your modules just to fix it.</p>\n\n<p>As far as customization goes, there are some plugins for MI, but if you want to go beyond them you\'ll be back at the problem of dealing with Makefiles and build tools across a dozen+ platforms, so it really isn\'t going to help you too much in that realm.</p>\n'}, {'answer_id': 74628, 'author': 'brian d foy', 'author_id': 2766176, 'author_profile': 'https://Stackoverflow.com/users/2766176', 'pm_score': 4, 'selected': False, 'text': '<p>I just uploaded <a href="http://search.cpan.org/dist/Distribution-Cooker" rel="nofollow noreferrer">Distribution::Cooker</a> to CPAN. It\'s what I use to make new distributions. The nice thing about it is that your distributions can be whatever you like: you\'re just cooking some templates. I don\'t care if anyone uses it. For me it\'s simple, low tech, and doesn\'t cause extra problems.</p>\n\n<p>You might start with something like <a href="http://search.cpan.org/dist/Module-Starter" rel="nofollow noreferrer">Module::Starter</a> to make your starter templates then add your own boilerplate and favorite way of doing things. You choose not only whatever you want in each file, but which files show up in the distro. As you figure out how you like to do things, you simply update your own templates.</p>\n\n<p>As for Makemaker and Module::Build, <s>the future is Module::Build</s>. It\'s only us old guys using Makemaker anymore. :) There are ways to use both (or pretend to use both) at the same time. <s>Look at the Module::Build, Module::Build::Compat, and Module::Install docs</s>. Module::Build was kicked out of Perl\'s Standard Library and it\'s future is uncertain. It\'s back to Makemaker as a build system. </p>\n\n<p>Although this is a bit of a cop-out answer, try using each just to get a little experience with each.</p>\n'}, {'answer_id': 74840, 'author': 'Penfold', 'author_id': 11952, 'author_profile': 'https://Stackoverflow.com/users/11952', 'pm_score': 2, 'selected': False, 'text': '<p>Personally, I recommend Module::Install, as do a lot of folks I know - the likes of the Catalyst and Moose folks also use it. </p>\n'}, {'answer_id': 75295, 'author': 'Michael Carman', 'author_id': 8233, 'author_profile': 'https://Stackoverflow.com/users/8233', 'pm_score': 2, 'selected': False, 'text': '<p>Here\'s a little clarification of the direction I hoped the responses would take:</p>\n\n<ul>\n<li>pros/cons of various of frameworks</li>\n<li>compatibility/install base of frameworks</li>\n<li>suitability for internal (local) vs. external (CPAN) releases</li>\n<li><em>not</em> bare "use X" answers</li>\n</ul>\n\n<p><a href="https://stackoverflow.com/questions/73889/which-framework-should-i-use-to-write-modules#74216">Dave\'s answer</a> has some good pro/con info. <a href="https://stackoverflow.com/questions/73889/which-framework-should-i-use-to-write-modules#74133">Leon\'s answer</a> alludes to compatibility but isn\'t explicit. As <a href="https://stackoverflow.com/questions/73889/which-framework-should-i-use-to-write-modules#74628">brian d foy mentioned</a>, only the old hats use EUMM, but I\'m not convinced that MB is a good framework for things destined for CPAN due to it not being part of the core until 5.9.</p>\n'}, {'answer_id': 80207, 'author': 'Eric Wilhelm', 'author_id': 11580, 'author_profile': 'https://Stackoverflow.com/users/11580', 'pm_score': 3, 'selected': False, 'text': "<p>The only trouble with compatibility regarding Module::Build is when a user tries to install modules without updating their CPAN client (CPAN.pm or CPANPLUS.pm) If they are installing your module from the CPAN, they can just as easily upgrade their client from the same mirror.</p>\n\n<p>If you don't want to do <em>anything</em> complicated in your build process, sure: use EUMM. But if you have a build problem on a different target platform, you might end up in the Makefile, which is different on every variation of make.</p>\n\n<p>Module::Build gives you lots of features (anything you can think of if you extend it) and is all perl so you never end up debugging a makefile. Module::Install gives you features, but you have to bundle it and everything ends up running through 'make' in the end.</p>\n"}, {'answer_id': 214717, 'author': 'Schwern', 'author_id': 14660, 'author_profile': 'https://Stackoverflow.com/users/14660', 'pm_score': 7, 'selected': True, 'text': '<p><strong>NOTE</strong> This advice is out of date. <a href="http://www.dagolden.com/index.php/2140/paying-respect-to-modulebuild/" rel="nofollow noreferrer">Module::Build has been removed from the Perl core</a> but lives on as a CPAN module. The pros and cons still stand, and my opinions about MakeMaker still stand.</p>\n\n<hr>\n\n<p>As the former maintainer of ExtUtils::MakeMaker, I like to recommend Module::Build because MakeMaker is a horror show. Module::Build is so much better put together. But those aren\'t your concerns and I\'ll present my "least hassle for you" answer.</p>\n\n<h2>Executive Summary:</h2>\n\n<p>Because Module::Build support is not 100% in place through all of Perl, start with MakeMaker. If you want to do any customization at all, switch to Module::Build. Since their basic layout, options and interface are almost identical this will be painless. As seductive as it looks, avoid Module::Install.</p>\n\n<p>Fortunately, Module::Build can emulate MakeMaker which helps some, but doesn\'t help if you\'re going to do any customization. See <a href="http://search.cpan.org/perldoc?Module::Build::Compat" rel="nofollow noreferrer">Module::Build::Compat</a>.</p>\n\n<p>For CPAN releases using Module::Build is fine. There\'s enough Module::Build stuff on CPAN now that everyone\'s dealt with getting it bootstrapped already.</p>\n\n<p>Finally, the new <a href="http://module-build.sourceforge.net/META-spec.html#configure_requires" rel="nofollow noreferrer"><code>configure_requires</code></a> option lets CPAN shells know to install Module::Build before they can start building the module. Unfortunately only the latest CPAN shells know about configure_requires.</p>\n\n<p>Oh, whatever you do don\'t use h2xs (unless you\'re writing XS code... and even then think about it).</p>\n\n<h2>MakeMaker Pros:</h2>\n\n<ul>\n<li>Comes with Perl and used by the Perl core (therefore it is actively\nmaintained and will remain so forever)</li>\n<li>Everything knows what to do with a Makefile.PL.</li>\n<li>Most module authoring documentation will cover MakeMaker.</li>\n<li>Uses make (those who know make can debug and patch the build\nprocess)</li>\n</ul>\n\n<h2>MakeMaker Cons:</h2>\n\n<ul>\n<li>Requires make (think Windows)</li>\n<li>Difficult to customize</li>\n<li>Even harder to customize and make cross platform</li>\n<li>Difficult to debug when something goes wrong (unless you understand make)</li>\n</ul>\n\n<h2>Module::Build Pros:</h2>\n\n<ul>\n<li>Easier to customize/subclass</li>\n<li>Pure Perl</li>\n<li>Easier to debug (it\'s Perl)</li>\n<li>Can emulate MakeMaker in several ways</li>\n<li>The CPAN shell will install Module::Build for you</li>\n</ul>\n\n<h2>Module::Build Cons:</h2>\n\n<ul>\n<li>The Module::Build maintainers (and indeed all of the Perl Toolchain Gang) hate it </li>\n<li>Older versions of CPAN clients (including CPANPLUS) don\'t know anything about Module::Build.</li>\n</ul>\n\n<h2>Module::Install Pros:</h2>\n\n<ul>\n<li>Slick interface</li>\n<li>Bundles itself, you have a known version</li>\n<li>Everything knows how to deal with a Makefile.PL</li>\n</ul>\n\n<h2>Module::Install Cons:</h2>\n\n<ul>\n<li>Requires make</li>\n<li>Always uses bundled version, vulnerable to external breakage</li>\n<li>Difficult to customize outside its interface</li>\n<li>Mucks with the guts of MakeMaker so a new MakeMaker release will eventually break it.</li>\n<li>Does not know how to generate a META file using the v2 meta-spec\n(increasingly a problem with newer tools)</li>\n</ul>\n'}, {'answer_id': 214720, 'author': 'Schwern', 'author_id': 14660, 'author_profile': 'https://Stackoverflow.com/users/14660', 'pm_score': 4, 'selected': False, 'text': '<p>You also might want to look at <a href="http://search.cpan.org/dist/Dist-Zilla/" rel="nofollow noreferrer">Dist-Zilla</a> which is a new author-only tool to create distributions. Because it just helps build the distribution, it doesn\'t ship with your code or do any installation, it can do a lot of powerful stuff.</p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73889', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/8233/'] |
73,892 | <p>How can I <strong>pre pend</strong> (insert at beginning of file) a file to all files of a type in folder and sub-folders using <code>Powershell</code>?</p>
<p>I need to add a standard header file to all <code>.cs</code> and was trying to use <code>Powershell</code> to do so, but while I was able to append it in a few lines of code I was stuck when trying to <strong>pre-pend</strong> it.</p>
| [{'answer_id': 74035, 'author': 'agnul', 'author_id': 6069, 'author_profile': 'https://Stackoverflow.com/users/6069', 'pm_score': 1, 'selected': False, 'text': '<p>Have no idea, but if you have the code to append just do it the other way round. Something like</p>\n\n<ol>\n<li>rename existing file,</li>\n<li>create an empty file named the same as above </li>\n<li>append header to new empty file,</li>\n<li>append renamed file to previous,</li>\n<li>delete renamed file</li>\n</ol>\n'}, {'answer_id': 74072, 'author': 'Vhaerun', 'author_id': 11234, 'author_profile': 'https://Stackoverflow.com/users/11234', 'pm_score': 1, 'selected': False, 'text': "<p>Algorithmically talking , you don't really need a temporary file :</p>\n\n<p>1)read the content of the file you need to modify</p>\n\n<p>2)modify the content ( as a string , assuming you have the content in a variable named content ) , like this : content = header + content</p>\n\n<p>3)seek to the beginning of the file , each language has a seek method or a seek equivalent</p>\n\n<p>4)write the new content</p>\n\n<p>5)truncate the file at the position returned by the file pointer</p>\n\n<p>There you have it,no temporary file. :)</p>\n"}, {'answer_id': 74073, 'author': 'Mark Schill', 'author_id': 9482, 'author_profile': 'https://Stackoverflow.com/users/9482', 'pm_score': 4, 'selected': True, 'text': '<p>Here is a very simple example to show you one of the ways it could be done.</p>\n\n<pre><code>$Content = "This is your content`n"\nGet-ChildItem *.cs | foreach-object { \n$FileContents = Get-Content -Path $_\nSet-Content -Path $_ -Value ($Content + $FileContents)\n}\n</code></pre>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73892', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/11673/'] |
73,895 | <p>Has anyone run into issues serializing components into a file and reading them back, specifically in the area where the component vendor upgrades the VCL components. For example a file serialized with DelphiX and then years later read back with delphiY. Do the serialization formats change and if so what can be done to prevent errors reading in the componets when upgrading.</p>
| [{'answer_id': 73990, 'author': 'Birger', 'author_id': 11485, 'author_profile': 'https://Stackoverflow.com/users/11485', 'pm_score': 0, 'selected': False, 'text': "<p>Formats will defintely change, as vendors will add features to their components. Serialization simply loops over all published properties and saves them to a stream. When they are read back, each of the properties that is read from the stream will be set back to the component. If the property does not exist anymore, you have a problem. I don't think you can do anything about that besides some basic exception handling.</p>\n\n<p>Best way to guarantee compatibility is to do your own serialization.</p>\n"}, {'answer_id': 74244, 'author': 'Peter', 'author_id': 12833, 'author_profile': 'https://Stackoverflow.com/users/12833', 'pm_score': 0, 'selected': False, 'text': '<p>Thanks for the reply. I was trying to avoid custom serialization and take advantage of the each component serialization technique, but with the lack opf any way to "patch" an upgrade to a new component format I guess custom serialization is the only method.</p>\n'}, {'answer_id': 74300, 'author': 'Lars Fosdal', 'author_id': 10002, 'author_profile': 'https://Stackoverflow.com/users/10002', 'pm_score': 3, 'selected': True, 'text': '<p>The built-in RTTI based system for serializing published properties is vulnerable to changes in the components. Going forwards is manageable as long as old properties are kept in new objects. I.e. you leave the property interface as is, but can toss away the contents if you like. Going backwards is worse - as a newer version saved property can\'t be opened in older version load, and that will be a problem.</p>\n\n<p>There are components / libs (<a href="http://www.torry.net/quicksearchd.php?String=RTTI&Title=Yes" rel="nofollow noreferrer">http://www.torry.net/quicksearchd.php?String=RTTI&Title=Yes</a>) that can add serialization in XML format and this may help a bit as you can choose to skip content you don\'t know.</p>\n\n<p>You still need to be mindful about how you design your published content and should probably find a way to "ignore but propagate" content that your current version don\'t understand. This will allow you to open and change a file in a newer format while attempting to keep newer attributes, instead of stripping them.</p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73895', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12833/'] |
73,902 | <p>Is there someway to have a part of the page that renders like a little sub-page, like components?</p>
<p>For example, if I have a shopping cart on all my pages?</p>
| [{'answer_id': 73917, 'author': 'DevelopingChris', 'author_id': 1220, 'author_profile': 'https://Stackoverflow.com/users/1220', 'pm_score': 3, 'selected': False, 'text': '<p>Using preview 5, Html.RenderPartial is your man, you can render sub-controls, and pass them your viewdata, or an arbitrary model, and new viewdata combo.</p>\n'}, {'answer_id': 73973, 'author': 'DevelopingChris', 'author_id': 1220, 'author_profile': 'https://Stackoverflow.com/users/1220', 'pm_score': 4, 'selected': True, 'text': '<p>If you want it to render another controllers action, as a component, to get encapsulation, you use.</p>\n\n<p>Html.RenderAction</p>\n\n<p>uses routedata to get you there, has its own viewdata and kind of mini life cycle</p>\n'}, {'answer_id': 74280, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': False, 'text': '<p>You can create an ActionFilter that modifies the view data. That way, you can decorate every action that returns the partial with the action filter. Take a look at my post:</p>\n\n<p><a href="http://stephenwalther.com/blog/archive/2008/08/12/asp-net-mvc-tip-31-passing-data-to-master-pages-and-user-controls.aspx" rel="nofollow noreferrer">http://stephenwalther.com/blog/archive/2008/08/12/asp-net-mvc-tip-31-passing-data-to-master-pages-and-user-controls.aspx</a></p>\n'}, {'answer_id': 78286, 'author': 'Matt Hinze', 'author_id': 2676, 'author_profile': 'https://Stackoverflow.com/users/2676', 'pm_score': 1, 'selected': False, 'text': '<p>You are looking for <a href="http://groups.google.com/group/mvccontrib-discuss/browse_thread/thread/b050e21fe322c08a" rel="nofollow noreferrer">subcontrollers</a>. This implementation is the best way to do what you are talking about.</p>\n\n<p>Edit: I just posted about this here: <a href="http://mhinze.com/subcontrollers-in-aspnet-mvc/" rel="nofollow noreferrer">http://mhinze.com/subcontrollers-in-aspnet-mvc/</a></p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73902', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/11559/'] |
73,910 | <p>I would like to write small console based applications on Windows Mobile. What console applications might I use?</p>
| [{'answer_id': 74020, 'author': 'Ryan Steckler', 'author_id': 12673, 'author_profile': 'https://Stackoverflow.com/users/12673', 'pm_score': 0, 'selected': False, 'text': "<p>There is no command prompt style console on Windows Mobile. If you're really after a command prompt, check out www.pocketdos.com for a high level of dos application compatibility.\nIf you're more interested in writing small applications for Windows Mobile, C# or VB.Net are your best choices.\nOn small mobile devices like this, command prompts are significantly harder for users to interact with compared to GUI based applications.</p>\n"}, {'answer_id': 9212727, 'author': 'Willem Hengeveld', 'author_id': 1049677, 'author_profile': 'https://Stackoverflow.com/users/1049677', 'pm_score': 1, 'selected': False, 'text': "<p>it may be useful to know that when you use printf from a standard windows mobile application, the output will end up in the kernel log of the device.</p>\n\n<p>This has several drawbacks:\n * Access to the kernellog is manufacturer+device dependent.\n * The length of the string you can print is limited to 255 characters.</p>\n\n<p>if you run your tool in the visualstudio environment in the debugger, you will get the output of the printf's in your log window.</p>\n"}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73910', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1856916/'] |
73,927 | <p>I'm looking into clustering points on a map (latitude/longitude). Are there any recommendations as to a suitable algorithm that is fast and scalable?</p>
<p>More specifically, I have a series of latitude/longitude coordinates and a map viewport. I'm trying to cluster the points that are close together in order to remove clutter.</p>
<p>I already have a solution to the problem (<a href="http://bouldr.net" rel="noreferrer">see here</a>), only I am wondering if there is any formal algorithm that solves the problem efficiently.</p>
| [{'answer_id': 73998, 'author': 'Paul Reiners', 'author_id': 7648, 'author_profile': 'https://Stackoverflow.com/users/7648', 'pm_score': 3, 'selected': False, 'text': '<p><em>Google Maps Hacks</em> has a hack, <a href="https://flylib.com/books/en/2.367.1/hack_69_cluster_markers_at_high_zoom_levels.html" rel="nofollow noreferrer">"Hack 69. Cluster Markers at High Zoom Levels"</a>, on that.</p>\n<p>Also, see <a href="http://en.wikipedia.org/wiki/Data_clustering" rel="nofollow noreferrer">Wikipedia on clustering algorithms</a>.</p>\n'}, {'answer_id': 125455, 'author': 'Geri Langlois', 'author_id': 4888, 'author_profile': 'https://Stackoverflow.com/users/4888', 'pm_score': 4, 'selected': True, 'text': '<p>For a virtual earth application I\'ve used the clustering described \n<a href="https://web.archive.org/web/20130410092213/http://www.soulsolutions.com.au/Articles/ClusteringVirtualEarthPart1.aspx" rel="nofollow noreferrer">here</a>. It\'s lightning fast and easily extensible.</p>\n'}, {'answer_id': 561344, 'author': 'David Dean', 'author_id': 67829, 'author_profile': 'https://Stackoverflow.com/users/67829', 'pm_score': 2, 'selected': False, 'text': '<p>You could look at indexing all your points using a <a href="http://wiki.openstreetmap.org/wiki/QuadTiles" rel="nofollow noreferrer">QuadTile</a> scheme, and then based upon the scale the further down the quad-splits you go. All similarly located points will then be near each other in your index, allowing the clustering to happen efficiently.</p>\n\n<p>QuadTiles are an example of <a href="http://en.wikipedia.org/wiki/Morton_number_(number_theory)" rel="nofollow noreferrer">Morton Codes</a>, and there is a python example linked from that wikipedia article that may help.</p>\n'}, {'answer_id': 18633159, 'author': 'user1530779', 'author_id': 1530779, 'author_profile': 'https://Stackoverflow.com/users/1530779', 'pm_score': 1, 'selected': False, 'text': '<p>I looked at various libraries and found them so complex couldn\'t understand a word so I decided to make my own clustering algorithm</p>\n\n<p>Here goes my code in Java</p>\n\n<pre><code>static int OFFSET = 268435456;\n static double RADIUS = 85445659.4471;\n static double pi = 3.1444;\n\npublic static double lonToX(double lon) {\n return Math.round(OFFSET + RADIUS * lon * pi / 180);\n }\n\n public static double latToY(double lat) {\n return Math.round(OFFSET\n - RADIUS\n * Math.log((1 + Math.sin(lat * pi / 180))\n / (1 - Math.sin(lat * pi / 180))) / 2);\n }\n</code></pre>\n\n<p>// This calculates the pixel distance between tow lat long points at a particular zoom level </p>\n\n<pre><code> public static int pixelDistance(double lat1, double lon1, double lat2,\n double lon2, int zoom) {\n double x1 = lonToX(lon1);\n double y1 = latToY(lat1);\n\n double x2 = lonToX(lon2);\n double y2 = latToY(lat2);\n\n return (int) (Math\n .sqrt(Math.pow((x1 - x2), 2) + Math.pow((y1 - y2), 2))) >> (21 - zoom);\n }\n</code></pre>\n\n<p>// The main function which actually calculates the clusters\n1. ArrayList of lat long points is iterated to length .\n2. inner loop a copy of the same arraylist is iterated from i+1 position ie leaving the top loop\'s index\n3. 0th element is taken as the centre of centroid and all other points are compared if their pixel distance is very less add it into cluster\n4. remove all elements from top arraylist and copy arraylist which have formed cluster\n5 restart the process by reinitializing the index from 0;\n6 if the centroid selected has no clusters then that element is not deleted</p>\n\n<pre><code>static ArrayList<Cluster> cluster(ArrayList<Marker> markers, int zoom) {\n\n ArrayList<Cluster> clusterList = new ArrayList<Cluster>();\n\n ArrayList<Marker> originalListCopy = new ArrayList<Marker>();\n\n for (Marker marker : markers) {\n originalListCopy.add(marker);\n }\n\n /* Loop until all markers have been compared. */\n for (int i = 0; i < originalListCopy.size();) {\n\n /* Compare against all markers which are left. */\n\n ArrayList<Marker> markerList = new ArrayList<Marker>();\n for (int j = i + 1; j < markers.size();) {\n int pixelDistance = pixelDistance(markers.get(i).getLatitude(),\n markers.get(i).getLongitude(), markers.get(j)\n .getLatitude(), markers.get(j).getLongitude(),\n zoom);\n\n if (pixelDistance < 40) {\n\n markerList.add(markers.get(i));\n markerList.add(markers.get(j));\n\n markers.remove(j);\n\n originalListCopy.remove(j);\n j = i + 1;\n } else {\n j++;\n }\n\n }\n\n if (markerList.size() > 0) {\n Cluster cluster = new Cluster(clusterList.size(), markerList,\n markerList.size() + 1, originalListCopy.get(i)\n .getLatitude(), originalListCopy.get(i)\n .getLongitude());\n clusterList.add(cluster);\n originalListCopy.remove(i);\n markers.remove(i);\n i = 0;\n\n } else {\n i++;\n }\n\n /* If a marker has been added to cluster, add also the one */\n /* we were comparing to and remove the original from array. */\n\n }\n return clusterList;\n }\n\nJust pass in your array list here containing latitude and longitude\n\nthen to display clusters\nhere goes the function\n\n\n@Override\n public void onTaskCompleted(ArrayList<FlatDetails> flatDetailsList) {\n\n LatLngBounds.Builder builder = new LatLngBounds.Builder();\n\n originalListCopy = new ArrayList<FlatDetails>();\n ArrayList<Marker> markersList = new ArrayList<Marker>();\n for (FlatDetails detailList : flatDetailsList) {\n\n markersList.add(new Marker(detailList.getLatitude(), detailList\n .getLongitude(), detailList.getApartmentTypeString()));\n\n originalListCopy.add(detailList);\n\n builder.include(new LatLng(detailList.getLatitude(), detailList\n .getLongitude()));\n\n }\n\n LatLngBounds bounds = builder.build();\n int padding = 0; // offset from edges of the map in pixels\n CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);\n\n googleMap.moveCamera(cu);\n\n ArrayList<Cluster> clusterList = Utils.cluster(markersList,\n (int) googleMap.getCameraPosition().zoom);\n\n // Removes all markers, overlays, and polylines from the map.\n googleMap.clear();\n\n // Zoom in, animating the camera.\n googleMap.animateCamera(CameraUpdateFactory.zoomTo(previousZoomLevel),\n 2000, null);\n\n CircleOptions circleOptions = new CircleOptions().center(point) //\n // setcenter\n .radius(3000) // set radius in meters\n .fillColor(Color.TRANSPARENT) // default\n .strokeColor(Color.BLUE).strokeWidth(5);\n\n googleMap.addCircle(circleOptions);\n\n for (Marker detail : markersList) {\n\n if (detail.getBhkTypeString().equalsIgnoreCase("1 BHK")) {\n googleMap.addMarker(new MarkerOptions()\n .position(\n new LatLng(detail.getLatitude(), detail\n .getLongitude()))\n .snippet(String.valueOf(""))\n .title("Flat" + flatDetailsList.indexOf(detail))\n .icon(BitmapDescriptorFactory\n .fromResource(R.drawable.bhk1)));\n } else if (detail.getBhkTypeString().equalsIgnoreCase("2 BHK")) {\n googleMap.addMarker(new MarkerOptions()\n .position(\n new LatLng(detail.getLatitude(), detail\n .getLongitude()))\n .snippet(String.valueOf(""))\n .title("Flat" + flatDetailsList.indexOf(detail))\n .icon(BitmapDescriptorFactory\n .fromResource(R.drawable.bhk_2)));\n\n }\n\n else if (detail.getBhkTypeString().equalsIgnoreCase("3 BHK")) {\n googleMap.addMarker(new MarkerOptions()\n .position(\n new LatLng(detail.getLatitude(), detail\n .getLongitude()))\n .snippet(String.valueOf(""))\n .title("Flat" + flatDetailsList.indexOf(detail))\n .icon(BitmapDescriptorFactory\n .fromResource(R.drawable.bhk_3)));\n\n } else if (detail.getBhkTypeString().equalsIgnoreCase("2.5 BHK")) {\n googleMap.addMarker(new MarkerOptions()\n .position(\n new LatLng(detail.getLatitude(), detail\n .getLongitude()))\n .snippet(String.valueOf(""))\n .title("Flat" + flatDetailsList.indexOf(detail))\n .icon(BitmapDescriptorFactory\n .fromResource(R.drawable.bhk2)));\n\n } else if (detail.getBhkTypeString().equalsIgnoreCase("4 BHK")) {\n googleMap.addMarker(new MarkerOptions()\n .position(\n new LatLng(detail.getLatitude(), detail\n .getLongitude()))\n .snippet(String.valueOf(""))\n .title("Flat" + flatDetailsList.indexOf(detail))\n .icon(BitmapDescriptorFactory\n .fromResource(R.drawable.bhk_4)));\n\n } else if (detail.getBhkTypeString().equalsIgnoreCase("5 BHK")) {\n googleMap.addMarker(new MarkerOptions()\n .position(\n new LatLng(detail.getLatitude(), detail\n .getLongitude()))\n .snippet(String.valueOf(""))\n .title("Flat" + flatDetailsList.indexOf(detail))\n .icon(BitmapDescriptorFactory\n .fromResource(R.drawable.bhk5)));\n\n } else if (detail.getBhkTypeString().equalsIgnoreCase("5+ BHK")) {\n googleMap.addMarker(new MarkerOptions()\n .position(\n new LatLng(detail.getLatitude(), detail\n .getLongitude()))\n .snippet(String.valueOf(""))\n .title("Flat" + flatDetailsList.indexOf(detail))\n .icon(BitmapDescriptorFactory\n .fromResource(R.drawable.bhk_5)));\n\n }\n\n else if (detail.getBhkTypeString().equalsIgnoreCase("2 BHK")) {\n googleMap.addMarker(new MarkerOptions()\n .position(\n new LatLng(detail.getLatitude(), detail\n .getLongitude()))\n .snippet(String.valueOf(""))\n .title("Flat" + flatDetailsList.indexOf(detail))\n .icon(BitmapDescriptorFactory\n .fromResource(R.drawable.bhk_2)));\n\n }\n }\n\n for (Cluster cluster : clusterList) {\n\n BitmapFactory.Options options = new BitmapFactory.Options();\n options.inMutable = true;\n options.inPurgeable = true;\n Bitmap bitmap = BitmapFactory.decodeResource(getResources(),\n R.drawable.cluster_marker, options);\n\n Canvas canvas = new Canvas(bitmap);\n\n Paint paint = new Paint();\n paint.setColor(getResources().getColor(R.color.white));\n paint.setTextSize(30);\n\n canvas.drawText(String.valueOf(cluster.getMarkerList().size()), 10,\n 40, paint);\n\n googleMap.addMarker(new MarkerOptions()\n .position(\n new LatLng(cluster.getClusterLatitude(), cluster\n .getClusterLongitude()))\n .snippet(String.valueOf(cluster.getMarkerList().size()))\n .title("Cluster")\n .icon(BitmapDescriptorFactory.fromBitmap(bitmap)));\n\n }\n\n }\n\n\n\n\nANY QUESTIONS OR DOUBTS PLEASE ASK WILL CLEAR THEM ALL ...........THANKS\n</code></pre>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73927', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12037/'] |
73,930 | <p>What do I need to add to my <code>.spec</code> file to create the desktop shortcut and assign an icon to the shortcut during install of my <code>.rpm</code>? If a script is required, an example would be very helpful.</p>
| [{'answer_id': 74003, 'author': 'akdom', 'author_id': 145, 'author_profile': 'https://Stackoverflow.com/users/145', 'pm_score': 3, 'selected': False, 'text': "<p>You use a .desktop file for icons under linux. Where to put the icon depends on what distribution and what desktop environment you are using. Since I'm currently running Gnome on Fedora 9, I will answer it in those terms.</p>\n<p>An example foo.desktop file would be:</p>\n<pre><code>[Desktop Entry]\nEncoding=UTF-8\nGenericName=Generic Piece Of Software\nName=FooBar\nExec=/usr/bin/foo.sh\nIcon=foo.png\nTerminal=false\nType=Application\nCategories=Qt;Gnome;Applications;\n</code></pre>\n<p>The .desktop file should under Fedora 9 Gnome be located in /usr/share/applications/ , you can run a locate on .desktop to figure out where you should put in on your distro. Gnome will generally look in the KDE icon directory to see if there are other icons there also....</p>\n<blockquote>\n<p>Encoding, Name and Exec should speak for themselves.</p>\n<ul>\n<li>Generic name == Brief Description of application.</li>\n<li>Icon == The image to display for the icon</li>\n<li>Terminal == Is this a terminal application, should I start it as one?</li>\n<li>Type == Type of program this is, can be used in placing the icon in a menu.</li>\n<li>Categories == This information is what is mainly used to place the icon in a given menu if an XML file to specify such is not present. The setup for menus is handled a little differently by everyone.</li>\n</ul>\n</blockquote>\n<p>There are more attributes you can set, but they aren't strictly necessary.</p>\n<p>The image file used sits somewhere in the bowels of the /usr/share/icons/ directory. You can parse through that to find all the wonders of how such things work, but the basics are that you pick the directory for the icon type (in my case gnome) and place the image within the appropriate directory (there is a scalable directory for .svg images, and specific sizes such as 48x48 for raster images. Under Gnome all images are generally .png).</p>\n"}, {'answer_id': 75904, 'author': 'SpoonMeiser', 'author_id': 1577190, 'author_profile': 'https://Stackoverflow.com/users/1577190', 'pm_score': 2, 'selected': False, 'text': '<p>akdom has given a fairly good answer, but doesn\'t do its relevance justice.</p>\n\n<p>Many common desktops, including Gnome, KDE and XFCE where relevant, implement the specifications laid out by <a href="http://www.freedesktop.org/" rel="nofollow noreferrer">freedesktop.org</a>. Among these, is the <a href="http://standards.freedesktop.org/desktop-entry-spec/latest/" rel="nofollow noreferrer">Desktop Entry Specification</a> which describes the format of files that define desktop icons, and <a href="http://standards.freedesktop.org/basedir-spec/latest/" rel="nofollow noreferrer">Desktop Base Directory Specification</a> that describes the locations that desktop environments should look to find these files.</p>\n\n<p>Your RPM needs to include a .desktop file, as specified by the <a href="http://standards.freedesktop.org/desktop-entry-spec/latest/" rel="nofollow noreferrer">Desktop Entry Specification</a>, and install it in the correct location as specified either by the <a href="http://standards.freedesktop.org/basedir-spec/latest/" rel="nofollow noreferrer">Desktop Base Directory Specification</a>, or in a distribution specific location (I imagine there will be aliases to use in the spec file for this location).</p>\n'}, {'answer_id': 36131913, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>To create a desktop icon to an application follow the two steps below.</p>\n\n<ol>\n<li><p>In an Editor create a new file.</p>\n\n<pre><code>gedit ~/.local/share/applications/NameYouWantForApplication.desktop\n</code></pre></li>\n<li><p>Place this section within the file and save it.</p>\n\n<pre><code>[Desktop Entry]\nType=Application\nEncoding=UTF-8\nName=JeremysPentaho\nComment=Whatever Comment You want\nExec=/home/[email protected]/Source/Pentaho/data-integration/spoon.sh\nIcon=/home/[email protected]/Source/Pentaho/data-integration/NameOfmyIconFile.jpg\nTerminal=false\n</code></pre></li>\n</ol>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73930', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/'] |
73,947 | <p>I'm talking about an action game with no upper score limit and no way to verify the score on the server by replaying moves etc. </p>
<p>What I really need is the strongest encryption possible in Flash/PHP, and a way to prevent people calling the PHP page other than through my Flash file. I have tried some simple methods in the past of making multiple calls for a single score and completing a checksum / fibonacci sequence etc, and also obfuscating the SWF with Amayeta SWF Encrypt, but they were all hacked eventually.</p>
<p>Thanks to StackOverflow responses I have now found some more info from Adobe - <a href="http://www.adobe.com/devnet/flashplayer/articles/secure_swf_apps_12.html" rel="noreferrer">http://www.adobe.com/devnet/flashplayer/articles/secure_swf_apps_12.html</a> and <a href="https://github.com/mikechambers/as3corelib" rel="noreferrer">https://github.com/mikechambers/as3corelib</a> - which I think I can use for the encryption. Not sure this will get me around CheatEngine though.</p>
<p>I need to know the best solutions for both AS2 and AS3, if they are different.</p>
<p>The main problems seem to be things like TamperData and LiveHTTP headers, but I understand there are more advanced hacking tools as well - like CheatEngine (thanks Mark Webster)</p>
| [{'answer_id': 74043, 'author': 'Stephen Deken', 'author_id': 7154, 'author_profile': 'https://Stackoverflow.com/users/7154', 'pm_score': 5, 'selected': False, 'text': '<p>You may be asking the wrong question. You seem focused on the methods people are using to game their way up the high score list, but blocking specific methods only goes so far. I have no experience with TamperData, so I can\'t speak to that.</p>\n\n<p>The question you should be asking is: "How can I verify that submitted scores are valid and authentic?" The specific way to do that is game-dependent. For very simple puzzle games, you might send over the score along with the specific starting state and the sequence of moves that resulted in the end state, and then re-run the game on the server side using the same moves. Confirm that the stated score is the same as the computed score and only accept the score if they match.</p>\n'}, {'answer_id': 74063, 'author': 'Oli', 'author_id': 12870, 'author_profile': 'https://Stackoverflow.com/users/12870', 'pm_score': 2, 'selected': False, 'text': "<p>Encrypting using a known (private) reversible key would be the simplest method. I'm not all up on AS so I'm not sure what sorts of encryption providers there are.</p>\n\n<p>But you could include variables like game-length (encrypted, again) and a click count.</p>\n\n<p>All things like this <em>can</em> be reverse engineered so consider throwing in a bunch of junk data to throw people off the scent.</p>\n\n<p>Edit: It might be worth chucking in some PHP sessions too. Start the session when they click start game and (as the comment to this post says) log the time. When they submit the score you can check they've actually got an open game and they're not submitting a score too soon or too large.</p>\n\n<p>It might be worth working out a scalar to see say what the maximum score is per second/minute of play.</p>\n\n<p>Neither of these things are uncircumventable but it'll help to have some logic not in the Flash where people can see it.</p>\n"}, {'answer_id': 74069, 'author': 'Jan Krüger', 'author_id': 12471, 'author_profile': 'https://Stackoverflow.com/users/12471', 'pm_score': 1, 'selected': False, 'text': "<p>Whenever your highscore system is based on the fact that the Flash application sends unencrpyted/unsigned highscore data via the network, that can be intercepted and manipulated/replayed. The answer follows from that: encrypt (decently!) or cryptographically sign highscore data. This, at least, makes it harder for people to crack your highscore system because they'll need to extract the secret key from your SWF file. Many people will probably give up right there. On the other hand, all it takes is a singly person to extract the key and post it somewhere.</p>\n\n<p>Real solutions involve more communication between the Flash application and the highscore database so that the latter can verify that a given score is somewhat realistic. This is probably complicated depending on what kind of game you've got.</p>\n"}, {'answer_id': 74128, 'author': 'David Arno', 'author_id': 7122, 'author_profile': 'https://Stackoverflow.com/users/7122', 'pm_score': 2, 'selected': False, 'text': '<p>There is no way to make it completely unhackable, as it is easy to decompile SWFs, and a skilled developer hacker could then trace through your code and work out how to bypass any encrypted system you might employ.</p>\n\n<p>If you simply want to stop kids cheating via the use of simple tools like TamperData though, then you could generate an encryption key that you pass to the SWF at startup. Then use something like <a href="http://code.google.com/p/as3crypto/" rel="nofollow noreferrer">http://code.google.com/p/as3crypto/</a> to encrypt the high score before passing it back to the PHP code. Then decrypt it at the server end before storing it in the database.</p>\n'}, {'answer_id': 74242, 'author': 'Mark Webster', 'author_id': 7068, 'author_profile': 'https://Stackoverflow.com/users/7068', 'pm_score': 1, 'selected': False, 'text': '<p>It\'s not really possible to achieve what you want. The internals of the Flash app are always partially accessible, especially when you know how to use things like <a href="http://www.cheatengine.org/" rel="nofollow noreferrer">CheatEngine</a>, meaning no matter how secure your website and browser<->server communications are, it is still going to be relatively simple to overcome.</p>\n'}, {'answer_id': 74448, 'author': 'stormlash', 'author_id': 12657, 'author_profile': 'https://Stackoverflow.com/users/12657', 'pm_score': 4, 'selected': False, 'text': '<p>An easy way to do this would be to provide a cryptographic hash of your highscore value along with the score it self. For example, when posting the results via HTTP GET:\n<strong><a href="http://example.com/highscores.php?score=500&checksum=0a16df3dc0301a36a34f9065c3ff8095" rel="noreferrer">http://example.com/highscores.php?score=500&checksum=0a16df3dc0301a36a34f9065c3ff8095</a></strong></p>\n\n<p>When calculating this checksum, a shared secret should be used; this secret should never be transmitted over the network, but should be hard coded within both the PHP backend and the flash frontend. The checksum above was created by prepending the string "<strong>secret</strong>" to the score "<strong>500</strong>", and running it through md5sum.</p>\n\n<p>Although this system will prevent a user from posting arbitrary scores, it does not prevent a "replay attack", where a user reposts a previously calculated score and hash combination. In the example above, a score of 500 would always produce the same hash string. Some of this risk can be mitigated by incorporating more information (such as a username, timestamp, or IP address) in the string which is to be hashed. Although this will not prevent the replay of data, it will insure that a set of data is only valid for a single user at a single time.</p>\n\n<p>To prevent <strong>any</strong> replay attacks from occurring, some type of challenge-response system will have to be created, such as the following:</p>\n\n<ol>\n<li>The flash game ("the client") performs an HTTP GET of <strong><a href="http://example.com/highscores.php" rel="noreferrer">http://example.com/highscores.php</a></strong> with no parameters. This page returns two values: a randomly generated <em>salt</em> value, and a cryptographic hash of that salt value combined with the shared secret. This salt value should be stored in a local database of pending queries, and should have a timestamp associated with it so that it can "expire" after perhaps one minute.</li>\n<li>The flash game combines the salt value with the shared secret and calculates a hash to verify that this matches the one provided by the server. This step is necessary to prevent tampering with salt values by users, as it verifies that the salt value was actually generated by the server.</li>\n<li>The flash game combines the salt value with the shared secret, high score value, and any other relevant information (nickname, ip, timestamp), and calculates a hash. It then sends this information back to the PHP backend via HTTP GET or POST, along with the salt value, high score, and other information.</li>\n<li>The server combines the information received in the same way as on the client, and calculates a hash to verify that this matches the one provided by the client. It then also verifies that the salt value is still valid as listed in the pending query list. If both these conditions are true, it writes the high score to the high score table and returns a signed "success" message to the client. It also removes the salt value from the pending query list.</li>\n</ol>\n\n<p><strong>Please keep in mind that the security of any of the above techniques is compromised if the shared secret is ever accessible to the user</strong></p>\n\n<p>As an alternative, some of this back-and-forth could be avoided by forcing the client to communicate with the server over HTTPS, and insuring that the client is preconfigured to trust only certificates signed by a specific certificate authority which you alone have access to.</p>\n'}, {'answer_id': 74505, 'author': 'Peter Bailey', 'author_id': 8815, 'author_profile': 'https://Stackoverflow.com/users/8815', 'pm_score': 2, 'selected': False, 'text': '<p>You are talking about what is called the "client trust" problem. Because the client (in this cash, a SWF running in a browser) is doing something it\'s designed to do. Save a high score.</p>\n\n<p>The problem is that you want to make sure that "save score" requests are coming from your flash movie, and not some arbitrary HTTP request. A possible solution for this is to encode a token generated by the server into the SWF at the time of request (using <a href="http://flasm.sourceforge.net/" rel="nofollow noreferrer">flasm</a>) that must accompany the request to save a high score. Once the server saves that score, the token is expired and can no longer be used for requests.</p>\n\n<p>The downside of this is that a user will only be able to submit one high score per load of the flash movie - you\'ve have to force them to refresh/reload the SWF before they can play again for a new score.</p>\n'}, {'answer_id': 74841, 'author': 'tqbf', 'author_id': 5674, 'author_profile': 'https://Stackoverflow.com/users/5674', 'pm_score': 10, 'selected': True, 'text': '<p>This is a classic problem with Internet games and contests. Your Flash code works with users to decide a score for a game. But users aren\'t trusted, and the Flash code runs on the user\'s computer. You\'re SOL. There is nothing you can do to prevent an attacker from forging high scores:</p>\n\n<ul>\n<li><p>Flash is even easier to reverse engineer than you might think it is, since the bytecodes are well documented and describe a high-level language (Actionscript) --- when you publish a Flash game, you\'re publishing your source code, whether you know it or not.</p></li>\n<li><p>Attackers control the runtime memory of the Flash interpreter, so that anyone who knows how to use a programmable debugger can alter any variable (including the current score) at any time, or alter the program itself.</p></li>\n</ul>\n\n<p>The simplest possible attack against your system is to run the HTTP traffic for the game through a proxy, catch the high-score save, and replay it with a higher score.</p>\n\n<p>You can try to block this attack by binding each high score save to a single instance of the game, for instance by sending an encrypted token to the client at game startup, which might look like:</p>\n\n<pre><code>hex-encoding( AES(secret-key-stored-only-on-server, timestamp, user-id, random-number))\n</code></pre>\n\n<p>(You could also use a session cookie to the same effect).</p>\n\n<p>The game code echoes this token back to the server with the high-score save. But an attacker can still just launch the game again, get a token, and then immediately paste that token into a replayed high-score save. </p>\n\n<p>So next you feed not only a token or session cookie, but also a high-score-encrypting session key. This will be a 128 bit AES key, itself encrypted with a key hardcoded into the Flash game:</p>\n\n<pre><code>hex-encoding( AES(key-hardcoded-in-flash-game, random-128-bit-key))\n</code></pre>\n\n<p>Now before the game posts the high score, it decrypts the high-score-encrypting-session key, which it can do because you hardcoded the high-score-encrypting-session-key-decrypting-key into the Flash binary. You encrypt the high score with this decrypted key, along with the SHA1 hash of the high score:</p>\n\n<pre><code>hex-encoding( AES(random-128-bit-key-from-above, high-score, SHA1(high-score)))\n</code></pre>\n\n<p>The PHP code on the server checks the token to make sure the request came from a valid game instance, then decrypts the encrypted high score, checking to make sure the high-score matches the SHA1 of the high-score (if you skip this step, decryption will simply produce random, likely very high, high scores). </p>\n\n<p>So now the attacker decompiles your Flash code and quickly finds the AES code, which sticks out like a sore thumb, although even if it didn\'t it\'d be tracked down in 15 minutes with a memory search and a tracer ("I know my score for this game is 666, so let\'s find 666 in memory, then catch any operation that touches that value --- oh look, the high score encryption code!"). With the session key, the attacker doesn\'t even have to run the Flash code; she grabs a game launch token and a session key and can send back an arbitrary high score.</p>\n\n<p>You\'re now at the point where most developers just give up --- give or take a couple months of messing with attackers by:</p>\n\n<ul>\n<li><p>Scrambling the AES keys with XOR operations</p></li>\n<li><p>Replacing key byte arrays with functions that calculate the key</p></li>\n<li><p>Scattering fake key encryptions and high score postings throughout the binary.</p></li>\n</ul>\n\n<p>This is all mostly a waste of time. It goes without saying, SSL isn\'t going to help you either; SSL can\'t protect you when one of the two SSL endpoints is evil.</p>\n\n<p>Here are some things that can actually reduce high score fraud:</p>\n\n<ul>\n<li><p>Require a login to play the game, have the login produce a session cookie, and don\'t allow multiple outstanding game launches on the same session, or multiple concurrent sessions for the same user.</p></li>\n<li><p>Reject high scores from game sessions that last less than the shortest real games ever played (for a more sophisticated approach, try "quarantining" high scores for game sessions that last less than 2 standard deviations below the mean game duration). Make sure you\'re tracking game durations serverside.</p></li>\n<li><p>Reject or quarantine high scores from logins that have only played the game once or twice, so that attackers have to produce a "paper trail" of reasonable looking game play for each login they create.</p></li>\n<li><p>"Heartbeat" scores during game play, so that your server sees the score growth over the lifetime of one game play. Reject high scores that don\'t follow reasonable score curves (for instance, jumping from 0 to 999999). </p></li>\n<li><p>"Snapshot" game state during game play (for instance, amount of ammunition, position in the level, etc), which you can later reconcile against recorded interim scores. You don\'t even have to have a way to detect anomalies in this data to start with; you just have to collect it, and then you can go back and analyze it if things look fishy.</p></li>\n<li><p>Disable the account of any user who fails one of your security checks (for instance, by ever submitting an encrypted high score that fails validation). </p></li>\n</ul>\n\n<p>Remember though that you\'re only deterring high score fraud here. There\'s <em>nothing</em> you can do to prevent if. If there\'s money on the line in your game, someone is going to defeat any system you come up with. The objective isn\'t to <em>stop</em> this attack; it\'s to make the attack more expensive than just getting really good at the game and beating it.</p>\n'}, {'answer_id': 79423, 'author': 'DGM', 'author_id': 14253, 'author_profile': 'https://Stackoverflow.com/users/14253', 'pm_score': 4, 'selected': False, 'text': '<p>I like what tpqf said, but rather than disabling an account when cheating is discovered, implement a honeypot so whenever they log in, they see their hacked scores and never suspect that they have been marked as a troll. Google for "phpBB MOD Troll" and you\'ll see an ingenious approach.</p>\n'}, {'answer_id': 413336, 'author': 'Lucas Meijer', 'author_id': 47901, 'author_profile': 'https://Stackoverflow.com/users/47901', 'pm_score': 2, 'selected': False, 'text': '<p>I usually include "ghost data" of the game session with the highscore entry. So if I\'m making a racing game, I include the replay data. You often have the replay data already for replay functionality or ghost racing functionality (playing against your last race, or playing against the ghost of dude #14 on the leaderboard).</p>\n\n<p>Checking these is very manual labour, but if the goal is to verify if the top 10 entries in a contest are legit, this can be a useful addition to the arsenal of security measures others have pointed out already.</p>\n\n<p>If the goal is to keep highscores list online untill the end of time without anybody having to look at them, this won\'t bring you much.</p>\n'}, {'answer_id': 413794, 'author': 'Scott Reynen', 'author_id': 10837, 'author_profile': 'https://Stackoverflow.com/users/10837', 'pm_score': 2, 'selected': False, 'text': '<p>In my experience, this is best approached as a social engineering problem rather than a programming problem. Rather than focusing on making it impossible to cheat, focus on making it boring by removing the incentives to cheat. For example, if the main incentive is publicly visible high scores, simply putting a delay on when high scores are shown can significantly reduce cheating by removing the positive feedback loop for cheaters.</p>\n'}, {'answer_id': 2004006, 'author': 'Vaughn', 'author_id': 243636, 'author_profile': 'https://Stackoverflow.com/users/243636', 'pm_score': 2, 'selected': False, 'text': "<p>The way that a new popular arcade mod does it is that it sends data from the flash to php, back to flash (or reloads it), then back to php. This allows you to do anything you want to compare the data as well bypass post data/decryption hacks and the like. One way that it does this is by assigning 2 randomized values from php into the flash (which you cannot grab or see even if running a realtime flash data grabber), using a mathematical formula to add the score with the random values then checking it using the same formula to reverse it to see if the score matches it when it finally goes to the php at the end. These random values are never visible as well as it also times the transaction taking place and if it's any more than a couple seconds then it also flags it as cheating because it assumes you have stopped the send to try to figure out the randomized values or run the numbers through some type of cipher to return possible random values to compare with the score value.</p>\n\n<p>This seems like a pretty good solution if you ask me, does anybody see any issues with using this method? Or possible ways around it?</p>\n"}, {'answer_id': 7110508, 'author': 'divillysausages', 'author_id': 639441, 'author_profile': 'https://Stackoverflow.com/users/639441', 'pm_score': 2, 'selected': False, 'text': '<p>In the accepted answer tqbf mentions that you can just do a memory search for the score variable ("My score is 666 so I look for the number 666 in memory").</p>\n\n<p>There\'s a way around this. I have a class here: <a href="http://divillysausages.com/blog/safenumber_and_safeint" rel="nofollow">http://divillysausages.com/blog/safenumber_and_safeint</a></p>\n\n<p>Basically, you have an object to store your score. In the setter it multiplies the value that you pass it with a random number (+ and -), and in the getter you divide the saved value by the random multiplicator to get the original back. It\'s simple, but helps stop memory search.</p>\n\n<p>Also, check out the video from some of the guys behind the PushButton engine who talk about some of the different ways you can combat hacking: <a href="http://zaa.tv/2010/12/the-art-of-hacking-flash-games/" rel="nofollow">http://zaa.tv/2010/12/the-art-of-hacking-flash-games/</a>. They were the inspiration behind the class.</p>\n'}, {'answer_id': 8915028, 'author': 'mathieu landry', 'author_id': 1062353, 'author_profile': 'https://Stackoverflow.com/users/1062353', 'pm_score': 1, 'selected': False, 'text': '<p>I think the simplest way would be to make calls to a function like RegisterScore(score) each time the game registers a score to be added and then encode it, package it and send it to a php script as a string. The php script would know how to decode it properly. This would stop any calls straight to the php script as any tries to force a score would result in a decompression error.</p>\n'}, {'answer_id': 9590507, 'author': 'hurturk', 'author_id': 1233686, 'author_profile': 'https://Stackoverflow.com/users/1233686', 'pm_score': 2, 'selected': False, 'text': '<p>It is only possible by keeping the <strong>all game logic at server-side</strong> which also stores the score internally without knowledge of the user. For economical and scientific reasons, mankind can not apply this theory to all game types excluding turn-based. For e.g. keeping physics at server-side is computationally expensive and hard to get responsive as speed of hand. Even possible, while playing chess anyone can match AI chess gameplay to opponent. Therefore, better <strong>multiplayer games</strong> should also contain on-demand creativity.</p>\n'}, {'answer_id': 10725193, 'author': 'zeller', 'author_id': 1413277, 'author_profile': 'https://Stackoverflow.com/users/1413277', 'pm_score': 2, 'selected': False, 'text': "<p>You cannot trust any data the client returns. Validation needs to be performed on the server side. I'm not a game developer, but I do make business software. In both instances money can be involved and people will break client side obfuscation techniques.</p>\n\n<p>Maybe send data back to server periodically and do some validation. Don't focus on client code, even if that is where your applicaiton lives.</p>\n"}, {'answer_id': 17994553, 'author': 'Chris Panayotoff', 'author_id': 1584898, 'author_profile': 'https://Stackoverflow.com/users/1584898', 'pm_score': 2, 'selected': False, 'text': '<p>I made kind of workaround... I had a gave where scores incremented ( you always get +1 score ). First, I started to count from random num (let\'s say 14 ) and when I display the scores, just showed the scores var minus 14. This was so if the crackers are looking for example for 20, they won\'t find it ( it will be 34 in the memory ). Second, since I know what the next point should be... I used adobe crypto library, to create the hash of what the next point <strong>should be</strong>. When I have to increment the scores, I check if the hash of the incremented scores is equal to the hash is should be. If the cracker have changed the points in the memory, the hashes are not equal. I perform some server-side verification and when I got different points from game and from the PHP, I know that cheating were involved. Here is snippet ot my code ( I\'m using Adobe Crypto libraty MD5 class and random cryptography salt. callPhp() is my server side validation )</p>\n\n<pre><code>private function addPoint(event:Event = null):void{\n trace("expectedHash: " + expectedHash + " || new hash: " + MD5.hash( Number(SCORES + POINT).toString() + expectedHashSalt) );\n if(expectedHash == MD5.hash( Number(SCORES + POINT).toString() + expectedHashSalt)){\n SCORES +=POINT;\n callPhp();\n expectedHash = MD5.hash( Number(SCORES + POINT).toString() + expectedHashSalt);\n } else {\n //trace("cheat engine usage");\n }\n }\n</code></pre>\n\n<p>Using this technique + SWF obfustication, I was able to stop the crackers. Also, when I\'m sending the scores to the server-side, I use my own small, encryption / decryption function. Something like this (server side code not included, but you can see the algorithm and write it in PHP) :</p>\n\n<pre><code>package {\n\n import bassta.utils.Hash;\n\n public class ScoresEncoder {\n\n private static var ranChars:Array;\n private static var charsTable:Hash;\n\n public function ScoresEncoder() {\n\n }\n\n public static function init():void{\n\n ranChars = String("qwertyuiopasdfghjklzxcvbnm").split("")\n\n charsTable = new Hash({\n "0": "x",\n "1": "f",\n "2": "q",\n "3": "z",\n "4": "a",\n "5": "o",\n "6": "n",\n "7": "p",\n "8": "w",\n "9": "y"\n\n });\n\n }\n\n public static function encodeScore(_s:Number):String{\n\n var _fin:String = "";\n\n var scores:String = addLeadingZeros(_s);\n for(var i:uint = 0; i< scores.length; i++){\n //trace( scores.charAt(i) + " - > " + charsTable[ scores.charAt(i) ] );\n _fin += charsTable[ scores.charAt(i) ];\n }\n\n return _fin;\n\n }\n\n public static function decodeScore(_s:String):String{\n\n var _fin:String = "";\n\n var decoded:String = _s;\n\n for(var i:uint = 0; i< decoded.length; i++){\n //trace( decoded.charAt(i) + " - > " + charsTable.getKey( decoded.charAt(i) ) );\n _fin += charsTable.getKey( decoded.charAt(i) );\n }\n\n return _fin;\n\n }\n\n public static function encodeScoreRand(_s:Number):String{\n var _fin:String = "";\n\n _fin += generateRandomChars(10) + encodeScore(_s) + generateRandomChars(3)\n\n return _fin;\n }\n\n public static function decodeScoreRand(_s:String):Number{\n\n var decodedString:String = _s;\n var decoded:Number;\n\n decodedString = decodedString.substring(10,13); \n decodedString = decodeScore(decodedString);\n\n decoded = Number(decodedString);\n\n return decoded;\n }\n\n public static function generateRandomChars(_length:Number):String{\n\n var newRandChars:String = "";\n\n for(var i:uint = 0; i< _length; i++){\n newRandChars+= ranChars[ Math.ceil( Math.random()*ranChars.length-1 )];\n }\n\n return newRandChars;\n }\n\n private static function addLeadingZeros(_s:Number):String{\n\n var _fin:String;\n\n if(_s < 10 ){\n _fin = "00" + _s.toString();\n }\n\n if(_s >= 10 && _s < 99 ) {\n _fin = "0" + _s.toString();\n }\n\n if(_s >= 100 ) {\n _fin = _s.toString();\n } \n\n return _fin;\n }\n\n\n }//end\n}\n</code></pre>\n\n<p>Then I send the variable among with other fake-vars and it just get\'s lost among the way... It is a lot of work for just small flash game, but where prizes are involved some people just get greedy. If you need any help, write me a PM.</p>\n\n<p>Cheers, Ico</p>\n'}, {'answer_id': 23642533, 'author': 'm1gu3l', 'author_id': 3243730, 'author_profile': 'https://Stackoverflow.com/users/3243730', 'pm_score': 1, 'selected': False, 'text': '<p>It might be a good idea to communicate with backend via <a href="http://www.silexlabs.org/amfphp/" rel="nofollow">AMFPHP</a>. It should discourage at least the lazy ones from trying to push the results via browser console.</p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73947', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/11911/'] |
73,950 | <p>How can I combine multiple PDFs into one PDF without a 3rd party component?</p>
| [{'answer_id': 73987, 'author': 'Jorge Ferreira', 'author_id': 6508, 'author_profile': 'https://Stackoverflow.com/users/6508', 'pm_score': 2, 'selected': False, 'text': '<p>AFAIK C# has no built-in support for handling PDF so what you are asking can not be done without using a 3rd party component or a COTS library.</p>\n\n<p>Regarding libraries there is a myriad of possibilities. Just to point a few:</p>\n\n<p><a href="http://csharp-source.net/open-source/pdf-libraries" rel="nofollow noreferrer">http://csharp-source.net/open-source/pdf-libraries</a></p>\n\n<p><a href="http://www.codeproject.com/KB/graphics/giospdfnetlibrary.aspx" rel="nofollow noreferrer">http://www.codeproject.com/KB/graphics/giospdfnetlibrary.aspx</a></p>\n\n<p><a href="http://www.pdftron.com/net/index.html" rel="nofollow noreferrer">http://www.pdftron.com/net/index.html</a></p>\n'}, {'answer_id': 74031, 'author': 'vengafoo', 'author_id': 12834, 'author_profile': 'https://Stackoverflow.com/users/12834', 'pm_score': 3, 'selected': False, 'text': '<p>The .NET Framework does not contain the ability to modify/create PDFs. You need a 3rd party component to accomplish what you are looking for.</p>\n'}, {'answer_id': 74080, 'author': 'Sergey Volegov', 'author_id': 9024, 'author_profile': 'https://Stackoverflow.com/users/9024', 'pm_score': 4, 'selected': False, 'text': '<p>I don\'t think you can.\nOpensource component PDFSharp has that functionality, and a nice <a href="http://www.pdfsharp.com/PDFsharp/index.php?option=com_content&task=view&id=24&Itemid=35" rel="noreferrer" title="source sample">source code sample on file combining</a></p>\n'}, {'answer_id': 74122, 'author': 'Nathan Jones', 'author_id': 5848, 'author_profile': 'https://Stackoverflow.com/users/5848', 'pm_score': 2, 'selected': False, 'text': '<p>As others have said, there is nothing built in to do that task. Use <a href="http://itextsharp.sourceforge.net/" rel="nofollow noreferrer">iTextSharp</a> with this <a href="http://www.steedsoft.com/itextsharp/tutorial01/ap01Concat.cs.html" rel="nofollow noreferrer">example code</a>.</p>\n'}, {'answer_id': 74174, 'author': 'MagicKat', 'author_id': 8505, 'author_profile': 'https://Stackoverflow.com/users/8505', 'pm_score': -1, 'selected': False, 'text': '<p>Although it has already been said, you can\'t manipulate PDFs with the built-in libraries of the .NET Framework. I can however recommend <a href="http://itextsharp.sourceforge.net/" rel="nofollow noreferrer">iTextSharp</a>, which is a .NET port of the Java iText. I have played around with it, and found it to be a very easy tool to use.</p>\n'}, {'answer_id': 74276, 'author': 'Paul', 'author_id': 215086, 'author_profile': 'https://Stackoverflow.com/users/215086', 'pm_score': -1, 'selected': False, 'text': '<p><a href="http://itextsharp.sourceforge.net/" rel="nofollow noreferrer">ITextSharp</a> is the way to go</p>\n'}, {'answer_id': 22138935, 'author': 'Sajitha Rathnayake', 'author_id': 2345900, 'author_profile': 'https://Stackoverflow.com/users/2345900', 'pm_score': 2, 'selected': False, 'text': '<p>I don\'t think .NET Framework contains such like libraries. I used iTextsharp with c# to combine pdf files. I think iTextsharp is easyest way to do this. Here is the code I used.</p>\n\n<pre><code>string[] lstFiles=new string[3];\n lstFiles[0]=@"C:/pdf/1.pdf";\n lstFiles[1]=@"C:/pdf/2.pdf";\n lstFiles[2]=@"C:/pdf/3.pdf";\n\n PdfReader reader = null;\n Document sourceDocument = null;\n PdfCopy pdfCopyProvider = null;\n PdfImportedPage importedPage;\n string outputPdfPath=@"C:/pdf/new.pdf";\n\n\n sourceDocument = new Document();\n pdfCopyProvider = new PdfCopy(sourceDocument, new System.IO.FileStream(outputPdfPath, System.IO.FileMode.Create));\n\n //Open the output file\n sourceDocument.Open();\n\n try\n {\n //Loop through the files list\n for (int f = 0; f < lstFiles.Length-1; f++)\n {\n int pages =get_pageCcount(lstFiles[f]);\n\n reader = new PdfReader(lstFiles[f]);\n //Add pages of current file\n for (int i = 1; i <= pages; i++)\n {\n importedPage = pdfCopyProvider.GetImportedPage(reader, i);\n pdfCopyProvider.AddPage(importedPage);\n }\n\n reader.Close();\n }\n //At the end save the output file\n sourceDocument.Close();\n }\n catch (Exception ex)\n {\n throw ex;\n }\n\n\nprivate int get_pageCcount(string file)\n{\n using (StreamReader sr = new StreamReader(File.OpenRead(file)))\n {\n Regex regex = new Regex(@"/Type\\s*/Page[^s]");\n MatchCollection matches = regex.Matches(sr.ReadToEnd());\n\n return matches.Count;\n }\n}\n</code></pre>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73950', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/'] |
73,958 | <p>In a shellscript, I'd like to set the IP of my box, run a command, then move to the next IP. The IPs are an entire C block.</p>
<p>The question is how do I set the IP of the box without editing a file? What command sets the IP on Slackware?</p>
<p>Thanks</p>
| [{'answer_id': 74039, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': "<p>It should be something like: <code>ifconfig eth0 192.168.0.42 up</code></p>\n\n<p>Replace eth0 by the network interface of your network card, obviously adapt the ip address to your needs and the up is only necessary once, but doesn't hurt if you run it each time. </p>\n"}, {'answer_id': 74058, 'author': 'tialaramex', 'author_id': 9654, 'author_profile': 'https://Stackoverflow.com/users/9654', 'pm_score': 0, 'selected': False, 'text': "<p>I don't know Slackware very well, I last used it over ten years ago. However, any mainstream Linux distribution should have either the 'ifconfig' program, or the 'ip' program or both. You will need to have root privilges, so either become root (e.g with su) or use the 'sudo' program if you know how. Let's do it with 'ip' first.</p>\n\n<pre><code>ip addr add 10.1.2.3 dev eth0\n</code></pre>\n\n<p>sets the device eth0 (usually the primary wired network adaptor) to have IP address 10.1.2.3. You can remove the address from this adaptor again when you're done with it...</p>\n\n<pre><code>ip addr del 10.1.2.3 dev eth0\n</code></pre>\n\n<p>ifconfig works a bit differently,</p>\n\n<pre><code>ifconfig eth0 10.1.2.3 netmask 255.255.255.0\n</code></pre>\n\n<p>again sets up device eth0, with IP address 10.1.2.3</p>\n\n<p>Depending on what you want these addresses for, you may also need to know how to set up a manual route, so that your IP packets actually get delivered wherever they're going.</p>\n"}, {'answer_id': 75221, 'author': 'Thomee', 'author_id': 12825, 'author_profile': 'https://Stackoverflow.com/users/12825', 'pm_score': 2, 'selected': False, 'text': "<p>As mentioned in other answers, you can use either the ifconfig command or the ip command. ip is a much more robust command, and I prefer to use it. A full script which loops through a full class C subnet adding the IP, doing stuff, then removing it follows. Note that it doesn't use .0 or .255, which are the network and broadcast addresses of the subnet. Also, when using the ip command to add or remove an address, it's good to include the mask width, as well (the /24 at the end of the address).</p>\n\n<pre><code>#!/bin/bash\nSUBNET=192.168.135.\nETH=eth0\n\nfor i in {1..254}\ndo\n ip addr add ${SUBNET}${i}/24 dev ${ETH}\n\n # do whatever you want here\n\n ip addr del ${SUBNET}${i}/24 dev ${ETH}\ndone</code></pre>\n"}, {'answer_id': 220745, 'author': 'Eduardo', 'author_id': 9823, 'author_profile': 'https://Stackoverflow.com/users/9823', 'pm_score': 0, 'selected': False, 'text': '<p>In one line, e.g.: ifconfig eth0 192.168.10.12 netmask 255.255.255.0</p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73958', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/'] |
73,960 | <p>In IE, the dropdown-list takes the same width as the dropbox (I hope I am making sense) whereas in Firefox the dropdown-list's width varies according to the content. </p>
<p>This basically means that I have to make sure that the dropbox is wide enough to display the longest selection possible. This makes my page look very ugly :(</p>
<p>Is there any workaround for this problem?
How can I use CSS to set different widths for dropbox and the dropdownlist?</p>
| [{'answer_id': 74062, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>You can add a style directly to the select element:</p>\n\n<p><code><select name="foo" style="width: 200px"></code></p>\n\n<p>So this select item will be 200 pixels wide.</p>\n\n<p>Alternatively you can apply a class or id to the element and reference it in a stylesheet</p>\n'}, {'answer_id': 74117, 'author': 'pilsetnieks', 'author_id': 6615, 'author_profile': 'https://Stackoverflow.com/users/6615', 'pm_score': 0, 'selected': False, 'text': "<p>So far there isn't one. Don't know about IE8 but it cannot be done in IE6 & IE7, unless you implement your own dropdown list functionality with javascript. There are examples how to do it on the web, though I don't see much benefit in duplicating existing functionality.</p>\n"}, {'answer_id': 74149, 'author': 'Robert C. Barth', 'author_id': 9209, 'author_profile': 'https://Stackoverflow.com/users/9209', 'pm_score': 3, 'selected': False, 'text': "<p>There is no way to do it in IE6/IE7/IE8. The control is drawn by the app and IE simply doesn't draw it that way. Your best bet is to implement your own drop-down via simple HTML/CSS/JavaScript if it's that important to have the the drop-down one width and the list another width.</p>\n"}, {'answer_id': 74550, 'author': 'Sleep Deprivation Ninja', 'author_id': 13002, 'author_profile': 'https://Stackoverflow.com/users/13002', 'pm_score': 4, 'selected': False, 'text': '<p>Creating your own drop down list is more of a pain than it\'s worth. You can use some JavaScript to make the IE drop down work.</p>\n\n<p>It uses a bit of the YUI library and a special extension for fixing IE select boxes.</p>\n\n<p>You will need to include the following and wrap your <code><select></code> elements in a <code><span class="select-box"></code></p>\n\n<p>Put these before the body tag of your page:</p>\n\n<pre><code><script src="http://us.js2.yimg.com/us.js.yimg.com/lib/common/utils/2/yahoo_2.0.0-b3.js" type="text/javascript">\n</script>\n<script src="http://us.js2.yimg.com/us.js.yimg.com/lib/common/utils/2/event_2.0.0-b3.js" type="text/javascript">\n</script>\n<script src="http://us.js2.yimg.com/us.js.yimg.com/lib/common/utils/2/dom_2.0.2-b3.js" type="text/javascript">\n</script>\n<script src="ie-select-width-fix.js" type="text/javascript">\n</script>\n<script>\n// for each select box you want to affect, apply this:\nvar s1 = new YAHOO.Hack.FixIESelectWidth( \'s1\' ); // s1 is the ID of the select box you want to affect\n</script>\n</code></pre>\n\n<p>Post acceptance edit:</p>\n\n<p>You can also do this without the YUI library and Hack control. All you really need to do is put an onmouseover="this.style.width=\'auto\'" onmouseout="this.style.width=\'100px\'" (or whatever you want) on the select element. The YUI control gives it that nice animation but it\'s not necessary. This task can also be accomplished with jquery and other libraries (although, I haven\'t found explicit documentation for this)</p>\n\n<p>-- amendment to the edit:<br>\nIE has a problem with the onmouseout for select controls (it doesn\'t consider mouseover on options being a mouseover on the select). This makes using a mouseout very tricky. The first solution is the best I\'ve found so far.</p>\n'}, {'answer_id': 714570, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>We have the same thing on an asp:dropdownlist:\n</p>\n\n<p>In Firefox(3.0.5) the dropdown is the width of the longest item in the dropdown, which is like 600 pixels wide or something like that.</p>\n'}, {'answer_id': 912435, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>In jQuery this works fairly well. Assume the dropdown has id="dropdown".</p>\n\n<pre><code>$(document).ready(function(){\n\n $("#dropdown").mousedown(function(){\n if($.browser.msie) {\n $(this).css("width","auto");\n }\n });\n $("#dropdown").change(function(){\n if ($.browser.msie) {\n $(this).css("width","175px");\n }\n });\n\n});\n</code></pre>\n'}, {'answer_id': 1037055, 'author': 'Tinus', 'author_id': 121290, 'author_profile': 'https://Stackoverflow.com/users/121290', 'pm_score': 3, 'selected': False, 'text': '<p>@Thad you need to add a blur event handler as well</p>\n\n<pre><code>$(document).ready(function(){\n $("#dropdown").mousedown(function(){\n if($.browser.msie) {\n $(this).css("width","auto");\n }\n });\n $("#dropdown").change(function(){\n if ($.browser.msie) {\n $(this).css("width","175px");\n }\n });\n $("#dropdown").blur(function(){\n if ($.browser.msie) {\n $(this).css("width","175px");\n }\n });\n});\n</code></pre>\n\n<p>However, this will still expand the selectbox on click, instead of just the elements. (and it seems to fail in IE6, but works perfectly in Chrome and IE7)</p>\n'}, {'answer_id': 1383840, 'author': 'Justin Fisher', 'author_id': 169060, 'author_profile': 'https://Stackoverflow.com/users/169060', 'pm_score': 3, 'selected': False, 'text': '<p>I used the following solution and it seems to work well in most situations.</p>\n\n<pre><code><style>\nselect{width:100px}\n</style>\n\n<html>\n<select onmousedown="if($.browser.msie){this.style.position=\'absolute\';this.style.width=\'auto\'}" onblur="this.style.position=\'\';this.style.width=\'\'">\n <option>One</option>\n <option>Two - A long option that gets cut off in IE</option>\n</select>\n</html>\n</code></pre>\n\n<hr>\n\n<p>Note: the <em>$.browser.msie</em> does require jquery.</p>\n'}, {'answer_id': 1568875, 'author': 'bluwater2001', 'author_id': 175111, 'author_profile': 'https://Stackoverflow.com/users/175111', 'pm_score': 2, 'selected': False, 'text': '<p>Here is the simplest solution.</p>\n\n<p>Before I start, I must tell you dropdown select box will automatically expand in almost all the browsers except IE6. So, I would do a browser check (i.e., IE6) and write the following only to that browser. Here it goes. First check for the browser.</p>\n\n<p>The code will magically expands the dropdown select box. The only problem with the solution is onmouseover the dropdown will be expanded to 420px, and because the overflow = hidden we are hiding the expanded dropdown size and showing it as 170px; so, the arrow at the right side of the ddl will be hidden and cannot be seen. but the select box will be expanded to 420px; which is what we really want. Just try the code below for yourself and use it if you like it.</p>\n\n<pre><code>.ctrDropDown\n{\n width:420px; <%--this is the actual width of the dropdown list--%>\n}\n.ctrDropDownClick\n{\n width:420px; <%-- this the width of the dropdown select box.--%>\n}\n\n<div style="width:170px; overflow:hidden;">\n<asp:DropDownList runat="server" ID="ddlApplication" onmouseout = "this.className=\'ctrDropDown\';" onmouseover ="this.className=\'ctrDropDownClick\';" class="ctrDropDown" onBlur="this.className=\'ctrDropDown\';" onMouseDown="this.className=\'ctrDropDownClick\';" onChange="this.className=\'ctrDropDown\';"></asp:DropDownList>\n</div>\n</code></pre>\n\n<p>The above is the IE6 CSS. The common CSS for all other browsers should be as below.</p>\n\n<pre><code>.ctrDropDown\n{\n width:170px; <%--this is the actual width of the dropdown list--%>\n}\n.ctrDropDownClick\n{\n width:auto; <%-- this the width of the dropdown select box.--%>\n}\n</code></pre>\n'}, {'answer_id': 1873417, 'author': 'Ybbest', 'author_id': 134579, 'author_profile': 'https://Stackoverflow.com/users/134579', 'pm_score': 1, 'selected': False, 'text': '<p><a href="http://developer.yahoo.com/yui/examples/button/button-menu-select.html#" rel="nofollow noreferrer">http://developer.yahoo.com/yui/examples/button/button-menu-select.html#</a></p>\n'}, {'answer_id': 1875534, 'author': 'cam', 'author_id': 228154, 'author_profile': 'https://Stackoverflow.com/users/228154', 'pm_score': 2, 'selected': False, 'text': '<p>if you want a simple dropdown &/or flyout menu with no transition effects just use CSS... you can force IE6 to support :hover on all element using an .htc file (css3hover?) with behavior (IE6 only property) defined in the conditionally attached CSS file.</p>\n'}, {'answer_id': 2516571, 'author': 'BalusC', 'author_id': 157882, 'author_profile': 'https://Stackoverflow.com/users/157882', 'pm_score': 8, 'selected': True, 'text': '<p>Here\'s another <a href="http://jquery.com" rel="noreferrer">jQuery</a> based example. In contrary to all the other answers posted here, it takes all keyboard and mouse events into account, especially clicks:</p>\n\n<pre><code>if (!$.support.leadingWhitespace) { // if IE6/7/8\n $(\'select.wide\')\n .bind(\'focus mouseover\', function() { $(this).addClass(\'expand\').removeClass(\'clicked\'); })\n .bind(\'click\', function() { $(this).toggleClass(\'clicked\'); })\n .bind(\'mouseout\', function() { if (!$(this).hasClass(\'clicked\')) { $(this).removeClass(\'expand\'); }})\n .bind(\'blur\', function() { $(this).removeClass(\'expand clicked\'); });\n}\n</code></pre>\n\n<p>Use it in combination with this piece of CSS:</p>\n\n<pre><code>select {\n width: 150px; /* Or whatever width you want. */\n}\nselect.expand {\n width: auto;\n}\n</code></pre>\n\n<p>All you need to do is to add the class <code>wide</code> to the dropdown element(s) in question.</p>\n\n<pre><code><select class="wide">\n ...\n</select>\n</code></pre>\n\n<p><a href="http://jsfiddle.net/HnV9Q/" rel="noreferrer">Here is a jsfiddle example</a>. Hope this helps.</p>\n'}, {'answer_id': 2969250, 'author': 'Sai', 'author_id': 337515, 'author_profile': 'https://Stackoverflow.com/users/337515', 'pm_score': 4, 'selected': False, 'text': '<p>you could just try the following...</p>\n\n<pre><code> styleClass="someStyleWidth"\n onmousedown="javascript:if(navigator.appName==\'Microsoft Internet Explorer\'){this.style.position=\'absolute\';this.style.width=\'auto\'}" \n onblur="this.style.position=\'\';this.style.width=\'\'"\n</code></pre>\n\n<p>I tried and it works for me. Nothing else is required.</p>\n'}, {'answer_id': 3048216, 'author': 'lucien', 'author_id': 367610, 'author_profile': 'https://Stackoverflow.com/users/367610', 'pm_score': 2, 'selected': False, 'text': '<p>check this out.. it\'s not perfect but it works and it\'s for IE only and doesn\'t affect FF. I used the regular javascript for onmousedown to establish IE only fix.. but the msie from jquery could be used as well in the onmousedown.. the main idea is the "onchange" and on blur to have the select box return to normal... decide you\'re own width for those. I needed 35%. </p>\n\n<pre><code>onmousedown="javascript:if(navigator.appName==\'Microsoft Internet Explorer\'){this.style.width=\'auto\'}" \nonchange="this.style.width=\'35%\'"\nonblur="this.style.width=\'35%\'"\n</code></pre>\n'}, {'answer_id': 3161181, 'author': 'Hammad Tariq', 'author_id': 243354, 'author_profile': 'https://Stackoverflow.com/users/243354', 'pm_score': 0, 'selected': False, 'text': '<p>The hedgerwow link (the YUI animation work-around) in the first best answer is broken, I guess the domain got expired. I copied the code before it got expired, so you can find it here (owner of code can let me know if I am breaching any copyrights by uploading it again)</p>\n\n<p><a href="http://ciitronian.com/blog/programming/yui-button-mimicking-native-select-dropdown-avoid-width-problem/" rel="nofollow noreferrer">http://ciitronian.com/blog/programming/yui-button-mimicking-native-select-dropdown-avoid-width-problem/</a></p>\n\n<p>On the same blog post I wrote about making an exact same SELECT element like the normal one using YUI Button menu. Have a look and let me know if this helps! </p>\n'}, {'answer_id': 3303191, 'author': 'lhoess', 'author_id': 398403, 'author_profile': 'https://Stackoverflow.com/users/398403', 'pm_score': 0, 'selected': False, 'text': '<p>This seems to work with IE6 and doesn\'t appear to break others. The other nice thing is that it changes the menu automatically as soon as you change your drop down selection.</p>\n\n<pre><code>$(document).ready(function(){\n $("#dropdown").mouseover(function(){\n if($.browser.msie) {\n $(this).css("width","auto");\n }\n });\n $("#dropdown").change(function(){\n if ($.browser.msie) {\n $("#dropdown").trigger("mouseover");\n }\n });\n\n});\n</code></pre>\n'}, {'answer_id': 3494994, 'author': 'jbabey', 'author_id': 386152, 'author_profile': 'https://Stackoverflow.com/users/386152', 'pm_score': 2, 'selected': False, 'text': "<p>BalusC's answer above works great, but there is a small fix I would add if the content of your dropdown has a smaller width than what you define in your CSS select.expand, add this to the mouseover bind:</p>\n\n<pre><code>.bind('mouseover', function() { $(this).addClass('expand').removeClass('clicked');\n if ($(this).width() < 300) // put your desired minwidth here\n {\n $(this).removeClass('expand');\n }})\n</code></pre>\n"}, {'answer_id': 3759984, 'author': 'Ewen', 'author_id': 453874, 'author_profile': 'https://Stackoverflow.com/users/453874', 'pm_score': 3, 'selected': False, 'text': '<p>If you use jQuery then try out this IE select width plugin:</p>\n\n<p><a href="http://www.jainaewen.com/files/javascript/jquery/ie-select-style/" rel="noreferrer">http://www.jainaewen.com/files/javascript/jquery/ie-select-style/</a></p>\n\n<p>Applying this plugin makes the select box in Internet Explorer appear to work as it would work in Firefox, Opera etc by allowing the option elements to open at full width without loosing the look and style of the fixed width. It also adds support for padding and borders on the select box in Internet Explorer 6 and 7.</p>\n'}, {'answer_id': 6389369, 'author': 'Derrick', 'author_id': 265100, 'author_profile': 'https://Stackoverflow.com/users/265100', 'pm_score': 2, 'selected': False, 'text': '<p>This is something l have done taking bits from other people\'s stuff.</p>\n\n<pre><code> $(document).ready(function () {\n if (document.all) {\n\n $(\'#<%=cboDisability.ClientID %>\').mousedown(function () {\n $(\'#<%=cboDisability.ClientID %>\').css({ \'width\': \'auto\' });\n });\n\n $(\'#<%=cboDisability.ClientID %>\').blur(function () {\n $(this).css({ \'width\': \'208px\' });\n });\n\n $(\'#<%=cboDisability.ClientID %>\').change(function () {\n $(\'#<%=cboDisability.ClientID %>\').css({ \'width\': \'208px\' });\n });\n\n $(\'#<%=cboEthnicity.ClientID %>\').mousedown(function () {\n $(\'#<%=cboEthnicity.ClientID %>\').css({ \'width\': \'auto\' });\n });\n\n $(\'#<%=cboEthnicity.ClientID %>\').blur(function () {\n $(this).css({ \'width\': \'208px\' });\n });\n\n $(\'#<%=cboEthnicity.ClientID %>\').change(function () {\n $(\'#<%=cboEthnicity.ClientID %>\').css({ \'width\': \'208px\' });\n });\n\n }\n });\n</code></pre>\n\n<p>where cboEthnicity and cboDisability are dropdowns with option text wider than the width of the select itself. </p>\n\n<p>As you can see, l have specified document.all as this only works in IE. Also, l encased the dropdowns within div elements like this:</p>\n\n<pre><code><div id="dvEthnicity" style="width: 208px; overflow: hidden; position: relative; float: right;"><asp:DropDownList CssClass="select" ID="cboEthnicity" runat="server" DataTextField="description" DataValueField="id" Width="200px"></asp:DropDownList></div>\n</code></pre>\n\n<p>This takes care of the other elements moving out of place when your dropdown expands. The only downside here is that the menulist visual disappears when you are selecting but returns as soon as you have selected.</p>\n\n<p>Hope this helps someone.</p>\n'}, {'answer_id': 7312042, 'author': 'Federico Valido', 'author_id': 929457, 'author_profile': 'https://Stackoverflow.com/users/929457', 'pm_score': 1, 'selected': False, 'text': '<p>The jquery BalusC\'s solution improved by me. Used also: Brad Robertson\'s <a href="http://doctype.com/ie7-width-overrides-minwidth-select" rel="nofollow">comment here</a>.</p>\n\n<p>Just put this in a .js, use the wide class for your desired combos and don\'t forge to give it an Id. Call the function in the onload (or documentReady or whatever).<br/>\nAs simple ass that :)<br/>\nIt will use the width that you defined for the combo as minimun length.</p>\n\n<pre class="lang-js prettyprint-override"><code>function fixIeCombos() {\n if ($.browser.msie && $.browser.version < 9) {\n var style = $(\'<style>select.expand { width: auto; }</style>\');\n $(\'html > head\').append(style);\n\n var defaultWidth = "200";\n\n // get predefined combo\'s widths.\n var widths = new Array();\n $(\'select.wide\').each(function() {\n var width = $(this).width();\n if (!width) {\n width = defaultWidth;\n }\n widths[$(this).attr(\'id\')] = width;\n });\n\n $(\'select.wide\')\n .bind(\'focus mouseover\', function() {\n // We\'re going to do the expansion only if the resultant size is bigger\n // than the original size of the combo.\n // In order to find out the resultant size, we first clon the combo as\n // a hidden element, add to the dom, and then test the width.\n var originalWidth = widths[$(this).attr(\'id\')];\n\n var $selectClone = $(this).clone();\n $selectClone.addClass(\'expand\').hide();\n $(this).after( $selectClone );\n var expandedWidth = $selectClone.width()\n $selectClone.remove();\n if (expandedWidth > originalWidth) {\n $(this).addClass(\'expand\').removeClass(\'clicked\');\n }\n })\n .bind(\'click\', function() {\n $(this).toggleClass(\'clicked\'); \n })\n .bind(\'mouseout\', function() {\n if (!$(this).hasClass(\'clicked\')) {\n $(this).removeClass(\'expand\');\n }\n })\n .bind(\'blur\', function() {\n $(this).removeClass(\'expand clicked\');\n })\n }\n}\n</code></pre>\n'}, {'answer_id': 7659553, 'author': 'Ahmad Alfy', 'author_id': 497828, 'author_profile': 'https://Stackoverflow.com/users/497828', 'pm_score': 0, 'selected': False, 'text': '<p>Based on the solution posted by <a href="https://stackoverflow.com/questions/73960/dropdownlist-width-in-ie/2969250#2969250">Sai</a>, this is how to do it with jQuery.</p>\n\n<pre><code>$(document).ready(function() {\n if ($.browser.msie) $(\'select.wide\')\n .bind(\'onmousedown\', function() { $(this).css({position:\'absolute\',width:\'auto\'}); })\n .bind(\'blur\', function() { $(this).css({position:\'static\',width:\'\'}); });\n});\n</code></pre>\n'}, {'answer_id': 9115565, 'author': 'mcmwhfy', 'author_id': 1057912, 'author_profile': 'https://Stackoverflow.com/users/1057912', 'pm_score': 2, 'selected': False, 'text': "<p>this is the best way to do this:</p>\n\n<pre><code>select:focus{\n min-width:165px;\n width:auto;\n z-index:9999999999;\n position:absolute;\n}\n</code></pre>\n\n<p>it's exactly the same like BalusC solution. \nOnly this is easier. ;)</p>\n"}, {'answer_id': 9200617, 'author': 'n0nag0n', 'author_id': 721019, 'author_profile': 'https://Stackoverflow.com/users/721019', 'pm_score': 0, 'selected': False, 'text': '<p>I thought I\'d throw my hat in the ring. I make a SaaS application and I had a select menu embedded inside a table. This method worked, but it skewed everything in the table.</p>\n\n<pre><code>onmousedown="if(navigator.appName==\'Microsoft Internet Explorer\'){this.style.position=\'absolute\';this.style.width=\'auto\'}\nonblur="if(navigator.appName==\'Microsoft Internet Explorer\'){this.style.position=\'\'; this.style.width= \'225px\';}"\n</code></pre>\n\n<p>So what I did to make it all better was throw the select inside a z-indexed div.</p>\n\n<pre><code><td valign="top" style="width:225px; overflow:hidden;">\n <div style="position: absolute; z-index: 5;" onmousedown="var select = document.getElementById(\'select\'); if(navigator.appName==\'Microsoft Internet Explorer\'){select.style.position=\'absolute\';select.style.width=\'auto\'}">\n <select name="select_name" id="select" style="width: 225px;" onblur="if(navigator.appName==\'Microsoft Internet Explorer\'){this.style.position=\'\'; this.style.width= \'225px\';}" onChange="reportFormValues(\'filter_<?=$job_id?>\',\'form_values\')">\n <option value="0">All</option>\n <!--More Options-->\n </select>\n </div>\n</td>\n</code></pre>\n'}, {'answer_id': 10497987, 'author': 'Arif', 'author_id': 1196718, 'author_profile': 'https://Stackoverflow.com/users/1196718', 'pm_score': 0, 'selected': False, 'text': '<p>Its tested in all version of IE, Chrome, FF & Safari</p>\n<p><strong>JavaScript code:</strong></p>\n<pre class="lang-js prettyprint-override"><code><!-- begin hiding\nfunction expandSELECT(sel) {\n sel.style.width = \'\';\n}\n\nfunction contractSELECT(sel) {\n sel.style.width = \'100px\';\n}\n// end hiding -->\n</code></pre>\n<p><strong>Html code:</strong></p>\n<pre class="lang-html prettyprint-override"><code><select name="sideeffect" id="sideeffect" style="width:100px;" onfocus="expandSELECT(this);" onblur="contractSELECT(this);" >\n <option value="0" selected="selected" readonly="readonly">Select</option>\n <option value="1" >Apple</option>\n <option value="2" >Orange + Banana + Grapes</option>\n</code></pre>\n'}, {'answer_id': 11236037, 'author': 'Aerendel', 'author_id': 1349107, 'author_profile': 'https://Stackoverflow.com/users/1349107', 'pm_score': 0, 'selected': False, 'text': '<p>I\'ve had to work around this issue and once came up with a pretty complete and scalable solution working for IE6, 7 and 8 (and compatible with other browsers obviously).\nI\'ve written a whole article about it right here: <a href="http://www.edgeoftheworld.fr/wp/work/dealing-with-fixed-sized-dropdown-lists-in-internet-explorer" rel="nofollow">http://www.edgeoftheworld.fr/wp/work/dealing-with-fixed-sized-dropdown-lists-in-internet-explorer</a></p>\n\n<p>Thought I\'d share this for people who are still running into this problem, as none of the above solutions work in every case (in my opinion).</p>\n'}, {'answer_id': 12037082, 'author': 'PowerKiKi', 'author_id': 37706, 'author_profile': 'https://Stackoverflow.com/users/37706', 'pm_score': 2, 'selected': False, 'text': '<p>A full fledged jQuery plugin is available. It supports non-breaking layout and keyboard interactions, check out the demo page: <a href="http://powerkiki.github.com/ie_expand_select_width/" rel="nofollow">http://powerkiki.github.com/ie_expand_select_width/</a></p>\n\n<p>disclaimer: I coded that thing, patches welcome</p>\n'}, {'answer_id': 13035783, 'author': 'RasTheDestroyer', 'author_id': 836366, 'author_profile': 'https://Stackoverflow.com/users/836366', 'pm_score': 0, 'selected': False, 'text': '<p>I tried all of these solutions and none worked completely for me. This is what I came up with</p>\n\n<pre><code>$(document).ready(function () {\n\nvar clicknum = 0;\n\n$(\'.dropdown\').click(\n function() {\n clicknum++;\n if (clicknum == 2) {\n clicknum = 0;\n $(this).css(\'position\', \'\');\n $(this).css(\'width\', \'\');\n }\n }).blur(\n function() {\n $(this).css(\'position\', \'\');\n $(this).css(\'width\', \'\');\n clicknum = 0;\n }).focus(\n function() {\n $(this).css(\'position\', \'relative\');\n $(this).css(\'width\', \'auto\');\n }).mousedown(\n function() {\n $(this).css(\'position\', \'relative\');\n $(this).css(\'width\', \'auto\');\n });\n})(jQuery);\n</code></pre>\n\n<p>Be sure to add a dropdown class to each dropdown in your html</p>\n\n<p>The trick here is using the specialized click function (I found it here <a href="https://stackoverflow.com/questions/898463/fire-event-each-time-a-dropdownlist-item-is-selected-with-jquery">Fire event each time a DropDownList item is selected with jQuery</a>). Many of the other solutions on here use the event handler change, which works well but won\'t trigger if the user selects the same option as was previously selected. </p>\n\n<p>Like many of the other solutions, focus and mousedown is for when the user puts the dropdown in focus, blur is for when they click away.</p>\n\n<p>You may also want to stick some kind of browser detection in this so it only effects ie. It doesn\'t look bad in other browsers though</p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73960', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/747/'] |
73,964 | <p>I would like to turn the HTML generated by my CFM page into a PDF, and have the user prompted with the standard "Save As" prompt when navigating to my page.</p>
| [{'answer_id': 73982, 'author': 'Frank Wiles', 'author_id': 12568, 'author_profile': 'https://Stackoverflow.com/users/12568', 'pm_score': 1, 'selected': False, 'text': "<p>I'm not that familiar with ColdFusion, but what you need to do is set the Content-Type of the page when the user requests it to be application/octet-stream. This will prompt them for a download every time. </p>\n\n<p>Hope this helps!</p>\n"}, {'answer_id': 74374, 'author': 'Soldarnal', 'author_id': 3420, 'author_profile': 'https://Stackoverflow.com/users/3420', 'pm_score': 5, 'selected': True, 'text': '<p>You should use the cfdocument tag (with format="PDF") to generate the PDF by placing it around the page you are generating. You\'ll want to specify a filename attribute, otherwise the document will just stream right to your browser.</p>\n\n<p>After you have saved the content as a PDF, use cfheader and cfcontent in combination to output the PDF as an attachment ("Save As") and add the file to the response stream. I also added deletefile="Yes" on the cfcontent tag to keep the file system clean of the files.</p>\n\n<pre><code><cfdocument format="PDF" filename="file.pdf" overwrite="Yes">\n<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">\n<html>\n<head>\n <title>Hello World</title>\n</head>\n<body>\n Hello World\n</body>\n</html>\n</cfdocument>\n<cfheader name="Content-Disposition" value="attachment;filename=file.pdf">\n<cfcontent type="application/octet-stream" file="#expandPath(\'.\')#\\file.pdf" deletefile="Yes">\n</code></pre>\n\n<p>As an aside: I\'m just using file.pdf for the filename in the example below, but you might want to use some random or session generated string for the filename to avoid problems resulting from race conditions.</p>\n'}, {'answer_id': 75118, 'author': 'Ben Doom', 'author_id': 12267, 'author_profile': 'https://Stackoverflow.com/users/12267', 'pm_score': 2, 'selected': False, 'text': "<p>If you want to avoid storing the PDF at all, using cfdocument without a filename will send the pdf (of flashpaper) directly to the browser without using the cfheader and cfcontent.</p>\n\n<p>Caveat: Like with using cfheader/cfcontent, you need to do this before the cache gets flushed to the browser, since it's basically doing the same thing without having to store the file.</p>\n\n<p>To get the content, I would probably use cfsavecontent wrapped around the same calls/includes/etc. that generate the page, with two major exceptions. cfdocument seems to have issues with external stylesheets, so using an include to put the styles directly into the document is probably a good idea. You can try using an @import instead -- it works for some people. Also, I'd be careful about relative links to images, as they can sometimes break. </p>\n"}, {'answer_id': 88297, 'author': 'Andy Waschick', 'author_id': 6000, 'author_profile': 'https://Stackoverflow.com/users/6000', 'pm_score': 2, 'selected': False, 'text': '<p>The <code><cfdocument></code> approach is the sanctioned way to get it done, however it does not offer everything possible in the way of manipulating existing PDF documents. I had a project where I needed to generate coupons based using a pre-designed, print-resolution PDF template. <code><cfdocument></code> would have let me approximate the output, but only with bitmap images embedded in HTML. True, I could fake print-resolution by making a large image and scaling it in HTML, but the original was a nice, clean, vector-image file and I wanted to use that instead. </p>\n\n<p>I ended up using a copy of <code><cfx_pdf></code> to get the job done. (<a href="http://www.easel2.com/" rel="nofollow noreferrer">Developer\'s Site</a>, <a href="http://www.cftagstore.com/tags/cfxpdf.cfm" rel="nofollow noreferrer">CF Tag Store</a>) It\'s a CF wrapper around a Java PDF library that lets you manipulate existing PDF documents, including filling out PDF forms, setting permissions, merging files, drawing vector graphics, tables, and text, use custom fonts, etc, etc. If you are willing to work with it, you can get some pretty spectacular results. </p>\n\n<p>The one drawback is that it appears the developer has left this product out to pasture for a long time. The developer site is still copyright 2003 and doesn\'t mention anything past ColdFusion MX 6.1. I ended up having to break some of the encrypted templates in order to fix a couple of bugs and make it work as I needed it to. Nontheless, it is a powerful tool.</p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73964', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2232/'] |
73,971 | <p>In JavaScript, what is the best way to determine if a date provided falls within a valid range?</p>
<p>An example of this might be checking to see if the user input <code>requestedDate</code> is part of the next valid work week. Note that this is not just checking to see if one date is larger than another as a valid date would be equal to or greater than the lower end of the range while less than or equal to the upper end of the range.</p>
| [{'answer_id': 74024, 'author': 'Jesper Blad Jensen', 'author_id': 11559, 'author_profile': 'https://Stackoverflow.com/users/11559', 'pm_score': 3, 'selected': False, 'text': "<p>So if i understand currenctly, you need to look if one date is bigger than the other.</p>\n\n<pre><code>function ValidRange(date1,date2)\n{\n return date2.getTime() > date1.getTime();\n}\n</code></pre>\n\n<p>You then need to parse the strings you are getting from the UI, with Date.parse, like this:</p>\n\n<pre><code>ValidRange(Date.parse('10-10-2008'),Date.parse('11-11-2008'));\n</code></pre>\n\n<p>Does that help?</p>\n"}, {'answer_id': 74040, 'author': 'rjzii', 'author_id': 1185, 'author_profile': 'https://Stackoverflow.com/users/1185', 'pm_score': 5, 'selected': True, 'text': '<p>This is actually a problem that I have seen come up before a lot in my works and the following bit of code is my answer to the problem.</p>\n\n<pre><code>// checkDateRange - Checks to ensure that the values entered are dates and \n// are of a valid range. By this, the dates must be no more than the \n// built-in number of days appart.\nfunction checkDateRange(start, end) {\n // Parse the entries\n var startDate = Date.parse(start);\n var endDate = Date.parse(end);\n // Make sure they are valid\n if (isNaN(startDate)) {\n alert("The start date provided is not valid, please enter a valid date.");\n return false;\n }\n if (isNaN(endDate)) {\n alert("The end date provided is not valid, please enter a valid date.");\n return false;\n }\n // Check the date range, 86400000 is the number of milliseconds in one day\n var difference = (endDate - startDate) / (86400000 * 7);\n if (difference < 0) {\n alert("The start date must come before the end date.");\n return false;\n }\n if (difference <= 1) {\n alert("The range must be at least seven days apart.");\n return false;\n }\n return true;\n}\n</code></pre>\n\n<p>Now a couple things to note about this code, the <code>Date.parse</code> function should work for most input types, but has been known to have issues with some formats such as "YYYY MM DD" so you should test that before using it. However, I seem to recall that most browsers will interpret the date string given to Date.parse based upon the computers region settings.</p>\n\n<p>Also, the multiplier for 86400000 should be whatever the range of days you are looking for is. So if you are looking for dates that are at least one week apart then it should be seven.</p>\n'}, {'answer_id': 74051, 'author': 'Grant Wagner', 'author_id': 9254, 'author_profile': 'https://Stackoverflow.com/users/9254', 'pm_score': 3, 'selected': False, 'text': '<pre><code>var myDate = new Date(2008, 9, 16);\n\n// is myDate between Sept 1 and Sept 30?\n\nvar startDate = new Date(2008, 9, 1);\nvar endDate = new Date(2008, 9, 30);\n\nif (startDate < myDate && myDate < endDate) {\n alert(\'yes\');\n // myDate is between startDate and endDate\n}\n</code></pre>\n\n<p>There are a variety of formats you can pass to the Date() constructor to construct a date. You can also construct a new date with the current time:</p>\n\n<pre><code>var now = new Date();\n</code></pre>\n\n<p>and set various properties on it:</p>\n\n<pre><code>now.setYear(...);\nnow.setMonth(...);\n// etc\n</code></pre>\n\n<p>See <a href="http://www.javascriptkit.com/jsref/date.shtml" rel="noreferrer">http://www.javascriptkit.com/jsref/date.shtml</a> or <a href="http://www.google.ca/search?q=javascript+date+object" rel="noreferrer">Google</a> for more details.</p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73971', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1185/'] |
73,972 | <p>I have somehow misconfigured fingers. This leads to a very annoying situation.</p>
<ol>
<li>I select a block of text to copy;</li>
<li>I move the cursor the place where I want to paste the code;</li>
<li>I accidentally press Ctrl+C again instead of Ctrl+V;</li>
<li>My block of copied text is replaced by an empty block;</li>
<li>I have to go back and do it all over again. Grrrrr.</li>
</ol>
<p>Is there any way to disable this behavior, that is to disable copy of empty blocks of text in Visual Studio 2005+?</p>
| [{'answer_id': 73989, 'author': 'Magnus Johansson', 'author_id': 3584, 'author_profile': 'https://Stackoverflow.com/users/3584', 'pm_score': 4, 'selected': False, 'text': '<p>Press CTRL+SHIFT+V twice.</p>\n'}, {'answer_id': 74004, 'author': 'John Sheehan', 'author_id': 1786, 'author_profile': 'https://Stackoverflow.com/users/1786', 'pm_score': 7, 'selected': True, 'text': "<p>It's not copying an empty block, it's copying the blank line. You can change this setting in Tools > Options > Text Editor > All Languages > 'Apply Cut or Copy Commands to blank lines when there is no selection'</p>\n"}, {'answer_id': 74015, 'author': 'Jeremy Wiebe', 'author_id': 11807, 'author_profile': 'https://Stackoverflow.com/users/11807', 'pm_score': 2, 'selected': False, 'text': '<p>I\'m using Visual Studio 2008 (but I believe this answer applies to Visual Studio 2005).</p>\n\n<p>Select Tools -> Options.</p>\n\n<p>Navigate to the "Text Editor" node and expand it. </p>\n\n<p>Expand "All Languages" (or whatever language you want to apply this to) and check the "Apply Cut or Copy commands to blank lines when there is no selection".</p>\n'}, {'answer_id': 74034, 'author': 'EndangeredMassa', 'author_id': 106, 'author_profile': 'https://Stackoverflow.com/users/106', 'pm_score': 2, 'selected': False, 'text': '<blockquote>\n <p>The option that saved my sanity is found in Tools - Options - Text Editor - All Languages - General. There\'s a checkbox Apply Cut or Copy commands to blank lines when there is no selection. Unchecking this allowed me to hit Ctrl+C all i want on a blank line without losing the content on my clipboard. </p>\n</blockquote>\n\n<p><a href="http://blogs.msdn.com/saraford/archive/2007/09/28/did-you-know-how-not-to-accidentally-copy-a-blank-line.aspx" rel="nofollow noreferrer">Source</a></p>\n'}, {'answer_id': 74064, 'author': 'dcstraw', 'author_id': 10391, 'author_profile': 'https://Stackoverflow.com/users/10391', 'pm_score': 1, 'selected': False, 'text': '<p>Go to Tools > Options > Text Editor > All Languages > General</p>\n\n<p>The option on that page is "Apply Cut or Copy commands to blank lines when there is no selection"</p>\n'}, {'answer_id': 14822566, 'author': 'FearlessHyena', 'author_id': 724485, 'author_profile': 'https://Stackoverflow.com/users/724485', 'pm_score': 1, 'selected': False, 'text': '<p>For some reason that option didn\'t work for me (VS2010)</p>\n\n<p>The answer mentioned here where you assign Ctrl+C to the macro worked however <a href="https://stackoverflow.com/questions/108094/disabling-single-line-copy-in-visual-studio">Disabling single line copy in Visual Studio</a></p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73972', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/6508/'] |
73,988 | <p>I am receiving a message from a commercial program stating that the "LogMessage" stored procedure is not found. There does not appear to be a stored procedure called LogMessage in the associated MS SQLServer 2000 database. What can I do to track down the missing procedure, other than calling the company?</p>
| [{'answer_id': 74016, 'author': 'senfo', 'author_id': 10792, 'author_profile': 'https://Stackoverflow.com/users/10792', 'pm_score': 2, 'selected': False, 'text': "<p>The reason you couldn't find it is because it's not there. Unless you have the original proc, you're going to have to call the company.</p>\n\n<p>Granted, you could take a stab at creating the proc, yourself. But why bother when somebody already has the original proc?</p>\n\n<p>Is this a fresh install of the commercial product? If so, this is completely their responsibility.</p>\n"}, {'answer_id': 74531, 'author': 'Jen A', 'author_id': 12979, 'author_profile': 'https://Stackoverflow.com/users/12979', 'pm_score': 1, 'selected': False, 'text': "<p>Occasionally you will also get this message if you do not have permissions to access the stored procedure. Log in as 'sa' or equivalent to verify that the proc is indeed missing.</p>\n"}, {'answer_id': 185105, 'author': 'rice', 'author_id': 23933, 'author_profile': 'https://Stackoverflow.com/users/23933', 'pm_score': 0, 'selected': False, 'text': "<p>LogMessage seems pretty self-explanatory. You could probably take a stab at creating one yourself just to see what happens, if you can't easily get the real thing.</p>\n\n<p>Create a new table called LoggedMessages and just insert to the table when the proc is called. Then see what pops in.</p>\n\n<p>Kind of hacky, but given that it's a logging mechanism, which is tangential to the main features of the app, you could give it a try.</p>\n"}, {'answer_id': 3419417, 'author': 'MatthewMartin', 'author_id': 33264, 'author_profile': 'https://Stackoverflow.com/users/33264', 'pm_score': 0, 'selected': False, 'text': "<p>Well, if the company is out of business, unhelpful, etc, or your in a hurry, then attach a SQL trace, look at what kind and how many parameters are being passed and create a stored procedure with that name and signature. It may take some experimentation to get the signature right dependening on the data access API being used. The body of the stored procedure would be empty. Since this is just logging, presumably this will let the rest of the app run, but logging would be off.</p>\n\n<p>Make sure that the rest of the schema is there. Obviously if the entire schema is missing, then this trick won't work.</p>\n\n<p>If you have a maintenance agreement with the vendor go holler at them, that's what maintenance and support is for.</p>\n"}] | 2008/09/16 | ['https://Stackoverflow.com/questions/73988', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/'] |
74,010 | <p>I am a bit rusty on my cursor lingo in PL/SQL. Anyone know this?</p>
| [{'answer_id': 74105, 'author': 'Dave Costa', 'author_id': 6568, 'author_profile': 'https://Stackoverflow.com/users/6568', 'pm_score': 2, 'selected': False, 'text': '<p>An explicit cursor is one you declare, like:</p>\n\n<pre><code>CURSOR my_cursor IS\n SELECT table_name FROM USER_TABLES\n</code></pre>\n\n<p>An implicit cursor is one created to support any in-line SQL you write (either static or dynamic).</p>\n'}, {'answer_id': 74135, 'author': 'stjohnroe', 'author_id': 2985, 'author_profile': 'https://Stackoverflow.com/users/2985', 'pm_score': 4, 'selected': False, 'text': '<p>An explicit cursor is defined as such in a declaration block:</p>\n\n<pre><code>DECLARE \nCURSOR cur IS \n SELECT columns FROM table WHERE condition;\nBEGIN\n...\n</code></pre>\n\n<p>an implicit cursor is implented directly in a code block:</p>\n\n<pre><code>...\nBEGIN\n SELECT columns INTO variables FROM table where condition;\nEND;\n...\n</code></pre>\n'}, {'answer_id': 74624, 'author': 'Kristian', 'author_id': 12911, 'author_profile': 'https://Stackoverflow.com/users/12911', 'pm_score': 2, 'selected': False, 'text': '<p>With explicit cursors, you have complete control over how to access information in the database. You decide when to OPEN the cursor, when to FETCH records from the cursor (and therefore from the table or tables in the SELECT statement of the cursor) how many records to fetch, and when to CLOSE the cursor. Information about the current state of your cursor is available through examination of the cursor attributes.</p>\n\n<p>See <a href="http://www.unix.com.ua/orelly/oracle/prog2/ch06_03.htm" rel="nofollow noreferrer">http://www.unix.com.ua/orelly/oracle/prog2/ch06_03.htm</a> for details.</p>\n'}, {'answer_id': 76178, 'author': 'Sten Vesterli', 'author_id': 9363, 'author_profile': 'https://Stackoverflow.com/users/9363', 'pm_score': 6, 'selected': True, 'text': '<p>An implicit cursor is one created "automatically" for you by Oracle when you execute a query. It is simpler to code, but suffers from </p>\n\n<ul>\n<li>inefficiency (the ANSI standard specifies that it must fetch twice to check if there is more than one record)</li>\n<li>vulnerability to data errors (if you ever get two rows, it raises a TOO_MANY_ROWS exception)</li>\n</ul>\n\n<p>Example</p>\n\n<pre><code>SELECT col INTO var FROM table WHERE something;\n</code></pre>\n\n<p>An explicit cursor is one you create yourself. It takes more code, but gives more control - for example, you can just open-fetch-close if you only want the first record and don\'t care if there are others. </p>\n\n<p>Example</p>\n\n<pre><code>DECLARE \n CURSOR cur IS SELECT col FROM table WHERE something; \nBEGIN\n OPEN cur;\n FETCH cur INTO var;\n CLOSE cur;\nEND;\n</code></pre>\n'}, {'answer_id': 78765, 'author': 'ropable', 'author_id': 14508, 'author_profile': 'https://Stackoverflow.com/users/14508', 'pm_score': 0, 'selected': False, 'text': '<p>Every SQL statement executed by the Oracle database has a cursor associated with it, which is a private work area to store processing information. Implicit cursors are implicitly created by the Oracle server for all DML and SELECT statements.</p>\n\n<p>You can declare and use Explicit cursors to name the private work area, and access its stored information in your program block.</p>\n'}, {'answer_id': 80246, 'author': 'Ethan Post', 'author_id': 4527, 'author_profile': 'https://Stackoverflow.com/users/4527', 'pm_score': -1, 'selected': False, 'text': "<p>Explicit...</p>\n\n<p>cursor foo is select * from blah;\nbegin\n open fetch exit when close cursor yada yada yada</p>\n\n<p>don't use them, use implicit</p>\n\n<p>cursor foo is select * from blah;</p>\n\n<p>for n in foo loop\n x = n.some_column\nend loop</p>\n\n<p>I think you can even do this</p>\n\n<p>for n in (select * from blah) loop...</p>\n\n<p>Stick to implicit, they close themselves, they are more readable, they make life easy.</p>\n"}, {'answer_id': 84014, 'author': 'pablo', 'author_id': 16112, 'author_profile': 'https://Stackoverflow.com/users/16112', 'pm_score': 2, 'selected': False, 'text': '<p>These days implicit cursors are more efficient than explicit cursors.</p>\n\n<p><a href="http://www.oracle.com/technology/oramag/oracle/04-sep/o54plsql.html" rel="nofollow noreferrer">http://www.oracle.com/technology/oramag/oracle/04-sep/o54plsql.html</a></p>\n\n<p><a href="http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1205168148688" rel="nofollow noreferrer">http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1205168148688</a></p>\n'}, {'answer_id': 2824542, 'author': 'Derek Swingley', 'author_id': 1934, 'author_profile': 'https://Stackoverflow.com/users/1934', 'pm_score': 1, 'selected': False, 'text': '<p>Google is your friend: <a href="http://docstore.mik.ua/orelly/oracle/prog2/ch06_03.htm" rel="nofollow noreferrer">http://docstore.mik.ua/orelly/oracle/prog2/ch06_03.htm</a></p>\n\n<blockquote>\n <p>PL/SQL issues an implicit cursor\n whenever you execute a SQL statement\n directly in your code, as long as that\n code does not employ an explicit\n cursor. It is called an "implicit"\n cursor because you, the developer, do\n not explicitly declare a cursor for\n the SQL statement.</p>\n \n <p>An explicit cursor is a SELECT\n statement that is explicitly defined\n in the declaration section of your\n code and, in the process, assigned a\n name. There is no such thing as an\n explicit cursor for UPDATE, DELETE,\n and INSERT statements.</p>\n</blockquote>\n'}, {'answer_id': 2825689, 'author': 'Ian Carpenter', 'author_id': 55640, 'author_profile': 'https://Stackoverflow.com/users/55640', 'pm_score': 2, 'selected': False, 'text': '<p>In answer to the first question. Straight from the Oracle <a href="http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10472/static.htm#LNPLS00602" rel="nofollow noreferrer">documentation</a></p>\n\n<blockquote>\n <p>A cursor is a pointer to a private SQL\n area that stores information about\n processing a specific SELECT or DML\n statement.</p>\n</blockquote>\n'}, {'answer_id': 2833203, 'author': 'UltraCommit', 'author_id': 297267, 'author_profile': 'https://Stackoverflow.com/users/297267', 'pm_score': 1, 'selected': False, 'text': "<p>A cursor is a SELECTed window on an Oracle table, this means a group of records present in an Oracle table, and satisfying certain conditions. A cursor can SELECT all the content of a table, too. With a cursor you can manipulate Oracle columns, aliasing them in the result. An example of implicit cursor is the following:</p>\n\n<pre><code>BEGIN\n DECLARE\n CURSOR C1\n IS\n SELECT DROPPED_CALLS FROM ALARM_UMTS;\n\n C1_REC C1%ROWTYPE;\n BEGIN\n FOR C1_REC IN C1\n LOOP\n DBMS_OUTPUT.PUT_LINE ('DROPPED CALLS: ' || C1_REC.DROPPED_CALLS);\n END LOOP;\n END;\nEND;\n/\n</code></pre>\n\n<p>With FOR ... LOOP... END LOOP you open and close the cursor authomatically, when the records of the cursor have been all analyzed.</p>\n\n<p>An example of explicit cursor is the following:</p>\n\n<pre><code>BEGIN\n DECLARE\n CURSOR C1\n IS\n SELECT DROPPED_CALLS FROM ALARM_UMTS;\n\n C1_REC C1%ROWTYPE;\n BEGIN\n OPEN c1;\n\n LOOP\n FETCH c1 INTO c1_rec;\n\n EXIT WHEN c1%NOTFOUND;\n\n DBMS_OUTPUT.PUT_LINE ('DROPPED CALLS: ' || C1_REC.DROPPED_CALLS);\n END LOOP;\n\n CLOSE c1;\n END;\nEND;\n/\n</code></pre>\n\n<p>In the explicit cursor you open and close the cursor in an explicit way, checking the presence of records and stating an exit condition.</p>\n"}, {'answer_id': 3138202, 'author': 'shaiksyedbasha', 'author_id': 378667, 'author_profile': 'https://Stackoverflow.com/users/378667', 'pm_score': 1, 'selected': False, 'text': '<p>Implicit cursor returns only one record and are called automatically. However, explicit cursors are called manually and can return more than one record.</p>\n'}, {'answer_id': 9258147, 'author': 'Ganesh Pathare', 'author_id': 1206438, 'author_profile': 'https://Stackoverflow.com/users/1206438', 'pm_score': 2, 'selected': False, 'text': "<p>1.CURSOR: When PLSQL issues sql statements it creates private work area\n to parse & execute the sql statement is called cursor.</p>\n\n<p>2.IMPLICIT: When any PL/SQLexecutable block issues sql statement.\n PL/SQL creates implicit cursor and manages automatically means\n implcit open & close takes place. It used when sql statement return\n only one row.It has 4 attributes SQL%ROWCOUNT, SQL%FOUND,\n SQL%NOTFOUND, SQL%ISOPEN.</p>\n\n<p>3.EXPLICIT: It is created & managed by the programmer. It needs every\n time explicit open,fetch & close. It is used when sql statement\n returns more than one row. It has also 4 attributes\n CUR_NAME%ROWCOUNT, CUR_NAME%FOUND, CUR_NAME%NOTFOUND, \n CUR_NAME%ISOPEN. It process several rows by using loop. \n The programmer can pass the parameter too to explicit cursor.</p>\n\n<ul>\n<li>Example: Explicit Cursor</li>\n</ul>\n\n<p> </p>\n\n<pre><code>declare \n cursor emp_cursor \n is \n select id,name,salary,dept_id \n from employees; \n v_id employees.id%type; \n v_name employees.name%type; \n v_salary employees.salary%type; \n v_dept_id employees.dept_id%type; \n begin \n open emp_cursor; \n loop \n fetch emp_cursor into v_id,v_name,v_salary,v_dept_id; \n exit when emp_cursor%notfound;\n dbms_output.put_line(v_id||', '||v_name||', '||v_salary||','||v_dept_id); \n end loop; \n close emp_cursor; \n end;\n</code></pre>\n"}, {'answer_id': 11323942, 'author': 'prince', 'author_id': 1500760, 'author_profile': 'https://Stackoverflow.com/users/1500760', 'pm_score': 2, 'selected': False, 'text': '<p>Implicit cursors require anonymous buffer memory. </p>\n\n<p>Explicit cursors can be executed again and again by using their name.They are stored in user defined memory space rather than being stored in an anonymous buffer memory and hence can be easily accessed afterwards.</p>\n'}, {'answer_id': 28938170, 'author': 'Lalit Kumar B', 'author_id': 3989608, 'author_profile': 'https://Stackoverflow.com/users/3989608', 'pm_score': 2, 'selected': False, 'text': '<p><strong>From a performance point of view, Implicit cursors are faster.</strong></p>\n<p>Let\'s compare the performance between an explicit and implicit cursor:</p>\n<pre><code>SQL> DECLARE\n 2 l_loops NUMBER := 100000;\n 3 l_dummy dual.dummy%TYPE;\n 4 l_start NUMBER;\n 5 -- explicit cursor declaration\n 6 CURSOR c_dual IS\n 7 SELECT dummy\n 8 FROM dual;\n 9 BEGIN\n 10 l_start := DBMS_UTILITY.get_time;\n 11 -- explicitly open, fetch and close the cursor\n 12 FOR i IN 1 .. l_loops LOOP\n 13 OPEN c_dual;\n 14 FETCH c_dual\n 15 INTO l_dummy;\n 16 CLOSE c_dual;\n 17 END LOOP;\n 18\n 19 DBMS_OUTPUT.put_line(\'Explicit: \' ||\n 20 (DBMS_UTILITY.get_time - l_start) || \' hsecs\');\n 21\n 22 l_start := DBMS_UTILITY.get_time;\n 23 -- implicit cursor for loop\n 24 FOR i IN 1 .. l_loops LOOP\n 25 SELECT dummy\n 26 INTO l_dummy\n 27 FROM dual;\n 28 END LOOP;\n 29\n 30 DBMS_OUTPUT.put_line(\'Implicit: \' ||\n 31 (DBMS_UTILITY.get_time - l_start) || \' hsecs\');\n 32 END;\n 33 /\nExplicit: 332 hsecs\nImplicit: 176 hsecs\n\nPL/SQL procedure successfully completed.\n</code></pre>\n<p>So, a significant difference is clearly visible. Implicit cursor is much faster than an explicit cursor.</p>\n<p>More examples <a href="http://oracle-base.com/articles/misc/implicit-vs-explicit-cursors-in-oracle-plsql.php" rel="nofollow noreferrer">here</a>.</p>\n'}, {'answer_id': 47336170, 'author': 'Vadzim', 'author_id': 603516, 'author_profile': 'https://Stackoverflow.com/users/603516', 'pm_score': 1, 'selected': False, 'text': '<p>As stated in other answers, implicit cursors are easier to use and less error-prone. </p>\n\n<p>And <a href="https://oracle-base.com/articles/misc/implicit-vs-explicit-cursors-in-oracle-plsql" rel="nofollow noreferrer">Implicit vs. Explicit Cursors in Oracle PL/SQL</a> shows that implicit cursors are up to two times faster than explicit ones too.</p>\n\n<p>It\'s strange that no one had yet mentioned <a href="https://docs.oracle.com/cloud/latest/db112/LNPLS/cursor_for_loop_statement.htm#LNPLS1155" rel="nofollow noreferrer">Implicit FOR LOOP Cursor</a>:</p>\n\n<pre><code>begin\n for cur in (\n select t.id from parent_trx pt inner join trx t on pt.nested_id = t.id\n where t.started_at > sysdate - 31 and t.finished_at is null and t.extended_code is null\n )\n loop\n update trx set finished_at=sysdate, extended_code = -1 where id = cur.id;\n update parent_trx set result_code = -1 where nested_id = cur.id;\n end loop cur;\nend;\n</code></pre>\n\n<p>Another example on SO: <a href="https://stackoverflow.com/questions/15854749/pl-sql-for-loop-implicit-cursor">PL/SQL FOR LOOP IMPLICIT CURSOR</a>.</p>\n\n<p>It\'s way more shorter than explicit form.</p>\n\n<p>This also provides a nice workaround for <a href="https://stackoverflow.com/questions/15113086/postgresql-and-oracle-update-multiple-tables-from-common-subquery/47335611#47335611">updating multiple tables from CTE</a>.</p>\n'}, {'answer_id': 55813639, 'author': 'GOVIND DIXIT', 'author_id': 8549281, 'author_profile': 'https://Stackoverflow.com/users/8549281', 'pm_score': 1, 'selected': False, 'text': '<p>In PL/SQL, A cursor is a pointer to this context area. It contains all the information needed for processing the statement. </p>\n\n<p><strong>Implicit Cursors:</strong>\nImplicit cursors are automatically created by Oracle whenever an SQL statement is executed, when there is no explicit cursor for the statement. Programmers cannot control the implicit cursors and the information in it.</p>\n\n<p><strong>Explicit Cursors:</strong>\nExplicit cursors are programmer-defined cursors for gaining more control over the context area. An explicit cursor should be defined in the declaration section of the PL/SQL Block. It is created on a SELECT Statement which returns more than one row.</p>\n\n<p>The syntax for creating an explicit cursor is:</p>\n\n<pre><code>CURSOR cursor_name IS select_statement; \n</code></pre>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/74010', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3208/'] |
74,019 | <p>How can I specify the filename when dumping data into the response stream?</p>
<p>Right now I'm doing the following:</p>
<pre><code>byte[] data= GetFoo();
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/pdf";
Response.BinaryWrite(data);
Response.End();
</code></pre>
<p>With the code above, I get "foo.aspx.pdf" as the filename to save. I seem to remember being able to add a header to the response to specify the filename to save.</p>
| [{'answer_id': 74044, 'author': 'Sklivvz', 'author_id': 7028, 'author_profile': 'https://Stackoverflow.com/users/7028', 'pm_score': 4, 'selected': False, 'text': '<pre><code>Response.AppendHeader("Content-Disposition", "attachment; filename=foo.pdf");\n</code></pre>\n'}, {'answer_id': 74049, 'author': 'Ryan Farley', 'author_id': 1627, 'author_profile': 'https://Stackoverflow.com/users/1627', 'pm_score': 7, 'selected': True, 'text': '<p>Add a content-disposition to the header: </p>\n\n<pre><code>Response.AddHeader("content-disposition", @"attachment;filename=""MyFile.pdf""");\n</code></pre>\n'}, {'answer_id': 74060, 'author': 'Kibbee', 'author_id': 1862, 'author_profile': 'https://Stackoverflow.com/users/1862', 'pm_score': 1, 'selected': False, 'text': '<pre><code> Response.AddHeader("Content-Disposition", "attachment;filename=" & FileName & ";")\n</code></pre>\n'}, {'answer_id': 14347162, 'author': 'EMR', 'author_id': 729980, 'author_profile': 'https://Stackoverflow.com/users/729980', 'pm_score': 5, 'selected': False, 'text': '<p>FYI... if you use "inline" instead of "attachment" the file will open automatically in IE. Instead of prompting the user with a Open/Save dialogue.</p>\n\n<pre><code>Response.AppendHeader("content-disposition", string.Format("inline;FileName=\\"{0}\\"", fileName));\n</code></pre>\n'}, {'answer_id': 30972670, 'author': 'Sam', 'author_id': 238753, 'author_profile': 'https://Stackoverflow.com/users/238753', 'pm_score': 2, 'selected': False, 'text': '<p>For some reason, most of the answers out there don\'t seem to even attempt to encode the file name value. If the file contains spaces, semicolons or quotes, it mightn\'t come across correctly.</p>\n\n<p>It looks like you can use the <a href="http://msdn.microsoft.com/library/system.net.mime.contentdisposition.aspx" rel="nofollow"><code>ContentDisposition</code></a> class to generate a correct header value:</p>\n\n<pre><code>Response.AppendHeader("Content-Disposition", new ContentDisposition\n{\n FileName = yourFilename\n}.ToString());\n</code></pre>\n\n<p>You can check out <a href="http://referencesource.microsoft.com/System/net/System/Net/mail/ContentDisposition.cs.html#234ee68565525ad0" rel="nofollow">the source code for <code>ContentDisposition.ToString()</code></a> to confirm that it\'s trying to encode it properly.</p>\n\n<p><strong>Warning</strong>: This seems to crash when the filename contains a dash (not a hyphen). I haven\'t bothered looking into this yet.</p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/74019', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1672/'] |
74,032 | <p>I'm looking for real world best practices, how other people might have implemented solutions with complex domains.</p>
| [{'answer_id': 74070, 'author': 'Eric Schoonover', 'author_id': 3957, 'author_profile': 'https://Stackoverflow.com/users/3957', 'pm_score': 2, 'selected': False, 'text': '<p>This is what <a href="http://msdn.microsoft.com/en-us/library/system.collections.iequalitycomparer.aspx" rel="nofollow noreferrer">MSDN</a> has to say about IEqualityComparer (non-generic):</p>\n<blockquote>\n<p>This interface allows the implementation of customized equality comparison for collections. That is, you can create your own definition of equality, and specify that this definition be used with a collection type that accepts the <code>IEqualityComparer</code> interface. In the .NET Framework, constructors of the <code>Hashtable</code>, <code>NameValueCollection</code>, and <code>OrderedDictionary</code> collection types accept this interface.</p>\n<p>This interface supports only equality comparisons. Customization of comparisons for sorting and ordering is provided by the <code>IComparer</code> interface.</p>\n</blockquote>\n<p>It looks like the generic version of this interface performs the same function but is used for <code>Dictionary<(Of <(TKey, TValue>)>)</code> collections.</p>\n<p>As far as best practices around using this interface for your own purposes. I would say that the best practice would be to use it when you are deriving or implementing a class that has similar functionality to the above mentioned .NET framework collections and where you want to add the same capability to your own collections. This will ensure that you are consistent with how the .NET framework uses the interface.</p>\n<p>In other words support the use of this interface if you are developing a custom collection and you want to allow your consumers to control equality which is used in a number of LINQ and collection related methods (eg. Sort).</p>\n'}, {'answer_id': 74110, 'author': 'Chris Marasti-Georg', 'author_id': 96, 'author_profile': 'https://Stackoverflow.com/users/96', 'pm_score': 1, 'selected': False, 'text': '<p>I would say that the best use would be when you need to plug in different equality rules for a certain algorithm. Much in the same way that a sorting algorithm might accept an <code>IComparer<T></code>, a finding algorithm might accept an <code>IEqualityComparer<T></code></p>\n'}, {'answer_id': 74125, 'author': 'Jesper Blad Jensen', 'author_id': 11559, 'author_profile': 'https://Stackoverflow.com/users/11559', 'pm_score': 1, 'selected': False, 'text': "<p>The list uses this interface alot, so you can say a.Substract(b) or other of these nice functions.</p>\n\n<p>Just remember: If you're objects don't return the same Hashcode, the Equals is not called.</p>\n"}, {'answer_id': 533826, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': False, 'text': '<p>I did the following, I\'m not sure if it is real-world best practice, but it worked fine for me. :)</p>\n\n<pre><code>public class GenericEqualityComparer<T> : IEqualityComparer<T>\n{\n private Func<T, T, Boolean> _comparer;\n private Func<T, int> _hashCodeEvaluator;\n public GenericEqualityComparer(Func<T, T, Boolean> comparer)\n {\n _comparer = comparer;\n }\n\n public GenericEqualityComparer(Func<T, T, Boolean> comparer, Func<T, int> hashCodeEvaluator)\n {\n _comparer = comparer;\n _hashCodeEvaluator = hashCodeEvaluator;\n }\n\n #region IEqualityComparer<T> Members\n\n public bool Equals(T x, T y)\n {\n return _comparer(x, y);\n }\n\n public int GetHashCode(T obj)\n {\n if(obj == null) {\n throw new ArgumentNullException("obj");\n }\n if(_hashCodeEvaluator == null) {\n return 0;\n } \n return _hashCodeEvaluator(obj);\n }\n\n #endregion\n}\n</code></pre>\n\n<p>Then you can use it in your collections.</p>\n\n<pre><code>var comparer = new GenericEqualityComparer<ShopByProduct>((x, y) => x.ProductId == y.ProductId);\nvar current = SelectAll().Where(p => p.ShopByGroup == group).ToList();\nvar toDelete = current.Except(products, comparer);\nvar toAdd = products.Except(current, comparer);\n</code></pre>\n\n<p>If you need to support custom GetHashCode() functionality, use the alternative constructor to provide a lambda to do the alternative calculation:</p>\n\n<pre><code>var comparer = new GenericEqualityComparer<ShopByProduct>(\n (x, y) => { return x.ProductId == y.ProductId; }, \n (x) => { return x.Product.GetHashCode()}\n);\n</code></pre>\n\n<p>I hope this helps. =)</p>\n'}, {'answer_id': 1535426, 'author': 'dahlbyk', 'author_id': 54249, 'author_profile': 'https://Stackoverflow.com/users/54249', 'pm_score': 4, 'selected': False, 'text': '<p>Any time you consider using an <code>IEqualityComparer<T></code>, pause to think if the class could be made to implement <code>IEquatable<T></code> instead. If a <code>Product</code> should always be compared by ID, just define it to be equated as such so you can use the default comparer.</p>\n\n<p>That said, there are still a few of reasons you might want a custom comparer:</p>\n\n<ol>\n<li>If there are multiple ways instances of a class could be considered equal. The best example of this is a string, for which the framework provides six different comparers in <a href="http://msdn.microsoft.com/en-us/library/system.stringcomparer.aspx" rel="noreferrer"><code>StringComparer</code></a>.</li>\n<li>If the class is defined in such a way that you can\'t define it as <code>IEquatable<T></code>. This would include classes defined by others and classes generated by the compiler (specifically anonymous types, which use a property-wise comparison by default).</li>\n</ol>\n\n<p>If you do decide you need a comparer, you can certainly use a generalized comparer (see DMenT\'s answer), but if you need to reuse that logic you should encapsulate it in a dedicated class. You could even declare it by inheriting from the generic base:</p>\n\n<pre><code>class ProductByIdComparer : GenericEqualityComparer<ShopByProduct>\n{\n public ProductByIdComparer()\n : base((x, y) => x.ProductId == y.ProductId, z => z.ProductId)\n { }\n}\n</code></pre>\n\n<p>As far as use, you should take advantage of comparers when possible. For example, rather than calling <code>ToLower()</code> on every string used as a dictionary key (logic for which will be strewn across your app), you should declare the dictionary to use a case-insensitive <code>StringComparer</code>. The same goes for the LINQ operators that accept a comparer. But again, always consider if the equatable behavior that should be intrinsic to the class rather than defined externally.</p>\n'}, {'answer_id': 4679491, 'author': 'Peet Brits', 'author_id': 371917, 'author_profile': 'https://Stackoverflow.com/users/371917', 'pm_score': 3, 'selected': False, 'text': '<p>See this post for (better) alternatives: <a href="https://stackoverflow.com/questions/98033/wrap-a-delegate-in-an-iequalitycomparer">Wrap a delegate in an IEqualityComparer</a></p>\n\n<p>Scroll down to the part on <a href="https://stackoverflow.com/questions/98033/wrap-a-delegate-in-an-iequalitycomparer/1239337#1239337">KeyEqualityComparer</a> and especially the part on <a href="https://stackoverflow.com/questions/98033/wrap-a-delegate-in-an-iequalitycomparer/3719802#3719802">the importance of GetHashCode</a>. There is a whole <a href="https://stackoverflow.com/questions/98033/wrap-a-delegate-in-an-iequalitycomparer/3719617#3719617">discussion</a> on why <code>obj.GetHashCode();</code> (as suggested by DMenT\'s post) is wrong and should just return 0 instead.</p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/74032', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5802/'] |
74,057 | <p>Is there a way to use sql-server like analytic functions in Hibernate?</p>
<p>Something like </p>
<pre><code>select foo from Foo foo where f.x = max(f.x) over (partition by f.y)
</code></pre>
| [{'answer_id': 75287, 'author': 'Jason Weathered', 'author_id': 3736, 'author_profile': 'https://Stackoverflow.com/users/3736', 'pm_score': 3, 'selected': False, 'text': '<p>You are after a native SQL query.</p>\n\n<p>If you are using JPA the syntax is:</p>\n\n<pre><code>Query q = em.createNativeQuery("select foo.* from Foo foo " +\n "where f.x = max(f.x) over " +\n "(partition by f.y)", Foo.class);\n</code></pre>\n\n<p>If you need to return multiple types, take a look at the <a href="http://java.sun.com/javaee/5/docs/api/javax/persistence/SqlResultSetMapping.html" rel="noreferrer">SQLResultSetMapping</a> annotation.</p>\n\n<p>If you\'re using the the Hibernate API directly:</p>\n\n<pre><code>Query q = session.createSQLQuery("select {foo.*} from Foo foo " +\n "where f.x = max(f.x) over "+\n "(partition by f.y)");\nq.addEntity("foo", Foo.class);\n</code></pre>\n\n<p>See <a href="http://www.hibernate.org/hib_docs/v3/reference/en/html/objectstate.html#objectstate-querying-nativesql" rel="noreferrer">10.4.4. Queries in native SQL</a> in the Hibernate documentation for more details.</p>\n\n<p>In both APIs you can pass in parameters as normal using setParameter. </p>\n'}, {'answer_id': 2027784, 'author': 'Petr Macek', 'author_id': 15045, 'author_profile': 'https://Stackoverflow.com/users/15045', 'pm_score': 2, 'selected': False, 'text': '<p>Another approach would be to use the mapping. Please see this article: <a href="https://forums.hibernate.org/viewtopic.php?f=1&t=998482" rel="nofollow noreferrer">https://forums.hibernate.org/viewtopic.php?f=1&t=998482</a></p>\n\n<p>I am against the usage of native SQL queries in Hibernate... you lose the benefits of having a mapping:-)</p>\n'}, {'answer_id': 33003427, 'author': 'Eric Mayes', 'author_id': 1661071, 'author_profile': 'https://Stackoverflow.com/users/1661071', 'pm_score': 2, 'selected': False, 'text': '<p>Yes you can, but you will need to extend the hibernate dialect like the following:</p>\n\n<p>import org.hibernate.dialect.Oracle10gDialect;</p>\n\n<pre><code>public class ExtendedDialect extends Oracle10gDialect{\n public ExtendedDialect()\n {\n super();\n registerKeyword("over");\n registerKeyword("partition");\n }\n}\n</code></pre>\n\n<p>Once this class is on your classpath, you will need to tell hibernate to use it instead of the original dialect (in this case Oracle10gDialect). I am not sure which frameworks you are using, but in the case of Spring, you can use the following property under the LocalContainerEntityManagerFactoryBean:</p>\n\n<pre><code> <property name="jpaVendorAdapter">\n <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">\n <property name="databasePlatform" value="path.to.dialect.ExtendedDialect" />\n </bean>\n </property>\n</code></pre>\n\n<p>Then you can use over and partition in @Formula annotations, @Where annotations and other hibernate features without confusing hibernate.</p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/74057', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12905/'] |
74,083 | <p>When using Business Objects' CrystalReportViewer control, how can you detect and manually print the report the user has currently drilled into? You can print this automatically using the Print() method of the CrystalReportViewer, but I want to be able to do a manual printing of this report.</p>
<p>It is possible to print the main ReportSource of the CrystalReportViewer, but I need to know what report the user has drilled into and then do a manual printing of that particular drill down. Any ideas?</p>
| [{'answer_id': 75287, 'author': 'Jason Weathered', 'author_id': 3736, 'author_profile': 'https://Stackoverflow.com/users/3736', 'pm_score': 3, 'selected': False, 'text': '<p>You are after a native SQL query.</p>\n\n<p>If you are using JPA the syntax is:</p>\n\n<pre><code>Query q = em.createNativeQuery("select foo.* from Foo foo " +\n "where f.x = max(f.x) over " +\n "(partition by f.y)", Foo.class);\n</code></pre>\n\n<p>If you need to return multiple types, take a look at the <a href="http://java.sun.com/javaee/5/docs/api/javax/persistence/SqlResultSetMapping.html" rel="noreferrer">SQLResultSetMapping</a> annotation.</p>\n\n<p>If you\'re using the the Hibernate API directly:</p>\n\n<pre><code>Query q = session.createSQLQuery("select {foo.*} from Foo foo " +\n "where f.x = max(f.x) over "+\n "(partition by f.y)");\nq.addEntity("foo", Foo.class);\n</code></pre>\n\n<p>See <a href="http://www.hibernate.org/hib_docs/v3/reference/en/html/objectstate.html#objectstate-querying-nativesql" rel="noreferrer">10.4.4. Queries in native SQL</a> in the Hibernate documentation for more details.</p>\n\n<p>In both APIs you can pass in parameters as normal using setParameter. </p>\n'}, {'answer_id': 2027784, 'author': 'Petr Macek', 'author_id': 15045, 'author_profile': 'https://Stackoverflow.com/users/15045', 'pm_score': 2, 'selected': False, 'text': '<p>Another approach would be to use the mapping. Please see this article: <a href="https://forums.hibernate.org/viewtopic.php?f=1&t=998482" rel="nofollow noreferrer">https://forums.hibernate.org/viewtopic.php?f=1&t=998482</a></p>\n\n<p>I am against the usage of native SQL queries in Hibernate... you lose the benefits of having a mapping:-)</p>\n'}, {'answer_id': 33003427, 'author': 'Eric Mayes', 'author_id': 1661071, 'author_profile': 'https://Stackoverflow.com/users/1661071', 'pm_score': 2, 'selected': False, 'text': '<p>Yes you can, but you will need to extend the hibernate dialect like the following:</p>\n\n<p>import org.hibernate.dialect.Oracle10gDialect;</p>\n\n<pre><code>public class ExtendedDialect extends Oracle10gDialect{\n public ExtendedDialect()\n {\n super();\n registerKeyword("over");\n registerKeyword("partition");\n }\n}\n</code></pre>\n\n<p>Once this class is on your classpath, you will need to tell hibernate to use it instead of the original dialect (in this case Oracle10gDialect). I am not sure which frameworks you are using, but in the case of Spring, you can use the following property under the LocalContainerEntityManagerFactoryBean:</p>\n\n<pre><code> <property name="jpaVendorAdapter">\n <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">\n <property name="databasePlatform" value="path.to.dialect.ExtendedDialect" />\n </bean>\n </property>\n</code></pre>\n\n<p>Then you can use over and partition in @Formula annotations, @Where annotations and other hibernate features without confusing hibernate.</p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/74083', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/'] |
74,092 | <p>I have a function in Python which is iterating over the attributes returned from <code>dir(obj)</code>, and I want to check to see if any of the objects contained within is a function, method, built-in function, etc. Normally you could use <code>callable()</code> for this, but I don't want to include classes. The best I've come up with so far is:</p>
<pre><code>isinstance(obj, (types.BuiltinFunctionType, types.FunctionType, types.MethodType))
</code></pre>
<p>Is there a more future-proof way to do this check?</p>
<p><strong>Edit:</strong> I misspoke before when I said: "Normally you could use <code>callable()</code> for this, but I don't want to disqualify classes." I actually <em>do</em> want to disqualify classes. I want to match <em>only</em> functions, not classes.</p>
| [{'answer_id': 74138, 'author': 'Jim', 'author_id': 8427, 'author_profile': 'https://Stackoverflow.com/users/8427', 'pm_score': 2, 'selected': False, 'text': '<pre><code>if hasattr(obj, \'__call__\'): pass\n</code></pre>\n\n<p>This also fits in better with Python\'s "duck typing" philosophy, because you don\'t really care <em>what</em> it is, so long as you can call it.</p>\n\n<p>It\'s worth noting that <code>callable()</code> is being removed from Python and is not present in 3.0.</p>\n'}, {'answer_id': 74295, 'author': 'dF.', 'author_id': 3002, 'author_profile': 'https://Stackoverflow.com/users/3002', 'pm_score': 3, 'selected': False, 'text': '<p>If you want to exclude classes and other random objects that may have a <code>__call__</code> method, and only check for functions and methods, these three functions in the <a href="http://docs.python.org/lib/module-inspect.html" rel="noreferrer"><code>inspect</code> module</a></p>\n\n<pre><code>inspect.isfunction(obj)\ninspect.isbuiltin(obj)\ninspect.ismethod(obj)\n</code></pre>\n\n<p>should do what you want in a future-proof way.</p>\n'}, {'answer_id': 75370, 'author': 'Matthieu', 'author_id': 9310, 'author_profile': 'https://Stackoverflow.com/users/9310', 'pm_score': 1, 'selected': False, 'text': "<p>Depending on what you mean by 'class':</p>\n\n<pre><code>callable( obj ) and not inspect.isclass( obj )\n</code></pre>\n\n<p>or:</p>\n\n<pre><code>callable( obj ) and not isinstance( obj, types.ClassType )\n</code></pre>\n\n<p>For example, results are different for 'dict':</p>\n\n<pre><code>>>> callable( dict ) and not inspect.isclass( dict )\nFalse\n>>> callable( dict ) and not isinstance( dict, types.ClassType )\nTrue\n</code></pre>\n"}, {'answer_id': 75507, 'author': 'Matthieu', 'author_id': 9310, 'author_profile': 'https://Stackoverflow.com/users/9310', 'pm_score': 5, 'selected': True, 'text': '<p>The inspect module has exactly what you want:</p>\n\n<pre><code>inspect.isroutine( obj )\n</code></pre>\n\n<p>FYI, the code is:</p>\n\n<pre><code>def isroutine(object):\n """Return true if the object is any kind of function or method."""\n return (isbuiltin(object)\n or isfunction(object)\n or ismethod(object)\n or ismethoddescriptor(object))\n</code></pre>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/74092', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/156/'] |
74,108 | <p>I wrote a script to export twitter friends as foaf rdf description. Now I'm looking for a tool to visualize the friend networks. I tried <a href="http://foafscape.berlios.de/" rel="nofollow noreferrer">http://foafscape.berlios.de/</a> but for 300+ Nodes it is really slow and does a bad job on auto formatting.</p>
<p>Any hints for good graph visualization tools? It's ok if they do not support foaf directly, but they should be able to use images for graph nodes and be able to display large graphs. Linux support would be nice.</p>
<p>Oh, and I'm searching for an interactive tool where I can move nodes by hand.</p>
<p><strong>Update:</strong> Thanks for your input. I know graphviz and for static images it is really great. But for large datasets I need to be able to select nodes and highlight all neighbours. </p>
<ul>
<li><strong>Prefuse</strong> looks great: <a href="http://prefuse.org/gallery/graphview/" rel="nofollow noreferrer">http://prefuse.org/gallery/graphview/</a></li>
<li>trough prefuse I found <strong>vizster</strong>, which is exactly what I search (just need to find some sourcecode) <a href="http://jheer.org/vizster/" rel="nofollow noreferrer">http://jheer.org/vizster/</a></li>
</ul>
| [{'answer_id': 74137, 'author': 'sirprize', 'author_id': 12902, 'author_profile': 'https://Stackoverflow.com/users/12902', 'pm_score': 4, 'selected': True, 'text': '<p>perhaps the <a href="http://prefuse.org/" rel="noreferrer">prefuse</a> visualization toolkit might help you. It\'s based on Java and has many sample apps including a <a href="http://prefuse.org/gallery/graphview/" rel="noreferrer">graph viewer</a>.</p>\n'}, {'answer_id': 74142, 'author': 'Jan Krüger', 'author_id': 12471, 'author_profile': 'https://Stackoverflow.com/users/12471', 'pm_score': 2, 'selected': False, 'text': '<p>I don\'t know of any program that auto-generates graph visualizations <em>and</em> allows you to interactively adjust nodes, but <a href="http://www.graphviz.org/" rel="nofollow noreferrer">Graphviz</a> is a really popular tool for graph visualization. It can export to SVG so you can edit the result in your favorite vector graphics editor.</p>\n'}, {'answer_id': 74150, 'author': 'Cristian Ciupitu', 'author_id': 12892, 'author_profile': 'https://Stackoverflow.com/users/12892', 'pm_score': 2, 'selected': False, 'text': '<p>You could try <a href="http://www.graphviz.org" rel="nofollow noreferrer">Graphviz</a>. It <em>runs on Linux</em>, Windows and Mac OS X and it will generate an image (PNG, PS, etc) of the graph. You will have to transform your foaf data into its own custom language, but it\'s pretty easy to learn.</p>\n'}, {'answer_id': 74157, 'author': 'Paul Reiners', 'author_id': 7648, 'author_profile': 'https://Stackoverflow.com/users/7648', 'pm_score': 1, 'selected': False, 'text': '<p>If you\'re using Java, you could use <a href="http://www.jgraph.com/" rel="nofollow noreferrer">JGraph</a>.</p>\n'}, {'answer_id': 74270, 'author': 'Adam Hopkinson', 'author_id': 12280, 'author_profile': 'https://Stackoverflow.com/users/12280', 'pm_score': 2, 'selected': False, 'text': '<p>Try using Google Social Graph. In one of the talks at dConstruct08 last week there was a social graph showing the friend connections of Robert Scoble.</p>\n\n<p><a href="http://code.google.com/apis/socialgraph/" rel="nofollow noreferrer">http://code.google.com/apis/socialgraph/</a><br>\n<a href="http://dconstruct.org/2008" rel="nofollow noreferrer">http://dconstruct.org/2008</a></p>\n'}, {'answer_id': 74338, 'author': 'willasaywhat', 'author_id': 12234, 'author_profile': 'https://Stackoverflow.com/users/12234', 'pm_score': 1, 'selected': False, 'text': '<p>I know Adobe Flex has a few graph visualization components out there, and of course that would enable the app to run on Flash which has an excellent penetration rate into your potential userbase. I\'d Google up the Flex SpringGraph component, and check that out. There are a ton of graphing components in the wild for Flex, both paid and free versions.</p>\n\n<p>Just one SpringGraph off the top of my head:\n<a href="http://www.adobe.com/cfusion/exchange/index.cfm?event=extensionDetail&extid=1048510" rel="nofollow noreferrer">http://www.adobe.com/cfusion/exchange/index.cfm?event=extensionDetail&extid=1048510</a></p>\n'}, {'answer_id': 74395, 'author': 'wxs', 'author_id': 12981, 'author_profile': 'https://Stackoverflow.com/users/12981', 'pm_score': 2, 'selected': False, 'text': '<p>As recommended by other posters, definitely <a href="http://graphviz.org" rel="nofollow noreferrer" title="Graphviz">Graphviz</a>. It takes an input file, let\'s call it foaf.dot, in the following format:</p>\n\n<pre><code>graph G {\n "George Formby" [shape=custom, shapefile="file:formby.png"];\n "Michael Jackson" [shape=custom, shapefile="file:jackson.png"];\n "George Formby" -- "Michael Jackson";\n "Fred Flinstone" -- "Michael Jackson";\n "Michael Jackson" -- "Steve McQueen";\n}\n</code></pre>\n\n<p>Note that this file describes an undirected graph (hopefully your friendships are reciprocal). The syntax for directed graphs is similar.</p>\n\n<p>In order to output your graph to a pdf file (assuming that you have already installed graphviz) run the following command</p>\n\n<pre><code>dot -Tpdf foaf.dot > foaf.pdf\n</code></pre>\n\n<p>Graphviz supports a number of output formats other than pdf, see its documentation for details.</p>\n\n<p>I find that the \'dot\' program usually provides the best output results, however graphviz contains a total of 5 layout programs. From the documentation:</p>\n\n<ul>\n<li>dot - filter for drawing directed graphs</li>\n<li>neato - filter for drawing undirected graphs</li>\n<li>twopi - filter for radial layouts of graphs</li>\n<li>circo - filter for circular layout of graphs</li>\n<li>fdp - filter for drawing undirected graphs</li>\n</ul>\n'}, {'answer_id': 130674, 'author': 'rec', 'author_id': 14022, 'author_profile': 'https://Stackoverflow.com/users/14022', 'pm_score': 1, 'selected': False, 'text': '<p>check this forum: <a href="http://goosebumps4all.net/34all/bb/forumdisplay.php?fid=28" rel="nofollow noreferrer">http://goosebumps4all.net/34all/bb/forumdisplay.php?fid=28</a>\nfor some flare examples, there is a friend of a friend graph around there.</p>\n'}, {'answer_id': 3799959, 'author': 'wxs', 'author_id': 12981, 'author_profile': 'https://Stackoverflow.com/users/12981', 'pm_score': 2, 'selected': False, 'text': '<p>I previously recommended Graphviz, but thought I should add another recommendation now that I have used <a href="http://gephi.org/" rel="nofollow">Gephi</a>, a newer tool than a lot of the stuff here. It\'s a very powerful interactive graph exploration tool which I have found much more usable and much faster than a lot of the alternatives here.</p>\n'}, {'answer_id': 4278493, 'author': 'ow3n', 'author_id': 441878, 'author_profile': 'https://Stackoverflow.com/users/441878', 'pm_score': 1, 'selected': False, 'text': '<p>have you tried the Python-based IDE NodeBox (1.0)? That\'s what I used to generate these: <a href="http://givememydata.com/#images" rel="nofollow">http://givememydata.com/#images</a></p>\n\n<p>vizster looks cool though, I\'ll check out that.</p>\n'}, {'answer_id': 7317557, 'author': 'Dan Brickley', 'author_id': 278046, 'author_profile': 'https://Stackoverflow.com/users/278046', 'pm_score': 1, 'selected': False, 'text': '<p>For large graphs, Gephi (http://gephi.org/) is very popular. It is highly customisable, with lots of layout and presentation options. </p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/74108', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/720/'] |
74,112 | <p>I'm using a C# MailMessage to attach a wave file (8K) to an email message. I'd like to provide a player within the body of that email message that will play that wave file if the user chooses to do so. I've tried using the embedded <object> version of WMP, and a cid: reference to the file, but Outlook 2003 rejects the object tag and won't run it. If it helps, I know my users will be on Outlook 2003.</p>
| [{'answer_id': 74163, 'author': 'Jesper Blad Jensen', 'author_id': 11559, 'author_profile': 'https://Stackoverflow.com/users/11559', 'pm_score': 1, 'selected': False, 'text': '<p>If it don\'t support objects tags, then try the Embed tag instead:</p>\n\n<p><a href="http://www.mioplanet.com/rsc/embed_mediaplayer.htm" rel="nofollow noreferrer">http://www.mioplanet.com/rsc/embed_mediaplayer.htm</a></p>\n\n<p>I don\'t know it if works, but it is worth a shot :)</p>\n'}, {'answer_id': 74323, 'author': 'Grank', 'author_id': 12975, 'author_profile': 'https://Stackoverflow.com/users/12975', 'pm_score': 0, 'selected': False, 'text': '<p>I would try using the <a href="http://www.htmlcodetutorial.com/embeddedobjects/_EMBED.html" rel="nofollow noreferrer">EMBED</a> tag. I\'m not too surprised that OBJECT doesn\'t work, as invoking an ActiveX control is a potential "security hole" of sorts in the email system. I\'m not sure that EMBED would work either though, and that\'s probably by design. Many users would find that behavior undesirable (their email being able to take multimedia actions on opening in Outlook) and the expected user experience is to have attachments listed with the option to execute them on click.\nThe alternative might be to have a link they could click that would open a web page with the multimedia embedded, if you don\'t want them to have to play it locally on their associated multimedia app.</p>\n'}, {'answer_id': 74503, 'author': 'Timothy Lee Russell', 'author_id': 12919, 'author_profile': 'https://Stackoverflow.com/users/12919', 'pm_score': 0, 'selected': False, 'text': "<p>I don't think this is possible as ActiveX and Javascript are disabled in Outlook.</p>\n\n<p>It seems like it would be better to just link to a web page that has an embedded player with the audio file.</p>\n"}, {'answer_id': 299974, 'author': 'Mike Powell', 'author_id': 205, 'author_profile': 'https://Stackoverflow.com/users/205', 'pm_score': 1, 'selected': True, 'text': '<p>If you know the message recipients are running Outlook (which implies you\'re using this internally), you might be able to accomplish something even better by incorporating your player controls into a <a href="http://www.outlookcode.com/article.aspx?id=35" rel="nofollow noreferrer">custom Outlook form</a>.</p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/74112', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/322538/'] |
74,113 | <p>It seems obvious that some people have been able to figure out how to access the iPhone camera through the SDK (Spore Origins, for example). How can this be done?</p>
| [{'answer_id': 74255, 'author': 'wxs', 'author_id': 12981, 'author_profile': 'https://Stackoverflow.com/users/12981', 'pm_score': 7, 'selected': True, 'text': '<p>You need to use the <code>UIImagePickerController</code> class, basically:</p>\n\n<pre><code>UIImagePickerController *picker = [[UIImagePickerController alloc] init];\npicker.delegate = pickerDelegate\npicker.sourceType = UIImagePickerControllerSourceTypeCamera\n</code></pre>\n\n<p>The <code>pickerDelegate</code> object above needs to implement the following method:</p>\n\n<pre><code>- (void)imagePickerController:(UIImagePickerController *)picker\n didFinishPickingMediaWithInfo:(NSDictionary *)info\n</code></pre>\n\n<p>The dictionary <code>info</code> will contain entries for the original, and the edited image, keyed with <code>UIImagePickerControllerOriginalImage</code> and <code>UIImagePickerControllerEditedImage</code> respectively. (see <a href="https://developer.apple.com/documentation/uikit/uiimagepickercontrollerdelegate" rel="nofollow noreferrer">https://developer.apple.com/documentation/uikit/uiimagepickercontrollerdelegate</a> and <a href="https://developer.apple.com/documentation/uikit/uiimagepickercontrollerinfokey" rel="nofollow noreferrer">https://developer.apple.com/documentation/uikit/uiimagepickercontrollerinfokey</a> for more details)</p>\n'}, {'answer_id': 3211440, 'author': 'binshi', 'author_id': 356250, 'author_profile': 'https://Stackoverflow.com/users/356250', 'pm_score': 3, 'selected': False, 'text': '<p>Hmmmm.....Ever tried using an OverlayView? With this the camera might look customized but in actuality its just a view above it.</p>\n\n<p>If the private API\'s are directly accessed it might result in the app being rejected by Apple.\nSee if the below link helps.</p>\n\n<p><a href="http://www.articlesbase.com/programming-articles/custom-camera-applications-development-using-iphone-sdk-766832.html" rel="noreferrer">link text</a></p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/74113', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5338/'] |
74,116 | <p>I have always been able to read and write basic text files in C++, but so far no one has discussed much more than that. </p>
<p>My question is this:</p>
<p>If developing a file type by myself for use by an application I also create, how would I go about writing the data to a file and preserve the layout, formatting, etc.? Are there any standards, or does it just depend on the creativity of the programmer?</p>
| [{'answer_id': 74124, 'author': 'Vhaerun', 'author_id': 11234, 'author_profile': 'https://Stackoverflow.com/users/11234', 'pm_score': 0, 'selected': False, 'text': '<p>If you create a binary file , you can write any file to it . The only drawback is that you have to know exactly where it starts and where it ends .</p>\n'}, {'answer_id': 74131, 'author': 'Frank Wiles', 'author_id': 12568, 'author_profile': 'https://Stackoverflow.com/users/12568', 'pm_score': 0, 'selected': False, 'text': "<p>You usually use a third party library for these things. For example, you would link in a database library for say Oracle that would allow you to talk to the database. Because the underlying file type, ( i.e. Excel spreadsheet vs Openoffice, Oracle vs MySQL, etc. ) differ these libraries abstract away your need to care how the file is constructed. </p>\n\n<p>Hope that helps you find what you're looking for!</p>\n"}, {'answer_id': 74132, 'author': 'cazlab', 'author_id': 6178, 'author_profile': 'https://Stackoverflow.com/users/6178', 'pm_score': 2, 'selected': False, 'text': '<p>There are a number of standards of course. The likely one to use is some flavor of xml since there are libraries and tools that already exist to help you work with it, but nothing is stopping you from inventing your own.</p>\n'}, {'answer_id': 74134, 'author': 'David Thibault', 'author_id': 5903, 'author_profile': 'https://Stackoverflow.com/users/5903', 'pm_score': 2, 'selected': False, 'text': "<p>You basically have to come up with your own file format and write binary data.\nYou can also serialize your object model and write the output to a file, but that's usually less efficient.</p>\n\n<p>Better to use an existing database, or use xml (or other) for simple needs. If you want to write a file in a format that already exists, find a library that supports it.</p>\n"}, {'answer_id': 74139, 'author': 'Marc Gear', 'author_id': 6563, 'author_profile': 'https://Stackoverflow.com/users/6563', 'pm_score': 2, 'selected': False, 'text': '<p>Well you could store the data in a format you could read, but which maintained the integrity of your data (XML or JSON for instance). </p>\n\n<p>Or (<em>shudder</em>) you could come up with your own propriatory binary format, and use that.</p>\n'}, {'answer_id': 74153, 'author': 'Jean', 'author_id': 7898, 'author_profile': 'https://Stackoverflow.com/users/7898', 'pm_score': 2, 'selected': False, 'text': '<p>you would go at it exactly the same way as you would a text file. writing your data byte by byte, encoded in such a way that when you read the file you know what you are reading. \nfor a spreadsheet application you could even use a text format (OOXML, OpenDocument) to store presentation and content information. </p>\n\n<p>Or you could define binary datastructures and write that directly to the file.</p>\n\n<p>the choice between text or binary format depends on the application. for a configuration file you may prefer a text file which can be modified outside your app, for a database you will most likely choose a binary format for performance reasons.</p>\n'}, {'answer_id': 74160, 'author': 'Tom Ritter', 'author_id': 8435, 'author_profile': 'https://Stackoverflow.com/users/8435', 'pm_score': 2, 'selected': False, 'text': '<p>You have to know the binary file format for the file you are trying to create. Consider <a href="http://www.joelonsoftware.com/items/2008/02/19.html" rel="nofollow noreferrer">Joel\'s post on this topic</a>: the 97-2003 File Format is a 349 page spec. </p>\n\n<p>Nearly all the time, to do something like that, you use an API, to avoid the grunt work. Be careful however, because trial and error and figuring out "what works" by trial and error can result in an upgrade of the program breaking your code. Plus you have to take into account other operating systems, minor version differences, patches, etc.</p>\n'}, {'answer_id': 74173, 'author': 'Brian R. Bondy', 'author_id': 3153, 'author_profile': 'https://Stackoverflow.com/users/3153', 'pm_score': 1, 'selected': False, 'text': '<p>See <a href="http://www.wotsit.org/" rel="nofollow noreferrer">wotsit.org</a> for information on file formats for various file types. Example: You can figure out exactly how to write out a .BMP file and how it is composed.</p>\n\n<p>Writing to a database can be done by using a wrapper class in your language, mainly passing it SQL commands. </p>\n'}, {'answer_id': 74177, 'author': 'Nerdfest', 'author_id': 7855, 'author_profile': 'https://Stackoverflow.com/users/7855', 'pm_score': 0, 'selected': False, 'text': '<p>Use xml (something open, descriptive, and validatable), and stick with the text. There are standards for this sort of thing as well, including <a href="http://en.wikipedia.org/wiki/OpenDocument" rel="nofollow noreferrer">ODF</a></p>\n'}, {'answer_id': 74182, 'author': 'foxxtrot', 'author_id': 10369, 'author_profile': 'https://Stackoverflow.com/users/10369', 'pm_score': 0, 'selected': False, 'text': '<p>You can open the file as binary, instead of text (how one does this depends somewhat on the platform), from there you can write the data directly out to disk. The only real caveat to this is <a href="http://en.wikipedia.org/wiki/Endianess" rel="nofollow noreferrer">endianess</a>, which can become an issue when moving the files from one architecture to another (x86 to PPC for instance).</p>\n\n<p>Writing binary data to disk is really no harder than writing text, and really, your creativity is key for how you store the data.</p>\n'}, {'answer_id': 74189, 'author': 'Allan Wind', 'author_id': 9706, 'author_profile': 'https://Stackoverflow.com/users/9706', 'pm_score': 0, 'selected': False, 'text': '<p>The general problem is usually referred to as serialization of your application state and in your case with a source/target of a file in whatever format makes sense for you. These days the preferred input/output format is XML, and you may want to look into the existing standards in this field. The problem then becomes how do I map from the state of my system to the particular schema. Boost has a serialization framework that you may want to check out.</p>\n\n<p>/Allan</p>\n'}, {'answer_id': 74240, 'author': 'Eclipse', 'author_id': 8701, 'author_profile': 'https://Stackoverflow.com/users/8701', 'pm_score': 0, 'selected': False, 'text': '<p>There are a variety of approaches you can take, but in general you\'ll want some sort of serialization library. BOOST::Serialization, or <a href="http://code.google.com/apis/protocolbuffers/" rel="nofollow noreferrer" title="Google's Protocal Buffers">Google\'s Protocal Buffers</a> are a good example of these. The basic idea is that you have memory structures (classes and objects) that represent your data, and you want to write that data to a file in a way that can be used to reconstruct those structures again.</p>\n\n<p>If you\'re hesitant to use a library, you can do it all manually, but realize that you can end up writing a lot of redundant code, or developing your own library. See <a href="http://msdn.microsoft.com/en-us/library/c565h7xx.aspx" rel="nofollow noreferrer">fopen, fread, fwrite and fclose</a> for a starting point.</p>\n'}, {'answer_id': 382786, 'author': 'user21826', 'author_id': 21826, 'author_profile': 'https://Stackoverflow.com/users/21826', 'pm_score': 0, 'selected': False, 'text': '<p>A typical binary file format for custom data is an "indexed file format" consisting of</p>\n\n<pre>\n-------\n|index|\n-------\n|data |\n-------\n</pre>\n\n<p>Where the index contains records "pointing" to the data.</p>\n\n<p>The index consists of records containing an offset and a size. The offset tells you where in the file the data is stored and the size tells you the size of the data at that offset (i.e. the number of bytes to read).</p>\n\n<pre>\ntypedef struct {\n size_t offset\n size_t size\n} Index\n\ntypedef struct {\n int ID\n char First[20]\n char Last[20]\n char *RandomInfo\n} Data\n</pre>\n\n<p>Suppose you want to store 50 records in the file you would create 50 indices and 50 data structures. The 50 index structures would be written to the file first, followed by the 50 data structures.</p>\n\n<p>To read the file you would read in the 50 index structures, then from the data in the read-in index structures you could tell where to "seek" to read the data records.</p>\n\n<p>Look up (fopen, fread, fwrite, fclose, ftell) for functions to read/write the data.</p>\n\n<p>(Sorry my semicolon key doesn\'t work)</p>\n'}, {'answer_id': 22926815, 'author': 'icedwater', 'author_id': 1091386, 'author_profile': 'https://Stackoverflow.com/users/1091386', 'pm_score': 0, 'selected': False, 'text': '<p>1985 called, and said they have some help IFF you are willing to read up. The <a href="http://en.wikipedia.org/wiki/Interchange_File_Format" rel="nofollow">interchange file format</a> is still in use today and provides some basic metadata around binary files, such as RIFF or WAV audio. (Unfortunately, TIFF is a false friend.) It <a href="http://en.wikipedia.org/wiki/Interchange_File_Format" rel="nofollow">allegedly</a> even inspired PNG, so it can\'t be that bad.</p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/74116', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/73/'] |
74,126 | <p>I have a Windows XP SP2 virtual machine which can be accessed via VNC. It's also running Deep Freeze so there should be no problem in forcing it to reboot. I am looking for a way to force the operating system to reboot instead of shutting down or completely remove the ability to shut down the machine using software applications (such as the usual way from the start menu, the shutdown program or other custom programs).</p>
<p>Thank you,
Tom</p>
| [{'answer_id': 74143, 'author': 'Alex Fort', 'author_id': 12624, 'author_profile': 'https://Stackoverflow.com/users/12624', 'pm_score': 3, 'selected': False, 'text': '<p>Try this:</p>\n\n<p><code>shutdown /r /t 1 /f</code></p>\n\n<p>Alex</p>\n'}, {'answer_id': 74156, 'author': 'Toby Mills', 'author_id': 12377, 'author_profile': 'https://Stackoverflow.com/users/12377', 'pm_score': 1, 'selected': False, 'text': '<p>In XP there is a DOS command called shutdown. If you type <code>shutdown /?</code> from a command prompt you will see the options available. Using this you can create a Batch file.</p>\n'}, {'answer_id': 74158, 'author': 'Burkhard', 'author_id': 12860, 'author_profile': 'https://Stackoverflow.com/users/12860', 'pm_score': 0, 'selected': False, 'text': "<p>Try DShutdown.exe. It's flexible and can do all these things.</p>\n"}, {'answer_id': 74200, 'author': 'Toby Mills', 'author_id': 12377, 'author_profile': 'https://Stackoverflow.com/users/12377', 'pm_score': 3, 'selected': True, 'text': '<p>To remove the ability to shut down then your best bet is to create a group policy for the user/user group and specify that they can only restart the system. I have done this in the past to ensure that only the administrator account can shut down a computer. it has prevented me from mistakenly shutting down a remote pc at 2am in the morning when i meant to re-start it.</p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/74126', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/'] |
74,148 | <p>How do you convert between hexadecimal numbers and decimal numbers in C#?</p>
| [{'answer_id': 74183, 'author': 'Sklivvz', 'author_id': 7028, 'author_profile': 'https://Stackoverflow.com/users/7028', 'pm_score': 2, 'selected': False, 'text': '<pre><code>String stringrep = myintvar.ToString("X");\n\nint num = int.Parse("FF", System.Globalization.NumberStyles.HexNumber);\n</code></pre>\n'}, {'answer_id': 74185, 'author': 'Jesper Blad Jensen', 'author_id': 11559, 'author_profile': 'https://Stackoverflow.com/users/11559', 'pm_score': 5, 'selected': False, 'text': '<p>It looks like you can say</p>\n\n<pre><code>Convert.ToInt64(value, 16)\n</code></pre>\n\n<p>to get the decimal from hexdecimal.</p>\n\n<p>The other way around is:</p>\n\n<pre><code>otherVar.ToString("X");\n</code></pre>\n'}, {'answer_id': 74191, 'author': 'Rob', 'author_id': 12413, 'author_profile': 'https://Stackoverflow.com/users/12413', 'pm_score': 4, 'selected': False, 'text': '<p><a href="https://web.archive.org/web/20081231062758/http://www.geekpedia.com/KB8_How-do-I-convert-from-decimal-to-hex-and-hex-to-decimal.html" rel="noreferrer">From Geekpedia</a>:</p>\n\n<pre><code>// Store integer 182\nint decValue = 182;\n\n// Convert integer 182 as a hex in a string variable\nstring hexValue = decValue.ToString("X");\n\n// Convert the hex string back to the number\nint decAgain = int.Parse(hexValue, System.Globalization.NumberStyles.HexNumber);\n</code></pre>\n'}, {'answer_id': 74198, 'author': 'Jonathan Rupp', 'author_id': 12502, 'author_profile': 'https://Stackoverflow.com/users/12502', 'pm_score': 6, 'selected': False, 'text': '<p>Hex -> decimal:</p>\n<pre><code>Convert.ToInt64(hexString, 16);\n</code></pre>\n<p>Decimal -> Hex</p>\n<pre><code>string.Format("{0:x}", intValue);\n</code></pre>\n'}, {'answer_id': 74223, 'author': 'Andy McCluggage', 'author_id': 3362, 'author_profile': 'https://Stackoverflow.com/users/3362', 'pm_score': 9, 'selected': True, 'text': '<p>To convert from decimal to hex do...</p>\n\n<pre><code>string hexValue = decValue.ToString("X");\n</code></pre>\n\n<p>To convert from hex to decimal do either...</p>\n\n<pre><code>int decValue = int.Parse(hexValue, System.Globalization.NumberStyles.HexNumber);\n</code></pre>\n\n<p>or </p>\n\n<pre><code>int decValue = Convert.ToInt32(hexValue, 16);\n</code></pre>\n'}, {'answer_id': 2484244, 'author': 'Ecstatic Coder', 'author_id': 298120, 'author_profile': 'https://Stackoverflow.com/users/298120', 'pm_score': 1, 'selected': False, 'text': '<pre><code> static string chex(byte e) // Convert a byte to a string representing that byte in hexadecimal\n {\n string r = "";\n string chars = "0123456789ABCDEF";\n r += chars[e >> 4];\n return r += chars[e &= 0x0F];\n } // Easy enough...\n\n static byte CRAZY_BYTE(string t, int i) // Take a byte, if zero return zero, else throw exception (i=0 means false, i>0 means true)\n {\n if (i == 0) return 0;\n throw new Exception(t);\n }\n\n static byte hbyte(string e) // Take 2 characters: these are hex chars, convert it to a byte\n { // WARNING: This code will make small children cry. Rated R.\n e = e.ToUpper(); // \n string msg = "INVALID CHARS"; // The message that will be thrown if the hex str is invalid\n\n byte[] t = new byte[] // Gets the 2 characters and puts them in seperate entries in a byte array.\n { // This will throw an exception if (e.Length != 2).\n (byte)e[CRAZY_BYTE("INVALID LENGTH", e.Length ^ 0x02)], \n (byte)e[0x01] \n };\n\n for (byte i = 0x00; i < 0x02; i++) // Convert those [ascii] characters to [hexadecimal] characters. Error out if either character is invalid.\n {\n t[i] -= (byte)((t[i] >= 0x30) ? 0x30 : CRAZY_BYTE(msg, 0x01)); // Check for 0-9\n t[i] -= (byte)((!(t[i] < 0x0A)) ? (t[i] >= 0x11 ? 0x07 : CRAZY_BYTE(msg, 0x01)) : 0x00); // Check for A-F\n } \n\n return t[0x01] |= t[0x00] <<= 0x04; // The moment of truth.\n }\n</code></pre>\n'}, {'answer_id': 4474966, 'author': 'Omair', 'author_id': 546562, 'author_profile': 'https://Stackoverflow.com/users/546562', 'pm_score': 1, 'selected': False, 'text': '<p>This is not really easiest way but this source code enable you to right any types of octal number i.e 23.214, 23 and 0.512 and so on. Hope this will help you..</p>\n\n<pre><code> public string octal_to_decimal(string m_value)\n {\n double i, j, x = 0;\n Int64 main_value;\n int k = 0;\n bool pw = true, ch;\n int position_pt = m_value.IndexOf(".");\n if (position_pt == -1)\n {\n main_value = Convert.ToInt64(m_value);\n ch = false;\n }\n else\n {\n main_value = Convert.ToInt64(m_value.Remove(position_pt, m_value.Length - position_pt));\n ch = true;\n }\n\n while (k <= 1)\n {\n do\n {\n i = main_value % 10; // Return Remainder\n i = i * Convert.ToDouble(Math.Pow(8, x)); // calculate power\n if (pw)\n x++;\n else\n x--;\n o_to_d = o_to_d + i; // Saving Required calculated value in main variable\n main_value = main_value / 10; // Dividing the main value \n }\n while (main_value >= 1);\n if (ch)\n {\n k++;\n main_value = Convert.ToInt64(Reversestring(m_value.Remove(0, position_pt + 1)));\n }\n else\n k = 2;\n pw = false;\n x = -1;\n }\n return (Convert.ToString(o_to_d));\n } \n</code></pre>\n'}, {'answer_id': 6205484, 'author': 'msanjay', 'author_id': 392985, 'author_profile': 'https://Stackoverflow.com/users/392985', 'pm_score': 2, 'selected': False, 'text': '<p>If it\'s a really big hex string beyond the capacity of the normal integer:</p>\n\n<p>For .NET 3.5, we can use BouncyCastle\'s BigInteger class:</p>\n\n<pre><code>String hex = "68c7b05d0000000002f8";\n// results in "494809724602834812404472"\nString decimal = new Org.BouncyCastle.Math.BigInteger(hex, 16).ToString();\n</code></pre>\n\n<p>.NET 4.0 has the <a href="http://msdn.microsoft.com/en-us/library/system.numerics.biginteger.aspx" rel="nofollow">BigInteger</a> class.</p>\n'}, {'answer_id': 6666767, 'author': 'Luke Puplett', 'author_id': 107783, 'author_profile': 'https://Stackoverflow.com/users/107783', 'pm_score': -1, 'selected': False, 'text': '<p>An extension method for converting a byte array into a hex representation. This pads each byte with leading zeros.</p>\n\n<pre><code> /// <summary>\n /// Turns the byte array into its Hex representation.\n /// </summary>\n public static string ToHex(this byte[] y)\n {\n StringBuilder sb = new StringBuilder();\n foreach (byte b in y)\n {\n sb.Append(b.ToString("X").PadLeft(2, "0"[0]));\n }\n return sb.ToString();\n }\n</code></pre>\n'}, {'answer_id': 9126750, 'author': 'Vadym Stetsiak', 'author_id': 6952, 'author_profile': 'https://Stackoverflow.com/users/6952', 'pm_score': 4, 'selected': False, 'text': '<p>If you want maximum performance when doing conversion from hex to decimal number, you can use the approach with pre-populated table of hex-to-decimal values.</p>\n\n<p>Here is the code that illustrates that idea. My <a href="http://vadmyst.blogspot.com/2012/02/fast-convertion-of-hex-string-into.html" rel="noreferrer">performance tests</a> showed that it can be 20%-40% faster than Convert.ToInt32(...):</p>\n\n<pre><code>class TableConvert\n {\n static sbyte[] unhex_table =\n { -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1\n ,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1\n ,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1\n , 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1,-1,-1,-1,-1\n ,-1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1\n ,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1\n ,-1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1\n ,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1\n };\n\n public static int Convert(string hexNumber)\n {\n int decValue = unhex_table[(byte)hexNumber[0]];\n for (int i = 1; i < hexNumber.Length; i++)\n {\n decValue *= 16;\n decValue += unhex_table[(byte)hexNumber[i]];\n }\n return decValue;\n }\n }\n</code></pre>\n'}, {'answer_id': 21079586, 'author': 'Chris Panayotoff', 'author_id': 1584898, 'author_profile': 'https://Stackoverflow.com/users/1584898', 'pm_score': -1, 'selected': False, 'text': '<p>Here is my function:</p>\n\n<pre><code>using System;\nusing System.Collections.Generic;\nclass HexadecimalToDecimal\n{\n static Dictionary<char, int> hexdecval = new Dictionary<char, int>{\n {\'0\', 0},\n {\'1\', 1},\n {\'2\', 2},\n {\'3\', 3},\n {\'4\', 4},\n {\'5\', 5},\n {\'6\', 6},\n {\'7\', 7},\n {\'8\', 8},\n {\'9\', 9},\n {\'a\', 10},\n {\'b\', 11},\n {\'c\', 12},\n {\'d\', 13},\n {\'e\', 14},\n {\'f\', 15},\n };\n\n static decimal HexToDec(string hex)\n {\n decimal result = 0;\n hex = hex.ToLower();\n\n for (int i = 0; i < hex.Length; i++)\n {\n char valAt = hex[hex.Length - 1 - i];\n result += hexdecval[valAt] * (int)Math.Pow(16, i);\n }\n\n return result;\n }\n\n static void Main()\n {\n\n Console.WriteLine("Enter Hexadecimal value");\n string hex = Console.ReadLine().Trim();\n\n //string hex = "29A";\n Console.WriteLine("Hex {0} is dec {1}", hex, HexToDec(hex));\n\n Console.ReadKey();\n }\n}\n</code></pre>\n'}, {'answer_id': 28408141, 'author': 'Mihók Balázs', 'author_id': 4545945, 'author_profile': 'https://Stackoverflow.com/users/4545945', 'pm_score': 0, 'selected': False, 'text': '<p>My version is I think a little more understandable because my C# knowledge is not so high.\nI\'m using this algorithm: <a href="http://easyguyevo.hubpages.com/hub/Convert-Hex-to-Decimal" rel="nofollow">http://easyguyevo.hubpages.com/hub/Convert-Hex-to-Decimal</a> (The Example 2)</p>\n\n<pre><code>using System;\nusing System.Collections.Generic;\n\nstatic class Tool\n{\n public static string DecToHex(int x)\n {\n string result = "";\n\n while (x != 0)\n {\n if ((x % 16) < 10)\n result = x % 16 + result;\n else\n {\n string temp = "";\n\n switch (x % 16)\n {\n case 10: temp = "A"; break;\n case 11: temp = "B"; break;\n case 12: temp = "C"; break;\n case 13: temp = "D"; break;\n case 14: temp = "E"; break;\n case 15: temp = "F"; break;\n }\n\n result = temp + result;\n }\n\n x /= 16;\n }\n\n return result;\n }\n\n public static int HexToDec(string x)\n {\n int result = 0;\n int count = x.Length - 1;\n for (int i = 0; i < x.Length; i++)\n {\n int temp = 0;\n switch (x[i])\n {\n case \'A\': temp = 10; break;\n case \'B\': temp = 11; break;\n case \'C\': temp = 12; break;\n case \'D\': temp = 13; break;\n case \'E\': temp = 14; break;\n case \'F\': temp = 15; break;\n default: temp = -48 + (int)x[i]; break; // -48 because of ASCII\n }\n\n result += temp * (int)(Math.Pow(16, count));\n count--;\n }\n\n return result;\n }\n}\n\nclass Program\n{\n static void Main(string[] args)\n {\n Console.Write("Enter Decimal value: ");\n int decNum = int.Parse(Console.ReadLine());\n\n Console.WriteLine("Dec {0} is hex {1}", decNum, Tool.DecToHex(decNum));\n\n Console.Write("\\nEnter Hexadecimal value: ");\n string hexNum = Console.ReadLine().ToUpper();\n\n Console.WriteLine("Hex {0} is dec {1}", hexNum, Tool.HexToDec(hexNum));\n\n Console.ReadKey();\n }\n}\n</code></pre>\n'}, {'answer_id': 29939746, 'author': 'Jewel', 'author_id': 4845704, 'author_profile': 'https://Stackoverflow.com/users/4845704', 'pm_score': 0, 'selected': False, 'text': '<p>Convert binary to Hex</p>\n\n<pre><code>Convert.ToString(Convert.ToUInt32(binary1, 2), 16).ToUpper()\n</code></pre>\n'}, {'answer_id': 44120599, 'author': 'user7925882', 'author_id': 7925882, 'author_profile': 'https://Stackoverflow.com/users/7925882', 'pm_score': 2, 'selected': False, 'text': '<p>Hex to Decimal Conversion</p>\n\n<pre><code>Convert.ToInt32(number, 16);\n</code></pre>\n\n<p>Decimal to Hex Conversion</p>\n\n<pre><code>int.Parse(number, System.Globalization.NumberStyles.HexNumber)\n</code></pre>\n\n<p><a href="http://kodecenter.com/article?id=f3ed25f1-2563-4323-9f43-c4fbbc9c372f" rel="nofollow noreferrer">For more details Check this article</a></p>\n'}, {'answer_id': 49569835, 'author': 'Aravin', 'author_id': 3058254, 'author_profile': 'https://Stackoverflow.com/users/3058254', 'pm_score': 2, 'selected': False, 'text': '<p>Try using BigNumber in C# - Represents an arbitrarily large signed integer.</p>\n\n<h3>Program</h3>\n\n<pre><code>using System.Numerics;\n...\nvar bigNumber = BigInteger.Parse("837593454735734579347547357233757342857087879423437472347757234945743");\nConsole.WriteLine(bigNumber.ToString("X"));\n</code></pre>\n\n<h3>Output</h3>\n\n<pre><code>4F30DC39A5B10A824134D5B18EEA3707AC854EE565414ED2E498DCFDE1A15DA5FEB6074AE248458435BD417F06F674EB29A2CFECF\n</code></pre>\n\n<h3>Possible Exceptions,</h3>\n\n<p>ArgumentNullException - value is null.</p>\n\n<p>FormatException - value is not in the correct format.</p>\n\n<h3>Conclusion</h3>\n\n<p>You can convert string and store a value in BigNumber without constraints about the size of the number unless the string is empty and non-analphabets</p>\n'}, {'answer_id': 54082994, 'author': 'Krisztián Molnár', 'author_id': 10881471, 'author_profile': 'https://Stackoverflow.com/users/10881471', 'pm_score': -1, 'selected': False, 'text': '<p>My solution is a bit like back to basics, but it works without using any built-in functions to convert between number systems.</p>\n\n<pre><code> public static string DecToHex(long a)\n {\n int n = 1;\n long b = a;\n while (b > 15)\n {\n b /= 16;\n n++;\n }\n string[] t = new string[n];\n int i = 0, j = n - 1;\n do\n {\n if (a % 16 == 10) t[i] = "A";\n else if (a % 16 == 11) t[i] = "B";\n else if (a % 16 == 12) t[i] = "C";\n else if (a % 16 == 13) t[i] = "D";\n else if (a % 16 == 14) t[i] = "E";\n else if (a % 16 == 15) t[i] = "F";\n else t[i] = (a % 16).ToString();\n a /= 16;\n i++;\n }\n while ((a * 16) > 15);\n string[] r = new string[n];\n for (i = 0; i < n; i++)\n {\n r[i] = t[j];\n j--;\n }\n string res = string.Concat(r);\n return res;\n }\n</code></pre>\n'}, {'answer_id': 67015650, 'author': 'MohsenB', 'author_id': 1358148, 'author_profile': 'https://Stackoverflow.com/users/1358148', 'pm_score': 0, 'selected': False, 'text': "<p>You can use this code and possible set Hex length and part's:<br></p>\n<pre><code>const int decimal_places = 4;\nconst int int_places = 4;\nstatic readonly string decimal_places_format = $"X{decimal_places}";\nstatic readonly string int_places_format = $"X{int_places}";\n\npublic static string DecimaltoHex(decimal number)\n{\n var n = (int)Math.Truncate(number);\n var f = (int)Math.Truncate((number - n) * ((decimal)Math.Pow(10, decimal_places)));\n return $"{string.Format($"{{0:{int_places_format}}}", n)}{string.Format($"{{0:{decimal_places_format}}}", f)}";\n}\n\npublic static decimal HextoDecimal(string number)\n{\n var n = number.Substring(0, number.Length - decimal_places);\n var f = number.Substring(number.Length - decimal_places);\n return decimal.Parse($"{int.Parse(n, System.Globalization.NumberStyles.HexNumber)}.{int.Parse(f, System.Globalization.NumberStyles.HexNumber)}");\n}\n</code></pre>\n"}, {'answer_id': 67652913, 'author': 'Dejan Dozet', 'author_id': 4541566, 'author_profile': 'https://Stackoverflow.com/users/4541566', 'pm_score': 1, 'selected': False, 'text': '<p>This one worked for me:</p>\n<pre><code>public static decimal HexToDec(string hex)\n{\n if (hex.Length % 2 == 1)\n hex = "0" + hex;\n byte[] raw = new byte[hex.Length / 2];\n decimal d = 0;\n for (int i = 0; i < raw.Length; i++)\n {\n raw[i] = Convert.ToByte(hex.Substring(i * 2, 2), 16);\n d += Math.Pow(256, (raw.Length - 1 - i)) * raw[i];\n }\n return d.ToString();\n return d;\n}\n</code></pre>\n'}, {'answer_id': 68256392, 'author': 'Rakibul', 'author_id': 12944359, 'author_profile': 'https://Stackoverflow.com/users/12944359', 'pm_score': 1, 'selected': False, 'text': '<p>Decimal - Hexa</p>\n<pre><code> var decValue = int.Parse(Console.ReadLine());\n string hex = string.Format("{0:x}", decValue);\n Console.WriteLine(hex);\n</code></pre>\n<p>Hexa - Decimal (use namespace: using System.Globalization;)</p>\n<pre><code> var hexval = Console.ReadLine();\n int decValue = int.Parse(hexval, NumberStyles.HexNumber);\n Console.WriteLine(decValue);\n</code></pre>\n'}, {'answer_id': 71229254, 'author': 'Marco Antonio', 'author_id': 6907130, 'author_profile': 'https://Stackoverflow.com/users/6907130', 'pm_score': 1, 'selected': False, 'text': '<p><strong>FOUR C# native ways to convert Hex to Dec and back:</strong></p>\n<pre><code>using System;\n\nnamespace Hexadecimal_and_Decimal\n{\n internal class Program\n {\n private static void Main(string[] args)\n {\n string hex = "4DEAD";\n int dec;\n\n // hex to dec:\n dec = int.Parse(hex, System.Globalization.NumberStyles.HexNumber);\n // or:\n dec = Convert.ToInt32(hex, 16);\n\n // dec to hex:\n hex = dec.ToString("X"); // lowcase: x, uppercase: X\n // or:\n hex = string.Format("{0:X}", dec); // lowcase: x, uppercase: X\n\n Console.WriteLine("Hexadecimal number: " + hex);\n Console.WriteLine("Decimal number: " + dec);\n }\n }\n}\n</code></pre>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/74148', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3362/'] |
74,162 | <p>I'm trying to write a query that extracts and transforms data from a table and then insert those data into another table. Yes, this is a data warehousing query and I'm doing it in MS Access. So basically I want some query like this:</p>
<pre><code>INSERT INTO Table2(LongIntColumn2, CurrencyColumn2) VALUES
(SELECT LongIntColumn1, Avg(CurrencyColumn) as CurrencyColumn1 FROM Table1 GROUP BY LongIntColumn1);
</code></pre>
<p>I tried but get a syntax error message.</p>
<p>What would you do if you want to do this?</p>
| [{'answer_id': 74196, 'author': 'Forgotten Semicolon', 'author_id': 1960, 'author_profile': 'https://Stackoverflow.com/users/1960', 'pm_score': 3, 'selected': False, 'text': '<p>Remove <code>VALUES</code> from your SQL.</p>\n'}, {'answer_id': 74204, 'author': 'pilsetnieks', 'author_id': 6615, 'author_profile': 'https://Stackoverflow.com/users/6615', 'pm_score': 9, 'selected': True, 'text': '<p>No "VALUES", no parenthesis:</p>\n\n<pre><code>INSERT INTO Table2(LongIntColumn2, CurrencyColumn2)\nSELECT LongIntColumn1, Avg(CurrencyColumn) as CurrencyColumn1 FROM Table1 GROUP BY LongIntColumn1;\n</code></pre>\n'}, {'answer_id': 74214, 'author': 'GSerg', 'author_id': 11683, 'author_profile': 'https://Stackoverflow.com/users/11683', 'pm_score': 5, 'selected': False, 'text': '<p>Remove both VALUES and the parenthesis.</p>\n\n<pre><code>INSERT INTO Table2 (LongIntColumn2, CurrencyColumn2)\nSELECT LongIntColumn1, Avg(CurrencyColumn) FROM Table1 GROUP BY LongIntColumn1\n</code></pre>\n'}, {'answer_id': 74222, 'author': 'Jorge Ferreira', 'author_id': 6508, 'author_profile': 'https://Stackoverflow.com/users/6508', 'pm_score': 5, 'selected': False, 'text': '<p>You have two syntax options:</p>\n\n<p><strong>Option 1</strong></p>\n\n<pre><code>CREATE TABLE Table1 (\n id int identity(1, 1) not null,\n LongIntColumn1 int,\n CurrencyColumn money\n)\n\nCREATE TABLE Table2 (\n id int identity(1, 1) not null,\n LongIntColumn2 int,\n CurrencyColumn2 money\n)\n\nINSERT INTO Table1 VALUES(12, 12.00)\nINSERT INTO Table1 VALUES(11, 13.00)\n\nINSERT INTO Table2\nSELECT LongIntColumn1, Avg(CurrencyColumn) as CurrencyColumn1 FROM Table1 GROUP BY LongIntColumn1\n</code></pre>\n\n<p><strong>Option 2</strong></p>\n\n<pre><code>CREATE TABLE Table1 (\n id int identity(1, 1) not null,\n LongIntColumn1 int,\n CurrencyColumn money\n)\n\nINSERT INTO Table1 VALUES(12, 12.00)\nINSERT INTO Table1 VALUES(11, 13.00)\n\n\nSELECT LongIntColumn1, Avg(CurrencyColumn) as CurrencyColumn1\nINTO Table2\nFROM Table1\nGROUP BY LongIntColumn1\n</code></pre>\n\n<p>Bear in mind that Option 2 will create a table with only the columns on the projection (those on the SELECT).</p>\n'}, {'answer_id': 74231, 'author': 'Philippe Grondier', 'author_id': 11436, 'author_profile': 'https://Stackoverflow.com/users/11436', 'pm_score': 2, 'selected': False, 'text': '<p>Well I think the best way would be (will be?) to define 2 recordsets and use them as an intermediate between the 2 tables. </p>\n\n<ol>\n<li>Open both recordsets</li>\n<li>Extract the data from the first table (SELECT blablabla) </li>\n<li>Update 2nd recordset with data available in the first recordset (either by adding new records or updating existing records</li>\n<li>Close both recordsets</li>\n</ol>\n\n<p>This method is particularly interesting if you plan to update tables from different databases (ie each recordset can have its own connection ...)</p>\n'}, {'answer_id': 74239, 'author': 'Sean', 'author_id': 8334, 'author_profile': 'https://Stackoverflow.com/users/8334', 'pm_score': 4, 'selected': False, 'text': '<p>I believe your problem in this instance is the "values" keyword. You use the "values" keyword when you are inserting only one row of data. For inserting the results of a select, you don\'t need it. </p>\n\n<p>Also, you really don\'t need the parentheses around the select statement. </p>\n\n<p>From <a href="http://msdn.microsoft.com/en-us/library/bb208861.aspx" rel="noreferrer">msdn</a>:</p>\n\n<p>Multiple-record append query:</p>\n\n<pre><code>INSERT INTO target [(field1[, field2[, …]])] [IN externaldatabase]\nSELECT [source.]field1[, field2[, …]\nFROM tableexpression\n</code></pre>\n\n<p>Single-record append query:</p>\n\n<pre><code>INSERT INTO target [(field1[, field2[, …]])] \nVALUES (value1[, value2[, …])\n</code></pre>\n'}, {'answer_id': 74285, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>Do you want to insert extraction in an existing table? </p>\n\n<p>If it does not matter then you can try the below query:</p>\n\n<pre><code>SELECT LongIntColumn1, Avg(CurrencyColumn) as CurrencyColumn1 INTO T1 FROM Table1 \nGROUP BY LongIntColumn1);\n</code></pre>\n\n<p>It will create a new table -> T1 with the extracted information</p>\n'}, {'answer_id': 74347, 'author': 'Chris OC', 'author_id': 11041, 'author_profile': 'https://Stackoverflow.com/users/11041', 'pm_score': 2, 'selected': False, 'text': '<p>Remove "values" when you\'re appending a group of rows, and remove the extra parentheses. You can avoid the circular reference by using an alias for avg(CurrencyColumn) (as you did in your example) or by not using an alias at all.</p>\n\n<p>If the column names are the same in both tables, your query would be like this:</p>\n\n<pre><code>INSERT INTO Table2 (LongIntColumn, Junk)\nSELECT LongIntColumn, avg(CurrencyColumn) as CurrencyColumn1\nFROM Table1\nGROUP BY LongIntColumn;\n</code></pre>\n\n<p>And it would work without an alias:</p>\n\n<pre><code>INSERT INTO Table2 (LongIntColumn, Junk)\nSELECT LongIntColumn, avg(CurrencyColumn)\nFROM Table1\nGROUP BY LongIntColumn;\n</code></pre>\n'}, {'answer_id': 348981, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': "<p>inserting data form one table to another table in different DATABASE</p>\n\n<pre><code>insert into DocTypeGroup \n Select DocGrp_Id,DocGrp_SubId,DocGrp_GroupName,DocGrp_PM,DocGrp_DocType \n from Opendatasource( 'SQLOLEDB','Data Source=10.132.20.19;UserID=sa;Password=gchaturthi').dbIPFMCI.dbo.DocTypeGroup\n</code></pre>\n"}] | 2008/09/16 | ['https://Stackoverflow.com/questions/74162', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/8203/'] |
74,171 | <p>I maintain a Java Swing application.</p>
<p>For backwards compatibility with java 5 (for Apple machines), we maintain two codebases, 1 using features from Java 6, another without those features.</p>
<p>The code is largely the same, except for 3-4 classes that uses Java 6 features.</p>
<p>I wish to just maintain 1 codebase. Is there a way during compilation, to get the Java 5 compiler to 'ignore' some parts of my code?</p>
<p>I do not wish to simply comment/uncomment parts of my code, depending on the version of my java compiler.</p>
| [{'answer_id': 74202, 'author': 'chessguy', 'author_id': 1908025, 'author_profile': 'https://Stackoverflow.com/users/1908025', 'pm_score': 2, 'selected': False, 'text': '<p>I think the best approach here is probably to use build scripts. You can have all your code in one location, and by choosing which files to include, and which not to include, you can choose what version of your code to compile. Note that this may not help if you need finer-grained control than per file.</p>\n'}, {'answer_id': 74229, 'author': 'Nikki9696', 'author_id': 456669, 'author_profile': 'https://Stackoverflow.com/users/456669', 'pm_score': 1, 'selected': False, 'text': '<p>Not really, but there are workarounds. See\n<a href="http://forums.sun.com/thread.jspa?threadID=154106&messageID=447625" rel="nofollow noreferrer">http://forums.sun.com/thread.jspa?threadID=154106&messageID=447625</a></p>\n\n<p>That said, you should stick with at least having one file version for Java 5 and one for Java 6, and include them via a build or make as appropriate. Sticking it all in one big file and trying to get the compiler for 5 to ignore stuff it doesn\'t understand isn\'t a good solution.</p>\n\n<p>HTH</p>\n\n<p>-- nikki --</p>\n'}, {'answer_id': 74259, 'author': 'DarenW', 'author_id': 10468, 'author_profile': 'https://Stackoverflow.com/users/10468', 'pm_score': 1, 'selected': False, 'text': '<p>This will make all the Java purists cringe (which is fun, heh heh) but i would use the C preprocessor, put #ifdefs in my source. A makefile, rakefile, or whatever controls your build, would have to run cpp to make a temporary files to feed the compiler. I have no idea if ant could be made to do this. </p>\n\n<p>While stackoverflow looks like it\'ll be <em>the</em> place for all answers, you could wehn no one\'s looking mosey on over to <a href="http://www.javaranch.com" rel="nofollow noreferrer">http://www.javaranch.com</a> for Java wisdom. I imagine this question has been dealt with there, prolly a long time ago.</p>\n'}, {'answer_id': 74268, 'author': 'Burkhard', 'author_id': 12860, 'author_profile': 'https://Stackoverflow.com/users/12860', 'pm_score': 0, 'selected': False, 'text': '<p>There is no pre-compiler in Java. Thus, no way to do a #ifdef like in C.\nBuild scripts would be the best way.</p>\n'}, {'answer_id': 74292, 'author': 'freespace', 'author_id': 8297, 'author_profile': 'https://Stackoverflow.com/users/8297', 'pm_score': 0, 'selected': False, 'text': "<p>You can get conditional compile, but not very nicely - javac will ignore unreachable code. Thus if you structured your code properly, you can get the compiler to ignore parts of your code. To use this properly, you would also need to pass the correct arguments to javac so it doesn't report unreachable code as errors, and refuse to compile :-)</p>\n"}, {'answer_id': 74319, 'author': 'Jesse Glick', 'author_id': 12916, 'author_profile': 'https://Stackoverflow.com/users/12916', 'pm_score': 2, 'selected': False, 'text': '<p>Keep one "master" source root that builds under JDK 5. Add a second parallel source root that has to build under JDK 6 or higher. (There should be no overlap, i.e. no classes present in both.) Use an interface to define the entry point between the two, and a tiny bit of reflection.</p>\n\n<p>For example:</p>\n\n<pre><code>---%<--- main/RandomClass.java\n// ...\nif (...is JDK 6+...) {\n try {\n JDK6Interface i = (JDK6Interface)\n Class.forName("JDK6Impl").newInstance();\n i.browseDesktop(...);\n } catch (Exception x) {\n // fall back...\n }\n}\n---%<--- main/JDK6Interface.java\npublic interface JDK6Interface {\n void browseDesktop(URI uri);\n}\n---%<--- jdk6/JDK6Impl.java\npublic class JDK6Impl implements JDK6Interface {\n public void browseDesktop(URI uri) {\n java.awt.Desktop.getDesktop().browse(uri);\n }\n}\n---%<---\n</code></pre>\n\n<p>You could configure these as separate projects in an IDE using different JDKs, etc. The point is that the main root can be compiled independently and it is very clear what you can use in which root, whereas if you try to compile different parts of a single root separately it is too easy to accidentally "leak" usage of JDK 6 into the wrong files.</p>\n\n<p>Rather than using Class.forName like this, you can also use some kind of service registration system - java.util.ServiceLoader (if main could use JDK 6 and you wanted optional support for JDK 7!), NetBeans Lookup, Spring, etc. etc.</p>\n\n<p>The same technique can be used to create support for an optional library rather than a newer JDK.</p>\n'}, {'answer_id': 74366, 'author': 'Steve g', 'author_id': 12092, 'author_profile': 'https://Stackoverflow.com/users/12092', 'pm_score': 2, 'selected': False, 'text': '<p>You can probably refactor your code so that conditional compile really isn\'t needed, just conditional classloading. Something like this:</p>\n\n<pre><code>public interface Opener{\n\npublic void open(File f);\n\n public static class Util{\n public Opener getOpener(){\n if(System.getProperty("java.version").beginsWith("1.5")){\n return new Java5Opener();\n }\n try{ \n return new Java6Opener();\n }catch(Throwable t){\n return new Java5Opener();\n }\n }\n }\n\n}\n</code></pre>\n\n<p>This could be a lot of effort depending on how many version-specific pieces of code you have.</p>\n'}, {'answer_id': 74555, 'author': '18Rabbit', 'author_id': 12662, 'author_profile': 'https://Stackoverflow.com/users/12662', 'pm_score': 3, 'selected': True, 'text': '<p>Assuming that the classes have similar functionality with 1.5 vs. 6.0 differences in implementation you could merge them into one class. Then, without editing the source to comment/uncomment, you can rely on the optimization that the compiler always do. If an if expression is always false, the code in the if statement will not be included in the compilation.</p>\n\n<p>You can make a static variable in one of your classes to determine which version you want to run:</p>\n\n<pre><code>public static final boolean COMPILED_IN_JAVA_6 = false;\n</code></pre>\n\n<p>And then have the affected classes check that static variable and put the different sections of code in a simple if statement</p>\n\n<pre><code>if (VersionUtil.COMPILED_IN_JAVA_6) {\n // Java 6 stuff goes here\n} else {\n // Java 1.5 stuff goes here\n}\n</code></pre>\n\n<p>Then when you want to compile the other version you just have to change that one variable and recompile. It might make the java file larger but it will consolidate your code and eliminate any code duplication that you have. Your editor may complain about unreachable code or whatever but the compiler should blissfully ignore it.</p>\n'}, {'answer_id': 74603, 'author': 'Bill K', 'author_id': 12943, 'author_profile': 'https://Stackoverflow.com/users/12943', 'pm_score': 0, 'selected': False, 'text': "<p>The public static final solution mentioned above has one additional benefit the author didn't mention--as I understand it, the compiler will recognize it at compile time and compile out any code that is within an if statement that refers to that final variable.</p>\n\n<p>So I think that's the exact solution you were looking for.</p>\n"}, {'answer_id': 74617, 'author': 'Garth Gilmour', 'author_id': 2635682, 'author_profile': 'https://Stackoverflow.com/users/2635682', 'pm_score': 0, 'selected': False, 'text': "<p>A simple solution could be:</p>\n\n<ul>\n<li>Place the divergent classes outside of your normal classpath.</li>\n<li>Write a simple custom classloader and install it in main as your default.</li>\n<li>For all classes apart from the 5/6 ones the cassloader can defer to its parent (the normal system classloader)</li>\n<li>For the 5/6 ones (which should be the only ones that cannot be found by the parent) it can decide which to use via the 'os.name' property or one of your own.</li>\n</ul>\n"}, {'answer_id': 76114, 'author': 'Michael Myers', 'author_id': 13531, 'author_profile': 'https://Stackoverflow.com/users/13531', 'pm_score': 1, 'selected': False, 'text': '<p>It depends on what Java 6 features you want to use. For a simple thing like adding row sorters to JTables, you can actually test at runtime:</p>\n\n<pre><code>private static final double javaVersion =\n Double.parseDouble(System.getProperty("java.version").substring(0, 3));\nprivate static final boolean supportsRowSorter =\n (javaVersion >= 1.6);\n\n//...\n\nif (supportsRowSorter) {\n myTable.setAutoCreateRowSorter(true);\n} else {\n // not supported\n}\n</code></pre>\n\n<p>This code must be compiled with Java 6, but can be run with any version (no new classes are referenced).</p>\n\n<p>EDIT: to be more correct, it will work with any version since 1.3 (according to <a href="http://java.sun.com/j2se/versioning_naming.html" rel="nofollow noreferrer" title="J2SE SDK/JRE Version String Naming Convention">this page</a>).</p>\n'}, {'answer_id': 76276, 'author': 'Ian', 'author_id': 4396, 'author_profile': 'https://Stackoverflow.com/users/4396', 'pm_score': 3, 'selected': False, 'text': '<p>The suggestions about using custom class loaders and dynamically commented code are a bit incredulous when it comes to maintenance and the preservation of the sanity of whichever poor soul picks up the project after you shuffle to pastures new.</p>\n\n<p>The solution is easy. Pull the affected classes out into two separate, independent projects - make sure the package names are the same, and just compile into jars that you can then consume in your main project. If you keep the package names the same, and the method signatures the same, no problems - just drop whichever version of the jar you need into your deployment script. I would assume you run separate build scripts or have separate targets in the same script - ant and maven can both easily handle conditionally grabbing files and copying them.</p>\n'}, {'answer_id': 76951, 'author': 'shadit', 'author_id': 9925, 'author_profile': 'https://Stackoverflow.com/users/9925', 'pm_score': 1, 'selected': False, 'text': '<p>You can do all of your compiling exclusively on Java6 and then use System.getProperty("java.version") to conditionally run either the Java5 or the Java6 code path.</p>\n\n<p>You can have Java6-only code in a class and the class will run fine on Java5 as long as the Java6-only code path is not executed.</p>\n\n<p>This is a trick that is used to write applets that will run on the ancient MSJVM all the way up to brand-new Java Plug-in JVMs.</p>\n'}, {'answer_id': 146035, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': "<p>You can use reflection API. put all your 1.5 code in one class and 1.6 api in another. In your ant script create two targets one for 1.5 that won't compile the 1.6 class and one for 1.6 that won't compile the class for 1.5. in your code check your java version and load the appropriate class using reflection that way javac won't complain about missing functions. This is how i can compile my MRJ(Mac Runtime for Java) applications on windows.</p>\n"}] | 2008/09/16 | ['https://Stackoverflow.com/questions/74171', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12944/'] |
74,188 | <p>I've created a ListBox to display items in groups, where the groups are wrapped right to left when they can no longer fit within the height of the ListBox's panel. So, the groups would appear similar to this in the listbox, where each group's height is arbitrary (group 1, for instance, is twice as tall as group 2):</p>
<pre><code>[ 1 ][ 3 ][ 5 ]
[ ][ 4 ][ 6 ]
[ 2 ][ ]
</code></pre>
<p>The following XAML works correctly in that it performs the wrapping, and allows the horizontal scroll bar to appear when the items run off the right side of the ListBox.</p>
<pre><code><ListBox>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.GroupStyle>
<ItemsPanelTemplate>
<WrapPanel Orientation="Vertical"
Height="{Binding Path=ActualHeight,
RelativeSource={RelativeSource
FindAncestor,
AncestorLevel=1,
AncestorType={x:Type ScrollContentPresenter}}}"/>
</ItemsPanelTemplate>
</ListBox.GroupStyle>
</ListBox>
</code></pre>
<p>The problem occurs when a group of items is longer than the height of the WrapPanel. Instead of allowing the vertical scroll bar to appear to view the cutoff item group, the items in that group are simply clipped. I'm assuming that this is a side effect of the Height binding in the WrapPanel - the scrollbar thinks it does not have to enabled.</p>
<p>Is there any way to enable the scrollbar, or another way around this issue that I'm not seeing?</p>
| [{'answer_id': 74235, 'author': 'dcstraw', 'author_id': 10391, 'author_profile': 'https://Stackoverflow.com/users/10391', 'pm_score': 0, 'selected': False, 'text': '<p>I would think that you are correct that it has to do with the binding. What happens when you remove the binding? With the binding are you trying to fill up at least the entire height of the list box? If so, consider binding to MinHeight instead, or try using the <code>VerticalAlignment</code> property.</p>\n'}, {'answer_id': 74306, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>Thanks for answering, David.</p>\n\n<p>When the binding is <code>removed</code>, no wrapping occurs. The <strong>WrapPanel</strong> puts every group into a single vertical column.</p>\n\n<p>The binding is meant to force the WrapPanel to actually wrap. If no binding is set, the WrapPanel assumes the height is infinite and never wraps.</p>\n\n<p>Binding to <code>MinHeight</code> results in an empty listbox. I can see how the <code>VerticalAlignment</code> property could seem to be a solution, but alignment itself prevents any wrapping from occurring. When binding and alignment are used together, the alignment has no effect on the problem.</p>\n'}, {'answer_id': 74565, 'author': 'Abe Heidebrecht', 'author_id': 9268, 'author_profile': 'https://Stackoverflow.com/users/9268', 'pm_score': 2, 'selected': False, 'text': '<p>By setting the Height property on the WrapPanel to the height of the ScrollContentPresenter, it will never scroll vertically. However, if you remove that Binding, it will never wrap, since in the layout pass, it has infinite height to layout in. </p>\n\n<p>I would suggest creating your own panel class to get the behavior you want. Have a separate dependency property that you can bind the desired height to, so you can use that to calculate the target height in the measure and arrange steps. If any one child is taller than the desired height, use that child\'s height as the target height to calculate the wrapping.</p>\n\n<p>Here is an example panel to do this:</p>\n\n<pre><code>public class SmartWrapPanel : WrapPanel\n{\n /// <summary>\n /// Identifies the DesiredHeight dependency property\n /// </summary>\n public static readonly DependencyProperty DesiredHeightProperty = DependencyProperty.Register(\n "DesiredHeight",\n typeof(double),\n typeof(SmartWrapPanel),\n new FrameworkPropertyMetadata(Double.NaN, \n FrameworkPropertyMetadataOptions.AffectsArrange |\n FrameworkPropertyMetadataOptions.AffectsMeasure));\n\n /// <summary>\n /// Gets or sets the height to attempt to be. If any child is taller than this, will use the child\'s height.\n /// </summary>\n public double DesiredHeight\n {\n get { return (double)GetValue(DesiredHeightProperty); }\n set { SetValue(DesiredHeightProperty, value); }\n }\n\n protected override Size MeasureOverride(Size constraint)\n {\n Size ret = base.MeasureOverride(constraint);\n double h = ret.Height;\n\n if (!Double.IsNaN(DesiredHeight))\n {\n h = DesiredHeight;\n foreach (UIElement child in Children)\n {\n if (child.DesiredSize.Height > h)\n h = child.DesiredSize.Height;\n }\n }\n\n return new Size(ret.Width, h);\n }\n\n protected override System.Windows.Size ArrangeOverride(Size finalSize)\n {\n double h = finalSize.Height;\n\n if (!Double.IsNaN(DesiredHeight))\n {\n h = DesiredHeight;\n foreach (UIElement child in Children)\n {\n if (child.DesiredSize.Height > h)\n h = child.DesiredSize.Height;\n }\n }\n\n return base.ArrangeOverride(new Size(finalSize.Width, h));\n }\n}\n</code></pre>\n'}, {'answer_id': 82798, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>Here is the slightly modified code - all credit given to Abe Heidebrecht, who previously posted it - that allows both horizontal and vertical scrolling. The only change is that the return value of MeasureOverride needs to be base.MeasureOverride(new Size(ret.width, h)).</p>\n\n<pre><code>// Original code : Abe Heidebrecht\npublic class SmartWrapPanel : WrapPanel\n{\n /// <summary>\n /// Identifies the DesiredHeight dependency property\n /// </summary>\n public static readonly DependencyProperty DesiredHeightProperty = DependencyProperty.Register(\n "DesiredHeight",\n typeof(double),\n typeof(SmartWrapPanel),\n new FrameworkPropertyMetadata(Double.NaN, \n FrameworkPropertyMetadataOptions.AffectsArrange |\n FrameworkPropertyMetadataOptions.AffectsMeasure));\n\n /// <summary>\n /// Gets or sets the height to attempt to be. If any child is taller than this, will use the child\'s height.\n /// </summary>\n public double DesiredHeight\n {\n get { return (double)GetValue(DesiredHeightProperty); }\n set { SetValue(DesiredHeightProperty, value); }\n }\n\n protected override Size MeasureOverride(Size constraint)\n {\n Size ret = base.MeasureOverride(constraint);\n double h = ret.Height;\n\n if (!Double.IsNaN(DesiredHeight))\n {\n h = DesiredHeight;\n foreach (UIElement child in Children)\n {\n if (child.DesiredSize.Height > h)\n h = child.DesiredSize.Height;\n }\n }\n\n return base.MeasureOverride(new Size(ret.Width, h));\n }\n\n protected override System.Windows.Size ArrangeOverride(Size finalSize)\n {\n double h = finalSize.Height;\n\n if (!Double.IsNaN(DesiredHeight))\n {\n h = DesiredHeight;\n foreach (UIElement child in Children)\n {\n if (child.DesiredSize.Height > h)\n h = child.DesiredSize.Height;\n }\n }\n\n return base.ArrangeOverride(new Size(finalSize.Width, h));\n }\n}\n</code></pre>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/74188', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/'] |
74,190 | <p>We have a 4 server cluster running ASP.NET web application using ASP.NET State Server Service for session. On one of the 4 servers ASP.NET State Server Service is running and other servers are configured to look at this. Very often we have to patch the servers, and applying patch on the State Server requires few minutes of downtime. </p>
<p>Is there a way to configure more than two ASP.NET State Server Services in a cluster, so if one goes down, the other takes over?</p>
| [{'answer_id': 74221, 'author': 'Jon Galloway', 'author_id': 5, 'author_profile': 'https://Stackoverflow.com/users/5', 'pm_score': 1, 'selected': False, 'text': '<p>I\'d look into Session State Partitioning. Good info here:\n<a href="http://blog.maartenballiauw.be/post/2008/01/ASPNET-Session-State-Partitioning-using-State-Server-Load-Balancing.aspx" rel="nofollow noreferrer">http://blog.maartenballiauw.be/post/2008/01/ASPNET-Session-State-Partitioning-using-State-Server-Load-Balancing.aspx</a></p>\n'}, {'answer_id': 634383, 'author': 'Tormod Hystad', 'author_id': 73960, 'author_profile': 'https://Stackoverflow.com/users/73960', 'pm_score': 0, 'selected': False, 'text': '<p>A second ASP.NET State Server Service cannot take over if the first one fails <em>without</em> losing the part of session info stored on the first server. New sessions will be handled fine by the second server. To get this behaviour you need to set up session state partitioning (see <a href="https://stackoverflow.com/questions/74190/can-you-have-more-than-one-asp-net-state-server-service-in-a-cluster/74221#74221">Jon Galloway\'s answer</a>).</p>\n\n<p>This behaviour is by design; the ASP.NET state service does not do replication of the session data between servers.</p>\n\n<p>If you need out of process session data replicated to several servers you must either use one of the commercial offerings (ScaleOut, for instance) or wait for Microsoft Project Velocity to become production-ready. Personally I am eagerly awaiting the release of Velocity and will switch to it from ASP.NET state server as soon as I feel confident in the product.</p>\n\n<p><a href="http://blogs.msdn.com/velocity/archive/2008/06/05/how-to-use-session-store-provider-microsoft-project-code-named-velocity.aspx" rel="nofollow noreferrer">This link</a> has more on Velocity for session state for ASP.NET.</p>\n'}, {'answer_id': 4207866, 'author': 'Raffy Arnaez', 'author_id': 511177, 'author_profile': 'https://Stackoverflow.com/users/511177', 'pm_score': 1, 'selected': False, 'text': '<p>ASP Stateserver does not replicate session from the 1st node.</p>\n\n<p>But at least keeping your Web up and running on the next retry.</p>\n\n<p>Thought of implementing the ASP State Service on a MSCS Clustered Environment</p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/74190', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12872/'] |
74,206 | <p>I have been playing with this for a while, but the closest I have gotten is a button that opens the <code>Paste Special</code> dialog box and requires another couple of mouse clicks to paste the contents of the clipboard as unformatted text. </p>
<p>So often I am doing a <code>copy-paste</code> from a web site into a document where I don't want the additional baggage of the HTML formatting, it would be nice to be able to do this with a shortcut key or a toolbar button.</p>
| [{'answer_id': 74237, 'author': 'GSerg', 'author_id': 11683, 'author_profile': 'https://Stackoverflow.com/users/11683', 'pm_score': 4, 'selected': True, 'text': '<p>Make the button call the macro:</p>\n\n<pre><code>public sub PasteSpecialUnformatted()\n selection.pastespecial datatype:=wdpastetext\nend sub\n</code></pre>\n'}, {'answer_id': 74969, 'author': 'Mackaaij', 'author_id': 13222, 'author_profile': 'https://Stackoverflow.com/users/13222', 'pm_score': 0, 'selected': False, 'text': '<p>I use <a href="http://www.getfingertips.com/" rel="nofollow noreferrer">FingerTips</a> for this. By default it will make CTRL+W -> Paste Special. Furthermore it supports macro text and a lot of useful start-programs-quick things and some Microsoft Outlook tricks to support Getting Things Done.</p>\n'}, {'answer_id': 85696, 'author': 'Jon Schneider', 'author_id': 12484, 'author_profile': 'https://Stackoverflow.com/users/12484', 'pm_score': 2, 'selected': False, 'text': '<p>I would suggest using the <a href="http://www.stevemiller.net/puretext/" rel="nofollow noreferrer">PureText</a> lightweight utility application by Steve Miller for this.</p>\n\n<p>PureText runs in your system tray and listens on a global hotkey (which you can define -- I use Win+V) to perform a "paste text sans formatting" -- essentially the same operation as opening up an instance of notepad.exe, pasting into that, re-copying the resultant plain text, and then pasting into the actual target application.</p>\n\n<p>The advantage of this approach is that you\'ll be able to perform a "paste text sans formatting" in any of your applications, not just in Word.</p>\n\n<p>I first installed PureText a couple of years ago and have been using it heavily ever since; it has become a "must-have" utility application for me. Highly recommended.</p>\n'}, {'answer_id': 14869170, 'author': 'DaDecoder', 'author_id': 2070998, 'author_profile': 'https://Stackoverflow.com/users/2070998', 'pm_score': 0, 'selected': False, 'text': '<p>You can simply use Quick Access Panel in MS Word 2007 and later versions.</p>\n\n<p>It is very simple to add <a href="http://dadecoder.blogspot.in/2013/02/add-shortcut-buttons-in-ms-word-2007.html" rel="nofollow">Shortcut Buttons in MS Office</a></p>\n\n<p>And saves a lot of time for regular users. </p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/74206', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/30018/'] |
74,218 | <p>Is there a way to restart the Rails app (e.g. when you've changed a plugin/config file) while Mongrel is running. Or alternatively quickly restart Mongrel. Mongrel gives these hints that you can but how do you do it?</p>
<p>** Signals ready. TERM => stop. USR2 => restart. INT => stop (no restart).</p>
<p>** Rails signals registered. HUP => reload (without restart). It might not work well.</p>
| [{'answer_id': 74241, 'author': 'Jan Krüger', 'author_id': 12471, 'author_profile': 'https://Stackoverflow.com/users/12471', 'pm_score': 2, 'selected': False, 'text': '<p>For example,</p>\n\n<pre><code>killall -USR2 mongrel_rails\n</code></pre>\n'}, {'answer_id': 74998, 'author': 'TonyLa', 'author_id': 1295, 'author_profile': 'https://Stackoverflow.com/users/1295', 'pm_score': 2, 'selected': False, 'text': '<p>in your rails home directory </p>\n\n<pre><code>mongrel_rails cluster::restart\n</code></pre>\n'}, {'answer_id': 75028, 'author': 'Lucas Oman', 'author_id': 6726, 'author_profile': 'https://Stackoverflow.com/users/6726', 'pm_score': 3, 'selected': False, 'text': "<p>You can add the -c option if the config for your app's cluster is elsewhere:</p>\n\n<pre><code>mongrel_rails cluster::restart -c /path/to/config\n</code></pre>\n"}, {'answer_id': 90316, 'author': 'Mike Berrow', 'author_id': 17251, 'author_profile': 'https://Stackoverflow.com/users/17251', 'pm_score': 3, 'selected': False, 'text': '<p>1st discover the current mongrel pid path with something like:</p>\n\n<blockquote>\n <p>>ps axf | fgrep mongrel</p>\n</blockquote>\n\n<p>you will see a process line like:</p>\n\n<p><strong>ruby /usr/lib64/ruby/gems/1.8/gems/swiftiply-0.6.1.1/bin/mongrel_rails start -p 3000 -a 0.0.0.0 -e development -P /home/xxyyzz/rails/myappname/tmp/pids/mongrel.pid -d</strong></p>\n\n<p>Take the \'-P /home/xxyyzz/rails/myappname/tmp/pids/mongrel.pid\' part and use it like this:</p>\n\n<blockquote>\n <p>>mongrel_rails restart -P /home/xxyyzz/rails/myappname/tmp/pids/mongrel.pid</p>\n</blockquote>\n\n<p><strong>Sending USR2 to Mongrel at PID 18481...Done.</strong></p>\n\n<p>I use this to recover from the dreaded "Broken pipe" to MySQL problem.</p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/74218', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/6432/'] |
74,248 | <p>On a JSTL/JSP page, I have a java.util.Date object from my application. I need to find the day <em>after</em> the day specified by that object. I can use <jsp:scriptlet> to drop into Java and use java.util.Calendar to do the necessary calculations, but this feels clumsy and inelegant to me.</p>
<p>Is there some way to use JSP or JSTL tags to achieve this end without having to switch into full-on Java, or is the latter the only way to accomplish this?</p>
| [{'answer_id': 74274, 'author': 'sirprize', 'author_id': 12902, 'author_profile': 'https://Stackoverflow.com/users/12902', 'pm_score': 2, 'selected': False, 'text': '<p>While this does not answer your initial question, you could perhaps eliminate the hassle of going through java.util.Calendar by doing this:</p>\n\n<pre><code>// Date d given\nd.setTime(d.getTime()+86400000);\n</code></pre>\n'}, {'answer_id': 74582, 'author': 'jodonnell', 'author_id': 4223, 'author_profile': 'https://Stackoverflow.com/users/4223', 'pm_score': 2, 'selected': False, 'text': '<p>You have to either use a scriptlet or write your own tag. For the record, using Calendar would look like this:</p>\n\n<pre><code>Calendar cal = Calendar.getInstance();\ncal.setTime (date);\ncal.add (Calendar.DATE, 1);\ndate = cal.getTime ();\n</code></pre>\n\n<p>Truly horrible.</p>\n'}, {'answer_id': 74619, 'author': 'Mark B', 'author_id': 13070, 'author_profile': 'https://Stackoverflow.com/users/13070', 'pm_score': 1, 'selected': False, 'text': "<p>Unfortunately there is no tag in the standard JSP/JSTL libraries that I know of that would allow you to do this date calculation.</p>\n\n<p>The simplest, and most inelegant, solution is to just use some scriptlet code to do the calculation. You've already stated that you think this is a clunky solution, and I agree with you. I would probably write a custom JSP taglib to get this if I were you.</p>\n"}, {'answer_id': 74646, 'author': 'ScArcher2', 'author_id': 1310, 'author_profile': 'https://Stackoverflow.com/users/1310', 'pm_score': 4, 'selected': True, 'text': '<p>I\'m not a fan of putting java code in your jsp.</p>\n\n<p>I\'d use a static method and a taglib to accomplish this.</p>\n\n<p>Just my idea though. There are many ways to solve this problem.</p>\n\n<pre><code>public static Date addDay(Date date){\n //TODO you may want to check for a null date and handle it.\n Calendar cal = Calendar.getInstance();\n cal.setTime (date);\n cal.add (Calendar.DATE, 1);\n return cal.getTime();\n}\n</code></pre>\n\n<p>functions.tld</p>\n\n<pre><code><?xml version="1.0" encoding="UTF-8" ?>\n<taglib xmlns="http://java.sun.com/xml/ns/j2ee"\n xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\n xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"\n version="2.0">\n <description>functions library</description>\n <display-name>functions</display-name>\n <tlib-version>1.1</tlib-version>\n <short-name>xfn</short-name>\n <uri>http://yourdomain/functions.tld</uri>\n <function>\n <description>\n Adds 1 day to a date.\n </description>\n <name>addDay</name>\n <function-class>Functions</function-class>\n <function-signature>java.util.Date addDay(java.util.Date)</function-signature>\n <example>\n ${xfn:addDay(date)}\n </example>\n </function>\n</taglib>\n</code></pre>\n'}, {'answer_id': 76166, 'author': 'Mwanji Ezana', 'author_id': 7288, 'author_profile': 'https://Stackoverflow.com/users/7288', 'pm_score': 1, 'selected': False, 'text': "<p>In general, I think JSPs should not have data logic. They should get all the data they need to display from the Controller and all their logic should be about HOW the data is displayed, not WHAT is displayed. This is usually a lot simpler and a lot less code/XML than adding a custom tag.</p>\n\n<p>And if there isn't any re-use happening, is a tiny scriptlet really that much worse than the taglib XML?</p>\n"}] | 2008/09/16 | ['https://Stackoverflow.com/questions/74248', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2041950/'] |
74,261 | <p>Is there a general rule of thumb to follow when storing web application data to know what database backend should be used? Is the number of hits per day, number of rows of data, or other metrics that I should consider when choosing?</p>
<p>My initial idea is that the order for this would look something like the following (but not necessarily, which is why I'm asking the question).</p>
<ol>
<li>Flat Files</li>
<li>BDB</li>
<li>SQLite</li>
<li>MySQL</li>
<li>PostgreSQL</li>
<li>SQL Server</li>
<li>Oracle</li>
</ol>
| [{'answer_id': 74273, 'author': 'chakrit', 'author_id': 3055, 'author_profile': 'https://Stackoverflow.com/users/3055', 'pm_score': 0, 'selected': False, 'text': '<p>Your application\'s utilization of the database is the most critical ones. Mainly what queries are used most often (SELECT, INSERT or UPDATE)?</p>\n\n<p>Say if you use SQLite, it is gears for smaller application but for "web" application you might a bigger one like MySQL or SQL Server.</p>\n\n<p>The way you write scripts and your web application platforms also matters. If you\'re developing on a Microsoft platform, then SQL Server is a better alternative.</p>\n'}, {'answer_id': 74281, 'author': 'Jan Krüger', 'author_id': 12471, 'author_profile': 'https://Stackoverflow.com/users/12471', 'pm_score': 4, 'selected': True, 'text': '<p>It\'s not quite that easy. The only general rule of thumb is that you should look for another solution when the current one can\'t keep up anymore. That could include using different software (not necessarily in any globally fixed order), hardware or architecture.</p>\n\n<p>You will probably get a lot more benefit out of caching data using something like <a href="http://danga.com/memcached/" rel="nofollow noreferrer">memcached</a> than switching to another random storage backend.</p>\n'}, {'answer_id': 74291, 'author': 'Brian G', 'author_id': 3208, 'author_profile': 'https://Stackoverflow.com/users/3208', 'pm_score': -1, 'selected': False, 'text': '<p>I think your list is subjective but I will play your game.</p>\n\n<p>Flat Files </p>\n\n<p>BDB </p>\n\n<p>SQLite</p>\n\n<p>MySQL</p>\n\n<p>PostgreSQL</p>\n\n<p>SQL Server </p>\n\n<p>Oracle</p>\n\n<p>Teradata</p>\n'}, {'answer_id': 74297, 'author': 'Eric Z Beard', 'author_id': 1219, 'author_profile': 'https://Stackoverflow.com/users/1219', 'pm_score': 3, 'selected': False, 'text': '<p>If you think you are going to ever need one of the heavyweights (SqlServer, Oracle), you should start with one of those at the beginning. Data migrations are extremely difficult. In the long run it will cost you less to just start at the top and stay there.</p>\n'}, {'answer_id': 74299, 'author': 'swilliams', 'author_id': 736, 'author_profile': 'https://Stackoverflow.com/users/736', 'pm_score': 0, 'selected': False, 'text': "<p>Typically, I go with what is commonly accepted by whichever framework I am using. So, if I'm doing .NET => SQL Server, Python (via Django or Pylons) => MySQL or SQLite.</p>\n\n<p>I almost never use flat files though.</p>\n"}, {'answer_id': 74317, 'author': 'Ken Ray', 'author_id': 12253, 'author_profile': 'https://Stackoverflow.com/users/12253', 'pm_score': 0, 'selected': False, 'text': '<p>There is more to choosing an RDBMS solution that just "back end horsepower". The ability to have commitment control, for example, so you can roll back a failed transaction is one. reason.</p>\n\n<p>Unless you are in the megatransaction rate application, most database engines would be adequate - so it becomes a question of how much you want to pay for the software, whether it runs on the hardware and operating system environment you want, and what expertise you have in managing that software.</p>\n'}, {'answer_id': 74318, 'author': 'catfood', 'author_id': 12802, 'author_profile': 'https://Stackoverflow.com/users/12802', 'pm_score': 2, 'selected': False, 'text': "<p>I think you're being overly specific in your rankings. You can pretty much start with flat files and the like for very small data sets, go up to something like DBM for slightly bigger ones that don't require SQL-like syntax, and go to some kind of SQL database after that.</p>\n\n<p>But who wants to do all that rewriting? If the application will benefit from access to joins, stored procedures, triggers, foreign key validation, and the like--just use a SQL database regardless of the dataset size.</p>\n\n<p><em>Which one</em> should depend more on the client's existing installations and what DBA skills are available than on the amount of data you're holding.</p>\n\n<p>In other words, the size of your database is far from the only consideration, and maybe not the most important one.</p>\n"}, {'answer_id': 74354, 'author': 'Joel Coehoorn', 'author_id': 3043, 'author_profile': 'https://Stackoverflow.com/users/3043', 'pm_score': 0, 'selected': False, 'text': "<p>That progression sounds painful. If you're going to include MS products (especially the for-pay SQL Server) in there anywhere, you may as well use the whole stack, since you only have to pay for the last of these:</p>\n\n<pre><code>SQL Server Compact -> SQL Server Express -> SQL Server Enterprise (clustered). \n</code></pre>\n\n<p>If you target your app at SQL Server Compact initially, all your SQL code is guaranteed to scale up to the next version without modification. If you get bigger than SQL Server Enterprise, then congratulations. That's what they call a <em>good</em> problem to have.</p>\n\n<p>Also: go back and check the SO podcasts. I believe they talked about this briefly.</p>\n"}, {'answer_id': 74373, 'author': 'Sam', 'author_id': 9406, 'author_profile': 'https://Stackoverflow.com/users/9406', 'pm_score': 0, 'selected': False, 'text': "<p>This question depends on your situation really.</p>\n\n<p>If you have control over the server you're deploying to and you can install whatever services you need, then the time to install a MySql or MSSQL Express server and code against an existing database framework VERSUS coding against flat file structure is not worth the effort of considering.</p>\n"}, {'answer_id': 74406, 'author': 'Mostlyharmless', 'author_id': 12881, 'author_profile': 'https://Stackoverflow.com/users/12881', 'pm_score': 1, 'selected': False, 'text': '<p>There is no blanket answer to this, but ALMOST always, using flat files is not a good idea. You have to parse through them (i suppose) and they do not scale well. Starting with a proper database, like Oracle or SQL Server (or MySQL, Postgres if you are looking for free options) is a good idea. For very little overhead, you will save yourself a lot of effort and headache later on. They also allow you to structure your data in a non-stupid fashion, leaving you free to think of WHAT you will do with the data rather than HOW you will be getting it in/out.</p>\n'}, {'answer_id': 74474, 'author': 'willasaywhat', 'author_id': 12234, 'author_profile': 'https://Stackoverflow.com/users/12234', 'pm_score': 1, 'selected': False, 'text': "<p>It really depends on your data, and how you intend to use it. At one of my previous positions, we used Postgres due to the native geo-location and timezone extensions which existed because it allowed us to manage our data using polygonal datatypes. For us, we needed to do that, and we also wanted to use stored procedures, views and the like. </p>\n\n<p>Now, another place I worked at used MySQL simply because the data was normalized, standard row by row data. </p>\n\n<p>SQL Server, for a long time, had a 4gb database limit (see SQL Server 2000), but despite that limitation it remains a very stable platform for small to medium applications for which the old data is purged. </p>\n\n<p>Now, from working with Oracle and SQL Server 05/08, all I can tell you is that if you want the creme of the crop for stability, scalability and flexibility, then these two are your best bet. For enterprise applications, I strongly recommend them (merely because that's what we use where I work now).</p>\n\n<p>Other things to consider:</p>\n\n<ul>\n<li>Language integration (ASP.NET session storage, role management, etc.)</li>\n<li>Query types (Select, Update, Delete) [Although this is more of a schema design issue, not a DBMS issue)</li>\n<li>Data storage requirements</li>\n</ul>\n"}, {'answer_id': 74477, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>What about FireBird? Where would that fit into that list?</p>\n'}, {'answer_id': 74520, 'author': 'skamradt', 'author_id': 9217, 'author_profile': 'https://Stackoverflow.com/users/9217', 'pm_score': 0, 'selected': False, 'text': '<p>And lets not forget the requirements that the "customer" of your solution must also have in place. If your writing a commercial application for a small companies, then Oracle might not be a good choice... but if your writing a customized solution for a large enterprise which must share data among multiple campuses, and has a good sized IT department then the decision of Oracle vs Sql Server would come down to what does the customer most likely already have deployed. </p>\n\n<p>Data migration nowdays isn\'t that bad since we have those great tools from Embarcadero, so I would instead let the customer needs drive the decision.</p>\n'}, {'answer_id': 74581, 'author': 'Cruachan', 'author_id': 7315, 'author_profile': 'https://Stackoverflow.com/users/7315', 'pm_score': 0, 'selected': False, 'text': "<p>If you have the option SQL Server is a good choice from the word go, predominantly because you have access to solid procedures and functions and the database backup facilities are totally reliable. Wrapping up as much as your logic as you can inside the database itself (rather than in whatever language you are using) helps security and performance - indeed there's an good argument to be made for always using procedures for insert/update logic as these make you invulnerable to injection attacks.</p>\n\n<p>If I have the choice the only time I'd consider MySQL in preference is with a large, fairly simple, database predominantly used for read access. This isn't to decry MySQL which has improved markedly of late and I happily use if I don't have the choice, but for more complex systems with update/insert activity MSSQL is generally the superior option.</p>\n"}] | 2008/09/16 | ['https://Stackoverflow.com/questions/74261', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2581/'] |
74,266 | <p>I have an ext combobox which uses a store to suggest values to a user as they type. </p>
<p>An example of which can be found here: <a href="http://extjs.com/deploy/ext/examples/form/combos.html" rel="nofollow noreferrer">combobox example</a></p>
<p>Is there a way of making it so the <strong>suggested text list</strong> is rendered to an element in the DOM. Please note I do not mean the "applyTo" config option, as this would render the whole control, including the textbox to the DOM element.</p>
| [{'answer_id': 74680, 'author': 'noah', 'author_id': 12034, 'author_profile': 'https://Stackoverflow.com/users/12034', 'pm_score': 0, 'selected': False, 'text': '<p>So clarify, you want the selected text to render somewhere besides directly below the text input. Correct?</p>\n\n<p>ComboBox is just a composite of <a href="http://extjs.com/deploy/dev/docs/?class=Ext.DataView" rel="nofollow noreferrer">Ext.DataView</a>, a text input, and an optional trigger button. There isn\'t an official option for what you want and hacking it to make it do what you want would be really painful. So, the easiest course of action (other than finding and using some other library with a component that does exactly what you want) is to build your own with the components above:</p>\n\n<ol>\n<li>Create a text box. You can use an <a href="http://extjs.com/deploy/dev/docs/?class=Ext.form.TextField" rel="nofollow noreferrer">Ext.form.TextField</a> if you want, and observe the keyup event.</li>\n<li>Create a DataView bound to your store, rendering to whatever DOM element you want. Depending on what you want, listen to the \'selectionchange\' event and take whatever action you need to in response to the selection. e.g., setValue on an Ext.form.Hidden (or plain HTML input type="hidden" element).</li>\n<li>In your keyup event listener, call the store\'s filter method (see <a href="http://extjs.com/deploy/dev/docs/?class=Ext.data.Store" rel="nofollow noreferrer">doc</a>), passing the field name and the value from the text field. e.g., store.filter(\'name\',new RegEx(value+\'.*\'))</li>\n</ol>\n\n<p>It\'s a little more work, but it\'s a lot shorter than writing your own component from scratch or hacking the ComboBox to behave like you want.</p>\n'}, {'answer_id': 75619, 'author': 'Thevs', 'author_id': 8559, 'author_profile': 'https://Stackoverflow.com/users/8559', 'pm_score': 2, 'selected': True, 'text': "<p>You can use plugin for this, since you can call or even override private methods from within the plugin:</p>\n\n<pre><code>var suggested_text_plugin = {\n\n init: function(o) {\n\n o.onTypeAhead = function() {\n // Original code from the sources goes here:\n\n if(this.store.getCount() > 0){\n var r = this.store.getAt(0);\n var newValue = r.data[this.displayField];\n var len = newValue.length;\n var selStart = this.getRawValue().length;\n if(selStart != len){\n this.setRawValue(newValue);\n this.selectText(selStart, newValue.length);\n }\n }\n\n // Your code to display newValue in DOM\n ......myDom.getEl().update(newValue);\n };\n }\n};\n\n\n// in combobox code:\n\nvar cb = new Ext.form.ComboBox({\n ....\n plugins: suggested_text_plugin,\n ....\n});\n</code></pre>\n\n<p>I think it's even possible to create a whole chain of methods, calling original method before or after yours, but I haven't tried this yet.</p>\n\n<p>Also, please don't push me hard for using non-standard plugin definition and invocation methodics (undocumented). It's just my way of seeing things.</p>\n\n<p>EDIT:</p>\n\n<p>I think the method chain could be implemented something like that (untested):</p>\n\n<pre><code>....\no.origTypeAhead = new Function(this.onTypeAhead.toSource());\n// or just\no.origTypeAhead = this.onTypeAhead;\n....\n\no.onTypeAhead = function() {\n // Call original\n this.origTypeAhead();\n // Display value into your DOM element\n ...myDom....\n};\n</code></pre>\n"}, {'answer_id': 81766, 'author': 'Chris James', 'author_id': 3193, 'author_profile': 'https://Stackoverflow.com/users/3193', 'pm_score': 0, 'selected': False, 'text': '<p>@Thevs</p>\n\n<p>I think you were on the right track. </p>\n\n<p>What I did was override the initList method of Combobox.</p>\n\n<pre><code> Ext.override(Ext.form.ComboBox, {\n initList : function(){\n</code></pre>\n\n<p>If you look at the code you can see the bit where it renders the list of suggestions to a dataview. So just set the apply to the dom element you want:</p>\n\n<pre><code> this.view = new Ext.DataView({\n //applyTo: this.innerList,\n applyTo: "contentbox",\n</code></pre>\n'}, {'answer_id': 83721, 'author': 'Thevs', 'author_id': 8559, 'author_profile': 'https://Stackoverflow.com/users/8559', 'pm_score': 0, 'selected': False, 'text': "<p>@qui</p>\n\n<p>Ok. I thought you want an extra DOM field (in addition to existing combo field).</p>\n\n<p>But your solution would override a method in the ComboBox class, isn't it? That would lead to all your combo-boxes would render to the same DOM. Using a plugin would override only one particular instance.</p>\n"}, {'answer_id': 85687, 'author': 'noah', 'author_id': 12034, 'author_profile': 'https://Stackoverflow.com/users/12034', 'pm_score': 1, 'selected': False, 'text': "<p>@qui</p>\n\n<p>Another thing to consider is that initList is not part of the API. That method could disappear or the behavior could change significantly in future releases of Ext. If you never plan on upgrading, then you don't need to worry.</p>\n"}] | 2008/09/16 | ['https://Stackoverflow.com/questions/74266', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3193/'] |
74,267 | <p>I'm trying to script the shutdown of my VM Servers in a .bat.
if one of the vmware-cmd commands fails (as the machine is already shutdown say), I'd like it to continue instead of bombing out.</p>
<pre><code>c:
cd "c:\Program Files\VMWare\VmWare Server"
vmware-cmd C:\VMImages\TCVMDEVSQL01\TCVMDEVSQL01.vmx suspend soft -q
vmware-cmd C:\VMImages\DevEnv\DevEnv\DevEnv.vmx suspend soft -q
vmware-cmd C:\VMImages\DevEnv\TCVMDEV02\TCVMDEV02.vmx suspend soft =q
robocopy c:\vmimages\ \\tcedilacie1tb\VMShare\DevEnvironmentBackups\ /mir /z /r:0 /w:0
vmware-cmd C:\VMImages\TCVMDEVSQL01\TCVMDEVSQL01.vmx start
vmware-cmd C:\VMImages\DevEnv\DevEnv\DevEnv.vmx start
vmware-cmd C:\VMImages\DevEnv\TCVMDEV02\TCVMDEV02.vmx start
</code></pre>
| [{'answer_id': 74304, 'author': 'Jen A', 'author_id': 12979, 'author_profile': 'https://Stackoverflow.com/users/12979', 'pm_score': 2, 'selected': False, 'text': '<p>Have you tried using "start (cmd)" for each command you are executing?</p>\n'}, {'answer_id': 74314, 'author': 'Burkhard', 'author_id': 12860, 'author_profile': 'https://Stackoverflow.com/users/12860', 'pm_score': 0, 'selected': False, 'text': '<p>You could write a little Program that executes the command an returns a value (say -1 for an error). This value can then be used in your Batch-File.</p>\n'}, {'answer_id': 74321, 'author': 'chakrit', 'author_id': 3055, 'author_profile': 'https://Stackoverflow.com/users/3055', 'pm_score': 6, 'selected': True, 'text': '<p>Run it inside another command instance with <code>CMD /C</code></p>\n\n<pre><code>CMD /C vmware-cmd C:\\...\n</code></pre>\n\n<p>This should keep the original BAT files running.</p>\n'}, {'answer_id': 74376, 'author': 'bastos.sergio', 'author_id': 12772, 'author_profile': 'https://Stackoverflow.com/users/12772', 'pm_score': 0, 'selected': False, 'text': '<p>A batch file should continue executing, even if the previous command has generated an error. Perhaps, what you are seeying is the batch aborting due to some other error?</p>\n'}, {'answer_id': 74502, 'author': 'kenny', 'author_id': 3225, 'author_profile': 'https://Stackoverflow.com/users/3225', 'pm_score': 3, 'selected': False, 'text': '<p>If you are calling another batch file, you must use CALL batchfile.cmd</p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/74267', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/11538/'] |
74,269 | <p>I have a DataGrid, populated with objects in an ArrayCollection. After updating one of the objects' fields, I want the screen to update. The data source is not bindable, because I'm constructing it at runtime (and I don't understand how to make it bindable on the fly yet -- that's another question).</p>
<p>In this situation, if I call InvalidateDisplayList() on the grid nothing seems to happen. But if I call invalidateList(), the updates happen. (And it's very smooth too -- no flicker like I would expect from invalidating a window in WIN32.)</p>
<p>So the question: what is the difference between InvalidateList and InvalidateDisplayList? From the documentation it seems like either one should work.</p>
| [{'answer_id': 74481, 'author': 'beingdevious', 'author_id': 12550, 'author_profile': 'https://Stackoverflow.com/users/12550', 'pm_score': 0, 'selected': False, 'text': '<p>invalidateDisplayList() merely sets a flag so that updateDisplayList() can be called later during a screen update. invalidateList() is what you want. </p>\n\n<p><a href="http://livedocs.adobe.com/flex/2/langref/mx/core/UIComponent.html#invalidateDisplayList()" rel="nofollow noreferrer">http://livedocs.adobe.com/flex/2/langref/mx/core/UIComponent.html#invalidateDisplayList()</a></p>\n'}, {'answer_id': 74504, 'author': 'mikechambers', 'author_id': 10232, 'author_profile': 'https://Stackoverflow.com/users/10232', 'pm_score': 5, 'selected': True, 'text': '<p>invalidateList tells the component that the data has changed, and it needs to reload it and re-render it.</p>\n\n<p>invalidateDisplayList tells the component that it needs to redraw itself (but not necessarily reload its data).</p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/74269', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4540/'] |
74,315 | <p>I'm doing a website for a family member's wedding. A feature they requested was a photo section where all the guests could go after the wedding and upload their snaps. I said this was a stellar idea and I went off to build it.</p>
<p>Well there's just the one problem: logistics. Upload speeds are slow and photos from modern cameras are huge (2-5+Megs). </p>
<p>I will only need ~800px wide images and some of them might require rotating so ideally I'm looking about using a client-side editor to do three things:</p>
<ol>
<li>Let users pick multiple files</li>
<li>Let them rotate some images so they're the right way up</li>
<li>Resize them and then upload</li>
</ol>
<p>And in my dream world, it'd be free and open source. Any ideas?</p>
<p>Just a reminder: this is something the guests have to use. Some of them will be pretty computer savvy but others will be almost completely illiterate. Installing desktop apps isn't really an option. And I assume 98% of them have Flash and Java installed.</p>
<p>Edit: I'd prefer a Flash/Java option over SilverLight, not least because it has a smaller install rate at the moment, but also because I'm on Linux and I'd like to test it =)</p>
| [{'answer_id': 74330, 'author': 'swilliams', 'author_id': 736, 'author_profile': 'https://Stackoverflow.com/users/736', 'pm_score': 1, 'selected': False, 'text': '<p><a href="http://picasa.google.com/" rel="nofollow noreferrer">Picasa</a> is a pretty great/free photo management app. It let\'s you do some pretty impressive editing, and has upload capabilities, though I can\'t remember if it will upload to anywhere, or just certain popular sites (like Flickr).</p>\n'}, {'answer_id': 74337, 'author': 'justin.m.chase', 'author_id': 12958, 'author_profile': 'https://Stackoverflow.com/users/12958', 'pm_score': 1, 'selected': False, 'text': "<p>You could use Silverlight or Flash or some custom plugin to allow managed uploads, where you can display a progress bar for example. There isn't much you can do about upload speeds but you can at least show them progress while it's going on.</p>\n\n<p>I don't know of any canned upload programs you can use but it shouldn't be too hard to make one (unless you don't know Flash or Silverlight).</p>\n"}, {'answer_id': 74365, 'author': 'jeffrey', 'author_id': 12814, 'author_profile': 'https://Stackoverflow.com/users/12814', 'pm_score': -1, 'selected': False, 'text': '<p>GIMP (<a href="http://www.gimp.org/" rel="nofollow noreferrer">http://www.gimp.org/</a>) is a good tool for doing resize and is open source.</p>\n'}, {'answer_id': 74371, 'author': 'Kyle Renfro', 'author_id': 8187, 'author_profile': 'https://Stackoverflow.com/users/8187', 'pm_score': 2, 'selected': False, 'text': '<p>I have had good luck with <a href="http://gallery.menalto.com/" rel="nofollow noreferrer">Gallery</a>. It is free, open source, and has all the features you mentioned.</p>\n\n<p>It will allow your users to upload photos without any intervention from you.</p>\n'}, {'answer_id': 74379, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>How about using <a href="https://www.photoshop.com/express/landing.html" rel="nofollow noreferrer">PhotoShop Online</a> It allows you to edit photos with a web based editor and offers 2GB of storage. I\'ve not used it myself so don\'t know if it allows for multiple users to access the same account though</p>\n'}, {'answer_id': 74389, 'author': 'Grank', 'author_id': 12975, 'author_profile': 'https://Stackoverflow.com/users/12975', 'pm_score': 1, 'selected': False, 'text': '<p>Out of curiosity, on what web stack is this to run? LAMP? 2k3+IIS? etc etc? Many of the open source solutions out there are cross-platform but others are not...</p>\n'}, {'answer_id': 74390, 'author': 'zigdon', 'author_id': 4913, 'author_profile': 'https://Stackoverflow.com/users/4913', 'pm_score': 2, 'selected': False, 'text': "<p>Another option could be to allow people to upload their photos to whatever service they're used to using (flickr, google, smugmug, or any other), and just accept a username for that service, or a URL for the folder. </p>\n\n<p>Then you can have your application grab a copy of those pictures to store locally with a consistent interface.</p>\n"}, {'answer_id': 74416, 'author': 'chakrit', 'author_id': 3055, 'author_profile': 'https://Stackoverflow.com/users/3055', 'pm_score': 1, 'selected': False, 'text': '<p>Is <strong>E-mailing the photo in</strong> an available option?</p>\n\n<p>Most people who want to share photos probably already know how to send photos in email. And most email clients has already solved the problems of file uploading.</p>\n\n<p>Just setup one gmail/whatevermail account and have your website poll the inbox.</p>\n\n<p>It\'s something like what <a href="http://twitpic.com/" rel="nofollow noreferrer">TwitPic</a> does for twitter but your requirements seem to be more simpler than that.</p>\n'}, {'answer_id': 74425, 'author': 'mikechambers', 'author_id': 10232, 'author_profile': 'https://Stackoverflow.com/users/10232', 'pm_score': 2, 'selected': False, 'text': '<p>If you are doing this with Flash and using Flickr, then I would check out the AS3 Flickr library:</p>\n\n<p><a href="http://code.google.com/p/as3flickrlib/" rel="nofollow noreferrer">http://code.google.com/p/as3flickrlib/</a></p>\n\n<p>which has support for uploading images.</p>\n\n<p>Upload requires authentication. The library also contains a Flex based control for handling this:</p>\n\n<p><a href="http://www.mikechambers.com/blog/2008/08/12/flex-based-flickr-api-authorization-control/" rel="nofollow noreferrer">http://www.mikechambers.com/blog/2008/08/12/flex-based-flickr-api-authorization-control/</a></p>\n\n<p>(the rest of the library is ActionScript 3 and can be used in Flex or Flash.</p>\n\n<p>Probably the easiest solution is to just have the images uploaded to Flickr, edited in Picnik (built into Flickr now), and then loaded onto the users site using either the Flickr RSS feeds or APIs:</p>\n\n<p><a href="http://www.flickr.com/help/picnik/" rel="nofollow noreferrer">http://www.flickr.com/help/picnik/</a></p>\n\n<p><a href="http://www.flickr.com/services/api/" rel="nofollow noreferrer">http://www.flickr.com/services/api/</a></p>\n\n<p>hope that helps...</p>\n\n<p>mike chambers</p>\n\n<p>[email protected]</p>\n'}, {'answer_id': 74463, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>Personally most users don\'t understand DPI and their images even trimmed down end up larger than the php.ini for most hosting companies allow.</p>\n\n<p>I\'m not sure how much control you want to give them or how you want the public side to behave.</p>\n\n<p>I\'d suggest using a dropbox FTP application such as <a href="http://etonica.com/dropbox/index.html" rel="nofollow noreferrer">http://etonica.com/dropbox/index.html</a> (tango dropbox) It\'s free to your clients and you only have to pay for your version so you can set up the FTP information and secure it.</p>\n\n<p>I\'d have them download something link paint.net (which is FREE) have them edit the photos to the proper size and then just drag and drop them to this application. it\'s easy and doesn\'t require php.ini to be modified.</p>\n\n<p>You could also use something like slideshowpro\'s director application.</p>\n'}, {'answer_id': 74572, 'author': 'Changos', 'author_id': 12808, 'author_profile': 'https://Stackoverflow.com/users/12808', 'pm_score': 1, 'selected': False, 'text': '<p>I completly agree with zigdon, allow different sites, but only pick up photos from the web. I you still want to allow uploads, and put a cap on size.</p>\n\n<p>Now, if you want to throw yourself into something big, I would suggest putting a cap on size, and then using JQuery (or other library) to work with the images.</p>\n\n<p>Just my 2 cents</p>\n'}, {'answer_id': 74595, 'author': 'Changos', 'author_id': 12808, 'author_profile': 'https://Stackoverflow.com/users/12808', 'pm_score': 1, 'selected': False, 'text': '<p>You could also have them email the pictures to picasa. Picasa web has a feature where you can send images to a "secret" email that will post them to a picasa account. Set up a picasa account, distribute the "secret" email, and wait for all the pictures to show up.</p>\n'}, {'answer_id': 74729, 'author': 'ScArcher2', 'author_id': 1310, 'author_profile': 'https://Stackoverflow.com/users/1310', 'pm_score': 2, 'selected': False, 'text': '<p>I\'d use an applet. You could do the resizing of the pictures and rotating on the client side.</p>\n\n<p>It looks like <a href="http://sourceforge.net/projects/jupload/" rel="nofollow noreferrer">JUpload</a> may do this for you.</p>\n'}, {'answer_id': 74747, 'author': 'Sleep Deprivation Ninja', 'author_id': 13002, 'author_profile': 'https://Stackoverflow.com/users/13002', 'pm_score': 2, 'selected': False, 'text': '<p>I\'ve used swfupload quite a bit. It\'s pretty awesome: <a href="http://www.swfupload.org/" rel="nofollow noreferrer">http://www.swfupload.org/</a></p>\n'}, {'answer_id': 78595, 'author': 'Gaurav', 'author_id': 13492, 'author_profile': 'https://Stackoverflow.com/users/13492', 'pm_score': 1, 'selected': False, 'text': '<p>Going the Flickr route is easy and will work well.</p>\n\n<p>If you want to go more advanced, I\'d recommend <a href="http://snipshot.com/services/" rel="nofollow noreferrer">snipshot</a> or <a href="http://www.picnik.com/info/api" rel="nofollow noreferrer">picknik</a> (Flickr uses it). Both are free to use and have APIs to use.</p>\n'}, {'answer_id': 80200, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>Depends on the web server. If you can use servlets, try this :</p>\n\n<pre><code>// UploadServlet.java : Proof of Concept - Mike Smith March 2006\n// Accept a file from the client, assume it is an image, rescale it and save it to disk for later display\nimport javax.servlet.http.*;\nimport javax.imageio.*;\nimport java.io.*;\nimport java.util.*;\nimport java.sql.*;\nimport org.apache.commons.fileupload.*;\nimport org.apache.commons.fileupload.disk.*;\nimport org.apache.commons.fileupload.servlet.*;\nimport java.awt.image.*;\nimport java.awt.*;\n\npublic class UploadServlet extends HttpServlet {\n\npublic static void printHeader(PrintWriter pw) {\n pw.println("<HEAD><TITLE>Upload Servlet</TITLE><HEAD>");\n pw.println("<BODY>");\n}\n\npublic static void printTrailer(PrintWriter pw) {\n pw.println("<img src=\\"../images/poweredby.png\\" align=left>");\n pw.println("<img src=\\"../images/tomcat-power.gif\\" align=right>");\n pw.println("</BODY></HTML>");\n}\n\n\npublic void init() { // Servlet init() : called when the servlet is LOADED (not when invoked)\n}\n\npublic void service(HttpServletRequest req, HttpServletResponse res) throws IOException {\n DiskFileItemFactory dfifact;\n ServletFileUpload sfu; \n java.util.List items;\n Iterator it;\n FileItem fi;\n String field, filename, contype;\n boolean inmem, ismulti;\n long sz;\n BufferedImage img;\n int width, height, nwidth, nheight, pixels;\n double scaling;\n final int MAXPIXELS = 350 * 350;\n\n res.setContentType("text/html");\n PrintWriter pw = res.getWriter();\n printHeader(pw);\n\n ismulti = FileUpload.isMultipartContent(req);\n if (ismulti) {\n pw.println("Great! Multipart detected");\n dfifact = new DiskFileItemFactory(999999, new File("/tmp"));\n sfu = new ServletFileUpload(dfifact);\n try {\n items = sfu.parseRequest(req);\n } catch (FileUploadException e) {\n pw.println("Failed to parse file, error [" + e + "]");\n printTrailer(pw);\n pw.close();\n return;\n }\n it = items.iterator();\n while (it.hasNext()) {\n fi = (FileItem) it.next();\n if (fi.isFormField()) {\n pw.println("Form field [" + fi.getFieldName() + "] value [" + fi.getString() + "]");\n }\n else { // Its an upload\n field = fi.getFieldName();\n filename = fi.getName();\n contype = fi.getContentType();\n inmem = fi.isInMemory();\n sz = fi.getSize();\n pw.println("Upload field=" + field + " file=" + filename + " content=" + contype + " inmem=" + inmem\n + " size=" + sz);\n InputStream istream = fi.getInputStream();\n img = ImageIO.read(istream);\n nwidth = width = img.getWidth();\n nheight = height = img.getHeight();\n pixels = width * height;\n if (pixels > MAXPIXELS) {\n scaling = Math.sqrt((double) MAXPIXELS / (double) pixels);\n nheight = (int) ((double) height * scaling);\n nwidth = (int) ((double) width * scaling);\n }\n BufferedImage output = new BufferedImage(nwidth, nheight, BufferedImage.TYPE_3BYTE_BGR);\n Graphics2D g = output.createGraphics();\n g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);\n g.drawImage(img, 0, 0, nwidth, nheight, null);\n ImageIO.write(output, "jpeg", new File("/var/tomcat/webapps/pioneer/demo.jpg"));\n istream.close(); \n }\n }\n }\n else\n pw.println("Bugger! Multipart not detected");\n printTrailer(pw);\n pw.close();\n}\n\npublic void destroy() {\n}\n}\n</code></pre>\n'}, {'answer_id': 130742, 'author': 'c.sokun', 'author_id': 15396, 'author_profile': 'https://Stackoverflow.com/users/15396', 'pm_score': 1, 'selected': False, 'text': '<p>I am currently required to implement the similar requirement as Oli.</p>\n\n<p>I believe Facebook.com use java applet of some sort, and it work pretty well but I am not sure if the applet available as OSS. I am going to look into JUpload suggested by ScArcher2.</p>\n\n<p>If you guy no of any other good applet please keep it coming.</p>\n'}, {'answer_id': 144686, 'author': 'Mauricio Scheffer', 'author_id': 21239, 'author_profile': 'https://Stackoverflow.com/users/21239', 'pm_score': 3, 'selected': True, 'text': '<p>The most common solution for this is a java applet, although most of them are not free. Examples:</p>\n\n<ul>\n<li><a href="http://www.jumploader.com/" rel="nofollow noreferrer">http://www.jumploader.com/</a></li>\n<li><a href="http://www.aurigma.com/Products/ImageUploader/OnlineDemo.aspx" rel="nofollow noreferrer">http://www.aurigma.com/Products/ImageUploader/OnlineDemo.aspx</a></li>\n<li><a href="http://www.javaatwork.com/java-upload-applet/details.html" rel="nofollow noreferrer">http://www.javaatwork.com/java-upload-applet/details.html</a></li>\n<li>JUpload, mentioned by ScArcher2</li>\n</ul>\n'}, {'answer_id': 144708, 'author': 'Karan', 'author_id': 11110, 'author_profile': 'https://Stackoverflow.com/users/11110', 'pm_score': 1, 'selected': False, 'text': '<p>I\'d <strong>highly</strong> suggest using <a href="http://thefilebrowser.com/" rel="nofollow noreferrer">FileBrowser</a> by Lussomo. It\'s as easy as \'drag and drop\' :D</p>\n\n<p>I\'ve used it for my game development team where we had a raw dump of over 200 concept art images, and we simply extracted FileBrowser to a PHP-enabled webserver and dumped the images in appropriate directories (1 per album), and ran the thumbnailing script. It handles cropping of the images, and optimizing their size for you. So much better than using something like Menalto Gallery where you have to upload them through an awkward upload interface.</p>\n'}, {'answer_id': 499604, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>Try this out\n<a href="http://www.lunarvis.com/products/tinymcefilebrowserwithupload.php" rel="nofollow noreferrer">http://www.lunarvis.com/products/tinymcefilebrowserwithupload.php</a></p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/74315', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12870/'] |
74,326 | <p>I am working on a large C++ project in Visual Studio 2008, and there are a lot of files with unnecessary <code>#include</code> directives. Sometimes the <code>#include</code>s are just artifacts and everything will compile fine with them removed, and in other cases classes could be forward declared and the #include could be moved to the <code>.cpp</code> file. Are there any good tools for detecting both of these cases?</p>
| [{'answer_id': 74491, 'author': 'Eclipse', 'author_id': 8701, 'author_profile': 'https://Stackoverflow.com/users/8701', 'pm_score': 7, 'selected': True, 'text': "<p>While it won't reveal unneeded include files, Visual studio has a setting <code>/showIncludes</code> (right click on a <code>.cpp</code> file, <code>Properties->C/C++->Advanced</code>) that will output a tree of all included files at compile time. This can help in identifying files that shouldn't need to be included.</p>\n\n<p>You can also take a look at the pimpl idiom to let you get away with fewer header file dependencies to make it easier to see the cruft that you can remove.</p>\n"}, {'answer_id': 74539, 'author': 'Max Lybbert', 'author_id': 10593, 'author_profile': 'https://Stackoverflow.com/users/10593', 'pm_score': 3, 'selected': False, 'text': '<p>Like Timmermans, I\'m not familiar with any tools for this. But I have known programmers who wrote a Perl (or Python) script to try commenting out each include line one at a time and then compile each file.</p>\n\n<hr>\n\n<p>It appears that now Eric Raymond <a href="http://catb.org/~esr/deheader/" rel="nofollow noreferrer">has a tool for this</a>.</p>\n\n<p>Google\'s <a href="http://google-styleguide.googlecode.com/svn/trunk/cpplint/cpplint.py" rel="nofollow noreferrer">cpplint.py</a> has an "include what you use" rule (among many others), but as far as I can tell, no "include <strong>only</strong> what you use." Even so, it can be useful.</p>\n'}, {'answer_id': 74547, 'author': 'Graeme Perrow', 'author_id': 1821, 'author_profile': 'https://Stackoverflow.com/users/1821', 'pm_score': 4, 'selected': False, 'text': '<p>I don\'t know of any such tools, and I have thought about writing one in the past, but it turns out that this is a difficult problem to solve.</p>\n\n<p>Say your source file includes a.h and b.h; a.h contains <code>#define USE_FEATURE_X</code> and b.h uses <code>#ifdef USE_FEATURE_X</code>. If <code>#include "a.h"</code> is commented out, your file may still compile, but may not do what you expect. Detecting this <em>programatically</em> is non-trivial.</p>\n\n<p>Whatever tool does this would need to know your build environment as well. If a.h looks like:</p>\n\n<pre><code>#if defined( WINNT )\n #define USE_FEATURE_X\n#endif\n</code></pre>\n\n<p>Then <code>USE_FEATURE_X</code> is only defined if <code>WINNT</code> is defined, so the tool would need to know what directives are generated by the compiler itself as well as which ones are specified in the compile command rather than in a header file.</p>\n'}, {'answer_id': 74859, 'author': 'Joe', 'author_id': 12567, 'author_profile': 'https://Stackoverflow.com/users/12567', 'pm_score': 5, 'selected': False, 'text': '<p><a href="http://www.gimpel.com/html/pcl.htm" rel="noreferrer" title="PC Lint">PC Lint</a> works quite well for this, and it finds all sorts of other goofy problems for you too. It has command line options that can be used to create External Tools in Visual Studio, but I\'ve found that the <a href="http://www.riverblade.co.uk/products/visual_lint/index.html" rel="noreferrer" title="Visual Lint">Visual Lint</a> addin is easier to work with. Even the free version of Visual Lint helps. But give PC-Lint a shot. Configuring it so it doesn\'t give you too many warnings takes a bit of time, but you\'ll be amazed at what it turns up. </p>\n'}, {'answer_id': 79991, 'author': 'Roger Nelson', 'author_id': 14964, 'author_profile': 'https://Stackoverflow.com/users/14964', 'pm_score': 2, 'selected': False, 'text': '<p>Adding one or both of the following #defines \nwill exclude often unnecessary header files and \nmay substantially improve\ncompile times especially if the code that is not using Windows API functions.</p>\n\n<pre><code>#define WIN32_LEAN_AND_MEAN\n#define VC_EXTRALEAN\n</code></pre>\n\n<p>See <a href="http://support.microsoft.com/kb/166474" rel="nofollow noreferrer">http://support.microsoft.com/kb/166474</a></p>\n'}, {'answer_id': 80423, 'author': 'bk1e', 'author_id': 8090, 'author_profile': 'https://Stackoverflow.com/users/8090', 'pm_score': 2, 'selected': False, 'text': '<p>If you are looking to remove unnecessary <code>#include</code> files in order to decrease build times, your time and money might be better spent parallelizing your build process using <a href="http://msdn.microsoft.com/en-us/library/bb385193.aspx" rel="nofollow noreferrer">cl.exe /MP</a>, <a href="http://www.gnu.org/software/make/manual/make.html#Parallel" rel="nofollow noreferrer">make -j</a>, <a href="http://www.xoreax.com/solutions_vs.htm" rel="nofollow noreferrer">Xoreax IncrediBuild</a>, distcc/<a href="http://en.opensuse.org/Icecream" rel="nofollow noreferrer">icecream</a>, etc.</p>\n\n<p>Of course, if you already have a parallel build process and you\'re still trying to speed it up, then by all means clean up your <code>#include</code> directives and remove those unnecessary dependencies.</p>\n'}, {'answer_id': 81402, 'author': 'MSalters', 'author_id': 15416, 'author_profile': 'https://Stackoverflow.com/users/15416', 'pm_score': 0, 'selected': False, 'text': "<p>Some of the existing answers state that it's hard. That's indeed true, because you need a full compiler to detect the cases in which a forward declaration would be appropriate. You cant parse C++ without knowing what the symbols mean; the grammar is simply too ambiguous for that. You must know whether a certain name names a class (could be forward-declared) or a variable (can't). Also, you need to be namespace-aware.</p>\n"}, {'answer_id': 82033, 'author': 'Richard Corden', 'author_id': 11698, 'author_profile': 'https://Stackoverflow.com/users/11698', 'pm_score': 5, 'selected': False, 'text': '<p>!!DISCLAIMER!! I work on a commercial static analysis tool (not PC Lint). !!DISCLAIMER!!</p>\n\n<p>There are several issues with a simple non parsing approach:</p>\n\n<p>1) Overload Sets:</p>\n\n<p>It\'s possible that an overloaded function has declarations that come from different files. It might be that removing one header file results in a different overload being chosen rather than a compile error! The result will be a silent change in semantics that may be very difficult to track down afterwards.</p>\n\n<p>2) Template specializations:</p>\n\n<p>Similar to the overload example, if you have partial or explicit specializations for a template you want them all to be visible when the template is used. It might be that specializations for the primary template are in different header files. Removing the header with the specialization will not cause a compile error, but may result in undefined behaviour if that specialization would have been selected. (See: <a href="https://stackoverflow.com/questions/59331/visibility-of-template-specialization-of-c-function">Visibility of template specialization of C++ function</a>)</p>\n\n<p>As pointed out by \'msalters\', performing a full analysis of the code also allows for analysis of class usage. By checking how a class is used though a specific path of files, it is possible that the definition of the class (and therefore all of its dependnecies) can be removed completely or at least moved to a level closer to the main source in the include tree.</p>\n'}, {'answer_id': 82080, 'author': 'anon6439', 'author_id': 15477, 'author_profile': 'https://Stackoverflow.com/users/15477', 'pm_score': 1, 'selected': False, 'text': '<p>If you aren\'t already, using a precompiled header to include everything that you\'re not going to change (platform headers, external SDK headers, or static already completed pieces of your project) will make a huge difference in build times.</p>\n\n<p><a href="http://msdn.microsoft.com/en-us/library/szfdksca(VS.71).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/szfdksca(VS.71).aspx</a></p>\n\n<p>Also, although it may be too late for your project, organizing your project into sections and not lumping all local headers to one big main header is a good practice, although it takes a little extra work.</p>\n'}, {'answer_id': 85296, 'author': 'selwyn', 'author_id': 16314, 'author_profile': 'https://Stackoverflow.com/users/16314', 'pm_score': 2, 'selected': False, 'text': '<p>Start with each include file, and ensure that each include file only includes what is necessary to compile itself. Any include files that are then missing for the C++ files, can be added to the C++ files themselves.</p>\n\n<p>For each include and source file, comment out each include file one at a time and see if it compiles.</p>\n\n<p>It is also a good idea to sort the include files alphabetically, and where this is not possible, add a comment.</p>\n'}, {'answer_id': 109890, 'author': 'Sam', 'author_id': 19791, 'author_profile': 'https://Stackoverflow.com/users/19791', 'pm_score': 2, 'selected': False, 'text': '<p>If your header files generally start with</p>\n\n<pre><code>#ifndef __SOMEHEADER_H__\n#define __SOMEHEADER_H__\n// header contents\n#endif\n</code></pre>\n\n<p>(as opposed to using #pragma once) you could change that to:</p>\n\n<pre><code>#ifndef __SOMEHEADER_H__\n#define __SOMEHEADER_H__\n// header contents\n#else \n#pragma message("Someheader.h superfluously included")\n#endif\n</code></pre>\n\n<p>And since the compiler outputs the name of the cpp file being compiled, that would let you know at least which cpp file is causing the header to be brought in multiple times.</p>\n'}, {'answer_id': 144427, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>PC-Lint can indeed do this. One easy way to do this is to configure it to detect just unused include files and ignore all other issues. This is pretty straightforward - to enable just message 766 ("Header file not used in module"), just include the options -w0 +e766 on the command line.</p>\n\n<p>The same approach can also be used with related messages such as 964 ("Header file not directly used in module") and 966 ("Indirectly included header file not used in module").</p>\n\n<p>FWIW I wrote about this in more detail in a blog post last week at <a href="http://www.riverblade.co.uk/blog.php?archive=2008_09_01_archive.xml#3575027665614976318" rel="nofollow noreferrer">http://www.riverblade.co.uk/blog.php?archive=2008_09_01_archive.xml#3575027665614976318</a>.</p>\n'}, {'answer_id': 273669, 'author': 'Adrian', 'author_id': 23624, 'author_profile': 'https://Stackoverflow.com/users/23624', 'pm_score': 2, 'selected': False, 'text': '<p>If you\'re interested in this topic in general, you might want to check out Lakos\' <a href="https://rads.stackoverflow.com/amzn/click/com/0201633620" rel="noreferrer" rel="nofollow noreferrer" title="Large-Scale C++ Software Design">Large Scale C++ Software Design</a>. It\'s a bit dated, but goes into lots of "physical design" issues like finding the absolute minimum of headers that need to be included. I haven\'t really seen this sort of thing discussed anywhere else.</p>\n'}, {'answer_id': 1047706, 'author': 'Alex', 'author_id': 129233, 'author_profile': 'https://Stackoverflow.com/users/129233', 'pm_score': 2, 'selected': False, 'text': '<p>Give <a href="http://www.profactor.co.uk/includemanager.php" rel="nofollow noreferrer">Include Manager</a> a try. It integrates easily in Visual Studio and visualizes your include paths which helps you to find unnecessary stuff.\nInternally it uses Graphviz but there are many more cool features. And although it is a commercial product it has a very low price.</p>\n'}, {'answer_id': 2543781, 'author': 'Vladimir', 'author_id': 304903, 'author_profile': 'https://Stackoverflow.com/users/304903', 'pm_score': 2, 'selected': False, 'text': '<p>You can build an include graph using <a href="http://www.mobile-mir.com/cpp/" rel="nofollow noreferrer">C/C++ Include File Dependencies Watcher</a>, and find unneeded includes visually.</p>\n'}, {'answer_id': 3150373, 'author': 'rubenvb', 'author_id': 256138, 'author_profile': 'https://Stackoverflow.com/users/256138', 'pm_score': 0, 'selected': False, 'text': '<p>Maybe a little late, but I once found a WebKit perl script that did just what you wanted. It\'ll need some adapting I believe (I\'m not well versed in perl), but it should do the trick:</p>\n\n<p><a href="http://trac.webkit.org/browser/branches/old/safari-3-2-branch/WebKitTools/Scripts/find-extra-includes" rel="nofollow noreferrer">http://trac.webkit.org/browser/branches/old/safari-3-2-branch/WebKitTools/Scripts/find-extra-includes</a></p>\n\n<p>(this is an old branch because trunk doesn\'t have the file anymore)</p>\n'}, {'answer_id': 5109452, 'author': 'Josh Kelley', 'author_id': 25507, 'author_profile': 'https://Stackoverflow.com/users/25507', 'pm_score': 5, 'selected': False, 'text': '<p>There\'s a new Clang-based tool, <a href="https://github.com/include-what-you-use/include-what-you-use" rel="noreferrer">include-what-you-use</a>, that aims to do this.</p>\n'}, {'answer_id': 6201332, 'author': 'PeterSom', 'author_id': 779373, 'author_profile': 'https://Stackoverflow.com/users/779373', 'pm_score': 1, 'selected': False, 'text': '<p>If you would work with Eclipse CDT you could try out <a href="http://includator.com" rel="nofollow">http://includator.com</a> to optimize your include structure. However, Includator might not know enough about VC++\'s predefined includes and setting up CDT to use VC++ with correct includes is not built into CDT yet.</p>\n'}, {'answer_id': 26853966, 'author': 'Britton Kerin', 'author_id': 3973301, 'author_profile': 'https://Stackoverflow.com/users/3973301', 'pm_score': 0, 'selected': False, 'text': "<p>If there's a particular header that you think isn't needed anymore (say\nstring.h), you can comment out that include then put this below all the\nincludes:</p>\n\n<pre><code>#ifdef _STRING_H_\n# error string.h is included indirectly\n#endif\n</code></pre>\n\n<p>Of course your interface headers might use a different #define convention\nto record their inclusion in CPP memory. Or no convention, in which case\nthis approach won't work.</p>\n\n<p>Then rebuild. There are three possibilities:</p>\n\n<ul>\n<li><p>It builds ok. string.h wasn't compile-critical, and the include for it\ncan be removed.</p></li>\n<li><p>The #error trips. string.g was included indirectly somehow\nYou still don't know if string.h is required. If it is required, you\nshould directly #include it (see below).</p></li>\n<li><p>You get some other compilation error. string.h was needed and isn't being\nincluded indirectly, so the include was correct to begin with.</p></li>\n</ul>\n\n<p>Note that depending on indirect inclusion when your .h or .c directly uses\nanother .h is almost certainly a bug: you are in effect promising that your\ncode will only require that header as long as some other header you're using\nrequires it, which probably isn't what you meant.</p>\n\n<p>The caveats mentioned in other answers about headers that modify behavior\nrather that declaring things which cause build failures apply here as well.</p>\n"}, {'answer_id': 29883562, 'author': 'Jean-Michaël Celerier', 'author_id': 1495627, 'author_profile': 'https://Stackoverflow.com/users/1495627', 'pm_score': 1, 'selected': False, 'text': '<p>The latest Jetbrains IDE, CLion, automatically shows (in gray) the includes that are not used in the current file.</p>\n\n<p>It is also possible to have the list of all the unused includes (and also functions, methods, etc...) from the IDE.</p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/74326', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13013/'] |
74,350 | <p>I'm trying to implement some drag and drop functionality for a material system being developed at my work. Part of this system includes a 'Material Library' which acts as a repository, divided into groups, of saved materials on the user's hard drive.</p>
<p>As part of some UI polish, I was hoping to implement a 'highlight' type feature. When dragging and dropping, windows that you can legally drop a material onto will very subtly change color to improve feedback to the user that this is a valid action.</p>
<p>I am changing the bar with 'Basic Materials' (Just a CWnd with a CStatic) from having a medium gray background when unhighlighed to a blue background when hovered over. It all works well, the OnDragEnter and OnDragExit messages seem robust and set a flag indicating the highlight status. Then in OnCtrlColor I do this:</p>
<pre><code> if (!m_bHighlighted) {
pDC->FillSolidRect(0, 0, m_SizeX, kGroupHeaderHeight, kBackgroundColour);
}
else {
pDC->FillSolidRect(0, 0, m_SizeX, kGroupHeaderHeight, kHighlightedBackgroundColour);
}
</code></pre>
<p>However, as you can see in the screenshot, the painting 'glitches' below the dragged object, leaving the original gray in place. It looks really ugly and basically spoils the whole effect.</p>
<p>Is there any way I can get around this?</p>
| [{'answer_id': 74501, 'author': 'Andy', 'author_id': 3857, 'author_profile': 'https://Stackoverflow.com/users/3857', 'pm_score': 0, 'selected': False, 'text': "<p>It almost looks like the CStatic doesn't know that it needs to repaint itself, so the background color of the draggable object is left behind. Maybe try to invalidate the CStatic, and see if that helps at all?</p>\n"}, {'answer_id': 77701, 'author': 'Aidan Ryan', 'author_id': 1042, 'author_profile': 'https://Stackoverflow.com/users/1042', 'pm_score': 1, 'selected': False, 'text': '<p>Remote debugging is a godsend for debugging visual issues. It\'s a pain to set up, but having a VM ready for remote debugging will pay off for sure.</p>\n\n<p>What I like to do is set a ton of breakpoints in my paint handling, as well as in the framework paint code itself. This allows you to effectively "freeze frame" the painting without borking it up by flipping into devenv. This way you can get the true picture of who\'s painting in what order, and where you\'ve got the chance to break in a fill that rect the way you need to.</p>\n'}, {'answer_id': 81662, 'author': 'Ali Parr', 'author_id': 1169, 'author_profile': 'https://Stackoverflow.com/users/1169', 'pm_score': 1, 'selected': True, 'text': '<p>Thanks for the answers guys, ajryan, you seem to always come up with help for my questions so extra thanks.</p>\n\n<p>Thankfully this time the answer was fairly straightforward....</p>\n\n<pre><code>ImageList_DragShowNolock(FALSE);\nm_pDragDropTargetWnd->SendMessage(WM_USER_DRAG_DROP_OBJECT_DRAG_ENTER, (WPARAM)pDragDropObject, (LPARAM)(&dragDropPoint));\nImageList_DragShowNolock(TRUE);\n</code></pre>\n\n<p>This turns off the drawing of the dragged image, then sends a message to the window being entered to repaint in a highlighted state, then finally redraws the drag image over the top. Seems to have done the trick.</p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/74350', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1169/'] |
74,358 | <p>How can I get <a href="http://search.cpan.org/perldoc?LWP" rel="noreferrer">LWP</a> to verify that the certificate of the server I'm connecting to is signed by a trusted authority and issued to the correct host? As far as I can tell, it doesn't even check that the certificate claims to be for the hostname I'm connecting to. That seems like a major security hole (especially with the recent DNS vulnerabilities).</p>
<p><strong>Update:</strong> It turns out what I really wanted was <code>HTTPS_CA_DIR</code>, because I don't have a ca-bundle.crt. But <code>HTTPS_CA_DIR=/usr/share/ca-certificates/</code> did the trick. I'm marking the answer as accepted anyway, because it was close enough.</p>
<p><strong>Update 2:</strong> It turns out that <code>HTTPS_CA_DIR</code> and <code>HTTPS_CA_FILE</code> only apply if you're using Net::SSL as the underlying SSL library. But LWP also works with IO::Socket::SSL, which will ignore those environment variables and happily talk to any server, no matter what certificate it presents. Is there a more general solution?</p>
<p><strong>Update 3:</strong> Unfortunately, the solution still isn't complete. Neither Net::SSL nor IO::Socket::SSL is checking the host name against the certificate. This means that someone can get a legitimate certificate for some domain, and then impersonate any other domain without LWP complaining.</p>
<p><strong>Update 4:</strong> <a href="http://search.cpan.org/dist/libwww-perl/" rel="noreferrer">LWP 6.00</a> finally solves the problem. See <a href="https://stackoverflow.com/questions/74358/how-can-i-get-lwp-to-validate-ssl-server-certificates#5329129">my answer</a> for details.</p>
| [{'answer_id': 74432, 'author': 'Brian Phillips', 'author_id': 7230, 'author_profile': 'https://Stackoverflow.com/users/7230', 'pm_score': 3, 'selected': False, 'text': '<p>There are two means of doing this depending on which SSL module you have installed. The <a href="http://search.cpan.org/src/GAAS/libwww-perl-5.814/README.SSL" rel="nofollow noreferrer">LWP docs recommend installing Crypt::SSLeay</a>. If that\'s what you\'ve done, setting the <code>HTTPS_CA_FILE</code> environment variable to point to your ca-bundle.crt should do the trick. (the <a href="http://search.cpan.org/perldoc?Crypt::SSLeay" rel="nofollow noreferrer">Crypt::SSLeay docs</a> mentions this but is a bit light on details). Also, depending on your setup, you may need to set the <code>HTTPS_CA_DIR</code> environment variable instead.</p>\n\n<p>Example for Crypt::SSLeay:</p>\n\n<pre>\n<code>\nuse LWP::Simple qw(get);\n$ENV{HTTPS_CA_FILE} = "/path/to/your/ca/file/ca-bundle";\n$ENV{HTTPS_DEBUG} = 1;\n\nprint get("https://some-server-with-bad-certificate.com");\n\n__END__\nSSL_connect:before/connect initialization\nSSL_connect:SSLv2/v3 write client hello A\nSSL_connect:SSLv3 read server hello A\nSSL3 alert write:fatal:unknown CA\nSSL_connect:error in SSLv3 read server certificate B\nSSL_connect:error in SSLv3 read server certificate B\nSSL_connect:before/connect initialization\nSSL_connect:SSLv3 write client hello A\nSSL_connect:SSLv3 read server hello A\nSSL3 alert write:fatal:bad certificate\nSSL_connect:error in SSLv3 read server certificate B\nSSL_connect:before/connect initialization\nSSL_connect:SSLv2 write client hello A\nSSL_connect:error in SSLv2 read server hello B\n</code>\n</pre>\n\n<p>Note that get doesn\'t <code>die</code>, but it does return an <code>undef</code>.</p>\n\n<p>Alternatively, you can use the <code>IO::Socket::SSL</code> module (also available from the CPAN). To make this verify the server certificate you need to modify the SSL context defaults:</p>\n\n<pre>\n<code>\nuse IO::Socket::SSL qw(debug3);\nuse Net::SSLeay;\nBEGIN {\n IO::Socket::SSL::set_ctx_defaults(\n verify_mode => Net::SSLeay->VERIFY_PEER(),\n ca_file => "/path/to/ca-bundle.crt",\n # ca_path => "/alternate/path/to/cert/authority/directory"\n );\n}\nuse LWP::Simple qw(get);\n\nwarn get("https:://some-server-with-bad-certificate.com");\n</code>\n</pre>\n\n<p>This version also causes <code>get()</code> to return undef but prints a warning to <code>STDERR</code> when you execute it (as well as a bunch of debugging if you import the debug* symbols from IO::Socket::SSL):</p>\n\n<pre>\n<code>\n% perl ssl_test.pl\nDEBUG: .../IO/Socket/SSL.pm:1387: new ctx 139403496\nDEBUG: .../IO/Socket/SSL.pm:269: socket not yet connected\nDEBUG: .../IO/Socket/SSL.pm:271: socket connected\nDEBUG: .../IO/Socket/SSL.pm:284: ssl handshake not started\nDEBUG: .../IO/Socket/SSL.pm:327: Net::SSLeay::connect -> -1\nDEBUG: .../IO/Socket/SSL.pm:1135: SSL connect attempt failed with unknown errorerror:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed\n\nDEBUG: .../IO/Socket/SSL.pm:333: fatal SSL error: SSL connect attempt failed with unknown errorerror:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed\nDEBUG: .../IO/Socket/SSL.pm:1422: free ctx 139403496 open=139403496\nDEBUG: .../IO/Socket/SSL.pm:1425: OK free ctx 139403496\nDEBUG: .../IO/Socket/SSL.pm:1135: IO::Socket::INET configuration failederror:00000000:lib(0):func(0):reason(0)\n500 Can\'t connect to some-server-with-bad-certificate.com:443 (SSL connect attempt failed with unknown errorerror:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed) \n</code>\n</pre> \n'}, {'answer_id': 612238, 'author': 'dave0', 'author_id': 73886, 'author_profile': 'https://Stackoverflow.com/users/73886', 'pm_score': 2, 'selected': False, 'text': '<p>If you use LWP::UserAgent directly (not via LWP::Simple) you can validate the hostname in the certificate by adding the "If-SSL-Cert-Subject" header to your HTTP::Request object. The value of the header is treated as a regular expression to be applied on the certificate subject, and if it does not match, the request fails. For example:</p>\n\n<pre><code>#!/usr/bin/perl \nuse LWP::UserAgent;\nmy $ua = LWP::UserAgent->new();\nmy $req = HTTP::Request->new(GET => \'https://yourdomain.tld/whatever\');\n$req->header(\'If-SSL-Cert-Subject\' => \'/CN=make-it-fail.tld\');\n\nmy $res = $ua->request( $req );\n\nprint "Status: " . $res->status_line . "\\n"\n</code></pre>\n\n<p>will print</p>\n\n<pre><code>Status: 500 Bad SSL certificate subject: \'/C=CA/ST=Ontario/L=Ottawa/O=Your Org/CN=yourdomain.tld\' !~ //CN=make-it-fail.tld/\n</code></pre>\n'}, {'answer_id': 2318320, 'author': 'goneri', 'author_id': 2710608, 'author_profile': 'https://Stackoverflow.com/users/2710608', 'pm_score': 1, 'selected': False, 'text': '<p>You may also consider Net::SSLGlue ( <a href="http://search.cpan.org/dist/Net-SSLGlue/lib/Net/SSLGlue.pm" rel="nofollow noreferrer">http://search.cpan.org/dist/Net-SSLGlue/lib/Net/SSLGlue.pm</a> ) But, take care, it depends on recent IO::Socket::SSL and Net::SSLeay versions.</p>\n'}, {'answer_id': 2322654, 'author': 'Marsh Ray', 'author_id': 116270, 'author_profile': 'https://Stackoverflow.com/users/116270', 'pm_score': 1, 'selected': False, 'text': "<p>You are right to be concerned about this. Unfortunately, I don't think it's possible to do it 100% securely under any of the low-level SSL/TLS bindings I looked at for Perl.</p>\n\n<p>Essentially you need to pass in the hostname of the server you want to connect to the SSL library before the handshaking gets underway. Alternatively, you could arrange for a callback to occur at the right moment and abort the handshake from inside the callback if it doesn't check out. People writing Perl bindings to OpenSSL seemed to have troubles making the callback interface consistently.</p>\n\n<p>The method to check the hostname against the server's cert is dependent on the protocol, too. So that would have to be a parameter to any perfect function.</p>\n\n<p>You might want to see if there are any bindings to the Netscape/Mozilla NSS library. It seemed pretty good at doing this when I looked at it.</p>\n"}, {'answer_id': 5329129, 'author': 'cjm', 'author_id': 8355, 'author_profile': 'https://Stackoverflow.com/users/8355', 'pm_score': 6, 'selected': True, 'text': '<p>This long-standing security hole has finally been fixed in version 6.00 of <a href="https://metacpan.org/release/libwww-perl" rel="noreferrer">libwww-perl</a>. Starting with that version, by default <a href="https://metacpan.org/pod/LWP::UserAgent" rel="noreferrer">LWP::UserAgent</a> verifies that HTTPS servers present a valid certificate matching the expected hostname (unless <code>$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}</code> is set to a false value or, for backwards compatibility if that variable is not set at all, either <code>$ENV{HTTPS_CA_FILE}</code> or <code>$ENV{HTTPS_CA_DIR}</code> is set).</p>\n\n<p>This can be controlled by the new <a href="https://metacpan.org/pod/LWP::UserAgent#ssl_opts" rel="noreferrer">ssl_opts</a> option of LWP::UserAgent. See that link for details on how the Certificate Authority certificates are located. But <strong>be careful</strong>, the way LWP::UserAgent used to work, if you provide a <code>ssl_opts</code> hash to the constructor, then <strong><code>verify_hostname</code> defaulted to 0</strong> instead of 1. (<a href="https://rt.cpan.org/Public/Bug/Display.html?id=67947" rel="noreferrer">This bug</a> was fixed in LWP 6.03.) To be safe, always specify <code>verify_hostname => 1</code> in your <code>ssl_opts</code>.</p>\n\n<p>So <code>use LWP::UserAgent 6;</code> should be sufficient to have server certificates validated.</p>\n'}, {'answer_id': 7722012, 'author': 'blumentopf', 'author_id': 988281, 'author_profile': 'https://Stackoverflow.com/users/988281', 'pm_score': 2, 'selected': False, 'text': '<p>All the solutions presented here contain a major security flaw in that they only verify the validity of the certificate\'s trust chain, but don\'t compare the certificate\'s Common Name to the hostname you\'re connecting to. Thus, a man in the middle may present an arbitrary certificate to you and LWP will happily accept it as long as it\'s signed by a CA you trust. The bogus certificate\'s Common Name is irrelevant because it\'s never checked by LWP.</p>\n\n<p>If you\'re using <code>IO::Socket::SSL</code> as LWP\'s backend, you can enable verification of the Common Name by setting the <code>verifycn_scheme</code> parameter like this:</p>\n\n<pre><code>use IO::Socket::SSL;\nuse Net::SSLeay;\nBEGIN {\n IO::Socket::SSL::set_ctx_defaults(\n verify_mode => Net::SSLeay->VERIFY_PEER(),\n verifycn_scheme => \'http\',\n ca_path => "/etc/ssl/certs"\n );\n}\n</code></pre>\n'}, {'answer_id': 23570769, 'author': 'bshok', 'author_id': 1544311, 'author_profile': 'https://Stackoverflow.com/users/1544311', 'pm_score': 3, 'selected': False, 'text': '<p>I landed on this page looking for a way to bypass SSL validation but all answers were still very helpful. Here are my findings. For those looking to bypass SSL validation (not recommended but there may be cases where you will absolutely have to), I\'m on lwp 6.05 and this worked for me:</p>\n\n<pre><code>use strict;\nuse warnings;\nuse LWP::UserAgent;\nuse HTTP::Request::Common qw(GET);\nuse Net::SSL;\n\nmy $ua = LWP::UserAgent->new( ssl_opts => { verify_hostname => 0 }, );\nmy $req = GET \'https://github.com\';\nmy $res = $ua->request($req);\nif ($res->is_success) {\n print $res->content;\n} else {\n print $res->status_line . "\\n";\n}\n</code></pre>\n\n<p>I also tested on a page with POST and it also worked. The key is to use Net::SSL along with verify_hostname = 0.</p>\n'}, {'answer_id': 35243146, 'author': 'Bojoer', 'author_id': 3586145, 'author_profile': 'https://Stackoverflow.com/users/3586145', 'pm_score': 0, 'selected': False, 'text': '<p>Just perform execute the following command in Terminal:\n<strong>sudo cpan install Mozilla::CA</strong></p>\n\n<p>It should solve it.</p>\n'}] | 2008/09/16 | ['https://Stackoverflow.com/questions/74358', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/8355/'] |
Subsets and Splits