Most Popular
1500 questions
1819
votes
15 answers
When looking at most sites (including SO), most of them use:
instead of:
What are the main differences between the two, if any?
Are there valid reasons to use one instead of the other?
Are there valid…
Aron Rotteveel
- 77,970
- 17
- 103
- 128
1814
votes
39 answers
How to measure elapsed time in Python?
What I want is to start counting time somewhere in my code and then get the passed time, to measure the time it took to execute few function. I think I'm using the timeit module wrong, but the docs are just confusing for me.
import timeit
start =…
gilbert8
- 18,173
- 3
- 13
- 3
1814
votes
62 answers
Sort a Map by values
I am relatively new to Java, and often find that I need to sort a Map on the values.
Since the values are not unique, I find myself converting the keySet into an array, and sorting that array through array sort with a custom comparator…
Abe
- 2,463
- 4
- 19
- 16
1813
votes
19 answers
Proper use of the IDisposable interface
I know from reading Microsoft documentation that the "primary" use of the IDisposable interface is to clean up unmanaged resources.
To me, "unmanaged" means things like database connections, sockets, window handles, etc. But, I've seen code where…
cwick
- 25,316
- 12
- 36
- 40
1813
votes
34 answers
How can I set the default value for an HTML
I thought that adding a "value" attribute set on the
Jichao
- 38,362
- 43
- 118
- 192
1809
votes
12 answers
Meaning of @classmethod and @staticmethod for beginner?
Could someone explain to me the meaning of @classmethod and @staticmethod in python? I need to know the difference and the meaning.
As far as I understand, @classmethod tells a class that it's a method which should be inherited into subclasses,…
user1632861
1808
votes
19 answers
Why should text files end with a newline?
I assume everyone here is familiar with the adage that all text files should end with a newline. I've known of this "rule" for years but I've always wondered — why?
Will Robertson
- 59,258
- 32
- 95
- 115
1808
votes
10 answers
Getting the class name of an instance?
How do I find out a name of class that created an instance of an object in Python if the function I am doing this from is the base class of which the class of the instance has been derived?
Was thinking maybe the inspect module might have helped me…
Dan
- 32,023
- 22
- 57
- 85
1804
votes
22 answers
Why should I use a pointer rather than the object itself?
I'm coming from a Java background and have started working with objects in C++. But one thing that occurred to me is that people often use pointers to objects rather than the objects themselves, for example this declaration:
Object *myObject = new…
gEdringer
- 15,496
- 3
- 13
- 26
1803
votes
22 answers
Command to collapse all sections of code?
In Visual Studio is there a command to collapse/expand all the sections of code in a file?
Mr. Flibble
- 25,865
- 21
- 68
- 98
1800
votes
4 answers
Is there a reason for C#'s reuse of the variable in a foreach?
When using lambda expressions or anonymous methods in C#, we have to be wary of the access to modified closure pitfall. For example:
foreach (var s in strings)
{
query = query.Where(i => i.Prop == s); // access to modified closure
...
}
Due…
StriplingWarrior
- 142,651
- 26
- 235
- 300
1798
votes
11 answers
How to send a header using a HTTP request through a cURL call?
I wish to send a header to my Apache server on a Linux box. How can I achieve this via a cURL call?
gagneet
- 33,361
- 29
- 75
- 102
1794
votes
17 answers
Who is listening on a given TCP port on Mac OS X?
On Linux, I can use netstat -pntl | grep $PORT or fuser -n tcp $PORT to find out which process (PID) is listening on the specified TCP port. How do I get the same information on Mac OS X?
pts
- 71,941
- 19
- 102
- 171
1788
votes
9 answers
How to redirect and append both standard output and standard error to a file with Bash
To redirect standard output to a truncated file in Bash, I know to use:
cmd > file.txt
To redirect standard output in Bash, appending to a file, I know to use:
cmd >> file.txt
To redirect both standard output and standard error to a truncated…
flybywire
- 247,088
- 187
- 391
- 495
1788
votes
45 answers
Remove tracking branches no longer on remote
Is there a simple way to delete all tracking branches whose remote equivalent no longer exists?
Example:
Branches (local and remote)
master
origin/master
origin/bug-fix-a
origin/bug-fix-b
origin/bug-fix-c
Locally, I only have a master branch. Now…
Mailo Světel
- 20,734
- 5
- 28
- 40