qid
int64
1
82.4k
question
stringlengths
27
22.5k
answers
stringlengths
509
252k
date
stringlengths
10
10
metadata
stringlengths
108
162
74,372
<p>I am involved in the process of porting a system containing several hundreds of ksh scripts from AIX, Solaris and HPUX to Linux. I have come across the following difference in the way ksh behaves on the two systems:</p> <pre><code>#!/bin/ksh flag=false echo "a\nb" | while read x do flag=true done echo "flag = ${flag}" exit 0 </code></pre> <p>On AIX, Solaris and HPUX the output is "flag = true" on Linux the output is "flag = false".</p> <p>My questions are:</p> <ul> <li>Is there an environment variable that I can set to get Linux's ksh to behave like the other Os's'? Failing that:</li> <li>Is there an option on Linux's ksh to get the required behavior? Failing that:</li> <li>Is there a ksh implementation available for Linux with the desired behavior?</li> </ul> <p>Other notes:</p> <ul> <li>On AIX, Solaris and HPUX ksh is a variant of ksh88.</li> <li>On Linux, ksh is the public domain ksh (pdksh)</li> <li>On AIX, Solaris and HPUX dtksh and ksh93 (where I have them installed) are consistent with ksh</li> <li>The Windows NT systems I have access to: Cygwin and MKS NT, are consistent with Linux.</li> <li>On AIX, Solaris and Linux, bash is consistent, giving the incorrect (from my perspective) result of "flag = false".</li> </ul> <p>The following table summarizes the systems the problem:</p> <pre><code>uname -s uname -r which ksh ksh version flag = ======== ======== ========= =========== ====== Linux 2.6.9-55.0.0.0.2.ELsmp /bin/ksh PD KSH v5.2.14 99/07/13.2 false AIX 3 /bin/ksh Version M-11/16/88f true // AIX 5.3 /bin/ksh93 Version M-12/28/93e true SunOS 5.8, 5.9 and 5.10 /bin/ksh Version M-11/16/88i true /usr/dt/bin/dtksh Version M-12/28/93d true HP-UX B.11.11 and B.11.23 /bin/ksh Version 11/16/88 true /usr/dt/bin/dtksh Version M-12/28/93d true CYGWIN_NT-5.1 1.5.25(0.156/4/2) /bin/ksh PD KSH v5.2.14 99/07/13.2 false Windows_NT 5 .../mksnt/ksh.exe Version 8.7.0 build 1859... false // MKS </code></pre> <h1>Update</h1> <p>After some advice from people in my company we decided to make the following modification to the code. This gives us the same result whether using the "real" ksh's (ksh88, ksh93) or any of the ksh clones (pdksh, MSK ksh). This also works correctly with bash.</p> <pre><code>#!/bin/ksh echo "a\nb" &gt; junk flag=false while read x do flag=true done &lt; junk echo "flag = ${flag}" exit 0 </code></pre> <p>Thanks to jj33 for the previously accepted answer.</p>
[{'answer_id': 74421, 'author': 'zigdon', 'author_id': 4913, 'author_profile': 'https://Stackoverflow.com/users/4913', 'pm_score': 0, 'selected': False, 'text': "<p>I don't know of any particular option to force ksh to be compatible with a particular older version. That said, perhaps you could install a very old version of ksh on your linux box, and have it behave in a compatible manner?</p>\n\n<p>It might be easier to install a more modern version of amy shell on the AIX/HP-UX boxes, and just migrate your scripts to use sh. I know there are versions of bash available for all platforms.</p>\n"}, {'answer_id': 74446, 'author': 'jj33', 'author_id': 430, 'author_profile': 'https://Stackoverflow.com/users/430', 'pm_score': 3, 'selected': False, 'text': '<p>Instead of using pdksh on linux, use the "real" ksh from kornshell.org. pdksh is a blind re-implementation of ksh. kornshell.org is the original korn shell dating back 25 years or so (the one written by David Korn). AIX and Solaris use versions of the original ksh, so the kornshell.org version is usually feature- and bug- complete. Having cut my teeth with SunOS/Solaris, installing kornshell.org ksh is usually one of the first things I do on a new Linux box...</p>\n'}, {'answer_id': 74580, 'author': 'Alex M', 'author_id': 9652, 'author_profile': 'https://Stackoverflow.com/users/9652', 'pm_score': 0, 'selected': False, 'text': '<p>Your script gives the correct (true) output when <code>zsh</code> is used with the <code>emulate -L ksh</code> option. If all else fails you may wish to try using <code>zsh</code> on Linux.</p>\n'}, {'answer_id': 74787, 'author': 'jtimberman', 'author_id': 7672, 'author_profile': 'https://Stackoverflow.com/users/7672', 'pm_score': 1, 'selected': False, 'text': '<p>I installed \'ksh\' and \'pdksh\' on my local Ubuntu Hardy system. </p>\n\n<pre><code>ii ksh 93s+20071105-1 The real, AT&amp;T version of the Korn shell\nii pdksh 5.2.14-21ubunt A public domain version of the Korn shell\n</code></pre>\n\n<p>ksh has the "correct" behavior that you\'re expecting while pdksh does not. You might check your local Linux distribution\'s software repository for a "real" ksh, instead of using pdksh. The "Real Unix" OS\'s are going to install the AT&amp;T version of Korn shell, rather than pdksh, by default, what with them being based off AT&amp;T Unix (System V) :-).</p>\n'}, {'answer_id': 76858, 'author': 'szabgab', 'author_id': 11827, 'author_profile': 'https://Stackoverflow.com/users/11827', 'pm_score': 1, 'selected': False, 'text': '<p>Do you have to stay within ksh?</p>\n\n<p>Even if you use the same ksh you\'ll still call all kinds of external commands (grep, ps, cat, etc...) part of them will have different parameters and different output from system to system. Either you\'ll have to take in account those differences or use the GNU version of each one of them to make things the same.</p>\n\n<p>The <a href="http://www.perl.org/" rel="nofollow noreferrer">Perl</a> programming language originally was designed exactly to overcome this problem.\nIt includes all the features a unix shell programmer would want from he shell program but\nit is the same on every Unix system. You might not have the latest version on all those\nsystems, but if you need to install something, maybe it is better to install perl.</p>\n'}, {'answer_id': 95267, 'author': 'Andrew Stein', 'author_id': 13029, 'author_profile': 'https://Stackoverflow.com/users/13029', 'pm_score': 3, 'selected': True, 'text': '<p>After some advice from people in my company we decided to make the following modification to the code. This gives us the same result whether using the "real" ksh\'s (ksh88, ksh93) or any of the ksh clones (pdksh, MSK ksh). This also works correctly with bash.</p>\n\n<pre><code>#!/bin/ksh\necho "a\\nb" &gt; junk\nflag=false\nwhile read x\ndo\n flag=true\ndone &lt; junk\necho "flag = ${flag}"\nexit 0\n</code></pre>\n\n<p>Thanks to jj33 for the previous accepted answer.</p>\n'}, {'answer_id': 255217, 'author': 'mpez0', 'author_id': 27898, 'author_profile': 'https://Stackoverflow.com/users/27898', 'pm_score': 1, 'selected': False, 'text': '<p>The reason for the differences is whether the inside block is executed in the original shell context or in a subshell. You may be able to control this with the () and {} grouping commands. Using a temporary file, as you do in your update, will work most of the time but will run into problems if the script is run twice rapidly, or if it executes without clearing the file, etc.</p>\n\n<pre><code>#!/bin/ksh\nflag=false\necho "a\\nb" | { while read x\ndo \n flag=true\ndone }\necho "flag = ${flag}"\nexit 0\n</code></pre>\n\n<p>That may help with the problem you were getting on the Linux ksh. If you use parentheses instead of braces, you\'ll get the Linux behavior on the other ksh implementations.</p>\n'}, {'answer_id': 22537900, 'author': 'venkat', 'author_id': 3442785, 'author_profile': 'https://Stackoverflow.com/users/3442785', 'pm_score': 1, 'selected': False, 'text': '<p>Here is the another solution for echo "\\n" issue</p>\n\n<p><strong>Steps:</strong></p>\n\n<ol>\n<li>Find ksh package name</li>\n</ol>\n\n<p><code>$ rpm -qa --queryformat "%{NAME}-%{VERSION}-%{RELEASE}(%{ARCH})\\n" | grep "ksh"\nksh-20100621-19.el6_4.3(x86_64)</code></p>\n\n<ol>\n<li><p>uninstall ksh\n<code>$ sudo yum remove ksh-20100621-19.el6_4.3.x86_64</code></p></li>\n<li><p>down load pdksh-5.2.14-37.el5_8.1.x86_64.rpm (Please check OS for 32-bit or 64-bit and choose correct pkg)</p></li>\n<li><p>Install pdksh-5.2.14-37.el5_8.1.x86_64.rpm</p></li>\n</ol>\n\n<p><code>$ sudo yum -y install /SCRIPT_PATH/pdksh-5.2.14-37.el5_8.1.x86_64.rpm</code></p>\n\n<p><strong>Output before PDKSH install</strong></p>\n\n<pre><code>$ ora_db_start_stop.sh\n\\n==============\nUsage: START\n==============\\n\\n\n./ora_db_start_stop.sh START ALL \\n\nOR \\n\n./ora_db_start_stop.sh START ONE_OR_MORE \\n\n\\n==============\nUsage: STOP\n==============\\n\\n\n./ora_db_start_stop.sh STOP ALL \\n\nOR \\n\n./ora_db_start_stop.sh STOP ONE_OR_MORE \\n\\n\n</code></pre>\n\n<p><strong>After PDKSH install</strong></p>\n\n<p>==============</p>\n\n<h1>Usage: START</h1>\n\n<p><code>./ora_db_start_stop.sh START ALL</code></p>\n\n<p>OR</p>\n\n<p><code>./ora_db_start_stop.sh START ONE_OR_MORE</code></p>\n\n<p>==============</p>\n\n<h1>Usage: STOP</h1>\n\n<p><code>./ora_db_start_stop.sh STOP ALL</code></p>\n\n<p>OR</p>\n\n<p><code>./ora_db_start_stop.sh STOP ONE_OR_MORE</code></p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74372', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13029/']
74,385
<p>I need to convert a value which is in a <code>DateTime</code> variable into a <code>varchar</code> variable formatted as <code>yyyy-mm-dd</code> format (without time part).</p> <p>How do I do that?</p>
[{'answer_id': 74394, 'author': 'Joel Coehoorn', 'author_id': 3043, 'author_profile': 'https://Stackoverflow.com/users/3043', 'pm_score': 8, 'selected': False, 'text': '<p>Try the following:</p>\n\n<pre><code>CONVERT(varchar(10), [MyDateTimecolumn], 20)\n</code></pre>\n\n<p>For a full date time and not just date do: </p>\n\n<pre><code>CONVERT(varchar(23), [MyDateTimecolumn], 121)\n</code></pre>\n\n<p>See this page for convert styles:</p>\n\n<p><a href="http://msdn.microsoft.com/en-us/library/ms187928.aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/ms187928.aspx</a><br>\nOR<br>\n<a href="http://www.w3schools.com/sql/func_convert.asp" rel="noreferrer">SQL Server CONVERT() Function</a></p>\n'}, {'answer_id': 74404, 'author': 'Per Hornshøj-Schierbeck', 'author_id': 11619, 'author_profile': 'https://Stackoverflow.com/users/11619', 'pm_score': 3, 'selected': False, 'text': '<p>Either <code>Cast</code> or <code>Convert</code>:</p>\n\n<p>Syntax for <code>CAST</code>:</p>\n\n<pre><code>CAST ( expression AS data_type [ (length ) ])\n</code></pre>\n\n<p>Syntax for <code>CONVERT</code>:</p>\n\n<pre><code>CONVERT ( data_type [ ( length ) ] , expression [ , style ] )\n</code></pre>\n\n<p><a href="http://msdn.microsoft.com/en-us/library/ms187928.aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/ms187928.aspx</a></p>\n\n<p>Actually since you asked for a specific format:</p>\n\n<pre><code>REPLACE(CONVERT(varchar(10), Date, 102), \'.\', \'-\')\n</code></pre>\n'}, {'answer_id': 74431, 'author': 'Allan Wind', 'author_id': 9706, 'author_profile': 'https://Stackoverflow.com/users/9706', 'pm_score': 1, 'selected': False, 'text': '<p>You did not say which database, but with mysql here is an easy way to get a date from a timestamp (and the varchar type conversion should happen automatically):</p>\n\n<pre><code>mysql&gt; select date(now());\n+-------------+\n| date(now()) |\n+-------------+\n| 2008-09-16 | \n+-------------+\n1 row in set (0.00 sec)\n</code></pre>\n'}, {'answer_id': 74438, 'author': 'Amy Patterson', 'author_id': 300930, 'author_profile': 'https://Stackoverflow.com/users/300930', 'pm_score': 2, 'selected': False, 'text': '<p>Try the following:</p>\n\n<pre><code>CONVERT(VARCHAR(10),GetDate(),102)\n</code></pre>\n\n<p>Then you would need to replace the "." with "-".</p>\n\n<p>Here is a site that helps\n<a href="http://www.mssqltips.com/tip.asp?tip=1145" rel="nofollow noreferrer">http://www.mssqltips.com/tip.asp?tip=1145</a></p>\n'}, {'answer_id': 74469, 'author': 'TonyOssa', 'author_id': 3276, 'author_profile': 'https://Stackoverflow.com/users/3276', 'pm_score': 9, 'selected': True, 'text': "<p>With Microsoft Sql Server:</p>\n\n<pre><code>--\n-- Create test case\n--\nDECLARE @myDateTime DATETIME\nSET @myDateTime = '2008-05-03'\n\n--\n-- Convert string\n--\nSELECT LEFT(CONVERT(VARCHAR, @myDateTime, 120), 10)\n</code></pre>\n"}, {'answer_id': 74473, 'author': 'Johnny Bravado', 'author_id': 12222, 'author_profile': 'https://Stackoverflow.com/users/12222', 'pm_score': -1, 'selected': False, 'text': '<p>You don\'t say what language but I am assuming <code>C#/.NET</code> because it has a native <code>DateTime</code> data type. In that case just convert it using the <code>ToString</code> method and use a format specifier such as:</p>\n\n<pre><code>DateTime d = DateTime.Today;\nstring result = d.ToString("yyyy-MM-dd");\n</code></pre>\n\n<p>However, I would caution against using this in a database query or concatenated into a SQL statement. Databases require a specific formatting string to be used. You are better off zeroing out the time part and using the DateTime as a SQL parameter if that is what you are trying to accomplish.</p>\n'}, {'answer_id': 138476, 'author': 'Andy Jones', 'author_id': 5096, 'author_profile': 'https://Stackoverflow.com/users/5096', 'pm_score': 2, 'selected': False, 'text': '<pre><code>declare @dt datetime\n\nset @dt = getdate()\n\nselect convert(char(10),@dt,120) \n</code></pre>\n\n<p>I have fixed data length of <code>char(10)</code> as you want a specific string format.</p>\n'}, {'answer_id': 6254392, 'author': 'Arek Bee', 'author_id': 664252, 'author_profile': 'https://Stackoverflow.com/users/664252', 'pm_score': 2, 'selected': False, 'text': '<p>Try:</p>\n\n<pre><code>select replace(convert(varchar, getdate(), 111),\'/\',\'-\');\n</code></pre>\n\n<p>More on <a href="http://www.mssqltips.com/tip.asp?tip=1145" rel="nofollow">ms sql tips</a></p>\n'}, {'answer_id': 6430393, 'author': "P's-SQL", 'author_id': 809074, 'author_profile': 'https://Stackoverflow.com/users/809074', 'pm_score': 3, 'selected': False, 'text': "<p>-- This gives you the time as 0 in format 'yyyy-mm-dd 00:00:00.000'</p>\n\n<pre><code>\nSELECT CAST( CONVERT(VARCHAR, GETDATE(), 101) AS DATETIME) ; \n</code></pre>\n"}, {'answer_id': 7040880, 'author': 'OldBuildingAndLoan', 'author_id': 70870, 'author_profile': 'https://Stackoverflow.com/users/70870', 'pm_score': 2, 'selected': False, 'text': "<p>The OP mentioned <strong>datetime</strong> format. For me, the time part gets in the way.<br>\nI think it's a bit cleaner to remove the time portion (by casting datetime to date) before formatting.</p>\n\n<pre><code>convert( varchar(10), convert( date, @yourDate ) , 111 )\n</code></pre>\n"}, {'answer_id': 10819689, 'author': 'dmunozpa', 'author_id': 1017892, 'author_profile': 'https://Stackoverflow.com/users/1017892', 'pm_score': 3, 'selected': False, 'text': '<p>With Microsoft SQL Server:</p>\n\n<p>Use Syntax for CONVERT:</p>\n\n<pre><code>CONVERT ( data_type [ ( length ) ] , expression [ , style ] )\n</code></pre>\n\n<p>Example:</p>\n\n<pre><code>SELECT CONVERT(varchar,d.dateValue,1-9)\n</code></pre>\n\n<p>For the style you can find more info here: <a href="http://msdn.microsoft.com/en-us/library/ms187928.aspx" rel="noreferrer">MSDN - Cast and Convert (Transact-SQL)</a>.</p>\n'}, {'answer_id': 11587309, 'author': 'FCKOE', 'author_id': 1541843, 'author_profile': 'https://Stackoverflow.com/users/1541843', 'pm_score': 3, 'selected': False, 'text': '<p>You can use <code>DATEPART(DATEPART, VARIABLE)</code>. For example:</p>\n\n<pre class="lang-sql prettyprint-override"><code>DECLARE @DAY INT \nDECLARE @MONTH INT\nDECLARE @YEAR INT\nDECLARE @DATE DATETIME\n@DATE = GETDATE()\nSELECT @DAY = DATEPART(DAY,@DATE)\nSELECT @MONTH = DATEPART(MONTH,@DATE)\nSELECT @YEAR = DATEPART(YEAR,@DATE)\n</code></pre>\n'}, {'answer_id': 15621120, 'author': 'IvanSnek', 'author_id': 1899696, 'author_profile': 'https://Stackoverflow.com/users/1899696', 'pm_score': 2, 'selected': False, 'text': '<p>This is how I do it: <code>CONVERT(NVARCHAR(10), DATE1, 103) )</code></p>\n'}, {'answer_id': 17713768, 'author': 'Zar Shardan', 'author_id': 913845, 'author_profile': 'https://Stackoverflow.com/users/913845', 'pm_score': 5, 'selected': False, 'text': '<p>SQL Server 2012 has a new function , FORMAT: \n<a href="http://msdn.microsoft.com/en-us/library/ee634924.aspx">http://msdn.microsoft.com/en-us/library/ee634924.aspx</a></p>\n\n<p>and you can use custom date time format strings: <a href="http://msdn.microsoft.com/en-us/library/ee634398.aspx">http://msdn.microsoft.com/en-us/library/ee634398.aspx</a></p>\n\n<p>These pages imply it is also available on SQL2008R2, but I don\'t have one handy to test if that\'s the case.</p>\n\n<p>Example usage (Australian datetime): </p>\n\n<pre><code>FORMAT(VALUE,\'dd/MM/yyyy h:mm:ss tt\')\n</code></pre>\n'}, {'answer_id': 19537658, 'author': 'Colin', 'author_id': 150342, 'author_profile': 'https://Stackoverflow.com/users/150342', 'pm_score': 9, 'selected': False, 'text': "<p>Here's some test sql for all the styles.</p>\n\n<pre><code>DECLARE @now datetime\nSET @now = GETDATE()\nselect convert(nvarchar(MAX), @now, 0) as output, 0 as style \nunion select convert(nvarchar(MAX), @now, 1), 1\nunion select convert(nvarchar(MAX), @now, 2), 2\nunion select convert(nvarchar(MAX), @now, 3), 3\nunion select convert(nvarchar(MAX), @now, 4), 4\nunion select convert(nvarchar(MAX), @now, 5), 5\nunion select convert(nvarchar(MAX), @now, 6), 6\nunion select convert(nvarchar(MAX), @now, 7), 7\nunion select convert(nvarchar(MAX), @now, 8), 8\nunion select convert(nvarchar(MAX), @now, 9), 9\nunion select convert(nvarchar(MAX), @now, 10), 10\nunion select convert(nvarchar(MAX), @now, 11), 11\nunion select convert(nvarchar(MAX), @now, 12), 12\nunion select convert(nvarchar(MAX), @now, 13), 13\nunion select convert(nvarchar(MAX), @now, 14), 14\n--15 to 19 not valid\nunion select convert(nvarchar(MAX), @now, 20), 20\nunion select convert(nvarchar(MAX), @now, 21), 21\nunion select convert(nvarchar(MAX), @now, 22), 22\nunion select convert(nvarchar(MAX), @now, 23), 23\nunion select convert(nvarchar(MAX), @now, 24), 24\nunion select convert(nvarchar(MAX), @now, 25), 25\n--26 to 99 not valid\nunion select convert(nvarchar(MAX), @now, 100), 100\nunion select convert(nvarchar(MAX), @now, 101), 101\nunion select convert(nvarchar(MAX), @now, 102), 102\nunion select convert(nvarchar(MAX), @now, 103), 103\nunion select convert(nvarchar(MAX), @now, 104), 104\nunion select convert(nvarchar(MAX), @now, 105), 105\nunion select convert(nvarchar(MAX), @now, 106), 106\nunion select convert(nvarchar(MAX), @now, 107), 107\nunion select convert(nvarchar(MAX), @now, 108), 108\nunion select convert(nvarchar(MAX), @now, 109), 109\nunion select convert(nvarchar(MAX), @now, 110), 110\nunion select convert(nvarchar(MAX), @now, 111), 111\nunion select convert(nvarchar(MAX), @now, 112), 112\nunion select convert(nvarchar(MAX), @now, 113), 113\nunion select convert(nvarchar(MAX), @now, 114), 114\nunion select convert(nvarchar(MAX), @now, 120), 120\nunion select convert(nvarchar(MAX), @now, 121), 121\n--122 to 125 not valid\nunion select convert(nvarchar(MAX), @now, 126), 126\nunion select convert(nvarchar(MAX), @now, 127), 127\n--128, 129 not valid\nunion select convert(nvarchar(MAX), @now, 130), 130\nunion select convert(nvarchar(MAX), @now, 131), 131\n--132 not valid\norder BY style\n</code></pre>\n\n<p>Here's the result</p>\n\n<pre><code>output style\nApr 28 2014 9:31AM 0\n04/28/14 1\n14.04.28 2\n28/04/14 3\n28.04.14 4\n28-04-14 5\n28 Apr 14 6\nApr 28, 14 7\n09:31:28 8\nApr 28 2014 9:31:28:580AM 9\n04-28-14 10\n14/04/28 11\n140428 12\n28 Apr 2014 09:31:28:580 13\n09:31:28:580 14\n2014-04-28 09:31:28 20\n2014-04-28 09:31:28.580 21\n04/28/14 9:31:28 AM 22\n2014-04-28 23\n09:31:28 24\n2014-04-28 09:31:28.580 25\nApr 28 2014 9:31AM 100\n04/28/2014 101\n2014.04.28 102\n28/04/2014 103\n28.04.2014 104\n28-04-2014 105\n28 Apr 2014 106\nApr 28, 2014 107\n09:31:28 108\nApr 28 2014 9:31:28:580AM 109\n04-28-2014 110\n2014/04/28 111\n20140428 112\n28 Apr 2014 09:31:28:580 113\n09:31:28:580 114\n2014-04-28 09:31:28 120\n2014-04-28 09:31:28.580 121\n2014-04-28T09:31:28.580 126\n2014-04-28T09:31:28.580 127\n28 جمادى الثانية 1435 9:31:28:580AM 130\n28/06/1435 9:31:28:580AM 131\n</code></pre>\n\n<p>Make <code>nvarchar(max)</code> shorter to trim the time. For example:</p>\n\n<pre><code>select convert(nvarchar(11), GETDATE(), 0)\nunion select convert(nvarchar(max), GETDATE(), 0)\n</code></pre>\n\n<p>outputs:</p>\n\n<pre><code>May 18 2018\nMay 18 2018 9:57AM\n</code></pre>\n"}, {'answer_id': 23369972, 'author': 'Gabriel', 'author_id': 3112707, 'author_profile': 'https://Stackoverflow.com/users/3112707', 'pm_score': 1, 'selected': False, 'text': '<pre><code>CONVERT(VARCHAR, GETDATE(), 23)\n</code></pre>\n'}, {'answer_id': 27231940, 'author': 'Konstantin', 'author_id': 1665649, 'author_profile': 'https://Stackoverflow.com/users/1665649', 'pm_score': 2, 'selected': False, 'text': '<p>The shortest and the simplest way is :</p>\n\n<pre><code>DECLARE @now AS DATETIME = GETDATE()\n\nSELECT CONVERT(VARCHAR, @now, 23)\n</code></pre>\n'}, {'answer_id': 41594909, 'author': 'Ema.H', 'author_id': 2630447, 'author_profile': 'https://Stackoverflow.com/users/2630447', 'pm_score': 2, 'selected': False, 'text': '<p>You can convert your date in many formats, the syntaxe is simple to use :</p>\n\n<pre><code>CONVERT(\'TheTypeYouWant\', \'TheDateToConvert\', \'TheCodeForFormating\' * )\nCONVERT(NVARCHAR(10), DATE_OF_DAY, 103) =&gt; 15/09/2016\n</code></pre>\n\n<ul>\n<li>The code is an integer, here 3 is the third formating without century, if you want the century just change the code to 103.</li>\n</ul>\n\n<p><strong>In your case</strong>, i\'ve just converted and restrict size by nvarchar(10) like this :</p>\n\n<pre><code>CONVERT(NVARCHAR(10), MY_DATE_TIME, 120) =&gt; 2016-09-15\n</code></pre>\n\n<p>See more at : <a href="http://www.w3schools.com/sql/func_convert.asp" rel="nofollow noreferrer">http://www.w3schools.com/sql/func_convert.asp</a></p>\n\n<p><strong>Another solution</strong> (if your date is a Datetime) is a simple <strong>CAST</strong> :</p>\n\n<pre><code>CAST(MY_DATE_TIME as DATE) =&gt; 2016-09-15\n</code></pre>\n'}, {'answer_id': 45005103, 'author': 'Dilkhush', 'author_id': 7384154, 'author_profile': 'https://Stackoverflow.com/users/7384154', 'pm_score': 2, 'selected': False, 'text': "<p>Try this SQL:</p>\n\n<pre><code>select REPLACE(CONVERT(VARCHAR(24),GETDATE(),103),'/','_') + '_'+ \n REPLACE(CONVERT(VARCHAR(24),GETDATE(),114),':','_')\n</code></pre>\n"}, {'answer_id': 53440678, 'author': 'Dilkhush', 'author_id': 7384154, 'author_profile': 'https://Stackoverflow.com/users/7384154', 'pm_score': 1, 'selected': False, 'text': "<pre><code>DECLARE @DateTime DATETIME\nSET @DateTime = '2018-11-23 10:03:23'\nSELECT CONVERT(VARCHAR(100),@DateTime,121 )\n</code></pre>\n"}, {'answer_id': 53486217, 'author': 'Peter Majko', 'author_id': 4528229, 'author_profile': 'https://Stackoverflow.com/users/4528229', 'pm_score': 2, 'selected': False, 'text': "<p>For SQL Server 2008+ You can use CONVERT and FORMAT together.</p>\n\n<p>For example, for European style (e.g. Germany) timestamp:</p>\n\n<pre><code>CONVERT(VARCHAR, FORMAT(GETDATE(), 'dd.MM.yyyy HH:mm:ss', 'de-DE'))\n</code></pre>\n"}, {'answer_id': 57322855, 'author': 'Beyhan', 'author_id': 2599859, 'author_profile': 'https://Stackoverflow.com/users/2599859', 'pm_score': 0, 'selected': False, 'text': "<p>Write a function</p>\n\n<pre><code>CREATE FUNCTION dbo.TO_SAP_DATETIME(@input datetime)\nRETURNS VARCHAR(14)\nAS BEGIN\n DECLARE @ret VARCHAR(14)\n SET @ret = COALESCE(SUBSTRING(REPLACE(REPLACE(REPLACE(CONVERT(VARCHAR(26), @input, 25),'-',''),' ',''),':',''),1,14),'00000000000000');\n RETURN @ret\nEND\n</code></pre>\n"}, {'answer_id': 61617060, 'author': 'Andres Galindo', 'author_id': 13475919, 'author_profile': 'https://Stackoverflow.com/users/13475919', 'pm_score': 1, 'selected': False, 'text': "<pre><code>select REPLACE(CONVERT(VARCHAR, FORMAT(GETDATE(), N'dd/MM/yyyy hh:mm:ss tt')),'.', '/')\n</code></pre>\n\n<p>will give <code>05/05/2020 10:41:05 AM</code> as a result</p>\n"}, {'answer_id': 67225951, 'author': 'Zain', 'author_id': 4281423, 'author_profile': 'https://Stackoverflow.com/users/4281423', 'pm_score': 0, 'selected': False, 'text': "<p>Simple use &quot;Convert&quot; and then use &quot;Format&quot; to get your desire date format</p>\n<pre><code>DECLARE @myDateTime DATETIME\nSET @myDateTime = '2008-05-03'\n\nSELECT FORMAT(CONVERT(date, @myDateTime ),'yyyy-MM-dd')\n</code></pre>\n"}]
2008/09/16
['https://Stackoverflow.com/questions/74385', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/7604/']
74,386
<p>Is it possible to call managed code, specifically IronRuby or IronPython from unamanaged code such as C++ or Delphi?</p> <p>For example, we have an application written in Delphi that is being moved to C#.NET We'd like to provide Ruby or Python scripting in our new application to replace VBSCRIPT. However, we would need to provide Ruby/Python scripting in the old Delphi application. Is it possible to use the managed dlls provided by IronRuby/IronPython from Delphi code?</p>
[{'answer_id': 74420, 'author': 'Lars Truijens', 'author_id': 1242, 'author_profile': 'https://Stackoverflow.com/users/1242', 'pm_score': 2, 'selected': False, 'text': '<p>Yes. That is possible using <a href="http://msdn.microsoft.com/en-us/library/f07c8z1c.aspx" rel="nofollow noreferrer">Com Callable Wrappers</a>. Basically you are enabling your .Net classes to be called through COM/ActiveX from your win32 code (Delphi or C++).</p>\n'}, {'answer_id': 74441, 'author': 'Karg', 'author_id': 12685, 'author_profile': 'https://Stackoverflow.com/users/12685', 'pm_score': 3, 'selected': False, 'text': '<p>It is possible to host the CLR or DLR in unmanaged code as it is a COM component. From that point you can load the managed assemblies you need to interact with.</p>\n\n<p>From MSDN: <a href="http://msdn.microsoft.com/en-us/library/9x0wh2z3.aspx" rel="noreferrer">Hosting the Common Language Runtime</a></p>\n'}, {'answer_id': 74456, 'author': 'Lars Fosdal', 'author_id': 10002, 'author_profile': 'https://Stackoverflow.com/users/10002', 'pm_score': 4, 'selected': True, 'text': '<p>Yes. Delphi for Win32 example here: <a href="http://interop.managed-vcl.com/" rel="noreferrer">http://interop.managed-vcl.com/</a><br>\nShows how to use a C# as well as a Delphi.NET assembly from Delphi for Win32.</p>\n'}, {'answer_id': 75252, 'author': 'Vegar', 'author_id': 11956, 'author_profile': 'https://Stackoverflow.com/users/11956', 'pm_score': 0, 'selected': False, 'text': '<p>Have you seen <a href="http://www.remobjects.com/product/?id=%7BB6BD1030-F630-4DA8-9018-73C03265A0EF%7D" rel="nofollow noreferrer">Hydra</a> from RemObjects? I have no experience with it, but from the intro, it looks relevant.</p>\n'}, {'answer_id': 934717, 'author': 'fuzzyman', 'author_id': 5341, 'author_profile': 'https://Stackoverflow.com/users/5341', 'pm_score': 2, 'selected': False, 'text': '<p>Why not embed CPython instead, which has an API intended to be used directly from C/C++. You lose the multiple language advantage but probably gain simplicity.</p>\n'}, {'answer_id': 2351140, 'author': 'Lukas Cenovsky', 'author_id': 138803, 'author_profile': 'https://Stackoverflow.com/users/138803', 'pm_score': 2, 'selected': False, 'text': '<p>I use <a href="http://sites.google.com/site/robertgiesecke/Home/uploads/unmanagedexports" rel="nofollow noreferrer">Unmanaged Exports</a> to created interface to IronPython script engine in C#. Be carefull when you use .NET code from Win32 Delphi - you have to use <code>Set8087CW($133F);</code> to change floating point exception behavior.</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74386', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12999/']
74,391
<p>Multithread algorithms are notably hard to design/debug/prove. Dekker's algorithm is a prime example of how hard it can be to design a correct synchronized algorithm. Tanenbaum's Modern operating systems is filled with examples in its IPC section. Does anyone have a good reference (books, articles) for this? Thanks!</p>
[{'answer_id': 74899, 'author': 'Mostlyharmless', 'author_id': 12881, 'author_profile': 'https://Stackoverflow.com/users/12881', 'pm_score': 0, 'selected': False, 'text': '<p>@Just in case: I is. But from what i learnt, doing so for a non trivial algorithm is a major pain. I leave that sort of a thing for brainier people. I learnt what i know from Parallel Program Design: A Foundation (1988)\nby K M Chandy, J Misra </p>\n'}, {'answer_id': 75060, 'author': 'Chris Vest', 'author_id': 13251, 'author_profile': 'https://Stackoverflow.com/users/13251', 'pm_score': 4, 'selected': False, 'text': "<p>It is impossible to prove anything without building upon guarentees, so the first thing you want to do is to get familiar with the memory model of your target platform; Java and x86 both have solid and standardized memory models - I'm not so sure about CLR, but if all else fails, you'll have build upon the memory model of your target CPU architecture. The exception to this rule is if you intend to use a language that does does not allow any shared mutable state at all - I've heard Erlang is like that.</p>\n\n<p>The first problem of concurrency is shared mutable state.</p>\n\n<p>That can be fixed by:</p>\n\n<ul>\n<li>Making state immutable</li>\n<li>Not sharing state</li>\n<li>Guarding shared mutable state by the <em>same</em> lock (two different locks cannot guard the same piece of state, unless you <em>always</em> use exactly these two locks)</li>\n</ul>\n\n<p>The second problem of concurrency is safe publication. How do you make data available to other threads? How do you perform a hand-over? You'll the solution to this problem in the memory model, and (hopefully) in the API. Java, for instance, has many ways to publish state and the java.util.concurrent package contains tools specifically designed to handle inter-thread communication.</p>\n\n<p>The third (and harder) problem of concurrency is locking. Mismanaged lock-ordering is the source of dead-locks. You can analytically prove, building upon the memory model guarentees, whether or not dead-locks are possible in your code. However, you need to design and write your code with that in mind, otherwise the complexity of the code can quickly render such an analysis impossible to perform in practice.</p>\n\n<p>Then, once you have, or before you do, prove the correct use of concurrency, you will have to prove single-threaded correctness. The set of bugs that can occur in a concurrent code base is equal to the set of single-threaded program bugs, plus all the possible concurrency bugs.</p>\n"}, {'answer_id': 75832, 'author': 'dckc', 'author_id': 7963, 'author_profile': 'https://Stackoverflow.com/users/7963', 'pm_score': 2, 'selected': False, 'text': '<p>Short answer: it\'s hard.</p>\n\n<p>There was some really good work in the DEC SRC Modula-3 and larch stuff from the late 1980\'s.</p>\n\n<p>e.g.</p>\n\n<ul>\n<li><p><a href="ftp://gatekeeper.dec.com/pub/DEC/SRC/research-reports/SRC-020.ps.Z" rel="nofollow noreferrer">Thread synchronization: A formal specification</a> (1991)\nby A D Birrell, J V Guttag, J J Horning, R Levin\nSystem Programming with Modula-3, chapter 5 </p></li>\n<li><p><a href="http://gatekeeper.dec.com/pub/DEC/SRC/research-reports/SRC-159.pdf" rel="nofollow noreferrer">Extended static checking</a> (1998)\nby David L. Detlefs, David L. Detlefs, K. Rustan, K. Rustan, M. Leino, M. Leino, Greg Nelson, Greg Nelson, James B. Saxe, James B. Saxe</p></li>\n</ul>\n\n<p>Some of the good ideas from Modula-3 are making it into the Java world, e.g.\nJML, though "JML is currently limited to sequential specification" says the <a href="http://www.eecs.ucf.edu/~leavens/JML/jmlrefman/jmlrefman_1.html" rel="nofollow noreferrer">intro</a>.</p>\n'}, {'answer_id': 88368, 'author': 'mweerden', 'author_id': 4285, 'author_profile': 'https://Stackoverflow.com/users/4285', 'pm_score': 1, 'selected': False, 'text': "<p>I don't have any concrete references, but you might want to look into the Owicki-Gries theory (if you like theorem proving) or process theory/algebra (for which there are also various model-checking tools available).</p>\n"}, {'answer_id': 88393, 'author': 'Apocalisp', 'author_id': 3434, 'author_profile': 'https://Stackoverflow.com/users/3434', 'pm_score': 2, 'selected': False, 'text': '<p><a href="http://books.google.com/books?id=WR828X_7488C&amp;dq=pi-calculus&amp;pg=PP1&amp;ots=C2uWpHm7fN&amp;sig=H_cJSbWkK6TzKTe3x89BtTDYSyw&amp;hl=en&amp;sa=X&amp;oi=book_result&amp;resnum=1&amp;ct=result" rel="nofollow noreferrer">The Pi-Calculus, A Theory of Mobile Processes</a> is a good place to begin.</p>\n'}, {'answer_id': 93424, 'author': 'jdkoftinoff', 'author_id': 32198, 'author_profile': 'https://Stackoverflow.com/users/32198', 'pm_score': 2, 'selected': False, 'text': '<p>"Principles of Concurrent and Distributed Programming", M. Ben-Ari<br>\nISBN-13: 978-0-321-31283-9<br>\nThey have in on safari books online for reading:<br>\n<a href="http://my.safaribooksonline.com/9780321312839" rel="nofollow noreferrer">http://my.safaribooksonline.com/9780321312839</a></p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74391', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13035/']
74,392
<p>I know there is a Jackpot API <a href="http://jackpot.netbeans.org/docs/org-netbeans-modules-jackpot/overview-summary.html" rel="nofollow noreferrer">http://jackpot.netbeans.org/docs/org-netbeans-modules-jackpot/overview-summary.html</a> for programmatic access the the rules engine, has anyone had success seperating this from NetBeans itself? So it can operate on any Java source files?</p>
[{'answer_id': 74899, 'author': 'Mostlyharmless', 'author_id': 12881, 'author_profile': 'https://Stackoverflow.com/users/12881', 'pm_score': 0, 'selected': False, 'text': '<p>@Just in case: I is. But from what i learnt, doing so for a non trivial algorithm is a major pain. I leave that sort of a thing for brainier people. I learnt what i know from Parallel Program Design: A Foundation (1988)\nby K M Chandy, J Misra </p>\n'}, {'answer_id': 75060, 'author': 'Chris Vest', 'author_id': 13251, 'author_profile': 'https://Stackoverflow.com/users/13251', 'pm_score': 4, 'selected': False, 'text': "<p>It is impossible to prove anything without building upon guarentees, so the first thing you want to do is to get familiar with the memory model of your target platform; Java and x86 both have solid and standardized memory models - I'm not so sure about CLR, but if all else fails, you'll have build upon the memory model of your target CPU architecture. The exception to this rule is if you intend to use a language that does does not allow any shared mutable state at all - I've heard Erlang is like that.</p>\n\n<p>The first problem of concurrency is shared mutable state.</p>\n\n<p>That can be fixed by:</p>\n\n<ul>\n<li>Making state immutable</li>\n<li>Not sharing state</li>\n<li>Guarding shared mutable state by the <em>same</em> lock (two different locks cannot guard the same piece of state, unless you <em>always</em> use exactly these two locks)</li>\n</ul>\n\n<p>The second problem of concurrency is safe publication. How do you make data available to other threads? How do you perform a hand-over? You'll the solution to this problem in the memory model, and (hopefully) in the API. Java, for instance, has many ways to publish state and the java.util.concurrent package contains tools specifically designed to handle inter-thread communication.</p>\n\n<p>The third (and harder) problem of concurrency is locking. Mismanaged lock-ordering is the source of dead-locks. You can analytically prove, building upon the memory model guarentees, whether or not dead-locks are possible in your code. However, you need to design and write your code with that in mind, otherwise the complexity of the code can quickly render such an analysis impossible to perform in practice.</p>\n\n<p>Then, once you have, or before you do, prove the correct use of concurrency, you will have to prove single-threaded correctness. The set of bugs that can occur in a concurrent code base is equal to the set of single-threaded program bugs, plus all the possible concurrency bugs.</p>\n"}, {'answer_id': 75832, 'author': 'dckc', 'author_id': 7963, 'author_profile': 'https://Stackoverflow.com/users/7963', 'pm_score': 2, 'selected': False, 'text': '<p>Short answer: it\'s hard.</p>\n\n<p>There was some really good work in the DEC SRC Modula-3 and larch stuff from the late 1980\'s.</p>\n\n<p>e.g.</p>\n\n<ul>\n<li><p><a href="ftp://gatekeeper.dec.com/pub/DEC/SRC/research-reports/SRC-020.ps.Z" rel="nofollow noreferrer">Thread synchronization: A formal specification</a> (1991)\nby A D Birrell, J V Guttag, J J Horning, R Levin\nSystem Programming with Modula-3, chapter 5 </p></li>\n<li><p><a href="http://gatekeeper.dec.com/pub/DEC/SRC/research-reports/SRC-159.pdf" rel="nofollow noreferrer">Extended static checking</a> (1998)\nby David L. Detlefs, David L. Detlefs, K. Rustan, K. Rustan, M. Leino, M. Leino, Greg Nelson, Greg Nelson, James B. Saxe, James B. Saxe</p></li>\n</ul>\n\n<p>Some of the good ideas from Modula-3 are making it into the Java world, e.g.\nJML, though "JML is currently limited to sequential specification" says the <a href="http://www.eecs.ucf.edu/~leavens/JML/jmlrefman/jmlrefman_1.html" rel="nofollow noreferrer">intro</a>.</p>\n'}, {'answer_id': 88368, 'author': 'mweerden', 'author_id': 4285, 'author_profile': 'https://Stackoverflow.com/users/4285', 'pm_score': 1, 'selected': False, 'text': "<p>I don't have any concrete references, but you might want to look into the Owicki-Gries theory (if you like theorem proving) or process theory/algebra (for which there are also various model-checking tools available).</p>\n"}, {'answer_id': 88393, 'author': 'Apocalisp', 'author_id': 3434, 'author_profile': 'https://Stackoverflow.com/users/3434', 'pm_score': 2, 'selected': False, 'text': '<p><a href="http://books.google.com/books?id=WR828X_7488C&amp;dq=pi-calculus&amp;pg=PP1&amp;ots=C2uWpHm7fN&amp;sig=H_cJSbWkK6TzKTe3x89BtTDYSyw&amp;hl=en&amp;sa=X&amp;oi=book_result&amp;resnum=1&amp;ct=result" rel="nofollow noreferrer">The Pi-Calculus, A Theory of Mobile Processes</a> is a good place to begin.</p>\n'}, {'answer_id': 93424, 'author': 'jdkoftinoff', 'author_id': 32198, 'author_profile': 'https://Stackoverflow.com/users/32198', 'pm_score': 2, 'selected': False, 'text': '<p>"Principles of Concurrent and Distributed Programming", M. Ben-Ari<br>\nISBN-13: 978-0-321-31283-9<br>\nThey have in on safari books online for reading:<br>\n<a href="http://my.safaribooksonline.com/9780321312839" rel="nofollow noreferrer">http://my.safaribooksonline.com/9780321312839</a></p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74392', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/11858/']
74,409
<p>I'm looking to create a "Countries You've Visited" map - just like the ones you've probably seen on Facebook, TravelAdvisor and whatnot.</p> <p>I've tried different flash kits, but they're not quite as advanced as I'd like them to be. The main problem I've encountered with all the different kits is changing the background color on a country when you click on it and have it keep that color when you "deselect" it. This is obviously necessary to give the user some visual feedback.</p> <p>The only way I've managed to do this so far is to initialize the flash through javascript with a huge XML string, have a click callback that interacts with Javascript, and with javascript alter the XML string using regular expressions, then send back the XML to the flash. It's pretty obvious that this method is FAR from optimal, and also very, very slow.</p> <p>I've tried FusionMaps, amMap, AnyMaps and diyMap and so far I've not found any way of doing this with either of them. If anyone has done anything similar with either of these, I'd really to know how :-)</p> <p>Does anyone have any pointers or suggestions on what I should look at? I'm starting to think that it would be a simpler (though less flexible) to just use the free SVG continent maps on Wikipedia, convert them to PNG and create an image map of all the countries - then use Canvas and VML to draw an element on top of the countries - but this just seems like a huge pain and very error-prone compared to a flash solution.</p> <p>Thanks for reading, and I hope someone has some pointers for me :-)</p> <ul> <li>Mr. Doom</li> </ul>
[{'answer_id': 74458, 'author': 'Grank', 'author_id': 12975, 'author_profile': 'https://Stackoverflow.com/users/12975', 'pm_score': 0, 'selected': False, 'text': "<p>If it will work for what you're building, Virtual Earth is in 6.1 these days and has a lot of excellent and easy-to-use javascript calls in the API to load polygons. If you have the point data that defines the countries (which should be freely available), you can easily define a VEShape polygon with an array of VELatLong objects, and toss an event handler on it to color them on click. The nice thing about VE is that the javascript API is really flexible and easy to use, and exposes a lot of nice mapping features.</p>\n"}, {'answer_id': 98810, 'author': 'Chris Pietschmann', 'author_id': 7831, 'author_profile': 'https://Stackoverflow.com/users/7831', 'pm_score': 0, 'selected': False, 'text': '<p>In case you are interested, there is an ASP.NET Virtual Earth Mapping Server Control here:</p>\n\n<p><a href="http://simplovation.com/page/webmapsve.aspx" rel="nofollow noreferrer">http://simplovation.com/page/webmapsve.aspx</a></p>\n\n<p>This is essentially a "wrapper" around Virtual Earth that abstracts out most (if not all) of the JavaScript that you would traditionally need to write. It allows you to handle map events and manipulate map events completely from server-side .NET code.</p>\n'}, {'answer_id': 415727, 'author': 'thenonhacker', 'author_id': 46915, 'author_profile': 'https://Stackoverflow.com/users/46915', 'pm_score': 1, 'selected': False, 'text': '<p>Try starting with Google Maps. If you want a good example of a website that uses Google Maps and put colored areas on it, visit <a href="http://Wikimapia.org" rel="nofollow noreferrer">Wikimapia.org</a>.</p>\n'}, {'answer_id': 471909, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>I was looking for the same thing, and then I found Google\'s Virtualization Intensity Map.\nYou can find more information <a href="http://code.google.com/apis/visualization/documentation/gallery/geomap.html" rel="nofollow noreferrer">here</a></p>\n'}, {'answer_id': 5755770, 'author': 'Waqar Alamgir', 'author_id': 457124, 'author_profile': 'https://Stackoverflow.com/users/457124', 'pm_score': 0, 'selected': False, 'text': '<p>Try this may be this what you expect\n<a href="http://www.ammap.com/" rel="nofollow">http://www.ammap.com/</a></p>\n'}, {'answer_id': 6014578, 'author': 'bjornd', 'author_id': 367960, 'author_profile': 'https://Stackoverflow.com/users/367960', 'pm_score': 2, 'selected': False, 'text': '<blockquote>\n <p>just seems like a huge pain and very error-prone</p>\n</blockquote>\n\n<p>I overcame the pain and fixed errors (ok, most of them). Here is the result: <a href="http://jvectormap.owl-hollow.net" rel="nofollow">jVectorMap</a></p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74409', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']
74,422
<p>Hi i want to write a game with a main game form and lot of other normal forms. What is the best way to manage update-paint cycle in that case?</p> <p>Should the game form paint loop only should be overriden? or should i do an application.do events() in the main method?</p> <p>Please guide me regarding this. i am new to windows forms world</p>
[{'answer_id': 74454, 'author': 'GEOCHET', 'author_id': 5640, 'author_profile': 'https://Stackoverflow.com/users/5640', 'pm_score': 1, 'selected': False, 'text': '<p>If you are making a game, you should be looking into <a href="http://msdn.microsoft.com/en-us/magazine/cc164112.aspx" rel="nofollow noreferrer">DirectX</a>, <a href="http://csgl.sourceforge.net/" rel="nofollow noreferrer">OpenGL</a>, or <a href="http://xna101.spaces.live.com/" rel="nofollow noreferrer">XNA</a>.</p>\n'}, {'answer_id': 74487, 'author': 'Michael Meadows', 'author_id': 7643, 'author_profile': 'https://Stackoverflow.com/users/7643', 'pm_score': 2, 'selected': True, 'text': '<p>Your logic thread should be separate from the form, so you won\'t need DoEvents(). If you\'re using GDI+, then you should force an Update() on a loop. Windows Forms doesn\'t do double buffering very well, so depending on how sophisticated your graphics will be you might have some difficulties with flicker.</p>\n\n<p>My suggestion is to look at using the <a href="http://msdn.microsoft.com/en-us/library/bb318659(VS.85).aspx" rel="nofollow noreferrer">DirectX managed library</a>. It\'s a lot to learn, but gives you everything you need.</p>\n\n<p><strong>EDIT:</strong>\nI have been reading recently about WPF, which seems like a much better platform for simple to moderately complex games, because it provides a much higher level API than the <a href="http://msdn.microsoft.com/en-us/library/bb318659(VS.85).aspx" rel="nofollow noreferrer">DirectX managed Library</a>. It probably has performance and flexibility limitations for more complex games, however.</p>\n'}, {'answer_id': 74500, 'author': 'Karg', 'author_id': 12685, 'author_profile': 'https://Stackoverflow.com/users/12685', 'pm_score': 2, 'selected': False, 'text': '<p>The body of the question doesn\'t mention Compact Framework, just Winforms. This is pretty much the accepted answer for Winforms from Tom Miller (Xna Game Studio and Managed DirectX guy from Microsoft):</p>\n\n<p><a href="http://blogs.msdn.com/tmiller/archive/2005/05/05/415008.aspx" rel="nofollow noreferrer">Winforms Game Loop</a></p>\n\n<p>@Rich B: The game loop is independent of how the rendering is done (DirectX, MDX, GDI+)</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74422', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13046/']
74,430
<p>I am trying to use the <code>import random</code> statement in python, but it doesn't appear to have any methods in it to use.</p> <p>Am I missing something?</p>
[{'answer_id': 74445, 'author': 'jamuraa', 'author_id': 9805, 'author_profile': 'https://Stackoverflow.com/users/9805', 'pm_score': 2, 'selected': False, 'text': '<p>I think you need to give some more information. It\'s not really possible to answer why it\'s not working based on the information in the question. The basic documentation for random is at: \n<a href="https://docs.python.org/library/random.html" rel="nofollow noreferrer">https://docs.python.org/library/random.html</a></p>\n\n<p>You might check there. </p>\n'}, {'answer_id': 74459, 'author': 'Chris AtLee', 'author_id': 4558, 'author_profile': 'https://Stackoverflow.com/users/4558', 'pm_score': 0, 'selected': False, 'text': "<p>Can you post an example of what you're trying to do? It's not clear from your question what the actual problem is.</p>\n\n<p>Here's an example of how to use the random module:</p>\n\n<pre><code>import random\nprint random.randint(0,10)\n</code></pre>\n"}, {'answer_id': 74476, 'author': 'Vinko Vrsalovic', 'author_id': 5190, 'author_profile': 'https://Stackoverflow.com/users/5190', 'pm_score': 1, 'selected': False, 'text': '<pre><code>Python 2.5.2 (r252:60911, Jun 16 2008, 18:27:58)\n[GCC 3.3.4 (pre 3.3.5 20040809)] on linux2\nType "help", "copyright", "credits" or "license" for more information.\n&gt;&gt;&gt; import random\n&gt;&gt;&gt; random.seed()\n&gt;&gt;&gt; dir(random)\n[\'BPF\', \'LOG4\', \'NV_MAGICCONST\', \'RECIP_BPF\', \'Random\', \'SG_MAGICCONST\', \'SystemRandom\', \'TWOPI\', \'WichmannHill\', \'_BuiltinMethodType\', \'_MethodType\', \'__all__\', \'__builtins__\', \'__doc__\', \'__file__\', \'__name__\', \'_acos\', \'_ceil\', \'_cos\', \'_e\', \'_exp\', \'_hexlify\', \'_inst\', \'_log\', \'_pi\', \'_random\', \'_sin\', \'_sqrt\', \'_test\', \'_test_generator\', \'_urandom\', \'_warn\', \'betavariate\', \'choice\', \'expovariate\', \'gammavariate\', \'gauss\', \'getrandbits\', \'getstate\', \'jumpahead\', \'lognormvariate\', \'normalvariate\', \'paretovariate\', \'randint\', \'random\', \'randrange\', \'sample\', \'seed\', \'setstate\', \'shuffle\', \'uniform\', \'vonmisesvariate\', \'weibullvariate\']\n&gt;&gt;&gt; random.randint(0,3)\n3\n&gt;&gt;&gt; random.randint(0,3)\n1\n&gt;&gt;&gt; \n</code></pre>\n'}, {'answer_id': 74485, 'author': 'Chris Bunch', 'author_id': 422, 'author_profile': 'https://Stackoverflow.com/users/422', 'pm_score': 0, 'selected': False, 'text': '<p>Seems to work fine for me. Check out the methods in the <a href="http://docs.python.org/lib/module-random.html" rel="nofollow noreferrer">official python documentation</a> for random:</p>\n\n<pre><code>&gt;&gt;&gt; import random\n&gt;&gt;&gt; random.random()\n0.69130806168332215\n&gt;&gt;&gt; random.uniform(1, 10)\n8.8384170917436293\n&gt;&gt;&gt; random.randint(1, 10)\n4\n</code></pre>\n'}, {'answer_id': 75360, 'author': 'Thomas Vander Stichele', 'author_id': 2900, 'author_profile': 'https://Stackoverflow.com/users/2900', 'pm_score': 0, 'selected': False, 'text': '<p>Works for me:</p>\n\n<pre><code>Python 2.5.1 (r251:54863, Jun 15 2008, 18:24:51) \n[GCC 4.3.0 20080428 (Red Hat 4.3.0-8)] on linux2\nType "help", "copyright", "credits" or "license" for more information.\n&gt;&gt;&gt; import random\n&gt;&gt;&gt; brothers = [\'larry\', \'curly\', \'moe\']\n&gt;&gt;&gt; random.choice(brothers)\n\'moe\'\n&gt;&gt;&gt; random.choice(brothers)\n\'curly\'\n</code></pre>\n'}, {'answer_id': 75427, 'author': 'Jerry Hill', 'author_id': 12773, 'author_profile': 'https://Stackoverflow.com/users/12773', 'pm_score': 6, 'selected': True, 'text': "<p>You probably have a file named random.py or random.pyc in your working directory. That's shadowing the built-in random module. You need to rename random.py to something like my_random.py and/or remove the random.pyc file.</p>\n\n<p>To tell for sure what's going on, do this:</p>\n\n<pre><code>&gt;&gt;&gt; import random\n&gt;&gt;&gt; print random.__file__\n</code></pre>\n\n<p>That will show you exactly which file is being imported.</p>\n"}, {'answer_id': 76404, 'author': 'tzot', 'author_id': 6899, 'author_profile': 'https://Stackoverflow.com/users/6899', 'pm_score': 1, 'selected': False, 'text': '<p>If the script you are trying to run is itself called random.py, then you would have a naming conflict. Choose a different name for your script.</p>\n'}, {'answer_id': 78304, 'author': 'Johan Dahlin', 'author_id': 14337, 'author_profile': 'https://Stackoverflow.com/users/14337', 'pm_score': 2, 'selected': False, 'text': "<p>This is happening because you have a random.py file in the python search path, most likely the current directory.</p>\n\n<p>Python is searching for modules using sys.path, which normally includes the current directory before the standard site-packages, which contains the expected random.py.</p>\n\n<p>This is expected to be fixed in Python 3.0, so that you can't import modules from the current directory without using a special import syntax.</p>\n\n<p>Just remove the random.py + random.pyc in the directory you're running python from and it'll work fine.</p>\n"}]
2008/09/16
['https://Stackoverflow.com/questions/74430', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13050/']
74,443
<p>What is the easiest way to manage the authorized_keys file for openssh across a large number of hosts? If I need to add or revoke a new key to an account on 10 hosts say, I must login and add the public key manually, or through a clumsy shell script, which is time consuming. </p> <p>Ideally there would be a central database linking keys to accounts@machines with some sort of grouping support (IE, add this key to username X on all servers in the web category). There's fork of SSH with ldap support, but I'd rather use the mainline SSH packages.</p>
[{'answer_id': 74523, 'author': 'JBB', 'author_id': 12332, 'author_profile': 'https://Stackoverflow.com/users/12332', 'pm_score': 0, 'selected': False, 'text': '<p>I\'ve always done this by maintaining a "master" tree of the different servers\' keys, and using rsync to update the remote machines. This lets you edit things in one location, push the changes out efficiently, and keeps things "up to date" -- everyone edits the master files, no one edits the files on random hosts.</p>\n\n<p>You may want to look at projects which are made for running commands across groups of machines, such as Func at <a href="https://fedorahosted.org/func" rel="nofollow noreferrer">https://fedorahosted.org/func</a> or other server configuration management packages. </p>\n'}, {'answer_id': 74538, 'author': 'Allan Wind', 'author_id': 9706, 'author_profile': 'https://Stackoverflow.com/users/9706', 'pm_score': 0, 'selected': False, 'text': '<p>Have you considered using clusterssh (or similar) to automate the file transfer? Another option is one of the centralized <a href="http://en.wikipedia.org/wiki/Comparison_of_open_source_configuration_management_software" rel="nofollow noreferrer">configuration systems</a>.</p>\n\n<p>/Allan</p>\n'}, {'answer_id': 74557, 'author': 'Chris AtLee', 'author_id': 4558, 'author_profile': 'https://Stackoverflow.com/users/4558', 'pm_score': 4, 'selected': True, 'text': '<p>I\'d checkout the <a href="http://web.monkeysphere.info/" rel="noreferrer">Monkeysphere</a> project. It uses OpenPGP\'s web of trust concepts to manage ssh\'s authorized_keys and known_hosts files, without requiring changes to the ssh client or server.</p>\n'}, {'answer_id': 5407319, 'author': 'Cristian Măgherușan-Stanciu', 'author_id': 673288, 'author_profile': 'https://Stackoverflow.com/users/673288', 'pm_score': 2, 'selected': False, 'text': '<p>I use Puppet for lots of things, including this.\n(using the ssh_authorized_key resource type)</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74443', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/11105/']
74,447
<p>If I attempt to connect to Mac OS X 10.5 Leopard's built in vnc server at a low color depth from Windows, the client bombs after connecting. It only works when I set it to the highest color depth. I've tried with at least 3 windows VNC clients. Any ideas? There some setting I can set in Mac OS X?</p> <p>It takes about 20 seconds to repaint the screen with my current connection and high bit depth setting.</p>
[{'answer_id': 74673, 'author': 'Ricardo Amores', 'author_id': 10136, 'author_profile': 'https://Stackoverflow.com/users/10136', 'pm_score': 2, 'selected': False, 'text': '<p>In my experience you can\'t lower the color depth with the default vnc server. I won\'t assert it, because maybe that behaviour could be changed using a console command.</p>\n\n<p>I\'d recommend installing another VNC server in mac, like <a href="http://sourceforge.net/projects/osxvnc/" rel="nofollow noreferrer">http://sourceforge.net/projects/osxvnc/</a></p>\n'}, {'answer_id': 74708, 'author': 'mike511', 'author_id': 9593, 'author_profile': 'https://Stackoverflow.com/users/9593', 'pm_score': 1, 'selected': False, 'text': '<p>The built-in vnc seems to have very little configurability that I can see.</p>\n\n<p>As an alternative, you can try using <a href="http://sourceforge.net/projects/osxvnc/" rel="nofollow noreferrer">osxvnc</a> which I believe allows different bit depths</p>\n'}, {'answer_id': 74811, 'author': 'Mason', 'author_id': 8973, 'author_profile': 'https://Stackoverflow.com/users/8973', 'pm_score': 3, 'selected': True, 'text': '<p>Not with the builtin VNC server. <a href="http://sourceforge.net/projects/osxvnc/" rel="nofollow noreferrer">Vine Server</a> allows you to change the bit depth that clients connect at though.</p>\n'}, {'answer_id': 4685235, 'author': 'user545125', 'author_id': 545125, 'author_profile': 'https://Stackoverflow.com/users/545125', 'pm_score': 0, 'selected': False, 'text': '<p>I use both. I find the built-in VNC server in OS X offers the most compatibility with keystrokes. I use it when I\'m on the local network. When using VPN (much slower), I setup Vine Server ("System Server" mode) on a non-standard port # (say 5905), with a much lower color resolution, so the screen doesn\'t take 30 seconds to redraw whenever I click something.</p>\n\n<p>Then I just ask my client to connect over the appropriate port: 5900 calls the built-in VNC server (for high rez use on the LAN), &amp; 5905 calls Vine Server (for screen update speed over VPN). Best of both worlds.</p>\n'}, {'answer_id': 5083959, 'author': 'Jeremy PYne', 'author_id': 629101, 'author_profile': 'https://Stackoverflow.com/users/629101', 'pm_score': 1, 'selected': False, 'text': '<p>You can from the client side switch to High Color(16 bits) but not Low Color(8 bits). You can also enable JPEG compression. With both of these options on the sessions speed of to me from completely unusable(~45s for initial screen draw and ~5s lag on clicking menus) to quite usable(&lt;5s for initial screen draw and &lt;1s lag on clicking menus).</p>\n\n<p>Note that these times are for connecting from a remote computer to my home iMac on a cable modem. Also this is running dual screens witch get sent out even though I only use the primary one on VNC. I have yet to figure out a way to switch off the secondary screen in VNC and its to troublesome to unplug it.</p>\n'}, {'answer_id': 10485417, 'author': 'Mark Richman', 'author_id': 134484, 'author_profile': 'https://Stackoverflow.com/users/134484', 'pm_score': 0, 'selected': False, 'text': "<p>I gave up and started using LogMeIn's free edition.</p>\n"}]
2008/09/16
['https://Stackoverflow.com/questions/74447', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5885/']
74,451
<p>Windows file system is case insensitive. How, given a file/folder name (e.g. "somefile"), I get the <em>actual</em> name of that file/folder (e.g. it should return "SomeFile" if Explorer displays it so)?</p> <p>Some ways I know, all of which seem quite backwards:</p> <ol> <li>Given the full path, search for each folder on the path (via FindFirstFile). This gives proper cased results of each folder. At the last step, search for the file itself.</li> <li>Get filename from handle (as in <a href="http://msdn.microsoft.com/en-us/library/aa366789(VS.85).aspx" rel="noreferrer">MSDN example</a>). This requires opening a file, creating file mapping, getting it's name, parsing device names etc. Pretty convoluted. And it does not work for folders or zero-size files.</li> </ol> <p>Am I missing some obvious WinAPI call? The simplest ones, like GetActualPathName() or GetFullPathName() return the name using casing that was passed in (e.g. returns "program files" if that was passed in, even if it should be "Program Files").</p> <p>I'm looking for a native solution (not .NET one).</p>
[{'answer_id': 74563, 'author': 'bugmagnet', 'author_id': 426, 'author_profile': 'https://Stackoverflow.com/users/426', 'pm_score': 2, 'selected': False, 'text': '<p>Okay, this is VBScript, but even so I\'d suggest using the Scripting.FileSystemObject object</p>\n\n<pre><code>Dim fso\nSet fso = CreateObject("Scripting.FileSystemObject")\nDim f\nSet f = fso.GetFile("C:\\testfile.dat") \'actually named "testFILE.dAt"\nwscript.echo f.Name\n</code></pre>\n\n<p>The response I get is from this snippet is </p>\n\n<pre><code>testFILE.dAt\n</code></pre>\n\n<p>Hope that at least points you in the right direction.</p>\n'}, {'answer_id': 74588, 'author': 'cspirz', 'author_id': 8352, 'author_profile': 'https://Stackoverflow.com/users/8352', 'pm_score': 2, 'selected': False, 'text': '<p>Have you tried using <a href="http://msdn.microsoft.com/en-us/library/bb762179(VS.85).aspx" rel="nofollow noreferrer">SHGetFileInfo?</a></p>\n'}, {'answer_id': 74589, 'author': 'Adam Rosenfield', 'author_id': 9530, 'author_profile': 'https://Stackoverflow.com/users/9530', 'pm_score': -1, 'selected': False, 'text': '<p>After a quick test, <a href="http://msdn.microsoft.com/en-us/library/aa364980(VS.85).aspx" rel="nofollow noreferrer">GetLongPathName()</a> does what you want.</p>\n'}, {'answer_id': 81493, 'author': 'NeARAZ', 'author_id': 6799, 'author_profile': 'https://Stackoverflow.com/users/6799', 'pm_score': 4, 'selected': True, 'text': '<p>And hereby I answer my own question, based on <a href="https://stackoverflow.com/questions/74451/getting-actual-file-name-with-proper-casing-on-windows#74588">original answer from <em>cspirz</em></a>.</p>\n\n<p>Here\'s a function that given absolute, relative or network path, will return the path with upper/lower case as it would be displayed on Windows. If some component of the path does not exist, it will return the passed in path from that point.</p>\n\n<p>It is quite involved because it tries to handle network paths and other edge cases. It operates on wide character strings and uses std::wstring. Yes, in theory Unicode TCHAR could be not the same as wchar_t; that is an exercise for the reader :)</p>\n\n<pre><code>std::wstring GetActualPathName( const wchar_t* path )\n{\n // This is quite involved, but the meat is SHGetFileInfo\n\n const wchar_t kSeparator = L\'\\\\\';\n\n // copy input string because we\'ll be temporary modifying it in place\n size_t length = wcslen(path);\n wchar_t buffer[MAX_PATH];\n memcpy( buffer, path, (length+1) * sizeof(path[0]) );\n\n size_t i = 0;\n\n std::wstring result;\n\n // for network paths (\\\\server\\share\\RestOfPath), getting the display\n // name mangles it into unusable form (e.g. "\\\\server\\share" turns\n // into "share on server (server)"). So detect this case and just skip\n // up to two path components\n if( length &gt;= 2 &amp;&amp; buffer[0] == kSeparator &amp;&amp; buffer[1] == kSeparator )\n {\n int skippedCount = 0;\n i = 2; // start after \'\\\\\'\n while( i &lt; length &amp;&amp; skippedCount &lt; 2 )\n {\n if( buffer[i] == kSeparator )\n ++skippedCount;\n ++i;\n }\n\n result.append( buffer, i );\n }\n // for drive names, just add it uppercased\n else if( length &gt;= 2 &amp;&amp; buffer[1] == L\':\' )\n {\n result += towupper(buffer[0]);\n result += L\':\';\n if( length &gt;= 3 &amp;&amp; buffer[2] == kSeparator )\n {\n result += kSeparator;\n i = 3; // start after drive, colon and separator\n }\n else\n {\n i = 2; // start after drive and colon\n }\n }\n\n size_t lastComponentStart = i;\n bool addSeparator = false;\n\n while( i &lt; length )\n {\n // skip until path separator\n while( i &lt; length &amp;&amp; buffer[i] != kSeparator )\n ++i;\n\n if( addSeparator )\n result += kSeparator;\n\n // if we found path separator, get real filename of this\n // last path name component\n bool foundSeparator = (i &lt; length);\n buffer[i] = 0;\n SHFILEINFOW info;\n\n // nuke the path separator so that we get real name of current path component\n info.szDisplayName[0] = 0;\n if( SHGetFileInfoW( buffer, 0, &amp;info, sizeof(info), SHGFI_DISPLAYNAME ) )\n {\n result += info.szDisplayName;\n }\n else\n {\n // most likely file does not exist.\n // So just append original path name component.\n result.append( buffer + lastComponentStart, i - lastComponentStart );\n }\n\n // restore path separator that we might have nuked before\n if( foundSeparator )\n buffer[i] = kSeparator;\n\n ++i;\n lastComponentStart = i;\n addSeparator = true;\n }\n\n return result;\n}\n</code></pre>\n\n<p>Again, thanks to cspirz for pointing me to SHGetFileInfo.</p>\n'}, {'answer_id': 5452625, 'author': 'sergioko', 'author_id': 679366, 'author_profile': 'https://Stackoverflow.com/users/679366', 'pm_score': 2, 'selected': False, 'text': '<p>There is another solution. First call GetShortPathName() and then GetLongPathName(). Guess what character case will be used then? ;-)</p>\n'}, {'answer_id': 32892823, 'author': 'Doub', 'author_id': 67432, 'author_profile': 'https://Stackoverflow.com/users/67432', 'pm_score': 0, 'selected': False, 'text': '<p><a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa364421(v=vs.85).aspx" rel="nofollow">FindFirstFileNameW</a> will work with a few drawbacks:</p>\n\n<ul>\n<li>it doesn\'t work on UNC paths</li>\n<li>it strips the drive letter so you need to add it back</li>\n<li>if there are more than one hard link to your file you need to identify the right one</li>\n</ul>\n'}, {'answer_id': 47353320, 'author': 'raymai97', 'author_id': 1261956, 'author_profile': 'https://Stackoverflow.com/users/1261956', 'pm_score': 1, 'selected': False, 'text': '<p>Just found that the <code>Scripting.FileSystemObject</code> suggested by @bugmagnet 10 years ago is a treasure. Unlike my old method, it works on Absolute Path, Relative Path, UNC Path and Very Long Path (path longer than <code>MAX_PATH</code>). Shame on me for not testing his method earlier.</p>\n\n<p>For future reference, I would like to present this code which can be compiled in both C and C++ mode. In C++ mode, the code will use STL and ATL. In C mode, you can clearly see how everything is working behind the scene.</p>\n\n<pre><code>#include &lt;Windows.h&gt;\n#include &lt;objbase.h&gt;\n#include &lt;conio.h&gt; // for _getch()\n\n#ifndef __cplusplus\n# include &lt;stdio.h&gt;\n\n#define SafeFree(p, fn) \\\n if (p) { fn(p); (p) = NULL; }\n\n#define SafeFreeCOM(p) \\\n if (p) { (p)-&gt;lpVtbl-&gt;Release(p); (p) = NULL; }\n\n\nstatic HRESULT CorrectPathCasing2(\n LPCWSTR const pszSrc, LPWSTR *ppszDst)\n{\n DWORD const clsCtx = CLSCTX_INPROC_SERVER;\n LCID const lcid = LOCALE_USER_DEFAULT;\n LPCWSTR const pszProgId = L"Scripting.FileSystemObject";\n LPCWSTR const pszMethod = L"GetAbsolutePathName";\n HRESULT hr = 0;\n CLSID clsid = { 0 };\n IDispatch *pDisp = NULL;\n DISPID dispid = 0;\n VARIANT vtSrc = { VT_BSTR };\n VARIANT vtDst = { VT_BSTR };\n DISPPARAMS params = { 0 };\n SIZE_T cbDst = 0;\n LPWSTR pszDst = NULL;\n\n // CoCreateInstance&lt;IDispatch&gt;(pszProgId, &amp;pDisp)\n\n hr = CLSIDFromProgID(pszProgId, &amp;clsid);\n if (FAILED(hr)) goto eof;\n\n hr = CoCreateInstance(&amp;clsid, NULL, clsCtx,\n &amp;IID_IDispatch, (void**)&amp;pDisp);\n if (FAILED(hr)) goto eof;\n if (!pDisp) {\n hr = E_UNEXPECTED; goto eof;\n }\n\n // Variant&lt;BSTR&gt; vtSrc(pszSrc), vtDst;\n // vtDst = pDisp-&gt;InvokeMethod( pDisp-&gt;GetIDOfName(pszMethod), vtSrc );\n\n hr = pDisp-&gt;lpVtbl-&gt;GetIDsOfNames(pDisp, NULL,\n (LPOLESTR*)&amp;pszMethod, 1, lcid, &amp;dispid);\n if (FAILED(hr)) goto eof;\n\n vtSrc.bstrVal = SysAllocString(pszSrc);\n if (!vtSrc.bstrVal) {\n hr = E_OUTOFMEMORY; goto eof;\n }\n params.rgvarg = &amp;vtSrc;\n params.cArgs = 1;\n hr = pDisp-&gt;lpVtbl-&gt;Invoke(pDisp, dispid, NULL, lcid,\n DISPATCH_METHOD, &amp;params, &amp;vtDst, NULL, NULL);\n if (FAILED(hr)) goto eof;\n if (!vtDst.bstrVal) {\n hr = E_UNEXPECTED; goto eof;\n }\n\n // *ppszDst = AllocWStrCopyBStrFrom(vtDst.bstrVal);\n\n cbDst = SysStringByteLen(vtDst.bstrVal);\n pszDst = HeapAlloc(GetProcessHeap(),\n HEAP_ZERO_MEMORY, cbDst + sizeof(WCHAR));\n if (!pszDst) {\n hr = E_OUTOFMEMORY; goto eof;\n }\n CopyMemory(pszDst, vtDst.bstrVal, cbDst);\n *ppszDst = pszDst;\n\neof:\n SafeFree(vtDst.bstrVal, SysFreeString);\n SafeFree(vtSrc.bstrVal, SysFreeString);\n SafeFreeCOM(pDisp);\n return hr;\n}\n\nstatic void Cout(char const *psz)\n{\n printf("%s", psz);\n}\n\nstatic void CoutErr(HRESULT hr)\n{\n printf("Error HRESULT 0x%.8X!\\n", hr);\n}\n\nstatic void Test(LPCWSTR pszPath)\n{\n LPWSTR pszRet = NULL;\n HRESULT hr = CorrectPathCasing2(pszPath, &amp;pszRet);\n if (FAILED(hr)) {\n wprintf(L"Input: &lt;%s&gt;\\n", pszPath);\n CoutErr(hr);\n }\n else {\n wprintf(L"Was: &lt;%s&gt;\\nNow: &lt;%s&gt;\\n", pszPath, pszRet);\n HeapFree(GetProcessHeap(), 0, pszRet);\n }\n}\n\n\n#else // Use C++ STL and ATL\n# include &lt;iostream&gt;\n# include &lt;iomanip&gt;\n# include &lt;string&gt;\n# include &lt;atlbase.h&gt;\n\nstatic HRESULT CorrectPathCasing2(\n std::wstring const &amp;srcPath,\n std::wstring &amp;dstPath)\n{\n HRESULT hr = 0;\n CComPtr&lt;IDispatch&gt; disp;\n hr = disp.CoCreateInstance(L"Scripting.FileSystemObject");\n if (FAILED(hr)) return hr;\n\n CComVariant src(srcPath.c_str()), dst;\n hr = disp.Invoke1(L"GetAbsolutePathName", &amp;src, &amp;dst);\n if (FAILED(hr)) return hr;\n\n SIZE_T cch = SysStringLen(dst.bstrVal);\n dstPath = std::wstring(dst.bstrVal, cch);\n return hr;\n}\n\nstatic void Cout(char const *psz)\n{\n std::cout &lt;&lt; psz;\n}\n\nstatic void CoutErr(HRESULT hr)\n{\n std::wcout\n &lt;&lt; std::hex &lt;&lt; std::setfill(L\'0\') &lt;&lt; std::setw(8)\n &lt;&lt; "Error HRESULT 0x" &lt;&lt; hr &lt;&lt; "\\n";\n}\n\nstatic void Test(std::wstring const &amp;path)\n{\n std::wstring output;\n HRESULT hr = CorrectPathCasing2(path, output);\n if (FAILED(hr)) {\n std::wcout &lt;&lt; L"Input: &lt;" &lt;&lt; path &lt;&lt; "&gt;\\n";\n CoutErr(hr);\n }\n else {\n std::wcout &lt;&lt; L"Was: &lt;" &lt;&lt; path &lt;&lt; "&gt;\\n"\n &lt;&lt; "Now: &lt;" &lt;&lt; output &lt;&lt; "&gt;\\n";\n }\n}\n\n#endif\n\n\nstatic void TestRoutine(void)\n{\n HRESULT hr = CoInitialize(NULL);\n\n if (FAILED(hr)) {\n Cout("CoInitialize failed!\\n");\n CoutErr(hr);\n return;\n }\n\n Cout("\\n[ Absolute Path ]\\n");\n Test(L"c:\\\\uSers\\\\RayMai\\\\docuMENTs");\n Test(L"C:\\\\WINDOWS\\\\SYSTEM32");\n\n Cout("\\n[ Relative Path ]\\n");\n Test(L".");\n Test(L"..");\n Test(L"\\\\");\n\n Cout("\\n[ UNC Path ]\\n");\n Test(L"\\\\\\\\VMWARE-HOST\\\\SHARED FOLDERS\\\\D\\\\PROGRAMS INSTALLER");\n\n Cout("\\n[ Very Long Path ]\\n");\n Test(L"\\\\\\\\?\\\\C:\\\\VERYVERYVERYLOOOOOOOONGFOLDERNAME\\\\"\n L"VERYVERYVERYLOOOOOOOONGFOLDERNAME\\\\"\n L"VERYVERYVERYLOOOOOOOONGFOLDERNAME\\\\"\n L"VERYVERYVERYLOOOOOOOONGFOLDERNAME\\\\"\n L"VERYVERYVERYLOOOOOOOONGFOLDERNAME\\\\"\n L"VERYVERYVERYLOOOOOOOONGFOLDERNAME\\\\"\n L"VERYVERYVERYLOOOOOOOONGFOLDERNAME\\\\"\n L"VERYVERYVERYLOOOOOOOONGFOLDERNAME\\\\"\n L"VERYVERYVERYLOOOOOOOONGFOLDERNAME");\n\n Cout("\\n!! Worth Nothing Behavior !!\\n");\n Test(L"");\n Test(L"1234notexist");\n Test(L"C:\\\\bad\\\\PATH");\n\n CoUninitialize();\n}\n\nint main(void)\n{\n TestRoutine();\n _getch();\n return 0;\n}\n</code></pre>\n\n<p>Screenshot:</p>\n\n<p><a href="https://i.stack.imgur.com/goDre.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/goDre.png" alt="screenshot2"></a></p>\n\n<hr>\n\n<p>Old Answer:</p>\n\n<p>I found that <code>FindFirstFile()</code> will return the proper casing file name (last part of path) in <code>fd.cFileName</code>. If we pass <code>c:\\winDOWs\\exPLORER.exe</code> as first parameter to <code>FindFirstFile()</code>, the <code>fd.cFileName</code> would be <code>explorer.exe</code> like this:</p>\n\n<p><a href="https://i.stack.imgur.com/3ihE5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3ihE5.png" alt="prove"></a></p>\n\n<p>If we replace the last part of path with <code>fd.cFileName</code>, we will get the last part right; the path would become <code>c:\\winDOWs\\explorer.exe</code>.</p>\n\n<p>Assuming the path is always absolute path (no change in text length), we can just apply this \'algorithm\' to every part of path (except the drive letter part). </p>\n\n<p>Talk is cheap, here is the code:</p>\n\n<pre><code>#include &lt;windows.h&gt;\n#include &lt;stdio.h&gt;\n\n/*\n c:\\windows\\windowsupdate.log --&gt; c:\\windows\\WindowsUpdate.log\n*/\nstatic HRESULT MyProcessLastPart(LPTSTR szPath)\n{\n HRESULT hr = 0;\n HANDLE hFind = NULL;\n WIN32_FIND_DATA fd = {0};\n TCHAR *p = NULL, *q = NULL;\n /* thePart = GetCorrectCasingFileName(thePath); */\n hFind = FindFirstFile(szPath, &amp;fd);\n if (hFind == INVALID_HANDLE_VALUE) {\n hr = HRESULT_FROM_WIN32(GetLastError());\n hFind = NULL; goto eof;\n }\n /* thePath = thePath.ReplaceLast(thePart); */\n for (p = szPath; *p; ++p);\n for (q = fd.cFileName; *q; ++q, --p);\n for (q = fd.cFileName; *p = *q; ++p, ++q);\neof:\n if (hFind) { FindClose(hFind); }\n return hr;\n}\n\n/*\n Important! \'szPath\' should be absolute path only.\n MUST NOT SPECIFY relative path or UNC or short file name.\n*/\nEXTERN_C\nHRESULT __stdcall\nCorrectPathCasing(\n LPTSTR szPath)\n{\n HRESULT hr = 0;\n TCHAR *p = NULL;\n if (GetFileAttributes(szPath) == -1) {\n hr = HRESULT_FROM_WIN32(GetLastError()); goto eof;\n }\n for (p = szPath; *p; ++p)\n {\n if (*p == \'\\\\\' || *p == \'/\')\n {\n TCHAR slashChar = *p;\n if (p[-1] == \':\') /* p[-2] is drive letter */\n {\n p[-2] = toupper(p[-2]);\n continue;\n }\n *p = \'\\0\';\n hr = MyProcessLastPart(szPath);\n *p = slashChar;\n if (FAILED(hr)) goto eof;\n }\n }\n hr = MyProcessLastPart(szPath);\neof:\n return hr;\n}\n\nint main()\n{\n TCHAR szPath[] = TEXT("c:\\\\windows\\\\EXPLORER.exe");\n HRESULT hr = CorrectPathCasing(szPath);\n if (SUCCEEDED(hr))\n {\n MessageBox(NULL, szPath, TEXT("Test"), MB_ICONINFORMATION);\n }\n return 0;\n}\n</code></pre>\n\n<p><a href="https://i.stack.imgur.com/vYAcH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vYAcH.png" alt="prove 2"></a></p>\n\n<p>Advantages:</p>\n\n<ul>\n<li>The code works on every version of Windows since Windows 95.</li>\n<li>Basic error-handling.</li>\n<li>Highest performance possible. <code>FindFirstFile()</code> is very fast, direct buffer manipulation makes it even faster.</li>\n<li>Just C and pure WinAPI. Small executable size.</li>\n</ul>\n\n<p>Disadvantages:</p>\n\n<ul>\n<li>Only absolute path is supported, other are undefined behavior.</li>\n<li>Not sure if it is relying on undocumented behavior.</li>\n<li>The code might be too raw too much DIY for some people. Might get you flamed.</li>\n</ul>\n\n<p>Reason behind the code style:</p>\n\n<p>I use <code>goto</code> for error-handling because I was used to it (<code>goto</code> is very handy for error-handling in C). I use <code>for</code> loop to perform functions like <code>strcpy</code> and <code>strchr</code> on-the-fly because I want to be certain what was actually executed.</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74451', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/6799/']
74,461
<p>I'm currently playing with the Silverlight(Beta 2) Datagrid control. Before I wired up the SelectionChanged event, the grid would sort perfectly by clicking on the header. Now, when the grid is clicked, it will fire the SelectionChanged event when I click the header to sort. Is there any way around this?</p> <p>In a semi-related topic, I'd like to have the SelectionChanged event fire when I click on an already selected item (so that I can have a pop-up occur to allow the user to edit the selected value). Right now, you have to click on a different value and then back to the value you wanted in order for it to pop up. Is there another way? </p> <p>Included is my code. </p> <p>The Page:</p> <pre><code>&lt;UserControl x:Class="WebServicesApp.Page" xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" Width="1280" Height="1024" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"&gt; &lt;Grid x:Name="LayoutRoot" Background="White"&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition /&gt; &lt;RowDefinition /&gt; &lt;/Grid.RowDefinitions&gt; &lt;StackPanel Grid.Row="0" x:Name="OurStack" Orientation="Vertical" Margin="5,5,5,5"&gt; &lt;ContentControl VerticalAlignment="Center" HorizontalAlignment="Center"&gt; &lt;StackPanel x:Name="SearchStackPanel" Orientation="Horizontal" Margin="5,5,5,5"&gt; &lt;TextBlock x:Name="SearchEmail" HorizontalAlignment="Stretch" VerticalAlignment="Center" Text="Email Address:" Margin="5,5,5,5" /&gt; &lt;TextBox x:Name="InputText" HorizontalAlignment="Stretch" VerticalAlignment="Center" Width="150" Height="Auto" Margin="5,5,5,5"/&gt; &lt;Button x:Name="SearchButton" Content="Search" Click="CallServiceButton_Click" HorizontalAlignment="Center" VerticalAlignment="Center" Width="75" Height="Auto" Background="#FFAFAFAF" Margin="5,5,5,5"/&gt; &lt;/StackPanel&gt; &lt;/ContentControl&gt; &lt;Grid x:Name="DisplayRoot" Background="White" ShowGridLines="True" HorizontalAlignment="Center" VerticalAlignment="Center" MaxHeight="300" MinHeight="100" MaxWidth="800" MinWidth="200" ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.VerticalScrollBarVisibility="Visible"&gt; &lt;data:DataGrid ItemsSource="{Binding ''}" CanUserReorderColumns="False" CanUserResizeColumns="False" AutoGenerateColumns="False" AlternatingRowBackground="#FFAFAFAF" SelectionMode="Single" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="5,5,5,5" x:Name="IncidentGrid" SelectionChanged="IncidentGrid_SelectionChanged"&gt; &lt;data:DataGrid.Columns&gt; &lt;data:DataGridTextColumn DisplayMemberBinding="{Binding Address}" Header="Email Address" IsReadOnly="True" /&gt; &lt;!--Width="150"--&gt; &lt;data:DataGridTextColumn DisplayMemberBinding="{Binding whereClause}" Header="Where Clause" IsReadOnly="True" /&gt; &lt;!--Width="500"--&gt; &lt;data:DataGridTextColumn DisplayMemberBinding="{Binding Enabled}" Header="Enabled" IsReadOnly="True" /&gt; &lt;/data:DataGrid.Columns&gt; &lt;/data:DataGrid&gt; &lt;/Grid&gt; &lt;/StackPanel&gt; &lt;Grid x:Name="EditPersonPopupGrid" Visibility="Collapsed"&gt; &lt;Rectangle HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Opacity="0.765" Fill="#FF8A8A8A" /&gt; &lt;Border CornerRadius="30" Background="#FF2D1DCC" Width="700" Height="400" HorizontalAlignment="Center" VerticalAlignment="Center" BorderThickness="1,1,1,1" BorderBrush="#FF000000"&gt; &lt;StackPanel x:Name="EditPersonStackPanel" Orientation="Vertical" Background="White" HorizontalAlignment="Center" VerticalAlignment="Center" Width="650" &gt; &lt;ContentControl&gt; &lt;StackPanel x:Name="EmailEditStackPanel" Orientation="Horizontal"&gt; &lt;TextBlock Text="Email Address:" Width="200" Margin="5,0,5,0" /&gt; &lt;TextBox x:Name="EmailPopupTextBox" Width="200" /&gt; &lt;/StackPanel&gt; &lt;/ContentControl&gt; &lt;ContentControl&gt; &lt;StackPanel x:Name="AppliesToDropdownStackPanel" Orientation="Horizontal" Margin="2,2,2,0"&gt; &lt;TextBlock Text="Don't send when update was done by:" /&gt; &lt;StackPanel Orientation="Vertical" MaxHeight="275" MaxWidth="350" &gt; &lt;TextBlock x:Name="SelectedItemTextBlock" TextAlignment="Right" Width="200" Margin="5,0,5,0" /&gt; &lt;Grid x:Name="UserDropDownGrid" MaxHeight="75" MaxWidth="200" Visibility="Collapsed" ScrollViewer.VerticalScrollBarVisibility="Visible" ScrollViewer.HorizontalScrollBarVisibility="Hidden" &gt; &lt;Rectangle Fill="White" /&gt; &lt;Border Background="White"&gt; &lt;ListBox x:Name="UsersListBox" SelectionChanged="UsersListBox_SelectionChanged" ItemsSource="{Binding UserID}" /&gt; &lt;/Border&gt; &lt;/Grid&gt; &lt;/StackPanel&gt; &lt;Button x:Name="DropDownButton" Click="DropDownButton_Click" VerticalAlignment="Top" Width="25" Height="25"&gt; &lt;Path Height="10" Width="10" Fill="#FF000000" Stretch="Fill" Stroke="#FF000000" Data="M514.66669,354 L542.16669,354 L527.74988,368.41684 z" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="1,1,1,1"/&gt; &lt;/Button&gt; &lt;/StackPanel&gt; &lt;/ContentControl&gt; &lt;TextBlock Text="Where Clause Condition:" /&gt; &lt;TextBox x:Name="WhereClauseTextBox" Height="200" Width="800" AcceptsReturn="True" TextWrapping="Wrap" /&gt; &lt;ContentControl&gt; &lt;StackPanel Orientation="Vertical"&gt; &lt;StackPanel Orientation="Horizontal"&gt; &lt;Button x:Name="TestConditionButton" Content="Test Condition" Margin="5,5,5,5" Click="TestConditionButton_Click" /&gt; &lt;Button x:Name="Save" Content="Save" HorizontalAlignment="Right" Margin="5,5,5,5" Click="Save_Click" /&gt; &lt;Button x:Name="Cancel" Content="Cancel" HorizontalAlignment="Right" Margin="5,5,5,5" Click="Cancel_Click" /&gt; &lt;/StackPanel&gt; &lt;TextBlock x:Name="TestContitionResults" Visibility="Collapsed" /&gt; &lt;/StackPanel&gt; &lt;/ContentControl&gt; &lt;/StackPanel&gt; &lt;/Border&gt; &lt;/Grid&gt; &lt;/Grid&gt; </code></pre> <p></p> <p>And the call that occurs when the grid's selection is changed:</p> <pre><code>Private Sub IncidentGrid_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) If mFirstTime Then mFirstTime = False Else Dim data As SimpleASMX.EMailMonitor = CType(IncidentGrid.SelectedItem, SimpleASMX.EMailMonitor) Dim selectedGridItem As SimpleASMX.EMailMonitor = Nothing If IncidentGrid.SelectedItem IsNot Nothing Then selectedGridItem = CType(IncidentGrid.SelectedItem, SimpleASMX.EMailMonitor) EmailPopupTextBox.Text = selectedGridItem.Address SelectedItemTextBlock.Text = selectedGridItem.AppliesToUserID WhereClauseTextBox.Text = selectedGridItem.whereClause IncidentGrid.SelectedIndex = mEmailMonitorData.IndexOf(selectedGridItem) End If If IncidentGrid.SelectedIndex &gt; -1 Then EditPersonPopupGrid.Visibility = Windows.Visibility.Visible Else EditPersonPopupGrid.Visibility = Windows.Visibility.Collapsed End If End If End Sub </code></pre> <p>Sorry if my code is atrocious, I'm still learning Silverlight.</p>
[{'answer_id': 74877, 'author': 'Senkwe', 'author_id': 6419, 'author_profile': 'https://Stackoverflow.com/users/6419', 'pm_score': 3, 'selected': True, 'text': '<p>That looks like a Silverlight bug to me. I\'ve just tried it and what\'s happening on my end is that the <strong>SelectionChanged</strong> event fires twice when you click the column header and to make matters worse, the index of the selected item doesn\'t stay synched with the currently selected item.</p>\n\n<p>I\'d suggest you work your way around it by using the knowledge that the first time SelectionChanged fires, the value of the datagrid\'s <strong>SelectedItem</strong> property will be <strong>null</strong></p>\n\n<p>Here\'s some sample code that at least lives with the issue. Your <strong>SelectionChanged</strong> logic can go in the <strong>if</strong> clause.</p>\n\n<pre><code>public partial class Page : UserControl\n{\n private Person _currentSelectedPerson;\n\n public Page()\n {\n InitializeComponent();\n\n List&lt;Person&gt; persons = new List&lt;Person&gt;();\n persons.Add(new Person() { Age = 5, Name = "Tom" });\n persons.Add(new Person() { Age = 3, Name = "Lisa" });\n persons.Add(new Person() { Age = 4, Name = "Sam" });\n\n dg.ItemsSource = persons;\n } \n\n private void SelectionChanged(object sender, EventArgs e)\n {\n DataGrid grid = sender as DataGrid;\n if (grid.SelectedItem != null)\n {\n _currentSelectedPerson = grid.SelectedItem as Person;\n }\n else\n {\n grid.SelectedItem = _currentSelectedPerson;\n }\n }\n }\n\npublic class Person\n{\n public string Name { get; set; }\n public int Age { get; set; }\n}\n</code></pre>\n'}, {'answer_id': 76586, 'author': 'Rob', 'author_id': 12413, 'author_profile': 'https://Stackoverflow.com/users/12413', 'pm_score': 0, 'selected': False, 'text': "<p>This worked, but now if I sort twice, on the first one it sorts, and then does the popup as the first selected item of the grid . If I close the popup grid, and then try to sort a second time, it stack overflows, and crashes firefox out.</p>\n\n<p>I'm thinking I may need to rethink working in silverlight until the system gets a bit more stable.</p>\n\n<p>Thanks for the answer Hovito!</p>\n"}, {'answer_id': 498801, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>Frozen Columns in Silverlight DataGrid..</p>\n\n<p><a href="http://dotnetdreamer.wordpress.com/2009/01/31/silverlight-2-datagrid-frozen-columns/" rel="nofollow noreferrer">http://dotnetdreamer.wordpress.com/2009/01/31/silverlight-2-datagrid-frozen-columns/</a></p>\n'}, {'answer_id': 592048, 'author': 'Matthew Timbs', 'author_id': 21343, 'author_profile': 'https://Stackoverflow.com/users/21343', 'pm_score': 1, 'selected': False, 'text': '<p>There\'s a bugfix for the first issue you mentioned (selection changed event getting fired on resort).</p>\n\n<p>See the following URL for Microsoft\'s patch:</p>\n\n<p><a href="http://www.microsoft.com/downloads/details.aspx?familyid=084A1BB2-0078-4009-94EE-E659C6409DB0&amp;displaylang=en" rel="nofollow noreferrer">http://www.microsoft.com/downloads/details.aspx?familyid=084A1BB2-0078-4009-94EE-E659C6409DB0&amp;displaylang=en</a></p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74461', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12413/']
74,466
<p>I have a .ico file that is embedded as a resource (build action set to resource). I am trying to create a NotifyIcon. How can I reference my icon?</p> <pre><code>notifyIcon = new NotifyIcon(); notifyIcon.Icon = ?? // my icon file is called MyIcon.ico and is embedded </code></pre>
[{'answer_id': 74671, 'author': 'user13125', 'author_id': 13125, 'author_profile': 'https://Stackoverflow.com/users/13125', 'pm_score': 8, 'selected': True, 'text': '<p>Your icon file should be added to one of your project assemblies and its Build Action should be set to Resource. After adding a reference to the assembly, you can create a NotifyIcon like this:</p>\n\n<pre><code>System.Windows.Forms.NotifyIcon icon = new System.Windows.Forms.NotifyIcon();\nStream iconStream = Application.GetResourceStream( new Uri( "pack://application:,,,/YourReferencedAssembly;component/YourPossibleSubFolder/YourResourceFile.ico" )).Stream;\nicon.Icon = new System.Drawing.Icon( iconStream );\n</code></pre>\n'}, {'answer_id': 74679, 'author': 'Jaykul', 'author_id': 8718, 'author_profile': 'https://Stackoverflow.com/users/8718', 'pm_score': 4, 'selected': False, 'text': '<p>Well, you don\'t want to use the resx style resources: you just stick the ico file in your project in a folder (lets say "ArtWork") and in the properties, set the Build Action to "Resources" ...</p>\n\n<p>Then you can reference it in XAML using PACK URIs ... "pack://application:,,,/Artwork/Notify.ico"</p>\n\n<p>See here: <a href="http://msdn.microsoft.com/en-us/library/aa970069.aspx#Programming_with_Pack_URIs" rel="noreferrer">http://msdn.microsoft.com/en-us/library/aa970069.aspx</a> and the <a href="http://msdn.microsoft.com/en-us/library/aa972152.aspx" rel="noreferrer">sample</a></p>\n\n<p>If you want to be a little bit more ... WPF-like, you should look into the <a href="http://www.codeplex.com/wpfcontrib/Wiki/View.aspx?title=NotifyIcon&amp;referringTitle=Home" rel="noreferrer">WPF Contrib</a> project on CodePlex which has a NotifyIcon control which you can create in XAML and which uses standard WPF menus (so you can stick "anything" in the menu).</p>\n'}, {'answer_id': 75049, 'author': 'shinybluesphere', 'author_id': 10282, 'author_profile': 'https://Stackoverflow.com/users/10282', 'pm_score': 2, 'selected': False, 'text': '<p>I created a project here and used an embedded resource (build action was set to Embedded Resource, rather than just resource). This solution doesn\'t work with Resource, but you may be able to manipulate it. I put this on the OnIntialized() but it doesn\'t have to go there.</p>\n\n<pre><code>//IconTest = namespace; exclamic.ico = resource \nSystem.IO.Stream stream = this.GetType().Assembly.GetManifestResourceStream("IconTest.Resources.exclamic.ico");\n\n if (stream != null)\n {\n //Decode the icon from the stream and set the first frame to the BitmapSource\n BitmapDecoder decoder = IconBitmapDecoder.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.None);\n BitmapSource source = decoder.Frames[0];\n\n //set the source of your image\n image.Source = source;\n }\n</code></pre>\n'}, {'answer_id': 1870823, 'author': 'Thomas Bratt', 'author_id': 15985, 'author_profile': 'https://Stackoverflow.com/users/15985', 'pm_score': 5, 'selected': False, 'text': '<p>A common usage pattern is to have the notify icon the same as the main window\'s icon. The icon is defined as a PNG file.</p>\n\n<p>To do this, add the image to the project\'s resources and then use as follows:</p>\n\n<pre><code>var iconHandle = MyNamespace.Properties.Resources.MyImage.GetHicon();\nthis.notifyIcon.Icon = System.Drawing.Icon.FromHandle(iconHandle);\n</code></pre>\n\n<p>In the window XAML:</p>\n\n<pre><code>&lt;Window x:Class="MyNamespace.Window1"\nxmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"\nxmlns:local="clr-namespace:Seahorse"\nxmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"\nHeight="600"\nIcon="images\\MyImage.png"&gt;\n</code></pre>\n'}, {'answer_id': 32081321, 'author': 'Mike Sage', 'author_id': 862414, 'author_profile': 'https://Stackoverflow.com/users/862414', 'pm_score': 2, 'selected': False, 'text': '<p>If you are just looking for the simple answer, I think this is it where MyApp is your application name and where that\'s the root namespace name for your application. You have to use the pack URI syntax, but it doesn\'t have to be that complicated to pull an icon out of your embedded resources. </p>\n\n<pre><code> &lt;Window x:Class="MyApp.MainWindow"\n xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"\n xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"\n xmlns:d="http://schemas.microsoft.com/expression/blend/2008"\n xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"\n mc:Ignorable="d"\n Height="100"\n Width="200"\n Icon="pack://application:,,,/MyApp;component/Resources/small_icon.ico"&gt;\n</code></pre>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74466', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3047/']
74,471
<p>I have a function that takes, amongst others, a parameter declared as <em>int privateCount</em>. When I want to call ToString() on this param, ReSharper greys it out and marks it as a redundant call. So, curious as I am, I remove the ToString(), and the code still builds!</p> <p>How can a C# compiler allow this, where <em>str</em> is a string?</p> <p><code>str += privateCount +</code> ...</p>
[{'answer_id': 74495, 'author': 'Haacked', 'author_id': 598, 'author_profile': 'https://Stackoverflow.com/users/598', 'pm_score': 5, 'selected': True, 'text': '<p>The + operator for string is overloaded to call String.Concat passing in the left and right side of the expression. Thus:</p>\n\n<pre><code>string x = "123" + 45;\n</code></pre>\n\n<p>Gets compiled to:</p>\n\n<pre><code>String.Concat("123", 45);\n</code></pre>\n\n<p>Since String.Concat takes in two objects, the right hand side (45) is boxed and then ToString() is called on it.</p>\n\n<p>Note that this "overloading" is not via operator overloading in the language (aka it\'s not a method named op_Addition) but is handled by the compiler.</p>\n'}, {'answer_id': 74546, 'author': 'Stephen Deken', 'author_id': 7154, 'author_profile': 'https://Stackoverflow.com/users/7154', 'pm_score': 2, 'selected': False, 'text': "<p>C# automatically converts the objects to strings for you. Consider this line of code:</p>\n\n<pre><code>aString = aString + 23;\n</code></pre>\n\n<p>This is valid C#; it compiles down to a call to String.Concat(), which takes two objects as arguments. Those objects are automatically converted to string objects for you.</p>\n\n<p>The same thing occurs when you write:</p>\n\n<pre><code>aString += 23;\n</code></pre>\n\n<p>Again, this compiles down to the same call to String.Concat(); it's just written differently.</p>\n"}, {'answer_id': 74606, 'author': 'Drejc', 'author_id': 6482, 'author_profile': 'https://Stackoverflow.com/users/6482', 'pm_score': 1, 'selected': False, 'text': '<p>This is a valid bad practice, as you must think twice if the variable is a string or an int. What if the variable would be called myInt?</p>\n\n<pre><code>myInt = myInt + 23;\n</code></pre>\n\n<p>it is more readable and understandable in this form?</p>\n\n<pre><code>myInt = mInt + "23";\n</code></pre>\n\n<p>or even:</p>\n\n<pre><code>myInt = string.Format("{0}{1}", myInt, 23);\n</code></pre>\n\n<p>We know from the code that it is a string and not an integer.</p>\n'}, {'answer_id': 75404, 'author': 'Thomas Danecker', 'author_id': 9632, 'author_profile': 'https://Stackoverflow.com/users/9632', 'pm_score': 3, 'selected': False, 'text': '<p>It is not only bad practice, but also less performant: The integer has to be boxed because String.Concat expectes an object while int.ToString() does not require boxing.</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74471', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/8741/']
74,484
<p>We distribute an application that uses an MS Access .mdb file. Somebody has noticed that after opening the file in MS Access the file size shrinks a lot. That suggests that the file is a good candidate for compacting, but we don't supply the means for our users to do that.</p> <p>So, my question is, does it matter? Do we care? What bad things can happen if our users never compact the database?</p>
[{'answer_id': 74510, 'author': 'EndangeredMassa', 'author_id': 106, 'author_profile': 'https://Stackoverflow.com/users/106', 'pm_score': -1, 'selected': False, 'text': "<p>If you don't offer your users a way to decompress and the raw size isn't an issue to begin with, then don't bother.</p>\n"}, {'answer_id': 74527, 'author': 'Danimal', 'author_id': 2757, 'author_profile': 'https://Stackoverflow.com/users/2757', 'pm_score': 0, 'selected': False, 'text': "<p>I've found that Access database files almost always get corrupted over time. Compacting and repairing them helps hold that off for a while.</p>\n"}, {'answer_id': 74535, 'author': 'David Smart', 'author_id': 9623, 'author_profile': 'https://Stackoverflow.com/users/9623', 'pm_score': 1, 'selected': False, 'text': "<p>I would offer the users a method for compacting the database. I've seen databases grow to 600+ megabytes when compacting will reduce to 60-80.</p>\n"}, {'answer_id': 74537, 'author': 'Nate', 'author_id': 12779, 'author_profile': 'https://Stackoverflow.com/users/12779', 'pm_score': 5, 'selected': True, 'text': '<p>In addition to making your database smaller, it\'ll recompute the indexes on your tables and defragment your tables which can make access faster. It\'ll also find any inconsistencies that should never happen in your database, but might, due to bugs or crashes in Access.</p>\n\n<p>It\'s not totally without risk though -- a <a href="http://blogs.msdn.com/access/archive/2008/05/29/kb-article-950812-compact-and-repair-might-delete-your-database-access-2007.aspx" rel="noreferrer">bug in Access 2007</a> would occasionally delete your database during the process.</p>\n\n<p>So it\'s generally a good thing to do, but pair it with a good backup routine. With the backup in place, you can also recover from any \'unrecoverable\' compact and repair problems with a minimum of data loss.</p>\n'}, {'answer_id': 74785, 'author': 'Keithius', 'author_id': 5956, 'author_profile': 'https://Stackoverflow.com/users/5956', 'pm_score': 2, 'selected': False, 'text': '<p>Compacting an Access database (also known as a MS JET database) is a bit like defragmenting a hard drive. Access (or, more accurately, the MS JET database engine) isn\'t very good with re-using space - so when a record is updated, inserted, or deleted, the space is not always reclaimed - instead, new space is added to the end of the database file and used instead. </p>\n\n<p>A general rule of thumb is that if your [Access] database will be written to (updated, changed, or added to), you should allow for compacting - otherwise it <strong>will</strong> grow in size (much more than just the data you\'ve added, too). </p>\n\n<p>So, to answer your question(s): </p>\n\n<ul>\n<li>Yes, it does matter (unless your database is read-only). </li>\n<li>You should care (unless you <em>don\'t</em> care about your user\'s disk space).</li>\n<li>If you don\'t compact an Access database, over time it will grow much, much, much larger than the data inside it would suggest, slowing down performance and increasing the possibilities of errors and corruption. (As a file-based database, Access database files are notorious for corruption, especially when accessed over a network.)</li>\n</ul>\n\n<p>This article on <a href="http://support.microsoft.com/kb/230501" rel="nofollow noreferrer">How to Compact Microsoft Access Database Through ADO</a> will give you a good starting point if you decide to add this functionality to your app.</p>\n'}, {'answer_id': 74797, 'author': 'Philippe Grondier', 'author_id': 11436, 'author_profile': 'https://Stackoverflow.com/users/11436', 'pm_score': 0, 'selected': False, 'text': '<p>Well it really matters! mdb files keep increasing in size each time you manipulate its data, until it reaches unbearable size. But you don\'t have to supply a compacting method through your interface. You can add the following code in your mdb file to have it compacted each time the file is closed:</p>\n\n<p>Application.SetOption ("Auto Compact"), 1</p>\n'}, {'answer_id': 74876, 'author': 'calebjenkins', 'author_id': 13199, 'author_profile': 'https://Stackoverflow.com/users/13199', 'pm_score': 0, 'selected': False, 'text': '<p>I would also <em>highly</em> recommend looking in to VistaDB (<a href="http://www.vistadb.net/" rel="nofollow noreferrer">http://www.vistadb.net/</a>) or SQL Compact(<a href="http://www.microsoft.com/sql/editions/compact/" rel="nofollow noreferrer">http://www.microsoft.com/sql/editions/compact/</a>) for your application. These might not be the right fit for your app... but are def worth a look.</p>\n'}, {'answer_id': 74930, 'author': 'BIBD', 'author_id': 685, 'author_profile': 'https://Stackoverflow.com/users/685', 'pm_score': 1, 'selected': False, 'text': "<p>To echo Nate:\nIn older versions, I've had it corrupt databases - so a good backup regime is essential. I wouldn't code anything into your app to do that automatically. However, if a customer finds that their database is running really slow, your tech support people could talk them through it if need be (with appropriate backups of course).</p>\n\n<p>If their database is getting to be so large that the compaction starts to be come a necessity though, maybe it's time to move to MS-SQL.</p>\n"}, {'answer_id': 75065, 'author': 'Chris OC', 'author_id': 11041, 'author_profile': 'https://Stackoverflow.com/users/11041', 'pm_score': 3, 'selected': False, 'text': '<p>Make sure you compact and repair the database regularly, especially if the database application experiences frequent record updates, deletions and insertions. Not only will this keep the size of the database file down to the minimum - which will help speed up database operations and network communications - it performs database housekeeping, too, which is of even greater benefit to the stability of your data. But before you compact the database, make sure that you make a backup of the file, just in case something goes wrong with the compaction.</p>\n\n<p>Jet compacts a database to reorganize the content within the file so that each 4 KB "page" (2KB for Access 95/97) of space allotted for data, tables, or indexes is located in a contiguous area. Jet recovers the space from records marked as deleted and rewrites the records in each table in primary key order, like a clustered index. This will make your db\'s read/write ops faster.</p>\n\n<p>Jet also updates the table statistics during compaction. This includes identifying the number of records in each table, which will allow Jet to use the most optimal method to scan for records, either by using the indexes or by using a full table scan when there are few records. After compaction, run each stored query so that Jet re-optimizes it using these updated table statistics, which can improve query performance.</p>\n\n<p>Access 2000, 2002, 2003 and 2007 combine the compaction with a repair operation if it\'s needed. The repair process:</p>\n\n<p>1 - Cleans up incomplete transactions</p>\n\n<p>2 - Compares data in system tables with data in actual tables, queries and indexes and repairs the mistakes</p>\n\n<p>3 - Repairs very simple data structure mistakes, such as lost pointers to multi-page records (which isn\'t always successful and is why "repair" doesn\'t always work to save a corrupted Access database)</p>\n\n<p>4 - Replaces missing information about a VBA project\'s structure</p>\n\n<p>5 - Replaces missing information needed to open a form, report and module</p>\n\n<p>6 - Repairs simple object structure mistakes in forms, reports, and modules</p>\n\n<p>The bad things that can happen if the users never compact/repair the db is that it will become slow due to bloat, and it may become unstable - meaning corrupted.</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74484', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/9328/']
74,494
<p>I'm developing a website on an XP virtual machine and have an SMTP virtual server set up in IIS -- it delivers mail just fine. What I would <em>like</em> is to confirm that any emails the site sends are only going to a specific domain.</p> <p>The XP firewall seems to only involve incoming connections, I can't block outgoing TCP on port 25. And I haven't been able to configure the SMTP server to filter by delivery address.</p> <p>With this setup, is there any easy way to filter outgoing email by destination address?</p>
[{'answer_id': 74554, 'author': 'Vaibhav', 'author_id': 380, 'author_profile': 'https://Stackoverflow.com/users/380', 'pm_score': 0, 'selected': False, 'text': "<p>I think the easiest way would be to add a check to your mail sending code on the website (there's got to be some class which is in charge of sending the mails out).</p>\n\n<p>You could include a check which is only active when the code is compiled in debug mode (using compiler directives). Thus, when you are developing and building the site in debug mode, this code checks if the outgoing messages are valid (specific domain) or not. If they are it lets them go, else it doesn't send the mail.</p>\n"}, {'answer_id': 75434, 'author': 'Neil C. Obremski', 'author_id': 9642, 'author_profile': 'https://Stackoverflow.com/users/9642', 'pm_score': 2, 'selected': True, 'text': '<p>Here\'s one idea:</p>\n\n<p>Under <code>Advanced Delivery</code> options (<code>SMTP Virtual Server Properties</code> &gt; <code>Delivery</code> tab &gt; <code>Advanced</code>). There you can set a "Smart Host" which is the SMTP server that will be used to actually send the mail, so you could possibly have it deliver directly to the specific domain\'s incoming SMTP server.</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74494', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13071/']
74,514
<p>Implementing Equals() for reference types is harder than it seems. My current canonical implementation goes like this:</p> <pre><code>public bool Equals( MyClass obj ) { // If both refer to the same reference they are equal. if( ReferenceEquals( obj, this ) ) return true; // If the other object is null they are not equal because in C# this cannot be null. if( ReferenceEquals( obj, null ) ) return false; // Compare data to evaluate equality return _data.Equals( obj._data ); } public override bool Equals( object obj ) { // If both refer to the same reference they are equal. if( ReferenceEquals( obj, this ) ) return true; // If the other object is null or is of a different types the objects are not equal. if( ReferenceEquals( obj, null ) || obj.GetType() != GetType() ) return false; // Use type-safe equality comparison return Equals( (MyClass)obj ); } public override int GetHashCode() { // Use data's hash code as our hashcode return _data.GetHashCode(); } </code></pre> <p>I think that this covers all corner (inheritance and such) cases but I may be wrong. What do you guys think?</p>
[{'answer_id': 74540, 'author': 'Peter Ritchie', 'author_id': 5620, 'author_profile': 'https://Stackoverflow.com/users/5620', 'pm_score': 0, 'selected': False, 'text': '<p>It depends on whether you\'re writing a value type or a reference type. For a sortable value type, I recommend this:\n<a href="http://msmvps.com/blogs/peterritchie/archive/2006/03/25/a-code-snippet-for-visual-studio-2005-that-implements-a-skeleton-value-type-adhering-to-framework-design-guidelines.aspx" rel="nofollow noreferrer">A code snippet for Visual Studio 2005 that implements a skeleton value type adhering to Framework Design Guidelines</a></p>\n'}, {'answer_id': 74559, 'author': 'chakrit', 'author_id': 3055, 'author_profile': 'https://Stackoverflow.com/users/3055', 'pm_score': 0, 'selected': False, 'text': '<p>Concerning inheritance, I think you should just let the OO paradigm does its magic.</p>\n\n<p>Specifically, the <code>GetType()</code> check should be removed, it might break polymorphism down the line.</p>\n'}, {'answer_id': 74704, 'author': 'Santiago Palladino', 'author_id': 12791, 'author_profile': 'https://Stackoverflow.com/users/12791', 'pm_score': 0, 'selected': False, 'text': '<p>I agree with chakrit, objects of different types should be allowed to be semantically equal if they have the same data or ID.</p>\n\n<p>Personally, I use the following:</p>\n\n<pre><code> public override bool Equals(object obj)\n {\n var other = obj as MyClass;\n if (other == null) return false;\n\n return this.data.Equals(other.data);\n }\n</code></pre>\n'}, {'answer_id': 74765, 'author': 'tvanfosson', 'author_id': 12950, 'author_profile': 'https://Stackoverflow.com/users/12950', 'pm_score': 1, 'selected': False, 'text': "<p>Better hope that this._data is not null if it's also a reference type.</p>\n\n<pre><code>public bool Equals( MyClass obj )\n{\n if (obj == null) {\n return false;\n }\n else {\n return (this._data != null &amp;&amp; this._data.Equals( obj._data ))\n || obj._data == null;\n }\n}\n\npublic override bool Equals( object obj )\n{\n if (obj == null || !(obj is MyClass)) {\n return false;\n }\n else {\n return this.Equals( (MyClass)obj );\n }\n}\n\npublic override int GetHashCode() {\n return this._data == null ? 0 : this._data.GetHashCode();\n}\n</code></pre>\n"}, {'answer_id': 74802, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': True, 'text': '<p>I wrote a fairly comprehensive guide to this a while back. For a start your equals implementations should be shared (i.e. the overload taking an object should pass through to the one taking a strongly typed object). Additionally you need to consider things such as your object should be immutable because of the need to override GetHashCode. More info here:</p>\n\n<p><a href="http://gregbeech.com/blog/implementing-object-equality-in-dotnet" rel="nofollow noreferrer">http://gregbeech.com/blog/implementing-object-equality-in-dotnet</a></p>\n'}, {'answer_id': 69503610, 'author': 'Manfred', 'author_id': 411428, 'author_profile': 'https://Stackoverflow.com/users/411428', 'pm_score': 0, 'selected': False, 'text': '<p>As the link in the accepted answer by Greg Beech is broken, I hope this answer might be helpful to some.</p>\n<p>Microsoft\'s documentation provides the following example for a typical implementation of <code>Equals()</code> on reference types (i.e. class):</p>\n<pre class="lang-cs prettyprint-override"><code>public override bool Equals(object obj) =&gt; this.Equals(obj as TwoDPoint);\n\npublic bool Equals(TwoDPoint p)\n{\n if (p is null)\n {\n return false;\n }\n\n // Optimization for a common success case.\n if (Object.ReferenceEquals(this, p))\n {\n return true;\n }\n\n // If run-time types are not exactly the same, return false.\n if (this.GetType() != p.GetType())\n {\n return false;\n }\n\n // Return true if the fields match.\n // Note that the base class is not invoked because it is\n // System.Object, which defines Equals as reference equality.\n return (X == p.X) &amp;&amp; (Y == p.Y);\n}\n</code></pre>\n<p>The complete example with more details including what to do in derived classes or for structs, can be found at <a href="https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/statements-expressions-operators/how-to-define-value-equality-for-a-type" rel="nofollow noreferrer">&quot;How to define value equality for a class or struct (C# Programming Guide)&quot;</a></p>\n<p>As an alternative to what is described in Microsoft\'s doc, the method <code>GetHashCode()</code> can also be implemented as follows:</p>\n<pre class="lang-cs prettyprint-override"><code>public override int GetHashCode()\n{\n return HashCode.Combine(X, Y);\n}\n</code></pre>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74514', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12851/']
74,519
<p>I would like to use the 7-Zip DLLs from Delphi but have not been able to find decent documentation or examples. Does anyone know how to use the 7-Zip DLLs from Delphi?</p>
[{'answer_id': 81893, 'author': 'Oliver Giesen', 'author_id': 9784, 'author_profile': 'https://Stackoverflow.com/users/9784', 'pm_score': 6, 'selected': True, 'text': '<p>As of release 1.102 the <a href="http://wiki.delphi-jedi.org/index.php?title=JEDI_Code_Library" rel="noreferrer">JEDI Code Library</a> has support for <a href="http://en.wikipedia.org/wiki/7-Zip" rel="noreferrer">7-Zip</a> built into the <a href="http://jcl.svn.sourceforge.net/viewvc/jcl/trunk/jcl/source/common/JclCompression.pas?view=markup" rel="noreferrer">JclCompression</a> unit. Haven\'t used it myself yet, though.</p>\n'}, {'answer_id': 91654, 'author': 'Drejc', 'author_id': 6482, 'author_profile': 'https://Stackoverflow.com/users/6482', 'pm_score': 1, 'selected': False, 'text': '<p>If you intend to use 7Zip only for zip and unzip take a look at the <a href="http://www.angusj.com/delphi/" rel="nofollow noreferrer">TZip</a> component.\nI have written a small wrapper for my own purposes, which you can find in the <a href="https://monex.svn.sourceforge.net/svnroot/monex/trunk/Knjiznice/" rel="nofollow noreferrer">Zipper.pas</a> file, feel free to reuse.</p>\n'}, {'answer_id': 1344656, 'author': 'jasonpenny', 'author_id': 28445, 'author_profile': 'https://Stackoverflow.com/users/28445', 'pm_score': 5, 'selected': False, 'text': "<p>Expanding on Oliver Giesen's answer, as with a lot of the JEDI Code Library, I couldn't find any decent documentation, but this works for me:</p>\n\n<pre><code>uses\n JclCompression;\n\nprocedure TfrmSevenZipTest.Button1Click(Sender: TObject);\nconst\n FILENAME = 'F:\\temp\\test.zip';\nvar\n archiveclass: TJclDecompressArchiveClass;\n archive: TJclDecompressArchive;\n item: TJclCompressionItem;\n s: String;\n i: Integer;\nbegin\n archiveclass := GetArchiveFormats.FindDecompressFormat(FILENAME);\n\n if not Assigned(archiveclass) then\n raise Exception.Create('Could not determine the Format of ' + FILENAME);\n\n archive := archiveclass.Create(FILENAME);\n try\n if not (archive is TJclSevenZipDecompressArchive) then\n raise Exception.Create('This format is not handled by 7z.dll');\n\n archive.ListFiles;\n\n s := Format('test.zip Item Count: %d'#13#10#13#10, [archive.ItemCount]);\n\n for i := 0 to archive.ItemCount - 1 do\n begin\n item := archive.Items[i];\n case item.Kind of\n ikFile:\n s := s + IntToStr(i+1) + ': ' + item.PackedName + #13#10;\n ikDirectory:\n s := s + IntToStr(i+1) + ': ' + item.PackedName + '\\'#13#10;//'\n end;\n end;\n\n if archive.ItemCount > 0 then\n begin\n// archive.Items[0].Selected := true;\n// archive.ExtractSelected('F:\\temp\\test');\n\n archive.ExtractAll('F:\\temp\\test');\n end;\n\n ShowMessage(s);\n finally\n archive.Free;\n end;\nend;\n</code></pre>\n"}, {'answer_id': 1348084, 'author': 'Hugues Van Landeghem', 'author_id': 87736, 'author_profile': 'https://Stackoverflow.com/users/87736', 'pm_score': 3, 'selected': False, 'text': '<p>7 Zip Plugin API</p>\n\n<p><a href="http://www.progdigy.com/?page_id=13" rel="noreferrer">http://www.progdigy.com/?page_id=13</a></p>\n'}, {'answer_id': 7301230, 'author': 'Kachwahed', 'author_id': 188311, 'author_profile': 'https://Stackoverflow.com/users/188311', 'pm_score': 2, 'selected': False, 'text': '<p>Zip and 7z with NO DLL, try out Synopse:\n<a href="http://synopse.info/forum/viewtopic.php?pid=163" rel="nofollow">http://synopse.info/forum/viewtopic.php?pid=163</a></p>\n'}, {'answer_id': 8392265, 'author': 'Marcus Adams', 'author_id': 168493, 'author_profile': 'https://Stackoverflow.com/users/168493', 'pm_score': 2, 'selected': False, 'text': '<p>Delphi now has native, cross platform zip support with TZipFile in XE2:</p>\n\n<p><a href="http://delphiwiki.com/extract-zip-files-in-delphi-and-firemonkey-with-tzipfile/" rel="noreferrer">How to extract zip files with TZipFile in Delphi XE2 and FireMonkey</a></p>\n'}, {'answer_id': 42602091, 'author': 'Tone Škoda', 'author_id': 3572009, 'author_profile': 'https://Stackoverflow.com/users/3572009', 'pm_score': 0, 'selected': False, 'text': '<p>I tried many solutions and had problems, this one worked.</p>\n\n<p>Download <a href="https://github.com/zedalaye/d7zip" rel="nofollow noreferrer">https://github.com/zedalaye/d7zip</a>\nCopy 7z.dll and sevenzip.pas to your project diroctory and add sevenzip.pas to your project.</p>\n\n<p>Then you can use this to unzip:</p>\n\n<pre><code>using sevenzip;\n\nprocedure Unzip7zFile (zipFullFname:string);\n var\n outDir:string;\n begin\n with CreateInArchive(CLSID_CFormat7z) do\n begin \n OpenFile(zipFullFname);\n outDir := ChangeFileExt(zipFullFname, \'\');\n ForceDirectories (outDir);\n ExtractTo(outDir);\n end;\n end;\n</code></pre>\n\n<p>Usage:</p>\n\n<pre><code>Unzip7zFile(ExtractFilePath(Application.ExeName) + \'STR_SI_FULL_1000420.7z\');\n</code></pre>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74519', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13054/']
74,521
<p>Does anyone have details in setting up Qt4 in Visual Studio 2008? Links to other resources would be appreciated as well.</p> <p>I already know that the commercial version of Qt has applications to this end. I also realize that I'll probably need to compile from source as the installer for the open source does not support Visual Studio and installs Cygwin.</p>
[{'answer_id': 81893, 'author': 'Oliver Giesen', 'author_id': 9784, 'author_profile': 'https://Stackoverflow.com/users/9784', 'pm_score': 6, 'selected': True, 'text': '<p>As of release 1.102 the <a href="http://wiki.delphi-jedi.org/index.php?title=JEDI_Code_Library" rel="noreferrer">JEDI Code Library</a> has support for <a href="http://en.wikipedia.org/wiki/7-Zip" rel="noreferrer">7-Zip</a> built into the <a href="http://jcl.svn.sourceforge.net/viewvc/jcl/trunk/jcl/source/common/JclCompression.pas?view=markup" rel="noreferrer">JclCompression</a> unit. Haven\'t used it myself yet, though.</p>\n'}, {'answer_id': 91654, 'author': 'Drejc', 'author_id': 6482, 'author_profile': 'https://Stackoverflow.com/users/6482', 'pm_score': 1, 'selected': False, 'text': '<p>If you intend to use 7Zip only for zip and unzip take a look at the <a href="http://www.angusj.com/delphi/" rel="nofollow noreferrer">TZip</a> component.\nI have written a small wrapper for my own purposes, which you can find in the <a href="https://monex.svn.sourceforge.net/svnroot/monex/trunk/Knjiznice/" rel="nofollow noreferrer">Zipper.pas</a> file, feel free to reuse.</p>\n'}, {'answer_id': 1344656, 'author': 'jasonpenny', 'author_id': 28445, 'author_profile': 'https://Stackoverflow.com/users/28445', 'pm_score': 5, 'selected': False, 'text': "<p>Expanding on Oliver Giesen's answer, as with a lot of the JEDI Code Library, I couldn't find any decent documentation, but this works for me:</p>\n\n<pre><code>uses\n JclCompression;\n\nprocedure TfrmSevenZipTest.Button1Click(Sender: TObject);\nconst\n FILENAME = 'F:\\temp\\test.zip';\nvar\n archiveclass: TJclDecompressArchiveClass;\n archive: TJclDecompressArchive;\n item: TJclCompressionItem;\n s: String;\n i: Integer;\nbegin\n archiveclass := GetArchiveFormats.FindDecompressFormat(FILENAME);\n\n if not Assigned(archiveclass) then\n raise Exception.Create('Could not determine the Format of ' + FILENAME);\n\n archive := archiveclass.Create(FILENAME);\n try\n if not (archive is TJclSevenZipDecompressArchive) then\n raise Exception.Create('This format is not handled by 7z.dll');\n\n archive.ListFiles;\n\n s := Format('test.zip Item Count: %d'#13#10#13#10, [archive.ItemCount]);\n\n for i := 0 to archive.ItemCount - 1 do\n begin\n item := archive.Items[i];\n case item.Kind of\n ikFile:\n s := s + IntToStr(i+1) + ': ' + item.PackedName + #13#10;\n ikDirectory:\n s := s + IntToStr(i+1) + ': ' + item.PackedName + '\\'#13#10;//'\n end;\n end;\n\n if archive.ItemCount > 0 then\n begin\n// archive.Items[0].Selected := true;\n// archive.ExtractSelected('F:\\temp\\test');\n\n archive.ExtractAll('F:\\temp\\test');\n end;\n\n ShowMessage(s);\n finally\n archive.Free;\n end;\nend;\n</code></pre>\n"}, {'answer_id': 1348084, 'author': 'Hugues Van Landeghem', 'author_id': 87736, 'author_profile': 'https://Stackoverflow.com/users/87736', 'pm_score': 3, 'selected': False, 'text': '<p>7 Zip Plugin API</p>\n\n<p><a href="http://www.progdigy.com/?page_id=13" rel="noreferrer">http://www.progdigy.com/?page_id=13</a></p>\n'}, {'answer_id': 7301230, 'author': 'Kachwahed', 'author_id': 188311, 'author_profile': 'https://Stackoverflow.com/users/188311', 'pm_score': 2, 'selected': False, 'text': '<p>Zip and 7z with NO DLL, try out Synopse:\n<a href="http://synopse.info/forum/viewtopic.php?pid=163" rel="nofollow">http://synopse.info/forum/viewtopic.php?pid=163</a></p>\n'}, {'answer_id': 8392265, 'author': 'Marcus Adams', 'author_id': 168493, 'author_profile': 'https://Stackoverflow.com/users/168493', 'pm_score': 2, 'selected': False, 'text': '<p>Delphi now has native, cross platform zip support with TZipFile in XE2:</p>\n\n<p><a href="http://delphiwiki.com/extract-zip-files-in-delphi-and-firemonkey-with-tzipfile/" rel="noreferrer">How to extract zip files with TZipFile in Delphi XE2 and FireMonkey</a></p>\n'}, {'answer_id': 42602091, 'author': 'Tone Škoda', 'author_id': 3572009, 'author_profile': 'https://Stackoverflow.com/users/3572009', 'pm_score': 0, 'selected': False, 'text': '<p>I tried many solutions and had problems, this one worked.</p>\n\n<p>Download <a href="https://github.com/zedalaye/d7zip" rel="nofollow noreferrer">https://github.com/zedalaye/d7zip</a>\nCopy 7z.dll and sevenzip.pas to your project diroctory and add sevenzip.pas to your project.</p>\n\n<p>Then you can use this to unzip:</p>\n\n<pre><code>using sevenzip;\n\nprocedure Unzip7zFile (zipFullFname:string);\n var\n outDir:string;\n begin\n with CreateInArchive(CLSID_CFormat7z) do\n begin \n OpenFile(zipFullFname);\n outDir := ChangeFileExt(zipFullFname, \'\');\n ForceDirectories (outDir);\n ExtractTo(outDir);\n end;\n end;\n</code></pre>\n\n<p>Usage:</p>\n\n<pre><code>Unzip7zFile(ExtractFilePath(Application.ExeName) + \'STR_SI_FULL_1000420.7z\');\n</code></pre>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74521', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/11994/']
74,526
<p>In Team Foundation Server, I know that you can use the <strong>Annotate</strong> feature to see who last edited each line in a particular file (equivalent to "Blame" in CVS). What I'd like to do is akin to running Annotate on every file in a project, and get a summary report of all the developers who have edited a file in the project, and how many lines of code they currently "own" in that project.</p> <p>Aside from systematically running Annotate of each file, I can't see a way to do this. Any ideas that would make this process faster?</p> <p>PS - I'm doing to this to see how much of a consultant's code still remains in a particular (rather large) project, not to keep tabs on my developers, in case you're worried about my motivation :)</p>
[{'answer_id': 78498, 'author': 'granth', 'author_id': 11210, 'author_profile': 'https://Stackoverflow.com/users/11210', 'pm_score': 5, 'selected': True, 'text': '<p>It\'s easy enough to use the "tf.exe history" command recursively across a directory of files in TFS. This will tell you who changed what files.</p>\n\n<p>However what you\'re after is a little bit more than this - you want to know if the latest versions of any files have lines written by a particular user.</p>\n\n<p>The Team Foundation Power Tools ship with a command-line version of annotate called "tfpt.exe annotate". This has a /noprompt option to direct the output to the console, but it only outputs the changeset id - not the user name.</p>\n\n<p>You could also use the TFS VersionControl object model to write a tool that does exactly what you need.</p>\n'}, {'answer_id': 858420, 'author': 'Mitch Wheat', 'author_id': 16076, 'author_profile': 'https://Stackoverflow.com/users/16076', 'pm_score': 1, 'selected': False, 'text': "<p>If you install the TFS Power tools (at least for VS2005); it's called annotate.</p>\n\n<p>It might be part of VS2008...</p>\n"}, {'answer_id': 4125543, 'author': 'Jeroen Wiert Pluimers', 'author_id': 29290, 'author_profile': 'https://Stackoverflow.com/users/29290', 'pm_score': 1, 'selected': False, 'text': '<p>Annotate is now part of Visual Studio (I think it was introduced in VS 2010).</p>\n\n<p><a href="http://msdn.microsoft.com/en-us/library/bb385979.aspx" rel="nofollow">Docs</a></p>\n'}, {'answer_id': 6185950, 'author': 'e-mre', 'author_id': 351671, 'author_profile': 'https://Stackoverflow.com/users/351671', 'pm_score': 1, 'selected': False, 'text': '<p>You can use TFS Analysis Cube to see generate a code churn report, which I believe is something you would like.</p>\n'}, {'answer_id': 41813450, 'author': 'Quincy', 'author_id': 562861, 'author_profile': 'https://Stackoverflow.com/users/562861', 'pm_score': 0, 'selected': False, 'text': '<p>I\'m writing an answer to an 8 year old question :). Its not really a full answer, but a suggestion to look into excel reports for TFS.</p>\n\n<p>TFS2013 / 2015 on prem has something has an excel report that can be used to visualize Code Churn. </p>\n\n<p>In VS open team explorer then select "Documents" then explode "Excel Reports". I believe Code Churn report has something like discussed. The report is made by some default project template so I think tfs2013 on prem just creates it.</p>\n\n<p>Code Churn Excel Report VS2015\n<a href="https://msdn.microsoft.com/en-us/library/dd695782.aspx" rel="nofollow noreferrer">https://msdn.microsoft.com/en-us/library/dd695782.aspx</a></p>\n'}, {'answer_id': 48261049, 'author': 'akjoshi', 'author_id': 45382, 'author_profile': 'https://Stackoverflow.com/users/45382', 'pm_score': 0, 'selected': False, 'text': '<p>I had very similar requirement to get details of particular attribute in a file e.g. who added, when, related work items etc.; Following GitHub project is having implementation to get required details and required minimal changes to work with multiple files or project -</p>\n\n<p><a href="https://github.com/SonarQubeCommunity/sonar-scm-tfvc" rel="nofollow noreferrer">SonarQube SCM TFVC plugin</a> </p>\n\n<p>It requires analysis to be executed from Windows machines with the Team Foundation Server Object Model installed (download for TFS 2013). </p>\n\n<p>This blog post is also having good explaination and sample application - </p>\n\n<p><a href="http://geekswithblogs.net/TarunArora/archive/2011/06/18/tfs-2010-sdk-connecting-to-tfs-2010-programmaticallyndashpart-1.aspx" rel="nofollow noreferrer">TFS SDK: Connecting to TFS 2010 &amp; TFS 2012 Programmatically</a></p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74526', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/8114/']
74,561
<p>I am interested in writing static code analyzer for vb.net to see if it conforms to my company standard coding guidelines. Please advise from where i have to start.</p>
[{'answer_id': 74573, 'author': 'Haacked', 'author_id': 598, 'author_profile': 'https://Stackoverflow.com/users/598', 'pm_score': 4, 'selected': False, 'text': '<p>Rather than write your own static code analyzer, I recommend you use <a href="http://msdn.microsoft.com/en-us/library/bb429476(VS.80).aspx" rel="noreferrer">FxCop</a>: and instead, write custom FxCop rules for your needs. It\'ll save you a lot of time.\n<a href="http://www.binarycoder.net/fxcop/" rel="noreferrer">http://www.binarycoder.net/fxcop/</a></p>\n'}, {'answer_id': 74578, 'author': 'Jonathan Rupp', 'author_id': 12502, 'author_profile': 'https://Stackoverflow.com/users/12502', 'pm_score': 0, 'selected': False, 'text': "<p>Start with FxCop. If you can't do what you're trying there, try something like NStatic or NDepend.</p>\n"}, {'answer_id': 74609, 'author': 'Alex Fort', 'author_id': 12624, 'author_profile': 'https://Stackoverflow.com/users/12624', 'pm_score': 2, 'selected': False, 'text': "<p>I would suggest you use Mono's Gendarme. It's a very nice tool, with plenty of built in rules. It also generates nice HTML reports.</p>\n"}, {'answer_id': 74636, 'author': 'Scott Dorman', 'author_id': 1559, 'author_profile': 'https://Stackoverflow.com/users/1559', 'pm_score': 0, 'selected': False, 'text': '<p>The best options are to use FxCop or StyleCop and write custom rules if necessary.</p>\n'}, {'answer_id': 74736, 'author': 'David B Heise', 'author_id': 13124, 'author_profile': 'https://Stackoverflow.com/users/13124', 'pm_score': 2, 'selected': True, 'text': '<p><a href="http://go.microsoft.com/fwlink/?LinkId=70294" rel="nofollow noreferrer">FXCop</a> is a good start for coding problems/mistakes, <a href="http://blogs.msdn.com/sourceanalysis/" rel="nofollow noreferrer">StyleCop</a> is good for coding style (obviously), but if neither of those two work then you then you can either write a parser yourself or use the <a href="http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.vbcodeprovider.aspx" rel="nofollow noreferrer">VBCodeProvider</a> class in the .Net Framework</p>\n'}, {'answer_id': 74741, 'author': 'alnayyir', 'author_id': 13127, 'author_profile': 'https://Stackoverflow.com/users/13127', 'pm_score': 0, 'selected': False, 'text': "<p>Use FxCop, this isn't a project you want to undertake personally. The parsing/lexical rules involved and the possible catches would be insane. The only way I could imagine doing it while retaining a modicum of sanity would be to use Lisp thanks to the extreme amount of expressiveness, but again, best to use FxCop.</p>\n\n<p>If you must write a custom in-house tool for some (dogmatic?) reason, I'd recommend writing a Lisp program that does only basic rules-checking. Don't try to make it comprehensive, we're talking the kind of frontier that AI researchers are dealing with in terms of the parsing capabilities of a piece of software.</p>\n\n<p>Just use Lisp to find the possible obvious offenders, or just at catching whatever it ends up being good at catching in terms of non-compliant code, then subject it to a brief human eye scan. I highly recommend abusing macros if you do use Lisp to write the parser.</p>\n"}, {'answer_id': 74991, 'author': 'Krzysztof Kozmic', 'author_id': 13163, 'author_profile': 'https://Stackoverflow.com/users/13163', 'pm_score': 2, 'selected': False, 'text': "<p>if you need mroe architectural insight use NDepend. This tool does not stop to amaze me. It can do soo much more than FxCop. It's commercial though, but has a free trial version</p>\n"}, {'answer_id': 186607, 'author': 'aaimnr', 'author_id': 26444, 'author_profile': 'https://Stackoverflow.com/users/26444', 'pm_score': 0, 'selected': False, 'text': '<p>I agree with one of the posters that it would be a quite difficult taks, but rather than with Lisp I\'d start with F#, just like Microsoft did for their 3rd party windows drivers analysis tool:</p>\n\n<p><a href="http://arstechnica.com/journals/microsoft.ars/2005/11/10/1796" rel="nofollow noreferrer">http://arstechnica.com/journals/microsoft.ars/2005/11/10/1796</a></p>\n\n<p>F# shares Lisp\'s expressiveness (ok, almost) and works on CLR just like VB.NET, which would make the whole thing easier.</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74561', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']
74,570
<p>I'm maintaining <a href="http://perl-begin.org/" rel="nofollow noreferrer">the Perl Beginners' Site</a> and used a modified template from Open Source Web Designs. Now, the problem is that I still have an undesired artifact: a gray line on the left side of the main frame, to the left of the navigation menu. Here's <a href="http://www.shlomifish.org/Files/files/images/Computer/Screenshots/perl-begin-bad-artif.png" rel="nofollow noreferrer">an image</a> highlighting the undesired effect.</p> <p>How can I fix the CSS to remedy this problem?</p>
[{'answer_id': 74610, 'author': 'Shog9', 'author_id': 811, 'author_profile': 'https://Stackoverflow.com/users/811', 'pm_score': 4, 'selected': True, 'text': "<p>It's the <code>background-image</code> on the body showing through. Quick fix (edit style.css or add elsewhere):</p>\n\n<pre><code>#page-container\n{\n background-color: white;\n}\n</code></pre>\n"}, {'answer_id': 74613, 'author': 'Stephen Wrighton', 'author_id': 7516, 'author_profile': 'https://Stackoverflow.com/users/7516', 'pm_score': 1, 'selected': False, 'text': '<p>That is an image. (see it here: <a href="http://perl-begin.org/images/background.gif" rel="nofollow noreferrer">http://perl-begin.org/images/background.gif</a>) It\'s set in the BODY class of your stylesheet.</p>\n'}, {'answer_id': 74621, 'author': 'Jonathan Rupp', 'author_id': 12502, 'author_profile': 'https://Stackoverflow.com/users/12502', 'pm_score': 0, 'selected': False, 'text': "<p>I think it's this:</p>\n\n<pre><code>#page-container {\n border-left: solid 1px rgb(150,150,150); border-right: solid 1px rgb(150,150,150); \n}\n</code></pre>\n\n<p>However, I'm not seeing why the right border isn't showing up....</p>\n"}, {'answer_id': 74663, 'author': 'Jim', 'author_id': 8427, 'author_profile': 'https://Stackoverflow.com/users/8427', 'pm_score': 1, 'selected': False, 'text': '<p>The grey line is supposed to be there. The reason why it looks odd is because the very top is hidden by the buffer element. Remove the <code>background-color</code> rule from this ruleset:</p>\n\n<pre><code>.buffer {\n float: left; width: 160px; height: 20px; margin: 0px; padding: 0px; background-color: rgb(255,255,255); \n}\n</code></pre>\n'}, {'answer_id': 74774, 'author': 'user11070', 'author_id': 11070, 'author_profile': 'https://Stackoverflow.com/users/11070', 'pm_score': 0, 'selected': False, 'text': '<p>I would do a quick fix on this to add the style:</p>\n\n<pre><code>border-left:2px solid #BDBDBD;\n</code></pre>\n\n<p>to the .buffer class</p>\n\n<pre><code>.buffer {style.css (line 328)\n background-color:#FFFFFF;\n border-left:2px solid #BDBDBD; /* Grey border */\n float:left;\n height:20px;\n margin:0px;\n padding:0px;\n width:160px;\n}\n</code></pre>\n'}, {'answer_id': 74795, 'author': 'Buzz', 'author_id': 13113, 'author_profile': 'https://Stackoverflow.com/users/13113', 'pm_score': 0, 'selected': False, 'text': "<p>I found the problem. </p>\n\n<p>The problem is that you need to set a white background on #page-container. As things stand, it has a transparent background, so the 5pt left margin on navbar-sidebanner is revealing the bg of the page_container ... so change that bg and you're cool. </p>\n"}, {'answer_id': 75055, 'author': 'Shlomi Fish', 'author_id': 7709, 'author_profile': 'https://Stackoverflow.com/users/7709', 'pm_score': -1, 'selected': False, 'text': '<p>Thanks to all the people who answered. The problem was indeed the transparency of the #page-container and the background image of the body. I fixed them both in the stylesheet. </p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74570', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/7709/']
74,586
<p>There's <a href="http://developer.apple.com/quicktime/download/" rel="nofollow noreferrer">Quicktime SDK</a> for Windows, but any application that uses it needs quicktime runtime libraries to be installed on the system (SDK itself just has headers and library stubs, and not the actual DLLs).</p> <p>If my application uses Quicktime, I'd like to install the necessary libraries with it's installer, thus not requiring user to install Quicktime separately. What I'm looking for is some sort of "quicktime redistributable".</p> <p>As of now (quicktime 7.x), I can't find a way to do that. I could bundle whole quicktime installer (about 20 MiB), and launch it with MSI's silent/unattended flag. However, that way it has several side effects:</p> <ol> <li>creates Quicktime player shortcut on desktop and in quick launch bar</li> <li>hijacks file associations, (e.g. .mov becomes associated with Quicktime Player, even if it was associated with something else before)</li> <li>installs some service/process (qttask) that presumably watches for Quicktime associations, or handles auto-updates.</li> <li>installs Quicktime Player, which I don't need in fact.</li> </ol> <p>Of the above, first three are quite bad.</p> <p>Is there a way to "just install the libraries" for Quicktime?</p> <p>In my application, I'd use Quicktime to import images, movies and audio files in various formats. If there is no sane way to install Quicktime runtime without side effects (changed file associations, extra icons, ...), then I should be seriously looking at alternative solutions (e.g. FreeImage to load images, perhaps DirectShow for video/audio).</p>
[{'answer_id': 74700, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>You could include, with your setup package, a program called Quicktime Lite. It comes with the same libraries as Quicktime uses, but is much, much smaller.</p>\n\n<p>Here"s the link:\n<a href="http://www.codecguide.com/qt_lite.htm" rel="nofollow noreferrer">Download Quicktime Lite</a></p>\n'}, {'answer_id': 74814, 'author': 'emk', 'author_id': 12089, 'author_profile': 'https://Stackoverflow.com/users/12089', 'pm_score': 3, 'selected': True, 'text': '<p>If you need to redistribute QuickTime, see <a href="http://developer.apple.com/softwarelicensing/agreements/quicktime.html" rel="nofollow noreferrer">QuickTime Licensing</a> for details. You\'re not allowed to redistribute any of the QuickTime libraries without a written agreement with Apple. Many CD-replication companies will actually request proof of this agreement before printing large numbers of CDs.</p>\n\n<p>I would definitely not distribute "QuickTime Lite" without consulting with either a lawyer or your Apple licensing representative.</p>\n\n<p>Your best bet, AFAIK, is to use the full QuickTime installer (all 20MB of it), and have your main installer run it with a "silent" flag. That, at least, will allow your users to install QuickTime without a half-dozen dialogs (and without those annoying pictures of surfers in bikinis). The people at Apple\'s licensing division seemed to think that using the "silent" flag was acceptable, at least when we consulted them.</p>\n\n<p>One warning: If the user already has an older version of QuickTime 6 Pro (or earlier) installed, then installing QuickTime 7 silently will nuke their QuickTime Pro registration and they\'ll have to repurchase it. We actually detect this situation in our installer and display a warning during the installation process, much like Apple does.</p>\n\n<p>Yes, this is a pain. After 6+ years of working with QuickTime, I\'d honestly recommend looking at other video frameworks. We\'re currently evaluating Ogg Theora.</p>\n'}, {'answer_id': 74845, 'author': 'Dark Shikari', 'author_id': 11206, 'author_profile': 'https://Stackoverflow.com/users/11206', 'pm_score': 0, 'selected': False, 'text': '<p>Quicktime Alternative does what you want, but for the reasons others have stated here, its illegal. Apple probably is not going to let you do what you want.</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74586', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/6799/']
74,604
<p>It seems as if making the clipboard ring appear in the VS2008 toolbox is pretty elusive. Does anyone know how to turn this on ? <kbd>Ctrl</kbd>-<kbd>Shift</kbd>-<kbd>V</kbd> works fine, but I'd like to see what on the ring.</p>
[{'answer_id': 74607, 'author': 'GEOCHET', 'author_id': 5640, 'author_profile': 'https://Stackoverflow.com/users/5640', 'pm_score': 0, 'selected': False, 'text': "<p>If you drag text to the toolbox doesn't it appear?</p>\n"}, {'answer_id': 74644, 'author': 'John Sheehan', 'author_id': 1786, 'author_profile': 'https://Stackoverflow.com/users/1786', 'pm_score': 0, 'selected': False, 'text': "<p>It was removed in Visual Studio 2005. I'm trying to find a source for this.</p>\n"}, {'answer_id': 74901, 'author': 'dummy', 'author_id': 6297, 'author_profile': 'https://Stackoverflow.com/users/6297', 'pm_score': 1, 'selected': False, 'text': '<p>You should give <a href="http://ditto-cp.sourceforge.net/" rel="nofollow noreferrer">Ditto</a> a try. It saves everything you put in your clipboard into an sqlite database. A shortcut pops it up and shows the history of your clippings. </p>\n\n<p>The nice thing is that you can instantly search in this window through all your clippings. </p>\n\n<p>I set it up to remeber everything in my clipboard for 60 days and made a habit of copying everything that might be usefull. That way I can quickly find that particular SQL statement, i did last week. Just dont search for "select" ;-)</p>\n\n<p>Try it for some days and you will be amazed. There is also a <a href="http://prdownloads.sourceforge.net/ditto-cp/Ditto_Portable_3_15_4_0.zip?download" rel="nofollow noreferrer">portable Version</a></p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74604', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13110/']
74,612
<p>I have a table inside a div. I want the table to occupy the entire width of the div tag.</p> <p>In the CSS, I've set the <code>width</code> of the table to <code>100%</code>. Unfortunately, when the div has some <code>margin</code> on it, the table ends up wider than the div it's in.</p> <p>I need to support IE6 and IE7 (as this is an internal app), although I'd obviously like a fully cross-browser solution if possible!</p> <p>I'm using the following DOCTYPE...</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; </code></pre> <hr> <p><strong>Edit</strong>: Unfortunately I can't hard-code the width as I'm dynamically generating the HTML and it includes nesting the divs recursively inside each other (with left margin on each div, this creates a nice 'nested' effect).</p>
[{'answer_id': 74715, 'author': 'Nate', 'author_id': 12779, 'author_profile': 'https://Stackoverflow.com/users/12779', 'pm_score': 3, 'selected': False, 'text': '<p>The following works for me in Firefox and IE7... a guideline, though is: if you set width on an element, don\'t set margin or padding on the same element. This holds true <em>especially</em> if you\'re mixing units -- say, mixing percents and pixels.</p>\n\n<pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;\n\n&lt;html&gt;\n &lt;head&gt;\n &lt;title&gt;Test&lt;/title&gt;\n &lt;/head&gt;\n &lt;body&gt;\n &lt;div style="width: 500px; background-color:#F33;"&gt;\n This is the outer div\n &lt;div style="background-color: #FAA; padding: 10px; margin:10px;"&gt;\n This is the inner div\n &lt;table cellpadding="0" cellspacing="0" style="width: 100%"&gt;\n &lt;tr&gt;\n &lt;td style="border: 1px solid blue; background-color:#FEE;"&gt;Here is my td&lt;/td&gt;\n &lt;/tr&gt;\n &lt;/table&gt;\n &lt;/div&gt;\n &lt;/div&gt;\n &lt;/body&gt;\n&lt;/html&gt;\n</code></pre>\n\n<p>See <a href="http://bl.ocks.org/1752582" rel="nofollow noreferrer">here</a> for an example.</p>\n'}, {'answer_id': 74799, 'author': 'Nate', 'author_id': 12779, 'author_profile': 'https://Stackoverflow.com/users/12779', 'pm_score': 1, 'selected': False, 'text': "<p>In the case where you're automatically generating code that may have margins on it, adding a simple, unstyled <code>&lt;div&gt;</code> element wrapping your table might do the trick.</p>\n"}, {'answer_id': 74913, 'author': 'buti-oxa', 'author_id': 2515, 'author_profile': 'https://Stackoverflow.com/users/2515', 'pm_score': 0, 'selected': False, 'text': '<p>That is the big problem with the way CSS treats width property and the reason Microsoft implemented box model differently at first. Microsoft lost, and now it\'s either width or margin/padding/border for an element. </p>\n\n<p>Situation may change to better in CSS3 with <a href="http://www.css3.info/preview/box-sizing/" rel="nofollow noreferrer">box-sizing property</a></p>\n'}, {'answer_id': 75100, 'author': 'Joe Morgan', 'author_id': 13244, 'author_profile': 'https://Stackoverflow.com/users/13244', 'pm_score': 1, 'selected': False, 'text': '<p>I\'ve always used <code>&lt;table width="100%"&gt;</code></p>\n'}, {'answer_id': 75343, 'author': 'Christian Davén', 'author_id': 12534, 'author_profile': 'https://Stackoverflow.com/users/12534', 'pm_score': 0, 'selected': False, 'text': '<p>Maybe this extensive article about <a href="http://www.456bereastreet.com/archive/200612/internet_explorer_and_the_css_box_model/" rel="nofollow noreferrer">Internet Explorer and the CSS box model</a> will help?</p>\n'}, {'answer_id': 76242, 'author': 'farzad', 'author_id': 9394, 'author_profile': 'https://Stackoverflow.com/users/9394', 'pm_score': 0, 'selected': False, 'text': "<p>try this:</p>\n\n<pre><code>div {\n padding: 0px;\n}\n\ntable {\n width: 100%;\n margin: 0px;\n}\n</code></pre>\n\n<p>by setting the padding of the div to zero, you will remove the space between the borders of the div and the content of it. by setting the width of the table to 100% and it's margin to zero, you will remove the space between the borders of the table and it's container.</p>\n"}, {'answer_id': 76478, 'author': 'Eric DeLabar', 'author_id': 7556, 'author_profile': 'https://Stackoverflow.com/users/7556', 'pm_score': 2, 'selected': False, 'text': "<p>Percentage-based widths are relative to the first parent element that has a width specified. If your div does not have a width specified then the width of the table has nothing to do with it. Can you post a simplified version of the markup that shows what your <code>DOM</code> tree looks like? </p>\n\n<p>From another angle, if your parent div DOES have a width set and the margin is still affecting your table then you are probably in quirks mode. You have specified your <code>DOCTYPE</code>, but be aware that the <code>DOCTYPE</code> element MUST be the first line in the file. Something else to note when dealing with <code>IE6</code>, by default, if your content is wider than your parent, the parent will be stretched to accommodate, you can stop this by adding <code>overflow: hidden</code> to your <code>css</code> for the parent element but in the process you might obscure some of the child element's content. </p>\n"}, {'answer_id': 84685, 'author': 'David Heggie', 'author_id': 4309, 'author_profile': 'https://Stackoverflow.com/users/4309', 'pm_score': 2, 'selected': False, 'text': '<p>Not really sure what the problem is here - this works fine in IE6/7 and FF3. Setting the width of the .container DIV element sets the table\'s width. Adding margins to the .container div doesn\'t affect the table. Maybe there\'s something else in your markup / CSS that\'s affecting the layout?</p>\n\n<pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"\n"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;\n\n&lt;html&gt;\n &lt;head&gt;\n &lt;title&gt;Boxes and Tables&lt;/title&gt;\n &lt;style type="text/css"&gt;\n\n div.container {\n background-color: yellow;\n border: 1px solid #000;\n width: 500px;\n margin: 5px auto;\n }\n\n table.contained {\n width: 100%;\n border-collapse: collapse;\n }\n\n table td {\n border: 2px solid #999;\n }\n\n &lt;/style&gt;\n &lt;/head&gt;\n\n &lt;body&gt;\n &lt;div class="container"&gt;\n &lt;table class="contained"&gt;\n &lt;thead&gt;\n &lt;tr&gt;&lt;th&gt;Column1&lt;/th&gt;&lt;th&gt;Column2&lt;/th&gt;&lt;th&gt;Column3&lt;/th&gt;&lt;/tr&gt;\n &lt;/thead&gt;\n &lt;tbody&gt;\n &lt;tr&gt;&lt;td&gt;Value&lt;/td&gt;&lt;td&gt;Value&lt;/td&gt;&lt;td&gt;Value&lt;/td&gt;&lt;/tr&gt;\n &lt;tr&gt;&lt;td&gt;Value&lt;/td&gt;&lt;td&gt;Value&lt;/td&gt;&lt;td&gt;Value&lt;/td&gt;&lt;/tr&gt;\n &lt;tr&gt;&lt;td&gt;Value&lt;/td&gt;&lt;td&gt;Value&lt;/td&gt;&lt;td&gt;Value&lt;/td&gt;&lt;/tr&gt;\n &lt;tr&gt;&lt;td&gt;Value&lt;/td&gt;&lt;td&gt;Value&lt;/td&gt;&lt;td&gt;Value&lt;/td&gt;&lt;/tr&gt;\n &lt;tr&gt;&lt;td&gt;Value&lt;/td&gt;&lt;td&gt;Value&lt;/td&gt;&lt;td&gt;Value&lt;/td&gt;&lt;/tr&gt;\n &lt;/tbody&gt;\n &lt;/table&gt;\n &lt;/div&gt;\n &lt;/body&gt;\n&lt;/html&gt;\n</code></pre>\n'}, {'answer_id': 84714, 'author': 'Konrad Rudolph', 'author_id': 1968, 'author_profile': 'https://Stackoverflow.com/users/1968', 'pm_score': 0, 'selected': False, 'text': '<p>Incidentally, is there a good reason for you not to use the strict doctype? strict should always be the default. transitional is only intended for legacy code.</p>\n'}, {'answer_id': 650759, 'author': 'Chris', 'author_id': 13700, 'author_profile': 'https://Stackoverflow.com/users/13700', 'pm_score': 2, 'selected': False, 'text': "<p>I figured out the heart of the problem here. It has to do with <code>border-collapse</code>. I've had this same problem for a while now. Since tables often have thin borders the problem is not obvious to most people. If you put a regular table with width set to 100% inside a div, as Nate has, you will be fine.</p>\n\n<p>However, if you specify <code>border-collapse:collapse</code> on the table, the table will break out of the div. This is not obvious to most people because it may only break out by one pixel, or depending on the context it's in and the user agent, perhaps not at all.</p>\n\n<p>To make it clearer what is going on, try this: Put Nate's example next to David Heggie's example in an html file.</p>\n\n<p>It will look like both work fine. But now, change Nate's inline TD style to <code>border: 40px solid blue</code>. Change David's table td style to <code>border: 40px solid #999;</code>. At this point, David's table breaks out of the div by 50% of its border on each side. Nate's still works.\nPut a <code>border-collapse:collapse</code> style on Nate's table and his breaks now too.</p>\n\n<p>It's the <code>border-collapse</code> that is causing it!</p>\n"}, {'answer_id': 3908157, 'author': 'Nestor', 'author_id': 470854, 'author_profile': 'https://Stackoverflow.com/users/470854', 'pm_score': 0, 'selected': False, 'text': '<p>The following code works on IE6/8, Chrome, Firefox, Safari:</p>\n\n<pre><code>&lt;style type="text/css"&gt;\n div.container \n {\n width: 500px;\n padding: 10px;\n margin: 10px;\n border: 1px solid red;\n }\n table.contained \n {\n width: 100%;\n border: 1px solid blue;\n }\n&lt;/style&gt;\n\n&lt;div class="container"&gt;\n &lt;table class="contained"&gt;\n &lt;tr&gt;\n &lt;td&gt;Hello&lt;/td&gt;&lt;td&gt;World&lt;/td&gt;\n &lt;/tr&gt;\n &lt;/table&gt;\n&lt;/div&gt;\n</code></pre>\n\n<p>Try copy and paste and build on it (just move the style part to the header or to a separate .css file), maybe the way you using of putting the CSS inline (using the style tag) has something to do with the problem, or it is some other CSS surrounding the div table blocks? Floating can also give troubles.</p>\n\n<p>P.S. I set red and blue borders to see where the areas expand to for a more visual check.</p>\n'}, {'answer_id': 12907189, 'author': 'William', 'author_id': 1562498, 'author_profile': 'https://Stackoverflow.com/users/1562498', 'pm_score': 0, 'selected': False, 'text': '<p>overflow: auto; on the outermost div may help if you are seeing weird things - like the outermost div being smaller than you want it or not taking up the entire size of the divs inside of it.</p>\n'}, {'answer_id': 28622543, 'author': 'Sharad Biradar', 'author_id': 2114874, 'author_profile': 'https://Stackoverflow.com/users/2114874', 'pm_score': 5, 'selected': False, 'text': '<p>Add the below CSS to your <code>&lt;table&gt;</code>:</p>\n\n<pre><code>table-layout: fixed;\nwidth: 100%;\n</code></pre>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74612', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/475/']
74,614
<p>Every project I compile with Delphi 7, in which I do <strong><em>not</em></strong> compile with run-time packages, gives a linker error: "Too many resources". Even a blank application gives this error.</p> <p>In other words: Delphi died on me.</p>
[{'answer_id': 74647, 'author': 'JosephStyons', 'author_id': 672, 'author_profile': 'https://Stackoverflow.com/users/672', 'pm_score': 1, 'selected': False, 'text': '<p>What happens when you try to build it from the command line?\n(i.e., \\Program Files\\Borland\\Delphi7\\Bin\\dcc32.exe)</p>\n\n<p>Also, have you build any custom .RES files for this project? If not, try deleting the default .RES that Delphi created for you, and let it get re-created by the project.</p>\n\n<p>You can also force an update to the .RES file by changing something trivial, like the version #, saving your project, then changing it back again.</p>\n\n<p>Sorry these are not answers... but hopefully we will find the issue with a little poking around.</p>\n'}, {'answer_id': 74658, 'author': 'Francesca', 'author_id': 9842, 'author_profile': 'https://Stackoverflow.com/users/9842', 'pm_score': 1, 'selected': False, 'text': "<p>Make sure you don't duplicate the resource inclusion, like having multiple {$R *.dfm} lines in a unit or multiple {$R *.res} for the project. Could also be included anywhere in a unit like {$R MyProject.res} as well...</p>\n"}, {'answer_id': 74678, 'author': 'Lars Fosdal', 'author_id': 10002, 'author_profile': 'https://Stackoverflow.com/users/10002', 'pm_score': 0, 'selected': False, 'text': '<p>Most likely a corrupted project.res file. Try renaming the old and see if it is successfully recreated?</p>\n'}, {'answer_id': 11429758, 'author': 'Abhineet', 'author_id': 1292600, 'author_profile': 'https://Stackoverflow.com/users/1292600', 'pm_score': 0, 'selected': False, 'text': '<p>I get this error in few projects in Delphi 6.</p>\n\n<p>I found a workaround for this. PFB the details: (Take a backup of the .res file if it is modified)</p>\n\n<ol>\n<li>Change {$R .res} to {$R *.res}</li>\n<li>Compile the project</li>\n<li>Delete the .res file and place the original file (whose backup was taken)</li>\n<li>Change the {$ *.res} to {$R .res}</li>\n<li>Hit Compile/Build</li>\n</ol>\n'}, {'answer_id': 31096773, 'author': 'Rohit Gupta', 'author_id': 4779472, 'author_profile': 'https://Stackoverflow.com/users/4779472', 'pm_score': 0, 'selected': False, 'text': '<p>This sometimes happens when you migrate a project from a previous version of Delphi. The solution as mentioned earlier is to delete the <strong>.res</strong> file.</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74614', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']
74,616
<p>example:</p> <pre><code>public static void DoSomething&lt;K,V&gt;(IDictionary&lt;K,V&gt; items) { items.Keys.Each(key =&gt; { if (items[key] **is IEnumerable&lt;?&gt;**) { /* do something */ } else { /* do something else */ } } </code></pre> <p>Can this be done without using reflection? How do I say IEnumerable in C#? Should I just use IEnumerable since IEnumerable&lt;> implements IEnumerable? </p>
[{'answer_id': 74648, 'author': 'Jorge Ferreira', 'author_id': 6508, 'author_profile': 'https://Stackoverflow.com/users/6508', 'pm_score': 2, 'selected': False, 'text': '<pre><code>if (typeof(IEnumerable).IsAssignableFrom(typeof(V))) {\n</code></pre>\n'}, {'answer_id': 74772, 'author': 'Isak Savo', 'author_id': 8521, 'author_profile': 'https://Stackoverflow.com/users/8521', 'pm_score': 0, 'selected': False, 'text': '<p>I\'m not sure I understand what you mean here. Do you want to know if the object is of <strong>any generic type</strong> or do you want to test if it is a <strong>specific generic type</strong>? Or do you just want to know if is enumerable?</p>\n\n<p>I don\'t think the first is possible. The second is definitely possible, just treat it as any other type. For the third, just test it against IEnumerable as you suggested.</p>\n\n<p>Also, you cannot use the \'is\' operator on types. </p>\n\n<pre><code>// Not allowed\nif (string is Object)\n Foo();\n// You have to use \nif (typeof(object).IsAssignableFrom(typeof(string))\n Foo();\n</code></pre>\n\n<p>See <a href="https://stackoverflow.com/questions/72360/how-to-use-the-is-operator-in-systemtype-variables">this question about types</a> for more details. Maybe it\'ll help you.</p>\n'}, {'answer_id': 75266, 'author': 'Paul van Brenk', 'author_id': 1837197, 'author_profile': 'https://Stackoverflow.com/users/1837197', 'pm_score': -1, 'selected': False, 'text': '<p>You want to check out the <a href="http://msdn.microsoft.com/en-us/library/system.type.isinstanceoftype.aspx" rel="nofollow noreferrer">Type.IsInstanceOfType</a> method</p>\n'}, {'answer_id': 75341, 'author': 'Thomas Danecker', 'author_id': 9632, 'author_profile': 'https://Stackoverflow.com/users/9632', 'pm_score': 1, 'selected': False, 'text': "<p>I'd use overloading:</p>\n\n<pre><code>public static void DoSomething&lt;K,V&gt;(IDictionary&lt;K,V&gt; items)\n where V : IEnumerable\n{\n items.Keys.Each(key =&gt; { /* do something */ });\n}\n\npublic static void DoSomething&lt;K,V&gt;(IDictionary&lt;K,V&gt; items)\n{\n items.Keys.Each(key =&gt; { /* do something else */ });\n}\n</code></pre>\n"}, {'answer_id': 75502, 'author': 'Konrad Rudolph', 'author_id': 1968, 'author_profile': 'https://Stackoverflow.com/users/1968', 'pm_score': 6, 'selected': True, 'text': '<p><a href="https://stackoverflow.com/a/74648/1968">The previously accepted answer</a> is nice but it is wrong. Thankfully, the error is a small one. Checking for <code>IEnumerable</code> is not enough if you really want to know about the generic version of the interface; there are a lot of classes that implement only the nongeneric interface. I\'ll give the answer in a minute. First, though, I\'d like to point out that the accepted answer is overly complicated, since the following code would achieve the same under the given circumstances:</p>\n\n<pre><code>if (items[key] is IEnumerable)\n</code></pre>\n\n<p>This does even more because it works for each item separately (and not on their common subclass, <code>V</code>).</p>\n\n<p>Now, for the correct solution. This is a bit more complicated because we have to take the generic type <code>IEnumerable`1</code> (that is, the type <code>IEnumerable&lt;&gt;</code> with one type parameter) and inject the right generic argument:</p>\n\n<pre><code>static bool IsGenericEnumerable(Type t) {\n var genArgs = t.GetGenericArguments();\n if (genArgs.Length == 1 &amp;&amp;\n typeof(IEnumerable&lt;&gt;).MakeGenericType(genArgs).IsAssignableFrom(t))\n return true;\n else\n return t.BaseType != null &amp;&amp; IsGenericEnumerable(t.BaseType);\n}\n</code></pre>\n\n<p>You can test the correctness of this code easily:</p>\n\n<pre><code>var xs = new List&lt;string&gt;();\nvar ys = new System.Collections.ArrayList();\nConsole.WriteLine(IsGenericEnumerable(xs.GetType()));\nConsole.WriteLine(IsGenericEnumerable(ys.GetType()));\n</code></pre>\n\n<p>yields:</p>\n\n<pre><code>True\nFalse\n</code></pre>\n\n<p>Don\'t be overly concerned by the fact that this uses reflection. While it\'s true that this adds runtime overhead, so does the use of the <code>is</code> operator.</p>\n\n<p>Of course the above code is awfully constrained and could be expanded into a more generally applicable method, <code>IsAssignableToGenericType</code>. The following implementation is slightly incorrect<sup>1</sup> and I’ll leave it here <em>for historic purposes only</em>. <strong>Do not use it</strong>. Instead, <a href="https://stackoverflow.com/a/1075059/1968">James has provided an excellent, correct implementation in his answer.</a></p>\n\n<pre><code>public static bool IsAssignableToGenericType(Type givenType, Type genericType) {\n var interfaceTypes = givenType.GetInterfaces();\n\n foreach (var it in interfaceTypes)\n if (it.IsGenericType)\n if (it.GetGenericTypeDefinition() == genericType) return true;\n\n Type baseType = givenType.BaseType;\n if (baseType == null) return false;\n\n return baseType.IsGenericType &amp;&amp;\n baseType.GetGenericTypeDefinition() == genericType ||\n IsAssignableToGenericType(baseType, genericType);\n}\n</code></pre>\n\n<p><sup>1</sup> It fails when the <code>genericType</code> is the same as <code>givenType</code>; for the same reason, it fails for nullable types, i.e.</p>\n\n<pre><code>IsAssignableToGenericType(typeof(List&lt;int&gt;), typeof(List&lt;&gt;)) == false\nIsAssignableToGenericType(typeof(int?), typeof(Nullable&lt;&gt;)) == false\n</code></pre>\n\n<p>I’ve created a <a href="https://gist.github.com/4174727" rel="noreferrer">gist with a comprehensive suite of test cases</a>.</p>\n'}, {'answer_id': 75600, 'author': 'Rich Visotcky', 'author_id': 400730, 'author_profile': 'https://Stackoverflow.com/users/400730', 'pm_score': 3, 'selected': False, 'text': '<p>A word of warning about generic types and using IsAssignableFrom()...</p>\n\n<p>Say you have the following:</p>\n\n<pre><code>public class MyListBase&lt;T&gt; : IEnumerable&lt;T&gt; where T : ItemBase\n{\n}\n\npublic class MyItem : ItemBase\n{\n}\n\npublic class MyDerivedList : MyListBase&lt;MyItem&gt;\n{\n}\n</code></pre>\n\n<p>Calling IsAssignableFrom on the base list type or on the derived list type will return false, yet clearly <code>MyDerivedList</code> inherits <code>MyListBase&lt;T&gt;</code>. (A quick note for Jeff, generics absolutely <em>must</em> be wrapped in a code block or tildes to get the <code>&lt;T&gt;</code>, otherwise it\'s omitted. Is this intended?) The problem stems from the fact that <code>MyListBase&lt;MyItem&gt;</code> is treated as an entirely different type than <code>MyListBase&lt;T&gt;</code>. The following article could explain this a little better. <a href="http://mikehadlow.blogspot.com/2006/08/reflecting-generics.html" rel="nofollow noreferrer">http://mikehadlow.blogspot.com/2006/08/reflecting-generics.html</a></p>\n\n<p>Instead, try the following recursive function:</p>\n\n<pre><code> public static bool IsDerivedFromGenericType(Type givenType, Type genericType)\n {\n Type baseType = givenType.BaseType;\n if (baseType == null) return false;\n if (baseType.IsGenericType)\n {\n if (baseType.GetGenericTypeDefinition() == genericType) return true;\n }\n return IsDerivedFromGenericType(baseType, genericType);\n }\n</code></pre>\n\n<p>/EDIT: Konrad\'s new post which takes the generic recursion into account as well as interfaces is spot on. Very nice work. :)</p>\n\n<p>/EDIT2: If a check is made on whether genericType is an interface, performance benefits could be realized. The check can be an if block around the current interface code, but if you\'re interested in using .NET 3.5, a friend of mine offers the following:</p>\n\n<pre><code> public static bool IsAssignableToGenericType(Type givenType, Type genericType)\n {\n var interfaces = givenType.GetInterfaces().Where(it =&gt; it.IsGenericType).Select(it =&gt; it.GetGenericTypeDefinition());\n var foundInterface = interfaces.FirstOrDefault(it =&gt; it == genericType);\n if (foundInterface != null) return true;\n\n Type baseType = givenType.BaseType;\n if (baseType == null) return false;\n\n return baseType.IsGenericType ?\n baseType.GetGenericTypeDefinition() == genericType :\n IsAssignableToGenericType(baseType, genericType);\n }\n</code></pre>\n'}, {'answer_id': 390981, 'author': 'Hosam Aly', 'author_id': 41283, 'author_profile': 'https://Stackoverflow.com/users/41283', 'pm_score': 0, 'selected': False, 'text': '<p>I used to think such a situation may be solvable in a way similar to @Thomas Danecker\'s <a href="https://stackoverflow.com/questions/74616/how-to-detect-if-type-is-another-generic-type#75341">solution</a>, but adding another template argument:</p>\n\n<pre><code>public static void DoSomething&lt;K, V, U&gt;(IDictionary&lt;K,V&gt; items)\n where V : IEnumerable&lt;U&gt; { /* do something */ }\npublic static void DoSomething&lt;K, V&gt;(IDictionary&lt;K,V&gt; items)\n { /* do something else */ }\n</code></pre>\n\n<p>But I noticed now that it does\'t work unless I specify the template arguments of the first method explicitly. This is clearly not customized per each item in the dictionary, but it may be a kind of poor-man\'s solution.</p>\n\n<p>I would be very thankful if someone could point out anything incorrect I might have done here.</p>\n'}, {'answer_id': 1075059, 'author': 'James Fraumeni', 'author_id': 132345, 'author_profile': 'https://Stackoverflow.com/users/132345', 'pm_score': 7, 'selected': False, 'text': "<p>Thanks very much for this post. I wanted to provide a version of Konrad Rudolph's solution that has worked better for me. I had minor issues with that version, notably when testing if a Type is a nullable value type:</p>\n\n<pre><code>public static bool IsAssignableToGenericType(Type givenType, Type genericType)\n{\n var interfaceTypes = givenType.GetInterfaces();\n\n foreach (var it in interfaceTypes)\n {\n if (it.IsGenericType &amp;&amp; it.GetGenericTypeDefinition() == genericType)\n return true;\n }\n\n if (givenType.IsGenericType &amp;&amp; givenType.GetGenericTypeDefinition() == genericType)\n return true;\n\n Type baseType = givenType.BaseType;\n if (baseType == null) return false;\n\n return IsAssignableToGenericType(baseType, genericType);\n}\n</code></pre>\n"}, {'answer_id': 8684023, 'author': 'Matt Johnson-Pint', 'author_id': 634824, 'author_profile': 'https://Stackoverflow.com/users/634824', 'pm_score': 2, 'selected': False, 'text': "<p>Thanks for the great info. For convienience, I've refactored this into an extension method and reduced it to a single statement.</p>\n\n<pre><code>public static bool IsAssignableToGenericType(this Type givenType, Type genericType)\n{\n return givenType.GetInterfaces().Any(t =&gt; t.IsGenericType &amp;&amp; t.GetGenericTypeDefinition() == genericType) ||\n givenType.BaseType != null &amp;&amp; (givenType.BaseType.IsGenericType &amp;&amp; givenType.BaseType.GetGenericTypeDefinition() == genericType ||\n givenType.BaseType.IsAssignableToGenericType(genericType));\n}\n</code></pre>\n\n<p>Now it can be easily called with:</p>\n\n<p>sometype.IsAssignableToGenericType(typeof(MyGenericType&lt;>))</p>\n"}]
2008/09/16
['https://Stackoverflow.com/questions/74616', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12934/']
74,620
<p>Can't understand why the following takes place:</p> <pre><code>String date = "06-04-2007 07:05"; SimpleDateFormat fmt = new SimpleDateFormat("MM-dd-yyyy HH:mm"); Date myDate = fmt.parse(date); System.out.println(myDate); //Mon Jun 04 07:05:00 EDT 2007 long timestamp = myDate.getTime(); System.out.println(timestamp); //1180955100000 -- where are the milliseconds? // on the other hand... myDate = new Date(); System.out.println(myDate); //Tue Sep 16 13:02:44 EDT 2008 timestamp = myDate.getTime(); System.out.println(timestamp); //1221584564703 -- why, oh, why? </code></pre>
[{'answer_id': 74652, 'author': 'Vinko Vrsalovic', 'author_id': 5190, 'author_profile': 'https://Stackoverflow.com/users/5190', 'pm_score': 5, 'selected': True, 'text': '<p>What milliseconds? You are providing only minutes information in the first example, whereas your second example grabs current date from the system with milliseconds, what is it you\'re looking for?</p>\n\n<pre><code>String date = "06-04-2007 07:05:00.999";\nSimpleDateFormat fmt = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss.S");\nDate myDate = fmt.parse(date);\n\nSystem.out.println(myDate); \nlong timestamp = myDate.getTime();\nSystem.out.println(timestamp);\n</code></pre>\n'}, {'answer_id': 74683, 'author': 'Mostlyharmless', 'author_id': 12881, 'author_profile': 'https://Stackoverflow.com/users/12881', 'pm_score': 2, 'selected': False, 'text': '<p>Because simple date format you specified discards the milliseconds. So the resulting Date object does not have that info. So when you print it out, its all 0s.</p>\n\n<p>On the other hand, the Date object does retain the milliseconds when you assign it a value with milliseconds (in this case, using new Date()). So when you print them out, it contains the millisecs too.</p>\n'}, {'answer_id': 74685, 'author': 'ScArcher2', 'author_id': 1310, 'author_profile': 'https://Stackoverflow.com/users/1310', 'pm_score': 0, 'selected': False, 'text': '<p>When you parse a date it only uses the information you provide.\nIn this case it only knows MM-dd-yyyy HH:mm.</p>\n\n<p>Creating a new date object returns the current system date/time (number of milliseconds since the epoch). </p>\n'}, {'answer_id': 74694, 'author': 'tim_yates', 'author_id': 6509, 'author_profile': 'https://Stackoverflow.com/users/6509', 'pm_score': 0, 'selected': False, 'text': '<p>toString() of a Date object does not show you the milliseconds... But they are there</p>\n\n<p>So new Date() is an object with milisecond resolution, as can be seen by:</p>\n\n<pre><code> System.out.printf( "ms = %d\\n", myDate.getTime() % 1000 ) ;\n</code></pre>\n\n<p>However, when you construct your date with SimpleDateFormat, no milliseconds are passed to it</p>\n\n<p>Am I missing the question here?</p>\n\n<p>[edit] Hahaha...way too slow ;)</p>\n'}, {'answer_id': 75140, 'author': 'laz', 'author_id': 8753, 'author_profile': 'https://Stackoverflow.com/users/8753', 'pm_score': 0, 'selected': False, 'text': '<p>Date.getTime returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by the Date object. So "06-04-2007 07:05" - "01-01-1970 00:00" is equal to 1180955340000 milliseconds. Since the only concern of your question is about the time portion of the date, a rough way of thinking of this calculation is the number of milliseconds between 07:05 and 00:00 which is 25500000. This is evenly divisible by 1000 since neither time has any milliseconds.</p>\n\n<p>In the second date it uses the current time when that line of code is executed. That will use whatever the current milliseconds past the current second are in the calculation. Therefore, Date.getTime will more than likely return a number that is not evenly divisible by 1000.</p>\n'}, {'answer_id': 76006, 'author': 'Michael', 'author_id': 13379, 'author_profile': 'https://Stackoverflow.com/users/13379', 'pm_score': 0, 'selected': False, 'text': '<p>The <code>getTime()</code> method of <code>Date</code> returns the number of milliseconds since January 1, 1970 (this date is called the "epoch" because all computer dates are based off of this date). It should <strong>not</strong> be used to display a human-readable version of your Date.</p>\n\n<p>Use the <code>SimpleDateFormat.format()</code> method instead. Here is a revised version of part of your code that I think may solve your problem:</p>\n\n<pre><code>String date = "06-04-2007 07:05:23:123";\nSimpleDateFormat fmt = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss:S");\nDate myDate = fmt.parse(date); \n\nSystem.out.println(myDate); //Mon Jun 04 07:05:23 EDT 2007\nString formattedDate = fmt.format(myDate);\nSystem.out.println(formattedDate); //06-04-2007 07:05:23:123\n</code></pre>\n'}, {'answer_id': 78965, 'author': 'Ryan Delucchi', 'author_id': 9931, 'author_profile': 'https://Stackoverflow.com/users/9931', 'pm_score': 2, 'selected': False, 'text': '<p>Instead of using the Sun JDK Time/Date libraries (which leave much to be desired) I recommend taking a look at <a href="http://joda-time.sourceforge.net" rel="nofollow noreferrer">http://joda-time.sourceforge.net</a>.</p>\n\n<p>This is a very mature and active sourceforge project and has a very elegant API.</p>\n'}, {'answer_id': 647220, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<pre><code>import java.util.*;\n\npublic class Time {\n public static void main(String[] args) {\n Long l = 0L;\n Calendar c = Calendar.getInstance();\n //milli sec part of current time\n l = c.getTimeInMillis() % 1000; \n //current time without millisec\n StringBuffer sb = new StringBuffer(c.getTime().toString());\n //millisec in string\n String s = ":" + l.toString();\n //insert at right place\n sb.insert(19, s);\n //ENJOY\n System.out.println(sb);\n }\n}\n</code></pre>\n'}, {'answer_id': 61567225, 'author': 'Basil Bourque', 'author_id': 642706, 'author_profile': 'https://Stackoverflow.com/users/642706', 'pm_score': 1, 'selected': False, 'text': '<h1>tl;dr</h1>\n\n<p>The accepted <a href="https://stackoverflow.com/a/74652/642706">Answer by Vinko Vrsalovic</a> is correct. Your input is whole minutes, so the milliseconds for fractional second should indeed be zero.</p>\n\n<p>Use <em>java.time</em>.</p>\n\n<pre><code>LocalDateTime.parse\n( \n "06-04-2007 07:05" , \n DateTimeFormatter.ofPattern( "MM-dd-uuuu HH:mm" ) \n)\n.atZone\n(\n ZoneId.of( "Africa/Casablanca" ) \n)\n.toInstant()\n.getEpochMilli()\n</code></pre>\n\n<h1><em>java.time</em></h1>\n\n<p>The modern approach uses the <em>java.time</em> classes defined in JSR 310 that years ago supplanted the terrible classes you are using.</p>\n\n<p>Define a formatting pattern to match your input. FYI: Learn to use standard ISO 8601 formats for exchanging date-time values as text.</p>\n\n<pre><code>String input = "06-04-2007 07:05" ;\nDateTimeFormatter f = DateTimeFormatter.ofPattern( "MM-dd-uuuu HH:mm" ) ;\n</code></pre>\n\n<p>Parse your input as a <code>LocalDateTime</code>, as it lacks an indicator of time zone or offset-from-UTC.</p>\n\n<pre><code>LocalDateTime ldt = LocalDateTime.parse( input , f ) ;\n</code></pre>\n\n<p>This represents a date and a time-of-day, but lacks the context of a time zone or offset. So we do not know if you meant 7 AM in Tokyo Japan, 7 AM in Toulouse France, or 7 AM in Toledo Ohio US. This issue of time zone is crucial, because your desired count of milliseconds is a count since the first moment of 1970 as seen in UTC (an offset of zero hours-minutes-seconds), 1970-01-01T00:00Z. </p>\n\n<p>So we must place your input value, the <a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/time/LocalDateTime.html" rel="nofollow noreferrer"><code>LocalDateTime</code></a> object, in the context of a time zone or offset. </p>\n\n<p>If your input was intended to represent a date and time in UTC, use <a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/time/OffsetDateTime.html" rel="nofollow noreferrer"><code>OffsetDateTime</code></a> with <a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/time/ZoneOffset.html#UTC" rel="nofollow noreferrer"><code>ZoneOffset.UTC</code></a>.</p>\n\n<pre><code>OffsetDateTime odt = ldt.atOffset( ZoneOffset.UTC ) ; // Do this if your date and time represent a moment as seen in UTC. \n</code></pre>\n\n<p>If your input was intended to represent a date and time as seen through the wall-clock time used by the people of a particular region, use <a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/time/ZonedDateTime.html" rel="nofollow noreferrer"><code>ZonedDateTime</code></a>. </p>\n\n<pre><code>ZoneId z = ZoneId.of( "Asia/Tokyo" ) ;\nZonedDateTime zdt = ldt.atZone( z ) ;\n</code></pre>\n\n<p>Next we want to interrogate for the count of milliseconds since the epoch of first moment of 1970 in UTC. With either a <code>OffsetDateTime</code> or <code>ZonedDateTime</code> object in hand, extract a <code>Instant</code> by calling <code>toInstant</code>. </p>\n\n<pre><code>Instant instant = odt.toInstant() ;\n</code></pre>\n\n<p>…or…</p>\n\n<pre><code>Instant instant = zdt.toInstant() ;\n</code></pre>\n\n<p>Now get count of milliseconds. </p>\n\n<pre><code>long millisecondsSinceEpoch = instant.toEpochMilli() ;\n</code></pre>\n\n<p>By the way, I suggest you not track time by a count of milliseconds. Use ISO 8601 formatted text instead: easy to parse by machine, easy to read by humans across cultures. A count of milliseconds is neither. </p>\n\n<hr>\n\n<p><a href="https://i.stack.imgur.com/CNlDF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CNlDF.png" alt="Table of date-time types in Java, both modern and legacy"></a></p>\n\n<hr>\n\n<h1>About <em>java.time</em></h1>\n\n<p>The <a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/time/package-summary.html" rel="nofollow noreferrer"><em>java.time</em></a> framework is built into Java 8 and later. These classes supplant the troublesome old <a href="https://en.wikipedia.org/wiki/Legacy_system" rel="nofollow noreferrer">legacy</a> date-time classes such as <a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Date.html" rel="nofollow noreferrer"><code>java.util.Date</code></a>, <a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Calendar.html" rel="nofollow noreferrer"><code>Calendar</code></a>, &amp; <a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/text/SimpleDateFormat.html" rel="nofollow noreferrer"><code>SimpleDateFormat</code></a>.</p>\n\n<p>To learn more, see the <a href="http://docs.oracle.com/javase/tutorial/datetime/TOC.html" rel="nofollow noreferrer"><em>Oracle Tutorial</em></a>. And search Stack Overflow for many examples and explanations. Specification is <a href="https://jcp.org/en/jsr/detail?id=310" rel="nofollow noreferrer">JSR 310</a>.</p>\n\n<p>The <a href="http://www.joda.org/joda-time/" rel="nofollow noreferrer"><em>Joda-Time</em></a> project, now in <a href="https://en.wikipedia.org/wiki/Maintenance_mode" rel="nofollow noreferrer">maintenance mode</a>, advises migration to the <a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/time/package-summary.html" rel="nofollow noreferrer">java.time</a> classes.</p>\n\n<p>You may exchange <em>java.time</em> objects directly with your database. Use a <a href="https://en.wikipedia.org/wiki/JDBC_driver" rel="nofollow noreferrer">JDBC driver</a> compliant with <a href="http://openjdk.java.net/jeps/170" rel="nofollow noreferrer">JDBC 4.2</a> or later. No need for strings, no need for <code>java.sql.*</code> classes. Hibernate 5 &amp; JPA 2.2 support <em>java.time</em>. </p>\n\n<p>Where to obtain the java.time classes? </p>\n\n<ul>\n<li><a href="https://en.wikipedia.org/wiki/Java_version_history#Java_SE_8" rel="nofollow noreferrer"><strong>Java SE 8</strong></a>, <a href="https://en.wikipedia.org/wiki/Java_version_history#Java_SE_9" rel="nofollow noreferrer"><strong>Java SE 9</strong></a>, <a href="https://en.wikipedia.org/wiki/Java_version_history#Java_SE_10" rel="nofollow noreferrer"><strong>Java SE 10</strong></a>, <a href="https://en.wikipedia.org/wiki/Java_version_history#Java_SE_11" rel="nofollow noreferrer"><strong>Java SE 11</strong></a>, and later - Part of the standard Java API with a bundled implementation.\n\n<ul>\n<li>Java 9 adds some minor features and fixes.</li>\n</ul></li>\n<li><a href="https://en.wikipedia.org/wiki/Java_version_history#Java_SE_6" rel="nofollow noreferrer"><strong>Java SE 6</strong></a> and <a href="https://en.wikipedia.org/wiki/Java_version_history#Java_SE_7" rel="nofollow noreferrer"><strong>Java SE 7</strong></a>\n\n<ul>\n<li>Most of the <em>java.time</em> functionality is back-ported to Java 6 &amp; 7 in <a href="http://www.threeten.org/threetenbp/" rel="nofollow noreferrer"><strong><em>ThreeTen-Backport</em></strong></a>.</li>\n</ul></li>\n<li><a href="https://en.wikipedia.org/wiki/Android_(operating_system)" rel="nofollow noreferrer"><strong>Android</strong></a>\n\n<ul>\n<li>Later versions of Android bundle implementations of the <em>java.time</em> classes.</li>\n<li>For earlier Android (&lt;26), the <a href="https://github.com/JakeWharton/ThreeTenABP" rel="nofollow noreferrer"><strong><em>ThreeTenABP</em></strong></a> project adapts <a href="http://www.threeten.org/threetenbp/" rel="nofollow noreferrer"><strong><em>ThreeTen-Backport</em></strong></a> (mentioned above). See <a href="http://stackoverflow.com/q/38922754/642706"><em>How to use ThreeTenABP…</em></a>.</li>\n</ul></li>\n</ul>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74620', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/10675/']
74,625
<p>A good while ago, I read <a href="http://www.viemu.com/a-why-vi-vim.html" rel="noreferrer">an article by the creator of viemu</a>, clearing up a lot of the misconceptions about vi, as well as explaining why it's a good idea (and why it's been very popular for the last 30 years+). The same guy also has <a href="http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html" rel="noreferrer">a great set of graphical cheat sheets</a> that teach the basics a few bits at a time.</p> <p>I'm convinced.</p> <p>I've been convinced for the past 2 years in fact. But I still really haven't gotten around to force myself to learn vi as my primary editor, the learning curve is just too high. When I get down to work, acceptable but immediate productivity (using my current editor) has so far won over tremendous productivity farther down the line (using vi).</p> <p>Does anybody have any good tips to help get past the learning curve? It can be straight out tips, some other tutorial or article, whatever.</p> <p>Edit: Note that I'm aware of the <a href="http://www.vim.org/" rel="noreferrer">vim/gVim</a>, <a href="http://cream.sourceforge.net/" rel="noreferrer">Cream</a> and <a href="http://code.google.com/p/macvim/" rel="noreferrer">MacVim</a> (etc.) variants of vi. I kept my question about vi to refer to the vi family as a whole. Thanks for all the great answers.</p> <h3>Update (April 2009)</h3> <p>I've been using Vim (more precisely, MacVim) in my day to day professional life since last December. I'm not going back :-)</p> <p>Good luck to everyone in their Vim mastery.</p>
[{'answer_id': 74635, 'author': 'Bob Dizzle', 'author_id': 9581, 'author_profile': 'https://Stackoverflow.com/users/9581', 'pm_score': 3, 'selected': False, 'text': '<p>delete all other text editor apps.</p>\n\n<p>Then you will have to learn it.</p>\n'}, {'answer_id': 74651, 'author': 'Dana', 'author_id': 7856, 'author_profile': 'https://Stackoverflow.com/users/7856', 'pm_score': 3, 'selected': False, 'text': '<p>The simplest way to <em>force</em> yourself might be just to remove all the other editors from your machine. Get rid of temptation :)</p>\n'}, {'answer_id': 74659, 'author': 'shyam', 'author_id': 7616, 'author_profile': 'https://Stackoverflow.com/users/7616', 'pm_score': 0, 'selected': False, 'text': '<p>delete notepad.exe and create a shortcut to vim called notepad instead :)</p>\n\n<p>or do all your coding via ssh or on a machine that has no GUI ;)</p>\n'}, {'answer_id': 74660, 'author': 'Bob Wintemberg', 'author_id': 12999, 'author_profile': 'https://Stackoverflow.com/users/12999', 'pm_score': 0, 'selected': False, 'text': "<p>I've tried keeping a small cheat sheet or sticky notes of common vi commands. I do the same thing for an IDE I use. I find if I put sticky notes of keyboard shortcuts or commands on my monitor(s) it helps me learn them. Once I've used the shortcut enough and think I remember it well, I'll remove the sticky note.</p>\n"}, {'answer_id': 74664, 'author': 'Aaron Jensen', 'author_id': 11229, 'author_profile': 'https://Stackoverflow.com/users/11229', 'pm_score': 6, 'selected': False, 'text': '<p>The first thing I\'d do is lay a piece of paper or a book over your arrow keys and your ins/home/end/pgup/down keys. Those aren\'t needed in Vi. </p>\n\n<p>Next I\'d get used to hitting ctrl+[ whenever you\'re told to hit escape. It\'s much faster and you won\'t need to take your hands off the keyboard.</p>\n\n<p>Then I\'d watch my screencasts:</p>\n\n<p><a href="http://www.youtube.com/watch?v=FcpQ7koECgk" rel="noreferrer">http://www.youtube.com/watch?v=FcpQ7koECgk</a></p>\n\n<p><a href="http://www.youtube.com/watch?v=c6WCm6z5msk" rel="noreferrer">http://www.youtube.com/watch?v=c6WCm6z5msk</a></p>\n\n<p><a href="http://www.youtube.com/watch?v=BPDoI7gflxM" rel="noreferrer">http://www.youtube.com/watch?v=BPDoI7gflxM</a></p>\n\n<p><a href="http://www.youtube.com/watch?v=J1_CfIb-3X4" rel="noreferrer">http://www.youtube.com/watch?v=J1_CfIb-3X4</a></p>\n\n<p>Then, just practice practice practice.</p>\n\n<p><em>edit</em>\nThe reason for avoiding the arrow keys is that they slow you down. One of the largest benefits of Vim is the speed it allows you. The arrow keys also prevent you from really embracing the modal nature, which is very powerful when mastered.</p>\n'}, {'answer_id': 74667, 'author': 'Guy', 'author_id': 1463, 'author_profile': 'https://Stackoverflow.com/users/1463', 'pm_score': 2, 'selected': False, 'text': "<p>Write down all the short-cuts and features that you use in your current editor while you're using it at work. Then sit down on Saturday morning and using Google and stack overflow find out how to do each one of those in vi. Probably best if you use a sheet (or sheets) of paper for this.</p>\n\n<p>Now disable/delete the other editors at work so that it'll take you longer to find and re-install them than look at your comparison sheet and do it in vi - i.e. you have no choice.</p>\n\n<p>Lastly, publish your list of crossover shortcuts from your old editor to your new one on your blog.</p>\n\n<p>Good luck!</p>\n"}, {'answer_id': 74672, 'author': 'Lucas Oman', 'author_id': 6726, 'author_profile': 'https://Stackoverflow.com/users/6726', 'pm_score': 8, 'selected': True, 'text': "<p>First of all, you may want to pick up Vim; it has a vastly superior feature set along with everything vi has.</p>\n\n<p>That said, it takes discipline to learn. If you have a job and can't afford the productivity hit (without getting fired), I'd suggest taking on a weekend project for the sole purpose of learning the editor. Keep its documentation open as you work, and be disciplined enough not to chicken out. As you learn more, become efficient and start relying on muscle memory, it won't be as hard to stick with it.</p>\n\n<p>I've been using Vim for so long that I don't even think about what keys to press to search or navigate or save. And my hands never leave the keyboard. To use Vim is one of the best choices I've made in my programming career.</p>\n"}, {'answer_id': 74692, 'author': 'Craig H', 'author_id': 2328, 'author_profile': 'https://Stackoverflow.com/users/2328', 'pm_score': 0, 'selected': False, 'text': "<p>umm, the is more of a physcology question than a programming question, but the best way I have been able to do things that I really didn't want to do is to just do it, and stop trying to thing of ways to motivate myself to do it.</p>\n\n<p>Just think of it as brushing your teeth. Do you have to motivate yourself to do it? No, you just do it.</p>\n"}, {'answer_id': 74709, 'author': 'TM.', 'author_id': 12983, 'author_profile': 'https://Stackoverflow.com/users/12983', 'pm_score': 2, 'selected': False, 'text': "<p>My recommendation is to come up with some simple programs and write them, start to finish, using VI.</p>\n\n<p>Odds are, you will be too frustrated at first by the learning curve to force yourself to use them at work or in any time-sensitive environment.</p>\n\n<p>I've done this before to get familiar with environments/editors, and it works pretty well. </p>\n\n<p>If you are having problems coming up with things to write, I recommend redoing projects you did in school (or anything else that you've done previously). This method has the added bonus of letting you see how much of a better developer you have become. :)</p>\n\n<p>Edit: forgot to mention that you should do this entirely from the console to avoid any temptation to use the mouse!</p>\n"}, {'answer_id': 74714, 'author': 'Matt Hucke', 'author_id': 2554901, 'author_profile': 'https://Stackoverflow.com/users/2554901', 'pm_score': 0, 'selected': False, 'text': "<p>Spend ten years posting to Usenet from a machine where only vi and emacs were available (and where emacs had an annoying long startup time when invoked from 'rn').</p>\n\n<p>That's how I learned it.</p>\n\n<p>But for a quicker approach, all I can recommend is that you just commit yourself to learning it, and spend a few hours working on some source code. Install vim if you don't have it already - it has wonderful syntax highlighting features.</p>\n\n<p>It's well worth it. I know that I can go to just about any Unix machine, anywhere in the western world, perhaps even through a slow dialup connection or on a GUI-less machine, and be fully productive within minutes.</p>\n"}, {'answer_id': 74726, 'author': 'Cristian Ciupitu', 'author_id': 12892, 'author_profile': 'https://Stackoverflow.com/users/12892', 'pm_score': 4, 'selected': False, 'text': '<p>You should start with <strong><a href="http://www.vim.org/" rel="noreferrer">vim</a></strong> (Vi IMproved) and especially its GUI - <strong>gVim</strong>. The GUI has menus and on Windows you can use the copy, cut and paste shortcuts, so you can replace Notepad immediately. And since the menus display the shortcuts (vim commands) you could learn a lot.</p>\n\n<p>Another thing that you should do from the beginning is to configure vi for your needs. For example, you can transform vim into a <a href="http://sontek.net/turning-vim-into-a-modern-python-ide" rel="noreferrer">Python IDE</a>. By doing this, you\'ll have no excuse for using another editor, because vi will offer you everything you need.</p>\n'}, {'answer_id': 74730, 'author': 'Jon Ericson', 'author_id': 1438, 'author_profile': 'https://Stackoverflow.com/users/1438', 'pm_score': 2, 'selected': False, 'text': "<p>Don't use <strong>X11</strong>?</p>\n\n<pre><code>$ sudu rm /usr/local/bin/emacs\n</code></pre>\n\n<p>Change your login shell to <strong>vi</strong>?</p>\n\n<p>First, force yourself to use <strong>ed</strong>, then <strong>vi</strong> will seem like a luxury?</p>\n\n<p>Use the <strong>vi</strong> key bindings in <strong>bash</strong>?</p>\n\n<p>Just start using <strong>vi</strong> all the time?</p>\n\n<p>It seems to me that learning an editor isn't terribly different from learning a language. Immersion works best.</p>\n\n<p>I use <strong>vi</strong> for really quick edits or when I can't use <strong>X11</strong> for some reason, but I live in <strong>emacs</strong>. Really powerful editors are worth taking the time to learn.</p>\n"}, {'answer_id': 74733, 'author': 'Bill K', 'author_id': 12943, 'author_profile': 'https://Stackoverflow.com/users/12943', 'pm_score': 4, 'selected': False, 'text': '<p>For me VI is a good emergency editor, but not something I want to use if there is any other alternative available. I realize this is not for everyone though, I\'m not saying it\'s horrid or anything, I just personally prefer a discoverable UI.</p>\n\n<p>But you really have to know VI if you do anything significant in Linux!</p>\n\n<p>So just learn the basics:\ni=insert mode\nesc=leave insert mode\n:wq=save and quit\n:q!=don\'t save and quit\nx=when not in insert mode, delete the character.\n/=search</p>\n\n<p>That will get you through any editing emergency. There is nothing you can\'t do with those few commands (and navigation of course). The rest you can "Tack on" as you need them.</p>\n\n<p>Keep a reference or book available though--when you NEED to use VI, you probably won\'t be able to browse the web--but the man page may be somewhat useful.</p>\n'}, {'answer_id': 74784, 'author': 'Garth Gilmour', 'author_id': 2635682, 'author_profile': 'https://Stackoverflow.com/users/2635682', 'pm_score': 2, 'selected': False, 'text': '<p>You could get your hands on one of the original Happy Hacker keyboards (no arrow keys) and place your (wireless) mouse out of reach each time you start editing.</p>\n'}, {'answer_id': 74798, 'author': 'Craig Hyatt', 'author_id': 5808, 'author_profile': 'https://Stackoverflow.com/users/5808', 'pm_score': 2, 'selected': False, 'text': "<p>It's easy to write out a big list of commands/shortcuts, but it's difficult to remember them all without practice.</p>\n\n<p>Focus on one new command at a time. When it becomes automatic, say after using it for a week or two, add another to your repertoire. </p>\n\n<p>You'll be taking the long way around to accomplish certain things in the short term - these are obvious opportunities for new shortcuts to learn.</p>\n\n<p>In my experience it was easier when I tried not to take on too much at once.</p>\n"}, {'answer_id': 74812, 'author': 'Andrew Harmel-Law', 'author_id': 2455, 'author_profile': 'https://Stackoverflow.com/users/2455', 'pm_score': 0, 'selected': False, 'text': "<p>Wait until you have to debug a wierd and wondeful problem in a live environment where all you can do is get to the command line. You might not end up liking VI, but it will save you a lot of time and you'll learn loads of tricks to step through massive (log) files.</p>\n"}, {'answer_id': 74816, 'author': 'Michael Cramer', 'author_id': 1496728, 'author_profile': 'https://Stackoverflow.com/users/1496728', 'pm_score': 2, 'selected': False, 'text': '<p>My number one suggestion: learn to type fast, without needing to look at the keyboard.</p>\n\n<p>If you can\'t touch type and are always hunting-and-pecking for the colon or the hjkl or :%s/foo/bar, forget about it. Typing <em>can</em> be faster than using the mouse, but if that\'s not the case for you, vi\'s not going to work.</p>\n\n<p>But combine good typing skills, ssh and <a href="http://en.wikipedia.org/wiki/GNU_Screen" rel="nofollow noreferrer">screen</a> and vi will be natural.</p>\n'}, {'answer_id': 74842, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>Print out one of the many Vi/Vim cheat sheets you can find on the internet and force yourself to stick with it for a few weeks.</p>\n\n<p>Once you learn some basic commands you can be pretty efficient. From there, just keep plugging away and learn a new command every once in a while. There is no way you can learn ALL the vi commands. I believe there are more vi commands than there are atoms in the universe!! :)</p>\n'}, {'answer_id': 74895, 'author': 'chiggsy', 'author_id': 13202, 'author_profile': 'https://Stackoverflow.com/users/13202', 'pm_score': 0, 'selected': False, 'text': '<p>The best way? Set your terminal to use vi keybindings. </p>\n'}, {'answer_id': 74967, 'author': 'Matt Price', 'author_id': 852, 'author_profile': 'https://Stackoverflow.com/users/852', 'pm_score': 2, 'selected': False, 'text': '<p>Face the fact that it will create an immediate performance hit. When learning a new tool you need to be able to do something that you know how to do with other tools so the problem isn\'t your problem. After using the new tool a while it will disappear and you will be only focusing on the underlying problem. </p>\n\n<p>With something like vim (as others have said, vim is vastly superior to vi) it is important to reread and browse the documentation periodically. The interface is completely undiscoverable without it. With each new reading you will see a feature and say, "ah ha, that would have solved this issue I was trying to figure out last week", and will file it away in your brain. Solutions connected to real-world problems that you\'ve had are much easier for you to remember than random shortcuts. </p>\n\n<p>In the end you can use vim with a fairly small subset of it\'s features, so don\'t be overwhelmed with all the bells and whistles. Think of all the features in Word, do 99% of the people use them?</p>\n'}, {'answer_id': 74996, 'author': 'David Laing', 'author_id': 13238, 'author_profile': 'https://Stackoverflow.com/users/13238', 'pm_score': 2, 'selected': False, 'text': '<p>gVIM has a really good tutorial (link in the Start menu group).</p>\n\n<p>I found working through that helped to get over the initial learning hump; and then switching my Visual Studio to ViEMU helped me hone my VI skills.</p>\n\n<p>Also, the screencasts at <a href="http://vimcasts.org/" rel="nofollow noreferrer">http://vimcasts.org/</a> are great!</p>\n'}, {'answer_id': 75010, 'author': 'TMarshall', 'author_id': 8847, 'author_profile': 'https://Stackoverflow.com/users/8847', 'pm_score': 4, 'selected': False, 'text': "<p>You asked for good tips to help get past the learning curve on the vi text editor. Many of the previous answers suggest you use no other editors. I think that is good advice. Switching to vi from a more graphical editor requires a change in mindset. It requires thinking in terms of commands, rather than visual changes.</p>\n\n<p>I used nothing but vi for many years and believe the only way you can be productive is to memorize the commands you regularly use. The way I did this was to make a short list of the most common keyboard commands. I grouped and color-coded these commands by function, i.e. <em>Moving the Cursor, Editing, Searching</em>, etc. I was careful to only include the most commonly used commands I did not know. The idea is to create a quick reference that is also an aid in memorization – not to replace the available help screens. Then I printed this list and taped it to the wall behind my monitor so I could see it easily. (The graphical cheat sheets you mentioned might work better for some, but are probably a better reference source than a memorization tool.)</p>\n\n<p><strong>Here's the key.</strong> As I became comfortable with one of the commands, I drew a line through it with a pencil. I could still see it if I needed it, but it was symbolic to me that I had mastered that command. That gave me confidence and motivation as I could see regular progress. Once I had most of them crossed off, I removed them and added some of the more rarely used commands. I continued this process until I was satisfied with my command of vi. I knew I had reached that point when I realized I had not crossed off any commands or even looked at the list in a long time.</p>\n\n<p>A couple years ago I had need to work on a UNIX platform where vi was the only editor available. I bought a little pocket reference book on vi, but hardly used it. I ended up making lists and posting them on the wall as I did the first time I used vi. By the end of the first week, I was very comfortable even though it had been five years since I had used vi.</p>\n"}, {'answer_id': 75012, 'author': 'Nathan Fellman', 'author_id': 1084, 'author_profile': 'https://Stackoverflow.com/users/1084', 'pm_score': 0, 'selected': False, 'text': "<p>I only learned vi when I started working for an ISP where the scripts for editing domains only opened vi on a terminal. I had no choice but to learn it, but I've never regretted it.</p>\n\n<p>In short, put yourself in a situation where you have no choice but to learn it.</p>\n"}, {'answer_id': 75074, 'author': 'Phillip Wells', 'author_id': 3012, 'author_profile': 'https://Stackoverflow.com/users/3012', 'pm_score': 0, 'selected': False, 'text': '<p>I learned vi from the excellent O\'Reilly book <a href="https://rads.stackoverflow.com/amzn/click/com/1565924266" rel="nofollow noreferrer" rel="nofollow noreferrer">"Learning the vi editor"</a>.</p>\n'}, {'answer_id': 75099, 'author': 'Brian', 'author_id': 13264, 'author_profile': 'https://Stackoverflow.com/users/13264', 'pm_score': 5, 'selected': False, 'text': '<p>I\'ve been a on-again, off-again user of vim throughout the years (doing the occasional sys admin job). I just recently started spending more time doing my programming work in it. I\'d suggest starting with gvim too. It integrates well with most OS environments, and (even better), you can fall back to the mouse when you need to :).</p>\n\n<p>To get going with vim, <strong>run through the vimtutor</strong> (bundled with gVim) once or twice (takes an hour or so). I can\'t overstate how helpful it was for me! Especially the first parts about the different ways to move through a document, and how edit actions are recorded with motion commands, etc, etc. After that, things will be MUCH clearer.</p>\n\n<p>Then, start doing quick, minor edits with it (notepad-replacement stuff) \'till you are comfortable enough to do useful editing at a rapid clip. Then try doing your day-to-day work in it. You\'ll find yourself pining for the "repeat last action" command in other editors in no time!</p>\n'}, {'answer_id': 75101, 'author': 'sammyo', 'author_id': 10826, 'author_profile': 'https://Stackoverflow.com/users/10826', 'pm_score': 0, 'selected': False, 'text': '<p>Google is your friend. Keep a window or tab handy and when you have something that you need to do several times, say indent code or search with a regex, look it up. The best hints sites will become familar, bookmark some and perhaps print out a cheat sheet. </p>\n'}, {'answer_id': 75151, 'author': 'Eduardo Marinho', 'author_id': 13211, 'author_profile': 'https://Stackoverflow.com/users/13211', 'pm_score': 2, 'selected': False, 'text': "<p><code>ESC gg=G</code> to reindent code and <code>:retab</code> to convert tabs to spaces or spaces to tabs was what hooked me to vim. So actually you don't need to be forced to use it, you just have to learn when it can help you increase your speed.</p>\n\n<p>Go through <code>vimtutor</code>. </p>\n\n<p>Start using vim for simple editing, like config files or html. Learn the commands as you need them. </p>\n\n<p>Search google for a good .vimrc used by someone who uses a toolchain that resembles yours. Turn on syntax highlighting. Find a nice color scheme.</p>\n\n<p>Learn macros because Vim is the best for automated tasks and snippet insertion, like formatting a few words into a complex XML tag or converting a CSV to an HTML table.</p>\n"}, {'answer_id': 75193, 'author': 'ben.prew', 'author_id': 13185, 'author_profile': 'https://Stackoverflow.com/users/13185', 'pm_score': 2, 'selected': False, 'text': '<p>I remember when I first started learning emacs, it was after I was already very comfortable with Vim, and I was in the same or similar boat that you were, where I knew how to get a lot done in another editor, so as I started using emacs, it was always painfully slow.</p>\n\n<p>However, I think what you\'ll have to do is just absorb a little bit of the pain, and always, always, ALWAYS make sure that you look up the documentation for doing something that you <em>know</em> you can do in your previous editor, such as moving to the end of a line, or selecting a region of text.</p>\n\n<p>It also helps if you have a local vi-expert on hand that you can ask questions, or if you\'re like our company, you promote pair programming. That way when you\'re trying to do something that should be easy, you can simply ask someone, they\'ll show you how, and if you\'re using the editor regularly for a few weeks, you shouldn\'t have to ask more then a couple of times before it becomes second nature.</p>\n\n<p>If you don\'t have any local resources, there are plenty of books/tutorials/reference sheets online that should be able to answer most of your questions.</p>\n\n<p>Ultimately, learning Vi is like learning other skills, there\'s no silver bullet, and you\'ll have to accept that, for a while, you\'re going to be less productive in it then your current editor. Just keep telling yourself, "Other people have been able to learn Vi, and I\'m at least as smart as them" (That\'s what I tell myself anyway :) )</p>\n'}, {'answer_id': 75212, 'author': 'Roberto Bonvallet', 'author_id': 13169, 'author_profile': 'https://Stackoverflow.com/users/13169', 'pm_score': 4, 'selected': False, 'text': '<p>Every time you\'re doing a complex editing task, keep wondering if there is a more efficient way to do it. Most times, when it\'s something that you can describe in simple terms (like "swap paragraphs of text" or "delete everything after the X character in commented lines"), it\'s something you can do in just a couple of keystrokes in vim.</p>\n\n<p>There are some key features that are extremely useful, and you\'ll end using all the time. The ones I love the most are:</p>\n\n<ul>\n<li>Block selection (Ctrl-V)</li>\n<li>Macro recording (q)</li>\n<li>Virtual editing (:set ve=all)</li>\n<li>Regular expressions</li>\n<li>Piping to external Unix programs</li>\n<li>Key mappings</li>\n<li>Autocompletion (C-p, C-x C-p, C-x C-f)</li>\n<li>The operation+movement combination (this is amazingly powerful)</li>\n</ul>\n\n<p>Ask other programmers what features they find most useful and adopt the ones that fit better your brain. Steal ideas from other people\'s <code>.vimrc</code>s (<a href="https://github.com/rbonvall/dotvim/blob/master/vimrc.vim" rel="nofollow noreferrer">here\'s mine</a>)</p>\n'}, {'answer_id': 75223, 'author': 'Jonathan', 'author_id': 3251, 'author_profile': 'https://Stackoverflow.com/users/3251', 'pm_score': 3, 'selected': False, 'text': '<p>I wrote a guide to <a href="http://jmcpherson.org/editing.html" rel="nofollow noreferrer">efficient editing with Vim</a> a while back. You may find it helpful.</p>\n\n<p>I\'d step back for a minute and ask yourself "why do I want to learn this editor? What makes me think it\'ll be faster or better than my current text editor?" Then learn those features that will make Vi(m) indispensable to you. </p>\n\n<p>For instance, Vim\'s CTags integration is completely indispensable for me. I work with a very, very large codebase, and the ability to jump to a function or class definition in one keystroke (regardless of which file it\'s in) is an absolutely killer feature, one I have trouble working without.</p>\n\n<p>Use your .vimrc file to make macros that automate common tasks.</p>\n\n<p>Your autopilot editor-chooser will pick the editor that will get the job done quickest and with the least amount of mental effort. A little prep-work will ensure that editor is Vim. :-)</p>\n'}, {'answer_id': 75263, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 4, 'selected': False, 'text': '<p>force yourself not. the path to mastery love is.</p>\n'}, {'answer_id': 75269, 'author': 'Kearns', 'author_id': 6500, 'author_profile': 'https://Stackoverflow.com/users/6500', 'pm_score': 0, 'selected': False, 'text': '<p>I would start with <a href="http://www.vim.org/htmldoc/editing.html#:argdo" rel="nofollow noreferrer">argdo</a>, and once you fall in love with that, the rest is easy...</p>\n'}, {'answer_id': 75286, 'author': 'DarenW', 'author_id': 10468, 'author_profile': 'https://Stackoverflow.com/users/10468', 'pm_score': 0, 'selected': False, 'text': '<p>Spend a couple hours at the vi lover\'s site <a href="http://nereida.deioc.ull.es/html/vilovers.html" rel="nofollow noreferrer">http://nereida.deioc.ull.es/html/vilovers.html</a> - loads of tutorials, links, etc. with enthusiastic fans of vi. </p>\n'}, {'answer_id': 75359, 'author': 'Kristian', 'author_id': 12911, 'author_profile': 'https://Stackoverflow.com/users/12911', 'pm_score': 0, 'selected': False, 'text': "<p>I've started using VI because it's the default editor on pretty much every operating system except for Windows. Then again I don't do a lot of coding on Windows so that helps.</p>\n\n<p>If you want to force yourself on a *NIX/OSX system just remove the other editors or alias them. For the rest it's up to yourself. Everytime you don't use VI to edit a file you won't get a cookie.</p>\n"}, {'answer_id': 75447, 'author': 'Brian G', 'author_id': 3208, 'author_profile': 'https://Stackoverflow.com/users/3208', 'pm_score': 0, 'selected': False, 'text': '<p>I used it to edit files on the webserver which was linux instead of using FTP. That was 9 years ago and I have since mastered the skills.</p>\n\n<p>The other thing is find something great you can do in VI such as global search and replace or something even more powerful, and use VI whenever you need to do that.</p>\n'}, {'answer_id': 75530, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>You might want to start out with Cream. Cream describes itself as "a modern configuration" of vim. Basically, it is a special version of vim which looks and feels like any other text editor for all practical purposes. But enable the "expert mode" and you have all the power and behavior of vim.</p>\n\n<p>So you can start using Cream as a regular text editor and then experiment with the "expert mode" until you are comfortable enough to fully switch to vim.</p>\n'}, {'answer_id': 75545, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>One thing that I found really confusing in modern vi (vim?) is the input mode that allows for some, but not all features of command mode. I feel much more comfortable when input mode is fully dumbed down to "overwrite only, no cursor movement possible" kind of thing that old Solaris vi has. The true vi requires you to stay in command mode most of the time.</p>\n\n<p>That being said, there is no need to learn vi nowadays - emacs is just as ubiquitous. :)</p>\n'}, {'answer_id': 75548, 'author': 'user13060', 'author_id': 13060, 'author_profile': 'https://Stackoverflow.com/users/13060', 'pm_score': 2, 'selected': False, 'text': '<p>Install <code>gVim</code> on all platforms you use.</p>\n\n<p>Then run through the the vimtutor (<code>:help vimtutor</code> or <code>vimtutor</code> at the command line).</p>\n\n<p>Watch the following lecture and follow its advice: <a href="http://video.google.com/videoplay?docid=2538831956647446078" rel="nofollow noreferrer">7 Habits For Effective Text Editing 2.0</a></p>\n\n<p>I say you definitely want to start using it for all your editing. If you fear a loss of productivity then take a weekend to practice it solid (I once did this to switch to dvorak from qwerty and had my productivity high enough by Monday and managed to stick with it after).</p>\n\n<p>It\'s worth the effort and you won\'t look back!</p>\n'}, {'answer_id': 75622, 'author': 'Mark Witczak', 'author_id': 1536194, 'author_profile': 'https://Stackoverflow.com/users/1536194', 'pm_score': 3, 'selected': False, 'text': '<p>Two things that will greatly improve your vi skills:</p>\n\n<ol>\n<li>Practice, practice, practice</li>\n<li>Nethack</li>\n</ol>\n'}, {'answer_id': 76211, 'author': 'Steve Losh', 'author_id': 13498, 'author_profile': 'https://Stackoverflow.com/users/13498', 'pm_score': 0, 'selected': False, 'text': '<p>symlink every terminal editor on your system to vim and symlink every graphical editor on your system to a script that opens a new terminal window with vim running.</p>\n'}, {'answer_id': 77658, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': "<p>The way I did it was to take a few minutes initially to go over the most basic stuff -- moving the cursor around, searching forwards and back, jumping to next and previous words/sentences/paragraphs, etc. Inserting, appending. Whatever you can fit in your head. Then, when you've got something to do that doesn't have to be done in the next 15 seconds, make yourself use it.</p>\n\n<p>When you're pretty comfortable with the basics, slowly learn the more advanced commands -- especially those that leverage your previous learning (like replacing the next 3 words, or deleting to the next search target)</p>\n\n<p>I love using VI, once I learned how. The advanced commands are far more powerful than what most of the GUI editors seem to offer, and the fact that it's ubiquitous and text-based, and so available over ssh, is all the better.</p>\n"}, {'answer_id': 78784, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>If you force yourself to use it for a few days you will see that the commands soon become second-nature. If you are on a posix system, I recommend you start with the BSD-licensed nvi, a classical 1:1 vi clone, and then move on to vim. If you start with vim, it is likely you only use a subset of the editing commands because its INSERT mode is very similar to GUI editors.</p>\n'}, {'answer_id': 78825, 'author': 'tomasr', 'author_id': 10292, 'author_profile': 'https://Stackoverflow.com/users/10292', 'pm_score': 1, 'selected': False, 'text': '<p>Personally, what I had to do was make sure that I could use the Vim key-bindings (or at least, close enough) in several applications. Having to completely switch how I edited text whenever I changed editors made it too hard to get the Vim editing style committed to muscle memory.</p>\n\n<p>In my case, Viemu + vimperator did the trick.</p>\n'}, {'answer_id': 78832, 'author': 'titanae', 'author_id': 2387, 'author_profile': 'https://Stackoverflow.com/users/2387', 'pm_score': 0, 'selected': False, 'text': '<p>I have VI on Windows, the version I use is listed below, if I am in a console window I always default to VI, then regardless of what OS I am running on I know I can edit the file. Conversely if I am in UI mode, I use Notepad++ go figure.</p>\n\n<p>NT VI - Version 0.23\nDeveloped by:\n Tony Andrews\nBased on a program by:\n Tim Thompson</p>\n'}, {'answer_id': 78845, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': "<p>Play lots of nethack. That's what I did when I was in college, and I found out later that the cursor movement was the same. Although at this point you may need to change the setting to use the vi style keymap.</p>\n"}, {'answer_id': 79010, 'author': 'Paulus', 'author_id': 14209, 'author_profile': 'https://Stackoverflow.com/users/14209', 'pm_score': 3, 'selected': False, 'text': '<p>My suggestion: start small. Just start by memorizing a small set of most useful commands. When I started vi, these were my top 10:</p>\n\n<ul>\n<li>(Esc) to return to command mode (most important!)</li>\n<li>a to add text after cursor</li>\n<li>A to add text at end of current line</li>\n<li>x to delete 1 character</li>\n<li>dd to delete 1 line</li>\n<li>R to replace text (overwrite)</li>\n<li>u to undo</li>\n<li>:q! (Enter) to quit without saving</li>\n<li>:w (Enter) to save</li>\n<li>ZZ to save and quit</li>\n</ul>\n\n<p>A lot of basic editing can be done using only these commands. Once you get comfortable, the rest don\'t look too difficult.</p>\n\n<p>BTW, I\'d like to add that I used to rely on vi for my primary text editor, but now only if I have to. In my case, productivity is better when I use tools like Emacs or Visual Studio (please note: "in my case"). Try more than one tool and choose the one that helps your productivity the most. Good luck!</p>\n'}, {'answer_id': 79097, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': "<p>I made myself a handy one-page cheat sheet and used it to learn all the non-basic features. However, practice is about the only way to master anything.</p>\n\n<p>vi is nice because it's on every UNIX-type computer, Mac OS X, Solaris, Linux. Find an old decstation box on eBay? It's got vi. How about Sun OS 4? vi again.</p>\n"}, {'answer_id': 80191, 'author': 'Brian Mitchell', 'author_id': 13716, 'author_profile': 'https://Stackoverflow.com/users/13716', 'pm_score': 0, 'selected': False, 'text': "<p>While i'm a great fan of vi in general, and vim in particular, there are many powerful editors, and you shouldn't feel you need to use vi, or it in some way is some absolute perfect editor, because it's not.</p>\n\n<p>If you have to force yourself to use vi, I would be concerned that you don't feel productive using it. However, if you insist on persisting, I would probably just make sure I used vi for every single editing task. Whenever I need to do something and I don't quite no the best way to do it, I'd try to find the optimal (in terms of minimal keystrokes) to do it in vi <em>after</em> I did it a non-optimal normal way. I'd then make a post-it note with this little tip (or maybe just a text file) so I would remember it for next time.</p>\n\n<p>Over time, your productivity with vi will dramatically improve.</p>\n"}, {'answer_id': 102478, 'author': 'webmat', 'author_id': 6349, 'author_profile': 'https://Stackoverflow.com/users/6349', 'pm_score': 0, 'selected': False, 'text': "<p>Why don't I pitch in with my very own low-friction way to force myself? :-)</p>\n\n<p>What I do is simple: I try to make my git commit messages with vim (default editor when you don't specify a message at the command-line).</p>\n\n<p>Of course a commit message is so short that it barely helps. But when re-editing a message with <code>git commit --amend</code> it's more helpful.</p>\n"}, {'answer_id': 106330, 'author': 'Jeremy Cantrell', 'author_id': 18866, 'author_profile': 'https://Stackoverflow.com/users/18866', 'pm_score': 0, 'selected': False, 'text': '<p>Do what I did. Use it for everything, and hang out in #vim on freenode.</p>\n'}, {'answer_id': 129975, 'author': 'webmat', 'author_id': 6349, 'author_profile': 'https://Stackoverflow.com/users/6349', 'pm_score': 0, 'selected': False, 'text': '<p>When you need to quickly search for something, having it all on one page can help. </p>\n'}, {'answer_id': 456031, 'author': 'Johan', 'author_id': 51425, 'author_profile': 'https://Stackoverflow.com/users/51425', 'pm_score': 1, 'selected': False, 'text': '<p>Use the post-it note method :-)</p>\n\n<p>When using gvim, allow your self to use the menus.\nRead a book/tutorial about vim so you know the basics.\n(insert and command mode)</p>\n\n<p>Select some really cool functions you think you need and write those on post-it notes \nand then stick those on the lower part off your monitor.</p>\n\n<p>A good start is probably \ni, a, o, gg, G, :10 ,/something</p>\n\n<p>and some cut and paste like \nyy, dd, p</p>\n\n<p>and just top off with \nv, V (the visual mode) + cut and paste</p>\n\n<p>Then when you know them, replace on post-it with a new one that has a even cooler function, \nand repeat until you are happy.</p>\n\n<p>/Johan</p>\n'}, {'answer_id': 456101, 'author': 'bk1e', 'author_id': 8090, 'author_profile': 'https://Stackoverflow.com/users/8090', 'pm_score': 3, 'selected': False, 'text': '<p>It sounds silly, but playing <a href="http://en.wikipedia.org/wiki/Roguelike" rel="noreferrer">roguelike</a> games (such as <a href="http://www.nethack.org/" rel="noreferrer">Nethack</a> or <a href="http://www.thangorodrim.net/" rel="noreferrer">Angband</a>) is a fun way to get comfortable with using the <code>h</code>/<code>j</code>/<code>k</code>/<code>l</code> keys for cursor navigation. </p>\n'}, {'answer_id': 464374, 'author': 'too much php', 'author_id': 28835, 'author_profile': 'https://Stackoverflow.com/users/28835', 'pm_score': 0, 'selected': False, 'text': '<p>I was forced to learn Vim for my first programming job when I was 16 (the boss wouldn\'t let us use anything else), but I didn\'t make any real progress until I read <a href="http://iccf-holland.org/click5.html#oualline" rel="nofollow noreferrer">Steve Oualline\'s Vim Book</a> - it is highly recommended as a starting point if you want to get serious with vim.</p>\n\n<p>Vim actually takes more time to master than do some programming languages (the features are <em>that</em> complex). Trying to \'master\' Vim by printing cheat sheets would be like trying to master Haskell by reading a couple of blog posts. Be prepared to invest some serious time and you will be well rewarded.</p>\n'}, {'answer_id': 834552, 'author': 'Hamish Downer', 'author_id': 3189, 'author_profile': 'https://Stackoverflow.com/users/3189', 'pm_score': 5, 'selected': False, 'text': '<p><strong>Step 0:</strong> learn to touch type. Seriously - if your fingers don\'t know where the keys are then vim is going to be a pain. And even if you reject vim, touch typing will <a href="https://stackoverflow.com/questions/31757/should-programmers-be-excellent-typists">improve your programming</a> (ask <a href="http://steve-yegge.blogspot.com/2008/09/programmings-dirtiest-little-secret.html" rel="noreferrer">Steve Yegge</a> ) by making the mind to monitor link friction free. There is a <a href="https://stackoverflow.com/questions/410880/how-do-i-improve-my-typing-skills">lot</a> of <a href="https://stackoverflow.com/questions/10475/touch-typing-software-recommendations">software</a> that can help you improve your typing.</p>\n\n<p><strong>Step 1:</strong> use <strong>vimtutor</strong> to get you started. It is in gvim (under\nthe help menu I think) or you can just type \'vimtutor\' at the command\nline. It will take 30-45 minutes of your time and then your fingers will\nknow the basics of vi/vim and you should be able to edit files without\nwanting to hurl your keyboard out of the window. </p>\n\n<p><strong>Step 2:</strong> use vim everywhere. See <a href="https://stackoverflow.com/questions/826208/making-vim-ubiquitous">this\nquestion</a>\nfor tips and links for using vim and vi key bindings at the command\nline, from your web browser, for composing emails, in your IDE ... You\nneed to use vim to embed the key bindings in your muscle memory.</p>\n\n<p><strong>Step 3:</strong> learn more about vim. You will only have scratched the\nsurface with vimtutor. You can <a href="http://video.google.com/videoplay?docid=2538831956647446078" rel="noreferrer">watch this\nvideo</a> or\nread <a href="http://www.moolenaar.net/habits.html" rel="noreferrer">this article</a> (both about\nthe "Seven habits of effective text editing". You can \n<a href="https://stackoverflow.com/questions/164847/what-is-in-your-vimrc">read</a>\nabout\n<a href="https://stackoverflow.com/questions/20735/useful-vim-features">tips</a>\nand\n<a href="https://stackoverflow.com/questions/726894/vim-tricks-your-mom-never-told-you-about-dark-corners">tricks</a> \non\n<a href="https://stackoverflow.com/questions/95072/what-are-your-favorite-vim-tricks">StackOverflow</a>.\nYou can browse <a href="http://vim.wikia.com/wiki/Main_Page" rel="noreferrer">vimtips</a>. Learn a\nlitle often would be my advice - there is so much out there that\nsticking to bite-size chunks will be the best way to make the knowledge\nstick.</p>\n\n<p><strong>Step 4:</strong> Profit :)</p>\n'}, {'answer_id': 834586, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>When I was a lot younger (eleven), my family moved to Germany for a couple of years. I was able to learn the language through immersion - I simply had no choice but to speak the language (although if I was in a dire situation I could find an English speaker). </p>\n\n<p>My suggestion is that you do the same - unless you\'re in an absolutely desperate situation (e.g. "ok, I just deleted /etc/passwd and need to put back root"), make the conscious decision to do your best with vi. It actually doesn\'t take that long to learn the basics, if you\'re willing. </p>\n\n<p>As others have suggested, </p>\n\n<pre><code>vim-tutor\n</code></pre>\n\n<p>can be a really good starting point, <a href="http://www.ekvin.com/dr/images/1/14/Vi_cheatsheet.png" rel="nofollow noreferrer" title="this image">as can this image</a>. </p>\n'}, {'answer_id': 858158, 'author': 'Aaron Digulla', 'author_id': 34088, 'author_profile': 'https://Stackoverflow.com/users/34088', 'pm_score': 2, 'selected': False, 'text': '<p>The main reason for me to use <code>vi</code> is <code>ssh</code> (or Putty on Windows): When you\'re logged into a Unix server remotely, then <code>vi</code> is always available. And it works with VT100 when neither the cursor keys nor backspace/delete are mapped.</p>\n\n<p>Also having a book like <a href="https://rads.stackoverflow.com/amzn/click/com/1565924975" rel="nofollow noreferrer" rel="nofollow noreferrer">VI Editor Pocket Reference</a> helps greatly.</p>\n'}, {'answer_id': 1828046, 'author': 'Excalibur2000', 'author_id': 126277, 'author_profile': 'https://Stackoverflow.com/users/126277', 'pm_score': 1, 'selected': False, 'text': '<p>How to force yourself ? My advice is to be in a work environment where you have to maintain 10 unix boxes by telnetting/puttying into them from windows. You will quickly realise that the only way to efficiently edit text on multiple variants of *nix is to use a standard editor that comes with almost every distro I know. Also, when X11 does not start up on a fresh install, vi is your only friend :)</p>\n'}, {'answer_id': 3464220, 'author': 'Myer', 'author_id': 78202, 'author_profile': 'https://Stackoverflow.com/users/78202', 'pm_score': 3, 'selected': False, 'text': '<p>EDIT: I\'ve created <a href="http://flashcarddb.com/cardset/135218-vim-flashcards" rel="noreferrer">a flashcard set over at the online spaced repetition site flashcarddb.com</a>, in case you\'re interested ... </p>\n\n<ol>\n<li>Use a spaced repetition flash card program such as <a href="http://www.mnemosyne-proj.org/" rel="noreferrer">mnemosyne</a>, <a href="http://www.supermemo.com/" rel="noreferrer">supermemo</a>, or <a href="http://ichi2.net/anki/" rel="noreferrer">anki</a> to incorporate learning and retaining new commands into your daily routine. It\'s not enough to be using vim as your daily editor. To master it, you have to be storing those codes in your head, laying in wait for the time when they\'re the ideal solution to the task at hand.</li>\n<li>Maintain a .vimrc with customizations</li>\n<li>Write or edit a vim plugin</li>\n</ol>\n'}, {'answer_id': 7769304, 'author': 'lang2', 'author_id': 172265, 'author_profile': 'https://Stackoverflow.com/users/172265', 'pm_score': 1, 'selected': False, 'text': '<p>I learnt vim/vi over ten years ago when I was doing my masters. Back then the only machine I have access to are Sun Sparc stations (Sparc 20 I think). And vi is the only thing that\'s on it. So one thing you can do to "force" yourself is to uninstall any other editor you have!</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74625', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/6349/']
74,626
<p>I have a CIFS share mounted on a Linux machine. The CIFS server is down, or the internet connection is down, and anything that touches the CIFS mount now takes several minutes to timeout, and is unkillable while you wait. I can't even run ls in my home directory because there is a symlink pointing inside the CIFS mount and ls tries to follow it to decide what color it should be. If I try to umount it (even with -fl), the umount process hangs just like ls does. Not even sudo kill -9 can kill it. How can I force the kernel to unmount?</p>
[{'answer_id': 74695, 'author': 'Chris AtLee', 'author_id': 4558, 'author_profile': 'https://Stackoverflow.com/users/4558', 'pm_score': 2, 'selected': False, 'text': '<p>There\'s a -f option to umount that you can try:</p>\n\n<pre><code>umount -f /mnt/fileshare\n</code></pre>\n\n<p>Are you specifying the \'-t cifs\' option to mount? Also make sure you\'re not specifying the \'hard\' option to mount.</p>\n\n<p>You may also want to consider <a href="http://www.ricardis.tudelft.nl/~vincent/fusesmb/" rel="nofollow noreferrer">fusesmb</a>, since the filesystem will be running in userspace you can kill it just like any other process.</p>\n'}, {'answer_id': 74837, 'author': 'Sunny Milenov', 'author_id': 8220, 'author_profile': 'https://Stackoverflow.com/users/8220', 'pm_score': 2, 'selected': False, 'text': '<p>Try umount -f /mnt/share. Works OK with NFS, never tried with cifs.</p>\n\n<p>Also, take a look at autofs, it will mount the share only when accessed, and will unmount it afterworlds.</p>\n\n<p>There is a good tutorial at <a href="http://www.howtoforge.com/accessing_windows_or_samba_shares_using_autofs" rel="nofollow noreferrer">www.howtoforge.net</a></p>\n'}, {'answer_id': 96288, 'author': 'Kemal', 'author_id': 7506, 'author_profile': 'https://Stackoverflow.com/users/7506', 'pm_score': 9, 'selected': True, 'text': "<p>I use lazy unmount: <code>umount -l</code> (that's a lowercase <code>L</code>)</p>\n\n<blockquote>\n <p>Lazy unmount. Detach the filesystem\n from the filesystem hierarchy now, and\n cleanup all references to the\n filesystem as soon as it is not busy\n anymore. (Requires kernel 2.4.11 or\n later.)</p>\n</blockquote>\n"}, {'answer_id': 12945984, 'author': 'jnice', 'author_id': 1754934, 'author_profile': 'https://Stackoverflow.com/users/1754934', 'pm_score': 3, 'selected': False, 'text': '<p>I had this issue for a day until I found the real resolution. Instead of trying to force unmount an smb share that is hung, mount the share with the "soft" option. If a process attempts to connect to the share that is not available it will stop trying after a certain amount of time.</p>\n\n<blockquote>\n <p>soft Make the mount soft. Fail file system calls after a number of seconds.</p>\n</blockquote>\n\n<pre><code>mount -t smbfs -o soft //username@server/share /users/username/smb/share\n\nstat /users/username/smb/share/file\nstat: /users/username/smb/share/file: stat: Operation timed out\n</code></pre>\n\n<p>May not be a real answer to your question but it is a solution to the problem</p>\n'}, {'answer_id': 17128821, 'author': 'ivanlan', 'author_id': 2489809, 'author_profile': 'https://Stackoverflow.com/users/2489809', 'pm_score': 6, 'selected': False, 'text': '<p><code>umount -a -t cifs -l</code></p>\n\n<p>worked like a charm for me on CentOS 6.3. It saved me a server reboot.</p>\n'}, {'answer_id': 21489953, 'author': 'Phil Johnson', 'author_id': 3258894, 'author_profile': 'https://Stackoverflow.com/users/3258894', 'pm_score': 4, 'selected': False, 'text': '<p>This works for me (Ubuntu 13.10 Desktop to an Ubuntu 14.04 Server) :-</p>\n\n<pre><code> sudo umount -f /mnt/my_share\n</code></pre>\n\n<p>Mounted with </p>\n\n<pre><code> sudo mount -t cifs -o username=me,password=mine //192.168.0.111/serv_share /mnt/my_share\n</code></pre>\n\n<p>where serv_share is that set up and pointed to in the smb.conf file.</p>\n'}, {'answer_id': 23168749, 'author': 'Benedikt Köppel', 'author_id': 1067124, 'author_profile': 'https://Stackoverflow.com/users/1067124', 'pm_score': 2, 'selected': False, 'text': '<p>I had a very similar problem with davfs. In the man page of <code>umount.davfs</code>, I found that the <code>-f -l -n -r -v</code> options are ignored by <code>umount.davfs</code>. To force-unmount my davfs mount, I had to use <code>umount -i -f -l /media/davmount</code>.</p>\n'}, {'answer_id': 26286465, 'author': 'Andy Fraley', 'author_id': 866057, 'author_profile': 'https://Stackoverflow.com/users/866057', 'pm_score': 4, 'selected': False, 'text': '<p>On RHEL 6 this worked:</p>\n\n<pre><code>umount -f -a -t cifs -l \n</code></pre>\n'}, {'answer_id': 27376945, 'author': 'chataros', 'author_id': 457250, 'author_profile': 'https://Stackoverflow.com/users/457250', 'pm_score': -1, 'selected': False, 'text': '<p>On RHEL 6 this worked for me also:</p>\n\n<p>umount -f -a -t cifs -l FOLDER_NAME</p>\n'}, {'answer_id': 28272031, 'author': 'zhjb7', 'author_id': 4518793, 'author_profile': 'https://Stackoverflow.com/users/4518793', 'pm_score': 1, 'selected': False, 'text': '<pre><code>umount -f -t cifs -l /mnt &amp;\n</code></pre>\n\n<p>Be careful of <code>&amp;</code>, let <code>umount</code> run in background.\n<code>umount</code> will detach filesystem first, so you will find nothing abount <code>/mnt</code>. If you run <code>df</code> command, then it will <code>umount /mnt</code> forcibly. </p>\n'}, {'answer_id': 29678826, 'author': 'JimmyPheonix', 'author_id': 4797231, 'author_profile': 'https://Stackoverflow.com/users/4797231', 'pm_score': -1, 'selected': False, 'text': '<p>A lazy unmount will do the job for you.</p>\n\n<pre><code>umount -l &lt;mount path&gt;\n</code></pre>\n'}, {'answer_id': 73278742, 'author': 'mgutt', 'author_id': 318765, 'author_profile': 'https://Stackoverflow.com/users/318765', 'pm_score': 0, 'selected': False, 'text': '<p>I experienced very different results regarding unmounting a dead cifs mount and found several tricks to bypass the problem temporarily.</p>\n<p>Let\'s start with the <code>mountpoint</code> command. It can be useful to analyze the status of a mount:</p>\n<pre><code>mountpoint /mnt/smb_share\n</code></pre>\n<p>Usually it returns <code>is a mountpoint</code> or <code>/ is not a mountpoint</code>.</p>\n<p>But it can even return:</p>\n<ul>\n<li>No such device</li>\n<li>Transport endpoint is not connected</li>\n<li>&lt;nothing / stale&gt;</li>\n</ul>\n<p>For every result expect of <code>is not a mountpoint</code> there is a chance of unmounting.</p>\n<p>You could try the usual way:</p>\n<p><code>umount /mnt/smb_share</code></p>\n<p>or force mode:</p>\n<p><code>umount /mnt/smb_share -f</code></p>\n<p>But often the force does not help. It simply returns the same nasty <code>device is busy</code> message.</p>\n<p>Then the only option is to use the lazy mode:</p>\n<p><code>umount /mnt/smb_share -l</code></p>\n<p>BUT: This does not unmount anything. It only &quot;moves&quot; the mount to the root of the system, which can be seen as follows:</p>\n<pre><code># lsof | grep mount | grep cwd\nmount.cif 3125 root cwd unknown / (stat: No such device)\nmount.cif 3150 root cwd unknown / (stat: No such device)\n</code></pre>\n<p>It is even noted in the documentation:</p>\n<blockquote>\n<p>Lazy unmount. Detach the filesystem from the file hierarchy\nnow, and clean up all references to this filesystem as soon\nas it is not busy anymore.</p>\n</blockquote>\n<p>Now if you are unlucky, it will stay there forever. Even killing the process probably does not help:</p>\n<p><code>kill -9 $pid</code></p>\n<p>But why is this a problem? Because <code>mount /mnt/smb_share</code> does not work until the lazy unmounted path is really cleaned up by the Linux Kernel. And this is even mentioned in the documentation of <code>umount</code>. &quot;lazy&quot; should only be used to avoid a long shutdown / reboot times:</p>\n<blockquote>\n<p>A system reboot would be expected in near future if you’re\ngoing to use this option for network filesystem or local\nfilesystem with submounts. The recommended use-case for\numount -l is to prevent hangs on shutdown due to an\nunreachable network share where a normal umount will hang due\nto a downed server or a network partition. Remounts of the\nshare will not be possible.</p>\n</blockquote>\n<p><strong>Workarounds</strong></p>\n<p><strong>Use a different SMB version</strong></p>\n<p>If you still have hopes that the lazy unmounted path will ever be not busy anymore and cleaned up by the Linux Kernel or you can\'t reboot at the moment, then you are maybe lucky and your SMB server supports different protocol versions. By that we can use the following trick:</p>\n<p>Lets say you mounted your share as follows:</p>\n<pre><code>mount.cifs //smb.server/share /mnt/smb_share -o username=smb_user,password=smb_pw\n</code></pre>\n<p>By that Linux automatically tries the maximum support SMB protocol version. Maybe 3.1. Now, you can force this version and it won\'t mount as expected:</p>\n<pre><code>mount.cifs //smb.server/share /mnt/smb_share -o username=smb_user,password=smb_pw,vers=3.1\n</code></pre>\n<p>But then simply try a different version:</p>\n<pre><code>mount.cifs //smb.server/share /mnt/smb_share -o username=smb_user,password=smb_pw,vers=3.0\n</code></pre>\n<p>or maybe 2.1:</p>\n<pre><code>mount.cifs //smb.server/share /mnt/smb_share -o username=smb_user,password=smb_pw,vers=2.1\n</code></pre>\n<p><strong>Change the IP of the SMB server</strong></p>\n<p>If you are able to change the IP address or add a second IP to your SMB server, you can use this to mount the same server.</p>\n<p><strong>Dirty: Forward the traffic</strong></p>\n<p>Lets say the SMB server has the IP address 10.0.0.1 and the mount is really dead. Then create this <code>iptables</code> rule:</p>\n<pre><code>iptables -t nat -A OUTPUT -d 10.0.0.250 -j DNAT --to-destination 10.0.0.1\n</code></pre>\n<p>Now change your mount rule accordingly, so it mounts the samba server through IP 10.0.0.250 instead of 10.0.0.1 and voila, its mounted without server reboot. Dirty, but it works. PS <a href="https://superuser.com/a/681707/129262">This rule does not survive a reboot</a>, so you should mount the SMB server manually and leave the <code>/etc/fstab</code> as usual.</p>\n<p><strong>More debugging</strong></p>\n<p>If you want to check if samba connection itself is theoretically working, you could try to list all SMB shares of the server through SMB3 as follows:</p>\n<pre><code>smbclient //smb.server -U &quot;smb_user&quot; -m SMB3 -L\n</code></pre>\n<p>or to view the content of a share with SMB1:</p>\n<pre><code>smbclient //smb.server -U &quot;smb_user&quot; -m NT1 -c ls\n</code></pre>\n'}, {'answer_id': 73978769, 'author': 'Aliceisnt', 'author_id': 10095447, 'author_profile': 'https://Stackoverflow.com/users/10095447', 'pm_score': 0, 'selected': False, 'text': "<p>Approaching this problem sideways:</p>\n<p>If you can't unmount because the filesystem is busy, is your ssh/terminal session cd'd into the mount directory, therefore making the filesystem busy?</p>\n<p>For me, the solution was to cd into my home, then sudo umount worked flawlessly.</p>\n<pre><code>cd ~\numount /path/to/my/share\n</code></pre>\n<p>I would post this as a comment, but I have insufficient reputation. Hoping to spare someone else the forehead slap.</p>\n"}]
2008/09/16
['https://Stackoverflow.com/questions/74626', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/10168/']
74,641
<p>I currently am tasked with updating an XML file (persistance.xml) within a jar at a customers site. I can of course unjar the file, update the xml, then rejar the file for redeployment. I would like to kind these command line operations in a Swing App so that the person doing it does not have to drop to the command line. Any thoughts on a way to do this programatically? </p>
[{'answer_id': 74684, 'author': 'Dan Dyer', 'author_id': 5171, 'author_profile': 'https://Stackoverflow.com/users/5171', 'pm_score': 4, 'selected': True, 'text': '<p>The Java API has <a href="http://java.sun.com/javase/6/docs/api/java/util/jar/package-summary.html" rel="noreferrer">classes</a> for manipulating JAR files.</p>\n'}, {'answer_id': 74688, 'author': 'Bill the Lizard', 'author_id': 1288, 'author_profile': 'https://Stackoverflow.com/users/1288', 'pm_score': 1, 'selected': False, 'text': '<p>You can use Java\'s <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/zip/ZipFile.html" rel="nofollow noreferrer">ZipFile</a> and <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/zip/ZipEntry.html" rel="nofollow noreferrer">ZipEntry</a> classes to read the contents of a JAR file, then use <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/zip/ZipOutputStream.html" rel="nofollow noreferrer">ZipOutputStream</a> to create a new one.</p>\n'}, {'answer_id': 74702, 'author': 'jodonnell', 'author_id': 4223, 'author_profile': 'https://Stackoverflow.com/users/4223', 'pm_score': 2, 'selected': False, 'text': '<p>Sure:</p>\n\n<pre><code>File tmp = new File ("tmp");\ntmp.mkdirs();\nProcess unjar = new ProcessBuilder ("jar", "-xf", "myjar.jar", tmp.getName ()).start();\nunjar.waitFor();\n// TODO read and update persistence.xml\nProcess jar = new ProcessBuilder ("jar", "-cf", "myjar.jar", tmp.getName()).start();\njar.waitFor();\n</code></pre>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74641', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/387361/']
74,649
<p>What is the syntax to declare a type for my compare-function generator in code like the following?</p> <pre><code>var colName:String = ""; // actually assigned in a loop gc.sortCompareFunction = function() : ??WHAT_GOES_HERE?? { var tmp:String = colName; return function(a:Object,b:Object):int { return compareGeneral(a,b,tmp); }; }(); </code></pre>
[{'answer_id': 74743, 'author': 'Brent', 'author_id': 10680, 'author_profile': 'https://Stackoverflow.com/users/10680', 'pm_score': 2, 'selected': True, 'text': '<p>Isn\'t "Function" a data type?</p>\n'}, {'answer_id': 125763, 'author': 'Brian Hodge', 'author_id': 20628, 'author_profile': 'https://Stackoverflow.com/users/20628', 'pm_score': 0, 'selected': False, 'text': '<p>In order to understand what the data type is, we must know what the intended outcome of the return is. I need to see the code block for compareGeneral, and I still don\'t believe this will help. You have two returns withing the same function "gc.sortCompareFunction", I believe this is incorrect as return gets a value and then acts as a break command meaning the rest of the anything withing the same function block is ignored. The problem is that I don\'t know which return is the intended return, and I don\'t know that flash knows either. You can use * as a data type, but this should only really be used in specific situations. In this situation I believe you need only the one return value that merely returns whatever the value of compareGeneral.</p>\n\n<p>Now if this is a compareGenerator it really should either return a Boolean TRUE or FALSE, or a int 0 or 1, lets use the former. Also I believe we can use one less function. Since I have not seen all of your code and I am not exactly sure what your trying to accomplish, the following is hypothetical.</p>\n\n<blockquote>\n<pre>\nfunction compareGeneral(a:object,b:object):Boolean\n{\n //Check some property associated to each object for likeness.\n if(a.someAssignedPropery == b.someAssignedPropery)\n {\n return true;\n }\n return false;\n}\nvar objA:Object = new Object();\nobjA.someAssignedProperty = "AS3";\nobjB.someAssignedProperty = "AS3";\n\ncompareGeneral(objA,objB);\n</pre>\n</blockquote>\n\n<p>In this case compareGeneral(objA,objB); returns true, though we haven\'t done anything useful with it yet. Here is a way you may use it. Remember that it either returns a value of true or false so we can treat it like a variable.</p>\n\n<blockquote>\n<pre>\nif(compareGeneral(objA,objB)) //same as if(compareGeneral(objA,objB)) == true)\n{\n trace("You have found a match!");\n //Here you can call some other function or set a variable or whatever you require functionality wise based on a match being found.\n}\nelse\n{\n trace("No match could be found!");\n}\n</pre>\n</blockquote>\n\n<p>I hope that this is able to help you understand data types and return values. I do not know what you were doing with tmp, but generally functions that return a value deal with that one thing and only that thing, so it is best that the compare function compare one thing against the other and that be the extent of the call. Whatever functionality you require with tmp can go inside its own function or method, and be called when needed.</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74649', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4540/']
74,662
<p>We have an intranet system that schedules routine tasks. We also have Fogbugz for bug tracking. When an urgent bug comes in, we track that task in the bugtracker. However, I need to write back to both the Intranet and our CMS. I'm thinking Biztalk as the middle piece, but am not sure the best way to go about it. Database adapter? Web services?</p> <p>I know I can use the CMS adapter for Microsoft CMS. I'd love to hear your experiences with Fogbugz.</p>
[{'answer_id': 74766, 'author': 'SqlRyan', 'author_id': 8114, 'author_profile': 'https://Stackoverflow.com/users/8114', 'pm_score': 1, 'selected': False, 'text': "<p>I'm guessing that watching the database for changes would be the best way to do it. That way, you could post any changes you saw happen in the FogBugz database through other Biztalk adapters.</p>\n\n<p>Please keep us updated with what you decide to do - I'd be interested to hear about it.</p>\n"}, {'answer_id': 221448, 'author': 'Nick Heppleston', 'author_id': 29915, 'author_profile': 'https://Stackoverflow.com/users/29915', 'pm_score': 1, 'selected': False, 'text': '<p>Version 6 of the FogBugz API is pretty well documented at <a href="http://www.fogcreek.com/FogBugz/docs/60/topics/advanced/API.html" rel="nofollow noreferrer">http://www.fogcreek.com/FogBugz/docs/60/topics/advanced/API.html</a>. The API is implemented as an ASP page that accepts GET or POST params and returns XML after a user has been authenticated.</p>\n\n<p>So, we can use the HTTP Send Adapter to POST requests to the FogBugz system, either updating bug records or retrieving information. The response from the API call is basic Xml that will be returned in the response body that can be read by BizTalk as necessary.</p>\n\n<p>Be aware that the HTTP Send Adapter can only POST data - it cannot use the GET verb (<a href="http://msdn.microsoft.com/en-us/library/aa561642.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/aa561642.aspx</a>)</p>\n'}, {'answer_id': 221462, 'author': 'Riri', 'author_id': 298, 'author_profile': 'https://Stackoverflow.com/users/298', 'pm_score': 0, 'selected': False, 'text': '<p>Isn\'t FogBugz based on a SQL Server Database? Or do you use a hosted alternative? </p>\n\n<p>If it\'s using a SQL Server you\'re controlling I\'d just tie up two send ports to the process that read and handles the "FixBugMessage". One send port that uses the CMS Adapter and writes to the CMS and another that just uses the SQL Adapter and via an Stored Procedure writes to the FogBugz database.</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74662', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2757/']
74,674
<p>I need to check CPU and memory usage for the server in java, anyone know how it could be done?</p>
[{'answer_id': 74720, 'author': 'Tim Howland', 'author_id': 4276, 'author_profile': 'https://Stackoverflow.com/users/4276', 'pm_score': 1, 'selected': False, 'text': '<p>If you are using Tomcat, check out <a href="https://code.google.com/p/psi-probe/" rel="nofollow noreferrer">Psi Probe</a>, which lets you monitor internal and external memory consumption as well as a host of other areas.</p>\n'}, {'answer_id': 74724, 'author': 'moonshadow', 'author_id': 11834, 'author_profile': 'https://Stackoverflow.com/users/11834', 'pm_score': 2, 'selected': False, 'text': '<p>Java\'s <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html" rel="nofollow noreferrer">Runtime</a> object can report the JVM\'s memory usage. For CPU consumption you\'ll have to use an external utility, like Unix\'s top or Windows Process Manager.</p>\n'}, {'answer_id': 74742, 'author': 'Rich Adams', 'author_id': 10018, 'author_profile': 'https://Stackoverflow.com/users/10018', 'pm_score': 3, 'selected': False, 'text': "<p>For memory usage, the following will work,</p>\n\n<pre><code>long total = Runtime.getRuntime().totalMemory();\nlong used = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();\n</code></pre>\n\n<p>For CPU usage, you'll need to use an external application to measure it.</p>\n"}, {'answer_id': 74753, 'author': 'blahspam', 'author_id': 8290, 'author_profile': 'https://Stackoverflow.com/users/8290', 'pm_score': 2, 'selected': False, 'text': '<p><a href="http://java.sun.com/developer/technicalArticles/J2SE/jconsole.html" rel="nofollow noreferrer">JConsole</a> is an easy way to monitor a running Java application or you can use a Profiler to get more detailed information on your application. I like using the <a href="http://profiler.netbeans.org/" rel="nofollow noreferrer">NetBeans Profiler</a> for this.</p>\n'}, {'answer_id': 74759, 'author': 'Bill K', 'author_id': 12943, 'author_profile': 'https://Stackoverflow.com/users/12943', 'pm_score': 2, 'selected': False, 'text': '<p>If you use the runtime/totalMemory solution that has been posted in many answers here (I\'ve done that a lot), be sure to force two garbage collections first if you want fairly accurate/consistent results.</p>\n\n<p>For effiency Java usually allows garbage to fill up all of memory before forcing a GC, and even then it\'s not usually a complete GC, so your results for runtime.freeMemory() always be somewhere between the "real" amount of free memory and 0.</p>\n\n<p>The first GC doesn\'t get everything, it gets most of it.</p>\n\n<p>The upswing is that if you just do the freeMemory() call you will get a number that is absolutely useless and varies widely, but if do 2 gc\'s first it is a very reliable gauge. It also makes the routine MUCH slower (seconds, possibly).</p>\n'}, {'answer_id': 74763, 'author': 'Jeremy', 'author_id': 4419, 'author_profile': 'https://Stackoverflow.com/users/4419', 'pm_score': 6, 'selected': False, 'text': '<p>If you are looking specifically for memory in JVM:</p>\n\n<pre><code>Runtime runtime = Runtime.getRuntime();\n\nNumberFormat format = NumberFormat.getInstance();\n\nStringBuilder sb = new StringBuilder();\nlong maxMemory = runtime.maxMemory();\nlong allocatedMemory = runtime.totalMemory();\nlong freeMemory = runtime.freeMemory();\n\nsb.append("free memory: " + format.format(freeMemory / 1024) + "&lt;br/&gt;");\nsb.append("allocated memory: " + format.format(allocatedMemory / 1024) + "&lt;br/&gt;");\nsb.append("max memory: " + format.format(maxMemory / 1024) + "&lt;br/&gt;");\nsb.append("total free memory: " + format.format((freeMemory + (maxMemory - allocatedMemory)) / 1024) + "&lt;br/&gt;");\n</code></pre>\n\n<p>However, these should be taken only as an estimate...</p>\n'}, {'answer_id': 74801, 'author': 'Telcontar', 'author_id': 518, 'author_profile': 'https://Stackoverflow.com/users/518', 'pm_score': 3, 'selected': False, 'text': '<p>Since Java 1.5 the JDK comes with a new tool: <a href="http://java.sun.com/developer/technicalArticles/J2SE/jconsole.html" rel="noreferrer">JConsole</a> wich can show you the CPU and memory usage of any 1.5 or later JVM. It can do charts of these parameters, export to CSV, show the number of classes loaded, the number of instances, deadlocks, threads etc...</p>\n'}, {'answer_id': 75051, 'author': 'Gregg', 'author_id': 7994, 'author_profile': 'https://Stackoverflow.com/users/7994', 'pm_score': 1, 'selected': False, 'text': '<p>The <a href="http://www.yourkit.com/" rel="nofollow noreferrer">YourKit</a> Java profiler is an excellent commercial solution. You can find further information in the docs on <a href="http://www.yourkit.com/docs/75/help/cpu_profiling/cpu_intro.jsp" rel="nofollow noreferrer">CPU profiling</a> and <a href="http://www.yourkit.com/docs/75/help/memory_profiling/memory_telemetry.jsp" rel="nofollow noreferrer">memory profiling</a>.</p>\n'}, {'answer_id': 75129, 'author': 'Javamann', 'author_id': 10166, 'author_profile': 'https://Stackoverflow.com/users/10166', 'pm_score': 4, 'selected': False, 'text': '<p>JMX, The MXBeans (ThreadMXBean, etc) provided will give you Memory and CPU usages.</p>\n\n<pre><code>OperatingSystemMXBean operatingSystemMXBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();\noperatingSystemMXBean.getSystemCpuLoad();\n</code></pre>\n'}, {'answer_id': 76113, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 4, 'selected': False, 'text': '<p>If you are using the Sun JVM, and are interested in the internal memory usage of the application (how much out of the allocated memory your app is using) I prefer to turn on the JVMs built-in garbage collection logging. You simply add -verbose:gc to the startup command.</p>\n\n<p>From the Sun documentation:</p>\n\n<blockquote>\n <p>The command line argument -verbose:gc prints information at every\n collection. Note that the format of the -verbose:gc output is subject\n to change between releases of the J2SE platform. For example, here is\n output from a large server application:</p>\n\n<pre><code>[GC 325407K-&gt;83000K(776768K), 0.2300771 secs]\n[GC 325816K-&gt;83372K(776768K), 0.2454258 secs]\n[Full GC 267628K-&gt;83769K(776768K), 1.8479984 secs]\n</code></pre>\n \n <p>Here we see two minor collections and one major one. The numbers\n before and after the arrow</p>\n\n<pre><code>325407K-&gt;83000K (in the first line)\n</code></pre>\n \n <p>indicate the combined size of live objects before and after garbage\n collection, respectively. After minor collections the count includes\n objects that aren\'t necessarily alive but can\'t be reclaimed, either\n because they are directly alive, or because they are within or\n referenced from the tenured generation. The number in parenthesis</p>\n\n<pre><code>(776768K) (in the first line)\n</code></pre>\n \n <p>is the total available space, not counting the space in the permanent\n generation, which is the total heap minus one of the survivor spaces.\n The minor collection took about a quarter of a second.</p>\n\n<pre><code>0.2300771 secs (in the first line)\n</code></pre>\n</blockquote>\n\n<p>For more info see: <a href="http://java.sun.com/docs/hotspot/gc5.0/gc_tuning_5.html" rel="noreferrer">http://java.sun.com/docs/hotspot/gc5.0/gc_tuning_5.html</a></p>\n'}, {'answer_id': 7870722, 'author': 'Phil', 'author_id': 661773, 'author_profile': 'https://Stackoverflow.com/users/661773', 'pm_score': 2, 'selected': False, 'text': '<p>Here is some simple code to calculate the current memory usage in megabytes:</p>\n\n<pre><code>double currentMemory = ( (double)((double)(Runtime.getRuntime().totalMemory()/1024)/1024))- ((double)((double)(Runtime.getRuntime().freeMemory()/1024)/1024));\n</code></pre>\n'}, {'answer_id': 8038928, 'author': 'Fuangwith S.', 'author_id': 24550, 'author_profile': 'https://Stackoverflow.com/users/24550', 'pm_score': 0, 'selected': False, 'text': '<p>For Eclipse, you can use TPTP (Test and Performance Tools Platform) for analyse memory usage and etc. <a href="http://eclipse.org/articles/Article-TPTP-Profiling-Tool/tptpProfilingArticle.html" rel="nofollow">more information</a></p>\n'}, {'answer_id': 8973770, 'author': 'Dave', 'author_id': 1165214, 'author_profile': 'https://Stackoverflow.com/users/1165214', 'pm_score': 5, 'selected': False, 'text': '<pre><code>import java.io.File;\nimport java.text.NumberFormat;\n\npublic class SystemInfo {\n\n private Runtime runtime = Runtime.getRuntime();\n\n public String info() {\n StringBuilder sb = new StringBuilder();\n sb.append(this.osInfo());\n sb.append(this.memInfo());\n sb.append(this.diskInfo());\n return sb.toString();\n }\n\n public String osName() {\n return System.getProperty(&quot;os.name&quot;);\n }\n\n public String osVersion() {\n return System.getProperty(&quot;os.version&quot;);\n }\n\n public String osArch() {\n return System.getProperty(&quot;os.arch&quot;);\n }\n\n public long totalMem() {\n return Runtime.getRuntime().totalMemory();\n }\n\n public long usedMem() {\n return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();\n }\n\n public String memInfo() {\n NumberFormat format = NumberFormat.getInstance();\n StringBuilder sb = new StringBuilder();\n long maxMemory = runtime.maxMemory();\n long allocatedMemory = runtime.totalMemory();\n long freeMemory = runtime.freeMemory();\n sb.append(&quot;Free memory: &quot;);\n sb.append(format.format(freeMemory / 1024));\n sb.append(&quot;&lt;br/&gt;&quot;);\n sb.append(&quot;Allocated memory: &quot;);\n sb.append(format.format(allocatedMemory / 1024));\n sb.append(&quot;&lt;br/&gt;&quot;);\n sb.append(&quot;Max memory: &quot;);\n sb.append(format.format(maxMemory / 1024));\n sb.append(&quot;&lt;br/&gt;&quot;);\n sb.append(&quot;Total free memory: &quot;);\n sb.append(format.format((freeMemory + (maxMemory - allocatedMemory)) / 1024));\n sb.append(&quot;&lt;br/&gt;&quot;);\n return sb.toString();\n\n }\n\n public String osInfo() {\n StringBuilder sb = new StringBuilder();\n sb.append(&quot;OS: &quot;);\n sb.append(this.osName());\n sb.append(&quot;&lt;br/&gt;&quot;);\n sb.append(&quot;Version: &quot;);\n sb.append(this.osVersion());\n sb.append(&quot;&lt;br/&gt;&quot;);\n sb.append(&quot;: &quot;);\n sb.append(this.osArch());\n sb.append(&quot;&lt;br/&gt;&quot;);\n sb.append(&quot;Available processors (cores): &quot;);\n sb.append(runtime.availableProcessors());\n sb.append(&quot;&lt;br/&gt;&quot;);\n return sb.toString();\n }\n\n public String diskInfo() {\n /* Get a list of all filesystem roots on this system */\n File[] roots = File.listRoots();\n StringBuilder sb = new StringBuilder();\n\n /* For each filesystem root, print some info */\n for (File root : roots) {\n sb.append(&quot;File system root: &quot;);\n sb.append(root.getAbsolutePath());\n sb.append(&quot;&lt;br/&gt;&quot;);\n sb.append(&quot;Total space (bytes): &quot;);\n sb.append(root.getTotalSpace());\n sb.append(&quot;&lt;br/&gt;&quot;);\n sb.append(&quot;Free space (bytes): &quot;);\n sb.append(root.getFreeSpace());\n sb.append(&quot;&lt;br/&gt;&quot;);\n sb.append(&quot;Usable space (bytes): &quot;);\n sb.append(root.getUsableSpace());\n sb.append(&quot;&lt;br/&gt;&quot;);\n }\n return sb.toString();\n }\n}\n</code></pre>\n'}, {'answer_id': 15733233, 'author': 'danieln', 'author_id': 1083423, 'author_profile': 'https://Stackoverflow.com/users/1083423', 'pm_score': 4, 'selected': False, 'text': '<p>From <a href="http://knight76.blogspot.co.il/2009/05/how-to-get-java-cpu-usage-jvm-instance.html">here</a></p>\n\n<pre><code> OperatingSystemMXBean operatingSystemMXBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();\n RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();\n int availableProcessors = operatingSystemMXBean.getAvailableProcessors();\n long prevUpTime = runtimeMXBean.getUptime();\n long prevProcessCpuTime = operatingSystemMXBean.getProcessCpuTime();\n double cpuUsage;\n try\n {\n Thread.sleep(500);\n }\n catch (Exception ignored) { }\n\n operatingSystemMXBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();\n long upTime = runtimeMXBean.getUptime();\n long processCpuTime = operatingSystemMXBean.getProcessCpuTime();\n long elapsedCpu = processCpuTime - prevProcessCpuTime;\n long elapsedTime = upTime - prevUpTime;\n\n cpuUsage = Math.min(99F, elapsedCpu / (elapsedTime * 10000F * availableProcessors));\n System.out.println("Java CPU: " + cpuUsage);\n</code></pre>\n'}, {'answer_id': 31187628, 'author': 'sbeliakov', 'author_id': 2182091, 'author_profile': 'https://Stackoverflow.com/users/2182091', 'pm_score': 2, 'selected': False, 'text': '<p>I would also add the following way to track CPU Load:</p>\n\n<pre><code>import java.lang.management.ManagementFactory;\nimport com.sun.management.OperatingSystemMXBean;\n\ndouble getCpuLoad() {\n OperatingSystemMXBean osBean =\n (com.sun.management.OperatingSystemMXBean) ManagementFactory.\n getPlatformMXBeans(OperatingSystemMXBean.class);\n return osBean.getProcessCpuLoad();\n}\n</code></pre>\n\n<p>You can read more <a href="https://www.java.net/community-item/hidden-java-7-features-%E2%80%93-system-and-process-cpu-load-monitoring" rel="nofollow">here</a></p>\n'}, {'answer_id': 69076398, 'author': 'Antonio Noack', 'author_id': 4979303, 'author_profile': 'https://Stackoverflow.com/users/4979303', 'pm_score': 0, 'selected': False, 'text': '<p>I want to add a note to the existing answers:</p>\n<p>These methods only keep track of JVM Memory. The actual process may consume more memory.</p>\n<p>java.nio.ByteBuffer.allocateDirect() is a function/library, that is easily missed, and indeed allocated native memory, that is not part of the Java memory management.</p>\n<p>On Linux, you may use something like this to get the actually consumed memory: <a href="https://linuxhint.com/check_memory_usage_process_linux/" rel="nofollow noreferrer">https://linuxhint.com/check_memory_usage_process_linux/</a></p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74674', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13123/']
74,689
<p>How do you guys manage the information overflow? What are the tools that you guys use? One of the usefull tool is RSS feed reader. Does Any body uses any other tools or any other ways to effectively manage the information?</p>
[{'answer_id': 74697, 'author': 'Ian P', 'author_id': 10853, 'author_profile': 'https://Stackoverflow.com/users/10853', 'pm_score': 0, 'selected': False, 'text': '<p>Well, this is an obvious one, but iGoogle seems to do a great job for me.</p>\n'}, {'answer_id': 74717, 'author': 'Lucas Oman', 'author_id': 6726, 'author_profile': 'https://Stackoverflow.com/users/6726', 'pm_score': 3, 'selected': True, 'text': "<p>Be an information snob.</p>\n\n<p>If the blog doesn't absolutely rock your world, don't read it. It's so easy to get bogged down, even obsessed, with too much information. No matter what tools you have, you're still human and can only read so many words per day.</p>\n"}, {'answer_id': 74727, 'author': 'Tomo', 'author_id': 9622, 'author_profile': 'https://Stackoverflow.com/users/9622', 'pm_score': 2, 'selected': False, 'text': '<p>I use <a href="http://evernote.com/" rel="nofollow noreferrer">Evernote</a> to keep notes and search through them.</p>\n'}, {'answer_id': 74734, 'author': 'Mostlyharmless', 'author_id': 12881, 'author_profile': 'https://Stackoverflow.com/users/12881', 'pm_score': 0, 'selected': False, 'text': '<p>Depends on what information you are looking to manage. Can you be more specific?\nI use google reader to handle things i read, RememberTheMilk to remind me of what i have to do, and gmail overall to quickly store and search data/correspondences. \nOh and i use the <a href="http://www.43folders.com/2004/09/03/introducing-the-hipster-pda" rel="nofollow noreferrer">hipster PDA</a> too!</p>\n\n<p>You should probably check out <a href="http://lifehacker.com/" rel="nofollow noreferrer">Lifehacker</a> for more tools and Getting Things Done apps.</p>\n'}, {'answer_id': 74752, 'author': 'Jesper Blad Jensen', 'author_id': 11559, 'author_profile': 'https://Stackoverflow.com/users/11559', 'pm_score': 0, 'selected': False, 'text': "<p>Like you say most sites have a RSS feed today. Get a RSS Reader that sync between computers if you use more than one computer, so you don't have to mark alot of post as read. A good program is FeedDeamon, its free and sync between computers, there is even a online version as well, if you are on the road. FeedDeamon also have tools to help you identify the feeds, that you dont really read, and gives you a top 10 of feeds that you look on alot. This can help you delete bad RSS-Feeds, and also help you organize you're feeds.</p>\n\n<p>I also use Delicious, to keep my bookmarks in sync, and is very handy if you bookmark alot.</p>\n\n<p>Other than that, I don't really use any more tools - just the common sence that there is only 24 hours in the day, so dont use it to just read information that you don't need - bookmark interesting blog post from RSS, and read them later when you need to.</p>\n"}, {'answer_id': 74768, 'author': 'metadave', 'author_id': 7237, 'author_profile': 'https://Stackoverflow.com/users/7237', 'pm_score': 0, 'selected': False, 'text': '<p>I\'ve been using <a href="http://delicious.com" rel="nofollow noreferrer">Delicious</a> quite a bit over the past 2 years and it\'s been a great help.</p>\n'}, {'answer_id': 74779, 'author': 'Chris Wuestefeld', 'author_id': 10082, 'author_profile': 'https://Stackoverflow.com/users/10082', 'pm_score': 0, 'selected': False, 'text': '<p>If you\'re primarily interested in blogs, what I think we need is a way to prioritize the information that we, <strong>personally</strong>, are interested in. There used to be an RSS reader called wTicker (now demised) that used Bayesian filtering to rate articles for you. Another product under development, <a href="http://www.particls.com/" rel="nofollow noreferrer">Particls</a>, would similarly watch what you read and highlight similar content.</p>\n\n<p>What about other types of information, though? For example, the tasks that OneNote or EverNote, or more obscure tools like <a href="http://www.zootsoftware.com/" rel="nofollow noreferrer">Zoot</a> aim to facilitate?</p>\n'}, {'answer_id': 75416, 'author': 'Kristian', 'author_id': 12911, 'author_profile': 'https://Stackoverflow.com/users/12911', 'pm_score': 2, 'selected': False, 'text': '<p>I use Google Reader for the feeds. Split it up in multiple categories, \'A\' with the more unique stuff, \'B\' with the spam (Digg for example, easy to ignore because the important stuff shows up in \'A\'), \'C\' for my webcomics.</p>\n\n<p>I always read the stuff in \'A\', when bored I read \'C\' and \'B\' when I have spare time. It happens a lot of time that I\'ll mark \'B\' as read just to get rid of it.</p>\n\n<p>For work I\'m stuck with Outlook, so I use the \'Tasks\' function of Outlook a lot to get things sorted. Also a big believer of \'Inbox Zero\' (<a href="http://www.43folders.com/izero" rel="nofollow noreferrer">http://www.43folders.com/izero</a>).</p>\n'}, {'answer_id': 75574, 'author': 'spinodal', 'author_id': 11374, 'author_profile': 'https://Stackoverflow.com/users/11374', 'pm_score': 0, 'selected': False, 'text': '<p>It depends on the type of information you meant. The answers above contain most of the tools. But if you use ms office you shall explore Office OneNote.</p>\n'}, {'answer_id': 94894, 'author': 'jtimberman', 'author_id': 7672, 'author_profile': 'https://Stackoverflow.com/users/7672', 'pm_score': 1, 'selected': False, 'text': '<p>I use a small number of tools and techniques, because it is easy to get distracted managing the information management tools, rather than managing the information.</p>\n\n<ol>\n<li><p>Google Reader - The key for me was creating @work and @home labels, for the appropriate location.</p></li>\n<li><p>TiddlyWiki - I keep track of all my notes for work projects in a TiddlyWiki file. </p></li>\n<li><p>Delicious - I keep my bookmarks here. When I come across a link I want to read later (usually in my RSS Reader), I tag it @readreview. When I read it, I delete it unless it is useful reference, then I retag appropriately.</p></li>\n<li><p>Local bookmarks - I store bookmarks on the browser toolbar in folders so I can middle-click and open all in tabs. Obviously these would be limited in number :-). I also have a bookmarklets folder.</p></li>\n</ol>\n\n<p>I don\'t have a PDA. I have a pad of graph paper on my desk that I use for writing temporary notes and diagrams (permanent notes go into the TiddlyWiki). A lot of "productivity blogs" like to promote various tools, and some of these caught on for people, but I find my system is pretty simple and easy for me to manage. This makes it useful.</p>\n'}, {'answer_id': 95129, 'author': 'Svetlana', 'author_id': 2279145, 'author_profile': 'https://Stackoverflow.com/users/2279145', 'pm_score': 0, 'selected': False, 'text': '<ol>\n<li>iGoogle: News, RSS, Wether, New Films, E-Mail widgets</li>\n<li>ToDoList: every day work aspects</li>\n<li>Local MediaWiki, for local company knowleges</li>\n<li>Smartphone MS Excel for personal finances.</li>\n</ol>\n'}, {'answer_id': 63631268, 'author': 'Igor Stefurak', 'author_id': 4703032, 'author_profile': 'https://Stackoverflow.com/users/4703032', 'pm_score': 0, 'selected': False, 'text': '<ol>\n<li>I still read news and blogs from RSS feeds. <a href="https://feedly.com/" rel="nofollow noreferrer">Feedly</a> is the best tool for that right now.</li>\n<li>When I find something interesting in Feedly, I add it to <a href="https://getpocket.com" rel="nofollow noreferrer">Pocket</a> and read later. A Premium account allows me to highlight paragraphs I would like to save.</li>\n<li>I also set up a receipt on <a href="https://ifttt.com/" rel="nofollow noreferrer">IFTTT</a> that monitors my likes on Twitter and adds links from the liked tweets to Pocket too.</li>\n<li>As Substack grows, there is the new email newsletter boom. But my inbox is also a place where I do my work. So, I wrote an apps script file to receive newsletters once or twice a day and prevent them from distracting me from work. And then, I published it as <a href="https://gsuite.google.com/marketplace/app/silent_inbox/236151031043" rel="nofollow noreferrer">Silent Inbox</a> add-on that plugs into your Gmail.</li>\n</ol>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74689', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13128/']
74,690
<p>I have a QMainWindow in a Qt application. When I close it I want it to store its current restore size (the size of the window when it is not maximized). This works well when I close the window in restore mode (that is, not maximized). But if I close the window if it is maximized, then next time i start the application and restore the application (because it starts in maximized mode), then it does not remember the size it should restore to. Is there a way to do this?</p>
[{'answer_id': 74885, 'author': 'dF.', 'author_id': 3002, 'author_profile': 'https://Stackoverflow.com/users/3002', 'pm_score': 2, 'selected': False, 'text': "<p>I've encountered this problem as well.</p>\n\n<p>What you can do: in addition to the window's size, save whether it's maximized or not (<code>QWidget::isMaximized()</code>). </p>\n\n<p>Then next time you start the application, first set the size (<code>QWidget::resize()</code>) and then maximize it if appropriate (<code>QWidget::showMaximized()</code>). When it's restored, it should return to the correct size.</p>\n"}, {'answer_id': 76699, 'author': 'Colin Jensen', 'author_id': 9884, 'author_profile': 'https://Stackoverflow.com/users/9884', 'pm_score': 5, 'selected': True, 'text': '<p>Use the <a href="http://doc.qt.io/qt-4.8/qwidget.html#saveGeometry" rel="nofollow noreferrer">QWidget::saveGeometry</a> feature to write the current settings into the registry.(The registry is accessed using QSettings). Then use restoreGeometry() upon startup to return to the previous state.</p>\n'}, {'answer_id': 8736705, 'author': 'iforce2d', 'author_id': 624593, 'author_profile': 'https://Stackoverflow.com/users/624593', 'pm_score': 4, 'selected': False, 'text': '<p>I found that a combination of all the previous answers here was necessary on Fedora 14. Be careful <strong>not</strong> to save the size and position when the window is maximized!</p>\n\n<pre><code>void MainWindow::writePositionSettings()\n{\n QSettings qsettings( "iforce2d", "killerapp" );\n\n qsettings.beginGroup( "mainwindow" );\n\n qsettings.setValue( "geometry", saveGeometry() );\n qsettings.setValue( "savestate", saveState() );\n qsettings.setValue( "maximized", isMaximized() );\n if ( !isMaximized() ) {\n qsettings.setValue( "pos", pos() );\n qsettings.setValue( "size", size() );\n }\n\n qsettings.endGroup();\n}\n\nvoid MainWindow::readPositionSettings()\n{\n QSettings qsettings( "iforce2d", "killerapp" );\n\n qsettings.beginGroup( "mainwindow" );\n\n restoreGeometry(qsettings.value( "geometry", saveGeometry() ).toByteArray());\n restoreState(qsettings.value( "savestate", saveState() ).toByteArray());\n move(qsettings.value( "pos", pos() ).toPoint());\n resize(qsettings.value( "size", size() ).toSize());\n if ( qsettings.value( "maximized", isMaximized() ).toBool() )\n showMaximized();\n\n qsettings.endGroup();\n}\n</code></pre>\n\n<p>In main(), the position settings are read before showing the window the first time...</p>\n\n<pre><code>MainWindow mainWindow;\nmainWindow.readPositionSettings();\nmainWindow.show();\n</code></pre>\n\n<p>...and these event handlers update the settings as necessary. (This causes a writes to the settings file for every mouse movement during the move and resize which is not ideal.)</p>\n\n<pre><code>void MainWindow::moveEvent( QMoveEvent* )\n{\n writePositionSettings();\n}\n\nvoid MainWindow::resizeEvent( QResizeEvent* )\n{\n writePositionSettings();\n}\n\nvoid MainWindow::closeEvent( QCloseEvent* )\n{\n writePositionSettings();\n}\n</code></pre>\n\n<p>Still, the vertical component of the position is not quite right, it seems to be ignoring the height of the window title bar... if anyone knows how to deal with that let me know :)</p>\n'}, {'answer_id': 10866437, 'author': 'Raimar', 'author_id': 894142, 'author_profile': 'https://Stackoverflow.com/users/894142', 'pm_score': 0, 'selected': False, 'text': '<p>The image at <a href="http://qt-project.org/doc/qt-4.8/application-windows.html" rel="nofollow">http://qt-project.org/doc/qt-4.8/application-windows.html</a> shows, that <code>geometry.x()</code> and <code>geometry.y()</code> are not equal to <code>x()</code> and <code>y()</code>, which are the same as <code>pos()</code>.</p>\n\n<p>In my case, I use:</p>\n\n<pre><code>x()\ny()\nwidth()\nheight()\n</code></pre>\n\n<p>and restore these successfully with: </p>\n\n<pre><code>move()\nresize()\n</code></pre>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74690', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1585/']
74,693
<p>I would like to avoid using native libaries if at all possible. Surely there is a better way to solve this issue for Linux, Windows and Mac OS X.</p>
[{'answer_id': 74804, 'author': 'Steve g', 'author_id': 12092, 'author_profile': 'https://Stackoverflow.com/users/12092', 'pm_score': 0, 'selected': False, 'text': '<p>You can use the Java Sound API. I believe this is part of java 5. This may allow you to do what you want to do.</p>\n\n<p><a href="http://java.sun.com/products/java-media/sound/" rel="nofollow noreferrer">http://java.sun.com/products/java-media/sound/</a> </p>\n\n<p>here are some examples:</p>\n\n<p><a href="http://www.jsresources.org/examples/" rel="nofollow noreferrer">http://www.jsresources.org/examples/</a></p>\n'}, {'answer_id': 237297, 'author': 'wnoise', 'author_id': 15464, 'author_profile': 'https://Stackoverflow.com/users/15464', 'pm_score': 2, 'selected': False, 'text': "<p>Sorry, you're out of luck. You'll need JNI, and it'll be obnoxiously different for different platforms. The base java libraries cover tasks and hardware that are pretty much universal. CD drives weren't and aren't considered so.</p>\n"}]
2008/09/16
['https://Stackoverflow.com/questions/74693', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13098/']
74,696
<p>I have a C++ program that when run, by default, displays the X in the upper right corner. Clicking X, minimizes the program. I've added code using the SHInitDialog function to change the X to OK, so that clicking OK exits the program.</p> <p>My question: Is there a better method that applies to the window, since SHInitDialog works best with Dialog Boxes?</p>
[{'answer_id': 74719, 'author': 'ageektrapped', 'author_id': 631, 'author_profile': 'https://Stackoverflow.com/users/631', 'pm_score': 0, 'selected': False, 'text': "<p>Not sure how it's done in C++, but in .NET if you set the MinimizeBox property to false, you get an OK button. Since .NET Windows code is fancy wrapper code, there should be a C++ equivalent</p>\n"}, {'answer_id': 74775, 'author': 'ctacke', 'author_id': 13154, 'author_profile': 'https://Stackoverflow.com/users/13154', 'pm_score': 2, 'selected': False, 'text': '<p>Take a look at <a href="http://msdn.microsoft.com/en-us/library/aa453682.aspx" rel="nofollow noreferrer">SHDoneButton</a> API.</p>\n'}, {'answer_id': 75346, 'author': 'Jack Snipes', 'author_id': 1382, 'author_profile': 'https://Stackoverflow.com/users/1382', 'pm_score': 3, 'selected': True, 'text': '<p>With Windows Mobile 5.0 and higher, using the CreateWindowEx function passing it WS_EX_CAPTIONOKBTN for the extended style works.</p>\n\n<p>@ctacke SHDoneButton may have also worked but I wanted to change the main window without handling it like a dialogbox, which is basically what SHInitDialog is doing.</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74696', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1382/']
74,723
<p>This problem has been afflicting me for quite a while and it's been really annoying.</p> <p>Every time I login after a reboot/power cycle the explorer takes some time to show up. I've taken the step of waiting for all the services to boot up and then I login, but it doesn't make any difference. The result is always the same: Some of the icons do not show up even if the applications have started.</p> <p>I've dug a bit on the code that makes one application "stick" an icon in there, but is there an API call that one can perform so explorer re-reads all that icon info? Like invalidate or redraw or something of the sort?</p> <hr> <p>Apparently, it looks like Jon was right and it's not possible to do it.</p> <p>I've followed Bob Dizzle and Mark Ransom code and build this (Delphi Code):</p> <pre><code>procedure Refresh; var hSysTray: THandle; begin hSysTray := GetSystrayHandle; SendMessage(hSysTray, WM_PAINT, 0, 0); end; function GetSystrayHandle: THandle; var hTray, hNotify, hSysPager: THandle; begin hTray := FindWindow('Shell_TrayWnd', ''); if hTray = 0 then begin Result := hTray; exit; end; hNotify := FindWindowEx(hTray, 0, 'TrayNotifyWnd', ''); if hNotify = 0 then begin Result := hNotify; exit; end; hSyspager := FindWindowEx(hNotify, 0, 'SysPager', ''); if hSyspager = 0 then begin Result := hSyspager; exit; end; Result := FindWindowEx(hSysPager, 0, 'ToolbarWindow32', 'Notification Area'); end;</code></pre> <p>But to no avail.</p> <p>I've even tried with <pre><code>InvalidateRect()</code></pre> and still no show.</p> <p>Any other suggestions?</p>
[{'answer_id': 74769, 'author': 'Jonathan Sayce', 'author_id': 13153, 'author_profile': 'https://Stackoverflow.com/users/13153', 'pm_score': 2, 'selected': False, 'text': "<p>As far as I know that isn't possible Gustavo - it's up to each application to put its notifyicon in the systray, and ensure it's kept in the right state. </p>\n\n<p>You'll notice sometimes when explorer.exe crashes that certain icons don't reappear - this isn't because their process has crashed, simply that their application hasn't put the notifyicon in the systray when the new instance of explorer.exe started up. Once again, it's the application that's responsible.</p>\n\n<p>Sorry not to have better news for you!</p>\n"}, {'answer_id': 74781, 'author': 'Bob Dizzle', 'author_id': 9581, 'author_profile': 'https://Stackoverflow.com/users/9581', 'pm_score': 2, 'selected': False, 'text': '<p>Include following code with yours to refresh System Tray.</p>\n\n<pre><code>public const int WM_PAINT = 0xF;\n[DllImport("USER32.DLL")]\npublic static extern int SendMessage(IntPtr hwnd, int msg, int character,\n IntPtr lpsText);\n\nSend WM_PAINT Message to paint System Tray which will refresh it.\nSendMessage(traynotifywnd, WM_PAINT, 0, IntPtr.Zero);\n</code></pre>\n'}, {'answer_id': 74871, 'author': 'Mark Ransom', 'author_id': 5987, 'author_profile': 'https://Stackoverflow.com/users/5987', 'pm_score': 1, 'selected': False, 'text': '<p>I use the following C++ code to get the window handle to the tray window. <strong>Note:</strong> this has only been tested on Windows XP.</p>\n\n<p><pre><code>HWND FindSystemTrayIcons(void)\n{\n // the system tray icons are contained in a specific window hierarchy;\n // use the Spy++ utility to see the chain\n HWND hwndTray = ::FindWindow("Shell_TrayWnd", "");\n if (hwndTray == NULL)\n return NULL;\n HWND hwndNotifyWnd = ::FindWindowEx(hwndTray, NULL, "TrayNotifyWnd", "");\n if (hwndNotifyWnd == NULL)\n return NULL;\n HWND hwndSysPager = ::FindWindowEx(hwndNotifyWnd, NULL, "SysPager", "");\n if (hwndSysPager == NULL)\n return NULL;\n return ::FindWindowEx(hwndSysPager, NULL, "ToolbarWindow32", "Notification Area");\n}\n</pre></code></p>\n'}, {'answer_id': 1052920, 'author': 'Louis Davis', 'author_id': 103205, 'author_profile': 'https://Stackoverflow.com/users/103205', 'pm_score': 5, 'selected': True, 'text': '<p>Take a look at this blog entry: <a href="http://malwareanalysis.com/CommunityServer/blogs/geffner/archive/2008/02/15/985.aspx" rel="noreferrer">REFRESHING THE TASKBAR NOTIFICATION AREA</a>. I am using this code to refresh the system tray to get rid of orphaned icons and it works perfectly.\nThe blog entry is very informative and gives a great explanation of the steps the author performed to discover his solution.</p>\n\n<pre><code>#define FW(x,y) FindWindowEx(x, NULL, y, L"")\n\nvoid RefreshTaskbarNotificationArea()\n{\n HWND hNotificationArea;\n RECT r;\n\n GetClientRect(\n hNotificationArea = FindWindowEx(\n FW(FW(FW(NULL, L"Shell_TrayWnd"), L"TrayNotifyWnd"), L"SysPager"),\n NULL,\n L"ToolbarWindow32",\n // L"Notification Area"), // Windows XP\n L"User Promoted Notification Area"), // Windows 7 and up\n &amp;r);\n\n for (LONG x = 0; x &lt; r.right; x += 5)\n for (LONG y = 0; y &lt; r.bottom; y += 5)\n SendMessage(\n hNotificationArea,\n WM_MOUSEMOVE,\n 0,\n (y &lt;&lt; 16) + x);\n}\n</code></pre>\n'}, {'answer_id': 1052937, 'author': 'bugmagnet', 'author_id': 426, 'author_profile': 'https://Stackoverflow.com/users/426', 'pm_score': 2, 'selected': False, 'text': '<p>I covered this issue last year on my <a href="http://codeaholic.blogspot.com" rel="nofollow noreferrer">Codeaholic</a> weblog in an article entitled <a href="http://codeaholic.blogspot.com/2008/07/delphi-updating-systray.html" rel="nofollow noreferrer">[Delphi] Updating SysTray</a>. </p>\n\n<p>My solution is a Delphi ActiveX/COM DLL. The download link still works (though for how much longer I don\'t know as my <a href="http://www.plug.org.au" rel="nofollow noreferrer">PLUG</a> membership has lapsed.)</p>\n'}, {'answer_id': 18038441, 'author': 'Stephen Klancher', 'author_id': 221018, 'author_profile': 'https://Stackoverflow.com/users/221018', 'pm_score': 4, 'selected': False, 'text': '<p>Two important details for anyone using Louis\'s answer (from <a href="http://malwareanalysis.com/CommunityServer/blogs/geffner/archive/2008/02/15/985.aspx">REFRESHING THE TASKBAR NOTIFICATION AREA</a>) on Windows 7 or Windows 8:</p>\n\n<p>First, as the answer was reflected to show, the window titled "Notification Area" in XP is now titled "User Promoted Notification Area" in Windows 7 (actually probably Vista) and up.</p>\n\n<p>Second, this code does not clear icons that are currently hidden. These are contained in a separate window. Use the original code to refresh visible icons, and the following to refresh hidden icons.</p>\n\n<pre><code>//Hidden icons\nGetClientRect(\n hNotificationArea = FindWindowEx(\n FW(NULL, L"NotifyIconOverflowWindow"),\n NULL,\n L"ToolbarWindow32",\n L"Overflow Notification Area"),\n &amp;r);\n\nfor (LONG x = 0; x &lt; r.right; x += 5)\n for (LONG y = 0; y &lt; r.bottom; y += 5)\n SendMessage(\n hNotificationArea,\n WM_MOUSEMOVE,\n 0,\n (y &lt;&lt; 16) + x);\n</code></pre>\n\n<p>For anyone who just needs a utility to run to accomplish this, rather than code, I built a simple exe with this update: <a href="http://projects.stephenklancher.com/project/id/88/Refresh_Notification_Area">Refresh Notification Area</a></p>\n'}, {'answer_id': 53938471, 'author': 'user2712225', 'author_id': 2712225, 'author_profile': 'https://Stackoverflow.com/users/2712225', 'pm_score': 0, 'selected': False, 'text': '<p>@Skip R, and anyone else wanting to do this in C, with this code verified compiled in a recent (most recent) mingw on Windows 10 64 bit (but with the mingw 32 bit package installed), this seems to work in Windows XP / 2003 to get rid of stale notification area icons.</p>\n\n<p>I installed mingw via Chocolatey, like this:</p>\n\n<pre><code>choco install mingw --x86 --force --params "/exception:sjlj"\n</code></pre>\n\n<p>(your mileage may vary on that, on my system, the compiler was then installed here:</p>\n\n<pre><code>C:\\ProgramData\\chocolatey\\lib\\mingw\\tools\\install\\mingw32\\bin\\gcc.exe\n</code></pre>\n\n<p>and then a simple</p>\n\n<pre><code>gcc refresh_notification_area.c\n</code></pre>\n\n<p>yielded an a.exe which solved a stale notification area icon problem I was having on Windows 2003 (32 bit).</p>\n\n<p>The code, adapted from @Stephen Klancher above is (note this may only work on Windows XP/2003, which fulfilled my purposes):</p>\n\n<pre><code>#include &lt;windows.h&gt;\n\n#define FW(x,y) FindWindowEx(x, NULL, y, "")\n\nint main ()\n{\n\n HWND hNotificationArea;\n RECT r;\n\n //WinXP\n // technique found at:\n // https://stackoverflow.com/questions/74723/can-you-send-a-signal-to-windows-explorer-to-make-it-refresh-the-systray-icons#18038441\n GetClientRect(\n hNotificationArea = FindWindowEx(\n FW(FW(FW(NULL, "Shell_TrayWnd"), "TrayNotifyWnd"), "SysPager"),\n NULL,\n "ToolbarWindow32",\n "Notification Area"),\n &amp;r);\n\n for (LONG x = 0; x &lt; r.right; x += 5)\n for (LONG y = 0; y &lt; r.bottom; y += 5)\n SendMessage(\n hNotificationArea,\n WM_MOUSEMOVE,\n 0,\n (y &lt;&lt; 16) + x);\n\n return 0;\n\n}\n</code></pre>\n'}, {'answer_id': 56088800, 'author': 'Yuanhui', 'author_id': 5001634, 'author_profile': 'https://Stackoverflow.com/users/5001634', 'pm_score': 1, 'selected': False, 'text': '<p>After lots of times trying I found that there are three issues you must to know:</p>\n\n<ul>\n<li>The parent of hidden tray window is <code>NotifyIconOverflowWindow</code>, other than <code>Shell_TrayWnd</code>.</li>\n<li>You shouldn\'t use <code>caption</code> parameter of <code>FindWindowEx</code> to find a window, because these is lots of langue versions of Windows OS, they are not always be the same title Obviously.</li>\n<li>Use <code>spy++</code> of Visual Studio to find or make assurance what you want.</li>\n</ul>\n\n<p>So, I changed code from @Stephen Klancher and @Louis Davis, thank you guys.</p>\n\n<p>The following code worked for me.</p>\n\n<pre><code>#define FW(x,y) FindWindowEx(x, NULL, y, L"")\nvoid RefreshTaskbarNotificationArea()\n{\n HWND hNotificationArea;\n RECT r;\n GetClientRect(hNotificationArea = FindWindowEx(FW(NULL, L"NotifyIconOverflowWindow"), NULL, L"ToolbarWindow32", NULL), &amp;r);\n for (LONG x = 0; x &lt; r.right; x += 5)\n {\n for (LONG y = 0; y &lt; r.bottom; y += 5)\n {\n SendMessage(hNotificationArea, WM_MOUSEMOVE, 0, (y &lt;&lt; 16) + x);\n }\n }\n}\n</code></pre>\n'}, {'answer_id': 73008007, 'author': 'tom42', 'author_id': 10959519, 'author_profile': 'https://Stackoverflow.com/users/10959519', 'pm_score': 0, 'selected': False, 'text': '<p>Powershell solution, put this in your script</p>\n<pre><code>Add-Type -AssemblyName System.Windows.Forms\nAdd-Type @&quot;\nusing System;\nusing System.Runtime.InteropServices;\n\npublic struct RECT {\n public int left;\n public int top;\n public int right;\n public int bottom;\n}\n\npublic class pInvoke {\n [DllImport(&quot;user32.dll&quot;)]\n public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);\n\n [DllImport(&quot;user32.dll&quot;)]\n public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);\n\n [DllImport(&quot;user32.dll&quot;)]\n public static extern bool GetClientRect(IntPtr hWnd, out RECT lpRect);\n\n [DllImport(&quot;user32.dll&quot;)]\n public static extern IntPtr SendMessage(IntPtr hWnd, uint msg, int wParam, int lParam);\n \n public static void RefreshTrayArea() {\n IntPtr systemTrayContainerHandle = FindWindow(&quot;Shell_TrayWnd&quot;, null);\n IntPtr systemTrayHandle = FindWindowEx(systemTrayContainerHandle, IntPtr.Zero, &quot;TrayNotifyWnd&quot;, null);\n IntPtr sysPagerHandle = FindWindowEx(systemTrayHandle, IntPtr.Zero, &quot;SysPager&quot;, null);\n IntPtr notificationAreaHandle = FindWindowEx(sysPagerHandle, IntPtr.Zero, &quot;ToolbarWindow32&quot;, &quot;Notification Area&quot;);\n if (notificationAreaHandle == IntPtr.Zero) {\n notificationAreaHandle = FindWindowEx(sysPagerHandle, IntPtr.Zero, &quot;ToolbarWindow32&quot;, &quot;User Promoted Notification Area&quot;);\n IntPtr notifyIconOverflowWindowHandle = FindWindow(&quot;NotifyIconOverflowWindow&quot;, null);\n IntPtr overflowNotificationAreaHandle = FindWindowEx(notifyIconOverflowWindowHandle, IntPtr.Zero, &quot;ToolbarWindow32&quot;, &quot;Overflow Notification Area&quot;);\n RefreshTrayArea(overflowNotificationAreaHandle);\n }\n RefreshTrayArea(notificationAreaHandle);\n }\n\n private static void RefreshTrayArea(IntPtr windowHandle) {\n const uint wmMousemove = 0x0200;\n RECT rect;\n GetClientRect(windowHandle, out rect);\n for (var x = 0; x &lt; rect.right; x += 5)\n for (var y = 0; y &lt; rect.bottom; y += 5)\n SendMessage(windowHandle, wmMousemove, 0, (y &lt;&lt; 16) + x);\n }\n}\n&quot;@\n</code></pre>\n<p>Then use <code>[pInvoke]::RefreshTrayArea()</code> to reset</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74723', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/8167/']
74,728
<p>Is it possible to place an application using vsto if the office is not installed? It doesn't appear to be so, but I was wondering if anyone had a work-around.</p>
[{'answer_id': 78182, 'author': 'Mike Dimmick', 'author_id': 6970, 'author_profile': 'https://Stackoverflow.com/users/6970', 'pm_score': 3, 'selected': True, 'text': "<p>VSTO wraps Office's Automation interfaces. Office is doing the work under the covers, so must be installed.</p>\n"}, {'answer_id': 1846877, 'author': 'Predrag', 'author_id': 224765, 'author_profile': 'https://Stackoverflow.com/users/224765', 'pm_score': 1, 'selected': False, 'text': '<p>Just to compare with Web Office Extensions, did it also need Office installed on the server?</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74728', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13139/']
74,782
<p>What's the difference between eruby and erb? What considerations would drive me to choose one or the other?</p> <p>My application is generating config files for network devices (routers, load balancers, firewalls, etc.). My plan is to template the config files, using embedded ruby (via either eruby or erb) within the source files to do things like iteratively generate all the interface config blocks for a router (these blocks are all very similar, differing only in a label and an IP address). For example, I might have a config template file like this:</p> <pre><code>hostname sample-router &lt;%= r = String.new; [ ["GigabitEthernet1/1", "10.5.16.1"], ["GigabitEthernet1/2", "10.5.17.1"], ["GigabitEthernet1/3", "10.5.18.1"] ].each { |tuple| r &lt;&lt; "interface #{tuple[0]}\n" r &lt;&lt; " ip address #{tuple[1]} netmask 255.255.255.0\n" } r.chomp %&gt; logging 10.5.16.26 </code></pre> <p>which, when run through an embedded ruby interpreter (either erb or eruby), produces the following output:</p> <pre><code>hostname sample-router interface GigabitEthernet1/1 ip address 10.5.16.1 netmask 255.255.255.0 interface GigabitEthernet1/2 ip address 10.5.17.1 netmask 255.255.255.0 interface GigabitEthernet1/3 ip address 10.5.18.1 netmask 255.255.255.0 logging 10.5.16.26 </code></pre>
[{'answer_id': 74807, 'author': 'Jordi Bunster', 'author_id': 4272, 'author_profile': 'https://Stackoverflow.com/users/4272', 'pm_score': 3, 'selected': False, 'text': "<p>Doesn't really matter, they're both the same. erb is pure ruby, eruby is written in C so it's a bit faster.</p>\n\n<p>erubis (a third one) is pure ruby, and faster than both the ones listed above. But I doubt the speed of that is the bottleneck for you, so just use erb. It's part of Ruby Standard Library.</p>\n"}, {'answer_id': 74823, 'author': 'Daniel Spiewak', 'author_id': 9815, 'author_profile': 'https://Stackoverflow.com/users/9815', 'pm_score': 2, 'selected': False, 'text': "<p>Eruby is an external executable, while erb is a library within Ruby. You would use the former if you wanted independent processing of your template files (e.g. quick-and-dirty PHP replacement), and the latter if you needed to process them within the context of some other Ruby script. It is more common to use ERB simply because it is more flexible, but I'll admit that I have been guilty of dabbling in eruby to execute <code>.rhtml</code> files for quick little utility websites.</p>\n"}, {'answer_id': 81574, 'author': 'Jon Wood', 'author_id': 25258, 'author_profile': 'https://Stackoverflow.com/users/25258', 'pm_score': 0, 'selected': False, 'text': '<p>I\'m doing something similar using erb, and the performance is fine for me.</p>\n\n<p>As Jordi said though, it depends what context you want to run this in - if you\'re literally going to use templates like the one you listed, eruby would probably work better, but I\'d guess you\'re actually going to be passing variables to the template, in which case you want erb.</p>\n\n<p>Just for reference, when using erb you\'ll need to pass it the binding for the object you want to take variables from, something like this:</p>\n\n<pre><code>device = Device.new\ndevice.add_interface("GigabitEthernet1/1", "10.5.16.1")\ndevice.add_interface("GigabitEthernet1/2", "10.5.17.1")\n\ntemplate = File.read("/path/to/your/template.erb")\nconfig = ERB.new(template).result(device.binding)\n</code></pre>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74782', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13157/']
74,786
<p>Google created protocol buffers as a replacement for the bulky XML method of data transition. Faster XML processing was just not good enough. Most of the web has grown up as a hodge podge of different technologies that have been integrated to work within the browser or to generate html. JavaScript is separate from HTML. Flash and Silverlight are plugged in the mix as well. We can get the job done with the tools we have but can we do better? <br> Before you mention standards, (which are a good thing to have), think about evolutionary change versus revolutionary change. If Henry Ford asked people about a better way to get around they would have said they wanted a faster horse. (Webkit is a faster horse.) <br> I am hoping there is a project and I just haven’t read of it.</p>
[{'answer_id': 75015, 'author': 'Shog9', 'author_id': 811, 'author_profile': 'https://Stackoverflow.com/users/811', 'pm_score': 2, 'selected': False, 'text': '<p>There are all sorts of "replacements", and have been since before the web existed. The problem with talking about a "replacement" for HTML+JS is that the conversation generally starts out of frustration with one or more specific aspects of the current implementations: </p>\n\n<ul>\n<li>"i hate the lack of presentation-specific tags, can we replace it?"</li>\n<li>"i hate the lack of semantic tags, can we replace it?"</li>\n<li>"i hate the CSS box model, can we replace it?"</li>\n<li>"i hate the sub-par printing support, can we replace it?"</li>\n<li>"i hate the hacks required to get glitzy animation, can we replace it?"</li>\n<li>...</li>\n</ul>\n\n<p>Someone wants a faster horse, someone wants a tireless horse, someone wants a stronger horse, someone wants a horse that smells like burning petroleum instead of, uh, horse... Put all the ideas together and you <em>might</em> get a Model-T... or you might get something out of a Jules Verne / steampunk nightmare. </p>\n\n<p>For every revolution that results in something better, there are scores that produce bloodshed followed by more of the same. Be careful what you wish for...</p>\n'}, {'answer_id': 75085, 'author': 'mislav', 'author_id': 11687, 'author_profile': 'https://Stackoverflow.com/users/11687', 'pm_score': 0, 'selected': False, 'text': '<p>You mentioned two alternatives already: <strong>Silverlight</strong> and <strong>Flash</strong>. It\'s safe to assume that ~95% people have Flash Player installed; Silverlight has also seen quite good adoption in this short amount of time. </p>\n\n<p>But jumping on the eye-candy bandwagon isn\'t necessarily going to make your site better. There will be issues with accessibility, search engines not being to properly index your content, users not being to bookmark pages they want to get back to. Rich graphics pages, although vector, take more to load and can often turn out just annoying (where the goal was visual appeal, the opposite happened). All these things can be worked around or even fixed, but it takes much more resources compared to using standards.</p>\n\n<p>All these things would apply even if there was some new technology that we <em>"haven\'t read of"</em>.</p>\n\n<p>HTTP is as slow as network connection is, not by poor design. It\'s actually very efficient. HTML processing is also blazing fast, considering browsers performed well enough for people using them even on sites with terrible, fat table-based markup. JavaScript scene is looking very bright; there is increased attention on the new version of the specs, multiple implementations, incredible speed advantages in modern browsers over the course of last year. And don\'t think only WebKit is fast -- Opera and Mozilla have never fallen behind.</p>\n\n<p>If you observe what was happening on the Internet in the last 20 years, you would have noticed that proprietary, vendor-dictated technologies eventually got pushed out by open standards. The only reason Flash Player survived was that JavaScript and open video codecs needed some time to get developed. Now that they are here, I think the same thing is going to happen all over again.</p>\n'}, {'answer_id': 75215, 'author': 'Zach', 'author_id': 9128, 'author_profile': 'https://Stackoverflow.com/users/9128', 'pm_score': 0, 'selected': False, 'text': '<p>You might be interested in <a href="http://research.sun.com/projects/lively/" rel="nofollow noreferrer">Sun\'s Lively</a>.</p>\n\n<p>There will also probably be more tools that compile to HTML+JavaScript, so you won\'t have to deal with them directly (like GWT.) There are also projects that try compile other languages to work in the browser (like <a href="http://hotruby.yukoba.jp/" rel="nofollow noreferrer">HotRuby</a>).</p>\n'}, {'answer_id': 77827, 'author': 'matt lohkamp', 'author_id': 14026, 'author_profile': 'https://Stackoverflow.com/users/14026', 'pm_score': 0, 'selected': False, 'text': "<p>so what you're looking for is a paradigm shift in web technology. it's always tough to imagine how that will look - maybe new tech will become a more immersive experience, incorporating more senses then just sight and sound (touch is a good candidate), as well as something that allows for full-range-motion interaction rather then the 2D 'point and click' mouse interface.</p>\n"}, {'answer_id': 78092, 'author': 'ddaa', 'author_id': 11549, 'author_profile': 'https://Stackoverflow.com/users/11549', 'pm_score': 2, 'selected': False, 'text': '<p>HTML+CSS+JS will be replaced by HTML+CSS+SVG+JS, which will be replaced by incrementally more modern versions of the former, sometimes with something new added in the mix. The web technologies of today are very different of the web technologies of 10 years ago. You can expect the landscape will still be different in ten years.</p>\n\n<p>Look where the alpha geeks look. Well, they are all looking at REST designs with lots of Javascript and CSS.</p>\n\n<p>The various "web replacement" technologies promoted by Microsoft, Adobe, Sun, etc. are only here because those companies hope to get people back into lock-in. Pray that they do not succeed.</p>\n\n<p>The web technologies are not be themselve a "hodge-podge". The hodge-podge aspect comes from multiple implementations with their own bugs and quirks. In other words, it comes from open formats implemented in a competitive market.</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74786', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5410/']
74,790
<p>Is it possible to listen for a certain hotkey (e.g:<kbd>Ctrl</kbd><kbd>-</kbd><kbd>I</kbd>) and then perform a specific action? My application is written in C, will only run on Linux, and it doesn't have a GUI. Are there any libraries that help with this kind of task?</p> <p>EDIT: as an example, amarok has global shortcuts, so for example if you map a combination of keys to an action (let's say <kbd>Ctrl</kbd><kbd>-</kbd><kbd>+</kbd>, <kbd>Ctrl</kbd> and <kbd>+</kbd>) you could execute that action when you press the keys. If I would map <kbd>Ctrl</kbd><kbd>-</kbd><kbd>+</kbd> to the volume increase action, each time I press <kbd>ctrl</kbd><kbd>-</kbd><kbd>+</kbd> the volume should increase by a certain amount.</p> <p>Thanks</p>
[{'answer_id': 74988, 'author': "Lawrence D'Anna", 'author_id': 10168, 'author_profile': 'https://Stackoverflow.com/users/10168', 'pm_score': 3, 'selected': True, 'text': '<p>How global do your hotkeys need to be? Is it enough for them to be global for a X session? In that case you should be able to open an Xlib connection and listen for the events you need.</p>\n\n<p>Ordinarily keyboard events in X are delivered to the window that currently has the focus, and propagated up the hierarchy until they are handled. Clearly this is not what we want. We need to process the event before any other window can get to it. We need to call <a href="http://tronche.com/gui/x/xlib/input/XGrabKey.html" rel="nofollow noreferrer">XGrabKey</a> on the root window with the keycode and modifiers of our hotkey to accomplish this.</p>\n\n<p>I found a good example <a href="http://ubuntuforums.org/showpost.php?p=5419687&amp;postcount=1" rel="nofollow noreferrer">here</a>.</p>\n'}, {'answer_id': 74989, 'author': 'Incident', 'author_id': 11613, 'author_profile': 'https://Stackoverflow.com/users/11613', 'pm_score': 0, 'selected': False, 'text': "<p>In UNIX, your access to a commandline shell is via a <strong>terminal</strong>. This harks back to the days when folks accessed their big shared computers literally via terminals connected directly to the machines (e.g. by a serial cable).</p>\n\n<p>In fact, the 'xterm' program or whatever derivative you use on your UNIX box is properly referred to as a <strong>terminal emulator</strong> - it behaves (from both your point of view and that of the operating system) much like one of those old-fashioned terminal machines.</p>\n\n<p>This makes it slightly complicated to handle input in interesting ways, since there are lots of different kinds of terminals, and your UNIX system has to know about the capabilities of each kind. These capabilities were traditionally stored in a <strong>termcap</strong> file, and I think more modern systems use <strong>terminfo</strong> instead. Try</p>\n\n<pre><code>man 5 terminfo\n</code></pre>\n\n<p>on a Linux system for more information.</p>\n\n<p>Now, the good news is that you don't need to do too much messing about with terminal capabilities, etc. to have a commandline application that does interesting things with input or windowing features. There's a library, <strong>curses</strong>, that will help. Lookup </p>\n\n<pre><code>man 3 ncurses\n</code></pre>\n\n<p>on your Linux system for more information. You will probably be able to find a decent tutorial on using curses online.</p>\n"}, {'answer_id': 75025, 'author': 'Chris AtLee', 'author_id': 4558, 'author_profile': 'https://Stackoverflow.com/users/4558', 'pm_score': 1, 'selected': False, 'text': '<p>One way to do it is to have your application listen on a certain port, or socket file, for incoming requests.</p>\n\n<p>Then you can write a small client application that connects to that port or socket file and sends commands to the running application.</p>\n\n<p>Then you can configure your window manager to bind certain key combinations to launch your small client app.</p>\n'}, {'answer_id': 75226, 'author': 'zweiterlinde', 'author_id': 6592, 'author_profile': 'https://Stackoverflow.com/users/6592', 'pm_score': 2, 'selected': False, 'text': '<p>I think <a href="https://stackoverflow.com/questions/74790/is-there-a-way-for-my-binary-to-react-to-some-global-hotkeys-in-linux#74988">smoofra</a> is on the right track here; you\'re looking to register a global hotkey with X so that you can intercept keypresses and take appropriate action. <a href="http://tronche.com/gui/x/xlib/" rel="nofollow noreferrer">Xlib</a> is probably what you want, and <a href="http://tronche.com/gui/x/xlib/input/XGrabKey.html" rel="nofollow noreferrer">XGrabKey</a> is the function, i think.</p>\n\n<p>It\'s not easy to learn, I\'m afraid; I did locate this example that seems useful: <a href="http://incise.org/tinywm.html" rel="nofollow noreferrer">TinyWM</a>. I also found an <a href="http://ubuntuforums.org/showthread.php?p=5787060" rel="nofollow noreferrer">example</a> using Java/JNI (accessing the same underlying Xlib function).</p>\n'}, {'answer_id': 75485, 'author': 'ddaa', 'author_id': 11549, 'author_profile': 'https://Stackoverflow.com/users/11549', 'pm_score': 2, 'selected': False, 'text': '<p>You should look at the source code of <a href="http://hocwp.free.fr/xbindkeys/xbindkeys.html" rel="nofollow noreferrer">xbindkeys</a>.</p>\n\n<p>Xlib programming is pretty arcane, documentation is hard to find, and there are subtle portability issues. You\'ll be better off copying some battle-hardened code.</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74790', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/11234/']
74,818
<p>Our team has been experiencing a recurring problem with velocity templates. Upon rendering, some throw a RuntimeException with the message "Template.merge() failure - Unable to render Velocity Template, '/template.vm'". We have not been able to reproduce the problem and the documentation on the web is pretty insufficient. The problem is not consistently reproducible - the same templates whose rendering sometimes causes the error also manage to display without problems at other times. The Template class <a href="http://www.docjar.com/docs/api/org/apache/velocity/Template.html" rel="nofollow noreferrer">source code</a> is also of little help. Thank you in advance.</p> <hr> <p>Edit: Based on Nathan Bubna's response I need to clarify that we are using Velocity version 1.4.</p> <hr> <p>Edit: Since it was pointed out that a stack trace would be beneficial, here it is:</p> <p>2008-09-15 11:07:57,336 ERROR velocity - Template.merge() failure. The document is null, most likely due to parsing error. 2008-09-15 11:07:57,336 ERROR VelocityResult - Unable to render Velocity Template, '/search/[template-redacted].vm' java.lang.Exception: Template.merge() failure. The document is null, most likely due to parsing error. at org.apache.velocity.Template.merge(Template.java:277) at com.opensymphony.webwork.dispatcher.VelocityResult.doExecute(VelocityResult.java:91) at com.opensymphony.webwork.dispatcher.WebWorkResultSupport.execute(WebWorkResultSupport.java:109) at com.opensymphony.xwork.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:258) at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:182) at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35) at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164) at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35) at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164) at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35) at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164) at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35) at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164) at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35) at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164) at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35) at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164) at com.opensymphony.xwork.DefaultActionProxy.execute(DefaultActionProxy.java:116) at com.opensymphony.webwork.dispatcher.ServletDispatcher.serviceAction(ServletDispatcher.java:272) at com.opensymphony.webwork.dispatcher.ServletDispatcher.service(ServletDispatcher.java:237) at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:39) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at org.nanocontainer.nanowar.webwork2.PicoObjectFactoryFilter.doFilter(PicoObjectFactoryFilter.java:46) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at org.nanocontainer.nanowar.ServletRequestContainerFilter.doFilter(ServletRequestContainerFilter.java:44) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at com.bostoncapital.stuyvesant.RememberUserNameFilter.doFilter(RememberUserNameFilter.java:30) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:482) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:526) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:825) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:738) at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:526) at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684) at java.lang.Thread.run(Unknown Source)</p>
[{'answer_id': 77516, 'author': 'Jorn', 'author_id': 8681, 'author_profile': 'https://Stackoverflow.com/users/8681', 'pm_score': 0, 'selected': False, 'text': "<p>Since the comments in the source already state this shouldn't happen, I think it's a bug in the Template software. Submit a bug report to whoever wrote it.</p>\n"}, {'answer_id': 78409, 'author': 'tgdavies', 'author_id': 11002, 'author_profile': 'https://Stackoverflow.com/users/11002', 'pm_score': 0, 'selected': False, 'text': '<p>You need to get the full stack trace of the RuntimeException and its causes.</p>\n\n<p>Please edit your answer to add that information.</p>\n'}, {'answer_id': 118809, 'author': 'Lyudmil', 'author_id': 13121, 'author_profile': 'https://Stackoverflow.com/users/13121', 'pm_score': 0, 'selected': False, 'text': "<p>I have emailed the authors of the code to see if they can provide some insight. I'll make sure to share anything I've learned.</p>\n"}, {'answer_id': 213983, 'author': 'Nathan Bubna', 'author_id': 8131, 'author_profile': 'https://Stackoverflow.com/users/8131', 'pm_score': 3, 'selected': True, 'text': "<p>What version of Velocity are you using? There were some race conditions in old versions that caused this. Most were squashed in the Velocity 1.5 release. Though i would personally recommend using Velocity 1.6-beta1. It has vastly improved performance (memory and speed) and a lot of minor bug fixes that didn't make it into 1.5.</p>\n\n<p>Edit: Since you say you are using 1.4, then, yes, i'm sure this is the race condition we fixed. Please consider upgrading. 1.6 is definitely your best bet, as it has the fix for your bug and improved performance. 1.6 final should be out very soon.</p>\n"}, {'answer_id': 241901, 'author': 'user26294', 'author_id': 26294, 'author_profile': 'https://Stackoverflow.com/users/26294', 'pm_score': 1, 'selected': False, 'text': '<p>I am working on the same bug right now, on our website.</p>\n\n<p>It does appear to be a race condition: I can reproduce it consistently using multiple processes fetching the same page, but never reproduce it if I serialize the requests.</p>\n\n<p>I am using velocity-1.5; I tried migrating to 1.6-beta1 but see other errors.</p>\n\n<p><strong>RESOLVED</strong>: see comments below</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74818', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13121/']
74,821
<p>I recently installed vim-enhanced , but I can't find any article/tutorial related to it.All I could find is a page that briefly describes it's new features , along with several RPM's to download . What exactly does it have to offer to scripting languages that regular vi/vim can't ?</p> <p>Thanks</p>
[{'answer_id': 74857, 'author': 'Lucas Oman', 'author_id': 6726, 'author_profile': 'https://Stackoverflow.com/users/6726', 'pm_score': 3, 'selected': False, 'text': '<p>According to <a href="http://linux.maruhn.com/sec/vim-enhanced.html" rel="noreferrer">this</a>, vim-enhanced is just vim "with the perl, python, tcl, and cscope options compiled in." You should be able to find everything you need to know about these compile options in <a href="http://vimdoc.sourceforge.net/htmldoc/help.html" rel="noreferrer">the documentation</a>.</p>\n'}, {'answer_id': 94775, 'author': 'Zathrus', 'author_id': 16220, 'author_profile': 'https://Stackoverflow.com/users/16220', 'pm_score': 0, 'selected': False, 'text': "<p>If you're new to vim, then run vimtutor</p>\n\n<p>You may also want to start out by reading :help and learning how to use the help system. In particular :help topic (control-D) and :help topic (more useful if you have :set wildmenu) will help you find topics in vim's built-in help (which is notably superior to trying to Google for things). If all else fails there's also :helpgrep topic and then use the quickfix buffer to see the hits (:cn, :cp, :cl, etc).</p>\n\n<p>The #vim channel on Freenode IRC network is also a good place to get help.</p>\n"}]
2008/09/16
['https://Stackoverflow.com/questions/74821', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/11234/']
74,829
<p>What should I type on the Mac OS X terminal to run a script as root?</p>
[{'answer_id': 74830, 'author': 'Bob Wintemberg', 'author_id': 12999, 'author_profile': 'https://Stackoverflow.com/users/12999', 'pm_score': 2, 'selected': False, 'text': '<p>sudo ./<em>scriptname</em></p>\n'}, {'answer_id': 74833, 'author': 'dF.', 'author_id': 3002, 'author_profile': 'https://Stackoverflow.com/users/3002', 'pm_score': 7, 'selected': True, 'text': '<p>As in any unix-based environment, you can use the <a href="http://xkcd.com/149/" rel="noreferrer"><code>sudo</code></a> command:</p>\n\n<pre><code>$ sudo script-name\n</code></pre>\n\n<p>It will ask for your password (your own, not a separate <code>root</code> password).</p>\n'}, {'answer_id': 74846, 'author': 'Dana', 'author_id': 7856, 'author_profile': 'https://Stackoverflow.com/users/7856', 'pm_score': -1, 'selected': False, 'text': "<p>sudo ./scriptname</p>\n\n<p>sudo bash will basically switch you over to running a shell as root, although it's probably best to stay as su as little as possible.</p>\n"}, {'answer_id': 75016, 'author': 'jackrabbit', 'author_id': 3707, 'author_profile': 'https://Stackoverflow.com/users/3707', 'pm_score': 2, 'selected': False, 'text': '<p>In order for sudo to work the way everyone suggest, you need to be in the <code>admin</code> group.</p>\n'}, {'answer_id': 5622489, 'author': 'Rob B', 'author_id': 141325, 'author_profile': 'https://Stackoverflow.com/users/141325', 'pm_score': 4, 'selected': False, 'text': '<p>Or you can access root terminal by typing sudo -s</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74829', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/877/']
74,844
<p>I am not new to *nix, however lately I have been spending a lot of time at the prompt. My question is what are the advantages of using KornShell (ksh) or Bash Shell? Where are the pitfalls of using one over the other? </p> <p>Looking to understand from the perspective of a user, rather than purely scripting.</p>
[{'answer_id': 74868, 'author': 'foxxtrot', 'author_id': 10369, 'author_profile': 'https://Stackoverflow.com/users/10369', 'pm_score': -1, 'selected': False, 'text': "<p>Bash is the benchmark, but that's mostly because you can be reasonably sure it's installed on every *nix out there. If you're planning to distribute the scripts, use Bash.</p>\n\n<p>I can not really address the actual programming differences between the shells, unfortunately.</p>\n"}, {'answer_id': 74872, 'author': 'Allen', 'author_id': 6043, 'author_profile': 'https://Stackoverflow.com/users/6043', 'pm_score': 2, 'selected': False, 'text': '<p>For one thing, bash has tab completion. This alone is enough to make me prefer it over ksh.</p>\n\n<p><a href="http://zsh.org/" rel="nofollow noreferrer">Z shell</a> has a good combination of ksh\'s unique features with the nice things that bash provides, plus a lot more stuff on top of that. </p>\n'}, {'answer_id': 74936, 'author': 'Hank Gay', 'author_id': 4203, 'author_profile': 'https://Stackoverflow.com/users/4203', 'pm_score': 2, 'selected': False, 'text': "<p>@foxxtrot</p>\n\n<p>Actually, the standard shell is Bourne shell (<code>sh</code>). <code>/bin/sh</code> on Linux is actually <code>bash</code>, but if you're aiming for cross-platform scripts, you're better off sticking to features of the original Bourne shell or writing it in something like <code>perl</code>.</p>\n"}, {'answer_id': 74992, 'author': 'Chris AtLee', 'author_id': 4558, 'author_profile': 'https://Stackoverflow.com/users/4558', 'pm_score': 3, 'selected': False, 'text': '<p>I don\'t have experience with ksh, but I have used both bash and zsh. I prefer zsh over bash because of its support for very powerful file globbing, variable expansion modifiers, and faster tab completion.</p>\n\n<p>Here\'s a quick intro: <a href="http://friedcpu.wordpress.com/2007/07/24/zsh-the-last-shell-youll-ever-need/" rel="noreferrer">http://friedcpu.wordpress.com/2007/07/24/zsh-the-last-shell-youll-ever-need/</a></p>\n'}, {'answer_id': 75092, 'author': 'Incident', 'author_id': 11613, 'author_profile': 'https://Stackoverflow.com/users/11613', 'pm_score': 2, 'selected': False, 'text': "<p>My answer would be 'pick one and learn how to use it'. They're both decent shells; bash probably has more bells and whistles, but they both have the basic features you'll want. bash is more universally available these days. If you're using Linux all the time, just stick with it.</p>\n\n<p>If you're programming, trying to stick to plain 'sh' for portability is good practice, but then with bash available so widely these days that bit of advice is probably a bit old-fashioned.</p>\n\n<p>Learn how to use completion and your shell history; read the manpage occasionally and try to learn a few new things.</p>\n"}, {'answer_id': 75114, 'author': 'Kristian', 'author_id': 12911, 'author_profile': 'https://Stackoverflow.com/users/12911', 'pm_score': 3, 'selected': False, 'text': '<p>This is a bit of a Unix vs Linux battle. Most if not all Linux distributions have bash installed and ksh optional. Most Unix systems, like Solaris, AIX and HPUX have ksh as default.</p>\n\n<p>Personally I always use ksh, I love the vi completion and I pretty much use Solaris for everything.</p>\n'}, {'answer_id': 75187, 'author': 'Matthieu', 'author_id': 9310, 'author_profile': 'https://Stackoverflow.com/users/9310', 'pm_score': -1, 'selected': False, 'text': '<p><em>Bash</em> is the standard for Linux.<br>\nMy experience is that it is easier to find help for bash than for ksh or csh.</p>\n'}, {'answer_id': 76773, 'author': 'Jon Ericson', 'author_id': 1438, 'author_profile': 'https://Stackoverflow.com/users/1438', 'pm_score': 3, 'selected': False, 'text': '<p>For scripts, I always use <em>ksh</em> because it smooths over <a href="https://stackoverflow.com/questions/2732/shell-scripting-input-redirection-oddities#12412">gotchas</a>.</p>\n\n<p>But I find <em>bash</em> more comfortable for interactive use. For me the <em>emacs</em> key bindings and tab completion are the main benefits. But that\'s mostly force of habit, not any technical issue with <em>ksh</em>.</p>\n'}, {'answer_id': 76829, 'author': 'j.e.hahn', 'author_id': 13735, 'author_profile': 'https://Stackoverflow.com/users/13735', 'pm_score': 7, 'selected': True, 'text': '<p>Bash. </p>\n\n<p>The various UNIX and Linux implementations have various different source level implementations of ksh, some of which are real ksh, some of which are pdksh implementations and some of which are just symlinks to some other shell that has a "ksh" personality. This can lead to weird differences in execution behavior.</p>\n\n<p>At least with bash you can be sure that it\'s a single code base, and all you need worry about is what (usually minimum) version of bash is installed. Having done a lot of scripting on pretty much every modern (and not-so-modern) UNIX, programming to bash is more reliably consistent in my experience.</p>\n'}, {'answer_id': 5525644, 'author': 'Henk Langeveld', 'author_id': 667820, 'author_profile': 'https://Stackoverflow.com/users/667820', 'pm_score': 5, 'selected': False, 'text': "<p>I'm a korn-shell veteran, so know that I speak from that perspective.</p>\n\n<p>However, I have been comfortable with Bourne shell, ksh88, and ksh93, and for the most I know which features are supported in which. (I should skip ksh88 here, as it's not widely distributed anymore.)</p>\n\n<p>For interactive use, take whatever fits your need. Experiment. I like being able to use the same shell for interactive use and for programming.</p>\n\n<p>I went from ksh88 on SVR2 to tcsh, to ksh88sun (which added significant internationalisation support) and ksh93. I tried bash, and hated it because\nit flattened my history. Then I discovered <code>shopt -s lithist</code> and all was well.\n(The <code>lithist</code> option assures that newlines are preserved in your command\nhistory.)</p>\n\n<p>For shell programming, I'd seriously recommend ksh93 if you want a consistent programming language, good POSIX conformance, and good performance, as many common unix commands can be available as builtin functions. </p>\n\n<p>If you want portability use at least both. And make sure you have a good test suite.</p>\n\n<p>There are many subtle differences between shells. Consider for example reading from a pipe:</p>\n\n<pre><code>b=42 &amp;&amp; echo one two three four |\n read a b junk &amp;&amp; echo $b\n</code></pre>\n\n<p>This will produce different results in different shells. The korn-shell runs pipelines from back to front; the last element in the pipeline runs in the current process. Bash did not support this useful behaviour until v4.x, and even then, it's not the default.</p>\n\n<p>Another example illustrating consistency: The <code>echo</code> command itself, which was made obsolete by the split between BSD and SYSV unix, and each introduced their own convention for not printing newlines (and other behaviour). The result of this can still be seen in many 'configure' scripts.</p>\n\n<p>Ksh took a radical approach to that - and introduced the <code>print</code> command, which actually supports both methods (the <code>-n</code> option from BSD, and the trailing <code>\\c</code> special character from SYSV)</p>\n\n<p>However, for serious systems programming I'd recommend something other than a shell, like python, perl. Or take it a step further, and use a platform like puppet - which allows you to watch and correct the state of whole clusters of systems, with good auditing.</p>\n\n<p>Shell programming is like swimming in uncharted waters, or worse.</p>\n\n<p>Programming in any language requires familiarity with its syntax, its interfaces and behaviour. Shell programming isn't any different.</p>\n\n\n"}, {'answer_id': 6985612, 'author': 'David W.', 'author_id': 368630, 'author_profile': 'https://Stackoverflow.com/users/368630', 'pm_score': 7, 'selected': False, 'text': "<p>The difference between Kornshell and Bash are minimal. There are certain advantages one has over the other, but the differences are tiny:</p>\n\n<ul>\n<li>BASH is much easier to set a prompt that displays the current directory. To do the same in Kornshell is hackish.</li>\n<li>Kornshell has associative arrays and BASH doesn't. Now, the last time I used Associative arrays was... Let me think... Never.</li>\n<li>Kornshell handles loop syntax a bit better. You can usually set a value in a Kornshell loop and have it available after the loop.</li>\n<li>Bash handles getting exit codes from pipes in a cleaner way.</li>\n<li>Kornshell has the <code>print</code> command which is way better than the <code>echo</code> command.</li>\n<li>Bash has tab completions. In older versions</li>\n<li>Kornshell has the <code>r</code> history command that allows me to quickly rerun older commands.</li>\n<li>Kornshell has the syntax <code>cd old new</code> which replaces <code>old</code> with <code>new</code> in your directory and CDs over there. It's convenient when you have are in a directory called <code>/foo/bar/barfoo/one/bar/bar/foo/bar</code> and you need to cd to <code>/foo/bar/barfoo/two/bar/bar/foo/bar</code> In Kornshell, you can simply do <code>cd one two</code> and be done with it. In BASH, you'd have to <code>cd ../../../../../two/bar/bar/foo/bar</code>.</li>\n</ul>\n\n<p>I'm an old Kornshell guy because I learned Unix in the 1990s, and that was the shell of choice back then. I can use Bash, but I get frustrated by it at times because in habit I use some minor feature that Kornshell has that BASH doesn't and it doesn't work. So, whenever possible, I set Kornshell as my default.</p>\n\n<p>However, I am going to tell you to learn BASH. Bash is now implemented on most Unix systems as well as on Linux, and there are simply more resources available for learning BASH and getting help than Kornshell. If you need to do something exotic in BASH, you can go on Stackoverflow, post your question, and you'll get a dozen answers in a few minutes -- and some of them will even be correct!.</p>\n\n<p>If you have a Kornshell question and post it on Stackoverflow, you'll have to wait for some old past their prime hacker like me wake up from his nap before you get an answer. And, forget getting any response if they're serving pudding up in the old age home that day.</p>\n\n<p>BASH is simply the shell of choice now, so if you've got to learn something, might as well go with what is popular.</p>\n"}, {'answer_id': 7279284, 'author': 'MeaCulpa', 'author_id': 846050, 'author_profile': 'https://Stackoverflow.com/users/846050', 'pm_score': 2, 'selected': False, 'text': "<p>Available in most UNIX system, ksh is standard-comliant, clearly designed, well-rounded.\nI think books,helps in ksh is enough and clear, especially the O'Reilly book.\nBash is a mass. I keep it as root login shell for Linux at home only.</p>\n\n<p>For interactive use, I prefer zsh on Linux/UNIX. I run scripts in zsh, but I'll test most of my scripts, functions in AIX ksh though.</p>\n"}]
2008/09/16
['https://Stackoverflow.com/questions/74844', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13158/']
74,847
<p>Typically I use <code>E_ALL</code> to see anything that PHP might say about my code to try and improve it.</p> <p>I just noticed a error constant <code>E_STRICT</code>, but have never used or heard about it, is this a good setting to use for development? The manual says:</p> <blockquote> <p>Run-time notices. Enable to have PHP suggest changes to your code which will ensure the best interoperability and forward compatibility of your code. </p> </blockquote> <p>So I'm wondering if I'm using the best <code>error_reporting</code> level with <code>E_ALL</code> or would that along with <code>E_STRICT</code> be the best? Or is there any other combination I've yet to learn?</p>
[{'answer_id': 74864, 'author': 'Tim Boland', 'author_id': 70, 'author_profile': 'https://Stackoverflow.com/users/70', 'pm_score': -1, 'selected': False, 'text': '<p>ini_set("display_errors","2");\nERROR_REPORTING(E_ALL);</p>\n'}, {'answer_id': 74907, 'author': 'Daniel Papasian', 'author_id': 7548, 'author_profile': 'https://Stackoverflow.com/users/7548', 'pm_score': 3, 'selected': False, 'text': '<p>In my opinion, the higher you set the error reporting level in development phase, the better. </p>\n\n<p>In a live environment, you want a slightly (but only slightly) reduced set, but you want them logged somewhere that they can\'t be seen by the user (I prefer <code>syslog</code>).</p>\n\n<p><a href="http://php.net/error_reporting" rel="nofollow noreferrer">http://php.net/error_reporting</a></p>\n\n<p><code>E_ALL | E_STRICT</code> for development with PHP before 5.2.0.</p>\n\n<p>5.2 introduces <code>E_RECOVERABLE_ERROR</code> and 5.3 introduces <code>E_DEPRECATED</code> and <code>E_USER_DEPRECATED</code>. You\'ll probably want to turn those on if you\'re running one of those versions.</p>\n\n<p>If you wanted to use magic numbers you could just set the <code>error_reporting</code> value to some fairly high value of <code>2^n-1</code> - say, <code>16777215</code>, and that would really just turn on all the bits between <code>1..n</code>. But I don\'t think using magic numbers is a good idea...</p>\n\n<p>In my opinion, PHP has dropped the ball a bit by having <code>E_ALL</code> not really be all. But apparently it\'s going to be fixed in PHP 6...</p>\n'}, {'answer_id': 74923, 'author': 'Jim', 'author_id': 8427, 'author_profile': 'https://Stackoverflow.com/users/8427', 'pm_score': 6, 'selected': True, 'text': '<p>In PHP 5, the things covered by <code>E_STRICT</code> are not covered by <code>E_ALL</code>, so to get the most information, you need to combine them:</p>\n\n<pre><code> error_reporting(E_ALL | E_STRICT);\n</code></pre>\n\n<p>In PHP 5.4, <code>E_STRICT</code> will be included in <code>E_ALL</code>, so you can use just <code>E_ALL</code>.</p>\n\n<p>You can also use</p>\n\n<pre><code>error_reporting(-1);\n</code></pre>\n\n<p>which will always enable <em>all</em> errors. Which is more semantically correct as:</p>\n\n<pre><code>error_reporting(~0);\n</code></pre>\n'}, {'answer_id': 74924, 'author': 'Jan Krüger', 'author_id': 12471, 'author_profile': 'https://Stackoverflow.com/users/12471', 'pm_score': 2, 'selected': False, 'text': '<p>In newer PHP versions, E_ALL includes more classes of errors. Since PHP 5.3, E_ALL includes everything <em>except</em> E_STRICT. In PHP 6 it will alledgedly include even that. This is a good hint: it\'s better to see more error messages rather than less.</p>\n\n<p>What\'s included in E_ALL is documented in the <a href="http://uk.php.net/manual/en/errorfunc.constants.php" rel="nofollow noreferrer">PHP predefined constants</a> page in the online manual.</p>\n\n<p>Personally, I think it doesn\'t matter all that much if you use E_STRICT. It certainly won\'t hurt you, especially since it may prevent you from writing scripts that have a small chance of getting broken in future versions of PHP. On the other hand, in some cases strict messages may be too noisy, perhaps especially if you\'re in a hurry. I suggest that you turn it on by default and turn it off when it gets annoying.</p>\n'}, {'answer_id': 74963, 'author': 'stormlash', 'author_id': 12657, 'author_profile': 'https://Stackoverflow.com/users/12657', 'pm_score': 1, 'selected': False, 'text': '<p>Depending on your long term support plans for this code, debugging with <code>E_STRICT</code> enabled may help your code to continue working in the distant future, but it is probably overkill for day-to-day use. There are two important things about <code>E_STRICT</code> to keep in mind:</p>\n\n<ol>\n<li><a href="http://us3.php.net/error_reporting" rel="nofollow noreferrer">Per the manual</a>, most <code>E_STRICT</code> errors are generated at compile time, not runtime. If you are increasing the error level to <code>E_ALL</code> within your code (and not via <em>php.ini</em>), you may never see <code>E_STRICT</code> errors anyway.</li>\n<li><code>E_STRICT</code> is contained within <code>E_ALL</code> under PHP 6, but not under PHP 5. If you upgrade your server to PHP6, and have <code>E_ALL</code> configured as described in #1 above, you will begin to see <code>E_STRICT</code> errors without requiring any additional changes on your part.</li>\n</ol>\n'}, {'answer_id': 75368, 'author': 'Pablo Borowicz', 'author_id': 13275, 'author_profile': 'https://Stackoverflow.com/users/13275', 'pm_score': 0, 'selected': False, 'text': '<p>Not strictly speaking of error_reporting, I\'d <strong>strongly</strong> suggest using any IDE that automatically shows parsing errors and common glitches (eg, assignment in condition).</p>\n\n<p>Zend Studio for Eclipse has this feature enabled by default, and since I started using it, it has been helping me <strong>a lot</strong> at catching errors before they occur.</p>\n\n<p>For example, I had this piece of code where I was caching some data in the <code>$GLOBALS</code> variable, but I inadvertently wrote <code>$_GLOBALS</code> instead. The data never got cached up, and I\'d never knew if Zend didn\'t tell me: "Hey, this <code>$_GLOBALS</code> thingy appears only once, that might be an error".</p>\n'}, {'answer_id': 75392, 'author': 'Eduardo Marinho', 'author_id': 13211, 'author_profile': 'https://Stackoverflow.com/users/13211', 'pm_score': 3, 'selected': False, 'text': '<p>Use the following in php.ini:</p>\n\n<pre><code>error_reporting = E_ALL | E_STRICT\n</code></pre>\n\n<p>Also you should install <a href="http://xdebug.org" rel="nofollow noreferrer" title="Xdebug">Xdebug</a>, it can highlight your errors in blinding bright colors and print useful detailed information. </p>\n\n<p>Never let any error or notice in your code, even if it\'s harmless.</p>\n'}, {'answer_id': 7227429, 'author': 'RiaD', 'author_id': 768110, 'author_profile': 'https://Stackoverflow.com/users/768110', 'pm_score': 2, 'selected': False, 'text': '<p>You may use <code>error_reporting = -1</code><br>\nIt will always consist of all bits (even if they are not in E_ALL)</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74847', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5261/']
74,865
<p>I recently was working with a subversion project that checked out code not only from the repository I was working with, but also from a separate repository on a different server.</p> <p>How can I configure my repository to do this?</p> <p>I'm using the subversion client version 1.3.2 on Linux, and I also have access to TortoiseSVN version 1.4.8 (built on svn version 1.4.6) in Windows.</p>
[{'answer_id': 74878, 'author': 'Hank Gay', 'author_id': 4203, 'author_profile': 'https://Stackoverflow.com/users/4203', 'pm_score': 5, 'selected': True, 'text': '<p>See <a href="http://svnbook.red-bean.com/en/1.0/ch07s03.html" rel="nofollow noreferrer">svn:externals</a>:</p>\n\n<blockquote>\n <p>Sometimes it is useful to construct a working copy that is made out of a number of different checkouts. For example, you may want different subdirectories to come from different locations in a repository, or perhaps from different repositories altogether. You could certainly setup such a scenario by hand—using <code>svn checkout</code> to create the sort of nested working copy structure you are trying to achieve. But if this layout is important for everyone who uses your repository, every other user will need to perform the same checkout operations that you did.</p>\n \n <p>Fortunately, Subversion provides support for <em>externals definitions</em>. An externals definition is a mapping of a local directory to the URL—and possibly a particular revision—of a versioned resource. In Subversion, you declare externals definitions in groups using the <code>svn:externals</code> property. You can create or modify this property using <code>svn propset</code> or <code>svn propedit</code> (see <a href="http://svnbook.red-bean.com/en/1.0/ch07s02.html#svn-ch-7-sect-2.1" rel="nofollow noreferrer">the section called “Why Properties?”</a>). It can be set on any versioned directory, and its value is a multi-line table of subdirectories (relative to the versioned directory on which the property is set) and fully qualified, absolute Subversion repository URLs...</p>\n</blockquote>\n'}, {'answer_id': 74887, 'author': 'Isak Savo', 'author_id': 8521, 'author_profile': 'https://Stackoverflow.com/users/8521', 'pm_score': 2, 'selected': False, 'text': '<p>I think you should take a look at the <a href="http://svnbook.red-bean.com/en/1.0/ch07s03.html" rel="nofollow noreferrer">svn:externals</a> property</p>\n'}, {'answer_id': 74890, 'author': 'Doug Moore', 'author_id': 13179, 'author_profile': 'https://Stackoverflow.com/users/13179', 'pm_score': 2, 'selected': False, 'text': '<p>Try svn:externals</p>\n\n<p><a href="http://svnbook.red-bean.com/en/1.0/ch07s03.html" rel="nofollow noreferrer">http://svnbook.red-bean.com/en/1.0/ch07s03.html</a></p>\n'}, {'answer_id': 74896, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>Search for the svn:externals property in the <a href="http://svnbook.red-bean.com/en/1.0/ch07s03.html" rel="nofollow noreferrer">documentation</a>.</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74865', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/7154/']
74,879
<p>I am looking for a tool which will take an XML instance document and output a corresponding XSD schema.</p> <p>I certainly recognize that the generated XSD schema will be limited when compared to creating a schema by hand (it probably won't handle optional or repeating elements, or data constraints), but it could at least serve as a quick starting point.</p>
[{'answer_id': 74939, 'author': 'Danimal', 'author_id': 2757, 'author_profile': 'https://Stackoverflow.com/users/2757', 'pm_score': 7, 'selected': True, 'text': '<p>the <a href="https://msdn.microsoft.com/en-us/library/x6c1kb0s(v=vs.110).aspx" rel="noreferrer">Microsoft XSD inference tool</a> is a good, free solution. Many XML editing tools, such as XmlSpy (mentioned by @Garth Gilmour) or OxygenXML Editor also have that feature. They\'re rather expensive, though. BizTalk Server also has an XSD inferring tool as well.<br/></p>\n\n<p>edit: I just discovered the .net <a href="http://msdn.microsoft.com/en-us/library/system.xml.schema.xmlschemainference.aspx" rel="noreferrer">XmlSchemaInference</a> class, so if you\'re using .net you should consider that</p>\n'}, {'answer_id': 74943, 'author': 'Garth Gilmour', 'author_id': 2635682, 'author_profile': 'https://Stackoverflow.com/users/2635682', 'pm_score': 2, 'selected': False, 'text': '<p>Altova XmlSpy does this well - you can find an overview <a href="http://www.altova.com/products/xmlspy/dtd_editor.html" rel="nofollow noreferrer">here</a></p>\n'}, {'answer_id': 80570, 'author': 'Robert Gould', 'author_id': 15124, 'author_profile': 'https://Stackoverflow.com/users/15124', 'pm_score': 3, 'selected': False, 'text': '<p>If all you want is XSD, LiquidXML has a free version that does XSDs, and its got a GUI to it so you can tweak the XSD if you like. Anyways nowadays I write my own XSDs by hand, but its all thanks to this app.</p>\n\n<p><a href="http://www.liquid-technologies.com/" rel="noreferrer">http://www.liquid-technologies.com/</a></p>\n'}, {'answer_id': 88683, 'author': 'Pat Hermens', 'author_id': 1677, 'author_profile': 'https://Stackoverflow.com/users/1677', 'pm_score': 4, 'selected': False, 'text': "<p>If you have .Net installed, a tool to generate XSD schemas and classes is already included by default.<br />\nFor me, the XSD tool is installed under the following structure. This may differ depending on your installation directory.</p>\n\n<pre><code>C:\\Program Files\\Microsoft Visual Studio 8\\VC&gt;xsd\nMicrosoft (R) Xml Schemas/DataTypes support utility\n[Microsoft (R) .NET Framework, Version 2.0.50727.42]\nCopyright (C) Microsoft Corporation. All rights reserved.\n\nxsd.exe -\n Utility to generate schema or class files from given source.\n\nxsd.exe &lt;schema&gt;.xsd /classes|dataset [/e:] [/l:] [/n:] [/o:] [/s] [/uri:]\nxsd.exe &lt;assembly&gt;.dll|.exe [/outputdir:] [/type: [...]]\nxsd.exe &lt;instance&gt;.xml [/outputdir:]\nxsd.exe &lt;schema&gt;.xdr [/outputdir:]\n</code></pre>\n\n<p>Normally the classes and schemas that this tool generates work rather well, especially if you're going to be consuming them in a .Net language</p>\n\n<p>I typically take the XML document that I'm after, push it through the XSD tool with the <code>/o:&lt;your path&gt;</code> flag to generate a schema (xsd) and then push the xsd file back through the tool using the <code>/classes /L:VB (or CS) /o:&lt;your path&gt;</code> flags to get classes that I can import and use in my day to day .Net projects</p>\n"}, {'answer_id': 88695, 'author': 'Andreas Petersson', 'author_id': 16542, 'author_profile': 'https://Stackoverflow.com/users/16542', 'pm_score': 3, 'selected': False, 'text': '<p>if you are working in the java world - <em>intelliJ idea</em> has also extensive xml support, including xsd generation and samle xml from xsd generation, and with plugins you can get xslt debuggers. - especially nice if you plan to use tools such as jaxb afterwards.</p>\n'}, {'answer_id': 184070, 'author': 'Dario', 'author_id': 11583, 'author_profile': 'https://Stackoverflow.com/users/11583', 'pm_score': 6, 'selected': False, 'text': '<p>You can use an open source and cross-platform option: inst2xsd from <a href="http://xmlbeans.apache.org/" rel="noreferrer">Apache\'s XMLBeans</a>. I find it very useful and easy.</p>\n\n<p>Just download, unzip and play (it requires Java).</p>\n'}, {'answer_id': 1236639, 'author': 'Derferman', 'author_id': 129012, 'author_profile': 'https://Stackoverflow.com/users/129012', 'pm_score': 6, 'selected': False, 'text': '<p><a href="http://www.thaiopensource.com/relaxng/trang.html" rel="noreferrer">Trang</a> is the best option here. Open source and cross platform (although Java is required)</p>\n<p>From the Trang Website:</p>\n<blockquote>\n<p>Trang converts between different schema languages for XML. It supports the following languages</p>\n<ul>\n<li>RELAX NG (XML syntax)</li>\n<li>RELAX NG compact syntax</li>\n<li>XML 1.0 DTDs</li>\n<li>W3C XML Schema</li>\n</ul>\n<p>A schema written in any of the supported schema languages can be converted into any of the other supported schema languages, except that W3C XML Schema is supported for output only, not for input.</p>\n<p><strong>Trang can also infer a schema from one or more example XML documents.</strong></p>\n</blockquote>\n<p><a href="https://github.com/relaxng/jing-trang" rel="noreferrer">Download Link</a></p>\n'}, {'answer_id': 8397984, 'author': 'edorian', 'author_id': 285578, 'author_profile': 'https://Stackoverflow.com/users/285578', 'pm_score': 4, 'selected': False, 'text': '<p>There also is <a href="http://kore-nordmann.de/blog/0104_generating_xml_schemas_from_xml.html" rel="noreferrer"><strong><code>XML schema learner</code></strong></a> which is available on <a href="https://github.com/kore/XML-Schema-learner" rel="noreferrer">Github</a>.</p>\n\n<p>It can take <strong>multiple xml files</strong> and <strong>extract a common XSD from all of those files</strong>.</p>\n'}, {'answer_id': 11190143, 'author': 'Nathan Donnellan', 'author_id': 997216, 'author_profile': 'https://Stackoverflow.com/users/997216', 'pm_score': 4, 'selected': False, 'text': '<p>In VS2010 if you load an XML file into the editor, click the XML menu >> Create Schema.</p>\n'}, {'answer_id': 18034165, 'author': 'v_e', 'author_id': 1935216, 'author_profile': 'https://Stackoverflow.com/users/1935216', 'pm_score': 2, 'selected': False, 'text': '<p>This is an old thread but I thought it could be useful to post this link: just found this tool:\n<a href="https://github.com/wiztools/xsd-gen" rel="nofollow">xsd-gen Generate XML Schema from XML</a></p>\n\n<p>and it just did what I needed.</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74879', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/863/']
74,880
<p>Conceptually, I would like to accomplish the following but have had trouble understand how to code it properly in C#:</p> <pre><code> SomeMethod { // Member of AClass{} DoSomething; Start WorkerMethod() from BClass in another thread; DoSomethingElse; } </code></pre> <p>Then, when WorkerMethod() is complete, run this:</p> <p><pre><code> void SomeOtherMethod() // Also member of AClass{} { ... } </pre></code></p> <p>Can anyone please give an example of that? </p>
[{'answer_id': 74917, 'author': 'MagicKat', 'author_id': 8505, 'author_profile': 'https://Stackoverflow.com/users/8505', 'pm_score': 1, 'selected': False, 'text': '<p>Check out BackgroundWorker.</p>\n'}, {'answer_id': 74948, 'author': 'Isak Savo', 'author_id': 8521, 'author_profile': 'https://Stackoverflow.com/users/8521', 'pm_score': 5, 'selected': True, 'text': '<p>The <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx" rel="noreferrer">BackgroundWorker</a> class was added to .NET 2.0 for this exact purpose.</p>\n\n<p>In a nutshell you do:</p>\n\n<pre><code>BackgroundWorker worker = new BackgroundWorker();\nworker.DoWork += delegate { myBClass.DoHardWork(); }\nworker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(SomeOtherMethod);\nworker.RunWorkerAsync();\n</code></pre>\n\n<p>You can also add fancy stuff like cancellation and progress reporting if you want :)</p>\n'}, {'answer_id': 75050, 'author': 'Randolpho', 'author_id': 12716, 'author_profile': 'https://Stackoverflow.com/users/12716', 'pm_score': 0, 'selected': False, 'text': "<p>Ok, I'm unsure of how you want to go about this. From your example, it looks like WorkerMethod does not create its own thread to execute under, but you want to call that method on another thread. </p>\n\n<p>In that case, create a short worker method that calls WorkerMethod then calls SomeOtherMethod, and queue that method up on another thread. Then when WorkerMethod completes, SomeOtherMethod is called. For example:</p>\n\n<pre><code>public class AClass\n{\n public void SomeMethod()\n {\n DoSomething();\n\n ThreadPool.QueueUserWorkItem(delegate(object state)\n {\n BClass.WorkerMethod();\n SomeOtherMethod();\n });\n\n DoSomethingElse();\n }\n\n private void SomeOtherMethod()\n {\n // handle the fact that WorkerMethod has completed. \n // Note that this is called on the Worker Thread, not\n // the main thread.\n }\n}\n</code></pre>\n"}, {'answer_id': 75164, 'author': 'Vivek', 'author_id': 7418, 'author_profile': 'https://Stackoverflow.com/users/7418', 'pm_score': 1, 'selected': False, 'text': '<p>Use Async Delegates:</p>\n\n<pre><code>// Method that does the real work\npublic int SomeMethod(int someInput)\n{\nThread.Sleep(20);\nConsole.WriteLine(”Processed input : {0}”,someInput);\nreturn someInput+1;\n} \n\n\n// Method that will be called after work is complete\npublic void EndSomeOtherMethod(IAsyncResult result)\n{\nSomeMethodDelegate myDelegate = result.AsyncState as SomeMethodDelegate;\n// obtain the result\nint resultVal = myDelegate.EndInvoke(result);\nConsole.WriteLine(”Returned output : {0}”,resultVal);\n}\n\n// Define a delegate\ndelegate int SomeMethodDelegate(int someInput);\nSomeMethodDelegate someMethodDelegate = SomeMethod;\n\n// Call the method that does the real work\n// Give the method name that must be called once the work is completed.\nsomeMethodDelegate.BeginInvoke(10, // Input parameter to SomeMethod()\nEndSomeOtherMethod, // Callback Method\nsomeMethodDelegate); // AsyncState\n</code></pre>\n'}, {'answer_id': 75513, 'author': 'ashwnacharya', 'author_id': 1909, 'author_profile': 'https://Stackoverflow.com/users/1909', 'pm_score': 2, 'selected': False, 'text': '<p>You have to use AsyncCallBacks. You can use AsyncCallBacks to specify a delegate to a method, and then specify CallBack Methods that get called once the execution of the target method completes.</p>\n\n<p>Here is a small Example, run and see it for yourself.</p>\n\n<p>class Program\n {</p>\n\n<pre><code> public delegate void AsyncMethodCaller();\n\n\n public static void WorkerMethod()\n {\n Console.WriteLine("I am the first method that is called.");\n Thread.Sleep(5000);\n Console.WriteLine("Exiting from WorkerMethod.");\n }\n\n public static void SomeOtherMethod(IAsyncResult result)\n {\n Console.WriteLine("I am called after the Worker Method completes.");\n }\n\n\n\n static void Main(string[] args)\n {\n AsyncMethodCaller asyncCaller = new AsyncMethodCaller(WorkerMethod);\n AsyncCallback callBack = new AsyncCallback(SomeOtherMethod);\n IAsyncResult result = asyncCaller.BeginInvoke(callBack, null);\n Console.WriteLine("Worker method has been called.");\n Console.WriteLine("Waiting for all invocations to complete.");\n Console.Read();\n\n }\n}\n</code></pre>\n'}, {'answer_id': 75743, 'author': 'Keith', 'author_id': 905, 'author_profile': 'https://Stackoverflow.com/users/905', 'pm_score': 3, 'selected': False, 'text': "<p>In .Net 2 the BackgroundWorker was introduced, this makes running async operations really easy:</p>\n\n<pre><code>BackgroundWorker bw = new BackgroundWorker { WorkerReportsProgress = true };\n\nbw.DoWork += (sender, e) =&gt; \n {\n //what happens here must not touch the form\n //as it's in a different thread\n };\n\nbw.ProgressChanged += ( sender, e ) =&gt;\n {\n //update progress bars here\n };\n\nbw.RunWorkerCompleted += (sender, e) =&gt; \n {\n //now you're back in the UI thread you can update the form\n //remember to dispose of bw now\n };\n\nworker.RunWorkerAsync();\n</code></pre>\n\n<p>In .Net 1 you have to use threads.</p>\n"}, {'answer_id': 77113, 'author': 'Romain Verdier', 'author_id': 4687, 'author_profile': 'https://Stackoverflow.com/users/4687', 'pm_score': 2, 'selected': False, 'text': '<p>Although there are several possibilities here, I would use a delegate, asynchronously called using <code>BeginInvoke</code> method.</p>\n\n<p><strong>Warning</strong> : don\'t forget to always call <code>EndInvoke</code> on the <code>IAsyncResult</code> to avoid eventual memory leaks, as described in <a href="http://www.ondotnet.com/pub/a/dotnet/2003/02/24/asyncdelegates.html?page=2" rel="nofollow noreferrer">this article</a>.</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74880', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/10505/']
74,883
<p>I cannot seem to compile mod_dontdothat on Windows. Has anybody managed to achieve this?</p> <p>Edit:</p> <p>I've tried compiling the file according to the readme on the site and I've tried to add extra libs to reduce the link errors. Ive got the following installed:</p> <ol> <li>Apache 2.2.9</li> <li>Visual Studio 2008</li> <li>ActivePerl</li> <li>apxs-win32 from ApacheLounge</li> <li>Subversion libs and headers</li> </ol> <p>I run the following command line:</p> <pre> C:\Program Files\Apache Software Foundation\Apache2.2\bin>apxs -c -I ..\include\ svn_config.h -L ..\lib -L C:\Progra~1\Micros~1.0\VC\lib -l apr-1.lib -l aprutil- 1.lib -l svn_subr-1.lib -l libapr-1.lib -l libaprutil-1.lib -l libhttpd.lib -l l ibsvn_subr-1.lib -l mod_dav.lib mod_dontdothat.c </pre> <p>Then I get the following errors:</p> <pre> cl /nologo /MD /W3 /O2 /D WIN32 /D _WINDOWS /D NDEBUG -I"C:\PROGRA~1\APACHE~ 1\Apache2.2\include" /I"..\include\svn_config.h" /c /Fomod_dontdothat.lo mod_d ontdothat.c mod_dontdothat.c link kernel32.lib /nologo /subsystem:windows /dll /machine:I386 /libpath:"C:\PRO GRA~1\APACHE~1\Apache2.2\lib" /out:mod_dontdothat.so /libpath:"..\lib" /libpat h:"C:\Progra~1\Micros~1.0\VC\lib" apr-1.lib aprutil-1.lib svn_subr-1.lib libapr -1.lib libaprutil-1.lib libhttpd.lib libsvn_subr-1.lib mod_dav.lib mod_dontdot hat.lo Creating library mod_dontdothat.lib and object mod_dontdothat.exp mod_dontdothat.lo : error LNK2019: unresolved external symbol _dav_svn_split_uri @32 referenced in function _is_this_legal svn_subr-1.lib(io.obj) : error LNK2001: unresolved external symbol __imp__libint l_dgettext svn_subr-1.lib(subst.obj) : error LNK2001: unresolved external symbol __imp__lib intl_dgettext svn_subr-1.lib(config_auth.obj) : error LNK2001: unresolved external symbol __im p__libintl_dgettext svn_subr-1.lib(time.obj) : error LNK2001: unresolved external symbol __imp__libi ntl_dgettext svn_subr-1.lib(nls.obj) : error LNK2001: unresolved external symbol __imp__libin tl_dgettext svn_subr-1.lib(dso.obj) : error LNK2001: unresolved external symbol __imp__libin tl_dgettext svn_subr-1.lib(path.obj) : error LNK2001: unresolved external symbol __imp__libi ntl_dgettext svn_subr-1.lib(prompt.obj) : error LNK2001: unresolved external symbol __imp__li bintl_dgettext svn_subr-1.lib(error.obj) : error LNK2019: unresolved external symbol __imp__lib intl_dgettext referenced in function _print_error svn_subr-1.lib(config.obj) : error LNK2001: unresolved external symbol __imp__li bintl_dgettext svn_subr-1.lib(utf.obj) : error LNK2001: unresolved external symbol __imp__libin tl_dgettext svn_subr-1.lib(cmdline.obj) : error LNK2001: unresolved external symbol __imp__l ibintl_dgettext svn_subr-1.lib(utf.obj) : error LNK2019: unresolved external symbol __imp__libin tl_sprintf referenced in function _fuzzy_escape svn_subr-1.lib(path.obj) : error LNK2001: unresolved external symbol __imp__libi ntl_sprintf svn_subr-1.lib(cmdline.obj) : error LNK2019: unresolved external symbol __imp__l ibintl_fprintf referenced in function _svn_cmdline_init svn_subr-1.lib(config_win.obj) : error LNK2019: unresolved external symbol __imp __SHGetFolderPathA@20 referenced in function _svn_config__win_config_path svn_subr-1.lib(config_win.obj) : error LNK2019: unresolved external symbol __imp __SHGetFolderPathW@20 referenced in function _svn_config__win_config_path svn_subr-1.lib(config_win.obj) : error LNK2019: unresolved external symbol __imp __RegCloseKey@4 referenced in function _svn_config__parse_registry svn_subr-1.lib(config_win.obj) : error LNK2019: unresolved external symbol __imp __RegEnumKeyExA@32 referenced in function _svn_config__parse_registry svn_subr-1.lib(config_win.obj) : error LNK2019: unresolved external symbol __imp __RegOpenKeyExA@20 referenced in function _svn_config__parse_registry svn_subr-1.lib(config_win.obj) : error LNK2019: unresolved external symbol __imp __RegQueryValueExA@24 referenced in function _parse_section svn_subr-1.lib(config_win.obj) : error LNK2019: unresolved external symbol __imp __RegEnumValueA@32 referenced in function _parse_section svn_subr-1.lib(win32_xlate.obj) : error LNK2019: unresolved external symbol __im p__CoUninitialize@0 referenced in function _svn_subr__win32_xlate_open svn_subr-1.lib(win32_xlate.obj) : error LNK2019: unresolved external symbol __im p__CoInitializeEx@8 referenced in function _svn_subr__win32_xlate_open svn_subr-1.lib(win32_xlate.obj) : error LNK2019: unresolved external symbol __im p__CoCreateInstance@20 referenced in function _get_page_id_from_name svn_subr-1.lib(nls.obj) : error LNK2019: unresolved external symbol __imp__libin tl_bindtextdomain referenced in function _svn_nls_init svn_subr-1.lib(stream.obj) : error LNK2019: unresolved external symbol _inflate referenced in function _read_handler_gz svn_subr-1.lib(stream.obj) : error LNK2019: unresolved external symbol _inflateI nit_ referenced in function _read_handler_gz svn_subr-1.lib(stream.obj) : error LNK2019: unresolved external symbol _deflate referenced in function _write_handler_gz svn_subr-1.lib(stream.obj) : error LNK2019: unresolved external symbol _deflateI nit_ referenced in function _write_handler_gz svn_subr-1.lib(stream.obj) : error LNK2019: unresolved external symbol _deflateE nd referenced in function _close_handler_gz svn_subr-1.lib(stream.obj) : error LNK2019: unresolved external symbol _inflateE nd referenced in function _close_handler_gz mod_dontdothat.so : fatal error LNK1120: 21 unresolved externals apxs:Error: Command failed with rc=6291456 . </pre> <p>I'm not too much of a C guru, so any help in finding these unresolved external symbols will be much appreciated!</p>
[{'answer_id': 77964, 'author': 'Jason Dagit', 'author_id': 5113, 'author_profile': 'https://Stackoverflow.com/users/5113', 'pm_score': 1, 'selected': False, 'text': "<p>Thanks for revising the question.</p>\n\n<p>It looks like a definite linker issue. I see that the first undefined symbol is related to webdav. Are you sure you have that library in the right place? I see you give a nice long path with lots of svn libs, maybe it's possible you overlooked just one?</p>\n"}, {'answer_id': 482896, 'author': 'agnul', 'author_id': 6069, 'author_profile': 'https://Stackoverflow.com/users/6069', 'pm_score': 2, 'selected': False, 'text': "<p>Googling around I've got </p>\n\n<ul>\n<li><code>mod_dav_svn.lib</code> for <code>_dav_svn_split_uri</code></li>\n<li><code>intl3_svn.lib</code> for all things <code>_libintl</code></li>\n<li><code>shell32.lib</code> for SHGetFolderPath</li>\n<li><code>advapi32.lib</code> for <code>Reg</code>istry stuff</li>\n<li><code>ole32.lib</code> for <code>CoInitialize</code> and it's ilk</li>\n<li><code>inflate</code> and <code>deflate</code> smell like <code>zlib1.lib</code> or something like that</li>\n</ul>\n\n<p>Hope that helps.</p>\n"}, {'answer_id': 499837, 'author': 'Eduard Wirch', 'author_id': 17428, 'author_profile': 'https://Stackoverflow.com/users/17428', 'pm_score': 4, 'selected': True, 'text': '<p>I managed to compile the module. Prerequisites:</p>\n\n<ul>\n<li>Apache 2.2.11</li>\n<li><a href="http://www.apachelounge.com/download/apxs_win32.zip" rel="noreferrer">apxs-win32</a> from www.apachelounge.com</li>\n<li>Visual Studio 2005</li>\n<li><a href="http://www.activestate.com/activeperl/" rel="noreferrer">Active Perl 5.8.8</a> (you need perl for apxs-win32 installation)</li>\n</ul>\n\n<p>Here is a step-by-step guide.\nDownload these packages:</p>\n\n<ul>\n<li><a href="http://subversion.tigris.org/files/documents/15/44595/svn-win32-1.5.5_dev.zip" rel="noreferrer">http://subversion.tigris.org/files/documents/15/44595/svn-win32-1.5.5_dev.zip</a> (we need the libraries and header files from this package)</li>\n<li><a href="http://subversion.tigris.org/downloads/subversion-1.5.5.zip" rel="noreferrer">http://subversion.tigris.org/downloads/subversion-1.5.5.zip</a> (we will be using the <code>mod_dav_svn</code> sources to compile a static lib)</li>\n</ul>\n\n<p>Unpack the dev package to <code>c:\\temp\\svn</code> and the other package to <code>c:\\temp\\svn-src</code> and the <code>mod_dontdothat</code> files to <code>C:\\Temp\\dontdothat</code>.</p>\n\n<p>One of the dependencies of <code>mod_dontdothat</code> module is <code>mod_dav_svn</code> module. Unfortunately you\'ll find the <code>mod_dav_svn</code> binary only as a shared library (DLL). You cannot link against\na DLL. So the first step is to build a static <code>mod_dav_svn</code> library:</p>\n\n<pre><code>cd C:\\Temp\\svn-src\\subversion\\mod_dav_svn\napxs -c -I ..\\include -L C:\\Temp\\svn\\lib -l libsvn_delta-1.lib -l libsvn_diff-1.lib -l libsvn_fs-1.lib -l libsvn_fs_base-1.lib -l libsvn_fs_fs-1.lib -l libsvn_fs_util-1.lib -l libsvn_repos-1.lib -l libsvn_subr-1.lib -l libapr-1.lib -l libaprutil-1.lib -l libhttpd.lib -l mod_dav.lib -l xml.lib -n mod_dav_svn mod_dav_svn.c activity.c authz.c deadprops.c liveprops.c lock.c merge.c mirror.c repos.c util.c version.c reports\\dated-rev.c reports\\file-revs.c reports\\get-locations.c reports\\get-location-segments.c reports\\get-locks.c reports\\log.c reports\\mergeinfo.c reports\\replay.c reports\\update.c\n</code></pre>\n\n<p>The apxs call will print the commands it executes. The last command is a link call which builds the DLL. Copy it replace "link" by "lib", remove the "/dll" param, and change the "out" param file name to "<code>libmod_dav_svn.lib</code>". You should get something similar to: </p>\n\n<pre><code>lib kernel32.lib /nologo /subsystem:windows /machine:I386 /libpath:"C:\\PROGRA~1\\APACHE~1\\Apache2.2\\lib" /out:libmod_dav_svn.lib /libpath:"C:\\Temp\\svn\\lib" libsvn_delta-1.lib libsvn_diff-1.lib libsvn_fs-1.lib libsvn_fs_base-1.lib libsvn_fs_fs-1.lib libsvn_fs_util-1.lib libsvn_repos-1.lib libsvn_subr-1.lib libapr-1.lib libaprutil-1.lib libhttpd.lib mod_dav.lib xml.lib reports\\update.lo reports\\replay.lo reports\\mergeinfo.lo reports\\log.lo reports\\get-locks.lo reports\\get-location-segments.lo reports\\get-locations.lo reports\\file-revs.lo reports\\dated-rev.lo version.lo util.lo repos.lo mirror.lo merge.lo lock.lo liveprops.lo deadprops.lo authz.lo activity.lo mod_dav_svn.lo\n</code></pre>\n\n<p>You will get some link warnings. You can ignore them. Copy the <code>libmod_dav_svn.lib</code> to the <code>mod_dontdothat</code> directory. Now start the compilation process for <code>mod_dontdothat</code>:</p>\n\n<pre><code>C:\\Temp\\dontdothat\napxs -c -I C:\\Temp\\svn\\include -L C:\\Temp\\svn\\lib -l libsvn_subr-1.lib -l libapr-1.lib -l libaprutil-1.lib -l libhttpd.lib -l mod_dav.lib -l xml.lib -l libmod_dav_svn.lib mod_dontdothat.c\napxs -i -n dontdothat mod_dontdothat.so\n</code></pre>\n\n<p>This should do the trick.</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74883', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2822/']
74,886
<p>I need to rearrange some content in various directories but it's a bit of a pain. In order to debug the application I'm working on (a ruby app) I need to move my gems into my gem folder one at a time (long story; nutshell: one is broken and I can't figure out which one).</p> <p>So I need to do something like:</p> <pre><code>sudo mv backup/gem/foo gem/ sudo mv backup/doc/foo doc/ sudo mv backup/specification/foo.gemspec specification/ </code></pre> <p>replacing "foo" each time. How can I author a simple shell script to let me do something like: gemMove("foo") and it fill in the blanks for me?</p>
[{'answer_id': 74920, 'author': 'pjz', 'author_id': 8002, 'author_profile': 'https://Stackoverflow.com/users/8002', 'pm_score': 4, 'selected': True, 'text': '<p>Put the following into a file named <code>gemmove</code>:</p>\n<pre><code>#!/bin/bash\n\nif [ &quot;x$1&quot; == x ]; then\n echo &quot;Must have an arg&quot;\n exit 1\nfi\n\nfor d in gem doc specification ; do \n mv &quot;backup/$d/$1&quot; &quot;$d&quot;\ndone\n</code></pre>\n<p>then do</p>\n<pre><code>chmod a+x gemmove\n</code></pre>\n<p>and then call <code>sudo /path/to/gemmove foo</code> to move the foo gem from the backup dirs into the real ones</p>\n'}, {'answer_id': 74937, 'author': 'sirprize', 'author_id': 12902, 'author_profile': 'https://Stackoverflow.com/users/12902', 'pm_score': 1, 'selected': False, 'text': '<p>You could simply use the bash shell arguments, like this:</p>\n\n<pre><code>#!/bin/bash\n# This is move.sh\nmv backup/gem/$1 gem/\nmv backup/doc/$1 doc/\n# ...\n</code></pre>\n\n<p>and then execute it as:</p>\n\n<pre><code>sudo ./move.sh foo\n</code></pre>\n\n<p>Be sure make the script executable, with</p>\n\n<pre><code>chmod +x move.sh\n</code></pre>\n'}, {'answer_id': 74995, 'author': 'catfood', 'author_id': 12802, 'author_profile': 'https://Stackoverflow.com/users/12802', 'pm_score': 1, 'selected': False, 'text': '<p>in bash, something like:</p>\n\n<pre><code>function gemMove()\n{\nfilename=$1\n mv backup/gem/$filename gem/$filename\n mv backup/doc/$filename doc/$filename\n mv backup/specification/$filename.spec specification\n}\n</code></pre>\n\n<p>then you can just call <code>gemMove("foo")</code> elsewhere in the script.</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74886', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/10071/']
74,892
<p>The JPEG compression encoding process splits a given image into blocks of 8x8 pixels, working with these blocks in future lossy and lossless compressions. <a href="http://en.wikipedia.org/wiki/Jpeg#JPEG_codec_example" rel="noreferrer">[source]</a></p> <p>It is also mentioned that if the image is a multiple 1MCU block (defined as a Minimum Coded Unit, 'usually 16 pixels in both directions') that lossless alterations to a JPEG can be performed. <a href="http://en.wikipedia.org/wiki/Jpeg#Lossless_editing" rel="noreferrer">[source]</a></p> <p>I am working with product images and would like to know both if, and how much benefit can be derived from using multiples of 16 in my final image size (say, using an image with size 480px by 360px) vs. a non-multiple of 16 (such as 484x362). In this example I am not interested in further alterations, editing, or recompression of the final image.</p> <p>To try to get closer to a specific answer where I know there must be largely generalities: Given a 480x360 image that is 64k and saved at maximum quality in Photoshop <a href="http://enstxzrnsprxt.6hops.net/Random_Bill_Blass_Pen_and_Pencil_Set___2_PacklewStandard.jpg" rel="noreferrer">[example]</a>:</p> <ul> <li>Can I expect any quality loss from an image that is 484x362</li> <li>What amount of file size addition can I expect (for this example, the additional space would be white pixels)</li> <li>Are there any other disadvantages to growing larger than the 8px grid?</li> </ul> <p>I know it's arbitrary to use that specific example, but it would still be helpful (for me and potentially any others pondering an image size) to understand what level of compromise I'd be dealing with in breaking the non-8px grid.</p> <p>The key issue here is a debate I've had is whether 8-pixel divisible images are higher quality than images that are not divisible by 8-pixels.</p>
[{'answer_id': 75103, 'author': 'Dark Shikari', 'author_id': 11206, 'author_profile': 'https://Stackoverflow.com/users/11206', 'pm_score': 6, 'selected': True, 'text': "<p>8 pixels is the cutoff. The reason is because JPEG images are simply an array of 8x8 DCT blocks; if the image resolution isn't mod8 in both directions, the encoder has to pad the sides up to the next mod8 resolution. This in practice is not very expensive bit-wise; what's much worse are the cases when an image has sharp black lines (such as a letterboxed image) that don't lie on block boundaries. This is especially problematic in video encoding. The reason for this being a problem is that the frequency transform of a sharp line is a Gaussian distribution of coefficients--resulting in an enormous number of bits to code.</p>\n\n<p>For those curious, the most common method of padding edges in intra compression (such as JPEG images) is to mirror the lines of pixels before the edge. For example, if you need to pad three lines and line X is the edge, line X+1 is equal to line X, line X+2 is equal to line X-1, and line X+3 is equal to line X-2. This quite effectively minimizes the cost in transform coefficients of the extra lines.</p>\n\n<p>In inter coding, however, the padding algorithms generally simply duplicate the last line, because the mirror method does not work well for inter compression, such as in video compression.</p>\n"}, {'answer_id': 75106, 'author': 'Mike Ivanov', 'author_id': 5126, 'author_profile': 'https://Stackoverflow.com/users/5126', 'pm_score': 2, 'selected': False, 'text': '<p>The image dimensions being multiples of 8 or 16 is not going to affect the size on disk very much, but you can get dramatic savings if you can line up the visual contents to the 8x8 pixel grid, such as if there is a repeating pattern or texture in the image.</p>\n'}, {'answer_id': 84213, 'author': 'Tometzky', 'author_id': 15862, 'author_profile': 'https://Stackoverflow.com/users/15862', 'pm_score': 2, 'selected': False, 'text': '<p>A JPG with sizes being multiplies of 8 can also be rotated/flipped with no quality loss. For example gthumb can do this on Linux.</p>\n'}, {'answer_id': 117126, 'author': 'Mark Ransom', 'author_id': 5987, 'author_profile': 'https://Stackoverflow.com/users/5987', 'pm_score': 1, 'selected': False, 'text': '<p>What <a href="https://stackoverflow.com/questions/74892/is-there-a-quality-file-size-or-other-benefit-to-jpeg-sizes-being-multiples-of#84213">Tometzky</a> said. If you don\'t have the correct multiple, the lossless flip and rotate algorithms don\'t work. That\'s because the padding on the right/bottom that can be safely ignored now ends up on the left/top, where it can\'t.</p>\n'}, {'answer_id': 117170, 'author': 'Mark Ransom', 'author_id': 5987, 'author_profile': 'https://Stackoverflow.com/users/5987', 'pm_score': 2, 'selected': False, 'text': "<p>Sometimes you need to use 16 pixel boundaries rather than 8 because of subsampling; every 2nd pixel is thrown away during the encoding process, and those 8x8 DCT blocks started out as 16x16 and will decode back to 16x16. This won't be a problem at the highest quality settings.</p>\n"}]
2008/09/16
['https://Stackoverflow.com/questions/74892', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2486915/']
74,902
<p>I installed Mono on my iMac last night and I immidiately had a change of heart! I don't think Mono is ready for prime time. </p> <p>The Mono website says to run the following script to uninstall:</p> <pre><code>#!/bin/sh -x #This script removes Mono from an OS X System. It must be run as root rm -r /Library/Frameworks/Mono.framework rm -r /Library/Receipts/MonoFramework-SVN.pkg cd /usr/bin for i in `ls -al | grep Mono | awk '{print $9}'`; do rm ${i} done </code></pre> <p>Has anyone had to uninstall Mono? Was it as straight forward as running the above script or do I have to do more? How messy was it? Any pointers are appreciated.</p>
[{'answer_id': 74919, 'author': 'Alex Fort', 'author_id': 12624, 'author_profile': 'https://Stackoverflow.com/users/12624', 'pm_score': 0, 'selected': False, 'text': "<p>Mono doesn't contain a lot of fluff, so just running those commands will be fine. It's as simple as deleting all the data folders, and the binaries.</p>\n"}, {'answer_id': 74934, 'author': 'Adrian Petrescu', 'author_id': 12171, 'author_profile': 'https://Stackoverflow.com/users/12171', 'pm_score': 5, 'selected': True, 'text': '<p>The above script simply deletes everything related to Mono on your system -- and since the developers wrote it, I\'m sure they didn\'t miss anything :) Unlike some other operating systems made by software companies that rhyme with "Macrosoft", uninstalling software in OS X is as simple as deleting the files, 99% of the time.. no registry or anything like that.</p>\n\n<p>So, long story short, yes, that script is probably the only thing you need to do.</p>\n'}, {'answer_id': 768240, 'author': 'joev', 'author_id': 3449, 'author_profile': 'https://Stackoverflow.com/users/3449', 'pm_score': 2, 'selected': False, 'text': '<p>To expand on feelingsofwhite.com\'s answer, the Mono installer for Mac OS puts the uninstall script in the /Library/Receipts directory, not in the installer image as it says in the Notes.rtf file. The Receipts directory is what the Mac OS Installer.app uses to keep track of which packages were responsible for installing which files. Usually, a list of these is kept in a .bom ("Bill of Materials") file, which can be explored with the lsbom command.</p>\n\n<p>In the case of Mono, they also add a whole bunch of links from your /usr/bin and man directories. Their uninstall scripts finds these and removes them. Since the uninstall script lives in a place the uninstaller deletes, you should probably copy the uninstall script somewhere else before running it:</p>\n\n<pre><code>cd\ncp /Library/Receipts/MonoFramework-2.4_7.macos10.novell.universal.pkg/Contents/Resources/uninstallMono.sh .\nsudo ./uninstallMono.sh\nrm uninstallMono.sh\n</code></pre>\n'}, {'answer_id': 4471531, 'author': 'Theseven7', 'author_id': 505479, 'author_profile': 'https://Stackoverflow.com/users/505479', 'pm_score': 0, 'selected': False, 'text': '<p><a href="http://dragthor.wordpress.com/2007/07/24/uninstall-mono-on-mac-os-x/" rel="nofollow">http://dragthor.wordpress.com/2007/07/24/uninstall-mono-on-mac-os-x/</a>\nWork for me, OSX, But I Use the uninstall script file (.sh) from the Mono Installer Package.</p>\n'}, {'answer_id': 6657711, 'author': 'Albireo', 'author_id': 91696, 'author_profile': 'https://Stackoverflow.com/users/91696', 'pm_score': 3, 'selected': False, 'text': '<p>Seems the uninstall script has been slightly modified as today (2011-07-12):</p>\n\n<pre><code>#!/bin/sh -x\n\n#This script removes Mono from an OS X System. It must be run as root\n\nrm -r /Library/Frameworks/Mono.framework\n\nrm -r /Library/Receipts/MonoFramework-*\n\nfor dir in /usr/bin /usr/share/man/man1 /usr/share/man/man3 /usr/share/man/man5; do\n (cd ${dir};\n for i in `ls -al | grep /Library/Frameworks/Mono.framework/ | awk \'{print $9}\'`; do\n rm ${i}\n done);\ndone\n</code></pre>\n\n<p>You can find the current version <a href="http://www.mono-project.com/Mono:OSX#Uninstalling_Mono_on_Mac_OS_X" rel="nofollow noreferrer">here</a>.</p>\n\n<p>By the way: it\'s the same exact thing that runs the uninstaller <a href="https://stackoverflow.com/questions/74902/uninstall-mono-from-mac-os-x-v10-5-leopard/768240#768240">mentioned by joev</a> (although as <a href="https://stackoverflow.com/questions/74902/uninstall-mono-from-mac-os-x-v10-5-leopard/768240#comment-6661580">jochem noted</a> it is <em>not</em> located in the <code>/Library/Receipts</code>, it must be found in the installation package=.</p>\n'}, {'answer_id': 11478972, 'author': 'Oldfrith', 'author_id': 1524730, 'author_profile': 'https://Stackoverflow.com/users/1524730', 'pm_score': -1, 'selected': False, 'text': '<p>I just deleted the mono.frameworks folder. I got tired of answering "yes" billions of times...</p>\n'}, {'answer_id': 46015929, 'author': 'montrealist', 'author_id': 65232, 'author_profile': 'https://Stackoverflow.com/users/65232', 'pm_score': 3, 'selected': False, 'text': '<p>Year 2017 answer for those, like myself, looking at SE first and <a href="http://www.mono-project.com/docs/about-mono/supported-platforms/osx/#uninstalling-mono-on-mac-os-x" rel="noreferrer">official docs</a> later (FYI I know the question was for OS Leopard). Run these commands in the terminal:</p>\n\n<pre><code>sudo rm -rf /Library/Frameworks/Mono.framework\nsudo pkgutil --forget com.xamarin.mono-MDK.pkg\nsudo rm -rf /etc/paths.d/mono-commands\n</code></pre>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74902', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/877/']
74,928
<p>I'm trying to figure out the best way to parse a GE Logician MEL trace file to make it easier to read.</p> <p>It has segments like </p> <pre>>{!gDYNAMIC_3205_1215032915_810 = (clYN)} execute>GDYNAMIC_3205_1215032915_810 = "Yes, No" results>"Yes, No" execute>end results>"Yes, No" >{!gDYNAMIC_3205_1215032893_294 = (clYN)} execute>GDYNAMIC_3205_1215032893_294 = "Yes, No" results>"Yes, No" execute>end results>"Yes, No" </pre> <p>and</p> <pre>>{IF (STR(F3205_1220646638_285, F3205_1220646638_301) == "") THEN "" ELSE (\par\tab fnHeadingFormat("Depression") + CFMT(F3205_1220646638_285, "", "Have you often been bothered by feeling down, depressed or hopeless? ", "B", "\par ") + CFMT(F3205_1220646638_301, "", "Have you often been bothered by little interest or pleasure in doing things? ", "B", "\par ") ) ENDIF} execute>call STR("No", "No") results>"NoNo" execute>"NoNo" == "" results>FALSE execute>if FALSE results>FALSE execute>call FNHEADINGFORMAT("Depression") execute>call CFMT("Depression", "B,2") results>"\fs24\b Depression\b0\fs20 " execute>"\r\n" + "\fs24\b Depression\b0\fs20 " results>"\r\n\fs24\b Depression\b0\fs20 " execute>"\r\n\fs24\b Depression\b0\fs20 " + "\r\n" results>"\r\n\fs24\b Depression\b0\fs20 \r\n" results>return "\r\n\fs24\b Depression\b0\fs20 \r\n" execute>call CFMT("No", "", "Have you often been bothered by feeling down, depressed or hopeless? ", "B", "\par ") results>"\b Have you often been bothered by feeling down, depressed or hopeless? \b0 No\par " execute>"\r\n\fs24\b Depression\b0\fs20 \r\n" + "\b Have you often been bothered by feeling down, depressed or hopeless? \b0 No\par " results>"\r\n\fs24\b Depression\b0\fs20 \r\n\b Have you often been bothered by feeling down, depressed or hopeless? \b0 No\par " execute>call CFMT("No", "", "Have you often been bothered by little interest or pleasure in doing things? ", "B", "\par ") results>"\b Have you often been bothered by little interest or pleasure in doing things? \b0 No\par " execute>"\r\n\fs24\b Depression\b0\fs20 \r\n\b Have you often been bothered by feeling down, depressed or hopeless? \b0 No\par " + "\b Have you often been bothered by little interest or pleasure in doing things? \b0 No\par " results>"\r\n\fs24\b Depression\b0\fs20 \r\n\b Have you often been bothered by feeling down, depressed or hopeless? \b0 No\par \b Have you often been bothered by little interest or pleasure in doing things? \b0 No\par " </pre> <p>I could grovel through doing it procedurally, but after all the regexps I've worked with, I find it hard to believe there's nothing out there that will let me define the rules for parsing the file in a similar manner. Am I wrong?</p>
[{'answer_id': 74942, 'author': 'metadave', 'author_id': 7237, 'author_profile': 'https://Stackoverflow.com/users/7237', 'pm_score': 2, 'selected': False, 'text': '<p><a href="http://www.antlr.org" rel="nofollow noreferrer">Antlr</a> would do the trick.</p>\n'}, {'answer_id': 74944, 'author': 'INS', 'author_id': 13136, 'author_profile': 'https://Stackoverflow.com/users/13136', 'pm_score': 1, 'selected': False, 'text': '<p>You could try ANTLR or lex/yacc.</p>\n'}, {'answer_id': 74964, 'author': 'Daniel Spiewak', 'author_id': 9815, 'author_profile': 'https://Stackoverflow.com/users/9815', 'pm_score': 1, 'selected': False, 'text': "<p>If it were me, I would derive a context-free grammar and plug it into a parser generator, probably Scala's combinator library. However, this grammar looks reasonably easy to parse by hand, just bear in mind the automata theory and it shouldn't be a problem.</p>\n"}, {'answer_id': 74970, 'author': 'nimish', 'author_id': 3926, 'author_profile': 'https://Stackoverflow.com/users/3926', 'pm_score': 3, 'selected': True, 'text': "<p>Make a grammar using ANTLR. If you're using C, lex/yacc are native. ANTLR creates native parsers in Java, Python and .NET. Your output looks like a repl; try asking the vendor for a spec on the input language.</p>\n"}, {'answer_id': 74971, 'author': 'Mostlyharmless', 'author_id': 12881, 'author_profile': 'https://Stackoverflow.com/users/12881', 'pm_score': 1, 'selected': False, 'text': '<p>I would imagine you could use tools like LEX, FLEX, CUP, ANTLR or YACC (or their equivalents for whatever programming language you are using. Any mainstream programming language has some flavor of these available.) to parse the files if they have a specific structure [more accurately, if they could be represented by a grammar]. These might not work for finer points though.</p>\n'}, {'answer_id': 75018, 'author': 'chessguy', 'author_id': 1908025, 'author_profile': 'https://Stackoverflow.com/users/1908025', 'pm_score': 1, 'selected': False, 'text': '<p>There\'s a programming language called Haskell that has a great parsing library you might try. www.haskell.org and <a href="http://legacy.cs.uu.nl/daan/parsec.html" rel="nofollow noreferrer">http://legacy.cs.uu.nl/daan/parsec.html</a> for more details</p>\n'}, {'answer_id': 91500, 'author': 'tsee', 'author_id': 13164, 'author_profile': 'https://Stackoverflow.com/users/13164', 'pm_score': 2, 'selected': False, 'text': '<p>In case you\'re using Perl for parsing. The Perl equivalent of YACC would be <a href="http://search.cpan.org/dist/Parse-Yapp" rel="nofollow noreferrer">the Parse::Yapp</a> module. When I translated a yacc grammar for use with my Perl code, the translation was mostly mechanic. There\'s also a recursive descent parser generator, which is slow but powerful: <a href="http://search.cpan.org/dist/Parse-RecDescent" rel="nofollow noreferrer">Parse::RecDescent</a>.</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74928', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2531/']
74,947
<p>What is the best way to maniupulate richtext / *.rtf data in SQL server 2005 / 2008 I have looked at ocx solutions. Maybe creating some CLR stored procs??</p> <p>The problem is that I have several notes written in richtext that need to be combined for ease of reporting. Like SELECT @Notes = @Notes + RTFColumn FROM Notestable WHERE ...</p>
[{'answer_id': 74975, 'author': 'WIDBA', 'author_id': 10868, 'author_profile': 'https://Stackoverflow.com/users/10868', 'pm_score': 1, 'selected': False, 'text': '<p>I think you are probably better off creating a simple application to read the two files, merge the data and save if that is where you are heading. Its sounds like you are expecting the database to do something outside of its store/retrieve job functions...</p>\n'}, {'answer_id': 164465, 'author': 'Josef', 'author_id': 5581, 'author_profile': 'https://Stackoverflow.com/users/5581', 'pm_score': 1, 'selected': True, 'text': "<p>CLR would be the equivalent of writing a program and might not work as efficiently.</p>\n\n<p>The database isn't really designed to do what you are asking of it and, a CLR sproc that handled it would be blocking, on many levels. So you would be better off writing a program that manually processed through the rows to do what you want it to do.</p>\n"}]
2008/09/16
['https://Stackoverflow.com/questions/74947', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13219/']
74,951
<p>Flex has built in drag-n-drop for list controls, and allows you to override this. But they don't cover this in examples. The built-in functionality automatically drags the list-item, if you want to override this you find the handlers are being set up on the list itself. What I specifically want to do, is my TileList shows small thumbnails of items I can drag onto a large Canvas. As I drag an item from the list, the drag proxy should be a different image.</p> <p><strong>So, I followed the technique suggested and it only works if I explicitly set the width/height on the proxy Image. Why?</strong></p>
[{'answer_id': 75541, 'author': 'Theo', 'author_id': 1109, 'author_profile': 'https://Stackoverflow.com/users/1109', 'pm_score': 2, 'selected': False, 'text': '<p>It\'s not obvious until you\'ve tried it =) I struggled with the same thing just a few weeks ago. This was my solution:</p>\n\n<p>The list:</p>\n\n<pre><code>&lt;List&gt;\n &lt;mouseDown&gt;onListMouseDown(event)&lt;/mouseDown&gt;\n&lt;/Tree&gt;\n</code></pre>\n\n<p>The mouse down handler:</p>\n\n<pre><code>private function onMouseDown( event : MouseEvent ) : void {\n var list : List = List(event.currentTarget);\n\n // the data of the clicked row, change the name of the class to your own\n var item : MyDataType = MyDataType(list.selectedItem);\n\n var source : DragSource = new DragSource();\n\n // MyAwsomeDragFormat is the key that you will retrieve the data by in the\n // component that handles the drop\n source.addData(item, "MyAwsomeDragFormat");\n\n // this is the component that will be shown as the drag proxy image\n var dragView : UIComponent = new Image();\n\n // set the source of the image to a bigger version here\n dragView.source = getABiggerImage(item);\n\n // get hold of the renderer of the clicked row, to use as the drag initiator\n var rowRenderer : UIComponent = UIComponent(list.indexToItemRenderer(list.selectedIndex));\n\n DragManager.doDrag(\n rowRenderer,\n source,\n event,\n dragView\n );\n}\n</code></pre>\n\n<p>That will start the drag when the user clicks an item in the list. Notice that I don\'t set <code>dragEnabled</code> and the other drag-related properties on the list since I handle all that myself.</p>\n\n<p>It can be useful to add this to the beginning of the event handler:</p>\n\n<pre><code>if ( event.target is ScrollThumb || event.target is Button ) {\n return;\n}\n</code></pre>\n\n<p>Just to short circuit if the user clicks somewhere in the scrollbar. It\'s not very elegant but it does the job.</p>\n'}, {'answer_id': 2185111, 'author': 'Ola', 'author_id': 264449, 'author_profile': 'https://Stackoverflow.com/users/264449', 'pm_score': 1, 'selected': False, 'text': '<p>I found a simpler answer <a href="http://www.dgrigg.com/post.cfm/11/03/2006/DataGrid-Drag-Image" rel="nofollow noreferrer">here</a>. That example extends a DataGrid control, but you can do the same with a List control. In my case, I use an image source instead of Class:</p>\n\n<pre><code>public class CustomDragList extends List {\n\n [Bindable]\n public var dragProxyImageSource:Object;\n\n override protected function get dragImage():IUIComponent {\n var image:Image = new Image();\n image.width = 50;\n image.height = 50;\n image.source = dragProxyImageSource;\n image.owner = this;\n return image;\n }\n}\n</code></pre>\n\n<p>Then use that custom list like this:</p>\n\n<pre><code>&lt;control:CustomDragList\n allowMultipleSelection="true"\n dragEnabled="true" \n dragProxyImageSource="{someImageSource}"\n dragStart="onDragStart(event)"/&gt;\n</code></pre>\n\n<p>Where \'someImageSource\' can be anything you\'d normally use for an image source (embedded, linked, etc.)</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74951', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13220/']
74,957
<p>In PowerShell I'm reading in a text file. I'm then doing a Foreach-Object over the text file and am only interested in the lines that do NOT contain strings that are in <code>$arrayOfStringsNotInterestedIn</code>.</p> <p>What is the syntax for this?</p> <pre><code> Get-Content $filename | Foreach-Object {$_} </code></pre>
[{'answer_id': 75034, 'author': 'Mark Schill', 'author_id': 9482, 'author_profile': 'https://Stackoverflow.com/users/9482', 'pm_score': 4, 'selected': False, 'text': "<p>You can use the -notmatch operator to get the lines that don't have the characters you are interested in. </p>\n\n<pre><code> Get-Content $FileName | foreach-object { \n if ($_ -notmatch $arrayofStringsNotInterestedIn) { $) }\n</code></pre>\n"}, {'answer_id': 75091, 'author': 'Chris Bilson', 'author_id': 12934, 'author_profile': 'https://Stackoverflow.com/users/12934', 'pm_score': 7, 'selected': True, 'text': '<p>If $arrayofStringsNotInterestedIn is an [array] you should use -notcontains:</p>\n\n<pre><code>Get-Content $FileName | foreach-object { `\n if ($arrayofStringsNotInterestedIn -notcontains $_) { $) }\n</code></pre>\n\n<p>or better (IMO)</p>\n\n<pre><code>Get-Content $FileName | where { $arrayofStringsNotInterestedIn -notcontains $_}\n</code></pre>\n'}, {'answer_id': 143727, 'author': 'Bruno Gomes', 'author_id': 8669, 'author_profile': 'https://Stackoverflow.com/users/8669', 'pm_score': 2, 'selected': False, 'text': "<p>To exclude the lines that contain any of the strings in $arrayOfStringsNotInterestedIn, you should use:</p>\n\n<pre><code>(Get-Content $FileName) -notmatch [String]::Join('|',$arrayofStringsNotInterestedIn)\n</code></pre>\n\n<p>The code proposed by Chris only works if $arrayofStringsNotInterestedIn contains the full lines you want to exclude.</p>\n"}]
2008/09/16
['https://Stackoverflow.com/questions/74957', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1463/']
74,960
<p>I'm looking at the SOAP output from a web service I'm developing, and I noticed something curious:</p> <pre><code>&lt;soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"&gt; &lt;soapenv:Body&gt; &lt;ns1:CreateEntityTypesResponse xmlns:ns1="http://somedomain.com/wsinterface"&gt; &lt;newKeys&gt; &lt;value&gt;1234&lt;/value&gt; &lt;/newKeys&gt; &lt;newKeys&gt; &lt;value&gt;2345&lt;/value&gt; &lt;/newKeys&gt; &lt;newKeys&gt; &lt;value&gt;3456&lt;/value&gt; &lt;/newKeys&gt; &lt;newKeys xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/&gt; &lt;newKeys xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/&gt; &lt;errors&gt;Error1&lt;/errors&gt; &lt;errors&gt;Error2&lt;/errors&gt; &lt;/ns1:CreateEntityTypesResponse&gt; &lt;/soapenv:Body&gt; &lt;/soapenv:Envelope&gt; </code></pre> <p>I have two newKeys elements that are nil, and both elements insert a namespace reference for xsi. I'd like to include that namespace in the soapenv:Envelope element so that the namespace reference is only sent once.</p> <p>I am using WSDL2Java to generate the service skeleton, so I don't directly have access to the Axis2 API.</p>
[{'answer_id': 75128, 'author': 'Michael Sharek', 'author_id': 1958, 'author_profile': 'https://Stackoverflow.com/users/1958', 'pm_score': 3, 'selected': False, 'text': '<h3>Using WSDL2Java</h3>\n\n<p>If you have used the Axis2 WSDL2Java tool you\'re kind of stuck with what it generates for you. However you can try to change the skeleton in this section:</p>\n\n<pre><code> // create SOAP envelope with that payload\n org.apache.axiom.soap.SOAPEnvelope env = null;\n env = toEnvelope(\n getFactory(_operationClient.getOptions().getSoapVersionURI()),\n methodName,\n optimizeContent(new javax.xml.namespace.QName\n ("http://tempuri.org/","methodName")));\n\n//adding SOAP soap_headers\n_serviceClient.addHeadersToEnvelope(env);\n</code></pre>\n\n<p>To add the namespace to the envelope add these lines somewhere in there:</p>\n\n<pre><code>OMNamespace xsi = getFactory(_operationClient.getOptions().getSoapVersionURI()).\n createOMNamespace("http://www.w3.org/2001/XMLSchema-instance", "xsi");\n\nenv.declareNamespace(xsi);\n</code></pre>\n\n<h3>Hand-coded</h3>\n\n<p>If you are "hand-coding" the service you might do something like this:</p>\n\n<pre><code>SOAPFactory fac = OMAbstractFactory.getSOAP11Factory(); \nSOAPEnvelope envelope = fac.getDefaultEnvelope();\nOMNamespace xsi = fac.createOMNamespace("http://www.w3.org/2001/XMLSchema-instance", "xsi");\n\nenvelope.declareNamespace(xsi);\nOMNamespace methodNs = fac.createOMNamespace("http://somedomain.com/wsinterface", "ns1");\n\nOMElement method = fac.createOMElement("CreateEntityTypesResponse", methodNs);\n\n//add the newkeys and errors as OMElements here...\n</code></pre>\n\n<h3>Exposing service in aar</h3>\n\n<p>If you are creating a service inside an aar you may be able to influence the SOAP message produced by using the target namespace or schema namespace properties (see <a href="http://wso2.org/library/2060" rel="noreferrer">this article</a>).</p>\n\n<p>Hope that helps.</p>\n'}, {'answer_id': 11162724, 'author': 'dodoconr', 'author_id': 726202, 'author_profile': 'https://Stackoverflow.com/users/726202', 'pm_score': 1, 'selected': False, 'text': '<p>Other option is that the variable MY_QNAME has the prefix empty.</p>\n\n<pre><code>public static final QName MY_QNAME = new QName("http://www.hello.com/Service/",\n "tagname",\n "prefix");\n</code></pre>\n\n<p>So, if you fill it, then it works.</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74960', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13224/']
74,986
<p>I'm developing a .NET 3.5 XBAP application that runs perfectly fine in FF3 and IE6/7 etc. I'm just wondering if its possible to get these to run under other browsers, specifically (as its in the limelight at the moment) Google Chrome.</p>
[{'answer_id': 75038, 'author': 'Bob Wintemberg', 'author_id': 12999, 'author_profile': 'https://Stackoverflow.com/users/12999', 'pm_score': 2, 'selected': False, 'text': '<p>At the moment, XBAPs do not work in Google Chrome. I\'ve gotten it to run once, somehow, but every time there after I\'ve received an error that the browser cannot locate xpcom.dll. Apparently this error occurs for more than just XBAP applications. From what I\'ve read users will have to wait for a fix seeing as Chrome is still in beta.</p>\n\n<p><strong>Update:</strong></p>\n\n<p>Looks like it\'s not going to be fixed: <a href="http://code.google.com/p/chromium/issues/detail?id=4051" rel="nofollow noreferrer">http://code.google.com/p/chromium/issues/detail?id=4051</a></p>\n'}, {'answer_id': 588987, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 5, 'selected': True, 'text': '<p>XBAP applications do work in google chrome, however you have to set your environments PATH variable to the directory where xpcom.dll is located.</p>\n\n<p>for example SET PATH=PATH;"C:\\Program Files\\Mozilla Firefox"</p>\n'}, {'answer_id': 5210368, 'author': 'Michael Maddox', 'author_id': 12712, 'author_profile': 'https://Stackoverflow.com/users/12712', 'pm_score': 2, 'selected': False, 'text': '<p>Here is another alternative solution that still requires Firefox to be installed, but you copy DLLs instead of modifying the PATH:</p>\n\n<p><a href="http://adrianbega.blogspot.com/2009/04/execute-xbap-in-google-chrome.html" rel="nofollow">http://adrianbega.blogspot.com/2009/04/execute-xbap-in-google-chrome.html</a></p>\n'}, {'answer_id': 7306745, 'author': 'Noora', 'author_id': 928674, 'author_profile': 'https://Stackoverflow.com/users/928674', 'pm_score': 2, 'selected': False, 'text': '<p>First thing required here is to make the .Net framework 3.5 installed, once its done check whether the application is working in Mozilla Firefox, because it uses the plugin of Mozilla, if there is some issue in Mozilla, execute the <code>aspnet_regiis.exe -iru</code> from Visual Studio command prompt with administrative priviledge, then set Path variable to <code>C:\\Program Files\\Mozilla Firefox</code> and add the following DLLs to the location <code>C:\\Users\\[Username]\\AppData\\Local\\Google\\Chrome\\Application</code></p>\n\n<ul>\n<li>mozalloc.dll</li>\n<li>mozcpp19.dll</li>\n<li>mozcrt19.dll</li>\n<li>mozjs.dll</li>\n<li>mozsqlite3.dll</li>\n<li>nspr4.dll</li>\n<li>nss3.dll</li>\n<li>nssutil3.dll</li>\n<li>plc4.dll</li>\n<li>plds4.dll</li>\n<li>smime3.dll</li>\n<li>ssl3.dll</li>\n<li>test.txt</li>\n<li>xpcom.dll</li>\n<li>xul.dll</li>\n</ul>\n\n<p>and restart the browser, and check the application, if it still shows the plugin crashed, try re-installing the framework first and then Mozilla, also for Windows 7, mozilla requires to put the NPWPF.dll to the location <code>C:\\Program Files (x86)\\Mozilla Firefox\\plugins</code>.</p>\n\n<p>After this whole lot of hell, the application may still not debug, then publish the XBAP application and check with file and keep your finger crossed as it may work this time, this is how I made my application work in my system and checked for 5 more systems, so hope it resolve your problem too.</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/74986', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5777/']
74,993
<p>When running any kind of server under load there are several resources that one would like to monitor to make sure that the server is healthy. This is specifically true when testing the system under load.</p> <p>Some examples for this would be CPU utilization, memory usage, and perhaps disk space. What other resource should I be monitoring, and what tools are available to do so?</p>
[{'answer_id': 75020, 'author': 'GEOCHET', 'author_id': 5640, 'author_profile': 'https://Stackoverflow.com/users/5640', 'pm_score': -1, 'selected': False, 'text': '<p>I typically watch <code>top</code> and <code>tail -f /var/log/auth.log</code>.</p>\n'}, {'answer_id': 75024, 'author': 'Daniel Papasian', 'author_id': 7548, 'author_profile': 'https://Stackoverflow.com/users/7548', 'pm_score': 4, 'selected': True, 'text': "<p>As many as you can afford to, and can then graph/understand/look at the results. Monitoring resources is useful for not only capacity planning, but anomaly detection, and anomaly detection significantly helps your ability to detect security events.</p>\n\n<p>You have a decent start with your basic graphs. I'd want to also monitor the number of threads, number of connections, network I/O, disk I/O, page faults (arguably this is related to memory usage), context switches.</p>\n\n<p>I really like munin for graphing things related to hosts.</p>\n"}, {'answer_id': 75036, 'author': 'cori', 'author_id': 8151, 'author_profile': 'https://Stackoverflow.com/users/8151', 'pm_score': 0, 'selected': False, 'text': "<p>In addition to top and auth.log, I often look at mtop, and enable mysql's slowquerylog and watch mysqldumpslow.</p>\n\n<p>I also use Nagios to monitor CPU, Memory, and logged in users (on a VPS or dedicated server). That last lets me know when someone other than me has logged in.</p>\n"}, {'answer_id': 75054, 'author': 'tante', 'author_id': 2065014, 'author_profile': 'https://Stackoverflow.com/users/2065014', 'pm_score': 1, 'selected': False, 'text': '<p>"df -h" to make sure that no partition runs full which can lead to all kinds of funky problems, watching the syslog is of course also useful, for that I recommend installing "logwatch" (<a href="http://www.logwatch.org/" rel="nofollow noreferrer" title="Logwatch">Logwatch Website</a>) on your server which sends you an email if weird things start showing up in your syslog.</p>\n'}, {'answer_id': 75776, 'author': 'pjz', 'author_id': 8002, 'author_profile': 'https://Stackoverflow.com/users/8002', 'pm_score': 1, 'selected': False, 'text': '<p><a href="http://www.cacti.net/" rel="nofollow noreferrer">Cacti</a> is a good web-based monitoring/graphing solution. Very complete, very easy to use, with a large userbase including many large Enterprise-level installations.</p>\n\n<p>If you want more \'alerting\' and less \'graphing\', check out <a href="http://www.nagios.org/" rel="nofollow noreferrer">nagios</a>.</p>\n\n<p>As for \'what to monitor\', you want to monitor systems at both the system and application level, so yes: network/memory/disk i/o, interrupts and such over the system level. The application level gets more specific, so a webserver might measure hits/second, errors/second (non-200 responses), etc and a database might measure queries/second, average query fulfillment time, etc.</p>\n'}, {'answer_id': 77183, 'author': 'gbjbaanb', 'author_id': 13744, 'author_profile': 'https://Stackoverflow.com/users/13744', 'pm_score': 0, 'selected': False, 'text': '<p>network of course :) Use MRTG to get some nice bandwidth graphs, they\'re just pretty most of the time.. until a spammer finds a hole in your security and it suddenly increases.</p>\n\n<p>Nagios is good for alerting as mentioned, and is easy to get setup. You can then use the mrtg plugin to get alerts for your network traffic too.</p>\n\n<p>I also recommend ntop as it shows where your network traffic is going.</p>\n\n<p>A good link to get you going with Munin and Monit: <a href="http://www.howtoforge.com/server_monitoring_monit_munin" rel="nofollow noreferrer">link text</a></p>\n'}, {'answer_id': 82856, 'author': 'Jon Topper', 'author_id': 6945, 'author_profile': 'https://Stackoverflow.com/users/6945', 'pm_score': 2, 'selected': False, 'text': "<p>I use Zabbix extensively in production, which comes with a stack of useful defaults. Some examples of the sorts of things we've configured it to monitor:</p>\n\n<ul>\n<li>Network usage</li>\n<li>CPU usage (% user,system,nice times)</li>\n<li>Load averages (1m, 5m, 15m)</li>\n<li>RAM usage (real, swap, shm)</li>\n<li>Disc throughput</li>\n<li>Active connections (by port number)</li>\n<li>Number of processes (by process type)</li>\n<li>Ping time from remote location</li>\n<li>Time to SSL certificate expiry</li>\n<li>MySQL internals (query cache usage, num temporary tables in RAM and on disc, etc)</li>\n</ul>\n\n<p>Anything you can monitor with Zabbix, you can also attach triggers to - so it can restart failed services; or page you to alert about problems.</p>\n\n<p>Collect the data now, before performance becomes an issue. When it does, you'll be glad of the historical baselines, and the fact you'll be able to show what date and time problems started happening for when you need to hunt down and punish exactly which developer made bad changes :)</p>\n"}, {'answer_id': 87035, 'author': 'JBB', 'author_id': 12332, 'author_profile': 'https://Stackoverflow.com/users/12332', 'pm_score': 1, 'selected': False, 'text': "<p>Beware the afore-mentioned slowquerylog in mysql. It should only be used when trying to figure out why some queries are slow. It has the side-effect of making ALL your queries slow while it's enabled. :P It's intended for debugging, not logging. </p>\n\n<p>Think 'passive monitoring' whenever possible. For instance, sniff the network traffic rather than monitor it from your server -- have another machine watch the packets fly back and forth and record statistics about them.</p>\n\n<p>(By the way, that's one of my favorites -- if you watch connections being established and note when they end, you can find a lot of data about slow queries or slow anything else, without putting any load on the server you care about.)</p>\n"}, {'answer_id': 397922, 'author': 'oneself', 'author_id': 9435, 'author_profile': 'https://Stackoverflow.com/users/9435', 'pm_score': 2, 'selected': False, 'text': "<p>I ended up using dstat which is vmstat's nicer looking cousin.</p>\n\n<p>This will show most everything you need to know about a machine's health,\nincluding:</p>\n\n<ul>\n<li>CPU</li>\n<li>Disk</li>\n<li>Memory</li>\n<li>Network</li>\n<li>Swap</li>\n</ul>\n"}]
2008/09/16
['https://Stackoverflow.com/questions/74993', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/9435/']
75,001
<p>As popular as Ruby and Rails are, it seems like this problem would already be solved. JRuby and mod_rails are all fine and dandy, but why isn't there an Apache mod for just straight Ruby?</p>
[{'answer_id': 75095, 'author': 'AShelly', 'author_id': 10396, 'author_profile': 'https://Stackoverflow.com/users/10396', 'pm_score': 2, 'selected': False, 'text': '<p>There is one: <a href="http://www.modruby.net/en/" rel="nofollow noreferrer">mod_ruby</a>, but it hasn\'t been maintained in about 2 years.</p>\n'}, {'answer_id': 75217, 'author': 'mislav', 'author_id': 11687, 'author_profile': 'https://Stackoverflow.com/users/11687', 'pm_score': 5, 'selected': False, 'text': '<p>There is <a href="http://www.modrails.com/" rel="nofollow noreferrer">Phusion Passenger</a>, a robust Apache module that can run <a href="http://rack.rubyforge.org/" rel="nofollow noreferrer">Rack</a> applications with minimum configuration. It\'s becoming appealing to shared hosts, and turning any program into a Rack application is ridiculously easy:</p>\n\n<blockquote>\n <p>A Rack application is an Ruby <strong>object</strong>\n (not a class) that responds to <code>call</code>.\n It takes exactly <em>one argument</em>, the\n environment and returns an Array of\n exactly <em>three values</em>: The status, the\n headers, and the body.</p>\n</blockquote>\n'}, {'answer_id': 75628, 'author': 'Nate', 'author_id': 12779, 'author_profile': 'https://Stackoverflow.com/users/12779', 'pm_score': 3, 'selected': False, 'text': '<p>It\'s perhaps worth double-clarifying mislav\'s point that mod_rails isn\'t actually limited to Rails code at all. The new name, mod_rack, is way better. Trivially small apps can be rackable -- their example being:</p>\n\n<pre><code>class HelloWorld\n def call(env)\n [200, {"Content-Type" =&gt; "text/plain"}, ["Hello world!"]]\n end\nend\n</code></pre>\n'}, {'answer_id': 76089, 'author': 'Honza', 'author_id': 8621, 'author_profile': 'https://Stackoverflow.com/users/8621', 'pm_score': 0, 'selected': False, 'text': '<p>There is <a href="http://www.modrails.com/" rel="nofollow noreferrer">mod_rails</a> and it can run <a href="http://rack.rubyforge.org/" rel="nofollow noreferrer">Rack</a> applications, what more can you need?</p>\n'}, {'answer_id': 109518, 'author': 'Jörg W Mittag', 'author_id': 2988, 'author_profile': 'https://Stackoverflow.com/users/2988', 'pm_score': 5, 'selected': True, 'text': '<p>The basic problem is this: for a long time, MRI was the only feasible Ruby Implementation. MRI has a number of problems that make it hard to embed it into another application (which is basically what <a href="http://ModRuby.Net/" rel="noreferrer">mod_ruby</a> does: it embeds MRI in Apache), especially a multi-threaded one (which Apache is). It is not particularly thread-safe and it has quite a bit of global state.</p>\n\n<p>This global state means for example that if one Rails application modifies some class, then <em>all other</em> Rails applications that run on the same Apache server, will <em>also</em> see this modified class.</p>\n\n<p>Another problem is that the MRI source code is not easily hackable. MRI is now more than 15 years old, and it\'s starting to show.</p>\n\n<p>As a result of these problems, mod_ruby has never <em>really</em> properly worked, and at some point the maintainers simply gave up.</p>\n\n<p>The C based PHP interpreter, on the other hand, was designed from day one to be run as mod_php inside Apache. Indeed, for the first couple of versions, there wasn\'t even a commandline version of the interpreter, mod_php was the <em>only</em> way to run PHP.</p>\n\n<p><a href="http://ModRails.Com/" rel="noreferrer">Phusion Passenger (aka mod_rack aka mod_rails)</a> solves this problem by basically giving up and sidestepping the problem: they simply run a seperate copy of MRI in a seperate process for every application. It works great, and not only for Ruby. It supports <a href="http://WSGI.Org/" rel="noreferrer">WSGI</a> (standard interface for Python Web Frameworks), <a href="http://Rack.RubyForge.Org/" rel="noreferrer">Rack</a> (standard interface for Ruby Web Frameworks) and direct support for Ruby on Rails.</p>\n\n<p>My hopes are on <a href="https://GitHub.Com/rue/mod_rubinius/" rel="noreferrer">mod_rubinius</a>, which unfortunately doesn\'t exist yet. <a href="http://Rubini.us/" rel="noreferrer">Rubinius</a> was designed from the beginning to be thread-safe, embeddable, free of global state, not use the C stack and so on. It was designed to be able to run multiple Rubinius VMs inside one Rubinius process. This makes mod_rubinius infinitely easier to implement and maintain than mod_ruby. Unfortunately, of course, Rubinius is not released yet, and the real work on mod_rubinius cannot even begin until Rubinius is released. The good news is that mod_rubinius already has more manpower behind it than mod_ruby ever had, because it has paid developers working on it by a Rails hosting company that <em>desperately</em> wants to use it themselves.</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/75001', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/6726/']
75,011
<p>In a VB6 application, I have a <code>Dictionary</code> whose keys are <code>String</code>s and values are instances of a custom class. If I call <code>RemoveAll()</code> on the <code>Dictionary</code>, will it first free the custom objects? Or do I explicitly need to do this myself?</p> <pre><code>Dim d as Scripting.Dictionary d("a") = New clsCustom d("b") = New clsCustom ' Are these two lines necessary? Set d("a") = Nothing Set d("b") = Nothing d.RemoveAll </code></pre>
[{'answer_id': 75066, 'author': 'Neil C. Obremski', 'author_id': 9642, 'author_profile': 'https://Stackoverflow.com/users/9642', 'pm_score': 3, 'selected': True, 'text': '<p>Yes, all objects in the <code>Dictionary</code> will be released after a call to <code>RemoveAll()</code>. From a performance (as in speed) standpoint I would say those lines setting the variables to <code>Nothing</code> are unnecessary, because the code has to first look them up based on the key names whereas <code>RemoveAll()</code> will enumerate and release everything in one loop.</p>\n'}, {'answer_id': 75073, 'author': 'Chris Smith', 'author_id': 9073, 'author_profile': 'https://Stackoverflow.com/users/9073', 'pm_score': 2, 'selected': False, 'text': '<p><code>RemoveAll</code> will remove all the associations from the <code>Dictionary</code>: both the keys and values. \nIt would be a reference leak for the <code>Dictionary</code> to keep a reference to the values in the <code>Dictionary</code>.</p>\n'}, {'answer_id': 75107, 'author': 'palehorse', 'author_id': 312, 'author_profile': 'https://Stackoverflow.com/users/312', 'pm_score': 0, 'selected': False, 'text': '<p>If there are no other variables that reference the items in the collection then those objects should be handed to the Garbage Collector to be cleaned up the next time the GC is run.</p>\n\n<p>If you, for example do this where sObj is a static variable somewhere then the when the GC is invoked next by the system, the first object will be cleaned up but the second which still is referenced by sObj will not.</p>\n\n<pre><code>d("a") = New clsCustom\nd("b") = New clsCustom code.\nsObj = d("b")\n\nd.RemoveAll()\n</code></pre>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/75011', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/863/']
75,014
<p>In a multi-threaded application I'm working on, we occasionally see <code>ConcurrentModificationExceptions</code> on our Lists (which are mostly <code>ArrayList</code>, sometimes Vectors). But there are other times when I think concurrent modifications are happening because iterating through the collection appears to be missing items, but no exceptions are thrown. I know that the docs for <code>ConcurrentModificationException</code> says you can't rely on it, but how would I go about making sure I'm not concurrently modifying a List? And is wrapping every access to the collection in a synchronized block the only way to prevent it?</p> <p><strong>Update:</strong> Yes, I know about <code>Collections.synchronizedCollection</code>, but it doesn't guard against somebody modifying the collection while you're iterating through it. I think at least some of my problem is happening when somebody adds something to a collection while I'm iterating through it.</p> <p><strong>Second Update</strong> If somebody wants to combine the mention of the synchronizedCollection and cloning like Jason did with a mention of the java.util.concurrent and the apache collections frameworks like jacekfoo and Javamann did, I can accept an answer.</p>
[{'answer_id': 75041, 'author': 'Tim Howland', 'author_id': 4276, 'author_profile': 'https://Stackoverflow.com/users/4276', 'pm_score': 2, 'selected': False, 'text': '<p>Check out <a href="http://www.javadoconline.com/search.jsp?from=main&amp;class=java.util.concurrent&amp;action=search" rel="nofollow noreferrer">java.util.concurrent</a> for versions of the standard Collections classes that are engineered to handle concurrency better.</p>\n'}, {'answer_id': 75043, 'author': 'Hank Gay', 'author_id': 4203, 'author_profile': 'https://Stackoverflow.com/users/4203', 'pm_score': 1, 'selected': False, 'text': "<p>You could try using defensive copying so that modifications to one <code>List</code> don't affect others.</p>\n"}, {'answer_id': 75048, 'author': 'Jason Cohen', 'author_id': 4926, 'author_profile': 'https://Stackoverflow.com/users/4926', 'pm_score': 2, 'selected': False, 'text': '<p>Yes you have to synchronize access to collections objects.</p>\n\n<p>Alternatively, you can use the synchronized wrappers around any existing object. See <a href="http://java.sun.com/javase/6/docs/api/java/util/Collections.html#synchronizedList(java.util.List)" rel="nofollow noreferrer">Collections.synchronizedCollection()</a>. For example:</p>\n\n<pre><code>List&lt;String&gt; safeList = Collections.synchronizedList( originalList );\n</code></pre>\n\n<p>However all code needs to use the safe version, and even so iterating while another thread modifies will result in problems.</p>\n\n<p>To solve the iteration problem, copy the list first. Example:</p>\n\n<pre><code>for ( String el : safeList.clone() )\n{ ... }\n</code></pre>\n\n<p>For more optimized, thread-safe collections, also look at <a href="http://www.javadoconline.com/search.jsp?from=main&amp;class=java.util.concurrent&amp;action=search" rel="nofollow noreferrer">java.util.concurrent</a>.</p>\n'}, {'answer_id': 75053, 'author': 'sblundy', 'author_id': 4893, 'author_profile': 'https://Stackoverflow.com/users/4893', 'pm_score': -1, 'selected': False, 'text': '<p><a href="http://java.sun.com/javase/6/docs/api/java/util/Collections.html#synchronizedList(java.util.List)" rel="nofollow noreferrer">Collections.synchronizedList()</a> will render a list nominally thread-safe and java.util.concurrent has more powerful features.</p>\n'}, {'answer_id': 75068, 'author': 'Mat Mannion', 'author_id': 6282, 'author_profile': 'https://Stackoverflow.com/users/6282', 'pm_score': 2, 'selected': False, 'text': "<p>Usually you get a ConcurrentModificationException if you're trying to remove an element from a list whilst it's being iterated through.</p>\n\n<p>The easiest way to test this is:</p>\n\n<pre><code>List&lt;Blah&gt; list = new ArrayList&lt;Blah&gt;();\nfor (Blah blah : list) {\n list.remove(blah); // will throw the exception\n}\n</code></pre>\n\n<p>I'm not sure how you'd get around it. You may have to implement your own thread-safe list, or you could create copies of the original list for writing and have a synchronized class that writes to the list.</p>\n"}, {'answer_id': 75088, 'author': 'toluju', 'author_id': 12457, 'author_profile': 'https://Stackoverflow.com/users/12457', 'pm_score': 1, 'selected': False, 'text': '<p>Wrapping accesses to the collection in a synchronized block is the correct way to do this. Standard programming practice dictates the use of some sort of locking mechanism (semaphore, mutex, etc) when dealing with state that is shared across multiple threads.</p>\n\n<p>Depending on your use case however you can usually make some optimizations to only lock in certain cases. For example, if you have a collection that is frequently read but rarely written, then you can allow concurrent reads but enforce a lock whenever a write is in progress. Concurrent reads only cause conflicts if the collection is in the process of being modified.</p>\n'}, {'answer_id': 75093, 'author': 'Todd Gamblin', 'author_id': 9122, 'author_profile': 'https://Stackoverflow.com/users/9122', 'pm_score': 1, 'selected': False, 'text': "<p>ConcurrentModificationException is best-effort because what you're asking is a hard problem. There's no good way to do this reliably without sacrificing performance besides proving that your access patterns do not concurrently modify the list.</p>\n\n<p>Synchronization would likely prevent concurrent modifications, and it may be what you resort to in the end, but it can end up being costly. The best thing to do is probably to sit down and think for a while about your algorithm. If you can't come up with a lock-free solution, then resort to synchronization.</p>\n"}, {'answer_id': 75196, 'author': 'Javamann', 'author_id': 10166, 'author_profile': 'https://Stackoverflow.com/users/10166', 'pm_score': 3, 'selected': False, 'text': '<p>Depending on your update frequency one of my favorites is the CopyOnWriteArrayList or CopyOnWriteArraySet. They create a new list/set on updates to avoid concurrent modification exception. </p>\n'}, {'answer_id': 75205, 'author': 'jb.', 'author_id': 7918, 'author_profile': 'https://Stackoverflow.com/users/7918', 'pm_score': 1, 'selected': False, 'text': "<p>See the implementation. It basically stores an int:</p>\n\n<pre><code>transient volatile int modCount;\n</code></pre>\n\n<p>and that is incremented when there is a 'structural modification' (like remove). If iterator detects that modCount changed it throws Concurrent modification exception. </p>\n\n<p>Synchronizing (via Collections.synchronizedXXX) won't do good since it does not guarantee iterator safety it only synchronizes writes and reads via put, get, set ...</p>\n\n<p>See java.util.concurennt and apache collections framework (it has some classes that are optimized do work correctly in concurrent environment when there is more reads (that are unsynchronized) than writes - see FastHashMap. </p>\n"}, {'answer_id': 76998, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': -1, 'selected': False, 'text': "<p>This will get rid of your concurrent modification exception. I won't speak to the efficiency however ;)</p>\n\n<pre><code>List&lt;Blah&gt; list = fillMyList();\nList&lt;Blah&gt; temp = new ArrayList&lt;Blah&gt;();\nfor (Blah blah : list) {\n //list.remove(blah); would throw the exception\n temp.add(blah);\n}\nlist.removeAll(temp);\n</code></pre>\n"}, {'answer_id': 82025, 'author': 'Bill Michell', 'author_id': 7938, 'author_profile': 'https://Stackoverflow.com/users/7938', 'pm_score': 3, 'selected': True, 'text': '<p>Your original question seems to be asking for an iterator that sees live updates to the underlying collection while remaining thread-safe. This is an incredibly expensive problem to solve in the general case, which is why none of the standard collection classes do it.</p>\n\n<p>There are lots of ways of achieving partial solutions to the problem, and in your application, one of those may be sufficient.</p>\n\n<p>Jason gives <a href="https://stackoverflow.com/questions/75014/detecting-concurrent-modifications#75048">a specific way to achieve thread safety, and to avoid throwing a ConcurrentModificationException</a>, but only at the expense of liveness.</p>\n\n<p>Javamann mentions <a href="https://stackoverflow.com/questions/75014/detecting-concurrent-modifications#75196">two specific classes</a> in the <code>java.util.concurrent</code> package that solve the same problem in a lock-free way, where scalability is critical. These only shipped with Java 5, but there have been various projects that backport the functionality of the package into earlier Java versions, including <a href="http://backport-jsr166.sourceforge.net/" rel="nofollow noreferrer">this one</a>, though they won\'t have such good performance in earlier JREs.</p>\n\n<p>If you are already using some of the Apache Commons libraries, then as jacekfoo <a href="https://stackoverflow.com/questions/75014/detecting-concurrent-modifications#75205">points out</a>, the <a href="http://commons.apache.org/collections/" rel="nofollow noreferrer">apache collections framework</a> contains some helpful classes.</p>\n\n<p>You might also consider looking at the <a href="http://www.devx.com/Java/Article/36183" rel="nofollow noreferrer">Google collections framework</a>.</p>\n'}, {'answer_id': 796493, 'author': 'Sean Turner', 'author_id': 96894, 'author_profile': 'https://Stackoverflow.com/users/96894', 'pm_score': 1, 'selected': False, 'text': "<p>You can also synchronize over iteratins over the list. </p>\n\n<pre><code>List&lt;String&gt; safeList = Collections.synchronizedList( originalList );\n\npublic void doSomething() {\n synchronized(safeList){\n for(String s : safeList){\n System.out.println(s);\n\n }\n }\n\n}\n</code></pre>\n\n<p>This will lock the list on synchronization and block all threads that try to access the list while you edit it or iterate over it. The downside is that you create a bottleneck.</p>\n\n<p>This saves some memory over the .clone() method and might be faster depending on what you're doing in the iteration... </p>\n"}]
2008/09/16
['https://Stackoverflow.com/questions/75014', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3333/']
75,052
<p>I have a flash player that has a set of songs loaded via an xml file.</p> <p>The files dont start getting stream until you pick one.</p> <p>If I quickly cycle through each of the 8 files, then flash starts trying to download each of the 8 files at the same time.</p> <p>I'm wondering if there is a way to clear the file that is being downloaded. So that bandwidth is not eaten up if someone decides to click on lots of track names.</p> <p>Something like mySound.clear would be great, or mySound.stopStreaming..</p> <p>Has anyone had this problem before?</p> <p>Regards,</p> <p>Chris</p>
[{'answer_id': 75323, 'author': 'Jon', 'author_id': 12261, 'author_profile': 'https://Stackoverflow.com/users/12261', 'pm_score': 0, 'selected': False, 'text': '<p>If you do something like:</p>\n\n<p>MySoundObject = undefined;</p>\n\n<p>That should do it.</p>\n'}, {'answer_id': 259891, 'author': 'HanClinto', 'author_id': 26933, 'author_profile': 'https://Stackoverflow.com/users/26933', 'pm_score': 2, 'selected': True, 'text': '<p>Check out <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/media/Sound.html#close()" rel="nofollow noreferrer">Sound.Close()</a>.</p>\n\n<p>From the docs: "<em>Closes the stream, causing any download of data to cease. No data may be read from the stream after the close() method is called.</em>"</p>\n\n<p>This is the <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/media/Sound.html#close()" rel="nofollow noreferrer">source code example</a> from the linked docs:</p>\n\n<pre><code>package {\n import flash.display.Sprite;\n import flash.net.URLRequest;\n import flash.media.Sound; \n import flash.text.TextField;\n import flash.text.TextFieldAutoSize;\n import flash.events.MouseEvent;\n import flash.errors.IOError;\n import flash.events.IOErrorEvent;\n\n public class Sound_closeExample extends Sprite {\n private var snd:Sound = new Sound();\n private var button:TextField = new TextField();\n private var req:URLRequest = new URLRequest("http://av.adobe.com/podcast/csbu_dev_podcast_epi_2.mp3");\n\n public function Sound_closeExample() {\n button.x = 10;\n button.y = 10;\n button.text = "START";\n button.border = true;\n button.background = true;\n button.selectable = false;\n button.autoSize = TextFieldAutoSize.LEFT;\n\n button.addEventListener(MouseEvent.CLICK, clickHandler);\n\n this.addChild(button);\n }\n\n private function clickHandler(e:MouseEvent):void {\n\n if(button.text == "START") {\n\n snd.load(req);\n snd.play(); \n\n snd.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);\n\n button.text = "STOP";\n }\n else if(button.text == "STOP") {\n\n try {\n snd.close();\n button.text = "Wait for loaded stream to finish.";\n }\n catch (error:IOError) {\n button.text = "Couldn\'t close stream " + error.message; \n }\n }\n }\n\n private function errorHandler(event:IOErrorEvent):void {\n button.text = "Couldn\'t load the file " + event.text;\n }\n }\n}\n</code></pre>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/75052', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/6822/']
75,057
<p>What is the best way of ensuring that a user supplied password is a strong password in a registration or change password form?</p> <p>One idea I had (in python)</p> <pre><code>def validate_password(passwd): conditions_met = 0 conditions_total = 3 if len(passwd) &gt;= 6: if passwd.lower() != passwd: conditions_met += 1 if len([x for x in passwd if x.isdigit()]) &gt; 0: conditions_met += 1 if len([x for x in passwd if not x.isalnum()]) &gt; 0: conditions_met += 1 result = False print conditions_met if conditions_met &gt;= 2: result = True return result </code></pre>
[{'answer_id': 75108, 'author': 'Mostlyharmless', 'author_id': 12881, 'author_profile': 'https://Stackoverflow.com/users/12881', 'pm_score': -1, 'selected': False, 'text': '<p>Password strength checkers, and if you have time+resources (its justified only if you are checking for more than a few passwords) use Rainbow Tables.</p>\n'}, {'answer_id': 75109, 'author': 'Peter Boughton', 'author_id': 9360, 'author_profile': 'https://Stackoverflow.com/users/9360', 'pm_score': -1, 'selected': False, 'text': '<p>With a series of checks to ensure it meets minimum criteria:<ul>\n<li>at least 8 characters long</li>\n<li>contains at least one non-alphanumeric symbol</li>\n<li>does not match or contain username/email/etc.</li>\n<li>etc</li>\n</ul></p>\n\n<p>Here\'s a jQuery plugin that reports password strength (not tried it myself):\n<a href="http://phiras.wordpress.com/2007/04/08/password-strength-meter-a-jquery-plugin/" rel="nofollow noreferrer">http://phiras.wordpress.com/2007/04/08/password-strength-meter-a-jquery-plugin/</a></p>\n\n<p>And the same thing ported to PHP:\n<a href="http://www.alixaxel.com/wordpress/2007/06/09/php-password-strength-algorithm/" rel="nofollow noreferrer">http://www.alixaxel.com/wordpress/2007/06/09/php-password-strength-algorithm/</a></p>\n'}, {'answer_id': 75149, 'author': 'VirtuosiMedia', 'author_id': 13281, 'author_profile': 'https://Stackoverflow.com/users/13281', 'pm_score': 4, 'selected': False, 'text': '<p>Depending on the language, I usually use regular expressions to check if it has:</p>\n\n<ul>\n<li>At least one uppercase and one\nlowercase letter</li>\n<li>At least one number</li>\n<li>At least one special character</li>\n<li>A length of at least six characters</li>\n</ul>\n\n<p>You can require all of the above, or use a strength meter type of script. For my strength meter, if the password has the right length, it is evaluated as follows:</p>\n\n<ul>\n<li>One condition met: weak password</li>\n<li>Two conditions met: medium password</li>\n<li>All conditions met: strong password</li>\n</ul>\n\n<p>You can adjust the above to meet your needs.</p>\n'}, {'answer_id': 75173, 'author': 'David Webb', 'author_id': 3171, 'author_profile': 'https://Stackoverflow.com/users/3171', 'pm_score': 2, 'selected': False, 'text': "<p>The two simplest metrics to check for are:</p>\n\n<ol>\n<li>Length. I'd say 8 characters as a minimum.</li>\n<li>Number of different character classes the password contains. These are usually, lowercase letters, uppercase letters, numbers and punctuation and other symbols. A strong password will contain characters from at least three of these classes; if you force a number or other non-alphabetic character you significantly reduce the effectiveness of dictionary attacks.</li>\n</ol>\n"}, {'answer_id': 75498, 'author': 'user9116', 'author_id': 9116, 'author_profile': 'https://Stackoverflow.com/users/9116', 'pm_score': 3, 'selected': False, 'text': "<p>The object-oriented approach would be a set of rules. Assign a weight to each rule and iterate through them. In psuedo-code:</p>\n\n<pre><code>abstract class Rule {\n\n float weight;\n\n float calculateScore( string password );\n\n}\n</code></pre>\n\n<p>Calculating the total score:</p>\n\n<pre><code>float getPasswordStrength( string password ) { \n\n float totalWeight = 0.0f;\n float totalScore = 0.0f;\n\n foreach ( rule in rules ) {\n\n totalWeight += weight;\n totalScore += rule.calculateScore( password ) * rule.weight;\n\n }\n\n return (totalScore / totalWeight) / rules.count;\n\n}\n</code></pre>\n\n<p>An example rule algorithm, based on number of character classes present:</p>\n\n<pre><code>float calculateScore( string password ) {\n\n float score = 0.0f;\n\n // NUMBER_CLASS is a constant char array { '0', '1', '2', ... }\n if ( password.contains( NUMBER_CLASS ) )\n score += 1.0f;\n\n if ( password.contains( UPPERCASE_CLASS ) )\n score += 1.0f;\n\n if ( password.contains( LOWERCASE_CLASS ) )\n score += 1.0f;\n\n // Sub rule as private method\n if ( containsPunctuation( password ) )\n score += 1.0f;\n\n return score / 4.0f;\n\n}\n</code></pre>\n"}, {'answer_id': 1872514, 'author': 'SapphireSun', 'author_id': 210920, 'author_profile': 'https://Stackoverflow.com/users/210920', 'pm_score': 0, 'selected': False, 'text': '<p>I don\'t know if anyone will find this useful, but I really liked the idea of a ruleset as suggested by phear so I went and wrote a rule Python 2.6 class (although it\'s probably compatible with 2.5):</p>\n\n<pre><code>import re\n\nclass SecurityException(Exception):\n pass\n\nclass Rule:\n """Creates a rule to evaluate against a string.\n Rules can be regex patterns or a boolean returning function.\n Whether a rule is inclusive or exclusive is decided by the sign\n of the weight. Positive weights are inclusive, negative weights are\n exclusive. \n\n\n Call score() to return either 0 or the weight if the rule \n is fufilled. \n\n Raises a SecurityException if a required rule is violated.\n """\n\n def __init__(self,rule,weight=1,required=False,name=u"The Unnamed Rule"):\n try:\n getattr(rule,"__call__")\n except AttributeError:\n self.rule = re.compile(rule) # If a regex, compile\n else:\n self.rule = rule # Otherwise it\'s a function and it should be scored using it\n\n if weight == 0:\n return ValueError(u"Weights can not be 0")\n\n self.weight = weight\n self.required = required\n self.name = name\n\n def exclusive(self):\n return self.weight &lt; 0\n def inclusive(self):\n return self.weight &gt;= 0\n exclusive = property(exclusive)\n inclusive = property(inclusive)\n\n def _score_regex(self,password):\n match = self.rule.search(password)\n if match is None:\n if self.exclusive: # didn\'t match an exclusive rule\n return self.weight\n elif self.inclusive and self.required: # didn\'t match on a required inclusive rule\n raise SecurityException(u"Violation of Rule: %s by input \\"%s\\"" % (self.name.title(), password))\n elif self.inclusive and not self.required:\n return 0\n else:\n if self.inclusive:\n return self.weight\n elif self.exclusive and self.required:\n raise SecurityException(u"Violation of Rule: %s by input \\"%s\\"" % (self.name,password))\n elif self.exclusive and not self.required:\n return 0\n\n return 0\n\n def score(self,password):\n try:\n getattr(self.rule,"__call__")\n except AttributeError:\n return self._score_regex(password)\n else:\n return self.rule(password) * self.weight\n\n def __unicode__(self):\n return u"%s (%i)" % (self.name.title(), self.weight)\n\n def __str__(self):\n return self.__unicode__()\n</code></pre>\n\n<p>I hope someone finds this useful!</p>\n\n<p>Example Usage:</p>\n\n<pre><code>rules = [ Rule("^foobar",weight=20,required=True,name=u"The Fubared Rule"), ]\ntry:\n score = 0\n for rule in rules:\n score += rule.score()\nexcept SecurityException e:\n print e \nelse:\n print score\n</code></pre>\n\n<p>DISCLAIMER: Not unit tested</p>\n'}, {'answer_id': 4191130, 'author': 'Sean Reifschneider', 'author_id': 267126, 'author_profile': 'https://Stackoverflow.com/users/267126', 'pm_score': 2, 'selected': False, 'text': '<p>Cracklib is great, and in newer packages there is a Python module available for it. However, on systems that don\'t yet have it, such as CentOS 5, I\'ve written a ctypes wrapper for the system cryptlib. This would also work on a system that you can\'t install python-libcrypt. It <em>does</em> require python with ctypes available, so for CentOS 5 you have to install and use the python26 package.</p>\n\n<p>It also has the advantage that it can take the username and check for passwords that contain it or are substantially similar, like the libcrypt "FascistGecos" function but without requiring the user to exist in /etc/passwd.</p>\n\n<p>My <a href="http://github.com/linsomniac/python-ctypescracklib" rel="nofollow">ctypescracklib library is available on github</a></p>\n\n<p>Some example uses:</p>\n\n<pre><code>&gt;&gt;&gt; FascistCheck(\'jafo1234\', \'jafo\')\n\'it is based on your username\'\n&gt;&gt;&gt; FascistCheck(\'myofaj123\', \'jafo\')\n\'it is based on your username\'\n&gt;&gt;&gt; FascistCheck(\'jxayfoxo\', \'jafo\')\n\'it is too similar to your username\'\n&gt;&gt;&gt; FascistCheck(\'cretse\')\n\'it is based on a dictionary word\'\n</code></pre>\n'}, {'answer_id': 4298717, 'author': 'siznax', 'author_id': 59037, 'author_profile': 'https://Stackoverflow.com/users/59037', 'pm_score': 2, 'selected': False, 'text': '<p>after reading the other helpful answers, this is what i\'m going with:</p>\n\n<p>-1 same as username<br>\n+0 contains username<br>\n+1 more than 7 chars<br>\n+1 more than 11 chars<br>\n+1 contains digits<br>\n+1 mix of lower and uppercase<br>\n+1 contains punctuation<br>\n+1 non-printable char </p>\n\n<p>pwscore.py:</p>\n\n<pre><code>import re\nimport string\nmax_score = 6\ndef score(username,passwd):\n if passwd == username:\n return -1\n if username in passwd:\n return 0\n score = 0\n if len(passwd) &gt; 7:\n score+=1\n if len(passwd) &gt; 11:\n score+=1\n if re.search(\'\\d+\',passwd):\n score+=1\n if re.search(\'[a-z]\',passwd) and re.search(\'[A-Z]\',passwd):\n score+=1\n if len([x for x in passwd if x in string.punctuation]) &gt; 0:\n score+=1\n if len([x for x in passwd if x not in string.printable]) &gt; 0:\n score+=1\n return score\n</code></pre>\n\n<p>example usage:</p>\n\n<pre><code>import pwscore\n score = pwscore(username,passwd)\n if score &lt; 3:\n return "weak password (score=" \n + str(score) + "/"\n + str(pwscore.max_score)\n + "), try again."\n</code></pre>\n\n<p>probably not the most efficient, but seems reasonable. \nnot sure FascistCheck => \'too similar to username\' is \nworth it.</p>\n\n<p>\'abc123ABC!@£\' = score 6/6 if not a superset of username</p>\n\n<p>maybe that should score lower.</p>\n'}, {'answer_id': 7285380, 'author': 'varun', 'author_id': 95967, 'author_profile': 'https://Stackoverflow.com/users/95967', 'pm_score': 1, 'selected': False, 'text': '<p>Well this is what I use:</p>\n\n<pre><code> var getStrength = function (passwd) {\n intScore = 0;\n intScore = (intScore + passwd.length);\n if (passwd.match(/[a-z]/)) {\n intScore = (intScore + 1);\n }\n if (passwd.match(/[A-Z]/)) {\n intScore = (intScore + 5);\n }\n if (passwd.match(/\\d+/)) {\n intScore = (intScore + 5);\n }\n if (passwd.match(/(\\d.*\\d)/)) {\n intScore = (intScore + 5);\n }\n if (passwd.match(/[!,@#$%^&amp;*?_~]/)) {\n intScore = (intScore + 5);\n }\n if (passwd.match(/([!,@#$%^&amp;*?_~].*[!,@#$%^&amp;*?_~])/)) {\n intScore = (intScore + 5);\n }\n if (passwd.match(/[a-z]/) &amp;&amp; passwd.match(/[A-Z]/)) {\n intScore = (intScore + 2);\n }\n if (passwd.match(/\\d/) &amp;&amp; passwd.match(/\\D/)) {\n intScore = (intScore + 2);\n }\n if (passwd.match(/[a-z]/) &amp;&amp; passwd.match(/[A-Z]/) &amp;&amp; passwd.match(/\\d/) &amp;&amp; passwd.match(/[!,@#$%^&amp;*?_~]/)) {\n intScore = (intScore + 2);\n }\n return intScore;\n} \n</code></pre>\n'}, {'answer_id': 50489987, 'author': 'Johan', 'author_id': 650492, 'author_profile': 'https://Stackoverflow.com/users/650492', 'pm_score': 4, 'selected': True, 'text': '<p><strong>1: Eliminate often used passwords</strong><br>\nCheck the entered passwords against a list of often used passwords (see e.g. the top 100.000 passwords in the leaked LinkedIn password list: <a href="http://www.adeptus-mechanicus.com/codex/linkhap/combo_not.zip" rel="noreferrer">http://www.adeptus-mechanicus.com/codex/linkhap/combo_not.zip</a>), make sure to include <a href="http://www.gamehouse.com/blog/leet-speak-cheat-sheet/" rel="noreferrer">leetspeek substitutions</a>:\nA@, E3, B8, S5, etc.<br>\nRemove parts of the password that hit against this list from the entered phrase, before going to part 2 below.</p>\n\n<p><strong>2: Don\'t force any rules on the user</strong> </p>\n\n<p>The golden rule of passwords is that longer is better.<br>\nForget about forced use of caps, numbers, and symbols because (the vast majority of) users will:\n- Make the first letter a capital;\n- Put the number <code>1</code> at the end;\n- Put a <code>!</code> after that if a symbol is required.</p>\n\n<p><strong>Instead check password strength</strong> </p>\n\n<p>For a decent starting point see: <a href="http://www.passwordmeter.com/" rel="noreferrer">http://www.passwordmeter.com/</a> </p>\n\n<p>I suggest as a minimum the following rules:</p>\n\n<pre><code>Additions (better passwords)\n-----------------------------\n- Number of Characters Flat +(n*4) \n- Uppercase Letters Cond/Incr +((len-n)*2) \n- Lowercase Letters Cond/Incr +((len-n)*2) \n- Numbers Cond +(n*4) \n- Symbols Flat +(n*6)\n- Middle Numbers or Symbols Flat +(n*2) \n- Shannon Entropy Complex *EntropyScore\n\nDeductions (worse passwords)\n----------------------------- \n- Letters Only Flat -n \n- Numbers Only Flat -(n*16) \n- Repeat Chars (Case Insensitive) Complex - \n- Consecutive Uppercase Letters Flat -(n*2) \n- Consecutive Lowercase Letters Flat -(n*2) \n- Consecutive Numbers Flat -(n*2) \n- Sequential Letters (3+) Flat -(n*3) \n- Sequential Numbers (3+) Flat -(n*3) \n- Sequential Symbols (3+) Flat -(n*3)\n- Repeated words Complex - \n- Only 1st char is uppercase Flat -n\n- Last (non symbol) char is number Flat -n\n- Only last char is symbol Flat -n\n</code></pre>\n\n<p>Just following <a href="http://www.passwordmeter.com/" rel="noreferrer">passwordmeter</a> is not enough, because sure enough its naive algorithm sees <kbd>Password1!</kbd> as good, whereas it is exceptionally weak.\nMake sure to disregard initial capital letters when scoring as well as trailing numbers and symbols (as per the last 3 rules).</p>\n\n<p><strong>Calculating Shannon entropy</strong><br>\nSee: <a href="https://stackoverflow.com/questions/15450192/fastest-way-to-compute-entropy-in-python">Fastest way to compute entropy in Python</a></p>\n\n<p><strong>3: Don\'t allow any passwords that are too weak</strong><br>\nRather than forcing the user to bend to self-defeating rules, allow anything that will give a high enough score. How high depends on your use case. </p>\n\n<p><strong>And most importantly</strong><br>\nWhen you accept the password and store it in a database, <a href="https://stackoverflow.com/questions/4578431/how-to-hash-and-salt-passwords">make sure to salt and hash it!</a>.</p>\n'}, {'answer_id': 54055977, 'author': 'Braiam', 'author_id': 792066, 'author_profile': 'https://Stackoverflow.com/users/792066', 'pm_score': -1, 'selected': False, 'text': '<blockquote>\n <p>What is the best way of ensuring that a user supplied password is a strong password in a registration or change password form?</p>\n</blockquote>\n\n<p>Don\'t evaluate complexity and or strength, users will find a way to fool your system or get so frustrated that they will leave. That will only get you situations <a href="https://xkcd.com/936/" rel="nofollow noreferrer">like this</a>. Just require certain length and that leaked passwords aren\'t used. Bonus points: make sure whatever you implement allows the use of password managers and/or 2FA.</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/75057', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13099/']
75,064
<p>I know something about Java but completely new to Enterprise Java. I'm trying my hand with NetBeans 6.1 and GlassFish Application Server. Please guide me to some resources which tell me actually what java enterprise applications are, how they are different from normal java classes etc. </p> <p>Also which is the best application server to use (on Linux)?</p>
[{'answer_id': 75126, 'author': 'Kristian', 'author_id': 11429, 'author_profile': 'https://Stackoverflow.com/users/11429', 'pm_score': 3, 'selected': False, 'text': '<p><a href="http://java.sun.com/javaee/5/docs/tutorial/doc/" rel="noreferrer">The Java EE 5 Tutorial</a> - read online or as pdf</p>\n\n<p><a href="http://www.manning.com/panda/" rel="noreferrer">EJB 3 in Action</a> - great book that covers everything you need to know</p>\n\n<p>I have also recently started with Java EE and I have only used Glassfish/Sun Application Server so far, but from what I understad from my colleagues at work and what I have seen so far Glassfish seems to be the the best choice at the moment.</p>\n'}, {'answer_id': 75222, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>Glassfish on Linux is an excellent choice.</p>\n'}, {'answer_id': 95084, 'author': 'Zombies', 'author_id': 17675, 'author_profile': 'https://Stackoverflow.com/users/17675', 'pm_score': 5, 'selected': True, 'text': '<p>"what java enterprise applications are, how they are different from normal java classes etc"</p>\n\n<p>Well they are normal classes. They are ran by an application server. The "application server" is often <em>just a JVM</em>, but sometimes enhanced or modified or extended by the vendor. But that shouldn\'t be any concern to you. The application server (ie: JVM) uses a class loader (probably customized by vendor) to load your servlet (any class that implements the HttpServlet interface). Any other classes (not just J2EE classes, but all classes) will be loaded by the class loader. From there on it is your same java code. I hope this gives you the kind of answer you want. Reading J2EE documents (even aimed towards developers) usually entails meaningless buzzwords.</p>\n\n<p>I would recommend that you look over the J2EE Tutorial from Sun. It\'s free, and goes over the basics that you should know before moving onto a framework (Struts for example). And of course must need to know if you are just going to use just straight J2EE.</p>\n\n<p>You may wish to familiarize yourself with some of this:</p>\n\n<ul>\n<li><a href="http://java.sun.com/j2ee/1.4/docs/api/" rel="noreferrer">http://java.sun.com/j2ee/1.4/docs/api/</a></li>\n<li>You may also wish to go over HTTP specification (RFC or elsewhere) as well in case you don\'t understand how http requests and responses are processed by a standalone webserver.</li>\n<li><a href="http://java.sun.com/j2ee/1.4/docs/tutorial/doc/Overview3.html" rel="noreferrer">http://java.sun.com/j2ee/1.4/docs/tutorial/doc/Overview3.html</a> (web containers in particular)</li>\n</ul>\n\n<p>A couple of helpful facts:</p>\n\n<ul>\n<li>A JSP is compiled into a servlet. These were created so that your Servlets wouldn\'t have to be developed using an Output Writer to handle every write to page content (the JSP will be compiled into that for you). ie: out.println("&lt;html&gt;etcetc...")</li>\n<li>the request (HttpServletRequest) object represents the request.</li>\n<li>the response (HttpServletRespone) object will build the response. (both the http headers and content).</li>\n<li>Session and Context objects are also important. The former is for carrying session scoped objects (managed by the app server) and mapped to a jsessionid cookie on the client side (so it knows what client (ie: request) has what objects on the server side). The context object is used for initial settings.</li>\n<li>You will want to go over web containers to fit it all together.</li>\n</ul>\n'}, {'answer_id': 6365910, 'author': 'Caffeinated', 'author_id': 763029, 'author_profile': 'https://Stackoverflow.com/users/763029', 'pm_score': 1, 'selected': False, 'text': '<p>I always like to start with wikipedia: <a href="http://en.wikipedia.org/wiki/Java_Platform,_Enterprise_Edition" rel="nofollow">http://en.wikipedia.org/wiki/Java_Platform,_Enterprise_Edition</a></p>\n\n<p>Mastering a good IDE like Eclipse is worthwhile. </p>\n\n<p>Last but not least, YouTube has nice how-to vids:</p>\n\n<p><a href="http://www.youtube.com/watch?v=_-IDpzC0n9Y" rel="nofollow">http://www.youtube.com/watch?v=_-IDpzC0n9Y</a></p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/75064', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13198/']
75,076
<p>I would like to be able to obtain all the parameter values from the stack frame in .NET. A bit like how you're able to see the values in the call stack when in the Visual Studio debugger. My approach has concentrated on using the <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.stackframe%28v=vs.71%29.aspx" rel="noreferrer">StackFrame class</a> and then to reflect over a <a href="http://msdn.microsoft.com/en-us/library/system.reflection.parameterinfo%28v=vs.71%29.aspx" rel="noreferrer">ParameterInfo</a> array. I've had success with reflection and properties, but this is proving a bit trickier.</p> <p>Is there an approach for achieving this?</p> <p>The code so far looks like this:</p> <pre><code>class Program { static void Main(string[] args) { A a = new A(); a.Go(1); } } public class A { internal void Go(int x) { B b = new B(); b.Go(4); } } public class B { internal void Go(int y) { Console.WriteLine(GetStackTrace()); } public static string GetStackTrace() { StringBuilder sb = new StringBuilder(); StackTrace st = new StackTrace(true); StackFrame[] frames = st.GetFrames(); foreach (StackFrame frame in frames) { MethodBase method = frame.GetMethod(); sb.AppendFormat("{0} - {1}",method.DeclaringType, method.Name); ParameterInfo[] paramaters = method.GetParameters(); foreach (ParameterInfo paramater in paramaters) { sb.AppendFormat("{0}: {1}", paramater.Name, paramater.ToString()); } sb.AppendLine(); } return sb.ToString(); } } </code></pre> <h2>The output looks like this:</h2> <pre><code>SfApp.B - GetStackTrace SfApp.B - Go y: Int32 y SfApp.A - Go x: Int32 x SfApp.Program - Main args: System.String[] args </code></pre> <h2>I'd like it to look more like this:</h2> <pre><code>SfApp.B - GetStackTrace SfApp.B - Go y: 4 SfApp.A - Go x: 1 SfApp.Program - Main </code></pre> <hr/> <p>Just for a bit of context, my plan was to try and use this when I throw my own exceptions. I'll look at your suggestions in more detail and see if I can see it fitting.</p>
[{'answer_id': 75297, 'author': 'Lars Truijens', 'author_id': 1242, 'author_profile': 'https://Stackoverflow.com/users/1242', 'pm_score': 4, 'selected': True, 'text': '<p>It seems it can\'t be done that way. It will only provide meta information about the method and its parameters. Not the actual value at the time of the callstack. </p>\n\n<p>Some suggest deriving your classes from <a href="http://msdn.microsoft.com/en-us/library/system.contextboundobject.aspx" rel="noreferrer">ContextBoundObject</a> and use <a href="http://msdn.microsoft.com/en-us/library/system.runtime.remoting.messaging.imessagesink.aspx" rel="noreferrer">IMessageSink</a> to be notified off all method calls and the values of the parameters. This is normally used for <a href="http://en.wikipedia.org/wiki/.NET_Remoting" rel="noreferrer">.NET Remoting</a>.</p>\n\n<p>Another suggestion might be to write a debugger. This is how the IDE gets its information. Microsoft has <a href="http://blogs.msdn.com/jmstall/archive/2004/09/30/236281.aspx" rel="noreferrer">Mdbg</a> of which you can get the source code. Or write a <a href="http://msdn.microsoft.com/en-us/magazine/cc300553.aspx" rel="noreferrer">CLR profiler</a>.</p>\n'}, {'answer_id': 70553027, 'author': 'Marco Luzzara', 'author_id': 5587393, 'author_profile': 'https://Stackoverflow.com/users/5587393', 'pm_score': 1, 'selected': False, 'text': '<p>I am quite sure this is possible somehow, but I am not competent enough to give you the answer you wish. I am suggesting a different approach, less flexible but still useful if you have a stack trace in advance and you would like to see the arguments passed to each frame.</p>\n<p>Typically you would scatter log messages at the start of each method present in your stack trace, but that is pretty cumbersome and not always possible: what if you call methods defined in an external library?</p>\n<hr />\n<p>While I was searching for an inspiration on how to tackle this problem, I found a library called <a href="https://github.com/pardeike/Harmony" rel="nofollow noreferrer">Harmony</a>, that allows you to patch methods at runtime. Basically a method can be decorated with a prefix, a postfix and/or a finalizer. It is all very well explained in the documentation, but the idea you could use in order to provide details about methods in a stack trace is to create a <a href="https://harmony.pardeike.net/articles/patching-prefix.html" rel="nofollow noreferrer">prefix</a> that prints the parameters of each frame.</p>\n<p>Unfortunately, with Harmony only, I do not think it is possible to do this for the methods in the current <code>StackTrace</code>, as you would like to do, even using a postfix/finalizer. Nonetheless it can be done before the target method is called.</p>\n<hr />\n<p>I have created a very simple library called <code>DebugLogger</code> that internally uses Harmony and that simplifies the procedure. <a href="https://github.com/marco-luzzara/DebugLogger" rel="nofollow noreferrer">Here</a> is the repository, but you can also find it on Nuget:</p>\n<pre><code>dotnet add package DebugLogger --version 1.0.0\n</code></pre>\n<p>It still has many limitations, in part because of Harmony, there are just a bunch of tests and is not ready to be considered a library, but it is a good starting point in my opinion. I have prepared a <a href="https://dotnetfiddle.net/79dHkJ" rel="nofollow noreferrer">Fiddle</a> showing the initialization of <code>DebugLogger</code> and a couple of dummy classes to make the demo &quot;meaningful&quot;.</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/75076', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2422/']
75,105
<p>I need to store phone numbers in a table. Please suggest which datatype should I use? <strong>Wait. Please read on before you hit reply..</strong></p> <p>This field needs to be indexed heavily as Sales Reps can use this field for searching (including wild character search).</p> <p>As of now, we are expecting phone numbers to come in a number of formats (from an XML file). Do I have to write a parser to convert to a uniform format? There could be millions of data (with duplicates) and I dont want to tie up the server resources (in activities like preprocessing too much) every time some source data comes through..</p> <p>Any suggestions are welcome..</p> <p>Update: <strong>I have no control over source data. Just that the structure of xml file is standard. Would like to keep the xml parsing to a minimum. Once it is in database, retrieval should be quick. One crazy suggestion going on around here is that it should even work with Ajax AutoComplete feature (so Sales Reps can see the matching ones immediately). OMG!!</strong></p>
[{'answer_id': 75113, 'author': 'John Sheehan', 'author_id': 1786, 'author_profile': 'https://Stackoverflow.com/users/1786', 'pm_score': 2, 'selected': False, 'text': "<p>nvarchar with preprocessing to standardize them as much as possible. You'll probably want to extract extensions and store them in another field.</p>\n"}, {'answer_id': 75119, 'author': 'Iain Holder', 'author_id': 1122, 'author_profile': 'https://Stackoverflow.com/users/1122', 'pm_score': 1, 'selected': False, 'text': "<p>Normalise the data then store as a varchar. Normalising could be tricky.</p>\n\n<p>That should be a one-time hit. Then as a new record comes in, you're comparing it to normalised data. Should be very fast.</p>\n"}, {'answer_id': 75122, 'author': 'cori', 'author_id': 8151, 'author_profile': 'https://Stackoverflow.com/users/8151', 'pm_score': 2, 'selected': False, 'text': "<p>I'm probably missing the obvious here, but wouldn't a varchar just long enough for your longest expected phone number work well?</p>\n\n<p>If I <em>am</em> missing something obvious, I'd love it if someone would point it out...</p>\n"}, {'answer_id': 75125, 'author': 'user13270', 'author_id': 13270, 'author_profile': 'https://Stackoverflow.com/users/13270', 'pm_score': 1, 'selected': False, 'text': '<p>Use a <code>varchar</code> field with a length restriction.</p>\n'}, {'answer_id': 75130, 'author': 'Alex Fort', 'author_id': 12624, 'author_profile': 'https://Stackoverflow.com/users/12624', 'pm_score': 2, 'selected': False, 'text': "<p>I would use a varchar(22). Big enough to hold a north american phone number with extension. You would want to strip out all the nasty '(', ')', '-' characters, or just parse them all into one uniform format.</p>\n\n<p>Alex</p>\n"}, {'answer_id': 75136, 'author': 'Joseph Bui', 'author_id': 3275, 'author_profile': 'https://Stackoverflow.com/users/3275', 'pm_score': 3, 'selected': False, 'text': '<p>Use CHAR(10) if you are storing US Phone numbers only. Remove everything but the digits.</p>\n'}, {'answer_id': 75143, 'author': 'Joseph Daigle', 'author_id': 507, 'author_profile': 'https://Stackoverflow.com/users/507', 'pm_score': 2, 'selected': False, 'text': '<p>SQL Server 2005 is pretty well optimized for substring queries for text in indexed varchar fields. For 2005 they introduced new statistics to the string summary for index fields. This helps significantly with full text searching.</p>\n'}, {'answer_id': 75155, 'author': 'Kearns', 'author_id': 6500, 'author_profile': 'https://Stackoverflow.com/users/6500', 'pm_score': 7, 'selected': True, 'text': '<p>Does this include:</p>\n\n<ul>\n<li>International numbers?</li>\n<li>Extensions?</li>\n<li>Other information besides the actual number (like "ask for bobby")?</li>\n</ul>\n\n<p>If all of these are no, I would use a 10 char field and strip out all non-numeric data. If the first is a yes and the other two are no, I\'d use two varchar(50) fields, one for the original input and one with all non-numeric data striped and used for indexing. If 2 or 3 are yes, I think I\'d do two fields and some kind of crazy parser to determine what is extension or other data and deal with it appropriately. Of course you could avoid the 2nd column by doing something with the index where it strips out the extra characters when creating the index, but I\'d just make a second column and probably do the stripping of characters with a trigger.</p>\n\n<p>Update: to address the AJAX issue, it may not be as bad as you think. If this is realistically the main way anything is done to the table, store only the digits in a secondary column as I said, and then make the index for that column the clustered one.</p>\n'}, {'answer_id': 75163, 'author': 'Brad Osterloo', 'author_id': 9162, 'author_profile': 'https://Stackoverflow.com/users/9162', 'pm_score': 6, 'selected': False, 'text': '<p>We use varchar(15) and certainly index on that field.</p>\n\n<p>The reason being is that International standards can support up to 15 digits</p>\n\n<p><a href="http://en.wikipedia.org/wiki/Phone_number" rel="noreferrer">Wikipedia - Telephone Number Formats</a></p>\n\n<p>If you do support International numbers, I recommend the separate storage of a World Zone Code or Country Code to better filter queries by so that you do not find yourself parsing and checking the length of your phone number fields to limit the returned calls to USA for example</p>\n'}, {'answer_id': 75197, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': "<p>Since you need to accommodate many different phone number formats (and probably include things like extensions etc.) it may make the most sense to just treat it as you would any other varchar. If you could control the input, you could take a number of approaches to make the data more useful, but it doesn't sound that way. </p>\n\n<p>Once you decide to simply treat it as any other string, you can focus on overcoming the inevitable issues regarding bad data, mysterious phone number formating and whatever else will pop up. The challenge will be in building a good search strategy for the data and not how you store it in my opinion. It's always a difficult task having to deal with a large pile of data which you had no control over collecting.</p>\n"}, {'answer_id': 75239, 'author': 'Magnus Johansson', 'author_id': 3584, 'author_profile': 'https://Stackoverflow.com/users/3584', 'pm_score': 1, 'selected': False, 'text': "<p>Use SSIS to extract and process the information. That way you will have the processing of the XML files separated from SQL Server. You can also do the SSIS transformations on a separate server if needed. Store the phone numbers in a standard format using VARCHAR. NVARCHAR would be unnecessary since we are talking about numbers and maybe a couple of other chars, like '+', ' ', '(', ')' and '-'.</p>\n"}, {'answer_id': 5872451, 'author': 'fjleon', 'author_id': 455003, 'author_profile': 'https://Stackoverflow.com/users/455003', 'pm_score': 2, 'selected': False, 'text': '<p>using varchar is pretty inefficient. use the money type and create a user declared type "phonenumber" out of it, and create a rule to only allow positive numbers.</p>\n\n<p>if you declare it as (19,4) you can even store a 4 digit extension and be big enough for international numbers, and only takes 9 bytes of storage. Also, indexes are speedy.</p>\n'}, {'answer_id': 17784147, 'author': 'Rob G', 'author_id': 2097355, 'author_profile': 'https://Stackoverflow.com/users/2097355', 'pm_score': 1, 'selected': False, 'text': '<p>It is fairly common to use an "x" or "ext" to indicate extensions, so allow 15 characters (for full international support) plus 3 (for "ext") plus 4 (for the extension itself) giving a total of 22 characters. That should keep you safe.</p>\n\n<p>Alternatively, normalise on input so any "ext" gets translated to "x", giving a maximum of 20.</p>\n'}, {'answer_id': 42965499, 'author': 'Mr. Tripodi', 'author_id': 4220094, 'author_profile': 'https://Stackoverflow.com/users/4220094', 'pm_score': 1, 'selected': False, 'text': '<p>I realize this thread is old, but it\'s worth mentioning an advantage of storing as a numeric type for formatting purposes, specifically in .NET framework.</p>\n\n<p>IE</p>\n\n<pre><code>.DefaultCellStyle.Format = "(###)###-####" // Will not work on a string\n</code></pre>\n'}, {'answer_id': 45651436, 'author': 'Jayghosh Wankar', 'author_id': 7173263, 'author_profile': 'https://Stackoverflow.com/users/7173263', 'pm_score': 1, 'selected': False, 'text': '<p><strong>It is always better to have separate tables for multi valued attributes like phone number.</strong></p>\n\n<p>As you have no control on source data so, you can parse the data from XML file and convert it into the proper format so that there will not be any issue with formats of a particular country and store it in a separate table so that <strong>indexing and retrieval both will be efficient</strong>.</p>\n\n<p>Thank you.</p>\n'}, {'answer_id': 61000613, 'author': 'Ej Manalo Carbona', 'author_id': 9160045, 'author_profile': 'https://Stackoverflow.com/users/9160045', 'pm_score': 0, 'selected': False, 'text': '<p>Use data type long instead.. dont use int because it only allows whole numbers between -32,768 and 32,767 but if you use long data type you can insert numbers between -2,147,483,648 and 2,147,483,647.</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/75105', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13205/']
75,123
<p>I have a DataSet which I get a DataTable from that I am being passed back from a function call. It has 15-20 columns, however I only want 10 columns of the data.</p> <p>Is there a way to remove those columns that I don't want, copy the DataTable to another that has only the columns defined that I want or is it just better to iterate the collection and just use the columns I need.</p> <p>I need to write the values out to a fixed length data file.</p>
[{'answer_id': 75178, 'author': 'Tom Ritter', 'author_id': 8435, 'author_profile': 'https://Stackoverflow.com/users/8435', 'pm_score': 9, 'selected': True, 'text': '<p>Aside from limiting the columns selected to reduce bandwidth and memory:</p>\n\n<pre><code>DataTable t;\nt.Columns.Remove("columnName");\nt.Columns.RemoveAt(columnIndex);\n</code></pre>\n'}, {'answer_id': 75558, 'author': 'Timothy Carter', 'author_id': 4660, 'author_profile': 'https://Stackoverflow.com/users/4660', 'pm_score': 5, 'selected': False, 'text': '<p>To remove all columns after the one you want, below code should work. It will remove at index 10 (remember Columns are 0 based), until the Column count is 10 or less.</p>\n\n<pre><code>DataTable dt;\nint desiredSize = 10;\n\nwhile (dt.Columns.Count &gt; desiredSize)\n{\n dt.Columns.RemoveAt(desiredSize);\n}\n</code></pre>\n'}, {'answer_id': 58115639, 'author': 'SU7', 'author_id': 8043435, 'author_profile': 'https://Stackoverflow.com/users/8043435', 'pm_score': 3, 'selected': False, 'text': '<p>The question has already been marked as answered, But I guess the question states that the person wants to remove multiple columns from a <code>DataTable</code>. </p>\n\n<p>So for that, here is what I did, when I came across the same problem.</p>\n\n<pre><code>string[] ColumnsToBeDeleted = { "col1", "col2", "col3", "col4" };\n\nforeach (string ColName in ColumnsToBeDeleted)\n{\n if (dt.Columns.Contains(ColName))\n dt.Columns.Remove(ColName);\n}\n</code></pre>\n'}, {'answer_id': 69431049, 'author': 'Hannington Mambo', 'author_id': 1909689, 'author_profile': 'https://Stackoverflow.com/users/1909689', 'pm_score': 0, 'selected': False, 'text': '<p>How about you just select the columns you want like this:</p>\n<pre><code>Dim Subjects As String = &quot;Math, English&quot;\nDim SubjectData As DataTable = Table.AsDataView.ToTable(True, Subjects.Split(&quot;,&quot;))\n</code></pre>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/75123', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3208/']
75,127
<p>I have a bulletin board (punBB based) that I was running out of the root directory for a couple of years. I foolishly decided to do a little gardening and in the process moved the punbb code into it's own subdirectory. The code works great; as long as you point the browser at the new subdirectory. The issue is that the users expect to see it at the root...</p> <p>I tried an index file in the root that had the following:</p> <pre><code>&lt;?php chdir('punbb'); include('index.php'); </code></pre> <p>But that didn't seem to do the trick. So, I tried using the "damn cool voodoo" of mod_rewrite in .htaccess but I can't seem to figure out the right combination of rules to make it work.</p> <p>Here is what I would like to make happen:</p> <p>User enters: </p> <pre><code> http://guardthe.net </code></pre> <p>Browser displays: </p> <pre><code> http://guardthe.net/punbb/ </code></pre> <p>or</p> <pre><code> http://punbb.guardthe.net/ </code></pre> <p>Is this possible, or should I just move the code base back into the root?</p>
[{'answer_id': 75144, 'author': 'user13270', 'author_id': 13270, 'author_profile': 'https://Stackoverflow.com/users/13270', 'pm_score': 1, 'selected': False, 'text': '<p>a PHP file with a 301 HTTP permenant redirect.</p>\n\n<p>Put the following into index.php in the root directory of guardthe.net</p>\n\n<pre><code>&lt;?php\nHeader( "HTTP/1.1 301 Moved Permanently" );\nHeader( "Location: http://guardthe.net/punbb/" );\n?&gt;\n</code></pre>\n\n<p>browser will re-direct with search engine friendliness.</p>\n'}, {'answer_id': 75147, 'author': 'Jan Krüger', 'author_id': 12471, 'author_profile': 'https://Stackoverflow.com/users/12471', 'pm_score': 0, 'selected': False, 'text': "<p>Your example code is missing but here's one way to do it using mod_rewrite:</p>\n\n<pre><code>RewriteEngine on\nRewriteRule ^$ http://guardthe.net/punbb/ [L,R=301]\n</code></pre>\n"}, {'answer_id': 75185, 'author': 'toluju', 'author_id': 12457, 'author_profile': 'https://Stackoverflow.com/users/12457', 'pm_score': 0, 'selected': False, 'text': "<p>You could write a small redirect script to take care of this simply and quickly.</p>\n\n<pre><code>&lt;?php \nheader( 'Location: http://guardthe.net/punbb/' ); \n?&gt;\n</code></pre>\n\n<p>Enter that as the only content in your index.php in your root directory, and any requests sent to that folder will then redirect the user to the forum.</p>\n"}, {'answer_id': 75214, 'author': 'Mr Shark', 'author_id': 6093, 'author_profile': 'https://Stackoverflow.com/users/6093', 'pm_score': 2, 'selected': False, 'text': '<p>Something like this in .htacces should do it:</p>\n\n<pre><code> RewriteEngine On\n RewriteRule ^/?$ /punbb/ [R=301,L]\n</code></pre>\n\n<p>The 301 return code is to mark the move as permanentm making it posible for the browser to update bookmarks.</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/75127', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']
75,134
<p>How do I have two effects in jQuery run in <code>sequence</code>, not simultaneously? Take this piece of code for example:</p> <pre><code>$("#show-projects").click(function() { $(".page:visible").fadeOut("normal"); $("#projects").fadeIn("normal"); }); </code></pre> <p>The <code>fadeOut</code> and the <code>fadeIn</code> run simultaneously, how do I make them run one after the other?</p>
[{'answer_id': 75194, 'author': 'neuroguy123', 'author_id': 12529, 'author_profile': 'https://Stackoverflow.com/users/12529', 'pm_score': 4, 'selected': False, 'text': '<p>What you want is a queue.</p>\n\n<p>Check out the reference page <a href="http://api.jquery.com/queue/" rel="nofollow noreferrer">http://api.jquery.com/queue/</a> for some working examples.</p>\n'}, {'answer_id': 75259, 'author': 'Jim', 'author_id': 8427, 'author_profile': 'https://Stackoverflow.com/users/8427', 'pm_score': 6, 'selected': True, 'text': '<p>You can supply a callback to the effects functions that run after the effect has completed.</p>\n\n<pre><code>$("#show-projects").click(function() {\n $(".page:visible").fadeOut("normal", function() {\n $("#projects").fadeIn("normal");\n });\n});\n</code></pre>\n'}, {'answer_id': 23672352, 'author': 'niall.campbell', 'author_id': 323722, 'author_profile': 'https://Stackoverflow.com/users/323722', 'pm_score': 0, 'selected': False, 'text': '<p>Does there have to be a target? surely you can use a random target to queue events sequentially so long as the target is constant...below I\'m using the parent of an animation target to store the queue.</p>\n\n<pre><code>//example of adding sequential effects through\n//event handlers and a jquery event trigger\njQuery( document ).unbind( "bk_prompt_collapse.slide_up" );\njQuery( document ).bind( "bk_prompt_collapse.slide_up" , function( e, j_obj ) {\n jQuery(j_obj).queue(function() {\n //running our timed effect\n jQuery(this).find(\'div\').slideUp(400);\n //adding a fill delay to the parent\n jQuery(this).delay(400).dequeue();\n });\n}); \n//the last action removes the content from the dom\n//if its in the queue then it will fire sequentially\njQuery( document ).unbind( "bk_prompt_collapse.last_action" );\njQuery( document ).bind( "bk_prompt_collapse.last_action" , function( e, j_obj ) {\n jQuery(j_obj).queue(function() {\n //Hot dog!!\n jQuery(this).remove().dequeue();\n });\n});\njQuery("tr.bk_removing_cart_row").trigger( \n "bk_prompt_collapse" , \n jQuery("tr.bk_removing_cart_row") \n);\n</code></pre>\n\n<p>Not sure if its possible but it seems like you could bind .dequeue() to fire when another jquery event fires, instead of firing inline in my example above? effectively halting an animation queue?</p>\n'}, {'answer_id': 26987154, 'author': 'brilliantairic', 'author_id': 586204, 'author_profile': 'https://Stackoverflow.com/users/586204', 'pm_score': 1, 'selected': False, 'text': '<pre><code>$( "#foo" ).fadeOut( 300 ).delay( 800 ).fadeIn( 400 );\n</code></pre>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/75134', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/6967/']
75,139
<p>Google custom search code is provided as a form tag. However, Asp.net only allows a single form tag on a page. What is the best way to implement their code so you can include it on an aspx page (say as part of a Masterpage or navigation element). </p>
[{'answer_id': 75234, 'author': 'Chris Van Opstal', 'author_id': 7264, 'author_profile': 'https://Stackoverflow.com/users/7264', 'pm_score': 3, 'selected': False, 'text': '<p>You can have multiple form tags on an ASP.NET page. The limitation is on server-side (runat="server") form tags. </p>\n\n<p>You can implement two form tags (or more) as long as only one has the runat="server" attribute and one is not contained in the other. Example:</p>\n\n<pre><code>&lt;body&gt;\n&lt;form action="http://www.google.com/cse" id="cse-search-box"&gt; ... &lt;/form&gt;\n&lt;form runat="server" id="aspNetform"&gt; ... &lt;/form&gt;\n&lt;body&gt;\n</code></pre>\n'}, {'answer_id': 75288, 'author': 'Eric Longman', 'author_id': 13282, 'author_profile': 'https://Stackoverflow.com/users/13282', 'pm_score': 2, 'selected': False, 'text': '<p>You may be able to have multiple form tags, but note that they cannot be nested. You\'ll run into all kinds of weirdness in that scenario (e.g., I\'ve seen cases where the opening tag for the nested form apparently gets ignored and then its closing tag winds up closing the "parent" form out). </p>\n'}, {'answer_id': 75380, 'author': 'Timothy Lee Russell', 'author_id': 12919, 'author_profile': 'https://Stackoverflow.com/users/12919', 'pm_score': 0, 'selected': False, 'text': '<p>You could use Javascript:</p>\n\n<pre><code>&lt;input name="Query" type="text" class="searchField" id="Query" value="Search" size="15" onfocus="if(this.value == \'Search\') { this.value = \'\'; }" onblur="if(this.value == \'\') { this.value = \'Search\'; }" onkeydown="var event = event || window.event; var key = event.which || event.keyCode; if(key==13) window.open(\'http://www.google.com/search?q=\' + getElementById(\'Query\').value ); " /&gt;&lt;input name="" type="button" class="searchButton" value="go" onclick="window.open(\'http://www.google.com/search?q=\' + getElementById(\'Query\').value );" /&gt;\n</code></pre>\n'}, {'answer_id': 767329, 'author': 'sean', 'author_id': 82371, 'author_profile': 'https://Stackoverflow.com/users/82371', 'pm_score': 1, 'selected': False, 'text': '<p>You\'ll need to remove the form tag and use javascript send the query. Have a look at \n<a href="http://my6solutions.com/post/2009/04/19/Fixing-Google-Custom-Search-nested-form-tags-in-asp-net-pages.aspx" rel="nofollow noreferrer">http://my6solutions.com/post/2009/04/19/Fixing-Google-Custom-Search-nested-form-tags-in-asp-net-pages.aspx</a></p>\n\n<p>I have included the before and after code as well. So you can see what I\'ve done to integrate it with blogengine .net.</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/75139', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']
75,145
<p>How to you find the URL that represents the documentation of a .NET framework method on the MSDN website?</p> <p>For example, I want to embed the URL for the .NET framework method into some comments in some code. The normal "mangled" URL that one gets searching MSDN isn't very friendly looking: <a href="http://msdn.microsoft.com/library/xd12z8ts.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/library/xd12z8ts.aspx</a>. Using a Google search URL isn't all that pretty looking either.</p> <p>What I really want a URL that can be embedded in comments that is plain and easy to read. For example,</p> <p>// blah blah blah. See http://&lt;....>/System.Byte.ToString for more information</p>
[{'answer_id': 75167, 'author': 'user7116', 'author_id': 7116, 'author_profile': 'https://Stackoverflow.com/users/7116', 'pm_score': 3, 'selected': False, 'text': '<p>A lot of the time you can merely append the lowercase namespace reference to the domain:</p>\n\n<pre><code>http://msdn.microsoft.com/en-us/library/system.windows.application_events.aspx\n</code></pre>\n\n<p>Moreover, for say the .Net 2.0 version (or any specific version) you can add "(VS.80)":</p>\n\n<pre><code>http://msdn.microsoft.com/en-us/library/system.windows.forms.button(VS.80).aspx\n</code></pre>\n\n<p>Other versions:</p>\n\n<ul>\n<li>.Net 1.1 -> (VS.71)</li>\n<li>.Net 2.0 -> (VS.80)</li>\n<li>.Net 3.0 -> (VS.85)</li>\n<li>.Net 3.5 -> (VS.90)</li>\n</ul>\n\n<p>Try it for a method (Control.IsInputChar) like so:\n<a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.control.isinputchar.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/system.windows.forms.control.isinputchar.aspx</a></p>\n'}, {'answer_id': 75177, 'author': 'Jeff Stong', 'author_id': 2459, 'author_profile': 'https://Stackoverflow.com/users/2459', 'pm_score': 3, 'selected': True, 'text': '<p>It\'s simple -- just add the name of the method to the end of <a href="http://msdn.microsoft.com//library/" rel="nofollow noreferrer">http://msdn.microsoft.com//library/</a>.</p>\n\n<p>For example, to find the URL for the System.Byte.ToString method go to <a href="http://msdn.microsoft.com//library/System.Byte.ToString" rel="nofollow noreferrer">http://msdn.microsoft.com//library/System.Byte.ToString</a></p>\n'}, {'answer_id': 75210, 'author': 'Shaun Austin', 'author_id': 1120, 'author_profile': 'https://Stackoverflow.com/users/1120', 'pm_score': 2, 'selected': False, 'text': "<p>It's probably quickest to just type it into Google in my experience. </p>\n\n<p>EDIT:</p>\n\n<p>Now that you've edited your post to clarify what you actually meant I would say that embedding URLs in your comments is nice but you really have no guarantees that either the mangled URL or the pretty one will exist in future.</p>\n"}, {'answer_id': 75540, 'author': 'Scott Gowell', 'author_id': 6943, 'author_profile': 'https://Stackoverflow.com/users/6943', 'pm_score': 0, 'selected': False, 'text': '<p><a href="http://labnol.blogspot.com/2006/09/learn-to-create-firefox-search-plugin.html" rel="nofollow noreferrer">Create a Search engine for MSDN Library in Firefox</a>\nLike this perhaps?</p>\n'}, {'answer_id': 75556, 'author': 'Mostlyharmless', 'author_id': 12881, 'author_profile': 'https://Stackoverflow.com/users/12881', 'pm_score': 1, 'selected': False, 'text': '<p>In my experiecne, googling it works faster than msdn search.</p>\n'}, {'answer_id': 78008, 'author': 'Aaron Powell', 'author_id': 11388, 'author_profile': 'https://Stackoverflow.com/users/11388', 'pm_score': 1, 'selected': False, 'text': '<p>I find that googling "msdn " does it.</p>\n\n<p>ie - msdn System.Web.UI.WebControls.Repeater.ItemDataBound</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/75145', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2459/']
75,153
<p>During a typical day programming, I implement functions in a way that I would like to remember. For instance, say I tuned a DB insert function that, when I come across the situation again, I want to find what I did to resuse. I need a place to keep the solution(what I did), and I need to find it somehow, which may be months or a year later. Using a mind map sort of idea, I was thinking about a personal wiki, but then I heard the stackoverflow podcast mention using this site for such a reason. Does anybody else keep track of slick things they've done so that they may find it sometime in the future. If so, what did you use, and in general, how do you use it?</p> <hr> <p>i like to personal blog idea and using the stack for it. i'll try the idea of posting at the stack and then answering it myself, with the benefit of other people potentially giving their opinion. As long a the stack will be around for a while :)</p>
[{'answer_id': 75172, 'author': 'Adrian Petrescu', 'author_id': 12171, 'author_profile': 'https://Stackoverflow.com/users/12171', 'pm_score': 0, 'selected': False, 'text': '<p>The technical term for what you are thinking of is "code snippets", and googling for that will find you many programs designed to store them for a variety of platforms, including entirely web-based ones such as <a href="http://snippets.dzone.com/" rel="nofollow noreferrer">this one</a>.</p>\n'}, {'answer_id': 75176, 'author': 'tante', 'author_id': 2065014, 'author_profile': 'https://Stackoverflow.com/users/2065014', 'pm_score': 1, 'selected': False, 'text': '<p>I use a personal Wiki, my del.icio.us bookmarks and my own blog for that. Usually my blog: When I learn something that I know I might stumble on again I write a short post in my blog.</p>\n'}, {'answer_id': 75183, 'author': 'Kevin Sheffield', 'author_id': 590, 'author_profile': 'https://Stackoverflow.com/users/590', 'pm_score': 0, 'selected': False, 'text': '<p>I set up dekiwiki on a server at work that my coworkers and I use for company specifics stuff but also for general programming tips that arise as well. </p>\n'}, {'answer_id': 75184, 'author': 'user13270', 'author_id': 13270, 'author_profile': 'https://Stackoverflow.com/users/13270', 'pm_score': 0, 'selected': False, 'text': '<p>A simple wiki, may be useful. See<a href="http://info.tikiwiki.org/tiki-index.php" rel="nofollow noreferrer">Tiki Wiki</a></p>\n'}, {'answer_id': 75188, 'author': 'David Smart', 'author_id': 9623, 'author_profile': 'https://Stackoverflow.com/users/9623', 'pm_score': 2, 'selected': False, 'text': '<p>I use <a href="http://www.neomem.org/" rel="nofollow noreferrer">neomem</a> all the time. I write notes to myself. Then I can later search for it.</p>\n'}, {'answer_id': 75216, 'author': 'Vaibhav', 'author_id': 380, 'author_profile': 'https://Stackoverflow.com/users/380', 'pm_score': 0, 'selected': False, 'text': '<p>I always put it on my <a href="http://blog.gadodia.net" rel="nofollow noreferrer">blog</a>. Not only am I able to get back to it later, there is also a chance that it can help someone else as well.</p>\n'}, {'answer_id': 75242, 'author': 'Mostlyharmless', 'author_id': 12881, 'author_profile': 'https://Stackoverflow.com/users/12881', 'pm_score': 1, 'selected': False, 'text': '<p>I use WikiDPad or Wiki-On-A-Stick. It works not only for code snippets but also to take notes, record typical problems you get and how to solve them and documentation. Take my word for it, it makes your job a LOT more easier if you have proper notes... and add the power of interlinking to it and you have a killer resource. I have very bad memory and taking notes has improved my performance by an order of magnitude. It also saves you from having to ask someone the same question twice or thrice. Also, if anyone asks the same question, you can just helpfully point them to the wiki and they can read it and add to it if they need to.</p>\n'}, {'answer_id': 75247, 'author': 'Arc the daft', 'author_id': 8615, 'author_profile': 'https://Stackoverflow.com/users/8615', 'pm_score': 0, 'selected': False, 'text': "<p>It's oldschool, but I keep notes in a notebook. Makes remembering solutions (or the problems that caused them) a bit easier. Usually I make 1-2 pages of notes a day.</p>\n\n<p>The digital equivalent of this would be keeping a private blog or journal. Easy enough to add a search program to help you find stuff. </p>\n\n<p>Worthwhile things that my boss might be interested in, like bugs and user calls all get entered into bug tracking software where it is more formally handled.</p>\n"}, {'answer_id': 75307, 'author': 'Kristopher Johnson', 'author_id': 1175, 'author_profile': 'https://Stackoverflow.com/users/1175', 'pm_score': 3, 'selected': True, 'text': "<p>Jeff Atwood recommends using Stack Overflow for this kind of thing. Post a question (your problem) and then post an answer (the solution you found). This lets you share the information with the world, and maybe get some valuable feedback or better solutions.</p>\n\n<p>(Wow, I got downvoted for repeating what Jeff Atwood said. I won't do that again, I promise.)</p>\n"}, {'answer_id': 75362, 'author': 'Justin Voss', 'author_id': 5616, 'author_profile': 'https://Stackoverflow.com/users/5616', 'pm_score': 0, 'selected': False, 'text': '<p>I use the excellent <a href="http://trac.edgewall.org/" rel="nofollow noreferrer">Trac project management system</a> for my personal projects, and I use it\'s wiki as a brainstorming and note-taking tool. And, because it also hooks into the Subversion repository and the bug tracking system, I can link from my notes right to a particular section of code or a bug report.</p>\n'}, {'answer_id': 75396, 'author': 'scubabbl', 'author_id': 9450, 'author_profile': 'https://Stackoverflow.com/users/9450', 'pm_score': 0, 'selected': False, 'text': '<p>I keep my personal projects on assembla. Wiki, Issue Tracking, Source Control... very useful.</p>\n'}, {'answer_id': 75553, 'author': 'Cheekysoft', 'author_id': 1820, 'author_profile': 'https://Stackoverflow.com/users/1820', 'pm_score': 2, 'selected': False, 'text': '<p>You may find these questions useful</p>\n\n<ul>\n<li><a href="https://stackoverflow.com/questions/4101/where-do-you-store-your-code-snippets#4137">Where do you store your code snippets?</a></li>\n<li><a href="https://stackoverflow.com/questions/17770/tracking-useful-information">Tracking useful information</a></li>\n<li><a href="https://stackoverflow.com/questions/53881/what-is-your-preferred-site-for-code-snippets">What is you preferred site for code snippets?</a></li>\n</ul>\n'}, {'answer_id': 75678, 'author': 'Jonathan Arkell', 'author_id': 11052, 'author_profile': 'https://Stackoverflow.com/users/11052', 'pm_score': 0, 'selected': False, 'text': "<p>Check to see if your editor has some kind of annotations feature. Ideally you could link a particular location in code with a small note, and store it in a centralized place. If it doesn't, that kind of plugin wouldn't be too hard to build, your biggest hurdle is going to be how to link the piece of code to a file (due to the volatile nature of code) and even that one isn't insurmountable.</p>\n"}]
2008/09/16
['https://Stackoverflow.com/questions/75153', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13143/']
75,156
<p>This is a shared hosting environment. I control the server, but not necessarily the content. I've got a client with a Perl script that seems to run out of control every now and then and suck down 50% of the processor until the process is killed.</p> <p>With ASP scripts, I'm able to restrict the amount of time the script can run, and IIS will simply shut it down after, say, 90 seconds. This doesn't work for Perl scripts, since it's running as a cgi process (and actually launches an external process to execute the script). </p> <p>Similarly, techniques that look for excess resource consumption in a worker process will likely not see this, since the resource that's being consumed (the processor) is being chewed up by a child process rather than the WP itself.</p> <p>Is there a way to make IIS abort a Perl script (or other cgi-type process) that's running too long? How??</p>
[{'answer_id': 75875, 'author': 'arclight', 'author_id': 13366, 'author_profile': 'https://Stackoverflow.com/users/13366', 'pm_score': 1, 'selected': False, 'text': '<p>On a UNIX-style system, I would use a signal handler trapping ALRM events, then use the alarm function to start a timer before starting an action that I expected might timeout. If the action completed, I\'d use alarm(0) to turn off the alarm and exit normally, otherwise the signal handler should pick it up to close everything up gracefully.</p>\n\n<p>I have not worked with perl on Windows in a while and while Windows is somewhat POSIXy, I cannot guarantee this will work; you\'ll have to check the perl documentation to see if or to what extent signals are supported on your platform.</p>\n\n<p>More detailed information on signal handling and this sort of self-destruct programming using alarm() can be found in the Perl Cookbook. Here\'s a brief example lifted from another post and modified a little:</p>\n\n<pre><code>eval {\n # Create signal handler and make it local so it falls out of scope\n # outside the eval block\n local $SIG{ALRM} = sub {\n print "Print this if we time out, then die.\\n";\n die "alarm\\n";\n };\n\n # Set the alarm, take your chance running the routine, and turn off\n # the alarm if it completes.\n alarm(90);\n routine_that_might_take_a_while();\n alarm(0);\n};\n</code></pre>\n'}, {'answer_id': 76657, 'author': 'piCookie', 'author_id': 8763, 'author_profile': 'https://Stackoverflow.com/users/8763', 'pm_score': 0, 'selected': False, 'text': '<p>Googling for "iis cpu limit" gives these hits: </p>\n\n<p><a href="http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/38fb0130-b14b-48d5-a0a2-05ca131cf4f2.mspx?mfr=true" rel="nofollow noreferrer">http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/38fb0130-b14b-48d5-a0a2-05ca131cf4f2.mspx?mfr=true</a></p>\n\n<p>"The CPU monitoring feature monitors and automatically shuts down worker processes that consume large amounts of CPU time. CPU monitoring is enabled for individual application pools."</p>\n\n<p><a href="http://technet.microsoft.com/en-us/library/cc728189.aspx" rel="nofollow noreferrer">http://technet.microsoft.com/en-us/library/cc728189.aspx</a></p>\n\n<p>"By using CPU monitoring, you can monitor worker processes for CPU usage and optionally shut down the worker processes that consume large amounts of CPU time. CPU monitoring is only available in worker process isolation mode."</p>\n'}, {'answer_id': 76723, 'author': 'jwmiller5', 'author_id': 7824, 'author_profile': 'https://Stackoverflow.com/users/7824', 'pm_score': 1, 'selected': False, 'text': '<p>The ASP script timeout applies to all scripting languages. If the script is running in an ASP page, the script timeout will close the offending page.</p>\n'}, {'answer_id': 155999, 'author': 'Eric Longman', 'author_id': 13282, 'author_profile': 'https://Stackoverflow.com/users/13282', 'pm_score': 1, 'selected': False, 'text': '<p>An update on this one...</p>\n\n<p>It turns out that this particular script apparently is a little buggy, and that the Googlebot has the uncanny ability to "press it\'s buttons" and drive it crazy. The script is an older, commercial application that does calendaring. Apparently, it displays links for "next month" and "previous month", and if you follow the "next month" too many times, you\'ll fall off a cliff. The resulting page, however, still includes a "next month" link. Googlebot would continuously beat the script to death and chew up the processor.</p>\n\n<p>Curiously, adding a robots.txt with Disallow: / didn\'t solve the problem. Either the Googlebot had already gotten ahold of the script and wouldn\'t let loose, or else it simply was disregarding the robots.txt.</p>\n\n<p>Anyway, Microsoft\'s Process Explorer (<a href="http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx" rel="nofollow noreferrer">http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx</a>) was a huge help, as it allowed me to see the environment for the perl.exe process in more detail, and I was able to determine from it that it was the Googlebot causing my problems.</p>\n\n<p>Once I knew that (and determined that robots.txt wouldn\'t solve the problem), I was able to use IIS directly to block all traffic to this site from *.googlebot.com, which worked well in this case, since we don\'t care if Google indexes this content.</p>\n\n<p>Thanks much for the other ideas that everyone posted!</p>\n\n<p>Eric Longman</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/75156', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13282/']
75,159
<p>I need to provide statistics on how many lines of code <code>(LOC)</code> associated with a system. The application part is easy but I need to also include any code residing within the SQL Server database. This would apply to stored procedures, functions, triggers, etc. </p> <p>How can I easily get that info? Can it be done (accurately) with <strong>TSQL</strong> by querying the system <code>tables\sprocs</code>, etc?</p>
[{'answer_id': 75190, 'author': 'Mitchel Sellers', 'author_id': 13279, 'author_profile': 'https://Stackoverflow.com/users/13279', 'pm_score': 1, 'selected': False, 'text': '<p>Personally you might just script the objects to file using SQL Server Management tools, it will get a few extras in there for the checks to do the drop first incase the object exists.</p>\n'}, {'answer_id': 75412, 'author': 'Chris Bilson', 'author_id': 12934, 'author_profile': 'https://Stackoverflow.com/users/12934', 'pm_score': 2, 'selected': False, 'text': '<p>Just select all the text from syscomments and count how many lines you have. The text column is text, which you can\'t really see in Management studio, so I would write a program or power shell script like this:</p>\n\n<pre><code>$conn = new-object System.Data.SqlClient.SqlConnection("Server=server;Database=database;Integrated Security=SSPI")\n$cmd = new-object System.Data.SqlClient.SqlCommand("select text from syscomments", $conn)\n$conn.Open()\n$reader = $cmd.ExecuteReader()\n\n$reader.Read() | out-null\n$reader.GetString(0) | clip\n$reader.Close()\n$conn.Close()\n</code></pre>\n\n<p>Paste into an editor that has a line count, and you\'re done.</p>\n'}, {'answer_id': 83666, 'author': 'ninegrid', 'author_id': 13661, 'author_profile': 'https://Stackoverflow.com/users/13661', 'pm_score': 4, 'selected': True, 'text': '<p>In Management Studio, right click the database you want a line count for... select Tasks -> Generate Scripts, you can select script options in the Scripts Wizard to include or exclude objects, when you have it set the way you like it can generate to a new query window </p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/75159', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4872/']
75,175
<p>Is it possible to create an instance of a generic type in Java? I'm thinking based on what I've seen that the answer is <code>no</code> (<em>due to type erasure</em>), but I'd be interested if anyone can see something I'm missing:</p> <pre><code>class SomeContainer&lt;E&gt; { E createContents() { return what??? } } </code></pre> <p>EDIT: It turns out that <a href="http://www.artima.com/weblogs/viewpost.jsp?thread=208860" rel="noreferrer">Super Type Tokens</a> could be used to resolve my issue, but it requires a lot of reflection-based code, as some of the answers below have indicated.</p> <p>I'll leave this open for a little while to see if anyone comes up with anything dramatically different than Ian Robertson's <a href="http://www.artima.com/weblogs/viewpost.jsp?thread=208860" rel="noreferrer">Artima Article</a>.</p>
[{'answer_id': 75201, 'author': 'Adam Rosenfield', 'author_id': 9530, 'author_profile': 'https://Stackoverflow.com/users/9530', 'pm_score': 0, 'selected': False, 'text': "<p>As you said, you can't really do it because of type erasure. You can sort of do it using reflection, but it requires a lot of code and lot of error handling.</p>\n"}, {'answer_id': 75254, 'author': 'Justin Rudd', 'author_id': 12968, 'author_profile': 'https://Stackoverflow.com/users/12968', 'pm_score': 9, 'selected': False, 'text': "<p>You are correct. You can't do <code>new E()</code>. But you can change it to</p>\n\n<pre><code>private static class SomeContainer&lt;E&gt; {\n E createContents(Class&lt;E&gt; clazz) {\n return clazz.newInstance();\n }\n}\n</code></pre>\n\n<p>It's a pain. But it works. Wrapping it in the factory pattern makes it a little more tolerable.</p>\n"}, {'answer_id': 75313, 'author': 'Mike Stone', 'author_id': 122, 'author_profile': 'https://Stackoverflow.com/users/122', 'pm_score': 3, 'selected': False, 'text': '<p>Here is an option I came up with, it may help:</p>\n\n<pre><code>public static class Container&lt;E&gt; {\n private Class&lt;E&gt; clazz;\n\n public Container(Class&lt;E&gt; clazz) {\n this.clazz = clazz;\n }\n\n public E createContents() throws Exception {\n return clazz.newInstance();\n }\n}\n</code></pre>\n\n<p>EDIT: Alternatively you can use this constructor (but it requires an instance of E):</p>\n\n<pre><code>@SuppressWarnings("unchecked")\npublic Container(E instance) {\n this.clazz = (Class&lt;E&gt;) instance.getClass();\n}\n</code></pre>\n'}, {'answer_id': 75345, 'author': 'noah', 'author_id': 12034, 'author_profile': 'https://Stackoverflow.com/users/12034', 'pm_score': 7, 'selected': False, 'text': "<p>I don't know if this helps, but when you subclass (including anonymously) a generic type, the type information is available via reflection. e.g.,</p>\n<pre><code>public abstract class Foo&lt;E&gt; {\n\n public E instance; \n\n public Foo() throws Exception {\n instance = ((Class)((ParameterizedType)this.getClass().\n getGenericSuperclass()).getActualTypeArguments()[0]).newInstance();\n ...\n }\n\n}\n</code></pre>\n<p>So, when you subclass Foo, you get an instance of Bar e.g.,</p>\n<pre><code>// notice that this in anonymous subclass of Foo\nassert( new Foo&lt;Bar&gt;() {}.instance instanceof Bar );\n</code></pre>\n<p>But it's a lot of work, and only works for subclasses. Can be handy though.</p>\n"}, {'answer_id': 75528, 'author': 'Tom Hawtin - tackline', 'author_id': 4725, 'author_profile': 'https://Stackoverflow.com/users/4725', 'pm_score': 6, 'selected': False, 'text': "<p>You'll need some kind of abstract factory of one sort or another to pass the buck to:</p>\n\n<pre><code>interface Factory&lt;E&gt; {\n E create();\n}\n\nclass SomeContainer&lt;E&gt; {\n private final Factory&lt;E&gt; factory;\n SomeContainer(Factory&lt;E&gt; factory) {\n this.factory = factory;\n }\n E createContents() {\n return factory.create();\n }\n}\n</code></pre>\n"}, {'answer_id': 75595, 'author': 'Pavel Feldman', 'author_id': 5507, 'author_profile': 'https://Stackoverflow.com/users/5507', 'pm_score': 0, 'selected': False, 'text': '<p>If you mean \n<code>new E()</code> \nthen it is impossible. And I would add that it is not always correct - how do you know if E has public no-args constructor?\nBut you can always delegate creation to some other class that knows how to create an instance - it can be <code>Class&lt;E&gt;</code> or your custom code like this</p>\n\n<pre><code>interface Factory&lt;E&gt;{\n E create();\n} \n\nclass IntegerFactory implements Factory&lt;Integer&gt;{ \n private static int i = 0; \n Integer create() { \n return i++; \n }\n}\n</code></pre>\n'}, {'answer_id': 87187, 'author': 'jb.', 'author_id': 7918, 'author_profile': 'https://Stackoverflow.com/users/7918', 'pm_score': 3, 'selected': False, 'text': '<p>If you want not to type class name twice during instantiation like in:</p>\n\n<pre><code>new SomeContainer&lt;SomeType&gt;(SomeType.class);\n</code></pre>\n\n<p>You can use factory method:</p>\n\n<pre><code>&lt;E&gt; SomeContainer&lt;E&gt; createContainer(Class&lt;E&gt; class); \n</code></pre>\n\n<p>Like in:</p>\n\n<pre><code>public class Container&lt;E&gt; {\n\n public static &lt;E&gt; Container&lt;E&gt; create(Class&lt;E&gt; c) {\n return new Container&lt;E&gt;(c);\n }\n\n Class&lt;E&gt; c;\n\n public Container(Class&lt;E&gt; c) {\n super();\n this.c = c;\n }\n\n public E createInstance()\n throws InstantiationException,\n IllegalAccessException {\n return c.newInstance();\n }\n\n}\n</code></pre>\n'}, {'answer_id': 376216, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': False, 'text': '<p>You can use:</p>\n\n<pre><code>Class.forName(String).getConstructor(arguments types).newInstance(arguments)\n</code></pre>\n\n<p>But you need to supply the exact class name, including packages, eg. <code>java.io.FileInputStream</code>. I used this to create a math expressions parser.</p>\n'}, {'answer_id': 3635805, 'author': 'Lars Bohl', 'author_id': 438960, 'author_profile': 'https://Stackoverflow.com/users/438960', 'pm_score': 5, 'selected': False, 'text': '<pre><code>package org.foo.com;\n\nimport java.lang.reflect.ParameterizedType;\nimport java.lang.reflect.Type;\n\n/**\n * Basically the same answer as noah\'s.\n */\npublic class Home&lt;E&gt;\n{\n\n @SuppressWarnings ("unchecked")\n public Class&lt;E&gt; getTypeParameterClass()\n {\n Type type = getClass().getGenericSuperclass();\n ParameterizedType paramType = (ParameterizedType) type;\n return (Class&lt;E&gt;) paramType.getActualTypeArguments()[0];\n }\n\n private static class StringHome extends Home&lt;String&gt;\n {\n }\n\n private static class StringBuilderHome extends Home&lt;StringBuilder&gt;\n {\n }\n\n private static class StringBufferHome extends Home&lt;StringBuffer&gt;\n {\n } \n\n /**\n * This prints "String", "StringBuilder" and "StringBuffer"\n */\n public static void main(String[] args) throws InstantiationException, IllegalAccessException\n {\n Object object0 = new StringHome().getTypeParameterClass().newInstance();\n Object object1 = new StringBuilderHome().getTypeParameterClass().newInstance();\n Object object2 = new StringBufferHome().getTypeParameterClass().newInstance();\n System.out.println(object0.getClass().getSimpleName());\n System.out.println(object1.getClass().getSimpleName());\n System.out.println(object2.getClass().getSimpleName());\n }\n\n}\n</code></pre>\n'}, {'answer_id': 5389482, 'author': 'Rachid', 'author_id': 670960, 'author_profile': 'https://Stackoverflow.com/users/670960', 'pm_score': 0, 'selected': False, 'text': '<pre><code>return (E)((Class)((ParameterizedType)this.getClass().getGenericSuperclass()).getActualTypeArguments()[0]).newInstance();\n</code></pre>\n'}, {'answer_id': 10042797, 'author': 'Bogdan Veliscu', 'author_id': 818753, 'author_profile': 'https://Stackoverflow.com/users/818753', 'pm_score': 0, 'selected': False, 'text': '<p>You can achieve this with the following snippet:</p>\n\n<pre><code>import java.lang.reflect.ParameterizedType;\n\npublic class SomeContainer&lt;E&gt; {\n E createContents() throws InstantiationException, IllegalAccessException {\n ParameterizedType genericSuperclass = (ParameterizedType)\n getClass().getGenericSuperclass();\n @SuppressWarnings("unchecked")\n Class&lt;E&gt; clazz = (Class&lt;E&gt;)\n genericSuperclass.getActualTypeArguments()[0];\n return clazz.newInstance();\n }\n public static void main( String[] args ) throws Throwable {\n SomeContainer&lt; Long &gt; scl = new SomeContainer&lt;&gt;();\n Long l = scl.createContents();\n System.out.println( l );\n }\n}\n</code></pre>\n'}, {'answer_id': 12407106, 'author': 'Sergiy Sokolenko', 'author_id': 131337, 'author_profile': 'https://Stackoverflow.com/users/131337', 'pm_score': 4, 'selected': False, 'text': '<p>From <a href="http://docs.oracle.com/javase/tutorial/java/generics/restrictions.html" rel="nofollow noreferrer">Java Tutorial - Restrictions on Generics</a>:</p>\n<p><strong><a href="http://docs.oracle.com/javase/tutorial/java/generics/restrictions.html#createObjects" rel="nofollow noreferrer">Cannot Create Instances of Type Parameters</a></strong></p>\n<p>You cannot create an instance of a type parameter. For example, the following code causes a compile-time error:</p>\n<pre><code>public static &lt;E&gt; void append(List&lt;E&gt; list) {\n E elem = new E(); // compile-time error\n list.add(elem);\n}\n</code></pre>\n<p>As a workaround, you can create an object of a type parameter through reflection:</p>\n<pre><code>public static &lt;E&gt; void append(List&lt;E&gt; list, Class&lt;E&gt; cls) throws Exception {\n E elem = cls.getDeclaredConstructor().newInstance(); // OK\n list.add(elem);\n}\n</code></pre>\n<p>You can invoke the append method as follows:</p>\n<pre><code>List&lt;String&gt; ls = new ArrayList&lt;&gt;();\nappend(ls, String.class);\n</code></pre>\n'}, {'answer_id': 14146479, 'author': 'Luigi R. Viggiano', 'author_id': 258289, 'author_profile': 'https://Stackoverflow.com/users/258289', 'pm_score': 2, 'selected': False, 'text': '<p>I thought I could do that, but quite disappointed: it doesn\'t work, but I think it still worths sharing. </p>\n\n<p>Maybe someone can correct:</p>\n\n<pre><code>import java.lang.reflect.InvocationHandler;\nimport java.lang.reflect.Method;\nimport java.lang.reflect.Proxy;\n\ninterface SomeContainer&lt;E&gt; {\n E createContents();\n}\n\npublic class Main {\n\n @SuppressWarnings("unchecked")\n public static &lt;E&gt; SomeContainer&lt;E&gt; createSomeContainer() {\n return (SomeContainer&lt;E&gt;) Proxy.newProxyInstance(Main.class.getClassLoader(),\n new Class[]{ SomeContainer.class }, new InvocationHandler() {\n @Override\n public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {\n Class&lt;?&gt; returnType = method.getReturnType();\n return returnType.newInstance();\n }\n });\n }\n\n public static void main(String[] args) {\n SomeContainer&lt;String&gt; container = createSomeContainer();\n\n [*] System.out.println("String created: [" +container.createContents()+"]");\n\n }\n}\n</code></pre>\n\n<p>It produces:</p>\n\n<pre><code>Exception in thread "main" java.lang.ClassCastException: java.lang.Object cannot be cast to java.lang.String\n at Main.main(Main.java:26)\n at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)\n at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n at java.lang.reflect.Method.invoke(Method.java:601)\n at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)\n</code></pre>\n\n<p>Line 26 is the one with the <code>[*]</code>.</p>\n\n<p>The only viable solution is the one by @JustinRudd</p>\n'}, {'answer_id': 14191442, 'author': 'R2D2M2', 'author_id': 1949703, 'author_profile': 'https://Stackoverflow.com/users/1949703', 'pm_score': 5, 'selected': False, 'text': "<p>If you need a new instance of a type argument inside a generic class then make your constructors demand its class...</p>\n\n<pre><code>public final class Foo&lt;T&gt; {\n\n private Class&lt;T&gt; typeArgumentClass;\n\n public Foo(Class&lt;T&gt; typeArgumentClass) {\n\n this.typeArgumentClass = typeArgumentClass;\n }\n\n public void doSomethingThatRequiresNewT() throws Exception {\n\n T myNewT = typeArgumentClass.newInstance();\n ...\n }\n}\n</code></pre>\n\n<p>Usage:</p>\n\n<pre><code>Foo&lt;Bar&gt; barFoo = new Foo&lt;Bar&gt;(Bar.class);\nFoo&lt;Etc&gt; etcFoo = new Foo&lt;Etc&gt;(Etc.class);\n</code></pre>\n\n<p>Pros:</p>\n\n<ul>\n<li>Much simpler (and less problematic) than Robertson's Super Type Token (STT) approach.</li>\n<li>Much more efficient than the STT approach (which will eat your cellphone for breakfast).</li>\n</ul>\n\n<p>Cons:</p>\n\n<ul>\n<li>Can't pass Class to a default constructor (which is why Foo is final). If you really do need a default constructor you can always add a setter method but then you must remember to give her a call later.</li>\n<li>Robertson's objection... More Bars than a black sheep (although specifying the type argument class one more time won't exactly kill you). And contrary to Robertson's claims this does not violate the DRY principal anyway because the compiler will ensure type correctness.</li>\n<li>Not entirely <code>Foo&lt;L&gt;</code>proof. For starters... <code>newInstance()</code> will throw a wobbler if the type argument class does not have a default constructor. This does apply to all known solutions though anyway.</li>\n<li>Lacks the total encapsulation of the STT approach. Not a big deal though (considering the outrageous performance overhead of STT).</li>\n</ul>\n"}, {'answer_id': 21553287, 'author': 'Roald', 'author_id': 2344378, 'author_profile': 'https://Stackoverflow.com/users/2344378', 'pm_score': -1, 'selected': False, 'text': '<p>You can with a classloader and the class name, eventually some parameters.</p>\n\n<pre><code>final ClassLoader classLoader = ...\nfinal Class&lt;?&gt; aClass = classLoader.loadClass("java.lang.Integer");\nfinal Constructor&lt;?&gt; constructor = aClass.getConstructor(int.class);\nfinal Object o = constructor.newInstance(123);\nSystem.out.println("o = " + o);\n</code></pre>\n'}, {'answer_id': 21716855, 'author': 'Ira', 'author_id': 3299647, 'author_profile': 'https://Stackoverflow.com/users/3299647', 'pm_score': 3, 'selected': False, 'text': "<p>When you are working with E at compile time you don't really care the actual generic type &quot;E&quot; (either you use reflection or work with base class of generic type) so let the subclass provide instance of E.</p>\n<pre><code>abstract class SomeContainer&lt;E&gt;\n{\n abstract protected E createContents();\n public void doWork(){\n E obj = createContents();\n // Do the work with E \n }\n}\n\nclass BlackContainer extends SomeContainer&lt;Black&gt;{\n protected Black createContents() {\n return new Black();\n }\n}\n</code></pre>\n"}, {'answer_id': 25195050, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 5, 'selected': False, 'text': '<p>You can do this now and it doesn\'t require a bunch of reflection code.</p>\n\n<pre><code>import com.google.common.reflect.TypeToken;\n\npublic class Q26289147\n{\n public static void main(final String[] args) throws IllegalAccessException, InstantiationException\n {\n final StrawManParameterizedClass&lt;String&gt; smpc = new StrawManParameterizedClass&lt;String&gt;() {};\n final String string = (String) smpc.type.getRawType().newInstance();\n System.out.format("string = \\"%s\\"",string);\n }\n\n static abstract class StrawManParameterizedClass&lt;T&gt;\n {\n final TypeToken&lt;T&gt; type = new TypeToken&lt;T&gt;(getClass()) {};\n }\n}\n</code></pre>\n\n<p>Of course if you need to call the constructor that will require some reflection, but that is very well documented, this trick isn\'t!</p>\n\n<p>Here is the <a href="https://google.github.io/guava/releases/19.0/api/docs/com/google/common/reflect/TypeToken.html" rel="noreferrer">JavaDoc for TypeToken</a>.</p>\n'}, {'answer_id': 26796874, 'author': 'Amio.io', 'author_id': 1075289, 'author_profile': 'https://Stackoverflow.com/users/1075289', 'pm_score': 2, 'selected': False, 'text': "<p>An imporovement of @Noah's answer. </p>\n\n<p><strong>Reason for Change</strong></p>\n\n<p><strong>a]</strong> Is safer if more then 1 generic type is used in case you changed the order.</p>\n\n<p><strong>b]</strong> A class generic type signature changes from time to time so that you will not be surprised by unexplained exceptions in the runtime.</p>\n\n<p><strong>Robust Code</strong></p>\n\n<pre><code>public abstract class Clazz&lt;P extends Params, M extends Model&gt; {\n\n protected M model;\n\n protected void createModel() {\n Type[] typeArguments = ((ParameterizedType) this.getClass().getGenericSuperclass()).getActualTypeArguments();\n for (Type type : typeArguments) {\n if ((type instanceof Class) &amp;&amp; (Model.class.isAssignableFrom((Class) type))) {\n try {\n model = ((Class&lt;M&gt;) type).newInstance();\n } catch (InstantiationException | IllegalAccessException e) {\n throw new RuntimeException(e);\n }\n }\n }\n}\n</code></pre>\n\n<p>Or use the one liner</p>\n\n<p><strong>One Line Code</strong></p>\n\n<pre><code>model = ((Class&lt;M&gt;) ((ParameterizedType) this.getClass().getGenericSuperclass()).getActualTypeArguments()[1]).newInstance();\n</code></pre>\n"}, {'answer_id': 29680588, 'author': 'Ingo', 'author_id': 86604, 'author_profile': 'https://Stackoverflow.com/users/86604', 'pm_score': 4, 'selected': False, 'text': '<p>Think about a more functional approach: instead of creating some E out of nothing (which is clearly a code smell), pass a function that knows how to create one, i.e.</p>\n\n<pre><code>E createContents(Callable&lt;E&gt; makeone) {\n return makeone.call(); // most simple case clearly not that useful\n}\n</code></pre>\n'}, {'answer_id': 35315432, 'author': 'Neepsnikeep', 'author_id': 5507619, 'author_profile': 'https://Stackoverflow.com/users/5507619', 'pm_score': 3, 'selected': False, 'text': '<p>Java unfortunatly does not allow what you want to do. See the <a href="http://docs.oracle.com/javase/tutorial/java/generics/restrictions.html#createObjects" rel="nofollow noreferrer">official workaround</a> :</p>\n\n<blockquote>\n <p>You cannot create an instance of a type parameter. For example, the following code causes a compile-time error:</p>\n</blockquote>\n\n<pre><code>public static &lt;E&gt; void append(List&lt;E&gt; list) {\n E elem = new E(); // compile-time error\n list.add(elem);\n}\n</code></pre>\n\n<blockquote>\n <p>As a workaround, you can create an object of a type parameter through reflection:</p>\n</blockquote>\n\n<pre><code>public static &lt;E&gt; void append(List&lt;E&gt; list, Class&lt;E&gt; cls) throws Exception {\n E elem = cls.newInstance(); // OK\n list.add(elem);\n}\n</code></pre>\n\n<blockquote>\n <p>You can invoke the append method as follows:</p>\n</blockquote>\n\n<pre><code>List&lt;String&gt; ls = new ArrayList&lt;&gt;();\nappend(ls, String.class);\n</code></pre>\n'}, {'answer_id': 36315051, 'author': 'Daniel Pryden', 'author_id': 128397, 'author_profile': 'https://Stackoverflow.com/users/128397', 'pm_score': 7, 'selected': False, 'text': '<p>In Java 8 you can use the <a href="https://docs.oracle.com/javase/8/docs/api/java/util/function/Supplier.html" rel="noreferrer"><code>Supplier</code></a> functional interface to achieve this pretty easily:</p>\n\n<pre><code>class SomeContainer&lt;E&gt; {\n private Supplier&lt;E&gt; supplier;\n\n SomeContainer(Supplier&lt;E&gt; supplier) {\n this.supplier = supplier;\n }\n\n E createContents() {\n return supplier.get();\n }\n}\n</code></pre>\n\n<p>You would construct this class like this:</p>\n\n<pre><code>SomeContainer&lt;String&gt; stringContainer = new SomeContainer&lt;&gt;(String::new);\n</code></pre>\n\n<p>The syntax <code>String::new</code> on that line is a <a href="https://docs.oracle.com/javase/tutorial/java/javaOO/methodreferences.html" rel="noreferrer">constructor reference</a>.</p>\n\n<p>If your constructor takes arguments you can use a lambda expression instead:</p>\n\n<pre><code>SomeContainer&lt;BigInteger&gt; bigIntegerContainer\n = new SomeContainer&lt;&gt;(() -&gt; new BigInteger(1));\n</code></pre>\n'}, {'answer_id': 53955316, 'author': 'Alexandr', 'author_id': 511804, 'author_profile': 'https://Stackoverflow.com/users/511804', 'pm_score': 0, 'selected': False, 'text': '<p>Here is an improved solution, based on <code>ParameterizedType.getActualTypeArguments</code>, already mentioned by @noah, @Lars Bohl, and some others. </p>\n\n<p>First small improvement in the implementation. Factory should not return instance, but a type. As soon as you return instance using <code>Class.newInstance()</code> you reduce a scope of usage. Because only no-arguments constructors can be invoke like this. A better way is to return a type, and allow a client to choose, which constructor he wants to invoke:</p>\n\n<pre><code>public class TypeReference&lt;T&gt; {\n public Class&lt;T&gt; type(){\n try {\n ParameterizedType pt = (ParameterizedType) this.getClass().getGenericSuperclass();\n if (pt.getActualTypeArguments() == null || pt.getActualTypeArguments().length == 0){\n throw new IllegalStateException("Could not define type");\n }\n if (pt.getActualTypeArguments().length != 1){\n throw new IllegalStateException("More than one type has been found");\n }\n Type type = pt.getActualTypeArguments()[0];\n String typeAsString = type.getTypeName();\n return (Class&lt;T&gt;) Class.forName(typeAsString);\n\n } catch (Exception e){\n throw new IllegalStateException("Could not identify type", e);\n }\n\n }\n}\n</code></pre>\n\n<p>Here is a usage examples. @Lars Bohl has shown only a signe way to get reified geneneric via extension. @noah only via creating an instance with <code>{}</code>. Here are tests to demonstrate both cases:</p>\n\n<pre><code>import java.lang.reflect.Constructor;\n\npublic class TypeReferenceTest {\n\n private static final String NAME = "Peter";\n\n private static class Person{\n final String name;\n\n Person(String name) {\n this.name = name;\n }\n }\n\n @Test\n public void erased() {\n TypeReference&lt;Person&gt; p = new TypeReference&lt;&gt;();\n Assert.assertNotNull(p);\n try {\n p.type();\n Assert.fail();\n } catch (Exception e){\n Assert.assertEquals("Could not identify type", e.getMessage());\n }\n }\n\n @Test\n public void reified() throws Exception {\n TypeReference&lt;Person&gt; p = new TypeReference&lt;Person&gt;(){};\n Assert.assertNotNull(p);\n Assert.assertEquals(Person.class.getName(), p.type().getName());\n Constructor ctor = p.type().getDeclaredConstructor(NAME.getClass());\n Assert.assertNotNull(ctor);\n Person person = (Person) ctor.newInstance(NAME);\n Assert.assertEquals(NAME, person.name);\n }\n\n static class TypeReferencePerson extends TypeReference&lt;Person&gt;{}\n\n @Test\n public void reifiedExtenension() throws Exception {\n TypeReference&lt;Person&gt; p = new TypeReferencePerson();\n Assert.assertNotNull(p);\n Assert.assertEquals(Person.class.getName(), p.type().getName());\n Constructor ctor = p.type().getDeclaredConstructor(NAME.getClass());\n Assert.assertNotNull(ctor);\n Person person = (Person) ctor.newInstance(NAME);\n Assert.assertEquals(NAME, person.name);\n }\n}\n</code></pre>\n\n<p><strong>Note:</strong> you can force the clients of <code>TypeReference</code> always use <code>{}</code> when instance is created by making this class abstract: <code>public abstract class TypeReference&lt;T&gt;</code>. I\'ve not done it, only to show erased test case. </p>\n'}, {'answer_id': 54213575, 'author': 'Se Song', 'author_id': 3458608, 'author_profile': 'https://Stackoverflow.com/users/3458608', 'pm_score': 3, 'selected': False, 'text': "<p>Hope this's not too late to help!!!</p>\n<p>Java is type-safe, meaning that only Objects are able to create instances.</p>\n<p>In my case I cannot pass parameters to the <code>createContents</code> method. My solution is using extends unlike the answer below.</p>\n<pre><code>private static class SomeContainer&lt;E extends Object&gt; {\n E e;\n E createContents() throws Exception{\n return (E) e.getClass().getDeclaredConstructor().newInstance();\n }\n}\n</code></pre>\n<p>This is my example case in which I can't pass parameters.</p>\n<pre><code>public class SomeContainer&lt;E extends Object&gt; {\n E object;\n\n void resetObject throws Exception{\n object = (E) object.getClass().getDeclaredConstructor().newInstance();\n }\n}\n</code></pre>\n<p>Using reflection create run time error, if you extends your generic class with none object type. To extends your generic type to object convert this error to compile time error.</p>\n"}, {'answer_id': 57112253, 'author': 'Sudhanshu Jain', 'author_id': 6685277, 'author_profile': 'https://Stackoverflow.com/users/6685277', 'pm_score': 2, 'selected': False, 'text': '<p>what you can do is -</p>\n\n<ol>\n<li><p>First declare the variable of that generic class </p>\n\n<p>2.Then make a constructor of it and instantiate that object</p></li>\n<li><p>Then use it wherever you want to use it</p></li>\n</ol>\n\n<p>example-</p>\n\n<p>1 </p>\n\n<blockquote>\n <p><code>private Class&lt;E&gt; entity;</code></p>\n</blockquote>\n\n<p>2 </p>\n\n<pre><code>public xyzservice(Class&lt;E&gt; entity) {\n this.entity = entity;\n }\n\n\n\npublic E getEntity(Class&lt;E&gt; entity) throws InstantiationException, IllegalAccessException {\n return entity.newInstance();\n }\n</code></pre>\n\n<p>3.</p>\n\n<blockquote>\n <p>E e = getEntity(entity);</p>\n</blockquote>\n'}, {'answer_id': 57125467, 'author': 'cacheoff', 'author_id': 2549901, 'author_profile': 'https://Stackoverflow.com/users/2549901', 'pm_score': 2, 'selected': False, 'text': '<p>Use the <a href="https://static.javadoc.io/com.google.code.gson/gson/2.6.2/com/google/gson/reflect/TypeToken.html" rel="nofollow noreferrer"><code>TypeToken&lt;T&gt;</code></a> class:</p>\n\n<pre><code>public class MyClass&lt;T&gt; {\n public T doSomething() {\n return (T) new TypeToken&lt;T&gt;(){}.getRawType().newInstance();\n }\n}\n</code></pre>\n'}, {'answer_id': 67363847, 'author': 'Braian Coronel', 'author_id': 5279996, 'author_profile': 'https://Stackoverflow.com/users/5279996', 'pm_score': 0, 'selected': False, 'text': '<p>Note that a generic type in kotlin could come without a default constructor.</p>\n<pre><code> implementation(&quot;org.objenesis&quot;,&quot;objenesis&quot;, &quot;3.2&quot;)\n</code></pre>\n<hr />\n<pre><code> val fooType = Foo::class.java\n var instance: T = try {\n fooType.newInstance()\n } catch (e: InstantiationException) {\n// Use Objenesis because the fooType class has not a default constructor\n val objenesis: Objenesis = ObjenesisStd()\n objenesis.newInstance(fooType)\n }\n</code></pre>\n<ul>\n<li><a href="https://stackoverflow.com/q/4133709/5279996">Withou default constructor</a></li>\n<li><a href="http://objenesis.org/tutorial.html" rel="nofollow noreferrer">Objenesis</a></li>\n</ul>\n'}, {'answer_id': 68001457, 'author': 'michal.jakubeczy', 'author_id': 2470765, 'author_profile': 'https://Stackoverflow.com/users/2470765', 'pm_score': 0, 'selected': False, 'text': "<p>I was inspired with Ira's solution and slightly modified it.</p>\n<pre><code>abstract class SomeContainer&lt;E&gt;\n{\n protected E createContents() {\n throw new NotImplementedException();\n }\n\n public void doWork(){\n E obj = createContents();\n // Do the work with E \n }\n}\n\nclass BlackContainer extends SomeContainer&lt;Black&gt;{\n // this method is optional to implement in case you need it\n protected Black createContents() {\n return new Black();\n }\n}\n</code></pre>\n<p>In case you need <code>E</code> instance you can implement <code>createContents</code> method in your derived class (or leave it not implemented in case you don't need it.</p>\n"}]
2008/09/16
['https://Stackoverflow.com/questions/75175', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5309/']
75,180
<p>If you have a statically allocated array, the Visual Studio debugger can easily display all of the array elements. However, if you have an array allocated dynamically and pointed to by a pointer, it will only display the first element of the array when you click the + to expand it. Is there an easy way to tell the debugger, show me this data as an array of type Foo and size X?</p>
[{'answer_id': 75202, 'author': 'shoosh', 'author_id': 9611, 'author_profile': 'https://Stackoverflow.com/users/9611', 'pm_score': 9, 'selected': True, 'text': '<p>Yes, simple.\nsay you have</p>\n\n<pre><code>char *a = new char[10];\n</code></pre>\n\n<p>writing in the debugger:</p>\n\n<pre><code>a,10\n</code></pre>\n\n<p>would show you the content as if it were an array.</p>\n'}, {'answer_id': 75204, 'author': 'Drealmer', 'author_id': 12291, 'author_profile': 'https://Stackoverflow.com/users/12291', 'pm_score': 5, 'selected': False, 'text': '<p>In a watch window, add a comma after the name of the array, and the amount of items you want to be displayed.</p>\n'}, {'answer_id': 12477304, 'author': 'wog', 'author_id': 1022328, 'author_profile': 'https://Stackoverflow.com/users/1022328', 'pm_score': 0, 'selected': False, 'text': '<p>I haven\'t found a way to use this with a multidimensional array. But you can at least (if you know the index of your desired entry) add a watch to a specific value. Simply use the index-operator.</p>\n\n<p>For an Array named current, which has an Array named Attribs inside, which has an Array named Attrib inside, it should look like this if you like to have to position 26:</p>\n\n<pre><code>((*((*current).Attribs)).Attrib)[26]\n</code></pre>\n\n<p>You can also use an offset</p>\n\n<pre><code>((*((*current).Attribs)).Attrib)+25\n</code></pre>\n\n<p>will show ne "next" 25 elements. \n(I\'m using VS2008, this shows only 25 elements maximum).</p>\n'}, {'answer_id': 21000009, 'author': 'dabinsi', 'author_id': 3173933, 'author_profile': 'https://Stackoverflow.com/users/3173933', 'pm_score': 1, 'selected': False, 'text': '<p>For MFC arrays (CArray, CStringArray, ...)\nfollowing the next link in its Tip #4</p>\n\n<p><a href="http://www.codeproject.com/Articles/469416/10-More-Visual-Studio-Debugging-Tips-for-Native-De" rel="nofollow">http://www.codeproject.com/Articles/469416/10-More-Visual-Studio-Debugging-Tips-for-Native-De</a></p>\n\n<p>For example for "CArray pArray", add in the Watch windows</p>\n\n<pre><code> pArray.m_pData,5 \n</code></pre>\n\n<p>to see the first 5 elements .</p>\n\n<p>If pArray is a two dimensional CArray you can look at any of the elements of the second dimension using the next syntax:</p>\n\n<pre><code> pArray.m_pData[x].m_pData,y\n</code></pre>\n'}, {'answer_id': 22239703, 'author': 'gpliu', 'author_id': 337863, 'author_profile': 'https://Stackoverflow.com/users/337863', 'pm_score': 3, 'selected': False, 'text': "<p>a revisit:</p>\n\n<p>let's assume you have a below pointer:</p>\n\n<pre><code>double ** a; // assume 5*10\n</code></pre>\n\n<p>then you can write below in Visual Studio debug watch:</p>\n\n<pre><code>(double(*)[10]) a[0],5\n</code></pre>\n\n<p>which will cast it into an array like below, and you can view all contents in one go.</p>\n\n<pre><code>double[5][10] a;\n</code></pre>\n"}, {'answer_id': 25690207, 'author': 'Riaz Rizvi', 'author_id': 213307, 'author_profile': 'https://Stackoverflow.com/users/213307', 'pm_score': 5, 'selected': False, 'text': '<p>There are two methods to view data in an array m4x4:</p>\n\n<pre><code>float m4x4[16]={\n 1.f,0.f,0.f,0.f,\n 0.f,2.f,0.f,0.f,\n 0.f,0.f,3.f,0.f,\n 0.f,0.f,0.f,4.f\n};\n</code></pre>\n\n<p>One way is with a Watch window (Debug/Windows/Watch). Add watch =</p>\n\n<pre><code>m4x4,16\n</code></pre>\n\n<p>This displays data in a list:</p>\n\n<p><img src="https://i.stack.imgur.com/K54SJ.png" alt="enter image description here"></p>\n\n<p>Another way is with a Memory window (Debug/Windows/Memory). Specify a memory start address = </p>\n\n<pre><code>m4x4\n</code></pre>\n\n<p>This displays data in a table, which is better for two and three dimensional matrices:</p>\n\n<p><img src="https://i.stack.imgur.com/kBbEI.png" alt="enter image description here"></p>\n\n<p>Right-click on the Memory window to determine how the binary data is visualized. Choices are limited to integers, floats and some text encodings.</p>\n'}, {'answer_id': 28973224, 'author': 'Taylor Price', 'author_id': 3805, 'author_profile': 'https://Stackoverflow.com/users/3805', 'pm_score': 2, 'selected': False, 'text': '<p>Yet another way to do this is specified here in <a href="https://msdn.microsoft.com/en-us/library/75w45ekt.aspx" rel="nofollow">MSDN</a>.</p>\n\n<p>In short, you can display a character array as several types of string. If you\'ve got an array declared as:</p>\n\n<pre><code>char *a = new char[10];\n</code></pre>\n\n<p>You could print it as a unicode string in the watch window with the following:</p>\n\n<pre><code>a,su\n</code></pre>\n\n<p>See the tables on the MSDN page for all of the different conversions possible since there are quite a few. Many different string variants, variants to print individual items in the array, etc.</p>\n'}, {'answer_id': 31872247, 'author': 'Legolas', 'author_id': 109787, 'author_profile': 'https://Stackoverflow.com/users/109787', 'pm_score': 2, 'selected': False, 'text': '<p>You can find a list of many things you can do with variables in the watch window in this gem in the docs:\n<a href="https://msdn.microsoft.com/en-us/library/75w45ekt.aspx" rel="nofollow">https://msdn.microsoft.com/en-us/library/75w45ekt.aspx</a></p>\n\n<p>For a variable a, there are the things already mentioned in other answers like </p>\n\n<pre><code>a,10 \na,su \n</code></pre>\n\n<p>but there\'s a whole lot of other specifiers for format and size, like: </p>\n\n<pre><code>a,en (shows an enum value by name instead of the number)\na,mb (to show 1 line of \'memory\' view right there in the watch window)\n</code></pre>\n'}, {'answer_id': 31900913, 'author': 'vicky', 'author_id': 3922508, 'author_profile': 'https://Stackoverflow.com/users/3922508', 'pm_score': 3, 'selected': False, 'text': '<p>For,</p>\n\n<pre><code>int **a; //row x col\n</code></pre>\n\n<p>add this to watch</p>\n\n<pre><code>(int(**)[col])a,row\n</code></pre>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/75180', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/9530/']
75,181
<p>Here's a very simple Prototype example.</p> <p>All it does is, on window load, an ajax call which sticks some html into a div.</p> <pre class="lang-html prettyprint-override"><code>&lt;html&gt; &lt;head&gt; &lt;script type=&quot;text/javascript&quot; src=&quot;scriptaculous/lib/prototype.js&quot;&gt;&lt;/script&gt; &lt;script type=&quot;text/javascript&quot;&gt; Event.observe(window, 'load', function(){ new Ajax.Request('get-table.php', { method: 'get', onSuccess: function(response){ $('content').innerHTML = response.responseText; //At this call, the div has HTML in it click1(); }, onFailure: function(){ alert('Fail!'); } }); //At this call, the div is empty click1(); }); function click1(){if($('content').innerHTML){alert('Found content');}else{alert('Empty div');}} &lt;/script&gt; &lt;/head&gt; &lt;body&gt;&lt;div id=&quot;content&quot;&gt;&lt;/div&gt;&lt;/body&gt; &lt;/html&gt; </code></pre> <p>The thing that's confusing is the context in which Prototype understands that the div actually has stuff in it.</p> <p>If you look at the onSuccess part of the ajax call, you'll see that at that point $('content').innerHTML has stuff in it.</p> <p>However when I check $('content').innerHTML right after the ajax call, it appears to be empty.</p> <p>This has to be some fundamental misunderstanding on my part. Anyone care to explain it to me?</p> <hr /> <p><strong>Edit</strong><br /> I just want to clarify something. I realize that the Ajax call is asynchronous.</p> <p>Here's the actual order that things are being executed and why it's confusing to me:</p> <ol> <li>The page loads.</li> <li>The Ajax request to get-table.php is made.</li> <li>The call to click1() INSIDE onSuccess happens. I see an alert that the div has content.</li> <li>The call to click1() AFTER the Ajax call happens. I see an alert that the div is empty.</li> </ol> <p>So it's like the code is executing in the order it's written but the DOM is not updating in the same order.</p> <hr /> <p><strong>Edit 2</strong> So the short answer is that putting the code in onSuccess is the correct place.</p> <p>Another case to consider is the one where you do an Ajax call and then do another Ajax call from the onSuccess of the first call like this:</p> <pre class="lang-js prettyprint-override"><code>new Ajax.Request('foo.php',{ method: 'get', onSuccess: function(response){ doAnotherAjaxCall(); } }); function doAnotherAjaxCall(){ new Ajax.Request('foo.php',{ method: 'get', onSuccess: function(response){ //Anything that needs to happen AFTER the call to doAnotherAjaxCall() above //needs to happen here! } }); } </code></pre>
[{'answer_id': 75228, 'author': 'Jan Krüger', 'author_id': 12471, 'author_profile': 'https://Stackoverflow.com/users/12471', 'pm_score': 4, 'selected': True, 'text': '<p>The first letter of AJAX stands for "asynchronous". This means that the AJAX call is performed in the background, i.e. the AJAX request call <em>immediately returns</em>. This means that the code immediately after it is normally actually executed <em>before</em> the onSuccess handler gets called (and before the AJAX request has even finished).</p>\n\n<p>Taking into account your edited question: in some browsers (e.g. Firefox), alert boxes are not as modal as you might think. Asynchronous code may pop up an alert box even if another one is already open. In that case, the newer alert box (the one from the asynchronous code) gets displayed on top of the older one. This creates the illusion that the asynchronous code got executed first.</p>\n'}, {'answer_id': 75240, 'author': 'Lasar', 'author_id': 9438, 'author_profile': 'https://Stackoverflow.com/users/9438', 'pm_score': 0, 'selected': False, 'text': '<p>Without having tried your code: The AJAX call is executed asynchronously. Meaning that your Ajax.Request fires, then goes on to the click1() call that tells you the div is empty. At some point after that the Ajax request is finished and content is actually put into the div. At this point the onSuccess function is executed and you get the content you expected.</p>\n'}, {'answer_id': 75271, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': "<p>It's Ajax call, which is asynchronous. That means right after that request call, response hasn't come back yet, that's why $('content') is still empty.</p>\n"}, {'answer_id': 75486, 'author': 'Stimy', 'author_id': 8852, 'author_profile': 'https://Stackoverflow.com/users/8852', 'pm_score': 0, 'selected': False, 'text': '<p>The onSuccess element of the function call you are making to handle the AJAX call is executed at the time you receive a response from get-table.php. This is a separate Javascript function which you are telling the browser to call when you get an answer from get-table.php. The code below your AJAX.Request call is accessed as soon as the AJAX.Request call is made, but not necessarily before get-table.php is called. So yes I think there is a bit of a fundamental misunderstanding of how AJAX works, likely due to using a library to hide the details.</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/75181', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/305/']
75,182
<p>How can one detect being in a chroot jail without root privileges? Assume a standard BSD or Linux system. The best I came up with was to look at the inode value for "/" and to consider whether it is reasonably low, but I would like a more accurate method for detection.</p> <p><code>[edit 20080916 142430 EST]</code> Simply looking around the filesystem isn't sufficient, as it's not difficult to duplicate things like /boot and /dev to fool the jailed user.</p> <p><code>[edit 20080916 142950 EST]</code> For Linux systems, checking for unexpected values within /proc is reasonable, but what about systems that don't support /proc in the first place?</p>
[{'answer_id': 75310, 'author': 'sammyo', 'author_id': 10826, 'author_profile': 'https://Stackoverflow.com/users/10826', 'pm_score': 2, 'selected': False, 'text': "<p>Preventing stuff like that is the whole point. If it's your code that's supposed to run in the chroot, have it set a flag on startup. If you're hacking, hack: check for several common things in known locations, count the files in /etc, something in /dev. </p>\n"}, {'answer_id': 75390, 'author': 'SpoonMeiser', 'author_id': 1577190, 'author_profile': 'https://Stackoverflow.com/users/1577190', 'pm_score': 2, 'selected': False, 'text': "<p>I guess it depends why you might be in a chroot, and whether any effort has gone into disguising it.</p>\n\n<p>I'd check /proc, these files are automatically generated system information files. The kernel will populate these in the root filesystem, but it's possible that they don't exist in the chroot filesystem.</p>\n\n<p>If the root filesystem's /proc has been bound to /proc in the chroot, then it is likely that there are some discrepancies between that information and the chroot environment. Check /proc/mounts for example.</p>\n\n<p>Similrarly, check /sys.</p>\n"}, {'answer_id': 88716, 'author': 'user10392', 'author_id': 10392, 'author_profile': 'https://Stackoverflow.com/users/10392', 'pm_score': 5, 'selected': True, 'text': "<p>The inode for / will always be 2 if it's the root directory of an ext2/ext3/ext4 filesystem, but you may be chrooted inside a complete filesystem. If it's just chroot (and not some other virtualization), you could run mount and compare the mounted filesystems against what you see. Verify that every mount point has inode 2.</p>\n"}, {'answer_id': 215381, 'author': 'Joshua', 'author_id': 14768, 'author_profile': 'https://Stackoverflow.com/users/14768', 'pm_score': 2, 'selected': False, 'text': "<p>On BSD systems (check with uname -a), proc should always be present. Check if the dev/inode pair of /proc/1/exe (use stat on that path, it won't follow the symlink by text but by the underlying hook) matches /sbin/init.</p>\n\n<p>Checking the root for inode #2 is also a good one.</p>\n\n<p>On most other systems, a root user can find out much faster by attempting the fchdir root-breaking trick. If it goes anywhere you are in a chroot jail.</p>\n"}, {'answer_id': 8070267, 'author': "Gilles 'SO- stop being evil'", 'author_id': 387076, 'author_profile': 'https://Stackoverflow.com/users/387076', 'pm_score': 3, 'selected': False, 'text': '\n\n<p>On Linux with root permissions, test if the root directory of the init process is your root directory. Although <code>/proc/1/root</code> is always a symbolic link to <code>/</code>, following it leads to the “master” root directory (assuming the init process is not chrooted, but that\'s hardly ever done). If <code>/proc</code> isn\'t mounted, you can bet you\'re in a chroot.</p>\n\n<pre><code>[ "$(stat -c %d:%i /)" != "$(stat -c %d:%i /proc/1/root/.)" ]\n# With ash/bash/ksh/zsh\n! [ -x /proc/1/root/. ] || [ /proc/1/root/. -ef / ]\n</code></pre>\n\n<p>This is more precise than <a href="https://stackoverflow.com/questions/75182/detecting-a-chroot-jail-from-within/215381#215381">looking at <code>/proc/1/exe</code></a> because that could be different outside a chroot if <code>init</code> has been upgraded since the last boot or if the chroot is on the main root filesystem and <code>init</code> is hard linked in it.</p>\n\n<p>If you do not have root permissions, you can look at <code>/proc/1/mountinfo</code> and <code>/proc/$$/mountinfo</code> (briefly documented in <a href="http://www.kernel.org/doc/Documentation/filesystems/proc.txt" rel="nofollow noreferrer"><code>filesystems/proc.txt</code> in the Linux kernel documentation</a>). This file is world-readable and contains a lot of information about each mount point in the process\'s view of the filesystem. The paths in that file are restricted by the chroot affecting the reader process, if any. If the process reading <code>/proc/1/mountinfo</code> is chrooted into a filesystem that\'s different from the global root (assuming pid 1\'s root is the global root), then no entry for <code>/</code> appears in <code>/proc/1/mountinfo</code>. If the process reading <code>/proc/1/mountinfo</code> is chrooted to a directory on the global root filesystem, then an entry for <code>/</code> appears in <code>/proc/1/mountinfo</code>, but with a different mount id. Incidentally, the root field (<code>$4</code>) indicates where the chroot is in its master filesystem. Again, this is specific to Linux.</p>\n\n<pre><code>[ "$(awk \'$5=="/" {print $1}\' &lt;/proc/1/mountinfo)" != "$(awk \'$5=="/" {print $1}\' &lt;/proc/$$/mountinfo)" ]\n</code></pre>\n'}, {'answer_id': 17851543, 'author': 'Alex', 'author_id': 920842, 'author_profile': 'https://Stackoverflow.com/users/920842', 'pm_score': 0, 'selected': False, 'text': '<p>If you entered the chroot with schroot, then you can check the value of $debian_chroot.</p>\n'}, {'answer_id': 24245912, 'author': 'Jérôme Pouiller', 'author_id': 301717, 'author_profile': 'https://Stackoverflow.com/users/301717', 'pm_score': 3, 'selected': False, 'text': "<p>If you are not in a chroot and the root filesystem is ext2/ext3/ext4, the inode for / will always be 2. You may check that using</p>\n<pre><code>stat -c %i /\n</code></pre>\n<p>or</p>\n<pre><code>ls -id /\n</code></pre>\n<p>Interresting, but let's try to find path of chroot directory. Ask to <code>stat</code> on which device / is located:</p>\n<pre><code>stat -c %04D /\n</code></pre>\n<p>First byte is major of device and lest byte is minor. For example, 0802, means major 8, minor 1. If you check in /dev, you will see this device is /dev/sda2. If you are root you can directly create correspondong device in your chroot:</p>\n<pre><code>mknode /tmp/root_dev b 8 1\n</code></pre>\n<p>Now, let's find inode associated to our chroot. debugfs allows list contents of files using inode numbers. For exemple, <code>ls -id /</code> returned 923960:</p>\n<pre><code>sudo debugfs /tmp/root_dev -R 'ls &lt;923960&gt;'\n 923960 (12) . 915821 (32) .. 5636100 (12) var \n5636319 (12) lib 5636322 (12) usr 5636345 (12) tmp \n5636346 (12) sys 5636347 (12) sbin 5636348 (12) run \n5636349 (12) root 5636350 (12) proc 5636351 (12) mnt \n5636352 (12) home 5636353 (12) dev 5636354 (12) boot \n5636355 (12) bin 5636356 (12) etc 5638152 (16) selinux \n5769366 (12) srv 5769367 (12) opt 5769375 (3832) media \n</code></pre>\n<p>Interesting information is inode of <code>..</code> entry: 915821. I can ask its content:</p>\n<pre><code>sudo debugfs /tmp/root_dev -R 'ls &lt;915821&gt;'\n915821 (12) . 2 (12) .. 923960 (20) debian-jail \n923961 (4052) other-jail \n</code></pre>\n<p>Directory called <code>debian-jail</code> has inode 923960. So last component of my chroot dir is <code>debian-jail</code>. Let's see parent directory (inode 2) now:</p>\n<pre><code>sudo debugfs /tmp/root_dev -R 'ls &lt;2&gt;'\n 2 (12) . 2 (12) .. 11 (20) lost+found 1046529 (12) home \n 130817 (12) etc 784897 (16) media 3603 (20) initrd.img \n 261633 (12) var 654081 (12) usr 392449 (12) sys 392450 (12) lib \n 784898 (12) root 915715 (12) sbin 1046530 (12) tmp \n1046531 (12) bin 784899 (12) dev 392451 (12) mnt \n 915716 (12) run 12 (12) proc 1046532 (12) boot 13 (16) lib64 \n 784945 (12) srv 915821 (12) opt 3604 (3796) vmlinuz \n</code></pre>\n<p>Directory called <code>opt</code> has inode 915821 and inode 2 is root of filesystem. So my chroot directory is <code>/opt/debian-jail</code>. Sure, <code>/dev/sda1</code> may be mounted on another filesystem. You need to check that (use lsof or directly picking information <code>/proc</code>).</p>\n"}, {'answer_id': 48844758, 'author': 'Samuel Harmer', 'author_id': 594137, 'author_profile': 'https://Stackoverflow.com/users/594137', 'pm_score': 2, 'selected': False, 'text': '<p>I wanted the same information for a jail running on FreeBSD (as Ansible doesn\'t seem to detect this scenario).</p>\n\n<p>On the FreeNAS distribution of FreeBSD 11, <code>/proc</code> is not mounted on the host, but it is within the jail. Whether this is also true on regular FreeBSD I don\'t know for sure, but <a href="https://www.freebsd.org/doc/en/articles/linux-users/procfs.html" rel="nofollow noreferrer">procfs: Gone But Not Forgotten</a> seems to suggest it is. Either way, you probably wouldn\'t want to try mounting it just to detect jail status and therefore I\'m not certain it can be used as a reliable predictor of being within a jail.</p>\n\n<p>I also ruled out using stat on <code>/</code> as certainly on FreeNAS all jails are given their own file system (i.e. <a href="https://www.freebsd.org/doc/handbook/zfs-term.html" rel="nofollow noreferrer">a ZFS dataset</a>) and therefore the <code>/</code> node on the host and in the jail both have inode 4. I expect this is common on FreeBSD 11 in general.</p>\n\n<p>So the approach I settled on was using <a href="https://www.freebsd.org/cgi/man.cgi?procstat" rel="nofollow noreferrer">procstat</a> on pid 0.</p>\n\n<pre><code>[root@host ~]# procstat 0\n PID PPID PGID SID TSID THR LOGIN WCHAN EMUL COMM \n 0 0 0 0 0 1234 - swapin - kernel \n[root@host ~]# echo $?\n0\n[root@host ~]# jexec guest tcsh\nroot@guest:/ # procstat 0\nprocstat: sysctl(kern.proc): No such process\nprocstat: procstat_getprocs()\nroot@guest:/ # echo $?\n1\n</code></pre>\n\n<p>I am making an assumption here that pid 0 will always be the kernel on the host, and there won\'t be a pid 0 inside the jail.</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/75182', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13277/']
75,191
<p>In C/C++, what an <code>unsigned char</code> is used for? How is it different from a regular <code>char</code>?</p>
[{'answer_id': 75238, 'author': 'Todd Gamblin', 'author_id': 9122, 'author_profile': 'https://Stackoverflow.com/users/9122', 'pm_score': 7, 'selected': False, 'text': '<p>This is implementation dependent, as the C standard does NOT define the signed-ness of <code>char</code>. Depending on the platform, char may be <code>signed</code> or <code>unsigned</code>, so you need to explicitly ask for <code>signed char</code> or <code>unsigned char</code> if your implementation depends on it. Just use <code>char</code> if you intend to represent characters from strings, as this will match what your platform puts in the string.</p>\n\n<p>The difference between <code>signed char</code> and <code>unsigned char</code> is as you\'d expect. On most platforms, <code>signed char</code> will be an 8-bit two\'s complement number ranging from <code>-128</code> to <code>127</code>, and <code>unsigned char</code> will be an 8-bit unsigned integer (<code>0</code> to <code>255</code>). Note the standard does NOT require that <code>char</code> types have 8 bits, only that <code>sizeof(char)</code> return <code>1</code>. You can get at the number of bits in a char with <code>CHAR_BIT</code> in <code>limits.h</code>. There are few if any platforms today where this will be something other than <code>8</code>, though.</p>\n\n<p>There is a nice summary of this issue <a href="http://www.arm.linux.org.uk/docs/faqs/signedchar.php" rel="noreferrer">here</a>.</p>\n\n<p>As others have mentioned since I posted this, you\'re better off using <code>int8_t</code> and <code>uint8_t</code> if you really want to represent small integers.</p>\n'}, {'answer_id': 75279, 'author': 'James Hopkin', 'author_id': 11828, 'author_profile': 'https://Stackoverflow.com/users/11828', 'pm_score': 4, 'selected': False, 'text': "<p><code>signed char</code> has range -128 to 127; <code>unsigned char</code> has range 0 to 255.</p>\n\n<p><code>char</code> will be equivalent to either signed char or unsigned char, depending on the compiler, but is a distinct type.</p>\n\n<p>If you're using C-style strings, just use <code>char</code>. If you need to use chars for arithmetic (pretty rare), specify signed or unsigned explicitly for portability.</p>\n"}, {'answer_id': 75324, 'author': 'neuroguy123', 'author_id': 12529, 'author_profile': 'https://Stackoverflow.com/users/12529', 'pm_score': 2, 'selected': False, 'text': '<p>Some googling found <a href="http://bytes.com/forum/thread61480.html" rel="nofollow noreferrer">this</a>, where people had a discussion about this.</p>\n\n<p>An unsigned char is basically a single byte. So, you would use this if you need one byte of data (for example, maybe you want to use it to set flags on and off to be passed to a function, as is often done in the Windows API).</p>\n'}, {'answer_id': 75327, 'author': 'Zac Gochenour', 'author_id': 1812999, 'author_profile': 'https://Stackoverflow.com/users/1812999', 'pm_score': 3, 'selected': False, 'text': '<p>An <code>unsigned char</code> is an unsigned byte value (0 to 255). You may be thinking of <code>char</code> in terms of being a "character" but it is really a numerical value. The regular <code>char</code> is signed, so you have 128 values, and these values map to characters using ASCII encoding. But in either case, what you are storing in memory is a byte value.</p>\n'}, {'answer_id': 75334, 'author': 'Julienne Walker', 'author_id': 13259, 'author_profile': 'https://Stackoverflow.com/users/13259', 'pm_score': 3, 'selected': False, 'text': "<p>In terms of direct values a regular char is used when the values are known to be between <code>CHAR_MIN</code> and <code>CHAR_MAX</code> while an unsigned char provides double the range on the positive end. For example, if <code>CHAR_BIT</code> is 8, the range of regular <code>char</code> is only guaranteed to be [0, 127] (because it can be signed or unsigned) while <code>unsigned char</code> will be [0, 255] and <code>signed char</code> will be [-127, 127].</p>\n\n<p>In terms of what it's used for, the standards allow objects of POD (plain old data) to be directly converted to an array of unsigned char. This allows you to examine the representation and bit patterns of the object. The same guarantee of safe type punning doesn't exist for char or signed char.</p>\n"}, {'answer_id': 75348, 'author': 'Dark Shikari', 'author_id': 11206, 'author_profile': 'https://Stackoverflow.com/users/11206', 'pm_score': 3, 'selected': False, 'text': "<p>If you like using various types of specific length and signedness, you're probably better off with <code>uint8_t</code>, <code>int8_t</code>, <code>uint16_t</code>, etc simply because they do exactly what they say.</p>\n"}, {'answer_id': 75364, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': "<p>An unsigned char uses the bit that is reserved for the sign of a regular char as another number. This changes the range to [0 - 255] as opposed to [-128 - 127]. </p>\n\n<p>Generally unsigned chars are used when you don't want a sign. This will make a difference when doing things like shifting bits (shift extends the sign) and other things when dealing with a char as a byte rather than using it as a number.</p>\n"}, {'answer_id': 75883, 'author': 'ugasoft', 'author_id': 10120, 'author_profile': 'https://Stackoverflow.com/users/10120', 'pm_score': 3, 'selected': False, 'text': "<p><code>unsigned char</code> is the heart of all bit trickery. In almost <em>all</em> compilers for <em>all</em> platforms an <code>unsigned char</code> is simply a <strong>byte</strong> and an unsigned integer of (usually) 8 bits that can be treated as a small integer or a pack of bits.</p>\n<p>In addition, as someone else has said, the standard doesn't define the sign of a char. So you have 3 distinct <code>char</code> types: <code>char</code>, <code>signed char</code>, <code>unsigned char</code>.</p>\n"}, {'answer_id': 79405, 'author': 'Zachary Garrett', 'author_id': 14692, 'author_profile': 'https://Stackoverflow.com/users/14692', 'pm_score': 5, 'selected': False, 'text': "<p>As for example usages of <em>unsigned char</em>:</p>\n\n<p><code>unsigned char</code> is often used in computer graphics, which very often (though not always) assigns a single byte to each colour component. It is common to see an RGB (or RGBA) colour represented as 24 (or 32) bits, each an <code>unsigned char</code>. Since <code>unsigned char</code> values fall in the range [0,255], the values are typically interpreted as: </p>\n\n<ul>\n<li>0 meaning a total lack of a given colour component.</li>\n<li>255 meaning 100% of a given colour pigment.</li>\n</ul>\n\n<p>So you would end up with RGB red as (255,0,0) -> (100% red, 0% green, 0% blue).</p>\n\n<p>Why not use a <code>signed char</code>? Arithmetic and bit shifting becomes problematic. As explained already, a <code>signed char</code>'s range is essentially shifted by -128. A very simple and naive (mostly unused) method for converting RGB to grayscale is to average all three colour components, but this runs into problems when the values of the colour components are negative. Red (255, 0, 0) averages to (85, 85, 85) when using <code>unsigned char</code> arithmetic. However, if the values were <code>signed char</code>s (127,-128,-128), we would end up with (-99, -99, -99), which would be (29, 29, 29) in our <code>unsigned char</code> space, which is incorrect.</p>\n"}, {'answer_id': 80376, 'author': 'bk1e', 'author_id': 8090, 'author_profile': 'https://Stackoverflow.com/users/8090', 'pm_score': 3, 'selected': False, 'text': '<p><code>char</code> and <code>unsigned char</code> aren\'t guaranteed to be 8-bit types on all platforms&mdash;they are guaranteed to be 8-bit or larger. Some platforms have <a href="https://isocpp.org/wiki/faq/intrinsic-types#bits-per-byte" rel="nofollow noreferrer">9-bit, 32-bit, or 64-bit bytes</a>. However, the most common platforms today (Windows, Mac, Linux x86, etc.) have 8-bit bytes.</p>\n'}, {'answer_id': 87648, 'author': 'Fruny', 'author_id': 16815, 'author_profile': 'https://Stackoverflow.com/users/16815', 'pm_score': 10, 'selected': True, 'text': "<p>In C++, there are three <em>distinct</em> character types:</p>\n<ul>\n<li><code>char</code></li>\n<li><code>signed char</code></li>\n<li><code>unsigned char</code></li>\n</ul>\n<p>If you are using character types for <em>text</em>, use the unqualified <code>char</code>:</p>\n<ul>\n<li>it is the type of character literals like <code>'a'</code> or <code>'0'</code> (in C++ only, in C their type is <code>int</code>)</li>\n<li>it is the type that makes up C strings like <code>&quot;abcde&quot;</code></li>\n</ul>\n<p>It also works out as a number value, but it is unspecified whether that value is treated as signed or unsigned. Beware character comparisons through inequalities - although if you limit yourself to ASCII (0-127) you're just about safe.</p>\n<p>If you are using character types as <em>numbers</em>, use:</p>\n<ul>\n<li><code>signed char</code>, which gives you <em>at least</em> the -127 to 127 range. (-128 to 127 is common)</li>\n<li><code>unsigned char</code>, which gives you <em>at least</em> the 0 to 255 range.</li>\n</ul>\n<p>&quot;At least&quot;, because the C++ standard only gives the minimum range of values that each numeric type is required to cover. <code>sizeof (char)</code> is required to be 1 (i.e. one byte), but a byte could in theory be for example 32 bits. <strong><code>sizeof</code> would still be report its size as <code>1</code></strong> - meaning that you <em>could</em> have <code>sizeof (char) == sizeof (long) == 1</code>.</p>\n"}, {'answer_id': 442647, 'author': 'Johannes Schaub - litb', 'author_id': 34509, 'author_profile': 'https://Stackoverflow.com/users/34509', 'pm_score': 5, 'selected': False, 'text': "<p>Because I feel it's really called for, I just want to state some rules of C and C++ (they are the same in this regard). First, <em>all bits</em> of <code>unsigned char</code> participate in determining the value if any unsigned char object. Second, <code>unsigned char</code> is explicitly stated unsigned.</p>\n<p>Now, I had a discussion with someone about what happens when you convert the value <code>-1</code> of type int to <code>unsigned char</code>. He refused the idea that the resulting <code>unsigned char</code> has all its bits set to 1, because he was worried about sign representation. But he didn't have to be. It's immediately following out of this rule that the conversion does what is intended:</p>\n<blockquote>\n<p>If the new type is unsigned, the value is converted by repeatedly adding or subtracting one more than the maximum value that can be represented in the new type until the value is in the range of the new type. (<code>6.3.1.3p2</code> in a C99 draft)</p>\n</blockquote>\n<p>That's a mathematical description. C++ describes it in terms of modulo calculus, which yields to the same rule. Anyway, what is <em>not</em> guaranteed is that all bits in the integer <code>-1</code> are one before the conversion. So, what do we have so we can claim that the resulting <code>unsigned char</code> has all its <code>CHAR_BIT</code> bits turned to 1?</p>\n<ol>\n<li>All bits participate in determining its value - that is, no padding bits occur in the object.</li>\n<li>Adding only one time <code>UCHAR_MAX+1</code> to <code>-1</code> will yield a value in range, namely <code>UCHAR_MAX</code></li>\n</ol>\n<p>That's enough, actually! So whenever you want to have an <code>unsigned char</code> having all its bits one, you do</p>\n<pre><code>unsigned char c = (unsigned char)-1;\n</code></pre>\n<p>It also follows that a conversion is <em>not</em> just truncating higher order bits. The fortunate event for <em>two's complement</em> is that it is just a truncation there, but the same isn't necessarily true for other sign representations.</p>\n"}, {'answer_id': 14456663, 'author': 'munna', 'author_id': 1865289, 'author_profile': 'https://Stackoverflow.com/users/1865289', 'pm_score': 3, 'selected': False, 'text': '<p><code>unsigned char</code> takes only positive values....like <strong>0</strong> to <strong>255</strong></p>\n\n<p>where as</p>\n\n<p><code>signed char</code> takes both positive and negative values....like <strong>-128</strong> to <strong>+127</strong></p>\n'}, {'answer_id': 45228423, 'author': 'ZhaoGang', 'author_id': 2830167, 'author_profile': 'https://Stackoverflow.com/users/2830167', 'pm_score': 2, 'selected': False, 'text': '<p>quoted frome "the c programming laugage" book:</p>\n\n<p>The qualifier <code>signed</code> or <code>unsigned</code> may be applied to char or any integer. unsigned numbers\nare always positive or zero, and obey the laws of arithmetic modulo 2^n, where n is the number\nof bits in the type. So, for instance, if chars are 8 bits, unsigned char variables have values\nbetween 0 and 255, while signed chars have values between -128 and 127 (in a two\' s\ncomplement machine.) Whether plain chars are signed or unsigned is machine-dependent,\nbut printable characters are always positive.</p>\n'}, {'answer_id': 47480841, 'author': 'NL628', 'author_id': 8925851, 'author_profile': 'https://Stackoverflow.com/users/8925851', 'pm_score': 2, 'selected': False, 'text': '<p><code>unsigned char</code> takes only positive values: 0 to 255 while\n<code>signed char</code> takes positive and negative values: -128 to +127.</p>\n'}, {'answer_id': 59587899, 'author': 'Kalana', 'author_id': 11383441, 'author_profile': 'https://Stackoverflow.com/users/11383441', 'pm_score': 2, 'selected': False, 'text': '<p><code>signed char</code> and <code>unsigned char</code> both represent 1byte, but they have different ranges.</p>\n\n<pre><code> Type | range\n-------------------------------\nsigned char | -128 to +127\nunsigned char | 0 to 255\n</code></pre>\n\n<p>In <code>signed char</code> if we consider <code>char letter = \'A\'</code>, \'A\' is represent binary of 65 in <code>ASCII/Unicode</code>, If 65 can be stored, -65 also can be stored. There are no negative binary values in <code>ASCII/Unicode</code> there for no need to worry about negative values.</p>\n\n<p><strong>Example</strong></p>\n\n<pre><code>#include &lt;stdio.h&gt;\n\nint main()\n{\n signed char char1 = 255;\n signed char char2 = -128;\n unsigned char char3 = 255;\n unsigned char char4 = -128;\n\n printf("Signed char(255) : %d\\n",char1);\n printf("Unsigned char(255) : %d\\n",char3);\n\n printf("\\nSigned char(-128) : %d\\n",char2);\n printf("Unsigned char(-128) : %d\\n",char4);\n\n return 0;\n}\n</code></pre>\n\n<p><strong>Output -:</strong></p>\n\n<pre><code>Signed char(255) : -1\nUnsigned char(255) : 255\n\nSigned char(-128) : -128\nUnsigned char(-128) : 128\n</code></pre>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/75191', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1785/']
75,213
<p>In C++, what is the purpose of the scope resolution operator when used without a scope? For instance:</p> <pre><code>::foo(); </code></pre>
[{'answer_id': 75224, 'author': 'shoosh', 'author_id': 9611, 'author_profile': 'https://Stackoverflow.com/users/9611', 'pm_score': 2, 'selected': False, 'text': '<p>referring to the global scope</p>\n'}, {'answer_id': 75249, 'author': 'Drealmer', 'author_id': 12291, 'author_profile': 'https://Stackoverflow.com/users/12291', 'pm_score': 2, 'selected': False, 'text': '<p>When you already have a function named foo() in your local scope but you need to access the one in the global scope.</p>\n'}, {'answer_id': 75251, 'author': 'itsmatt', 'author_id': 7862, 'author_profile': 'https://Stackoverflow.com/users/7862', 'pm_score': 2, 'selected': False, 'text': '<p>My c++ is rusty but I believe if you have a function declared in the local scope, such as foo() and one at global scope, foo() refers to the local one. ::foo() will refer to the global one.</p>\n'}, {'answer_id': 75262, 'author': 'Mark', 'author_id': 4405, 'author_profile': 'https://Stackoverflow.com/users/4405', 'pm_score': 7, 'selected': True, 'text': '<p>It means global scope. You might need to use this operator when you have conflicting functions or variables in the same scope and you need to use a global one. You might have something like:</p>\n\n<pre><code>void bar(); // this is a global function\n\nclass foo {\n void some_func() { ::bar(); } // this function is calling the global bar() and not the class version\n void bar(); // this is a class member\n};\n</code></pre>\n\n<p>If you need to call the global bar() function from within a class member function, you should use ::bar() to get to the global version of the function.</p>\n'}, {'answer_id': 75309, 'author': 'Matt Price', 'author_id': 852, 'author_profile': 'https://Stackoverflow.com/users/852', 'pm_score': 3, 'selected': False, 'text': "<p>Also you should note, that name resolution happens before overload resolution. So if there is something with the same name in your current scope then it will stop looking for other names and try to use them.</p>\n\n<pre><code>void bar() {};\nclass foo {\n void bar(int) {};\n void foobar() { bar(); } // won't compile needs ::bar()\n void foobar(int i) { bar(i); } // ok\n}\n</code></pre>\n"}, {'answer_id': 22085788, 'author': 'Shafik Yaghmour', 'author_id': 1708801, 'author_profile': 'https://Stackoverflow.com/users/1708801', 'pm_score': 4, 'selected': False, 'text': '<p>A name that begins with the <a href="http://en.wikipedia.org/wiki/Scope_resolution_operator" rel="noreferrer">scope resolution operator </a>(<code>::</code>) is looked up in the global namespace. We can see this by looking at the <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3485.pdf" rel="noreferrer">draft C++ standard</a> section <code>3.4.3</code> <em>Qualified name lookup</em> paragraph <em>4</em> which says (<em>emphasis mine</em>):</p>\n\n<blockquote>\n <p>A name prefixed by the unary scope operator :: (5.1) <strong>is looked up in global scope</strong>, in the translation unit where it is used. The name shall be declared in global namespace scope or shall be a name whose declaration is visible in global scope because of a using-directive (3.4.3.2). The use of :: <strong>allows a global name to be referred to even if its identifier has been hidden</strong> (3.3.10).</p>\n</blockquote>\n\n<p>As the standard states this allows us to use names from the global namespace <a href="http://publib.boulder.ibm.com/infocenter/lnxpcomp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8l.doc%2Flanguage%2Fref%2Fcplr175.htm" rel="noreferrer">that would otherwise be hidden</a>, the example from the linked document is as follows:</p>\n\n<pre><code>int count = 0;\n\nint main(void) {\n int count = 0;\n ::count = 1; // set global count to 1\n count = 2; // set local count to 2\n return 0;\n}\n</code></pre>\n\n<p>The wording is very similar going back to <a href="http://www.open-std.org/Jtc1/sc22/wg21/docs/papers/2005/n1804.pdf" rel="noreferrer">N1804</a> which is the earliest draft standard available. </p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/75213', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1785/']
75,218
<p>How can I detect when an Exception has been thrown anywhere in my application?</p> <p>I'm try to auto-magically send myself an email whenever an exception is thrown anywhere in my Java Desktop Application. I figure this way I can be more proactive.</p> <p>I know I could just explicitly log and notify myself whenever an exception occurs, but I'd have to do it everywhere and I might(more likely will) miss a couple.</p> <p>Any suggestions?</p>
[{'answer_id': 75274, 'author': 'toluju', 'author_id': 12457, 'author_profile': 'https://Stackoverflow.com/users/12457', 'pm_score': 0, 'selected': False, 'text': '<p>In this case I think your best bet might be to write a custom classloader to handle all classloading in your application, and whenever an exception class is requested you return a class that wraps the requested exception class. This wrapper calls through to the wrapped exception but also logs the exception event.</p>\n'}, {'answer_id': 75277, 'author': 'Jason Cohen', 'author_id': 4926, 'author_profile': 'https://Stackoverflow.com/users/4926', 'pm_score': 3, 'selected': False, 'text': '<p>The new debugging hooks in Java 1.5 let you do this. It enables e.g. "break on any exception" in debuggers.</p>\n\n<p><a href="http://java.sun.com/j2se/1.5.0/docs/guide/jpda/jdi/com/sun/jdi/event/ExceptionEvent.html" rel="noreferrer">Here\'s the specific Javadoc</a> you need.</p>\n'}, {'answer_id': 75285, 'author': 'Justin Rudd', 'author_id': 12968, 'author_profile': 'https://Stackoverflow.com/users/12968', 'pm_score': 2, 'selected': False, 'text': '<p>Check out <a href="http://java.sun.com/javase/6/docs/api/java/lang/Thread.UncaughtExceptionHandler.html" rel="nofollow noreferrer">Thread.UncaughtExceptionHandler</a>. You can set it per thread or a default one for the entire VM.</p>\n\n<p>This would at least help you catch the ones you miss.</p>\n'}, {'answer_id': 75298, 'author': 'Mat Mannion', 'author_id': 6282, 'author_profile': 'https://Stackoverflow.com/users/6282', 'pm_score': 1, 'selected': False, 'text': '<p>If you\'re using a web framework such as <a href="http://www.springframework.org" rel="nofollow noreferrer">Spring</a> then you can delegate in your web.xml to a page and then use the controller to send the email. For example:</p>\n\n<p>In web.xml:</p>\n\n<pre><code>&lt;error-page&gt;\n &lt;error-code&gt;500&lt;/error-code&gt;\n &lt;location&gt;/error/500.htm&lt;/location&gt;\n&lt;/error-page&gt;\n</code></pre>\n\n<p>Then define /error/500.htm as a controller. You can access the exception from the parameter javax.servlet.error.exception:</p>\n\n<pre><code>Exception exception = (Exception) request.getAttribute("javax.servlet.error.exception");\n</code></pre>\n\n<p>If you\'re just running a regular Java program, then I would imagine you\'re stuck with public static void main(String[] args) { try { ... } catch (Exception e) {} }</p>\n'}, {'answer_id': 75302, 'author': 'David Webb', 'author_id': 3171, 'author_profile': 'https://Stackoverflow.com/users/3171', 'pm_score': 0, 'selected': False, 'text': '<p>I assume you don\'t mean <em>any</em> Exception but rather any <em>uncaught</em> Exception.</p>\n\n<p>If this is the case <a href="http://java.sun.com/developer/JDCTechTips/2001/tt0109.html#handling" rel="nofollow noreferrer">this article on the Sun Website</a> has some ideas. You need to wrap your top level method in a <code>try-catch</code> block and also do some extra work to handle other Threads.</p>\n'}, {'answer_id': 75439, 'author': 'shemnon', 'author_id': 8020, 'author_profile': 'https://Stackoverflow.com/users/8020', 'pm_score': 6, 'selected': True, 'text': '<p>You probobly don\'t want to mail on any exception. There are lots of code in the JDK that actaully depend on exceptions to work normally. What I presume you are more inerested in are uncaught exceptions. If you are catching the exceptions you should handle notifications there.</p>\n\n<p>In a desktop app there are two places to worry about this, in the <a href="/questions/tagged/event-dispatch-thread" class="post-tag" title="show questions tagged &#39;event-dispatch-thread&#39;" rel="tag">event-dispatch-thread</a> (EDT) and outside of the EDT. Globaly you can register a class implementing <code>java.util.Thread.UncaughtExceptionHandler</code> and register it via <code>java.util.Thread.setDefaultUncaughtExceptionHandler</code>. This will get called if an exception winds down to the bottom of the stack and the thread hasn\'t had a handler set on the current thread instance on the thread or the ThreadGroup.</p>\n\n<p>The EDT has a different hook for handling exceptions. A system property <code>\'sun.awt.exception.handler\'</code> needs to be registerd with the Fully Qualified Class Name of a class with a zero argument constructor. This class needs an instance method handle(<code>Throwable</code>) that does your work. The return type doesn\'t matter, and since a new instance is created every time, don\'t count on keeping state.</p>\n\n<p>So if you don\'t care what thread the exception occurred in a sample may look like this:</p>\n\n<pre><code>class ExceptionHandler implements Thread.UncaughtExceptionHandler {\n public void uncaughtException(Thread t, Throwable e) {\n handle(e);\n }\n\n public void handle(Throwable throwable) {\n try {\n // insert your e-mail code here\n } catch (Throwable t) {\n // don\'t let the exception get thrown out, will cause infinite looping!\n }\n }\n\n public static void registerExceptionHandler() {\n Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler());\n System.setProperty("sun.awt.exception.handler", ExceptionHandler.class.getName());\n }\n}\n</code></pre>\n\n<p>Add this class into some random package, and then call the <code>registerExceptionHandler</code> method and you should be ready to go.</p>\n'}, {'answer_id': 75449, 'author': 'Nik', 'author_id': 13267, 'author_profile': 'https://Stackoverflow.com/users/13267', 'pm_score': 0, 'selected': False, 'text': '<p>Sending an email may not be possible if you are getting a runtime exception like OutOfMemoryError or StackOverflow. Most likely you will have to spawn another process and catch any exceptions thrown by it (with the various techniques mentioned above).</p>\n'}, {'answer_id': 76614, 'author': 'Alexandre Victoor', 'author_id': 11897, 'author_profile': 'https://Stackoverflow.com/users/11897', 'pm_score': 1, 'selected': False, 'text': '<p>If you are using java 1.3/1.4, Thread.UncaughtExceptionHandler is not available. \nIn this case you can use a solution based on AOP to trigger some code when an exception is thrown. Spring and/or aspectJ might be helpful.</p>\n'}, {'answer_id': 8152499, 'author': 'Alex Fedulov', 'author_id': 336152, 'author_profile': 'https://Stackoverflow.com/users/336152', 'pm_score': 1, 'selected': False, 'text': '<p>In my current project I faced the similar requirement regarding the errors detection. For this purpose I have applied the following approach: I use log4j for logging across my app, and everywhere, where the exception is caught I do the standard thing: <code>log.error("Error\'s description goes here", e);</code>, where e is the Exception being thrown (see log4j documentation for details regarding the initialization of the "log").\nIn order to detect the error, I use my own Appender, which extends the log4j AppenderSkeleton class:</p>\n\n<pre><code>import org.apache.log4j.AppenderSkeleton;\nimport org.apache.log4j.spi.LoggingEvent;\n\npublic class ErrorsDetectingAppender extends AppenderSkeleton {\n\n private static boolean errorsOccured = false;\n\n public static boolean errorsOccured() {\n return errorsOccured;\n }\n\n public ErrorsDetectingAppender() {\n super();\n }\n\n @Override\n public void close() {\n // TODO Auto-generated method stub\n }\n\n @Override\n public boolean requiresLayout() {\n return false;\n }\n\n @Override\n protected void append(LoggingEvent event) {\n if (event.getLevel().toString().toLowerCase().equals("error")) {\n System.out.println("-----------------Errors detected");\n this.errorsOccured = true;\n }\n }\n}\n</code></pre>\n\n<p>The log4j configuration file has to just contain a definition of the new appender and its attachement to the selected logger (root in my case):</p>\n\n<pre><code>log4j.rootLogger = OTHER_APPENDERS, ED\nlog4j.appender.ED=com.your.package.ErrorsDetectingAppender\n</code></pre>\n\n<p>You can either call the errorsOccured() method of the ErrorsDetectingAppender at some significant point in your programs\'s execution flow or react immidiately by adding functionality to the if block in the append() method. This approach is consistent with the semantics: things that you consider errors and log them as such, are detected. If you will later consider selected errors not so important, you just change the logging level to log.warn() and report will not be sent.</p>\n'}, {'answer_id': 57960747, 'author': 'Raedwald', 'author_id': 545127, 'author_profile': 'https://Stackoverflow.com/users/545127', 'pm_score': 0, 'selected': False, 'text': '<p>There is simply no good reason to be informed of every thrown exception. I guess you are assuming that a thrown exception indicates a "problem" that your "need" to know about. But this is wrong. If an exception is thrown, caught and handled, all is well. The only thing you <em>need</em> to be worried about is an exception that is thrown but not handled (not caught). But you can do that in a <code>try</code>...<code>catch</code> clause yourself.</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/75218', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2443/']
75,230
<p>How do you quickly find the URL for a Win32 API on MSDN? It's easy for .NET methods -- just add the method name (for example, System.Byte.ToString) to <a href="http://msdn.microsoft.com/library/" rel="nofollow noreferrer">http://msdn.microsoft.com/library/</a>.</p> <p>However, for Win32 APIs (say GetLongPathName), this doesn't work: <a href="http://msdn.microsoft.com/en-us/library/GetLongPathName" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/GetLongPathName</a>.</p> <p>I want to be able to use the URL in code comments or documentation. So the URL one gets with an MSDN or Google search (for example, <a href="http://msdn.microsoft.com/library/aa364980.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/library/aa364980.aspx</a>) isn't really what I'm looking for. I'd really like my code comments to look something like:</p> <p>// blah blah blah. See <a href="http://msdn.microsoft.com/en-us/library/GetLongPathName" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/GetLongPathName</a> for more information.</p> <p>What's the magic pixie dust for Win32 APIs? Or does it only work for .NET methods?</p>
[{'answer_id': 75321, 'author': 'japollock', 'author_id': 1210318, 'author_profile': 'https://Stackoverflow.com/users/1210318', 'pm_score': 3, 'selected': False, 'text': '<p>Google might be your best bet. I know the msdn site search has time and again pointed me in the wrong direction, but a quick switch to Google ("GetLongPathName site:msdn.microsoft.com") never steers me wrong.</p>\n'}, {'answer_id': 118638, 'author': 'jussij', 'author_id': 14738, 'author_profile': 'https://Stackoverflow.com/users/14738', 'pm_score': 0, 'selected': False, 'text': '<p>FWIW if you have the <strong>MSDN</strong> installed locally on your machine the <a href="http://www.zeusedit.com/forum/viewtopic.php?p=3758" rel="nofollow noreferrer">Zeus</a> editor has a feature to search the local copy of the <strong>MSDN</strong>.</p>\n\n<p>For example, placing the cursor on the <strong>GetLongPathName</strong> word within a text document and using the <a href="http://www.zeusedit.com/forum/viewtopic.php?p=3758" rel="nofollow noreferrer">Zeus</a> Help, <strong>Quick Help, Current Word</strong> menu, the following <strong>MSDN</strong> page gets loaded: </p>\n\n<p><em>ms-help://MS.VSCC.v80/MS.MSDN.vAug06.en/fileio/fs/getlongpathname.htm</em> </p>\n'}, {'answer_id': 1138828, 'author': 'peterchen', 'author_id': 31317, 'author_profile': 'https://Stackoverflow.com/users/31317', 'pm_score': 0, 'selected': False, 'text': '<p>I am using <a href="http://www.codeproject.com/KB/macros/Linkify.aspx" rel="nofollow noreferrer">Linkify</a> by <em>cough</em> me, which lets you link </p>\n\n<pre><code>// see msdn:GetLongPathName\n</code></pre>\n\n<p>to the google search japollock mentions.</p>\n'}, {'answer_id': 1138850, 'author': 'Kirill V. Lyadvinsky', 'author_id': 123111, 'author_profile': 'https://Stackoverflow.com/users/123111', 'pm_score': 0, 'selected': False, 'text': '<p>You could use MSDN search. </p>\n\n<p><a href="http://social.msdn.microsoft.com/Search/en-US/?Refinement=86&amp;Query=" rel="nofollow noreferrer">http://social.msdn.microsoft.com/Search/en-US/?Refinement=86&amp;Query=</a><strong>GetLongPathName</strong></p>\n\n<p><code>Refinement=86</code> stands for Win32 search.</p>\n'}, {'answer_id': 72611509, 'author': 'Mr. Doge', 'author_id': 12772224, 'author_profile': 'https://Stackoverflow.com/users/12772224', 'pm_score': 0, 'selected': False, 'text': '<p>MSDN GET api <code>(I don\'t know how new this is)</code></p>\n<pre><code>&quot;https://learn.microsoft.com/api/search?locale=en-us&amp;scoringprofile=semantic-captions&amp;%24top=1&amp;search=&quot; functionName\n</code></pre>\n<p>returns json like such:</p>\n<pre class="lang-json prettyprint-override"><code>{\n &quot;results&quot;: [\n {\n &quot;title&quot;: &quot;KeClearEvent function (wdm.h) - Windows drivers&quot;,\n &quot;url&quot;: &quot;https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/nf-wdm-keclearevent&quot;,\n &quot;displayUrl&quot;: {\n &quot;content&quot;: &quot;/windows-hardware/drivers/ddi/wdm/nf-wdm-keclearevent&quot;,\n &quot;hitHighlights&quot;: [\n {\n &quot;start&quot;: 41,\n &quot;length&quot;: 12\n }\n ]\n },\n &quot;description&quot;: &quot;The KeClearEvent routine sets an event to a not-signaled state.&quot;,\n &quot;descriptions&quot;: [\n {\n &quot;content&quot;: &quot;KeClearEvent function (wdm.h) Article 04/18/2022 2 minutes to read In this article The KeClearEvent routine sets an event to a not-signaled state.&quot;,\n &quot;hitHighlights&quot;: [\n {\n &quot;start&quot;: 0,\n &quot;length&quot;: 12\n },\n {\n &quot;start&quot;: 87,\n &quot;length&quot;: 12\n }\n ]\n },\n {\n &quot;content&quot;: &quot;For better performance, use KeClearEvent unless the caller uses the value returned by KeResetEvent to determine what to do next.&quot;,\n &quot;hitHighlights&quot;: [\n {\n &quot;start&quot;: 28,\n &quot;length&quot;: 12\n }\n ]\n }\n ],\n &quot;lastUpdatedDate&quot;: &quot;2022-04-18T04:31:00+00:00&quot;,\n &quot;breadcrumbs&quot;: []\n }\n ],\n &quot;spellingCorrection&quot;: [],\n &quot;scopeRemoved&quot;: false,\n &quot;count&quot;: 18,\n &quot;nextLink&quot;: &quot;https://learn.microsoft.com/api/Search?locale=en-us\\u0026search=KeClearEvent\\u0026$skip=1\\u0026$top=1&quot;,\n &quot;srcheng&quot;: &quot;02&quot;\n}\n</code></pre>\n<p>if you want <em>really</em> fast, you can bind it to a hotkey<br>\n<a href="https://www.autohotkey.com/v2/" rel="nofollow noreferrer">AutohotkeyV2</a></p>\n<pre><code>#SingleInstance force\nListLines 0\nKeyHistory 0\nSendMode &quot;Input&quot; ; Recommended for new scripts due to its superior speed and reliability.\nSetWorkingDir A_ScriptDir ; Ensures a consistent starting directory.\n\nlinkFromName(functionName) {\n json:=downloadToVar(&quot;https://learn.microsoft.com/api/search?locale=en-us&amp;scoringprofile=semantic-captions&amp;%24top=1&amp;search=&quot; functionName)\n obj:=JSON_parse(json)\n if (obj.results.Length) {\n RegExMatch(obj.results[1].title, &quot;.*?(?=\\s|$)&quot;, &amp;OutputVar)\n if (OutputVar.0 = functionName) {\n validUrl:=obj.results[1].url\n } else if (OutputVar.0 = functionName &quot;W&quot; || OutputVar.0 = functionName &quot;A&quot;) {\n validUrl:=SubStr(obj.results[1].url, 1, -1) &quot;w&quot;\n }\n ; A_Clipboard:=validUrl\n Run validUrl\n }\n}\n\n; linkFromName(&quot;GetLongPathNameW&quot;) ;works\n; linkFromName(&quot;GetLongPathName&quot;) ;works\nlinkFromName(A_Clipboard)\n\nExitapp\n\nf3::Exitapp\n\ndownloadToVar(url) {\n whr := ComObject(&quot;WinHttp.WinHttpRequest.5.1&quot;)\n whr.Open(&quot;GET&quot;, url, true)\n whr.SetRequestHeader(&quot;User-Agent&quot;, &quot;Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)&quot;)\n whr.Send()\n ; Using \'true\' above and the call below allows the script to remain responsive.\n whr.WaitForResponse()\n return whr.ResponseText\n}\n\nJSON_parse(str) {\n\n c_:=1\n\n return JSON_value()\n\n JSON_value() {\n\n char_:=SubStr(str, c_, 1)\n Switch char_ {\n case &quot;{&quot;:\n obj_:=Map()\n ;object\n c_++\n loop {\n skip_s()\n if (SubStr(str, c_, 1) == &quot;}&quot;) {\n c_++\n return obj_\n }\n\n ; key_:=JSON_objKey()\n ; a or &quot;a&quot;\n if (SubStr(str, c_, 1) == &quot;`&quot;&quot;) {\n RegExMatch(str, &quot;(?:\\\\.|.)*?(?=`&quot;)&quot;, &amp;OutputVar, c_ + 1)\n key_:=RegExReplace(OutputVar.0, &quot;\\\\(.)&quot;, &quot;$1&quot;)\n c_+=OutputVar.Len\n } else {\n RegExMatch(str, &quot;.*?(?=[\\s:])&quot;, &amp;OutputVar, c_)\n key_:=OutputVar.0\n c_+=OutputVar.Len\n }\n\n c_:=InStr(str, &quot;:&quot;, true, c_) + 1\n skip_s()\n\n value_:=JSON_value()\n obj_[key_]:=value_\n obj_.DefineProp(key_, {Value: value_})\n\n skip_s()\n if (SubStr(str, c_, 1) == &quot;,&quot;) {\n c_++, skip_s()\n }\n }\n case &quot;[&quot;:\n arr_:=[]\n ;array\n c_++\n loop {\n skip_s()\n if (SubStr(str, c_, 1) == &quot;]&quot;) {\n c_++\n return arr_\n }\n\n value_:=JSON_value()\n arr_.Push(value_)\n\n skip_s()\n char_:=SubStr(str, c_, 1)\n if (char_ == &quot;,&quot;) {\n c_++, skip_s()\n }\n }\n case &quot;`&quot;&quot;:\n RegExMatch(str, &quot;(?:\\\\.|.)*?(?=`&quot;)&quot;, &amp;OutputVar, c_ + 1)\n unquoted:=RegExReplace(OutputVar.0, &quot;\\\\(.)&quot;, &quot;$1&quot;)\n c_+=OutputVar.Len + 2\n return unquoted\n case &quot;0&quot;, &quot;1&quot;, &quot;2&quot;, &quot;3&quot;, &quot;4&quot;, &quot;5&quot;, &quot;6&quot;, &quot;7&quot;, &quot;8&quot;, &quot;9&quot;:\n RegExMatch(str, &quot;[0-9.]*&quot;, &amp;OutputVar, c_)\n c_+=OutputVar.Len\n return Number(OutputVar.0)\n case &quot;t&quot;:\n ;&quot;true&quot;\n c_+=4\n return {a:1}\n case &quot;f&quot;:\n ;&quot;false&quot;\n c_+=5\n return {a:0}\n case &quot;n&quot;:\n ;&quot;null&quot;\n c_+=4\n return {a:-1}\n\n\n }\n }\n\n skip_s() {\n RegExMatch(str, &quot;\\s*&quot;, &amp;OutputVar, c_)\n c_+=OutputVar.Len\n }\n}\n</code></pre>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/75230', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2459/']
75,245
<p>Is it possible to reach the individual columns of table2 using HQL with a configuration like this?</p> <pre><code>&lt;hibernate-mapping&gt; &lt;class table="table1"&gt; &lt;set name="table2" table="table2" lazy="true" cascade="all"&gt; &lt;key column="result_id"/&gt; &lt;many-to-many column="group_id"/&gt; &lt;/set&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt; </code></pre>
[{'answer_id': 75272, 'author': 'sblundy', 'author_id': 4893, 'author_profile': 'https://Stackoverflow.com/users/4893', 'pm_score': 1, 'selected': False, 'text': '<p>They\'re just properties of table1\'s table2 property.</p>\n\n<pre><code>select t1.table2.property1, t1.table2.property2, ... from table1 as t1\n</code></pre>\n\n<p>You might have to join, like so</p>\n\n<pre><code>select t2.property1, t2.property2, ... \n from table1 as t1\n inner join t1.table2 as t2\n</code></pre>\n\n<p>Here\'s the relevant part of the <a href="http://www.hibernate.org/hib_docs/reference/en/html/queryhql.html#queryhql-select" rel="nofollow noreferrer">hibernate doc</a>.</p>\n'}, {'answer_id': 75402, 'author': 'Mike Desjardins', 'author_id': 10466, 'author_profile': 'https://Stackoverflow.com/users/10466', 'pm_score': 1, 'selected': False, 'text': "<p>You can query on them, but you can't make it part of the where clause. E.g.,</p>\n\n<pre><code>select t1.table2.x from table1 as t1\n</code></pre>\n\n<p>would work, but</p>\n\n<pre><code>select t1 from table1 as t1 where t1.table2.x = foo\n</code></pre>\n\n<p>would not.</p>\n"}, {'answer_id': 76181, 'author': 'Michael', 'author_id': 13379, 'author_profile': 'https://Stackoverflow.com/users/13379', 'pm_score': 0, 'selected': False, 'text': '<p>Let\'s say table2 has a column "<code>color varchar(128)</code>" and this column is properly mapped to Hibernate.</p>\n\n<p>You should be able to do something like this:</p>\n\n<pre><code>from table1 where table2.color = \'red\'\n</code></pre>\n\n<p>This will return all <code>table1</code> rows that are linked to a <code>table2</code> row whose <code>color</code> column is \'red\'. Note that in your Hibernate mapping, your <code>set</code> has the same name as the table it references. The above query uses the name of the <em>set</em>, <strong>not</strong> the name of the table.</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/75245', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']
75,246
<p>What are the implications of running a Microsoft Access Database in both 2003 and 2007? </p> <p>Is there some class I forgot to take?</p> <p>The program was originally built in office 2003, and then run in 2007. Issues seem to happen when the machine it is being run on has both 2003 and 2007 on it. The issue would also appear to stem from reference from the "Microsoft Access 12.0 Object Library" (or the "Microsoft Access 11.0 Object Library" in 2003). To see this, just look at the Tools: Refrences menu on the VBA screen. </p> <p>The error's symptom is basically the code not be recognized (almost like it doesn’t recognize the programming language I’m using). It usually follows this with a box that says "The expression On Load you entered as the event property settings produced the following error: Object or class does not support the set of events". You can also replace “On Load” with “On Click” for buttons or “On Change” for text boxes.</p> <p>I personally suspect that the computer is taking parts of the Microsoft Access 11.0/12.0 Object Library and then mixes the two into a useless VBA reference. What further confirms my suspicion is the box that pops up when going between the two that says "Configuring Microsoft Access" Another issue that further confirms my suspicion is it will run on whichever one it is opened on first (2007, for example) and then not run on the other (2003 continuing the example)</p> <p>The only other issue is I have had to fix was changing the last part of the DoCmd.OpenForm ,,,,, acFormReadOnly (or acReadOnly, depending on how the machine seems to feel on that particular day - yes it would work with one, one day and then want me to switch it another) to simply locking the individual text boxes</p> <p>Maybe it’s not quite coding, but I think it might be able to be fixed by coding.</p> <p>Hopefully that’s enough for someone to come up with something.</p>
[{'answer_id': 75433, 'author': 'Philippe Grondier', 'author_id': 11436, 'author_profile': 'https://Stackoverflow.com/users/11436', 'pm_score': 0, 'selected': False, 'text': "<p>We have an MS-Acces application, developped with Access 2003 and used on either full or runtime version of Access 2003 and Access 2007 (Access 2007 Runtime being free, we are making a great use of it!). There is no particular issue except the references management. Our code analyses the Office version installed on the computer and automatically updates corresponding references (not only Access but also Excel, Outlook, Word, etc.: code is very tricky but of great interest!)</p>\n\n<p>To my own knowledge, no major objects, properties or methods available in Office 2003/VBA were deprecated in Office 2007. Office 2003 code will then run with Access 2007 once these references issues solved. Some new objects were introduced in Office 2007 so I would not advise any developer to use it to develop code to be further used with Access 2003.</p>\n\n<p>But the main &amp; real issue of your question is: why should one run both Access versions on the same computer? This is what I'd do if I want to make sure to crash my apps. I think that if your objectives were to develop software, you should definitely find a better configuration for your machine!</p>\n"}, {'answer_id': 75442, 'author': 'Jason Weathered', 'author_id': 3736, 'author_profile': 'https://Stackoverflow.com/users/3736', 'pm_score': 0, 'selected': False, 'text': '<p>In general, having multiple versions of Access installed on the one machine is unsupported and will result in the issues you are seeing with the object references.</p>\n\n<p>If the database is authored in Access 2003, compiled to an .MDE, and then deployed onto a separate Windows instance running Access 2007, you should not have any significant issues (other than UI changes such as custom toolbars being thrown into the Add-Ins ribbon).</p>\n\n<p>For testing on multiple versions of Access you will need some form of isolation between each version. I use multiple virtual machines to accomplish this. My primary Windows VM runnings Office 2007 and IE7 and I have a second VM which has Office 2003 and IE6 for testing.</p>\n\n<p>Note that if you wish to simply use Word, Excel and Outlook 2007 with Access 2003, you can install Access 2003 first by itself and then do a custom install of Office 2007 and deselect Access 2007.</p>\n'}, {'answer_id': 75757, 'author': 'Chris OC', 'author_id': 11041, 'author_profile': 'https://Stackoverflow.com/users/11041', 'pm_score': 2, 'selected': True, 'text': '<p>Microsoft\'s official position is that installing multiple office versions on the same pc is not supported and not recommended, and Access 2007 seems to be designed to prove that to us!</p>\n\n<p>That said, you can avoid most issues by doing the following:</p>\n\n<p>1 - Splitting the db into a back end and front end. Place the back end (tables and relationships) in a network folder, and place a copy of the front end (all other objects) on each user\'s desktop.</p>\n\n<p>2 - It\'s best to make the front end an mde to avoid the references shuffle every time you open the db in the other version of Access.</p>\n\n<p>3 - Create a shortcut to open the front end with the desired version of Access so it\'s <em>always</em> opened with that version. (And remember to use the shortcut!) In the shortcut\'s target:</p>\n\n<p>"path to Access 12 msaccess.exe" "path to db.mdb"</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/75246', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']
75,255
<p>When you're doing a usual gdb session on an executable file on the same computer, you can give the run command and it will start the program over again.</p> <p>When you're running gdb on an embedded system, as with the command <code>target localhost:3210</code>, how do you start the program over again without quitting and restarting your gdb session?</p>
[{'answer_id': 76727, 'author': 'Drew Frezell', 'author_id': 10954, 'author_profile': 'https://Stackoverflow.com/users/10954', 'pm_score': 3, 'selected': False, 'text': "<p>Unfortunately, I don't know of a way to restart the application and still maintain your session. A workaround is to set the PC back to the entry point of your program. You can do this by either calling:</p>\n\n<p><code>jump <em>function</em></code></p>\n\n<p>or </p>\n\n<p><code>set $pc=<em>address</em></code>.</p>\n\n<p>If you munged the arguments to <code>main</code> you may need set them up again.</p>\n\n<p>Edit:</p>\n\n<p>There are a couple of caveats with the above method that could cause problems.</p>\n\n<ul>\n<li>If you are in a multi-threaded program jumping to main will jump the current thread to main, all other threads remain. If the current thread held a lock...then you have some problems.</li>\n<li>Memory leaks, if you program flow allocates some stuff during initialization then you just leaked a bunch of memory with the jump.</li>\n<li>Open files will still remain open. If you mmap some files or an address, the call will most likely fail.</li>\n</ul>\n\n<p>So, using jump isn't the same thing as restarting the program.</p>\n"}, {'answer_id': 346019, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>Presumably you are running gdbserver on the embedded system.</p>\n\n<p>You can ask it to restart your program instead of exiting with <a href="http://web.archive.org/web/20090605020212/http://sourceware.org/gdb/current/onlinedocs/gdb_19.html" rel="nofollow noreferrer">target extended-remote</a></p>\n'}, {'answer_id': 1640110, 'author': 'Michael Snyder', 'author_id': 404880, 'author_profile': 'https://Stackoverflow.com/users/404880', 'pm_score': 2, 'selected': False, 'text': '<p>"jump _start" is the usual way.</p>\n'}, {'answer_id': 5200638, 'author': 'pdileepa', 'author_id': 55376, 'author_profile': 'https://Stackoverflow.com/users/55376', 'pm_score': 5, 'selected': True, 'text': '<p>You are looking for <a href="http://sourceware.org/gdb/onlinedocs/gdb/Server.html" rel="noreferrer">Multi-Process Mode for gdbserver</a> and <a href="http://sourceware.org/gdb/onlinedocs/gdb/Remote-Configuration.html" rel="noreferrer"><code>set remote exec-file filename</code></a></p>\n'}, {'answer_id': 35966136, 'author': 'Jehandad', 'author_id': 3840400, 'author_profile': 'https://Stackoverflow.com/users/3840400', 'pm_score': 2, 'selected': False, 'text': "<p>If you are running regular gdb you can type 'run' shortcut 'r' and gdb asks you if you wish to restart the program</p>\n"}, {'answer_id': 42813624, 'author': 'hermannk', 'author_id': 3186936, 'author_profile': 'https://Stackoverflow.com/users/3186936', 'pm_score': 2, 'selected': False, 'text': '<p>For me the method described in <a href="http://openocd.org/doc/html/GDB-and-OpenOCD.html#Sample-GDB-session-startup" rel="nofollow noreferrer">21.2 Sample GDB session startup</a> works great. When I enter <code>monitor reset halt</code> later at the “(gdb)” prompt the target hardware is reset and I can re-start the application with <code>c</code> (= continue).</p>\n\n<p>The <code>load</code> command can be omitted between the runs because there is no need to flash the program again and again.</p>\n'}, {'answer_id': 44161527, 'author': 'Ciro Santilli OurBigBook.com', 'author_id': 895245, 'author_profile': 'https://Stackoverflow.com/users/895245', 'pm_score': 2, 'selected': False, 'text': '<p><strong>Step-by-step procedure</strong></p>\n\n<p>Remote:</p>\n\n<pre><code># pwd contains cross-compiled ./myexec\ngdbserver --multi :1234\n</code></pre>\n\n<p>Local:</p>\n\n<pre><code># pwd also contains the same cross-compiled ./myexec\ngdb -ex \'target extended-remote 192.168.0.1:1234\' \\\n -ex \'set remote exec-file ./myexec\' \\\n --args ./myexec arg1 arg2\n(gdb) r\n[Inferior 1 (process 1234) exited normally]\n(gdb) r\n[Inferior 1 (process 1235) exited normally]\n(gdb) monitor exit\n</code></pre>\n\n<p>Tested in Ubuntu 14.04.</p>\n\n<p>It is also possible to pass CLI arguments to the program as:</p>\n\n<pre><code>gdbserver --multi :1234 ./myexec arg1 arg2\n</code></pre>\n\n<p>and the <code>./myexec</code> part removes the need for <code>set remote exec-file ./myexec</code>, but this has the following annoyances:</p>\n\n<ul>\n<li>undocumented: <a href="https://sourceware.org/bugzilla/show_bug.cgi?id=21981" rel="nofollow noreferrer">https://sourceware.org/bugzilla/show_bug.cgi?id=21981</a></li>\n<li>does not show on <code>show args</code> and does not persist across restarts: <a href="https://sourceware.org/bugzilla/show_bug.cgi?id=21980" rel="nofollow noreferrer">https://sourceware.org/bugzilla/show_bug.cgi?id=21980</a></li>\n</ul>\n\n<p>Pass environment variables and change working directory without restart: <a href="https://stackoverflow.com/questions/45149858/how-to-modify-the-environment-variables-of-gdbserver-without-restarting-it">How to modify the environment variables and working directory of gdbserver --multi without restarting it?</a></p>\n'}, {'answer_id': 44786145, 'author': 'Steven Eckhoff', 'author_id': 2511892, 'author_profile': 'https://Stackoverflow.com/users/2511892', 'pm_score': 0, 'selected': False, 'text': '<p>On EFM32 Happy Gecko none of the suggestions would work for me, so here is what I have learned from the documentation on integrating GDB into the Eclipse environment.</p>\n\n<pre><code>(gdb) mon reset 0\n(gdb) continue\n(gdb) continue\n</code></pre>\n\n<p>This puts me in the state that I would have expected when hitting reset from the IDE.</p>\n'}, {'answer_id': 67924905, 'author': 'abhiarora', 'author_id': 5735010, 'author_profile': 'https://Stackoverflow.com/users/5735010', 'pm_score': 1, 'selected': False, 'text': "<p>You can use <code>jump</code> gdb command. For that, you can check your <code>startup</code> script.\nMy <code>startup script</code> has a symbol.</p>\n<pre><code> .section .text.Reset_Handler\n .weak Reset_Handler\n .type Reset_Handler, %function\nReset_Handler: \n ldr r0, =_estack\n mov sp, r0 /* set stack pointer */\n</code></pre>\n<p>I wanted to jump to start. That's why I used:</p>\n<pre><code>jump Reset_Handler\n</code></pre>\n"}]
2008/09/16
['https://Stackoverflow.com/questions/75255', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/11138/']
75,258
<p>Nikhil Kothari's <a href="http://projects.nikhilk.net/ScriptSharp/" rel="nofollow noreferrer">Script#</a> is quite possibly one of the most amazing concepts I've seen in the JavaScript arena for quite some time. This question isn't about JavaScript, but rather about language compilation in the .NET runtime.</p> <p>I've been rather interested in how, using the .NET platform, one can write a compiler for a language that already has a compiler (like C#) that will generate separate output from the original compiler while allowing the original compiler to generate output for the same source during the same build operation, all the while referencing/using the output of the other compiler as well.</p> <p>I'm not entirely sure I even understand the process well enough to ask the question with the right details, but this is the way I currently see the process, as per diagrams in the Script# docs. I've thought about many things involving complex language design and compilation that may be able to take advantage of concepts like this and I'm interested in what other people think about the concepts.</p> <p>--</p> <p>Edit: Thanks for commenting,so far; your information is, in it's own right, very intriguing and I should like to research it more, but my question is actually about how I would be able to write my own compiler/s that can be run on the same source at the same time producing multiple different types of (potentially) interdependent output using the CLR. Script# serves as an example since it generates JavaScript and an Assembly using the same C# source, all the while making the compiled Assembly cooperate with the JavaScript. I'm curious what the various approaches and theoretical concepts are in designing something of this nature.</p>
[{'answer_id': 75397, 'author': 'ibz', 'author_id': 5475, 'author_profile': 'https://Stackoverflow.com/users/5475', 'pm_score': 0, 'selected': False, 'text': "<p>So let's say you want to compile C# into Javascript. You are asking whether you can take advantage of the existing C# compilers, so instead of compiling C# into Javascript directly you actually convert the MSIL generated by the C# compiler into Javascript?</p>\n\n<p>Sure, you can do that. Once you have the MSIL binary you can do whatever you want to it.</p>\n"}, {'answer_id': 75583, 'author': 'Lars Truijens', 'author_id': 1242, 'author_profile': 'https://Stackoverflow.com/users/1242', 'pm_score': 0, 'selected': False, 'text': '<p>Microsoft has a research project called <a href="http://labs.live.com/volta/" rel="nofollow noreferrer">Volta</a> which, amongst other things, compiles msil to JavaScript.</p>\n\n<blockquote>\n <p>a developer toolset for building\n multi-tier web applications using\n existing and familiar tools,\n techniques and patterns. Volta’s\n declarative tier-splitting enables\n developers to postpone architectural\n decisions about distribution until the\n last possible responsible moment.\n Also, thanks to a shared programming\n model across multiple-tiers, Volta\n enables new end-to-end profiling and\n testing for higher levels of\n application performance, robustness,\n and reliability. Using the declarative\n tier-splitting, developers can refine\n architectural decisions based on this\n profiling data. This saves time and\n costs associated with manual\n refactoring. In effect, Volta extends\n the .NET platform to further enable\n the development of software+services\n applications, using existing and\n familiar tools and techniques.</p>\n \n <p>You architect and build your\n application as a .NET client\n application, assigning the portions of\n the application that run on the server\n tier and client tier late in the\n development process. You can target\n either web browsers or the CLR as\n clients and Volta handles the\n complexities of tier-splitting. The\n compiler creates cross-browser\n JavaScript for the client tier, web\n services for the server tier, and all\n communication, serialization,\n synchronization, security, and other\n boilerplate code to tie the tiers\n together. In effect, Volta offers a\n best-effort experience in multiple\n environments without requiring\n tailoring of the application.</p>\n</blockquote>\n'}, {'answer_id': 155447, 'author': 'sirwart', 'author_id': 6222, 'author_profile': 'https://Stackoverflow.com/users/6222', 'pm_score': 3, 'selected': True, 'text': "<p>It's important to realize that all a compiler does is take a source language (C# in this case), parse it so the compiler has a representation that makes sense to it and not humans (this is the abstract syntax tree), and then does a naive code generation to the target language (msil is the target for languages that run on the .NET runtime).</p>\n\n<p>Now if the script# code is turned into an assembly and interacts with other .NET code, that means this compiler must be generating msil. script# is using csc.exe for this, which is just the standard c# comiler. Now to generate the javascript, it must take either c# or msil, parse it, and generate javascript to send to the browser. The docs says it has a custom c# -> js compiler called ssc.exe. </p>\n\n<p>To make things interact consistently on both the client side and the server side it has a set of reference assemblies that are written in .NET but are also compiled to javascript. This is not a compiler specific issue though, those reference assemblies are the script# runtime. The runtime is probably responsible for a lot of the script# magic you're perceiving though.</p>\n"}]
2008/09/16
['https://Stackoverflow.com/questions/75258', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/8543/']
75,261
<p>I got this output when running <code>sudo cpan Scalar::Util::Numeric</code></p> <pre> jmm@freekbox:~/bfwsandbox/sa/angel/astroportal/dtu8e/resources$ sudo cpan Scalar::Util::Numeric [sudo] password for jmm: CPAN: Storable loaded ok Going to read /home/jmm/.cpan/Metadata Database was generated on Tue, 09 Sep 2008 16:02:51 GMT CPAN: LWP::UserAgent loaded ok Fetching with LWP: ftp://ftp.perl.org/pub/CPAN/authors/01mailrc.txt.gz Going to read /home/jmm/.cpan/sources/authors/01mailrc.txt.gz Fetching with LWP: ftp://ftp.perl.org/pub/CPAN/modules/02packages.details.txt.gz Going to read /home/jmm/.cpan/sources/modules/02packages.details.txt.gz Database was generated on Tue, 16 Sep 2008 16:02:50 GMT There's a new CPAN.pm version (v1.9205) available! [Current version is v1.7602] You might want to try install Bundle::CPAN reload cpan without quitting the current session. It should be a seamless upgrade while we are running... Fetching with LWP: ftp://ftp.perl.org/pub/CPAN/modules/03modlist.data.gz Going to read /home/jmm/.cpan/sources/modules/03modlist.data.gz Going to write /home/jmm/.cpan/Metadata Running install for module Scalar::Util::Numeric Running make for C/CH/CHOCOLATE/Scalar-Util-Numeric-0.02.tar.gz CPAN: Digest::MD5 loaded ok Checksum for /home/jmm/.cpan/sources/authors/id/C/CH/CHOCOLATE/Scalar-Util-Numeric-0.02.tar.gz ok Scanning cache /home/jmm/.cpan/build for sizes Scalar-Util-Numeric-0.02/ Scalar-Util-Numeric-0.02/Changes Scalar-Util-Numeric-0.02/lib/ Scalar-Util-Numeric-0.02/lib/Scalar/ Scalar-Util-Numeric-0.02/lib/Scalar/Util/ Scalar-Util-Numeric-0.02/lib/Scalar/Util/Numeric.pm Scalar-Util-Numeric-0.02/Makefile.PL Scalar-Util-Numeric-0.02/MANIFEST Scalar-Util-Numeric-0.02/META.yml Scalar-Util-Numeric-0.02/Numeric.xs Scalar-Util-Numeric-0.02/ppport.h Scalar-Util-Numeric-0.02/README Scalar-Util-Numeric-0.02/t/ Scalar-Util-Numeric-0.02/t/pod.t Scalar-Util-Numeric-0.02/t/Scalar-Util-Numeric.t Removing previously used /home/jmm/.cpan/build/Scalar-Util-Numeric-0.02 CPAN.pm: Going to build C/CH/CHOCOLATE/Scalar-Util-Numeric-0.02.tar.gz Checking if your kit is complete... Looks good Writing Makefile for Scalar::Util::Numeric cp lib/Scalar/Util/Numeric.pm blib/lib/Scalar/Util/Numeric.pm AutoSplitting blib/lib/Scalar/Util/Numeric.pm (blib/lib/auto/Scalar/Util/Numeric) /usr/bin/perl /usr/share/perl/5.8/ExtUtils/xsubpp -typemap /usr/share/perl/5.8/ExtUtils/typemap Numeric.xs > Numeric.xsc && mv Numeric.xsc Numeric.c cc -c -D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O3 -DVERSION=\"0.02\" -DXS_VERSION=\"0.02\" -fPIC "-I/usr/lib/perl/5.8/CORE" Numeric.c In file included from Numeric.xs:2: /usr/lib/perl/5.8/CORE/perl.h:420:24: error: sys/types.h: No such file or directory /usr/lib/perl/5.8/CORE/perl.h:451:19: error: ctype.h: No such file or directory /usr/lib/perl/5.8/CORE/perl.h:463:23: error: locale.h: No such file or directory /usr/lib/perl/5.8/CORE/perl.h:480:20: error: setjmp.h: No such file or directory /usr/lib/perl/5.8/CORE/perl.h:486:26: error: sys/param.h: No such file or directory /usr/lib/perl/5.8/CORE/perl.h:491:23: error: stdlib.h: No such file or directory /usr/lib/perl/5.8/CORE/perl.h:496:23: error: unistd.h: No such file or directory /usr/lib/perl/5.8/CORE/perl.h:776:23: error: string.h: No such file or directory /usr/lib/perl/5.8/CORE/perl.h:925:27: error: netinet/in.h: No such file or directory /usr/lib/perl/5.8/CORE/perl.h:929:26: error: arpa/inet.h: No such file or directory /usr/lib/perl/5.8/CORE/perl.h:939:25: error: sys/stat.h: No such file or directory /usr/lib/perl/5.8/CORE/perl.h:961:21: error: time.h: No such file or directory /usr/lib/perl/5.8/CORE/perl.h:968:25: error: sys/time.h: No such file or directory /usr/lib/perl/5.8/CORE/perl.h:975:27: error: sys/times.h: No such file or directory /usr/lib/perl/5.8/CORE/perl.h:982:19: error: errno.h: No such file or directory /usr/lib/perl/5.8/CORE/perl.h:997:25: error: sys/socket.h: No such file or directory /usr/lib/perl/5.8/CORE/perl.h:1024:21: error: netdb.h: No such file or directory /usr/lib/perl/5.8/CORE/perl.h:1127:24: error: sys/ioctl.h: No such file or directory /usr/lib/perl/5.8/CORE/perl.h:1156:23: error: dirent.h: No such file or directory In file included from /usr/lib/gcc/i486-linux-gnu/4.2.3/include/syslimits.h:7, from /usr/lib/gcc/i486-linux-gnu/4.2.3/include/limits.h:11, from /usr/lib/perl/5.8/CORE/perl.h:1510, from Numeric.xs:2: /usr/lib/gcc/i486-linux-gnu/4.2.3/include/limits.h:122:61: error: limits.h: No such file or directory In file included from /usr/lib/perl/5.8/CORE/perl.h:2120, from Numeric.xs:2: /usr/lib/perl/5.8/CORE/handy.h:136:25: error: inttypes.h: No such file or directory In file included from /usr/lib/perl/5.8/CORE/perl.h:2284, from Numeric.xs:2: /usr/lib/perl/5.8/CORE/unixish.h:106:21: error: signal.h: No such file or directory In file included from Numeric.xs:2: /usr/lib/perl/5.8/CORE/perl.h:2421:33: error: pthread.h: No such file or directory In file included from Numeric.xs:2: /usr/lib/perl/5.8/CORE/perl.h:2423: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘perl_os_thread’ /usr/lib/perl/5.8/CORE/perl.h:2424: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘perl_mutex’ /usr/lib/perl/5.8/CORE/perl.h:2425: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘perl_cond’ /usr/lib/perl/5.8/CORE/perl.h:2426: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘perl_key’ In file included from /usr/lib/perl/5.8/CORE/iperlsys.h:51, from /usr/lib/perl/5.8/CORE/perl.h:2733, from Numeric.xs:2: /usr/lib/perl/5.8/CORE/perlio.h:65:19: error: stdio.h: No such file or directory In file included from /usr/lib/perl/5.8/CORE/iperlsys.h:51, from /usr/lib/perl/5.8/CORE/perl.h:2733, from Numeric.xs:2: /usr/lib/perl/5.8/CORE/perlio.h:259: error: expected ‘)’ before ‘*’ token /usr/lib/perl/5.8/CORE/perlio.h:262: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token /usr/lib/perl/5.8/CORE/perlio.h:265: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token /usr/lib/perl/5.8/CORE/perlio.h:268: error: expected declaration specifiers or ‘...’ before ‘FILE’ In file included from /usr/lib/perl/5.8/CORE/perl.h:2747, from Numeric.xs:2: /usr/lib/perl/5.8/CORE/sv.h:389: error: expected specifier-qualifier-list before ‘DIR’ In file included from /usr/lib/perl/5.8/CORE/op.h:497, from /usr/lib/perl/5.8/CORE/perl.h:2754, from Numeric.xs:2: /usr/lib/perl/5.8/CORE/reentr.h:72:20: error: pwd.h: No such file or directory /usr/lib/perl/5.8/CORE/reentr.h:75:20: error: grp.h: No such file or directory /usr/lib/perl/5.8/CORE/reentr.h:85:26: error: crypt.h: No such file or directory /usr/lib/perl/5.8/CORE/reentr.h:90:27: error: shadow.h: No such file or directory In file included from /usr/lib/perl/5.8/CORE/op.h:497, from /usr/lib/perl/5.8/CORE/perl.h:2754, from Numeric.xs:2: /usr/lib/perl/5.8/CORE/reentr.h:612: error: field ‘_crypt_struct’ has incomplete type /usr/lib/perl/5.8/CORE/reentr.h:620: error: field ‘_drand48_struct’ has incomplete type /usr/lib/perl/5.8/CORE/reentr.h:624: error: field ‘_grent_struct’ has incomplete type /usr/lib/perl/5.8/CORE/reentr.h:635: error: field ‘_hostent_struct’ has incomplete type /usr/lib/perl/5.8/CORE/reentr.h:654: error: field ‘_netent_struct’ has incomplete type /usr/lib/perl/5.8/CORE/reentr.h:669: error: field ‘_protoent_struct’ has incomplete type /usr/lib/perl/5.8/CORE/reentr.h:684: error: field ‘_pwent_struct’ has incomplete type /usr/lib/perl/5.8/CORE/reentr.h:695: error: field ‘_servent_struct’ has incomplete type /usr/lib/perl/5.8/CORE/reentr.h:710: error: field ‘_spent_struct’ has incomplete type /usr/lib/perl/5.8/CORE/reentr.h:721: error: field ‘_gmtime_struct’ has incomplete type /usr/lib/perl/5.8/CORE/reentr.h:724: error: field ‘_localtime_struct’ has incomplete type /usr/lib/perl/5.8/CORE/reentr.h:771: error: field ‘_random_struct’ has incomplete type /usr/lib/perl/5.8/CORE/reentr.h:772: error: expected specifier-qualifier-list before ‘int32_t’ In file included from /usr/lib/perl/5.8/CORE/perl.h:2756, from Numeric.xs:2: /usr/lib/perl/5.8/CORE/av.h:13: error: expected specifier-qualifier-list before ‘ssize_t’ In file included from /usr/lib/perl/5.8/CORE/perl.h:2759, from Numeric.xs:2: /usr/lib/perl/5.8/CORE/scope.h:232: error: expected specifier-qualifier-list before ‘sigjmp_buf’ In file included from Numeric.xs:2: /usr/lib/perl/5.8/CORE/perl.h:2931: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘getuid’ /usr/lib/perl/5.8/CORE/perl.h:2932: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘geteuid’ /usr/lib/perl/5.8/CORE/perl.h:2933: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘getgid’ /usr/lib/perl/5.8/CORE/perl.h:2934: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘getegid’ In file included from Numeric.xs:2: /usr/lib/perl/5.8/CORE/perl.h:3238:22: error: math.h: No such file or directory In file included from /usr/lib/perl/5.8/CORE/perl.h:3881, from Numeric.xs:2: /usr/lib/perl/5.8/CORE/thrdvar.h:85: error: field ‘Tstatbuf’ has incomplete type /usr/lib/perl/5.8/CORE/thrdvar.h:86: error: field ‘Tstatcache’ has incomplete type /usr/lib/perl/5.8/CORE/thrdvar.h:91: error: field ‘Ttimesbuf’ has incomplete type In file included from /usr/lib/perl/5.8/CORE/perl.h:3883, from Numeric.xs:2: /usr/lib/perl/5.8/CORE/intrpvar.h:66: error: expected specifier-qualifier-list before ‘time_t’ In file included from /usr/lib/perl/5.8/CORE/perl.h:3950, from Numeric.xs:2: /usr/lib/perl/5.8/CORE/proto.h:128: error: expected declaration specifiers or ‘...’ before ‘mode_t’ /usr/lib/perl/5.8/CORE/proto.h:128: error: expected declaration specifiers or ‘...’ before ‘uid_t’ /usr/lib/perl/5.8/CORE/proto.h:297: error: expected declaration specifiers or ‘...’ before ‘off64_t’ /usr/lib/perl/5.8/CORE/proto.h:299: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘Perl_do_sysseek’ /usr/lib/perl/5.8/CORE/proto.h:300: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘Perl_do_tell’ /usr/lib/perl/5.8/CORE/proto.h:411: error: expected declaration specifiers or ‘...’ before ‘gid_t’ /usr/lib/perl/5.8/CORE/proto.h:411: error: expected declaration specifiers or ‘...’ before ‘uid_t’ /usr/lib/perl/5.8/CORE/proto.h:736: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘Perl_my_fork’ /usr/lib/perl/5.8/CORE/proto.h:1020: error: expected declaration specifiers or ‘...’ before ‘pid_t’ /usr/lib/perl/5.8/CORE/proto.h:1300: error: expected declaration specifiers or ‘...’ before ‘pid_t’ /usr/lib/perl/5.8/CORE/proto.h:1456: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token /usr/lib/perl/5.8/CORE/proto.h:2001: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘Perl_PerlIO_read’ /usr/lib/perl/5.8/CORE/proto.h:2002: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘Perl_PerlIO_write’ /usr/lib/perl/5.8/CORE/proto.h:2003: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘Perl_PerlIO_unread’ /usr/lib/perl/5.8/CORE/proto.h:2004: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘Perl_PerlIO_tell’ /usr/lib/perl/5.8/CORE/proto.h:2005: error: expected declaration specifiers or ‘...’ before ‘off64_t’ In file included from /usr/lib/perl/5.8/CORE/perl.h:3988, from Numeric.xs:2: /usr/lib/perl/5.8/CORE/perlvars.h:31: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PL_thr_key’ /usr/lib/perl/5.8/CORE/perlvars.h:48: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PL_op_mutex’ /usr/lib/perl/5.8/CORE/perlvars.h:52: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PL_dollarzero_mutex’ /usr/lib/perl/5.8/CORE/perl.h:4485:24: error: sys/ipc.h: No such file or directory /usr/lib/perl/5.8/CORE/perl.h:4486:24: error: sys/sem.h: No such file or directory /usr/lib/perl/5.8/CORE/perl.h:4611:24: error: sys/file.h: No such file or directory In file included from /usr/lib/perl/5.8/CORE/perlapi.h:38, from /usr/lib/perl/5.8/CORE/XSUB.h:349, from Numeric.xs:3: /usr/lib/perl/5.8/CORE/intrpvar.h:66: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token /usr/lib/perl/5.8/CORE/intrpvar.h:237: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token /usr/lib/perl/5.8/CORE/intrpvar.h:238: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token /usr/lib/perl/5.8/CORE/intrpvar.h:239: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token /usr/lib/perl/5.8/CORE/intrpvar.h:240: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token In file included from /usr/lib/perl/5.8/CORE/perlapi.h:39, from /usr/lib/perl/5.8/CORE/XSUB.h:349, from Numeric.xs:3: /usr/lib/perl/5.8/CORE/perlvars.h:31: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token /usr/lib/perl/5.8/CORE/perlvars.h:48: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token /usr/lib/perl/5.8/CORE/perlvars.h:52: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token In file included from Numeric.xs:4: ppport.h:3042:1: warning: "PERL_UNUSED_DECL" redefined In file included from Numeric.xs:2: /usr/lib/perl/5.8/CORE/perl.h:163:1: warning: this is the location of the previous definition Numeric.c: In function ‘XS_Scalar__Util__Numeric_is_num’: Numeric.c:20: error: invalid type argument of ‘unary *’ Numeric.c:20: error: invalid type argument of ‘unary *’ Numeric.c:20: error: invalid type argument of ‘unary *’ Numeric.c:22: error: invalid type argument of ‘unary *’ Numeric.c:24: error: invalid type argument of ‘unary *’ Numeric.xs:16: error: invalid type argument of ‘unary *’ Numeric.xs:17: error: invalid type argument of ‘unary *’ Numeric.xs:20: error: invalid type argument of ‘unary *’ Numeric.xs:20: error: invalid type argument of ‘unary *’ Numeric.xs:20: error: invalid type argument of ‘unary *’ Numeric.xs:20: error: invalid type argument of ‘unary *’ Numeric.xs:20: error: invalid type argument of ‘unary *’ Numeric.c:36: error: invalid type argument of ‘unary *’ Numeric.c:36: error: invalid type argument of ‘unary *’ Numeric.c: In function ‘XS_Scalar__Util__Numeric_uvmax’: Numeric.c:43: error: invalid type argument of ‘unary *’ Numeric.c:43: error: invalid type argument of ‘unary *’ Numeric.c:43: error: invalid type argument of ‘unary *’ Numeric.c:45: error: invalid type argument of ‘unary *’ Numeric.xs:26: error: invalid type argument of ‘unary *’ Numeric.xs:26: error: invalid type argument of ‘unary *’ Numeric.xs:26: error: invalid type argument of ‘unary *’ Numeric.xs:26: error: invalid type argument of ‘unary *’ Numeric.xs:26: error: invalid type argument of ‘unary *’ Numeric.c:51: error: invalid type argument of ‘unary *’ Numeric.c:51: error: invalid type argument of ‘unary *’ Numeric.c: In function ‘boot_Scalar__Util__Numeric’: Numeric.c:60: error: invalid type argument of ‘unary *’ Numeric.c:60: error: invalid type argument of ‘unary *’ Numeric.c:60: error: invalid type argument of ‘unary *’ Numeric.c:63: error: invalid type argument of ‘unary *’ Numeric.c:63: error: invalid type argument of ‘unary *’ Numeric.c:63: error: invalid type argument of ‘unary *’ Numeric.c:63: error: invalid type argument of ‘unary *’ Numeric.c:63: error: invalid type argument of ‘unary *’ Numeric.c:63: error: invalid type argument of ‘unary *’ Numeric.c:63: error: invalid type argument of ‘unary *’ Numeric.c:63: error: invalid type argument of ‘unary *’ Numeric.c:63: error: invalid type argument of ‘unary *’ Numeric.c:63: error: invalid type argument of ‘unary *’ Numeric.c:63: error: invalid type argument of ‘unary *’ Numeric.c:65: error: invalid type argument of ‘unary *’ Numeric.c:65: error: invalid type argument of ‘unary *’ Numeric.c:66: error: invalid type argument of ‘unary *’ Numeric.c:66: error: invalid type argument of ‘unary *’ Numeric.c:67: error: invalid type argument of ‘unary *’ Numeric.c:67: error: invalid type argument of ‘unary *’ Numeric.c:67: error: invalid type argument of ‘unary *’ Numeric.c:67: error: invalid type argument of ‘unary *’ make: *** [Numeric.o] Error 1 /usr/bin/make -- NOT OK Running make test Can't test without successful make Running make install make had returned bad status, install seems impossible jmm@freekbox:~/bfwsandbox/sa/angel/astroportal/dtu8e/resources$ </pre>
[{'answer_id': 75320, 'author': 'Leon Timmermans', 'author_id': 4727, 'author_profile': 'https://Stackoverflow.com/users/4727', 'pm_score': 2, 'selected': False, 'text': "<p>It can't find basic system headers. Either your include path is seriously messed up, or the headers are not installed.</p>\n"}, {'answer_id': 75395, 'author': 'amoore', 'author_id': 7573, 'author_profile': 'https://Stackoverflow.com/users/7573', 'pm_score': 5, 'selected': True, 'text': "<p>You're missing your C library development headers. You should install a package that has them. These are necessary to install this module because it has to compile some non-perl C code and needs to know more about your system.</p>\n\n<p>I can't tell what kind of operating system you're on, but it looks like linux. If it's debian, you should be able to use apt-get to install the 'libc6-dev' package. That will contain the headers you need to compile this module. On other types of linux there will be a similarly named package.</p>\n"}, {'answer_id': 75399, 'author': 'Mark Grimes', 'author_id': 13233, 'author_profile': 'https://Stackoverflow.com/users/13233', 'pm_score': 2, 'selected': False, 'text': '<p>Awfully hard to read without line breaks, but it looks like you are missing <code>sys/types.h</code> on your system. Do you have a full build environment installed (gcc, make, etc.)? What OS and distribution are you using?</p>\n\n<p>In the future, you should bockquote output like this (select the text and click the quote button).</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/75261', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']
75,267
<p>In how many languages is Null not equal to anything not even Null?</p>
[{'answer_id': 75278, 'author': 'Josh Bush', 'author_id': 1672, 'author_profile': 'https://Stackoverflow.com/users/1672', 'pm_score': 2, 'selected': False, 'text': '<p>Oracle is this way.</p>\n\n<pre><code>SELECT * FROM dual WHERE NULL=null; --no rows returned\n</code></pre>\n'}, {'answer_id': 75314, 'author': 'Jonathan Rupp', 'author_id': 12502, 'author_profile': 'https://Stackoverflow.com/users/12502', 'pm_score': 5, 'selected': True, 'text': "<p>It's this way in SQL (as a logic language) because null means unknown/undefined.</p>\n\n<p>However, in programming languages (like say, C++ or C#), a null pointer/reference is a specific value with a specific meaning -- nothing.</p>\n\n<p>Two nothings are equivilent, but two unknowns are not. The confusion comes from the fact that the same name (null) is used for both concepts.</p>\n"}, {'answer_id': 75366, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>MySQL has a null-safe equality operator, &lt;=>, which returns true if both sides are equal or both sides are null. See <a href="http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#operator_equal-to" rel="nofollow noreferrer">MySQL Docs</a>.</p>\n'}, {'answer_id': 75472, 'author': 'AShelly', 'author_id': 10396, 'author_profile': 'https://Stackoverflow.com/users/10396', 'pm_score': 2, 'selected': False, 'text': '<p>You can make ruby work that way:</p>\n\n<pre><code>class Null\n def self.==(other);false;end\nend\nn=Null\nprint "Null equals nothing" if n!=Null\n</code></pre>\n'}, {'answer_id': 137965, 'author': 'Hugh Allen', 'author_id': 15069, 'author_profile': 'https://Stackoverflow.com/users/15069', 'pm_score': 2, 'selected': False, 'text': '<p>In VB6 the expression <code>Null = Null</code> will produce <code>Null</code> instead of <code>True</code> as you would expect.\nThis will cause a runtime error if you try to assign it to a Boolean, however if you use it\nas the condition of "<code>If ... Then</code>" it will act like <code>False</code>. Moreover <code>Null &lt;&gt; Null</code> will <strong>also</strong>\nproduce <code>Null</code>, so:</p>\n\n<p><strong>In VB6 you could say that <code>Null</code> is neither equal to itself (or anything else), nor unequal!</strong></p>\n\n<p>You\'re supposed to test for it using the <code>IsNull()</code> function.</p>\n\n<p>VB6 also has other special values:</p>\n\n<ul>\n<li><code>Nothing</code> for object references. <code>Nothing = Nothing</code> is a compile error. (you\'re supposed to compare it using "<code>is</code>")</li>\n<li><code>Missing</code> for optional parameters which haven\'t been given. It has no literal representation so you can\'t even write <code>Missing = Missing</code>. (the test is <code>IsMissing(foo)</code>)</li>\n<li><code>Empty</code> for uninitialized variables. This one does test equal to itself although there\'s <strong>also</strong> a function <code>IsEmpty()</code>.</li>\n<li>... let me know if I\'ve forgotten one</li>\n</ul>\n\n<p>I remember being a bit disgusted with VB.</p>\n'}, {'answer_id': 138047, 'author': 'Jeffrey L Whitledge', 'author_id': 10174, 'author_profile': 'https://Stackoverflow.com/users/10174', 'pm_score': 2, 'selected': False, 'text': '<p>In C#, Nullable&lt;bool&gt; has interesting properties with respect to logical operators, but the equality operator is the same as other types in that language (i.e., ((bool?)null == (bool?)null) == true).</p>\n\n<p>To preserve the <a href="http://en.wikipedia.org/wiki/Short-circuit_evaluation" rel="nofollow noreferrer">short-circuited</a> behavior of the short-circuited logical operators, and to preserve consistency with the non-short-circuited logical operators, the nullable boolean has some interesting properties. For example: true || null == true. false &amp;&amp; null == false, etc. This stands in direct contradiction with other three-valued logic languages such as <a href="http://en.wikipedia.org/wiki/SQL#Standardization" rel="nofollow noreferrer">ANSI SQL</a>.</p>\n'}, {'answer_id': 1805207, 'author': 'Stephane Grenier', 'author_id': 39371, 'author_profile': 'https://Stackoverflow.com/users/39371', 'pm_score': 0, 'selected': False, 'text': '<p>In SQL you would have to do something like:</p>\n\n<pre><code>WHERE column is NULL\n</code></pre>\n\n<p>rather than</p>\n\n<pre><code>WHERE column = NULL\n</code></pre>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/75267', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/6178/']
75,270
<p>Does anyone know of a good open source plugin for database querying and exploring within Eclipse? </p> <p>The active Database Exploring plugin within Eclipse is really geared around being associated with a Java project. While I am just trying to run ad-hoc queries and explore the schema. I am effectively looking for a just a common, quick querying tool without the overhead of having to create a code project. I have found a couple open source database plugins for Eclipse but these have not seen active development in over a year.</p> <p>Any suggestions?</p>
[{'answer_id': 75278, 'author': 'Josh Bush', 'author_id': 1672, 'author_profile': 'https://Stackoverflow.com/users/1672', 'pm_score': 2, 'selected': False, 'text': '<p>Oracle is this way.</p>\n\n<pre><code>SELECT * FROM dual WHERE NULL=null; --no rows returned\n</code></pre>\n'}, {'answer_id': 75314, 'author': 'Jonathan Rupp', 'author_id': 12502, 'author_profile': 'https://Stackoverflow.com/users/12502', 'pm_score': 5, 'selected': True, 'text': "<p>It's this way in SQL (as a logic language) because null means unknown/undefined.</p>\n\n<p>However, in programming languages (like say, C++ or C#), a null pointer/reference is a specific value with a specific meaning -- nothing.</p>\n\n<p>Two nothings are equivilent, but two unknowns are not. The confusion comes from the fact that the same name (null) is used for both concepts.</p>\n"}, {'answer_id': 75366, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>MySQL has a null-safe equality operator, &lt;=>, which returns true if both sides are equal or both sides are null. See <a href="http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#operator_equal-to" rel="nofollow noreferrer">MySQL Docs</a>.</p>\n'}, {'answer_id': 75472, 'author': 'AShelly', 'author_id': 10396, 'author_profile': 'https://Stackoverflow.com/users/10396', 'pm_score': 2, 'selected': False, 'text': '<p>You can make ruby work that way:</p>\n\n<pre><code>class Null\n def self.==(other);false;end\nend\nn=Null\nprint "Null equals nothing" if n!=Null\n</code></pre>\n'}, {'answer_id': 137965, 'author': 'Hugh Allen', 'author_id': 15069, 'author_profile': 'https://Stackoverflow.com/users/15069', 'pm_score': 2, 'selected': False, 'text': '<p>In VB6 the expression <code>Null = Null</code> will produce <code>Null</code> instead of <code>True</code> as you would expect.\nThis will cause a runtime error if you try to assign it to a Boolean, however if you use it\nas the condition of "<code>If ... Then</code>" it will act like <code>False</code>. Moreover <code>Null &lt;&gt; Null</code> will <strong>also</strong>\nproduce <code>Null</code>, so:</p>\n\n<p><strong>In VB6 you could say that <code>Null</code> is neither equal to itself (or anything else), nor unequal!</strong></p>\n\n<p>You\'re supposed to test for it using the <code>IsNull()</code> function.</p>\n\n<p>VB6 also has other special values:</p>\n\n<ul>\n<li><code>Nothing</code> for object references. <code>Nothing = Nothing</code> is a compile error. (you\'re supposed to compare it using "<code>is</code>")</li>\n<li><code>Missing</code> for optional parameters which haven\'t been given. It has no literal representation so you can\'t even write <code>Missing = Missing</code>. (the test is <code>IsMissing(foo)</code>)</li>\n<li><code>Empty</code> for uninitialized variables. This one does test equal to itself although there\'s <strong>also</strong> a function <code>IsEmpty()</code>.</li>\n<li>... let me know if I\'ve forgotten one</li>\n</ul>\n\n<p>I remember being a bit disgusted with VB.</p>\n'}, {'answer_id': 138047, 'author': 'Jeffrey L Whitledge', 'author_id': 10174, 'author_profile': 'https://Stackoverflow.com/users/10174', 'pm_score': 2, 'selected': False, 'text': '<p>In C#, Nullable&lt;bool&gt; has interesting properties with respect to logical operators, but the equality operator is the same as other types in that language (i.e., ((bool?)null == (bool?)null) == true).</p>\n\n<p>To preserve the <a href="http://en.wikipedia.org/wiki/Short-circuit_evaluation" rel="nofollow noreferrer">short-circuited</a> behavior of the short-circuited logical operators, and to preserve consistency with the non-short-circuited logical operators, the nullable boolean has some interesting properties. For example: true || null == true. false &amp;&amp; null == false, etc. This stands in direct contradiction with other three-valued logic languages such as <a href="http://en.wikipedia.org/wiki/SQL#Standardization" rel="nofollow noreferrer">ANSI SQL</a>.</p>\n'}, {'answer_id': 1805207, 'author': 'Stephane Grenier', 'author_id': 39371, 'author_profile': 'https://Stackoverflow.com/users/39371', 'pm_score': 0, 'selected': False, 'text': '<p>In SQL you would have to do something like:</p>\n\n<pre><code>WHERE column is NULL\n</code></pre>\n\n<p>rather than</p>\n\n<pre><code>WHERE column = NULL\n</code></pre>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/75270', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12600/']
75,273
<p>I'm in an <strong>ASP.NET UserControl</strong>. When I type Control-K, Control-D to reformat all the markup, I get a series of messages from VS 2008:</p> <p>"Could not reformat the document. The original format was restored."</p> <p>"Could not complete the action."</p> <p>"The operation could not be completed. The parameter is incorrect."</p> <p>Anybody know what causes this?</p> <p><strong>Edit</strong>: OK, that is just...weird.</p> <p>The problem is here:</p> <pre><code>&lt;asp:TableCell&gt; &lt;asp:Button Text="Cancel" runat="server" ID="lnkCancel" CssClass="CellSingleItem" /&gt; &lt;/asp:TableCell&gt; </code></pre> <p>Somehow that asp:Button line is causing the problem. But if I delete any individual attribute, the formatting works. Or if I add a new attribute, the formatting works. Or if I change the tag to be non-self-closing, it works. But if I undo and leave it as-is, it doesn't work.</p> <p>All I can figure is that this is some sort of really obscure, bizarre bug.</p>
[{'answer_id': 75283, 'author': 'John Sheehan', 'author_id': 1786, 'author_profile': 'https://Stackoverflow.com/users/1786', 'pm_score': 4, 'selected': True, 'text': "<p>There's probably some malformed markup somewhere in your document. Have you tried it on a fresh document?</p>\n"}, {'answer_id': 75305, 'author': 'Steve Morgan', 'author_id': 5806, 'author_profile': 'https://Stackoverflow.com/users/5806', 'pm_score': 1, 'selected': False, 'text': '<p>I encountered this for the first time a few weeks ago. I found it was down to invalid HTML. I had to cut out sections of content and paste it back in a little at a time to track down the problem.</p>\n'}, {'answer_id': 75308, 'author': 'palehorse', 'author_id': 312, 'author_profile': 'https://Stackoverflow.com/users/312', 'pm_score': 2, 'selected': False, 'text': '<p>Usually this sort of behavior is caused by invalid code. It may only be invalid HTML causing it which would still allow the program to be compiled.</p>\n\n<p>For example, if tags are mismatched like this the IDE cannot reformat it.</p>\n\n<pre><code>&lt;div&gt;&lt;h1&gt;My Title&lt;/div&gt;&lt;/h1\n</code></pre>\n\n<p>Check your warnings to see if there are any entries pointing towards mismatched or unclosed tags.</p>\n'}, {'answer_id': 1849607, 'author': 'Calvin', 'author_id': 225079, 'author_profile': 'https://Stackoverflow.com/users/225079', 'pm_score': 1, 'selected': False, 'text': '<p>For me, I had some bogus characters in my markup code. I only found this out by copy and pasting all my text into Notepad. After that, I saw the bogus characters (showed up as little squares). I just deleted those lines and retyped them and now everything is ok.</p>\n'}, {'answer_id': 2026362, 'author': 'Iman', 'author_id': 184572, 'author_profile': 'https://Stackoverflow.com/users/184572', 'pm_score': 2, 'selected': False, 'text': '<p>select the entire suspicious codes segments and use Ctrl+k,Ctrl+F to format only the selected segments instead of whole document .</p>\n\n<p>this way you can find the exact place of problems specially not closed or inappropriate closed tags and fix them .</p>\n\n<p>after all scanning segment by segment is done you can format the whole document for sure</p>\n'}, {'answer_id': 3549709, 'author': 'jordanbtucker', 'author_id': 164430, 'author_profile': 'https://Stackoverflow.com/users/164430', 'pm_score': 2, 'selected': False, 'text': '<p>For me, it\'s usually as issue with whitespace. To fix it, I open Find and Replace (CTRL+H), set <strong>Look in</strong> to "Current Document", check <strong>Use</strong> and select "Regular expressions". For <strong>Find what</strong> I enter ":b|\\n" (minus quotes), and for <strong>Replace with</strong> I enter a single space. Then I click <strong>Replace All</strong>.</p>\n\n<p>The steps above will replace all whitespace—including line breaks—with a single space, and the next time you format the document, you shouldn\'t get any errors. That is assuming you don\'t have malformed HTML.</p>\n'}, {'answer_id': 7331909, 'author': 'Olle89', 'author_id': 596847, 'author_profile': 'https://Stackoverflow.com/users/596847', 'pm_score': 3, 'selected': False, 'text': '<p>Did get the problem today.</p>\n\n<p>My solution: Restart Visual Studio</p>\n'}, {'answer_id': 41345298, 'author': 'ViVi', 'author_id': 5621607, 'author_profile': 'https://Stackoverflow.com/users/5621607', 'pm_score': 0, 'selected': False, 'text': '<p>Just to add some more information. This issue is caused due to some invalid markup in <code>html</code>. \nIt won\'t cause any blocking while running the application. </p>\n\n<p>Unfortunately the solutions mentioned here did not work for me.\n1. Restarting visual studio\n2. Replacing spaces using regex etc</p>\n\n<p>The best solution to fix the issue is to go to the specific line where the issue is caused and check that line for any invalid symbols like <code>,</code> or <code>"</code>. Just remove it and it will work fine.</p>\n'}, {'answer_id': 48592288, 'author': 'Sterling Diaz', 'author_id': 1228807, 'author_profile': 'https://Stackoverflow.com/users/1228807', 'pm_score': 2, 'selected': False, 'text': '<p>My problem was an extra <code>"</code>. Look carefully the html.</p>\n'}, {'answer_id': 58850704, 'author': 'ydinesh', 'author_id': 5891802, 'author_profile': 'https://Stackoverflow.com/users/5891802', 'pm_score': 0, 'selected': False, 'text': '<p>My issue is extra " in the value of html attribute, After removing this it is working fine for me.</p>\n'}, {'answer_id': 66116857, 'author': 'Prince Tyagi', 'author_id': 14886434, 'author_profile': 'https://Stackoverflow.com/users/14886434', 'pm_score': 1, 'selected': False, 'text': '<p>I had an unwanted semi-colon. But you may have quote (\'), double quote (&quot;), semi-colon (;) or any special character.</p>\n<p>So, editing my answer with more details and a screenshot because it still very active.</p>\n<p><a href="https://i.stack.imgur.com/7jn4Z.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7jn4Z.png" alt="enter image description here" /></a></p>\n<p>Go to that line by double clicking the error and search for the extra (unwanted) quote (\'), double quote (&quot;), semi-colon (;) or any special character. Remove it because it is causing the error.</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/75273', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5486/']
75,282
<p>I'm handling the <code>onSelectIndexChanged</code> event. An event is raised when the DropDownList selection changes. the problem is that the DropDownList still returns the old values for <code>SelectedValue</code> and <code>SelectedIndex</code>. What am I doing wrong?</p> <p>Here is the DropDownList definition from the aspx file:</p> <pre><code>&lt;div style="margin: 0px; padding: 0px 1em 0px 0px;"&gt; &lt;span style="margin: 0px; padding: 0px; vertical-align: top;"&gt;Route:&lt;/span&gt; &lt;asp:DropDownList id="Select1" runat="server" onselectedindexchanged="index_changed" AutoPostBack="true"&gt; &lt;/asp:DropDownList&gt; &lt;asp:Literal ID="Literal1" runat="server"&gt;&lt;/asp:Literal&gt; &lt;/div&gt; </code></pre> <p>Here is the DropDownList <code>OnSelectedIndexChanged</code> event handler:</p> <pre><code>protected void index_changed(object sender, EventArgs e) { decimal d = Convert.ToDecimal( Select1.SelectedValue ); Literal1.Text = d.ToString(); } </code></pre>
[{'answer_id': 75306, 'author': 'Mitchel Sellers', 'author_id': 13279, 'author_profile': 'https://Stackoverflow.com/users/13279', 'pm_score': 5, 'selected': True, 'text': '<p>Do you have any code in page load that is by chance re-defaulting the value to the first value?</p>\n\n<p>When the page reloads do you see the new value?</p>\n'}, {'answer_id': 75383, 'author': 'Donn Felker', 'author_id': 5210, 'author_profile': 'https://Stackoverflow.com/users/5210', 'pm_score': 0, 'selected': False, 'text': '<p>Is it possible that you have items copied throughout your datasource for the drop down list? </p>\n'}, {'answer_id': 75389, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>add this:\nif page.isnotpostback {</p>\n\n<p>}\naround your code to bind the dropdownlist. </p>\n'}, {'answer_id': 75437, 'author': 'axk', 'author_id': 578, 'author_profile': 'https://Stackoverflow.com/users/578', 'pm_score': 2, 'selected': False, 'text': '<p>This may seem obvious, but anyway.\nDo you initialize this dropdown with an initial value in some other event handler like OnLoad ?\nIf so you should check if that event is risen by a postback or by the first load. So you should have something like</p>\n\n<pre><code>if(!IsPostback) d.SelectedValue = "Default"\n</code></pre>\n'}, {'answer_id': 75827, 'author': 'Jason Stevenson', 'author_id': 13368, 'author_profile': 'https://Stackoverflow.com/users/13368', 'pm_score': 2, 'selected': False, 'text': '<p>If you are using AJAX you may also be doing a callback, not a full postback. In that case you may want to use this in your page load method:</p>\n\n<pre><code> if (!IsCallback &amp;&amp; !IsPostBack)\n {\n // Do your page setup here\n }\n</code></pre>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/75282', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4491/']
75,303
<p>Lisp developed a set of interesting language features quite early on in the academic world, but most of them never caught on in production environments.</p> <p>Some languages, like JavaScript, adapted basic features like garbage collection and lexical closures, but all the stuff that might actually change how you write programs on a large scale, like powerful macros, the code-as-data thing and custom control structures, only seems to propagate within other functional languages, none of which are practical to use for non-trivial projects.</p> <p>The functional programming community also came up with a lot of other interesting ideas (apart from functional programming itself), like referential transparency, generalised case-expressions (ie, pattern-matching, not crippled like C/C# switches) and curried functions, which seem obviously useful in regular programming and should be easy to integrate with existing programming practice, but for some reason seem to be stuck in the academic world forever.</p> <p>Why do these features have such a hard time getting adopted? Are there any modern, practical languages that actually learn from Lisp instead of half-assedly copying "first class functions", or is there an inherent conflict that makes this impossible?</p>
[{'answer_id': 75349, 'author': 'sblundy', 'author_id': 4893, 'author_profile': 'https://Stackoverflow.com/users/4893', 'pm_score': 3, 'selected': False, 'text': '<p><a href="http://www.scala-lang.org" rel="nofollow noreferrer">Scala</a> is a cool functional/OO language with pattern matching, first class functions, and the like. It has the advantage of compiling to Java bytecode and inter-operates well with Java code.</p>\n'}, {'answer_id': 75358, 'author': 'Josh', 'author_id': 11702, 'author_profile': 'https://Stackoverflow.com/users/11702', 'pm_score': 2, 'selected': False, 'text': '<p>Have you checked out <a href="http://research.microsoft.com/fsharp/fsharp.aspx" rel="nofollow noreferrer">F#</a></p>\n'}, {'answer_id': 75406, 'author': 'Mendelt', 'author_id': 3320, 'author_profile': 'https://Stackoverflow.com/users/3320', 'pm_score': 2, 'selected': False, 'text': "<p>Lot's of dynamic programming languages implement ideas from functional programming. The newer .Net languages (C# and VB) have what they call lambda's but these aren't side effect free.</p>\n\n<p>It's not difficult combining concepts from functional programming and object oriented programming for example but it doesn't always make a lot of sense. Object oriented languages (try to) encapsulate state inside objects while functional languages encapsulate state inside functions. If you combine objects and functions in one language it gets harder to make sense of all this.</p>\n\n<p>There have been a lot of languages that have combined these paradigms by just throwing them together (F#) and this can be usefull but I think we still need a couple of decades of playing with languages like this untill we can create a new paradigm that succesfully will combine the ideas from oo and functional programming.</p>\n"}, {'answer_id': 75448, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>C# 3.0 definitely does.</p>\n\n<p>C# now has </p>\n\n<ol>\n<li>Lambda Expressions</li>\n<li>Higher Order Functions </li>\n<li>Map / Reduce + Filter ( Folding?) to lists and all types which implement IEnumerable.</li>\n<li>LINQ</li>\n<li>Object + Collection Initializers.</li>\n</ol>\n\n<p>The last two list items may not fall under proper functional programming, anyways the answer is C# has implemented many useful concepts from Lisp etc.</p>\n'}, {'answer_id': 75514, 'author': 'Paul Reiners', 'author_id': 7648, 'author_profile': 'https://Stackoverflow.com/users/7648', 'pm_score': 3, 'selected': False, 'text': '<p>Python or Ruby. See Paul Graham\'s <a href="http://www.paulgraham.com/lispfaq1.html" rel="nofollow noreferrer">thoughts on this</a> in the question "I like Lisp but my company won\'t let me use it. What should I do?".</p>\n'}, {'answer_id': 75638, 'author': 'Christopher Cashell', 'author_id': 13091, 'author_profile': 'https://Stackoverflow.com/users/13091', 'pm_score': 2, 'selected': False, 'text': "<p>Lua.</p>\n\n<p>It's used as a scripting/extension language for a number of games (like World of Worcraft), and applications (Snort, NMAP, Wireshark, etc). In fact, according to an Adobe developer, Adobe's Lightroom is over 40% Lua.</p>\n\n<p>The guys behind Lua have repeatedly listed Scheme and Lisp as major influences on Lua, and Lua has even been described as Scheme without the parentheses.</p>\n"}, {'answer_id': 75736, 'author': 'nlucaroni', 'author_id': 157, 'author_profile': 'https://Stackoverflow.com/users/157', 'pm_score': 4, 'selected': False, 'text': '<blockquote>\n <p><em>Are there any modern, practical\n languages that actually learn from\n Lisp instead of half-assedly copying\n "first class functions", or is there\n an inherent conflict that makes this\n impossible?</em></p>\n</blockquote>\n\n<p>Why aren\'t lisp, haskell, ocaml, or f# modern?</p>\n\n<p>You might just need to take it on yourself and look at them and realize that they are more robust, with libraries like java, then you\'d think.</p>\n\n<p>A lot of features have been adopted from functional languages to other languages. But vice versa -- (some) functional languages have objects, for example.</p>\n'}, {'answer_id': 76259, 'author': 'Luís Oliveira', 'author_id': 2967, 'author_profile': 'https://Stackoverflow.com/users/2967', 'pm_score': 3, 'selected': False, 'text': '<p>Common Lisp, used in the real-world albeit not wildely so, I guess.</p>\n'}, {'answer_id': 76297, 'author': 'Daniel Spiewak', 'author_id': 9815, 'author_profile': 'https://Stackoverflow.com/users/9815', 'pm_score': 3, 'selected': False, 'text': '<p>Scala is the absolute king of languages which have adopted significant academic features. Higher kinds, self types, polymorphic pattern matching, etc. All of these are bleeding-edge (or near to it) academic research topics that have been incorporated into Scala as fundamental features. Arguably, this has been to the detriment of the langauge\'s simplicity, but it does lead to some very interesting patterns.</p>\n\n<p>C# is more mainstream than Scala, but it also has adopted fewer of these "out-there" functional features. LINQ is a limited implementation for Wadler\'s generalized list comprehensions, and everyone knows about lambdas. But for all that, C# (rightfully) remains a bit conservative in adopting research features from the academic world.</p>\n'}, {'answer_id': 76369, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': False, 'text': '<p>Erlang has recently gained renewed exposure not only through being used by Twitter, but also by the rise of XMPP driven messaging and implementations such as ejabberd. It sports many of the ideas coming from functional programming being a language designed with that in mind. Initially used to run Telephone switches and conceived by Ericson to run the first GSM networks. It is still around, it is fully functional (as a language) and used in many production environments. </p>\n'}, {'answer_id': 76413, 'author': 'ima', 'author_id': 5733, 'author_profile': 'https://Stackoverflow.com/users/5733', 'pm_score': 2, 'selected': False, 'text': '<p>In addition to what was said, a lot of LISP goodness is based on guaranteed lack of side-effects and using built-in data structures. Both rarely hold in real world. ML is probably better functional base.</p>\n'}, {'answer_id': 78137, 'author': 'drewr', 'author_id': 3227, 'author_profile': 'https://Stackoverflow.com/users/3227', 'pm_score': 3, 'selected': False, 'text': '<p>I suggest you try <a href="http://clojure.org" rel="noreferrer">Clojure</a>. Syntactically beautiful dialect, functional (in the ML sense), and <em>fast</em>. You get immutability, software transactional memory, multiversion concurrency control, a REPL, SLIME support, and an inexhaustible FFI. It\'s the Lisp (&amp; Haskell) for the Business Programmer. I\'m having a great time using it daily in my real job.</p>\n'}, {'answer_id': 79009, 'author': 'jfm3', 'author_id': 11138, 'author_profile': 'https://Stackoverflow.com/users/11138', 'pm_score': 3, 'selected': False, 'text': '<p>There is no known correlation between a language "catching on" and whether or not is has powerful, well researched, well designed features.</p>\n\n<p>A lot has been said on the subject. It exists all over the place in technology, and also the arts. We know artist A has more training and produces works of greater breadth and depth than artist B, yet artist B is far more successful in the marketplace. Is it because there\'s a zeitgeist? Is is because artist B has better marketing? Is it because most people won\'t take the time to understand artist A? Maybe artist B is secretly awful and we should mistrust experts who make judgements about artists? Probably all of the above, to some degree or another. </p>\n\n<p>This drives people who study the arts, and people who study programming languages, crazy.</p>\n'}, {'answer_id': 188105, 'author': 'Thedric Walker', 'author_id': 26166, 'author_profile': 'https://Stackoverflow.com/users/26166', 'pm_score': 1, 'selected': False, 'text': '<p>Another "real-world" language that implements functional programming features is Javascript. Since absolutely everything has a value, then high-order functions are easily implemented. You also have other tenants of functional programming such as lambda functions, closures, and currying.</p>\n'}, {'answer_id': 216232, 'author': 'J D', 'author_id': 13924, 'author_profile': 'https://Stackoverflow.com/users/13924', 'pm_score': 0, 'selected': False, 'text': '<p>The features you refer to ("powerful" macros, the code-as-data thing and custom control structures) have not propagated within other functional languages. They died after Lisp taught us that they are a bad idea.</p>\n\n<p>Modern functional languages (OCaml, Haskell, Erlang, Scala, F#, C# 3.0, JavaScript) do not have those features.</p>\n\n<p>Cheers,\nJon Harrop.</p>\n'}, {'answer_id': 216273, 'author': 'David Hicks', 'author_id': 3653, 'author_profile': 'https://Stackoverflow.com/users/3653', 'pm_score': 2, 'selected': False, 'text': '<blockquote>\n <p>Lisp developed a set of interesting language features quite early on in the academic\n world, but most of them never caught on in production environments.</p>\n</blockquote>\n\n<p>Because the kind of people who manage software developers aren\'t the kinds of people who you can have an interesting chat comparing different language features with. Around 2000, I wanted to use LISP to implement XML-to-HTML transforms on our corporate website (this is around the time of Amazon implementing their backend in LISP). I didn\'t get to. This is mildly ironic seeing as the company I was working for made and sold a <a href="http://en.wikipedia.org/wiki/LispWorks" rel="nofollow noreferrer">Common LISP environment</a>.</p>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/75303', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4607/']
75,322
<p>I have an ASP.Net/AJAX control kit project that i am working on. 80% of the time there is no problem. The page runs as it should. If you refresh the page it will sometimes show a javascript error "Sys is undefined".</p> <p>It doesn't happen all the time, but it is reproducible. When it happens, the user has to shut down their browser and reopen the page.</p> <p>This leads me to believe that it could be an IIS setting.</p> <p>Another note. I looked at the page source both when I get the error, and when not. When the page throws errors the following code is missing:</p> <pre><code>&lt;script src="/ScriptResource.axd?d=EAvfjPfYejDh0Z2Zq5zTR_TXqL0DgVcj_h1wz8cst6uXazNiprV1LnAGq3uL8N2vRbpXu46VsAMFGSgpfovx9_cO8tpy2so6Qm_0HXVGg_Y1&amp;amp;t=baeb8cc" type="text/javascript"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; //&lt;![CDATA[ if (typeof(Sys) === 'undefined') throw new Error('ASP.NET Ajax client-side framework failed to load.'); //]]&gt; &lt;/script&gt; </code></pre>
[{'answer_id': 75460, 'author': 'Compulsion', 'author_id': 3675, 'author_profile': 'https://Stackoverflow.com/users/3675', 'pm_score': 3, 'selected': False, 'text': '<p>Try setting your ScriptManager to this.</p>\n\n<pre><code>&lt;asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" /&gt; \n</code></pre>\n'}, {'answer_id': 97842, 'author': 'Aaron Powell', 'author_id': 11388, 'author_profile': 'https://Stackoverflow.com/users/11388', 'pm_score': 2, 'selected': False, 'text': '<p>In addition to ensuring you have the ScriptManager on your page you need to ensure that your web.config is appropriately configured.</p>\n\n<p>When ASP.NET AJAX 1.0 was released (for .NET 2.0) there was a lot of custom web.config settings which added handlers, controls, etc.</p>\n\n<p>You\'ll find the config info here: <a href="http://www.asp.net/AJAX/documentation/live/ConfiguringASPNETAJAX.aspx" rel="nofollow noreferrer">http://www.asp.net/AJAX/documentation/live/ConfiguringASPNETAJAX.aspx</a></p>\n'}, {'answer_id': 200316, 'author': 'Tom Carter', 'author_id': 2839, 'author_profile': 'https://Stackoverflow.com/users/2839', 'pm_score': 2, 'selected': False, 'text': "<p>Make sure that any client scripts you have that interact with .NET AJAX have the following line at the end:</p>\n\n<pre><code>if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();\n</code></pre>\n\n<p>This tells the script manager that the whole script file has loaded and that it can begin to call client methods</p>\n"}, {'answer_id': 538200, 'author': 'MadMax1138', 'author_id': 65187, 'author_profile': 'https://Stackoverflow.com/users/65187', 'pm_score': 2, 'selected': False, 'text': '<p>I was having this same issue and after much wrangling I decided to try and isolate the problem and simply load the script manager in an empty page which still resulted in this same error. Having isolated the problem I discovered through a comparison of my site\'s web.config with a brand new (working) test site that changing <code>&lt;compilation debug="true"&gt;</code> to <code>&lt;compilation debug="false"&gt;</code> in the system.web section of my web.config fixes the problem. </p>\n\n<p>I also had to remove the <code>&lt;xhtmlConformance mode="Legacy"/&gt;</code> entry from system.web to make the update panel work properly. <a href="http://weblogs.asp.net/scottgu/archive/2006/12/10/gotcha-don-t-use-xhtmlconformance-mode-legacy-with-asp-net-ajax.aspx" rel="nofollow noreferrer">Click here</a> for a description of this issue.</p>\n'}, {'answer_id': 678245, 'author': 'TygerKrash', 'author_id': 7652, 'author_profile': 'https://Stackoverflow.com/users/7652', 'pm_score': 0, 'selected': False, 'text': '<p>Was having a similar issue, except that my page was consistently generating the Sys is undefined error. </p>\n\n<p>For me the problem stems from the fact that I\'ve just installed the AJAX 1.0 extension for .NET 2.0 but had already created my web project in Visual Studio.</p>\n\n<p>When tried to create AJAX controls I kept encountering this error, I spotted Slace\'s and MadMax1138s posts here. And figured it was my web.config, I created a new project using the new "AJAX enabled web site" project type, and sure enough the web.config has a large number of customizations necessary to use the AJAX controls. </p>\n\n<p>I just updated that web.config with the web.config updates I had already made myself and dropped it into my existing project and everything worked fine.</p>\n'}, {'answer_id': 1718513, 'author': 'Dean L', 'author_id': 127887, 'author_profile': 'https://Stackoverflow.com/users/127887', 'pm_score': 6, 'selected': False, 'text': '<p>I fixed my problem by moving the <code>&lt;script type="text/javascript"&gt;&lt;/script&gt;</code> block containing the Sys.* calls lower down (to the last item before the close of the body\'s <code>&lt;asp:Content/&gt;</code> section) in the HTML on the page. I originally had my the script block in the HEAD <code>&lt;asp:Content/&gt;</code> section of my page. I was working inside a page that had a MasterPageFile. Hope this helps someone out.</p>\n'}, {'answer_id': 2563888, 'author': 'Ray', 'author_id': 4872, 'author_profile': 'https://Stackoverflow.com/users/4872', 'pm_score': 4, 'selected': False, 'text': '<p>When I experienced the errors </p>\n\n<ul>\n<li>Sys is undefined</li>\n<li>ASP.NET Ajax client-side framework failed to load</li>\n</ul>\n\n<p>in IE when using ASP.NET Ajax controls in .NET 2.0, I needed to add the following to the web.config file within the <code>&lt;system.web&gt;</code> tags:</p>\n\n<pre><code>&lt;httpHandlers&gt;\n &lt;remove verb="*" path="*.asmx"/&gt;\n &lt;add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&gt;\n &lt;add verb="GET" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler" validate="false"/&gt;\n&lt;/httpHandlers&gt;\n</code></pre>\n'}, {'answer_id': 2789879, 'author': 'Arsalan', 'author_id': 335611, 'author_profile': 'https://Stackoverflow.com/users/335611', 'pm_score': -1, 'selected': False, 'text': "<p>Please please please do check that the Server has the correct time and date set...</p>\n\n<p>After about wasting 6 hours, i read it somewhere...</p>\n\n<p>The date and time for the server must be updated to work correctly...</p>\n\n<p>otherwise you will get 'Sys' is undefined error.</p>\n"}, {'answer_id': 2856354, 'author': 'kaash', 'author_id': 343901, 'author_profile': 'https://Stackoverflow.com/users/343901', 'pm_score': -1, 'selected': False, 'text': '<p>Just create blank .axd files in your solutions root foder problem will be resolved. (2 file: scriptresouce.asx, webresource.asxd)</p>\n'}, {'answer_id': 3511184, 'author': 'g9ncom', 'author_id': 341062, 'author_profile': 'https://Stackoverflow.com/users/341062', 'pm_score': 0, 'selected': False, 'text': '<p>I have been seeing the exact same error today, but it was not a config or direct JavaScript issue.</p>\n\n<p>An external .net project had been updated but the changes not picked up properly in the compilation of the web site. My presumption is that ASP.NET ajax was not able to construct the client representations of the .NET objects properly and so was failing to load correctly.</p>\n\n<p>To resolve, I rebuilt the external project(s), and rebuilt my solution that was experiencing issues. The problem went away. </p>\n'}, {'answer_id': 3757770, 'author': 'Anish', 'author_id': 453539, 'author_profile': 'https://Stackoverflow.com/users/453539', 'pm_score': -1, 'selected': False, 'text': '<p>Hi thanx a lot it solved my issue ,</p>\n\n<p>By default vs 2008 will add </p>\n\n<pre><code> &lt;!--&lt;add verb="*" path="*.asmx" validate="false" type="Microsoft.Web.Script.Services.ScriptHandlerFactory, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /&gt;\n &lt;add verb="GET" path="ScriptResource.axd" type="Microsoft.Web.Handlers.ScriptResourceHandler" validate="false" /&gt;--&gt;\n</code></pre>\n\n<p>Need to correct Default config(Above) to below code\n<strong>FIX</strong></p>\n\n<pre><code> &lt;add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&gt;\n &lt;add verb="GET" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler" validate="false"/&gt;\n</code></pre>\n'}, {'answer_id': 4260550, 'author': 'Alcides Martínez', 'author_id': 518003, 'author_profile': 'https://Stackoverflow.com/users/518003', 'pm_score': 3, 'selected': False, 'text': '<p>You must add these lines in the web.config</p>\n\n<p>\n \n \n \n \n \n \n \n \n \n \n </p>\n\n<pre><code>&lt;httpHandlers&gt;\n &lt;remove verb="*" path="*.asmx"/&gt;\n &lt;add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&gt;\n &lt;add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&gt;\n &lt;add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/&gt;\n&lt;/httpHandlers&gt;\n&lt;httpModules&gt;\n &lt;add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&gt;\n&lt;/httpModules&gt;\n&lt;/system.web&gt;\n</code></pre>\n\n<p>\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n </p>\n\n<p>Hope this helps.</p>\n'}, {'answer_id': 6020313, 'author': 'JonK', 'author_id': 755955, 'author_profile': 'https://Stackoverflow.com/users/755955', 'pm_score': 0, 'selected': False, 'text': '<p>I found the error when using a combination of the Ajax Control Toolkit ToolkitScriptManager and URL Write 2.0.</p>\n\n<p>In my <code>&lt;rewrite&gt; &lt;outboundRules&gt;</code> I had a precondition:</p>\n\n<pre><code>&lt;preConditions&gt;\n &lt;preCondition name="IsHTML"&gt;\n &lt;add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html"/&gt;\n &lt;/preCondition&gt;\n&lt;/preConditions&gt;\n</code></pre>\n\n<p>But apparently some of my outbound rules weren\'t set to use the precondition. </p>\n\n<p>Once I had that preCondition set on all my outbound rules:</p>\n\n<pre><code>&lt;rule preCondition="IsHTML" name="MyOutboundRule"&gt;\n</code></pre>\n\n<p>No more problem. </p>\n'}, {'answer_id': 6291807, 'author': 'Zara_me', 'author_id': 121336, 'author_profile': 'https://Stackoverflow.com/users/121336', 'pm_score': 1, 'selected': False, 'text': '<p>I solved this problem by creating separate asp.net ajax solution and copy and paste all ajax configuration from web.config to working project.</p>\n\n<p>here are the must configuration you should set in web.config</p>\n\n<pre><code> &lt;configuration&gt;\n&lt;configSections&gt;\n &lt;sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"&gt;\n &lt;sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"&gt;\n &lt;section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/&gt;\n&lt;/sectionGroup&gt;\n\n &lt;/sectionGroup&gt;\n&lt;/configSections&gt;\n</code></pre>\n\n<p></p>\n\n<pre><code> &lt;assemblies&gt;\n\n &lt;add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&gt;\n\n &lt;/assemblies&gt;\n &lt;/compilation&gt;\n &lt;httpHandlers&gt;\n &lt;remove verb="*" path="*.asmx"/&gt;\n &lt;add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&gt;\n &lt;add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&gt;\n &lt;add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/&gt;\n &lt;/httpHandlers&gt;\n &lt;httpModules&gt;\n &lt;add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&gt;\n &lt;/httpModules&gt;\n&lt;/system.web&gt;\n &lt;system.webServer&gt;\n &lt;validation validateIntegratedModeConfiguration="false"/&gt;\n &lt;modules&gt;\n &lt;add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&gt;\n &lt;/modules&gt;\n &lt;handlers&gt;\n &lt;remove name="WebServiceHandlerFactory-Integrated"/&gt;\n &lt;add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&gt;\n &lt;add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&gt;\n &lt;add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&gt;\n &lt;/handlers&gt;\n&lt;/system.webServer&gt;\n</code></pre>\n'}, {'answer_id': 6870078, 'author': 'Max', 'author_id': 260093, 'author_profile': 'https://Stackoverflow.com/users/260093', 'pm_score': 0, 'selected': False, 'text': '<p>Make sure you don\'t have any Rewrite rules that change your url.</p>\n\n<p>In my case the application thought it was only level deeper then the url reached.</p>\n\n<p>Example: <a href="http://mysite.com/app/page.aspx" rel="nofollow">http://mysite.com/app/page.aspx</a> was the real url.\nBut i cut off /app/ this worked fine for ASP.net and WCF, but clearly not for Ajax.</p>\n'}, {'answer_id': 9350258, 'author': 'Zviadi', 'author_id': 299203, 'author_profile': 'https://Stackoverflow.com/users/299203', 'pm_score': 3, 'selected': False, 'text': '<p>I was using telerik and had exactly same problem.</p>\n\n<p>adding this to web.config resolved my issue :)</p>\n\n<pre><code>&lt;location path="Telerik.Web.UI.WebResource.axd"&gt; \n &lt;system.web&gt; \n &lt;authorization&gt; \n &lt;allow users="*"/&gt; \n &lt;/authorization&gt; \n &lt;/system.web&gt; \n&lt;/location&gt;\n</code></pre>\n\n<p>maybe it will help you too. it was Authentication problem.</p>\n\n<p><a href="http://blogs.telerik.com/blogs/posts/10-03-16/common-reasons-for-the-lsquo-sys-is-undefined-rsquo-error-in-asp-net-ajax-applications.aspx" rel="nofollow">Source</a></p>\n'}, {'answer_id': 9442728, 'author': 'v s', 'author_id': 1023156, 'author_profile': 'https://Stackoverflow.com/users/1023156', 'pm_score': 0, 'selected': False, 'text': '<p>I had similar problems and to my surprise what I found that one of my developer had saved web.config in the same folder/solution as <strong>web123.config</strong> and by mistake both of these files were uploaded.</p>\n\n<p>As soon as I deleted the <strong>web123.config</strong> file, this error disappeared and ajax framework was loading correctly. even though I have </p>\n\n<pre><code>&lt;compilation debug="true"&gt;\n</code></pre>\n\n<p>In my case I also have following segment. My project is using framework 3.5</p>\n\n<pre><code> &lt;httpHandlers&gt;\n &lt;remove verb="*" path="*.asmx"/&gt;\n &lt;add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&gt;\n &lt;add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&gt;\n &lt;add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/&gt;\n&lt;/httpHandlers&gt;\n&lt;httpModules&gt;\n &lt;add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&gt;\n&lt;/httpModules&gt;\n&lt;/system.web&gt;\n</code></pre>\n'}, {'answer_id': 11031391, 'author': 'Carl Onager', 'author_id': 1400368, 'author_profile': 'https://Stackoverflow.com/users/1400368', 'pm_score': 0, 'selected': False, 'text': "<p>This is going to sound stupid but I had a similar problem with a site being developed in VS2010 and hosted in the VS Dev Server. The page in question had a scriptmanager to create the connection to a wcf service. I added an extra method to the service and this error started appearing. </p>\n\n<p>What fixed it for me was changing from 'Auto-assign Port' to 'Specific port' with a different port number in the oroject Web settings.</p>\n\n<p>I wish I knew why...</p>\n"}, {'answer_id': 13631823, 'author': 'GoldBishop', 'author_id': 659246, 'author_profile': 'https://Stackoverflow.com/users/659246', 'pm_score': 0, 'selected': False, 'text': 'Development Environment:\n<ul>\n<li>Dev-Env: VS 2012</li>\n<li>FX: 4.0/4.5</li>\n<li>Implementations: Master(ScriptManager + UpdatePanel/Timer) + Content (UpdatePanel)</li>\n<li>Patterns: PageRouting.</li>\n</ul>\n<h2>Disclaimer:</h2>\n<p>If all the <code>web.config</code> solutions do not work for you and you have implemented PageRouting (IIS 7+), then the code snippet below will solve your problems.</p>\n<h2>Background:</h2>\n<p>Dont mean to Highjack this question but had the same problem as everyone else and implemented 100% of the suggestions here, with minor modifications for .Net 4.0/4.5, and none of them worked for me.</p>\n<p>In my situation i had implemented <a href="http://msdn.microsoft.com/en-us/library/cc668201.aspx" rel="nofollow noreferrer">Page Routing</a> which was ghosting my problem. Basically it would work for about 20, or so, debug runs and then BAM would error out with the <code>Sys is undefined</code> error.</p>\n<p>After reviewing a couple other posts, that got to talking about the Clean-URL logic, i remembered that i had done PageRouting setup\'s.</p>\n<p>Here is the resource i used to build my patterns: <a href="http://msdn.microsoft.com/en-us/library/cc668201.aspx" rel="nofollow noreferrer">Page Routing</a></p>\n<p>My one-liner code fixed my VS2012 Debugging problem:</p>\n<pre><code>rts.Ignore(&quot;{resource}.axd/{*pathInfo}&quot;) \'Ignores any Resource cache references, used heavily in AJAX interactions.\n</code></pre>\n'}, {'answer_id': 14865444, 'author': 'Mahesh', 'author_id': 446154, 'author_profile': 'https://Stackoverflow.com/users/446154', 'pm_score': 0, 'selected': False, 'text': '<p>Even after adding the correct entry for web config still getting this error ? most common reason for this error is JavaScript that references the Sys namespace too early.\nThen most obvious fix would be move the java script block below the ScriptManager control:</p>\n'}, {'answer_id': 16109767, 'author': 'RacerNerd', 'author_id': 1634605, 'author_profile': 'https://Stackoverflow.com/users/1634605', 'pm_score': 0, 'selected': False, 'text': '<p>I don\'t think this point has been added and since I just spent some time hunting this down I hope it can help.<br/><br/>\nI am working with IIS 7 and using the ASP.NET v4 Framework.<br/>\nIn my case it was <strong>important that an entry be added to both the and section of the entry in the web.config file.</strong><br/><br/>\nMy web.config file has a lot of handlers and in my case it was easiest to add the ScriptResources entry to the top of the handlers section. <strong>Most importantly, it needs to be placed before any entry that will act as a wildcard and capture the request.</strong> Adding it after a wildcard entry will cause it to be ignored and the error will still appear.<br/><br/>The module can be added to the top or bottom of the section.<br/><br/>\nWeb.config Sample:</p>\n\n<pre><code>&lt;system.webServer&gt;\n &lt;handlers&gt;\n &lt;clear /&gt;\n &lt;add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /&gt;\n &lt;!-- Make sure wildcard rules are below the ScriptResource tag --&gt;\n &lt;/handlers&gt;\n &lt;modules&gt;\n &lt;add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&gt;\n &lt;!-- Other modules are added here --&gt;\n &lt;/modules&gt;\n &lt;/system.webServer&gt;\n</code></pre>\n'}, {'answer_id': 16822213, 'author': 'David Glass', 'author_id': 1521279, 'author_profile': 'https://Stackoverflow.com/users/1521279', 'pm_score': 1, 'selected': False, 'text': '<p>In case none of the above works for you, and you happen to be overriding OnPreRenderComplete, make sure you call base.OnPreRenderComplete. My therapist is going to be happy to see me back</p>\n'}, {'answer_id': 17256975, 'author': 'goodeye', 'author_id': 292060, 'author_profile': 'https://Stackoverflow.com/users/292060', 'pm_score': 3, 'selected': False, 'text': '<p>Dean L\'s answer, <a href="https://stackoverflow.com/a/1718513/292060">https://stackoverflow.com/a/1718513/292060</a> worked for me, since my call to Sys was also too early. Since I\'m using jQuery, instead of moving it down, I put the script inside a document.ready call:</p>\n\n<pre><code>$(document).ready(function () {\n Sys. calls here\n});\n</code></pre>\n\n<p>This seems to be late enough that Sys is available.</p>\n'}, {'answer_id': 18301056, 'author': 'Farschidus', 'author_id': 1379217, 'author_profile': 'https://Stackoverflow.com/users/1379217', 'pm_score': 1, 'selected': False, 'text': "<p>I had the same problem after updating my AjaxControlToolkit.dll to the latest version 4.1.7.725 from 4.1.60623.0. \nI've searched and came up to this page, but none of the answers help me.\nAfter looking to the sample website of the Ajax Control Toolkit that is in the CodePlex zip file, I have realized that the <code>&lt;asp:ScriptManager&gt;</code> replaced by the new <code>&lt;ajaxtoolkit:ToolkitScriptManager&gt;</code>. I did so and there is no <em>Sys.Extended is undefined</em> any more.</p>\n"}, {'answer_id': 28965519, 'author': 'onlyme', 'author_id': 3954673, 'author_profile': 'https://Stackoverflow.com/users/3954673', 'pm_score': 0, 'selected': False, 'text': '<p>I had same probleme but i fixed it by: </p>\n\n<p>When putting a script file into a page, make sure it is </p>\n\n<pre><code>&lt;script&gt;&lt;/script&gt; and not &lt;script /&gt;.\n</code></pre>\n\n<p>I have followed this:\n<a href="http://forums.asp.net/t/1742435.aspx?An+element+with+id+form1+could+not+be+found+Script+error+on+page+load" rel="nofollow">http://forums.asp.net/t/1742435.aspx?An+element+with+id+form1+could+not+be+found+Script+error+on+page+load</a></p>\n\n<p>Hope this will help</p>\n'}, {'answer_id': 30093900, 'author': 'Jawad Siddiqui', 'author_id': 1085016, 'author_profile': 'https://Stackoverflow.com/users/1085016', 'pm_score': 0, 'selected': False, 'text': '<p>Add</p>\n\n<pre><code>if (typeof(Sys) !== \'undefined\') Sys.Application.notifyScriptLoaded(); \n</code></pre>\n\n<p>Please check <a href="https://msdn.microsoft.com/en-us/library/vstudio/bb310952(v=vs.100).aspx" rel="nofollow">enter link description here</a></p>\n'}, {'answer_id': 32057625, 'author': 'Alexandre N.', 'author_id': 1398758, 'author_profile': 'https://Stackoverflow.com/users/1398758', 'pm_score': 3, 'selected': False, 'text': '<p>Try one of this solutions: </p>\n\n<p><strong>1. The browser fails to load the compressed script</strong></p>\n\n<p>This is usually the case if you get the error on IE6, but not on other browsers.</p>\n\n<p>The Script Resource Handler – ScriptResource.axd compresses the scripts before returning them to the browser. In pre-RTM releases, the handler did it all the time for all browsers, and it wasn’t configurable. There is an issue in one of the components of IE6 that prevents it from loading compressed scripts correctly. See KB article <a href="http://support.microsoft.com/default.aspx?scid=kb;en-us;Q312496" rel="noreferrer">here</a>. In RTM builds, we’ve made two fixes for this. One, we don’t compress if IE6 is the browser client. Two, we’ve now made compression configurable. Here’s how you can toggle the web.config.</p>\n\n<p>How do you fix it? First, make sure you are using the AJAX Extensions 1.0 RTM release. That alone should be enough. You can also try turning off compression by editing your web.config to have the following:</p>\n\n<pre><code>&lt;system.web.extensions&gt;\n&lt;scripting&gt;\n&lt;scriptResourceHandler enableCompression="false" enableCaching="true" /&gt;\n&lt;/scripting&gt;\n&lt;/system.web.extensions&gt;\n</code></pre>\n\n<p><strong>2. The required configuration for ScriptResourceHandler doesn’t exist for the web.config for your application</strong></p>\n\n<p>Make sure your web.config contains the entries from the default web.config file provided with the extensions install. (default location: C:\\Program Files\\Microsoft ASP.NET\\ASP.NET 2.0 AJAX Extensions\\v1.0.61025)</p>\n\n<p><strong>3. The virtual directory you are using for your web, isn’t correctly marked as an application (thus the configuration isn’t getting loaded) - This would happen for IIS webs.</strong></p>\n\n<p>Make sure that you are using a Web Application, and not just a Virtual Directory </p>\n\n<p><strong>4. ScriptResource.axd requests return 404</strong></p>\n\n<p>This usually points to a mis-configuration of ASP.NET as a whole. On a default installation of ASP.NET, any web request to a resource ending in .axd is passed from IIS to ASP.NET via an isapi mapping. Additionally the mapping is configured to not check if the file exists. If that mapping does not exist, or the check if file exists isn\'t disabled, then IIS will attempt to find the physical file ScriptResource.axd, won\'t find it, and return 404.</p>\n\n<p>You can check to see if this is the problem by coipy/pasting the full url to ScriptResource.axd from here, and seeing what it returns</p>\n\n<pre><code>&lt;script src="/MyWebApp/ScriptResource.axd?[snip - long query string]" type="text/javascript"&gt;&lt;/script&gt;\n</code></pre>\n\n<p>How do you fix this? If ASP.NET isn\'t properly installed at all, you can run the "aspnet_regiis.exe" command line tool to fix it up. It\'s located in C:\\WINDOWS\\Microsoft.Net\\Framework\\v2.0.50727. You can run "aspnet_regiis -i -enable", which does the full registration of ASP.NET with IIS and makes sure the ISAPI is enabled in IIS6. You can also run "aspnet_regiis -s w3svc/1/root/MyWebApp" to only fix up the registration for your web application.</p>\n\n<p><strong>5. Resolving the "Sys is undefined" error in ASP.NET AJAX RTM under IIS 7</strong></p>\n\n<p>Put this entry under <code>&lt;system.webServer/&gt;&lt;handlers/&gt;</code>:</p>\n\n<pre><code>&lt;add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /&gt;\n</code></pre>\n\n<p>and remove the one under <code>&lt;system.web/&gt;&lt;httpHandlers/&gt;</code>.</p>\n\n<p>References: \n<a href="http://weblogs.asp.net/chrisri/demystifying-sys-is-undefined" rel="noreferrer">http://weblogs.asp.net/chrisri/demystifying-sys-is-undefined</a>\n<a href="http://geekswithblogs.net/lorint/archive/2007/03/28/110161.aspx" rel="noreferrer">http://geekswithblogs.net/lorint/archive/2007/03/28/110161.aspx</a></p>\n'}, {'answer_id': 37473809, 'author': 'hsobhy', 'author_id': 1030977, 'author_profile': 'https://Stackoverflow.com/users/1030977', 'pm_score': 0, 'selected': False, 'text': '<p>In my case, I\'ve found a very hidden reason ... There was this page route with in <strong>Global.ascx.cs</strong> which doesn\'t appear in my tests in sub-folders but returns the question error all the time .. another day with strange issues.</p>\n\n<pre><code>routes.MapPageRoute("siteDefault", "{culture}/", "~/default.aspx", false, new RouteValueDictionary(new { culture = "(\\\\w{2})|(\\\\w{2}-\\\\w{2})" }));\n</code></pre>\n'}, {'answer_id': 39619160, 'author': 'Fernando Meneses Gomes', 'author_id': 1291937, 'author_profile': 'https://Stackoverflow.com/users/1291937', 'pm_score': 1, 'selected': False, 'text': '<p>In my case the problem was that I had putted the following code to keep the gridview tableheader after partial postback:</p>\n\n<pre><code> protected override void OnPreRenderComplete(EventArgs e)\n {\n if (grv.Rows.Count &gt; 0)\n {\n grv.HeaderRow.TableSection = TableRowSection.TableHeader;\n }\n }\n</code></pre>\n\n<p>Removing this code stopped the issue.</p>\n'}, {'answer_id': 46821137, 'author': 'Hawkeye', 'author_id': 4036454, 'author_profile': 'https://Stackoverflow.com/users/4036454', 'pm_score': 3, 'selected': False, 'text': '<p>I hate adding to such a huge topic and so much later, but I\'ve think I have a solution that works in VS2015 at the very least.</p>\n<p>I was on a hunt to find a reason for the sys error, and the only solution that worked for me was to add <code>EnableCdn=&quot;true&quot;</code> in a <code>ScriptManager</code> like this:</p>\n<pre><code>&lt;asp:ScriptManager ID=&quot;ScriptManager1&quot; runat=&quot;server&quot; EnableCdn=&quot;true&quot; /&gt;\n</code></pre>\n<p>See the <a href="https://learn.microsoft.com/en-us/dotnet/api/system.web.ui.scriptmanager.enablecdn?view=netframework-4.8" rel="nofollow noreferrer">MSDN</a> for more information.</p>\n<p><strong>Why do we need to do this?</strong></p>\n<p>When working on a asp.net web application, you have to enable CDN so that Microsoft can download the <code>Sys.</code> library.</p>\n<p>There was probably a script in your page that was using the <code>Sys</code> function. Setting <code>EnableCdn=&quot;true&quot;</code> would ensure that the <code>Sys</code> library is downloaded before it is used.</p>\n<p><strong>What\'s CDN?</strong></p>\n<p>It stands for &quot;Content Delivery Network&quot; and enabling it allows certain resources to download with simple references.</p>\n<p>A quote from <a href="https://www.sitepoint.com/7-reasons-to-use-a-cdn/" rel="nofollow noreferrer">https://www.sitepoint.com/7-reasons-to-use-a-cdn/</a></p>\n<blockquote>\n<p>Most CDNs are used to host static resources such as images, videos,\naudio clips, CSS files and JavaScript. You’ll find common JavaScript\nlibraries, HTML5 shims, CSS resets, fonts and other assets available\non a variety of public and private CDN systems.</p>\n</blockquote>\n<p>Both Google and Microsoft have CDNs. All you have to do is add a reference. Usually CDNs are added via a script resource:</p>\n<pre><code>&lt;script src=&quot;https://ajax.aspnetcdn.com/ajax/4.5.1/1/MicrosoftAjax.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;\n</code></pre>\n<p>Once you set <code>EnableCdn=&quot;true&quot;</code> and Microsoft will add it\'s little CDN reference (like the one above) in the page which downloads the <code>Sys</code> library.</p>\n<p>I hope that helps anybody that ran into the same issue.</p>\n'}, {'answer_id': 64142737, 'author': 'Bm Z', 'author_id': 1542087, 'author_profile': 'https://Stackoverflow.com/users/1542087', 'pm_score': 0, 'selected': False, 'text': '<p>I know this is an old thread but I found a somewhat unique solution. In my case I was getting the error because I am using both Webforms and MVC in the same ASP.NET web application. After mapping routes the issue showed up. I fixed it by adding the following code to ignore routes for both &quot;{resource}.aspx/{*pathInfo}&quot; and &quot;{resource}.axd/{*pathInfo}&quot;</p>\n<pre><code> private void RegisterRoutes(RouteCollection routes)\n {\n routes.IgnoreRoute(&quot;{resource}.aspx/{*pathInfo}&quot;);\n routes.IgnoreRoute(&quot;{resource}.axd/{*pathInfo}&quot;);\n\n routes.MapRoute(\n &quot;Default&quot;, \n &quot;{controller}/{action}/{id}&quot;, \n new { controller = &quot;Test&quot;, action = &quot;Index&quot;, id = UrlParameter.Optional }\n );\n }\n</code></pre>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/75322', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']
75,340
<p>Can anyone recommend an efficient method to execute XSLT transforms of XML data within a Ruby application? The XSL gem (REXSL) is not available yet, and while I have seen a project or two that implement it, I'm wary of using them so early on. A friend had recommended a shell out call to Perl, but I'm worried about resources. </p> <p>This is for a linux environment.</p>
[{'answer_id': 75460, 'author': 'Compulsion', 'author_id': 3675, 'author_profile': 'https://Stackoverflow.com/users/3675', 'pm_score': 3, 'selected': False, 'text': '<p>Try setting your ScriptManager to this.</p>\n\n<pre><code>&lt;asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" /&gt; \n</code></pre>\n'}, {'answer_id': 97842, 'author': 'Aaron Powell', 'author_id': 11388, 'author_profile': 'https://Stackoverflow.com/users/11388', 'pm_score': 2, 'selected': False, 'text': '<p>In addition to ensuring you have the ScriptManager on your page you need to ensure that your web.config is appropriately configured.</p>\n\n<p>When ASP.NET AJAX 1.0 was released (for .NET 2.0) there was a lot of custom web.config settings which added handlers, controls, etc.</p>\n\n<p>You\'ll find the config info here: <a href="http://www.asp.net/AJAX/documentation/live/ConfiguringASPNETAJAX.aspx" rel="nofollow noreferrer">http://www.asp.net/AJAX/documentation/live/ConfiguringASPNETAJAX.aspx</a></p>\n'}, {'answer_id': 200316, 'author': 'Tom Carter', 'author_id': 2839, 'author_profile': 'https://Stackoverflow.com/users/2839', 'pm_score': 2, 'selected': False, 'text': "<p>Make sure that any client scripts you have that interact with .NET AJAX have the following line at the end:</p>\n\n<pre><code>if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();\n</code></pre>\n\n<p>This tells the script manager that the whole script file has loaded and that it can begin to call client methods</p>\n"}, {'answer_id': 538200, 'author': 'MadMax1138', 'author_id': 65187, 'author_profile': 'https://Stackoverflow.com/users/65187', 'pm_score': 2, 'selected': False, 'text': '<p>I was having this same issue and after much wrangling I decided to try and isolate the problem and simply load the script manager in an empty page which still resulted in this same error. Having isolated the problem I discovered through a comparison of my site\'s web.config with a brand new (working) test site that changing <code>&lt;compilation debug="true"&gt;</code> to <code>&lt;compilation debug="false"&gt;</code> in the system.web section of my web.config fixes the problem. </p>\n\n<p>I also had to remove the <code>&lt;xhtmlConformance mode="Legacy"/&gt;</code> entry from system.web to make the update panel work properly. <a href="http://weblogs.asp.net/scottgu/archive/2006/12/10/gotcha-don-t-use-xhtmlconformance-mode-legacy-with-asp-net-ajax.aspx" rel="nofollow noreferrer">Click here</a> for a description of this issue.</p>\n'}, {'answer_id': 678245, 'author': 'TygerKrash', 'author_id': 7652, 'author_profile': 'https://Stackoverflow.com/users/7652', 'pm_score': 0, 'selected': False, 'text': '<p>Was having a similar issue, except that my page was consistently generating the Sys is undefined error. </p>\n\n<p>For me the problem stems from the fact that I\'ve just installed the AJAX 1.0 extension for .NET 2.0 but had already created my web project in Visual Studio.</p>\n\n<p>When tried to create AJAX controls I kept encountering this error, I spotted Slace\'s and MadMax1138s posts here. And figured it was my web.config, I created a new project using the new "AJAX enabled web site" project type, and sure enough the web.config has a large number of customizations necessary to use the AJAX controls. </p>\n\n<p>I just updated that web.config with the web.config updates I had already made myself and dropped it into my existing project and everything worked fine.</p>\n'}, {'answer_id': 1718513, 'author': 'Dean L', 'author_id': 127887, 'author_profile': 'https://Stackoverflow.com/users/127887', 'pm_score': 6, 'selected': False, 'text': '<p>I fixed my problem by moving the <code>&lt;script type="text/javascript"&gt;&lt;/script&gt;</code> block containing the Sys.* calls lower down (to the last item before the close of the body\'s <code>&lt;asp:Content/&gt;</code> section) in the HTML on the page. I originally had my the script block in the HEAD <code>&lt;asp:Content/&gt;</code> section of my page. I was working inside a page that had a MasterPageFile. Hope this helps someone out.</p>\n'}, {'answer_id': 2563888, 'author': 'Ray', 'author_id': 4872, 'author_profile': 'https://Stackoverflow.com/users/4872', 'pm_score': 4, 'selected': False, 'text': '<p>When I experienced the errors </p>\n\n<ul>\n<li>Sys is undefined</li>\n<li>ASP.NET Ajax client-side framework failed to load</li>\n</ul>\n\n<p>in IE when using ASP.NET Ajax controls in .NET 2.0, I needed to add the following to the web.config file within the <code>&lt;system.web&gt;</code> tags:</p>\n\n<pre><code>&lt;httpHandlers&gt;\n &lt;remove verb="*" path="*.asmx"/&gt;\n &lt;add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&gt;\n &lt;add verb="GET" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler" validate="false"/&gt;\n&lt;/httpHandlers&gt;\n</code></pre>\n'}, {'answer_id': 2789879, 'author': 'Arsalan', 'author_id': 335611, 'author_profile': 'https://Stackoverflow.com/users/335611', 'pm_score': -1, 'selected': False, 'text': "<p>Please please please do check that the Server has the correct time and date set...</p>\n\n<p>After about wasting 6 hours, i read it somewhere...</p>\n\n<p>The date and time for the server must be updated to work correctly...</p>\n\n<p>otherwise you will get 'Sys' is undefined error.</p>\n"}, {'answer_id': 2856354, 'author': 'kaash', 'author_id': 343901, 'author_profile': 'https://Stackoverflow.com/users/343901', 'pm_score': -1, 'selected': False, 'text': '<p>Just create blank .axd files in your solutions root foder problem will be resolved. (2 file: scriptresouce.asx, webresource.asxd)</p>\n'}, {'answer_id': 3511184, 'author': 'g9ncom', 'author_id': 341062, 'author_profile': 'https://Stackoverflow.com/users/341062', 'pm_score': 0, 'selected': False, 'text': '<p>I have been seeing the exact same error today, but it was not a config or direct JavaScript issue.</p>\n\n<p>An external .net project had been updated but the changes not picked up properly in the compilation of the web site. My presumption is that ASP.NET ajax was not able to construct the client representations of the .NET objects properly and so was failing to load correctly.</p>\n\n<p>To resolve, I rebuilt the external project(s), and rebuilt my solution that was experiencing issues. The problem went away. </p>\n'}, {'answer_id': 3757770, 'author': 'Anish', 'author_id': 453539, 'author_profile': 'https://Stackoverflow.com/users/453539', 'pm_score': -1, 'selected': False, 'text': '<p>Hi thanx a lot it solved my issue ,</p>\n\n<p>By default vs 2008 will add </p>\n\n<pre><code> &lt;!--&lt;add verb="*" path="*.asmx" validate="false" type="Microsoft.Web.Script.Services.ScriptHandlerFactory, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /&gt;\n &lt;add verb="GET" path="ScriptResource.axd" type="Microsoft.Web.Handlers.ScriptResourceHandler" validate="false" /&gt;--&gt;\n</code></pre>\n\n<p>Need to correct Default config(Above) to below code\n<strong>FIX</strong></p>\n\n<pre><code> &lt;add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&gt;\n &lt;add verb="GET" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler" validate="false"/&gt;\n</code></pre>\n'}, {'answer_id': 4260550, 'author': 'Alcides Martínez', 'author_id': 518003, 'author_profile': 'https://Stackoverflow.com/users/518003', 'pm_score': 3, 'selected': False, 'text': '<p>You must add these lines in the web.config</p>\n\n<p>\n \n \n \n \n \n \n \n \n \n \n </p>\n\n<pre><code>&lt;httpHandlers&gt;\n &lt;remove verb="*" path="*.asmx"/&gt;\n &lt;add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&gt;\n &lt;add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&gt;\n &lt;add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/&gt;\n&lt;/httpHandlers&gt;\n&lt;httpModules&gt;\n &lt;add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&gt;\n&lt;/httpModules&gt;\n&lt;/system.web&gt;\n</code></pre>\n\n<p>\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n </p>\n\n<p>Hope this helps.</p>\n'}, {'answer_id': 6020313, 'author': 'JonK', 'author_id': 755955, 'author_profile': 'https://Stackoverflow.com/users/755955', 'pm_score': 0, 'selected': False, 'text': '<p>I found the error when using a combination of the Ajax Control Toolkit ToolkitScriptManager and URL Write 2.0.</p>\n\n<p>In my <code>&lt;rewrite&gt; &lt;outboundRules&gt;</code> I had a precondition:</p>\n\n<pre><code>&lt;preConditions&gt;\n &lt;preCondition name="IsHTML"&gt;\n &lt;add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html"/&gt;\n &lt;/preCondition&gt;\n&lt;/preConditions&gt;\n</code></pre>\n\n<p>But apparently some of my outbound rules weren\'t set to use the precondition. </p>\n\n<p>Once I had that preCondition set on all my outbound rules:</p>\n\n<pre><code>&lt;rule preCondition="IsHTML" name="MyOutboundRule"&gt;\n</code></pre>\n\n<p>No more problem. </p>\n'}, {'answer_id': 6291807, 'author': 'Zara_me', 'author_id': 121336, 'author_profile': 'https://Stackoverflow.com/users/121336', 'pm_score': 1, 'selected': False, 'text': '<p>I solved this problem by creating separate asp.net ajax solution and copy and paste all ajax configuration from web.config to working project.</p>\n\n<p>here are the must configuration you should set in web.config</p>\n\n<pre><code> &lt;configuration&gt;\n&lt;configSections&gt;\n &lt;sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"&gt;\n &lt;sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"&gt;\n &lt;section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/&gt;\n&lt;/sectionGroup&gt;\n\n &lt;/sectionGroup&gt;\n&lt;/configSections&gt;\n</code></pre>\n\n<p></p>\n\n<pre><code> &lt;assemblies&gt;\n\n &lt;add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&gt;\n\n &lt;/assemblies&gt;\n &lt;/compilation&gt;\n &lt;httpHandlers&gt;\n &lt;remove verb="*" path="*.asmx"/&gt;\n &lt;add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&gt;\n &lt;add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&gt;\n &lt;add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/&gt;\n &lt;/httpHandlers&gt;\n &lt;httpModules&gt;\n &lt;add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&gt;\n &lt;/httpModules&gt;\n&lt;/system.web&gt;\n &lt;system.webServer&gt;\n &lt;validation validateIntegratedModeConfiguration="false"/&gt;\n &lt;modules&gt;\n &lt;add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&gt;\n &lt;/modules&gt;\n &lt;handlers&gt;\n &lt;remove name="WebServiceHandlerFactory-Integrated"/&gt;\n &lt;add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&gt;\n &lt;add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&gt;\n &lt;add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&gt;\n &lt;/handlers&gt;\n&lt;/system.webServer&gt;\n</code></pre>\n'}, {'answer_id': 6870078, 'author': 'Max', 'author_id': 260093, 'author_profile': 'https://Stackoverflow.com/users/260093', 'pm_score': 0, 'selected': False, 'text': '<p>Make sure you don\'t have any Rewrite rules that change your url.</p>\n\n<p>In my case the application thought it was only level deeper then the url reached.</p>\n\n<p>Example: <a href="http://mysite.com/app/page.aspx" rel="nofollow">http://mysite.com/app/page.aspx</a> was the real url.\nBut i cut off /app/ this worked fine for ASP.net and WCF, but clearly not for Ajax.</p>\n'}, {'answer_id': 9350258, 'author': 'Zviadi', 'author_id': 299203, 'author_profile': 'https://Stackoverflow.com/users/299203', 'pm_score': 3, 'selected': False, 'text': '<p>I was using telerik and had exactly same problem.</p>\n\n<p>adding this to web.config resolved my issue :)</p>\n\n<pre><code>&lt;location path="Telerik.Web.UI.WebResource.axd"&gt; \n &lt;system.web&gt; \n &lt;authorization&gt; \n &lt;allow users="*"/&gt; \n &lt;/authorization&gt; \n &lt;/system.web&gt; \n&lt;/location&gt;\n</code></pre>\n\n<p>maybe it will help you too. it was Authentication problem.</p>\n\n<p><a href="http://blogs.telerik.com/blogs/posts/10-03-16/common-reasons-for-the-lsquo-sys-is-undefined-rsquo-error-in-asp-net-ajax-applications.aspx" rel="nofollow">Source</a></p>\n'}, {'answer_id': 9442728, 'author': 'v s', 'author_id': 1023156, 'author_profile': 'https://Stackoverflow.com/users/1023156', 'pm_score': 0, 'selected': False, 'text': '<p>I had similar problems and to my surprise what I found that one of my developer had saved web.config in the same folder/solution as <strong>web123.config</strong> and by mistake both of these files were uploaded.</p>\n\n<p>As soon as I deleted the <strong>web123.config</strong> file, this error disappeared and ajax framework was loading correctly. even though I have </p>\n\n<pre><code>&lt;compilation debug="true"&gt;\n</code></pre>\n\n<p>In my case I also have following segment. My project is using framework 3.5</p>\n\n<pre><code> &lt;httpHandlers&gt;\n &lt;remove verb="*" path="*.asmx"/&gt;\n &lt;add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&gt;\n &lt;add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&gt;\n &lt;add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/&gt;\n&lt;/httpHandlers&gt;\n&lt;httpModules&gt;\n &lt;add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&gt;\n&lt;/httpModules&gt;\n&lt;/system.web&gt;\n</code></pre>\n'}, {'answer_id': 11031391, 'author': 'Carl Onager', 'author_id': 1400368, 'author_profile': 'https://Stackoverflow.com/users/1400368', 'pm_score': 0, 'selected': False, 'text': "<p>This is going to sound stupid but I had a similar problem with a site being developed in VS2010 and hosted in the VS Dev Server. The page in question had a scriptmanager to create the connection to a wcf service. I added an extra method to the service and this error started appearing. </p>\n\n<p>What fixed it for me was changing from 'Auto-assign Port' to 'Specific port' with a different port number in the oroject Web settings.</p>\n\n<p>I wish I knew why...</p>\n"}, {'answer_id': 13631823, 'author': 'GoldBishop', 'author_id': 659246, 'author_profile': 'https://Stackoverflow.com/users/659246', 'pm_score': 0, 'selected': False, 'text': 'Development Environment:\n<ul>\n<li>Dev-Env: VS 2012</li>\n<li>FX: 4.0/4.5</li>\n<li>Implementations: Master(ScriptManager + UpdatePanel/Timer) + Content (UpdatePanel)</li>\n<li>Patterns: PageRouting.</li>\n</ul>\n<h2>Disclaimer:</h2>\n<p>If all the <code>web.config</code> solutions do not work for you and you have implemented PageRouting (IIS 7+), then the code snippet below will solve your problems.</p>\n<h2>Background:</h2>\n<p>Dont mean to Highjack this question but had the same problem as everyone else and implemented 100% of the suggestions here, with minor modifications for .Net 4.0/4.5, and none of them worked for me.</p>\n<p>In my situation i had implemented <a href="http://msdn.microsoft.com/en-us/library/cc668201.aspx" rel="nofollow noreferrer">Page Routing</a> which was ghosting my problem. Basically it would work for about 20, or so, debug runs and then BAM would error out with the <code>Sys is undefined</code> error.</p>\n<p>After reviewing a couple other posts, that got to talking about the Clean-URL logic, i remembered that i had done PageRouting setup\'s.</p>\n<p>Here is the resource i used to build my patterns: <a href="http://msdn.microsoft.com/en-us/library/cc668201.aspx" rel="nofollow noreferrer">Page Routing</a></p>\n<p>My one-liner code fixed my VS2012 Debugging problem:</p>\n<pre><code>rts.Ignore(&quot;{resource}.axd/{*pathInfo}&quot;) \'Ignores any Resource cache references, used heavily in AJAX interactions.\n</code></pre>\n'}, {'answer_id': 14865444, 'author': 'Mahesh', 'author_id': 446154, 'author_profile': 'https://Stackoverflow.com/users/446154', 'pm_score': 0, 'selected': False, 'text': '<p>Even after adding the correct entry for web config still getting this error ? most common reason for this error is JavaScript that references the Sys namespace too early.\nThen most obvious fix would be move the java script block below the ScriptManager control:</p>\n'}, {'answer_id': 16109767, 'author': 'RacerNerd', 'author_id': 1634605, 'author_profile': 'https://Stackoverflow.com/users/1634605', 'pm_score': 0, 'selected': False, 'text': '<p>I don\'t think this point has been added and since I just spent some time hunting this down I hope it can help.<br/><br/>\nI am working with IIS 7 and using the ASP.NET v4 Framework.<br/>\nIn my case it was <strong>important that an entry be added to both the and section of the entry in the web.config file.</strong><br/><br/>\nMy web.config file has a lot of handlers and in my case it was easiest to add the ScriptResources entry to the top of the handlers section. <strong>Most importantly, it needs to be placed before any entry that will act as a wildcard and capture the request.</strong> Adding it after a wildcard entry will cause it to be ignored and the error will still appear.<br/><br/>The module can be added to the top or bottom of the section.<br/><br/>\nWeb.config Sample:</p>\n\n<pre><code>&lt;system.webServer&gt;\n &lt;handlers&gt;\n &lt;clear /&gt;\n &lt;add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /&gt;\n &lt;!-- Make sure wildcard rules are below the ScriptResource tag --&gt;\n &lt;/handlers&gt;\n &lt;modules&gt;\n &lt;add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&gt;\n &lt;!-- Other modules are added here --&gt;\n &lt;/modules&gt;\n &lt;/system.webServer&gt;\n</code></pre>\n'}, {'answer_id': 16822213, 'author': 'David Glass', 'author_id': 1521279, 'author_profile': 'https://Stackoverflow.com/users/1521279', 'pm_score': 1, 'selected': False, 'text': '<p>In case none of the above works for you, and you happen to be overriding OnPreRenderComplete, make sure you call base.OnPreRenderComplete. My therapist is going to be happy to see me back</p>\n'}, {'answer_id': 17256975, 'author': 'goodeye', 'author_id': 292060, 'author_profile': 'https://Stackoverflow.com/users/292060', 'pm_score': 3, 'selected': False, 'text': '<p>Dean L\'s answer, <a href="https://stackoverflow.com/a/1718513/292060">https://stackoverflow.com/a/1718513/292060</a> worked for me, since my call to Sys was also too early. Since I\'m using jQuery, instead of moving it down, I put the script inside a document.ready call:</p>\n\n<pre><code>$(document).ready(function () {\n Sys. calls here\n});\n</code></pre>\n\n<p>This seems to be late enough that Sys is available.</p>\n'}, {'answer_id': 18301056, 'author': 'Farschidus', 'author_id': 1379217, 'author_profile': 'https://Stackoverflow.com/users/1379217', 'pm_score': 1, 'selected': False, 'text': "<p>I had the same problem after updating my AjaxControlToolkit.dll to the latest version 4.1.7.725 from 4.1.60623.0. \nI've searched and came up to this page, but none of the answers help me.\nAfter looking to the sample website of the Ajax Control Toolkit that is in the CodePlex zip file, I have realized that the <code>&lt;asp:ScriptManager&gt;</code> replaced by the new <code>&lt;ajaxtoolkit:ToolkitScriptManager&gt;</code>. I did so and there is no <em>Sys.Extended is undefined</em> any more.</p>\n"}, {'answer_id': 28965519, 'author': 'onlyme', 'author_id': 3954673, 'author_profile': 'https://Stackoverflow.com/users/3954673', 'pm_score': 0, 'selected': False, 'text': '<p>I had same probleme but i fixed it by: </p>\n\n<p>When putting a script file into a page, make sure it is </p>\n\n<pre><code>&lt;script&gt;&lt;/script&gt; and not &lt;script /&gt;.\n</code></pre>\n\n<p>I have followed this:\n<a href="http://forums.asp.net/t/1742435.aspx?An+element+with+id+form1+could+not+be+found+Script+error+on+page+load" rel="nofollow">http://forums.asp.net/t/1742435.aspx?An+element+with+id+form1+could+not+be+found+Script+error+on+page+load</a></p>\n\n<p>Hope this will help</p>\n'}, {'answer_id': 30093900, 'author': 'Jawad Siddiqui', 'author_id': 1085016, 'author_profile': 'https://Stackoverflow.com/users/1085016', 'pm_score': 0, 'selected': False, 'text': '<p>Add</p>\n\n<pre><code>if (typeof(Sys) !== \'undefined\') Sys.Application.notifyScriptLoaded(); \n</code></pre>\n\n<p>Please check <a href="https://msdn.microsoft.com/en-us/library/vstudio/bb310952(v=vs.100).aspx" rel="nofollow">enter link description here</a></p>\n'}, {'answer_id': 32057625, 'author': 'Alexandre N.', 'author_id': 1398758, 'author_profile': 'https://Stackoverflow.com/users/1398758', 'pm_score': 3, 'selected': False, 'text': '<p>Try one of this solutions: </p>\n\n<p><strong>1. The browser fails to load the compressed script</strong></p>\n\n<p>This is usually the case if you get the error on IE6, but not on other browsers.</p>\n\n<p>The Script Resource Handler – ScriptResource.axd compresses the scripts before returning them to the browser. In pre-RTM releases, the handler did it all the time for all browsers, and it wasn’t configurable. There is an issue in one of the components of IE6 that prevents it from loading compressed scripts correctly. See KB article <a href="http://support.microsoft.com/default.aspx?scid=kb;en-us;Q312496" rel="noreferrer">here</a>. In RTM builds, we’ve made two fixes for this. One, we don’t compress if IE6 is the browser client. Two, we’ve now made compression configurable. Here’s how you can toggle the web.config.</p>\n\n<p>How do you fix it? First, make sure you are using the AJAX Extensions 1.0 RTM release. That alone should be enough. You can also try turning off compression by editing your web.config to have the following:</p>\n\n<pre><code>&lt;system.web.extensions&gt;\n&lt;scripting&gt;\n&lt;scriptResourceHandler enableCompression="false" enableCaching="true" /&gt;\n&lt;/scripting&gt;\n&lt;/system.web.extensions&gt;\n</code></pre>\n\n<p><strong>2. The required configuration for ScriptResourceHandler doesn’t exist for the web.config for your application</strong></p>\n\n<p>Make sure your web.config contains the entries from the default web.config file provided with the extensions install. (default location: C:\\Program Files\\Microsoft ASP.NET\\ASP.NET 2.0 AJAX Extensions\\v1.0.61025)</p>\n\n<p><strong>3. The virtual directory you are using for your web, isn’t correctly marked as an application (thus the configuration isn’t getting loaded) - This would happen for IIS webs.</strong></p>\n\n<p>Make sure that you are using a Web Application, and not just a Virtual Directory </p>\n\n<p><strong>4. ScriptResource.axd requests return 404</strong></p>\n\n<p>This usually points to a mis-configuration of ASP.NET as a whole. On a default installation of ASP.NET, any web request to a resource ending in .axd is passed from IIS to ASP.NET via an isapi mapping. Additionally the mapping is configured to not check if the file exists. If that mapping does not exist, or the check if file exists isn\'t disabled, then IIS will attempt to find the physical file ScriptResource.axd, won\'t find it, and return 404.</p>\n\n<p>You can check to see if this is the problem by coipy/pasting the full url to ScriptResource.axd from here, and seeing what it returns</p>\n\n<pre><code>&lt;script src="/MyWebApp/ScriptResource.axd?[snip - long query string]" type="text/javascript"&gt;&lt;/script&gt;\n</code></pre>\n\n<p>How do you fix this? If ASP.NET isn\'t properly installed at all, you can run the "aspnet_regiis.exe" command line tool to fix it up. It\'s located in C:\\WINDOWS\\Microsoft.Net\\Framework\\v2.0.50727. You can run "aspnet_regiis -i -enable", which does the full registration of ASP.NET with IIS and makes sure the ISAPI is enabled in IIS6. You can also run "aspnet_regiis -s w3svc/1/root/MyWebApp" to only fix up the registration for your web application.</p>\n\n<p><strong>5. Resolving the "Sys is undefined" error in ASP.NET AJAX RTM under IIS 7</strong></p>\n\n<p>Put this entry under <code>&lt;system.webServer/&gt;&lt;handlers/&gt;</code>:</p>\n\n<pre><code>&lt;add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /&gt;\n</code></pre>\n\n<p>and remove the one under <code>&lt;system.web/&gt;&lt;httpHandlers/&gt;</code>.</p>\n\n<p>References: \n<a href="http://weblogs.asp.net/chrisri/demystifying-sys-is-undefined" rel="noreferrer">http://weblogs.asp.net/chrisri/demystifying-sys-is-undefined</a>\n<a href="http://geekswithblogs.net/lorint/archive/2007/03/28/110161.aspx" rel="noreferrer">http://geekswithblogs.net/lorint/archive/2007/03/28/110161.aspx</a></p>\n'}, {'answer_id': 37473809, 'author': 'hsobhy', 'author_id': 1030977, 'author_profile': 'https://Stackoverflow.com/users/1030977', 'pm_score': 0, 'selected': False, 'text': '<p>In my case, I\'ve found a very hidden reason ... There was this page route with in <strong>Global.ascx.cs</strong> which doesn\'t appear in my tests in sub-folders but returns the question error all the time .. another day with strange issues.</p>\n\n<pre><code>routes.MapPageRoute("siteDefault", "{culture}/", "~/default.aspx", false, new RouteValueDictionary(new { culture = "(\\\\w{2})|(\\\\w{2}-\\\\w{2})" }));\n</code></pre>\n'}, {'answer_id': 39619160, 'author': 'Fernando Meneses Gomes', 'author_id': 1291937, 'author_profile': 'https://Stackoverflow.com/users/1291937', 'pm_score': 1, 'selected': False, 'text': '<p>In my case the problem was that I had putted the following code to keep the gridview tableheader after partial postback:</p>\n\n<pre><code> protected override void OnPreRenderComplete(EventArgs e)\n {\n if (grv.Rows.Count &gt; 0)\n {\n grv.HeaderRow.TableSection = TableRowSection.TableHeader;\n }\n }\n</code></pre>\n\n<p>Removing this code stopped the issue.</p>\n'}, {'answer_id': 46821137, 'author': 'Hawkeye', 'author_id': 4036454, 'author_profile': 'https://Stackoverflow.com/users/4036454', 'pm_score': 3, 'selected': False, 'text': '<p>I hate adding to such a huge topic and so much later, but I\'ve think I have a solution that works in VS2015 at the very least.</p>\n<p>I was on a hunt to find a reason for the sys error, and the only solution that worked for me was to add <code>EnableCdn=&quot;true&quot;</code> in a <code>ScriptManager</code> like this:</p>\n<pre><code>&lt;asp:ScriptManager ID=&quot;ScriptManager1&quot; runat=&quot;server&quot; EnableCdn=&quot;true&quot; /&gt;\n</code></pre>\n<p>See the <a href="https://learn.microsoft.com/en-us/dotnet/api/system.web.ui.scriptmanager.enablecdn?view=netframework-4.8" rel="nofollow noreferrer">MSDN</a> for more information.</p>\n<p><strong>Why do we need to do this?</strong></p>\n<p>When working on a asp.net web application, you have to enable CDN so that Microsoft can download the <code>Sys.</code> library.</p>\n<p>There was probably a script in your page that was using the <code>Sys</code> function. Setting <code>EnableCdn=&quot;true&quot;</code> would ensure that the <code>Sys</code> library is downloaded before it is used.</p>\n<p><strong>What\'s CDN?</strong></p>\n<p>It stands for &quot;Content Delivery Network&quot; and enabling it allows certain resources to download with simple references.</p>\n<p>A quote from <a href="https://www.sitepoint.com/7-reasons-to-use-a-cdn/" rel="nofollow noreferrer">https://www.sitepoint.com/7-reasons-to-use-a-cdn/</a></p>\n<blockquote>\n<p>Most CDNs are used to host static resources such as images, videos,\naudio clips, CSS files and JavaScript. You’ll find common JavaScript\nlibraries, HTML5 shims, CSS resets, fonts and other assets available\non a variety of public and private CDN systems.</p>\n</blockquote>\n<p>Both Google and Microsoft have CDNs. All you have to do is add a reference. Usually CDNs are added via a script resource:</p>\n<pre><code>&lt;script src=&quot;https://ajax.aspnetcdn.com/ajax/4.5.1/1/MicrosoftAjax.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;\n</code></pre>\n<p>Once you set <code>EnableCdn=&quot;true&quot;</code> and Microsoft will add it\'s little CDN reference (like the one above) in the page which downloads the <code>Sys</code> library.</p>\n<p>I hope that helps anybody that ran into the same issue.</p>\n'}, {'answer_id': 64142737, 'author': 'Bm Z', 'author_id': 1542087, 'author_profile': 'https://Stackoverflow.com/users/1542087', 'pm_score': 0, 'selected': False, 'text': '<p>I know this is an old thread but I found a somewhat unique solution. In my case I was getting the error because I am using both Webforms and MVC in the same ASP.NET web application. After mapping routes the issue showed up. I fixed it by adding the following code to ignore routes for both &quot;{resource}.aspx/{*pathInfo}&quot; and &quot;{resource}.axd/{*pathInfo}&quot;</p>\n<pre><code> private void RegisterRoutes(RouteCollection routes)\n {\n routes.IgnoreRoute(&quot;{resource}.aspx/{*pathInfo}&quot;);\n routes.IgnoreRoute(&quot;{resource}.axd/{*pathInfo}&quot;);\n\n routes.MapRoute(\n &quot;Default&quot;, \n &quot;{controller}/{action}/{id}&quot;, \n new { controller = &quot;Test&quot;, action = &quot;Index&quot;, id = UrlParameter.Optional }\n );\n }\n</code></pre>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/75340', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13320/']
75,347
<p>I've been asked to implement some code that will update a row in a MS SQL Server database and then use a stored proc to insert the update in a history table. We can't add a stored proc to do this since we don't control the database. I know in stored procs you can do the update and then call execute on another stored proc. Can I set it up to do this in code using one SQL command?</p>
[{'answer_id': 75422, 'author': 'dpollock', 'author_id': 7884, 'author_profile': 'https://Stackoverflow.com/users/7884', 'pm_score': 0, 'selected': False, 'text': '<p>You can also create sql triggers.</p>\n'}, {'answer_id': 75429, 'author': 'foxxtrot', 'author_id': 10369, 'author_profile': 'https://Stackoverflow.com/users/10369', 'pm_score': 0, 'selected': False, 'text': '<p>Depending on your library, you can usually just put both queries in one Command String, separated by a semi-colon.</p>\n'}, {'answer_id': 75431, 'author': 'JBB', 'author_id': 12332, 'author_profile': 'https://Stackoverflow.com/users/12332', 'pm_score': 0, 'selected': False, 'text': "<p>Insufficient information -- what SQL server? Why have a history table?</p>\n\n<p>Triggers will do this sort of thing. MySQL's binlog might be more useful for you. </p>\n\n<p>You say you don't control the database. Do you control the code that accesses it? Add logging there and keep it out of the SQL server entirely.</p>\n"}, {'answer_id': 75465, 'author': 'Joel Coehoorn', 'author_id': 3043, 'author_profile': 'https://Stackoverflow.com/users/3043', 'pm_score': 2, 'selected': True, 'text': '<p>Either run them both in the same statement (separate the separate commands by a semi-colon) or a use a transaction so you can rollback the first statement if the 2nd fails.</p>\n'}, {'answer_id': 75470, 'author': 'Nathan Feger', 'author_id': 8563, 'author_profile': 'https://Stackoverflow.com/users/8563', 'pm_score': 1, 'selected': False, 'text': "<p>You don't really need a stored proc for this. The question really boils down to whether or not you have control over all the inserts. If in fact you have access to all the inserts, you can simply wrap an insert into datatable, and a insert into historytable in a single transasction. This will ensure that both are completed for 'success' to occur. However, when accessing to tables in sequence within a transaction you need to make sure you don't lock historytable then datatable, or else you could have a deadlock situation.</p>\n\n<p>However, if you do not have control over the inserts, you can add a trigger to certain db systems that will give you access to the data that are modified, inserted or deleted. It may or may not give you all the data you need, like who did the insert, update or delete, but it will tell you what changed.</p>\n"}, {'answer_id': 75852, 'author': 'osp70', 'author_id': 2357, 'author_profile': 'https://Stackoverflow.com/users/2357', 'pm_score': 0, 'selected': False, 'text': '<p>Thanks all for your reply, below is a synopsis of what I ended up doing. Now to test to see if the trans actually roll back in event of a fail. </p>\n\n<pre><code>sSQL = "BEGIN TRANSACTION;" &amp; _\n " Update table set col1 = @col1, col2 = @col2" &amp; _\n " where col3 = @col3 and " &amp; _\n " EXECUTE addcontacthistoryentry @parm1, @parm2, @parm3, @parm4, @parm5, @parm6; " &amp; _\n "COMMIT TRANSACTION;"\n</code></pre>\n'}]
2008/09/16
['https://Stackoverflow.com/questions/75347', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2357/']
75,361
<p>I have a column containing the strings 'Operator (1)' and so on until 'Operator (600)' so far.</p> <p>I want to get them numerically ordered and I've come up with</p> <pre><code>select colname from table order by cast(replace(replace(colname,'Operator (',''),')','') as int) </code></pre> <p>which is very very ugly.</p> <p>Better suggestions?</p>
[{'answer_id': 75398, 'author': 'Joel Coehoorn', 'author_id': 3043, 'author_profile': 'https://Stackoverflow.com/users/3043', 'pm_score': 3, 'selected': True, 'text': "<p>It's that, InStr()/SubString(), changing Operator(1) to Operator(001), storing the n in Operator(n) separately, or creating a computed column that hides the ugly string manipulation. What you have seems fine.</p>\n"}, {'answer_id': 75474, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>My answer would be to change the problem. I would add an operatorNumber field to the table if that is possible. Change the update/insert routines to extract the number and store it. That way the string conversion hit is only once per record.</p>\n\n<p>The ordering logic would require the string conversion every time the query is run.</p>\n'}, {'answer_id': 76471, 'author': 'Ricardo C', 'author_id': 232589, 'author_profile': 'https://Stackoverflow.com/users/232589', 'pm_score': 0, 'selected': False, 'text': '<p>Well, first define the meaning of that column. Is operator a name so you can justify using chars? Or is it a number? </p>\n\n<p>If the field is a name then you will use chars, and then you would want to determine the fixed length. Pad all operator names with zeros on the left. Define naming rules for operators (I.E. No leters. Or the codes you would use in a series like "A001")</p>\n\n<p>An index will sort the physical data in the server. And a properly define text naming will sort them on a query. You would want both.</p>\n\n<p>If the operator is a number, then you got the data type for that column wrong and needs to be changed.</p>\n'}, {'answer_id': 76618, 'author': 'Cruachan', 'author_id': 7315, 'author_profile': 'https://Stackoverflow.com/users/7315', 'pm_score': 1, 'selected': False, 'text': "<p>If you really <em>have</em> to leave the data in the format you have - and adding a numeric sort order column is the better solution - then consider wrapping the text manipulation up in a user defined function. </p>\n\n<p>select colname from table order by dbo.udfSortOperator(colname)</p>\n\n<p>It's less ugly and gives you some abstraction. There's an additional overhead of the function call but on a table containing low thousands of rows in a not-too-heavily hit database server it's not a major concern. Make notes in the function to optomise later as required.</p>\n"}, {'answer_id': 150106, 'author': 'Constantin', 'author_id': 20310, 'author_profile': 'https://Stackoverflow.com/users/20310', 'pm_score': 0, 'selected': False, 'text': "<p><strong>Indexed computed column</strong></p>\n\n<p>If you find yourself ordering on or otherwise querying <code>operator</code> column often, consider creating a computed column for its numeric value and adding an index for it. This will give you a computed/persistent column (which sounds like oxymoron, but isn't).</p>\n"}]
2008/09/16
['https://Stackoverflow.com/questions/75361', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5190/']