Most Popular
1500 questions
3439
votes
60 answers
How can I pretty-print JSON in a shell script?
Is there a (Unix) shell script to format JSON in human-readable form?
Basically, I want it to transform the following:
{ "foo": "lorem", "bar": "ipsum" }
... into something like this:
{
"foo": "lorem",
"bar": "ipsum"
}
AnC
3429
votes
32 answers
How to iterate over rows in a DataFrame in Pandas
I have a DataFrame from Pandas:
import pandas as pd
inp = [{'c1':10, 'c2':100}, {'c1':11,'c2':110}, {'c1':12,'c2':120}]
df = pd.DataFrame(inp)
print df
Output:
c1 c2
0 10 100
1 11 110
2 12 120
Now I want to iterate over the rows of this…
Roman
- 112,185
- 158
- 335
- 439
3417
votes
11 answers
What does the explicit keyword mean?
What does the explicit keyword mean in C++?
Skizz
- 67,359
- 10
- 66
- 108
3416
votes
34 answers
How do I sort a dictionary by value?
I have a dictionary of values read from two fields in a database: a string field and a numeric field. The string field is unique, so that is the key of the dictionary.
I can sort on the keys, but how can I sort based on the values?
Note: I have read…
Gern Blanston
- 42,124
- 19
- 48
- 64
3382
votes
30 answers
AngularJS: Service vs provider vs factory
What are the differences between a Service, Provider and Factory in AngularJS?
Lior
- 40,128
- 12
- 36
- 40
3381
votes
27 answers
What is the difference between __str__ and __repr__?
What is the difference between __str__ and __repr__ in Python?
Casebash
- 107,788
- 83
- 240
- 344
3377
votes
45 answers
How do I loop through or enumerate a JavaScript object?
I have a JavaScript object like the following:
var p = {
"p1": "value1",
"p2": "value2",
"p3": "value3"
};
How do I loop through all of p's elements (p1, p2, p3...) and get their keys and values?
Tanmoy
- 42,038
- 14
- 43
- 54
3360
votes
47 answers
How do I convert a String to an int in Java?
How can I convert a String to an int?
"1234" → 1234
Unknown user
- 42,925
- 16
- 37
- 42
3337
votes
23 answers
Convert bytes to a string
I'm using this code to get standard output from an external program:
>>> from subprocess import *
>>> command_stdout = Popen(['ls', '-l'], stdout=PIPE).communicate()[0]
The communicate() method returns an array of bytes:
>>> command_stdout
b'total…
Tomas Sedovic
- 39,061
- 9
- 37
- 30
3335
votes
24 answers
What is the difference between call and apply?
What is the difference between using Function.prototype.apply() and Function.prototype.call() to invoke a function?
var func = function() {
alert('hello!');
};
func.apply(); vs func.call();
Are there performance differences between the two…
John Duff
- 36,850
- 5
- 32
- 45
3330
votes
20 answers
403 Forbidden vs 401 Unauthorized HTTP responses
For a web page that exists, but for which a user does not have sufficient privileges (they are not logged in or do not belong to the proper user group), what is the proper HTTP response to serve?
401 Unauthorized?
403 Forbidden?
Something else?
What…
VirtuosiMedia
- 49,626
- 21
- 91
- 139
3318
votes
21 answers
3315
votes
17 answers
How can I add new keys to a dictionary?
How do I add a key to an existing dictionary? It doesn't have an .add() method.
lfaraone
- 47,846
- 16
- 49
- 70
3292
votes
26 answers
What is a serialVersionUID and why should I use it?
Eclipse issues warnings when a serialVersionUID is missing.
The serializable class Foo does not declare a static final
serialVersionUID field of type long
What is serialVersionUID and why is it important? Please show an example where missing…
ashokgelal
- 77,504
- 26
- 70
- 83
3289
votes
28 answers
How do I list all of the files in a commit?
I am looking for a simple Git command that provides a nicely formatted list of all files that were part of the commit given by a hash (SHA-1), with no extraneous information.
I have tried:
git show a303aa90779efdd2f6b9d90693e2cbbbe4613c1d
Although…
Philip Fourie
- 103,989
- 10
- 59
- 82