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
} |
End of preview. Expand in Data Studio
No dataset card yet
- Downloads last month
- 8