input_text
stringlengths 115
13.8k
| output_text
stringlengths 24
15k
| metadata
dict |
---|---|---|
Please answer the following Stack Overflow question:
Title: Git: What's the best practice to "git clone" into an existing folder?
<p>I have a working copy of the project, without any source control meta data. Now, I'd like to do the equivalent of git-clone into this folder, and keep my local changes.</p>
<p>git-clone doesn't allow me to clone into an existing folder. What is the best practice here?</p> | <p>This can be done by cloning to a new directory, then moving the <code>.git</code> directory into your existing directory.</p>
<p>If your existing directory is named "code".</p>
<pre><code>git clone https://myrepo.com/git.git temp
mv temp/.git code/.git
rm -rf temp
</code></pre>
<p>This can also be done without doing a checkout during the clone command; more information can be found <a href="https://stackoverflow.com/questions/2411031/git-how-do-i-clone-into-a-non-empty-directory">here</a>.</p> | {
"question_id": 5377960,
"question_date": "2011-03-21T13:04:52.757Z",
"question_score": 632,
"tags": "git",
"answer_id": 13852329,
"answer_date": "2012-12-13T03:11:45.480Z",
"answer_score": 735
} |
Please answer the following Stack Overflow question:
Title: jQuery selector regular expressions
<p>I am after documentation on using wildcard or regular expressions (not sure on the exact terminology) with a jQuery selector.</p>
<p>I have looked for this myself but have been unable to find information on the syntax and how to use it. Does anyone know where the documentation for the syntax is?</p>
<p>EDIT: The attribute filters allow you to select based on patterns of an attribute value.</p> | <p>James Padolsey created a <a href="http://james.padolsey.com/javascript/regex-selector-for-jquery/" rel="noreferrer">wonderful filter</a> that allows regex to be used for selection.</p>
<p>Say you have the following <code>div</code>:</p>
<pre><code><div class="asdf">
</code></pre>
<p>Padolsey's <code>:regex</code> filter can select it like so:</p>
<pre><code>$("div:regex(class, .*sd.*)")
</code></pre>
<p>Also, check the <a href="http://docs.jquery.com/Selectors" rel="noreferrer">official documentation on selectors</a>.</p>
<h2>UPDATE: <code>:</code> syntax Deprecation JQuery 3.0</h2>
<p>Since <code>jQuery.expr[':']</code> used in Padolsey's implementation is already deprecated and will render a syntax error in the latest version of jQuery, here is his code adapted to jQuery 3+ syntax:</p>
<pre class="lang-js prettyprint-override"><code>jQuery.expr.pseudos.regex = jQuery.expr.createPseudo(function (expression) {
return function (elem) {
var matchParams = expression.split(','),
validLabels = /^(data|css):/,
attr = {
method: matchParams[0].match(validLabels) ?
matchParams[0].split(':')[0] : 'attr',
property: matchParams.shift().replace(validLabels, '')
},
regexFlags = 'ig',
regex = new RegExp(matchParams.join('').replace(/^\s+|\s+$/g, ''), regexFlags);
return regex.test(jQuery(elem)[attr.method](attr.property));
}
});
</code></pre> | {
"question_id": 190253,
"question_date": "2008-10-10T05:40:48.353Z",
"question_score": 632,
"tags": "javascript|jquery|regex|jquery-selectors",
"answer_id": 190255,
"answer_date": "2008-10-10T05:41:58.557Z",
"answer_score": 355
} |
Please answer the following Stack Overflow question:
Title: Hide keyboard in react-native
<p>If I tap onto a textinput, I want to be able to tap somewhere else in order to dismiss the keyboard again (not the return key though). I haven't found the slightest piece of information concerning this in all the tutorials and blog posts that I read.</p>
<p>This basic example is still not working for me with react-native 0.4.2 in the Simulator. Couldn't try it on my iPhone yet.</p>
<pre class="lang-js prettyprint-override"><code><View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Text style={styles.instructions}>
To get started, edit index.ios.js
</Text>
<Text style={styles.instructions}>
Press Cmd+R to reload,{'\n'}
Cmd+D or shake for dev menu
</Text>
<TextInput
style={{height: 40, borderColor: 'gray', borderWidth: 1}}
onEndEditing={this.clearFocus}
/>
</View>
</code></pre> | <p>The problem with keyboard not dismissing gets more severe if you have <code>keyboardType='numeric'</code>, as there is no way to dismiss it.</p>
<p>Replacing View with ScrollView is not a correct solution, as if you have multiple <code>textInput</code>s or <code>button</code>s, tapping on them while the keyboard is up will only dismiss the keyboard.</p>
<p>Correct way is to encapsulate View with <code>TouchableWithoutFeedback</code> and calling <code>Keyboard.dismiss()</code></p>
<p>EDIT: You can now use <code>ScrollView</code> with <code>keyboardShouldPersistTaps='handled'</code> to only dismiss the keyboard when the tap is not handled by the children (ie. tapping on other textInputs or buttons)</p>
<p>If you have</p>
<pre class="lang-js prettyprint-override"><code><View style={{flex: 1}}>
<TextInput keyboardType='numeric'/>
</View>
</code></pre>
<p>Change it to</p>
<pre class="lang-js prettyprint-override"><code><ScrollView contentContainerStyle={{flexGrow: 1}}
keyboardShouldPersistTaps='handled'
>
<TextInput keyboardType='numeric'/>
</ScrollView>
</code></pre>
<p>or</p>
<pre class="lang-js prettyprint-override"><code>import {Keyboard} from 'react-native'
<TouchableWithoutFeedback onPress={Keyboard.dismiss} accessible={false}>
<View style={{flex: 1}}>
<TextInput keyboardType='numeric'/>
</View>
</TouchableWithoutFeedback>
</code></pre>
<p>EDIT: You can also create a Higher Order Component to dismiss the keyboard.</p>
<pre class="lang-js prettyprint-override"><code>import React from 'react';
import { TouchableWithoutFeedback, Keyboard, View } from 'react-native';
const DismissKeyboardHOC = (Comp) => {
return ({ children, ...props }) => (
<TouchableWithoutFeedback onPress={Keyboard.dismiss} accessible={false}>
<Comp {...props}>
{children}
</Comp>
</TouchableWithoutFeedback>
);
};
const DismissKeyboardView = DismissKeyboardHOC(View)
</code></pre>
<p>Simply use it like this</p>
<pre class="lang-js prettyprint-override"><code>...
render() {
<DismissKeyboardView>
<TextInput keyboardType='numeric'/>
</DismissKeyboardView>
}
</code></pre>
<p>NOTE: the <code>accessible={false}</code> is required to make the input form continue to be accessible through VoiceOver. Visually impaired people will thank you!</p> | {
"question_id": 29685421,
"question_date": "2015-04-16T20:33:33.987Z",
"question_score": 632,
"tags": "reactjs|react-native",
"answer_id": 34779467,
"answer_date": "2016-01-14T00:09:05.847Z",
"answer_score": 794
} |
Please answer the following Stack Overflow question:
Title: Should I use <i> tag for icons instead of <span>?
<p>Facebook's HTML and Twitter Bootstrap HTML (before v3) both use the <code><i></code> tag to display icons.</p>
<p>However, from the <a href="http://www.w3.org/International/questions/qa-b-and-I-tags/" rel="noreferrer">HTML5 spec</a>:</p>
<blockquote>
<p>The I element represents a span of text in an alternate voice or mood,
or otherwise offset from the normal prose, such as a taxonomic
designation, a technical term, an idiomatic phrase from another
language, a thought, a ship name, or some other prose whose typical
typographic presentation is italicized.</p>
</blockquote>
<p>Why are they using <code><i></code> tag to display icons? Isn't it a bad practice? Or am I missing something here?</p>
<p>I am using <code>span</code> to display icons and it seems to be working for me until now.</p>
<p><strong>Update:</strong></p>
<p>Bootstrap 3 uses <code>span</code> for icons. <a href="https://getbootstrap.com/docs/3.4/components/#glyphicons-how-to-use" rel="noreferrer">Official Doc</a>.</p>
<p>Bootstrap 5 is back to <code>i</code> <a href="https://icons.getbootstrap.com/#usage" rel="noreferrer">Official doc</a></p> | <blockquote>
<p>Why are they using <code><i></code> tag to display icons ?</p>
</blockquote>
<p>Because it is:</p>
<ul>
<li>Short</li>
<li>i stands for icon (although not in HTML)</li>
</ul>
<blockquote>
<p>Is it not a bad practice ?</p>
</blockquote>
<p>Awful practice. It is a triumph of performance over semantics.</p> | {
"question_id": 11135261,
"question_date": "2012-06-21T09:27:38.843Z",
"question_score": 632,
"tags": "html|semantic-markup",
"answer_id": 11135302,
"answer_date": "2012-06-21T09:29:51.030Z",
"answer_score": 654
} |
Please answer the following Stack Overflow question:
Title: Why are exclamation marks used in Ruby methods?
<p>In Ruby some methods have a question mark (<code>?</code>) that ask a question like <code>include?</code> that ask if the object in question is included, this then returns a true/false.</p>
<p>But why do some methods have exclamation marks (<code>!</code>) where others don't?</p>
<p>What does it mean?</p> | <p>In general, methods that end in <code>!</code> indicate that the method will <strong>modify the object it's called on</strong>. Ruby calls these as "<strong>dangerous methods</strong>" because they change state that someone else might have a reference to. Here's a simple example for strings:</p>
<pre><code>foo = "A STRING" # a string called foo
foo.downcase! # modifies foo itself
puts foo # prints modified foo
</code></pre>
<p>This will output:</p>
<pre><code>a string
</code></pre>
<p>In the standard libraries, there are a lot of places you'll see pairs of similarly named methods, one with the <code>!</code> and one without. The ones without are called "safe methods", and they return a copy of the original with changes applied to <strong>the copy</strong>, with the callee unchanged. Here's the same example without the <code>!</code>:</p>
<pre><code>foo = "A STRING" # a string called foo
bar = foo.downcase # doesn't modify foo; returns a modified string
puts foo # prints unchanged foo
puts bar # prints newly created bar
</code></pre>
<p>This outputs:</p>
<pre><code>A STRING
a string
</code></pre>
<p>Keep in mind this is just a convention, but a lot of Ruby classes follow it. It also helps you keep track of what's getting modified in your code.</p> | {
"question_id": 612189,
"question_date": "2009-03-04T20:02:28.443Z",
"question_score": 632,
"tags": "ruby|methods|naming-conventions|immutability",
"answer_id": 612196,
"answer_date": "2009-03-04T20:04:41.870Z",
"answer_score": 711
} |
Please answer the following Stack Overflow question:
Title: What are the true benefits of ExpandoObject?
<p>The <a href="http://msdn.microsoft.com/en-us/library/system.dynamic.expandoobject(VS.100).aspx" rel="noreferrer">ExpandoObject</a> class being added to .NET 4 allows you to arbitrarily set properties onto an object at runtime.</p>
<p>Are there any advantages to this over using a <a href="http://msdn.microsoft.com/en-us/library/xfhwa508.aspx" rel="noreferrer"><code>Dictionary<string, object></code></a>, or really even a <a href="http://msdn.microsoft.com/en-us/library/system.collections.hashtable.aspx" rel="noreferrer">Hashtable</a>? As far as I can tell, this is nothing but a hash table that you can access with slightly more succinct syntax.</p>
<p>For example, why is this:</p>
<pre><code>dynamic obj = new ExpandoObject();
obj.MyInt = 3;
obj.MyString = "Foo";
Console.WriteLine(obj.MyString);
</code></pre>
<p>Really better, or substantially different, than:</p>
<pre><code>var obj = new Dictionary<string, object>();
obj["MyInt"] = 3;
obj["MyString"] = "Foo";
Console.WriteLine(obj["MyString"]);
</code></pre>
<p>What <strong>real</strong> advantages are gained by using ExpandoObject instead of just using an arbitrary dictionary type, other than not being obvious that you're using a type that's going to be determined at runtime.</p> | <p>Since I wrote the MSDN article you are referring to, I guess I have to answer this one.</p>
<p>First, I anticipated this question and that's why I wrote a blog post that shows a more or less real use case for ExpandoObject: <a href="https://devblogs.microsoft.com/csharpfaq/dynamic-in-c-4-0-introducing-the-expandoobject/" rel="noreferrer">Dynamic in C# 4.0: Introducing the ExpandoObject</a>.</p>
<p>Shortly, ExpandoObject can help you create complex hierarchical objects. For example, imagine that you have a dictionary within a dictionary:</p>
<pre><code>Dictionary<String, object> dict = new Dictionary<string, object>();
Dictionary<String, object> address = new Dictionary<string,object>();
dict["Address"] = address;
address["State"] = "WA";
Console.WriteLine(((Dictionary<string,object>)dict["Address"])["State"]);
</code></pre>
<p>The deeper the hierarchy, the uglier the code. With ExpandoObject, it stays elegant and readable.</p>
<pre><code>dynamic expando = new ExpandoObject();
expando.Address = new ExpandoObject();
expando.Address.State = "WA";
Console.WriteLine(expando.Address.State);
</code></pre>
<p>Second, as was already pointed out, ExpandoObject implements INotifyPropertyChanged interface which gives you more control over properties than a dictionary.</p>
<p>Finally, you can add events to ExpandoObject like here:</p>
<pre><code>class Program
{
static void Main(string[] args)
{
dynamic d = new ExpandoObject();
// Initialize the event to null (meaning no handlers)
d.MyEvent = null;
// Add some handlers
d.MyEvent += new EventHandler(OnMyEvent);
d.MyEvent += new EventHandler(OnMyEvent2);
// Fire the event
EventHandler e = d.MyEvent;
e?.Invoke(d, new EventArgs());
}
static void OnMyEvent(object sender, EventArgs e)
{
Console.WriteLine("OnMyEvent fired by: {0}", sender);
}
static void OnMyEvent2(object sender, EventArgs e)
{
Console.WriteLine("OnMyEvent2 fired by: {0}", sender);
}
}
</code></pre>
<p>Also, keep in mind that nothing is preventing you from accepting event arguments in a dynamic way. In other words, instead of using <code>EventHandler</code>, you can use <code>EventHandler<dynamic></code> which would cause the second argument of the handler to be <code>dynamic</code>.</p> | {
"question_id": 1653046,
"question_date": "2009-10-31T01:09:42.637Z",
"question_score": 632,
"tags": "c#|.net|.net-4.0|c#-4.0",
"answer_id": 1663044,
"answer_date": "2009-11-02T19:06:58.190Z",
"answer_score": 744
} |
Please answer the following Stack Overflow question:
Title: Performance optimization strategies of last resort
<p>There are plenty of performance questions on this site already, but it occurs to me that almost all are very problem-specific and fairly narrow. And almost all repeat the advice to avoid premature optimization.</p>
<p>Let's assume:</p>
<ul>
<li>the code already is working correctly</li>
<li>the algorithms chosen are already optimal for the circumstances of the problem</li>
<li>the code has been measured, and the offending routines have been isolated</li>
<li>all attempts to optimize will also be measured to ensure they do not make matters worse</li>
</ul>
<p>What I am looking for here is strategies and tricks to squeeze out up to the last few percent in a critical algorithm when there is nothing else left to do but whatever it takes.</p>
<p>Ideally, try to make answers language agnostic, and indicate any down-sides to the suggested strategies where applicable.</p>
<p>I'll add a reply with my own initial suggestions, and look forward to whatever else the Stack Overflow community can think of.</p> | <p>OK, you're defining the problem to where it would seem there is not much room for improvement. That is fairly rare, in my experience. I tried to explain this in a Dr. Dobbs article in November 1993, by starting from a conventionally well-designed non-trivial program with no obvious waste and taking it through a series of optimizations until its wall-clock time was reduced from 48 seconds to 1.1 seconds, and the source code size was reduced by a factor of 4. My diagnostic tool <a href="https://stackoverflow.com/questions/375913/what-can-i-use-to-profile-c-code-in-linux/378024#378024">was this</a>. The sequence of changes was this:</p>
<ul>
<li><p>The first problem found was use of list clusters (now called "iterators" and "container classes") accounting for over half the time. Those were replaced with fairly simple code, bringing the time down to 20 seconds.</p></li>
<li><p>Now the largest time-taker is more list-building. As a percentage, it was not so big before, but now it is because the bigger problem was removed. I find a way to speed it up, and the time drops to 17 seconds.</p></li>
<li><p>Now it is harder to find obvious culprits, but there are a few smaller ones that I can do something about, and the time drops to 13 sec.</p></li>
</ul>
<p>Now I seem to have hit a wall. The samples are telling me exactly what it is doing, but I can't seem to find anything that I can improve. Then I reflect on the basic design of the program, on its transaction-driven structure, and ask if all the list-searching that it is doing is actually mandated by the requirements of the problem.</p>
<p>Then I hit upon a re-design, where the program code is actually generated (via preprocessor macros) from a smaller set of source, and in which the program is not constantly figuring out things that the programmer knows are fairly predictable. In other words, don't "interpret" the sequence of things to do, "compile" it.</p>
<ul>
<li>That redesign is done, shrinking the source code by a factor of 4, and the time is reduced to 10 seconds.</li>
</ul>
<p>Now, because it's getting so quick, it's hard to sample, so I give it 10 times as much work to do, but the following times are based on the original workload.</p>
<ul>
<li><p>More diagnosis reveals that it is spending time in queue-management. In-lining these reduces the time to 7 seconds.</p></li>
<li><p>Now a big time-taker is the diagnostic printing I had been doing. Flush that - 4 seconds.</p></li>
<li><p>Now the biggest time-takers are calls to <em>malloc</em> and <em>free</em>. Recycle objects - 2.6 seconds.</p></li>
<li><p>Continuing to sample, I still find operations that are not strictly necessary - 1.1 seconds.</p></li>
</ul>
<p>Total speedup factor: 43.6</p>
<p>Now no two programs are alike, but in non-toy software I've always seen a progression like this. First you get the easy stuff, and then the more difficult, until you get to a point of diminishing returns. Then the insight you gain may well lead to a redesign, starting a new round of speedups, until you again hit diminishing returns. Now this is the point at which it might make sense to wonder whether <code>++i</code> or <code>i++</code> or <code>for(;;)</code> or <code>while(1)</code> are faster: the kinds of questions I see so often on Stack Overflow.</p>
<p>P.S. It may be wondered why I didn't use a profiler. The answer is that almost every one of these "problems" was a function call site, which stack samples pinpoint. Profilers, even today, are just barely coming around to the idea that statements and call instructions are more important to locate, and easier to fix, than whole functions.</p>
<p>I actually built a profiler to do this, but for a real down-and-dirty intimacy with what the code is doing, there's no substitute for getting your fingers right in it. It is not an issue that the number of samples is small, because none of the problems being found are so tiny that they are easily missed.</p>
<p>ADDED: jerryjvl requested some examples. Here is the first problem. It consists of a small number of separate lines of code, together taking over half the time:</p>
<pre><code> /* IF ALL TASKS DONE, SEND ITC_ACKOP, AND DELETE OP */
if (ptop->current_task >= ILST_LENGTH(ptop->tasklist){
. . .
/* FOR EACH OPERATION REQUEST */
for ( ptop = ILST_FIRST(oplist); ptop != NULL; ptop = ILST_NEXT(oplist, ptop)){
. . .
/* GET CURRENT TASK */
ptask = ILST_NTH(ptop->tasklist, ptop->current_task)
</code></pre>
<p>These were using the list cluster ILST (similar to a list class). They are implemented in the usual way, with "information hiding" meaning that the users of the class were not supposed to have to care how they were implemented. When these lines were written (out of roughly 800 lines of code) thought was not given to the idea that these could be a "bottleneck" (I hate that word). They are simply the recommended way to do things. It is easy to say <em>in hindsight</em> that these should have been avoided, but in my experience <em>all</em> performance problems are like that. In general, it is good to try to avoid creating performance problems. It is even better to find and fix the ones that are created, even though they "should have been avoided" (in hindsight). I hope that gives a bit of the flavor.</p>
<p>Here is the second problem, in two separate lines:</p>
<pre><code> /* ADD TASK TO TASK LIST */
ILST_APPEND(ptop->tasklist, ptask)
. . .
/* ADD TRANSACTION TO TRANSACTION QUEUE */
ILST_APPEND(trnque, ptrn)
</code></pre>
<p>These are building lists by appending items to their ends. (The fix was to collect the items in arrays, and build the lists all at once.) The interesting thing is that these statements only cost (i.e. were on the call stack) 3/48 of the original time, so they were not in fact a big problem <em>at the beginning</em>. However, after removing the first problem, they cost 3/20 of the time and so were now a "bigger fish". In general, that's how it goes.</p>
<p>I might add that this project was distilled from a real project I helped on. In that project, the performance problems were far more dramatic (as were the speedups), such as calling a database-access routine within an inner loop to see if a task was finished.</p>
<p>REFERENCE ADDED:
The source code, both original and redesigned, can be found in <a href="http://www.drdobbs.com/parallel/performance-tuning-slugging-it-out/184409106" rel="noreferrer">www.ddj.com</a>, for 1993, in file 9311.zip, files slug.asc and slug.zip.</p>
<p>EDIT 2011/11/26:
There is now a <a href="https://sourceforge.net/projects/randompausedemo/" rel="noreferrer">SourceForge project</a> containing source code in Visual C++ and a blow-by-blow description of how it was tuned. It only goes through the first half of the scenario described above, and it doesn't follow exactly the same sequence, but still gets a 2-3 order of magnitude speedup.</p> | {
"question_id": 926266,
"question_date": "2009-05-29T14:26:59.977Z",
"question_score": 632,
"tags": "performance|optimization|language-agnostic",
"answer_id": 927773,
"answer_date": "2009-05-29T19:41:53.210Z",
"answer_score": 446
} |
Please answer the following Stack Overflow question:
Title: How can I get a value from a cell of a dataframe?
<p>I have constructed a condition that extracts exactly one row from my data frame:</p>
<pre><code>d2 = df[(df['l_ext']==l_ext) & (df['item']==item) & (df['wn']==wn) & (df['wd']==1)]
</code></pre>
<p>Now I would like to take a value from a particular column:</p>
<pre><code>val = d2['col_name']
</code></pre>
<p>But as a result, I get a data frame that contains one row and one column (i.e., one cell). It is not what I need. I need one value (one float number). How can I do it in pandas?</p> | <p>If you have a DataFrame with only one row, then access the first (only) row as a Series using <em><a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.iloc.html" rel="noreferrer">iloc</a></em>, and then the value using the column name:</p>
<pre><code>In [3]: sub_df
Out[3]:
A B
2 -0.133653 -0.030854
In [4]: sub_df.iloc[0]
Out[4]:
A -0.133653
B -0.030854
Name: 2, dtype: float64
In [5]: sub_df.iloc[0]['A']
Out[5]: -0.13365288513107493
</code></pre> | {
"question_id": 16729574,
"question_date": "2013-05-24T07:17:06.607Z",
"question_score": 631,
"tags": "python|pandas|dataframe",
"answer_id": 16729808,
"answer_date": "2013-05-24T07:31:09.940Z",
"answer_score": 731
} |
Please answer the following Stack Overflow question:
Title: Maven Install on Mac OS X
<p>I'm trying to install maven through the terminal by following <a href="http://maven.apache.org/download.html" rel="noreferrer">these instructions</a>.</p>
<p>So far I got this:</p>
<pre><code>export M2_HOME=/user/apple/apache-maven-3.0.3
export M2=$M2_HOME/bin
export PATH=$M2:$PATH
export JAVA_HOME=/usr/java/jdk1.6.0_22
</code></pre>
<p>Where do you go to find this?</p> | <p>OS X prior to Mavericks (10.9) actually comes with Maven 3 built in.</p>
<p>If you're on OS X Lion, you won't have java installed by default. Run <code>java</code> by itself and it'll prompt you to install it.</p>
<p>Assuming qualifications are met, run <code>mvn -version</code> and see some output like this:</p>
<pre><code>Apache Maven 3.0.3 (r1075438; 2011-02-28 12:31:09-0500)
Maven home: /usr/share/maven
Java version: 1.6.0_29, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: en_US, platform encoding: MacRoman
OS name: "mac os x", version: "10.7.2", arch: "x86_64", family: "mac"
</code></pre> | {
"question_id": 8826881,
"question_date": "2012-01-11T21:26:40.497Z",
"question_score": 631,
"tags": "macos|maven|maven-3",
"answer_id": 8826992,
"answer_date": "2012-01-11T21:35:18.860Z",
"answer_score": 225
} |
Please answer the following Stack Overflow question:
Title: Find and replace in file and overwrite file doesn't work, it empties the file
<p>I would like to run a find and replace on an HTML file through the command line.</p>
<p>My command looks something like this:</p>
<pre><code>sed -e s/STRING_TO_REPLACE/STRING_TO_REPLACE_IT/g index.html > index.html
</code></pre>
<p>When I run this and look at the file afterward, it is empty. It deleted the contents of my file.</p>
<p>When I run this after restoring the file again:</p>
<pre><code>sed -e s/STRING_TO_REPLACE/STRING_TO_REPLACE_IT/g index.html
</code></pre>
<p>The <code>stdout</code> is the contents of the file, and the find and replace has been executed.</p>
<p>Why is this happening?</p> | <p>When the <strong>shell</strong> sees <code>> index.html</code> in the command line it opens the file <code>index.html</code> for <strong>writing</strong>, wiping off all its previous contents.</p>
<p>To fix this you need to pass the <code>-i</code> option to <code>sed</code> to make the changes inline and create a backup of the original file before it does the changes in-place:</p>
<pre><code>sed -i.bak s/STRING_TO_REPLACE/STRING_TO_REPLACE_IT/g index.html
</code></pre>
<p>Without the .bak the command will fail on some platforms, such as Mac OSX.</p> | {
"question_id": 5171901,
"question_date": "2011-03-02T18:44:28.380Z",
"question_score": 631,
"tags": "shell|unix|sed|io-redirection",
"answer_id": 5171935,
"answer_date": "2011-03-02T18:48:27.940Z",
"answer_score": 972
} |
Please answer the following Stack Overflow question:
Title: How can I find script's directory?
<p>Consider the following Python code:</p>
<pre><code>import os
print os.getcwd()
</code></pre>
<p>I use <code>os.getcwd()</code> to <a href="http://www.faqs.org/docs/diveintopython/regression_path.html" rel="noreferrer">get the script file's directory location</a>. When I run the script from the command line it gives me the correct path whereas when I run it from a script run by code in a Django view it prints <code>/</code>.</p>
<p>How can I get the path to the script from within a script run by a Django view?</p>
<p><strong>UPDATE:</strong><br>
Summing up the answers thus far - <code>os.getcwd()</code> and <code>os.path.abspath()</code> both give the current working directory which may or may not be the directory where the script resides. In my web host setup <code><code>__file__</code></code> gives only the filename without the path.</p>
<p>Isn't there any way in Python to (always) be able to receive the path in which the script resides?</p> | <p>You need to call <code>os.path.realpath</code> on <code>__file__</code>, so that when <code>__file__</code> is a filename without the path you still get the dir path:</p>
<pre><code>import os
print(os.path.dirname(os.path.realpath(__file__)))
</code></pre> | {
"question_id": 4934806,
"question_date": "2011-02-08T15:14:48.217Z",
"question_score": 631,
"tags": "python|directory|django-views|getcwd",
"answer_id": 9350788,
"answer_date": "2012-02-19T16:10:35.347Z",
"answer_score": 1003
} |
Please answer the following Stack Overflow question:
Title: Why is enum class preferred over plain enum?
<p>I heard a few people recommending to use enum <em>classes</em> in C++ because of their <strong>type safety</strong>. </p>
<p>But what does that really mean?</p> | <p>C++ has two kinds of <code>enum</code>:</p>
<ol>
<li><code>enum class</code>es</li>
<li>Plain <code>enum</code>s</li>
</ol>
<p>Here are a couple of examples on how to declare them:</p>
<pre><code> enum class Color { red, green, blue }; // enum class
enum Animal { dog, cat, bird, human }; // plain enum
</code></pre>
<p><strong>What is the difference between the two?</strong></p>
<ul>
<li><p><code>enum class</code>es - enumerator names are <strong>local</strong> to the enum and their values do <em>not</em> implicitly convert to other types (like another <code>enum</code> or <code>int</code>)</p>
</li>
<li><p>Plain <code>enum</code>s - where enumerator names are in the same scope as the enum and their
values implicitly convert to integers and other types</p>
</li>
</ul>
<p>Example:</p>
<pre><code>enum Color { red, green, blue }; // plain enum
enum Card { red_card, green_card, yellow_card }; // another plain enum
enum class Animal { dog, deer, cat, bird, human }; // enum class
enum class Mammal { kangaroo, deer, human }; // another enum class
void fun() {
// examples of bad use of plain enums:
Color color = Color::red;
Card card = Card::green_card;
int num = color; // no problem
if (color == Card::red_card) // no problem (bad)
cout << "bad" << endl;
if (card == Color::green) // no problem (bad)
cout << "bad" << endl;
// examples of good use of enum classes (safe)
Animal a = Animal::deer;
Mammal m = Mammal::deer;
int num2 = a; // error
if (m == a) // error (good)
cout << "bad" << endl;
if (a == Mammal::deer) // error (good)
cout << "bad" << endl;
}
</code></pre>
<h2>Conclusion:</h2>
<p><code>enum class</code>es should be preferred because they cause fewer surprises that could potentially lead to bugs.</p> | {
"question_id": 18335861,
"question_date": "2013-08-20T13:06:13.057Z",
"question_score": 631,
"tags": "c++|class|enums|c++-faq",
"answer_id": 18335862,
"answer_date": "2013-08-20T13:06:13.057Z",
"answer_score": 697
} |
Please answer the following Stack Overflow question:
Title: Disable output buffering
<p>Is output buffering enabled by default in Python's interpreter for <code>sys.stdout</code>?</p>
<p>If the answer is positive, what are all the ways to disable it?</p>
<p>Suggestions so far:</p>
<ol>
<li>Use the <code>-u</code> command line switch</li>
<li>Wrap <code>sys.stdout</code> in an object that flushes after every write</li>
<li>Set <code>PYTHONUNBUFFERED</code> env var</li>
<li><code>sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)</code></li>
</ol>
<p>Is there any other way to set some global flag in <code>sys</code>/<code>sys.stdout</code> programmatically during execution?</p> | <p>From <a href="http://mail.python.org/pipermail/tutor/2003-November/026645.html" rel="nofollow noreferrer">Magnus Lycka answer on a mailing list</a>:</p>
<blockquote>
<p>You can skip buffering for a whole
python process using <code>python -u</code>
(or <code>#!/usr/bin/env python -u</code> etc.) or by
setting the environment variable
PYTHONUNBUFFERED.</p>
<p>You could also replace sys.stdout with
some other stream like wrapper which
does a flush after every call.</p>
<pre><code>class Unbuffered(object):
def __init__(self, stream):
self.stream = stream
def write(self, data):
self.stream.write(data)
self.stream.flush()
def writelines(self, datas):
self.stream.writelines(datas)
self.stream.flush()
def __getattr__(self, attr):
return getattr(self.stream, attr)
import sys
sys.stdout = Unbuffered(sys.stdout)
print 'Hello'
</code></pre>
</blockquote> | {
"question_id": 107705,
"question_date": "2008-09-20T09:17:20.480Z",
"question_score": 631,
"tags": "python|stdout|buffered",
"answer_id": 107717,
"answer_date": "2008-09-20T09:24:31.307Z",
"answer_score": 500
} |
Please answer the following Stack Overflow question:
Title: How can I reference a commit in an issue comment on GitHub?
<p>I find a lot of answers on how to reference a GitHub issue in a git comment (using the #xxx notation).
I'd like to reference a commit in my comment, generating a link to the commit details page?</p> | <p>To reference a commit, simply write its SHA-hash, and it'll automatically get turned into a link.</p>
<h3>See also:</h3>
<ul>
<li>The <a href="https://help.github.com/articles/autolinked-references-and-urls/#commit-shas" rel="noreferrer">Autolinked references and URLs / Commit SHAs</a> section of
<em>Writing on GitHub</em>.</li>
</ul> | {
"question_id": 8910271,
"question_date": "2012-01-18T12:43:01.690Z",
"question_score": 631,
"tags": "github|commit|issue-tracking",
"answer_id": 8910323,
"answer_date": "2012-01-18T12:47:50.937Z",
"answer_score": 768
} |
Please answer the following Stack Overflow question:
Title: ImageMagick security policy 'PDF' blocking conversion
<p>The Imagemagick security policy seems to be not allowing me perform this conversion from pdf to png. Converting other extensions seem to be working, just not from pdf. I haven't changed any of the imagemagick settings since I installed it... I am using Arch Linux, if the OS matters.</p>
<pre><code>user@machine $ convert -density 300 -depth 8 -quality 90 input.pdf output.png
convert: attempt to perform an operation not allowed by the security policy `PDF' @ error/constitute.c/IsCoderAuthorized/408.
convert: no images defined `output.png' @ error/convert.c/ConvertImageCommand/3288.
</code></pre> | <p>The ImageMagick change was kept after Ghostscript was fixed because applications (especially web applications) often feed arbitrary user-supplied files to ImageMagick, don't always enforce format restrictions properly, and, since Postscript (which PDF uses) is a turing-complete programming language running in a sandbox, there's always the possibility of another hole in the sandbox.</p>
<p>It's much better to leave things configured so ImageMagick refuses to process files that require running a program and, instead, just invoke Ghostscript directly when you <em>intentionally</em> want to permit Postscript rendering.</p>
<p>That would be accomplished by a Ghostscript command like this:</p>
<pre><code>gs -dSAFER -r600 -sDEVICE=pngalpha -o foo.png myfile.pdf
</code></pre>
<p>Yes, this is a variation on the GhostScript command ImageMagic calls. (see ImageMagick's <code>delegates.xml</code>. <code>-o</code> is shorthand for <code>-dBATCH -dNOPAUSE -sOutputFile=</code>)</p>
<p>What's important is that ImageMagick stays locked down, you don't needlessly invoke an intermediate program, and you get more control over the rendering parameters. (eg. <code>-r600</code> is the DPI to render at and changing <code>-sDEVICE=pngalpha</code> allows you to render directly to your desired format)</p> | {
"question_id": 52998331,
"question_date": "2018-10-25T21:25:09.513Z",
"question_score": 631,
"tags": "linux|ubuntu|pdf|imagemagick|imagemagick-convert",
"answer_id": 67066219,
"answer_date": "2021-04-12T21:58:13.653Z",
"answer_score": 28
} |
Please answer the following Stack Overflow question:
Title: Media Queries: How to target desktop, tablet, and mobile?
<p>I have been doing some research on media queries and I still don't quite understand how to target devices of certain sizes. </p>
<p>I want to be able to target desktop, tablet and mobile. I know that there will be some discrepancies but it would be nice to have a generic system that can be used to target these devices. </p>
<p>Some examples I have found:</p>
<pre><code># Mobile
only screen and (min-width: 480px)
# Tablet
only screen and (min-width: 768px)
# Desktop
only screen and (min-width: 992px)
# Huge
only screen and (min-width: 1280px)
</code></pre>
<p>Or:</p>
<pre><code># Phone
only screen and (max-width:320px)
# Tablet
only screen and (min-width:321px) and (max-width:768px)
# Desktop
only screen and (min-width:769px)
</code></pre>
<p>What should the breakpoints be for each device?</p> | <p>IMO these are the best breakpoints:</p>
<pre><code>@media (min-width:320px) { /* smartphones, portrait iPhone, portrait 480x320 phones (Android) */ }
@media (min-width:480px) { /* smartphones, Android phones, landscape iPhone */ }
@media (min-width:600px) { /* portrait tablets, portrait iPad, e-readers (Nook/Kindle), landscape 800x480 phones (Android) */ }
@media (min-width:801px) { /* tablet, landscape iPad, lo-res laptops ands desktops */ }
@media (min-width:1025px) { /* big landscape tablets, laptops, and desktops */ }
@media (min-width:1281px) { /* hi-res laptops and desktops */ }
</code></pre>
<p><strong>Edit</strong>: Refined to work better with 960 grids:</p>
<pre><code>@media (min-width:320px) { /* smartphones, iPhone, portrait 480x320 phones */ }
@media (min-width:481px) { /* portrait e-readers (Nook/Kindle), smaller tablets @ 600 or @ 640 wide. */ }
@media (min-width:641px) { /* portrait tablets, portrait iPad, landscape e-readers, landscape 800x480 or 854x480 phones */ }
@media (min-width:961px) { /* tablet, landscape iPad, lo-res laptops ands desktops */ }
@media (min-width:1025px) { /* big landscape tablets, laptops, and desktops */ }
@media (min-width:1281px) { /* hi-res laptops and desktops */ }
</code></pre>
<p>In practice, many designers convert pixels to <code>em</code>s, largely because <code>em</code>s afford better zooming. At standard zoom <code>1em === 16px</code>, multiply pixels by <code>1em/16px</code> to get <code>em</code>s. For example, <code>320px === 20em</code>.</p>
<p>In response to the comment, <code>min-width</code> is standard in "mobile-first" design, wherein you start by designing for your smallest screens, and then add ever-increasing media queries, working your way onto larger and larger screens.</p>
<p>Regardless of whether you prefer <code>min-</code>, <code>max-</code>, or combinations thereof, be cognizant of the order of your rules, keeping in mind that if multiple rules match the same element, the later rules will override the earlier rules.</p> | {
"question_id": 6370690,
"question_date": "2011-06-16T10:57:10.503Z",
"question_score": 630,
"tags": "css|mobile|media-queries|tablet",
"answer_id": 7354648,
"answer_date": "2011-09-08T21:19:54.200Z",
"answer_score": 886
} |
Please answer the following Stack Overflow question:
Title: Find out whether radio button is checked with JQuery?
<p>I can set a radio button to checked fine, but what I want to do is setup a sort of 'listener' that activates when a certain radio button is checked. </p>
<p><strong>Take, for example the following code:</strong> </p>
<pre><code>$("#element").click(function()
{
$('#radio_button').attr("checked", "checked");
});
</code></pre>
<p>it adds a checked attribute and all is well, but how would I go about
adding an alert. For example, that pops up when the radio button is checked
without the help of the click function?</p> | <pre><code>$('#element').click(function() {
if($('#radio_button').is(':checked')) { alert("it's checked"); }
});
</code></pre> | {
"question_id": 2272507,
"question_date": "2010-02-16T11:33:08.677Z",
"question_score": 630,
"tags": "jquery|html|jquery-ui|checked",
"answer_id": 2272532,
"answer_date": "2010-02-16T11:38:13.447Z",
"answer_score": 1178
} |
Please answer the following Stack Overflow question:
Title: Authentication plugin 'caching_sha2_password' cannot be loaded
<p>I am connecting MySQL - 8.0 with MySQL Workbench and getting the below error:</p>
<blockquote>
<p>Authentication plugin 'caching_sha2_password' cannot be loaded:
dlopen(/usr/local/mysql/lib/plugin/caching_sha2_password.so, 2): image
not found</p>
</blockquote>
<p>I have tried with other client tool as well.</p>
<p>Any solution for this?</p> | <p>You can change the encryption of the user's password by altering the user with below Alter command :</p>
<blockquote>
<p>ALTER USER 'username'@'ip_address' IDENTIFIED WITH mysql_native_password BY
'password';</p>
</blockquote>
<p><strong>OR</strong></p>
<p>We can avoid this error by make it work with old password plugin:</p>
<p>First change the authentication plugin in <strong>my.cnf file for Linux / my.ini file in Windows</strong>:</p>
<blockquote>
<p>[mysqld] </p>
<p>default_authentication_plugin=mysql_native_password</p>
</blockquote>
<p>Restart the mysql server to take the changes in affect and try connecting via MySQL with any mysql client.</p>
<p>If still unable to connect and getting the below error:</p>
<pre><code>Unable to load plugin 'caching_sha2_password'
</code></pre>
<p>It means your user needs the above plugin. So try creating new user with create user or grant command after changing default plugin. then new user need the native plugin and you will able to connect MySQL.</p>
<p>Thanks</p> | {
"question_id": 49194719,
"question_date": "2018-03-09T13:19:55.327Z",
"question_score": 630,
"tags": "mysql|database|mysql-workbench|mysql-8.0",
"answer_id": 49228443,
"answer_date": "2018-03-12T05:08:21.523Z",
"answer_score": 82
} |
Please answer the following Stack Overflow question:
Title: pip uses incorrect cached package version, instead of the user-specified version
<p>I need to install psycopg2 v2.4.1 specifically. I accidentally did:</p>
<pre><code> pip install psycopg2
</code></pre>
<p>Instead of:</p>
<pre><code> pip install psycopg2==2.4.1
</code></pre>
<p>That installs 2.4.4 instead of the earlier version. </p>
<p>Now even after I pip uninstall psycopg2 and attempt to reinstall with the correct version, it appears that pip is re-using the cache it downloaded the first time.</p>
<p>How can I force pip to clear out its download cache and use the specific version I'm including in the command?</p> | <p>If using pip 6.0 or newer, try adding the <code>--no-cache-dir</code> option (<a href="https://pip.pypa.io/en/stable/reference/pip_install/#caching" rel="noreferrer">source</a>).</p>
<p>If using pip older than pip 6.0, upgrade it with <code>pip install -U pip</code>.</p> | {
"question_id": 9510474,
"question_date": "2012-03-01T04:06:35.080Z",
"question_score": 630,
"tags": "python|pip",
"answer_id": 9510610,
"answer_date": "2012-03-01T04:26:15.043Z",
"answer_score": 658
} |
Please answer the following Stack Overflow question:
Title: How do I change the data type for a column in MySQL?
<p>I want to change the data type of multiple columns from float to int. What is the simplest way to do this?</p>
<p>There is no data to worry about, yet.</p> | <p><a href="http://dev.mysql.com/doc/refman/5.1/en/alter-table.html" rel="noreferrer">http://dev.mysql.com/doc/refman/5.1/en/alter-table.html</a></p>
<pre><code>ALTER TABLE tablename MODIFY columnname INTEGER;
</code></pre>
<p>This will change the datatype of given column</p>
<p>Depending on how many columns you wish to modify it might be best to generate a script, or use some kind of mysql client GUI</p> | {
"question_id": 1356866,
"question_date": "2009-08-31T10:44:24.233Z",
"question_score": 630,
"tags": "mysql",
"answer_id": 1356875,
"answer_date": "2009-08-31T10:46:28.600Z",
"answer_score": 1157
} |
Please answer the following Stack Overflow question:
Title: UnicodeDecodeError when reading CSV file in Pandas with Python
<p>I'm running a program which is processing 30,000 similar files. A random number of them are stopping and producing this error...</p>
<pre><code>File "C:\Importer\src\dfman\importer.py", line 26, in import_chr
data = pd.read_csv(filepath, names=fields)
File "C:\Python33\lib\site-packages\pandas\io\parsers.py", line 400, in parser_f
return _read(filepath_or_buffer, kwds)
File "C:\Python33\lib\site-packages\pandas\io\parsers.py", line 205, in _read
return parser.read()
File "C:\Python33\lib\site-packages\pandas\io\parsers.py", line 608, in read
ret = self._engine.read(nrows)
File "C:\Python33\lib\site-packages\pandas\io\parsers.py", line 1028, in read
data = self._reader.read(nrows)
File "parser.pyx", line 706, in pandas.parser.TextReader.read (pandas\parser.c:6745)
File "parser.pyx", line 728, in pandas.parser.TextReader._read_low_memory (pandas\parser.c:6964)
File "parser.pyx", line 804, in pandas.parser.TextReader._read_rows (pandas\parser.c:7780)
File "parser.pyx", line 890, in pandas.parser.TextReader._convert_column_data (pandas\parser.c:8793)
File "parser.pyx", line 950, in pandas.parser.TextReader._convert_tokens (pandas\parser.c:9484)
File "parser.pyx", line 1026, in pandas.parser.TextReader._convert_with_dtype (pandas\parser.c:10642)
File "parser.pyx", line 1046, in pandas.parser.TextReader._string_convert (pandas\parser.c:10853)
File "parser.pyx", line 1278, in pandas.parser._string_box_utf8 (pandas\parser.c:15657)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xda in position 6: invalid continuation byte
</code></pre>
<p>The source/creation of these files all come from the same place. What's the best way to correct this to proceed with the import?</p> | <p><code>read_csv</code> takes an <code>encoding</code> option to deal with files in different formats. I mostly use <code>read_csv('file', encoding = "ISO-8859-1")</code>, or alternatively <code>encoding = "utf-8"</code> for reading, and generally <code>utf-8</code> for <code>to_csv</code>.</p>
<p>You can also use one of several <code>alias</code> options like <code>'latin'</code> or <code>'cp1252'</code> (Windows) instead of <code>'ISO-8859-1'</code> (see <a href="https://docs.python.org/3/library/codecs.html#standard-encodings" rel="noreferrer">python docs</a>, also for numerous other encodings you may encounter).</p>
<p>See <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html" rel="noreferrer">relevant Pandas documentation</a>,
<a href="http://docs.python.org/3/library/csv.html#examples" rel="noreferrer">python docs examples on csv files</a>, and plenty of related questions here on SO. A good background resource is <a href="https://www.joelonsoftware.com/2003/10/08/the-absolute-minimum-every-software-developer-absolutely-positively-must-know-about-unicode-and-character-sets-no-excuses/" rel="noreferrer">What every developer should know about unicode and character sets</a>.</p>
<p>To detect the encoding (assuming the file contains non-ascii characters), you can use <code>enca</code> (see <a href="https://linux.die.net/man/1/enconv" rel="noreferrer">man page</a>) or <code>file -i</code> (linux) or <code>file -I</code> (osx) (see <a href="https://linux.die.net/man/1/file" rel="noreferrer">man page</a>).</p> | {
"question_id": 18171739,
"question_date": "2013-08-11T12:06:25.160Z",
"question_score": 630,
"tags": "python|pandas|csv|dataframe|unicode",
"answer_id": 18172249,
"answer_date": "2013-08-11T13:10:22.297Z",
"answer_score": 1121
} |
Please answer the following Stack Overflow question:
Title: How can I extract a predetermined range of lines from a text file on Unix?
<p>I have a ~23000 line SQL dump containing several databases worth of data. I need to extract a certain section of this file (i.e. the data for a single database) and place it in a new file. I know both the start and end line numbers of the data that I want.</p>
<p>Does anyone know a Unix command (or series of commands) to extract all lines from a file between say line 16224 and 16482 and then redirect them into a new file?</p> | <pre><code>sed -n '16224,16482p;16483q' filename > newfile
</code></pre>
<p>From the <a href="https://www.gnu.org/software/sed/manual/sed.html#Common-Commands" rel="noreferrer">sed manual</a>:</p>
<blockquote>
<p><strong>p</strong> -
Print out the pattern space (to the standard output). This command is usually only used in conjunction with the -n command-line option.</p>
<p><strong>n</strong> -
If auto-print is not disabled, print the pattern space, then, regardless, replace the pattern space with the next line of input. If
there is no more input then sed exits without processing any more
commands.</p>
<p><strong>q</strong> -
Exit <code>sed</code> without processing any more commands or input.
Note that the current pattern space is printed if auto-print is not disabled with the -n option.</p>
</blockquote>
<p><a href="https://www.gnu.org/software/sed/manual/sed.html#Addresses" rel="noreferrer">and</a></p>
<blockquote>
<p>Addresses in a sed script can be in any of the following forms:</p>
<p><strong>number</strong>
Specifying a line number will match only that line in the input.</p>
<p>An address range can be specified by specifying two addresses
separated by a comma (,). An address range matches lines starting from
where the first address matches, and continues until the second
address matches (inclusively).</p>
</blockquote> | {
"question_id": 83329,
"question_date": "2008-09-17T13:40:59.947Z",
"question_score": 630,
"tags": "text-processing",
"answer_id": 83347,
"answer_date": "2008-09-17T13:42:34.123Z",
"answer_score": 913
} |
Please answer the following Stack Overflow question:
Title: Error message "error:0308010C:digital envelope routines::unsupported"
<p>I created the default IntelliJ IDEA React project and got this:</p>
<pre class="lang-none prettyprint-override"><code>Error: error:0308010C:digital envelope routines::unsupported
at new Hash (node:internal/crypto/hash:67:19)
at Object.createHash (node:crypto:130:10)
at module.exports (/Users/user/Programming Documents/WebServer/untitled/node_modules/webpack/lib/util/createHash.js:135:53)
at NormalModule._initBuildHash (/Users/user/Programming Documents/WebServer/untitled/node_modules/webpack/lib/NormalModule.js:417:16)
at handleParseError (/Users/user/Programming Documents/WebServer/untitled/node_modules/webpack/lib/NormalModule.js:471:10)
at /Users/user/Programming Documents/WebServer/untitled/node_modules/webpack/lib/NormalModule.js:503:5
at /Users/user/Programming Documents/WebServer/untitled/node_modules/webpack/lib/NormalModule.js:358:12
at /Users/user/Programming Documents/WebServer/untitled/node_modules/loader-runner/lib/LoaderRunner.js:373:3
at iterateNormalLoaders (/Users/user/Programming Documents/WebServer/untitled/node_modules/loader-runner/lib/LoaderRunner.js:214:10)
at iterateNormalLoaders (/Users/user/Programming Documents/WebServer/untitled/node_modules/loader-runner/lib/LoaderRunner.js:221:10)
/Users/user/Programming Documents/WebServer/untitled/node_modules/react-scripts/scripts/start.js:19
throw err;
^
</code></pre>
<p>It seems to be a recent issue - <em><a href="https://github.com/webpack/webpack/issues/14532" rel="noreferrer">webpack ran into this 4 days ago and is still working on it</a></em>.</p> | <p>In your package.json: change this line</p>
<pre class="lang-json prettyprint-override"><code>"start": "react-scripts start"
</code></pre>
<p>to</p>
<pre class="lang-json prettyprint-override"><code>"start": "react-scripts --openssl-legacy-provider start"
</code></pre> | {
"question_id": 69692842,
"question_date": "2021-10-23T23:39:57.517Z",
"question_score": 630,
"tags": "node.js|reactjs|webpack|webstorm",
"answer_id": 69713899,
"answer_date": "2021-10-25T19:45:46.500Z",
"answer_score": 372
} |
Please answer the following Stack Overflow question:
Title: Decorators with parameters?
<p>I have a problem with the transfer of the variable <code>insurance_mode</code> by the decorator. I would do it by the following decorator statement:</p>
<pre><code>@execute_complete_reservation(True)
def test_booking_gta_object(self):
self.test_select_gta_object()
</code></pre>
<p>but unfortunately, this statement does not work. Perhaps maybe there is better way to solve this problem.</p>
<pre><code>def execute_complete_reservation(test_case,insurance_mode):
def inner_function(self,*args,**kwargs):
self.test_create_qsf_query()
test_case(self,*args,**kwargs)
self.test_select_room_option()
if insurance_mode:
self.test_accept_insurance_crosseling()
else:
self.test_decline_insurance_crosseling()
self.test_configure_pax_details()
self.test_configure_payer_details
return inner_function
</code></pre> | <p>The syntax for decorators with arguments is a bit different - the decorator with arguments should return a function that will <em>take a function</em> and return another function. So it should really return a normal decorator. A bit confusing, right? What I mean is:</p>
<pre><code>def decorator_factory(argument):
def decorator(function):
def wrapper(*args, **kwargs):
funny_stuff()
something_with_argument(argument)
result = function(*args, **kwargs)
more_funny_stuff()
return result
return wrapper
return decorator
</code></pre>
<p><a href="https://www.artima.com/weblogs/viewpost.jsp?thread=240845#decorator-functions-with-decorator-arguments" rel="noreferrer">Here</a> you can read more on the subject - it's also possible to implement this using callable objects and that is also explained there.</p> | {
"question_id": 5929107,
"question_date": "2011-05-08T17:40:08.867Z",
"question_score": 630,
"tags": "python|decorator",
"answer_id": 5929165,
"answer_date": "2011-05-08T17:54:08.057Z",
"answer_score": 1064
} |
Please answer the following Stack Overflow question:
Title: Javascript / Chrome - How to copy an object from the webkit inspector as code
<p>I am doing a console.log statement in my javascript in order to log a javascript object. I'm wondering if there's a way, once that's done - to copy that object as javascript code. What I'm trying to do is convert an object that was created using ajax to parse an xml feed into a static javascript object so that a file can run locally, without a server. I've included a screenshot of the object in the chrome inspector window so you can see what I'm trying to do.<img src="https://i.stack.imgur.com/RsxAB.png" alt="enter image description here"></p> | <ol>
<li><p>Right-click an object in Chrome's console and select <code>Store as Global Variable</code> from the context menu. It will return something like <code>temp1</code> as the variable name.</p>
</li>
<li><p>Chrome also has a <code>copy()</code> method, so <code>copy(temp1)</code> in the console should copy that object to your clipboard.</p>
</li>
</ol>
<p><a href="https://thumbs.gfycat.com/JadedUnsteadyFennecfox-size_restricted.gif" rel="noreferrer"><img src="https://thumbs.gfycat.com/JadedUnsteadyFennecfox-size_restricted.gif" alt="Copy Javascript Object in Chrome DevTools" /></a></p>
<p><strong>Note on Recursive Objects:</strong> If you're trying to copy a recursive object, you will get <code>[object Object]</code>. The way out is to try <code>copy(JSON.stringify(temp1))</code> , the object will be fully copied to your clipboard as a valid JSON, so you'd be able to format it as you wish, using one of many resources.</p>
<p>If you get the <code>Uncaught TypeError: Converting circular structure to JSON</code> message, you can use <code>JSON.stringify</code>'s second argument (which is a filter function) to filter out the offending circular properties. See this <a href="https://stackoverflow.com/a/12659424/622287">Stack Overflow answer</a> for more details.</p> | {
"question_id": 10305365,
"question_date": "2012-04-24T20:15:44.060Z",
"question_score": 630,
"tags": "javascript|google-chrome|object|webkit",
"answer_id": 25140576,
"answer_date": "2014-08-05T13:54:16.613Z",
"answer_score": 1589
} |
Please answer the following Stack Overflow question:
Title: Differences between distribute, distutils, setuptools and distutils2?
<h2>The Situation</h2>
<p>I’m trying to port an open-source library to Python 3. (<a href="http://sympy.org/">SymPy</a>, if anyone is wondering.) </p>
<p>So, I need to run <code>2to3</code> automatically when building for Python 3. To do that, I need to use <code>distribute</code>. Therefore, I need to port the current system, which (according to the doctest) is <code>distutils</code>. </p>
<p><br></p>
<h2>The Problem</h2>
<p>Unfortunately, I’m not sure what’s the difference between these modules—<code>distutils</code>, <code>distribute</code>, <code>setuptools</code>. The documentation is sketchy as best, as they all seem to be a fork of one another, intended to be compatible in most circumstances (but actually, not all)…and so on, and so forth. </p>
<p><br></p>
<h2>The Question</h2>
<p><strong>Could someone explain the differences?</strong> What am I supposed to use? What is the most modern solution? (As an aside, I’d also appreciate some guide on porting to <code>Distribute</code>, but that’s a tad beyond the scope of the question…)</p> | <p>As of May 2022, most of the other answers to this question are several years out-of-date. When you come across advice on Python packaging issues, remember to look at the date of publication, and don't trust out-of-date information.</p>
<p>The <a href="https://packaging.python.org/" rel="noreferrer">Python Packaging User Guide</a> is worth a read. Every page has a "last updated" date displayed, so you can check the recency of the manual, and it's quite comprehensive. The fact that it's hosted on a subdomain of python.org of the Python Software Foundation just adds credence to it. The <a href="https://packaging.python.org/en/latest/key_projects/" rel="noreferrer">Project Summaries</a> page is especially relevant here.</p>
<h2>Summary of tools:</h2>
<p>Here's a summary of the Python packaging landscape:</p>
<h3>Supported tools:</h3>
<ul>
<li><p><strong><code>setuptools</code></strong> was developed to overcome Distutils' limitations, and is not included in the standard library. It introduced a command-line utility called <code>easy_install</code>. It also introduced the <code>setuptools</code> Python package that can be imported in your <code>setup.py</code> script, and the <code>pkg_resources</code> Python package that can be imported in your code to locate data files installed with a distribution. One of its gotchas is that it monkey-patches the <code>distutils</code> Python package. It should work well with <code>pip</code>. <a href="https://github.com/pypa/setuptools/releases" rel="noreferrer">It sees regular releases.</a></p>
<ul>
<li><sub><a href="https://setuptools.readthedocs.io/en/latest/" rel="noreferrer">Official docs</a> | <a href="https://pypi.python.org/pypi/setuptools" rel="noreferrer">Pypi page</a> | <a href="https://github.com/pypa/setuptools" rel="noreferrer">GitHub repo</a> | <a href="https://packaging.python.org/key_projects/#setuptools" rel="noreferrer"><code>setuptools</code> section of Python Package User Guide</a></sub></li>
</ul>
</li>
<li><p><strong><code>scikit-build</code></strong> is an improved build system generator that internally uses CMake to build compiled Python extensions. Because scikit-build isn't based on distutils, it doesn't really have any of its limitations. When ninja-build is present, scikit-build can compile large projects over three times faster than the alternatives. It should work well with <code>pip</code>.</p>
<ul>
<li><sub><a href="http://scikit-build.readthedocs.io/en/latest/" rel="noreferrer">Official docs</a> | <a href="https://pypi.org/project/scikit-build/" rel="noreferrer">Pypi page</a> | <a href="https://github.com/scikit-build/scikit-build" rel="noreferrer">GitHub repo</a> | <a href="https://packaging.python.org/key_projects/#scikit-build" rel="noreferrer"><code>scikit-build</code> section of Python Package User Guide</a></sub></li>
</ul>
</li>
<li><p><strong><code>distlib</code></strong> is a library that provides functionality that is used by higher level tools like <code>pip</code>.</p>
<ul>
<li><sub><a href="http://pythonhosted.org/distlib/" rel="noreferrer">Official Docs</a> | <a href="https://pypi.org/project/distlib" rel="noreferrer">Pypi page</a> | <a href="https://bitbucket.org/pypa/distlib" rel="noreferrer">Bitbucket repo</a> | <a href="https://packaging.python.org/key_projects/#distlib" rel="noreferrer"><code>distlib</code> section of Python Package User Guide</a></sub></li>
</ul>
</li>
<li><p><strong><code>packaging</code></strong> is also a library that provides functionality used by higher level tools like <code>pip</code> and <code>setuptools</code></p>
<ul>
<li><sub><a href="https://packaging.pypa.io/" rel="noreferrer">Official Docs</a> | <a href="https://pypi.org/project/packaging" rel="noreferrer">Pypi page</a> | <a href="https://github.com/pypa/packaging" rel="noreferrer">GitHub repo</a> | <a href="https://packaging.python.org/key_projects/#packaging" rel="noreferrer"><code>packaging</code> section of Python Package User Guide</a></sub></li>
</ul>
</li>
</ul>
<h3>Deprecated/abandoned tools:</h3>
<ul>
<li><p><strong><code>distutils</code></strong> is still included in the standard library of Python, but is considered deprecated as of Python 3.10. It is useful for simple Python distributions, but lacks features. It introduces the <code>distutils</code> Python package that can be imported in your <code>setup.py</code> script.</p>
<ul>
<li><sub><a href="https://docs.python.org/3/library/distutils.html" rel="noreferrer">Official docs</a> | <a href="https://packaging.python.org/key_projects/#distutils" rel="noreferrer"><code>distutils</code> section of Python Package User Guide</a></sub></li>
</ul>
</li>
<li><p><strong><code>distribute</code></strong> was a fork of <code>setuptools</code>. It shared the same namespace, so if you had Distribute installed, <code>import setuptools</code> would actually import the package distributed with Distribute. <em><strong>Distribute was merged back into Setuptools 0.7</strong></em>, so you don't need to use Distribute any more. In fact, the version on Pypi is just a compatibility layer that installs Setuptools.</p>
</li>
<li><p><strong><code>distutils2</code></strong> was an attempt to take the best of <code>distutils</code>, <code>setuptools</code> and <code>distribute</code> and become the standard tool included in Python's standard library. The idea was that <code>distutils2</code> would be distributed for old Python versions, and that <code>distutils2</code> would be renamed to <code>packaging</code> for Python 3.3, which would include it in its standard library. These plans did not go as intended, however, and currently, <em><strong><code>distutils2</code> is an abandoned project</strong></em>. The latest release was in March 2012, and its Pypi home page has finally been updated to reflect its death.</p>
</li>
</ul>
<h2>Others:</h2>
<p>There are other tools, if you are interested, read <a href="https://packaging.python.org/en/latest/key_projects/" rel="noreferrer">Project Summaries</a> in the Python Packaging User Guide. I won't list them all, to not repeat that page, and to keep the answer matching the question, which was only about <code>distribute</code>, <code>distutils</code>, <code>setuptools</code> and <code>distutils2</code>.</p>
<h2>Recommendation:</h2>
<p>If all of this is new to you, and you don't know where to start, <strong>I would recommend learning <code>setuptools</code></strong>, along with <code>pip</code> and <code>virtualenv</code>, which all work very well together.</p>
<p>If you're looking into <code>virtualenv</code>, you might be interested in this question: <a href="https://stackoverflow.com/q/41573587/247696">What is the difference between <code>venv</code>, <code>pyvenv</code>, <code>pyenv</code>, <code>virtualenv</code>, <code>virtualenvwrapper</code>, etc?</a>. (Yes, I know, I groan with you.)</p> | {
"question_id": 6344076,
"question_date": "2011-06-14T13:17:27.553Z",
"question_score": 630,
"tags": "python|packaging|setuptools|distutils|distribute",
"answer_id": 14753678,
"answer_date": "2013-02-07T14:37:50.217Z",
"answer_score": 889
} |
Please answer the following Stack Overflow question:
Title: "echo -n" prints "-n"
<p>I have a problem with <code>echo</code> in my script:</p>
<pre><code>echo -n "Some string..."
</code></pre>
<p>prints</p>
<pre class="lang-none prettyprint-override"><code>-n Some string...
</code></pre>
<p>and moves to the next line. In the console it's working correcly without newline:</p>
<pre class="lang-none prettyprint-override"><code>Some string...
</code></pre> | <p>There are multiple versions of the <code>echo</code> command, with different behaviors. Apparently the shell used for your script uses a version that doesn't recognize <code>-n</code>.</p>
<p>The <code>printf</code> command has much more consistent behavior. <code>echo</code> is fine for simple things like <code>echo hello</code>, but I suggest using <code>printf</code> for anything more complicated.</p>
<p>What system are you on, and what shell does your script use?</p> | {
"question_id": 11193466,
"question_date": "2012-06-25T16:38:14.947Z",
"question_score": 629,
"tags": "sh",
"answer_id": 11193533,
"answer_date": "2012-06-25T16:42:33.530Z",
"answer_score": 671
} |
Please answer the following Stack Overflow question:
Title: Is it possible to run one logrotate check manually?
<p>Is it possible to run one iteration of logrotate manually without scheduling it on some interval?</p> | <p>Yes: <code>logrotate --force $CONFIG_FILE</code></p> | {
"question_id": 2117771,
"question_date": "2010-01-22T14:14:22.743Z",
"question_score": 629,
"tags": "logging|logrotate",
"answer_id": 2117789,
"answer_date": "2010-01-22T14:16:33.060Z",
"answer_score": 831
} |
Please answer the following Stack Overflow question:
Title: Is there a difference between "==" and "is"?
<p>My <a href="https://english.stackexchange.com/questions/19967/what-does-google-fu-mean">Google-fu</a> has failed me.</p>
<p>In Python, are the following two tests for equality equivalent?</p>
<pre><code>n = 5
# Test one.
if n == 5:
print 'Yay!'
# Test two.
if n is 5:
print 'Yay!'
</code></pre>
<p>Does this hold true for objects where you would be comparing instances (a <code>list</code> say)?</p>
<p>Okay, so this kind of answers my question:</p>
<pre><code>L = []
L.append(1)
if L == [1]:
print 'Yay!'
# Holds true, but...
if L is [1]:
print 'Yay!'
# Doesn't.
</code></pre>
<p>So <code>==</code> tests value where <code>is</code> tests to see if they are the same object?</p> | <p><code>is</code> will return <code>True</code> if two variables point to the same object (in memory), <code>==</code> if the objects referred to by the variables are equal.</p>
<pre><code>>>> a = [1, 2, 3]
>>> b = a
>>> b is a
True
>>> b == a
True
# Make a new copy of list `a` via the slice operator,
# and assign it to variable `b`
>>> b = a[:]
>>> b is a
False
>>> b == a
True
</code></pre>
<p>In your case, the second test only works because Python caches small integer objects, which is an implementation detail. For larger integers, this does not work:</p>
<pre><code>>>> 1000 is 10**3
False
>>> 1000 == 10**3
True
</code></pre>
<p>The same holds true for string literals:</p>
<pre><code>>>> "a" is "a"
True
>>> "aa" is "a" * 2
True
>>> x = "a"
>>> "aa" is x * 2
False
>>> "aa" is intern(x*2)
True
</code></pre>
<p>Please see <a href="https://stackoverflow.com/questions/26595/is-there-any-difference-between-foo-is-none-and-foo-none">this question</a> as well.</p> | {
"question_id": 132988,
"question_date": "2008-09-25T12:27:09.733Z",
"question_score": 629,
"tags": "python|reference|equality|semantics",
"answer_id": 133024,
"answer_date": "2008-09-25T12:32:37.473Z",
"answer_score": 1100
} |
Please answer the following Stack Overflow question:
Title: Send and receive messages through NSNotificationCenter in Objective-C?
<p>I am attempting to send and receive messages through <code>NSNotificationCenter</code> in Objective-C. However, I haven't been able to find any examples on how to do this. How do you send and receive messages through <code>NSNotificationCenter</code>?</p> | <pre><code>@implementation TestClass
- (void) dealloc
{
// If you don't remove yourself as an observer, the Notification Center
// will continue to try and send notification objects to the deallocated
// object.
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
- (id) init
{
self = [super init];
if (!self) return nil;
// Add this instance of TestClass as an observer of the TestNotification.
// We tell the notification center to inform us of "TestNotification"
// notifications using the receiveTestNotification: selector. By
// specifying object:nil, we tell the notification center that we are not
// interested in who posted the notification. If you provided an actual
// object rather than nil, the notification center will only notify you
// when the notification was posted by that particular object.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(receiveTestNotification:)
name:@"TestNotification"
object:nil];
return self;
}
- (void) receiveTestNotification:(NSNotification *) notification
{
// [notification name] should always be @"TestNotification"
// unless you use this method for observation of other notifications
// as well.
if ([[notification name] isEqualToString:@"TestNotification"])
NSLog (@"Successfully received the test notification!");
}
@end
</code></pre>
<p>... somewhere else in another class ...</p>
<pre><code>- (void) someMethod
{
// All instances of TestClass will be notified
[[NSNotificationCenter defaultCenter]
postNotificationName:@"TestNotification"
object:self];
}
</code></pre> | {
"question_id": 2191594,
"question_date": "2010-02-03T11:47:47.090Z",
"question_score": 629,
"tags": "ios|objective-c|nsnotificationcenter",
"answer_id": 2191802,
"answer_date": "2010-02-03T12:25:51.843Z",
"answer_score": 1041
} |
Please answer the following Stack Overflow question:
Title: What does the number in parentheses shown after Unix command names in manpages mean?
<p>For example: <code>man(1)</code>, <code>find(3)</code>, <code>updatedb(2)</code>? </p>
<p>What do the numbers in parentheses (Brit. "brackets") mean?</p> | <p>It's the section that the man page for the command is assigned to.</p>
<p>These are split as</p>
<ol>
<li>General commands</li>
<li>System calls</li>
<li>C library functions</li>
<li>Special files (usually devices, those found in /dev) and drivers</li>
<li>File formats and conventions</li>
<li>Games and screensavers</li>
<li>Miscellanea</li>
<li>System administration commands and daemons</li>
</ol>
<p>Original descriptions of each section can be seen in the <a href="https://web.archive.org/web/20170601064537/http://plan9.bell-labs.com/7thEdMan/v7vol1.pdf" rel="noreferrer">Unix Programmer's Manual</a> (page ii).</p>
<p>In order to access a man page given as "foo(5)", run:</p>
<pre class="lang-sh prettyprint-override"><code>man 5 foo
</code></pre> | {
"question_id": 62936,
"question_date": "2008-09-15T13:37:47.130Z",
"question_score": 629,
"tags": "linux|unix|command-line|manpage",
"answer_id": 62972,
"answer_date": "2008-09-15T13:42:31.707Z",
"answer_score": 604
} |
Please answer the following Stack Overflow question:
Title: Why do you need to put #!/bin/bash at the beginning of a script file?
<p>I have made <a href="http://en.wikipedia.org/wiki/Bash_%28Unix_shell%29" rel="noreferrer">Bash</a> scripts before and they all ran fine without <code>#!/bin/bash</code> at the beginning.</p>
<p>What's the point of putting it in? Would things be any different?</p>
<p>Also, how do you pronounce <code>#</code>? I know that <code>!</code> is pronounced as "bang."</p>
<p>How is <code>#!</code> pronounced?</p> | <p>It's a convention so the *nix shell knows what kind of interpreter to run.</p>
<p>For example, older flavors of ATT defaulted to <em>sh</em> (the Bourne shell), while older versions of BSD defaulted to <em>csh</em> (the C shell).</p>
<p>Even today (where most systems run bash, the <em>"Bourne Again Shell"</em>), scripts can be in bash, python, perl, ruby, PHP, etc, etc. For example, you might see <code>#!/bin/perl</code> or <code>#!/bin/perl5</code>.</p>
<p>PS:
The exclamation mark (<code>!</code>) is affectionately called <em>"bang"</em>. The shell comment symbol (<code>#</code>) is sometimes called <em>"hash"</em>.</p>
<p>PPS:
Remember - under *nix, associating a suffix with a file type is merely a <em>convention</em>, not a <em>"rule"</em>. An <em>executable</em> can be a binary program, any one of a million script types and other things as well. Hence the need for <code>#!/bin/bash</code>.</p> | {
"question_id": 8967902,
"question_date": "2012-01-23T06:24:31.527Z",
"question_score": 628,
"tags": "linux|bash|scripting|shebang",
"answer_id": 8967916,
"answer_date": "2012-01-23T06:26:04.073Z",
"answer_score": 517
} |
Please answer the following Stack Overflow question:
Title: Android changing Floating Action Button color
<p>I have been trying to change Material's Floating Action Button color, but without success.</p>
<pre><code><android.support.design.widget.FloatingActionButton
android:id="@+id/profile_edit_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="16dp"
android:clickable="true"
android:src="@drawable/ic_mode_edit_white_24dp" />
</code></pre>
<p>I have tried to add:</p>
<pre><code>android:background="@color/mycolor"
</code></pre>
<p>or via code:</p>
<pre><code>FloatingActionButton fab = (FloatingActionButton) rootView.findViewById(R.id.profile_edit_fab);
fab.setBackgroundColor(Color.parseColor("#mycolor"));
</code></pre>
<p>or</p>
<pre><code>fab.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#mycolor")));
</code></pre>
<p>But none of the above worked. I have also tried the solutions in the proposed duplicate question, but none of them works; the button remained green and also became a square.</p>
<p>P.S. It would be also nice to know how to add ripple effect, couldn't understand that either.</p> | <p>As described in the <a href="http://developer.android.com/reference/android/support/design/widget/FloatingActionButton.html?utm_campaign=io15&utm_source=dac&utm_medium=blog" rel="noreferrer">documentation</a>, by default it takes the color set in <strong>styles.xml</strong> attribute <strong>colorAccent</strong>.</p>
<blockquote>
<p>The background color of this view defaults to the your theme's colorAccent. If you wish to change this at runtime then you can do so via setBackgroundTintList(ColorStateList).</p>
</blockquote>
<p>If you wish to change the color</p>
<ul>
<li>in XML with attribute <strong>app:backgroundTint</strong></li>
</ul>
<pre class="lang-xml prettyprint-override"><code><android.support.design.widget.FloatingActionButton
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_add"
app:backgroundTint="@color/orange"
app:borderWidth="0dp"
app:elevation="6dp"
app:fabSize="normal" >
</code></pre>
<ul>
<li>in code with <strong>.setBackgroundTintList</strong> (answer below by <a href="https://stackoverflow.com/questions/30969455/android-changing-floating-action-button-color/32031019#32031019">ywwynm</a>)</li>
</ul>
<p>As @Dantalian mentioned in the comments, if you wish to change the icon color for Design Support Library <strong>up to v22 (inclusive)</strong>, you can use</p>
<pre><code>android:tint="@color/white"
</code></pre>
<p>For Design Support Library <strong>since v23</strong> for you can use:</p>
<pre><code>app:tint="@color/white"
</code></pre>
<p>Also with <code>androidX</code> libraries you need to set a 0dp border in your xml layout:</p>
<pre class="lang-xml prettyprint-override"><code><com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_add"
app:backgroundTint="@color/orange"
app:borderWidth="0dp"
app:elevation="6dp"
app:fabSize="normal" />
</code></pre> | {
"question_id": 30969455,
"question_date": "2015-06-21T21:20:22.013Z",
"question_score": 628,
"tags": "java|android|android-5.0-lollipop|floating-action-button",
"answer_id": 31179286,
"answer_date": "2015-07-02T08:24:59.733Z",
"answer_score": 1215
} |
Please answer the following Stack Overflow question:
Title: What's the difference between getPath(), getAbsolutePath(), and getCanonicalPath() in Java?
<p>What's the difference between <code>getPath()</code>, <code>getAbsolutePath()</code>, and <code>getCanonicalPath()</code> in Java?</p>
<p>And when do I use each one?</p> | <p>Consider these filenames:</p>
<p><code>C:\temp\file.txt</code> - This is a path, an absolute path, and a canonical path.</p>
<p><code>.\file.txt</code> - This is a path. It's neither an absolute path nor a canonical path.</p>
<p><code>C:\temp\myapp\bin\..\\..\file.txt</code> - This is a path and an absolute path. It's not a canonical path.</p>
<p>A canonical path is always an absolute path.</p>
<p>Converting from a path to a canonical path makes it absolute (usually tack on the current working directory so e.g. <code>./file.txt</code> becomes <code>c:/temp/file.txt</code>). The canonical path of a file just "purifies" the path, removing and resolving stuff like <code>..\</code> and resolving symlinks (on unixes).</p>
<p>Also note the following example with nio.Paths:</p>
<pre><code>String canonical_path_string = "C:\\Windows\\System32\\";
String absolute_path_string = "C:\\Windows\\System32\\drivers\\..\\";
System.out.println(Paths.get(canonical_path_string).getParent());
System.out.println(Paths.get(absolute_path_string).getParent());
</code></pre>
<p>While both paths refer to the same location, the output will be quite different:</p>
<pre><code>C:\Windows
C:\Windows\System32\drivers
</code></pre> | {
"question_id": 1099300,
"question_date": "2009-07-08T16:53:51.690Z",
"question_score": 628,
"tags": "java",
"answer_id": 1099370,
"answer_date": "2009-07-08T17:11:23.560Z",
"answer_score": 664
} |
Please answer the following Stack Overflow question:
Title: How do I pick randomly from an array?
<p>I want to know if there is a much cleaner way of doing this. Basically, I want to pick a random element from an array of variable length. Normally, I would do it like this:</p>
<pre><code>myArray = ["stuff", "widget", "ruby", "goodies", "java", "emerald", "etc" ]
item = myArray[rand(myarray.length)]
</code></pre>
<p>Is there something that is more readable / simpler to replace the second line? Or is that the best way to do it. I suppose you could do <code>myArray.shuffle.first</code>, but I only saw <code>#shuffle</code> a few minutes ago on SO, I haven't actually used it yet.</p> | <p>Just use <a href="http://ruby-doc.org/core-1.9.3/Array.html#method-i-sample" rel="noreferrer"><code>Array#sample</code></a>:</p>
<pre><code>[:foo, :bar].sample # => :foo, or :bar :-)
</code></pre>
<p>It is available in Ruby 1.9.1+. To be also able to use it with an earlier version of Ruby, you could <a href="https://github.com/marcandre/backports" rel="noreferrer"><code>require "backports/1.9.1/array/sample"</code></a>.</p>
<p>Note that in Ruby 1.8.7 it exists under the unfortunate name <code>choice</code>; it was renamed in later version so you shouldn't use that.</p>
<p>Although not useful in this case, <code>sample</code> accepts a number argument in case you want a number of distinct samples.</p> | {
"question_id": 3482149,
"question_date": "2010-08-14T05:26:49.963Z",
"question_score": 628,
"tags": "ruby|arrays|random",
"answer_id": 3483802,
"answer_date": "2010-08-14T14:39:35.490Z",
"answer_score": 1240
} |
Please answer the following Stack Overflow question:
Title: Is it possible to use Java 8 for Android development?
<p>Searching the web, it is not clear if Java 8 is supported for Android development or not.</p>
<p>Before I download/setup Java 8, can some one point me at any "official" documentation that says Java 8 is or is not supported for Android development.</p> | <h2>java 8</h2>
<p>Android supports all Java 7 language features and a subset of Java 8 language features that vary by platform version.</p>
<p>To check which features of java 8 are supported </p>
<p><a href="https://developer.android.com/studio/write/java8-support.html" rel="noreferrer">Use Java 8 language features</a></p>
<blockquote>
<p>We've decided to add support for Java 8 language features directly into the current javac and dx set of tools, and deprecate the Jack toolchain. With this new direction, existing tools and plugins dependent on the Java class file format should continue to work. Moving forward, Java 8 language features will be natively supported by the Android build system. We're aiming to launch this as part of Android Studio in the coming weeks, and we wanted to share this decision early with you. </p>
</blockquote>
<p><a href="https://android-developers.googleblog.com/2017/03/future-of-java-8-language-feature.html" rel="noreferrer">Future of Java 8 Language Feature Support on Android</a></p>
<h2>Eclipse Users:</h2>
<p>For old developers who prefer Eclipse, <a href="https://developer.android.com/sdk/installing/installing-adt.html" rel="noreferrer">google stops support Eclipse Android Developer tools</a></p>
<p>if you installed Java 8 JDK, then give it a try, if any problems appears try to set the compiler as 1.6 in Eclipse from window menu → <strong>Preferences</strong> → <strong>Java</strong> → <strong>Compiler</strong>.
Java 7 will works too:</p>
<p><img src="https://i.stack.imgur.com/SCTyV.png" alt="Eclipse Preferences -> Java -> Compiler"></p>
<blockquote>
<p>Java 7 or higher is required if you are targeting Android 5.0 and
higher.</p>
</blockquote>
<p>install multiple JDK and try.</p> | {
"question_id": 23318109,
"question_date": "2014-04-27T00:40:43.717Z",
"question_score": 628,
"tags": "java|android|java-8|android-gradle-plugin",
"answer_id": 23318269,
"answer_date": "2014-04-27T01:10:12.387Z",
"answer_score": 196
} |
Please answer the following Stack Overflow question:
Title: Are the PUT, DELETE, HEAD, etc methods available in most web browsers?
<p>I've seen a couple questions around here like <a href="https://stackoverflow.com/questions/165720/how-to-debug-restful-services">How to debug RESTful services</a>, which mentions:</p>
<blockquote>
<p>Unfortunately that same browser won't allow me to test HTTP PUT, DELETE, and to a certain degree even HTTP POST.</p>
</blockquote>
<p>I've also heard that browsers support only GET and POST, from some other sources like:</p>
<ul>
<li><a href="http://www.packetizer.com/ws/rest.html" rel="noreferrer">http://www.packetizer.com/ws/rest.html</a></li>
<li><a href="http://www.mail-archive.com/[email protected]/msg13518.html" rel="noreferrer">http://www.mail-archive.com/[email protected]/msg13518.html</a></li>
<li><a href="http://www.xml.com/cs/user/view/cs_msg/1098" rel="noreferrer">http://www.xml.com/cs/user/view/cs_msg/1098</a></li>
</ul>
<p>However, a few quick tests in Firefox show that sending <code>PUT</code> and <code>DELETE</code> requests works as expected -- the <code>XMLHttpRequest</code> completes successfully, and the request shows up in the server logs with the right method. Is there some aspect to this I'm missing, such as cross-browser compatibility or non-obvious limitations?</p> | <p>No. The <a href="http://w3c.github.io/html/sec-forms.html#form-control-infrastructure-form-submission" rel="noreferrer">HTML 5 spec</a> mentions:</p>
<blockquote>
<p>The method and formmethod content attributes are enumerated attributes
with the following keywords and states:</p>
<p>The keyword <strong>get</strong>, mapping to the state GET, indicating the HTTP GET
method. The GET method should only request and retrieve data and
should have no other effect. </p>
<p>The keyword <strong>post</strong>, mapping to the state
POST, indicating the HTTP POST method. The POST method requests that
the server accept the submitted form's data to be processed, which may
result in an item being added to a database, the creation of a new web
page resource, the updating of the existing page, or all of the
mentioned outcomes.</p>
<p>The keyword <strong>dialog</strong>, mapping to the state dialog, indicating that
submitting the form is intended to close the dialog box in which the
form finds itself, if any, and otherwise not submit. </p>
<p>The invalid value default for these attributes is the GET state</p>
</blockquote>
<p>I.e. HTML forms only support <strong>GET</strong> and <strong>POST</strong> as HTTP request methods. A workaround for this is to tunnel other methods through POST by using a hidden form field which is read by the server and the request dispatched accordingly.</p>
<p>However, <strong>GET</strong>, <strong>POST</strong>, <strong>PUT</strong> and <strong>DELETE</strong> <em>are</em> supported by the implementations of XMLHttpRequest (i.e. AJAX calls) in all the major web browsers (IE, Firefox, Safari, Chrome, Opera).</p> | {
"question_id": 165779,
"question_date": "2008-10-03T05:26:59.697Z",
"question_score": 628,
"tags": "http|cross-browser|browser|ajax",
"answer_id": 166501,
"answer_date": "2008-10-03T12:02:06.047Z",
"answer_score": 473
} |
Please answer the following Stack Overflow question:
Title: Is a GUID unique 100% of the time?
<p>Is a GUID unique 100% of the time?</p>
<p>Will it stay unique over multiple threads?</p> | <blockquote>
<p>While each generated GUID is not
guaranteed to be unique, the total
number of unique keys (2<sup>128</sup> or
3.4×10<sup>38</sup>) is so large that the probability of the same number being
generated twice is very small. For
example, consider the observable
universe, which contains about 5×10<sup>22</sup>
stars; every star could then have
6.8×10<sup>15</sup> universally unique GUIDs.</p>
</blockquote>
<p>From <a href="https://en.wikipedia.org/wiki/Globally_Unique_Identifier" rel="noreferrer">Wikipedia</a>.</p>
<hr />
<p>These are some good articles on how a GUID is made (for .NET) and how you could get the same guid in the right situation.</p>
<p><a href="https://ericlippert.com/2012/04/24/guid-guide-part-one/" rel="noreferrer">https://ericlippert.com/2012/04/24/guid-guide-part-one/</a></p>
<p><a href="https://ericlippert.com/2012/04/30/guid-guide-part-two/" rel="noreferrer">https://ericlippert.com/2012/04/30/guid-guide-part-two/</a></p>
<p><a href="https://ericlippert.com/2012/05/07/guid-guide-part-three/" rel="noreferrer">https://ericlippert.com/2012/05/07/guid-guide-part-three/</a></p>
<p></p> | {
"question_id": 39771,
"question_date": "2008-09-02T15:17:22.680Z",
"question_score": 628,
"tags": "language-agnostic|guid",
"answer_id": 39776,
"answer_date": "2008-09-02T15:19:17.450Z",
"answer_score": 507
} |
Please answer the following Stack Overflow question:
Title: How can I return NULL from a generic method in C#?
<p>I have a generic method with this (dummy) code (yes I'm aware IList has predicates, but my code is not using IList but some other collection, anyway this is irrelevant for the question...)</p>
<pre class="lang-cs prettyprint-override"><code> static T FindThing<T>(IList collection, int id) where T : IThing, new()
{
foreach (T thing in collection)
{
if (thing.Id == id)
return thing;
}
return null; // ERROR: Cannot convert null to type parameter 'T' because it could be a value type. Consider using 'default(T)' instead.
}
</code></pre>
<p>This gives me a build error</p>
<blockquote>
<p>"Cannot convert null to type parameter
'T' because it could be a value type.
Consider using 'default(T)' instead."</p>
</blockquote>
<p>Can I avoid this error?</p> | <p>Three options:</p>
<ul>
<li>Return <code>default</code> (or <code>default(T)</code> for older versions of C#) which means you'll return <code>null</code> if <code>T</code> is a reference type (or a nullable value type), <code>0</code> for <code>int</code>, <code>'\0'</code> for <code>char</code>, etc. (<a href="https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/default-values-table" rel="noreferrer">Default values table (C# Reference)</a>)</li>
<li>If you're happy to restrict <code>T</code> to be a reference type with the <code>where T : class</code> constraint and then return <code>null</code> as normal</li>
<li>If you're happy to restrict <code>T</code> to be a non-nullable value type with the <code>where T : struct</code> constraint, then again you can return <code>null</code> as normal from a method with a return value of <code>T?</code> - note that this is <em>not</em> returning a null reference, but the null value of the nullable value type.</li>
</ul> | {
"question_id": 302096,
"question_date": "2008-11-19T14:51:41.877Z",
"question_score": 628,
"tags": "c#|generics",
"answer_id": 302129,
"answer_date": "2008-11-19T14:59:53.577Z",
"answer_score": 1114
} |
Please answer the following Stack Overflow question:
Title: Understanding REST: Verbs, error codes, and authentication
<p>I am looking for a way to wrap APIs around default functions in my PHP-based web applications, databases and CMSs. </p>
<p>I have looked around and found several "skeleton" frameworks. In addition to the answers in my question, there is <a href="http://tonic.sourceforge.net/" rel="noreferrer">Tonic</a>, a REST framework I like because it is very lightweight.</p>
<p>I like REST the best for its simplicity, and would like to create an API architecture based on it. I'm trying to get my head around the basic principles and have not fully understood it yet. Therefore, a number of questions.</p>
<p><strong>1. Am I understanding it right?</strong></p>
<p>Say I have a resource "users". I could set up a number of URIs like so:</p>
<pre><code>/api/users when called with GET, lists users
/api/users when called with POST, creates user record
/api/users/1 when called with GET, shows user record
when called with PUT, updates user record
when called with DELETE, deletes user record
</code></pre>
<p>is this a correct representation of a RESTful architecture so far?</p>
<p><strong>2. I need more verbs</strong></p>
<p>Create, Update and Delete may be enough in theory, but in practice I will have the need for a lot more verbs. I realize these are things that <em>could</em> be embedded in an update request, but they are specific actions that can have specific return codes and I wouldn't want to throw them all into one action.</p>
<p>Some that come to mind in the user example are:</p>
<pre><code>activate_login
deactivate_login
change_password
add_credit
</code></pre>
<p>how would I express actions such as those in a RESTful URL architecture?</p>
<p>My instinct would be to do a GET call to a URL like </p>
<pre><code>/api/users/1/activate_login
</code></pre>
<p>and expect a status code back. </p>
<p>That deviates from the idea of using HTTP verbs, though. What do you think?</p>
<p><strong>3. How to return error messages and codes</strong></p>
<p>A great part of REST's beauty stems from its use of standard HTTP methods. On an error, I emit a header with a 3xx,4xx or 5xx error status code. For a detailed error description, I can use the body (right?). So far so good. But what would be the way to transmit a <strong>proprietary error code</strong> that is more detailed in describing what went wrong (e.g. "failed to connect to database", or "database login wrong")? If I put it into the body along with the message, I have to parse it out afterwards. Is there a standard header for this kind of thing?</p>
<p><strong>4. How to do authentication</strong></p>
<ul>
<li>What would a API key based authentication following REST principles look like?</li>
<li>Are there strong points against using sessions when authenticating a REST client, other than that it's a blatant violation of the REST principle? :) (only half kidding here, session based authentication would play well with my existing infrastructure.)</li>
</ul> | <p>I noticed this question a couple of days late, but I feel that I can add some insight. I hope this can be helpful towards your RESTful venture.</p>
<hr>
<p><strong>Point 1: Am I understanding it right?</strong></p>
<p>You understood right. That is a correct representation of a RESTful architecture. You may find the following matrix from <a href="http://en.wikipedia.org/wiki/Representational_State_Transfer#Applied_to_web_services" rel="noreferrer">Wikipedia</a> very helpful in defining your nouns and verbs:</p>
<hr>
<p>When dealing with a <strong>Collection</strong> URI like: <strong><code>http://example.com/resources/</code></strong></p>
<ul>
<li><p><strong>GET</strong>: List the members of the collection, complete with their member URIs for further navigation. For example, list all the cars for sale.</p></li>
<li><p><strong>PUT</strong>: Meaning defined as "replace the entire collection with another collection".</p></li>
<li><p><strong>POST</strong>: Create a new entry in the collection where the ID is assigned automatically by the collection. The ID created is usually included as part of the data returned by this operation.</p></li>
<li><p><strong>DELETE</strong>: Meaning defined as "delete the entire collection".</p></li>
</ul>
<hr>
<p>When dealing with a <strong>Member</strong> URI like: <strong><code>http://example.com/resources/7HOU57Y</code></strong></p>
<ul>
<li><p><strong>GET</strong>: Retrieve a representation of the addressed member of the collection expressed in an appropriate MIME type.</p></li>
<li><p><strong>PUT</strong>: Update the addressed member of the collection or create it with the specified ID.</p></li>
<li><p><strong>POST</strong>: Treats the addressed member as a collection in its own right and creates a new subordinate of it.</p></li>
<li><p><strong>DELETE</strong>: Delete the addressed member of the collection.</p></li>
</ul>
<hr>
<p><strong>Point 2: I need more verbs</strong></p>
<p>In general, when you think you need more verbs, it may actually mean that your resources need to be re-identified. Remember that in REST you are always acting on a resource, or on a collection of resources. What you choose as the resource is quite important for your API definition.</p>
<p><strong>Activate/Deactivate Login</strong>: If you are creating a new session, then you may want to consider "the session" as the resource. To create a new session, use POST to <code>http://example.com/sessions/</code> with the credentials in the body. To expire it use PUT or a DELETE (maybe depending on whether you intend to keep a session history) to <code>http://example.com/sessions/SESSION_ID</code>.</p>
<p><strong>Change Password:</strong> This time the resource is "the user". You would need a PUT to <code>http://example.com/users/USER_ID</code> with the old and new passwords in the body. You are acting on "the user" resource, and a change password is simply an update request. It's quite similar to the UPDATE statement in a relational database.</p>
<blockquote>
<p>My instinct would be to do a GET call
to a URL like
<code>/api/users/1/activate_login</code></p>
</blockquote>
<p>This goes against a very core REST principle: The correct usage of HTTP verbs. Any GET request should never leave any side effect. </p>
<p>For example, a GET request should never create a session on the database, return a cookie with a new Session ID, or leave any residue on the server. The GET verb is like the SELECT statement in a database engine. Remember that the response to any request with the GET verb should be cache-able when requested with the same parameters, just like when you request a static web page.</p>
<hr>
<p><strong>Point 3: How to return error messages and codes</strong> </p>
<p>Consider the 4xx or 5xx HTTP status codes as error categories. You can elaborate the error in the body.</p>
<p><strong>Failed to Connect to Database:</strong> / <strong>Incorrect Database Login</strong>: In general you should use a 500 error for these types of errors. This is a server-side error. The client did nothing wrong. 500 errors are normally considered "retryable". i.e. the client can retry the same exact request, and expect it to succeed once the server's troubles are resolved. Specify the details in the body, so that the client will be able to provide some context to us humans.</p>
<p>The other category of errors would be the 4xx family, which in general indicate that the client did something wrong. In particular, this category of errors normally indicate to the client that there is no need to retry the request as it is, because it will continue to fail permanently. i.e. the client needs to change something before retrying this request. For example, "Resource not found" (HTTP 404) or "Malformed Request" (HTTP 400) errors would fall in this category.</p>
<hr>
<p><strong>Point 4: How to do authentication</strong></p>
<p>As pointed out in point 1, instead of authenticating a user, you may want to think about creating a session. You will be returned a new "Session ID", along with the appropriate HTTP status code (200: Access Granted or 403: Access Denied).</p>
<p>You will then be asking your RESTful server: "Can you GET me the resource for this Session ID?". </p>
<p>There is no authenticated mode - REST is stateless: You create a session, you ask the server to give you resources using this Session ID as a parameter, and on logout you drop or expire the session. </p> | {
"question_id": 2001773,
"question_date": "2010-01-04T19:55:36.773Z",
"question_score": 628,
"tags": "web-services|rest",
"answer_id": 2022938,
"answer_date": "2010-01-07T19:13:00.017Z",
"answer_score": 648
} |
Please answer the following Stack Overflow question:
Title: Do Swift-based applications work on OS X 10.9/iOS 7 and lower?
<p>Will Swift-based applications work on <a href="http://en.wikipedia.org/wiki/OS_X_Mavericks" rel="noreferrer">OS X 10.9</a> (Mavericks)/iOS 7 and lower?</p>
<p>For example, I have a machine running <a href="http://en.wikipedia.org/wiki/OS_X_Mountain_Lion" rel="noreferrer">OS X 10.8</a> (Mountain Lion), and I am wondering if an application I write in Swift will run on it.</p>
<p>Or what should I have to create a Swift application using Mac OS?</p> | <p>I just tested it for you, Swift applications compile into standard binaries and can be run on OS X 10.9 and iOS 7.</p>
<hr>
<p>Simple Swift application used for testing:</p>
<pre><code>func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
var controller = UIViewController()
var view = UIView(frame: CGRectMake(0, 0, 320, 568))
view.backgroundColor = UIColor.redColor()
controller.view = view
var label = UILabel(frame: CGRectMake(0, 0, 200, 21))
label.center = CGPointMake(160, 284)
label.textAlignment = NSTextAlignment.Center
label.text = "I'am a test label"
controller.view.addSubview(label)
self.window!.rootViewController = controller
self.window!.makeKeyAndVisible()
return true
}
</code></pre> | {
"question_id": 24001778,
"question_date": "2014-06-02T19:25:57.273Z",
"question_score": 628,
"tags": "swift|xcode|macos",
"answer_id": 24002461,
"answer_date": "2014-06-02T20:11:35.790Z",
"answer_score": 523
} |
Please answer the following Stack Overflow question:
Title: How to convert comma-separated String to List?
<p>Is there any built-in method in Java which allows us to convert comma separated String to some container (e.g array, List or Vector)? Or do I need to write custom code for that?</p>
<pre><code>String commaSeparated = "item1 , item2 , item3";
List<String> items = //method that converts above string into list??
</code></pre> | <p><strong>Convert comma separated String to List</strong></p>
<pre><code>List<String> items = Arrays.asList(str.split("\\s*,\\s*"));
</code></pre>
<p>The above code splits the string on a delimiter defined as: <code>zero or more whitespace, a literal comma, zero or more whitespace</code> which will place the words into the list and collapse any whitespace between the words and commas.</p>
<hr>
<p>Please note that this returns simply a wrapper on an array: you <strong><em>CANNOT</em></strong> for example <code>.remove()</code> from the resulting <code>List</code>. For an actual <code>ArrayList</code> you must further use <code>new ArrayList<String></code>.</p> | {
"question_id": 7488643,
"question_date": "2011-09-20T16:40:02.903Z",
"question_score": 627,
"tags": "java|string|collections|split",
"answer_id": 7488676,
"answer_date": "2011-09-20T16:42:47.930Z",
"answer_score": 1148
} |
Please answer the following Stack Overflow question:
Title: Python exit commands - why so many and when should each be used?
<p>It seems that python supports many different commands to stop script execution.<br>The choices I've found are: <code>quit()</code>, <code>exit()</code>, <code>sys.exit()</code>, <code>os._exit()</code> </p>
<p>Have I missed any?
What's the difference between them? When would you use each?</p> | <p>The functions<sup>*</sup> <code>quit()</code>, <code>exit()</code>, and <code>sys.exit()</code> function in the same way: they raise the <code>SystemExit</code> exception. So there is no real difference, except that <code>sys.exit()</code> is always available but <code>exit()</code> and <code>quit()</code> are only available if the <code>site</code> module is imported (<a href="https://docs.python.org/3/library/constants.html#constants-added-by-the-site-module" rel="noreferrer">docs</a>).</p>
<p>The <code>os._exit()</code> function is special, it exits immediately without calling any cleanup functions (it doesn't flush buffers, for example). This is designed for highly specialized use cases... basically, only in the child after an <code>os.fork()</code> call.</p>
<h2>Conclusion</h2>
<ul>
<li><p>Use <code>exit()</code> or <code>quit()</code> in the REPL.</p>
</li>
<li><p>Use <code>sys.exit()</code> in scripts, or <code>raise SystemExit()</code> if you prefer.</p>
</li>
<li><p>Use <code>os._exit()</code> for child processes to exit after a call to <code>os.fork()</code>.</p>
</li>
</ul>
<p>All of these can be called without arguments, or you can specify the exit status, e.g., <code>exit(1)</code> or <code>raise SystemExit(1)</code> to exit with status 1. Note that portable programs are limited to exit status codes in the range 0-255, if you <code>raise SystemExit(256)</code> on many systems this will get truncated and your process will actually exit with status 0.</p>
<h3>Footnotes</h3>
<p><sup>*</sup> Actually, <code>quit()</code> and <code>exit()</code> are callable instance objects, but I think it's okay to call them functions.</p> | {
"question_id": 19747371,
"question_date": "2013-11-02T22:00:32.197Z",
"question_score": 627,
"tags": "python",
"answer_id": 19747557,
"answer_date": "2013-11-02T22:22:20.640Z",
"answer_score": 132
} |
Please answer the following Stack Overflow question:
Title: Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
<p>What might be causing the error <code>Error: EACCES: permission denied, access '/usr/local/lib/node_modules'</code>?</p>
<pre><code>npm ERR! path /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR! { Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/local/lib/node_modules' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/macbookmd101/.npm/_logs/2018-02-21T16_26_08_421Z-debug.log
</code></pre> | <p>Change your file permissions... Like this</p>
<p>First check who owns the directory</p>
<pre><code>ls -la /usr/local/lib/node_modules
</code></pre>
<p>it is denying access because the node_module folder is owned by root</p>
<pre><code>drwxr-xr-x 3 root wheel 102 Jun 24 23:24 node_modules
</code></pre>
<p>so this needs to be changed by changing root to your user but first run command below to check your current user <a href="https://stackoverflow.com/questions/1104972/how-do-i-get-the-name-of-the-active-user-via-the-command-line-in-os-x">How do I get the name of the active user via the command line in OS X?</a></p>
<p><code>id -un</code> OR <code>whoami</code></p>
<p>Then change owner</p>
<pre><code>sudo chown -R [owner]:[owner] /usr/local/lib/node_modules
</code></pre>
<p>OR</p>
<pre><code>sudo chown -R ownerName: /usr/local/lib/node_modules
</code></pre>
<p>OR</p>
<pre><code>sudo chown -R $USER /usr/local/lib/node_modules
</code></pre> | {
"question_id": 48910876,
"question_date": "2018-02-21T16:30:30.410Z",
"question_score": 627,
"tags": "node.js|npm|permission-denied",
"answer_id": 51024493,
"answer_date": "2018-06-25T13:19:33.850Z",
"answer_score": 982
} |
Please answer the following Stack Overflow question:
Title: Is it possible to insert multiple rows at a time in an SQLite database?
<p>In MySQL you can insert multiple rows like this:</p>
<pre><code>INSERT INTO 'tablename' ('column1', 'column2') VALUES
('data1', 'data2'),
('data1', 'data2'),
('data1', 'data2'),
('data1', 'data2');
</code></pre>
<p>However, I am getting an error when I try to do something like this. Is it possible to insert multiple rows at a time in an SQLite database? What is the syntax to do that?</p> | <h2>update</h2>
<p>As <a href="https://stackoverflow.com/a/1609688/558639">BrianCampbell points out here</a>, <strong>SQLite 3.7.11 and above now supports the simpler syntax of the original post</strong>. However, the approach shown is still appropriate if you want maximum compatibility across legacy databases.</p>
<h2>original answer</h2>
<p>If I had privileges, I would bump <a href="https://stackoverflow.com/a/1734067/356895">river's reply</a>: You <strong>can</strong> insert multiple rows in SQLite, you just need <strong>different syntax</strong>. To make it perfectly clear, the OPs MySQL example:</p>
<pre><code>INSERT INTO 'tablename' ('column1', 'column2') VALUES
('data1', 'data2'),
('data1', 'data2'),
('data1', 'data2'),
('data1', 'data2');
</code></pre>
<p>This can be recast into SQLite as:</p>
<pre><code> INSERT INTO 'tablename'
SELECT 'data1' AS 'column1', 'data2' AS 'column2'
UNION ALL SELECT 'data1', 'data2'
UNION ALL SELECT 'data1', 'data2'
UNION ALL SELECT 'data1', 'data2'
</code></pre>
<h2>a note on performance</h2>
<p>I originally used this technique to efficiently load large datasets from Ruby on Rails. <strong>However</strong>, <a href="https://stackoverflow.com/a/5209093/558639">as Jaime Cook points out</a>, it's not clear this is any faster wrapping individual <code>INSERTs</code> within a single transaction:</p>
<pre><code>BEGIN TRANSACTION;
INSERT INTO 'tablename' table VALUES ('data1', 'data2');
INSERT INTO 'tablename' table VALUES ('data3', 'data4');
...
COMMIT;
</code></pre>
<p>If efficiency is your goal, you should try this first.</p>
<h2>a note on UNION vs UNION ALL</h2>
<p>As several people commented, if you use <code>UNION ALL</code> (as shown above), all rows will be inserted, so in this case, you'd get four rows of <code>data1, data2</code>. If you omit the <code>ALL</code>, then duplicate rows will be eliminated (and the operation will presumably be a bit slower). We're using UNION ALL since it more closely matches the semantics of the original post.</p>
<h2>in closing</h2>
<p>P.S.: Please +1 <a href="https://stackoverflow.com/a/1734067/356895">river's reply</a>, as it presented the solution first.</p> | {
"question_id": 1609637,
"question_date": "2009-10-22T20:04:42.983Z",
"question_score": 627,
"tags": "sql|sqlite|syntax",
"answer_id": 5009740,
"answer_date": "2011-02-15T21:29:57.630Z",
"answer_score": 670
} |
Please answer the following Stack Overflow question:
Title: How can I set up an editor to work with Git on Windows?
<p>I'm trying out <strong>Git on Windows</strong>. I got to the point of trying "git commit" and I got this error:</p>
<blockquote>
<p>Terminal is dumb but no VISUAL nor
EDITOR defined. Please supply the
message using either -m or -F option.</p>
</blockquote>
<p>So I figured out I need to have an environment variable called EDITOR. No problem. I set it to point to Notepad. That worked, almost. The default commit message opens in Notepad. But Notepad doesn't support bare line feeds. I went out and got <a href="http://notepad-plus.sourceforge.net/uk/site.htm" rel="noreferrer">Notepad++</a>, but I can't figure out how to get Notepad++ set up as the <code>%EDITOR%</code> in such a way that it works with Git as expected.</p>
<p>I'm not married to Notepad++. At this point I don't mind what editor I use. I just want to be able to <strong>type commit messages in an editor</strong> rather than the command line (with <code>-m</code>).</p>
<p>Those of you using Git on Windows: What tool do you use to edit your commit messages, and what did you have to do to make it work?</p> | <p>Update September 2015 (6 years later)</p>
<p>The <a href="https://github.com/git-for-windows/git/releases/tag/v2.5.3.windows.1" rel="noreferrer">last release of git-for-Windows (2.5.3)</a> now includes:</p>
<blockquote>
<p>By configuring <strong><code>git config core.editor notepad</code></strong>, users <a href="https://github.com/git-for-windows/git/issues/381" rel="noreferrer">can now use <code>notepad.exe</code> as their default editor</a>.<br>
Configuring <code>git config format.commitMessageColumns 72</code> will be picked up by the notepad wrapper and line-wrap the commit message after the user edits it.</p>
</blockquote>
<p>See <a href="https://github.com/git-for-windows/build-extra/commit/69b301bbd7c18226c63d83638991cb2b7f84fb64" rel="noreferrer">commit 69b301b</a> by <a href="https://github.com/dscho" rel="noreferrer">Johannes Schindelin (<code>dscho</code>)</a>.</p>
<p>And Git 2.16 (Q1 2018) will show a message to tell the user that it is waiting for the user to finish editing when spawning an editor, in case the editor
opens to a hidden window or somewhere obscure and the user gets
lost.</p>
<p>See <a href="https://github.com/git/git/commit/abfb04d0c74cde804c734015ff5868a88c84fb6f" rel="noreferrer">commit abfb04d</a> (07 Dec 2017), and <a href="https://github.com/git/git/commit/a64f213d3fa13fa01e582b6734fe7883ed975dc9" rel="noreferrer">commit a64f213</a> (29 Nov 2017) by <a href="https://github.com/larsxschneider" rel="noreferrer">Lars Schneider (<code>larsxschneider</code>)</a>.<br>
Helped-by: <a href="https://github.com/gitster" rel="noreferrer">Junio C Hamano (<code>gitster</code>)</a>.<br>
<sup>(Merged by <a href="https://github.com/gitster" rel="noreferrer">Junio C Hamano -- <code>gitster</code> --</a> in <a href="https://github.com/git/git/commit/0c69a132cb1adf0ce9f31e6631f89321e437cb76" rel="noreferrer">commit 0c69a13</a>, 19 Dec 2017)</sup></p>
<blockquote>
<h2><code>launch_editor()</code>: indicate that Git waits for user input</h2>
<p>When a graphical <code>GIT_EDITOR</code> is spawned by a Git command that opens
and waits for user input (e.g. "<code>git rebase -i</code>"), then the editor window
might be obscured by other windows.<br>
The user might be left staring at
the original Git terminal window without even realizing that s/he needs
to interact with another window before Git can proceed. To this user Git
appears hanging.</p>
<p>Print a message that Git is waiting for editor input in the original
terminal and get rid of it when the editor returns, if the terminal
supports erasing the last line</p>
</blockquote>
<hr>
<p>Original answer</p>
<p>I just tested it with git version 1.6.2.msysgit.0.186.gf7512 and Notepad++5.3.1</p>
<p>I prefer to <em>not</em> have to set an EDITOR variable, so I tried:</p>
<pre class="lang-bash prettyprint-override"><code>git config --global core.editor "\"c:\Program Files\Notepad++\notepad++.exe\""
# or
git config --global core.editor "\"c:\Program Files\Notepad++\notepad++.exe\" %*"
</code></pre>
<p>That always gives:</p>
<pre><code>C:\prog\git>git config --global --edit
"c:\Program Files\Notepad++\notepad++.exe" %*: c:\Program Files\Notepad++\notepad++.exe: command not found
error: There was a problem with the editor '"c:\Program Files\Notepad++\notepad++.exe" %*'.
</code></pre>
<p>If I define a npp.bat including:</p>
<pre><code>"c:\Program Files\Notepad++\notepad++.exe" %*
</code></pre>
<p>and I type:</p>
<pre><code>C:\prog\git>git config --global core.editor C:\prog\git\npp.bat
</code></pre>
<p>It just works from the DOS session, <strong>but not from the git shell</strong>.<br>
(not that with the core.editor configuration mechanism, a script with "<code>start /WAIT...</code>" in it would not work, but only open a new DOS window)</p>
<hr>
<p><a href="https://stackoverflow.com/questions/10564/how-can-i-set-up-an-editor-to-work-with-git-on-windows/1431003#1431003">Bennett's answer</a> mentions the possibility to avoid adding a script, but to reference directly the program itself <strong>between simple quotes</strong>. Note the direction of the slashes! Use <code>/</code> NOT <code>\</code> to separate folders in the path name!</p>
<pre class="lang-bash prettyprint-override"><code>git config --global core.editor \
"'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"
</code></pre>
<p>Or if you are in a 64 bit system:</p>
<pre class="lang-bash prettyprint-override"><code>git config --global core.editor \
"'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"
</code></pre>
<p>But I prefer using a script (see below): that way I can play with different paths or different options without having to register again a <code>git config</code>.</p>
<hr>
<p>The actual solution (with a script) was to realize that:<br>
<strong>what you refer to in the config file is actually a shell (<code>/bin/sh</code>) script</strong>, not a DOS script.</p>
<p>So what does work is:</p>
<pre><code>C:\prog\git>git config --global core.editor C:/prog/git/npp.bat
</code></pre>
<p>with <code>C:/prog/git/npp.bat</code>:</p>
<pre class="lang-bash prettyprint-override"><code>#!/bin/sh
"c:/Program Files/Notepad++/notepad++.exe" -multiInst "$*"
</code></pre>
<p>or</p>
<pre class="lang-bash prettyprint-override"><code>#!/bin/sh
"c:/Program Files/Notepad++/notepad++.exe" -multiInst -notabbar -nosession -noPlugin "$*"
</code></pre>
<p>With that setting, I can do '<code>git config --global --edit</code>' from DOS or Git Shell, or I can do '<code>git rebase -i ...</code>' from DOS or Git Shell.<br>
Bot commands will trigger a new instance of notepad++ (hence the <code>-multiInst</code>' option), and wait for that instance to be closed before going on.</p>
<p>Note that I use only '/', not <code>\</code>'. And I <a href="https://stackoverflow.com/questions/623518/msysgit-on-windows-what-should-i-be-aware-of-if-any">installed msysgit using option 2.</a> (Add the <code>git\bin</code> directory to the <code>PATH</code> environment variable, but without overriding some built-in windows tools)</p>
<p>The fact that the notepad++ wrapper is called .bat is not important.<br>
It would be better to name it 'npp.sh' and to put it in the <code>[git]\cmd</code> directory though (or in any directory referenced by your PATH environment variable).</p>
<hr>
<p>See also:</p>
<ul>
<li><a href="https://stackoverflow.com/questions/255202/how-do-i-view-git-diff-output-with-visual-diff-program/255212#255212">How do I view ‘git diff’ output with visual diff program?</a> for the general theory</li>
<li><a href="https://stackoverflow.com/questions/780425/how-do-i-setup-diffmerge-with-msysgit-gitk/783667#783667">How do I setup DiffMerge with msysgit / gitk?</a> for another example of external tool (DiffMerge, and WinMerge)</li>
</ul>
<hr>
<p><a href="https://stackoverflow.com/users/2716305/lightfire228">lightfire228</a> adds <a href="https://stackoverflow.com/questions/10564/how-can-i-set-up-an-editor-to-work-with-git-on-windows/773973#comment74027740_773973">in the comments</a>:</p>
<blockquote>
<p>For anyone having an issue where N++ just opens a blank file, and git doesn't take your commit message, see "<a href="https://stackoverflow.com/q/30085970/6309">Aborting commit due to empty message</a>": change your <code>.bat</code> or <code>.sh</code> file to say:</p>
</blockquote>
<pre><code>"<path-to-n++" .git/COMMIT_EDITMSG -<arguments>.
</code></pre>
<blockquote>
<p>That will tell notepad++ to open the temp commit file, rather than a blank new one.</p>
</blockquote> | {
"question_id": 10564,
"question_date": "2008-08-14T01:43:04.270Z",
"question_score": 627,
"tags": "windows|git|cygwin|editor",
"answer_id": 773973,
"answer_date": "2009-04-21T18:34:54.007Z",
"answer_score": 612
} |
Please answer the following Stack Overflow question:
Title: Confused about Service vs Factory
<p>As I understand it, when inside a factory I return an object that gets injected into a controller. When inside a service I am dealing with the object using <code>this</code> and not returning anything. </p>
<p>I was under the assumption that a service was <em>always a singleton</em>, and that a <strong>new factory object</strong> gets injected in every controller. However, as it turns out, a factory object is a singleton too?</p>
<p>Example code to demonstrate:</p>
<pre><code>var factories = angular.module('app.factories', []);
var app = angular.module('app', ['ngResource', 'app.factories']);
factories.factory('User', function () {
return {
first: 'John',
last: 'Doe'
};
});
app.controller('ACtrl', function($scope, User) {
$scope.user = User;
});
app.controller('BCtrl', function($scope, User) {
$scope.user = User;
});
</code></pre>
<p>When changing <code>user.first</code> in <code>ACtrl</code> it turns out that <code>user.first</code> in <code>BCtrl</code> is also changed, e.g. <code>User</code> is a singleton? </p>
<p>My assumption was that a new instance was injected in a controller with a factory?</p> | <p><strong>All angular services are singletons</strong>:</p>
<p>Docs (see <em>Services as singletons</em>): <a href="https://docs.angularjs.org/guide/services" rel="noreferrer">https://docs.angularjs.org/guide/services</a></p>
<blockquote>
<p>Lastly, it is important to realize that all Angular services are application singletons. This means that there is only one instance of a given service per injector. </p>
</blockquote>
<p>Basically the difference between the service and factory is as follows:</p>
<pre><code>app.service('myService', function() {
// service is just a constructor function
// that will be called with 'new'
this.sayHello = function(name) {
return "Hi " + name + "!";
};
});
app.factory('myFactory', function() {
// factory returns an object
// you can run some code before
return {
sayHello : function(name) {
return "Hi " + name + "!";
}
}
});
</code></pre>
<p>Check out this presentation about $provide: <a href="http://slides.wesalvaro.com/20121113/#/" rel="noreferrer">http://slides.wesalvaro.com/20121113/#/</a></p>
<p>Those slides were used in one of the AngularJs meetups: <a href="http://blog.angularjs.org/2012/11/more-angularjs-meetup-videos.html" rel="noreferrer">http://blog.angularjs.org/2012/11/more-angularjs-meetup-videos.html</a></p> | {
"question_id": 13762228,
"question_date": "2012-12-07T11:31:55.327Z",
"question_score": 627,
"tags": "angularjs",
"answer_id": 13763886,
"answer_date": "2012-12-07T13:17:36.387Z",
"answer_score": 607
} |
Please answer the following Stack Overflow question:
Title: Should I always use a parallel stream when possible?
<p>With Java 8 and lambdas it's easy to iterate over collections as streams, and just as easy to use a parallel stream. Two examples from <a href="http://docs.oracle.com/javase/tutorial/collections/interfaces/collection.html">the docs</a>, the second one using parallelStream:</p>
<pre><code>myShapesCollection.stream()
.filter(e -> e.getColor() == Color.RED)
.forEach(e -> System.out.println(e.getName()));
myShapesCollection.parallelStream() // <-- This one uses parallel
.filter(e -> e.getColor() == Color.RED)
.forEach(e -> System.out.println(e.getName()));
</code></pre>
<p>As long as I don't care about the order, would it always be beneficial to use the parallel? One would think it is faster dividing the work on more cores.</p>
<p>Are there other considerations? When should parallel stream be used and when should the non-parallel be used?</p>
<p><sup>(This question is asked to trigger a discussion about how and when to use parallel streams, not because I think always using them is a good idea.)</sup></p> | <p>A parallel stream has a much higher overhead compared to a sequential one. Coordinating the threads takes a significant amount of time. I would use sequential streams by default and only consider parallel ones if</p>
<ul>
<li><p>I have a massive amount of items to process (or the processing of each item takes time and is parallelizable)</p></li>
<li><p>I have a performance problem in the first place</p></li>
<li><p>I don't already run the process in a multi-thread environment (for example: in a web container, if I already have many requests to process in parallel, adding an additional layer of parallelism inside each request could have more negative than positive effects)</p></li>
</ul>
<p>In your example, the performance will anyway be driven by the synchronized access to <code>System.out.println()</code>, and making this process parallel will have no effect, or even a negative one.</p>
<p>Moreover, remember that parallel streams don't magically solve all the synchronization problems. If a shared resource is used by the predicates and functions used in the process, you'll have to make sure that everything is thread-safe. In particular, side effects are things you really have to worry about if you go parallel.</p>
<p>In any case, measure, don't guess! Only a measurement will tell you if the parallelism is worth it or not.</p> | {
"question_id": 20375176,
"question_date": "2013-12-04T12:17:46.480Z",
"question_score": 627,
"tags": "java|parallel-processing|java-8|java-stream",
"answer_id": 20375622,
"answer_date": "2013-12-04T12:37:54.250Z",
"answer_score": 857
} |
Please answer the following Stack Overflow question:
Title: Can we have multiple <tbody> in same <table>?
<p>Can we have multiple <code><tbody></code> tags in same <code><table></code>? If yes then in what scenarios should we use multiple <code><tbody></code> tags?</p> | <p>Yes you can use them, for example I use them to more easily style groups of data, like this:</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-css lang-css prettyprint-override"><code>thead th { width: 100px; border-bottom: solid 1px #ddd; font-weight: bold; }
tbody:nth-child(odd) { background: #f5f5f5; border: solid 1px #ddd; }
tbody:nth-child(even) { background: #e5e5e5; border: solid 1px #ddd; }</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><table>
<thead>
<tr><th>Customer</th><th>Order</th><th>Month</th></tr>
</thead>
<tbody>
<tr><td>Customer 1</td><td>#1</td><td>January</td></tr>
<tr><td>Customer 1</td><td>#2</td><td>April</td></tr>
<tr><td>Customer 1</td><td>#3</td><td>March</td></tr>
</tbody>
<tbody>
<tr><td>Customer 2</td><td>#1</td><td>January</td></tr>
<tr><td>Customer 2</td><td>#2</td><td>April</td></tr>
<tr><td>Customer 2</td><td>#3</td><td>March</td></tr>
</tbody>
<tbody>
<tr><td>Customer 3</td><td>#1</td><td>January</td></tr>
<tr><td>Customer 3</td><td>#2</td><td>April</td></tr>
<tr><td>Customer 3</td><td>#3</td><td>March</td></tr>
</tbody>
</table></code></pre>
</div>
</div>
</p>
<p><a href="http://jsfiddle.net/umRJr/" rel="noreferrer">You can view an example here</a>. It'll only work in newer browsers, but that's what I'm supporting in my current application, you can use the grouping for JavaScript etc. The main thing is it's a convenient way to visually group the rows to make the data much more readable. There are other uses of course, but as far as applicable examples, this one is the most common one for me.</p> | {
"question_id": 3076708,
"question_date": "2010-06-19T18:25:10.520Z",
"question_score": 627,
"tags": "html|html-table|xhtml",
"answer_id": 3076790,
"answer_date": "2010-06-19T18:45:14.537Z",
"answer_score": 759
} |
Please answer the following Stack Overflow question:
Title: Making Python loggers output all messages to stdout in addition to log file
<p>Is there a way to make Python logging using the <code>logging</code> module automatically output things to stdout <em>in addition</em> to the log file where they are supposed to go? For example, I'd like all calls to <code>logger.warning</code>, <code>logger.critical</code>, <code>logger.error</code> to go to their intended places but in addition always be copied to <code>stdout</code>. This is to avoid duplicating messages like:</p>
<pre><code>mylogger.critical("something failed")
print "something failed"
</code></pre> | <p>All logging output is handled by the handlers; just add a <a href="http://docs.python.org/library/logging.handlers.html#streamhandler" rel="noreferrer"><code>logging.StreamHandler()</code></a> to the root logger.</p>
<p>Here's an example configuring a stream handler (using <code>stdout</code> instead of the default <code>stderr</code>) and adding it to the root logger:</p>
<pre><code>import logging
import sys
root = logging.getLogger()
root.setLevel(logging.DEBUG)
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
root.addHandler(handler)
</code></pre> | {
"question_id": 14058453,
"question_date": "2012-12-27T17:11:21.280Z",
"question_score": 626,
"tags": "python|logging|error-logging",
"answer_id": 14058475,
"answer_date": "2012-12-27T17:12:56.517Z",
"answer_score": 847
} |
Please answer the following Stack Overflow question:
Title: Share cookie between subdomain and domain
<p>I have two questions. I understand that if I specify the domain as <code>.example.com</code> (with the leading dot) in the cookie that all subdomains can share a cookie.</p>
<p>Can <code>subdomain.example.com</code> access a cookie created in <code>example.com</code> (without the <code>www</code> subdomain)?</p>
<p>Can <code>example.com</code> (without the <code>www</code> subdomain) access the cookie if created in <code>subdomain.example.com</code>?</p> | <p>If you set a cookie like this:</p>
<pre><code>Set-Cookie: name=value
</code></pre>
<p>then the cookie will <strong>only apply to the request domain</strong>, and will only be sent for requests to the exact same domain, not any other subdomains. (See <a href="https://stackoverflow.com/questions/12387338/what-is-a-host-only-cookie">What is a host only cookie?</a>)</p>
<p>Two different domains (e.g. <code>example.com</code> and <code>subdomain.example.com</code>, or <code>sub1.example.com</code> and <code>sub2.example.com</code>) can only share cookies if the <code>domain</code> attribute is present in the header:</p>
<pre><code>Set-Cookie: name=value; domain=example.com
</code></pre>
<p>The domain attribute must "<a href="https://datatracker.ietf.org/doc/html/rfc6265#section-5.1.3" rel="noreferrer">domain-match</a>" the request URL for it to be valid, which basically means it must be the request domain or a super-domain. So this applies for both examples in the question, as well as sharing between two separate subdomains.</p>
<p>This cookie would then be sent for <strong>any subdomain of <em><code>example.com</code></em></strong>, including nested subdomains like <code>subsub.subdomain.example.com</code>. (Bear in mind there are other attributes that could restrict the scope of the cookie and when it gets sent by the browser, like <code>path</code> or <code>Secure</code>).</p>
<p>Because of the way the domain-matching works, if you want <code>sub1.example.com</code> and <code>sub2.example.com</code> to share cookies, then you'll also share them with <code>sub3.example.com</code>.</p>
<p>See also:</p>
<ul>
<li><a href="http://www.phpied.com/www-vs-no-www-and-cookies/" rel="noreferrer">www vs no-www and cookies</a></li>
<li><a href="https://scripts.cmbuckley.co.uk/cookies.php" rel="noreferrer">cookies test script</a> to try it out</li>
</ul>
<hr />
<p>A note on leading dots in <code>domain</code> attributes: In the early <a href="https://datatracker.ietf.org/doc/html/rfc2109" rel="noreferrer">RFC 2109</a>, only domains with a leading dot (<code>domain=.example.com</code>) could be used across subdomains. But this could not be shared with the top-level domain, so what you ask was not possible in the older spec.</p>
<p>However, the newer specification <a href="https://datatracker.ietf.org/doc/html/rfc6265" rel="noreferrer">RFC 6265</a> ignores any leading dot, meaning you can use the cookie on subdomains as well as the top-level domain.</p> | {
"question_id": 18492576,
"question_date": "2013-08-28T15:46:52.767Z",
"question_score": 626,
"tags": "http|cookies|subdomain",
"answer_id": 23086139,
"answer_date": "2014-04-15T14:07:11.507Z",
"answer_score": 966
} |
Please answer the following Stack Overflow question:
Title: git-diff to ignore ^M
<p>In a project where some of the files contains <code>^M</code> as newline separators. Diffing these files are apparently impossible, since git-diff sees it as the entire file is just a single line.</p>
<p>How does one diff with the previous version?</p>
<p>Is there an option like "treat ^M as newline when diffing" ?</p>
<pre><code>prompt> git-diff "HEAD^" -- MyFile.as
diff --git a/myproject/MyFile.as b/myproject/MyFile.as
index be78321..a393ba3 100644
--- a/myproject/MyFile.cpp
+++ b/myproject/MyFile.cpp
@@ -1 +1 @@
-<U+FEFF>import flash.events.MouseEvent;^Mimport mx.controls.*;^Mimport mx.utils.Delegate
\ No newline at end of file
+<U+FEFF>import flash.events.MouseEvent;^Mimport mx.controls.*;^Mimport mx.utils.Delegate
\ No newline at end of file
prompt>
</code></pre>
<hr />
<p>UPDATE:</p>
<p>now I have written a Ruby script that checks out the latest 10 revisions and converts CR to LF.</p>
<pre class="lang-ruby prettyprint-override"><code>require 'fileutils'
if ARGV.size != 3
puts "a git-path must be provided"
puts "a filename must be provided"
puts "a result-dir must be provided"
puts "example:"
puts "ruby gitcrdiff.rb project/dir1/dir2/dir3/ SomeFile.cpp tmp_somefile"
exit(1)
end
gitpath = ARGV[0]
filename = ARGV[1]
resultdir = ARGV[2]
unless FileTest.exist?(".git")
puts "this command must be run in the same dir as where .git resides"
exit(1)
end
if FileTest.exist?(resultdir)
puts "the result dir must not exist"
exit(1)
end
FileUtils.mkdir(resultdir)
10.times do |i|
revision = "^" * i
cmd = "git show HEAD#{revision}:#{gitpath}#{filename} | tr '\\r' '\\n' > #{resultdir}/#{filename}_rev#{i}"
puts cmd
system cmd
end
</code></pre> | <p><a href="https://help.github.com/articles/dealing-with-line-endings/" rel="noreferrer">GitHub suggests</a> that you should make sure to only use \n as a newline character in git-handled repos. There's an option to auto-convert:</p>
<pre><code>$ git config --global core.autocrlf true
</code></pre>
<p>Of course, this is said to convert crlf to lf, while you want to convert cr to lf. I hope this still works …</p>
<p>And then convert your files:</p>
<pre><code># Remove everything from the index
$ git rm --cached -r .
# Re-add all the deleted files to the index
# You should get lots of messages like: "warning: CRLF will be replaced by LF in <file>."
$ git diff --cached --name-only -z | xargs -0 git add
# Commit
$ git commit -m "Fix CRLF"
</code></pre>
<p>core.autocrlf is described on <a href="http://schacon.github.com/git/git-config.html" rel="noreferrer">the man page</a>.</p> | {
"question_id": 1889559,
"question_date": "2009-12-11T17:23:49.190Z",
"question_score": 626,
"tags": "git|diff|newline|git-diff",
"answer_id": 1889699,
"answer_date": "2009-12-11T17:43:44.587Z",
"answer_score": 505
} |
Please answer the following Stack Overflow question:
Title: How to completely uninstall Android Studio on Mac?
<p>I recently downloaded Android Studio on my Macbook Pro and I messed up with it every time I open it. It gives me plugin errors and several other errors. I need to uninstall it completely from my mac. I tried to delete it from my mac and then install it again as if you would do the first time, but it did nothing and now the same problems occur.</p>
<p><strong>How can I manage to remove it completely and install a fresh one again?</strong></p> | <p>Execute these commands in the terminal (excluding the lines with hashtags - they're comments):</p>
<pre class="lang-bash prettyprint-override"><code># Deletes the Android Studio application
# Note that this may be different depending on what you named the application as, or whether you downloaded the preview version
rm -Rf /Applications/Android\ Studio.app
# Delete All Android Studio related preferences
# The asterisk here should target all folders/files beginning with the string before it
rm -Rf ~/Library/Preferences/AndroidStudio*
rm -Rf ~/Library/Preferences/Google/AndroidStudio*
# Deletes the Android Studio's plist file
rm -Rf ~/Library/Preferences/com.google.android.*
# Deletes the Android Emulator's plist file
rm -Rf ~/Library/Preferences/com.android.*
# Deletes mainly plugins (or at least according to what mine (Edric) contains)
rm -Rf ~/Library/Application\ Support/AndroidStudio*
rm -Rf ~/Library/Application\ Support/Google/AndroidStudio*
# Deletes all logs that Android Studio outputs
rm -Rf ~/Library/Logs/AndroidStudio*
rm -Rf ~/Library/Logs/Google/AndroidStudio*
# Deletes Android Studio's caches
rm -Rf ~/Library/Caches/AndroidStudio*
# Deletes older versions of Android Studio
rm -Rf ~/.AndroidStudio*
</code></pre>
<p>If you would like to delete all <strong>projects</strong>:</p>
<pre class="lang-bash prettyprint-override"><code>rm -Rf ~/AndroidStudioProjects
</code></pre>
<p>To remove gradle related files (caches & wrapper)</p>
<pre class="lang-bash prettyprint-override"><code>rm -Rf ~/.gradle
</code></pre>
<p>Use the below command to delete all <strong>Android Virtual Devices</strong>(AVDs) and keystores.</p>
<p><em><strong>Note</strong>: This folder is used by other Android IDEs as well, so if you still using other IDE you may not want to delete this folder)</em></p>
<pre class="lang-bash prettyprint-override"><code>rm -Rf ~/.android
</code></pre>
<p>To delete Android SDK tools</p>
<pre class="lang-bash prettyprint-override"><code>rm -Rf ~/Library/Android*
</code></pre>
<p>Emulator Console Auth Token</p>
<pre class="lang-bash prettyprint-override"><code>rm -Rf ~/.emulator_console_auth_token
</code></pre>
<p>Thanks to those who commented/improved on this answer!</p>
<hr />
<h1>Notes</h1>
<ol>
<li>The flags for <code>rm</code> are case-sensitive<a href="https://linuxacademy.com/community/posts/show/topic/7331-r-flag-vs-r-flag-and-case-sensitivity-question" rel="noreferrer" title="See Linux Academy question for more info"><sup>1</sup></a> (as with most other commands), which means that the <code>f</code> flag must be in lower case. However, the <code>r</code> flag can also be capitalised.</li>
<li>The flags for <code>rm</code> can be either combined together or separated. They don't have to be combined.</li>
</ol>
<h2>What the flags indicate</h2>
<ol>
<li>The <code>r</code> flag indicates that the <code>rm</code> command should-
<blockquote>
<p>a<em>ttempt to remove the file hierarchy rooted in each file argument.</em> - <strong>DESCRIPTION</strong> section on the manpage for <code>rm</code> (See <code>man rm</code> for more info)</p>
</blockquote>
</li>
<li>The <code>f</code> flag indicates that the <code>rm</code> command should-
<blockquote>
<p>a<em>ttempt to remove the files without prompting for confirmation, regardless of the file's permissions.</em> - <strong>DESCRIPTION</strong> section on the manpage for <code>rm</code> (See <code>man rm</code> for more info)</p>
</blockquote>
</li>
</ol> | {
"question_id": 17625622,
"question_date": "2013-07-12T23:56:17.740Z",
"question_score": 626,
"tags": "macos|android-studio|uninstallation",
"answer_id": 18458893,
"answer_date": "2013-08-27T06:54:57.087Z",
"answer_score": 1533
} |
Please answer the following Stack Overflow question:
Title: How to set up fixed width for <td>?
<p>Simple scheme:</p>
<pre><code> <tr class="something">
<td>A</td>
<td>B</td>
<td>C</td>
<td>D</td>
</tr>
</code></pre>
<p>I need to set up a fixed width for <code><td></code>. I've tried:</p>
<pre><code>tr.something {
td {
width: 90px;
}
}
</code></pre>
<p>Also</p>
<pre><code>td.something {
width: 90px;
}
</code></pre>
<p>for </p>
<pre><code><td class="something">B</td>
</code></pre>
<p>And even</p>
<pre><code><td style="width: 90px;">B</td>
</code></pre>
<p>But the width of <code><td></code> is still the same.</p> | <h2>For Bootstrap 4.0:</h2>
<p>In Bootstrap 4.0.0 you cannot use the <code>col-*</code> classes reliably (works in Firefox, but not in Chrome).
You need to use <a href="https://stackoverflow.com/a/34987484/2256700">OhadR's answer</a>:</p>
<pre><code><tr>
<th style="width: 16.66%">Col 1</th>
<th style="width: 25%">Col 2</th>
<th style="width: 50%">Col 4</th>
<th style="width: 8.33%">Col 5</th>
</tr>
</code></pre>
<h2>For Bootstrap 3.0:</h2>
<p>With twitter bootstrap 3 use: <code>class="col-md-*"</code> where * is a number of columns of width.</p>
<pre><code><tr class="something">
<td class="col-md-2">A</td>
<td class="col-md-3">B</td>
<td class="col-md-6">C</td>
<td class="col-md-1">D</td>
</tr>
</code></pre>
<h2>For Bootstrap 2.0:</h2>
<p>With twitter bootstrap 2 use: <code>class="span*"</code> where * is a number of columns of width.</p>
<pre><code><tr class="something">
<td class="span2">A</td>
<td class="span3">B</td>
<td class="span6">C</td>
<td class="span1">D</td>
</tr>
</code></pre>
<p>** If you have <code><th></code> elements set the width there and not on the <code><td></code> elements.</p> | {
"question_id": 15115052,
"question_date": "2013-02-27T14:50:11.010Z",
"question_score": 625,
"tags": "css|twitter-bootstrap|width|html-table",
"answer_id": 18498071,
"answer_date": "2013-08-28T20:58:46.523Z",
"answer_score": 1264
} |
Please answer the following Stack Overflow question:
Title: What is the printf format specifier for bool?
<p>Since ANSI C99 there is <code>_Bool</code> or <code>bool</code> via <code>stdbool.h</code>. But is there also a <code>printf</code> format specifier for bool?</p>
<p>I mean something like in that pseudo code:</p>
<pre><code>bool x = true;
printf("%B\n", x);
</code></pre>
<p>which would print:</p>
<pre><code>true
</code></pre> | <p>There is no format specifier for <code>bool</code> types. However, since any integral type shorter than <code>int</code> is promoted to <code>int</code> when passed down to <code>printf()</code>'s variadic arguments, you can use <code>%d</code>:</p>
<pre><code>bool x = true;
printf("%d\n", x); // prints 1
</code></pre>
<p>But why not:</p>
<pre><code>printf(x ? "true" : "false");
</code></pre>
<p>or, better:</p>
<pre><code>printf("%s", x ? "true" : "false");
</code></pre>
<p>or, even better:</p>
<pre><code>fputs(x ? "true" : "false", stdout);
</code></pre>
<p>instead?</p> | {
"question_id": 17307275,
"question_date": "2013-06-25T20:50:17.033Z",
"question_score": 625,
"tags": "c|boolean|printf",
"answer_id": 17307307,
"answer_date": "2013-06-25T20:52:10.597Z",
"answer_score": 963
} |
Please answer the following Stack Overflow question:
Title: SQL Server: Database stuck in "Restoring" state
<p>I backed up a database:</p>
<pre><code>BACKUP DATABASE MyDatabase
TO DISK = 'MyDatabase.bak'
WITH INIT --overwrite existing
</code></pre>
<p>And then tried to restore it:</p>
<pre><code>RESTORE DATABASE MyDatabase
FROM DISK = 'MyDatabase.bak'
WITH REPLACE --force restore over specified database
</code></pre>
<p>And now the database is stuck in the restoring state.</p>
<p>Some people have theorized that it's because there was no log file in the backup, and it needed to be rolled forward using:</p>
<pre><code>RESTORE DATABASE MyDatabase
WITH RECOVERY
</code></pre>
<p>Except that, of course, fails:</p>
<pre><code>Msg 4333, Level 16, State 1, Line 1
The database cannot be recovered because the log was not restored.
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.
</code></pre>
<p>And exactly what you want in a catastrophic situation is a restore that won't work.</p>
<hr>
<p>The backup contains both a data and log file:</p>
<pre><code>RESTORE FILELISTONLY
FROM DISK = 'MyDatabase.bak'
Logical Name PhysicalName
============= ===============
MyDatabase C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\MyDatabase.mdf
MyDatabase_log C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\MyDatabase_log.LDF
</code></pre> | <p>You need to use the <code>WITH RECOVERY</code> option, with your database <code>RESTORE</code> command, to bring your database online as part of the restore process.</p>
<p>This is of course only if you do not intend to restore any transaction log backups, i.e. you only wish to restore a database backup and then be able to access the database.</p>
<p>Your command should look like this,</p>
<pre><code>RESTORE DATABASE MyDatabase
FROM DISK = 'MyDatabase.bak'
WITH REPLACE,RECOVERY
</code></pre>
<p>You may have more sucess using the restore database wizard in SQL Server Management Studio. This way you can select the specific file locations, the overwrite option, and the WITH Recovery option.</p> | {
"question_id": 520967,
"question_date": "2009-02-06T16:21:45.040Z",
"question_score": 625,
"tags": "sql-server|backup|restore",
"answer_id": 521039,
"answer_date": "2009-02-06T16:39:44.100Z",
"answer_score": 467
} |
Please answer the following Stack Overflow question:
Title: How to allow <input type="file"> to accept only image files?
<p>I need to upload only image file through <code><input type="file"></code> tag. </p>
<p>Right now, it accepts all file types. But, I want to restrict it to only specific image file extensions which include <code>.jpg</code>, <code>.gif</code> etc.</p>
<p>How can I achieve this functionality?</p> | <p>Use the <strong>accept</strong> attribute of the input tag. To accept only PNG's, JPEG's and GIF's you can use the following code:</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code><label>Your Image File
<input type="file" name="myImage" accept="image/png, image/gif, image/jpeg" />
</label></code></pre>
</div>
</div>
</p>
<p>Or simply:</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code><label>Your Image File
<input type="file" name="myImage" accept="image/*" />
</label></code></pre>
</div>
</div>
</p>
<p>Note that this only provides a hint to the browser as to what file-types to display to the user, but this can be easily circumvented, so you should always validate the uploaded file on the server also.</p>
<p>It should work in IE 10+, Chrome, Firefox, Safari 6+, Opera 15+, but support is very sketchy on mobiles (as of 2015) and by some reports, this may actually prevent some mobile browsers from uploading anything at all, so be sure to test your target platforms well.</p>
<p>For detailed browser support, see <a href="http://caniuse.com/#feat=input-file-accept" rel="noreferrer">http://caniuse.com/#feat=input-file-accept</a></p> | {
"question_id": 3828554,
"question_date": "2010-09-30T07:14:46.797Z",
"question_score": 625,
"tags": "html",
"answer_id": 6225815,
"answer_date": "2011-06-03T10:20:55.527Z",
"answer_score": 1463
} |
Please answer the following Stack Overflow question:
Title: Configure Flask dev server to be visible across the network
<p>I'm not sure if this is Flask specific, but when I run an app in dev mode (<code>http://localhost:5000</code>), I cannot access it from other machines on the network (with <code>http://[dev-host-ip]:5000</code>). With Rails in dev mode, for example, it works fine. I couldn't find any docs regarding the Flask dev server configuration. Any idea what should be configured to enable this?</p> | <p>While this is possible, you should not use the Flask dev server in production. The Flask dev server is not designed to be particularly secure, stable, or efficient. See the docs on <a href="https://flask.palletsprojects.com/deploying/index.html" rel="noreferrer">deploying</a> for correct solutions.</p>
<hr />
<p>The <code>--host</code> option to <code>flask run</code>, or the <code>host</code> parameter to <code>app.run()</code>, controls what address the development server listens to. By default it runs on <code>localhost</code>, change it to <code>flask run --host=0.0.0.0</code> (or <code>app.run(host="0.0.0.0")</code>) to run on all your machine's IP addresses.</p>
<p><code>0.0.0.0</code> is a special value that you can't use in the browser directly, you'll need to navigate to the actual IP address of the machine on the network. You may also need to adjust your firewall to allow external access to the port.</p>
<p>The Flask <a href="https://flask.palletsprojects.com/quickstart/#a-minimal-application" rel="noreferrer">quickstart docs</a> explain this in the "Externally Visible Server" section:</p>
<blockquote>
<p>If you run the server you will notice that the server is only
accessible from your own computer, not from any other in the network.
This is the default because in debugging mode a user of the
application can execute arbitrary Python code on your computer.</p>
<p>If you have the debugger disabled or trust the users on your network,
you can make the server publicly available simply by adding
<code>--host=0.0.0.0</code> to the command line:</p>
<pre class="lang-none prettyprint-override"><code>$ flask run --host=0.0.0.0
</code></pre>
<p>This tells your operating system to listen on all public IPs.</p>
</blockquote> | {
"question_id": 7023052,
"question_date": "2011-08-11T08:40:28.277Z",
"question_score": 625,
"tags": "python|flask|werkzeug",
"answer_id": 7027113,
"answer_date": "2011-08-11T13:53:42.787Z",
"answer_score": 943
} |
Please answer the following Stack Overflow question:
Title: Linux command to print directory structure in the form of a tree
<p>Is there any linux command that I can call from a Bash script that will print the directory structure in the form of a tree, e.g.,</p>
<pre><code>folder1
a.txt
b.txt
folder2
folder3
</code></pre> | <p>Is this what you're looking for <a href="http://mama.indstate.edu/users/ice/tree/" rel="noreferrer">tree</a>? It should be in most distributions (maybe as an optional install).</p>
<pre><code>~> tree -d /proc/self/
/proc/self/
|-- attr
|-- cwd -> /proc
|-- fd
| `-- 3 -> /proc/15589/fd
|-- fdinfo
|-- net
| |-- dev_snmp6
| |-- netfilter
| |-- rpc
| | |-- auth.rpcsec.context
| | |-- auth.rpcsec.init
| | |-- auth.unix.gid
| | |-- auth.unix.ip
| | |-- nfs4.idtoname
| | |-- nfs4.nametoid
| | |-- nfsd.export
| | `-- nfsd.fh
| `-- stat
|-- root -> /
`-- task
`-- 15589
|-- attr
|-- cwd -> /proc
|-- fd
| `-- 3 -> /proc/15589/task/15589/fd
|-- fdinfo
`-- root -> /
27 directories
</code></pre>
<p>sample taken from maintainer's web page.</p>
<p>You can add the option <code>-L #</code> where <code>#</code> is replaced by a number, to specify the max recursion depth.</p>
<p>Remove <code>-d</code> to display also files.</p> | {
"question_id": 3455625,
"question_date": "2010-08-11T05:58:00.870Z",
"question_score": 625,
"tags": "linux|command-line",
"answer_id": 3455675,
"answer_date": "2010-08-11T06:04:27.910Z",
"answer_score": 916
} |
Please answer the following Stack Overflow question:
Title: How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?
<p>I have a .diff file created by a coworker, and would like to apply the changes listed in that diff file to my local branch of the exact same repository. I do not have access to that worker's pc or branch that was used to generate this diff file.</p>
<p>Obviously I could go line by line and retype everything, but i'd rather not subject the system to human error. What's the easiest way to do this?</p> | <p>Copy the diff file to the root of your repository, and then do:</p>
<pre><code>git apply yourcoworkers.diff
</code></pre>
<p>More information about the <code>apply</code> command is available on <a href="http://www.kernel.org/pub/software/scm/git/docs/git-apply.html">its man page</a>.</p>
<p>By the way: A better way to exchange whole commits by file is the combination of the commands <code>git format-patch</code> on the sender and then <code>git am</code> on the receiver, because it also transfers the authorship info and the commit message.</p>
<p>If the patch application fails and if the commits the diff was generated from are actually in your repo, you can use the <code>-3</code> option of <code>apply</code> that tries to merge in the changes.</p>
<p>It also works with Unix pipe as follows:</p>
<pre><code>git diff d892531 815a3b5 | git apply
</code></pre> | {
"question_id": 12320863,
"question_date": "2012-09-07T15:13:23.793Z",
"question_score": 625,
"tags": "git|diff|git-diff",
"answer_id": 12320940,
"answer_date": "2012-09-07T15:17:46.197Z",
"answer_score": 933
} |
Please answer the following Stack Overflow question:
Title: What does a lock statement do under the hood?
<p>I see that for using objects which are not thread safe we wrap the code with a lock like this:</p>
<pre><code>private static readonly Object obj = new Object();
lock (obj)
{
// thread unsafe code
}
</code></pre>
<p>So, what happens when multiple threads access the same code (let's assume that it is running in a ASP.NET web application). Are they queued? If so how long will they wait?</p>
<p>What is the performance impact because of using locks?</p> | <p>The <code>lock</code> statement is translated by C# 3.0 to the following:</p>
<pre><code>var temp = obj;
Monitor.Enter(temp);
try
{
// body
}
finally
{
Monitor.Exit(temp);
}
</code></pre>
<p>In C# 4.0 <a href="https://ericlippert.com/2009/03/06/locks-and-exceptions-do-not-mix/" rel="noreferrer">this has changed</a> and it is now generated as follows:</p>
<pre><code>bool lockWasTaken = false;
var temp = obj;
try
{
Monitor.Enter(temp, ref lockWasTaken);
// body
}
finally
{
if (lockWasTaken)
{
Monitor.Exit(temp);
}
}
</code></pre>
<p>You can find more info about what <code>Monitor.Enter</code> does <a href="https://docs.microsoft.com/dotnet/api/system.threading.monitor.enter#System_Threading_Monitor_Enter_System_Object_" rel="noreferrer">here</a>. To quote MSDN:</p>
<blockquote>
<p>Use <code>Enter</code> to acquire the Monitor on
the object passed as the parameter. If
another thread has executed an <code>Enter</code>
on the object but has not yet executed
the corresponding <code>Exit</code>, the current
thread will block until the other
thread releases the object. It is
legal for the same thread to invoke
<code>Enter</code> more than once without it
blocking; however, an equal number of
<code>Exit</code> calls must be invoked before
other threads waiting on the object
will unblock.</p>
</blockquote>
<p>The <code>Monitor.Enter</code> method will wait infinitely; it will <em>not</em> time out.</p> | {
"question_id": 6029804,
"question_date": "2011-05-17T10:55:13.383Z",
"question_score": 625,
"tags": "c#|.net|synchronization|locking|thread-safety",
"answer_id": 6029829,
"answer_date": "2011-05-17T10:57:52.143Z",
"answer_score": 525
} |
Please answer the following Stack Overflow question:
Title: Colorized grep -- viewing the entire file with highlighted matches
<p>I find <code>grep</code>'s <code>--color=always</code> flag to be tremendously useful. However, grep only prints lines with matches (unless you ask for context lines). Given that each line it prints has a match, the highlighting doesn't add as much capability as it could.</p>
<p>I'd really like to <code>cat</code> a file and see the entire file with the pattern matches highlighted.</p>
<p>Is there some way I can tell grep to print every line being read regardless of whether there's a match? I know I could write a script to run grep on every line of a file, but I was curious whether this was possible with standard <code>grep</code>.</p> | <p>Here are some ways to do it:</p>
<pre><code>grep --color 'pattern\|$' file
grep --color -E 'pattern|$' file
egrep --color 'pattern|$' file
</code></pre>
<p>The <code>|</code> symbol is the OR operator. Either escape it using <code>\</code> or tell grep that the search text has to be interpreted as regular expressions by adding -E or using the <code>egrep</code> command instead of <code>grep</code>.</p>
<p>The search text "pattern|$" is actually a trick, it will match lines that have <code>pattern</code> OR lines that have an end. Because all lines have an end, all lines are matched, but the end of a line isn't actually any characters, so it won't be colored.</p>
<p>To also pass the colored parts through pipes, e.g. towards <code>less</code>, provide the <code>always</code> parameter to <code>--color</code>:</p>
<pre><code>grep --color=always 'pattern\|$' file | less -r
grep --color=always -E 'pattern|$' file | less -r
egrep --color=always 'pattern|$' file | less -r
</code></pre> | {
"question_id": 981601,
"question_date": "2009-06-11T14:55:29.873Z",
"question_score": 625,
"tags": "bash|shell|colors|grep",
"answer_id": 981831,
"answer_date": "2009-06-11T15:30:58.197Z",
"answer_score": 985
} |
Please answer the following Stack Overflow question:
Title: Difference between Grunt, NPM and Bower ( package.json vs bower.json )
<p>I'm new to using npm and bower, building my first app in emberjs :).<br>
I do have a bit of experience with rails, so I'm familiar with the idea of files for listing dependencies (such as bundler Gemfile)</p>
<p>Question: when I want to add a package (and check in the dependency into git), where does it belong - into <code>package.json</code> or into <code>bower.json</code>?</p>
<p>From what I gather,<br>
running <code>bower install</code> will fetch the package and put it in <code>/vendor</code> directory,<br>
running <code>npm install</code> it will fetch it and put it into <code>/node_modules</code> directory. </p>
<p><a href="https://stackoverflow.com/a/16493586/1592915">This SO answer</a> says bower is for front-end and npm is for backend stuff.<br>
<a href="https://github.com/stefanpenner/ember-app-kit" rel="noreferrer">Ember-app-kit</a> seems to adhere to this distinction from the first glance... But instructions in gruntfile for <a href="https://github.com/stefanpenner/ember-app-kit/blob/master/Gruntfile.js#L40-L42" rel="noreferrer">enabling some functionality</a> give two explicit commands, so I'm totally confused here.</p>
<p>Intuitively I would guess that </p>
<ol>
<li><p><strong>npm install --save-dev package-name</strong> would be equivalent to adding the package-name to my package.json </p></li>
<li><p><strong>bower install --save package-name</strong> might be the same as adding the package to my <em>bower.json</em> and running <strong>bower install</strong>? </p></li>
</ol>
<p>If that is the case, when should I ever install packages explicitly like that without adding them to the file that manages dependencies (apart from installing command line tools globally)?</p> | <p><strong>Update for mid 2016</strong>:</p>
<p>The things are changing so fast that if it's late 2017 this answer might not be up to date anymore!</p>
<p>Beginners can quickly get lost in choice of build tools and workflows, but what's most up to date in 2016 is not using Bower, Grunt or Gulp at all! With help of Webpack you can do everything directly in NPM!</p>
<ul>
<li><p>Google "npm as build tool" result:
<a href="https://medium.com/@dabit3/introduction-to-using-npm-as-a-build-tool-b41076f488b0#.c33e74tsa">https://medium.com/@dabit3/introduction-to-using-npm-as-a-build-tool-b41076f488b0#.c33e74tsa</a></p></li>
<li><p>Webpack: <a href="https://webpack.github.io/docs/installation.html">https://webpack.github.io/docs/installation.html</a></p></li>
</ul>
<p>Don't get me wrong people use other workflows and I still use GULP in my legacy project(but slowly moving out of it), but this is how it's done in the best companies and developers working in this workflow make a LOT of money!</p>
<p>Look at this template it's a very up-to-date setup consisting of a mixture of the best and the latest technologies:
<a href="https://github.com/coryhouse/react-slingshot">https://github.com/coryhouse/react-slingshot</a></p>
<ul>
<li>Webpack</li>
<li>NPM as a build tool (no Gulp, Grunt or Bower)</li>
<li>React with Redux</li>
<li>ESLint</li>
<li>the list is long. Go and explore!</li>
</ul>
<p>Your questions:</p>
<blockquote>
<p>When I want to add a package (and check in the dependency into git),
where does it belong - into package.json or into bower.json</p>
</blockquote>
<ul>
<li><p>Everything belongs in package.json now</p></li>
<li><p>Dependencies required for build are in "devDependencies" i.e. <code>npm install require-dir --save-dev</code> (--save-dev updates your package.json by adding an entry to devDependencies)</p></li>
<li>Dependencies required for your application during runtime are in "dependencies" i.e. <code>npm install lodash --save</code> (--save updates your package.json by adding an entry to dependencies)</li>
</ul>
<blockquote>
<p>If that is the case, when should I ever install packages explicitly like that without adding them to the file that manages dependencies (apart from installing command line tools globally)?</p>
</blockquote>
<p><strong>Always</strong>. Just because of comfort. When you add a flag (<code>--save-dev</code> or <code>--save</code>) the file that manages deps (package.json) gets updated automatically. Don't waste time by editing dependencies in it manually. Shortcut for <code>npm install --save-dev package-name</code> is <code>npm i -D package-name</code> and shortcut for <code>npm install --save package-name</code> is <code>npm i -S package-name</code></p> | {
"question_id": 21198977,
"question_date": "2014-01-18T01:36:01.197Z",
"question_score": 625,
"tags": "javascript|gruntjs|bower",
"answer_id": 39234812,
"answer_date": "2016-08-30T18:37:17.213Z",
"answer_score": 157
} |
Please answer the following Stack Overflow question:
Title: PHP expects T_PAAMAYIM_NEKUDOTAYIM?
<p>Does anyone have a <code>T_PAAMAYIM_NEKUDOTAYIM</code>?</p> | <p>It’s the double colon operator <a href="http://php.net/manual/en/language.oop5.paamayim-nekudotayim.php" rel="noreferrer"><code>::</code></a> (see <a href="http://docs.php.net/manual/en/tokens.php" rel="noreferrer">list of parser tokens</a>).</p> | {
"question_id": 592322,
"question_date": "2009-02-26T20:34:52.957Z",
"question_score": 625,
"tags": "php|runtime-error|syntax-error|error-code",
"answer_id": 592326,
"answer_date": "2009-02-26T20:36:31.750Z",
"answer_score": 373
} |
Please answer the following Stack Overflow question:
Title: Import SQL dump into PostgreSQL database
<p>We are switching hosts and the old one provided a SQL dump of the PostgreSQL database of our site.</p>
<p>Now, I'm trying to set this up on a local WAMP server to test this.</p>
<p>The only problem is that I don't have an idea how to import this database in the PostgreSQL 9 that I have set up.</p>
<p>I tried pgAdmin III but I can't seem to find an 'import' function. So I just opened the SQL editor and pasted the contents of the dump there and executed it, it creates the tables but it keeps giving me errors when it tries to put the data in it.</p>
<pre><code>ERROR: syntax error at or near "t"
LINE 474: t 2011-05-24 16:45:01.768633 2011-05-24 16:45:01.768633 view...
The lines:
COPY tb_abilities (active, creation, modtime, id, lang, title, description) FROM stdin;
t 2011-05-24 16:45:01.768633 2011-05-24 16:45:01.768633 view nl ...
</code></pre>
<p>I've also tried to do this with the command prompt but I can't find the command that I need.</p>
<p>If I do</p>
<pre><code>psql mydatabase < C:/database/db-backup.sql;
</code></pre>
<p>I get the error</p>
<pre><code>ERROR: syntax error at or near "psql"
LINE 1: psql mydatabase < C:/database/db-backu...
^
</code></pre>
<p>What's the best way to import the database?</p> | <pre><code>psql databasename < data_base_dump
</code></pre>
<p>That's the command you are looking for. </p>
<p>Beware: <code>databasename</code> must be created before importing.
Have a look at the <a href="https://www.postgresql.org/docs/8.1/static/backup.html#BACKUP-DUMP-RESTORE" rel="noreferrer">PostgreSQL Docs Chapter 23. Backup and Restore</a>.</p> | {
"question_id": 6842393,
"question_date": "2011-07-27T09:50:50.780Z",
"question_score": 624,
"tags": "database|postgresql",
"answer_id": 6842496,
"answer_date": "2011-07-27T09:57:47.637Z",
"answer_score": 936
} |
Please answer the following Stack Overflow question:
Title: How to prevent auto-closing of console after the execution of batch file
<p>What command can I put at the end of a batch file to prevent auto-closing of the console after the execution of the file?</p> | <p>In Windows/DOS batch files:</p>
<pre><code>pause
</code></pre>
<p>This prints a nice <code>"Press any key to continue . . . "</code> message</p>
<p>Or, if you don't want the <code>"Press any key to continue . . ."</code> message, do this instead:</p>
<pre><code>pause >nul
</code></pre> | {
"question_id": 988403,
"question_date": "2009-06-12T18:57:37.503Z",
"question_score": 624,
"tags": "windows|command-line|batch-file",
"answer_id": 988423,
"answer_date": "2009-06-12T18:59:33.380Z",
"answer_score": 764
} |
Please answer the following Stack Overflow question:
Title: psql: FATAL: role "postgres" does not exist
<p>I'm a postgres novice. </p>
<p>I installed the postgres.app for mac. I was playing around with the psql commands and I accidentally dropped the postgres database. I don't know what was in it. </p>
<p>I'm currently working on a tutorial: <a href="http://www.rosslaird.com/blog/building-a-project-with-mezzanine/">http://www.rosslaird.com/blog/building-a-project-with-mezzanine/</a></p>
<p>And I'm stuck at <code>sudo -u postgres psql postgres</code></p>
<p>ERROR MESSAGE: <code>psql: FATAL: role "postgres" does not exist</code></p>
<p>$ which psql </p>
<pre><code>/Applications/Postgres.app/Contents/MacOS/bin/psql
</code></pre>
<p>This is what prints out of <code>psql -l</code></p>
<pre><code> List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
------------+------------+----------+---------+-------+---------------------------
user | user | UTF8 | en_US | en_US |
template0 | user | UTF8 | en_US | en_US | =c/user +
| | | | | user =CTc/user
template1 | user | UTF8 | en_US | en_US | =c/user +
| | | | | user =CTc/user
(3 rows)
</code></pre>
<p>So what are the steps I should take? Delete an everything related to psql and reinstall everything?</p>
<p>Thanks for the help guys!</p> | <p>NOTE: If you installed postgres using homebrew, see the comment from @user3402754 below. </p>
<p>Note that the error message does <strong>NOT</strong> talk about a missing database, it talks about a missing role. Later in the login process it might also stumble over the missing database.</p>
<p>But the first step is to check the missing role: What is the output within <code>psql</code> of the command <code>\du</code> ? On my Ubuntu system the relevant line looks like this:</p>
<pre><code> List of roles
Role name | Attributes | Member of
-----------+-----------------------------------+-----------
postgres | Superuser, Create role, Create DB | {}
</code></pre>
<p>If there is not at least one role with <code>superuser</code>, then you have a problem :-) </p>
<p>If there is one, you can use that to login. And looking at the output of your <code>\l</code> command: The permissions for <code>user</code> on the <code>template0</code> and <code>template1</code> databases are the same as on my Ubuntu system for the superuser <code>postgres</code>. So I think your setup simple uses <code>user</code> as the superuser. So you could try this command to login:</p>
<pre><code>sudo -u user psql user
</code></pre>
<p>If <code>user</code> is really the DB superuser you can create another DB superuser and a private, empty database for him:</p>
<pre><code>CREATE USER postgres SUPERUSER;
CREATE DATABASE postgres WITH OWNER postgres;
</code></pre>
<p>But since your postgres.app setup does not seem to do this, you also should not. Simple adapt the tutorial.</p> | {
"question_id": 15301826,
"question_date": "2013-03-08T19:31:57.607Z",
"question_score": 624,
"tags": "macos|postgresql|terminal",
"answer_id": 15309551,
"answer_date": "2013-03-09T10:13:04.797Z",
"answer_score": 588
} |
Please answer the following Stack Overflow question:
Title: How to get the path of a running JAR file?
<p>My code runs inside a JAR file, say <strong>foo.jar</strong>, and I need to know, in the code, in which folder the running <strong>foo.jar</strong> is.</p>
<p>So, if <strong>foo.jar</strong> is in <code>C:\FOO\</code>, I want to get that path no matter what my current working directory is.</p> | <pre><code>return new File(MyClass.class.getProtectionDomain().getCodeSource().getLocation()
.toURI()).getPath();
</code></pre>
<p>Replace "MyClass" with the name of your class.</p>
<p>Obviously, this will do odd things if your class was loaded from a non-file location.</p> | {
"question_id": 320542,
"question_date": "2008-11-26T12:30:38.180Z",
"question_score": 624,
"tags": "java|path|jar|executable-jar",
"answer_id": 320595,
"answer_date": "2008-11-26T12:50:03.103Z",
"answer_score": 586
} |
Please answer the following Stack Overflow question:
Title: C# getting its own class name
<p>If I have a class called <code>MyProgram</code>, is there a way of retrieving "<em>MyProgram</em>" as a string?</p> | <p>Try this:</p>
<pre><code>this.GetType().Name
</code></pre> | {
"question_id": 2113069,
"question_date": "2010-01-21T21:30:26.173Z",
"question_score": 624,
"tags": "c#|reflection",
"answer_id": 2113076,
"answer_date": "2010-01-21T21:31:21.217Z",
"answer_score": 965
} |
Please answer the following Stack Overflow question:
Title: Python "extend" for a dictionary
<p>What is the best way to extend a dictionary with another one while avoiding the use of a <code>for</code> loop? For instance:</p>
<pre><code>>>> a = { "a" : 1, "b" : 2 }
>>> b = { "c" : 3, "d" : 4 }
>>> a
{'a': 1, 'b': 2}
>>> b
{'c': 3, 'd': 4}
</code></pre>
<p>Result:</p>
<pre><code>{ "a" : 1, "b" : 2, "c" : 3, "d" : 4 }
</code></pre>
<p>Something like:</p>
<pre><code>a.extend(b) # This does not work
</code></pre> | <pre><code>a.update(b)
</code></pre>
<p><a href="http://docs.python.org/library/stdtypes.html#dict.update" rel="noreferrer">Latest Python Standard Library Documentation</a></p> | {
"question_id": 577234,
"question_date": "2009-02-23T10:59:32.567Z",
"question_score": 624,
"tags": "python|dictionary",
"answer_id": 577241,
"answer_date": "2009-02-23T11:01:49.987Z",
"answer_score": 912
} |
Please answer the following Stack Overflow question:
Title: What characters are valid for JavaScript variable names?
<p>Which characters can be used for naming a JavaScript variable?</p>
<p>I want to create a small "extension library" for my non-JavaScript users here at work (who all seem to be squeamish when it comes to the language). I love how jQuery and Prototype have both use the <code>$</code> dollar sign, and since I use jQuery, I'm looking for another nice single-character symbol to use. </p>
<p>I realize that I could just test out a number of characters, but I'm hoping to narrow down my list of characters to start with (in consideration of future integration with another popular library, perhaps).</p> | <p>To quote <a href="http://mathiasbynens.be/notes/javascript-identifiers" rel="noreferrer"><em><strong>Valid JavaScript variable names</strong></em></a>, my write-up summarizing the relevant spec sections:</p>
<blockquote>
<p>An identifier must start with <code>$</code>, <code>_</code>, or any character in the Unicode categories <a href="http://graphemica.com/categories/uppercase-letter" rel="noreferrer">“Uppercase letter (Lu)”</a>, <a href="http://graphemica.com/categories/lowercase-letter" rel="noreferrer">“Lowercase letter (Ll)”</a>, <a href="http://graphemica.com/categories/titlecase-letter" rel="noreferrer">“Titlecase letter (Lt)”</a>, <a href="http://graphemica.com/categories/modifier-letter" rel="noreferrer">“Modifier letter (Lm)”</a>, <a href="http://graphemica.com/categories/other-letter" rel="noreferrer">“Other letter (Lo)”</a>, or <a href="http://graphemica.com/categories/letter-number" rel="noreferrer">“Letter number (Nl)”</a>.</p>
<p>The rest of the string can contain the same characters, plus any <em>U+200C zero width non-joiner</em> characters, <em>U+200D zero width joiner</em> characters, and characters in the Unicode categories <a href="http://graphemica.com/unicode/categories/nonspacing-mark" rel="noreferrer">“Non-spacing mark (Mn)”</a>, <a href="http://graphemica.com/categories/spacing-combining-mark" rel="noreferrer">“Spacing combining mark (Mc)”</a>, <a href="http://graphemica.com/categories/decimal-digit-number" rel="noreferrer">“Decimal digit number (Nd)”</a>, or <a href="http://graphemica.com/categories/connector-punctuation" rel="noreferrer">“Connector punctuation (Pc)”</a>.</p>
</blockquote>
<p>I’ve also created <a href="http://mothereff.in/js-variables" rel="noreferrer" title="JavaScript variable name validator">a tool</a> that will tell you if any string that you enter is a valid JavaScript variable name according to ECMAScript 5.1 and Unicode 6.1:</p>
<p><a href="http://mothereff.in/js-variables" rel="noreferrer"><img src="https://i.imgur.com/GNv5t.png" alt="JavaScript variable name validator" /></a></p>
<hr />
<p>P.S. To give you an idea of how wrong Anthony Mills' answer is: if you were to summarize all these rules in a single ASCII-only regular expression for JavaScript, <strong>it would be 11,236 characters long</strong>. Here it is:</p>
<pre><code>// ES5.1 / Unicode 6.1
/^(?!(?:do|if|in|for|let|new|try|var|case|else|enum|eval|false|null|undefined|NaN|this|true|void|with|break|catch|class|const|super|throw|while|yield|delete|export|import|public|return|static|switch|typeof|default|extends|finally|package|private|continue|debugger|function|arguments|interface|protected|implements|instanceof)$)[$A-Z\_a-z\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u0527\u0531-\u0556\u0559\u0561-\u0587\u05d0-\u05ea\u05f0-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u08a0\u08a2-\u08ac\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0977\u0979-\u097f\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c33\u0c35-\u0c39\u0c3d\u0c58\u0c59\u0c60\u0c61\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d60\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e87\u0e88\u0e8a\u0e8d\u0e94-\u0e97\u0e99-\u0e9f\u0ea1-\u0ea3\u0ea5\u0ea7\u0eaa\u0eab\u0ead-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f4\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f0\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1877\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191c\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19c1-\u19c7\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1ce9-\u1cec\u1cee-\u1cf1\u1cf5\u1cf6\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2119-\u211d\u2124\u2126\u2128\u212a-\u212d\u212f-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c2e\u2c30-\u2c5e\u2c60-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u2e2f\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309d-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312d\u3131-\u318e\u31a0-\u31ba\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fcc\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua697\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua78e\ua790-\ua793\ua7a0-\ua7aa\ua7f8-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa80-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uabc0-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc][$A-Z\_a-z\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u0527\u0531-\u0556\u0559\u0561-\u0587\u05d0-\u05ea\u05f0-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u08a0\u08a2-\u08ac\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0977\u0979-\u097f\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c33\u0c35-\u0c39\u0c3d\u0c58\u0c59\u0c60\u0c61\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d60\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e87\u0e88\u0e8a\u0e8d\u0e94-\u0e97\u0e99-\u0e9f\u0ea1-\u0ea3\u0ea5\u0ea7\u0eaa\u0eab\u0ead-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f4\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f0\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1877\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191c\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19c1-\u19c7\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1ce9-\u1cec\u1cee-\u1cf1\u1cf5\u1cf6\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2119-\u211d\u2124\u2126\u2128\u212a-\u212d\u212f-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c2e\u2c30-\u2c5e\u2c60-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u2e2f\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309d-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312d\u3131-\u318e\u31a0-\u31ba\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fcc\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua697\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua78e\ua790-\ua793\ua7a0-\ua7aa\ua7f8-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa80-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uabc0-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc0-9\u0300-\u036f\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u08e4-\u08fe\u0900-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c01-\u0c03\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c82\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0d02\u0d03\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d82\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0eb9\u0ebb\u0ebc\u0ec8-\u0ecd\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102b-\u103e\u1040-\u1049\u1056-\u1059\u105e-\u1060\u1062-\u1064\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u1810-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19b0-\u19c0\u19c8\u19c9\u19d0-\u19d9\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1b00-\u1b04\u1b34-\u1b44\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1b82\u1ba1-\u1bad\u1bb0-\u1bb9\u1be6-\u1bf3\u1c24-\u1c37\u1c40-\u1c49\u1c50-\u1c59\u1cd0-\u1cd2\u1cd4-\u1ce8\u1ced\u1cf2-\u1cf4\u1dc0-\u1de6\u1dfc-\u1dff\u200c\u200d\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua620-\ua629\ua66f\ua674-\ua67d\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua880\ua881\ua8b4-\ua8c4\ua8d0-\ua8d9\ua8e0-\ua8f1\ua900-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe26\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f]*$/
</code></pre> | {
"question_id": 1661197,
"question_date": "2009-11-02T13:04:29.420Z",
"question_score": 624,
"tags": "javascript|character",
"answer_id": 9337047,
"answer_date": "2012-02-17T23:48:55.857Z",
"answer_score": 1062
} |
Please answer the following Stack Overflow question:
Title: Import existing source code to GitHub
<p>How can I import source code from my computer to my GitHub account?</p> | <p>If you've got local source code you want to add to a new remote new git repository without 'cloning' the remote first, do the following (I often do this - you create your remote empty repository in bitbucket/github, then push up your source)</p>
<ol>
<li><p>Create the remote repository, and get the URL such as <code>[email protected]:/youruser/somename.git</code> or <code>https://github.com/youruser/somename.git</code></p>
<p><em>If your local GIT repo is already set up, skips steps 2 and 3</em></p>
<hr></li>
<li><p>Locally, at the root directory of your source, <code>git init</code></p>
<p>2a. If you initialize the repo with a .gitignore and a README.md you should do a <code>git pull {url from step 1}</code> to ensure you don't commit files to source that you want to ignore ;)</p></li>
<li><p>Locally, add and commit what you want in your initial repo (for everything, <code>git add .</code> then <code>git commit -m 'initial commit comment'</code>)</p>
<hr></li>
<li><p>to attach your remote repo with the name 'origin' (like cloning would do)<br>
<code>git remote add origin [URL From Step 1]</code></p></li>
<li>Execute <code>git pull origin master</code> to pull the remote branch so that they are in sync.</li>
<li>to push up your master branch (change master to something else for a different branch):<br>
<code>git push origin master</code></li>
</ol> | {
"question_id": 4658606,
"question_date": "2011-01-11T14:25:12.047Z",
"question_score": 624,
"tags": "git|github",
"answer_id": 8012698,
"answer_date": "2011-11-04T16:36:39.613Z",
"answer_score": 983
} |
Please answer the following Stack Overflow question:
Title: Can we instantiate an abstract class?
<p>During one of my interview, I was asked "If we can instantiate an abstract class?"</p>
<p>My reply was "No. we can't". But, interviewer told me "Wrong, we can." </p>
<p>I argued a bit on this. Then he told me to try this myself at home. </p>
<pre><code>abstract class my {
public void mymethod() {
System.out.print("Abstract");
}
}
class poly {
public static void main(String a[]) {
my m = new my() {};
m.mymethod();
}
}
</code></pre>
<p>Here, I'm creating instance of my class and calling method of abstract class. Can anyone please explain this to me? Was I really wrong during my interview?</p> | <blockquote>
<p>Here, i'm creating instance of my class</p>
</blockquote>
<p>No, you are not creating the instance of your abstract class here. Rather you are creating an instance of an <em>anonymous subclass</em> of your abstract class. And then you are invoking the method on your <em>abstract class</em> reference pointing to <em>subclass object</em>.</p>
<p>This behaviour is clearly listed in <a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.9" rel="noreferrer">JLS - Section # 15.9.1</a>: -</p>
<blockquote>
<p>If the class instance creation expression ends in a class body, then
the class being instantiated is an anonymous class. Then: </p>
<ul>
<li>If T denotes a class, then an anonymous direct subclass of the class named by T is declared. It is a compile-time error if the
class denoted by T is a final class.</li>
<li>If T denotes an interface, then an anonymous direct subclass of Object that implements the interface named by T is declared.</li>
<li>In either case, the body of the subclass is the ClassBody given in the class instance creation expression.</li>
<li><strong>The class being instantiated is the anonymous subclass.</strong></li>
</ul>
</blockquote>
<p>Emphasis mine.</p>
<p>Also, in <a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-12.html#jls-12.5" rel="noreferrer">JLS - Section # 12.5</a>, you can read about the <em>Object Creation Process</em>. I'll quote one statement from that here: -</p>
<blockquote>
<p>Whenever a new class instance is created, memory space is allocated
for it with room for all the instance variables declared in the class
type and all the instance variables declared in each superclass of the
class type, including all the instance variables that may be hidden.</p>
<p>Just before a reference to the newly created object is returned as the
result, the indicated constructor is processed to initialize the new
object using the following procedure:</p>
</blockquote>
<p>You can read about the complete procedure on the link I provided.</p>
<hr>
<p>To practically see that the class being instantiated is an <em>Anonymous SubClass</em>, you just need to compile both your classes. Suppose you put those classes in two different files:</p>
<p><strong>My.java:</strong></p>
<pre><code>abstract class My {
public void myMethod() {
System.out.print("Abstract");
}
}
</code></pre>
<p><strong>Poly.java:</strong></p>
<pre><code>class Poly extends My {
public static void main(String a[]) {
My m = new My() {};
m.myMethod();
}
}
</code></pre>
<p>Now, compile both your source files:</p>
<pre><code>javac My.java Poly.java
</code></pre>
<p>Now in the directory where you compiled the source code, you will see the following class files:</p>
<pre><code>My.class
Poly$1.class // Class file corresponding to anonymous subclass
Poly.class
</code></pre>
<p>See that class - <code>Poly$1.class</code>. It's the class file created by the compiler corresponding to the anonymous subclass you instantiated using the below code:</p>
<pre><code>new My() {};
</code></pre>
<p>So, it's clear that there is a different class being instantiated. It's just that, that class is given a name only after compilation by the compiler.</p>
<p>In general, all the anonymous subclasses in your class will be named in this fashion:</p>
<pre><code>Poly$1.class, Poly$2.class, Poly$3.class, ... so on
</code></pre>
<p>Those numbers denote the order in which those anonymous classes appear in the enclosing class.</p> | {
"question_id": 13670991,
"question_date": "2012-12-02T16:01:58.503Z",
"question_score": 624,
"tags": "java|oop|class|object|abstract",
"answer_id": 13671003,
"answer_date": "2012-12-02T16:04:01.307Z",
"answer_score": 782
} |
Please answer the following Stack Overflow question:
Title: How to add elements to an empty array in PHP?
<p>If I define an array in PHP such as (I don't define its size):</p>
<pre class="lang-php prettyprint-override"><code>$cart = array();
</code></pre>
<p>Do I simply add elements to it using the following?</p>
<pre class="lang-php prettyprint-override"><code>$cart[] = 13;
$cart[] = "foo";
$cart[] = obj;
</code></pre>
<p>Don't arrays in PHP have an add method, for example, <code>cart.add(13)</code>?</p> | <p>Both <a href="http://php.net/manual/en/function.array-push.php" rel="noreferrer"><code>array_push</code></a> and the method you described will work.</p>
<pre><code>$cart = array();
$cart[] = 13;
$cart[] = 14;
// etc
//Above is correct. but below one is for further understanding
$cart = array();
for($i=0;$i<=5;$i++){
$cart[] = $i;
}
echo "<pre>";
print_r($cart);
echo "</pre>";
</code></pre>
<p>Is the same as: </p>
<pre><code><?php
$cart = array();
array_push($cart, 13);
array_push($cart, 14);
// Or
$cart = array();
array_push($cart, 13, 14);
?>
</code></pre> | {
"question_id": 676677,
"question_date": "2009-03-24T09:35:00.250Z",
"question_score": 623,
"tags": "php|arrays|variables",
"answer_id": 676703,
"answer_date": "2009-03-24T09:42:53.897Z",
"answer_score": 991
} |
Please answer the following Stack Overflow question:
Title: How can I exclude one word with grep?
<p>I need something like:</p>
<pre><code>grep ^"unwanted_word"XXXXXXXX
</code></pre> | <p>You can do it using <code>-v</code> (for <code>--invert-match</code>) option of grep as:</p>
<pre><code>grep -v "unwanted_word" file | grep XXXXXXXX
</code></pre>
<p><code>grep -v "unwanted_word" file</code> will filter the lines that have the <code>unwanted_word</code> and <code>grep XXXXXXXX</code> will list only lines with pattern <code>XXXXXXXX</code>.</p>
<p><strong>EDIT:</strong></p>
<p>From your comment it looks like you want to list all lines without the <code>unwanted_word</code>. In that case all you need is:</p>
<pre><code>grep -v 'unwanted_word' file
</code></pre> | {
"question_id": 4538253,
"question_date": "2010-12-27T11:09:06.197Z",
"question_score": 623,
"tags": "regex|string|search|grep",
"answer_id": 4538335,
"answer_date": "2010-12-27T11:21:55.303Z",
"answer_score": 1071
} |
Please answer the following Stack Overflow question:
Title: How to install Boost on Ubuntu
<p>I'm on Ubuntu, and I want to install Boost. I tried with</p>
<pre><code>sudo apt-get install boost
</code></pre>
<p>But there was no such package. What is the best way to install Boost on Ubuntu?</p> | <p>You can use <code>apt-get</code> command (requires <code>sudo</code>)</p>
<pre><code>sudo apt-get install libboost-all-dev
</code></pre>
<p>Or you can call</p>
<pre><code>aptitude search boost
</code></pre>
<p>find packages you need and install them using the <code>apt-get</code> command.</p> | {
"question_id": 12578499,
"question_date": "2012-09-25T07:52:59.263Z",
"question_score": 623,
"tags": "ubuntu|boost",
"answer_id": 12578564,
"answer_date": "2012-09-25T07:57:27.013Z",
"answer_score": 1061
} |
Please answer the following Stack Overflow question:
Title: How to dynamically change a web page's title?
<p>I have a webpage that implements a set of tabs each showing different content. The tab clicks do not refresh the page but hide/unhide contents at the client side.</p>
<p>Now there is a requirement to change the page title according to the tab selected on the page ( for SEO reasons ). Is this possible? Can someone suggest a solution to dynamically alter the page title via javascript without reloading the page?</p> | <p><strong>Update</strong>: as per the comments and reference on <a href="https://searchengineland.com/tested-googlebot-crawls-javascript-heres-learned-220157" rel="noreferrer">SearchEngineLand</a>
most web crawlers will index the updated title. Below answer is obsolete, but the code is still applicable.</p>
<blockquote>
<p>You can just do something like, <code>document.title = "This is the new
page title.";</code>, but that would totally defeat the purpose of SEO. Most
crawlers aren't going to support javascript in the first place, so
they will take whatever is in the element as the page title.</p>
<p>If you want this to be compatible with most of the important crawlers,
you're going to need to actually change the title tag itself, which
would involve reloading the page (PHP, or the like). You're not going
to be able to get around that, if you want to change the page title in
a way that a crawler can see.</p>
</blockquote> | {
"question_id": 413439,
"question_date": "2009-01-05T15:25:13.333Z",
"question_score": 623,
"tags": "javascript|html",
"answer_id": 413455,
"answer_date": "2009-01-05T15:29:48.613Z",
"answer_score": 847
} |
Please answer the following Stack Overflow question:
Title: How to access host port from docker container
<p>I have a docker container running jenkins. As part of the build process, I need to access a web server that is run locally on the host machine. Is there a way the host web server (which can be configured to run on a port) can be exposed to the jenkins container?</p>
<p>I'm running docker natively on a Linux machine.</p>
<p>UPDATE:</p>
<p>In addition to @larsks answer below, to get the IP address of the Host IP from the host machine, I do the following:</p>
<pre><code>ip addr show docker0 | grep -Po 'inet \K[\d.]+'
</code></pre> | <p>When running Docker natively on Linux, you can access host services using the IP address of the <code>docker0</code> interface. From inside the container, this will be your default route.</p>
<p>For example, on my system:</p>
<pre><code>$ ip addr show docker0
7: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
valid_lft forever preferred_lft forever
inet6 fe80::f4d2:49ff:fedd:28a0/64 scope link
valid_lft forever preferred_lft forever
</code></pre>
<p>And inside a container:</p>
<pre><code># ip route show
default via 172.17.0.1 dev eth0
172.17.0.0/16 dev eth0 src 172.17.0.4
</code></pre>
<p>It's fairly easy to extract this IP address using a simple shell
script:</p>
<pre><code>#!/bin/sh
hostip=$(ip route show | awk '/default/ {print $3}')
echo $hostip
</code></pre>
<p>You may need to modify the <code>iptables</code> rules on your host to permit
connections from Docker containers. Something like this will do the
trick:</p>
<pre><code># iptables -A INPUT -i docker0 -j ACCEPT
</code></pre>
<p>This would permit access to any ports on the host from Docker
containers. Note that:</p>
<ul>
<li><p>iptables rules are ordered, and this rule may or may not do the
right thing depending on what other rules come before it.</p>
</li>
<li><p>you will only be able to access host services that are either (a)
listening on <code>INADDR_ANY</code> (aka 0.0.0.0) or that are explicitly
listening on the <code>docker0</code> interface.</p>
</li>
</ul>
<hr />
<p>If you are using Docker on <a href="https://docs.docker.com/docker-for-mac/networking/#there-is-no-docker0-bridge-on-macos#i-want-to-connect-from-a-container-to-a-service-on-the-host" rel="noreferrer">MacOS</a> or <a href="https://docs.docker.com/docker-for-windows/networking/#there-is-no-docker0-bridge-on-windows#i-want-to-connect-from-a-container-to-a-service-on-the-host" rel="noreferrer">Windows</a> 18.03+, you can connect to the magic hostname <code>host.docker.internal</code>.</p>
<hr />
<p>Lastly, under Linux you can run your container in the host network namespace by setting <code>--net=host</code>; in this case <code>localhost</code> on your host is the same as <code>localhost</code> inside the container, so containerized service will act like non-containerized services and will be accessible without any additional configuration.</p> | {
"question_id": 31324981,
"question_date": "2015-07-09T18:01:28.250Z",
"question_score": 623,
"tags": "docker|docker-container",
"answer_id": 31328031,
"answer_date": "2015-07-09T20:54:28.943Z",
"answer_score": 362
} |
Please answer the following Stack Overflow question:
Title: Cocoa: What's the difference between the frame and the bounds?
<p><code>UIView</code> and its subclasses all have the properties <code>frame</code> and <code>bounds</code>. What's the difference?</p> | <p>The <strong>bounds</strong> of an <a href="http://developer.apple.com/iPhone/library/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html" rel="noreferrer">UIView</a> is the <a href="http://developer.apple.com/iPhone/library/documentation/GraphicsImaging/Reference/CGGeometry/Reference/reference.html#//apple_ref/doc/c_ref/CGRect" rel="noreferrer">rectangle</a>, expressed as a location (x,y) and size (width,height) relative to its own coordinate system (0,0).</p>
<p>The <strong>frame</strong> of an <a href="http://developer.apple.com/iPhone/library/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html" rel="noreferrer">UIView</a> is the <a href="http://developer.apple.com/iPhone/library/documentation/GraphicsImaging/Reference/CGGeometry/Reference/reference.html#//apple_ref/doc/c_ref/CGRect" rel="noreferrer">rectangle</a>, expressed as a location (x,y) and size (width,height) relative to the superview it is contained within.</p>
<p>So, imagine a view that has a size of 100x100 (width x height) positioned at 25,25 (x,y) of its superview. The following code prints out this view's bounds and frame:</p>
<pre><code>// This method is in the view controller of the superview
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"bounds.origin.x: %f", label.bounds.origin.x);
NSLog(@"bounds.origin.y: %f", label.bounds.origin.y);
NSLog(@"bounds.size.width: %f", label.bounds.size.width);
NSLog(@"bounds.size.height: %f", label.bounds.size.height);
NSLog(@"frame.origin.x: %f", label.frame.origin.x);
NSLog(@"frame.origin.y: %f", label.frame.origin.y);
NSLog(@"frame.size.width: %f", label.frame.size.width);
NSLog(@"frame.size.height: %f", label.frame.size.height);
}
</code></pre>
<p>And the output of this code is:</p>
<pre><code>bounds.origin.x: 0
bounds.origin.y: 0
bounds.size.width: 100
bounds.size.height: 100
frame.origin.x: 25
frame.origin.y: 25
frame.size.width: 100
frame.size.height: 100
</code></pre>
<p>So, we can see that in both cases, the width and the height of the view is the same regardless of whether we are looking at the bounds or frame. What is different is the x,y positioning of the view. In the case of the bounds, the x and y coordinates are at 0,0 as these coordinates are relative to the view itself. However, the frame x and y coordinates are relative to the position of the view within the parent view (which earlier we said was at 25,25).</p>
<p>There is also a <a href="http://www.slideshare.net/onoaonoa/cs193p-lecture-5-view-animation" rel="noreferrer">great presentation</a> that covers UIViews. See slides 1-20 which not only explain the difference between frames and bounds but also show visual examples.</p> | {
"question_id": 1210047,
"question_date": "2009-07-31T00:07:04.597Z",
"question_score": 623,
"tags": "cocoa|cocoa-touch|uiview",
"answer_id": 1210141,
"answer_date": "2009-07-31T00:43:25.207Z",
"answer_score": 946
} |
Please answer the following Stack Overflow question:
Title: How do I split a string into a list of words?
<p>How do I split a sentence and store each word in a list? For example, given a string like <code>"these are words"</code>, how do I get a list like <code>["these", "are", "words"]</code>?</p> | <p>Given a string <code>sentence</code>, this stores each word in a list called <code>words</code>:</p>
<pre><code>words = sentence.split()
</code></pre> | {
"question_id": 743806,
"question_date": "2009-04-13T12:48:44.750Z",
"question_score": 622,
"tags": "python|list|split|text-segmentation",
"answer_id": 743823,
"answer_date": "2009-04-13T12:54:16.937Z",
"answer_score": 530
} |
Please answer the following Stack Overflow question:
Title: How to extract numbers from a string in Python?
<p>I would like to extract all the numbers contained in a string. Which is better suited for the purpose, regular expressions or the <code>isdigit()</code> method?</p>
<p>Example:</p>
<pre><code>line = "hello 12 hi 89"
</code></pre>
<p>Result:</p>
<pre><code>[12, 89]
</code></pre> | <p>If you only want to extract only positive integers, try the following:</p>
<pre><code>>>> txt = "h3110 23 cat 444.4 rabbit 11 2 dog"
>>> [int(s) for s in txt.split() if s.isdigit()]
[23, 11, 2]
</code></pre>
<p>I would argue that this is better than the regex example because you don't need another module and it's more readable because you don't need to parse (and learn) the <a href="https://docs.python.org/3/library/re.html#regular-expression-syntax" rel="noreferrer">regex mini-language</a>.</p>
<p>This will not recognize floats, negative integers, or integers in hexadecimal format. If you can't accept these limitations, <a href="https://stackoverflow.com/questions/4289331/python-extract-numbers-of-a-string/4289415#4289415">jmnas's answer below</a> will do the trick.</p> | {
"question_id": 4289331,
"question_date": "2010-11-27T00:00:40.523Z",
"question_score": 622,
"tags": "python|regex|string|numbers",
"answer_id": 4289557,
"answer_date": "2010-11-27T01:14:13.653Z",
"answer_score": 660
} |
Please answer the following Stack Overflow question:
Title: React.js inline style best practices
<p>I'm aware that you can specify styles within React classes, like this:</p>
<pre><code>const MyDiv = React.createClass({
render: function() {
const style = {
color: 'white',
fontSize: 200
};
return <div style={style}> Have a good and productive day! </div>;
}
});
</code></pre>
<p>Should I be aiming to do all styling this way, and have no styles at all specified in my CSS file?</p>
<p>Or should I avoid inline styles completely?</p>
<p>It seems odd and messy to do a little bit of both - two places would need to be checked when tweaking styling.</p> | <p>There aren't a lot of "Best Practices" yet. Those of us that are using inline-styles, for React components, are still very much experimenting.</p>
<p>There are a number of approaches that vary wildly: <a href="https://github.com/FormidableLabs/radium/tree/905227c122b1775775cf8d82c508cce4179cff08/docs/comparison" rel="noreferrer">React inline-style lib comparison chart</a></p>
<h2>All or nothing?</h2>
<p>What we refer to as "style" actually includes quite a few concepts:</p>
<ul>
<li>Layout — <em>how an element/component looks in relationship to others</em></li>
<li>Appearance — <em>the characteristics of an element/component</em></li>
<li>Behavior and state — <em>how an element/component looks in a given state</em></li>
</ul>
<h2>Start with state-styles</h2>
<p>React is already managing the state of your components, this makes styles of <strong>state and behavior</strong> a natural fit for colocation with your component logic.</p>
<p>Instead of building components to render with conditional state-classes, consider adding state-styles directly:</p>
<pre><code>// Typical component with state-classes
<li
className={classnames({ 'todo-list__item': true, 'is-complete': item.complete })} />
// Using inline-styles for state
<li className='todo-list__item'
style={(item.complete) ? styles.complete : {}} />
</code></pre>
<p>Note that we're using a class to style <strong>appearance</strong> but no longer using any <code>.is-</code> prefixed class for <strong>state and behavior</strong>.</p>
<p>We can use <code>Object.assign</code> (ES6) or <code>_.extend</code> (underscore/lodash) to add support for multiple states:</p>
<pre><code>// Supporting multiple-states with inline-styles
<li 'todo-list__item'
style={Object.assign({}, item.complete && styles.complete, item.due && styles.due )}>
</code></pre>
<h2>Customization and reusability</h2>
<p>Now that we're using <code>Object.assign</code> it becomes very simple to make our component reusable with different styles. If we want to override the default styles, we can do so at the call-site with props, like so: <code><TodoItem dueStyle={ fontWeight: "bold" } /></code>. Implemented like this:</p>
<pre><code><li 'todo-list__item'
style={Object.assign({},
item.due && styles.due,
item.due && this.props.dueStyles)}>
</code></pre>
<h3>Layout</h3>
<p>Personally, I don't see compelling reason to inline layout styles. There are a number of great CSS layout systems out there. I'd just use one.</p>
<p>That said, don't add layout styles directly to your component. Wrap your components with layout components. Here's an example.</p>
<pre><code>// This couples your component to the layout system
// It reduces the reusability of your component
<UserBadge
className="col-xs-12 col-sm-6 col-md-8"
firstName="Michael"
lastName="Chan" />
// This is much easier to maintain and change
<div class="col-xs-12 col-sm-6 col-md-8">
<UserBadge
firstName="Michael"
lastName="Chan" />
</div>
</code></pre>
<p>For layout support, I often try to design components to be <code>100%</code> <code>width</code> and <code>height</code>.</p>
<h3>Appearance</h3>
<p>This is the most contentious area of the "inline-style" debate. Ultimately, it's up to the component your designing and the comfort of your team with JavaScript.</p>
<p>One thing is certain, you'll need the assistance of a library. Browser-states (<code>:hover</code>, <code>:focus</code>), and media-queries are painful in raw React.</p>
<p>I like <a href="http://projects.formidablelabs.com/radium/" rel="noreferrer">Radium</a> because the syntax for those hard parts is designed to model that of SASS.</p>
<h2>Code organization</h2>
<p>Often you'll see a style object outside of the module. For a todo-list component, it might look something like this:</p>
<pre><code>var styles = {
root: {
display: "block"
},
item: {
color: "black"
complete: {
textDecoration: "line-through"
},
due: {
color: "red"
}
},
}
</code></pre>
<h2>getter functions</h2>
<p>Adding a bunch of style logic to your template can get a little messy (as seen above). I like to create getter functions to compute styles:</p>
<pre><code>React.createClass({
getStyles: function () {
return Object.assign(
{},
item.props.complete && styles.complete,
item.props.due && styles.due,
item.props.due && this.props.dueStyles
);
},
render: function () {
return <li style={this.getStyles()}>{this.props.item}</li>
}
});
</code></pre>
<h2>Further watching</h2>
<p>I discussed all of these in more detail at React Europe earlier this year: <a href="https://www.youtube.com/watch?v=ERB1TJBn32c" rel="noreferrer">Inline Styles and when it's best to 'just use CSS'</a>.</p>
<p>I'm happy to help as you make new discoveries along the way :) Hit me up -> <a href="http://twitter.com/@chantastic" rel="noreferrer">@chantastic</a></p> | {
"question_id": 26882177,
"question_date": "2014-11-12T08:16:24.477Z",
"question_score": 622,
"tags": "css|reactjs|inline-styles",
"answer_id": 31638988,
"answer_date": "2015-07-26T15:56:01.803Z",
"answer_score": 507
} |
Please answer the following Stack Overflow question:
Title: GitHub: invalid username or password
<p>I have a project hosted on GitHub. I fail when trying to push my modifications on the master. I always get the following error message</p>
<pre><code>Password for 'https://[email protected]':
remote: Invalid username or password.
fatal: Authentication failed for 'https://[email protected]/eurydyce/MDANSE.git/'
</code></pre>
<p>However, setting my ssh key to github seems ok. Indeed, when I do a <code>ssh -T [email protected]</code> I get</p>
<pre><code>Hi eurydyce! You've successfully authenticated, but GitHub does not provide shell access.
</code></pre>
<p>Which seems to indicate that everything is OK from that side (eurydyce being my github username). I strictly followed the instructions given on github and the recommendations of many stack discussion but no way. Would you have any idea of what I may have done wrong?</p> | <p><a href="https://[email protected]/eurydyce/MDANSE.git" rel="noreferrer">https://[email protected]/eurydyce/MDANSE.git</a> is not an ssh url, it is an https one (which would require your GitHub account name, instead of '<code>git</code>').</p>
<p>Try to use <code>ssh://[email protected]:eurydyce/MDANSE.git</code> or just <code>[email protected]:eurydyce/MDANSE.git</code></p>
<pre><code>git remote set-url origin [email protected]:eurydyce/MDANSE.git
</code></pre>
<p>The <a href="https://stackoverflow.com/users/406014/pellegrini-eric">OP Pellegrini Eric</a> adds:</p>
<blockquote>
<p>That's what I did in my <code>~/.gitconfig</code> file that contains currently the following entries <code>[remote "origin"] [email protected]:eurydyce/MDANSE.git</code> </p>
</blockquote>
<p>This should not be in your global config (the one in <code>~/</code>).<br>
You could check <code>git config -l</code> in your repo: that url should be declared in the <em>local</em> config: <code><yourrepo>/.git/config</code>.</p>
<p>So make sure you are in the repo path when doing the <code>git remote set-url</code> command.</p>
<hr>
<p>As noted in <a href="https://stackoverflow.com/users/101662/oliver">Oliver</a>'s <a href="https://stackoverflow.com/a/34919582/6309">answer</a>, an HTTPS URL would not use username/password if <a href="https://help.github.com/en/github/authenticating-to-github/securing-your-account-with-two-factor-authentication-2fa" rel="noreferrer">two-factor authentication (2FA)</a> is activated.</p>
<p>In that case, the password should be a <a href="https://help.github.com/en/github/authenticating-to-github/accessing-github-using-two-factor-authentication#using-two-factor-authentication-with-the-command-line" rel="noreferrer">PAT (personal access token)</a> as seen in "<a href="https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line#using-a-token-on-the-command-line" rel="noreferrer">Using a token on the command line</a>".</p>
<p>That applies only for HTTPS URLS, SSH is not affected by this limitation.</p> | {
"question_id": 29297154,
"question_date": "2015-03-27T09:23:01.563Z",
"question_score": 622,
"tags": "github",
"answer_id": 29297250,
"answer_date": "2015-03-27T09:27:46.997Z",
"answer_score": 403
} |
Please answer the following Stack Overflow question:
Title: How to print struct variables in console?
<p>How can I print (to the console) the <code>Id</code>, <code>Title</code>, <code>Name</code>, etc. of this struct in Golang?</p>
<pre><code>type Project struct {
Id int64 `json:"project_id"`
Title string `json:"title"`
Name string `json:"name"`
Data Data `json:"data"`
Commits Commits `json:"commits"`
}
</code></pre> | <p>To print the name of the fields in a struct:</p>
<pre><code>fmt.Printf("%+v\n", yourProject)
</code></pre>
<p>From the <a href="http://golang.org/pkg/fmt/" rel="noreferrer"><code>fmt</code> package</a>:</p>
<blockquote>
<p>when printing structs, the plus flag (<code>%+v</code>) adds field names</p>
</blockquote>
<p>That supposes you have an instance of Project (in '<code>yourProject</code>')</p>
<p>The article <a href="http://blog.golang.org/json-and-go" rel="noreferrer">JSON and Go</a> will give more details on how to retrieve the values from a JSON struct.</p>
<hr>
<p>This <a href="https://gobyexample.com/json" rel="noreferrer">Go by example page</a> provides another technique:</p>
<pre><code>type Response2 struct {
Page int `json:"page"`
Fruits []string `json:"fruits"`
}
res2D := &Response2{
Page: 1,
Fruits: []string{"apple", "peach", "pear"}}
res2B, _ := json.Marshal(res2D)
fmt.Println(string(res2B))
</code></pre>
<p>That would print:</p>
<pre><code>{"page":1,"fruits":["apple","peach","pear"]}
</code></pre>
<hr>
<p>If you don't have any instance, then you need to <strong><a href="http://blog.golang.org/laws-of-reflection" rel="noreferrer">use reflection</a></strong> to display the name of the field of a given struct, <a href="http://play.golang.org/p/JKHjPu3cgB" rel="noreferrer">as in this example</a>.</p>
<pre><code>type T struct {
A int
B string
}
t := T{23, "skidoo"}
s := reflect.ValueOf(&t).Elem()
typeOfT := s.Type()
for i := 0; i < s.NumField(); i++ {
f := s.Field(i)
fmt.Printf("%d: %s %s = %v\n", i,
typeOfT.Field(i).Name, f.Type(), f.Interface())
}
</code></pre> | {
"question_id": 24512112,
"question_date": "2014-07-01T13:57:18.837Z",
"question_score": 622,
"tags": "struct|go",
"answer_id": 24512194,
"answer_date": "2014-07-01T14:00:38.340Z",
"answer_score": 1061
} |
Please answer the following Stack Overflow question:
Title: Sort array of objects by one property
<p>How can I sort this array of objects by one of its fields, like <code>name</code> or <code>count</code>?</p>
<pre><code>Array
(
[0] => stdClass Object
(
[ID] => 1
[name] => Mary Jane
[count] => 420
)
[1] => stdClass Object
(
[ID] => 2
[name] => Johnny
[count] => 234
)
[2] => stdClass Object
(
[ID] => 3
[name] => Kathy
[count] => 4354
)
....
</code></pre> | <p>Use <a href="http://php.net/manual/en/function.usort.php" rel="noreferrer">usort</a>, here's an example adapted from the manual:</p>
<pre><code>function cmp($a, $b) {
return strcmp($a->name, $b->name);
}
usort($your_data, "cmp");
</code></pre>
<p>You can also use any <a href="https://www.php.net/manual/en/language.types.callable.php" rel="noreferrer">callable</a> as the second argument. Here are some examples:</p>
<ul>
<li><p>Using <a href="https://www.php.net/manual/en/functions.anonymous.php" rel="noreferrer">anonymous functions</a> (from PHP 5.3)</p>
<pre><code> usort($your_data, function($a, $b) {return strcmp($a->name, $b->name);});
</code></pre>
</li>
<li><p>From inside a class</p>
<pre><code> usort($your_data, array($this, "cmp")); // "cmp" should be a method in the class
</code></pre>
</li>
<li><p>Using <a href="https://wiki.php.net/rfc/arrow_functions_v2" rel="noreferrer">arrow functions</a> (from PHP 7.4)</p>
<pre><code> usort($your_data, fn($a, $b) => strcmp($a->name, $b->name));
</code></pre>
</li>
</ul>
<p>Also, if you're comparing numeric values, <code>fn($a, $b) => $a->count - $b->count</code> as the "compare" function should do the trick, or, if you want yet another way of doing the same thing, starting from PHP 7 you can use the <a href="https://www.php.net/manual/en/migration70.new-features.php#migration70.new-features.spaceship-op" rel="noreferrer">Spaceship operator</a>, like this: <code>fn($a, $b) => $a->count <=> $b->count</code>.</p> | {
"question_id": 4282413,
"question_date": "2010-11-26T03:50:56.690Z",
"question_score": 622,
"tags": "php|arrays|sorting|object|multidimensional-array",
"answer_id": 4282423,
"answer_date": "2010-11-26T03:53:22.620Z",
"answer_score": 879
} |
Please answer the following Stack Overflow question:
Title: How to sort an array of custom objects by property value in Swift
<p>Let's say we have a custom class named <code>imageFile</code> and this class contains two properties:</p>
<pre><code>class imageFile {
var fileName = String()
var fileID = Int()
}
</code></pre>
<p>Lots of them are stored in an Array:</p>
<pre><code>var images : Array = []
var aImage = imageFile()
aImage.fileName = "image1.png"
aImage.fileID = 101
images.append(aImage)
aImage = imageFile()
aImage.fileName = "image1.png"
aImage.fileID = 202
images.append(aImage)
</code></pre>
<p>How can I sort the images array by 'fileID' in ascending or descending order?</p> | <p>First, declare your Array as a typed array so that you can call methods when you iterate:</p>
<pre><code>var images : [imageFile] = []
</code></pre>
<p>Then you can simply do:</p>
<p><strong>Swift 2</strong></p>
<pre><code>images.sorted({ $0.fileID > $1.fileID })
</code></pre>
<p><strong>Swift 3+</strong></p>
<pre><code>images.sorted(by: { $0.fileID > $1.fileID })
</code></pre>
<p>The example above gives the results in descending order.</p> | {
"question_id": 24130026,
"question_date": "2014-06-09T22:27:01.290Z",
"question_score": 622,
"tags": "arrays|sorting|swift",
"answer_id": 24130092,
"answer_date": "2014-06-09T22:32:08.733Z",
"answer_score": 1083
} |
Please answer the following Stack Overflow question:
Title: Purge or recreate a Ruby on Rails database
<p>I have a dev Ruby on Rails database full of data. I want to delete everything and rebuild the database. I'm thinking of using something like:</p>
<pre><code>rake db:recreate
</code></pre>
<p>Is this possible?</p> | <p>I know two ways to do this:</p>
<p>This will reset your database and reload your current schema with all:</p>
<pre><code>rake db:reset db:migrate
</code></pre>
<p>This will destroy your db and then create it and then migrate your current schema:</p>
<pre><code>rake db:drop db:create db:migrate
</code></pre>
<p>All data will be lost in both scenarios.</p> | {
"question_id": 4116067,
"question_date": "2010-11-07T01:23:00.807Z",
"question_score": 622,
"tags": "ruby-on-rails|ruby-on-rails-3|rake",
"answer_id": 4116124,
"answer_date": "2010-11-07T01:40:59.270Z",
"answer_score": 1154
} |
Please answer the following Stack Overflow question:
Title: UITextField text change event
<p>How can I detect any text changes in a textField? The delegate method <code>shouldChangeCharactersInRange</code> works for something, but it did not fulfill my need exactly. Since until it returns YES, the textField texts are not available to other observer methods. </p>
<p>e.g. in my code <code>calculateAndUpdateTextFields</code> did not get the updated text, the user has typed. </p>
<p>Is their any way to get something like <code>textChanged</code> Java event handler. </p>
<pre><code>- (BOOL)textField:(UITextField *)textField
shouldChangeCharactersInRange:(NSRange)range
replacementString:(NSString *)string
{
if (textField.tag == kTextFieldTagSubtotal
|| textField.tag == kTextFieldTagSubtotalDecimal
|| textField.tag == kTextFieldTagShipping
|| textField.tag == kTextFieldTagShippingDecimal)
{
[self calculateAndUpdateTextFields];
}
return YES;
}
</code></pre> | <p>From <a href="https://web.archive.org/web/20170109233344/http://iphonedevsdk.com:80/forum/iphone-sdk-development/4541-what-proper-way-do-uitextfield-text-change-call-back.html" rel="noreferrer">proper way to do uitextfield text change call back</a>:</p>
<blockquote>
<p>I catch the characters sent to a UITextField control something like this:</p>
</blockquote>
<pre><code>// Add a "textFieldDidChange" notification method to the text field control.
</code></pre>
<p>In Objective-C:</p>
<pre><code>[textField addTarget:self
action:@selector(textFieldDidChange:)
forControlEvents:UIControlEventEditingChanged];
</code></pre>
<p>In Swift:</p>
<pre><code>textField.addTarget(self, action: #selector(textFieldDidChange), for: .editingChanged)
</code></pre>
<blockquote>
<p>Then in the <code>textFieldDidChange</code> method you can examine the contents of the textField, and reload your table view as needed.</p>
</blockquote>
<p>You could use that and put <strong>calculateAndUpdateTextFields</strong> as your <code>selector</code>.</p> | {
"question_id": 7010547,
"question_date": "2011-08-10T12:09:41.583Z",
"question_score": 622,
"tags": "ios|objective-c|swift|event-handling|uitextfielddelegate",
"answer_id": 7010676,
"answer_date": "2011-08-10T12:21:10.383Z",
"answer_score": 1139
} |
Please answer the following Stack Overflow question:
Title: Remove a folder from git tracking
<p>I need to exclude a folder (name uploads) from tracking. I tried to run</p>
<pre><code>git rm -r --cached wordpress/wp-content/uploads
</code></pre>
<p>and after that I added the path to .gitignore</p>
<pre><code>/wordpress/wp-content/uploads
</code></pre>
<p>but when I ran <code>git status</code> they show up as deleted. If I try to commit the changes, the files will be deleted, not only removed from tracking.</p>
<p>What am I doing wrong? </p>
<p>I have also tried</p>
<pre><code>git update-index --assume-unchanged <file>
</code></pre>
<p>but this seems to untrack only files. But I need to remove an entire folder (including subfolders) from tracking.</p> | <p>I came across this question while Googling for "git remove folder from tracking". The OP's question lead me to the answer. I am summarizing it here for future generations.</p>
<p><strong>Question</strong></p>
<p>How do I remove a folder from my git repository without deleting it from my local machine (i.e., development environment)?</p>
<p><strong>Answer</strong></p>
<p>Step 1. Add the folder path to your repo's root <code>.gitignore</code> file.</p>
<pre><code>path_to_your_folder/
</code></pre>
<p>Step 2. Remove the folder from your local git tracking, but keep it on your disk.</p>
<pre><code>git rm -r --cached path_to_your_folder/
</code></pre>
<p>Step 3. Push your changes to your git repo.</p>
<p>The folder will be considered "deleted" from Git's point of view (i.e. they are in past history, but not in the latest commit, and people pulling from this repo will get the files removed from their trees), but stay on your working directory because you've used <code>--cached</code>.</p> | {
"question_id": 24290358,
"question_date": "2014-06-18T16:10:23.387Z",
"question_score": 622,
"tags": "git|git-rm",
"answer_id": 30360954,
"answer_date": "2015-05-20T21:46:22.763Z",
"answer_score": 1295
} |
Please answer the following Stack Overflow question:
Title: Heroku + node.js error (Web process failed to bind to $PORT within 60 seconds of launch)
<p>I have my first node.js app (runs fine locally) - but I am unable to deploy it via heroku (first time w/ heroku as well). The code is below. SO doesn't let me write so much code, so I would just say that the running the code locally as well within my network shows no issue.</p>
<pre><code> var http = require('http');
var fs = require('fs');
var path = require('path');
http.createServer(function (request, response) {
console.log('request starting for ');
console.log(request);
var filePath = '.' + request.url;
if (filePath == './')
filePath = './index.html';
console.log(filePath);
var extname = path.extname(filePath);
var contentType = 'text/html';
switch (extname) {
case '.js':
contentType = 'text/javascript';
break;
case '.css':
contentType = 'text/css';
break;
}
path.exists(filePath, function(exists) {
if (exists) {
fs.readFile(filePath, function(error, content) {
if (error) {
response.writeHead(500);
response.end();
}
else {
response.writeHead(200, { 'Content-Type': contentType });
response.end(content, 'utf-8');
}
});
}
else {
response.writeHead(404);
response.end();
}
});
}).listen(5000);
console.log('Server running at http://127.0.0.1:5000/');
</code></pre>
<p>Any idea ?</p> | <p>Heroku dynamically assigns your app a port, so you can't set the port to a fixed number. Heroku adds the port to the env, so you can pull it from there. Switch your listen to this:</p>
<pre><code>.listen(process.env.PORT || 5000)
</code></pre>
<p>That way it'll still listen to port 5000 when you test locally, but it will also work on Heroku. <em>Important note</em> - <strong>PORT</strong> word must be capital.</p>
<p>You can check out the Heroku docs on Node.js <a href="https://devcenter.heroku.com/articles/nodejs" rel="noreferrer">here</a>.</p> | {
"question_id": 15693192,
"question_date": "2013-03-28T22:20:39.763Z",
"question_score": 622,
"tags": "node.js|heroku",
"answer_id": 15693371,
"answer_date": "2013-03-28T22:36:48.270Z",
"answer_score": 1350
} |
Please answer the following Stack Overflow question:
Title: Recover from losing uncommitted changes by "git reset --hard"
<p>Is there any way to recover uncommitted changes to the working directory from a <code>git reset --hard HEAD</code>? </p> | <p>You <em>cannot</em> get back uncommitted changes in general. </p>
<p>Previously staged changes (<code>git add</code>) should be recoverable from index objects, so if you did, use <code>git fsck --lost-found</code> to locate the objects related to it. (This writes the objects to the <code>.git/lost-found/</code> directory; from there you can use <code>git show <filename></code> to see the contents of each file.)</p>
<p>If not, the answer here would be: look at your backup. <strong>Perhaps your editor/IDE stores temp copies</strong> under /tmp or C:\TEMP and things like that.[1]</p>
<pre><code>git reset HEAD@{1}
</code></pre>
<p>This will restore to the previous HEAD</p>
<p>[1] <strong>vim</strong> e.g. optionally stores persistent undo, <strong>eclipse</strong> IDE stores <em>local history</em>; such features might save your a**</p> | {
"question_id": 5788037,
"question_date": "2011-04-26T08:52:08.557Z",
"question_score": 622,
"tags": "git",
"answer_id": 5788069,
"answer_date": "2011-04-26T08:55:05.017Z",
"answer_score": 593
} |
Please answer the following Stack Overflow question:
Title: Presenting modal in iOS 13 fullscreen
<p>In iOS 13 there is a new behaviour for modal view controller when being presented.</p>
<p>Now it's not fullscreen by default and when I try to slide down, the app just dismiss the View Controller automatically.</p>
<p>How can I prevent this behaviour and get back to the old fullscreen modal vc?</p>
<p><a href="https://i.stack.imgur.com/8wo6K.png" rel="noreferrer"><img src="https://i.stack.imgur.com/8wo6K.png" alt="modal behaviour"></a></p>
<p>Thanks</p> | <p>With iOS 13, as stated in the <a href="https://developer.apple.com/videos/play/wwdc2019/103/" rel="noreferrer">Platforms State of the Union</a> during the WWDC 2019, Apple introduced a new default card presentation. In order to force the fullscreen you have to specify it explicitly with:</p>
<pre><code>let vc = UIViewController()
vc.modalPresentationStyle = .fullScreen //or .overFullScreen for transparency
self.present(vc, animated: true, completion: nil)
</code></pre> | {
"question_id": 56435510,
"question_date": "2019-06-03T23:01:50.167Z",
"question_score": 622,
"tags": "ios|viewcontroller|modalviewcontroller|ios13",
"answer_id": 56435511,
"answer_date": "2019-06-03T23:01:50.167Z",
"answer_score": 801
} |
Please answer the following Stack Overflow question:
Title: What does a just-in-time (JIT) compiler do?
<p>What does a JIT compiler specifically do as opposed to a non-JIT compiler? Can someone give a succinct and easy to understand description?</p> | <p>A JIT compiler runs <strong>after</strong> the program has started and compiles the code (usually bytecode or some kind of VM instructions) on the fly (or just-in-time, as it's called) into a form that's usually faster, typically the host CPU's native instruction set. A JIT has access to dynamic runtime information whereas a standard compiler doesn't and can make better optimizations like inlining functions that are used frequently.</p>
<p>This is in contrast to a traditional compiler that compiles <strong>all</strong> the code to machine language <strong>before</strong> the program is first run.</p>
<p>To paraphrase, conventional compilers build the whole program as an EXE file BEFORE the first time you run it. For newer style programs, an assembly is generated with pseudocode (p-code). Only AFTER you execute the program on the OS (e.g., by double-clicking on its icon) will the (JIT) compiler kick in and generate machine code (m-code) that the Intel-based processor or whatever will understand.</p> | {
"question_id": 95635,
"question_date": "2008-09-18T18:52:08.630Z",
"question_score": 622,
"tags": "compilation|compiler-construction|jit",
"answer_id": 95679,
"answer_date": "2008-09-18T18:55:52.207Z",
"answer_score": 607
} |
Please answer the following Stack Overflow question:
Title: What is the use of the @ symbol in PHP?
<p>I have seen uses of <code>@</code> in front of certain functions, like the following:</p>
<pre><code>$fileHandle = @fopen($fileName, $writeAttributes);
</code></pre>
<p>What is the use of this symbol?</p> | <p>It suppresses error messages — see <a href="http://php.net/manual/language.operators.errorcontrol.php" rel="noreferrer">Error Control Operators</a> in the PHP manual.</p> | {
"question_id": 1032161,
"question_date": "2009-06-23T12:08:32.817Z",
"question_score": 622,
"tags": "php|operators|error-suppression",
"answer_id": 1032169,
"answer_date": "2009-06-23T12:09:12.770Z",
"answer_score": 679
} |
Please answer the following Stack Overflow question:
Title: Undefined, unspecified and implementation-defined behavior
<p>What is <em>undefined behavior</em> (UB) in C and C++? What about <em>unspecified behavior</em> and <em>implementation-defined</em> behavior? What is the difference between them?</p> | <p><em><strong>Undefined behavior</strong></em> is one of those aspects of the C and C++ language that can be surprising to programmers coming from other languages (other languages try to hide it better). Basically, it is possible to write C++ programs that do not behave in a predictable way, even though many C++ compilers will not report any errors in the program!</p>
<p>Let's look at a classic example:</p>
<pre><code>#include <iostream>
int main()
{
char* p = "hello!\n"; // yes I know, deprecated conversion
p[0] = 'y';
p[5] = 'w';
std::cout << p;
}
</code></pre>
<p>The variable <code>p</code> points to the string literal <code>"hello!\n"</code>, and the two assignments below try to modify that string literal. What does this program do? According to section 2.14.5 paragraph 11 of the C++ standard, it invokes <em>undefined behavior</em>:</p>
<blockquote>
<p>The effect of attempting to modify a string literal is undefined.</p>
</blockquote>
<p>I can hear people screaming "But wait, I can compile this no problem and get the output <code>yellow</code>" or "What do you mean undefined, string literals are stored in read-only memory, so the first assignment attempt results in a core dump". This is exactly the problem with undefined behavior. Basically, the standard allows anything to happen once you invoke undefined behavior (even nasal demons). If there is a "correct" behavior according to your mental model of the language, that model is simply wrong; The C++ standard has the only vote, period.</p>
<p>Other examples of undefined behavior include accessing an array beyond its bounds, <a href="https://stackoverflow.com/q/2894891">dereferencing the null pointer</a>, <a href="https://stackoverflow.com/q/6441218">accessing objects after their lifetime ended</a> or writing <a href="https://stackoverflow.com/q/949433">allegedly clever expressions</a> like <code>i++ + ++i</code>.</p>
<p>Section 1.9 of the C++ standard also mentions undefined behavior's two less dangerous brothers, <strong>unspecified behavior</strong> and <strong>implementation-defined behavior</strong>:</p>
<blockquote>
<p>The semantic descriptions in this International Standard define a parameterized nondeterministic abstract machine.</p>
<p>Certain aspects and operations of the abstract machine are described in this International Standard as <strong>implementation-defined</strong> (for example, <code>sizeof(int)</code>). These constitute the parameters of the abstract machine. Each implementation shall include documentation describing its characteristics and behavior in these respects.</p>
<p>Certain other aspects and operations of the abstract machine are described in this International Standard as <strong>unspecified</strong> (for example, order of evaluation of arguments to a function). Where possible, this International Standard defines a set of allowable behaviors. These define the nondeterministic aspects of the abstract machine.</p>
<p>Certain other operations are described in this International Standard as <strong>undefined</strong> (for example, the effect of dereferencing the null pointer). [ <em>Note</em>: <strong>this International Standard imposes no requirements on the behavior of programs that contain undefined behavior.</strong> —<em>end note</em> ]</p>
</blockquote>
<p>Specifically, section 1.3.24 states:</p>
<blockquote>
<p>Permissible undefined behavior ranges from <strong>ignoring the situation completely with unpredictable results</strong>, to behaving during translation or program execution in a documented manner characteristic of the environment (with or without the issuance of a diagnostic message), to terminating a translation or execution (with the issuance of a diagnostic message).</p>
</blockquote>
<p>What can you do to avoid running into undefined behavior? Basically, you have to read <a href="https://stackoverflow.com/questions/388242/">good C++ books</a> by authors who know what they're talking about. Avoid internet tutorials. Avoid bullschildt.</p> | {
"question_id": 2397984,
"question_date": "2010-03-07T21:10:30.717Z",
"question_score": 622,
"tags": "c++|c|undefined-behavior|unspecified-behavior|implementation-defined-behavior",
"answer_id": 4105123,
"answer_date": "2010-11-05T10:41:41.690Z",
"answer_score": 471
} |
Please answer the following Stack Overflow question:
Title: How to make layout with rounded corners..?
<p>How can I make a layout with rounded corners? I want to apply rounded corners to my <code>LinearLayout</code>.</p> | <p>1: Define <strong>layout_bg.xml</strong> in drawables:</p>
<pre><code><?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF"/>
<stroke android:width="3dp" android:color="#B1BCBE" />
<corners android:radius="10dp"/>
<padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
</shape>
</code></pre>
<p>2: Add <code>layout_bg.xml</code> as background to your layout</p>
<pre><code>android:background="@drawable/layout_bg"
</code></pre> | {
"question_id": 16161448,
"question_date": "2013-04-23T05:12:55.120Z",
"question_score": 621,
"tags": "android|xml|image|layout|android-shapedrawable",
"answer_id": 16161493,
"answer_date": "2013-04-23T05:17:03.673Z",
"answer_score": 1233
} |
Please answer the following Stack Overflow question:
Title: Virtualbox shared folder permissions
<p>I'm using Windows and Virtualbox with RedHat, putting it simple: I've created a shared folder so I can use Eclipse on my Windows OS and do some testing in Linux.</p>
<p>However, I can't access the shared folder with my user, I've logged in with root and used <code>chmod 777</code> and even moved my user to the folder's group.</p>
<p>Whatever I do the result is the same: </p>
<p><code>/media/sf_sharedFolder/: Permission denied</code></p>
<p>What can I do? How can I access the shared folder with my user?</p> | <p>Add yourself to the <code>vboxsf</code> group within the guest VM.</p>
<p><strong>Solution 1</strong></p>
<p>Run <code>sudo adduser $USER vboxsf</code> from terminal.<br>
(On Suse it's <code>sudo usermod --append --groups vboxsf $USER</code>)</p>
<p>To take effect you should log out and then log in, or you may need to reboot.</p>
<p><strong>Solution 2</strong></p>
<p>Edit the file <code>/etc/group</code> (you will need root privileges). Look for the line <code>vboxsf:x:999</code> and add at the end <code>:yourusername</code> -- use this solution if you don't have sudo.</p>
<p>To take effect you should log out and then log in, or you may need to reboot.</p> | {
"question_id": 26740113,
"question_date": "2014-11-04T16:25:26.947Z",
"question_score": 621,
"tags": "virtualbox|shared-directory",
"answer_id": 26981786,
"answer_date": "2014-11-17T20:53:25.627Z",
"answer_score": 1279
} |
Please answer the following Stack Overflow question:
Title: What is polymorphism, what is it for, and how is it used?
<p>What is polymorphism, what is it for, and how is it used?</p> | <p>If you think about the Greek roots of the term, it should become obvious.</p>
<ul>
<li>Poly = many: polygon = many-sided, polystyrene = many styrenes <sup>(a)</sup>, polyglot = many languages, and so on.</li>
<li>Morph = change or form: morphology = study of biological form, Morpheus = the Greek god of dreams able to take any form.</li>
</ul>
<p>So polymorphism is the ability (in programming) to present the same interface for differing underlying forms (data types).</p>
<p>For example, in many languages, integers and floats are implicitly polymorphic since you can add, subtract, multiply and so on, irrespective of the fact that the types are different. They're rarely considered as objects in the usual term.</p>
<p>But, in that same way, a class like <code>BigDecimal</code> or <code>Rational</code> or <code>Imaginary</code> can also provide those operations, even though they operate on different data types.</p>
<p>The classic example is the <code>Shape</code> class and all the classes that can inherit from it (square, circle, dodecahedron, irregular polygon, splat and so on).</p>
<p>With polymorphism, each of these classes will have different underlying data. A point shape needs only two co-ordinates (assuming it's in a two-dimensional space of course). A circle needs a center and radius. A square or rectangle needs two co-ordinates for the top left and bottom right corners and (possibly) a rotation. An irregular polygon needs a series of lines.</p>
<p>By making the class responsible for its code as well as its data, you can achieve polymorphism. In this example, every class would have its own <code>Draw()</code> function and the client code could simply do:</p>
<pre><code>shape.Draw()
</code></pre>
<p>to get the correct behavior for any shape.</p>
<p>This is in contrast to the old way of doing things in which the code was separate from the data, and you would have had functions such as <code>drawSquare()</code> and <code>drawCircle()</code>.</p>
<p>Object orientation, polymorphism and inheritance are all closely-related concepts and they're vital to know. There have been many "silver bullets" during my long career which basically just fizzled out but the OO paradigm has turned out to be a good one. Learn it, understand it, love it - you'll be glad you did :-)</p>
<hr>
<p><sup>(a)</sup> I originally wrote that as a joke but it turned out to be correct and, therefore, not that funny. The monomer styrene happens to be made from carbon and hydrogen, <code>C<sub>8</sub>H<sub>8</sub></code>, and polystyrene is made from groups of that, <code>(C<sub>8</sub>H<sub>8</sub>)<sub>n</sub></code>.</p>
<p>Perhaps I should have stated that a polyp was many occurrences of the letter <code>p</code> although, now that I've had to explain the joke, even that doesn't seem funny either.</p>
<p>Sometimes, you should just quit while you're behind :-)</p> | {
"question_id": 1031273,
"question_date": "2009-06-23T08:14:21.620Z",
"question_score": 621,
"tags": "oop|polymorphism|computer-science",
"answer_id": 1031385,
"answer_date": "2009-06-23T08:44:54.820Z",
"answer_score": 589
} |
Please answer the following Stack Overflow question:
Title: Can you find all classes in a package using reflection?
<p>Is it possible to find all classes or interfaces in a given package? (Quickly looking at e.g. <a href="http://java.sun.com/javase/6/docs/api/java/lang/Package.html" rel="noreferrer"><code>Package</code></a>, it would seem like no.)</p> | <p>Due to the dynamic nature of class loaders, this is not possible. Class loaders are not required to tell the VM which classes it can provide, instead they are just handed requests for classes, and have to return a class or throw an exception.</p>
<p>However, if you write your own class loaders, or examine the classpaths and it's jars, it's possible to find this information. This will be via filesystem operations though, and not reflection. There might even be libraries that can help you do this.</p>
<p>If there are classes that get generated, or delivered remotely, you will not be able to discover those classes.</p>
<p>The normal method is instead to somewhere register the classes you need access to in a file, or reference them in a different class. Or just use convention when it comes to naming.</p>
<p>Addendum: <a href="https://github.com/ronmamo/reflections" rel="noreferrer">The Reflections Library</a> will allow you to look up classes in the current classpath. It can be used to get all classes in a package:</p>
<pre><code> Reflections reflections = new Reflections("my.project.prefix");
Set<Class<? extends Object>> allClasses =
reflections.getSubTypesOf(Object.class);
</code></pre> | {
"question_id": 520328,
"question_date": "2009-02-06T13:43:16.810Z",
"question_score": 621,
"tags": "java|reflection|package",
"answer_id": 520339,
"answer_date": "2009-02-06T13:47:57.080Z",
"answer_score": 409
} |
Please answer the following Stack Overflow question:
Title: Show whitespace characters in Visual Studio Code
<p>Is it possible to show whitespace characters, like the space character, in Visual Studio Code? </p>
<p>There doesn't appear to be an option for it in the <code>settings.json</code> (though it is an option in <em>Atom.io</em>), and I haven't been able to display whitespace characters using CSS.</p> | <p><strong>VS Code 1.6.0 and Greater</strong></p>
<p>As mentioned by <a href="https://stackoverflow.com/a/40037865/2814830">aloisdg below</a>, <code>editor.renderWhitespace</code> is now an enum taking either <code>none</code>, <code>boundary</code> or <code>all</code>. To view all whitespaces:</p>
<pre><code>"editor.renderWhitespace": "all",
</code></pre>
<p><strong>Before VS Code 1.6.0</strong></p>
<p>Before 1.6.0, you had to set <code>editor.renderWhitespace</code> to <code>true</code>:</p>
<pre><code>"editor.renderWhitespace": true
</code></pre> | {
"question_id": 30140595,
"question_date": "2015-05-09T13:38:38.080Z",
"question_score": 621,
"tags": "visual-studio-code|whitespace|vscode-settings|non-printing-characters",
"answer_id": 30140625,
"answer_date": "2015-05-09T13:41:28.937Z",
"answer_score": 851
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.