qid
int64 4
22.2M
| question
stringlengths 18
48.3k
| answers
list | date
stringlengths 10
10
| metadata
list |
|---|---|---|---|---|
138,419
|
<p>While porting an application from SQL 2005 to SQL Server Compact Edition, I found that I need to port this command:</p>
<pre><code>SELECT TOP 1 Id FROM tblJob WHERE Holder_Id IS NULL
</code></pre>
<p>But SQL Server Compact Edition doesn't support the <code>TOP</code> keyword. How can I port this command?</p>
|
[
{
"answer_id": 138439,
"author": "Robinb",
"author_id": 22064,
"author_profile": "https://Stackoverflow.com/users/22064",
"pm_score": 6,
"selected": true,
"text": "SELECT TOP(1) Id \nFROM tblJob \nWHERE Holder_Id IS NULL\n"
},
{
"answer_id": 140835,
"author": "Mike Dimmick",
"author_id": 6970,
"author_profile": "https://Stackoverflow.com/users/6970",
"pm_score": 2,
"selected": false,
"text": "CommandText"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138419",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15136/"
] |
138,422
|
<p>I have a HTML report, which needs to be printed landscape because of the many columns. It there a way to do this, without the user having to change the document settings?</p>
<p>And what are the options amongst browsers.</p>
|
[
{
"answer_id": 138456,
"author": "yann.kmm",
"author_id": 15780,
"author_profile": "https://Stackoverflow.com/users/15780",
"pm_score": 3,
"selected": false,
"text": "div.page { \n writing-mode: tb-rl;\n}\n"
},
{
"answer_id": 138483,
"author": "gizmo",
"author_id": 9396,
"author_profile": "https://Stackoverflow.com/users/9396",
"pm_score": 4,
"selected": false,
"text": "@page {\n size: landscape;\n}\n"
},
{
"answer_id": 1392794,
"author": "John",
"author_id": 33,
"author_profile": "https://Stackoverflow.com/users/33",
"pm_score": 10,
"selected": true,
"text": "@media print{@page {size: landscape}}\n"
},
{
"answer_id": 3068496,
"author": "Naveen Mettapally",
"author_id": 370160,
"author_profile": "https://Stackoverflow.com/users/370160",
"pm_score": 1,
"selected": false,
"text": "<style type=\"text/css\" media=\"print\">\n.landscape { \n width: 100%; \n height: 100%; \n margin: 0% 0% 0% 0%; filter: progid:DXImageTransform.Microsoft.BasicImage(Rotation=1); \n} \n</style>\n"
},
{
"answer_id": 13541556,
"author": "Satheesh",
"author_id": 1849501,
"author_profile": "https://Stackoverflow.com/users/1849501",
"pm_score": 1,
"selected": false,
"text": "-webkit-transform: rotate(-90deg); -moz-transform:rotate(-90deg);\n filter:progid:DXImageTransform.Microsoft.BasicImage(rotation=3);\n"
},
{
"answer_id": 24950044,
"author": "Navin Rauniyar",
"author_id": 2313718,
"author_profile": "https://Stackoverflow.com/users/2313718",
"pm_score": 1,
"selected": false,
"text": "@media print and (orientation:landscape) { … }\n"
},
{
"answer_id": 26025787,
"author": "Eduardo Cuomo",
"author_id": 717267,
"author_profile": "https://Stackoverflow.com/users/717267",
"pm_score": 5,
"selected": false,
"text": "<style type=\"text/css\" media=\"print\">\n @page { \n size: landscape;\n }\n body { \n writing-mode: tb-rl;\n }\n</style>\n"
},
{
"answer_id": 27787031,
"author": "Shankar",
"author_id": 1944282,
"author_profile": "https://Stackoverflow.com/users/1944282",
"pm_score": 2,
"selected": false,
"text": "<style type=\"text/css\" media=\"print\">\n @page Section1\n {size:11 8.5in;\n margin:.5in 13.6pt 0in 13.6pt;\n mso-header-margin:.5in;\n mso-footer-margin:.5in;\n mso-paper-source:4;}\ndiv.Section1\n {page:Section1;}\n</style>\n\n\n\n<div class=\"Section1\"> put text / images / other stuff </div>\n"
},
{
"answer_id": 42344471,
"author": "robstarbuck",
"author_id": 999248,
"author_profile": "https://Stackoverflow.com/users/999248",
"pm_score": 4,
"selected": false,
"text": "size"
},
{
"answer_id": 44069821,
"author": "Denis",
"author_id": 632199,
"author_profile": "https://Stackoverflow.com/users/632199",
"pm_score": 4,
"selected": false,
"text": "margin"
},
{
"answer_id": 58727538,
"author": "sherz",
"author_id": 12331257,
"author_profile": "https://Stackoverflow.com/users/12331257",
"pm_score": -1,
"selected": false,
"text": "@page {\n size: auto\n}\n"
},
{
"answer_id": 59071414,
"author": "Arkadiy Bolotov",
"author_id": 1708124,
"author_profile": "https://Stackoverflow.com/users/1708124",
"pm_score": 2,
"selected": false,
"text": "body {\n margin: 0;\n background: #CCCCCC;\n}\n\ndiv.page {\n margin: 10px auto;\n border: solid 1px black;\n display: block;\n page-break-after: always;\n width: 209mm;\n height: 296mm;\n overflow: hidden;\n background: white;\n}\n\ndiv.landscape-parent {\n width: 296mm;\n height: 209mm;\n}\n\ndiv.landscape {\n width: 296mm;\n height: 209mm;\n}\n\ndiv.content {\n padding: 10mm;\n}\n\nbody,\ndiv,\ntd {\n font-size: 13px;\n font-family: Verdana;\n}\n\n@media print {\n body {\n background: none;\n }\n div.page {\n width: 209mm;\n height: 296mm;\n }\n div.landscape {\n transform: rotate(270deg) translate(-296mm, 0);\n transform-origin: 0 0;\n }\n div.portrait,\n div.landscape,\n div.page {\n margin: 0;\n padding: 0;\n border: none;\n background: none;\n }\n}"
},
{
"answer_id": 67360337,
"author": "Rich",
"author_id": 6542267,
"author_profile": "https://Stackoverflow.com/users/6542267",
"pm_score": 2,
"selected": false,
"text": "<html>"
},
{
"answer_id": 69067910,
"author": "thphoenix",
"author_id": 2112461,
"author_profile": "https://Stackoverflow.com/users/2112461",
"pm_score": 0,
"selected": false,
"text": "@media print{@page {size: landscape}}\n"
},
{
"answer_id": 73721340,
"author": "prajun7",
"author_id": 12778051,
"author_profile": "https://Stackoverflow.com/users/12778051",
"pm_score": 0,
"selected": false,
"text": "GlobalStyles"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138422",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/56/"
] |
138,449
|
<p>Here's the problem:</p>
<p>In C# I'm getting information from a legacy ACCESS database. .NET converts the content of the database (in the case of this problem a string) to Unicode before handing the content to me.</p>
<p>How do I convert this Unicode string back to it's ASCII equivalent?</p>
<p><hr>
<strong>Edit</strong><br>
Unicode char 710 is indeed MODIFIER LETTER CIRCUMFLEX ACCENT. Here's the problem a bit more precise: </p>
<pre> -> (Extended) ASCII character ê (Extended ASCII 136) was inserted in the database.
-> Either Access or the reading component in .NET converted this to U+02C6 U+0065
(MODIFIER LETTER CIRCUMFLEX ACCENT + LATIN SMALL LETTER E)
-> I need the (Extended) ASCII character 136 back.
</pre>
<p><hr>
Here's what I've tried (I see now why this did not work...):</p>
<pre><code>string myInput = Convert.ToString(Convert.ToChar(710));
byte[] asBytes = Encoding.ASCII.GetBytes(myInput);
</code></pre>
<p>But this does not result in 94 but a byte with value 63...<br>
Here's a new try but it still does not work:</p>
<pre><code>byte[] bytes = Encoding.ASCII.GetBytes("ê");
</code></pre>
<p><hr>
<strong>Soltution</strong><br>
Thanks to both <a href="https://stackoverflow.com/questions/138449/how-to-convert-a-unicode-character-to-its-extended-ascii-equivalent#138579">csgero</a> and <a href="https://stackoverflow.com/questions/138449/how-to-convert-a-unicode-character-to-its-extended-ascii-equivalent#138583">bzlm</a> for pointing in the right direction I solved the problem <a href="https://stackoverflow.com/questions/138449/how-to-convert-a-unicode-character-to-its-ascii-equivalent#141816">here</a>.</p>
|
[
{
"answer_id": 141816,
"author": "Huppie",
"author_id": 1830,
"author_profile": "https://Stackoverflow.com/users/1830",
"pm_score": 5,
"selected": true,
"text": "byte[] bytes = Encoding.GetEncoding(437).GetBytes(\"ê\");\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138449",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1830/"
] |
138,477
|
<p>Is it possible to send my own developed exceptions over Soap to a client using http.sys??</p>
|
[
{
"answer_id": 9320072,
"author": "dyslexicanaboko",
"author_id": 603807,
"author_profile": "https://Stackoverflow.com/users/603807",
"pm_score": 1,
"selected": false,
"text": "'This is in VB.Net\n<WebMethod()> _\nPublic Function ThrowTestSoapException() As TestSoapException\n Return New TestSoapException()\nEnd Function\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138477",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
138,493
|
<p>How does one handle a <code>DateTime</code> with a <code>NOT NULL</code>?</p>
<p>I want to do something like this:</p>
<pre><code>SELECT * FROM someTable WHERE thisDateTime IS NOT NULL
</code></pre>
<p>But how?</p>
|
[
{
"answer_id": 138495,
"author": "Johnno Nolan",
"author_id": 1116,
"author_profile": "https://Stackoverflow.com/users/1116",
"pm_score": 6,
"selected": true,
"text": "/****** Object: Table [dbo].[DateTest] Script Date: 09/26/2008 10:44:21 ******/\nSET ANSI_NULLS ON\nGO\nSET QUOTED_IDENTIFIER ON\nGO\nCREATE TABLE [dbo].[DateTest](\n [Date1] [datetime] NULL,\n [Date2] [datetime] NOT NULL\n) ON [PRIMARY]\n\nGO\nInsert into DateTest (Date1,Date2) VALUES (NULL,'1-Jan-2008')\nInsert into DateTest (Date1,Date2) VALUES ('1-Jan-2008','1-Jan-2008')\nGo\nSELECT * FROM DateTest WHERE Date1 is not NULL\nGO\nSELECT * FROM DateTest WHERE Date2 is not NULL\n"
},
{
"answer_id": 140658,
"author": "Mike Dimmick",
"author_id": 6970,
"author_profile": "https://Stackoverflow.com/users/6970",
"pm_score": 2,
"selected": false,
"text": "ANSI_NULLS"
},
{
"answer_id": 11324686,
"author": "H.M.",
"author_id": 1218928,
"author_profile": "https://Stackoverflow.com/users/1218928",
"pm_score": 2,
"selected": false,
"text": "select 1 where getdate()<>null\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138493",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14777/"
] |
138,496
|
<p>How would you go about producing reports by user selected date ranges in a rails app? What are the best date range pickers? </p>
<p>edit in response to patrick : I am looking for a bit of both widget and active record advice but what I am really curious about is how to restfully display a date ranged list based on user selected dates. </p>
|
[
{
"answer_id": 138810,
"author": "Patrick McKenzie",
"author_id": 15046,
"author_profile": "https://Stackoverflow.com/users/15046",
"pm_score": 6,
"selected": true,
"text": "date_select"
},
{
"answer_id": 140588,
"author": "Pete",
"author_id": 13472,
"author_profile": "https://Stackoverflow.com/users/13472",
"pm_score": 2,
"selected": false,
"text": " #initialize start_date and end_date up here, by pulling from params probably\n @models = SomeModel.find(:all, :conditions => ['date >= ? and date <= ?', params[:start_date], params[:end_date]])\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138496",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6805/"
] |
138,497
|
<p>How can I iterate over each file in a directory using a <code>for</code> loop?</p>
<p>And how could I tell if a certain entry is a directory or if it's just a file?</p>
|
[
{
"answer_id": 138513,
"author": "Axeman",
"author_id": 22108,
"author_profile": "https://Stackoverflow.com/users/22108",
"pm_score": 3,
"selected": false,
"text": "for %1 in (*.*) do echo %1\n"
},
{
"answer_id": 138522,
"author": "Sam Meldrum",
"author_id": 16005,
"author_profile": "https://Stackoverflow.com/users/16005",
"pm_score": 4,
"selected": false,
"text": "@echo off\nfor %%i in (*.*) do echo %%i\n"
},
{
"answer_id": 138538,
"author": "jop",
"author_id": 11830,
"author_profile": "https://Stackoverflow.com/users/11830",
"pm_score": 10,
"selected": true,
"text": "for /r %i in (*) do echo %i\n"
},
{
"answer_id": 138540,
"author": "Biri",
"author_id": 968,
"author_profile": "https://Stackoverflow.com/users/968",
"pm_score": 2,
"selected": false,
"text": "Dim fileSystemObject\nSet fileSystemObject = CreateObject(\"Scripting.FileSystemObject\")\n\nDim mainFolder\nSet mainFolder = fileSystemObject.GetFolder(myFolder)\n\nDim files\nSet files = mainFolder.Files\n\nFor Each file in files\n...\nNext\n\nDim subFolders\nSet subFolders = mainFolder.SubFolders\n\nFor Each folder in subFolders\n...\nNext\n"
},
{
"answer_id": 138581,
"author": "Marco",
"author_id": 22620,
"author_profile": "https://Stackoverflow.com/users/22620",
"pm_score": 8,
"selected": false,
"text": "for %f in (.\\*) do @echo %f"
},
{
"answer_id": 138964,
"author": "aphoria",
"author_id": 2441,
"author_profile": "https://Stackoverflow.com/users/2441",
"pm_score": 6,
"selected": false,
"text": "FOR"
},
{
"answer_id": 1092220,
"author": "Jay",
"author_id": 151152,
"author_profile": "https://Stackoverflow.com/users/151152",
"pm_score": 6,
"selected": false,
"text": "pushd somedir\nfor /f \"delims=\" %%f in ('dir /b /a-d-h-s') do echo %%f\npopd\n"
},
{
"answer_id": 3811318,
"author": "Ankur",
"author_id": 447137,
"author_profile": "https://Stackoverflow.com/users/447137",
"pm_score": 2,
"selected": false,
"text": "dir /b /a-d > AllFilesInCurrentDirectorylist.txt\n"
},
{
"answer_id": 4596730,
"author": "sugerfunk",
"author_id": 562923,
"author_profile": "https://Stackoverflow.com/users/562923",
"pm_score": 2,
"selected": false,
"text": "FOR /F \"delims=\" %I IN ('DIR /B /AD \"filename\" 2^>^&1 ^>NUL') DO IF \"%I\" == \"File Not Found\" ECHO Not a directory\n"
},
{
"answer_id": 14085171,
"author": "Knoots",
"author_id": 1936983,
"author_profile": "https://Stackoverflow.com/users/1936983",
"pm_score": 2,
"selected": false,
"text": "for /f \"delims=\" %%a IN ('xcopy \"D:\\*.pdf\" c:\\ /l') do echo %%a\n"
},
{
"answer_id": 25790431,
"author": "Max",
"author_id": 798927,
"author_profile": "https://Stackoverflow.com/users/798927",
"pm_score": 2,
"selected": false,
"text": "forfiles /s \n"
},
{
"answer_id": 37140635,
"author": "Aaron Votre",
"author_id": 5334898,
"author_profile": "https://Stackoverflow.com/users/5334898",
"pm_score": 7,
"selected": false,
"text": "for %%f in (directory\\path\\*) do ( something_here )"
},
{
"answer_id": 40930205,
"author": "Littlepony",
"author_id": 7210128,
"author_profile": "https://Stackoverflow.com/users/7210128",
"pm_score": 2,
"selected": false,
"text": "::Example directory\nset SetupDir=C:\\Users\n\n::Loop in the folder with \"/r\" to search in recursive folders, %%f being a loop ::variable \nfor /r \"%SetupDir%\" %%f in (*.msi *.exe) do set /a counter+=1\n\necho there are %counter% files in your folder\n"
},
{
"answer_id": 52523587,
"author": "Sam B",
"author_id": 1058419,
"author_profile": "https://Stackoverflow.com/users/1058419",
"pm_score": 1,
"selected": false,
"text": "cd %USERPROFILE%\\AppData\\Local\\Temp\\\nrem files only\nfor /r %%a in (*) do (\necho deleting file \"%%a\" ...\nif exist \"%%a\" del /s /q \"%%a\"\n)\nrem folders only\nfor /D %%a in (*) do (\necho deleting folder \"%%a\" ...\nif exist \"%%a\" rmdir /s /q \"%%a\"\n)\n"
},
{
"answer_id": 54925414,
"author": "jafarbtech",
"author_id": 6082645,
"author_profile": "https://Stackoverflow.com/users/6082645",
"pm_score": 3,
"selected": false,
"text": "for /F \"delims=\" %%a in ('dir /b /s') do echo %%a\n"
},
{
"answer_id": 56761665,
"author": "datchung",
"author_id": 4856020,
"author_profile": "https://Stackoverflow.com/users/4856020",
"pm_score": 3,
"selected": false,
"text": "For /R C:\\absoulte\\path\\ %%G IN (*.*) do (\n Echo %%G\n)\n"
},
{
"answer_id": 59904503,
"author": "Ste",
"author_id": 8262102,
"author_profile": "https://Stackoverflow.com/users/8262102",
"pm_score": 3,
"selected": false,
"text": "recursive"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138497",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11234/"
] |
138,501
|
<p>I have mixed data i nvarchar column (words and numbers).
Which is fastest way to sort data in this column in Numeric Order.</p>
<p>Result example:</p>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>...</li>
<li>10</li>
<li>11</li>
<li>...</li>
<li>aaaa</li>
<li>aaab</li>
<li>b</li>
<li>ba</li>
<li>ba</li>
<li>...</li>
</ul>
|
[
{
"answer_id": 138507,
"author": "Dan",
"author_id": 17121,
"author_profile": "https://Stackoverflow.com/users/17121",
"pm_score": -1,
"selected": false,
"text": "SELECT * FROM foo ORDER BY CAST(somecolumn AS int);\n"
},
{
"answer_id": 138549,
"author": "SelvirK",
"author_id": 17465,
"author_profile": "https://Stackoverflow.com/users/17465",
"pm_score": -1,
"selected": false,
"text": "SELECT * FROM TableName\nORDER BY CASE WHEN 1 = IsNumeric(ColumnName) THEN Cast(ColumnName AS INT) END\n"
},
{
"answer_id": 138567,
"author": "Lasse V. Karlsen",
"author_id": 267,
"author_profile": "https://Stackoverflow.com/users/267",
"pm_score": 5,
"selected": true,
"text": "ORDER BY\n CASE WHEN ISNUMERIC(column) = 1 THEN 0 ELSE 1 END,\n CASE WHEN ISNUMERIC(column) = 1 THEN CAST(column AS INT) ELSE 0 END,\n column\n"
},
{
"answer_id": 139562,
"author": "George Mastros",
"author_id": 1408129,
"author_profile": "https://Stackoverflow.com/users/1408129",
"pm_score": 2,
"selected": false,
"text": "Declare @Temp Table(Data VarChar(20))\n\nInsert Into @Temp Values('1')\nInsert Into @Temp Values('2')\nInsert Into @Temp Values('3')\nInsert Into @Temp Values('10')\nInsert Into @Temp Values('11')\nInsert Into @Temp Values('aaaa')\nInsert Into @Temp Values('aaab')\nInsert Into @Temp Values('b')\nInsert Into @Temp Values('ba')\nInsert Into @Temp Values('ba')\n\nSelect * From @Temp\nOrder By Case When IsNumeric(Data) = 1 \n Then Right('0000000000000000000' + Data, 20) \n Else Data End\n"
},
{
"answer_id": 139618,
"author": "Learning",
"author_id": 18275,
"author_profile": "https://Stackoverflow.com/users/18275",
"pm_score": -1,
"selected": false,
"text": "select * from Table order by ascii(Column)\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138501",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17465/"
] |
138,508
|
<p>My understanding of the MVC is as follows (incase it's horribly wrong, I am afterall new to it)</p>
<ol>
<li>Models are the things that interface with the database</li>
<li>Views are the design/layout of the page</li>
<li>Controllers are where everything starts and are essentially the page logic</li>
</ol>
<p>I'm using <a href="http://codeigniter.com/" rel="noreferrer">CodeIgniter</a> but I would hazard a guess it's not just limited to that or possibly even just to PHP frameworks.</p>
<p>Where do I put global classes?</p>
<p>I may have a model for Products and I then run a query that collects 20 products from the database. Do I now make 20 models or should I have a separate class for it, if the latter, where do I put this class (other controllers will need to use it too)</p>
|
[
{
"answer_id": 138595,
"author": "kosoant",
"author_id": 15114,
"author_profile": "https://Stackoverflow.com/users/15114",
"pm_score": 3,
"selected": true,
"text": "findByPk --> returns a single value object\nfindAll --> returns a collection of value objects (0-n)\netc.\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138508",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1384652/"
] |
138,511
|
<p>I know there's some <code>JAVA_OPTS</code> to set to remotely debug a Java program.</p>
<p>What are they and what do they mean ?</p>
|
[
{
"answer_id": 138518,
"author": "Hans Sjunnesson",
"author_id": 8683,
"author_profile": "https://Stackoverflow.com/users/8683",
"pm_score": 10,
"selected": true,
"text": "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=1044\n"
},
{
"answer_id": 173447,
"author": "paulgreg",
"author_id": 3122,
"author_profile": "https://Stackoverflow.com/users/3122",
"pm_score": 9,
"selected": false,
"text": "-Xdebug"
},
{
"answer_id": 40306242,
"author": "thebiggestlebowski",
"author_id": 1483903,
"author_profile": "https://Stackoverflow.com/users/1483903",
"pm_score": 4,
"selected": false,
"text": "java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 <YourAppName>\n"
},
{
"answer_id": 46329491,
"author": "neves",
"author_id": 10335,
"author_profile": "https://Stackoverflow.com/users/10335",
"pm_score": 2,
"selected": false,
"text": "mvnDebug"
},
{
"answer_id": 48396996,
"author": "Antony Shumskikh",
"author_id": 6488013,
"author_profile": "https://Stackoverflow.com/users/6488013",
"pm_score": 7,
"selected": false,
"text": "*:"
},
{
"answer_id": 49569527,
"author": "Jovi Qiao",
"author_id": 9573426,
"author_profile": "https://Stackoverflow.com/users/9573426",
"pm_score": 3,
"selected": false,
"text": "java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8001,suspend=y -jar target/cxf-boot-simple-0.0.1-SNAPSHOT.jar\n"
},
{
"answer_id": 54864975,
"author": "Santosh b",
"author_id": 5156999,
"author_profile": "https://Stackoverflow.com/users/5156999",
"pm_score": 2,
"selected": false,
"text": "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=PORT_NUMBER\n"
},
{
"answer_id": 59893443,
"author": "Boney",
"author_id": 6102097,
"author_profile": "https://Stackoverflow.com/users/6102097",
"pm_score": 1,
"selected": false,
"text": "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=PORT_NUMBER\n"
},
{
"answer_id": 70015702,
"author": "Prashant Jainer",
"author_id": 7030465,
"author_profile": "https://Stackoverflow.com/users/7030465",
"pm_score": -1,
"selected": false,
"text": "--debug *:($port)"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138511",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3122/"
] |
138,514
|
<p>I have a ASP.NET 2.0 webpage with 2 UserControls (.ascx). Each UserControl contains a bunch of validators. Placing a ValidationSummary on the page will display all validation errors, of both UserControl's. Placing a ValidationSummary in each UserControl will display all the errors of both controls twice. </p>
<p>What I want is a ValidationSummary for each UserControl, displaying only the errors on that UserControl. </p>
<p>I've tried to solve this by setting the ValidationGroup property of the validators on each usercontrol dynamicaly. That way each validationsummary should display only the errors of its UserControl. I've used this code:</p>
<pre><code>foreach (Control ctrl in this.Controls)
{
if (ctrl is BaseValidator)
{
(ctrl as BaseValidator).ValidationGroup = this.ClientID;
}
}
ValidationSummary1.ValidationGroup = this.ClientID;
</code></pre>
<p>This however seems to disable both clientside and server side validation, because no validation occurs when submitting the form.</p>
<p>Help?</p>
|
[
{
"answer_id": 139099,
"author": "HectorMac",
"author_id": 1400,
"author_profile": "https://Stackoverflow.com/users/1400",
"pm_score": 3,
"selected": true,
"text": "Page.Validate(MyValidationGroup1);\nPage.Validate(MyValidationGroup2);\nif(Page.IsValid)\n{\n //do stuff\n}\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138514",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6399/"
] |
138,515
|
<p>In continuation of the my <a href="https://stackoverflow.com/questions/138331/any-decent-text-diffmerge-engine-for-net">previous question</a>, are the any good controls for text diffs visualization?</p>
<p>Something like StackOverflow's revision diff viewer but for WinForms or WPF</p>
<p>Requirements:</p>
<ul>
<li>free, preferably open-source</li>
<li>based on WPF or WinForms</li>
</ul>
<p>No apps please, only components. </p>
<p><strong>I'm not interested in OSS diff tools</strong></p>
|
[
{
"answer_id": 45256402,
"author": "halllo",
"author_id": 6466378,
"author_profile": "https://Stackoverflow.com/users/6466378",
"pm_score": 2,
"selected": false,
"text": "netstandard1.0"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138515",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1196/"
] |
138,521
|
<p>How feasible would it be to compile Python (possibly via an intermediate C representation) into machine code?</p>
<p>Presumably it would need to link to a Python runtime library, and any parts of the Python standard library which were Python themselves would need to be compiled (and linked in) too.</p>
<p>Also, you would need to bundle the Python interpreter if you wanted to do dynamic evaluation of expressions, but perhaps a subset of Python that didn't allow this would still be useful.</p>
<p>Would it provide any speed and/or memory usage advantages? Presumably the startup time of the Python interpreter would be eliminated (although shared libraries would still need loading at startup).</p>
|
[
{
"answer_id": 23596973,
"author": "amirouche",
"author_id": 140837,
"author_profile": "https://Stackoverflow.com/users/140837",
"pm_score": 2,
"selected": false,
"text": "pythoncalledfromc.py"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138521",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22610/"
] |
138,547
|
<p>I'm using SQL Server 2008 with Advanced Services on my Vista Home Premium. I'd installed Full-text searching during installation, The SQL Full-text Filter Daemon Launcher is running thorough an admin user account. When I go to a database through the SQL Server Management Studio, I don't see the "Storage" option under the database, so I can't create/edit my Full-text catalogs.</p>
<p>I was able to create a Full-text catalog through T-SQL, and can run Full-text searches on the columns I've selected in the database. I'm just not able to see the "Storage" option.</p>
<p>Any idea what's missing?</p>
|
[
{
"answer_id": 1695437,
"author": "Ryan",
"author_id": 205914,
"author_profile": "https://Stackoverflow.com/users/205914",
"pm_score": 0,
"selected": false,
"text": "EXEC sp_fulltext_database 'enable';\nGO\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138547",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6939/"
] |
138,550
|
<p>I didn't find an explicit answer to this question in the WiX Documentation (or Google, for that matter). Of course I could just write the appropriate registry keys in HKCR, but it makes me feel dirty and I'd expect this to be a standard task which should have a nice default solution.</p>
<p>For bonus points, I'd like to know how to make it "safe", i.e. don't overwrite existing registrations for the file type and remove the registration on uninstall only if it has been registered during installation and is unchanged.</p>
|
[
{
"answer_id": 139151,
"author": "Edward Wilde",
"author_id": 5182,
"author_profile": "https://Stackoverflow.com/users/5182",
"pm_score": 3,
"selected": false,
"text": "<ProgId Id='AcmeFoobar.xyzfile' Description='Acme Foobar data file'>\n <Extension Id='xyz' ContentType='application/xyz'>\n <Verb Id='open' Sequence='10' Command='Open' Target='[!FileId]' Argument='\"%1\"' />\n </Extension>\n</ProgId>\n"
},
{
"answer_id": 139168,
"author": "OregonGhost",
"author_id": 20363,
"author_profile": "https://Stackoverflow.com/users/20363",
"pm_score": 4,
"selected": false,
"text": "<ProgId Id=\"MyApplication.MyFile\" Description=\"My file type\">\n <Extension Id=\"myext\" ContentType=\"application/whatever\">\n <Verb Id=\"open\" Command=\"open\" TargetFile=\"MyApplication.exe\" Argument=\""%1"\"/>\n </Extension>\n</ProgId>\n"
},
{
"answer_id": 909334,
"author": "saschabeaumont",
"author_id": 592,
"author_profile": "https://Stackoverflow.com/users/592",
"pm_score": 4,
"selected": false,
"text": "ProgId"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138550",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20363/"
] |
138,552
|
<p>I need to replace character (say) <strong>x</strong> with character (say) <strong>P</strong> in a string, but only if it is contained in a quoted substring.
An example makes it clearer:</p>
<pre><code>axbx'cxdxe'fxgh'ixj'k -> axbx'cPdPe'fxgh'iPj'k
</code></pre>
<p>Let's assume, for the sake of simplicity, that quotes always come in pairs. </p>
<p>The obvious way is to just process the string one character at a time (a simple state machine approach);<br>
however, I'm wondering if regular expressions can be used to do all the processing in one go.</p>
<p>My target language is C#, but I guess my question pertains to any language having builtin or library support for regular expressions.</p>
|
[
{
"answer_id": 138594,
"author": "Remo.D",
"author_id": 16827,
"author_profile": "https://Stackoverflow.com/users/16827",
"pm_score": 1,
"selected": false,
"text": "'<repl>'=$0\nrepl:x=P\n"
},
{
"answer_id": 138615,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 4,
"selected": true,
"text": ">>> import re\n>>> re.sub(r\"x(?=[^']*'([^']|'[^']*')*$)\", \"P\", \"axbx'cxdxe'fxgh'ixj'k\")\n\"axbx'cPdPe'fxgh'iPj'k\"\n"
},
{
"answer_id": 138620,
"author": "Zsolt Botykai",
"author_id": 11621,
"author_profile": "https://Stackoverflow.com/users/11621",
"pm_score": 1,
"selected": false,
"text": ":%s:\\('[^']*\\)x\\([^']*'\\):\\1P\\2:gci\n"
},
{
"answer_id": 138755,
"author": "jop",
"author_id": 11830,
"author_profile": "https://Stackoverflow.com/users/11830",
"pm_score": 3,
"selected": false,
"text": "[Test]\npublic void ReplaceTextInQuotes()\n{\n Assert.AreEqual(\"axbx'cPdPe'fxgh'iPj'k\", \n Regex.Replace(\"axbx'cxdxe'fxgh'ixj'k\",\n @\"x(?=[^']*'([^']|'[^']*')*$)\", \"P\"));\n}\n"
},
{
"answer_id": 139467,
"author": "Markus Jarderot",
"author_id": 22364,
"author_profile": "https://Stackoverflow.com/users/22364",
"pm_score": 1,
"selected": false,
"text": "Pattern: (?s)\\G((?:^[^']*'|(?<=.))(?:'[^']*'|[^'x]+)*+)x\nReplacement: \\1P\n"
},
{
"answer_id": 139802,
"author": "Cristian Diaconescu",
"author_id": 11545,
"author_profile": "https://Stackoverflow.com/users/11545",
"pm_score": 2,
"selected": false,
"text": "3 replacements. \nOriginal: |axbx'cxdxe'fxgh'ixj'k|\nResult: |axbx'cPdPe'fxgh'iPj'k|\n"
},
{
"answer_id": 140977,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "#!/usr/bin/perl -w\n\nuse strict;\n\n# Break up the string.\n# The spliting uses quotes\n# as the delimiter.\n# Put every broken substring\n# into the @fields array.\n\nmy @fields;\nwhile (<>) {\n @fields = split /'/, $_;\n}\n\n# For every substring indexed with an odd\n# number, search for x and replace it\n# with P.\n\nmy $count;\nmy $end = $#fields;\nfor ($count=0; $count < $end; $count++) {\n if ($count % 2 == 1) {\n $fields[$count] =~ s/a/P/g;\n } \n}\n"
},
{
"answer_id": 150711,
"author": "jfs",
"author_id": 4279,
"author_profile": "https://Stackoverflow.com/users/4279",
"pm_score": 2,
"selected": false,
"text": "#!/usr/bin/env python\nimport re\n\ntext = \"axbx'cxdxe'fxgh'ixj'k\"\n\ns = re.sub(\"'.*?'\", lambda m: re.sub(\"x\", \"P\", m.group(0)), text)\n\nprint s == \"axbx'cPdPe'fxgh'iPj'k\", s\n# -> True axbx'cPdPe'fxgh'iPj'k\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138552",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11545/"
] |
138,555
|
<p>I need to convert HTML documents into valid XML, preferably XHTML. What's the best way to do this? Does anybody know a toolkit/library/sample/...whatever that helps me to get that task done?</p>
<p>To be a bit more clear here, my application has to do the conversion automatically at runtime. I don't look for a tool that helps me to move some pages to XHTML manually.</p>
|
[
{
"answer_id": 138561,
"author": "prakash",
"author_id": 123,
"author_profile": "https://Stackoverflow.com/users/123",
"pm_score": 6,
"selected": true,
"text": "c:\\temp>tidy -help\ntidy [option...] [file...] [option...] [file...]\nUtility to clean up and pretty print HTML/XHTML/XML\nsee http://tidy.sourceforge.net/\n\nOptions for HTML Tidy for Windows released on 14 February 2006:\n\nFile manipulation\n-----------------\n -output <file>, -o write output to the specified <file>\n <file>\n -config <file> set configuration options from the specified <file>\n -file <file>, -f write errors to the specified <file>\n <file>\n -modify, -m modify the original input files\n\nProcessing directives\n---------------------\n -indent, -i indent element content\n -wrap <column>, -w wrap text at the specified <column>. 0 is assumed if\n <column> <column> is missing. When this option is omitted, the\n default of the configuration option \"wrap\" applies.\n -upper, -u force tags to upper case\n -clean, -c replace FONT, NOBR and CENTER tags by CSS\n -bare, -b strip out smart quotes and em dashes, etc.\n -numeric, -n output numeric rather than named entities\n -errors, -e only show errors\n -quiet, -q suppress nonessential output\n -omit omit optional end tags\n -xml specify the input is well formed XML\n -asxml, -asxhtml convert HTML to well formed XHTML\n -ashtml force XHTML to well formed HTML\n -access <level> do additional accessibility checks (<level> = 0, 1, 2, 3).\n 0 is assumed if <level> is missing.\n\nCharacter encodings\n-------------------\n -raw output values above 127 without conversion to entities\n -ascii use ISO-8859-1 for input, US-ASCII for output\n -latin0 use ISO-8859-15 for input, US-ASCII for output\n -latin1 use ISO-8859-1 for both input and output\n -iso2022 use ISO-2022 for both input and output\n -utf8 use UTF-8 for both input and output\n -mac use MacRoman for input, US-ASCII for output\n -win1252 use Windows-1252 for input, US-ASCII for output\n -ibm858 use IBM-858 (CP850+Euro) for input, US-ASCII for output\n -utf16le use UTF-16LE for both input and output\n -utf16be use UTF-16BE for both input and output\n -utf16 use UTF-16 for both input and output\n -big5 use Big5 for both input and output\n -shiftjis use Shift_JIS for both input and output\n -language <lang> set the two-letter language code <lang> (for future use)\n\nMiscellaneous\n-------------\n -version, -v show the version of Tidy\n -help, -h, -? list the command line options\n -xml-help list the command line options in XML format\n -help-config list all configuration options\n -xml-config list all configuration options in XML format\n -show-config list the current configuration settings\n\nUse --blah blarg for any configuration option \"blah\" with argument \"blarg\"\n\nInput/Output default to stdin/stdout respectively\nSingle letter options apart from -f may be combined\nas in: tidy -f errs.txt -imu foo.html\nFor further info on HTML see http://www.w3.org/MarkUp\n"
},
{
"answer_id": 2485280,
"author": "Cetin Sert",
"author_id": 112882,
"author_profile": "https://Stackoverflow.com/users/112882",
"pm_score": 2,
"selected": false,
"text": "var xhtml = Html2Xhtml.RunAsFilter(stdin => stdin.Write(html)).ReadToEnd();\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138555",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6777/"
] |
138,558
|
<p>Trying to understand an fft (Fast Fourier Transform) routine I'm using (stealing)(recycling)</p>
<p>Input is an array of 512 data points which are a sample waveform.
Test data is generated into this array. fft transforms this array into frequency domain.
Trying to understand relationship between freq, period, sample rate and position in fft array. I'll illustrate with examples:</p>
<p>========================================</p>
<p>Sample rate is 1000 samples/s.
Generate a set of samples at 10Hz.</p>
<p>Input array has peak values at arr(28), arr(128), arr(228) ...
period = 100 sample points</p>
<p>peak value in fft array is at index 6 (excluding a huge value at 0) </p>
<p>========================================</p>
<p>Sample rate is 8000 samples/s
Generate set of samples at 440Hz</p>
<p>Input array peak values include arr(7), arr(25), arr(43), arr(61) ...
period = 18 sample points</p>
<p>peak value in fft array is at index 29 (excluding a huge value at 0)</p>
<p>========================================</p>
<p>How do I relate the index of the peak in the fft array to frequency ?</p>
|
[
{
"answer_id": 411335,
"author": "JeffV",
"author_id": 445087,
"author_profile": "https://Stackoverflow.com/users/445087",
"pm_score": 1,
"selected": false,
"text": "s_prev = 0\ns_prev2 = 0\ncoeff = 2*cos(2*PI*normalized_frequency);\nfor each sample, x[n],\n s = x[n] + coeff*s_prev - s_prev2;\n s_prev2 = s_prev;\n s_prev = s;\nend\npower = s_prev2*s_prev2 + s_prev*s_prev - coeff*s_prev2*s_prev;\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138558",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2135219/"
] |
138,565
|
<p>For a new project that I'm doing in PHP I've created an SQLMethods class to connect to the database and perform queries. Tonight was the first night that I actually got to test it (I wrote it a week or so ago and forgot about it) and an unexpected error occured: When it was calling my ExecuteQuery() function, it wouldn't use the database I selected in the constructor.</p>
<p>The constructor:</p>
<pre><code> public function SQLMethods() {
$SQLConnection = mysql_connect($SQLDBAddress, $SQLUserName, $SQLPassword);
if (!$SQLConnection) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db($SQLDB, $SQLConnection);
}
</code></pre>
<p>The function in question:</p>
<pre><code> public function ExecuteQuery($Query) {
mysql_query($Query, $SQLConnection) or die('Could not perform query: ' . mysql_error());
}
</code></pre>
<p>Does anyone see what the issue might be? Does the connection close after the constructor completes?</p>
|
[
{
"answer_id": 138590,
"author": "cruizer",
"author_id": 6441,
"author_profile": "https://Stackoverflow.com/users/6441",
"pm_score": 4,
"selected": true,
"text": " $this->SQLConnection\n"
},
{
"answer_id": 138591,
"author": "Greg",
"author_id": 1916,
"author_profile": "https://Stackoverflow.com/users/1916",
"pm_score": 2,
"selected": false,
"text": "$SQLConnection"
},
{
"answer_id": 138599,
"author": "Ólafur Waage",
"author_id": 22459,
"author_profile": "https://Stackoverflow.com/users/22459",
"pm_score": 1,
"selected": false,
"text": "$SQLConnection"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138565",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14877/"
] |
138,576
|
<p>I'm trying to use the tree command in a windows commandline to generate a text file listing the contents of a directory but when I pipe the output the unicode characters get stuffed up.</p>
<p>Here is the command I am using:</p>
<pre><code>tree /f /a > output.txt
</code></pre>
<p>The results in the console window are fine:</p>
<pre>
\---Erika szobája
cover.jpg
Erika szobája.m3u
Kátai Tamás - 01 Télvíz.ogg
Kátai Tamás - 02 Zölderdõ.ogg
Kátai Tamás - 03 Renoir kertje.ogg
Kátai Tamás - 04 Esõben szaladtál.ogg
Kátai Tamás - 05 Ázik az út.ogg
Kátai Tamás - 06 Sûrû völgyek takaród.ogg
Kátai Tamás - 07 Õszhozó.ogg
Kátai Tamás - 08 Mécsvilág.ogg
Kátai Tamás - 09 Zúzmara.ogg
</pre>
<p>But the text file is no good:</p>
<pre>
\---Erika szob ja
cover.jpg
Erika szob ja.m3u
K tai Tam s - 01 T‚lv¡z.ogg
K tai Tam s - 02 Z”lderdä.ogg
K tai Tam s - 03 Renoir kertje.ogg
K tai Tam s - 04 Esäben szaladt l.ogg
K tai Tam s - 05 µzik az £t.ogg
K tai Tam s - 06 S–r– v”lgyek takar¢d.ogg
K tai Tam s - 07 åszhoz¢.ogg
K tai Tam s - 08 M‚csvil g.ogg
K tai Tam s - 09 Z£zmara.ogg
</pre>
<p>How can I fix this? Ideally the text file would be exactly the same as the output in the console window.</p>
<p>I tried Chris Jester-Young's suggestion (what happened, did you delete it Chris?) of running the command line with the /U switch, it looked like exactly what I needed but it does not appear to work. I have tried opening the file in both VS2008 and notepad and both show the same incorrect characters.</p>
|
[
{
"answer_id": 139302,
"author": "C. K. Young",
"author_id": 13,
"author_profile": "https://Stackoverflow.com/users/13",
"pm_score": 3,
"selected": false,
"text": "tree.com"
},
{
"answer_id": 2767458,
"author": "sorin",
"author_id": 99834,
"author_profile": "https://Stackoverflow.com/users/99834",
"pm_score": 2,
"selected": false,
"text": "tree.com"
},
{
"answer_id": 8556928,
"author": "Chris",
"author_id": 1105206,
"author_profile": "https://Stackoverflow.com/users/1105206",
"pm_score": 2,
"selected": false,
"text": "tree /f /a > %temp%\\Listing >> files.txt\n"
},
{
"answer_id": 11199864,
"author": "Ricardo Bohner",
"author_id": 1481477,
"author_profile": "https://Stackoverflow.com/users/1481477",
"pm_score": 7,
"selected": true,
"text": "tree /f /a |clip\n"
},
{
"answer_id": 14517967,
"author": "Kenn",
"author_id": 629644,
"author_profile": "https://Stackoverflow.com/users/629644",
"pm_score": 2,
"selected": false,
"text": "tree /A > output.txt\n"
},
{
"answer_id": 15961769,
"author": "XP1",
"author_id": 412486,
"author_profile": "https://Stackoverflow.com/users/412486",
"pm_score": 4,
"selected": false,
"text": "powershell -command \"tree /f > tree.txt\"\n"
},
{
"answer_id": 16087554,
"author": "Ricardo Bohner",
"author_id": 2295852,
"author_profile": "https://Stackoverflow.com/users/2295852",
"pm_score": 3,
"selected": false,
"text": "tree /f > ascii.txt\n"
},
{
"answer_id": 38905948,
"author": "Miguel",
"author_id": 6678484,
"author_profile": "https://Stackoverflow.com/users/6678484",
"pm_score": 0,
"selected": false,
"text": "tree"
},
{
"answer_id": 44244216,
"author": "user1959451",
"author_id": 1959451,
"author_profile": "https://Stackoverflow.com/users/1959451",
"pm_score": 1,
"selected": false,
"text": "tree /f /a > output.txt\n"
},
{
"answer_id": 51255816,
"author": "Gras Double",
"author_id": 289317,
"author_profile": "https://Stackoverflow.com/users/289317",
"pm_score": 2,
"selected": false,
"text": "PowerShell -Command \"TREE /F | Out-File output.txt -Encoding utf8\"\n"
},
{
"answer_id": 68489416,
"author": "Minty",
"author_id": 6804439,
"author_profile": "https://Stackoverflow.com/users/6804439",
"pm_score": 0,
"selected": false,
"text": "function listTree {\n tree /f\n echo .\n}\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138576",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/48281/"
] |
138,600
|
<p>What is the right way of initializing a static map? Do we need a static function that will initialize it? </p>
|
[
{
"answer_id": 138612,
"author": "Ferruccio",
"author_id": 4086,
"author_profile": "https://Stackoverflow.com/users/4086",
"pm_score": 9,
"selected": false,
"text": "#include <map>\nusing namespace std;\n\nmap<int, char> m = {{1, 'a'}, {3, 'b'}, {5, 'c'}, {7, 'd'}};\n"
},
{
"answer_id": 138633,
"author": "PierreBdR",
"author_id": 7136,
"author_profile": "https://Stackoverflow.com/users/7136",
"pm_score": 7,
"selected": false,
"text": "#include <map>\n\nusing namespace std;\n\nmap<int,int> create_map()\n{\n map<int,int> m;\n m[1] = 2;\n m[3] = 4;\n m[5] = 6;\n return m;\n}\n\nmap<int,int> m = create_map();\n"
},
{
"answer_id": 1730798,
"author": "Vite Falcon",
"author_id": 210634,
"author_profile": "https://Stackoverflow.com/users/210634",
"pm_score": 7,
"selected": false,
"text": "template <typename T, typename U>\nclass create_map\n{\nprivate:\n std::map<T, U> m_map;\npublic:\n create_map(const T& key, const U& val)\n {\n m_map[key] = val;\n }\n\n create_map<T, U>& operator()(const T& key, const U& val)\n {\n m_map[key] = val;\n return *this;\n }\n\n operator std::map<T, U>()\n {\n return m_map;\n }\n};\n"
},
{
"answer_id": 1731203,
"author": "eduffy",
"author_id": 7536,
"author_profile": "https://Stackoverflow.com/users/7536",
"pm_score": 3,
"selected": false,
"text": "PierreBdR"
},
{
"answer_id": 2096681,
"author": "Brian Neal",
"author_id": 63485,
"author_profile": "https://Stackoverflow.com/users/63485",
"pm_score": 6,
"selected": false,
"text": "#include <map>\n#include <string>\n\ntypedef std::map<std::string, int> MyMap;\n\nconst MyMap::value_type rawData[] = {\n MyMap::value_type(\"hello\", 42),\n MyMap::value_type(\"world\", 88),\n};\nconst int numElems = sizeof rawData / sizeof rawData[0];\nMyMap myMap(rawData, rawData + numElems);\n"
},
{
"answer_id": 24683285,
"author": "user3826594",
"author_id": 3826594,
"author_profile": "https://Stackoverflow.com/users/3826594",
"pm_score": 4,
"selected": false,
"text": "#include <map>\n\nstd::map<std::string, std::string> aka;\n\nstruct akaInit\n{\n akaInit()\n {\n aka[ \"George\" ] = \"John\";\n aka[ \"Joe\" ] = \"Al\";\n aka[ \"Phil\" ] = \"Sue\";\n aka[ \"Smitty\" ] = \"Yando\";\n }\n} AkaInit;\n"
},
{
"answer_id": 39423771,
"author": "Dmitry Oberemchenko",
"author_id": 6816103,
"author_profile": "https://Stackoverflow.com/users/6816103",
"pm_score": 4,
"selected": false,
"text": "std::map <int, int> mymap = \n{\n std::pair <int, int> (1, 1),\n std::pair <int, int> (2, 2),\n std::pair <int, int> (2, 2)\n};\n"
},
{
"answer_id": 41368801,
"author": "isnullxbh",
"author_id": 6266408,
"author_profile": "https://Stackoverflow.com/users/6266408",
"pm_score": 5,
"selected": false,
"text": "const std::map<LogLevel, const char*> g_log_levels_dsc =\n{\n { LogLevel::Disabled, \"[---]\" },\n { LogLevel::Info, \"[inf]\" },\n { LogLevel::Warning, \"[wrn]\" },\n { LogLevel::Error, \"[err]\" },\n { LogLevel::Debug, \"[dbg]\" }\n};\n"
},
{
"answer_id": 42650007,
"author": "Emanuele Benedetti",
"author_id": 5720542,
"author_profile": "https://Stackoverflow.com/users/5720542",
"pm_score": 3,
"selected": false,
"text": "typedef std::pair< int, char > elemPair_t;\nelemPair_t elemPairs[] = \n{\n elemPair_t( 1, 'a'), \n elemPair_t( 3, 'b' ), \n elemPair_t( 5, 'c' ), \n elemPair_t( 7, 'd' )\n};\n\nconst std::map< int, char > myMap( &elemPairs[ 0 ], &elemPairs[ sizeof( elemPairs ) / sizeof( elemPairs[ 0 ] ) ] );\n"
},
{
"answer_id": 66635078,
"author": "Hans Olsson",
"author_id": 5603247,
"author_profile": "https://Stackoverflow.com/users/5603247",
"pm_score": 2,
"selected": false,
"text": "const std::map<int, int> m = {{1,1},{4,2},{9,3},{16,4},{32,9}}\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138600",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15163/"
] |
138,607
|
<p>I have a very simple bit of script that changes the status of an item in a MySql database - it works fine in IE7, but if I try it in Firefox, it looks like it's worked, but hasn't... Which is extremely odd.</p>
<p>The code is very simple - first I get the details of the record I'm looking for:</p>
<pre><code><cfscript>
// Get the Product Attribute details
Arguments.qGetProductAttribute = Application.cfcProducts.getProductAttributes(Arguments.iProductAttributeID);
</cfscript>
</code></pre>
<p>This is working fine, if I dump the results, it's just the content of the record as expected. So then I use an if statement to change the 'active' field from one to zero or vice versa.</p>
<pre><code><!--- If Product Attribute is active, mark as inactive --->
<cfif Arguments.qGetProductAttribute.bActive EQ 0>
<cfquery name="qChangeStatus" datasource="#Request.sDSN#">
UPDATE tblProductAttributes
SET bActive = <cfqueryparam value="1" cfsqltype="CF_SQL_INTEGER" maxlength="1" />
WHERE iProductAttributeID = <cfqueryparam value="#Arguments.iProductAttributeID#" cfsqltype="CF_SQL_INTEGER" />;
</cfquery>
<!--- Else if Product Attribute is inactive, mark as active --->
<cfelseif Arguments.qGetProductAttribute.bActive EQ 1>
<cfquery name="qChangeStatus" datasource="#Request.sDSN#">
UPDATE tblProductAttributes
SET bActive = <cfqueryparam value="0" cfsqltype="CF_SQL_INTEGER" maxlength="1" />
WHERE iProductAttributeID = <cfqueryparam value="#Arguments.iProductAttributeID#" cfsqltype="CF_SQL_INTEGER" />;
</cfquery>
</cfif>
</code></pre>
<p>I can't see any reason whatsoever for this not to work... and indeed, in IE7 it works perfectly...</p>
<p>What happens is after this script is run, the browser goes back to the page that displays all of these records. For each record if the 'bActive' field is set to '1', it will display the word 'Active' and if it's set to 'zero', it will display 'Disabled'.
Simple enough.</p>
<p>If I run the script to disable a record, Firefox actually displays the word 'disabled' as expected, but the database record doesn't change!</p>
<p>I'm at a loss... how can server-side code work fine in one browser and not in another?!</p>
|
[
{
"answer_id": 139807,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "WHERE iProductAttributeID = <cfqueryparam value=\"#Arguments.iProductAttributeID#\" cfsqltype=\"CF_SQL_INTEGER\" />;\n"
},
{
"answer_id": 140577,
"author": "ale",
"author_id": 21960,
"author_profile": "https://Stackoverflow.com/users/21960",
"pm_score": 2,
"selected": false,
"text": "<cfquery name=\"qChangeStatus\" datasource=\"#Request.sDSN#\">\n UPDATE tblProductAttributes\n SET\n bActive = <cfqueryparam value=\"#val(1 - Arguments.qGetProductAttribute.bActive)#\" cfsqltype=\"CF_SQL_INTEGER\" maxlength=\"1\" />\n WHERE \n iProductAttributeID = <cfqueryparam value=\"#Arguments.iProductAttributeID#\" cfsqltype=\"CF_SQL_INTEGER\" />;\n</cfquery>\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138607",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22113/"
] |
138,616
|
<p>I need to enumerate all running applications. In particular, all top windows. And for every window I need to add my custom item to the system menu of that window.</p>
<p>How can I accomplish that in C++?</p>
<p><strong>Update.</strong></p>
<p>I would be more than happy to have a solution for Windows, MacOS, and Ubuntu (though, I'm not sure if MacOS and Ubuntu have such thing as 'system menu').</p>
|
[
{
"answer_id": 138657,
"author": "Chris",
"author_id": 2134,
"author_profile": "https://Stackoverflow.com/users/2134",
"pm_score": 1,
"selected": false,
"text": "HMENU hMenu = GetMenu(hwndNext);\n"
},
{
"answer_id": 138896,
"author": "efotinis",
"author_id": 12320,
"author_profile": "https://Stackoverflow.com/users/12320",
"pm_score": 3,
"selected": false,
"text": "HWND wnd = GetWindow(GetDesktopWindow(), GW_CHILD);\nwhile (wnd) {\n // handle 'wnd' here\n // ...\n wnd = GetNextWindow(wnd, GW_HWNDNEXT);\n}\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138616",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22623/"
] |
138,617
|
<p>Is there a way to create an html link using h:outputLink, other JSF tag or code to create a non faces request (HTTP GET) with request parameters?</p>
<p>For example I have the following navigation-rule</p>
<pre><code><navigation-rule>
<navigation-case>
<from-outcome>showMessage</from-outcome>
<to-view-id>/showMessage.jsf</to-view-id>
<redirect/>
</navigation-case>
</navigation-rule>
</code></pre>
<p>In my page I would like to output the following html code:</p>
<pre><code><a href="/showMessage.jsf?msg=23">click to see the message</a>
</code></pre>
<p>I could just write the html code in the page, but I want to use the navigation rule in order to have all the urls defined in a single configurable file.</p>
|
[
{
"answer_id": 139620,
"author": "hubbardr",
"author_id": 22457,
"author_profile": "https://Stackoverflow.com/users/22457",
"pm_score": 0,
"selected": false,
"text": "<h:form>\n <h:commandLink value=\"Click to see the message\" action=\"#{handler.outcome}\" />\n <h:inputHidden id=\"msgId\" value=\"#{bean.msgId}\"/>\n</h:form>\n"
},
{
"answer_id": 140050,
"author": "McDowell",
"author_id": 304,
"author_profile": "https://Stackoverflow.com/users/304",
"pm_score": 5,
"selected": true,
"text": "<managed-bean>\n <managed-bean-name>navBean</managed-bean-name>\n <managed-bean-class>foo.NavBean</managed-bean-class>\n <managed-bean-scope>application</managed-bean-scope>\n</managed-bean>\n"
},
{
"answer_id": 163930,
"author": "Ian McLaird",
"author_id": 18796,
"author_profile": "https://Stackoverflow.com/users/18796",
"pm_score": 0,
"selected": false,
"text": "<h:form>\n <h:commandLink value=\"click here\" action=\"${handler.outcome}\">\n <f:param name=\"msgId\" value=\"${bean.id}\" />\n </h:commandLink>\n</h:form>\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138617",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19331/"
] |
138,638
|
<p>Can I expose a class from another .net namespace as a class in my namespace? I use a class - antlr.collections.AST - as the return type for a function belonging to a class in my namespace; as a result, the user has to have</p>
<pre><code>using antlr.collections;
using myNamespace;
</code></pre>
<p>at the top of their files in order to use my function. Can I make myNamespace.AST an alias for antlr.collections.AST, such that the user only has to have</p>
<pre><code>using myNamespace;
</code></pre>
<p>at the top of their files?</p>
|
[
{
"answer_id": 138642,
"author": "Agnel Kurian",
"author_id": 45603,
"author_profile": "https://Stackoverflow.com/users/45603",
"pm_score": 2,
"selected": false,
"text": "namespace MyForms {\n class Class1 : Some.Other.Namespace.Class1 {\n // ...\n }\n}\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138638",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15371/"
] |
138,669
|
<p>How can i check in JavaScript if a variable is defined in a page? Suppose I want to check if a variable named "x" is defined in a page, if I do <code>if(x != null)</code>, it gives me an error.</p>
|
[
{
"answer_id": 138671,
"author": "Nick Berardi",
"author_id": 17,
"author_profile": "https://Stackoverflow.com/users/17",
"pm_score": -1,
"selected": false,
"text": "if (x !== undefined)\n"
},
{
"answer_id": 138676,
"author": "SSharma",
"author_id": 22628,
"author_profile": "https://Stackoverflow.com/users/22628",
"pm_score": 7,
"selected": false,
"text": "if (typeof(x) != \"undefined\")"
},
{
"answer_id": 138883,
"author": "Pablo Cabrera",
"author_id": 12540,
"author_profile": "https://Stackoverflow.com/users/12540",
"pm_score": 5,
"selected": false,
"text": "if (typeof a != \"undefined\") {\n a();\n}\n"
},
{
"answer_id": 139631,
"author": "kamens",
"author_id": 1335,
"author_profile": "https://Stackoverflow.com/users/1335",
"pm_score": 0,
"selected": false,
"text": "if (window.a != null) {\n a();\n}\n"
},
{
"answer_id": 141480,
"author": "Andrew Hedges",
"author_id": 11577,
"author_profile": "https://Stackoverflow.com/users/11577",
"pm_score": 6,
"selected": false,
"text": "if ('undefined' !== typeof x) {\n"
},
{
"answer_id": 3893015,
"author": "Dagg Nabbit",
"author_id": 886931,
"author_profile": "https://Stackoverflow.com/users/886931",
"pm_score": 1,
"selected": false,
"text": "typeof"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138669",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22628/"
] |
138,670
|
<p>How unique is the php session id? I got the impression from various things that I've read that I should not rely on two users never getting the same sessionid. Isn't it a GUID?</p>
|
[
{
"answer_id": 138748,
"author": "djsadinoff",
"author_id": 22369,
"author_profile": "https://Stackoverflow.com/users/22369",
"pm_score": 6,
"selected": false,
"text": "ini_set(\"session.entropy_file\", \"/dev/urandom\");\nini_set(\"session.entropy_length\", \"512\");\n"
},
{
"answer_id": 11024386,
"author": "MrJ",
"author_id": 973956,
"author_profile": "https://Stackoverflow.com/users/973956",
"pm_score": 3,
"selected": false,
"text": "num_sesion_ids = 1000*365.25 *7*10**9 < 2**36\ncollission_prob < 1 - (1-1/2**82)**(2**36) ≈ 1 - e**-(1/2**46) \n ≈ 1/2**46 \n"
},
{
"answer_id": 51474840,
"author": "Arun Sharma",
"author_id": 10110781,
"author_profile": "https://Stackoverflow.com/users/10110781",
"pm_score": -1,
"selected": false,
"text": "<?php\nsession_start();\n$_SESSION['username']=\"username\";\n?>\n\n<!DOCTYPE html>\n<html>\n<head>\n <title>Update</title>\n</head>\n<body>\n\n<table border=\"2\">\n <tr>\n <th>Username</th>\n <th>Email</th>\n <th>Edit</th>\n </tr>\n<?php\n $conn=mysqli_connect(\"localhost\",\"root\",\"\",\"telephasic\");\n $q2=\"select * from register where username = '\".$_SESSION['username'].\"'\";\n $run=mysqli_query($conn, $q2);\n while($row=mysqli_fetch_array($run))\n {\n $name=$row[1];\n $email=$row[2];\n ?>\n\n <tr>\n <td><?php echo $name; ?></td>\n <td><?php echo $email; ?></td>\n <td><a href=\"edit.php\"> Edit </a></td>\n </tr>\n <?php } ?>\n </table> \n </body>\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138670",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22629/"
] |
138,680
|
<p>is it possible to extend vim functionality via custom extension (preferably, written in Python)?</p>
<p>What I need ideally is custom command when in command mode. E.g.</p>
<p>ESC</p>
<p>:do_this</p>
<p>:do_that</p>
|
[
{
"answer_id": 138709,
"author": "Paolo Tedesco",
"author_id": 15622,
"author_profile": "https://Stackoverflow.com/users/15622",
"pm_score": 5,
"selected": true,
"text": "./configure --enable-pythoninterp \nmake\nsudo make install\n"
},
{
"answer_id": 5293536,
"author": "vrybas",
"author_id": 523157,
"author_profile": "https://Stackoverflow.com/users/523157",
"pm_score": 2,
"selected": false,
"text": "python2.6-dev"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138680",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22623/"
] |
138,696
|
<p>I have a multithreded application in perl for which I have to rely on several non-thread safe modules, so I have been using <code>fork()</code>ed processes with <code>kill()</code> signals as a message passing interface.</p>
<p>The problem is that the signal handlers are a bit erratic (to say the least) and often end up with processes that get killed in inapropriate states.</p>
<p>Is there a better way to do this?</p>
|
[
{
"answer_id": 138787,
"author": "innaM",
"author_id": 7498,
"author_profile": "https://Stackoverflow.com/users/7498",
"pm_score": 3,
"selected": false,
"text": "pipe my $reader, my $writer;\nmy $pid = fork();\nif ( $pid == 0 ) {\n close $reader;\n ...\n}\nelse {\n close $writer;\n my $msg_from_child = <$reader>;\n ....\n}\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138696",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7780/"
] |
138,703
|
<p>Is there any way to automatically wrap comments at the 80-column boundary as you type them? ..or failing that, any way to display a faint line at the coulmn 80 boundary to make wrapping them manually a little easier?</p>
<p>Several other IDEs I use have one or other of those functions and it makes writing comments that wrap in sensible places much easier/quicker.</p>
<p><strong>[Edit]</strong> If (like me) you're using Visual C++ Express, you need to change the VisualStudio part of the key into VCExpress - had me confused for a while there!</p>
|
[
{
"answer_id": 138962,
"author": "Jon Cage",
"author_id": 15369,
"author_profile": "https://Stackoverflow.com/users/15369",
"pm_score": 2,
"selected": false,
"text": "HKEY_CURRENT_USER\\Software\\Microsoft\\VCExpress\\9.0\\Text Editor\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138703",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15369/"
] |
138,747
|
<p>A client of mine uses Oracle 9i's utl_smtp to send mails out notifications to managers when their employees have made travel requests and they woul like quite a few changes made to the mailouts done. </p>
<p>We're having a lot of problems getting utl_smtp to talk to any smtp server on our network. We've even tried installing free smtp server on the oracle box but it will not spot the mail server running on port 25. The error code is ORA-29278.</p>
<p>So two questions really.</p>
<ol>
<li><p>Does anyone have any experience setting up email using Oracle's utl_smtp utility and have any suggestions as to where we might be going wrong.</p></li>
<li><p>Does anyone know if it is possible to get utl_smtp to dump text emails to a directory much as you can do if you're using system.net.mail's specifiedpickupdirectory config setting. This would be by far the preferable option.</p></li>
</ol>
<p>Thanks, Dan</p>
|
[
{
"answer_id": 139021,
"author": "Dan Maharry",
"author_id": 2756,
"author_profile": "https://Stackoverflow.com/users/2756",
"pm_score": 1,
"selected": false,
"text": "-- ****** Object: Stored Procedure TRAVELADMIN_DEV.HTML_EMAIL Script Date: 22/08/2008 12:41:02 ******\nCREATE PROCEDURE \"HTML_EMAIL\" (\n p_to in varchar2,\n p_cc in varchar2,\n p_from in varchar2,\n p_subject in varchar2,\n p_text in varchar2 default null,\n p_html in varchar2 default null\n )\nis\n l_boundary varchar2(255) default 'a1b2c3d4e3f2g1';\n l_connection utl_smtp.connection;\n l_body_html clob := empty_clob; --This LOB will be the email message\n l_offset number;\n l_ammount number;\n l_temp varchar2(32767) default null;\n p_smtp_hostname varchar2(30):= 'rockies';\n p_smtp_portnum varchar2(2) := '25';\nbegin\n l_connection := utl_smtp.open_connection( p_smtp_hostname, p_smtp_portnum );\n utl_smtp.helo( l_connection, p_smtp_hostname );\n utl_smtp.mail( l_connection, p_from );\n utl_smtp.rcpt( l_connection, p_to );\n l_temp := l_temp || 'MIME-Version: 1.0' || chr(13) || chr(10);\n l_temp := l_temp || 'To: ' || p_to || chr(13) || chr(10);\n IF ((p_cc <> NULL) OR (LENGTH(p_cc) > 0)) THEN\n l_temp := l_temp || 'Cc: ' || p_cc || chr(13) || chr(10);\n utl_smtp.rcpt( l_connection, p_cc );\n END IF;\n l_temp := l_temp || 'From: ' || p_from || chr(13) || chr(10);\n l_temp := l_temp || 'Subject: ' || p_subject || chr(13) || chr(10);\n l_temp := l_temp || 'Reply-To: ' || p_from || chr(13) || chr(10);\n l_temp := l_temp || 'Content-Type: multipart/alternative; boundary=' ||\n chr(34) || l_boundary || chr(34) || chr(13) ||\n chr(10);\n ----------------------------------------------------\n -- Write the headers\n dbms_lob.createtemporary( l_body_html, false, 10 );\n dbms_lob.write(l_body_html,length(l_temp),1,l_temp);\n ----------------------------------------------------\n -- Write the text boundary\n l_offset := dbms_lob.getlength(l_body_html) + 1;\n l_temp := '--' || l_boundary || chr(13)||chr(10);\n l_temp := l_temp || 'content-type: text/plain; charset=us-ascii' ||\n chr(13) || chr(10) || chr(13) || chr(10);\n dbms_lob.write(l_body_html,length(l_temp),l_offset,l_temp);\n ----------------------------------------------------\n -- Write the plain text portion of the email\n l_offset := dbms_lob.getlength(l_body_html) + 1;\n dbms_lob.write(l_body_html,length(p_text),l_offset,p_text);\n ----------------------------------------------------\n -- Write the HTML boundary\n l_temp := chr(13)||chr(10)||chr(13)||chr(10)||'--' || l_boundary ||\n chr(13) || chr(10);\n l_temp := l_temp || 'content-type: text/html;' ||\n chr(13) || chr(10) || chr(13) || chr(10);\n l_offset := dbms_lob.getlength(l_body_html) + 1;\n dbms_lob.write(l_body_html,length(l_temp),l_offset,l_temp);\n ----------------------------------------------------\n -- Write the HTML portion of the message\n l_offset := dbms_lob.getlength(l_body_html) + 1;\n dbms_lob.write(l_body_html,length(p_html),l_offset,p_html);\n ----------------------------------------------------\n -- Write the final html boundary\n l_temp := chr(13) || chr(10) || '--' || l_boundary || '--' || chr(13);\n l_offset := dbms_lob.getlength(l_body_html) + 1;\n dbms_lob.write(l_body_html,length(l_temp),l_offset,l_temp);\n ----------------------------------------------------\n -- Send the email in 1900 byte chunks to UTL_SMTP\n l_offset := 1;\n l_ammount := 1900;\n utl_smtp.open_data(l_connection);\n while l_offset < dbms_lob.getlength(l_body_html) loop\n utl_smtp.write_data(l_connection,\n dbms_lob.substr(l_body_html,l_ammount,l_offset));\n l_offset := l_offset + l_ammount ;\n l_ammount := least(1900,dbms_lob.getlength(l_body_html) - l_ammount);\n end loop;\n utl_smtp.close_data(l_connection);\n utl_smtp.quit( l_connection );\n dbms_lob.freetemporary(l_body_html);\nend;\n"
},
{
"answer_id": 139860,
"author": "cagcowboy",
"author_id": 19629,
"author_profile": "https://Stackoverflow.com/users/19629",
"pm_score": 3,
"selected": true,
"text": "set serveroutput on\n\ndeclare\n lConnection UTL_SMTP.CONNECTION;\nbegin\n lConnection := UTL_SMTP.OPEN_CONNECTION(your_smtp_server);\n DBMS_OUTPUT.PUT_LINE('Opened ok');\n\n UTL_SMTP.HELO(lConnection, your_client_machine_name);\n DBMS_OUTPUT.PUT_LINE('HELO ok');\n\n UTL_SMTP.MAIL(lConnection, your_email_address);\n UTL_SMTP.RCPT(lConnection, your_email_address);\n DBMS_OUTPUT.PUT_LINE('Addressing ok');\nend;\n/\n"
},
{
"answer_id": 179045,
"author": "Dan Maharry",
"author_id": 2756,
"author_profile": "https://Stackoverflow.com/users/2756",
"pm_score": 2,
"selected": false,
"text": "utl_smtp"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138747",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2756/"
] |
138,758
|
<p>I have an msi installer which was working fine. I added an external merge module. There were some directory merge errors during compilation. I removed the directories causing the error from the directory table of the merge module.</p>
<p>I am getting the error:</p>
<blockquote>
<p>MSI error 2732 error :Directory Manager not initialized.</p>
</blockquote>
<p>Please help in solving the issue.</p>
|
[
{
"answer_id": 53765568,
"author": "posix99",
"author_id": 6612140,
"author_profile": "https://Stackoverflow.com/users/6612140",
"pm_score": 0,
"selected": false,
"text": "msiexec /i <package.msi> /l*v <logfile>\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138758",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
138,771
|
<p>I'm just meddling in the ways of the RESTful web service in C# using ASP.Net 2.0 and have managed (via a class library, a reference to dll produced by the former and some adjustment of my web.config) to coax out a URI format like so:</p>
<p>http: //localhost/DevelopmentProject/testhandler/?input=thisismyinput</p>
<p>Which unremarkably just returns the input as a piece of text with the enlightening prefix "Your Input Was: "</p>
<p>I was under the impression that I could get the URI to become further ensmoothened to something more along the lines of:</p>
<p>http: //localhost/DevelopmentProject/testhandler/thisismyinput</p>
<p>and have the same result but have no idea how to get rid of the pesky "?input="</p>
<p>The entry to the httphandlers section of my web.config is (spaces added so code displays):</p>
<p>< add verb="*" path="testhandler/*" type="HandlerLib.testhandler, HandlerLib"/ ></p>
<p>I am running IIS 5.1 on the local machine, will this introduce a problem?</p>
<p>Essentially where am I going wrong?</p>
<p>Thanks.</p>
|
[
{
"answer_id": 138833,
"author": "WebDude",
"author_id": 15360,
"author_profile": "https://Stackoverflow.com/users/15360",
"pm_score": 1,
"selected": false,
"text": "<rewriter>\n <rewrite \n url=\"DevelopmentProject/testhandler/([\\w]+)\" \n to=\"DevelopmentProject/testhandler/?input=$1\" />\n</rewriter>\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138771",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
138,785
|
<p>I'm trying to learn RegEx in Ruby, based on what I'm reading in "<em>The Rails Way</em>". But, even this simple example has me stumped. I can't tell if it is a typo or not:</p>
<pre><code>text.gsub(/\s/, "-").gsub([^\W-], '').downcase
</code></pre>
<p>It seems to me that this would replace all spaces with <code>-</code>, then anywhere a string starts with a non letter or number followed by a dash, replace that with ''. But, using irb, it fails first on <code>^</code>:</p>
<blockquote>
<p>syntax error, unexpected '^', expecting ']'</p>
</blockquote>
<p>If I take out the <code>^</code>, it fails again on the W.</p>
|
[
{
"answer_id": 138800,
"author": "Khoth",
"author_id": 20686,
"author_profile": "https://Stackoverflow.com/users/20686",
"pm_score": 2,
"selected": false,
"text": "/[^\\W-]/"
},
{
"answer_id": 138809,
"author": "Vinko Vrsalovic",
"author_id": 5190,
"author_profile": "https://Stackoverflow.com/users/5190",
"pm_score": 4,
"selected": true,
"text": ">> text = \"I love spaces\"\n=> \"I love spaces\"\n>> text.gsub(/\\s/, \"-\").gsub(/[^\\W-]/, '').downcase\n=> \"--\"\n"
},
{
"answer_id": 138855,
"author": "Vinko Vrsalovic",
"author_id": 5190,
"author_profile": "https://Stackoverflow.com/users/5190",
"pm_score": 2,
"selected": false,
"text": ">> text.gsub(/\\s/, \"-\").gsub(/[^\\w-]/, '').downcase\n=> \"i-love-spaces\"\n"
},
{
"answer_id": 142565,
"author": "Orion Edwards",
"author_id": 234,
"author_profile": "https://Stackoverflow.com/users/234",
"pm_score": 2,
"selected": false,
"text": "text.gsub(/\\s/, \"-\")\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138785",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9450/"
] |
138,793
|
<p>I have a <em>JComboBox</em> and would like to have a separator in the list of elements. How do I do this in Java?</p>
<p>A sample scenario where this would come in handy is when making a combobox for font-family-selection; similar to the font-family-selection-control in Word and Excel. In this case I would like to show the most-used-fonts at the top, then a separator and finally all font-families below the separator in alphabetical order.</p>
<p>Can anyone help me with how to do this or is this not possible in Java?</p>
|
[
{
"answer_id": 138849,
"author": "macbirdie",
"author_id": 5049,
"author_profile": "https://Stackoverflow.com/users/5049",
"pm_score": 2,
"selected": false,
"text": "ListCellRenderer"
},
{
"answer_id": 139366,
"author": "PhiLho",
"author_id": 15459,
"author_profile": "https://Stackoverflow.com/users/15459",
"pm_score": 2,
"selected": false,
"text": "import java.awt.*;\nimport javax.swing.*;\n\n\n@SuppressWarnings(\"serial\")\npublic class TwoPartsComboBox extends JComboBox\n{\n private int m_lastFirstPartIndex;\n\n public TwoPartsComboBox(String[] itemsFirstPart, String[] itemsSecondPart)\n {\n super(itemsFirstPart);\n m_lastFirstPartIndex = itemsFirstPart.length - 1;\n for (int i = 0; i < itemsSecondPart.length; i++)\n {\n insertItemAt(itemsSecondPart[i], i);\n }\n\n setRenderer(new JLRenderer());\n }\n\n protected class JLRenderer extends JLabel implements ListCellRenderer\n {\n private JLabel m_lastFirstPart;\n\n public JLRenderer()\n {\n m_lastFirstPart = new JLabel();\n m_lastFirstPart.setBorder(new BottomLineBorder());\n// m_lastFirstPart.setBorder(new BottomLineBorder(10, Color.BLUE));\n }\n\n @Override\n public Component getListCellRendererComponent(\n JList list,\n Object value,\n int index,\n boolean isSelected,\n boolean cellHasFocus)\n {\n if (value == null)\n {\n value = \"Select an option\";\n }\n JLabel label = this;\n if (index == m_lastFirstPartIndex)\n {\n label = m_lastFirstPart;\n }\n label.setText(value.toString());\n label.setBackground(isSelected ? list.getSelectionBackground() : list.getBackground());\n label.setForeground(isSelected ? list.getSelectionForeground() : list.getForeground());\n label.setOpaque(true);\n\n return label;\n }\n }\n}\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138793",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3379/"
] |
138,819
|
<p>If I am iterating over each file using :</p>
<pre><code>@echo off
FOR %%f IN (*\*.\**) DO (
echo %%f
)
</code></pre>
<p>how could I print the extension of each file? I tried assigning %%f to a temporary variable, and then using the code : <code>echo "%t:~-3%"</code> to print but with no success.</p>
|
[
{
"answer_id": 138847,
"author": "Sam Holloway",
"author_id": 1377325,
"author_profile": "https://Stackoverflow.com/users/1377325",
"pm_score": 6,
"selected": true,
"text": "@echo off\nfor %%i in (*.*) do echo \"%%~xi\"\n"
},
{
"answer_id": 138913,
"author": "paxdiablo",
"author_id": 14860,
"author_profile": "https://Stackoverflow.com/users/14860",
"pm_score": 3,
"selected": false,
"text": "@echo off\nfor %%f in (*.*) do call :procfile %%f\ngoto :eof\n\n:procfile\n set fname=%1\n set ename=\n:loop1\n if \"%fname%\"==\"\" (\n set ename=\n goto :exit1\n )\n if not \"%fname:~-1%\"==\".\" (\n set ename=%fname:~-1%%ename%\n set fname=%fname:~0,-1%\n goto :loop1\n )\n:exit1\n echo.%ename%\n goto :eof\n"
},
{
"answer_id": 712610,
"author": "system PAUSE",
"author_id": 52963,
"author_profile": "https://Stackoverflow.com/users/52963",
"pm_score": 2,
"selected": false,
"text": "set"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138819",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11234/"
] |
138,839
|
<p>Currently I use .Net <code>WebBrowser.Document.Images()</code> to do this. It requires the <code>Webrowser</code> to load the document. It's messy and takes up resources. </p>
<p>According to <a href="https://stackoverflow.com/questions/138313/how-to-extract-img-src-title-and-alt-from-html-using-php">this question</a> XPath is better than a regex at this. </p>
<p>Anyone know how to do this in C#?</p>
|
[
{
"answer_id": 138863,
"author": "Khoth",
"author_id": 20686,
"author_profile": "https://Stackoverflow.com/users/20686",
"pm_score": -1,
"selected": false,
"text": "XmlDocument doc = new XmlDocument();\ndoc.LoadXml(html);\nXmlNodeList results = doc.SelectNodes(\"//img/@src\");\n"
},
{
"answer_id": 138867,
"author": "rslite",
"author_id": 15682,
"author_profile": "https://Stackoverflow.com/users/15682",
"pm_score": 2,
"selected": false,
"text": "Regex rg = new Regex(@\"<img.*?src=\"\"(.*?)\"\"\", RegexOptions.IgnoreCase);\n"
},
{
"answer_id": 138892,
"author": "mathieu",
"author_id": 971,
"author_profile": "https://Stackoverflow.com/users/971",
"pm_score": 7,
"selected": true,
"text": "public List<Uri> FetchLinksFromSource(string htmlSource)\n{\n List<Uri> links = new List<Uri>();\n string regexImgSrc = @\"<img[^>]*?src\\s*=\\s*[\"\"']?([^'\"\" >]+?)[ '\"\"][^>]*?>\";\n MatchCollection matchesImgSrc = Regex.Matches(htmlSource, regexImgSrc, RegexOptions.IgnoreCase | RegexOptions.Singleline);\n foreach (Match m in matchesImgSrc)\n {\n string href = m.Groups[1].Value;\n links.Add(new Uri(href));\n }\n return links;\n}\n"
},
{
"answer_id": 141711,
"author": "Paul Mrozowski",
"author_id": 3656,
"author_profile": "https://Stackoverflow.com/users/3656",
"pm_score": 4,
"selected": false,
"text": "HtmlDocument doc = new HtmlDocument();\ndoc.Load(@\"C:\\Sample.HTM\");\nHtmlNodeCollection linkNodes = doc.DocumentNode.SelectNodes(\"//a/@href\");\n\nContent match = null;\n\n// Run only if there are links in the document.\nif (linkNodes != null)\n{\n foreach (HtmlNode linkNode in linkNodes)\n {\n HtmlAttribute attrib = linkNode.Attributes[\"href\"];\n // Do whatever else you need here\n }\n}\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138839",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5648/"
] |
138,880
|
<p>Our web site (running Rails) freezes IE6 nearly every time. The same code, deployed on a different server, does not freeze IE6. Where and how should we start tracking this down?</p>
|
[
{
"answer_id": 139101,
"author": "Jim",
"author_id": 8427,
"author_profile": "https://Stackoverflow.com/users/8427",
"pm_score": 3,
"selected": false,
"text": "curl -D first.headers -o first.body http://first.example.com\ncurl -D second.headers -o second.body http://second.example.com\ndiff -u first.headers second.headers\ndiff -u first.body second.body\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138880",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18666/"
] |
138,884
|
<p>I would like to know when I should include external scripts or write them inline with the html code, in terms of performance and ease of maintenance.</p>
<p>What is the general practice for this?</p>
<p>Real-world-scenario - I have several html pages that need client-side form validation. For this I use a jQuery plugin that I include on all these pages. But the question is, do I:</p>
<ul>
<li>write the bits of code that configure this script inline?</li>
<li>include all bits in one file that's share among all these html pages?</li>
<li>include each bit in a separate external file, one for each html page?</li>
</ul>
<p>Thanks.</p>
|
[
{
"answer_id": 138893,
"author": "Konrad Rudolph",
"author_id": 1968,
"author_profile": "https://Stackoverflow.com/users/1968",
"pm_score": 8,
"selected": true,
"text": "<"
},
{
"answer_id": 7012473,
"author": "Miguel Ping",
"author_id": 22992,
"author_profile": "https://Stackoverflow.com/users/22992",
"pm_score": 3,
"selected": false,
"text": "jQuery"
},
{
"answer_id": 26247774,
"author": "Gleno",
"author_id": 427673,
"author_profile": "https://Stackoverflow.com/users/427673",
"pm_score": 5,
"selected": false,
"text": "<head>"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138884",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21613/"
] |
138,917
|
<p>Since I upgraded to Visual Studio 2008 from vs2005, I have found a very annoying behaviour when debugging large projects. If I attempt to step into inline code, the debugger appears to lock up for tens of seconds. Each time that I step inside such a function, there is a similar pause. Has anyone experienced this and is anyone aware of a work around?</p>
<p>Postscript:</p>
<p>After learning that MS had a service pack for vs2008 and needing to get it because of other compiling issues, the problem that I was encountering with the debugger was resolved. </p>
|
[
{
"answer_id": 139523,
"author": "Laur",
"author_id": 7134,
"author_profile": "https://Stackoverflow.com/users/7134",
"pm_score": 0,
"selected": false,
"text": "#ifdef _DEBUG\n #define INLINE\n#else\n #define INLINE inline\n#endif\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138917",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19674/"
] |
138,932
|
<p>In Win32, is there any way to get a unique cpu cycle count or something similar that would be uniform for multiple processes/languages/systems/etc.</p>
<p>I'm creating some log files, but have to produce multiple logfiles because we're hosting the .NET runtime, and I'd like to avoid calling from one to the other to log. As such, I was thinking I'd just produce two files, combine them, and then sort them, to get a coherent timeline involving cross-world calls.</p>
<p>However, GetTickCount does not increase for every call, so that's not reliable. Is there a better number, so that I get the calls in the right order when sorting?</p>
<hr>
<p><strong>Edit</strong>: Thanks to <a href="https://stackoverflow.com/users/893/greg-hewgill">@Greg</a> that put me on the track to QueryPerformanceCounter, which did the trick.</p>
|
[
{
"answer_id": 138963,
"author": "prakash",
"author_id": 123,
"author_profile": "https://Stackoverflow.com/users/123",
"pm_score": 4,
"selected": false,
"text": "timeGetTime()"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138932",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/267/"
] |
138,948
|
<p>I need to get UTF-8 working in my Java webapp (servlets + JSP, no framework used) to support <code>äöå</code> etc. for regular Finnish text and Cyrillic alphabets like <code>ЦжФ</code> for special cases.</p>
<p>My setup is the following:</p>
<ul>
<li>Development environment: Windows XP</li>
<li>Production environment: Debian</li>
</ul>
<p>Database used: MySQL 5.x</p>
<p>Users mainly use Firefox2 but also Opera 9.x, FF3, IE7 and Google Chrome are used to access the site.</p>
<p>How to achieve this?</p>
|
[
{
"answer_id": 138950,
"author": "kosoant",
"author_id": 15114,
"author_profile": "https://Stackoverflow.com/users/15114",
"pm_score": 10,
"selected": true,
"text": "<Connector port=\"8080\" maxHttpHeaderSize=\"8192\"\n maxThreads=\"150\" minSpareThreads=\"25\" maxSpareThreads=\"75\"\n enableLookups=\"false\" redirectPort=\"8443\" acceptCount=\"100\"\n connectionTimeout=\"20000\" disableUploadTimeout=\"true\" \n compression=\"on\" \n compressionMinSize=\"128\" \n noCompressionUserAgents=\"gozilla, traviata\" \n compressableMimeType=\"text/html,text/xml,text/plain,text/css,text/ javascript,application/x-javascript,application/javascript\"\n URIEncoding=\"UTF-8\"\n/>\n"
},
{
"answer_id": 1847079,
"author": "Mike Mountrakis",
"author_id": 224789,
"author_profile": "https://Stackoverflow.com/users/224789",
"pm_score": 1,
"selected": false,
"text": "<connection-url>jdbc:mysql://192.168.10.123:3308/mydatabase</connection-url>\n<driver-class>com.mysql.jdbc.Driver</driver-class>\n<user-name>nts</user-name>\n<password>xaxaxa!</password>\n<connection-property name=\"useUnicode\">true</connection-property>\n<connection-property name=\"characterEncoding\">greek</connection-property>\n"
},
{
"answer_id": 1889473,
"author": "Mike Mountrakis",
"author_id": 229797,
"author_profile": "https://Stackoverflow.com/users/229797",
"pm_score": -1,
"selected": false,
"text": "DriverManager.registerDriver(new com.mysql.jdbc.Driver());\nConnection conn = DriverManager.getConnection(\n \"jdbc:mysql://192.168.1.12:3308/mydb?characterEncoding=greek\",\n \"Myuser\", \"mypass\");\n"
},
{
"answer_id": 2828629,
"author": "John",
"author_id": 340505,
"author_profile": "https://Stackoverflow.com/users/340505",
"pm_score": 2,
"selected": false,
"text": "runtime.encoding=<encoding>\n"
},
{
"answer_id": 6762974,
"author": "caarlos0",
"author_id": 405013,
"author_profile": "https://Stackoverflow.com/users/405013",
"pm_score": 0,
"selected": false,
"text": "convmv --notest -f cp1252 -t utf8 * -r\n"
},
{
"answer_id": 21409344,
"author": "Raedwald",
"author_id": 545127,
"author_profile": "https://Stackoverflow.com/users/545127",
"pm_score": 4,
"selected": false,
"text": "org.springframework.web.filter.CharacterEncodingFilter"
},
{
"answer_id": 41541501,
"author": "Alireza Fattahi",
"author_id": 2648077,
"author_profile": "https://Stackoverflow.com/users/2648077",
"pm_score": 0,
"selected": false,
"text": "CharsetFilter"
},
{
"answer_id": 49864030,
"author": "Rogelio Triviño",
"author_id": 555002,
"author_profile": "https://Stackoverflow.com/users/555002",
"pm_score": 1,
"selected": false,
"text": "JAVA_OPTS=\"$JAVA_OPTS -Dfile.encoding=UTF-8\" \n"
},
{
"answer_id": 54835821,
"author": "Andrei Veshtard",
"author_id": 5917460,
"author_profile": "https://Stackoverflow.com/users/5917460",
"pm_score": 0,
"selected": false,
"text": "@Configuration\n@EnableWebMvc\n@ComponentScan(\"{package.with.components}\")\npublic class WebApplicationContextConfig implements WebMvcConfigurer {\n\n @Bean\n public MessageSource messageSource() {\n final ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();\n\n messageSource.setBasenames(\"messages\");\n messageSource.setDefaultEncoding(\"UTF-8\");\n\n return messageSource;\n }\n\n /* other beans and methods */\n\n}\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138948",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15114/"
] |
138,953
|
<p>When I save a file with an .htm or .html extension, which one is correct and what is different?</p>
|
[
{
"answer_id": 138957,
"author": "William Keller",
"author_id": 17095,
"author_profile": "https://Stackoverflow.com/users/17095",
"pm_score": 7,
"selected": true,
"text": "htm"
},
{
"answer_id": 138960,
"author": "ConroyP",
"author_id": 2287,
"author_profile": "https://Stackoverflow.com/users/2287",
"pm_score": 4,
"selected": false,
"text": "htm"
},
{
"answer_id": 139297,
"author": "Konrad Rudolph",
"author_id": 1968,
"author_profile": "https://Stackoverflow.com/users/1968",
"pm_score": 2,
"selected": false,
"text": "Content-Type"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138953",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21067/"
] |
138,981
|
<p>Is there any way to find out if a file is a directory?</p>
<p>I have the file name in a variable. In Perl I can do this:</p>
<pre><code>if(-d $var) { print "it's a directory\n" }
</code></pre>
|
[
{
"answer_id": 138995,
"author": "David Webb",
"author_id": 3171,
"author_profile": "https://Stackoverflow.com/users/3171",
"pm_score": 7,
"selected": true,
"text": "IF EXIST %VAR%\\NUL ECHO It's a directory\n"
},
{
"answer_id": 138996,
"author": "RomanM",
"author_id": 14587,
"author_profile": "https://Stackoverflow.com/users/14587",
"pm_score": 1,
"selected": false,
"text": "@echo off\nIF EXIST %1\\NUL goto print\nECHO not dir\npause\nexit\n:print\nECHO It's a directory\npause\n"
},
{
"answer_id": 140663,
"author": "pestophagous",
"author_id": 10278,
"author_profile": "https://Stackoverflow.com/users/10278",
"pm_score": 2,
"selected": false,
"text": "D:\\Documents and Settings>if exist \"D:\\Documents and Settings\\NUL\" echo yes"
},
{
"answer_id": 143935,
"author": "indiv",
"author_id": 19719,
"author_profile": "https://Stackoverflow.com/users/19719",
"pm_score": 4,
"selected": false,
"text": "@echo off\nif [%1]==[] goto usage\n\nfor /f \"delims=\" %%i in (\"%~1\") do set MYPATH=\"%%~fi\"\npushd %MYPATH% 2>nul\nif errorlevel 1 goto notdir\ngoto isdir\n\n:notdir\necho not a directory\ngoto exit\n\n:isdir\npopd\necho is a directory\ngoto exit\n\n:usage\necho Usage: %0 DIRECTORY_TO_TEST\n\n:exit\n"
},
{
"answer_id": 1466528,
"author": "Gerard",
"author_id": 3370464,
"author_profile": "https://Stackoverflow.com/users/3370464",
"pm_score": 7,
"selected": false,
"text": "if exist %1\\* echo Directory\n"
},
{
"answer_id": 3663155,
"author": "TechGuy",
"author_id": 441881,
"author_profile": "https://Stackoverflow.com/users/441881",
"pm_score": 0,
"selected": false,
"text": "%%~si\\NUL"
},
{
"answer_id": 3668165,
"author": "Kimae",
"author_id": 442469,
"author_profile": "https://Stackoverflow.com/users/442469",
"pm_score": 2,
"selected": false,
"text": "if not [%1] == [] (\n pushd %~dpn1 2> nul\n if errorlevel == 1 pushd %~dp1\n)\n"
},
{
"answer_id": 3728742,
"author": "batchman61",
"author_id": 449765,
"author_profile": "https://Stackoverflow.com/users/449765",
"pm_score": 6,
"selected": false,
"text": "@echo off\nSETLOCAL ENABLEEXTENSIONS\nset ATTR=%~a1\nset DIRATTR=%ATTR:~0,1%\nif /I \"%DIRATTR%\"==\"d\" echo %1 is a folder\n:EOF\n"
},
{
"answer_id": 3845794,
"author": "Gerard",
"author_id": 3370464,
"author_profile": "https://Stackoverflow.com/users/3370464",
"pm_score": 4,
"selected": false,
"text": "if exist %1\\ echo Directory\n"
},
{
"answer_id": 7567407,
"author": "Aziz",
"author_id": 937064,
"author_profile": "https://Stackoverflow.com/users/937064",
"pm_score": 3,
"selected": false,
"text": "if exist \"%~1\\\" echo Directory\n"
},
{
"answer_id": 11460289,
"author": "gialloporpora",
"author_id": 1207623,
"author_profile": "https://Stackoverflow.com/users/1207623",
"pm_score": 0,
"selected": false,
"text": "```\n@echo off\nset param=%~1\nset tempfile=__temp__.txt\ndir /b/ad > %tempfile%\nset isfolder=false\nfor /f \"delims=\" %%i in (temp.txt) do if /i \"%%i\"==\"%param%\" set isfolder=true\ndel %tempfile%\necho %isfolder%\nif %isfolder%==true echo %param% is a directory\n"
},
{
"answer_id": 11666547,
"author": "Cedric",
"author_id": 1554180,
"author_profile": "https://Stackoverflow.com/users/1554180",
"pm_score": 2,
"selected": false,
"text": "exist"
},
{
"answer_id": 16017962,
"author": "Lucien Baron",
"author_id": 2282964,
"author_profile": "https://Stackoverflow.com/users/2282964",
"pm_score": -1,
"selected": false,
"text": "IF [%~x1] == [] ECHO Directory\n"
},
{
"answer_id": 16985458,
"author": "user966939",
"author_id": 966939,
"author_profile": "https://Stackoverflow.com/users/966939",
"pm_score": 1,
"selected": false,
"text": "REM make sure ERRORLEVEL is 0\nTYPE NUL\n\nREM try to PUSHD into the path (store current dir and switch to another one)\nPUSHD \"insert path here...\" >NUL 2>&1\n\nREM if ERRORLEVEL is still 0, it's most definitely a directory\nIF %ERRORLEVEL% EQU 0 command...\n\nREM if needed/wanted, go back to previous directory\nPOPD\n"
},
{
"answer_id": 27097127,
"author": "Amr Ali",
"author_id": 4208440,
"author_profile": "https://Stackoverflow.com/users/4208440",
"pm_score": 0,
"selected": false,
"text": "@echo off\ncd /d C:\\\nfor /f \"delims=\" %%I in ('dir /a /ogn /b') do (\n call :isdir \"%%I\"\n if errorlevel 1 (echo F: %%~fI) else echo D: %%~fI\n)\ncmd/k\n\n:isdir\necho.%~a1 | findstr /b \"d\" >nul\nexit /b %errorlevel%\n\n:: Errorlevel\n:: 0 = folder\n:: 1 = file or item not found\n"
},
{
"answer_id": 28439918,
"author": "Samuel",
"author_id": 1045004,
"author_profile": "https://Stackoverflow.com/users/1045004",
"pm_score": 2,
"selected": false,
"text": "dir \"%DIR%\" > NUL 2>&1\n\nif not errorlevel 1 (\n echo Directory exists.\n) else (\n echo Directory does not exist.\n)\n"
},
{
"answer_id": 28956749,
"author": "Explorer09",
"author_id": 4606310,
"author_profile": "https://Stackoverflow.com/users/4606310",
"pm_score": 2,
"selected": false,
"text": "&&"
},
{
"answer_id": 33329575,
"author": "Frank N",
"author_id": 444255,
"author_profile": "https://Stackoverflow.com/users/444255",
"pm_score": 2,
"selected": false,
"text": "cd"
},
{
"answer_id": 46326332,
"author": "M. Jamal",
"author_id": 8642578,
"author_profile": "https://Stackoverflow.com/users/8642578",
"pm_score": 1,
"selected": false,
"text": "@pushd %~dp1\n@if not exist \"%~nx1\" (\n popd\n exit /b 0\n) else (\n if exist \"%~nx1\\*\" (\n popd\n exit /b 1\n ) else (\n popd\n exit /b 3\n )\n)\n"
},
{
"answer_id": 51579264,
"author": "Константин Ван",
"author_id": 4510033,
"author_profile": "https://Stackoverflow.com/users/4510033",
"pm_score": 2,
"selected": false,
"text": "CD"
},
{
"answer_id": 59896046,
"author": "Ste",
"author_id": 8262102,
"author_profile": "https://Stackoverflow.com/users/8262102",
"pm_score": 0,
"selected": false,
"text": "CD \\Work\nFOR /D /r %%G in (\"User*\") DO Echo We found\n"
},
{
"answer_id": 67907737,
"author": "k1dfr0std",
"author_id": 9135863,
"author_profile": "https://Stackoverflow.com/users/9135863",
"pm_score": 0,
"selected": false,
"text": "setlocal enableextensions"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138981",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11234/"
] |
138,994
|
<p>I have a procedure with a lot of </p>
<pre><code>i := i +1;
</code></pre>
<p>in it and I think </p>
<pre><code> inc(i);
</code></pre>
<p>looks a lot better. Is there a performance difference or does the function call just get inlined by the compiler? I know this probably doesn't matter at all to my app, I'm just curious.</p>
<p>EDIT: I did some gauging of the performance and found the difference to be very small, in fact as small as 5.1222741794670901427682121946224e-8! So it really doesn't matter. And optimization options really didn't change the outcome much. Thanks for all tips and suggestions!</p>
|
[
{
"answer_id": 139066,
"author": "Ondrej Kelle",
"author_id": 11480,
"author_profile": "https://Stackoverflow.com/users/11480",
"pm_score": 2,
"selected": false,
"text": "Inc(I);"
},
{
"answer_id": 139196,
"author": "PatrickvL",
"author_id": 12170,
"author_profile": "https://Stackoverflow.com/users/12170",
"pm_score": 3,
"selected": false,
"text": "type\n PSomeRecord = ^RSomeRecord;\n RSomeRecord = record\n Value1: Integer;\n Value2: Double;\n end;\n\nvar\n i: PSomeRecord; \n\nprocedure Test;\nbegin\n Inc(i); // This line increases i with SizeOf(RSomeRecord) bytes, thanks to POINTER_MATH !\nend;\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138994",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9077/"
] |
138,999
|
<p>I just started learning JSP technology, and came across a wall.</p>
<p><em>How do you output HTML from a method in <%! ... %> JSP declaration block?</em></p>
<p>This doesn't work:</p>
<pre><code><%!
void someOutput() {
out.println("Some Output");
}
%>
...
<% someOutput(); %>
</code></pre>
<p>Server says there's no “out”.</p>
<p><strong>U:</strong> I do know how to rewrite code with this method returning a string, but is there a way to do this inside <%! void () { } %> ? Though it may be non-optimal, it's still interesting.</p>
|
[
{
"answer_id": 139018,
"author": "Ashley Mercer",
"author_id": 13065,
"author_profile": "https://Stackoverflow.com/users/13065",
"pm_score": 5,
"selected": false,
"text": "<html>\n <head/>\n <body>\n <%!\n String someOutput() {\n return \"Some output\";\n }\n %>\n <% someOutput(); %>\n </body>\n</html>\n"
},
{
"answer_id": 139061,
"author": "paradoja",
"author_id": 18396,
"author_profile": "https://Stackoverflow.com/users/18396",
"pm_score": 4,
"selected": false,
"text": "<%! \n String someOutput() {\n return \"Some Output\";\n }\n%>\n...\n<%= someOutput() %>\n"
},
{
"answer_id": 140674,
"author": "Garth Gilmour",
"author_id": 2635682,
"author_profile": "https://Stackoverflow.com/users/2635682",
"pm_score": 3,
"selected": false,
"text": "void someOutput(JspWriter stream)\n"
},
{
"answer_id": 10996495,
"author": "Dave",
"author_id": 1451197,
"author_profile": "https://Stackoverflow.com/users/1451197",
"pm_score": 4,
"selected": false,
"text": "<%!\nprivate void myFunc(String Bits, javax.servlet.jsp.JspWriter myOut)\n{ \n try{ myOut.println(\"<div>\"+Bits+\"</div>\"); } \n catch(Exception eek) { }\n}\n%>\n...\n<%\n myFunc(\"more difficult than it should be\",out);\n%>\n"
},
{
"answer_id": 17661925,
"author": "hestellezg",
"author_id": 2093371,
"author_profile": "https://Stackoverflow.com/users/2093371",
"pm_score": -1,
"selected": false,
"text": "<%\n\nout.print(\"<p>Hey!</p>\"); \nout.print(\"<p>How are you?</p>\");\n\n%>\n"
},
{
"answer_id": 22159610,
"author": "Martin",
"author_id": 1021426,
"author_profile": "https://Stackoverflow.com/users/1021426",
"pm_score": 2,
"selected": false,
"text": "<%!\nString myMethod(String input) {\n return \"test \" + input;\n}\n%>\n\n<%= myMethod(\"1 2 3\") %>\n"
},
{
"answer_id": 22427128,
"author": "Jer Yango",
"author_id": 1501637,
"author_profile": "https://Stackoverflow.com/users/1501637",
"pm_score": 3,
"selected": false,
"text": "<%!\n String myVariable = \"Test\";\n pageContext.setAttribute(\"myVariable\", myVariable);\n%>\n\n<c:out value=\"myVariable\"/>\n<h1>${myVariable}</h1>\n"
},
{
"answer_id": 32263319,
"author": "Alaa Abuzaghleh",
"author_id": 1345798,
"author_profile": "https://Stackoverflow.com/users/1345798",
"pm_score": 2,
"selected": false,
"text": "<%! \n public void printChild(Categories cat, HttpServletResponse res ){\n try{\n if(cat.getCategoriesSet().size() >0){\n res.getWriter().write(\"\") ; \n }\n }catch(Exception exp){\n\n }\n }\n\n%>\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/138999",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1764/"
] |
139,000
|
<p>I hope someone might be able to help me here. I've tried to simplify my example as best I can.</p>
<p>I have an absolutely positioned DIV, which for this example I've made fill the browser window. This div has the overflow:auto attribute to provide scroll bars when the content is too big for the DIV to display.</p>
<p>Within the DIV I have a table to present some data, and it's width is 100%.</p>
<p>When the content becomes too large vertically, I expect the vertical scroll bar to appear and the table to shrink horizontally slightly to accommodate the scroll bar. However in IE7 what happens is the horizontal scroll bar also appears, despite there still being enough space horizontally for all the content in the div.</p>
<p>This is IE specific - firefox works perfectly.</p>
<p>Full source below. Any help greatly appreciated.</p>
<p>Tony</p>
<pre><code><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Table sizing bug?</title>
<style>
#maxsize
{
position: absolute;
left: 5px;
right: 5px;
top: 5px;
bottom: 5px;
border: 5px solid silver;
overflow: auto;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div id="maxsize">
<p>This will be fine until such time as the vertical size forces a
vertical scroll bar. At this point I'd expect the table to re-size
to now take into account of the new vertical scroll bar. Instead,
IE7 keeps the table the full size and introduces a horizontal
scroll bar.
</p>
<table width="100%" cellspacing="0" cellpadding="0" border="1">
<tbody>
<tr>
<td>A</td>
<td>B</td>
<td>C</td>
<td>D</td>
<td>E</td>
<td>F</td>
<td>G</td>
<td>H</td>
<td>I</td>
<td>J</td>
<td>K</td>
<td>L</td>
<td>M</td>
<td>N</td>
<td>O</td>
<td>P</td>
<td>Q</td>
<td>R</td>
</tr>
</tbody>
</table>
<p>Resize the browser window vertically so this content doesn't
fit any more</p>
<p>Hello</p><p>Hello</p><p>Hello</p><p>Hello</p><p>Hello</p>
<p>Hello</p><p>Hello</p><p>Hello</p><p>Hello</p><p>Hello</p>
</div>
</form>
</body>
</html>
</code></pre>
<hr>
<p><strong>added 03/16/10...</strong> thought it might be interesting to point out that GWT's source code points to this question in a comment... <a href="http://www.google.com/codesearch/p?hl=en#MTQ26449crI/com/google/gwt/user/client/ui/ScrollPanel.java&q=%22hack%20to%20account%20for%20the%22%20scrollpanel&sa=N&cd=1&ct=rc&l=48" rel="noreferrer">http://www.google.com/codesearch/p?hl=en#MTQ26449crI/com/google/gwt/user/client/ui/ScrollPanel.java&q=%22hack%20to%20account%20for%20the%22%20scrollpanel&sa=N&cd=1&ct=rc&l=48</a></p>
|
[
{
"answer_id": 139091,
"author": "Eran Galperin",
"author_id": 10585,
"author_profile": "https://Stackoverflow.com/users/10585",
"pm_score": 3,
"selected": false,
"text": "overflow: auto;\n"
},
{
"answer_id": 474635,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "<!-- zoom: 1 is a proprietary IE property. It doesn't really do anything here, except give hasLayout -->\n\n<div style=\"zoom: 1;\">\n <div style=\"zoom: 1; overflow: auto\">\n <table style=\"width: 100%\"...\n ...\n </table>\n </div>\n</div>\n"
},
{
"answer_id": 879515,
"author": "cetnar",
"author_id": 104796,
"author_profile": "https://Stackoverflow.com/users/104796",
"pm_score": 5,
"selected": false,
"text": "<div style=\"zoom: 1; overflow: auto;\">\n <div id=\"myDiv\" style=\"zoom: 1;\">\n <table style=\"width: 100%\"...\n ...\n </table>\n </div>\n</div>\n"
},
{
"answer_id": 1539977,
"author": "Joel Webber",
"author_id": 186651,
"author_profile": "https://Stackoverflow.com/users/186651",
"pm_score": 3,
"selected": false,
"text": "<div style=\"zoom: 1; overflow: auto;\">\n <div id=\"myDiv\" style=\"zoom: 1;\">\n <table style=\"width: 100%\">\n ...\n </table>\n </div>\n</div>\n"
},
{
"answer_id": 5180060,
"author": "Steve Tchorzewski",
"author_id": 642877,
"author_profile": "https://Stackoverflow.com/users/642877",
"pm_score": 1,
"selected": false,
"text": "html{overflow-x:hidden;}\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139000",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
139,005
|
<p>Dear Stacktoverflow, can you show me an example of how to use a QScrollBar? Thanks.</p>
|
[
{
"answer_id": 139107,
"author": "Torsten Marek",
"author_id": 9567,
"author_profile": "https://Stackoverflow.com/users/9567",
"pm_score": 2,
"selected": false,
"text": ">>> import sys\n>>> from PyQt4 import QtCore, QtGui\n>>> app = QtGui.QApplication(sys.argv)\n>>> sb = QtGui.QScrollBar()\n>>> sb.setMinimum(0)\n>>> sb.setMaximum(100)\n>>> def on_slider_moved(value): print \"new slider position: %i\" % (value, )\n>>> sb.connect(sb, QtCore.SIGNAL(\"sliderMoved(int)\"), on_slider_moved)\n>>> sb.show()\n>>> app.exec_()\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139005",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10710/"
] |
139,010
|
<p>I need to find out the file/directory name that a .lnk is pointing to using c#.</p>
<p>What is the simplest way to do this?</p>
<p>Thanks.</p>
|
[
{
"answer_id": 139032,
"author": "Kev",
"author_id": 419,
"author_profile": "https://Stackoverflow.com/users/419",
"pm_score": 4,
"selected": false,
"text": "IWshRuntimeLibrary.IWshShell shell = new IWshRuntimeLibrary.WshShell();\n\nIWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(link);\n\nConsole.WriteLine(shortcut.TargetPath);\n"
},
{
"answer_id": 220870,
"author": "Sam Saffron",
"author_id": 17174,
"author_profile": "https://Stackoverflow.com/users/17174",
"pm_score": 6,
"selected": false,
"text": "#region Signitures imported from http://pinvoke.net\n\n[DllImport(\"shfolder.dll\", CharSet = CharSet.Auto)]\ninternal static extern int SHGetFolderPath(IntPtr hwndOwner, int nFolder, IntPtr hToken, int dwFlags, StringBuilder lpszPath);\n\n[Flags()]\nenum SLGP_FLAGS\n{\n /// <summary>Retrieves the standard short (8.3 format) file name</summary>\n SLGP_SHORTPATH = 0x1,\n /// <summary>Retrieves the Universal Naming Convention (UNC) path name of the file</summary>\n SLGP_UNCPRIORITY = 0x2,\n /// <summary>Retrieves the raw path name. A raw path is something that might not exist and may include environment variables that need to be expanded</summary>\n SLGP_RAWPATH = 0x4\n}\n\n[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]\nstruct WIN32_FIND_DATAW\n{\n public uint dwFileAttributes;\n public long ftCreationTime;\n public long ftLastAccessTime;\n public long ftLastWriteTime;\n public uint nFileSizeHigh;\n public uint nFileSizeLow;\n public uint dwReserved0;\n public uint dwReserved1;\n [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]\n public string cFileName;\n [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]\n public string cAlternateFileName;\n}\n\n[Flags()]\nenum SLR_FLAGS\n{\n /// <summary>\n /// Do not display a dialog box if the link cannot be resolved. When SLR_NO_UI is set,\n /// the high-order word of fFlags can be set to a time-out value that specifies the\n /// maximum amount of time to be spent resolving the link. The function returns if the\n /// link cannot be resolved within the time-out duration. If the high-order word is set\n /// to zero, the time-out duration will be set to the default value of 3,000 milliseconds\n /// (3 seconds). To specify a value, set the high word of fFlags to the desired time-out\n /// duration, in milliseconds.\n /// </summary>\n SLR_NO_UI = 0x1,\n /// <summary>Obsolete and no longer used</summary>\n SLR_ANY_MATCH = 0x2,\n /// <summary>If the link object has changed, update its path and list of identifiers.\n /// If SLR_UPDATE is set, you do not need to call IPersistFile::IsDirty to determine\n /// whether or not the link object has changed.</summary>\n SLR_UPDATE = 0x4,\n /// <summary>Do not update the link information</summary>\n SLR_NOUPDATE = 0x8,\n /// <summary>Do not execute the search heuristics</summary>\n SLR_NOSEARCH = 0x10,\n /// <summary>Do not use distributed link tracking</summary>\n SLR_NOTRACK = 0x20,\n /// <summary>Disable distributed link tracking. By default, distributed link tracking tracks\n /// removable media across multiple devices based on the volume name. It also uses the\n /// Universal Naming Convention (UNC) path to track remote file systems whose drive letter\n /// has changed. Setting SLR_NOLINKINFO disables both types of tracking.</summary>\n SLR_NOLINKINFO = 0x40,\n /// <summary>Call the Microsoft Windows Installer</summary>\n SLR_INVOKE_MSI = 0x80\n}\n\n\n/// <summary>The IShellLink interface allows Shell links to be created, modified, and resolved</summary>\n[ComImport(), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid(\"000214F9-0000-0000-C000-000000000046\")]\ninterface IShellLinkW\n{\n /// <summary>Retrieves the path and file name of a Shell link object</summary>\n void GetPath([Out(), MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszFile, int cchMaxPath, out WIN32_FIND_DATAW pfd, SLGP_FLAGS fFlags);\n /// <summary>Retrieves the list of item identifiers for a Shell link object</summary>\n void GetIDList(out IntPtr ppidl);\n /// <summary>Sets the pointer to an item identifier list (PIDL) for a Shell link object.</summary>\n void SetIDList(IntPtr pidl);\n /// <summary>Retrieves the description string for a Shell link object</summary>\n void GetDescription([Out(), MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszName, int cchMaxName);\n /// <summary>Sets the description for a Shell link object. The description can be any application-defined string</summary>\n void SetDescription([MarshalAs(UnmanagedType.LPWStr)] string pszName);\n /// <summary>Retrieves the name of the working directory for a Shell link object</summary>\n void GetWorkingDirectory([Out(), MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszDir, int cchMaxPath);\n /// <summary>Sets the name of the working directory for a Shell link object</summary>\n void SetWorkingDirectory([MarshalAs(UnmanagedType.LPWStr)] string pszDir);\n /// <summary>Retrieves the command-line arguments associated with a Shell link object</summary>\n void GetArguments([Out(), MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszArgs, int cchMaxPath);\n /// <summary>Sets the command-line arguments for a Shell link object</summary>\n void SetArguments([MarshalAs(UnmanagedType.LPWStr)] string pszArgs);\n /// <summary>Retrieves the hot key for a Shell link object</summary>\n void GetHotkey(out short pwHotkey);\n /// <summary>Sets a hot key for a Shell link object</summary>\n void SetHotkey(short wHotkey);\n /// <summary>Retrieves the show command for a Shell link object</summary>\n void GetShowCmd(out int piShowCmd);\n /// <summary>Sets the show command for a Shell link object. The show command sets the initial show state of the window.</summary>\n void SetShowCmd(int iShowCmd);\n /// <summary>Retrieves the location (path and index) of the icon for a Shell link object</summary>\n void GetIconLocation([Out(), MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszIconPath,\n int cchIconPath, out int piIcon);\n /// <summary>Sets the location (path and index) of the icon for a Shell link object</summary>\n void SetIconLocation([MarshalAs(UnmanagedType.LPWStr)] string pszIconPath, int iIcon);\n /// <summary>Sets the relative path to the Shell link object</summary>\n void SetRelativePath([MarshalAs(UnmanagedType.LPWStr)] string pszPathRel, int dwReserved);\n /// <summary>Attempts to find the target of a Shell link, even if it has been moved or renamed</summary>\n void Resolve(IntPtr hwnd, SLR_FLAGS fFlags);\n /// <summary>Sets the path and file name of a Shell link object</summary>\n void SetPath([MarshalAs(UnmanagedType.LPWStr)] string pszFile);\n\n}\n\n[ComImport, Guid(\"0000010c-0000-0000-c000-000000000046\"),\nInterfaceType(ComInterfaceType.InterfaceIsIUnknown)]\npublic interface IPersist\n{\n [PreserveSig]\n void GetClassID(out Guid pClassID);\n}\n\n\n[ComImport, Guid(\"0000010b-0000-0000-C000-000000000046\"),\nInterfaceType(ComInterfaceType.InterfaceIsIUnknown)]\npublic interface IPersistFile : IPersist\n{\n new void GetClassID(out Guid pClassID);\n [PreserveSig]\n int IsDirty();\n\n [PreserveSig]\n void Load([In, MarshalAs(UnmanagedType.LPWStr)]\n string pszFileName, uint dwMode);\n\n [PreserveSig]\n void Save([In, MarshalAs(UnmanagedType.LPWStr)] string pszFileName,\n [In, MarshalAs(UnmanagedType.Bool)] bool fRemember);\n\n [PreserveSig]\n void SaveCompleted([In, MarshalAs(UnmanagedType.LPWStr)] string pszFileName);\n\n [PreserveSig]\n void GetCurFile([In, MarshalAs(UnmanagedType.LPWStr)] string ppszFileName);\n}\n\nconst uint STGM_READ = 0;\nconst int MAX_PATH = 260;\n\n// CLSID_ShellLink from ShlGuid.h \n[\n ComImport(),\n Guid(\"00021401-0000-0000-C000-000000000046\")\n]\npublic class ShellLink\n{\n}\n\n#endregion \n\n\npublic static string ResolveShortcut(string filename)\n{\n ShellLink link = new ShellLink();\n ((IPersistFile)link).Load(filename, STGM_READ);\n // TODO: if I can get hold of the hwnd call resolve first. This handles moved and renamed files. \n // ((IShellLinkW)link).Resolve(hwnd, 0) \n StringBuilder sb = new StringBuilder(MAX_PATH);\n WIN32_FIND_DATAW data = new WIN32_FIND_DATAW();\n ((IShellLinkW)link).GetPath(sb, sb.Capacity, out data, 0);\n return sb.ToString(); \n}\n"
},
{
"answer_id": 69596621,
"author": "DMike92",
"author_id": 1056540,
"author_profile": "https://Stackoverflow.com/users/1056540",
"pm_score": -1,
"selected": false,
"text": "mydir"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139010",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
139,012
|
<p>Does anyone know how I can achieve the following effect in OpenGL:</p>
<ul>
<li>Change the brightness of the rendered scene</li>
<li>Or implementing a Gamma setting in OpenGL</li>
</ul>
<p>I have tried by changing the ambient parameter of the light and the type of light (directional and omnidirectional) but the result was not uniform. TIA.</p>
<p>Thanks for your help, some additional information:
* I can't use any windows specifics API.
* The gamma setting should not affect the whole window as I must have different gamma for different views.</p>
|
[
{
"answer_id": 139054,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": true,
"text": "if( brightness > 1 )\n{\n glBlendFunc( GL_DEST_COLOR, GL_ONE );\n glColor3f( brightness-1, brightness-1, brightness-1 );\n}\nelse\n{\n glBlendFunc( GL_ZERO, GL_SRC_COLOR );\n glColor3f( brightness, brightness, brightness );\n}\nglEnable( GL_BLEND );\n\ndraw_quad();\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139012",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18564/"
] |
139,015
|
<p>I have a bunch of PDF files and my Perl program needs to do a full-text search of them to return which ones contain a specific string.
To date I have been using this:</p>
<pre><code>my @search_results = `grep -i -l \"$string\" *.pdf`;
</code></pre>
<p>where $string is the text to look for.
However this fails for most pdf's because the file format is obviously not ASCII.</p>
<p>What can I do that's easiest?</p>
<p>Clarification:
There are about 300 pdf's whose name I do not know in advance. PDF::Core is probably overkill. I am trying to get pdftotext and grep to play nice with each other given I don't know the names of the pdf's, I can't find the right syntax yet.</p>
<p>Final solution using Adam Bellaire's suggestion below:</p>
<pre><code>@search_results = `for i in \$( ls ); do pdftotext \$i - | grep --label="\$i" -i -l "$search_string"; done`;
</code></pre>
|
[
{
"answer_id": 139077,
"author": "Adam Bellaire",
"author_id": 21632,
"author_profile": "https://Stackoverflow.com/users/21632",
"pm_score": 4,
"selected": true,
"text": "my @search_results = `pdftotext myfile.pdf - | grep -i -l \\\"$string\\\"`;\n"
},
{
"answer_id": 151907,
"author": "Chris Dolan",
"author_id": 14783,
"author_profile": "https://Stackoverflow.com/users/14783",
"pm_score": 2,
"selected": false,
"text": "my $doc = CAM::PDF->new($filename) || die \"$CAM::PDF::errstr\\n\";\nfor my $pagenum (1 .. $doc->numPages()) {\n my $text = $doc->getPageText($pagenum);\n print $text;\n}\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139015",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22654/"
] |
139,025
|
<p>I'd like my application to have a full-screen mode. What is the easiest way to do this, do I need a third party library for this or is there something in the JDK that already offers this?</p>
|
[
{
"answer_id": 139068,
"author": "Ken",
"author_id": 20621,
"author_profile": "https://Stackoverflow.com/users/20621",
"pm_score": 2,
"selected": false,
"text": "setUndecorated(true)"
},
{
"answer_id": 10064657,
"author": "iptq",
"author_id": 1572906,
"author_profile": "https://Stackoverflow.com/users/1572906",
"pm_score": 2,
"selected": false,
"text": "JFrame frame = new JFrame();\n// set properties\nframe.setSize(Toolkit.getDefaultToolkit().getScreenSize());\nframe.setUndecorated(true);\nframe.setVisible(true);\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139025",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6583/"
] |
139,046
|
<p>I need to write code that picks up PGP-encrypted files from an FTP location and processes them. The files will be encrypted with my public key (not that I have one yet). Obviously, I need a PGP library that I can use from within Microsoft Access. Can you recommend one that is easy to use? </p>
<p>I'm looking for something that doesn't require a huge amount of PKI knowledge. Ideally, something that will easily generate the one-off private/public key pair, and then have a simple routine for decryption.</p>
|
[
{
"answer_id": 139147,
"author": "Bob Probst",
"author_id": 12424,
"author_profile": "https://Stackoverflow.com/users/12424",
"pm_score": 2,
"selected": false,
"text": "\"C:\\Program Files\\Network Associates\\PGPNT\\pgp\" +FORCE %1 -z *password* \n"
},
{
"answer_id": 139500,
"author": "hurcane",
"author_id": 21363,
"author_profile": "https://Stackoverflow.com/users/21363",
"pm_score": 4,
"selected": true,
"text": "Public Sub DecryptFile(ByVal FileName As String)\n Dim strCommand As String\n strCommand = \"C:\\Program Files\\GNU\\GnuPG\\gpg.exe \" _\n & \"--batch --passphrase \"\"My PassPhrase that I used\"\"\" & FileName\n Shell strCommand, vbNormalFocus\nEnd Sub\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139046",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21379/"
] |
139,053
|
<p>I have written an assembly I don't want other people to be able to use. My assembly is signed with a strong name key file, but how do I secure the code so that only my other assemblies signed with the same key can call the members in this assembly?</p>
|
[
{
"answer_id": 139087,
"author": "Richard",
"author_id": 20038,
"author_profile": "https://Stackoverflow.com/users/20038",
"pm_score": 2,
"selected": false,
"text": "[assembly:StrongNameIdentityPermissionAttribute(SecurityAction.RequestMinimum, \n PublicKey=\"00240000048000009400000006020000002400005253413100040000010001005\" +\n \"38a4a19382e9429cf516dcf1399facdccca092a06442efaf9ecaca33457be26ee0073c6bde5\" +\n \"1fe0873666a62459581669b510ae1e84bef6bcb1aff7957237279d8b7e0e25b71ad39df3684\" +\n \"5b7db60382c8eb73f289823578d33c09e48d0d2f90ed4541e1438008142ef714bfe604c41a4\" +\n \"957a4f6e6ab36b9715ec57625904c6\")]\n"
},
{
"answer_id": 139105,
"author": "ckramer",
"author_id": 20504,
"author_profile": "https://Stackoverflow.com/users/20504",
"pm_score": 1,
"selected": false,
"text": "[assembly: InternalsVisibleTo('MyAssembly,Version=1.0.0.1, Culture=neutral,PublicKeyToken=...\");\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139053",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3139/"
] |
139,055
|
<p>I'm using Subversive plugin in Ganymede, but after today's update it stopped working - it just doesn't see any valid svn connectors (I've already been using 1.2.0 dev version of SVNKit, instead of a stable one, because Subversive / Ganymede could not handle it; now it can't handle even the dev one). Any ideas how to make it work? Are subversive guys releasing a new version of their plugin / connectors soon?</p>
|
[
{
"answer_id": 143379,
"author": "rjray",
"author_id": 6421,
"author_profile": "https://Stackoverflow.com/users/6421",
"pm_score": 4,
"selected": true,
"text": "http://www.polarion.org/projects/subversive/download/eclipse/2.0/update-site/\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139055",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4688/"
] |
139,076
|
<p>I have a Java String that contains XML, with no line feeds or indentations. I would like to turn it into a String with nicely formatted XML. How do I do this?</p>
<pre><code>String unformattedXml = "<tag><nested>hello</nested></tag>";
String formattedXml = new [UnknownClass]().format(unformattedXml);
</code></pre>
<p>Note: My input is a <strong>String</strong>. My output is a <strong>String</strong>. </p>
<p>(Basic) mock result:</p>
<pre><code><?xml version="1.0" encoding="UTF-8"?>
<root>
<tag>
<nested>hello</nested>
</tag>
</root>
</code></pre>
|
[
{
"answer_id": 139096,
"author": "Lorenzo Boccaccia",
"author_id": 2273540,
"author_profile": "https://Stackoverflow.com/users/2273540",
"pm_score": 8,
"selected": false,
"text": "Transformer transformer = TransformerFactory.newInstance().newTransformer();\ntransformer.setOutputProperty(OutputKeys.INDENT, \"yes\");\ntransformer.setOutputProperty(\"{http://xml.apache.org/xslt}indent-amount\", \"2\");\n// initialize StreamResult with File object to save to file\nStreamResult result = new StreamResult(new StringWriter());\nDOMSource source = new DOMSource(doc);\ntransformer.transform(source, result);\nString xmlString = result.getWriter().toString();\nSystem.out.println(xmlString);\n"
},
{
"answer_id": 139333,
"author": "Kevin Hakanson",
"author_id": 22514,
"author_profile": "https://Stackoverflow.com/users/22514",
"pm_score": 4,
"selected": false,
"text": "String"
},
{
"answer_id": 139426,
"author": "Steve McLeod",
"author_id": 2959,
"author_profile": "https://Stackoverflow.com/users/2959",
"pm_score": 7,
"selected": false,
"text": "package ecb.sdw.pretty;\n\nimport org.apache.xml.serialize.OutputFormat;\nimport org.apache.xml.serialize.XMLSerializer;\nimport org.w3c.dom.Document;\nimport org.xml.sax.InputSource;\nimport org.xml.sax.SAXException;\n\nimport javax.xml.parsers.DocumentBuilder;\nimport javax.xml.parsers.DocumentBuilderFactory;\nimport javax.xml.parsers.ParserConfigurationException;\nimport java.io.IOException;\nimport java.io.StringReader;\nimport java.io.StringWriter;\nimport java.io.Writer;\n\n/**\n * Pretty-prints xml, supplied as a string.\n * <p/>\n * eg.\n * <code>\n * String formattedXml = new XmlFormatter().format(\"<tag><nested>hello</nested></tag>\");\n * </code>\n */\npublic class XmlFormatter {\n\n public XmlFormatter() {\n }\n\n public String format(String unformattedXml) {\n try {\n final Document document = parseXmlFile(unformattedXml);\n\n OutputFormat format = new OutputFormat(document);\n format.setLineWidth(65);\n format.setIndenting(true);\n format.setIndent(2);\n Writer out = new StringWriter();\n XMLSerializer serializer = new XMLSerializer(out, format);\n serializer.serialize(document);\n\n return out.toString();\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n\n private Document parseXmlFile(String in) {\n try {\n DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();\n DocumentBuilder db = dbf.newDocumentBuilder();\n InputSource is = new InputSource(new StringReader(in));\n return db.parse(is);\n } catch (ParserConfigurationException e) {\n throw new RuntimeException(e);\n } catch (SAXException e) {\n throw new RuntimeException(e);\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n\n public static void main(String[] args) {\n String unformattedXml =\n \"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?><QueryMessage\\n\" +\n \" xmlns=\\\"http://www.SDMX.org/resources/SDMXML/schemas/v2_0/message\\\"\\n\" +\n \" xmlns:query=\\\"http://www.SDMX.org/resources/SDMXML/schemas/v2_0/query\\\">\\n\" +\n \" <Query>\\n\" +\n \" <query:CategorySchemeWhere>\\n\" +\n \" \\t\\t\\t\\t\\t <query:AgencyID>ECB\\n\\n\\n\\n</query:AgencyID>\\n\" +\n \" </query:CategorySchemeWhere>\\n\" +\n \" </Query>\\n\\n\\n\\n\\n\" +\n \"</QueryMessage>\";\n\n System.out.println(new XmlFormatter().format(unformattedXml));\n }\n\n}\n"
},
{
"answer_id": 260314,
"author": "mlo55",
"author_id": 32993,
"author_profile": "https://Stackoverflow.com/users/32993",
"pm_score": 5,
"selected": false,
"text": "public String prettyPrint(final String xml){ \n\n if (StringUtils.isBlank(xml)) {\n throw new RuntimeException(\"xml was null or blank in prettyPrint()\");\n }\n\n final StringWriter sw;\n\n try {\n final OutputFormat format = OutputFormat.createPrettyPrint();\n final org.dom4j.Document document = DocumentHelper.parseText(xml);\n sw = new StringWriter();\n final XMLWriter writer = new XMLWriter(sw, format);\n writer.write(document);\n }\n catch (Exception e) {\n throw new RuntimeException(\"Error pretty printing xml:\\n\" + xml, e);\n }\n return sw.toString();\n}\n"
},
{
"answer_id": 962225,
"author": "Jonik",
"author_id": 56285,
"author_profile": "https://Stackoverflow.com/users/56285",
"pm_score": 4,
"selected": false,
"text": "import nu.xom.*;\nimport java.io.*;\n\n[...]\n\npublic static String format(String xml) throws ParsingException, IOException {\n ByteArrayOutputStream out = new ByteArrayOutputStream();\n Serializer serializer = new Serializer(out);\n serializer.setIndent(4); // or whatever you like\n serializer.write(new Builder().build(xml, \"\"));\n return out.toString(\"UTF-8\");\n}\n"
},
{
"answer_id": 1264912,
"author": "dfa",
"author_id": 89266,
"author_profile": "https://Stackoverflow.com/users/89266",
"pm_score": 7,
"selected": false,
"text": "public static String prettyFormat(String input, int indent) {\n try {\n Source xmlInput = new StreamSource(new StringReader(input));\n StringWriter stringWriter = new StringWriter();\n StreamResult xmlOutput = new StreamResult(stringWriter);\n TransformerFactory transformerFactory = TransformerFactory.newInstance();\n transformerFactory.setAttribute(\"indent-number\", indent);\n transformerFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, \"\");\n transformerFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, \"\");\n Transformer transformer = transformerFactory.newTransformer(); \n transformer.setOutputProperty(OutputKeys.INDENT, \"yes\");\n transformer.transform(xmlInput, xmlOutput);\n return xmlOutput.getWriter().toString();\n } catch (Exception e) {\n throw new RuntimeException(e); // simple exception handling, please review it\n }\n}\n\npublic static String prettyFormat(String input) {\n return prettyFormat(input, 2);\n}\n"
},
{
"answer_id": 1948577,
"author": "Sandeep Phukan",
"author_id": 237114,
"author_profile": "https://Stackoverflow.com/users/237114",
"pm_score": 4,
"selected": false,
"text": "transformer.setOutputProperty(OutputPropertiesFactory.S_KEY_INDENT_AMOUNT, \"8\");\n"
},
{
"answer_id": 2599074,
"author": "Mark Pope",
"author_id": 237733,
"author_profile": "https://Stackoverflow.com/users/237733",
"pm_score": 4,
"selected": false,
"text": "import org.dom4j.Document; \nimport org.dom4j.DocumentHelper; \nimport org.dom4j.io.OutputFormat; \nimport org.dom4j.io.XMLWriter;\n"
},
{
"answer_id": 2920419,
"author": "David Easley",
"author_id": 65555,
"author_profile": "https://Stackoverflow.com/users/65555",
"pm_score": 4,
"selected": false,
"text": "/**\n * XML utils, including formatting.\n */\npublic class XmlUtils\n{\n private static XmlFormatter formatter = new XmlFormatter(2, 80);\n\n public static String formatXml(String s)\n {\n return formatter.format(s, 0);\n }\n\n public static String formatXml(String s, int initialIndent)\n {\n return formatter.format(s, initialIndent);\n }\n\n private static class XmlFormatter\n {\n private int indentNumChars;\n private int lineLength;\n private boolean singleLine;\n\n public XmlFormatter(int indentNumChars, int lineLength)\n {\n this.indentNumChars = indentNumChars;\n this.lineLength = lineLength;\n }\n\n public synchronized String format(String s, int initialIndent)\n {\n int indent = initialIndent;\n StringBuilder sb = new StringBuilder();\n for (int i = 0; i < s.length(); i++)\n {\n char currentChar = s.charAt(i);\n if (currentChar == '<')\n {\n char nextChar = s.charAt(i + 1);\n if (nextChar == '/')\n indent -= indentNumChars;\n if (!singleLine) // Don't indent before closing element if we're creating opening and closing elements on a single line.\n sb.append(buildWhitespace(indent));\n if (nextChar != '?' && nextChar != '!' && nextChar != '/')\n indent += indentNumChars;\n singleLine = false; // Reset flag.\n }\n sb.append(currentChar);\n if (currentChar == '>')\n {\n if (s.charAt(i - 1) == '/')\n {\n indent -= indentNumChars;\n sb.append(\"\\n\");\n }\n else\n {\n int nextStartElementPos = s.indexOf('<', i);\n if (nextStartElementPos > i + 1)\n {\n String textBetweenElements = s.substring(i + 1, nextStartElementPos);\n\n // If the space between elements is solely newlines, let them through to preserve additional newlines in source document.\n if (textBetweenElements.replaceAll(\"\\n\", \"\").length() == 0)\n {\n sb.append(textBetweenElements + \"\\n\");\n }\n // Put tags and text on a single line if the text is short.\n else if (textBetweenElements.length() <= lineLength * 0.5)\n {\n sb.append(textBetweenElements);\n singleLine = true;\n }\n // For larger amounts of text, wrap lines to a maximum line length.\n else\n {\n sb.append(\"\\n\" + lineWrap(textBetweenElements, lineLength, indent, null) + \"\\n\");\n }\n i = nextStartElementPos - 1;\n }\n else\n {\n sb.append(\"\\n\");\n }\n }\n }\n }\n return sb.toString();\n }\n }\n\n private static String buildWhitespace(int numChars)\n {\n StringBuilder sb = new StringBuilder();\n for (int i = 0; i < numChars; i++)\n sb.append(\" \");\n return sb.toString();\n }\n\n /**\n * Wraps the supplied text to the specified line length.\n * @lineLength the maximum length of each line in the returned string (not including indent if specified).\n * @indent optional number of whitespace characters to prepend to each line before the text.\n * @linePrefix optional string to append to the indent (before the text).\n * @returns the supplied text wrapped so that no line exceeds the specified line length + indent, optionally with\n * indent and prefix applied to each line.\n */\n private static String lineWrap(String s, int lineLength, Integer indent, String linePrefix)\n {\n if (s == null)\n return null;\n\n StringBuilder sb = new StringBuilder();\n int lineStartPos = 0;\n int lineEndPos;\n boolean firstLine = true;\n while(lineStartPos < s.length())\n {\n if (!firstLine)\n sb.append(\"\\n\");\n else\n firstLine = false;\n\n if (lineStartPos + lineLength > s.length())\n lineEndPos = s.length() - 1;\n else\n {\n lineEndPos = lineStartPos + lineLength - 1;\n while (lineEndPos > lineStartPos && (s.charAt(lineEndPos) != ' ' && s.charAt(lineEndPos) != '\\t'))\n lineEndPos--;\n }\n sb.append(buildWhitespace(indent));\n if (linePrefix != null)\n sb.append(linePrefix);\n\n sb.append(s.substring(lineStartPos, lineEndPos + 1));\n lineStartPos = lineEndPos + 1;\n }\n return sb.toString();\n }\n\n // other utils removed for brevity\n}\n"
},
{
"answer_id": 3026021,
"author": "Kristoffer Lindvall",
"author_id": 299075,
"author_profile": "https://Stackoverflow.com/users/299075",
"pm_score": 2,
"selected": false,
"text": "Tidy t = new Tidy();\nt.setIndentContent(true);\nDocument d = t.parseDOM(\n new ByteArrayInputStream(\"HTML goes here\", null);\n\nOutputStream out = new ByteArrayOutputStream();\nt.pprint(d, out);\nString html = out.toString();\n"
},
{
"answer_id": 4472580,
"author": "khylo",
"author_id": 249672,
"author_profile": "https://Stackoverflow.com/users/249672",
"pm_score": 6,
"selected": false,
"text": "package com.test;\n\nimport java.io.ByteArrayInputStream;\nimport java.io.ByteArrayOutputStream;\n\nimport javax.xml.transform.OutputKeys;\nimport javax.xml.transform.Source;\nimport javax.xml.transform.Transformer;\nimport javax.xml.transform.sax.SAXSource;\nimport javax.xml.transform.sax.SAXTransformerFactory;\nimport javax.xml.transform.stream.StreamResult;\n\nimport org.xml.sax.InputSource;\n\npublic class XmlTest {\n public static void main(String[] args) {\n XmlTest t = new XmlTest();\n System.out.println(t.formatXml(\"<a><b><c/><d>text D</d><e value='0'/></b></a>\"));\n }\n\n public String formatXml(String xml){\n try{\n Transformer serializer= SAXTransformerFactory.newInstance().newTransformer();\n serializer.setOutputProperty(OutputKeys.INDENT, \"yes\");\n //serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, \"yes\");\n serializer.setOutputProperty(\"{http://xml.apache.org/xslt}indent-amount\", \"2\");\n //serializer.setOutputProperty(\"{http://xml.customer.org/xslt}indent-amount\", \"2\");\n Source xmlSource=new SAXSource(new InputSource(new ByteArrayInputStream(xml.getBytes())));\n StreamResult res = new StreamResult(new ByteArrayOutputStream()); \n serializer.transform(xmlSource, res);\n return new String(((ByteArrayOutputStream)res.getOutputStream()).toByteArray());\n }catch(Exception e){\n //TODO log error\n return xml;\n }\n }\n\n}\n"
},
{
"answer_id": 5227490,
"author": "Synesso",
"author_id": 45525,
"author_profile": "https://Stackoverflow.com/users/45525",
"pm_score": 3,
"selected": false,
"text": "import xml._\nval xml = XML.loadString(\"<tag><nested>hello</nested></tag>\")\nval formatted = new PrettyPrinter(150, 2).format(xml)\nprintln(formatted)\n"
},
{
"answer_id": 7714473,
"author": "Michael",
"author_id": 13379,
"author_profile": "https://Stackoverflow.com/users/13379",
"pm_score": 3,
"selected": false,
"text": "DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();\nDOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation(\"LS\");\nLSSerializer writer = impl.createLSSerializer();\nwriter.getDomConfig().setParameter(\"format-pretty-print\", Boolean.TRUE);\nLSOutput output = impl.createLSOutput();\nByteArrayOutputStream out = new ByteArrayOutputStream();\noutput.setByteStream(out);\nwriter.write(document, output);\nString xmlStr = new String(out.toByteArray());\n"
},
{
"answer_id": 11351356,
"author": "JFK",
"author_id": 851774,
"author_profile": "https://Stackoverflow.com/users/851774",
"pm_score": 1,
"selected": false,
"text": "<xsl:strip-space elements=\"*\"/>"
},
{
"answer_id": 11519668,
"author": "Steve McLeod",
"author_id": 2959,
"author_profile": "https://Stackoverflow.com/users/2959",
"pm_score": 8,
"selected": true,
"text": "import org.w3c.dom.Node;\nimport org.w3c.dom.bootstrap.DOMImplementationRegistry;\nimport org.w3c.dom.ls.DOMImplementationLS;\nimport org.w3c.dom.ls.LSSerializer;\nimport org.xml.sax.InputSource;\n\nimport javax.xml.parsers.DocumentBuilderFactory;\nimport java.io.StringReader;\n\n/**\n * Pretty-prints xml, supplied as a string.\n * <p/>\n * eg.\n * <code>\n * String formattedXml = new XmlFormatter().format(\"<tag><nested>hello</nested></tag>\");\n * </code>\n */\npublic class XmlFormatter {\n\n public String format(String xml) {\n\n try {\n final InputSource src = new InputSource(new StringReader(xml));\n final Node document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(src).getDocumentElement();\n final Boolean keepDeclaration = Boolean.valueOf(xml.startsWith(\"<?xml\"));\n\n //May need this: System.setProperty(DOMImplementationRegistry.PROPERTY,\"com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl\");\n\n\n final DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();\n final DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation(\"LS\");\n final LSSerializer writer = impl.createLSSerializer();\n\n writer.getDomConfig().setParameter(\"format-pretty-print\", Boolean.TRUE); // Set this to true if the output needs to be beautified.\n writer.getDomConfig().setParameter(\"xml-declaration\", keepDeclaration); // Set this to true if the declaration is needed to be outputted.\n\n return writer.writeToString(document);\n } catch (Exception e) {\n throw new RuntimeException(e);\n }\n }\n\n public static void main(String[] args) {\n String unformattedXml =\n \"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?><QueryMessage\\n\" +\n \" xmlns=\\\"http://www.SDMX.org/resources/SDMXML/schemas/v2_0/message\\\"\\n\" +\n \" xmlns:query=\\\"http://www.SDMX.org/resources/SDMXML/schemas/v2_0/query\\\">\\n\" +\n \" <Query>\\n\" +\n \" <query:CategorySchemeWhere>\\n\" +\n \" \\t\\t\\t\\t\\t <query:AgencyID>ECB\\n\\n\\n\\n</query:AgencyID>\\n\" +\n \" </query:CategorySchemeWhere>\\n\" +\n \" </Query>\\n\\n\\n\\n\\n\" +\n \"</QueryMessage>\";\n\n System.out.println(new XmlFormatter().format(unformattedXml));\n }\n}\n"
},
{
"answer_id": 19236572,
"author": "max",
"author_id": 767434,
"author_profile": "https://Stackoverflow.com/users/767434",
"pm_score": 2,
"selected": false,
"text": "public static String prettyPrintXMLAsString(String xmlString) {\n /* Remove new lines */\n final String LINE_BREAK = \"\\n\";\n xmlString = xmlString.replaceAll(LINE_BREAK, \"\");\n StringBuffer prettyPrintXml = new StringBuffer();\n /* Group the xml tags */\n Pattern pattern = Pattern.compile(\"(<[^/][^>]+>)?([^<]*)(</[^>]+>)?(<[^/][^>]+/>)?\");\n Matcher matcher = pattern.matcher(xmlString);\n int tabCount = 0;\n while (matcher.find()) {\n String str1 = (null == matcher.group(1) || \"null\".equals(matcher.group())) ? \"\" : matcher.group(1);\n String str2 = (null == matcher.group(2) || \"null\".equals(matcher.group())) ? \"\" : matcher.group(2);\n String str3 = (null == matcher.group(3) || \"null\".equals(matcher.group())) ? \"\" : matcher.group(3);\n String str4 = (null == matcher.group(4) || \"null\".equals(matcher.group())) ? \"\" : matcher.group(4);\n\n if (matcher.group() != null && !matcher.group().trim().equals(\"\")) {\n printTabs(tabCount, prettyPrintXml);\n if (!str1.equals(\"\") && str3.equals(\"\")) {\n ++tabCount;\n }\n if (str1.equals(\"\") && !str3.equals(\"\")) {\n --tabCount;\n prettyPrintXml.deleteCharAt(prettyPrintXml.length() - 1);\n }\n\n prettyPrintXml.append(str1);\n prettyPrintXml.append(str2);\n prettyPrintXml.append(str3);\n if (!str4.equals(\"\")) {\n prettyPrintXml.append(LINE_BREAK);\n printTabs(tabCount, prettyPrintXml);\n prettyPrintXml.append(str4);\n }\n prettyPrintXml.append(LINE_BREAK);\n }\n }\n return prettyPrintXml.toString();\n}\n\nprivate static void printTabs(int count, StringBuffer stringBuffer) {\n for (int i = 0; i < count; i++) {\n stringBuffer.append(\"\\t\");\n }\n}\n\npublic static void main(String[] args) {\n String x = new String(\n \"<soap:Envelope xmlns:soap=\\\"http://schemas.xmlsoap.org/soap/envelope/\\\"><soap:Body><soap:Fault><faultcode>soap:Client</faultcode><faultstring>INVALID_MESSAGE</faultstring><detail><ns3:XcbSoapFault xmlns=\\\"\\\" xmlns:ns3=\\\"http://www.someapp.eu/xcb/types/xcb/v1\\\"><CauseCode>20007</CauseCode><CauseText>INVALID_MESSAGE</CauseText><DebugInfo>Problems creating SAAJ object model</DebugInfo></ns3:XcbSoapFault></detail></soap:Fault></soap:Body></soap:Envelope>\");\n System.out.println(prettyPrintXMLAsString(x));\n}\n"
},
{
"answer_id": 21736245,
"author": "milosmns",
"author_id": 2102748,
"author_profile": "https://Stackoverflow.com/users/2102748",
"pm_score": 3,
"selected": false,
"text": "public String prettyPrint(String xml) {\n if (xml == null || xml.trim().length() == 0) return \"\";\n\n int stack = 0;\n StringBuilder pretty = new StringBuilder();\n String[] rows = xml.trim().replaceAll(\">\", \">\\n\").replaceAll(\"<\", \"\\n<\").split(\"\\n\");\n\n for (int i = 0; i < rows.length; i++) {\n if (rows[i] == null || rows[i].trim().length() == 0) continue;\n\n String row = rows[i].trim();\n if (row.startsWith(\"<?\")) {\n // xml version tag\n pretty.append(row + \"\\n\");\n } else if (row.startsWith(\"</\")) {\n // closing tag\n String indent = repeatString(\" \", --stack);\n pretty.append(indent + row + \"\\n\");\n } else if (row.startsWith(\"<\")) {\n // starting tag\n String indent = repeatString(\" \", stack++);\n pretty.append(indent + row + \"\\n\");\n } else {\n // tag data\n String indent = repeatString(\" \", stack);\n pretty.append(indent + row + \"\\n\");\n }\n }\n\n return pretty.toString().trim();\n }\n"
},
{
"answer_id": 24650999,
"author": "codeskraps",
"author_id": 619587,
"author_profile": "https://Stackoverflow.com/users/619587",
"pm_score": 3,
"selected": false,
"text": "public static String getPrettyXml(String xml) {\n if (xml == null || xml.trim().length() == 0) return \"\";\n\n int stack = 0;\n StringBuilder pretty = new StringBuilder();\n String[] rows = xml.trim().replaceAll(\">\", \">\\n\").replaceAll(\"<\", \"\\n<\").split(\"\\n\");\n\n for (int i = 0; i < rows.length; i++) {\n if (rows[i] == null || rows[i].trim().length() == 0) continue;\n\n String row = rows[i].trim();\n if (row.startsWith(\"<?\")) {\n pretty.append(row + \"\\n\");\n } else if (row.startsWith(\"</\")) {\n String indent = repeatString(--stack);\n pretty.append(indent + row + \"\\n\");\n } else if (row.startsWith(\"<\") && row.endsWith(\"/>\") == false) {\n String indent = repeatString(stack++);\n pretty.append(indent + row + \"\\n\");\n if (row.endsWith(\"]]>\")) stack--;\n } else {\n String indent = repeatString(stack);\n pretty.append(indent + row + \"\\n\");\n }\n }\n\n return pretty.toString().trim();\n}\n\nprivate static String repeatString(int stack) {\n StringBuilder indent = new StringBuilder();\n for (int i = 0; i < stack; i++) {\n indent.append(\" \");\n }\n return indent.toString();\n} \n"
},
{
"answer_id": 26361221,
"author": "Wojtek",
"author_id": 2685402,
"author_profile": "https://Stackoverflow.com/users/2685402",
"pm_score": 1,
"selected": false,
"text": "import org.apache.xml.security.c14n.CanonicalizationException;\nimport org.apache.xml.security.c14n.Canonicalizer;\nimport org.apache.xml.security.c14n.InvalidCanonicalizerException;\nimport org.w3c.dom.Element;\nimport org.w3c.dom.bootstrap.DOMImplementationRegistry;\nimport org.w3c.dom.ls.DOMImplementationLS;\nimport org.w3c.dom.ls.LSSerializer;\nimport org.xml.sax.InputSource;\nimport org.xml.sax.SAXException;\n\nimport javax.xml.parsers.DocumentBuilderFactory;\nimport javax.xml.parsers.ParserConfigurationException;\nimport javax.xml.transform.TransformerException;\nimport java.io.IOException;\nimport java.io.StringReader;\n\npublic class XmlUtils {\n public static String toCanonicalXml(String xml) throws InvalidCanonicalizerException, ParserConfigurationException, SAXException, CanonicalizationException, IOException {\n Canonicalizer canon = Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS);\n byte canonXmlBytes[] = canon.canonicalize(xml.getBytes());\n return new String(canonXmlBytes);\n }\n\n public static String prettyFormat(String input) throws TransformerException, ParserConfigurationException, IOException, SAXException, InstantiationException, IllegalAccessException, ClassNotFoundException {\n InputSource src = new InputSource(new StringReader(input));\n Element document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(src).getDocumentElement();\n Boolean keepDeclaration = input.startsWith(\"<?xml\");\n DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();\n DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation(\"LS\");\n LSSerializer writer = impl.createLSSerializer();\n writer.getDomConfig().setParameter(\"format-pretty-print\", Boolean.TRUE);\n writer.getDomConfig().setParameter(\"xml-declaration\", keepDeclaration);\n return writer.writeToString(document);\n }\n}\n"
},
{
"answer_id": 27681201,
"author": "ThomasRS",
"author_id": 459579,
"author_profile": "https://Stackoverflow.com/users/459579",
"pm_score": 2,
"selected": false,
"text": "// construct lightweight, threadsafe, instance\nPrettyPrinter prettyPrinter = PrettyPrinterBuilder.newPrettyPrinter().build();\n\nStringBuilder buffer = new StringBuilder();\nString xml = ..; // also works with char[] or Reader\n\nif(prettyPrinter.process(xml, buffer)) {\n // valid XML, print buffer\n} else {\n // invalid XML, print xml\n}\n"
},
{
"answer_id": 29994838,
"author": "vsnyc",
"author_id": 2063026,
"author_profile": "https://Stackoverflow.com/users/2063026",
"pm_score": 1,
"selected": false,
"text": "Scala"
},
{
"answer_id": 30171112,
"author": "BijanE",
"author_id": 2339693,
"author_profile": "https://Stackoverflow.com/users/2339693",
"pm_score": 2,
"selected": false,
"text": "import java.io.StringReader;\nimport org.jdom2.input.SAXBuilder;\nimport org.jdom2.output.Format;\nimport org.jdom2.output.XMLOutputter;\n\nString prettyXml = new XMLOutputter(Format.getPrettyFormat()).\n outputString(new SAXBuilder().build(new StringReader(uglyXml)));\n"
},
{
"answer_id": 30213453,
"author": "Georgy Gobozov",
"author_id": 423868,
"author_profile": "https://Stackoverflow.com/users/423868",
"pm_score": 3,
"selected": false,
"text": " String xml = \"<root>\" +\n \"\\n \" +\n \"\\n<name>Coco Puff</name>\" +\n \"\\n <total>10</total> </root>\";\n\ntry {\n Document document = DocumentBuilderFactory.newInstance()\n .newDocumentBuilder()\n .parse(new InputSource(new ByteArrayInputStream(xml.getBytes(\"utf-8\"))));\n\n XPath xPath = XPathFactory.newInstance().newXPath();\n NodeList nodeList = (NodeList) xPath.evaluate(\"//text()[normalize-space()='']\",\n document,\n XPathConstants.NODESET);\n\n for (int i = 0; i < nodeList.getLength(); ++i) {\n Node node = nodeList.item(i);\n node.getParentNode().removeChild(node);\n }\n\n Transformer transformer = TransformerFactory.newInstance().newTransformer();\n transformer.setOutputProperty(OutputKeys.ENCODING, \"UTF-8\");\n transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, \"yes\");\n transformer.setOutputProperty(OutputKeys.INDENT, \"yes\");\n transformer.setOutputProperty(\"{http://xml.apache.org/xslt}indent-amount\", \"4\");\n\n StringWriter stringWriter = new StringWriter();\n StreamResult streamResult = new StreamResult(stringWriter);\n\n transformer.transform(new DOMSource(document), streamResult);\n\n System.out.println(stringWriter.toString());\n}\ncatch (Exception e) {\n e.printStackTrace();\n}\n"
},
{
"answer_id": 31571512,
"author": "Anand",
"author_id": 1343090,
"author_profile": "https://Stackoverflow.com/users/1343090",
"pm_score": 3,
"selected": false,
"text": "import java.io.StringWriter;\nimport org.dom4j.DocumentHelper;\nimport org.dom4j.io.OutputFormat;\nimport org.dom4j.io.XMLWriter;\n\n**\n * Pretty Print XML String\n * \n * @param inputXmlString\n * @return\n */\npublic static String prettyPrintXml(String xml) {\n\n final StringWriter sw;\n\n try {\n final OutputFormat format = OutputFormat.createPrettyPrint();\n final org.dom4j.Document document = DocumentHelper.parseText(xml);\n sw = new StringWriter();\n final XMLWriter writer = new XMLWriter(sw, format);\n writer.write(document);\n }\n catch (Exception e) {\n throw new RuntimeException(\"Error pretty printing xml:\\n\" + xml, e);\n }\n return sw.toString();\n}\n"
},
{
"answer_id": 32119396,
"author": "comonad",
"author_id": 460175,
"author_profile": "https://Stackoverflow.com/users/460175",
"pm_score": 1,
"selected": false,
"text": "String leastPrettifiedXml = uglyXml.replaceAll(\"><\", \">\\n<\");\n"
},
{
"answer_id": 37221093,
"author": "Sireesh Yarlagadda",
"author_id": 2057902,
"author_profile": "https://Stackoverflow.com/users/2057902",
"pm_score": 0,
"selected": false,
"text": " try\n {\n TransformerFactory transFactory = TransformerFactory.newInstance();\n Transformer transformer = null;\n transformer = transFactory.newTransformer();\n StringWriter buffer = new StringWriter();\n transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, \"yes\");\n transformer.transform(new DOMSource(element),\n new StreamResult(buffer)); \n String str = buffer.toString();\n System.out.println(\"XML INSIDE IS #########################################\"+str);\n return element;\n }\n catch (TransformerConfigurationException e)\n {\n e.printStackTrace();\n }\n catch (TransformerException e)\n {\n e.printStackTrace();\n }\n"
},
{
"answer_id": 37599612,
"author": "maks tkach",
"author_id": 6068492,
"author_profile": "https://Stackoverflow.com/users/6068492",
"pm_score": 3,
"selected": false,
"text": "import javax.xml.transform.OutputKeys;\nimport javax.xml.transform.Source;\nimport javax.xml.transform.Transformer;\nimport javax.xml.transform.TransformerFactory;\nimport javax.xml.transform.stream.StreamResult;\nimport javax.xml.transform.stream.StreamSource;\n\nString formattedXml1 = prettyFormat(\"<root><child>aaa</child><child/></root>\");\n\npublic static String prettyFormat(String input) {\n return prettyFormat(input, \"2\");\n}\n\npublic static String prettyFormat(String input, String indent) {\n Source xmlInput = new StreamSource(new StringReader(input));\n StringWriter stringWriter = new StringWriter();\n try {\n TransformerFactory transformerFactory = TransformerFactory.newInstance();\n Transformer transformer = transformerFactory.newTransformer();\n transformer.setOutputProperty(OutputKeys.INDENT, \"yes\");\n transformer.setOutputProperty(\"{http://xml.apache.org/xslt}indent-amount\", indent);\n transformer.transform(xmlInput, new StreamResult(stringWriter));\n\n String pretty = stringWriter.toString();\n pretty = pretty.replace(\"\\r\\n\", \"\\n\");\n return pretty; \n } catch (Exception e) {\n throw new RuntimeException(e);\n }\n}\n"
},
{
"answer_id": 47107329,
"author": "Steve T",
"author_id": 3465795,
"author_profile": "https://Stackoverflow.com/users/3465795",
"pm_score": 0,
"selected": false,
"text": "// you call this method passing in the xml text\npublic static void prettyPrint(String text){\n prettyPrint(text, 0);\n}\n\n// \"index\" corresponds to the number of levels of nesting and/or the number of tabs to print before printing the tag\npublic static void prettyPrint(String xmlText, int index){\n boolean foundTagStart = false;\n StringBuilder tagChars = new StringBuilder();\n String startTag = \"\";\n String endTag = \"\";\n String[] chars = xmlText.split(\"\");\n // find the next start tag\n for(String ch : chars){\n if(ch.equalsIgnoreCase(\"<\")){\n tagChars.append(ch);\n foundTagStart = true;\n } else if(ch.equalsIgnoreCase(\">\") && foundTagStart){\n startTag = tagChars.append(ch).toString();\n String tempTag = startTag;\n endTag = (tempTag.contains(\"\\\"\") ? (tempTag.split(\" \")[0] + \">\") : tempTag).replace(\"<\", \"</\"); // <startTag attr1=1 attr2=2> => </startTag>\n break;\n } else if(foundTagStart){\n tagChars.append(ch);\n }\n }\n // once start and end tag are calculated, print start tag, then content, then end tag\n if(foundTagStart){\n int startIndex = xmlText.indexOf(startTag);\n int endIndex = xmlText.indexOf(endTag);\n // handle if matching tags NOT found\n if((startIndex < 0) || (endIndex < 0)){\n if(startIndex < 0) {\n // no start tag found\n return;\n } else {\n // start tag found, no end tag found (handles single tags aka \"<mytag/>\" or \"<?xml ...>\")\n printTabs(index);\n System.out.println(startTag);\n // move on to the next tag\n // NOTE: \"index\" (not index+1) because next tag is on same level as this one\n prettyPrint(xmlText.substring(startIndex+startTag.length(), xmlText.length()), index);\n return;\n }\n // handle when matching tags found\n } else {\n String content = xmlText.substring(startIndex+startTag.length(), endIndex);\n boolean isTagContainsTags = content.contains(\"<\"); // content contains tags\n printTabs(index);\n if(isTagContainsTags){ // ie: <tag1><tag2>stuff</tag2></tag1>\n System.out.println(startTag);\n prettyPrint(content, index+1); // \"index+1\" because \"content\" is nested\n printTabs(index);\n } else {\n System.out.print(startTag); // ie: <tag1>stuff</tag1> or <tag1></tag1>\n System.out.print(content);\n }\n System.out.println(endTag);\n int nextIndex = endIndex + endTag.length();\n if(xmlText.length() > nextIndex){ // if there are more tags on this level, continue\n prettyPrint(xmlText.substring(nextIndex, xmlText.length()), index);\n }\n }\n } else {\n System.out.print(xmlText);\n }\n}\n\nprivate static void printTabs(int counter){\n while(counter-- > 0){ \n System.out.print(\"\\t\");\n }\n}\n"
},
{
"answer_id": 51272975,
"author": "user3083990",
"author_id": 3083990,
"author_profile": "https://Stackoverflow.com/users/3083990",
"pm_score": 3,
"selected": false,
"text": " public static void main(String[] args) throws Exception {\n DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();\n dbf.setValidating(false);\n DocumentBuilder db = dbf.newDocumentBuilder();\n Document doc = db.parse(new FileInputStream(new File(\"C:/Users/xyz.xml\")));\n prettyPrint(doc);\n\n}\n\nprivate static String prettyPrint(Document document)\n throws TransformerException {\n TransformerFactory transformerFactory = TransformerFactory\n .newInstance();\n Transformer transformer = transformerFactory.newTransformer();\n transformer.setOutputProperty(OutputKeys.INDENT, \"yes\");\n transformer.setOutputProperty(\"{http://xml.apache.org/xslt}indent-amount\", \"2\");\n transformer.setOutputProperty(OutputKeys.ENCODING, \"UTF-8\");\n transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, \"no\");\n DOMSource source = new DOMSource(document);\n StringWriter strWriter = new StringWriter();\n StreamResult result = new StreamResult(strWriter);transformer.transform(source, result);\n System.out.println(strWriter.getBuffer().toString());\n\n return strWriter.getBuffer().toString();\n\n}\n"
},
{
"answer_id": 54683129,
"author": "Valentyn Kolesnikov",
"author_id": 1947482,
"author_profile": "https://Stackoverflow.com/users/1947482",
"pm_score": 1,
"selected": false,
"text": "U.formatXml(string)"
},
{
"answer_id": 56006254,
"author": "Benson Githinji",
"author_id": 6740199,
"author_profile": "https://Stackoverflow.com/users/6740199",
"pm_score": 2,
"selected": false,
"text": "public static String prettyPrintXml(String xmlStringToBeFormatted) {\n String formattedXmlString = null;\n try {\n DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();\n documentBuilderFactory.setValidating(true);\n DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();\n InputSource inputSource = new InputSource(new StringReader(xmlStringToBeFormatted));\n Document document = documentBuilder.parse(inputSource);\n\n Transformer transformer = TransformerFactory.newInstance().newTransformer();\n transformer.setOutputProperty(OutputKeys.INDENT, \"yes\");\n transformer.setOutputProperty(\"{http://xml.apache.org/xslt}indent-amount\", \"2\");\n\n StreamResult streamResult = new StreamResult(new StringWriter());\n DOMSource dOMSource = new DOMSource(document);\n transformer.transform(dOMSource, streamResult);\n formattedXmlString = streamResult.getWriter().toString().trim();\n } catch (Exception ex) {\n StringWriter sw = new StringWriter();\n ex.printStackTrace(new PrintWriter(sw));\n System.err.println(sw.toString());\n }\n return formattedXmlString;\n}\n"
},
{
"answer_id": 56531539,
"author": "Faisal K",
"author_id": 8332759,
"author_profile": "https://Stackoverflow.com/users/8332759",
"pm_score": -1,
"selected": false,
"text": "public void formatXML(final String unformattedXML) {\n final int length = unformattedXML.length();\n final int indentSpace = 3;\n final StringBuilder newString = new StringBuilder(length + length / 10);\n final char space = ' ';\n int i = 0;\n int indentCount = 0;\n char currentChar = unformattedXML.charAt(i++);\n char previousChar = currentChar;\n boolean nodeStarted = true;\n newString.append(currentChar);\n for (; i < length - 1;) {\n currentChar = unformattedXML.charAt(i++);\n if(((int) currentChar < 33) && !nodeStarted) {\n continue;\n }\n switch (currentChar) {\n case '<':\n if ('>' == previousChar && '/' != unformattedXML.charAt(i - 1) && '/' != unformattedXML.charAt(i) && '!' != unformattedXML.charAt(i)) {\n indentCount++;\n }\n newString.append(System.lineSeparator());\n for (int j = indentCount * indentSpace; j > 0; j--) {\n newString.append(space);\n }\n newString.append(currentChar);\n nodeStarted = true;\n break;\n case '>':\n newString.append(currentChar);\n nodeStarted = false;\n break;\n case '/':\n if ('<' == previousChar || '>' == unformattedXML.charAt(i)) {\n indentCount--;\n }\n newString.append(currentChar);\n break;\n default:\n newString.append(currentChar);\n }\n previousChar = currentChar;\n }\n newString.append(unformattedXML.charAt(length - 1));\n System.out.println(newString.toString());\n}\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139076",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2959/"
] |
139,088
|
<p>when i use setDefaultLookAndFeelDecorated(true) method in Java
why is the Frame appear FullScreen when i maximize the Frame ?
and how can i disaple the FullScreen mode in this method ?</p>
|
[
{
"answer_id": 144142,
"author": "Angelo van der Sijpt",
"author_id": 19144,
"author_profile": "https://Stackoverflow.com/users/19144",
"pm_score": 3,
"selected": true,
"text": "setDefaultLookAndFeelDecorated"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139088",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22634/"
] |
139,115
|
<p>Here is the scenario:</p>
<p>I have a winforms application using NHibernate. When launched, I populate a DataGridView with the results of a NHibernate query. This part works fine. If I update a record in that list and flush the session, the update takes in the database. Upon closing the form after the update, I call a method to retrieve a list of objects to populate the DataGridView again to pick up the change and also get any other changes that may have occurred by somebody else. The problem is that the record that got updated, NHibernate doesn't reflect the change in the list it gives me. When I insert or delete a record, everything works fine. It is just when I update, that I get this behavior. I narrowed it down to NHibernate with their caching mechanism. I cannot figure out a way to make NHibernate retrieve from the database instead of using the cache after an update occurs. I posted on the NHibernate forums, but the suggestions they gave me didn't work. I stated this and nobody replied back. I am not going to state what I have tried in case I didn't do it right. If you answer with something that I tried exactly, I will state it in the comments of your answer.</p>
<p>This is the code that I use to retrieve the list:</p>
<pre><code>public IList<WorkOrder> FindBy(string fromDate, string toDate)
{
IQuery query = _currentSession.CreateQuery("from WorkOrder wo where wo.Date >= ? and wo.Date <= ?");
query.SetParameter(0, fromDate);
query.SetParameter(1, toDate);
return query.List<WorkOrder>();
}
</code></pre>
<p>The session is passed to the class when it is constructed. I can post my mapping file also, but I am not sure if there is anything wrong with it, since everything else works. Anybody seen this before? This is the first project that I have used NHibernate, thanks for the help.</p>
|
[
{
"answer_id": 191800,
"author": "Watson",
"author_id": 25807,
"author_profile": "https://Stackoverflow.com/users/25807",
"pm_score": 2,
"selected": false,
"text": "Session.Update(obj);\nSession.Evict(obj);\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139115",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1117/"
] |
139,118
|
<p>Does anyone know how to get the HTML out of an IFRAME I have tried several different ways:</p>
<pre><code>document.getElementById('iframe01').contentDocument.body.innerHTML
document.frames['iframe01'].document.body.innerHTML
document.getElementById('iframe01').contentWindow.document.body.innerHTML
</code></pre>
<p>etc</p>
|
[
{
"answer_id": 139132,
"author": "ConroyP",
"author_id": 2287,
"author_profile": "https://Stackoverflow.com/users/2287",
"pm_score": 3,
"selected": false,
"text": "<iframe id=\"my_iframe\" ...></iframe>\n\n$('#my_iframe').contents().find('html').html();\n"
},
{
"answer_id": 139155,
"author": "wcm",
"author_id": 2173,
"author_profile": "https://Stackoverflow.com/users/2173",
"pm_score": 4,
"selected": false,
"text": "window.frames['iframe01'].document.body.innerHTML \n"
},
{
"answer_id": 3510256,
"author": "cypher",
"author_id": 381786,
"author_profile": "https://Stackoverflow.com/users/381786",
"pm_score": 4,
"selected": false,
"text": "<iframe id = \"testframe\" onload = populateIframe(this.id);></iframe>\n\n// The following function should be inside a script tag\n\nfunction populateIframe(id) { \n\n var text = \"This is a Test\"\nvar iframe = document.getElementById(id); \n\nvar doc; \n\nif(iframe.contentDocument) { \n doc = iframe.contentDocument; \n} else {\n doc = iframe.contentWindow.document; \n}\n\ndoc.body.innerHTML = text; \n\n }\n"
},
{
"answer_id": 7289262,
"author": "Sourabh",
"author_id": 912359,
"author_profile": "https://Stackoverflow.com/users/912359",
"pm_score": 2,
"selected": false,
"text": "function gethtml() {\n const x = document.getElementById(\"myframe\")\n const y = x.contentWindow || x.contentDocument\n const z = y.document ? y.document : y\n alert(z.body.innerHTML)\n}\n"
},
{
"answer_id": 13843635,
"author": "ravi404",
"author_id": 948301,
"author_profile": "https://Stackoverflow.com/users/948301",
"pm_score": 2,
"selected": false,
"text": "$('#my_iframe').contents().find('body').html();\n"
},
{
"answer_id": 24305538,
"author": "user1175106",
"author_id": 1175106,
"author_profile": "https://Stackoverflow.com/users/1175106",
"pm_score": 0,
"selected": false,
"text": "document.getElementById('iframe01').outerHTML\n"
},
{
"answer_id": 54197533,
"author": "Ahsan Horani",
"author_id": 4453224,
"author_profile": "https://Stackoverflow.com/users/4453224",
"pm_score": 1,
"selected": false,
"text": "<div id='myframe'>\n\n <?php \n /* \n Use below function to display final HTML inside this div\n */\n\n //Display Frame\n echo displayFrame(); \n ?>\n\n</div>\n\n<?php\n\n/* \n Function to display frame from another domain \n*/\n\nfunction displayFrame()\n{\n $webUrl = 'http://[external-web-domain.com]/';\n\n //Get HTML from the URL\n $content = file_get_contents($webUrl);\n\n //Add custom JS to returned HTML content\n $customJS = \"\n <script>\n\n /* Here I am writing a sample jQuery to hide the navigation menu\n You can write your own jQuery for this content\n */\n //Hide Navigation bar\n jQuery(\\\".navbar\\\").hide();\n\n </script>\";\n\n //Append Custom JS with HTML\n $html = $content . $customJS;\n\n //Return customized HTML\n return $html;\n}\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139118",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
139,131
|
<p>i have a number of jsp files under web-inf folder. Inside my web.xml i specify an errorppage for 404 amd 403 and java.lang.exception. Do i need to include a page directive for each of my jsp's or will they automatically get forwarded to the exception handling page because they are under web-inf?</p>
<p>If this is true does this mean that jsps which are not placed under web-inf do need to have the page directive added in order to forward them to the exception handling page?</p>
<p>thank you , im just trying to understand the consequences of web-inf</p>
|
[
{
"answer_id": 139174,
"author": "Steve g",
"author_id": 12092,
"author_profile": "https://Stackoverflow.com/users/12092",
"pm_score": 2,
"selected": true,
"text": "<error-page> \n <error-code>404</error-code> \n <location>/404Error.jsp</location> \n</error-page>\n<error-page> \n <error-code>403</error-code> \n <location>/403Error.jsp</location> \n</error-page>\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139131",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
139,142
|
<p>In an ASP.NET web application with a lot of HTML pages, a lot of inline JavaScript functions are accumulating. What is a good plan for organizing them into external files? Most of the functions are particular to the page for which they are written, but a few are relevant to the entire application.</p>
<p>A single file could get quite large. With C#, etc., I usually divide the files at least into one containing the general functions and classes, so that I can use the same file for other applications, and one for functions and classes particular to this application. I don't think that a large file would be good for performance in a web application, however.</p>
<p>What is the thinking in this regard?</p>
|
[
{
"answer_id": 140662,
"author": "Jason Bunting",
"author_id": 1790,
"author_profile": "https://Stackoverflow.com/users/1790",
"pm_score": 2,
"selected": false,
"text": "protected override void OnLoad(EventArgs e)\n{\n base.OnLoad(e);\n string possiblePageSpecificJavaScriptFile = string.Format(\"{0}.js\", this.TemplateControl.AppRelativeVirtualPath);\n if (File.Exists(Server.MapPath(possiblePageSpecificJavaScriptFile)) == true)\n {\n string absolutePath = possiblePageSpecificJavaScriptFile.Replace(\"~\", Request.ApplicationPath);\n absolutePath = string.Format(\"/{0}\", absolutePath.TrimStart('/'));\n Page.ClientScript.RegisterClientScriptInclude(absolutePath, absolutePath);\n }\n}\n"
},
{
"answer_id": 143469,
"author": "cllpse",
"author_id": 20946,
"author_profile": "https://Stackoverflow.com/users/20946",
"pm_score": 1,
"selected": false,
"text": "Default.aspx\nDefault.aspx.js\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139142",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
139,157
|
<p>I am building a menu in HTML/CSS/JS and I need a way to prevent the text in the menu from being highlighted when double-clicked on. I need a way to pass the id's of several divs into a function and have highlighting turned off within them. </p>
<p>So when the user accidentally (or on purpose) double clicks on the menu, the menu shows its sub-elements but its text does not highlight.</p>
<p>There are a number of scripts out there floating around on the web, but many seem outdated. What's the best way?</p>
|
[
{
"answer_id": 139195,
"author": "Vijesh VP",
"author_id": 22016,
"author_profile": "https://Stackoverflow.com/users/22016",
"pm_score": 0,
"selected": false,
"text": "<script type=\"text/javascript\">\n function clearSelection() {\n var sel;\n if (document.selection && document.selection.empty) {\n document.selection.empty();\n } else if (window.getSelection) {\n sel = window.getSelection();\n if (sel && sel.removeAllRanges)\n sel.removeAllRanges();\n }\n } \n</script>\n\n<div ondblclick=\"clearSelection()\">Some text goes here.</div>\n"
},
{
"answer_id": 141935,
"author": "Joe Lencioni",
"author_id": 18986,
"author_profile": "https://Stackoverflow.com/users/18986",
"pm_score": 2,
"selected": false,
"text": "#id::-moz-selection {\n background: transparent;\n}\n\n#id::selection {\n background: transparent;\n}\n"
},
{
"answer_id": 142801,
"author": "scunliffe",
"author_id": 6144,
"author_profile": "https://Stackoverflow.com/users/6144",
"pm_score": 6,
"selected": true,
"text": "div.noSelect {\n -moz-user-select: none; /* mozilla browsers */\n -khtml-user-select: none; /* webkit browsers */\n}\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139157",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/315650/"
] |
139,180
|
<p>I have a Python module installed on my system and I'd like to be able to see what functions/classes/methods are available in it.</p>
<p>I want to call the <code>help</code> function on each one. In Ruby I can do something like <code>ClassName.methods</code> to get a list of all the methods available on that class. Is there something similar in Python?</p>
<p>e.g. something like:</p>
<pre><code>from somemodule import foo
print(foo.methods) # or whatever is the correct method to call
</code></pre>
|
[
{
"answer_id": 139193,
"author": "camflan",
"author_id": 22445,
"author_profile": "https://Stackoverflow.com/users/22445",
"pm_score": 9,
"selected": false,
"text": "dir(module)"
},
{
"answer_id": 139198,
"author": "Thomas Wouters",
"author_id": 17624,
"author_profile": "https://Stackoverflow.com/users/17624",
"pm_score": 9,
"selected": true,
"text": "inspect"
},
{
"answer_id": 139258,
"author": "Oli",
"author_id": 22035,
"author_profile": "https://Stackoverflow.com/users/22035",
"pm_score": 6,
"selected": false,
"text": "import types\nimport yourmodule\n\nprint([getattr(yourmodule, a) for a in dir(yourmodule)\n if isinstance(getattr(yourmodule, a), types.FunctionType)])\n"
},
{
"answer_id": 140106,
"author": "Dan Lenski",
"author_id": 20789,
"author_profile": "https://Stackoverflow.com/users/20789",
"pm_score": 8,
"selected": false,
"text": "import"
},
{
"answer_id": 142501,
"author": "Algorias",
"author_id": 22893,
"author_profile": "https://Stackoverflow.com/users/22893",
"pm_score": 5,
"selected": false,
"text": "dir(module) \n"
},
{
"answer_id": 9794849,
"author": "adnan",
"author_id": 407743,
"author_profile": "https://Stackoverflow.com/users/407743",
"pm_score": 7,
"selected": false,
"text": "inspect.getmembers"
},
{
"answer_id": 10079706,
"author": "bmu",
"author_id": 1301710,
"author_profile": "https://Stackoverflow.com/users/1301710",
"pm_score": 5,
"selected": false,
"text": "dir(module)"
},
{
"answer_id": 30584102,
"author": "ckb",
"author_id": 1668964,
"author_profile": "https://Stackoverflow.com/users/1668964",
"pm_score": 3,
"selected": false,
"text": "import re\npattern = re.compile(\"def (.*)\\(\")\nfor i, line in enumerate(open('Example.py')):\n for match in re.finditer(pattern, line):\n print '%s: %s' % (i+1, match.groups()[0])\n"
},
{
"answer_id": 31005891,
"author": "csl",
"author_id": 21028,
"author_profile": "https://Stackoverflow.com/users/21028",
"pm_score": 6,
"selected": false,
"text": "import"
},
{
"answer_id": 40118371,
"author": "Vishal Lamba",
"author_id": 7038953,
"author_profile": "https://Stackoverflow.com/users/7038953",
"pm_score": 2,
"selected": false,
"text": "import module"
},
{
"answer_id": 41549607,
"author": "Saurya Man Patel",
"author_id": 6538142,
"author_profile": "https://Stackoverflow.com/users/6538142",
"pm_score": 2,
"selected": false,
"text": "(C:\\Program Files\\Anaconda2) C:\\Users\\lenovo>ipython\nPython 2.7.12 |Anaconda 4.2.0 (64-bit)| (default, Jun 29 2016, 11:07:13) [MSC v.1500 64 bit (AMD64)]\nType \"copyright\", \"credits\" or \"license\" for more information.\n\nIPython 5.1.0 -- An enhanced Interactive Python.\n? -> Introduction and overview of IPython's features.\n%quickref -> Quick reference.\nhelp -> Python's own help system.\nobject? -> Details about 'object', use 'object??' for extra details.\n\nIn [1]: import hashlib\n\nIn [2]: hashlib.\n hashlib.algorithms hashlib.new hashlib.sha256\n hashlib.algorithms_available hashlib.pbkdf2_hmac hashlib.sha384\n hashlib.algorithms_guaranteed hashlib.sha1 hashlib.sha512\n hashlib.md5 hashlib.sha224\n"
},
{
"answer_id": 46105518,
"author": "Cireo",
"author_id": 2284490,
"author_profile": "https://Stackoverflow.com/users/2284490",
"pm_score": 5,
"selected": false,
"text": "import ast\n\nsource = open(<filepath_to_parse>).read()\nfunctions = [f.name for f in ast.parse(source).body\n if isinstance(f, ast.FunctionDef)]\n"
},
{
"answer_id": 49490170,
"author": "Xantium",
"author_id": 8372104,
"author_profile": "https://Stackoverflow.com/users/8372104",
"pm_score": 4,
"selected": false,
"text": "dir()"
},
{
"answer_id": 52351591,
"author": "Manish Kumar",
"author_id": 6436791,
"author_profile": "https://Stackoverflow.com/users/6436791",
"pm_score": 1,
"selected": false,
"text": "result=[]\nfor i in dir(your_module):\n if type(getattr(your_module, i)).__name__ == \"function\":\n result.append(getattr(your_module, i))\n"
},
{
"answer_id": 60745386,
"author": "eid",
"author_id": 8549873,
"author_profile": "https://Stackoverflow.com/users/8549873",
"pm_score": 2,
"selected": false,
"text": "import sys\nfrom inspect import getmembers, isfunction\nfcn_list = [o[0] for o in getmembers(sys.modules[__name__], isfunction)]\n"
},
{
"answer_id": 60968677,
"author": "Julien Faujanet",
"author_id": 12419998,
"author_profile": "https://Stackoverflow.com/users/12419998",
"pm_score": 2,
"selected": false,
"text": "r = globals()\nsep = '\\n'+100*'*'+'\\n' # To make it clean to read.\nfor k in list(r.keys()):\n try:\n if str(type(r[k])).count('function'):\n print(sep+k + ' : \\n' + str(r[k].__doc__))\n except Exception as e:\n print(e)\n"
},
{
"answer_id": 63268485,
"author": "Karthik Nandula",
"author_id": 7130405,
"author_profile": "https://Stackoverflow.com/users/7130405",
"pm_score": 2,
"selected": false,
"text": "dir"
},
{
"answer_id": 65308505,
"author": "Boris Verkhovskiy",
"author_id": 3064538,
"author_profile": "https://Stackoverflow.com/users/3064538",
"pm_score": 2,
"selected": false,
"text": "vars(module)"
},
{
"answer_id": 65745550,
"author": "Guimoute",
"author_id": 9282844,
"author_profile": "https://Stackoverflow.com/users/9282844",
"pm_score": 1,
"selected": false,
"text": "# Get this script's name.\nimport os\nscript_name = os.path.basename(__file__).rstrip(\".py\")\n\n# Import it from its path so that you can use it as a Python object.\nimport importlib.util\nspec = importlib.util.spec_from_file_location(script_name, __file__)\nx = importlib.util.module_from_spec(spec)\nspec.loader.exec_module(x)\n\n# List the functions defined in it.\nfrom inspect import getmembers, isfunction\nlist_of_functions = getmembers(x, isfunction)\n"
},
{
"answer_id": 67014346,
"author": "Josh Peak",
"author_id": 622276,
"author_profile": "https://Stackoverflow.com/users/622276",
"pm_score": 3,
"selected": false,
"text": "__main__"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139180",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6527/"
] |
139,199
|
<p>I realize that parameterized SQL queries is the optimal way to sanitize user input when building queries that contain user input, but I'm wondering what is wrong with taking user input and escaping any single quotes and surrounding the whole string with single quotes. Here's the code:</p>
<pre><code>sSanitizedInput = "'" & Replace(sInput, "'", "''") & "'"
</code></pre>
<p>Any single-quote the user enters is replaced with double single-quotes, which eliminates the users ability to end the string, so anything else they may type, such as semicolons, percent signs, etc., will all be part of the string and not actually executed as part of the command. </p>
<p>We are using Microsoft SQL Server 2000, for which I believe the single-quote is the only string delimiter and the only way to escape the string delimiter, so there is no way to execute anything the user types in.</p>
<p>I don't see any way to launch an SQL injection attack against this, but I realize that if this were as bulletproof as it seems to me someone else would have thought of it already and it would be common practice. </p>
<p>What's wrong with this code? Is there a way to get an SQL injection attack past this sanitization technique? Sample user input that exploits this technique would be very helpful.</p>
<hr/>
<p>UPDATE:</p>
<p>I still don't know of any way to effectively launch a SQL injection attack against this code. A few people suggested that a backslash would escape one single-quote and leave the other to end the string so that the rest of the string would be executed as part of the SQL command, and I realize that this method would work to inject SQL into a MySQL database, but in SQL Server 2000 the only way (that I've been able to find) to escape a single-quote is with another single-quote; backslashes won't do it.</p>
<p>And unless there is a way to stop the escaping of the single-quote, none of the rest of the user input will be executed because it will all be taken as one contiguous string.</p>
<p>I understand that there are better ways to sanitize input, but I'm really more interested in learning why the method I provided above won't work. If anyone knows of any specific way to mount a SQL injection attack against this sanitization method I would love to see it.</p>
|
[
{
"answer_id": 376674,
"author": "AviD",
"author_id": 10080,
"author_profile": "https://Stackoverflow.com/users/10080",
"pm_score": 5,
"selected": false,
"text": "username = left(Replace(sInput, \"'\", \"''\"), 20)\n"
},
{
"answer_id": 35529646,
"author": "miroxlav",
"author_id": 2392157,
"author_profile": "https://Stackoverflow.com/users/2392157",
"pm_score": -1,
"selected": false,
"text": "nvarchar"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139199",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22392/"
] |
139,207
|
<p>So many different controls to choose from! What are best practices for determining which control to use for displaying data in ASP.NET?</p>
|
[
{
"answer_id": 19445450,
"author": "Iman",
"author_id": 184572,
"author_profile": "https://Stackoverflow.com/users/184572",
"pm_score": 4,
"selected": false,
"text": "<asp:ListView runat=\"server\" OnItemCommand=\"Unnamed1_ItemCommand\">\n<ItemTemplate> <%# Eval(\"Name\")%> </ItemTemplate>\n<asp:ListView>\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139207",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1768/"
] |
139,209
|
<p>Or do you populate your form controls manually by a method?</p>
<p>Is either considered a best practice?</p>
|
[
{
"answer_id": 19445450,
"author": "Iman",
"author_id": 184572,
"author_profile": "https://Stackoverflow.com/users/184572",
"pm_score": 4,
"selected": false,
"text": "<asp:ListView runat=\"server\" OnItemCommand=\"Unnamed1_ItemCommand\">\n<ItemTemplate> <%# Eval(\"Name\")%> </ItemTemplate>\n<asp:ListView>\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139209",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16419/"
] |
139,212
|
<p>I've added cookie support to SOAPpy by overriding HTTPTransport. I need functionality beyond that of SOAPpy, so I was planning on moving to ZSI, but I can't figure out how to put the Cookies on the ZSI posts made to the service. Without these cookies, the server will think it is an unauthorized request and it will fail.</p>
<p>How can I add cookies from a Python CookieJar to ZSI requests?</p>
|
[
{
"answer_id": 145610,
"author": "Florian Bösch",
"author_id": 19435,
"author_profile": "https://Stackoverflow.com/users/19435",
"pm_score": 2,
"selected": true,
"text": "b = Binding(url='/cgi-bin/simple-test', tracefile=fp)\nb.cookies['foo'] = 'bar'\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139212",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17583/"
] |
139,214
|
<p>The most egregiously redundant code construct I often see involves using the code sequence</p>
<pre><code>if (condition)
return true;
else
return false;
</code></pre>
<p>instead of simply writing</p>
<pre><code>return (condition);
</code></pre>
<p>I've seen this beginner error in all sorts of languages: from Pascal and C to PHP and Java. What other such constructs would you flag in a code review?</p>
|
[
{
"answer_id": 139231,
"author": "WW.",
"author_id": 14663,
"author_profile": "https://Stackoverflow.com/users/14663",
"pm_score": 2,
"selected": false,
"text": " // stuff\n return;\n}\n"
},
{
"answer_id": 139249,
"author": "Otherside",
"author_id": 18697,
"author_profile": "https://Stackoverflow.com/users/18697",
"pm_score": 3,
"selected": false,
"text": "if (condition == true)\n{\n ...\n}\n"
},
{
"answer_id": 139263,
"author": "Paul Tomblin",
"author_id": 3333,
"author_profile": "https://Stackoverflow.com/users/3333",
"pm_score": 4,
"selected": false,
"text": "if (foo == true)\n{\n do stuff\n}\n"
},
{
"answer_id": 139284,
"author": "Nick Johnson",
"author_id": 12030,
"author_profile": "https://Stackoverflow.com/users/12030",
"pm_score": 2,
"selected": false,
"text": "void myfunction() {\n if(condition) {\n // Do some stuff\n if(othercond) {\n // Do more stuff\n }\n }\n}\n"
},
{
"answer_id": 139320,
"author": "Steve Fallows",
"author_id": 18882,
"author_profile": "https://Stackoverflow.com/users/18882",
"pm_score": 2,
"selected": false,
"text": "bool a;\nbool b;\n...\nif (a == true)\n b = true;\nelse\n b = false;\n"
},
{
"answer_id": 139337,
"author": "Otherside",
"author_id": 18697,
"author_profile": "https://Stackoverflow.com/users/18697",
"pm_score": 2,
"selected": false,
"text": "exit"
},
{
"answer_id": 139347,
"author": "RossFabricant",
"author_id": 20754,
"author_profile": "https://Stackoverflow.com/users/20754",
"pm_score": 2,
"selected": false,
"text": "int foo; \nfoo = GetFoo();\n"
},
{
"answer_id": 139395,
"author": "zoul",
"author_id": 17279,
"author_profile": "https://Stackoverflow.com/users/17279",
"pm_score": 3,
"selected": false,
"text": "return (test == 1)? ((test == 0) ? 0 : 1) : ((test == 0) ? 0 : 1);\n"
},
{
"answer_id": 139399,
"author": "ComSubVie",
"author_id": 15709,
"author_profile": "https://Stackoverflow.com/users/15709",
"pm_score": 1,
"selected": false,
"text": "function foo() {\n if ( something ) {\n return;\n } else {\n do_something();\n }\n}\n"
},
{
"answer_id": 139424,
"author": "PiedPiper",
"author_id": 19315,
"author_profile": "https://Stackoverflow.com/users/19315",
"pm_score": 2,
"selected": false,
"text": "return (condition);\n"
},
{
"answer_id": 139435,
"author": "Panos",
"author_id": 8049,
"author_profile": "https://Stackoverflow.com/users/8049",
"pm_score": 2,
"selected": false,
"text": "if (name != null)\n person.Name = name;\n"
},
{
"answer_id": 139548,
"author": "Panos",
"author_id": 8049,
"author_profile": "https://Stackoverflow.com/users/8049",
"pm_score": 2,
"selected": false,
"text": "if (x > 0)\n{\n // a lot of code to calculate z\n y = x + z;\n}\nelse\n{\n // a lot of code to calculate z\n y = x - z;\n}\n"
},
{
"answer_id": 147843,
"author": "Diomidis Spinellis",
"author_id": 20520,
"author_profile": "https://Stackoverflow.com/users/20520",
"pm_score": 2,
"selected": false,
"text": "{\n char buff = malloc(1024);\n /* ... */\n free(buff);\n}\n"
},
{
"answer_id": 154965,
"author": "EvilTeach",
"author_id": 7734,
"author_profile": "https://Stackoverflow.com/users/7734",
"pm_score": 1,
"selected": false,
"text": "char s[100];\n"
},
{
"answer_id": 162204,
"author": "ilitirit",
"author_id": 9825,
"author_profile": "https://Stackoverflow.com/users/9825",
"pm_score": 0,
"selected": false,
"text": "const int foo = 5;\nConsole.WriteLine(\"Number of Items: \" + foo.ToString());\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139214",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20520/"
] |
139,228
|
<p>One of our developers is continually writing code and putting it into version control without testing it. The quality of our code is suffering as a result.</p>
<p>Besides getting rid of the developer, how can I solve this problem?</p>
<p>EDIT</p>
<p>I have talked to him about it number of times and even given him written warning </p>
|
[
{
"answer_id": 139412,
"author": "Rafał Dowgird",
"author_id": 12166,
"author_profile": "https://Stackoverflow.com/users/12166",
"pm_score": 3,
"selected": false,
"text": "Intro\n What shall we do with a drunken sailor, (3×)\n Early in the morning?\nChorus\n Wey–hey and up she rises, (3×)\n Early in the morning!\nVerses\n Stick him in a bag and beat him senseless, (3×)\n Early in the morning!\n Put him in the longboat till he’s sober, (3×)\n Early in the morning!\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139228",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17560/"
] |
139,245
|
<p>How to get the relative path in t sql? Take for example a <code>.sql</code> file is located in the folder <code>D:\temp</code>, I want to get path of the file hello.txt in the folder <code>D:\temp\App_Data</code>. How to use the relative path reference?</p>
<p>Let's say I am executing the sql file inside the SQL server management studio.</p>
|
[
{
"answer_id": 169730,
"author": "GilM",
"author_id": 10192,
"author_profile": "https://Stackoverflow.com/users/10192",
"pm_score": 4,
"selected": true,
"text": "DECLARE @RelDir varchar(1000)\nSET @RelDir = 'D:\\temp\\'\n...\n"
},
{
"answer_id": 15553094,
"author": "Kelly Davis",
"author_id": 1587986,
"author_profile": "https://Stackoverflow.com/users/1587986",
"pm_score": 0,
"selected": false,
"text": "@echo OFF\nSETLOCAL DisableDelayedExpansion\nFOR /F \"usebackq delims=\" %%a in (`\"findstr /n ^^ t-SQL.SQL\"`) do (\n set \"var=%%a\"\n SETLOCAL EnableDelayedExpansion\n set \"var=!var:*:=!\"\n set RunLocation=%~dp0\n echo(%~dp0!var! > newsql.sql\n ENDLOCAL\n)\n sqlcmd newsql.sql\n"
},
{
"answer_id": 26897979,
"author": "mateuscb",
"author_id": 461958,
"author_profile": "https://Stackoverflow.com/users/461958",
"pm_score": 4,
"selected": false,
"text": "script.sql"
},
{
"answer_id": 37771241,
"author": "water",
"author_id": 6159495,
"author_profile": "https://Stackoverflow.com/users/6159495",
"pm_score": 1,
"selected": false,
"text": "@set FullScriptDir=%CD%\nsqlcmd -S .\\SQLINSTANCE -i script.sql\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139245",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3834/"
] |
139,260
|
<p>I'm having a problem writing Norwegian characters into an XML file using C#. I have a string variable containing some Norwegian text (with letters like æøå). </p>
<p>I'm writing the XML using an XmlTextWriter, writing the contents to a MemoryStream like this:</p>
<pre><code>MemoryStream stream = new MemoryStream();
XmlTextWriter xmlTextWriter = new XmlTextWriter(stream, Encoding.GetEncoding("ISO-8859-1"));
xmlTextWriter.Formatting = Formatting.Indented;
xmlTextWriter.WriteStartDocument(); //Start doc
</code></pre>
<p>Then I add my Norwegian text like this:</p>
<pre><code>xmlTextWriter.WriteCData(myNorwegianText);
</code></pre>
<p>Then I write the file to disk like this:</p>
<pre><code>FileStream myFile = new FileStream(myPath, FileMode.Create);
StreamWriter sw = new StreamWriter(myFile);
stream.Position = 0;
StreamReader sr = new StreamReader(stream);
string content = sr.ReadToEnd();
sw.Write(content);
sw.Flush();
myFile.Flush();
myFile.Close();
</code></pre>
<p>Now the problem is that in the file on this, all the Norwegian characters look funny.</p>
<p>I'm probably doing the above in some stupid way. Any suggestions on how to fix it?</p>
|
[
{
"answer_id": 139612,
"author": "Thomas Danecker",
"author_id": 9632,
"author_profile": "https://Stackoverflow.com/users/9632",
"pm_score": 3,
"selected": false,
"text": " Encoding encoding = Encoding.GetEncoding(\"ISO-8859-1\");\n\n FileStream myFile = new FileStream(myPath, FileMode.Create);\n StreamWriter sw = new StreamWriter(myFile, encoding);\n\n stream.Position = 0;\n StreamReader sr = new StreamReader(stream, encoding);\n string content = sr.ReadToEnd();\n\n sw.Write(content);\n sw.Flush();\n\n myFile.Flush();\n myFile.Close();\n"
},
{
"answer_id": 13536234,
"author": "Troy Alford",
"author_id": 1454806,
"author_profile": "https://Stackoverflow.com/users/1454806",
"pm_score": 3,
"selected": false,
"text": "Encoding"
},
{
"answer_id": 35490926,
"author": "mauro.Joestar",
"author_id": 5879824,
"author_profile": "https://Stackoverflow.com/users/5879824",
"pm_score": 0,
"selected": false,
"text": "var doc = new XDocument(new XDeclaration(\"1.0\", \"ISO-8859-1\", \"\"));\n using (XmlWriter writer = doc.CreateWriter()){\n writer.WriteStartDocument();\n writer.WriteStartElement(\"Root\");\n writer.WriteElementString(\"Foo\", \"value\");\n writer.WriteEndElement();\n writer.WriteEndDocument();\n }\n doc.Save(\"dte.xml\");\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139260",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5795/"
] |
139,261
|
<p>For testing purposes I have to generate a file of a certain size (to test an upload limit). </p>
<p>What is a command to create a file of a certain size on Linux?</p>
|
[
{
"answer_id": 139278,
"author": "Grundlefleck",
"author_id": 4120,
"author_profile": "https://Stackoverflow.com/users/4120",
"pm_score": 5,
"selected": false,
"text": "$INPUT-FILE=/dev/zero"
},
{
"answer_id": 139282,
"author": "Paul Tomblin",
"author_id": 3333,
"author_profile": "https://Stackoverflow.com/users/3333",
"pm_score": 3,
"selected": false,
"text": "dd if=/dev/zero of=my_file.txt count=12345\n"
},
{
"answer_id": 139287,
"author": "dsm",
"author_id": 7780,
"author_profile": "https://Stackoverflow.com/users/7780",
"pm_score": 4,
"selected": false,
"text": "[dsm@localhost:~]$ perl -e 'print \"\\0\" x 100' > filename.ext\n"
},
{
"answer_id": 139289,
"author": "Ilya Kochetov",
"author_id": 15329,
"author_profile": "https://Stackoverflow.com/users/15329",
"pm_score": 9,
"selected": true,
"text": "dd if=/dev/zero of=upload_test bs=file_size count=1\n"
},
{
"answer_id": 139415,
"author": "Brian",
"author_id": 9493,
"author_profile": "https://Stackoverflow.com/users/9493",
"pm_score": 5,
"selected": false,
"text": "dd if=/dev/zero of=the_file bs=1 count=0 seek=12345\n"
},
{
"answer_id": 245239,
"author": "Benedikt Waldvogel",
"author_id": 4308,
"author_profile": "https://Stackoverflow.com/users/4308",
"pm_score": 4,
"selected": false,
"text": "#include <unistd.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <stdlib.h>\n\nint main() {\n int fd = creat(\"/tmp/foo.txt\", 0644);\n ftruncate(fd, SIZE_IN_BYTES);\n close(fd);\n return 0;\n}\n"
},
{
"answer_id": 8706411,
"author": "steve",
"author_id": 495637,
"author_profile": "https://Stackoverflow.com/users/495637",
"pm_score": 5,
"selected": false,
"text": "mkfile"
},
{
"answer_id": 8706714,
"author": "jørgensen",
"author_id": 1091587,
"author_profile": "https://Stackoverflow.com/users/1091587",
"pm_score": 8,
"selected": false,
"text": "truncate -s 10G foo\nfallocate -l 5G bar\n"
},
{
"answer_id": 13055390,
"author": "user1772090",
"author_id": 1772090,
"author_profile": "https://Stackoverflow.com/users/1772090",
"pm_score": 2,
"selected": false,
"text": "< /dev/zero head -c 1048576 > output\n"
},
{
"answer_id": 18833290,
"author": "devin",
"author_id": 45777,
"author_profile": "https://Stackoverflow.com/users/45777",
"pm_score": 4,
"selected": false,
"text": "/dev/zero"
},
{
"answer_id": 19051306,
"author": "BЈовић",
"author_id": 476681,
"author_profile": "https://Stackoverflow.com/users/476681",
"pm_score": 3,
"selected": false,
"text": " dd if=/dev/zero of=/tmp/zero_big_data_file.bin bs=1M count=20\n"
},
{
"answer_id": 38504877,
"author": "Berkay92",
"author_id": 5291413,
"author_profile": "https://Stackoverflow.com/users/5291413",
"pm_score": 3,
"selected": false,
"text": "base64 /dev/urandom | head -c 4000000 > 4mb.txt\n"
},
{
"answer_id": 59553998,
"author": "qin",
"author_id": 3358215,
"author_profile": "https://Stackoverflow.com/users/3358215",
"pm_score": 3,
"selected": false,
"text": "fallocate"
},
{
"answer_id": 74584789,
"author": "linux.cnf",
"author_id": 10000566,
"author_profile": "https://Stackoverflow.com/users/10000566",
"pm_score": 0,
"selected": false,
"text": "for i in {1..10};do fallocate -l 2G filename$i;done\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139261",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4120/"
] |
139,266
|
<p>When creating an auto updating feature for a .NET WinForms application, how does it update the DLLs and not affect the currently running application?</p>
<p>Since the application is running during the update process, won't there be a lock on the DLLs (because those DLLs will have to be overwritten during the update).</p>
|
[
{
"answer_id": 67638945,
"author": "Lev",
"author_id": 3087417,
"author_profile": "https://Stackoverflow.com/users/3087417",
"pm_score": 0,
"selected": false,
"text": "ProgramFiles\\WindowsApps"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139266",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
139,288
|
<p>what is an efficient way to get a certain time for the next day in Java?
Let's say I want the long for tomorrow 03:30:00.
Setting Calendar fields and Date formatting are obvious.
Better or smarter ideas, thanks for sharing them!</p>
<p>Okami</p>
|
[
{
"answer_id": 139319,
"author": "Brandon DuRette",
"author_id": 17834,
"author_profile": "https://Stackoverflow.com/users/17834",
"pm_score": 2,
"selected": false,
"text": "Date"
},
{
"answer_id": 139349,
"author": "Paul Tomblin",
"author_id": 3333,
"author_profile": "https://Stackoverflow.com/users/3333",
"pm_score": 5,
"selected": true,
"text": "// make it now\nCalendar dateCal = Calendar.getInstance();\n// make it tomorrow\ndateCal.add(Calendar.DAY_OF_YEAR, 1);\n// Now set it to the time you want\ndateCal.set(Calendar.HOUR_OF_DAY, hours);\ndateCal.set(Calendar.MINUTE, minutes);\ndateCal.set(Calendar.SECOND, seconds);\ndateCal.set(Calendar.MILLISECOND, 0);\nreturn dateCal.getTime();\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139288",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11450/"
] |
139,315
|
<p>I'd like to run a script that builds the documentation for my php project. It is basically just using wget to run phpdoc.</p>
|
[
{
"answer_id": 139330,
"author": "RobbieGee",
"author_id": 6752,
"author_profile": "https://Stackoverflow.com/users/6752",
"pm_score": 4,
"selected": false,
"text": "SET BUILDLOG=%~dp0%build_log.html\nrem %~dp0 returns the full working path *of this script*\nSET PHPDOCURL=http://localhost/PHPDocumentor/docbuilder\nSET PHPDOCCONFIG=yourconfigfile\n\nwget -O %BUILDLOG% \"%PHPDOCURL%/builder.php?setting_useconfig=%PHPDOCCONFIG%&setting_output=HTML%3ASmarty%3Adefault&ConverterSetting=HTML%3ASmarty%3Adefault&setting_title=Generated+Documentation&setting_defaultpackagename=default&setting_defaultcategoryname=default&interface=web&dataform=true\"\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139315",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6752/"
] |
139,325
|
<p>How to set all the values in a <code>std::map</code> to the same value, without using a loop iterating over each value? </p>
|
[
{
"answer_id": 139377,
"author": "Konrad Rudolph",
"author_id": 1968,
"author_profile": "https://Stackoverflow.com/users/1968",
"pm_score": 5,
"selected": true,
"text": "for (auto& [_, v] : mymap) v = value;\n"
},
{
"answer_id": 139570,
"author": "ravenspoint",
"author_id": 16582,
"author_profile": "https://Stackoverflow.com/users/16582",
"pm_score": 2,
"selected": false,
"text": "map <int,string> myMap;\nfor( int k=0;k<1000;k++)\n myMap.insert(pair<int,string>(k,string(\"\")));\n"
},
{
"answer_id": 30972901,
"author": "Benjamin Smith",
"author_id": 2715107,
"author_profile": "https://Stackoverflow.com/users/2715107",
"pm_score": 2,
"selected": false,
"text": "#include <boost/range/adaptor/map.hpp>\nauto my_values = boost::adaptors::values(my_map);\nstd::fill(my_values.begin(), my_values.end(), 123);\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139325",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6841/"
] |
139,358
|
<p>In a user defined wizard page, is there a way to capture change or focus events of the controls? I want to provide an immediate feedback on user input in some dropdowns (e.g. a message box)</p>
|
[
{
"answer_id": 139404,
"author": "Otherside",
"author_id": 18697,
"author_profile": "https://Stackoverflow.com/users/18697",
"pm_score": 2,
"selected": false,
"text": "OnEnter"
},
{
"answer_id": 157659,
"author": "Treb",
"author_id": 22114,
"author_profile": "https://Stackoverflow.com/users/22114",
"pm_score": 3,
"selected": true,
"text": "[Code]\n\nvar \n MyCustomPage : TWizardPage;\n\nprocedure MyEditField_OnChange(Sender: TObject);\nbegin\n MsgBox('TEST', mbError, MB_OK);\nend;\n\nfunction MyCustomPage_Create(PreviousPageId: Integer): Integer;\nvar \n MyEditField: TEdit;\nbegin\n MyCustomPage := CreateCustomPage(PreviousPageId, 'Caption', 'Description');\n MyEditField := TEdit.Create(MyCustomPage);\n MyEditField.OnChange := @MyEditField_OnChange;\nend;\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139358",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22114/"
] |
139,365
|
<p>I've begun to use TDD. As mentioned in <a href="https://stackoverflow.com/questions/64333/what-is-the-downside-to-test-driven-development#64402">an earlier question</a> the biggest difficulty is handling interface changes. How do you reduce the impact on your test cases as requirements change?</p>
|
[
{
"answer_id": 139888,
"author": "spiv",
"author_id": 22701,
"author_profile": "https://Stackoverflow.com/users/22701",
"pm_score": 4,
"selected": true,
"text": "def test_add_item_to_order(self):\n acct = Account('Joe', 'Bloggs')\n shipping_addr = Address('123 Elm St', 'etc' 'etc')\n order = Order(acct, shipping_addr)\n item = OrderItem('Purple Widget')\n order.addItem(item)\n self.assertEquals([item], order.items)\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139365",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16496/"
] |
139,368
|
<p>I mean, how does Java decide which protocols are available? I run some code from inside Eclipse, and it works just fine. Then I run the same code from outside Eclipse, and I get "unknown protocol" MalformedURLException. Probably it has to do with the code base, or something? Any hints would be helpful.</p>
<p>Thanks!</p>
|
[
{
"answer_id": 139392,
"author": "sblundy",
"author_id": 4893,
"author_profile": "https://Stackoverflow.com/users/4893",
"pm_score": 2,
"selected": true,
"text": "URLStreamHandler"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139368",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11384/"
] |
139,373
|
<p>For an embedded system I need to place a few data structures at fixed addresses, so that a separate control CPU can access them at a known location. I'm using linker scripts for the embedded target to accomplish this, plus #defines of those same addresses for the control CPU.</p>
<p>It bothers me that these address constants are therefore defined in two places, the linker script and a header file. I'd like to have just one. The best solution I've come up with so far is to have the Makefile run cpp on the linker script, allowing it to #include the same header.</p>
<p>Is there a better way to accomplish this? Is there some little-known option to ld or a naming convention for the linker script which will automatically run it through cpp?</p>
|
[
{
"answer_id": 8413428,
"author": "Olof Forshell",
"author_id": 501673,
"author_profile": "https://Stackoverflow.com/users/501673",
"pm_score": 0,
"selected": false,
"text": "static struct SOMESTRUCT somestruct @ 0x40000000;\nextern int someextint @ 0x3ffffffc;\nchar somebuffer[77] @ 0x80000000;\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139373",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4761/"
] |
139,384
|
<p>I need to calculate averages, standard deviations, medians etc for a bunch of numerical data. Is there a good open source .NET library I can use? I have found NMath but it is not free and may be overkill for my needs.</p>
|
[
{
"answer_id": 161479,
"author": "Mark Heath",
"author_id": 7532,
"author_profile": "https://Stackoverflow.com/users/7532",
"pm_score": 2,
"selected": false,
"text": "/// <summary>\n/// Very basic statistical analysis routines\n/// </summary>\npublic class Statistics\n{\n List<double> numbers;\n public double Sum { get; private set; }\n public double Min { get; private set; }\n public double Max { get; private set; }\n double sumOfSquares;\n\n public Statistics()\n {\n numbers = new List<double>();\n }\n\n public int Count\n {\n get { return numbers.Count; }\n }\n\n public void Add(double number)\n {\n if(Count == 0)\n {\n Min = Max = number;\n }\n numbers.Add(number);\n Sum += number;\n sumOfSquares += number * number;\n Min = Math.Min(Min,number);\n Max = Math.Max(Max,number); \n }\n\n public double Average\n {\n get { return Sum / Count; }\n }\n\n public double StandardDeviation\n {\n get { return Math.Sqrt(sumOfSquares / Count - (Average * Average)); }\n }\n\n /// <summary>\n /// A simplistic implementation of Median\n /// Returns the middle number if there is an odd number of elements (correct)\n /// Returns the number after the midpoint if there is an even number of elements\n /// Sorts the list on every call, so should be optimised for performance if planning\n /// to call lots of times\n /// </summary>\n public double Median\n {\n get\n {\n if (numbers.Count == 0)\n throw new InvalidOperationException(\"Can't calculate the median with no data\");\n numbers.Sort();\n int middleIndex = (Count) / 2;\n return numbers[middleIndex];\n }\n }\n}\n"
},
{
"answer_id": 5086428,
"author": "David Pope",
"author_id": 92789,
"author_profile": "https://Stackoverflow.com/users/92789",
"pm_score": 0,
"selected": false,
"text": "class Program\n{\n static void Main(string[] args)\n {\n using (StreamWriter sw = new StreamWriter(\"output.csv\", false, Encoding.ASCII))\n {\n WriteCsvLine(sw, new List<string>() { \"Name\", \"Length\", \"LastWrite\" });\n\n DirectoryInfo di = new DirectoryInfo(\".\");\n foreach (FileInfo fi in di.GetFiles(\"*.mp3\", SearchOption.AllDirectories))\n {\n List<string> columns = new List<string>();\n columns.Add(fi.Name.Replace(\",\", \"<comma>\"));\n columns.Add(fi.Length.ToString());\n columns.Add(fi.LastWriteTime.Ticks.ToString());\n\n WriteCsvLine(sw, columns);\n }\n }\n }\n\n static void WriteCsvLine(StreamWriter sw, List<string> columns)\n {\n sw.WriteLine(string.Join(\",\", columns.ToArray()));\n }\n}\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139384",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7532/"
] |
139,387
|
<p>OK, I'm not looking for anti-patterns - I'm looking for things that aren't really patterns, or perhaps patterns that have been abused.</p>
<p>My personal least favourite is the "Helper" pattern.</p>
<p>E.g. I need to create a SQL query, so call SQLQueryHelper. This needs to process some strings, so it in turn calls StringHelper. Etc., etc.</p>
<p>See - this isn't really a design pattern at all...</p>
<p>[edit]
Don't you people who vote this down think you should add a constructive remark?</p>
|
[
{
"answer_id": 139488,
"author": "Matt Howells",
"author_id": 16881,
"author_profile": "https://Stackoverflow.com/users/16881",
"pm_score": 4,
"selected": false,
"text": "DataManager\nBusinessLogicManager\nWidgetManager\n"
},
{
"answer_id": 672783,
"author": "Jonas Kölker",
"author_id": 58668,
"author_profile": "https://Stackoverflow.com/users/58668",
"pm_score": 2,
"selected": false,
"text": "ascending = sortBy compare somelist\ndescending = sortBy (flip compare) somelist\npairsBySecondComponent = sortBy (comparing snd) somelist\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139387",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17641/"
] |
139,427
|
<p>Should I stick with Sun's Java code conventions for PHP code?</p>
|
[
{
"answer_id": 12336618,
"author": "Justin",
"author_id": 44026,
"author_profile": "https://Stackoverflow.com/users/44026",
"pm_score": 6,
"selected": false,
"text": "LoggerInterface"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139427",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4235/"
] |
139,474
|
<p>I'd like to capture the output of <a href="http://us3.php.net/manual/en/function.var-dump.php" rel="noreferrer"><code>var_dump</code></a> to a string.</p>
<p>The PHP documentation says;</p>
<blockquote>
<p>As with anything that outputs its result directly to the browser, the <a href="http://us3.php.net/manual/en/ref.outcontrol.php" rel="noreferrer">output-control functions</a> can be used to capture the output of this function, and save it in a string (for example).</p>
</blockquote>
<p>What would be an example of how that might work?</p>
<p><code>print_r()</code> isn't a valid possibility, because it's not going to give me the information that I need.</p>
|
[
{
"answer_id": 139491,
"author": "Eran Galperin",
"author_id": 10585,
"author_profile": "https://Stackoverflow.com/users/10585",
"pm_score": 10,
"selected": true,
"text": "<?php\nob_start();\nvar_dump($someVar);\n$result = ob_get_clean();\n?>\n"
},
{
"answer_id": 139498,
"author": "Ian P",
"author_id": 10853,
"author_profile": "https://Stackoverflow.com/users/10853",
"pm_score": 6,
"selected": false,
"text": "$dump = print_r($variable, true);\n"
},
{
"answer_id": 139553,
"author": "inxilpro",
"author_id": 12549,
"author_profile": "https://Stackoverflow.com/users/12549",
"pm_score": 10,
"selected": false,
"text": "var_export"
},
{
"answer_id": 147343,
"author": "Sergey Stolyarov",
"author_id": 15958,
"author_profile": "https://Stackoverflow.com/users/15958",
"pm_score": 4,
"selected": false,
"text": "serialize()"
},
{
"answer_id": 18085031,
"author": "ZurabWeb",
"author_id": 1016530,
"author_profile": "https://Stackoverflow.com/users/1016530",
"pm_score": 4,
"selected": false,
"text": "echo json_encode($dataobject);"
},
{
"answer_id": 19344690,
"author": "Khandad Niazi",
"author_id": 1842394,
"author_profile": "https://Stackoverflow.com/users/1842394",
"pm_score": 3,
"selected": false,
"text": "function varDumpToString ($var)\n{\n ob_start();\n var_dump($var);\n return ob_get_clean();\n}\n"
},
{
"answer_id": 19890427,
"author": "hanshenrik",
"author_id": 1067003,
"author_profile": "https://Stackoverflow.com/users/1067003",
"pm_score": 4,
"selected": false,
"text": "function return_var_dump(...$args): string\n{\n ob_start();\n try {\n var_dump(...$args);\n return ob_get_clean();\n } catch (\\Throwable $ex) {\n // PHP8 ArgumentCountError for 0 arguments, probably..\n // in php<8 this was just a warning\n ob_end_clean();\n throw $ex;\n }\n}\n"
},
{
"answer_id": 25835613,
"author": "Younis Bensalah",
"author_id": 1322787,
"author_profile": "https://Stackoverflow.com/users/1322787",
"pm_score": 4,
"selected": false,
"text": "var_dump()"
},
{
"answer_id": 28039196,
"author": "Dev C",
"author_id": 4472749,
"author_profile": "https://Stackoverflow.com/users/4472749",
"pm_score": -1,
"selected": false,
"text": "function assignVarDumpValueToString($object) {\n ob_start();\n var_dump($object);\n $result = ob_get_clean();\n return $result;\n}\n"
},
{
"answer_id": 50130617,
"author": "Charlie Vieillard",
"author_id": 2568082,
"author_profile": "https://Stackoverflow.com/users/2568082",
"pm_score": 2,
"selected": false,
"text": "fwrite(fopen('php://stdout', 'w'), var_export($object, true));\n"
},
{
"answer_id": 55884110,
"author": "Wadih M.",
"author_id": 76673,
"author_profile": "https://Stackoverflow.com/users/76673",
"pm_score": 1,
"selected": false,
"text": "var_dump()"
},
{
"answer_id": 57455169,
"author": "vuchkov",
"author_id": 3809048,
"author_profile": "https://Stackoverflow.com/users/3809048",
"pm_score": -1,
"selected": false,
"text": "echo($var);"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139474",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/305/"
] |
139,479
|
<p>How universally is the C99 standard supported in today's compilers? I understand that not even GCC fully supports it. Is this right?</p>
<p>Which features of C99 are supported more than others, i.e. which can I use to be quite sure that most compilers will understand me?</p>
|
[
{
"answer_id": 141497,
"author": "Michael Burr",
"author_id": 12711,
"author_profile": "https://Stackoverflow.com/users/12711",
"pm_score": 4,
"selected": false,
"text": "stdint.h"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139479",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8206/"
] |
139,482
|
<p>Pretty sure this question counts as blasphemy to most web 2.0 proponents, but I do think there are times when you could possibly <em>not</em> want pieces of your site being easily ripped off into someone else's arbitrary web aggregator. At least enough so they'd need to be arsed to do it by hand if they really wanted it.</p>
<p>My idea was to make a script that positioned text nodes by absolute coordinates in the order they'd appear normally within their respective paragraphs, but then stored those text nodes in a random, jumbled up order in the DOM. Of course, getting a system like that to work properly (proper text wrap, alignment, styling, etc.) seems almost akin to writing my own document renderer from scratch.</p>
<p>I was also thinking of combining that with a CAPTCHA-like thing to muss up the text in subtle ways so as to hinder screen scrapers that could simply look at snapshots and discern letters or whatnot. But that's probably overthinking it.</p>
<p>Hmm. Has anyone yet devised any good methods for doing something like this?</p>
|
[
{
"answer_id": 139549,
"author": "Mark Nold",
"author_id": 4134,
"author_profile": "https://Stackoverflow.com/users/4134",
"pm_score": 3,
"selected": true,
"text": "ps10825('4VUknMERbnt0OAP3klgpmjs....abd26')"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139482",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19825/"
] |
139,484
|
<p>I have two (UNIX) programs A and B that read and write from stdin/stdout.</p>
<p>My first problem is how to connect the stdout of A to stdin of B <em>and</em> the stdout of B to the stdin of A. I.e., something like A | B but a bidirectional pipe. I suspect I could solve this by <a href="http://tldp.org/LDP/abs/html/x16834.html" rel="noreferrer">using exec to redirect</a> but I could not get it to work. The programs are interactive so a temporary file would not work.</p>
<p>The second problem is that I would like to duplicate each direction and pipe a duplicate via a logging program to stdout so that I can see the (text-line based) traffic that pass between the programs. Here I may get away with tee >(...) if I can solve the first problem.</p>
<p>Both these problems seems like they should have well known solutions but I have not be able to find anything.</p>
<p>I would prefer a POSIX shell solution, or at least something that works in bash on cygwin.</p>
<p>Thanks to your answers I came up with the following solution. The A/B commands uses nc to listen to two ports. The logging program uses sed (with -u for unbuffered processing).</p>
<pre><code>bash-3.2$ fifodir=$(mktemp -d)
bash-3.2$ mkfifo "$fifodir/echoAtoB"
bash-3.2$ mkfifo "$fifodir/echoBtoA"
bash-3.2$ sed -u 's/^/A->B: /' "$fifodir/echoAtoB" &
bash-3.2$ sed -u 's/^/B->A: /' "$fifodir/echoBtoA" &
bash-3.2$ mkfifo "$fifodir/loopback"
bash-3.2$ nc -l -p 47002 < "$fifodir/loopback" \
| tee "$fifodir/echoAtoB" \
| nc -l -p 47001 \
| tee "$fifodir/echoBtoA" > "$fifodir/loopback"
</code></pre>
<p>This listens for connection to port 47001 and 47002 and echos all traffic to standard output.</p>
<p>In shell 2 do:</p>
<pre><code>bash-3.2$ nc localhost 47001
</code></pre>
<p>In shell 3 do:</p>
<pre><code>bash-3.2$ nc localhost 47002
</code></pre>
<p>Now lines entered in shell 2 will be written to shell 3 and vice versa and the traffic logged to shell 1, something like:</p>
<pre><code>B->A: input to port 47001
A->B: input to port 47002
</code></pre>
<p>The above has been tested on Cygwin</p>
<p>Update: The script above stopped working after a few days(!). Apparently it can deadlock. Some of the suggestions in the answers may be more reliable.</p>
|
[
{
"answer_id": 139518,
"author": "Aaron Maenpaa",
"author_id": 2603,
"author_profile": "https://Stackoverflow.com/users/2603",
"pm_score": 3,
"selected": false,
"text": "mkfifo pipe\ngawk '$1' < pipe | gawk '$1' > pipe\n"
},
{
"answer_id": 139532,
"author": "sherbang",
"author_id": 5026,
"author_profile": "https://Stackoverflow.com/users/5026",
"pm_score": 4,
"selected": false,
"text": "# mkfifo foo\n# A < foo | B > foo\n# rm foo\n"
},
{
"answer_id": 139602,
"author": "Bruno Gomes",
"author_id": 8669,
"author_profile": "https://Stackoverflow.com/users/8669",
"pm_score": 2,
"selected": false,
"text": "#!/usr/bin/expect -f\nspawn proc1\nset proc1 $spawn_id\nspawn proc2\ninteract -u $proc1\n"
},
{
"answer_id": 139629,
"author": "mweerden",
"author_id": 4285,
"author_profile": "https://Stackoverflow.com/users/4285",
"pm_score": 1,
"selected": false,
"text": "/dev/fd/0"
},
{
"answer_id": 527491,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "cmd1 |& cmd2 >&p <&p\n"
},
{
"answer_id": 7911486,
"author": "basicer",
"author_id": 800316,
"author_profile": "https://Stackoverflow.com/users/800316",
"pm_score": 2,
"selected": false,
"text": "#include <stdio.h>\n#include <unistd.h>\n\n#define PERROR_AND_DIE(_x_) {perror(_x_); _exit(1);}\n\nint main(int argc, char **argv) {\n int fd0[2];\n int fd1[2];\n\n\n if ( argc != 3 ) {\n fprintf(stdout, \"Usage %s: \\\"[command 1]\\\" \\\"[command 2]\\\"\\n\", argv[0]);\n _exit(1);\n }\n\n if ( pipe(fd0) || pipe(fd1) ) PERROR_AND_DIE(\"pipe\")\n\n pid_t id = fork();\n if ( id == -1 ) PERROR_AND_DIE(\"fork\");\n\n if ( id ) {\n if ( -1 == close(0) ) PERROR_AND_DIE(\"P1: close 0\");\n if ( -1 == dup2(fd0[0], 0) ) PERROR_AND_DIE(\"P1: dup 0\"); //Read my STDIN from this pipe\n\n if ( -1 == close(1) ) PERROR_AND_DIE(\"P1: close 1\");\n if ( -1 == dup2(fd1[1], 1) ) PERROR_AND_DIE(\"P1: dup 1\"); //Write my STDOUT here\n execl(\"/bin/sh\", \"/bin/sh\", \"-c\", argv[1], NULL);\n PERROR_AND_DIE(\"P1: exec\")\n }\n\n if ( -1 == close(0) ) PERROR_AND_DIE(\"P2: close 0\");\n if ( -1 == dup2(fd1[0], 0) ) PERROR_AND_DIE(\"P2: dup 0\");\n\n if ( -1 == close(1) ) PERROR_AND_DIE(\"P2: close 1\");\n if ( -1 == dup2(fd0[1], 1) ) PERROR_AND_DIE(\"P2: dup 1\");\n\n\n execl(\"/bin/sh\", \"/bin/sh\", \"-c\", argv[2], NULL);\n PERROR_AND_DIE(\"P2: exec\")\n}\n"
},
{
"answer_id": 13626580,
"author": "mmaruska",
"author_id": 890091,
"author_profile": "https://Stackoverflow.com/users/890091",
"pm_score": 0,
"selected": false,
"text": "#! /bin/bash\n# initiator needs argument\n\nif [ $# -gt 0 ]; then\n a=$1\n echo \"Question $a\"\nelse\n read a\nfi\n\nif [ $# -gt 0 ]; then\n read a\n echo \"$a\" >&2\nelse\n echo \"Answer to $a is ...\"\nfi\n\nexit 0\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139484",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22676/"
] |
139,525
|
<p>I have an Xtext/Xpand (oAW 4.3, Eclipse 3.4) generator plug-in, which I run together with the editor plug-in in a second workbench. There, I'd like to run Xpand workflows programmatically on the model file I create. If I set the model file using the absolute path of the IFile I have, e.g. with:</p>
<pre><code>String dslFile = file.getLocation().makeAbsolute().toOSString();
</code></pre>
<p>Or if I use a file URI retrieved with:</p>
<pre><code>String dslFile = file.getLocationURI().toString();
</code></pre>
<p>The file is not found:</p>
<pre><code>org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Resource '/absolute/path/to/my/existing/dsl.file' does not exist.
at org.openarchitectureware.xtext.parser.impl.AbstractParserComponent.invokeInternal(AbstractParserComponent.java:55)
</code></pre>
<p>To what value should I set the model file attribute (dslFile) in the map I hand to the WorkflowRunner:</p>
<pre><code>Map properties = new HashMap();
properties.put("modelFile", dslFile);
</code></pre>
<p>I also tried leaving the properties empty and referencing the model file relative to the workflow file (inside the workflow file), but that yields a FileNotFoundException. Running all of this in a normal app (not in a second workbench) works fine.</p>
|
[
{
"answer_id": 192038,
"author": "Fabian Steeg",
"author_id": 18154,
"author_profile": "https://Stackoverflow.com/users/18154",
"pm_score": 1,
"selected": true,
"text": "properties.put(\"modelFile\", file.getLocation().makeAbsolute().toOSString());\n"
},
{
"answer_id": 3146098,
"author": "Richard Gomes",
"author_id": 62131,
"author_profile": "https://Stackoverflow.com/users/62131",
"pm_score": 0,
"selected": false,
"text": "import gnu.getopt.Getopt;\nimport gnu.getopt.LongOpt;\n\nimport java.io.File;\nimport java.io.IOException;\n\nimport org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher;\n\npublic class Launcher implements Runnable {\n\n //\n // main program\n //\n\n public static void main(final String[] args) {\n new Launcher(args).run();\n }\n\n\n //\n // private final fields\n //\n\n private static final String defaultModelDir = \"src/main/resources/model\";\n private static final String defaultTargetDir = \"target/generated/pageflow-maven-plugin/java\";\n private static final String defaultFileEncoding = \"UTF-8\";\n\n private static final LongOpt[] longopts = new LongOpt[] {\n new LongOpt(\"baseDir\", LongOpt.REQUIRED_ARGUMENT, new StringBuffer(), 'b'),\n new LongOpt(\"modelDir\", LongOpt.REQUIRED_ARGUMENT, new StringBuffer(), 'm'),\n new LongOpt(\"targetDir\", LongOpt.REQUIRED_ARGUMENT, new StringBuffer(), 't'),\n new LongOpt(\"encoding\", LongOpt.REQUIRED_ARGUMENT, new StringBuffer(), 'e'),\n new LongOpt(\"help\", LongOpt.NO_ARGUMENT, null, 'h'),\n new LongOpt(\"verbose\", LongOpt.NO_ARGUMENT, null, 'v'),\n };\n\n\n private final String[] args;\n\n //\n // public constructors\n //\n\n public Launcher(final String[] args) {\n this.args = args;\n }\n\n\n public void run() {\n final String cwd = System.getProperty(\"user.dir\");\n String baseDir = cwd;\n String modelDir = defaultModelDir;\n String targetDir = defaultTargetDir;\n String encoding = defaultFileEncoding;\n boolean verbose = false;\n\n final StringBuffer sb = new StringBuffer();\n final Getopt g = new Getopt(\"pageflow-dsl-generator\", this.args, \"b:m:t:e:hv;\", longopts);\n g.setOpterr(false); // We'll do our own error handling\n int c;\n while ((c = g.getopt()) != -1)\n switch (c) {\n case 'b':\n baseDir = g.getOptarg();\n break;\n case 'm':\n modelDir = g.getOptarg();\n break;\n case 't':\n targetDir = g.getOptarg();\n break;\n case 'e':\n encoding = g.getOptarg();\n break;\n case 'h':\n printUsage();\n System.exit(0);\n break;\n case 'v':\n verbose = true;\n break;\n case '?':\n default:\n System.out.println(\"The option '\" + (char) g.getOptopt() + \"' is not valid\");\n printUsage();\n System.exit(1);\n break;\n }\n\n String absoluteModelDir;\n String absoluteTargetDir;\n\n try {\n absoluteModelDir = checkDir(baseDir, modelDir, false, true);\n absoluteTargetDir = checkDir(baseDir, targetDir, true, true);\n } catch (final IOException e) {\n throw new RuntimeException(e.getMessage(), e.getCause());\n }\n\n if (verbose) {\n System.err.println(String.format(\"modeldir = %s\", absoluteModelDir));\n System.err.println(String.format(\"targetdir = %s\", absoluteTargetDir));\n System.err.println(String.format(\"encoding = %s\", encoding));\n }\n\n Mwe2Launcher.main(\n new String[] {\n \"workflow.PageflowGenerator\",\n \"-p\", \"modelDir=\".concat(absoluteModelDir),\n \"-p\", \"targetDir=\".concat(absoluteTargetDir),\n \"-p\", \"fileEncoding=\".concat(encoding)\n });\n\n }\n\n\n private void printUsage() {\n System.err.println(\"Syntax: [-b <baseDir>] [-m <modelDir>] [-t <targetDir>] [-e <encoding>] [-h] [-v]\");\n System.err.println(\"Options:\");\n System.err.println(\" -b, --baseDir project home directory, e.g: /home/workspace/myapp\");\n System.err.println(\" -m, --modelDir default is: \".concat(defaultModelDir));\n System.err.println(\" -t, --targetDir default is: \".concat(defaultTargetDir));\n System.err.println(\" -e, --encoding default is: \".concat(defaultFileEncoding));\n System.err.println(\" -h, --help this help text\");\n System.err.println(\" -v, --verbose verbose mode\");\n }\n\n private String checkDir(final String basedir, final String dir, final boolean create, final boolean fail) throws IOException {\n final StringBuilder sb = new StringBuilder();\n sb.append(basedir).append('/').append(dir);\n final File f = new File(sb.toString()).getCanonicalFile();\n final String absolutePath = f.getAbsolutePath();\n if (create) {\n if (f.isDirectory()) return absolutePath;\n if (f.mkdirs()) return absolutePath;\n } else {\n if (f.isDirectory()) return absolutePath;\n }\n if (!fail) return null;\n throw new IOException(String.format(\"Failed to locate or create directory %s\", absolutePath));\n }\n\n private String checkFile(final String basedir, final String file, final boolean fail) throws IOException {\n final StringBuilder sb = new StringBuilder();\n sb.append(basedir).append('/').append(file);\n final File f = new File(sb.toString()).getCanonicalFile();\n final String absolutePath = f.getAbsolutePath();\n if (f.isFile()) return absolutePath;\n if (!fail) return null;\n throw new IOException(String.format(\"Failed to find or locate directory %s\", absolutePath));\n }\n\n}\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139525",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18154/"
] |
139,534
|
<p>I've just solved another *I-though-I-was-using-this-version-of-a-library-but-apparently-my-app-server-has-already-loaded-an-older-version-of-this-library-*issue (sigh).</p>
<p>Does anybody know a good way to verify (or monitor) whether your application has access to all the appropriate jar-files, or loaded class-versions?</p>
<p>Thanks in advance!</p>
<p>[P.S. A very good reason to start using the <a href="http://en.wikipedia.org/wiki/OSGi#Architecture" rel="noreferrer">OSGi module architecture</a> in my view!]</p>
<p><strong>Update</strong>: <a href="http://www.jboss.org/community/docs/DOC-9697" rel="noreferrer">This</a> article helped as well! It gave me insight which classes JBoss' classloader loaded by writing it to a log file.</p>
|
[
{
"answer_id": 141969,
"author": "Tom",
"author_id": 22850,
"author_profile": "https://Stackoverflow.com/users/22850",
"pm_score": 5,
"selected": true,
"text": "java -verbose:class"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139534",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9707/"
] |
139,580
|
<p>I'm working on some code for a loosely coupled cluster. To achieve optimal performance during jobs, I have the cluster remap its data each time a child enters or exits. This will eventually be made optional, but for now it performs its data balancing by default. My balancing is basically just making sure that each child never has more than the average number of files per machine, plus one. The plus one is for the remainder if the division isn't clean. And since the remainder will <em>always</em> be less than the number of children [except 0 case, but we can exclude that], children after a balancing will have at most avg + 1.</p>
<p>Everything seems fine, until I realized my algorithm is O(n!). Go down the list of children, find out the avg, remainder, who has too many and who has too few. For each child in the too many list, go through list, send to each child who has too few.</p>
<p>Is there a better solution to this? I feel there must be.</p>
<p>Edit: Here is some psuedocode to show how i derived O(n!):</p>
<pre><code>foreach ( child in children ) {
if ( child.dataLoad > avg + 1 ) {
foreach ( child2 in children ) {
if ( child != child2 && child2.dataLoad < avg ) {
sendLoad(child, child2)
}
}
}
}
</code></pre>
<p>Edit: O(n^2). Foreach n, n => n*n => n^2. I guess I didn't have enough coffee this morning! ;)</p>
<p>In the future I'd like to move to a more flexible and resilient distribution method[weights and hueristics], but for now, a uniform distribution of data works.</p>
|
[
{
"answer_id": 139827,
"author": "Ralph M. Rickenbach",
"author_id": 4549416,
"author_profile": "https://Stackoverflow.com/users/4549416",
"pm_score": 3,
"selected": true,
"text": "for each child in list {\n if child2 == nil then assert(\"Error in logic\");\n while child.workload > avg + 1 {\n sendwork(child, child2, min(avg + 1 - child2.workload, child.workload - (avg + 1)))\n if child2.workload == avg + 1 then child2 = child2.next;\n }\n}\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139580",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8945/"
] |
139,592
|
<p>I've got a generic dictionary <code>Dictionary<string, T></code> that I would like to essentially make a Clone() of ..any suggestions. </p>
|
[
{
"answer_id": 139626,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 8,
"selected": false,
"text": "var newDictionary = oldDictionary.ToDictionary(entry => entry.Key,\n entry => entry.Value);\n"
},
{
"answer_id": 139841,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 9,
"selected": true,
"text": "public static Dictionary<TKey, TValue> CloneDictionaryCloningValues<TKey, TValue>\n (Dictionary<TKey, TValue> original) where TValue : ICloneable\n{\n Dictionary<TKey, TValue> ret = new Dictionary<TKey, TValue>(original.Count,\n original.Comparer);\n foreach (KeyValuePair<TKey, TValue> entry in original)\n {\n ret.Add(entry.Key, (TValue) entry.Value.Clone());\n }\n return ret;\n}\n"
},
{
"answer_id": 140114,
"author": "Compile This",
"author_id": 4048,
"author_profile": "https://Stackoverflow.com/users/4048",
"pm_score": 4,
"selected": false,
"text": "Dictionary"
},
{
"answer_id": 140279,
"author": "Shaun Bowe",
"author_id": 1514,
"author_profile": "https://Stackoverflow.com/users/1514",
"pm_score": 3,
"selected": false,
"text": "object deepcopy = FromBinary(ToBinary(yourDictionary));\n\npublic Byte[] ToBinary()\n{\n MemoryStream ms = null;\n Byte[] byteArray = null;\n try\n {\n BinaryFormatter serializer = new BinaryFormatter();\n ms = new MemoryStream();\n serializer.Serialize(ms, this);\n byteArray = ms.ToArray();\n }\n catch (Exception unexpected)\n {\n Trace.Fail(unexpected.Message);\n throw;\n }\n finally\n {\n if (ms != null)\n ms.Close();\n }\n return byteArray;\n}\n\npublic object FromBinary(Byte[] buffer)\n{\n MemoryStream ms = null;\n object deserializedObject = null;\n\n try\n {\n BinaryFormatter serializer = new BinaryFormatter();\n ms = new MemoryStream();\n ms.Write(buffer, 0, buffer.Length);\n ms.Position = 0;\n deserializedObject = serializer.Deserialize(ms);\n }\n finally\n {\n if (ms != null)\n ms.Close();\n }\n return deserializedObject;\n}\n"
},
{
"answer_id": 1499136,
"author": "loty",
"author_id": 181952,
"author_profile": "https://Stackoverflow.com/users/181952",
"pm_score": 2,
"selected": false,
"text": "Dictionary<string , List<double>>"
},
{
"answer_id": 4265943,
"author": "Herald Smit",
"author_id": 518635,
"author_profile": "https://Stackoverflow.com/users/518635",
"pm_score": 7,
"selected": false,
"text": "Dictionary<string, int> dictionary = new Dictionary<string, int>();\n\nDictionary<string, int> copy = new Dictionary<string, int>(dictionary);\n"
},
{
"answer_id": 32451470,
"author": "nikssa23",
"author_id": 1080516,
"author_profile": "https://Stackoverflow.com/users/1080516",
"pm_score": 3,
"selected": false,
"text": "Dictionary<int, int> copy= new Dictionary<int, int>(yourListOrDictionary);\n"
},
{
"answer_id": 39109022,
"author": "Arvind",
"author_id": 2766943,
"author_profile": "https://Stackoverflow.com/users/2766943",
"pm_score": 0,
"selected": false,
"text": " public static Dictionary<K,V> CloneDictionary<K,V>(Dictionary<K,V> dict) where K : ICloneable where V : ICloneable\n {\n Dictionary<K, V> newDict = null;\n\n if (dict != null)\n {\n // If the key and value are value types, just use copy constructor.\n if (((typeof(K).IsValueType || typeof(K) == typeof(string)) &&\n (typeof(V).IsValueType) || typeof(V) == typeof(string)))\n {\n newDict = new Dictionary<K, V>(dict);\n }\n else // prepare to clone key or value or both\n {\n newDict = new Dictionary<K, V>();\n\n foreach (KeyValuePair<K, V> kvp in dict)\n {\n K key;\n if (typeof(K).IsValueType || typeof(K) == typeof(string))\n {\n key = kvp.Key;\n }\n else\n {\n key = (K)kvp.Key.Clone();\n }\n V value;\n if (typeof(V).IsValueType || typeof(V) == typeof(string))\n {\n value = kvp.Value;\n }\n else\n {\n value = (V)kvp.Value.Clone();\n }\n\n newDict[key] = value;\n }\n }\n }\n\n return newDict;\n }\n"
},
{
"answer_id": 49430077,
"author": "BonifatiusK",
"author_id": 1613529,
"author_profile": "https://Stackoverflow.com/users/1613529",
"pm_score": 3,
"selected": false,
"text": " // assuming this fills the List\n List<Dictionary<string, string>> obj = this.getData(); \n\n List<Dictionary<string, string>> objCopy = new List<Dictionary<string, string>>(obj);\n"
},
{
"answer_id": 61707825,
"author": "peter feldman",
"author_id": 5738262,
"author_profile": "https://Stackoverflow.com/users/5738262",
"pm_score": 5,
"selected": false,
"text": "Dictionary<string, string> dict2 = new Dictionary<string, string>(dict);\n"
},
{
"answer_id": 64354962,
"author": "MSA",
"author_id": 4924495,
"author_profile": "https://Stackoverflow.com/users/4924495",
"pm_score": 0,
"selected": false,
"text": "Dictionary<string, object> dictSrc { get; set; }\n\npublic class ComplexClass : ICloneable\n{\n \n private Point3D ...;\n private Vector3D ....;\n [...]\n\n public object Clone()\n {\n ComplexClass clone = new ComplexClass();\n clone = (ComplexClass)this.MemberwiseClone();\n return clone;\n }\n\n}\n\n\ndictSrc[\"toto\"] = new ComplexClass()\ndictSrc[\"tata\"] = 12.3\n...\n\ndictDest = dictSrc.ToDictionary(entry => entry.Key,\n entry => ((entry.Value is ICloneable) ? (entry.Value as ICloneable).Clone() : entry.Value) );\n\n\n"
},
{
"answer_id": 69558172,
"author": "Sariato",
"author_id": 14407593,
"author_profile": "https://Stackoverflow.com/users/14407593",
"pm_score": 0,
"selected": false,
"text": "Dictionary<string, Dictionary<string, dynamic>> buildInfoDict =\n new Dictionary<string, Dictionary<string, dynamic>>()\n {\n {\"tag\",new Dictionary<string,dynamic>(){\n { \"attrName\", \"tag\" },\n { \"isCss\", \"False\" },\n { \"turnedOn\",\"True\" },\n { \"tag\",null }\n } },\n {\"id\",new Dictionary<string,dynamic>(){\n { \"attrName\", \"id\" },\n { \"isCss\", \"False\" },\n { \"turnedOn\",\"True\" },\n { \"id\",null }\n } },\n {\"width\",new Dictionary<string,dynamic>(){\n { \"attrName\", \"width\" },\n { \"isCss\", \"True\" },\n { \"turnedOn\",\"True\" },\n { \"width\",\"20%\" }\n } },\n {\"height\",new Dictionary<string,dynamic>(){\n { \"attrName\", \"height\" },\n { \"isCss\", \"True\" },\n { \"turnedOn\",\"True\" },\n { \"height\",\"20%\" }\n } },\n {\"text\",new Dictionary<string,dynamic>(){\n { \"attrName\", null },\n { \"isCss\", \"False\" },\n { \"turnedOn\",\"True\" },\n { \"text\",\"\" }\n } },\n {\"href\",new Dictionary<string,dynamic>(){\n { \"attrName\", null },\n { \"isCss\", \"False\" },\n { \"flags\", \"removeAttrIfTurnedOff\" },\n { \"turnedOn\",\"True\" },\n { \"href\",\"about:blank\" }\n } }\n };\n\nvar cln=clone(buildInfoDict);\n\npublic static dynamic clone(dynamic obj)\n{\n dynamic cloneObj = null;\n if (IsAssignableFrom(obj, typeof(IDictionary)))\n {\n cloneObj = Activator.CreateInstance(obj.GetType());\n foreach (var key in obj.Keys)\n {\n cloneObj[key] = clone(obj[key]);\n }\n\n }\n else if (IsNumber(obj) || obj.GetType() == typeof(string))\n {\n cloneObj = obj;\n }\n else\n {\n Debugger.Break();\n }\n return cloneObj;\n}\n\n\npublic static bool IsAssignableFrom(this object obj, Type ObjType = null, Type ListType = null, bool HandleBaseTypes = false)\n{\n if (ObjType == null)\n {\n ObjType = obj.GetType();\n }\n\n bool Res;\n\n do\n {\n Res = (ObjType.IsGenericType && ObjType.GetGenericTypeDefinition().IsAssignableFrom(ListType)) ||\n (ListType == null && ObjType.IsAssignableFrom(obj.GetType()));\n ObjType = ObjType.BaseType;\n } while ((!Res && ObjType != null) && HandleBaseTypes && ObjType != typeof(object));\n\n return Res;\n}\n\npublic static bool IsNumber(this object value)\n{\n return value is sbyte\n || value is byte\n || value is short\n || value is ushort\n || value is int\n || value is uint\n || value is long\n || value is ulong\n || value is float\n || value is double\n || value is decimal;\n}\n"
},
{
"answer_id": 71386057,
"author": "Paul Yao",
"author_id": 4425192,
"author_profile": "https://Stackoverflow.com/users/4425192",
"pm_score": 0,
"selected": false,
"text": "internal static Dictionary<string, object> Clone(Dictionary<string, object> dictIn) \n {\n Dictionary<string, object> dictOut = new Dictionary<string, object>();\n \n IDictionaryEnumerator enumMyDictionary = dictIn.GetEnumerator();\n while (enumMyDictionary.MoveNext())\n {\n string strKey = (string)enumMyDictionary.Key;\n object oValue = enumMyDictionary.Value;\n dictOut.Add(strKey, oValue);\n }\n \n return dictOut; \n }\n"
},
{
"answer_id": 71985784,
"author": "schwartz",
"author_id": 6414026,
"author_profile": "https://Stackoverflow.com/users/6414026",
"pm_score": 0,
"selected": false,
"text": " private static IDictionary<string, T> Copy<T>(this IDictionary<string, T> dict)\n where T : ICloneable\n {\n if (typeof(T).IsValueType)\n {\n return new Dictionary<string, T>(dict);\n }\n else\n {\n var copy = new Dictionary<string, T>();\n foreach (var pair in dict)\n {\n copy[pair.Key] = pair.Value;\n }\n return copy;\n }\n }\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139592",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4398/"
] |
139,593
|
<p>I have the following code:</p>
<pre><code>info = new System.Diagnostics.ProcessStartInfo("TheProgram.exe", String.Join(" ", args));
info.CreateNoWindow = true;
info.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
info.RedirectStandardOutput = true;
info.UseShellExecute = false;
System.Diagnostics.Process p = System.Diagnostics.Process.Start(info);
p.WaitForExit();
Console.WriteLine(p.StandardOutput.ReadToEnd()); //need the StandardOutput contents
</code></pre>
<p>I know that the output from the process I am starting is around 7MB long. Running it in the Windows console works fine. Unfortunately programmatically this hangs indefinitely at <code>WaitForExit</code>. Note also this code does NOT hang for smaller outputs (like 3KB).</p>
<p>Is it possible that the internal <code>StandardOutput</code> in <code>ProcessStartInfo</code> can't buffer 7MB? If so, what should I do instead? If not, what am I doing wrong?</p>
|
[
{
"answer_id": 139604,
"author": "Rob",
"author_id": 7872,
"author_profile": "https://Stackoverflow.com/users/7872",
"pm_score": 7,
"selected": false,
"text": "Process.StandardOutput"
},
{
"answer_id": 5441188,
"author": "song",
"author_id": 677841,
"author_profile": "https://Stackoverflow.com/users/677841",
"pm_score": -1,
"selected": false,
"text": "p.StartInfo.RedirectStandardoutput = False\np.StartInfo.RedirectStandarderror = False\n"
},
{
"answer_id": 7608823,
"author": "Mark Byers",
"author_id": 61974,
"author_profile": "https://Stackoverflow.com/users/61974",
"pm_score": 10,
"selected": true,
"text": "StandardOutput"
},
{
"answer_id": 10086961,
"author": "stevejay",
"author_id": 604006,
"author_profile": "https://Stackoverflow.com/users/604006",
"pm_score": 5,
"selected": false,
"text": "OutputDataReceived"
},
{
"answer_id": 11035292,
"author": "Kuzman Marinov",
"author_id": 1456498,
"author_profile": "https://Stackoverflow.com/users/1456498",
"pm_score": 1,
"selected": false,
"text": "AutoResetEvent"
},
{
"answer_id": 22956924,
"author": "Karol Tyl",
"author_id": 1343408,
"author_profile": "https://Stackoverflow.com/users/1343408",
"pm_score": 4,
"selected": false,
"text": "if (process.WaitForExit(timeout) \n && outputWaitHandle.WaitOne(timeout) \n && errorWaitHandle.WaitOne(timeout))\n"
},
{
"answer_id": 27920086,
"author": "Marcell",
"author_id": 4090002,
"author_profile": "https://Stackoverflow.com/users/4090002",
"pm_score": -1,
"selected": false,
"text": "pProcess.StartInfo.UseShellExecute = False\n"
},
{
"answer_id": 32457135,
"author": "Elina Maliarsky",
"author_id": 5257482,
"author_profile": "https://Stackoverflow.com/users/5257482",
"pm_score": 2,
"selected": false,
"text": " Process proc = new Process();\n proc.StartInfo.FileName = batchFile;\n proc.StartInfo.UseShellExecute = false;\n proc.StartInfo.CreateNoWindow = true;\n proc.StartInfo.RedirectStandardError = true;\n proc.StartInfo.RedirectStandardInput = true;\n proc.StartInfo.RedirectStandardOutput = true;\n proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; \n proc.Start();\n StreamWriter streamWriter = proc.StandardInput;\n StreamReader outputReader = proc.StandardOutput;\n StreamReader errorReader = proc.StandardError;\n while (!outputReader.EndOfStream)\n {\n string text = outputReader.ReadLine(); \n streamWriter.WriteLine(text);\n }\n\n while (!errorReader.EndOfStream)\n { \n string text = errorReader.ReadLine();\n streamWriter.WriteLine(text);\n }\n\n streamWriter.Close();\n proc.WaitForExit();\n"
},
{
"answer_id": 34687299,
"author": "Jon",
"author_id": 3072057,
"author_profile": "https://Stackoverflow.com/users/3072057",
"pm_score": 3,
"selected": false,
"text": "// Read the output stream first and then wait.\nstring output = p.StandardOutput.ReadToEnd();\np.WaitForExit();\n"
},
{
"answer_id": 39872058,
"author": "Muhammad Rehan Saeed",
"author_id": 1212017,
"author_profile": "https://Stackoverflow.com/users/1212017",
"pm_score": 5,
"selected": false,
"text": "try\n{\n var exitCode = await StartProcess(\n \"dotnet\", \n \"--version\", \n @\"C:\\\",\n 10000, \n Console.Out, \n Console.Out);\n Console.WriteLine($\"Process Exited with Exit Code {exitCode}!\");\n}\ncatch (TaskCanceledException)\n{\n Console.WriteLine(\"Process Timed Out!\");\n}\n"
},
{
"answer_id": 41722847,
"author": "Eric Ouellet",
"author_id": 452845,
"author_profile": "https://Stackoverflow.com/users/452845",
"pm_score": 2,
"selected": false,
"text": "process.Start(); \n// Here the operating system could give the cpu to another thread. \n// For example, the newly created thread (Process) and it could start writing to the output\n// immediately before next line would execute. \n// That create a race condition.\nprocess.BeginOutputReadLine();\n"
},
{
"answer_id": 42140736,
"author": "omriman12",
"author_id": 2338687,
"author_profile": "https://Stackoverflow.com/users/2338687",
"pm_score": 1,
"selected": false,
"text": "public void GetProcessOutputWithTimeout(Process process, int timeoutSec, CancellationToken token, out string output, out int exitCode)\n{\n string outputLocal = \"\"; int localExitCode = -1;\n var task = System.Threading.Tasks.Task.Factory.StartNew(() =>\n {\n outputLocal = process.StandardOutput.ReadToEnd();\n process.WaitForExit();\n localExitCode = process.ExitCode;\n }, token);\n\n if (task.Wait(timeoutSec, token))\n {\n output = outputLocal;\n exitCode = localExitCode;\n }\n else\n {\n exitCode = -1;\n output = \"\";\n }\n}\n\nusing (var process = new Process())\n{\n process.StartInfo = ...;\n process.Start();\n string outputUnicode; int exitCode;\n GetProcessOutputWithTimeout(process, PROCESS_TIMEOUT, out outputUnicode, out exitCode);\n}\n"
},
{
"answer_id": 43211575,
"author": "Marko Avlijaš",
"author_id": 5712410,
"author_profile": "https://Stackoverflow.com/users/5712410",
"pm_score": 1,
"selected": false,
"text": " private bool Run(string fullCommand)\n {\n Error = \"\";\n int timeout = 5000;\n\n var result = ProcessNoBS.Start(\n filename: @\"C:\\Program Files\\Git\\cmd\\git.exe\",\n arguments: fullCommand,\n timeoutInMs: timeout,\n workingDir: @\"C:\\test\");\n\n if (result.hasTimedOut)\n {\n Error = String.Format(\"Timeout ({0} sec)\", timeout/1000);\n return false;\n }\n\n if (result.ExitCode != 0)\n {\n Error = (String.IsNullOrWhiteSpace(result.stderr)) \n ? result.stdout : result.stderr;\n return false;\n }\n\n return true;\n }\n"
},
{
"answer_id": 44428790,
"author": "Alexis Coles",
"author_id": 960750,
"author_profile": "https://Stackoverflow.com/users/960750",
"pm_score": 1,
"selected": false,
"text": " StreamWriter sw = null;\n var queue = new ConcurrentQueue<string>();\n\n var flushTask = new System.Timers.Timer(50);\n flushTask.Elapsed += (s, e) =>\n {\n while (!queue.IsEmpty)\n {\n string line = null;\n if (queue.TryDequeue(out line))\n sw.WriteLine(line);\n }\n sw.FlushAsync();\n };\n flushTask.Start();\n\n using (var process = new Process())\n {\n try\n {\n process.StartInfo.FileName = @\"...\";\n process.StartInfo.Arguments = $\"...\";\n process.StartInfo.UseShellExecute = false;\n process.StartInfo.RedirectStandardOutput = true;\n process.StartInfo.RedirectStandardError = true;\n\n process.Start();\n\n var outputRead = Task.Run(() =>\n {\n while (!process.StandardOutput.EndOfStream)\n {\n queue.Enqueue(process.StandardOutput.ReadLine());\n }\n });\n\n var errorRead = Task.Run(() =>\n {\n while (!process.StandardError.EndOfStream)\n {\n queue.Enqueue(process.StandardError.ReadLine());\n }\n });\n\n var timeout = new TimeSpan(hours: 0, minutes: 10, seconds: 0);\n\n if (Task.WaitAll(new[] { outputRead, errorRead }, timeout) &&\n process.WaitForExit((int)timeout.TotalMilliseconds))\n {\n if (process.ExitCode != 0)\n {\n throw new Exception($\"Failed run... blah blah\");\n }\n }\n else\n {\n throw new Exception($\"process timed out after waiting {timeout}\");\n }\n }\n catch (Exception e)\n {\n throw new Exception($\"Failed to succesfully run the process.....\", e);\n }\n }\n }\n"
},
{
"answer_id": 47213952,
"author": "ergohack",
"author_id": 4151626,
"author_profile": "https://Stackoverflow.com/users/4151626",
"pm_score": 3,
"selected": false,
"text": "Process p = new Process()\n{\n StartInfo = new ProcessStartInfo()\n {\n FileName = exe,\n Arguments = args,\n UseShellExecute = false,\n RedirectStandardOutput = true,\n RedirectStandardError = true\n }\n};\np.Start();\n\nstring cv_error = null;\nThread et = new Thread(() => { cv_error = p.StandardError.ReadToEnd(); });\net.Start();\n\nstring cv_out = null;\nThread ot = new Thread(() => { cv_out = p.StandardOutput.ReadToEnd(); });\not.Start();\n\np.WaitForExit();\not.Join();\net.Join();\n"
},
{
"answer_id": 53504707,
"author": "Yepeekai",
"author_id": 413464,
"author_profile": "https://Stackoverflow.com/users/413464",
"pm_score": 2,
"selected": false,
"text": "using (Process process = new Process())\n{\n process.StartInfo.FileName = filename;\n process.StartInfo.Arguments = arguments;\n process.StartInfo.UseShellExecute = false;\n process.StartInfo.RedirectStandardOutput = true;\n process.StartInfo.RedirectStandardError = true;\n\n process.Start();\n\n var tStandardOutput = process.StandardOutput.ReadToEndAsync();\n var tStandardError = process.StandardError.ReadToEndAsync();\n\n if (process.WaitForExit(timeout))\n {\n string output = await tStandardOutput;\n string errors = await tStandardError;\n\n // Process completed. Check process.ExitCode here.\n }\n else\n {\n // Timed out.\n }\n}\n"
},
{
"answer_id": 54191042,
"author": "Sam Hobbs",
"author_id": 2392247,
"author_profile": "https://Stackoverflow.com/users/2392247",
"pm_score": -1,
"selected": false,
"text": "StreamReader stream = null;\ntry { stream = new StreamReader(Path); }\ncatch (Exception ex)\n{\n Console.Error.WriteLine(\"Input open error: \" + ex.Message);\n return;\n}\nConsole.SetIn(stream);\nint datasize = 0;\ntry\n{\n string record = Console.ReadLine();\n while (record != null)\n {\n datasize += record.Length + 2;\n record = Console.ReadLine();\n Console.WriteLine(record);\n }\n}\ncatch (Exception ex)\n{\n Console.Error.WriteLine($\"Error: {ex.Message}\");\n return;\n}\n"
},
{
"answer_id": 56490740,
"author": "eglasius",
"author_id": 66372,
"author_profile": "https://Stackoverflow.com/users/66372",
"pm_score": 1,
"selected": false,
"text": "var outputFile = Path.GetTempFileName();\ninfo = new System.Diagnostics.ProcessStartInfo(\"TheProgram.exe\", String.Join(\" \", args) + \" > \" + outputFile + \" 2>&1\");\ninfo.CreateNoWindow = true;\ninfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;\ninfo.UseShellExecute = false;\nSystem.Diagnostics.Process p = System.Diagnostics.Process.Start(info);\np.WaitForExit();\nConsole.WriteLine(File.ReadAllText(outputFile)); //need the StandardOutput contents\n"
},
{
"answer_id": 57940402,
"author": "Deepscorn",
"author_id": 884195,
"author_profile": "https://Stackoverflow.com/users/884195",
"pm_score": 1,
"selected": false,
"text": "private static int DoProcess(string workingDir, string fileName, string arguments)\n{\n int exitCode;\n using (var process = new Process\n {\n StartInfo =\n {\n WorkingDirectory = workingDir,\n WindowStyle = ProcessWindowStyle.Hidden,\n CreateNoWindow = true,\n UseShellExecute = false,\n FileName = fileName,\n Arguments = arguments,\n RedirectStandardError = true,\n RedirectStandardOutput = true\n },\n EnableRaisingEvents = true\n })\n {\n using (var outputWaitHandle = new AutoResetEvent(false))\n using (var errorWaitHandle = new AutoResetEvent(false))\n {\n process.OutputDataReceived += (sender, args) =>\n {\n // ReSharper disable once AccessToDisposedClosure\n if (args.Data != null) Debug.Log(args.Data);\n else outputWaitHandle.Set();\n };\n process.ErrorDataReceived += (sender, args) =>\n {\n // ReSharper disable once AccessToDisposedClosure\n if (args.Data != null) Debug.LogError(args.Data);\n else errorWaitHandle.Set();\n };\n\n process.Start();\n process.BeginOutputReadLine();\n process.BeginErrorReadLine();\n\n WaitHandle.WaitAll(new WaitHandle[] { outputWaitHandle, errorWaitHandle });\n\n exitCode = process.ExitCode;\n }\n }\n return exitCode;\n}\n"
},
{
"answer_id": 73454991,
"author": "Koby Douek",
"author_id": 1694368,
"author_profile": "https://Stackoverflow.com/users/1694368",
"pm_score": 0,
"selected": false,
"text": "string result = process.StandardOutput.ReadToEnd();\nstring error = process.StandardError.ReadToEnd();\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139593",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6583/"
] |
139,605
|
<p>How can I find out whether a specific RedHat release (RHEL4, RHEL5...) contains a certain package (or a certain version of a package)? For Debian and Ubuntu, there's packages.debian.org and packages.ubuntu.com; is there a similar web site for RedHat?</p>
<p>Note: I don't want to have to install all the releases just to check some package version :-)</p>
|
[
{
"answer_id": 4140439,
"author": "MarcH",
"author_id": 317623,
"author_profile": "https://Stackoverflow.com/users/317623",
"pm_score": 0,
"selected": false,
"text": "rsync://"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139605",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2148773/"
] |
139,607
|
<p>I've seen both done in some code I'm maintaining, but don't know the difference. Is there one?</p>
<p>let me add that myCustomer is an instance of Customer</p>
|
[
{
"answer_id": 139611,
"author": "Kilhoffer",
"author_id": 5469,
"author_profile": "https://Stackoverflow.com/users/5469",
"pm_score": 8,
"selected": true,
"text": "System.Type"
},
{
"answer_id": 139615,
"author": "Jakub Šturc",
"author_id": 2361,
"author_profile": "https://Stackoverflow.com/users/2361",
"pm_score": 4,
"selected": false,
"text": "class VipCustomer : Customer\n{\n .....\n}\n\nstatic void Main()\n{\n Customer c = new VipCustomer();\n c.GetType(); // returns typeof(VipCustomer)\n}\n"
},
{
"answer_id": 139781,
"author": "FlySwat",
"author_id": 1965,
"author_profile": "https://Stackoverflow.com/users/1965",
"pm_score": 3,
"selected": false,
"text": "public class foo\n{\n}\n\npublic class bar : foo\n{\n}\n\nbar myBar = new bar();\n\n// Would fail, even though bar is a child of foo.\nif (myBar.getType == typeof(foo))\n\n// However this Would work\nif (myBar is foo)\n"
},
{
"answer_id": 141879,
"author": "David Pokluda",
"author_id": 223,
"author_profile": "https://Stackoverflow.com/users/223",
"pm_score": 2,
"selected": false,
"text": "public Type WhoAreYou(Base base)\n{\n base.GetType();\n}\n"
},
{
"answer_id": 18982810,
"author": "Praveen Kumar",
"author_id": 2811254,
"author_profile": "https://Stackoverflow.com/users/2811254",
"pm_score": 1,
"selected": false,
"text": "class BaseClass\n{ }\n\nclass DerivedClass : BaseClass\n{ }\n\nclass FinalClass\n{\n static void RevealType(BaseClass baseCla)\n {\n Console.WriteLine(typeof(BaseClass)); // compile time\n Console.WriteLine(baseCla.GetType()); // run time\n }\n\n static void Main(string[] str)\n {\n RevealType(new BaseClass());\n\n Console.ReadLine();\n }\n}\n// ********* By Praveen Kumar Srivastava \n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139607",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18931/"
] |
139,623
|
<p>How do I cause the page to make the user jump to a new web page after X seconds. If possible I'd like to use HTML but a niggly feeling tells me it'll have to be Javascript.</p>
<p>So far I have the following but it has no time delay</p>
<pre><code><body onload="document.location='newPage.html'">
</code></pre>
|
[
{
"answer_id": 139660,
"author": "slashnick",
"author_id": 21030,
"author_profile": "https://Stackoverflow.com/users/21030",
"pm_score": 5,
"selected": true,
"text": "<meta http-equiv=\"refresh\" content=\"5;url=http://example.com/\"/>\n"
},
{
"answer_id": 139661,
"author": "hubbardr",
"author_id": 22457,
"author_profile": "https://Stackoverflow.com/users/22457",
"pm_score": 1,
"selected": false,
"text": "<meta http-equiv=\"refresh\" content=\"5;url=newPage.html\">\n"
},
{
"answer_id": 139680,
"author": "Jason Z",
"author_id": 2470,
"author_profile": "https://Stackoverflow.com/users/2470",
"pm_score": 2,
"selected": false,
"text": "setTimeout(\"window.location.href = 'newPage.html';\", 5000);\n"
},
{
"answer_id": 139740,
"author": "Huuuze",
"author_id": 10040,
"author_profile": "https://Stackoverflow.com/users/10040",
"pm_score": 1,
"selected": false,
"text": "<body onload=\"setTimeout('window.location = \\'newpage.html\\'', 5000)\">\n"
},
{
"answer_id": 141456,
"author": "Andrew Hedges",
"author_id": 11577,
"author_profile": "https://Stackoverflow.com/users/11577",
"pm_score": 0,
"selected": false,
"text": "eval"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139623",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1384652/"
] |
139,630
|
<p>What's the difference between <code>TRUNCATE</code> and <code>DELETE</code> in SQL?</p>
<p>If your answer is platform specific, please indicate that.</p>
|
[
{
"answer_id": 139633,
"author": "David Aldridge",
"author_id": 6742,
"author_profile": "https://Stackoverflow.com/users/6742",
"pm_score": 9,
"selected": true,
"text": "DELETE"
},
{
"answer_id": 139877,
"author": "polara",
"author_id": 8754,
"author_profile": "https://Stackoverflow.com/users/8754",
"pm_score": 5,
"selected": false,
"text": "TRUNCATE TABLE"
},
{
"answer_id": 143811,
"author": "CaptainPicard",
"author_id": 15203,
"author_profile": "https://Stackoverflow.com/users/15203",
"pm_score": 2,
"selected": false,
"text": "SQL> delete from t1;\n\n10918 rows deleted.\n\nElapsed: 00:00:00.58\n\nExecution Plan\n----------------------------------------------------------\n 0 DELETE STATEMENT Optimizer=FIRST_ROWS (Cost=43 Card=1)\n 1 0 DELETE OF 'T1'\n 2 1 TABLE ACCESS (FULL) OF 'T1' (TABLE) (Cost=43 Card=1)\n\n\n\n\nStatistics\n----------------------------------------------------------\n 30 recursive calls\n 12118 db block gets\n 213 consistent gets\n 142 physical reads\n 3975328 redo size\n 441 bytes sent via SQL*Net to client\n 537 bytes received via SQL*Net from client\n 4 SQL*Net roundtrips to/from client\n 2 sorts (memory)\n 0 sorts (disk)\n 10918 rows processed\n"
},
{
"answer_id": 1873309,
"author": "Sachin Chourasiya",
"author_id": 184862,
"author_profile": "https://Stackoverflow.com/users/184862",
"pm_score": 4,
"selected": false,
"text": "TRUNCATE"
},
{
"answer_id": 12900557,
"author": "Bhaumik Patel",
"author_id": 1218422,
"author_profile": "https://Stackoverflow.com/users/1218422",
"pm_score": 8,
"selected": false,
"text": "+----------------------------------------+----------------------------------------------+\n| Truncate | Delete |\n+----------------------------------------+----------------------------------------------+\n| We can't Rollback after performing | We can Rollback after delete. |\n| Truncate. | |\n| | |\n| Example: | Example: |\n| BEGIN TRAN | BEGIN TRAN |\n| TRUNCATE TABLE tranTest | DELETE FROM tranTest |\n| SELECT * FROM tranTest | SELECT * FROM tranTest |\n| ROLLBACK | ROLLBACK |\n| SELECT * FROM tranTest | SELECT * FROM tranTest |\n+----------------------------------------+----------------------------------------------+\n| Truncate reset identity of table. | Delete does not reset identity of table. |\n+----------------------------------------+----------------------------------------------+\n| It locks the entire table. | It locks the table row. |\n+----------------------------------------+----------------------------------------------+\n| Its DDL(Data Definition Language) | Its DML(Data Manipulation Language) |\n| command. | command. |\n+----------------------------------------+----------------------------------------------+\n| We can't use WHERE clause with it. | We can use WHERE to filter data to delete. |\n+----------------------------------------+----------------------------------------------+\n| Trigger is not fired while truncate. | Trigger is fired. |\n+----------------------------------------+----------------------------------------------+\n| Syntax : | Syntax : |\n| 1) TRUNCATE TABLE table_name | 1) DELETE FROM table_name |\n| | 2) DELETE FROM table_name WHERE |\n| | example_column_id IN (1,2,3) |\n+----------------------------------------+----------------------------------------------+\n"
},
{
"answer_id": 18673219,
"author": "user27332",
"author_id": 2704077,
"author_profile": "https://Stackoverflow.com/users/2704077",
"pm_score": 2,
"selected": false,
"text": "DELETE is a DML command\nDELETE you can rollback\nDelete = Only Delete- so it can be rolled back\nIn DELETE you can write conditions using WHERE clause\nSyntax – Delete from [Table] where [Condition]\n"
},
{
"answer_id": 25032124,
"author": "Vinay Pandit",
"author_id": 3890653,
"author_profile": "https://Stackoverflow.com/users/3890653",
"pm_score": 0,
"selected": false,
"text": "begin Tran\ndelete from Employee\n\nselect * from Employee\nRollback\nselect * from Employee\n"
},
{
"answer_id": 43488613,
"author": "Mykhailo Seniutovych",
"author_id": 7111692,
"author_profile": "https://Stackoverflow.com/users/7111692",
"pm_score": 0,
"selected": false,
"text": "delete"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139630",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6742/"
] |
139,639
|
<p>I am working with Reporting Services and Sharepoint, I have an application that leverages reporting services however a client would like our application integrated into sharepoint. Currently we are tightly coupled to the ReportService.asmx webservice which exposes various methods for performing operations. Reporting Services has something called "Sharepoint Integration mode" when enabled the report server works differently and Sharepoint is used to manage the reports. Sharepoint adds a new web service called ReportService2006.asmx which is almost exactly the same. </p>
<p>Now our application uses a web reference to the ReportService and uses various objects exposed by the service. ReportService2006 has exactly the same objects but they are obviously in a different namespace e.g I have 2 web references - 1 to each service so there is an object MyApplication.ReportService.CatalogItem and another MyApplication.ReportService2006.CatalogItem.</p>
<p>I've tried to use dependency injection to absract the Service out of our application coupled with a factory pattern to determine which implementation of my interface to instantiate. Heres my interface. I've simplified it to include only the calls I need for this application.</p>
<pre><code>using System;
using NetworkUserEncrypt.ReportService;
namespace MyApplication.Service
{
public interface IReportingService
{
CatalogItem CreateDataSource(string DataSource, string Parent, bool Overwrite, DataSourceDefinition Definition, Property[] Properties);
void DeleteItem(string Item);
DataSourceDefinition GetDataSourceContents(string DataSource);
byte[] GetReportDefinition(string Report);
CatalogItem[] ListChildren(string Item);
}
}
</code></pre>
<p>So I have 2 implementations of this each instantiating a different web service e.g:</p>
<pre><code>namespace MyApp.Service.Implementation
{
class ReportingServiceImpl : IReportingService
{
ReportingService _service = null;
public ReportingServiceImpl()
{
ReportingService _service = new ReportingService();
}
/* SNIP */
}
}
</code></pre>
<p>and</p>
<pre><code>namespace MyApp.Service.Implementation
{
class ReportingService2006Impl : IReportingService
{
ReportingService2006 _service = null;
public ReportingService2006Impl()
{
ReportingService2006 _service = new ReportingService2006();
}
/* SNIP */
}
}
</code></pre>
<p>So the plan is I can inject these into my ServiceWrapper at run time. However - if you'll notice the interface is tied to the ReportService and some of the methods return objects that are from the web reference e.g. CatalogItem. Thus my project won't build because my implementation for ReportService2006 is referencing the CatalogItem from a different namespace.</p>
<p>Any ideas? Am I going totally the wrong direction with this?</p>
|
[
{
"answer_id": 139633,
"author": "David Aldridge",
"author_id": 6742,
"author_profile": "https://Stackoverflow.com/users/6742",
"pm_score": 9,
"selected": true,
"text": "DELETE"
},
{
"answer_id": 139877,
"author": "polara",
"author_id": 8754,
"author_profile": "https://Stackoverflow.com/users/8754",
"pm_score": 5,
"selected": false,
"text": "TRUNCATE TABLE"
},
{
"answer_id": 143811,
"author": "CaptainPicard",
"author_id": 15203,
"author_profile": "https://Stackoverflow.com/users/15203",
"pm_score": 2,
"selected": false,
"text": "SQL> delete from t1;\n\n10918 rows deleted.\n\nElapsed: 00:00:00.58\n\nExecution Plan\n----------------------------------------------------------\n 0 DELETE STATEMENT Optimizer=FIRST_ROWS (Cost=43 Card=1)\n 1 0 DELETE OF 'T1'\n 2 1 TABLE ACCESS (FULL) OF 'T1' (TABLE) (Cost=43 Card=1)\n\n\n\n\nStatistics\n----------------------------------------------------------\n 30 recursive calls\n 12118 db block gets\n 213 consistent gets\n 142 physical reads\n 3975328 redo size\n 441 bytes sent via SQL*Net to client\n 537 bytes received via SQL*Net from client\n 4 SQL*Net roundtrips to/from client\n 2 sorts (memory)\n 0 sorts (disk)\n 10918 rows processed\n"
},
{
"answer_id": 1873309,
"author": "Sachin Chourasiya",
"author_id": 184862,
"author_profile": "https://Stackoverflow.com/users/184862",
"pm_score": 4,
"selected": false,
"text": "TRUNCATE"
},
{
"answer_id": 12900557,
"author": "Bhaumik Patel",
"author_id": 1218422,
"author_profile": "https://Stackoverflow.com/users/1218422",
"pm_score": 8,
"selected": false,
"text": "+----------------------------------------+----------------------------------------------+\n| Truncate | Delete |\n+----------------------------------------+----------------------------------------------+\n| We can't Rollback after performing | We can Rollback after delete. |\n| Truncate. | |\n| | |\n| Example: | Example: |\n| BEGIN TRAN | BEGIN TRAN |\n| TRUNCATE TABLE tranTest | DELETE FROM tranTest |\n| SELECT * FROM tranTest | SELECT * FROM tranTest |\n| ROLLBACK | ROLLBACK |\n| SELECT * FROM tranTest | SELECT * FROM tranTest |\n+----------------------------------------+----------------------------------------------+\n| Truncate reset identity of table. | Delete does not reset identity of table. |\n+----------------------------------------+----------------------------------------------+\n| It locks the entire table. | It locks the table row. |\n+----------------------------------------+----------------------------------------------+\n| Its DDL(Data Definition Language) | Its DML(Data Manipulation Language) |\n| command. | command. |\n+----------------------------------------+----------------------------------------------+\n| We can't use WHERE clause with it. | We can use WHERE to filter data to delete. |\n+----------------------------------------+----------------------------------------------+\n| Trigger is not fired while truncate. | Trigger is fired. |\n+----------------------------------------+----------------------------------------------+\n| Syntax : | Syntax : |\n| 1) TRUNCATE TABLE table_name | 1) DELETE FROM table_name |\n| | 2) DELETE FROM table_name WHERE |\n| | example_column_id IN (1,2,3) |\n+----------------------------------------+----------------------------------------------+\n"
},
{
"answer_id": 18673219,
"author": "user27332",
"author_id": 2704077,
"author_profile": "https://Stackoverflow.com/users/2704077",
"pm_score": 2,
"selected": false,
"text": "DELETE is a DML command\nDELETE you can rollback\nDelete = Only Delete- so it can be rolled back\nIn DELETE you can write conditions using WHERE clause\nSyntax – Delete from [Table] where [Condition]\n"
},
{
"answer_id": 25032124,
"author": "Vinay Pandit",
"author_id": 3890653,
"author_profile": "https://Stackoverflow.com/users/3890653",
"pm_score": 0,
"selected": false,
"text": "begin Tran\ndelete from Employee\n\nselect * from Employee\nRollback\nselect * from Employee\n"
},
{
"answer_id": 43488613,
"author": "Mykhailo Seniutovych",
"author_id": 7111692,
"author_profile": "https://Stackoverflow.com/users/7111692",
"pm_score": 0,
"selected": false,
"text": "delete"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139639",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4950/"
] |
139,650
|
<p>I have normally hand written xml like this:</p>
<pre><code><tag><?= $value ?></tag>
</code></pre>
<p>Having found tools such as simpleXML, should I be using those instead? What's the advantage of doing it using a tool like that?</p>
|
[
{
"answer_id": 139855,
"author": "hakamadare",
"author_id": 17597,
"author_profile": "https://Stackoverflow.com/users/17597",
"pm_score": 2,
"selected": false,
"text": "XML::Simple"
},
{
"answer_id": 140203,
"author": "Stefan Gehrig",
"author_id": 11354,
"author_profile": "https://Stackoverflow.com/users/11354",
"pm_score": 2,
"selected": false,
"text": "$w=new XMLWriter();\n$w->openMemory();\n$w->startDocument('1.0','UTF-8');\n$w->startElement(\"root\");\n $w->writeAttribute(\"ah\", \"OK\");\n $w->text('Wow, it works!');\n$w->endElement();\necho htmlentities($w->outputMemory(true));\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139650",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16511/"
] |
139,655
|
<p>I have a need to convert Pixels to Points in C#. I've seen some complicated explanations about the topic, but can't seem to locate a simple formula. Let's assume a standard 96dpi, how do I calulate this conversion?</p>
|
[
{
"answer_id": 139712,
"author": "Mark Ransom",
"author_id": 5987,
"author_profile": "https://Stackoverflow.com/users/5987",
"pm_score": 9,
"selected": true,
"text": "GetDeviceCaps"
},
{
"answer_id": 1079075,
"author": "Hejazi",
"author_id": 73195,
"author_profile": "https://Stackoverflow.com/users/73195",
"pm_score": 6,
"selected": false,
"text": "Graphics g = this.CreateGraphics();\npoints = pixels * 72 / g.DpiX;\ng.Dispose();\n"
},
{
"answer_id": 1256286,
"author": "Ian Boyd",
"author_id": 12597,
"author_profile": "https://Stackoverflow.com/users/12597",
"pm_score": 5,
"selected": false,
"text": " 72 pt x pt\n------ = ----- (1) for 150dpi system\n150 px y px\n"
},
{
"answer_id": 3228295,
"author": "david",
"author_id": 389466,
"author_profile": "https://Stackoverflow.com/users/389466",
"pm_score": 2,
"selected": false,
"text": "points = pixels * 96 / 72\n"
},
{
"answer_id": 3498075,
"author": "daniel",
"author_id": 422269,
"author_profile": "https://Stackoverflow.com/users/422269",
"pm_score": -1,
"selected": false,
"text": "213.67 Manual Entry \n 0.45 Add 0.45 \n214.12 Subtotal \n213.75 Round to a multiple of 0.75 \n213.00 Subtract 0.75 provides manual entry converted by Excel \n284.00 Divide by 0.75 gives the number of pixels of height\n"
},
{
"answer_id": 38811104,
"author": "Michael Zhang",
"author_id": 6567533,
"author_profile": "https://Stackoverflow.com/users/6567533",
"pm_score": 1,
"selected": false,
"text": "int pixels = (int)((dp) * Resources.System.DisplayMetrics.Density + 0.5f);\n"
},
{
"answer_id": 62802275,
"author": "hasii",
"author_id": 3415543,
"author_profile": "https://Stackoverflow.com/users/3415543",
"pm_score": 1,
"selected": false,
"text": " from wx import ScreenDC\n from wx import Size\n\n size: Size = ScreenDC().GetPPI()\n print(f'x-DPI: {size.GetWidth()} y-DPI: {size.GetHeight()}')\n"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139655",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13603/"
] |
139,668
|
<p>Under what circumstances will the Win32 API function OleGetClipboard() fail and return <code>CLIPBRD_E_CANT_OPEN</code>?</p>
<p>More background: I am assisting with a Firefox bug fix. Details here:</p>
<p><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=444800#c19" rel="nofollow noreferrer" title="cannot retrieve image data from clipboard in lossless format">bug 444800 - cannot retrieve image data from clipboard in lossless format</a></p>
<p>In the automated test that I helped write, we see that OleGetClipboard() sometimes fails and returns <code>CLIPBRD_E_CANT_OPEN</code>. That is unexpected, and the Firefox code to pull image data off the Windows clipboard depends on that call succeeding.</p>
|
[
{
"answer_id": 140387,
"author": "Mike Dimmick",
"author_id": 6970,
"author_profile": "https://Stackoverflow.com/users/6970",
"pm_score": 4,
"selected": true,
"text": "OleGetClipboard"
}
] |
2008/09/26
|
[
"https://Stackoverflow.com/questions/139668",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.