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 |
|---|---|---|---|---|---|---|
39,855 | <p>Is it possible to embed a PowerPoint presentation (.ppt) into a webpage (.xhtml)?</p>
<p>This will be used on a local intranet where there is a mix of Internet Explorer 6 and Internet Explorer 7 only, so no need to consider other browsers.</p>
<hr>
<p>I've given up... I guess Flash is the way ... | [
{
"answer_id": 39857,
"author": "matt b",
"author_id": 4249,
"author_profile": "https://Stackoverflow.com/users/4249",
"pm_score": 0,
"selected": false,
"text": "<p>The first few results on Google all sound like good options:</p>\n\n<p><a href=\"http://www.pptfaq.com/FAQ00708.htm\" rel=\... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39855",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/383/"
] | Is it possible to embed a PowerPoint presentation (.ppt) into a webpage (.xhtml)?
This will be used on a local intranet where there is a mix of Internet Explorer 6 and Internet Explorer 7 only, so no need to consider other browsers.
---
I've given up... I guess Flash is the way forward. | Google Docs can serve up PowerPoint (and PDF) documents in it's document viewer. You don't have to sign up for Google Docs, just upload it to your website, and call it from your page:
```
<iframe src="//docs.google.com/gview?url=https://www.yourwebsite.com/powerpoint.ppt&embedded=true" style="width:600px; height:500px... |
39,856 | <p>I have an actionscript file that defines a class that I would like to use inside a Flex application. </p>
<p>I have defined some custom controls in a actionscript file and then import them via the application tag:</p>
<pre>
<code>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:scorecard... | [
{
"answer_id": 39864,
"author": "Herms",
"author_id": 1409,
"author_profile": "https://Stackoverflow.com/users/1409",
"pm_score": 4,
"selected": true,
"text": "<p>You'd need to import the class inside a script tag.</p>\n\n<pre><code><mx:Application\n xmlns:mx=\"http://www.adobe.com/2... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39856",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1638/"
] | I have an actionscript file that defines a class that I would like to use inside a Flex application.
I have defined some custom controls in a actionscript file and then import them via the application tag:
```
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:scorecard="com.apterasoftware.scor... | You'd need to import the class inside a script tag.
```
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
import com.apterasoftware.scorecard.controls.*;
// Other imports go here
// Functions and other code go here
</mx:Script>
<!-- Components and other MXML stuff go here -->... |
39,867 | <p>I have a script that has a part that looks like that:</p>
<pre><code>for file in `ls *.tar.gz`; do
echo encrypting $file
gpg --passphrase-file /home/$USER/.gnupg/backup-passphrase \
--simple-sk-checksum -c $file
done
</code></pre>
<p>For some reason if I run this script manually, works perfectly fine and ... | [
{
"answer_id": 39877,
"author": "Nick Berardi",
"author_id": 17,
"author_profile": "https://Stackoverflow.com/users/17",
"pm_score": 0,
"selected": false,
"text": "<p>make sure the user that is running the cron job has the permissions needed to encrypt the file. </p>\n"
},
{
"an... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39867",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3105/"
] | I have a script that has a part that looks like that:
```
for file in `ls *.tar.gz`; do
echo encrypting $file
gpg --passphrase-file /home/$USER/.gnupg/backup-passphrase \
--simple-sk-checksum -c $file
done
```
For some reason if I run this script manually, works perfectly fine and all files are encrypted. I... | It turns out that the answer was easier than I expected. There is a `--batch` parameter missing, gpg tries to read from /dev/tty that doesn't exist for cron jobs. To debug that I have used `--exit-on-status-write-error` param. But to use that I was inspired by exit status 2, reported by echoing `$?` as Cd-Man suggested... |
39,874 | <p>What data structures would you use to represent a chessboard for a computer chess program?</p>
| [
{
"answer_id": 39881,
"author": "slm",
"author_id": 4262,
"author_profile": "https://Stackoverflow.com/users/4262",
"pm_score": 3,
"selected": false,
"text": "<p>The simple approach is to use an 8x8 integer array. Use 0 for empty squares and assign values for the pieces:</p>\n\n<pre><cod... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39874",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4262/"
] | What data structures would you use to represent a chessboard for a computer chess program? | Initially, use an **8 \* 8 integer array** to represent the chess board.
You can start programing using this notation. Give point values for the pieces. For example:
```
**White**
9 = white queen
5 = white rook
3 = bishop
3 = knight
1 = pawn
**black**
-9 = white queen
-5 = white rook
-3 = bishop
-3 = knight
-1 = paw... |
39,910 | <p>I want to use the MultipleLookupField control in a web page that will run in the context of SharePoint. I was wondering if anyone would help me with an example, which shows step by step how to use the control two display two SPField Collections.</p>
| [
{
"answer_id": 40929,
"author": "Matt Bishop",
"author_id": 4301,
"author_profile": "https://Stackoverflow.com/users/4301",
"pm_score": 3,
"selected": true,
"text": "<p>I'm not entirely sure I understand your question, especially the bit about displaying two SPField collections. Sorry if... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39910",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1360/"
] | I want to use the MultipleLookupField control in a web page that will run in the context of SharePoint. I was wondering if anyone would help me with an example, which shows step by step how to use the control two display two SPField Collections. | I'm not entirely sure I understand your question, especially the bit about displaying two SPField collections. Sorry if this turns out to be the answer to a completely different question!
Anyway here's a quick demo walkthrough of using the MultipleLookupField in a web part.
Create a team site. Add a few tasks to the ... |
39,912 | <p>I was looking at the API documentation for stl vector, and noticed there was no method on the vector class that allowed the removal of an element with a certain value. This seems like a common operation, and it seems odd that there's no built in way to do this.</p>
| [
{
"answer_id": 39923,
"author": "bradtgmurray",
"author_id": 1546,
"author_profile": "https://Stackoverflow.com/users/1546",
"pm_score": 4,
"selected": false,
"text": "<p>Use the global method std::remove with the begin and end iterator, and then use std::vector.erase to actually remove ... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39912",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1546/"
] | I was looking at the API documentation for stl vector, and noticed there was no method on the vector class that allowed the removal of an element with a certain value. This seems like a common operation, and it seems odd that there's no built in way to do this. | `std::remove` does not actually erase elements from the container: it moves the elements to be removed to the end of the container, and returns the new end iterator which can be passed to `container_type::erase` to do the actual removal of the extra elements that are now at the end of the container:
```
std::vector<in... |
39,916 | <p>Is there a programmatic way to build <em>htpasswd</em> files, without depending on OS specific functions (i.e. <code>exec()</code>, <code>passthru()</code>)?</p>
| [
{
"answer_id": 39935,
"author": "Jordi Bunster",
"author_id": 4272,
"author_profile": "https://Stackoverflow.com/users/4272",
"pm_score": -1,
"selected": false,
"text": "<p><a href=\"http://trac.edgewall.org\" rel=\"nofollow noreferrer\">Trac</a> ships with a Python replacement for htpas... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39916",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/115/"
] | Is there a programmatic way to build *htpasswd* files, without depending on OS specific functions (i.e. `exec()`, `passthru()`)? | .httpasswd files are just text files with a specific format depending on the hash function specified. If you are using MD5 they look like this:
```
foo:$apr1$y1cXxW5l$3vapv2yyCXaYz8zGoXj241
```
That's the login, a colon, ,$apr1$, the salt and 1000 times md5 encoded as base64. If you select SHA1 they look like this:
... |
39,928 | <p>I'm getting a <strong><code>Connection Busy With Results From Another Command</code></strong> error from a SQLServer Native Client driver when a SSIS package is running. Only when talking to SQLServer 2000. A different part that talks to SQLServer 2005 seems to always run fine. Any thoughts?</p>
| [
{
"answer_id": 40105,
"author": "Craig",
"author_id": 2894,
"author_profile": "https://Stackoverflow.com/users/2894",
"pm_score": 2,
"selected": true,
"text": "<p><a href=\"http://support.microsoft.com/kb/822668\" rel=\"nofollow noreferrer\">Microsoft KB article 822668</a> is relevant he... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39928",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2978/"
] | I'm getting a **`Connection Busy With Results From Another Command`** error from a SQLServer Native Client driver when a SSIS package is running. Only when talking to SQLServer 2000. A different part that talks to SQLServer 2005 seems to always run fine. Any thoughts? | [Microsoft KB article 822668](http://support.microsoft.com/kb/822668) is relevant here:
>
> FIX: "Connection is busy with results for another command" error message occurs when you run a linked server query
> -------------------------------------------------------------------------------------------------------------... |
39,960 | <p>In Python one can get a dictionary of all local and global variables in the current scope with the built-in functions <code>locals()</code> and <code>globals()</code>. Is there some equivalent way of doing this in Javascript? For instance, I would like to do something like the following:</p>
<pre><code>var foo = ... | [
{
"answer_id": 39982,
"author": "Bartosz Bierkowski",
"author_id": 3666,
"author_profile": "https://Stackoverflow.com/users/3666",
"pm_score": 2,
"selected": false,
"text": "<p>Well, I don't think that there is something like that in js. You can always use eval instead of locals(). Like ... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39960",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/208/"
] | In Python one can get a dictionary of all local and global variables in the current scope with the built-in functions `locals()` and `globals()`. Is there some equivalent way of doing this in Javascript? For instance, I would like to do something like the following:
```
var foo = function(){ alert('foo'); };
var bar =... | * locals() - No.
* globals() - Yes.
`window` is a reference to the global scope, like `globals()` in python.
```
globals()["foo"]
```
is the same as:
```
window["foo"]
``` |
40,022 | <p>I'm using LINQ to SQL classes in a project where the database design is still in a bit of flux.</p>
<p>Is there an easy way of synchronising the classes with the schema, or do I need to manually update the classes if a table design changes?</p>
| [
{
"answer_id": 40027,
"author": "Michael Haren",
"author_id": 29,
"author_profile": "https://Stackoverflow.com/users/29",
"pm_score": 2,
"selected": false,
"text": "<p>I think Jeff complained about this recently. One common technique is to drag all the objects into the designer again...<... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40022",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4048/"
] | I'm using LINQ to SQL classes in a project where the database design is still in a bit of flux.
Is there an easy way of synchronising the classes with the schema, or do I need to manually update the classes if a table design changes? | You can use SQLMetal.exe to generate your dbml and or cs/vb file. Use a pre-build script to start it and target the directory where your datacontext project belongs.
```
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\x64\sqlmetal.exe
/server:<SERVER>
/database:<database>
/code:"path\Solution\DataContextPr... |
40,028 | <p>I think it can be done by applying the transformation matrix of the scenegraph to z-normal (0, 0, 1), but it doesn't work. My code goes like this:</p>
<pre><code>Vector3f toScreenVector = new Vector3f(0, 0, 1);
Transform3D t3d = new Transform3D();
tg.getTransform(t3d); //tg is Transform Group of all objects in a sc... | [
{
"answer_id": 40666,
"author": "caramelcarrot",
"author_id": 3877,
"author_profile": "https://Stackoverflow.com/users/3877",
"pm_score": 2,
"selected": false,
"text": "<p>If I get this right, you want a vector that is normal to the screen plane, but in world coordinates?</p>\n\n<p>In th... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40028",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3388/"
] | I think it can be done by applying the transformation matrix of the scenegraph to z-normal (0, 0, 1), but it doesn't work. My code goes like this:
```
Vector3f toScreenVector = new Vector3f(0, 0, 1);
Transform3D t3d = new Transform3D();
tg.getTransform(t3d); //tg is Transform Group of all objects in a scene
t3d.transf... | Yes, you got my question right. Sorry that I was a little bit confused yesterday. Now I have corrected the code by following your suggestion and mixing two pieces of code in the question together:
```
Vector3f toScreenVector = new Vector3f(0, 0, 1);
Transform3D t3d = new Transform3D();
canvas.getImagePlateToVworld(t3... |
40,043 | <p>How can I create a new database from my C# application?</p>
<p>I'm assuming once I create it, I can simply generate a connection string on the fly and connect to it, and the issue all the CREATE TABLE statements.</p>
| [
{
"answer_id": 40061,
"author": "Espo",
"author_id": 2257,
"author_profile": "https://Stackoverflow.com/users/2257",
"pm_score": 5,
"selected": true,
"text": "<p><a href=\"http://support.microsoft.com/kb/307283\" rel=\"noreferrer\">KB307283</a> explains how to create a database using ADO... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40043",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3314/"
] | How can I create a new database from my C# application?
I'm assuming once I create it, I can simply generate a connection string on the fly and connect to it, and the issue all the CREATE TABLE statements. | [KB307283](http://support.microsoft.com/kb/307283) explains how to create a database using ADO.NET.
From the article:
```
String str;
SqlConnection myConn = new SqlConnection ("Server=localhost;Integrated security=SSPI;database=master");
str = "CREATE DATABASE MyDatabase ON PRIMARY " +
"(NAME = MyDatabase_Data, ... |
40,054 | <p>Code below does not run correctly and throws <code>InvalidOperationExcepiton</code>.</p>
<pre><code>public void Foo()
{
DataContext context = new DataContext();
LinqEntity item = new LinqEntity(){ Id = 1, Name = "John", Surname = "Doe"} ;
context.LinqEntities.Attach(item, true);
}
</code></pre>
| [
{
"answer_id": 40079,
"author": "Adam Lassek",
"author_id": 1249,
"author_profile": "https://Stackoverflow.com/users/1249",
"pm_score": 1,
"selected": false,
"text": "<p>I'm not sure what you mean by disconnected from the database.</p>\n\n<p>It appears that you are trying to insert a new... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40054",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4215/"
] | Code below does not run correctly and throws `InvalidOperationExcepiton`.
```
public void Foo()
{
DataContext context = new DataContext();
LinqEntity item = new LinqEntity(){ Id = 1, Name = "John", Surname = "Doe"} ;
context.LinqEntities.Attach(item, true);
}
``` | By default, the entities will use all fields for checking concurrency when making edits. That's what's throwing the InvalidOperationException.
This can be setting the Update Check property for all fields to Never. This must be done on all fields to attach the entity as modified. If this is done, an additional call to ... |
40,075 | <p>I am writing a few extensions to mimic the map and reduce functions in Lisp.</p>
<pre><code>public delegate R ReduceFunction<T,R>(T t, R previous);
public delegate void TransformFunction<T>(T t, params object[] args);
public static R Reduce<T,R>(this List<T> list, ReduceFunction<T,R> ... | [
{
"answer_id": 40084,
"author": "Jake Pearson",
"author_id": 632,
"author_profile": "https://Stackoverflow.com/users/632",
"pm_score": 2,
"selected": false,
"text": "<p>I would use the built in Func delegates instead. This same code would work on any IEnumerable. Your code would turn i... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40075",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1455/"
] | I am writing a few extensions to mimic the map and reduce functions in Lisp.
```
public delegate R ReduceFunction<T,R>(T t, R previous);
public delegate void TransformFunction<T>(T t, params object[] args);
public static R Reduce<T,R>(this List<T> list, ReduceFunction<T,R> r, R initial)
{
var aggregate = initial... | These look very similar to extensions in Linq already:
```
//takes a function that matches the Func<T,R> delegate
listInstance.Aggregate(
startingValue,
(x, y) => /* aggregate two subsequent values */ );
//takes a function that matches the Action<T> delegate
listInstance.ForEach(
x => /* do something w... |
40,090 | <p>Is it true that the only way to handle default function arguments is through function overloading?</p>
<p>For example, in PHP I can do this:</p>
<pre><code>function foo($x, $y=0)
{
}
</code></pre>
<p>Would the best way to handle it in C# be this?</p>
<pre><code>void foo(int x)
{
foo(x, 0);
}
void foo(int x, i... | [
{
"answer_id": 40093,
"author": "Blair Conrad",
"author_id": 1199,
"author_profile": "https://Stackoverflow.com/users/1199",
"pm_score": 4,
"selected": true,
"text": "<p>Yes, that'd be best<s>, except you'd omit the <code>$</code>s on the parameter names</s>, as others have pointed out. ... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40090",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/305/"
] | Is it true that the only way to handle default function arguments is through function overloading?
For example, in PHP I can do this:
```
function foo($x, $y=0)
{
}
```
Would the best way to handle it in C# be this?
```
void foo(int x)
{
foo(x, 0);
}
void foo(int x, int y)
{
}
```
***[Example lifted from here... | Yes, that'd be best~~, except you'd omit the `$`s on the parameter names~~, as others have pointed out. For those interested in the rationale behind the lack of default parameter values, see @Giovanni Galbo's explanation. |
40,107 | <p>I imagine everyone has seen code like:</p>
<pre><code>public void Server2ClientEnumConvert( ServerEnum server)
{
switch(server)
{
case ServerEnum.One:
return ClientEnum.ABC
//And so on.
</code></pre>
<p>Instead of this badness we could do somthing like:</p>
<pre><code>public enum ... | [
{
"answer_id": 40128,
"author": "bdukes",
"author_id": 2688,
"author_profile": "https://Stackoverflow.com/users/2688",
"pm_score": 0,
"selected": false,
"text": "<p>I would probably use struct as the type, and then throw an exception if it isn't an Enum type. I don't see how your (Type,... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40107",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1455/"
] | I imagine everyone has seen code like:
```
public void Server2ClientEnumConvert( ServerEnum server)
{
switch(server)
{
case ServerEnum.One:
return ClientEnum.ABC
//And so on.
```
Instead of this badness we could do somthing like:
```
public enum ServerEnum
{
[Enum2Enum(ClientEn... | Using almost the same example, you can achieve this directly in the enum:
```
public enum ServerEnum
{
One = ClientEnum.ABC,
}
```
This has the benefit of not requiring Reflection, is easier to read (in my opinion), and overall requires less overhead. |
40,112 | <p>I've got an MS-Access app (1/10th MS-Acccess, 9/10ths MS-SQL) that needs to display photographs of some assets along with their specifications. Currently the images are stored in an MS-Access table as an OLE Object (and copy-n-pasted into the field by the users).</p>
<p>For various reasons, I would like to do is st... | [
{
"answer_id": 40182,
"author": "Daren Thomas",
"author_id": 2260,
"author_profile": "https://Stackoverflow.com/users/2260",
"pm_score": 0,
"selected": false,
"text": "<p>The easiest way is probably to plop an Internet Explorer onto one of your forms. Check out this site: <a href=\"http:... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40112",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/685/"
] | I've got an MS-Access app (1/10th MS-Acccess, 9/10ths MS-SQL) that needs to display photographs of some assets along with their specifications. Currently the images are stored in an MS-Access table as an OLE Object (and copy-n-pasted into the field by the users).
For various reasons, I would like to do is store the or... | Another option is to put an image control on your form. There is a property of that control (Picture) that is simply the path to the image. Here is a short example in VBA of how you might use it.
txtPhoto would be a text box bound to the database field with the path to the image
imgPicture is the image control
The exa... |
40,116 | <p>How do I get it to work with my project?</p>
<p><a href="http://ajax.asp.net/" rel="noreferrer">http://ajax.asp.net/</a></p>
<p><a href="http://www.codeplex.com/AjaxControlToolkit/" rel="noreferrer">http://www.codeplex.com/AjaxControlToolkit/</a></p>
| [
{
"answer_id": 40118,
"author": "Zack Peterson",
"author_id": 83,
"author_profile": "https://Stackoverflow.com/users/83",
"pm_score": 5,
"selected": false,
"text": "<p><strong>Install the ASP.NET AJAX Control Toolkit</strong></p>\n\n<ol>\n<li><p>Download the ZIP file\nAjaxControlToolkit-... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40116",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/83/"
] | How do I get it to work with my project?
<http://ajax.asp.net/>
<http://www.codeplex.com/AjaxControlToolkit/> | **Install the ASP.NET AJAX Control Toolkit**
1. Download the ZIP file
AjaxControlToolkit-Framework3.5SP1-DllOnly.zip
from the [ASP.NET AJAX Control
Toolkit Releases](http://www.codeplex.com/AjaxControlToolkit/Release/ProjectReleases.aspx?ReleaseId=16488) page of the
CodePlex web site.
2. Copy the contents of this zip ... |
40,122 | <p>My group is developing a service-based (.NET WCF) application and we're trying to decide how to handle exceptions in our internal services. Should we throw exceptions? Return exceptions serialized as XML? Just return an error code?</p>
<p>Keep in mind that the user will never see these exceptions, it's only for ... | [
{
"answer_id": 40140,
"author": "Phil Bennett",
"author_id": 2995,
"author_profile": "https://Stackoverflow.com/users/2995",
"pm_score": 1,
"selected": false,
"text": "<p>I'm a bit confused, I'm not being flippant -- you say you want to return exceptions serialised as XML on the one hand... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40122",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4219/"
] | My group is developing a service-based (.NET WCF) application and we're trying to decide how to handle exceptions in our internal services. Should we throw exceptions? Return exceptions serialized as XML? Just return an error code?
Keep in mind that the user will never see these exceptions, it's only for other parts o... | WCF uses `SoapFaults` as its native way of transmitting exceptions from either the service to the client, or the client to the service.
You can declare a custom SOAP fault using the `FaultContract` attribute in your contract interface:
For example:
```
[ServiceContract(Namespace="foobar")]
interface IContract
{
... |
40,125 | <p>I'm trying to get a Firefox plugin to read data from a HTTP get, parse the results and present them as links in a bookmark-like drop-down menu.</p>
<p>My quesion then is: Does anyone have any sample code that will do this?</p>
| [
{
"answer_id": 40167,
"author": "Robert J. Walker",
"author_id": 4287,
"author_profile": "https://Stackoverflow.com/users/4287",
"pm_score": 2,
"selected": false,
"text": "<p>Having never developed one myself, I'm not certain how this is typically done in Firefox plugins, but since plugi... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40125",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4165/"
] | I'm trying to get a Firefox plugin to read data from a HTTP get, parse the results and present them as links in a bookmark-like drop-down menu.
My quesion then is: Does anyone have any sample code that will do this? | Having never developed one myself, I'm not certain how this is typically done in Firefox plugins, but since plugin scripting is JavaScript, I can probably help out with the loading part. Assuming a variable named url containing the URL you want to request:
```
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", ur... |
40,133 | <p>I have been experimenting with <a href="http://www.woopra.com/" rel="nofollow noreferrer">woopra.com</a> A web analytics tool. Which requires a piece of javascript code to be added to each page to function. This is easy enough with more dynamic sites with universal headers or footers but not for totally static html ... | [
{
"answer_id": 40156,
"author": "Grey Panther",
"author_id": 1265,
"author_profile": "https://Stackoverflow.com/users/1265",
"pm_score": 3,
"selected": true,
"text": "<p>I think that <a href=\"http://httpd.apache.org/docs/2.2/mod/mod_ext_filter.html\" rel=\"nofollow noreferrer\">mod_filt... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40133",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3720/"
] | I have been experimenting with [woopra.com](http://www.woopra.com/) A web analytics tool. Which requires a piece of javascript code to be added to each page to function. This is easy enough with more dynamic sites with universal headers or footers but not for totally static html pages.
I attempted to work round it by ... | I think that [mod\_filter\_ext](http://httpd.apache.org/docs/2.2/mod/mod_ext_filter.html) is the module you are looking for. You can write a short Perl script for example to insert the JS code in the pages and register it to process HTML pages:
```
while (<>) {
s/<html>/\Q<script>....\E/;
print $_;
}
```
You... |
40,161 | <p>Does C# have built-in support for parsing strings of page numbers? By page numbers, I mean the format you might enter into a print dialog that's a mixture of comma and dash-delimited.</p>
<p>Something like this:</p>
<pre><code>1,3,5-10,12
</code></pre>
<p>What would be really nice is a solution that gave me back... | [
{
"answer_id": 40165,
"author": "Daniel Jennings",
"author_id": 3641,
"author_profile": "https://Stackoverflow.com/users/3641",
"pm_score": 3,
"selected": false,
"text": "<p>It doesn't have a built-in way to do this, but it would be trivial to do using String.Split.</p>\n\n<p>Simply spli... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40161",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/305/"
] | Does C# have built-in support for parsing strings of page numbers? By page numbers, I mean the format you might enter into a print dialog that's a mixture of comma and dash-delimited.
Something like this:
```
1,3,5-10,12
```
What would be really nice is a solution that gave me back some kind of list of all page num... | Should be simple:
```
foreach( string s in "1,3,5-10,12".Split(',') )
{
// try and get the number
int num;
if( int.TryParse( s, out num ) )
{
yield return num;
continue; // skip the rest
}
// otherwise we might have a range
// split on the range delimiter
string[] subs... |
40,193 | <p>I've got to get a directory listing that contains about 2 million files, but when I do an <code>ls</code> command on it nothing comes back. I've waited 3 hours. I've tried <code>ls | tee directory.txt</code>, but that seems to hang forever. </p>
<p>I assume the server is doing a lot of inode sorting. Is there any w... | [
{
"answer_id": 40195,
"author": "Mark Biek",
"author_id": 305,
"author_profile": "https://Stackoverflow.com/users/305",
"pm_score": 1,
"selected": false,
"text": "<p>How about <code>find ./ -type f</code> (which will find all files in the currently directory)? Take off the <code>-type f... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40193",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1536194/"
] | I've got to get a directory listing that contains about 2 million files, but when I do an `ls` command on it nothing comes back. I've waited 3 hours. I've tried `ls | tee directory.txt`, but that seems to hang forever.
I assume the server is doing a lot of inode sorting. Is there any way to speed up the `ls` command ... | ```
ls -U
```
will do the ls without sorting.
Another source of slowness is `--color`. On some linux machines, there is a convenience alias which adds `--color=auto'` to the ls call, making it look up file attributes for each file found (slow), to color the display. This can be avoided by `ls -U --color=never` or `\... |
40,211 | <p>I have a flag enum below.</p>
<pre><code>[Flags]
public enum FlagTest
{
None = 0x0,
Flag1 = 0x1,
Flag2 = 0x2,
Flag3 = 0x4
}
</code></pre>
<p>I cannot make the if statement evaluate to true.</p>
<pre><code>FlagTest testItem = FlagTest.Flag1 | FlagTest.Flag2;
if (testItem == FlagTest.Flag1)
{
/... | [
{
"answer_id": 40213,
"author": "17 of 26",
"author_id": 2284,
"author_profile": "https://Stackoverflow.com/users/2284",
"pm_score": 3,
"selected": false,
"text": "<p>For bit operations, you need to use bitwise operators.</p>\n\n<p>This should do the trick:</p>\n\n<pre><code>if ((testIte... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40211",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2469/"
] | I have a flag enum below.
```
[Flags]
public enum FlagTest
{
None = 0x0,
Flag1 = 0x1,
Flag2 = 0x2,
Flag3 = 0x4
}
```
I cannot make the if statement evaluate to true.
```
FlagTest testItem = FlagTest.Flag1 | FlagTest.Flag2;
if (testItem == FlagTest.Flag1)
{
// Do something,
// however This i... | In .NET 4 there is a new method [Enum.HasFlag](http://msdn.microsoft.com/en-us/library/system.enum.hasflag%28VS.100%29.aspx). This allows you to write:
```
if ( testItem.HasFlag( FlagTest.Flag1 ) )
{
// Do Stuff
}
```
which is much more readable, IMO.
The .NET source indicates that this performs the same logic ... |
40,244 | <p>Assume that I have programs <code>P0</code>, <code>P1</code>, ...<code>P(n-1)</code> for some <code>n > 0</code>. How can I easily redirect the output of program <code>Pi</code> to program <code>P(i+1 mod n)</code> for all <code>i</code> (<code>0 <= i < n</code>)?</p>
<p>For example, let's say I have a pro... | [
{
"answer_id": 40339,
"author": "Mark Witczak",
"author_id": 1536194,
"author_profile": "https://Stackoverflow.com/users/1536194",
"pm_score": 3,
"selected": false,
"text": "<p>This is a very interesting question. I (vaguely) remember an assignment very similar in college 17 years ago. W... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40244",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4285/"
] | Assume that I have programs `P0`, `P1`, ...`P(n-1)` for some `n > 0`. How can I easily redirect the output of program `Pi` to program `P(i+1 mod n)` for all `i` (`0 <= i < n`)?
For example, let's say I have a program `square`, which repeatedly reads a number and than prints the square of that number, and a program `ca... | After spending quite some time yesterday trying to redirect `stdout` to `stdin`, I ended up with the following method. It isn't really nice, but I think I prefer it over the named pipe/fifo solution.
```
read | { P0 | ... | P(n-1); } >/dev/fd/0
```
The `{ ... } >/dev/fd/0` is to redirect stdout to stdin for the pipe... |
40,264 | <p>Let's say you have a class called Customer, which contains the following fields:</p>
<ul>
<li>UserName</li>
<li>Email</li>
<li>First Name</li>
<li>Last Name</li>
</ul>
<p>Let's also say that according to your business logic, all Customer objects must have these four properties defined.</p>
<p>Now, we can do this ... | [
{
"answer_id": 40276,
"author": "Aldie",
"author_id": 4133,
"author_profile": "https://Stackoverflow.com/users/4133",
"pm_score": -1,
"selected": false,
"text": "<p>Unless it's more than 1 argument, I always use arrays or objects as constructor parameters and rely on error checking to ma... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40264",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1574/"
] | Let's say you have a class called Customer, which contains the following fields:
* UserName
* Email
* First Name
* Last Name
Let's also say that according to your business logic, all Customer objects must have these four properties defined.
Now, we can do this pretty easily by forcing the constructor to specify each... | Two design approaches to consider
The [essence](http://www.hillside.net/plop/plop98/final_submissions/P10.pdf) pattern
The [fluent interface](https://martinfowler.com/bliki/FluentInterface.html) pattern
These are both similar in intent, in that we slowly build up an intermediate object, and then create our target ob... |
40,269 | <p>Is there an easy way to find the storage card's path on a Windows Mobile device
when there is a storage card and a bluetooth ftp connection?</p>
| [
{
"answer_id": 41316,
"author": "Dominik Grabiec",
"author_id": 3719,
"author_profile": "https://Stackoverflow.com/users/3719",
"pm_score": 1,
"selected": false,
"text": "<p>On Windows CE 5 (which is the base for Windows Mobile 6) the storage cards get mounted at the root file system as ... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40269",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4298/"
] | Is there an easy way to find the storage card's path on a Windows Mobile device
when there is a storage card and a bluetooth ftp connection? | Keep in mind that "\Storage Card" is english oriented. A device made for a different region may have a different name. The name of the storage card path on my device varies with how I am using the device.
Some time ago in the MSDN forms I responded to a few questions on how to detect the storage cards in the file sys... |
40,273 | <p>A client of mine has asked me to integrate a 3rd party API into their Rails app. The only problem is that the API uses SOAP. Ruby has basically dropped SOAP in favor of REST. They provide a Java adapter that apparently works with the Java-Ruby bridge, but we'd like to keep it all in Ruby, if possible. I looked i... | [
{
"answer_id": 40318,
"author": "Jason Navarrete",
"author_id": 3920,
"author_profile": "https://Stackoverflow.com/users/3920",
"pm_score": 2,
"selected": false,
"text": "<p>Try <strong>SOAP4R</strong></p>\n\n<ul>\n<li><a href=\"http://dev.ctor.org/soap4r\" rel=\"nofollow noreferrer\">SO... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40273",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2884/"
] | A client of mine has asked me to integrate a 3rd party API into their Rails app. The only problem is that the API uses SOAP. Ruby has basically dropped SOAP in favor of REST. They provide a Java adapter that apparently works with the Java-Ruby bridge, but we'd like to keep it all in Ruby, if possible. I looked into soa... | We used the built in `soap/wsdlDriver` class, which is actually SOAP4R.
It's dog slow, but really simple. The SOAP4R that you get from gems/etc is just an updated version of the same thing.
Example code:
```
require 'soap/wsdlDriver'
client = SOAP::WSDLDriverFactory.new( 'http://example.com/service.wsdl' ).create_rp... |
40,317 | <p>I have an NFS-mounted directory on a Linux machine that has hung. I've tried to force an unmount, but it doesn't seem to work:</p>
<pre><code>$ umount -f /mnt/data
$ umount2: Device or resource busy
$ umount: /mnt/data: device is busy
</code></pre>
<p>If I type "<code>mount</code>", it appears that the directory i... | [
{
"answer_id": 40320,
"author": "tessein",
"author_id": 3075,
"author_profile": "https://Stackoverflow.com/users/3075",
"pm_score": 9,
"selected": true,
"text": "<p>You might try a lazy unmount:</p>\n\n<pre><code>umount -l\n</code></pre>\n"
},
{
"answer_id": 40331,
"author": ... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40317",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/742/"
] | I have an NFS-mounted directory on a Linux machine that has hung. I've tried to force an unmount, but it doesn't seem to work:
```
$ umount -f /mnt/data
$ umount2: Device or resource busy
$ umount: /mnt/data: device is busy
```
If I type "`mount`", it appears that the directory is no longer mounted, but it hangs if ... | You might try a lazy unmount:
```
umount -l
``` |
40,335 | <p>I'm need to find a method to programmatically determine which disk drive Windows is using to boot. In other words, I need a way from Windows to determine which drive the BIOS is using to boot the whole system. </p>
<p>Does Windows expose an interface to discover this? With how big the Windows API is, I'm hoping the... | [
{
"answer_id": 40347,
"author": "UnkwnTech",
"author_id": 115,
"author_profile": "https://Stackoverflow.com/users/115",
"pm_score": 3,
"selected": false,
"text": "<p>Unless C: is not the drive that windows booted from.<br />Parse the %SystemRoot% variable, it contains the location of the... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40335",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2171/"
] | I'm need to find a method to programmatically determine which disk drive Windows is using to boot. In other words, I need a way from Windows to determine which drive the BIOS is using to boot the whole system.
Does Windows expose an interface to discover this? With how big the Windows API is, I'm hoping there is some... | 1. Go into `Control Panel`
2. `System and Security`
3. `Administrative Tools`
4. Launch the `System Configuration` tool
If you have multiple copies of Windows installed, the one you are booted with will be named such as:
```
Windows 7 (F:\Windows)
Windows 7 (C:\Windows) : Current OS, Default OS
``` |
40,361 | <p>I have an application which extracts data from an XML file using XPath. If a node in that XML source file is missing I want to return the value "N/A" (much like the Oracle NVL function). The trick is that the application doesn't support XSLT; I'd like to do this using XPath and XPath alone.</p>
<p>Is that possible?... | [
{
"answer_id": 40443,
"author": "Hank Gay",
"author_id": 4203,
"author_profile": "https://Stackoverflow.com/users/4203",
"pm_score": 2,
"selected": false,
"text": "<p>Short answer: no. Such a function was considered and explicitly rejected for version 2 of the XPath spec (see the non-nor... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40361",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1019/"
] | I have an application which extracts data from an XML file using XPath. If a node in that XML source file is missing I want to return the value "N/A" (much like the Oracle NVL function). The trick is that the application doesn't support XSLT; I'd like to do this using XPath and XPath alone.
Is that possible? | It can be done but only if the return value when the node does exist is *the string value of the node, not the node itself*. The XPath
```
substring(concat("N/A", /foo/baz), 4 * number(boolean(/foo/baz)))
```
will return the string value of the `baz` element if it exists, otherwise the string "N/A".
To generalize t... |
40,402 | <p>I need to empty an LDF file before sending to a colleague. How do I force SQL Server to truncate the log?</p>
| [
{
"answer_id": 40420,
"author": "Blorgbeard",
"author_id": 369,
"author_profile": "https://Stackoverflow.com/users/369",
"pm_score": 8,
"selected": false,
"text": "<p>In management studio:</p>\n\n<ul>\n<li>Don't do this on a live environment, but to ensure you shrink your dev db as much ... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40402",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1042/"
] | I need to empty an LDF file before sending to a colleague. How do I force SQL Server to truncate the log? | if I remember well... in query analyzer or equivalent:
```
BACKUP LOG databasename WITH TRUNCATE_ONLY
DBCC SHRINKFILE ( databasename_Log, 1)
``` |
40,422 | <p>Ok, so I want an autocomplete dropdown with linkbuttons as selections. So, the user puts the cursor in the "text box" and is greated with a list of options. They can either start typing to narrow down the list, or select one of the options on the list. As soon as they click (or press enter) the dataset this is linke... | [
{
"answer_id": 40504,
"author": "JasonS",
"author_id": 1865,
"author_profile": "https://Stackoverflow.com/users/1865",
"pm_score": 0,
"selected": false,
"text": "<p>You'll have to handle the OnSelectedIndexChanged event of your drop down list to rebind your dataset based on the users sel... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40422",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4140/"
] | Ok, so I want an autocomplete dropdown with linkbuttons as selections. So, the user puts the cursor in the "text box" and is greated with a list of options. They can either start typing to narrow down the list, or select one of the options on the list. As soon as they click (or press enter) the dataset this is linked t... | This widget can be made with three items: a text input, button input, and an unordered list to hold the results.
```
__________ _
|__________||v|__ <-- text and button
| | <-- ul (styled to appear relative to text input)
| |
| |
|______________|
... |
40,423 | <p>Actually, this question seems to have two parts:</p>
<ul>
<li>How to implement pattern matching?</li>
<li>How to implement <a href="http://erlang.org/doc/reference_manual/expressions.html#6.9" rel="noreferrer">send and receive</a> (i.e. the Actor model)?</li>
</ul>
<p>For the pattern matching part, I've been looki... | [
{
"answer_id": 40616,
"author": "1729",
"author_id": 4319,
"author_profile": "https://Stackoverflow.com/users/4319",
"pm_score": 3,
"selected": true,
"text": "<p>One of the important things about erlang is how the features are used to make robust systems.</p>\n\n<p>The send/recieve model... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40423",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | Actually, this question seems to have two parts:
* How to implement pattern matching?
* How to implement [send and receive](http://erlang.org/doc/reference_manual/expressions.html#6.9) (i.e. the Actor model)?
For the pattern matching part, I've been looking into various projects like [App](http://members.cox.net/nela... | One of the important things about erlang is how the features are used to make robust systems.
The send/recieve model is no-sharing, and explicitly copying.
The processes themselves are lightweight threads.
If you did desire the robust properties of the erlang model, you would be best to use real processes and IPC rat... |
40,452 | <p>I have to POST some parameters to a URL outside my network, and the developers on the other side asked me to not use HTTP Parameters: instead I have to post my key-values in <strong>HTTP Headers</strong>.</p>
<p>The fact is that I don't really understand what they mean: I tried to use a ajax-like post, with XmlHttp... | [
{
"answer_id": 40455,
"author": "Lasse V. Karlsen",
"author_id": 267,
"author_profile": "https://Stackoverflow.com/users/267",
"pm_score": 0,
"selected": false,
"text": "<p>You should post more information.</p>\n\n<p>For instance, is this C#? It looks like it, but I might be wrong.</p>\n... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40452",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1178/"
] | I have to POST some parameters to a URL outside my network, and the developers on the other side asked me to not use HTTP Parameters: instead I have to post my key-values in **HTTP Headers**.
The fact is that I don't really understand what they mean: I tried to use a ajax-like post, with XmlHttp objects, and also I tr... | Like @lassevk said, a redirect won't work.
You should use the WebRequest class to do an HTTP POST from your page or application. There's an example [here](http://msdn.microsoft.com/en-us/library/debx8sh9.aspx). |
40,456 | <p>If I select from a table group by the month, day, year,
it only returns rows with records and leaves out combinations without any records, making it appear at a glance that every day or month has activity, you have to look at the date column actively for gaps. How can I get a row for every day/month/year, even when... | [
{
"answer_id": 40462,
"author": "SQLMenace",
"author_id": 740,
"author_profile": "https://Stackoverflow.com/users/740",
"pm_score": 3,
"selected": false,
"text": "<p>Create a calendar table and outer join on that table</p>\n"
},
{
"answer_id": 40481,
"author": "Tom Mayfield",... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40456",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2477/"
] | If I select from a table group by the month, day, year,
it only returns rows with records and leaves out combinations without any records, making it appear at a glance that every day or month has activity, you have to look at the date column actively for gaps. How can I get a row for every day/month/year, even when no... | [My developer](https://stackoverflow.com/users/51836/clark) got back to me with this code, underscores converted to dashes because StackOverflow was mangling underscores -- no numbers table required. Our example is complicated a bit by a join to another table, but maybe the code example will help someone someday.
```
... |
40,465 | <p>I have a List of Foo.</p>
<p>Foo has a string property named Bar.</p>
<p>I'd like to use <strong>LINQ</strong> to get a string[] of <strong>distinct</strong> values for Foo.Bar in List of Foo.</p>
<p>How can I do this?</p>
| [
{
"answer_id": 40477,
"author": "Lasse V. Karlsen",
"author_id": 267,
"author_profile": "https://Stackoverflow.com/users/267",
"pm_score": 2,
"selected": false,
"text": "<p>Try this:</p>\n\n<pre><code>var distinctFooBars = (from foo in foos\n select foo.Bar).Distinc... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40465",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1946/"
] | I have a List of Foo.
Foo has a string property named Bar.
I'd like to use **LINQ** to get a string[] of **distinct** values for Foo.Bar in List of Foo.
How can I do this? | I'd go lambdas... wayyy nicer
```
var bars = Foos.Select(f => f.Bar).Distinct().ToArray();
```
works the same as what @lassevk posted.
I'd also add that you might want to keep from converting to an array until the last minute.
LINQ does some optimizations behind the scenes, queries stay in its query form until ex... |
40,480 | <p>I always thought Java uses <strong>pass-by-reference</strong>.</p>
<p>However, I've seen <a href="http://javadude.com/articles/passbyvalue.htm" rel="noreferrer">a blog post</a> that claims that Java uses <strong>pass-by-value</strong>.</p>
<p>I don't think I understand the distinction they're making.</p>
<p>What is ... | [
{
"answer_id": 40499,
"author": "SCdF",
"author_id": 1666,
"author_profile": "https://Stackoverflow.com/users/1666",
"pm_score": 10,
"selected": false,
"text": "<p>Java is always pass by value, with no exceptions, <strong>ever</strong>.</p>\n\n<p>So how is it that anyone can be at all co... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40480",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4315/"
] | I always thought Java uses **pass-by-reference**.
However, I've seen [a blog post](http://javadude.com/articles/passbyvalue.htm) that claims that Java uses **pass-by-value**.
I don't think I understand the distinction they're making.
What is the explanation? | The terms "pass-by-value" and "pass-by-reference" have special, [precisely defined](https://en.wikipedia.org/w/index.php?title=Pass-by-value) meanings in computer science. These meanings differ from the intuition many people have when first hearing the terms. Much of the confusion in this discussion seems to come from ... |
40,511 | <p>As the title already states, I'm trying to declare a nested function and return a pointer to that function. I want this function 'not' to return a new function pointer which will return the negation of whatever the original function was.</p>
<p>Here is what I have:</p>
<pre><code>someType not( someType original ) ... | [
{
"answer_id": 40537,
"author": "Steve Willard",
"author_id": 402,
"author_profile": "https://Stackoverflow.com/users/402",
"pm_score": 0,
"selected": false,
"text": "<p>I'm using GCC.</p>\n\n<p>You can turn on nested functions by using the flag:</p>\n\n<pre><code>-fnested-functions\n</c... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40511",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/402/"
] | As the title already states, I'm trying to declare a nested function and return a pointer to that function. I want this function 'not' to return a new function pointer which will return the negation of whatever the original function was.
Here is what I have:
```
someType not( someType original ) {
int isNot( List... | Steve, you have a completely wrong mental model of what is a C function.
```
someType resultFunc = calloc( 1024, 1 );
memcpy( resultFunc, &isNot, 1024 );
```
From your code fragment, I can surmise that you think that you can copy function's compiled code into a block of memory, and then reuse it. This kind of thing... |
40,525 | <p>I'm trying to call a function after I load some XML into Actionscript, and I'm just wondering how I call that function. Example:</p>
<pre><code>//Function Declarations
function parentFunction()
{
function callMe()
{
textField.text = "lawl";
}
}
</code></pre>
<p>Now, <strong>how do I call the "call... | [
{
"answer_id": 40617,
"author": "Michael Pryor",
"author_id": 245,
"author_profile": "https://Stackoverflow.com/users/245",
"pm_score": 3,
"selected": true,
"text": "<p>Are you forced to declare callMe inside of parentFunction? I assume so because otherwise you would just do</p>\n\n<p>f... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40525",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/557/"
] | I'm trying to call a function after I load some XML into Actionscript, and I'm just wondering how I call that function. Example:
```
//Function Declarations
function parentFunction()
{
function callMe()
{
textField.text = "lawl";
}
}
```
Now, **how do I call the "callMe()" function** in a different ... | Are you forced to declare callMe inside of parentFunction? I assume so because otherwise you would just do
function parent() { }
function callMe() { }
To be clear, a function can't own another function unless you provide some scope for that function to live in.
So in JavaScript, you would do this by using the protot... |
40,535 | <p>I need to determine if I'm on a particular view. My use case is that I'd like to decorate navigation elements with an "on" class for the current view. Is there a built in way of doing this?</p>
| [
{
"answer_id": 40538,
"author": "Jim Geurts",
"author_id": 3085,
"author_profile": "https://Stackoverflow.com/users/3085",
"pm_score": 2,
"selected": false,
"text": "<p>My current solution is with extension methods:</p>\n\n<pre><code>public static class UrlHelperExtensions\n{\n /// &l... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40535",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3085/"
] | I need to determine if I'm on a particular view. My use case is that I'd like to decorate navigation elements with an "on" class for the current view. Is there a built in way of doing this? | Here what i am using. I think this is actually generated by the MVC project template in VS:
```
public static bool IsCurrentAction(this HtmlHelper helper, string actionName, string controllerName)
{
string currentControllerName = (string)helper.ViewContext.RouteData.Values["controller"];
string cur... |
40,545 | <p>Is there is any way to change the datasource location for a report and all of it's subreports without having to open each of them manually?</p>
| [
{
"answer_id": 40704,
"author": "David Cumps",
"author_id": 4329,
"author_profile": "https://Stackoverflow.com/users/4329",
"pm_score": -1,
"selected": false,
"text": "<p>I'm guessing you're talking about .rdl files from Reporting Services? (If not, my answer might be wrong)</p>\n\n<p>Th... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40545",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4286/"
] | Is there is any way to change the datasource location for a report and all of it's subreports without having to open each of them manually? | Here is how I set my connections at runtime. I get the connection info from a config location.
```
#'SET REPORT CONNECTION INFO
For i = 0 To rsource.ReportDocument.DataSourceConnections.Count - 1
rsource.ReportDocument.DataSourceConnections(i).SetConnection(crystalServer, crystalDB, crystal... |
40,568 | <p>Are square brackets in URLs allowed?</p>
<p>I noticed that <a href="http://hc.apache.org/httpclient-3.x/index.html" rel="noreferrer">Apache commons HttpClient</a> (3.0.1) throws an IOException, wget and Firefox however accept square brackets.</p>
<p>URL example:</p>
<pre><code>http://example.com/path/to/file[3].h... | [
{
"answer_id": 40571,
"author": "Ben Scheirman",
"author_id": 3381,
"author_profile": "https://Stackoverflow.com/users/3381",
"pm_score": 1,
"selected": false,
"text": "<p>Best to URL encode those, as they are clearly not supported in all web servers. Sometimes, even when there is a sta... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40568",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4308/"
] | Are square brackets in URLs allowed?
I noticed that [Apache commons HttpClient](http://hc.apache.org/httpclient-3.x/index.html) (3.0.1) throws an IOException, wget and Firefox however accept square brackets.
URL example:
```
http://example.com/path/to/file[3].html
```
My HTTP client encounters such URLs but I'm no... | [RFC 3986](http://www.ietf.org/rfc/rfc3986.txt) states
>
> A host identified by an Internet
> Protocol literal address, version 6
> [RFC3513] or later, is distinguished
> by enclosing the IP literal within
> square brackets ("[" and "]"). This
> is the only place where square bracket
> characters are allowed in... |
40,577 | <p>In Ruby, I'm trying to do the following.</p>
<pre><code>def self.stats(since)
return Events.find(:all, :select => 'count(*) as this_count', :conditions => ['Date(event_date) >= ?', (Time.now - since)]).first.this_count
end
</code></pre>
<p>where "since" is a string representing an amount of time ('1 hou... | [
{
"answer_id": 40580,
"author": "John Millikin",
"author_id": 3560,
"author_profile": "https://Stackoverflow.com/users/3560",
"pm_score": 2,
"selected": false,
"text": "<p>Try using <a href=\"http://chronic.rubyforge.org/\" rel=\"nofollow noreferrer\">Chronic</a> to parse the date string... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40577",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4322/"
] | In Ruby, I'm trying to do the following.
```
def self.stats(since)
return Events.find(:all, :select => 'count(*) as this_count', :conditions => ['Date(event_date) >= ?', (Time.now - since)]).first.this_count
end
```
where "since" is a string representing an amount of time ('1 hour', '1 day', '3 days') and so on. A... | I hacked this together with the ActiveSupport gem:
```
require 'active_support'
def string_to_date(date_string)
parts = date_string.split
return parts[0].to_i.send(parts[1])
end
sinces = ['1 hour', '1 day', '3 days']
sinces.each do |since|
puts "#{since} ago: #{string_to_date(since).ago(Time.now)}"
end
```
[... |
40,590 | <p>Both the jQuery and Prototpye JavaScript libraries refuse to allow me to use a variable to select an list item element by index number although they accept a hard coded number. </p>
<p>For example, in Prototype this works:</p>
<pre><code>$$('li')[5].addClassName('active');
</code></pre>
<p>But this will not work ... | [
{
"answer_id": 40599,
"author": "John Millikin",
"author_id": 3560,
"author_profile": "https://Stackoverflow.com/users/3560",
"pm_score": 3,
"selected": false,
"text": "<p>Are you certain that <code>currentPage</code> is an integer? Try something like:</p>\n\n<pre><code>var currentPage =... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40590",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4320/"
] | Both the jQuery and Prototpye JavaScript libraries refuse to allow me to use a variable to select an list item element by index number although they accept a hard coded number.
For example, in Prototype this works:
```
$$('li')[5].addClassName('active');
```
But this will not work no matter how I try to cast the v... | It looks like I just needed to be more specific in my element selector although it is weird that a hard coded number would work.
```
jQuery('#pagination-digg li').eq(currentPage).addClass("active");
``` |
40,637 | <p>I'm building an excel template (*.xlt) for a user here, and one of the things I want to do is have it insert the current date when a new document is created (ie, when they double-click the file in windows explorer). How do I do this?</p>
<p><strong>Update:</strong> I should have added that I would prefer not to us... | [
{
"answer_id": 40674,
"author": "1729",
"author_id": 4319,
"author_profile": "https://Stackoverflow.com/users/4319",
"pm_score": 2,
"selected": false,
"text": "<p>You can edit the default template for excel - </p>\n\n<p>There is a file called <code>Book.xlt</code> in the <code>XLSTART</c... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40637",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3043/"
] | I'm building an excel template (\*.xlt) for a user here, and one of the things I want to do is have it insert the current date when a new document is created (ie, when they double-click the file in windows explorer). How do I do this?
**Update:** I should have added that I would prefer not to use any vba (macro). If t... | You could use the worksheet function =TODAY(), but obviously this would be updated to the current date whenever the workbook is recalculated.
The only other method I can think of is, as 1729 said, to code the Workbook\_Open event:
```
Private Sub Workbook_Open()
ThisWorkbook.Worksheets("Sheet1").Range("A1").Value... |
40,651 | <p>I've inherited a large VB6 app at my current workplace. I'm kinda learning VB6 on the job and there are a number of problems I'm having. The major issue at the moment is I can't figure out how to check if a key exists in a Collection object. Can anyone help?</p>
| [
{
"answer_id": 40659,
"author": "Mark Biek",
"author_id": 305,
"author_profile": "https://Stackoverflow.com/users/305",
"pm_score": 3,
"selected": false,
"text": "<p>I've always done it with a function like this:</p>\n\n<pre><code>public function keyExists(myCollection as collection, sKe... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40651",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4315/"
] | I've inherited a large VB6 app at my current workplace. I'm kinda learning VB6 on the job and there are a number of problems I'm having. The major issue at the moment is I can't figure out how to check if a key exists in a Collection object. Can anyone help? | @Mark Biek Your keyExists closely matches my standard Exists() function. To make the class more useful for COM-exposed collections and checking for numeric indexes, I'd recommend changing sKey and myCollection to not be typed. If the function is going to be used with a collection of objects, 'set' is required (on the l... |
40,663 | <p>I'm trying to find a way to validate a large XML file against an XSD. I saw the question <a href="https://stackoverflow.com/questions/15732/whats-the-best-way-to-validate-an-xml-file-against-an-xsd-file">...best way to validate an XML...</a> but the answers all pointed to using the Xerces library for validation. The... | [
{
"answer_id": 40678,
"author": "jodonnell",
"author_id": 4223,
"author_profile": "https://Stackoverflow.com/users/4223",
"pm_score": 6,
"selected": true,
"text": "<p>Instead of using a DOMParser, use a SAXParser. This reads from an input stream or reader so you can keep the XML on disk... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40663",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3274/"
] | I'm trying to find a way to validate a large XML file against an XSD. I saw the question [...best way to validate an XML...](https://stackoverflow.com/questions/15732/whats-the-best-way-to-validate-an-xml-file-against-an-xsd-file) but the answers all pointed to using the Xerces library for validation. The only problem ... | Instead of using a DOMParser, use a SAXParser. This reads from an input stream or reader so you can keep the XML on disk instead of loading it all into memory.
```
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setValidating(true);
factory.setNamespaceAware(true);
SAXParser parser = factory.newSAX... |
40,665 | <p>I'm maintaining some code that uses a *= operator in a query to a Sybase database and I can't find documentation on it. Does anyone know what *= does? I assume that it is some sort of a join.</p>
<pre><code>select * from a, b where a.id *= b.id</code></pre>
<p>I can't figure out how this is different from:</p>
... | [
{
"answer_id": 40671,
"author": "Lasse V. Karlsen",
"author_id": 267,
"author_profile": "https://Stackoverflow.com/users/267",
"pm_score": 3,
"selected": false,
"text": "<p>It means outer join, a simple = means inner join.</p>\n\n<pre><code>*= is LEFT JOIN and =* is RIGHT JOIN.\n</code><... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40665",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4066/"
] | I'm maintaining some code that uses a \*= operator in a query to a Sybase database and I can't find documentation on it. Does anyone know what \*= does? I assume that it is some sort of a join.
```
select * from a, b where a.id *= b.id
```
I can't figure out how this is different from:
```
select * from a, b where a... | From <http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.dc34982_1500/html/mig_gde/mig_gde160.htm>:
Inner and outer tables
The terms outer table and inner table describe the placement of the tables in an outer join:
* In a left join, the outer table and inner table are the left and right tables respective... |
40,692 | <p>Is it possible to create a REST web service using ASP.NET 2.0? The articles and blog entries I am finding all seem to indicate that ASP.NET 3.5 with WCF is required to create REST web services with ASP.NET.</p>
<p>If it is possible to create REST web services in ASP.NET 2.0 can you provide an example.</p>
<p>Than... | [
{
"answer_id": 40701,
"author": "Joel Coehoorn",
"author_id": 3043,
"author_profile": "https://Stackoverflow.com/users/3043",
"pm_score": 0,
"selected": false,
"text": "<p>I'm only just beginning to use them, but from what I've seen 2.0 pretty assumes SOAP.</p>\n"
},
{
"answer_id... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40692",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3498/"
] | Is it possible to create a REST web service using ASP.NET 2.0? The articles and blog entries I am finding all seem to indicate that ASP.NET 3.5 with WCF is required to create REST web services with ASP.NET.
If it is possible to create REST web services in ASP.NET 2.0 can you provide an example.
Thanks! | I have actually created a REST web service with asp.net 2.0. Its really no different than creating a web page.
When I did it, I really didn't have much time to research how to do it with an asmx file so I did it in a standard aspx file. I know thier is extra overhead by doing it this way but as a first revision it was... |
40,705 | <p>At the beginning of all my executable Python scripts I put the <a href="http://en.wikipedia.org/wiki/Shebang_(Unix)" rel="noreferrer">shebang</a> line:</p>
<pre><code>#!/usr/bin/env python
</code></pre>
<p>I'm running these scripts on a system where <code>env python</code> yields a Python 2.2 environment. My scrip... | [
{
"answer_id": 40715,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 4,
"selected": true,
"text": "<p>\"env\" simply executes the first thing it finds in the PATH env var. To switch to different python, prepend the directory fo... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40705",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3594/"
] | At the beginning of all my executable Python scripts I put the [shebang](http://en.wikipedia.org/wiki/Shebang_(Unix)) line:
```
#!/usr/bin/env python
```
I'm running these scripts on a system where `env python` yields a Python 2.2 environment. My scripts quickly fail because I have a manual check for a compatible Py... | "env" simply executes the first thing it finds in the PATH env var. To switch to different python, prepend the directory for that python's executable to the path before invoking your script. |
40,730 | <p>How do you give a C# auto-property an initial value?</p>
<p>I either use the constructor, or revert to the old syntax. </p>
<p><strong> Using the Constructor:</strong></p>
<pre><code>class Person
{
public Person()
{
Name = "Initial Name";
}
public string Name { get; set; }
}
</code></pre>... | [
{
"answer_id": 40734,
"author": "OwenP",
"author_id": 2547,
"author_profile": "https://Stackoverflow.com/users/2547",
"pm_score": 3,
"selected": false,
"text": "<p>Have you tried using the <a href=\"http://msdn.microsoft.com/en-us/library/system.componentmodel.defaultvalueattribute.aspx\... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40730",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/946/"
] | How do you give a C# auto-property an initial value?
I either use the constructor, or revert to the old syntax.
**Using the Constructor:**
```
class Person
{
public Person()
{
Name = "Initial Name";
}
public string Name { get; set; }
}
```
**Using normal property syntax** (with an initia... | In C# 5 and earlier, to give auto implemented properties an initial value, you have to do it in a constructor.
Since [C# 6.0](https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-version-history#c-version-60), you can specify initial value in-line. The syntax is:
```
public int X { get; set; } = x; // C# ... |
40,737 | <p><a href="https://stackoverflow.com/questions/32230/tracking-down-where-disk-space-has-gone-on-linux">In this question</a> someone asked for ways to display disk usage in Linux. I'd like to take this one step further down the cli-path... how about a shell script that takes the output from something like a reasonable ... | [
{
"answer_id": 40862,
"author": "toolkit",
"author_id": 3295,
"author_profile": "https://Stackoverflow.com/users/3295",
"pm_score": 1,
"selected": false,
"text": "<p>I guess there are a couple of options:</p>\n\n<ol>\n<li><p>For a pure CLI solution, use something like gnuplot. See <a hre... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40737",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4162/"
] | [In this question](https://stackoverflow.com/questions/32230/tracking-down-where-disk-space-has-gone-on-linux) someone asked for ways to display disk usage in Linux. I'd like to take this one step further down the cli-path... how about a shell script that takes the output from something like a reasonable answer to the ... | I would recommend [munin](http://munin.projects.linpro.no/). It is designed for exactly this sort of thing - graphing CPU usage, memory usage, disc-usage and such. sort of like MRTG (but MRTG is primarily aimed at graphing router's traffic, graphing anything but bandwidth with it is very hackish)
Writing Munin plugins... |
40,787 | <p>I'd like to keep a "compile-counter" for one of my projects. I figured a quick and dirty way to do this would be to keep a text file with a plain number in it, and then simply call upon a small script to increment this each time I compile.</p>
<p>How would I go about doing this using the regular Windows command lin... | [
{
"answer_id": 40826,
"author": "Steven Murawski",
"author_id": 1233,
"author_profile": "https://Stackoverflow.com/users/1233",
"pm_score": 2,
"selected": false,
"text": "<p>It would be an new shell (but I think it is worth it), but from PowerShell it would be </p>\n\n<pre><code>[int](ge... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40787",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/914/"
] | I'd like to keep a "compile-counter" for one of my projects. I figured a quick and dirty way to do this would be to keep a text file with a plain number in it, and then simply call upon a small script to increment this each time I compile.
How would I go about doing this using the regular Windows command line?
I don'... | You can try a plain old batchfile.
```
@echo off
for /f " delims==" %%i in (counter.txt) do set /A temp_counter= %%i+1
echo %temp_counter% > counter.txt
```
assuming the count.bat and counter.txt are located in the same directory. |
40,814 | <p>I need to execute a large set of SQL statements (creating a bunch of tables, views and stored procedures) from within a C# program.</p>
<p>These statements need to be separated by <code>GO</code> statements, but <code>SqlCommand.ExecuteNonQuery()</code> does not like <code>GO</code> statements. My solution, which I... | [
{
"answer_id": 40824,
"author": "ila",
"author_id": 1178,
"author_profile": "https://Stackoverflow.com/users/1178",
"pm_score": 2,
"selected": false,
"text": "<p>I also faced the same problem, and I could not find any other way but splitting the single SQL operation in separate files, th... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40814",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/369/"
] | I need to execute a large set of SQL statements (creating a bunch of tables, views and stored procedures) from within a C# program.
These statements need to be separated by `GO` statements, but `SqlCommand.ExecuteNonQuery()` does not like `GO` statements. My solution, which I suppose I'll post for reference, was to sp... | Use SQL Server Management Objects (SMO) which understands GO separators. See my blog post here: [http://weblogs.asp.net/jongalloway/Handling-\_2200\_GO\_2200\_-Separators-in-SQL-Scripts-*2D00*-the-easy-way](http://weblogs.asp.net/jgalloway/archive/2006/11/07/Handling-_2200_GO_2200_-Separators-in-SQL-Scripts-_2D00_-the-... |
40,816 | <p>If I have an HTML helper like so:</p>
<pre><code>Name:<br />
<%=Html.TextBox("txtName",20) %><br />
</code></pre>
<p>How do I apply a CSS class to it? Do I have to wrap it in a span? Or do I need to somehow utilize the HtmlAttributes property of the helper?</p>
| [
{
"answer_id": 40846,
"author": "Dale Ragan",
"author_id": 1117,
"author_profile": "https://Stackoverflow.com/users/1117",
"pm_score": 6,
"selected": true,
"text": "<p>You can pass it into the TextBox call as a parameter.</p>\n\n<pre><code>Name:<br/> \n<%= Html.TextBox(\"txtN... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40816",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/230/"
] | If I have an HTML helper like so:
```
Name:<br />
<%=Html.TextBox("txtName",20) %><br />
```
How do I apply a CSS class to it? Do I have to wrap it in a span? Or do I need to somehow utilize the HtmlAttributes property of the helper? | You can pass it into the TextBox call as a parameter.
```
Name:<br/>
<%= Html.TextBox("txtName", "20", new { @class = "hello" }) %>
```
This line will create a text box with the value 20 and assign the class attribute with the value hello. I put the @ character in front of the class, because class is a reserved ... |
40,840 | <p>I have a custom installer action that updates the PATH environment, and creates an additional environment variable. Appending a directory to the existing path variable is working fine, but for some reason my attempts to create a new environment variable have been unsuccessful. The code I am using is:</p>
<pre><code... | [
{
"answer_id": 40864,
"author": "Rob Walker",
"author_id": 3631,
"author_profile": "https://Stackoverflow.com/users/3631",
"pm_score": 1,
"selected": false,
"text": "<p>What OS is this? Is it on a 64-bit system? What is the nature of the failure: silent or is an exception thrown?</p>\n\... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40840",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3114/"
] | I have a custom installer action that updates the PATH environment, and creates an additional environment variable. Appending a directory to the existing path variable is working fine, but for some reason my attempts to create a new environment variable have been unsuccessful. The code I am using is:
```
using... | Is there any reason that you have to do it through the registry?
If not, you can use Environment.SetEnvironmentVariable() since .NET 2.0. It allows you to set on a machine, process or user basis. |
40,853 | <p>I have some code like this in a winforms app I was writing to query a user's mail box Storage Quota.</p>
<pre><code>DirectoryEntry mbstore = new DirectoryEntry(
@"LDAP://" + strhome,
m_serviceaccount,
[m_pwd],
AuthenticationTypes.Secure);
</code></pre>
<p>No matter what approach I tried ... | [
{
"answer_id": 40865,
"author": "Steven Murawski",
"author_id": 1233,
"author_profile": "https://Stackoverflow.com/users/1233",
"pm_score": 2,
"selected": false,
"text": "<p>If you store it as a secure string and save the secure string to a file (possibly using <a href=\"http://msdn.micr... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40853",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4337/"
] | I have some code like this in a winforms app I was writing to query a user's mail box Storage Quota.
```
DirectoryEntry mbstore = new DirectoryEntry(
@"LDAP://" + strhome,
m_serviceaccount,
[m_pwd],
AuthenticationTypes.Secure);
```
No matter what approach I tried (like `SecureString`), I a... | The sanctified method is to use CryptoAPI and the Data Protection APIs.
To encrypt, use something like this (C++):
```
DATA_BLOB blobIn, blobOut;
blobIn.pbData=(BYTE*)data;
blobIn.cbData=wcslen(data)*sizeof(WCHAR);
CryptProtectData(&blobIn, description, NULL, NULL, NULL, CRYPTPROTECT_LOCAL_MACHINE | CRYPTPROTECT_UI_... |
40,873 | <p>I have a table which is full of arbitrarily formatted phone numbers, like this</p>
<pre><code>027 123 5644
021 393-5593
(07) 123 456
042123456
</code></pre>
<p>I need to search for a phone number in a similarly arbitrary format ( e.g. <code>07123456</code> should find the entry <code>(07) 123 456</code></p>
<p>The w... | [
{
"answer_id": 40880,
"author": "Matt Hamilton",
"author_id": 615,
"author_profile": "https://Stackoverflow.com/users/615",
"pm_score": 2,
"selected": false,
"text": "<p>An out-of-the-box idea, but could you use a \"replace\" function to strip out any instances of \"(\", \"-\" and \" \",... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40873",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/234/"
] | I have a table which is full of arbitrarily formatted phone numbers, like this
```
027 123 5644
021 393-5593
(07) 123 456
042123456
```
I need to search for a phone number in a similarly arbitrary format ( e.g. `07123456` should find the entry `(07) 123 456`
The way I'd do this in a normal programming language is t... | This looks like a problem from the start. Any kind of searching you do will require a table scan and we all know that's bad.
How about adding a column with a hash of the current phone numbers after stripping out all formatting characters. Then you can at least index the hash values and avoid a full blown table scan.
... |
40,912 | <p>I'm looking for a way to check within <code>pageLoad()</code> if this method is raised during load event because of a postback/async postback or because of being loaded and access the first time.</p>
<p>This is similar to <code>Page.IsPostback</code> property within code behind page.</p>
<p>TIA,
Ricky</p>
| [
{
"answer_id": 40924,
"author": "Greg Hurlman",
"author_id": 35,
"author_profile": "https://Stackoverflow.com/users/35",
"pm_score": 2,
"selected": false,
"text": "<p>You could have a hidden input that you set to a known value on the server side if it's a postback/callback - and your jav... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40912",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4191/"
] | I'm looking for a way to check within `pageLoad()` if this method is raised during load event because of a postback/async postback or because of being loaded and access the first time.
This is similar to `Page.IsPostback` property within code behind page.
TIA,
Ricky | One way you could do that is to wire up an Application.Load handler in Application.Init, then have that handler unbind itself after running:
```
Sys.Application.add_init(AppInit);
function AppInit() {
Sys.Application.add_load(RunOnce);
}
function RunOnce() {
// This will only happen once per GET request to the p... |
40,913 | <p>I am having problems manually looping through xml data that is received via an HTTPService call, the xml looks something like this: </p>
<pre><code><DataTable>
<Row>
<text>foo</text>
</Row>
<Row>
<text>bar</text>
</Row>
</DataT... | [
{
"answer_id": 40930,
"author": "dlamblin",
"author_id": 459,
"author_profile": "https://Stackoverflow.com/users/459",
"pm_score": 2,
"selected": false,
"text": "<p>Row isn't an array unless there are multiple Row elements. It is annoying. You have to do something like this, but I haven'... | 2008/09/02 | [
"https://Stackoverflow.com/questions/40913",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1638/"
] | I am having problems manually looping through xml data that is received via an HTTPService call, the xml looks something like this:
```
<DataTable>
<Row>
<text>foo</text>
</Row>
<Row>
<text>bar</text>
</Row>
</DataTable>
```
When the webservice result event is fired I do something li... | The problem lies in this statement
```
event.result.DataTable.Row.length
```
`length` is not a property of `XMLList`, but a method:
```
event.result.DataTable.Row.length()
```
it's confusing, but that's the way it is.
*Addition:* actually, the safest thing to do is to always use a `for each` loop when iterating ... |
40,943 | <p>What code do you need to add in PHP to automatically have the browser download a file to the local machine when a link is visited?</p>
<p>I am specifically thinking of functionality similar to that of download sites that prompt the user to save a file to disk once you click on the name of the software?</p>
| [
{
"answer_id": 40945,
"author": "grom",
"author_id": 486,
"author_profile": "https://Stackoverflow.com/users/486",
"pm_score": 5,
"selected": false,
"text": "<p>Here is an example of sending back a pdf.</p>\n\n<pre><code>header('Content-type: application/pdf');\nheader('Content-Dispositi... | 2008/09/03 | [
"https://Stackoverflow.com/questions/40943",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/277/"
] | What code do you need to add in PHP to automatically have the browser download a file to the local machine when a link is visited?
I am specifically thinking of functionality similar to that of download sites that prompt the user to save a file to disk once you click on the name of the software? | Send the following headers before outputting the file:
```
header("Content-Disposition: attachment; filename=\"" . basename($File) . "\"");
header("Content-Type: application/octet-stream");
header("Content-Length: " . filesize($File));
header("Connection: close");
```
[@grom](https://stackoverflow.com/users/486/grom... |
40,966 | <p>I have a javascript function that manipulates the DOM when it is called (adds CSS classes, etc). This is invoked when the user changes some values in a form. When the document is first loading, I want to invoke this function to prepare the initial state (which is simpler in this case than setting up the DOM from t... | [
{
"answer_id": 40972,
"author": "John Millikin",
"author_id": 3560,
"author_profile": "https://Stackoverflow.com/users/3560",
"pm_score": 4,
"selected": true,
"text": "<p>Definitely use <code>onload</code>. Keep your scripts separate from your page, or you'll go mad trying to disentangle... | 2008/09/03 | [
"https://Stackoverflow.com/questions/40966",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/122/"
] | I have a javascript function that manipulates the DOM when it is called (adds CSS classes, etc). This is invoked when the user changes some values in a form. When the document is first loading, I want to invoke this function to prepare the initial state (which is simpler in this case than setting up the DOM from the se... | Definitely use `onload`. Keep your scripts separate from your page, or you'll go mad trying to disentangle them later. |
40,999 | <p>Here's a quick question I've been banging my head against today.</p>
<p>I'm trying to convert a .Net dataset into an XML stream, transform it with an xsl file in memory, then output the result to a new XML file. </p>
<p>Here's the current solution:</p>
<pre><code> string transformXML = @"pathToXslDocument"... | [
{
"answer_id": 41012,
"author": "aku",
"author_id": 1196,
"author_profile": "https://Stackoverflow.com/users/1196",
"pm_score": 4,
"selected": true,
"text": "<p>I'm not sure but it seems that you didn't reset position in stream before passing it to XmlReader. Try to seek at the beginning... | 2008/09/03 | [
"https://Stackoverflow.com/questions/40999",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2916/"
] | Here's a quick question I've been banging my head against today.
I'm trying to convert a .Net dataset into an XML stream, transform it with an xsl file in memory, then output the result to a new XML file.
Here's the current solution:
```
string transformXML = @"pathToXslDocument";
XmlDocument origi... | I'm not sure but it seems that you didn't reset position in stream before passing it to XmlReader. Try to seek at the beginning of your stream before trying to read from it. Also it may be necessary to close\flush stream after you wrote some data to it.
**EDIT**:
Just tried following code and it worked perfectly:
``... |
41,045 | <p>As a general rule, I prefer using value rather than pointer semantics in C++ (ie using <code>vector<Class></code> instead of <code>vector<Class*></code>). Usually the slight loss in performance is more than made up for by not having to remember to delete dynamically allocated objects.</p>
<p>Unfortunate... | [
{
"answer_id": 41059,
"author": "1800 INFORMATION",
"author_id": 3146,
"author_profile": "https://Stackoverflow.com/users/3146",
"pm_score": 6,
"selected": true,
"text": "<p>Since the objects of different classes will have different sizes, you would end up running into the slicing proble... | 2008/09/03 | [
"https://Stackoverflow.com/questions/41045",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2994/"
] | As a general rule, I prefer using value rather than pointer semantics in C++ (ie using `vector<Class>` instead of `vector<Class*>`). Usually the slight loss in performance is more than made up for by not having to remember to delete dynamically allocated objects.
Unfortunately, value collections don't work when you wa... | Since the objects of different classes will have different sizes, you would end up running into the slicing problem if you store them as values.
One reasonable solution is to store container safe smart pointers. I normally use boost::shared\_ptr which is safe to store in a container. Note that std::auto\_ptr is not.
... |
41,089 | <p>I have a vb6 form with an ocx control on it. The ocx control has a button on it that I want to press from code. How do I do this?</p>
<p>I have:</p>
<pre><code>Dim b As CommandButton
Set b = ocx.GetButton("btnPrint")
SendMessage ocx.hwnd, WM_COMMAND, GetWindowLong(b.hwnd, GWL_ID), b.hwnd
</code></pre>
<p>but it d... | [
{
"answer_id": 41123,
"author": "Gishu",
"author_id": 1695,
"author_profile": "https://Stackoverflow.com/users/1695",
"pm_score": 1,
"selected": false,
"text": "<p>If you have access to the OCX code, you could expose the associated event handler and invoke it directly.<br>\nDon't know if... | 2008/09/03 | [
"https://Stackoverflow.com/questions/41089",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4495/"
] | I have a vb6 form with an ocx control on it. The ocx control has a button on it that I want to press from code. How do I do this?
I have:
```
Dim b As CommandButton
Set b = ocx.GetButton("btnPrint")
SendMessage ocx.hwnd, WM_COMMAND, GetWindowLong(b.hwnd, GWL_ID), b.hwnd
```
but it doesn't seem to work. | I believe the following will work:
```
Dim b As CommandButton
Set b = ocx.GetButton("btnPrint")
b = True
```
`CommandButton`s actually have two functions. One is the usual click button and the other is a toggle button that acts similar to a `CheckBox`. The default property of the `CommandButton` is actually the `Val... |
41,097 | <p>The question sort of says it all.</p>
<p>Whether it's for code testing purposes, or you're modeling a real-world process, or you're trying to impress a loved one, what are some algorithms that folks use to generate interesting time series data? Are there any good resources out there with a consolidated list? No con... | [
{
"answer_id": 41123,
"author": "Gishu",
"author_id": 1695,
"author_profile": "https://Stackoverflow.com/users/1695",
"pm_score": 1,
"selected": false,
"text": "<p>If you have access to the OCX code, you could expose the associated event handler and invoke it directly.<br>\nDon't know if... | 2008/09/03 | [
"https://Stackoverflow.com/questions/41097",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4069/"
] | The question sort of says it all.
Whether it's for code testing purposes, or you're modeling a real-world process, or you're trying to impress a loved one, what are some algorithms that folks use to generate interesting time series data? Are there any good resources out there with a consolidated list? No constraints o... | I believe the following will work:
```
Dim b As CommandButton
Set b = ocx.GetButton("btnPrint")
b = True
```
`CommandButton`s actually have two functions. One is the usual click button and the other is a toggle button that acts similar to a `CheckBox`. The default property of the `CommandButton` is actually the `Val... |
41,107 | <p>I've been looking for a <em>simple</em> Java algorithm to generate a pseudo-random alpha-numeric string. In my situation it would be used as a unique session/key identifier that would "likely" be unique over <code>500K+</code> generation (my needs don't really require anything much more sophisticated). </p>
<p>Id... | [
{
"answer_id": 41156,
"author": "erickson",
"author_id": 3474,
"author_profile": "https://Stackoverflow.com/users/3474",
"pm_score": 12,
"selected": true,
"text": "<h2>Algorithm</h2>\n<p>To generate a random string, concatenate characters drawn randomly from the set of acceptable symbols... | 2008/09/03 | [
"https://Stackoverflow.com/questions/41107",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3803/"
] | I've been looking for a *simple* Java algorithm to generate a pseudo-random alpha-numeric string. In my situation it would be used as a unique session/key identifier that would "likely" be unique over `500K+` generation (my needs don't really require anything much more sophisticated).
Ideally, I would be able to spec... | Algorithm
---------
To generate a random string, concatenate characters drawn randomly from the set of acceptable symbols until the string reaches the desired length.
Implementation
--------------
Here's some fairly simple and very flexible code for generating random identifiers. *Read the information that follows* ... |
41,155 | <p>In the process of developing my first WCF service and when I try to use it I get "Method not Allowed" with no other explanation. </p>
<p>I've got my interface set up with the ServiceContract and OperationContract:</p>
<pre><code> [OperationContract]
void FileUpload(UploadedFile file);
</code></pre>
<p>Alon... | [
{
"answer_id": 41205,
"author": "Jeremy McGee",
"author_id": 3546,
"author_profile": "https://Stackoverflow.com/users/3546",
"pm_score": 2,
"selected": false,
"text": "<p>The basic intrinsic types (e.g. <code>byte</code>, <code>int</code>, <code>string</code>, and arrays) will be seriali... | 2008/09/03 | [
"https://Stackoverflow.com/questions/41155",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/831/"
] | In the process of developing my first WCF service and when I try to use it I get "Method not Allowed" with no other explanation.
I've got my interface set up with the ServiceContract and OperationContract:
```
[OperationContract]
void FileUpload(UploadedFile file);
```
Along with the actual method:
```
... | Your browser is sending an HTTP GET request: Make sure you have the WebGet attribute on the operation in the contract:
```
[ServiceContract]
public interface IUploadService
{
[WebGet()]
[OperationContract]
string TestGetMethod(); // This method takes no arguments, returns a string. Perfect for testing quic... |
41,159 | <p>Given the following:</p>
<pre><code>List<List<Option>> optionLists;
</code></pre>
<p>what would be a quick way to determine the subset of Option objects that appear in all N lists? Equality is determined through some string property such as option1.Value == option2.Value.</p>
<p>So we should end up wi... | [
{
"answer_id": 41175,
"author": "Matt Hamilton",
"author_id": 615,
"author_profile": "https://Stackoverflow.com/users/615",
"pm_score": 4,
"selected": true,
"text": "<p>Ok, this will find the list of Option objects that have a Value appearing in <em>every</em> list.</p>\n\n<pre><code>var... | 2008/09/03 | [
"https://Stackoverflow.com/questions/41159",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3615/"
] | Given the following:
```
List<List<Option>> optionLists;
```
what would be a quick way to determine the subset of Option objects that appear in all N lists? Equality is determined through some string property such as option1.Value == option2.Value.
So we should end up with `List<Option>` where each item appears onl... | Ok, this will find the list of Option objects that have a Value appearing in *every* list.
```
var x = from list in optionLists
from option in list
where optionLists.All(l => l.Any(o => o.Value == option.Value))
orderby option.Value
select option;
```
It doesn't do a "distinct" select... |
41,185 | <p>I'm doing a fair bit of work in Ruby recently, and using</p>
<pre><code> ruby script/console
</code></pre>
<p>Is absolutely critical. However, I'm really disappointed with the default Windows console in Vista, especially in that there's a really annoying bug where moving the cursor back when at the bottom of the s... | [
{
"answer_id": 41190,
"author": "lomaxx",
"author_id": 493,
"author_profile": "https://Stackoverflow.com/users/493",
"pm_score": 0,
"selected": false,
"text": "<p><a href=\"http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx\" rel=\"nofollow norefer... | 2008/09/03 | [
"https://Stackoverflow.com/questions/41185",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4322/"
] | I'm doing a fair bit of work in Ruby recently, and using
```
ruby script/console
```
Is absolutely critical. However, I'm really disappointed with the default Windows console in Vista, especially in that there's a really annoying bug where moving the cursor back when at the bottom of the screen irregularly causes i... | I use [Console2](http://sourceforge.net/projects/console/).
I like the tabbed interface and that copy works properly if text breaks at the end of a line. |
41,198 | <p>How can I get an image to stretch the height of a <code>DIV</code> class?</p>
<p>Currently it looks like this:</p>
<p><img src="https://i.stack.imgur.com/DcrXC.png" width="650" /></p>
<p>However, I would like the <code>DIV</code> to be stretched so the <code>image</code> fits properly, but I do not want to resize... | [
{
"answer_id": 41201,
"author": "DevelopingChris",
"author_id": 1220,
"author_profile": "https://Stackoverflow.com/users/1220",
"pm_score": 1,
"selected": false,
"text": "<pre><code>display:inline \nfloat:left \n</code></pre>\n\n<p>is your problem</p>\n\n<p>Floating makes the parents w... | 2008/09/03 | [
"https://Stackoverflow.com/questions/41198",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2592/"
] | How can I get an image to stretch the height of a `DIV` class?
Currently it looks like this:

However, I would like the `DIV` to be stretched so the `image` fits properly, but I do not want to resize the `image.
Here is the CSS for the `DIV` (the grey box):
```css
.product1 ... | Add `overflow:auto;` to `.product1` |
41,204 | <p>Is there a fast and clean way of returning a JSON hash back from any node in a Ruby on Rails' acts_as_nested_set without using recursion?</p>
<p>Here's the recursive solution for reference:</p>
<pre><code>class Node < ActiveRecord::Base
has_many :products
def json_hash
if children.size > 0
chil... | [
{
"answer_id": 41275,
"author": "Mike Stone",
"author_id": 122,
"author_profile": "https://Stackoverflow.com/users/122",
"pm_score": 2,
"selected": false,
"text": "<p>There is a <a href=\"http://en.wikipedia.org/wiki/Tree_traversal\" rel=\"nofollow noreferrer\">wikipedia article</a> on t... | 2008/09/03 | [
"https://Stackoverflow.com/questions/41204",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3499/"
] | Is there a fast and clean way of returning a JSON hash back from any node in a Ruby on Rails' acts\_as\_nested\_set without using recursion?
Here's the recursive solution for reference:
```
class Node < ActiveRecord::Base
has_many :products
def json_hash
if children.size > 0
children.collect { |node| { ... | There is a [wikipedia article](http://en.wikipedia.org/wiki/Tree_traversal) on tree traversal which shows different alternatives to the recursive solution you are using. It may be tricky to use them in your specific case, but it should be possible.
However, my question to you is, is there a specific reason you want to... |
41,218 | <p>I am running MAMP locally on my laptop, and I like to test as much as I can locally. Unfortunately, since I work on e-commerce stuff (PHP), I normally force ssl in most of the checkout forms and it just fails on my laptop. Is there any easy configuration that I might be missing to allow "https" to run under MAMP? Pl... | [
{
"answer_id": 41272,
"author": "David Crow",
"author_id": 2783,
"author_profile": "https://Stackoverflow.com/users/2783",
"pm_score": 2,
"selected": false,
"text": "<p>There doesn't seem to be an easier way, <a href=\"http://www.rocketwerx.com/blog/8-apple/34-getting-ssl-to-work-with-ma... | 2008/09/03 | [
"https://Stackoverflow.com/questions/41218",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4247/"
] | I am running MAMP locally on my laptop, and I like to test as much as I can locally. Unfortunately, since I work on e-commerce stuff (PHP), I normally force ssl in most of the checkout forms and it just fails on my laptop. Is there any easy configuration that I might be missing to allow "https" to run under MAMP? Pleas... | >
> **NOTE: startssl is no longer supported after version 2+ of MAMP. You
> have to update the config files (httpd.conf) to enable ssl.**
>
>
>
You can modify the free version of MAMP to enable ssl by default very easily. Once you have setup all the SSL parts of apache and have it working so that calling apachect... |
41,239 | <p>I am pretty sure that the settings that I am using are correct, so all possible things can be wrong which I should check out so that I can make authentication with our Active Directory work.</p>
| [
{
"answer_id": 41247,
"author": "grom",
"author_id": 486,
"author_profile": "https://Stackoverflow.com/users/486",
"pm_score": 1,
"selected": false,
"text": "<p>Try test if PHP can connect to active directory</p>\n\n<pre><code><?php\n$ds = ldap_connect('host.ad.lan', 389);\nldap_set_o... | 2008/09/03 | [
"https://Stackoverflow.com/questions/41239",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/380/"
] | I am pretty sure that the settings that I am using are correct, so all possible things can be wrong which I should check out so that I can make authentication with our Active Directory work. | Try test if PHP can connect to active directory
```
<?php
$ds = ldap_connect('host.ad.lan', 389);
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);
ldap_bind($ds, 'admin@ad.lan', 'xxx');
$sr = ldap_search($ds, 'CN=Cameron Zemek,OU=Users,OU=BRC,DC=ad,DC=lan', '(objectclass... |
41,244 | <p>I found an example in the <a href="http://msdn2.microsoft.com/en-us/bb330936.aspx" rel="noreferrer">VS2008 Examples</a> for Dynamic LINQ that allows you to use a SQL-like string (e.g. <code>OrderBy("Name, Age DESC"))</code> for ordering. Unfortunately, the method included only works on <code>IQueryable<... | [
{
"answer_id": 41262,
"author": "Kjetil Watnedal",
"author_id": 4116,
"author_profile": "https://Stackoverflow.com/users/4116",
"pm_score": 6,
"selected": false,
"text": "<p>I guess it would work to use reflection to get whatever property you want to sort on:</p>\n\n<pre><code>IEnumerabl... | 2008/09/03 | [
"https://Stackoverflow.com/questions/41244",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1786/"
] | I found an example in the [VS2008 Examples](http://msdn2.microsoft.com/en-us/bb330936.aspx) for Dynamic LINQ that allows you to use a SQL-like string (e.g. `OrderBy("Name, Age DESC"))` for ordering. Unfortunately, the method included only works on `IQueryable<T>`. Is there any way to get this functionality on `IEnumera... | Just stumbled into this oldie...
To do this without the dynamic LINQ library, you just need the code as below. This covers most common scenarios including nested properties.
To get it working with `IEnumerable<T>` you could add some wrapper methods that go via `AsQueryable` - but the code below is the core `Expressio... |
41,279 | <p>I've got bunches of auxiliary files that are generated by code and LaTeX documents that I dearly wish <em>would not</em> be suggested by SpotLight as potential search candidates. I'm not looking for <code>example.log</code>, I'm looking for <code>example.tex</code>!</p>
<p>So can Spotlight be configured to ignore, ... | [
{
"answer_id": 41283,
"author": "D2VIANT",
"author_id": 4365,
"author_profile": "https://Stackoverflow.com/users/4365",
"pm_score": 2,
"selected": false,
"text": "<p>Not sure how to do it on a file type level, but you can do it on a folder level:</p>\n\n<p>Source: <a href=\"http://lists.... | 2008/09/03 | [
"https://Stackoverflow.com/questions/41279",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4161/"
] | I've got bunches of auxiliary files that are generated by code and LaTeX documents that I dearly wish *would not* be suggested by SpotLight as potential search candidates. I'm not looking for `example.log`, I'm looking for `example.tex`!
So can Spotlight be configured to ignore, say, all `.log` files?
(I know, I know... | @Will - these things that define types are called [uniform type identifiers](http://developer.apple.com/macosx/uniformtypeidentifiers.html).
The problem is they are a combination of extensions (like .txt) and generic types (i.e. public.plain-text matches a txt file without the txt extension based purely on content) so... |
41,290 | <p>I have a file which is an XML representation of some data that is taken from a Web service and cached locally within a Web Application. The idea being is that this data is <em>very</em> static, but just <em>might</em> change. So I have set it up to cache to a file, and stuck a monitor against it to check if it has b... | [
{
"answer_id": 41312,
"author": "Ubiguchi",
"author_id": 2562,
"author_profile": "https://Stackoverflow.com/users/2562",
"pm_score": 1,
"selected": false,
"text": "<p>If you're locking on a object stored as a <em>static</em> then the lock should work for all threads in the same Applicati... | 2008/09/03 | [
"https://Stackoverflow.com/questions/41290",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/832/"
] | I have a file which is an XML representation of some data that is taken from a Web service and cached locally within a Web Application. The idea being is that this data is *very* static, but just *might* change. So I have set it up to cache to a file, and stuck a monitor against it to check if it has been deleted. Once... | Here is the code that I use to make sure a file is not locked by another process. It's not 100% foolproof, but it gets the job done most of the time:
```
/// <summary>
/// Blocks until the file is not locked any more.
/// </summary>
/// <param name="fullPath"></param>
bool WaitForFile(string fullPa... |
41,304 | <p>I know in ASP.NET I can get an item from a DropDownList by using</p>
<pre><code>DropDownList1.Items.FindByText
</code></pre>
<p>Is there a similar method I can use in WPF for a ComboBox?</p>
<p>Here's the scenario.</p>
<p>I have a table called RestrictionFormat that contains a column called RestrictionType, the ... | [
{
"answer_id": 41305,
"author": "aku",
"author_id": 1196,
"author_profile": "https://Stackoverflow.com/users/1196",
"pm_score": 2,
"selected": false,
"text": "<p>In WPF you can use FindName method.</p>\n\n<p>XAML:</p>\n\n<pre><code> <ComboBox Name=\"combo\">\n <ComboBo... | 2008/09/03 | [
"https://Stackoverflow.com/questions/41304",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/71/"
] | I know in ASP.NET I can get an item from a DropDownList by using
```
DropDownList1.Items.FindByText
```
Is there a similar method I can use in WPF for a ComboBox?
Here's the scenario.
I have a table called RestrictionFormat that contains a column called RestrictionType, the type is a foreign key to a table that st... | Can you use ItemContainerGenerator?
ItemContainerGenerator contains a ContainerFromItem method that takes an object parameter. If you have a reference to the full object that your comboBox contains (or a way to reconstruct it), you can use the following:
```
ComboBoxItem item =
(ComboBoxItem)myComboBox.ItemConta... |
41,319 | <p>What's the "best" (taking both speed and readability into account) way to determine if a list is empty? Even if the list is of type <code>IEnumerable<T></code> and doesn't have a Count property.</p>
<p>Right now I'm tossing up between this:</p>
<pre><code>if (myList.Count() == 0) { ... }
</code></pre>
<p>an... | [
{
"answer_id": 41324,
"author": "Lasse V. Karlsen",
"author_id": 267,
"author_profile": "https://Stackoverflow.com/users/267",
"pm_score": 8,
"selected": true,
"text": "<p>You could do this:</p>\n\n<pre><code>public static Boolean IsEmpty<T>(this IEnumerable<T> source)\n{\n ... | 2008/09/03 | [
"https://Stackoverflow.com/questions/41319",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/615/"
] | What's the "best" (taking both speed and readability into account) way to determine if a list is empty? Even if the list is of type `IEnumerable<T>` and doesn't have a Count property.
Right now I'm tossing up between this:
```
if (myList.Count() == 0) { ... }
```
and this:
```
if (!myList.Any()) { ... }
```
My g... | You could do this:
```
public static Boolean IsEmpty<T>(this IEnumerable<T> source)
{
if (source == null)
return true; // or throw an exception
return !source.Any();
}
```
**Edit**: Note that simply using the .Count method will be fast if the underlying source actually has a fast Count property. A va... |
41,330 | <p>How do I detect if the system has a default recording device installed?
I bet this can be done through some calls to the Win32 API, anyone has any experience with this?</p>
<p>I'm talking about doing this through code, not by opening the control panel and taking a look under sound options.</p>
| [
{
"answer_id": 41346,
"author": "Espo",
"author_id": 2257,
"author_profile": "https://Stackoverflow.com/users/2257",
"pm_score": 0,
"selected": false,
"text": "<p>There is an Open Source Audio API called <a href=\"http://www.portaudio.com/\" rel=\"nofollow noreferrer\">PortAudio</a> that... | 2008/09/03 | [
"https://Stackoverflow.com/questions/41330",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1509946/"
] | How do I detect if the system has a default recording device installed?
I bet this can be done through some calls to the Win32 API, anyone has any experience with this?
I'm talking about doing this through code, not by opening the control panel and taking a look under sound options. | Using the [DirectX SDK](https://www.microsoft.com/en-in/download/details.aspx?id=6812), you can call DirectSoundCaptureEnumerate, which will call your DSEnumCallback function for each DirectSoundCapture device on the system. The first parameter passed to your DSEnumCallback is an LPGUID, which is the "Address of the GU... |
41,397 | <p>Right, I know I am totally going to look an idiot with this one, but my brain is just <em>not</em> kicking in to gear this morning.</p>
<p>I want to have a method where I can say "if it goes bad, come back with this type of Exception", right?</p>
<p>For example, something like (<strong>and this doesn't wor... | [
{
"answer_id": 41402,
"author": "Jon Limjap",
"author_id": 372,
"author_profile": "https://Stackoverflow.com/users/372",
"pm_score": 0,
"selected": false,
"text": "<p>Have you tried, instead:</p>\n\n<pre><code>static T TestException<Exception>(string message)\n{}\n</code></pre>\n\n... | 2008/09/03 | [
"https://Stackoverflow.com/questions/41397",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/832/"
] | Right, I know I am totally going to look an idiot with this one, but my brain is just *not* kicking in to gear this morning.
I want to have a method where I can say "if it goes bad, come back with this type of Exception", right?
For example, something like (**and this doesn't work**):
```
static ExType TestExcep... | You can almost do it like this:
```
static void TestException<E>(string message) where E : Exception, new()
{
var e = new E();
e.Message = message;
throw e;
}
```
However, that doesn't compile because Exception.Message is read only. It can only be assigned by passing it to the constructor, and there's no... |
41,400 | <p>I am looking to do this in C/C++. I came across <a href="http://www.swig.org/Doc1.3/Varargs.html" rel="nofollow noreferrer"><strong>Variable Length Arguments</strong></a>, but this suggests a solution with Python and C using <a href="http://sourceware.org/libffi/" rel="nofollow noreferrer">libffi</a>.</p>
<p>Now, if... | [
{
"answer_id": 41413,
"author": "Mark Ingram",
"author_id": 986,
"author_profile": "https://Stackoverflow.com/users/986",
"pm_score": 0,
"selected": false,
"text": "<p>How do you mean a pure C/C++ solution?</p>\n<p>The rest parameter (...) is supported cross platform in the C runtime.</p... | 2008/09/03 | [
"https://Stackoverflow.com/questions/41400",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/123/"
] | I am looking to do this in C/C++. I came across [**Variable Length Arguments**](http://www.swig.org/Doc1.3/Varargs.html), but this suggests a solution with Python and C using [libffi](http://sourceware.org/libffi/).
Now, if I want to wrap the `printf` function with `myprintf`.
I do it like below:
```
void myprintf(c... | The problem is that you cannot use 'printf' with *va\_args*. You must use **vprintf** if you are using variable argument lists. *vprint*, *vsprintf*, *vfprintf*, etc. (there are also 'safe' versions in Microsoft's C runtime that will prevent buffer overruns, etc.)
You sample works as follows:
```
void myprintf(char* ... |
41,407 | <p>I'm currently working on a parser for our internal log files (generated by log4php, log4net and log4j). So far I have a nice regular expression to parse the logs, except for one annoying bit: Some log messages span multiple lines, which I can't get to match properly. The regex I have now is this:</p>
<pre><code>(?&... | [
{
"answer_id": 41412,
"author": "samjudson",
"author_id": 1908,
"author_profile": "https://Stackoverflow.com/users/1908",
"pm_score": 0,
"selected": false,
"text": "<p>You need to pass the <code>RegexOptions</code>. Singleline flag in to the regular expression, so that \".\" matches all ... | 2008/09/03 | [
"https://Stackoverflow.com/questions/41407",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/909/"
] | I'm currently working on a parser for our internal log files (generated by log4php, log4net and log4j). So far I have a nice regular expression to parse the logs, except for one annoying bit: Some log messages span multiple lines, which I can't get to match properly. The regex I have now is this:
```
(?<date>\d{2}/\d{... | This will only work if the log message doesn't contain a date at the beginning of the line, but you could try adding a negative look-ahead assertion for a date in the "message" group:
```
(?<date>\d{2}/\d{2}/\d{2})\s(?<time>\d{2}:\d{2}:\d{2},\d{3})\s(?<message>(.(?!^\d{2}/\d{2}/
\d{2}))+)
```
Note that this requires... |
41,479 | <p>After discussion with colleagues regarding the use of the 'var' keyword in C# 3 I wondered what people's opinions were on the appropriate uses of type inference via var?</p>
<p>For example I rather lazily used var in questionable circumstances, e.g.:-</p>
<pre><code>foreach(var item in someList) { // ... } // Type... | [
{
"answer_id": 41486,
"author": "Matt Hamilton",
"author_id": 615,
"author_profile": "https://Stackoverflow.com/users/615",
"pm_score": 6,
"selected": false,
"text": "<p>I think the use of var should be coupled with wisely-chosen variable names.</p>\n\n<p>I have no problem using var in a... | 2008/09/03 | [
"https://Stackoverflow.com/questions/41479",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3394/"
] | After discussion with colleagues regarding the use of the 'var' keyword in C# 3 I wondered what people's opinions were on the appropriate uses of type inference via var?
For example I rather lazily used var in questionable circumstances, e.g.:-
```
foreach(var item in someList) { // ... } // Type of 'item' not clear.... | I still think `var` can make code more readable in some cases. If I have a Customer class with an Orders property, and I want to assign that to a variable, I will just do this:
```
var orders = cust.Orders;
```
I don't care if Customer.Orders is `IEnumerable<Order>`, `ObservableCollection<Order>` or `BindingList<Ord... |
41,492 | <p>Is it possible to determine which property of an ActiveX control is the default property? For example, what is the default property of the VB6 control CommandButton and how would I found out any other controls default!</p>
<p><strong>/EDIT:</strong> Without having source to the object itself</p>
| [
{
"answer_id": 41612,
"author": "Eugene Yokota",
"author_id": 3827,
"author_profile": "https://Stackoverflow.com/users/3827",
"pm_score": 1,
"selected": false,
"text": "<p>I don't use VB, but here it goes.</p>\n\n<p>I found <a href=\"http://msdn.microsoft.com/en-us/library/aa733705%28VS.... | 2008/09/03 | [
"https://Stackoverflow.com/questions/41492",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1111/"
] | Is it possible to determine which property of an ActiveX control is the default property? For example, what is the default property of the VB6 control CommandButton and how would I found out any other controls default!
**/EDIT:** Without having source to the object itself | Use OLE/Com Object Viewer, which is distributed with Microsoft Visual Studio.
Go to type libraries and find the library the control is housed in, for example CommandButton is stored in ***Microsoft Forms 2.0 Object Library***. Right click the library and select view. Find the coclass representing the control and sele... |
41,513 | <p>I am going to be using Subversion for source control on a new J2EE web application. What directory structure will you recommend for organizing code, tests and documentation?</p>
| [
{
"answer_id": 41524,
"author": "Mendelt",
"author_id": 3320,
"author_profile": "https://Stackoverflow.com/users/3320",
"pm_score": 4,
"selected": false,
"text": "<p>I usually have</p>\n\n<pre>\nProject Directory\n src - actual source\n doc - documentation\n lib - libraries referenced... | 2008/09/03 | [
"https://Stackoverflow.com/questions/41513",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I am going to be using Subversion for source control on a new J2EE web application. What directory structure will you recommend for organizing code, tests and documentation? | I usually have
```
Project Directory
src - actual source
doc - documentation
lib - libraries referenced from source
dep - installation files for dependencies that don't fit in lib
db - database installation script
```
In work with Visual Studio, I'm not sure if this works the same in the java world. But ... |
41,562 | <p>I've had to do some introspection in python and it wasn't pretty:</p>
<pre><code>name = sys._getframe(1).f_code
name = "%s:%d %s()" %(os.path.split(name.co_filename)[1],name.co_firstlineno,name.co_name)
</code></pre>
<p>To get something like</p>
<pre><code>foo.py:22 bar() blah blah
</code></pre>
<p>In our debugg... | [
{
"answer_id": 41574,
"author": "Curt Hagenlocher",
"author_id": 533,
"author_profile": "https://Stackoverflow.com/users/533",
"pm_score": 3,
"selected": true,
"text": "<p>A print statement does its IO through \"sys.stdout.write\" so you can override sys.stdout if you want to manipulate ... | 2008/09/03 | [
"https://Stackoverflow.com/questions/41562",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4319/"
] | I've had to do some introspection in python and it wasn't pretty:
```
name = sys._getframe(1).f_code
name = "%s:%d %s()" %(os.path.split(name.co_filename)[1],name.co_firstlineno,name.co_name)
```
To get something like
```
foo.py:22 bar() blah blah
```
In our debugging output.
I'd ideally like to prepend anything... | A print statement does its IO through "sys.stdout.write" so you can override sys.stdout if you want to manipulate the print stream. |
41,568 | <p>this kind of follows on from another <a href="https://stackoverflow.com/questions/41290/file-access-strategy-in-a-multi-threaded-environment-web-app">question</a> of mine.</p>
<p>Basically, once I have the code to access the file (will review the answers there in a minute) what would be the best way to <strong>test<... | [
{
"answer_id": 41578,
"author": "Eric Z Beard",
"author_id": 1219,
"author_profile": "https://Stackoverflow.com/users/1219",
"pm_score": -1,
"selected": false,
"text": "<p>Your idea should work fine. Basically you just want to spawn a bunch of threads, and make sure the ones writing the... | 2008/09/03 | [
"https://Stackoverflow.com/questions/41568",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/832/"
] | this kind of follows on from another [question](https://stackoverflow.com/questions/41290/file-access-strategy-in-a-multi-threaded-environment-web-app) of mine.
Basically, once I have the code to access the file (will review the answers there in a minute) what would be the best way to **test** it?
I am thinking of cr... | In .NET, `ThreadPool` threads won't return without setting up `ManualResetEvent`s or `AutoResetEvent`s. I find these overkill for a quick test method (not to mention kind of complicated to create, set, and manage). Background worker is a also a bit complex with the callbacks and such.
Something I have found that works... |
41,576 | <p>I wonder what the best practice for this scenario is:</p>
<p>I have a Sharepoint Site (MOSS2007) with an ASPX Page on it. However, I cannot use any inline source and stuff like Event handlers do not work, because Sharepoint does not allow Server Side Script on ASPX Pages per default.</p>
<p>Two solutions:</p>
<ol... | [
{
"answer_id": 42248,
"author": "Daniel McPherson",
"author_id": 897,
"author_profile": "https://Stackoverflow.com/users/897",
"pm_score": 1,
"selected": false,
"text": "<p>What does the ASPX page do? What functionality does it add? How are you adding the page into the site? By the looks... | 2008/09/03 | [
"https://Stackoverflow.com/questions/41576",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/91/"
] | I wonder what the best practice for this scenario is:
I have a Sharepoint Site (MOSS2007) with an ASPX Page on it. However, I cannot use any inline source and stuff like Event handlers do not work, because Sharepoint does not allow Server Side Script on ASPX Pages per default.
Two solutions:
1. Change the `PageParse... | So in that case I would wrap it up in a feature and deploy it via a solution. This way I think you will avoid the issue you are seeing. This is especially useful if you plan to use this functionality within other sites too.
You can also embed web parts directly in the page, much like you do a WebControl, thereby avoi... |
41,590 | <p>I come from a Java background, where packages are used, not namespaces. I'm used to putting classes that work together to form a complete object into packages, and then reusing them later from that package. But now I'm working in C++.</p>
<p>How do you use namespaces in C++? Do you create a single namespace for the... | [
{
"answer_id": 41598,
"author": "Mark Ingram",
"author_id": 986,
"author_profile": "https://Stackoverflow.com/users/986",
"pm_score": 8,
"selected": true,
"text": "<p>Namespaces are packages essentially. They can be used like this:</p>\n\n<pre><code>namespace MyNamespace\n{\n class MyCl... | 2008/09/03 | [
"https://Stackoverflow.com/questions/41590",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1585/"
] | I come from a Java background, where packages are used, not namespaces. I'm used to putting classes that work together to form a complete object into packages, and then reusing them later from that package. But now I'm working in C++.
How do you use namespaces in C++? Do you create a single namespace for the entire ap... | Namespaces are packages essentially. They can be used like this:
```
namespace MyNamespace
{
class MyClass
{
};
}
```
Then in code:
```
MyNamespace::MyClass* pClass = new MyNamespace::MyClass();
```
Or, if you want to always use a specific namespace, you can do this:
```
using namespace MyNamespace;
MyCla... |
41,594 | <p>I have a table in an access table which contains Product entries, one of the columns has a jpg image stored as an OLE Object. I am trying to import this table to MySQL but nothing seems to work. I have tried the MySQL migration tool but that has a known issue with Access and OLE Objects. (The issue being it does... | [
{
"answer_id": 41617,
"author": "DAC",
"author_id": 1111,
"author_profile": "https://Stackoverflow.com/users/1111",
"pm_score": 1,
"selected": false,
"text": "<p>As far as I remember, the Microsoft \"<a href=\"http://www.microsoft.com/downloads/details.aspx?familyid=D842F8B4-C914-4AC7-B2... | 2008/09/03 | [
"https://Stackoverflow.com/questions/41594",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2720/"
] | I have a table in an access table which contains Product entries, one of the columns has a jpg image stored as an OLE Object. I am trying to import this table to MySQL but nothing seems to work. I have tried the MySQL migration tool but that has a known issue with Access and OLE Objects. (The issue being it doesnt work... | Ok so in the interests of airing my dirty code in public here what i came up with.
Note : this is a hack designed to be used once and then thrown away.
This Method takes in a datarowview containing 1 row of data from the access table. The Images are wrapped in OLE serialization, im not entirely familiar with how th... |
41,630 | <p>I would like to execute an OS command from my ruby script but I want to add an argument from a ruby variable.</p>
<p>I know that's possible by using keyword <em>system</em> like that :</p>
<pre><code>#!/usr/bin/env ruby
directory = '/home/paulgreg/'
system 'ls ' + directory
</code></pre>
<p>but is that possible b... | [
{
"answer_id": 41635,
"author": "Jordi Bunster",
"author_id": 4272,
"author_profile": "https://Stackoverflow.com/users/4272",
"pm_score": 4,
"selected": true,
"text": "<p>No, that will just concatenate the output from <code>ls</code> and the contents of <code>directory</code>.</p>\n\n<p>... | 2008/09/03 | [
"https://Stackoverflow.com/questions/41630",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3122/"
] | I would like to execute an OS command from my ruby script but I want to add an argument from a ruby variable.
I know that's possible by using keyword *system* like that :
```
#!/usr/bin/env ruby
directory = '/home/paulgreg/'
system 'ls ' + directory
```
but is that possible by using the "backquotes or backticks syn... | No, that will just concatenate the output from `ls` and the contents of `directory`.
But you can do this:
```
#!/usr/bin/env ruby
directory = '/home/paulgreg/'
`ls #{directory}`
``` |
41,638 | <p>The current system that I am working on makes use of Castle Activerecord to provide ORM (Object Relational Mapping) between the Domain objects and the database. This is all well and good and at most times actually works well!</p>
<p>The problem comes about with Castle Activerecords support for asynchronous executio... | [
{
"answer_id": 169708,
"author": "ZeroBugBounce",
"author_id": 11314,
"author_profile": "https://Stackoverflow.com/users/11314",
"pm_score": 3,
"selected": false,
"text": "<p>I solved a problem very similar to this where I copied the data out of a lot of older web service contracts into ... | 2008/09/03 | [
"https://Stackoverflow.com/questions/41638",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/231/"
] | The current system that I am working on makes use of Castle Activerecord to provide ORM (Object Relational Mapping) between the Domain objects and the database. This is all well and good and at most times actually works well!
The problem comes about with Castle Activerecords support for asynchronous execution, well, m... | I solved a problem very similar to this where I copied the data out of a lot of older web service contracts into WCF data contracts. I created a number of methods that had signatures like this:
```
public static T ChangeType<S, T>(this S source) where T : class, new()
```
The first time this method (or any of the ot... |
41,647 | <p>When using the php include function the include is succesfully executed, but it is also outputting a char before the output of the include is outputted, the char is of hex value 3F and I have no idea where it is coming from, although it seems to happen with every include. </p>
<p>At first I thbought it was file enc... | [
{
"answer_id": 41655,
"author": "Thomas Owens",
"author_id": 572,
"author_profile": "https://Stackoverflow.com/users/572",
"pm_score": 0,
"selected": false,
"text": "<p>I see <code>hello, world</code> on the page you linked to. No problems that I can see...</p>\n\n<p>I'm using Firefox 3.... | 2008/09/03 | [
"https://Stackoverflow.com/questions/41647",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1111/"
] | When using the php include function the include is succesfully executed, but it is also outputting a char before the output of the include is outputted, the char is of hex value 3F and I have no idea where it is coming from, although it seems to happen with every include.
At first I thbought it was file encoding, but... | What you are seeing is a UTF-8 Byte Order Mark:
>
> The UTF-8 representation of the BOM is the byte sequence EF BB BF, which appears as the ISO-8859-1 characters  in most text editors and web browsers not prepared to handle UTF-8.
>
>
> [Byte Order Mark on Wikipedia](http://en.wikipedia.org/wiki/Byte_Order_Mark)... |
41,652 | <p>We have got a custom <code>MembershipProvider</code> in <code>ASP.NET</code>. Now there are 2 possible scenario the user can be validated:</p>
<ol>
<li><p>User login via <code>login.aspx</code> page by entering his username/password. I have used <strong>Login control</strong> and linked it with the <code>MyMembersh... | [
{
"answer_id": 41664,
"author": "MartinHN",
"author_id": 2972,
"author_profile": "https://Stackoverflow.com/users/2972",
"pm_score": 5,
"selected": true,
"text": "<p>After validation is successful, you need to sign in the user, by calling FormsAuthentication.Authenticate: <a href=\"http:... | 2008/09/03 | [
"https://Stackoverflow.com/questions/41652",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/191/"
] | We have got a custom `MembershipProvider` in `ASP.NET`. Now there are 2 possible scenario the user can be validated:
1. User login via `login.aspx` page by entering his username/password. I have used **Login control** and linked it with the `MyMembershipProvider`. This is working perfectly fine.
2. An authentication t... | After validation is successful, you need to sign in the user, by calling FormsAuthentication.Authenticate: <http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.authenticate.aspx>
EDIT: It is FormsAuthentication.SetAuthCookie:
<http://msdn.microsoft.com/en-us/library/twk5762b.aspx>
Also, to... |
41,659 | <p>Is there any way in the Servlet API to access properties specified in web.xml (such as initialization parameters) from within a Bean or Factory class that is not associated at all with the web container?</p>
<p>For example, I'm writing a Factory class, and I'd like to include some logic within the Factory to check ... | [
{
"answer_id": 41767,
"author": "Tim Howland",
"author_id": 4276,
"author_profile": "https://Stackoverflow.com/users/4276",
"pm_score": 1,
"selected": false,
"text": "<p>Have you considered using the Spring framework for this? That way, your beans don't get any extra cruft, and spring ha... | 2008/09/03 | [
"https://Stackoverflow.com/questions/41659",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4249/"
] | Is there any way in the Servlet API to access properties specified in web.xml (such as initialization parameters) from within a Bean or Factory class that is not associated at all with the web container?
For example, I'm writing a Factory class, and I'd like to include some logic within the Factory to check a hierarch... | One way you could do this is:
```
public class FactoryInitialisingServletContextListener implements ServletContextListener {
public void contextDestroyed(ServletContextEvent event) {
}
public void contextInitialized(ServletContextEvent event) {
Properties properties = new Properties();
Se... |
41,665 | <p>Is there any way to convert a bmp image to jpg/png without losing the quality in C#? Using Image class we can convert bmp to jpg but the quality of output image is very poor. Can we gain the quality level as good as an image converted to jpg using photoshop with highest quality?</p>
| [
{
"answer_id": 41672,
"author": "GateKiller",
"author_id": 383,
"author_profile": "https://Stackoverflow.com/users/383",
"pm_score": 0,
"selected": false,
"text": "<p>You can try:</p>\n\n<pre><code>Bitmap.InterpolationMode = InterpolationMode.HighQualityBicubic;\n</code></pre>\n\n<p>and<... | 2008/09/03 | [
"https://Stackoverflow.com/questions/41665",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/191/"
] | Is there any way to convert a bmp image to jpg/png without losing the quality in C#? Using Image class we can convert bmp to jpg but the quality of output image is very poor. Can we gain the quality level as good as an image converted to jpg using photoshop with highest quality? | ```
var qualityEncoder = Encoder.Quality;
var quality = (long)<desired quality>;
var ratio = new EncoderParameter(qualityEncoder, quality );
var codecParams = new EncoderParameters(1);
codecParams.Param[0] = ratio;
var jpegCodecInfo = <one of the codec infos from ImageCodecInfo.GetImageEncoders() with mime type = "imag... |
41,674 | <p>In Visual Studio you can create a template XML document from an existing schema. The new <a href="http://msdn.microsoft.com/en-us/library/cc716766.aspx" rel="noreferrer">XML Schema Explorer</a> in VS2008 SP1 takes this a stage further and can create a sample XML document complete with data.
Is there a class library ... | [
{
"answer_id": 174148,
"author": "curtisk",
"author_id": 17651,
"author_profile": "https://Stackoverflow.com/users/17651",
"pm_score": 0,
"selected": false,
"text": "<p>Directly, none that I can think of, other than third party add-ons. You could utilize the <a href=\"http://msdn.microso... | 2008/09/03 | [
"https://Stackoverflow.com/questions/41674",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3873/"
] | In Visual Studio you can create a template XML document from an existing schema. The new [XML Schema Explorer](http://msdn.microsoft.com/en-us/library/cc716766.aspx) in VS2008 SP1 takes this a stage further and can create a sample XML document complete with data.
Is there a class library in .NET to do this automaticall... | some footwork is involved, but you could load the xsd into a DataSet object, iterate over the Tables and add a few rows in each by calling calling NewRow() on each and then adding those rows back into their respective tables.. then save the DataSet out to a file:
```
DataSet ds = new DataSet();
ds.ReadXmlSchema("c:/xs... |
41,686 | <p>I've got some Java code using a servlet and Apache Commons FileUpload to upload a file to a set directory. It's working fine for character data (e.g. text files) but image files are coming out garbled. I can open them but the image doesn't look like it should. Here's my code:</p>
<p>Servlet</p>
<pre><code>protec... | [
{
"answer_id": 41694,
"author": "Nick Berardi",
"author_id": 17,
"author_profile": "https://Stackoverflow.com/users/17",
"pm_score": 0,
"selected": false,
"text": "<p>Are you sure that the image isn't coming through garbled or that you aren't dropping some packets on the way in. </p>\n"... | 2008/09/03 | [
"https://Stackoverflow.com/questions/41686",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1900/"
] | I've got some Java code using a servlet and Apache Commons FileUpload to upload a file to a set directory. It's working fine for character data (e.g. text files) but image files are coming out garbled. I can open them but the image doesn't look like it should. Here's my code:
Servlet
```
protected void doPost(HttpSer... | One thing I don't like is here in this block from StreamUtils.getBytes():
```
1 while (true) {
2 int nBytesRead = src.read(buff);
3 if (nBytesRead < 0) {
4 break;
5 }
6 byteStream.write(buff);
7 }
```
At line 6, it writes the entire buffer, no matter how many bytes are read in. I am not convinced ... |