Undo a Git merge that hasn't been pushed yet

I accidentally ran `git merge some_other_branch` on my local master branch. I haven't pushed the changes to origin master. How do I undo the merge? --- After merging, `git status` says: ``` # On br...

8 Jul at 05:11

How do I get a timestamp in JavaScript?

I want a single number that represents the current date and time, like a [Unix timestamp](https://en.wikipedia.org/wiki/Unix_time).

How do I clone all remote branches?

My `master` and `development` branches are tracked remotely on [GitHub](http://en.wikipedia.org/wiki/GitHub). How do I clone both these branches?

How do I update or sync a forked repository on GitHub?

I forked a project, made changes, and created a pull request which was accepted. New commits were later added to the repository. How do I get those commits into my fork?

Setting "checked" for a checkbox with jQuery

I'd like to do something like this to tick a `checkbox` using : ``` $(".myCheckBox").checked(true); ``` or ``` $(".myCheckBox").selected(true); ``` Does such a thing exist?

"Thinking in AngularJS" if I have a jQuery background?

Suppose I'm familiar with developing client-side applications in [jQuery](http://jquery.com/), but now I'd like to start using [AngularJS](http://angularjs.org/). Can you describe the paradigm shift t...

2 Nov at 23:22

Why does Google prepend while(1); to their JSON responses?

Why does Google prepend `while(1);` to their (private) JSON responses? For example, here's a response while turning a calendar on and off in [Google Calendar](https://calendar.google.com/calendar/abo...

3 Jan at 22:3

Which "href" value should I use for JavaScript links, "#" or "javascript:void(0)"?

The following are two methods of building a link that has the sole purpose of running JavaScript code. Which is better, in terms of functionality, page load speed, validation purposes, etc.? ``` func...

Avoiding NullPointerException in Java

I use `x != null` to avoid [NullPointerException](https://docs.oracle.com/javase/9/docs/api/java/lang/NullPointerException.html). Is there an alternative? ``` if (x != null) { // ... } ```

10 Jul at 23:18

How to enumerate an enum?

How can you enumerate an `enum` in C#? E.g. the following code does not compile: ``` public enum Suit { Spades, Hearts, Clubs, Diamonds } public void EnumerateAllSuitsDemoMethod() {...

24 Nov at 00:35

How do I check if a directory exists or not in a Bash shell script?

What command checks if a directory exists or not within a Bash shell script?

27 Jan at 23:14

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`?

28 Mar at 12:1

The Definitive C++ Book Guide and List

This question attempts to collect the few pearls among the dozens of bad C++ books that are published every year. Unlike many other programming languages, which are often picked up on the go from tuto...

18 Jan at 12:34

How do I UPDATE from a SELECT in SQL Server?

In , 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 a...

1 May at 16:21

What is RESTful programming?

What exactly is [RESTful programming](https://en.wikipedia.org/wiki/Representational_state_transfer)?

10 Jul at 23:19

How can I pair socks from a pile efficiently?

Yesterday I was pairing the socks from the clean laundry and figured out the way I was doing it is not very efficient. I was doing a naive search — picking one sock and "iterating" the pile in order t...

Iterating over dictionaries using 'for' loops

``` d = {'x': 1, 'y': 2, 'z': 3} for key in d: print(key, 'corresponds to', d[key]) ``` How does Python recognize that it needs only to read the `key` from the dictionary? Is `key` a special key...

1 Apr at 00:48

How do I delete a commit from a branch?

How do I delete a commit from my branch history? Should I use `git reset --hard HEAD`?

8 Jul at 04:44

Undoing a git rebase

How do I easily undo a git rebase? A lengthy manual method is: 1. checkout the commit parent to both of the branches 2. create and checkout a temporary branch 3. cherry-pick all commits by hand 4. re...

7 Aug at 20:15

How to insert an item into an array at a specific index (JavaScript)

I am looking for a JavaScript array insert method, in the style of: ``` arr.insert(index, item) ``` Preferably in jQuery, but any JavaScript implementation will do at this point.

7 Mar at 12:49

Create ArrayList from array

Given an array of type `Element[]`: ``` Element[] array = {new Element(1), new Element(2), new Element(3)}; ``` How do I convert this array into an object of type [ArrayList<Element>](https://docs.or...

17 Jul at 00:14

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` c...

2 Dec at 14:6

What is the !! (not not) operator in JavaScript?

I saw some code that seems to use an operator I don't recognize, in the form of two exclamation points, like so: `!!`. Can someone please tell me what this operator does? The context in which I saw t...

13 Aug at 21:20

Proper use cases for Android UserManager.isUserAGoat()?

I was looking at the new APIs introduced in [Android 4.2](http://en.wikipedia.org/wiki/Android_version_history#Android_4.1.2F4.2_Jelly_Bean). While looking at the [UserManager](http://developer.androi...

7 Sep at 08:21

How to round to at most 2 decimal places, if necessary

I'd like to round at most two decimal places, but . Input: ``` 10 1.7777777 9.1 ``` Output: ``` 10 1.78 9.1 ``` How can I do this in JavaScript?

5 May at 15:28

Sort array of objects by string property value

I have an array of JavaScript objects: ``` var objs = [ { first_nom: 'Lazslo', last_nom: 'Jamf' }, { first_nom: 'Pig', last_nom: 'Bodine' }, { first_nom: 'Pirate', last_nom: 'Pr...

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 "TE...

How do I test for an empty JavaScript object?

After an AJAX request, sometimes my application may return an empty object, like: ``` var a = {}; ``` How can I check whether that's the case?

17 Jan at 13:22

How do I efficiently iterate over each entry in a Java Map?

If I have an object implementing the `Map` interface in Java and I wish to iterate over every pair contained within it, what is the most efficient way of going through the map? Will the ordering of ...

How do I tell if a file does not exist in Bash?

This checks if a file exists: ``` #!/bin/bash FILE=$1 if [ -f $FILE ]; then echo "File $FILE exists." else echo "File $FILE does not exist." fi ``` How do I only check if the file does e...

17 Jul at 00:23

Using global variables in a function

How do I create or use a global variable inside a function? How do I use a global variable that was defined in one function inside other functions? --- `global``UnboundLocalError`[UnboundLocalError...

9 Sep at 14:53

What are the differences between a pointer variable and a reference variable?

What is the difference between a pointer variable and a reference variable?

4 Jul at 20:58

How do I cast int to enum in C#?

How do I cast an `int` to an `enum` in C#?

10 Jul at 23:22

Why is char[] preferred over String for passwords?

In Swing, the password field has a `getPassword()` (returns `char[]`) method instead of the usual `getText()` (returns `String`) method. Similarly, I have come across a suggestion not to use `String` ...

13 Jan at 11:48

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 be able to access its elements (values in ...

24 Oct at 18:50

Move existing, uncommitted work to a new branch in Git

I started some work on a new feature and after coding for a bit, I decided this feature should be on its own branch. How do I move the existing uncommitted changes to a new branch and reset my curre...

9 Oct at 05:1

How do I get the current branch name in Git?

How do I get the name of the current branch in Git?

8 Jul at 06:38

How do I get the current time?

How do I get the current time?

1 Apr at 11:27

View the change history of a file using Git versioning

How do I view the history of an individual file with complete details of what has changed? `git log -- [filename]` shows me the commit history of a file, but how do I see the file content that changed...

10 Jul at 21:49

Remove a file from a Git repository without deleting it from the local filesystem

I want to remove a file from my repository. ``` git rm file_to_remove.txt ``` will remove the file from the repository, but it will also remove the file from the local file system. How do I remove th...

How do I correctly clone a JavaScript object?

I have an object `x`. I'd like to copy it as object `y`, such that changes to `y` do not modify `x`. I realized that copying objects derived from built-in JavaScript objects will result in extra, unwa...

30 Apr at 19:52

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?

6 Jun at 19:40

How do I POST JSON data with cURL?

I use Ubuntu and installed [cURL](https://en.wikipedia.org/wiki/CURL) on it. I want to test my Spring REST application with cURL. I wrote my POST code at the Java side. However, I want to test it with...

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...

How to copy files

How do I copy a file in Python?

What does the explicit keyword mean?

What does the `explicit` keyword mean in C++?

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 , so that when I ask questions such as this, I can rework my code. When sh...

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 ge...

8 May at 17:29

What is __init__.py for?

What is [__init__.py](https://docs.python.org/3/tutorial/modules.html#packages) for in a Python source directory?

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

How can I convert a `String` to an `int`? ``` "1234" → 1234 ```

25 Jan at 13:11