instruction
stringlengths
21
27.8k
chosen
stringlengths
18
28.2k
rejected
stringlengths
18
33.6k
__index_level_0__
int64
0
50k
<p>What strategies have you used with Model Based Testing?</p> <ul> <li>Do you use it exclusively for integration testing, or branch it out to other areas (unit/functional/system/spec verification)? </li> <li>Do you build focused "sealed" models or do you evolve complex onibus models over time?</li> <li>When in the p...
<p>[There are several essays worth reading on this. Stack Overflow won't let me post more than one, so I've aggregated them in a blog post, linked at the end of this answer.]</p> <p>First, a quick note on terms. I tend to use James Bach’s definition of Testing as “Questioning a product in order to evaluate it”. All te...
<p>The best way is to try by yourself a Model based testing tool. It's the best way for know if the model based testing is adapted in your context. And what sort of strategies is the good one.</p> <p>I advise you the "MaTeLo" tool of All4Tec (www.all4tec.net)</p> <p>"MaTeLo is a test cases generator for black box fun...
4,565
<p>I am calling an unmanaged C++ dll that expects a char* as one of its parameters and I want to push a byte[] into it. The project is written in VB.NET. </p> <p>What type of marshalling will work for this?</p>
<p>If you need to pin a managed structure in order to pass it as a parameter you can use the following code.</p> <pre><code> // (c) 2007 Marc Clifton /// &lt;summary&gt; /// A helper class for pinning a managed structure so that it is suitable for /// unmanaged calls. A pinned object will not be collect...
<p>I'm not a .net expert, but I've needed to do something similar recently.</p> <p>It is not just a matter of serialization, you also have to stop the garbage collector from cleaning up your byte array while it is being used in C++ land...</p> <p>The below snippet of C# should help.</p> <pre>// pin the byte[] (byteA...
33,105
<p>Nowadays, we have tons of Javascript libraries per page in addition to the Javascript files we write ourselves. How do you manage them all? How do you minify them in an organized way? </p>
<p><strong>Organization</strong></p> <p>All of my scripts are maintained in a directory structure that I follow whenever I work on a site. The directory structure normally goes something like this:</p> <pre><code>+--root |--javascript |--lib |--prototype.js |--scriptaculous |--s...
<p>I'v been using this lately: <a href="http://code.google.com/apis/ajaxlibs/" rel="nofollow noreferrer">http://code.google.com/apis/ajaxlibs/</a></p> <p>And then have a "jscripts" folder where I keep my custom code. </p>
26,985
<p>We have been asked to look into a fully open source solution for a big project, they want the project be as near to 100% Open Source as possible, mainly because as it's a community project there may be very little money available in the future except for the running of a host. Using OS software saves on licence cost...
<p>"True" .NET only runs on Windows. However, the <a href="http://www.mono-project.com/Main_Page" rel="nofollow noreferrer">Mono project</a> allows applications written for .NET to run on Linux (and other platforms) so long as there aren't any compatibility issues. Mono has a <a href="http://www.mono-project.com/MoMA" ...
<p>Further to some previous answers; some other Mono details:</p> <p><li>Currently the compiler targeting .NET 2.0 and 3.5 is <a href="http://mono-project.com/Languages" rel="nofollow noreferrer">NOT the default compiler</a>. To me this suggests an immature platform. If you're starting out a new project, being able ...
49,051
<p>I've inherited a rather large application that really could use some cleanup. There is data access code littered throughout the application. In code behinds, some in business logic classes, some inline in in classic asp pages. </p> <p>What I'd like to do is refactor this code, removing all the data access code into...
<p>If you have access to .NET Framework 3.5 and Linq to SQL, you can do it very easily, check this video:</p> <p><a href="http://weblogs.asp.net/scottgu/archive/2007/08/16/linq-to-sql-part-6-retrieving-data-using-stored-procedures.aspx" rel="nofollow noreferrer">LINQ to SQL: Using Stored Procedures</a></p> <blockquot...
<p>dragging and dropping the stored procedures onto a dataset design surface (in .net 2.0 and higher) generates a wrapping function</p> <p>but if you have a lot of them to do, you might be better off using or writing a simple code generator</p> <p>two options for this: </p> <ol> <li>generate the wrapping code yours...
36,825
<p>I often have trouble with prints being especially difficult to remove from the build plate on my Micro3D printer. My wife suggested using a hair dryer on the underside of the plate. I was initially appalled at the idea, but now I think she may be on to something. Is this safe? Good idea? Bad idea? Heresay?</p>
<p>Typically, people <em>cool down</em> their build plates to get parts to release, rather than heat them up. That said, I doubt a hair drier will get hot enough to do any damage to the build plate. You could try it with no harm done.</p>
<p>cold wind can help to acceleratory cool down and dry the build plates to make it easy to part them.</p>
352
<p>I am trying to optimize some stored procedures on a SQL Server 2000 database and when I try to use SQL Profiler I get an error message "In order to run a trace against SQL Server you have to be a member of sysadmin fixed server role.". It seems that only members of the sysadmin role can run traces on the server (som...
<p>That's what cronjobs are made for. <code>man crontab</code> assuming you are running a linux server. If you don't have shell access or no way to setup cronjobs, there are free services that setup cronjobs on external servers and ping one of your URLs.</p>
<p>Command line PHP + cron would be the way I would go. It's simple and should fit the bill. It is usually installed with PHP as a matter of course.</p>
14,625
<p>I need to configure Tomcat memory settings as part of a larger installation, so manually configuring tomcat with the configuration app after the fact is out of the question. I thought I could just throw the JVM memory settings into the JAVA_OPTS environment variable, but I'm testing that with jconsole to see if it w...
<p>Serhii's suggestion works and here is some more detail.</p> <p>If you look in your installation's bin directory you will see catalina.sh or .bat scripts. If you look in these you will see that they run a setenv.sh or setenv.bat script respectively, if it exists, to set environment variables. The relevant environm...
<p>Just edit your your catalina/bin/startup.sh script. Add the following commands in it: </p> <pre><code>#Adjust it to the size you want. Ignore the from bit. export CATALINA_OPTS="-Xmx1024m" #This should point to your catalina base directory export CATALINA_BASE=/usr/local/tomcat #This is only used if you editing th...
36,331
<p>I want to delete all but the 4 newest directories in my parent directory. How would you do this in Bash?</p>
<pre><code>ls -atrd */ | head --lines=-4 | xargs rm -rf </code></pre> <p><strong>Edit:</strong> added 'a' argument to ls</p>
<p>Another, BSD-safe, way to do it, with arrays (why not?)</p> <pre><code>#!/bin/bash ARRAY=( `ls -td */` ) ELEMENTS=${#ARRAY[@]} COUNTER=4 while [ $COUNTER -lt $ELEMENTS ]; do echo ${ARRAY[${COUNTER}]} let COUNTER=COUNTER+1 done </code></pre>
9,743
<p>I have a function that takes another function as a parameter. If the function is a member of a class, I need to find the name of that class. E.g.</p> <pre><code>def analyser(testFunc): print testFunc.__name__, 'belongs to the class, ... </code></pre> <p>I thought </p> <pre><code>testFunc.__class__ </code></...
<pre><code>testFunc.im_class </code></pre> <p><a href="https://docs.python.org/reference/datamodel.html#the-standard-type-hierarchy" rel="nofollow noreferrer">https://docs.python.org/reference/datamodel.html#the-standard-type-hierarchy</a></p> <blockquote> <p><code>im_class</code> is the class of <code>im_self</cod...
<p>Please use following function to get method names inside of a class </p> <pre><code>def getLocalMethods(clss): import types # This is a helper function for the test function below. # It returns a sorted list of the names of the methods # defined in a class. It's okay if you don't fully understand it! result = [ ]...
39,359
<p>What criteria should I use to decide whether I write VBA code like this:</p> <pre><code>Set xmlDocument = New MSXML2.DOMDocument </code></pre> <p>or like this:</p> <pre><code>Set xmlDocument = CreateObject("MSXML2.DOMDocument") </code></pre> <p>?</p>
<p>As long as the variable is not typed as object</p> <pre><code>Dim xmlDocument as MSXML2.DOMDocument Set xmlDocument = CreateObject("MSXML2.DOMDocument") </code></pre> <p>is the same as</p> <pre><code>Dim xmlDocument as MSXML2.DOMDocument Set xmlDocument = New MSXML2.DOMDocument </code></pre> <p>both use early bi...
<p>For the former you need to have a reference to the type library in your application. It will typically use early binding (assuming you declare your variable as MSXML2.DOMDocument rather than as Object, which you probably will), so will generally be faster and will give you intellisense support.</p> <p>The latter c...
20,528
<p>I'm trying to find a way of applying graphics to my ABS printed parts. </p> <p>I need a robust method which can produce a decent amount of detail with true color and legible fine text . I also was hoping to avoid the use of stickers and opt for something that's slightly more permanent. </p> <p>I was wondering if t...
<p>Industry has for years used a 'pad printer' to put images on complex shapes, like plastic or ceramic travel mugs, etc.</p> <p>I have observed these, but never used one. I see no reason why there couldn't be a DIY version made.</p> <p>Best of luck, and I look forward to seeing what you come up with!</p>
<p>You really can't. That said the only group that has this kind of tech is .. Disney of all companies. That said their tech is good at simple shapes. Nothing more.</p> <p>I have seen some hydro transfer techniques. However that will not let you position a graphic as it is all done with a stretch transfer material ont...
349
<p>Is there a catchall function somewhere that works well for sanitizing user input for SQL injection and XSS attacks, while still allowing certain types of HTML tags?</p>
<p>It's a common misconception that user input can be filtered. PHP even has a (now deprecated) &quot;feature&quot;, called <a href="https://www.php.net/manual/en/security.magicquotes.php" rel="noreferrer">magic-quotes</a>, that builds on this idea. It's nonsense. Forget about filtering (or cleaning, or whatever people...
<p>There is the filter extension (<a href="http://devolio.com/blog/archives/413-Data-Filtering-Using-PHPs-Filter-Functions-Part-one.html" rel="nofollow noreferrer">howto-link</a>, <a href="http://php.net/filter" rel="nofollow noreferrer">manual</a>), which works pretty well with all GPC variables. It's not a magic-do-i...
15,760
<p>I have a few longtables that stretch several pages and I want to use pageref and hyperref to link to these rows.</p> <p>But whatever I try, the links always refer to the start of the table. When I look into the aux file, the labels all seem to be re-defined into table.[number of table].</p> <p>I tried putting invi...
<p>I solved this problem by introducing a custom counter and label command:</p> <pre><code>\newcounter{mycounter} \newcommand{\mylabel}[1]{\refstepcounter{mycounter} \label{#1}} </code></pre>
<p>According to <a href="http://newsgroups.derkeiler.com/Archive/Comp/comp.text.tex/2008-05/msg01417.html" rel="nofollow noreferrer">This article</a> and <a href="http://www.ctan.org/tex-archive/macros/latex/contrib/hyperref/" rel="nofollow noreferrer">The readme for Hyperref</a> you need to include the Hyperref packag...
38,705
<p>I want to create dynamic content based on this. I know it's somewhere, as web analytics engines can get this data to determine how people got to your site (referrer, search terms used, etc.), but I don't know how to get at it myself.</p>
<p>You can use the "referer" part of the request that the user sent to figure out what he searched for. Example from Google:</p> <blockquote> <p><a href="http://www.google.no/search?q=stack%20overflow" rel="nofollow noreferrer">http://www.google.no/search?q=stack%20overflow</a></p> </blockquote> <p>So you must sear...
<p>This is some code to backup the idea of using a querystring method and if that's not available using the UrlReferrer property of the Request object. This can then be stashed in a session object (or somewhere else if that works better for you) so that you can track the source between pages. (Page_Load doesn't seem to...
8,120
<p>Suppose A.css styles B.html. What tools/techniques are there to programmatically reduce the size of A.css while holding its styling effects on B.html constant? Here are some techniques I would imagine such a tool using:</p> <ol> <li><p><strong>Remove redundancies in A.css.</strong> For example, if the same class is...
<p>Generally you just remove all unnecessary whitespace. Remember to keep the original as well, so you don't lose readability when editing the site later.</p>
<p>Unless you have an usually large CSS file, I would opt for readability and modifiability of the CSS file rather than having a smaller CSS file. Since CSS files are static (for the most part), most browsers will do a really good job of caching them. While all your suggestions are good ones, combining things that a...
25,616
<p>During our build process we run <code>aspnet_compiler.exe</code> against our websites to make sure that all the late-bound stuff in ASP.NET/MVC actually builds (I know nothing about ASP.NET but am assured this is necessary to prevent finding the failures at runtime).</p> <p>Our sites are fairly large in size, with ...
<ol> <li>Compiler should generate second code-behind file for every .aspx page, <a href="http://webproject.scottgu.com/CSharp/UnderstandingCodeBehind/UnderstandingCodeBehind.aspx" rel="nofollow noreferrer" title="check">check</a></li> <li>During compilation, aspnet_compiler.exe will copy ALL of the web site files to th...
<p>Just my 2 cents.</p> <p>One of the things slowing down ASP.NET views precompilation significantly is the <code>-fixednames</code> command line option for <code>aspnet_compiler.exe</code>. <strong>Do not use it</strong> especially if you're on Razor/MVC.</p> <p>When publishing the wep app from Visual Studio make su...
36,927
<p>Given a heapdump or a running VM, how do I discover what the contents of the permanent generation is ? I know about 'jmap -permstat' but that's not available on Windows.</p>
<p>The permanent generation contains the class object. So you should check the heap dump or other form of object list for classes. If you have problem with the size of permanent generation usually it is caused by two reason:</p> <ul> <li>your program or a library you use creates classes dynamically and the default si...
<p>you can use JConsole or jvisualvm.exe(with jdk 1.6 7) to find what is where. If you want to know how all of your objects are related to each other and tree of objects, then you might want to try Eclipse Memory Analyzer -- <a href="http://www.eclipse.org/mat/" rel="nofollow noreferrer">http://www.eclipse.org/mat/</a>...
23,619
<p>I am writing some software to identify tracking numbers (in the same way that Google identifies FedEx or UPS numbers when you search for them). Most couriers use a system, such as a "weighted average mod system" which can be used to identify if a number is a valid tracking number. Does anyone know if TNT consignment...
<p>OK, so it's three months since you asked but I stumbled across this as I'm writing a similar piece of software. As far as we know TNT uses the <a href="http://en.wikipedia.org/wiki/S10_(UPU_standard)" rel="nofollow noreferrer">S10</a> tracking number system. Which means that their numbers will be of the type AA#####...
<p>As far as I can tell, there isn't one. Sorry.</p> <p>I take it you're trying to validate the tracking number entered to make sure it was entered properly?</p> <p>-- Kevin Fairchild</p>
8,124
<p>I have a set of mercurial repositories being served online with hgwebdir.cgi. I would like to be able to show a graphical representation of the branches and merges in the same way that <a href="http://hg.serpentine.com/mercurial/book/graph" rel="nofollow noreferrer">this site</a> does. I can't seem to find any refer...
<p>Until version 1.1 comes out (in a few days) you'd need to clone and install from the <a href="http://hg.intevation.org/mercurial/crew/" rel="nofollow noreferrer">Mercurial crew respository</a></p>
<p>This future will be enabled in next release, try use develop version from repo.</p> <p>In console u can use <a href="http://www.selenic.com/mercurial/wiki/index.cgi/GraphlogExtension" rel="nofollow noreferrer">glog extension</a></p>
34,364
<p>I'm using the .NET TWAIN code from <a href="http://www.codeproject.com/KB/dotnet/twaindotnet.aspx?msg=1007385#xx1007385xx" rel="nofollow noreferrer">http://www.codeproject.com/KB/dotnet/twaindotnet.aspx?msg=1007385#xx1007385xx</a> in my application. When I try to scan an image when the scanner is not plugged in, th...
<p>Maybe I'm taking the question too literally, but using the TWAIN API, it is not possible to check if a device is plugged in i.e. connected and powered on. The TWAIN standard does define a capability for this purpose called CAP_DEVICEONLINE, but this feature is so poorly conceived and so few drivers implement it cor...
<p>i try do this but dont work good with TWAIN mybe try WIA </p> <p>mybe try this:</p> <p>on buton run scanner </p> <pre><code>timer1.Interval = 30000; switch (cmd) { case TwainCommand.TransferReady: { .......... } default: { timer1.Start(); break; } </code></pre> <p>on event timer tick </p> <pre><code>{ Endin...
12,556
<p>If you know the local path and file name of the file you want the end user to upload (via browser). Then is it possible to pre-set these properties for the HTML file input element (or any upload control)? So when the user clicks 'browse' to select the file to upload, then the dialog has preselected the filename.</p>...
<p>Unless it is a custom upload control, this cannot be done for security reasons. </p> <p>If a html page could set the file to be uploaded using javascript, for instance, an arbitrary html page could upload any file from the client computer (form submission can be triggered via javascript)</p>
<p>This type of interaction with file-upload controls is disabled for security reasons.</p>
45,657
<p>What are differences between CallContext and ThreadStatic?</p> <p>I've understood that in an ASP.NET environment data stored in CallContext could be persisted throughout the request until it ends while ThreadStatic may or may not work since the request may switch threads. I've also learned that the HttpContext is i...
<p>Very often a request will use the same thread throughout, but it certainly won't always be the case - ASP.NET exhibits <em>thread agility</em>. There's an old <a href="http://piers7.blogspot.com/2005/11/threadstatic-callcontext-and_02.html" rel="nofollow noreferrer">in-depth blog article about the matter</a> from 20...
<p>Items stored as ThreadStatic are available to more than one request. IIS reuses the thread after a request is complete to process subsequent requests, it can even swap a request from one thread to another during processing. ASP.Net clears down the CallContext after each request.</p>
34,427
<p>I have been seriously disappointed with WPF validation system. Anyway! How can I validate the complete form by clicking the "button"? </p> <p>For some reason everything in WPF is soo complicated! I can do the validation in 1 line of code in ASP.NET which requires like 10-20 lines of code in WPF!!</p> <p>I can do t...
<p>A WPF application should disable the button to submit a form iff the entered data is not valid. You can achieve this by implementing the <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.idataerrorinfo.aspx" rel="noreferrer">IDataErrorInfo</a> interface on your business object, using Bindings wi...
<p>The description of your problem is a little vague to me. I mean, I'm not exactly sure what your difficulty is. Assuming that the DataContext is some sort of presenter or controller that has a propetry representing the customer instance, and ValidateCommand is a property of type ICommand:</p> <pre><code> &lt;StackP...
13,012
<p>Need to an expression that returns only things with an "I" followed by either a "J" or a "V" (No Quotes) and then a minimum of 1 number up to 3 numbers.</p> <p>I J### <br /> I V### <br /> I J## <br /> I V## <br /> I J# <br /> I v# <br /></p>
<p>Depends on your flavor</p> <pre><code>I(J|V)[0-9]{1,3} </code></pre> <p>Do you also need a space after an "I"?</p> <pre><code>I (J|V)[0-9]{1,3} </code></pre>
<p>I think the others missed the <code>v#</code> spec. </p> <pre><code>I[JVv]\d{1,3} </code></pre> <p>Of course perhaps the lowercase <code>v</code> was a typo.</p>
39,933
<p>How can I make my <code>std::fstream</code> object start reading a text file from the second line?</p>
<p>Use getline() to read the first line, then begin reading the rest of the stream.</p> <pre><code>ifstream stream("filename.txt"); string dummyLine; getline(stream, dummyLine); // Begin reading your stream here while (stream) ... </code></pre> <p>(Changed to std::getline (thanks dalle.myopenid.com))</p>
<pre><code>#include &lt;fstream&gt; #include &lt;iostream&gt; using namespace std; int main () { char buffer[256]; ifstream myfile ("test.txt"); // first line myfile.getline (buffer,100); // the rest while (! myfile.eof() ) { myfile.getline (buffer,100); cout &lt;&lt; buffer &lt;&lt; endl; }...
19,866
<p>I have a pivot table on an olap cube. I can go into a page field and manually deselect multiple items. How can I do this in VBA based on a list of items I need excluded? (n.b. I do not have a corrresponding list of items I need included)</p> <p>I know how to exclude these items in other ways, by altering the underl...
<p>You do not have to run an MDX query to list the members of a dimension, you can look at the properties of the cube object in VBA. Start with this and see where it gets you!</p> <p>Set oCat = New ADOMD.Catalog</p> <p>loop through this for example: oCat.CubeDefs(sCube).Dimensions(3).Hierarchies(0).Levels(2).Mem...
<p>I apologize for this example being in C#, but I really don't know enough VBA to translate it (perhaps someone can edit this entry and add it below).</p> <p>Are you refering to something like this?</p> <pre><code>((MOE.PivotField)pivotTableObject.PivotFields("[NAME]")).Delete(); </code></pre> <p>Where MOE is the M...
12,664
<h2><strong>Edit: I have solved this by myself. See <a href="https://stackoverflow.com/questions/145241/change-the-value-of-a-text-box-to-its-current-order-in-a-sortable-tab/145388#145388">my answer below</a></strong></h2> <p>I have set up a nice sortable table with jQuery and it is quite nice. But now i want to extend...
<p>Hardnrg in #jquery ended up solving it for me.</p> <p>It involved adding an id="" to each input:</p> <pre><code>&lt;form name="productform"&gt; &lt;table cellspacing="0" id="table-2" name="productform"&gt; &lt;thead&gt; &lt;tr&gt;&lt;td&gt;Product&lt;/td&gt; &lt;td&gt;Order&lt;/td&gt;&l...
<p>Hmmm.. I think you want to do something like this:</p> <pre><code>$("input:text", "#table-2").each( function(i){ this.value=i+1; }); </code></pre> <p>The $().each() function's info is here: <a href="http://docs.jquery.com/Core/each" rel="nofollow noreferrer">http://docs.jquery.com/Core/each</a></p>
17,510
<p>I know it's bad to use HTML Tables for everything... and that tables should be used only to present tabular data and not to achieve some style goal. </p> <p>My question is, how do you make HTML forms with CSS so they look nice and aligned like when using tables?</p>
<p>Nick Rigby wrote an excellent article for A List Apart titled <a href="http://www.alistapart.com/articles/prettyaccessibleforms/" rel="noreferrer">Prettier Accessible Forms</a></p> <p>Uses fieldset, legend, label. Highly semantic.</p>
<p>I would lookup using the div tag to layout data on a page.</p> <p>Tables are still very much useful for tabular data, but its frowned upon for laying out a page.</p> <p>View source here on stackoverflow.com, there's probably some good examples.</p>
21,701
<p>Date coming out of a database, need to format as "mm/dd/yy"</p> <pre><code>For Each dr as DataRow in ds.Tables(0).Rows Response.Write(dr("CreateDate")) Next </code></pre>
<pre><code>string.Format( "{0:MM/dd/yy}", dr("CreateDate") ) </code></pre> <p>Edit: If dr("CreateDate") is DBNull, this returns "".</p>
<pre><code>Response.Write(DateTime.Parse(dr("CreateDate").ToString()).ToString("MM/dd/yyyy")) </code></pre>
15,615
<p>The only thing I've found has been;</p> <pre class="lang-css prettyprint-override"><code>.hang { text-indent: -3em; margin-left: 3em; } </code></pre> <p>The only way for this to work is putting text in a paragraph, which causes those horribly unsightly extra lines. I'd much rather just have them in a <cod...
<p><code>&lt;span&gt;</code> is an inline element. The term <em>hanging indent</em> is meaningless unless you're talking about a paragraph (which generally means a block element). You can, of course, change the margins on <code>&lt;p&gt;</code> or <code>&lt;div&gt;</code> or any other block element to get rid of extra ...
<p>ysth's answer is best with one debatable exception; the unit of measure should correspond to the size of the font.</p> <pre class="lang-css prettyprint-override"><code>p { text-indent: -2en; padding-left: 2en; } </code></pre> <p>"3" would also work adequately well; "em" is not recommended as it is wider than ...
3,293
<p>How can I bind an array parameter in the HQL editor of the HibernateTools plugin? The query parameter type list does not include arrays or collections.</p> <p>For example:<br> <code>Select * from Foo f where f.a in (:listOfValues)</code>.<br> How can I bind an array to that listOfValues?</p>
<p>You probably cannot. Hibernate replaces the objects it gets out of the database with it's own objects (kind of proxies). I would strongly assume Hibernate cannot do that with an array. So if you want to bind the array-data put it into a List on access by Hibernate.</p> <p>As an example one could do:</p> <pre><code...
<p>I am sure you have already got the answer for this but for anyone else viewing this. it appears that the HQL editor for hibernate tools does not support querying collections. you whould have to not use the parameter and hard code it while testing in the Hibernate Tools HQL editor </p> <pre><code>Select * from Foo...
12,025
<p>My company makes its money off of a great user experience using IE6, 7, Firefox and Safari. 90% of our traffic ends up IE and probably 60% of that traffic is still IE6. IE6 has a bunch of known gotcha's such as accessing DOM objects while they are still being inserted crashing the browser. Almost none of these is...
<p>We don't worry about it. Instead, we use a third party tool like jQuery (well, <strong>EXACTLY</strong> like jQuery in our company) to ensure cross-platform idiosyncrasies are handled.</p>
<blockquote> <p>Beleive it or not some of jQuery (and other libraries) functions don't work on all browsers.</p> </blockquote> <p>Ofcourse, if you relate to IE5 or NN4, jQuery may not be the best pick. Otherwise, you won't have a problem with this. I use jQuery for a HUGE site and i don't have problems with libr...
41,738
<p>I've created a dtsx package with Sql Server Business Intelligence Development studio, and I am executing it using the dtexec utility. Using dtexec I am setting certain properties at runtime using the /set switch. So my command looks something like:</p> <pre><code>dtexec /f "mypackage.dtsx" /set \Package.Connection...
<p>This steps is for creating an XML configuration file (.dtsConfig) which can keep your sensitive data, like the password of your connection string, without having a Protection Level that can make you difficult to move the package from one machine to another.</p> <p>In this example, assumed you have an OLE DB Connect...
<p>Here are the guidelines from MSDN about package security. <a href="http://msdn.microsoft.com/en-us/library/ms141747.aspx" rel="nofollow">Setting the Protection Level of Packages</a></p>
32,932
<p>At work I work closely with MS-Office. I have managed to generate some scripts that perform various tasks. While I can port functions to VBA with some difficulty, I do not fully understand the foundations of the VBA language.</p> <p>Items for which I seek basic syntax and examples include: 'hello world' program, lo...
<p>The versions of VBA post Office 2000 are almost identical to VB6. This <a href="http://msdn.microsoft.com/en-us/vbasic/ms789086.aspx" rel="nofollow noreferrer">MSDN site</a> is a great place to start. The <a href="http://msdn.microsoft.com/en-au/vbrun/default.aspx" rel="nofollow noreferrer">VB6 resource center</a> ...
<p>I think you will find this video tutorial pretty helpful:</p> <p><a href="http://developresource.weebly.com/10/post/2011/11/vba.html" rel="nofollow">http://developresource.weebly.com/10/post/2011/11/vba.html</a></p> <p>And there are some other great stuffs you can find there so have a try :)</p>
37,301
<p>How would I drag and drop something into a static control? It looks like I need to create a sub class of COleDropTarget and include that as a member variable in a custom CStatic. That doesn't appear to be working though. When I try and drag something onto the Static control I get the drop denied cursor.</p>
<p>The static control's <code>m_hWnd</code> must be valid when you call <code>COleDropTarget::Register</code>, which is why it doesn't work from within your <code>CMyStatic</code> constructor. What you can do is override <code>CWnd::PreSubclassWindow</code> within your <code>CMyStatic</code> class:</p> <pre><code>clas...
<p>In addition to the PreSubClassWindow() addition, you also have to set your CStatic control to have the Notify flag set in its resource parameters. Otherwise the control won't let the app know about mouse movements and hence not trigger the OnDragEnter() method.</p>
25,716
<p>I have got the following situation. On a machine there is a <strong>Fritz ISDN</strong> card. There is a process that is responsible for playing a certain wave file on this device's wave out (<strong>ISDN</strong> connection is made at startup and made persistent). The scenario is easy, whenever needed the process c...
<p>I don't have the time to Google too much for this, but I know that either Larry Osterman or Raymond Chen blogged about a similar situation.</p> <p>I'll check back later when I have more time to see if this question is still open.</p>
<p>What is the return value when the sound does not play? If you get MMSYSERR_NOERROR that points to the driver incorrectly reporting to the OS that the buffer was processed.</p> <p>Has the WAV file itself changed? This <a href="http://blogs.msdn.com/larryosterman/archive/2007/07/24/playsound-is-failing-on-vista-what-...
3,101
<p>I'm creating a low level keyboard hook in c# using SetWindowsHookEx, question is how can I make the on keyboard event function run on a thread other from the main thread? Also I currently don't have a thread other then the main thread, so how can I create one that will halt until a keyboard hook event will occur?</p...
<p>Here is the code for the <a href="http://forum.cheatengine.org/viewtopic.php?t=192699&amp;sid=d25bb4a9d48a3518bba28ec63d6510a2" rel="nofollow noreferrer">C# Keyboard hook</a>.</p> <p>You just need to call Hook.CreateHook(METHODNAMEHERE); in a new Thread (see the Thread class).</p>
<p>As there is an answer how to set a hook on new thread, this only answers the second part of the question:</p> <p>If you are using a windows form application, there are some catches in using additional threads. They need to use Control.Invoke to communicate with the form controls.</p> <p>Other than that, start your...
21,509
<p>I've been playing with mod_python in apache2 which seems to work differently than python does in general - there's a bit different syntax and things you need to do. It's not very well documented and after a few days of playing with it, I'm really not seeing the point of mod_python at all, especially when things like...
<ol> <li>Don't use mod_python. A common mistake is take mod_python as "mod_php, but for python" and that is <strong>not true</strong>. Use <a href="http://code.google.com/p/modwsgi/" rel="noreferrer">mod_wsgi</a> instead.</li> <li>Choose a web framework. <a href="http://cherrypy.org/" rel="noreferrer">CherryPy</a>. <a ...
<p>mod_python wasn't really made for doing basic webprogramming. I suggest you go with a framework:</p> <ul> <li><a href="http://www.djangoproject.com/" rel="noreferrer">django</a></li> <li><a href="http://cherrypy.org" rel="noreferrer">cherrypy</a></li> <li><a href="http://webpy.org" rel="noreferrer">web.py</a></li>...
26,530
<p>Here's a hypothetical situation I've been wondering about lately. Suppose I have an interactive page created in ASP.NET and Ajax that I want multiple users to be able to manipulate at the same time. What would be the best way to maintain this page's state? Especially if the page was relatively ephemeral, and did ...
<p>I beleive there are a few ways you can do this: 1) Stream the pdf binary data to the browser and change the mime type so the browser handles it as pdf, or 2) Stream the pdf bindara data to the broswer using the "attachment;file=" header which will cause the browser to give you the option of opening or saving the f...
<p>What headers are you serving up with the PDF? IE has issues with downloadable files if the cache headers are set to no-cache, and (although) I doubt this is the issue, IE can't handle very large downloads (e.g. 2.x Gig)</p>
21,259
<p>Using .NET 1.1, I have a DataGrid that contains three columns for each row. </p> <p>Row one has a label with some text.</p> <p>Row three will always have two radio buttons and two checkboxes and those are in the HTML side of the page.</p> <p>Row two will have dynamically generated controls (just textboxes for now...
<p>Remember: every time a postback occurs you are working with a <em>new instance</em> of your page class. Dynamic controls added to the page during a previous postback went to the garbage collector as soon as the page for that postback rendered to the browser, along with the rest of that page instance. You need to ...
<p>you have to regenerate the controls. You should be able to get their values from the http request object</p>
24,570
<p>I have an application that has several objects (about 50 so far, but growing). There is only one instance of each of these objects in the app and these instances get shared among components.</p> <p>What I've done is derive all of the objects from a base BrokeredObject class:</p> <pre><code>class BrokeredObject { ...
<p>Yes, there is a way. A pretty simple even in C++ to what that C# code does (without checking for inheritance though):</p> <pre><code>template&lt;typename T&gt; BrokeredObject * GetOrCreateObject() { return new T(); } </code></pre> <p>This will work and do the same as the C# code. It is also type-safe: If the typ...
<p>You should almost certainly be using dependency injection.</p>
47,454
<p>I have a small command line program that uses the Team System API. When the correct Team System isn't installed on the machine, the program prints a traceback with System.IO.FileNotFoundException, but it also <strong>crashes</strong> and shows the standard error messasge:</p> <blockquote> <p>XXX has encountered a...
<p>.NET code is JITted on a method-by-method basis. Does your "Main" method make reference to the external libraries? If so, consider:</p> <pre><code>[MethodImpl(MethodImplOptions.NoInlining)] static int Main() { // add "args" etc if needed try { return Main2(); } catch (Exception ex) { Console...
<p>Yes. The assembly will be loaded the first time you use a type that itself references a type from the assembly to be loaded. </p> <p>So the solution is to create a helper class that wraps all interaction with the API. Then wrap calls to this wrapper class in a try/catch.</p> <p>Something like:</p> <pre><code>p...
26,419
<p>If you use a GUID as a password for a publicly facing application as a means to gain access to a service, is this security through obscurity?</p> <p>I think the obvious answer is yes, but the level of security seems very high to me since the chances of guessing a GUID is very very low correct?</p> <p><b>Update</b>...
<p>Actually, using a GUID as a password is not a good idea (compared to coming up with a truly random password of equivalent length). Although it appears long, it's actually only 16 bytes which typically includes the user's MAC address, the date/time and a smallish random element. If a hacker can determine the users M...
<p>I recommend against using a GUID as a password (except maybe as an initial one to be changed later). Any password that has to be written down to be remembered is <strike>inherently</strike> unsafe. It will get written down.</p> <p><strong>Edit:</strong> "inherently" is inaccurate. see conversation in comments</p>
37,017
<p>In Vc++ 6.0 mscomm control,please any body explain this function How it works ,what it does</p> <pre><code>if (m_comm.GetCommEvent()==2 ) { VARIANT in_dat; in_dat = m_comm.GetInput(); CString strInput(in_dat.bstrVal); m_input = m_input + strInput; ...
<p>The code checks whether a comm event occured. If it did, then the input data is obtained from the control and appended to m_input. Afterwards, the data is updated.</p> <p>The code does not offer much more insight.</p>
<p>Just in case you don't know, "the data is updated" in HS' post means 'the dialog box fields are updated to show the new data'</p>
41,811
<p>Is there a difference between just saying <code>throw;</code> and <code>throw ex;</code> assuming <code>ex</code> is the exception you're catching?</p>
<p><code>throw ex;</code> will erase your stacktrace. Don't do this unless you mean to clear the stacktrace. Just use <code>throw;</code></p>
<p>You have two options throw; or throw the orginal exceptional as an innerexception of a new exception. Depending on what you need.</p>
11,415
<p>Suppose a database table has a column "Name" which is defined as key for the table. Usual name values will be "Bill", "Elizabeth", "Bob", "Alice". Lookups on the table will be done by the name key as well.</p> <p>Does hashing the values optimize the operations in any way? i.e. entering each name as some hashed valu...
<p>Assuming your database generates an index for the primary key (and I can't imagine it wouldn't) it's doing it for you. So yes, it should absolutely be something that the database handles.</p>
<p>No, don't hash them. Your database will build an index based on the data, and hashing won't help. The only time it <em>might</em> help is if your key values were much longer than the hash.</p>
27,938
<p>A number of forms in my project inherit from a base form. It is easy to get at the Controls collection of the derived forms, but I have not found a simple way to access the Components collection, since VS marks this as private. </p> <p>I assume this could be done with reflection, but I'm not really sure how best to...
<p>If you set the Modifiers property of your components to strict protected makes them accessible without the use of a components collection. </p> <p>Edit: Discoverability could be done using reflection to walk over each field. Although that might be suboptimal in your case.</p>
<p>If you're worried about forgetting to override the function, then make it abstract.</p>
5,104
<p>I have this legacy code base <strong>(Compaq PERL)</strong>, about 1500 lines of code, that I need to port to Windows. I wanted to use <strong>gnu PASCAL</strong> (which I have installed and have working). I have already got our assembler <strong>(HP 64000 8051)</strong> off the VAX and on to <strong>Windows (KEIL 8...
<p>I would try to port it to <a href="http://www.freepascal.org/" rel="nofollow noreferrer">Free Pascal</a>, but with a time limit. If it's too hard, then fall back to a more recently used (by you) language.</p> <p>Is there any way to test if the new (ported or translated) version behaves the same as the old one?</p>
<p>I think porting 1500 lines of code to any language/platform should not be too hard given the fact that all you need to do is "perform fills" and compute checksums. Personally I would have preferred C# - it has a soothing effect on my mind :) but given your proficiency in C/C++ I would advise that you go with C++ for...
45,148
<p>I'd like to have some rails apps over different servers sharing the same session. I can do it within the same server but don't know if it is possible to share over different servers. Anyone already did or knows how to do it?</p> <p>Thanks</p>
<p>Depending on how your app is set up, you <em>can</em> easily share cookies from sites in the same domain (foo.domain, bar.domain, domain) by setting your apps up to use the same secret: <a href="http://www.russellquinn.com/2008/01/30/multiple-rails-applications/" rel="nofollow noreferrer">http://www.russellquinn.com...
<p>Try using database-backed sessions.</p>
13,041
<p>When developing whether its Web or Desktop at which point should a developer switch from SQLite, MySQL, MS SQL, etc</p>
<p>It depends on what you are doing. You might switch if:</p> <ul> <li>You need more scalability or better performance - say from SQLite to SQL Server or Oracle.</li> <li>You need access to more specific datatypes.</li> <li>You need to support a customer that only runs a particular database.</li> <li>You need better D...
<p>BrianLy hit the nail on the head, but I'd also add that you may end up using different databases at different levels of development. It's not uncommon for developers to use SQLite on their workstation when they're coding against their personal development server, and then have the staging and/or production sites usi...
2,688
<p>Regarding the following excerpt of <a href="https://stackoverflow.com/questions/247389/please-help-me-understand-the-specifics-of-the-gpl#247428">this comment</a>:</p> <blockquote> <p>AFAIK, it's fine to interact with GPL code over a network adapter. It's not normally OK (again, AFAIK) to have code that's m...
<p>I agree with earlier comments that this looks bad as far as the spirit of the GPL goes. Doing it anyway would probably meet some resistance in the community which might take forms like:</p> <ul> <li>Not checking your work back into project trunks</li> <li>Not distributing your work if published separately</li> <li>...
<p>Obligatory I Am Not A Lawyer.</p> <p>Are you violating the legal clauses of the GPL? Probably not. ATI and nVidia do this sort of thing with their graphics drivers for Linux. However, it's important to note that Linux is GPLv2; this may have changed with GPLv3.</p> <p>Are you violating the spirit of the GPL? Yes...
30,814
<p>We noticed that lots of bugs in our software developed in C# (or Java) cause a NullReferenceException.</p> <p>Is there a reason why "null" has even been included in the language?</p> <p>After all, if there were no "null", I would have no bug, right?</p> <p>In other words, what feature in the language couldn't wor...
<p>Anders Hejlsberg, &quot;C# father&quot;, just spoke about that point in <a href="https://www2.computerworld.com.au/article/261958/a-z_programming_languages_c_/?pp=3" rel="nofollow noreferrer">his Computerworld interview</a>:</p> <blockquote> <p>For example, in the type system we do not have separation between value ...
<p>Null is an essential requirement of any OO language. Any object variable that hasn't been assigned an object reference has to be null. </p>
21,456
<p>I'm trying to generate some code at runtime where I put in some boiler-plate stuff and the user is allowed to enter the actual working code. My boiler-plate code looks something like this:</p> <pre><code>using System; public class ClassName { public double TheFunction(double input) { // user enter...
<p>Escape them by doubling them up:</p> <pre><code>string s = String.Format("{{ hello to all }}"); Console.WriteLine(s); //prints '{ hello to all }' </code></pre> <p>From <a href="http://msdn.microsoft.com/en-us/netframework/aa569608.aspx#Question1" rel="noreferrer">http://msdn.microsoft.com/en-us/netframework/aa5696...
<p>Be extra extra cautious in who has access to the application. A better solution might be to create a simple parser that only expects a few, limited, commands.</p>
19,429
<p>Which of the two databases is most popular in business/industry? I ask this because in terms of straight revenue or market share, I suspect they're about 50-50, because US government is big on DB2. So, discounting government, military, and academia, which database vendor has the greatest share of the business segmen...
<p>"Lies, damned lies, and statistics". Being a DB2 guy I am baised. But if you believe statistics from Gartner and other consultants Oracle has a lead over DB2 in terms of revenue. I don't think anyone really estimates number of server installs and I am not going to attempt to do this either but I can tell you that we...
<p>For a more recent press release originating from <a href="http://www.gartner.com/" rel="nofollow noreferrer">Gartner</a>, see <a href="http://www.sqlmanager.net/en/news/sql/1189" rel="nofollow noreferrer">here</a></p>
23,846
<p>My Access 2000 DB causes me problems - sometimes (haven't pinpointed the cause) the "book" form won't close. Clicking its close button does nothing, File -> Close does nothing, even closing Access results in no action. I don't have an OnClose handler for this form. The only workaround I can find involves opening ...
<p>Here's a forum post describing, I think, the same problem you face. Excerpt belows states a workaround.</p> <blockquote> <p>What I do is to put code on the close button that reassigns the sourceobject of any subforms to a blank form, such as:</p> <p>me!subParts.sourceobject = "subBlank" 'subBlank is my for...
<p>That sure is weird. Do you have any timer controls on the form? If you do, try disabling it in the OnClose.</p>
10,993
<p>I have a folder that is my working copy. How do I remove all SVN functionality from this folder? There is a reason for me doing this, somehow my master folder that contains all my working copies of sites, has somehow been turned into a working copy itself, so I have a working copy within itself as such.</p> <p>So, ...
<p>Just remove all ".svn" folders in it. That's it.</p>
<p>can't you just delete the .svn subfolder?</p> <p>As far as I know SVN stores everything about its connection to the repository in this subfolder (at least in windows)</p>
22,136
<p>How do I create a resource that I can reference and use in various parts of my program easily?</p> <p>My specific problem is that I have a NotifyIcon that I want to change the icon of depending on the state of the program. A common problem, but one I've been struggling with for a long time. </p>
<p>Well, after searching around and cobbling together various points from around StackOverflow (gee, I love this place already), most of the problems were already past this stage. I did manage to work out an answer to my problem though.</p> <p><strong>How to create a resource:</strong></p> <p>In my case, I want to cr...
<p>Code posted by Matthew Scharley has a memory leak:</p> <pre><code>paused = !paused; if (paused) notifyIcon.Icon = Properties.Resources.RedIcon; else notifyIcon.Icon = Properties.Resources.GreenIcon; </code></pre> <p>You should <code>Dispose()</code> notifyIcon.Icon before replacing it, because <code>Properti...
11,603
<p>Some of my colleagues use special comments on their bug fixes, for example:</p> <pre><code>// 2008-09-23 John Doe - bug 12345 // &lt;short description&gt; </code></pre> <p>Does this make sense?<br> Do you comment bug fixes in a special way?</p> <p>Please let me know.</p>
<p>I don't put in comments like that, the source control system already maintains that history and I am already able to log the history of a file.</p> <p>I do put in comments that describe why something non-obvious is being done though. So if the bug fix makes the code less predictable and clear, then I explain why.</...
<p>To locate ones specific comment we use <strong>DKBUGBUG</strong> - which means David Kelley's fix and reviewer can easily identity, Ofcourse we will add Date and other VSTS bug tracking number etc along with this. </p>
15,074
<p>I inherited a project that uses SQL Server 200x, wherein a column that stores a value that is always considered as a percentage in the problem domain is stored as its greater than 1 decimal equivalent. For example, <em>70%</em> (0.7, literally) is stored as <em>70</em>, <em>100%</em> as <em>100</em>, etc. Aside from...
<p>There are actually four good reasons I can think of that you might want to store—and calculate with—whole-number percentage values rather than floating-point equivalents:</p> <ol> <li>Depending on the data types chosen, the integer value may take up less space.</li> <li>Depending on the data type, the floating-poin...
<p>And to add to the data storage issue, if you can use integer arithmetic for whatever processing you are doing, the performance is much better than when doing floating point arithmetic... So storing ther percetages as integer values may allow the processing logic to itilize integer arithmetic </p>
36,738
<p>Should you set all the objects to <code>null</code> (<code>Nothing</code> in VB.NET) once you have finished with them? </p> <p>I understand that in .NET it is essential to dispose of any instances of objects that implement the <code>IDisposable</code> interface to release some resources although the object can stil...
<p>Karl is absolutely correct, there is no need to set objects to null after use. If an object implements <code>IDisposable</code>, just make sure you call <code>IDisposable.Dispose()</code> when you're done with that object (wrapped in a <code>try</code>..<code>finally</code>, or, a <code>using()</code> block). But ev...
<p>Some object suppose the <code>.dispose()</code> method which forces the resource to be removed from memory.</p>
2,491
<p>I'm preparing a class on Visual Basic 2005 targeting Visual Basic 6 programmers migrating to the .NET platform.<br /><br/> I would like a word of advice about whether to recommend them to always enable <strong>Option Strict</strong> or not.<br /><br/> I've worked exclusively with C-style programming languages, mostl...
<p>Yes! Option Strict is definitely a best practice with .Net. Emphasize that .Net is at it's core a strongly typed platform, and will be until the DLR is more completely supported. With few exceptions, every <code>Dim</code> and <code>Function</code> should have an explicit type declared to go with it. Things like...
<p>If you're used to having your types checked, then you probably want option strict on. turning it off can have advantages, but if your brain isn't tuned to spotting errors where your compiler would usually complain, then I would say to leave it on. I've worked in VB.Net a lot, and I have to say, that even though I w...
27,430
<p>If one Googles for "difference between <code>notify()</code> and <code>notifyAll()</code>" then a lot of explanations will pop up (leaving apart the javadoc paragraphs). It all boils down to the number of waiting threads being waken up: one in <code>notify()</code> and all in <code>notifyAll()</code>.</p> <p>Howeve...
<blockquote> <p>However (if I do understand the difference between these methods right), only one thread is always selected for further monitor acquisition.</p> </blockquote> <p>That is not correct. <code>o.notifyAll()</code> wakes <em>all</em> of the threads that are blocked in <code>o.wait()</code> calls. The th...
<p>Waking up all does not make much significance here. wait notify and notifyall, all these are put after owning the object's monitor. If a thread is in the waiting stage and notify is called, this thread will take up the lock and no other thread at that point can take up that lock. So concurrent access can not take p...
5,764
<p>I truly love VIM - it's one of only a handful of applications I've every come across that make you feel warm and fuzzy inside. However, for PHP development, I still use PDT Eclipse although I would love to switch. </p> <p>The reason I can't quite at the moment is the CTRL+SPACE code-assist functionality that I re...
<p>Vim has <a href="http://vimdoc.sourceforge.net/htmldoc/version7.html#new-omni-completion" rel="nofollow noreferrer">OmniCompletion</a> built in, you should add this to your .vimrc:</p> <pre><code>filetype plugin on au FileType php set omnifunc=phpcomplete#CompletePHP </code></pre> <p>In addition I recommend you th...
<p>Code assist it's a new feature of VIM 7 [Ctrl+x] [Ctrl+o] will auto complete your code or open a popup of options</p> <p>More features of VIM 7 can be found in this <a href="http://linuxhelp.blogspot.com/2006/09/visual-walk-through-of-couple-of-new.html" rel="nofollow noreferrer">blogpost</a></p> <p>Btw, I too lik...
24,789
<p>I have an <code>.xsd</code>, <code>.vb</code>, <code>.xsc</code>, and <code>.xss</code> file for a dataset in Visual&nbsp;Studio&nbsp;2008 that I copied over from another Visual Studio project, however I need to make changes to the dataset. Thus I got into the XSD file, created new columns, deleted ones that aren't ...
<p>You just have to exclude your <code>.xsd</code> file and include it again. It will regenerate your <code>designer.vb</code> file.</p>
<p>Unfortunately, this is in the gray area of things things that I can do when I need to, but I haven't needed to do enough to impart the knowledge to others. </p> <p>All I know is that <code>*.designer.vb</code> means that this code was generated by Visual Studio, and if it generated it once it can do it again. Addi...
36,122
<p>I am looking for a way to maintain PHP sessions across multiple domains on the same server. I am going to be integrating my sites with a Simple Machines Forum so I will need to use MySQL based sessions. Thanks!</p>
<p>Depending upon your preferred method of modifying PHP variables (Apache's config, .htaccess), change the session.cookie_domain value to be a consistent value.</p> <p>I have multiple sub-domains, and each VirtualHost section in the Apache config file contains the following line:</p> <p>php_value session.cookie_doma...
<p>If one site is going to forward or link to a second it can include the session id in the <em>href</em> of the link or as an <em>input</em> in a form. Similar to George's <em>img tag</em> method, but the session would only move over if and when it was needed. </p> <p>Which is best depends on the usage pattern of you...
30,245
<p>How does one go about converting an image to black and white in PHP?</p> <p>Not just turning it into greyscale but every pixel made black or white?</p>
<p>Simply round the grayscale color to either black or white.</p> <pre><code>float gray = (r + g + b) / 3 if(gray &gt; 0x7F) return 0xFF; return 0x00; </code></pre>
<p>For each pixel you must convert from color to greyscale - something like $grey = $red * 0.299 + $green * 0.587 + $blue * 0.114; (these are NTSC weighting factors; other similar weightings exist. This mimics the eye's varying responsiveness to different colors).</p> <p>Then you need to decide on a cut-off value - ge...
31,734
<p>Can I really and truly trust .NET to initialize fields (like ints, structs and the like)? And what if I still want to initialize those fields - what could be the repercussions?</p>
<p>The <a href="http://www.ecma-international.org/publications/standards/Ecma-334.htm" rel="nofollow noreferrer">C# specification</a> states on p.305 (17.4.4)</p> <blockquote> <p>The initial value of a field, whether it be a static field or an instance field, is the default value (§12.2) of the field’s type. It is...
<p>Yes, you can really trust .NET to initialize fields to their default values. There are basically no repercussions for doing it explicitly. (One small caveat here: if you initialize static fields explicitly, then anyone running the type initializer a second time via reflection will end up re-initializing those fields...
33,679
<p>I need to simply go through all the cells in a Excel Spreadsheet and check the values in the cells. The cells may contain text, numbers or be blank. I am not very familiar / comfortable working with the concept of 'Range'. Therefore, any sample codes would be greatly appreciated. (I did try to google it, but the...
<p>If you only need to look at the cells that are in use you can use:</p> <pre><code>sub IterateCells() For Each Cell in ActiveSheet.UsedRange.Cells 'do some stuff Next End Sub </code></pre> <p>that will hit everything in the range from A1 to the last cell with data (the bottom right-most cell)</p>
<p>In Excel VBA, this function will give you the content of any cell in any worksheet.</p> <pre><code>Function getCellContent(Byref ws As Worksheet, ByVal rowindex As Integer, ByVal colindex As Integer) as String getCellContent = CStr(ws.Cells(rowindex, colindex)) End Function </code></pre> <p>So if you want to c...
9,949
<p>I've been working with LINQ To SQL for a little while now and when it comes to removing an entity from the DB, I've always called the table's .DeleteOnSubmit and passed in the entity. Sometimes I've found myself writing something like:</p> <pre><code>db.Users.DeleteOnSubmit(db.Users.Where(c =&gt; c.ID == xyz).Selec...
<p>Here is a solution...</p> <pre><code>public static void DeleteByPK&lt;TSource, TPK&gt;(TPK pk, DataContext dc) where TSource : class { Table&lt;TSource&gt; table = dc.GetTable&lt;TSource&gt;(); TableDef tableDef = GetTableDef&lt;TSource&gt;(); dc.ExecuteCommand("DELETE FROM [" + tableDef.TableName + "]...
<p>I don't believe Linq to Sql can do this natively, although writing a stored procedure would give you what you want, with syntax like:</p> <pre><code>db.spDeleteUserById(id); </code></pre> <p>This would requre writing a stored procedure for each table, but it's a pretty trivial amount of SQL.</p> <hr> <p>Check ou...
44,021
<p>I have a .NET string which is Base64 encoded representation of an array of encrypted bytes. It is produced like this:</p> <pre><code>String Encrypt( String message ) { CryptoStream cryptostream = ... StreamWriter stream = new StreamWriter( cryptostream ); ... return Convert.ToBase64String( ... ); }...
<p>I always the the <a href="http://msdn.microsoft.com/en-us/library/system.convert.frombase64string.aspx" rel="nofollow noreferrer">Convert</a> class to convert the string into an array of Byte.</p> <p>An example:</p> <pre><code> public static string DeCryptString(string s) { byte[] b = System.Convert.Fro...
<p>There is no public built-in way to stream from a string, as of .NET 3.5.</p> <p>You can implement a simple StringStream class that inherits from Stream, which will free you from having to convert the string to an array of bytes.</p>
22,675
<p>Lifehacker had a post a couple days ago asking people about <a href="http://lifehacker.com/5054519/" rel="nofollow noreferrer">the best mouse you've ever had</a> and it appears some people have traded their mouse for a tablet.</p> <p>I'm curious if anyone here has traded their mouse in for a tablet? Does it work w...
<p>I don't know Java best practices, but it occurs to me that if you are claiming that serialization will never happen, you could add a writeObject method which throws. Then suppress the warning, safe in the knowledge that it cannot possibly apply to you.</p> <p>Otherwise someone might in future serialize your object ...
<p>Please follow this link to get detailed explanation: <a href="http://technologiquepanorama.wordpress.com/2009/02/13/what-is-use-of-serialversiouid/" rel="nofollow noreferrer">http://technologiquepanorama.wordpress.com/2009/02/13/what-is-use-of-serialversiouid/</a></p>
17,661
<p>I have example of code below. </p> <pre><code>&lt;script type="text/javascript" src="assets/scripts/somescript.php"&gt;. &lt;/script&gt; </code></pre> <p>So, will my browser still cache this just by not setting this scripts headers meta tag cache to must-revalidate?</p>
<p>Some browsers are more agressive with default caching than others. However, there are cache control headers you can send to indicate when to reload the code. </p> <pre><code>header("Expires: " . date("r", time() + ( 60 * 60 * 24 * 7 * 1 ) ) ); // Expires in 1 week header("Content-Type: application/x-javascript"); <...
<p>If you send a <code>Content-type: text/javascript; charset="your_charset"</code> the browser will recognize your PHP script as a valid Javascript resource and will handle it like any other Javascript. You can control browser caching behavior by issuing the correct headers in your PHP script using <a href="http://de....
38,642
<p>More information from <a href="http://en.wikipedia.org/wiki/Perl_6#Junctions" rel="noreferrer">the Perl 6 Wikipedia entry</a></p> <p><strong>Junctions</strong></p> <p>Perl 6 introduces the concept of junctions: values that are composites of other values.[24] In the earliest days of Perl 6's design, these were call...
<p>How many days are in a given month?</p> <pre><code>given( $month ){ when any(qw'1 3 5 7 8 10 12') { $day = 31 } when any(qw'4 6 9 11') { $day = 30 } when 2 { $day = 29 } } </code></pre>
<p>The most attractive feature of junctions is that you don't need to write a lot of code test for complex situations. You describe the situation with the junctions, then apply the test. You don't think about how you get the answer (for instance, using short circuit operators or if blocks) but what question you are ask...
12,782
<p>I'm receiving feedback from a developer that "The only way visual basic (6) can deal with a UNC path is to map it to a drive." Is this accurate? And, if so, what's the underlying issue and are there any alternatives other than a mapped drive?</p>
<p>We have a legacy VB6 app that uses UNC to build a connection string, so I know VB6 can do it. Often, you'll find permissions problems to be the culprit.</p>
<p>What sort of file I/O are you doing? If it's text, look into using a FileSystemObject.</p>
11,194
<p>I have had a 3d printer for a while now, and I have a lot of the quality settings dialed in pretty well, but one thing that constantly bugs me is removing the raft from my finished prints. I am using Repetier and I have set the air gap to 0.2 mm. That led to much better results than the default 0, which were impossi...
<p>I have been able to get rafts that peel off by editing the g-code after the raft has finished and adding an M104 set temperature command telling my printer to cool the nozzle down to about 40 degrees and then another M104 command to tell the nozzle to heat back up again. This gives the raft enough time to cool and t...
<p>I use raft almost always for ABS and PLA. My favorite setting for gap is somewhere between 0.11-0.13 mm both for 0.1 and 0.2 mm layer height.</p> <p>By using 3-4 layers of raft I always get predictably good quality of a lower layer and not have any issues with removing prints from the surface which I had without us...
692
<p>I'm looking for a .NET library that will allow creation of a Word document. I need to export HTML based content to a Word doc (97-2003 format, not docx).</p> <p>I know that there are the Microsoft Office Automation libraries and Office interop, but as far as I can tell, they require that you have office actually i...
<p><em>Would it work if I somehow converted the CSS to be embedded in the HTML??</em></p> <p>Yes. I use an internal style sheet, as I mentioned.</p> <p>Document Example:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;STYLE type="text/css"&gt; h1 {text-align:center; font-size:12.0pt; font-family:Arial; font-weight:...
<p>Since the doc format specification is not open, and the interop assemblies are the Microsoft solution, I fear that they are your primary (or even only) option.</p> <p>They do indeed require office to be installed, and they open Word (although showing a window is optional).</p> <p>I think Word can open HTML documen...
35,782
<p><em>[This question is related to but not the same as <a href="https://stackoverflow.com/questions/206564/what-is-the-performance-implication-of-converting-to-bool-in-c">this one</a>.]</em></p> <p>If I try to use values of certain types as boolean expressions, I get a warning. Rather than suppress the warning, I so...
<p>The argument of the ! operator and the first argument of the ternary operator are both implicitly converted to bool, so !! and ?: are IMO silly redundant decorations of the cast. I vote for </p> <pre><code>b = (t != 0); </code></pre> <p>No implicit conversions.</p>
<p>The double not feels funny to me and in debug code will be very different than in optimized code.</p> <p>If you're in love with !! you could always Macro it.</p> <pre><code>#define LONGTOBOOL(x) (!!(x)) </code></pre> <p>(as an aside, the ternary operator is what I favor in these cases)</p>
25,249
<p>There have been some questions about whether or not JavaScript is an object-oriented language. Even a statement, "just because a language has objects doesn't make it OO."</p> <p>Is JavaScript an object-oriented language?</p>
<p>IMO (and it is only an opinion) <strong>the</strong> key characteristic of an object orientated language would be that it would support <a href="http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming" rel="nofollow noreferrer"><em>polymorphism</em></a>. Pretty much all dynamic languages do that.</...
<p>I would say it has capabilities to seem OO. Especially if you take advantage of it's ability to create methods on an existing object (anonymous methods in some languages). Client script libraries like jquery (jquery.com) or prototype (prototypejs.org) are good examples of libraries taking advantage of this, making j...
13,293
<p>I have a desktop application having heavyweight components (JxBrowser) in a JFrame. How can I make a snapshot from the GUI and save it to for example a png file? </p> <p>Note: The method using Graphics2d and Component.paint()/paintAll()/print/printAll works only for lightweight components. </p> <p>Any answers appr...
<p>My name is Roman and I'm developer at TeamDev.</p> <p>JxBrowser component it's a heavyweight component that embedds a native mozilla window to display web pages. To get screenshot of a full web page from JxBrowser component you can really use the Java Robot functionality with web page scrolling. For small web pages...
<p>You can try also to create a screenshot by implementing this:</p> <pre><code> int width = frameContainer.getWidth(); int height = frameContainer.getHeight(); BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); frameContaine...
43,120
<p>I know how to find what I need from XML using XPath. The syntax takes a little getting used to, but it is quite powerful. I'm interested in learning XQuery also, but the SQL like syntax seems awkward. Even so, if it can provide not just a select equivalent, but also update, insert, and delete as SQL does, I will ...
<p>No. None of <a href="http://www.w3.org/TR/xpath20/" rel="noreferrer"><strong>XPath</strong></a> or <a href="http://www.w3.org/TR/xquery/" rel="noreferrer"><strong>XQuery</strong></a> has SQL-like update/insert/delete functionality.</p> <p>You need to look for an implementation of the "<a href="http://www.w3.org/TR/...
<p>XPath is a language for addressing parts of an XML document. So it cannot have any DML statement. It is select statement by definition.</p>
39,842
<p>I'm SSHing into a remote server on the command line, and trying to copy a directory onto my local machine with the <code>scp</code> command. However, the remote server returns this "usage" message:</p> <pre><code>[Stewart:console/ebooks/discostat] jmm% scp -p ./styles/ usage: scp [-1246BCEpqrv] [-c cipher] [-F ssh_...
<p>You need to <code>scp</code> something somewhere. You have <code>scp ./styles/</code>, so you're saying secure copy <code>./styles/</code>, but not where to copy it to.</p> <p>Generally, if you want to download, it will go:</p> <pre><code># download: remote -&gt; local scp user@remote_host:remote_file local_file ...
<p>No, you still need to <code>scp [from] [to]</code> whichever way you're copying</p> <p>The difference is, you need to <code>scp -p server:serverpath localpath</code></p>
44,703
<p>I have need to write an application which uses a speech recognition engine -- either the built in vista one, or a third party one -- that can display a word or phrase, and recognise when the user reads it (or an approximation of it). I also need to be able to switch quickly between languages, without changing the l...
<p>A similar question was asked on Joel on Software a while back. You can use the <a href="http://msdn.microsoft.com/en-us/library/system.speech.recognition.aspx" rel="noreferrer">System.Speech.Recognition</a> namespace to do this...with some limitations. Add System.Speech (should be in the GAC) to your project. Her...
<p><a href="http://www.nuance.com/for-developers/dragon/index.htm" rel="nofollow noreferrer">Dragon Naturally Speaking SDK</a> might be worth looking at. <a href="http://www.codeproject.com/KB/cs/TextToSpeechWindowsSAPI.aspx" rel="nofollow noreferrer">This project</a> looked interesting.</p> <p>Haven't got to play wit...
28,105
<p>I'm using this script to display all the images in a folder, but I can't figure out how to get each image's file name to display underneath it. Any suggestions?</p> <pre><code>&lt;?php $dirname = "images"; $images = scandir($dirname); $ignore = Array(".", "..", "otherfiletoignore"); foreach($images as $curimg){ ...
<pre><code>echo "&lt;img src='images/$curimg' /&gt;&lt;br /&gt;$curimg&lt;br /&gt;\n"; </code></pre>
<p>I think nickf's suggestion is the simplest thing you can do achieve what you want without any css or complex structure..</p>
32,185
<p>I've spent hours trying to get my code to work, its a rats nest of if/elses. Basically I want to check a country name against these two arrays:</p> <pre><code>//if its in this array add a 'THE' $keywords = array("bahamas","island","kingdom","republic","maldives","netherlands", "isle of man","i...
<p>This builds on @sgehrig's answer, but note the change in your exceptions:</p> <pre><code>//if its in this array add a 'THE' $keywords = array("bahamas","island","kingdom","republic","maldives","netherlands", "isle of man","ivory","philippines","seychelles","usa"); //if its in this array, take ...
<p>The easiest would be to split it into two steps, ad the "the" for the countries that match the first list, and then just remove it if if matches the words in the second list.</p>
35,980
<p>What do you consider the most rapid RAD environment for a working prototype? Not for debate. </p> <ul> <li>language</li> <li>platform</li> <li>IDE</li> <li>DB </li> <li>(personal note)</li> </ul> <p>Thank you.</p> <p>P.S.1 I was pretty happy with PERL for back-end prototyping... I get stuck when dealing with t...
<p>For prototypes on Windows, Visual Basic is hard to beat. If you need to suppoort another platform (or multiple platforms), then Tcl/Tk is fairly productive, as well.</p>
<p>I'd say Python with <a href="http://wxpython.org/" rel="nofollow noreferrer">wxPython</a></p>
14,930
<p>Got a quick question. Does anyone know how to let JAXB (marshall) render boolean fields as 1 and 0 instead of printing out "true" and "false"?</p>
<p>The adapter class:</p> <pre><code>import javax.xml.bind.annotation.adapters.XmlAdapter; public class BooleanAdapter extends XmlAdapter&lt;Integer, Boolean&gt; { @Override public Boolean unmarshal( Integer s ) { return s == null ? null : s == 1; } @Override public Integer marshal( B...
<p>You can write a pair of parser/writers and define the property mapping in binding JAXB XML.</p>
44,697
<p>My last couple of projects have involved websites that sell a product/service and require a 'checkout' process in which users put in their credit card information and such. Obviously we got SSL certificates for the security of it plus giving peace of mind to the customers. I am, however, a little clueless as to the ...
<p>I personally go with "SSL from go to woe". </p> <p>If your user never enters a credit card number, sure, no SSL. </p> <p>But there's an inherent possible security leak from the cookie replay. </p> <ol> <li>User visits site and gets assigned a cookie. </li> <li>User browses site and adds data to cart ( using cooki...
<p>I only ever redirect my sites to SSL when it requires the user to enter sensitive information. With a shopping cart as soon as they have to fill out a page with their personal information or credit card details I redirect them to a SSL page. For the rest of the site its probably not needed - if they are just viewing...
13,300
<p>I am running a Tomcat application, and I need to display some time values. Unfortunately, the time is coming up an hour off. I looked into it and discovered that my default TimeZone is being set to:</p> <pre><code>sun.util.calendar.ZoneInfo[id="GMT-08:00", offset=-28800000, ...
<p>It's a "quirk" in the way the JVM looks up the zoneinfo file. See <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6456628" rel="noreferrer">Bug ID 6456628</a>.</p> <p>The easiest workaround is to make /etc/localtime a symlink to the correct zoneinfo file. For Pacific time, the following commands shoul...
<p>It may help to double-check the timezone rules your OS is using.</p> <pre><code>/usr/bin/zdump -v /etc/localtime | less </code></pre> <p>This file should contain your daylight savings rules, like this one for the year 2080:</p> <pre><code>/etc/localtime Sun Mar 31 01:00:00 2080 UTC = Sun Mar 31 02:00:00 2080 BST...
2,814
<p>I have to develop a system to <strong>monitor</strong> the <strong>generation/transmission</strong> of reports.</p> <ul> <li>System data will be stored in database tables (Sybase)</li> <li>Reports will be generated with different schedules ("mon-fri 10pm", "sat 5am", "1st day of the month", etc.)</li> <li>System wi...
<p>Something in the lines of</p> <pre><code>myString.split(&quot;\\s+&quot;); </code></pre> <p>This groups all white spaces as a delimiter.</p> <p>So if I have the string:</p> <pre><code>&quot;Hello[space character][tab character]World&quot; </code></pre> <p>This should yield the strings <code>&quot;Hello&quot;</code> ...
<p>Study this code.. good luck</p> <pre><code> import java.util.*; class Demo{ public static void main(String args[]){ Scanner input = new Scanner(System.in); System.out.print("Input String : "); String s1 = input.nextLine(); String[] tokens = s1.split("[\\s\\xA0]+"); ...
27,852
<p>The scenario is trying to adjust font size to get a nice graphic arrangement, or trying to decide where to break a caption/subtitle. a) In XL VBA is there a way to find out whether a text on a textbox, or caption on a label, still fits the control? b) Is there a way to know where was the text/caption broken on multi...
<p>I gave this a rest, gave it enough back-of-head time (which produces far better results than "burp a non-answer ASAP, for credits"), and...</p> <pre><code>Function TextWidth(aText As String, Optional aFont As NewFont) As Single Dim theFont As New NewFont Dim notSeenTBox As Control On Error Resume Next ...
<p>I'm sure there is no way to do this with the ordinary Excel controls on the Forms toolbar, not least because (as I understand it) they are simply drawings and not full Windows controls.</p> <p>The simplest approach may be to make a slightly conservative estimate of the maximum text length for each control, through ...
32,045
<p>There are a ton of drivers &amp; famous applications that are not available in 64-bit. Adobe for instance does not provider a 64-bit Flash player plugin for Internet Explorer. And because of that, even though I am running 64-bit Vista, I have to run 32-bit IE. Microsoft Office, Visual Studio also don't ship in 64-bi...
<p>If you are starting from scratch, 64-bit programming is not that hard. However, all the programs you mention are not new. </p> <p>It's a whole lot easier to build a 64-bit application from scratch, rather than port it from an existing code base. There are many gotchas when porting, especially when you get into a...
<p>Their <a href="http://blogs.adobe.com/penguin.swf/2006/10/whats_so_difficult_64bit_editi.html" rel="nofollow noreferrer">Linux/Flash blog</a> goes some way to explain why there isn't a 64bit Flash Player as yet. Some is Linux-specific, some is not.</p>
19,360
<p>Ok, so at some point in time, somebody checked in some files with names that require a case sensitive file system into the trunk of a repository that I constantly check out. This of course leads to my local working copy locking up when I try to check it out (on my Windows computer). Is there any way that I can set...
<p>You can use the repository browser to remove/rename the offending file then update your working copy as per normal, fix up any references to the file you renamed that may need fixing up, and commit the fixes.</p> <p>Then drag up a shotgun and shoot whoever did this in the first place. Case sensitivity abuse is one ...
<p>Recompile svn using Interix's compiler. Now it handles case correctly on NTFS.</p>
24,921
<p>I've heard people referring to this table and was not sure what it was about.</p>
<p>It's a sort of dummy table with a single record used for selecting when you're not actually interested in the data, but instead want the results of some system function in a select statement:</p> <p>e.g. <code>select sysdate from dual;</code></p> <p>See <a href="http://www.adp-gmbh.ch/ora/misc/dual.html" rel="nofoll...
<p>It's a object to put in the from that return 1 empty row. For example: select 1 from dual; returns 1</p> <p>select 21+44 from dual; returns 65</p> <p>select [sequence].nextval from dual; returns the next value from the sequence.</p>
9,947
<p>It would seem the Immediate window needs some jazzing up ala IntelliSense?</p> <p>Anyone agree/disagree? Is this coming in VS2008/2010?</p>
<p>Ctrl + Space in immediate if you don't have the intellisense coming up automatically. Like Joel, intellisense seems to come in go in the immed window.</p>
<p>When debugging in Visual Studio 2008, you can get intellisense to pop up by pressing ctrl+space. Also, it will pop up in a quick watch window with the same keystroke. Very handy.</p>
36,697
<p>Using .Net 3.0 and VS2005. </p> <p>The objects in question are consumed from a WCF service then serialized back into XML for a legacy API. So rather than serializing the TestObject, it was serializing .TestObject which was missing the [XmlRoot] attribute; however, all the [Xml*] attributes for the child elements we...
<p><strong>== IF ==</strong></p> <p>This is only for the <code>XmlRoot</code> attribute. The <code>XmlSerializer</code> has one constructor where you can specify the <code>XmlRoot</code> attribute.</p> <p>Kudos to csgero for pointing it. His comment should be the solution.</p> <pre><code>XmlSerializer Constructor (T...
<p>I found someone who provides a means to solve this situation:</p> <p><a href="http://www.request-response.com/blog/PermaLink,guid,efa4e231-ddf1-48f4-9a26-54363e799d42.aspx" rel="nofollow noreferrer">Matevz Gacnik's Weblog</a></p> <p>Using that approach of <code>XmlAttributeOverrides</code>, I wrote the following:<...
19,279
<p>I am sending newsletters from a Java server and one of the hyperlinks is arriving missing a period, rendering it useless:</p> <pre><code>Please print your &lt;a href=3D&quot;http://xxxxxxx.xxx.xx.edu= au//newsletter2/3/InnovExpoInviteVIP.pdf&quot;&gt; VIP invitation&lt;/a&gt; for future re= ference and check the Inn...
<p>From an SMTP perspective, you can start a line with a period but you have to send two periods instead. If the SMTP client you're using doesn't do this, you may encounter the problem you describe.</p> <p>It might be worth trying an IP sniffer to see where the problem really is. There are likely at least two separate...
<p>I am not sure, but it looks a bit as if your email is getting encoded. 0x3D is the hexadecimal character 61, which is the equals character ('=').</p> <p>What classes/libary are you using to send the emails? Check the settings regarding encoding.</p>
14,564
<p>I have an exe file generated with py2exe. In the setup.py I specify an icon to be embedded in the exe:</p> <pre><code>windows=[{'script': 'my_script.py','icon_resources': [(0, 'my_icon.ico')], ... </code></pre> <p>I tried loading the icon using:</p> <pre><code>hinst = win32api.GetModuleHandle(None) hicon = win32g...
<p>@efotinis: You're right. </p> <p>Here is a workaround until py2exe gets fixed and you don't want to include the same icon twice:</p> <pre><code>hicon = win32gui.CreateIconFromResource(win32api.LoadResource(None, win32con.RT_ICON, 1), True) </code></pre> <p>Be aware that <strong>1</strong> is not the ID you gave ...
<p>You should set the icon ID to something other than 0:</p> <pre><code>'icon_resources': [(42, 'my_icon.ico')] </code></pre> <p>Windows resource IDs must be between 1 and 32767.</p>
11,610
<p>I was wondering if I could pop up <code>JOptionPane</code>s or other Swing components from within a browser using JSP.</p>
<p>If you embed an applet. But I don't think that's what you want. Swing is for desktop apps. JSP web pages. If you want components, try looking into JSF or some of the many AJAX Javascript frameworks like prototype.</p>
<p>Assuming you're familiar with Swing, you may want to introduce yourself to <a href="http://wicket.apache.org/" rel="nofollow noreferrer">Apache Wicket</a> which is very similar to the way you build web pages as Swing is to building GUI:s. That is, in Wicket you add new instancef of Label, Button, DataTable etc. etc....
29,876
<p>I have written a very simple bash script to help me migrate from dev to staging. What it does is it deletes all files in staging, copies the files over from dev to stage.</p> <p>However, the config.inc.php file needs to have the first instance of "dev" to be changed to "stage", and no other instance changed.</p> ...
<p>This will change only the first appearance of "dev" to "stage"</p> <pre><code>sed -i '0,/dev/ s/dev/stage/' config.inc.php </code></pre> <p>Be aware that it changes "devel" into "stageel". This version behaves just like you want, only a "dev" is searched, not a "devel" (in fact, <code>s/\&lt;dev\&gt;/stage/</code>...
<p>The first part (editing your file) can be done well with the stream editor utility <code>sed</code>:</p> <pre><code>sed -i -e s/dev/stage/ config.inc.php </code></pre> <p>This edits the file in-place (<code>-i</code>) with no backup, using expression <code>/dev/stage/</code> (<code>-e</code>) to replace one expres...
45,105