qid
int64
4
22.2M
question
stringlengths
18
48.3k
answers
list
date
stringlengths
10
10
metadata
list
22,431
<p>I am looking for information on handling search in different ORMs.</p> <p>Currently I am redeveloping some old application in PHP and one of requirements is: make everything or almost everything searchable, so user just types "punkrock live" and the app finds videos clips, music tracks, reviews, upcoming events or even user comments labeled that way.</p> <p>In environment where everything is searchable ORM need to support this feature in two ways:</p> <ul> <li>providing some indexing API on "O" side of ORM</li> <li>providing means for bulk database retrieval on "R" side</li> </ul> <p>Ideal solution would return ready made objects based on searched string. Do you know any good end-to-end solutions that does the job, not necessarily in PHP? If you dealt with similar problem it would be nice to listen what your experience is. Something more than <em>Use Lucene</em> or <em>semantic web is the way</em> oneliners, tho ;-)*</p>
[ { "answer_id": 302878, "author": "lo_fye", "author_id": 3407, "author_profile": "https://Stackoverflow.com/users/3407", "pm_score": 1, "selected": false, "text": "public function save(PropelPDO $con = null)\n{\n if($this->getIsSearchable())\n {\n // update your search i...
2008/08/22
[ "https://Stackoverflow.com/questions/22431", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2169/" ]
22,444
<p>I have this gigantic ugly string:</p> <pre class="lang-none prettyprint-override"><code>J0000000: Transaction A0001401 started on 8/22/2008 9:49:29 AM J0000010: Project name: E:\foo.pf J0000011: Job name: MBiek Direct Mail Test J0000020: Document 1 - Completed successfully </code></pre> <p>I'm trying to extract pieces from it using regex. In this case, I want to grab everything after <code>Project Name</code> up to the part where it says <code>J0000011:</code> (the 11 is going to be a different number every time).</p> <p>Here's the regex I've been playing with:</p> <pre class="lang-none prettyprint-override"><code>Project name:\s+(.*)\s+J[0-9]{7}: </code></pre> <p>The problem is that it doesn't stop until it hits the <strong>J0000020:</strong> at the end.</p> <p>How do I make the regex stop at the first occurrence of <code>J[0-9]{7}</code>?</p>
[ { "answer_id": 22449, "author": "jj33", "author_id": 430, "author_profile": "https://Stackoverflow.com/users/430", "pm_score": 8, "selected": true, "text": ".*" }, { "answer_id": 22457, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackove...
2008/08/22
[ "https://Stackoverflow.com/questions/22444", "https://Stackoverflow.com", "https://Stackoverflow.com/users/305/" ]
22,459
<p>I'm getting some strange, intermittent, data aborts (&lt; 5% of the time) in some of my code, when calling <code>memset()</code>. The problem is that is usually doesn't happen unless the code is running for a couple days, so it's hard to catch it in the act.</p> <p>I'm using the following code:</p> <pre><code>char *msg = (char*)malloc(sizeof(char)*2048); char *temp = (char*)malloc(sizeof(char)*1024); memset(msg, 0, 2048); memset(temp, 0, 1024); char *tempstr = (char*)malloc(sizeof(char)*128); sprintf(temp, "%s %s/%s %s%s", EZMPPOST, EZMPTAG, EZMPVER, TYPETXT, EOL); strcat(msg, temp); //Add Data memset(tempstr, '\0', 128); wcstombs(tempstr, gdevID, wcslen(gdevID)); sprintf(temp, "%s: %s%s", "DeviceID", tempstr, EOL); strcat(msg, temp); </code></pre> <p>As you can see, I'm not trying to use memset with a size larger that what's originally allocated with <code>malloc()</code></p> <p>Anyone see what might be wrong with this?</p>
[ { "answer_id": 22473, "author": "Joel Spolsky", "author_id": 4, "author_profile": "https://Stackoverflow.com/users/4", "pm_score": 5, "selected": true, "text": "malloc" }, { "answer_id": 22486, "author": "FreeMemory", "author_id": 2132, "author_profile": "https://Stac...
2008/08/22
[ "https://Stackoverflow.com/questions/22459", "https://Stackoverflow.com", "https://Stackoverflow.com/users/194/" ]
22,474
<p>How do I select all records that contain "LCS" within the title column in sql.</p>
[ { "answer_id": 22476, "author": "Owen", "author_id": 2109, "author_profile": "https://Stackoverflow.com/users/2109", "pm_score": 3, "selected": true, "text": "SELECT * FROM TABLE WHERE TABLE.TITLE LIKE '%LCS%';\n" }, { "answer_id": 22489, "author": "SQLMenace", "author_id...
2008/08/22
[ "https://Stackoverflow.com/questions/22474", "https://Stackoverflow.com", "https://Stackoverflow.com/users/453046/" ]
22,500
<p>The <a href="http://en.wikipedia.org/wiki/ANSI_C" rel="noreferrer">Wikipedia article on ANSI C</a> says:</p> <blockquote> <p>One of the aims of the ANSI C standardization process was to produce a superset of K&amp;R C (the first published standard), incorporating many of the unofficial features subsequently introduced. However, the standards committee also included several new features, such as function prototypes (borrowed from the C++ programming language), and a more capable preprocessor. The syntax for parameter declarations was also changed to reflect the C++ style.</p> </blockquote> <p>That makes me think that there are differences. However, I didn't see a comparison between K&amp;R C and ANSI C. Is there such a document? If not, what are the major differences?</p> <p>EDIT: I believe the K&amp;R book says "ANSI C" on the cover. At least I believe the version that I have at home does. So perhaps there isn't a difference anymore?</p>
[ { "answer_id": 22516, "author": "FreeMemory", "author_id": 2132, "author_profile": "https://Stackoverflow.com/users/2132", "pm_score": 4, "selected": false, "text": "int f( p, q, r ) \nint p, float q, double r; \n{ \n // Code goes here \n}\n" }, { "answer_id": 55632, "...
2008/08/22
[ "https://Stackoverflow.com/questions/22500", "https://Stackoverflow.com", "https://Stackoverflow.com/users/572/" ]
22,503
<p>I have a form view, in the edit template I have two drop downs. Drop down 1 is explicitly set with a list of allowed values. It is also set to autopostback. Drop down 2 is databound to an objectdatasource, this objectdatasource uses the first dropdown as one of it's parameters. (The idea is that drop down 1 limits what is shown in drop down 2)</p> <p>On the first view of the edit template for an item it works fine. But if drop down 1 has a different item selected it post back and generates an error </p> <blockquote> <p>Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.</p> </blockquote> <p>Here is the drop down list #2:</p> <pre><code>&lt;asp:DropDownList ID="ProjectList" runat="server" SelectedValue='&lt;%# Bind("ConnectToProject_ID","{0:D}") %&gt;' DataSourceID="MasterProjectsDataSource2" DataTextField="Name" DataValueField="ID" AppendDataBoundItems="true"&gt; &lt;asp:ListItem Value="0" Text="{No Master Project}" Selected="True" /&gt; &lt;/asp:DropDownList&gt; </code></pre> <p>And here is the MasterProjectDataSource2:</p> <pre><code>&lt;asp:ObjectDataSource ID="MasterProjectsDataSource2" runat="server" SelectMethod="GetMasterProjectList" TypeName="WebWorxData.Project" &gt; &lt;SelectParameters&gt; &lt;asp:ControlParameter ControlID="RPMTypeList" Name="RPMType_ID" PropertyName="SelectedValue" Type="Int32" /&gt; &lt;/SelectParameters&gt; &lt;/asp:ObjectDataSource&gt; </code></pre> <p>Any help on how to get this to work would be greatly appriciated.</p>
[ { "answer_id": 183587, "author": "craigmoliver", "author_id": 12252, "author_profile": "https://Stackoverflow.com/users/12252", "pm_score": 2, "selected": false, "text": "FormView fv = (FormView)sender;\nDropDownList ddl = (DropDownList)fv.FindControl(\"ProjectList\");\nddl.SelectedValue...
2008/08/22
[ "https://Stackoverflow.com/questions/22503", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2496/" ]
22,509
<p>I have an ASP.NET webforms application (3.5 SP1) that I'm working on, and attempting to enable gzip fpr HTML and CSS that comes down the pipe. I'm using <a href="http://www.stardeveloper.com/articles/display.html?article=2007110401&amp;page=1" rel="nofollow noreferrer">this implementation</a> (and tried a few others that hook into Application_BeginRequest), and it seems to be corrupting the external CSS file that the pages use, but intermittently...suddenly all styles will disappear on a page refresh, stay that way for awhile, and then suddenly start working again.</p> <p>Both IE7 and FF3 exhibit this behavior. When viewing the CSS using the web developer toolbar, it returns jibberish. The cache-control header is coming through as "private," but I don't know enough to figure out if that's a contributing factor or not.</p> <p>Also, this is running on the ASP.NET Development Server. Maybe it'd be fine with IIS, but I'm developing on XP and it'd be IIS5.</p>
[ { "answer_id": 22585, "author": "travis", "author_id": 1414, "author_profile": "https://Stackoverflow.com/users/1414", "pm_score": 4, "selected": true, "text": "%systemroot%\\system32\\inetsrv\\MetaBase.xml" } ]
2008/08/22
[ "https://Stackoverflow.com/questions/22509", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1212/" ]
22,519
<p>I have a folder in my web server used for the users to upload photos using an ASP page.</p> <p>Is it safe enough to give IUSR write permissions to the folder? Must I secure something else? I am afraid of hackers bypassing the ASP page and uploading content directly to the folder.</p> <p>I'm using ASP classic and IIS6 on Windows 2003 Server. The upload is through HTTP, not FTP.</p> <p>Edit: Changing the question for clarity and changing my answers as comments.</p>
[ { "answer_id": 24401, "author": "chrisofspades", "author_id": 2614, "author_profile": "https://Stackoverflow.com/users/2614", "pm_score": 0, "selected": false, "text": "set fs=Server.CreateObject(\"Scripting.FileSystemObject\")\nset f=fs.GetFile(\"upload.jpg\")\n'image mime types or imag...
2008/08/22
[ "https://Stackoverflow.com/questions/22519", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2385/" ]
22,524
<p>Example: You have a shortcut <code>s</code> to <code>SomeProgram</code> in the current directory.</p> <p>In <code>cmd.exe</code>, you can type <code>s</code> and it will launch the program.</p> <p>In PowerShell, typing <code>s</code> gives:</p> <blockquote> <p><code>The term 's' is not recognized as a cmdlet, function, operable program, or script file. Verify the term and try again.</code></p> </blockquote> <p>If you type <code>s.lnk</code> or <code>SomeProgram</code>, it runs the program just fine.</p> <p>How can I configure PowerShell to execute shortcuts just like programs?</p>
[ { "answer_id": 23687, "author": "slipsec", "author_id": 1635, "author_profile": "https://Stackoverflow.com/users/1635", "pm_score": 2, "selected": false, "text": "& \"C:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727\\aspnet_regiis.exe\" -r | out-null\n" }, { "answer_id": 23694, ...
2008/08/22
[ "https://Stackoverflow.com/questions/22524", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2495/" ]
22,528
<p>I would like to have a reference for the pros and cons of using include <strong>files vs objects(classes)</strong> when developing PHP applications.</p> <p>I know I would benefit from having one place to go for this answer...I have a few opinions of my own but I look forward to hearing others.</p> <p><strong>A Simple Example:</strong></p> <p>Certain pages on my site are only accessible to logged in users. I have two options for implementation (there are others but let's limit it to these two)</p> <ol> <li><p><em>Create an authenticate.php file and include it on every page. It holds the logic for authentication.</em></p></li> <li><p><em>Create a user object, which has an authenticate function, reference the object for authentication on every page.</em> </p></li> </ol> <p><strong>Edit</strong> I'd like to see some way weigh the benefits of one over the other. My current (and weak reasons) follow:</p> <p>Includes - Sometimes a function is just easier/shorter/faster to call Objects - Grouping of functionality and properties leads for longer term maintenance.</p> <p><strong>Includes</strong> - Less code to write (no constructor, no class syntax) call me lazy but this is true.</p> <p><strong>Objects</strong> - Force formality and a single approach to functions and creation. </p> <p><strong>Includes</strong> - Easier for a novice to deal with Objects - Harder for novices, but frowned upon by professionals.</p> <p>I look at these factors at the start of a project to decide if I want to do includes or objects. Those are a few pros and cons off the top of my head.</p>
[ { "answer_id": 22551, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 1, "selected": false, "text": "include" }, { "answer_id": 22578, "author": "Brian Warshaw", "author_id": 1344, "author_profile": ...
2008/08/22
[ "https://Stackoverflow.com/questions/22528", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2490/" ]
22,552
<p>I have a regex that is going to end up being a bit long and it'd make it much easier to read to have it across multiple lines.</p> <p>I tried this but it just barfs.</p> <pre><code>preg_match( '^J[0-9]{7}:\s+ (.*?) #Extract the Transaction Start Date msg \s+J[0-9]{7}:\s+Project\sname:\s+ (.*?) #Extract the Project Name \s+J[0-9]{7}:\s+Job\sname:\s+ (.*?) #Extract the Job Name \s+J[0-9]{7}:\s+', $this-&gt;getResultVar('FullMessage'), $atmp ); </code></pre> <p>Is there are way to pass a regex in the above form to preg_match?</p>
[ { "answer_id": 22572, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 4, "selected": true, "text": "preg_match(\"/\n test\n/x\", $foo, $bar);\n" }, { "answer_id": 22574, "author": "Mark Biek", "author...
2008/08/22
[ "https://Stackoverflow.com/questions/22552", "https://Stackoverflow.com", "https://Stackoverflow.com/users/305/" ]
22,566
<p>How do I get Perl to read the contents of a given directory into an array?</p> <p><a href="https://en.wikipedia.org/wiki/Grave_accent#Use_in_programming" rel="noreferrer">Backticks</a> can do it, but is there some method using 'scandir' or a similar term?</p>
[ { "answer_id": 22573, "author": "jj33", "author_id": 430, "author_profile": "https://Stackoverflow.com/users/430", "pm_score": 7, "selected": true, "text": "opendir(D, \"/path/to/directory\") || die \"Can't open directory: $!\\n\";\nwhile (my $f = readdir(D)) {\n print \"\\$f = $f\\n\...
2008/08/22
[ "https://Stackoverflow.com/questions/22566", "https://Stackoverflow.com", "https://Stackoverflow.com/users/277/" ]
22,570
<p>Here is the issue I am having: I have a large query that needs to compare datetimes in the where clause to see if two dates are on the same day. My current solution, which sucks, is to send the datetimes into a UDF to convert them to midnight of the same day, and then check those dates for equality. When it comes to the query plan, this is a disaster, as are almost all UDFs in joins or where clauses. This is one of the only places in my application that I haven't been able to root out the functions and give the query optimizer something it can actually use to locate the best index.</p> <p>In this case, merging the function code back into the query seems impractical.</p> <p>I think I am missing something simple here.</p> <p>Here's the function for reference.</p> <pre><code>if not exists (select * from dbo.sysobjects where id = object_id(N'dbo.f_MakeDate') and type in (N'FN', N'IF', N'TF', N'FS', N'FT')) exec('create function dbo.f_MakeDate() returns int as begin declare @retval int return @retval end') go alter function dbo.f_MakeDate ( @Day datetime, @Hour int, @Minute int ) returns datetime as /* Creates a datetime using the year-month-day portion of @Day, and the @Hour and @Minute provided */ begin declare @retval datetime set @retval = cast( cast(datepart(m, @Day) as varchar(2)) + '/' + cast(datepart(d, @Day) as varchar(2)) + '/' + cast(datepart(yyyy, @Day) as varchar(4)) + ' ' + cast(@Hour as varchar(2)) + ':' + cast(@Minute as varchar(2)) as datetime) return @retval end go </code></pre> <p>To complicate matters, I am joining on time zone tables to check the date against the local time, which could be different for every row:</p> <pre><code>where dbo.f_MakeDate(dateadd(hh, tz.Offset + case when ds.LocalTimeZone is not null then 1 else 0 end, t.TheDateINeedToCheck), 0, 0) = @activityDateMidnight </code></pre> <p>[Edit]</p> <p>I'm incorporating @Todd's suggestion:</p> <pre><code>where datediff(day, dateadd(hh, tz.Offset + case when ds.LocalTimeZone is not null then 1 else 0 end, t.TheDateINeedToCheck), @ActivityDate) = 0 </code></pre> <p>My misconception about how datediff works (the same day of year in consecutive years yields 366, not 0 as I expected) caused me to waste a lot of effort.</p> <p>But the query plan didn't change. I think I need to go back to the drawing board with the whole thing.</p>
[ { "answer_id": 22579, "author": "jason saldo", "author_id": 1293, "author_profile": "https://Stackoverflow.com/users/1293", "pm_score": 3, "selected": false, "text": "where\nyear(date1) = year(date2)\nand month(date1) = month(date2)\nand day(date1) = day(date2)\n" }, { "answer_id...
2008/08/22
[ "https://Stackoverflow.com/questions/22570", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1219/" ]
22,617
<p>I need to find out how to format numbers as strings. My code is here:</p> <pre><code>return str(hours)+":"+str(minutes)+":"+str(seconds)+" "+ampm </code></pre> <p>Hours and minutes are integers, and seconds is a float. the str() function will convert all of these numbers to the tenths (0.1) place. So instead of my string outputting "5:30:59.07 pm", it would display something like "5.0:30.0:59.1 pm".</p> <p>Bottom line, what library / function do I need to do this for me?</p>
[ { "answer_id": 22624, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 8, "selected": true, "text": "hours, minutes, seconds = 6, 56, 33\nf'{hours:02}:{minutes:02}:{seconds:02} {\"pm\" if hours > 12 else \"am\"}'\n" },...
2008/08/22
[ "https://Stackoverflow.com/questions/22617", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2504/" ]
22,623
<p>What are the best practices to consider when catching exceptions and re-throwing them? I want to make sure that the <code>Exception</code> object's <code>InnerException</code> and stack trace are preserved. Is there a difference between the following code blocks in the way they handle this?</p> <pre><code>try { //some code } catch (Exception ex) { throw ex; } </code></pre> <p>Vs:</p> <pre><code>try { //some code } catch { throw; } </code></pre>
[ { "answer_id": 22628, "author": "Darren Kopp", "author_id": 77, "author_profile": "https://Stackoverflow.com/users/77", "pm_score": 9, "selected": true, "text": "throw;" }, { "answer_id": 22639, "author": "Forgotten Semicolon", "author_id": 1960, "author_profile": "ht...
2008/08/22
[ "https://Stackoverflow.com/questions/22623", "https://Stackoverflow.com", "https://Stackoverflow.com/users/357/" ]
22,676
<p>I have a small utility that I use to download an MP3 file from a website on a schedule and then builds/updates a podcast XML file which I've added to iTunes.</p> <p>The text processing that creates/updates the XML file is written in Python. However, I use wget inside a Windows <code>.bat</code> file to download the actual MP3 file. I would prefer to have the entire utility written in Python.</p> <p>I struggled to find a way to actually download the file in Python, thus why I resorted to using <code>wget</code>.</p> <p>So, how do I download the file using Python?</p>
[ { "answer_id": 22682, "author": "Corey", "author_id": 1595, "author_profile": "https://Stackoverflow.com/users/1595", "pm_score": 10, "selected": true, "text": "urllib.request.urlopen()" }, { "answer_id": 22721, "author": "Grant", "author_id": 30, "author_profile": "h...
2008/08/22
[ "https://Stackoverflow.com/questions/22676", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2109/" ]
22,696
<p>OK, here is my problem, without being too specific for reasons of being fired for putting company practices on the internet.</p> <p>There are spreadsheets made. These are uploaded to the database. I need to filter out duplicates from uploading. The only way to do this is by making sure that for each and every entry that two fields aren't the same as an entry already in the database. As just becasue one field is the same does not mean its a duplicate. There are two specific fields lets call them FLDA and FLDB that both must match up to an entry in the database already. I can filter by one field already. I'm thinking this has to be a subquery but I'm not sure how to apply it. This is hard to decribe. Just ask if your not sure what I mean.</p>
[ { "answer_id": 24673, "author": "Fionnuala", "author_id": 2548, "author_profile": "https://Stackoverflow.com/users/2548", "pm_score": 1, "selected": false, "text": "INSERT INTO ToUpdate ( Field1, Field2 )\nSELECT e.H1, e.H2\nFROM (SELECT * FROM [Sheet1$] IN '' [Excel 8.0;HDR=YES;IMEX=1;d...
2008/08/22
[ "https://Stackoverflow.com/questions/22696", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
22,697
<p>What's the best framework for creating mock objects in Java? Why? What are the pros and cons of each framework?</p>
[ { "answer_id": 23048, "author": "Brian Laframboise", "author_id": 1557, "author_profile": "https://Stackoverflow.com/users/1557", "pm_score": 9, "selected": true, "text": "import static org.mockito.Mockito.*;\n\nList mockedList = mock(List.class);\nmockedList.clear();\nverify(mockedList)...
2008/08/22
[ "https://Stackoverflow.com/questions/22697", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2030/" ]
22,708
<p>How would you determine the column name (e.g. "AQ" or "BH") of the nth column in Excel?</p> <p>Edit: A language-agnostic algorithm to determine this is the main goal here.</p>
[ { "answer_id": 22715, "author": "Joseph Sturtevant", "author_id": 317, "author_profile": "https://Stackoverflow.com/users/317", "pm_score": 6, "selected": true, "text": "public static string Column(int column)\n{\n column--;\n if (column >= 0 && column < 26)\n return ((char)...
2008/08/22
[ "https://Stackoverflow.com/questions/22708", "https://Stackoverflow.com", "https://Stackoverflow.com/users/940/" ]
22,720
<p>I have a listening port on my server that I'm connecting to using a Java class and the <code>Socket</code> interface, i.e.</p> <pre><code>Socket mySocket = new Socket(host,port); </code></pre> <p>I then grab an <code>OutputStream</code>, decorate with a <code>PrintWriter</code> in autoflush mode and I'm laughing - except if the listening port closes. Then I get </p> <pre><code>tcp4 0 0 *.9999 *.* LISTEN tcp 0 0 127.0.0.1.45737 127.0.0.1.9999 CLOSE_WAIT </code></pre> <p>and I can't seem to detect the problem in the program - I've tried using the <code>isConnected()</code> method on the socket but it doesn't seem to know that the connection is closed.</p> <p>I want to be aware of the problem the next time I try and write to the Socket so that I can try and reconnect and report the issue.</p> <p>Any advice please?</p> <p>Thanks all</p>
[ { "answer_id": 22803, "author": "James A. Rosen", "author_id": 1190, "author_profile": "https://Stackoverflow.com/users/1190", "pm_score": 2, "selected": true, "text": "isOutputShutdown()" } ]
2008/08/22
[ "https://Stackoverflow.com/questions/22720", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2362/" ]
22,732
<p>I am trying to do some string concatenation/formatting, but it's putting all the parameters into the first placeholder.</p> <p><strong>Code</strong></p> <pre><code>function CreateAppPoolScript([string]$AppPoolName, [string]$AppPoolUser, [string]$AppPoolPass) { # Command to create an IIS application pool $AppPoolScript = "cscript adsutil.vbs CREATE ""w3svc/AppPools/$AppPoolName"" IIsApplicationPool`n" $AppPoolScript += "cscript adsutil.vbs SET ""w3svc/AppPools/$AppPoolName/WamUserName"" ""$AppPoolUser""`n" $AppPoolScript += "cscript adsutil.vbs SET ""w3svc/AppPools/$AppPoolName/WamUserPass"" ""$AppPoolPass""`n" $AppPoolScript += "cscript adsutil.vbs SET ""w3svc/AppPools/$AppPoolName/AppPoolIdentityType"" 3" return $AppPoolScript } $s = CreateAppPoolScript("name", "user", "pass") write-host $s </code></pre> <p><strong>Output</strong></p> <pre class="lang-none prettyprint-override"><code>cscript adsutil.vbs CREATE "w3svc/AppPools/name user pass" IIsApplicationPool cscript adsutil.vbs SET "w3svc/AppPools/name user pass/WamUserName" "" cscript adsutil.vbs SET "w3svc/AppPools/name user pass/WamUserPass" "" cscript adsutil.vbs SET "w3svc/AppPools/name user pass/AppPoolIdentityType" 3 </code></pre>
[ { "answer_id": 22770, "author": "Paul Roub", "author_id": 1324, "author_profile": "https://Stackoverflow.com/users/1324", "pm_score": 7, "selected": true, "text": "$s = CreateAppPoolScript \"name\" \"user\" \"pass\"\n" }, { "answer_id": 40890, "author": "Emperor XLII", "a...
2008/08/22
[ "https://Stackoverflow.com/questions/22732", "https://Stackoverflow.com", "https://Stackoverflow.com/users/636/" ]
22,764
<p>In Ruby 1.8 and earlier,</p> <pre><code>Foo </code></pre> <p>is a constant (a Class, a Module, or another constant). Whereas</p> <pre><code>foo </code></pre> <p>is a variable. The key difference is as follows:</p> <pre><code>module Foo bar = 7 BAZ = 8 end Foo::BAZ # =&gt; 8 Foo::bar # NoMethodError: undefined method 'bar' for Foo:Module </code></pre> <p>That's all well and good, but Ruby 1.9 <a href="http://pragdave.blogs.pragprog.com/pragdave/2008/04/fun-with-ruby-1.html" rel="nofollow noreferrer">allows UTF-8 source code</a>. So is <code>℃</code> "uppercase" or "lowecase" as far as this is concerned? What about <code>⊂</code> (strict subset) or <code>Ɖfoo</code>?</p> <p>Is there a general rule?</p> <p><em>Later:</em></p> <p>Ruby-core is already considering some of the mathematical operators. For example</p> <pre><code>module Kernel def √(num) ... end def ∑(*args) ... end end </code></pre> <p>would allow</p> <pre><code>x = √2 y = ∑(1, 45, ...) </code></pre> <p>I would love to see</p> <pre><code>my_proc = λ { |...| ... } x ∈ my_enumerable # same as my_enumerable.include?(x) my_infinite_range = (1..∞) return 'foo' if x ≠ y 2.21 ≈ 2.2 </code></pre>
[ { "answer_id": 25592, "author": "Orion Edwards", "author_id": 234, "author_profile": "https://Stackoverflow.com/users/234", "pm_score": 2, "selected": false, "text": "String#upcase" }, { "answer_id": 25610, "author": "Julio César", "author_id": 2148, "author_profile":...
2008/08/22
[ "https://Stackoverflow.com/questions/22764", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1190/" ]
22,801
<p>It's about PHP but I've no doubt many of the same comments will apply to other languages.</p> <p>Simply put, what are the differences in the different types of loop for PHP? Is one faster/better than the others or should I simply put in the most readable loop?</p> <pre><code>for ($i = 0; $i &lt; 10; $i++) { # code... } foreach ($array as $index =&gt; $value) { # code... } do { # code... } while ($flag == false); </code></pre>
[ { "answer_id": 22810, "author": "wvdschel", "author_id": 2018, "author_profile": "https://Stackoverflow.com/users/2018", "pm_score": 0, "selected": false, "text": "for" }, { "answer_id": 22811, "author": "mercutio", "author_id": 1951, "author_profile": "https://Stacko...
2008/08/22
[ "https://Stackoverflow.com/questions/22801", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1384652/" ]
22,807
<p>Wondering if there is a better why in the WHERE clause of choosing records when you need to look at effective start and end dates?</p> <p>Currently this how I've done it in the past on MS SQL Server. Just worried about the date and not the time. I'm using SQL Server 2005.</p> <pre><code>AND Convert(datetime, Convert(char(10), ep.EffectiveStartDate, 101)) &lt;= Convert(datetime, Convert(char(10), GetDate(), 101)) AND Convert(datetime, Convert(char(10), ep.EffectiveEndDate, 101)) &gt;= Convert(datetime, Convert(char(10), GetDate(), 101)) </code></pre>
[ { "answer_id": 22809, "author": "Darren Kopp", "author_id": 77, "author_profile": "https://Stackoverflow.com/users/77", "pm_score": -1, "selected": false, "text": "ep.EffectiveStartDate BETWEEN @date1 AND @date2\n" }, { "answer_id": 22824, "author": "AlexCuse", "author_id...
2008/08/22
[ "https://Stackoverflow.com/questions/22807", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2526/" ]
22,814
<p>I need to see the contents of the viewstate of an asp.net page. I looked for a viewstate decoder, found <a href="http://www.testingreflections.com/node/view/3424" rel="noreferrer">Fridz Onion's ViewState Decoder</a> but it asks for the url of a page to get its viewstate. Since my viewstate is formed after a postback and comes as a result of an operation in an update panel, I cannot provide a url. I need to copy &amp; paste the viewstate string and see what's inside. Is there a tool or a website exist that can help viewing the contents of viewstate?</p>
[ { "answer_id": 10605023, "author": "Sameer Alibhai", "author_id": 2343, "author_profile": "https://Stackoverflow.com/users/2343", "pm_score": 4, "selected": false, "text": "using System;\nusing System.Collections;\nusing System.Text;\nusing System.IO;\nusing System.Web.UI;\n\n\nnamespace...
2008/08/22
[ "https://Stackoverflow.com/questions/22814", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31505/" ]
22,816
<p>I know the following libraries for drawing charts in an SWT/Eclipse RCP application:</p> <ul> <li><a href="http://www.eclipse.org/articles/article.php?file=Article-BIRTChartEngine/index.html" rel="noreferrer">Eclipse BIRT Chart Engine</a> (Links to an article on how to use it)</li> <li><a href="http://www.jfree.org/jfreechart/" rel="noreferrer">JFreeChart</a></li> </ul> <p>Which other libraries are there for drawing pretty charts with SWT? Or charts in Java generally? After all, you can always display an image...</p>
[ { "answer_id": 43112, "author": "Ryan P", "author_id": 1539, "author_profile": "https://Stackoverflow.com/users/1539", "pm_score": 5, "selected": true, "text": "Composite comp = new Composite(parent, SWT.NONE | SWT.EMBEDDED);\nFrame frame = SWT_AWT.new_Frame(comp);\nJFreeChart chart = cr...
2008/08/22
[ "https://Stackoverflow.com/questions/22816", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1793/" ]
22,836
<p>In Perl, what is a good way to perform a replacement on a string using a regular expression and store the value in a different variable, without changing the original?</p> <p>I usually just copy the string to a new variable then bind it to the <code>s///</code> regex that does the replacement on the new string, but I was wondering if there is a better way to do this?</p> <pre><code>$newstring = $oldstring; $newstring =~ s/foo/bar/g; </code></pre>
[ { "answer_id": 22896, "author": "John Siracusa", "author_id": 164, "author_profile": "https://Stackoverflow.com/users/164", "pm_score": 9, "selected": true, "text": "(my $newstring = $oldstring) =~ s/foo/bar/g;\n" }, { "answer_id": 24090, "author": "Pat", "author_id": 238...
2008/08/22
[ "https://Stackoverflow.com/questions/22836", "https://Stackoverflow.com", "https://Stackoverflow.com/users/277/" ]
22,879
<p>I'm able to connect to and read an excel file no problem. But when importing data such as zipcodes that have leading zeros, how do you prevent excel from guessing the datatype and in the process stripping out leading zeros?</p>
[ { "answer_id": 22908, "author": "palehorse", "author_id": 312, "author_profile": "https://Stackoverflow.com/users/312", "pm_score": 4, "selected": true, "text": "Provider=Microsoft.ACE.OLEDB.12.0;\n Data Source=c:\\path\\to\\myfile.xlsx;\n Extended Properties=\\\"Excel 12.0 Xml;IME...
2008/08/22
[ "https://Stackoverflow.com/questions/22879", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1874/" ]
22,880
<p>Specifically this is regarding when using a client session cookie to identify a session on the server.</p> <p>Is the best answer to use SSL/HTTPS encryption for the entire web site, and you have the best guarantee that no man in the middle attacks will be able to sniff an existing client session cookie?</p> <p>And perhaps second best to use some sort of encryption on the session value itself that is stored in your session cookie?</p> <p>If a malicious user has physical access to a machine, they can still look at the filesystem to retrieve a valid session cookie and use that to hijack a session?</p>
[ { "answer_id": 6532807, "author": "Nima", "author_id": 822755, "author_profile": "https://Stackoverflow.com/users/822755", "pm_score": -1, "selected": false, "text": "$ip=$_SERVER['REMOTE_ADDER'];\n$_SESSEION['ip']=$ip;\n" }, { "answer_id": 19726572, "author": "Alexandru", ...
2008/08/22
[ "https://Stackoverflow.com/questions/22880", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1341/" ]
22,909
<p>I want to show HTML content inside Flash. Is there some way to do this? I am talking about full blown HTML (with JavaScript if possible).</p>
[ { "answer_id": 22921, "author": "Theo", "author_id": 1109, "author_profile": "https://Stackoverflow.com/users/1109", "pm_score": 1, "selected": false, "text": "htmlText" } ]
2008/08/22
[ "https://Stackoverflow.com/questions/22909", "https://Stackoverflow.com", "https://Stackoverflow.com/users/184/" ]
22,935
<p>Does anyone have a technique for generating SQL table create (and data insert) commands pragmatically from a CSV (or sheet in a .xls) file? </p> <p>I've got a third party database system which I'd like to populate with data from a csv file (or sheet in a xls file) but the importer supplied can't create the table structure automatically as it does the import. My csv file has lots of tables with lots of columns so I'd like to automate the table creation process as well as the data importing if possible but I'm unsure about how to go about generating the create statement...</p>
[ { "answer_id": 22948, "author": "SQLMenace", "author_id": 740, "author_profile": "https://Stackoverflow.com/users/740", "pm_score": 2, "selected": true, "text": "SELECT * INTO NewTablenNmeHere\nFROM OPENROWSET( 'Microsoft.Jet.OLEDB.4.0', \n'Excel 8.0;Database=C:\\testing.xls','SELECT * F...
2008/08/22
[ "https://Stackoverflow.com/questions/22935", "https://Stackoverflow.com", "https://Stackoverflow.com/users/39040/" ]
22,976
<p>I've got a JavaScript "object", built this way:</p> <pre><code>function foo() { this.length = 0; } foo.prototype.getLength = function() { return this.length; } ... </code></pre> <p>I know how to emulate namespaces with singleton JavaScript objects, but what is the best way to "namepace" an object such as that above that will intanced? </p> <p>I know that several JavaScript libraries have namepacing capabilities, but I'm using jQuery and would rather not add another library to the mix. I'd like to be able to provide my own, perhaps by exploiting jQuery, intrinsic namespacing scheme for the JS objects of mine that need to be instanced. </p> <p>Thanks rp</p>
[ { "answer_id": 22998, "author": "Nickolay", "author_id": 1026, "author_profile": "https://Stackoverflow.com/users/1026", "pm_score": 2, "selected": false, "text": "namespace.foo = function foo() {...}\nnamespace.foo.prototype.getLength = function() { ... }\n" }, { "answer_id": 23...
2008/08/22
[ "https://Stackoverflow.com/questions/22976", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2536/" ]
22,979
<p>I'm looking for a way to poll different servers and check that SQL server is up and running. I'm writing my code in C#. I don't particularly care about individual databases, just that SQL server is running and responsive.</p> <p>Any ideas?</p>
[ { "answer_id": 451160, "author": "Benjamin Autin", "author_id": 1440933, "author_profile": "https://Stackoverflow.com/users/1440933", "pm_score": 2, "selected": false, "text": "System.Data.Sql.SqlDataSourceEnumerator" } ]
2008/08/22
[ "https://Stackoverflow.com/questions/22979", "https://Stackoverflow.com", "https://Stackoverflow.com/users/178/" ]
22,988
<p>I have several "ASP:TextBox" controls on a form (about 20).<br> When the form loads, the text boxes are populated from a database.<br> The user can change the populated values, and when they submit the form, I take the values posted to the server and conditionally save them (determined by some business logic).<br> All but 1 of the text boxes work as intended.</p> <p>The odd box out, upon postback, does not contain the updated value that the user typed into the box.<br> When debugging the application, it is clear that <code>myTextBox.Text</code> reflects the old, pre-populated value, not the new, user-supplied value.<br> Every other box properly shows their respective user-supplied values.</p> <p>I did find a workaround.<br> My solution was to basically extract the text box's value out of the <code>Request.Form</code> object: <code>Request.Form[myTextBox.UniqueID]</code>, which does contain the user-supplied value.</p> <p>What could be going on, here?<br> As I mentioned, the other text boxes receive the user-supplied values just fine, and this particular problematic text box doesn't have any logic associated to it -- it just takes the value and saves it.<br> The main difference between this text box and the others is that this is a multi-line box (for inputting notes), which I believe is rendered as an HTML "textarea" tag instead of an "input" tag in ASP.NET.</p>
[ { "answer_id": 23058, "author": "Jon Erickson", "author_id": 1950, "author_profile": "https://Stackoverflow.com/users/1950", "pm_score": 3, "selected": false, "text": "protected void Page_Load(object sender, EventArgs e)\n{\n if (!Page.IsPostBack)\n {\n // populate text boxe...
2008/08/22
[ "https://Stackoverflow.com/questions/22988", "https://Stackoverflow.com", "https://Stackoverflow.com/users/418/" ]
23,027
<p>While setting up CruiseControl, I added a buildpublisher block to the publisher tasks:</p> <pre><code>&lt;buildpublisher&gt; &lt;sourceDir&gt;C:\MyBuild\&lt;/sourceDir&gt; &lt;publishDir&gt;C:\MyBuildPublished\&lt;/publishDir&gt; &lt;alwaysPublish&gt;false&lt;/alwaysPublish&gt; &lt;/buildpublisher&gt; </code></pre> <p>This works, but it copies the entire file contents of the build, I only want to copy the DLL's and .aspx pages, I don't need the source code to get published.</p> <p>Does anyone know of a way to filter this, or do I need to setup a task to run a RoboCopy script instead?</p>
[ { "answer_id": 32681, "author": "Mike", "author_id": 2848, "author_profile": "https://Stackoverflow.com/users/2848", "pm_score": 1, "selected": false, "text": "<MSBuild Projects=\"@(VSProjects)\"\n Properties=\"Configuration=$(Configuration)\">\n <Output TaskParameter=\"TargetOutputs\"...
2008/08/22
[ "https://Stackoverflow.com/questions/23027", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1965/" ]
23,083
<p>In the Windows applications I work on, we have a custom framework that sits directly above Win32 (don't ask). When we create a window, our normal practice is to put <code>this</code> in the window's user data area via <code>SetWindowLong(hwnd, GWL_USERDATA, this)</code>, which allows us to have an MFC-like callback or a tightly integrated <code>WndProc</code>, depending. The problem is that this will not work on 64-bit Windows, since LONG is only 32-bits wide. What's a better solution to this problem that works on both 32- and 64-bit systems?</p>
[ { "answer_id": 23101, "author": "Chris", "author_id": 2134, "author_profile": "https://Stackoverflow.com/users/2134", "pm_score": 6, "selected": true, "text": "LONG_PTR SetWindowLongPtr( \n HWND hWnd,\n int nIndex,\n LONG_PTR dwNewLong\n);\n" } ]
2008/08/22
[ "https://Stackoverflow.com/questions/23083", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2354/" ]
23,094
<p>What's the best way to handle a user going back to a page that had cached items in an asp.net app? Is there a good way to capture the back button (event?) and handle the cache that way?</p>
[ { "answer_id": 24334, "author": "travis", "author_id": 1414, "author_profile": "https://Stackoverflow.com/users/1414", "pm_score": 4, "selected": true, "text": "Response.Cache.SetExpires(DateTime.Now.AddSeconds(60));\nResponse.Cache.SetCacheability(HttpCacheability.Public);\nResponse.Cac...
2008/08/22
[ "https://Stackoverflow.com/questions/23094", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1874/" ]
23,102
<p>I'm pretty green still when it comes to web programming, I've spent most of my time on client applications. So I'm curious about the common exploits I should fear/test for in my site.</p>
[ { "answer_id": 23116, "author": "Rob Cooper", "author_id": 832, "author_profile": "https://Stackoverflow.com/users/832", "pm_score": 3, "selected": false, "text": "bool UserCredentialsOK(User user)\n{\n\n if (user.Name == \"modesty\")\n return false;\n else\n // perfo...
2008/08/22
[ "https://Stackoverflow.com/questions/23102", "https://Stackoverflow.com", "https://Stackoverflow.com/users/580/" ]
23,106
<p>What is the best method to parse multiple, discrete, custom XML documents with Java?</p>
[ { "answer_id": 23121, "author": "jcsalterego", "author_id": 1416, "author_profile": "https://Stackoverflow.com/users/1416", "pm_score": 2, "selected": false, "text": "org.xml.sax.XMLReader" }, { "answer_id": 5299265, "author": "Valdis", "author_id": 438990, "author_pr...
2008/08/22
[ "https://Stackoverflow.com/questions/23106", "https://Stackoverflow.com", "https://Stackoverflow.com/users/828/" ]
23,124
<p>As the title mentions, I have a timeout callback handler on an ajax call, and I want to be able to test that condition but nothing is coming to mind immediately on ways I can force my application to hit that state, any suggestions?</p>
[ { "answer_id": 23131, "author": "Andy", "author_id": 1993, "author_profile": "https://Stackoverflow.com/users/1993", "pm_score": 2, "selected": false, "text": "<?php\n sleep(10); //sleep for 10 seconds.\n print \"This script has finished.\";\n>\n" }, { "answer_id": 23227, ...
2008/08/22
[ "https://Stackoverflow.com/questions/23124", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2272/" ]
23,169
<p>When using Groovy <code>MarkupBuilder</code>, I have places where I need to output text into the document, or call a function which outputs text into the document. Currently, I'm using the undefined tag <em>"text"</em> to do the output. Is there a better way to write this code?</p> <pre><code>li { text("${type.getAlias()} blah blah ") function1(type.getXYZ()) if (type instanceof Class1) { text(" implements ") ft.getList().each { if (it == '') return text(it) if (!function2(type, it)) text(", ") } } } </code></pre>
[ { "answer_id": 23734, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "void text(n){\n builder.yield n\n}\n" }, { "answer_id": 81815, "author": "Hank Gay", "author_id": 4203, ...
2008/08/22
[ "https://Stackoverflow.com/questions/23169", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
23,175
<p>This is mostly geared toward desktop application developers. <br />How do I design a caching block which plays nicely with the GC? <br />How do I tell the GC that I have just done a cache sweep and it is time to do a GC? <br />How do I get an accurate measure of when it is time to do a cache sweep?</p> <p>Are there any prebuilt caching schemes which I could borrow some ideas from?</p>
[ { "answer_id": 23734, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "void text(n){\n builder.yield n\n}\n" }, { "answer_id": 81815, "author": "Hank Gay", "author_id": 4203, ...
2008/08/22
[ "https://Stackoverflow.com/questions/23175", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1490/" ]
23,178
<p>Is there a .NET variable that returns the "All Users" directory?</p>
[ { "answer_id": 23194, "author": "Kibbee", "author_id": 1862, "author_profile": "https://Stackoverflow.com/users/1862", "pm_score": 4, "selected": true, "text": "system.environment" }, { "answer_id": 23202, "author": "Peter Meyer", "author_id": 1875, "author_profile": ...
2008/08/22
[ "https://Stackoverflow.com/questions/23178", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1632/" ]
23,190
<p>I am working on a function to establish the entropy of a distribution. It uses a copula, if any are familiar with that. I need to sum up the values in the array based on which dimensions are &quot;cared about.&quot;</p> <p>Example: Consider the following example...</p> <pre> Dimension 0 (across) _ _ _ _ _ _ _ _ _ _ _ _ _ |_ 0 _|_ 0 _|_ 0 _|_ 2 _| Dimension 1 |_ 1 _|_ 0 _|_ 2 _|_ 0 _| (down) |_ 0 _|_ 3 _|_ 0 _|_ 6 _| |_ 0 _|_ 0 _|_ 0 _|_ 0 _| I "care about" dimension 0 only, and "don't care" about the rest (dim 1). Summing this array with the above specifications will "collapse" the "stacks" of dimension 1 down to a single 4 x 1 array: _ _ _ _ _ _ _ _ _ _ _ _ _ |_ 1 _|_ 3 _|_ 2 _|_ 8 _| This can then be summed, or have any operation performed. </pre> <p>I need to do this with an array of 'n' dimensions, which could feasibly be 20. Also, I need to be able to do this, caring about certain dimensions, and collapsing the rest. I am having an especially hard time with this because I cant visualize 20 dimensions :p . If anyone could help me set up some c/c++ code to collapse/sum, I would be very very grateful.</p> <h3>Update:</h3> <p>Just got home. Here is some info to answer your questions:</p> <ol> <li>Sorry for rolling back the edits, I was hoping when I clicked roll-back it would show me the changes so I could see what I messed up, a bit like wikipedia. This wasn't the case, as I found out.</li> <li>@jeff - What doesnt make sense? I am using this great service for (what I think is) a legit reason. I want to get better at my hobby, which is all it is, as I am in high school. Many of my posts regard implementing a genetic algorithm (This post, sparsearray, rank an array, pointer manipulation).</li> <li>I am using a sparse array representation, as it is possible to exceed the number of molecules in the universe using a traditional (dense) array. For now, the implementation of the sparsearray itself doesnt matter a whole lot, as I am working to make it work with a standard array before going to a sparse representation. For those who havent seen my previous questions, I am using a binary search tree as the structure to contain the sparse array points, and a &quot;driver&quot; function to traverse the tree as necessary, returning whatever the function is designed to do. This is flexible, so I can accomodate a lot of different methods of accessing the array.</li> <li>The structure is a hypercube, and the number of dimensions is specified at run time, as well as the length of each dimension (which are all the same, as it is a hypercube).</li> </ol> <p>Thanks everyone for your imput.</p>
[ { "answer_id": 23275, "author": "nlucaroni", "author_id": 157, "author_profile": "https://Stackoverflow.com/users/157", "pm_score": 0, "selected": false, "text": "[1] --> [1,2,3,4,5,6,...]\n[2] --> [1,2,3,4,5,6,...]\n[3] --> [1,2,3,4,5,6,...]\n[4] --> [1,2,3,4,5,6,...]\n[5] --> [1,2,3,4,...
2008/08/22
[ "https://Stackoverflow.com/questions/23190", "https://Stackoverflow.com", "https://Stackoverflow.com/users/522/" ]
23,197
<p>I have a library that reads/writes to a USB-device using CreateFile() API. The device happens to implement the HID-device profile, such that it's compatible with Microsoft's HID class driver.</p> <p>Some other application installed on the system is opening the device in read/write mode with no share mode. Which prevents my library (and anything that consumes it) from working with the device. I suppose that's the rub with being an HID-compatible device -- other driver software (mice, controllers, PHIDGETS, etc) can be uncooperative. </p> <p>Anyway, the device file path is of the form: </p> <pre> 1: "\\?\hid#hpqremhiddevice&col01#5&21ff20e7&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}". 2: "\\?\hid#vid_045e&pid_0023#7&34aa9ece&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}". 3: "\?\hid#vid_056a&pid_00b0&col01#6&5b05f29&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}". </pre> <p>And I'm trying to open it using code, like:</p> <pre><code>// First, open it with minimum permissions, this device may not be ours. // we'll re-open it later in read/write hid_device_ref = CreateFile( device_path, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); </code></pre> <p>I've considered a tool like FileMon or Process Monitor from SysInternals. But I can't seem to get it to report usage on device file handles like the one listed above.</p>
[ { "answer_id": 23219, "author": "Eric Z Beard", "author_id": 1219, "author_profile": "https://Stackoverflow.com/users/1219", "pm_score": 1, "selected": false, "text": "//Open file on the device\ndeviceHandle = \n CreateFile (deviceDetail->DevicePath, \n GENERIC_READ, FILE_SHARE_REA...
2008/08/22
[ "https://Stackoverflow.com/questions/23197", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2146/" ]
23,209
<p>I'm building an application against some legacy, third party libraries, and having problems with the linking stage. I'm trying to compile with Visual Studio 9. My compile command is:</p> <pre><code>cl -DNT40 -DPOMDLL -DCRTAPI1=_cdecl -DCRTAPI2=cdecl -D_WIN32 -DWIN32 -DWIN32_LEAN_AND_MEAN -DWNT -DBYPASS_FLEX -D_INTEL=1 -DIPLIB=none -I. -I"D:\src\include" -I"C:\Program Files\Microsoft Visual Studio 9.0\VC\include" -c -nologo -EHsc -W1 -Ox -Oy- -MD mymain.c </code></pre> <p>The code compiles cleanly. The link command is:</p> <pre><code>link -debug -nologo -machine:IX86 -verbose:lib -subsystem:console mymain.obj wsock32.lib advapi32.lib msvcrt.lib oldnames.lib kernel32.lib winmm.lib [snip large list of dependencies] D:\src\lib\app_main.obj -out:mymain.exe </code></pre> <p>The errors that I'm getting are:</p> <pre><code>app_main.obj : error LNK2019: unresolved external symbol "_\_declspec(dllimport) public: void __thiscall std::locale::facet::_Register(void)" (__imp_?_Register@facet@locale@std@@QAEXXZ) referenced in function "class std::ctype&lt;char&gt; const &amp; __cdecl std::use_facet&lt;class std::ctype&lt;char&gt; (class std::locale const &amp;)" (??$use_facet@V?$ctype@D@std@@@std@@YAABV?$ctype@D@0@ABVlocale@0@@Z) app_main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static unsigned int __cdecl std::ctype&lt;char&gt;::_Getcat(class std::locale::facet const * *)" (__imp_?_Getcat@?$ctype@D@std@@SAIPAPBVfacet@locale@2@@Z) referenced in function "class std::ctype&lt;char&gt; const &amp; __cdecl std::use_facet&lt;class std::ctype&lt;char&gt; (class std::locale const &amp;)" (??$use_facet@V?$ctype@D@std@@@std@@YAABV?$ctype@D@0@ABVlocale@0@@Z) app_main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static unsigned int __cdecl std::ctype&lt;unsigned short&gt;::_Getcat(class std::locale::facet const * *)" (__imp_?_Getcat@?$ctype@G@std@@SAIPAPBVfacet@locale@2@@Z) referenced in function "class std::ctype&lt;unsigned short&gt; const &amp; __cdecl std::use_facet&lt;class std::ctype&lt;unsigned short&gt; &gt;(class std::locale const &amp;)" (??$use_facet@V?$ctype@G@std@@@std@@YAABV?$ctype@G@0@ABVlocale@0@@Z) mymain.exe : fatal error LNK1120: 3 unresolved externals </code></pre> <p>Notice that these errors are coming from the legacy code, not my code - app_main.obj is part of the legacy code, while mymain.c is my source. I've done some searching around, and what that I've read says that this type of error is caused by a mismatch with the -MD switch between my code and the library that I'm linking to. Since I'm dealing with legacy code, a solution has to come from my environment. It's been a long time since I've done C++ work, and even longer since I've used Visual Studio, so I'm hoping that this is just some ignorance on my part. Any ideas on how to get these resolved?</p>
[ { "answer_id": 44886, "author": "Henk", "author_id": 4613, "author_profile": "https://Stackoverflow.com/users/4613", "pm_score": 2, "selected": false, "text": "DEFAULTLIB:\"libc\npmtd\" /DEFAULTLI\nB:\"uuid.lib\" /DE\nFAULTLIB:\"uuid.l\nib\" /include:?id\n@?$num_put@DV?$o\nstreambuf_iter...
2008/08/22
[ "https://Stackoverflow.com/questions/23209", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1322/" ]
23,216
<p>I can never remember the differences in regular expression syntax used by tools like <a href="http://en.wikipedia.org/wiki/Grep" rel="noreferrer">grep</a> and <a href="http://en.wikipedia.org/wiki/AWK" rel="noreferrer">AWK</a>, or languages like Python and PHP. Generally, Perl has the most expansive syntax, but I'm often hamstrung by the limitations of even <code>egrep</code> ("extended" <code>grep</code>).</p> <p>Is there a site that lists the differences in a concise and easy-to-read fashion?</p>
[ { "answer_id": 23232, "author": "yukondude", "author_id": 726, "author_profile": "https://Stackoverflow.com/users/726", "pm_score": 4, "selected": false, "text": "grep" } ]
2008/08/22
[ "https://Stackoverflow.com/questions/23216", "https://Stackoverflow.com", "https://Stackoverflow.com/users/726/" ]
23,217
<p>I've been making a concerted effort to improve my javascript skills lately by reading as much javascript code as I can. In doing this I've sometimes seen the <code>javascript:</code> prefix appended to the front of event handler attributes in HTML element tags. What's the purpose of this prefix? Basically, is there any appreciable difference between:</p> <pre><code>onchange="javascript: myFunction(this)" </code></pre> <p>and</p> <pre><code>onchange="myFunction(this)" </code></pre> <p>?</p>
[ { "answer_id": 23222, "author": "TheSmurf", "author_id": 1975282, "author_profile": "https://Stackoverflow.com/users/1975282", "pm_score": 5, "selected": true, "text": "javascript:" }, { "answer_id": 23237, "author": "Henrik Paul", "author_id": 2238, "author_profile":...
2008/08/22
[ "https://Stackoverflow.com/questions/23217", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1680/" ]
23,228
<p>Compare</p> <pre><code>String.Format("Hello {0}", "World"); </code></pre> <p>with</p> <pre><code>"Hello {0}".Format("World"); </code></pre> <p>Why did the .Net designers choose a static method over an instance method? What do you think?</p>
[ { "answer_id": 23248, "author": "Dan Blair", "author_id": 1327, "author_profile": "https://Stackoverflow.com/users/1327", "pm_score": 1, "selected": false, "text": "String.Format()" }, { "answer_id": 23253, "author": "Mat Noguchi", "author_id": 1799, "author_profile":...
2008/08/22
[ "https://Stackoverflow.com/questions/23228", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2361/" ]
23,250
<p>I was curious about how other people use the <strong>this</strong> keyword. I tend to use it in constructors, but I may also use it throughout the class in other methods. Some examples:</p> <p>In a constructor:</p> <pre><code>public Light(Vector v) { this.dir = new Vector(v); } </code></pre> <p>Elsewhere</p> <pre><code>public void SomeMethod() { Vector vec = new Vector(); double d = (vec * vec) - (this.radius * this.radius); } </code></pre>
[ { "answer_id": 23264, "author": "Corey", "author_id": 1595, "author_profile": "https://Stackoverflow.com/users/1595", "pm_score": 7, "selected": false, "text": "class Vector3\n{\n float x;\n float y;\n float z;\n\n public Vector3(float x, float y, float z)\n {\n thi...
2008/08/22
[ "https://Stackoverflow.com/questions/23250", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2016/" ]
23,277
<p>I've read the Wikipedia articles for both <a href="http://en.wikipedia.org/wiki/Procedural_programming" rel="noreferrer">procedural programming</a> and <a href="http://en.wikipedia.org/wiki/Functional_programming" rel="noreferrer">functional programming</a>, but I'm still slightly confused. Could someone boil it down to the core?</p>
[ { "answer_id": 23693, "author": "Brad Gilbert", "author_id": 1337, "author_profile": "https://Stackoverflow.com/users/1337", "pm_score": 7, "selected": false, "text": "sub factorial ( UInt:D $n is copy ) returns UInt {\n\n # modify \"outside\" state\n state $call-count++;\n # in this ...
2008/08/22
[ "https://Stackoverflow.com/questions/23277", "https://Stackoverflow.com", "https://Stackoverflow.com/users/572/" ]
23,287
<p>What is the best approach to calculating the largest prime factor of a number?</p> <p>I'm thinking the most efficient would be the following:</p> <ol> <li>Find lowest prime number that divides cleanly</li> <li>Check if result of division is prime</li> <li>If not, find next lowest</li> <li>Go to 2.</li> </ol> <p>I'm basing this assumption on it being easier to calculate the small prime factors. Is this about right? What other approaches should I look into?</p> <p>Edit: I've now realised that my approach is futile if there are more than 2 prime factors in play, since step 2 fails when the result is a product of two other primes, therefore a recursive algorithm is needed.</p> <p>Edit again: And now I've realised that this does still work, because the last found prime number has to be the highest one, therefore any further testing of the non-prime result from step 2 would result in a smaller prime.</p>
[ { "answer_id": 31235, "author": "palotasb", "author_id": 3063, "author_profile": "https://Stackoverflow.com/users/3063", "pm_score": -1, "selected": false, "text": "N" }, { "answer_id": 202429, "author": "Ralph M. Rickenbach", "author_id": 4549416, "author_profile": "...
2008/08/22
[ "https://Stackoverflow.com/questions/23287", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1951/" ]
23,372
<p>What would be the best method for getting a custom element (that is using J2ME native Graphics) painted on LWUIT elements?</p> <p>The custom element is an implementation from mapping library, that paints it's content (for example Google map) to Graphics object. How would it be possible to paint the result directly on LWUIT elements (at the moment I am trying to paint it on a Component). </p> <p>Is the only way to write a wrapper in LWUIT package, that would expose the internal implementation of it?</p> <p><strong>Edit:</strong></p> <p><strong><em>John:</em></strong> your solution looks like a lot of engineering :P What I ended up using is following wrapper:</p> <pre><code>package com.sun.lwuit; public class ImageWrapper { private final Image image; public ImageWrapper(final Image lwuitBuffer) { this.image = lwuitBuffer; } public javax.microedition.lcdui.Graphics getGraphics() { return image.getGraphics().getGraphics(); } } </code></pre> <p>Now I can get the 'native' Graphics element from LWUIT. Paint on it - effectively painting on LWUIT image. And I can use the image to paint on a component.</p> <p>And it still looks like a hack :)</p> <p>But the real problem is 50kB of code overhead, even after obfuscation. But this is a issue for another post :)</p> <p>/JaanusSiim</p>
[ { "answer_id": 86279, "author": "Honza", "author_id": 8621, "author_profile": "https://Stackoverflow.com/users/8621", "pm_score": 2, "selected": false, "text": "private Image buffer = null; // keep this\n\nint[] bufferArray = new int[desiredWidth * desiredHeight];\njavax.microedition.lcd...
2008/08/22
[ "https://Stackoverflow.com/questions/23372", "https://Stackoverflow.com", "https://Stackoverflow.com/users/706/" ]
23,376
<p>Has anyone found a good compression format for MS Sqlserver databases? If so, what do you use and are you pleased with how it performs? </p> <p>My company frequently will compress a database snapshot from one of our clients and download it so we have a local copy for testing and dev purposes. We tried zip in the past, but once the database files crossed the 4Gb boundary we had to use rar (zip is 32-bit only). The problem is rar takes a lot of time to compress, and we don't know if it gives us the best compression ratio either.</p> <p>This isn't a question about the compression utility so much as the compression format. We use WinRar, but are considering 7zip, which supports a number of formats.</p>
[ { "answer_id": 26428, "author": "dlamblin", "author_id": 459, "author_profile": "https://Stackoverflow.com/users/459", "pm_score": 1, "selected": false, "text": "cat file | gzip > file.gz" }, { "answer_id": 73290927, "author": "MrCalvin", "author_id": 3175384, "author...
2008/08/22
[ "https://Stackoverflow.com/questions/23376", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2188/" ]
23,397
<p>How do I implement some logic that will allow me to reproduce on Windows the functionality that I have on Linux with the <code>fork()</code> system call, using Python?</p> <p>I'm specifically trying to execute a method on the SAPI Com component, while continuing the other logic in the main thread without blocking or waiting.</p>
[ { "answer_id": 23510, "author": "Eli Courtwright", "author_id": 1694, "author_profile": "https://Stackoverflow.com/users/1694", "pm_score": 2, "selected": false, "text": " from threading import Thread\n \n def separate_computations(x, y):\n print sum(x for i in range(y)) ...
2008/08/22
[ "https://Stackoverflow.com/questions/23397", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2555/" ]
23,399
<p>I've got an interesting design question. I'm designing the security side of our project, to allow us to have different versions of the program for different costs and also to allow Manager-type users to grant or deny access to parts of the program to other users. Its going to web-based and hosted on our servers.</p> <p>I'm using a simple Allow or Deny option for each 'Resource' or screen.</p> <p>We're going to have a large number of resources, and the user will be able to set up many different groups to put users in to control access. Each user can only belong to a single group.</p> <p>I've got two approaches to this in mind, and was curious which would be better for the SQL server in terms of performance.</p> <p><strong>Option A</strong> The presence of an entry in the access table means access is allowed. This will not need a column in the database to store information. If no results are returned, then access is denied.</p> <p>I think this will mean a smaller table, but would queries search the whole table to determine there is no match?</p> <p><strong>Option B</strong> A bit column is included in the database that controls the Allow/Deny. This will mean there is always a result to be found, and makes for a larger table.</p> <p>Thoughts?</p>
[ { "answer_id": 23432, "author": "Eric Z Beard", "author_id": 1219, "author_profile": "https://Stackoverflow.com/users/1219", "pm_score": 3, "selected": true, "text": "UserResources\n-------------\nUserId FK->Users\nResourceId FK->Resources\n" }, { "answer_id": 23480, "author"...
2008/08/22
[ "https://Stackoverflow.com/questions/23399", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1470/" ]
23,445
<p>I have two collections of the same object, <code>Collection&lt;Foo&gt; oldSet</code> and <code>Collection&lt;Foo&gt; newSet</code>. The required logic is as follow:</p> <ul> <li>if <code>foo</code> is in(*) <code>oldSet</code> but not <code>newSet</code>, call <code>doRemove(foo)</code></li> <li>else if <code>foo</code> is not in <code>oldSet</code> but in <code>newSet</code>, call <code>doAdd(foo)</code></li> <li>else if <code>foo</code> is in both collections but modified, call <code>doUpdate(oldFoo, newFoo)</code></li> <li>else if <code>!foo.activated &amp;&amp; foo.startDate &gt;= now</code>, call <code>doStart(foo)</code></li> <li>else if <code>foo.activated &amp;&amp; foo.endDate &lt;= now</code>, call <code>doEnd(foo)</code></li> </ul> <p>(*) "in" means the unique identifier matches, not necessarily the content.</p> <p>The current (legacy) code does many comparisons to figure out <code>removeSet</code>, <code>addSet</code>, <code>updateSet</code>, <code>startSet</code> and <code>endSet</code>, and then loop to act on each item.</p> <p>The code is quite messy (partly because I have left out some spaghetti logic already) and I am trying to refactor it. Some more background info:</p> <ul> <li>As far as I know, the <code>oldSet</code> and <code>newSet</code> are actually backed by <code>ArrayList</code></li> <li>Each set contains less than 100 items, most likely max out at 20</li> <li>This code is called frequently (measured in millions/day), although the sets seldom differ</li> </ul> <p>My questions:</p> <ul> <li>If I convert <code>oldSet</code> and <code>newSet</code> into <code>HashMap&lt;Foo&gt;</code> (order is not of concern here), with the IDs as keys, would it made the code easier to read and easier to compare? How much of time &amp; memory performance is loss on the conversion?</li> <li>Would iterating the two sets and perform the appropriate operation be more efficient and concise?</li> </ul>
[ { "answer_id": 23944, "author": "martinatime", "author_id": 1353, "author_profile": "https://Stackoverflow.com/users/1353", "pm_score": 4, "selected": false, "text": "Collection<Foo> oldSet = ...;\nCollection<Foo> newSet = ...;\n\nprivate Collection difference(Collection a, Collection b)...
2008/08/22
[ "https://Stackoverflow.com/questions/23445", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2551/" ]
23,446
<p>Have just started using Visual Studio Professional's built-in unit testing features, which as I understand, uses MS Test to run the tests.</p> <p>The .trx file that the tests produce is xml, but was wondering if there was an easy way to convert this file into a more "manager-friendly" format?</p> <p>My ultimate goal is to be able to automate the unit-testing and be able to produce a nice looking document that shows the tests run and how 100% of them passed :)</p>
[ { "answer_id": 289473, "author": "Preet Sangha", "author_id": 30225, "author_profile": "https://Stackoverflow.com/users/30225", "pm_score": 2, "selected": false, "text": "<xsl:stylesheet version=\"2.0\" \n xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"\n ...
2008/08/22
[ "https://Stackoverflow.com/questions/23446", "https://Stackoverflow.com", "https://Stackoverflow.com/users/443/" ]
23,448
<p>Has anyone worked with <a href="http://www.google.com.br/url?sa=t&amp;ct=res&amp;cd=1&amp;url=http%3A%2F%2Fen.wikipedia.org%2Fwiki%2FDomain-specific_programming_language&amp;ei=QyWvSIXcC4foebjSlHs&amp;usg=AFQjCNFsZOnJm-AGmi5sxai8YI-0Al6wfA&amp;sig2=6nX5EkUmNkEwiSKAkUeyZQ" rel="noreferrer">DSLs (Domain Specific Languages)</a> in the finance domain? I am planning to introduce some kind of DSL support in the application that I am working on and would like to share some ideas.</p> <p>I am in a stage of identifying which are the most stable domain elements and selecting the features which would be better implemented with the DSL. I have not yet defined the syntax for this first feature.</p>
[ { "answer_id": 31770859, "author": "SemanticBeeng", "author_id": 4032515, "author_profile": "https://Stackoverflow.com/users/4032515", "pm_score": 1, "selected": false, "text": " object Main extends App {\n //Required for doing LocalDate comparisons...a scalaism\n implicit val LocalDa...
2008/08/22
[ "https://Stackoverflow.com/questions/23448", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2015/" ]
23,511
<p>I'm working with Subversion based on Windows and would like to write an easy utility in .NET for working with the Apache password file. I understand that it uses a function referred to as MD5Crypt, but I can't seem to find a description of the algorithm beyond that at some point it uses MD5 to create a hash.</p> <p>Can someone describe the MD5Crypt algorithm and password line format?</p>
[ { "answer_id": 23557, "author": "Mark Harrison", "author_id": 116, "author_profile": "https://Stackoverflow.com/users/116", "pm_score": 2, "selected": false, "text": "System.Security.Cryptography.MD5CryptoServiceProvider md5 = new\nSystem.Security.Cryptography.MD5CryptoServiceProvider();...
2008/08/22
[ "https://Stackoverflow.com/questions/23511", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1954/" ]
23,566
<p>On IIS 6, what does an IIS reset do? </p> <p>Please compare to recycling an app pool and stopping and starting an ASP.NET web site.</p> <p>If you replace a DLL or edit/replace the web.config on an ASP.NET web site is that the same as stopping and starting that web site?</p>
[ { "answer_id": 23573, "author": "Michael Stum", "author_id": 91, "author_profile": "https://Stackoverflow.com/users/91", "pm_score": 3, "selected": false, "text": "web.config" }, { "answer_id": 23581, "author": "jonezy", "author_id": 2272, "author_profile": "https://S...
2008/08/22
[ "https://Stackoverflow.com/questions/23566", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1463/" ]
23,569
<p>How do you calculate the distance between 2 cities? </p>
[ { "answer_id": 23632, "author": "Jared Updike", "author_id": 2543, "author_profile": "https://Stackoverflow.com/users/2543", "pm_score": 1, "selected": false, "text": "// Cities are points x0,y0 and x1,y1 in kilometers or miles or Smoots[1]\ndx = x1 - x0;\ndy = y1 - y0;\ndist = sqrt(dx*d...
2008/08/22
[ "https://Stackoverflow.com/questions/23569", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2141/" ]
23,578
<p>And on top of that, are there cases where one has to use the global assembly cache or where one cannot use it?</p>
[ { "answer_id": 23635, "author": "Kev", "author_id": 419, "author_profile": "https://Stackoverflow.com/users/419", "pm_score": 4, "selected": false, "text": "AllowPartiallyTrustedCallers" } ]
2008/08/22
[ "https://Stackoverflow.com/questions/23578", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2374/" ]
23,603
<p>I'm developing a library alongside several projects that use it, and I've found myself frequently modifying the library at the same time as a project (e.g., adding a function to the library and immediately using it in the project).<br> As a result, the project would no longer compile with previous versions of the library.</p> <p>So if I need to rollback a change or test a previous version of the project, I'd like to know what version of the library was used at check-in.<br> I suppose I could do this manually (by just writing the version number in the log file), but it would be great if this could happen automatically.</p>
[ { "answer_id": 23702, "author": "tghw", "author_id": 2363, "author_profile": "https://Stackoverflow.com/users/2363", "pm_score": 2, "selected": false, "text": "/\n /trunk\n /tags\n /branches\n" }, { "answer_id": 23816, "author": "Orion Edwards", "author_id": 234, "...
2008/08/22
[ "https://Stackoverflow.com/questions/23603", "https://Stackoverflow.com", "https://Stackoverflow.com/users/112/" ]
23,620
<p>I'm using TinyMCE in an ASP.Net project, and I need a spell check. The only TinyMCE plugins I've found use PHP on the server side, and I guess I could just break down and install PHP on my server and do that, but quite frankly, what a pain. I don't want to do that.</p> <p>As it turns out, Firefox's built-in spell check will work fine for me, but it doesn't seem to work on TinyMCE editor boxes. I've enabled the gecko_spellcheck option, which is supposed to fix it, but it doesn't.</p> <p>Does anybody know of a nice rich-text editor that doesn't break the browser's spell check?</p>
[ { "answer_id": 23733, "author": "Shog9", "author_id": 811, "author_profile": "https://Stackoverflow.com/users/811", "pm_score": 2, "selected": false, "text": "gecko_spellcheck" } ]
2008/08/22
[ "https://Stackoverflow.com/questions/23620", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2527/" ]
23,689
<p>Does anyone know of a .NET date/time parser similar to <a href="http://chronic.rubyforge.org/" rel="noreferrer">Chronic for Ruby</a> (handles stuff like "tomorrow" or "3pm next thursday")?</p> <p>Note: I do write Ruby (which is how I know about Chronic) but this project must use .NET.</p>
[ { "answer_id": 23833, "author": "Burton", "author_id": 1493, "author_profile": "https://Stackoverflow.com/users/1493", "pm_score": 2, "selected": false, "text": "Private Function ConvertDateTimeToStringRelativeToNow(ByVal d As DateTime) As String\n Dim diff As TimeSpan = DateTime.Now(...
2008/08/22
[ "https://Stackoverflow.com/questions/23689", "https://Stackoverflow.com", "https://Stackoverflow.com/users/521/" ]
23,715
<p>Has anyone had any success running two different web servers -- such as Apache and CherryPy -- alongside each other on the same machine? I am experimenting with other web servers right now, and I'd like to see if I can do my experiments while keeping my other sites up and running. You could say that this isn't so much a specific-software question as it is a general networking question.</p> <ul> <li>I know it's possible to run two web servers on different ports; but is there any way to configure them so that they can run on the <em>same port</em> (ie, they both run on port 80)?</li> <li>The web servers would <em>not</em> be serving files from the same domains. For example, Apache might serve up documents from foo.domain.com, and the other web server would serve from bar.domain.com.</li> </ul> <p>I do know that this is not an ideal configuration. I'd just like to see if it can be done before I go sprinting down the rabbit hole. :) </p>
[ { "answer_id": 23732, "author": "Gary Richardson", "author_id": 2506, "author_profile": "https://Stackoverflow.com/users/2506", "pm_score": 4, "selected": true, "text": "NameVirtualHost *\n<virtualhost *>\n ServerName other.site.com\n\n # assumes CherryPy listens on port 8080\n ProxyP...
2008/08/22
[ "https://Stackoverflow.com/questions/23715", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2321/" ]
23,755
<p>When implementing a needle search of a haystack in an object-oriented way, you essentially have three alternatives:</p> <pre><code>1. needle.find(haystack) 2. haystack.find(needle) 3. searcher.find(needle, haystack)</code></pre> <p>Which do you prefer, and why?</p> <p>I know some people prefer the second alternative because it avoids introducing a third object. However, I can't help feeling that the third approach is more conceptually "correct", at least if your goal is to model "the real world".</p> <p>In which cases do you think it is justified to introduce helper objects, such as the searcher in this example, and when should they be avoided?</p>
[ { "answer_id": 23756, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 3, "selected": false, "text": "needle.find(haystack)" }, { "answer_id": 23769, "author": "Mike Stone", "author_id": 122, "author_...
2008/08/22
[ "https://Stackoverflow.com/questions/23755", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1709/" ]
23,763
<p>I'm working on some code to colorize an image in Java. Basically what I'd like to do is something along the lines of GIMP's colorize command, so that if I have a BufferedImage and a Color, I can colorize the Image with the given color. Anyone got any ideas? My current best guess at doing something like this is to get the rgb value of each pixel in the BufferedImage and add the RGB value of the Color to it with some scaling factor.</p>
[ { "answer_id": 23795, "author": "Nick", "author_id": 1490, "author_profile": "https://Stackoverflow.com/users/1490", "pm_score": 3, "selected": false, "text": "Y = 0.3*R + 0.59*G + 0.11*B" }, { "answer_id": 27185, "author": "Bernie Perez", "author_id": 1992, "author_p...
2008/08/22
[ "https://Stackoverflow.com/questions/23763", "https://Stackoverflow.com", "https://Stackoverflow.com/users/85/" ]
23,787
<p>What is the best way to find something in a list? I know LINQ has some nice tricks, but let's also get suggestions for C# 2.0. Lets get the best refactorings for this common code pattern.</p> <p>Currently I use code like this:</p> <pre><code>// mObjList is a List&lt;MyObject&gt; MyObject match = null; foreach (MyObject mo in mObjList) { if (Criteria(mo)) { match = mo; break; } } </code></pre> <p>or</p> <pre><code>// mObjList is a List&lt;MyObject&gt; bool foundIt = false; foreach (MyObject mo in mObjList) { if (Criteria(mo)) { foundIt = true; break; } } </code></pre>
[ { "answer_id": 23794, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 1, "selected": false, "text": "break" }, { "answer_id": 23799, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "...
2008/08/23
[ "https://Stackoverflow.com/questions/23787", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1490/" ]
23,802
<p>I'm wondering what the best practice is for handling the problem with having to "include" so many files in my PHP scripts in order to ensure that all the classes I need to use are accessible to my script. </p> <p>Currently, I'm just using <a href="http://php.net/manual/en/function.include-once.php" rel="nofollow noreferrer">include_once</a> to include the classes I access directly. Each of those would <code>include_once</code> the classes that they access. </p> <p>I've looked into using the <code>__autoload</code> function, but hat doesn't seem to work well if you plan to have your class files organized in a directory tree. If you did this, it seems like you'd end up walking the directory tree until you found the class you were looking for. <strong><em>Also, I'm not sure how this effects classes with the same name in different namespaces.</em></strong> </p> <p><strong>Is there an easier way to handle this?</strong> </p> <p>Or is PHP just not suited to "<strong>enterprisey</strong>" type applications with lots of different objects all located in separate files that can be in many different directories.</p>
[ { "answer_id": 23805, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 0, "selected": false, "text": "__autoload" }, { "answer_id": 23806, "author": "JasonMichael", "author_id": 1935, "author_profile"...
2008/08/23
[ "https://Stackoverflow.com/questions/23802", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1862/" ]
23,853
<p>I am using Struts + Velocity in a Java application, but after I submit a form, the confirmation page (Velocity template) shows the variable names instead an empty label, like the Age in following example:</p> <blockquote> <p><strong>Name</strong>: Fernando</p> <p><strong>Age</strong>: {person.age}</p> <p><strong>Sex</strong>: Male</p> </blockquote> <p>I would like to know how to hide it!</p>
[ { "answer_id": 23879, "author": "Jason Sparks", "author_id": 512, "author_profile": "https://Stackoverflow.com/users/512", "pm_score": 7, "selected": true, "text": "$!variable\n" } ]
2008/08/23
[ "https://Stackoverflow.com/questions/23853", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2274/" ]
23,867
<p>The <code>Close</code> method on an <code>ICommunicationObject</code> can throw two types of exceptions as MSDN outlines <a href="http://msdn.microsoft.com/en-us/library/ms195520.aspx" rel="nofollow noreferrer">here</a>. I understand why the <code>Close</code> method can throw those exceptions, but what I don't understand is why the <code>Dispose</code> method on a service proxy calls the <code>Close</code> method without a <code>try</code> around it. Isn't your <code>Dispose</code> method the one place where you want make sure you don't throw any exceptions?</p>
[ { "answer_id": 23879, "author": "Jason Sparks", "author_id": 512, "author_profile": "https://Stackoverflow.com/users/512", "pm_score": 7, "selected": true, "text": "$!variable\n" } ]
2008/08/23
[ "https://Stackoverflow.com/questions/23867", "https://Stackoverflow.com", "https://Stackoverflow.com/users/781/" ]
23,899
<p>I've got to do some significant development in a large, old, spaghetti-ridden ASP system. I've been away from ASP for a long time, focusing my energies on Rails development.</p> <p>One basic step I've taken is to refactor pages into subs and functions with meaningful names, so that at least it's easy to understand @ the top of the file what's generally going on.</p> <p>Is there a worthwhile MVC framework for ASP? Or a best practice at how to at least get business logic out of the views? (I remember doing a lot of includes back in the day -- is that still the way to do it?)</p> <p>I'd love to get some unit testing going for business logic too, but maybe I'm asking too much?</p> <h3>Update:</h3> <p>There are over 200 ASP scripts in the project, some thousands of lines long ;) UGH!</p> <p>We may opt for the &quot;big rewrite&quot; but until then, when I'm in changing a page, I want to spend a little extra time cleaning up the spaghetti.</p>
[ { "answer_id": 60404, "author": "Christopher Mahan", "author_id": 479, "author_profile": "https://Stackoverflow.com/users/479", "pm_score": 5, "selected": true, "text": "<font size=3>crap</font>" } ]
2008/08/23
[ "https://Stackoverflow.com/questions/23899", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2477/" ]
23,907
<p>Basically I want to get the number of lines-of-code in the repository after each commit.</p> <p>The only (really crappy) ways I have found is to use <code>git filter-branch</code> to run <code>wc -l *</code>, and a script that runs <code>git reset --hard</code> on each commit, then runs <code>wc -l</code></p> <p>To make it a bit clearer, when the tool is run, it would output the lines of code of the very first commit, then the second and so on. This is what I want the tool to output (as an example):</p> <pre class="lang-none prettyprint-override"><code>me@something:~/$ gitsloc --branch master 10 48 153 450 1734 1542 </code></pre> <p>I've played around with the ruby 'git' library, but the closest I found was using the <code>.lines()</code> method on a diff, which seems like it should give the added lines (but does not: it returns 0 when you delete lines for example)</p> <pre class="lang-rb prettyprint-override"><code>require 'rubygems' require 'git' total = 0 g = Git.open(working_dir = '/Users/dbr/Desktop/code_projects/tvdb_api') last = nil g.log.each do |cur| diff = g.diff(last, cur) total = total + diff.lines puts total last = cur end </code></pre>
[ { "answer_id": 35664, "author": "fserb", "author_id": 3702, "author_profile": "https://Stackoverflow.com/users/3702", "pm_score": 5, "selected": false, "text": "git log --shortstat --reverse --pretty=oneline\n" } ]
2008/08/23
[ "https://Stackoverflow.com/questions/23907", "https://Stackoverflow.com", "https://Stackoverflow.com/users/745/" ]
23,918
<p>I'm trying to do a simple rotation in OpenGL but must be missing the point. I'm not looking for a specific fix so much as a quick explanation or link that explains OpenGL rotation more generally.</p> <p>At the moment I have code like this:</p> <pre><code>glPushMatrix(); glRotatef(90.0, 0.0, 1.0, 0.0); glBegin(GL_TRIANGLES); glVertex3f( 1.0, 1.0, 0.0 ); glVertex3f( 3.0, 2.0, 0.0 ); glVertex3f( 3.0, 1.0, 0.0 ); glEnd(); glPopMatrix(); </code></pre> <p>But the result is not a triangle rotated 90 degrees.</p> <p><strong>Edit</strong> Hmm thanks to Mike Haboustak - it appeared my code was calling a SetCamera function that use glOrtho. I'm too new to OpenGL to have any idea of what this meant but disabling this and rotating in the Z-axis produced the desired result. </p>
[ { "answer_id": 23925, "author": "spate", "author_id": 2276, "author_profile": "https://Stackoverflow.com/users/2276", "pm_score": 3, "selected": false, "text": "glMatrixMode(GL_MODELVIEW);\n" } ]
2008/08/23
[ "https://Stackoverflow.com/questions/23918", "https://Stackoverflow.com", "https://Stackoverflow.com/users/364/" ]
23,930
<p>I want to see all the different ways you can come up with, for a factorial subroutine, or program. The hope is that anyone can come here and see if they might want to learn a new language.</p> <h2>Ideas:</h2> <ul> <li>Procedural</li> <li>Functional</li> <li>Object Oriented</li> <li>One liners</li> <li>Obfuscated</li> <li>Oddball</li> <li>Bad Code</li> <li><a href="http://en.wikipedia.org/wiki/Polyglot_%28computing%29" rel="nofollow noreferrer">Polyglot</a></li> </ul> <p>Basically I want to see an example, of different ways of writing an algorithm, and what they would look like in different languages.</p> <p>Please limit it to one example per entry. I will allow you to have more than one example per answer, if you are trying to highlight a specific style, language, or just a well thought out idea that lends itself to being in one post.</p> <p>The only real requirement is it must find the factorial of a given argument, in all languages represented.</p> <h1>Be Creative!</h1> <h2>Recommended Guideline:</h2> <pre> # Language Name: Optional Style type - Optional bullet points Code Goes Here Other informational text goes here </pre> <p>I will ocasionally go along and edit any answer that does not have decent formatting.</p>
[ { "answer_id": 23932, "author": "Brad Gilbert", "author_id": 1337, "author_profile": "https://Stackoverflow.com/users/1337", "pm_score": 2, "selected": false, "text": "multi factorial ( Int $n where { $n <= 0 } ){\n return 1;\n}\nmulti factorial ( Int $n ){\n return $n * factorial( $n...
2008/08/23
[ "https://Stackoverflow.com/questions/23930", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1337/" ]
23,931
<p>Given two different image files (in whatever format I choose), I need to write a program to predict the chance if one being the illegal copy of another. The author of the copy may do stuff like rotating, making negative, or adding trivial details (as well as changing the dimension of the image).</p> <p>Do you know any algorithm to do this kind of job?</p>
[ { "answer_id": 3445087, "author": "Tom Gullen", "author_id": 356635, "author_profile": "https://Stackoverflow.com/users/356635", "pm_score": 8, "selected": false, "text": "white\nred\nblue\ngreen\nblack\n" }, { "answer_id": 3464874, "author": "navneeth", "author_id": 1912...
2008/08/23
[ "https://Stackoverflow.com/questions/23931", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
23,962
<p>For example, Look at the code that calculates the n-th Fibonacci number:</p> <pre><code>fib(int n) { if(n==0 || n==1) return 1; return fib(n-1) + fib(n-2); } </code></pre> <p>The problem with this code is that it will generate stack overflow error for any number greater than 15 (in most computers).</p> <p>Assume that we are calculating fib(10). In this process, say fib(5) is calculated a lot of times. Is there some way to store this in memory for fast retrieval and thereby increase the speed of recursion?</p> <p>I am looking for a generic technique that can be used in almost all problems.</p>
[ { "answer_id": 23973, "author": "roo", "author_id": 716, "author_profile": "https://Stackoverflow.com/users/716", "pm_score": 1, "selected": false, "text": "class fibstorage {\n\n\n bool has-result(int n) { return fibresults.contains(n); }\n int get-result(int n) { return fibresult...
2008/08/23
[ "https://Stackoverflow.com/questions/23962", "https://Stackoverflow.com", "https://Stackoverflow.com/users/184/" ]
23,970
<p>Joe Van Dyk <a href="http://www.zenspider.com/pipermail/ruby/2008-August/004223.html" rel="noreferrer">asked the Ruby mailing list</a>:</p> <blockquote> <p>Hi,</p> <p>In Ruby, I guess you can't marshal a lambda/proc object, right? Is that possible in lisp or other languages?</p> <p>What I was trying to do:</p> </blockquote> <pre><code>l = lamda { ... } Bj.submit "/path/to/ruby/program", :stdin =&gt; Marshal.dump(l) </code></pre> <blockquote> <p>So, I'm sending BackgroundJob a lambda object, which contains the context/code for what to do. But, guess that wasn't possible. I ended up marshaling a normal ruby object that contained instructions for what to do after the program ran.</p> <p>Joe</p> </blockquote>
[ { "answer_id": 3705317, "author": "dominic", "author_id": 122875, "author_profile": "https://Stackoverflow.com/users/122875", "pm_score": 4, "selected": false, "text": "code = %{\n lambda {\"hello ruby code\".split(\" \").each{|e| puts e + \"!\"}}\n}\n" }, { "answer_id": 52353...
2008/08/23
[ "https://Stackoverflow.com/questions/23970", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1190/" ]
23,996
<p>I'm working with <a href="http://webby.rubyforge.org" rel="nofollow noreferrer" title="Webby">Webby</a> and am looking for some clarification. Can I define attributes like <code>title</code> or <code>author</code> in my layout?</p>
[ { "answer_id": 26243, "author": "Mando Escamilla", "author_id": 1388162, "author_profile": "https://Stackoverflow.com/users/1388162", "pm_score": 2, "selected": true, "text": "SITE.page_defaults['title'] = \"My awesome title\"\nSITE.page_defaults['author'] = \"Shaz...
2008/08/23
[ "https://Stackoverflow.com/questions/23996", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2165/" ]
24,041
<p>I'm using markdown to edit this question right now. In some <a href="http://en.wikipedia.org/wiki/Wikipedia:How_to_edit_a_page#Wiki_markup" rel="noreferrer">wikis</a> I used wiki markup. Are they the same thing? Are they related? Please explain. If I want to implement one or the other in a web project (like stackoverflow) what do I need to use?</p>
[ { "answer_id": 24093, "author": "Keith", "author_id": 905, "author_profile": "https://Stackoverflow.com/users/905", "pm_score": 7, "selected": false, "text": "<ul>\n <li>Item one</li>\n <li>Item two</li>\n</ul>\n" } ]
2008/08/23
[ "https://Stackoverflow.com/questions/24041", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1363/" ]
24,046
<p>I do some minor programming and web work for a local community college. Work that includes maintaining a very large and soul destroying website that consists of a hodge podge of VBScript, javascript, Dreamweaver generated cruft and a collection of add-ons that various conmen have convinced them to buy over the years. </p> <p>A few days ago I got a call "The website is locking up for people using Safari!" Okay, step one download Safari(v3.1.2), step two surf to the site. Everything appears to work fine.</p> <p>Long story short I finally isolated the problem and it relates to Safari's back button. The website uses a fancy-pants javascript menu that works in every browser I've tried including Safari, the first time around. But in Safari if you follow a link off the page and then hit the back button the menu no longer works.</p> <p>I made a pared down webpage to illustrate the principle.</p> <pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&gt; &lt;html&gt; &lt;head&gt;&lt;title&gt;Safari Back Button Test&lt;/title&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt; &lt;/head&gt; &lt;body onload="alert('Hello');"&gt; &lt;a href="http://www.codinghorror.com"&gt;Coding Horror&lt;/a&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Load the page and you see the alert box. Then follow the link off the page and hit the back button. In IE and Firefox you see the alert box again, in Safari you do not.</p> <p>After a vigorous googling I've discovered others with similar problems but no really satisfactory answers. So my question is how can I make my pages work the same way in Safari after the user hits the back button as they do in other browsers?</p> <p>If this is a stupid question please be gentle, javascript is somewhat new to me.</p>
[ { "answer_id": 24059, "author": "Stefan Ladwig", "author_id": 2585, "author_profile": "https://Stackoverflow.com/users/2585", "pm_score": 3, "selected": false, "text": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n<html>\n<head><title>Safari Back Button Test</title>...
2008/08/23
[ "https://Stackoverflow.com/questions/24046", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2051/" ]
24,109
<p>I want to expand my programming horizons to Linux. A good, dependable basic toolset is important, and what is more basic than an IDE?</p> <p>I could find these SO topics:</p> <ul> <li><a href="https://stackoverflow.com/questions/2756/lightweight-ide-for-linux">Lightweight IDE for linux</a> and</li> <li><a href="https://stackoverflow.com/questions/17228/what-tools-do-you-use-to-develop-c-applications-on-linux">What tools do you use to develop C++ applications on Linux?</a></li> </ul> <p>I'm not looking for a <em>lightweight</em> IDE. If an IDE is worth the money, then I will pay for it, so it need not be free.</p> <p>My question, then:</p> <blockquote> <p><em>What good, C++ programming IDE is available for Linux?</em></p> </blockquote> <p>The minimums are fairly standard: syntax highlighting, code completion (like <a href="http://en.wikipedia.org/wiki/IntelliSense" rel="nofollow noreferrer">intellisense</a> or its Eclipse counterpart) and integrated debugging (e.g., basic breakpoints).</p> <p>I have searched for it myself, but there are so many that it is almost impossible to separate the good from the bads by hand, especially for someone like me who has little C++ coding experience in Linux. I know that <a href="http://www.eclipse.org/cdt/" rel="nofollow noreferrer">Eclipse supports C++</a>, and I really like that IDE for Java, but is it any good for C++ and is there something better?</p> <p>The second post actually has some good suggestions, but what I am missing is what exactly makes the sugested IDE so good for the user, what are its (dis)advantages?</p> <p>Maybe my question should therefore be:</p> <blockquote> <p><em>What IDE do you propose (given your experiences), and why?</em></p> </blockquote>
[ { "answer_id": 24156, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 5, "selected": false, "text": "man" }, { "answer_id": 2540028, "author": "Charles Zhang", "author_id": 304449, "author_profile": ...
2008/08/23
[ "https://Stackoverflow.com/questions/24109", "https://Stackoverflow.com", "https://Stackoverflow.com/users/46/" ]
24,130
<p>Which is better to use in PHP, a 2D array or a class? I've included an example of what I mean by this.</p> <pre><code>// Using a class class someClass { public $name; public $height; public $weight; function __construct($name, $height, $weight) { $this -&gt; name = $name; $this -&gt; height = $height; $this -&gt; weight = $weight; } } $classArray[1] = new someClass('Bob', 10, 20); $classArray[2] = new someClass('Fred', 15, 10); $classArray[3] = new someClass('Ned', 25, 30); // Using a 2D array $normalArray[1]['name'] = 'Bob'; $normalArray[1]['height'] = 10; $normalArray[1]['weight'] = 20; $normalArray[2]['name'] = 'Fred'; $normalArray[2]['height'] = 15; $normalArray[2]['weight'] = 10; $normalArray[3]['name'] = 'Ned'; $normalArray[3]['height'] = 25; $normalArray[3]['weight'] = 30; </code></pre> <hr> <p>Assuming that somebody doesn't come out and show that classes are too slow, it looks like class wins.</p> <p>I've not idea which answer I should accept to I've just upvoted all of them.</p> <hr> <p>And I have now written two near identical pages, one using the 2D array (written before this question was posted) and now one using a class and I must say that the class produces much nicer code. I have no idea how much overhead is going to be generated but I doubt it will rival the improvement to the code itself.</p> <p>Thank you for helping to make me a better programmer.</p>
[ { "answer_id": 24134, "author": "Brian Warshaw", "author_id": 1344, "author_profile": "https://Stackoverflow.com/users/1344", "pm_score": 4, "selected": true, "text": "weight" }, { "answer_id": 4571581, "author": "Richard Varno", "author_id": 214891, "author_profile":...
2008/08/23
[ "https://Stackoverflow.com/questions/24130", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1384652/" ]
24,168
<p>When writing database queries in something like TSQL or PLSQL, we often have a choice of iterating over rows with a cursor to accomplish the task, or crafting a single SQL statement that does the same job all at once.</p> <p>Also, we have the choice of simply pulling a large set of data back into our application and then processing it row by row, with C# or Java or PHP or whatever.</p> <p>Why is it better to use set-based queries? What is the theory behind this choice? What is a good example of a cursor-based solution and its relational equivalent?</p>
[ { "answer_id": 24211, "author": "Mark Brackett", "author_id": 2199, "author_profile": "https://Stackoverflow.com/users/2199", "pm_score": 4, "selected": false, "text": "--Cursor\nDECLARE @phoneNumber char(7)\nDECLARE c CURSOR LOCAL FAST_FORWARD FOR\n SELECT PhoneNumber FROM Customer WH...
2008/08/23
[ "https://Stackoverflow.com/questions/24168", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1219/" ]
24,200
<p>I am hitting some performance bottlenecks with my C# client inserting bulk data into a SQL Server 2005 database and I'm looking for ways in which to speed up the process.</p> <p>I am already using the SqlClient.SqlBulkCopy (which is based on TDS) to speed up the data transfer across the wire which helped a lot, but I'm still looking for more.</p> <p>I have a simple table that looks like this: </p> <pre><code> CREATE TABLE [BulkData]( [ContainerId] [int] NOT NULL, [BinId] [smallint] NOT NULL, [Sequence] [smallint] NOT NULL, [ItemId] [int] NOT NULL, [Left] [smallint] NOT NULL, [Top] [smallint] NOT NULL, [Right] [smallint] NOT NULL, [Bottom] [smallint] NOT NULL, CONSTRAINT [PKBulkData] PRIMARY KEY CLUSTERED ( [ContainerIdId] ASC, [BinId] ASC, [Sequence] ASC )) </code></pre> <p>I'm inserting data in chunks that average about 300 rows where ContainerId and BinId are constant in each chunk and the Sequence value is 0-n and the values are pre-sorted based on the primary key. </p> <p>The %Disk time performance counter spends a lot of time at 100% so it is clear that disk IO is the main issue but the speeds I'm getting are several orders of magnitude below a raw file copy.</p> <p>Does it help any if I:</p> <ol> <li>Drop the Primary key while I am doing the inserting and recreate it later</li> <li>Do inserts into a temporary table with the same schema and periodically transfer them into the main table to keep the size of the table where insertions are happening small</li> <li>Anything else?</li> </ol> <p>-- Based on the responses I have gotten, let me clarify a little bit:</p> <p>Portman: I'm using a clustered index because when the data is all imported I will need to access data sequentially in that order. I don't particularly need the index to be there while importing the data. Is there any advantage to having a nonclustered PK index while doing the inserts as opposed to dropping the constraint entirely for import?</p> <p>Chopeen: The data is being generated remotely on many other machines (my SQL server can only handle about 10 currently, but I would love to be able to add more). It's not practical to run the entire process on the local machine because it would then have to process 50 times as much input data to generate the output.</p> <p>Jason: I am not doing any concurrent queries against the table during the import process, I will try dropping the primary key and see if that helps.</p>
[ { "answer_id": 2899468, "author": "JohnB", "author_id": 287311, "author_profile": "https://Stackoverflow.com/users/287311", "pm_score": 5, "selected": false, "text": "--Disable Index ALTER INDEX [IX_Users_UserID] SalesDB.Users DISABLE\nGO\n--Enable Index ALTER INDEX [IX_Users_UserID] Sal...
2008/08/23
[ "https://Stackoverflow.com/questions/24200", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1948/" ]
24,207
<p>I'm trying to use “rusage” statistics in my program to get data similar to that of the <a href="http://en.wikipedia.org/wiki/Time_%28Unix%29" rel="nofollow noreferrer">time</a> tool. However, I'm pretty sure that I'm doing something wrong. The values seem about right but can be a bit weird at times. I didn't find good resources online. Does somebody know how to do it better?</p> <p>Sorry for the long code.</p> <pre><code>class StopWatch { public: void start() { getrusage(RUSAGE_SELF, &amp;m_begin); gettimeofday(&amp;m_tmbegin, 0); } void stop() { getrusage(RUSAGE_SELF, &amp;m_end); gettimeofday(&amp;m_tmend, 0); timeval_sub(m_end.ru_utime, m_begin.ru_utime, m_diff.ru_utime); timeval_sub(m_end.ru_stime, m_begin.ru_stime, m_diff.ru_stime); timeval_sub(m_tmend, m_tmbegin, m_tmdiff); } void printf(std::ostream&amp; out) const { using namespace std; timeval const&amp; utime = m_diff.ru_utime; timeval const&amp; stime = m_diff.ru_stime; format_time(out, utime); out &lt;&lt; "u "; format_time(out, stime); out &lt;&lt; "s "; format_time(out, m_tmdiff); } private: rusage m_begin; rusage m_end; rusage m_diff; timeval m_tmbegin; timeval m_tmend; timeval m_tmdiff; static void timeval_add(timeval const&amp; a, timeval const&amp; b, timeval&amp; ret) { ret.tv_usec = a.tv_usec + b.tv_usec; ret.tv_sec = a.tv_sec + b.tv_sec; if (ret.tv_usec &gt; 999999) { ret.tv_usec -= 1000000; ++ret.tv_sec; } } static void timeval_sub(timeval const&amp; a, timeval const&amp; b, timeval&amp; ret) { ret.tv_usec = a.tv_usec - b.tv_usec; ret.tv_sec = a.tv_sec - b.tv_sec; if (a.tv_usec &lt; b.tv_usec) { ret.tv_usec += 1000000; --ret.tv_sec; } } static void format_time(std::ostream&amp; out, timeval const&amp; tv) { using namespace std; long usec = tv.tv_usec; while (usec &gt;= 1000) usec /= 10; out &lt;&lt; tv.tv_sec &lt;&lt; '.' &lt;&lt; setw(3) &lt;&lt; setfill('0') &lt;&lt; usec; } }; // class StopWatch </code></pre>
[ { "answer_id": 26827, "author": "Mike Haboustak", "author_id": 2146, "author_profile": "https://Stackoverflow.com/users/2146", "pm_score": 2, "selected": false, "text": "static int timeval_diff_ms(timeval const& end, timeval const& start) {\n int micro_seconds = (end.tv_sec - start.t...
2008/08/23
[ "https://Stackoverflow.com/questions/24207", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1968/" ]
24,221
<p>What is the purpose of annotations in Java? I have this fuzzy idea of them as somewhere in between a comment and actual code. Do they affect the program at run time?</p> <p>What are their typical usages?</p> <p>Are they unique to Java? Is there a C++ equivalent?</p>
[ { "answer_id": 24227, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 4, "selected": false, "text": "@Override" }, { "answer_id": 24335, "author": "Eli Courtwright", "author_id": 1694, "author_profil...
2008/08/23
[ "https://Stackoverflow.com/questions/24221", "https://Stackoverflow.com", "https://Stackoverflow.com/users/142/" ]
24,241
<p>Can you use windows hooks or other methods to do code injection with c#? I've seen lots of things about code injection but all of them are done in C/C++. I don't know either of those languages and have a really hard time translating. Does anyone have any ideas on how to do this?</p>
[ { "answer_id": 39620743, "author": "unknown6656", "author_id": 3902603, "author_profile": "https://Stackoverflow.com/users/3902603", "pm_score": 2, "selected": false, "text": "IntPtr _methodPtr" } ]
2008/08/23
[ "https://Stackoverflow.com/questions/24241", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2128/" ]
24,270
<p>As far as I can tell, in spite of the countless millions or billions spent on OOP education, languages, and tools, OOP has not improved developer productivity or software reliability, nor has it reduced development costs. Few people use OOP in any rigorous sense (few people adhere to or understand principles such as LSP); there seems to be little uniformity or consistency to the approaches that people take to modelling problem domains. All too often, the class is used simply for its syntactic sugar; it puts the functions for a record type into their own little namespace.</p> <p>I've written a large amount of code for a wide variety of applications. Although there have been places where true substitutable subtyping played a valuable role in the application, these have been pretty exceptional. In general, though much lip service is given to talk of "re-use" the reality is that unless a piece of code does <em>exactly</em> what you want it to do, there's very little cost-effective "re-use". It's extremely hard to design classes to be extensible <em>in the right way</em>, and so the cost of extension is normally so great that "re-use" simply isn't worthwhile.</p> <p>In many regards, this doesn't surprise me. The real world isn't "OO", and the idea implicit in OO--that we can model things with some class taxonomy--seems to me very fundamentally flawed (I can sit on a table, a tree stump, a car bonnet, someone's lap--but not one of those is-a chair). Even if we move to more abstract domains, OO modelling is often difficult, counterintuitive, and ultimately unhelpful (consider the classic examples of circles/ellipses or squares/rectangles).</p> <p>So what am I missing here? Where's the value of OOP, and why has all the time and money failed to make software any better?</p>
[ { "answer_id": 24331, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 4, "selected": false, "text": "HANDLE" }, { "answer_id": 24361, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": ...
2008/08/23
[ "https://Stackoverflow.com/questions/24270", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2131/" ]
24,279
<p>In my second year of University we were "taught" Haskell, I know almost nothing about it and even less about functional programming.</p> <p>What is functional programming, why and/xor where would I want to use it instead of non-functional programming and am I correct in thinking that C is a non-functional programming language?</p>
[ { "answer_id": 24301, "author": "John with waffle", "author_id": 279, "author_profile": "https://Stackoverflow.com/users/279", "pm_score": 2, "selected": false, "text": "SomeKindOfRecord<T> getOrCreate(T thing) { \n if(localMap.contains(thing)) { return localMap.get(thing); }\n Som...
2008/08/23
[ "https://Stackoverflow.com/questions/24279", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1384652/" ]
24,298
<p>I'm looking for a pre-built solution I can use in my RoR application. I'm ideally looking for something similar to the ASP.NET Forms authentication that provides email validation, sign-up controls, and allows users to reset their passwords. Oh yeah, and easily allows me to pull the user that is currently logged into the application.</p> <p>I've started to look into the already written pieces, but I've found it to be really confusing. I've looked at LoginGenerator, RestfulAuthentication, SaltedLoginGenerator, but there doesn't seem to be one place that has great tutorials or provide a comparison of them. If there's a site I just haven't discovered yet, or if there is a de-facto standard that most people use, I'd appreciate the helping hand.</p>
[ { "answer_id": 741170, "author": "Brian Armstrong", "author_id": 76486, "author_profile": "https://Stackoverflow.com/users/76486", "pm_score": 7, "selected": true, "text": "has_secure_password" }, { "answer_id": 1901005, "author": "sarahhodne", "author_id": 231245, "a...
2008/08/23
[ "https://Stackoverflow.com/questions/24298", "https://Stackoverflow.com", "https://Stackoverflow.com/users/168/" ]
24,315
<p>In C# I can use the FileSystemWatcher object to watch for a specific file and raise an event when it is created, modified, etc.</p> <p>The problem I have with this class is that it raises the event the moment the file becomes created, even if the process which created the file is still in the process of writing. I have found this to be very problematic, especially if I'm trying to read something like an XML document where the file must have some structure to it which won't exist until it is completed being written.</p> <p>Does .NET (preferably 2.0) have any way to raise an event after the file becomes accessible, or do I have to constantly try reading the file until it doesn't throw an exception to know it is available?</p>
[ { "answer_id": 24429, "author": "Kibbee", "author_id": 1862, "author_profile": "https://Stackoverflow.com/users/1862", "pm_score": 3, "selected": false, "text": " Public Sub WriteToFile(ByVal FilePath As String, ByVal FileName As String, ByVal Data() As Byte)\n Dim FileOpen As Boo...
2008/08/23
[ "https://Stackoverflow.com/questions/24315", "https://Stackoverflow.com", "https://Stackoverflow.com/users/392/" ]
24,451
<p>I've long been under the impression that <code>goto</code> should never be used if possible.</p> <p>However, while perusing libavcodec (which is written in C) the other day, I was surprised to notice multiple uses of it.</p> <p>Is it ever advantageous to use <code>goto</code> in a language that supports loops and functions? If so, why? Please provide a concrete example that clearly justifies the use of a <code>goto</code>.</p>
[ { "answer_id": 24475, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 5, "selected": false, "text": "goto" }, { "answer_id": 24511, "author": "Jakub Šturc", "author_id": 2361, "author_profile": "http...
2008/08/23
[ "https://Stackoverflow.com/questions/24451", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1597/" ]
24,468
<p>When I try to run a .NET assembly (<code>boo.exe</code>) from a network share (mapped to a drive), it fails since it's only partially trusted:</p> <pre><code>Unhandled Exception: System.Security.SecurityException: That assembly does not allow partially trusted callers. at System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Assembly asm, PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh, SecurityAction action, Object demand, IPermission permThatFailed) at BooCommandLine..ctor() at Program..ctor() at ProgramModule.Main(String[] argv) The action that failed was: LinkDemand The assembly or AppDomain that failed was: boo, Version=0.0.0.0, Culture=neutral, PublicKeyToken=32c39770e9a21a67 The Zone of the assembly that failed was: Intranet The Url of the assembly that failed was: file:///H:/boo-svn/bin/boo.exe </code></pre> <p>With instructions from <a href="http://www.georgewesolowski.com/blog/PermaLink,guid,4cc5fcdf-cc68-4cf0-a083-b22a8bdc92d6.aspx" rel="nofollow noreferrer">a blog post</a>, I added a policy to the .NET Configuration fully trusting all assemblies with <code>file:///H:/*</code> as their URL. I verified this by entering the URL <code>file:///H:/boo-svn/bin/boo.exe</code> into the <em>Evaluate Assembly</em> tool in the .NET Configuration and noting that boo.exe had the <em>Unrestricted</em> permission (which it didn't have before the policy).</p> <p>Even with the permission, <code>boo.exe</code> does not run. I still get the same error message.</p> <p>What can I do to debug this problem? Is there another way to run "partially trusted" assemblies from network shares without having to change something for every assembly I want to run?</p>
[ { "answer_id": 26376, "author": "Tomi Kyöstilä", "author_id": 616, "author_profile": "https://Stackoverflow.com/users/616", "pm_score": 2, "selected": false, "text": "caspol" } ]
2008/08/23
[ "https://Stackoverflow.com/questions/24468", "https://Stackoverflow.com", "https://Stackoverflow.com/users/616/" ]
24,470
<p>Trying to find some simple SQL Server PIVOT examples. Most of the examples that I have found involve counting or summing up numbers. I just want to pivot some string data. For example, I have a query returning the following.</p> <pre><code>Action1 VIEW Action1 EDIT Action2 VIEW Action3 VIEW Action3 EDIT </code></pre> <p>I would like to use PIVOT (if even possible) to make the results like so:</p> <pre><code>Action1 VIEW EDIT Action2 VIEW NULL Action3 VIEW EDIT </code></pre> <p>Is this even possible with the PIVOT functionality?</p>
[ { "answer_id": 24538, "author": "vzczc", "author_id": 224, "author_profile": "https://Stackoverflow.com/users/224", "pm_score": 3, "selected": false, "text": "select \n distinct a,\n (select distinct t2.b from t t2 where t1.a=t2.a and t2.b='VIEW'),\n (select distinct t2.b from...
2008/08/23
[ "https://Stackoverflow.com/questions/24470", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2626/" ]
24,495
<p>I have a Struts + Velocity structure like for example, a Person class, whose one property is a Car object (with its own getter/setter methods) and it is mapped to a Velocity form that submits to an Action, using ModelDriven and getModel structure.</p> <p>I what to put a button on the form that shows "View Car" if car property is not null or car.id != 0 or show another button "Choose Car" if car is null or car.id = 0.</p> <p>How do I code this. I tried something like that in the template file:</p> <pre><code>#if($car != null) #ssubmit("name=view" "value=View Car") #else #ssubmit("name=new" "value=Choose Car") #end </code></pre> <p>But I keep getting error about Null value in the <em>#if</em> line. </p> <p>I also created a boolean method hasCar() in Person to try, but I can't access it and I don't know why.</p> <p>And Velocity + Struts tutorials are difficult to find or have good information.</p> <p>Thanks</p>
[ { "answer_id": 24510, "author": "Brian Matthews", "author_id": 1969, "author_profile": "https://Stackoverflow.com/users/1969", "pm_score": 4, "selected": true, "text": "#if($car)\n" }, { "answer_id": 64065, "author": "Nathan Bubna", "author_id": 8131, "author_profile"...
2008/08/23
[ "https://Stackoverflow.com/questions/24495", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2274/" ]
24,515
<p>Not very technical, but... I have to implement a bad words filter in a new site we are developing. So I need a "good" bad words list to feed my db with... any hint / direction? Looking around with google I <a href="http://urbanoalvarez.es/blog/2008/04/04/bad-words-list/" rel="noreferrer">found this</a> one, and it's a start, but nothing more.</p> <p>Yes, I know that this kind of filters are easily escaped... but the client will is the client will !!! :-) </p> <p>The site will have to filter out both english and italian words, but for italian I can ask my colleagues to help me with a community-built list of "parolacce" :-) - an email will do. </p> <p>Thanks for any help.</p>
[ { "answer_id": 24615, "author": "UnkwnTech", "author_id": 115, "author_profile": "https://Stackoverflow.com/users/115", "pm_score": 6, "selected": true, "text": "<?php\n\n/**\n * @author unkwntech@unkwndesign.com\n **/\n\nif($_GET['act'] == 'do')\n {\n $pattern['a'] = '/[a]/'; $replac...
2008/08/23
[ "https://Stackoverflow.com/questions/24515", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1178/" ]
24,516
<p>I'm trying to parse a grammar in ocamlyacc (pretty much the same as regular yacc) which supports function application with no operators (like in Ocaml or Haskell), and the normal assortment of binary and unary operators. I'm getting a reduce/reduce conflict with the '-' operator, which can be used both for subtraction and negation. Here is a sample of the grammar I'm using:</p> <pre><code>%token &lt;int&gt; INT %token &lt;string&gt; ID %token MINUS %start expr %type &lt;expr&gt; expr %nonassoc INT ID %left MINUS %left APPLY %% expr: INT { ExprInt $1 } | ID { ExprId $1 } | expr MINUS expr { ExprSub($1, $3) } | MINUS expr { ExprNeg $2 } | expr expr %prec APPLY { ExprApply($1, $2) }; </code></pre> <p>The problem is that when you get an expression like "a - b" the parser doesn't know whether this should be reduced as "a (-b)" (negation of b, followed by application) or "a - b" (subtraction). The subtraction reduction is correct. How do I resolve the conflict in favor of that rule?</p>
[ { "answer_id": 24589, "author": "James A. Rosen", "author_id": 1190, "author_profile": "https://Stackoverflow.com/users/1190", "pm_score": 4, "selected": true, "text": "expr" }, { "answer_id": 7678584, "author": "Chris Dodd", "author_id": 16406, "author_profile": "htt...
2008/08/23
[ "https://Stackoverflow.com/questions/24516", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1891/" ]