instruction stringlengths 21 27.8k | chosen stringlengths 18 28.2k | rejected stringlengths 18 33.6k | __index_level_0__ int64 0 50k |
|---|---|---|---|
<pre><code>something.each do |x|
#lots of stuff
end if some_condition
</code></pre>
| <p>I think the popular way is to <strong>use statement modifiers only if it is a one-liner</strong>.
In all other cases, use the normal if style prevalent in C, Java etc.</p>
<pre><code>bail_out if reqd_param.nil?
if its_gonna_be_long then
long_exec stmt1
long_exec stmt2
....
end
</code></pre>
| <p>In the organization I work for we have started to flag such constructs for re-write.</p>
| 25,641 |
<p>Are there any good online resources for how to create, maintain and think about writing test routines for numerical analysis code?</p>
<p>One of the limitations I can see for something like testing matrix multiplication is that the obvious tests (like having one matrix being the identity) may not fully test the fun... | <p>It sounds as if you need to think about testing in at least two different ways:</p>
<ol>
<li><p>Some numerical methods allow for some meta-thinking. For example, invertible operations allow you to set up test cases to see if the result is within acceptable error bounds of the original. For example, matrix <em>M-i... | <p>Check out a book by <a href="http://en.wikipedia.org/wiki/David_Gries" rel="nofollow noreferrer">David Gries</a> called <a href="https://rads.stackoverflow.com/amzn/click/com/0387964800" rel="nofollow noreferrer" rel="nofollow noreferrer">The Science of Programming</a>. It's about proving the correctness of programs... | 3,714 |
<p>I have been learning C++ for a while now, I find it very powerful. But, the problem is the the level of abstraction is not much and I have to do memory management myself.
What are the languages that I can use which uses a higher level of abstraction.</p>
| <p>Java, C#, Ruby, Python and JavaScript are probably the big choices before you.</p>
<p><a href="http://en.wikipedia.org/wiki/Java_(programming_language)" rel="noreferrer">Java</a> and <a href="http://en.wikipedia.org/wiki/C_Sharp" rel="noreferrer">C#</a> are not hugely different languages. This big difference you'll... | <p>Since you are already into C++, next step would be to learn .Net through <a href="http://www.ondotnet.com/pub/a/dotnet/2003/01/13/intromcpp.html" rel="nofollow noreferrer">managed C++</a> or managed extensions for C++..this will get you a step in the big world of .Net framework..Once you understand the framework, ma... | 8,623 |
<p>I have some XML in an XmlDocument, and I want to display it on an ASP.NET page. (The XML should be in a control; the page will have other content.) Right now, we're using the Xml control for that. Trouble is, the XML displays with no indentation. Ugly.</p>
<p>It appears that I'm supposed to create an XSLT for i... | <p>You could try to use XmlWriter/XmlTextWriter, set the writer's Indentation property, write to a StringBuilder or MemoryStream, and output the result inside a <pre> tag</p>
| <p>You can find a slightly modified version of the XSLT that IE uses to transform XML to HTML when viewing in IE at <a href="http://www.dpawson.co.uk/xsl/sect4/N10301.html#d15977e117" rel="nofollow noreferrer">http://www.dpawson.co.uk/xsl/sect4/N10301.html#d15977e117</a>.</p>
<p>I have used it in a WebBrowser control ... | 45,597 |
<p>Does anyone have an XSLT that will take the app.config and render it into a non-techie palatable format?</p>
<p>The purpose being mainly informational, but with the nice side-effect of validating the XML (if it's been made invalid, it won't render)</p>
| <p>First draft at a solution to show</p>
<ul>
<li>Connection Strings</li>
<li>App Settings</li>
</ul>
<p>Whack this in the app.config:</p>
<pre><code><?xml-stylesheet type="text/xsl" href="display-config.xslt"?>
</code></pre>
<p>And this is the contents of display-config.xslt:</p>
<pre><code><?xml version... | <p>What type of conversion are you looking for? Just for informational purposes? What level of detail are you looking to transform?</p>
| 22,100 |
<p>Let's say that we have an ARGB color:</p>
<pre><code>Color argb = Color.FromARGB(127, 69, 12, 255); //Light Urple.
</code></pre>
<p>When this is painted on top of an existing color, the colors will blend. So when it is blended with white, the resulting color is <code>Color.FromARGB(255, 162, 133, 255);</code></p>
... | <p>It's called <a href="http://en.wikipedia.org/wiki/Alpha_compositing" rel="noreferrer">alpha blending</a>.</p>
<p>In psuedocode, assuming the background color (blend) always has 255 alpha. Also assumes alpha is 0-255.</p>
<pre><code>alpha=argb.alpha()
r = (alpha/255)*argb.r() + (1 - alpha/255)*blend.r()
g = (alpha/... | <p>if you don't need to know this pre-render, you could always use the win32 method of getpixel, I believe. </p>
<p>Note: typing on iPhone in the middle of Missouri with no inet access. Will look up real win32 example and see if there is a .net equivalent.</p>
<p>In case anyone cares, and doesn't want to use the (exc... | 2,490 |
<p>This is a continuation of <a href="https://3dprinting.stackexchange.com/questions/19523/filament-not-being-extruded">this question</a> where comments and answers were extremely helpful in diagnosing the issue, which I am still unable to solve.</p>
<p>I determined I have the problem shown in figure 3 on <a href="http... | <p>Yes.</p>
<p>The issue is, that there are small gaps between the layers. But you can coat the print in an airtight material. While epoxy and similar materials work very well, they are somewhat too viscous and take a long time to cure.</p>
<p>My special recipe for coating PLA prints with a fast-curing airtight thin la... | <p>Yes.</p>
<p>The issue is, that there are small gaps between the layers. But you can coat the print in an airtight material. While epoxy and similar materials work very well, they are somewhat too viscous and take a long time to cure.</p>
<p>My special recipe for coating PLA prints with a fast-curing airtight thin la... | 2,166 |
<p>I have asked our hosting provider to add mod_python to our httpd server. The server appears to be in an hsphere cluster and they appear to use yum to administer it. He is reporting some dependencies missing and I do't quite understand how that could have come about.</p>
<p>versions (this is as much as I have been... | <p>We have mod_python 3.3 running on Apache 2.2 on a CentOS (forgot the version). All we did is download the tar.gz (from <a href="http://httpd.apache.org/modules/python-download.cgi" rel="nofollow noreferrer">http://httpd.apache.org/modules/python-download.cgi</a>) , extract it...</p>
<pre><code>$ ./configure --with-... | <p>My first reaction would be to <code>yum update apache</code> (or just a <code>yum update</code>). </p>
<p>Then try the <code>yum install mod_python</code>.</p>
| 20,100 |
<p>FCKeditor has InsertHtml API (<a href="http://docs.fckeditor.net/FCKeditor_2.x/Developers_Guide/JavaScript_API" rel="nofollow noreferrer">JavaScript API document</a>) that inserts HTML in the current cursor position. How do I insert at the very end of the document?</p>
<p>Do I need to start browser sniffing with so... | <p>It looks like you could use a combination of GetHTML and SetHTML to get the current contents, append your html and reinsert everything into the editor. Although it does say </p>
<blockquote>
<p>Note that when using this method, you will lose any listener that you may have previously registered on the editor.Edito... | <pre><code>var oEditor = FCKeditorAPI.GetInstance('Editor_instance') ;
OldText=oEditor.GetXHTML( true );
oEditor.SetData( OldText+"Your text");
</code></pre>
| 4,487 |
<p>I broke 2 keys (i.e. left ctrl, enter) on my Asus UX31A laptop and it seems that this model is too old to find replacement keys.</p>
<p>Is there any way I can find a 3D model of the needed keys to have them 3D printed?</p>
<p>I do not have a printer nor I have any experience in this field.
What I need is either some... | <p>This is more off-topic as an answer, but serves as a possible solution.</p>
<p>Replacementlaptopkeys.com is a resource that appears to have keycaps for the model you've noted.</p>
<p><a href="https://www.replacementlaptopkeys.com/asus-zenbook-ux31a-db71-laptop-keys-replacement-dark-brown-black/" rel="nofollow norefe... | <p>You're better off if you can get the key from Fred's link. I was impressed by the detail of a 3D-printed battery cover for electronic calipers, but I'm sure it took much work to get it right. Also, ebay has keyboards for your model.</p>
| 1,943 |
<p>I'm using a <code>BindingList<T></code> in my Windows Forms that contains a list of "<code>IComparable<Contact></code>" Contact-objects. Now I'd like the user to be able to sort by any column displayed in the grid.</p>
<p>There is a way described on MSDN online which shows how to implement a custom coll... | <p>I higly appreciate <a href="https://stackoverflow.com/a/281324/3834">Matthias' solution</a> for its simplicity and beauty.</p>
<p>However, while this gives excellent results for low data volumes, when working with large data volumes the performance is not so good, due to reflection.</p>
<p>I ran a test with a coll... | <p>Not for custom objects. In .Net 2.0, I had to roll my on sorting using BindingList. There may be something new in .Net 3.5 but I have not looked into that yet. Now that there is LINQ and the sorting options that come with if this now may be easier to implement.</p>
| 31,062 |
<p>Here's a simplified version of my scenario:</p>
<ul>
<li>I have a table named <strong>Project</strong> that I reference via an 'id' field.</li>
<li>I have a table named <strong>Photo</strong> that has a field named 'project_id' which I use to relate multiple photos to a single project. The Photo table also has an a... | <p>For the "last n items" problem in MySQL, take look here: <a href="https://stackoverflow.com/questions/271730/how-to-select-maximum-3-items-per-users-in-mysql">How to select maximum 3 items per users in MySQL?</a> (it's right in the top answer).</p>
<p>When you take it from there, all you are missing is a JOIN with ... | <pre><code>SELECT project.*, photo.*
FROM photo
LEFT JOIN project USING project_id
WHERE photo.project_id = '{$id}'
ORDER BY photo_id DESC
LIMIT project.project_photos_limit
</code></pre>
<p>Try that? (with your fieldnames, obviously)</p>
| 40,526 |
<p>We've installed Windows Search Server Express on one of our servers, which apparently runs on top of sharepoint.</p>
<p>Sharepoint was installed on port 80, where our "normal" intranet runs. When I disable the intranet and run the sharepoint site, everything works as intended. The intranet is linked in many places... | <p>Sharepoint sites should be able to run on any port- if you go into Sharepoint Central Admin and create or delete web applications without a problem.</p>
<p>Is it your intention to run heterogenously with Sharepoint and your regular site both on Port 80? I know that you can create a web application on 80 and then no... | <p>Thank you! I found the option in the sharepoint administration website.</p>
<p>I add this response to detail the steps I have taken - maybe they are useful for someone else.</p>
<p>In the sharepoint administration website (running flawlessly on another port), I chose "create or extend web applications", then "exte... | 34,193 |
<p>Doesn't an ORM usually involve doing something like a select *?</p>
<p>If I have a table, MyThing, with column A, B, C, D, etc, then there typically would be an object, MyThing with properties A, B, C, D. </p>
<p>It would be evil if that object were incompletely instantiated by a select statement that looked lik... | <p>In my limited experience, things are as you describe--it's a messy situation and the usual cop-out "it depends" answer applies.</p>
<p>A good example would be the online store that I work for. It has a <code>Brand</code> object, and on the main page of the Web site, all of the brands that the store sells are listed... | <p>SELECT * is not bad. Did you ask whoever considered it to be bad "why?".</p>
| 37,230 |
<p>I'm storing a Word document in a SQL Server 2005 database in a varbinary(max) column. Is there a way to open this document from a VB.NET Windows Forms application without serialising to a file first (i.e. directly from the byte array I've read from the database)?</p>
| <p>Depends on what's reading it. If it's Word, you'll probably have to serialize to a file, but if it's a function or library that can take an IO.Stream then you could wrap a new MemoryStream around the byte array and pass that.</p>
| <p>Not really. You need to treat it like an e-mail attachment, where the file is generally copied to a temp folder that is cleaned out periodically.</p>
| 8,103 |
<p>I'm using the <a href="http://msdn.microsoft.com/en-us/library/ms178329.aspx" rel="nofollow noreferrer">ASP.NET Login Controls</a> and <a href="http://msdn.microsoft.com/en-us/library/aa480476.aspx" rel="nofollow noreferrer">Forms Authentication</a> for membership/credentials for an ASP.NET web application. It keep... | <p>Use the LoginUrl property for the forms item?</p>
<pre><code><authentication mode="Forms">
<forms defaultUrl="~/Default.aspx" loginUrl="~/login.aspx" timeout="1440" ></forms>
</authentication>
</code></pre>
| <p>I found the answer at <a href="http://www.codersource.net/asp_net_forms_authentication.aspx" rel="nofollow noreferrer">CoderSource.net</a>. I had to put the correct path into my web.config file.</p>
<pre><code><?xml version="1.0"?>
<configuration>
<system.web>
...
<!--
... | 5,308 |
<p>I have XML files in a directory that I wish to get over to a webservice on a server that will validate them and return a true/false as to whether they are valid in construct and values etc.
Reason for server side processing is that the validation rules may change from time to time and need to adjust in one place as ... | <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,238 |
<p>I have a batch process that reads data from multiple tables into a dataset based on a common key. I then build a second dataset of the destination data querying on the same key. </p>
<p>At this point I have two Datasets that are structurally identical (from a table/column layout perspective). I then have a proces... | <p>profile the db and see what queries are being fired. copy the queries from Profiler and try to exe them manually. if they fail, then the problem is with the sql and the error is coming from the db and simply being passed up to your application.</p>
<p>this should at least tell u if the problem is caused by the lack... | <p>you have to set the PK for each table in the dataset like you did.
i don't think there's a way for adapter to figure out what the PK's are by itself.
if there is and someone knows it i'm all ears.</p>
| 35,171 |
<p>Why does this work:</p>
<pre><code>$(window).keydown(function(event){
alert(event.keyCode);
});
</code></pre>
<p>but not this:</p>
<pre><code>$('#ajaxSearchText').keydown(function(event){
alert(event.keyCode);
});
</code></pre>
<p>I'm testing with Firefox 3.
Interestingly, neither of them work in IE7.</p... | <p>Checked this in Chrome, IE7 and Firefox 3.0.3. Works as it should. jQuery version 1.2.6.</p>
<pre><code><html>
<head>
<script type="text/javascript" src="jquery-1.2.6.js"></script>
<script type="text/javascript">
$(function()
{
$("#ajaxSearchText").ke... | <p>Because key events are not supported on the 'window' object.</p>
<p><a href="http://www.w3schools.com/jsref/obj_window.asp" rel="nofollow noreferrer">http://www.w3schools.com/jsref/obj_window.asp</a></p>
<p>But only on 'document':</p>
<p><a href="http://www.w3schools.com/jsref/dom_obj_event.asp" rel="nofollow nor... | 22,673 |
<p>I am wondering if Unittesting and using statements can really go hand in hand as there is no way to mock the disposable object instantiated in the using statement. How would I be able to effectively unittest a method containing the following using statement?</p>
<pre>
public void MyMethod()
{
using(MyDisposableC... | <p>No, using statements are certainly not forbidden. But what does MyDisposableClass actually do? It strikes me that this isn't really a matter of the using statement being a problem - it's a matter of the method creating a new object which you want to mock - <em>that's</em> the problem.</p>
<p>Do you genuinely need t... | <p>Using the <a href="http://en.wikipedia.org/wiki/Factory_method_pattern" rel="nofollow noreferrer">factory pattern</a> and/or <a href="http://en.wikipedia.org/wiki/Dependency_injection" rel="nofollow noreferrer">dependency injection pattern</a> will greatly simplify the way you unit test methods that instantiate thei... | 46,802 |
<p>I have Java 1.5.0 installed on a Mac OS machine. I have the Java Embedding Plugin 0.9.6.4 installed and java enabled on the preferences panel. When I go to <a href="http://java.com/en/download/help/testvm.xml" rel="nofollow noreferrer">http://java.com/en/download/help/testvm.xml</a> the applet appears blank. Does an... | <p>I have found the solution. The Java Embedding Plugin uses the installed JVM which itself gets its proxy definitions from MacOS and not from Firefox. So, proxy definitions have to be defined for both MacOS/Safari and Firefox.
I've also updated Firefox and selected Java 1.5 on the Java preferences panel. However I'm n... | <p>Firefox 3.0.1 on Mac OS X 10.5 should support java applets without any extra Java Embedding Plugin.</p>
| 15,525 |
<p>Is it possible to use a variable from one page in a piece of code on another? e.g. submit a form on one page and on the second page use a PHP script to add the data from the form to a MySQL table</p>
<p>Thanks for all the help </p>
| <p>This is what the GET and POST 'super' globals are for.
<a href="http://www.tizag.com/phpT/postget.php" rel="nofollow noreferrer">http://www.tizag.com/phpT/postget.php</a></p>
| <p>The script that generates the form does not have to be the script the processes the form. all it takes is for the FORM tag to point to the correct script. The only caveat is that whatever page you submit the form data to also has to then generate some suitable output (unless you do a AJAX POST).</p>
<p>If you're in... | 27,692 |
<p>I am trying to do the following in ASP.NET 3.5. Basically, I am binding a LINQDataSource to a DataList. There is a property called "Deleted" and if it is true, I want to display different markup. The following code throws errors:</p>
<pre><code><asp:DataList runat="server">
<ItemTemplate>
... | <p>I might suggest keeping the code-front lean and writing out the desired text via a function result:</p>
<pre><code><asp:DataList runat="server">
<ItemTemplate>
<%# GetText(Container.DataItem) %>
</ItemTemplate>
</asp:DataList>
</code></pre>
<p>And the code-behind:</p>... | <p>Perhaps use the ItemDataBound event of a datalist. For gridview's its the rowdatabound event that is ideal for altering display of values based on other values in the result set.
<a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.datalist.itemdatabound.aspx" rel="nofollow noreferrer">ItemData... | 33,117 |
<p>I need to create a custom volume slider for a WMP object. The current slider is complicated to modify, and use, is there a simple way to generate a slider on an HTML page that can have it's value passed to a javascript function?</p>
| <p><a href="http://jqueryui.com/demos/slider/" rel="noreferrer">jQuery UI Slider</a> (<a href="http://docs.jquery.com/UI/Slider" rel="noreferrer">API docs</a>)</p>
| <p>The code below should be enough to get you started. Tested in Opera, IE and Chrome.</p>
<pre><code><script>
var l=0;
function f(i){
im = 'i' + l;
d=document.all[im];
d.height=99;
document.all.f1.t1.value=i;
im = 'i' + i;
d=document.all[im];
d.height=1;
l=i;
}
</script>
<center>
<form id='f1'>... | 20,850 |
<p>C++ 0x has template aliases (sometimes referred to as template typedefs). See <a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Alias_templates" rel="noreferrer">here</a>. Current spec of C++ does not. </p>
<p>What do you like to use as work around ? Container objects or Macros ?
Do you feel its worth it ?</p>
| <blockquote>
<p>What do you like to use as work around ? Container objects or Macros ? Do you feel its worth it ?</p>
</blockquote>
<p>The canonical way is to use a metafunction like thus:</p>
<pre><code>template <typename T>
struct my_string_map {
typedef std::map<std::string, T> type;
};
// Invok... | <p>Sometimes you can just explicitly write out the untemplated typedefs for all the necessary types. If the base class is templated on multiple template args with only one type desired to be typedefed you can inherit a specialized class with typedef effectively included in the inherited class name. This approach is les... | 4,576 |
<p>I'm working on the K&R book. I've read farther ahead than I've done exercises, mostly for lack of time. I'm catching up, and have done almost all the exercises from chapter 1, which is the tutorial.</p>
<p>My issue was exercise 1-18. The exercise is to:</p>
<blockquote>
<p>Write a program to remove trailing ... | <p>There is no reason to have two buffers, you can trim the input line in place</p>
<pre><code>int trim(char line[])
{
int len = 0;
for (len = 0; line[len] != 0; ++len)
;
while (len > 0 &&
line[len-1] == ' ' && line[len-1] == '\t' && line[len-1] == '\n')
... | <p>First of all:</p>
<blockquote>
<p>int main(void)</p>
</blockquote>
<p>You know the parameters to main(). They're nothing. (Or argc&argv, but I don't think that's Chapter 1 material.)</p>
<p>Stylewise, you might want to try K&R-style brackets. They're much easier on the vertical space:</p>
<pre><code>vo... | 19,574 |
<p>Lets say I have a web app which has a page that may contain 4 script blocks - the script I write may be found in one of those blocks, but I do not know which one, that is handled by the controller. </p>
<p>I bind some <code>onclick</code> events to a button, but I find that they sometimes execute in an order I did ... | <p>If order is important you can create your own events and bind callbacks to fire when those events are triggered by other callbacks.</p>
<pre><code>$('#mydiv').click(function(e) {
// maniplate #mydiv ...
$('#mydiv').trigger('mydiv-manipulated');
});
$('#mydiv').bind('mydiv-manipulated', function(e) {
//... | <p>JQuery 1.5 introduces promises, and here's the simplest implementation I've seen to control order of execution. Full documentation at <a href="http://api.jquery.com/jquery.when/" rel="nofollow">http://api.jquery.com/jquery.when/</a></p>
<pre><code>$.when( $('#myDiv').css('background-color', 'red') )
.then( alert('... | 36,993 |
<p>I have read the post <a href="http://www.julienlecomte.net/blog/2007/10/28/" rel="noreferrer">here</a> about using setTimeout() during intensive DOM processing (using JavaScript), but how can I integrate this function with the below code? The below code works fine for a small number of options, but when the number o... | <p>Here is a solution:</p>
<pre><code>function appendToSelect() {
$("#mySelect").children().remove();
$("#mySelect").html(
'<option selected value="'+obj.data[0].value+'">'
+ obj.data[0].name
+ '</option>'
);
obj.data.splice(0, 1); // we only want remaining data
var appendOptions = fu... | <p>You would need to rewrite the function to cache the element list, then loop over the list using a counter of some sort.</p>
<p>Then when the counter reaches counter % max_num_before_wait == 0, call timeout back to the function itself.</p>
<p>Make sure to clear the cache and counter at the end of the complete list,... | 25,886 |
<p>I have a .NET assembly which I have exposed to COM via a tlb file, and an installer which registers the tlb. I have manually checked that the installer works correctly and that COM clients can access the library. So far, so good...</p>
<p>However, I am trying to put together some automated system tests which check ... | <p>The Closest I've gotten to a solution is something like the following:</p>
<pre><code>using System;
class ComClass
{
public bool CallFunction(arg1, arg2)
{
Type ComType;
object ComObject;
ComType = Type.GetTypeFromProgID("Registered.ComClass");
// Create an instance of your ... | <p>Using <a href="http://msdn.microsoft.com/en-us/library/tt0cf3sx(VS.80).aspx" rel="nofollow noreferrer">tlbimp.exe</a> you can generate an assembly from your COM component that can be used in .NET code</p>
| 48,037 |
<p>I'm trying to find out the most efficient (best performance) way to check date field for current date. Currently we are using:</p>
<pre><code>SELECT COUNT(Job) AS Jobs
FROM dbo.Job
WHERE (Received BETWEEN DATEADD(d, DATEDIFF(d, 0, GETDATE()), 0)
AND DATEADD(d, DATEDIFF(d, 0,... | <pre><code>WHERE
DateDiff(d, Received, GETDATE()) = 0
</code></pre>
<p>Edit: As lined out in the comments to this answer, that's not an ideal solution. Check the other answers in this thread, too. </p>
| <p>that's pretty much the best way to do it.
you could put the DATEADD(d, DATEDIFF(d, 0, GETDATE()), 0) and DATEADD(d, DATEDIFF(d, 0, GETDATE()), 1) into variables and use those instead but i don't think that this will improve performance.</p>
| 42,212 |
<p>How do I make an MD5 hash of a string with Delphi?</p>
| <p>If you want an MD5 digest and have the <a href="http://www.indyproject.org" rel="nofollow noreferrer">Indy</a> components installed, you can do this:</p>
<pre><code>uses SysUtils, IdGlobal, IdHash, IdHashMessageDigest;
with TIdHashMessageDigest5.Create do
try
Result := TIdHash128.AsHex(HashValue('Hello, world'... | <p>Using ICS, you simply call StrMD5 function which is located in OverbytecsMD5 unit.</p>
<p>Beside that specific function, there are a lot more MD5 function for other datatypes and scenarios. There are also other hash methods such as SHA.</p>
| 8,302 |
<p>I have a COM interop assembly, and I would like to check from a .NET application whether the component I'm about to create is installed on the machine. </p>
<p>I would like to provide a nice error message if it is not installed.</p>
<p>Put the instantiation into try-catch is not a good solution for me, as I would ... | <p>I think the best way, unfortunately, is to try and instantiate it. Checking in the registry does not guarantee that the component is actually there at all (e.g. the file may have been deleted or moved post registration).</p>
| <p>You might also instantiate an object of the com class you want to check in a try/catch block so as to warn your user in the catch block. Blunt solution, I agree.</p>
<p>Checking the registry seems the most reasonable approach to me, as an unregistered com component is pretty useless.</p>
| 38,233 |
<p>Is there a setting in ReSharper 4 (or even Visual Studio itself...) that forces a warning if I forget to wrap code in a <code>using</code> block, or omit the proper Dispose call in a <code>finally</code> block?</p>
| <p>Correct automatic Dispose analysis requires DFA (Data Flow Analysis) in a global way. It is unlikely that you create an IDisposable object and doesn't call any method on it and do not pass it around as an argument. If disposable object is passed to other methods (including calling its members, when "this" is implici... | <p>You could design a small add-in to R# that you could have run inside the code editor that scans the code and updates the code analysis to reflect that you an object who's missing the structure you've just described. </p>
<p>I'd look into the R# plugin architecture if you decide to go that route.</p>
| 12,713 |
<p>Is there any way that I can change how a Literal of a code snippet renders when it is used in the code that the snippet generates?</p>
<p>Specifically I'd like to know if I can have a literal called say, $PropertyName$ and then get the snippet engine to render "_$PropertyName$ where the first character is made lowe... | <p>Unfortunately there seems to be no way. Snippets offer amazingly limited support for <a href="http://msdn.microsoft.com/en-us/library/ms242312(VS.80).aspx" rel="noreferrer">transformation functions</a> as you can see.</p>
<p>You have to stick with the VS standard solution, which is to write two literals: one for th... | <p>a "fix" may be to use a prefix in the naming or the member variable, i.e.:</p>
<pre><code>string m_$name$;
string $name$
{
get{return m_$name$;}
set{m_$name$=value;}
};
</code></pre>
| 19,904 |
<p>I need to understand a good way to design a web page with dynamically updated graphs. It should be something close to what stock market graphs look like (e.g. <a href="http://finance.google.com/finance?q=NASDAQ%3AGOOG" rel="nofollow noreferrer">Google Finance</a>), although with a bit more complicated functionality,... | <p>I have used the <a href="http://code.google.com/apis/chart/" rel="nofollow noreferrer">Google Charts API</a> to do this sort of thing. For a simple example, see my <a href="http://hewgill.com/sunriseset/" rel="nofollow noreferrer">Sunrise and Sunset</a> page. This page calculates sunrise and sunset times for a given... | <p>I'm not sure about the Flash side of things, but this would be pretty simple to do in Silverlight. I am pretty sure you'd easily be able to make a server request in Flash too.</p>
<p>I'd do some searching for long polling.</p>
| 40,887 |
<p>I have an web application using asp.net 2.0 and vb.net I wrote a bat file to use GPG to encryt a file and call it whithin asp.net shell(pathname & filename).
when I double click on the bat file from cmd windows it works fine but when I call it in the application everything command that I pass is executed perfect... | <p>I had a similar problem:</p>
<p><a href="https://stackoverflow.com/questions/34183/cnet-why-is-my-processstart-hanging">C#.Net: Why is my Process.Start() hanging?</a></p>
<p>It seems that Microsoft, in all their infinite wisdom, has blocked batch files from being executed by IIS in Windows Server 2003. Brenden Tom... | <p>Not sure how you are using 'shell()' but <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.process.start.aspx?ppud=4" rel="nofollow noreferrer">Process.Start</a> is the way to go.</p>
| 18,762 |
<p>Under FreeCAD, I sketched on the face of a solid as follows :</p>
<p><a href="https://i.stack.imgur.com/Qe4nu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Qe4nu.png" alt="sketch"></a></p>
<p>My problem is, when I use "Pad a selected sketch", the solid created comprises also the original solid... | <p>Ok, I got help on <a href="http://forum.freecadweb.org/viewtopic.php?f=3&t=19756" rel="nofollow noreferrer">this forum thread</a></p>
<p>Using <code>Part Extrude</code> instead of <code>Pad a selected sketch</code> on the sketch will create an independent solid.</p>
<p>It also turns out that, instead of creati... | <p>If you just select the face, and pad the face (versus padding the solid), you should not have this problem. </p>
| 483 |
<p>I have spent a long time searching for a product that would bring functionality similar to matplotlib to the .NET framework. From what I can tell, nothing really measures up. Is this an accurate assessment? Here is what I have found:</p>
<p>Commercial:</p>
<ul>
<li>ChartFX</li>
<li>Dundas</li>
<li>KitWare's Act... | <p>You could also look at <a href="http://www.ffconsultancy.com/products/fsharp_for_visualization/index.html" rel="noreferrer">F# for Visualization</a>, I've got the beta and it's quite good for some basic stuff - not (yet) so good if you want more control over the presentation.</p>
<p>Another possibility (which I hav... | <p>At <a href="http://www.resolversystems.com" rel="nofollow noreferrer">Resolver Systems</a> we're working on a project called <a href="http://code.google.com/p/ironclad" rel="nofollow noreferrer">Ironclad</a>, which will eventually (hopefully) allow you to use cPython extensions like matplotlib and numpy transparentl... | 40,735 |
<p>The Image Web Part doesn't seem to have an href attribute that I can set. Is there something I am missing?</p>
| <p>Does it have to be an Image Web Part? If not I would simply use a <a href="http://office.microsoft.com/en-us/sharepointserver/HA100240461033.aspx" rel="noreferrer">Content Editor Web Part</a> and paste the required HTML there.</p>
<pre><code><a href="http://www.google.com"><img src="urlToImage" /></a... | <p>what if it have to?
users need to have an opportunity to change the link and the image themselves and not to disturb an administrator.</p>
| 14,484 |
<p>I need to match and remove all tags using a regular expression in Perl. I have the following:</p>
<pre><code><\\??(?!p).+?>
</code></pre>
<p>But this still matches with the closing <code></p></code> tag. Any hint on how to match with the closing tag as well?</p>
<p>Note, this is being performed on x... | <p>I came up with this:</p>
<pre><code><(?!\/?p(?=>|\s.*>))\/?.*?>
x/
< # Match open angle bracket
(?! # Negative lookahead (Not matching and not consuming)
\/? # 0 or 1 /
p # p
(?= # Positive lookahead (Matching and not consuming)
> # > -... | <p>You should probably also remove any attributes on the <p> tag, since someone bad could do something like:</p>
<pre><code><p onclick="document.location.href='http://www.evil.com'">Clickable text</p>
</code></pre>
<p>The easiest way to do this, is to use the regex people suggest here to search for &am... | 4,970 |
<p>I'm using Windows XP and I want to know if the local area is available or not?</p>
<p>And if I'm using another OS would that affect on my code?</p>
| <p>Use the following code</p>
<pre><code>using System.Net.NetworkInformation; //(Add reference of System.Net.dll)
public partial class Form1: Form
{
public Form1()
{
InitializeComponent();
NetworkChange.NetworkAvailabilityChanged += NetworkChange_NetworkAvailabilityChanged;
}
private vo... | <p><a href="https://stackoverflow.com/questions/325872/detect-an-internet-connection-activation-with-delphi">Here's how to do it in Delphi.</a></p>
| 47,651 |
<p>If I target the x86 platform for my .NET app, will it run properly on AMD chips? I know that it will work with Intel chips, and that Vista 64 has the ability to run x86 apps in a special mode, but I don't know how much of that is hardware and how much of that is the OS. </p>
<p>I've tested it on Vista 64 with an In... | <p>Yes - they are binary compatible, otherwise they wouldn't be drop-in replacements for each other :)</p>
<p>Unless you mean IA64 vs AMD64 - those are incompatible architectures.</p>
| <p>It will work fine</p>
| 40,736 |
<p>I don't like paper documents. I like everything stored on a server. I'd like to avoid printing, signing, and scanning, if possible.</p>
<p><b>How do I get signatures from people to sign-off on forms and still keep it digital?</b></p>
<p>The purpose of signing is to prove that certain departments have OK'd the do... | <p>There are myriad approaches discussed in Schneier's <em>Applied Cryptography</em>.</p>
<p>Much of what you're looking for comes down to a Digital Signature Algorithm (DSA) - of which NIST has one, asymetric encryption algorithms can provide, etc.</p>
<p>The simple route would be to collect delivery and read receip... | <p>Having been searching for a system to this, I've just found docshaker.com on killerstartups. It pretty much allow you to do as you've just described Neall.</p>
| 22,210 |
<p>I am searching for a way to compress JavaScript code for the iPhone. Is there a way to avoid using a lot of CPU time on the small and rather slow device?</p>
| <p>Use <a href="http://www.crockford.com/javascript/jsmin.html" rel="nofollow noreferrer">JSMin</a> and avoid <a href="http://dean.edwards.name/packer/" rel="nofollow noreferrer">packer</a> which is really more CPU consuming and slower to "deflate"</p>
| <p>Making sure your webserver properly serves stuff gzipped/deflated when the client supports it is usually more effective than minifying the program code itself. Of course, using both tends to give even smaller sizes.</p>
| 14,017 |
<p>Does visual studio 2008 support classic asp development?</p>
<p>It's been years since I created a classic ASP website and I was wondering if I can use my current toolset or if I have to resign myself to notepad.</p>
<p>Thanks</p>
<p>Matt</p>
| <p>I know VS 2008 now includes Intellisense and Debugging feature for classic ASP, so thats make me think Yes.</p>
<p>Be sure you get the Service Pack 1 version.</p>
| <p>This is a good reference for setting up a classic ASP site in Visual Studio 2008:</p>
<p><a href="http://www.codeproject.com/KB/debug/DebugVBScriptVS2008.aspx" rel="nofollow">http://www.codeproject.com/KB/debug/DebugVBScriptVS2008.aspx</a></p>
<p>Additionally, I had to give "Everyone" access to the Virtual Directo... | 29,779 |
<p>Is there a way to check to see if a date/time is valid you would think these would be easy to check:</p>
<pre><code>$date = '0000-00-00';
$time = '00:00:00';
$dateTime = $date . ' ' . $time;
if(strtotime($dateTime)) {
// why is this valid?
}
</code></pre>
<p>what really gets me is this:</p>
<pre><code>echo d... | <p>From <a href="http://php.net/manual/en/function.checkdate.php#78362" rel="noreferrer">php.net</a></p>
<pre><code><?php
function isValidDateTime($dateTime)
{
if (preg_match("/^(\d{4})-(\d{2})-(\d{2}) ([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$/", $dateTime, $matches)) {
if (checkdate($matches[2], $m... | <pre><code><?php
function is_date( $str ) {
$stamp = strtotime( $str );
if (!is_numeric($stamp)) {
return FALSE;
}
$month = date( 'm', $stamp );
$day = date( 'd', $stamp );
$year = date( 'Y', $stamp );
if (checkdate($month, $day, $year)) {
return TRUE;
}
retu... | 17,071 |
<p>In Eclipse 3.3.2, I would like to replace a character (say ',') by a new line in a file.
What should I write in the "Replace with" box in order to do so ?</p>
<p>EDIT : Many answers seems to be for Eclipse 3.4. Is there a solution for Eclipse 3.3.X ?</p>
| <p>Check box 'Regular Expressions' and use '\R' in the 'Replace with' box</p>
<p>It's a new feature introduced with Eclipse 3.4, See <a href="http://download.eclipse.org/eclipse/downloads/drops/R-3.4-200806172000/whatsnew3.4/eclipse-news-part1.html" rel="noreferrer">What's New in 3.4</a></p>
| <p>I've just found <a href="http://www.andyjarrett.co.uk/2006/11/02/eclipse-regex-and-newline-bug/" rel="nofollow noreferrer">an article about that problem</a>. It seems to be a bug.</p>
<p>There's a workaround which is to copy a new line in clipboard and then paste it inside the "replace" box.</p>
| 18,961 |
<p>Our usage case is a database responsible for accounts, sessions, licenses, etc. — it needs to be polled upon client startup, so high reliability is crucial. As such, we'd like to replicate across different servers in physically separate networks, just in case an entire datacenter happens to go down. I have successfu... | <p>When you talk about different locations for the servers, does it also mean different domains? Your comment on web replication is true, but applies only to the daily changes made to the database. Your initial snapshot can be of any size, even if it is a huge database. If your daily updates are limited (a few 1000's s... | <p>I know this is an old post but hopefully this helps: SQL Server Management Studio uses a comma to separate the host from the port. </p>
<p><a href="https://stackoverflow.com/questions/89576/how-do-you-specify-a-different-port-number-in-sql-management-studio">How do you specify a different port number in SQL Managem... | 29,238 |
<p>I'm relatively new to the Windows Server world (coming from *nix land). I'm used to analyzing a web-server's configuration by grepping through an apache config file. </p>
<p>Is there an equivalent file/group-of-files for IIS? Lacking that, is there an official scripting interface for IIS?</p>
| <p>PowerShell would be the way to go.</p>
<p>Here are some stack overflow posts:</p>
<p><a href="https://stackoverflow.com/questions/tagged/powershell+iis6">https://stackoverflow.com/questions/tagged/powershell+iis6</a></p>
<p>Also, googling <strong>powershell IIS</strong> will get you started.</p>
| <p>Default scripting tool in IIS is the ADSUTIL.VBS script in the \InetPubs\Scripts directory. </p>
<p><a href="http://technet.microsoft.com/en-us/library/cc781546.aspx" rel="nofollow noreferrer">Using the Adsutil.vbs Administration Script</a></p>
<p>You can pretty much do anything to the IIS metabase with that tool.... | 44,903 |
<p>JSF is setting the ID of an input field to <code>search_form:expression</code>. I need to specify some styling on that element, but that colon looks like the beginning of a pseudo-element to the browser so it gets marked invalid and ignored. Is there anyway to escape the colon or something?</p>
<pre><code>input#sea... | <p>Backslash: </p>
<pre><code>input#search_form\:expression { ///...}
</code></pre>
<ul>
<li>See also <em><a href="http://msdn.microsoft.com/en-us/library/ms762307(VS.85).aspx" rel="noreferrer">Using Namespaces with CSS</a></em> (MSDN)</li>
</ul>
| <p>I found only this format worked for me for IE7 (Firefox too), and I use JSF/Icefaces 1.8.2.</p>
<pre>
Say form id=FFF, element id=EEE
var jq=jQuery.noConflict();
jq(document).ready(function() {
jq("[id=FFF:EEE]").someJQueryLibFunction({ jQuery lib function options go here })
});
</pre>
| 14,864 |
<p>I have a dev branch that hasn't been touched for a while. I merged the trunk into it to integrate many fixes/changes in the main line since it was branched out, but now I have many small conflicts (merge-left/merge-right).</p>
<p>I want the latest trunk revision to be used to resolve each conflict. Is there a comma... | <p>I think you can use the "--accept theirs-full" option when you issue the svn merge command.
That should do what you want...</p>
| <p>I think TSVN could do this if you do a "Check for modifications", which will show you all the files including the conflicted ones, select them all, and then choose 'resolve using theirs'. </p>
<p>Not sure if TSVN is relevant for your platform, or it that's actually exactly what you want to to do, but it might be ... | 42,592 |
<p>I have the following <code>before_filter</code>:</p>
<pre><code> def find_current_membership
respond_to do |wants|
wants.html { @current_membership = @group.memberships.for(@current_user) }
wants.rss {}
wants.js { @current_membership = @group.memberships.for(@current_user) }
end
end
... | <p>If I'm reading this right, it looks like <code>find_current_membership</code> is your <code>before_filter</code> method, is that right? eg:</p>
<pre><code>class SomeController < ApplicationController
before_filter :find_current_membership
...
</code></pre>
<p>I think it's a bit non-standard to use <code>res... | <p>How about this simple solution!?</p>
<pre><code>def find_current_membership
@current_membership = @group.memberships.for(@current_user)
respond_to do |wants|
wants.html
wants.rss {}
wants.js
end
end
</code></pre>
| 30,357 |
<p>I have a question regarding a symptom of my misuse of CreateProcess. I'm using the lpcommandline parameter to feed the path to my executable and parameters. My misuse is that I have not surrounded the path to the exe with quotes. </p>
<p>My question is, why does the CreateProcess work just fine on most computers ... | <p>As the document Martin York linked to hinted, CreateProcess() has some behaviour for back-compat with pre-long-name programs.</p>
<p>"c:\program files\sub dir\program name arg1 arg2" will look for:</p>
<blockquote>
<pre><code>"c:\program.exe" files\sub dir\program name arg1 arg2
"c:\program files\sub.exe" dir\prog... | <p>A good way to diagnose something like that is to build in to your application error and reporting mechanism. This helps for so many purposes- mainly for bugs that you may never see yourself and which some users may just ignore and not report to you. This way you can diagnose what these parameters were when the com... | 33,305 |
<p>Typically in a large network a computer needs to operate behind an authenticated proxy - any connections to the outside world require a username/password which is often the password a user uses to log into email, workstation etc.</p>
<p>This means having to put the network password in the <code>apt.conf</code> file... | <p>With the following approach you never have to save your proxy password in plain text. You just have to type in a password interactively as soon as you need http/https/ftp access:</p>
<ul>
<li>Use openssl to encrypt your plain text proxy password into a file, with e.g. AES256 encryption:</li>
</ul>
<blockquote>
<... | <p>Is public key authentication a valid alternative for you?</p>
| 3,945 |
<p>What algorithms and processes are involved in storing revision changes like stackoverflow and wikipedia do?</p>
<p>Is only one copy of the message kept? And if so is it only the latest copy? Then only changes to go back to the previous version(s) are stored from there? (This would make for a faster display of th... | <p>The <a href="http://en.wikipedia.org/wiki/Diff#Algorithm" rel="nofollow noreferrer">longest common substring algorithm</a> can be used to detect differences between versions, but it is limited. For example, it does not detect the moving around of text as such, but it would see this as unrelated removals and insertio... | <p>Typical revision changes are stored using a delta algorithm, so the only data stored are the changes in each revision in relation to the original. I am unsure of wikipedia or stackoverflow how they have it implemented.</p>
| 10,557 |
<p>I'm a firm believer of the heretic thought of tight coupling between the backend and frontend: I want existing, implied knowledge about a backend to be automatically made use of when generating user interfaces. E.g., if a VARCHAR column has a maximum with of 20 characters, there GUIs should automatically constrain t... | <p>web2py does most of what you ask:</p>
<p>Based on a field type and its validators it will render the field with the appropriate widget. You can override with</p>
<pre><code>db.table.field.widget=...
</code></pre>
<p>and use a third party widget.</p>
<p>web2py has js to blocks the user from entering a non-integer... | <p>I believe that Django models does not support composite primary keys (see <a href="http://docs.djangoproject.com/en/dev/topics/db/models/#automatic-primary-key-fields" rel="nofollow noreferrer">documentation</a>). But perhaps you can use SQLAlchemy in Django? A <a href="http://www.google.com/search?q=sqlalchemy+djan... | 6,498 |
<p>I'm sure there is a good (or at least decent) reason for this. What is it?</p>
| <blockquote>
<p>I think this is a brilliant question -
and I think there is need of a better
answer.</p>
<p>Surely the only reason is that there
is something in a framework somewhere
that isn't very thread-safe. </p>
</blockquote>
<p>That "something" is almost every single instance member on every singl... | <p>Hmm I'm not pretty sure but I think that when we have a progress controls like waiting bars, progress bars we can update their values from another thread and everything works great without any glitches. </p>
| 3,158 |
<p>I'd be leading a new project soon. And I've been pondering over what are the basic infrastructure for a software project. These are the stuff that I think every project should have:</p>
<p>-Coding style conventions</p>
<p>-Naming conventions</p>
<p>-Standard project directory structure(eg maven standard dir layou... | <p>As a preliminary answer, check out the Joel test:
<a href="http://www.joelonsoftware.com/articles/fog0000000043.html" rel="noreferrer">http://www.joelonsoftware.com/articles/fog0000000043.html</a></p>
<p>Just an appetizer:</p>
<blockquote>
<ol>
<li>Do you use source control?</li>
<li>Can you make a build in ... | <p>Knowledge management is crucial. As you already plan to use wiki (like Trac or <a href="http://www.redmine.org/" rel="nofollow noreferrer">Redmine</a>) you could use it for KM as well.</p>
| 11,642 |
<p>We have recently moved back to InstallShield 2008 from rolling our own install. So, I am still trying to get up the learning curve on it. </p>
<p>We are using Firebird and a usb driver, that we couldn't find good msi install solutions. So, we have a cmd line to install firebird silently and the usb driver mostly si... | <p>Chris, I had trouble getting the MsiGetProperty to work at all. Just adding the code that you have </p>
<pre><code>string sRemove;
number nBuffer;
nBuffer = 256;
if (MsiGetProperty(ISMSI_HANDLE, "REMOVE", sRemove, nBuffer) = ERROR_SUCCESS) then
//do something
endif;
</code></pre>
<p>I get "undefined identifi... | <p>There are MSI properties you can look at that will tell you if a product is already installed or if an uninstall is taking place. The Installed property will be true if the product is already there, so you can use it in a Boolean expression (Ex: Not Installed). The REMOVE property will be set to "ALL" if an uninstal... | 15,854 |
<p>I can understand the use for one level of namespaces. But 3 levels of namespaces. Looks insane. Is there any practical use for that? Or is it just a misconception?</p>
| <p>Hierarchical namespaces do have a use in that they allow progressively more refined definitions. Certainly a single provider may produce two classes with the same name. Often the first level is occupied by the company name, the second specifies the product, the third (and possibly more) my provide the domain.</p>
<... | <p>It depends on your needs and programming style. But one of the benefits of <code>namespace</code> is to help partition name space (hence the name). With a single namespace, as your project is increases in size and complexity, so does the likelihood of name-collision.</p>
<p>If you're writing code that's meant to ... | 14,266 |
<p>I have multiple threads (C# application running on IIS) running that all need to communicate with the same MQ backend. To minimize network traffic, I need to only send a backend request when there is work to be done. There will be one thread to monitor if there is work to be done, and it needs to notify the other ... | <p>Check out <a href="http://msdn.microsoft.com/en-us/library/system.threading.waithandle.aspx" rel="nofollow noreferrer">WaitHandle</a> and its descending classes. <a href="http://msdn.microsoft.com/en-us/library/system.threading.eventwaithandle.aspx" rel="nofollow noreferrer">EventWaitHandle</a> may suit your needs.<... | <p><a href="http://msdn.microsoft.com/en-us/library/yy12yx1f(VS.80).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/yy12yx1f(VS.80).aspx</a></p>
<p>You can use AutoReset Events</p>
| 25,779 |
<p>How can I get line numbers to <code>print</code> in <strong>Visual Studio 2005</strong> when printing <code>code</code> listings?</p>
| <p>There is an option in the Print Dialog to do the same (in VS 2005 and 2008 atleast)!</p>
| <p>Isn't there an option in the Print Dialog?</p>
<p>Edit: There is. Go to File => Print, and then in the bottom left there is "Print what" and then "Include line Numbers"</p>
| 2,586 |
<p>I'm translating my C# code for YouTube video comments into PHP. In order to properly nest comment replies, I need to re-arrange XML nodes. In PHP I'm using DOMDocument and DOMXPath which closely corresponds to C# XmlDocument. I've gotten pretty far in my translation but now I'm stuck on getting the parent node of a ... | <p><a href="http://no2.php.net/manual/en/class.domelement.php" rel="noreferrer">DOMElement</a> is a subclass of <a href="http://no2.php.net/manual/en/class.domnode.php" rel="noreferrer">DOMNode</a>, so it does have parent_node property. Just use $domNode->parentNode; to find the parent node.</p>
<p>In your example, th... | <p>I'm not entirely sure how your code works, but it seems like you have a small error in your code. </p>
<p>On the line you posted in your question you have <code>$link->parent_node()</code>, but in the answer with the entire code snippet you have <code>$link**s**->parent_node()</code>. </p>
<p>I don't think t... | 4,852 |
<p>I am finding that calling a stored proc in Excel is not as easy as it should be, but calling a view, or a direct table is very easy. So, how can I create a view that will call a stored proc with no params?</p>
<p>I know I won't be able to pass any values into the view, and I don't need or want to, Just want to wrap... | <p>iirc (I don't have a copy to hand) if you happen to be in T-SQL it should be possible to select * from a <strong>user defined table function</strong> (which are for most intents and purposes identical to sprocs) which returns a table variable.</p>
| <p>You should be able to put a trigger on a dummy table, and call the proc inside the trigger.</p>
<p>This is definitely a hack, and you would want to really lock down permissions on the table and proc.</p>
| 45,547 |
<p>I would like to retrieve at runtime the values for the "dialect" and "connection.driver_class" properties specified in the configuration file.</p>
<p>Do you know how to do that?</p>
<p>Many thanks,
Nicola</p>
| <p>thanks for your answer.
One thing that I don't like in that solution is that I need to keep the configuration and pass it around in the methods that need the knowledge of the dialect.</p>
<p>I found a couple of other ways that need only a reference to the ISession of of the ISessionFactory.</p>
<p>From the ISessio... | <p>When you build the Configuration object and load the XML and eventually build the SessionFactory, hang on to the Configuration object reference you have.</p>
<p>You can use the Properties object of the Configuration reference you have, or you can do something like Dialect.GetDialect(_configuration.Properties).</p>
| 35,559 |
<p>I know that I am supposed to use <code>delete []</code> after I use <code>new []</code>, so using <code>auto_ptr</code> with <code>new []</code> is not such a bright idea.</p>
<p>However, while debugging <code>delete []</code> (using Visual Studio 2005), I noticed that the call went into a function that looked like... | <p>Consider this code:</p>
<pre><code>class DeleteMe
{
public:
~DeleteMe()
{
std::cout << "Thanks mate, I'm gone!\n";
}
};
int main()
{
DeleteMe *arr = new DeleteMe[5];
delete arr;
return 0;
}
</code></pre>
<p>If you run that in VS2005 it will print:</p>
<pre>Thanks mate, I'm gone!</pre>
<p>I... | <p>Just because they might work the same now, doesn't mean you can necessarily treat them the same - the behaviour could change. And besides, who cares - you should write your code so you don't have to remember.</p>
<p>Additionally, you can use <a href="http://www.boost.org/doc/libs/1_36_0/libs/smart_ptr/scoped_array.... | 38,652 |
<p>Is there any way to view the activity log for the integrate SourceSafe inside Visual Studio 2005 Pro? I'd like to be able to quickly see the results of any Get Latest Version, Check In and Checkout actions, and I can't find a way to get that information without having to open the VSS client.</p>
| <p>The output window (View - Output) echoes a lot. If it isn't verbose enough though I don't know how one would configure that.</p>
| <p>That's what I was missing - I never saw the [Source Control] option for the "Show output from:" setting in the Output window. Great, thanks.</p>
| 17,124 |
<p>Is there a way to compress a VMWare image on a ESXi server for archival purposes?</p>
| <p>What is wrong with simply using your faviourite archiver/compressor utility?</p>
| <p>I concur with <a href="https://stackoverflow.com/questions/148999/archiving-vmware-images-on-esxi#149059">@Sec</a> - I use .tar.gz or .tar.bz2.</p>
| 17,954 |
<p>I have a Team Foundation Server 2008 Installation and a separate machine with the Team Build service.</p>
<p>I can create team builds and trigger them manually in Visual Studio or via the command line (where they complete successfully). However check ins to the source tree do not cause a build to trigger despite th... | <p>Ok I have found the answer myself after several dead ends. In the end I fixed this unintentionally while fixing another issue. Basically we had just turned on the automatic execution of unit tests for our builds. The test would run sucessfully but then immediately the build would bomb out with a message saying it wa... | <p>Select your team project from team explorer, then right click on the Builds folder. Select a new build definition and then select the trigger tab. Move the radio button to "Build each check-in (more builds)"</p>
<p>More info can be found here</p>
<p><a href="http://msdn.microsoft.com/en-us/library/ms181716.aspx"... | 6,543 |
<p>I am currently building in Version 3.5 of the .Net framework and I have a resource (.resx) file that I am trying to access in a web application. I have exposed the .resx properties as public access modifiers and am able to access these properties in the controller files or other .cs files in the web app. My questi... |
<pre class="lang-cs prettyprint-override"><code><%= Resources.<ResourceName>.<Property> %>
</code></pre>
| <p>If you are using ASP.NET 2.0 or higher, after you compile with the resource file, you can reference it through the Resources namespace:</p>
<pre><code>text = Resources.YourResourceFilename.YourProperty;
</code></pre>
<p>You even get Intellisense on the filenames and properties.</p>
| 8,852 |
<p>I need to upload images using FileUpload without postback(using Ajax).I tried many examples.But in all postback is coming or they are using PHP.Can anyone help me to do single file upload or multi file upload using ajax in ASP.Net with C#.</p>
| <p>SWFUpload</p>
<p><a href="http://demo.swfupload.org/v220beta3/simpledemo/index.php" rel="noreferrer">http://demo.swfupload.org/v220beta3/simpledemo/index.php</a></p>
<p><a href="http://swfupload.org/" rel="noreferrer">http://swfupload.org/</a></p>
<p>Javascript and Flash, there's no post-back :) and there's .NET ... | <p>There is no such thing as a ajax file upload. The components that you see either use flash swfupload or a hidden iframe that they post a form to that give the impression it is happening in an ajax manner. There are many plugins avaiable to help you do this. My favourite is <a href="http://jquery.webunity.nl/" rel="n... | 43,642 |
<p>I have a page where I combine labels, input boxes and text areas to display some content.
I would like all of them to have the same font-family and font-size.
I have played with the <em>font-family: inherit</em> style but this doesn't seem to work for the input and text areas.
What would be the easiest way to ensur... | <p>Ok ... this does the trick:</p>
<pre><code>*
{
font-family: arial;
}
input
{
font-family: inherit;
font-size: 100%
}
textarea
{
font-family: inherit;
font-size: 100%
}
</code></pre>
| <p>I think most CSS devs will do something like </p>
<pre><code>body {font: normal 10pt Arial}
</code></pre>
<p>At the top of the CSS file.</p>
<p>If you want to change labels from this, just add a </p>
<pre><code>label, input, textarea {font-family:Georgia}
</code></pre>
<p>somewhere down the road.</p>
| 49,745 |
<p>If I have a button like the one in this image :</p>
<p><strong><a href="http://www.freeimagehosting.net/image.php?4cd775814c.png" rel="nofollow noreferrer">http://www.freeimagehosting.net/image.php?4cd775814c.png</a></strong></p>
<p>how could I make the text display itself vertically ? As in </p>
<pre>
j
B
u
t
t
... | <p>You can use HTML for JButton or JLabel. So </p>
<pre><code>button = new JButton("<html>J<br>b<br>u<br>t<br>t<br>o<br>n<br>1</html>");
</code></pre>
<p>should do the trick.</p>
| <p>I don't know if this is useful to you, but <a href="http://www.codeguru.com/java/articles/199.shtml" rel="noreferrer">this sample</a> shows how to make a vertical label. The difference is that it rotates all of the text (and/or the icon) instead of stacking the letters. I don't know how difficult it would be to modi... | 32,477 |
<p>When a user hits Refresh on their browser, it reloads the page but keeps the contents of form fields. While I can see this being a useful default, it can be annoying on some dynamic pages, leading to a broken user experience.</p>
<p>Is there a way, in HTTP headers or equivalents, to change this behaviour?</p>
| <pre><code><input autocomplete="off">
</code></pre>
| <p>I wonder, if you set the page not to be cached through meta tags, will that fix the problem? <a href="http://lists.evolt.org/archive/Week-of-Mon-20030106/131984.html" rel="nofollow noreferrer">http://lists.evolt.org/archive/Week-of-Mon-20030106/131984.html</a> If it does, it'll have the benefit of working on browser... | 7,546 |
<p>How do I limit a SQL Server Profiler trace to a specific database? I can't see how to filter the trace to not see events for all databases on the instance I connect to.</p>
| <p>Under Trace properties > Events Selection tab > select show all columns. Now under column filters, you should see the database name. Enter the database name for the Like section and you should see traces only for that database.</p>
| <p>Create a new template and check DBname. Use that template for your tracefile.</p>
| 34,338 |
<p>I have a need to populate a Word 2007 document from code, including repeating table sections - currently I use an XML transform on the document.xml portion of the docx, but this is extremely time consuming to setup (each time you edit the template document, you have to recreate the transform.xsl file, which can take... | <p>I tried myself to write some code for that purpose, but gave up. Now I use a 3rd party product: <a href="http://www.aspose.com/categories/file-format-components/aspose.words-for-.net-and-java/default.aspx" rel="nofollow noreferrer"><strong>Aspose Words</strong></a> and am quite happy with that component.</p>
<p>It ... | <p>Have you considered using VB? You could create a separate assembly to populate your document.</p>
<p>I know you are looking for a C# solution, but the XML literal support is one area where XML literal support could help you populate the document. Create a document in Word to server as a template, unzip the docx, ... | 36,941 |
<p>I need to display many pages of news in a site. Should I do the pagination in the database query using <code>LIMIT</code> or with the PHP script after getting all the results?</p>
| <p>Use limit in SQL! Every time!</p>
<p>Otherwise you're throwing around considerably more data than you need to, which makes your scripts unnecessarily slow, and will lead to scalability problems as the amount of data in your tables increases.</p>
<p>Limit is your friend!</p>
| <p>Personally, I would use the query to do it. Obviously, that can change if your dealing with AJAX and such, but just doing a basic limit in the query and outputting the results is simple and efficient.</p>
| 13,429 |
<p>I'm trying to debug an MSBuild task, and I know there is some way to write to the MSBuild log from within a custom task but I forget how.</p>
| <p>The base <a href="http://msdn.microsoft.com/en-us/library/microsoft.build.utilities.task.aspx" rel="noreferrer">Task</a> class has a <code>Log</code> property you can use:</p>
<pre><code>Log.LogMessage("My message");
</code></pre>
| <p>For unit testing purposes, I wrap the logger around a helper class</p>
<pre><code>public static void Log(ITask task, string message, MessageImportance importance)
{
try
{
BuildMessageEventArgs args = new BuildMessageEventArgs(message, string.Empty,
task.ToString(), importance);
... | 19,769 |
<p>I need to round decimal numbers to six places using JavaScript, but I need to consider legacy browsers so I <a href="http://www.hunlock.com/blogs/The_Complete_Javascript_Number_Reference" rel="noreferrer">can't rely on Number.toFixed</a> </p>
<blockquote>
<p>The big catch with toExponential, toFixed, and toPrecis... | <p>Try this:</p>
<pre><code>if (!Number.prototype.toFixed)
Number.prototype.toFixed = function(precision) {
var power = Math.pow(10, precision || 0);
return String(Math.round(this * power)/power);
}
</code></pre>
| <p>I think Firefox 1.5 and IE 5 are pretty much no longer used, or by a very minor quantity of people.<br>
It is a bit like coding to support Netscape Navigator... :-)<br>
Unless some other major browser (Opera? Safari? unlikely...) doesn't support this, or if your Web logs show lot of legacy browser use, you can proba... | 43,738 |
<p>Recently, I have heard people talking about masterspool, when talking about 3D printing filament.</p>
<ul>
<li>What <em>exactly</em> is master spool?</li>
<li>Where did the idea come from and when?</li>
<li>Is it being widely adopted? Or to be specific, how many distributors/manufacturers have adopted this already,... | <p>A masterspool is the practice of printing your own spool out of filament, which will then be used to support your filament you purchase without a spool attached. The main idea is to create a reusable spool and create less waste. </p>
<p>(<em>NOTE: I'm in no way affiliated with MatterHackers.com, nor am I an endorse... | <p>One key difference between a 'masterspool' and any old spare empty reel you have left over is that the masterspool is a 2-part design which can be fitted over an existing roll of filament without needing to un-spool and re-spool the whole roll.</p>
<p>The idea being that filament can be packaged and secured for shi... | 991 |
<p>I am trying to find a generic way of accessing a set of containers. I have a standard vector and list in addition to another custom list.</p>
<p>The custom list defines an iterator;</p>
<pre><code>class Iterator: public std::iterator<std::forward_iterator_tag, T> {
// ...
}
Iterator begin() {
return... | <p>Here are some articles you might find of interest</p>
<p><a href="http://accu.org/index.php/journals/479" rel="noreferrer">Giving STL Iterators a Base Class</a></p>
<p><a href="http://thbecker.net/free_software_utilities/type_erasure_for_cpp_iterators/start_page.html" rel="noreferrer">Type Erasure for C++ Iterator... | <p>Better late than never...</p>
<p>The latest issue of <a href="http://accu.org/index.php/aboutus/aboutjournals" rel="nofollow noreferrer">C-Vu</a> turned up and guess what was in it: That's right, iterators that do <em>exactly</em> what you wanted.</p>
<p>Unfortunately you need to become a member of the <a href="ht... | 3,126 |
<p>I am intentionally leaving this quite vague at first. I'm looking for discussion and what issues are important more than I'm looking for hard answers.</p>
<p>I'm in the middle of designing an app that does something like portfolio management. The design I have so far is</p>
<ul>
<li>Problem: a problem that needs... | <p>Hmm, sounds kind of like this site...</p>
<p>As far as a database design would go, a versioning system kind of like SVN, where you never actually do any updates, just inserts (with a version number) when things change, might be what you need. This is called MVCC, Multi-Value Concurrency Control. A wiki is another... | <p>I suppose there's</p>
<h2>Option 4: the hybrid</h2>
<p>Move the common Thing attributes into a single-inheritance table, then add an <code>custom_attributes</code> table. This makes foreign-keys simpler, reduces duplication, and allows flexibility. It doesn't solve the problems of type-safety for the additional ... | 3,277 |
<p>I'm creating a user-based website. For each user, I'll need a few MySQL tables to store different types of information (that is, userInfo, quotesSubmitted, and ratesSubmitted). Is it a better idea to:</p>
<p>a) Create one database for the site (that is, "mySite") and then hundreds or thousands of tables inside thi... | <p>Use one database.</p>
<p>Use one table to hold users and one table to hold quotes.</p>
<p>In between those two tables you have a table that contains information to match users to quotes, this table will hold the rating that a user has given a quote.</p>
<p>This simple design will allow you to store a practically ... | <p>Use one database and one table. You will require a table "User" and this table will be linked (Primary--Foreign key) to these table.</p>
| 42,487 |
<p>I'm trying to be a good developer and create some documentation before I start programming my next project.</p>
<p>I have created a database schema diagram in Visio and created relationships between columns.</p>
<p>However, I am looking for a way to make the relationships between columns more clear. I want the ar... | <p>You can use the Visio Drawing tools to force the Relationship Connector to glue to particular Connection Points on the Table Shapes:</p>
<ol>
<li>Turn on Connection Points in the View menu.</li>
<li>On the standard toolbar find the Connector Tool just to the right of the Pointer Tool. Click on the little arrow and ... | <p>To my knowledge this is how visio draws it, and it is not possible to get it to point at an exact column. its kinda annoying, but I guess you learn to live with the FK markings</p>
| 25,245 |
<p>If I have class names such as "left", "right", "clear" and xhtml like</p>
<pre><code><a href="index.php" class="right continueLink">Continue</a>
</code></pre>
<p>With CSS like</p>
<pre><code>.right {
float: right;
}
</code></pre>
<p>I know it's not a semantic name, but it does make things much easier... | <p>I don't think that's a very good idea. Now when you (or a future maintainer) go to change your website layout, you'll either have to change <code>.right</code> to <code>{float:left;}</code> (obviously a bad idea) or go through all your HTML files and change <code>right</code> to <code>left</code>.</p>
<p>Why do you... | <p>.right and other classes like that, certainly makes it quick to write create a tag with a <code>float:right</code> rule attached to it, but I think this method has more disadvantages than advantages:</p>
<p>Often a class-style with a single <code>float:right;</code> in it will lack something, your example wil only ... | 29,982 |
<p>In C#, I'm creating an XML file from a DataTable using dataTable.WriteXml(filePath), and get the following:</p>
<pre><code><?xml version="1.0" encoding="utf-8" ?>
<ExperienceProfiles>
<ExperienceProfile>
<Col1>blah</Col1>
<Col2>4ed397bf-a4d5-4ace-9d44-8c1a5cdb0f34</C... | <p>What you want is some way to tell the DataSet the expected format of your data. You're in luck, the DataSet supports just this feature.</p>
<p>You will need to create an XML schema for your data and load it into the DataSet before you write out the XML. In the schema define Col1 and Col2 as attributes of the Expe... | <blockquote>
<p>Short answer: you can't, using the
WriteXml method of a DataTable.</p>
<p>Long answer (which is not very long):
Just roll your own.</p>
</blockquote>
<p>Retract my answer, as per above :)</p>
| 46,192 |
<p>Does anyone know what substantial differences there are between the <a href="http://www.postgresql.org" rel="noreferrer">regular PostgreSQL</a> and <a href="http://www.enterprisedb.com/products/postgres_plus.do" rel="noreferrer">Postgres Plus</a>?</p>
| <p>The database is the same, meaning that the SQL is fully compatible to any other PostgreSQL installation around (save for the GIS data formats). </p>
<p>The main difference is that there is a bunch of modules and tools bundled with Postgres Plus that you would have to collect and install separately and by yourself o... | <p>I used 8.2 and when was the time to switch to 8.3 I tried PostGresPlus.</p>
<p>The Speed was a lot <strong>faster</strong>. LOT I mean queries that took 30 secs, takes now less than 2 seconds. I am not sure if it's 8.3 that is faster or the Enterprise Plus but I can tell you that I was impressed. </p>
<p>Other thi... | 44,744 |
<p>Can anybody help me to build an XSD file to validate XMLs like these:</p>
<pre><code>[test]
[a/]
[b/]
[a/]
[b/]
[/test]
[test]
[a/]
[a/]
[b/]
[/test]
</code></pre>
<p>Basically, I can have any number of <code><a></code> and/or <code><b></code> nodes without any other rule (can't use <code><xs:seque... | <p>It isn't going to very fast if you have a lot of <strong>a</strong> or <strong>b</strong> nodes but this validates against what you've described.</p>
<pre><code><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="test">
<xs:complexType>
<xs:sequence>
... | <p>If you paste the sample XML, we can help you better. However, <a href="https://stackoverflow.com/questions/288236/xsd-code-generator">Microsoft has an XSD code generator</a> that generates an XSD based on an XML file that you pass in as an argument.</p>
| 46,170 |
<p>See title. By lightweight markup I mean something like markdown or wikitext.</p>
| <p>Well, silverstripe <a href="http://www.silverstripe.com/" rel="nofollow noreferrer">http://www.silverstripe.com/</a> is thought to be a good option for people who care about web standards , as is modx <a href="http://modxcms.com/" rel="nofollow noreferrer">http://modxcms.com/</a> </p>
<p>For a lighter editor, check... | <p>I am a user of Joomla. I think Joomla is in the top five CMS.</p>
| 13,078 |
<p>I have a simple database with two tables. Users and Configurations. A user has a foreign key to link it to a particular configuration.</p>
<p>I am having a strange problem where the following query always causes an inner join to the Configuration table regardless of the second parameter value. As far as I can tell,... | <p>switch() needs an integral type (like int, char, ...)</p>
<p>string is not an integral type, neither does string have an implicit conversion to an integral type, so it can't be used in a switch statement</p>
| <p>The easiest alternative BTW is a <code>std::map<std::string, boost::function> StringSwitch;</code></p>
<p>This lets you say <code>StringSwitch["Some string"](arguments...)</code></p>
| 39,760 |
<p>Does anyone know of an MD5/SHA1/etc routine that is easily used with GLib (i.e. you can give it a GIOChannel, etc)?</p>
| <p>Unless you have a <em>very</em> good reason, use glib's built-in MD5, SHA1, and SHA256 implementations with <a href="http://developer.gnome.org/glib/unstable/glib-Data-Checksums.html#GChecksum" rel="nofollow noreferrer"><code>GChecksum</code></a>. It doesn't have a built-in function to construct a checksum from an I... | <p>You normally have to do library glue stuff yourself...</p>
<pre><code>void get_channel_md5( GIOChannel* channel, unsigned char output[16] )
{
md5_context ctx;
gint64 fileSize = <get file size somehow?>;
gint64 filePos = 0ll;
gsize bufferSize = g_io_channel_get_buffer_size( channel );
voi... | 13,788 |
<p>I have been tasked with going through a number of ColdFusion sites that have recently been the subject of a rather nasty SQL Injection attack. Basically my work involves adding <code><cfqueryparam</code>> tags to all of the inline sql. For the most part I've got it down, but can anybody tell me how to use cfque... | <p>@Joel, I have to disagree.</p>
<pre><code>select a,b,c
from Foo
where name like <cfqueryparam cfsqltype="columnType" value="%#variables.someName#%" />
</code></pre>
<ol>
<li><p>Never suggest to someone that they should "select star." Bad form! Even for an example! (Even copied from the question!)</p></li>
<l... | <pre><code>select a,b,c
from Foo
where name like <cfqueryparam cfsqltype="cf_sql_varchar" value="%Bob%" />;
</code></pre>
| 6,872 |
<p>in web.xml i set my welcome file to a jsp within web.xml</p>
<pre><code><welcome-file>WEB-INF/index.jsp</welcome-file>
</code></pre>
<p>inside index.jsp i then forward on to a servlet </p>
<pre><code><% response.sendRedirect(response.encodeRedirectURL("myServlet/")); %>
</code></pre>
<p>however... | <p>I use the <a href="http://tomcat.apache.org/tomcat-6.0-doc/jasper-howto.html" rel="nofollow noreferrer">Tomcat jasper ANT tasks</a> in my project, which precompile the JSPs into servlets and add the new servlet mappings to the original web.xml. In the DEV builds, just skip this step and deploy the JSPs without pre-... | <p>There is the <strong>jasper2</strong> ant task others have noted. I thought I'd mention a couple of other options I've found.</p>
<p>One is cactus' <strong>webxmlmerge</strong> ant task, which uses org.codehaus.cargo.module.webapp.WebXmlMerger </p>
<p>Another would be to use <strong>JAXB</strong> to manipulate th... | 19,603 |
<p>So I am missing small sections of a layer when it prints, after a retraction for a layer change or a move, the extruder stops moving (no it isn't clicking or anything else. Just not moving). Which is fine for a few millimeters because the pressure inside the Bowden setup keeps pushing enough filament through. Howeve... | <p>I have made some learning on mechanical setup and discovered some issues on my printer, there are few:</p>
<ol>
<li>Bed warped, even with glass (thin thickness), making BAL confused with Z-movement over the bed.</li>
<li>Overextrusion making layer oversized in terms of thickness.</li>
<li>Some of missing mechanical... | <p>The first picture seems to show layer shift. Usual causes include:</p>
<ol>
<li>Missed Z movement, so the nozzle hits the build and the layer is offset.</li>
<li>Bad acceleration in X/Y, so there is missed X/Y movement, and the layer is offset.</li>
</ol>
<p>Adjustment: reduce Z G0 speed, and reduce X/Y speeds (G0... | 698 |
<p>I've created a script that runs every night on my Linux server that uses <code>mysqldump</code> to back up each of my MySQL databases to .sql files and packages them together as a compressed .tar file. The next step I want to accomplish is to send that tar file through email to a remote email server for safekeeping.... | <p>None of the mutt ones worked for me. It was thinking the email address was part of the attachment. Had to do:</p>
<pre><code>echo "This is the message body" | mutt -a "/path/to/file.to.attach" -s "subject of message" -- recipient@domain.example
</code></pre>
| <p>If mutt is not working or not installed,try this-</p>
<pre><code>*#!/bin/sh
FilePath=$1
FileName=$2
Message=$3
MailList=$4
cd $FilePath
Rec_count=$(wc -l < $FileName)
if [ $Rec_count -gt 0 ]
then
(echo "The attachment contains $Message" ; uuencode $FileName $FileName.csv ) | mailx -s "$Message" $MailList
fi*
... | 3,802 |
<p>Best way to center a <code><div></code> element on a page both vertically and horizontally?</p>
<p>I know that <code>margin-left: auto; margin-right: auto;</code> will center on the horizontal, but what is the best way to do it vertically, too?</p>
| <h2>The best and most flexible way</h2>
<p>The main trick in this demo is that in the normal flow of elements going from top to bottom, so the <code>margin-top: auto</code> is set to zero. However, an absolutely positioned element acts the same for distribution of free space, and similarly can be centered vertically at... | <p>This solution worked for me</p>
<pre><code> .middleDiv{
position : absolute;
height : 90%;
bottom: 5%;
}
</code></pre>
<p>(or height : 70% / bottom : 15% </p>
<p>height : 40% / bottom :30% ...) </p>
| 46,527 |
<p>What is the best way to convert a double to a long without casting?</p>
<p>For example:</p>
<pre><code>double d = 394.000;
long l = (new Double(d)).longValue();
System.out.println("double=" + d + ", long=" + l);
</code></pre>
| <p>Assuming you're happy with truncating towards zero, just cast:</p>
<pre><code>double d = 1234.56;
long x = (long) d; // x = 1234
</code></pre>
<p>This will be faster than going via the wrapper classes - and more importantly, it's more readable. Now, if you need rounding other than "always towards zero" you'll need... | <p>Simply put, casting is more efficient than creating a Double object.</p>
| 41,623 |
<p>We are currently designing a website that will be accessed from kiosks in a museum. Users will need to be able to browse through a number of different web pages that will currently contain static HTML content as well as go through various interactive presentations that will be based on flash and run in flash player.... | <p>You can have the same content, but you should have different CSS files. The touchscreen version will need to employ much larger fonts, and in some cases a touchscreen keyboard, whereas the home users won't need that.</p>
<p>Further, you may want to promote museum events on the sidebar of the home version to get pe... | <p>Using a browser for your UI seems like a good decision, the things I would be worried about would be other apps or even browser pop-ups coming up that would interfere with the usability of your kiosk. Possible mitigation for this is to create your own browser app using the Microsoft WebBrowser control to ensure the... | 29,122 |
<p>These seem to mean the same thing. But what term is more appropriate in what context?</p>
| <p>In general terms (and in normal English usage) the terms mean the same thing.</p>
<p>In the specific context of HTML / Javascript the terms get confused because the HTML representation of a DOM element has <em>attributes</em> (that being the term used in XML for the key/value pairs contained within a tag) but when... | <p>Delphi used properties and they have found their way into .NET (because it has the same architect).</p>
<p>In Delphi they are often used in combination with runtime type information such that the integrated property editor can be used to set the property in designtime.</p>
<p>Properties are not always related to f... | 32,268 |
<p>I have a Rake task (in lib/tasks directory) that I run with cron on my shared web hosting. The problem is that I want to compare a UTF-8 string using case statment but my source code is not UTF-8 encoded. If I save source code as UTF-8 there is error when I try to start it :(</p>
<p>What I have to do? </p>
<p>May ... | <p>I found that my problem was not in case statment</p>
<p>The problem was that when I save my source code in UTF-8 format, my text editor add 3 bytes (BOM) at the beginning to indicate that encoding is UTF-8.</p>
<blockquote>
<p><strong>Q: What is a BOM?</strong></p>
<p><strong>A:</strong> A byte order mark (BOM) cons... | <p>Try using the <code>mb_chars</code> method from Rails' <a href="http://api.rubyonrails.org/classes/ActiveSupport/Multibyte/Chars.html" rel="nofollow noreferrer">ActiveSupport</a> framework:</p>
<pre><code>result = case utf8string.mb_chars
when 'АБВ': 1
when 'ГДИ': 2
when 'ЙКЛ': 3
when 'МНО': 4
else 5... | 46,013 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.