input_text stringlengths 115 13.8k | output_text stringlengths 24 15k | metadata dict |
|---|---|---|
Please answer the following Stack Overflow question:
Title: Why is processing a sorted array faster than processing an unsorted array?
<p>Here is a piece of C++ code that shows some very peculiar behavior. For some strange reason, sorting the data (<em>before</em> the timed region) miraculously makes the loop almost ... | <p><strong>You are a victim of <a href="https://en.wikipedia.org/wiki/Branch_predictor" rel="noreferrer">branch prediction</a> fail.</strong></p>
<hr />
<h2>What is Branch Prediction?</h2>
<p>Consider a railroad junction:</p>
<p><a href="https://commons.wikimedia.org/wiki/File:Entroncamento_do_Transpraia.JPG" rel="nore... | {
"question_id": 11227809,
"question_date": "2012-06-27T13:51:36.160Z",
"question_score": 26621,
"tags": "java|c++|performance|cpu-architecture|branch-prediction",
"answer_id": 11227902,
"answer_date": "2012-06-27T13:56:42.820Z",
"answer_score": 34269
} |
Please answer the following Stack Overflow question:
Title: How do I undo the most recent local commits in Git?
<p>I accidentally committed the wrong files to <a href="https://en.wikipedia.org/wiki/Git" rel="noreferrer">Git</a>, but didn't push the commit to the server yet. How do I undo those commits from the <em>lo... | <h1>Undo a commit & redo</h1>
<pre class="lang-sh prettyprint-override"><code>$ git commit -m "Something terribly misguided" # (0: Your Accident)
$ git reset HEAD~ # (1)
[ edit files as necessary ] # (2)
$ git add . # (3)
$... | {
"question_id": 927358,
"question_date": "2009-05-29T18:09:14.627Z",
"question_score": 24809,
"tags": "git|version-control|git-commit|undo",
"answer_id": 927386,
"answer_date": "2009-05-29T18:13:42.373Z",
"answer_score": 27023
} |
Please answer the following Stack Overflow question:
Title: How do I delete a Git branch locally and remotely?
<h4>Failed Attempts to Delete a Remote Branch:</h4>
<pre class="lang-bash prettyprint-override"><code>$ git branch -d remotes/origin/bugfix
error: branch 'remotes/origin/bugfix' not found.
$ git branch -d o... | <h1>Executive Summary</h1>
<pre><code>git push -d <remote_name> <branchname>
git branch -d <branchname>
</code></pre>
<p><strong>Note:</strong> In most cases, <code><remote_name></code> will be <code>origin</code>.</p>
<h1>Delete Local Branch</h1>
<p>To delete the <em><strong>local</strong></em>... | {
"question_id": 2003505,
"question_date": "2010-01-05T01:12:15.867Z",
"question_score": 19556,
"tags": "git|version-control|git-branch|git-push|git-remote",
"answer_id": 2003515,
"answer_date": "2010-01-05T01:13:55.193Z",
"answer_score": 24567
} |
Please answer the following Stack Overflow question:
Title: What is the difference between 'git pull' and 'git fetch'?
<p>What are the differences between <a href="https://git-scm.com/docs/git-pull" rel="noreferrer"><code>git pull</code></a> and <a href="https://git-scm.com/docs/git-fetch" rel="noreferrer"><code>git ... | <p>In the simplest terms, <a href="http://git-scm.com/docs/git-pull" rel="noreferrer"><code>git pull</code></a> does a <a href="http://git-scm.com/docs/git-fetch" rel="noreferrer"><code>git fetch</code></a> followed by a <a href="http://git-scm.com/docs/git-merge" rel="noreferrer"><code>git merge</code></a>.</p>
<hr />... | {
"question_id": 292357,
"question_date": "2008-11-15T09:51:09.660Z",
"question_score": 13368,
"tags": "git|version-control|git-pull|git-fetch",
"answer_id": 292359,
"answer_date": "2008-11-15T09:52:40.267Z",
"answer_score": 11135
} |
Please answer the following Stack Overflow question:
Title: What does the "yield" keyword do?
<p>What is the use of the <code>yield</code> keyword in Python? What does it do?</p>
<p>For example, I'm trying to understand this code<sup><strong>1</strong></sup>:</p>
<pre><code>def _get_child_candidates(self, distance, m... | <p>To understand what <code>yield</code> does, you must understand what <em>generators</em> are. And before you can understand generators, you must understand <em>iterables</em>.</p>
<h2>Iterables</h2>
<p>When you create a list, you can read its items one by one. Reading its items one by one is called iteration:</p>
<p... | {
"question_id": 231767,
"question_date": "2008-10-23T22:21:11.623Z",
"question_score": 12259,
"tags": "python|iterator|generator",
"answer_id": 231855,
"answer_date": "2008-10-23T22:48:44.797Z",
"answer_score": 17250
} |
Please answer the following Stack Overflow question:
Title: Which JSON content type do I use?
<p>There are many "standards" for the <a href="http://en.wikipedia.org/wiki/JSON" rel="noreferrer">JSON</a> content type:</p>
<pre class="lang-none prettyprint-override"><code>application/json
application/x-javascr... | <p>For JSON text:</p>
<pre><code>application/json
</code></pre>
<blockquote>
<p>The MIME media type for JSON text is <code>application/json</code>. The default encoding is UTF-8. <sup>(Source: <a href="http://www.ietf.org/rfc/rfc4627.txt" rel="noreferrer">RFC 4627</a>)</sup></p>
</blockquote>
<p>For <a href="http://en.... | {
"question_id": 477816,
"question_date": "2009-01-25T15:25:19.067Z",
"question_score": 11267,
"tags": "json|mime-types|content-type",
"answer_id": 477819,
"answer_date": "2009-01-25T15:27:29.720Z",
"answer_score": 11322
} |
Please answer the following Stack Overflow question:
Title: How can I remove a specific item from an array?
<p>How do I remove a specific value from an array? Something like:</p>
<pre class="lang-js prettyprint-override"><code>array.remove(value); // removes all elements with value
</code></pre>
<p>I have to use <em... | <p>Find the <code>index</code> of the array element you want to remove using <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf" rel="noreferrer"><code>indexOf</code></a>, and then remove that index with <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/... | {
"question_id": 5767325,
"question_date": "2011-04-23T22:17:18.487Z",
"question_score": 10953,
"tags": "javascript|arrays",
"answer_id": 5767357,
"answer_date": "2011-04-23T22:23:50.933Z",
"answer_score": 15553
} |
Please answer the following Stack Overflow question:
Title: How do I rename a local Git branch?
<p>How do I rename a local branch which has not yet been pushed to a remote repository?</p>
<p>Related:</p>
<ul>
<li><a href="https://stackoverflow.com/questions/1526794/rename-master-branch-for-both-local-and-remote-git-r... | <p>To rename the current branch:</p>
<pre><code>git branch -m <newname>
</code></pre>
<p>To rename a branch while pointed to any branch:</p>
<pre><code>git branch -m <oldname> <newname>
</code></pre>
<p><code>-m</code> is short for <code>--move</code>.</p>
<hr />
<p>To push the local branch and reset... | {
"question_id": 6591213,
"question_date": "2011-07-06T03:20:36.830Z",
"question_score": 10738,
"tags": "git|version-control|git-branch",
"answer_id": 6591218,
"answer_date": "2011-07-06T03:21:42.917Z",
"answer_score": 17541
} |
Please answer the following Stack Overflow question:
Title: How do I undo 'git add' before commit?
<p>I mistakenly added files to Git using the command:</p>
<pre><code>git add myfile.txt
</code></pre>
<p>I have not yet run <code>git commit</code>. How do I undo this so that these changes will not be included in the c... | <p>Undo <code>git add</code> for uncommitted changes with:</p>
<pre><code>git reset <file>
</code></pre>
<p>That will remove the file from the current index (the "about to be committed" list) without changing anything else.</p>
<hr />
<p>To unstage all changes for all files:</p>
<pre><code>git reset
</c... | {
"question_id": 348170,
"question_date": "2008-12-07T21:57:46.503Z",
"question_score": 10682,
"tags": "git|undo|git-add",
"answer_id": 348234,
"answer_date": "2008-12-07T22:30:48.340Z",
"answer_score": 12688
} |
Please answer the following Stack Overflow question:
Title: What is the "-->" operator in C++?
<p>After reading <a href="http://groups.google.com/group/comp.lang.c++.moderated/msg/33f173780d58dd20" rel="noreferrer">Hidden Features and Dark Corners of C++/STL</a> on <code>comp.lang.c++.moderated</code>, I was complete... | <p><code>--></code> is not an operator. It is in fact two separate operators, <code>--</code> and <code>></code>.</p>
<p>The conditional's code decrements <code>x</code>, while returning <code>x</code>'s original (not decremented) value, and then compares the original value with <code>0</code> using the <code>>... | {
"question_id": 1642028,
"question_date": "2009-10-29T06:57:45.903Z",
"question_score": 9843,
"tags": "c++|c|operators|code-formatting|standards-compliance",
"answer_id": 1642035,
"answer_date": "2009-10-29T07:00:09.617Z",
"answer_score": 9538
} |
Please answer the following Stack Overflow question:
Title: What and where are the stack and heap?
<ul>
<li>What are the stack and heap?</li>
<li>Where are they located physically in a computer's memory?</li>
<li>To what extent are they controlled by the OS or language run-time?</li>
<li>What is their scope?</li>
<li... | <p>The stack is the memory set aside as scratch space for a thread of execution. When a function is called, a block is reserved on the top of the stack for local variables and some bookkeeping data. When that function returns, the block becomes unused and can be used the next time a function is called. The stack is ... | {
"question_id": 79923,
"question_date": "2008-09-17T04:18:06.337Z",
"question_score": 9106,
"tags": "memory-management|stack|language-agnostic|dynamic-memory-allocation|heap-memory",
"answer_id": 80113,
"answer_date": "2008-09-17T04:52:19.437Z",
"answer_score": 6633
} |
Please answer the following Stack Overflow question:
Title: Can comments be used in JSON?
<p>Can I use comments inside a <a href="https://en.wikipedia.org/wiki/JSON" rel="noreferrer">JSON</a> file? If so, how?</p> | <p>No.</p>
<p>JSON is data-only. If you include a comment, then it must be data too.</p>
<p>You could have a designated data element called <code>"_comment"</code> (or something) that should be ignored by apps that use the JSON data.</p>
<p>You would probably be better having the comment in the processes that... | {
"question_id": 244777,
"question_date": "2008-10-28T20:39:03.333Z",
"question_score": 9088,
"tags": "json|comments",
"answer_id": 244858,
"answer_date": "2008-10-28T21:01:42.307Z",
"answer_score": 6741
} |
Please answer the following Stack Overflow question:
Title: How do I force "git pull" to overwrite local files?
<p>How do I force an overwrite of local files on a <code>git pull</code>? My local repository contains a file of the same filename as on the server.</p>
<blockquote>
<p>error: Untracked working tree file 'e... | <blockquote>
<h2>⚠ Warning:</h2>
<p>Any uncommitted local changes to tracked files will be lost.</p>
<p>Any local files that are <em>not</em> tracked by Git will not be affected.</p>
</blockquote>
<hr />
<p>First, update all <code>origin/<branch></code> refs to latest:</p>
<pre><code>git fetch --all
</code></pre>... | {
"question_id": 1125968,
"question_date": "2009-07-14T14:58:15.550Z",
"question_score": 8913,
"tags": "git|version-control|overwrite|git-pull|git-fetch",
"answer_id": 8888015,
"answer_date": "2012-01-17T00:02:58.813Z",
"answer_score": 12364
} |
Please answer the following Stack Overflow question:
Title: Why does HTML think “chucknorris” is a color?
<p>Why do certain random strings produce colors when entered as background colors in HTML?</p>
<p>For example, <code>bgcolor="chucknorris"</code> produces a <strong>red background</strong>:</p>
<p><div ... | <p>It’s a holdover from the Netscape days:</p>
<blockquote>
<p>Missing digits are treated as 0[...]. An incorrect digit is simply interpreted as 0. For example the values #F0F0F0, F0F0F0, F0F0F, #FxFxFx and FxFxFx are all the same.</p>
</blockquote>
<p>It is from the blog post <em><a href="http://scrappy-do.blogspot.co... | {
"question_id": 8318911,
"question_date": "2011-11-29T22:54:22.833Z",
"question_score": 8506,
"tags": "html|browser|background-color",
"answer_id": 8333464,
"answer_date": "2011-11-30T21:53:38.350Z",
"answer_score": 7907
} |
Please answer the following Stack Overflow question:
Title: How do I check if an element is hidden in jQuery?
<p>How do I toggle the visibility of an element using <code>.hide()</code>, <code>.show()</code>, or <code>.toggle()</code>?</p>
<p>How do I test if an element is <code>visible</code> or <code>hidden</code>?... | <p>Since the question refers to a single element, this code might be more suitable:</p>
<pre><code>// Checks CSS content for display:[none|block], ignores visibility:[true|false]
$(element).is(":visible");
// The same works with hidden
$(element).is(":hidden");
</code></pre>
<p>It is the same as <a... | {
"question_id": 178325,
"question_date": "2008-10-07T13:03:18.057Z",
"question_score": 8447,
"tags": "javascript|jquery|dom|visibility",
"answer_id": 178450,
"answer_date": "2008-10-07T13:30:22.217Z",
"answer_score": 10070
} |
Please answer the following Stack Overflow question:
Title: What does "use strict" do in JavaScript, and what is the reasoning behind it?
<p>Recently, I ran some of my JavaScript code through Crockford's <a href="http://www.jslint.com/" rel="noreferrer">JSLint</a>, and it gave the following error:</p>
<blockquote>
<p... | <h2>Update for ES6 modules</h2>
<p>Inside <a href="https://caniuse.com/#feat=es6-module" rel="noreferrer">native ECMAScript modules</a> (with <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/import" rel="noreferrer"><code>import</code></a> and <a href="https://developer.mozilla.org/docs/W... | {
"question_id": 1335851,
"question_date": "2009-08-26T16:10:13.827Z",
"question_score": 8264,
"tags": "javascript|syntax|jslint|use-strict",
"answer_id": 1335881,
"answer_date": "2009-08-26T16:15:39.370Z",
"answer_score": 5369
} |
Please answer the following Stack Overflow question:
Title: How do I check out a remote Git branch?
<p>Somebody pushed a branch called <code>test</code> with <code>git push origin test</code> to a shared repository. I can see the branch with <code>git branch -r</code>. How do I check out the remote <code>test</code> ... | <p>The answer has been split depending on whether there is one remote repository configured or multiple. The reason for this is that for the single remote case, some of the commands can be simplified as there is less ambiguity.</p>
<p><strong>Updated for Git 2.23:</strong> For older versions, see the section at the end... | {
"question_id": 1783405,
"question_date": "2009-11-23T14:23:46.150Z",
"question_score": 8058,
"tags": "git|git-checkout|remote-branch",
"answer_id": 1783426,
"answer_date": "2009-11-23T14:26:08.970Z",
"answer_score": 10952
} |
Please answer the following Stack Overflow question:
Title: How do I remove local (untracked) files from the current Git working tree?
<p>How do I delete untracked local files from the current working tree?</p> | <blockquote>
<h2><a href="https://git-scm.com/docs/git-clean" rel="noreferrer">git-clean</a> - Remove untracked files from the working tree</h2>
<h3>Synopsis</h3>
<pre><code>git clean [-d] [-f] [-i] [-n] [-q] [-e <pattern>] [-x | -X] [--] <path>…
</code></pre>
<h3>Description</h3>
<p>Cleans the working tre... | {
"question_id": 61212,
"question_date": "2008-09-14T09:06:10.647Z",
"question_score": 7766,
"tags": "git|branch|git-branch",
"answer_id": 64966,
"answer_date": "2008-09-15T17:32:55.957Z",
"answer_score": 9518
} |
Please answer the following Stack Overflow question:
Title: What does if __name__ == "__main__": do?
<p>What does this do, and why should one include the <code>if</code> statement?</p>
<pre><code>if __name__ == "__main__":
print("Hello, World!")
</code></pre>
<hr />
<p><sub>This question expla... | <h1>Short Answer</h1>
<p>It's boilerplate code that protects users from accidentally invoking the script when they didn't intend to. Here are some common problems when the guard is omitted from a script:</p>
<ul>
<li><p>If you import the guardless script in another script (e.g. <code>import my_script_without_a_name_eq_... | {
"question_id": 419163,
"question_date": "2009-01-07T04:11:00.010Z",
"question_score": 7713,
"tags": "python|namespaces|program-entry-point|python-module|idioms",
"answer_id": 419185,
"answer_date": "2009-01-07T04:26:43.380Z",
"answer_score": 8420
} |
Please answer the following Stack Overflow question:
Title: How do I redirect to another webpage?
<p>How can I redirect the user from one page to another using jQuery or pure JavaScript?</p> | <h2>One does not simply redirect using jQuery</h2>
<p>jQuery is not necessary, and <a href="https://developer.mozilla.org/en-US/docs/Web/API/Location/replace" rel="noreferrer"><strong><code>window.location.replace(...)</code></strong></a> will best simulate an HTTP redirect. </p>
<p><code>window.location.replace(...... | {
"question_id": 503093,
"question_date": "2009-02-02T12:54:16.867Z",
"question_score": 7707,
"tags": "javascript|jquery|redirect",
"answer_id": 506004,
"answer_date": "2009-02-03T04:24:09.767Z",
"answer_score": 16001
} |
Please answer the following Stack Overflow question:
Title: How to modify existing, unpushed commit messages?
<p>I wrote the wrong thing in a commit message.</p>
<p>How can I change the message? The commit has not been pushed yet.</p> | <h1>Amending the most recent commit message</h1>
<pre class="lang-sh prettyprint-override"><code>git commit --amend
</code></pre>
<p>will open your editor, allowing you to change the commit message of the most recent commit. Additionally, you can set the commit message directly in the command line with:</p>
<pre class=... | {
"question_id": 179123,
"question_date": "2008-10-07T15:44:47.920Z",
"question_score": 7653,
"tags": "git|git-commit|git-rewrite-history|git-amend",
"answer_id": 179147,
"answer_date": "2008-10-07T15:50:34.630Z",
"answer_score": 17827
} |
Please answer the following Stack Overflow question:
Title: How do JavaScript closures work?
<p>How would you explain JavaScript closures to someone with a knowledge of the concepts they consist of (for example functions, variables and the like), but does not understand closures themselves?</p>
<p>I have seen <a hre... | <p>A closure is a pairing of:</p>
<ol>
<li>A function and</li>
<li>A reference to that function's outer scope (lexical environment)</li>
</ol>
<p>A lexical environment is part of every execution context (stack frame) and is a map between identifiers (i.e. local variable names) and values.</p>
<p>Every function in JavaS... | {
"question_id": 111102,
"question_date": "2008-09-21T14:12:07.003Z",
"question_score": 7623,
"tags": "javascript|function|variables|scope|closures",
"answer_id": 111111,
"answer_date": "2008-09-21T14:18:18.347Z",
"answer_score": 8191
} |
Please answer the following Stack Overflow question:
Title: How do I revert a Git repository to a previous commit?
<p>How do I revert from my current state to a snapshot made on a certain commit?</p>
<p>If I do <code>git log</code>, then I get the following output:</p>
<pre><code>$ git log
commit a867b4af366350be2e... | <p>This depends a lot on what you mean by "revert".</p>
<h2>Temporarily switch to a different commit</h2>
<p>If you want to temporarily go back to it, fool around, then come back to where you are, all you have to do is check out the desired commit:</p>
<pre class="lang-sh prettyprint-override"><code># This wi... | {
"question_id": 4114095,
"question_date": "2010-11-06T16:58:14.550Z",
"question_score": 7617,
"tags": "git|git-checkout|git-reset|git-revert",
"answer_id": 4114122,
"answer_date": "2010-11-06T17:04:54.543Z",
"answer_score": 11626
} |
Please answer the following Stack Overflow question:
Title: Does Python have a ternary conditional operator?
<p>Is there a <a href="https://en.wikipedia.org/wiki/%3F:#Python" rel="noreferrer">ternary conditional operator</a> in Python?</p> | <p>Yes, it was <a href="https://mail.python.org/pipermail/python-dev/2005-September/056846.html" rel="noreferrer" title="[Python-Dev] Conditional Expression Resolution">added</a> in version 2.5. The expression syntax is:</p>
<pre class="lang-py prettyprint-override"><code>a if condition else b
</code></pre>
<p>First <c... | {
"question_id": 394809,
"question_date": "2008-12-27T08:32:18.533Z",
"question_score": 7477,
"tags": "python|operators|conditional-operator",
"answer_id": 394814,
"answer_date": "2008-12-27T08:44:19.883Z",
"answer_score": 8627
} |
Please answer the following Stack Overflow question:
Title: var functionName = function() {} vs function functionName() {}
<p>I've recently started maintaining someone else's JavaScript code. I'm fixing bugs, adding features and also trying to tidy up the code and make it more consistent.</p>
<p>The previous develope... | <p>The difference is that <code>functionOne</code> is a function expression and so only defined when that line is reached, whereas <code>functionTwo</code> is a function declaration and is defined as soon as its surrounding function or script is executed (due to <a href="http://adripofjavascript.com/blog/drips/variable... | {
"question_id": 336859,
"question_date": "2008-12-03T11:31:07.473Z",
"question_score": 7477,
"tags": "javascript|function|syntax|idioms",
"answer_id": 336868,
"answer_date": "2008-12-03T11:37:42.267Z",
"answer_score": 5484
} |
Please answer the following Stack Overflow question:
Title: How to check whether a string contains a substring in JavaScript?
<p>Usually I would expect a <code>String.contains()</code> method, but there doesn't seem to be one. </p>
<p>What is a reasonable way to check for this?</p> | <p>ECMAScript 6 introduced <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes" rel="noreferrer"><code>String.prototype.includes</code></a>:</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-cod... | {
"question_id": 1789945,
"question_date": "2009-11-24T13:04:29.157Z",
"question_score": 7413,
"tags": "javascript|string|substring|string-matching",
"answer_id": 1789952,
"answer_date": "2009-11-24T13:05:36.550Z",
"answer_score": 15389
} |
Please answer the following Stack Overflow question:
Title: How do I make Git forget about a file that was tracked, but is now in .gitignore?
<p>I put a file that was previously being tracked by Git onto the <code>.gitignore</code> list. However, the file still shows up in <code>git status</code> after it is edited. ... | <p><code>.gitignore</code> will prevent untracked files from being added (without an <code>add -f</code>) to the set of files tracked by Git. However, Git will continue to track any files that are already being tracked.</p>
<p>To stop tracking a file, we must remove it from the index:</p>
<pre><code>git rm --cached <... | {
"question_id": 1274057,
"question_date": "2009-08-13T19:23:22.140Z",
"question_score": 7405,
"tags": "git|gitignore|git-rm",
"answer_id": 1274447,
"answer_date": "2009-08-13T20:40:59.257Z",
"answer_score": 7877
} |
Please answer the following Stack Overflow question:
Title: Why is subtracting these two times (in 1927) giving a strange result?
<p>If I run the following program, which parses two date strings referencing times 1 second apart and compares them:</p>
<pre><code>public static void main(String[] args) throws ParseExcep... | <p>It's a time zone change on December 31st in Shanghai.</p>
<p>See <a href="http://www.timeanddate.com/worldclock/clockchange.html?n=237&year=1927" rel="noreferrer">this page</a> for details of 1927 in Shanghai. Basically at midnight at the end of 1927, the clocks went back 5 minutes and 52 seconds. So "1927-12-3... | {
"question_id": 6841333,
"question_date": "2011-07-27T08:15:58.380Z",
"question_score": 7398,
"tags": "java|date|timezone",
"answer_id": 6841479,
"answer_date": "2011-07-27T08:31:10.090Z",
"answer_score": 11679
} |
Please answer the following Stack Overflow question:
Title: What is the difference between String and string in C#?
<p>What are the differences between these two and which one should I use?</p>
<pre><code>string s = "Hello world!";
String s = "Hello world!";
</code></pre> | <p><a href="https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/string" rel="noreferrer"><code>string</code></a> is an alias in C# for <a href="https://docs.microsoft.com/en-us/dotnet/api/system.string" rel="noreferrer"><code>System.String</code></a>.<br />
So technically, there is no difference.... | {
"question_id": 7074,
"question_date": "2008-08-10T07:18:02.320Z",
"question_score": 7301,
"tags": "c#|.net|string|types|alias",
"answer_id": 7077,
"answer_date": "2008-08-10T07:22:02.030Z",
"answer_score": 6861
} |
Please answer the following Stack Overflow question:
Title: How do I remove a property from a JavaScript object?
<p>Given an object:</p>
<pre><code>let myObject = {
"ircEvent": "PRIVMSG",
"method": "newURI",
"regex": "^http://.*"
};
</code></pre>
<p>Ho... | <p>To remove a property from an object (mutating the object), you can do it like this:</p>
<pre><code>delete myObject.regex;
// or,
delete myObject['regex'];
// or,
var prop = "regex";
delete myObject[prop];
</code></pre>
<p>Demo
<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-b... | {
"question_id": 208105,
"question_date": "2008-10-16T10:57:45.830Z",
"question_score": 7138,
"tags": "javascript|object|properties",
"answer_id": 208106,
"answer_date": "2008-10-16T10:58:53.207Z",
"answer_score": 9479
} |
Please answer the following Stack Overflow question:
Title: What are metaclasses in Python?
<p>What are metaclasses? What are they used for?</p> | <p>A metaclass is the class of a class. A class defines how an instance of the class (i.e. an object) behaves while a metaclass defines how a class behaves. A class is an instance of a metaclass.</p>
<p>While in Python you can use arbitrary callables for metaclasses (like <a href="https://stackoverflow.com/questions/1... | {
"question_id": 100003,
"question_date": "2008-09-19T06:10:46.830Z",
"question_score": 6956,
"tags": "python|oop|metaclass|python-class|python-datamodel",
"answer_id": 100146,
"answer_date": "2008-09-19T07:01:58.623Z",
"answer_score": 3383
} |
Please answer the following Stack Overflow question:
Title: How to find all files containing specific text (string) on Linux
<p>How do I find all files containing a specific string of text within their file contents?</p>
<p>The following doesn't work. It seems to display every single file in the system.</p>
<pre clas... | <p>Do the following:</p>
<pre class="lang-sh prettyprint-override"><code>grep -rnw '/path/to/somewhere/' -e 'pattern'
</code></pre>
<ul>
<li><code>-r</code> or <code>-R</code> is recursive,</li>
<li><code>-n</code> is line number, and</li>
<li><code>-w</code> stands for match the whole word.</li>
<li><code>-l</code> (l... | {
"question_id": 16956810,
"question_date": "2013-06-06T08:06:45.533Z",
"question_score": 6894,
"tags": "linux|text|grep|directory|find",
"answer_id": 16957078,
"answer_date": "2013-06-06T08:21:35.803Z",
"answer_score": 12548
} |
Please answer the following Stack Overflow question:
Title: What is the difference between px, dip, dp, and sp?
<p>What is the difference between the units of measure
px, dip, dp, and sp?</p> | <p>From the <a href="http://developer.android.com/guide/topics/resources/more-resources.html#Dimension" rel="noreferrer">Android Developer Documentation</a>:</p>
<ol>
<li>
<blockquote>
<p><strong>px</strong><br />
<strong>Pixels</strong> - corresponds to actual pixels on the screen.</p>
</blockquote>
</li>
<li>
<blockq... | {
"question_id": 2025282,
"question_date": "2010-01-08T03:23:46.680Z",
"question_score": 6251,
"tags": "android|android-layout|user-interface|dimension|units-of-measurement",
"answer_id": 2025541,
"answer_date": "2010-01-08T04:41:53.070Z",
"answer_score": 6114
} |
Please answer the following Stack Overflow question:
Title: Move the most recent commit(s) to a new branch with Git
<p>How do I move my recent commits on master to a new branch, and reset master to before those commits were made? e.g. From this:</p>
<pre><code>master A - B - C - D - E
</code></pre>
<p>To this:</p>
<p... | <h2>Moving to an existing branch</h2>
<p>If you want to move your commits to an <strong>existing branch</strong>, it will look like this:</p>
<pre><code>git checkout existingbranch
git merge master
git checkout master
git reset --hard HEAD~3 # Go back 3 commits. You *will* lose uncommitted work.
git checkout existingbr... | {
"question_id": 1628563,
"question_date": "2009-10-27T03:07:34.733Z",
"question_score": 6101,
"tags": "git|git-branch|branching-and-merging",
"answer_id": 1628584,
"answer_date": "2009-10-27T03:15:15.320Z",
"answer_score": 7862
} |
Please answer the following Stack Overflow question:
Title: What is the difference between POST and PUT in HTTP?
<p>According to <a href="https://www.rfc-editor.org/rfc/rfc2616#section-9.5" rel="noreferrer">RFC 2616, § 9.5</a>, <code>POST</code> is used to <em>create</em> a resource:</p>
<blockquote>
<p>The POST meth... | <p><strong>Overall:</strong></p>
<p>Both PUT and POST can be used for creating.</p>
<p>You have to ask, "what are you performing the action upon?", to distinguish what you should be using. Let's assume you're designing an API for asking questions. If you want to use POST, then you would do that to a list of ... | {
"question_id": 630453,
"question_date": "2009-03-10T14:25:20.390Z",
"question_score": 6081,
"tags": "http|rest|post|put",
"answer_id": 630475,
"answer_date": "2009-03-10T14:29:46.930Z",
"answer_score": 4718
} |
Please answer the following Stack Overflow question:
Title: How do I include a JavaScript file in another JavaScript file?
<p>How do I include a JavaScript file inside another JavaScript file, similar to <code>@import</code> in CSS?</p> | <p>The old versions of JavaScript had no import, include, or require, so many different approaches to this problem have been developed.</p>
<p>But since 2015 (ES6), JavaScript has had the <a href="http://exploringjs.com/es6/ch_modules.html" rel="noreferrer">ES6 modules</a> standard to import modules in Node.js, which i... | {
"question_id": 950087,
"question_date": "2009-06-04T11:59:50.987Z",
"question_score": 6067,
"tags": "javascript|file|import|include",
"answer_id": 950146,
"answer_date": "2009-06-04T12:13:28.403Z",
"answer_score": 5227
} |
Please answer the following Stack Overflow question:
Title: What is the difference between "let" and "var"?
<p>ECMAScript 6 introduced <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let" rel="noreferrer">the <code>let</code> statement</a>.</p>
<p>I've heard that it's described a... | <h1>Scoping rules</h1>
<p>The main difference is scoping rules. Variables declared by <code>var</code> keyword are scoped to the immediate function body (hence the function scope) while <code>let</code> variables are scoped to the immediate <em>enclosing</em> block denoted by <code>{ }</code> (hence the block scope).</... | {
"question_id": 762011,
"question_date": "2009-04-17T20:09:26.777Z",
"question_score": 5908,
"tags": "javascript|scope|ecmascript-6|var|let",
"answer_id": 11444416,
"answer_date": "2012-07-12T02:53:34.897Z",
"answer_score": 7819
} |
Please answer the following Stack Overflow question:
Title: How do I discard unstaged changes in Git?
<p>How do I discard changes in my working copy that are not in the index?</p> | <p>Another quicker way is:</p>
<pre><code>git stash save --keep-index --include-untracked
</code></pre>
<p>You don't need to include <code>--include-untracked</code> if you don't want to be thorough about it.</p>
<p>After that, you can drop that stash with a <code>git stash drop</code> command if you like.</p> | {
"question_id": 52704,
"question_date": "2008-09-09T19:33:59.133Z",
"question_score": 5867,
"tags": "git|version-control",
"answer_id": 52719,
"answer_date": "2008-09-09T19:39:24.970Z",
"answer_score": 3074
} |
Please answer the following Stack Overflow question:
Title: How do I get the directory where a Bash script is located from within the script itself?
<p>How do I get the path of the directory in which a <a href="http://en.wikipedia.org/wiki/Bash_%28Unix_shell%29" rel="noreferrer">Bash</a> script is located, <em>inside... | <pre><code>#!/usr/bin/env bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
</code></pre>
<p>is a useful one-liner which will give you the full directory name of the script no matter where it is being called from.</p>
<p>It will work as long as the ... | {
"question_id": 59895,
"question_date": "2008-09-12T20:39:56.860Z",
"question_score": 5843,
"tags": "bash|directory",
"answer_id": 246128,
"answer_date": "2008-10-29T08:36:45.740Z",
"answer_score": 7670
} |
Please answer the following Stack Overflow question:
Title: How do I execute a program or call a system command?
<p>How do I call an external command within Python as if I'd typed it in a shell or command prompt?</p> | <p>Use the <a href="https://docs.python.org/library/subprocess.html" rel="noreferrer"><code>subprocess</code></a> module in the standard library:</p>
<pre class="lang-py prettyprint-override"><code>import subprocess
subprocess.run(["ls", "-l"])
</code></pre>
<p>The advantage of <a href="https://docs... | {
"question_id": 89228,
"question_date": "2008-09-18T01:35:30.273Z",
"question_score": 5790,
"tags": "python|shell|terminal|subprocess|command",
"answer_id": 89243,
"answer_date": "2008-09-18T01:39:35.257Z",
"answer_score": 5512
} |
Please answer the following Stack Overflow question:
Title: Which equals operator (== vs ===) should be used in JavaScript comparisons?
<p>I'm using <a href="http://en.wikipedia.org/wiki/JSLint" rel="noreferrer">JSLint</a> to go through JavaScript, and it's returning many suggestions to replace <code>==</code> (two e... | <p>The strict equality operator (<code>===</code>) behaves identically to the abstract equality operator (<code>==</code>) except no type conversion is done, and the types must be the same to be considered equal.</p>
<p>Reference: <a href="http://www.c-point.com/javascript_tutorial/jsgrpComparison.htm" rel="noreferrer... | {
"question_id": 359494,
"question_date": "2008-12-11T14:19:49.123Z",
"question_score": 5652,
"tags": "javascript|operators|equality|equality-operator|identity-operator",
"answer_id": 359509,
"answer_date": "2008-12-11T14:25:06.430Z",
"answer_score": 7047
} |
Please answer the following Stack Overflow question:
Title: How do I change the URI (URL) for a remote Git repository?
<p>I have a repo (origin) on a USB key that I cloned on my hard drive (local). I moved "origin" to a NAS and successfully tested cloning it from here.</p>
<p>I would like to know if I can c... | <p>You can</p>
<pre><code>git remote set-url origin new.git.url/here
</code></pre>
<p>See <a href="https://git-scm.com/docs/git-remote" rel="noreferrer"><code>git help remote</code></a>. You also can edit <code>.git/config</code> and change the URLs there.</p>
<p>You're not in any danger of losing history unless you do... | {
"question_id": 2432764,
"question_date": "2010-03-12T12:48:47.280Z",
"question_score": 5538,
"tags": "git|url|git-remote",
"answer_id": 2432799,
"answer_date": "2010-03-12T12:55:50.670Z",
"answer_score": 8868
} |
Please answer the following Stack Overflow question:
Title: What is the maximum length of a URL in different browsers?
<p>What is the maximum length of a URL for each browser?</p>
<p>Is a maximum URL length part of the HTTP specification?</p> | <h2>Short answer - de facto limit of 2000 characters</h2>
<p>If you keep URLs under 2000 characters, they'll work in virtually any combination of client and server software.</p>
<p>If you are targeting particular browsers, see below for more details on specific limits.</p>
<h2>Longer answer - first, the standards...</h... | {
"question_id": 417142,
"question_date": "2009-01-06T16:14:30.410Z",
"question_score": 5471,
"tags": "http|url|browser",
"answer_id": 417184,
"answer_date": "2009-01-06T16:22:18.443Z",
"answer_score": 5691
} |
Please answer the following Stack Overflow question:
Title: How can I validate an email address in JavaScript?
<p>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?</p... | <p>Using <a href="http://en.wikipedia.org/wiki/Regular_expression" rel="noreferrer">regular expressions</a> is probably the best way. You can see a bunch of tests <a href="http://jsfiddle.net/ghvj4gy9/embedded/result,js/" rel="noreferrer">here</a> (taken from <a href="https://cs.chromium.org/chromium/src/third_party/bl... | {
"question_id": 46155,
"question_date": "2008-09-05T16:10:11.093Z",
"question_score": 5434,
"tags": "javascript|html|regex|email-validation",
"answer_id": 46181,
"answer_date": "2008-09-05T16:15:34.747Z",
"answer_score": 6290
} |
Please answer the following Stack Overflow question:
Title: How do I reset or revert a file to a specific revision?
<p>How do I revert a modified file to its previous revision at a specific commit hash (which I determined via <a href="https://git-scm.com/docs/git-log" rel="noreferrer"><code>git log</code></a> and <a ... | <p>Assuming the hash of the commit you want is <code>c5f567</code>:</p>
<pre><code>git checkout c5f567 -- file1/to/restore file2/to/restore
</code></pre>
<p>The <a href="https://git-scm.com/docs/git-checkout" rel="noreferrer">git checkout</a> man page gives more information.</p>
<p>If you want to revert to the commit b... | {
"question_id": 215718,
"question_date": "2008-10-18T23:34:02.570Z",
"question_score": 5426,
"tags": "git|version-control|git-checkout",
"answer_id": 215731,
"answer_date": "2008-10-18T23:39:35.210Z",
"answer_score": 7335
} |
Please answer the following Stack Overflow question:
Title: How can I safely create a nested directory?
<p>How do I check if the directory into which a file is going to be written does exist, and if it does not, create the directory using Python?</p> | <p>On Python ≥ 3.5, use <a href="https://docs.python.org/library/pathlib.html#pathlib.Path.mkdir" rel="noreferrer"><code>pathlib.Path.mkdir</code></a>:</p>
<pre><code>from pathlib import Path
Path("/my/directory").mkdir(parents=True, exist_ok=True)
</code></pre>
<p>For older versions of Python, I see two answers with... | {
"question_id": 273192,
"question_date": "2008-11-07T18:56:45.670Z",
"question_score": 5316,
"tags": "python|exception|path|directory|operating-system",
"answer_id": 273227,
"answer_date": "2008-11-07T19:06:07.663Z",
"answer_score": 6675
} |
Please answer the following Stack Overflow question:
Title: How do I push a new local branch to a remote Git repository and track it too?
<p>How do I:</p>
<ol>
<li><p>Create a local branch from another branch (via <code>git branch</code> or <code>git checkout -b</code>).</p>
</li>
<li><p>Push the local branch
to the ... | <p>In Git 1.7.0 and later, you can checkout a new branch:</p>
<pre><code>git checkout -b <branch>
</code></pre>
<p>Edit files, add and commit. Then <a href="https://git-scm.com/docs/git-push" rel="noreferrer">push with the <code>-u</code> (short for <code>--set-upstream</code>)</a> option:</p>
<pre><code>git p... | {
"question_id": 2765421,
"question_date": "2010-05-04T12:58:34.517Z",
"question_score": 5295,
"tags": "git|repository|git-branch|git-push|git-remote",
"answer_id": 6232535,
"answer_date": "2011-06-03T20:50:29.507Z",
"answer_score": 7955
} |
Please answer the following Stack Overflow question:
Title: How do I replace all occurrences of a string in JavaScript?
<p>Given a string:</p>
<pre><code>s = "Test abc test test abc test test test abc test test abc";
</code></pre>
<p>This seems to only remove the first occurrence of <code>abc</code> in the ... | <p>In the latest versions of most popular browsers, you can use <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll" rel="nofollow noreferrer"><code>replaceAll</code></a>
as shown here:</p>
<pre class="lang-js prettyprint-override"><code>let result = "1 abc 2... | {
"question_id": 1144783,
"question_date": "2009-07-17T17:53:46.750Z",
"question_score": 5261,
"tags": "javascript|string|replace",
"answer_id": 1145525,
"answer_date": "2009-07-17T20:29:12.147Z",
"answer_score": 2320
} |
Please answer the following Stack Overflow question:
Title: What is a plain English explanation of "Big O" notation?
<p>I'd prefer as little formal definition as possible and simple mathematics.</p> | <p>Quick note, my answer is almost certainly confusing <a href="http://en.wikipedia.org/wiki/Big_O_notation" rel="noreferrer">Big Oh notation</a> (which is an upper bound) with Big Theta notation "Θ" (which is a two-side bound). But in my experience, this is actually typical of discussions in non-academic set... | {
"question_id": 487258,
"question_date": "2009-01-28T11:10:32.043Z",
"question_score": 5261,
"tags": "algorithm|complexity-theory|computer-science|big-o|time-complexity",
"answer_id": 487278,
"answer_date": "2009-01-28T11:18:57.817Z",
"answer_score": 6995
} |
Please answer the following Stack Overflow question:
Title: How do I resolve merge conflicts in a Git repository?
<p>How do I resolve merge conflicts in my Git repository?</p> | <p>Try:</p>
<pre class="lang-bash prettyprint-override"><code>git mergetool
</code></pre>
<p>It opens a GUI that steps you through each conflict, and you get to choose how to merge. Sometimes it requires a bit of hand editing afterwards, but usually it's enough by itself. It is much better than doing the whole thing ... | {
"question_id": 161813,
"question_date": "2008-10-02T11:31:05.777Z",
"question_score": 5242,
"tags": "git|git-merge|merge-conflict-resolution|git-merge-conflict",
"answer_id": 163659,
"answer_date": "2008-10-02T17:50:25.100Z",
"answer_score": 3288
} |
Please answer the following Stack Overflow question:
Title: What is the most efficient way to deep clone an object in JavaScript?
<p>What is the most efficient way to clone a JavaScript object? I've seen <code>obj = eval(uneval(o));</code> being used, but <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScri... | <h1>Native deep cloning</h1>
<p>There's now a JS standard called <a href="https://developer.mozilla.org/en-US/docs/Web/API/structuredClone" rel="noreferrer">"structured cloning"</a>, that works experimentally in Node 11 and later, will land in browsers, and which has <a href="https://www.npmjs.com/package/@un... | {
"question_id": 122102,
"question_date": "2008-09-23T16:26:09.163Z",
"question_score": 5171,
"tags": "javascript|object|clone",
"answer_id": 122704,
"answer_date": "2008-09-23T18:09:37.277Z",
"answer_score": 5581
} |
Please answer the following Stack Overflow question:
Title: Reset local repository branch to be just like remote repository HEAD
<p>How do I reset my local branch to be just like the branch on the remote repository?</p>
<p>I tried:</p>
<pre><code>git reset --hard HEAD
</code></pre>
<p>But <code>git status</code> clai... | <p>Setting your branch to exactly match the remote branch can be done in two steps:</p>
<pre><code>git fetch origin
git reset --hard origin/master
</code></pre>
<p>If you want to save your current branch's state before doing this (just in case), you can do:</p>
<pre><code>git commit -a -m "Saving my work, just in ... | {
"question_id": 1628088,
"question_date": "2009-10-27T00:27:20.543Z",
"question_score": 5146,
"tags": "git|undo",
"answer_id": 1628334,
"answer_date": "2009-10-27T01:44:30.760Z",
"answer_score": 8868
} |
Please answer the following Stack Overflow question:
Title: What is the difference between "INNER JOIN" and "OUTER JOIN"?
<p>Also, how do <code>LEFT OUTER JOIN</code>, <code>RIGHT OUTER JOIN</code>, and <code>FULL OUTER JOIN</code> fit in?</p> | <p>Assuming you're joining on columns with no duplicates, which is a very common case:</p>
<ul>
<li><p>An inner join of A and B gives the result of A intersect B, i.e. the inner part of a <a href="http://en.wikipedia.org/wiki/Venn_diagram" rel="noreferrer">Venn diagram</a> intersection.</p>
</li>
<li><p>An outer join o... | {
"question_id": 38549,
"question_date": "2008-09-01T22:36:06.940Z",
"question_score": 5108,
"tags": "sql|join|inner-join|outer-join",
"answer_id": 38578,
"answer_date": "2008-09-01T22:59:34.840Z",
"answer_score": 6574
} |
Please answer the following Stack Overflow question:
Title: How to determine the URL that a local Git repository was originally cloned from
<p>I pulled a project with several forks on GitHub, but forgot which fork it was. How do I determine which fork I pulled?</p> | <p>To obtain only the remote URL:</p>
<pre><code>git config --get remote.origin.url
</code></pre>
<p>If you require full output, and you are on a network that can reach the remote repo where the origin resides:</p>
<pre><code>git remote show origin
</code></pre>
<p>When using <code>git clone</code> (from GitHub, or any... | {
"question_id": 4089430,
"question_date": "2010-11-03T16:47:46.247Z",
"question_score": 5063,
"tags": "git|github|git-remote",
"answer_id": 4089452,
"answer_date": "2010-11-03T16:50:16.040Z",
"answer_score": 7046
} |
Please answer the following Stack Overflow question:
Title: How do I check whether a checkbox is checked in jQuery?
<p>I need to check the <code>checked</code> property of a checkbox and perform an action based on the checked property using jQuery.</p>
<p>For example, if the <code>age</code> checkbox is checked, then... | <p>This worked for me:</p>
<pre><code>$get("isAgeSelected ").checked == true
</code></pre>
<p>Where <code>isAgeSelected</code> is the id of the control.</p>
<p>Also, @karim79's <a href="https://stackoverflow.com/questions/901712/check-checkbox-checked-property-using-jquery/901727#901727">answer</a> works fine. I am ... | {
"question_id": 901712,
"question_date": "2009-05-23T15:16:39.917Z",
"question_score": 5054,
"tags": "javascript|jquery|html|checkbox",
"answer_id": 903152,
"answer_date": "2009-05-24T05:30:25.670Z",
"answer_score": 116
} |
Please answer the following Stack Overflow question:
Title: How do I add an empty directory to a Git repository?
<p>How do I add an empty directory (that contains no files) to a Git repository?</p> | <p>Another way to make a directory stay (almost) empty (in the repository) is to create a <code>.gitignore</code> file inside that directory that contains these four lines:</p>
<pre><code># Ignore everything in this directory
*
# Except this file
!.gitignore
</code></pre>
<p>Then you don't have to get the order right... | {
"question_id": 115983,
"question_date": "2008-09-22T16:41:03.660Z",
"question_score": 5046,
"tags": "git|directory|git-add",
"answer_id": 932982,
"answer_date": "2009-05-31T22:10:40.167Z",
"answer_score": 4849
} |
Please answer the following Stack Overflow question:
Title: Regular expression to match a line that doesn't contain a word
<p>I know it's possible to match a word and then reverse the matches using other tools (e.g. <code>grep -v</code>). However, is it possible to match lines that do not contain a specific word, e.g... | <p>The notion that regex doesn't support inverse matching is not entirely true. You can mimic this behavior by using negative look-arounds:</p>
<pre><code>^((?!hede).)*$
</code></pre>
<p>Non-capturing variant:</p>
<pre class="lang-regex prettyprint-override"><code>^(?:(?!:hede).)*$
</code></pre>
<p>The regex above will... | {
"question_id": 406230,
"question_date": "2009-01-02T07:30:16.097Z",
"question_score": 5042,
"tags": "regex|pattern-matching|regex-negation",
"answer_id": 406408,
"answer_date": "2009-01-02T09:55:05.323Z",
"answer_score": 6952
} |
Please answer the following Stack Overflow question:
Title: How do I create a GUID / UUID?
<p>How do I create GUIDs (globally-unique identifiers) in JavaScript? The GUID / UUID should be at least 32 characters and should stay in the ASCII range to avoid trouble when passing them around.</p>
<p>I'm not sure what routi... | <p>UUIDs (Universally Unique IDentifier), also known as GUIDs (Globally Unique IDentifier), according to <a href="https://www.ietf.org/rfc/rfc4122.txt" rel="noreferrer">RFC 4122</a>, are identifiers designed to provide certain uniqueness guarantees.</p>
<p>While it is possible to implement RFC-compliant UUIDs in a few ... | {
"question_id": 105034,
"question_date": "2008-09-19T20:01:00.147Z",
"question_score": 5019,
"tags": "javascript|guid|uuid",
"answer_id": 105074,
"answer_date": "2008-09-19T20:05:25.003Z",
"answer_score": 2593
} |
Please answer the following Stack Overflow question:
Title: How can I horizontally center an element?
<p>How can I horizontally center a <code><div></code> within another <code><div></code> using CSS?</p>
<pre class="lang-html prettyprint-override"><code><div id="outer">
<div id="... | <p>You can apply this CSS to the inner <code><div></code>:</p>
<pre class="lang-css prettyprint-override"><code>#inner {
width: 50%;
margin: 0 auto;
}
</code></pre>
<p>Of course, you don't have to set the <code>width</code> to <code>50%</code>. Any width less than the containing <code><div></code> will ... | {
"question_id": 114543,
"question_date": "2008-09-22T12:27:57.510Z",
"question_score": 4905,
"tags": "html|css|alignment|centering",
"answer_id": 114549,
"answer_date": "2008-09-22T12:29:07.710Z",
"answer_score": 5375
} |
Please answer the following Stack Overflow question:
Title: How do I exit Vim?
<p>I am stuck and cannot escape. It says:</p>
<pre><code>type :quit<Enter> to quit VIM
</code></pre>
<p>But when I type that it simply appears in the object body.</p> | <p>Hit the <kbd>Esc</kbd> key to enter "Normal mode". Then you can type <code>:</code> to enter "Command-line mode". A colon (<code>:</code>) will appear at the bottom of the screen and you can type in one of the following commands. To execute a command, press the <kbd>Enter</kbd> key.</p>
<ul>
<li>... | {
"question_id": 11828270,
"question_date": "2012-08-06T12:25:47.927Z",
"question_score": 4851,
"tags": "vim|vi",
"answer_id": 11828573,
"answer_date": "2012-08-06T12:46:16.327Z",
"answer_score": 5931
} |
Please answer the following Stack Overflow question:
Title: Accessing the index in 'for' loops
<p>How do I access the index while iterating over a sequence with a <code>for</code> loop?</p>
<pre><code>xs = [8, 23, 45]
for x in xs:
print("item #{} = {}".format(index, x))
</code></pre>
<p>Desired output:... | <p>Use the built-in function <a href="https://docs.python.org/3/library/functions.html#enumerate" rel="noreferrer" title="enumerate"><code>enumerate()</code></a>:</p>
<pre><code>for idx, x in enumerate(xs):
print(idx, x)
</code></pre>
<p>It is <em><a href="https://stackoverflow.com/questions/25011078/what-does-pyth... | {
"question_id": 522563,
"question_date": "2009-02-06T22:47:54.433Z",
"question_score": 4845,
"tags": "python|loops|list",
"answer_id": 522578,
"answer_date": "2009-02-06T22:52:36.357Z",
"answer_score": 8044
} |
Please answer the following Stack Overflow question:
Title: How do I make a flat list out of a list of lists?
<p>I have a list of lists like <code>[[1, 2, 3], [4, 5, 6], [7], [8, 9]]</code>. How can I flatten it to get <code>[1, 2, 3, 4, 5, 6, 7, 8, 9]</code>?</p>
<hr />
<p><sub>If your list of lists comes from a nes... | <p>Given a list of lists <code>l</code>,</p>
<pre><code>flat_list = [item for sublist in l for item in sublist]
</code></pre>
<p>which means:</p>
<pre><code>flat_list = []
for sublist in l:
for item in sublist:
flat_list.append(item)
</code></pre>
<p>is faster than the shortcuts posted so far. (<code>l</cod... | {
"question_id": 952914,
"question_date": "2009-06-04T20:30:05.527Z",
"question_score": 4832,
"tags": "python|list|multidimensional-array|flatten",
"answer_id": 952952,
"answer_date": "2009-06-04T20:37:01.207Z",
"answer_score": 6719
} |
Please answer the following Stack Overflow question:
Title: What is the difference between a URI, a URL, and a URN?
<p>What is the difference between a <a href="http://en.wikipedia.org/wiki/Uniform_Resource_Locator" rel="noreferrer"><strong>URL</strong></a>, a <a href="http://en.wikipedia.org/wiki/Uniform_Resource_Id... | <p>From <a href="http://www.ietf.org/rfc/rfc3986.txt" rel="noreferrer">RFC 3986</a>:</p>
<blockquote>
<p>A URI can be further classified as a locator, a name, or both. The
term "Uniform Resource Locator" (URL) refers to the subset of URIs
that, in addition to identifying a resource, provide a means of
locati... | {
"question_id": 176264,
"question_date": "2008-10-06T21:26:58.073Z",
"question_score": 4823,
"tags": "http|url|uri|urn|rfc3986",
"answer_id": 176274,
"answer_date": "2008-10-06T21:29:48.410Z",
"answer_score": 1900
} |
Please answer the following Stack Overflow question:
Title: How do I squash my last N commits together?
<p>How do I squash my last N commits together into one commit?</p> | <p>Use <code>git rebase -i <after-this-commit></code> and replace "pick" on the second and subsequent commits with "squash" or "fixup", as described in <a href="http://git-scm.com/docs/git-rebase#_interactive_mode">the manual</a>.</p>
<p>In this example, <code><after-this-commit></code> is either the SHA1 ... | {
"question_id": 5189560,
"question_date": "2011-03-04T04:11:26.517Z",
"question_score": 4782,
"tags": "git|rebase|squash|git-squash",
"answer_id": 5189600,
"answer_date": "2011-03-04T04:18:49.737Z",
"answer_score": 2749
} |
Please answer the following Stack Overflow question:
Title: How to pass "Null" (a real surname!) to a SOAP web service in ActionScript 3
<p>We have an employee whose surname is Null. Our employee lookup application is killed when that last name is used as the search term (which happens to be quite often now). The err... | <h1> Tracking it down </h1>
<p>At first I thought this was a coercion bug where <code>null</code> was getting coerced to <code>"null"</code> and a test of <code>"null" == null</code> was passing. It's not. <strong>I was close, but so very, very wrong. Sorry about that!</strong></p>
<p>I've since done lots of <a href=... | {
"question_id": 4456438,
"question_date": "2010-12-16T00:42:14.013Z",
"question_score": 4738,
"tags": "apache-flex|actionscript|soap|coldfusion|wsdl",
"answer_id": 18000768,
"answer_date": "2013-08-01T17:31:46.023Z",
"answer_score": 1140
} |
Please answer the following Stack Overflow question:
Title: What's the difference between tilde(~) and caret(^) in package.json?
<p>After I upgraded to the latest stable <code>node</code> and <code>npm</code>, I tried <code>npm install moment --save</code>. It saves the entry in the <code>package.json</code> with the... | <p>See the <a href="https://docs.npmjs.com/cli/v8/configuring-npm/package-json#dependencies" rel="noreferrer">NPM docs</a> and <a href="https://docs.npmjs.com/cli/v6/using-npm/semver" rel="noreferrer">semver docs</a>:</p>
<ul>
<li><p><code>~version</code> <strong>“Approximately equivalent to version”</strong>, will upd... | {
"question_id": 22343224,
"question_date": "2014-03-12T06:02:21.987Z",
"question_score": 4706,
"tags": "node.js|npm|package.json|semantic-versioning",
"answer_id": 22345808,
"answer_date": "2014-03-12T08:28:07.070Z",
"answer_score": 5404
} |
Please answer the following Stack Overflow question:
Title: How do I check if an array includes a value in JavaScript?
<p>What is the most concise and efficient way to find out if a JavaScript array contains a value?</p>
<p>This is the only way I know to do it:</p>
<pre><code>function contains(a, obj) {
for (var ... | <p>Modern browsers have <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes#browser_compatibility" rel="noreferrer"><code>Array#includes</code></a>, which does <em>exactly</em> that and <a href="https://kangax.github.io/compat-table/es2016plus/#test-Array.prototype.i... | {
"question_id": 237104,
"question_date": "2008-10-25T22:14:40.913Z",
"question_score": 4695,
"tags": "javascript|arrays|algorithm|time-complexity|javascript-objects",
"answer_id": 1473742,
"answer_date": "2009-09-24T19:35:24.250Z",
"answer_score": 5157
} |
Please answer the following Stack Overflow question:
Title: Undo a Git merge that hasn't been pushed yet
<p>I accidentally ran <code>git merge some_other_branch</code> on my local master branch. I haven't pushed the changes to origin master. How do I undo the merge?</p>
<hr />
<p>After merging, <code>git status</code... | <p>With <code>git reflog</code> check which commit is one prior the merge (<code>git reflog</code> will be a better option than <code>git log</code>). Then you can reset it using:</p>
<pre><code>git reset --hard commit_sha
</code></pre>
<p>There's also another way:</p>
<pre><code>git reset --hard HEAD~1
</code></pre... | {
"question_id": 2389361,
"question_date": "2010-03-05T19:24:44.700Z",
"question_score": 4657,
"tags": "git|undo|git-merge",
"answer_id": 2389423,
"answer_date": "2010-03-05T19:34:01.440Z",
"answer_score": 5293
} |
Please answer the following Stack Overflow question:
Title: How do I clone all remote branches?
<p>My <code>master</code> and <code>development</code> branches are tracked remotely on <a href="http://en.wikipedia.org/wiki/GitHub" rel="noreferrer">GitHub</a>. How do I clone both these branches?</p> | <p>First, clone a remote <a href="http://en.wikipedia.org/wiki/Git_%28software%29" rel="noreferrer">Git</a> repository and <a href="http://en.wikipedia.org/wiki/Cd_%28command%29" rel="noreferrer"><code>cd</code></a> into it:</p>
<pre><code>$ git clone git://example.com/myproject
$ cd myproject
</code></pre>
<p>Next, lo... | {
"question_id": 67699,
"question_date": "2008-09-15T22:42:07.430Z",
"question_score": 4608,
"tags": "git|git-branch|git-clone|remote-branch",
"answer_id": 72156,
"answer_date": "2008-09-16T13:28:22.230Z",
"answer_score": 5031
} |
Please answer the following Stack Overflow question:
Title: How do I get a timestamp in JavaScript?
<p>I want a single number that represents the current date and time, like a <a href="https://en.wikipedia.org/wiki/Unix_time" rel="noreferrer">Unix timestamp</a>.</p> | <h3>Timestamp in milliseconds</h3>
<p>To get the number of milliseconds since <a href="https://en.wikipedia.org/wiki/Unix_time" rel="noreferrer">Unix epoch</a>, call <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now" rel="noreferrer"><code>Date.now</code></a>:</p>
<pre><... | {
"question_id": 221294,
"question_date": "2008-10-21T09:29:33.367Z",
"question_score": 4597,
"tags": "javascript|datetime|timestamp|date-arithmetic",
"answer_id": 221297,
"answer_date": "2008-10-21T09:32:32.487Z",
"answer_score": 5712
} |
Please answer the following Stack Overflow question:
Title: How do I read / convert an InputStream into a String in Java?
<p>If you have a <code>java.io.InputStream</code> object, how should you process that object and produce a <code>String</code>?</p>
<hr />
<p>Suppose I have an <code>InputStream</code> that contai... | <p>A nice way to do this is using <a href="http://commons.apache.org/" rel="noreferrer">Apache commons</a> <code><a href="https://commons.apache.org/proper/commons-io/javadocs/api-release/org/apache/commons/io/IOUtils.html" rel="noreferrer">IOUtils</a></code> to copy the <code>InputStream</code> into a <code>StringWrit... | {
"question_id": 309424,
"question_date": "2008-11-21T16:47:40.287Z",
"question_score": 4560,
"tags": "java|string|io|stream|inputstream",
"answer_id": 309448,
"answer_date": "2008-11-21T16:54:20.960Z",
"answer_score": 2733
} |
Please answer the following Stack Overflow question:
Title: Setting "checked" for a checkbox with jQuery
<p>I'd like to do something like this to tick a <code>checkbox</code> using <strong>jQuery</strong>:</p>
<pre><code>$(".myCheckBox").checked(true);
</code></pre>
<p>or</p>
<pre><code>$(".myCheckBox").selected(t... | <h2>Modern jQuery</h2>
<p>Use <a href="https://api.jquery.com/prop" rel="noreferrer"><code>.prop()</code></a>:</p>
<pre><code>$('.myCheckbox').prop('checked', true);
$('.myCheckbox').prop('checked', false);
</code></pre>
<h2>DOM API</h2>
<p>If you're working with just one element, you can always just access the und... | {
"question_id": 426258,
"question_date": "2009-01-08T22:20:24.913Z",
"question_score": 4479,
"tags": "javascript|jquery|checkbox|selected|checked",
"answer_id": 426276,
"answer_date": "2009-01-08T22:25:08.447Z",
"answer_score": 6338
} |
Please answer the following Stack Overflow question:
Title: How do I update or sync a forked repository on GitHub?
<p>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?</p> | <p>In your local clone of your forked repository, you can add the original GitHub repository as a "remote". ("Remotes" are like nicknames for the URLs of repositories - <code>origin</code> is one, for example.) Then you can fetch all the branches from that upstream repository, and rebase your work... | {
"question_id": 7244321,
"question_date": "2011-08-30T13:53:00.447Z",
"question_score": 4477,
"tags": "git|github|synchronization|repository|git-fork",
"answer_id": 7244456,
"answer_date": "2011-08-30T14:01:26.267Z",
"answer_score": 5098
} |
Please answer the following Stack Overflow question:
Title: How do I delete a remote tag?
<p>How do I delete a Git tag that has already been pushed?</p> | <p>You can push an 'empty' reference to the remote tag name:</p>
<pre><code>git push origin :tagname
</code></pre>
<p>Or, more expressively, use the <code>--delete</code> option (or <code>-d</code> if your git version is older than 1.8.0):</p>
<pre><code>git push --delete origin tagname
</code></pre>
<p>Note that git h... | {
"question_id": 5480258,
"question_date": "2011-03-29T23:41:56.757Z",
"question_score": 4418,
"tags": "git|git-tag",
"answer_id": 5480292,
"answer_date": "2011-03-29T23:45:58.983Z",
"answer_score": 7282
} |
Please answer the following Stack Overflow question:
Title: Difference between @staticmethod and @classmethod
<p>What is the difference between a function decorated with <a href="http://docs.python.org/library/functions.html#staticmethod" rel="noreferrer"><code>@staticmethod</code></a> and one decorated with <a href=... | <p>Maybe a bit of example code will help: Notice the difference in the call signatures of <code>foo</code>, <code>class_foo</code> and <code>static_foo</code>:</p>
<pre><code>class A(object):
def foo(self, x):
print(f"executing foo({self}, {x})")
@classmethod
def class_foo(cls, x):
... | {
"question_id": 136097,
"question_date": "2008-09-25T21:01:57.843Z",
"question_score": 4397,
"tags": "python|oop|methods|python-decorators",
"answer_id": 1669524,
"answer_date": "2009-11-03T19:13:48.353Z",
"answer_score": 3735
} |
Please answer the following Stack Overflow question:
Title: Why does Google prepend while(1); to their JSON responses?
<p>Why does Google prepend <code>while(1);</code> to their (private) JSON responses?</p>
<p>For example, here's a response while turning a calendar on and off in <a href="https://calendar.google.com... | <p>It prevents <a href="http://haacked.com/archive/2009/06/25/json-hijacking.aspx" rel="noreferrer">JSON hijacking</a>, a major JSON security issue that is formally <a href="https://security.stackexchange.com/questions/155518/why-json-hijacking-attack-doesnt-work-in-modern-browsers-how-was-it-fixed">fixed</a> in all ma... | {
"question_id": 2669690,
"question_date": "2010-04-19T18:00:09.750Z",
"question_score": 4376,
"tags": "javascript|json|ajax|security",
"answer_id": 2669766,
"answer_date": "2010-04-19T18:11:41.890Z",
"answer_score": 4515
} |
Please answer the following Stack Overflow question:
Title: Understanding slicing
<p>I need a good explanation (references are a plus) on Python slicing.</p> | <p>The syntax is:</p>
<pre><code>a[start:stop] # items start through stop-1
a[start:] # items start through the rest of the array
a[:stop] # items from the beginning through stop-1
a[:] # a copy of the whole array
</code></pre>
<p>There is also the <code>step</code> value, which can be used with a... | {
"question_id": 509211,
"question_date": "2009-02-03T22:31:02.787Z",
"question_score": 4336,
"tags": "python|slice|sequence",
"answer_id": 509295,
"answer_date": "2009-02-03T22:48:24.687Z",
"answer_score": 6143
} |
Please answer the following Stack Overflow question:
Title: Avoiding NullPointerException in Java
<p>I use <code>x != null</code> to avoid <a href="https://docs.oracle.com/javase/9/docs/api/java/lang/NullPointerException.html" rel="noreferrer"><code>NullPointerException</code></a>. Is there an alternative?</p>
<pre c... | <p>This to me sounds like a reasonably common problem that junior to intermediate developers tend to face at some point: they either don't know or don't trust the contracts they are participating in and defensively overcheck for nulls. Additionally, when writing their own code, they tend to rely on returning nulls to ... | {
"question_id": 271526,
"question_date": "2008-11-07T08:31:40.203Z",
"question_score": 4315,
"tags": "java|nullpointerexception|null",
"answer_id": 271874,
"answer_date": "2008-11-07T12:06:40.507Z",
"answer_score": 2804
} |
Please answer the following Stack Overflow question:
Title: Change a HTML5 input's placeholder color with CSS
<p>Chrome supports the <a href="http://www.w3.org/html/wg/drafts/html/master/single-page.html#the-placeholder-attribute" rel="noreferrer" title="The placeholder attribute">placeholder attribute</a> on <code>i... | <h2>Implementation</h2>
<p>There are three different implementations: pseudo-elements, pseudo-classes, and nothing.</p>
<ul>
<li>WebKit, Blink (Safari, Google Chrome, Opera 15+) and Microsoft Edge are using a pseudo-element: <code>::-webkit-input-placeholder</code>. <sup>[<a href="https://bugs.webkit.org/show_bug.cgi?i... | {
"question_id": 2610497,
"question_date": "2010-04-09T19:54:53.263Z",
"question_score": 4278,
"tags": "css|html|placeholder|html-input",
"answer_id": 2610741,
"answer_date": "2010-04-09T20:36:56.707Z",
"answer_score": 5052
} |
Please answer the following Stack Overflow question:
Title: How is Docker different from a virtual machine?
<p>I keep rereading <a href="https://docs.docker.com/" rel="noreferrer">the Docker documentation</a> to try to understand the difference between Docker and a full VM. How does it manage to provide a full filesy... | <p>Docker originally used <a href="https://linuxcontainers.org/lxc/" rel="noreferrer">LinuX Containers</a> (LXC), but later switched to <a href="https://github.com/opencontainers/runc" rel="noreferrer">runC</a> (formerly known as <strong>libcontainer</strong>), which runs in the same operating system as its host. This ... | {
"question_id": 16047306,
"question_date": "2013-04-16T21:19:47.263Z",
"question_score": 4245,
"tags": "docker|virtual-machine",
"answer_id": 16048358,
"answer_date": "2013-04-16T22:35:27.317Z",
"answer_score": 3852
} |
Please answer the following Stack Overflow question:
Title: How to close/hide the Android soft keyboard programmatically?
<p>I have an <code>EditText</code> and a <code>Button</code> in my layout.</p>
<p>After writing in the edit field and clicking on the <code>Button</code>, I want to hide the virtual keyboard when ... | <p>To help clarify this madness, I'd like to begin by apologizing on behalf of all Android users for Google's downright ridiculous treatment of the soft keyboard. The reason there are so many answers, each different, for the same simple question is that this API, like many others in Android, is horribly designed. I can... | {
"question_id": 1109022,
"question_date": "2009-07-10T11:27:17.090Z",
"question_score": 4238,
"tags": "android|android-edittext|android-softkeyboard|android-input-method|soft-keyboard",
"answer_id": 17789187,
"answer_date": "2013-07-22T13:44:29.240Z",
"answer_score": 2493
} |
Please answer the following Stack Overflow question:
Title: How to enumerate an enum
<p>How can you enumerate an <code>enum</code> in C#?</p>
<p>E.g. the following code does not compile:</p>
<pre class="lang-cs prettyprint-override"><code>public enum Suit
{
Spades,
Hearts,
Clubs,
Diamonds
}
public ... | <pre><code>foreach (Suit suit in (Suit[]) Enum.GetValues(typeof(Suit)))
{
}
</code></pre>
<p><strong>Note</strong>: The cast to <code>(Suit[])</code> is not strictly necessary, <a href="https://gist.github.com/bartoszkp/9e059c3edccc07a5e588#gistcomment-2625454" rel="noreferrer">but it does make the code 0.5 ns faster<... | {
"question_id": 105372,
"question_date": "2008-09-19T20:34:50.797Z",
"question_score": 4236,
"tags": "c#|.net|loops|enums|enumeration",
"answer_id": 105402,
"answer_date": "2008-09-19T20:37:18.187Z",
"answer_score": 5136
} |
Please answer the following Stack Overflow question:
Title: How do I copy to the clipboard in JavaScript?
<p>How do I copy text to the clipboard (multi-browser)?</p>
<p>Related: <em><a href="https://stackoverflow.com/questions/17527870/how-does-trello-access-the-users-clipboard">How does Trello access the user's ... | <h1>Overview</h1>
<p>There are three primary browser APIs for copying to the clipboard:</p>
<ol>
<li><p><a href="https://www.w3.org/TR/clipboard-apis/#async-clipboard-api" rel="noreferrer">Async Clipboard API</a> <code>[navigator.clipboard.writeText]</code></p>
<ul>
<li>Text-focused portion available in <a href="https:... | {
"question_id": 400212,
"question_date": "2008-12-30T13:09:05.777Z",
"question_score": 4218,
"tags": "javascript|clipboard|copy-paste",
"answer_id": 30810322,
"answer_date": "2015-06-12T18:56:18.323Z",
"answer_score": 3187
} |
Please answer the following Stack Overflow question:
Title: How do I check if a directory exists in a Bash shell script?
<p>What command checks if a directory exists or not within a Bash shell script?</p> | <p>To check if a directory exists:</p>
<pre><code>if [ -d "$DIRECTORY" ]; then
echo "$DIRECTORY does exist."
fi
</code></pre>
<p>To check if a directory does not exist:</p>
<pre><code>if [ ! -d "$DIRECTORY" ]; then
echo "$DIRECTORY does not exist."
fi
</code></pre>
<hr />
<p>... | {
"question_id": 59838,
"question_date": "2008-09-12T20:06:25.757Z",
"question_score": 4207,
"tags": "bash|shell|unix|posix",
"answer_id": 59839,
"answer_date": "2008-09-12T20:07:06.113Z",
"answer_score": 5666
} |
Please answer the following Stack Overflow question:
Title: How do I remove a submodule?
<p>How do I remove a Git submodule?
Why can't I do
<code>git submodule rm module_name</code>?</p> | <p>Since <a href="https://github.com/git/git/blob/v1.8.3-rc0/Documentation/RelNotes/1.8.3.txt#L135-L137" rel="noreferrer">git1.8.3 (April 22d, 2013)</a>:</p>
<blockquote>
<p>There was no Porcelain way to say "I no longer am interested in this submodule", once you express your interest in a submodule with &quo... | {
"question_id": 1260748,
"question_date": "2009-08-11T14:31:24.183Z",
"question_score": 4194,
"tags": "git|git-submodules",
"answer_id": 16162000,
"answer_date": "2013-04-23T05:57:49.983Z",
"answer_score": 2585
} |
Please answer the following Stack Overflow question:
Title: What are the differences between a HashMap and a Hashtable in Java?
<p>What are the differences between a <a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/HashMap.html" rel="noreferrer"><code>HashMap</code></a> and a <a href="h... | <p>There are several differences between <a href="http://java.sun.com/javase/7/docs/api/java/util/HashMap.html" rel="noreferrer"><code>HashMap</code></a> and <a href="http://java.sun.com/javase/7/docs/api/java/util/Hashtable.html" rel="noreferrer"><code>Hashtable</code></a> in Java:</p>
<ol>
<li><p><code>Hashtable</co... | {
"question_id": 40471,
"question_date": "2008-09-02T20:12:00.117Z",
"question_score": 4191,
"tags": "java|collections|hashmap|hashtable",
"answer_id": 40878,
"answer_date": "2008-09-02T23:02:37.180Z",
"answer_score": 4141
} |
Please answer the following Stack Overflow question:
Title: Finding the index of an item in a list
<p>Given a list <code>["foo", "bar", "baz"]</code> and an item in the list <code>"bar"</code>, how do I get its index <code>1</code>?</p> | <pre><code>>>> ["foo", "bar", "baz"].index("bar")
1
</code></pre>
<p>Reference: <a href="https://docs.python.org/tutorial/datastructures.html#more-on-lists" rel="noreferrer">Data Structures > More on Lists</a></p>
<h1>Caveats follow</h1>
<p>Note that while this is per... | {
"question_id": 176918,
"question_date": "2008-10-07T01:39:38.437Z",
"question_score": 4141,
"tags": "python|list|indexing",
"answer_id": 176921,
"answer_date": "2008-10-07T01:40:49.213Z",
"answer_score": 5671
} |
Please answer the following Stack Overflow question:
Title: What is RESTful programming?
<p>What exactly is <a href="https://en.wikipedia.org/wiki/Representational_state_transfer" rel="noreferrer">RESTful programming</a>?</p> | <p>An <strong>architectural style</strong> called <a href="https://en.wikipedia.org/wiki/Representational_state_transfer" rel="noreferrer"><strong>REST (Representational State Transfer)</strong></a> advocates that web applications should use HTTP as it was <strong>originally envisioned</strong>. Lookups should use <a h... | {
"question_id": 671118,
"question_date": "2009-03-22T14:45:39.317Z",
"question_score": 4139,
"tags": "rest|http|architecture|definition",
"answer_id": 29648972,
"answer_date": "2015-04-15T11:26:17.950Z",
"answer_score": 806
} |
Please answer the following Stack Overflow question:
Title: How can I pair socks from a pile efficiently?
<p>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 to fi... | <p>Sorting solutions have been proposed, but <strong>sorting is a little too much</strong>: We don't need order; <strong>we just need equality groups</strong>.</p>
<p>So <strong>hashing</strong> would be enough (and faster).</p>
<ol>
<li>For each color of socks, <strong>form a pile</strong>. Iterate over all socks in... | {
"question_id": 14415881,
"question_date": "2013-01-19T15:34:35.667Z",
"question_score": 4122,
"tags": "algorithm|sorting|language-agnostic|matching",
"answer_id": 14419556,
"answer_date": "2013-01-19T22:27:57.507Z",
"answer_score": 2553
} |
Please answer the following Stack Overflow question:
Title: How do I UPDATE from a SELECT in SQL Server?
<p>In <strong>SQL Server</strong>, it is possible to insert rows into a table with an <code>INSERT.. SELECT</code> statement:</p>
<pre><code>INSERT INTO Table (col1, col2, col3)
SELECT col1, col2, col3
FROM other... | <pre><code>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'
</code></pre> | {
"question_id": 2334712,
"question_date": "2010-02-25T14:36:53.113Z",
"question_score": 4114,
"tags": "sql|sql-server|tsql|select|sql-update",
"answer_id": 2334741,
"answer_date": "2010-02-25T14:39:55.367Z",
"answer_score": 5851
} |
Please answer the following Stack Overflow question:
Title: Iterating over dictionaries using 'for' loops
<pre><code>d = {'x': 1, 'y': 2, 'z': 3}
for key in d:
print(key, 'corresponds to', d[key])
</code></pre>
<p>How does Python recognize that it needs only to read the <code>key</code> from the dictionary? Is <... | <p><code>key</code> is just a variable name. </p>
<pre><code>for key in d:
</code></pre>
<p>will simply loop over the keys in the dictionary, rather than the keys and values. To loop over both key and value you can use the following:</p>
<p>For Python 3.x:</p>
<pre><code>for key, value in d.items():
</code></pre>... | {
"question_id": 3294889,
"question_date": "2010-07-20T22:27:42.460Z",
"question_score": 4000,
"tags": "python|dictionary",
"answer_id": 3294899,
"answer_date": "2010-07-20T22:29:33.213Z",
"answer_score": 6490
} |
Please answer the following Stack Overflow question:
Title: Create ArrayList from array
<p>Given an array of type <code>Element[]</code>:</p>
<pre><code>Element[] array = {new Element(1), new Element(2), new Element(3)};
</code></pre>
<p>How do I convert this array into an object of type <a href="https://docs.oracle.... | <pre><code>new ArrayList<>(Arrays.asList(array));
</code></pre> | {
"question_id": 157944,
"question_date": "2008-10-01T14:38:32.667Z",
"question_score": 3994,
"tags": "java|arrays|arraylist|type-conversion",
"answer_id": 157950,
"answer_date": "2008-10-01T14:39:12.010Z",
"answer_score": 4998
} |
Please answer the following Stack Overflow question:
Title: grep: show lines surrounding each match
<p>How do I <code>grep</code> and show the preceding and following 5 lines surrounding each matched line?</p> | <p>For <strong>BSD</strong> or <strong>GNU</strong> <code>grep</code> you can use <code>-B num</code> to set how many lines before the match and <code>-A num</code> for the number of lines after the match.</p>
<pre><code>grep -B 3 -A 2 foo README.txt
</code></pre>
<p>If you want the same number of lines before and af... | {
"question_id": 9081,
"question_date": "2008-08-12T17:55:32.813Z",
"question_score": 3973,
"tags": "search|logging|grep|command-line-interface",
"answer_id": 9083,
"answer_date": "2008-08-12T17:57:43.307Z",
"answer_score": 5233
} |
Please answer the following Stack Overflow question:
Title: How do I delete a commit from a branch?
<p>How do I delete a commit from my branch history?
Should I use <code>git reset --hard HEAD</code>?</p> | <p><strong>Careful:</strong> <code>git reset --hard</code> <em>WILL DELETE YOUR WORKING DIRECTORY CHANGES</em>. Be sure to <strong>stash any local changes you want to keep</strong> before running this command.</p>
<p>Assuming you are sitting on that commit, then this command will wack it...</p>
<pre><code>git reset -... | {
"question_id": 1338728,
"question_date": "2009-08-27T03:39:50.927Z",
"question_score": 3972,
"tags": "git|git-rebase|git-reset",
"answer_id": 1338744,
"answer_date": "2009-08-27T03:44:04.727Z",
"answer_score": 5075
} |
Please answer the following Stack Overflow question:
Title: Undoing a git rebase
<p>How do I easily undo a git rebase? A lengthy manual method is:</p>
<ol>
<li>checkout the commit parent to both of the branches</li>
<li>create and checkout a temporary branch</li>
<li>cherry-pick all commits by hand</li>
<li>reset the... | <p>The easiest way would be to find the head commit of the branch as it was immediately before the rebase started in the <a href="https://git-scm.com/docs/git-reflog" rel="noreferrer">reflog</a>...</p>
<pre><code>git reflog
</code></pre>
<p>and to reset the current branch to it (with the usual caveats about being absol... | {
"question_id": 134882,
"question_date": "2008-09-25T17:59:22.230Z",
"question_score": 3944,
"tags": "git|rebase|git-rebase|undo",
"answer_id": 135614,
"answer_date": "2008-09-25T19:56:28.343Z",
"answer_score": 5435
} |
Please answer the following Stack Overflow question:
Title: What is the !! (not not) operator in JavaScript?
<p>I saw some code that seems to use an operator I don't recognize, in the form of two exclamation points, like so: <code>!!</code>. Can someone please tell me what this operator does?</p>
<p>The context in w... | <p>It converts <code>Object</code> to <code>boolean</code>. If it was falsey (e.g., <code>0</code>, <code>null</code>, <code>undefined</code>, etc.), it would be <code>false</code>, otherwise, <code>true</code>.</p>
<pre><code>!object // Inverted Boolean
!!object // Noninverted Boolean, so true Boolean representation
... | {
"question_id": 784929,
"question_date": "2009-04-24T08:13:58.470Z",
"question_score": 3935,
"tags": "javascript|operators",
"answer_id": 784946,
"answer_date": "2009-04-24T08:18:07.963Z",
"answer_score": 3509
} |
Please answer the following Stack Overflow question:
Title: Proper use cases for Android UserManager.isUserAGoat()?
<p>I was looking at the new APIs introduced in <a href="http://en.wikipedia.org/wiki/Android_version_history#Android_4.1.2F4.2_Jelly_Bean" rel="noreferrer">Android 4.2</a>.
While looking at the <a href=... | <h3>Android R Update:</h3>
<p>From Android R, this method always returns false. Google says that this is done "to protect goat privacy":</p>
<pre><code>/**
* Used to determine whether the user making this call is subject to
* teleportations.
*
* <p>As of {@link android.os.Build.VERSION_CODES#LOLLIPO... | {
"question_id": 13375357,
"question_date": "2012-11-14T08:34:01.523Z",
"question_score": 3935,
"tags": "java|android|usermanager",
"answer_id": 13375461,
"answer_date": "2012-11-14T08:40:30.647Z",
"answer_score": 1953
} |
Please answer the following Stack Overflow question:
Title: How can I validate an email address using a regular expression?
<p>Over the years I have slowly developed a <a href="http://en.wikipedia.org/wiki/Regular_expression" rel="noreferrer">regular expression</a> that validates <em>most</em> email addresses correct... | <p>The <a href="http://ex-parrot.com/%7Epdw/Mail-RFC822-Address.html" rel="noreferrer">fully RFC 822 compliant regex</a> is inefficient and obscure because of its length. Fortunately, RFC 822 was superseded twice and the current specification for email addresses is <a href="https://datatracker.ietf.org/doc/html/rfc532... | {
"question_id": 201323,
"question_date": "2008-10-14T14:14:34.980Z",
"question_score": 3929,
"tags": "regex",
"answer_id": 201378,
"answer_date": "2008-10-14T14:26:43.723Z",
"answer_score": 3118
} |
Please answer the following Stack Overflow question:
Title: How to insert an item into an array at a specific index (JavaScript)
<p>I am looking for a JavaScript array insert method, in the style of:</p>
<pre><code>arr.insert(index, item)
</code></pre>
<p>Preferably in jQuery, but any JavaScript implementation will d... | <p>You want the <strong><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice" rel="noreferrer"><code>splice</code></a></strong> function on the native array object.</p>
<p><code>arr.splice(index, 0, item);</code> will insert <code>item</code> into <code>arr</code> at th... | {
"question_id": 586182,
"question_date": "2009-02-25T14:29:30.877Z",
"question_score": 3923,
"tags": "javascript|arrays",
"answer_id": 586189,
"answer_date": "2009-02-25T14:32:56.157Z",
"answer_score": 6284
} |
Please answer the following Stack Overflow question:
Title: How do I test for an empty JavaScript object?
<p>After an AJAX request, sometimes my application may return an empty object, like:</p>
<pre><code>var a = {};
</code></pre>
<p>How can I check whether that's the case?</p> | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys#Browser_compatibility" rel="noreferrer">ECMA 5+</a>:</p>
<pre><code>// because Object.keys(new Date()).length === 0;
// we have to do some additional check
obj // null and undefined check
&& Object.keys(obj... | {
"question_id": 679915,
"question_date": "2009-03-25T01:39:45.860Z",
"question_score": 3894,
"tags": "javascript|javascript-objects",
"answer_id": 32108184,
"answer_date": "2015-08-20T01:32:52.957Z",
"answer_score": 7213
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.