instruction stringlengths 21 27.8k | chosen stringlengths 18 28.2k | rejected stringlengths 18 33.6k | __index_level_0__ int64 0 50k |
|---|---|---|---|
<p>I was recently tasked with coming up with an offsite backup strategy. We have about 2TB of data that would need to be backed up so our needs are a little out of the norm. </p>
<p>I looked into Iron Mountain and they wanted $12,000 a month! </p>
<p>Does anyone have any suggestions on how best to handle backing up t... | <p>You can buy external eSATA RAID boxes in the 8TB capacity range <a href="http://www.newegg.com/Product/Product.aspx?Item=N82E16822101110" rel="nofollow noreferrer">for $2600</a>. I'm not saying that particular product is the right choice, but that's the kind of box that will do 6TB in RAID5 and still be portable eno... | <p>I've used <a href="http://bqbackup.com" rel="nofollow noreferrer">bqbackup.com</a> for 1-2 years no problem. You can do a sync using rsync nightly. Wanted to add that their prices are dirt cheap, and I now have close to 1TB with them.</p>
| 3,064 |
<p>Say you've loaded a text file into a string, and you'd like to convert all Unicode escapes into actual Unicode characters inside of the string. </p>
<p>Example:</p>
<blockquote>
<p>"The following is the top half of an integral character in Unicode '\u2320', and this is the lower half '\U2321'."</p>
</blockquote>... | <p>The answer is simple and works well with strings up to at least several thousand characters.</p>
<p>Example 1:</p>
<pre><code>Regex rx = new Regex( @"\\[uU]([0-9A-F]{4})" );
result = rx.Replace( result, match => ((char) Int32.Parse(match.Value.Substring(2), NumberStyles.HexNumber)).ToString() );
</code></pre>
... | <p>I think you better add the small letters to your regular expression. It worked better for me.</p>
<pre><code>Regex rx = new Regex(@"\\[uU]([0-9A-Fa-f]{4})");
result = rx.Replace(result, match => ((char) Int32.Parse(match.Value.Substring(2), NumberStyles.HexNumber)).ToString());
</code></pre>
| 22,237 |
<p>I am writing a web-framework for Python, of which the goal is to be as "small" as possible (currently under 100 lines of code).. You can see the current code <a href="http://github.com/dbr/pyerweb/tree/master" rel="nofollow noreferrer">on github</a></p>
<p>Basically it's written to be as simple to use as possible. ... | <p>Look at <a href="http://www.python.org/dev/peps/pep-0333/" rel="nofollow noreferrer">PEP 333</a> for an excellent design pattern for a very lightweight web server. If your server has this exact API, you can reuse it in a lot of context with a lot of other products.</p>
<p>PEP 333 (WSGI) suggests that you don't dir... | <p>You should reconsider the notion of returning <a href="http://en.wikipedia.org/wiki/Html" rel="nofollow noreferrer">HTML</a> - headers are part of <a href="http://en.wikipedia.org/wiki/Http" rel="nofollow noreferrer">HTTP</a>.
If you build your framework around an HTTP stream, the headers are simply lines that prece... | 45,215 |
<p>I printed a raspberry pi case from PLA. <a href="https://www.thingiverse.com/thing:1549574" rel="noreferrer">This case</a>.</p>
<p>I fitted it to my raspberry pi and now the wifi keeps dropping out. When I take it out of the case there is no problem. </p>
<p>The filament I am using is Black, 3D Hero 1.75mm.</p>
<... | <p>Typically the black pigments in polymers are mineral based. If you are having true WiFi issues then it sounds like your filiment is using black iron oxide also called <a href="https://en.wikipedia.org/wiki/Magnetite" rel="nofollow noreferrer">magnetite</a> for the black pigment. This is the same material they use in... | <p>Typically the black pigments in polymers are mineral based. If you are having true WiFi issues then it sounds like your filiment is using black iron oxide also called <a href="https://en.wikipedia.org/wiki/Magnetite" rel="nofollow noreferrer">magnetite</a> for the black pigment. This is the same material they use in... | 1,262 |
<p>I have a string in Bash:</p>
<pre class="lang-sh prettyprint-override"><code>string="My string"
</code></pre>
<p>How can I test if it contains another string?</p>
<pre class="lang-sh prettyprint-override"><code>if [ $string ?? 'foo' ]; then
echo "It's there!"
fi
</code></pre>
<p>Where <code>??<... | <p>You can use <a href="https://stackoverflow.com/a/229585/3755692">Marcus's answer (* wildcards)</a> outside a case statement, too, if you use double brackets:</p>
<pre><code>string='My long string'
if [[ $string == *"My long"* ]]; then
echo "It's there!"
fi
</code></pre>
<p>Note that spaces in the needle string n... | <pre><code>msg="message"
function check {
echo $msg | egrep [abc] 1> /dev/null
if [ $? -ne 1 ];
then
echo "found"
else
echo "not found"
fi
}
check
</code></pre>
<p>This will find any occurance of a or b or c</p>
| 28,413 |
<p><em>After delving into the world of opensource I have found implementation is emphasised over design. Version control allows for a project to branch off in many directions, which projects may do; this suggests lack of consensus or direction amongst the participants.</em></p>
<h3>What software or websites are useful... | <p>There are literally hundreds more collaboration apps out there and more keep appearing by the day, but these should get you started: </p>
<p><strong>Source Control (Online):</strong></p>
<ul>
<li><a href="http://www.assembla.com/" rel="noreferrer">Assembla</a> - Public source is
free, private repositories are paid... | <p>A wiki (such as <a href="http://www.screwturn.eu/" rel="nofollow noreferrer">ScrewTurn</a>, or <a href="http://www.mediawiki.org/wiki/MediaWiki" rel="nofollow noreferrer">MediaWiki</a>) is a good tool to document a project.</p>
<p><a href="http://www.basecamphq.com/" rel="nofollow noreferrer">BaseCamp</a> by 37 Sig... | 23,219 |
<p>I have a ListBox with a bunch of images in it (done through a datatemplate). The images are created by setting the items source:</p>
<pre><code><Image x:Name="ItemImage" Source="{Binding ImageUrl}"/>
</code></pre>
<p>and then they are cleared by using the listbox's Items.Clear() method. New Images are add... | <p>Monitoring of the system health using statspack (9i) or AWR (10g+) would be the best method of identifying bottlenecks.</p>
<p>In particular:</p>
<ul>
<li>lookout for redo waits. The redo log is critical in maintaining a high write rate</li>
<li>Use bind variables</li>
<li>Use bulk operations wherever possible.</l... | <p>Depending on the characteristics of your application and your data, consider a bulk data load using an Oracle external table. Have the application write the data to a text file, then use an INSERT INTO your target table from a SELECT on the external table = very fast.</p>
<p>There are some constraints, and it may ... | 22,458 |
<p>I have a database that i'm dealing with which is updated every few hours remotely (not on any specific time span) and i have no control over the administration of it. I have web clients connecting to it to view information contained within it. These clients (coded using PHP and Javascript) might be checking the data... | <p>You should use some sort of cache. For more serious sites, take a look at memcached.
If you are in a smaller scale, cache the results to file by serializing it.</p>
| <p>Do you have control over the web app? If users are logged in and have sessions associated with them, you could cache the time since a user last queried the database, and refuse to hand back new data if a request is beneath some threshold interval since the last query.</p>
<p><a href="http://us.php.net/session" rel... | 40,706 |
<p>I am wondering about what the difference between logging and tracing is.</p>
<p>Is the difference basically that tracing is more detailed log giving developers a tool to debug applications at runtime?</p>
<p>I have been experimenting with log4net and doing logging. Now I am wondering if I should be doing tracing a... | <p>Logging is the generic term for recording information - tracing is the specific form of logging used to debug.</p>
<p>In .NET the System.Diagnostics.Trace and System.Diagnostics.Debug objects allow simple logging to a number of "event listeners" that you can configure in app.config. You can also use TraceSwitches t... | <p>logging != debugging</p>
<p>Sometimes keeping log files is necessary to solve issues with the client, they prove what happened on the server side.</p>
| 20,773 |
<p>I know this site is written using ASP.Net MVC and I do not see "/Home" in the url. This proves to me that it can be done. What special route and do I need?</p>
| <p>Just change "Home" to an empty string.</p>
<pre><code>routes.MapRoute(
"Home",
"",
new { action = Index, controller = Home }
);
</code></pre>
| <p>In IIS 7, you can simply delete the Default.aspx file that comes with ASP.NET MVC (assuming you're running on Preview 3 or higher). That file was needed due to an issue with Cassini that was fixed in .NET 3.5 SP1.</p>
<p>For more details check out:</p>
<p><a href="http://haacked.com/archive/2008/04/10/upcoming-cha... | 3,627 |
<p>Is there a way to tell the debugger to stop just before returning, on whichever statement exits from the method, be it return, exception, or fall out the bottom? I am inspired by the fact that the Java editor shows me all the places that my method <em>can</em> exit - it highlights them when you click on the return t... | <p>Put a breakpoint on the line of the method signature. That is where you write</p>
<pre><code>public void myMethod() {
</code></pre>
<p>Then right-click on the breakpoint and select "Breakpoint Properties". At the bottom of the pop-up there are two checkboxes: "Method Entry", "Method Exit". Check the latter.</p>
| <p>Good question. Off the top of my head, I'd do this:</p>
<pre><code>public void method(Object stuff) {
try {
/* normal code */
} finally {
int x = 0;
}
}
</code></pre>
<p>You can set the breakpoint on the x = 0 line, and it will ALWAYS be executed no matter where you return. Even with an... | 24,113 |
<p>WPF WebBrowser control looks great but knowledge accumlated over time about WinForms WebBrowser is substantial and it's hard to ignore work like csExWB. It would be nice to know what functional shortcomings or advantages exists in .NET 3.5's WPF WebBrowser control over WinForms WebBrowser control. In particular, is ... | <p>From one full day of frustration with wpf's component, here's what I discovered. Apparently, winforms webbrowser exposes much more methods and properties. For instance, there's no <code>IsWebBrowserContextMenuEnabled</code>, <code>ActiveXInstance</code>, etc. in wpf webbrowser.</p>
<p>Also, the <code>document</code... | <p>I must admit I don't know the differences, but if you hit problems you could perhaps use <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.integration.windowsformshost.aspx" rel="nofollow noreferrer">WindowsFormsHost</a> to host the winform version in WPF, <a href="http://nayyeri.net/blog/host-wi... | 20,689 |
<p>When hiring a front-end developer, what specific skills and practices should you test for? What is a good metric for evaluating their skill in HTML, CSS and Javascript?</p>
<p>Obviously, table-less semantic HTML and pure CSS layout are probably the key skills. But what about specific techniques? Should he/she be ab... | <p>When I interview people for a position of Client-Side developer I try to figure out:</p>
<pre>
1) Understanding DOM (what is that, how is it related to HTML etc)
2) Understanding XML/namespaces
3) Understanding JavaScript (object-oriented? what otherwise)
4) Knowing approaches to componentization (XBL, HTC) - plus
... | <p>I wouldn't put too much weight on it, as proper HTML/CSS is so simple that anyone can learn it in a week.</p>
<p>That said, you might want to review their portfolio to help you make a decision on their current skill level.</p>
| 24,157 |
<p>Suppose I have a .NET assembly, A, which uses reflection to load assemblies B and C (also .NET). These two assemblies both implement a number of large interfaces (the same for both). When a method is called in A it tries to make B do the work. However, B is unreliable and might throw exceptions. Now A has two modes,... | <p>You might do this, it saves some repetition:</p>
<pre><code>public class BErrorWrapper : I1, I2, I3{
...
public int DoSomeWork(int num){
try
{
return B.DoSomeWork(num);
}
catch(MyLibException e)
{
if (FailWithExceptions) throw;
return C.DoSomeWOrk(num);... | <p>Hmmm... to save some code you could wrap most of the common signatures via delegates, like below (note I've only included the core bits to keep it clear - but you can add your <code>FailWithExceptions</code> stuff trivially):</p>
<pre><code> static void TryWithFallback<T>(Action<T> primary, Action<... | 38,659 |
<p>I am looking for an open-source Java-based raytracing system suitable for use in modeling underwater ray-based acoustics. Such a package might be similar to the Comprehensive Acoustic System Simulation (CASS) with the Gaussian Ray Bundle (GRAB) but I would prefer an open-source, free-to-use or free-to-modify model ... | <p>The <a href="http://sourceforge.net/projects/rapsor" rel="nofollow noreferrer">RaPSor</a> project appears to be a java based ray-tracing simulator. It actually stands for Radio Propagation Simulator and was developed initially to support radio signal propagation for things like projecting dead spots in the WiFi cov... | <p>Have you taken a look at the <a href="http://j3d.sourceforge.net/" rel="nofollow noreferrer">Rings</a> project? I don't know enough about ray tracing to judge whether or not Rings is implemented in the way you need it to be for maximum usefulness. The documentation and examples seem pretty good.</p>
| 13,085 |
<p>I was reading about Clojure and found a discussion about Java not supporting tail calls, in the current version, and that people were throwing exceptions to simulate tail calling in the JVM, anyways it sounds like people are doing some crazy stuff out there. So this got me wondering about C#'s tail calling, same iss... | <p>CLR code will tail call in some cases but not others - it depends on the JIT.</p>
<p>See <a href="https://web.archive.org/web/20190114032303/https://blogs.msdn.microsoft.com/davbr/2007/06/20/tail-call-jit-conditions" rel="nofollow noreferrer">David Broman's blog entry</a> and <a href="http://blogs.msdn.com/shrib/ar... | <p>Tail recursion is possible on the JVM in certain cases. For example, Scala asks for an efficient implementation of basic tail recursion (see this blog post, look for <a href="http://www.willarson.com/blog/?p=15" rel="nofollow noreferrer">Language Trivia #8</a>, only quote I could find just now). There is talk and re... | 45,979 |
<p>I am looking for details of the VTable structure, order and contents, and the location of the vtable pointers within objects. </p>
<p>Ideally, this will cover single inheritance, multiple inheritance, and virtual inheritance.</p>
<p>References to external documentation would also be appreciated</p>
<p>Documentati... | <p>A virtual table is generally treated as an array of function pointers, although compilers are free to put data pointers (in MI and VI scenarios, or to typeinfos), integers (for fixups), or sentinel elements (such as NULL pointers) into it as well. The layout is generally compiler-specific (or ABI-specific where mul... | <p>Most of the compiler implementations that I have seen just "embed" the base object into the derived object. It becomes irrelevant where the vtable is kept because the relative offset into the object will just be added at compile time as references are evaluated. </p>
<p>Multiple and virtual inheritance are more com... | 9,610 |
<p>I have a WPF TreeView with just 1 level of items. The TreeView is data bound to an ObservableCollection of strings. How can I ensure that the same icon appears to the left of each node in the TreeView?</p>
| <p>I think the best approach is to set a Style on the TreeView that will change the Template of the TreeViewItems to have the Image that you want.</p>
<p>The Template will probably need to be a StackPanel with an Image and a label control, you bind the image to your icon, and the label text to the strings from the Obs... | <p>I think the best approach is to set a Style on the TreeView that will change the Template of the TreeViewItems to have the Image that you want.</p>
<p>The Template will probably need to be a StackPanel with an Image and a label control, you bind the image to your icon, and the label text to the strings from the Obs... | 31,186 |
<p><strong>I was wondering if this printer(daVinci 1.0) had the ability to print very small objects, like insects, coins, or small nuts. (About the size of 1 -2 cubic centimeters)</strong></p>
<p><a href="http://us.xyzprinting.com/us_en/Product/da-Vinci-1.0-AiO" rel="nofollow">Here</a> is a link to the printer on the... | <p>1) If we're talking about FFF/FDM printers:</p>
<p>Accuracy of the electronics and motors allows it, yes.
But how FDM printers work it might be very hard to lay down layers of molten plastic so small as to preserve little details in the X and Y axis, not much of a problem doing 20 micron layer height though (Z reso... | <p>Strictly by looking at the technical specifications of an FDM printer, there are a few things to note regarding the <em>maximum print quality</em> you can expect to achieve:</p>
<ul>
<li>The <strong>minimum layer height</strong> - here given to be <em>0.1 mm</em></li>
<li>The <strong>nozzle diameter</strong> - her... | 195 |
<p>Is it possible to insert a row, but only if one of the values already in the table does not exist?</p>
<p>I'm creating a <em>Tell A Friend</em> with referral points for an ecommerce system, where I need to insert the friend's email into the database table, but only if it doesn't already exist in the table. This is ... | <p>If the column is a primary key or a unique index:</p>
<pre><code>INSERT INTO table (email) VALUES (email_address) ON DUPLICATE KEY UPDATE
email=email_address
</code></pre>
<p>Knowing my luck there's a better way of doing it though. AFAIK there's no equivalent of "ON DUPLICATE KEY DO NOTHING" in MySQL. I'm not sure... | <p>If the email field was the primary key then the constraints on the table would stop a duplicate from being entered.</p>
| 36,320 |
<p>I need to display an error message on rejecting a drop in my application.</p>
<p>I tried this in the <code>OnDrop()</code> but then the source application hangs until my message box is dismissed.</p>
<p>How can I do that?</p>
| <p>You can always call PostMessage with a private message in the WM_APP range and in the message handler show the error.</p>
<p>That way you show the error after the drag and drop operation is really over and there is no danger of messing up anything.</p>
| <p>You're right. But all the data I need to report in the message box is in the OnDrop.</p>
| 7,164 |
<p>I need a CSS selector that can find the 2nd div of 2 that has the same class. I've looked at <code>nth-child()</code> but it's not what I want since I can't see a way to further clarify what class I want. These 2 divs will be siblings in the document if that helps.</p>
<p>My HTML looks something like this:</p>
<pr... | <p>Selectors can be combined:</p>
<pre><code>.bar:nth-child(2)
</code></pre>
<p>means "thing that has class <em>bar</em>" that is also the 2nd child.</p>
| <p>First you must select the parent element and set <code>:nth-of-type(n)</code> for the parent and then select the element you want. something like this :</p>
<pre><code>#topmenu li:nth-of-type(2) ul.childUl {
</code></pre>
<p>This will select the second submenu from topmenu. <code>#topmenu li</code> is the parent... | 39,371 |
<p>WARNING: I have been learning Python for all of 10 minutes so apologies for any stupid questions!</p>
<p>I have written the following code, however I get the following exception: </p>
<blockquote>
<p>Message File
Name Line Position Traceback Node
31
exceptions.TypeE... | <p>I'm going to assume you're coming from a Java-ish background, so there are a few key differences to point out.</p>
<pre><code>class Computer(object):
"""Docstrings are used kind of like Javadoc to document classes and
members. They are the first thing inside a class or method.
You probably want to ext... | <p>That isn't valid python.</p>
<p>The constructor for a Python class is <code>def __init__(self, ...):</code> and you cannot overload it.</p>
<p>What you can do is use defaults for the arguments, eg.</p>
<pre><code>class Computer:
def __init__(self, compName="Computer1", compIp="0.0.0.0", compScreenSize=17):
... | 40,302 |
<p>I want to copy a file from A to B in C#. How do I do that?</p>
| <p>The File.Copy method:</p>
<p><a href="http://msdn.microsoft.com/en-us/library/system.io.file.copy.aspx" rel="nofollow noreferrer">MSDN Link</a></p>
| <p>System.IO.File.Copy</p>
| 4,027 |
<p>I have been noticing on my trackers that bots are visiting my site ALOT. Should I change or edit my robots.txt or change something? Not sure if thats good, because they are indexing or what?</p>
| <blockquote>
<p>Should i change or edit my robots.txt or change something? </p>
</blockquote>
<p>Depends on the bot. Some bots will dutifully ignore robots.txt.
We had a similar problem 18 months ago with the google AD bot because our customer was purchasing Soooo many ads.
Google AD bots will (as documented) igno... | <p>I really don't think changing the robots.txt is going to help, because only GOOD bots abide by it. All other ignore it and parse your content as they please. Personally I use <a href="http://www.codeplex.com/urlrewriter" rel="nofollow noreferrer">http://www.codeplex.com/urlrewriter</a> to get rid of the undesirabl... | 42,394 |
<p>i have a winforms application. i have a user control with a lot of icons. the user can load this control on a form many times (in a tabbed layout). right now i am loading the icons each time the control is created (could be up to 50 times in teh app). is there any way to cache these icons in the application. if... | <p>You can make a singleton class for each icon. The first reference it creates the handle. Subsequent calls uses the existing handle.</p>
<p>Without knowing more about your user control my next suggestion can be only be very general. But you could have a single bitmap layer on which you draw all your icons. The remai... | <p>If the issue is the number of "icons" (not sure what you mean here) you can use Image-Lists. For example, a Listview control can reference icons in an image-list, instead of keeping a full copy for each item (not sure if this applies to your case though).</p>
| 42,078 |
<p>I have a Double which could have a value from around 0.000001 to 1,000,000,000.000</p>
<p>I wish to format this number as a string but conditionally depending on its size. So if it's very small I want to format it with something like:</p>
<pre><code>String.Format("{0:.000000000}", number);
</code></pre>
<p>if it'... | <p>Use Math.Log10 of the absolute value of the double to figure out how many 0's you need either left (if positive) or right (if negative) of the decimal place. Choose the format string based on this value. You'll need handle zero values separately.</p>
<pre><code>string s;
double epislon = 0.0000001; // or however ... | <p>If it were me, I'd write a custom wrapper class and put tvanfosson's code into its <code>ToString</code> method. That way you could still work with the double value, but you'd get the right string representation in just about all cases. It'd look something like this:</p>
<pre><code>class FormattedDouble
{
pu... | 46,265 |
<p>I love scaffolding and it extremely helpful for prototyping. But Should we use scaffolding for developing application as such?</p>
| <p>The name "scaffolding" is sort of a misnomer in Rails now (post 2.0). The structure generated through scaffolding generator is more of a base application to build on, rather than a "prototype" that you throw away later.</p>
<p>At least, if you are designing your application to be RESTful, you will find yourself kee... | <p>Actually It's depends on your requirements. When we consider about the scaffold it will generate CRUD(Create, Read, Update and Delete) operations instantly. So if you need to remove some of operations its really easy if you coded it manually. But that also can be done by using scaffold also. Just you have to remove ... | 47,627 |
<p>When I downloaded Skype, I noticed that, in place of a normal "disk image" icon, there was a custom icon, and when I double clicked on the icon, the window used a colorful image as the background, prompting me to drag the skype icon into the applications folder.</p>
<p>How can I do that with my applications?</p>
<... | <p>Let me add to the other answers <a href="http://www.jwz.org/blog/2006/03/setting-view-options-on-dmg-files/" rel="nofollow noreferrer">jwz's howto</a> on setting view options on .dmg files. This is the simplest one that I got to work with no problems.</p>
<p>Also, to change the icon from the default .dmg icon: </p>... | <p>If you’re interested in a commercial solution, there are a number of DMG designer apps available, including the following I gleaned from a <a href="http://www.macupdate.com/search.php?starget=google&keywords=dmg" rel="nofollow noreferrer">MacUpdate search</a>:</p>
<ul>
<li><a href="http://freespace.virgin.net/j... | 8,686 |
<p>This code:</p>
<pre><code>db = "C:\Dokumente und Einstellungen\hom\Anwendungsdaten\BayWotch4\Neuer Ordner\baywotch.db5"
TextExportFile = "C:\Dokumente und Einstellungen\hom\Anwendungsdaten\BayWotch4\Neuer Ordner\Exp.txt"
Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
cn.Open _
... | <p>You might consider using something like a WCF service and streaming the xml up using the GZipStream. I am doing something similar to this and it is working pretty well. </p>
| <p>Wouldn't a normal string be enough? It's overkill to serialize / deserialize an entire XDoc instance in my opinion. Of course, you can also zip the entire thing to reduce the size of the requests.</p>
| 44,239 |
<p>I am writing a drop-in replacement for a legacy application in Java. One of the requirements is that the ini files that the older application used have to be read as-is into the new Java Application. The format of this ini files is the common windows style, with header sections and key=value pairs, using # as the ... | <p>The library I've used is <a href="http://ini4j.sourceforge.net/" rel="noreferrer">ini4j</a>. It is lightweight and parses the ini files with ease. Also it uses no esoteric dependencies to 10,000 other jar files, as one of the design goals was to use only the standard Java API</p>
<p>This is an example on how the ... | <p>It is just as simple as this.....</p>
<pre><code>//import java.io.FileInputStream;
//import java.io.FileInputStream;
Properties prop = new Properties();
//c:\\myapp\\config.ini is the location of the ini file
//ini file should look like host=localhost
prop.load(new FileInputStream("c:\\myapp\\config.ini"));
String... | 23,136 |
<p>When the program runs, there is a series of ListView forms. We populated one of them with items (as strings) and we check whether the state of selection has changed. Once it's changed, we grab the text of the selected item using FocusedItem.Text. The first time works just fine but when another selection is made, the... | <p>Put the following condition around in the <code>OnSelectedIndexHandler</code>:</p>
<pre><code>if(listViewObject.SelectedItems!=null&& listViewObject.SelectedItems.Count>0)
{
//....your code here
}
</code></pre>
| <p>I have run a test program and see no instance where FocusedItem could be nulls.</p>
<p>Could you post some code?</p>
<p>Here is what I got after I selects the item 'a' then selects the item 'b' and then click on an empty space:</p>
<pre><code>ItemSelectionChanged
Item : ListViewItem: {a}
IsSelecte... | 34,942 |
<p>Has anyone had any success running two different web servers -- such as Apache and CherryPy -- alongside each other on the same machine? I am experimenting with other web servers right now, and I'd like to see if I can do my experiments while keeping my other sites up and running. You could say that this isn't so ... | <p>You can't have two processes bound to the same port on the same IP address. You can add another IP address to the box and have each server listen on one.</p>
<p>Another option is to proxy pass one server to the other. With Apache, you could do something like:</p>
<pre><code>NameVirtualHost *
<virtualhost *>
... | <p>Your best bet would be putting Apache httpd in front of port 80 and relay requests meant for other servers through Apache by using modules. Most popular scenario would be Tomcat behind Apache where you'll be able to run both php and jsp applications.</p>
<p>I'm not familiar with CherryPy, so I can only suggest you ... | 4,357 |
<p>How do I take a set of polygons which contain arbitrary values and create a corresponding bitmap where each pixel contains the value of the polygon at that location?</p>
<p>To put the question into context, my polygons contain information about the average number of people per square kilometre within the polygon. I... | <p>What GIS software are you using? ArcGIS offers the Polygon to Raster tool in ArcGIS 9.2 or later, which is scriptable as the PolygonToRaster_conversion function.</p>
<pre><code>PolygonToRaster_conversion (in_features, value_field, out_raster_dataset, cell_assignment, priority_field, cellsize)
</code></pre>
| <p>ImageMagick can convert from svg to png, maybe you can take a look at the code, or simply create svg and use IM for the conversion? <a href="http://scruffy.rubyforge.org/" rel="nofollow noreferrer" title="Scruffy">Scruffy</a> does that.</p>
| 8,306 |
<p>I've been using Visual Studio for a long time and the constant shuffling of the code tabs at the top drives me bonkers. I was wondering if there were any add-ins that might change this or other UI behavior.</p>
<p>Things that might be cool:</p>
<ul>
<li>Sticky Tabs that won't go away.</li>
<li>Multi-code file coll... | <p>The "Having the solution tree go to the file you are currently looking at automatically" feature already exists in VS2008, but isn't enabled by default. Go to tools -> options -> projects and solutions -> general and check the "Track Active Item in Solution Explorer" box.</p>
| <p>The "Having the solution tree go to the file you are currently looking at automatically" feature already exists in VS2008, but isn't enabled by default. Go to tools -> options -> projects and solutions -> general and check the "Track Active Item in Solution Explorer" box.</p>
| 12,794 |
<p>I found an example in the <a href="http://msdn2.microsoft.com/en-us/bb330936.aspx" rel="noreferrer">VS2008 Examples</a> for Dynamic LINQ that allows you to use a SQL-like string (e.g. <code>OrderBy("Name, Age DESC"))</code> for ordering. Unfortunately, the method included only works on <code>IQueryable<... | <p>Just stumbled into this oldie...</p>
<p>To do this without the dynamic LINQ library, you just need the code as below. This covers most common scenarios including nested properties.</p>
<p>To get it working with <code>IEnumerable<T></code> you could add some wrapper methods that go via <code>AsQueryable</code... | <pre><code>var result1 = lst.OrderBy(a=>a.Name);// for ascending order.
var result1 = lst.OrderByDescending(a=>a.Name);// for desc order.
</code></pre>
| 6,255 |
<p>I am writing a text editor for Mac OS X. I need to display hidden characters in an NSTextView (such as spaces, tabs, and special characters). I have spent a lot of time searching for how to do this but so far I have not found an answer. If anyone could point me in the right direction I would be grateful.</p>
| <p>Have a look at the NSLayoutManager class. Your NSTextView will have a layout manager associated with it, and the layout manager is responsible for associating a character (space, tab, etc.) with a glyph (the image of that character drawn on the screen).</p>
<p>In your case, you would probably be most interested in ... | <p>I solved the problem of converting between NSGlyphs and the corresponding unichar in the NSTextView. The code below works beautifully and replaces spaces with bullets for visible text:</p>
<pre><code>- (void)drawGlyphsForGlyphRange:(NSRange)range atPoint:(NSPoint)origin
{
NSFont *font = [[CURRENT_TEXT_VIEW typ... | 38,458 |
<p>Is it a good idea to share views between different controllers (using the <em>Views/Shared</em> folder)?<br><br> I am creating my first MVC application and it requires some pieces of data that are similar to each other. They "explain" different things (and will therefore be stored in different tables) but they each ... | <p>With our project we isolate most of the views to the controllers and don't reuse many of them, but we do use a lot of user controls and partial views so that we don't end up repeating ourselves. This lets us keep everything strongly typed as well, perhaps it might suit your scenario?</p>
| <p>If you had a common page format, say a table, then you could create a generic view in the Shared folder. This ViewData would have to contain column information as well as the data, as well as some information about any links.</p>
<p>The details are not difficult, and it would save time if there are a lot of simila... | 45,797 |
<p>Is anyone using the OSGi Bundle Repository and what for?</p>
| <p>I am using it!</p>
<p>When you develop an osgi bundle and the target platform doesn't include the libraries (jar/bundle) your bundle relies on, it needs to added to the target platform. you could either repackage your jar to make it an osgi bundle or just download the bundle from the OBR.</p>
<p>Eclipse also provi... | <p>I am using it!</p>
<p>When you develop an osgi bundle and the target platform doesn't include the libraries (jar/bundle) your bundle relies on, it needs to added to the target platform. you could either repackage your jar to make it an osgi bundle or just download the bundle from the OBR.</p>
<p>Eclipse also provi... | 32,527 |
<p>Is there a way to select designtime packages on a project bases?</p>
<p>Packages are very useful in large project to keep the build time acceptable, but they are a real pita in those large projects too. When one developer adds a new package, it breaks to build for all other until they install the new package on the... | <p>At my previous job I wrote a little tool to help us with versioning packages. I really should recreate that tool in my spare time and make it available. The tool was not hard to write though, so maybe you can implement something like it yourself.</p>
<p>Basically it worked like this:</p>
<ul>
<li>Subversion repo... | <p>We put the source for our packages in source control along with a batchfile that rebuilds them. If there is a change in the tree for packages then we rebuild them. This doesn't address installing new packages, but there are registry hits that can take care of that, so it is possible that we could include .reg snip... | 24,436 |
<p>Our website connects to a database correctly when running the website locally using the built-in web server. But, when we deploy the site to our server running IIS, we get a database connection error. The database server is different from our IIS server. Note that a trusted connection to a different database on t... | <p>When you're running a web site using Cassini, the account used by the web server process is your own account that you use to log on to your Windows machine. That account will be different on IIS.</p>
<p>Consider the security implications of opening the database up to a broader access than you may need with trusted ... | <p>I'd check the user account that app domain in IIS is using to connect to SQL Server. The account in IIS may not have access to network resources as well which would explain the trouble reaching the other database server.</p>
| 25,127 |
<p>Has anyone written an 'UnFormat' routine for Delphi?</p>
<p>What I'm imagining is the <em>inverse</em> of <em>SysUtils.Format</em> and looks something like this </p>
<p>UnFormat('a number %n and another %n',[float1, float2]); </p>
<p>So you could unpack a string into a series of variables using format strings.<... | <p>This is called scanf in C, I've made a Delphi look-a-like for this :</p>
<pre><code>function ScanFormat(const Input, Format: string; Args: array of Pointer): Integer;
var
InputOffset: Integer;
FormatOffset: Integer;
InputChar: Char;
FormatChar: Char;
function _GetInputChar: Char;
begin
if InputOffs... | <p>I tend to take care of this using a simple parser. I have two functions, one is called NumStringParts which returns the number of "parts" in a string with a specific delimiter (in your case above the space) and GetStrPart returns the specific part from a string with a specific delimiter. Both of these routines hav... | 9,829 |
<p>Right now, I have </p>
<pre><code>SELECT gp_id FROM gp.keywords
WHERE keyword_id = 15
AND (SELECT practice_link FROM gp.practices
WHERE practice_link IS NOT NULL
AND id = gp_id)
</code></pre>
<p>This does not provide a syntax error, however for values where it should return row(s), it just returns 0 ... | <p>I'm not even sure that is valid SQL, so I'm surprised it is working at all:</p>
<pre><code>SELECT gp_id
FROM gp.keywords
WHERE keyword_id = 15
AND (SELECT practice_link FROM gp.practices WHERE practice_link IS NOT NULL AND id = gp_id)
</code></pre>
<p>How about this instead:</p>
<pre><code>SELECT kw.gp_id, p.... | <pre><code>SELECT k.gp_id
FROM gp.keywords k, gp.practices p
WHERE
p.id = k.gp_id.AND
k.keyword_id = 15 AND
p.practice_link is not null
</code></pre>
| 30,303 |
<p>Ruby on Rails does not do multithreaded request-responses very well, or at least, ActiveRecord doesn't.</p>
<p>The notion of only one request-response active at the same time can be a hassle when creating web applications which fork off a shell-command that takes long to finish.</p>
<p>What I'd like are some of yo... | <p>Rails currently doesn't handle concurrent requests within a single MRI (Matz Ruby Interpreter) Ruby process. Each request is essentally wrapped with a giant mutex. A lot of work has gone into making the forthcoming Rails 2.2 thread-safe, but you're not going to get a lot of benefit from this when running under Ruby ... | <p>Ruby 1.9 is adding lightweight Fibers:</p>
<p><a href="http://www.infoq.com/news/2007/08/ruby-1-9-fibers" rel="nofollow noreferrer">http://www.infoq.com/news/2007/08/ruby-1-9-fibers</a></p>
| 15,711 |
<p>I'm looking into why a managed process is using a lot of memory. Is there a way to run <code>GC.Collect(3)</code> from WinDbg, so that I can focus on the actual memory allocation?</p>
| <p>I don't think there is any way to run a .NET garbage collection from WinDbg, but I also don't think it is necessary.</p>
<p>See <a href="https://learn.microsoft.com/en-us/archive/blogs/ricom/" rel="nofollow noreferrer">Rico Mariani's Performance Tidbits - Tracking down managed memory leaks (how to find a GC leak)</a... | <p>Hey Roger, Hopefully your memory leak is resolved by now. :-)<p>
I would first be sure that it is "managed memory leak". By that I mean that when you look at Performance Monitor counters <strong>.NET CLR Memory -> # Bytes in all heaps</strong> is increasing at the same rate as the <strong>Process -> Private Bytes... | 43,323 |
<p>Is there any way that I can programmatically create (and I guess access) hidden folders on a storage device from within c#?</p>
| <pre><code>using System.IO;
string path = @"c:\folders\newfolder"; // or whatever
if (!Directory.Exists(path))
{
DirectoryInfo di = Directory.CreateDirectory(path);
di.Attributes = FileAttributes.Directory | FileAttributes.Hidden;
}
</code></pre>
| <p>Code to get only Root folders path.</p>
<p>Like If we have C:/Test/
C:/Test/Abc
C:/Test/xyz
C:/Test2/
C:/Test2/mnp</p>
<p>It will return root folders path i.e.
C:/Test/
C:/Test2/</p>
<pre><code> int index = 0;
while (index < lst.Count)
{
My obj = lst[index];
... | 11,779 |
<p>This is the day of weird behavior.</p>
<p>We have a Win32 project made with Delphi 2007, which hosts the .NET runtime and calls into .NET to show new forms, as part of a transition period.</p>
<p>Recently we've begun experiencing exceptions at seemingly random locations and points of our code: Arithmetic overflow or... | <p>Have you added all the WMI components? As far as I know, you need all the WMI components to access the counters!</p>
<blockquote>
<p>The Performance Counter Windows Management Instrumentation (WMI) Provider component provides a bridge between the performance registry interface and the WMI interface. This componen... | <p>Have you added all the WMI components? As far as I know, you need all the WMI components to access the counters!</p>
<blockquote>
<p>The Performance Counter Windows Management Instrumentation (WMI) Provider component provides a bridge between the performance registry interface and the WMI interface. This componen... | 8,065 |
<p>I have seen another program provide traceroute functionality within it but without needing root (superuser) privileges? I've always assumed that raw sockets need to be root, but is there some other way? (I think somebody mentioned "supertrace" or "tracepath"?) Thanks!</p>
| <p>Ping the target, gradually increasing the TTL and watching where the "TTL exceeded" responses originate.</p>
| <p>If you have a modern Linux distro you can look at the source for traceroute (or tracepath, which came about before traceroute went no setuid) and tcptraceroute. None of those require RAW sockets -- checked on Fedora 9, they aren't setuid and work with default options for the normal user.</p>
<p>Using the code that ... | 10,261 |
<p>I'm working on a website that uses not just frames, but frames within frames (ew, I know, but I don't get to choose). It actually works OK most of the time, but I'm running into a problem with some of the frames within frames in Safari (only).</p>
<p>Some of the two-deep frames render in Safari with a small space ... | <pre><code>//Add to main menu
MenuItem newMenuItem1 = new MenuItem();
newMenuItem1.Header = "Test 123";
this.MainMenu.Items.Add(newMenuItem1);
//Add to a sub item
MenuItem newMenuItem2 = new MenuItem();
MenuItem newExistMenuItem = (MenuItem)this.MainMenu.Items[0];
newMenuItem2.Header = "Test 456";
newExistMenuItem.Ite... | <p>ASP.NET -> WEB Forms -> Create Menu</p>
<pre><code>CREATE TABLE `webmenu` (
`idmenu` smallint(5) NOT NULL,
`submenu` smallint(5) DEFAULT NULL,
`menu_title` varchar(45) DEFAULT NULL,
`menu_url` varchar(45) DEFAULT NULL,
`status` enum('1','0') DEFAULT '1',
PRIMARY KEY (`idmenu`)
) ENGINE=InnoDB DEFAULT CH... | 37,183 |
<p>What is the best way to copy a directory (with sub-dirs and files) from one remote Linux server to another remote Linux server? I have connected to both using SSH client (like Putty). I have root access to both. </p>
| <p>There are two ways I usually do this, both use ssh:</p>
<pre><code>scp -r sourcedir/ user@dest.com:/dest/dir/
</code></pre>
<p>or, the more robust and faster (in terms of transfer speed) method:</p>
<pre><code>rsync -auv -e ssh --progress sourcedir/ user@dest.com:/dest/dir/
</code></pre>
<p>Read the man pages fo... | <p>As non-root user ideally:</p>
<p>scp -r src $host:$path</p>
<p>If you already some of the content on $host consider using rsync with ssh as a tunnel.</p>
<p>/Allan</p>
| 9,479 |
<p>Here's the situation. I have a webservice (C# 2.0), which consists of (mainly) a class inheriting from System.Web.Services.WebService. It contains a few methods, which all need to call a method that checks if they're authorized or not.</p>
<p>Basically something like this (pardon the architecture, this is purely as... | <p>Here is what you need to do to get this to work correctly.</p>
<p>It is possible to create your own custom SoapHeader:</p>
<pre><code>public class ServiceAuthHeader : SoapHeader
{
public string SiteKey;
public string Password;
public ServiceAuthHeader() {}
}
</code></pre>
<p>Then you need a SoapExten... | <p>You can implement the so-called SOAP extension by deriving from <a href="http://msdn.microsoft.com/en-us/library/system.web.services.protocols.soapextension.aspx" rel="nofollow noreferrer">SoapExtension base</a> class. That way you will be able to inspect an incoming SOAP message and perform validate logic before a ... | 15,835 |
<p>Have you ever wanted to test and quantitatively show whether your application would perform better as a static build or shared build, stripped or non-stripped, upx or no upx, gcc -O2 or gcc -O3, hash or btree, etc etc. If so this is the thread for you. There are hundreds of ways to tune an application, but how do we... | <p>There was a talk at PyCon this week discussing the various profiling methods on Python today. I don't think anything is as complete as what your looking for, but it may be worth a look.
<a href="http://us.pycon.org/2009/conference/schedule/event/15/" rel="nofollow noreferrer">http://us.pycon.org/2009/conference/sch... | <p>I'm not sure what your question is precisely, but for profiling Java (web)applications you can use the netbeans profiler and profiler4j (available on sourceforge). I have used both and can recommend them over eclipse tptp.</p>
<p>See <a href="https://stackoverflow.com/questions/186615/how-to-set-up-eclipse-tptp">Ho... | 27,778 |
<p>This question comes out of the discussion on <a href="https://stackoverflow.com/questions/101825/whats-the-best-way-of-using-a-pair-triple-etc-of-values-as-one-value-in-c">tuples</a>.</p>
<p>I started thinking about the hash code that a tuple should have.
What if we will accept KeyValuePair class as a tuple? It do... | <p>Don't override GetHashcode() and Equals() on mutable classes, only override it on immutable classes or structures, else if you modify a object used as key the hash table won't function properly anymore (you won't be able to retrieve the value associated to the key after the key object was modified)</p>
<p>Also hash... | <blockquote>
<p>so probably it won't be aware of the hash codes of it's "children".</p>
</blockquote>
<p>Your example seems to prove otherwise :-) The hash code for the key <code>MyClass</code> and the value <code>1</code> is the same for both <code>KeyValuePair</code>'s . The KeyValuePair implementation must be u... | 12,832 |
<p>How would I implement "close all other tabs" function for a tab control using Context menu strip?</p>
| <p>I made a small app with just one tabcontrol in the main window and a context menu connected to that tabcontrol.</p>
<p>The following is the handler for the context menu item:</p>
<pre><code> private void closeAllOtherToolStripMenuItem_Click(object sender, EventArgs e)
{
for (int i = 0; i < th... | <p>Before you "close all" your tabs, you should dispose (and remove event handlers) of any controls/objects you had instantiated in each tab page. Also, you can use the .Clear method of the TabPages collection instead of removing each tab page in a loop.</p>
| 38,611 |
<p>As moving the endstop upwards reduces the range of the z-axis, I was wondering whether it reduces the maximum height of the printable object, by the distance the endstop was moved. Or is this somehow (to a certain extent) beeing counterbalanced?</p>
<p>(Follow-up question of <a href="https://3dprinting.stackexchang... | <p>If you move up the end stop such that it raises the nozzle with respect to the build platform you lose height, so basically the answer is yes. But, as seen in your referenced question, your nozzle location is determined by the mechanical layout of the printer and the end stop had to be raised in order to print at al... | <p>After adjusting the endstop check that the documented maximum height (150mm) is still achievable. Just move Z axis in the menu.</p>
| 1,078 |
<p>I got curious by <a href="http://dotnet.kapenilattex.com/?p=93" rel="nofollow noreferrer">Jon Limjap's interview mishap</a> and started to look for efficient ways to do palindrome detection. I checked the <a href="https://stackoverflow.com/questions/228518/palindrome-golf">palindrome golf</a> answers and it seems to... | <p>Given only one palindrome, you will have to do it in O(N), yes. You can get more efficiency with multi-processors by splitting the string as you said.</p>
<p>Now say you want to do exact DNA matching. These strings are thousands of characters long, and they are very repetitive. This gives us the opportunity to optim... | <p>With Python, short code can be faster since it puts the load into the faster internals of the VM (And there is the whole cache and other such things)</p>
<pre><code>def ispalin(x):
return all(x[a]==x[-a-1] for a in xrange(len(x)>>1))
</code></pre>
| 30,834 |
<p>I have the unfortunate task of fixing a legacy ASP site that was migrated to Windows Server 2003, and I know nothing about ASP. The main issue appears to be with ASPSmartUpload, of which I have version 2.3 installed. According to <a href="http://foradvice.net/smart_upload_faq.htm" rel="nofollow noreferrer">http://... | <p>We searched for quite a while before finding these dlls. </p>
<p>Here is the link for the <a href="http://www.umbrellastudio.com/how-to/aspsmartupload-dll/" rel="nofollow">ASPSMARTUPLOAD.DLL Usage</a> page that tells you how to install it and a link for downloading version 3.3. </p>
<p>From what I understand, wi... | <p>Fortunately I have a copy of the original v3.3 distribution.
I've shared it <a href="http://1drv.ms/1BhbuD5" rel="nofollow">here</a>.</p>
| 6,743 |
<p>I was given a task to display when a record in the database was added, however the previous developers never made a field for this, and I can't go back and make up dates for all the existing records. Is there an easy way to extract out a record Creation date from a <code>SQL server 2000</code> query. </p>
<pre><cod... | <p>If it's not stored as a field, the info is <em>lost</em> after the transaction log recycles (typically daily), and maybe even sooner.</p>
| <p>create another column and give it a default of getdate() that will take care of inserted date, for updated date you will need to write an update trigger</p>
| 14,179 |
<p>I've previously encountered the suggestion to call System.Threading.Thread.Sleep(0); in tights loops in C# to prevent CPU hogging and used it to good effect.</p>
<p>I have a PowerShell script that has a tight loop and I'm wondering whether I should be calling [Thread]::Sleep(0) or Start-Sleep 0 or whether the PS en... | <p>I find there are a couple of problems with explicitly yielding a thread via .Sleep() or other means when you are just making sure it doesn't take over the processor. The first is that it just makes your code look poor as it's sprinkled with Thread.Sleep(0). You can comment every instance but it doesn't look great.... | <p>I would recommend to use Thread.SpinWait(20). It works well on Intel HT boxes.
The advanced way is to check the number of CPU's and call either Sleep(0) for single CPU or SpitWait(20) otherwise</p>
| 36,259 |
<p>Background: Over the next month, I'll be giving three talks about or at least including <code>LINQ</code> in the context of <code>C#</code>. I'd like to know which topics are worth giving a fair amount of attention to, based on what people may find hard to understand, or what they may have a mistaken impression of. ... | <p>Delayed execution</p>
| <p>Something i bet almost on one knows: you can use inline ifs in a linq query. Something like this:</p>
<pre><code>var result = from foo in bars where (
((foo.baz != null) ? foo.baz : false) &&
foo.blah == "this")
select foo;
</code></pre>
<p>I would suppose you can insert lambdas as well althoug... | 26,493 |
<p>What are some macros that you have found useful in Visual Studio for code manipulation and automation? </p>
| <p>This is one of the handy ones I use on HTML and XML files:</p>
<pre><code>''''replaceunicodechars.vb
Option Strict Off
Option Explicit Off
Imports EnvDTE
Imports System.Diagnostics
Public Module ReplaceUnicodeChars
Sub ReplaceUnicodeChars()
DTE.ExecuteCommand("Edit.Find")
ReplaceAllChar(ChrW(8... | <p>You might want to add in code snippets as well, they help to speed up the development time and increase productivity.</p>
<p>The standard VB code snippets come with the default installation. The C# code snippets must be downloaded and added seperately. (Link below for those)</p>
<p>As far as macros go, I generally... | 3,584 |
<p>I'm working on a webapp, and every so often we run into situations where pages will load without applying CSS. This problem has shown up in IE6, IE7, Safari 3, and FF3.</p>
<p>A page refresh will always fix the problem.</p>
<p>There are 3 CSS files loaded, all within the same style block using @import:</p>
<pre><... | <p>I've had a similar thing happen that I was able to fix by including a base style sheet first using the "link rel" method rather than "@import". i.e. move your [base css file] inclusion to:</p>
<pre><code><link rel="stylesheet" href="[base css file]" type="text/css" media="screen" />
</code></pre>
<p>and put ... | <p>Use ab or httperf or curl or something to repeatedly load the CSS files from the webserver. Perhaps it's not consistently serving the pages.</p>
| 11,977 |
<p>In my Servlet I would like to access the root of the context so that I can do some JavaScript minifying.</p>
<p>It would be possible to do the minify as part of the install process but I would like to do it on Servlet startup to reduce the implementation cost.</p>
<p>Does anyone know of a method for getting the co... | <p>This should give you the real path that you can use to extract / edit files.</p>
<p><a href="http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/ServletContext.html#getRealPath(java.lang.String)" rel="noreferrer">Javadoc Link</a></p>
<p>We're doing something similar in a context listener.</p>
<pre><code>p... | <p>Do you mean:</p>
<pre><code>public class MyServlet extends HttpServlet {
public void init(final ServletConfig config) {
final String context = config.getServletContext();
...
}
...
}
</code></pre>
<p>Or something more complex?</p>
| 8,182 |
<p>Although this question looks simple, it is kind of tricky.</p>
<p>Consider the following table:</p>
<pre><code>CREATE TABLE A (
id INT,
value FLOAT,
"date" DATETIME,
group VARCHAR(50)
);
</code></pre>
<p>I would like to obtain the <code>ID</code> and <code>value</code> of the records that contain ... | <p>You could try with a subquery</p>
<pre>
select group, id, value, date from A where date in
( select MAX(date) as date
from A
group by group )
order by group
</pre>
| <p>As long as the Date column is unique for each group I think something like this might work:</p>
<pre><code>SELECT A.ID, A.Value
FROM A
INNER JOIN (SELECT Group, MAX(Date) As MaxDate FROM A GROUP BY Group) B
ON A.Group = B.Group AND A.Date = B.MaxDate
</code></pre>
| 49,288 |
<p>I have a database that many different client applications (a smattering of web services, some java apps and a few dot net applications) connect to. Not all of these are running on windows (Sadly, otherwise it would make this an easy answer question with just enabling windows authentication for database connections).... | <p>I'm assuming you want to hide the passwords from casual observers. If they were evil, steely eyed observers with access to all the source code on one of the machines that connects, then they can get the password with a bit of reverse engineering.</p>
<p>Remember that you do not need to use the same protection for ... | <p>Using encryption is not a good idea. If someone compromize the key he can decrypt it. Use a hash algorith with salt to store paswords. Hash algorithms are one way so its not reversible. But they are vulnerable to dictionary attacks so use salt (concatane plain text with something long and verbose than hash it). It a... | 32,244 |
<p>Take the following string as an example: </p>
<p>"The quick brown fox" </p>
<p>Right now the q in quick is at index 4 of the string (starting at 0) and the f in fox is at index 16. Now lets say the user enters some more text into this string.</p>
<p>"The very quick dark brown fox"</p>
<p>Now the q is at index ... | <p>Let's say that you have a string and some of its letters are <i>interesting</i>. To make things easier let's say that the letter at index 0 is always interesting and you never add something before it—a sentinel. Write down pairs of (interesting letter, distance to the previous interesting letter). If the strin... | <p>The standard trick that usually helps in similar situations is to keep the characters of the string as leaves in a balanced binary tree. Additionally, internal nodes of the tree should keep sets of letters (if the alphabet is small and fixed, they could be bitmaps) that occur in the subtree rooted at a particular no... | 5,680 |
<p>I have a program that needs to run as a normal user most of the time, but once in a while I need to stop and start a service. How do I go about making a program that runs as a normal user most of the time but elevates into administrator mode for some function?</p>
| <p>As far as I know, you need to start a seperate process that runs as the administrator. You can't elevate a process once it's already been started.</p>
<p>See <a href="https://stackoverflow.com/questions/78696/vista-uac-access-elevation-and-net">this question</a>.</p>
| <p>You need to use what is referred to as Impersonation..</p>
<p>[<a href="http://support.microsoft.com/kb/306158][1]" rel="nofollow noreferrer">http://support.microsoft.com/kb/306158][1]</a></p>
<p>The above shows how it would be accomplished for an ASP.Net app, but the code is probably near identical for your needs... | 30,924 |
<p>So like I sayed in the title, Why can't the Anet A6 do .05 layer height? I found that some printers can do .05 layer heights, but the Anet A6 can't? I am interested to know if it is the stepper motors or the threaded rods or something. Maybe this is something I can do a small "test print" on? </p>
| <p>I'm not familiar with the Anet A6 specifically, but as many other things in a 3D printer, the minimum layer height is co-determined by a number of factors. For the Z-axis the factors I am aware of are:</p>
<ul>
<li>The number of steps in the stepper motor</li>
<li>The geometry of the lead screw</li>
<li>The tolera... | <p>I have an Anet A6 and once you get your settings dialled in, bed level accurate and belt tensioner correct you can do 0.05 mm very well (although I for some reason went with 0.06 mm and never tried the extra 0.01 mm lower but it shouldn't have an issue). Note: I did this using all the stock parts so 0... | 846 |
<p>I'm looking for a homegrown way to scramble production data for use in development and test. I've built a couple of scripts that make random social security numbers, shift birth dates, scramble emails, etc. But I've come up against a wall trying to scramble customer names. I want to keep real names so we can stil... | <p>I use <a href="http://www.generatedata.com/" rel="noreferrer">generatedata</a>. It is an open source php script which can generate all sorts of dummy data. </p>
| <p>Frankly, I'm not sure why this is needed. Your dev/test environments should be private, behind your firewall, and not accessible from the web.</p>
<p>Your developers should be trusted, and you have legal recourse against them if they fail to live up to your trust.</p>
<p>I think the real question should be "Shoul... | 20,383 |
<p>How do I have a script run every, say 30 minutes? I assume there are different ways for different OSs. I'm using OS X.</p>
| <p>Just use <strong>launchd</strong>. It is a very powerful launcher system and meanwhile it is the standard launcher system for Mac OS X (current OS X version wouldn't even boot without it). For those who are not familiar with <code>launchd</code> (or with OS X in general), it is like a crossbreed between <code>init</... | <p>For apple scripts, I set up a special iCal calendar and use alarms to run them periodically. For command line tools, I use launchd.</p>
| 16,103 |
<p>I have an application for entering in serial numbers to a database. A serial number has a set number of attributes that defines it and the the user must/may provide them to generate.</p>
<pre><code>public class Serial
{
public string Number {get; set;}
public string Part {get; set;}
public string MfgOr... | <p>In vim, apart from adding syntax highlighting to show incorrect syntax (the "if" example would not highlight the if correctly) you can add this to your .vimrc:</p>
<pre><code>autocmd FileType sh set makeprg=bash\ -n\ '%'
autocmd FileType sh let &efm = "%E%f:\ line\ %l:\ %m," . &efm
</code></pre>
<p>Now whe... | <p>Red Hat splits up the VIM RPM's into vim-minimal, vim-enhanced and then some. You need the vim-enhanced RPM's to do syntax highlighting. As CentOS is nothing more than repackaged RHEL, the same goes for CentOS. And if it has to be for Windows: GVim is readily available.</p>
<p>You could see the syntax highlighting ... | 49,710 |
<p>Im trying to use to define a one-to-many relationship in a single table. For example lets say I have a Groups table with these entries:</p>
<pre>
Group:
Group_1:
name: Atlantic Records
Group_2:
name: Capital Records
Group_3:
name: Gnarls Barkley
Group_4:
name: Death Cab For Cutie
Group_5:
... | <p>There are a number of possible issues with this approach, but with a minimal understanding of the requirements, here goes:</p>
<p>There appear to be really three 'entities' here: Artist/Band, Label/Recording Co. and Management Co.</p>
<p>Artists/Bands can have a Label/Recording CO
Artists/Bands can have a Managem... | <p>Yes, you would need a bridge that contained the fields you described. However, I would think your table should be split if it is following the same type of entities as you describe.</p>
| 29,124 |
<p>Ideally the reader has upgraded a native C++ program to Visual Studio 2008, which contains an OpenClipboard() block. Why not try setting a breakpoint just after getting a successful return-code from OpenClipboard() and step through your code. According to the Internet it may work on your system, but of course, not... | <p>You want <code>split</code>, from the built-in <a href="https://docs.python.org/library/shlex.html" rel="noreferrer"><code>shlex</code></a> module.</p>
<pre><code>>>> import shlex
>>> shlex.split('this is "a test"')
['this', 'is', 'a test']
</code></pre>
<p>This should do exactly what you... | <p>Try this:</p>
<pre><code> def adamsplit(s):
result = []
inquotes = False
for substring in s.split('"'):
if not inquotes:
result.extend(substring.split())
else:
result.append(substring)
inquotes = not inquotes
return result
</code></pre>
<p>Some test strings:</p>
... | 10,543 |
<p>I am using SubSonic 2.1 Final but having problems running "Version" with the SubCommander. I think this problem began when I installed SQL Server 2008 on my local machine and removed 2005.</p>
<p>This is the error I get:</p>
<pre><code>ERROR: Trying to execute Version
Error Message: System.IO.FileNotFoundException... | <p>You probably have to compile SubCommander with the SqlServer 2008 version of Microsoft.SqlServer.Management.Smo dlls</p>
| <p>You probably have to compile SubCommander with the SqlServer 2008 version of Microsoft.SqlServer.Management.Smo dlls</p>
| 43,874 |
<p>I've been making a concerted effort to improve my javascript skills lately by reading as much javascript code as I can. In doing this I've sometimes seen the <code>javascript:</code> prefix appended to the front of event handler attributes in HTML element tags. What's the purpose of this prefix? Basically, is there ... | <p>Probably nothing in your example. My understanding is that <code>javascript:</code> is for anchor tags (in place of an actual <code>href</code>). You'd use it so that your script can execute when the user clicks the link, but without initiating a navigation back to the page (which a blank <code>href</code> coupled w... | <p>I don't know if the <code>javascript:</code> prefix means anything within the <code>onevent</code> attributes but I know they are annoying in anchor tags when trying to open the link in a new tab. The <code>href</code> should be used as a fall back and <strong>never</strong> to attach javascript to links.</p>
| 4,323 |
<p>Is there a version of memset() which sets a value that is larger than 1 byte (char)? For example, let's say we have a memset32() function, so using it we can do the following:</p>
<pre><code>int32_t array[10];
memset32(array, 0xDEADBEEF, sizeof(array));
</code></pre>
<p>This will set the value 0xDEADBEEF in all th... | <pre><code>void memset64( void * dest, uint64_t value, uintptr_t size )
{
uintptr_t i;
for( i = 0; i < (size & (~7)); i+=8 )
{
memcpy( ((char*)dest) + i, &value, 8 );
}
for( ; i < size; i++ )
{
((char*)dest)[i] = ((char*)&value)[i&7];
}
}
</code></pre>
<p>(Explanation, a... | <p>write your own; it's trivial even in asm. </p>
| 13,419 |
<p>I'm at the beginning/middle of a project that we chose to implement using GWT. Has anyone encountered any major pitfalls in using GWT (and GWT-EXT) that were unable to be overcome? How about from a performance perspective?</p>
<p>A couple things that we've seen/heard already include:</p>
<ul>
<li>Google not being ... | <p>I'll start by saying that I'm a massive GWT fan, but yes there are many pitfalls, but most if not all we were able to overcome:</p>
<p><strong>Problem:</strong> Long compile times, as your project grows so does the amount of time it takes to compile it. I've heard of reports of 20 minute compiles, but mine are on a... | <p>Re-using RPC service objects.<br>
It causes race conditions with symptoms that look like the app hanging.</p>
| 12,506 |
<p>Is that possible to have a single PHP SOAP server which will handle requests to several classes (services)?</p>
<p>If yes, could you please show an example implementation?</p>
<p>If not, could you please describe why?</p>
| <p>Could you wrap the other services in a single class? Completely untested, it was just a thought... </p>
<pre>
class MySoapService
{
public function __construct()
{
$this->_service1 = new Service1();
$this->_service2 = new Service2();
}
// You could probably use __call() here and intercept any cal... | <p>Another take on the same general idea (proxy class) - for php5
Uses a hash to map functions to callbacks.</p>
<pre><code>class ServiceProxy {
private $map = array();
public function addMethod($name, $callback) {
if(is_callable($callback)) {
$this->map[$name] = $callback;
... | 44,757 |
<pre><code>class Score
{
var $score;
var $name;
var $dept;
var $date;
function Score($score, $name, $dept, $date)
{
$this->scores = ($score);
$this->name = ($name);
$this->dept = ($dept);
$this->date = ($date);
}
function return_score(){
... | <p>You can't return more than once in a function. You <em>could</em> return a concatenated string:</p>
<pre><code>return $this->scores.' '.this->name.' '.$this->dept.' '.$this->date;
//added spaces for readability, but this is a silly thing to do anyway...
</code></pre>
<p>I wouldn't recommend it though a... | <p>First of all you should use public, protected or private instead of var</p>
<pre><code>var $score;
var $name;
var $dept;
var $date;
</code></pre>
<p>such as </p>
<pre><code>protected $score;
</code></pre>
<p>or with a coding standard prefix protected/private variables and methods with underscore like such</p>
<... | 40,485 |
<p>Is there a way to query or just access newly added object (using ObjectContext.AddObject method) in Entity Framework? I mean situation when it is not yet saved to data store using SaveChanges</p>
<p>I understand that queries are translated to underlying SQL and executed against data store, and it don't have this ne... | <p>In EF, if you use this code, you have all the entities that are already loaded in the context (including newly added ones) :</p>
<pre><code>context.ObjectStateManager.GetObjectStateEntries(EntityState.Added | EntityState.Modified | EntityState.Unchanged).Select(o => o.Entity).OfType<YourObjectType>()
</cod... | <p>"The same question also applies to LinqToSql."</p>
<p>For LINQ-to-SQL, look at <a href="http://msdn.microsoft.com/en-us/library/system.data.linq.datacontext.getchangeset.aspx" rel="nofollow noreferrer"><code>DataContext.GetChangeSet()</code></a>; this has <a href="http://msdn.microsoft.com/en-us/library/system.data... | 42,258 |
<p>Is there a clever way to determine which field is causing 'string or binary data would be truncated' with LINQ.</p>
<p>I've always ended up doing it manually by stepping through a debugger, but with a batch using 'SubmitChanges' I have to change my code to inserting a single row to find the culprit in a batch of ro... | <p>Fire up SQL Profiler. The last query from your application should be the one that is failing.</p>
| <p>Assuming you are processing a large batch of records and you don't want to (can't) validate the data before hand and you just want db constraints to catch any errors?</p>
<p>Change your program to catch the exception and print out the current record details to a log file or something.</p>
<pre><code>Record # 9999
... | 39,418 |
<p>I've recently bought a 3D printer and waiting for it to be delivered I've given quite a lot of time to looking things up on Thingiverse. I see people create incredible models with gears, screws, lids and a lot of very cool and functional connectors (there are some project for boxes with an iris tipe lid that can be ... | <p>The answer to your question is yes, there are tutorials to help you create better models. Unfortunately, the back-story to the answer is beyond the scope of StackExchange.</p>
<p>Don't limit yourself to Blender, especially if you are attempting to create non-organic (engineering-type) models. Blender is great for c... | <p>I think rather than looking for a tutorial at this stage, it might be instructive to watch some videos on tuning and calibration (since these touch on what is difficult). Also download Cura (or some other slicer of your choice) and look into how your existing models would be printed layer by layer. Cura has a layer ... | 431 |
<p>I have a personal pet project I'd like to start on, targeted at windows mobile 6. I've never done win mobile dev and would like to know what resources are out there, good tools to use, perhaps a jump start tutorial, as well as any gotchas I might want to keep in mind when developing for the platform?</p>
| <p>Windows Mobile 6 devices come with .NET Compact Framework 2.0 in ROM and also expose .NET APIs for a lot of things (camera, system notifications, email, contacts, ...).</p>
<p>I'd recommend using Visual Studio 2008 and the <a href="http://www.microsoft.com/downloads/details.aspx?familyid=06111A3A-A651-4745-88EF-3D4... | <p>A good reference book to check out is "Microsoft Mobile Development Handbook" by Wigley, Moth, and Foot. It covers a lot of topics in mobile development with the .NET compact framework, and also the Windows Mobile platform. </p>
<p>You also might want to learn about Windows CE, which Windows Mobile is a flavor of.... | 9,442 |
<p>I am a new user of Extjs library, I created a grid successfully and it works just fine, now I want to use Ext.grid.GridFilters to add filtering to my grid, however I don't see this class in the Extjs source code files, where I can get the required files?</p>
| <p>Filtering is a custom thing you have to implement by yourself. There are a few community add-ons which make it easy, but start by looking at the actual grid STORE instead of the grid panel. The store contains the data and supports filtering. Once the data is filtered, the store will raise it's data changed event ... | <p>There is proper filter option is provided by ExtJs:</p>
<pre><code>store.filterBy(function(rec, id)) { return (rec.get("RecName") =="FilterRecord");}
</code></pre>
<p>After filtering data, filter will always present in stores Filters config. So if we want to remove filters and show all records then just clear appl... | 36,086 |
<p>I'm working on some upgrades to an internal web analytics system we provide for our clients (in the absence of a preferred vendor or Google Analytics), and I'm working on the following query:</p>
<pre><code>select
path as EntryPage,
count(Path) as [Count]
from
(
/* Sub-query 1 */
sel... | <p>For starters,</p>
<pre><code> where pv1.Domain = isnull(@Domain, pv1.Domain)
</code></pre>
<p>won't SARG. You can't optimize a match on a function, as I remember.</p>
| <p>To continue from doofledorf. </p>
<p>Try this:</p>
<pre><code>where
(@Domain is null or pv1.Domain = @Domain) and
v1.Campaign = @Campaign
</code></pre>
<p>Ok, I have a couple of suggestions</p>
<ol>
<li><p>Create this covered index: </p>
<pre><code> create index idx2 on [PageViews]([SessionID], Domain, Cr... | 44,094 |
<p>I got a quick question about running a directX application (C++) in a managed environment. I'm attempting to write a MDI tool (in C#) where the background of the parent window would be an embedded render window of directX (C++). </p>
<p>I've read ways that involved writing the C++ into a native dll, however it woul... | <p>The easiest way to do this would be to add a C++/CLI project to your solution. This would then enable you to use the DirectX COM interfaces directly and create a managed wrapper that's easy to call from your C# code. I've taken this approach a few times and it's by far the easiest way of mixing DirectX and .Net that... | <p>First of all writing the C++ part in a different dll file doesn't mean that it couldn't be at the same solution as the C# project.</p>
<p>In order to use native DX to render on a managed window you need to pass the HWND window id (use form.WindowId.ToInt32) to the C++ D3Ddevice c'tor. after that each time you'll re... | 33,393 |
<p>I want to store a large number of sound files in a database, but I don't know if it is a good practice. I would like to know the pros and cons of doing it in this way.</p>
<p>I also thought on the possibility to have "links" to those files, but maybe this will carry more problems than solutions. Any experience in t... | <p>Every system I know of that stores large numbers of big files stores them externally to the database. You store all of the queryable data for the file (title, artist, length, etc) in the database, along with a partial path to the file. When it's time to retrieve the file, you extract the file's path, prepend some fi... | <p>The best way to storing audio/video files, you can use any distributed storage that can be local or on cloud.</p>
<p><a href="https://min.io/" rel="nofollow noreferrer">https://min.io/</a></p>
<p>for cloud:
AWS S3</p>
| 18,706 |
<p>I have the following code in a web.config file of the default IIS site.</p>
<pre><code><httpModules>
<add type="MDL.BexWebControls.Charts.ChartStreamHandler,Charts" name="ChartStreamHandler"/>
</httpModules>
</code></pre>
<p>Then when I setup and browse to a virtual directory I get this error... | <p>I've found the answer. Wrap the HttpModule section in location tags and set the inheritInChildApplications attribute to false.</p>
<pre><code><location path="." inheritInChildApplications="false">
<system.web>
<httpModules>
<add type="MDL.BexWebControls.Charts.ChartStreamHandler,Ch... | <p><a href="http://msdn.microsoft.com/en-us/library/ms178685.aspx" rel="nofollow noreferrer">According to Microsoft</a>, other websites do not inherit settings from the Default Website. Do you mean you are editing the default web.config which is located in the same folder as the machine.config?</p>
| 5,854 |
<p>I need to sanitize HTML submitted by the user by closing any open tags with correct nesting order. I have been looking for an algorithm or Python code to do this but haven't found anything except some half-baked implementations in PHP, etc.</p>
<p>For example, something like</p>
<pre><code><p>
<ul>
... | <p>using BeautifulSoup:</p>
<pre><code>from BeautifulSoup import BeautifulSoup
html = "<p><ul><li>Foo"
soup = BeautifulSoup(html)
print soup.prettify()
</code></pre>
<p>gets you</p>
<pre><code><p>
<ul>
<li>
Foo
</li>
</ul>
</p>
</code></pre>
<p>As far a... | <p>Just now, I got a html which lxml and pyquery didn't work good on , seems there are some errors in the html.
Since Tidy is not easy to install in windows, I choose <code>BeautifulSoup</code>.
But I found that:</p>
<pre><code>from BeautifulSoup import BeautifulSoup
import lxml.html
soup = BeautifulSoup(page)
h = lxm... | 37,458 |
<p>The standard answer is that it's useful when you only need to write a few lines of code ...</p>
<p>I have both languages integrated inside of Eclipse. Because Eclipse handles the compiling, interpreting, running etc. both "run" exactly the same.</p>
<p>The Eclipse IDE for both is similar - instant "compilation", i... | <p>A quick example (from <a href="http://coreygoldberg.blogspot.com/2008/09/python-vs-java-http-get-request.html" rel="noreferrer">http://coreygoldberg.blogspot.com/2008/09/python-vs-java-http-get-request.html</a>) : </p>
<p>You have a back end in Java, and you need to perform HTTP GET resquests.</p>
<p>Natively :</p... | <p>Syntax sugar.</p>
| 12,242 |
<p>It would be nice if it did both a list of methods to choose from and the list of potential input parameters. This was done for powershell and I was curious if there was any similar functionality implemented for emacs or vim?</p>
<p>Clarification:</p>
<p>A fellow developer I work with wants to use either vim or em... | <p>You can use a vim editor emulator for Visual Studio.</p>
<p><a href="http://www.viemu.com/" rel="nofollow noreferrer">http://www.viemu.com/</a></p>
| <p>Some of the suggestions in <A href="https://stackoverflow.com/questions/129257/eclipse-sytle-function-completions-in-emacs-for-c-c-and-java"><a href="https://stackoverflow.com/questions/129257/eclipse-sytle-function-completions-in-emacs-for-c-c-and-java">Eclipse Style Function Completions in Emacs for C, C++ and JAV... | 29,368 |
<p>Every morning we have a process that issues numerous queries (~10000) to DB2 on an AS400/iSeries/i6 (whatever IBM calls it nowadays), in the last 2 months, the operators have been complaining that our query locks a couple of files preventing them from completing their nightly processing. The queries are very simplis... | <p>Try adding "FOR READ ONLY" to the query then it won't lock records as you retrieve them.</p>
| <p>Writes to the files on the AS/400 side from an RPG/COBOL/JPL job program will cause a file lock (by default I think). The job will be unable to get this lock when you are reading. The solution we used was ... don't read the files when jobs are running. We created a big schedule sheet in excel and put all the sql ser... | 25,285 |
<p>I have a table that has, in essence, this structure:</p>
<pre> key value
------ ------
2 val1
3 val2
5 val3</pre>
<p>The keys are sequential integers from 1 up to (currently) 1 million, increasing by several thousand each day. Gaps in the keys occur when records have been ... | <p>SQL queries have no looping mechanism. Procedure languages have loops, but queries themselves can only "loop" over data that they find in a table (or a derived table).</p>
<p>What I do to generate a list of numbers on the fly is to do a cross-join on a small table of digits 0 through 9:</p>
<pre><code>CREATE TABL... | <p>In MySQL you can find the edges of the gaps by performing left joins against itself with positive and negative offsets.</p>
<p>Eg:</p>
<pre><code>create table seq ( i int primary key, v varchar(10) );
insert into seq values( 2, 'val1' ), (3, 'val2' ), (5, 'val3' );
select s.i-1 from seq s left join seq m on m.i... | 40,173 |
<p>This question is a follow-up to a question I asked the other day <a href="https://stackoverflow.com/questions/302022/sql-need-to-find-duplicate-records-but-exclude-reversed-transactions">("Need to find duplicate records but exclude reversed transactions")</a>.</p>
<p>I have a Crystal Report which displays customers... | <p>Does the reversals always sort to the bottom? If so you can use a formula to check the Next record and conditionally hide the detail section.</p>
<p>So in the detail section add a formula to conditionally suppress the section if it is a reversal record or if the current record matches a subsequent reversal record:... | <p>Is it too late to change the data model slightly, so that reversing and reversed records and flagged in some way? I once worked on such a system where records were inserted with a flag of 'C' (current) and if reversed were updated to 'O' (original), and the reversal record was marked as 'R'. All queries that only ... | 40,656 |
<p>I often get a PDF from our designer (built in Adobe InDesign) which is supposed to be sent out to thousands of people.</p>
<p>I've got the list with all the people, and it's easy doing a mail merge in OpenOffice.org. However, OpenOffice.org doesn't support the advanced PDF. I just want to output some text onto each... | <p>Now I've made an account. I fixed it by using the ingenious pdftk.</p>
<p>In my quest I totally overlook the feature "background" and "overlay". My solution was this:</p>
<pre><code>pdftk names.pdf background boat_background.pdf output out.pdf
</code></pre>
<p>Creating the <code>names.pdf</code> you can easily do... | <p>You can use InDesign's data merge function, or you can do what you've been doing with printing a portion of the job, and then printing the mail merge atop that with Word or Open Office.
But also look into finding a company that can do variable data offset printing or dynamic publishing. Might be a little more expen... | 46,481 |
<p>I'd like to compare two consecutive elements in a std::list while iterating through the list. What is the proper way to access element i+1 while my iterator is at element i?
Thanks
Cobe</p>
| <p>STL provide the adjacent_find() algorithm that can be used to find two consecutive equal elements. There is also a version with a custom predicate.</p>
<p>These are the prototypes:</p>
<pre><code>template <class ForwardIterator>
ForwardIterator adjacent_find ( ForwardIterator first, ForwardIterator last )... | <pre><code>for (list<int>::iterator it = test.begin(); it!=test.end(); it++) {
cout<<*it<<":\t";
list<int>::iterator copy = it;
for( list<int>::iterator it2 = ++copy; it2!=test.end();it2++){
cout<<*it2<<"\t";
}
cout<<en... | 32,662 |
<p>I've used a tool from Aspose (<a href="http://www.aspose.com/categories/file-format-components/aspose.pdf.kit-for-.net-and-java/default.aspx" rel="noreferrer">Aspose.PDF.kit</a>) to generate a JPG thumbnail on the fly of a PDF for a .NET application. This works great, but what kind of other alternatives are there?... | <p>Using Itext to create Thumbnails of PDFS</p>
<p><a href="http://threebit.net/mail-archive/itext-questions/msg00436.html" rel="nofollow noreferrer">http://threebit.net/mail-archive/itext-questions/msg00436.html</a></p>
<p>I would recommend iTextSharp so you don't need the java redistributable</p>
| <p>I absolutely despise working with PDF documents. But when I absolutely have to, I have been using <a href="http://itextsharp.sourceforge.net/" rel="nofollow noreferrer">iTextSharp</a>. It has quite a bit of functionality, <a href="http://itext.ugent.be/library/api/" rel="nofollow noreferrer">the API is fairly well... | 24,192 |
<blockquote>
<p><strong>Possible Duplicate:</strong><br>
<a href="https://stackoverflow.com/questions/295579/fastest-way-to-determine-if-an-integers-square-root-is-an-integer">Fastest way to determine if an integer's square root is an integer</a> </p>
</blockquote>
<p>What's a way to see if a number is a <a... |
<pre class="lang-cs prettyprint-override"><code>bool IsPerfectSquare(long input)
{
long closestRoot = (long) Math.Sqrt(input);
return input == closestRoot * closestRoot;
}
</code></pre>
<p>This may get away from <em>some</em> of the problems of just checking "is the square root an integer" but possibly not a... | <p>In Common Lisp, I use the following:</p>
<pre class="lang-lisp prettyprint-override"><code>(defun perfect-square-p (n)
(= (expt (isqrt n) 2)
n))
</code></pre>
| 44,719 |
<p>I have an existing ASP.NET 2.0 website, stored in Team Foundation Server 2005. Some of the pages/controls are encoded as ANSI (according to Notepad++) and the Content-Type header is set to:</p>
<pre><code><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"/>
</code></pre>
<p>I would lik... | <p>It depends on how much of the text in your codebase is using characters outside the ASCII range of 0..127.</p>
<p>You might want to scan for those first, to see how much impact it will have. If your codebase is primarily in English, then you probably don't have much to worry about.</p>
| <p>Something useful I just discovered is that you can right-click on a file on Source Control Explorer, then choose Properties. You can then see/modify the encoding as far as TFS is concerned.</p>
| 41,914 |
<p>Assuming you have a high quality printer with a fast processor, will you see a noticeable improvement by upgrading from 16X/32X microstepping drivers to 64X/128X microstepping drivers? (e.g. smoother surface finish). In what ways do they perform differently from the more common 16X or 32X stepper drivers. I'm thin... | <p>You will likely not see a noticeable improvement by upgrading from a 16x or 32x to a 64x or 128x microstepping driver. Depending on the motors you're driving and the size of the load you could actually see a decrease in quality.</p>
<p>Although microstepping increases theoretical resolution it does not necessarily ... | <p>Prints benefit from higher microstepping in two ways:</p>
<p><strong>Noise level</strong></p>
<p>Using microstepping reduces noise from your printer's operation.</p>
<p><strong>Print quality</strong></p>
<p>Using higher resolution microstepping does not increase the physical accuracy of your prints meaningfully,... | 112 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.