qid int64 1 3.11M | question stringlengths 10 32.1k | date stringlengths 10 10 | metadata list | response_j stringlengths 0 33.7k | response_k stringlengths 3 34.7k |
|---|---|---|---|---|---|
2,714,404 | I have a VBA form (in Excel if that matters) that contains text boxes.
On three occasions, I have found myself pressing the tab key to navigate to the next control, but instead an actual TAB is being put in the text box.
The form normally acts as it should, but it does concern me that this gremlin is showing up spora... | 2010/04/26 | [
"https://Stackoverflow.com/questions/2714404",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/250385/"
] | I have also had this behaviour in my coworkers' computer for several years now, while mine works fine. I have set all the Checkboxes TabStop property to False. It seems to work fine now. | This might solve the problem:
```
Public Sub MoveFocusToNextControl(xfrmFormName As UserForm, _
xctlCurrentControl As control)
Dim xctl As control
Dim lngTab As Long, lngNewTab As Long
On Error Resume Next
' Move focus to the next control in the tab order
lngTab = xctlCurrentControl.TabIndex + 1
For Each xctl I... |
2,714,404 | I have a VBA form (in Excel if that matters) that contains text boxes.
On three occasions, I have found myself pressing the tab key to navigate to the next control, but instead an actual TAB is being put in the text box.
The form normally acts as it should, but it does concern me that this gremlin is showing up spora... | 2010/04/26 | [
"https://Stackoverflow.com/questions/2714404",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/250385/"
] | As a quick work-around, use this code in the control's Exit event.
```
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox1.Text = VBA.Replace(TextBox1.Text, VBA.Chr(9), "")
End Sub
``` | This might solve the problem:
```
Public Sub MoveFocusToNextControl(xfrmFormName As UserForm, _
xctlCurrentControl As control)
Dim xctl As control
Dim lngTab As Long, lngNewTab As Long
On Error Resume Next
' Move focus to the next control in the tab order
lngTab = xctlCurrentControl.TabIndex + 1
For Each xctl I... |
2,714,404 | I have a VBA form (in Excel if that matters) that contains text boxes.
On three occasions, I have found myself pressing the tab key to navigate to the next control, but instead an actual TAB is being put in the text box.
The form normally acts as it should, but it does concern me that this gremlin is showing up spora... | 2010/04/26 | [
"https://Stackoverflow.com/questions/2714404",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/250385/"
] | I was able to reproduce the problem 100% of the time by launching Excel, immediately pulling up the form, and holding down the tab key.
If I change any code at all in the form and resave the workbook, the problem goes away. I'm going to chalk this up to a fluke compilation error within VBA. | Set the `TabKeyBehavior` property to `False` to get "Tab jumps to next field" behavior. |
2,714,404 | I have a VBA form (in Excel if that matters) that contains text boxes.
On three occasions, I have found myself pressing the tab key to navigate to the next control, but instead an actual TAB is being put in the text box.
The form normally acts as it should, but it does concern me that this gremlin is showing up spora... | 2010/04/26 | [
"https://Stackoverflow.com/questions/2714404",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/250385/"
] | As a quick work-around, use this code in the control's Exit event.
```
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox1.Text = VBA.Replace(TextBox1.Text, VBA.Chr(9), "")
End Sub
``` | Set the `TabKeyBehavior` property to `False` to get "Tab jumps to next field" behavior. |
2,714,404 | I have a VBA form (in Excel if that matters) that contains text boxes.
On three occasions, I have found myself pressing the tab key to navigate to the next control, but instead an actual TAB is being put in the text box.
The form normally acts as it should, but it does concern me that this gremlin is showing up spora... | 2010/04/26 | [
"https://Stackoverflow.com/questions/2714404",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/250385/"
] | I was able to reproduce the problem 100% of the time by launching Excel, immediately pulling up the form, and holding down the tab key.
If I change any code at all in the form and resave the workbook, the problem goes away. I'm going to chalk this up to a fluke compilation error within VBA. | As a quick work-around, use this code in the control's Exit event.
```
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox1.Text = VBA.Replace(TextBox1.Text, VBA.Chr(9), "")
End Sub
``` |
2,714,404 | I have a VBA form (in Excel if that matters) that contains text boxes.
On three occasions, I have found myself pressing the tab key to navigate to the next control, but instead an actual TAB is being put in the text box.
The form normally acts as it should, but it does concern me that this gremlin is showing up spora... | 2010/04/26 | [
"https://Stackoverflow.com/questions/2714404",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/250385/"
] | I was able to reproduce the problem 100% of the time by launching Excel, immediately pulling up the form, and holding down the tab key.
If I change any code at all in the form and resave the workbook, the problem goes away. I'm going to chalk this up to a fluke compilation error within VBA. | I have also had this behaviour in my coworkers' computer for several years now, while mine works fine. I have set all the Checkboxes TabStop property to False. It seems to work fine now. |
2,714,404 | I have a VBA form (in Excel if that matters) that contains text boxes.
On three occasions, I have found myself pressing the tab key to navigate to the next control, but instead an actual TAB is being put in the text box.
The form normally acts as it should, but it does concern me that this gremlin is showing up spora... | 2010/04/26 | [
"https://Stackoverflow.com/questions/2714404",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/250385/"
] | I was able to reproduce the problem 100% of the time by launching Excel, immediately pulling up the form, and holding down the tab key.
If I change any code at all in the form and resave the workbook, the problem goes away. I'm going to chalk this up to a fluke compilation error within VBA. | This might solve the problem:
```
Public Sub MoveFocusToNextControl(xfrmFormName As UserForm, _
xctlCurrentControl As control)
Dim xctl As control
Dim lngTab As Long, lngNewTab As Long
On Error Resume Next
' Move focus to the next control in the tab order
lngTab = xctlCurrentControl.TabIndex + 1
For Each xctl I... |
2,714,404 | I have a VBA form (in Excel if that matters) that contains text boxes.
On three occasions, I have found myself pressing the tab key to navigate to the next control, but instead an actual TAB is being put in the text box.
The form normally acts as it should, but it does concern me that this gremlin is showing up spora... | 2010/04/26 | [
"https://Stackoverflow.com/questions/2714404",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/250385/"
] | I created a form with three text boxes. I entered characters and tabbed onto the next for some time without being able to duplicate your problem.
The only way I can get an tab into the text box is by entering Ctrl+Tab. This might be embarrassing but backspace removes it so it is not a major issue. Is it possible that ... | Set the `TabKeyBehavior` property to `False` to get "Tab jumps to next field" behavior. |
962,564 | I'm evaluating Apache CXF for a project so I wrote a small demo application to try a few things out. Following the CXF user's guide, I was able to get my application up and running pretty quickly.
One thing I wanted to test was how well CXF is able to handle a method that returns a large array of primitives. So I defi... | 2009/06/07 | [
"https://Stackoverflow.com/questions/962564",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/109412/"
] | This definitely isn't anything CXF can do anything about. It more of a JAXB issue. I believe that internally, JAXB handles all the "maxOccurs != 1" cases as a java collection, not an array. It just converts to the array as the last step of the process if it needs to. Since java collections cannot hold primitives, it wo... | You say the cliernt performance suffers as the umber of elements in the array increases. This sounds reasonable to me - more data, less performance. What were you expecting there? As long as it's a linear degredation, it's behaving OK.
As for the creation of millions of objects, a modern JVM will do this without break... |
2,430,655 | Consider the following block of code:
```
class CheckStore {
private String displayText;
private boolean state;
private String meaningfulText;
private URL url;
public CheckStore(String text, boolean state) {
this.displayText = text;
this.state = state;
}
:
:
}
```
Whe... | 2010/03/12 | [
"https://Stackoverflow.com/questions/2430655",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/157027/"
] | In Java, `null` is just a value that a reference (which is basically a restricted pointer) can have. It means that the reference refers to nothing. In this case you still consume the space for the reference. This is 4 bytes on 32-bit systems or 8 bytes on 64-bit systems. However, you're not consuming any space for the ... | I'd like to add:
1. variable of reference type will be initialized as null value.
2. null is not object. because (null instanceof Object) equals to false
3. there is only one null value in JVM. No matter how many variables refer to null.
Object s = (String)null;
Object i = (Integer)null;
System.out.println(s == i... |
2,430,655 | Consider the following block of code:
```
class CheckStore {
private String displayText;
private boolean state;
private String meaningfulText;
private URL url;
public CheckStore(String text, boolean state) {
this.displayText = text;
this.state = state;
}
:
:
}
```
Whe... | 2010/03/12 | [
"https://Stackoverflow.com/questions/2430655",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/157027/"
] | In Java, `null` is just a value that a reference (which is basically a restricted pointer) can have. It means that the reference refers to nothing. In this case you still consume the space for the reference. This is 4 bytes on 32-bit systems or 8 bytes on 64-bit systems. However, you're not consuming any space for the ... | You can use [**jol**](http://openjdk.java.net/projects/code-tools/jol/) to get the layout of that class. (However be careful, you might need a deeper understanding on the mechanics behind it, don't blindly trust the result and be aware it is just an estimate for the currently used VM (1.7.0\_76 x64 win in my case:):
I... |
2,430,655 | Consider the following block of code:
```
class CheckStore {
private String displayText;
private boolean state;
private String meaningfulText;
private URL url;
public CheckStore(String text, boolean state) {
this.displayText = text;
this.state = state;
}
:
:
}
```
Whe... | 2010/03/12 | [
"https://Stackoverflow.com/questions/2430655",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/157027/"
] | In Java, `null` is just a value that a reference (which is basically a restricted pointer) can have. It means that the reference refers to nothing. In this case you still consume the space for the reference. This is 4 bytes on 32-bit systems or 8 bytes on 64-bit systems. However, you're not consuming any space for the ... | Null means 0. There is usually one place null defined in memory. Whenever one points to it using a programming language. Everything points to same place. It means only one 4 byte memory is consumed for NULL. Then whatever points to it does not consume any more memory. Definition of NULL is language specific but definin... |
2,430,655 | Consider the following block of code:
```
class CheckStore {
private String displayText;
private boolean state;
private String meaningfulText;
private URL url;
public CheckStore(String text, boolean state) {
this.displayText = text;
this.state = state;
}
:
:
}
```
Whe... | 2010/03/12 | [
"https://Stackoverflow.com/questions/2430655",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/157027/"
] | I'd like to add:
1. variable of reference type will be initialized as null value.
2. null is not object. because (null instanceof Object) equals to false
3. there is only one null value in JVM. No matter how many variables refer to null.
Object s = (String)null;
Object i = (Integer)null;
System.out.println(s == i... | You can use [**jol**](http://openjdk.java.net/projects/code-tools/jol/) to get the layout of that class. (However be careful, you might need a deeper understanding on the mechanics behind it, don't blindly trust the result and be aware it is just an estimate for the currently used VM (1.7.0\_76 x64 win in my case:):
I... |
2,430,655 | Consider the following block of code:
```
class CheckStore {
private String displayText;
private boolean state;
private String meaningfulText;
private URL url;
public CheckStore(String text, boolean state) {
this.displayText = text;
this.state = state;
}
:
:
}
```
Whe... | 2010/03/12 | [
"https://Stackoverflow.com/questions/2430655",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/157027/"
] | I'd like to add:
1. variable of reference type will be initialized as null value.
2. null is not object. because (null instanceof Object) equals to false
3. there is only one null value in JVM. No matter how many variables refer to null.
Object s = (String)null;
Object i = (Integer)null;
System.out.println(s == i... | Null means 0. There is usually one place null defined in memory. Whenever one points to it using a programming language. Everything points to same place. It means only one 4 byte memory is consumed for NULL. Then whatever points to it does not consume any more memory. Definition of NULL is language specific but definin... |
2,675,355 | I developing an application (in C#) where objects are active under a period of time, they have from and to properties of DateTime-type. Now I want to speed up my search routine for queries like: Are there other active objects in this timeperiod/at this time.
Is there any existing temporal index I can use or can I use... | 2010/04/20 | [
"https://Stackoverflow.com/questions/2675355",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/321299/"
] | You should also take a look at the [interval tree](http://en.wikipedia.org/wiki/Interval_tree):
>
> In computer science, an interval tree
> is an ordered tree data structure to
> hold intervals. Specifically, it
> allows one to efficiently find all
> intervals that overlap with any given
> interval or point.
>
... | Why not just order your data in a list, and then use a binary search-like algorithm to limit the number of objects you consider. |
2,675,355 | I developing an application (in C#) where objects are active under a period of time, they have from and to properties of DateTime-type. Now I want to speed up my search routine for queries like: Are there other active objects in this timeperiod/at this time.
Is there any existing temporal index I can use or can I use... | 2010/04/20 | [
"https://Stackoverflow.com/questions/2675355",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/321299/"
] | Why not just order your data in a list, and then use a binary search-like algorithm to limit the number of objects you consider. | This is an interesting sorting problem, as you need to consider both the start and end date of each element. If you used a simple sorting algorithm, then you could sort by either start date or end date, but sorting by both wouldn't be very effective, as an element with an early start date could have a very late end dat... |
2,675,355 | I developing an application (in C#) where objects are active under a period of time, they have from and to properties of DateTime-type. Now I want to speed up my search routine for queries like: Are there other active objects in this timeperiod/at this time.
Is there any existing temporal index I can use or can I use... | 2010/04/20 | [
"https://Stackoverflow.com/questions/2675355",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/321299/"
] | Why not just order your data in a list, and then use a binary search-like algorithm to limit the number of objects you consider. | There is an [i4o](http://i4o.codeplex.com/) (indexes for objects) library. May be it would be useful. |
2,675,355 | I developing an application (in C#) where objects are active under a period of time, they have from and to properties of DateTime-type. Now I want to speed up my search routine for queries like: Are there other active objects in this timeperiod/at this time.
Is there any existing temporal index I can use or can I use... | 2010/04/20 | [
"https://Stackoverflow.com/questions/2675355",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/321299/"
] | You should also take a look at the [interval tree](http://en.wikipedia.org/wiki/Interval_tree):
>
> In computer science, an interval tree
> is an ordered tree data structure to
> hold intervals. Specifically, it
> allows one to efficiently find all
> intervals that overlap with any given
> interval or point.
>
... | This is an interesting sorting problem, as you need to consider both the start and end date of each element. If you used a simple sorting algorithm, then you could sort by either start date or end date, but sorting by both wouldn't be very effective, as an element with an early start date could have a very late end dat... |
2,675,355 | I developing an application (in C#) where objects are active under a period of time, they have from and to properties of DateTime-type. Now I want to speed up my search routine for queries like: Are there other active objects in this timeperiod/at this time.
Is there any existing temporal index I can use or can I use... | 2010/04/20 | [
"https://Stackoverflow.com/questions/2675355",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/321299/"
] | You should also take a look at the [interval tree](http://en.wikipedia.org/wiki/Interval_tree):
>
> In computer science, an interval tree
> is an ordered tree data structure to
> hold intervals. Specifically, it
> allows one to efficiently find all
> intervals that overlap with any given
> interval or point.
>
... | There is an [i4o](http://i4o.codeplex.com/) (indexes for objects) library. May be it would be useful. |
2,785,624 | I have a problem with my site.I cant make the table appears on the img. It appears down of the image or up of the image. I need some help with the codes. Actually i dont want the img to reapet and to fit in users window everytime. The code to insert the img is this
```
<body oncontextmenu="return false;" background="... | 2010/05/07 | [
"https://Stackoverflow.com/questions/2785624",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/333969/"
] | if you want a background image to fit the size of the browser (which i'm guessing at, but if you have a 100% height and width on your image, that seems what you're after), you could do something like this:
```
<style type="text/css">
*{margin:0;padding:0;}
html,body{height:100%;}
.backgroundlayer { position:absolute;t... | Consider using CSS background properties.
HTML (something like this, un-tested):
```
<body ... style="background-image:url('bg_body.jpg'); background-repeat: no-repeat;">
```
If you want your background image to "resize" to the browser, you will have to hack it to work. One common way is probably to use two div tag... |
2,785,624 | I have a problem with my site.I cant make the table appears on the img. It appears down of the image or up of the image. I need some help with the codes. Actually i dont want the img to reapet and to fit in users window everytime. The code to insert the img is this
```
<body oncontextmenu="return false;" background="... | 2010/05/07 | [
"https://Stackoverflow.com/questions/2785624",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/333969/"
] | if you want a background image to fit the size of the browser (which i'm guessing at, but if you have a 100% height and width on your image, that seems what you're after), you could do something like this:
```
<style type="text/css">
*{margin:0;padding:0;}
html,body{height:100%;}
.backgroundlayer { position:absolute;t... | There is a couple things here that don't make too much sense:
"oncontextmenu="return false;" are you trying to run some sort of javascript? If so, you need to call a function before the "return false", like so:
```
<body onload="someFunction() return false;">
```
Also, I don't think you can set a background for an ... |
3,083,904 | I have had an attack on my web server where .html files were copied by FTP into a public html directory.
The FTP password was very strong.
I'm trying to determin whether PHP initiated the FTP transfer. Is there an Apache or Nix log file that can give me this information?
**Additional information**
I have FTP log ent... | 2010/06/21 | [
"https://Stackoverflow.com/questions/3083904",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/328765/"
] | You might have a malware on your workstation that runs your FTP client. The malware must steal passwords from your FTP client and send it to some third-party.
This happened to us. All our landing pages were injected with malicious code/ iframe-url code that will download this malware on all machines that opens the pag... | As far as I know, the FTP protocol does not have a User-Agent header or anything similar. Even if it had so, why would malware writers add code to actively identify their software as malware? And, why would you want to prevent legitimate use of scripting tools like PHP?
These kind of attacks normally come from two sou... |
3,083,904 | I have had an attack on my web server where .html files were copied by FTP into a public html directory.
The FTP password was very strong.
I'm trying to determin whether PHP initiated the FTP transfer. Is there an Apache or Nix log file that can give me this information?
**Additional information**
I have FTP log ent... | 2010/06/21 | [
"https://Stackoverflow.com/questions/3083904",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/328765/"
] | >
> I have had an attack on my web server where .html files were copied by FTP into a public html directory.
>
>
>
How do you know they were copied via FTP?
>
> The FTP password was very strong.
>
>
>
Not really very relevant. FTP sends passwords unencrypted - so even assuming that the files were delivered v... | As far as I know, the FTP protocol does not have a User-Agent header or anything similar. Even if it had so, why would malware writers add code to actively identify their software as malware? And, why would you want to prevent legitimate use of scripting tools like PHP?
These kind of attacks normally come from two sou... |
2,510,076 | I am *loving* ASP.NET MVC, keeping up with the releases/docs can sometimes be tricky, so maybe I'm just not getting something... I want to use a TextBoxFor(), and working with LabelFor() etc. is fine, all the magic happens for me.
But if I create...
```
<%=Html.TextBoxFor(x => x.LastName) %>
```
And wanted to do s... | 2010/03/24 | [
"https://Stackoverflow.com/questions/2510076",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/49843/"
] | I think you can do something like:
```
<%=Html.TextBoxFor(x => x.LastName, new { id = "LastName" })%>
```
[Overloads of TextBoxFor](http://msdn.microsoft.com/en-us/library/system.web.mvc.html.inputextensions.textboxfor%28VS.100%29.aspx) | As a point of interest it appears that the Html.Textbox() code will generate an id, duplicating the control name for anything that begins with a letter (a-z). If however your 'name' begins with a number it will simply not bother.
This is a fantastic 'feature' that has caused me grief for the past hour or so. |
2,510,076 | I am *loving* ASP.NET MVC, keeping up with the releases/docs can sometimes be tricky, so maybe I'm just not getting something... I want to use a TextBoxFor(), and working with LabelFor() etc. is fine, all the magic happens for me.
But if I create...
```
<%=Html.TextBoxFor(x => x.LastName) %>
```
And wanted to do s... | 2010/03/24 | [
"https://Stackoverflow.com/questions/2510076",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/49843/"
] | I think you can do something like:
```
<%=Html.TextBoxFor(x => x.LastName, new { id = "LastName" })%>
```
[Overloads of TextBoxFor](http://msdn.microsoft.com/en-us/library/system.web.mvc.html.inputextensions.textboxfor%28VS.100%29.aspx) | By default your control id is your model binding value, You can also Just use firebug. select the control and get by default control id. |
2,510,076 | I am *loving* ASP.NET MVC, keeping up with the releases/docs can sometimes be tricky, so maybe I'm just not getting something... I want to use a TextBoxFor(), and working with LabelFor() etc. is fine, all the magic happens for me.
But if I create...
```
<%=Html.TextBoxFor(x => x.LastName) %>
```
And wanted to do s... | 2010/03/24 | [
"https://Stackoverflow.com/questions/2510076",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/49843/"
] | As a point of interest it appears that the Html.Textbox() code will generate an id, duplicating the control name for anything that begins with a letter (a-z). If however your 'name' begins with a number it will simply not bother.
This is a fantastic 'feature' that has caused me grief for the past hour or so. | By default your control id is your model binding value, You can also Just use firebug. select the control and get by default control id. |
2,510,076 | I am *loving* ASP.NET MVC, keeping up with the releases/docs can sometimes be tricky, so maybe I'm just not getting something... I want to use a TextBoxFor(), and working with LabelFor() etc. is fine, all the magic happens for me.
But if I create...
```
<%=Html.TextBoxFor(x => x.LastName) %>
```
And wanted to do s... | 2010/03/24 | [
"https://Stackoverflow.com/questions/2510076",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/49843/"
] | Since MVC4 there is a built-in way to do it - [@Html.IdFor()](http://msdn.microsoft.com/en-us/library/hh833709%28v=vs.108%29.aspx).
[Here is a sample](http://www.nickriggs.com/posts/getting-the-id-and-name-attribute-generated-by-typed-html-helpers/) of using it:
```
@Html.IdFor(m => m.Filters.Occurred.From)
```
and... | As a point of interest it appears that the Html.Textbox() code will generate an id, duplicating the control name for anything that begins with a letter (a-z). If however your 'name' begins with a number it will simply not bother.
This is a fantastic 'feature' that has caused me grief for the past hour or so. |
2,510,076 | I am *loving* ASP.NET MVC, keeping up with the releases/docs can sometimes be tricky, so maybe I'm just not getting something... I want to use a TextBoxFor(), and working with LabelFor() etc. is fine, all the magic happens for me.
But if I create...
```
<%=Html.TextBoxFor(x => x.LastName) %>
```
And wanted to do s... | 2010/03/24 | [
"https://Stackoverflow.com/questions/2510076",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/49843/"
] | Since MVC4 there is a built-in way to do it - [@Html.IdFor()](http://msdn.microsoft.com/en-us/library/hh833709%28v=vs.108%29.aspx).
[Here is a sample](http://www.nickriggs.com/posts/getting-the-id-and-name-attribute-generated-by-typed-html-helpers/) of using it:
```
@Html.IdFor(m => m.Filters.Occurred.From)
```
and... | By default your control id is your model binding value, You can also Just use firebug. select the control and get by default control id. |
2,037,234 | I am calling the Google Analytics \_trackEvent() function on a web page, and get back an error from the obfuscated Google code. In Firebug, it comes back "q is undefined". In Safari developer console: "TypeError: Result of expression 'q' [undefined] is not an object."
As a test, I have reduced the page to only this c... | 2010/01/10 | [
"https://Stackoverflow.com/questions/2037234",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/213042/"
] | This problem seems to occure when the page is not fully loaded yet: <http://www.google.com/support/forum/p/Google+Analytics/thread?tid=4596554b1e9a1545&hl=en>
The provided solution is to wait for pageTracker.cb
```
function trackEvent(target, action, opt_label, opt_value) {
if(pageTracker && !pageTracker.cb) {
... | Actually the answer no. 1 is not correct. That's because pageTracker.cb never gets set (it's an obfuscated property name) with other versions of GA.
You should call upon initialization:
`pageTracker._initData()` |
2,037,234 | I am calling the Google Analytics \_trackEvent() function on a web page, and get back an error from the obfuscated Google code. In Firebug, it comes back "q is undefined". In Safari developer console: "TypeError: Result of expression 'q' [undefined] is not an object."
As a test, I have reduced the page to only this c... | 2010/01/10 | [
"https://Stackoverflow.com/questions/2037234",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/213042/"
] | This problem seems to occure when the page is not fully loaded yet: <http://www.google.com/support/forum/p/Google+Analytics/thread?tid=4596554b1e9a1545&hl=en>
The provided solution is to wait for pageTracker.cb
```
function trackEvent(target, action, opt_label, opt_value) {
if(pageTracker && !pageTracker.cb) {
... | This looks like a bug in ga.js introduced when they added `_initData()` functionality to `_trackPageview()`. Unfortunately `_initData()` isn't actually called after the conditional. Hope they fix it before they deprecate`_initData()` for good.
e.g.
This page suggests the above should work without calling `_initData()`... |
2,037,234 | I am calling the Google Analytics \_trackEvent() function on a web page, and get back an error from the obfuscated Google code. In Firebug, it comes back "q is undefined". In Safari developer console: "TypeError: Result of expression 'q' [undefined] is not an object."
As a test, I have reduced the page to only this c... | 2010/01/10 | [
"https://Stackoverflow.com/questions/2037234",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/213042/"
] | Actually the answer no. 1 is not correct. That's because pageTracker.cb never gets set (it's an obfuscated property name) with other versions of GA.
You should call upon initialization:
`pageTracker._initData()` | This looks like a bug in ga.js introduced when they added `_initData()` functionality to `_trackPageview()`. Unfortunately `_initData()` isn't actually called after the conditional. Hope they fix it before they deprecate`_initData()` for good.
e.g.
This page suggests the above should work without calling `_initData()`... |
1,044,679 | how do i count double tap in simulator? | 2009/06/25 | [
"https://Stackoverflow.com/questions/1044679",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/83905/"
] | ```
- (void) touchesBegan:(NSSet *) touches withEvent:(UIEvent *) event
{
UITouch *touch = [touches anyObject];
if (touch.tapCount == 2)
{
// do your stuff here
}
}
``` | Implement one of the touch functions defined in UIResponder (touchesBegan, touchedEnded, etc...). When you get the touches array, you can get a UITouch's tap count using code like this:
```
UITouch * t = [touches anyObject];
NSLog(@"%d", [t tapCount]);
``` |
2,215,363 | I'm writing a program, some kind of database. While I was reading manual of `fclose(3)` I found that it calls `fflush(3)` to flush `FILE*` buffers to disk (actually to OS buffer, but it doesn't matter right now, we can always call `fsync(2)`).
Because I'm writing a DB it is obvious that I want to prevent data loss. I... | 2010/02/07 | [
"https://Stackoverflow.com/questions/2215363",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/129413/"
] | fflush will only flush the the C Library internal buffers to the OS, so an fflush won't guarantee that there won't be data loss.
Calling fflush repeatedly (without intermediate fwrites) won't help, as you have already flushed the data to the OS once. The second fflush call will return SUCCESS as there is *nothing* to ... | You could fseek(3) to the end of the file (assuming you'd know the length) before doing anything. That way you'd eliminate the possibility of failure due to insufficient disk space. |
2,215,363 | I'm writing a program, some kind of database. While I was reading manual of `fclose(3)` I found that it calls `fflush(3)` to flush `FILE*` buffers to disk (actually to OS buffer, but it doesn't matter right now, we can always call `fsync(2)`).
Because I'm writing a DB it is obvious that I want to prevent data loss. I... | 2010/02/07 | [
"https://Stackoverflow.com/questions/2215363",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/129413/"
] | You could preallocate some reasonable amount of disk space. Write, flush, and fsync some binary zeros (or whatever) and then seek back to where you were. Rinse and repeat when necessary. And remember to truncate if necessary.
A bit of a pain but it should work. | You could fseek(3) to the end of the file (assuming you'd know the length) before doing anything. That way you'd eliminate the possibility of failure due to insufficient disk space. |
2,215,363 | I'm writing a program, some kind of database. While I was reading manual of `fclose(3)` I found that it calls `fflush(3)` to flush `FILE*` buffers to disk (actually to OS buffer, but it doesn't matter right now, we can always call `fsync(2)`).
Because I'm writing a DB it is obvious that I want to prevent data loss. I... | 2010/02/07 | [
"https://Stackoverflow.com/questions/2215363",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/129413/"
] | The reason the subsequent fflush() operations succeed is that there is no (new) data to write to disk. The first fflush() failed; that is tragic but history. The subsequent fflush() has nothing to do, so it does so successfully.
If you are writing to a database, you have to be careful about each write - not just deali... | You could fseek(3) to the end of the file (assuming you'd know the length) before doing anything. That way you'd eliminate the possibility of failure due to insufficient disk space. |
2,215,363 | I'm writing a program, some kind of database. While I was reading manual of `fclose(3)` I found that it calls `fflush(3)` to flush `FILE*` buffers to disk (actually to OS buffer, but it doesn't matter right now, we can always call `fsync(2)`).
Because I'm writing a DB it is obvious that I want to prevent data loss. I... | 2010/02/07 | [
"https://Stackoverflow.com/questions/2215363",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/129413/"
] | The reason the subsequent fflush() operations succeed is that there is no (new) data to write to disk. The first fflush() failed; that is tragic but history. The subsequent fflush() has nothing to do, so it does so successfully.
If you are writing to a database, you have to be careful about each write - not just deali... | fflush will only flush the the C Library internal buffers to the OS, so an fflush won't guarantee that there won't be data loss.
Calling fflush repeatedly (without intermediate fwrites) won't help, as you have already flushed the data to the OS once. The second fflush call will return SUCCESS as there is *nothing* to ... |
2,215,363 | I'm writing a program, some kind of database. While I was reading manual of `fclose(3)` I found that it calls `fflush(3)` to flush `FILE*` buffers to disk (actually to OS buffer, but it doesn't matter right now, we can always call `fsync(2)`).
Because I'm writing a DB it is obvious that I want to prevent data loss. I... | 2010/02/07 | [
"https://Stackoverflow.com/questions/2215363",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/129413/"
] | The reason the subsequent fflush() operations succeed is that there is no (new) data to write to disk. The first fflush() failed; that is tragic but history. The subsequent fflush() has nothing to do, so it does so successfully.
If you are writing to a database, you have to be careful about each write - not just deali... | You could preallocate some reasonable amount of disk space. Write, flush, and fsync some binary zeros (or whatever) and then seek back to where you were. Rinse and repeat when necessary. And remember to truncate if necessary.
A bit of a pain but it should work. |
1,181,561 | I am using Enterprise Library 4 on one of my projects for logging (and other purposes). I've noticed that there is some cost to the logging that I am doing that I can mitigate by doing the logging on a separate thread.
The way I am doing this now is that I create a LogEntry object and then I call BeginInvoke on a dele... | 2009/07/25 | [
"https://Stackoverflow.com/questions/1181561",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3957/"
] | I wrote this code a while back, feel free to use it.
```
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace MediaBrowser.Library.Logging {
public abstract class ThreadedLogger : LoggerBase {
Queue<Action> queue = new Queue<Action>();
... | An extra level of indirection may help here.
Your first async method call can put messages onto a synchonized Queue and set an event -- so the locks are happening in the thread-pool, not on your worker threads -- and then have yet another thread pulling messages off the queue when the event is raised. |
1,181,561 | I am using Enterprise Library 4 on one of my projects for logging (and other purposes). I've noticed that there is some cost to the logging that I am doing that I can mitigate by doing the logging on a separate thread.
The way I am doing this now is that I create a LogEntry object and then I call BeginInvoke on a dele... | 2009/07/25 | [
"https://Stackoverflow.com/questions/1181561",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3957/"
] | In response to Sam Safrons post, I wanted to call flush and make sure everything was really finished writting. In my case, I am writing to a database in the queue thread and all my log events were getting queued up but sometimes the application stopped before everything was finished writing which is not acceptable in m... | If what you have in mind is a SHARED queue, then I think you are going to have to synchronize the writes to it, the pushes and the pops.
But, I still think it's worth aiming at the shared queue design. In comparison to the IO of logging and probably in comparison to the other work your app is doing, the brief amount ... |
1,181,561 | I am using Enterprise Library 4 on one of my projects for logging (and other purposes). I've noticed that there is some cost to the logging that I am doing that I can mitigate by doing the logging on a separate thread.
The way I am doing this now is that I create a LogEntry object and then I call BeginInvoke on a dele... | 2009/07/25 | [
"https://Stackoverflow.com/questions/1181561",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3957/"
] | Here is what I came up with... also see Sam Saffron's answer. This answer is community wiki in case there are any problems that people see in the code and want to update.
```
/// <summary>
/// A singleton queue that manages writing log entries to the different logging sources (Enterprise Library Logging) off the execu... | Just an update:
Using enteprise library 5.0 with .NET 4.0 it can easily be done by:
```
static public void LogMessageAsync(LogEntry logEntry)
{
Task.Factory.StartNew(() => LogMessage(logEntry));
}
```
See:
<http://randypaulo.wordpress.com/2011/07/28/c-enterprise-library-asynchronous-logging/> |
1,181,561 | I am using Enterprise Library 4 on one of my projects for logging (and other purposes). I've noticed that there is some cost to the logging that I am doing that I can mitigate by doing the logging on a separate thread.
The way I am doing this now is that I create a LogEntry object and then I call BeginInvoke on a dele... | 2009/07/25 | [
"https://Stackoverflow.com/questions/1181561",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3957/"
] | I suggest to *start with measuring actual performance impact of logging* on the overall system (i.e. by running profiler) and optionally switching to something faster like [log4net](http://logging.apache.org/log4net/index.html) (I've personally migrated to it from EntLib logging a long time ago).
If this does not work... | If what you have in mind is a SHARED queue, then I think you are going to have to synchronize the writes to it, the pushes and the pops.
But, I still think it's worth aiming at the shared queue design. In comparison to the IO of logging and probably in comparison to the other work your app is doing, the brief amount ... |
1,181,561 | I am using Enterprise Library 4 on one of my projects for logging (and other purposes). I've noticed that there is some cost to the logging that I am doing that I can mitigate by doing the logging on a separate thread.
The way I am doing this now is that I create a LogEntry object and then I call BeginInvoke on a dele... | 2009/07/25 | [
"https://Stackoverflow.com/questions/1181561",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3957/"
] | I wrote this code a while back, feel free to use it.
```
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace MediaBrowser.Library.Logging {
public abstract class ThreadedLogger : LoggerBase {
Queue<Action> queue = new Queue<Action>();
... | In response to Sam Safrons post, I wanted to call flush and make sure everything was really finished writting. In my case, I am writing to a database in the queue thread and all my log events were getting queued up but sometimes the application stopped before everything was finished writing which is not acceptable in m... |
1,181,561 | I am using Enterprise Library 4 on one of my projects for logging (and other purposes). I've noticed that there is some cost to the logging that I am doing that I can mitigate by doing the logging on a separate thread.
The way I am doing this now is that I create a LogEntry object and then I call BeginInvoke on a dele... | 2009/07/25 | [
"https://Stackoverflow.com/questions/1181561",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3957/"
] | I wrote this code a while back, feel free to use it.
```
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace MediaBrowser.Library.Logging {
public abstract class ThreadedLogger : LoggerBase {
Queue<Action> queue = new Queue<Action>();
... | I wanted to say that my previous post was kind of useless. You can simply set AutoFlush to true and you will not have to loop through all the listeners. However, I still had crazy problem with parallel threads trying to flush the logger. I had to create another boolean that was set to true during the copying of the que... |
1,181,561 | I am using Enterprise Library 4 on one of my projects for logging (and other purposes). I've noticed that there is some cost to the logging that I am doing that I can mitigate by doing the logging on a separate thread.
The way I am doing this now is that I create a LogEntry object and then I call BeginInvoke on a dele... | 2009/07/25 | [
"https://Stackoverflow.com/questions/1181561",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3957/"
] | I suggest to *start with measuring actual performance impact of logging* on the overall system (i.e. by running profiler) and optionally switching to something faster like [log4net](http://logging.apache.org/log4net/index.html) (I've personally migrated to it from EntLib logging a long time ago).
If this does not work... | An extra level of indirection may help here.
Your first async method call can put messages onto a synchonized Queue and set an event -- so the locks are happening in the thread-pool, not on your worker threads -- and then have yet another thread pulling messages off the queue when the event is raised. |
1,181,561 | I am using Enterprise Library 4 on one of my projects for logging (and other purposes). I've noticed that there is some cost to the logging that I am doing that I can mitigate by doing the logging on a separate thread.
The way I am doing this now is that I create a LogEntry object and then I call BeginInvoke on a dele... | 2009/07/25 | [
"https://Stackoverflow.com/questions/1181561",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3957/"
] | Yes, you need a producer/consumer queue. I have one example of this in my threading tutorial - if you look my ["deadlocks / monitor methods"](http://pobox.com/~skeet/csharp/threads/deadlocks.shtml) page you'll find the code in the second half.
There are plenty of other examples online, of course - and .NET 4.0 will sh... | I wanted to say that my previous post was kind of useless. You can simply set AutoFlush to true and you will not have to loop through all the listeners. However, I still had crazy problem with parallel threads trying to flush the logger. I had to create another boolean that was set to true during the copying of the que... |
1,181,561 | I am using Enterprise Library 4 on one of my projects for logging (and other purposes). I've noticed that there is some cost to the logging that I am doing that I can mitigate by doing the logging on a separate thread.
The way I am doing this now is that I create a LogEntry object and then I call BeginInvoke on a dele... | 2009/07/25 | [
"https://Stackoverflow.com/questions/1181561",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3957/"
] | Yes, you need a producer/consumer queue. I have one example of this in my threading tutorial - if you look my ["deadlocks / monitor methods"](http://pobox.com/~skeet/csharp/threads/deadlocks.shtml) page you'll find the code in the second half.
There are plenty of other examples online, of course - and .NET 4.0 will sh... | If what you have in mind is a SHARED queue, then I think you are going to have to synchronize the writes to it, the pushes and the pops.
But, I still think it's worth aiming at the shared queue design. In comparison to the IO of logging and probably in comparison to the other work your app is doing, the brief amount ... |
1,181,561 | I am using Enterprise Library 4 on one of my projects for logging (and other purposes). I've noticed that there is some cost to the logging that I am doing that I can mitigate by doing the logging on a separate thread.
The way I am doing this now is that I create a LogEntry object and then I call BeginInvoke on a dele... | 2009/07/25 | [
"https://Stackoverflow.com/questions/1181561",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3957/"
] | I wanted to say that my previous post was kind of useless. You can simply set AutoFlush to true and you will not have to loop through all the listeners. However, I still had crazy problem with parallel threads trying to flush the logger. I had to create another boolean that was set to true during the copying of the que... | An extra level of indirection may help here.
Your first async method call can put messages onto a synchonized Queue and set an event -- so the locks are happening in the thread-pool, not on your worker threads -- and then have yet another thread pulling messages off the queue when the event is raised. |
2,458,446 | I am not an expert web-dev so please bear with me here.
I would like to display a banner style header for a page with the top part taken up by an image that is 275x116 and then a horizontal menu bar (styled using ul items) appearing at 70% from the top of the banner.
How would I set this up so that the banner appears... | 2010/03/16 | [
"https://Stackoverflow.com/questions/2458446",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/265838/"
] | Append these items to your existing styles:
```
#header
{
position: relative; //this will keep your absolute items inside of this container
}
#logo
{
z-index: 1;
}
.container {
z-index: 2;
position: absolute;
}
.container ul li {
float: left;
}
``` | Make the `.container` float left, position relative and move it around until it's where you need it. |
1,776,241 | I try to compile a ([LWJGL](http://en.wikipedia.org/wiki/Lightweight_Java_Game_Library)) Java project using [NetBeans](http://en.wikipedia.org/wiki/NetBeans).
I clicked on the project -> properties and under Libraries -> Compile. I added the Jars location, the source files location and javadoc location.
Still when I ... | 2009/11/21 | [
"https://Stackoverflow.com/questions/1776241",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/80932/"
] | Try to remove all libraries, "build and clean" (obviously compile give 100% errors...). Try to add all libraries, press "ok". After that wait for "scanning the projects" to finish successfully and after that retry to "build and clean". | I added the directory location of the jar files and I needed to add each jar individually. |
845,058 | How do I get a line count of a large file in the most memory- and time-efficient manner?
```
def file_len(filename):
with open(filename) as f:
for i, _ in enumerate(f):
pass
return i + 1
``` | 2009/05/10 | [
"https://Stackoverflow.com/questions/845058",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12855/"
] | I had to post this on a similar question until my reputation score jumped a bit (thanks to whoever bumped me!).
All of these solutions ignore one way to make this run considerably faster, namely by using the unbuffered (raw) interface, using bytearrays, and doing your own buffering. (This only applies in Python 3. In... | This code is shorter and clearer. It's probably the best way:
```
num_lines = open('yourfile.ext').read().count('\n')
``` |
845,058 | How do I get a line count of a large file in the most memory- and time-efficient manner?
```
def file_len(filename):
with open(filename) as f:
for i, _ in enumerate(f):
pass
return i + 1
``` | 2009/05/10 | [
"https://Stackoverflow.com/questions/845058",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12855/"
] | ```
def file_len(full_path):
""" Count number of lines in a file."""
f = open(full_path)
nr_of_lines = sum(1 for line in f)
f.close()
return nr_of_lines
``` | An alternative for big files is using [`xreadlines():`](https://python-reference.readthedocs.io/en/latest/docs/file/xreadlines.html)
```
count = 0
for line in open(thefilepath).xreadlines( ): count += 1
```
For Python 3 please see: [What substitutes xreadlines() in Python 3?](https://stackoverflow.com/questions/354... |
845,058 | How do I get a line count of a large file in the most memory- and time-efficient manner?
```
def file_len(filename):
with open(filename) as f:
for i, _ in enumerate(f):
pass
return i + 1
``` | 2009/05/10 | [
"https://Stackoverflow.com/questions/845058",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12855/"
] | I had to post this on a similar question until my reputation score jumped a bit (thanks to whoever bumped me!).
All of these solutions ignore one way to make this run considerably faster, namely by using the unbuffered (raw) interface, using bytearrays, and doing your own buffering. (This only applies in Python 3. In... | Just to complete the above methods I tried a variant with the fileinput module:
```
import fileinput as fi
def filecount(fname):
for line in fi.input(fname):
pass
return fi.lineno()
```
And passed a 60mil lines file to all the above stated methods:
```
mapcount : 6.1331050396
simpleco... |
845,058 | How do I get a line count of a large file in the most memory- and time-efficient manner?
```
def file_len(filename):
with open(filename) as f:
for i, _ in enumerate(f):
pass
return i + 1
``` | 2009/05/10 | [
"https://Stackoverflow.com/questions/845058",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12855/"
] | Here is a python program to use the multiprocessing library to distribute the line counting across machines/cores. My test improves counting a 20million line file from 26 seconds to 7 seconds using an 8 core windows 64 server. Note: not using memory mapping makes things much slower.
```
import multiprocessing, sys, ti... | If one wants to get the line count cheaply in Python in Linux, I recommend this method:
```
import os
print os.popen("wc -l file_path").readline().split()[0]
```
file\_path can be both abstract file path or relative path. Hope this may help. |
845,058 | How do I get a line count of a large file in the most memory- and time-efficient manner?
```
def file_len(filename):
with open(filename) as f:
for i, _ in enumerate(f):
pass
return i + 1
``` | 2009/05/10 | [
"https://Stackoverflow.com/questions/845058",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12855/"
] | ```
def file_len(full_path):
""" Count number of lines in a file."""
f = open(full_path)
nr_of_lines = sum(1 for line in f)
f.close()
return nr_of_lines
``` | [Kyle's answer](https://stackoverflow.com/a/1019572/2698552)
```
num_lines = sum(1 for line in open('my_file.txt'))
```
is probably best, an alternative for this is
```
num_lines = len(open('my_file.txt').read().splitlines())
```
Here is the comparision of performance of both
```
In [20]: timeit sum(1 for lin... |
845,058 | How do I get a line count of a large file in the most memory- and time-efficient manner?
```
def file_len(filename):
with open(filename) as f:
for i, _ in enumerate(f):
pass
return i + 1
``` | 2009/05/10 | [
"https://Stackoverflow.com/questions/845058",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12855/"
] | You could execute a subprocess and run `wc -l filename`
```
import subprocess
def file_len(fname):
p = subprocess.Popen(['wc', '-l', fname], stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
result, err = p.communicate()
if p.returncode != 0:
raise IOEr... | ```
def line_count(path):
count = 0
with open(path) as lines:
for count, l in enumerate(lines, start=1):
pass
return count
``` |
845,058 | How do I get a line count of a large file in the most memory- and time-efficient manner?
```
def file_len(filename):
with open(filename) as f:
for i, _ in enumerate(f):
pass
return i + 1
``` | 2009/05/10 | [
"https://Stackoverflow.com/questions/845058",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12855/"
] | the result of opening a file is an iterator, which can be converted to a sequence, which has a length:
```
with open(filename) as f:
return len(list(f))
```
this is more concise than your explicit loop, and avoids the `enumerate`. | Similarly:
```
lines = 0
with open(path) as f:
for line in f:
lines += 1
``` |
845,058 | How do I get a line count of a large file in the most memory- and time-efficient manner?
```
def file_len(filename):
with open(filename) as f:
for i, _ in enumerate(f):
pass
return i + 1
``` | 2009/05/10 | [
"https://Stackoverflow.com/questions/845058",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12855/"
] | How about this one-liner:
```
file_length = len(open('myfile.txt','r').read().split('\n'))
```
Takes 0.003 sec using this method to time it on a 3900 line file
```
def c():
import time
s = time.time()
file_length = len(open('myfile.txt','r').read().split('\n'))
print time.time() - s
``` | You can use the `os.path` module in the following way:
```
import os
import subprocess
Number_lines = int( (subprocess.Popen( 'wc -l {0}'.format( Filename ), shell=True, stdout=subprocess.PIPE).stdout).readlines()[0].split()[0] )
```
, where `Filename` is the absolute path of the file. |
845,058 | How do I get a line count of a large file in the most memory- and time-efficient manner?
```
def file_len(filename):
with open(filename) as f:
for i, _ in enumerate(f):
pass
return i + 1
``` | 2009/05/10 | [
"https://Stackoverflow.com/questions/845058",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12855/"
] | Just to complete the above methods I tried a variant with the fileinput module:
```
import fileinput as fi
def filecount(fname):
for line in fi.input(fname):
pass
return fi.lineno()
```
And passed a 60mil lines file to all the above stated methods:
```
mapcount : 6.1331050396
simpleco... | i found that you can just.
```
f = open("data.txt")
linecout = len(f.readlines())
```
will give you an answer |
845,058 | How do I get a line count of a large file in the most memory- and time-efficient manner?
```
def file_len(filename):
with open(filename) as f:
for i, _ in enumerate(f):
pass
return i + 1
``` | 2009/05/10 | [
"https://Stackoverflow.com/questions/845058",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12855/"
] | A one-line bash solution similar to [this answer](https://stackoverflow.com/a/845069/1397061), using the modern `subprocess.check_output` function:
```
def line_count(filename):
return int(subprocess.check_output(['wc', '-l', filename]).split()[0])
``` | Another possibility:
```
import subprocess
def num_lines_in_file(fpath):
return int(subprocess.check_output('wc -l %s' % fpath, shell=True).strip().split()[0])
``` |
193,095 | .NET throws an exception trying to parse a datetime string in this format:
**Fri, 10 Oct 2008 00:05:51 CST**
Convert.ToDateTime("Fri, 10 Oct 2008 00:05:51 CST") results in an exception:
>
> The string was not recognized as a
> valid DateTime. There is a unknown
> word starting at index 26
>
>
>
Character 26 ... | 2008/10/10 | [
"https://Stackoverflow.com/questions/193095",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26550/"
] | <http://msdn.microsoft.com/en-us/library/ey1cdcx8.aspx>
You need to use the overloaded DateTime.Parse to accurately parse timezones. | If a specific date and time format will be parsed across different locales, use one of the overloads of the ParseExact method and provide a format specifier. |
1,991,776 | How can I parse the following string:
Phone + 300 mins & unlimited texts - 24 month plan $25
to obtain the bracketed values, i.e.
Phone + [300] mins & [unlimited] texts - [24] month plan $[25] | 2010/01/02 | [
"https://Stackoverflow.com/questions/1991776",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/242319/"
] | Depends, if they all look like that, then:
`/Phone \+ (\w+) mins & (\w+) texts - (\d+) month plan \$(\w+)/`
That assumes that a plan may contain unlimited minutes.
You can use the regex like this:
```
str = "Phone + 300 mins & unlimited texts - 24 month plan $25"
regex = /Phone \+ (\w+) mins & (\w+) texts - (\d+)... | Match can also be abbreviated with the `=~`
so:
```
string =~ /Phone\s*\+\s*(\w*)\s*mins\s*&\s*(\w*)\s*texts\s*-\s*(\w*)\s*month\s*plan\s*\$(\w*)/
```
performs a match on the string with the regex on the right hand side.
You can also directly access the value of a group (the parts of the regex within parens) utili... |
2,013,676 | My problem is that I need to dynamically include a javascript file from another external javascript file. I'm trying to do it by using this function:
```
function addCustomScriptTag(url) {
var scriptTag=document.createElement('script');
scriptTag.type = 'text/javascript';
scriptTag.src=url;
var... | 2010/01/06 | [
"https://Stackoverflow.com/questions/2013676",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/244783/"
] | Append it to the body then. Javascript doesn't have to go exclusively in the <head> of your document. | I think it's because IE6 doesn't support `getElementsByTagName()`, try replacing it with `document.body`. |
2,013,676 | My problem is that I need to dynamically include a javascript file from another external javascript file. I'm trying to do it by using this function:
```
function addCustomScriptTag(url) {
var scriptTag=document.createElement('script');
scriptTag.type = 'text/javascript';
scriptTag.src=url;
var... | 2010/01/06 | [
"https://Stackoverflow.com/questions/2013676",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/244783/"
] | It depends when you add it to the head DOM element. Operation aborted occurs in all versions of IE because you're trying to modify a DOM element via JavaScript before that DOM element has finished loading, <http://support.microsoft.com/default.aspx/kb/927917>.
If you need this script loaded right away, you could do an... | Append it to the body then. Javascript doesn't have to go exclusively in the <head> of your document. |
2,013,676 | My problem is that I need to dynamically include a javascript file from another external javascript file. I'm trying to do it by using this function:
```
function addCustomScriptTag(url) {
var scriptTag=document.createElement('script');
scriptTag.type = 'text/javascript';
scriptTag.src=url;
var... | 2010/01/06 | [
"https://Stackoverflow.com/questions/2013676",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/244783/"
] | Consider using a library like jQuery and then just use the equivalent (if not using jQuery) of [`getScript`](http://docs.jquery.com/Ajax/jQuery.getScript). This will handle cross-browser quirks and inconsistencies for the most part. | I think it's because IE6 doesn't support `getElementsByTagName()`, try replacing it with `document.body`. |
2,013,676 | My problem is that I need to dynamically include a javascript file from another external javascript file. I'm trying to do it by using this function:
```
function addCustomScriptTag(url) {
var scriptTag=document.createElement('script');
scriptTag.type = 'text/javascript';
scriptTag.src=url;
var... | 2010/01/06 | [
"https://Stackoverflow.com/questions/2013676",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/244783/"
] | It depends when you add it to the head DOM element. Operation aborted occurs in all versions of IE because you're trying to modify a DOM element via JavaScript before that DOM element has finished loading, <http://support.microsoft.com/default.aspx/kb/927917>.
If you need this script loaded right away, you could do an... | Consider using a library like jQuery and then just use the equivalent (if not using jQuery) of [`getScript`](http://docs.jquery.com/Ajax/jQuery.getScript). This will handle cross-browser quirks and inconsistencies for the most part. |
2,013,676 | My problem is that I need to dynamically include a javascript file from another external javascript file. I'm trying to do it by using this function:
```
function addCustomScriptTag(url) {
var scriptTag=document.createElement('script');
scriptTag.type = 'text/javascript';
scriptTag.src=url;
var... | 2010/01/06 | [
"https://Stackoverflow.com/questions/2013676",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/244783/"
] | It depends when you add it to the head DOM element. Operation aborted occurs in all versions of IE because you're trying to modify a DOM element via JavaScript before that DOM element has finished loading, <http://support.microsoft.com/default.aspx/kb/927917>.
If you need this script loaded right away, you could do an... | I think it's because IE6 doesn't support `getElementsByTagName()`, try replacing it with `document.body`. |
2,013,676 | My problem is that I need to dynamically include a javascript file from another external javascript file. I'm trying to do it by using this function:
```
function addCustomScriptTag(url) {
var scriptTag=document.createElement('script');
scriptTag.type = 'text/javascript';
scriptTag.src=url;
var... | 2010/01/06 | [
"https://Stackoverflow.com/questions/2013676",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/244783/"
] | I steal from the jQuery source:
```
var head = document.getElementsByTagName("head")[0];
var script = document.createElement("script");
script.src = s.url;
// Attach handlers for all browsers
script.onload = script.onreadystatechange = function(){
if ( !done && (!this.readyState ||
this.readyState == "... | I think it's because IE6 doesn't support `getElementsByTagName()`, try replacing it with `document.body`. |
2,013,676 | My problem is that I need to dynamically include a javascript file from another external javascript file. I'm trying to do it by using this function:
```
function addCustomScriptTag(url) {
var scriptTag=document.createElement('script');
scriptTag.type = 'text/javascript';
scriptTag.src=url;
var... | 2010/01/06 | [
"https://Stackoverflow.com/questions/2013676",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/244783/"
] | It depends when you add it to the head DOM element. Operation aborted occurs in all versions of IE because you're trying to modify a DOM element via JavaScript before that DOM element has finished loading, <http://support.microsoft.com/default.aspx/kb/927917>.
If you need this script loaded right away, you could do an... | I steal from the jQuery source:
```
var head = document.getElementsByTagName("head")[0];
var script = document.createElement("script");
script.src = s.url;
// Attach handlers for all browsers
script.onload = script.onreadystatechange = function(){
if ( !done && (!this.readyState ||
this.readyState == "... |
1,344,576 | **Is it possible for there to by any type of value in `$_GET` or `$_POST` which is *not* an array or string?**
For those who read code better, is it at all possible to run this simple script on a *web server* and get it to throw the exception?
```
// crash-me.php
<?php
function must_be_array_or_string($value) {
... | 2009/08/28 | [
"https://Stackoverflow.com/questions/1344576",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28835/"
] | Except for file uploads, values are always strings or arrays. | I believe in the case of file uploads, the `'error'` and `'size'` fields would be `ints`. |
3,054,059 | EDITED FOR BETTER UNDERSTANDING
I made a custom control with propertise for some global variables.
```
private string[] LBTitles = new string[1] { "Rien" };
//...
[CategoryAttribute("WildData"), DescriptionAttribute("Tableau des noms des titres au dessus de le listbox")]
public string[] Titles
{
get { return LBTi... | 2010/06/16 | [
"https://Stackoverflow.com/questions/3054059",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/313101/"
] | It's "thread-safe" in the sense that the call to `Change` won't actually corrupt the timer.
However, it's not "thread-safe" in the sense that you definitely have a race condition (it's not possible to ensure that `timerCallback2` isn't running when you're in `DoStuff`). | Per MSDN documentation the Timer type is thread safe, so the only place you have to be careful is where you call `DoStuff();.` |
2,422,185 | As far as I can tell Adobe Air does not support persistent HTTP connections via KEEP ALIVEs.
Does anyone know any different?
Thanks | 2010/03/11 | [
"https://Stackoverflow.com/questions/2422185",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/239472/"
] | Here's basically how I ended up solving this.
While Amorya's and MHarrison's answers were valid, they had one assumption: that once created, not only the tables but each row in each table would always be the same.
The problem is that my process to pre-populate the "Animals" database, using existing data (that is upda... | The way I'm doing this is: ship a database of the static stuff as part of your app bundle. On app launch, check if there is a database file in Documents. If not, copy the one from the app bundle to Documents. Then open the database from Documents: this is the only one you read from and edit.
When an upgrade has happen... |
2,422,185 | As far as I can tell Adobe Air does not support persistent HTTP connections via KEEP ALIVEs.
Does anyone know any different?
Thanks | 2010/03/11 | [
"https://Stackoverflow.com/questions/2422185",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/239472/"
] | Here's basically how I ended up solving this.
While Amorya's and MHarrison's answers were valid, they had one assumption: that once created, not only the tables but each row in each table would always be the same.
The problem is that my process to pre-populate the "Animals" database, using existing data (that is upda... | Storing your SQLite database in the Documents directory (NSDocumentDirectory) is certainly the way to go.
In general, you should avoid application changes that modify or delete SQL tables as much as possible (adding is ok). However, when you absolutely have to make a change in an update, something like what Amorya said... |
2,614,101 | If i want to use a variable as name of the new column, is this posible in MS SQL?
Example that dont work:
```
ALTER TABLE my_table ADD @column INT
```
**This worked great for me:**
```
EXEC ('ALTER TABLE my_table ADD ' + @column + ' INT')
``` | 2010/04/10 | [
"https://Stackoverflow.com/questions/2614101",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/285447/"
] | This is possible using dynamic sql to build your DDL and using the `EXEC` command to execute the string.
```
Declare @SQL VarChar(1000)
SELECT @SQL = 'ALTER TABLE my_table ADD ' + @column + ' INT'
Exec (@SQL)
```
See [this](http://www.sqlteam.com/article/introduction-to-dynamic-sql-part-2) article.
I will also ad... | Have a look at ([EXECUTE (Transact-SQL)](http://msdn.microsoft.com/en-us/library/ms188332.aspx))
```
CREATE TABLE MyTable(
ID INT
)
GO
SELECT * FROM MyTable
GO
DECLARE @column VARCHAR(100)
SET @column = 'MyNewCol'
EXEC('ALTER TABLE MyTable ADD ' + @column + ' INT')
GO
SELECT * FROM MyTable
GO
DROP TABLE MyTabl... |
2,614,101 | If i want to use a variable as name of the new column, is this posible in MS SQL?
Example that dont work:
```
ALTER TABLE my_table ADD @column INT
```
**This worked great for me:**
```
EXEC ('ALTER TABLE my_table ADD ' + @column + ' INT')
``` | 2010/04/10 | [
"https://Stackoverflow.com/questions/2614101",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/285447/"
] | This is possible using dynamic sql to build your DDL and using the `EXEC` command to execute the string.
```
Declare @SQL VarChar(1000)
SELECT @SQL = 'ALTER TABLE my_table ADD ' + @column + ' INT'
Exec (@SQL)
```
See [this](http://www.sqlteam.com/article/introduction-to-dynamic-sql-part-2) article.
I will also ad... | ```
alter procedure sp_check_table_column
(
@field_name varchar(max),
@data_type varchar(max),
@mandatory varchar(max)
)
as
if not exists (select COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = '<table_name>' and COLUMN_NAME = @field_name)
begin
declare @sql varchar(max)
set @sql = ('ALTER ... |
2,614,101 | If i want to use a variable as name of the new column, is this posible in MS SQL?
Example that dont work:
```
ALTER TABLE my_table ADD @column INT
```
**This worked great for me:**
```
EXEC ('ALTER TABLE my_table ADD ' + @column + ' INT')
``` | 2010/04/10 | [
"https://Stackoverflow.com/questions/2614101",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/285447/"
] | Have a look at ([EXECUTE (Transact-SQL)](http://msdn.microsoft.com/en-us/library/ms188332.aspx))
```
CREATE TABLE MyTable(
ID INT
)
GO
SELECT * FROM MyTable
GO
DECLARE @column VARCHAR(100)
SET @column = 'MyNewCol'
EXEC('ALTER TABLE MyTable ADD ' + @column + ' INT')
GO
SELECT * FROM MyTable
GO
DROP TABLE MyTabl... | ```
alter procedure sp_check_table_column
(
@field_name varchar(max),
@data_type varchar(max),
@mandatory varchar(max)
)
as
if not exists (select COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = '<table_name>' and COLUMN_NAME = @field_name)
begin
declare @sql varchar(max)
set @sql = ('ALTER ... |
2,098,751 | I have encountered the following statement in fortran:
```
integer iparam(11), ipntr(14)
logical select(maxncv)
Double precision
& ax(maxn), d(maxncv,3), resid(maxn),
& v(ldv,maxncv), workd(3*maxn),
& workev(3*maxncv),
& ... | 2010/01/20 | [
"https://Stackoverflow.com/questions/2098751",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3834/"
] | "logical" is a boolean type, which takes on only the values .TRUE. or .FALSE. The declaration creates a 1D array of name "select" of length "maxncv", just as the previous declaration creates an integer 1D array "iparam" of length "11".
The layout (e.g., the continuation symbol on the start of continued lines) and the ... | logical is a datatype just like double precision is. select is a variable just like d is. maxncv is an array bound just like maxncv is. |
2,146,117 | I have compiled my own Kernel module and now I would like to be able to load it
into the GNU Debugger GDB. I did this once, a year ago or so to have a look
at the memory layout. It worked fine then, but of course I was too silly to
write down the single steps I took to accomplish this... Can anyone enlighten
me or poi... | 2010/01/27 | [
"https://Stackoverflow.com/questions/2146117",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/259964/"
] | It has been a while since I was actively developing drivers for Linux, so maybe my answer is a bit out of date. I would say you cannot use GDB. If at all, only to debug post mortem on dump files. To debug you should rather use a kernel debugger. Build the kernel with a kernel debugger enabled (there is one out-of-the b... | I suspect what you did was
```
gdb /boot/vmlinux /proc/kcore
```
Of course you can't actually do any debugging, but it's certainly good enough to have a poke around the kernel. |
2,146,117 | I have compiled my own Kernel module and now I would like to be able to load it
into the GNU Debugger GDB. I did this once, a year ago or so to have a look
at the memory layout. It worked fine then, but of course I was too silly to
write down the single steps I took to accomplish this... Can anyone enlighten
me or poi... | 2010/01/27 | [
"https://Stackoverflow.com/questions/2146117",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/259964/"
] | For kernels > 2.6.26 (i.e. after May 2008), the preferred way is probably to use "kgdb light" (not to be confused with its ancestor kgdb, available as a set of kernel patches).
"kgdb light" is now part of the kernel (in by default in current Ubuntu kernels, for instance), and it's capabilities are improving fast (Jason... | I suspect what you did was
```
gdb /boot/vmlinux /proc/kcore
```
Of course you can't actually do any debugging, but it's certainly good enough to have a poke around the kernel. |
1,388,061 | Is this the right way to do a nested navigation?
```
<dl>
<dt>Struktur</dt>
<dd>
<ul id="structure">
<li><a href="/module/structure/add">Hinzufügen</a></li>
<li><a href="/module/structure/index">Auflisten</a></li>
</ul>
</dd>
<dt>Nachrichten</dt>
<dd>
<ul id="messages">
<li><a href="/m... | 2009/09/07 | [
"https://Stackoverflow.com/questions/1388061",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/150325/"
] | I agree with n1313, it really depends what you mean by "right way".
If you do want a nit-picky answer: Strictly speaking, "Hinzufügen" and "Auflisten" are not the *definition* of "Struktur", so using a `<dl>` list to structure those elements is probably not The Right Way™. A simple nested `<ul>` list might be better.
... | semantically, i dont think using a dt tag is correct.
use a h2 or h3 tag instead.
```
<h2>Nachrichten</h2>
<ul id="messages">
<li><a href="/module/messages/add">Schreiben</a></li>
<li><a href="/module/messages/directory">Ordner</a></li>
<li><a href="/module/messages/index">Auflisten</a></li>
</ul>
```
lo... |
812,192 | I'm using pdb to debug Python programs and am unhappy with it's behaviour.
I have the screen divided into multiple emacs windows, and when I execute pdb, it (randomly?) replaces one of the windows with the output of the \*gud\* debugger.
Also, when a breakpoint is encountered, even if the debugging buffer is alread... | 2009/05/01 | [
"https://Stackoverflow.com/questions/812192",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6691/"
] | Look into [sticky windows](http://www.emacswiki.org/emacs/StickyWindows). | You should use [Sticky Windows](http://www.emacswiki.org/emacs/StickyWindows) to make your windows and buffers stick where they are but Sticky Windows won't stop gud/pdb from trying to steal your windows. When gud/pdb can't steal your source code window, it opens a new Emacs Frame even if there is another window on the... |
812,192 | I'm using pdb to debug Python programs and am unhappy with it's behaviour.
I have the screen divided into multiple emacs windows, and when I execute pdb, it (randomly?) replaces one of the windows with the output of the \*gud\* debugger.
Also, when a breakpoint is encountered, even if the debugging buffer is alread... | 2009/05/01 | [
"https://Stackoverflow.com/questions/812192",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6691/"
] | Look into [sticky windows](http://www.emacswiki.org/emacs/StickyWindows). | I tried all these approaches without success on Emacs 24.
If you are still interested I reverted to the old gdb behavior using 'gud-gdb' which implements the old behavior of gdb/emacs interaction (no dedicated-windows and no I/O buffer). If you don't want to call M-x gud-gdb when you use it, you can define an alias for... |
812,192 | I'm using pdb to debug Python programs and am unhappy with it's behaviour.
I have the screen divided into multiple emacs windows, and when I execute pdb, it (randomly?) replaces one of the windows with the output of the \*gud\* debugger.
Also, when a breakpoint is encountered, even if the debugging buffer is alread... | 2009/05/01 | [
"https://Stackoverflow.com/questions/812192",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6691/"
] | Look into [sticky windows](http://www.emacswiki.org/emacs/StickyWindows). | I have a solution that prevents the gdb from stealing windows. It works with Emacs 24.4 (2014-07-18 snapshot) and does not require dedicating buffers. The benefit over other answers is you won't have to bother dedicating and undedicating buffers whenever you change buffers, which quickly becomes tedious.
Place this ad... |
138,884 | I would like to know when I should include external scripts or write them inline with the html code, in terms of performance and ease of maintenance.
What is the general practice for this?
Real-world-scenario - I have several html pages that need client-side form validation. For this I use a jQuery plugin that I incl... | 2008/09/26 | [
"https://Stackoverflow.com/questions/138884",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21613/"
] | The only defense I can offer for inline javascipt is that when using strongly typed views with .net MVC you can refer to c# variables mid javascript which I've found useful. | Google has included load times into it's page ranking measurements, if you inline a lot, it will take longer for the spiders to crawl thru your page, this may be influence your page ranking if you have to much included. in any case different strategies may have influence on your ranking. |
138,884 | I would like to know when I should include external scripts or write them inline with the html code, in terms of performance and ease of maintenance.
What is the general practice for this?
Real-world-scenario - I have several html pages that need client-side form validation. For this I use a jQuery plugin that I incl... | 2008/09/26 | [
"https://Stackoverflow.com/questions/138884",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21613/"
] | If you only care about performance, most of advice in this thread is flat out wrong, and is becoming more and more wrong in the SPA era, where we can assume that the page is useless without the JS code. I've spent countless hours optimizing SPA page load times, and verifying these results with different browsers. Acros... | Always try to use external Js as inline js is always difficult to maintain.
Moreover, it is professionally required that you use an external js since majority of the developers recommend using js externally.
I myself use external js. |
138,884 | I would like to know when I should include external scripts or write them inline with the html code, in terms of performance and ease of maintenance.
What is the general practice for this?
Real-world-scenario - I have several html pages that need client-side form validation. For this I use a jQuery plugin that I incl... | 2008/09/26 | [
"https://Stackoverflow.com/questions/138884",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21613/"
] | Externalizing javascript is one of the yahoo performance rules:
<http://developer.yahoo.com/performance/rules.html#external>
While the hard-and-fast rule that you should always externalize scripts will generally be a good bet, in some cases you may want to inline some of the scripts and styles. You should however onl... | During early prototyping keep your code inline for the benefit of fast iteration, but be sure to make it all external by the time you reach production.
I'd even dare to say that if you can't place all your Javascript externally, then you have a bad design under your hands, and you should refactor your data and scripts |
138,884 | I would like to know when I should include external scripts or write them inline with the html code, in terms of performance and ease of maintenance.
What is the general practice for this?
Real-world-scenario - I have several html pages that need client-side form validation. For this I use a jQuery plugin that I incl... | 2008/09/26 | [
"https://Stackoverflow.com/questions/138884",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21613/"
] | Externalizing javascript is one of the yahoo performance rules:
<http://developer.yahoo.com/performance/rules.html#external>
While the hard-and-fast rule that you should always externalize scripts will generally be a good bet, in some cases you may want to inline some of the scripts and styles. You should however onl... | The only defense I can offer for inline javascipt is that when using strongly typed views with .net MVC you can refer to c# variables mid javascript which I've found useful. |
138,884 | I would like to know when I should include external scripts or write them inline with the html code, in terms of performance and ease of maintenance.
What is the general practice for this?
Real-world-scenario - I have several html pages that need client-side form validation. For this I use a jQuery plugin that I incl... | 2008/09/26 | [
"https://Stackoverflow.com/questions/138884",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21613/"
] | Another reason why you should always use external scripts is for easier transition to [Content Security Policy (CSP)](http://developer.chrome.com/extensions/contentSecurityPolicy.html). CSP defaults forbid all inline script, making your site more resistant to XSS attacks. | Three considerations:
* How much code do you need (sometimes libraries are a first-class consumer)?
* Specificity: is this code only functional in the context of this specific document or element?
* Every code inside the document tends to make it longer and thus slower. Besides that SEO considerations make it obvious,... |
138,884 | I would like to know when I should include external scripts or write them inline with the html code, in terms of performance and ease of maintenance.
What is the general practice for this?
Real-world-scenario - I have several html pages that need client-side form validation. For this I use a jQuery plugin that I incl... | 2008/09/26 | [
"https://Stackoverflow.com/questions/138884",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21613/"
] | i think the [specific to one page, short script case](http://www.thefutureoftheweb.com/blog/when-to-use-inline-javascript) is (only) defensible case for inline script | The only defense I can offer for inline javascipt is that when using strongly typed views with .net MVC you can refer to c# variables mid javascript which I've found useful. |
138,884 | I would like to know when I should include external scripts or write them inline with the html code, in terms of performance and ease of maintenance.
What is the general practice for this?
Real-world-scenario - I have several html pages that need client-side form validation. For this I use a jQuery plugin that I incl... | 2008/09/26 | [
"https://Stackoverflow.com/questions/138884",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21613/"
] | Actually, there's a pretty solid case to use inline javascript. **If the js is small enough** (one-liner), I tend to prefer the javascript inline because of two factors:
* **Locality**. There's no need to navigate an external file to validate the behaviour of some javascript
* **AJAX**. If you're refreshing some secti... | On the point of keeping JavaScript external:
ASP.NET 3.5SP1 recently introduced functionality to create a Composite script resource (merge a bunch of js files into one). Another benefit to this is when Webserver compression is turned on, downloading one slightly larger file will have a better compression ratio then ma... |
138,884 | I would like to know when I should include external scripts or write them inline with the html code, in terms of performance and ease of maintenance.
What is the general practice for this?
Real-world-scenario - I have several html pages that need client-side form validation. For this I use a jQuery plugin that I incl... | 2008/09/26 | [
"https://Stackoverflow.com/questions/138884",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21613/"
] | i think the [specific to one page, short script case](http://www.thefutureoftheweb.com/blog/when-to-use-inline-javascript) is (only) defensible case for inline script | Actually, there's a pretty solid case to use inline javascript. **If the js is small enough** (one-liner), I tend to prefer the javascript inline because of two factors:
* **Locality**. There's no need to navigate an external file to validate the behaviour of some javascript
* **AJAX**. If you're refreshing some secti... |
138,884 | I would like to know when I should include external scripts or write them inline with the html code, in terms of performance and ease of maintenance.
What is the general practice for this?
Real-world-scenario - I have several html pages that need client-side form validation. For this I use a jQuery plugin that I incl... | 2008/09/26 | [
"https://Stackoverflow.com/questions/138884",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21613/"
] | Another hidden benefit of external scripts is that you can easily run them through a syntax checker like [jslint](http://www.jslint.com/). That can save you from a lot of heartbreaking, hard-to-find, IE6 bugs. | Always try to use external Js as inline js is always difficult to maintain.
Moreover, it is professionally required that you use an external js since majority of the developers recommend using js externally.
I myself use external js. |
138,884 | I would like to know when I should include external scripts or write them inline with the html code, in terms of performance and ease of maintenance.
What is the general practice for this?
Real-world-scenario - I have several html pages that need client-side form validation. For this I use a jQuery plugin that I incl... | 2008/09/26 | [
"https://Stackoverflow.com/questions/138884",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21613/"
] | Actually, there's a pretty solid case to use inline javascript. **If the js is small enough** (one-liner), I tend to prefer the javascript inline because of two factors:
* **Locality**. There's no need to navigate an external file to validate the behaviour of some javascript
* **AJAX**. If you're refreshing some secti... | I would take a look at the required code and divide it into as many separate files as needed. Every js file would only hold one "logical set" of functions etc. eg. one file for all login related functions.
Then during site developement on each html page you only include those that are needed.
When you go live with yo... |
1,936,837 | After finding the fastest string replace algorithm in [this thread](https://stackoverflow.com/questions/1919096/mass-string-replace-in-python), I've been trying to modify one of them to suit my needs, particularly [this one](https://stackoverflow.com/questions/1919096/mass-string-replace-in-python/1919221#1919221) by g... | 2009/12/20 | [
"https://Stackoverflow.com/questions/1936837",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/117603/"
] | You could use a negative lookbehind (assuming the regex engine in question supports it) to only match ampersands that do not follow another ampersand.
```
/(?<!&)&/
``` | Maybe loop while (q = str.find('&', p)) != -1, then append the left side (p + 2 to q - 1) and the replacement value. |
1,936,837 | After finding the fastest string replace algorithm in [this thread](https://stackoverflow.com/questions/1919096/mass-string-replace-in-python), I've been trying to modify one of them to suit my needs, particularly [this one](https://stackoverflow.com/questions/1919096/mass-string-replace-in-python/1919221#1919221) by g... | 2009/12/20 | [
"https://Stackoverflow.com/questions/1936837",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/117603/"
] | You could use a negative lookbehind (assuming the regex engine in question supports it) to only match ampersands that do not follow another ampersand.
```
/(?<!&)&/
``` | I think this does the trick:
```
import re
def fix(text):
dict = {"y":"\033[0;30m",
"c":"\033[0;31m",
"b":"\033[0;32m",
"Y":"\033[0;33m",
"u":"\033[0;34m",
"&":"&"}
myparts = re.split('\&(\&*)', text)
myparts[1:]=[dict.get(x[0],"&"+x[0])+x[1:] i... |
1,936,837 | After finding the fastest string replace algorithm in [this thread](https://stackoverflow.com/questions/1919096/mass-string-replace-in-python), I've been trying to modify one of them to suit my needs, particularly [this one](https://stackoverflow.com/questions/1919096/mass-string-replace-in-python/1919221#1919221) by g... | 2009/12/20 | [
"https://Stackoverflow.com/questions/1936837",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/117603/"
] | You could use a negative lookbehind (assuming the regex engine in question supports it) to only match ampersands that do not follow another ampersand.
```
/(?<!&)&/
``` | re.sub will do what you want. It takes a regex pattern and can take a function to process the match and return the replacement. Below if the character following the & is not in the dictionary, no replacement is made. && is replaced with & to allow escaping an & that is followed by a character in the dictionary.
Also '... |
2,620,473 | I have seen many answers on stackoverflow, but I didn't find an answer that is matching mine.
Apart from all those difference, Does it make sense if we say an abstract class abstracts the implementation of behaviour while an interface abstracts the type which implements the behaviour. | 2010/04/12 | [
"https://Stackoverflow.com/questions/2620473",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/266037/"
] | The main differences from design point of view are that:
* you can declare a contract on constructor of the implementing classes, by creating a protected constructor in the base abstract class.
* you can provide implementations of methods usable by base classes
* you can make a wrapper around the contract (e.g. valida... | Not really no, because an abstract class doesn't need to implement any behaviour. It probably should, because otherwise you may argue the usefulness of it, but it doesn't *have to*. |
2,620,473 | I have seen many answers on stackoverflow, but I didn't find an answer that is matching mine.
Apart from all those difference, Does it make sense if we say an abstract class abstracts the implementation of behaviour while an interface abstracts the type which implements the behaviour. | 2010/04/12 | [
"https://Stackoverflow.com/questions/2620473",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/266037/"
] | An abstract class can (and normally does) provide some implementation.
And interface cannot provide any implementation. | Interface = pure abstract class (abstract class with no implementation) |
2,620,473 | I have seen many answers on stackoverflow, but I didn't find an answer that is matching mine.
Apart from all those difference, Does it make sense if we say an abstract class abstracts the implementation of behaviour while an interface abstracts the type which implements the behaviour. | 2010/04/12 | [
"https://Stackoverflow.com/questions/2620473",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/266037/"
] | The main differences from design point of view are that:
* you can declare a contract on constructor of the implementing classes, by creating a protected constructor in the base abstract class.
* you can provide implementations of methods usable by base classes
* you can make a wrapper around the contract (e.g. valida... | Both have specific uses as per the language design- abstract class are designed to be a base class and cannot be instantiated. wheras when u need to define just a contract (NO implementation) which each implementing class must follow in thrie own way, then u must use interfaces.Also -
Can be a base class for Inherita... |
2,620,473 | I have seen many answers on stackoverflow, but I didn't find an answer that is matching mine.
Apart from all those difference, Does it make sense if we say an abstract class abstracts the implementation of behaviour while an interface abstracts the type which implements the behaviour. | 2010/04/12 | [
"https://Stackoverflow.com/questions/2620473",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/266037/"
] | An abstract class can (and normally does) provide some implementation.
And interface cannot provide any implementation. | Both have specific uses as per the language design- abstract class are designed to be a base class and cannot be instantiated. wheras when u need to define just a contract (NO implementation) which each implementing class must follow in thrie own way, then u must use interfaces.Also -
Can be a base class for Inherita... |
2,620,473 | I have seen many answers on stackoverflow, but I didn't find an answer that is matching mine.
Apart from all those difference, Does it make sense if we say an abstract class abstracts the implementation of behaviour while an interface abstracts the type which implements the behaviour. | 2010/04/12 | [
"https://Stackoverflow.com/questions/2620473",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/266037/"
] | An abstract class can (and normally does) provide some implementation.
And interface cannot provide any implementation. | Not really no, because an abstract class doesn't need to implement any behaviour. It probably should, because otherwise you may argue the usefulness of it, but it doesn't *have to*. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.