instruction stringlengths 21 27.8k | chosen stringlengths 18 28.2k | rejected stringlengths 18 33.6k | __index_level_0__ int64 0 50k |
|---|---|---|---|
<p>When should I choose one or the other? What are the implications regarding space and (full-text) indexing?</p>
<p>BTW: I'm currently using SQL Server 2005 planing to upgrade to 2008 in the following months.</p>
<p>Thanks</p>
| <p>The new (max) fields make it a lot easier to deal with the data from .NET code. With <code>varbinary(max)</code>, you simply set the value of a <code>SqlParameter</code> to a byte array and you are done. WIth the image field, you need to write a few hundred lines of code to stream the data into and out of the fiel... | <p>Once you put it in the blob, it's going to be difficult to be used for normal SQL comparison. See <a href="http://msdn.microsoft.com/en-us/library/ms178158.aspx" rel="nofollow noreferrer">Using Large-Value Data Types</a>.</p>
| 6,939 |
<p>I asked <a href="https://stackoverflow.com/questions/269417/which-language-should-i-use">a question</a> earlier about which language to use for an AI prototype. The consensus seemed to be that if I want it to be fast, I need to use a language like Java or C++, but that Python / Perl / Ruby would be good for the inte... | <p><a href="http://www.boost.org/doc/libs/1_36_0/libs/python/doc/tutorial/doc/html/index.html" rel="noreferrer">Boost.Python</a> provides an easy way to turn C++ code into Python modules. It's rather mature and works well in my experience. </p>
<p>For example, the inevitable Hello World...</p>
<pre><code>char const* ... | <p>I have a different perspective, having had lots of luck with integrating C++ and Python for some real time live video image processing.</p>
<p>I would say you should match the language to the task for each module. If you're responding to a network, do it in Python, Python can keep up with network traffic just fine... | 34,140 |
<p>I have an array of a few million numbers.</p>
<pre><code>double* const data = new double (3600000);
</code></pre>
<p>I need to iterate through the array and find the range (the largest value in the array minus the smallest value). However, there is a catch. I only want to find the range where the smallest and larg... | <p>The algorithm you describe is really O(N), but i think the constant is too high. Another solution which looks reasonable is to use O(N*log(N)) algorithm the following way:</p>
<pre><code>* create sorted container (std::multiset) of first 1000 numbers
* in loop (j=1, j<(3600000-1000); ++j)
- calculate range
... | <p>Idea of algorithm:</p>
<p>Take the first 1000 values of data and sort them<br>
The last in the sort - the first is range(data + 0, data + 999).<br>
Then remove from the sort pile the first element with the value data[0]<br>
and add the element data[1000]<br>
Now, the last in the sort - the first is range(data + 1, ... | 17,829 |
<p>I just forgot the password. Can anyone help me how to get back the password.</p>
| <p>There is no way to get the old password back. Log into the SQL server management console as a machine or domain admin using integrated authentication, you can then change any password (including sa).</p>
<p>Start the SQL service again and use the new created login (recovery in my example)
Go via the security panel ... | <p>MSSQL have its own database management tool called as "MSSQL Server Management Studio (SSMS)".
Here are steps to reset SA password using SSMS :</p>
<p>1] Open SSMS management console, it will prompt for authentication details,</p>
<p>Select Server Type : "Database Engine",
Server name : IP / hostname of your MSSQL... | 23,834 |
<p>With hot plastic being laid down layer after layer, I am worried about fumes. Should I only print in a well ventilated work space? Should I add additional ventilation?</p>
| <p>The short answer is: <strong>yes, it is always a good idea to print in a well-ventilated area</strong>. The longer answer can be articulated as follows:</p>
<h3>Definition of "fumes"</h3>
<p>"Fumes" is a fuzzy word that from a chemical/physical perspective includes at least three different thing... | <p>There are some contradicting sources out there on whether plastics, especially ABS, have toxic fumes. It is well known that PLA is food safe, as it is an organic, biodegradable polymer being based on a particular cornstarch. This means that PLA <em>is</em> safe when printing, although it can produce foul smells from... | 873 |
<p>I am writing a web application that will run in kiosk mode on a touch screen. I am currently only targeting it for running on Firefox 3. A few of the use cases I have need to visit external sites. I wish to do so with an embedded browser, which I'm tackling with the help of an <code><iframe></code>. I need bac... | <p>Because there is only one history object shared within each tab this seems impossible. The proper way around it would be to test <code>window.history.current</code> or <code>window.history.previous</code> before calling back. Unfortunately, <code>window.history.current</code> is privileged and so not available to un... | <p>You might want to take a look at <a href="http://www.adobe.com/products/air/develop/ajax/" rel="nofollow noreferrer">Adobe AIR</a>. It lets you write your application using all the same tools / languages (ajax, html, etc etc), but since it runs as a desktop app and not in a web browser, you have more control over th... | 30,326 |
<p>I've been working on the Android SDK platform, and it is a little unclear how to save an application's state. So given this minor re-tooling of the 'Hello, Android' example:</p>
<pre class="lang-java prettyprint-override"><code>package com.android.hello;
import android.app.Activity;
import android.os.Bundle;
import... | <p>You need to override <code>onSaveInstanceState(Bundle savedInstanceState)</code> and write the application state values you want to change to the <code>Bundle</code> parameter like this:</p>
<pre><code>@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceSta... | <h2>What to save and what not to?</h2>
<p>Ever wondered why the text in the <code>EditText</code> gets saved automatically while an orientation change? Well, this answer is for you.</p>
<p>When an instance of an Activity gets destroyed and the System recreates a new instance (for example, configuration change). It tr... | 18,292 |
<p>Let's say we have 2 php variables:</p>
<ul>
<li><strong>$name</strong> = 'caption';</li>
<li><strong>$url</strong> = '<a href="http://domain.com/photo.jpg" rel="nofollow noreferrer">http://domain.com/photo.jpg</a>';</li>
</ul>
<p>The input string of <code>'{@url,<img src="," alt="{@name}" />}'</code> should ... | <p>I think you've come across one of those situations where you <em>shouldn't</em> use regex.</p>
<p>much like this one.</p>
<p><a href="https://stackoverflow.com/questions/154708/multi-line-group-and-search-with-regex">Multi-Line group and search with Regex</a>
<a href="https://stackoverflow.com/questions/154708/mul... | <p>It's for a CMS. Admins can add column fields, then add template code for how it will be displayed on the listing page. The {@tags} are used to output the dynamic column values. This template code:</p>
<p><code><p>Link: <a href="{@url}">{@name}</a> - {@date}</p></code></p>
<p>would create a ... | 28,243 |
<p>For enterprise web apps, every little bit counts.</p>
<p>What performance tips can you share to help programmers program more efficiently?</p>
<p>To start it off:</p>
<ol>
<li><p>Use StringBuilders over strings since strings are Mutable (they get re-created every time you modify them).</p></li>
<li><p>Avoid using... | <p>The points made in the question are micro-optimisations. I disagree with the very premise that "every little bit helps" - particularly if it comes at the expense of readability.</p>
<p>You see, if you can read and understand your code really easily, that means you can make architectural changes easily. Those are wh... | <ul>
<li>Make good use of the Cache object for any data that doesn't change very often but gets used alot. If you need to keep your cache objects in line with your database, have a look at SqlCacheDependency.</li>
<li>Disable ViewState wherever it isn't required</li>
</ul>
| 37,166 |
<p>this is my old code</p>
<hr>
<pre><code> protected override bool OnPreAction(string actionName, System.Reflection.MethodInfo methodInfo)
{
if ("|Register|RegisterPage|Login|LoginPage|Logout|Service".ToLower().Contains(actionName.ToLower()))
{
return base.OnPreAction(actionName, m... | <pre><code>string actionName = (string)filterContext.RouteData.Values["action"];
</code></pre>
| <pre><code>string actionName = (string)filterContext.RouteData.Values["action"];
</code></pre>
| 30,543 |
<p>I have a form with a <code><textarea></code> and I want to capture any line breaks in that textarea on the server-side, and replace them with a <code><br/></code>.</p>
<p>Is that possible?</p>
<p>I tried setting <code>white-space:pre</code> on the <code>textarea</code>'s CSS, but it's still not enough.... | <p>Have a look at the <a href="http://ca3.php.net/manual/en/function.nl2br.php" rel="nofollow noreferrer"><code>nl2br()</code></a> function. It should do exactly what you want.</p>
| <p>For those wanting an answer that does not rely on <code>nl2br()</code>:</p>
<pre><code>$newList = ereg_replace( "\n",'|', $_POST['theTextareaContents']);
</code></pre>
<p>or (in this case):</p>
<pre><code>$newList = ereg_replace( "\n",'<br/>', $_POST['theTextareaContents']);
</code></pre>
<hr>
<p>PHP Side... | 36,815 |
<p>How many lines of code can a <code>.java</code> file contain? Does it depend on the JVM being used?</p>
| <p>To extend upon <a href="https://stackoverflow.com/questions/107855/is-there-any-no-of-lines-code-limit-for-a-java-class#107870" title="Jonas' response">Jonas's response</a>, the Java Virtual Machine Specification, <a href="http://docs.oracle.com/javase/specs/jvms/se5.0/html/ClassFile.doc.html#40222" rel="norefer... | <p>I believe there is a 64kb limit on bytecode size per method.</p>
| 13,324 |
<p>Here is a snippet of the file <em>/proc/self/smaps</em>:</p>
<pre><code>00af8000-00b14000 r-xp 00000000 fd:00 16417 /lib/ld-2.8.so
Size: 112 kB
Rss: 88 kB
Pss: 1 kB
Shared_Clean: 88 kB
Shared_Dirty: 0 kB
Private_Clean: 0 kB
Private_Dirt... | <p>The format of smaps is: </p>
<p>[BOTTOM]-[TOP] [PERM] [FILE OFFSET]</p>
<p>b80e9000-b80ea000 rw-p 0001b000 08:05 605294 /lib/ld-2.8.90.so</p>
<p>So there the actual content of the file '/lib/ld-2.8.90.so' at file offset 0x0001b000 is mapped at 0xb80e9000 in that program's memory.</p>
<p>To extract the line n... | <p>You'll need to extract information from Linux's memory handler to determine how the application's virtual memory map relates to the pages given. It gets trickier if you also want to track information in pages that have been swapped out of memory.</p>
<p>You'll find <a href="http://tldp.org/LDP/khg/HyperNews/get/me... | 27,055 |
<p>Given a html document, what is the most correct and concise regular expression pattern to remove the query strings from each url in the document?</p>
| <p>You can't usefully parse HTML with a regexp. If you know the format of the page in advance — eg.</p>
<ul>
<li>links are always in the form < a href="url with no unnecessary character escapes">, or</li>
<li>all links are absolute, and no other non-link strings beginning with http: exist</li>
</ul>
<p>then you ca... | <p>Find this:</p>
<pre><code>/href="([^\?"]*?)\?[^\"]*"/
</code></pre>
<p>Replace with:</p>
<pre><code>href="\1"
</code></pre>
<p>you may have to watch out that it doesn't strip <code><link></code> tags.</p>
| 34,186 |
<p>Part of a new product I have been assigned to work on involves server-side conversion of the 'common' video formats to something that Flash can play.</p>
<p>As far as I know, my only option is to convert to FLV. I have been giving ffmpeg a go around, but I'm finding a few WMV files that come out with garbled sound ... | <p>Flash can play the following formats:</p>
<pre><code>FLV with AAC or MP3 audio, and FLV1 (Sorenson Spark H.263), VP6, or H.264 video.
MP4 with AAC or MP3 audio, and H.264 video (mp4s must be hinted with qt-faststart or mp4box).
</code></pre>
<p>ffmpeg is an overall good conversion utility; mencoder works better wi... | <p>Most encoders, by default (ffmpeg included) put the header atom of the mp4 (the "moov atom") at the end of the video, since they can't place the header until they're done encoding. However, in order for the file to start playback before its done downloading, the moov atom has to be moved to the front.</p>
<p>To do... | 12,327 |
<p>I am creating a C# WinForms application. I would like to have a Custom Form Border. And I want to create a black custom window (with border and controls) like that of Adobe Lightroom. For example -
<a href="https://i.stack.imgur.com/VNDFM.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VNDFM.jpg" ... | <p>If the custom-chrome tools don't provide you with the look-and-feel that you want, this kind of thing is easy to do yourself in C#. Basically, you create a borderless form (FormBorderStyle = None) and then create all the controls and borders yourself, by placing controls where you need them (a label for the title b... | <p>My task was to make active window more noticeable, bright - than others, inactive windows of the app. App has many opened windows, some modal, some modeless - and the MDI parent one.</p>
<p>You can can use something like not-a-border - a frame inside the client area. Here is the code snippet, a part of a base class... | 39,361 |
<p>I was searching here about converting a string like "16:20" to a DateTime type without losing the format, I said I dont want to add dd/MM/yyy or seconds or AM/PM, because db just accept this format.</p>
<p>I tried with Cultures yet</p>
<p>Thanks in Advance</p>
| <p>All DateTime objects must have a date and a time.</p>
<p>If you want just the time, use TimeSpan: </p>
<pre><code>TimeSpan span = TimeSpan.Parse("16:20");
</code></pre>
<p>If you want a DateTime, add that time to the min value:</p>
<pre><code>TimeSpan span = TimeSpan.Parse("16.20");
DateTime dt = DateTime.MinVa... | <p>I want to address this part of your question:</p>
<blockquote>
<p>without losing the format</p>
</blockquote>
<p>A database will generally store all datetime values in a standard common format that's not even human readable. If you use a datetime column the original format is destroyed.</p>
<p>However, when yo... | 47,110 |
<p>I'd like to be able to (effectively) sort a database view - I know that conceptually order in a db view is invalid, but I have the following scenario to deal with:</p>
<ul>
<li>a third-party legacy application, that reads data from database tables using a select(*) from tablename statement</li>
<li>the legacy appli... | <p>First off, I've had to work on this type of project before and it's truly a bitch. My condolences.</p>
<p>This is a little out there, but if your DBMS supports it, perhaps you could create a user defined table function that does an ordered select from your legacy table, then set up your view to select from the UDT... | <p>If I'm understanding this correctly, you could solve this by:<br>
1) Renaming the original table<br>
2) Creating a view with the name of the table that the legacy app queries.<br>
3) Define the view to be a query that orders the records in the way that legacy app expects.</p>
| 20,397 |
<p>Does anyone know a good date parser for different languages/locales. The built-in parser of Java (SimpleDateFormat) is very strict. It should complete missing parts with the current date. </p>
<p>For example </p>
<ul>
<li>if I do not enter the year (only day and month) then the current year should be used. </li>
<... | <p>Check Joda Time, and its Freaky <a href="https://www.joda.org/joda-time/userguide.html#Input_and_Output" rel="nofollow noreferrer">Formatters</a>.</p>
<p><a href="http://www.oracle.com/technetwork/articles/java/jf14-date-time-2125367.html" rel="nofollow noreferrer">Java 8 includes JSR-310</a> so that could be a sol... | <p>I would have to say +1 for JodaTime. In addition to parsing, Joda makes just about every date-related operation better.</p>
| 27,416 |
<p>There is a 3D desktop printer <a href="https://en.wikipedia.org/wiki/RepRap_project">RepRap</a> which can print most of its own components.</p>
<p>Assuming each printed printer will print the next one and so on. Are there any limitation how many times this can be achieved?</p>
<p>For example somebody printed for m... | <p>The files used to print these objects are digital, and do not degrade in any way after each printing. There are no side effects or degradation that occurs over time due simply to printing them multiple times.</p>
<p>This is the RepRap philosophy, and the machines are actually designed with enough tolerance for prin... | <p>As long as you maintain each printer and keep a proper calibration, go for it, this is what they were designed to do, I've even made replacement parts for myself.</p>
<p>Unfortunately the <a href="https://en.wikipedia.org/wiki/RepRap_project#History" rel="nofollow">RepRap project just shut down on 1/15/16</a> due t... | 96 |
<p>I'm trying to setup a bidirectional localConnection (LC) between two flash objects on the same web page. One object is AS2 and the other AS3.</p>
<ol>
<li>I'm using one LC object to send and receive data on each swf. (This shouldn't matter, right? I tried using two objects, one for sending and one for receiving, bu... | <p>One possible cause is that I've noticed that multiple listeners to the same LC name seem not to work. To see what I mean, open <a href="http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_16243" rel="nofollow noreferrer">this page</a> on two different tabs, and you should see that both of the "sending" SWFs... | <p>You don't by chance have two different browsers open to the same page do you? LocalConnection will connect across browsers which may cause that issue.</p>
<p>Usually what I do to ensure the LC names are unique is to generate a random LC name on the server, then pass that LC name to both swfs using FlashVars.</p>
<... | 34,595 |
<p>I want to run a standalone ruby script in which I need my RoR environment to be used. Specifically, I need my models extending ActionMailer and ActiveRecord. I also need to read the database configuration from my database.yml.
How do I go about it?</p>
| <p>The easiest way is to change the shebang of your script from :</p>
<pre><code>#!/usr/bin/ruby
</code></pre>
<p>to</p>
<pre><code>#!/path/to/your/rails/script/runner
</code></pre>
<p>Et voilà, your script will be run with the full rails environment loaded. You can also run your script as <code>./my_script -e prod... | <p>Check out this thread:
<a href="https://stackoverflow.com/questions/293302/how-do-i-run-ruby-tasks-that-use-my-rails-models">How do I run Ruby tasks that use my Rails models?</a></p>
<p>Essentially it boils down to:</p>
<pre><code>require "#{ENV['RAILS_ROOT']}/config/environment.rb"
</code></pre>
<p>Have fun!</p>... | 43,508 |
<p>Why is it that there are two kinds of references in xaml.</p>
<p>One looks like this:</p>
<pre><code>xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
</code></pre>
<p>But mine look like this:</p>
<pre><code>xmlns:WPFToolKit="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit"
</code></pre>
<p>W... | <p>The second instance is basically an unmapped, but explicit reference to a namespace in an assembly. The first instance is a mapped reference to a namespace in some assembly referenced by your project. <a href="http://msdn.microsoft.com/en-us/library/ms747086.aspx" rel="noreferrer">XAML Namespaces and Namespace Mappi... | <p>The schema reference is used for the standard XAML elements, which the compiler knows how to map directly to built-in WPF classes.</p>
<p>The CLR namespace reference is a hint for the compiler which assmebly and namespace to look for when mapping the XML elements in your namespace namespace to your CLR/WPF classes.... | 21,665 |
<p>We are currently creating an InfoPath 2007 form is deployed in SharePoint 2007. In the form we populate the repeating tables with more than 60 records. However, when we're submitting the form, an error message appears. Does the number of records in the repeating table affects the submitting of the form? Also provide... | <p>Your best bet would be to not use Zend_Auth's storage to hold information that's likely to change - by default it only holds the identity (for good reason). I'd probably make a User class that wrapped all the Auth, ACL (and probably profile) functionality that uses a static get_current() method to load the user sta... | <p>I have done it like this, it works, but I don't know if there is not some better way,how to do it </p>
<pre><code>$user_data = User::getUser($user_id)->toArray();
unset($user_data['password']);
$std_user = new stdClass();
foreach ($user_data as $key => $value)
{
$std_user->$key = $value;
}
$auth = Ze... | 39,219 |
<p>The scroll lock button seems to be a reminder of the good old green terminal days. Does anyone still use it? Should the 101 button keyboard become the 100 button keyboard?</p>
| <p>In Excel, if you turn on scroll lock, using the arrow keys scrolls the spread sheet instead of changing the cell the cursor is in.</p>
| <p>I use it all the time, with the purpose for which it was made. For a variety of things.</p>
| 17,177 |
<p>I get DNS records from a Python program, using <a href="http://www.dnspython.org/" rel="nofollow noreferrer">DNS
Python</a></p>
<p>I can get various DNSSEC-related records:</p>
<pre><code>>>> import dns.resolver
>>> myresolver = dns.resolver.Resolver()
>>> myresolver.use_edns(1, 0, 1400)... | <p>You probably mean RRSIG ANY (otherwise, the order is wrong, the class needs to be after the type)</p>
<pre><code>>>> print myresolver.query('sources.org', 'RRSIG', 'ANY')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.5/site-packages/dns/resolv... | <p>If you try this, what happens?</p>
<pre><code>print myresolver.query('sources.org', 'ANY', 'RRSIG')
</code></pre>
| 10,829 |
<p>On a Creality CR-10 Max, there is a bag of unidentified spares, which include three unmarked nozzles.</p>
<p>There is a needle that is exactly 0.4 mm in diameter, which needle fits exactly inside one of nozzles. It also fits loosely in the largest nozzle, which diameter looks like it's really close to 0.8 mm on my d... | <p>I've designed similar sensor casings, sometimes the filament catches a ridge/ledge or part of the cavity, even when it is chamfered or rounded. The arm of the limit switch pushes the filament up, away from the filament straight path.</p>
<p>Have you tried cutting the filament under a very sharp angle, that may work.... | <p>Here is 3D model that better explains why it was catching and how to remedy the problem:</p>
<p><a href="https://i.stack.imgur.com/ooe48.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ooe48.png" alt="enter image description here" /></a></p>
<p><a href="https://i.stack.imgur.com/dTy92.png" rel="no... | 1,706 |
<p>Suppose you need to run a program on the world’s fastest supercomputer which will take 10 years to complete. You could:</p>
<ul>
<li>Spend $250M now</li>
<li>Program for 9 years, <a href="http://en.wikipedia.org/wiki/Moore%27s_Law" rel="nofollow noreferrer">Moore’s law</a> speedup (4,000x faster), spend $1M in 10ye... | <p><a href="http://en.wikipedia.org/wiki/Moore%27s_law" rel="nofollow noreferrer">Moore's Law</a> is not about speed, it's about the number of transistors in a given area of silicon. There is no guarantee that in 9 years the speed will increase 4000x. If anything, GHz speed has levelled off in recent years. What is inc... | <p>But Moore's law does not speed up programming. </p>
<p>9 years of programming will never be condensed into 2 weeks.</p>
<p>Unless you successfully spend the 9 years programming an automated thought reading machine I suppose.</p>
| 46,444 |
<p>I found several controlsets for that nice looking ribbons (DotNetBar, DivElements, ...), but all require a license for at least 100 USD. Is there a free controlset that looks quite as nice as the commericial ones?</p>
| <p>You can download the Microsoft WPF Ribbon Control through the Office Developer UI Licence.</p>
<p>It was meant to be released last week.</p>
<p><a href="http://windowsclient.net/wpf/wpf35/wpf-35sp1-ribbon-walkthrough.aspx" rel="nofollow noreferrer">http://windowsclient.net/wpf/wpf35/wpf-35sp1-ribbon-walkthrough.as... | <p>Might want to take a look at <a href="http://arstechnica.com/journals/linux.ars/2007/08/30/mono-developer-brings-the-ribbon-interface-to-linux" rel="nofollow noreferrer">http://arstechnica.com/journals/linux.ars/2007/08/30/mono-developer-brings-the-ribbon-interface-to-linux</a></p>
<p>It's for mono, but might be wo... | 32,509 |
<p>I need to cleanup the HTML of pasted text into TinyMCE by passing it to a webservice and then getting it back into the textarea.
So I need to override the Ctrl+V in TinyMCE to caputre the text, do a background request, and on return continue with whatever the paste handler was for TinyMCE.
First off, where is TinyMC... | <p>You could write a plug-in that handles the ctrl+v event and passes it through or modify the paste plug-in. The following code is found at <a href="http://source.ibiblio.org/trac/lyceum/browser/vendor/wordpress/trunk/wp-includes/js/tinymce/plugins/paste/editor_plugin.js?rev=1241" rel="nofollow noreferrer">plugins/pas... | <p>Tiny Editor has a plugin called "paste".</p>
<p>When using it, you can define two functions in the init-section</p>
<pre><code>/**
* This option enables you to modify the pasted content BEFORE it gets
* inserted into the editor.
*/
paste_preprocess : function(plugin, args)
{
//Replace empty styles
args... | 14,571 |
<p>I've having trouble directly accessing the <strong>Win32_OperatingSystem</strong> management class that is exposed via WMI.</p>
<p>It is a singleton class, and I'm pretty certain "Win32_OperatingSystem=@" is the correct path syntax to get the instance of a singleton.</p>
<p>The call to InvokeMethod produces the ex... | <p>Win32_OperatingSystem is not a singleton class - if you check its qualifiers, you'll see that there is no Singleton qualifier defined for it, so you'll have to use ManagementObjectSearcher.Get() or ManagementClass.GetInstances() even though there is only one instance of the class. Win32_OperatingSystem key property ... | <p>I'm not 100% sure of the answer, but have you tried using reflector to look at what ManagementObjectSearcher does? It may give you some clue as to what you are doing wrong.</p>
| 8,008 |
<p><a href="http://macromates.com/" rel="nofollow noreferrer">TextMate</a> may be the best editor out there, but is has a big disadvantage: it undoes each character typed instead of grouping characters. This makes a large undo tedious!</p>
<p>Do you now any hacks, plugins or workarounds to fix this issue?</p>
| <p>I know the developer's been promising a fix for years now, and it's something the user community complains about a lot. But I don't think I've seen anything more useful than "hold down Cmd-Z to repeat".</p>
| <p>This is not exactly what you're asking for but more a work around because as dnord said, this is a fundamental issue with TextMate and won't be fixed until Allen Odegard decides to fix it.</p>
<p>Have you considered trying one of the clipboard managers out there? At least that way you can clip chunks of text and 'u... | 30,751 |
<p>If I drag and drop a selection of a webpage from Firefox to HTML-Kit, HTML-Kit asks me whether I want to paste as text or HTML. If I select "text," I get this:</p>
<pre><code>Version:0.9
StartHTML:00000147
EndHTML:00000516
StartFragment:00000181
EndFragment:00000480
SourceURL:http://en.wikipedia.org/wiki/Herodotus
... | <p>For completeness, here is the P/Invoke Win32 API code to get RAW clipboard data</p>
<pre><code>using System;
using System.Runtime.InteropServices;
using System.Text;
//--------------------------------------------------------------------------------
http://metadataconsulting.blogspot.com/2019/06/How-to-get-HTML-fro... | <p>It is Microsoft specific, don't expect to see the same information in other OSes.<br>
Note that you get the same format when you copy a fragment from IE.</p>
<p>I am not sure what you mean by "webpage-to-webpage drag and drop operation". To drop where? A textarea?</p>
<p>I don't know C#, but in C/C++ applications,... | 17,118 |
<p>Our application is an Xbap running in full trust. I have a function similar to this:</p>
<pre><code>private void ShowPage(Page page)
{
NavigationWindow mainWindow = Application.Current.MainWindow as NavigationWindow;
mainWindow.Navigate(page);
}
</code></pre>
<p>This works great for browsing inside an ex... | <p>Apparently WPF is a little new for StackOverflow. Here is the function I came up with in case anyone else stumbles across this.</p>
<pre><code>private void ShowPage(Page page)
{
NavigationWindow popup = new NavigationWindow();
popup.Height = 400;
popup.Width = 600;
popup.Show();
popup.Navigate... | <p>You are correct that this would only work in Full Trust. You cannot create a popup in partial trust.</p>
| 39,013 |
<p>I am facing this peculiar problem. My webapp, works fine on my localhost. Its a JSP/Struts-Tomcat-MySQL app. However, when I host it on hostjava.net (shared tomcat), it is unable to connect to the database.</p>
<p>After some debugging, I have identified the problem, to be with JNDI lookup for datasource. If you wan... | <p>Shouldn't this:</p>
<pre><code>url="jdbc:mysql://localhost/[db name]?autoReconnect=true"
</code></pre>
<p>really point at the name of the server on which the database is hosted? On th remote host the database server may not be the same machine as the tomcat instance. I would think that you have to say </p>
<p>url... | <p>"java.lang.NullPointerException
at com.DAO.UserDAO.userLogin(UserDAO.java:109)
at com.Actions.UserAction.execute(UserAction.java:66)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(Re... | 29,209 |
<p>This is an interesting conundrum.</p>
<p>We have a WPF app that has a Vista-like theme using soft pastels, Aero control templates, etc. What we've noticed is that this UI appears incredibly washed out on low quality LCDs. Is there a way to boost color saturation application-wide or are we at the mercy of bad monito... | <p>You chose a bad palette.</p>
<p>Do some work on the UI; introduce more natural contrast.</p>
<p>You wouldn't want to add programming to work around the bad palette choice, even if you could. </p>
<p>Just change the colors. </p>
| <p>A wild idea would be to implement a saturation shader and set it on the window :)
that way the user can control the saturation by himself!</p>
<p>but..like i said... a wild idea, probably not a good one!</p>
| 15,028 |
<p>I have a server written in Java that runs as a Windows service (thanks to Install4J). I want this service to be able to download the latest version of the JAR file it runs from, and start running the new code. The stitch is that I don't want the Windows service to fully exit.</p>
<p>Ideally, I would accomplish th... | <p>Here is a complicated, but portable, way.</p>
<p>Split your code into two jars. One very small jar is there just to manage process startup. It creates a ClassLoader that holds the other jar on its classpath.</p>
<p>When you want to load a new version, you terminate all threads running code from the old jar. Nul... | <p>General approach:</p>
<pre><code>import java.io.BufferedInputStream;
import java.util.Arrays;
public class ProcessSpawner {
public static void main(String[] args) {
//You can change env variables and working directory, and
//have better control over arguments.
//See [ProcessBuilder javadocs][1]
... | 24,127 |
<p>Let's say I've got a setup that look something like</p>
<pre><code>phd/code/
phd/figures/
phd/thesis/
</code></pre>
<p>For historical reasons, these all have their own git repositories. But I'd like to combine them into a single one to simplify things a little. For example, right now I might make two sets of chang... | <p>Here's a solution I gave <a href="https://stackoverflow.com/questions/614229/can-i-move-the-git-directory-for-a-repo-to-its-parent-directory/614254">here</a>:</p>
<ol>
<li><p>First do a complete backup of your phd directory: I don't want to be held responsible for your losing years of hard work! ;-)</p>
<pre><cod... | <p>I'll throw my solution in here too. It's basically a fairly simple bash script wrapper around <code>git filter-branch</code>. Like other solutions it only migrates master branches and doesn't migrate tags. But the full master commit histories are migrated and it is a short bash script so it should be relatively easy... | 34,950 |
<p>In Ruby on Rails, how to add foreign key constraint in migration?</p>
| <p>Here's a gem-based solution that includes support for adding and removing foreign key constraints, doesn't fail with sqlite, and works correctly with schema.rb files:</p>
<p><a href="http://github.com/matthuhiggins/foreigner" rel="noreferrer">http://github.com/matthuhiggins/foreigner</a></p>
| <p>Would it be enough with adding the following, for example with <code>Products</code> and <code>User</code> models?</p>
<p><code>add_index :products, :user_id</code></p>
| 41,414 |
<p>What are some of the ways? What frameworks can you use?</p>
| <p>Here's a project which does this: <a href="http://tsqlunit.sourceforge.net/" rel="nofollow noreferrer">http://tsqlunit.sourceforge.net/</a></p>
<p>Also, Visual Studio Team System for DBA has built-in support for unit testing of Databases.</p>
| <p><a href="http://tst.codeplex.com/" rel="nofollow noreferrer">T.S.T. the T-SQL Test Tool</a></p>
<blockquote>
<p>TST is a tool that simplifies the task
of writing and running test automation
for code written in T-SQL. At the
heart of the TST tool is the TST
database. This database contains a
series of st... | 7,702 |
<p>I'm working with <a href="http://pear.php.net/package/Log" rel="nofollow noreferrer">logging in PHP with Pear</a>, and I get into a standard problem: can I use file-based logging when the DB is not available? I don't mind if it's slow due to concurrency issues, but it cannot fail to work due to multiple, simultaneou... | <p>Generally, logging to the file system is a good fall back if you can't connect to your database. Simultaneous hits shouldn't be a problem (locks...). If you already have your logs adapted for a database perhaps the easiest way to go would be to use sqlite as a fall back.</p>
<p>Another way would be to email log eve... | <p>You can pass an existing database object into the <a href="http://www.csh.rit.edu/~jon/projects/pear/Log/guide.html#the-sql-db-handler" rel="nofollow noreferrer">singleton method of Log</a> - if you don't have a database you can revert to alternative logging methods (or good old user_error())</p>
<pre><code>require... | 25,250 |
<p>I am thinking to use closed-loop stepper motors to prevent step loss and make the machine more accurate. What options (preferably low cost) are there for:</p>
<p><code>stepper motor + driver + encoder + microcontoller</code></p>
<p>Is building it from scratch worth it? E.g. Arduino Mega 2560 + RAMPS 1.4/1.5/1.6 + ... | <p>A number of options exist, but keep in mind that cost will be a limiting factor.</p>
<p><em>(Small sidenote: cost depends on persective, financial cost does not equal mental cost. The tradeoff between buy or make depends also on your willingness to persist when things don't work right away.)</em></p>
<p><strong>Be... | <p>So, I am one of those who has implemented this on my big scale heavily modified cr-10 S5. </p>
<p>Why?</p>
<p>Well with bigger prints, the risk of crashing into itself because of a small blob is very real. Possibly ruining a 100$ worth of filament and missing deadlines. (We are using this professionally.) Blobs wi... | 1,598 |
<p>I've a dialog which contains a Qt TabWidget with a number of tabs added. </p>
<p>I'd like to hide one of the tabs. </p>
<pre><code>_mytab->hide()
</code></pre>
<p>doesn't work. I don't want to just delete the tab and all its widgets from the .ui file because other code relies on the widgets within the tab. ... | <p>I would use QTabDialog::removePage(QWidget* pTabPage) which does not delete pTabPage, which is what you want.</p>
<pre><code>_myTabDlg->removePage(_mytab);
</code></pre>
<p>I'm using it and it works fine !</p>
| <p>I had encountered the same problem. I am using the following approach.</p>
<p>Now here is the data.</p>
<blockquote>
<p>genTab is the name of my QTabWidget</p>
<p>tabX is the name of the tab that i want to remove.</p>
</blockquote>
<p>(Note that this is the second tab in the Tab Widget. Hence, i will be using "... | 25,485 |
<p>I want a simple tutorial to show me how to load a yaml file and parse the data. Expat style would be great but any solution that actually shows me the data in some form would be useful.</p>
<p>So far I ran multiple tests in the <code>yaml-0.1.1</code> source code for C and I either get an error, no output whatsoever... | <p>Try <a href="https://github.com/jbeder/yaml-cpp" rel="noreferrer">yaml-cpp</a> (as suggested by <a href="https://stackoverflow.com/questions/244784/yaml-serialization-library-for-c">this question</a>) for a C++ parser.</p>
<p>Disclosure: I'm the author.</p>
<p>Example syntax (from the <a href="https://github.com/j... | <p>A Google Code Search (now defunct) for "yaml load lang:c++" gave this as the first link: <a href="https://github.com/wilhelmtell/libyamlpp/blob/master/demo/begin/demo.cc" rel="nofollow noreferrer">demo.cc</a>:</p>
<pre><code>#include <iyaml++.hh>
#include <tr1/memory>
#include <iostream>
#include ... | 47,671 |
<p>I know there are things like doing manual check to make sure the codes committed is fundamentally correct. But beside that? Reason i asking is because a big project there are so many commits everyday.</p>
| <p>Generally speaking commit notifications are useful so that you have some idea what's happening in the code on a daily basis. For example, I know when a new feature has been implemented, or a bug fix is checked in. If there's so many commits that this gets lost in the noise then it might be worth filtering or reducin... | <p>I find it primarily useful for tracking. In general such automatic notifications get filtered off into a bucket in my mailer, along with the "smoketest passed, smoketest failed" type email...then when there is a failure, you can track it back to the set of checkins fairly straightforwardly.</p>
<p>Note that one ca... | 23,022 |
<p>I'm currently getting through the <a href="http://www.cplusplus.com" rel="nofollow noreferrer">http://www.cplusplus.com</a> tutorial and I came across this section here: <a href="http://www.cplusplus.com/doc/tutorial/inheritance.html" rel="nofollow noreferrer">http://www.cplusplus.com/doc/tutorial/inheritance.html</... | <p>There are some really good rules of thumb for this in Marshall Cline's <a href="http://yosefk.com/c++fqa/friend.html" rel="nofollow noreferrer">C++ FAQ Lite</a>.</p>
<p>The whole thing is good but see, in particular, <a href="http://yosefk.com/c++fqa/friend.html#fqa-14.2" rel="nofollow noreferrer">"Do friends viola... | <p>As friends generally violate the data-hiding mechanisms, they have to be used only when really needed. If your design relies heavily on friends, it's probably wrong in some way.</p>
<p>An example of when you can't do without friends is overriding the << and >> stream operators. Also, friend classes are often ... | 47,931 |
<p>Most 3 mm (mostly are actually 2.85 mm) filament extruders have some kind of gear reduction. Many 1.75 mm extruders are direct-drive / ungeared but some do use gears. What kind of reduction ratios are suitable or optimal?</p>
| <p>I'm not sure if it's possible, but on github is code for setting CuraEngine up. Maybe you'll find this link, <a href="https://github.com/Ultimaker/CuraEngine/blob/master/src/settings/settings.cpp" rel="nofollow noreferrer"> CuraEngine/src/settings/settings.cpp</a> helpful. </p>
<p>The latest release has more speed ... | <p>I'm not sure if it's possible, but on github is code for setting CuraEngine up. Maybe you'll find this link, <a href="https://github.com/Ultimaker/CuraEngine/blob/master/src/settings/settings.cpp" rel="nofollow noreferrer"> CuraEngine/src/settings/settings.cpp</a> helpful. </p>
<p>The latest release has more speed ... | 214 |
<p>I'm having a problem with a administrative app I'm working on. I'm build an interface for stopping, starting and querying various services across 40 or so servers. </p>
<p>I'm looking at service.controller and have been successful in stopping and starting various services with button events but now I'm trying to ... | <p>You can trigger the periodic service check by using a Timer object. You can run your service queries on the Elapsed event.</p>
<pre><code> private void t_Elapsed(object sender, ElapsedEventArgs e)
{
// Check service statuses
}
</code></pre>
<p>As for displaying statuses in a text box, you should... | <p>Maybe you don't want to poll:</p>
<pre><code>Private serviceController As ServiceController = Nothing
Private serviceControllerStatusRunning = False
Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Try
serviceController = New ServiceController("NameOfTheTheServiceYouWant... | 37,078 |
<p>I've got a Fitnesse RowFixture that returns a list of business objects. The object has a field which is a float representing a percentage between 0 and 1. The <em>consumer</em> of the business object will be a web page or report that comes from a designer, so the formatting of the percentage will be up to the desi... | <p>You certainly don't want to modify your Business Logic just to make your tests look better. Good news however, there is a way to accomplish this that is not difficult, but not as easy as passing in a format specifier.</p>
<p>Try to think of your Fit Fixture as a service boundary between FitNesse and your applicatio... | <p>I'm not sure what the "polution" is. Either the requirement is that your Business Object returns a value expressed as a percentage, in which case your business object should offer that -OR- you are testing the true value of the response as float, which you have now. </p>
<p>Trying to get fitnesse to massage the v... | 12,759 |
<p>Perforce allows people to check in unchanged files. Why any version control system would allow this is beyond me, but that's a topic for another question. I want to create a trigger that will deny the submission of unchanged files. However, I have no experience with Perforce triggers. From what I've read, I'm gue... | <p>In recent version of perforce allow a client setting which prevents submitting unchanged files:</p>
<pre><code> SubmitOptions: Flags to change submit behaviour.
submitunchanged All open files are submitted
submitunchanged+reopen (default).
revertunchanged ... | <p>The script below is done in Linux using a perl script. I'm sure you can adapt it as necessary in Windows and using a scripting language other than Perl.</p>
<p>As the admin user, type
<code>p4 triggers</code>. </p>
<p>Add this under the <code>Triggers:</code> line of your script.</p>
<p><code>Trigger_name chan... | 19,610 |
<p>The only documentation I've found for the components of the Castle project I've found <a href="http://www.castleproject.org/container/documentation/v1rc3/index.html" rel="nofollow noreferrer">here</a> in the form of online HTML files. Does anyone know of anything that is more off-line friendly or printable (e.g. PD... | <p>Decker, I've wondered about the same thing (not only for Castle Windsor) for many Web based resources. Offline usage. I wonder whether there's a tool that could create Web Arcive files (MHT) files by crawling the links on a web page. I'm sure there must be one in the wild... </p>
<p>Update:</p>
<p>I <a href="ht... | <p>You can create a mirror of that site for offline browsing using Wget.</p>
<p><a href="http://wget.addictivecode.org/FrequentlyAskedQuestions" rel="nofollow noreferrer">http://wget.addictivecode.org/FrequentlyAskedQuestions</a></p>
| 49,271 |
<p>In the database I have a field named 'body' that has an XML in it. The
method I created in the model looks like this:</p>
<pre><code>def self.get_personal_data_module(person_id)
person_module = find_by_person_id(person_id)
item_module = Hpricot(person_module.body)
personal_info = Array.new
pers... | <p>This is relatively simple; you're getting an Array because the code is building one. If you wanted to return an object, you'd do something like this:</p>
<pre><code>class PersonalData
attr_accessor :studies
attr_accessor :birth_place
attr_accessor :marital_status
def initialize(studies,birth_place,marital_... | <p>on a slightly different tack.</p>
<p>The idea of using a class method to do this feels wrong from an OO point of view.</p>
<p>You should really refactor this so that it works from an instance method. </p>
<pre>
def personal_data_module
item_module = Hpricot(body)
{
:studies => (item_module/"studi... | 18,141 |
<p>There is filament residue on my glass bed that is so thin that it wont come off. I have had residue buildup for over a year now and none of it has come off. This residue appears with both the PETG and the PLA filament I have. Is there anyway to remove this residue?</p>
<p><a href="https://i.stack.imgur.com/DmG4e.png... | <p>I would try a single edge razor blade at a low angle used as a scraper. If you can't feel the blade catching in the residue, it probably isn't an issue.</p>
<p>If you must get rid of it you don't have good choices of solvents. Maybe you can burn it off by placing the class in an oven through a clean cycle. With ... | <p>Maybe you could put your bed at the max temperature and print a large square of 1 mm onto it using a higher than normal temperature for that filament, maybe this bonds the residue to the new print. Let it cool down and pry the print off or remove while hot.</p>
| 1,763 |
<p>I feel like I'm re-inventing the wheel here, but I need to find a way of taking a URL from a catchall,and redirecting that to another route.</p>
<p>The reason for this is because I need to do some things like adding session cookies for certain urls, and then pass them on to their relevant action.</p>
<p>What's the... | <p>You can try changing the master page at runtime. It's not the most beautiful solution though.</p>
<p><a href="http://frugalcoder.us/post/2008/11/ASPNet-MVC-Theming.aspx" rel="nofollow noreferrer">Theming Support</a></p>
| <p>If I understand question...</p>
<p>Looking at your previous question (<a href="https://stackoverflow.com/questions/237440/redirect-to-controller-but-with-a-different-master-using-a-catchall-wildcard">redirect-to-controller-but-with-a-different-master-using-a-catchall-wildcard</a>) you want to take the wildcard from... | 37,051 |
<p>I would like users to submit a URL that is valid but also is an image, ending with .jpg, .png, or .gif.</p>
| <pre>(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*\.(?:jpg|gif|png))(?:\?([^#]*))?(?:#(.*))?</pre>
<p>That's a (slightly modified) version of the official URI parsing regexp from <a href="http://www.ietf.org/rfc/rfc2396.txt" rel="noreferrer">RFC 2396</a>. It allows for <code>#fragments</code> and <code>?querystrings</code> ... | <pre><code>^((http(s?)\:\/\/|~/|/)?([\w]+:\w+@)?([a-zA-Z]{1}([\w\-]+\.)+([\w]{2,5}))(:[\d]{1,5})?((/?\w+/)+|/?)(\w+\.(jpg|png|gif))
</code></pre>
| 20,478 |
<p>Im just writing a small Ajax framework for re-usability in small projects and i've hit a problem. Basically i get a '<code>NS_ERROR_ILLEGAL_VALUE</code>' error while sending the request and i've no idea what is happening.</p>
<p>The HTML Page
(trimmed but shows the error)</p>
<pre><code><!DOCTYPE html PUBLIC "-... | <p>The exception "Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE)" is caused by an illegal value being passed into the call of open method.</p>
<p>Looking through your code I found misspelling:</p>
<pre>
this.RequestedMethod = p_RequestMethod;
this.DestinationURL = p_DestinationURL;
this.XMLHttp... | <p>This error message is one of the 'quirks' of FireFox's XMLHttpRequest object. The same issue in IE will have different symptoms.</p>
<p>You don't want to deal with all these quirks yourself now that there's lots of good libraries out there. </p>
<p>For instance in Netscape and FX calling <code>XMLHttpRequestObjec... | 24,850 |
<p>in the <code>System.Linq</code> namespace, we can now extend our <a href="https://learn.microsoft.com/en-us/dotnet/api/system.collections.ienumerable?view=netframework-3.5" rel="noreferrer">IEnumerable's</a> to have the <a href="https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.any?view=netframewor... | <p>If you are starting with something that has a <code>.Length</code> or <code>.Count</code> (such as <code>ICollection<T></code>, <code>IList<T></code>, <code>List<T></code>, etc) - then this will be the fastest option, since it doesn't need to go through the <code>GetEnumerator()</code>/<code>MoveNe... | <p>I have created a sample application using IList with 100 elements to 1 millions items to see Count vs Any which is best.</p>
<p><strong>Code</strong></p>
<pre><code>class Program
{
static void Main()
{
//Creating List of customers
IList<Customer> customers = new List<Customer>();... | 39,234 |
<p>When I create utility classes I typically create a class that has a private constructor and exposes all of it's methods and properties as static. What's the best approach for this? What's the difference between the way I do or creating a static class?</p>
| <p>Static classes are automatically sealed, so people can't inherit and override their behavior.</p>
<p>That is the only real difference (unless there is something special in the IL)</p>
<p>So if you use a static class, you save yourself the trouble of making the constructor private, and declaring the class sealed.</... | <p>Also I'm going to go with the private constructor never being called by the static methods. So any initialisation in there would be wasted... But that's just a theory.</p>
| 41,804 |
<p>I want to create a library with a modified version of printf and then call LD_PRELOAD so when my program calls printf it uses my version. Can someone explain to me how to use LD_PRELOAD and if there is a something special I need to do in my code or my library? </p>
| <p>You just set the environment variable <code>LD_PRELOAD</code> to the full path to the replacement library. Since all programs you launch after that point will attempt to use this library, you may want to make a wrapper script that sets <code>LD_PRELOAD</code> then calls the program you want to run.</p>
| <p>That seems like a bad idea. Why not name your version of <code>printf</code> something else?</p>
| 34,415 |
<p>I just started using GNU Emacs as my text editor and I am concerned about getting afflicted with "<a href="http://en.wikipedia.org/wiki/Emacs#Emacs_pinky" rel="nofollow noreferrer">Emacs Pinky</a>" by having to constantly press the control key with my pinky finger as is required when using Emacs. How can I avoid pot... | <p>Making <KBD>caps lock</KBD> another control key is a good place to start. Invest in an ergonomic keyboard. Some emacs users even go as far as to get foot pedal things for control and meta...</p>
| <p>
Just to overcome this issue I remap all the copy,paste,save...etc into numpad.For further ease I bought a separate numpad and place it behind my laptop key board.</p>
<p><img src="https://i.stack.imgur.com/zBQUO.jpg" /></p>
<p>
You can easily remap the keys using AHK(auto hot key).I am using the following key map... | 7,574 |
<p>Attempting to write a definition of DPI has lead me to:</p>
<p>DPI (dots), PPI (points), LPI (lines) all refer to the same concept hereafter referred to as DPI.</p>
<p>DPI is a device dependent measurement. It says, "This is the resolution of this device."</p>
<p>Vector based files are not tied to any one DPI (t... | <p>Because a bitmapped image has no physical size, it has no dpi. If you have a file format where physical size is modeled, you can have a (modeled) dpi.</p>
<p>You might want to make a distinction between addressability and covered area. If a dot is not square but a circle, the covered area is larger.</p>
<p>b.t.w. ... | <p>Certain file formats will contain a DPI value, but it can be ignored for most purposes. What you care about is the ratio of the size in pixels over the size you're displaying or printing. Lower levels generally result in a blurrier picture.</p>
| 35,789 |
<p>How do I call the correct overloaded function given a reference to an object based on the actual type of the object. For example...</p>
<pre><code>class Test
{
object o1 = new object();
object o2 = new string("ABCD");
MyToString(o1);
MyToString(o2);//I want this to call the second overloaded functio... | <p>Ok as soon as I hit post I remembered this can indeed be done using reflection...</p>
<pre><code>var methInfo = typeof(Test).GetMethod("MyToString", new Type[] {o.GetType()});
methInfo.Invoke(this, new object[] {o});
</code></pre>
| <p>Why not have a toString() function in the actual object itself? That way you can call myObj.toString() and the relative output is given. Then you don't have to do any comparisons.</p>
| 42,851 |
<p>C++ seems to be rather grouchy when declaring templates across multiple files. More specifically, when working with templated classes, the linker expect all method definitions for the class in a single compiler object file. When you take into account headers, other declarations, inheritance, etc., things get really ... | <blockquote>
<p>Are there any general advice or workarounds for organizing or redistributing templated member definitions across multiple files?</p>
</blockquote>
<p>Yes; don't.</p>
<p>The C++ spec permits a compiler to be able to "see" the entire template (declaration <em>and</em> definition) at the point of insta... | <p>When/if your compiler supports C++0x, the <code>extern</code> keyword can be used to separate template declarations from definitions.</p>
<p>See <a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Extern_template" rel="nofollow noreferrer">here</a> for a brief explanation.</p>
<p>Also, section 6.3, "The Separation Mod... | 5,666 |
<p>I am wondering what is the best way to construct a common utilities library that can be used in different projects. I am using .Net and C#.</p>
<p>Should I create a separate project for each utility such as Logging, Authentication, Excel etc. and release them separately along with dependencies or should i include a... | <p>I would probably figure out what functionality you want to provide (at least generally) and then define a logical namespace hierarchy around that. Once you've got the overarching definition, you should be able to create all of the library files and structure the modularity of it so you don't have one behemoth "ever... | <p>I've found a great way of sharing common source code and utilities between my projects! In each new project I create a "Junction Point"-folder pointing to the same repository of common source files. Then in the project-tree in Visual Studio I select "Show All Files" and "Include" on the files I need. This works real... | 21,284 |
<p>I have a interest in a <a href="http://support.microsoft.com/kb/941132/en-us" rel="nofollow noreferrer">reported bug</a> which Microsoft have made available a hotfix for. When looking on the site, I'm not able to figure out if this fix is included in a service pack or not. Do anyone know where I can find this out?</... | <p>You didn't mention your product but:</p>
<p>List of fixes in Service Pack 1 for XP: <a href="http://support.microsoft.com/kb/324720" rel="nofollow noreferrer">http://support.microsoft.com/kb/324720</a></p>
<p>List of fixes in Service Pack 2 for XP: <a href="http://support.microsoft.com/kb/811113" rel="nofollow nor... | <p>For security-related patches, try MBSA: <a href="http://technet.microsoft.com/en-us/security/cc184924.aspx" rel="nofollow noreferrer">http://technet.microsoft.com/en-us/security/cc184924.aspx</a></p>
<p>Also try running a WMI query against installed hotfixes. I believe that Service Packs register bundled hotfixes.<... | 17,877 |
<p>I have a C# collection of strings. Each string is a sentence that can appear on a page. I also have a collection of page breaks which is a collection of int's. representing the index where the collection of strings are split to a new page.</p>
<p>Example: Each 10 items in the string collection is a page so the coll... | <p>"Pure" Linq isn't a good fit for this problem. The best fit is to rely on the methods and properties of List(T). There aren't -that- many special cases.</p>
<pre><code>//pageNum is zero-based.
List<string> GetPage(List<string> docList, List<int> pageBreaks, int pageNum)
{
// 0 page case
if ... | <p>Not sure what the list of page breaks is for. I would think of it this way. A collection of strings, a page number, and the size of the page. Then you could do something like:</p>
<pre><code>List<string> strings = ...
int pageNum = ...
int pageSze = ...
if (pageNum < 1) pageNum = 1;
if (pageSize < 1... | 29,472 |
<p>I'm trying to bring a legacy C# .NET 1.1 application into the modern era. We use DataTables for our collections of what could have been business objects.</p>
<p>Given that most of the code thinks it is talking to the interface of a DataRow, what generic collection would make for the least painful transition?</p>
| <p>if im reading your question rightly, you are asking for which container will just store a list of your Business objects and then allow you to just enumerate through the collection, or select via an index.</p>
<p>well I would consider looking into the List<></p>
<p>where you methods would accept either IList<... | <p>Instead of changing away from the DataSet/DataTable APIs, why not subclass DataTable and DataRow into types suitable for your business logic?</p>
<p>The support for subclassed DataRow and DataTable objects is superb. You'll get the strong typing you want in your new code, along with the backwards compatiblity for y... | 49,806 |
<p>I wonder what options there are for .NET (or C# specifically) code coverage, especially in the lower priced segment?</p>
<p>I am not looking for recommendations, but for a comparison of products based on facts. I know the following:</p>
<ul>
<li><a href="http://www.ncover.com/" rel="nofollow noreferrer">NCover</a>... | <p>I use the version of NCover that comes with <a href="http://www.testdriven.net" rel="nofollow noreferrer">TestDriven.NET</a>. It will allow you to easily right-click on your unit test class library, and hit <em>Test With→Coverage</em>, and it will pull up the report.</p>
| <p>Code coverage features, as well as programmable API's, come with Visual Studio 2010. Sadly, the only two editions that include the full Code Coverage capabilities are Premium and Ultimate. However, I do believe the API's will be available with any edition, so creating code coverage files and writing a viewer for the... | 34,917 |
<p>Let's say you have a typical web app and with a file configuration.whatever. Every developer working on the project will have one version for their dev boxes, there will be a dev, prod and stage versions. How do you deal with this in source control? Not check in this file at all, check it with different names or do ... | <p>What I've done in the past is to have a default config file which is checked in to source control. Then, each developer has their own override config file which is excluded from source control. The app first loads the default, and then if the override file is present, loads that and uses any settings from the overri... | <p>We just keep the production config file checked in. It's the developer's responsibility to change the file when they pull it out of source safe for staging or development. This has burnt us in the past so I wouldn't suggest it.</p>
| 2,787 |
<p>I'm digging into Reflection for the first time and I'm truely stuck. I've googled everything I can think of. I'm 90% where I wanna be now.</p>
<p>I'm trying to return the value of a Property in a custom class through Reflection.</p>
<p>Here's my class declaration:</p>
<pre><code>Public Class Class2
Private ne... | <p><code>Me</code> refers to the <code>ObjectCompare</code> object, which is different than the class from which the <code>PropertyInfo</code> objects were derived (<code>Class2</code>). You need to also pass in an object of the type from which you retrieved the <code>PropertyInfo</code> objects.</p>
<pre><code>Publi... | <p>I'm not really sure I know what you are trying to do here but I'll have a stab at it.</p>
<p>Here is the code that I have come up:</p>
<p><strong>Calling</strong>:</p>
<pre><code> Dim test As New Class2
test.NewProperty2 = "2"
Dim go As New ObjectCompare
go.CompareObjects(test)
</... | 40,007 |
<p>I am running an application through gdb and I want to set a breakpoint for any time a specific variable is accessed / changed. Is there a good method for doing this? I would also be interested in other ways to monitor a variable in C/C++ to see if/when it changes.</p>
| <p><em>watch</em> only breaks on write, <em>rwatch</em> let you break on read, and <em>awatch</em> let you break on read/write.</p>
<p>You can set read watchpoints on memory locations:</p>
<pre><code>gdb$ rwatch *0xfeedface
Hardware read watchpoint 2: *0xfeedface
</code></pre>
<p>but one limitation applies to the rw... | <p>In addition to what has already been answered/commented by <a href="https://stackoverflow.com/users/5577/asksol">asksol</a> and <a href="https://stackoverflow.com/users/2508150/paolo-m">Paolo M</a></p>
<p>I didn't at first read understand, why do we need to cast the results. Though I read this: <a href="https://sour... | 8,330 |
<p>From the MSDN documentation:</p>
<p>"Synchronized supports multiple writing threads, provided that no threads are reading the Hashtable. The synchronized wrapper does not provide thread-safe access in the case of one or more readers and one or more writers."</p>
<p>Source:
<a href="http://msdn.microsoft.com/en-us/... | <p>For the same reason there are different levels of DB transaction. You may care that writes are guaranteed, but not mind reading stale/possibly bad data.
<hr/>
<strong>EDIT</strong> I note that their specific example is an Enumerator. They can't handle this case in their wrapper, because if you break from the enume... | <p>you would need it when you are for-eaching over a hashtable on one thread (reads) and there exists other threads that may add/remove items to/from it (writes) ...</p>
| 29,814 |
<p>I need a regex for the following pattern:</p>
<ul>
<li><p>Total of 5 characters (alpha and numeric, nothing else).</p></li>
<li><p>first character must be a letter (<code>A</code>, <code>B</code>, or <code>C</code> only)</p></li>
<li><p>the remaining 4 characters can be number or letter.</p></li>
</ul>
<p>Clarifca... | <p>EDIT: Grrr... edited regex due to new "clarification" :)</p>
<pre><code>^[A-C][a-zA-Z0-9]{4}$
</code></pre>
<p>EDIT: To explain the above Regex in English...</p>
<p><code>^</code> and <code>$</code> mean "From start to finish" (this ensures that the whole string must perfectly match)</p>
<p><code>[A-C]</code> me... | <p>In case this is not Perl regexps we're talking about, some cut-and-paste is needed:</p>
<pre><code>[ABC][a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9]
</code></pre>
<p>I cut-and-pasted "[a-zA-Z0-9]" four times.</p>
| 43,318 |
<p>This should be fine seeing as the CLR hasn't actually changed?</p>
<p>The boxes running the C# 2.0 code <strong>have</strong> had .NET 3.5 rolled out.</p>
<p>The background is that we have a windows service (.NET 2.0 exe built with VS2005, deployed to ~150 servers) that dynamically loads assemblies (almost like pl... | <p>C#3 and .Net 3.5 adds new assemblies, but the IL is unchanged.</p>
<p>This means that with .Net 2 assemblies you can compile and use C#3, as long as you don't use Linq or anything else that references System.Linq or System.Core</p>
<p><code>yield</code>, <code>var</code>, lambda syntax, anon types and initialisers... | <p>This is interesting stuff. I was looking at <a href="http://www.albahari.com/nutshell/linqbridge.html" rel="nofollow noreferrer">LinqBridge</a> yesterday after someone on this forum suggested it to me and they are doing a similar thing.</p>
<p>I find it strange that Microsoft named the frameworks 2.0, 3.0 and 3.5 w... | 3,092 |
<p>I use Tortoise SVN usuallly, but I have been looking into Mercurial since it is a distributed revision control system. </p>
<p>What I am looking for, in both systems, is a tool that let me pick only parts of a file and commit them. If I want to do this now, I have to copy to a temp version of the file and keep only... | <p>Mercurial can do this with the <a href="https://www.mercurial-scm.org/wiki/RecordExtension" rel="nofollow noreferrer">record</a> extension.</p>
<p>It'll prompt you for each file and each diff hunk. For example:</p>
<pre><code>% hg record
diff --git a/prelim.tex b/prelim.tex
2 hunks, 4 lines changed
examine change... | <p>I would recommend not working like this. </p>
<p>If you have to sets of changes, set A which is ready to check in and set B which is not ready yet, how can you be sure that only checking in set A will not break your build/tests? You may miss some lines, forget about lines in a different file, or not realize a depen... | 17,982 |
<p>How can I put a link in a C# <code>TextBox</code>? I have tried to put HTML tags in the box but instead of showing a link it shows the entire HTML tag. Can this be done with a <code>TextBox</code>?</p>
| <p>Use the <a href="http://msdn.microsoft.com/en-us/library/f591a55w.aspx" rel="noreferrer">RichTextBox</a>, no need to build your own, it cames with VS</p>
| <p>To my knowledge not with the standard textbox. You'd have to create your own. One option it the <a href="http://www.telerik.com/" rel="nofollow noreferrer">Telerik</a> controls, they're a little pricey for individual development, but very robust and configurable.</p>
| 42,854 |
<p>How can I do the Ruby method <a href="http://www.ruby-doc.org/core/classes/Array.html#M002241" rel="noreferrer">"Flatten" Ruby Method</a> in C#. This method flattens a jagged array into a single-dimensional array.</p>
<p>For example:</p>
<pre><code>s = [ 1, 2, 3 ] #=> [1, 2, 3]
t = [ 4, 5, 6, [7, 8] ]... | <p>Recursive solution:</p>
<pre><code>IEnumerable Flatten(IEnumerable array)
{
foreach(var item in array)
{
if(item is IEnumerable)
{
foreach(var subitem in Flatten((IEnumerable)item))
{
yield return subitem;
}
}
else
{... | <p>I would also agree that SelectMany does this.</p>
<pre><code>var s = new[] { 1, 2, 3 };
var t = new[] { 4, 5, 6 };
var a = new[] { s, t, new[] {7, 8} };
a.SelectMany(e => e);
// IEnumerable<int> {1,2,3,4,5,6,7,8}
</code></pre>
<p>I normalized the array. s and t are arrays of int.
a is an array of arrays.
... | 23,959 |
<p>You can structure a C++ program so that (almost) all the code resides in Header files. It essentially looks like a C# or Java program. However, you do need at least one <code>.cpp</code> file to pull in all the header files when compiling. Now I know some people would absolutely detest this idea. But I haven't found... | <p>I disagree with point 1. </p>
<p>Yes, there is only one .cpp and the built time from scratch is faster. But, you rarely build from scratch. You make small changes, and it would need to recompile the whole project each time.</p>
<p>I prefer doing it the other way around:</p>
<ul>
<li>keep shared declarations in .h... | <p>static-or-global-variable kludges even less transparent, perhaps un-debuggable.<p>
for example counting the total number of iterations for analysis.<p>
In MY kludged files putting such items at the top of the cpp file makes them easy to find.<p>
By "perhaps un-debuggable", I mean that routinely I will put such a glo... | 23,563 |
<p>I'm having issues with my SQL Reporting Services reports. I'm using a custom font for report headers, and when deployed to the server it does not render correctly when I print or export to PDF/TIFF. I have installed the font on the server. Is there anything else I need to do in order to use custom fonts?</p>
<p>Whe... | <p>The PDF files served up from SSRS, like many PDF files, have embedded postscript fonts. So, the local fonts used in the report are converted to a best matching postscript font when the conversion takes place so the PDF is totally portable without relying on locally installed fonts. </p>
<p>You can see the official ... | <p>We had to install NeoDynamic barcode software to render the barcode as an image since we can't include the barcode fonts in PDF exports.</p>
| 3,988 |
<p>We have a large C# (.net 2.0) app which uses our own C++ COM component and a 3rd party fingerprint scanner library also accessed via COM. We ran into an issue where in production some events from the fingerprint library do not get fired into the C# app, although events from our own C++ COM component fired and were r... | <p>It seems that stdole.dll is a <strong>primary interop assembly</strong>. See <a href="http://msdn.microsoft.com/en-us/library/aa195478(office.11).aspx" rel="noreferrer">Office 2003 Primary Interop Assemblies on MSDN.</a></p>
| <p>I had to also add a reference to my project for stdole. Even though I don't have any references to it (it's a simple image app), 2 of our users were getting errors that it was missing. It could be that they were only running .net 2.0 when this is a 3.5 app. I have figured out why.</p>
<p>I also went in to publis... | 19,595 |
<p>I was curious about how other people use the <strong>this</strong> keyword. I tend to use it in constructors, but I may also use it throughout the class in other methods. Some examples:</p>
<p>In a constructor:</p>
<pre><code>public Light(Vector v)
{
this.dir = new Vector(v);
}
</code></pre>
<p>Elsewhere</p>
... | <p>There are several usages of <a href="http://msdn.microsoft.com/en-us/library/dk1507sz.aspx" rel="noreferrer">this</a> keyword in C#.</p>
<ol>
<li><a href="http://msdn.microsoft.com/en-us/library/vstudio/dk1507sz%28v=vs.100%29.aspx" rel="noreferrer">To qualify members hidden by similar name</a></li>
<li><a href="htt... | <p>Never. Ever. If you have variable shadowing, your naming conventions are on crack. I mean, really, no distinguishing naming for member variables? <em>Facepalm</em></p>
| 4,325 |
<p>What is the best way to <strong>display</strong> and <strong>print</strong> XPS files in a Windows Forms application?</p>
| <p>I think the easiest way is to use WPF, you can host a WPF control inside a WinForms application - you don't have to rewrite your GUI in WPF or anything like that.</p>
<p>more information here : <a href="http://msdn.microsoft.com/en-us/library/ms745781.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/... | <p>I just call Process.Start(XpsRchVw.exe, "pathtofile")
if you have xps viewer EP installed then this will open your xps in xpsviewer and allow you to use it to print edit etc
binks</p>
| 23,488 |
<p>From a couple of preliminary tests it seems that <a href="http://msdn.microsoft.com/en-us/library/ms633497.aspx" rel="noreferrer"><code>EnumWindows</code></a> always returns windows in reverse instantiation order, i.e. most recently instantiated window first. Is that a valid observation? If so, is it true across all... | <p>It returns them in Z order. First the top-most window with <code>WS_EX_TOPMOST</code> set, until the bottom-most window with <code>WS_EX_TOPMOST set</code>, then the top-most window without <code>WS_EX_TOPMOST</code>, though to the bottom-most window without <code>WS_EX_TOPMOST</code>. Note that visibility is not ... | <p>If you control both processes you can send from the first one a SendMessage with "HWND_BROADCAST" as first parameter.</p>
<p>Then the other program when receive the msg, can do a SendMessage to his child windows.</p>
| 37,853 |
<p>I'm using MSTEST inside Visual Studio 2008. How can I have each unit test method in a certain test class act as if it were the first test to run so that all global state is reset before running each test? I do not want to explicitly clean up the world using TestInitialize, ClassInitialize, AssemblyInitialize, etc. F... | <p>In the end, I wrote a helper that used <a href="http://msdn.microsoft.com/en-us/library/system.appdomain.createdomain.aspx" rel="nofollow noreferrer">AppDomain.CreateDomain</a> and then used reflection to call the unit test under a different AppDomain. It provides the isolation I needed.</p>
<p><a href="http://soci... | <p>We had a similar issue arise with our MSTests. We handled it by calling a function at the beginning and end of the specific tests that needed it. </p>
<p>We are storing a test expiration date in our app configuration. Three tests needed this date to fall into a specific range to determine the appropriate values.... | 23,478 |
<p>Some context upfront:</p>
<p>Imagine a 200+ developers company finally setting up a more or less independent architecture team/department.
The software portfolio consisting of 20+ "projects"/applications of varying sizes in production was taken care of by team-leads/technical-leads, who were responsible for and in ... | <p>Here are a few issues that should be thought about:</p>
<ul>
<li>What is the exact mandate for the architecture team?</li>
<li>What is the architecture team's deliverable? A framework, guidelines, implementation help... Or are they just <a href="http://www.joelonsoftware.com/items/2008/05/01.html" rel="noreferrer"... | <p>in general, be very careful about the incentives both political and otherwise associated with the architecture group. it is far to easy for the 'architectural review board' (or whatever you want to call it) to become barriers to progress. All it takes is zero incentive to improve things and a negative incentive when... | 14,963 |
<p>If I view the HTML generated by one of my Jasper reports in IE7 I see the following: </p>
<pre><code><BR /><BR />
<A name="JR_PAGE_ANCHOR_0_1">
<TABLE style="WIDTH: 1000px" cellSpacing="0" cellPadding="0" bgColor="#ffffff" border="0">
<-- table body omitted -->
</TABLE>
</code></... | <p>I took Phil's advice and dove into the Jasper source code. I've fixed the problem and submitted it to the project. Details of the cause and resolution are available <a href="http://jasperforge.org/tracker/index.php?func=detail&aid=3180&group_id=102&atid=611&action=edit" rel="nofollow noreferrer">here... | <p>In excel export A1 cell transfor to JR_PAGE_ANCHOR_0_1.Some of tips are setting IS_ONE_PAGE_PER_SHEET property doing true, IS_DETECT_CELL_TYPE doing true but these are not working for me.
To avoid from this situation , configure your xlsx report configuration is worked for me (set ignore anchor is key point);</p>
<p... | 26,955 |
<p>I'm looking for a quick way to detect faces in pictures (stored as JPG or any other popular image format). Code in any popular programming language will do (Python, C#, Java, Matlab, etc.). I'm also willing to implement an algorithm by myself, as long as it is proven to be a good working one.</p>
<p>Alternatively, ... | <p><a href="http://opencv.willowgarage.com/wiki/" rel="nofollow noreferrer">OpenCV</a> is a open source library that has support for face recognition.</p>
| <p>I wrote about resources and example code for face classification in <a href="https://stackoverflow.com/questions/5412387/face-recognition/10708503#10708503">this post</a>.</p>
<p>If you want a quick way to do face recognition look at the example code for face recognition in OpenCV for Python or C++ <a href="http://... | 34,005 |
<p>Is it correct to assume that JQuery is not actually an implementation of ECMA spec but rather some kind of framework? </p>
<p>If that is true, what run time does it use? For example in IE, does it finally end up with the javascript engine in IE? </p>
<p>thanks</p>
<p>Sesh</p>
| <p>jQuery is written entirely in Javascript. It runs using whatever Javascript engine is in the browser that runs it, so if you run it in IE, it uses IE's engine. In Firefox it uses the Firefox engine.</p>
<p>Basically it's just an API built around the semi-standard Javascript API every browser complies to. It takes a... | <p>jQuery is a framework written in javascript, and so is of course run by the browsers javascript engine.</p>
| 37,750 |
<p>I have had an Anet A8 printer for about two months now and still have not gotten it to print good prints. </p>
<p>At first, it would only print completely solid parts and every time I would try infill from 10-90% the first layer would not stick or it would print really filmy like. As of now, it won't print the firs... | <p>With respect to the filament lifting off, and/or not adhering correctly, on the first layer, see <a href="https://3dprinting.stackexchange.com/questions/4018/filament-lifts-from-the-hot-bed-while-printing">Filament lifts from the hot bed while printing</a>... in particular, you may need to clean the bed, calibrate t... | <p>When I first started printing with the anet A8, I also had trash first layers.<br>
I tried (almost) everything:</p>
<ol>
<li>Leveling the bed maniacally several times (all the screws in the
frame need to be very tight) </li>
<li>Varying bed temperature and nozzle
temperature at all possible combinations. </li>
<li>... | 604 |
<p>I have a readonly Excel workbook containing a VBA application. The application saves any data that needs to be saved in a database, and the workbook is always closed without saving (by setting ThisWorkbook.Saved = True in BeforeClose).</p>
<p>I have the following problem:</p>
<ul>
<li><p>User double-clicks on the... | <p>In situations like this with multiple seperate components it's almost certainly best to test each component in isolation first, and then test the integrated whole.</p>
<p>So create frameworks and tests for testing:<br>
The Windows GUI<br>
The automation layer.<br>
The hardware device. </p>
<p>While automation can... | <p>Create custom test software package with a xUnit framework.</p>
| 22,636 |
<p>I have a problem where I am attempting to update a set of attributes with a fixed value contained within a repeating section of an XML document using the <code>Microsoft.BizTalk.Streaming.ValueMutator</code>. </p>
<p>For example the XML document which I am attempting to update contains the following input:</p>
<pr... | <p>You need to include the alpha element in your XPath expression.</p>
<p>I ran your code using the expression below: </p>
<pre><code>string xpathToUpdate = "/*[namespace-uri()='http://Test.Schemas']/*[local-name()='NodeA']/*[local-name()='NodeB']/*[local-name()='alpha']/@Type";
</code></pre>
<p>and got the followi... | <p>The XPath expression used:</p>
<p> <strong><code>//namespace-uri()='http://Test.Schemas']/*[local-name()='NodeA']/*[local-name()='NodeB']/*[@Type]</code></strong></p>
<p>selects only the lements that have a "Type" attribute.</p>
<p>Most probably what is needed is:</p>
<p> <stron... | 38,047 |
<p>What is the fastest way to find out whether two <code>ICollection<T></code> collections contain precisely the same entries? Brute force is clear, I was wondering if there is a more elegant method.</p>
<p>We are using C# 2.0, so no extension methods if possible, please!</p>
<p>Edit: the answer would be intere... | <p>use C5</p>
<p><a href="http://www.itu.dk/research/c5/" rel="nofollow noreferrer">http://www.itu.dk/research/c5/</a></p>
<p><a href="http://www.itu.dk/research/c5/Release1.1/c5doc/types/C5.ICollection_1.htm#T:C5.ICollection%601|M:C5.ICollection%601.ContainsAll%60%601(System.Collections.Generic.IEnumerable%7B%60%600... | <p>Brute force takes O(n) - comparing all elements (assuming they are sorted), which I would think is the best you could do - unless there is some property of the data that makes it easier.</p>
<p>I guess for the case of not sorted, its O(n*n). </p>
<p>In which case, I would think a solution based around a <a href="... | 39,737 |
<p>I have a JavaScript method that I need to run on one of my pages, in particular, the <code>onresize</code> event. </p>
<p>However, I don't see how I can set that event from my content page. I wish I could just put it on my master page, but I don't have the need for the method to be called on all pages that use th... | <p>Place the following in your content page:</p>
<pre><code><script type="text/javascript">
// here is a cross-browser compatible way of connecting
// handlers to events, in case you don't have one
function attachEventHandler(element, eventToHandle, eventHandler) {
if(element.attachEvent) {
element.... | <p>How about use code like the following in your Content Page (C#)?</p>
<pre><code>Page.ClientScript.RegisterStartupScript(this.GetType(), "resizeMyPage", "window.onresize=function(){ resizeMyPage();}", true);
</code></pre>
<p>Thus, you could have a <code>resizeMyPage</code> function defined somewhere in the Javascri... | 5,334 |
<p>I have a new VPS server, and I'm trying to get it to connect to another server at the same ISP. When I connect via mysql's command line tool, the connection is very fast.</p>
<p>When I use PHP to connect to the remote DB, the connection time may take up to 5 seconds. Queries after this are executed quickly.</p>
... | <p>I would check to see what mode PHP is running in, is it for some reason running the scripts as a CGI. Basically is PHP itself really slow, and its only noticeable when running remote operations.</p>
<p>Check the web server's configuration. Also if it's an option, try PHP from the command line and see if it perfor... | <p>I would check to see what mode PHP is running in, is it for some reason running the scripts as a CGI. Basically is PHP itself really slow, and its only noticeable when running remote operations.</p>
<p>Check the web server's configuration. Also if it's an option, try PHP from the command line and see if it perfor... | 34,549 |
<p>How can I create a regular expression that will grab delimited text from a string? For example, given a string like </p>
<pre><code>text ###token1### text text ###token2### text text
</code></pre>
<p>I want a regex that will pull out <code>###token1###</code>. Yes, I do want the delimiter as well. By adding an... | <pre><code>/###(.+?)###/
</code></pre>
<p>if you want the ###'s then you need</p>
<pre><code>/(###.+?###)/
</code></pre>
<p>the <strong>?</strong> means non greedy, if you didn't have the <strong>?</strong>, then it would grab too much. </p>
<p>e.g. <code>'###token1### text text ###token2###'</code> would all get ... | <p>Assuming you want to match ###token2### as well...</p>
<pre><code>/###.+###/
</code></pre>
| 10,204 |
<p>Do you follow a standard for wrapping long lines in source code? What line length do you find most comfortable to read?</p>
<p>Sometimes I find people who program on wide-screen monitors and like to use its full width for displaying source code. I prefer shorter lines, around 80-100 characters, but I have a hard ti... | <p>Don't compromise readability for dogmatic rules on the exact number of characters in a row. Horizontal scrolling is undesirable but an 81-character line is easier to read than an indentation-confusingly line-wrapped version.</p>
<p>80 characters is likely to be inadaquate for programming styles with large indentati... | <p>I use around 72-75 columns to ensure that I can print the code on letter-format pages without too much trouble. I also use spaces instead of tabs and am careful about the layout.</p>
<p>To notice when I am going off the right margin, I often put in a text line that I can
use as a ruler. I set the IDE display wind... | 34,797 |
<p>We have been using Adobe Flex for a major project but it's just too slow.</p>
<p>We're considering switching to Silverlight.</p>
<p>The problem seems to be that Silverlight is not as widely supported by browsers as Flex/Flash is.</p>
<p>For example I tried to access the Silverlight showcase using Safari for Windo... | <p>Browser Plugins are essentially native applications, so you essentially need a Plugin for each architecture.</p>
<p>For example, there is no 64-Bit Flash Plugin for Windows, so I always have to use 32-Bit IE for that. I also believe that there is no Linux-PPC support, but it's been a while since I've looked at that... | <p>Browser Plugins are essentially native applications, so you essentially need a Plugin for each architecture.</p>
<p>For example, there is no 64-Bit Flash Plugin for Windows, so I always have to use 32-Bit IE for that. I also believe that there is no Linux-PPC support, but it's been a while since I've looked at that... | 47,522 |
<p>In our CMS, we have a place in which we enable users to play around with their site hierarchy - move pages around, add and remove pages, etc.</p>
<p>We use drag & drop to implement moving pages around. </p>
<p>Each move has to saved in th DB, and exported to many HTML files. If we do that in every move, it wil... | <p>You should warn the user when he leaves the page with javascript.</p>
<p>From <a href="http://www.siafoo.net/article/67" rel="nofollow noreferrer">http://www.siafoo.net/article/67</a>:</p>
<p>Modern browsers have an event called window.beforeunload that is fired right when any event occurs that would cause the pag... | <p>The easiest way I can think of is to store the page info each time the user moves items around using Ajax (e.g. with an UpdatePanel, onUpdated event, let it fire some script that updates the users page config.</p>
<p>Alternatively - .Net's WebParts implementation does this automatically without intervention by the ... | 16,093 |
<p>Can a cookie be shared between two sites on the same top level domain? Say <code>www.example.com</code> and <code>secure.example.com</code> ?
We are looking into implementing a cache for non-secure content, and need to segregate secure content to another domain.
What parameters does the cookie need? I'm using asp.ne... | <p>Yes, you can. Use:</p>
<pre><code>Response.Cookies("UID").Domain = ".myserver.com"
</code></pre>
| <p>Yes, but beware don't set same-named cookies in various subdomains, as the resulting cookie appears to be random; instead, set one cookie in the .maindomain.com only (not in any .sub.domain.com)</p>
| 13,395 |
<p>I am trying to create an array starting with today and going back the last 30 days with PHP and I am having trouble. I can estimate but I don’t know a good way of doing it and taking into account the number of days in the previous month etc. Does anyone have a good solution? I can’t get close but I need to make su... | <p>Try this:</p>
<pre><code><?php
$d = array();
for($i = 0; $i < 30; $i++)
$d[] = date("d", strtotime('-'. $i .' days'));
?>
</code></pre>
| <p>You can use time to control the days:</p>
<pre><code>for ($i = 0; $i < 30; $i++)
{
$timestamp = time();
$tm = 86400 * $i; // 60 * 60 * 24 = 86400 = 1 day in seconds
$tm = $timestamp - $tm;
$the_date = date("m/d/Y", $tm);
}
</code></pre>
<p>Now, within the for loop you can use the $the_date vari... | 43,833 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.