Greatest Hits

25927 votes
105 answers
13.2m 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 do I undo those commits from the local repository?
7352 votes
56 answers
10.5m views

How to find all files containing specific text (string) on Linux?

How do I find all files containing a specific string of text within their file contents? The following doesn't work. It seems to display every single file in the system. find / -type f -exec grep -H '...
Nathan's user avatar
  • 74.4k
20305 votes
41 answers
11.1m views

How do I delete a Git branch 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 origin/bugfix error: branch 'origin/bugfix' not found....
Matthew Rankin's user avatar
498 votes
82 answers
2.0m 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 [...
Austin's user avatar
  • 5,001
8092 votes
46 answers
4.5m views

What does if __name__ == "__main__": do?

What does this do, and why should one include the if statement? if __name__ == "__main__": print("Hello, World!") If you are trying to close a question where someone should be ...
Devoted's user avatar
  • 178k
11651 votes
149 answers
12.0m views

How can I remove a specific item from an array in JavaScript?

How do I remove a specific value from an array? Something like: array.remove(value); Constraints: I have to use core JavaScript. Frameworks are not allowed.
Walker's user avatar
  • 129k
1799 votes
64 answers
2.1m 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 (...
a1cd's user avatar
  • 18.6k
12739 votes
50 answers
3.2m views

What does the "yield" keyword do in Python?

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 ...
Alex. S.'s user avatar
  • 144k
454 votes
58 answers
2.1m 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 [...
Tomas Skovgaard's user avatar
114 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 ...
Rania Umair's user avatar
  • 1,965
2647 votes
35 answers
9.5m views

How do I create an HTML button that acts like a link?

How do I create an HTML button that acts like a link? So that clicking the button redirects the user to a page. I want it to be accessible, and with minimal extra characters or parameters in the URL.
Andrew's user avatar
  • 228k
3484 votes
30 answers
6.7m views

How do I convert a String to an int in Java?

How can I convert a String to an int? "1234" → 1234
Unknown user's user avatar
  • 44.6k
4012 votes
138 answers
4.2m 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 ...
sinoohe's user avatar
  • 40.5k
27103 votes
25 answers
1.8m views

Why is processing a sorted array faster than processing an unsorted array?

In this C++ code, sorting the data (before the timed region) makes the primary loop ~6x faster: #include <algorithm> #include <ctime> #include <iostream> int main() { // ...
GManNickG's user avatar
  • 495k
4223 votes
39 answers
5.2m 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 ...
jamesmhaley's user avatar
  • 44.5k
9447 votes
53 answers
8.0m views

How do I force "git pull" to overwrite local files?

How do I force an overwrite of local files on a git pull? My local repository contains a file of the same filename as on the server. error: Untracked working tree file 'example.txt' would be ...
Jakub Troszok's user avatar
1555 votes
49 answers
1.7m views

Message "Support for password authentication was removed."

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. remote: Please see https://docs.github.com/en/get-started/...
Daemes's user avatar
  • 14.5k
3969 votes
33 answers
6.9m views

How to iterate over rows in a DataFrame in Pandas

I have a pandas dataframe, df: c1 c2 0 10 100 1 11 110 2 12 120 How do I iterate over the rows of this dataframe? For every row, I want to access its elements (values in cells) by the name ...
Roman's user avatar
  • 125k
11386 votes
39 answers
5.2m views

How can I rename a local Git branch?

How can I rename a local branch which has not yet been pushed to a remote repository? Related: Rename master branch for both local and remote Git repositories How do I rename both a Git local and ...
Forrest's user avatar
  • 123k
8489 votes
43 answers
8.2m 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 ...
Juri Glass's user avatar
  • 88.4k
1128 votes
33 answers
3.6m 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 ...
Jerry Chen's user avatar
  • 11.8k
3412 votes
17 answers
6.0m 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
szli's user avatar
  • 37.1k
5193 votes
28 answers
2.6m views

What is the difference between "INNER JOIN" and "OUTER JOIN"?

Also, how do LEFT OUTER JOIN, RIGHT OUTER JOIN, and FULL OUTER JOIN fit in?
Chris de Vries's user avatar
7736 votes
91 answers
2.6m views

Is Java "pass-by-reference" or "pass-by-value"?

I always thought Java uses pass-by-reference. However, I read a blog post which claims that Java uses pass-by-value. I don't think I understand the distinction the author is making. What is the ...
4077 votes
59 answers
5.1m 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? The following methods have bugs related to integer overflow: randomNum = minimum + (int)(Math.random() * maximum); // Bug: `randomNum` can be ...
user42155's user avatar
  • 49k
560 votes
42 answers
2.5m 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: ...
user3597950's user avatar
  • 9,291
3266 votes
15 answers
6.1m 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 ...
Mr Jedi's user avatar
  • 33.8k
5197 votes
13 answers
2.9m views

How do I exit Vim?

I am stuck and cannot escape. It says: type :quit<Enter> to quit VIM But when I type that it simply appears in the object body.
jclancy's user avatar
  • 49.8k
3658 votes
31 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 ...
intrepion's user avatar
  • 38.2k
2788 votes
52 answers
4.3m 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 ...
Conor's user avatar
  • 27.9k
2334 votes
31 answers
5.7m views

Get selected value in dropdown list using JavaScript

How do I get the selected value from a dropdown list using JavaScript? <form> <select id="ddlViewBy"> <option value="1">test1</option> <option value="2" ...
Fire Hand's user avatar
  • 25.4k
3485 votes
21 answers
5.2m 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.
lfaraone's user avatar
  • 49.6k
13689 votes
37 answers
3.4m views

What is the difference between 'git pull' and 'git fetch'?

What are the differences between git pull and git fetch?
Pablo Fernandez's user avatar
3426 votes
38 answers
1.4m 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 ...
dustbuster's user avatar
  • 80.2k
4076 votes
92 answers
4.3m 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?
stinkycheeseman's user avatar
2514 votes
31 answers
5.7m views

How do I declare and initialize an array in Java?

How do I declare and initialize an array in Java?
bestattendance's user avatar
2906 votes
36 answers
6.1m views

Renaming column names in Pandas

I want to change the column labels of a Pandas DataFrame from ['$a', '$b', '$c', '$d', '$e'] to ['a', 'b', 'c', 'd', 'e']
user1504276's user avatar
  • 29.2k
1868 votes
64 answers
4.3m 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 ...
Stephen C's user avatar
  • 700k
3445 votes
69 answers
6.5m 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)
leora's user avatar
  • 189k
1732 votes
14 answers
2.5m 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.
omg's user avatar
  • 137k
2724 votes
56 answers
4.9m 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 ...
Jaylen's user avatar
  • 39.1k
4327 votes
45 answers
6.1m 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?
Eugene M's user avatar
  • 47.6k
2 votes
1 answer
229k views

Ionic - how to prevent error "TS2339: Property XXX does not exist on type"

I'm doing a simple loop through an Array and calling a method on each element. this.scene.manager.scenes.forEach((scene) => { if(scene.refresh){ scene.refresh(); } }); This code works, but ...
anderlaini's user avatar
  • 1,593
2569 votes
33 answers
3.7m views

How can I save username and password in Git?

I want to use a push and pull automatically in Git Extensions, Sourcetree or any other Git GUI without entering my username and password in a prompt, every time. So how can I save my credentials in ...
Edson Cezar's user avatar
  • 26.1k
5560 votes
27 answers
5.9m views

Reset local repository branch to be just like remote repository HEAD

How do I reset my local branch to be just like the branch on the remote repository? I tried: git reset --hard HEAD But git status claims I have modified files: On branch master Changes to be ...
hap497's user avatar
  • 155k
1716 votes
36 answers
3.8m views

Find all tables containing column with specified name - MS SQL Server

Is it possible to query for table names which contain columns being LIKE '%myName%' ?
gruber's user avatar
  • 28.8k
11168 votes
38 answers
5.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. How do I undo this so that these changes will not be included in the commit?
oz10's user avatar
  • 154k
1912 votes
38 answers
4.8m views

How do I split a string in Java?

I want to split the string "004-034556" into two strings by the delimiter "-": part1 = "004"; part2 = "034556"; That means the first string will contain the ...
riyana's user avatar
  • 21.4k
1813 votes
24 answers
3.5m views

How to redirect one HTML page to another on load

Is it possible to set up a basic HTML page to redirect to another page on load?
chobo's user avatar
  • 31.6k
5557 votes
18 answers
5.7m views

How do I push a new local branch to a remote Git repository and track it too?

How do I: Create a local branch from another branch (via git branch or git checkout -b). Push the local branch to the remote repository (i.e. publish), but make it trackable so that git pull and git ...
Roni Yaniv's user avatar
  • 57.7k