qid int64 1 3.11M | question stringlengths 10 32.1k | date stringlengths 10 10 | metadata sequence | response_j stringlengths 0 33.7k | response_k stringlengths 3 34.7k |
|---|---|---|---|---|---|
2,630,186 | I am trying to work with an HTML.DropDownList in MVC and am not getting the expected return values. Here is my implementation for the selectList to bind to the drop down -
```
IEnumerable<status> stat = _provider.GetAllStatuses();
Statuses = new SelectList(stat.ToList(), "id", "name", i.status.id);
```
And here is ... | 2010/04/13 | [
"https://Stackoverflow.com/questions/2630186",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/306894/"
] | you don't give much to go in in your question:
>
> I am trying to add an additional
> column and value to an existing insert
> query - both integers, and running
> into trouble.
>
>
> Anything to look out for?
>
>
>
it is best practice to list all columns you intend to include values for in the list of colum... | make sure the column name sequence is the same as your insert data sequence.
Example
INSERT INTO TABLENAME
(ColumnName1,ColumnName2) VALUES (1,'data')
Becomes
INSERT INTO TABLENAME
(ColumnName1,ColumnName2,**ColumnNameNEW**) VALUES (1,'data','**newcolumndata**')
Notice both the new column name and the new data ar... |
1,689,138 | I'm working on a project with 2 other developers and I need to host it online. I need a site to host it for me with features such as version control, and others neat features.
can you suggest any ?
the project is not an open source one.
thanks. | 2009/11/06 | [
"https://Stackoverflow.com/questions/1689138",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/91607/"
] | I believe [XP-Dev](http://www.xp-dev.com), would work well for you, they offer a free plan that has two private projcets. [Pricing is here.](http://www.xp-dev.com/pricing) | BitBucket, with Mercurial-based source control, has private repositories:
<http://bitbucket.org/plans/> |
1,689,138 | I'm working on a project with 2 other developers and I need to host it online. I need a site to host it for me with features such as version control, and others neat features.
can you suggest any ?
the project is not an open source one.
thanks. | 2009/11/06 | [
"https://Stackoverflow.com/questions/1689138",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/91607/"
] | I believe [XP-Dev](http://www.xp-dev.com), would work well for you, they offer a free plan that has two private projcets. [Pricing is here.](http://www.xp-dev.com/pricing) | I'm using [unfuddle](http://unfuddle.com/) and highly recommend it. It's free for 200MB/2 users. Subversion and Git are supported and the interface is nice and clean. |
1,689,138 | I'm working on a project with 2 other developers and I need to host it online. I need a site to host it for me with features such as version control, and others neat features.
can you suggest any ?
the project is not an open source one.
thanks. | 2009/11/06 | [
"https://Stackoverflow.com/questions/1689138",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/91607/"
] | I believe [XP-Dev](http://www.xp-dev.com), would work well for you, they offer a free plan that has two private projcets. [Pricing is here.](http://www.xp-dev.com/pricing) | A lot of webhosts include these features as part of the normal monthly hosting plans. For example I use dreamhost.com and get subversion and trac included. |
1,689,138 | I'm working on a project with 2 other developers and I need to host it online. I need a site to host it for me with features such as version control, and others neat features.
can you suggest any ?
the project is not an open source one.
thanks. | 2009/11/06 | [
"https://Stackoverflow.com/questions/1689138",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/91607/"
] | I use projectlocker.com
They have a free version.
One of the nice features is the monthly report that shows you what everyone on your team did. | BitBucket, with Mercurial-based source control, has private repositories:
<http://bitbucket.org/plans/> |
1,689,138 | I'm working on a project with 2 other developers and I need to host it online. I need a site to host it for me with features such as version control, and others neat features.
can you suggest any ?
the project is not an open source one.
thanks. | 2009/11/06 | [
"https://Stackoverflow.com/questions/1689138",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/91607/"
] | I use projectlocker.com
They have a free version.
One of the nice features is the monthly report that shows you what everyone on your team did. | I'm using [unfuddle](http://unfuddle.com/) and highly recommend it. It's free for 200MB/2 users. Subversion and Git are supported and the interface is nice and clean. |
1,689,138 | I'm working on a project with 2 other developers and I need to host it online. I need a site to host it for me with features such as version control, and others neat features.
can you suggest any ?
the project is not an open source one.
thanks. | 2009/11/06 | [
"https://Stackoverflow.com/questions/1689138",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/91607/"
] | I use projectlocker.com
They have a free version.
One of the nice features is the monthly report that shows you what everyone on your team did. | A lot of webhosts include these features as part of the normal monthly hosting plans. For example I use dreamhost.com and get subversion and trac included. |
329,838 | I have, for my game, a Packet class, which represents network packet and consists basically of an array of data, and some pure virtual functions
I would then like to have classes deriving from Packet, for example: StatePacket, PauseRequestPacket, etc. Each one of these sub-classes would implement the virtual functions... | 2008/12/01 | [
"https://Stackoverflow.com/questions/329838",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42029/"
] | For copying you need to write a clone function, since a constructor cannot be virtual:
```
virtual Packet * clone() const = 0;
```
Which each Packet implementation implement like this:
```
virtual Packet * clone() const {
return new StatePacket(*this);
}
```
for example for StatePacket. Packet classes should ... | You need to look up the Factory Pattern.
The factory looks at the incomming data and created an object of the correct class for you. |
329,838 | I have, for my game, a Packet class, which represents network packet and consists basically of an array of data, and some pure virtual functions
I would then like to have classes deriving from Packet, for example: StatePacket, PauseRequestPacket, etc. Each one of these sub-classes would implement the virtual functions... | 2008/12/01 | [
"https://Stackoverflow.com/questions/329838",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42029/"
] | For copying you need to write a clone function, since a constructor cannot be virtual:
```
virtual Packet * clone() const = 0;
```
Which each Packet implementation implement like this:
```
virtual Packet * clone() const {
return new StatePacket(*this);
}
```
for example for StatePacket. Packet classes should ... | To have a Factory class that does not know about all the types ahead of time you need to provide a singleton where each class registers itself. I always get the syntax for defining static members of a template class wrong, so do not just cut&paste this:
```
class Packet { ... };
typedef Packet* (*packet_creator)();
... |
329,838 | I have, for my game, a Packet class, which represents network packet and consists basically of an array of data, and some pure virtual functions
I would then like to have classes deriving from Packet, for example: StatePacket, PauseRequestPacket, etc. Each one of these sub-classes would implement the virtual functions... | 2008/12/01 | [
"https://Stackoverflow.com/questions/329838",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42029/"
] | For copying you need to write a clone function, since a constructor cannot be virtual:
```
virtual Packet * clone() const = 0;
```
Which each Packet implementation implement like this:
```
virtual Packet * clone() const {
return new StatePacket(*this);
}
```
for example for StatePacket. Packet classes should ... | Why do we, myself included, always make such simple problems so complicated?
---
Perhaps I'm off base here. But I have to wonder: Is this really the best design for your needs?
By and large, function-only inheritance can be better achieved through function/method pointers, or aggregation/delegation and the passing a... |
1,669,958 | SQL Server 2008 Database Question.
I have 2 tables, for arguments sake called Customers and Users where a single Customer can have 1 to n Users. The Customers table generates a CustomerId which is a seeded identity with a +1 increment on it. What I'm after in the Users table is a compound key comprising the CustomerI... | 2009/11/03 | [
"https://Stackoverflow.com/questions/1669958",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/202055/"
] | I can think of no automatic way to do this without implementing a custom Stored Procedure that inserted the rows and checked to increment the Id appropriately, althouh others with more knowledge may have a better idea.
However, this smells to me of *naturalising a surrogate* key - which is not always a good idea.
Mor... | That's not really an option with a regular identity column, but you could set up an insert trigger to auto populate the user id though.
The naive way to do this would be to have the trigger select the max user id from the users table for the customer id on the inserted record, then add one to that. However, you'll run... |
1,669,958 | SQL Server 2008 Database Question.
I have 2 tables, for arguments sake called Customers and Users where a single Customer can have 1 to n Users. The Customers table generates a CustomerId which is a seeded identity with a +1 increment on it. What I'm after in the Users table is a compound key comprising the CustomerI... | 2009/11/03 | [
"https://Stackoverflow.com/questions/1669958",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/202055/"
] | I can think of no automatic way to do this without implementing a custom Stored Procedure that inserted the rows and checked to increment the Id appropriately, althouh others with more knowledge may have a better idea.
However, this smells to me of *naturalising a surrogate* key - which is not always a good idea.
Mor... | So you want a generated user\_id field that increments within the confines of a customer\_id.
I can't think of one database where that concept exists.
You could implement it with a trigger. But my question is: WHY?
Surrogate keys are supposed to not have any kind of meaning. Why would you try to make a key that, sim... |
3,060,765 | I've been looking into view models for mvc and I'm looking for the best way to do them. I've read loads of different articles but none seem to be clear as the "best way." So far example I might have a Customer model with the following properties:
* First Name
* Last Name
* Title
* Location
Where location is a foreign... | 2010/06/17 | [
"https://Stackoverflow.com/questions/3060765",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/267174/"
] | Here's what I may suggest: have a view model which reflects the fields of strongly typed view:
```
public class SomeViewModel
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Location { get; set; }
public IEnumerable<SelectListItem> PossibleLocations { get; set... | I'd have my ViewModel as this
```
public class SomeViewModel
{
public Customer Customer { get; set; }
public IEnumerable<Location> PossibleLocations { get; set; }
}
```
My controller like this:
```
public ActionResult Index()
{
var viewModel = new SomeViewModel
{
Customer ... |
1,680,649 | Gitk has a nice habit of showing me Tags:, Follows: and Precedes: for commit. How do I get the same information from command line? | 2009/11/05 | [
"https://Stackoverflow.com/questions/1680649",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/51209/"
] | To show the tag of a commit:
```
$ git describe --tags <commit>
```
To show the preceding commit:
```
$ git rev-list -1 <commit>^
```
To show the following commit:
```
$ git rev-list -1 <commit>..HEAD
``` | To show the tags that contain a commit (i.e. the tags that the commit precedes):
```
git tag --contains <commit>
``` |
1,321,482 | Here is the code which woks perfectly and validate to enter only digits in a TEXT BOX. Now i have a problem there. My problem is i need to enter decimal values there. So i need to enter 'DOT' in the TEXT BOX. This validation has been done by using ASCII values. I even use the ASCII value of 'DOT -> 249, 250'. But it do... | 2009/08/24 | [
"https://Stackoverflow.com/questions/1321482",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/154137/"
] | You can use regular expressions instead:
```
function validate(){
var val=document.getElementById("field").value; //Field value
if(/^[0-9\.]+$/.test(val)){
document.getElementById('bal').innerHTML='';
return true;
}else{
document.getElementById('bal').innerHTML=" Please Ent... | Using a masked input solves the problem and enhances the solution.
There is a [jQuery-Plugin](http://plugins.jquery.com/project/maskedinput) available which can do that. |
1,321,482 | Here is the code which woks perfectly and validate to enter only digits in a TEXT BOX. Now i have a problem there. My problem is i need to enter decimal values there. So i need to enter 'DOT' in the TEXT BOX. This validation has been done by using ASCII values. I even use the ASCII value of 'DOT -> 249, 250'. But it do... | 2009/08/24 | [
"https://Stackoverflow.com/questions/1321482",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/154137/"
] | You can use regular expressions instead:
```
function validate(){
var val=document.getElementById("field").value; //Field value
if(/^[0-9\.]+$/.test(val)){
document.getElementById('bal').innerHTML='';
return true;
}else{
document.getElementById('bal').innerHTML=" Please Ent... | ascii code for dot(.) is 249 as per the [ascii table](http://www.asciitablechart.com) so i hope e.keyCode may not be representing ascii value. |
1,321,482 | Here is the code which woks perfectly and validate to enter only digits in a TEXT BOX. Now i have a problem there. My problem is i need to enter decimal values there. So i need to enter 'DOT' in the TEXT BOX. This validation has been done by using ASCII values. I even use the ASCII value of 'DOT -> 249, 250'. But it do... | 2009/08/24 | [
"https://Stackoverflow.com/questions/1321482",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/154137/"
] | ~~The dot key is 46, just allow it in the if statement.~~
Oh, you're getting keyCode, not charCode so this is on keydown, not keypress. Ignore the above -- dot is 190. | Using a masked input solves the problem and enhances the solution.
There is a [jQuery-Plugin](http://plugins.jquery.com/project/maskedinput) available which can do that. |
1,321,482 | Here is the code which woks perfectly and validate to enter only digits in a TEXT BOX. Now i have a problem there. My problem is i need to enter decimal values there. So i need to enter 'DOT' in the TEXT BOX. This validation has been done by using ASCII values. I even use the ASCII value of 'DOT -> 249, 250'. But it do... | 2009/08/24 | [
"https://Stackoverflow.com/questions/1321482",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/154137/"
] | ~~The dot key is 46, just allow it in the if statement.~~
Oh, you're getting keyCode, not charCode so this is on keydown, not keypress. Ignore the above -- dot is 190. | ascii code for dot(.) is 249 as per the [ascii table](http://www.asciitablechart.com) so i hope e.keyCode may not be representing ascii value. |
1,490,538 | I am hosting a client's site while they are running an exchange server at their location to handle the email. Whenever I try to send email via PHP to one of their email addresses it fails as it is looking for the address on the local system.
Can I force the mail function to look outside of the server for sending mail?... | 2009/09/29 | [
"https://Stackoverflow.com/questions/1490538",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/154442/"
] | I'm guessing the easier way would be to not use the `mail` function, but a library that deals with sending mail by SMTP -- the SMTP being on your client's server.
You can for instance take a look at [Swift Mailer](http://swiftmailer.org/) (which has a pretty good reputation, and is used by the Symfony Framework), or [... | Media Temple has probably set it up this way to reduce the spam problems. You will have to ask Media Temple about the configuration.
I've worked with Media Temple before. They are pretty responsive to their customers needs. Chances are they have been asked and answered this question before. |
1,023,967 | On a Rails project, I'm using Sphinx together with Thinking Sphinx plugin. I index a table with an attribute :foo that is a float.
My desired behaviour when sorting for column :foo would be that nil values always appear at the end of the list, e.g.
```
id; foo (order foo desc)
-------
1; 5
2; 3
3; -4
4: -5
5: nil
6:... | 2009/06/21 | [
"https://Stackoverflow.com/questions/1023967",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/117525/"
] | The solution you've provided is what I would suggest - as yes, you're correct, Sphinx treats NULLs as 0's. | One solution I came up with in the meantime is to index an extra attribute, like this:
```
define_index do
indexes foo, :sortable => true
has "foo IS NULL", :as => :foo_nil, :sortable => true
end
```
what lets me order like this
```
:order => "foo_nil ASC, foo DESC"
```
It's a bit clumsy, especially as I hav... |
1,635,279 | When I format a text field to be displayed in "Bold"..it appears as bold in the ireport output, but is not displayed in bold when the same is viewed as a PDF..
any suggestions...? | 2009/10/28 | [
"https://Stackoverflow.com/questions/1635279",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/196444/"
] | Just had the same problem... I don't know if it will help you, but...
both the text field and the label have a property called "Pdf font name". You have to set this to a bold font (i.e. "Helvetica-Bold" instead of "Helvetica") to render the field bold in a PDF file.
If you edit the JRXML file directly, this setting i... | PdfFont name is obsolete. Use font extension instead. Add jasperreports-fonts-xxx.jar into the classpath. Or try <http://sites.google.com/site/xmedeko/code/misc/jasperreports-pdf-font-mapping> |
1,635,279 | When I format a text field to be displayed in "Bold"..it appears as bold in the ireport output, but is not displayed in bold when the same is viewed as a PDF..
any suggestions...? | 2009/10/28 | [
"https://Stackoverflow.com/questions/1635279",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/196444/"
] | Just had the same problem... I don't know if it will help you, but...
both the text field and the label have a property called "Pdf font name". You have to set this to a bold font (i.e. "Helvetica-Bold" instead of "Helvetica") to render the field bold in a PDF file.
If you edit the JRXML file directly, this setting i... | An excellent article on here gives the answer...
javaskeleton.blogspot.co.at/2010/12/embedding-fonts-into-pdf-generated-by.html
So you have to add the TrueType file of the font you want from C:\Windows\Fonts into iReport. In the latest version of iReport, which is 4.01, you go to Tools -> Options -> iReport Tab -> Fo... |
1,635,279 | When I format a text field to be displayed in "Bold"..it appears as bold in the ireport output, but is not displayed in bold when the same is viewed as a PDF..
any suggestions...? | 2009/10/28 | [
"https://Stackoverflow.com/questions/1635279",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/196444/"
] | Just had the same problem... I don't know if it will help you, but...
both the text field and the label have a property called "Pdf font name". You have to set this to a bold font (i.e. "Helvetica-Bold" instead of "Helvetica") to render the field bold in a PDF file.
If you edit the JRXML file directly, this setting i... | I had the same problem but I solved it by changing the version of jar file of Jasper in my web application.I compiled my jrxml file in Jaspersoft iReport 5.6.0 and the version of jar file of Jasper is also 5.6.0.
Previously it was 5.5.0 that is why it was not appearing in bold through the web application. |
1,635,279 | When I format a text field to be displayed in "Bold"..it appears as bold in the ireport output, but is not displayed in bold when the same is viewed as a PDF..
any suggestions...? | 2009/10/28 | [
"https://Stackoverflow.com/questions/1635279",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/196444/"
] | PdfFont name is obsolete. Use font extension instead. Add jasperreports-fonts-xxx.jar into the classpath. Or try <http://sites.google.com/site/xmedeko/code/misc/jasperreports-pdf-font-mapping> | An excellent article on here gives the answer...
javaskeleton.blogspot.co.at/2010/12/embedding-fonts-into-pdf-generated-by.html
So you have to add the TrueType file of the font you want from C:\Windows\Fonts into iReport. In the latest version of iReport, which is 4.01, you go to Tools -> Options -> iReport Tab -> Fo... |
1,635,279 | When I format a text field to be displayed in "Bold"..it appears as bold in the ireport output, but is not displayed in bold when the same is viewed as a PDF..
any suggestions...? | 2009/10/28 | [
"https://Stackoverflow.com/questions/1635279",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/196444/"
] | Just put this in your pom.xml:
```
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports-fonts</artifactId>
<version>5.6.1</version>
</dependency>
``` | PdfFont name is obsolete. Use font extension instead. Add jasperreports-fonts-xxx.jar into the classpath. Or try <http://sites.google.com/site/xmedeko/code/misc/jasperreports-pdf-font-mapping> |
1,635,279 | When I format a text field to be displayed in "Bold"..it appears as bold in the ireport output, but is not displayed in bold when the same is viewed as a PDF..
any suggestions...? | 2009/10/28 | [
"https://Stackoverflow.com/questions/1635279",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/196444/"
] | PdfFont name is obsolete. Use font extension instead. Add jasperreports-fonts-xxx.jar into the classpath. Or try <http://sites.google.com/site/xmedeko/code/misc/jasperreports-pdf-font-mapping> | I had the same problem but I solved it by changing the version of jar file of Jasper in my web application.I compiled my jrxml file in Jaspersoft iReport 5.6.0 and the version of jar file of Jasper is also 5.6.0.
Previously it was 5.5.0 that is why it was not appearing in bold through the web application. |
1,635,279 | When I format a text field to be displayed in "Bold"..it appears as bold in the ireport output, but is not displayed in bold when the same is viewed as a PDF..
any suggestions...? | 2009/10/28 | [
"https://Stackoverflow.com/questions/1635279",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/196444/"
] | Just put this in your pom.xml:
```
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports-fonts</artifactId>
<version>5.6.1</version>
</dependency>
``` | An excellent article on here gives the answer...
javaskeleton.blogspot.co.at/2010/12/embedding-fonts-into-pdf-generated-by.html
So you have to add the TrueType file of the font you want from C:\Windows\Fonts into iReport. In the latest version of iReport, which is 4.01, you go to Tools -> Options -> iReport Tab -> Fo... |
1,635,279 | When I format a text field to be displayed in "Bold"..it appears as bold in the ireport output, but is not displayed in bold when the same is viewed as a PDF..
any suggestions...? | 2009/10/28 | [
"https://Stackoverflow.com/questions/1635279",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/196444/"
] | An excellent article on here gives the answer...
javaskeleton.blogspot.co.at/2010/12/embedding-fonts-into-pdf-generated-by.html
So you have to add the TrueType file of the font you want from C:\Windows\Fonts into iReport. In the latest version of iReport, which is 4.01, you go to Tools -> Options -> iReport Tab -> Fo... | I had the same problem but I solved it by changing the version of jar file of Jasper in my web application.I compiled my jrxml file in Jaspersoft iReport 5.6.0 and the version of jar file of Jasper is also 5.6.0.
Previously it was 5.5.0 that is why it was not appearing in bold through the web application. |
1,635,279 | When I format a text field to be displayed in "Bold"..it appears as bold in the ireport output, but is not displayed in bold when the same is viewed as a PDF..
any suggestions...? | 2009/10/28 | [
"https://Stackoverflow.com/questions/1635279",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/196444/"
] | Just put this in your pom.xml:
```
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports-fonts</artifactId>
<version>5.6.1</version>
</dependency>
``` | I had the same problem but I solved it by changing the version of jar file of Jasper in my web application.I compiled my jrxml file in Jaspersoft iReport 5.6.0 and the version of jar file of Jasper is also 5.6.0.
Previously it was 5.5.0 that is why it was not appearing in bold through the web application. |
1,853,181 | I'm getting a fishy error when using glDrawElements(). I'm trying to render simple primitives (mainly rectangles) to speed up drawing of text and so forth, but when I call glDrawElements() the WHOLE screen blinks black (not just my window area) for one frame or so. The next frame it turns back to the same "Windows colo... | 2009/12/05 | [
"https://Stackoverflow.com/questions/1853181",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/87973/"
] | Obviously you are mixing VBO mode and VA mode. This is perfectly possible but must be use with care.
When you call:
```
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
```
This means that next time you render something with `glDrawElements(..., ..., ..., x)`, it will use x as a pointer o... | Bah! Found it. When I did
```
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
```
before rendering the flickering+crashing stopped. Is this the expected behavior? Sorry for wasting time and space. |
1,871,240 | ```
// strings is a 2D array (each string is 11 bytes long)
char strings[][11] = {"0123456789", "2222244444", "3333366666"};
printf("String 3 Character 2 is %c\n", strings[2][1]);
```
How can I code this print statement using pointer arithmetic instead of the `strings[2][1]` ? | 2009/12/09 | [
"https://Stackoverflow.com/questions/1871240",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/227648/"
] | In C, `a[b]` is the same as `*(a+b)` (and since addition is commutative, that implies that it's also equivalent to `b[a]`. People writing for the International Obfuscated C Code Contest frequently rely on this, using things like `x["string"];`. Needless to say, it's best to avoid that sort of thing unless you're intent... | How did I do with this?
```
char strings[][11] = { "0123456789", "2222244444", "3333366666" };
printf("String 3 Character 2 is %c\n", *(*(strings + 2) + 1));
``` |
1,871,240 | ```
// strings is a 2D array (each string is 11 bytes long)
char strings[][11] = {"0123456789", "2222244444", "3333366666"};
printf("String 3 Character 2 is %c\n", strings[2][1]);
```
How can I code this print statement using pointer arithmetic instead of the `strings[2][1]` ? | 2009/12/09 | [
"https://Stackoverflow.com/questions/1871240",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/227648/"
] | In C, `a[b]` is the same as `*(a+b)` (and since addition is commutative, that implies that it's also equivalent to `b[a]`. People writing for the International Obfuscated C Code Contest frequently rely on this, using things like `x["string"];`. Needless to say, it's best to avoid that sort of thing unless you're intent... | ```
*(*(strings+2)+1)
``` |
963,796 | How does a digital clocking system deal with user error such as someone forgetting to clock out or someone erroneously entering their code causing them to clock someone else in/out (who might not even be on the schedule that day). Its obvious there could be issues of dishonesty, but what about human error? | 2009/06/08 | [
"https://Stackoverflow.com/questions/963796",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | The better T&A (time & attendance) programs actually let this be configured in any of a number of ways. (Btw, typically the clocking software itself just marks down a "transaction" - this employee at that time did this thing - with no further processing, leaving that to the T&A system.)
* Have a "hard" clock out time ... | so if it is to prevent human error, a password which is actually a "verification code" can be used. So if Joe is 0123 and Mary is 0124, Joe's entering 0123 needs to be matched with his entering verification code of 8888 so that the system knows it is really Joe, not Mary entering 0123 by accident. |
963,796 | How does a digital clocking system deal with user error such as someone forgetting to clock out or someone erroneously entering their code causing them to clock someone else in/out (who might not even be on the schedule that day). Its obvious there could be issues of dishonesty, but what about human error? | 2009/06/08 | [
"https://Stackoverflow.com/questions/963796",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | The better T&A (time & attendance) programs actually let this be configured in any of a number of ways. (Btw, typically the clocking software itself just marks down a "transaction" - this employee at that time did this thing - with no further processing, leaving that to the T&A system.)
* Have a "hard" clock out time ... | The system must allow to print a preview of the final time sheet. Employees then get a copy, can verify it and return fixes (signed by their boss). These get merged with the data that already exists.
Unless you hijack your employees, force a RFID into their spine and make them crawl through a scanner tube four times a... |
1,898,987 | In vim, I do search with vimgrep frequently. I have mapping like below:
```
map <leader>s :execute "noautocmd vimgrep /\\<" . expand("<cword>") . "\\>/gj **/*.*" <Bar>
cw<CR> 5
```
The problem is that there are some temporary subfolders (like obj, objd) that I don't want to search for. How can I exclude subfolders ... | 2009/12/14 | [
"https://Stackoverflow.com/questions/1898987",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26349/"
] | You could try [ack](http://betterthangrep.com/) instead. It integrates nicely with vim and has lots of options for doing the sort of thing you want to do.
There are several ack-vim integrations on GitHub. For example: [here](http://github.com/mileszs/ack.vim). | For example in Ubuntu just
```
sudo apt-get install ack-grep
sudo ln -s /usr/bin/ack-grep /usr/bin/ack
```
then install <http://www.vim.org/scripts/script.php?script_id=2572>
and now add next line to your .vimrc
```
noremap <C-f> :copen<CR>:Ack --ignore-dir #first_ignore_dir# --ignore-dir #second_ignore_dir# -ai ... |
1,898,987 | In vim, I do search with vimgrep frequently. I have mapping like below:
```
map <leader>s :execute "noautocmd vimgrep /\\<" . expand("<cword>") . "\\>/gj **/*.*" <Bar>
cw<CR> 5
```
The problem is that there are some temporary subfolders (like obj, objd) that I don't want to search for. How can I exclude subfolders ... | 2009/12/14 | [
"https://Stackoverflow.com/questions/1898987",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26349/"
] | As of Vim 7.3.570, you can use wildignore to exclude patterns with vimgrep.
For example, to ignore the objd subfolder:
```
:set wildignore+=objd/**
```
Additional exclusions can be added by separating patterns with a comma:
```
:set wildignore+=objd/**,obj/**,*.tmp,test.c
```
See Vim's help documentation for a f... | You could try [ack](http://betterthangrep.com/) instead. It integrates nicely with vim and has lots of options for doing the sort of thing you want to do.
There are several ack-vim integrations on GitHub. For example: [here](http://github.com/mileszs/ack.vim). |
1,898,987 | In vim, I do search with vimgrep frequently. I have mapping like below:
```
map <leader>s :execute "noautocmd vimgrep /\\<" . expand("<cword>") . "\\>/gj **/*.*" <Bar>
cw<CR> 5
```
The problem is that there are some temporary subfolders (like obj, objd) that I don't want to search for. How can I exclude subfolders ... | 2009/12/14 | [
"https://Stackoverflow.com/questions/1898987",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26349/"
] | As of Vim 7.3.570, you can use wildignore to exclude patterns with vimgrep.
For example, to ignore the objd subfolder:
```
:set wildignore+=objd/**
```
Additional exclusions can be added by separating patterns with a comma:
```
:set wildignore+=objd/**,obj/**,*.tmp,test.c
```
See Vim's help documentation for a f... | For example in Ubuntu just
```
sudo apt-get install ack-grep
sudo ln -s /usr/bin/ack-grep /usr/bin/ack
```
then install <http://www.vim.org/scripts/script.php?script_id=2572>
and now add next line to your .vimrc
```
noremap <C-f> :copen<CR>:Ack --ignore-dir #first_ignore_dir# --ignore-dir #second_ignore_dir# -ai ... |
1,898,987 | In vim, I do search with vimgrep frequently. I have mapping like below:
```
map <leader>s :execute "noautocmd vimgrep /\\<" . expand("<cword>") . "\\>/gj **/*.*" <Bar>
cw<CR> 5
```
The problem is that there are some temporary subfolders (like obj, objd) that I don't want to search for. How can I exclude subfolders ... | 2009/12/14 | [
"https://Stackoverflow.com/questions/1898987",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26349/"
] | As showed in <http://vimcasts.org/blog/2013/03/combining-vimgrep-with-git-ls-files/> you could instead of exclude files, include the files you want to search. So you can search in the files tracked by Git with
```
:noautocmd vimgrep /{pattern}/gj `git ls-files`
```
In this way you are not searching the files stated ... | For example in Ubuntu just
```
sudo apt-get install ack-grep
sudo ln -s /usr/bin/ack-grep /usr/bin/ack
```
then install <http://www.vim.org/scripts/script.php?script_id=2572>
and now add next line to your .vimrc
```
noremap <C-f> :copen<CR>:Ack --ignore-dir #first_ignore_dir# --ignore-dir #second_ignore_dir# -ai ... |
1,898,987 | In vim, I do search with vimgrep frequently. I have mapping like below:
```
map <leader>s :execute "noautocmd vimgrep /\\<" . expand("<cword>") . "\\>/gj **/*.*" <Bar>
cw<CR> 5
```
The problem is that there are some temporary subfolders (like obj, objd) that I don't want to search for. How can I exclude subfolders ... | 2009/12/14 | [
"https://Stackoverflow.com/questions/1898987",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26349/"
] | As of Vim 7.3.570, you can use wildignore to exclude patterns with vimgrep.
For example, to ignore the objd subfolder:
```
:set wildignore+=objd/**
```
Additional exclusions can be added by separating patterns with a comma:
```
:set wildignore+=objd/**,obj/**,*.tmp,test.c
```
See Vim's help documentation for a f... | As showed in <http://vimcasts.org/blog/2013/03/combining-vimgrep-with-git-ls-files/> you could instead of exclude files, include the files you want to search. So you can search in the files tracked by Git with
```
:noautocmd vimgrep /{pattern}/gj `git ls-files`
```
In this way you are not searching the files stated ... |
3,052,418 | This is an odd one, not one I've come across before. My project complies and runs fine if I have my classes in the root folder (Not in App\_Code).
As soon as I move them into the App\_Code folder then it will compile, but running it will bring up the old
```
CS0234: The type or namespace name 'Linq' does not exist i... | 2010/06/16 | [
"https://Stackoverflow.com/questions/3052418",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/175407/"
] | You have to modify the web.config file of your web application to make it compile and use .net 3.5 (or maybe higher in your case):
```
<system.web>
<compilation>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
</compilation>
</system.web>
<system.codedom>
<c... | The reference is System.Linq, not System.Data.Linq.
How is your reference declared? |
3,052,418 | This is an odd one, not one I've come across before. My project complies and runs fine if I have my classes in the root folder (Not in App\_Code).
As soon as I move them into the App\_Code folder then it will compile, but running it will bring up the old
```
CS0234: The type or namespace name 'Linq' does not exist i... | 2010/06/16 | [
"https://Stackoverflow.com/questions/3052418",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/175407/"
] | You have to modify the web.config file of your web application to make it compile and use .net 3.5 (or maybe higher in your case):
```
<system.web>
<compilation>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
</compilation>
</system.web>
<system.codedom>
<c... | I had the exact same problem. The answer for me was to set Local Copy to True in the Properties Window for System.Data.Linq. |
3,052,418 | This is an odd one, not one I've come across before. My project complies and runs fine if I have my classes in the root folder (Not in App\_Code).
As soon as I move them into the App\_Code folder then it will compile, but running it will bring up the old
```
CS0234: The type or namespace name 'Linq' does not exist i... | 2010/06/16 | [
"https://Stackoverflow.com/questions/3052418",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/175407/"
] | I had the exact same problem. The answer for me was to set Local Copy to True in the Properties Window for System.Data.Linq. | The reference is System.Linq, not System.Data.Linq.
How is your reference declared? |
2,931,819 | I have an arbitrarily deep list of the form:
```
<ul>
<li></li>
<li>
<ul>
<li></li>
</ul>
</li>
</ul>
```
I am trying to build a function "nextElement" that returns a jQuery selector.
The first time the function is called, it returns the first li in the list. The second time it is called, it returns the n... | 2010/05/28 | [
"https://Stackoverflow.com/questions/2931819",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/283510/"
] | The no-jQuery solution..
```
function getIterator(){
var nodes = document.getElementByTagName("li");
var index = 0;
return {
next: function(){
return nodes[index++];
},
hasNext: function(){
return index < nodes.lenght - 1;
}
};
}
```
Then use
`... | Probably best to modify the concept of nextElement to be more like this:
```
(function($) {
var index = -1;
jQuery.fn.nextElement = function() {
index = (index + 1) % this.length;
return this.eq(index);
}
})(jQuery);
```
You can use it like this:
```
$("li").nextElement(); // returns fir... |
10,264 | I'd like some advice regarding defects on my print :
[](https://i.stack.imgur.com/5x4u2.jpg)
[](https://i.stack.imgur.com/3CgUe.jpg)
Here some details :
* Printer CR-10 S, nozzle 0.... | 2019/06/14 | [
"https://3dprinting.stackexchange.com/questions/10264",
"https://3dprinting.stackexchange.com",
"https://3dprinting.stackexchange.com/users/16756/"
] | If you break up a large piece into multiple smaller pieces and properly glue them together, you basically add stiffeners (as a result of printing walls). This could lead to a more stiff model; this might have been confused by calling large prints more brittle opposed to constructed models.
If printing is conducted at ... | I'd recommend getting the object to fit together by design, rather than glue - though I tend (if the item is never to be disassembled) use Zap-a-gap - that stuff sticks like crazy though you must not squeeze the parts together but let it naturally sit. |
2,206,607 | I have built a cms from scratch in PHP and I need a little help with getting it more secure. Basically I have arranged all my important files as followed:
```
/var/www/TESTUSERNAME/includes/val.php
```
Is this a secure way to stop people from getting hold of my values ?
Would it be a better to store these values i... | 2010/02/05 | [
"https://Stackoverflow.com/questions/2206607",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/123663/"
] | First of all, you configure the [php installation](http://www.securityfocus.com/infocus/1706) in such way that it becomes **less vulnerable**, you can also use the htaccess file to secure your directories.
What about other security issues?
**XSS
CSFR
SQL Injection
Session hijacking
Session Fixation
et... | Check POST data for SQL injection, XSS:Filter script (and HTML) inserted to your page.
These 2 are the most important.
And of course update your installation. also you shouldn't rely on Session. If somebody stole a cookie of logged user he change into this user. |
2,206,607 | I have built a cms from scratch in PHP and I need a little help with getting it more secure. Basically I have arranged all my important files as followed:
```
/var/www/TESTUSERNAME/includes/val.php
```
Is this a secure way to stop people from getting hold of my values ?
Would it be a better to store these values i... | 2010/02/05 | [
"https://Stackoverflow.com/questions/2206607",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/123663/"
] | First of all, you configure the [php installation](http://www.securityfocus.com/infocus/1706) in such way that it becomes **less vulnerable**, you can also use the htaccess file to secure your directories.
What about other security issues?
**XSS
CSFR
SQL Injection
Session hijacking
Session Fixation
et... | If you put the values in the database then you have to worry about SQL Injection. If you aren't using parametrized quires, then you might have a serious problem with SQL Injection and moving the values to the database could be a bad idea due to this increased attack surface. In MySQL SQL injection can be used to read f... |
1,817,640 | Is there a way to use the PHP `=>` operator (?) without using the `array()` "constructor"?
To be specific, I want to create a function that will get a list of keys and values without wrapping it into an array:
```
function keysAndValues($items) {
/* ... */
}
keysAndValues(
'key1' => 'value1',
'key2' => '... | 2009/11/30 | [
"https://Stackoverflow.com/questions/1817640",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41983/"
] | These would be named arguments. Nope, not possible in PHP. You will have to wrap an array() around them.
If it's not the array that's bothering you but the fact that you have to work with an array inside the function, try
```
function my_function($array)
{
extract($array);
...
if (isset($number)) echo "Number is: ".$... | well, specifically, the '=>' operator denotes the key, value pair inside an array, so there's really **no reason** to use it outside the array constructor.
that said, it is used inside things like a 'foreach' loop to grab the key and value for each item in an array
```
foreach ($arr as $key=>$val)
``` |
1,817,640 | Is there a way to use the PHP `=>` operator (?) without using the `array()` "constructor"?
To be specific, I want to create a function that will get a list of keys and values without wrapping it into an array:
```
function keysAndValues($items) {
/* ... */
}
keysAndValues(
'key1' => 'value1',
'key2' => '... | 2009/11/30 | [
"https://Stackoverflow.com/questions/1817640",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41983/"
] | These would be named arguments. Nope, not possible in PHP. You will have to wrap an array() around them.
If it's not the array that's bothering you but the fact that you have to work with an array inside the function, try
```
function my_function($array)
{
extract($array);
...
if (isset($number)) echo "Number is: ".$... | The closest thing you can get to what you want is by using dynamic arguments.
Using [this tutorial/overview](http://oreilly.com/pub/a/php/2001/05/17/php_foundations.html) as a base, here is a hack to provide a potential solution:
```
function keysAndValues() {
for($i = 0 ; $i < func_num_args(); $i++) {
list... |
1,817,640 | Is there a way to use the PHP `=>` operator (?) without using the `array()` "constructor"?
To be specific, I want to create a function that will get a list of keys and values without wrapping it into an array:
```
function keysAndValues($items) {
/* ... */
}
keysAndValues(
'key1' => 'value1',
'key2' => '... | 2009/11/30 | [
"https://Stackoverflow.com/questions/1817640",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41983/"
] | The closest thing you can get to what you want is by using dynamic arguments.
Using [this tutorial/overview](http://oreilly.com/pub/a/php/2001/05/17/php_foundations.html) as a base, here is a hack to provide a potential solution:
```
function keysAndValues() {
for($i = 0 ; $i < func_num_args(); $i++) {
list... | well, specifically, the '=>' operator denotes the key, value pair inside an array, so there's really **no reason** to use it outside the array constructor.
that said, it is used inside things like a 'foreach' loop to grab the key and value for each item in an array
```
foreach ($arr as $key=>$val)
``` |
153,724 | What I would like is a method to convert a double to a string which rounds using the half-up method - i.e. if the decimal to be rounded is 5, it always rounds up to the next number. This is the standard method of rounding most people expect in most situations.
I also would like only significant digits to be displayed ... | 2008/09/30 | [
"https://Stackoverflow.com/questions/153724",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12149/"
] | Assuming `value` is a `double`, you can do:
```
(double)Math.round(value * 100000d) / 100000d
```
That's for 5 digits precision. The number of zeros indicate the number of decimals. | If you Consider 5 or n number of decimal.
May be this answer solve your prob.
```
double a = 123.00449;
double roundOff1 = Math.round(a*10000)/10000.00;
double roundOff2 = Math.round(roundOff1*1000)/1000.00;
double roundOff = Math.round(roundOff2*100)/100.00;
System.out.println("result:"+roundOff)... |
153,724 | What I would like is a method to convert a double to a string which rounds using the half-up method - i.e. if the decimal to be rounded is 5, it always rounds up to the next number. This is the standard method of rounding most people expect in most situations.
I also would like only significant digits to be displayed ... | 2008/09/30 | [
"https://Stackoverflow.com/questions/153724",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12149/"
] | Assuming `value` is a `double`, you can do:
```
(double)Math.round(value * 100000d) / 100000d
```
That's for 5 digits precision. The number of zeros indicate the number of decimals. | Keep in mind that String.format() and DecimalFormat produce string using default Locale. So they may write formatted number with dot or comma as a separator between integer and decimal parts. To make sure that rounded String is in the format you want use java.text.NumberFormat as so:
```
Locale locale = Locale.ENGLI... |
153,724 | What I would like is a method to convert a double to a string which rounds using the half-up method - i.e. if the decimal to be rounded is 5, it always rounds up to the next number. This is the standard method of rounding most people expect in most situations.
I also would like only significant digits to be displayed ... | 2008/09/30 | [
"https://Stackoverflow.com/questions/153724",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12149/"
] | You can also use the
```
DecimalFormat df = new DecimalFormat("#.00000");
df.format(0.912385);
```
to make sure you have the trailing 0's. | There is a problem with the `Math.round` solution when trying to round to a negative number of decimal places. Consider the code
```
long l = 10;
for(int dp = -1; dp > -10; --dp) {
double mul = Math.pow(10,dp);
double res = Math.round(l * mul) / mul;
System.out.println(""+l+" rounded to "+dp+" dp = "+res);... |
153,724 | What I would like is a method to convert a double to a string which rounds using the half-up method - i.e. if the decimal to be rounded is 5, it always rounds up to the next number. This is the standard method of rounding most people expect in most situations.
I also would like only significant digits to be displayed ... | 2008/09/30 | [
"https://Stackoverflow.com/questions/153724",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12149/"
] | You can also use the
```
DecimalFormat df = new DecimalFormat("#.00000");
df.format(0.912385);
```
to make sure you have the trailing 0's. | here is my answer:
```
double num = 4.898979485566356;
DecimalFormat df = new DecimalFormat("#.##");
time = Double.valueOf(df.format(num));
System.out.println(num); // 4.89
``` |
153,724 | What I would like is a method to convert a double to a string which rounds using the half-up method - i.e. if the decimal to be rounded is 5, it always rounds up to the next number. This is the standard method of rounding most people expect in most situations.
I also would like only significant digits to be displayed ... | 2008/09/30 | [
"https://Stackoverflow.com/questions/153724",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12149/"
] | As some others have noted, the correct answer is to use either `DecimalFormat` or `BigDecimal`. Floating-point doesn't *have* decimal places so you cannot possibly round/truncate to a specific number of them in the first place. You have to work in a decimal radix, and that is what those two classes do.
I am posting th... | This was the simplest way I found to display only two decimal places.
```
double x = 123.123;
System.out.printf( "%.2f", x );
``` |
153,724 | What I would like is a method to convert a double to a string which rounds using the half-up method - i.e. if the decimal to be rounded is 5, it always rounds up to the next number. This is the standard method of rounding most people expect in most situations.
I also would like only significant digits to be displayed ... | 2008/09/30 | [
"https://Stackoverflow.com/questions/153724",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12149/"
] | You can also use the
```
DecimalFormat df = new DecimalFormat("#.00000");
df.format(0.912385);
```
to make sure you have the trailing 0's. | Try this: org.apache.commons.math3.util.Precision.round(double x, int scale)
See: <http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math3/util/Precision.html>
Apache Commons Mathematics Library homepage is: <http://commons.apache.org/proper/commons-math/index.html>
The internal implemetation ... |
153,724 | What I would like is a method to convert a double to a string which rounds using the half-up method - i.e. if the decimal to be rounded is 5, it always rounds up to the next number. This is the standard method of rounding most people expect in most situations.
I also would like only significant digits to be displayed ... | 2008/09/30 | [
"https://Stackoverflow.com/questions/153724",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12149/"
] | Try this: org.apache.commons.math3.util.Precision.round(double x, int scale)
See: <http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math3/util/Precision.html>
Apache Commons Mathematics Library homepage is: <http://commons.apache.org/proper/commons-math/index.html>
The internal implemetation ... | If you're using a technology that has a minimal JDK. Here's a way without any Java libs:
```
double scale = 100000;
double myVal = 0.912385;
double rounded = (int)((myVal * scale) + 0.5d) / scale;
``` |
153,724 | What I would like is a method to convert a double to a string which rounds using the half-up method - i.e. if the decimal to be rounded is 5, it always rounds up to the next number. This is the standard method of rounding most people expect in most situations.
I also would like only significant digits to be displayed ... | 2008/09/30 | [
"https://Stackoverflow.com/questions/153724",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12149/"
] | Assuming `value` is a `double`, you can do:
```
(double)Math.round(value * 100000d) / 100000d
```
That's for 5 digits precision. The number of zeros indicate the number of decimals. | DecimalFormat is the best ways to output, but I don't prefer it. I always do this all the time, because it return the double value. So I can use it more than just output.
```
Math.round(selfEvaluate*100000d.0)/100000d.0;
```
OR
```
Math.round(selfEvaluate*100000d.0)*0.00000d1;
```
If you need large decimal places... |
153,724 | What I would like is a method to convert a double to a string which rounds using the half-up method - i.e. if the decimal to be rounded is 5, it always rounds up to the next number. This is the standard method of rounding most people expect in most situations.
I also would like only significant digits to be displayed ... | 2008/09/30 | [
"https://Stackoverflow.com/questions/153724",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12149/"
] | Try this: org.apache.commons.math3.util.Precision.round(double x, int scale)
See: <http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math3/util/Precision.html>
Apache Commons Mathematics Library homepage is: <http://commons.apache.org/proper/commons-math/index.html>
The internal implemetation ... | The code snippet below shows how to display n digits. The trick is to set variable pp to 1 followed by n zeros. In the example below, variable pp value has 5 zeros, so 5 digits will be displayed.
```
double pp = 10000;
double myVal = 22.268699999999967;
String needVal = "22.2687";
double i = (5.0/pp);
String format... |
153,724 | What I would like is a method to convert a double to a string which rounds using the half-up method - i.e. if the decimal to be rounded is 5, it always rounds up to the next number. This is the standard method of rounding most people expect in most situations.
I also would like only significant digits to be displayed ... | 2008/09/30 | [
"https://Stackoverflow.com/questions/153724",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12149/"
] | A succinct solution:
```
public static double round(double value, int precision) {
int scale = (int) Math.pow(10, precision);
return (double) (Math.round(value * scale) / scale);
}
```
See also, <https://stackoverflow.com/a/22186845/212950>
Thanks to [jpdymond](https://stackoverflow.com/users/298407... | Keep in mind that String.format() and DecimalFormat produce string using default Locale. So they may write formatted number with dot or comma as a separator between integer and decimal parts. To make sure that rounded String is in the format you want use java.text.NumberFormat as so:
```
Locale locale = Locale.ENGLI... |
1,478,983 | I know that FlexBuiler's refactoring engine can deal with updating variable names… But I can't figure out if it's possible to refactor at the package level.
For example, I want to move `foo/a.as` to `foo/bar/a.as`, and I want the `package` path to be updated (ie, from `package foo` to `package foo.bar`) and references... | 2009/09/25 | [
"https://Stackoverflow.com/questions/1478983",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/71522/"
] | No, it does not. Sorry. Your only option is to follow that with Ctrl-H, and swap out foo. with foo.bar. | The upcoming [Flash Builder 4](http://labs.adobe.com/technologies/flashbuilder4/) will support Move refactoring to move a class into a different package. A public beta is available on Adobe Labs. |
1,904,318 | I've got an editor with lots of image thumbnails. I'd like a double-click on an image to display the full resolution image using a modal undecorated dialog. Ideally, this would be animated, to show the image zooming up to full resolution on the center of the screen, then any click would make the image go away, either z... | 2009/12/14 | [
"https://Stackoverflow.com/questions/1904318",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14467/"
] | This piece of code does more or less the trick...
There is still a problem in the way I'm setting the dialog's location...
Hope it helps.
```
import java.awt.BorderLayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geo... | You can create a custom control that displays the image at the scale you want.
1) Create a BufferedImage from the image file you want using [ImageIO.read(file)](http://java.sun.com/javase/6/docs/api/javax/imageio/ImageIO.html#read%28java.io.File%29) (you can also create it from an InputStream)
2) Extend the JCompon... |
161,937 | I understand there is a HTTP response header directive to disable page caching:
```
Cache-Control:no-cache
```
I can modify the header by "hand":
```
<%response.addHeader("Cache-Control","no-cache");%>
```
But is there a "nice" way to make the JSP interpreter return this header line in the server response?
(I c... | 2008/10/02 | [
"https://Stackoverflow.com/questions/161937",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17428/"
] | Also add
```
response.addHeader("Expires","-1");
response.addHeader("Pragma","no-cache");
```
to your headers and give that a shot. | If you were using a servlet, then I believe what you posted in the question would be the correct approach. I'm not aware of any way to do this in the JSP. |
161,937 | I understand there is a HTTP response header directive to disable page caching:
```
Cache-Control:no-cache
```
I can modify the header by "hand":
```
<%response.addHeader("Cache-Control","no-cache");%>
```
But is there a "nice" way to make the JSP interpreter return this header line in the server response?
(I c... | 2008/10/02 | [
"https://Stackoverflow.com/questions/161937",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17428/"
] | Also add
```
response.addHeader("Expires","-1");
response.addHeader("Pragma","no-cache");
```
to your headers and give that a shot. | ```
<?xml version="1.0"?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0">
<jsp:scriptlet><![CDATA[
response.setHeader("Cache-Control", "no-cache");
]]></jsp:scriptlet>
</jsp:root>
```
You must put the response header inside `<jsp:root />`. Also, I would instead recommend it sending this from y... |
161,937 | I understand there is a HTTP response header directive to disable page caching:
```
Cache-Control:no-cache
```
I can modify the header by "hand":
```
<%response.addHeader("Cache-Control","no-cache");%>
```
But is there a "nice" way to make the JSP interpreter return this header line in the server response?
(I c... | 2008/10/02 | [
"https://Stackoverflow.com/questions/161937",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17428/"
] | Also add
```
response.addHeader("Expires","-1");
response.addHeader("Pragma","no-cache");
```
to your headers and give that a shot. | IIRC some browsers may ignore the cache control settings in some contexts. The 'safe' workaround for this was to always get a page (even an AJAX chunk) with a new query string variable (like the time.) |
1,447,184 | Does it actually matter which CDN you use to link to your jquery file or any javascript file for that matter. Is one potentially faster than the other? What other factors could play a role in which cdn you decide to use? I know that Microsoft, Yahoo, and Google all have CDN's now. | 2009/09/18 | [
"https://Stackoverflow.com/questions/1447184",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33690/"
] | **Update based on comments:**
**Short version:** It doesn't matter much, but it may depend on what they host. They all host different things: Google doesn't host jQuery.Validate, Microsoft did not host jQuery-UI, since 2016 they do!!, Microsoft offers their scripts that would otherwise be served via `ScriptResource.a... | You should absolutely use the Google CDN for jQuery (and this is coming from a Microsoft-centric developer).
It's simple statistics. Those who would consider using the MS CDN for jQuery will always be a minority. There are too many non-MS developers using jQuery who will use Google's and wouldn't consider using Micros... |
1,447,184 | Does it actually matter which CDN you use to link to your jquery file or any javascript file for that matter. Is one potentially faster than the other? What other factors could play a role in which cdn you decide to use? I know that Microsoft, Yahoo, and Google all have CDN's now. | 2009/09/18 | [
"https://Stackoverflow.com/questions/1447184",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33690/"
] | >
> Is one potentially faster than the other?
>
>
>
I was actually curious of this myself so I setup a jsbin test page using each of the following and then ran it through webpagetest.org's visual comparison tool. I tested:
1. ajax.googleapis.com
2. code.jquery.com
3. ajax.aspnetcdn.com
4. cdnjs.cloudflare.com
W... | As stated by [Pingdom](http://royal.pingdom.com/2010/05/11/cdn-performance-downloading-jquery-from-google-microsoft-and-edgecast-cdns/):
>
> When someone visits your site, if they have already visited another
> site that uses the same jQuery file on the same CDN, the file will
> have been cached and doesn’t need to... |
1,447,184 | Does it actually matter which CDN you use to link to your jquery file or any javascript file for that matter. Is one potentially faster than the other? What other factors could play a role in which cdn you decide to use? I know that Microsoft, Yahoo, and Google all have CDN's now. | 2009/09/18 | [
"https://Stackoverflow.com/questions/1447184",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33690/"
] | One minor thing to consider is that both companies offer slightly different "extra" libraries:
* Microsoft is offering the **JQuery validation library** on their CDN, whereas Google is not (<http://www.asp.net/ajaxlibrary/cdn.ashx>)
* Google is offering the **JQuery UI library** on their CDN, whereas Microsoft is not ... | I think it depends on where is your targeted audience. You can use alertra.com to check both CDN speed from many locations around the world. |
1,447,184 | Does it actually matter which CDN you use to link to your jquery file or any javascript file for that matter. Is one potentially faster than the other? What other factors could play a role in which cdn you decide to use? I know that Microsoft, Yahoo, and Google all have CDN's now. | 2009/09/18 | [
"https://Stackoverflow.com/questions/1447184",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33690/"
] | My answer is bit different than others, I will go with microsoft if you need jquery validator which almost everyone need if you are using jquery.
Microsoft CDN http connection is Keep-Alive which is big plus when you are requesting multiple items.
So if you need jquery validation then use Microsoft CDN, even if you n... | Also consider when using Google CDN that some times people make typos such as ajax.googelapis.com. This could potentially create a really nasty xss (cross site scripting) attack. I have actually tested this out by registering a googlapis.com typo and very quickly found myself serving requests for javascript, maps, css ... |
1,447,184 | Does it actually matter which CDN you use to link to your jquery file or any javascript file for that matter. Is one potentially faster than the other? What other factors could play a role in which cdn you decide to use? I know that Microsoft, Yahoo, and Google all have CDN's now. | 2009/09/18 | [
"https://Stackoverflow.com/questions/1447184",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33690/"
] | It probably doesn't matter, but you could validate this with some A/B testing. Send half of your traffic to one CDN, and half to the other, and set up some profiling to measure the response. I would think it more important to be able to switch easily in case one or the other had some serious unavailability issues. | As stated by [Pingdom](http://royal.pingdom.com/2010/05/11/cdn-performance-downloading-jquery-from-google-microsoft-and-edgecast-cdns/):
>
> When someone visits your site, if they have already visited another
> site that uses the same jQuery file on the same CDN, the file will
> have been cached and doesn’t need to... |
1,447,184 | Does it actually matter which CDN you use to link to your jquery file or any javascript file for that matter. Is one potentially faster than the other? What other factors could play a role in which cdn you decide to use? I know that Microsoft, Yahoo, and Google all have CDN's now. | 2009/09/18 | [
"https://Stackoverflow.com/questions/1447184",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33690/"
] | As stated by [Pingdom](http://royal.pingdom.com/2010/05/11/cdn-performance-downloading-jquery-from-google-microsoft-and-edgecast-cdns/):
>
> When someone visits your site, if they have already visited another
> site that uses the same jQuery file on the same CDN, the file will
> have been cached and doesn’t need to... | Depending which industry the application targets, you may not want to use a CDN managed by other organisations. It often raises issues regarding to compliance, privacy and confidentiality.
For example, when you include Google Analytics in a secure application, the browser still sends the current URL as the "referer" ... |
1,447,184 | Does it actually matter which CDN you use to link to your jquery file or any javascript file for that matter. Is one potentially faster than the other? What other factors could play a role in which cdn you decide to use? I know that Microsoft, Yahoo, and Google all have CDN's now. | 2009/09/18 | [
"https://Stackoverflow.com/questions/1447184",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33690/"
] | One minor thing to consider is that both companies offer slightly different "extra" libraries:
* Microsoft is offering the **JQuery validation library** on their CDN, whereas Google is not (<http://www.asp.net/ajaxlibrary/cdn.ashx>)
* Google is offering the **JQuery UI library** on their CDN, whereas Microsoft is not ... | My answer is bit different than others, I will go with microsoft if you need jquery validator which almost everyone need if you are using jquery.
Microsoft CDN http connection is Keep-Alive which is big plus when you are requesting multiple items.
So if you need jquery validation then use Microsoft CDN, even if you n... |
1,447,184 | Does it actually matter which CDN you use to link to your jquery file or any javascript file for that matter. Is one potentially faster than the other? What other factors could play a role in which cdn you decide to use? I know that Microsoft, Yahoo, and Google all have CDN's now. | 2009/09/18 | [
"https://Stackoverflow.com/questions/1447184",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33690/"
] | Google will send you a jQuery version minified with their own software, this version is 6kb lighter than the standard minified version served by MS. Go for Google. | My answer is bit different than others, I will go with microsoft if you need jquery validator which almost everyone need if you are using jquery.
Microsoft CDN http connection is Keep-Alive which is big plus when you are requesting multiple items.
So if you need jquery validation then use Microsoft CDN, even if you n... |
1,447,184 | Does it actually matter which CDN you use to link to your jquery file or any javascript file for that matter. Is one potentially faster than the other? What other factors could play a role in which cdn you decide to use? I know that Microsoft, Yahoo, and Google all have CDN's now. | 2009/09/18 | [
"https://Stackoverflow.com/questions/1447184",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33690/"
] | You should absolutely use the Google CDN for jQuery (and this is coming from a Microsoft-centric developer).
It's simple statistics. Those who would consider using the MS CDN for jQuery will always be a minority. There are too many non-MS developers using jQuery who will use Google's and wouldn't consider using Micros... | Google will send you a jQuery version minified with their own software, this version is 6kb lighter than the standard minified version served by MS. Go for Google. |
1,447,184 | Does it actually matter which CDN you use to link to your jquery file or any javascript file for that matter. Is one potentially faster than the other? What other factors could play a role in which cdn you decide to use? I know that Microsoft, Yahoo, and Google all have CDN's now. | 2009/09/18 | [
"https://Stackoverflow.com/questions/1447184",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33690/"
] | As stated by [Pingdom](http://royal.pingdom.com/2010/05/11/cdn-performance-downloading-jquery-from-google-microsoft-and-edgecast-cdns/):
>
> When someone visits your site, if they have already visited another
> site that uses the same jQuery file on the same CDN, the file will
> have been cached and doesn’t need to... | I would advise that you base your usage on the general location of the users you're targeting.
If your site is targeted for general public, then using Google's CDN would be a good choice.
If your site is also targeted at China, then using Microsoft's CDN would be a better choice.
I know from my experience, as Google'... |
2,148,144 | So let's say I have a red square image that turns green when the mouse goes over it, and it turns back to red when the mouse leaves the square. I then made a menu sort of thing with it so that when I hover on the square, it turns green and a rectangle appears below it.
What I want to happen is this: After the rectang... | 2010/01/27 | [
"https://Stackoverflow.com/questions/2148144",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/260205/"
] | You have just a few errors in your code.
1. You never remove any classes, you only try adding classes. This will only work once, and all subsequent tries won't do anything since jQuery will not add the same class twice to the same element.
2. You shouldn't use the dot syntax when adding classes. Just supply the class... | If the menu is inside the square you can try something like this:
```
$('.square').bind("mouseenter",function(){
$(this).addClass('green');
$('.rectangle').show();
});
$('.square').bind("mouseleave",function(){
$(this).addClass('red');
$('.rectangle').hide();
});
``` |
2,148,144 | So let's say I have a red square image that turns green when the mouse goes over it, and it turns back to red when the mouse leaves the square. I then made a menu sort of thing with it so that when I hover on the square, it turns green and a rectangle appears below it.
What I want to happen is this: After the rectang... | 2010/01/27 | [
"https://Stackoverflow.com/questions/2148144",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/260205/"
] | I have recently had the same problem. What I did was adding an `mouseenter` event to the "child" element too so while passing from parent to child it's not turned off. Basically I have `mouseenter` and `mouseleave` on both elements (which of course are slightly overlapping for this to work). | If the menu is inside the square you can try something like this:
```
$('.square').bind("mouseenter",function(){
$(this).addClass('green');
$('.rectangle').show();
});
$('.square').bind("mouseleave",function(){
$(this).addClass('red');
$('.rectangle').hide();
});
``` |
2,148,144 | So let's say I have a red square image that turns green when the mouse goes over it, and it turns back to red when the mouse leaves the square. I then made a menu sort of thing with it so that when I hover on the square, it turns green and a rectangle appears below it.
What I want to happen is this: After the rectang... | 2010/01/27 | [
"https://Stackoverflow.com/questions/2148144",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/260205/"
] | You have just a few errors in your code.
1. You never remove any classes, you only try adding classes. This will only work once, and all subsequent tries won't do anything since jQuery will not add the same class twice to the same element.
2. You shouldn't use the dot syntax when adding classes. Just supply the class... | I have recently had the same problem. What I did was adding an `mouseenter` event to the "child" element too so while passing from parent to child it's not turned off. Basically I have `mouseenter` and `mouseleave` on both elements (which of course are slightly overlapping for this to work). |
3,103,982 | This Java code lists files in a directory on a Windows shared drive. Will it work correctly on a Unix system?
```
File directory = new File("\\\\server/Shared/stuff/mystuff");
for (File file: directory.listFiles()) {
System.out.println(file);
}
``` | 2010/06/23 | [
"https://Stackoverflow.com/questions/3103982",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/374479/"
] | Short answer: No.
Long answer: Do you have samba installed? Even then you need to mount the the share. So it probably won't work.
**EDIT**
Java delegates the call to the underlying OS eventually. Since Unix doesn't know what the `\\SERVERNAME` path means, Java doesn't know what it means either. What you have to do, ... | No, as that is a UNC Path, which is a windowsism.
Are you trying to access a windows share from unix? Then have a look at [jcifs](http://jcifs.samba.org/). |
3,103,982 | This Java code lists files in a directory on a Windows shared drive. Will it work correctly on a Unix system?
```
File directory = new File("\\\\server/Shared/stuff/mystuff");
for (File file: directory.listFiles()) {
System.out.println(file);
}
``` | 2010/06/23 | [
"https://Stackoverflow.com/questions/3103982",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/374479/"
] | Short answer: No.
Long answer: Do you have samba installed? Even then you need to mount the the share. So it probably won't work.
**EDIT**
Java delegates the call to the underlying OS eventually. Since Unix doesn't know what the `\\SERVERNAME` path means, Java doesn't know what it means either. What you have to do, ... | On my system (Debian Sid with Gnome 2.30 Desktop) I have to select "smb:///server/Shared/..." to achieve the same behaviour. I think, that GVFS (Gnome Virtual File System) using smbfs drivers handles the real connection in the background... |
3,103,982 | This Java code lists files in a directory on a Windows shared drive. Will it work correctly on a Unix system?
```
File directory = new File("\\\\server/Shared/stuff/mystuff");
for (File file: directory.listFiles()) {
System.out.println(file);
}
``` | 2010/06/23 | [
"https://Stackoverflow.com/questions/3103982",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/374479/"
] | Short answer: No.
Long answer: Do you have samba installed? Even then you need to mount the the share. So it probably won't work.
**EDIT**
Java delegates the call to the underlying OS eventually. Since Unix doesn't know what the `\\SERVERNAME` path means, Java doesn't know what it means either. What you have to do, ... | No...
Just let the user select the right path and use an OS dependent file-selection dialog. |
3,103,982 | This Java code lists files in a directory on a Windows shared drive. Will it work correctly on a Unix system?
```
File directory = new File("\\\\server/Shared/stuff/mystuff");
for (File file: directory.listFiles()) {
System.out.println(file);
}
``` | 2010/06/23 | [
"https://Stackoverflow.com/questions/3103982",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/374479/"
] | Short answer: No.
Long answer: Do you have samba installed? Even then you need to mount the the share. So it probably won't work.
**EDIT**
Java delegates the call to the underlying OS eventually. Since Unix doesn't know what the `\\SERVERNAME` path means, Java doesn't know what it means either. What you have to do, ... | The counter question I get when seeing this is: "Why would you want to hard-code a path in your application?"
Even if it was just for the example and you intend to load the path from a property file or anything, I still think you are on the wrong track here.
First of all you will want to avoid absolute paths like th... |
3,103,982 | This Java code lists files in a directory on a Windows shared drive. Will it work correctly on a Unix system?
```
File directory = new File("\\\\server/Shared/stuff/mystuff");
for (File file: directory.listFiles()) {
System.out.println(file);
}
``` | 2010/06/23 | [
"https://Stackoverflow.com/questions/3103982",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/374479/"
] | On my system (Debian Sid with Gnome 2.30 Desktop) I have to select "smb:///server/Shared/..." to achieve the same behaviour. I think, that GVFS (Gnome Virtual File System) using smbfs drivers handles the real connection in the background... | No, as that is a UNC Path, which is a windowsism.
Are you trying to access a windows share from unix? Then have a look at [jcifs](http://jcifs.samba.org/). |
3,103,982 | This Java code lists files in a directory on a Windows shared drive. Will it work correctly on a Unix system?
```
File directory = new File("\\\\server/Shared/stuff/mystuff");
for (File file: directory.listFiles()) {
System.out.println(file);
}
``` | 2010/06/23 | [
"https://Stackoverflow.com/questions/3103982",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/374479/"
] | No...
Just let the user select the right path and use an OS dependent file-selection dialog. | No, as that is a UNC Path, which is a windowsism.
Are you trying to access a windows share from unix? Then have a look at [jcifs](http://jcifs.samba.org/). |
3,103,982 | This Java code lists files in a directory on a Windows shared drive. Will it work correctly on a Unix system?
```
File directory = new File("\\\\server/Shared/stuff/mystuff");
for (File file: directory.listFiles()) {
System.out.println(file);
}
``` | 2010/06/23 | [
"https://Stackoverflow.com/questions/3103982",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/374479/"
] | On my system (Debian Sid with Gnome 2.30 Desktop) I have to select "smb:///server/Shared/..." to achieve the same behaviour. I think, that GVFS (Gnome Virtual File System) using smbfs drivers handles the real connection in the background... | The counter question I get when seeing this is: "Why would you want to hard-code a path in your application?"
Even if it was just for the example and you intend to load the path from a property file or anything, I still think you are on the wrong track here.
First of all you will want to avoid absolute paths like th... |
3,103,982 | This Java code lists files in a directory on a Windows shared drive. Will it work correctly on a Unix system?
```
File directory = new File("\\\\server/Shared/stuff/mystuff");
for (File file: directory.listFiles()) {
System.out.println(file);
}
``` | 2010/06/23 | [
"https://Stackoverflow.com/questions/3103982",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/374479/"
] | No...
Just let the user select the right path and use an OS dependent file-selection dialog. | The counter question I get when seeing this is: "Why would you want to hard-code a path in your application?"
Even if it was just for the example and you intend to load the path from a property file or anything, I still think you are on the wrong track here.
First of all you will want to avoid absolute paths like th... |
450,464 | I'm writing in C# the next generation of an old app originally written in Delphi. I often have to look in the old code and wondered if there's anyway to install Pascal syntax highlighting in the Visual Studio 2008 editor.
TIA. | 2009/01/16 | [
"https://Stackoverflow.com/questions/450464",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12379/"
] | Why don't you accept IDbConnection instead of connectionstring to your ctor? | Maybe...
```
class SmartDbConnection<T> where T : IDbConnection, new()
{
private readonly IDbConnection Connection;
public SmartDbConnection(string connectionString)
{
if (connectionString.Contains("MultipleActiveResultSets=true"))
{
Connection = new T();
Connection... |
450,464 | I'm writing in C# the next generation of an old app originally written in Delphi. I often have to look in the old code and wondered if there's anyway to install Pascal syntax highlighting in the Visual Studio 2008 editor.
TIA. | 2009/01/16 | [
"https://Stackoverflow.com/questions/450464",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12379/"
] | Why don't you accept IDbConnection instead of connectionstring to your ctor? | If you don't want to specify SqlConnection there, where would you specify it - and how would you know to use it only if the connection string contains "MultipleActiveResultSets=true"?
I suspect at some level you want a connection factory - either a `Func<string, IDbConnection>` you can pass in or set somewhere, or pos... |
450,464 | I'm writing in C# the next generation of an old app originally written in Delphi. I often have to look in the old code and wondered if there's anyway to install Pascal syntax highlighting in the Visual Studio 2008 editor.
TIA. | 2009/01/16 | [
"https://Stackoverflow.com/questions/450464",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12379/"
] | First - I've added `IDisposable` to this, as I believe it is important.
Second, note that providers are an alternative here:
```
class SmartDbConnection
{
private DbConnection Connection;
public SmartDbConnection(string provider, string connectionString)
{
Connection = DbProviderFactories.GetFact... | Why don't you accept IDbConnection instead of connectionstring to your ctor? |
450,464 | I'm writing in C# the next generation of an old app originally written in Delphi. I often have to look in the old code and wondered if there's anyway to install Pascal syntax highlighting in the Visual Studio 2008 editor.
TIA. | 2009/01/16 | [
"https://Stackoverflow.com/questions/450464",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12379/"
] | Why don't you accept IDbConnection instead of connectionstring to your ctor? | ```
class SmartDbConnection<T> where T: IDbConnection , new()
{
private readonly T Connection;
public SmartDbConnection(string ConnectionString)
{
if (ConnectionString.Contains("MultipleActiveResultSets=true"))
{
Connection = new T();
Connection.ConnectionString = Connection... |
450,464 | I'm writing in C# the next generation of an old app originally written in Delphi. I often have to look in the old code and wondered if there's anyway to install Pascal syntax highlighting in the Visual Studio 2008 editor.
TIA. | 2009/01/16 | [
"https://Stackoverflow.com/questions/450464",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12379/"
] | Maybe...
```
class SmartDbConnection<T> where T : IDbConnection, new()
{
private readonly IDbConnection Connection;
public SmartDbConnection(string connectionString)
{
if (connectionString.Contains("MultipleActiveResultSets=true"))
{
Connection = new T();
Connection... | If you don't want to specify SqlConnection there, where would you specify it - and how would you know to use it only if the connection string contains "MultipleActiveResultSets=true"?
I suspect at some level you want a connection factory - either a `Func<string, IDbConnection>` you can pass in or set somewhere, or pos... |
450,464 | I'm writing in C# the next generation of an old app originally written in Delphi. I often have to look in the old code and wondered if there's anyway to install Pascal syntax highlighting in the Visual Studio 2008 editor.
TIA. | 2009/01/16 | [
"https://Stackoverflow.com/questions/450464",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12379/"
] | First - I've added `IDisposable` to this, as I believe it is important.
Second, note that providers are an alternative here:
```
class SmartDbConnection
{
private DbConnection Connection;
public SmartDbConnection(string provider, string connectionString)
{
Connection = DbProviderFactories.GetFact... | Maybe...
```
class SmartDbConnection<T> where T : IDbConnection, new()
{
private readonly IDbConnection Connection;
public SmartDbConnection(string connectionString)
{
if (connectionString.Contains("MultipleActiveResultSets=true"))
{
Connection = new T();
Connection... |
450,464 | I'm writing in C# the next generation of an old app originally written in Delphi. I often have to look in the old code and wondered if there's anyway to install Pascal syntax highlighting in the Visual Studio 2008 editor.
TIA. | 2009/01/16 | [
"https://Stackoverflow.com/questions/450464",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12379/"
] | Maybe...
```
class SmartDbConnection<T> where T : IDbConnection, new()
{
private readonly IDbConnection Connection;
public SmartDbConnection(string connectionString)
{
if (connectionString.Contains("MultipleActiveResultSets=true"))
{
Connection = new T();
Connection... | ```
class SmartDbConnection<T> where T: IDbConnection , new()
{
private readonly T Connection;
public SmartDbConnection(string ConnectionString)
{
if (ConnectionString.Contains("MultipleActiveResultSets=true"))
{
Connection = new T();
Connection.ConnectionString = Connection... |
450,464 | I'm writing in C# the next generation of an old app originally written in Delphi. I often have to look in the old code and wondered if there's anyway to install Pascal syntax highlighting in the Visual Studio 2008 editor.
TIA. | 2009/01/16 | [
"https://Stackoverflow.com/questions/450464",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12379/"
] | First - I've added `IDisposable` to this, as I believe it is important.
Second, note that providers are an alternative here:
```
class SmartDbConnection
{
private DbConnection Connection;
public SmartDbConnection(string provider, string connectionString)
{
Connection = DbProviderFactories.GetFact... | If you don't want to specify SqlConnection there, where would you specify it - and how would you know to use it only if the connection string contains "MultipleActiveResultSets=true"?
I suspect at some level you want a connection factory - either a `Func<string, IDbConnection>` you can pass in or set somewhere, or pos... |
450,464 | I'm writing in C# the next generation of an old app originally written in Delphi. I often have to look in the old code and wondered if there's anyway to install Pascal syntax highlighting in the Visual Studio 2008 editor.
TIA. | 2009/01/16 | [
"https://Stackoverflow.com/questions/450464",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12379/"
] | If you don't want to specify SqlConnection there, where would you specify it - and how would you know to use it only if the connection string contains "MultipleActiveResultSets=true"?
I suspect at some level you want a connection factory - either a `Func<string, IDbConnection>` you can pass in or set somewhere, or pos... | ```
class SmartDbConnection<T> where T: IDbConnection , new()
{
private readonly T Connection;
public SmartDbConnection(string ConnectionString)
{
if (ConnectionString.Contains("MultipleActiveResultSets=true"))
{
Connection = new T();
Connection.ConnectionString = Connection... |
450,464 | I'm writing in C# the next generation of an old app originally written in Delphi. I often have to look in the old code and wondered if there's anyway to install Pascal syntax highlighting in the Visual Studio 2008 editor.
TIA. | 2009/01/16 | [
"https://Stackoverflow.com/questions/450464",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12379/"
] | First - I've added `IDisposable` to this, as I believe it is important.
Second, note that providers are an alternative here:
```
class SmartDbConnection
{
private DbConnection Connection;
public SmartDbConnection(string provider, string connectionString)
{
Connection = DbProviderFactories.GetFact... | ```
class SmartDbConnection<T> where T: IDbConnection , new()
{
private readonly T Connection;
public SmartDbConnection(string ConnectionString)
{
if (ConnectionString.Contains("MultipleActiveResultSets=true"))
{
Connection = new T();
Connection.ConnectionString = Connection... |
2,943,735 | I'm trying to read first row from the `file`
```
> source ./rank file
```
using this script
```
set line = ($<) <- inside rank
```
but when I enter
`echo $line` I receive nothing, how can I change it? thanks in advance | 2010/05/31 | [
"https://Stackoverflow.com/questions/2943735",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/348275/"
] | Since csh is brain-dead, you'll have to do something like this:
```
set line = `head -n 1 filename`
``` | It's built-in in Bash as:
```
read -r line < filename
``` |
2,943,735 | I'm trying to read first row from the `file`
```
> source ./rank file
```
using this script
```
set line = ($<) <- inside rank
```
but when I enter
`echo $line` I receive nothing, how can I change it? thanks in advance | 2010/05/31 | [
"https://Stackoverflow.com/questions/2943735",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/348275/"
] | Since csh is brain-dead, you'll have to do something like this:
```
set line = `head -n 1 filename`
``` | ```
set line = `cat file | sed 1q`
``` |
1,728,477 | I though it'll be interesting to look at threads and queues, so I've written 2 scripts, one will break a file up and encrypt each chunk in a thread, the other will do it serially. I'm still very new to python and don't really know why the treading script takes so much longer.
Threaded Script:
```
#!/usr/bin/env pyth... | 2009/11/13 | [
"https://Stackoverflow.com/questions/1728477",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/200822/"
] | 1. It seems like your second version only reads one chunk, while the first version reads the whole file - this would explain the big speedup. **Edit**: Another issue: I just noticed that you run `for lines in data` for no reason - this would actually encrypt the characters individually, which is much slower. Instead, j... | Threads are not a magical way to speed up programs - splitting work into threads will usually slow it down unless the program is spending a significant part of its time waiting for I/O. Each new thread adds more overhead to the code in splitting the work up, and more overhead in the OS in switching between threads.
In... |
1,728,477 | I though it'll be interesting to look at threads and queues, so I've written 2 scripts, one will break a file up and encrypt each chunk in a thread, the other will do it serially. I'm still very new to python and don't really know why the treading script takes so much longer.
Threaded Script:
```
#!/usr/bin/env pyth... | 2009/11/13 | [
"https://Stackoverflow.com/questions/1728477",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/200822/"
] | Threads are not a magical way to speed up programs - splitting work into threads will usually slow it down unless the program is spending a significant part of its time waiting for I/O. Each new thread adds more overhead to the code in splitting the work up, and more overhead in the OS in switching between threads.
In... | Threads have a couple different uses:
1. They only provide speedup if they allow you to get multiple pieces of hardware working at the same time on your problem, whether that hardware is CPU cores or disk heads.
2. They allow you to keep track of multiple sequences of I/O events that would be much more complicated wit... |
1,728,477 | I though it'll be interesting to look at threads and queues, so I've written 2 scripts, one will break a file up and encrypt each chunk in a thread, the other will do it serially. I'm still very new to python and don't really know why the treading script takes so much longer.
Threaded Script:
```
#!/usr/bin/env pyth... | 2009/11/13 | [
"https://Stackoverflow.com/questions/1728477",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/200822/"
] | Threads are not a magical way to speed up programs - splitting work into threads will usually slow it down unless the program is spending a significant part of its time waiting for I/O. Each new thread adds more overhead to the code in splitting the work up, and more overhead in the OS in switching between threads.
In... | Just a quick note to update this thread: python 3.2 has a new implementation of the GIL which relieves a lot of the overheads associated with multithreading, but does not eliminate the locking. (i.e. it does not allow you to use more than one core, but it allows you to use multiple threads on that core efficiently). |
End of preview. Expand in Data Studio
YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
StackExchange Paired 500K is a subset of lvwerra/stack-exchange-paired
which is a processed version of the HuggingFaceH4/stack-exchange-preferences. The following steps were applied: Parse HTML to Markdown with markdownify Create pairs (response_j, response_k) where j was rated better than k Sample at most 10 pairs per question Shuffle the dataset globally
This dataset is designed to be used for preference learning.
license: mit
- Downloads last month
- 2