instruction stringlengths 21 27.8k | chosen stringlengths 18 28.2k | rejected stringlengths 18 33.6k | __index_level_0__ int64 0 50k |
|---|---|---|---|
<p>What are the essential vim commands? What does a new-user need to know to keep themselves from getting into trouble? One command per comment, please.</p>
| <p>What I find irreplaceable (because it works in vi also, unlike vim's visual mode) are marks. You can mark various spots with <code>m</code> (lower case) and then a letter of your choice (eg x). Then you go elsewhere, and can go back with ``x<code>(backquote letter) to the exact spot, or with</code>'x` (apostrophe le... | <p>One of my favourite commands is %G which takes to directly to the end of a file. Especially useful in log-files.</p>
| 9,527 |
<p>I've got a lot of mysql data that I need to generate reports from. It's mostly historic data so it won't be changing much, but it weighs in at 20-30 gigabytes easily and is expected to grow. I currently have a collection of php scripts that will do some complex queries and output csv and excel files. I also use phpM... | <p>I'll discuss a few points on the {budget, business utility function, time frame} spectrum out there. For convenience, let's follow the architecture conceptualization you linked to at</p>
<p> <a href="http://en.wikipedia.org/wiki/Data_warehouse#Data_warehouse_architecture" rel="noreferrer" title="Wikip... | <p>Kimball is the simpler method for data warehousing.</p>
<p>We use Informatica for moving data around, but it doesn't do DW things like indexing by default.<br>
I like the idea of Wherescape RED, as a DW tool and using MS SQL's Linked Servers to obviate the need for an ETL tool.</p>
| 19,206 |
<p>This may seem like a stupid question, so here goes:</p>
<p>Other than parsing the string of FileInfo.FullPath for the drive letter to then use DriveInfo("c") etc to see if there is enough space to write this file. Is there a way to get the drive letter from FileInfo?</p>
| <pre><code>FileInfo f = new FileInfo(path);
string drive = Path.GetPathRoot(f.FullName);
</code></pre>
<p>This will return "C:\". That's really the only other way.</p>
| <p>Nothing wrong with a little string parsing :-)</p>
<pre><code>FullPath.Substring(0,1);
</code></pre>
| 48,367 |
<p>Could someone explain to me in simple terms the easiest way to change the indentation behavior of Vim based on the file type? For instance, if I open a Python file it should indent with 2 spaces, but if I open a Powershell script it should use 4 spaces.</p>
| <p>You can add <code>.vim</code> files to be executed whenever vim switches to a particular filetype.</p>
<p>For example, I have a file <code>~/.vim/after/ftplugin/html.vim</code> with this contents:</p>
<pre><code>setlocal shiftwidth=2
setlocal tabstop=2
</code></pre>
<p>Which causes vim to use tabs with a width o... | <p>I use a utility that I wrote in C called <a href="http://www.kylheku.com/cgit/c-snippets/tree/autotab.c" rel="nofollow"><code>autotab</code></a>. It analyzes the first few thousand lines of a file which you load and determines values for the Vim parameters <code>shiftwidth</code>, <code>tabstop</code> and <code>expa... | 19,232 |
<p>Here's what I'd like to do: </p>
<p>I want to create a library project that contains my Resource files (ie, UI Labels and whatnot). I'd like to then use the resource library both in my UI and in my Tests. (Ie, basically have a common place for my resources that I reference from multiple projects.)</p>
<p>Unfortuna... | <p>Not sure which version of Visual Studio you are using, so I will put steps for either one:</p>
<p>VS 2008 - When you open the resx file in design view, there is an option at the top beside Add Resource and Remove Resource, called Access Modifier, it is a drop down where you can change the generated code from intern... | <p>From the dataset designer and with the properties window visible, there is a "Modifier" property. For your datasets, it is likely saying internal.</p>
<p>I don't know if there is a setting to default all new datasets to public.</p>
| 17,029 |
<p>I have a Monoprice Maker Select v2. It is the kind where the moving plate (heat bed) provides the Y-axis and the moving extruder provides the X-axis. It has a fairly rigid sheet metal frame. In addition, I added steel rods has Z-braces.</p>
<p>I see some pretty obvious ghosting. This happens for an inch or so right... | <p>Ghosting is caused by differential movement between the bed and the head when the head undergoes acceleration. The forces add energy to a resonance in that differential vibration mode.</p>
<p>By changing how you mount the base, you will change the mode and probably change the frequency. </p>
<p>With the soft moun... | <p>I'm missing something here. How about damping the movement of table and head by placing a tuned mass damper on table and head? Something like a mass that is mounted in the top of a skyscraper...</p>
| 933 |
<p>What is the best way to include data in an HTML page? The data is not human-readable and will be processed by a script once the page has loaded. The options I can think of are:</p>
<ul>
<li><p>Using class and title attributes on hidden/empty <code><div></code> or <code><span></code> elements within the ... | <p>And help here? <a href="http://www.geocities.com/yongweiwu/multibyte.htm" rel="nofollow noreferrer">Multibyte Functions in Microsoft C Run-time</a></p>
| <p>There is actually a very simple (but weird) way of force the OnChar function to send unicode characters to the application even if it's configured in multi-byte character set:</p>
<pre><code>SetWindowLongW( m_hWnd, GWL_WNDPROC, GetWindowLong( m_hWnd, GWL_WNDPROC ) );
</code></pre>
<p>Simply by calling the unicode ... | 42,036 |
<p>I'm working on a time sheet application, where I'd like the user to be able to enter times in TextBoxes, e.g.: 8 a or 8:00 a or the like, just like you can in Excel.</p>
<p>Now if you enter a <em>date</em> in a TextBox and then use DateTime.TryParse, you can enter it in several formats (Jan 31, 2007; 1/31/2007; 31/... | <p>Come to think of it, never mind. I just noticed that if I use "am" and "pm" instead of "a" and "p", it works fine. It assumes today's date, instead of the default 1/1/0001, but that's not a problem for my purposes.</p>
<p>(Still, any reasonably easy solution to get the "a" and "p" to work is welcome.)</p>
| <p>You may be able to use the validating or validated event to capture the text and add the 'm'.</p>
| 35,739 |
<p>Here's a scenario I'm sure you're all familiar with. </p>
<ol>
<li><p>You have a fairly "hands off" customer, who really doesn't want to get too involved in the decision making despite your best efforts. </p></li>
<li><p>An experienced development team spend hours discussing the pros and cons of a particular approa... | <p>Make your customer pay by the effort you are putting into designing and developing the solution to their problem.</p>
<p>The more you work, the more you get. The customer will have to pay for his mistakes.</p>
<p>Customer will eventually learn to appreciate your experience and insight in the programming field.</p>... | <p>Or else, <em>if they won't pay for the effort</em>, just avoid putting that much resources into the solution of the problem, and just give them exactly what they've asked for and then think about it after the three weeks have passed.</p>
<p>Somewhat frustrating, yes, but that's the way it'll always be with that kin... | 7,715 |
<p>I am running a number of SSL-encrypted websites, and need to generate certificates to run on these. They are all internal applications, so I don't need to purchase a certificate, I can create my own.</p>
<p>I have found it quite tedious to do everything using openssl all the time, and figure this is the kind of thi... | <p>An option that doesn't require your own CA is to get certificates from <a href="http://www.cacert.org/" rel="noreferrer">CAcert</a> (they're free).</p>
<p>I find it convenient to add the two CAcert root certificates to my client machines, then I can manage all the SSL certificates through CAcert.</p>
| <p>I created <a href="https://github.com/brianclements/pkictl" rel="nofollow">a wrapper script</a>, written in Bash, for OpenSSL that might be useful to you here. To me, the easiest sources of user error when using OpenSSL were:</p>
<ol>
<li>Keeping a consistent and logical naming scheme for configuration/certs/keys s... | 3,836 |
<p>Is there a way to do gradients in css/html/javascript only that will work across all the major browsers? (MS IE 5+, Firefox, Opera, Safari)?</p>
<p>Edit: I would like to do this for backgrounds (header, main panel, side panels). Also, would like to have vertical line gradients as well.</p>
<p>Edit: after reading t... | <p>I'm unclear on the implementation details you are seeking (such as background, or just a border along the side of the window, etc); however, it's possible albeit a little tedious.</p>
<p>One example that comes to mind would be to have n-block level elements, such as divs, and then give them each a small height (a c... | <p>I think the short answer is no.</p>
<p>You can create something that looks like a gradient using only css, but to then use it like an image background... I think that is pushing it a bit.</p>
<p><strong>EDIT (feeling silly)</strong> </p>
<p>I found the solution: <a href="http://en.wikipedia.org/wiki/JPEG" rel="no... | 47,071 |
<p>Our app encrypts a value using RC2 in C++ code and I wrote a decryption routine in .NET </p>
<p>The problem is that it works fine on our dev server, which is Windows 2003 but fails on the Windows 2000 one. It's running the same code and I checked everything else and it seems there are differences in the way the 2 e... | <ol>
<li>Make sure Windows 2000 has SP3, or encryption is far less likely to work, particularly if using Capicom (or the api it wraps).</li>
<li>Not all of the encryption algorithms and keylengths are supported on Windows 2000 if using Capicom (or the api it wraps).</li>
</ol>
| <p>There's an <a href="http://support.microsoft.com/kb/841715" rel="nofollow noreferrer">obscure issue</a> with win2000/winxp encryption/decryption. The Cryptography Service Provider on win2000 has 40 for the effective key length and that's used by default even if you use a 128 bit key. So to fix that you have to manua... | 40,683 |
<p>I am building a web application that uses the database for Users, Security/roles, and to store content.</p>
<p>It seems a little daunting to me to begin on the road of unit testing because I have to make sure my database has been initialized properly for my tests to run.</p>
<p>What are common practices to help in... | <p>It's not a unit test if you are testing more than one unit. </p>
<p>Usually you'll have one component (your page, or the business layer) talking to a data layer object that is responsible for actually connecting and querying the database. My recommendation is to develop a unit test for the first component, using de... | <p>The cost of unit testing/TDD is that you have to alter your design so that you have a clean separation between the database and the domain layer, so that you can create a fake that will allow you to create tests that don't hit the database.</p>
<p>But that cleaner design is just the beginning of the cost. After tha... | 44,291 |
<p>I'd like to add a method <code>AddDefaultNamespace()</code> to the String class in Java so that I can type <code>"myString".AddDefaultNamespace()</code> instead of <code>DEFAULTNAMESPACE + "myString"</code>, to obtain something like <code>"MyDefaultNameSpace.myString"</code>. I don't want to add another derived clas... | <p><code>String</code> is a final class which means it cannot be extended to work on your own implementation.</p>
| <p>You can create your own version of String class and add a method :-)</p>
| 10,753 |
<p>What is the best way to handle user account management in a system, without having your employees who have access to a database, to have access to the accounts.</p>
<p>Examples:</p>
<ol>
<li><p>Storing username/password in the database. This is a bad idea because anyone that has access to a database can see the u... | <blockquote>
<p>This is a better method, but the account can be accessed by replacing the password hash in the database with the hash of another account that you know the auth info for.</p>
</blockquote>
<p>There's really no way around this. Anyone who as write access to the password file has complete control of th... | <p>You could store the <em>salt</em> for the hashed password in another table, of course each user would have their own salt. You could then limit access to that table.</p>
| 8,574 |
<p>I am programming an iPhone app, and I need to force it to exit due to certain user actions. After cleaning up memory the app allocated, what's the appropriate method to call to terminate the application?</p>
| <p>Have you tried <code>exit(0)</code>?</p>
<p>Alternatively, <code>[[NSThread mainThread] exit]</code>, although I have not tried that it seems like the more appropriate solution.</p>
| <p>The user should decide when an app exits.
I don't think it is a good user interaction when an app quits. Therefore there is no nice API for it, only the home button has one.</p>
<p>If there is an error: Implement it better or Notify the user.
If there have to be a restart: Implement it better of Notify the user.</p... | 46,289 |
<p>I am looking for a way to get a function in excel to retrieve the distance form one zip to another. Lets say i have a list of 100,000 possible recruits and I want to sort by nearest. Id have the conference zip code and then 100,000 recruit zip codes. I'm looking to be able to just write a function =ZipCodeDistance(a... | <p>If you have the latitude and longitude for each zip code, you can use trigonometry to calculate the distance as the crow flies.</p>
<p>There is a free database <a href="http://www.populardata.com/downloads.html" rel="nofollow noreferrer">here</a> that you can download.</p>
<p>To do the calculation, see the info <a... | <p>How to get the data and the algorithm are explained <a href="https://web.archive.org/web/1/http://blogs.techrepublic%2ecom%2ecom/programming-and-development/?p=634" rel="nofollow noreferrer">here</a>, but in C#. If your Excel VBA is OK, it shouldn't be too difficult to translate?</p>
| 47,429 |
<p>I need to deploy a web application on several laptops (although it is a web application, it is intended to run via <code>localhost</code> only - thus the need to deploy on several different machines).</p>
<p>Normally I would go to IIS and right click a directory to create a web application, but I would very much li... | <p>I can suggest you to take a <a href="http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/1805162e-6ac5-4a98-9a08-919c4c10827d.mspx?mfr=true" rel="nofollow noreferrer">look at this link</a> if you are deploying on IIS 6 <a href="http://learn.iis.net/page.aspx/114/getting-started-with-appcm... | <p>Have look at <a href="http://weblogs.asp.net/rmclaws/archive/2005/10/25/428422.aspx" rel="nofollow noreferrer">this post</a>. It explains how to start <a href="https://www.developer.com/net/deciding-on-a-microsoft-web-server-cassini-iis-and-iis-express.html" rel="nofollow noreferrer">Cassini web server</a> from the ... | 40,477 |
<p>I need a <a href="http://www.codeproject.com/KB/dotnet/regextutorial.aspx" rel="nofollow noreferrer">Regular Expressions</a> to get the text within 2 tags.</p>
<p>Lets say I want an array returned containing <strong>any text within <code><data</code>> and <code></data</code>> tags.</strong>
Or any text <stro... | <p>Since you specifically mentioned C#, here's how I'm doing that exact parsing:</p>
<pre><code>private static readonly Regex RgbValuePattern = new Regex(@"(?<r>\d{1,3}) ?, ?(?<g>\d{1,3}) ?, ?(?<b>\d{1,3})",
RegexOptions.Compiled | RegexOption... | <p>I believe real problems will arise when you want to parse nesting constructs. For example, when you want to examine XML like this
<code><data><data>123</data><data>456</data></data></code>
to extract data included in outermost <code><data></code> tags one RegEx alone would ... | 46,012 |
<p>I am looking for an open source project that uses EJB3 as backend and JSF as frontend. It should <em>not</em> be a tutorial but a real application that real people are using.</p>
<p>The application should be data-driven, i.e. the following aspects are fundamental and make 80% or more of the application.</p>
<ul>
<... | <p>Seam examples are quite good. They are stand-alone projects, that you may deploy out of the box. </p>
| <p>I am not sure is it 100% what your looking for, <strong>but check out the built in example that comes packaged with NetBeans 6.1</strong>. It uses JSF/EJB3/ApacheDerby. I played around with it for like 20 minutes and thought it was pretty cool as a simple/starter JavaEE application to learn from.</p>
| 5,908 |
<p>I know there is a tool that enables me to see what actually gets sent/received in my WCF application, that is it let's me see the actual SOAP messages being passed down the wire.
The problem is I don't remember what that tool was called, and my Google skills are not of much help either. Anyone?</p>
| <p>I believe your looking for the Service Trace Viewier.
<a href="http://msdn.microsoft.com/en-us/library/ms732023.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ms732023.aspx</a></p>
| <p>I enable tracing for the service and use Microsoft Service Trace Viewer to look at them.</p>
| 26,196 |
<p>On a CentOS LAMP box, trying to get require_once to work inside a script in PHP5. If the file to be included is not a in symlinked directory, it works fine, but if the file to be required is in a directory found via a symbolic link, it fails to find it.</p>
<p>Is this a limitation of require_once and symbolic links... | <p>To my knowledge, require_once can use symbolic links just fine. I'm using include_once with some symbolic links in a WordPress MU install and it works just fine - I can't imagine why require_once would function differently than include_once in that respect.</p>
<p>Any chance you've got <a href="http://php.net/manua... | <p>As far as I know there aren't. Are the permissions the same as when you don't use the sym link?</p>
| 23,778 |
<p>We have multiple MFC apps, which use CMutex( false, "blah" ), where "blah" allows the mutex to work across process boundaries.</p>
<p>One of these apps was re-written without MFC (using Qt instead). How can I simulate the CMutex using Win32 calls? (Qt's QMutex is not inter-process.) I prefer not to modify the MFC... | <p>For inter-process mutexes you want these calls:</p>
<blockquote>
<p><a href="http://msdn.microsoft.com/en-us/library/ms682411(VS.85).aspx" rel="nofollow noreferrer">CreateMutex</a></p>
<p><a href="http://msdn.microsoft.com/en-us/library/ms687032(VS.85).aspx" rel="nofollow noreferrer">WaitForSingleObject</a></p>
<p><... | <p>The following funcs will probably be what you want, they are all documented on MSDN.</p>
<pre><code>CreateMutex(...)
WaitForSingleObject(...)
ReleaseMutex(...)
</code></pre>
| 12,212 |
<p>I am trying to build a function in C/C++ to sort an array and replace each value with its "score" or rank. It takes in a double pointer array to an array of ints, and sorts the double pointers based on the dereferenced value of the integers. I have tried quite a few times to make it work, but can't get it down. O... | <p>You're close. You're referencing the address of the array items when you swap, which isn't necessary. The items in the array are pointers, and that's what needs to be swapped.</p>
<p>See below:</p>
<pre><code>void SortArray( int ** pArray, int ArrayLength )
{
int i, j, flag = 1; // set flag to 1 to begin in... | <p>To complete Brian Ensink's post, you'll find the STL full of surprises. For example, the std::sort algorithm:</p>
<pre><code>#include <iostream>
#include <vector>
#include <algorithm>
void printArray(const std::vector<int *> & p_aInt)
{
for(std::vector<int *>::size_type i = 0, ... | 3,798 |
<p>How can I start writing a plugin for <a href="http://en.wikipedia.org/wiki/Eclipse_%28software%29" rel="noreferrer">Eclipse</a>?</p>
<p>I've looked for documentation, but unfortunately there is very little or it's poor, so what articles can recommended?</p>
| <p>There are some pretty good resources and tutorials on the main Eclipse and IBM's site. One of the best ways is to pick an open source plug-in that has some similar features to what you want to do and start to dissect it.</p>
<ul>
<li><em><a href="http://www.eclipse.org/articles/Article-PDE-does-plugins/PDE-intro.ht... | <p>I think a very good resource is also to look at the examples that are available via the new Plug-In Project wizard.</p>
<p>Depending on what you want to provide with your plug-in, you can choose from editor plug-ins, view plug-ins, plug-ins that provide a property page (just to name a few) and see how they're built... | 38,335 |
<p>A couple of months ago I've coded a tiny tool that we needed at work for a specific task, and I've decided to share it on CodePlex. It's written in C# and honestly it's not big deal but since it's the first project I've ever built from scratch in that language and with the goal of opening it from the very beginning,... | <p>You should:</p>
<ul>
<li>Promote it where you think it would be relevant (forums,mailing lists etc.). Try not to spam though - it will create a backlash.</li>
<li>continue to provide updates as to create the appearance of an active project until more people pick it up.</li>
<li>Find project leaders, they are the so... | <p>You should:</p>
<ul>
<li>Promote it where you think it would be relevant (forums,mailing lists etc.). Try not to spam though - it will create a backlash.</li>
<li>continue to provide updates as to create the appearance of an active project until more people pick it up.</li>
<li>Find project leaders, they are the so... | 16,613 |
<p>Our testers are in the process of evaluating Visual Studio Team System 2008 Test Edition. As they are unfamiliar with the use of Visual Studio, I would like to give them as much help as I can.</p>
<p>I have had a look on Amazon for books on the Test edition of VS.Net, but there is only one VS.Net 2005 test edition ... | <p>For someone evaluating features who isn't that familiar with Visual Studio, I'd recommend the videos from a few places:</p>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/vsts2008/bb507749.aspx?wt.slv=topsectionsee" rel="nofollow noreferrer">"How Do I?" Videos for Team System</a></li>
<li><a href="http://www.asp... | <p>Also, have a look at msdn:</p>
<p>Walkthroughs for Test Edition<br/>
<a href="http://msdn.microsoft.com/en-us/library/ms182417.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ms182417.aspx</a></p>
<p>Web Test Walkthroughs<br/>
<a href="http://msdn.microsoft.com/en-us/library/aa337591.aspx" ... | 29,903 |
<p>What effect does a field name length has on the performance of a database? Is it negligible? Should I go with long descriptive names?</p>
| <p>I haven't measured the time, but I would imagine negligible. The field names are going to be sent back and forth over the network, both in your SQL statements TO the database and in the metadata that comes back FROM the database, but I think the incremental difference that a few bytes makes in those packets is belo... | <p>Internally, the query processor uses numbers for field names once the tokens in the query are parsed,
There are no sensible performance gains in short names on database objects. </p>
| 30,581 |
<p>A basic problem I run into quite often, but ever found a clean solution to, is one where you want to code behaviour for interaction between different objects of a common base class or interface. To make it a bit concrete, I'll throw in an example;</p>
<p><em>Bob has been coding on a strategy game which supports "co... | <p>Terrain has-a Terrain Attribute </p>
<p>Terrain Attributes are multidimensional. </p>
<p>Units has-a Propulsion.</p>
<p>Propulsion is compatible able with Terrain Attributes.</p>
<p>Units move by a Terrain visit with Propulsion as an argument.
That gets delegated to the Propulsion.</p>
<p>Units <em>may</em> get... | <p>Old idea:</p>
<blockquote>
<p>Make a class iTerrain and another
class iUnit which accepts an argument
which is the terrain type including a
method for affecting each unit type</p>
<p>example:</p>
<pre> <code> boat = new
iUnit("watercraft") field = new
iTerrain("grass")
field.effects(boat)</code></pre>... | 9,401 |
<p>I need to encode a 100KB+ string as base64 in VBA. Are there any built-in functions or COM objects available which will do this as a pure VBA approach is either complex or doesn't scale well at these volumes (see links from <a href="http://www.vbforums.com/showthread.php?t=379072" rel="noreferrer">dbb</a> and <a hre... | <p>You can use the MSXML Base64 encoding functionality as described at <a href="http://web.archive.org/web/20060527094535/http://www.nonhostile.com/howto-encode-decode-base64-vb6.asp" rel="nofollow noreferrer">www.nonhostile.com/howto-encode-decode-base64-vb6.asp</a>:</p>
<pre><code>Function EncodeBase64(text As String... | <p>As Mark C points out, you can use the MSXML Base64 encoding functionality as described <a href="http://www.nonhostile.com/howto-encode-decode-base64-vb6.asp" rel="nofollow noreferrer">here</a>.</p>
<p>I prefer late binding because it's easier to deploy, so here's the same function that will work without any VBA refe... | 20,509 |
<p>In many C/C++ macros I'm seeing the code of the macro wrapped in what seems like a meaningless <code>do while</code> loop. Here are examples.</p>
<pre><code>#define FOO(X) do { f(X); g(X); } while (0)
#define FOO(X) if (1) { f(X); g(X); } else
</code></pre>
<p>I can't see what the <code>do while</code> is doing. ... | <p>The <code>do ... while</code> and <code>if ... else</code> are there to make it so that a
semicolon after your macro always means the same thing. Let's say you
had something like your second macro.</p>
<pre><code>#define BAR(X) f(x); g(x)
</code></pre>
<p>Now if you were to use <code>BAR(X);</code> in an <code>if... | <p>I don't think it was mentioned so consider this</p>
<pre><code>while(i<100)
FOO(i++);
</code></pre>
<p>would be translated into</p>
<pre><code>while(i<100)
do { f(i++); g(i++); } while (0)
</code></pre>
<p>notice how <code>i++</code> is evaluated twice by the macro. This can lead to some interesting er... | 18,624 |
<p>I have a form showing progress messages as a fairly long process runs. It's a call to a web service so I can't really show a percentage complete figure on a progress bar meaningfully. (I don't particularly like the Marquee property of the progress bar)</p>
<p>I would like to show an animated GIF to give the process... | <p>It's not too hard.</p>
<ol>
<li>Drop a picturebox onto your form.</li>
<li>Add the .gif file as the image in the picturebox</li>
<li>Show the picturebox when you are loading.</li>
</ol>
<p><strong>Things to take into consideration:</strong></p>
<ul>
<li>Disabling the picturebox will prevent the gif from being animat... | <p>I had the same issue and came across different solutions by implementing which I used to face several different issues. Finally, below is what I put some pieces from different posts together which worked for me as expected.</p>
<pre><code>private void btnCompare_Click(object sender, EventArgs e)
{
ThreadStart t... | 20,015 |
<p>Is there a maximum number of characters that can be written to a file using a StreamWriter? Or is there a maximum number of characters that <code>WriteLine()</code> can output? I am trying to write some data to a file but all of the data does not seem to make it. This is the current state of my code:</p>
<pre><code... | <p>Are you calling StreamWriter.Close() or Flush()?</p>
| <p>Make sure that you are calling .Flush()</p>
| 19,772 |
<p>Is there explicit support for Single Table Inheritance in Django? Last I heard, the feature was still under development and debate. </p>
<p>Are there libraries/hacks I can use in the meantime to capture the basic behavior? I have a hierarchy that mixes different objects. The canonical example of a corporation struc... | <p>There are currently two forms of inheritance in Django - MTI (model table inheritance) and ABC (abstract base classes).</p>
<p>I wrote a <a href="http://web.archive.org/web/20090227074910/http://thisweekindjango.com/articles/2008/jun/17/abstract-base-classes-vs-model-tab/" rel="noreferrer">tutorial</a> on what's go... | <p>I think you can do something akin to this.</p>
<p>I have to implement a solution for this problem myself, and here was how I solved it:</p>
<pre class="lang-py prettyprint-override"><code>class Citrus(models.Model):
how_acidic = models.PositiveIntegerField(max_value=100)
skin_color = models.CharField()
t... | 29,862 |
<p>I'd like to write a plugin that does something with the currently edited file in Eclipse. But I'm not sure how to properly get the file's full path.</p>
<p>This is what I do now:</p>
<pre><code>IFile file = (IFile) window.getActivePage().getActiveEditor.getEditorInput().
getAdapter(IFile.class);
</code></pre>
... | <p>Looks like you want <a href="http://help.eclipse.org/helios/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fcore%2Fresources%2FIResource.html" rel="noreferrer"><code>IResource.getRawLocation()</code></a>. That returns an <code>IPath</code>, which also has a <code>makeAbsolute()</... | <p>For me, this run ok.</p>
<p>IWorkspaceRoot workSpaceRoot = ResourcesPlugin.getWorkspace().getRoot();</p>
<p>File file = workSpaceRoot.getRawLocation().makeAbsolute().toFile();</p>
<p>file list from this location:</p>
<p>File[] files = file.listFiles();</p>
| 38,398 |
<p>In a custom module for drupal 4.7 I hacked together a node object and passed it to node_save($node) to create nodes. This hack appears to no longer work in drupal 6. While I'm sure this hack could be fixed I'm curious if there is a standard solution to create nodes without a form. In this case the data is pulled ... | <p>I don't know of a standard API for creating a node pragmatically. But this is what I've gleaned from building a module that does what you're trying to do.</p>
<ol>
<li>Make sure the important fields are set: uid, name, type, language, title, body, filter (see <code>node_add()</code> and <code>node_form()</code>)</l... | <p>One more answer I discovered was to use <a href="http://api.drupal.org/api/function/blogapi_blogger_new_post/6" rel="nofollow noreferrer">the example</a> from the blogapi module in drupal core. The fact that it is in core gives me a bit more confidence that it will continue to work in future versions.</p>
| 11,422 |
<p>I have a windows service connecting to a SqlServer database on the local box. This works fine most all the time. At a large customer, however, the database connectivity gets corrupted for some rare and unknown reason. When this happens, calls to DbDataAdapter.Fill return a DataSet with a different number of colum... | <p>I've got the following in my <code>.emacs</code></p>
<pre><code>(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
</code></pre>
| <p>The following should work in your .bash_profile or .bashrc</p>
<pre><code>case $TERM in
xterm-color)
export PS1='\[\e]0;\W\007\]\[\e[34;1m\]\W\[\e[0m\]\$ '
;;
*)
export PS1='\W\$ '
;;
esac
</code></pre>
| 31,979 |
<p>In logging frameworks like log4j & log4net you have the ability to log various levels of information. Most of the levels have obvious intentions (such as what a "Debug" log is vs. a "Error"). However, one thing that I have always been timid on was classifying my logging as "Fatal".</p>
<p>What type of errors ar... | <p>I consider fatal errors to be when your application can't do any more useful work. Non-fatal errors are when there's a problem but your application can still continue to function, even at a reduced level of functionality or performance.</p>
<p>Examples of fatal errors include:</p>
<ul>
<li>Running out of disk spac... | <p>To make this answer short and sweet, if your application crashes, I would consider that fatal. If you cannot connect to an important resource such as a database or a required service, that would be fatal. Overall, I would say that if it keeps your application from running correctly and affects the user, I would cl... | 40,395 |
<p>What are the best SNMP libraries to use with .NET? Specifically for listening for traps or sending set or get requests.</p>
| <p>I am using the <a href="http://www.codeplex.com/sharpsnmplib" rel="noreferrer">Sharp SNMP Suite (#SNMP)</a> : LGPL, Mono compatible, developed in C# 3.0, has very good API.</p>
| <p>I've personally used Adventnet's <a href="http://www.webnms.com/net-snmp/index.html" rel="nofollow noreferrer">.NET SNMP API</a> for snmp work. It's now been renamed to WebNMS. I have code running based on this API several places, that has just worked and keeps on working 24/7.</p>
<p>Recommended for lots of exampl... | 17,668 |
<p>I have some scripts that ought to have stopped running but hang around forever. Is there some way I can figure out what they're writing to STDOUT and STDERR in a readable way?</p>
<p>I tried, for example, to do:</p>
<pre><code>$ tail -f /proc/(pid)/fd/1
</code></pre>
<p>but that doesn't really work. It was a lo... | <p>Since I'm not allowed to edit Jauco's answer, I'll give the full answer that worked for me (Russell's page relies on un-guaranteed behaviour that, if you close file descriptor 1 for STDOUT, the next <code>creat</code> call will open FD 1.</p>
<p>So, run a simple endless script like this:</p>
<pre><code>import time... | <p>You don't state your operating system, but I'm going to take a stab and say "Linux".</p>
<p>Seeing what is being written to stderr and stdout is probably not going to help. If it is useful, you could use tee(1) before you start the script to take a copy of stderr and stdout.</p>
<p>You can use ps(1) to look for w... | 31,050 |
<p>How do I access a page's HTTP response headers via JavaScript?</p>
<p>Related to <a href="https://stackoverflow.com/questions/220149/how-do-i-access-the-http-request-header-fields-via-javascript"><strong>this question</strong></a>, which was modified to ask about accessing two specific HTTP headers.</p>
<blockquot... | <p>Unfortunately, there isn't an API to give you the HTTP response headers for your initial page request. That was the original question posted here. It has been <a href="https://stackoverflow.com/questions/12258705/how-can-i-read-the-current-headers-without-making-a-new-request-with-js">repeatedly asked</a>, too, beca... | <p>This is an old question. Not sure when support became more broad, but <code>getAllResponseHeaders()</code> and <code>getResponseHeader()</code> appear to now be fairly standard: <a href="http://www.w3schools.com/xml/dom_http.asp" rel="nofollow">http://www.w3schools.com/xml/dom_http.asp</a></p>
| 27,116 |
<p>I find the autoindent style of Notepad++ a little weird: when I am typing on an indented line, I <em>do</em> want it to indent the next line after I press Enter (this it does properly). However, when I am on an empty line (no indentation, no characters) and I press Enter, it indents the next line, using the same ind... | <p>1) First install NppAutoIndent plugin if you don't have it.</p>
<blockquote>
<p>Plugins > Plugin Manager > Show Plugin Manager, then <strong>install NppAutoIndent</strong> from the "Available" tab of that menu.</p>
</blockquote>
<p>2) This behavior can be turned off by doing:</p>
<blockquote>
<p>Plugins > Npp... | <p>To be honest, this to me seems expected behaviour. Blank lines are used a lot by myself to break up the code to make it more readable, having the program make me have to tab out again would be VERY annoying. </p>
<p>I can understand this as a frustration with something like Python, but not with PHP... Though, befor... | 14,457 |
<p>I need to update a <code>combobox</code> with a new value so it changes the reflected text in it. The cleanest way to do this is after the <code>combobox</code>has been initialised and with a message.</p>
<p>So I am trying to craft a <code>postmessage</code> to the hwnd that contains the <code>combobox</code>.</p>
... | <p>You want <a href="http://msdn.microsoft.com/en-us/library/bb856484(VS.85).aspx" rel="nofollow noreferrer">ComboBox_SetCurSel</a>:</p>
<pre><code>ComboBox_SetCurSel(hWndCombo, n);
</code></pre>
<p>or if it's an MFC CComboBox control you can probably do:</p>
<pre><code>m_combo.SetCurSel(2);
</code></pre>
<p>I woul... | <p>if you fx want to change the title - which is the line shown when combobox is closed, then you can do following:</p>
<p>m_ComboBox.DeleteString(0); // first delete previous if any, 0 = visual string
m_ComboBox.AddString(_T("Hello there"));</p>
<p>put this in fx. in OnCloseupCombo - when event close a dropdownbox f... | 8,382 |
<p>I am trying to use the <a href="http://www.javac.info/" rel="nofollow noreferrer">BGGA closures prototype</a> with an existing JDK 6 (standard on Mac OS X Leopard). The sample code I'm compiling is from a BGGA tutorial:</p>
<pre><code>public static void main(String[] args) {
// function with no arguments; return... | <p>The TAR file distribution includes a modified javac.bat with a complete command line, including "-source 7", which is probably what you are missing here.</p>
| <p>Have you tried javac with -J-Xbootclasspath instead? That's used for passing -X arguments to the VM itself, which may be necessary for a change as low-level as this.</p>
<p>I very much doubt this will work with Eclipse, though. System libraries are for APIs, not language changes. You'd need to patch the Eclipse co... | 20,778 |
<p>I would like to use the task-list in Visual Studio but it really lacks almost any useful feature a task-list should provide. So I use <a href="http://www.abstractspoon.com/" rel="noreferrer">Todo-List</a> externally, to keep track of the things I need to get done. Would be nice to have it all in one place.</p>
<p>S... | <p>For semi-immediate programming tasks I use TODO comments in code and ReSharper for Visual Studio to view them.</p>
<p>For longer-term tasks I use Team Foundation Server to record work items.</p>
<p>For non-programming tasks I use Google Calendar.</p>
| <p>I don't know of an add-on (I use <a href="http://www.rememberthemilk.com/" rel="nofollow noreferrer">Remember The Milk</a> externally), but I think you are onto a good idea there.</p>
| 12,044 |
<p>I am trying to insert an image (jpg) in to a word document and the Selection.InlineShapes.AddPicture does not seem to be supported by win32old or I am doing something wrong. Has anyone had any luck inserting images. </p>
| <p>You can do this by calling the Document.InlineShapes.AddPicture() method.</p>
<p>The following example inserts an image into the active document, before the second sentence.</p>
<pre><code> require 'win32ole'
word = WIN32OLE.connect('Word.Application')
doc = word.ActiveDocument
image = 'C:\MyImage... | <p>Running on WinXP, Ruby 1.8.6, Word 2002/XP SP3, I recorded macros and translated them, as far as I could understand them, into this:</p>
<pre><code>require 'win32ole'
begin
word = WIN32OLE::new('Word.Application') # create winole Object
doc = word.Documents.Add
word.Selection.InlineShapes.AddPicture "C:\\p... | 31,926 |
<p>I am thinking along the lines of replicating a web hosts PHP setup environment for offline local development. The idea is to parse the output of phpinfo() and write any setup values it contains into a local php.ini. I would imagine everything ism included in phpinfo and that certain things would only be specific to... | <p>You will probably get more usable results from ini_get_all()</p>
<p><a href="http://us.php.net/manual/en/function.ini-get-all.php" rel="nofollow noreferrer">http://us.php.net/manual/en/function.ini-get-all.php</a></p>
<p>You could then traverse the associated array to reconstruct an ini file without the hassle of ... | <p>It's quite likely to just be a stock install. Even then, I'd still want to make the local development environment subtly different to the live php.ini, to ensure that it showed all errors that were being produced (as opposed to hiding, or just logging them on the live site).</p>
| 12,502 |
<p>I want to create a component that allows us to have compound keyboard shortcuts associated with an arbitrary command, like the Visual Studio IDE and Microsoft Office do.</p>
<p>That is, keyboard shortcuts consisting of a sequence of multiple keystrokes, such as <kbd>Ctrl</kbd> + <kbd>W</kbd> + <kbd>C</kbd>. In Visu... | <p>In answer to the question of <strong>keyboard chords</strong> specifically, I do not believe there is a ready-made option available to you at this point.</p>
<p>However, it should be simple enough to model. I would create a single class, perhaps <code>KeyboardChordProvider</code>. It will need to know about keybo... | <p>Use the form's OnKeyPressed event and check if the desired key combination was pressed in the eventArgs argument </p>
| 23,334 |
<p>An application I am working on reads information from files to populate a database. Some of the characters in the files are non-English, for example accented French characters.</p>
<p>The application is working fine in Windows but on our Solaris machine it is failing to recognise the special characters and is throw... | <p>Try to use</p>
<pre><code>java -Dfile.encoding=UTF-8 ...
</code></pre>
<p>when starting the application in both systems.</p>
<p>Another way to solve the problem is to change the encoding from both system to UTF-8, but i prefer the first option (less intrusive on the system).</p>
<p>EDIT:</p>
<p>Check this answe... | <p>You can also set the encoding at the command line, like so <code>java -Dfile.encoding=utf-8</code>.</p>
| 31,234 |
<p>How can I deploy a custom authentication provider in MOSS 2007?</p>
<p>Is there any provided functionality to do this (like a Sharepoint feature)?</p>
<p>Or do I have to install it in the GAC on each box in the farm manually? </p>
| <p>The usual approach for installing extensions like this is to use a feature, yes. However, you won't be using any specialized XML as this kind of extension is not catered for explicitly. So how can you do it? By using an essentially empty feature project that contains an Event Receiver assembly. The event receiver as... | <p>The <a href="http://www.codeplex.com/Release/ProjectReleases.aspx?ProjectName=CKS&ReleaseId=7746" rel="nofollow noreferrer">Windows Live Authentication</a> feature of the Community Kit for Sharepoint provides a nice example (with source code) of creating a solution package with a custom authentication provider. ... | 33,899 |
<p>I want to have a class which implements an interface, which specifies the specific subclass as a parameter.</p>
<pre><code>public abstract Task implements TaskStatus<Task> {
TaskStatus<T> listener;
protected complete() {
// ugly, unsafe cast
callback.complete((T) this);
}
}
public in... | <p>It is not clear what you are trying to do inside of <code>Task</code>. However, if you define the generic class <code>Task<T></code> as follows:</p>
<pre><code>class Task<T extends Task<T>> { ... }
</code></pre>
<p>The following two are possible:</p>
<pre><code>class MyTask extends Task<MyTas... | <p>I'm having a little trouble understanding what you're trying to accomplish through this. Could you provide some more details?</p>
<p>My read of the code says you have these tasks which will be sub-classed and after the tasks are complete, the executing thread will call complete() on the task. At this point you wa... | 18,605 |
<p>I've been told that code such as:</p>
<pre><code>for (int i = 0; i < x.length(); i++) {
// blah
}
</code></pre>
<p>is actually O(n^2) because of the repeated calls to <code>x.length()</code>. Instead I should use:</p>
<pre><code>int l = x.length();
for (int i = 0; i < l; i++) {
// blah
}
</code></pr... | <p>No, the length of a java string is O(1) because java's string class stores the length as a field.</p>
<p>The advice you've received is true of C, amongst other languages, but not java. C's strlen walks the char array looking for the end-of-string character. Joel's talked about it on the podcast, but in the context ... | <p>According to <a href="http://www.docjar.com/html/api/java/lang/String.java.html" rel="nofollow noreferrer">this</a>, the length is a field of the String object.</p>
| 31,778 |
<p>I've read the documentation on <a href="http://msdn.microsoft.com/en-us/library/ms776420(VS.85).aspx" rel="noreferrer">WideCharToMultiByte</a>, but I'm stuck on this parameter:</p>
<pre><code>lpMultiByteStr
[out] Pointer to a buffer that receives the converted string.
</code></pre>
<p>I'm not quite sure how to pro... | <p>Here's a couple of functions (based on Brian Bondy's example) that use WideCharToMultiByte and MultiByteToWideChar to convert between std::wstring and std::string using utf8 to not lose any data.</p>
<pre><code>// Convert a wide Unicode string to an UTF8 string
std::string utf8_encode(const std::wstring &wstr)
... | <p>Here is a <code>C</code> implementation of both <code>WideCharToMultiByte</code> and <code>MultiByteToWideChar</code>.
In both cases I ensure to tack a <code>null</code> character to the end of the destination buffers.</p>
<blockquote>
<p>MultiByteToWideChar does not null-terminate an output string if the input stri... | 26,547 |
<p>Does anyone have experience with developing for Sharepoint 2003 using Visual Studio 2008?</p>
<p>I need to upgrade to VS2008 because of Vista issues but need to support Sharepoint 2003 webparts. The webparts are all pretty simple. Will I be able to support those webparts using VS2008?</p>
| <p>AFAIK VS2008 only allows you to build .NET 2.0/3.0 out of the box, but...</p>
<p>I have VS2005 projects spitting out .NET 1.1 assemblies for WSSv2/SPS2003 and .NET 2.0 for WSSv3/MOSS2007 using MSBEE and I would think that this is possible in VS2008 also.</p>
<p>You will need to use MSBEE
<a href="http://www.codepl... | <p>SharePoint 2003 is built on top of .NET 1.1 and only Visual Studio 2003 supports it. I would recommend you not to use anything else. </p>
<p>I would advise you to create a virtual machine with SharePoint 2003 and Visual Studio 2003 and develop everything inside VM. This approach can be helpful if you are working on... | 30,124 |
<p>Is there anyone who has used or looked into using Jitterbit as well as BizTalk? If so, what are some pros and cons of each, and which one did you go with as your final solution?</p>
<p>Specifically, I'm looking for SAP integration, but any input would be appreciated.</p>
| <p>I've done a fair bit of integration with SAP, starting with the old SAP DCOM connector. More recently I've been involved in the selection of an integration platform to serve in an Enterprise Service Bus pattern.</p>
<p>We did web service samples to connect to SAP on a number of platforms, including BizTalk, Mule, ... | <p>I will say it simply, I have been using biztalk and was one of the people that helped validate the 2006 training course. Biztalk by far one the best server applications for Business process that is available today. You do also have to factor in the price point is ridiculously low compared to what else is out there.<... | 49,513 |
<p>I understand the overall meaning of pointers and references(or at least I think i do), I also understand that when I use <b>new</b> I am dynamically allocating memory.</p>
<p>My question is the following:</p>
<p>If i were to use <code>cout << &p</code>, it would display the "virtual memory location" of <... | <p>Sure, you can manipulate the pointer to access the different elements in the array, but you will need to manipulate the content of the pointer (i.e. the address of what p is pointing to), rather than the address of the pointer itself.</p>
<pre><code>int *p = new int[3];
p[0] = 13;
p[1] = 54;
p[2] = 42;
cout <&l... | <p>Think of "pointer types" in C and C++ as laying down a very long, logical <strong>row of cells</strong> superimposed on the bytes in the memory space of the CPU, starting at byte 0. The width of each cell, in bytes, depends on the "type" of the pointer. Each pointer type lays downs a row with differing cell widths. ... | 13,282 |
<p>I'm building a basic search functionality, using LIKE (I'd be using fulltext but can't at the moment) and I'm wondering if MySQL can, on searching for a keyword (e.g. WHERE field LIKE '%word%') return 20 words either side of the keyword, as well?</p>
| <p>You can do it all in the query using SUBSTRING_INDEX</p>
<pre><code>CONCAT_WS(
' ',
-- 20 words before
TRIM(
SUBSTRING_INDEX(
SUBSTRING(field, 1, INSTR(field, 'word') - 1 ),
' ',
-20
)
),
-- your word
'word',
-- 20 words after
TRIM(
SUBSTRING_INDEX(
SUBSTRING(field, INSTR... | <p>Use the INSTR() function to find the position of the word in the string, and then use SUBSTRING() function to select a portion of characters before and after the position.</p>
<p>You'd have to look out that your SUBSTRING instruction don't use negative values or you'll get weird results.</p>
<p>Try that, and repor... | 5,895 |
<p>I'm wondering if there's any way to write CSS specifically for Safari using only CSS. I know there has to be something out there, but I haven't found it yet.</p>
| <p>I think the question is valid. I agree with the other responses, but it doesn't mean it's a terrible question. I've only ever had to use a Safari CSS hack once as a temporary solution and later got rid of it. I agree that you shouldn't have to target just Safari, but no harm in knowing how to do it.</p>
<p>FYI, thi... | <p>This really depends on what you are trying to do. Are you trying to do something special just in safari using some of the CSS3 features included or are you trying to make a site cross browser compliant?</p>
<p>If you are trying to make a site cross browser compliant I'd recommend writing the site to look good in sa... | 9,481 |
<p>When using a subdomain and trying to view anything related to current_user. user is sent to a new session page, the page shows the session is created and gives the option to logout. I can use no subdomain and it works fine.</p>
| <p>Set it in your environment.rb (or environments/*.rb if you'll use different domains for each environment):</p>
<pre><code>ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.update( :session_domain => '.domain.com')
</code></pre>
| <p>@jkrall - to add to that, the whole options hash moved to :key, :secret, and :domain vs :session_key, :session_domain, etc.</p>
| 40,054 |
<p>I have looked at the ability to use tabs in Vim (with <code>:tabe</code>, <code>:tabnew</code>, etc.) as a replacement for my current practice of having many files open in the same window in hidden buffers.</p>
<p>I would like every distinct file that I have open to always be in its own tab. However, there are some... | <p>Stop, stop, stop.</p>
<p>This is not how Vim's tabs are designed to be used. In fact, they're misnamed. A better name would be "viewport" or "layout", because that's what a tab is—it's a different layout of windows of <em>all</em> of your existing buffers.</p>
<p>Trying to beat Vim into 1 tab == 1 buffer is ... | <p>relevant:
<a href="https://stackoverflow.com/questions/3297156/vim-can-global-marks-switch-tabs-instead-of-the-file-in-the-current-tab/71923358#71923358">Vim: can global marks switch tabs instead of the file in the current tab?</a></p>
<p>maybe useful to solve a little part of OP's problem:</p>
<pre><code> nno \ ... | 12,792 |
<p>I am troubleshooting an issue with IIS6 where all sites bound to ip addresses other than the default give an error message "network location cannot be reached" when trying to start any of these sites.</p>
<p>The nic has all the ip addresses configured.
When I do a httpcfg query iplisten, I see only the default ip a... | <p>The solution was to use httpcfg without specifying the port number. </p>
| <p>Sometimes there are bugs wehn applying windows updates. One thing you might try is running aspnet_regiis /i or /c. I'm not sure if that's your problem but it's certainly worth a shot.</p>
| 18,766 |
<p>When an iPhone application manages its own preferences, rather than using a bundle, it seems to be common practice to style that view to mimic the System Preferences app: fields are grouped by light rectangles with rounded edges; titles and explanatory text are added to the space between. </p>
<p>What is best used... | <p>You need to use a UITableView with the "group" style. I've seen some applications that "fake" it with graphics, but doing it with the correct components isn't terribly tricky. The main downside being you can't do it all in Interface Builder.</p>
| <p>The WordPress app does this. Look at the BlogDetail controller and nib. You'll see many UITableViewCells that are returned when the table asks for the row/section data from the controller.</p>
<p>You can find the code at the <a href="http://iphone.wordpress.org/contribute/" rel="nofollow noreferrer">Wordpress iPh... | 41,460 |
<p>A programmer I know has a website that is fully Standards Compliant. It uses Unicode-encoded fully-validated XHTML 1.1 with CSS. The pages are frames-free, table-free and JavaScript-free.</p>
<p>He would like to be directed to a blogging tool that does not demand any particular database system or web server, but d... | <p>I can't see this being a problem - allowable comments are not specified in a DTD (as they're effectively for humans, not computers). Also, the DOM API (<a href="http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html" rel="noreferrer">http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html</a>) explicitly allows m... | <p>Yes by all means. Any rendering engine (IE, Firefix, Opera, Safari, etc) will ignore any HTML comment tag completely regardless which position.</p>
| 47,756 |
<p>How would you write a regular expression to convert mark down into HTML? For example, you would type in the following:</p>
<pre><code>This would be *italicized* text and this would be **bold** text
</code></pre>
<p>This would then need to be converted to:</p>
<pre><code>This would be <em>italicized</em&... | <p>The best way is to find a version of the Markdown library ported to whatever language you are using (you did not specify in your question). </p>
<hr>
<p>Now that you have clarified that you only want STRONG and EM to be processed, and that you are using C#, I recommend you take a look at <a href="http://www.aspne... | <p>I came across the following <a href="http://kore-nordmann.de/blog/do_NOT_parse_using_regexp.html" rel="nofollow noreferrer">post</a> that recommends to not do this. In my case though I am looking to keep it simple, but thought I would post this per <a href="https://stackoverflow.com/users/11830/jop">jop's</a> recom... | 13,592 |
<p>So I just interviewed two people today, and gave them "tests" to see what their skills were like. Both are entry level applicants, one of which is actually still in college. Neither applicant saw anything wrong with the following code.</p>
<p>I do, obviously or I wouldn't have picked those examples. <strong>Do yo... | <p>I don't typically throw code at someone interviewing for a position and say "what's wrong?", mainly because I'm not convinced it really finds me the best candidate. Interviews are sometimes stressful and a bit overwhelming and coders aren't always on their A-game.</p>
<p>Regarding the questions, honestly I think ... | <p>Q1 also has a potential InvalidCastException on the <code>item.FindControl()</code> line.</p>
<p>I don't think Q1 or Q2 are outside the realms of being too hard, even for non C# users. Any level code should be able to see that you should be using a boolean for active, and only using one if statement.</p>
<p>Q3 tho... | 18,227 |
<p>This came up in <a href="https://stackoverflow.com/questions/101268/hidden-features-of-python">Hidden features of Python</a>, but I can't see good documentation or examples that explain how the feature works.</p>
| <p><code>Ellipsis</code>, or <code>...</code> is not a hidden feature, it's just a constant. It's quite different to, say, javascript ES6 where it's a part of the language syntax. No builtin class or Python language constuct makes use of it. </p>
<p>So the syntax for it depends entirely on you, or someone else, having... | <p>As stated in other answers, it can be used for creating slices.
Useful when you do not want to write many full slices notations (<code>:</code>), or when you are just not sure on what is dimensionality of the array being manipulated.</p>
<p>What I thought important to highlight, and that was missing on the other an... | 14,409 |
<p>Can I somehow disable spell-checking on HTML textfields (as seen in e.g. Safari)?</p>
| <p><strong>Update</strong>: As suggested by a commenter (additional credit to <a href="https://stackoverflow.com/questions/3416867/how-can-i-disable-the-spell-checker-on-text-inputs-on-the-iphone">How can I disable the spell checker on text inputs on the iPhone</a>), use this to handle all desktop and mobile browsers.<... | <p>If you have created your HTML element dynamically, you'll want to disable the attribute via JS. There is a little trap however:</p>
<p>When setting <code>elem.contentEditable</code> you can use either the boolean <code>false</code> or the string <code>"false"</code>. But when you set <code>elem.spellcheck<... | 31,774 |
<p>I am experiencing a minor layer separation when printing a body for a tipping-bucket rain gauge, which is basically a hollow tube with thin walls (3 mm). I am using <strong>Prusa I3 MK2</strong> and a <strong>Fillamentum ABS</strong> white plastic. The model has been sliced in <strong>Siplify 3D</strong> with the fo... | <p>The best thing you can do for a large ABS print is to have an enclosure heated to 50C or better. For example, see <a href="https://www.3dhubs.com/talk/thread/enclosed-vs-open-printers" rel="nofollow noreferrer">this</a>, <a href="https://www.reddit.com/r/3Dprinting/comments/2ynb78/heated_build_enclosure_temperatures... | <p>increasing the temperature by 5 to 10° as well as, increasing the layer thickness to "0.3" or "0.35" may assist ,additionally increasing the flow rate of the filament, by a small margin at most 10%. These options should improve the quality of the print as they improve the layer adhesion, however none of these option... | 668 |
<p>How do you install Boost on MacOS?
Right now I can't find bjam for the Mac.</p>
| <p>Download <a href="https://www.macports.org/" rel="noreferrer">MacPorts</a>, and run the following command:</p>
<pre><code>sudo port install boost
</code></pre>
| <p>you can download bjam for OSX (or any other OS) <a href="http://sourceforge.net/project/showfiles.php?group_id=7586&package_id=72941" rel="nofollow noreferrer">here</a></p>
| 12,989 |
<p>I have a Visual Studio 2005 solution (.sln) with a mix of .NET and C++ projects. What is the best way to generate the .build file I will need to run my build process with NAnt. I'm new to using NAnt, and I'm not sure how to set it up. Will I have to update the .build file manually every time there is a new source fi... | <p>There is no way that I know of to generate a .build file from an sln. There should be decent examples of .build files at <a href="http://nant.sourceforge.net" rel="nofollow noreferrer">http://nant.sourceforge.net</a>.</p>
<p>That being said there are two ways to build a .sln file from NAnt.</p>
<ul>
<li>checkout n... | <p>With nant you will have to use the EXEC command to shell out to msbuild for the solution files. </p>
<p>Others have been experiencing the same issues.</p>
| 43,951 |
<p>Is there any website/service which will enable me to add RSS subscription to any website?</p>
<p>This is for my company I work. We have a website which displays company related news. These news are supplied by an external agency and they gets updated to our database automatically. Our website picks up random/new ne... | <p>If you have the data in your database, creating one yourself is fairly straight forward - there's a simple tutorial <a href="http://www.downes.ca/cgi-bin/page.cgi?post=56" rel="nofollow noreferrer">here</a>.</p>
<p>Once you've set up a feed, in the <head> of your page, you put text like:</p>
<pre><code><l... | <p>Write a webhandler that exposes the content of the database as an RSS feed.</p>
| 11,894 |
<p>How can one programmatically sort a union query when pulling data from two tables? For example,</p>
<pre><code>SELECT table1.field1 FROM table1 ORDER BY table1.field1
UNION
SELECT table2.field1 FROM table2 ORDER BY table2.field1
</code></pre>
<p>Throws an exception</p>
<p>Note: this is being attempted on MS Acces... | <p>Sometimes you need to have the <code>ORDER BY</code> in each of the sections that need to be combined with <code>UNION</code>.</p>
<p>In this case</p>
<pre><code>SELECT * FROM
(
SELECT table1.field1 FROM table1 ORDER BY table1.field1
) DUMMY_ALIAS1
UNION ALL
SELECT * FROM
(
SELECT table2.field1 FROM table2... | <p>The second table cannot include the table name in the <code>ORDER BY</code> clause.</p>
<p>So...</p>
<pre><code>SELECT table1.field1 FROM table1 ORDER BY table1.field1
UNION
SELECT table2.field1 FROM table2 ORDER BY field1
</code></pre>
<p>Does not throw an exception</p>
| 26,288 |
<p>I create a GUID (as a string) and get the hash of it. Can I consider this hash to be unique?</p>
| <p>Not as reliably unique as the GUID itself, no.</p>
<p>Just to expand, you are reducing your uniqueness by a factor of 4, going from 16 bytes to 4 bytes of possible combinations.</p>
<p>As pointed out in the comments the hash size will make a difference. The 4 byte thing was an assumption, horrible at best I know, ... | <p>If you use cryptographic hash (MD5, SHA1, RIPEMD160), the hash will be unique (modulo collisions which are very improbable -- SHA1 is used e.g. for digital signatures, and MD5 is also collision-resistant on <em>random inputs</em>). Though, why do you want to hash a GUID?</p>
| 16,735 |
<p>I remember back when MS released a forum sample application, the design of the application was like this:</p>
<p>/Classes/User.cs
/Classes/Post.cs
...
/Users.cs
/Posts.cs</p>
<p>So the classes folder had just the class i.e. properties and getters/setters.
The Users.cs, Post.cs, etc. have the actual methods that ac... | <p>If every method is just a static call straight to the data source, then the "Posts" class is really a Factory. You could certainly put the static methods in "Posts" into the "Post" class (this is how CSLA works), but they are still factory methods.</p>
<p>I would say that a more modern and accurate name for the "P... | <p>Are you sure the classes aren't partial classes. In which case they really aren't two classes, just a single class spread across multiple files for better readability.</p>
| 8,252 |
<p>I have an array I've created in JavaScript. The end result comes out to element1,element2,,,element5,element6,,,element9.... etc</p>
<p>Once passed to ColdFusion, it removes the null elements, I end up with element1,element2,element5,element6,element9</p>
<p>I need to maintain these spaces, any ideas? My problem... | <p>Are you deserializing the jS array into a list? CF ignores empty list fields using its built-in functions. This can be worked around by processing the text directly. Someone has already done this for you, fortunately. There are several functions at cflib.org, like:</p>
<ul>
<li><a href="http://cflib.org/udf/Lis... | <p>In exchanging data between javascript and coldfusion have a look at using JSON. </p>
<p><a href="http://www.json.org" rel="nofollow noreferrer">http://www.json.org</a></p>
<p><a href="http://www.epiphantastic.com/cfjson/" rel="nofollow noreferrer">http://www.epiphantastic.com/cfjson/</a></p>
| 28,966 |
<p>I don't see a Visual Studio plugin for it (although I didn't look that hard, so I might have missed it), and searches turn up random third-party solutions, but is there something that comes with PowerShell or something that plugs into Visual Studio?</p>
| <p>Visual Studio templates are available <a href="http://channel9.msdn.com/playground/Sandbox/249904-Windows-PowerShell-Visual-Studio-2005-Templates-C-and-VBNET/" rel="nofollow noreferrer">here</a>. And there are samples in the Server 2008 SDK for developing providers and hosts.</p>
<p>If you are talking about an IDE... | <p>Sapiens Powershell Studio 2012 - hands down the best Powershell specific IDE.</p>
<p><a href="http://www.sapien.com/software/powershell_studio" rel="nofollow">http://www.sapien.com/software/powershell_studio</a></p>
| 30,398 |
<p>Like the title says, If I place an <code>app_offline.htm</code> in the application root, will it cut off currently running requests, or just new ones?</p>
| <p>Here is my lame experiment; I created an ASPX page with the following code:
</p>
<pre class="lang-cs prettyprint-override"><code>protected void Page_Load(object sender, EventArgs e)
{
Response.BufferOutput = false;
Response.Write("Step 1<br />");
System.Threading.Thread.Sleep(10000);
Response.... | <p>From ScottGu's blog:</p>
<blockquote>
<p>Basically, if you place a file with
this name in the root of a web
application directory, <strong>ASP.NET 2.0
will shut-down the application, unload
the application domain from the
server, and stop processing any new
incoming requests for that
application</st... | 21,656 |
<p>I have a script that did double inserts into the database with the same data. Is there a good way to do this (without scanning through, inserting every record into an array, and then deleting duplicate array entries)?</p>
| <pre><code>DELETE
FROM t
WHERE ID IN (
SELECT MAX(ID)
FROM t
GROUP BY {Your Group Criteria Here}
HAVING COUNT(*) > 1
)
</code></pre>
| <p>If you don't have anything referencing into the table by key right now, I'd mysqldump --complete-insert it, strip the primary keys, change the table definition to enforce some unique key or another that would catch your duplications, change the INSERTs to REPLACEs, and load the data back in. Gets you a nice clean t... | 49,770 |
<p>What techniques and/or modules are available to implement robust rate limiting (requests|bytes/ip/unit time) in apache?</p>
| <p>The best</p>
<ul>
<li><a href="https://github.com/jzdziarski/mod_evasive" rel="noreferrer">mod_evasive</a> (Focused more on reducing DoS exposure)</li>
<li><a href="http://dembol.org/blog/mod_cband/" rel="noreferrer">mod_cband</a> (Best featured for 'normal' bandwidth control)</li>
</ul>
<p>and the rest</p>
<ul>
... | <p>One more option - mod_qos</p>
<p>Not simple to configure - but powerful.</p>
<p><a href="http://opensource.adnovum.ch/mod_qos/" rel="nofollow">http://opensource.adnovum.ch/mod_qos/</a></p>
| 15,976 |
<p>I want to build an ASP.NET MVC application with Boo instead of C#. If you know the steps to configure this type of project setup, I'd be interested to know what I need to do. </p>
<p>The MVC project setup is no problem. What I'm trying to figure out how to configure the pages and project to switch to use the Boo la... | <p>So there are two levels of "work with Boo". One would be all the code (namely, the Controllers), and the other would be the views.</p>
<p>For the code, I assume Boo compiles to standard .NET assemblies, so simply properly following the naming conventions using by ASP.NET MVC should allow you to write Controllers. Y... | <p>The Brail view engine has been implemented to be used in ASP.NET MVC. The <a href="http://www.mvccontrib.org" rel="nofollow noreferrer">MvcContrib</a> project implemented the code. The <a href="http://code.google.com/p/mvccontrib/" rel="nofollow noreferrer">source code</a> is located on Google Code.</p>
<p>As far... | 5,060 |
<p>First, yes I know about <a href="https://stackoverflow.com/questions/50182/linuxx11-input-library-without-creating-a-window">this question</a>, but I'm looking for a bit more information that that. I have actually, a fairly similar problem, in that I need to be able to capture input for mouse/keyboard/joystick, and ... | <p>Using the link below look at the function void kGUISystemX::Loop(void)</p>
<p>This is my main loop for getting input via keyboard and mouse using X Windows on Linux.</p>
<p><a href="http://code.google.com/p/kgui/source/browse/trunk/kguilinux.cpp" rel="noreferrer">http://code.google.com/p/kgui/source/browse/trunk/k... | <p>You can get direct input from the files in /dev/input. This is simplest way to do it, and you don't need any extra software. </p>
| 15,296 |
<p>Assuming I have only the class name of a generic as a string in the form of "MyCustomGenericCollection(of MyCustomObjectClass)" and don't know the assembly it comes from, what is the easiest way to create an instance of that object? </p>
<p>If it helps, I know that the class implements IMyCustomInterface and is fro... | <p>Once you parse it up, use <a href="http://msdn.microsoft.com/en-us/library/w3f99sx1.aspx" rel="noreferrer">Type.GetType(string)</a> to get a reference to the types involved, then use <a href="http://msdn.microsoft.com/en-us/library/system.type.makegenerictype.aspx" rel="noreferrer">Type.MakeGenericType(Type[])</a> t... | <p>If you don't mind translating to VB.NET, something like this should work</p>
<pre><code>foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
{
// find the type of the item
Type itemType = assembly.GetType("MyCustomObjectClass", false);
// if we didnt find it, go to the next assembly
... | 15,812 |
<p>When a PHP application makes a database connection it of course generally needs to pass a login and password. If I'm using a single, minimum-permission login for my application, then the PHP needs to know that login and password somewhere. What is the best way to secure that password? It seems like just writing it i... | <p>Several people misread this as a question about how to <strong>store</strong> passwords in a database. That is wrong. It is about how to store the password that lets you get <strong>to</strong> the database.</p>
<p>The usual solution is to move the password out of source-code into a configuration file. Then leav... | <p>Actually, the best practice is to store your database crendentials in environment variables because :</p>
<ul>
<li>These credentials are dependant to environment, it means that you won't have the same credentials in dev/prod. Storing them in the same file for all environment is a mistake.</li>
<li>Credentials are <s... | 12,348 |
<p>During the installation of Apache2 I got the following message into cmd window:</p>
<blockquote>
<p>Installing the Apache2.2 service The
Apache2.2 service is successfully
installed. Testing httpd.conf....</p>
<p>Errors reported here must be corrected
before the service can be started.
httpd.exe: Coul... | <p>There is some other program listening on port 80, usual suspects are</p>
<ol>
<li>Skype (Listens on port 80)</li>
<li>NOD32 (Add Apache to the IMON exceptions' list for it to allow apache to bind)</li>
<li>Some other antivirus (Same as above)</li>
</ol>
<p>Way to correct it is either shutting down the program that... | <p>Thanks for the help guys. I found another culprit. Recently SimplifyMedia added a photo sharing option. Apparently it too uses port 80 and prevented Apache from starting up. I hope this helps someone out.</p>
| 23,771 |
<p>I'm working on a form that will display links to open different types of reports. This system has different types of users, so the users should only be able to see the links to the types of reports they can access.</p>
<p>Currently, the way I have this set up is that I have an ArrayList of LinkLabels, but the prob... | <p>You can apply the same event handler to every LinkLabel in your list and get the specific LinkLabel from the sender argument.</p>
| <p>Definitely recommend a single event handler for all of the dynamic LinkLabel instances. </p>
<p>I usually use a Hashtable where the key is the LinkLabel instance and the value is something that will be used within the click event (such as the report instance, if appropriate). </p>
<p>Then in the click event you us... | 17,056 |
<p>I need the "Select Data Source" dialog added to my application so that the user can manually select a range (or ranges) in Excel and the range is pasted in my text box. This functionality is everywhere in Excel (most notably when selecting a range for a chart). How can I easily do this?</p>
| <p>have you tried using the refedit control?</p>
<p><a href="http://support.microsoft.com/kb/213776" rel="nofollow noreferrer">How to Use the RefEdit Control with a UserForm</a></p>
| <pre><code>Dim myRange As Range
On Error Resume Next
Set myRange = Application.InputBox(prompt:="Select the cells you want", Type:=8)
On Error GoTo 0
If myRange Is Nothing Then
MsgBox "User cancelled"
Else
MsgBox "User selected " & myRange.Address
End If
</code></pre>
<p>This will show an input... | 29,460 |
<p>On input validation, I'm using balloon tips instead of message boxes.
My problem is that on Vista, they have the old XP style with the rounded corners, not the newer more rectangle like appearance.</p>
<p>I've tried creating them using CreateWindowEx and <code>tooltips_class32</code> or showing the Edit's associate... | <p>If you're using Delphi 2009, then adding balloon hints is reasonably straightforward, although the documentation is poor. (surprise, surprise)</p>
<ul>
<li>Drop a TBalloonHint on your form</li>
<li>Drop a TImageList to contain icons if needed.</li>
<li>Link the TIMageList to the TBalloonHint</li>
<li>Set the form's... | <p>As can be read in <a href="http://dn.codegear.com/article/38757" rel="nofollow noreferrer">Delphi 2009 reviewers guide</a> each VCL component now has a CustomHint property. It can be set to any descendant of TCustomHint.</p>
<p>Be sure to enable baloon hints in Vista else they won't show.</p>
| 38,162 |
<p>After hitting a few StackOverflowExceptions in .NET I noticed they completely bypass the unhandled exception handlers that .NET offers (Application.ThreadException / AppDomain.UnhandledException).
This is very disturbing since we have critical cleanup code in those exception handlers.</p>
<p>Is there any way to ove... | <p>There are three kind of so-called "asynchronous exceptions". That are the ThreadAbortException, the OutOfMemoryException and the mentioned StackOverflowException. Those excepions are allowed to occur at any instruction in your code.</p>
<p>And, there's also a way to overcome them:</p>
<p>The easiest is the ThreadA... | <p><a href="https://stackoverflow.com/a/107742/4076315">blowdart nailed it</a>. Really just a problem with typing code too quickly.</p>
<pre><code>private Thing _myThing = null;
Public Thing MyThing
{
get{
return this.MyThing;}
set{
this.MyThing = value;}
}
</code></pre>
| 13,315 |
<p>I'm making an automated script to read a list from a site posting the latest compiled code. That's the part I've already figured out. The next part of the script is to grab that compiled code from a server with an Untrusted Cert.</p>
<p>This is how I'm going about grabbing the file:</p>
<pre><code>$web = new-obj... | <p>You need to write a callback handler for <a href="http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.servercertificatevalidationcallback.aspx" rel="nofollow noreferrer">ServicePointManager.ServerCertificateValidationCallback</a>.</p>
| <p>The simplest PowerShell implementation of ServerCertificateValidationCallback is a script block that always returns true. This works for me in PowerShell version 5.1; haven't tested it on other versions.</p>
<pre><code>[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
</code></pre>
<... | 17,695 |
<p>I am using log.properties to configure logging for a Java app. Each class gets its own logger named after itself (e.g. com.company.program.ClassX).</p>
<p>I want to set a custom formatter for just one log, and leave the handler with the SimpleFormatter. Is this possible?</p>
<p>I am not interested in using log4j o... | <p>The <a href="http://java.sun.com/javase/6/docs/api/java/util/logging/Handler.html" rel="nofollow noreferrer">Handler</a> owns the Formatter, not the Logger. You would need a second Handler to perform special formatting. I'm assuming that you want both to show up in the console, so the answer would appear to be "no".... | <p>I believe this is a limitation of Java logging. </p>
<p>You should decide to become interested in log4j. java.util.logging is only marginally better than <code>System.out.println</code></p>
| 25,870 |
<p>Say I have a Rails Model called Thing. Thing has a url attribute that can <strong>optionally</strong> be set to a URL somewhere on the Internet. In view code, I need logic that does the following:</p>
<pre><code><% if thing.url.blank? %>
<%= link_to('Text', thing_path(thing)) %>
<% else %>
<%= ... | <p>In Rails 3 and higher:</p>
<pre><code>Rails.application.routes.url_helpers
</code></pre>
<p>e.g.</p>
<pre><code>Rails.application.routes.url_helpers.posts_path
Rails.application.routes.url_helpers.posts_url(:host => "example.com")
</code></pre>
| <p><em>(Edit: Forget my previous babble...)</em></p>
<p>Ok, there might be situations where you would go either to the model or to some other url... But I don't really think this belongs in the model, the view (or maybe the model) sounds more apropriate.</p>
<p>About the routes, as far as I know the routes is for the... | 44,327 |
<p><a href="http://www.nevrona.com/" rel="nofollow noreferrer">Nevrona Designs'</a> <a href="http://www.nevrona.com/Products/RaveReports/StandardEdition/tabid/66/Default.aspx" rel="nofollow noreferrer">Rave Reports</a> is a Report Engine for use by <a href="http://www.embarcadero.com/" rel="nofollow noreferrer">Embarca... | <p>This is more of a work-around than a true solution. I first posted this work-around on the Nevrona newsgroup (Group=nevrona.public.rave.developer.delphi.rave; Subject="Are you suffering from the Rave Endless Loop bug?: Work-around announced."; Date=13/11/2006 7:06 PM)</p>
<p>So here is my solution. It is more of a ... | <p>thank's a lot, this thread helps me out from my problem with endless printing loop in Nevrona Rave...., I set MinHeightLeft to 0,500, this setting is work but i'm not sure that it will work for anothers result set of my query report.</p>
| 9,439 |
<p>What issues / pitfalls must be considered when overriding <code>equals</code> and <code>hashCode</code>?</p>
| <h3>The theory (for the language lawyers and the mathematically inclined):</h3>
<p><code>equals()</code> (<a href="http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#equals(java.lang.Object)" rel="noreferrer">javadoc</a>) must define an equivalence relation (it must be <em>reflexive</em>, <em>symmetric</em... | <p>One gotcha I have found is where two objects contain references to each other (one example being a parent/child relationship with a convenience method on the parent to get all children).<br>
These sorts of things are fairly common when doing Hibernate mappings for example.</p>
<p>If you include both ends of the rel... | 4,721 |
<p>The program that I am currently assigned to has a requirement that I copy the contents of a table to a backup table, prior to the real processing.</p>
<p>During code review, a coworker pointed out that</p>
<pre><code>INSERT INTO BACKUP_TABLE
SELECT *
FROM PRIMARY_TABLE
</code></pre>
<p>is unduly risky, as it is p... | <p>Does the backup table stay around? Does it keep the data permanently, or is it just a copy of the current values?</p>
<p>Too bad about not being able to create/delete/rename/copy. Otherwise, if it's short term, just used in case something goes wrong, then you could drop it at the start of processing and do somethin... | <p>You could try something like:</p>
<pre><code>CREATE TABLE secondary_table AS SELECT * FROM primary_table;
</code></pre>
<p>Not sure if that automatically copies data. If not:</p>
<pre><code>CREATE TABLE secondary_table AS SELECT * FROM primary_table LIMIT 1;
INSERT INTO secondary_table SELECT * FROM primary_table... | 39,340 |
<p>Here's a question to expose my lack of experience: I have a method <strong>DoSomething()</strong> which throws an exception if it doesn't manage to do it cleanly. If it fails, I try the less accurate method <strong>DoSomethingApproximately()</strong> several times in the hope that it will find a sufficiently good so... | <p>You should never use exceptions for control flow of your application.</p>
<p>In your case I'd bunch the three methods together into a single method and have it return which particular approach succeeded, maybe with an enum or something like that.</p>
| <p>Return an error code instead of throwing an exception. </p>
<p>If the ways those methods fail do throw exceptions, catch them all in the same method and take appropriate action, like increasing a counter and returning an error code.</p>
<pre><code> bool result = DoSomething();
while (!result && tries ... | 15,430 |
<p>I have a custom class loader so that a desktop application can dynamically start loading classes from an AppServer I need to talk to. We did this since the amount of jars that are required to do this are ridiculous (if we wanted to ship them). We also have version problems if we don't load the classes dynamically at... | <p>The only way that a Class can be unloaded is if the Classloader used is garbage collected. This means, references to every single class and to the classloader itself need to go the way of the dodo.</p>
<p>One possible solution to your problem is to have a Classloader for every jar file, and a Classloader for each ... | <p>If you're live watching if unloading class worked in <a href="http://docs.oracle.com/javase/7/docs/technotes/guides/management/jconsole.html" rel="nofollow noreferrer">JConsole</a> or something, try also adding <code>java.lang.System.gc()</code> at the end of your class unloading logic. It explicitly triggers Garba... | 17,912 |
<p>I had someting like this in my code (.Net 2.0, MS SQL)</p>
<pre><code>SqlConnection connection = new SqlConnection(@"Data Source=localhost;Initial
Catalog=DataBase;Integrated Security=True");
connection.Open();
SqlCommand cmdInsert = connection.CreateCommand();
SqlTransaction sqlTran = connection.BeginTransa... | <p>Instead of inserting each record individually, Try using the <a href="http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlbulkcopy.aspx" rel="noreferrer">SqlBulkCopy</a> class to bulk insert all the records at once.</p>
<p>Create a DataTable and add all your records to the DataTable, and then use <a hr... | <p>I assume that what is taking the approximately 58 seconds is the physical inserting of 500,000 records - so you are getting around 10,000 inserts a second. Without knowing the specs of your database server machine (I see you are using localhost, so network delays shouldn't be an issue), it is hard to say if this is... | 15,475 |
<p>When working on a project, after the interesting parts are coded, my motivation is severely diminished. What do you do to get over this problem? </p>
| <p>Don't leave all the "boring" bits to the end - make sure that each component works, with regression tests and documentation, as early as possible in the project.</p>
<p>That said, the last few weeks are still going to involve chasing down the really elusive bugs, dealing with last-second requirements changes, final... | <p>I agree it is tough. The only thing that keeps me going is to keep in mind the feeling I would have after seeing it complete / shipped / in the hands of customers.</p>
| 11,765 |
<p>Given the hash of a blob, is there a way to get a list of commits that have this blob in their tree?</p>
| <p>Both of the following scripts take the blob’s SHA1 as the first argument, and after it, optionally, any arguments that <a href="http://git-scm.com/docs/git-log" rel="noreferrer"><code>git log</code></a> will understand. E.g. <code>--all</code> to search in all branches instead of just the current one, or <code>-g</c... | <p>So... I needed to find all files over a given limit in a repo over 8GB in size, with over 108,000 revisions. I adapted Aristotle's perl script along with a ruby script I wrote to reach this complete solution.</p>
<p>First, <code>git gc</code> - do this to ensure all objects are in packfiles - we don't scan objects... | 27,626 |
<p>I would like to create a copy of a database with approximately 40 InnoDB tables and around 1.5GB of data with mysqldump and MySQL 5.1.</p>
<p>What are the best parameters (ie: --single-transaction) that will result in the quickest dump and load of the data?</p>
<p>As well, when loading the data into the second DB,... | <h2>QUICKLY dumping a quiesced database:</h2>
<p>Using the "-T " option with mysqldump results in lots of .sql and .txt files in the specified directory. This is ~50% faster for dumping large tables than a single .sql file with INSERT statements (takes 1/3 less wall-clock time).</p>
<p>Additionally, there is a huge ... | <p>Use mk-parallel-dump tool from Maatkit.</p>
<p>At least that would probably be faster. I'd trust mysqldump more.</p>
<p>How often are you doing this? Is it really an application performance problem? Perhaps you should design a way of doing this which doesn't need to dump the whole data (replication?)</p>
<p>On th... | 15,921 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.