Greatest Hits
24274
votes
98
answers
11.0m
views
How do I undo the most recent local commits in Git?
I accidentally committed the wrong files to Git but didn't push the commit to the server yet.
How can I undo those commits from the local repository?
The only way seems to be to copy the edits in some ...
6678
votes
54
answers
9.0m
views
How do I find all files containing specific text on Linux?
I'm trying to find a way to scan my entire Linux system for all files containing a specific string of text. Just to clarify, I'm looking for text within the file, not in the file name.
When I was ...
19181
votes
42
answers
9.9m
views
How do I delete a Git branch locally and remotely?
I want to delete a branch both locally and remotely.
Failed Attempts to Delete a Remote Branch
$ git branch -d remotes/origin/bugfix
error: branch 'remotes/origin/bugfix' not found.
$ git branch -d ...
7477
votes
41
answers
4.0m
views
What does if __name__ == "__main__": do?
What does this do?
if __name__ == "__main__":
print("Hello world!")
12009
votes
47
answers
2.9m
views
What does the "yield" keyword do?
What is the use of the yield keyword in Python? What does it do?
For example, I'm trying to understand this code1:
def _get_child_candidates(self, distance, min_dist, max_dist):
if self._leftchild ...
110
votes
14
answers
1.8m
views
Regular expression to check if password is "8 characters including 1 uppercase letter, 1 special character, alphanumeric characters"
I want a regular expression to check that
a password must be eight characters including one uppercase letter, one special character and alphanumeric characters.
And here is my validation ...
10580
votes
132
answers
9.9m
views
How can I remove a specific item from an array?
How do I remove a specific value from an array? Something like:
array.remove(value); // removes all elements with value
I have to use core JavaScript. Frameworks are not allowed.
421
votes
55
answers
1.9m
views
How to solve "Error: Apache shutdown unexpectedly"?
I've just re-installed XAMPP, and when I try to start my Apache server in the XAMPP Control Panel, I now get the following errors:
16:50:25 [Apache] Status change detected: running
16:50:26 [...
2416
votes
38
answers
8.4m
views
How to create an HTML button that acts like a link
I would like to create an HTML button that acts like a link. So, when you click the button, it redirects to a page. I would like it to be as accessible as possible.
I would also like it so there aren'...
3354
votes
47
answers
6.5m
views
How do I convert a String to an int in Java?
How can I convert a String to an int?
"1234" → 1234
1048
votes
42
answers
851k
views
Support for password authentication was removed. Please use a personal access token instead
I got this error on my console when I tried to use git pull:
remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.
remote: Please see ...
322
votes
67
answers
1.3m
views
How to solve "Error: MySQL shutdown unexpectedly"?
When I open XAMPP and click start MySQL button and it gives me an error.
I had started it just before, but now it isn't working.
12:19:12 PM [mysql] Attempting to start MySQL app...
12:19:12 PM [...
4067
votes
37
answers
4.9m
views
How do I UPDATE from a SELECT in SQL Server?
In SQL Server, it is possible to insert rows into a table with an INSERT.. SELECT statement:
INSERT INTO Table (col1, col2, col3)
SELECT col1, col2, col3
FROM other_table
WHERE sql = 'cool'
Is it ...
26381
votes
27
answers
1.7m
views
Why is processing a sorted array faster than processing an unsorted array?
Here is a piece of C++ code that shows some very peculiar behavior. For some strange reason, sorting the data (before the timed region) miraculously makes the loop almost six times faster.
#include &...
8647
votes
48
answers
6.7m
views
How do I force "git pull" to overwrite local files?
How do I force an overwrite of local files on a git pull?
The scenario is the following:
A team member is modifying the templates for a website we are working on
They are adding some images to the ...
3614
votes
121
answers
3.4m
views
Message 'src refspec master does not match any' when pushing commits in Git
I clone my repository with:
git clone ssh://xxxxx/xx.git
But after I change some files and add and commit them, I want to push them to the server:
git add xxx.php
git commit -m "TEST"
git push ...
5062
votes
27
answers
2.5m
views
What is the difference between "INNER JOIN" and "OUTER JOIN"?
Also how do LEFT JOIN, RIGHT JOIN and FULL JOIN fit in?
7414
votes
92
answers
2.4m
views
Is Java "pass-by-reference" or "pass-by-value"?
I always thought Java uses pass-by-reference.
However, I've seen a blog post that claims that Java uses pass-by-value.
I don't think I understand the distinction they're making.
What is the ...
7857
votes
40
answers
6.9m
views
How do I check out a remote Git branch?
Somebody pushed a branch called test with git push origin test to a shared repository. I can see the branch with git branch -r.
How do I check out the remote test branch? I've tried:
git checkout ...
3906
votes
70
answers
4.8m
views
How do I generate random integers within a specific range in Java?
How do I generate a random int value in a specific range?
I have tried the following, but those do not work:
Attempt 1:
randomNum = minimum + (int)(Math.random() * maximum);
Bug: randomNum can be ...
10412
votes
38
answers
4.2m
views
How do I rename a local Git branch?
I don't want to rename a remote branch, as described in Rename master branch for both local and remote Git repositories.
How can I rename a local branch which hasn't been pushed to a remote repository?...
3486
votes
29
answers
2.4m
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 ...
3025
votes
11
answers
5.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 ...
3006
votes
14
answers
4.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
3311
votes
23
answers
4.9m
views
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.
5295
votes
102
answers
4.1m
views
How can I validate an email address in JavaScript?
I'd like to check if the user input is an email address in JavaScript, before sending it to a server or attempting to send an email to it, to prevent the most basic mistyping. How could I achieve this?...
3397
votes
32
answers
5.2m
views
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 ...
2175
votes
31
answers
5.1m
views
Get selected value in dropdown list using JavaScript
How do I get the selected value from a dropdown list using JavaScript?
I tried the methods below, but they all return the selected index instead of the value:
var e = document.getElementById("...
2376
votes
29
answers
5.3m
views
How do I declare and initialize an array in Java?
How do I declare and initialize an array in Java?
13177
votes
39
answers
3.2m
views
What is the difference between 'git pull' and 'git fetch'?
What are the differences between git pull and git fetch?
702
votes
28
answers
2.1m
views
"Uncaught SyntaxError: Cannot use import statement outside a module" when importing ECMAScript 6
I'm using ArcGIS JSAPI 4.12 and wish to use Spatial Illusions to draw military symbols on a map.
When I add milsymbol.js to the script, the console returns error
Uncaught SyntaxError: Cannot use ...
2514
votes
54
answers
4.3m
views
How do I import an SQL file using the command line in MySQL?
I have a .sql file with an export from phpMyAdmin. I want to import it into a different server using the command line.
I have a Windows Server 2008 R2 installation. I placed the .sql file on the C ...
4647
votes
12
answers
2.6m
views
How do I exit the Vim editor?
I'm stuck and cannot escape. It says:
"type :quit<Enter> to quit VIM"
But when I type that it simply appears in the object body.
2946
votes
27
answers
1.1m
views
Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools)
I updated to macOS Mojave (this happens on Catalina update too, and seems to potentially occur on every major update thereafter)
This morning I navigated to my work's codebase in the Command Line on ...
1636
votes
14
answers
2.3m
views
What does "javascript:void(0)" mean?
<a href="javascript:void(0)" id="loginlink">login</a>
I've seen such hrefs many times, but I don't know what exactly that means.
1715
votes
59
answers
3.7m
views
What does "Could not find or load main class" mean?
A common problem that new Java developers experience is that their programs fail to run with the error message: Could not find or load main class ...
What does this mean, what causes it, and how ...
493
votes
36
answers
1.9m
views
'pip' is not recognized as an internal or external command
I'm running into a weird error when trying to install Django on my computer.
This is the sequence that I typed into my command line:
C:\Python34> python get-pip.py
Requirement already up-to-date: ...
2114
votes
21
answers
4.7m
views
How to change permissions for a folder and its subfolders/files in one step
I would like to change the permissions of a folder and all its subfolders and files in one step (command) in Linux.
I have already tried the below command but it works only for the mentioned folder:
...
445
votes
29
answers
388k
views
Error message "error:0308010C:digital envelope routines::unsupported"
I created the default IntelliJ IDEA React project and got this:
Error: error:0308010C:digital envelope routines::unsupported
at new Hash (node:internal/crypto/hash:67:19)
at Object.createHash (...
3627
votes
87
answers
3.5m
views
How to round to at most 2 decimal places, if necessary
I'd like to round at most two decimal places, but only if necessary.
Input:
10
1.7777777
9.1
Output:
10
1.78
9.1
How can I do this in JavaScript?
4030
votes
41
answers
5.4m
views
Finding the index of an item in a list
Given a list ["foo", "bar", "baz"] and an item in the list "bar", how do I get its index 1?
3071
votes
62
answers
5.5m
views
How do I format a date in JavaScript?
How do I format a Date object to a string?
2504
votes
44
answers
3.5m
views
PowerShell says "execution of scripts is disabled on this system."
I am trying to run a cmd file that calls a PowerShell script from cmd.exe, but I am getting this error:
Management_Install.ps1 cannot be loaded because the execution of scripts is disabled on this ...
1735
votes
25
answers
3.4m
views
Redirect from an HTML page
Is it possible to set up a basic HTML page to redirect to another page on load?
2546
votes
32
answers
4.8m
views
Renaming column names in Pandas
How do I change the column labels of a pandas DataFrame from:
['$a', '$b', '$c', '$d', '$e']
to
['a', 'b', 'c', 'd', 'e'].
1842
votes
37
answers
4.5m
views
How to split a string in Java
I have a string, "004-034556", that I want to split into two strings:
string1="004";
string2="034556";
That means the first string will contain the characters before '-', and the second string will ...
8969
votes
30
answers
1.7m
views
What and where are the stack and heap?
Programming language books explain that value types are created on the stack, and reference types are created on the heap, without explaining what these two things are. I haven't read a clear ...
5347
votes
40
answers
4.9m
views
For-each over an array in JavaScript
How can I loop through all the entries in an array using JavaScript?
4838
votes
126
answers
4.6m
views
How to horizontally center an element
How can I horizontally center a <div> within another <div> using CSS?
<div id="outer">
<div id="inner">Foo foo</div>
</div>
10471
votes
37
answers
4.3m
views
How do I undo 'git add' before commit?
I mistakenly added files to Git using the command:
git add myfile.txt
I have not yet run git commit. Is there a way to undo this, so these files won't be included in the commit?