qid
int64
4
8.14M
question
stringlengths
20
48.3k
answers
list
date
stringlengths
10
10
metadata
list
input
stringlengths
12
45k
output
stringlengths
2
31.8k
16,178
<p>I need to programatically determine whether .NET 3.5 is installed. I thought it would be easy:</p> <pre><code>&lt;% Response.Write(Environment.Version.ToString()); %&gt; </code></pre> <p>Which returns "2.0.50727.1434" so no such luck...</p> <p>In my research I have that there are some rather obscure registry keys...
[ { "answer_id": 16187, "author": "Nick Berardi", "author_id": 17, "author_profile": "https://Stackoverflow.com/users/17", "pm_score": 2, "selected": false, "text": "<p>That is because technically .NET 3.5 is an extension of the 2.0 framework. The quickest way is to include an assembly fr...
2008/08/19
[ "https://Stackoverflow.com/questions/16178", "https://Stackoverflow.com", "https://Stackoverflow.com/users/285/" ]
I need to programatically determine whether .NET 3.5 is installed. I thought it would be easy: ``` <% Response.Write(Environment.Version.ToString()); %> ``` Which returns "2.0.50727.1434" so no such luck... In my research I have that there are some rather obscure registry keys I can look at but I'm not sure if that...
You could try: ``` static bool HasNet35() { try { AppDomain.CurrentDomain.Load( "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); return true; } catch { return false; } } ``` @[Nick](https://stackoverflow.com/questions/16178...
16,265
<p>I'm working with LINQ for the first time and wanted to get the Mapping to work when I have a money type in SQL, but my domain object property is of type double. How can I express this in the XML file, or in code so that the mapping does not throw the usual "invalid cast" exception?</p>
[ { "answer_id": 16270, "author": "JamesSugrue", "author_id": 1075, "author_profile": "https://Stackoverflow.com/users/1075", "pm_score": 1, "selected": false, "text": "<p>pretty sure Money maps to System.Decimal</p>\n\n<p><a href=\"http://msdn.microsoft.com/en-us/library/bb386947.aspx\" r...
2008/08/19
[ "https://Stackoverflow.com/questions/16265", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I'm working with LINQ for the first time and wanted to get the Mapping to work when I have a money type in SQL, but my domain object property is of type double. How can I express this in the XML file, or in code so that the mapping does not throw the usual "invalid cast" exception?
In the DBML XML file, you can set the Expression attribute of a Column element to something like this: ``` <Column Name="Table1.Amount" DbType="smallint" Type="System.Int32" Expression="CAST(Table1.Amount as int)" /> ```
16,298
<p>I have 2 hosts and I would like to point a subdomain on host one to a subdomain on host two:</p> <pre><code>subdomain.hostone.com --&gt; subdomain.hosttwo.com </code></pre> <p>I added a CNAME record to host one that points to subdomain.hosttwo.com but all I get is a '<strong>400 Bad Request</strong>' Error.</p> <...
[ { "answer_id": 16307, "author": "Nick Berardi", "author_id": 17, "author_profile": "https://Stackoverflow.com/users/17", "pm_score": 2, "selected": false, "text": "<p>It sounds like the web server on hosttwo.com doesn't allow undefined domains to be passed through. You also said you wan...
2008/08/19
[ "https://Stackoverflow.com/questions/16298", "https://Stackoverflow.com", "https://Stackoverflow.com/users/117/" ]
I have 2 hosts and I would like to point a subdomain on host one to a subdomain on host two: ``` subdomain.hostone.com --> subdomain.hosttwo.com ``` I added a CNAME record to host one that points to subdomain.hosttwo.com but all I get is a '**400 Bad Request**' Error. Can anyone see what I'm doing wrong?
Try changing it to "subdomain -> subdomain.hosttwo.com" The `CNAME` is an alias for a certain domain, so when you go to the control panel for hostone.com, you shouldn't have to enter the whole name into the `CNAME` alias. As far as the error you are getting, can you log onto subdomain.hostwo.com and check the logs?
16,306
<p>What would be the easiest way to separate the directory name from the file name when dealing with <code>SaveFileDialog.FileName</code> in C#?</p>
[ { "answer_id": 16313, "author": "rjzii", "author_id": 1185, "author_profile": "https://Stackoverflow.com/users/1185", "pm_score": 0, "selected": false, "text": "<p>Since the forward slash is not allowed in the filename, one simple way is to divide the SaveFileDialog.Filename using String...
2008/08/19
[ "https://Stackoverflow.com/questions/16306", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41/" ]
What would be the easiest way to separate the directory name from the file name when dealing with `SaveFileDialog.FileName` in C#?
Use: ``` System.IO.Path.GetDirectoryName(saveDialog.FileName) ``` (and the corresponding `System.IO.Path.GetFileName`). The Path class is really rather useful.
16,320
<p>I've seen projects where the classes in the DB layer have just static functions in them and other projects where those classes need to be instantiated to get access to the member functions. </p> <blockquote> <p>Which is "better" and why?</p> </blockquote>
[ { "answer_id": 16342, "author": "lomaxx", "author_id": 493, "author_profile": "https://Stackoverflow.com/users/493", "pm_score": 1, "selected": false, "text": "<p>It's all about the purpose of the DB Layer.\nIf you use an instance to access the DB layer, you are allowing multiple version...
2008/08/19
[ "https://Stackoverflow.com/questions/16320", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1463/" ]
I've seen projects where the classes in the DB layer have just static functions in them and other projects where those classes need to be instantiated to get access to the member functions. > > Which is "better" and why? > > >
I like a single object to be correlated to a single record in the database, i.e. an object must be instantiated. This is your basic [ActiveRecord](http://martinfowler.com/eaaCatalog/activeRecord.html) pattern. In my experience, the one-object-to-one-row approach creates a much more fluid and literate presentation in co...
16,340
<p>Say I have an object that stores a byte array and I want to be able to efficiently generate a hashcode for it. I've used the cryptographic hash functions for this in the past because they are easy to implement, but they are doing a lot more work than they should to be cryptographically oneway, and I don't care about...
[ { "answer_id": 16378, "author": "fulmicoton", "author_id": 446497, "author_profile": "https://Stackoverflow.com/users/446497", "pm_score": 2, "selected": false, "text": "<p>If you are looking for performance, I tested a few hash keys, and \nI recommend <a href=\"http://burtleburtle.net/b...
2008/08/19
[ "https://Stackoverflow.com/questions/16340", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1948/" ]
Say I have an object that stores a byte array and I want to be able to efficiently generate a hashcode for it. I've used the cryptographic hash functions for this in the past because they are easy to implement, but they are doing a lot more work than they should to be cryptographically oneway, and I don't care about th...
The hash code of an object does not need to be unique. The checking rule is: * Are the hash codes equal? Then call the full (slow) `Equals` method. * Are the hash codes not equal? Then the two items are definitely not equal. All you want is a `GetHashCode` algorithm that splits up your collection into roughly even...
16,403
<p>One of my biggest typographical frustrations about HTML is the way that it mangles conjoined whitespace. For example if I have:</p> <pre><code>&lt;span&gt;Following punctuation rules. With two spaces after the period. &lt;/span&gt; </code></pre> <p>One of the two spaces following the period will be considered t...
[ { "answer_id": 16410, "author": "Kevin", "author_id": 40, "author_profile": "https://Stackoverflow.com/users/40", "pm_score": 1, "selected": false, "text": "<p>You can use a styled pre block to preserve whitespace. Most WYSIWYG editors also insert &amp;nbsp; for you...</p>\n\n<p>Overall...
2008/08/19
[ "https://Stackoverflow.com/questions/16403", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1948/" ]
One of my biggest typographical frustrations about HTML is the way that it mangles conjoined whitespace. For example if I have: ``` <span>Following punctuation rules. With two spaces after the period. </span> ``` One of the two spaces following the period will be considered to be insignificant whitespace and be re...
For your specific example, there is no need to worry about it. Web browsers perform typographical rendering and place the correct amount of space between periods and whatever character follows (and it's different depending on the next character, according to kerning rules.) If you want line breaks, <br/> isn't really ...
16,432
<p>Let's say that you want to output or concat strings. Which of the following styles do you prefer?</p> <ul> <li><p><code>var p = new { FirstName = "Bill", LastName = "Gates" };</code></p></li> <li><p><code>Console.WriteLine("{0} {1}", p.FirstName, p.LastName);</code></p></li> <li><p><code>Console.WriteLine(p.FirstNa...
[ { "answer_id": 16436, "author": "Adam Haile", "author_id": 194, "author_profile": "https://Stackoverflow.com/users/194", "pm_score": 1, "selected": false, "text": "<p>Personally, the second one as everything you are using is in the direct order it will be output in. Whereas with the fir...
2008/08/19
[ "https://Stackoverflow.com/questions/16432", "https://Stackoverflow.com", "https://Stackoverflow.com/users/920/" ]
Let's say that you want to output or concat strings. Which of the following styles do you prefer? * `var p = new { FirstName = "Bill", LastName = "Gates" };` * `Console.WriteLine("{0} {1}", p.FirstName, p.LastName);` * `Console.WriteLine(p.FirstName + " " + p.LastName);` Do you rather use format or do you simply conc...
Try this code. It's a slightly modified version of your code. 1. I removed Console.WriteLine as it's probably a few orders of magnitude slower than what I'm trying to measure. 2. I'm starting the Stopwatch before the loop and stopping it right after, this way I'm not losing precision if the function takes for examp...
16,447
<p>I am trying to generate a report by querying 2 databases (Sybase) in classic ASP.</p> <p>I have created 2 connection strings:<br></p> <blockquote> <p>connA for databaseA<br> connB for databaseB</p> </blockquote> <p>Both databases are present on the same server (don't know if this matters)<br></p> <p>Queries:</p> <p>...
[ { "answer_id": 16461, "author": "SQLMenace", "author_id": 740, "author_profile": "https://Stackoverflow.com/users/740", "pm_score": 2, "selected": false, "text": "<p>your temp table is out of scope, it is only 'alive' during the first connection and will not be available in the 2nd conne...
2008/08/19
[ "https://Stackoverflow.com/questions/16447", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1311/" ]
I am trying to generate a report by querying 2 databases (Sybase) in classic ASP. I have created 2 connection strings: > > connA for databaseA > > connB for databaseB > > > Both databases are present on the same server (don't know if this matters) Queries: `q1 = SELECT column1 INTO #temp FROM databaseA....
With both queries, it looks like you are trying to insert into #temp. #temp is located on one of the databases (for arguments sake, databaseA). So when you try to insert into #temp from databaseB, it reports that it does not exist. Try changing it from *Into **#temp** From* to *Into **databaseA.dbo.#temp** From* in bo...
16,458
<p>I'm using <code>ColdFusion</code> to return a result set from a SQL database and turn it into a list.</p> <p>I need some way to generate an alphabetical navigation bar for that list. I have ColdFusion and the jQuery library available.</p> <p>I'm looking to generate something like this:</p> <pre><code>A | B | C |...
[ { "answer_id": 16545, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "<p>I would get the SQL result set to return the list in the first place, you can easily just take the first letter of the requi...
2008/08/19
[ "https://Stackoverflow.com/questions/16458", "https://Stackoverflow.com", "https://Stackoverflow.com/users/666/" ]
I'm using `ColdFusion` to return a result set from a SQL database and turn it into a list. I need some way to generate an alphabetical navigation bar for that list. I have ColdFusion and the jQuery library available. I'm looking to generate something like this: ``` A | B | C | ...      - A - A - B - B - B - C - D ...
So, there were plenty of good suggestions, but none did exactly what I wanted. Fortunately I was able to use them to figure out what I really wanted to do. The only thing the following doesn't do is print the last few unused letters (if there are any). That's why I have that cfif statement checking for 'W' as that's th...
16,460
<p>I was writing some <strong>ASP.NET</strong> control when I came to the scenario where I needed to remove items from a list, only when they matched a certain condition.</p> <p>The <code>RemoveAll</code> method of the generic <code>List</code> class does a good job, but removes <em>all</em> items that match the condi...
[ { "answer_id": 16464, "author": "mercutio", "author_id": 1951, "author_profile": "https://Stackoverflow.com/users/1951", "pm_score": 1, "selected": false, "text": "<p>Unless the method provides a \"limit\" parameter (which it doesn't) your best option is to go with a simple loop that rem...
2008/08/19
[ "https://Stackoverflow.com/questions/16460", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1801/" ]
I was writing some **ASP.NET** control when I came to the scenario where I needed to remove items from a list, only when they matched a certain condition. The `RemoveAll` method of the generic `List` class does a good job, but removes *all* items that match the condition, specified by the predicate. What if I want to...
If you want to specify both a limit for number of items to remove and a condition to select the items to remove, you can use this approach: ``` int limit = 30; // Suppose you want to remove 30 items at most list.RemoveAll(item => ShouldIRemoveThis(item) && limit-- > 0); ```
16,473
<p>Say we have the following method:</p> <pre><code>private MyObject foo = new MyObject(); // and later in the class public void PotentialMemoryLeaker(){ int firedCount = 0; foo.AnEvent += (o,e) =&gt; { firedCount++;Console.Write(firedCount);}; foo.MethodThatFiresAnEvent(); } </code></pre> <p>If the class wit...
[ { "answer_id": 16484, "author": "Lasse V. Karlsen", "author_id": 267, "author_profile": "https://Stackoverflow.com/users/267", "pm_score": 5, "selected": true, "text": "<p>Yes, save it to a variable and unhook it.</p>\n\n<pre><code>DelegateType evt = (o, e) =&gt; { firedCount++; Console....
2008/08/19
[ "https://Stackoverflow.com/questions/16473", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Say we have the following method: ``` private MyObject foo = new MyObject(); // and later in the class public void PotentialMemoryLeaker(){ int firedCount = 0; foo.AnEvent += (o,e) => { firedCount++;Console.Write(firedCount);}; foo.MethodThatFiresAnEvent(); } ``` If the class with this method is instantiated...
Yes, save it to a variable and unhook it. ``` DelegateType evt = (o, e) => { firedCount++; Console.Write(firedCount); }; foo.AnEvent += evt; foo.MethodThatFiresAnEvent(); foo.AnEvent -= evt; ``` And yes, if you don't, you'll *leak* memory, as you'll hook up a new delegate object each time. You'll also notice this be...
16,483
<p>How can I convince Firefox (3.0.1, if it matters) to send an If-Modified-Since header in an HTTPS request? It sends the header if the request uses plain HTTP and my server dutifully honors it. But when I request the same resource from the same server using HTTPS instead (i.e., simply changing the http:// in the UR...
[ { "answer_id": 16490, "author": "Nick Berardi", "author_id": 17, "author_profile": "https://Stackoverflow.com/users/17", "pm_score": 2, "selected": false, "text": "<p>HTTPS requests are not cached so sending an <strong>If-Modified-Since</strong> doesn't make any sense. The not caching i...
2008/08/19
[ "https://Stackoverflow.com/questions/16483", "https://Stackoverflow.com", "https://Stackoverflow.com/users/164/" ]
How can I convince Firefox (3.0.1, if it matters) to send an If-Modified-Since header in an HTTPS request? It sends the header if the request uses plain HTTP and my server dutifully honors it. But when I request the same resource from the same server using HTTPS instead (i.e., simply changing the http:// in the URL to ...
> > HTTPS requests are not cached so sending an If-Modified-Since doesn't make any sense. The not caching is a security precaution. > > > The not caching **on disk** is a security pre-caution, but it seems it indeed affects the **If-Modified-Since** behavior (glancing over the code). Try setting the Firefox prefe...
16,487
<p>I am using SourceForge for some Open Source projects and I want to automate the deployment of releases to the SourceForge File Release System. I use Maven for my builds and the standard SFTP deployment mechanism doesn't seem to work unless you do some manual preparation work. I have come across some old postings on ...
[ { "answer_id": 17779, "author": "Brian Matthews", "author_id": 1969, "author_profile": "https://Stackoverflow.com/users/1969", "pm_score": 0, "selected": false, "text": "<p>The Maven SourceForge plug-in does not work with Maven 2. Also I believe this plug-in uses FTP which is no longer s...
2008/08/19
[ "https://Stackoverflow.com/questions/16487", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1969/" ]
I am using SourceForge for some Open Source projects and I want to automate the deployment of releases to the SourceForge File Release System. I use Maven for my builds and the standard SFTP deployment mechanism doesn't seem to work unless you do some manual preparation work. I have come across some old postings on oth...
I'm not able to test this to confirm, but I believe it is possible without writing any plugins. You can [deploy to SourceForge using SCP](http://sourceforge.net/apps/trac/sourceforge/wiki/SCP), and the maven-deploy-plugin can be configured to [use SCP](http://maven.apache.org/plugins/maven-deploy-plugin/examples/deplo...
16,501
<p>For a person without a comp-sci background, what is a lambda in the world of Computer Science?</p>
[ { "answer_id": 16504, "author": "Mark Cidade", "author_id": 1659, "author_profile": "https://Stackoverflow.com/users/1659", "pm_score": 6, "selected": false, "text": "<p>It refers to <a href=\"http://en.wikipedia.org/wiki/Lambda_calculus\" rel=\"noreferrer\">lambda calculus</a>, which is...
2008/08/19
[ "https://Stackoverflow.com/questions/16501", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1344/" ]
For a person without a comp-sci background, what is a lambda in the world of Computer Science?
Lambda comes from the [Lambda Calculus](http://en.wikipedia.org/wiki/Lambda_calculus) and refers to anonymous functions in programming. Why is this cool? It allows you to write quick throw away functions without naming them. It also provides a nice way to write closures. With that power you can do things like this. *...
16,563
<p>So I'm working on a project that will allow users to enter <strong>poker hand histories</strong> from sites like PokerStars and then display the hand to them.</p> <p>It seems that regex would be a great tool for this, however I rank my regex knowledge at "slim to none".</p> <p>So I'm using PHP and looping through ...
[ { "answer_id": 16569, "author": "Ellen Teapot", "author_id": 1914, "author_profile": "https://Stackoverflow.com/users/1914", "pm_score": 2, "selected": false, "text": "<p>Look at the PCRE section in the PHP Manual. Also, <a href=\"http://www.regular-expressions.info/\" rel=\"nofollow nor...
2008/08/19
[ "https://Stackoverflow.com/questions/16563", "https://Stackoverflow.com", "https://Stackoverflow.com/users/428190/" ]
So I'm working on a project that will allow users to enter **poker hand histories** from sites like PokerStars and then display the hand to them. It seems that regex would be a great tool for this, however I rank my regex knowledge at "slim to none". So I'm using PHP and looping through this block of text line by lin...
Look at the PCRE section in the PHP Manual. Also, <http://www.regular-expressions.info/> is a great site for learning regex. Disclaimer: Regex is very addictive once you learn it.
16,568
<p>I'm interested in learning some (ideally) database agnostic ways of selecting the <em>n</em>th row from a database table. It would also be interesting to see how this can be achieved using the native functionality of the following databases: </p> <ul> <li>SQL Server</li> <li>MySQL</li> <li>PostgreSQL</li> <li>SQLit...
[ { "answer_id": 16570, "author": "Andrew G. Johnson", "author_id": 428190, "author_profile": "https://Stackoverflow.com/users/428190", "pm_score": 2, "selected": false, "text": "<p>ADD:</p>\n\n<pre><code>LIMIT n,1\n</code></pre>\n\n<p>That will limit the results to one result starting at ...
2008/08/19
[ "https://Stackoverflow.com/questions/16568", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1944/" ]
I'm interested in learning some (ideally) database agnostic ways of selecting the *n*th row from a database table. It would also be interesting to see how this can be achieved using the native functionality of the following databases: * SQL Server * MySQL * PostgreSQL * SQLite * Oracle I am currently doing something...
There are ways of doing this in optional parts of the standard, but a lot of databases support their own way of doing it. A really good site that talks about this and other things is <http://troels.arvin.dk/db/rdbms/#select-limit>. Basically, PostgreSQL and MySQL supports the non-standard: ``` SELECT... LIMIT y OFFS...
16,638
<p>I am having some trouble with the <a href="http://code.google.com/apis/maps/documentation/reference.html" rel="nofollow noreferrer">Google Maps API</a>. I have an array which holds a ojbect I created to store points.</p> <p>My array and class:</p> <pre><code>var tPoints = []; function tPoint(name) { va...
[ { "answer_id": 16655, "author": "Eric Z Beard", "author_id": 1219, "author_profile": "https://Stackoverflow.com/users/1219", "pm_score": 3, "selected": true, "text": "<p>Maybe a CLR stored procedure is what you are looking for. These are generally used when you need to interact with the...
2008/08/19
[ "https://Stackoverflow.com/questions/16638", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1992/" ]
I am having some trouble with the [Google Maps API](http://code.google.com/apis/maps/documentation/reference.html). I have an array which holds a ojbect I created to store points. My array and class: ``` var tPoints = []; function tPoint(name) { var id = name; var points = []; var pointsCo...
Maybe a CLR stored procedure is what you are looking for. These are generally used when you need to interact with the system in some way.
16,656
<p>I am working on a program that needs to create a multiple temporary folders for the application. These will not be seen by the user. The app is written in VB.net. I can think of a few ways to do it such as incremental folder name or random numbered folder names, but I was wondering, how other people solve this probl...
[ { "answer_id": 16667, "author": "jwalkerjr", "author_id": 689, "author_profile": "https://Stackoverflow.com/users/689", "pm_score": 1, "selected": false, "text": "<p>As long as the name of the folder doesn't need to be meaningful, how about using a GUID for them?</p>\n" }, { "ans...
2008/08/19
[ "https://Stackoverflow.com/questions/16656", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1632/" ]
I am working on a program that needs to create a multiple temporary folders for the application. These will not be seen by the user. The app is written in VB.net. I can think of a few ways to do it such as incremental folder name or random numbered folder names, but I was wondering, how other people solve this problem?
**Update:** Added File.Exists check per comment (2012-Jun-19) Here's what I've used in VB.NET. Essentially the same as presented, except I usually didn't want to create the folder immediately. The advantage to use [GetRandomFilename](http://msdn.microsoft.com/en-us/library/system.io.path.getrandomfilename.aspx) is t...
16,747
<p>I am building a public website using ASP.NET, as part of the deliverable I need to do an Admin Site for data entry of the stuff shown in the public site, I was wondering what techniques or procedures are people using to validate entries using ASP.NET MVC.</p>
[ { "answer_id": 25606, "author": "Daniel Pollard", "author_id": 2758, "author_profile": "https://Stackoverflow.com/users/2758", "pm_score": 6, "selected": true, "text": "<p>Take a look at the <a href=\"http://bassistance.de/jquery-plugins/jquery-plugin-validation/\" rel=\"noreferrer\">JQu...
2008/08/19
[ "https://Stackoverflow.com/questions/16747", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1549/" ]
I am building a public website using ASP.NET, as part of the deliverable I need to do an Admin Site for data entry of the stuff shown in the public site, I was wondering what techniques or procedures are people using to validate entries using ASP.NET MVC.
Take a look at the [JQuery Validation plugin](http://bassistance.de/jquery-plugins/jquery-plugin-validation/) this plugin is amazing,it's clean to implement and has all the features you could ever need, including remote validation via AJAX. Also a sample MVC controller method can be found [here](http://httpcode.com/bl...
16,770
<p>I'm trying to fully understand all of Haskell's concepts.</p> <p>In what ways are algebraic data types similar to generic types, e.g., in C# and Java? And how are they different? What's so algebraic about them anyway? </p> <p>I'm familiar with universal algebra and its rings and fields, but I only have a vague ide...
[ { "answer_id": 16810, "author": "olliej", "author_id": 784, "author_profile": "https://Stackoverflow.com/users/784", "pm_score": 6, "selected": true, "text": "<p>\"Algebraic Data Types\" in Haskell support <em>full parametric polymorphism</em>, which is the more technically correct name ...
2008/08/19
[ "https://Stackoverflow.com/questions/16770", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1659/" ]
I'm trying to fully understand all of Haskell's concepts. In what ways are algebraic data types similar to generic types, e.g., in C# and Java? And how are they different? What's so algebraic about them anyway? I'm familiar with universal algebra and its rings and fields, but I only have a vague idea of how Haskell'...
"Algebraic Data Types" in Haskell support *full parametric polymorphism*, which is the more technically correct name for generics, as a simple example the list data type: ``` data List a = Cons a (List a) | Nil ``` Is equivalent (as much as is possible, and ignoring non-strict evaluation, etc) to ``` class List<a...
16,795
<p>PHP has a great function called <a href="http://us2.php.net/manual/en/function.htmlspecialchars.php" rel="noreferrer">htmlspecialcharacters()</a> where you pass it a string and it replaces all of HTML's special characters with their safe equivalents, it's <em>almost</em> a one stop shop for sanitizing input. Very ni...
[ { "answer_id": 16801, "author": "Forgotten Semicolon", "author_id": 1960, "author_profile": "https://Stackoverflow.com/users/1960", "pm_score": 3, "selected": false, "text": "<p><a href=\"https://msdn.microsoft.com/en-us/library/system.web.httputility.htmlencode(v=vs.110).aspx\" rel=\"no...
2008/08/19
[ "https://Stackoverflow.com/questions/16795", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1366/" ]
PHP has a great function called [htmlspecialcharacters()](http://us2.php.net/manual/en/function.htmlspecialchars.php) where you pass it a string and it replaces all of HTML's special characters with their safe equivalents, it's *almost* a one stop shop for sanitizing input. Very nice right? Well is there an equivalent...
Try this. ``` var encodedHtml = HttpContext.Current.Server.HtmlEncode(...); ```
16,815
<p>I'm trying to do a simple test php script for sessions. Basically it increments a counter (stored in <code>$_SESSION</code>) every time you refresh that page. That works, but I'm trying to have a link to destroy the session which reloads the page with the <code>?destroy=1</code> parameter. I've tried a couple of if ...
[ { "answer_id": 16818, "author": "Andrew G. Johnson", "author_id": 428190, "author_profile": "https://Stackoverflow.com/users/428190", "pm_score": 4, "selected": true, "text": "<p>I think you put</p>\n\n<pre><code>$_POST['destroy']\n</code></pre>\n\n<p>Instead of</p>\n\n<pre><code>$_GET['...
2008/08/19
[ "https://Stackoverflow.com/questions/16815", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1912/" ]
I'm trying to do a simple test php script for sessions. Basically it increments a counter (stored in `$_SESSION`) every time you refresh that page. That works, but I'm trying to have a link to destroy the session which reloads the page with the `?destroy=1` parameter. I've tried a couple of if statements to see if that...
I think you put ``` $_POST['destroy'] ``` Instead of ``` $_GET['destroy'] ``` You need to use a form if you'd like to use a $\_POST variable. $\_GET variables are stored in the URL.
16,828
<p>It seems like the only way to do this is to pass the -i parameter in when you initially run less. Does anyone know of some secret hack to make something like this work</p> <pre><code>/something to search for/i </code></pre>
[ { "answer_id": 16837, "author": "Juha Syrjälä", "author_id": 1431, "author_profile": "https://Stackoverflow.com/users/1431", "pm_score": 10, "selected": true, "text": "<p>You can also type command <code>-I</code> while less is running. It toggles case sensitivity for searches.</p>\n" }...
2008/08/19
[ "https://Stackoverflow.com/questions/16828", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1797/" ]
It seems like the only way to do this is to pass the -i parameter in when you initially run less. Does anyone know of some secret hack to make something like this work ``` /something to search for/i ```
You can also type command `-I` while less is running. It toggles case sensitivity for searches.
16,833
<p>I need to periodically download, extract and save the contents of <a href="http://data.dot.state.mn.us/dds/det_sample.xml.gz" rel="noreferrer">http://data.dot.state.mn.us/dds/det_sample.xml.gz</a> to disk. Anyone have experience downloading gzipped files with C#?</p>
[ { "answer_id": 16841, "author": "Patrick", "author_id": 429, "author_profile": "https://Stackoverflow.com/users/429", "pm_score": 2, "selected": false, "text": "<p>The <a href=\"http://msdn.microsoft.com/en-us/library/system.io.compression.gzipstream.aspx\" rel=\"nofollow noreferrer\">GZ...
2008/08/19
[ "https://Stackoverflow.com/questions/16833", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1786/" ]
I need to periodically download, extract and save the contents of <http://data.dot.state.mn.us/dds/det_sample.xml.gz> to disk. Anyone have experience downloading gzipped files with C#?
To compress: ``` using (FileStream fStream = new FileStream(@"C:\test.docx.gzip", FileMode.Create, FileAccess.Write)) { using (GZipStream zipStream = new GZipStream(fStream, CompressionMode.Compress)) { byte[] inputfile = File.ReadAllBytes(@"c:\test.docx"); zipStream.Write(inputfile, 0, input...
16,861
<p>What is the best way to sanitize user input for a Python-based web application? Is there a single function to remove HTML characters and any other necessary characters combinations to prevent an <a href="http://en.wikipedia.org/wiki/Cross-site_scripting" rel="noreferrer">XSS</a> or SQL injection attack?</p>
[ { "answer_id": 16875, "author": "Justin Standard", "author_id": 92, "author_profile": "https://Stackoverflow.com/users/92", "pm_score": 0, "selected": false, "text": "<p>If you are using a framework like <a href=\"http://www.djangoproject.com/\" rel=\"nofollow noreferrer\">django</a>, th...
2008/08/19
[ "https://Stackoverflow.com/questions/16861", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2019/" ]
What is the best way to sanitize user input for a Python-based web application? Is there a single function to remove HTML characters and any other necessary characters combinations to prevent an [XSS](http://en.wikipedia.org/wiki/Cross-site_scripting) or SQL injection attack?
Here is a snippet that will remove all tags not on the white list, and all tag attributes not on the attribues whitelist (so you can't use `onclick`). It is a modified version of <http://www.djangosnippets.org/snippets/205/>, with the regex on the attribute values to prevent people from using `href="javascript:..."`, ...
16,935
<p>I'm trying to compile over 100 java classes from different packages from a clean directory (no incremental compiles) using the following ant tasks:</p> <pre><code>&lt;target name="-main-src-depend"&gt; &lt;depend srcdir="${src.dir}" destdir="${bin.dir}" cache="${cache.dir}" ...
[ { "answer_id": 16953, "author": "McDowell", "author_id": 304, "author_profile": "https://Stackoverflow.com/users/304", "pm_score": 1, "selected": false, "text": "<p>Does this happen when you run the javac command from the command line? You might want to try the <a href=\"http://ant.apach...
2008/08/19
[ "https://Stackoverflow.com/questions/16935", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2024/" ]
I'm trying to compile over 100 java classes from different packages from a clean directory (no incremental compiles) using the following ant tasks: ``` <target name="-main-src-depend"> <depend srcdir="${src.dir}" destdir="${bin.dir}" cache="${cache.dir}" closure="true"/> </tar...
> > It will be nice to know; what can > cause or causes a StackOverflowError > during compilation of Java code? > > > It is probable that evaluating the long expression in your java file consumes lots of memory and because this is being done in conjunction with the compilation of other classes, the VM just runs ...
16,945
<p>I would like to rename files and folders recursively by applying a string replacement operation.</p> <p>E.g. The word "shark" in files and folders should be replaced by the word "orca".</p> <p><code>C:\Program Files\Shark Tools\Wire Shark\Sharky 10\Shark.exe</code> </p> <p>should be moved to:</p> <p><code>C:\Pro...
[ { "answer_id": 17028, "author": "EBGreen", "author_id": 1358, "author_profile": "https://Stackoverflow.com/users/1358", "pm_score": 1, "selected": false, "text": "<p>So you would use recursion. Here is a powershell example that should be easy to convert to C#:</p>\n\n<pre><code>function ...
2008/08/19
[ "https://Stackoverflow.com/questions/16945", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I would like to rename files and folders recursively by applying a string replacement operation. E.g. The word "shark" in files and folders should be replaced by the word "orca". `C:\Program Files\Shark Tools\Wire Shark\Sharky 10\Shark.exe` should be moved to: `C:\Program Files\Orca Tools\Wire Orca\Orcay 10\Orca.e...
So you would use recursion. Here is a powershell example that should be easy to convert to C#: ``` function Move-Stuff($folder) { foreach($sub in [System.IO.Directory]::GetDirectories($folder)) { Move-Stuff $sub } $new = $folder.Replace("Shark", "Orca") if(!(Test-Path($new))) { ...
16,964
<p>I'm trying to implement something like this:</p> <pre><code>&lt;div&gt; &lt;table&gt; &lt;thead&gt; &lt;tr&gt; &lt;td&gt;Port name&lt;/td&gt; &lt;td&gt;Current port version&lt;/td&gt; &lt;td&gt;New port version&lt;/td&gt; &lt;td...
[ { "answer_id": 17024, "author": "Andrew Rimmer", "author_id": 1982, "author_profile": "https://Stackoverflow.com/users/1982", "pm_score": 3, "selected": true, "text": "<p>You don't want to use a Webforms button in ASP.NET MVC. MVC is a completely different way of working, and you no long...
2008/08/19
[ "https://Stackoverflow.com/questions/16964", "https://Stackoverflow.com", "https://Stackoverflow.com/users/614/" ]
I'm trying to implement something like this: ``` <div> <table> <thead> <tr> <td>Port name</td> <td>Current port version</td> <td>New port version</td> <td>Update</td> </tr> </thead> <% foreach (var ip in...
You don't want to use a Webforms button in ASP.NET MVC. MVC is a completely different way of working, and you no longer have the WebForms abstraction. You have 2 different options you can either replace your asp:Button with an input tag or use a standard hyperlink instead. If you use the input option then you will ne...
16,971
<p>I would like to have a nice template for doing this in development. How do I reset an increment identity's starting value in SQL Server?</p>
[ { "answer_id": 16977, "author": "Ryan Sampson", "author_id": 1375, "author_profile": "https://Stackoverflow.com/users/1375", "pm_score": 8, "selected": true, "text": "<pre><code>DBCC CHECKIDENT('TableName', RESEED, 0)\n</code></pre>\n" }, { "answer_id": 16983, "author": "Keit...
2008/08/19
[ "https://Stackoverflow.com/questions/16971", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1976/" ]
I would like to have a nice template for doing this in development. How do I reset an increment identity's starting value in SQL Server?
``` DBCC CHECKIDENT('TableName', RESEED, 0) ```
16,998
<p>I'm having trouble reading a "chunked" response when using a StreamReader to read the stream returned by GetResponseStream() of a HttpWebResponse:</p> <pre><code>// response is an HttpWebResponse StreamReader reader = new StreamReader(response.GetResponseStream()); string output = reader.ReadToEnd(); // throws exce...
[ { "answer_id": 17236, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": true, "text": "<p>Haven't tried it this with a \"chunked\" response but would something like this work? </p>\n\n<pre><code>StringBuilder sb = n...
2008/08/19
[ "https://Stackoverflow.com/questions/16998", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2047/" ]
I'm having trouble reading a "chunked" response when using a StreamReader to read the stream returned by GetResponseStream() of a HttpWebResponse: ``` // response is an HttpWebResponse StreamReader reader = new StreamReader(response.GetResponseStream()); string output = reader.ReadToEnd(); // throws exception... ``` ...
Haven't tried it this with a "chunked" response but would something like this work? ``` StringBuilder sb = new StringBuilder(); Byte[] buf = new byte[8192]; Stream resStream = response.GetResponseStream(); string tmpString = null; int count = 0; do { count = resStream.Read(buf, 0, buf.Length); if(count != 0...
17,017
<p>How do I convert a DateTime structure to its equivalent <a href="http://www.ietf.org/rfc/rfc3339.txt" rel="noreferrer">RFC 3339</a> formatted string representation and/or parse this string representation back to a <a href="http://msdn.microsoft.com/en-us/library/system.datetime.aspx" rel="noreferrer">DateTime</a> st...
[ { "answer_id": 17021, "author": "Oppositional", "author_id": 2029, "author_profile": "https://Stackoverflow.com/users/2029", "pm_score": 6, "selected": true, "text": "<p>This is an implementation in C# of how to parse and convert a DateTime to and from its RFC-3339 representation. The on...
2008/08/19
[ "https://Stackoverflow.com/questions/17017", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2029/" ]
How do I convert a DateTime structure to its equivalent [RFC 3339](http://www.ietf.org/rfc/rfc3339.txt) formatted string representation and/or parse this string representation back to a [DateTime](http://msdn.microsoft.com/en-us/library/system.datetime.aspx) structure? The RFC-3339 date-time format is used in a number ...
This is an implementation in C# of how to parse and convert a DateTime to and from its RFC-3339 representation. The only restriction it has is that the DateTime is in Coordinated Universal Time (UTC). ``` using System; using System.Globalization; namespace DateTimeConsoleApplication { /// <summary> /// Provid...
17,032
<p><a href="http://resharper.blogspot.com/2008/03/varification-using-implicitly-typed.html" rel="noreferrer">Resharper</a> certainly thinks so, and out of the box it will nag you to convert</p> <pre><code>Dooberry dooberry = new Dooberry(); </code></pre> <p>to</p> <pre><code>var dooberry = new Dooberry(); </code></p...
[ { "answer_id": 17041, "author": "John Sheehan", "author_id": 1786, "author_profile": "https://Stackoverflow.com/users/1786", "pm_score": 2, "selected": false, "text": "<p>I have a feeling this will be one of the most popular questions asked over time on Stack Overflow. It boils down to p...
2008/08/19
[ "https://Stackoverflow.com/questions/17032", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1853/" ]
[Resharper](http://resharper.blogspot.com/2008/03/varification-using-implicitly-typed.html) certainly thinks so, and out of the box it will nag you to convert ``` Dooberry dooberry = new Dooberry(); ``` to ``` var dooberry = new Dooberry(); ``` Is that really considered the best style?
It's of course a matter of style, but I agree with Dare: [C# 3.0 Implicit Type Declarations: To var or not to var?](http://www.25hoursaday.com/weblog/2008/05/21/C30ImplicitTypeDeclarationsToVarOrNotToVar.aspx). I think using var instead of an explicit type makes your code less readable.In the following code: ``` var r...
17,054
<p>How do you use network sockets in Pascal? ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­</p>
[ { "answer_id": 17062, "author": "Mickey", "author_id": 1494, "author_profile": "https://Stackoverflow.com/users/1494", "pm_score": 4, "selected": true, "text": "<p>Here's an example taken from <a href=\"http://www.bastisoft.de/programmierung/pascal/pasinet.html\" rel=\"nofollow noreferre...
2008/08/19
[ "https://Stackoverflow.com/questions/17054", "https://Stackoverflow.com", "https://Stackoverflow.com/users/868/" ]
How do you use network sockets in Pascal? ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
Here's an example taken from <http://www.bastisoft.de/programmierung/pascal/pasinet.html> ``` program daytime; { Simple client program } uses sockets, inetaux, myerror; const RemotePort : Word = 13; var Sock : LongInt; sAddr : TInetSockAddr; sin, sout : Text; Line : String; begin if ParamCoun...
17,056
<p>I'm currently working on an application where we have a SQL-Server database and I need to get a full text search working that allows us to search people's names.</p> <p>Currently the user can enter a into a name field that searches 3 different varchar cols. First, Last, Middle names</p> <p>So say I have 3 rows wit...
[ { "answer_id": 18072, "author": "Biri", "author_id": 968, "author_profile": "https://Stackoverflow.com/users/968", "pm_score": 2, "selected": false, "text": "<p>FreeTextTable should work.</p>\n\n<pre><code>INNER JOIN FREETEXTTABLE(Person, (LastName, Firstname, MiddleName), @SearchString)...
2008/08/19
[ "https://Stackoverflow.com/questions/17056", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1925/" ]
I'm currently working on an application where we have a SQL-Server database and I need to get a full text search working that allows us to search people's names. Currently the user can enter a into a name field that searches 3 different varchar cols. First, Last, Middle names So say I have 3 rows with the following i...
Thanks for the responses guys I finally was able to get it to work. With part of both Biri, and Kibbee's answers. I needed to add \* to the string and break it up on spaces in order to work. So in the end I got ``` .... @Name nvarchar(100), .... --""s added to prevent crash if searching on more then one word. DECLARE ...
17,085
<p>I have a simple CAML query like</p> <pre><code>&lt;Where&gt;&lt;Eq&gt;&lt;Field="FieldName"&gt;&lt;Value Type="Text"&gt;Value text&lt;/Value&gt;&lt;/Field&gt;&lt;/Eq&gt;&lt;/Where&gt; </code></pre> <p>And I have a variable to substitute for <code>Value text</code>. What's the best way to validate/escape the text t...
[ { "answer_id": 17093, "author": "Darren Kopp", "author_id": 77, "author_profile": "https://Stackoverflow.com/users/77", "pm_score": 0, "selected": false, "text": "<p>use <code>System.Xml.Linq.XElement</code> and <code>SetValue</code> method. This will format the text <em>(assuming a stri...
2008/08/19
[ "https://Stackoverflow.com/questions/17085", "https://Stackoverflow.com", "https://Stackoverflow.com/users/578/" ]
I have a simple CAML query like ``` <Where><Eq><Field="FieldName"><Value Type="Text">Value text</Value></Field></Eq></Where> ``` And I have a variable to substitute for `Value text`. What's the best way to validate/escape the text that is substituted here in the .NET framework? I've done a quick web search on this p...
When working with XML, always use the XML API that works with your programming environment. Don't try to roll your own XML document building and escaping code. As Longhorn213 mentioned, in .Net all the appropriate stuff is in the System.XML namespace. Trying to to write your own code for writing XML documents will just...
17,125
<p>I know what <code>yield</code> does, and I've seen a few examples, but I can't think of real life applications, have you used it to solve some specific problem?</p> <p>(Ideally some problem that cannot be solved some other way)</p>
[ { "answer_id": 17133, "author": "Nick Berardi", "author_id": 17, "author_profile": "https://Stackoverflow.com/users/17", "pm_score": 3, "selected": false, "text": "<p>actually I use it in a non traditional way on my site <a href=\"http://www.ideapipe.com\" rel=\"noreferrer\">IdeaPipe</a>...
2008/08/19
[ "https://Stackoverflow.com/questions/17125", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1782/" ]
I know what `yield` does, and I've seen a few examples, but I can't think of real life applications, have you used it to solve some specific problem? (Ideally some problem that cannot be solved some other way)
I realise this is an old question (pre Jon Skeet?) but I have been considering this question myself just lately. Unfortunately the current answers here (in my opinion) don't mention the most obvious advantage of the yield statement. The biggest benefit of the yield statement is that it allows you to iterate over very ...
17,140
<p>How do you run an external program and pass it command line parameters using C? If you have to use operating system API, include a solution for Windows, Mac, and Linux.</p>
[ { "answer_id": 17148, "author": "wilhelmtell", "author_id": 456, "author_profile": "https://Stackoverflow.com/users/456", "pm_score": 4, "selected": false, "text": "<pre><code>#include &lt;stdlib.h&gt;\n\nint main()\n{\n system(\"echo HAI\");\n\n return 0;\n}\n</code></pre>\n" },...
2008/08/19
[ "https://Stackoverflow.com/questions/17140", "https://Stackoverflow.com", "https://Stackoverflow.com/users/432/" ]
How do you run an external program and pass it command line parameters using C? If you have to use operating system API, include a solution for Windows, Mac, and Linux.
It really depends on what you're trying to do, exactly, as it's: 1. OS dependent 2. Not quite clear what you're trying to do. Nevertheless, I'll try to provide some information for you to decide. On UNIX, `fork()` creates a clone of your process from the place where you called fork. Meaning, if I have the followin...
17,172
<p>I've tried to do this several times with no luck. After reading <a href="https://stackoverflow.com/questions/1451/what-is-the-best-way-to-handle-multiple-permission-types#1477">this post</a>, it made me interested in doing this again. So can anyone tell me why the following doesn't work?</p> <pre><code>&lt;?php ...
[ { "answer_id": 17173, "author": "Espen Herseth Halvorsen", "author_id": 1542, "author_profile": "https://Stackoverflow.com/users/1542", "pm_score": 2, "selected": false, "text": "<p>It's been a long time since I used PHP, but I will assume that this will work:</p>\n\n<pre><code>&lt;?php\...
2008/08/19
[ "https://Stackoverflow.com/questions/17172", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40/" ]
I've tried to do this several times with no luck. After reading [this post](https://stackoverflow.com/questions/1451/what-is-the-best-way-to-handle-multiple-permission-types#1477), it made me interested in doing this again. So can anyone tell me why the following doesn't work? ``` <?php $guest = 1; $editor = 2; $admi...
Use the bitwise OR operator (|) to set bits, use the AND operator (&) to check bits. Your code should look like this: ``` <?php $guest = 1; $editor = 2; $admin = 4; $user = $editor; if( $user & ($editor | $admin) ) { echo "Test"; } ?> ``` If you don't understand binary and exa...
17,181
<p>In my most C++ project I heavily used ASSERTION statement as following:</p> <pre><code>int doWonderfulThings(const int* fantasticData) { ASSERT(fantasticData); if(!fantasticData) return -1; // ,,, return WOW_VALUE; } </code></pre> <p>But TDD community seems like to enjoy doing something lik...
[ { "answer_id": 17192, "author": "Mark Cidade", "author_id": 1659, "author_profile": "https://Stackoverflow.com/users/1659", "pm_score": 0, "selected": false, "text": "<p>I don't know which particlar TDD subcommunity you're refering to but the TDD patterns I've come across either use Asse...
2008/08/19
[ "https://Stackoverflow.com/questions/17181", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1556/" ]
In my most C++ project I heavily used ASSERTION statement as following: ``` int doWonderfulThings(const int* fantasticData) { ASSERT(fantasticData); if(!fantasticData) return -1; // ,,, return WOW_VALUE; } ``` But TDD community seems like to enjoy doing something like this: ``` int doMoreWon...
In my (limited) experience the first option is quite a bit safer. In a test-case you only test predefined input and compare the outcome, this works well as long as every possible edge-case has been checked. The first option just checks every input and thus tests the 'live' values, it filters out bugs real quickly, howe...
17,194
<p>I have a Monthly Status database view I need to build a report based on. The data in the view looks something like this:</p> <pre><code>Category | Revenue | Yearh | Month Bikes 10 000 2008 1 Bikes 12 000 2008 2 Bikes 12 000 2008 3 Bikes 15 000 2008 ...
[ { "answer_id": 17206, "author": "Christian Hagelid", "author_id": 202, "author_profile": "https://Stackoverflow.com/users/202", "pm_score": 1, "selected": false, "text": "<p>I could be wrong but shouldn't you be using a full outer join instead of just a left join? That way you will be ge...
2008/08/19
[ "https://Stackoverflow.com/questions/17194", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1199387/" ]
I have a Monthly Status database view I need to build a report based on. The data in the view looks something like this: ``` Category | Revenue | Yearh | Month Bikes 10 000 2008 1 Bikes 12 000 2008 2 Bikes 12 000 2008 3 Bikes 15 000 2008 1 Bikes ...
The Case Statement is my best sql friend. You also need a table for time to generate your 0 rev in both months. Assumptions are based on the availability of following tables: > > sales: Category | Revenue | Yearh | > Month > > > and > > tm: Year | Month (populated with all > dates required for reporting) > ...
17,225
<p>In Perl, you can execute system commands using system() or `` (backticks). You can even capture the output of the command into a variable. However, this hides the program execution in the background so that the person executing your script can't see it. </p> <p>Normally this is useful but sometimes I want to see wh...
[ { "answer_id": 17245, "author": "mk.", "author_id": 1797, "author_profile": "https://Stackoverflow.com/users/1797", "pm_score": 3, "selected": false, "text": "<p>Use open instead. Then you can capture the output of the command.</p>\n\n<pre><code>open(LS,\"|ls\");\nprint LS;\n</code></pre...
2008/08/19
[ "https://Stackoverflow.com/questions/17225", "https://Stackoverflow.com", "https://Stackoverflow.com/users/432/" ]
In Perl, you can execute system commands using system() or `` (backticks). You can even capture the output of the command into a variable. However, this hides the program execution in the background so that the person executing your script can't see it. Normally this is useful but sometimes I want to see what is goin...
As I understand, system() will print the result of the command, but not assign it. Eg. ``` [daniel@tux /]$ perl -e '$ls = system("ls"); print "Result: $ls\n"' bin dev home lost+found misc net proc sbin srv System tools var boot etc lib media mnt opt root selinux sys tmp usr Result: 0...
17,250
<p>I am creating an ZIP file with <code>ZipFile</code> in Python 2.5, it works OK so far:</p> <pre><code>import zipfile, os locfile = &quot;test.txt&quot; loczip = os.path.splitext (locfile)[0] + &quot;.zip&quot; zip = zipfile.ZipFile (loczip, &quot;w&quot;) zip.write (locfile) zip.close() </code></pre> <p>But I could...
[ { "answer_id": 17287, "author": "Harley Holcombe", "author_id": 1057, "author_profile": "https://Stackoverflow.com/users/1057", "pm_score": -1, "selected": false, "text": "<p>You can use the <a href=\"http://www.chilkatsoft.com/python.asp\" rel=\"nofollow noreferrer\">Chilkat</a> library...
2008/08/20
[ "https://Stackoverflow.com/questions/17250", "https://Stackoverflow.com", "https://Stackoverflow.com/users/394/" ]
I am creating an ZIP file with `ZipFile` in Python 2.5, it works OK so far: ``` import zipfile, os locfile = "test.txt" loczip = os.path.splitext (locfile)[0] + ".zip" zip = zipfile.ZipFile (loczip, "w") zip.write (locfile) zip.close() ``` But I couldn't find how to encrypt the files in the ZIP file. I could use sy...
I created a simple library to create a password encrypted zip file in python. - [**here**](https://github.com/smihica/pyminizip) ``` import pyminizip compression_level = 5 # 1-9 pyminizip.compress("src.txt", "dst.zip", "password", compression_level) ``` **The library requires zlib.** I have checked that the file c...
17,299
<p>I am trying to build a function in C/C++ to sort an array and replace each value with its "score" or rank. It takes in a double pointer array to an array of ints, and sorts the double pointers based on the dereferenced value of the integers. I have tried quite a few times to make it work, but can't get it down. O...
[ { "answer_id": 17312, "author": "OJ.", "author_id": 611, "author_profile": "https://Stackoverflow.com/users/611", "pm_score": 4, "selected": true, "text": "<p>You're close. You're referencing the address of the array items when you swap, which isn't necessary. The items in the array are ...
2008/08/20
[ "https://Stackoverflow.com/questions/17299", "https://Stackoverflow.com", "https://Stackoverflow.com/users/522/" ]
I am trying to build a function in C/C++ to sort an array and replace each value with its "score" or rank. It takes in a double pointer array to an array of ints, and sorts the double pointers based on the dereferenced value of the integers. I have tried quite a few times to make it work, but can't get it down. Once ag...
You're close. You're referencing the address of the array items when you swap, which isn't necessary. The items in the array are pointers, and that's what needs to be swapped. See below: ``` void SortArray( int ** pArray, int ArrayLength ) { int i, j, flag = 1; // set flag to 1 to begin initial pass int * ...
17,333
<p>What would be the most efficient way to compare two <code>double</code> or two <code>float</code> values?</p> <p>Simply doing this is not correct:</p> <pre><code>bool CompareDoubles1 (double A, double B) { return A == B; } </code></pre> <p>But something like:</p> <pre><code>bool CompareDoubles2 (double A, dou...
[ { "answer_id": 17341, "author": "OJ.", "author_id": 611, "author_profile": "https://Stackoverflow.com/users/611", "pm_score": 8, "selected": false, "text": "<p>The comparison with an epsilon value is what most people do (even in game programming).</p>\n\n<p>You should change your impleme...
2008/08/20
[ "https://Stackoverflow.com/questions/17333", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2057/" ]
What would be the most efficient way to compare two `double` or two `float` values? Simply doing this is not correct: ``` bool CompareDoubles1 (double A, double B) { return A == B; } ``` But something like: ``` bool CompareDoubles2 (double A, double B) { diff = A - B; return (diff < EPSILON) && (-diff < ...
Be extremely careful using any of the other suggestions. It all depends on context. I have spent a long time tracing bugs in a system that presumed `a==b` if `|a-b|<epsilon`. The underlying problems were: 1. The implicit presumption in an algorithm that if `a==b` and `b==c` then `a==c`. 2. Using the same epsilon for ...
17,359
<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....
[ { "answer_id": 17365, "author": "Chris N", "author_id": 1653, "author_profile": "https://Stackoverflow.com/users/1653", "pm_score": 5, "selected": false, "text": "<p>From looking at <code>man mailx</code>, the mailx program does not have an option for attaching a file. You could use anot...
2008/08/20
[ "https://Stackoverflow.com/questions/17359", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1339/" ]
I've created a script that runs every night on my Linux server that uses `mysqldump` 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. I've been abl...
None of the mutt ones worked for me. It was thinking the email address was part of the attachment. Had to do: ``` echo "This is the message body" | mutt -a "/path/to/file.to.attach" -s "subject of message" -- recipient@domain.example ```
17,370
<p>I've been using OpenGL extensions on Windows the <a href="https://stackoverflow.com/questions/14413/using-opengl-extensions-on-windows">painful way</a>. Is GLEW the easier way to go? How do I get started with it?</p>
[ { "answer_id": 17371, "author": "Ashwin Nanjappa", "author_id": 1630, "author_profile": "https://Stackoverflow.com/users/1630", "pm_score": 6, "selected": true, "text": "<p>Yes, the <strong>OpenGL Extension Wrangler Library</strong> (GLEW) is a painless way to use OpenGL extensions on Wi...
2008/08/20
[ "https://Stackoverflow.com/questions/17370", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1630/" ]
I've been using OpenGL extensions on Windows the [painful way](https://stackoverflow.com/questions/14413/using-opengl-extensions-on-windows). Is GLEW the easier way to go? How do I get started with it?
Yes, the **OpenGL Extension Wrangler Library** (GLEW) is a painless way to use OpenGL extensions on Windows. Here's how to get started on it: Identify the OpenGL extension and the extension APIs you wish to use. OpenGL extensions are listed in the [OpenGL Extension Registry](http://www.opengl.org/registry/). Check if...
17,373
<p>How do I open the default mail program with a Subject and Body in a cross-platform way?</p> <p>Unfortunately, this is for a a client app written in Java, not a website.</p> <p>I would like this to work in a cross-platform way (which means Windows and Mac, sorry Linux). I am happy to execute a VBScript in Windows, ...
[ { "answer_id": 17379, "author": "Ryan Farley", "author_id": 1627, "author_profile": "https://Stackoverflow.com/users/1627", "pm_score": 2, "selected": false, "text": "<p>Mailto isn't a bad route to go. But as you mentioned, you'll need to make sure it is encoded correctly. </p>\n\n<p>The...
2008/08/20
[ "https://Stackoverflow.com/questions/17373", "https://Stackoverflow.com", "https://Stackoverflow.com/users/338/" ]
How do I open the default mail program with a Subject and Body in a cross-platform way? Unfortunately, this is for a a client app written in Java, not a website. I would like this to work in a cross-platform way (which means Windows and Mac, sorry Linux). I am happy to execute a VBScript in Windows, or AppleScript in...
In Java 1.6 you have a stardard way to open the default mailer of the platform: [the Desktop.mail(URI) method](http://java.sun.com/javase/6/docs/api/java/awt/Desktop.html).The URI can be used to set all the fields of the mail (sender, recipients, body, subject). You can check a full example of desktop integration in Ja...
17,387
<p>I have a blogengine.net install that requires privatization.</p> <p>I'm doing research work at the moment, but I have to keep my blog/journal private until certain conditions are met.</p> <p>How can I privatize my blogEngine.net install so that readers must log in to read my posts?</p>
[ { "answer_id": 17392, "author": "lomaxx", "author_id": 493, "author_profile": "https://Stackoverflow.com/users/493", "pm_score": 0, "selected": false, "text": "<p>I would think it's possible to do this in the web config file by doing something like the following:</p>\n\n<pre><code>&lt;sy...
2008/08/20
[ "https://Stackoverflow.com/questions/17387", "https://Stackoverflow.com", "https://Stackoverflow.com/users/209/" ]
I have a blogengine.net install that requires privatization. I'm doing research work at the moment, but I have to keep my blog/journal private until certain conditions are met. How can I privatize my blogEngine.net install so that readers must log in to read my posts?
I use this extension. Just save the file as RequireLogin.cs in your App\_Code\Extensions folder and make sure the extension is activated. ``` using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using Sys...
17,434
<p>I have been reading through the <a href="http://yosefk.com/c++fqa/" rel="noreferrer">C++ FAQ</a> and was curious about the <a href="http://yosefk.com/c++fqa/friend.html" rel="noreferrer"><code>friend</code></a> declaration. I personally have never used it, however I am interested in exploring the language. </p> <p>...
[ { "answer_id": 17436, "author": "Ryan Fox", "author_id": 55, "author_profile": "https://Stackoverflow.com/users/55", "pm_score": 0, "selected": false, "text": "<p>When implementing tree algorithms for class, the framework code the prof gave us had the tree class as a friend of the node c...
2008/08/20
[ "https://Stackoverflow.com/questions/17434", "https://Stackoverflow.com", "https://Stackoverflow.com/users/716/" ]
I have been reading through the [C++ FAQ](http://yosefk.com/c++fqa/) and was curious about the [`friend`](http://yosefk.com/c++fqa/friend.html) declaration. I personally have never used it, however I am interested in exploring the language. What is a good example of using `friend`? --- Reading the FAQ a bit longer ...
Firstly (IMO) don't listen to people who say `friend` is not useful. It IS useful. In many situations you will have objects with data or functionality that are not intended to be publicly available. This is particularly true of large codebases with many authors who may only be superficially familiar with different area...
17,469
<p>Try loading <a href="http://www.zodiacwheels.com/images/wheels/blackout_thumb.jpg" rel="noreferrer">this normal .jpg file</a> in Internet Explorer 6.0. I get an error saying the picture won't load. Try it in any other browser and it works fine. What's wrong? The .jpg file is just a normal picture sitting on the web ...
[ { "answer_id": 17471, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 0, "selected": false, "text": "<p>It is possible for other applications to register themselves as a handler for files with a particular extension. Quickt...
2008/08/20
[ "https://Stackoverflow.com/questions/17469", "https://Stackoverflow.com", "https://Stackoverflow.com/users/432/" ]
Try loading [this normal .jpg file](http://www.zodiacwheels.com/images/wheels/blackout_thumb.jpg) in Internet Explorer 6.0. I get an error saying the picture won't load. Try it in any other browser and it works fine. What's wrong? The .jpg file is just a normal picture sitting on the web server. I can even create a sim...
The JPG you uploaded is in [CMYK](http://en.wikipedia.org/wiki/Cmyk), IE and Firefox versions before 3 can't read these. Open it using Photoshop (or anything similar, I'm sure GIMP would work too) and resave it in [RGB](http://en.wikipedia.org/wiki/Rgb). edit: Further Googling makes me suspect that CMYK isn't really a...
17,483
<p>Is anyone aware of a language feature or technique in C++ to prevent a child class from over riding a particular method in the parent class?</p> <pre><code>class Base { public: bool someGuaranteedResult() { return true; } }; class Child : public Base { public: bool someGuaranteedResult() { return false; /*...
[ { "answer_id": 17485, "author": "Ryan Fox", "author_id": 55, "author_profile": "https://Stackoverflow.com/users/55", "pm_score": 0, "selected": false, "text": "<p>If you address the child class as a type of its parent, then a non-virtual function will call the parent class's version.</p>...
2008/08/20
[ "https://Stackoverflow.com/questions/17483", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1366/" ]
Is anyone aware of a language feature or technique in C++ to prevent a child class from over riding a particular method in the parent class? ``` class Base { public: bool someGuaranteedResult() { return true; } }; class Child : public Base { public: bool someGuaranteedResult() { return false; /* Haha I broke ...
A couple of ideas: 1. Make your function private. 2. Do not make your function virtual. This doesn't actually prevent the function from being shadowed by another definition though. Other than that, I'm not aware of a language feature that will lock away your function in such a way which prevents it from being overloa...
17,500
<p>The <code>System.Windows.Threading.DispatcherObject</code> class (which <code>DependencyObject</code> is based on) contains a useful function, called <code>CheckAccess()</code>, that determines whether or not the code is running on the UI thread.</p> <p>When I wanted to use it yesterday, I was puzzled to find out t...
[ { "answer_id": 17507, "author": "Eric Haskins", "author_id": 100, "author_profile": "https://Stackoverflow.com/users/100", "pm_score": 0, "selected": false, "text": "<p>I can't find any documentation that says you shouldn't use those methods directly, but I haven't looked very long.</p>\...
2008/08/20
[ "https://Stackoverflow.com/questions/17500", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2074/" ]
The `System.Windows.Threading.DispatcherObject` class (which `DependencyObject` is based on) contains a useful function, called `CheckAccess()`, that determines whether or not the code is running on the UI thread. When I wanted to use it yesterday, I was puzzled to find out that Intellisense didn't show the function (...
A Microsoft employee [recently stated](http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/bd0e6f6c-cadd-48f1-8e1a-163c2f17e4ca/) CheckAccess is used only for "advanced scenarios", so they hid it from Intellisense. > > "CheckAccess and VerifyAccess have > always been marked to be not visible, > maybe IntelliSe...
17,586
<p>Word wrap is one of the must-have features in a modern text editor.</p> <p>How word wrap be handled? What is the best algorithm for word-wrap?</p> <p>If text is several million lines, how can I make word-wrap very fast?</p> <p>Why do I need the solution? Because my projects must draw text with various zoom level ...
[ { "answer_id": 17601, "author": "Sven Hecht", "author_id": 1168, "author_profile": "https://Stackoverflow.com/users/1168", "pm_score": 2, "selected": false, "text": "<p>With or without hyphenation?</p>\n\n<p>Without it's easy. Just encapsulate your text as wordobjects per word and give t...
2008/08/20
[ "https://Stackoverflow.com/questions/17586", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1556/" ]
Word wrap is one of the must-have features in a modern text editor. How word wrap be handled? What is the best algorithm for word-wrap? If text is several million lines, how can I make word-wrap very fast? Why do I need the solution? Because my projects must draw text with various zoom level and simultaneously beaut...
Here is a word-wrap algorithm I've written in C#. It should be fairly easy to translate into other languages (except perhaps for `IndexOfAny`). ```cs static char[] splitChars = new char[] { ' ', '-', '\t' }; private static string WordWrap(string str, int width) { string[] words = Explode(str, splitChars); in...
17,612
<p>Programmatic solution of course...</p>
[ { "answer_id": 17618, "author": "Ishmaeel", "author_id": 227, "author_profile": "https://Stackoverflow.com/users/227", "pm_score": 4, "selected": false, "text": "<p>You need to delve into unmanaged code. Here's a static class that I've been using:</p>\n\n<pre><code>public static class Re...
2008/08/20
[ "https://Stackoverflow.com/questions/17612", "https://Stackoverflow.com", "https://Stackoverflow.com/users/580/" ]
Programmatic solution of course...
<http://www.daveamenta.com/2008-05/c-delete-a-file-to-the-recycle-bin/> From above: ``` using Microsoft.VisualBasic; string path = @"c:\myfile.txt"; FileIO.FileSystem.DeleteDirectory(path, FileIO.UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); ```
17,624
<p>I have a table with a 'filename' column. I recently performed an insert into this column but in my haste forgot to append the file extension to all the filenames entered. Fortunately they are all '.jpg' images.</p> <p>How can I easily update the 'filename' column of these inserted fields (assuming I can select the...
[ { "answer_id": 17627, "author": "Matt Mitchell", "author_id": 364, "author_profile": "https://Stackoverflow.com/users/364", "pm_score": 6, "selected": true, "text": "<p>The solution is:</p>\n\n<pre><code>UPDATE tablename SET [filename] = RTRIM([filename]) + '.jpg' WHERE id &gt; 50\n</cod...
2008/08/20
[ "https://Stackoverflow.com/questions/17624", "https://Stackoverflow.com", "https://Stackoverflow.com/users/364/" ]
I have a table with a 'filename' column. I recently performed an insert into this column but in my haste forgot to append the file extension to all the filenames entered. Fortunately they are all '.jpg' images. How can I easily update the 'filename' column of these inserted fields (assuming I can select the recent row...
The solution is: ``` UPDATE tablename SET [filename] = RTRIM([filename]) + '.jpg' WHERE id > 50 ``` RTRIM is required because otherwise the [filename] column in its entirety will be selected for the string concatenation i.e. if it is a varchar(20) column and filename is only 10 letters long then it will still select...
17,645
<p>Am I correct in assuming that the only difference between &quot;windows files&quot; and &quot;unix files&quot; is the linebreak?</p> <p>We have a system that has been moved from a windows machine to a unix machine and are having troubles with the format.</p> <p>I need to automate the translation between unix/windows...
[ { "answer_id": 17649, "author": "samjudson", "author_id": 1908, "author_profile": "https://Stackoverflow.com/users/1908", "pm_score": 5, "selected": true, "text": "<p>This is only a difference in text files, where UNIX uses a single Line Feed (LF) to signify a new line, Windows uses a Ca...
2008/08/20
[ "https://Stackoverflow.com/questions/17645", "https://Stackoverflow.com", "https://Stackoverflow.com/users/86/" ]
Am I correct in assuming that the only difference between "windows files" and "unix files" is the linebreak? We have a system that has been moved from a windows machine to a unix machine and are having troubles with the format. I need to automate the translation between unix/windows before the files get delivered to ...
This is only a difference in text files, where UNIX uses a single Line Feed (LF) to signify a new line, Windows uses a Carriage Return/Line Feed (CRLF) and Mac uses just a CR. Binary files there should be no difference (i.e. a JPEG on a windows machine will be byte for byte the same as the same JPEG on a unix box.)
17,664
<p>I have an ASP.net Application that runs on the internal network (well, actually it's running on Sharepoint 2007). </p> <p>I just wonder:</p> <p>Can I somehow retrieve the name of the PC the Client is using? I would have access to Active Directory if that helps. The thing is, people use multiple PCs. So, I cannot ...
[ { "answer_id": 17691, "author": "OJ.", "author_id": 611, "author_profile": "https://Stackoverflow.com/users/611", "pm_score": 2, "selected": false, "text": "<p>Does <a href=\"http://msdn.microsoft.com/en-us/library/system.web.httprequest.userhostname.aspx\" rel=\"nofollow noreferrer\">Sy...
2008/08/20
[ "https://Stackoverflow.com/questions/17664", "https://Stackoverflow.com", "https://Stackoverflow.com/users/91/" ]
I have an ASP.net Application that runs on the internal network (well, actually it's running on Sharepoint 2007). I just wonder: Can I somehow retrieve the name of the PC the Client is using? I would have access to Active Directory if that helps. The thing is, people use multiple PCs. So, I cannot use any manual/sta...
[System.Web.HttpRequest.UserHostname](https://learn.microsoft.com/en-us/dotnet/api/system.web.httprequest.userhostname?redirectedfrom=MSDN&view=netframework-4.8#System_Web_HttpRequest_UserHostName) as suggested in [this answer](https://stackoverflow.com/a/17691/1011722) just returns the IP :-( But I just found this: ...
17,681
<p>I have a <a href="http://www.visualsvn.com/server/" rel="nofollow noreferrer">VisualSVN Server</a> installed on a Windows server, serving several repositories.</p> <p>Since the web-viewer built into VisualSVN server is a minimalistic subversion browser, I'd like to install <a href="http://websvn.tigris.org/" rel="n...
[ { "answer_id": 233587, "author": "Kit Roed", "author_id": 1339, "author_profile": "https://Stackoverflow.com/users/1339", "pm_score": 2, "selected": false, "text": "<p>I'm using VisualSVN Server and I just got done installing Trac. My goal was to get a better web-based repository browse...
2008/08/20
[ "https://Stackoverflow.com/questions/17681", "https://Stackoverflow.com", "https://Stackoverflow.com/users/267/" ]
I have a [VisualSVN Server](http://www.visualsvn.com/server/) installed on a Windows server, serving several repositories. Since the web-viewer built into VisualSVN server is a minimalistic subversion browser, I'd like to install [WebSVN](http://websvn.tigris.org/) on top of my repositories. The problem, however, is ...
I got WebSVN authentication working with VisualSVN server, albeit with a lot of hacking/trial-error customization of my own. Here's how I did it: 1. If you haven't already, install PHP manually by downloading the zip file and going through the online php manual install instructions. I installed PHP to C:\PHP 2. Extra...
17,772
<p>This is probably best shown with an example. I have an enum with attributes:</p> <pre><code>public enum MyEnum { [CustomInfo("This is a custom attrib")] None = 0, [CustomInfo("This is another attrib")] ValueA, [CustomInfo("This has an extra flag", AllowSomething = true)] ValueB, } </code>...
[ { "answer_id": 17807, "author": "JamesSugrue", "author_id": 1075, "author_profile": "https://Stackoverflow.com/users/1075", "pm_score": 5, "selected": true, "text": "<p>This is probably the easiest way.</p>\n\n<p>A quicker way would be to Statically Emit the IL code using Dynamic Method ...
2008/08/20
[ "https://Stackoverflow.com/questions/17772", "https://Stackoverflow.com", "https://Stackoverflow.com/users/905/" ]
This is probably best shown with an example. I have an enum with attributes: ``` public enum MyEnum { [CustomInfo("This is a custom attrib")] None = 0, [CustomInfo("This is another attrib")] ValueA, [CustomInfo("This has an extra flag", AllowSomething = true)] ValueB, } ``` I want to get t...
This is probably the easiest way. A quicker way would be to Statically Emit the IL code using Dynamic Method and ILGenerator. Although I've only used this to GetPropertyInfo, but can't see why you couldn't emit CustomAttributeInfo as well. For example code to emit a getter from a property ``` public delegate object...
17,785
<p>I know this is not programming directly, but it's regarding a development workstation I'm setting up.</p> <p>I've got a Windows Server 2003 machine that needs to be on two LAN segments at the same time. One of them is a 10.17.x.x LAN and the other is 10.16.x.x</p> <p>The problem is that I don't want to be using u...
[ { "answer_id": 17804, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "<p>If you don't move your network cables around and can assign yourself a static IP address on the 10.16.x.x network, you can r...
2008/08/20
[ "https://Stackoverflow.com/questions/17785", "https://Stackoverflow.com", "https://Stackoverflow.com/users/194/" ]
I know this is not programming directly, but it's regarding a development workstation I'm setting up. I've got a Windows Server 2003 machine that needs to be on two LAN segments at the same time. One of them is a 10.17.x.x LAN and the other is 10.16.x.x The problem is that I don't want to be using up the bandwidth on...
I'm no network expert but I have fiddled with the route command a number of times... ``` route add 0.0.0.0 MASK 0.0.0.0 <address of gateway on 10.17.x.x net> ``` Will route all default traffic through the 10.17.x.x gateway, if you find that it still routes through the other interface, you should make sure that the n...
17,786
<p>When compiling my C++ .Net application I get 104 warnings of the type:</p> <pre><code>Warning C4341 - 'XX': signed value is out of range for enum constant </code></pre> <p>Where XX can be</p> <ul> <li>WCHAR</li> <li>LONG</li> <li>BIT</li> <li>BINARY</li> <li>GUID</li> <li>...</li> </ul> <p>I can't seem to remove...
[ { "answer_id": 17790, "author": "Huppie", "author_id": 1830, "author_profile": "https://Stackoverflow.com/users/1830", "pm_score": 2, "selected": false, "text": "<p>In Visual Studio you can always disable specific warnings by going to:</p>\n\n<blockquote>\n <p>Project settings -> C/C++ ...
2008/08/20
[ "https://Stackoverflow.com/questions/17786", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1912/" ]
When compiling my C++ .Net application I get 104 warnings of the type: ``` Warning C4341 - 'XX': signed value is out of range for enum constant ``` Where XX can be * WCHAR * LONG * BIT * BINARY * GUID * ... I can't seem to remove these warnings whatever I do. When I double click on them it takes me to a part of my...
This is a [compiler bug](http://forums.msdn.microsoft.com/en-US/vclanguage/thread/7bc77d72-c223-4d5e-b9f7-4c639c68b624/). Here's [another post](http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=159519&SiteID=1) confirming it's a known issue. I've got the same issue in one of my projects and there's no way to preven...
17,795
<p>I wanted to show the users Name Address (see <a href="http://www.ipchicken.com" rel="nofollow noreferrer">www.ipchicken.com</a>), but the only thing I can find is the IP Address. I tried a reverse lookup, but didn't work either:</p> <pre><code>IPAddress ip = IPAddress.Parse(this.lblIp.Text); string hostName = Dns.G...
[ { "answer_id": 17797, "author": "saniul", "author_id": 52, "author_profile": "https://Stackoverflow.com/users/52", "pm_score": 0, "selected": false, "text": "<p>Not all IP addresses need to have hostnames. I think that's what is happening in your case. Try it ouy with more well-known IP/...
2008/08/20
[ "https://Stackoverflow.com/questions/17795", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2104/" ]
I wanted to show the users Name Address (see [www.ipchicken.com](http://www.ipchicken.com)), but the only thing I can find is the IP Address. I tried a reverse lookup, but didn't work either: ``` IPAddress ip = IPAddress.Parse(this.lblIp.Text); string hostName = Dns.GetHostByAddress(ip).HostName; this.lblHost.Text = h...
Edit of my previous answer. Try (in vb.net): ``` Dim sTmp As String Dim ip As IPHostEntry sTmp = MaskedTextBox1.Text Dim ipAddr As IPAddress = IPAddress.Parse(sTmp) ip = Dns.GetHostEntry(ipAddr) MaskedTextBox2.Text = ip.HostName ``` Dns.resolve appears to be obsolete in later versions of ....
17,870
<p>Is there a way to select data where any one of multiple conditions occur on the same field?</p> <p>Example: I would typically write a statement such as:</p> <pre><code>select * from TABLE where field = 1 or field = 2 or field = 3 </code></pre> <p>Is there a way to instead say something like:</p> <pre><code>selec...
[ { "answer_id": 17872, "author": "mercutio", "author_id": 1951, "author_profile": "https://Stackoverflow.com/users/1951", "pm_score": 6, "selected": true, "text": "<p>Sure thing, the simplest way is this:</p>\n\n<pre><code>select foo from bar where baz in (1,2,3)\n</code></pre>\n" }, ...
2008/08/20
[ "https://Stackoverflow.com/questions/17870", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2116/" ]
Is there a way to select data where any one of multiple conditions occur on the same field? Example: I would typically write a statement such as: ``` select * from TABLE where field = 1 or field = 2 or field = 3 ``` Is there a way to instead say something like: ``` select * from TABLE where field = 1 || 2 || 3 ``...
Sure thing, the simplest way is this: ``` select foo from bar where baz in (1,2,3) ```
17,877
<p>Just looking for the first step basic solution here that keeps the honest people out.</p> <p>Thanks, Mike</p>
[ { "answer_id": 17872, "author": "mercutio", "author_id": 1951, "author_profile": "https://Stackoverflow.com/users/1951", "pm_score": 6, "selected": true, "text": "<p>Sure thing, the simplest way is this:</p>\n\n<pre><code>select foo from bar where baz in (1,2,3)\n</code></pre>\n" }, ...
2008/08/20
[ "https://Stackoverflow.com/questions/17877", "https://Stackoverflow.com", "https://Stackoverflow.com/users/785/" ]
Just looking for the first step basic solution here that keeps the honest people out. Thanks, Mike
Sure thing, the simplest way is this: ``` select foo from bar where baz in (1,2,3) ```
17,880
<p>There is a rich scripting model for Microsoft Office, but not so with Apple iWork, and specifically the word processor Pages. While there are some AppleScript hooks, it looks like the best approach is to manipulate the underlying XML data.</p> <p>This turns out to be pretty ugly because (for example) page breaks ar...
[ { "answer_id": 17892, "author": "Mark Cidade", "author_id": 1659, "author_profile": "https://Stackoverflow.com/users/1659", "pm_score": 1, "selected": false, "text": "<p>You can either use remoting or WCF. See <a href=\"http://msdn.microsoft.com/en-us/library/aa730857(VS.80).aspx#netremo...
2008/08/20
[ "https://Stackoverflow.com/questions/17880", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1854/" ]
There is a rich scripting model for Microsoft Office, but not so with Apple iWork, and specifically the word processor Pages. While there are some AppleScript hooks, it looks like the best approach is to manipulate the underlying XML data. This turns out to be pretty ugly because (for example) page breaks are stored i...
In order for two applications (separate processes) to exchange events, they must agree on how these events are communicated. There are many different ways of doing this, and exactly which method to use may depend on architecture and context. The general term for this kind of information exchange between processes is [I...
17,906
<p>I have a rather classic UI situation - two ListBoxes named <code>SelectedItems</code> and <code>AvailableItems</code> - the idea being that the items you have already selected live in <code>SelectedItems</code>, while the items that are available for adding to <code>SelectedItems</code> (i.e. every item that isn't a...
[ { "answer_id": 18026, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 7, "selected": true, "text": "<p>Here's your solution.</p>\n\n<pre><code>&lt;Button Name=\"btn1\" &gt;click me \n &lt;Button.Style&gt; \n ...
2008/08/20
[ "https://Stackoverflow.com/questions/17906", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2122/" ]
I have a rather classic UI situation - two ListBoxes named `SelectedItems` and `AvailableItems` - the idea being that the items you have already selected live in `SelectedItems`, while the items that are available for adding to `SelectedItems` (i.e. every item that isn't already in there) live in `AvailableItems`. Als...
Here's your solution. ``` <Button Name="btn1" >click me <Button.Style> <Style> <Style.Triggers> <DataTrigger Binding ="{Binding ElementName=list1, Path=SelectedIndex}" Value="-1"> ...
17,911
<p>I've been having some trouble parsing various types of XML within flash (specifically FeedBurner RSS files and YouTube Data API responses). I'm using a <code>URLLoader</code> to load a XML file, and upon <code>Event.COMPLETE</code> creating a new XML object. 75% of the time this work fine, and every now and again I ...
[ { "answer_id": 17963, "author": "Re0sless", "author_id": 2098, "author_profile": "https://Stackoverflow.com/users/2098", "pm_score": 1, "selected": false, "text": "<p>Have you tried checking that the bytes loaded are the same as the total bytes?</p>\n\n<pre><code>URLLoader.bytesLoaded ==...
2008/08/20
[ "https://Stackoverflow.com/questions/17911", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1306/" ]
I've been having some trouble parsing various types of XML within flash (specifically FeedBurner RSS files and YouTube Data API responses). I'm using a `URLLoader` to load a XML file, and upon `Event.COMPLETE` creating a new XML object. 75% of the time this work fine, and every now and again I get this type of exceptio...
Have you tried checking that the bytes loaded are the same as the total bytes? ``` URLLoader.bytesLoaded == URLLoader.bytesTotal ``` That should tell you if the file has finished loading, it wont help with the compleate event firing to early, but it should tell you if its a problem with the xml been read. I am unsu...
17,928
<p>I want to quickly test an ocx. How do I drop that ocx in a console application. I have found some tutorials in CodeProject and but are incomplete. </p>
[ { "answer_id": 19021, "author": "Orion Edwards", "author_id": 234, "author_profile": "https://Stackoverflow.com/users/234", "pm_score": 2, "selected": false, "text": "<p>Isn't an OCX an ActiveX User Control? (something that you put onto a form for the user to interact with)?</p>\n\n<p>Th...
2008/08/20
[ "https://Stackoverflow.com/questions/17928", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1781/" ]
I want to quickly test an ocx. How do I drop that ocx in a console application. I have found some tutorials in CodeProject and but are incomplete.
Sure..it's pretty easy. Here's a fun app I threw together. I'm assuming you have Visual C++. Save to test.cpp and compile: cl.exe /EHsc test.cpp To test with your OCX you'll need to either #import the typelib and use it's CLSID (or just hard-code the CLSID) in the CoCreateInstance call. Using #import will also help d...
17,944
<p>I'm thinking in particular of how to display pagination controls, when using a language such as C# or Java.</p> <p>If I have <em>x</em> items which I want to display in chunks of <em>y</em> per page, how many pages will be needed?</p>
[ { "answer_id": 17949, "author": "Kibbee", "author_id": 1862, "author_profile": "https://Stackoverflow.com/users/1862", "pm_score": -1, "selected": false, "text": "<p>You'll want to do floating point division, and then use the ceiling function, to round up the value to the next integer.</...
2008/08/20
[ "https://Stackoverflow.com/questions/17944", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2084/" ]
I'm thinking in particular of how to display pagination controls, when using a language such as C# or Java. If I have *x* items which I want to display in chunks of *y* per page, how many pages will be needed?
Found an elegant solution: ``` int pageCount = (records + recordsPerPage - 1) / recordsPerPage; ``` Source: [Number Conversion, Roland Backhouse, 2001](http://www.cs.nott.ac.uk/~rcb/G51MPC/slides/NumberLogic.pdf)
17,947
<p>I cant post the code (proprietary issues) but does anyone know what types of things would cause the following error in C#. It is being thrown by a VOIP client that I wrote (using counterpath api) when the call is ended by the other client. The error is:</p> <pre><code>System.AccessViolationException was unhandled ...
[ { "answer_id": 17951, "author": "TK.", "author_id": 1816, "author_profile": "https://Stackoverflow.com/users/1816", "pm_score": 1, "selected": false, "text": "<p>This kind of prolem can occur if you are calling unmanaged code e.g. a dll. It can occur when Marshalling goes horribly wrong....
2008/08/20
[ "https://Stackoverflow.com/questions/17947", "https://Stackoverflow.com", "https://Stackoverflow.com/users/673/" ]
I cant post the code (proprietary issues) but does anyone know what types of things would cause the following error in C#. It is being thrown by a VOIP client that I wrote (using counterpath api) when the call is ended by the other client. The error is: ``` System.AccessViolationException was unhandled Message="Atte...
List of some possibilities: * An object is being used after it has been disposed. This can happen a lot if you are disposing managed object in a finalizer (you should not do that). * An unmannaged implementation of one of the object you are using is bugged and it corrupted the process memory heap. Happens a lot with D...
17,960
<p>Has anyone worked out how to get PowerShell to use <code>app.config</code> files? I have a couple of .NET DLL's I'd like to use in one of my scripts but they expect their own config sections to be present in <code>app.config</code>/<code>web.config</code>.</p>
[ { "answer_id": 18061, "author": "samjudson", "author_id": 1908, "author_profile": "https://Stackoverflow.com/users/1908", "pm_score": 3, "selected": false, "text": "<p>I'm guessing that the settings would have to be in powershell.exe.config in the powershell directory, but that seems to ...
2008/08/20
[ "https://Stackoverflow.com/questions/17960", "https://Stackoverflow.com", "https://Stackoverflow.com/users/419/" ]
Has anyone worked out how to get PowerShell to use `app.config` files? I have a couple of .NET DLL's I'd like to use in one of my scripts but they expect their own config sections to be present in `app.config`/`web.config`.
Cross-referencing with this thread, which helped me with the same question: [Subsonic Access To App.Config Connection Strings From Referenced DLL in Powershell Script](https://stackoverflow.com/questions/2789920/subsonic-access-to-app-config-connection-strings-from-referenced-dll-in-powershel) I added the following to...
17,965
<p>I have a process in Linux that's getting a segmentation fault. How can I tell it to generate a core dump when it fails?</p>
[ { "answer_id": 17994, "author": "Eli Courtwright", "author_id": 1694, "author_profile": "https://Stackoverflow.com/users/1694", "pm_score": 9, "selected": true, "text": "<p>This depends on what shell you are using. If you are using bash, then the ulimit command controls several settings...
2008/08/20
[ "https://Stackoverflow.com/questions/17965", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1084/" ]
I have a process in Linux that's getting a segmentation fault. How can I tell it to generate a core dump when it fails?
This depends on what shell you are using. If you are using bash, then the ulimit command controls several settings relating to program execution, such as whether you should dump core. If you type ``` ulimit -c unlimited ``` then that will tell bash that its programs can dump cores of any size. You can specify a size...
17,980
<p>I've searched for this a little but I have not gotten a particularly straight answer. In C (and I guess C++), how do you determine what comes after the % when using <code>printf</code>?. For example:</p> <pre><code>double radius = 1.0; double area = 0.0; area = calculateArea( radius ); printf( "%10.1f %10.2\n",...
[ { "answer_id": 17987, "author": "Eli Courtwright", "author_id": 1694, "author_profile": "https://Stackoverflow.com/users/1694", "pm_score": 3, "selected": false, "text": "<pre><code>man 3 printf\n</code></pre>\n\n<p>on a Linux system will give you all the information you need. You can a...
2008/08/20
[ "https://Stackoverflow.com/questions/17980", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2128/" ]
I've searched for this a little but I have not gotten a particularly straight answer. In C (and I guess C++), how do you determine what comes after the % when using `printf`?. For example: ``` double radius = 1.0; double area = 0.0; area = calculateArea( radius ); printf( "%10.1f %10.2\n", radius, area ); ``` I ...
<http://en.wikipedia.org/wiki/Printf#printf_format_placeholders> is Wikipedia's reference for format placeholders in printf. <http://www.cplusplus.com/reference/clibrary/cstdio/printf.html> is also helpful Basically in a simple form it's %[width].[precision][type]. Width allows you to make sure that the variable which...
17,984
<p>Alright, this might be a bit of a long shot, but I have having problems getting AnkhSVN to connect from Visual Studio 2005 to an external SVN server. There is a network proxy in the way, but I can't seem to find a way in AnkhSVN to configure the proxy and doesn't seem to be detecting the Internet Explorer proxy conf...
[ { "answer_id": 17987, "author": "Eli Courtwright", "author_id": 1694, "author_profile": "https://Stackoverflow.com/users/1694", "pm_score": 3, "selected": false, "text": "<pre><code>man 3 printf\n</code></pre>\n\n<p>on a Linux system will give you all the information you need. You can a...
2008/08/20
[ "https://Stackoverflow.com/questions/17984", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1185/" ]
Alright, this might be a bit of a long shot, but I have having problems getting AnkhSVN to connect from Visual Studio 2005 to an external SVN server. There is a network proxy in the way, but I can't seem to find a way in AnkhSVN to configure the proxy and doesn't seem to be detecting the Internet Explorer proxy configu...
<http://en.wikipedia.org/wiki/Printf#printf_format_placeholders> is Wikipedia's reference for format placeholders in printf. <http://www.cplusplus.com/reference/clibrary/cstdio/printf.html> is also helpful Basically in a simple form it's %[width].[precision][type]. Width allows you to make sure that the variable which...
18,034
<p>How do I create a self signed SSL certificate for an Apache Server to use while testing a web app?</p>
[ { "answer_id": 18038, "author": "tgmdbm", "author_id": 1851, "author_profile": "https://Stackoverflow.com/users/1851", "pm_score": -1, "selected": false, "text": "<p>Use OpenSSL (<a href=\"http://www.openssl.org/\" rel=\"nofollow noreferrer\">http://www.openssl.org/</a>)</p>\n\n<p>Here's...
2008/08/20
[ "https://Stackoverflow.com/questions/18034", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1310/" ]
How do I create a self signed SSL certificate for an Apache Server to use while testing a web app?
> > **How do I create a self-signed SSL > Certificate for testing purposes?** > > > from [http://httpd.apache.org/docs/2.0/ssl/ssl\_faq.html#selfcert](http://httpd.apache.org/docs/2.0/ssl/ssl_faq.html#selfcert "How do I create a self-signed SSL Certificate for testing purposes?"): 1. Make sure OpenSSL is install...
18,059
<p>I'm using the <code>System.Windows.Forms.WebBrowser</code>, to make a view a-la Visual Studio Start Page. However, it seems the control is catching and handling all exceptions by silently sinking them! No need to tell this is a very unfortunate behaviour.</p> <pre><code>void webBrowserNavigating(object sender, WebB...
[ { "answer_id": 18138, "author": "Judah Gabriel Himango", "author_id": 536, "author_profile": "https://Stackoverflow.com/users/536", "pm_score": 1, "selected": false, "text": "<p>I haven't seen the browser eat exceptions, unless you mean script errors. Script errors can be enabled via the...
2008/08/20
[ "https://Stackoverflow.com/questions/18059", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42/" ]
I'm using the `System.Windows.Forms.WebBrowser`, to make a view a-la Visual Studio Start Page. However, it seems the control is catching and handling all exceptions by silently sinking them! No need to tell this is a very unfortunate behaviour. ``` void webBrowserNavigating(object sender, WebBrowserNavigatingEventArgs...
My best bet why it happens is because there is a native-managed-native boundary to cross. The native part doesn't forward the managed exceptions correctly and there is not much that can be done. I am still hoping for a better answer though.
18,077
<p>I wanted some of those spiffy rounded corners for a web project that I'm currently working on.</p> <p>I thought I'd try to accomplish it using javascript and not CSS in an effort to keep the requests for image files to a minimum (yes, I know that it's possible to combine all required rounded corner shapes into one ...
[ { "answer_id": 19080, "author": "M. Dave Auayan", "author_id": 2007, "author_profile": "https://Stackoverflow.com/users/2007", "pm_score": 2, "selected": false, "text": "<p>Why not use <code>-moz-border-radius</code> and <code>-webkit-border-radius</code> in the stylesheet? It's valid CS...
2008/08/20
[ "https://Stackoverflow.com/questions/18077", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2114/" ]
I wanted some of those spiffy rounded corners for a web project that I'm currently working on. I thought I'd try to accomplish it using javascript and not CSS in an effort to keep the requests for image files to a minimum (yes, I know that it's possible to combine all required rounded corner shapes into one image) and...
How about this? ``` var mozborderAvailable = false; try { if (typeof(document.body.style.MozBorderRadius) !== "undefined") { mozborderAvailable = true; } } catch(err) {} ``` I tested it in Firefox 3 (true) and false in: Safari, IE7, and Opera. (Edit: better undefined test)
18,082
<p>What's the cleanest, most effective way to validate decimal numbers in JavaScript?</p> <p>Bonus points for:</p> <ol> <li>Clarity. Solution should be clean and simple.</li> <li>Cross-platform.</li> </ol> <p>Test cases:</p> <pre><code>01. IsNumeric('-1') =&gt; true 02. IsNumeric('-1.5') =&gt; true 03. IsNu...
[ { "answer_id": 18085, "author": "Michael Haren", "author_id": 29, "author_profile": "https://Stackoverflow.com/users/29", "pm_score": 6, "selected": false, "text": "<p>This way seems to work well:</p>\n\n<pre><code>function IsNumeric(input){\n var RE = /^-{0,1}\\d*\\.{0,1}\\d+$/;\n ...
2008/08/20
[ "https://Stackoverflow.com/questions/18082", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29/" ]
What's the cleanest, most effective way to validate decimal numbers in JavaScript? Bonus points for: 1. Clarity. Solution should be clean and simple. 2. Cross-platform. Test cases: ``` 01. IsNumeric('-1') => true 02. IsNumeric('-1.5') => true 03. IsNumeric('0') => true 04. IsNumeric('0.42') => true...
[@Joel's answer](https://stackoverflow.com/questions/18082/validate-numbers-in-javascript-isnumeric/174921#174921) is pretty close, but it will fail in the following cases: ``` // Whitespace strings: IsNumeric(' ') == true; IsNumeric('\t\t') == true; IsNumeric('\n\r') == true; // Number literals: IsNumeric(-1) ==...
18,097
<p>In C#, if I have an inherited class with a default constructor, do I have to explicitly call the base class' constructor or will it be implicitly called?</p> <pre><code>class BaseClass { public BaseClass() { // ... some code } } class MyClass : BaseClass { public MyClass() // Do I need to pu...
[ { "answer_id": 18100, "author": "Lars Mæhlum", "author_id": 960, "author_profile": "https://Stackoverflow.com/users/960", "pm_score": 0, "selected": false, "text": "<p>AFAIK, you only need to call the base constructor if you need to pass down any values to it.</p>\n" }, { "answer...
2008/08/20
[ "https://Stackoverflow.com/questions/18097", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1463/" ]
In C#, if I have an inherited class with a default constructor, do I have to explicitly call the base class' constructor or will it be implicitly called? ``` class BaseClass { public BaseClass() { // ... some code } } class MyClass : BaseClass { public MyClass() // Do I need to put ": base()" h...
You do not need to explicitly call the base constructor, it will be implicitly called. Extend your example a little and create a Console Application and you can verify this behaviour for yourself: ``` using System; namespace ConsoleApplication1 { class Program { static void Main(string[] args) ...
18,166
<p>I am attempting to POST against a vendor's server using PHP 5.2 with cURL. I'm reading in an XML document to post against their server and then reading in a response:</p> <pre><code>$request = trim(file_get_contents('test.xml')); $curlHandle = curl_init($servletURL); curl_setopt($curlHandle, CURLOPT_POST, TRUE); cu...
[ { "answer_id": 18215, "author": "mercutio", "author_id": 1951, "author_profile": "https://Stackoverflow.com/users/1951", "pm_score": 2, "selected": false, "text": "<p>Not an answer, but I find the whole fopen/fread/fclose thing very dull to peruse when looking at code.</p>\n\n<p>You can ...
2008/08/20
[ "https://Stackoverflow.com/questions/18166", "https://Stackoverflow.com", "https://Stackoverflow.com/users/204/" ]
I am attempting to POST against a vendor's server using PHP 5.2 with cURL. I'm reading in an XML document to post against their server and then reading in a response: ``` $request = trim(file_get_contents('test.xml')); $curlHandle = curl_init($servletURL); curl_setopt($curlHandle, CURLOPT_POST, TRUE); curl_setopt($cur...
It turns out it's an encoding issue. The app apparently needs the XML in www-form-urlencoded instead of form-data so I had to change: ``` # This sets the encoding to multipart/form-data curl_setopt($curlHandle, CURLOPT_POSTFIELDS, array('XML'=>$request)); ``` to ``` # This sets it to application/x-www-form-urlencod...
18,172
<p>I am looking for a robust way to copy files over a Windows network share that is tolerant of intermittent connectivity. The application is often used on wireless, mobile workstations in large hospitals, and I'm assuming connectivity can be lost either momentarily or for several minutes at a time. The files involved ...
[ { "answer_id": 18178, "author": "TheSmurf", "author_id": 1975282, "author_profile": "https://Stackoverflow.com/users/1975282", "pm_score": 3, "selected": false, "text": "<p>Try using BITS (Background Intelligent Transfer Service). It's the infrastructure that Windows Update uses, is acce...
2008/08/20
[ "https://Stackoverflow.com/questions/18172", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2144/" ]
I am looking for a robust way to copy files over a Windows network share that is tolerant of intermittent connectivity. The application is often used on wireless, mobile workstations in large hospitals, and I'm assuming connectivity can be lost either momentarily or for several minutes at a time. The files involved are...
I'm unclear as to what your actual problem is, so I'll throw out a few thoughts. * Do you want restartable copies (with such small file sizes, that doesn't seem like it'd be that big of a deal)? If so, look at [CopyFileEx with COPYFILERESTARTABLE](http://msdn.microsoft.com/en-us/library/aa363852.aspx) * Do you want ve...
18,216
<p>I'm not quite sure if this is possible, or falls into the category of pivot tables, but I figured I'd go to the pros to see.</p> <p>I have three basic tables: Card, Property, and CardProperty. Since cards do not have the same properties, and often multiple values for the same property, I decided to use the union ta...
[ { "answer_id": 18236, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "<p>Don't collapse by concatenation for storage of related records in your database. Its not exactly best practices. </p>\n\n<...
2008/08/20
[ "https://Stackoverflow.com/questions/18216", "https://Stackoverflow.com", "https://Stackoverflow.com/users/71/" ]
I'm not quite sure if this is possible, or falls into the category of pivot tables, but I figured I'd go to the pros to see. I have three basic tables: Card, Property, and CardProperty. Since cards do not have the same properties, and often multiple values for the same property, I decided to use the union table approa...
Is this for SQL server? If yes then [Concatenate Values From Multiple Rows Into One Column (2000)](http://wiki.lessthandot.com/index.php/Concatenate_Values_From_Multiple_Rows_Into_One_Column) [Concatenate Values From Multiple Rows Into One Column Ordered (2005+)](http://wiki.lessthandot.com/index.php/Concatenate_V...
18,223
<p>I have a table in a SQL Server 2005 database with a trigger that is supposed to add a record to a different table whenever a new record is inserted. It seems to work fine, but if I execute an Insert Into on the master table that uses a subquery as the source of the values, the trigger only inserts one record in the ...
[ { "answer_id": 18229, "author": "Andrew Rimmer", "author_id": 1982, "author_profile": "https://Stackoverflow.com/users/1982", "pm_score": 3, "selected": true, "text": "<p>Your trigger is only using the first row from 'Inserted'. This is a common misunderstanding when dealing with SQL tri...
2008/08/20
[ "https://Stackoverflow.com/questions/18223", "https://Stackoverflow.com", "https://Stackoverflow.com/users/741/" ]
I have a table in a SQL Server 2005 database with a trigger that is supposed to add a record to a different table whenever a new record is inserted. It seems to work fine, but if I execute an Insert Into on the master table that uses a subquery as the source of the values, the trigger only inserts one record in the oth...
Your trigger is only using the first row from 'Inserted'. This is a common misunderstanding when dealing with SQL triggers for the first time. The trigger fires per update not per row. For example if you do the following:- update products set title = 'geoff de geoff' this would update all the products, but a trigger...
18,265
<p>What methods are there for automatically getting a stack trace on Unix systems? I don't mean just getting a core file or attaching interactively with GDB, but having a SIGSEGV handler that dumps a backtrace to a text file. </p> <p>Bonus points for the following optional features:</p> <ul> <li>Extra information gat...
[ { "answer_id": 18406, "author": "Derek Park", "author_id": 872, "author_profile": "https://Stackoverflow.com/users/872", "pm_score": 4, "selected": true, "text": "<p>If you are on systems with the BSD <a href=\"http://linux.die.net/man/3/backtrace\" rel=\"nofollow noreferrer\"><code>back...
2008/08/20
[ "https://Stackoverflow.com/questions/18265", "https://Stackoverflow.com", "https://Stackoverflow.com/users/954/" ]
What methods are there for automatically getting a stack trace on Unix systems? I don't mean just getting a core file or attaching interactively with GDB, but having a SIGSEGV handler that dumps a backtrace to a text file. Bonus points for the following optional features: * Extra information gathering at crash time ...
If you are on systems with the BSD [`backtrace`](http://linux.die.net/man/3/backtrace) functionality available (Linux, OSX 1.5, BSD of course), you can do this programmatically in your signal handler. For example ([`backtrace` code derived from IBM example](http://www-128.ibm.com/developerworks/linux/library/l-cppexce...
18,407
<p>If I have a variable in C# that needs to be checked to determine if it is equal to one of a set of variables, what is the best way to do this?</p> <p>I'm not looking for a solution that stores the set in an array. I'm more curious to see if there is a solution that uses boolean logic in some way to get the answer.<...
[ { "answer_id": 18416, "author": "Corey", "author_id": 1595, "author_profile": "https://Stackoverflow.com/users/1595", "pm_score": 5, "selected": true, "text": "<pre><code> bool b = new int[] { 3,7,12,5 }.Contains(5);\n</code></pre>\n" }, { "answer_id": 18423, "author":...
2008/08/20
[ "https://Stackoverflow.com/questions/18407", "https://Stackoverflow.com", "https://Stackoverflow.com/users/392/" ]
If I have a variable in C# that needs to be checked to determine if it is equal to one of a set of variables, what is the best way to do this? I'm not looking for a solution that stores the set in an array. I'm more curious to see if there is a solution that uses boolean logic in some way to get the answer. I know I ...
``` bool b = new int[] { 3,7,12,5 }.Contains(5); ```
18,413
<p>I have a column of data that contains a percentage range as a string that I'd like to convert to a number so I can do easy comparisons.</p> <p>Possible values in the string:</p> <pre><code>'&lt;5%' '5-10%' '10-15%' ... '95-100%' </code></pre> <p>I'd like to convert this in my select where clause to just the first...
[ { "answer_id": 18437, "author": "Shazburg", "author_id": 2165, "author_profile": "https://Stackoverflow.com/users/2165", "pm_score": 0, "selected": false, "text": "<p>You can convert char data to other types of char (convert char(10) to varchar(10)), but you won't be able to convert char...
2008/08/20
[ "https://Stackoverflow.com/questions/18413", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1097/" ]
I have a column of data that contains a percentage range as a string that I'd like to convert to a number so I can do easy comparisons. Possible values in the string: ``` '<5%' '5-10%' '10-15%' ... '95-100%' ``` I'd like to convert this in my select where clause to just the first number, 5, 10, 15, etc. so that I c...
Try this, ``` SELECT substring(replace(interest , '<',''), patindex('%[0-9]%',replace(interest , '<','')), patindex('%[^0-9]%',replace(interest, '<',''))-1) FROM table1 ``` Tested at my end and it works, it's only my first try so you might be able to optimise it.
18,418
<p>When I am writing code in Python, I often need to remove items from a list or other sequence type based on some criteria. I haven't found a solution that is elegant and efficient, as removing items from a list you are currently iterating through is bad. For example, you can't do this:</p> <pre><code>for name in na...
[ { "answer_id": 18424, "author": "nlucaroni", "author_id": 157, "author_profile": "https://Stackoverflow.com/users/157", "pm_score": -1, "selected": false, "text": "<p>Well, this is clearly an issue with the data structure you are using. Use a hashtable for example. Some implementations s...
2008/08/20
[ "https://Stackoverflow.com/questions/18418", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1892/" ]
When I am writing code in Python, I often need to remove items from a list or other sequence type based on some criteria. I haven't found a solution that is elegant and efficient, as removing items from a list you are currently iterating through is bad. For example, you can't do this: ``` for name in names: if nam...
Two easy ways to accomplish just the filtering are: 1. Using `filter`: `names = filter(lambda name: name[-5:] != "Smith", names)` 2. Using list comprehensions: `names = [name for name in names if name[-5:] != "Smith"]` Note that both cases keep the values for which the predicate function evaluates to `True`, so you...
18,419
<p>I've got a combo-box that sits inside of a panel in Flex 3. Basically I want to fade the panel using a Fade effect in ActionScript. I can get the fade to work fine, however the label of the combo-box does not fade. I had this same issue with buttons and found that their fonts needed to be embedded. No problem. ...
[ { "answer_id": 18463, "author": "Matt MacLean", "author_id": 22, "author_profile": "https://Stackoverflow.com/users/22", "pm_score": 2, "selected": false, "text": "<p>Hmm, I am not sure why that isn't working for you. Here is an example of how I got it to work:</p>\n\n<pre><code>&lt;?xml...
2008/08/20
[ "https://Stackoverflow.com/questions/18419", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1290/" ]
I've got a combo-box that sits inside of a panel in Flex 3. Basically I want to fade the panel using a Fade effect in ActionScript. I can get the fade to work fine, however the label of the combo-box does not fade. I had this same issue with buttons and found that their fonts needed to be embedded. No problem. I embedd...
Hmm, I am not sure why that isn't working for you. Here is an example of how I got it to work: ``` <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="fx.play([panel])"> <mx:Style> @font-face { src: local("Arial");...
18,449
<p>For those of us who use standard shared hosting packages, such as GoDaddy or Network Solutions, how do you handle datetime conversions when your hosting server (PHP) and MySQL server are in different time zones?</p> <p>Also, does anybody have some best practice advice for determining what time zone a visitor to you...
[ { "answer_id": 18602, "author": "Joel Meador", "author_id": 1976, "author_profile": "https://Stackoverflow.com/users/1976", "pm_score": 4, "selected": false, "text": "<p>Store everything as UTC. You can do conversions at the client level, or on the server side using client settings.</p>...
2008/08/20
[ "https://Stackoverflow.com/questions/18449", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2056/" ]
For those of us who use standard shared hosting packages, such as GoDaddy or Network Solutions, how do you handle datetime conversions when your hosting server (PHP) and MySQL server are in different time zones? Also, does anybody have some best practice advice for determining what time zone a visitor to your site is ...
As of PHP 5.1.0 you can use [*date\_default\_timezone\_set()*](http://www.php.net/manual/en/function.date-default-timezone-set.php) function to set the default timezone used by all date/time functions in a script. For MySql (quoted from [MySQL Server Time Zone Support](http://dev.mysql.com/doc/refman/4.1/en/time-zone...
18,460
<p>What is the best way to authorize all users to one single page in a asp.net website.</p> <p>For except the login page and one other page, I deny all users from viewing pages in the website. </p> <p>How do you make this page accessible to all users?</p>
[ { "answer_id": 18469, "author": "Dillie-O", "author_id": 71, "author_profile": "https://Stackoverflow.com/users/71", "pm_score": 4, "selected": true, "text": "<p>I've been using forms authentication and creating the necessary GenericIdentity and CustomPrincipal objects that allows me to ...
2008/08/20
[ "https://Stackoverflow.com/questions/18460", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2172/" ]
What is the best way to authorize all users to one single page in a asp.net website. For except the login page and one other page, I deny all users from viewing pages in the website. How do you make this page accessible to all users?
I've been using forms authentication and creating the necessary GenericIdentity and CustomPrincipal objects that allows me to leverage the User.IsInRole type functions you typically only get with Windows authentication. That way in my web.config file, I can do stuff like... ``` <location path="Login.aspx"> <system...
18,465
<p>In .Net you can read a string value into another data type using either <code>&lt;datatype&gt;.parse</code> or <code>Convert.To&lt;DataType&gt;</code>. </p> <p>I'm not familiar with the fundamentals of parse versus convert so I am always at a loss when asked which one is better/faster/more appropriate. </p> <p>So ...
[ { "answer_id": 18474, "author": "TheSmurf", "author_id": 1975282, "author_profile": "https://Stackoverflow.com/users/1975282", "pm_score": 3, "selected": false, "text": "<p>Here's an answer for you:</p>\n\n<p><a href=\"http://www.dotnetspider.com/forum/ViewForum.aspx?ForumId=77428\" rel=...
2008/08/20
[ "https://Stackoverflow.com/questions/18465", "https://Stackoverflow.com", "https://Stackoverflow.com/users/149/" ]
In .Net you can read a string value into another data type using either `<datatype>.parse` or `Convert.To<DataType>`. I'm not familiar with the fundamentals of parse versus convert so I am always at a loss when asked which one is better/faster/more appropriate. So - which way is best in what type of circumstances?
The `Convert.ToXXX()` methods are for objects that might be of the correct or similar type, while `.Parse()` and `.TryParse()` are specifically for strings: ``` //o is actually a boxed int object o = 12345; //unboxes it int castVal = (int) 12345; //o is a boxed enum object o = MyEnum.ValueA; //this will get the und...
18,524
<p>I have a list of integers, <code>List&lt;Integer&gt;</code> and I'd like to convert all the integer objects into Strings, thus finishing up with a new <code>List&lt;String&gt;</code>.</p> <p>Naturally, I could create a new <code>List&lt;String&gt;</code> and loop through the list calling <code>String.valueOf()</cod...
[ { "answer_id": 18529, "author": "jsight", "author_id": 1432, "author_profile": "https://Stackoverflow.com/users/1432", "pm_score": 7, "selected": true, "text": "<p>As far as I know, iterate and instantiate is the only way to do this. Something like (for others potential help, since I'm ...
2008/08/20
[ "https://Stackoverflow.com/questions/18524", "https://Stackoverflow.com", "https://Stackoverflow.com/users/916/" ]
I have a list of integers, `List<Integer>` and I'd like to convert all the integer objects into Strings, thus finishing up with a new `List<String>`. Naturally, I could create a new `List<String>` and loop through the list calling `String.valueOf()` for each integer, but I was wondering if there was a better (read: *m...
As far as I know, iterate and instantiate is the only way to do this. Something like (for others potential help, since I'm sure you know how to do this): ``` List<Integer> oldList = ... /* Specify the size of the list up front to prevent resizing. */ List<String> newList = new ArrayList<>(oldList.size()); for (Integer...
18,538
<p>I'd like some sorthand for this:</p> <pre><code>Map rowToMap(row) { def rowMap = [:]; row.columns.each{ rowMap[it.name] = it.val } return rowMap; } </code></pre> <p>given the way the GDK stuff is, I'd expect to be able to do something like:</p> <pre><code>Map rowToMap(row) { row.columns.collectMap...
[ { "answer_id": 18981, "author": "danb", "author_id": 2031, "author_profile": "https://Stackoverflow.com/users/2031", "pm_score": 1, "selected": false, "text": "<p>I can't find anything built in... but using the ExpandoMetaClass I can do this: </p>\n\n<pre><code>ArrayList.metaClass.collec...
2008/08/20
[ "https://Stackoverflow.com/questions/18538", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2031/" ]
I'd like some sorthand for this: ``` Map rowToMap(row) { def rowMap = [:]; row.columns.each{ rowMap[it.name] = it.val } return rowMap; } ``` given the way the GDK stuff is, I'd expect to be able to do something like: ``` Map rowToMap(row) { row.columns.collectMap{ [it.name,it.val] } } ``` but I ha...
I've recently came across the need to do exactly that: converting a list into a map. This question was posted before Groovy version 1.7.9 came out, so the method [`collectEntries`](http://docs.groovy-lang.org/latest/html/api/org/codehaus/groovy/runtime/DefaultGroovyMethods.html#collectEntries(java.lang.Iterable,%20groo...
18,584
<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/9/how-do-i-calculate-someones-age-in-c">How do I calculate someone&#39;s age in C#?</a> </p> </blockquote> <p>Maybe this could be silly but and I don't have issues with my age but sometimes it is good to calcul...
[ { "answer_id": 18603, "author": "Kevin Crumley", "author_id": 1818, "author_profile": "https://Stackoverflow.com/users/1818", "pm_score": 1, "selected": false, "text": "<blockquote>\n <p>Maybe this could be silly but and I don't have issues with my age but sometimes it is good to calcul...
2008/08/20
[ "https://Stackoverflow.com/questions/18584", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1130097/" ]
> > **Possible Duplicate:** > > [How do I calculate someone's age in C#?](https://stackoverflow.com/questions/9/how-do-i-calculate-someones-age-in-c) > > > Maybe this could be silly but and I don't have issues with my age but sometimes it is good to calculate the exact age of someone, I have introduced my birt...
If you were born on January 12th 1975, you would be 33 years old today. If you were born on December 1st 1975, you would be 32 years old today. If you read the note by the birthday field when editing your profile you'll see it says "YYYY/MM/DD", I'm sure it will try to interpret dates of other formats but it looks li...
18,585
<h3>Update: Solved, with code</h3> <p><a href="https://stackoverflow.com/questions/18585/why-cant-you-bind-the-size-of-a-windows-form-to-applicationsettings#19056">I got it working, see my answer below for the code...</a></p> <h3>Original Post</h3> <p>As Tundey pointed out in <a href="https://stackoverflow.com/question...
[ { "answer_id": 18659, "author": "Rob Cooper", "author_id": 832, "author_profile": "https://Stackoverflow.com/users/832", "pm_score": 1, "selected": false, "text": "<p>Well I have had a quick play with this and you are correct, while there is no way to directly <em>bind</em> the size of t...
2008/08/20
[ "https://Stackoverflow.com/questions/18585", "https://Stackoverflow.com", "https://Stackoverflow.com/users/229/" ]
### Update: Solved, with code [I got it working, see my answer below for the code...](https://stackoverflow.com/questions/18585/why-cant-you-bind-the-size-of-a-windows-form-to-applicationsettings#19056) ### Original Post As Tundey pointed out in [his answer](https://stackoverflow.com/questions/18421/best-way-to-bind...
I finally came up with a Form subclass that solves this, once and for all. To use it: 1. Inherit from RestorableForm instead of Form. 2. Add a binding in (ApplicationSettings) -> (PropertyBinding) to WindowRestoreState. 3. Call Properties.Settings.Default.Save() when the window is about to close. Now window position ...
18,608
<p>I've got a group of inter-related classes that are all overridden together to create a particular implementation. I'm wondering if it is a good idea to enclose the interrelated subclasses in a namespace.</p> <p>For example purposes, consider the following namespaces and classes:</p> <pre><code>namespace Protocol {...
[ { "answer_id": 18616, "author": "Rob Cooper", "author_id": 832, "author_profile": "https://Stackoverflow.com/users/832", "pm_score": 4, "selected": true, "text": "<p>I think you are perhaps worrying too much!</p>\n\n<p>Does it make sense logically? Do you know where to find your code wit...
2008/08/20
[ "https://Stackoverflow.com/questions/18608", "https://Stackoverflow.com", "https://Stackoverflow.com/users/327/" ]
I've got a group of inter-related classes that are all overridden together to create a particular implementation. I'm wondering if it is a good idea to enclose the interrelated subclasses in a namespace. For example purposes, consider the following namespaces and classes: ``` namespace Protocol { public abstract cl...
I think you are perhaps worrying too much! Does it make sense logically? Do you know where to find your code within the namespaces? I would much rather see a codebase like the above with a small number of classes, relevant to the name with a hierarchy, than one large namespace where everything is interrelated.. Reme...
18,617
<p>How do you configure tomcat to bind to a single ip address (localhost) instead of all addresses?</p>
[ { "answer_id": 18623, "author": "ScArcher2", "author_id": 1310, "author_profile": "https://Stackoverflow.com/users/1310", "pm_score": 8, "selected": true, "text": "<p>Several connectors are configured, and each connector has an optional \"address\" attribute where you can set the IP addr...
2008/08/20
[ "https://Stackoverflow.com/questions/18617", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1310/" ]
How do you configure tomcat to bind to a single ip address (localhost) instead of all addresses?
Several connectors are configured, and each connector has an optional "address" attribute where you can set the IP address. 1. Edit `tomcat/conf/server.xml`. 2. Specify a bind address for that connector: ``` <Connector port="8080" protocol="HTTP/1.1" address="127.0.0.1" connectionTimeout="20000" ...
18,661
<p>Is it possible to get UI text from an external application in C#. </p> <p>In particular, is there a way to read Unicode text from a label (I assume it's a normal Windows label control) from an external Win32 app that was written by a 3rd party? The text is visible, but not selectable by mouse in the UI.</p> <p>I a...
[ { "answer_id": 18698, "author": "Lars Truijens", "author_id": 1242, "author_profile": "https://Stackoverflow.com/users/1242", "pm_score": 3, "selected": false, "text": "<p>You could do it if that unicode text is actually a window with a caption by sending a <a href=\"http://msdn.microsof...
2008/08/20
[ "https://Stackoverflow.com/questions/18661", "https://Stackoverflow.com", "https://Stackoverflow.com/users/838/" ]
Is it possible to get UI text from an external application in C#. In particular, is there a way to read Unicode text from a label (I assume it's a normal Windows label control) from an external Win32 app that was written by a 3rd party? The text is visible, but not selectable by mouse in the UI. I assume there is so...
You could do it if that unicode text is actually a window with a caption by sending a [WM\_GETTEXT](http://msdn.microsoft.com/en-us/library/ms632627.aspx) message. ``` [DllImport("user32.dll")] public static extern int SendMessage (IntPtr hWnd, int msg, int Param, System.Text.StringBuilder text); System.Text.StringB...
18,676
<p>I need to generate a random integer between 1 and n (where n is a positive whole number) to use for a unit test. I don't need something overly complicated to ensure true randomness - just an old-fashioned random number.</p> <p>How would I do that?</p>
[ { "answer_id": 18680, "author": "Kibbee", "author_id": 1862, "author_profile": "https://Stackoverflow.com/users/1862", "pm_score": 7, "selected": true, "text": "<p>To get a random integer value between 1 and N (inclusive) you can use the following.</p>\n\n<pre><code>CInt(Math.Ceiling(Rnd...
2008/08/20
[ "https://Stackoverflow.com/questions/18676", "https://Stackoverflow.com", "https://Stackoverflow.com/users/225/" ]
I need to generate a random integer between 1 and n (where n is a positive whole number) to use for a unit test. I don't need something overly complicated to ensure true randomness - just an old-fashioned random number. How would I do that?
To get a random integer value between 1 and N (inclusive) you can use the following. ``` CInt(Math.Ceiling(Rnd() * n)) + 1 ```