qid
int64
4
19.1M
question
stringlengths
18
48.3k
answers
list
date
stringlengths
10
10
metadata
list
264,685
<p>In CSS, with:</p> <pre><code>@page { @top-right { content: "Page " counter(page) " of " counter(pages); } } </code></pre> <p>I can have page numbers displayed at the top of every page when the page is printed. This works great. But now, how can I make it so the page number starts with 2 instead of 1? Can I do that by modifying the CSS rule above?</p>
[ { "answer_id": 264706, "author": "Treb", "author_id": 22114, "author_profile": "https://Stackoverflow.com/users/22114", "pm_score": -1, "selected": false, "text": "counter(page+1)" }, { "answer_id": 275099, "author": "schnaader", "author_id": 34065, "author_profile": "https://Stackoverflow.com/users/34065", "pm_score": 2, "selected": false, "text": "<h1 style=\"page-break-before:always\"></h1>\n" }, { "answer_id": 13829987, "author": "Brian Bell", "author_id": 1896166, "author_profile": "https://Stackoverflow.com/users/1896166", "pm_score": 2, "selected": false, "text": "@page {\n counter-increment: page;\n counter-reset: page 1;\n @top-right {\n content: \"Page \" counter(page) \" of \" counter(pages);\n }\n}\n page 1 0" }, { "answer_id": 59437476, "author": "Thirumalai Chellam Balagopalan", "author_id": 1900397, "author_profile": "https://Stackoverflow.com/users/1900397", "pm_score": 0, "selected": false, "text": ".seq-start{\n -fs-page-sequence: start;\n}\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/264685", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5295/" ]
264,687
<p>You launch a java program from a console (maybe using a .bat script). I don't want the console to remain visible, I want to hide it.</p> <p>Is there a simple way to do this ? Without JNI ?</p>
[ { "answer_id": 264699, "author": "Lukman", "author_id": 34586, "author_profile": "https://Stackoverflow.com/users/34586", "pm_score": 3, "selected": false, "text": "start program program" }, { "answer_id": 2780929, "author": "t3hnar", "author_id": 301517, "author_profile": "https://Stackoverflow.com/users/301517", "pm_score": 0, "selected": false, "text": "start javaw start javaw -jar ***.jar" }, { "answer_id": 2905197, "author": "Manikandan", "author_id": 349967, "author_profile": "https://Stackoverflow.com/users/349967", "pm_score": 3, "selected": false, "text": "start javaw" }, { "answer_id": 72703968, "author": "exadmin", "author_id": 14307095, "author_profile": "https://Stackoverflow.com/users/14307095", "pm_score": 0, "selected": false, "text": "start \"MyTitle\" \"c:\\Program Files (x86)\\Java\\jdk1.8.0_202\\bin\\javaw.exe\" -jar myApp.jar\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/264687", "https://Stackoverflow.com", "https://Stackoverflow.com/users/155796/" ]
264,689
<p>So I want to trigger an event (pausing/unpausing some media) whenever the user presses spacebar anywhere in the my Swing app.</p> <p>Since there are so many controls and panels that could have focus, its not really possible to add keyevents to them all(not to mention gross).</p> <p>So I found </p> <pre><code>KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher() </code></pre> <p>which is awesome, you can register global keypress pre-handlers. There's a major problem though - spaces will be typed all the time in input fields, table cells, etc, and I obviously dont want to trigger the pause event then!</p> <p>So any ideas? Perhaps there is way to detect globally whether the cursor is focused on something that allows text input, without having to check through a list of all the editable controls(vomit!)? </p>
[ { "answer_id": 266144, "author": "ykaganovich", "author_id": 10026, "author_profile": "https://Stackoverflow.com/users/10026", "pm_score": 1, "selected": false, "text": "KEY_EVENT_MASK" }, { "answer_id": 267044, "author": "dalyons", "author_id": 16925, "author_profile": "https://Stackoverflow.com/users/16925", "pm_score": 0, "selected": false, "text": "javax.swing.plaf.basic.BasicComboBoxEditor$BorderlessTextField\n KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventPostProcessor(new KeyEventPostProcessor() {\n\n public boolean postProcessKeyEvent(KeyEvent e) {\n if (e.getID() == KeyEvent.KEY_PRESSED) {\n Object s = e.getComponent();\n if (!(s instanceof JTextField) &&\n !(s instanceof JTable && ((JTable) s).isEditing())\n ) {\n music_player.pauseEvent();\n }\n\n //System.out.println(s.getClass().toString());\n }\n return true;\n }\n });\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/264689", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16925/" ]
264,702
<p>I have built an application that uses SQL Express 2005 and I want to deploy it, but the problem is that anyone who has SQL Management Studio(or something like that) installed on his computer, can connect to my database and change it. Is there anyway to prevent end-users from seeing or editing the content of my database, even those with the Administrator privileges? </p>
[ { "answer_id": 264721, "author": "Ed Guiness", "author_id": 4200, "author_profile": "https://Stackoverflow.com/users/4200", "pm_score": 1, "selected": false, "text": "WITH ENCRYPTION\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/264702", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34623/" ]
264,711
<p>Traditional logfile analytics tools (awstats, statcounter) or general web analytics (google analytics, yahoo web analytics) are not suitable for analyzing traffic on servlets. Is there a good alternative to log messages using a logging framework (log4j for example) and to write a custom analytics software for these?</p>
[ { "answer_id": 264721, "author": "Ed Guiness", "author_id": 4200, "author_profile": "https://Stackoverflow.com/users/4200", "pm_score": 1, "selected": false, "text": "WITH ENCRYPTION\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/264711", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28578/" ]
264,714
<p>I am trying to use a business object that I am passing to the report.rdlc. The properties in my object are not directly exposed. The properties I require are embedded within another object inside the top level object. As this is a WCF project I can't control what goes on at the server end. I am just able to request these objects or Insert/Update/Delete their info from the database. It is done in this way as the back end can use multiple flavors of database. </p> <p>Here is what I can see after adding my business object as a <code>DataSource</code>:</p> <pre><code>-BusinessObject -CustomerInfo -ClientName -ColumnName -DisplayName -FieldName -IsNull -KeyColumn -SenondKeyColumn -StringValue -ClientID -ColumnName -DisplayName -FieldName -IntValue -IsNull -KeyColumn -SenondKeyColumn +ClientAddress +Instrument +Telephone </code></pre> <p>etc etc</p> <p>I need to be able to display, for example, the <code>ClientName.StringValue</code> field. If I drag the field I want onto the report I get: </p> <pre><code>=First(Fields!StringValue.Value) </code></pre> <p>This doesn't display anything when the report is run, I assume because it can't qualify what <code>StringValue</code> it is talking about and there could be many. </p> <p>If I try dragging the <code>ClientName</code> object I get:</p> <pre><code>=First(Fields!ContactName.Value) </code></pre> <p>However this gives:</p> <pre><code>#ERROR </code></pre> <p>When the report is run.</p> <p>I would have thought you could use:</p> <pre><code>=First(Fields!ClientName.StringValue.Value) </code></pre> <p>but this won't even let me build.</p>
[ { "answer_id": 274748, "author": "Matt Johnson", "author_id": 34628, "author_profile": "https://Stackoverflow.com/users/34628", "pm_score": 2, "selected": true, "text": "=First(Fields!ClientName.Value.StringValue, \"BusinessObject_CustomerInfo\")\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/264714", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34628/" ]
264,720
<p>I am using a GDI+ Graphic to draw a 4000*3000 image to screen, but it is really slow. It takes about 300ms. I wish it just occupy less than 10ms.</p> <pre><code>Bitmap *bitmap = Bitmap::FromFile("XXXX",...); </code></pre> <p>//-------------------------------------------- // this part takes about 300ms, terrible!</p> <pre><code>int width = bitmap-&gt;GetWidth(); int height = bitmap-&gt;GetHeight(); DrawImage(bitmap,0,0,width,height); </code></pre> <p>//------------------------------------------</p> <p>I cannot use CachedBitmap, because I want to edit the bitmap later.</p> <p>How can I improve it? Or is any thing wrong? </p> <p>This native GDI function also draws the image into the screen, and it just take 1 ms:</p> <pre><code>SetStretchBltMode(hDC, COLORONCOLOR); StretchDIBits(hDC, rcDest.left, rcDest.top, rcDest.right-rcDest.left, rcDest.bottom-rcDest.top, 0, 0, width, height, BYTE* dib, dibinfo, DIB_RGB_COLORS, SRCCOPY); </code></pre> <p>//--------------------------------------------------------------</p> <p>If I want to use StretchDIBits, I need to pass BITMAPINFO, But how can I get BITMAPINFO from a Gdi+ Bitmap Object? I did the experiment by FreeImage lib, I call StretchDIBits using FreeImageplus object, it draw really fast. But now I need to draw Bitmap, and write some algorithm on Bitmap's bits array, how can I get BITMAPINFO if I have an Bitmap object? It's really annoying -___________-|</p>
[ { "answer_id": 265615, "author": "Cybis", "author_id": 32998, "author_profile": "https://Stackoverflow.com/users/32998", "pm_score": 4, "selected": false, "text": "Bitmap bmp = new Bitmap(...)\nTextureBrush myBrush = new TextureBrush(bmp)\n\nprivate void Paint(object sender, PaintEventArgs e):\n{\n //Don't draw the bitmap directly. \n //Only draw TextureBrush inside the Paint event.\n e.Graphics.FillRectangle(myBrush, ...)\n}\n" }, { "answer_id": 1617930, "author": "Ian Boyd", "author_id": 12597, "author_profile": "https://Stackoverflow.com/users/12597", "pm_score": 2, "selected": false, "text": "DrawImage(bitmap,0,0);\n DrawImage(bitmap, 0, 0, bitmap.GetWidth, bitmap.GetHeight);\n bitmap CachedBitmap CachedBitmap DrawImage CachedBitmap class procedure TGDIPlusHelper.DrawCachedBitmap(image: TGPImage;\n var cachedBitmap: TGPCachedBitmap;\n Graphics: TGPGraphics; x, y: Integer; width, height: Integer);\nvar\n b: TGPBitmap;\nbegin\n if (image = nil) then\n begin\n //i've chosen to not throw exceptions during paint code - it gets very nasty\n Exit;\n end;\n\n if (graphics = nil) then\n begin\n //i've chosen to not throw exceptions during paint code - it gets very nasty\n Exit;\n end;\n\n //Check if we have to invalidate the cached image because of size mismatch\n //i.e. if the user has \"zoomed\" the UI\n if (CachedBitmap <> nil) then\n begin\n if (CachedBitmap.BitmapWidth <> width) or (CachedBitmap.BitmapHeight <> height) then\n FreeAndNil(CachedBitmap); //nil'ing it will force it to be re-created down below\n end;\n\n //Check if we need to create the \"cached\" version of the bitmap\n if CachedBitmap = nil then\n begin\n b := TGDIPlusHelper.ResizeImage(image, width, height);\n try\n CachedBitmap := TGPCachedBitmap.Create(b, graphics);\n finally\n b.Free;\n end;\nend;\n\n if (graphics.DrawCachedBitmap(cachedBitmap, x, y) <> Ok) then\nbegin\n //The calls to DrawCachedBitmap failed\n //The API is telling us we have to recreate the cached bitmap\n FreeAndNil(cachedBitmap);\n b := TGDIPlusHelper.ResizeImage(image, width, height);\n try\n CachedBitmap := TGPCachedBitmap.Create(b, graphics);\n finally\n b.Free;\n end;\n\n graphics.DrawCachedBitmap(cachedBitmap, x, y);\n end;\n end;\n cachedBitmap DrawCachedBitmap Image imgPrintInvoice = new Image.FromFile(\"printer.png\");\nCachedBitmap imgPrintInvoiceCached = null;\n\n...\n\nint glyphSize = 16 * (GetCurrentDpi() / 96);\n\nDrawCachedBitmap(imgPrintInvoice , ref imgPrintInvoiceCached , graphics, \n 0, 0, glyphSize, glyphSize);\n" }, { "answer_id": 21456057, "author": "eugeniy", "author_id": 3253028, "author_profile": "https://Stackoverflow.com/users/3253028", "pm_score": 1, "selected": false, "text": "Bitmap *bitmap = Bitmap::FromFile(\"XXXX\",...);\n\nBitmap *bitmap2 = new Bitmap(bitmap); // make copy\n\nDrawImage(bitmap2,0,0,width,height);\n" }, { "answer_id": 34011819, "author": "Sator666", "author_id": 5451461, "author_profile": "https://Stackoverflow.com/users/5451461", "pm_score": 2, "selected": false, "text": "//--------Global-----------\nBitmap *g_pGDIBitmap; //for loading picture\nint gRozXOkna, gRozYOkna; //size of working window\nint gRozXObrazu, gRozYObrazu; //Size of picture X,Y\nHBITMAP g_hBitmap = NULL; //for displaying on window\n//------------------------------------------------------------------------------\nint ShowBitmapStretch(HDC hdc, HBITMAP hBmp, int RozX, int RozY, int RozXSkal, int RozYSkal, int PozX, int PozY) \n{\n if (hBmp == NULL) return -1;\n HDC hdc_mem = CreateCompatibleDC(hdc); //utworzenie kontekstu pamięciowego\n if (NULL == hdc_mem) return -2;\n //Trzeba połączyć BMP z hdc_mem, tzn. umieścić bitmapę w naszym kontekście pamięciowym\n if (DeleteObject(SelectObject(hdc_mem, hBmp)) == NULL) return -3; \n\n SetStretchBltMode(hdc, COLORONCOLOR); //important! for smoothness\n if (StretchBlt(hdc, PozX, PozY, RozXSkal, RozYSkal, hdc_mem, 0, 0, RozX, RozY, SRCCOPY) == 0) return -4;\n\n if (DeleteDC(hdc_mem) == 0) return -5;\n return 0; //OK\n}\n//---------------------------------------------------------------------------\nvoid ClearBitmaps(void)\n{\n if (g_hBitmap) { DeleteObject(g_hBitmap); g_hBitmap = NULL; }\n if (g_pGDIBitmap) { delete g_pGDIBitmap; g_pGDIBitmap = NULL; }\n}\n//---------------------------------------------------------------------------\nvoid MyOpenFile(HWND hWnd, szFileName)\n{\n ClearBitmaps(); //Important!\n g_pGDIBitmap = new Bitmap(szFileName); //load a picture from file\n\n if (g_pGDIBitmap == 0) return;\n //---Checking if picture was loaded\n gRozXObrazu = g_pGDIBitmap->GetWidth();\n gRozYObrazu = g_pGDIBitmap->GetHeight();\n if (gRozXObrazu == 0 || gRozYObrazu == 0) return;\n\n //---Uworzenie bitmapy do wyświatlaia; DO IT ONCE HERE!\n g_pGDIBitmap->GetHBITMAP(Gdiplus::Color(), &g_hBitmap); //creates a GDI bitmap from this Bitmap object\n if (g_hBitmap == 0) return;\n\n //---We need to force the window to redraw itself\n InvalidateRect(hWnd, NULL, TRUE);\n UpdateWindow(hWnd);\n}\n//---------------------------------------------------------------------------\nvoid MyOnPaint(HDC hdc, HWND hWnd) //in case WM_PAINT; DO IT MANY TIMES\n{\n if (g_hBitmap)\n {\n double SkalaX = 1.0, SkalaY = 1.0; //scale\n if (gRozXObrazu > gRozXOkna || gRozYObrazu > gRozYOkna || //too big picture, więc zmniejsz; \n (gRozXObrazu < gRozXOkna && gRozYObrazu < gRozYOkna)) //too small picture, można powiększyć \n {\n SkalaX = (double)gRozXOkna / (double)gRozXObrazu; //np. 0.7 dla zmniejszania; FOR DECREASE\n SkalaY = (double)gRozYOkna / (double)gRozYObrazu; //np. 1.7 dla powiększania; FOR INCREASE\n if (SkalaY < SkalaX) SkalaX = SkalaY; //ZAWSZE wybierz większe skalowanie, czyli mniejszą wartość i utaw w SkalaX\n }\n\n if (ShowBitmapStretch(hdc, g_hBitmap, gRozXObrazu, gRozYObrazu, (int)(gRozXObrazu*SkalaX), (int)(gRozYObrazu*SkalaX), 0, 0, msg) < 0) return;\n" }, { "answer_id": 46006572, "author": "Mostafa Saad", "author_id": 5082934, "author_profile": "https://Stackoverflow.com/users/5082934", "pm_score": 0, "selected": false, "text": "Graphics.DrawImage/DrawImageUnscaled\n ImageList.Draw(GFX,Point,Index)\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/264720", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25749/" ]
264,744
<p>What is the best way to structure a VB.NET <a href="http://en.wikipedia.org/wiki/Windows_Forms" rel="nofollow noreferrer">Windows Forms</a> application so that code can be reused and the application can be extended easily?</p> <p>I used to create lots of new forms. This lead to lots of repeated code and forms which did similar things.</p> <p>Now, for forms which do similar jobs, such as view/edit/delete items from a specific database table, I create a form with the required controls, have the form create an instance of a class with parameters such as a collection of the controls and a string containing the database table name. Then the individual controls call functions of the class.</p> <p>Advanced forms will inherit and extend this basic form class.</p> <ol> <li>Has there already been work done in this area?</li> <li>Are there books / articles available which discuss the options available on this topic?</li> </ol>
[ { "answer_id": 265219, "author": "RS Conley", "author_id": 7890, "author_profile": "https://Stackoverflow.com/users/7890", "pm_score": 2, "selected": false, "text": "ThisForm.ThisButton(<args>)" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/264744", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
264,745
<p>Imagine the following</p> <p>A type T has a field Company. When executing the following method it works perfectly:</p> <pre><code>Type t = typeof(T); t.GetProperty("Company") </code></pre> <p>Whith the following call I get null though</p> <pre><code>Type t = typeof(T); t.GetProperty("company", BindingFlags.IgnoreCase) </code></pre> <p>Anybody got an idea?</p>
[ { "answer_id": 264748, "author": "leppie", "author_id": 15541, "author_profile": "https://Stackoverflow.com/users/15541", "pm_score": 6, "selected": false, "text": "BindingFlags.Public | BindingFlags.Instance" }, { "answer_id": 264752, "author": "Pop Catalin", "author_id": 4685, "author_profile": "https://Stackoverflow.com/users/4685", "pm_score": 10, "selected": true, "text": "BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance" }, { "answer_id": 1461101, "author": "Josh Warner-Burke", "author_id": 177271, "author_profile": "https://Stackoverflow.com/users/177271", "pm_score": 4, "selected": false, "text": "public static void SetProperty(Object R, string propertyName, object value)\n{\n Type type = R.GetType();\n object result;\n result = type.InvokeMember(\n propertyName, \n BindingFlags.SetProperty | \n BindingFlags.IgnoreCase | \n BindingFlags.Public | \n BindingFlags.Instance, \n null, \n R, \n new object[] { value });\n}\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/264745", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11333/" ]
264,747
<p>Is there any way to find out what exceptions might be thrown by any method in .NET code? Ideally I want to see what might be thrown and choose which ones I want to handle. I guess I want the information you'd get from the throws clause in java. </p> <p>The situation is I'm doing a linq query on an xml document from the network and want to know what could go wrong. I could open up the assembly in reflector and have a look but I thought there might be an easier way. </p>
[ { "answer_id": 264755, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 6, "selected": true, "text": "/// <exception.../> OutOfMemoryException ThreadAbortException TypeLoadException" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/264747", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13028/" ]
264,763
<p>I am using msbuild to build a C++ project and I want to suppress the 'Post-Build Event'. I have tried the following properties with no success:</p> <pre><code>/property:PostBuildEvent= /property:VCPostBuildEventTool= </code></pre> <p>Neither will make any difference and the post build events are still executed.</p> <p>Does anyone know how to suppress these (and potentially other) events using msbuild?</p>
[ { "answer_id": 277742, "author": "Sunlight", "author_id": 33650, "author_profile": "https://Stackoverflow.com/users/33650", "pm_score": 0, "selected": false, "text": "SKIP_POST_BUILD_EVENTS msbuild" }, { "answer_id": 489354, "author": "leftend", "author_id": 11460, "author_profile": "https://Stackoverflow.com/users/11460", "pm_score": 3, "selected": true, "text": "set ISFULLBUILD=True\nmsbuild TFSBuild.proj >> BuildOutput.txt\n IF NOT '%ISFULLBUILD%'=='True' copy /y $(TargetFileName) \"..\\..\\..\\..\\..\\..\\Binaries\\$(ConfigurationName)\\\"\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/264763", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9236/" ]
264,764
<p>I'm currently working on a WebSphere 6.1 Web Project.</p> <p>In my java code, how can i get the current running application port?</p>
[ { "answer_id": 265080, "author": "McDowell", "author_id": 304, "author_profile": "https://Stackoverflow.com/users/304", "pm_score": 3, "selected": true, "text": "protected void doGet(HttpServletRequest request,\n HttpServletResponse response) throws ServletException, IOException {\n PrintWriter writer = response.getWriter();\n writer.write(\"\" + request.getLocalPort());\n writer.close();\n}\n <specialEndpoints xmi:id=\"NamedEndPoint_1214751102556\" endPointName=\"WC_defaulthost\">\n <endPoint xmi:id=\"EndPoint_1214751102556\" host=\"*\" port=\"9080\"/>\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/264764", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2937/" ]
264,766
<p>My code works great in IE8, Firefox and Safari. But it doesn't work properly in Opera. What happens is that the DIV is hidden but the space occupied by the DIV remains to appear in my web-page.</p> <pre><code>&lt;div style=" z-index:-1;height :380; width:760; position:relative; text-align:center" id="new-add"&gt; &lt;object id="banner-flash" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="769" height="382" top="0"&gt; &lt;param name="movie" value="exp.swf" /&gt; &lt;param name="quality" value="high" /&gt; &lt;param name="bgcolor" value="#ffffff" /&gt; &lt;param name="wmode" value="transparent" /&gt; &lt;embed src="exp.swf" wmode="transparent" quality="high" bgcolor="#ffffff" width="780" height="382" name="mymoviename" align="" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"&gt; &lt;/embed&gt; &lt;/object&gt; &lt;/div&gt; &lt;div id="fechar-link" style=" font-family: Verdana,Arial,Helvetica,sans-serif; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-size-adjust: none; font-stretch: normal; text-decoration: none; text-align:center" &gt; &lt;a href="#" onclick=" document.getElementById('new-add').style.height =0; document.getElementById('banner-flash').style.height =0; document.getElementById('fechar-link').style.height = 0; document.getElementById('new-add').style.visibility ='hidden'; document.getElementById('banner-flash').style.visibility ='hidden'; document.getElementById('fechar-link').style.visibility ='hidden'; " &gt;Close&lt;/a&gt; &lt;/div&gt; </code></pre> <p>What do I need to do, so the space occupied by the DIV disappears?</p> <p>Thanks</p>
[ { "answer_id": 264774, "author": "Romain Linsolas", "author_id": 26457, "author_profile": "https://Stackoverflow.com/users/26457", "pm_score": 0, "selected": false, "text": "document.getElementById(\"xxx\").display = \"none\";\n document.getElementById(\"xxx\").style.visibility = \"hidden\";\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/264766", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2019426/" ]
264,771
<p>How to put a File path control in VBA front panel? I want the user to be able to select the browse button and select the file path rather than putting up dialog boxes all over the place. I need the user to select three or more file paths.</p>
[ { "answer_id": 264808, "author": "fwzgekg", "author_id": 34116, "author_profile": "https://Stackoverflow.com/users/34116", "pm_score": 2, "selected": false, "text": "Application.FileDialog(msoFileDialogOpen) SHBrowseForFolder Declare Function" }, { "answer_id": 3770658, "author": "nghmuon", "author_id": 455192, "author_profile": "https://Stackoverflow.com/users/455192", "pm_score": 1, "selected": false, "text": "FilePath = Application.GetOpenFilename\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/264771", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13440/" ]
264,807
<p>How do you stop race conditions in MySQL? the problem at hand is caused by a simple algorithm:</p> <ol> <li>select a row from table</li> <li>if it doesn't exist, insert it</li> </ol> <p>and then either you get a duplicate row, or if you prevent it via unique/primary keys, an error.</p> <p>Now normally I'd think transactions help here, but because the row doesn't exist, the transaction don't actually help (or am I missing something?).</p> <p>LOCK TABLE sounds like an overkill, especially if the table is updated multiple times per second.</p> <p>The only other solution I can think of is GET_LOCK() for every different id, but isn't there a better way? Are there no scalability issues here as well? And also, doing it for every table sounds a bit unnatural, as it sounds like a very common problem in high-concurrency databases to me. </p>
[ { "answer_id": 1310487, "author": "xvga", "author_id": 160596, "author_profile": "https://Stackoverflow.com/users/160596", "pm_score": 0, "selected": false, "text": "$exists = $success = false;\ndo{\n $exists = check();// select a row in the table \n if (!$exists)\n $success = create_record();\n if ($success){\n $exists = true;\n }else if ($success != ERROR_DUP_ROW){\n log_error(\"failed to create row not 'coz DUP_ROW!\");\n break;\n }else{\n //probably other process has already created the record,\n //so try check again if exists\n }\n}while(!$exists)\n" }, { "answer_id": 14314075, "author": "Buttle Butkus", "author_id": 631764, "author_profile": "https://Stackoverflow.com/users/631764", "pm_score": 0, "selected": false, "text": "INSERT IGNORE LOCK ROLLBACK ROLLBACK TO SAVEPOINT *savepoint_name* LOCK" }, { "answer_id": 58712537, "author": "Robocide", "author_id": 179744, "author_profile": "https://Stackoverflow.com/users/179744", "pm_score": 0, "selected": false, "text": "INSERT INTO table_listnames (name, address, tele)\nSELECT * FROM (SELECT 'Rupert', 'Somewhere', '022') AS tmp\nWHERE NOT EXISTS (\n SELECT name FROM table_listnames WHERE name = 'Rupert'\n) LIMIT 1;\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/264807", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8437/" ]
264,813
<p>We would like to have the FormsCookieName of FormsCookiePath change per instance of our application. We have an application which has multiple instances on 1 server/domainname. Because of this we can only work in 1 application at the same time, since the cookies will overwrite eachother. Same for the Sessions btw.</p> <p>Is there a way to dynamicly, for example in the Global.asax Application_Start, change this name? This would be usefull as we keep a license name in each application which could be used as the basis for the CookieName.</p> <p>We already work with Web.config and extra files to overwrite Web.config values in external files using: <code>&lt;appSettings file="Web.AppSettings.Config"&gt;</code></p> <p>But this requires manual actions which can be forgotten and are redundant since the settings can be retrieved from the database.</p> <p>Thanks.</p>
[ { "answer_id": 5606765, "author": "Ron", "author_id": 175938, "author_profile": "https://Stackoverflow.com/users/175938", "pm_score": 2, "selected": false, "text": "\nprotected void Application_Start(object sender, EventArgs e)\n{\n // determine unique cookie name per application\n string cookieName = ...\n // Get the web.config forms settings\n Configuration c = WebConfigurationManager.OpenWebConfiguration(\"~\");\n AuthenticationSection auth = c.GetSection(\"system.web/authentication\") \n as AuthenticationSection;\n // See if we have mismatch in web.config or in Forms cookiename\n if (auth != null && auth.Forms != null && \n (auth.Forms.Name != cookieName \n || FormsAuthentication.FormsCookieName != cookieName\n )\n )\n {\n // Assign value in web.config for future restarts\n auth.Forms.Name = cookieName;\n // would be nice if this restarted the app, but it doesn't appear to\n c.Save();\n // This seems to restart the app\n System.Web.HttpRuntime.UnloadAppDomain();\n }\n ...\n}\n" }, { "answer_id": 37183358, "author": "Ashish Mehta", "author_id": 6324452, "author_profile": "https://Stackoverflow.com/users/6324452", "pm_score": 2, "selected": false, "text": " protected void Application_Start(Object sender, EventArgs e)\n {\n // This will enforce that FormsAuthentication class is loaded from configuration settings for the application.\n FormsAuthentication.Initialize();\n\n // The new cookie name whatever you need can go here, I needed some value from my application setting to be prefixed so I used it.\n string newCookieName = string.Format(\"{0}.ASPXAUTH\", ConfigurationManager.AppSettings[\"SomeSettingThatIsUniquetoSite\"]);\n\n // Modifying underlying baking field that points to FormsAuthentication.FormsCookieName \n Type type = typeof(FormsAuthentication);\n System.Reflection.FieldInfo field = type.GetField(\"_FormsName\", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);\n field.SetValue(null, newCookieName);\n }\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/264813", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2104/" ]
264,817
<p>I have code similar to the following in many places:</p> <pre><code>var dbParams = db.ReadParams(memberID, product, GetSubscriptionFields()); Debug.Assert(dbParams.Count == 4); _memberCode = dbParams[0]; _password = dbParams[1]; _userName = dbParams[2]; _reasonCode = dbParams[3]; </code></pre> <p>ReadParams() returns an array of strings, the number of strings depending on the GetSubscriptionFields() function. I could use dbParams[] directly in my code, but I find it more helpful to give meaningful names to each of the values in the array. Is there a way I can get all the results directly, without going through the array?</p> <p>I am looking for something like:</p> <pre><code>db.ReadParams(memberID, product, out _memberCode, out _password, out _userName, out _reasonCode); </code></pre> <p>or</p> <pre><code>Tuple&lt;_memberCode, _password, _userName, _reasonCode&gt; = db.ReadParams(memberID, product); </code></pre> <p>Of course, it has to be legal C# code :)</p>
[ { "answer_id": 264849, "author": "Ed Guiness", "author_id": 4200, "author_profile": "https://Stackoverflow.com/users/4200", "pm_score": 2, "selected": true, "text": "dbParams[MEMBER_CODE]\ndbParams[PASSWORD]\ndbParams[USERNAME]\ndbParams[REASON_CODE]\n" }, { "answer_id": 264855, "author": "David Wengier", "author_id": 489, "author_profile": "https://Stackoverflow.com/users/489", "pm_score": 1, "selected": false, "text": "public class Tuple<T1, T2, T3, T4>\n{\n public T1 Field1 { get; set; }\n public T2 Field2 { get; set; }\n public T3 Field3 { get; set; }\n public T4 Field4 { get; set; }\n}\n" }, { "answer_id": 264861, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 0, "selected": false, "text": " return new Foo {MemberCode = arr[0], ...}\n Action<string> static void Main()\n{\n string name = \"\";\n int value = 0;\n Foo(\"whatever\",\n x => { name = x; },\n x => { value = int.Parse(x); }); \n}\n// yucky; wash eyes after reading...\nstatic void Foo(string query, params Action<string>[] actions)\n{\n string[] results = Bar(query); // the actual query\n int len = actions.Length < results.Length ? actions.Length : results.Length;\n for (int i = 0; i < len; i++)\n {\n actions[i](results[i]);\n }\n}\n" }, { "answer_id": 264869, "author": "Mecki", "author_id": 15809, "author_profile": "https://Stackoverflow.com/users/15809", "pm_score": 2, "selected": false, "text": "Member m = db.ReadParams(memberID, product, GetSubscriptionFields());\n m.memberCode\nm.password\nm.username\nm.reasonCode\n ReadParamsResult rpr = myDb.ReadParamsAsObject(memberID, product, GetSubscriptionFields());\n\n// Verify that the expected result object has been returned\nDebug.Assert(rpr is Member);\n\n// Downcast\nMember m = (Member)rpr;\n" }, { "answer_id": 274504, "author": "Marcel Popescu", "author_id": 31793, "author_profile": "https://Stackoverflow.com/users/31793", "pm_score": 0, "selected": false, "text": "using System.Diagnostics;\n\npublic static class ArrayExtractor\n{\n public static void Extract<T1>(this object[] array, out T1 value1)\n where T1 : class\n {\n Debug.Assert(array.Length >= 1);\n value1 = array[0] as T1;\n }\n\n public static void Extract<T1, T2>(this object[] array, out T1 value1, out T2 value2)\n where T1 : class\n where T2 : class\n {\n Debug.Assert(array.Length >= 2);\n value1 = array[0] as T1;\n value2 = array[1] as T2;\n }\n}\n string fileName;\nstring contents;\nArrayExtractor.Extract(args, out fileName, out contents);\n args.Extract(out fileName, out contents);\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/264817", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31793/" ]
264,822
<p>I have a gradient image as a background for a table header(9x18pix). This image is called through a selector class. When the header content grows to 2 lines(vertical height increases), the bg image is tiling vertically and looks ugly. How can I stretch the bg image vertically without tiling?</p>
[ { "answer_id": 264847, "author": "Mecki", "author_id": 15809, "author_profile": "https://Stackoverflow.com/users/15809", "pm_score": 2, "selected": false, "text": "background-repeat: repeat-x;\n <html>\n<head><title>Gradient Test</title>\n<style type=\"text/css\">\n th {\n color:brown;\n background-image:url(http://img222.imageshack.us/img222/6586/fillhz2.png);\n background-repeat:repeat-x;\n margin: 0;\n }\n</style>\n</head>\n<body>\n <table>\n <tr>\n <th>One line</th>\n <th>Three<br>lines<br>of text</th>\n </tr>\n <tr>\n <td>Data</td>\n <td>Data</td>\n </tr>\n </table>\n</body>\n</html>\n" }, { "answer_id": 494733, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "<html>\n<head><title>Gradient Test</title>\n<style type=\"text/css\">\n th {\n color:brown;\n background-image:url(http://img222.imageshack.us/img222/6586/fillhz2.png);\n background-repeat:repeat;\n margin: 0;\n }\n</style>\n</head>\n<body>\n <table>\n <tr>\n <th>One line</th>\n <th>Three<br>lines<br>of text</th>\n </tr>\n <tr>\n <td>Data</td>\n <td>Data</td>\n </tr>\n </table>\n</body>\n</html>" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/264822", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34642/" ]
264,823
<p>Pretty simple question: When i have a persistable object, it usually has a property called ID (for abstract classes).</p> <p>So .. is the naming convention ID or Id?</p> <p>eg.</p> <pre><code>public int ID { get; set; } </code></pre> <p>or</p> <pre><code>public int Id { get; set; } </code></pre> <p>cheers :)</p> <p>PS. This is for .NET btw. FXCop conformat would be a bonus.</p>
[ { "answer_id": 264840, "author": "Mecki", "author_id": 15809, "author_profile": "https://Stackoverflow.com/users/15809", "pm_score": 3, "selected": false, "text": "getResourceURL\n getResourceUrl\n getResourceURL\nurlOfResource\ncompareUrlToString\n compareURLToString\ncompareUrlToString\n" }, { "answer_id": 782457, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "<Dictionary>\n<Acronyms>\n <CasingExceptions>\n <Acronym>ID</Acronym>\n </CasingExceptions>\n</Acronyms>\n</Dictionary>\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/264823", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30674/" ]
264,825
<p>There is a console Java application which is supposed to run until it is stopped by <kbd>Ctrl</kbd>+<kbd>C</kbd> or closing the console window. How that application can be programmed to execute a clean up code before exit?</p>
[ { "answer_id": 264833, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 5, "selected": true, "text": "class ShutdownHook extends Thread\n{\n public void run()\n {\n // perform shutdown actions\n }\n}\n\n// Then, somewhere in your code\n\nRuntime.getRuntime().addShutdownHook(new ShutdownHook())\n" }, { "answer_id": 9098218, "author": "alok bisht", "author_id": 1182997, "author_profile": "https://Stackoverflow.com/users/1182997", "pm_score": 0, "selected": false, "text": "Thread run() class ShutdownHookclass extends Thread {\n public void run() {\n // perform shutdown actions\n }\n}\n\n//could be written anywhere in your code\nRuntime.getRuntime().addShutdownHook(new ShutdownHookclass())\n" }, { "answer_id": 9098294, "author": "alok bisht", "author_id": 1182997, "author_profile": "https://Stackoverflow.com/users/1182997", "pm_score": 1, "selected": false, "text": "public class Backup {\n\n public static void createBackup(String s)\n {\n\n try{\n String fileName =\"C:\\\\bat\"+ \".bat\";\n FileWriter writer=new FileWriter(fileName);\n String batquery=\"cd C:\\\\Program Files\\\\MySQL\\\\MySQL Server 5.0\\\\bin\"\n + \"\\nmysqldump -uroot -proot bankdb > \\\"\"+s+\".sql\\\"\" \n +\"\\nexit\";\n\n writer.append(batquery);\n writer.close();\n }\n catch(Exception e){e.getMessage();}\n try{\n Process p =Runtime.getRuntime().exec(\"cmd /c start C:\\\\bat.bat\");\n\n }\n catch(Exception e){e.getMessage();}\n ShutDownHook sdh=new ShutDownHook();\n Runtime.getRuntime().addShutdownHook(sdh);\n }\n\n\n}\n\n class ShutDownHook extends Thread\n {\n public void run()\n {\n try\n {\n File f=new File(\"c:/bat.bat\");\n f.delete();\n }\n catch(Exception e){e.getMessage();}\n\n }\n\n }\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/264825", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31993/" ]
264,826
<p>How can I rename a Virtual Directory (or Web Application) in IIS 6.0/7.0 using VBScript?</p>
[ { "answer_id": 6680232, "author": "David", "author_id": 842853, "author_profile": "https://Stackoverflow.com/users/842853", "pm_score": 2, "selected": false, "text": "applicationHost.config c:\\Windows\\System32\\inetsrv\\config\\" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/264826", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
264,828
<p>My servlet application includes a number of library .jars, some of which contain embedded log4j.xml or log4j.properties files. I'd like to ensure that log4j finds my log4j.xml first! I've tried searching for some specification of the priorities of the various classpath elements in a servlet (e.g. does WEB-INF/classes always precede WEB-INF/lib?), or some way to configure or tweak the servlet's classloader so that a given resource directory appears early in the classpath. So far, I've drawn a blank. Any suggestions on ensuring that a servlet .war file loads the correct log4j.xml via the classloader?</p>
[ { "answer_id": 264880, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "Log4jConfigListener" }, { "answer_id": 265378, "author": "matt b", "author_id": 4249, "author_profile": "https://Stackoverflow.com/users/4249", "pm_score": 1, "selected": false, "text": "log4j.configuration" }, { "answer_id": 265552, "author": "Yonatan Maman", "author_id": 20065, "author_profile": "https://Stackoverflow.com/users/20065", "pm_score": 4, "selected": false, "text": "/WEB-INF/ /WEB-INF/classes /WEB-INF/lib/*.jar <Loader delegate=\"true\"/> /WEB-INF/classes /WEB-INF/lib/*.jar /WEB-INF/classes /WEB-INF/lib/*.jar $CATALINA_HOME/lib $CATALINA_HOME/lib/*.jar" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/264828", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6716/" ]
264,857
<p>I have a simple database:</p> <pre><code>ARTICLE ---------- ArticleId (PK), ArticleTitle ..other stuff... USER-ARTICLE ------------ ArchiveId (PK), UserId, ArticleId ..other stuff... </code></pre> <p>The <code>articleId</code>'s are foreign keys. </p> <p>I want to be able to delete a user article row by <code>UserArticleId</code> using the following code,</p> <pre><code>UserArticle myobjtodelete = PersonalArchiveDb.UserArticles.Single(ua =&gt; ua.ArchiveId == 3); PersonalArchiveDb.UserArticles.DeleteOnSubmit(myobjtodelete); PersonalArchiveDb.SubmitChanges(); </code></pre> <p><sup>(Yes I'm aware I can do the statement inside the delete rather than retrieving the object, it was for debugging purposes to make sure the object definitely exists - it does.)</sup></p> <p>When the debugger hits the <code>SubmitChanges()</code> line, I get a runtime error:</p> <blockquote> <p>Specified cast is not valid.</p> </blockquote> <p>Here is the stack trace,</p> <blockquote> <p>at System.Data.Linq.IdentityManager .StandardIdentityManager .SingleKeyManager`2.TryCreateKeyFromValues(Object[] values, V&amp; v) at System.Data.Linq.IdentityManager.StandardIdentityManager.IdentityCache`2.Find(Object[] keyValues) at System.Data.Linq.IdentityManager.StandardIdentityManager.Find(MetaType type, Object[] keyValues) at System.Data.Linq.CommonDataServices.GetCachedObject(MetaType type, Object[] keyValues) at System.Data.Linq.ChangeProcessor.GetOtherItem(MetaAssociation assoc, Object instance) at System.Data.Linq.ChangeProcessor.BuildEdgeMaps() at System.Data.Linq.ChangeProcessor.SubmitChanges(ConflictMode failureMode) at System.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode)<br> at System.Data.Linq.DataContext.SubmitChanges() at Driver_SOC_ASO.Controls.PersonalArchive.ArchiveListing.grdArchive_RowDeleting(Object sender, GridViewDeleteEventArgs e) in C:\work\Driver.Net\Driver-SOC-ASO\Driver-SOC-ASO\Controls\PersonalArchive\ArchiveListing.ascx.cs:line 78 at System.Web.UI.WebControls.GridView.OnRowDeleting(GridViewDeleteEventArgs e) at System.Web.UI.WebControls.GridView.HandleDelete(GridViewRow row, Int32 rowIndex) at System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) at System.Web.UI.WebControls.GridView.RaisePostBackEvent(String eventArgument) at System.Web.UI.WebControls.GridView.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)<br> at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)</p> </blockquote> <p>I am at a loss, any ideas?</p>
[ { "answer_id": 718301, "author": "Rony", "author_id": 51326, "author_profile": "https://Stackoverflow.com/users/51326", "pm_score": 0, "selected": false, "text": "ArticleId" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/264857", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3193/" ]
264,907
<p>I am running a Solr instance on Jetty and when I search using the Solr admin panel, it returns the entire document. What should I do to get only specified fields from each Solr document returned by the search?</p>
[ { "answer_id": 289882, "author": "Andrew Ingram", "author_id": 15687, "author_profile": "https://Stackoverflow.com/users/15687", "pm_score": 8, "selected": true, "text": "/?q=query&fl=field1,field2,field3\n" }, { "answer_id": 48007913, "author": "Nanda Kumar", "author_id": 8647198, "author_profile": "https://Stackoverflow.com/users/8647198", "pm_score": 1, "selected": false, "text": "http://xx.xxx.xx.xx:8983/solr/corename/select?indent=on&q=*:*&wt=json&fl=ImageID,Imagepath,Category\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/264907", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2220518/" ]
264,909
<p>do you have idea, if there would be some nice way to browse/log JMS queues? (I'm using OpenJMS)</p> <p>For topics I can just add one consumer more and that's about it but with queues I haven't finished with a solution yet. I would like to log all the messages in certain queues and topics without "popping" them from the queue (so that the logger counld browse queues "invisible").</p> <p>With <strong>javax.jms.QueueBrowser</strong> i can get a snapshot of the queues but that doesn't seem to provide "listener solution" - reading all the messages on the queues on infinite loop again and again and hoping that no messages happen to be both written and consumed before my snapshots - that didn't sound like a good solution.</p> <p>Another option would be to create two queues for each "logical queue" - one for logger and one for the actual use - logger would then forward the messages to the "actual queue" - that could maybe work but there could be better solution?</p> <p>So if somebody has a solution to get all messages in a queue by an "invisible" logger or some nice other solution for the logging, that'd be cool.</p>
[ { "answer_id": 289882, "author": "Andrew Ingram", "author_id": 15687, "author_profile": "https://Stackoverflow.com/users/15687", "pm_score": 8, "selected": true, "text": "/?q=query&fl=field1,field2,field3\n" }, { "answer_id": 48007913, "author": "Nanda Kumar", "author_id": 8647198, "author_profile": "https://Stackoverflow.com/users/8647198", "pm_score": 1, "selected": false, "text": "http://xx.xxx.xx.xx:8983/solr/corename/select?indent=on&q=*:*&wt=json&fl=ImageID,Imagepath,Category\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/264909", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28482/" ]
264,914
<p>Being used to (and potentially spoiled by) <code>MSSQL</code>, I'm wondering how I can get at tables size in <code>Oracle</code> 10g. I have googled it so I'm now aware that I may not have as easy an option as <code>sp_spaceused</code>. Still the potential answers I got are most of the time outdated or don't work. Probably because I'm no DBA on the schema I'm working with.</p> <p>Would anyone have solutions and or recommendations?</p>
[ { "answer_id": 264975, "author": "Tony Andrews", "author_id": 18747, "author_profile": "https://Stackoverflow.com/users/18747", "pm_score": 3, "selected": false, "text": "begin\n dbms_stats.gather_table_stats('MYSCHEMA','MYTABLE');\nend;\n/\n select blocks, empty_blocks, num_freelist_blocks\nfrom all_tables\nwhere owner = 'MYSCHEMA'\nand table_name = 'MYTABLE';\n begin\n dbms_stats.gather_schema_stats ('MYSCHEMA');\nend;\n/\n\nselect table_name, blocks, empty_blocks, num_freelist_blocks\nfrom user_tables;\n" }, { "answer_id": 265536, "author": "Justin Cave", "author_id": 10397, "author_profile": "https://Stackoverflow.com/users/10397", "pm_score": 5, "selected": false, "text": "OPTIMIZER_MODE USER_TABLES ALL_TABLES DBA_TABLES GATHER_TABLE_STATS sp_spaceused DBMS_SPACE show_space sp_spaceused" }, { "answer_id": 266964, "author": "WW.", "author_id": 14663, "author_profile": "https://Stackoverflow.com/users/14663", "pm_score": 8, "selected": false, "text": "COLUMN TABLE_NAME FORMAT A32\nCOLUMN OBJECT_NAME FORMAT A32\nCOLUMN OWNER FORMAT A10\n\nSELECT\n owner, \n table_name, \n TRUNC(sum(bytes)/1024/1024) Meg,\n ROUND( ratio_to_report( sum(bytes) ) over () * 100) Percent\nFROM\n(SELECT segment_name table_name, owner, bytes\n FROM dba_segments\n WHERE segment_type IN ('TABLE', 'TABLE PARTITION', 'TABLE SUBPARTITION')\n UNION ALL\n SELECT i.table_name, i.owner, s.bytes\n FROM dba_indexes i, dba_segments s\n WHERE s.segment_name = i.index_name\n AND s.owner = i.owner\n AND s.segment_type IN ('INDEX', 'INDEX PARTITION', 'INDEX SUBPARTITION')\n UNION ALL\n SELECT l.table_name, l.owner, s.bytes\n FROM dba_lobs l, dba_segments s\n WHERE s.segment_name = l.segment_name\n AND s.owner = l.owner\n AND s.segment_type IN ('LOBSEGMENT', 'LOB PARTITION')\n UNION ALL\n SELECT l.table_name, l.owner, s.bytes\n FROM dba_lobs l, dba_segments s\n WHERE s.segment_name = l.index_name\n AND s.owner = l.owner\n AND s.segment_type = 'LOBINDEX')\nWHERE owner in UPPER('&owner')\nGROUP BY table_name, owner\nHAVING SUM(bytes)/1024/1024 > 10 /* Ignore really small tables */\nORDER BY SUM(bytes) desc\n;\n" }, { "answer_id": 7104978, "author": "Vijay Chettiar", "author_id": 900269, "author_profile": "https://Stackoverflow.com/users/900269", "pm_score": 0, "selected": false, "text": "select segment_name as tablename, sum(bytes/ (1024 * 1024 * 1024)) as tablesize_in_GB\nFrom dba_segments /* if looking at tables not owned by you else use user_segments */\nwhere segment_name = 'TABLE_WHOSE_SIZE_I_WANT_TO_KNOW'\nand OWNER = 'WHO OWNS THAT TABLE' /* if user_segments is used delete this line */ \ngroup by segment_name ;\n" }, { "answer_id": 10109416, "author": "grokster", "author_id": 502441, "author_profile": "https://Stackoverflow.com/users/502441", "pm_score": 6, "selected": false, "text": "-- Tables + Size MB\nselect owner, table_name, round((num_rows*avg_row_len)/(1024*1024)) MB \nfrom all_tables \nwhere owner not like 'SYS%' -- Exclude system tables.\nand num_rows > 0 -- Ignore empty Tables.\norder by MB desc -- Biggest first.\n;\n\n\n--Tables + Rows\nselect owner, table_name, num_rows\n from all_tables \nwhere owner not like 'SYS%' -- Exclude system tables.\nand num_rows > 0 -- Ignore empty Tables.\norder by num_rows desc -- Biggest first.\n;\n exec dbms_utility.analyze_schema(user,'COMPUTE');\n" }, { "answer_id": 10927004, "author": "Geoffrey Musafu", "author_id": 1441502, "author_profile": "https://Stackoverflow.com/users/1441502", "pm_score": 0, "selected": false, "text": "SELECT\n owner, table_name, TRUNC(sum(bytes)/1024/1024/1024) GB\nFROM\n(SELECT segment_name table_name, owner, bytes\nFROM dba_segments\nWHERE segment_type in ('TABLE','TABLE PARTITION')\nUNION ALL\nSELECT i.table_name, i.owner, s.bytes\nFROM dba_indexes i, dba_segments s\nWHERE s.segment_name = i.index_name\nAND s.owner = i.owner\nAND s.segment_type in ('INDEX','INDEX PARTITION')\nUNION ALL\nSELECT l.table_name, l.owner, s.bytes\nFROM dba_lobs l, dba_segments s\nWHERE s.segment_name = l.segment_name\nAND s.owner = l.owner\nAND s.segment_type IN ('LOBSEGMENT','LOB PARTITION')\nUNION ALL\nSELECT l.table_name, l.owner, s.bytes\nFROM dba_lobs l, dba_segments s\nWHERE s.segment_name = l.index_name\nAND s.owner = l.owner\nAND s.segment_type = 'LOBINDEX')\n---WHERE owner in UPPER('&owner')\nGROUP BY table_name, owner\nHAVING SUM(bytes)/1024/1024 > 10 /* Ignore really small tables */\nORDER BY SUM(bytes) desc\n" }, { "answer_id": 13947612, "author": "rratina", "author_id": 1915068, "author_profile": "https://Stackoverflow.com/users/1915068", "pm_score": 3, "selected": false, "text": "\n\n SELECT owner, table_name, ROUND(sum(bytes)/1024/1024/1024, 2) GB\n FROM\n (SELECT segment_name table_name, owner, bytes\n FROM dba_segments\n WHERE segment_type IN ('TABLE', 'TABLE PARTITION', 'TABLE SUBPARTITION')\n UNION ALL\n SELECT i.table_name, i.owner, s.bytes\n FROM dba_indexes i, dba_segments s\n WHERE s.segment_name = i.index_name\n AND s.owner = i.owner\n AND s.segment_type IN ('INDEX', 'INDEX PARTITION', 'INDEX SUBPARTITION')\n UNION ALL\n SELECT l.table_name, l.owner, s.bytes\n FROM dba_lobs l, dba_segments s\n WHERE s.segment_name = l.segment_name\n AND s.owner = l.owner\n AND s.segment_type = 'LOBSEGMENT'\n UNION ALL\n SELECT l.table_name, l.owner, s.bytes\n FROM dba_lobs l, dba_segments s\n WHERE s.segment_name = l.index_name\n AND s.owner = l.owner\n AND s.segment_type = 'LOBINDEX')\n WHERE owner in UPPER('&owner')\n GROUP BY table_name, owner\n HAVING SUM(bytes)/1024/1024 > 10 /* Ignore really small tables */\n ORDER BY SUM(bytes) DESC\n ;\n\n" }, { "answer_id": 15666753, "author": "SS64", "author_id": 1720814, "author_profile": "https://Stackoverflow.com/users/1720814", "pm_score": 3, "selected": false, "text": "SELECT\n owner, \"Type\", table_name \"Name\", TRUNC(sum(bytes)/1024/1024) Meg\nFROM\n( SELECT segment_name table_name, owner, bytes, 'Table' as \"Type\"\n FROM dba_segments\n WHERE segment_type in ('TABLE','TABLE PARTITION','TABLE SUBPARTITION')\n UNION ALL\n SELECT i.table_name, i.owner, s.bytes, 'Index' as \"Type\"\n FROM dba_indexes i, dba_segments s\n WHERE s.segment_name = i.index_name\n AND s.owner = i.owner\n AND s.segment_type in ('INDEX','INDEX PARTITION','INDEX SUBPARTITION')\n UNION ALL\n SELECT l.table_name, l.owner, s.bytes, 'LOB' as \"Type\"\n FROM dba_lobs l, dba_segments s\n WHERE s.segment_name = l.segment_name\n AND s.owner = l.owner\n AND s.segment_type IN ('LOBSEGMENT','LOB PARTITION','LOB SUBPARTITION')\n UNION ALL\n SELECT l.table_name, l.owner, s.bytes, 'LOB Index' as \"Type\"\n FROM dba_lobs l, dba_segments s\n WHERE s.segment_name = l.index_name\n AND s.owner = l.owner\n AND s.segment_type = 'LOBINDEX')\n WHERE owner in UPPER('&owner')\nGROUP BY table_name, owner, \"Type\"\nHAVING SUM(bytes)/1024/1024 > 10 /* Ignore really small tables */\nORDER BY SUM(bytes) desc;\n" }, { "answer_id": 16661034, "author": "Sergey Stadnik", "author_id": 10557, "author_profile": "https://Stackoverflow.com/users/10557", "pm_score": 3, "selected": false, "text": "SELECT * FROM (\n SELECT\n owner, object_name, object_type, table_name, ROUND(bytes)/1024/1024 AS meg,\n tablespace_name, extents, initial_extent,\n ROUND(Sum(bytes/1024/1024) OVER (PARTITION BY table_name)) AS total_table_meg\n FROM (\n -- Tables\n SELECT owner, segment_name AS object_name, 'TABLE' AS object_type,\n segment_name AS table_name, bytes,\n tablespace_name, extents, initial_extent\n FROM dba_segments\n WHERE segment_type IN ('TABLE', 'TABLE PARTITION', 'TABLE SUBPARTITION')\n UNION ALL\n -- Indexes\n SELECT i.owner, i.index_name AS object_name, 'INDEX' AS object_type,\n i.table_name, s.bytes,\n s.tablespace_name, s.extents, s.initial_extent\n FROM dba_indexes i, dba_segments s\n WHERE s.segment_name = i.index_name\n AND s.owner = i.owner\n AND s.segment_type IN ('INDEX', 'INDEX PARTITION', 'INDEX SUBPARTITION')\n -- LOB Segments\n UNION ALL\n SELECT l.owner, l.column_name AS object_name, 'LOB_COLUMN' AS object_type,\n l.table_name, s.bytes,\n s.tablespace_name, s.extents, s.initial_extent\n FROM dba_lobs l, dba_segments s\n WHERE s.segment_name = l.segment_name\n AND s.owner = l.owner\n AND s.segment_type = 'LOBSEGMENT'\n -- LOB Indexes\n UNION ALL\n SELECT l.owner, l.column_name AS object_name, 'LOB_INDEX' AS object_type,\n l.table_name, s.bytes,\n s.tablespace_name, s.extents, s.initial_extent\n FROM dba_lobs l, dba_segments s\n WHERE s.segment_name = l.index_name\n AND s.owner = l.owner\n AND s.segment_type = 'LOBINDEX'\n )\n WHERE owner = UPPER('&owner')\n)\nWHERE total_table_meg > 10\nORDER BY total_table_meg DESC, meg DESC\n/\n" }, { "answer_id": 17177068, "author": "user2498491", "author_id": 2498491, "author_profile": "https://Stackoverflow.com/users/2498491", "pm_score": -1, "selected": false, "text": "CREATE OR REPLACE FUNCTION\n SYS.RAZMER_TABLICY_RAW(pNazvanie in varchar, pOwner in varchar2)\nreturn number\nis\n val number(16);\n sz number(16);\nbegin\n sz := 0;\n\n --Calculate size of table data segments\n select\n sum(t.bytes) into val\n from\n sys.dba_segments t\n where\n t.segment_name = upper(pNazvanie)\n and\n t.owner = upper(pOwner);\n sz := sz + nvl(val,0);\n\n --Calculate size of table indexes segments\n select\n sum(s.bytes) into val\n from\n all_indexes t\n inner join\n dba_segments s\n on\n t.index_name = s.segment_name\n where\n t.table_name = upper(pNazvanie)\n and\n t.owner = upper(pOwner);\n sz := sz + nvl(val,0);\n\n --Calculate size of table blob segments\n select\n sum(s.bytes) into val\n from\n all_lobs t\n inner join\n dba_segments s on t.segment_name = s.segment_name\n where\n t.table_name = upper(pNazvanie)\n and\n t.owner = upper(pOwner);\n sz := sz + nvl(val,0);\n\n return sz;\n\nend razmer_tablicy_raw;\n" }, { "answer_id": 19784650, "author": "mrvlad", "author_id": 1559870, "author_profile": "https://Stackoverflow.com/users/1559870", "pm_score": -1, "selected": false, "text": "-- 1\nEXPLAIN PLAN\n FOR\n SELECT\n Scheme.Table_name.table_column1 AS \"column1\",\n Scheme.Table_name.table_column2 AS \"column2\",\n Scheme.Table_name.table_column3 AS \"column3\",\n FROM Scheme.Table_name\n WHERE ;\n\nSELECT * FROM TABLE (DBMS_XPLAN.display);\n" }, { "answer_id": 20603961, "author": "rratina", "author_id": 3106111, "author_profile": "https://Stackoverflow.com/users/3106111", "pm_score": 1, "selected": false, "text": "SELECT owner, table_name, ROUND(sum(bytes)/1024/1024/1024, 2) GB\nFROM\n(SELECT segment_name table_name, owner, bytes\n FROM dba_segments\n WHERE segment_type IN ('TABLE', 'TABLE PARTITION', 'TABLE SUBPARTITION')\n UNION ALL\n SELECT i.table_name, i.owner, s.bytes\n FROM dba_indexes i, dba_segments s\n WHERE s.segment_name = i.index_name\n AND s.owner = i.owner\n AND s.segment_type IN ('INDEX', 'INDEX PARTITION', 'INDEX SUBPARTITION')\n UNION ALL\n SELECT l.table_name, l.owner, s.bytes\n FROM dba_lobs l, dba_segments s\n WHERE s.segment_name = l.segment_name\n and s.owner = l.owner\n AND s.segment_type in ('LOBSEGMENT', 'LOB PARTITION', 'LOB SUBPARTITION')\n UNION ALL\n SELECT l.table_name, l.owner, s.bytes\n FROM dba_lobs l, dba_segments s\n WHERE s.segment_name = l.index_name\n AND s.owner = l.owner\n AND s.segment_type = 'LOBINDEX')\nWHERE owner in UPPER('&owner')\nGROUP BY table_name, owner\nHAVING SUM(bytes)/1024/1024 > 10 /* Ignore really small tables */\norder by sum(bytes) desc\n;\n" }, { "answer_id": 23098053, "author": "bronx", "author_id": 3331762, "author_profile": "https://Stackoverflow.com/users/3331762", "pm_score": 2, "selected": false, "text": "select segment_name,segment_type,bytes/1024/1024 MB\nfrom dba_segments\nwhere segment_name='TABLENAME' and owner ='OWNERNAME' order by mb desc;\n" }, { "answer_id": 47378564, "author": "Najee Ghanim", "author_id": 4481610, "author_profile": "https://Stackoverflow.com/users/4481610", "pm_score": 2, "selected": false, "text": "SELECT owner,\n tablespace_name,\n TRUNC (SUM (bytes) / 1024 / 1024) Meg,\n ROUND (ratio_to_report (SUM (bytes)) OVER () * 100) Percent\nFROM (SELECT tablespace_name, owner, bytes\n FROM dba_segments\n WHERE segment_type IN\n ('TABLE', 'TABLE PARTITION', 'TABLE SUBPARTITION')\n UNION ALL\n SELECT i.tablespace_name, i.owner, s.bytes\n FROM dba_indexes i, dba_segments s\n WHERE s.segment_name = i.index_name\n AND s.owner = i.owner\n AND s.segment_type IN\n ('INDEX', 'INDEX PARTITION', 'INDEX SUBPARTITION')\n UNION ALL\n SELECT l.tablespace_name, l.owner, s.bytes\n FROM dba_lobs l, dba_segments s\n WHERE s.segment_name = l.segment_name\n AND s.owner = l.owner\n AND s.segment_type IN ('LOBSEGMENT', 'LOB PARTITION')\n UNION ALL\n SELECT l.tablespace_name, l.owner, s.bytes\n FROM dba_lobs l, dba_segments s\n WHERE s.segment_name = l.index_name\n AND s.owner = l.owner\n AND s.segment_type = 'LOBINDEX')\nWHERE owner IN UPPER ('&owner')\nGROUP BY owner, tablespace_name\n--HAVING SUM(bytes)/1024/1024 > 10 /* Ignore really small tables */\nORDER BY tablespace_name -- desc\n;\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/264914", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11477/" ]
264,917
<p>I want to create own header.jsp file instead of the one included in the JBoss Portal 2.6 but have to support the locale set by the user.</p> <p>The original header.jsp does not contain any i18n and I don't know how to do it, especially how to get the actual locale.</p>
[ { "answer_id": 569501, "author": "johnbr", "author_id": 376254, "author_profile": "https://Stackoverflow.com/users/376254", "pm_score": 1, "selected": false, "text": "<%@ taglib uri=\"http://java.sun.com/jsp/jstl/fmt\" prefix=\"fmt\" %>\n\n<%\n locale = request.getLocale() // get the user's locale from the HttpServletRequest\n\n%>\n <fmt:setLocale value=\"<%= locale %>\" />\n\n<fmt:setBundle basename=\"header\" />\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/264917", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25326/" ]
264,924
<p>We have a page that ordinarily has two elements arranged side-by-side. Despite exploring a few angles for this, we can't seem to make it work. We're not averse to using JavaScript, it just feels that a CSS based solution ought to be possible. Is there a way of using just CSS (and possibly extra markup if necessary) to make <code>element2</code> centre when it appears on its own?</p> <h1>Examples</h1> <p>Sometimes we have two elements, side by side.</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div id="container"&gt; &lt;div id="element1"&gt;content&lt;/div&gt; &lt;div id="element2"&gt;content&lt;/div&gt; &lt;/div&gt;</code></pre> </div> </div> </p> <p>But in some conditions only <code>element2</code> is on the page e.g.:</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div id="container"&gt; &lt;div id="element2"&gt;content&lt;/div&gt; &lt;/div&gt;</code></pre> </div> </div> </p>
[ { "answer_id": 264980, "author": "philnash", "author_id": 28376, "author_profile": "https://Stackoverflow.com/users/28376", "pm_score": 4, "selected": true, "text": "div#element2{\n width:100px;\n margin:0 auto;\n}\ndiv#element1{\n width:50px;\n float:left;\n}\ndiv#element1 + div#element2{\n width:50px;\n float:left;\n margin:0;\n}\n" }, { "answer_id": 267146, "author": "Steve Clay", "author_id": 3779, "author_profile": "https://Stackoverflow.com/users/3779", "pm_score": 0, "selected": false, "text": "#container {\n text-align:center;\n}\n#element1, #element2 {\n display:inline-block;\n}\n" }, { "answer_id": 267167, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "<style>\n #container {\n margin:0 auto;\n width:100px;\n }\n\n #container table{\n width: 100%;\n text-align:center;\n }\n\n #element1{ \n background-color:#0000ff;\n }\n\n #element2 {\n background-color: #ff0000;\n }\n</style>\n\n<div id=container>\n <table cellspacing=0 cellpadding=0>\n <tr>\n <td id=\"element1\">content</td>\n <td id=\"element2\">content</td>\n </tr>\n </table>\n</div>\n" }, { "answer_id": 267203, "author": "Bill the Lizard", "author_id": 1288, "author_profile": "https://Stackoverflow.com/users/1288", "pm_score": 2, "selected": false, "text": "last-child first-child last-child if div#container div#element2:last-child {\n width:100px;\n margin:0 auto;\n}\n\ndiv#element1{\n width:50px;\n float:left;\n}\n\ndiv##element2{\n width:50px;\n float:left;\n margin:0;\n}\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/264924", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2977/" ]
264,930
<p>I'm still working with this huge list of URLs, all the help I have received has been great.</p> <p>At the moment I have the list looking like this (17000 URLs though):</p> <ul> <li><code>http://www.example.com/page?CONTENT_ITEM_ID=1</code></li> <li><code>http://www.example.com/page?CONTENT_ITEM_ID=3</code></li> <li><code>http://www.example.com/page?CONTENT_ITEM_ID=2</code></li> <li><code>http://www.example.com/page?CONTENT_ITEM_ID=1</code></li> <li><code>http://www.example.com/page?CONTENT_ITEM_ID=2</code></li> <li><code>http://www.example.com/page?CONTENT_ITEM_ID=3</code></li> <li><code>http://www.example.com/page?CONTENT_ITEM_ID=3</code></li> </ul> <p>I can filter out the duplicates no problem with a couple of methods, awk etc. What I am really looking to do it take out the duplicate URLs but at the same time taking a count of how many times the URL exists in the list and printing the count next to the URL with a pipe separator. After processing the list it should look like this:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>url</th> <th>count</th> </tr> </thead> <tbody> <tr> <td><code>http://www.example.com/page?CONTENT_ITEM_ID=1</code></td> <td>2</td> </tr> <tr> <td><code>http://www.example.com/page?CONTENT_ITEM_ID=2</code></td> <td>2</td> </tr> <tr> <td><code>http://www.example.com/page?CONTENT_ITEM_ID=3</code></td> <td>3</td> </tr> </tbody> </table> </div> <p>What method would be the fastest way to achieve this?</p>
[ { "answer_id": 264942, "author": "S.Lott", "author_id": 10661, "author_profile": "https://Stackoverflow.com/users/10661", "pm_score": 2, "selected": false, "text": "from collections import defaultdict\nmyFile = open( \"urlFile\", \"ru\" )\nfq= defaultdict( int )\nfor n in myFile:\n fq[n] += 1\n\nfor url, count in fq.iteritems():\n print url.rstrip(), \"|\", count\n" }, { "answer_id": 264969, "author": "toolkit", "author_id": 3295, "author_profile": "https://Stackoverflow.com/users/3295", "pm_score": 2, "selected": false, "text": "while (<>) {\n chomp;\n $occurences{$_}++;\n}\nforeach $url (sort keys %occurences) {\n printf \"%s|%d\\n\", $url, $occurences{$url};\n}\n" }, { "answer_id": 265145, "author": "The Archetypal Paul", "author_id": 21755, "author_profile": "https://Stackoverflow.com/users/21755", "pm_score": 3, "selected": true, "text": "sort </file/of/urls | uniq --count | awk '{ print $2, \" | \", $1}'\n" }, { "answer_id": 297512, "author": "jfs", "author_id": 4279, "author_profile": "https://Stackoverflow.com/users/4279", "pm_score": 1, "selected": false, "text": "import fileinput, itertools\n\nurls = sorted(fileinput.input())\nfor url, sameurls in itertools.groupby(urls):\n print url.rstrip(), \"|\", sum(1 for _ in sameurls)\n $ cat foo.txt\nhttp://www.example.com/page?CONTENT_ITEM_ID=1\nhttp://www.example.com/page?CONTENT_ITEM_ID=3\nhttp://www.example.com/page?CONTENT_ITEM_ID=2\nhttp://www.example.com/page?CONTENT_ITEM_ID=1\nhttp://www.example.com/page?CONTENT_ITEM_ID=2\nhttp://www.example.com/page?CONTENT_ITEM_ID=3\nhttp://www.example.com/page?CONTENT_ITEM_ID=3\n\n$ python countuniq.py foo.txt\nhttp://www.example.com/page?CONTENT_ITEM_ID=1 | 2\nhttp://www.example.com/page?CONTENT_ITEM_ID=2 | 2\nhttp://www.example.com/page?CONTENT_ITEM_ID=3 | 3\n C:\\> timethis \"sort urls17000.txt|uniq -c\"\n...\nTimeThis : Elapsed Time : 00:00:00.688\n\nC:\\> timethis python countuniq.py urls17000.txt\n...\nTimeThis : Elapsed Time : 00:00:00.625\n\nC:\\> timethis python slott.py urls17000.txt\n...\nTimeThis : Elapsed Time : 00:00:00.562\n\nC:\\> timethis perl toolkit.pl urls17000.txt\n...\nTimeThis : Elapsed Time : 00:00:00.187\n C:\\> timethis perl toolkit.pl urls1778955.txt\n...\nTimeThis : Elapsed Time : 00:00:17.656\n\nC:\\> timethis \"sort urls1778955.txt|uniq -c\"\n...\nTimeThis : Elapsed Time : 00:01:54.234\n\n$ wc urls1778955.txt\n1778955 1778955 81831930 urls1778955.txt\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/264930", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30786/" ]
264,937
<p>Currently i have this method:</p> <pre><code>static boolean checkDecimalPlaces(double d, int decimalPlaces){ if (d==0) return true; double multiplier = Math.pow(10, decimalPlaces); double check = d * multiplier; check = Math.round(check); check = check/multiplier; return (d==check); } </code></pre> <p>But this method fails for <code>checkDecmialPlaces(649632196443.4279, 4)</code> probably because I do base 10 math on a base 2 number.</p> <p>So how can this check be done correctly?</p> <p>I thought of getting a string representation of the double value and then check that with a regexp - but that felt weird.</p> <p><strong>EDIT:</strong> Thanks for all the answers. There are cases where I really get a double and for those cases I implemented the following: </p> <pre><code>private static boolean checkDecimalPlaces(double d, int decimalPlaces) { if (d == 0) return true; final double epsilon = Math.pow(10.0, ((decimalPlaces + 1) * -1)); double multiplier = Math.pow(10, decimalPlaces); double check = d * multiplier; long checkLong = (long) Math.abs(check); check = checkLong / multiplier; double e = Math.abs(d - check); return e &lt; epsilon; } </code></pre> <p>I changed the <code>round</code> to a truncation. Seems that the computation done in <code>round</code> increases the inaccuracy too much. At least in the failing testcase.<br> As some of you pointed out if I could get to the 'real' string input I should use <code>BigDecimal</code> to check and so I have done: </p> <pre><code>BigDecimal decimal = new BigDecimal(value); BigDecimal checkDecimal = decimal.movePointRight(decimalPlaces); return checkDecimal.scale() == 0; </code></pre> <p>The <code>double</code> value I get comes from the Apache POI API that reads excel files. I did a few tests and found out that although the API returns <code>double</code> values for numeric cells I can get a accurate representation when I immediately format that <code>double</code> with the <code>DecimalFormat</code>: </p> <pre><code>DecimalFormat decimalFormat = new DecimalFormat(); decimalFormat.setMaximumIntegerDigits(Integer.MAX_VALUE); // don't use grouping for numeric-type cells decimalFormat.setGroupingUsed(false); decimalFormat.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US)); value = decimalFormat.format(numericValue); </code></pre> <p>This also works for values that can't be represented exactly in binary format.</p>
[ { "answer_id": 264947, "author": "paxdiablo", "author_id": 14860, "author_profile": "https://Stackoverflow.com/users/14860", "pm_score": 2, "selected": false, "text": "return (d==check);\n return (Math.abs(d-check) <= 0.0000001);\n" }, { "answer_id": 264952, "author": "Ned Batchelder", "author_id": 14343, "author_profile": "https://Stackoverflow.com/users/14343", "pm_score": 1, "selected": false, "text": "double" }, { "answer_id": 264968, "author": "Ken Gentle", "author_id": 8709, "author_profile": "https://Stackoverflow.com/users/8709", "pm_score": 3, "selected": false, "text": "scale" }, { "answer_id": 265011, "author": "tvanfosson", "author_id": 12950, "author_profile": "https://Stackoverflow.com/users/12950", "pm_score": 0, "selected": false, "text": "1.0e-13 0 static boolean checkDecimalPlaces(double d, unsigned int decimalPlaces){\n // take advantage of truncation, may need to use BigInt here\n // depending on your range\n double d_abs = Math.abs(d);\n unsigned long d_i = d_abs; \n unsigned long e = (d_abs - d_i) * Math.pow(10, decimalPlaces);\n return e > 0;\n }\n" }, { "answer_id": 265082, "author": "David Schmitt", "author_id": 4918, "author_profile": "https://Stackoverflow.com/users/4918", "pm_score": 4, "selected": true, "text": "n+1 d - round(d) epsilon d (d - round(d)) * 10^n epsilon n DoubleConverter d" }, { "answer_id": 4625738, "author": "Norm Wright", "author_id": 412153, "author_profile": "https://Stackoverflow.com/users/412153", "pm_score": 1, "selected": false, "text": " public int calcBase10Exponet (Number increment)\n {\n //toSting of 0.0=0.0\n //toSting of 1.0=1.0\n //toSting of 10.0=10.0\n //toSting of 100.0=100.0\n //toSting of 1000.0=1000.0\n //toSting of 10000.0=10000.0\n //toSting of 100000.0=100000.0\n //toSting of 1000000.0=1000000.0\n //toSting of 1.0E7=1.0E7\n //toSting of 1.0E8=1.0E8\n //toSting of 1.0E9=1.0E9\n //toSting of 1.0E10=1.0E10\n //toSting of 1.0E11=1.0E11\n //toSting of 0.1=0.1\n //toSting of 0.01=0.01\n //toSting of 0.0010=0.0010 <== need to trim off this extra zero\n //toSting of 1.0E-4=1.0E-4\n //toSting of 1.0E-5=1.0E-5\n //toSting of 1.0E-6=1.0E-6\n //toSting of 1.0E-7=1.0E-7\n //toSting of 1.0E-8=1.0E-8\n //toSting of 1.0E-9=1.0E-9\n //toSting of 1.0E-10=1.0E-10\n //toSting of 1.0E-11=1.0E-11\n double dbl = increment.doubleValue ();\n String str = Double.toString (dbl);\n// System.out.println (\"NumberBoxDefaultPatternCalculator: toSting of \" + dbl + \"=\" + str);\n if (str.contains (\"E\"))\n {\n return Integer.parseInt (str.substring (str.indexOf (\"E\") + 1));\n }\n if (str.endsWith (\".0\"))\n {\n return str.length () - 3;\n }\n while (str.endsWith (\"0\"))\n {\n str = str.substring (0, str.length () - 1);\n }\n return - (str.length () - str.indexOf (\".\") - 1);\n }\n" }, { "answer_id": 57309113, "author": "Dt D", "author_id": 8614269, "author_profile": "https://Stackoverflow.com/users/8614269", "pm_score": 1, "selected": false, "text": "private int checkPrecisionOfDouble(Double atribute) {\n String s = String.valueOf(atribute);\n String[] split = s.split(\"\\\\.\");\n return split[1].length();\n}\n private boolean checkPrecisionOfDouble(Double atribute, int decimalPlaces) {\n String s = String.valueOf(atribute);\n String[] split = s.split(\"\\\\.\");\n\n return split[1].length() == decimalPlaces;\n}\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/264937", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5271/" ]
264,950
<p>I am using a machine on which I do not have root access and would like to access files on a Samba server in random access mode. I know I can transfer the files in their entirety using smbclient but the files are very large (>1GB) and I would rather just treat them as remote files on which I can do random access.</p> <p>The problem as noted is that I don't have root access to this machine (a Linux box) so I can't mount the remote Samba file system. </p> <p>Is there a user-level solution that will let me randomly access the contents of a file on a Samba server? Seems it should be possible to do everything that the kernel file system client is doing but from a user-level application.</p> <p>I only need read-only access btw and the remote file is guaranteed not to change.</p>
[ { "answer_id": 264963, "author": "xsl", "author_id": 11387, "author_profile": "https://Stackoverflow.com/users/11387", "pm_score": 0, "selected": false, "text": "smbmount mkdir ~/temp\nsmbmount //{server}/{share} ~/temp -o username=username={username},password={password}\n smbmount mount" }, { "answer_id": 268478, "author": "Dave Griffiths", "author_id": 15379, "author_profile": "https://Stackoverflow.com/users/15379", "pm_score": 3, "selected": true, "text": "fd = smbc_open(path, O_RDONLY, 0);\nsmbc_fstat(fd, &st);\n\nfor (offset = st.st_size - BUFLEN; offset > 0; offset -= BUFLEN) {\n smbc_lseek(fd, offset, SEEK_SET);\n smbc_read(fd, buffer, BUFLEN);\n}\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/264950", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15379/" ]
264,951
<p>I'm just in the middle of revisiting maven. Our team had a bad experience when we last looked at this, as it was during the period when maven was rearchitecting from 1.x to 2.x, so a lot of the dependencies we needed hadn't been moved across to the new repositories. However, I have the time to reconsider now.</p> <p>I am interested in using maven and either LaTeX or DocBook for creating documentation, and I was wondering if anyone had any experiences to share, project/module structure, good plugins to use, etc...</p> <p>Many thanks :-)</p> <p>Edit:</p> <p>Just to clarify, I was looking to write a technical article/book, and my desired artifact would probably be a PDF.</p>
[ { "answer_id": 265015, "author": "lindelof", "author_id": 1428, "author_profile": "https://Stackoverflow.com/users/1428", "pm_score": -1, "selected": false, "text": "<plugin>\n <groupId>org.codehaus.mojo</groupId>\n <artifactId>exec-maven-plugin</artifactId>\n <executions>\n <execution>\n <id>latex</id>\n <goals>\n <goal>exec</goal>\n </goals>\n <phase>site</phase>\n <configuration>\n ...\n </configuration>\n </execution>\n </executions>\n</plugin>\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/264951", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3295/" ]
264,962
<p>I need to search a string in the string array. I dont want to use any for looping in it</p> <pre><code>string [] arr = {"One","Two","Three"}; string theString = "One" </code></pre> <p>I need to check whether theString variable is present in arr.</p>
[ { "answer_id": 264970, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 7, "selected": false, "text": "bool has = arr.Contains(var); // .NET 3.5\n bool has = Array.IndexOf(arr, var) >= 0;\n" }, { "answer_id": 264974, "author": "ZombieSheep", "author_id": 377, "author_profile": "https://Stackoverflow.com/users/377", "pm_score": 5, "selected": false, "text": "List<String> testing = new List<String>();\ntesting.Add(\"One\");\ntesting.Add(\"Two\");\ntesting.Add(\"Three\");\ntesting.Add(\"Mouse\");\nbool inList = testing.Contains(\"Mouse\");\n" }, { "answer_id": 264985, "author": "mohammedn", "author_id": 29268, "author_profile": "https://Stackoverflow.com/users/29268", "pm_score": 4, "selected": false, "text": "bool exists = arr.Contains(\"One\");\n" }, { "answer_id": 265008, "author": "Salman Kasbati", "author_id": 33931, "author_profile": "https://Stackoverflow.com/users/33931", "pm_score": 2, "selected": false, "text": "int findString(String var, String[] stringArray, int currentIndex, int stringMaxIndex)\n {\n if currentIndex > stringMaxIndex \n return (-stringMaxIndex-1);\n else if var==arr[currentIndex] //or use any string comparison op or function\n return 0;\n else \n return findString(var, stringArray, currentIndex++, stringMaxIndex) + 1 ;\n }\n\n\n\n //calling code\n int index = findString(var, arr, 0, getMaxIndex(arr));\n\n if index == -1 printOnScreen(\"Not found\");\n else printOnScreen(\"Found on index: \" + index);\n" }, { "answer_id": 265048, "author": "DOK", "author_id": 27637, "author_profile": "https://Stackoverflow.com/users/27637", "pm_score": 2, "selected": false, "text": "if MyArrayList.Contains(\"One\")\n" }, { "answer_id": 265067, "author": "bendin", "author_id": 33412, "author_profile": "https://Stackoverflow.com/users/33412", "pm_score": 2, "selected": false, "text": "arr.Contains(...) arr" }, { "answer_id": 265181, "author": "Tamir", "author_id": 30879, "author_profile": "https://Stackoverflow.com/users/30879", "pm_score": 7, "selected": true, "text": " string [] arr = {\"One\",\"Two\",\"Three\"};\n var target = \"One\";\n var results = Array.FindAll(arr, s => s.Equals(target));\n" }, { "answer_id": 19809325, "author": "Sharp Coders", "author_id": 1449894, "author_profile": "https://Stackoverflow.com/users/1449894", "pm_score": 4, "selected": false, "text": "string[] stringArray = { \"text1\", \"text2\", \"text3\", \"text4\" };\nstring value = \"text3\";\nint pos = Array.IndexOf(stringArray, value);\nif (pos > -1)\n{\n return true;\n}\nelse\n{\n return false;\n}\n" }, { "answer_id": 26803126, "author": "Yuliia Ashomok", "author_id": 3627736, "author_profile": "https://Stackoverflow.com/users/3627736", "pm_score": 2, "selected": false, "text": "public static T Find<T>(\n T[] array,\n Predicate<T> match\n)\n // we search an array of strings for a name containing the letter “a”:\nstatic void Main()\n{\n string[] names = { \"Rodney\", \"Jack\", \"Jill\" };\n string match = Array.Find (names, ContainsA);\n Console.WriteLine (match); // Jack\n}\nstatic bool ContainsA (string name) { return name.Contains (\"a\"); }\n string[] names = { \"Rodney\", \"Jack\", \"Jill\" };\nstring match = Array.Find (names, delegate (string name)\n { return name.Contains (\"a\"); } ); // Jack\n string[] names = { \"Rodney\", \"Jack\", \"Jill\" };\nstring match = Array.Find (names, n => n.Contains (\"a\")); // Jack\n" }, { "answer_id": 27312104, "author": "Ahmad", "author_id": 2651073, "author_profile": "https://Stackoverflow.com/users/2651073", "pm_score": 2, "selected": false, "text": "arr.Any(x => x == \"One\")\n" }, { "answer_id": 62878211, "author": "Ali", "author_id": 6741585, "author_profile": "https://Stackoverflow.com/users/6741585", "pm_score": 0, "selected": false, "text": "enter code here" }, { "answer_id": 63104947, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "Array.IndexOf Array.IndexOf int stringIndex = Array.IndexOf(arr, theString);\nif (stringIndex >= 0)\n{\n // theString has been found\n}\n if (Array.IndexOf(arr, theString) >= 0)\n{\n // theString has been found\n}\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/264962", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22162/" ]
265,018
<p>How can I create unicode console application with Delphi 2009?</p> <p>If I do like this:</p> <pre><code>{$APPTYPE CONSOLE} uses SysUtils; begin writeln('öüğşç سيمانتت'); end. </code></pre> <p>I get the following:</p> <pre><code>ougsc ??????? </code></pre>
[ { "answer_id": 265036, "author": "Michał Niklas", "author_id": 22595, "author_profile": "https://Stackoverflow.com/users/22595", "pm_score": 0, "selected": false, "text": "my_app.exe > unicode_file.txt\n" }, { "answer_id": 266305, "author": "mghie", "author_id": 30568, "author_profile": "https://Stackoverflow.com/users/30568", "pm_score": 4, "selected": true, "text": "program test;\n\n{$APPTYPE CONSOLE}\n\nuses\n Windows;\n\nvar\n s: WideString;\n i: integer;\n Written: Cardinal;\nbegin\n SetLength(s, 80);\n for i := 1 to 80 do\n s[i] := WideChar(48 + i);\n WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), PWideChar(s), 80, Written,\n nil);\nend.\n" }, { "answer_id": 278204, "author": "PatrickvL", "author_id": 12170, "author_profile": "https://Stackoverflow.com/users/12170", "pm_score": 0, "selected": false, "text": "SetConsoleOutputCP(CP_UTF8)\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265018", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
265,051
<p>A co-worker recently ran into a situation where a query to look up security permissions was taking ~15 seconds to run using an = comparison on UserID (which is a UNIQUEIDENTIFIER). Needless to say, the users were less than impressed.</p> <p>Out of frustration, my co-worker changed the = comparison to use a LIKE and the query sped up to under 1 second.</p> <p>Without knowing anything about the data schema (I don't have access to the database or execution plans), what could potentially cause this change in performance?</p> <p>(Broad and vague question, I know)</p>
[ { "answer_id": 265064, "author": "Cade Roux", "author_id": 18255, "author_profile": "https://Stackoverflow.com/users/18255", "pm_score": 1, "selected": false, "text": "LIKE SUBSTRING SQL" }, { "answer_id": 265107, "author": "Mike Burton", "author_id": 22225, "author_profile": "https://Stackoverflow.com/users/22225", "pm_score": 3, "selected": false, "text": "CONVERT(varchar, variable) = othervariable\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265051", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11780/" ]
265,062
<p>I'm looking for an example of how to load an image from file and print it on a page using WPF. I'm having a hard time finding good information about WPF printing.</p>
[ { "answer_id": 265127, "author": "MojoFilter", "author_id": 93, "author_profile": "https://Stackoverflow.com/users/93", "pm_score": 0, "selected": false, "text": "...\nPrintDialog printer = new PrintDialog();\n\nif (printer.ShowDialog()) {\n printer.PrintVisual(myVisual, \"A Page Title\");\n}\n" }, { "answer_id": 265155, "author": "Tamir", "author_id": 30879, "author_profile": "https://Stackoverflow.com/users/30879", "pm_score": 6, "selected": true, "text": "var bi = new BitmapImage();\nbi.BeginInit();\nbi.CacheOption = BitmapCacheOption.OnLoad;\nbi.UriSource = new Uri(\"\");\nbi.EndInit();\n\nvar vis = new DrawingVisual();\nusing (var dc = vis.RenderOpen())\n{\n dc.DrawImage(bi, new Rect { Width = bi.Width, Height = bi.Height });\n}\n\nvar pdialog = new PrintDialog();\nif (pdialog.ShowDialog() == true)\n{\n pdialog.PrintVisual(vis, \"My Image\");\n}\n" }, { "answer_id": 63384548, "author": "schorsch1989", "author_id": 1542368, "author_profile": "https://Stackoverflow.com/users/1542368", "pm_score": 1, "selected": false, "text": " PrintDialog dlg = new PrintDialog();\n\n if (dlg.ShowDialog() == true)\n {\n BitmapImage bmi = new BitmapImage(new Uri(strPath));\n\n Image img = new Image();\n img.Source = bmi;\n\n if (bmi.PixelWidth < dlg.PrintableAreaWidth ||\n bmi.PixelHeight < dlg.PrintableAreaHeight)\n {\n img.Stretch = Stretch.None;\n img.Width = bmi.PixelWidth;\n img.Height = bmi.PixelHeight;\n }\n\n\n if (dlg.PrintTicket.PageBorderless == PageBorderless.Borderless)\n {\n img.Margin = new Thickness(0);\n }\n else\n {\n img.Margin = new Thickness(48);\n }\n img.VerticalAlignment = VerticalAlignment.Top;\n img.HorizontalAlignment = HorizontalAlignment.Left;\n\n for (int i = 0; i < dlg.PrintTicket.CopyCount; i++)\n {\n dlg.PrintVisual(img, \"Print a Large Image\");\n }\n }\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265062", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18153/" ]
265,073
<p>I'm trying to make a PHP script, I have the script finished but it takes like 10 minutes to finish the process it is designed to do. This is not a problem, however I presume I have to keep the page loaded all this time which is annoying. Can I have it so that I start the process and then come back 10mins later and just view the log file it has generated?</p>
[ { "answer_id": 265088, "author": "Greg", "author_id": 24181, "author_profile": "https://Stackoverflow.com/users/24181", "pm_score": 2, "selected": false, "text": "ignore_user_abort()" }, { "answer_id": 265090, "author": "bastiandoeen", "author_id": 371953, "author_profile": "https://Stackoverflow.com/users/371953", "pm_score": 7, "selected": true, "text": "ignore_user_abort(true); \nset_time_limit(0);\n" }, { "answer_id": 265221, "author": "Christopher Lightfoot", "author_id": 24525, "author_profile": "https://Stackoverflow.com/users/24525", "pm_score": 3, "selected": false, "text": "pclose(popen(\"start php myscript.php\", \"r\"));" }, { "answer_id": 267853, "author": "Ronald Conco", "author_id": 16092, "author_profile": "https://Stackoverflow.com/users/16092", "pm_score": 2, "selected": false, "text": "> #!/usr/bin/php -q\n\n<?php\n\n//process logs\n\n?>\n" }, { "answer_id": 21063019, "author": "Nader", "author_id": 2336478, "author_profile": "https://Stackoverflow.com/users/2336478", "pm_score": 1, "selected": false, "text": "<?php \n\npclose(popen('php /path/to/file/server.php &'));\necho \"Server started. [OK]\"; \n\n?>\n ignore_user_abort(true); \nset_time_limit(0);\n <?php\n\n$output;\nexec('ps aux | grep -ie /path/to/file/server.php | awk \\'{print $2}\\' | xargs kill -9 ', $output);\n echo \"Server stopped. [OK]\";\n\n?>\n" }, { "answer_id": 28646163, "author": "RafaSashi", "author_id": 2456038, "author_profile": "https://Stackoverflow.com/users/2456038", "pm_score": 2, "selected": false, "text": "ignore_user_abort(true); CURLOPT_TIMEOUT_MS function async_curl($background_process=''){\n\n //-------------get curl contents----------------\n\n $ch = curl_init($background_process);\n curl_setopt_array($ch, array(\n CURLOPT_HEADER => 0,\n CURLOPT_RETURNTRANSFER =>true,\n CURLOPT_NOSIGNAL => 1, //to timeout immediately if the value is < 1000 ms\n CURLOPT_TIMEOUT_MS => 50, //The maximum number of mseconds to allow cURL functions to execute\n CURLOPT_VERBOSE => 1,\n CURLOPT_HEADER => 1\n ));\n $out = curl_exec($ch);\n\n //-------------parse curl contents----------------\n\n //$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);\n //$header = substr($out, 0, $header_size);\n //$body = substr($out, $header_size);\n\n curl_close($ch);\n\n return true;\n}\n\nasync_curl('http://example.com/background_process_1.php');\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265073", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26823/" ]
265,074
<p>I'm using event delegation to listen for events lower in the DOM, but it's not working for an onchange event on a select box. Does the onchange event propagate or bubble up the DOM?</p> <p>Googling has failed in finding a conclusive answer.</p>
[ { "answer_id": 265112, "author": "scunliffe", "author_id": 6144, "author_profile": "https://Stackoverflow.com/users/6144", "pm_score": -1, "selected": false, "text": "<div id=\"foo\">\n <select onchange=\"alert('hi');\">\n <option>Hello</option>\n <option>World</option>\n </select>\n</foo>\n" }, { "answer_id": 265128, "author": "schonarth", "author_id": 22116, "author_profile": "https://Stackoverflow.com/users/22116", "pm_score": 0, "selected": false, "text": "<SELECT> <OPTION>" }, { "answer_id": 266252, "author": "Sergey Ilinsky", "author_id": 23815, "author_profile": "https://Stackoverflow.com/users/23815", "pm_score": 6, "selected": true, "text": "change submit reset focus blur change submit reset" }, { "answer_id": 4722246, "author": "jcampbell1", "author_id": 20512, "author_profile": "https://Stackoverflow.com/users/20512", "pm_score": 5, "selected": false, "text": "$('div.field_container').change(function() {\n // code here runs in all browers, including IE.\n});\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265074", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21030/" ]
265,089
<p>I would like to display the up time of the machine my code is running, how can I do that?</p>
[ { "answer_id": 265115, "author": "Bogdan", "author_id": 24022, "author_profile": "https://Stackoverflow.com/users/24022", "pm_score": 2, "selected": false, "text": "using System.Diagnostics;\n..........\nPerformanceCounter perfc = new PerformanceCounter(\"System\",\"System Up Time\");\nperfc.NextValue();\nTimeSpan t = TimeSpan.FromSeconds(perfc.NextValue());\n..........\n" }, { "answer_id": 265474, "author": "Mark Cidade", "author_id": 1659, "author_profile": "https://Stackoverflow.com/users/1659", "pm_score": 3, "selected": false, "text": "using System.Management;\nusing System.Linq;\n\nTimeSpan GetUptime()\n { var query = new SelectQuery(\"SELECT LastBootUpTime \n FROM Win32_OperatingSystem \n WHERE Primary='true'\");\n var mos = new ManagementObjectSearcher(query);\n var str = mos.Get().First().Properties[\"LastBootUpTime\"].Value.ToString();\n\n return DateTime.Now - ManagementDateTimeConverter.ToDateTime(str);\n }\n" }, { "answer_id": 3387623, "author": "Jakub Chodounsky", "author_id": 394587, "author_profile": "https://Stackoverflow.com/users/394587", "pm_score": 1, "selected": false, "text": "public static TimeSpan GetUptime()\n{\n ManagementObject mo = new ManagementObject(@\"\\\\.\\root\\cimv2:Win32_OperatingSystem=@\");\n DateTime lastBootUp = ManagementDateTimeConverter.ToDateTime(mo[\"LastBootUpTime\"].ToString());\n return DateTime.Now.ToUniversalTime() - lastBootUp.ToUniversalTime();\n}\n" }, { "answer_id": 23367170, "author": "Robert Cutajar", "author_id": 481812, "author_profile": "https://Stackoverflow.com/users/481812", "pm_score": 2, "selected": false, "text": "System.Environment.TickCount var ticks = Stopwatch.GetTimestamp();\nvar uptime = ((double)ticks) / Stopwatch.Frequency;\nvar uptimeSpan = TimeSpan.FromSeconds(uptime);\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265089", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14441/" ]
265,096
<p>I'm trying to use <code>System.DirectoryServices</code> in a web site project and I'm getting this error:</p> <blockquote> <p>The type or namespace name 'DirectoryServices' does not exist in the namespace 'System' (are you missing an assembly reference?)</p> </blockquote> <p>My project has a reference to <code>System.DirectoryServices</code> in <code>web.config</code>: </p> <pre><code>&lt;add assembly="System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/&gt; </code></pre> <p>And I do have <code>using System.DirectoryServices</code> in the files where I want to use it.</p> <p>Does anybody have a clue where to look for the problem?</p>
[ { "answer_id": 265133, "author": "Mitch Wheat", "author_id": 16076, "author_profile": "https://Stackoverflow.com/users/16076", "pm_score": 3, "selected": false, "text": "<compilation debug=\"true\">\n <assemblies>\n <add assembly=\"System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A\"/>\n </assemblies>\n</compilation>\n" }, { "answer_id": 42107456, "author": "Navid Golforoushan", "author_id": 2253691, "author_profile": "https://Stackoverflow.com/users/2253691", "pm_score": 0, "selected": false, "text": "web.config <configuration>\n <system.web>\n <compilation debug=\"true\" targetFramework=\"4.0\">\n <assemblies>\n <add assembly=\"System.DirectoryServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a\"/>\n </assemblies>\n </compilation>\n </system.web>\n</configuration>\n Developer Command Prompt for VS C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319 sn -T System.DirectoryServices.dll\n" }, { "answer_id": 46180174, "author": "Basma Elshoky", "author_id": 2925809, "author_profile": "https://Stackoverflow.com/users/2925809", "pm_score": 3, "selected": false, "text": "Install-Package System.DirectoryServices -Version 4.0.0 \n" }, { "answer_id": 55000311, "author": "Pratheek S", "author_id": 8625413, "author_profile": "https://Stackoverflow.com/users/8625413", "pm_score": 1, "selected": false, "text": "directoryService <system.web>\n <location>\n\n<compilation debug=\"false\" numRecompilesBeforeAppRestart=\"100\" targetFramework=\"4.7\">\n <assemblies>\n<add assembly=\"System.DirectoryServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A\" />\n<add assembly=\"System.DirectoryServices.AccountManagement, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089\" />\n </assemblies>\n </compilation>\n</system.web>\n </location>\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265096", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12111/" ]
265,097
<p>Is there a built in VB.NET function to format a number as an Ordinal or do I have to write my own?</p> <p><a href="https://stackoverflow.com/questions/20156/ordinals-in-c">There isn't in C# so I'm thinking there isn't :(</a> </p>
[ { "answer_id": 265142, "author": "Binary Worrier", "author_id": 18797, "author_profile": "https://Stackoverflow.com/users/18797", "pm_score": 4, "selected": false, "text": "Public Function AddOrdinal(ByVal num As Integer) as String\n Select Case (num Mod 100)\n Case 11 To 13\n Return num.ToString() & \"th\"\n End Select\n Select Case num Mod 10\n Case 1\n Return num.ToString() & \"st\"\n Case 2\n Return num.ToString() & \"nd\"\n Case 3\n Return num.ToString() & \"rd\"\n Case Else\n Return num.ToString() & \"th\"\n End Select\nEnd Function\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265097", "https://Stackoverflow.com", "https://Stackoverflow.com/users/982/" ]
265,102
<p>I have to read CSV files line by line which can be 10 to 20 Meg. <code>file()</code> is useless and I have to find the quickest way.</p> <p>I have tried with <code>fgets()</code>, which runs fine, but I don't know if it reads a small block each time I call it, or if it caches a bigger one and optimize file I/O. Do I have to try the <code>fread()</code> way, parsing EOL by myself?</p>
[ { "answer_id": 265111, "author": "Greg", "author_id": 24181, "author_profile": "https://Stackoverflow.com/users/24181", "pm_score": 1, "selected": false, "text": "fgets() file() fgets()" }, { "answer_id": 265132, "author": "Treb", "author_id": 22114, "author_profile": "https://Stackoverflow.com/users/22114", "pm_score": 0, "selected": false, "text": "fgetcsv()" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265102", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8404/" ]
265,106
<p>I've been working on a project called <a href="http://www.codeplex.com/axial" rel="nofollow noreferrer">Axial</a> that converts MSIL (compiled C# or VB.NET) to JavaScript. There are a few samples of working code, but some common situations don't work properly. (The current release doesn't work in production mode and the SVN code doesn't work in debug mode but is much cleaner.) I've heard from quite a few people that they hate writing JavaScript, so I know the project has some merit, but I'd guess that attitude is less prevalent among the SO community.</p> <p>Assume the product works perfectly and smoothly, so your JavaScript works 100% of the time and a Visual Studio plug-in makes sure you're using the product correctly. Is this something you or your organization would use? What features other than straight code translation would interest you?</p>
[ { "answer_id": 265111, "author": "Greg", "author_id": 24181, "author_profile": "https://Stackoverflow.com/users/24181", "pm_score": 1, "selected": false, "text": "fgets() file() fgets()" }, { "answer_id": 265132, "author": "Treb", "author_id": 22114, "author_profile": "https://Stackoverflow.com/users/22114", "pm_score": 0, "selected": false, "text": "fgetcsv()" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265106", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23427/" ]
265,117
<p>OK, I have just been reading and trying for the last hour to import a CSV file from access into MySQL, but I can not get it to do it correctly, no matter what I try.</p> <p>My table is like so:</p> <pre><code>+-----------------+------------- | Field | Type +-----------------+------------- | ARTICLE_NO | varchar(20) | ARTICLE_NAME | varchar(100) | SUBTITLE | varchar(20) | CURRENT_BID | varchar(20) | START_PRICE | varchar(20) | BID_COUNT | varchar(20) | QUANT_TOTAL | varchar(20) | QUANT_SOLD | varchar(20) | STARTS | datetime | ENDS | datetime | ORIGIN_END | datetime | SELLER_ID | varchar(20) | BEST_BIDDER_ID | varchar(20) | FINISHED | varchar(20) | WATCH | varchar(20) | BUYITNOW_PRICE | varchar(20) | PIC_URL | varchar(20) | PRIVATE_AUCTION | varchar(20) | AUCTION_TYPE | varchar(20) | INSERT_DATE | datetime | UPDATE_DATE | datetime | CAT_1_ID | varchar(20) | CAT_2_ID | varchar(20) | ARTICLE_DESC | varchar(20) | DESC_TEXTONLY | varchar(20) | COUNTRYCODE | varchar(20) | LOCATION | varchar(20) | CONDITIONS | varchar(20) | REVISED | varchar(20) | PAYPAL_ACCEPT | tinyint(4) | PRE_TERMINATED | varchar(20) | SHIPPING_TO | varchar(20) | FEE_INSERTION | varchar(20) | FEE_FINAL | varchar(20) | FEE_LISTING | varchar(20) | PIC_XXL | tinyint(4) | PIC_DIASHOW | tinyint(4) | PIC_COUNT | varchar(20) | ITEM_SITE_ID | varchar(20) </code></pre> <p>Which should be fine, and my data is currently semicolon delimited, an example of a row from my csv file is thus:</p> <pre><code>"110268889894";"ORIGINAL 2008 ED HARDY GÜRTEL* MYSTERY LOVE * M *BLACK";"";0,00 €;0,00 €;0;1;0;8.7.2008 17:18:37;5.11.2008 16:23:37;6.10.2008 17:23:37;29;0;0;0;125,00 €;"";0;2;6.10.2008 16:21:51;6.10.2008 14:19:08;80578;0;;0;77;"";0;0;1;0;-1;0,00 €;0,00 €;0,00 €;0;0;0;77 "110293328957";"Orig. Ed Hardy Shirt - Tank Top - Gr. XS- OVP/NEU";"";25,05 €;0,00 €;7;1;0;27.9.2008 06:26:27;6.10.2008 18:26:21;6.10.2008 18:26:21;49;0;0;0;0,00 €;"";0;1;6.10.2008 16:21:56;6.10.2008 16:33:20;31058;0;;0;77;"";1;0;0;0;-1;0,00 €;0,00 €;0,00 €;0;0;0;77 </code></pre> <p>I am using a simple PHP page to output the table data, and it is completely wrong. The problem is not with the PHP page as a simple table with just text displays perfectly. I am wondering if I have selected incorrect field types or the columns do not match up, but I see no reason this would be the case. Could something be happening because the data is trying to be displayed as HTML?</p> <p>I have tried to keep this question as specific as possible, and am not asking for people to do it for me as others have suggested, but I honestly can not see where the problem is.</p> <p>edit: When trying to display the data through PHP, at the moment the page is completely black with some table cells having borders and others not, othertimes when trying different delimiters, the fields do not match the columns. The starts field has never displayed correctly.</p> <p>I am loading the file from a CSV file with this command: </p> <pre><code>LOAD DATA LOCAL INFILE 'C:/Dokumente und Einstellungen/hom/Desktop/tblAuction.txt' INTO TABLE Auctions FIELDS TERMINATED BY '\"' LINES TERMINATED BY '\n'; </code></pre> <p>It looks fine in the DB as far as I have been able to tell, apart from the starts field, which is not the main problem at the moment.</p> <p>edit2: I have serialized the result, and this is what was output to the screen:</p> <pre><code>i:0; </code></pre> <p>I have absolutely no idea what that means.</p> <p>edit3: I had tried updating the terminated by a delimiter, and after changing \" to ; the problem still remains of data not being put into the correct columns etc.., I don't understand what I have missed.</p>
[ { "answer_id": 265150, "author": "Treb", "author_id": 22114, "author_profile": "https://Stackoverflow.com/users/22114", "pm_score": 1, "selected": true, "text": "echo serialize($result); FIELDS TERMINATED BY '\\\"' FIELDS TERMINATED BY ';'" }, { "answer_id": 265174, "author": "Ted Elliott", "author_id": 16501, "author_profile": "https://Stackoverflow.com/users/16501", "pm_score": 3, "selected": false, "text": " FIELDS TERMINATED BY '\\\"'\n FIELDS TERMINATED BY ';'\n OPTIONALLY ENCLOSED BY '\"'\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265117", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1246613/" ]
265,122
<p>Can I find out when the last INSERT, UPDATE or DELETE statement was performed on a table in an Oracle database and if so, how?</p> <p>A little background: The Oracle version is 10g. I have a batch application that runs regularly, reads data from a single Oracle table and writes it into a file. I would like to skip this if the data hasn't changed since the last time the job ran.</p> <p>The application is written in C++ and communicates with Oracle via OCI. It logs into Oracle with a "normal" user, so I can't use any special admin stuff.</p> <p>Edit: Okay, "Special Admin Stuff" wasn't exactly a good description. What I mean is: I can't do anything besides SELECTing from tables and calling stored procedures. Changing anything about the database itself (like adding triggers), is sadly not an option if want to get it done before 2010.</p>
[ { "answer_id": 265298, "author": "dub", "author_id": 30022, "author_profile": "https://Stackoverflow.com/users/30022", "pm_score": 4, "selected": false, "text": "AUDIT INSERT ON user.table\n" }, { "answer_id": 265507, "author": "Justin Cave", "author_id": 10397, "author_profile": "https://Stackoverflow.com/users/10397", "pm_score": 6, "selected": true, "text": "ORA_ROWSCN ORA_ROWSCN ORA_ROWSCN ORA_ROWSCN ROWDEPENDENCIES ORA_ROWSCN" }, { "answer_id": 6832649, "author": "Paul", "author_id": 185034, "author_profile": "https://Stackoverflow.com/users/185034", "pm_score": 6, "selected": false, "text": "SELECT SCN_TO_TIMESTAMP(MAX(ora_rowscn)) from myTable;\n" }, { "answer_id": 16190272, "author": "user2315209", "author_id": 2315209, "author_profile": "https://Stackoverflow.com/users/2315209", "pm_score": -1, "selected": false, "text": "select * from all_objects ao where ao.OBJECT_TYPE = 'TABLE' and ao.OWNER = 'YOUR_SCHEMA_NAME'\n" }, { "answer_id": 25488439, "author": "grokster", "author_id": 502441, "author_profile": "https://Stackoverflow.com/users/502441", "pm_score": 4, "selected": false, "text": "SELECT * FROM all_tab_modifications;\n" }, { "answer_id": 38585531, "author": "TMtech", "author_id": 2307470, "author_profile": "https://Stackoverflow.com/users/2307470", "pm_score": 0, "selected": false, "text": "CHANGE NOTIFICATION" }, { "answer_id": 53763215, "author": "hui chen", "author_id": 9204563, "author_profile": "https://Stackoverflow.com/users/9204563", "pm_score": 2, "selected": false, "text": "SELECT *\nFROM ALL_TAB_MODIFICATIONS\nWHERE TABLE_NAME IN ()\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265122", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1733/" ]
265,123
<p>What is the best way to implement connection pooling in hsqldb, without compromising on the speed?</p>
[ { "answer_id": 266055, "author": "Chochos", "author_id": 10165, "author_profile": "https://Stackoverflow.com/users/10165", "pm_score": 3, "selected": true, "text": "DataSource BasicDataSource" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265123", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12649/" ]
265,138
<p>I'm working with Eclipse Version 3.2.1 Build M20060921-0945 on a MS-Windows 2000 SP4 using a JDK 1.5.0-12.<br> I takes my locale that is es-AR and sets all menu and context in Spanish which I don't like. So I had included in eclipse.ini file one parameter <em>"-nl en"</em>.<br> Since that, <em>"References..."</em> feature in both <em>"Search"</em> and contextual menu stopped working. I removed parameter and ran eclipse with <em>"-clean"</em> but still not working. I don't have any other clue about what is happening. Thank you all in advance.<br> Beto</p>
[ { "answer_id": 1648360, "author": "Ferry", "author_id": 199465, "author_profile": "https://Stackoverflow.com/users/199465", "pm_score": 5, "selected": false, "text": "<WORKSPACE>/.metadata/.plugins/org.eclipse.jdt.core" }, { "answer_id": 6598216, "author": "Tillmann", "author_id": 649995, "author_profile": "https://Stackoverflow.com/users/649995", "pm_score": 2, "selected": false, "text": "<WORKSPACE>/.metadata/.plugins/org.eclipse.jdt.core" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265138", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
265,140
<p><a href="http://www.springsource.org/extensions/se-workflow" rel="noreferrer">Spring Workflow</a> has now been published.</p> <ul> <li>Have you tried it yet? For what kind of scenario?</li> <li>What is your impression? How do you find it stacks up against other workflow libs?</li> <li>Found any good docs or tutorials?</li> </ul>
[ { "answer_id": 467127, "author": "SenoCtar", "author_id": 56174, "author_profile": "https://Stackoverflow.com/users/56174", "pm_score": 3, "selected": true, "text": "public final void afterPropertiesSet() throws Exception {\n if (this.flowInstanceDescriptorPersisters == null) {\n this.flowInstanceDescriptorPersisters.put(DEFAULT_PERSISTER, new DefaultFlowInstanceDescriptorPersister());\n }\n}\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265140", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20065/" ]
265,146
<p>I currently have a 32 bit dll that was created with Visual Studio 2003 in C++ using <a href="http://en.wikipedia.org/wiki/Managed_Extensions_for_C%2B%2B" rel="nofollow noreferrer">Managed Extensions</a>. I'm now trying to compile a 64 bit version without having to upgrade to C++/CLI. I've been following the tutorial at <a href="http://www.eggheadcafe.com/forumarchives/vclanguage/Aug2005/post23130822.asp" rel="nofollow noreferrer">this location</a>. I'm getting the following error:</p> <blockquote> <p> fatal error C1197: cannot reference 'c:\windows\microsoft.net\framework\v1.1.4322\mscorlib.dll' as the progam has already referenced 'c:\windows\microsoft.net\framework\v2.0.50727\mscorlib.dll'</p> </blockquote> <p>I can't figure out what is referencing the .NET 2.0 version of the dll.</p>
[ { "answer_id": 265167, "author": "UberJumper", "author_id": 34395, "author_profile": "https://Stackoverflow.com/users/34395", "pm_score": 1, "selected": false, "text": "#using \"C:\\Windows\\Microsoft.NET\\Framework\\v1.1.4322\\mscorlib.dll\n #using \"mscorlib.dll\"\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265146", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9539/" ]
265,160
<p>I need a java api, that cannot use JMF, to play video interpreted by the SO codecs but i want to retrieve the each frames in java code. Somebody know some?</p>
[ { "answer_id": 58000052, "author": "zakgof", "author_id": 2519698, "author_profile": "https://Stackoverflow.com/users/2519698", "pm_score": 0, "selected": false, "text": "IVelvetVideoLib lib = VelvetVideoLib().getInstance();\ntry (IDemuxer demuxer = lib.demuxer(new File(\"/some/path/example.mp4\"))) {\n IDecoderVideoStream videoStream = demuxer.videoStream(0);\n IFrame videoFrame;\n while ((videoFrame = videoStream.nextFrame()) != null) {\n BufferedImage image = videoFrame.image();\n // Use image as needed...\n }\n} \n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265160", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
265,166
<p>I need to pause for maybe 500 miliseconds before I submit a form. Here is what I have so far:</p> <pre><code> $(".rowqty input").bind("keyup", function() { $("#ViewCartPage form").animate({ opacity: 1.0 }, 3000).submit() }); </code></pre> <p>so when someone changes the quantity of the input field it submits the form, but I want it to wait for a slight amount of time incase they need a moment to type 2 or 3 numbers. </p> <p>As you can see I tried the animate function to try and delay things but with no luck.</p> <p>I know I could use this: <a href="http://blog.mythin.net/projects/jquery.php" rel="nofollow noreferrer">http://blog.mythin.net/projects/jquery.php</a></p> <p>I'd rather not add another JS to my site if there is a way around it.</p> <p>EDIT: Actually the pause plugin above is not working for me either.</p>
[ { "answer_id": 265172, "author": "Chris Van Opstal", "author_id": 7264, "author_profile": "https://Stackoverflow.com/users/7264", "pm_score": 3, "selected": true, "text": "$(\".rowqty input\").bind(\"keyup\", function() { setTimeout(\"$('#ViewCartPage form').submit()\", 500 });\n" }, { "answer_id": 10460448, "author": "khaled_webdev", "author_id": 1376051, "author_profile": "https://Stackoverflow.com/users/1376051", "pm_score": 0, "selected": false, "text": "setTimeout(function () {$(\"#formID\").submit()},1000);\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265166", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34548/" ]
265,171
<p>Is there a way that I can get a full crash dump when my application crashes suddenly? </p> <p>The problem is that I suspect that it's due to unmanaged code that kills the .net framework itself, and because of that, unless there's a debugger attached to the application at the moment of the crash, the application doesn't even gets a chance to handle the crash.</p> <p>I can't attach a debugger and wait, because the crash happens randomly and we have many installed locations, so I'm wondering if it's possible to do this without attaching a debugger.</p> <p>Edit: I'm aware of Microsoft Debugging SDK, and I also just found out about DebugDiag. I'd like to do this without having to attach to the application each time, as it's usually in the middle of a sale and I don't have time to attach the debugger and explore the stack trace. DebugDiag does seem to let me setup a rule for this, but it seems to only work on already running processes, rather than waiting for some process to launch.</p>
[ { "answer_id": 9836043, "author": "EdChum", "author_id": 704848, "author_profile": "https://Stackoverflow.com/users/704848", "pm_score": 0, "selected": false, "text": "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug Value Name = Auto\nType = String (REG_SZ)\nData Value = 1 or 0. (Default is 1)\nValue Name = Debugger\nType = String (REG_SZ)\nData Value = drwtsn32 -p %ld -e %ld -g\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265171", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16172/" ]
265,175
<p>Any idea anyone? Is it possible that we specify the name of the form input field? How to go about doing that?</p>
[ { "answer_id": 265191, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "<h:form id=\"searchForm\">\n <h:inputText id=\"searchField\" ... />\n</h:form>\n" }, { "answer_id": 265210, "author": "Romain Linsolas", "author_id": 26457, "author_profile": "https://Stackoverflow.com/users/26457", "pm_score": 3, "selected": false, "text": "_ <h:form> <h:form id=\"myForm\">\n <h:inputText id=\"myInput\" .../>\n</h:form>\n" }, { "answer_id": 265561, "author": "McDowell", "author_id": 304, "author_profile": "https://Stackoverflow.com/users/304", "pm_score": 3, "selected": false, "text": "UIData clientId clientId /** Request scope */\npublic class IdBean implements Serializable {\n private UIComponent mytext;\n\n public String getClientId() {\n return mytext.getClientId(FacesContext.getCurrentInstance());\n }\n\n public UIComponent getMytext() { return mytext; }\n public void setMytext(UIComponent mytext) { this.mytext = mytext; }\n\n public List<String> getRows() {\n List<String> rows = new ArrayList<String>();\n for (int i = 0; i < 10; i++) {\n rows.add(\"row\" + i);\n }\n return rows;\n }\n}\n <f:view>\n <h:form>\n <h:dataTable value=\"#{idBean.rows}\" var=\"row\">\n <h:column>\n <h:outputLabel value=\"#{row}\" />\n <h:inputText binding=\"#{idBean.mytext}\"\n onclick=\"foo('#{idBean.clientId}');\" />\n </h:column>\n </h:dataTable>\n </h:form>\n </f:view>\n\n <script type=\"text/javascript\">\n function foo(name) {\n alert('You clicked '+name);\n }\n </script>\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265175", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
265,180
<p>Is there any security issue if let say in one application we do a hidden post to another application to make use of that application functionality?</p>
[ { "answer_id": 265191, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "<h:form id=\"searchForm\">\n <h:inputText id=\"searchField\" ... />\n</h:form>\n" }, { "answer_id": 265210, "author": "Romain Linsolas", "author_id": 26457, "author_profile": "https://Stackoverflow.com/users/26457", "pm_score": 3, "selected": false, "text": "_ <h:form> <h:form id=\"myForm\">\n <h:inputText id=\"myInput\" .../>\n</h:form>\n" }, { "answer_id": 265561, "author": "McDowell", "author_id": 304, "author_profile": "https://Stackoverflow.com/users/304", "pm_score": 3, "selected": false, "text": "UIData clientId clientId /** Request scope */\npublic class IdBean implements Serializable {\n private UIComponent mytext;\n\n public String getClientId() {\n return mytext.getClientId(FacesContext.getCurrentInstance());\n }\n\n public UIComponent getMytext() { return mytext; }\n public void setMytext(UIComponent mytext) { this.mytext = mytext; }\n\n public List<String> getRows() {\n List<String> rows = new ArrayList<String>();\n for (int i = 0; i < 10; i++) {\n rows.add(\"row\" + i);\n }\n return rows;\n }\n}\n <f:view>\n <h:form>\n <h:dataTable value=\"#{idBean.rows}\" var=\"row\">\n <h:column>\n <h:outputLabel value=\"#{row}\" />\n <h:inputText binding=\"#{idBean.mytext}\"\n onclick=\"foo('#{idBean.clientId}');\" />\n </h:column>\n </h:dataTable>\n </h:form>\n </f:view>\n\n <script type=\"text/javascript\">\n function foo(name) {\n alert('You clicked '+name);\n }\n </script>\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265180", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
265,192
<p>I have the following code:</p> <pre><code>Using cmd As SqlCommand = Connection.CreateCommand cmd.CommandText = "UPDATE someTable SET Value = @Value" cmd.CommandText &amp;= " WHERE Id = @Id" cmd.Parameters.AddWithValue("@Id", 1234) cmd.Parameters.AddWithValue("@Value", "myValue") cmd.ExecuteNonQuery End Using </code></pre> <p>I wonder if there is any way to get the final SQL statment as a String, which should look like this:</p> <pre class="lang-sql prettyprint-override"><code>UPDATE someTable SET Value = "myValue" WHERE Id = 1234 </code></pre> <p>If anyone wonders why I would do this:</p> <ul> <li>for logging (failed) statements</li> <li>for having the possibility to copy &amp; paste it to the Enterprise Manager for testing purposes</li> </ul>
[ { "answer_id": 265253, "author": "Tomalak", "author_id": 18771, "author_profile": "https://Stackoverflow.com/users/18771", "pm_score": 6, "selected": false, "text": "CommandText" }, { "answer_id": 265261, "author": "Kon", "author_id": 22303, "author_profile": "https://Stackoverflow.com/users/22303", "pm_score": 7, "selected": false, "text": "string query = cmd.CommandText;\n\nforeach (SqlParameter p in cmd.Parameters)\n{\n query = query.Replace(p.ParameterName, p.Value.ToString());\n}\n" }, { "answer_id": 4146573, "author": "Flapper", "author_id": 391383, "author_profile": "https://Stackoverflow.com/users/391383", "pm_score": 8, "selected": true, "text": " public static String ParameterValueForSQL(this SqlParameter sp)\n {\n String retval = \"\";\n\n switch (sp.SqlDbType)\n {\n case SqlDbType.Char:\n case SqlDbType.NChar:\n case SqlDbType.NText:\n case SqlDbType.NVarChar:\n case SqlDbType.Text:\n case SqlDbType.Time:\n case SqlDbType.VarChar:\n case SqlDbType.Xml:\n case SqlDbType.Date:\n case SqlDbType.DateTime:\n case SqlDbType.DateTime2:\n case SqlDbType.DateTimeOffset:\n retval = \"'\" + sp.Value.ToString().Replace(\"'\", \"''\") + \"'\";\n break;\n\n case SqlDbType.Bit:\n retval = (sp.Value.ToBooleanOrDefault(false)) ? \"1\" : \"0\";\n break;\n\n default:\n retval = sp.Value.ToString().Replace(\"'\", \"''\");\n break;\n }\n\n return retval;\n }\n\n public static String CommandAsSql(this SqlCommand sc)\n {\n StringBuilder sql = new StringBuilder();\n Boolean FirstParam = true;\n\n sql.AppendLine(\"use \" + sc.Connection.Database + \";\");\n switch (sc.CommandType)\n {\n case CommandType.StoredProcedure:\n sql.AppendLine(\"declare @return_value int;\");\n\n foreach (SqlParameter sp in sc.Parameters)\n {\n if ((sp.Direction == ParameterDirection.InputOutput) || (sp.Direction == ParameterDirection.Output))\n {\n sql.Append(\"declare \" + sp.ParameterName + \"\\t\" + sp.SqlDbType.ToString() + \"\\t= \");\n\n sql.AppendLine(((sp.Direction == ParameterDirection.Output) ? \"null\" : sp.ParameterValueForSQL()) + \";\");\n\n }\n }\n\n sql.AppendLine(\"exec [\" + sc.CommandText + \"]\");\n\n foreach (SqlParameter sp in sc.Parameters)\n {\n if (sp.Direction != ParameterDirection.ReturnValue)\n {\n sql.Append((FirstParam) ? \"\\t\" : \"\\t, \");\n\n if (FirstParam) FirstParam = false;\n\n if (sp.Direction == ParameterDirection.Input)\n sql.AppendLine(sp.ParameterName + \" = \" + sp.ParameterValueForSQL());\n else\n\n sql.AppendLine(sp.ParameterName + \" = \" + sp.ParameterName + \" output\");\n }\n }\n sql.AppendLine(\";\");\n\n sql.AppendLine(\"select 'Return Value' = convert(varchar, @return_value);\");\n\n foreach (SqlParameter sp in sc.Parameters)\n {\n if ((sp.Direction == ParameterDirection.InputOutput) || (sp.Direction == ParameterDirection.Output))\n {\n sql.AppendLine(\"select '\" + sp.ParameterName + \"' = convert(varchar, \" + sp.ParameterName + \");\");\n }\n }\n break;\n case CommandType.Text:\n sql.AppendLine(sc.CommandText);\n break;\n }\n\n return sql.ToString();\n }\n use dbMyDatabase;\ndeclare @return_value int;\ndeclare @OutTotalRows BigInt = null;\nexec [spMyStoredProc]\n @InEmployeeID = 1000686\n , @InPageSize = 20\n , @InPage = 1\n , @OutTotalRows = @OutTotalRows output\n;\nselect 'Return Value' = convert(varchar, @return_value);\nselect '@OutTotalRows' = convert(varchar, @OutTotalRows);\n" }, { "answer_id": 5563678, "author": "dummy", "author_id": 6297, "author_profile": "https://Stackoverflow.com/users/6297", "pm_score": 0, "selected": false, "text": " Public Shared Function SqlString(ByVal cmd As SqlCommand) As String\n Dim sbRetVal As New System.Text.StringBuilder()\n For Each item As SqlParameter In cmd.Parameters\n Select Case item.DbType\n Case DbType.String\n sbRetVal.AppendFormat(\"DECLARE {0} AS VARCHAR(255)\", item.ParameterName)\n sbRetVal.AppendLine()\n sbRetVal.AppendFormat(\"SET {0} = '{1}'\", item.ParameterName, item.Value)\n sbRetVal.AppendLine()\n\n Case DbType.DateTime\n sbRetVal.AppendFormat(\"DECLARE {0} AS DATETIME\", item.ParameterName)\n sbRetVal.AppendLine()\n sbRetVal.AppendFormat(\"SET {0} = '{1}'\", item.ParameterName, item.Value)\n sbRetVal.AppendLine()\n\n Case DbType.Guid\n sbRetVal.AppendFormat(\"DECLARE {0} AS UNIQUEIDENTIFIER\", item.ParameterName)\n sbRetVal.AppendLine()\n sbRetVal.AppendFormat(\"SET {0} = '{1}'\", item.ParameterName, item.Value)\n sbRetVal.AppendLine()\n\n Case DbType.Int32\n sbRetVal.AppendFormat(\"DECLARE {0} AS int\", item.ParameterName)\n sbRetVal.AppendLine()\n sbRetVal.AppendFormat(\"SET {0} = {1}\", item.ParameterName, item.Value)\n sbRetVal.AppendLine()\n\n Case Else\n Stop\n\n End Select\n Next\n\n sbRetVal.AppendLine(\"\")\n sbRetVal.AppendLine(cmd.CommandText)\n\n Return sbRetVal.ToString()\nEnd Function\n" }, { "answer_id": 17777169, "author": "Mitch", "author_id": 138200, "author_profile": "https://Stackoverflow.com/users/138200", "pm_score": 5, "selected": false, "text": "SqlCommand cmd = new SqlCommand(\"GetEntity\", con);\ncmd.Parameters.AddWithValue(\"@foobar\", 1);\ncmd.Parameters.Add(new SqlParameter(){\n ParameterName = \"@outParam\",\n Direction = ParameterDirection.Output,\n SqlDbType = System.Data.SqlDbType.Int\n});\ncmd.Parameters.Add(new SqlParameter(){\n Direction = ParameterDirection.ReturnValue\n});\ncmd.CommandType = CommandType.StoredProcedure;\n -- BEGIN COMMAND\nDECLARE @foobar INT = 1;\nDECLARE @outParam INT = NULL;\nDECLARE @returnValue INT;\n-- END PARAMS\nEXEC @returnValue = GetEntity @foobar = @foobar, @outParam = @outParam OUTPUT\n-- RESULTS\nSELECT 1 as Executed, @returnValue as ReturnValue, @outParam as [@outParam];\n-- END COMMAND\n public class SqlCommandDumper\n{\n public static string GetCommandText(SqlCommand sqc)\n {\n StringBuilder sbCommandText = new StringBuilder();\n\n sbCommandText.AppendLine(\"-- BEGIN COMMAND\");\n\n // params\n for (int i = 0; i < sqc.Parameters.Count; i++)\n logParameterToSqlBatch(sqc.Parameters[i], sbCommandText);\n sbCommandText.AppendLine(\"-- END PARAMS\");\n\n // command\n if (sqc.CommandType == CommandType.StoredProcedure)\n {\n sbCommandText.Append(\"EXEC \");\n\n bool hasReturnValue = false;\n for (int i = 0; i < sqc.Parameters.Count; i++)\n {\n if (sqc.Parameters[i].Direction == ParameterDirection.ReturnValue)\n hasReturnValue = true;\n }\n if (hasReturnValue)\n {\n sbCommandText.Append(\"@returnValue = \");\n }\n\n sbCommandText.Append(sqc.CommandText);\n\n bool hasPrev = false;\n for (int i = 0; i < sqc.Parameters.Count; i++)\n {\n var cParam = sqc.Parameters[i];\n if (cParam.Direction != ParameterDirection.ReturnValue)\n {\n if (hasPrev)\n sbCommandText.Append(\",\");\n sbCommandText.Append(\" \");\n\n sbCommandText.Append(cParam.ParameterName);\n sbCommandText.Append(\" = \");\n sbCommandText.Append(cParam.ParameterName);\n\n if (cParam.Direction.HasFlag(ParameterDirection.Output))\n sbCommandText.Append(\" OUTPUT\");\n\n hasPrev = true;\n }\n }\n }\n else\n {\n sbCommandText.AppendLine(sqc.CommandText);\n }\n\n sbCommandText.AppendLine(\"-- RESULTS\");\n sbCommandText.Append(\"SELECT 1 as Executed\");\n for (int i = 0; i < sqc.Parameters.Count; i++)\n {\n var cParam = sqc.Parameters[i];\n\n if (cParam.Direction == ParameterDirection.ReturnValue)\n {\n sbCommandText.Append(\", @returnValue as ReturnValue\");\n }\n else if (cParam.Direction.HasFlag(ParameterDirection.Output))\n {\n sbCommandText.Append(\", \");\n sbCommandText.Append(cParam.ParameterName);\n sbCommandText.Append(\" as [\");\n sbCommandText.Append(cParam.ParameterName);\n sbCommandText.Append(']');\n }\n }\n sbCommandText.AppendLine(\";\");\n\n sbCommandText.AppendLine(\"-- END COMMAND\");\n return sbCommandText.ToString();\n }\n\n private static void logParameterToSqlBatch(SqlParameter param, StringBuilder sbCommandText)\n {\n sbCommandText.Append(\"DECLARE \");\n if (param.Direction == ParameterDirection.ReturnValue)\n {\n sbCommandText.AppendLine(\"@returnValue INT;\");\n }\n else\n {\n sbCommandText.Append(param.ParameterName);\n\n sbCommandText.Append(' ');\n if (param.SqlDbType != SqlDbType.Structured)\n {\n logParameterType(param, sbCommandText);\n sbCommandText.Append(\" = \");\n logQuotedParameterValue(param.Value, sbCommandText);\n\n sbCommandText.AppendLine(\";\");\n }\n else\n {\n logStructuredParameter(param, sbCommandText);\n }\n }\n }\n\n private static void logStructuredParameter(SqlParameter param, StringBuilder sbCommandText)\n {\n sbCommandText.AppendLine(\" {List Type};\");\n var dataTable = (DataTable)param.Value;\n\n for (int rowNo = 0; rowNo < dataTable.Rows.Count; rowNo++)\n {\n sbCommandText.Append(\"INSERT INTO \");\n sbCommandText.Append(param.ParameterName);\n sbCommandText.Append(\" VALUES (\");\n\n bool hasPrev = false;\n for (int colNo = 0; colNo < dataTable.Columns.Count; colNo++)\n {\n if (hasPrev)\n {\n sbCommandText.Append(\", \");\n }\n logQuotedParameterValue(dataTable.Rows[rowNo].ItemArray[colNo], sbCommandText);\n hasPrev = true;\n }\n sbCommandText.AppendLine(\");\");\n }\n }\n\n const string DATETIME_FORMAT_ROUNDTRIP = \"o\";\n private static void logQuotedParameterValue(object value, StringBuilder sbCommandText)\n {\n try\n {\n if (value == null)\n {\n sbCommandText.Append(\"NULL\");\n }\n else\n {\n value = unboxNullable(value);\n\n if (value is string\n || value is char\n || value is char[]\n || value is System.Xml.Linq.XElement\n || value is System.Xml.Linq.XDocument)\n {\n sbCommandText.Append(\"N'\");\n sbCommandText.Append(value.ToString().Replace(\"'\", \"''\"));\n sbCommandText.Append('\\'');\n }\n else if (value is bool)\n {\n // True -> 1, False -> 0\n sbCommandText.Append(Convert.ToInt32(value));\n }\n else if (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 sbCommandText.Append(value.ToString());\n }\n else if (value is DateTime)\n {\n // SQL Server only supports ISO8601 with 3 digit precision on datetime,\n // datetime2 (>= SQL Server 2008) parses the .net format, and will \n // implicitly cast down to datetime.\n // Alternatively, use the format string \"yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffK\"\n // to match SQL server parsing\n sbCommandText.Append(\"CAST('\");\n sbCommandText.Append(((DateTime)value).ToString(DATETIME_FORMAT_ROUNDTRIP));\n sbCommandText.Append(\"' as datetime2)\");\n }\n else if (value is DateTimeOffset)\n {\n sbCommandText.Append('\\'');\n sbCommandText.Append(((DateTimeOffset)value).ToString(DATETIME_FORMAT_ROUNDTRIP));\n sbCommandText.Append('\\'');\n }\n else if (value is Guid)\n {\n sbCommandText.Append('\\'');\n sbCommandText.Append(((Guid)value).ToString());\n sbCommandText.Append('\\'');\n }\n else if (value is byte[])\n {\n var data = (byte[])value;\n if (data.Length == 0)\n {\n sbCommandText.Append(\"NULL\");\n }\n else\n {\n sbCommandText.Append(\"0x\");\n for (int i = 0; i < data.Length; i++)\n {\n sbCommandText.Append(data[i].ToString(\"x\"));\n }\n }\n }\n else\n {\n sbCommandText.Append(\"/* UNKNOWN DATATYPE: \");\n sbCommandText.Append(value.GetType().ToString());\n sbCommandText.Append(\" *\" + \"/ N'\");\n sbCommandText.Append(value.ToString());\n sbCommandText.Append('\\'');\n }\n }\n }\n\n catch (Exception ex)\n {\n sbCommandText.AppendLine(\"/* Exception occurred while converting parameter: \");\n sbCommandText.AppendLine(ex.ToString());\n sbCommandText.AppendLine(\"*/\");\n }\n }\n\n private static object unboxNullable(object value)\n {\n var typeOriginal = value.GetType();\n if (typeOriginal.IsGenericType\n && typeOriginal.GetGenericTypeDefinition() == typeof(Nullable<>))\n {\n // generic value, unboxing needed\n return typeOriginal.InvokeMember(\"GetValueOrDefault\",\n System.Reflection.BindingFlags.Public |\n System.Reflection.BindingFlags.Instance |\n System.Reflection.BindingFlags.InvokeMethod,\n null, value, null);\n }\n else\n {\n return value;\n }\n }\n\n private static void logParameterType(SqlParameter param, StringBuilder sbCommandText)\n {\n switch (param.SqlDbType)\n {\n // variable length\n case SqlDbType.Char:\n case SqlDbType.NChar:\n case SqlDbType.Binary:\n {\n sbCommandText.Append(param.SqlDbType.ToString().ToUpper());\n sbCommandText.Append('(');\n sbCommandText.Append(param.Size);\n sbCommandText.Append(')');\n }\n break;\n case SqlDbType.VarBinary:\n case SqlDbType.Image:\n {\n sbCommandText.Append(\"VARBINARY\");\n sbCommandText.Append(\"(MAX /* Specified as \");\n sbCommandText.Append(param.Size);\n sbCommandText.Append(\" */)\");\n }\n break;\n case SqlDbType.VarChar:\n case SqlDbType.Text:\n {\n sbCommandText.Append(\"VARCHAR\");\n sbCommandText.Append(\"(MAX /* Specified as \");\n sbCommandText.Append(param.Size);\n sbCommandText.Append(\" */)\");\n }\n break;\n case SqlDbType.NVarChar:\n case SqlDbType.NText:\n {\n sbCommandText.Append(\"NVARCHAR\");\n sbCommandText.Append(\"(MAX /* Specified as \");\n sbCommandText.Append(param.Size);\n sbCommandText.Append(\" */)\");\n }\n break;\n // fixed length\n case SqlDbType.Bit:\n case SqlDbType.TinyInt:\n case SqlDbType.SmallInt:\n case SqlDbType.Int:\n case SqlDbType.BigInt:\n case SqlDbType.SmallMoney:\n case SqlDbType.Money:\n case SqlDbType.Decimal:\n case SqlDbType.Real:\n case SqlDbType.Float:\n case SqlDbType.Date:\n case SqlDbType.DateTime:\n case SqlDbType.DateTime2:\n case SqlDbType.DateTimeOffset:\n case SqlDbType.UniqueIdentifier:\n {\n sbCommandText.Append(param.SqlDbType.ToString().ToUpper());\n }\n break;\n // Unknown\n case SqlDbType.Timestamp:\n default:\n {\n sbCommandText.Append(\"/* UNKNOWN DATATYPE: \");\n sbCommandText.Append(param.SqlDbType.ToString().ToUpper());\n sbCommandText.Append(\" *\" + \"/ \");\n sbCommandText.Append(param.SqlDbType.ToString().ToUpper());\n }\n break;\n }\n }\n}\n" }, { "answer_id": 21166471, "author": "MPelletier", "author_id": 210916, "author_profile": "https://Stackoverflow.com/users/210916", "pm_score": 1, "selected": false, "text": "Using cmd As SqlCommand = Connection.CreateCommand\n cmd.CommandText = \"SELECT @Value\"\n cmd.Parameters.AddWithValue(\"@Value\", \"myValue\")\n Return cmd.ExecuteScalar\nEnd Using\n" }, { "answer_id": 21938880, "author": "alan", "author_id": 255858, "author_profile": "https://Stackoverflow.com/users/255858", "pm_score": 2, "selected": false, "text": "Activity Monitor SQL Server Management Studio Activity Monitor View Details" }, { "answer_id": 26043894, "author": "Shawn J. Molloy", "author_id": 589509, "author_profile": "https://Stackoverflow.com/users/589509", "pm_score": 1, "selected": false, "text": "string query = (from SqlParameter p in sqlCmd.Parameters where p != null where p.Value != null select string.Format(\"Param: {0} = {1}, \", p.ParameterName, p.Value.ToString())).Aggregate(sqlCmd.CommandText, (current, parameter) => current + parameter);\nDebug.WriteLine(query);\n Customer.prGetCustomerDetails: @Offset = 1, Param: @Fetch = 10, Param: @CategoryLevel1ID = 3, Param: @VehicleLineID = 9, Param: @SalesCode1 = bce, \n" }, { "answer_id": 29086720, "author": "HouseCat", "author_id": 3072640, "author_profile": "https://Stackoverflow.com/users/3072640", "pm_score": 1, "selected": false, "text": "private string GetActualQuery(SqlCommand sqlcmd)\n{\n string query = sqlcmd.CommandText;\n string parameters = \"\";\n string[] strArray = System.Text.RegularExpressions.Regex.Split(query, \" VALUES \");\n\n //Reconstructs the second half of the SQL Command\n parameters = \"(\";\n\n int count = 0;\n foreach (SqlParameter p in sqlcmd.Parameters)\n {\n if (count == (sqlcmd.Parameters.Count - 1))\n {\n parameters += p.Value.ToString();\n }\n else\n {\n parameters += p.Value.ToString() + \", \";\n }\n count++;\n }\n\n parameters += \")\";\n\n //Returns the string recombined.\n return strArray[0] + \" VALUES \" + parameters;\n}\n" }, { "answer_id": 30630876, "author": "Barry-Dean", "author_id": 4971445, "author_profile": "https://Stackoverflow.com/users/4971445", "pm_score": 2, "selected": false, "text": "public string ParameterValueForSQL(SqlParameter sp)\n {\n string retval = \"\";\n\n switch (sp.SqlDbType)\n {\n case SqlDbType.Char:\n case SqlDbType.NChar:\n case SqlDbType.NText:\n case SqlDbType.NVarChar:\n case SqlDbType.Text:\n case SqlDbType.Time:\n case SqlDbType.VarChar:\n case SqlDbType.Xml:\n case SqlDbType.Date:\n case SqlDbType.DateTime:\n case SqlDbType.DateTime2:\n case SqlDbType.DateTimeOffset:\n if (sp.Value == DBNull.Value)\n {\n retval = \"NULL\";\n }\n else\n {\n retval = \"'\" + sp.Value.ToString().Replace(\"'\", \"''\") + \"'\";\n }\n break;\n\n case SqlDbType.Bit:\n if (sp.Value == DBNull.Value)\n {\n retval = \"NULL\";\n }\n else\n {\n retval = ((bool)sp.Value == false) ? \"0\" : \"1\";\n }\n break;\n\n default:\n if (sp.Value == DBNull.Value)\n {\n retval = \"NULL\";\n }\n else\n {\n retval = sp.Value.ToString().Replace(\"'\", \"''\");\n }\n break;\n }\n\n return retval;\n }\n\n\n public string CommandAsSql(SqlCommand sc)\n {\n string sql = sc.CommandText;\n\n sql = sql.Replace(\"\\r\\n\", \"\").Replace(\"\\r\", \"\").Replace(\"\\n\", \"\");\n sql = System.Text.RegularExpressions.Regex.Replace(sql, @\"\\s+\", \" \");\n\n foreach (SqlParameter sp in sc.Parameters)\n {\n string spName = sp.ParameterName;\n string spValue = ParameterValueForSQL(sp);\n sql = sql.Replace(spName, spValue);\n }\n\n sql = sql.Replace(\"= NULL\", \"IS NULL\");\n sql = sql.Replace(\"!= NULL\", \"IS NOT NULL\");\n return sql;\n }\n" }, { "answer_id": 31431181, "author": "JotaSantana", "author_id": 3338558, "author_profile": "https://Stackoverflow.com/users/3338558", "pm_score": 0, "selected": false, "text": "Dim query As String = cmd.CommandText\nquery = query.Replace(\"SET\", \"SET\" & vbNewLine)\nquery = query.Replace(\"WHERE\", vbNewLine & \"WHERE\")\nquery = query.Replace(\"GROUP BY\", vbNewLine & \"GROUP BY\")\nquery = query.Replace(\"ORDER BY\", vbNewLine & \"ORDER BY\")\nquery = query.Replace(\"INNER JOIN\", vbNewLine & \"INNER JOIN\")\nquery = query.Replace(\"LEFT JOIN\", vbNewLine & \"LEFT JOIN\")\nquery = query.Replace(\"RIGHT JOIN\", vbNewLine & \"RIGHT JOIN\")\nIf query.Contains(\"UNION ALL\") Then\n query = query.Replace(\"UNION ALL\", vbNewLine & \"UNION ALL\" & vbNewLine)\nElseIf query.Contains(\"UNION DISTINCT\") Then\n query = query.Replace(\"UNION DISTINCT\", vbNewLine & \"UNION DISTINCT\" & vbNewLine)\nElse\n query = query.Replace(\"UNION\", vbNewLine & \"UNION\" & vbNewLine)\nEnd If\n\nFor Each par In cmd.Parameters\n If par.Value Is Nothing OrElse IsDBNull(par.Value) Then\n query = RegularExpressions.Regex.Replace(query, par.ParameterName & \"\\b\", \"NULL\")\n ElseIf TypeOf par.Value Is Date Then\n query = RegularExpressions.Regex.Replace(query, par.ParameterName & \"\\b\", \"'\" & Format(par.Value, \"yyyy-MM-dd HH:mm:ss\") & \"'\")\n ElseIf TypeOf par.Value Is TimeSpan Then\n query = RegularExpressions.Regex.Replace(query, par.ParameterName & \"\\b\", \"'\" & par.Value.ToString & \"'\")\n ElseIf TypeOf par.Value Is Double Or TypeOf par.Value Is Decimal Or TypeOf par.Value Is Single Then\n query = RegularExpressions.Regex.Replace(query, par.ParameterName & \"\\b\", Replace(par.Value.ToString, \",\", \".\"))\n ElseIf TypeOf par.Value Is Integer Or TypeOf par.Value Is UInteger Or TypeOf par.Value Is Long Or TypeOf par.Value Is ULong Then\n query = RegularExpressions.Regex.Replace(query, par.ParameterName & \"\\b\", par.Value.ToString)\n Else\n query = RegularExpressions.Regex.Replace(query, par.ParameterName & \"\\b\", \"'\" & MySqlHelper.EscapeString(CStr(par.Value)) & \"'\")\n End If\nNext\n SELECT * FROM order WHERE order_status = @order_status AND order_date = @order_date\n SELECT * FROM order WHERE order_status = 'C' AND order_date = '2015-01-01 00:00:00'\n" }, { "answer_id": 32351885, "author": "Jeroen Pot", "author_id": 878609, "author_profile": "https://Stackoverflow.com/users/878609", "pm_score": 3, "selected": false, "text": "SqlDebugHelper.CreateExecutableSqlStatement(sql, parameters);\n" }, { "answer_id": 37842825, "author": "Martin.Martinsson", "author_id": 434209, "author_profile": "https://Stackoverflow.com/users/434209", "pm_score": 2, "selected": false, "text": "public static class DbHelper\n{\n public static string ToString(this DbParameterCollection parameters, string sqlQuery)\n {\n return parameters.Cast<DbParameter>().Aggregate(sqlQuery, (current, p) => current.Replace(p.ParameterName, p.Value.ToString()));\n }\n}\n" }, { "answer_id": 40993397, "author": "o_link", "author_id": 7256266, "author_profile": "https://Stackoverflow.com/users/7256266", "pm_score": 0, "selected": false, "text": "public static string ToSqlStatement(this SqlCommand cmd)\n{\n return $@\"EXECUTE sp_executesql N'{cmd.CommandText.Replace(\"'\", \"''\")}'{cmd.Parameters.ToSqlParameters()}\";\n}\n\nprivate static string ToSqlParameters(this SqlParameterCollection col)\n{\n if (col.Count == 0)\n return string.Empty;\n var parameters = new List<string>();\n var parameterValues = new List<string>();\n foreach (SqlParameter param in col)\n {\n parameters.Add($\"{param.ParameterName}{param.ToSqlParameterType()}\");\n parameterValues.Add($\"{param.ParameterName} = {param.ToSqlParameterValue()}\");\n }\n return $\",N\\'{string.Join(\",\", parameters)}\\',{string.Join(\",\", parameterValues)}\";\n}\n\nprivate static object ToSqlParameterType(this SqlParameter param)\n{\n var paramDbType = param.SqlDbType.ToString().ToLower();\n if (param.Precision != 0 && param.Scale != 0)\n return $\"{paramDbType}({param.Precision},{param.Scale})\";\n if (param.Precision != 0)\n return $\"{paramDbType}({param.Precision})\";\n switch (param.SqlDbType)\n {\n case SqlDbType.VarChar:\n case SqlDbType.NVarChar:\n string s = param.SqlValue?.ToString() ?? string.Empty;\n return paramDbType + (s.Length > 0 ? $\"({s.Length})\" : string.Empty);\n default:\n return paramDbType;\n }\n}\n\nprivate static string ToSqlParameterValue(this SqlParameter param)\n{\n switch (param.SqlDbType)\n {\n case SqlDbType.Char:\n case SqlDbType.Date:\n case SqlDbType.DateTime:\n case SqlDbType.DateTime2:\n case SqlDbType.DateTimeOffset:\n case SqlDbType.NChar:\n case SqlDbType.NText:\n case SqlDbType.NVarChar:\n case SqlDbType.Text:\n case SqlDbType.Time:\n case SqlDbType.VarChar:\n case SqlDbType.Xml:\n return $\"\\'{param.SqlValue.ToString().Replace(\"'\", \"''\")}\\'\";\n case SqlDbType.Bit:\n return param.SqlValue.ToBooleanOrDefault() ? \"1\" : \"0\";\n default:\n return param.SqlValue.ToString().Replace(\"'\", \"''\");\n }\n}\n\npublic static bool ToBooleanOrDefault(this object o, bool defaultValue = false)\n{\n if (o == null)\n return defaultValue;\n string value = o.ToString().ToLower();\n switch (value)\n {\n case \"yes\":\n case \"true\":\n case \"ok\":\n case \"y\":\n return true;\n case \"no\":\n case \"false\":\n case \"n\":\n return false;\n default:\n bool b;\n if (bool.TryParse(o.ToString(), out b))\n return b;\n break;\n }\n return defaultValue;\n}\n" }, { "answer_id": 42398495, "author": "CheesusCrust", "author_id": 3277777, "author_profile": "https://Stackoverflow.com/users/3277777", "pm_score": -1, "selected": false, "text": "string.Join(\",\", from SqlParameter p in cmd.Parameters select p.ToString()) \n" }, { "answer_id": 45378224, "author": "Daghan Karakasoglu", "author_id": 2140434, "author_profile": "https://Stackoverflow.com/users/2140434", "pm_score": 2, "selected": false, "text": " public static string getQueryFromCommand(SqlCommand cmd)\n {\n StringBuilder CommandTxt = new StringBuilder();\n CommandTxt.Append(\"DECLARE \");\n List<string> paramlst = new List<string>();\n foreach (SqlParameter parms in cmd.Parameters)\n {\n paramlst.Add(parms.ParameterName);\n CommandTxt.Append(parms.ParameterName + \" AS \");\n CommandTxt.Append(parms.SqlDbType.ToString());\n CommandTxt.Append(\",\");\n }\n\n if (CommandTxt.ToString().Substring(CommandTxt.Length-1, 1) == \",\")\n CommandTxt.Remove(CommandTxt.Length-1, 1);\n CommandTxt.AppendLine();\n int rownr = 0;\n foreach (SqlParameter parms in cmd.Parameters)\n {\n string val = String.Empty;\n if (parms.DbType.Equals(DbType.String) || parms.DbType.Equals(DbType.DateTime))\n val = \"'\" + Convert.ToString(parms.Value).Replace(@\"\\\", @\"\\\\\").Replace(\"'\", @\"\\'\") + \"'\";\n if (parms.DbType.Equals(DbType.Int16) || parms.DbType.Equals(DbType.Int32) || parms.DbType.Equals(DbType.Int64) || parms.DbType.Equals(DbType.Decimal) || parms.DbType.Equals(DbType.Double))\n val = Convert.ToString(parms.Value);\n\n CommandTxt.AppendLine();\n CommandTxt.Append(\"SET \" + paramlst[rownr].ToString() + \" = \" + val.ToString());\n rownr += 1;\n }\n CommandTxt.AppendLine();\n CommandTxt.AppendLine();\n CommandTxt.Append(cmd.CommandText);\n return CommandTxt.ToString();\n }\n" }, { "answer_id": 52409927, "author": "George Birbilis", "author_id": 903783, "author_profile": "https://Stackoverflow.com/users/903783", "pm_score": 0, "selected": false, "text": " private static void CommandAsSql_Text(this SqlCommand command, System.Text.StringBuilder sql)\n {\n string query = command.CommandText;\n\n foreach (SqlParameter p in command.Parameters)\n query = Regex.Replace(query, \"\\\\B\" + p.ParameterName + \"\\\\b\", p.ParameterValueForSQL()); //the first one is \\B, the 2nd one is \\b, since ParameterName starts with @ which is a non-word character in RegEx (see https://stackoverflow.com/a/2544661)\n\n sql.AppendLine(query);\n }\n" }, { "answer_id": 56265036, "author": "Paul Sturm", "author_id": 879170, "author_profile": "https://Stackoverflow.com/users/879170", "pm_score": 3, "selected": false, "text": " private static void LogSQL(SqlCommand cmd)\n {\n string query = cmd.CommandText;\n\n foreach (SqlParameter prm in cmd.Parameters)\n {\n switch (prm.SqlDbType)\n {\n case SqlDbType.Bit:\n int boolToInt = (bool)prm.Value ? 1 : 0;\n query = query.Replace(prm.ParameterName, string.Format(\"{0}\", (bool)prm.Value ? 1 : 0));\n break;\n case SqlDbType.Int:\n query = query.Replace(prm.ParameterName, string.Format(\"{0}\", prm.Value));\n break;\n case SqlDbType.VarChar:\n query = query.Replace(prm.ParameterName, string.Format(\"'{0}'\", prm.Value));\n break;\n default:\n query = query.Replace(prm.ParameterName, string.Format(\"'{0}'\", prm.Value));\n break;\n }\n }\n\n // the following is my how I write to my log - your use will vary\n logger.Debug(\"{0}\", query);\n\n return;\n }\n LogSQL(queryCmd)\nqueryCmd.ExecuteNonQuery()\n" }, { "answer_id": 57780016, "author": "user11982798", "author_id": 11982798, "author_profile": "https://Stackoverflow.com/users/11982798", "pm_score": -1, "selected": false, "text": "Using cmd As SqlCommand = Connection.CreateCommand\n cmd.CommandText = \"UPDATE someTable SET Value = @Value\"\n cmd.CommandText &= \" WHERE Id = @Id\"\n cmd.Parameters.AddWithValue(\"@Id\", 1234)\n cmd.Parameters.AddWithValue(\"@Value\", \"myValue\")\n cmd.ExecuteNonQuery\nEnd Using\n Private sub Update( byval myID as Int32, byval myVal as String)\n Using cmd As SqlCommand = Connection.CreateCommand\n cmd.CommandText = \"UPDATE someTable SET Value = '\" & myVaL & \"'\" & _\n \" WHERE Id = \" & myID \n cmd.ExecuteNonQuery\n End Using\nEnd sub\n" }, { "answer_id": 57780188, "author": "user11982798", "author_id": 11982798, "author_profile": "https://Stackoverflow.com/users/11982798", "pm_score": 0, "selected": false, "text": "Private Function ConvToNonParm(ByRef Cmd As SqlClient.SqlCommand) As String\n For myCnt As Int16 = 1 To Cmd.Parameters.Count\n Dim myVal As String = Cmd.Parameters(myCnt - 1).Value\n Select Case Cmd.Parameters(myCnt - 1).SqlDbType\n Case SqlDbType.Char, SqlDbType.NChar, SqlDbType.VarChar, SqlDbType.NChar, SqlDbType.NVarChar 'and so on\n myVal = \"'\" & myVal & \"'\"\n 'Case \"others....\"\n\n Case Else\n 'please assing\n End Select\n Cmd.CommandText = Replace(Cmd.CommandText, Cmd.Parameters(myCnt - 1).ToString, myVal)\n Next\n Cmd.Parameters.Clear()\n Return Cmd.CommandText\nEnd Function\n myCmd.CommandText = \"UPDATE someTable SET Value = @Value\"\n myCmd.CommandText &= \" WHERE Id = @Id\"\n myCmd.Parameters.AddWithValue(\"@Id\", 1234)\n myCmd.Parameters.AddWithValue(\"@Value\", \"myValue\")\n\n myCmd.CommandText = ConvToNonParm(myCmd)\n" }, { "answer_id": 58191712, "author": "CAK2", "author_id": 773906, "author_profile": "https://Stackoverflow.com/users/773906", "pm_score": 0, "selected": false, "text": " private void ExtractSqlCommandForDebugging(SqlCommand cmd)\n {\n string sql = \"exec \" + cmd.CommandText;\n bool first = true;\n foreach (SqlParameter p in cmd.Parameters)\n {\n string value = ((p.Value == DBNull.Value) ? \"null\"\n : (p.Value is string) ? \"'\" + p.Value + \"'\"\n : p.Value.ToString());\n if (first)\n {\n sql += string.Format(\" {0}={1}\", p.ParameterName, value);\n first = false;\n }\n else\n {\n sql += string.Format(\"\\n , {0}={1}\", p.ParameterName, value);\n }\n }\n sql += \"\\nGO\";\n Debug.WriteLine(sql);\n }\n exec dbo.MyStoredProcName @SnailMail=False\n , @Email=True\n , @AcceptSnailMail=False\n , @AcceptEmail=False\n , @DistanceMiles=-1\n , @DistanceLocationList=''\n , @ExcludeDissatisfied=True\n , @ExcludeCodeRed=True\n , @MinAge=null\n , @MaxAge=18\n , @GenderTypeID=-1\n , @NewThisYear=-1\n , @RegisteredThisYear=-1\n , @FormersTermGroupList=''\n , @RegistrationStartDate=null\n , @RegistrationEndDate=null\n , @DivisionList='25'\n , @LocationList='29,30'\n , @OneOnOneOPL=-1\n , @JumpStart=-1\n , @SmallGroup=-1\n , @PurchasedEAP=-1\n , @RedeemedEAP=-1\n , @ReturnPlanYes=False\n , @MinNetPromoter=-1\n , @MinSurveyScore=-1\n , @VIPExclusionTypes='-2'\n , @FieldSelectionMask=65011584\n , @DisplayType=0\nGO\n" }, { "answer_id": 65753622, "author": "Seyed Hossein Mirheydari", "author_id": 12054364, "author_profile": "https://Stackoverflow.com/users/12054364", "pm_score": 2, "selected": false, "text": ":1,:2 ,... string query = cmd.CommandText;\nint i = 1;\nforeach (OracleParameter p in cmd.Parameters)\n {\n query = query.Replace(\":\"+i.ToString(),((p.Value==null)?\"\":p.Value.ToString()));\n i++;\n }\n" }, { "answer_id": 74242000, "author": "Ramakrishna Talla", "author_id": 849030, "author_profile": "https://Stackoverflow.com/users/849030", "pm_score": 0, "selected": false, "text": "//For Oracle db in the sql text the parameters could be like :ID,:NAME etc.\n//This is same as above Seyed Hossein Mirheydari, but slightly improved, \n//this works with parameter names well.\n//Further is straight simple one, you need to format for datatypes \n//after query is generated.\n private string GetFullOraQuery(OracleCommand cmd)\n {\n string query = cmd.CommandText;\n foreach (OracleParameter p in cmd.Parameters)\n {\n query = query.Replace(\":\" + p.ParameterName, ((p.Value == null) ? \"\" : p.Value.ToString()));\n }\n return query;\n }\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265192", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6297/" ]
265,208
<p>I have a list of integers in C#. I wish to remove duplicates. In C++ I would run it through the std::sort and then std::unique algorithms for a very efficient way of obtaining the unique list.</p> <p>What's the best way to do the same thing in C#? In other words, I'm looking for a more elegant way to do the following code:</p> <pre><code> private static int[] unique(int[] ids) { IDictionary&lt;int, object&gt; d = new Dictionary&lt;int, object&gt;(); foreach(int i in ids) d[i] = null; int[] results = new int[d.Count]; int j = 0; foreach(int id in d.Keys) results[j++] = id; return results; } </code></pre>
[ { "answer_id": 265214, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 4, "selected": true, "text": "int[] x = new[] { 1, 4, 23, 4, 1 };\nint[] distinct = x.Distinct().ToArray();\n// distinct is now { 1, 4, 23 } (but not necessarily in that order)\n" }, { "answer_id": 265260, "author": "Tamir", "author_id": 30879, "author_profile": "https://Stackoverflow.com/users/30879", "pm_score": 2, "selected": false, "text": " var vals = new List<int> { 1, 2, 3, 2, 1, 2, 3, 2, 3, 4, 3, 2, 3 };\n vals.Sort();\n var uniques = new HashSet<int>(vals);\n List<int> vals = new List<int>();\nvals.Add(1);\nvals.Add(2);\nvals.Add(3);\nvals.Add(2);\n...\nvals.Sort();\nList<int> uniques = new List<int>();\nvals.ForEach(delegate(int v) {\n if (!uniques.Contains(v)) uniques.Add(v);\n});\n" }, { "answer_id": 265288, "author": "slf", "author_id": 13263, "author_profile": "https://Stackoverflow.com/users/13263", "pm_score": 0, "selected": false, "text": "public IEnumerable<int> unique(int[] ids)\n{\n List<int> l = new List<int>();\n foreach (int id in ids)\n {\n if (!l.Contains(id))\n {\n l.Add(id);\n yield return id;\n }\n }\n}\n" }, { "answer_id": 2181589, "author": "Cine", "author_id": 264022, "author_profile": "https://Stackoverflow.com/users/264022", "pm_score": 0, "selected": false, "text": " private static List<T> GetUnique<T>(List<T> list) where T : IEquatable<T>\n {\n list.Sort();\n int count = list.Count;\n List<T> unique = new List<T>(count);\n T last = default(T);\n for (int i = 0; i < count; i++)\n {\n T val = list[i];\n if (i != 0 && last.Equals(val)) continue;\n last = val;\n unique.Add(val);\n }\n return unique;\n }\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265208", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34685/" ]
265,218
<p>I'm looking for a way to implement a referral system for my web site.</p> <p>Initially I went with <a href="http://mysite.com/?affid=0001" rel="nofollow noreferrer">http://mysite.com/?affid=0001</a> and used the affid in the query string affid value to record referrals. The problem with this is that from some common Google search phrases the link with the affid appears before the standard link in a Google search, meaning that affiliates will wrongly get credited for customers who have Googled our site.</p> <p>I also heard that having multiple different links that refer to the same page (eg. <a href="http://mysite.com/?affid=0001" rel="nofollow noreferrer">http://mysite.com/?affid=0001</a> and <a href="http://mysite.com/?affid=0002" rel="nofollow noreferrer">http://mysite.com/?affid=0002</a>) causes Google to reduce your ranking. Is this true?</p> <p>Does anyone have a solution to these problems?</p>
[ { "answer_id": 265262, "author": "Keltex", "author_id": 28260, "author_profile": "https://Stackoverflow.com/users/28260", "pm_score": 1, "selected": false, "text": "<meta name=\"ROBOTS\" content=\"NOINDEX, FOLLOW\"/>\n" }, { "answer_id": 265300, "author": "Jonathan S.", "author_id": 2034, "author_profile": "https://Stackoverflow.com/users/2034", "pm_score": 2, "selected": false, "text": "Response.Status = \"301 Moved Permanently\";\nResponse.AddHeader(\"Location\",\"http://www.example.com\"); \n" }, { "answer_id": 496260, "author": "Alan Doherty", "author_id": 59995, "author_profile": "https://Stackoverflow.com/users/59995", "pm_score": 0, "selected": false, "text": "<?php\nif (isset($_REQUEST['affid'])) {\n <make call to affiliate logging code, ensure it creates no visible output>\nheader(\"HTTP/1.1 301 Moved Permanently\");\nheader(\"Location: http://www.example.com/this-page/\");\nexit();\n}\n?>\n <CFHEADER statuscode=\"301\" statustext=\"Moved Permanently\">\n<CFHEADER name=\"Location\" value=\"http://www.example.com/this-page/\">\n #!/usr/bin/perl -w\nuse strict;\nprint \"Status: 301 Moved Permanantly\\n\";\nprint \"Location: http://www.example.com/this-page/\\n\\n\";\nexit;\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265218", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34632/" ]
265,228
<p>I have some function to find a value:</p> <pre><code>struct FindPredicate { FindPredicate(const SomeType&amp; t) : _t(t) { } bool operator()(SomeType&amp; t) { return t == _t; } private: const SomeType&amp; _t; }; bool ContainsValue(std::vector&lt;SomeType&gt;&amp; v, SomeType&amp; valueToFind) { return find_if(v.begin(), v.end(), FindPredicate(valueToFind)) != v.end(); } </code></pre> <p>Now I would like to write a function that checks if all members of a vector satisfy that predicate:</p> <pre><code>bool AllSatisfy(std::vector&lt;SomeType&gt;&amp; v) { /* ... */ } </code></pre> <p>One solution is to use the <code>std::count_if</code> algorithm.</p> <p>Does anyone know a solution that involves negating the predicate?</p>
[ { "answer_id": 265307, "author": "Luc Touraille", "author_id": 20984, "author_profile": "https://Stackoverflow.com/users/20984", "pm_score": 5, "selected": true, "text": "unary_function<SomeType, bool> not1 struct FindPredicate : public unary_function<SomeType, bool>\n{\n FindPredicate(const SomeType& t) : _t(t) {}\n\n bool operator()(const SomeType& t) const {\n return t == _t;\n }\n\nprivate:\n const SomeType& _t;\n};\n\nbool AllSatisfy(std::vector<SomeType>& v, SomeType& valueToFind)\n{\n return find_if(v.begin(), \n v.end(), \n not1(FindPredicate(valueToFind))) == v.end();\n}\n struct NotFindPredicate\n{\n\n NotFindPredicate(const SomeType& t) : _t(t) {\n }\n bool operator()(SomeType& t) {\n return t != _t;\n }\n\nprivate:\n const SomeType& _t;\n};\n\nbool AllSatisfy(std::vector<SomeType>& v) {\n return find_if(v.begin(), \n v.end(), \n NotFindPredicate(valueToFind)) == v.end();\n}\n template <class Functor>\nstruct Not\n{\n Not(Functor & f) : func(f) {}\n\n template <typename ArgType>\n bool operator()(ArgType & arg) { return ! func(arg); }\n\n private:\n Functor & func;\n};\n bool AllSatisfy(std::vector<SomeType>& v, SomeType& valueToFind)\n{\n FindPredicate f(valueToFind);\n return find_if(v.begin(), v.end(), Not<FindPredicate>(f)) == v.end();\n}\n" }, { "answer_id": 265323, "author": "Greg Rogers", "author_id": 5963, "author_profile": "https://Stackoverflow.com/users/5963", "pm_score": 3, "selected": false, "text": "bool AllSatisfy(std::vector<SomeType>& v, SomeType& valueToFind) {\n return find_if(v.begin(), v.end(), not1(FindPredicate(valueToFind))) != v.end();\n}\n" }, { "answer_id": 265451, "author": "Motti", "author_id": 3848, "author_profile": "https://Stackoverflow.com/users/3848", "pm_score": 2, "selected": false, "text": "not1 not" }, { "answer_id": 273722, "author": "Sanjaya R", "author_id": 9353, "author_profile": "https://Stackoverflow.com/users/9353", "pm_score": 0, "selected": false, "text": "bool all_equal(std::vector<SomeType>& v, SomeType& valueToFind)\n{\n return v.end() == find_if(v.begin(), v.end(), std::bind1st (equal_to (), valueToFind) );\n}\n\nbool all_not_equal( std::vector<SomeType>& v, SomeType &valueToFind ) {\n{\n return v.end() == find_if(v.begin(), v.end(), std::bind1st (not_equal_to (), valueToFind) );\n}\n template< typename InputIterator , typename Predicate >\nbool test_all( InputIterator first, InputIterator last, Predicate pred )\n{\n return last == find_if( first, last, pred );\n}\n\ntest_all( v.begin(), v.end(), std::bind1st( not_equals_to_( value )) );\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265228", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17650/" ]
265,251
<p>I've found an issue with ASP.NET that I know at least has stumped one other person out there. We were trying to use an HttpModule to handle wildcard requests to a web application. The generated url is dynamic and could potentially be several hundred characters long. Unfortunately there appears to be a limitation in the aspnet_isapi.dll file that limits the length of the path in the url to MAX_PATH which is hardcoded at 260 chars. </p> <p>Has anyone else ran into this and found a way around this limit? Query string parameters are not an option. </p> <p>Thanks, Greg Ballard</p>
[ { "answer_id": 5585672, "author": "lmingle", "author_id": 145836, "author_profile": "https://Stackoverflow.com/users/145836", "pm_score": 3, "selected": false, "text": "<httpRuntime maxUrlLength=\"1000\" relaxedUrlToFileSystemMapping=\"true\" />\n" }, { "answer_id": 35320241, "author": "Jon Schneider", "author_id": 12484, "author_profile": "https://Stackoverflow.com/users/12484", "pm_score": 2, "selected": false, "text": "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\services\\HTTP\\Parameters UrlSegmentMaxLength" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265251", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
265,258
<p>I am doing 2^1000 and I am getting this:</p> <p>1.07151e+301</p> <p>Is there any way to actually turn this into a proper number without the e+301, or at least can anyone show me where I can see how to turn this in to a real number, by some way working with the e+301 part?</p>
[ { "answer_id": 265272, "author": "Alnitak", "author_id": 6782, "author_profile": "https://Stackoverflow.com/users/6782", "pm_score": 3, "selected": false, "text": "% perl -Mbigint -e 'print 2**1000'\n10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376\n" }, { "answer_id": 265330, "author": "schnaader", "author_id": 34065, "author_profile": "https://Stackoverflow.com/users/34065", "pm_score": 2, "selected": false, "text": "unsigned int result[400]; // result digits\nunsigned int i, j, carry;\n\n// Initialize result digits\nfor (i = 0; i < 399; i++) {\n result[i] = 0;\n}\nresult[399] = 2;\n\nfor (i = 2; i <= 1000; i++) { // Calculate 2^i\n carry = 0;\n for (j = 399; j > 0; j--) {\n result[j] <<= 1; // multiply with 2\n result[j] += carry; // add carry\n carry = result[j] / 10;\n result[j] %= 10; // we want one digit (0-9) only\n }\n}\n\nprintf(\"2 ^ 1000 = \");\n// print result digits\nfor (i = 0; i < 400; i++) {\n if (result[i] != 0) { // no leading zeros, please\n for (j = i; j < 400; j++) {\n printf(\"%d\", result[j]);\n }\n break;\n }\n}\nprintf(\"\\n\");\n" }, { "answer_id": 265365, "author": "tvanfosson", "author_id": 12950, "author_profile": "https://Stackoverflow.com/users/12950", "pm_score": 5, "selected": true, "text": "printf printf( \"%f1000.0\", value );\n// note that 1000 is way larger than need be,\n// I'm just too lazy to count the digits\n cout cout.setf(ios::fixed);\ncout << setprecision(0) << value;\n" }, { "answer_id": 49108333, "author": "C AJAY KARTHIKEYAN", "author_id": 9445117, "author_profile": "https://Stackoverflow.com/users/9445117", "pm_score": 0, "selected": false, "text": "limits.h cmath.h cout.precision(0);\ncout<< fixed<< pow(2,31); //OR ANY NUMBER HERE\n" }, { "answer_id": 65357452, "author": "Raj Aryan", "author_id": 14348823, "author_profile": "https://Stackoverflow.com/users/14348823", "pm_score": 0, "selected": false, "text": "2^34 3.43597e+010 long long int a= pow(2,34)-2;\ncout<<a;\n 34359738366" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265258", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8715/" ]
265,293
<p>I have an ASP.Net MVC Ajax.BeginForm that submits and updates my page properly when I click the submit button. </p> <p>The problem is I need additional events to do the same thing, like when they change the text of an input. The additonal events do properly submit the form but they circumvent the onsubmit javascript generated on the form tag by the Ajax.BeginForm.</p> <p>Here is the form tag generated by Ajax.BeingForm:</p> <pre><code>&lt;form action="/Store/UpdateCart" method="post" onsubmit="Sys.Mvc.AsyncForm.handleSubmit(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: 'updatedContent' });"&gt; </code></pre> <p>And here is the jQuery to bind my other events that need to submit the form via Ajax:</p> <pre><code> $("#ShippingType, #ViewCart .ddl").bind("change", function() { $("#ViewCartPage form").submit() }); </code></pre> <p>Any ideas on how to get these additional events to trigger onsubmit like I need it too?</p>
[ { "answer_id": 265473, "author": "Andrew Stanton-Nurse", "author_id": 29813, "author_profile": "https://Stackoverflow.com/users/29813", "pm_score": 0, "selected": false, "text": "$(\"#ShippingType, #ViewCart .ddl\").bind(\"change\", function() { $(\"#ViewCartPage form\").onsubmit({ preventDefault: function() {} }) });\n" }, { "answer_id": 288186, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "bind(\"change\", function() { $(\"#ViewCartPage form\").submit() });\n bind(\"change\", function() { $(\"#ViewCartPage form\").onsubmit() });\n" }, { "answer_id": 299347, "author": "Slee", "author_id": 34548, "author_profile": "https://Stackoverflow.com/users/34548", "pm_score": 4, "selected": true, "text": "var options = {\n target: '#updatedContent', // target element(s) to be updated with server response \n beforeSubmit: showRequest, // pre-submit callback \n success: showResponse // post-submit callback \n };\n\n$('#ViewCartPage form').ajaxForm(options);\n" }, { "answer_id": 1234602, "author": "Sichbo", "author_id": 113396, "author_profile": "https://Stackoverflow.com/users/113396", "pm_score": 2, "selected": false, "text": "function SubmitMvcAjaxForm(formName) {\n eval('var event = new Object(); event.type=\"keypress\"; ' + document.forms[formName].attributes[\"onsubmit\"].value.replace('(this,', '(document.forms[\"' + formName + '\"],'));\n}\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265293", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34548/" ]
265,302
<p>First some background. I am trying to run <a href="http://www.communityengine.org/" rel="nofollow noreferrer">Community Engine</a> on a fresh install of Ubuntu. CE is a open src social networking plugin running on Rails. I was able to get CE up and running on my windows box w/o issue. I have decided to use Ubuntu 8.10 as my development environment now, and am stuck on this issue. I have researched this for the last couple nights and am still stuck.</p> <p>What happens is, when i get to this step of the instruction (<a href="http://github.com/bborn/communityengine/tree/master" rel="nofollow noreferrer">found here</a>):</p> <pre><code> Generate the community engine migrations: $ script/generate plugin_migration </code></pre> <p>I get the following error:</p> <pre><code>myuser@compy:~/Projects/MyProject$ script/generate plugin_migration /home/myuser/Projects/MyProject/config/../vendor/plugins/engines/boot.rb:4: This version of the engines plugin requires Rails 2.1.1 or later! (RuntimeError) from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' from /home/myuser/Projects/MyProject/config/environment.rb:12 from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' from /home/myuser/Projects/MyProject/vendor/rails/railties/lib/commands/generate.rb:1 from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' from script/generate:3 </code></pre> <p>Here's my version of ruby:</p> <pre><code>myuser@compy:~/Projects/MyProject$ ruby -v ruby 1.8.7 (2008-08-11 patchlevel 72) [i486-linux] </code></pre> <p>and my installed gems:</p> <pre><code>myuser@compy:~/Projects/MyProject$ gem list *** LOCAL GEMS *** actionmailer (2.2.0, 2.1.2, 2.1.1) actionpack (2.2.0, 2.1.2, 2.1.1) activerecord (2.2.0, 2.1.2, 2.1.1) activeresource (2.2.0, 2.1.2, 2.1.1) activesupport (2.2.0, 2.1.2, 2.1.1) aws-s3 (0.5.1) builder (2.1.2) capistrano (2.5.0) cgi_multipart_eof_fix (2.5.0) daemons (1.0.10) fastthread (1.0.1) gem_plugin (0.2.3) haml (2.0.4) highline (1.4.0) hpricot (0.6.164) htmlentities (4.0.0) mime-types (1.15) mongrel (1.1.5) net-scp (1.0.1) net-sftp (2.0.1) net-ssh (2.0.4) net-ssh-gateway (1.0.0) rails (2.2.0, 2.1.2, 2.1.1) &lt;--- clearly I have rails 2.1.1 or greater rake (0.8.3) RedCloth (4.1.0) rmagick (2.7.1) sqlite3-ruby (1.2.4) xml-simple (1.0.11) </code></pre> <p>I got this error when i only had rails 2.1.1 as well.</p> <p>Yes, I have way more gems than i need for CE, but in trying to track this down, this is what i ended up with. I have a sneaking suspicion that whatever the issue is, it's dumb and i should of caught it. But at this point, I've grown very frustrated with what was a simple process on an XP box.</p> <p>I have asked this question in the Community Engine google group, however, I have a feeling that this is more related to my setup of Ruby and Rails on my machine than to CE itself.</p> <p>Help would be appreciated.</p>
[ { "answer_id": 266520, "author": "Orion Edwards", "author_id": 234, "author_profile": "https://Stackoverflow.com/users/234", "pm_score": 3, "selected": false, "text": "config/environment.rb # Specifies gem version of Rails to use when vendor/rails is not present\nRAILS_GEM_VERSION = '2.1.0' unless defined? RAILS_GEM_VERSION\n RAILS_GEM_VERSION config/environment.rb rake rails:upgrade" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265302", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23458/" ]
265,305
<p>How do I go about performing AES encryption on a GUID?</p> <p>On the clients computer we will store a GUID and their public key, and our internal servers will have the private key and their guid.</p> <p>Is this all the necessary inputs to generate the AES encryption?</p>
[ { "answer_id": 265352, "author": "Jesse C. Slicer", "author_id": 3312, "author_profile": "https://Stackoverflow.com/users/3312", "pm_score": 0, "selected": false, "text": "private static readonly byte[] rgbKey = Encoding.UTF8.GetBytes(\"Ni=9OE=$i+62eprIuDr@ewOu5I9r34Ro\"); // change to your own secure key\n\nprivate static readonly byte[] rgbIv = Encoding.UTF8.GetBytes(\"to$eO_e!maI*o3ut\"); // change to your own secure initialization vector\n\npublic static string Encrypt(string originalString)\n{\n if (string.IsNullOrEmpty(originalString))\n {\n throw new ArgumentNullException(\n \"originalString\",\n \"The string which needs to be encrypted can not be null.\");\n }\n\n using (var cryptoProvider = new RijndaelManaged())\n using (var memoryStream = new MemoryStream())\n using (var encryptor = cryptoProvider.CreateEncryptor(rgbKey, rgbIv))\n using (var cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write))\n using (var writer = new StreamWriter(cryptoStream))\n {\n writer.Write(originalString);\n writer.Flush();\n cryptoStream.FlushFinalBlock();\n writer.Flush();\n return Convert.ToBase64String(memoryStream.GetBuffer(), 0, (int)memoryStream.Length);\n }\n}\n\npublic static string Decrypt(string encryptedString)\n{\n if (string.IsNullOrEmpty(encryptedString))\n {\n throw new ArgumentNullException(\n \"encryptedString\",\n \"The string which needs to be decrypted can not be null.\");\n }\n\n using (var cryptoProvider = new RijndaelManaged())\n using (var memoryStream = new MemoryStream(Convert.FromBase64String(encryptedString)))\n using (var decryptor = cryptoProvider.CreateDecryptor(rgbKey, rgbIv))\n using (var cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read))\n using (var reader = new StreamReader(cryptoStream))\n {\n return reader.ReadToEnd();\n }\n}\n" }, { "answer_id": 265435, "author": "Adam Liss", "author_id": 29157, "author_profile": "https://Stackoverflow.com/users/29157", "pm_score": 1, "selected": false, "text": "void encrypt(char *plaintext, char *key, char *crypt)\n{\n // Encrypt plaintext with the key, returning the result in crypt.\n\n}\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265305", "https://Stackoverflow.com", "https://Stackoverflow.com/users/39677/" ]
265,324
<p>Ok, I am importing and parsing csv files in a C# app. I started out doing a simple ReadLine() and splitting on commas but it turns out some of the text fields have commas in them. So I started to roll my own splitting function. Fortunately, it was only a few minutes before the "Hey stupid, someone's probably already done this?" light came on and, after a few minutes of searching, realized I could just do an OleDb connection to the directory and import them that way. That worked like a champ, until I ran into a few files with commas and parentheses in the file names. Then it blew up. Any suggestions on getting it to import from files like that? And no, I have no control over the input file names. Some will probably be read directly from CD, so I can't temporarily change the file name.</p>
[ { "answer_id": 265346, "author": "Treb", "author_id": 22114, "author_profile": "https://Stackoverflow.com/users/22114", "pm_score": 1, "selected": false, "text": "Path.GetTempFileName()" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265324", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19038/" ]
265,335
<p>My table has the following schema:</p> <p>id, parent_id, text</p> <p>Given the following data I would like to return an xml hierarchy:</p> <p>Data: (1,null,'x'), (2,1,'y'), (3,1,'z'), (4,2,'a')</p> <p>XML:<br> [row text="x"]<br> [row text="y"]<br> [row text="a"/]<br> [/row]<br> [row text="z"/]<br> [/row] </p> <hr> <p>Added: the hierachy has no maximum depth</p>
[ { "answer_id": 265359, "author": "S.Lott", "author_id": 10661, "author_profile": "https://Stackoverflow.com/users/10661", "pm_score": -1, "selected": false, "text": "for top in cursor( nodes where each parent==null ):\n build_tree( top )\n\ndef build_tree( parent ):\n emit opening tag\n for child in cursor( nodes where parent == parent ):\n build_tree( child )\n emit closing tag\n" }, { "answer_id": 265479, "author": "Cristian Libardo", "author_id": 16526, "author_profile": "https://Stackoverflow.com/users/16526", "pm_score": 1, "selected": false, "text": "SELECT T.*, T2.*, T3.* /*, ...*/ FROM myTable T \nINNER JOIN myTable T2 ON T2.parent_id=T.id\nINNER JOIN myTable T3 ON T3.parent_id=T2.id\n/* ... */\nWHERE T.parent_id IS NULL\nFOR XML AUTO\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265335", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2133/" ]
265,339
<p>I'd like to automate the FTP download of a database backup file using PowerShell. The file name includes the date so I can't just run the same FTP script every day. Is there a clean way to do this built into PowerShell or using the .NET framework?</p> <p>I want to use a secure FTP session.</p>
[ { "answer_id": 265402, "author": "PabloG", "author_id": 394, "author_profile": "https://Stackoverflow.com/users/394", "pm_score": 3, "selected": false, "text": "$source = \"ftp://ftp.microsoft.com/ResKit/win2000/dureg.zip\"\n$target = \"c:\\temp\\dureg.zip\"\n$WebClient = New-Object System.Net.WebClient\n$WebClient.DownloadFile($source, $target)\n" }, { "answer_id": 265955, "author": "Alex", "author_id": 26564, "author_profile": "https://Stackoverflow.com/users/26564", "pm_score": -1, "selected": false, "text": "$realdate = (Get-Date).ToString(\"yyyyMMdd\")\n\n$path = \"D:\\samplefolderstructure\\filename\" + $realdate + \".msi\"\n\nftps -f $path -s:D:\\FTP.txt\n ftps" }, { "answer_id": 268907, "author": "Eric Ness", "author_id": 18891, "author_profile": "https://Stackoverflow.com/users/18891", "pm_score": 5, "selected": false, "text": "$sourceuri = \"ftp://ftp.secureftp-test.com/hamlet.zip\"\n$targetpath = \"C:\\hamlet.zip\"\n$username = \"test\"\n$password = \"test\"\n\n# Create a FTPWebRequest object to handle the connection to the ftp server\n$ftprequest = [System.Net.FtpWebRequest]::create($sourceuri)\n\n# set the request's network credentials for an authenticated connection\n$ftprequest.Credentials =\n New-Object System.Net.NetworkCredential($username,$password)\n\n$ftprequest.Method = [System.Net.WebRequestMethods+Ftp]::DownloadFile\n$ftprequest.UseBinary = $true\n$ftprequest.KeepAlive = $false\n\n# send the ftp request to the server\n$ftpresponse = $ftprequest.GetResponse()\n\n# get a download stream from the server response\n$responsestream = $ftpresponse.GetResponseStream()\n\n# create the target file on the local system and the download buffer\n$targetfile = New-Object IO.FileStream ($targetpath,[IO.FileMode]::Create)\n[byte[]]$readbuffer = New-Object byte[] 1024\n\n# loop through the download stream and send the data to the target file\ndo{\n $readlength = $responsestream.Read($readbuffer,0,1024)\n $targetfile.Write($readbuffer,0,$readlength)\n}\nwhile ($readlength -ne 0)\n\n$targetfile.close()\n $ftprequest.EnableSsl = $true\n" }, { "answer_id": 10622686, "author": "Nathan", "author_id": 497982, "author_profile": "https://Stackoverflow.com/users/497982", "pm_score": 0, "selected": false, "text": "$bkdir = \"E:\\BackupsPWS\" #backups location directory\n$7Zip = 'C:\\\"Program Files\"\\7-Zip\\7z.exe' #compression utility\n$files_to_transfer = New-Object System.Collections.ArrayList #list of zipped files to be transferred over FTP\n$ftp_uri=\"myftpserver\"\n$user=\"myftpusername\"\n$pass=\"myftppassword\"\n\n# Find .bak files not zipped yet, zip them, add them to the list to be transferrd\nget-childitem -path $bkdir | Sort-Object length |\nwhere { $_.extension -match \".(bak)\" -and\n -not (test-path ($_.fullname -replace \"(bak)\", \"7z\")) } |\nforeach {\n $zipfilename = ($_.fullname -replace \"bak\", \"7z\")\n Invoke-Expression \"$7Zip a $zipfilename $($_.FullName)\"\n $files_to_transfer.Add($zipfilename)\n}\n\n# Find .bak files, if they've been zipped, delete the .bak file\nget-childitem -path $bkdir |\nwhere { $_.extension -match \".(bak)\" -and\n (test-path ($_.fullname -replace \"(bak)\", \"7z\")) } |\nforeach { del $_.fullname }\n\n# Transfer each zipped file over FTP\nforeach ($file in $files_to_transfer)\n{\n $webclient = New-Object System.Net.WebClient\n $webclient.Credentials = New-Object System.Net.NetworkCredential($user,$pass) # FTP credentials\n $ftp_urix = $ftp_uri + \"/\" + $file.Substring($bkdir.Length + 1) # ftp address where to transfer the file\n $uri=[system.URI] $ftp_urix\n $webclient.UploadFile($uri, $file) #transfer the file\n}\n" }, { "answer_id": 62217774, "author": "Martin Prikryl", "author_id": 850848, "author_profile": "https://Stackoverflow.com/users/850848", "pm_score": 1, "selected": false, "text": "Stream.CopyTo $fileUrl = \"ftp://ftp.example.com/remote/path/file.zip\"\n$localFilePath = \"C:\\local\\path\\file.zip\"\n\n$downloadRequest = [Net.WebRequest]::Create($fileUrl)\n$downloadRequest.Method = [System.Net.WebRequestMethods+Ftp]::DownloadFile\n$downloadRequest.Credentials =\n New-Object System.Net.NetworkCredential(\"username\", \"password\")\n# Enable secure FTPS (FTP over TLS/SSL)\n$downloadRequest.EnableSsl = $True\n\n$sourceStream = $downloadRequest.GetResponse().GetResponseStream()\n$targetStream = [System.IO.File]::Create($localFilePath)\n$sourceStream.CopyTo($targetStream);\n\n$sourceStream.Dispose()\n$targetStream.Dispose()\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265339", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18891/" ]
265,351
<p>I'm using System.Windows.SplashScreen to add a splash screen to my WinForms app (it has a lot of WPF controls, but the 'main window' is still a System.Windows.Forms.Form object). When the splash screen closes the whole app goes as well.</p> <p>Can I stop it taking the whole app with it?</p>
[ { "answer_id": 265399, "author": "Wilka", "author_id": 1367, "author_profile": "https://Stackoverflow.com/users/1367", "pm_score": 0, "selected": false, "text": "form.ShowDialog();\n System.Windows.Forms.Application.Run(form)\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265351", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1367/" ]
265,361
<p>I am trying to get a simple demo started with ActiveMQ that will demonstrate a TCP to TCP route. I am coding the endpoints and routes in a camel context in my activemq.xml configuration file.</p> <pre><code>&lt;camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring"&gt; &lt;package&gt;org.myorg.codec&lt;/package&gt; &lt;endpoint id="listener_A" uri="mina:tcp://localhost:42000?sync=false&amp;amp;textline=true"/&gt; &lt;endpoint id="listener_B" uri="mina:tcp://localhost:42001?sync=false&amp;amp;textline=true"/&gt; &lt;route&gt; &lt;from uri="activemq:listener_A"/&gt; &lt;to uri="activemq:listener_B"/&gt; &lt;/route&gt; &lt;route&gt; &lt;from uri="activemq:listener_B"/&gt; &lt;to uri="activemq:listener_A"/&gt; &lt;/route&gt; &lt;/camelContext&gt; </code></pre> <p>Any idea why this doesn't work?</p> <p>The AMQ server does not seem to be opening a listening port.</p> <p>Edit: The intent here, as a simple demonstation, is to connect to ActiveMQ with two telnet terminals (A and B) and be able to route messages from one to another through the message queue server. Later, I may try filtering or routing based on content.</p>
[ { "answer_id": 265539, "author": "James Strachan", "author_id": 2068211, "author_profile": "https://Stackoverflow.com/users/2068211", "pm_score": 2, "selected": true, "text": "<route>\n <from ref=\"listener_A\"/>\n <to ref=\"listener_B\"/>\n</route>\n" }, { "answer_id": 270690, "author": "JeffV", "author_id": 445087, "author_profile": "https://Stackoverflow.com/users/445087", "pm_score": 0, "selected": false, "text": "<endpoint id=\"listener_A\" uri=\"mina:tcp://localhost:42000?sync=false&amp;textline=true\"/> \n <from uri=\"activemq:listener_A\"/> \n <from ref=\"listener_A\"/> \n <from ref=\"mina:tcp://localhost:42000?sync=false&amp;textline=true\"/>\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265361", "https://Stackoverflow.com", "https://Stackoverflow.com/users/445087/" ]
265,362
<p>Is there any way to create - manipulate calendar events in Exchange Server 2003 ? I'm using VB.NET 2005. I don't want to use MAPI because everytime I will have to type user name and passwords. Is there any other way ? I used redemption.dll but everytime I want to add for eg. a calendar event it displays the login screen.</p> <p>Any suggestions ?</p> <p>Appreciate your help</p> <p>Thank you</p>
[ { "answer_id": 265539, "author": "James Strachan", "author_id": 2068211, "author_profile": "https://Stackoverflow.com/users/2068211", "pm_score": 2, "selected": true, "text": "<route>\n <from ref=\"listener_A\"/>\n <to ref=\"listener_B\"/>\n</route>\n" }, { "answer_id": 270690, "author": "JeffV", "author_id": 445087, "author_profile": "https://Stackoverflow.com/users/445087", "pm_score": 0, "selected": false, "text": "<endpoint id=\"listener_A\" uri=\"mina:tcp://localhost:42000?sync=false&amp;textline=true\"/> \n <from uri=\"activemq:listener_A\"/> \n <from ref=\"listener_A\"/> \n <from ref=\"mina:tcp://localhost:42000?sync=false&amp;textline=true\"/>\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265362", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
265,370
<p>what is the best way to convert a UTF-16 files to UTF-8? I need to use this in a cmd script.</p>
[ { "answer_id": 265444, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 4, "selected": false, "text": "using System;\nusing System.IO;\nusing System.Text;\n\nclass FileConverter\n{\n static void Main(string[] args)\n {\n string inputFile = args[0];\n string outputFile = args[1];\n using (StreamReader reader = new StreamReader(inputFile, Encoding.Unicode))\n {\n using (StreamWriter writer = new StreamWriter(outputFile, false, Encoding.UTF8))\n {\n CopyContents(reader, writer);\n }\n }\n }\n\n static void CopyContents(TextReader input, TextWriter output)\n {\n char[] buffer = new char[8192];\n int len;\n while ((len = input.Read(buffer, 0, buffer.Length)) != 0)\n {\n output.Write(buffer, 0, len);\n }\n }\n}\n" }, { "answer_id": 266279, "author": "Kaarel", "author_id": 12547, "author_profile": "https://Stackoverflow.com/users/12547", "pm_score": 6, "selected": true, "text": "recode utf16..utf8 text.txt\n" }, { "answer_id": 55801894, "author": "Ben Collins", "author_id": 3279, "author_profile": "https://Stackoverflow.com/users/3279", "pm_score": 3, "selected": false, "text": "C:\\> powershell -c \"Get-Content mytext.txt | Set-Content -Encoding utf8 mytext_utf8.txt\"\n > gc mytext.txt | sc -Encoding utf8 mytext_utf8.txt\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265370", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5363/" ]
265,371
<p>I'm working on an app that takes data from our DB and outputs an xml file using the FOR XML AUTO, ELEMENTS on the end of the generated query, followed by an XSLT to transform it the way we want. However in a particular case where we are generating some data using an sql scalar function, it always puts that element into a sub-table node named the same as the table node it's already in (so say it's a table xyz, it'd be <code>print("&lt;xyz&gt;&lt;node1&gt;&lt;/node1&gt;&lt;xyz&gt;&lt;generated-node-from-function&gt;&lt;/generated-node-from-function&gt;&lt;/xyz&gt;");</code></p> <p>No matter what I try (even directly manipulating a copy of the sql as generated by the app) it always seems to create this extra node layer, which causes problems later when we try to process this xml to extract the data later. Is there any particular property causing the xml generator in sql server to work this way, and is there any way to prevent it so I can keep the generated data node on the same level as the rest of the data for the table it's associated with?</p> <p>Edit: renamed columns/tables in some cases but otherwise should be the same sql.</p> <pre><code>SELECT * FROM (SELECT column1,column2,column3,iduser,jstart,jstop,jbatchperiod,jinactive,processed,column4,lock,column5,batchticketmicr,machineid,sjobopex,szopexrefid,jreceived,jstartopex,jstopopex,idspecialmicr,idp2batchoriginal,stateflags,bcrossrefid,bidentifier1,bidentifier2,bidentifier3,bidentifier4,bidentifier5,idexport,idimport,rsahash FROM table1) table1 LEFT JOIN (SELECT column21,ienvelope,isort,column1,idtemplate,processed,column4,lock,envelopetypecode,szqueuesvisitedunique,exportdate,jcompleted,status,ipriority,idbankaccount,iprioritybeforerzbump,fstoredrecondata,cscountyid,column10,column11,checkbox1,checkbox2,column12,column13,column14,xxxempfein,column15,column16,originalenvelopeid,column17,column18,xxxoag,trackingnumber,csldc,ecrossrefid,postmark,routingflags,eidentifier1,eidentifier2,eidentifier3,eidentifier4,eidentifier5,idexport FROM envelope) envelope ON table1.column1=Envelope.column1 LEFT JOIN (SELECT column21,column22,isort,column23,processed,side,pagetypecode,rawmicrline,rawscanline,rawbarcode,exportid,szlocandconf,szlocandconfpagefields,idformtemplate,szparms,rawmarksense,audittrail,audittrailelectronic,pixheight,pixwidth,ocrattemptcounter,idspecialmicr,idpageexception,pagemodifierflags,column10,csldc,rejectdate,rejectuser,rejectqueue,fsupervisorreject,xxxempno,xxxtraceno,xxxemplcnt,checkbox1,keyword,templatealtered,templateflags,pidentifier1,pidentifier2,pidentifier3,pidentifier4,pidentifier5,isscanlinevalid,idexport,clickcount FROM Table2) Table2 ON Envelope.column21=Page.column21 LEFT JOIN (select column22, column21, dbo.Fileimagepath(column21, column22) as path from Table2) Fileimg ON Table2.column21=FileImg.column21 AND Table2.column22=FileImg.column22 WHERE Envelope.column21 = 8 FOR XML AUTO, ELEMENTS </code></pre> <p>Another edit: basically FileImg's results are getting wrapped in an extra set of Table2 tags inside existing table2 tab with the rest of the data.</p> <p>Yet another Edit: Testing against another database with the same sql it worked correctly, it appears there is a bad setting in my database or the stored proc is different <em>goes to investigate farther</em>.</p> <p>If that doesn't work I'll try some of the other suggestions above, thanks for the help so far :)</p>
[ { "answer_id": 265640, "author": "splattne", "author_id": 6461, "author_profile": "https://Stackoverflow.com/users/6461", "pm_score": 1, "selected": false, "text": "SELECT table1.column1, table1.column2, ..., envelope.column21, ...\nFROM table1 LEFT JOIN envelope on table1.column1 = envelope.column1 ...\nWHERE envelope.column21 = 8\nFOR XML AUTO, ELEMENTS \n" }, { "answer_id": 265744, "author": "splattne", "author_id": 6461, "author_profile": "https://Stackoverflow.com/users/6461", "pm_score": 1, "selected": false, "text": "FileImagePath return 'test'\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265371", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3326/" ]
265,379
<p>Here's the scenario:</p> <p>You have an ASP.Net application supported by a Microsoft SQL Server database, and for this example there won't be any caching.</p> <p>For each page in your web application, what's more efficient:</p> <p>Attempting to condense everything you need into one (or a few) stored procedure calls that return multiple tables with all of the data you need (which you save into a dataset),</p> <p><em>or</em> </p> <p>to make each call separate (reading each call via a datareader), depending on how it logically makes sense.</p> <p>The reason I ask is I always end up doing things the 2nd way: creating simple methods that connect to the database and grab some data for each little task I have (i.e. a method for populating a specific dropdown, another for the main information for the page, etc).</p> <p>My concern is that what ends up happening when a page is requested, if I look at the SQL Profiler for the server, there will end up being up to 10 or so calls for that single page request. Is that excessive? In my mind it seems like it would be more efficient to condense data gathering by pages opposed to by tasks. Anyone have any experience with this?</p>
[ { "answer_id": 265928, "author": "sykespro", "author_id": 34444, "author_profile": "https://Stackoverflow.com/users/34444", "pm_score": 0, "selected": false, "text": "protected void Page_Load(object sender, EventArgs e)\n{\n DataSet ds = PicklistHelper.GetPicklistData(\n new String[]{\"pl_usertypes\",\"pl_projecttypes\",\"pl_stattypes\"});\n // Bind dropdowns\n ddl_a.DataSource = ds.Tables[0]; // pl_usertypes\n ddl_a.DataBind();\n\n ddl_b.DataSource = ds.Tables[1]; // pl_projecttypes\n ddl_b.DataBind();\n\n ddl_c.DataSource = ds.Tables[2]; // pl_stattypes\n ddl_c.DataBind();\n}\n Select * from pl_usertypes; Select * from pl_projecttypes; Select * from pl_stattypes;\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265379", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30006/" ]
265,392
<p>I have long been wondering why lazy evaluation is useful. I have yet to have anyone explain to me in a way that makes sense; mostly it ends up boiling down to "trust me".</p> <p>Note: I do not mean memoization. </p>
[ { "answer_id": 265408, "author": "Romain Linsolas", "author_id": 26457, "author_profile": "https://Stackoverflow.com/users/26457", "pm_score": 3, "selected": false, "text": "if (conditionOne && conditionTwo) {\n doSomething();\n}\n" }, { "answer_id": 265433, "author": "Charles Bretana", "author_id": 32632, "author_profile": "https://Stackoverflow.com/users/32632", "pm_score": 1, "selected": false, "text": " if (ConditionA && ConditionB) ... \n class Employee\n{\n private int supervisorId;\n private Employee supervisor;\n\n public Employee(int employeeId)\n {\n // code to call database and fetch employee record, and \n // populate all private data fields, EXCEPT supervisor\n }\n public Employee Supervisor\n { \n get \n { \n return supervisor?? (supervisor = new Employee(supervisorId)); \n } \n }\n}\n" }, { "answer_id": 265519, "author": "Vinko Vrsalovic", "author_id": 5190, "author_profile": "https://Stackoverflow.com/users/5190", "pm_score": 3, "selected": false, "text": "import time\n\ndef now(): return time.time()\n\ndef fibonacci(n): #Recursion for fibonacci (not-lazy)\n if n < 2:\n return n\n else:\n return fibonacci(n-1)+fibonacci(n-2)\n\nbefore1 = now()\nnotlazy = [fibonacci(x) for x in range(20)]\nafter1 = now()\nbefore2 = now()\nlazy = (fibonacci(x) for x in range(20))\nafter2 = now()\n\n\nbefore3 = now()\nfor i in notlazy:\n print i\nafter3 = now()\n\nbefore4 = now()\nfor i in lazy:\n print i\nafter4 = now()\n\nprint \"Not lazy generation: %f\" % (after1-before1)\nprint \"Lazy generation: %f\" % (after2-before2)\nprint \"Not lazy output: %f\" % (after3-before3)\nprint \"Lazy output: %f\" % (after4-before4)\n" }, { "answer_id": 265548, "author": "Edward Kmett", "author_id": 34707, "author_profile": "https://Stackoverflow.com/users/34707", "pm_score": 6, "selected": false, "text": "foo x = x + 3\n foo x y = if condition1\n then some (complicated set of combinators) (involving bigscaryexpression)\n else if condition2\n then bigscaryexpression\n else Nothing\n where some x y = ...\n bigscaryexpression = ...\n condition1 = ...\n condition2 = ...\n let foo x y \n | condition1 = some (complicated set of combinators) (involving bigscaryexpression)\n | condition2 = bigscaryexpression\n | otherwise = Nothing\n where some x y = ...\n bigscaryexpression = ...\n condition1 = ...\n condition2 = ...\n if' True x y = x\nif' False x y = y\n" }, { "answer_id": 268843, "author": "Marc Bernier", "author_id": 23569, "author_profile": "https://Stackoverflow.com/users/23569", "pm_score": 2, "selected": false, "text": "bool Function(void) {\n if (!SubFunction1())\n return false;\n if (!SubFunction2())\n return false;\n if (!SubFunction3())\n return false;\n\n(etc)\n\n return true;\n}\n bool Function(void) {\n if (!SubFunction1() || !SubFunction2() || !SubFunction3() || (etc) )\n return false;\n return true;\n}\n" }, { "answer_id": 284180, "author": "Chris Eidhof", "author_id": 36929, "author_profile": "https://Stackoverflow.com/users/36929", "pm_score": 6, "selected": false, "text": "quickSort quickSort [] = []\nquickSort (x:xs) = quickSort (filter (< x) xs) ++ [x] ++ quickSort (filter (>= x) xs)\n minimum ls = head (quickSort ls)\n [2, 1, 3,]" }, { "answer_id": 309321, "author": "Thomas Danecker", "author_id": 9632, "author_profile": "https://Stackoverflow.com/users/9632", "pm_score": 5, "selected": false, "text": "square x = x * x\n square (square (square 2))\n > square (square (2 * 2))\n> square (square 4)\n> square (4 * 4)\n> square 16\n> 16 * 16\n> 256\n > (square (square 2)) * (square (square 2))\n> ((square 2) * (square 2)) * (square (square 2))\n> ((2 * 2) * (square 2)) * (square (square 2))\n> (4 * (square 2)) * (square (square 2))\n> (4 * (2 * 2)) * (square (square 2))\n> (4 * 4) * (square (square 2))\n> 16 * (square (square 2))\n> ...\n> 256\n > (square (square 2)) * (square (square 2))\n> ((square 2) * (square 2)) * ((square 2) * (square 2))\n> ((2 * 2) * (2 * 2)) * ((2 * 2) * (2 * 2))\n> (4 * 4) * (4 * 4)\n> 16 * 16\n> 256\n square (square (square 2))\n\n ||\n \\/\n\n *\n / \\\n \\ /\n square (square 2)\n\n ||\n \\/\n\n *\n / \\\n \\ /\n *\n / \\\n \\ /\n square 2\n\n ||\n \\/\n\n *\n / \\\n \\ /\n *\n / \\\n \\ /\n *\n / \\\n \\ /\n 2\n" }, { "answer_id": 327436, "author": "peeles", "author_id": 29788, "author_profile": "https://Stackoverflow.com/users/29788", "pm_score": 2, "selected": false, "text": " if( obj != null && obj.Value == correctValue )\n {\n // do smth\n }\n" }, { "answer_id": 1019559, "author": "Juliet", "author_id": 40516, "author_profile": "https://Stackoverflow.com/users/40516", "pm_score": 3, "selected": false, "text": "type 'a stack =\n | EmptyStack\n | StackNode of 'a * 'a stack\n\nlet rec append x y =\n match x with\n | EmptyStack -> y\n | StackNode(hd, tl) -> StackNode(hd, append tl y)\n type 'a lazyStack =\n | StackNode of Lazy<'a * 'a lazyStack>\n | EmptyStack\n\nlet rec append x y =\n match x with\n | StackNode(item) -> Node(lazy(let hd, tl = item.Force(); hd, append tl y))\n | Empty -> y\n lazy .Force() .Force()" }, { "answer_id": 7630864, "author": "ertes", "author_id": 1142792, "author_profile": "https://Stackoverflow.com/users/1142792", "pm_score": 3, "selected": false, "text": "learnPat AI.Instinct.Train.Delta" }, { "answer_id": 7631130, "author": "Owen", "author_id": 371739, "author_profile": "https://Stackoverflow.com/users/371739", "pm_score": 2, "selected": false, "text": "fix f = f (fix f)\n f (f (f ....\n fact = fix $ \\f n -> if n == 0 then 1 else n * f (n-1)\n fix f f def fix[A](f: A => A): A = f(fix(f))\n\nval fact = fix[Int=>Int] { f => n =>\n if (n == 0) 1\n else n*f(n-1)\n}\n f def fix[A](f: (=>A) => A): A = f(fix(f))\n\ndef fact1(f: =>Int=>Int) = (n: Int) =>\n if (n == 0) 1\n else n*f(n-1)\n\nval fact = fix(fact1)\n" }, { "answer_id": 12687636, "author": "MathematicalOrchid", "author_id": 1006010, "author_profile": "https://Stackoverflow.com/users/1006010", "pm_score": 3, "selected": false, "text": "for for goto" }, { "answer_id": 19892724, "author": "Will Ness", "author_id": 849891, "author_profile": "https://Stackoverflow.com/users/849891", "pm_score": 2, "selected": false, "text": "sum . take 10 $ [1..10000000000] sum . take 1000000 . drop 500 $ cycle [1..20]" }, { "answer_id": 31413786, "author": "onmyway133", "author_id": 1418457, "author_profile": "https://Stackoverflow.com/users/1418457", "pm_score": 1, "selected": false, "text": "largestDivisible :: (Integral a) => a \nlargestDivisible = head (filter p [100000,99999..]) \n where p x = x `mod` 3829 == 0 \n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265392", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25573/" ]
265,398
<p>I have an application that uses <code>window.open()</code> to generate dynamic popups. Unfortunately, I've had trouble creating the content of the new windows using the standard DOM functions (<code>createElement</code>, <code>appendChild</code>), and I've gone to using <code>document.write()</code> to generate the page.</p> <p>Concretely, how can I go from this:</p> <pre><code>function writePopup() { var popup = window.open("", "popup", "height=400px, width=400px"); var doc = popup.document; doc.write("&lt;html&gt;"); doc.write("&lt;head&gt;"); doc.write("&lt;title&gt;Written Popup&lt;/title&gt;"); doc.write("&lt;/head&gt;"); doc.write("&lt;body&gt;"); doc.write("&lt;p&gt;Testing Write&lt;/p&gt;"); doc.write("&lt;/body&gt;"); doc.write("&lt;/html&gt;"); doc.close(); } </code></pre> <p>To a function that creates the same popup using the DOM? </p> <p>Edit: I did consider using an absolutely positioned element to simulate a popup, and though it looks better, the users need to be able to print the information being shown.</p>
[ { "answer_id": 265409, "author": "tvanfosson", "author_id": 12950, "author_profile": "https://Stackoverflow.com/users/12950", "pm_score": 2, "selected": true, "text": "function writePopup(){\n var popup = window.open(\"\", \"_blank\", \"height=400px, width=400px\");\n var doc = popup.document;\n doc.title = 'Written Popup';\n\n var p = doc.createElement('p');\n p.innerHTML = 'Testing Write';\n doc.body.appendChild(p);\n}\n" }, { "answer_id": 265521, "author": "Eric Wendelin", "author_id": 25066, "author_profile": "https://Stackoverflow.com/users/25066", "pm_score": 2, "selected": false, "text": "var popup = window.open(\"\", \"popup\", \"height=400px, width=400px\"); \nvar doc = popup.document.documentElement;\nvar p = document.createElement(\"p\"); \np.innerHTML = \"blah\"; \ndoc.appendChild(p);\n" }, { "answer_id": 265540, "author": "scunliffe", "author_id": 6144, "author_profile": "https://Stackoverflow.com/users/6144", "pm_score": 2, "selected": false, "text": "doc.innerHTML = newDOM;\n" }, { "answer_id": 541456, "author": "bobince", "author_id": 18936, "author_profile": "https://Stackoverflow.com/users/18936", "pm_score": 2, "selected": false, "text": "doc.write('<!DOCTYPE ...><html><head></head><body></body></html>');\ndoc.close();\ndoc.body.appendChild(...);\n" }, { "answer_id": 4012095, "author": "tmim", "author_id": 263123, "author_profile": "https://Stackoverflow.com/users/263123", "pm_score": 0, "selected": false, "text": "function writePopup(){\n var htmlString=[\n \"<html>\",\n \"<head>\",\n \"<title>Written popup</title>\",\n \"</head><body>\",\n \"<p>Testing write</p>\",\n \"</body></html>\"\n ].join(\"\\n\");\n window.open(\"data:text/html,\"+encodeURIComponent(htmlString), \"_blank\", \"height=400px, width=400px\");\n}\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265398", "https://Stackoverflow.com", "https://Stackoverflow.com/users/32771/" ]
265,403
<p>I'm using jQuery to handle all my ajax needs for an ASP.NET site coded in VB. When I use the built in $.ajax function to POST to a code-behind function and there is an exception, it simply exits the function, and shows an error on the client side.</p> <p>Besides making debugging difficult when coding, the bigger issue is that the Application_Error function in Global.asax isn't firing when those exceptions occur. This is making it almost impossible to track production errors.</p> <p>Why would it not bubble up to Application_Error? Is the answer to wrap the code-behind function in a Catch statement?</p> <p>jQuery ajax function:</p> <pre><code>$.ajax({ type: "POST", url: "page.aspx/GetData", data: "{'param':'" + param_value + "'}", contentType: "application/json; charset=utf-8", dataType: "json", success: function(msg) { processData(msg); }, error: function(XMLHttpRequest, textStatus, errorThrown) { alert("Error: " + textStatus + " - " + errorThrown); } }); </code></pre> <p>VB.NET function:</p> <pre><code>&lt;Script.Services.ScriptMethod()&gt; _ &lt;WebMethod()&gt; _ Public Shared Function GetData(ByVal param As Integer) As String 'Parse some data Return data End Function </code></pre>
[ { "answer_id": 350284, "author": "Josiah I.", "author_id": 12322, "author_profile": "https://Stackoverflow.com/users/12322", "pm_score": 1, "selected": false, "text": "error: function(XMLHttpRequest, textStatus, errorThrown) {\n alert(\"Error: \" + XMLHttpRequest.responseText);\n}\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265403", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12322/" ]
265,423
<p>I have to build an HTML table that shows data for users versus pages visited. It seems klunky to use for and/or foreach loops, but I can't think of anything better. I'm using PHP, but I would assume that this is language agnostic.</p>
[ { "answer_id": 265461, "author": "Kent Fredric", "author_id": 15614, "author_profile": "https://Stackoverflow.com/users/15614", "pm_score": 3, "selected": true, "text": "$tableformat = '<table><thead>%s</thead><tbody>%s</tbody></table>';\n$rowformat = '<tr>%s</tr>'; \n$cellformat = '<td>%s</td>'; \n\n$hdata = '';\nforeach( $data[0] as $cellname => $cellvalue )\n{\n $hdata .= sprintf( $cellformat, $cellname ); \n}\n$hdata = sprintf( $rowformat, $hdata ); \n$rdata = \"\";\nforeach( $data as $rownum => $rowvalue ) \n{ \n $row = \"\";\n foreach( $rowvalue as $colname => $colvalue ) \n {\n $row .= sprintf( $cellformat, $colvalue ); \n }\n $rdata .= sprintf($rowformat,$row); \n}\nreturn sprintf( $tableformat, $hdata, $rdata ); \n $hdata = \"<tr><td>\" . implode( \"</td><td>\", array_keys( $data[0] )) . \"</td></tr>\";\n $rdata .= \"<tr><td>\" . implode( \"</td><td>\", $rowvalue ) . \"</td></tr>\"; \n $tableformat = '<table><thead>%s</thead><tbody>%s</tbody></table>';\n $rowformat = '<tr>%s</tr>'; \n $cellformat = '<td>%s</td>'; \n\nfunction tr( $cells )\n{ \n $o = \"\";\n foreach( $cells as $i => $v )\n { \n $o .= sprintf( $cellformat, $v ); \n }\n return sprintf( $rowformat, $o ); \n}\n\n\nreturn sprintf( $tableformat, \n tr( array_keys($data[0])), \n implode(\"\", array_map( 'tr', $data )) ); \n" }, { "answer_id": 265623, "author": "troelskn", "author_id": 18180, "author_profile": "https://Stackoverflow.com/users/18180", "pm_score": -1, "selected": false, "text": "implode function render_table($data) {\n $html = '<table>';\n $tr = array();\n foreach (array_keys($data[0]) as $key) {\n $tr[] = '<th>' . htmlspecialchars($key) . '</th>';\n }\n $html .= \"\\n\" . '<thead>' . \"\\n\" . '<tr>' . \"\\n\" . implode(\"\\n\", $tr) . '</tr>' . '</thead>';\n $tbody = array();\n foreach ($data as $row) {\n $tr = array();\n foreach ($row as $value) {\n $tr[] = '<td>' . htmlspecialchars($value) . '</td>';\n }\n $tbody[] = '<tr>' . \"\\n\" . implode(\"\\n\", $tr) . '</tr>';\n }\n $html .= \"\\n\" . '<tbody>' . \"\\n\" . implode(\"\\n\", $tbody) . '</tbody>';\n $html .= '</table>';\n return $html;\n}\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265423", "https://Stackoverflow.com", "https://Stackoverflow.com/users/572/" ]
265,425
<p>An XML attribute declared as xs:boolean can acceptable be "true", "false", "0" or "1". However, in .NET, Boolean.Parse() will only accept "true" or "false". If it sees a "0" or "1", it throws a "Bad Format" exception.</p> <p>So, given that, what's the best way to parse such a value into a Boolean?</p> <p>(Unfortunately, I'm limited to .NET 2.0 solutions, but if v3.5 offers something, I'd love to hear about it.)</p>
[ { "answer_id": 265440, "author": "mdb", "author_id": 8562, "author_profile": "https://Stackoverflow.com/users/8562", "pm_score": 2, "selected": false, "text": "CBool Boolean.Parse try/catch Boolean.TryParse CBool Microsoft.VisualBasic.CompilerServices.Conversions::ToBoolean" }, { "answer_id": 265450, "author": "Panos", "author_id": 8049, "author_profile": "https://Stackoverflow.com/users/8049", "pm_score": 6, "selected": true, "text": "XmlConvert.ToBoolean" }, { "answer_id": 265477, "author": "Treb", "author_id": 22114, "author_profile": "https://Stackoverflow.com/users/22114", "pm_score": 0, "selected": false, "text": " string InnerText = yourXmlNode.InnerText; \nif (InnerText.Equals(\"0\"))\n InnerText = \"false\";\nelse if (InnerText.Equals(\"1\"))\n InnerText = \"true\";\n" }, { "answer_id": 15900739, "author": "Bananas", "author_id": 1703252, "author_profile": "https://Stackoverflow.com/users/1703252", "pm_score": 0, "selected": false, "text": "return value === 'true' || Number(value)\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265425", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12725/" ]
265,457
<p>Is there any BNF grammar for regular expression?</p>
[ { "answer_id": 32760631, "author": "n611x007", "author_id": 611007, "author_profile": "https://Stackoverflow.com/users/611007", "pm_score": 4, "selected": false, "text": "BNF Grammar of Regular Expressions\n\nFollowing the precedence rules given previously, a BNF grammar for Perl-style regular expressions can be constructed as follows.\n<RE> ::= <union> | <simple-RE>\n<union> ::= <RE> \"|\" <simple-RE>\n<simple-RE> ::= <concatenation> | <basic-RE>\n<concatenation> ::= <simple-RE> <basic-RE>\n<basic-RE> ::= <star> | <plus> | <elementary-RE>\n<star> ::= <elementary-RE> \"*\"\n<plus> ::= <elementary-RE> \"+\"\n<elementary-RE> ::= <group> | <any> | <eos> | <char> | <set>\n<group> ::= \"(\" <RE> \")\"\n<any> ::= \".\"\n<eos> ::= \"$\"\n<char> ::= any non metacharacter | \"\\\" metacharacter\n<set> ::= <positive-set> | <negative-set>\n<positive-set> ::= \"[\" <set-items> \"]\"\n<negative-set> ::= \"[^\" <set-items> \"]\"\n<set-items> ::= <set-item> | <set-item> <set-items>\n<set-items> ::= <range> | <char>\n<range> ::= <char> \"-\" <char>\n expression = term\n\n term | expression\n\nterm = factor\n\n factor term\n\nfactor = atom\n\n atom metacharacter\n\natom = character\n\n .\n\n ( expression )\n\n [ characterclass ]\n\n [ ^ characterclass ]\n\n { min }\n\n { min , }\n\n { min , max }\n\ncharacterclass = characterrange\n\n characterrange characterclass\n\ncharacterrange = begincharacter\n\n begincharacter - endcharacter\n\nbegincharacter = character\n\nendcharacter = character\n\ncharacter =\n\n anycharacterexceptmetacharacters\n\n \\ anycharacterexceptspecialcharacters\n\nmetacharacter = ?\n\n * {=0 or more, greedy}\n\n *? {=0 or more, non-greedy}\n\n + {=1 or more, greedy}\n\n +? {=1 or more, non-greedy}\n\n ^ {=begin of line character}\n\n $ {=end of line character}\n\n $` {=the characters to the left of the match}\n\n $' {=the characters to the right of the match}\n\n $& {=the characters that are matched}\n\n \\t {=tab character}\n\n \\n {=newline character}\n\n \\r {=carriage return character}\n\n \\f {=form feed character}\n\n \\cX {=control character CTRL-X}\n\n \\N {=the characters in Nth tag (if on match side)}\n\n $N{=the characters in Nth tag (if not on match side)}\n\n \\NNN {=octal code for character NNN}\n\n \\b {=match a 'word' boundary}\n\n \\B {=match not a 'word' boundary}\n\n \\d {=a digit, [0-9]}\n\n \\D {=not a digit, [^0-9]}\n\n \\s {=whitespace, [ \\t\\n\\r\\f]}\n\n \\S {=not a whitespace, [^ \\t\\n\\r\\f]}\n\n \\w {='word' character, [a-zA-Z0-9_]}\n\n \\W {=not a 'word' character, [^a-zA-Z0-9_]}\n\n \\Q {=put a quote (de-meta) on characters, until \\E}\n\n \\U {=change characters to uppercase, until \\E}\n\n \\L {=change characters to uppercase, until \\E}\n\nmin = integer\n\nmax = integer\n\ninteger = digit\n\n digit integer\n\nanycharacter = ! \" # $ % & ' ( ) * + , - . / :\n ; < = > ? @ [ \\ ] ^ _ ` { | } ~\n 0 1 2 3 4 5 6 7 8 9\n A B C D E F G H I J K L M N O P Q R S T U V W X Y Z\n a b c d e f g h i j k l m n o p q r s t u v w x y z\n\n---\n\n[book: see also: Bucknall, Julian - the Tomes of Delphi: Algorithms \nand Datastructures - p. 37 - 'Using regular expressions' - \nhttp://www.amazon.com/exec/obidos/tg/detail/-\n/1556227361/qid=1065748783/sr=1-1/ref=sr_1_1/002-0122962-7851254?\nv=glance&s=books]\n\n---\n---\n\nInternet: see also:\n\n---\n\nCompiler: Grammar: Expression: Regular: Which grammar defines set of \nall regular expressions? [BNF]\nhttp://www.faqts.com/knowledge_base/view.phtml/aid/25950/fid/1263\n\n---\n\nPerl Regular Expression: Quick Reference 1.05\nhttp://www.erudil.com/preqr.pdf\n\n---\n\nTop: Computers: Programming: Languages: Regular Expressions: Perl\nhttp://dmoz.org/Computers/Programming/Languages/Regular_Expressions/Per\nl/\n\n---\n\nTSE: Search/Replace:Regular Expression:Backus Naur Form:What is \npossible BNF for regular expression?\nhttp://www.faqts.com/knowledge_base/view.phtml/aid/25714/fid/1236\n\n---\n\nDelphi: Search: Regular expression: Create: How to create a regular \nexpression parser in Delphi?\nhttp://www.faqts.com/knowledge_base/view.phtml/aid/25645/fid/175\n\n---\n\nDelphi: Search: Regular expression: How to add regular expression \nsearching to Delphi? [Systools]\nhttp://www.faqts.com/knowledge_base/view.phtml/aid/25295/fid/175\n\n----------------------------------------------------------------------\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265457", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23051/" ]
265,478
<p>I have some HTML and jQuery that slides a <code>div</code> up and down to show or hide` it when a link is clicked:</p> <pre class="lang-html prettyprint-override"><code>&lt;ul class="product-info"&gt; &lt;li&gt; &lt;a href="#"&gt;YOU CLICK THIS TO SHOW/HIDE&lt;/a&gt; &lt;div class="toggle"&gt; &lt;p&gt;CONTENT TO SHOW/HIDE&lt;/p&gt; &lt;/div&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> <pre class="lang-js prettyprint-override"><code>$('div.toggle').hide(); $('ul.product-info li a').click(function(event){ $(this).next('div').slideToggle(200); } </code></pre> <p>My question is: How do I use <code>preventDefault()</code> to stop the link acting as a link and adding "#" to the end of my URL &amp; jumping to the top of the page?</p> <p>I can't figure out the right syntax, I just keep getting an error saying </p> <blockquote> <p>preventDefault() is not a function.</p> </blockquote>
[ { "answer_id": 265499, "author": "Davide Gualano", "author_id": 28582, "author_profile": "https://Stackoverflow.com/users/28582", "pm_score": 9, "selected": true, "text": "$('div.toggle').hide();\n$('ul.product-info li a').click(function(event) {\n event.preventDefault();\n $(this).next('div').slideToggle(200);\n});\n" }, { "answer_id": 265583, "author": "Kent Fredric", "author_id": 15614, "author_profile": "https://Stackoverflow.com/users/15614", "pm_score": 4, "selected": false, "text": " $('div.toggle').hide();\n $('ul.product-info li a').click(function(event){\n $(this).next('div').slideToggle(200);\n+ return false; \n });\n" }, { "answer_id": 832570, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "<ul class=\"product-info\">\n <li>\n <a>YOU CLICK THIS TO SHOW/HIDE</a>\n <div class=\"toggle\">\n <p>CONTENT TO SHOW/HIDE</p>\n </div>\n </li>\n</ul>\n a{\n cursor: pointer;\n }\n" }, { "answer_id": 6188520, "author": "sebarmeli", "author_id": 506570, "author_profile": "https://Stackoverflow.com/users/506570", "pm_score": 3, "selected": false, "text": "return false;\n" }, { "answer_id": 7061847, "author": "Ryan Little", "author_id": 786216, "author_profile": "https://Stackoverflow.com/users/786216", "pm_score": 5, "selected": false, "text": "return false event.preventDefault();" }, { "answer_id": 9299864, "author": "Jefrey Bulla", "author_id": 1140099, "author_profile": "https://Stackoverflow.com/users/1140099", "pm_score": 4, "selected": false, "text": "<html lang=\"en\">\n<head>\n<script type=\"text/javascript\">\naddEventListener(\"load\",function(){\n var links= document.getElementsByTagName(\"a\");\n for (var i=0;i<links.length;i++){\n links[i].addEventListener(\"click\",function(e){\n alert(\"NOPE!, I won't take you there haha\");\n //prevent event action\n e.preventDefault();\n })\n }\n}); \n\n</script>\n</head>\n<body>\n<div>\n<ul>\n <li><a href=\"http://www.google.com\">Google</a></li>\n <li><a href=\"http://www.facebook.com\">Facebook</a></li>\n <p id=\"p1\">Paragraph</p>\n</ul>\n</div>\n<p>By Jefrey Bulla</p>\n</body>\n</html>\n" }, { "answer_id": 10478514, "author": "Musaddiq Khan", "author_id": 1304924, "author_profile": "https://Stackoverflow.com/users/1304924", "pm_score": 6, "selected": false, "text": "href href=\"javascript:;\" <ul class=\"product-info\">\n <li>\n <a href=\"javascript:;\">YOU CLICK THIS TO SHOW/HIDE</a>\n <div class=\"toggle\">\n <p>CONTENT TO SHOW/HIDE</p>\n </div>\n </li>\n</ul>\n" }, { "answer_id": 20963186, "author": "HATCHA", "author_id": 1510985, "author_profile": "https://Stackoverflow.com/users/1510985", "pm_score": 4, "selected": false, "text": "<ul class=\"product-info\">\n <li>\n <a href=\"javascript:void(0);\">YOU CLICK THIS TO SHOW/HIDE</a>\n <div class=\"toggle\">\n <p>CONTENT TO SHOW/HIDE</p>\n </div>\n </li>\n</ul>\n" }, { "answer_id": 21549336, "author": "1nstinct", "author_id": 2467036, "author_profile": "https://Stackoverflow.com/users/2467036", "pm_score": 3, "selected": false, "text": "<a href\"...\"> jQuery(\"a\").click(function(e){\n var self = jQuery(this);\n var href = self.attr('href');\n e.preventDefault();\n // needed operations\n\n window.location = href;\n});\n" }, { "answer_id": 40193846, "author": "RPichioli", "author_id": 5885146, "author_profile": "https://Stackoverflow.com/users/5885146", "pm_score": 2, "selected": false, "text": "return false; event.preventDefault(); javascript:void(0) undefined <a href=\"\" onclick=\"return false;\"> ... </a>\n <a href=\"javascript:void(0);\"> ... </a>\n" }, { "answer_id": 48447130, "author": "A-Sharabiani", "author_id": 4505446, "author_profile": "https://Stackoverflow.com/users/4505446", "pm_score": 5, "selected": false, "text": "<a href=\"javascript:;\">Click Me</a>\n <a href=\"javascript:void(0);\">Click Me</a>\n preventDefault() <a href='#' onclick=\"event.preventDefault()\">Click Me</a>\n inline onclick IIFE event preventDefault() <a href='#' onclick=\"(function(e){e.preventDefault();})(event)\">Click Me</a>\n" }, { "answer_id": 69134018, "author": "Md Afsar Uddin", "author_id": 7453228, "author_profile": "https://Stackoverflow.com/users/7453228", "pm_score": 2, "selected": false, "text": "window.event.preventDefault();\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265478", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26107/" ]
265,481
<p>We moved our Visual C++ 2003 solution to Visual 2005 and now we have problems deploying to clean XP machines.</p> <p>Our solution has a DLL project and a command line executable which uses this DLL. Both projects create and embed manifest files.</p> <p>Our installer also copies the VC8 CRT runtimes from the C:\Programme\Microsoft Visual Studio 8\VC\redist\x86\Microsoft.VC80.CRT\ to the install dir.</p> <p>When we install on a clean Windows XP, we see the error message "Application has failed to start ... application configuration is incorrect."</p> <p>Putting the exe in Depends.exe, says:</p> <pre><code>Error: The Side-by-Side configuration information for "c:\program files\MySoftware\vc8\BENCHMARK.EXE" contains errors. This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem (14001). Error: The Side-by-Side configuration information for "c:\program files\MySoftware\vc8\MYLIB-VC8.DLL" contains errors. This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem (14001). Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module. </code></pre> <p>Event viewer logs:</p> <pre><code>Dependent Assembly Microsoft.VC80.CRT could not be found and Last Error was The referenced assembly is not installed on your system. Resolve Partial Assembly failed for Microsoft.VC80.CRT. Reference error message: The referenced assembly is not installed on your system. Generate Activation Context failed for C:\Program Files\MySoftware\vc8\Benchmark.exe. Reference error message: The operation completed successfully. </code></pre> <p>I've read copying the msvcp80.dll,msvcr80.dll,msvcm80.dll and Microsoft.VC80.CRT.manifest to application folder is sufficient.</p> <p>What am I doing wrong ?</p>
[ { "answer_id": 331440, "author": "gengmao", "author_id": 70742, "author_profile": "https://Stackoverflow.com/users/70742", "pm_score": 2, "selected": false, "text": "C/C++ -> Code Generation -> Runtime Library: Multi-threaded (/MT)\n Linker -> Input -> Ignore Specific Library: msvcrt.lib\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265481", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23000/" ]
265,484
<p>I think the field type should be string of variable length (VARCHAR), but what length should I use? </p> <p>To clarify: I want to pick a size that would be able to store <em>average</em> URL, and don't really care about maximum possible.</p>
[ { "answer_id": 265509, "author": "scunliffe", "author_id": 6144, "author_profile": "https://Stackoverflow.com/users/6144", "pm_score": 1, "selected": false, "text": "javascript:var foo='bar';...alert('Hello World');\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265484", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28098/" ]
265,494
<p>I have a website which uses themes. Depending on the url (if it is A.something.com or B.something.com, where A and B represent clients), I will load a different theme. The intention is to use one codebase for different clients. I have an app_themes folder, several themes inside, for different clients, and different CSS files for each theme (for business reasons the CSS file is the same for each theme, but duplicated). So my code looks like this:</p> <p>Public Overrides Property StyleSheetTheme() As String</p> <pre><code> Get Dim myHost As String = Request.Url.Host Return myHost End Get Set(ByVal value As String) End Set End Property Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit If Request.Url.Host.Contains("Savills") Then Page.Theme = "Savills" ElseIf Request.Url.Host.Contains("localhost") Then Page.Theme = "localhost" ElseIf Request.Url.Host.Contains("test.concepglobal.com") Then Page.Theme = "test.concepglobal.com" ElseIf Request.Url.Host.Contains("concepglobal") Then Page.Theme = "concepglobal" End If End Sub </code></pre> <p>My app_themes folder structure:</p> <p>App_Themes:</p> <p>localhost:</p> <p>Default.css</p> <p>Savills</p> <p>Savills.css</p> <p>However, everytime I load the site, the css is not picked up. So I don't get the h1 style I designed in the css (it is in there), but only the graphics specified in the aspx page.</p> <p>My source when running the site:</p> <p> (loading the site at that url).</p> <p>Confusingly, there is another link to the same css:</p> <p></p> <p>What am I doing wrong?</p> <p>Thanks </p>
[ { "answer_id": 265513, "author": "DOK", "author_id": 27637, "author_profile": "https://Stackoverflow.com/users/27637", "pm_score": 2, "selected": false, "text": "<location path=\"App_Themes\">\n <system.web>\n <authorization>\n <allow users=\"?\" />\n </authorization>\n </system.web>\n </location>\n" }, { "answer_id": 272202, "author": "Keltex", "author_id": 28260, "author_profile": "https://Stackoverflow.com/users/28260", "pm_score": 0, "selected": false, "text": "<system.web>\n <pages theme=\"concepglobal\"></pages>\n</system.web>\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265494", "https://Stackoverflow.com", "https://Stackoverflow.com/users/32484/" ]
265,505
<p>how do you go about saving images and displaying them from a SQL Server Image field when using ASP.NET MVC?</p> <p>Many thanks Nick</p>
[ { "answer_id": 271804, "author": "Simon Steele", "author_id": 4591, "author_profile": "https://Stackoverflow.com/users/4591", "pm_score": 0, "selected": false, "text": "public void RenderImage(int imageId)\n{\n // TODO: Replace this with your API to get the image blob data.\n byte[] data = this.repo.GetImageData(imageId);\n\n if (data != null)\n {\n // This assumes you're storing JPEG data\n Response.ContentType = \"image/jpeg\";\n Response.Expires = 0;\n Response.Buffer = true;\n Response.Clear();\n Response.BinaryWrite(data);\n }\n else\n {\n this.ControllerContext.HttpContext.ApplicationInstance.CompleteRequest();\n }\n}\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265505", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5463/" ]
265,508
<p>I need a dropdown list on my page that will allow a user to select their state. Since this is probably a control that will be used elsewhere, I thought it would be a good idea to create an MVC View User Control that could be reused.</p> <p>I was thinking the control would look something like this:</p> <pre><code>&lt;select name="" id=""&gt; &lt;option value="AL"&gt;Alabama&lt;/option&gt; &lt;option value="AK"&gt;Alaska&lt;/option&gt; &lt;/select&gt; </code></pre> <p>And the code in my view would be something like:</p> <pre><code>&lt;%= Html.RenderPartial("StateDropdownControl") %&gt; </code></pre> <p>My question is, what's the best way to set the name and id on the control? I'd want to make sure I could have multiple instances of this control on one page, if needed. Also, I'd want to be able to send in the state that should be selected by default.</p> <p>Would I do it with ViewData somehow?</p>
[ { "answer_id": 265543, "author": "Corey Gaudin", "author_id": 31195, "author_profile": "https://Stackoverflow.com/users/31195", "pm_score": 2, "selected": false, "text": " \n\n<%= Html.RenderPartial(\"/someDirectory/SomeControl.ascx\", \"MyID\") %>\n\n\nand in the UserControl do the following:\n\n<select name=\"<%=ViewData.Model%>\" id=\"<%=ViewData.Model%>\">\n\n....\n\n\nJust to be sure, a better way to handle it is to make a simple DTO (data transfer object) to hold that information so you can pass more information to your user control, that you will inevitably need.\n\nExample:\n\n\nclass ComboData \n{\n string ID {get;set;}\n string CssClass {get;set;}\n //Other stuff here\n}\n\n\n\n<%\nvar comboData = new ComboData {ID = \"myID\", CssClass = \"comboStyle\" }\n\n%>\n\n<%= Html.RenderPartial(\"/someDirectory/SomeControl.ascx\", comboData) %>\n\n\n <%= Html.RenderPartial(\"/someDirectory/SomeControl.ascx\", \"MyID\") %>\n <select name=\"<%=ViewData.Model%>\" id=\"<%=ViewData.Model%>\">\n\n....\n \nclass ComboData \n{\n string ID {get;set;}\n string CssClass {get;set;}\n //Other stuff here\n}\n \n<%\nvar comboData = new ComboData {ID = \"myID\", CssClass = \"comboStyle\" }\n\n%>\n\n<%= Html.RenderPartial(\"/someDirectory/SomeControl.ascx\", comboData) %>\n <select name=\"<%=ViewData.Model.ID%>\" id=\"<%=ViewData.Model.ID%>\" class=\"<%=ViewData.Model.CssClass%>\">\n\n....\n" }, { "answer_id": 265598, "author": "CubanX", "author_id": 27555, "author_profile": "https://Stackoverflow.com/users/27555", "pm_score": 4, "selected": true, "text": "public class StateDropDownPresentationModel\n{\n public string DropDownID { get; set; }\n public string SelectedState { get; set; }\n}\n <%= Html.RenderPartial(\"/someDirectory/SomeControl.ascx\", new StateDropDownPresentationModel { DropDownID = \"MyID\", SelectedState = \"IL\" } %>\n" }, { "answer_id": 272617, "author": "Matthew", "author_id": 20162, "author_profile": "https://Stackoverflow.com/users/20162", "pm_score": 1, "selected": false, "text": "<%= Html.DropDownList(\"SelectStates\"); %>\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265508", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34720/" ]
265,515
<p>Just wondering what people think is the best practice when implementing an IValueConverter which does not have a meaningfull ConvertBack implementation (or one that is only to be used as OneWay)?</p> <p>Should it throw (and in that case what exception), return null or return some default value. </p> <p>Thoughts?</p>
[ { "answer_id": 265544, "author": "Todd White", "author_id": 30833, "author_profile": "https://Stackoverflow.com/users/30833", "pm_score": 7, "selected": true, "text": "IValueConverter.ConvertBack DependencyProperty.UnsetValue" }, { "answer_id": 265558, "author": "Tamir", "author_id": 30879, "author_profile": "https://Stackoverflow.com/users/30879", "pm_score": 3, "selected": false, "text": "DependencyProperty.UnsetValue" }, { "answer_id": 38888483, "author": "bytecode77", "author_id": 1199684, "author_profile": "https://Stackoverflow.com/users/1199684", "pm_score": 3, "selected": false, "text": "ConvertBack Convert ConverterBase IValueConverter Convert ConvertBack public class ConverterBase : IValueConverter\n{\n public virtual object Convert(object value, Type targetType, object parameter, CultureInfo culture)\n {\n return DependencyProperty.UnsetValue;\n }\n public virtual object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)\n {\n return DependencyProperty.UnsetValue;\n }\n}\n\npublic class VisibilityConverter : ConverterBase\n{\n public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)\n {\n return ((bool)value ^ (parameter as bool? == true)).ToVisibility();\n }\n}\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265515", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9222/" ]
265,516
<p>Are hints really necessary for every sql statement? We have a dba who is anal about it and asks us to put hints on every select and update statements in our stored procs. Is this really necessary?</p>
[ { "answer_id": 265550, "author": "Joel Coehoorn", "author_id": 3043, "author_profile": "https://Stackoverflow.com/users/3043", "pm_score": 1, "selected": false, "text": "with (nolock)" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265516", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2137/" ]
265,518
<p>Create a flat text file in c++ around 50 - 100 MB with the content 'Added first line' should be inserted in to the file for 4 million times</p>
[ { "answer_id": 265557, "author": "Ferruccio", "author_id": 4086, "author_profile": "https://Stackoverflow.com/users/4086", "pm_score": 4, "selected": false, "text": "creat() open() chsize()" }, { "answer_id": 265575, "author": "Kip", "author_id": 18511, "author_profile": "https://Stackoverflow.com/users/18511", "pm_score": 2, "selected": false, "text": "#include <stdio.h>\nint main ()\n{\n const int FILE_SiZE = 50000; //size in KB\n const int BUFFER_SIZE = 1024;\n char buffer [BUFFER_SIZE + 1];\n int i;\n for(i = 0; i < BUFFER_SIZE; i++)\n buffer[i] = (char)(i%8 + 'a');\n buffer[BUFFER_SIZE] = '\\0';\n\n FILE *pFile = fopen (\"somefile.txt\", \"w\");\n for (i = 0; i < FILE_SIZE; i++)\n fprintf(pFile, buffer);\n\n fclose(pFile);\n\n return 0;\n}\n" }, { "answer_id": 38927643, "author": "EvilTeach", "author_id": 7734, "author_profile": "https://Stackoverflow.com/users/7734", "pm_score": 0, "selected": false, "text": "fopen the file for write.\nfseek to the desired file size - 1.\nfwrite a single byte\nfclose the file\n\ncreate a string containing the \"Added first line\\n\" a thousand times.\nfind it's length.\n fopen the file for write.\nfseek to the the string length * 4000\nfwrite a single byte\nfclose the file\n\nopen the file for read/write\nloop 4000 times, \n writing the string to the file.\nclose the file.\n" }, { "answer_id": 57706371, "author": "orfruit", "author_id": 1734108, "author_profile": "https://Stackoverflow.com/users/1734108", "pm_score": 1, "selected": false, "text": "int i;\nFILE *fp;\n\nfp = fopen(fname,\"wb\");\n\nif (fp != NULL) {\n\n // create big block's data\n uint8_t b[278528]; // some big chunk size\n\n for( i = 0; i < sizeof(b); i++ ) // custom initialization if != 0x00\n {\n b[i] = 0xFF;\n }\n\n // write all blocks to file\n for( i = 0; i < TOT_BLOCKS; i++ )\n fwrite(&b, sizeof(b), 1, fp);\n\n fclose (fp);\n}\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265518", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22076/" ]
265,524
<p>We have a few applications that use the same Linq 2 SQL DataContext. One of those Apps wil do massive inserts (it's a convertor from an old system). Is it possible to change the UpdateCheck of the TimeStamp column of each table at runtime ? Only for this one app we'd like to set it to Never, all the other apps should have Always.</p>
[ { "answer_id": 265582, "author": "Panos", "author_id": 8049, "author_profile": "https://Stackoverflow.com/users/8049", "pm_score": 1, "selected": false, "text": "[Column(Name=\"ITM_CREATE_DATE\", Storage=\"_ITM_CREATE_DATE\", DbType=\"DateTime NOT NULL\", UpdateCheck=UpdateCheck.Never)]\npublic System.DateTime CreationDate\n <DataContext>.designer.cs" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265524", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34723/" ]
265,528
<p>Many web sites support folksonomy tags. You may have heard of <a href="http://microformats.org/wiki/reltag" rel="nofollow noreferrer">rel-tag</a>, where it says that "The last path component of the URL is the text of the tag".</p> <p>I am looking for a bookmarklet or greasemonkey script (javascript) to get the "last path component" for the URL currently being viewed in the browser, add that tag into another URL, and then open that page in a new tab or window.</p> <p>For example, if I am looking at a <a href="http://delicious.com/popular/foo" rel="nofollow noreferrer">delicious.com page with the tag "foo"</a>, I may want to create <a href="http://technorati.com/tag/foo" rel="nofollow noreferrer">a new URL with the tag "foo"</a>. This should also work for multiple tags in the last path component, such as, <a href="http://delicious.com/popular/foo+bar" rel="nofollow noreferrer">foo+bar</a>.</p> <p>Some <a href="http://microformats.org/discuss/mail/microformats-discuss/2008-June/012144.html" rel="nofollow noreferrer">regexp suggestions</a> have been offered.</p>
[ { "answer_id": 321492, "author": "Jan Goyvaerts", "author_id": 33358, "author_profile": "https://Stackoverflow.com/users/33358", "pm_score": 0, "selected": false, "text": "^[a-z]+://[^/#?]+/[^#?]*?([^#?/]+)(?:[#?]|$)\n ^([^#?]*?)/?(?:[#?]|$)\n $1/tag\n" }, { "answer_id": 817324, "author": "Peter Boughton", "author_id": 9360, "author_profile": "https://Stackoverflow.com/users/9360", "pm_score": 3, "selected": true, "text": "location.pathname var NewUrl = 'http://technorati.com/tag/';\nvar LastPart = location.pathname.match( /[^\\/]+\\/?$/ );\nwindow.open( NewUrl + LastPart );\n /[^\\/]+\\$/ /[^\\/]+\\/*$/" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265528", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31241/" ]
265,530
<p>IDE: Microsoft Visual Studio Professional 2008</p> <p>Language: C#</p> <p>Background: I have one form and two groupboxes that are going to be used as preference catagory groupboxes. My problem is that everytime I drag one groupbox on top of the other (hide/show groupboxes upon listview catagory select), the base groupbox auto-parents the second groupbox I just dragged on top.</p> <p>Question: How do I stop the two groupboxes from auto-parenting themselves when dragged on top of one another?</p> <p>// Edit;</p> <p>Q) I assume you are trying to acheive a layout where you swap out the visible box? --Mitchel Sellers</p> <p>A) Yes I am. I know I could do it at runtime but I'd like to make that my last option in case there is a more appropriate solution.</p>
[ { "answer_id": 423772, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": " private void radioButton1_CheckedChanged(object sender, EventArgs e)\n {\n groupBox1.Location = new System.Drawing.Point(198, 234);\n groupBox2.Location = new System.Drawing.Point(660, 234);\n groupBox1.Visible = true;\n groupBox2.Visible = false;\n\n }\n\n private void radioButton2_CheckedChanged(object sender, EventArgs e)\n {\n groupBox1.Location = new System.Drawing.Point(660, 234);\n groupBox2.Location = new System.Drawing.Point(198, 234); \n groupBox1.Visible = false;\n groupBox2.Visible = true;\n }\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265530", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
265,541
<p>Not wanting to re-invent the wheel or anything, I was wondering if there's a plugin out there a field or form validation plugin that works with Prototype that you can recommend from your own experience and why?</p>
[ { "answer_id": 267512, "author": "Chase Seibert", "author_id": 7679, "author_profile": "https://Stackoverflow.com/users/7679", "pm_score": 0, "selected": false, "text": "<input type=\"text\" name=\"myDate\" class=\"validate-date\"/>\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265541", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2977/" ]
265,559
<p>When @RadioServiceGroup is set to NULL, I want to return all the records from the sbi_l_radioservicecodes table which has about 120 records. However, when I execute the following procedure and set the @RadioServiceGroup to NULL, it returns no records. Here is the stored proc:</p> <pre><code>CREATE PROCEDURE [dbo].[GetRadioServiceCodes] @RadioServiceGroup nvarchar(1000) = NULL AS BEGIN IF(@RadioServiceGroup = NULL) BEGIN SELECT rsc.RadioService FROM sbi_l_radioservicecodes rsc END ELSE BEGIN SELECT rsc.RadioService FROM sbi_l_radioservicecodes rsc WHERE rsc.RadioServiceGroup = @RadioServiceGroup END END </code></pre>
[ { "answer_id": 265569, "author": "Joel Coehoorn", "author_id": 3043, "author_profile": "https://Stackoverflow.com/users/3043", "pm_score": 1, "selected": false, "text": "If CREATE PROCEDURE [dbo].[GetRadioServiceCodes] \n@RadioServiceGroup nvarchar(1000) = NULL\nAS\nBEGIN \n SELECT rsc.RadioService\n FROM sbi_l_radioservicecodes rsc\n WHERE \n rsc.RadioServiceGroup = @RadioServiceGroup \n OR @RadioServiceGroup IS NULL\nEND\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265559", "https://Stackoverflow.com", "https://Stackoverflow.com/users/33690/" ]
265,579
<p><strong>Update:</strong> Since development machine has moved to Vista, i now automatically test as a standard user. And with XP being phased out, this question isn't so relavent anymore.</p> <hr> <p>Since the Windows 2000 logo requirements, Microsoft has been requiring that applications run as standard user. Like everyone else i always ran my desktop as an administrative user. And like every developer: i log in, develop, run, and test as an administrative user.</p> <p>Now with a new push to finally support standard users, i've been testing my applications by running them as a normal user - either through RunAs, or having my application relaunch itself with normal rights using <code>[SaferCreateLevel][1]</code>/<code>[SaferComputeTokenFromLevel][2]</code> if it detects it is running as an administrator. i quickly see how specacularly some of my apps fail under Windows XP as a standard user (due to my own stupidity). i also see how the same applications work fine under Vista (thanks to it's numerous shims to fix my bugs for me). </p> <p><strong>Aside:</strong> It's ironic that applications are more likely to run on Vista as a standard user than on XP.</p> <p>The question is do you test your applications for standard user compatiblity? Do you develop as a standard user on XP? Do you ignore standard user access and hope for the best?</p> <hr> <p>i tried, as a bonus, to have my app relaunch itself as a limited user (rather than normal user). It doesn't even come up - Windows says it failed to initialize. So there an area of future research on my part: making the app even support limited user.</p> <hr> <p>i specifically referred to standard users on XP rather than Vista to enforce the truth that Vista is no different from XP as far as compatibility is concerned. And anyone who says their app fails on Vista must realize it also fails on XP.</p>
[ { "answer_id": 265590, "author": "Joel Coehoorn", "author_id": 3043, "author_profile": "https://Stackoverflow.com/users/3043", "pm_score": 2, "selected": false, "text": "Application Data" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265579", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12597/" ]
265,585
<p>For example:</p> <pre><code>public class A : A.B { public class B { } } </code></pre> <p>Which generates this error from the compiler:</p> <blockquote> <p>Circular base class dependency involving 'A' and 'A.B'</p> </blockquote> <p>I always figured a nested class behaved just like a regular class except with special rules concerning accessing the outer class's private members, but I guess there's some implicit inheritance occurring between the two classes?</p>
[ { "answer_id": 265599, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 6, "selected": true, "text": "A.B x = new A.B.B.B.B.B.B.B.B.B.B.B.B();\n" }, { "answer_id": 265838, "author": "Tinister", "author_id": 34715, "author_profile": "https://Stackoverflow.com/users/34715", "pm_score": 1, "selected": false, "text": "public class A : A.AA\n{\n public class AA\n {\n // All of the class's logic\n }\n\n private AA _containedObject;\n}\n" }, { "answer_id": 39197714, "author": "Dave Cousineau", "author_id": 621316, "author_profile": "https://Stackoverflow.com/users/621316", "pm_score": 0, "selected": false, "text": "public class MyClass<T1, T2, T3> :\n MyClass<T1, T2, T3>.Interface\nwhere T1 : ...\nwhere T2 : ... \nwhere T3 : ... {\n public interface Interface { Interface SomeMethod(); }\n\n Interface Interface.SomeMethod() {\n ...\n }\n}\n\n// compile error: Circular base class dependency\n public sealed class MyClassInterfaces<T1, T2, T3>\nwhere T1 : ...\nwhere T2 : ... \nwhere T3 : ... {\n public interface Interface { Interface SomeMethod(); }\n}\n\nsealed class MyClass<T1, T2, T3> :\n MyClassInterfaces<T1, T2, T3>.Interface\nwhere T1 : ...\nwhere T2 : ... \nwhere T3 : ... {\n MyClassInterfaces<T1, T2, T3>.Interface\n MyClassInterfaces<T1, T2, T3>.Interface.SomeMethod() {\n ...\n }\n}\n public abstract class MyClassInterfaces<T1, T2, T3>\nwhere T1 : ...\nwhere T2 : ... \nwhere T3 : ... {\n public interface Interface { Interface SomeMethod(); }\n}\n\nsealed class MyClass<T1, T2, T3> :\n MyClassInterfaces<T1, T2, T3>,\n MyClassInterfaces<T1, T2, T3>.Interface\nwhere T1 : ...\nwhere T2 : ... \nwhere T3 : ... {\n Interface Interface.SomeMethod() {\n ...\n }\n}\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265585", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34715/" ]
265,592
<p>Let me preface this by saying I don't care what language this solution gets written in as long as it runs on windows. </p> <p>My problem is this: there is a site that has data which is frequently updated that I would like to get at regular intervals for later reporting. The site requires JavaScript to work properly so just using wget doesn't work. What is a good way to either embed a browser in a program or use a stand-alone browser to routinely scrape the screen for this data? </p> <p>Ideally, I'd like to grab certain tables on the page but can resort to regular expressions if necessary.</p>
[ { "answer_id": 265618, "author": "Tomalak", "author_id": 18771, "author_profile": "https://Stackoverflow.com/users/18771", "pm_score": 2, "selected": false, "text": "CreateObject(\"InternetExplorer.Application\") Navigate2() Set ie = CreateObject(\"InternetExplorer.Application\")\nie.Visible = True\nie.Navigate2 \"http://stackoverflow.com\"\n document.ReadyState" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265592", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14744/" ]
265,605
<p>I have a stored procedure that creates and opens some cursors. It closes them at the end, but if it hits an error those cursors are left open! Then subsequent runs fail when it tries to create cursors since a cursor with the name already exists.</p> <p>Is there a way I can query which cursors exists and if they are open or not so I can close and deallocate them? I feel like this is better than blindly trying to close and swallow errors.</p>
[ { "answer_id": 278120, "author": "Aaron Silverman", "author_id": 26197, "author_profile": "https://Stackoverflow.com/users/26197", "pm_score": 3, "selected": true, "text": "CREATE PROCEDURE dbo.p_cleanUpCursor @cursorName varchar(255) AS\nBEGIN\n\n DECLARE @cursorStatus int\n SET @cursorStatus = (SELECT cursor_status('global',@cursorName))\n\n DECLARE @sql varchar(255)\n SET @sql = ''\n\n IF @cursorStatus > 0\n SET @sql = 'CLOSE '+@cursorName\n\n IF @cursorStatus > -3\n SET @sql = @sql+' DEALLOCATE '+@cursorName\n\n IF @sql <> ''\n exec(@sql)\n\nEND\n" }, { "answer_id": 16177583, "author": "BlackICE", "author_id": 264607, "author_profile": "https://Stackoverflow.com/users/264607", "pm_score": 2, "selected": false, "text": "USE MASTER\nGO\nselect s.session_id, s.host_name, s.program_name, s.client_interface_name, s.login_name\n, c.cursor_id, c.properties, c.creation_time, c.is_open, con.text,\nl.resource_type, d.name, l.request_type, l.request_Status, l.request_reference_count, l.request_lifetime, l.request_owner_type\nfrom sys.dm_exec_cursors(0) c\nleft outer join (select * from sys.dm_exec_connections c cross apply sys.dm_exec_sql_text(c.most_recent_sql_handle) mr) con on c.session_id = con.session_id\nleft outer join sys.dm_exec_sessions s on s.session_id = c.session_id\nleft outer join sys.dm_tran_locks l on l.request_session_id = c.session_id\nleft outer join sys.databases d on d.database_id = l.resource_database_id\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265605", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26197/" ]
265,613
<p>How can I add new application mapping in IIS using vbscript?</p> <p>Thanks,</p>
[ { "answer_id": 265701, "author": "Tomalak", "author_id": 18771, "author_profile": "https://Stackoverflow.com/users/18771", "pm_score": 2, "selected": false, "text": "adsutil.vbs adsutil.vbs" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265613", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
265,628
<p>I added the columns in the select list to the order by list, but it is still giving me the error:</p> <p>ORDER BY items must appear in the select list if SELECT DISTINCT is specified.</p> <p>Here is the stored proc:</p> <pre><code>CREATE PROCEDURE [dbo].[GetRadioServiceCodesINGroup] @RadioServiceGroup nvarchar(1000) = NULL AS BEGIN SET NOCOUNT ON; SELECT DISTINCT rsc.RadioServiceCodeId, rsc.RadioServiceCode + ' - ' + rsc.RadioService as RadioService FROM sbi_l_radioservicecodes rsc INNER JOIN sbi_l_radioservicecodegroups rscg ON rsc.radioservicecodeid = rscg.radioservicecodeid WHERE rscg.radioservicegroupid IN (select val from dbo.fnParseArray(@RadioServiceGroup,',')) OR @RadioServiceGroup IS NULL ORDER BY rsc.RadioServiceCode,rsc.RadioServiceCodeId,rsc.RadioService END </code></pre>
[ { "answer_id": 265637, "author": "Joel Coehoorn", "author_id": 3043, "author_profile": "https://Stackoverflow.com/users/3043", "pm_score": 6, "selected": false, "text": "DISTINCT GROUP BY DISTINCT GROUP BY SELECT DISTINCT col1 FROM [table] WHERE col2 > 2 ORDER BY col1, col2\n col2 order by select distinct SELECT rsc.RadioServiceCodeId,\n rsc.RadioServiceCode + ' - ' + rsc.RadioService as RadioService\nFROM sbi_l_radioservicecodes rsc\nINNER JOIN sbi_l_radioservicecodegroups rscg \n ON rsc.radioservicecodeid = rscg.radioservicecodeid\nWHERE rscg.radioservicegroupid IN \n (SELECT val FROM dbo.fnParseArray(@RadioServiceGroup,','))\n OR @RadioServiceGroup IS NULL \nGROUP BY rsc.RadioServiceCode,rsc.RadioServiceCodeId,rsc.RadioService\nORDER BY rsc.RadioServiceCode,rsc.RadioServiceCodeId,rsc.RadioService\n" }, { "answer_id": 265641, "author": "Chris Van Opstal", "author_id": 7264, "author_profile": "https://Stackoverflow.com/users/7264", "pm_score": 7, "selected": true, "text": "ORDER BY 1, 2\n ORDER BY rsc.RadioServiceCodeId, rsc.RadioServiceCode + ' - ' + rsc.RadioService\n" }, { "answer_id": 11292320, "author": "rio", "author_id": 313881, "author_profile": "https://Stackoverflow.com/users/313881", "pm_score": 2, "selected": false, "text": "--this works \n\n SELECT DISTINCT (c.FirstName + ' ' + c.LastName) as FullName \n from SalesLT.Customer c \n order by FullName\n\n--this works too\n\n SELECT DISTINCT (c.FirstName + ' ' + c.LastName) \n from SalesLT.Customer c \n order by 1\n\n-- this doesn't \n\n SELECT DISTINCT (c.FirstName + ' ' + c.LastName) as FullName \n from SalesLT.Customer c \n order by c.FirstName, c.LastName\n\n-- the problem the DISTINCT needs an order on the new concatenated column, here I order on the singular column\n-- this works\n\n SELECT DISTINCT (c.FirstName + ' ' + c.LastName) \n as FullName, CustomerID \n from SalesLT.Customer c \n\norder by 1, CustomerID\n\n-- this doesn't\n\n SELECT DISTINCT (c.FirstName + ' ' + c.LastName) as FullName \n from SalesLT.Customer c \n order by 1, CustomerID\n" }, { "answer_id": 33627742, "author": "HenryS", "author_id": 4428815, "author_profile": "https://Stackoverflow.com/users/4428815", "pm_score": -1, "selected": false, "text": "SELECT DISTINCT TEST.* FROM (\n SELECT rsc.RadioServiceCodeId,\n rsc.RadioServiceCode + ' - ' + rsc.RadioService as RadioService\n FROM sbi_l_radioservicecodes rsc\n INNER JOIN sbi_l_radioservicecodegroups rscg ON rsc.radioservicecodeid = rscg.radioservicecodeid\n WHERE rscg.radioservicegroupid IN \n (select val from dbo.fnParseArray(@RadioServiceGroup,','))\n OR @RadioServiceGroup IS NULL \n ORDER BY rsc.RadioServiceCode,rsc.RadioServiceCodeId,rsc.RadioService\n) as TEST\n" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265628", "https://Stackoverflow.com", "https://Stackoverflow.com/users/33690/" ]
265,639
<p>I've got a text file that contains several 'records' inside of it. Each record contains a name and a collection of numbers as data. </p> <p>I'm trying to build a class that will read through the file, present only the names of all the records, and then allow the user to select which record data he/she wants. </p> <p>The first time I go through the file, I only read header names, but I can keep track of the 'position' in the file where the header is. I need random access to the text file to seek to the beginning of each record after a user asks for it.</p> <p>I have to do it this way because the file is too large to be read in completely in memory (1GB+) with the other memory demands of the application.</p> <p>I've tried using the .NET StreamReader class to accomplish this (which provides very easy to use 'ReadLine' functionality, but there is no way to capture the true position of the file (the position in the BaseStream property is skewed due to the buffer the class uses).</p> <p>Is there no easy way to do this in .NET? </p>
[ { "answer_id": 267056, "author": "Corbin March", "author_id": 7625, "author_profile": "https://Stackoverflow.com/users/7625", "pm_score": 3, "selected": false, "text": "using (BinaryWriter writer = \n new BinaryWriter(File.Open(\"data.txt\", FileMode.Create)))\n{\n writer.Write(\"one,1,1,1,1\");\n writer.Write(\"two,2,2,2,2\");\n writer.Write(\"three,3,3,3,3\");\n}\n using (BinaryReader reader = new BinaryReader(File.OpenRead(\"data.txt\")))\n{\n string line = null;\n long position = reader.BaseStream.Position;\n while (reader.PeekChar() > -1)\n {\n line = reader.ReadString();\n\n //parse the name out of the line here...\n\n Console.WriteLine(\"{0},{1}\", position, line);\n position = reader.BaseStream.Position;\n }\n}\n" }, { "answer_id": 921524, "author": "Jimmy", "author_id": 68936, "author_profile": "https://Stackoverflow.com/users/68936", "pm_score": 4, "selected": false, "text": "public class PositionableStreamReader : StreamReader\n{\n public PositionableStreamReader(string path)\n :base(path)\n {}\n\n private int myLineEndingCharacterLength = Environment.NewLine.Length;\n public int LineEndingCharacterLength\n {\n get { return myLineEndingCharacterLength; }\n set { myLineEndingCharacterLength = value; }\n }\n\n public override string ReadLine()\n {\n string line = base.ReadLine();\n if (null != line)\n myStreamPosition += line.Length + myLineEndingCharacterLength;\n return line;\n }\n\n private long myStreamPosition = 0;\n public long Position\n {\n get { return myStreamPosition; }\n set\n {\n myStreamPosition = value;\n this.BaseStream.Position = value;\n this.DiscardBufferedData();\n }\n }\n}\n PositionableStreamReader sr = new PositionableStreamReader(\"somepath.txt\");\n\n// read some lines\nwhile (something)\n sr.ReadLine();\n\n// bookmark the current position\nlong streamPosition = sr.Position;\n\n// read some lines\nwhile (something)\n sr.ReadLine();\n\n// go back to the bookmarked position\nsr.Position = streamPosition;\n\n// read some lines\nwhile (something)\n sr.ReadLine();\n" }, { "answer_id": 72898255, "author": "Theodore Tsirpanis", "author_id": 4964734, "author_profile": "https://Stackoverflow.com/users/4964734", "pm_score": 0, "selected": false, "text": "System.IO.RandomAccess Microsoft.Win32.SafeHandles.SafeFileHandle System.IO.File.OpenHandle" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265639", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
265,644
<p>What is the best way to build a dynamic <em>Threaded</em> ASP.net radio button list? I am not that familiar with <code>RadioButtonLists</code> and it is my understanding that ASP.net doesn't like the application of individual styling of <code>ListItems</code>.</p>
[ { "answer_id": 265668, "author": "Tor Haugen", "author_id": 32050, "author_profile": "https://Stackoverflow.com/users/32050", "pm_score": 1, "selected": false, "text": "RadioButtonList ReapeatDirection=\"Horizontal\"" } ]
2008/11/05
[ "https://Stackoverflow.com/questions/265644", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3111/" ]