All Questions
24,193,041
questions
3700
votes
19
answers
2.7m
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?
3696
votes
32
answers
2.6m
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 ...
3683
votes
11
answers
1.2m
views
What does the explicit keyword mean?
What does the explicit keyword mean in C++?
3672
votes
63
answers
1.8m
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" }
... ...
3652
votes
39
answers
1.2m
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 ...
3625
votes
30
answers
669k
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?
3620
votes
34
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 ...
3618
votes
22
answers
1.5m
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 ...
3602
votes
30
answers
2.3m
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 ...
3594
votes
48
answers
2.8m
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 ...
3586
votes
10
answers
6.9m
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
3561
votes
30
answers
3.2m
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. ...
3553
votes
78
answers
1.1m
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 ...
3551
votes
31
answers
5.1m
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?
3550
votes
20
answers
5.4m
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.
3545
votes
108
answers
3.4m
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....
3541
votes
18
answers
6.5m
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
3533
votes
24
answers
3.4m
views
Echo newline in Bash prints literal \n
How do I print a newline? This merely prints \n:
$ echo -e "Hello,\nWorld!"
Hello,\nWorld!
3528
votes
71
answers
6.7m
views
How do I format a date in JavaScript?
How do I format a Javascript Date object as a string? (Preferably in the format: 10-Aug-2010)
3511
votes
30
answers
6.8m
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
3501
votes
13
answers
2.2m
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 ...
3484
votes
25
answers
823k
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. ...
3483
votes
17
answers
3.5m
views
How do I copy a folder or file from remote to local using scp?
How do I copy a folder or file 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 ...
3482
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 ...
3473
votes
43
answers
2.4m
views
How to 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
3465
votes
21
answers
8.4m
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?
3461
votes
32
answers
1.9m
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.
3460
votes
12
answers
2.2m
views
Difference between "git add -A" and "git add ."
What is the difference between git add [--all | -A] and git add .?
3448
votes
32
answers
1.3m
views
Case insensitive 'Contains(string)'
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 ...
3443
votes
26
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 ...
3438
votes
34
answers
272k
views
The Mutable Default Argument in Python
Anyone tinkering with Python long enough has been bitten (or torn to pieces) by the following issue:
def foo(a=[]):
a.append(5)
return a
Python novices would expect this function called with ...
3428
votes
34
answers
3.5m
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?
3427
votes
45
answers
2.6m
views
From inside of a Docker container, how do I connect to the localhost of the machine?
I have a Nginx 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 device.
Is ...
3424
votes
18
answers
3.7m
views
How can I delete a file or folder in Python?
How can I delete a file or folder in Python?
3421
votes
30
answers
785k
views
AngularJS: Service vs provider vs factory
What are the differences between a Service, Provider and Factory in AngularJS?
3419
votes
46
answers
2.6m
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 ...
3413
votes
34
answers
5.4m
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 ...
3406
votes
41
answers
1.2m
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 ...
3402
votes
28
answers
1.4m
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 ...
3382
votes
35
answers
1.4m
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?
3381
votes
12
answers
502k
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 ...
3374
votes
15
answers
2.4m
views
What does cherry-picking a commit with Git mean?
What does git cherry-pick <commit> do?
3361
votes
84
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 ...
3358
votes
36
answers
3.9m
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");
...
3343
votes
34
answers
5.6m
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?
3332
votes
51
answers
2.1m
views
How can I check if an object is an array? [duplicate]
I'm trying to write a function that either accepts a list of strings, or a single string. If it's a string, then I want to convert it to an array with just the one item so I can loop over it without ...
3324
votes
16
answers
6.4m
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 ...
3321
votes
69
answers
2.0m
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 ...
3316
votes
17
answers
3.1m
views
How can I access environment variables in Python?
How can I get the value of an environment variable in Python?
3314
votes
24
answers
2.2m
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]
...