Highest scored questions
24,189,473 questions
3751
votes
63
answers
1.9m
views
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" }
... ...
3744
votes
26
answers
3.1m
views
How do I create a remote Git branch?
I created a local branch. How do I push it to the remote server?
3735
votes
33
answers
2.7m
views
What is the difference between public, protected, package-private and private in Java?
In Java, are there clear rules on when to use each of access modifiers, namely the default (package private), public, protected and private, while making class and interface and dealing with ...
3724
votes
19
answers
2.8m
views
Set cellpadding and cellspacing in CSS?
In an HTML table, the cellpadding and cellspacing can be set like this:
<table cellspacing="1" cellpadding="1">
How can the same be accomplished using CSS?
3703
votes
30
answers
722k
views
Commit only part of a file's changes in Git
When I make changes to a file in Git, how can I commit only some of the changes?
For example, how could I commit only 15 lines out of 30 lines that have been changed in a file?
3687
votes
40
answers
1.3m
views
What is dependency injection?
There have been several questions already posted with specific questions about dependency injection, such as when to use it and what frameworks are there for it. However,
What is dependency injection ...
3684
votes
30
answers
2.4m
views
How do I list all the files in a commit?
How can I print a plain list of all files that were part of a given commit?
Although the following lists the files, it also includes unwanted diff information for each:
git show ...
3678
votes
22
answers
1.7m
views
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 ...
3671
votes
14
answers
2.6m
views
How do you push a tag to a remote repository using Git?
I added a tag to the master branch on my machine:
git tag mytag master
How do I push this to the remote repository? Running git push gives the message:
Everything up-to-date
However, the remote ...
3661
votes
22
answers
3.7m
views
Echo newline in Bash prints literal \n
How do I print a newline? This merely prints \n:
echo -e "Hello,\nWorld!"
Output:
Hello,\nWorld!
3653
votes
30
answers
3.4m
views
How to check if a string contains a substring in Bash
I have a string in Bash:
string="My string"
How can I test if it contains another string?
if [ $string ?? 'foo' ]; then
echo "It's there!"
fi
Where ?? is my unknown operator. ...
3646
votes
35
answers
1.4m
views
When to use LinkedList over ArrayList in Java?
I've always been one to simply use:
List<String> names = new ArrayList<>();
I use the interface as the type name for portability, so that when I ask questions such as this, I can rework ...
3627
votes
20
answers
6.9m
views
How do I select rows from a DataFrame based on column values?
How can I select rows from a DataFrame based on values in some column in Pandas?
In SQL, I would use:
SELECT *
FROM table
WHERE column_name = some_value
3622
votes
48
answers
2.9m
views
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 ...
3611
votes
31
answers
5.3m
views
How to concatenate string variables in Bash
In PHP, strings are concatenated together as follows:
$foo = "Hello";
$foo .= " World";
Here, $foo becomes "Hello World".
How is this accomplished in Bash?
3611
votes
111
answers
3.6m
views
How can I convert a string to boolean in JavaScript?
Can I convert a string representing a boolean value (e.g., 'true', 'false') into an intrinsic type in JavaScript?
I have a hidden form in HTML that is updated based on a user's selection within a list....
3605
votes
72
answers
7.0m
views
How do I format a date in JavaScript?
How do I format a Javascript Date object as a string? (Preferable format: 10-Aug-2010)
3599
votes
20
answers
5.6m
views
How can I add new keys to a dictionary?
How do I add a new key to an existing dictionary? It doesn't have an .add() method.
3593
votes
17
answers
3.9m
views
How do I copy a folder from remote to local using scp? [closed]
How do I copy a folder from remote to local host using scp?
I use ssh to log in to my server.
Then, I would like to copy the remote folder foo to local /home/user/Desktop.
How do I achieve this?
3585
votes
10
answers
7.5m
views
Does Python have a string 'contains' substring method?
I'm looking for a string.contains or string.indexof method in Python.
I want to do:
if not somestring.contains("blah"):
continue
3568
votes
78
answers
1.2m
views
Why is the Android emulator so slow? How can we speed up the Android emulator?
I have got a 2.67 GHz Celeron processor, and 1.21 GB of RAM on a x86 Windows XP Professional machine.
My understanding is that the Android Emulator should start fairly quickly on such a machine, but ...
3556
votes
45
answers
2.9m
views
From inside of a Docker container, how do I connect to the localhost of the machine? [closed]
I have an Nginx instance running inside a Docker container. I have a MySQL running on the host system. I want to connect to the MySQL from within my container. MySQL is only binding to the localhost ...
3551
votes
32
answers
2.0m
views
pretty-print JSON using JavaScript
How can I display JSON in an easy-to-read (for human readers) format? I'm looking primarily for indentation and whitespace, with perhaps even colors / font-styles / etc.
3543
votes
48
answers
2.8m
views
How to add images to README.md on GitHub?
Recently I joined GitHub. I hosted some projects there.
I need to include some images in my README File. I don't know how to do that.
I searched about this, but all I got was some links which tell me ...
3541
votes
32
answers
7.0m
views
How do I convert a String to an int in Java?
How can I convert a String value to an int type?
"1234" → 1234
3533
votes
18
answers
4.0m
views
How can I delete a file or folder in Python?
How can I delete a file or folder in Python?
3519
votes
41
answers
2.4m
views
How can I assign a multiline string literal to a variable?
How do I convert this Ruby code with a multiline string into JavaScript?
text = <<"HERE"
This
Is
A
Multiline
String
HERE
3513
votes
41
answers
1.5m
views
Git is not working after macOS update ("xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools")
I updated to the latest OS, and/or restarted my computer (this happens on every major update, but this time all I did was restart my computer on 2022-09-13).
This morning I navigated to my work's ...
3505
votes
25
answers
836k
views
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?
const func = function() {
alert("Hello world!");
};
func.apply() vs. ...
3505
votes
34
answers
289k
views
"Least Astonishment" and the Mutable Default Argument
def foo(a=[]):
a.append(5)
return a
Python novices expect this function called with no parameter to always return a list with only one element: [5]. The result is different and astonishing:
&...
3495
votes
35
answers
1.6m
views
How do I make git use the editor of my choice for editing commit messages?
How do I globally configure git to use a particular editor (e.g. vim) for commit messages?
3494
votes
13
answers
2.2m
views
Difference between "git add -A" and "git add ."
What is the difference between git add [--all | -A] and git add .?
3490
votes
27
answers
1.3m
views
How to make '.Contains(string)' case insensitive
Is there a way to make the following return true?
string title = "ASTRINGTOTEST";
title.Contains("string");
There doesn't seem to be an overload that allows me to set the case ...
3488
votes
28
answers
1.5m
views
What does ** (double star/asterisk) and * (star/asterisk) do for parameters?
What do *args and **kwargs mean in these function definitions?
def foo(x, y, *args):
pass
def bar(x, y, **kwargs):
pass
See What do ** (double star/asterisk) and * (star/asterisk) mean in a ...
3478
votes
25
answers
1.2m
views
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 ...
3477
votes
16
answers
2.7m
views
What does cherry-picking a commit with Git mean?
What does git cherry-pick <commit> do?
3476
votes
34
answers
6.2m
views
How do I find out which process is listening on a TCP or UDP port on Windows? [closed]
How do I find out which process is listening on a TCP or UDP port on Windows?
3464
votes
21
answers
8.9m
views
How do I list all files of a directory?
How can I list all files of a directory in Python and add them to a list?
3457
votes
39
answers
1.3m
views
What's the problem with "using namespace std;"?
I have heard using namespace std; is wrong, and that I should use std::cout and std::cin directly instead.
Why is this? Does it risk declaring variables that share the same name as something in the ...
3455
votes
34
answers
3.6m
views
How can I change an element's class with JavaScript?
How can I change the class of an HTML element in response to an onclick or any other events using JavaScript?
3452
votes
17
answers
3.5m
views
How can I access environment variables in Python?
How can I get the value of an environment variable in Python?
3426
votes
30
answers
786k
views
AngularJS: Service vs provider vs factory
What are the differences between a Service, Provider and Factory in AngularJS?
3413
votes
34
answers
5.8m
views
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 ...
3412
votes
36
answers
4.0m
views
Initialization of an ArrayList in one line
I wanted to create a list of options for testing purposes. At first, I did this:
ArrayList<String> places = new ArrayList<String>();
places.add("Buenos Aires");
places.add("Córdoba");
...
3412
votes
13
answers
522k
views
Improve INSERT-per-second performance of SQLite
Optimizing SQLite is tricky. Bulk-insert performance of a C application can vary from 85 inserts per second to over 96,000 inserts per second!
Background: We are using SQLite as part of a desktop ...
3387
votes
85
answers
2.4m
views
How do I iterate over the words of a string?
How do I iterate over the words of a string composed of words separated by whitespace?
Note that I'm not interested in C string functions or that kind of character manipulation/access. I prefer ...
3374
votes
69
answers
2.1m
views
How can I merge properties of two JavaScript objects?
I need to be able to merge two (very simple) JavaScript objects at runtime. For example I'd like to:
var obj1 = { food: 'pizza', car: 'ford' }
var obj2 = { animal: 'dog' }
obj1.merge(obj2);
//obj1 ...
3367
votes
25
answers
2.3m
views
How do I clone a list so that it doesn't change unexpectedly after assignment?
While using new_list = my_list, any modifications to new_list changes my_list every time. Why is this, and how can I clone or copy the list to prevent it? For example:
>>> my_list = [1, 2, 3]
...
3365
votes
9
answers
6.6m
views
Why does my JavaScript code receive a "No 'Access-Control-Allow-Origin' header is present on the requested resource" error, while Postman does not?
Mod note: This question is about why XMLHttpRequest/fetch/etc. on the browser are subject to the Same Access Policy restrictions (you get errors mentioning CORB or CORS) while Postman is not. This ...
3361
votes
44
answers
2.2m
views
How do I pass a variable by reference?
I wrote this class for testing:
class PassByReference:
def __init__(self):
self.variable = 'Original'
self.change(self.variable)
print(self.variable)
def change(self, ...