lang2code

an NLP based code search tool


Link How do I undo the most recent local commits in Git? git
$ git commit -m "Something terribly misguided" # (0: Your Accident)
$ git reset HEAD~                              # (1)
<< edit files as necessary >>                  # (2)
$ git add .                                    # (3)
$ git commit -c ORIG_HEAD                      # (4)
Link How do I redirect to another webpage? javascript
// similar behavior as an HTTP redirect
window.location.replace("http://stackoverflow.com");

// similar behavior as clicking on a link
window.location.href = "http://stackoverflow.com";
Link How do I check if an element is hidden in jQuery? javascript
// Checks CSS content for display:[none|block], ignores visibility:[true|false]
$(element).is(":visible");

// The same works with hidden
$(element).is(":hidden");
Link Can comments be used in JSON? json
{
   "_comment": "comment text goes here...",
   "glossary": {
      "title": "example glossary",
      "GlossDiv": {
         "title": "S",
         "GlossList": {
            "GlossEntry": {
               "ID": "SGML",
               "SortAs": "SGML",
               "GlossTerm": "Standard Generalized Markup Language",
               "Acronym": "SGML",
               "Abbrev": "ISO 8879:1986",
               "GlossDef": {
                  "para": "A meta-markup language, used to create markup languages such as DocBook.",
                  "GlossSeeAlso": ["GML", "XML"]
               },
               "GlossSee": "markup"
            }
         }
      }
   }
}
Link How do I check whether a checkbox is checked in jQuery? javascript
$get("isAgeSelected ").checked == true
Link How do I discard unstaged changes in Git? git
git stash save --keep-index --include-untracked
Link How do I UPDATE from a SELECT in SQL Server? sql
UPDATE
    Table_A
SET
    Table_A.col1 = Table_B.col1,
    Table_A.col2 = Table_B.col2
FROM
    Some_Table AS Table_A
    INNER JOIN Other_Table AS Table_B
        ON Table_A.id = Table_B.id
WHERE
    Table_A.col3 = 'cool'
Link Does Python have a string 'contains' substring method? python
if "blah" not in somestring: 
    continue
Link What does "use strict" do in JavaScript, and what is the reasoning behind it? javascript
// Non-strict code...

(function(){
  "use strict";

  // Define your library strictly...
})();

// Non-strict code...
Link What is the "-->" operator in C++? c++
while( (x--) > 0 )
Link Iterate through a HashMap java
public static void printMap(Map mp) {
    Iterator it = mp.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry pair = (Map.Entry)it.next();
        System.out.println(pair.getKey() + " = " + pair.getValue());
        it.remove(); // avoids a ConcurrentModificationException
    }
}
Link How do I clone a specific Git branch? git
git clone --single-branch --branch  
Link Using global variables in a function python
globvar = 0

def set_globvar_to_one():
    global globvar    # Needed to modify global copy of globvar
    globvar = 1

def print_globvar():
    print(globvar)     # No need for global declaration to read value of globvar

set_globvar_to_one()
print_globvar()       # Prints 1
Link How do I check if a list is empty? python
if not a:
  print("List is empty")
Link Accessing the index in 'for' loops? python
for idx, val in enumerate(ints):
    print(idx, val)
Link How can I add new keys to a dictionary? python
d = {'key': 'value'}
print(d)
# {'key': 'value'}
d['mynewkey'] = 'mynewvalue'
print(d)
# {'key': 'value', 'mynewkey': 'mynewvalue'}
Link How do I efficiently iterate over each entry in a Java Map? java
Map map = ...
for (Map.Entry entry : map.entrySet()) {
    System.out.println(entry.getKey() + "/" + entry.getValue());
}
Link How to change the URI (URL) for a remote Git repository? git
git remote set-url origin new.git.url/here
Link How do I tell if a regular file does not exist in Bash? bash
if [ ! -f /tmp/foo.txt ]; then
    echo "File not found!"
fi
Link What is the maximum length of a URL in different browsers? http
Browser     Address bar   document.location
                          or anchor tag
------------------------------------------
Chrome          32779           >64k
Android          8192           >64k
Firefox          >64k           >64k
Safari           >64k           >64k
IE11             2047           5120
Edge 16          2047          10240