instruction
stringlengths
21
27.8k
chosen
stringlengths
18
28.2k
rejected
stringlengths
18
33.6k
__index_level_0__
int64
0
50k
<p>I am reading WIX script written by others. There are some code really confuses me. </p> <pre><code>&lt;Custom Action='UnLoadSchedulerPerfCounters' After='InstallInitialize'&gt; &lt;![CDATA[(Installed) AND (!Scheduler = 3)]]&gt; &lt;/Custom&gt; &lt;Custom Action='RollbackSchedulerPerfCounters' After='WriteRegist...
<p>From <a href="http://www.tramontana.co.hu/wix/lesson5.php#5.3" rel="nofollow noreferrer">http://www.tramontana.co.hu/wix/lesson5.php#5.3</a>:</p> <blockquote> <p>Prepending some special characters to the names will give them extra meaning:</p> <pre><code>% environment variable (name is case insensitive) ...
<p>Those are operators on the Windows Installer condition syntax. See this MSI SDK documentation for a complete list: <a href="http://msdn.microsoft.com/en-us/library/aa368012.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/aa368012.aspx</a>. </p>
30,575
<p>I am having a Html hyperlink. I need to link this hyperlink to another page.When I place the mouse over the link. It should show the image. how to do this</p>
<p>That depends on where you need to display the image. If you are looking for something along the lines of an icon next to or behind the link, you could accomplish this through CSS using a background image on the hover state of the link:</p> <pre><code>a:link { background-image:none; } a:hover { background-ima...
<p>you can do this using javascript..</p> <p>This will create a square that follows your mouse on div or element hover.</p> <p>Create a .js file with those contents here: </p> <pre><code> var WindowVisible = null; function WindowShow() { this.bind = function(obj,url,height,width) { obj.url = url; ...
36,798
<p>I am new to 3D printing. I own jewelry stores and want to 3D print my jewelry packaging for rings, necklaces, and bangles as in the picture below:</p> <p><a href="https://i.stack.imgur.com/NVwgE.png" rel="nofollow noreferrer" title="Product photo of a jewelry ring box"><img src="https://i.stack.imgur.com/NVwgE.png" ...
<h1>With the right materials</h1> <p>With the right material, you can get flexible surfaces and prints. Just two random examples:</p> <ul> <li>TPU is a flexible material, which can be used to print something like &quot;Lips&quot; that flex and take the jewelry or even strings that suspend the piece in the center.</li> ...
<p>I would advise against this, as you will get layer lines which isn't visible in normal form, and the fit wont be as smooth etc, resulting in a cheaper look &amp; feel. You will spend a lot of effort modifiying the parameters to get a foamy look, but still end up with a worse product. Instead the best option is proba...
2,181
<p>how can i figure out the last modified date of a html file im importing into my web app?</p> <p>The html file is on another server and different users can make updates, when i retrieve the page i want to be able see when it was last updated so i can label the updated date on my homepage. I</p>
<p>I assume you are using HTTP to retrieve the page.</p> <p>In that case you can use the HEAD method of HTTP to get the header data of the file. (See <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html" rel="noreferrer">http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html</a>, 9.4)</p> <p>Then you can che...
<p>There are some proposed meta tag keys representing Dublin Core values that may be used. See: <a href="https://stackoverflow.com/a/14893974/895245">https://stackoverflow.com/a/14893974/895245</a> </p>
24,957
<p>I use a structure of function pointers to implement an interface for different backends. The signatures are very different, but the return values are almost all void, void * or int.</p> <pre><code> struct my_interface { void (*func_a)(int i); void *(*func_b)(const char *bla); ... int (*func_z)(ch...
<p>By the C specification, casting a function pointer results in undefined behavior. In fact, for a while, GCC 4.3 prereleases would return NULL whenever you casted a function pointer, perfectly valid by the spec, but they backed out that change before release because it broke lots of programs.</p> <p>Assuming GCC co...
<p>Casting a function pointer to NULL is explicitly not supported by the C standard. You're at the mercy of the compiler writer. It works OK on a lot of compilers.</p> <p>It is one of the great annoyances of C that there is no equivalent of NULL or void* for function pointers.</p> <p>If you really want your code to...
22,900
<p>I've been programming in C,C++,C# and a few other languages for many years, mainly for Windows and Linux but also embedded platforms. Recently started to do some iPhone programming as a side project so I'm using Apple platforms for the first time since my Apple II days. I'm wondering what other developers that are c...
<p>I'm in the same boat as you (somewhat). I've been developing in C# for 7 years, ever since .NET 1.0. Over the past couple weeks I've been teaching myself Cocoa and Objective-C. Here are my impressions (note for note with yours)</p> <ul> <li><p>Agreed in that clutter can be a problem. I tend to use Spaces heavil...
<p>I came from a C# background as well and have been working with the iPhone SDK since beta 2. I totally agree with cranley about VS being a bit clunky compared to Xcode. Xcode is WAY different, and totally foreign when you start using it. So was VS though back in the day. Once you get by the learning curve it is a...
12,905
<p>My code runs inside a JAR file, say <strong>foo.jar</strong>, and I need to know, in the code, in which folder the running <strong>foo.jar</strong> is.</p> <p>So, if <strong>foo.jar</strong> is in <code>C:\FOO\</code>, I want to get that path no matter what my current working directory is.</p>
<pre><code>return new File(MyClass.class.getProtectionDomain().getCodeSource().getLocation() .toURI()).getPath(); </code></pre> <p>Replace "MyClass" with the name of your class.</p> <p>Obviously, this will do odd things if your class was loaded from a non-file location.</p>
<p>This method, called from code in the archive, returns the folder where the .jar file is. It should work in either Windows or Unix.</p> <pre><code> private String getJarFolder() { String name = this.getClass().getName().replace('.', '/'); String s = this.getClass().getResource("/" + name + ".class").toStri...
41,471
<p>We need to build an administration portal website to support our client/server application. Since we're a .Net shop the obvious traditional way would be to do that in ASP.Net. But Silverlight 2 will be coming out of beta a good while before our release date. Should we consider building the whole website in silverlig...
<p>I would recommend against building a pure Silverlight site.</p> <p>Silverlight suffers from the same issues as Flash does: Unintuitive Bookmarking, issues with printing, accessibility issues, not working back buttons and so on.</p> <p>Also, you would require your users to have Silverlight installed or at least to ...
<p>There are some <a href="https://stackoverflow.com/questions/56266/using-silverlight-for-an-entire-website#56302">downsides</a> with developing a site completely in Flash / Silverlight, but if those downsides won't matter to you or won't have an impact then there is nothing stopping you. Choose whatever tool you thin...
8,015
<p>I've generated some JSON and I'm trying to pull it into an object in JavaScript. I keep getting errors. Here's what I have:</p> <pre><code>var data = '{"count" : 1, "stack" : "sometext\n\n"}'; var dataObj = eval('('+data+')'); </code></pre> <p>This gives me an error: </p> <pre><code>unterminated string literal </...
<p>This is what you want:</p> <pre><code>var data = '{&quot;count&quot; : 1, &quot;stack&quot; : &quot;sometext\\n\\n&quot;}'; </code></pre> <p>You need to escape the <code>\</code> in your string (turning it into a double-<code>\</code>), otherwise it will become a newline in the JSON source, not the JSON data.</p>
<p>I encountered that problem while making a class in PHP&nbsp;4 to emulate json_encode (available in PHP&nbsp;5). Here's what I came up with:</p> <pre><code>class jsonResponse { var $response; function jsonResponse() { $this-&gt;response = array('isOK'=&gt;'KO', 'msg'=&gt;'Undefined'); } fun...
6,345
<p>I have an SVN repository and I need the commits to fail if no description is entered. Is this possible to do, preferably server-side? (The users use several different tools for interacting with the repository; although if this were possible client-side in TortoiseSVN, that would alleviate the problem)</p> <p>Google...
<p>Yup, you'll want to write a pre-commit hook in the repository which fails with an appropriate error message to send back to the client.</p> <p>If you look in the "hooks" directory of a freshly created repository, you'll find a <code>pre-commit.tmpl</code> file. That contains instructions, and the sample even checks...
<p>You can do that using <a href="http://svnbook.red-bean.com/en/1.5/svn.reposadmin.create.html#svn.reposadmin.create.hooks" rel="nofollow noreferrer">repository hooks</a>. In your case, you want a pre-commit hook that will check the message and reject the commit if it is empty.</p>
48,456
<p>How unique is the php session id? I got the impression from various things that I've read that I should not rely on two users never getting the same sessionid. Isn't it a GUID?</p>
<p>It's not very unique as shipped. In the default configuration it's the result of a hash of various things including the result of gettimeofday (which isn't terribly unique), but if you're worried, you should configure it to draw some entropy from /dev/urandom, like so</p> <pre><code>ini_set("session.entropy_file",...
<pre><code>&lt;?php session_start(); $_SESSION['username']="username"; ?&gt; &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Update&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;table border="2"&gt; &lt;tr&gt; &lt;th&gt;Username&lt;/th&gt; &lt;th&gt;Email&lt;/th&gt; &lt;th&...
16,796
<p>As we all know, when we derive a class and use polymorphism, someone, somewhere needs to know what class to instanciate. We can use factories, a big switch statement, if-else-if, etc. I just learnt from Bill K this is called Dependency Injection.</p> <p><strong>My Question: Is it good practice to use reflection and...
<p>My personal preference is neither - when there is a mapping of classes to some arbitrary string, a configuration file is the place to do it IMHO. This way, you <strong>never</strong> need to modify the code - especially if you use a dynamic loading mechanism to add new dynamic libraries. </p> <p>In general, I alway...
<p>I know this borders on the "no comment about loading images other ways", but why not just flip your dependencies -- rather than have ImageLoader depend on ImageFileFormats, have each IImageFileFormat depend on an ImageLoader? You'll gain a few things out of this:</p> <ul> <li>Each time you add a new IImageFileForm...
41,204
<p>On the site we are building. We need to be able to redirect the user to a default page when his session has ended.</p> <p>At first sight we used the Session_End with a Response.Redirect to do this job.</p> <pre><code>Sub Session_End(ByVal sender As Object, ByVal e As EventArgs) Response.Redirect("~/global/exit...
<p>We handled it by checking if the session data existed in Application.Begin_Request for the pages that were user specific and if it didn't then redirecting the user to login or homepage.</p>
<p>We handled it by checking if the session data existed in Application.Begin_Request for the pages that were user specific and if it didn't then redirecting the user to login or homepage.</p>
24,585
<p>I'm learning XML, currently of Wikibooks, but that is kinda huge and not oversee-able...</p> <p>anybody know a better place?</p>
<p><a href="http://www.w3schools.com/xml/default.asp" rel="noreferrer">W3Schools</a> are generally good for this type of stuff.</p>
<p>Even though there are plenty of tutorials about XML , I agree with Galwegian . I learned XML from <a href="http://www.w3schools.com/xml/default.asp" rel="nofollow noreferrer">W3Schools</a>.</p>
9,709
<ul> <li><p>How do I utilize a ?: operator in the SELECT clause of a LINQ query? If this can't be done, how can I emulate one? The goal is to get a CASE block in my select clause. As you might suspect, I'm getting an error: <em>Invalid anonymous type member declarator. Anonymous type members must be declared with a m...
<p>When creating an anonymous type (what you're doing with the "new" without specifying a type) you have to specify the member name for each property. From your example, it would look something like this: (also fixed your joins)</p> <pre><code>var query = from a in db.tblActivities join i in db.tblIPs on...
<p>I'm fairly new to Linq to SQL but I'm pretty sure it would go like this:</p> <pre><code>var query = from a in db.tblActivities from i in a.tblIPs from u in i.tblUsers select new { userName = (u.UserName == null) ? i.Address : u.UserName, a.Request, ...
35,824
<p>I am going to be starting a javascript reporting engine for my website, and have started some prototyping using MooTools. I really like being able to do things like this:</p> <pre><code>function showLeagues(leagues) { var leagueList = $("leagues"); leagueList.empty(); for(var i = 0; i&lt;leagues.length...
<p>syntactically, it may be nicer to use jQuery to do it, but its probably more efficient to use</p> <pre><code> document.createElement('li') </code></pre> <p>And eliminate the need for at the bare minimum a string comparison test and a minor token parse. </p> <p><a href="http://flydom.socianet.com/" rel="noreferr...
<p>Here's that same thing in jQuery. Basically to create a new element, you just put in the HTML you want.</p> <pre><code>function showLeagues(leagues) { var $leagueList = $("#leagues"); $leagueList.empty(); $.each(leagues, function (index, league) { $leagueList.append(getLeagueListElement(league))...
21,267
<p>So if I have to choose between a hash table or a prefix tree what are the discriminating factors that would lead me to choose one over the other. From my own naive point of view it seems as though using a trie has some extra overhead since it isn't stored as an array but that in terms of run time (assuming the longe...
<p>Advantages of tries:</p> <p>The basics:</p> <ul> <li>Predictable O(k) lookup time where k is the size of the key</li> <li>Lookup can take less than k time if it's not there</li> <li>Supports ordered traversal</li> <li>No need for a hash function</li> <li>Deletion is straightforward</li> </ul> <p>New operations:</...
<p>Some (usually embedded, real-time) applications require that the processing time be independent of the data. In that case, a hash table can guarantee a known execution time, while a trie varies based on the data.</p>
30,507
<p>I recently began profiling an osgi java application that I am writing using VisualVM. One thing I have noticed is that when the application starts sending data to a client (over JMS), the number of loaded classes starts increasing at a steady rate. The Heap size and the PermGen size remains constant, however. The...
<blockquote> <p>Are you dynamically creating new classes on the fly somehow?</p> </blockquote> <p>Thanks for your help. I figured out what the problem is. In one of my classes, I was using Jaxb to create an XML string. In doing this, JAXB ueses reflection to create a new class.</p> <pre><code>JAXBContext context...
<p>Yes, it's usually a memory leak (since we don't really deal with memory directly, it's more of a class instance leak). I've gone through this process before and usually it's some listener added to an old toolkit that didn't remove it self.</p> <p>In older code, A listener relationship causes the "listener" object ...
20,260
<p>I'm trying to implement a dynamic OPTION list in JavaScript. Depending on other selections in the web form, some of the OPTIONS in a specific SELECT are not valid. Things I've tried that don't work in IE are: </p> <ul> <li>populate all options, then set the disabled property for those that are invalid</li> <li>po...
<p><a href="http://webbugtrack.blogspot.com/2007/11/bug-293-cant-disable-options-in-ie.html" rel="nofollow noreferrer">IE doesn't support the disabled attribute on options</a>, and worse yet, <a href="http://webbugtrack.blogspot.com/2007/11/bug-280-lack-of-events-for-options.html" rel="nofollow noreferrer">IE doesn't s...
<p>Is it such a problem to repopulate the select with just the valid options? I've used this method many times and haven't encountered any problems.</p>
39,034
<p>I have a listview working in virtual mode, in the LargeIcons view. Retrieves are expensive, so I want to ask for the data for all the visible items. How do I get the start index and total number of the visible items?</p> <p>Update: I am aware of the CacheVirtualItems event. The third-party database we're using t...
<p>THE REAL Answer is :<br> * get the ScrollViewer of the ListView.<br> * ScrollViewer.VerticalOffset is the index of first shown item.<br> * ScrollViewer.ViewportHeight is the number of items shown. </p> <p>To get the ScrollViewer, you will need a function, FindDescendant(FrameworkElement, Type) that will search w...
<pre><code>foreach (var t in listView1.Items) { var lvitem = listView1.ItemContainerGenerator.ContainerFromItem(t) as ListViewItem; if (lvitem == null) continue; //lvitem will = null if it is not visible // otherwise do stuff with lvitem such as: lvitem....
48,623
<p>Do any of the existing JavaScript frameworks have a non-regex <code>replace()</code> function, or has this already been posted on the web somewhere as a one-off function?</p> <p>For example I want to replace <code>"@!#$123=%"</code> and I don't want to worry about which characters to escape. Most languages seem to ...
<p>i may be misunderstanding your question, but javascript does have a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace" rel="noreferrer"><code>replace()</code></a></p> <pre><code>var string = '@!#$123=%'; var newstring = string.replace('@!#$123=%', 'hi'); </code...
<p>You can do it with or without ignoring case sensitivity. <br /> Sadly, JavaScript's indexOf doesn't take locale vs. invariant as argument, so you'll have to replace <code>toLowerCase</code> with <code>toLocaleLowerCase</code> if you want to preserve culture-specifity. </p> <pre><code>function replaceAll(str, find, ...
36,705
<p>I'm using <code>System.Windows.Media.MediaPlayer</code> to play some sounds, and I would like to load these sounds from a ZIP file. It would be nice to be able to load these files as a stream directly from the zip file instead of having to unzip to a temp directory. However, <code>MediaPlayer.open</code> only accept...
<p>This is only useful if you are actually vigilant with tracking and reviewing. When I was working on a team, no matter how much documented that for example our servers in the production environment were natted and would not be able to resolve their own domain names or public IP addresses, every 6 months, I'd get a ca...
<p>I would also want to ask the question of how much time would be required to accurately track the mistakes, and if that time could be better spent directly on improving the software instead. If you can do this in a minimal amount of time and are able to refer back to your records to prevent future mistakes, it may be...
38,114
<p>I'd like to line up items approximately like this:</p> <pre><code>item1 item2 i3 longitemname i4 longitemname2 anotheritem i5 </code></pre> <p>Basically items of varying length arranged in a table like structure. The tricky part is the container for these can vary in size and I'...
<p>This can be done using floated div's, calculating the max width, and setting all widths to the max. Here's jquery code to do it:</p> <p>html:</p> <pre><code>&lt;div class="item"&gt;something&lt;/div&gt; &lt;div class="item"&gt;something else&lt;/div&gt; </code></pre> <p>css:</p> <pre><code>div.item { float: left...
<p>You could use block level elements floated left, but you will need some javascript to check the sizes, find the largest one, and set them all to that width.</p> <p>EDIT: Just read the second half of your post, and saw that you suggested just this fix. Count this post as +1 for your current idea :)</p>
14,962
<p>Basically I would like to find a way to ddo something like:</p> <pre><code>&lt;asp:Label ID="lID" runat="server" AssociatedControlID="txtId" Text="&lt;%# MyProperty %&gt;"&gt;&lt;/asp:Label&gt; </code></pre> <p>I know I could set it from code behind (writing lId.Text = MyProperty), but I'd prefer doing it in the m...
<p>You can do </p> <pre><code>&lt;asp:Label runat="server" Text='&lt;%# MyProperty %&gt;' /&gt; </code></pre> <p>And then a Page.DataBind() in the codebehind.</p>
<p>Call lID.Databind() from code-behind</p>
9,916
<p>I'd like to add a drop-down list to a Windows application. It will have two choices, neither of which are editable. What's the best control to use? Is it a combo box with the editing property set to No?</p> <p>I'm using Visual Studio 2008.</p>
<p>I'd suggest taking a look at the <a href="http://msdn.microsoft.com/en-us/library/aa511258.aspx" rel="nofollow noreferrer">Windows Vista User Experience Guide</a>. It sounds like you might be better off with radio buttons, or, if it's an explicit on/off type of situation, using a check box. I think we'd really need ...
<p>Set the DropDownStyle property to DropDownList.</p> <p>See <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.combobox.dropdownstyle(VS.80).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/system.windows.forms.combobox.dropdownstyle(VS.80).aspx</a></p>
12,779
<p>Using C# and System.Data.SqlClient, is there a way to retrieve a list of parameters that belong to a stored procedure on a SQL Server before I actually execute it?</p> <p>I have an a "multi-environment" scenario where there are multiple versions of the same database schema. Examples of environments might be "Develo...
<p>You can use SqlCommandBuilder.DeriveParameters() (see <a href="https://web.archive.org/web/20110304121600/http://www.davidhayden.com/blog/dave/archive/2006/11/01/SqlCommandBuilderDeriveParameters.aspx" rel="nofollow noreferrer">SqlCommandBuilder.DeriveParameters - Get Parameter Information for a Stored Procedure - A...
<p>All of these ADO.NET solutions are are asking the code library to query the database's metadata on your behalf. If you are going to take that performance hit anyhow, maybe you should just write some helper functions that call </p> <pre><code>Select count(*) from information_schema.parameters where ...(proc name =....
5,385
<p>I'd like to find a few large .NET projects that have public source code available.</p>
<p>For winforms development, <a href="http://www.icsharpcode.net/OpenSource/SD/" rel="nofollow noreferrer">SharpDevelop</a>.</p>
<p>Data &amp; Object Factory has a sample application that they publish (<em>Patterns in Action</em>) to showcase design patterns in .NET. The application shows implemetation of the design patterns from the Gang of Four and .NET versions of the patterns from <em>Head First Design Patterns</em>. It's all done in C#, and...
49,740
<p>I'm using the Fish Gadget (<a href="http://abowman.com/google-modules/fish/" rel="noreferrer">http://abowman.com/google-modules/fish/</a>) within a wiki based CMS, and need to reposition the gadget from one HTML element to another. (Note: the fish gadget is an example -- the problem occurs with other gadgets as well...
<p>Whenever you append a script element into a page, using jQuery, it will attempt to execute it. Thus when you move ig_reset (which is only a table - no script) it works without issue. When you try to move the wrapper - which contains the script - the script is moved and re-executed.</p> <p>We're working to fix this ...
<p>As John Resig notes, this <em>is</em> a jQuery issue. You can verify this by replacing your handler</p> <pre><code>$("#with-wrapper").click(function () { $('.sidebar-content-wrapper').contents().appendTo($("#sidebar")); }); </code></pre> <p>with one that avoids using the jQuery methods to actually move each el...
41,138
<p>I was recently tasked with debugging a strange problem within an e-commerce application. After an application upgrade the site started to hang from time to time and I was sent in to debug. After checking the event log I found that the SQL-server wrote ~200 000 events in a couple of minutes with the message saying th...
<p>Are you operating in explicit or implicit <a href="http://doc.ddart.net/mssql/sql70/ta-tz_8.htm" rel="nofollow noreferrer">transaction mode</a>?</p> <p>Since you're in explicit mode, I think you need to surround the DELETE operation with BEGIN TRANSACTION and COMMIT TRANSACTION statements.</p> <pre><code>WHILE EXI...
<p>I not sure if I understand the problem, but in the select clause it's making an inner join with another table. That join can cause to get no records and then the delete fails. Try using a left join.</p>
18,107
<p>What is the data that Process and Thread will not share ? </p> <p>An advance thanks goes to everybody who provide their time</p>
<p>Separate processes do not share any data with each other.</p> <p>Threads can share any heap-allocated or static data if they are running within the same process.</p>
<p>On UNIX, processes can share file descriptors with their child processes if the file descriptors are not set to close on exec (<code>FD_CLOEXEC</code>). Likewise, Windows supports sharing handles with child processes by setting <code>lpSecurityAttributes-&gt;bInheritHandle</code> to <code>TRUE</code> when calling <c...
21,344
<p>I'm looking around for a Java <a href="http://en.wikipedia.org/wiki/Code_signing" rel="noreferrer">code signing</a> certificate so my Java applets don't throw up such scary security warnings. However, all the places I've found offering them charge (in my opinion) way too much, like over USD200 per year. While doing ...
<p>Short answer: No, they're different.</p> <p>Long answer: It's the same sort of certificate and it uses the same crypto software, but the certificate has flags indicating what it is allowed to be used for. Code signing and web server are different uses. </p>
<p>Thawte offers code signing certificates <a href="http://www.thawte.com/code-signing/" rel="nofollow noreferrer">here</a>. I imagine other Certificate Authorities offer this service as well. You can also create self-signed certificates, with <a href="http://java.sun.com/j2se/1.5.0/docs/tooldocs/solaris/keytool.html" ...
10,431
<p>I have a UserControl Library solution which has the following </p> <p>UserControl ---UserControl project</p> <pre><code> ---UserControl Test Project </code></pre> <p>IN my test project, I am able to add my usercontrol to the tool box. When i drag it and drop it in my forms, it fails. I put in logging and f...
<p>Beware, I have found the DesignMode property to be unreliable where you have a control on another control on a form (say). It only seems to work for controls placed directly on the design surface.</p>
<p>Do you need the config file at design time? If not, you could change your code to test if it is running at design time, something like:</p> <pre><code>if (this.Site != null &amp;&amp; this.Site.DesignMode) { ... design time behavior } else { ... runtime behavior (read config file) } </code></pre>
46,963
<p>I may be barking up the wrong tree... However, what I have is a MySQL server that accepts connections only from a client with a valid SSL cert (see <a href="http://dev.mysql.com/doc/refman/5.0/en/secure-create-certs.html" rel="nofollow noreferrer">this link</a>). This works great for example with Rails. I have my da...
<p>in your <code>config.inc.php</code> add this line after applicable server stuff: </p> <pre><code>$cfg['Servers'][$i]['ssl']=true; </code></pre> <p>Assuming your php and its mysql client is configured with SSL in mind this should work. </p>
<p>I agree, the answer is not sufficient. The place everybody tells you to put your SSL certificate and pointer is in a <code>conf.d</code> virtualhost block. But that is for inbound traffic. Only if your <code>phpmyadmin</code> is being accessed from the IP address of the mysql server but that is NOT the case with ...
42,995
<p>In a <strong>Win32</strong> environment, you can use the <strong>GetLastInputInfo API</strong> call in <a href="https://learn.microsoft.com/windows/desktop/api/winuser/nf-winuser-getlastinputinfo" rel="nofollow noreferrer">Microsoft documentation</a>. Basically, this method returns the last tick that corresponds wi...
<p>As for Linux, I know that Pidgin has to determine idle time to change your status to away after a certain amount of time. You might open the source and see if you can find the code that does what you need it to do.</p>
<p>You seem to have answered your own question there Nathan ;-) "GetLastInputInfo" is the way to go.</p> <p>One trick is that if your application is running on the desktop, and the user connects to a virtual machine, then GetLastInputInfo will report no activity (since there is no activity on the host machine).</p> <...
2,480
<p>I use ssh-agent with password-protected keys on Linux. Every time I log into a certain machine, I do this:</p> <pre><code>eval `ssh-agent` &amp;&amp; ssh-add </code></pre> <p>This works well enough, but every time I log in and do this, I create another ssh-agent. Once in a while, I will do a <code>killall ssh-agen...
<p>have a look at Keychain. It was written b people in a similar situation to yourself. <a href="http://www.gentoo.org/proj/en/keychain/" rel="noreferrer">Keychain</a></p>
<p>Depending on which shell you use, you can set different profiles for login shells and mere regular new shells. In general you want to start ssh-agent for login shells, but not for every subshell. In bash these files would be <code>.bashrc</code> and <code>.bash_login</code>, for example.</p> <p>Most desktop linux...
12,791
<p>Im using asynchronous threading in my application WITH httpClient. I make a call using the Future Api like so </p> <pre><code>mStrResults = (String) rssFuture.get(); </code></pre> <p>this call attempts to retrieve an html string returned from my Callable httpClient call() method.</p> <p>What i want to do however...
<p>I'm not sure I understand your format exactly (it displays a little strange to me) but the easiest way to do this is <code>with - (NSArray *)componentsSeparatedByString:(NSString *)separator</code> which is a method in the NSString class... example:</p> <pre><code>NSArray *components = [myString componentsSeperated...
<p>I had a feeling more than a flat list is wanted. If you want a multidimensional structure you can do something like this:</p> <pre><code>NSArray *lines = [data componentsSeparatedByString:@"\n"]; for (NSString *line in lines) { NSArray *fields = [line componentsSeparatedByString:@"\t"]; // Do something her...
45,969
<p>I'd like to make a video tutorial for my SDK--one of those videos that shows the screen while some dude talks about what he's doing. Can someone direct me to easy and preferably free tools for doing so?</p> <p>Desired features: - Cuts (recording several snippets of video and putting them together afterward) - Subti...
<p>Camtasia is very good. I've also used wink, it is flash instead of video, but you can add navigation controls and text boxes. </p>
<p>a cool tool for screencasting is Camtasia Studio <a href="http://www.techsmith.com/camtasia.asp" rel="nofollow noreferrer">http://www.techsmith.com/camtasia.asp</a> with a free 30 day trial</p> <p>example : <a href="http://static.interspire.com/isc-demo/index.html" rel="nofollow noreferrer">http://static.interspire...
41,142
<p>Is there a way on the CVS command line to list all files associated with a tag?</p>
<p>About the closest you'll be able to get is with this:</p> <p>cvs -q log -R -N -S -rTAGNAME</p> <p>This works against local copy, it doesn't pull from the server.</p> <p>EDIT:</p> <p>As Ken mentioned, a slight variation will make it pull from the server, but in this situation you need to specify the module name t...
<p>I think it's</p> <pre><code>cvs ls -lR -r tag </code></pre> <p>but I'm on SVN now, so you'll have to test it.</p>
34,277
<p>While calculating the hash table bucket index from the hash code of a key, why do we avoid use of remainder after division (modulo) when the size of the array of buckets is a power of 2?</p>
<p>When calculating the hash, you want as much information as you can cheaply munge things into with good distribution across the entire range of bits: e.g. 32-bit unsigned integers are usually good, unless you have a lot (>3 billion) of items to store in the hash table.</p> <p>It's converting the hash code into a buc...
<p>Let us say that the table size is m = 2^p. Let k be a key. Then, whenever we do k mod m, we will only get the last p bits of the binary representation of k. Thus, if I put in several keys that have the same last p bits, the hash function will perform VERY VERY badly as all keys will be hashed to the same slot in the...
35,042
<p>I was in the process of printing a 16 hour print, but I must have failed to copy the G-code correctly, because the print stopped after 107 of 223 layers. Looking at the G-code, It also stops there. </p> <p>However, I had the full G-code on my computer, and decided to try and resume the print from layer 108. It seem...
<p>According to the RepRap.org <a href="http://reprap.org/wiki/G-code" rel="nofollow noreferrer">list of G-Code commands</a>, see <strong><a href="http://reprap.org/wiki/G-code#G0_.26_G1:_Move" rel="nofollow noreferrer">G0 &amp; G1: Move</a></strong>:</p> <blockquote> <p>The <code>Ennn</code> command is <em>The amou...
<p>Is the hotend temperature set correctly? If you only preheat the hotend but then turn it off, it will behave exactly as you described (while you're above <code>EXTRUDE_MINTEMP</code> it will behave normally, but once the temperature drops too low it will continue doing the XYZ-moves, but stop extruding). Perhaps you...
230
<p>I am wondering what makes sense in relation to what objects to expose through a WCF service - should I add WCF Serialization specifications to my business entities or should I implement a converter that maps my business entities to the DataContracts that I want to expose through my WCF service?</p> <p>Right now I h...
<p>In general, I think from a best practices standpoint, you should not expose the structure of your business objects as data contracts, but rather define "data contract-specific" classes and convert Business to Contract. It may require extra work, but from a separation of concerns and protection from change standpoin...
<p>Just to add to the above answers: The object that the webservice exposes is called the Data Transfer Object (DTO). Having a DTO to map your Business Entity object (BEO) is good because of the separation it provides between your webservice and the actual implementation/logic that lies behind the web-service.</p> <p>...
10,919
<p>Im trying to extract a line from wget's result but having trouble with it. This is my wget call:</p> <pre><code>$ wget -SO- -T 1 -t 1 http://myurl.com:15000/myhtml.html </code></pre> <p>Output:</p> <pre> --18:24:12-- http://xxx.xxxx.xxxx:15000/myhtml.html => `-' Resolving xxx.xxxx.xxxx... xxx.xxxx.xxx...
<p>The output of wget you are looking for is written on stderr. You must redirect it:</p> <pre><code>$ wget -SO- -T 1 -t 1 http://myurl.com:15000/myhtml.html 2&gt;&amp;1 | egrep -i "302" </code></pre>
<p>I found this question trying to scrape response codes to large lists of URLs after finding <code>curl</code> very slow (5+s per request).</p> <p>Previously, I was using this:</p> <p><code>curl -o /dev/null -I --silent --head --write-out %{http_code} https://example.com</code></p> <p>Building off Piotr and Adam's ans...
38,796
<p>I have an ASP.NET 2.0 application that spends an excessive amount of time in garbage collection, over 40%, when load tested on a production grade server (dual quad-core, 4g). I have been trying to isolate the problem but it is a large, complex code base making for slow going. There are no GC.Collect() calls. Whic...
<p>I've found the debugging labs on <a href="http://blogs.msdn.com/tess/" rel="nofollow noreferrer">Tess Ferrandez's blog</a> very helpful when looking at these sorts of issues.</p>
<p>Well, first off, my trick knee is acting up, and when it does that, it either means it's about to snow, or someone has been using a lot of "+" operators for string concatenation instead of using StringBuilder as the good lord intended.</p> <p>What about <a href="http://www.red-gate.com/Products/ants_profiler/index....
49,774
<p>In the clocks application, the timer screen shows a picker (probably a <code>UIPicker</code> in <code>UIDatePickerModeCountDownTimer</code> mode) with some text in the selection bar ("hours" and "mins" in this case).</p> <p>(edit) Note that these labels are <strong>fixed</strong>: They don't move when the picker wh...
<p>Create your picker, create a label with a shadow, and push it to a picker's subview below the selectionIndicator view. </p> <p>It would look something like this</p> <pre><code> UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(135, 93, 80, 30)] autorelease]; label.text = @"Label"; label.font = [UIFont b...
<p>Can you show where you define pickerTop and pickerSize?</p> <pre><code> CGFloat pickerTop = timePicker.bounds.origin.y; CGSize pickerSize = timePicker.bounds.size; </code></pre> <p>That is what I have, but pickerTop seems to be wrong.</p> <p>mike</p>
47,964
<p>I need to increase the max_allowed_packet param, to fit some theoretically very large items. If I set this param to say 10M, what price if any am I paying compared to setting it to 1M or 4M. Thanks for any input! Tomas</p>
<p>I found this explanation: <code>http://www.astahost.com/info.php/max_allowed_packet-mysql_t2725.html</code></p> <blockquote> <p>It's safe to increase the value of this variable because the extra memory is allocated only when needed. For example, mysqld allocates more memory only when you issue a long quer...
<p>I suggest not touching this variable, instead adjusting your storage implementation to handle any size files using the default settings.</p> <p>Can you see <a href="http://www.dreamwerx.net/phpforum/?id=1" rel="nofollow noreferrer">here</a> for an example.</p>
37,768
<p>I need to use JUnit 4.4 (or newer) in a set of eclipse plugin tests, but I've run into the following problem:</p> <p>Tests are not detected when running with the junit 4.4 or 4.5 bundles from springsource (<a href="http://www.springsource.com/repository/app/bundle/version/detail?name=com.springsource.org.junit&amp;...
<p>I cannot test this right now as I don't have an Eclipse 3.4 installation handy, but I've run across a similar problem a while ago in (I think) IntelliJ IDEA 7.0.x, and a workaround was to explicitly specify a test runner. </p> <p>With JUnit 4.5:</p> <pre><code>import org.junit.runners.JUnit4; @RunWith(JUnit4.clas...
<p>I don't know which version of JUnit it was, but to succesfully find test the test methods name must start with the word "<strong>test</strong>".</p> <p>In newer version you can simply mark test with @Test, for me it works in this combination:</p> <pre><code>import static junit.framework.Assert.*; ... @Test pu...
31,369
<p>Simple as the title states: Can you use only Java commands to take a screenshot and save it? Or, do I need to use an OS specific program to take the screenshot and then grab it off the clipboard?</p>
<p>Believe it or not, you can actually use <a href="http://java.sun.com/javase/6/docs/api/java/awt/Robot.html#createScreenCapture&#40;java.awt.Rectangle&#41;" rel="noreferrer"><code>java.awt.Robot</code></a> to "create an image containing pixels read from the screen." You can then write that image to a file on disk.</p...
<p>You can use <code>java.awt.Robot</code> to achieve this task.</p> <p>below is the code of server, which saves the captured screenshot as image in your Directory.</p> <pre><code>import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.net.ServerSocket; import java.net.Socket...
8,267
<p>So here's what I've got: </p> <ul> <li>An NSTableView with an NSMutableArray data source</li> <li>FSEvents monitoring a folder that contains the file that contains the data for the table view (Using <a href="http://stuconnolly.com/blog/archive/2008/05/08/fsevents-objectivec-wrapper" rel="nofollow noreferrer">SCEven...
<p>We call <strong>reloadData</strong> on NSTableView when we have new data to add/remove to the table.</p> <p>This might help, to force the NSTableView to redraw. </p> <p>I'm not really sure if this is what your asking though. The wording of your question is kind of confusing, you state a series of events, but never...
<p>Have you tried calling your method from your FSEvent on a second pass of the run-loop?</p> <pre><code>[myObject performSelector:@selector(reloadAction:) withObject:nil afterDelay:0.0]; </code></pre>
42,540
<p>I asked a question about Lua perfromance, and on of the <a href="https://stackoverflow.com/questions/124455/how-do-you-pre-size-an-array-in-lua#152894">responses</a> asked:</p> <blockquote> <p>Have you studied general tips for keeping Lua performance high? i.e. know table creation and rather reuse a table than cr...
<p>In response to some of the other answers and comments:</p> <p>It is true that as a programmer you should generally avoid premature optimization. <em>But</em>. This is not so true for scripting languages where the compiler does not optimize much -- or at all.</p> <p>So, whenever you write something in Lua, and that...
<p>Keep tables short, the larger the table the longer the search time. And in the same line iterating over numerically indexed tables (=arrays) is faster than key based tables (thus ipairs is faster than pairs)</p>
18,699
<p>I was wondering how common it is to find genetic algorithm approaches in commercial code.</p> <p>It always seemed to me that some kinds of schedulers could benefit from a GA engine, as a supplement to the main algorithm.</p>
<p>Genetic Algorithms have been widely used commercially. Optimizing train routing was an early application. More recently fighter planes have used GAs to optimize wing designs. I have used GAs extensively at work to generate solutions to problems that have an extremely large search space.</p> <p>Many problems are unl...
<p>LibreOffice Calc uses it in its Solver module.</p>
39,147
<p>I have some code which collects points (consed integers) from a loop which looks something like this:</p> <pre><code>(loop for x from 1 to 100 for y from 100 downto 1 collect `(,x . ,y)) </code></pre> <p>My question is, is it correct to use <code>`(,x . ,y)</code> in this situation?</p> <p>E...
<p>It would be much 'better' to just do (cons x y). </p> <p>But to <strong>answer the question</strong>, there is nothing wrong with doing that :) (except making it a tad slower).</p>
<p>Why not just</p> <pre><code>(cons x y) </code></pre> <p>By the way, I tried to run your code in CLISP and it didn't work as expected. Since I'm not a big fan of the loop macro here's how you might accomplish the same thing recursively:</p> <pre><code>(defun genint (stop) (if (= stop 1) '(1) (append (genin...
12,697
<p>I have a SQL Server 2005 database and I have 4 GB of text files that I need to import into it. The question is, if these 4 GB of text files are 1.2 GB when they are zipped, how big would the database be if they are imported? Does SQL Server shrink data by default, or how would I set this (think create a database as ...
<p>SQL Server will not shrink data by default. In fact, there will be a small overhead per column and row, so it would require more space. </p> <p>If you really must store those files in the DB (it is recommended that you don't), take a look at this <a href="http://mitch-wheat.blogspot.com/2007/05/save-and-restore-fi...
<p>There is no automatic compression - although you could put compressed data in columns it will be difficult to search.</p> <p>Are these being imported into a set of normalized tables? Are there spaces or other data which will be stripped (commas)?</p> <p>If so, you can expect space savings from the normalization a...
21,490
<p>I have a J2ee application where I basically want two objects, created by two separate servlets to communicate directly and I need these intances to be stable, i.e. to "know" each other during the session.</p> <p>The sequence is roughly: <br></p> <ol> <li>Client sends a request to Servlet #1, which creates object A...
<p>And what stops you from using the Session? You don't need JNDI, just place your object into session under a predefined name. If the communication object is application-wide, use Singleton. </p> <p>P.S. It looks to me you're doing something weird, while the solution could in fact be simpler. Can you describe the tas...
<p>To be honest: I don't fully understand what you are trying to achieve. Can you perhaps try to explain the problem you are trying to solve instead of the solution?</p> <p>What do these objects depend on? Are they user specific? Then put them into the session and you can retrieve them from the session again (request....
31,406
<p>There are various documents describing threading on Solaris/Linux, but nowwhere describing the Windows implementation. I have a passing interest in this, it seems strange that something so critical is (seemingly) not documented.</p> <p>Threading is not the same on different OS' - "Write Once, Run Anywhere" isn't tr...
<p>It really depends on the specific JVM implementation. I assume you're wondering about Sun's Windows JVM, and I can tell you with certainty that the Sun JVM maps a Java thread to an OS thread.</p> <p>You could try spawning up a couple of threads from Java code, open up Task Manager and see what happened.</p>
<p>That document is a little more about Solaris threading than the Java threading model. All JVMs call the native thread API of the OS they're written for so there is always one Java thread for an OS thread. The diagram in the document shows that it's not until the threads are in the OS space that they change. Each OS ...
9,277
<p>How can you depend on test code from another module in Maven? </p> <p>Example, I have 2 modules:</p> <ul> <li>Base</li> <li>Main</li> </ul> <p>I would like a test case in Main to extend a base test class in Base. Is this possible?</p> <p>Update: Found an <a href="https://stackoverflow.com/questions/174560/shar...
<p>I recommend using <a href="https://maven.apache.org/pom.html#Dependencies" rel="noreferrer">type instead of classifier</a> (see also: <a href="http://maven.apache.org/plugins/maven-deploy-plugin/examples/deploying-with-classifiers.html" rel="noreferrer">classifier</a>). It tells Maven a bit more explicitly what you...
<p>Yep ... just include the Base module as a dependency in Main. If you're only inheriting test code, then you can use the scope tag to make sure Maven doesn't include the code in your artifact when deployed. Something like this should work:</p> <pre><code>&lt;dependency&gt; &lt;groupId&gt;BaseGroup&lt;/groupId&...
21,039
<p>I'm on Windows Vista and IE7.</p> <p>Here's what I'd like to do:</p> <ol> <li>I have two flash files: <code>page1.swf</code> and <code>page2.swf</code>. They are just page from a magazine.</li> <li>Display <code>page1.swf</code></li> <li>Have a button that says "Change page"</li> <li>When I click the button; displ...
<p>This is more complicated but I've had to resort to this scenario before because machine and user profile settings sometimes don't match your visitor's preferences. For example, a UK visitor accessing your site temporarily from an Australian server.</p> <ol> <li><p>Use a geolocation service (e.g MaxMind.com) as sugg...
<p>In any of the events prior to Page Unload...Request.ServerVariables. If you want their physical timezone then you check their IP address and use an IP to Geo-Location conversion tool. </p> <p>I'm not sure if there's another way you can do it, so if you require the timezone their computer is configured for, it wou...
43,940
<p>I'm looking to have two versions of BOOST compiled into a project at the same time. Ideally they should be usable along these lines:</p> <pre><code>boost_1_36_0::boost::shared_ptr&lt;SomeClass&gt; someClass = new SomeClass(); boost_1_35_0::boost::regex expression("[0-9]", boost_1_35_0::boost::regex_constants::basi...
<p>I read (well scanned) through the <a href="http://thread.gmane.org/gmane.comp.lib.boost.devel/180008" rel="noreferrer">development list discussion</a>. There's no easy solution. To sum up:</p> <ol> <li><p>Wrapping header files in a namespace declaration </p> <pre><code>namespace boost_1_36_0 { #include &lt;...
<p>You'll have a world of trouble linking because the mangled names will be different. And yes, I see you knew that, but it seems like it will be trouble all around.</p>
14,940
<p>I am wondering what copy-local=true for references exactly does. Does it copy the referenced assembly along with all of its dependencies to the output directory?</p> <p>My scenario is the following: I have a custom log wrapper that utilizes log4net. I build a release assembly of MyLogWrapper.dll with log4net.dll re...
<p>Unfortunately it appears that according to the following statement taken from the <a href="http://msdn.microsoft.com/en-us/library/ez524kew(VS.80).aspx" rel="noreferrer">MSDN documentation</a> the CopyLocal functionality does not work as expected for assemblies already in the GAC.</p> <blockquote> <p>If you deplo...
<p>I've found that this is no more respected in Visual Studio 2015 with project references if the referenced project has a dependency to a GAC assembly. The GAC assembly is always copied to the root project output and copy local = false being respected only regarding the output of the project holding the reference to t...
41,431
<p>I run a 3D printer farm and I have to replace my Bowden tubes on the printers after about a month or two of use(roughly 1000 hours of use). The Bowden tubes continually melt on the side of the tube very near to where it pushes against the nozzle. I am running Ender 3 Pros and I run at about 205&nbsp;&deg;C with PLA....
<p>If the tube is PTFE, the tube is not likely to be melting unless your hotend temperature is out of control. You would probably notice the PLA cooking.</p> <p>So, perhaps they aren't PTFE, or perhaps it is wear.</p> <p>If it wasn't PTFE, you should be able to tell by the texture, slipperiness, and bending force.</...
<p>After a lot of hard work and months of replacing and inspecting this issue I realized what's going on. The bowden tube gets soft as it gets hotter and hotter which allows the filament which is being extruded and retracted at a high speed to wear down the side of the tube. After some time the tube gets stretched out ...
1,592
<p>I have a small lightweight application that is used as part of a larger solution. Currently it is written in C but I am looking to rewrite it using a cross-platform scripting language. The solution needs to run on Windows, Linux, Solaris, AIX and HP-UX.</p> <p>The existing C application works fine but I want to hav...
<p>Lua is a scripting language that meets your criteria. It's certainly the fastest and lowest memory scripting language available.</p>
<p>I agree with others in that you should probably try to make this a more portable C app instead of porting it over to something else since any scripting language is going to introduce significant overhead from a startup perspective, have a much larger memory footprint, and will probably be much slower.</p> <p>In my ...
42,526
<p>In PowerShell, even if it's possible to know if a drive is a network drive: see <a href="https://stackoverflow.com/questions/158359/in-powershell-how-can-i-determine-if-the-current-drive-is-a-networked-drive-or">In PowerShell, how can I determine if the current drive is a networked drive or not?</a></p> <p>When I t...
<p>Try WMI:</p> <pre><code>Get-WMIObject -query "Select ProviderName From Win32_LogicalDisk Where DeviceID='H:'" </code></pre>
<p>$drive = gwmi win32_logicaldisk -filter "DeviceID='H:'" if($drive.DriveType -eq 4) {write-host "drive is a network share"}</p>
19,173
<p>The method signature of a Java <code>main</code>method is:</p> <pre><code>public static void main(String[] args) { ... } </code></pre> <p><strong>Is there a reason why this method must be static?</strong></p>
<p>The method is static because otherwise there would be ambiguity: which constructor should be called? Especially if your class looks like this:</p> <pre><code>public class JavaClass{ protected JavaClass(int x){} public void main(String[] args){ } } </code></pre> <p>Should the JVM call <code>new JavaClass(int...
<p>because, a static members are not part of any specific class and that main method, not requires to create its Object, but can still refer to all other classes.</p>
17,649
<p>I tried the example from Rails Cookbook and managed to get it to work. However the <code>text_field_with_auto_complete</code> works only for one value.</p> <pre><code>class Expense &lt; ActiveRecord::Base has_and_belongs_to_many :categories end </code></pre> <p>In the New Expense View rhtml</p> <pre><code>&lt;%...
<p>If you are just trying to support multiple instances of autocomplete per field, you can pass a delimiter to the autocomplete options with the symbol :token. This provides a delimiter to allow multiple results. Stackoverflow would use :token => ' ' (there should be a space between the quotes, but the autoformat i...
<p>This is not quite your question, but I wouldn't recommend using HABTM anymore. You should create a join model and use has_many :through. (In your case you'd create a new model called ExpenseCategoryAssignment, or something)</p> <p>The problem is that HABTM creates ambiguities that rails doesn't like, and it tends...
31,155
<p>I need to send and receive data over serial connections (RS-232 and RS-422).</p> <p>How do I set up and communicate with such a connection? How do I figure out what the configuration settings (e.g. baud rate) should be and how do I set them?</p> <p>In particular I am looking to do this in Java, C/C++, or one of t...
<p>Build a time machine and go back to 1987? Ho ho.</p> <p>Ok, no more snarky comments.</p> <blockquote> <p>How do I figure out what the configuration settings (e.g. baud rate) should be...</p> </blockquote> <p>Read the datasheet? Ok, ok. Seriously, last one. If you don't know the baud rate of the device you are t...
<p>I have been using purejavacomm: <a href="http://www.sparetimelabs.com/purejavacomm/index.html" rel="nofollow">It is an implementation of javax.comm written in pure java + JNA</a></p> <p>Unlike rxtx, you don't need to install a dll. It is written in pure Java + JNA, which solved the problem of portability between Wi...
2,519
<p>Which XML validation tools can you recommend for both performance and accuracy, each of which is a critical issue on our system? We have the following requirements:</p> <ul> <li>It is <em>not</em> xmllint (see below)</li> <li>Supports RelaxNG</li> <li>Can easily integrate with Perl (this is optional, but it would ...
<p>I think that JDrago has the right idea, that you need to avoid libxml2-based tools for RNG validation, at least for now. I'm discovering this as well in my project. I recently logged two bugs against libxml2 concerning RNG validation.</p> <p>I recommend <a href="http://code.google.com/p/jing-trang/" rel="noreferr...
<p>I suspect xmllint uses the same underlying libraries (libxml2, etc) as anything else. It is counterintuitive to think that another front-end to the same library would give different results.</p>
32,267
<p>How would you reccommend handling RSS Feeds in ASP.NET MVC? Using a third party library? Using the RSS stuff in the BCL? Just making an RSS view that renders the XML? Or something completely different?</p>
<p>Here is what I recommend:</p> <ol> <li>Create a class called RssResult that inherits off the abstract base class ActionResult.</li> <li>Override the ExecuteResult method.</li> <li>ExecuteResult has the ControllerContext passed to it by the caller and with this you can get the data and content type.</li> <li><p>Once...
<p>I got this from Eran Kampf and a Scott Hanselman vid (forgot the link) so it's only slightly different from some other posts here, but hopefully helpful and copy paste ready as an example rss feed.</p> <p><a href="http://achadwick.com/Blog/Result/MVC%20RSS%20Feed" rel="nofollow noreferrer">From my blog</a></p> <p>...
3,302
<p>For those of you in the Visual Studio environment, how do you feel about wrapping any of your code in #regions? (or if any other IDE has something similar...)</p>
<p>9 out of 10 times, code folding means that you have failed to use the <a href="http://en.wikipedia.org/wiki/Separation_of_concerns" rel="noreferrer">SoC principle</a> for what its worth.<br /> I more or less feel the same thing about partial classes. If you have a piece of code you think is too big you need to chop ...
<p>I prefer #regions myself, but an old coworker couldn't stand to have things hidden. I understood his point once I worked on a page with 7 #regions, at least 3 of which had been auto-generated and had the same name, but in general I think they're a useful way of splitting things up and keeping everything less clutter...
2,780
<p>Anyone have any idea how to do the following?</p> <p>declare cursor open cursor fetch cursor &lt;&lt; Start reading the cursor in a LOOP >> Lets say the cursor have 10 records. Read until 5th record then go to the 6th record and do some checking.</p> <p>Now, is it possible to go back to 5th record from 6th record...
<p>Depends on the requirements.</p> <p>You can use the LAG() and LEAD() analytic functions to get information for the next and prior rows, i.e.</p> <pre><code>SQL&gt; ed Wrote file afiedt.buf 1 select ename, 2 sal, 3 lead(sal) over (order by ename) next_sal, 4 lag(sal) over (order by...
<p>How far do you need to go back? If you only need a look-ahead of one row, you could buffer just the previous row in your loop (application-side).</p>
20,841
<p>Can anyone recommend a good 3rd party control(s) for MS SQL 2005 Reporting Services. If you know some open library or implementation of such controls that could be very useful too.</p>
<p>Dundas do great RS add-ins if you have the budget:</p> <p><a href="http://www.dundas.com/index.aspx" rel="nofollow noreferrer">http://www.dundas.com/index.aspx</a></p>
<p>I agree, Dundas has great controls. I used it in one of my projects.</p> <p>This was the sample which I used to test out the CRI: <a href="http://www.codeplex.com/MSFTRSProdSamples/Wiki/View.aspx?title=SS2005%21Custom%20Report%20Item%20Sample&amp;referringTitle=Home" rel="nofollow noreferrer">http://www.codeplex.co...
13,090
<p>In ColdFusion, under Request Tuning in the administrator, how do I determine what is an optimal number (or at least a good guess) for the Maximum Number of Simultaneous Template Requests?</p> <p>Environment:<br/> CF8 Standard<br/> IIS 6<br/> Win2k3<br/> SQL2k5 on a separate box</p>
<p>The way of finding the right number of requests is load testing. That is, measuring changes in throughput under load when you vary the request number. Any significant change would require retesting. But I suspect most folks are going to baulk at that amount of work.</p> <p>I think a good rule of thumb is about 8 ...
<p>I would say at least 8 <em>per core</em>, not per CPU. And I think 8 is a little low given modern CPU cores, I would say at least 12.</p>
11,353
<p>I have a class that map objects to objects, but unlike dictionary it maps them both ways. I am now trying to implement a custom <code>IEnumerator</code> interface that iterates through the values.</p> <pre><code>public class Mapper&lt;K,T&gt; : IEnumerable&lt;T&gt;, IEnumerator&lt;T&gt; { C5.TreeDictionary&lt;K...
<p>First, don't make your collection object implement IEnumerator&lt;>. This leads to bugs. (Consider the situation where two threads are iterating over the same collection). </p> <p>Implementing an enumerator correctly turns out to be non-trivial, so C# 2.0 added special language support for doing it, based on the...
<p>Use yield return.</p> <p><a href="https://stackoverflow.com/questions/39476/what-is-the-yield-keyword-used-for-in-c#39496">What is the yield keyword used for in C#?</a></p>
7,755
<p>I'm performing a bulk insert with an ADO.NET 2.0 SqlBulkCopy object from a C# method into a MS SQL 2005 database, using a database user with limited permissions. When I try to run the operation, I get the error message:</p> <blockquote> <p>Bulk copy failed. User does not have ALTER TABLE permission on table ...
<p>Solved it! Looks like I need a refresher on flags enums. I was bitwise ANDing the enum values when I should have been ORing them.</p> <pre><code>SqlBulkCopyOptions.FireTriggers &amp; SqlBulkCopyOptions.CheckConstraints </code></pre> <p>evaluates to zero (which is equivalent to SqlBulkCopyOptions.Default.)</p> <...
<p>Possibilities only, I'm sorry</p> <p>SQL documentation for <a href="http://msdn.microsoft.com/en-us/library/ms188365(SQL.90).aspx" rel="nofollow noreferrer">BULK INSERT</a> specifies 3 cases where ALTER TABLE is needed. You listed 2 of them. Is the KeepIdentity option being set, even if not needed?</p> <p>Another ...
48,778
<p>Say I have a data structure, such as</p> <pre><code>d dog DS qualified d name 20 d breed 20 d birthdate 8 0 </code></pre> <p>I can then define </p> <pre><code>d poochie likeds(dog) </code></...
<p>Two options come to mind. The first is to create a source member with the d-specs for the dog attributes and instead of using likeds(dog), have a /copy after each data structure that will use that subfield definition. In my opinion, this can make for some sloppy code and can make things difficult for someone to an...
<p>To the best of my knowledge, no. But it might be possible to do something similar with subprocedures.</p> <p>Post this question on <a href="http://lists.midrange.com/listinfo/rpg400-l" rel="nofollow noreferrer">Midrange.com RPG-L</a> and someone smarter than me might be able to answer your question.</p>
27,399
<p>I love Python because it comes batteries included, and I use built-in functions, a lot, to do the dirty job for me.</p> <p>I have always been using happily the os.path module to deal with file path but recently I ended up with unexpected results on Python 2.5 under Ubuntu linux, while dealing with string that repre...
<p>If you want to manipulate Windows paths on linux you should use the ntpath module (this is the module that is imported as os.path on windows - posixpath is imported as os.path on linux)</p> <pre><code>&gt;&gt;&gt; import ntpath &gt;&gt;&gt; filepath = r"c:\ttemp\FILEPA~1.EXE" &gt;&gt;&gt; print ntpath.basename(file...
<p>See the documentation <a href="http://pydoc.org/2.5.1/posixpath.html" rel="nofollow noreferrer">here</a>, specifically: </p> <blockquote> <p>splitdrive(p) Split a pathname into drive and path. <strong>On Posix, drive is always empty.</strong></p> </blockquote> <p>So this won't work on a Linux box.</p>
22,022
<p>is there an if statement when it comes to mysql query statements?</p> <p>when i am updating a table record, i want to only update certain columns if they have a value to be updated.</p> <p>for example, i want an update table function, and there is a table for volunteers and a table for people who just want email u...
<p>I think this should work:</p> <pre><code>UPDATE volunteer, people SET volunteer.email = 'me@email.com', people.email = 'other@gmail.com', people.first_name = 'first', WHERE people.id = 2 AND volunteer.id = 5; </code></pre> <p>I got this from the <a href="http://dev.mysql.com/doc/refman/5.1/en/update.html" ...
<p>You <em>could</em> do this in one query, but it's not making sense to me why you would want to. Maybe describe the arguments to your desired function and what effect they would have?</p> <p>You can conditionally update something like this:</p> <pre><code>update tablereferences set foo.bar = if( somebooleanexpr...
23,038
<p>... say I check out some code, do a little dev or refactoring or whatever .. do I only check it back in when I'm completely happy? ... what if I change my mind about stuff while i'm coding? can I go back to a previous local version? is there a history of my local development?</p> <p>Is version control about deploy...
<p>Short answer. It's both.</p> <p>You need to be able to roll back to earlier versions for lots of reasons.</p>
<p>That depends how your Version Control system is used...</p> <p>In my experience, most companies use it for deployment history in most senses. That is, only working code should be put in. If you check something out and then are in the process of adding a block of code that doesn't yet work - then checking it back ...
43,937
<p>There is a MSBuild script, that includes number if Delphi and C# projects, unit tests etc. </p> <p>The problem is: how to mark build failed if warnings were raised (for testing purposes, not for release builds)? Using LogError instead of LogWarning in custom tasks seems to be not a good option, because the build sh...
<p>AFAIK MSBuild has no built-in support to retrieve the warning count at a given point of the build script. You can however follow these steps to achieve this goal:</p> <ol> <li>Create a custom logger that listens for the warning event and counts the number of warnings</li> <li>Create a custom task that exposes an [O...
<p>The C# compiler (csc.exe) has a /warnaserror switch will will treat warnings as errors and fail the build. This is also available as a setting in the .csproj file. I assume Delphi has a similar ability.</p>
18,401
<p>At the moment I have setup a custom ok cancel dialog with a drop down in c#. The ok and cancel buttons use the DialogResult property so no code behind it. What I now need to do is validate the drop down to check it isn't left empty before posting back a dialogresult.</p> <p>Is this possible?</p>
<p>From <a href="http://www.functionx.com/vcsharp2003/Lesson06.htm" rel="nofollow noreferrer">here</a></p> <p>Double-click the Closing field, and implement it as follows:</p> <pre><code>private void Second_Closing(object sender, System.ComponentModel.CancelEventArgs e) { // When the user attempts to clo...
<p>If you want check for something, you allways need some code behind the designer. For your case, you can use a "Closing" event in the form, check what you need and if you want, set "e.Cancel = true;" - then form will not be closed.</p>
33,837
<p>I use Visual Basic and an automation interface to retrieve strings from an external application. These strings contain simple html formatting codes (&lt;b&gt;, &lt;i&gt;, etc.). Is there any easy function in Visual Basic for Word to insert these strings into a word document and convert the html formatting codes to w...
<p>Here's a link to add HTML to the clipboard using VB:</p> <p><a href="http://support.microsoft.com/kb/274326" rel="noreferrer">http://support.microsoft.com/kb/274326</a></p> <p>Once you have the HTML on the clipboard, paste it into your word doc using something like this:</p> <pre><code>ActiveDocument.Range.PasteS...
<p>AFAIK there is no builtin function to do that in VBA. You will have to write it yourself, which would be not too difficult if you restirct it to parse <code>&lt;b&gt;, &lt;i&gt;, &lt;a&gt; and &lt;p&gt;,</code> for example. All other tags would have to be ignored.</p>
19,525
<p>I am a newbie for Visual Basic 6 project. I downloaded some tutorials for testing; however, I am not able to drag, move, or edit the UI form designer objects in those projects.</p> <p>Does anybody know there is an object lock function in VB6?<br /> If there is, how can I unlock it?</p>
<p>In this case I wouldn't go for an enum, I'd go for a "score" column. So the columns might be:</p> <pre><code>userid, questionid, score 1,1,4 1,2,4 1,3,3 2,1,1 2,2,4 ... </code></pre> <p>1 being very unsatisfied and 4 being very satisfied.</p> <p>Then a query like:</p> <pre><code>select 25*avg(score) from Blah </...
<p>Just in case anyone else has this problem; I have also found a tutorial which is quite useful. <a href="http://www.roughguidetophp.com/generating-reports-using-mysqls-aggregate-functions-sum-max-min-and-more/" rel="nofollow noreferrer">http://www.roughguidetophp.com/generating-reports-using-mysqls-aggregate-functio...
42,138
<p>How can I create a query for a full outer join across a M2M relationchip using the django QuerySet API?</p> <p>It that is not supported, some hint about creating my own manager to do this would be welcome.</p> <p><strong>Edited to add:</strong> @S.Lott: Thanks for the enlightenment. The need for the OUTER JOIN co...
<p>Django doesn't support "joins" in the usual SQL sense -- it supports object navigation.</p> <p>Note that a relational join (inner or outer) creates a new "class" of entities. One that doesn't have a definition in Django. So there's no proper "result set" since there's no class definition for the things you get ba...
<p>Colin, one of the guys I work with, wrote a post awhile back about doing custom joins in Django:</p> <p><a href="http://www.caktusgroup.com/blog/2009/09/28/custom-joins-with-djangos-queryjoin/" rel="nofollow noreferrer">http://www.caktusgroup.com/blog/2009/09/28/custom-joins-with-djangos-queryjoin/</a></p> <p>You ...
31,526
<p>I have a database full of small HTML documents and I need to programmatically insert several into, say, a PDF document with <em>iText</em> or a Word document with <em>Aspose.Words</em>. I need to preserve any formatting within the HTML documents (within reason, honouring &lt;b&gt; tags is a must, CSS like &lt;span s...
<p><a href="http://htmlparser.sourceforge.net/" rel="nofollow noreferrer">HTMLparser</a> is a good HTML parser.</p> <p>I have used this to parse HTML on one of my projects.</p> <p>You can write your own filters to parse the HTML for what you want, so the <code>&lt;br&gt;</code> tag shouldn't be difficult to parse o...
<p>Adobe Acrobat Pro allows you to grab sites via HTTP and does an excellent job of preserving the style and layout. I haven't used it from an API aspect, but it may be worth looking into.</p>
26,888
<p>Here's a software design question I've encountered several times and have never found an ideal solution for (I'm also dealing with it now again.)</p> <p>Many applications need some form of user/role management. You have base users, groups that these users can belong to (not limited to just one), roles and permissi...
<p>You should adapt your design because every organization is different. <a href="http://en.wikipedia.org/wiki/Role-based_access_control" rel="noreferrer">Check this page</a>, you can see a pattern for role-based administration.</p>
<p>Take a look at Scott Mitchell's ASP.NET 2.0 Membership, Roles and Profile Tutorial series:</p> <p><a href="http://weblogs.asp.net/scottgu/archive/2006/05/07/ASP.NET-2.0-Membership-and-Roles-Tutorial-Series.aspx" rel="nofollow noreferrer">http://weblogs.asp.net/scottgu/archive/2006/05/07/ASP.NET-2.0-Membership-and-R...
38,498
<p>I`d like to be able to read the content of office documents (for a custom crawler). </p> <p>The office version that need to be readable are from 2000 to 2007. I mainly want to be crawling words, excel and powerpoint documents.</p> <p>I don`t want to retrieve the formatting, only the text in it. </p> <p>The crawle...
<p>If you're already using Lucene.NET you might just want to take advantage of the various IFilters already available for doing this. Take a look at the open source <a href="http://sourceforge.net/projects/seekafile/&quot;SeekAFile&quot;" rel="nofollow noreferrer">SeekAFile</a> project. It will show you how to use an I...
<p>You might also consider checking out DtSearch (www.DtSearch.com). Although it is primarily a searching tool, it does a great job of extracting text from a large number of file types and is considerably cheaper than other options like the Oracle/Stellent OutsideIn technology or the equivalent from Autonomy.</p> <p>I...
14,075
<p>This morning, I was reading <a href="http://steve.yegge.googlepages.com/when-polymorphism-fails" rel="noreferrer">Steve Yegge's: When Polymorphism Fails</a>, when I came across a question that a co-worker of his used to ask potential employees when they came for their interview at Amazon.</p> <blockquote> <p>As a...
<p><strong>Polymorphic Tree Walking</strong>, Python version</p> <pre><code>#!/usr/bin/python class Node: """base class, you should not process one of these""" def process(self): raise('you should not be processing a node') class BinaryNode(Node): """base class for binary nodes""" def __init_...
<p>should use a functional language imo. Trees are harder to represent and manipulate in OO languages.</p>
3,354
<p>I have an OpenGl program in which I am displaying an image using textures. I want to be able to load a new image to be displayed. </p> <p>In my Init function I call:</p> <pre><code>Gl.glGenTextures(1, mTextures); </code></pre> <p>Since only one image will be displayed at time, I am using the same texture name for...
<p>I don't think the problem is in the code you're showing. You'll need to provide more information as to how you draw with the texture, as well as what the texture data passed to <code>glTexImage2D</code> looks like. Are you sure it's still valid by the time you call <code>glTexImage2D</code> ?</p>
<p>When do you submit the geometry using these textures? I assume that is interleaved with the texture loading, although you don't show that. Of course, if you are going to replace the texture name with different images, you don't need to use texture names at all, do you? You could just do the <code>glTextImage2D</cod...
43,034
<p>Why isn't Visual Studio 2005 generating a serialization setting when I set the project setting "Generate Serialization Assembly" to "On"?</p>
<p><a href="http://msdn.microsoft.com/en-us/library/ms164303.aspx" rel="noreferrer">It turns out that Dev Studio only honors this setting for Web Services.</a></p> <p>For non-web services you can get this to work by adding an AfterBuild target to your project file:</p> <pre><code> &lt;Target Name="AfterBuild" Depend...
<p>It can be done manually with <a href="http://msdn.microsoft.com/en-us/library/bk3w6240(VS.80).aspx" rel="nofollow noreferrer">sgen.exe</a>.</p>
16,476
<p>Here is the functionality I want:</p> <p>User selects an image from their machine, hits an Upload button (or better yet the following fires on the onchange event of the file input), and is able to see a preview of the image they are about to upload.</p> <p>Here is the current workflow I am using, but it seems subo...
<p>If you have memory to burn:</p> <ul> <li>cache the image bytes in memory</li> <li>set your ImageUrl to an image handler (.ashx) with some sort of cache identifier</li> <li>serve the image bytes from cache</li> <li>if the user cancels or leaves, discard the cached bytes</li> <li>if the user accepts, write the cached...
<p>You should upload and rename the image to match some sort of ID for your current record. Then, when you upload a new file, delete any old ones first, all in the codebehind.</p> <p>If you are only showing a thumbnail, you should try to use an image library to resize the image before saving. This will save on bandwid...
32,908
<p>Anyone know a good and effective way to search/match for a byte pattern in an byte[] array and then return the positions.</p> <p>For example</p> <pre><code>byte[] pattern = new byte[] {12,3,5,76,8,0,6,125}; byte[] toBeSearched = new byte[] {23,36,43,76,125,56,34,234,12,3,5,76,8,0,6,125,234,56,211,122,22,4,7,89,76...
<p>May I suggest something that doesn't involve creating strings, copying arrays or unsafe code:</p> <pre><code>using System; using System.Collections.Generic; static class ByteArrayRocks { static readonly int[] Empty = new int[0]; public static int[] Locate (this byte[] self, byte[] candidate) { ...
<p>You can put the byte array into <a href="http://msdn.microsoft.com/en-us/library/ezh7k8d5.aspx" rel="nofollow noreferrer">String</a> and run match by IndexOf. Or you can at least reuse <a href="http://en.wikipedia.org/wiki/String_searching_algorithm" rel="nofollow noreferrer">existing algorithms</a> on string matchi...
35,932
<p>I'm running a django instance behind nginx connected using fcgi (by using the manage.py runfcgi command). Since the code is loaded into memory I can't reload new code without killing and restarting the django fcgi processes, thus interrupting the live website. The restarting itself is very fast. But by killing the f...
<p>I would start a new fcgi process on a new port, change the nginx configuration to use the new port, have nginx reload configuration (which in itself is graceful), then eventually stop the old process (you can use netstat to find out when the last connection to the old port is closed).</p> <p>Alternatively, you can ...
<p>You can use spawning instead of FastCGI</p> <p><a href="http://www.eflorenzano.com/blog/post/spawning-django/" rel="nofollow noreferrer">http://www.eflorenzano.com/blog/post/spawning-django/</a></p>
47,229
<p>How can I find out the size of a file I opened with an application written in C ? I would like to know the size, because I want to put the content of the loaded file into a string, which I allocate using <code>malloc()</code>. Just writing <code>malloc(10000*sizeof(char));</code> is IMHO a bad idea. </p>
<p>You need to seek to the end of the file and then ask for the position:</p> <pre><code>fseek(fp, 0L, SEEK_END); sz = ftell(fp); </code></pre> <p>You can then seek back, e.g.:</p> <pre><code>fseek(fp, 0L, SEEK_SET); </code></pre> <p>or (if seeking to go to the beginning)</p> <pre><code>rewind(fp); </code></pre>
<pre><code>#include &lt;stdio.h&gt; #define MAXNUMBER 1024 int main() { int i; char a[MAXNUMBER]; FILE *fp = popen("du -b /bin/bash", "r"); while((a[i++] = getc(fp))!= 9) ; a[i] ='\0'; printf(" a is %s\n", a); pclose(fp); return 0; } </code></pre> <p>HTH</p>
29,510
<p>In a <a href="http://www.pygame.org/" rel="nofollow noreferrer">pyGame</a> application, I would like to render resolution-free GUI widgets described in SVG.</p> <p>How can I achieve this?</p> <p>(I like the <a href="http://ocemp.sourceforge.net/gui.html" rel="nofollow noreferrer">OCEMP GUI</a> toolkit but it seems t...
<p>This is a complete example which combines hints by other people here. It should render a file called test.svg from the current directory. It was tested on Ubuntu 10.10, python-cairo 1.8.8, python-pygame 1.9.1, python-rsvg 2.30.0.</p> <pre><code>#!/usr/bin/python import array import math import cairo import pygam...
<p>Based on other answers, here's a function to read a SVG file into a pygame image - including correcting color channel order and scaling:</p> <pre><code>def pygame_svg( svg_file, scale=1 ): svg = rsvg.Handle(file=svg_file) width, height= map(svg.get_property, ("width", "height")) width*=scale; height*=sc...
14,660
<p>Which of these queries is the faster?</p> <p>NOT EXISTS:</p> <pre><code>SELECT ProductID, ProductName FROM Northwind..Products p WHERE NOT EXISTS ( SELECT 1 FROM Northwind..[Order Details] od WHERE p.ProductId = od.ProductId) </code></pre> <p>Or NOT IN:</p> <pre><code>SELECT ProductID, ProductName...
<p>I always default to <code>NOT EXISTS</code>.</p> <p>The execution plans may be the same at the moment but if either column is altered in the future to allow <code>NULL</code>s the <code>NOT IN</code> version will need to do more work (even if no <code>NULL</code>s are actually present in the data) and the semantics...
<p>It depends..</p> <pre><code>SELECT x.col FROM big_table x WHERE x.key IN( SELECT key FROM really_big_table ); </code></pre> <p>would not be relatively slow the isn't much to limit size of what the query check to see if they key is in. EXISTS would be preferable in this case.</p> <p>But, depending on the DBMS's op...
20,849
<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/795746/warning-mysql-fetch-array-supplied-argument-is-not-a-valid-mysql-result">Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result</a> </p> </blockquote> <p>When I run my php page, I ge...
<p>It generally means that you've got an error in your SQL.</p> <pre><code>$sql = "SELECT * FROM myTable"; // table name only do not add tb $result = mysql_query($sql); var_dump($result); // bool(false) </code></pre> <p>Obviously, <code>false</code> is not a MySQL resource, hence you get that error.</p> <p><stron...
<pre><code>&lt;?PHP $user_name = "root"; $password = ""; $database = "addressbook"; $server = "127.0.0.1"; $db_handle = mysql_connect($server, $user_name, $password); $db_found = mysql_select_db($database, $db_handle); if ($db_found) { $SQL = "SELECT * FROM tb_address_book"; $result = mysql_...
20,467
<p>I'm starting to get comfortable with the idea of fakes, stubs, mocks, and dynamic mocks. But I am still a little iffy in my understanding of when to use partial mocks. </p> <p>It would seem that if you're planning on mocking a service and need to resort to a partial mock then it is a sign of bad design. Is it th...
<p>Its good design, imho. What happens when somebody comes after you and changes your method, removing the call to Reset? (btw, why so much state in your objects?) You might never know they screwed up until you hit production. By mocking it and asserting on that method call, you can assure nobody is going to mess u...
<p>My understanding of partial mock was that it was for mocking abstract classes, with only the abstract methods being mocked, and the existing concrete methods being left as they are?</p>
16,903
<p>If you could go back in time and tell yourself to read a specific book at the beginning of your career as a developer, which book would it be?</p> <p>I expect this list to be varied and to cover a wide range of things.</p> <p><strong>To search:</strong> Use the search box in the upper-right corner. To search the a...
<ul> <li><em>Code Complete</em> (2nd edition) by Steve McConnell</li> <li><em>The Pragmatic Programmer</em></li> <li><em>Structure and Interpretation of Computer Programs</em></li> <li><em>The C Programming Language</em> by Kernighan and Ritchie</li> <li><em>Introduction to Algorithms</em> by Cormen, Leiserson, Rivest ...
<p><a href="https://rads.stackoverflow.com/amzn/click/com/0201485672" rel="nofollow noreferrer" rel="nofollow noreferrer">Refactoring</a></p> <p><a href="https://rads.stackoverflow.com/amzn/click/com/0321127420" rel="nofollow noreferrer" rel="nofollow noreferrer">Patterns of Enterprise Application Architecture</a></p>...
2,403
<p>Here's a relatively common task for me, and, I think, for many a .NET programmer:<br> I want to use the .NET ThreadPool for scheduling worker threads that need to process a given type of tasks.</p> <p>As a refresher, the signatures for the queueing method of the ThreadPool and its associated delegate are:</p> <pre...
<p>It sounds like you are talking about a work queue? (and I sound like clippy...)</p> <p>For the record, thread-pool threads should typically be used for short pieces of work. You should ideally create your own threads for a long-lived queue. Note that .NET 4.0 may be adopting the CCR/TPL libraries, so we'll get some...
<p>ThreadPool exists since .NET 1.1 which didn't have Generics.</p> <p>I like how they chose not to break backwards compatibility :-)</p>
41,884
<p>I've figured out how to set VC++ to compile code into a .lib file instead of a .exe, but I'm having trouble getting a lib to link together with my other .obj files.</p> <p>Here is how I have the library and application folders set up. (I'm not sure if this is right)</p> <pre><code>AppFolder App.sln App.ncb ...
<p>On the project properties:</p> <p>Configuration Properties -> Linker -> Input -> Additional Dependancies</p> <p>Add it in there.</p> <p>Or, in your .h file for the library, add:</p> <pre><code>#pragma comment(lib, "Library") </code></pre> <p>This will do it automatically for you.</p>
<p>VC does not simply link the library if you include the header-file.</p> <p>You have to tell the linker to use the library. For good reasons: You alredy have thousands of libs in your library folder. If MSVC had to search all of them each time you link your program it would have to wade through hundrets of megabytes...
27,655
<p>I am working on a website that currently has a number of disparate search functions, for example:</p> <ul> <li>A crawl 'through the front door' of the website</li> <li>A search that communicates with a web-service</li> <li>etc...</li> </ul> <p>What would be the best way to tie these together, and provide what appear...
<p>Solr is an unbelievably flexible solution for search. Just in the last year I coded 2 solr-based websites and worked on a third existing one, each worked in a very different way.</p> <p>Solr simply eats XML requests to add something to index, and XML requests to search for something inside an index. It doesn't do c...
<p>Two other solutions that weren't as well-known &amp;/or available around the time the original question was asked:</p> <ul> <li><a href="https://www.google.com/cse/" rel="nofollow">Google Custom Search</a> - especially since the disable public URL option was recently added</li> <li><a href="http://yacy.net/en/index...
49,756
<p>My website was recently attacked by, what seemed to me as, an innocent code:</p> <pre><code>&lt;?php if ( isset( $ _GET['page'] ) ) { include( $ _GET['page'] . ".php" ); } else { include("home.php"); } ?&gt; </code></pre> <p>There where no SQL calls, so I wasn't afraid for SQL Injection. But, apparen...
<p>Use a whitelist and make sure the page is in the whitelist:</p> <pre><code> $whitelist = array('home', 'page'); if (in_array($_GET['page'], $whitelist)) { include($_GET['page'].'.php'); } else { include('home.php'); } </code></pre>
<p>@pek - That won't work, as your array keys are 0 and 1, not 'home' and 'page'.</p> <p>This code should do the trick, I believe:</p> <pre><code>&lt;?php $whitelist = array( 'home', 'page', ); if(in_array($_GET['page'], $whitelist)) { include($_GET['page'] . '.php'); } else { include('home.php'); } ?&gt; ...
5,987