id
int64
4
73.8M
title
stringlengths
10
150
body
stringlengths
17
50.8k
accepted_answer_id
int64
7
73.8M
answer_count
int64
1
182
comment_count
int64
0
89
community_owned_date
stringlengths
23
27
creation_date
stringlengths
23
27
favorite_count
int64
0
11.6k
last_activity_date
stringlengths
23
27
last_edit_date
stringlengths
23
27
last_editor_display_name
stringlengths
2
29
last_editor_user_id
int64
-1
20M
owner_display_name
stringlengths
1
29
owner_user_id
int64
1
20M
parent_id
null
post_type_id
int64
1
1
score
int64
-146
26.6k
tags
stringlengths
1
125
view_count
int64
122
11.6M
answer_body
stringlengths
19
51k
7,612,792
How can I calculate deciles with a range of 12,000 cells in excel?
<p>I have a column of 12,000+ numbers, both positive and negative, sorted from highest to lowest in an Excel spreadsheet. </p> <p>Is there an easy way to go about dividing this range into deciles?</p>
7,614,902
3
2
null
2011-09-30 15:38:05.003 UTC
null
2018-06-08 09:15:29.157 UTC
2012-04-11 19:18:39.41 UTC
null
128,421
null
918,513
null
1
6
excel|sorting|vba
82,243
<p>This may not be the most efficient solution, but you might try the following:</p> <ol> <li><p>Assuming your numbers are in cells A1 through A12000, enter the following formula in cell B1 <code>=PERCENTRANK($A$1:$A$12000,A1,1)</code>. This calculates the percent rank, with the set of values in cells $A$1:$A$12000, of the value in cell A1, rounded down to 1 decimal place (which is all you need to identify the decile).</p></li> <li><p>Copy the formula in cell B1 to cells B2 through B12000.</p></li> <li><p>Use the values in column B to identify the decile for the corresponding value in column A. 0 identifies values greater than or equal to the 0th percentile and less than the 10th percentile, 0.1 identifies values greater than or equal to the 10th percentile and less than the 20th percentile, and so on. Depending on the size of your set and whether or not there are duplicates, there may or may not be a value that gets assigned a PERCENTRANK of exactly 1.</p></li> </ol> <p>If you are using Excel 2010, you might, depending on your needs, consider using the new functions PERCENTRANK.INC and PERCENTRANK.EXC that are supposed to supercede PERCENTRANK.</p> <p>Hope this helps.</p>
7,220,626
Local variable and expression trees
<p>I am learning expression trees in C#.</p> <p>I am stuck now for a while:</p> <pre><code>string filterString = "ruby"; Expression&lt;Func&lt;string, bool&gt;&gt; expression = x =&gt; x == filterString; </code></pre> <p>How can I construct this expression by code? There is no sample how to capture a local variable. This one is easy:</p> <pre><code>Expression&lt;Func&lt;string, bool&gt;&gt; expression = x =&gt; x == "ruby"; </code></pre> <p>This would be:</p> <pre><code>ParameterExpression stringParam = Expression.Parameter(typeof(string), "x"); Expression constant = Expression.Constant("ruby"); BinaryExpression equals = Expression.Equal(stringParam, constant); Expression&lt;Func&lt;string, bool&gt;&gt; lambda1 = Expression.Lambda&lt;Func&lt;string, bool&gt;&gt;( equals, new ParameterExpression[] { stringParam }); </code></pre> <p>The debugger prints the following for (x => x == filterString) :</p> <blockquote> <p>{x => (x == value(Predicate.Program+&lt;>c__DisplayClass3).filterString)}</p> </blockquote> <p>Thanks for shedding some light on this topic.</p>
7,220,792
3
0
null
2011-08-28 11:23:28.933 UTC
10
2017-10-05 13:12:51.677 UTC
null
null
null
null
288,291
null
1
33
c#|linq|lambda
16,036
<p>Capturing a local variable is actually performed by "hoisting" the local variable into an <em>instance</em> variable of a compiler-generated class. The C# compiler creates a new instance of the extra class at the appropriate time, and changes any access to the local variable into an access of the instance variable in the relevant instance.</p> <p>So the expression tree then needs to be a field access within the instance - and the instance itself is provided via a <code>ConstantExpression</code>.</p> <p>The simplest approach for working how to create expression trees is usually to create something similar in a lambda expression, then look at the generated code in Reflector, turning the optimization level down so that Reflector doesn't convert it back to lambda expressions.</p>
7,240,520
Can you use HTML entities in the CSS “content” property?
<p>I would like to use HTML entities in CSS, but it shows me the <code>&amp;bull;</code> instead.</p> <pre class="lang-css prettyprint-override"><code>.down:before{ content:"&amp;bull; "; color:#f00; } </code></pre> <p>Also, why does the above code not work in IE? it does not show the before part at all.</p>
7,240,666
4
4
null
2011-08-30 08:26:11.48 UTC
7
2013-05-31 12:38:13.977 UTC
2012-07-22 08:55:33.337 UTC
null
1,494,505
null
97,688
null
1
32
html|css
42,035
<p>put hex value of your bullet specail character like this</p> <pre class="lang-css prettyprint-override"><code>div:before{ content:"\2022"; color:#f00; } </code></pre> <p>check this fiddle <a href="http://jsfiddle.net/sandeep/HPrkU/1/">http://jsfiddle.net/sandeep/HPrkU/1/</a></p> <p>NOTE: after &amp; before work in IE8</p>
24,371,293
Chrome Dev Tools - can I always have pretty print enabled?
<p>As part of our build the code is minimised I'm currently debugging some js and constantly have to click the pretty print button in chrome dev tools. Is there a way to permanently enable pretty printing in chrome dev tools ?</p>
33,480,898
2
2
null
2014-06-23 16:54:53.697 UTC
5
2021-11-10 16:34:04.913 UTC
null
null
null
null
199,684
null
1
35
google-chrome|pretty-print
8,485
<p>No it is not possible yet. The way that I do is that I manage it through the build process to not minify the CSS and JS.</p>
2,188,680
Is fastcall really faster?
<p>Is the fastcall calling convention really faster than other calling conventions, such as cdecl? Are there any benchmarks out there that show how performance is affected by calling convention?</p>
2,188,723
4
4
null
2010-02-02 23:56:03.997 UTC
8
2022-09-01 16:05:49.103 UTC
2022-09-01 16:05:49.103 UTC
null
995,714
null
264,250
null
1
44
c++|performance|x86|calling-convention|fastcall
12,454
<p>It depends on the platform. For a Xenon PowerPC, for example, it can be an order of magnitude difference due to a load-hit-store issue with passing data on the stack. I empirically timed the overhead of a <code>cdecl</code> function at about 45 cycles compared to ~4 for a <code>fastcall</code>.</p> <p>For an out-of-order x86 (Intel and AMD), the impact may be much less, because the registers are all shadowed and renamed anyway.</p> <p>The answer really is that you need to benchmark it yourself on the particular platform you care about.</p>
15,243,309
PC shutdown command with abort option that will work in Windows 8
<p>I have been trying to create a batch file(s) that triggers my Windows 8 PC to begin shutting down after 30 seconds has elapsed and that also has a warning message: "Your PC will shutdown in 30 seconds! Please press Cancel button to abort Shutdown." I have created the following batch files on my desktop:</p> <p>shutdown /s /c "Your PC will shutdown in 30 seconds! /t 30</p> <p>and:</p> <p>shutdown /a</p> <p>and it does shutdown the pc, but the message will not show until exactly 30 seconds later and goes away within 1 second and starts shutting down with no way to stop it. I have even tried to do the shutdown /a batch file before the 30 seconds is up with no luck in stopping the shutdown. </p> <p>Is the commands not correct for Windows 8?</p> <p>I would like to have one script with the popup message warning and with a cancel (abort) button prior to the 30 seconds expiring or at least get the 2 batch files to work in Windows 8 with a warning message and the abort batch file both working.</p> <p>Not sure if Windows 8 has a command or something that works but would like to get it working. Any help is so greatly appreciated!!!</p> <p>Thanks you very much!</p> <p>Billy</p>
15,243,392
5
0
null
2013-03-06 09:21:00.437 UTC
null
2014-03-14 00:15:43.93 UTC
null
null
null
null
1,781,011
null
1
2
batch-file|command|message|shutdown|abort
42,450
<p>Try</p> <pre><code>@echo off echo Your PC will shutdown in 30 seconds! Press CTRL+C to abort. ping -n 31 127.0.0.1&gt;nul shutdown /s </code></pre> <p>The PING command is a secure way of pausing the batch script for desired amount of time. More info here: <a href="https://stackoverflow.com/questions/735285/how-to-wait-in-a-batch-script">How to wait in a batch script?</a> </p> <p>Pressing Ctrl-C will abort a batch script from continuing.</p>
10,620,471
Hide navigation bar in storyboard
<p>Can anyone tell me how to hide the navigation bar in my storyboard. My code below is working fine when running in the simulator but it still appears in my storyboard which is really annoying me as it's messing around with the placement of my images. Can anyone help?</p> <pre><code>- (void) viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self.navigationController setNavigationBarHidden:YES animated:animated]; } - (void) viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [self.navigationController setNavigationBarHidden:NO animated:animated]; } </code></pre>
10,620,567
6
2
null
2012-05-16 14:15:37.81 UTC
2
2020-10-25 13:39:22.39 UTC
null
null
null
null
1,128,290
null
1
35
iphone|ios|ipad|uinavigationbar
31,135
<p><img src="https://i.stack.imgur.com/6R990.png" alt="enter image description here"></p> <p>Click on the controller that has the top bar navigate to the properties bar on the right hand side of Xcode. There is a drop down labeled Top Bar (as shown above) change this drop down to none.</p>
26,391,632
How to serialize enums to different property name using json.net
<p>I have the following enum</p> <pre><code>public enum PermissionType { [JsonProperty(PropertyName = "can_fly")] PermissionToFly, [JsonProperty(PropertyName = "can_swim")] PermissionToSwim }; </code></pre> <p>and a class with this property</p> <pre><code>[JsonProperty(PropertyName = "permissions", ItemConverterType = typeof(StringEnumConverter))] public IList&lt;PermissionType&gt; PermissionKeynames { get; set; }` </code></pre> <p>I want to serialize the list of enumerations to a list of strings, and that serialize list use the string specified in <code>PropertyName</code> (such as "can_swim") instead of the property's actual name "PermissionToSwim". However, whenever I call JsonConvert.SerializeObject, I end up with </p> <pre><code>"permission_keynames":["PermissionToFly","PermissionToSwim"] </code></pre> <p>instead of my desired </p> <pre><code>"permission_keynames":["can_fly","can_swim"] </code></pre> <p>I want to keep the phrase "PermissionToSwim" for use in my code, serialize to another word. Any idea how I can achieve this? My gut says that the annotation is the culprit, but I haven't been able to find the correct one.</p>
26,391,780
1
1
null
2014-10-15 20:34:49.667 UTC
7
2022-05-13 05:39:26.283 UTC
2014-10-16 13:35:31.487 UTC
null
723,860
null
723,860
null
1
34
c#|serialization|enums|json.net
24,699
<p><a href="https://github.com/JamesNK/Newtonsoft.Json/blob/master/Src/Newtonsoft.Json/Converters/StringEnumConverter.cs#L221" rel="noreferrer">Looks like</a> you can make this work using the <a href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.enummemberattribute(v=vs.110).aspx" rel="noreferrer"><code>EnumMember</code> attribute</a> (found in System.Runtime.Serialization).</p> <pre><code>public enum PermissionType { [EnumMember(Value = "can_fly")] PermissionToFly, [EnumMember(Value = "can_swim")] PermissionToSwim } </code></pre> <p>If you use those attributes you should also not need to set the <code>ItemConverterType</code> in the <code>JsonProperty</code> attribute on the list.</p>
26,009,516
TeamCity triggers too many builds for a new branch
<p>When I create a new branch <code>B</code> from branch <code>A</code> and do a single commit, TeamCity triggers multiple builds on <code>B</code>, although I would expect just a single build.<br> I set "Trigger a build on each check-in" to true, but nevertheless there should only be a single build because there is only one new commit. It seems that TeamCity triggers a build for each commit within the current month. All builds of branch <code>A</code> finished and the same build configuration is used to build branch <code>A</code> and <code>B</code>. Can I configure TeamCity to create builds just for the commits that haven't been built (no matter on which branch)?</p>
26,120,370
2
2
null
2014-09-24 05:53:22.627 UTC
9
2016-05-10 17:17:08.477 UTC
null
null
null
null
1,293,659
null
1
9
git|build|continuous-integration|teamcity|feature-branch
4,649
<p>It looks like you faced with this <a href="https://youtrack.jetbrains.com/issue/TW-29820" rel="noreferrer">issue</a>. As current workaround please try to set </p> <pre><code>teamcity.vcsTrigger.runBuildOnSameRevisionInEveryBranch=false </code></pre> <p>You can set it either as a parameter in build configuration - to affect a particular build configuration, or in <a href="https://confluence.jetbrains.com/display/TCD9/Configuring+TeamCity+Server+Startup+Properties#ConfiguringTeamCityServerStartupProperties-TeamCityinternalpropertiesinternal.properties" rel="noreferrer">internal.properties file</a> to affect all build configurations.</p>
7,128,348
Performance difference between a wild card import and the required class import
<p>What is the complexity in terms of performance between</p> <pre><code>java.io.* </code></pre> <p>and </p> <pre><code>java.io.File </code></pre> <p>PS.</p> <p>I know that the first one will include every file in <code>java.io.*</code> and the next one only the selected class file. </p>
7,128,365
7
5
null
2011-08-19 23:16:03.813 UTC
11
2019-09-27 01:01:25.92 UTC
2011-08-20 07:14:37.227 UTC
null
648,138
null
806,550
null
1
38
java|import|performance
13,445
<p>At runtime 0.</p> <p>Both generate the same byte code</p>
9,187,885
Trying to parse JSON in Python. ValueError: Expecting property name
<p>I am trying to parse a JSON object into a Python <code>dict</code>. I've never done this before. When I googled this particular error, (<em>What is wrong with the first char?</em>), other posts have said that the string being loaded is not actually a JSON string. I'm pretty sure this is, though.</p> <p>In this case, <code>eval()</code> works fine, but I'm wondering if there is a more appropriate way?</p> <p><strong>Note:</strong> This string comes directly from Twitter, via ptt tools.</p> <pre><code>&gt;&gt;&gt; import json &gt;&gt;&gt; line = '{u\'follow_request_sent\': False, u\'profile_use_background_image\': True, u\'default_profile_image\': False, u\'verified\': False, u\'profile_sidebar_fill_color\': u\'DDEEF6\', u\'profile_text_color\': u\'333333\', u\'listed_count\': 0}' &gt;&gt;&gt; json.loads(line) Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 326, in loads return _default_decoder.decode(s) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 366, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 382, in raw_decode obj, end = self.scan_once(s, idx) ValueError: Expecting property name: line 1 column 1 (char 1) </code></pre>
9,188,950
4
1
null
2012-02-08 04:34:44.363 UTC
3
2017-08-31 20:44:52.383 UTC
2016-11-18 14:01:08.16 UTC
null
1,304,273
null
1,044,561
null
1
27
python|json|twitter
48,182
<p>That's definitely not JSON - not as printed above anyhow. It's already been parsed into a Python object - JSON would have <code>false</code>, not <code>False</code>, and wouldn't show strings as <code>u</code> for unicode (all JSON strings are unicode). Are you sure you're not getting your json string turned into a Python object for free somewhere in the chain already, and thus loading it into json.loads() is obviously wrong because in fact it's not a string?</p>
24,715,426
How do you increase the apache fastCGI timeout on MAMP / MAMP Pro?
<p>Does anybody know how to increase the apache fastCGI timeout on MAMP / MAMP Pro? I've looked everywhere but can't seem to find it.</p> <p>Any help is appreciated as always.</p> <p>Thanks, Codarz360</p>
24,976,009
4
2
null
2014-07-12 17:15:06.973 UTC
12
2018-04-13 16:24:38.82 UTC
null
null
null
null
1,477,478
null
1
20
apache|mamp|fastcgi|mamp-pro
19,299
<p>This was so tedious but finally got it to work.</p> <p>In MAMP PRO:</p> <p>Under File > edit template > apache > httpd.conf</p> <p>Find the block for mod_fcgi</p> <pre><code>&lt;IfModule mod_fastcgi.c&gt; </code></pre> <p>and delete the following line:</p> <pre><code>MAMP_FastCgiServer_MAMP </code></pre> <p>Since you can specify which version of PHP you want to use with each domain, you need to set a new fastcgiserver, per php version, with its corresponding -idle-timeout ### flag. These should be placed where you deleted the previous <code>MAMP_FastCgiServer_MAMP</code> line.</p> <p>Examples:</p> <pre><code>FastCgiServer /Applications/MAMP/fcgi-bin/php5.5.10.fcgi -idle-timeout 2400 FastCgiServer /Applications/MAMP/fcgi-bin/php5.4.25.fcgi -idle-timeout 3600 </code></pre> <p>Save the file and MAMP PRO will require you to restart all of your servers in order for the changes to take place. Test it out and you should be able to do what you where doing with no 500 Errors. </p>
35,052,210
Unexpected system error after push was received
<p>There was some github.com down time today that I wasn't aware of until I went to push about one dozen local commits.</p> <ul> <li><a href="https://status.github.com/messages">https://status.github.com/messages</a></li> <li><a href="https://twitter.com/githubstatus">https://twitter.com/githubstatus</a></li> </ul> <p>Here's the message I received when trying to push to github.com:</p> <pre><code>remote: Unexpected system error after push was received. remote: These changes may not be reflected on github.com! remote: Your unique error code: abcdefghijklmnopqrstuvwxuz </code></pre> <p>Now that github.com is back up, when I view the project commit history online, I can see these dozen commits <strong><em>have not been pushed up</em></strong> to the repo.</p> <p>I figured I could just push these changes again with <code>git push origin master</code>, but I am told <code>Everything up-to-date</code>. Similarily a <code>git pull origin master</code> also shows <code>Everything up-to-date</code>.</p> <p>How can I get these local changes pushed up to my repo on github.com?</p>
41,004,739
5
3
null
2016-01-28 03:13:40.377 UTC
5
2016-12-06 23:17:57.347 UTC
null
null
null
null
763,010
null
1
29
github
4,464
<p>I agree with Yen Chi, he should have made this an answer. At the least, do an empty commit:</p> <pre><code>git commit --allow-empty </code></pre>
337,607
Optimal map routing with Google Maps
<p>Is there a way using the Google Maps API to get back an "optimized" route given a set of waypoints (in other words, a "good-enough" solution to the traveling salesman problem), or does it always return the route with the points in the specified order?</p>
9,097,520
5
1
null
2008-12-03 15:53:09.113 UTC
12
2019-01-27 11:12:38.07 UTC
null
null
null
Soldarnal
3,420
null
1
20
google-maps|traveling-salesman
32,807
<p>There is an option in Google Maps API DirectionsRequest called optimizeWaypoints, which should do what you want. This can only handle up to 8 waypoints, though.</p> <p>Alternatively, there is an open source (MIT license) library that you can use with the Google Maps API to get an optimal (up to 15 locations) or pretty close to optimal (up to 100 locations) route.</p> <p>See <a href="http://code.google.com/p/google-maps-tsp-solver/" rel="noreferrer">http://code.google.com/p/google-maps-tsp-solver/</a></p> <p>You can see the library in action at <a href="http://www.optimap.net" rel="noreferrer">www.optimap.net</a></p>
1,055,812
How to avoid call-time pass-by-reference deprecated error in PHP?
<p>I'm trying to <strong>reduce the warnings</strong> that are sent to my apache server log.</p> <p>One warning is:</p> <blockquote> <p>Call-time pass-by-reference has been deprecated.</p> </blockquote> <p>It is <strong>hard for me to imagine</strong> why this was deprecated since it is such a useful programming feature, basically I do this:</p> <pre><code>public function takeScriptsWithMarker(&amp;$lines, $marker) { ... } </code></pre> <p>and I call this function repeatedly getting results back from it and processing them but also letting the array $lines build up by being sent into this method repeatedly. </p> <ol> <li>To reprogram this would be extensive.</li> <li>I don't want to just "turn off warnings" since I want to see other warnings.</li> </ol> <p>So, as call-by-reference is deprecated, <strong>what is the "accepted way" to attain the functionality</strong> of this pattern: namely of sending an array of strings into a method, have them be changed by the method, then continuing to use that array?</p>
1,055,826
5
0
null
2009-06-28 21:22:32.93 UTC
6
2012-07-15 10:40:16.927 UTC
2012-07-15 10:40:16.927 UTC
null
367,456
null
4,639
null
1
30
php
27,283
<p>Actually, there's no problem with the way you define the function. Is a problem with the way you call the function. So for your example, instead of calling it like:</p> <pre><code>takeScriptsWithMarker(&amp;$lines, $marker); </code></pre> <p>You'd call it like:</p> <pre><code>takeScriptsWithMarker($lines, $marker); // no ampersands :) </code></pre> <p>So the feature is still available. But I don't know the reason behind this change.</p>
1,319,385
Using XPath in ElementTree
<p>My XML file looks like the following:</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;ItemSearchResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2008-08-19"&gt; &lt;Items&gt; &lt;Item&gt; &lt;ItemAttributes&gt; &lt;ListPrice&gt; &lt;Amount&gt;2260&lt;/Amount&gt; &lt;/ListPrice&gt; &lt;/ItemAttributes&gt; &lt;Offers&gt; &lt;Offer&gt; &lt;OfferListing&gt; &lt;Price&gt; &lt;Amount&gt;1853&lt;/Amount&gt; &lt;/Price&gt; &lt;/OfferListing&gt; &lt;/Offer&gt; &lt;/Offers&gt; &lt;/Item&gt; &lt;/Items&gt; &lt;/ItemSearchResponse&gt; </code></pre> <p>All I want to do is extract the ListPrice.</p> <p>This is the code I am using:</p> <pre><code>&gt;&gt; from elementtree import ElementTree as ET &gt;&gt; fp = open("output.xml","r") &gt;&gt; element = ET.parse(fp).getroot() &gt;&gt; e = element.findall('ItemSearchResponse/Items/Item/ItemAttributes/ListPrice/Amount') &gt;&gt; for i in e: &gt;&gt; print i.text &gt;&gt; &gt;&gt; e &gt;&gt; </code></pre> <p>Absolutely no output. I also tried</p> <pre><code>&gt;&gt; e = element.findall('Items/Item/ItemAttributes/ListPrice/Amount') </code></pre> <p>No difference.</p> <p>What am I doing wrong?</p>
1,319,417
5
0
null
2009-08-23 19:48:21.81 UTC
15
2021-03-30 14:28:01.123 UTC
2017-10-09 09:35:19.17 UTC
null
4,720,935
null
144,278
null
1
46
python|xml|xpath|elementtree
67,830
<p>There are 2 problems that you have.</p> <p>1) <code>element</code> contains only the root element, not recursively the whole document. It is of type Element not ElementTree.</p> <p>2) Your search string needs to use namespaces if you keep the namespace in the XML.</p> <p><strong>To fix problem #1:</strong> </p> <p>You need to change:</p> <pre><code>element = ET.parse(fp).getroot() </code></pre> <p>to:</p> <pre><code>element = ET.parse(fp) </code></pre> <p><strong>To fix problem #2:</strong></p> <p>You can take off the xmlns from the XML document so it looks like this: </p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;ItemSearchResponse&gt; &lt;Items&gt; &lt;Item&gt; &lt;ItemAttributes&gt; &lt;ListPrice&gt; &lt;Amount&gt;2260&lt;/Amount&gt; &lt;/ListPrice&gt; &lt;/ItemAttributes&gt; &lt;Offers&gt; &lt;Offer&gt; &lt;OfferListing&gt; &lt;Price&gt; &lt;Amount&gt;1853&lt;/Amount&gt; &lt;/Price&gt; &lt;/OfferListing&gt; &lt;/Offer&gt; &lt;/Offers&gt; &lt;/Item&gt; &lt;/Items&gt; &lt;/ItemSearchResponse&gt; </code></pre> <p>With this document you can use the following search string:</p> <pre><code>e = element.findall('Items/Item/ItemAttributes/ListPrice/Amount') </code></pre> <p>The full code:</p> <pre><code>from elementtree import ElementTree as ET fp = open("output.xml","r") element = ET.parse(fp) e = element.findall('Items/Item/ItemAttributes/ListPrice/Amount') for i in e: print i.text </code></pre> <p><strong>Alternate fix to problem #2:</strong> </p> <p>Otherwise you need to specify the xmlns inside the srearch string for each element.</p> <p>The full code:</p> <pre><code>from elementtree import ElementTree as ET fp = open("output.xml","r") element = ET.parse(fp) namespace = "{http://webservices.amazon.com/AWSECommerceService/2008-08-19}" e = element.findall('{0}Items/{0}Item/{0}ItemAttributes/{0}ListPrice/{0}Amount'.format(namespace)) for i in e: print i.text </code></pre> <hr> <p>Both print: </p> <blockquote> <p>2260</p> </blockquote>
941,100
Can comments appear before the DOCTYPE declaration?
<p>I would like to place a comment (<code>&lt;!-- this --&gt;</code> style) at the very top of my HTML code, preceding the DOCTYPE declaration. Does this conform to the standards? Is it supported by the major browsers? Are there any pitfalls in doing this?</p>
941,106
5
0
null
2009-06-02 18:21:19.31 UTC
13
2018-03-08 14:40:05.91 UTC
2016-10-21 11:45:52.4 UTC
null
444,991
null
103,091
null
1
63
html|comments|doctype
19,964
<p>Writing the <strong><code>&lt;!DOCTYPE&gt;</code></strong> first is certainly best practice.</p> <p>I remember strange problems a long, long time ago where some browser (probably IE6) ignored a <strong><code>&lt;!DOCTYPE&gt;</code></strong> because there was something seemingly innocent before it - I think just whitespace, but maybe it was a comment. In any case, it was a horrible, horrible bug to have to track down, and there's certainly never any good reason to have comments or whitespace before the <strong><code>&lt;!DOCTYPE&gt;</code></strong>.</p> <p>Writing the <strong><code>&lt;!DOCTYPE&gt;</code></strong> first is, I'd say, just something experienced web developers do to avoid horrible, elusive bugs.</p>
925,698
svn switch error - is not the same repository
<p>I have recently moved the SVN server and now i am tring to relocate the working copies from my computer to the new server. But i get the strangest error. i do :</p> <pre><code>svn switch http://99.99.99.new/svn/company/project/trunk/web </code></pre> <p>but i get</p> <pre><code>svn: 'http://99.99.99.old/svn/company/project/trunk/web' is not the same repository as 'http://99.99.99.new/svn/company/project' </code></pre> <p>the move was made with dump and import ... and the repo root is on <a href="http://99.99.99.new/svn/company/project" rel="noreferrer">http://99.99.99.new/svn/company/project</a></p> <p>Do you guys have any ideas of what might be wrong ? thanks a lot</p>
925,705
5
0
null
2009-05-29 12:14:43.13 UTC
29
2021-05-22 09:19:40.15 UTC
2021-05-22 09:19:40.15 UTC
null
792,066
null
65,503
null
1
77
svn
39,868
<p>Try using </p> <pre><code>svn switch --relocate http://99.99.99.old/svn/company/project/trunk/web http://99.99.99.new/svn/company/project/trunk/web </code></pre> <p>As noted by Sporino in the comments, since Subversion 1.7, there's a seperate <code>relocate</code> command:</p> <pre><code>svn relocate http://99.99.99.old/svn/company/project/trunk/web http://99.99.99.new/svn/company/project/trunk/web </code></pre>
346,169
When to use an object instance variable versus passing an argument to the method
<p>How do you decide between passing arguments to a method versus simply declaring them as object instance variables that are visible to all of the object's methods?</p> <p>I prefer keeping instance variables in a list at the end of the Class, but this list gets longer as my program grows. I figure if a variable is passed often enough it should just be visible to all methods that need it, but then I wonder, &quot;if everything is public there will be no need for passing anything at all!&quot;</p>
346,183
5
1
null
2008-12-06 10:30:08.123 UTC
41
2020-09-08 09:24:51.61 UTC
2020-09-08 09:24:51.61 UTC
Rich B
2,514,157
Ziggy
29,182
null
1
101
variables|methods|parameter-passing|declaration
30,644
<p>Since you're referring to instance variables, I'm assuming that you're working in an object-oriented language. To some degree, when to use instance variables, how to define their scope, and when to use local variables is subjective, but there are a couple of rules of thumb you can follow whenever creating your classes.</p> <ul> <li><p><strong>Instance variables are typically considered to be attributes of a class.</strong> Think of these as adjectives of the object that will be created from your class. If your instance data can be used to help describe the object, then it's probably safe to bet it's a good choice for instance data.</p></li> <li><p><strong>Local variables are used within the scope of methods to help them complete their work.</strong> Usually, a method should have a purpose of getting some data, returning some data, and/or proccessing/running an algorithm on some data. Sometimes, it helps to think of local variables as ways of helping a method get from beginning to end. </p></li> <li><p><strong>Instance variable scope is not just for security, but for encapsulation, as well.</strong> Don't assume that the "goal should be to keep all variables private." In cases of inheritance, making variables as protected is usually a good alternative. Rather than marking all instance data public, you create getters/setters for those that need to be accessed to the outside world. Don't make them all available - only the ones you need. This will come throughout the development lifecycle - it's hard to guess from the get go.</p></li> </ul> <p>When it comes to passing data around a class, it's difficult to say what you're doing is good practice without seeing some code . Sometimes, operating directly on the instance data is fine; other times, it's not. In my opinion, this is something that comes with experience - you'll develop some intuition as your object-oriented thinking skills improve.</p>
1,038,668
Cross Domain ExternalInterface "Error calling method on NPObject"
<p>I am trying to enable communication between Javascript and Flash via ExternalInterface across domains. The Javascript works great when it is located on the same domain as the SWF. But in one case, the HTML resides on domain A, the javascript and the flash both reside on domain B. I have done all of the following:</p> <ul> <li>The embed tag has <code>allowScriptAccess="always"</code> (and the object has that as a param)</li> <li>My SWF file's actionscipt has <code>Security.allowDomain("*")</code></li> <li>My SWF also calls <code>Security.allowInsecureDomain("*")</code></li> <li>Both domain A and domain B have a <code>/crossdomain.xml</code> file which has <code>allow-access-from domain="*"</code></li> </ul> <p>The SWF is able to call javascript on the page, but when I use Javascript to call functions exposed by ExternalInterface, I get</p> <blockquote> <p>Error calling method on NPObject! [plugin exception: Error in Actionscript. Use a try/catch block to find error.]</p> </blockquote> <p>This is ActionScript 2 so <code>ExternalInterface.marshallExceptions</code> is not available.</p>
1,055,234
6
2
null
2009-06-24 14:17:26.95 UTC
6
2012-05-24 15:50:21.42 UTC
2012-05-24 15:50:21.42 UTC
null
269,804
null
75,801
null
1
19
javascript|flash|actionscript-2|externalinterface
45,093
<p>You should only need two things for this to work:</p> <p>1) <code>allowscriptaccess=always</code> will allow your swf to send stuff out to the page</p> <p>2) <code>System.security.allowDomain("yourhtmldomain.com");</code></p> <p>Note that it's <code>System.security.allowDomain()</code> in AS2 - it's not the same as AS3 or what you have written above.</p> <p>number 2 above allows the html page on domainA to call things in the swf on domainB.</p> <p>The domain your js is hosted on won't matter here, since the browser embeds it on domainA, the script is executed in domainA.</p> <p>crossdomain.xml is mainly only for loading remote files, which you aren't doing, so you can remove that if you like. (and you probably don't want to have a crossdomain.xml file with <code>allow="*"</code> sitting on your main domain, that's very bad practice)</p>
712,279
What is the usefulness of `enable_shared_from_this`?
<p>I ran across <code>enable_shared_from_this</code> while reading the Boost.Asio examples and after reading the documentation I am still lost for how this should correctly be used. Can someone please give me an example and explanation of when using this class makes sense.</p>
712,307
6
1
null
2009-04-03 01:46:07.373 UTC
121
2022-08-10 12:54:14.59 UTC
2020-06-07 07:55:57.543 UTC
MGoDave
13,611,002
MGoDave
84,842
null
1
408
c++|boost|boost-asio|tr1
116,334
<p>It enables you to get a valid <code>shared_ptr</code> instance to <code>this</code>, when all you have is <code>this</code>. Without it, you would have no way of getting a <code>shared_ptr</code> to <code>this</code>, unless you already had one as a member. This example from the <a href="http://www.boost.org/doc/libs/1_38_0/libs/smart_ptr/enable_shared_from_this.html" rel="noreferrer">boost documentation for enable_shared_from_this</a>:</p> <pre><code>class Y: public enable_shared_from_this&lt;Y&gt; { public: shared_ptr&lt;Y&gt; f() { return shared_from_this(); } } int main() { shared_ptr&lt;Y&gt; p(new Y); shared_ptr&lt;Y&gt; q = p-&gt;f(); assert(p == q); assert(!(p &lt; q || q &lt; p)); // p and q must share ownership } </code></pre> <p>The method <code>f()</code> returns a valid <code>shared_ptr</code>, even though it had no member instance. Note that you cannot simply do this:</p> <pre><code>class Y: public enable_shared_from_this&lt;Y&gt; { public: shared_ptr&lt;Y&gt; f() { return shared_ptr&lt;Y&gt;(this); } } </code></pre> <p>The shared pointer that this returned will have a different reference count from the "proper" one, and one of them will end up losing and holding a dangling reference when the object is deleted.</p> <p><code>enable_shared_from_this</code> has become part of C++ 11 standard. You can also get it from there as well as from boost.</p>
23,169,941
What does "./bin/www" do in Express 4.x?
<p>I just started to learn about Express 4.0 in my Node.js app, and I found that it generated <code>./bin/www</code> file, on which only the application server and port settings are written and everything others like middleware and routing is defined in <code>./app.js</code> file.</p> <p>However, I'm not sure what this <code>./bin/www</code> does. I've used Express 3.x and I have always defined server and port settings as well as routing and middleware on the identical <code>./app.js</code> file, and launched my node app with <code>node app.js</code>. So what's the point of using the <code>./bin/www</code>? Does it only separate the server and port definition from others?</p> <p>Right now, when I create the package using express-generator, the <code>package.json</code> includes the following definition:</p> <pre><code>"scripts": { "start": "node ./bin/www" } </code></pre> <p>However, I wonder whether I should launch my app using <code>node ./bin/www</code>, or <code>npm start</code>. Which command should I run to start my app?</p> <p>And also, when I deploy my app to heroku, what should I write in the <code>Procfile</code> file? Is <code>web: node app.js</code> enough?</p>
23,249,547
7
2
null
2014-04-19 12:15:12.22 UTC
58
2022-01-11 18:29:24.587 UTC
2015-10-03 22:14:59.947 UTC
null
2,360,798
null
2,360,798
null
1
182
javascript|node.js|heroku|express
88,149
<p>In <strong>Express 3.0</strong>, you normally would use <code>app.configure()</code> (or <code>app.use()</code>) to set up the required middleware you need. Those middleware you specified are bundled together with Express 3.0.</p> <p>Example:</p> <pre><code>var express = require('express'); var routes = require('./routes'); var user = require('./routes/user'); var http = require('http'); var path = require('path'); var app = express(); // all environments app.set('port', process.env.PORT || 3000); app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'jade'); app.use(express.favicon()); app.use(express.logger('dev')); app.use(express.compress()); app.use(express.json()); app.use(express.urlencoded()); app.use(express.methodOverride()); </code></pre> <p>In <strong>Express 4.0</strong> however, all middleware have been removed so that they can be maintained and updated independently from the core Express (except the static middleware), thus they need to be called separately (what you see in <code>app.js</code>).</p> <p>The <code>bin/</code> directory serves as a location where you can define your various <strong>startup scripts</strong>. The <code>www</code> is an example to start the express app as a web server.</p> <p>Ultimately, you could have different scripts like <code>test</code>, <code>stop</code>, or <code>restart</code>, etc. Having this structure allows you to have different startup configurations, without cramming everything into <code>app.js</code>.</p> <p>The correct way to start your Express app is: </p> <pre><code>npm start </code></pre> <p>To deploy an <strong>Express 4.x</strong> app to <strong>Heroku</strong>, add this to your <code>Procfile</code>: </p> <pre><code>web: npm start </code></pre> <p>Or if you can just use the start script in your <code>package.json</code>, heroku will automatically uses that, read more <a href="https://devcenter.heroku.com/articles/deploying-nodejs#specifying-a-start-script" rel="noreferrer">here</a></p> <pre><code>"scripts": { "start": "node ./bin/www", } </code></pre>
1,398,705
How to use regex in selenium locators
<p>I'm using selenium RC and I would like, for example, to get all the links elements with attribute href that match:</p> <pre><code>http://[^/]*\d+com </code></pre> <p>I would like to use:</p> <pre><code>sel.get_attribute( '//a[regx:match(@href, "http://[^/]*\d+.com")]/@name' ) </code></pre> <p>which would return a list of the name attribute of all the links that match the regex. (or something like it)</p> <p>thanks</p>
2,327,235
5
2
null
2009-09-09 10:05:59.977 UTC
7
2020-01-29 09:52:10.943 UTC
2009-09-09 11:40:07.317 UTC
null
170,713
null
170,713
null
1
13
regex|xpath|selenium|selenium-rc
82,591
<p>A possible solution is to use <code>sel.get_eval()</code> and write a JS script that returns a list of the links. something like the following answer: <a href="https://stackoverflow.com/questions/2007367/selenium-is-it-possible-to-use-the-regexp-in-selenium-locators/2007531#2007531">selenium: Is it possible to use the regexp in selenium locators</a></p>
1,960,919
jQuery watch for domElement changes?
<p>I have an ajax callback which injects html markup into a footer div.</p> <p>What I can't figure out is how to create a way to monitor the div for when it's contents change. Placing the layout logic I'm trying to create in the callback isn't an option as each method (callback and my layout div handler) shouldn't know about the other.</p> <p>Ideally I'd like to see some kind of event handler akin to <code>$('#myDiv').ContentsChanged(function() {...})</code> or <code>$('#myDiv').TriggerWhenContentExists( function() {...})</code></p> <p>I found a plugin called watch and an improved version of that plugin but could never get either to trigger. I tried "watching" everything I could think of (i.e. height property of the div being changed via the ajax injection) but couldn't get them to do anything at all.</p> <p>Any thoughts/help?</p>
9,845,549
5
2
null
2009-12-25 10:15:29.3 UTC
12
2021-08-15 08:54:07.06 UTC
2019-06-15 17:26:56.117 UTC
null
4,370,109
null
188,528
null
1
37
javascript|jquery|jquery-plugins|jquery-events
59,138
<p>The most effective way I've found is to bind to the <code>DOMSubtreeModified</code> event. It works well with both jQuery's <code>$.html()</code> and via standard JavaScript's <code>innerHTML</code> property.</p> <pre><code>$('#content').bind('DOMSubtreeModified', function(e) { if (e.target.innerHTML.length &gt; 0) { // Content change handler } }); </code></pre> <p><a href="http://jsfiddle.net/hnCxK/">http://jsfiddle.net/hnCxK/</a></p> <p>When called from jQuery's <code>$.html()</code>, I found the event fires twice: once to clear existing contents and once to set it. A quick <code>.length</code>-check will work in simple implementations.</p> <p>It's also important to note that the event will <strong>always</strong> fire when set to an HTML string (ie <code>'&lt;p&gt;Hello, world&lt;/p&gt;'</code>). And that the event will only <strong>fire when changed</strong> for plain-text strings.</p>
2,249,980
C#, immutability and public readonly fields
<p>I have read in many places that exposing fields publicly is not a good idea, because if you later want to change to properties, you will have to recompile all the code which uses your class.</p> <p>However, in the case of immutable classes, I don't see why you would ever need to change to properties - you're not going to be adding logic to the 'set' after all.</p> <p>Any thoughts on this, am I missing something?</p> <p>Example of the difference, for those who read code more easily than text :)</p> <pre><code>//Immutable Tuple using public readonly fields public class Tuple&lt;T1,T2&gt; { public readonly T1 Item1; public readonly T2 Item2; public Tuple(T1 item1, T2 item2) { Item1 = item1; Item2 = item2; } } //Immutable Tuple using public properties and private readonly fields public class Tuple&lt;T1,T2&gt; { private readonly T1 _Item1; private readonly T2 _Item2; public Tuple(T1 item1, T2 item2) { _Item1 = item1; _Item2 = item2; } public T1 Item1 { get { return _Item1; } } public T2 Item2 { get { return _Item2; } } } </code></pre> <p>Of course, you could use auto-properties (<code>public T1 Item1 { get; private set; }</code>), but this only gets you 'agreed immutability' as opposed to 'guaranteed immutability'...</p>
2,250,059
6
0
null
2010-02-12 06:10:18.07 UTC
6
2021-01-27 14:24:51.643 UTC
2010-07-26 18:33:48.417 UTC
null
137,483
null
11,410
null
1
35
c#|properties|field|immutability
5,597
<p>It is an obvious omission from properties that you cannot write something like:</p> <pre><code>public T2 Item2 { get; readonly set; } </code></pre> <p>I'm not even sure <code>readonly</code> is the best word to use to mean <em>"can only be set in the constructor"</em>, but that's what we're stuck with.</p> <p>This is actually a feature that many people have requested, so let's hope that it will be introduced in a hypothetical new version of C# some time soon.</p> <p>See <a href="https://stackoverflow.com/questions/2166744/why-cant-properties-be-readonly">this related question</a>.</p>
1,638,895
How do I make a <div> move up and down when I'm scrolling the page?
<p>How can I make a div element move up and down the page when the user is scrolling the page? (where that element is always visible)</p>
1,638,909
6
0
null
2009-10-28 17:44:17.607 UTC
15
2015-05-19 08:17:26.46 UTC
2014-04-11 02:17:35.343 UTC
null
1,136,709
null
96,723
null
1
61
javascript|jquery|css|html
183,183
<p>You want to apply the fixed property to the position style of the element.</p> <pre><code>position: fixed; </code></pre> <p>What browser are you working with? Not all browsers support the fixed property. Read more about who supports it, who doesn't and some work around here</p> <p><a href="http://webreflection.blogspot.com/2009/09/css-position-fixed-solution.html" rel="noreferrer">http://webreflection.blogspot.com/2009/09/css-position-fixed-solution.html</a></p>
2,070,365
How to generate an image from text on fly at runtime
<p>Can anyone guide how to generate image from input text. Image might have any extension doesn't matter.</p>
2,070,493
6
3
null
2010-01-15 08:48:29.303 UTC
34
2019-07-26 16:23:46.72 UTC
2010-01-15 09:26:32.23 UTC
null
114,400
null
188,822
null
1
72
c#|image|text|drawing
104,469
<p>Ok, assuming you want to draw a string on an image in C#, you are going to need to use the System.Drawing namespace here:</p> <pre><code>private Image DrawText(String text, Font font, Color textColor, Color backColor) { //first, create a dummy bitmap just to get a graphics object Image img = new Bitmap(1, 1); Graphics drawing = Graphics.FromImage(img); //measure the string to see how big the image needs to be SizeF textSize = drawing.MeasureString(text, font); //free up the dummy image and old graphics object img.Dispose(); drawing.Dispose(); //create a new image of the right size img = new Bitmap((int) textSize.Width, (int)textSize.Height); drawing = Graphics.FromImage(img); //paint the background drawing.Clear(backColor); //create a brush for the text Brush textBrush = new SolidBrush(textColor); drawing.DrawString(text, font, textBrush, 0, 0); drawing.Save(); textBrush.Dispose(); drawing.Dispose(); return img; } </code></pre> <p>This code will measure the string first, and then create an image of the correct size.</p> <p>If you want to save the return of this function, just call the Save method of the returned image.</p>
2,319,983
Resizing an image in asp.net without losing the image quality
<p>I am developing an ASP.NET 3.5 web application in which I am allowing my users to upload either jpeg,gif,bmp or png images. If the uploaded image dimensions are greater then 103 x 32 the I want to resize the uploaded image to 103 x 32. I have read some blog posts and articles, and have also tried some of the code samples but nothing seems to work right. Has anyone succeed in doing this? </p>
2,320,124
7
3
null
2010-02-23 16:46:43.61 UTC
21
2019-03-29 07:18:05.977 UTC
2010-05-08 10:41:02.06 UTC
null
1,431
null
122,339
null
1
35
c#|asp.net|image|image-scaling
71,740
<p>I had the same problem a while back and dealt with it this way:</p> <pre><code>private Image RezizeImage(Image img, int maxWidth, int maxHeight) { if(img.Height &lt; maxHeight &amp;&amp; img.Width &lt; maxWidth) return img; using (img) { Double xRatio = (double)img.Width / maxWidth; Double yRatio = (double)img.Height / maxHeight; Double ratio = Math.Max(xRatio, yRatio); int nnx = (int)Math.Floor(img.Width / ratio); int nny = (int)Math.Floor(img.Height / ratio); Bitmap cpy = new Bitmap(nnx, nny, PixelFormat.Format32bppArgb); using (Graphics gr = Graphics.FromImage(cpy)) { gr.Clear(Color.Transparent); // This is said to give best quality when resizing images gr.InterpolationMode = InterpolationMode.HighQualityBicubic; gr.DrawImage(img, new Rectangle(0, 0, nnx, nny), new Rectangle(0, 0, img.Width, img.Height), GraphicsUnit.Pixel); } return cpy; } } private MemoryStream BytearrayToStream(byte[] arr) { return new MemoryStream(arr, 0, arr.Length); } private void HandleImageUpload(byte[] binaryImage) { Image img = RezizeImage(Image.FromStream(BytearrayToStream(binaryImage)), 103, 32); img.Save("IMAGELOCATION.png", System.Drawing.Imaging.ImageFormat.Gif); } </code></pre> <p>I just read that this was the the way to get highest quality.</p>
1,946,165
JSON find in JavaScript
<p>Is there a better way other than looping to find data in <a href="http://en.wikipedia.org/wiki/JSON" rel="noreferrer">JSON</a>? It's for edit and delete.</p> <pre><code>for(var k in objJsonResp) { if (objJsonResp[k].txtId == id) { if (action == 'delete') { objJsonResp.splice(k,1); } else { objJsonResp[k] = newVal; } break; } } </code></pre> <p>The data is arranged as list of maps. Like:</p> <pre><code>[ {id:value, pId:value, cId:value,...}, {id:value, pId:value, cId:value,...}, ... ] </code></pre>
1,946,247
7
1
null
2009-12-22 12:43:22.03 UTC
54
2021-01-10 02:17:35.93 UTC
2016-01-27 20:16:41.54 UTC
null
954,480
null
234,405
null
1
68
javascript|json|search
200,564
<p>(You're not searching through "JSON", you're searching through an array -- the JSON string has already been deserialized into an object graph, in this case an array.)</p> <p>Some options:</p> <h2>Use an Object Instead of an Array</h2> <p>If you're in control of the generation of this thing, does it <em>have</em> to be an array? Because if not, there's a much simpler way.</p> <p>Say this is your original data:</p> <pre><code>[ {"id": "one", "pId": "foo1", "cId": "bar1"}, {"id": "two", "pId": "foo2", "cId": "bar2"}, {"id": "three", "pId": "foo3", "cId": "bar3"} ] </code></pre> <p>Could you do the following instead?</p> <pre><code>{ "one": {"pId": "foo1", "cId": "bar1"}, "two": {"pId": "foo2", "cId": "bar2"}, "three": {"pId": "foo3", "cId": "bar3"} } </code></pre> <p>Then finding the relevant entry by ID is trivial:</p> <pre><code>id = "one"; // Or whatever var entry = objJsonResp[id]; </code></pre> <p>...as is updating it:</p> <pre><code>objJsonResp[id] = /* New value */; </code></pre> <p>...and removing it:</p> <pre><code>delete objJsonResp[id]; </code></pre> <p>This takes advantage of the fact that in JavaScript, you can index into an object using a property name as a string -- and that string can be a literal, or it can come from a variable as with <code>id</code> above.</p> <h2>Putting in an ID-to-Index Map</h2> <p>(Dumb idea, predates the above. Kept for historical reasons.)</p> <p>It looks like you need this to be an array, in which case there isn't really a better way than searching through the array unless you want to put a map on it, which you could do if you have control of the generation of the object. E.g., say you have this originally:</p> <pre><code>[ {"id": "one", "pId": "foo1", "cId": "bar1"}, {"id": "two", "pId": "foo2", "cId": "bar2"}, {"id": "three", "pId": "foo3", "cId": "bar3"} ] </code></pre> <p>The generating code could provide an id-to-index map:</p> <pre><code>{ "index": { "one": 0, "two": 1, "three": 2 }, "data": [ {"id": "one", "pId": "foo1", "cId": "bar1"}, {"id": "two", "pId": "foo2", "cId": "bar2"}, {"id": "three", "pId": "foo3", "cId": "bar3"} ] } </code></pre> <p>Then getting an entry for the id in the variable <code>id</code> is trivial:</p> <pre><code>var index = objJsonResp.index[id]; var obj = objJsonResp.data[index]; </code></pre> <p>This takes advantage of the fact you can index into objects using property names.</p> <p>Of course, if you do that, you have to update the map when you modify the array, which could become a maintenance problem.</p> <p>But if you're not in control of the generation of the object, or updating the map of ids-to-indexes is too much code and/ora maintenance issue, then you'll have to do a brute force search.</p> <h2>Brute Force Search (corrected)</h2> <p>Somewhat OT (although you <em>did</em> ask if there was a better way :-) ), but your code for looping through an array is incorrect. <a href="http://blog.niftysnippets.org/2010/11/myths-and-realities-of-forin.html" rel="noreferrer">Details here</a>, but you can't use <code>for..in</code> to loop through array indexes (or rather, if you do, you have to take special pains to do so); <code>for..in</code> loops through the <em>properties of an object</em>, not the <em>indexes of an array</em>. Your best bet with a non-sparse array (and yours is non-sparse) is a standard old-fashioned loop:</p> <pre><code>var k; for (k = 0; k &lt; someArray.length; ++k) { /* ... */ } </code></pre> <p>or</p> <pre><code>var k; for (k = someArray.length - 1; k &gt;= 0; --k) { /* ... */ } </code></pre> <p>Whichever you prefer (the latter is not always faster in all implementations, which is counter-intuitive to me, but there we are). (With a <em>sparse</em> array, you might use <code>for..in</code> but again taking special pains to avoid pitfalls; more in the article linked above.)</p> <p>Using <code>for..in</code> on an array <em>seems</em> to work in simple cases because arrays have properties for each of their indexes, and their only other default properties (<code>length</code> and their methods) are marked as non-enumerable. But it breaks as soon as you set (or a framework sets) any other properties on the array object (which is perfectly valid; arrays are just objects with a bit of special handling around the <code>length</code> property).</p>
1,563,243
Books that will cover TDD, DDD and Design Patterns in .NET
<p>I would like to get book(s) that will really give me a complete view of modern ASP.NET development using C#, TDD, ASP.NET MVC, DDD and Design Patterns such as the Repository pattern. I'm very competent with C# and ASP.NET MVC, but want to fill in the gaps. </p> <p>If you've had a good experience with a book or two that covers these topics could you please share them?</p>
1,563,333
9
0
null
2009-10-13 22:12:46.937 UTC
15
2011-03-29 12:30:36.53 UTC
null
null
null
null
135,952
null
1
13
asp.net|asp.net-mvc|tdd|domain-driven-design|repository-pattern
4,106
<p>I'm currently interested in how to architecture good .NET applications and I'm reading or have currently read some of the following books:</p> <ul> <li><a href="https://rads.stackoverflow.com/amzn/click/com/0201715945" rel="noreferrer" rel="nofollow noreferrer">Design Patterns Explained: A New Perspective on Object-Oriented Design</a></li> <li><a href="https://rads.stackoverflow.com/amzn/click/com/0321127420" rel="noreferrer" rel="nofollow noreferrer">Patterns of Enterprise Application Architecture</a> </li> <li><a href="http://www.amazon.co.uk/exec/obidos/ASIN/073562609X/ref=ox_ya_oh_product" rel="noreferrer">Microsoft .NET: Architecting Applications for the Enterprise</a> </li> <li><a href="http://www.amazon.co.uk/Microsoft-ASP-NET-AJAX-Architecting-PRO-Developer/dp/0735626219/ref=pd_bxgy_b_img_b" rel="noreferrer">Microsoft ASP.NET and AJAX: Architecting Web Applications</a></li> </ul> <p>Those two Microsoft books really explain how to design .NET applications with high testability using Inversion Of Control and such.</p> <p>And to be clear, yes they all use design patterns common in TDD, DDD, Dependency Injection, ans so on...</p>
2,272,107
How can I convert a JAR file to an EXE file?
<p>I want to created a JAR file and I want to run it on a client machine.So, I have a couple of questions:</p> <ol> <li>How can I convert the JAR file to an EXE file?</li> <li>How can I encrypt the JAR file's contents? The jar file could be extracted with WinRAR and the classes could be decompiled with any Java decompiler.</li> <li>How can I create an installer? My clients doesn't have any JVM and I don't want to ship JDK or JRE along, because they have big size.</li> </ol>
2,272,132
9
2
null
2010-02-16 10:28:28.857 UTC
6
2020-03-23 14:24:34.813 UTC
2018-07-21 06:57:03.67 UTC
null
252,518
null
252,518
null
1
23
jar|exe|java
89,979
<ol> <li><p>See this link: <a href="http://www.excelsior-usa.com/articles/java-to-exe.html" rel="noreferrer">Java to Exe</a>. It also explains what valid reasons are to do this, and when you should not.</p></li> <li><p>You can't really encrypt binaries as the machine has to understand them. That said, an optimized executable is very difficult to decompile, while plain class files are ease.</p></li> <li><p>If you have an exe there are installers enough.</p></li> </ol>
2,166,512
PHP case-insensitive in_array function
<p>Is it possible to do case-insensitive comparison when using the <code>in_array</code> function?</p> <p>So with a source array like this:</p> <pre><code>$a= array( 'one', 'two', 'three', 'four' ); </code></pre> <p>The following lookups would all return true:</p> <pre><code>in_array('one', $a); in_array('two', $a); in_array('ONE', $a); in_array('fOUr', $a); </code></pre> <p>What function or set of functions would do the same? I don't think <code>in_array</code> itself can do this.</p>
2,166,537
12
0
null
2010-01-30 01:55:13.703 UTC
24
2022-03-04 22:26:14.283 UTC
null
null
null
null
212,700
null
1
152
php|arrays
122,014
<p>you can use <a href="http://php.net/preg_grep" rel="noreferrer"><code>preg_grep()</code></a>:</p> <pre><code>$a= array( 'one', 'two', 'three', 'four' ); print_r( preg_grep( "/ONe/i" , $a ) ); </code></pre>
1,815,367
Catch and compute overflow during multiplication of two large integers
<p>I am looking for an efficient (optionally standard, elegant and easy to implement) solution to multiply relatively large numbers, and store the result into one or several integers :</p> <p>Let say I have two 64 bits integers declared like this :</p> <pre><code>uint64_t a = xxx, b = yyy; </code></pre> <p>When I do <code>a * b</code>, how can I detect if the operation results in an overflow and in this case store the carry somewhere?</p> <p>Please note that <em>I don't want to use any large-number library</em> since I have constraints on the way I store the numbers.</p>
1,815,371
14
3
null
2009-11-29 12:14:59.33 UTC
43
2021-08-01 00:29:14.767 UTC
2019-12-08 11:00:52.653 UTC
null
1,930,495
null
38,924
null
1
85
c|integer|bit-manipulation|multiplication|integer-overflow
89,642
<p><strong>1. Detecting the overflow</strong>:</p> <pre><code>x = a * b; if (a != 0 &amp;&amp; x / a != b) { // overflow handling } </code></pre> <p>Edit: Fixed division by <code>0</code> (thanks Mark!)</p> <p><strong>2. Computing the carry</strong> is quite involved. One approach is to split both operands into half-words, then apply <a href="https://en.wikipedia.org/wiki/Multiplication_algorithm#Long_multiplication" rel="noreferrer">long multiplication</a> to the half-words:</p> <pre><code>uint64_t hi(uint64_t x) { return x &gt;&gt; 32; } uint64_t lo(uint64_t x) { return ((1ULL &lt;&lt; 32) - 1) &amp; x; } void multiply(uint64_t a, uint64_t b) { // actually uint32_t would do, but the casting is annoying uint64_t s0, s1, s2, s3; uint64_t x = lo(a) * lo(b); s0 = lo(x); x = hi(a) * lo(b) + hi(x); s1 = lo(x); s2 = hi(x); x = s1 + lo(a) * hi(b); s1 = lo(x); x = s2 + hi(a) * hi(b) + hi(x); s2 = lo(x); s3 = hi(x); uint64_t result = s1 &lt;&lt; 32 | s0; uint64_t carry = s3 &lt;&lt; 32 | s2; } </code></pre> <p>To see that none of the partial sums themselves can overflow, we consider the worst case:</p> <pre><code> x = s2 + hi(a) * hi(b) + hi(x) </code></pre> <p>Let <code>B = 1 &lt;&lt; 32</code>. We then have</p> <pre><code> x &lt;= (B - 1) + (B - 1)(B - 1) + (B - 1) &lt;= B*B - 1 &lt; B*B </code></pre> <p>I believe this will work - at least it handles Sjlver's test case. Aside from that, it is untested (and might not even compile, as I don't have a C++ compiler at hand anymore).</p>
18,126,372
Safely fixing: javax.net.ssl.SSLPeerUnverifiedException: No peer certificate
<p>There are dozens of posts about this issue (javax.net.ssl.SSLPeerUnverifiedException: No peer certificate) but I haven't found anything that works for me.</p> <p>Many posts (like <a href="https://stackoverflow.com/questions/2642777/trusting-all-certificates-using-httpclient-over-https/6378872#6378872">this</a>, and <a href="https://stackoverflow.com/questions/12136907/how-to-create-an-https-connection/12172000#12172000">this</a>) "solve" this by allowing all certificates to be accepted but, of course, this is not a good solution for anything other than testing.</p> <p>Others seem quite localized and don't work for me. I really hope that someone has some insight that I lack.</p> <p>So, my problem: I'm testing on a server accessible only through the local network, connecting via HTTPS. Making the call I need to through the browser works fine. No complaining about certificates and if you check the certificates, it all looks good.</p> <p>When I try on my Android device, I get <code>javax.net.ssl.SSLPeerUnverifiedException: No peer certificate</code></p> <p>Here's the code that calls it:</p> <pre><code>StringBuilder builder = new StringBuilder(); builder.append( /* stuff goes here*/ ); httpGet.setEntity(new UrlEncodedFormEntity(nameValuePairs)); ResponseHandler&lt;String&gt; responseHandler = new BasicResponseHandler(); // Execute HTTP Post Request. Response body returned as a string HttpClient httpClient = MyActivity.getHttpClient(); HttpGet httpGet = new HttpGet(builder.toString()); String jsonResponse = httpClient.execute(httpGet, responseHandler); //Line causing the Exception </code></pre> <p>My code for <code>MyActivity.getHttpClient()</code>:</p> <pre><code>protected synchronized static HttpClient getHttpClient(){ if (httpClient != null) return httpClient; HttpParams httpParameters = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParameters, TIMEOUT_CONNECTION); HttpConnectionParams.setSoTimeout(httpParameters, TIMEOUT_SOCKET); HttpProtocolParams.setVersion(httpParameters, HttpVersion.HTTP_1_1); //Thread safe in case various AsyncTasks try to access it concurrently SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); ClientConnectionManager cm = new ThreadSafeClientConnManager(httpParameters, schemeRegistry); httpClient = new DefaultHttpClient(cm, httpParameters); CookieStore cookieStore = httpClient.getCookieStore(); HttpContext localContext = new BasicHttpContext(); localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore); return httpClient; } </code></pre> <p>Any help would be much appreciated.</p> <p><strong>Edit</strong></p> <p>Also just to mention I've had other SSL issues with another app but adding the <code>SchemeRegistry</code> portion fixed it for me before.</p> <p><strong>Edit 2</strong></p> <p>So far I've only tested on Android 3.1, but I need this to work on Android 2.2+ regardless. I just tested on the browser on my Android tab (Android 3.1) and it complains about the certificate. It's fine on my pc browser, but not on the Android browser or in my app.</p> <p><strong>Edit 3</strong></p> <p>Turns out the iOS browser also complains about it. I'm starting to think it's a certificate chain issue described here (<a href="https://stackoverflow.com/questions/13862908/ssl-certificate-is-not-trusted-on-mobile-only">SSL certificate is not trusted - on mobile only</a>)</p>
18,210,464
4
3
null
2013-08-08 12:44:25.02 UTC
14
2017-11-13 21:34:37.597 UTC
2017-05-23 12:01:59.317 UTC
null
-1
null
1,281,004
null
1
34
android|ssl-certificate
74,846
<p>It turns out my code was fine and the problem was that the server was not returning the full certificate chain. For more information see this SO post and this superuser post: </p> <p><a href="https://stackoverflow.com/questions/13862908/ssl-certificate-is-not-trusted-on-mobile-only">SSL certificate is not trusted - on mobile only</a></p> <p><a href="https://superuser.com/questions/347588/how-do-ssl-chains-work">https://superuser.com/questions/347588/how-do-ssl-chains-work</a></p>
17,732,190
How to record and save as mp3 online streaming audio
<p>I have a streaming url to stream in my application and I also record the same file to listen offline too. I am able to stream the URL with the help of media player and service, but now I am looking for the recording logic of the same file.</p> <p>How can I record live streaming and save file on the SD card?</p>
17,809,666
4
2
null
2013-07-18 19:23:37.347 UTC
8
2013-07-29 13:14:22.89 UTC
2013-07-23 12:07:29.953 UTC
null
469,983
null
1,271,465
null
1
6
android|android-mediaplayer
28,020
<p>I think your problem is solved there :</p> <p><a href="https://stackoverflow.com/a/5384161/2545832">https://stackoverflow.com/a/5384161/2545832</a></p> <p>Try to do a byte by byte operation. It works by this guy.</p> <p>Hope it helps !</p> <p>EDIT :</p> <p>Sorry didn't see the comment !</p>
18,147,400
Best way to append vector to vector
<pre><code>std::vector&lt;int&gt; a; std::vector&lt;int&gt; b; std::vector&lt;int&gt; c; </code></pre> <p>I would like to concatenate these three vectors by appending <code>b</code>'s and <code>c</code>'s elements to <code>a</code>. Which is the best way to do this, and why?</p> <hr> <p><strong>1)</strong> By using <code>vector::insert</code>:</p> <pre><code>a.reserve(a.size() + b.size() + c.size()); a.insert(a.end(), b.begin(), b.end()); a.insert(a.end(), c.begin(), c.end()); b.clear(); c.clear(); </code></pre> <p><strong>2)</strong> By using <code>std::copy</code>:</p> <pre><code>a.reserve(a.size() + b.size() + c.size()); std::copy(b.begin(), b.end(), std::inserter(a, a.end())); std::copy(c.begin(), c.end(), std::inserter(a, a.end())); b.clear(); c.clear(); </code></pre> <p><strong>3)</strong> By using <code>std::move</code> (from <code>C++11</code>):</p> <pre><code>a.reserve(a.size() + b.size() + c.size()); std::move(b.begin(), b.end(), std::inserter(a, a.end())); std::move(c.begin(), c.end(), std::inserter(a, a.end())); b.clear(); c.clear(); </code></pre>
18,147,538
4
5
null
2013-08-09 13:09:05.17 UTC
10
2018-05-21 04:00:36.3 UTC
2014-08-21 15:20:49.973 UTC
null
2,274,686
null
2,274,686
null
1
47
c++|c++11|vector|append|std
64,957
<p>In my opinion, your first solution is the best way to go.</p> <p><code>vector&lt;&gt;::insert</code> is designed to add element so it's the most adequate solution.</p> <p>You could call <code>reserve</code> on the destination vector to reserve some space, but unless you add a lot of vector together, it's likely that it wont provide much benefits: <code>vector&lt;&gt;::insert</code> know how many elements will be added, you will avoid only one <code>reserve</code> call.</p> <p><em>Note</em>: If those were <code>vector</code> of more complex type (ie a custom class, or even <code>std::string</code>), then using <code>std::move</code> could provide you with a nice performance boost, because it would avoid the copy-constructor. For a vector of <code>int</code> however, it won't give you any benefits.</p> <p><em>Note 2</em>: It's worth mentioning that using <code>std::move</code> will cause your source <code>vector</code>'s content to be unusable.</p>
6,803,322
How to achieve that Eclipse clean and build (aka rebuild)?
<p>I deleted my <code>./bin</code> folder in an Eclipse Indigo (super similar to Helios), and now I am wondering how to rebuild my Java project. I just cannot find a button like we can see in Netbeans.</p>
6,803,350
3
0
null
2011-07-23 21:09:26.067 UTC
11
2020-10-22 15:25:20.993 UTC
2013-01-07 04:04:34.997 UTC
null
394,322
null
819,822
null
1
50
java|eclipse|helios|rebuild
105,376
<p>For Eclipse you can find the rebuild option under <em>Project > Clean</em> and then select the project you want to clean up... that's all.</p> <p><a href="https://i.stack.imgur.com/ZGIL4.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ZGIL4.png" alt="Eclipse Clean projects selected below"></a></p> <p>This will build your project and create a new <code>bin</code> folder.</p>
57,271,400
Why does aggregate initialization not work anymore since C++20 if a constructor is explicitly defaulted or deleted?
<p>I'm migrating a C++ Visual Studio Project from VS2017 to VS2019.</p> <p>I'm getting an error now, that didn't occur before, that can be reproduced with these few lines of code:</p> <pre><code>struct Foo { Foo() = default; int bar; }; auto test = Foo { 0 }; </code></pre> <p>The error is</p> <blockquote> <p>(6): error C2440: 'initializing': cannot convert from 'initializer list' to 'Foo'</p> <p>(6): note: No constructor could take the source type, or constructor overload resolution was ambiguous</p> </blockquote> <p>The project is compiled with <code>/std:c++latest</code> flag. I reproduced it on <a href="https://godbolt.org/z/cHgLm3" rel="noreferrer">godbolt</a>. If I switch it to <code>/std:c++17</code>, it compiles fine as before. </p> <p>I tried to compile the same code with <a href="https://godbolt.org/z/G9c4oG" rel="noreferrer">clang</a> with <code>-std=c++2a</code> and got a similar error. Also, defaulting or deleting other constructors generates this error.</p> <p>Apparently, some new C++20 features were added in VS2019 and I'm assuming the origin of this issue is described in <a href="https://en.cppreference.com/w/cpp/language/aggregate_initialization" rel="noreferrer">https://en.cppreference.com/w/cpp/language/aggregate_initialization</a>. There it says that an aggregate can be a struct that (among other criteria) has</p> <ul> <li>no user-provided, inherited, or explicit constructors (explicitly defaulted or deleted constructors are allowed) (since C++17) (until C++20)</li> <li>no user-declared or inherited constructors (since C++20)</li> </ul> <p>Note that the part in parentheses "explicitly defaulted or deleted constructors are allowed" was dropped and that "user-provided" changed to "user-declared".</p> <p>So my first question is, am I right assuming that this change in the standard is the reason why my code compiled before but does not anymore?</p> <p>Of course, it's easy to fix this: Just remove the explicitly defaulted constructors.</p> <p>However, I have explicitly defaulted and deleted very many constructors in all of my projects because I found it was a good habit to make code much more expressive this way because it simply results in fewer surprises than with implicitly defaulted or deleted constructors. With this change however, this doesn't seem like such a good habit anymore...</p> <p><strong>So my actual question is:</strong> What is the reasoning behind this change from C++17 to C++20? Was this break of backwards compatibility made on purpose? Was there some trade off like "Ok, we're breaking backwards compatibility here, but it's for the greater good."? What is this greater good?</p>
57,271,633
4
4
null
2019-07-30 12:12:24.517 UTC
5
2020-09-28 19:09:54.867 UTC
2019-07-31 07:34:44.887 UTC
null
9,883,438
null
9,883,438
null
1
43
c++|c++17|backwards-compatibility|c++20
5,165
<p>The abstract from <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1008r1.pdf" rel="noreferrer">P1008</a>, the proposal that led to the change:</p> <blockquote> <p>C++ currently allows some types with user-declared constructors to be initialized via aggregate initialization, bypassing those constructors. The result is code that is surprising, confusing, and buggy. This paper proposes a fix that makes initialization semantics in C++ safer, more uniform,and easier to teach. We also discuss the breaking changes that this fix introduces.</p> </blockquote> <p>One of the examples they give is the following.</p> <blockquote> <pre><code>struct X { int i{4}; X() = default; }; int main() { X x1(3); // ill-formed - no matching c’tor X x2{3}; // compiles! } </code></pre> </blockquote> <p>To me, it's quite clear that the proposed changes are worth the backwards-incompatibility they bear. And indeed, it doesn't seem to be good practice anymore to <code>= default</code> aggregate default constructors.</p>
45,805,603
VS 2017 15.3 Yellow Triangles on References
<p>This morning I upgraded to VS 2017 15.3 and now am getting yellow triangles for most of my references. The project runs fine (build is good in CLI and VS and restore has been run multiple times) that I can tell (and even better on dotnetcore 2.0 actually) but these remain. Has anyone else had this happen or have a suggestion? Thanks.</p> <p>Link to project.assets.json file --> <a href="https://www.dropbox.com/s/c85yuyjiu4pnget/project.assets?dl=0" rel="noreferrer">https://www.dropbox.com/s/c85yuyjiu4pnget/project.assets?dl=0</a></p> <p><a href="https://i.stack.imgur.com/ufs6z.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ufs6z.png" alt="Yellow triangles in Solution Explorer "></a></p> <p>Also issue of greyed out usings and red references although everything builds and runs fine. </p> <p><a href="https://i.stack.imgur.com/9jyVC.png" rel="noreferrer"><img src="https://i.stack.imgur.com/9jyVC.png" alt="enter image description here"></a></p> <p><a href="https://i.stack.imgur.com/LwYFw.png" rel="noreferrer"><img src="https://i.stack.imgur.com/LwYFw.png" alt="Warnings Window"></a></p>
45,926,357
8
9
null
2017-08-21 21:13:10.817 UTC
4
2022-06-27 22:03:00.107 UTC
2017-08-28 14:24:59.497 UTC
null
67,920
null
67,920
null
1
35
visual-studio|.net-core
43,350
<p>Update: VisualStudio twitter account responded to me to note that this is a bug and they are working on a fix for the future on this....</p> <p>I have two responses to my post:</p> <p>1) The using issue noted with things greyed out was actually a ReSharper issue. If you upgrade to VS 2017 15.3 and use R# make sure you update it as well to 2017.2.</p> <p>2) The Yellow triangles issue is being looked at by the Visual Studio team but honestly I believe it to be linked to warnings in the build that those references are being coerced to either lower dependencies (ie Newtonsoft at different levels) or previews. The quickly evolving .NET 2.0 world may have exacerbated this issue. Yellow triangles have traditionally meant missing but check your warnings to see if that is related and then review the dependency chain. I will update this answer once I hear back from VS team (shout out to them and Damian Edwards + Scott Hanselman for helping me with this on Twitter).</p>
23,663,231
Does enumerate() produce a generator object?
<p>As a complete Python newbie, it certainly looks that way. Running the following...</p> <pre><code>x = enumerate(['fee', 'fie', 'foe']) x.next() # Out[1]: (0, 'fee') list(x) # Out[2]: [(1, 'fie'), (2, 'foe')] list(x) # Out[3]: [] </code></pre> <p>... I notice that: (a) <code>x</code> does have a <code>next</code> method, as seems to be required for generators, and (b) <code>x</code> can only be iterated over once, a characteristic of generators emphasized in <a href="https://stackoverflow.com/a/231855/980833">this famous <code>python</code>-tag answer</a>.</p> <p>On the other hand, the two most highly-upvoted answers to <a href="https://stackoverflow.com/questions/6416538/how-to-check-if-an-object-is-a-generator-object-in-python">this question</a> about how to determine whether an object is a generator would seem to indicate that <code>enumerate()</code> does <strong>not</strong> return a generator.</p> <pre><code>import types import inspect x = enumerate(['fee', 'fie', 'foe']) isinstance(x, types.GeneratorType) # Out[4]: False inspect.isgenerator(x) # Out[5]: False </code></pre> <p>... while a third <a href="https://stackoverflow.com/a/10644028/980833">poorly-upvoted answer</a> to that question would seem to indicate that <code>enumerate()</code> <strong>does</strong> in fact return a generator:</p> <pre><code>def isgenerator(iterable): return hasattr(iterable,'__iter__') and not hasattr(iterable,'__len__') isgenerator(x) # Out[8]: True </code></pre> <p>So what's going on? Is <code>x</code> a generator or not? Is it in some sense "generator-like", but not an actual generator? Does Python's use of duck-typing mean that the test outlined in the final code block above is actually the best one?</p> <p>Rather than continue to write down the possibilities running through my head, I'll just throw this out to those of you who will immediately know the answer. </p>
23,663,453
5
4
null
2014-05-14 19:14:43.66 UTC
5
2020-02-19 20:34:48.307 UTC
2017-05-23 12:32:10.8 UTC
null
-1
null
980,833
null
1
32
python
8,733
<p>While the Python documentation says that <code>enumerate</code> is functionally equivalent to:</p> <pre><code>def enumerate(sequence, start=0): n = start for elem in sequence: yield n, elem n += 1 </code></pre> <p>The real <code>enumerate</code> function returns an <strong>iterator</strong>, but not an actual generator. You can see this if you call <code>help(x)</code> after doing creating an <code>enumerate</code> object:</p> <pre><code>&gt;&gt;&gt; x = enumerate([1,2]) &gt;&gt;&gt; help(x) class enumerate(object) | enumerate(iterable[, start]) -&gt; iterator for index, value of iterable | | Return an enumerate object. iterable must be another object that supports | iteration. The enumerate object yields pairs containing a count (from | start, which defaults to zero) and a value yielded by the iterable argument. | enumerate is useful for obtaining an indexed list: | (0, seq[0]), (1, seq[1]), (2, seq[2]), ... | | Methods defined here: | | __getattribute__(...) | x.__getattribute__('name') &lt;==&gt; x.name | | __iter__(...) | x.__iter__() &lt;==&gt; iter(x) | | next(...) | x.next() -&gt; the next value, or raise StopIteration | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __new__ = &lt;built-in method __new__ of type object&gt; | T.__new__(S, ...) -&gt; a new object with type S, a subtype of T </code></pre> <p>In Python, generators are basically a specific type of iterator that's implemented by using a <code>yield</code> to return data from a function. However, <code>enumerate</code> is actually implemented in C, not pure Python, so there's no <code>yield</code> involved. You can find the source here: <a href="http://hg.python.org/cpython/file/2.7/Objects/enumobject.c">http://hg.python.org/cpython/file/2.7/Objects/enumobject.c</a></p>
15,959,008
Import web data in excel using VBA
<p>I want to import MutualFundsPortfolioValues to Excel. I don't know how to import data from a web site which I need to do is import web data to Excel within 2 different dates of chosen companies ..</p> <p>When I input dates to B3 and B4 cells and click Commandbutton1, Excel might import all data from my web-page to my Excel sheets "result"</p> <p>For example:</p> <pre><code>date 1: 04/03/2013 &lt;&lt;&lt;&lt; " it will be in sheets "input" cell B3 date 2 : 11/04/2013 &lt;&lt;&lt;&lt;&lt; " it will be in sheet "input " cell B4 choosen companies &lt;&lt;&lt;&lt;&lt;&lt; its Range "B7: B17" </code></pre> <p>I have added a sample excel worksheet and a printscreen of the web page.. Any ideas?</p> <p>My web page url :</p> <p><a href="http://www.spk.gov.tr/apps/MutualFundsPortfolioValues/FundsInfosFP.aspx?ctype=E&amp;submenuheader=0" rel="nofollow">http://www.spk.gov.tr/apps/MutualFundsPortfolioValues/FundsInfosFP.aspx?ctype=E&amp;submenuheader=0</a></p> <p>Sample Excel and Sample picture of the data: <a href="http://uploading.com/folders/get/b491mfb6/excel-web-query" rel="nofollow">http://uploading.com/folders/get/b491mfb6/excel-web-query</a></p>
15,962,055
2
7
null
2013-04-11 21:16:21.93 UTC
1
2014-06-27 13:26:52.35 UTC
2018-07-09 19:34:03.733 UTC
null
-1
null
2,272,046
null
1
3
vba|excel
56,441
<p>Here is the code to import data using IE Automation.</p> <blockquote> <p><strong>Input Parameters</strong> (Enter in Sheet1 as per screenshot below) <br/> start date = B3 <br/> end date = B4 <br/> Şirketler = B5 (It allows multiples values which should appear below B5 and so on)</p> </blockquote> <p><img src="https://i.stack.imgur.com/nt0rB.png" alt="enter image description here"></p> <p><strong>ViewSource of page</strong> input fileds <img src="https://i.stack.imgur.com/xeZpO.gif" alt="enter image description here"></p> <p><strong>How code works :</strong></p> <ul> <li>The code creates object of Internet Explorer and navigates to <a href="http://www.spk.gov.tr/apps/MutualFundsPortfolioValues/FundsInfosFP.aspx?ctype=E&amp;submenuheader=0" rel="nofollow noreferrer">site</a></li> <li>Waits till the page is completely loaded and ready. (IE.readystate)</li> <li>Creates the object html class</li> <li>Enter the values for the input fields from Sheet1 (txtDateBegin,txtDateEnd , lstCompany)</li> <li>Clicks on the submit button</li> <li>Iterates thru each row of table dgFunds and dumps into excel Sheet2</li> </ul> <p><strong>Code:</strong> </p> <pre><code> Dim IE As Object Sub Website() Dim Doc As Object, lastRow As Long, tblTR As Object Set IE = CreateObject("internetexplorer.application") IE.Visible = True navigate: IE.navigate "http://www.spk.gov.tr/apps/MutualFundsPortfolioValues/FundsInfosFP.aspx?ctype=E&amp;submenuheader=0" Do While IE.readystate &lt;&gt; 4: DoEvents: Loop Set Doc = CreateObject("htmlfile") Set Doc = IE.document If Doc Is Nothing Then GoTo navigate Set txtDtBegin = Doc.getelementbyid("txtDateBegin") txtDtBegin.Value = Format(Sheet1.Range("B3").Value, "dd.MM.yyyy") Set txtDtEnd = Doc.getelementbyid("txtDateEnd") txtDtEnd.Value = Format(Sheet1.Range("B4").Value, "dd.MM.yyyy") lastRow = Sheet1.Range("B65000").End(xlUp).row If lastRow &lt; 5 Then Exit Sub For i = 5 To lastRow Set company = Doc.getelementbyid("lstCompany") For x = 0 To company.Options.Length - 1 If company.Options(x).Text = Sheet1.Range("B" &amp; i) Then company.selectedIndex = x Set btnCompanyAdd = Doc.getelementbyid("btnCompanyAdd") btnCompanyAdd.Click Set btnCompanyAdd = Nothing wait Exit For End If Next Next wait Set btnSubmit = Doc.getelementbyid("btnSubmit") btnSubmit.Click wait Set tbldgFunds = Doc.getelementbyid("dgFunds") Set tblTR = tbldgFunds.getelementsbytagname("tr") Dim row As Long, col As Long row = 1 col = 1 On Error Resume Next For Each r In tblTR If row = 1 Then For Each cell In r.getelementsbytagname("th") Sheet2.Cells(row, col) = cell.innerText col = col + 1 Next row = row + 1 col = 1 Else For Each cell In r.getelementsbytagname("td") Sheet2.Cells(row, col) = cell.innerText col = col + 1 Next row = row + 1 col = 1 End If Next IE.Quit Set IE = Nothing MsgBox "Done" End Sub Sub wait() Application.wait Now + TimeSerial(0, 0, 10) Do While IE.readystate &lt;&gt; 4: DoEvents: Loop End Sub </code></pre> <p><strong>Ouput table</strong> in Sheet 2</p> <p><img src="https://i.stack.imgur.com/I0XUB.png" alt="enter image description here"></p> <p>HTH</p>
15,651,970
Extract Xcode project file from an .ipa or executable file
<p>Is there any way to extract an Xcode Project file from an .ipa (executable file)?</p> <p>I tried the following:</p> <p>Make a copy of the .ipa file and change .ipa to .zip. Double click on the <strong>Payload</strong> folder and open project folder. Right-click on that folder and select <strong>Show Package Contents</strong>.</p> <p>Everything seems to be okay, but I want to see the code, which is now showing as executable files. Is there any tool or any way to achieve this?</p>
15,652,006
4
0
null
2013-03-27 04:34:01.343 UTC
2
2018-08-18 22:37:04.5 UTC
2013-03-27 04:48:12.33 UTC
null
603,977
null
1,954,052
null
1
11
xcode
42,828
<p>The .ipa file contains, as you have noticed, your compiled project. So no, you can't get the Xcode project file or the source code. (Unless of course, someone deliberately copied those files in).</p>
5,367,961
Casting from one pointer to pointer type to another in Golang error
<p>Can anyone tell my why this wouldn't compile?</p> <pre><code>package main type myint int func set(a **myint) { i := myint(5) *a = &amp;i } func main() { var k *int set( (**myint)(&amp;k) ) // cannot convert &amp;k (type **int) to type **myint print( *k ) } </code></pre> <p>My reasoning so far is this. All types in Golang are different, but it allows to convert from one type to another with C-like cast syntax as long as underlying types are identical. In my example, converting 'int' to 'myint' is not a problem. '*int' to '*myint' isn't either. It's when you have pointer to pointer problems arise. I've been stuck on this for the second day now. Any help is appreciated.</p>
5,372,575
2
0
null
2011-03-20 10:43:04.697 UTC
10
2014-02-04 12:00:34.053 UTC
2011-03-20 17:49:46.56 UTC
null
357,978
null
357,978
null
1
21
pointers|go
38,233
<p>Here's my analysis.</p> <p><code>(**myint)(&amp;k)</code> -- cannot convert <code>&amp;k</code> (<code>type **int</code>) to <code>type **myint</code>:</p> <p><code>type **int</code> and <code>type **myint</code> are unnamed pointer types and their pointer base types, <code>type *int</code> and <code>type *myint</code>, don't have identical underlying types.</p> <p>If T (<code>*int</code> or <code>*myint</code>) is a pointer type literal, the corresponding underlying type is T itself.</p> <p><code>(*myint)(k)</code> -- can convert <code>k</code> (<code>type *int</code>) to <code>type *myint</code>:</p> <p><code>type *int</code> and <code>type *myint</code> are unnamed pointer types and their pointer base types, <code>type int</code> and <code>type myint</code> (<code>type myint int</code>), have identical underlying types.</p> <p>If T (<code>int</code>) is a predeclared type, the corresponding underlying type is T itself. If T (<code>myint</code>) is neither a predeclared type or nor a type literal, T's underlying type is the underlying type of the type to which T refers in its type declaration (<code>type myint int</code>). </p> <p><code>(myint)(*k)</code> -- can convert <code>*k</code> (<code>type int</code>) to <code>type myint</code>:</p> <p><code>type int</code> and <code>type myint</code> have identical underlying types. </p> <p>If T (<code>int</code>) is a predeclared type, the corresponding underlying type is T itself. If T (<code>myint</code>) is neither a predeclared type or nor a type literal, T's underlying type is the underlying type of the type to which T refers in its type declaration (<code>type myint int</code>). </p> <p>Here's the underlying type example from the Types section revised to use integers and int pointers.</p> <pre><code>type T1 int type T2 T1 type T3 *T1 type T4 T3 </code></pre> <p>The underlying type of <code>int</code>, <code>T1</code>, and <code>T2</code> is <code>int</code>. The underlying type of <code>*T1</code>, <code>T3</code>, and <code>T4</code> is <code>*T1</code>. </p> <p>References:</p> <p><a href="http://golang.org/doc/go_spec.html" rel="noreferrer">The Go Programming Language Specification</a></p> <p><a href="http://golang.org/doc/go_spec.html#Conversions" rel="noreferrer">Conversions</a></p> <p><a href="http://golang.org/doc/go_spec.html#Types" rel="noreferrer">Types</a></p> <p><a href="http://golang.org/doc/go_spec.html#Properties_of_types_and_values" rel="noreferrer">Properties of types and values</a></p> <p><a href="http://golang.org/doc/go_spec.html#Type_declarations" rel="noreferrer">Type declarations</a></p> <p><a href="http://golang.org/doc/go_spec.html#Predeclared_identifiers" rel="noreferrer">Predeclared identifiers</a></p> <p><a href="http://golang.org/doc/go_spec.html#Pointer_types" rel="noreferrer">Pointer Type</a></p>
453,099
Size of static array
<p>I declare a static char array, then I pass it to a function. How to get the no. of bytes in the array inside the function?</p>
453,104
7
0
null
2009-01-17 10:25:19.35 UTC
4
2018-10-17 10:08:20.03 UTC
null
null
null
Ron
49,781
null
1
15
c++|arrays|size
38,505
<p>You would have to pass it to the function. You can use sizeof() to get the size of an array. </p> <pre><code>const char foo[] = "foobar"; void doSomething( char *ptr, int length) { } doSomething(foo, sizeof(foo)); </code></pre> <p>This <a href="http://msdn.microsoft.com/en-us/library/4s7x1k91(VS.71).aspx" rel="nofollow noreferrer">MSDN page</a> has explains more about sizeof and has a bigger example.</p> <p>Edit: * <a href="https://stackoverflow.com/questions/453099/size-of-static-array#453131">see j_random_hacker's answer</a> for an intriguing technique using templates... *</p>
49,564
How to implement file upload progress bar on web?
<p>I would like display something more meaningful that animated gif while users upload file to my web application. What possibilities do I have? </p> <p><em>Edit: I am using .Net but I don't mind if somebody shows me platform agnostic version.</em></p>
49,590
7
0
null
2008-09-08 12:24:25.103 UTC
11
2009-08-28 14:12:52.51 UTC
2008-09-08 20:09:09.26 UTC
Jakub Šturc
2,361
Jakub Šturc
2,361
null
1
19
.net|javascript|ajax
20,435
<p>Here are a couple of versions of what you're looking for for some common JavaScript toolkits.</p> <ul> <li>Mootools - <a href="http://digitarald.de/project/fancyupload/" rel="noreferrer">http://digitarald.de/project/fancyupload/</a></li> <li>Extjs - <a href="http://extjs.com/learn/Extension:UploadForm" rel="noreferrer">http://extjs.com/learn/Extension:UploadForm</a></li> </ul>
1,317,486
How to avoid resubmit in jsp when refresh?
<p>I am writing a program, but i encounter a problem: when I refresh the jsp page, system will automatically resubmit the whole page, and i don't know how to avoid it, can someone help me ?</p>
1,317,597
7
0
null
2009-08-23 01:17:03.403 UTC
15
2019-06-26 07:12:07.67 UTC
null
null
null
null
140,899
null
1
22
jsp|refresh|submit
68,880
<p>Here's an explanation of the problem...</p> <p>Clicking the "submit" button on a form sends a request to the web server, which includes all the data entered on the form. Not only the URL but also the form data is part of the request, and this request is remembered by the browser. If the user clicks "refresh", the browser repeats the request, sending the same URL <em>and</em> form data to the web server again.</p> <p>But forms can be submitted in two different ways, GET or POST, depending on the "method" attribute of the "form" tag. There is a convention that a GET request has no side-effects; it only fetches data but does not make any changes to the database. On the other hand, if a request changes data it should always use a POST request. As I said, these are only conventions, and there is not much technical difference between them, but a very important difference is that browsers will warn the user if they try to repeat a POST -- clicking "refresh" will pop up a dialog box warning the user that this may cause an operation to be repeated, and confirming that they really want to resubmit. The browser does not show this confirmation when refreshing a GET request.</p> <p>Is your form using the GET method, as suspected by @mk? If so, changing it to POST is the simplest solution, since this will at least mean that the user is warned if they try to refresh.</p> <p>But a better solution is the POST+REDIRECT+GET idiom suggested by @cletus. This splits the database update (POST) and the view (GET) into two operations. Clicking refresh on the browser then merely repeats the GET, which has no side-effects.</p>
376,732
Zend Framework on nginx
<p>The Zend Framework based site I have been working on is now being migrated to its production server. This server turns out to be nginx (surprise!). Naturally the site does not work correctly as it was developed on Apache and relies on an htaccess file. </p> <p>My question is... anyone have any experience with this? Any ideas on how to translate what the htaccess file does to an nginx.conf file? I'm researching this but am hoping someone already has experience with this. Thanks!</p> <p>EDIT: This is the current htaccess:</p> <pre><code>RewriteEngine On RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [NC,L] RewriteRule ^.*$ /index.php [NC,L] </code></pre>
460,599
8
4
null
2008-12-18 02:31:24.56 UTC
17
2014-02-09 05:12:09.643 UTC
2008-12-18 03:26:09.02 UTC
gaoshan88
11,252
gaoshan88
11,252
null
1
16
php|zend-framework|mod-rewrite|nginx
34,957
<p>I know it's a pretty old thread but it might help some people anyway.</p> <p>Basically it redirects any 404 error to index.php, but if the file exists (type file) it will set the right root.</p> <p>I did it from the top of my head. It might not be working right away, and you have to put the right path and fastcgi config. I also put everything back to index.php as it should work like that with Zend_Framework</p> <pre><code>error_page 404 = /index.php; location / { if (-f $request_filename) { root /var/www; } } location ~ \.php$ { fastcgi_pass unix:/tmp/php.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/index.php; include /etc/nginx/fastcgi_params; } </code></pre>
462,165
error: ‘NULL’ was not declared in this scope
<p>I get this message when compiling C++ on gcc 4.3</p> <pre><code>error: ‘NULL’ was not declared in this scope </code></pre> <p>It appears and disappears and I don't know why. Why?</p> <p>Thanks.</p>
462,203
8
2
null
2009-01-20 17:05:40.377 UTC
22
2022-06-11 21:45:53.077 UTC
2009-01-20 17:13:17.693 UTC
null
48,461
null
48,461
null
1
130
c++|gcc|pointers|null
180,892
<p><code>NULL</code> is not a keyword. It's an identifier defined in some standard headers. You can include </p> <pre><code>#include &lt;cstddef&gt; </code></pre> <p>To have it in scope, including some other basics, like <code>std::size_t</code>.</p>
189,751
Google App Engine and 404 error
<p>I've setup a static website on GAE using hints found elsewhere, but can't figure out how to return a 404 error. My app.yaml file looks like</p> <pre><code>- url: (.*)/ static_files: static\1/index.html upload: static/index.html - url: / static_dir: static </code></pre> <p>with all the static html/jpg files stored under the static directory. The above works for files that exist, but returns a null length file if they don't. The answer is probably to write a python script to return a 404 error, but how do you set things up to serve the static files that exist but run the script for files that don't?</p> <p>Here is the log from fetching a non-existent file (nosuch.html) on the development application server:</p> <pre><code>ERROR 2008-11-25 20:08:34,084 dev_appserver.py] Error encountered reading file "/usr/home/ctuffli/www/tufflinet/static/nosuch.html": [Errno 2] No such file or directory: '/usr/home/ctuffli/www/tufflinet/static/nosuch.html' INFO 2008-11-25 20:08:34,088 dev_appserver.py] "GET /nosuch.html HTTP/1.1" 404 - </code></pre>
189,935
9
1
null
2008-10-10 00:51:00.14 UTC
28
2016-01-04 01:06:44.697 UTC
2010-06-29 14:26:58.573 UTC
ctuffli
365,695
ctuffli
26,683
null
1
38
python|google-app-engine|http-status-code-404
32,660
<p>You need to register a catch-all script handler. Append this at the end of your app.yaml:</p> <pre><code>- url: /.* script: main.py </code></pre> <p>In main.py you will need to put this code:</p> <pre><code>from google.appengine.ext import webapp from google.appengine.ext.webapp.util import run_wsgi_app class NotFoundPageHandler(webapp.RequestHandler): def get(self): self.error(404) self.response.out.write('&lt;Your 404 error html page&gt;') application = webapp.WSGIApplication([('/.*', NotFoundPageHandler)], debug=True) def main(): run_wsgi_app(application) if __name__ == "__main__": main() </code></pre> <p>Replace <code>&lt;Your 404 error html page&gt;</code> with something meaningful. Or better use a template, you can read how to do that <a href="http://code.google.com/appengine/docs/gettingstarted/templates.html" rel="noreferrer">here</a>.</p> <p>Please let me know if you have problems setting this up.</p>
1,195,549
How to avoid 'undefined index' errors?
<p>I am working through some code done by a previous developer. I'm pretty new to PHP so I am wondering if there is any well known pattern or solution to this problem.</p> <p>Basically the original author does not check any array indexes before he tries to use them. I know I can use <code>isset()</code> to check each before it is used, but right now there are hundreds of lines where these errors are appearing. Before I put on some music and start slamming my head into my keyboard I want to make sure there is not some nice shortcut for handling this. Here is a typical section of code I'm looking at:</p> <pre><code> /* snip */ &quot;text&quot; =&gt; $link . $top_pick_marker . $output['author'] . &quot;&amp;nbsp;&quot; . &quot;&amp;nbsp;&quot; . $output['new_icon'] . $output['rec_labels'] . &quot; &amp;nbsp; &quot; . $output['admin_link'] . $output['alternate_title'] . $output['access_info'] . $output['description'] . $output['url'] . $output['subject_terms'] . $output['form_subdivisions'] . $output['dates_of_coverage'] . $output['update_frequency'] . $output['place_terms'], /* snip */ </code></pre> <p>I know I can use <code>isset()</code> here for each item. I would have to rearrange things a bit and remove all the concatenation as it is now. Is there any other easy way to do this or am I just stuck with it?</p>
1,195,591
10
2
null
2009-07-28 17:31:34.157 UTC
7
2021-01-18 20:52:12.027 UTC
2021-01-18 20:52:12.027 UTC
null
1,839,439
Alex Ciarlillo
null
null
1
40
php|arrays
112,935
<p>Figure out what keys are in the $output array, and fill the missing ones in with empty strings.</p> <pre><code>$keys = array_keys($output); $desired_keys = array('author', 'new_icon', 'admin_link', 'etc.'); foreach($desired_keys as $desired_key){ if(in_array($desired_key, $keys)) continue; // already set $output[$desired_key] = ''; } </code></pre>
362,514
How can I return the current action in an ASP.NET MVC view?
<p>I wanted to set a CSS class in my master page, which depends on the current controller and action. I can get to the current controller via <code>ViewContext.Controller.GetType().Name</code>, but how do I get the current action (e.g. <code>Index</code>, <code>Show</code> etc.)?</p>
362,539
11
0
null
2008-12-12 11:33:34.607 UTC
86
2017-10-16 09:09:53.323 UTC
2014-01-03 00:08:25.897 UTC
Simucal
159,270
buggs
33,647
null
1
295
c#|asp.net-mvc
158,605
<p>Use the <code>ViewContext</code> and look at the <code>RouteData</code> collection to extract both the controller and action elements. But I think setting some data variable that indicates the application context (e.g., "editmode" or "error") rather than controller/action reduces the coupling between your views and controllers.</p>
600,733
Using Java to find substring of a bigger string using Regular Expression
<p>If I have a string like this:</p> <pre><code>FOO[BAR] </code></pre> <p>I need a generic way to get the "BAR" string out of the string so that no matter what string is between the square brackets it would be able to get the string.</p> <p>e.g.</p> <pre><code>FOO[DOG] = DOG FOO[CAT] = CAT </code></pre>
600,740
11
0
null
2009-03-01 22:58:05.41 UTC
22
2019-08-27 15:35:34.433 UTC
2009-04-03 21:57:00.58 UTC
Chad Birch
41,665
digiarnie
30,563
null
1
157
java|regex|string
370,479
<p>You should be able to use non-greedy quantifiers, specifically *?. You're going to probably want the following:</p> <pre><code>Pattern MY_PATTERN = Pattern.compile("\\[(.*?)\\]"); </code></pre> <p>This will give you a pattern that will match your string and put the text within the square brackets in the first group. Have a look at the <a href="http://download.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html" rel="noreferrer">Pattern API Documentation</a> for more information.</p> <p>To extract the string, you could use something like the following:</p> <pre><code>Matcher m = MY_PATTERN.matcher("FOO[BAR]"); while (m.find()) { String s = m.group(1); // s now contains "BAR" } </code></pre>
866,820
Visual studio forgets window settings and makes a mess
<p>I have this problem where I open Visual Studio and the internal windows are scattered all over the place. None of them are docked; some that should be visible have become invisible and vice versa. I then have to spend ages getting the windows back where I like them.</p> <p>It only seems to happen with some solutions and only appeared recently.</p> <p>For the life of me I can't fix the problem. Has anyone else been through this?</p>
866,957
12
2
null
2009-05-15 03:11:48.463 UTC
23
2019-02-26 21:06:37.52 UTC
2009-05-15 14:44:30.043 UTC
null
685
null
21,966
null
1
66
windows|visual-studio|dock
26,302
<p>Sounds like there is definitely a problem with Visual Studio retaining your settings between round-trips and possibly your Visual Studio settings profile in general.</p> <p>The solution I'd recommend is firstly to reset all settings, secondly customize things to your personal preference and finally take a backup of those customized settings. The idea is that this settings backup file can be used later to automate a quick settings restore to a point you are happy with. The following steps show how to do this and hopefully should sort out even the most confused Visual Studio setting issues:</p> <ol> <li><p>Close down all instances of Visual Studio.</p></li> <li><p>Go to Start > Programs > Visual Studio 200X > Visual Studio Tools > and choose 'Visual Studio 200X Command Prompt'</p></li> <li><p>Run the sligthly less well known 'devenv.exe /ResetUserData' command. With this command you will lose all of your Visual Studio environment settings and customizations. Because of this, the /ResetUserData switch is not officially supported and Microsoft does not advertise it (the switch is not described in the help for devenv.exe you get when you type devenv.exe /? in a command prompt). Importantly, wait for the resulting devenv.exe process to disappear from Task Manager or even better Process Explorer.</p></li> <li><p>When the process disappears from Task Manager or Process Explorer, run 'devenv.exe /ResetSettings' which will restore the IDE's default settings and eventually start a single instance of Visual Studio.</p></li> <li><p>Now in Visual Studio choose 'Import and Export Settings...' near the bottom of the 'Tools' menu to start the Import and Export Settings Wizard.</p></li> <li><p>Choose 'Reset all settings' radio button and Next > Choose 'No, just reset settings, overwriting my current settings' and Next > Choose your personal 'Settings Collection' preference, I would choose Visual C# Development Settings here (Note: What you choose here has an effect on keyboard shortcuts etc. but you can always repeat this process until happy) and click Finish.</p></li> <li><p>When you get the message that 'Your settings were successfully reset to XXXXXX Development Settings.' click Close then spend a good bit of time adding any personal customizations to Visual Studio such as opening windows you always want open, customizing toolbars and adding any toolbar buttons etc.</p></li> <li><p>When you are finished with your personal customization and completely happy with your setup go again to Tools > 'Import and Export Settings...'</p></li> <li><p>Choose 'Export selected environment settings' radio button and Next > Tick 'All Settings' and Next > Choose a file name and directory and click Finish to store a backup of your current settings in a .vssettings file.</p></li> <li><p>In future if things go haywire again head back to Tools > 'Import and Export Settings...' and this time choose 'Import selected environment settings' radio button and Next > Choose 'No, just import new settings, overwriting my current settings' and Next > Either choose the name of your .vssettings file from the list (usually under the My Settings folder) or Browse.. to where you saved the file and Next > Tick 'All Settings' and click Finish.</p></li> <li><p>Importantly, close the single instance of Visual Studio. Any future instance you open should retain your latest customizations.</p></li> </ol>
1,104,972
How do I get the name of the active user via the command line in OS X?
<p>How do I get the name of the active user via the command line in OS X?</p>
1,105,078
12
0
null
2009-07-09 16:23:18.773 UTC
14
2021-10-17 13:30:21.643 UTC
null
null
null
null
1,512
null
1
130
macos|command-line
202,062
<p>as 'whoami' has been obsoleted, it's probably more forward compatible to use:</p> <pre><code>id -un </code></pre>
856,845
How To: Best way to draw table in console app (C#)
<p>I have an interesting question. Imagine I have a lot of data changing in very fast intervals. I want to display that data as a table in console app. f.ex:</p> <pre><code>------------------------------------------------------------------------- | Column 1 | Column 2 | Column 3 | Column 4 | ------------------------------------------------------------------------- | | | | | | | | | | | | | | | ------------------------------------------------------------------------- </code></pre> <p>How to keep things fast and how to fix column widths ? I know how to do that in java, but I don't how it's done in C#.</p>
856,918
16
1
null
2009-05-13 08:50:12.123 UTC
49
2022-09-17 15:18:00.47 UTC
null
null
null
null
5,369
null
1
131
c#|console|drawing
190,859
<p>You could do something like the following:</p> <pre><code>static int tableWidth = 73; static void Main(string[] args) { Console.Clear(); PrintLine(); PrintRow("Column 1", "Column 2", "Column 3", "Column 4"); PrintLine(); PrintRow("", "", "", ""); PrintRow("", "", "", ""); PrintLine(); Console.ReadLine(); } static void PrintLine() { Console.WriteLine(new string('-', tableWidth)); } static void PrintRow(params string[] columns) { int width = (tableWidth - columns.Length) / columns.Length; string row = "|"; foreach (string column in columns) { row += AlignCentre(column, width) + "|"; } Console.WriteLine(row); } static string AlignCentre(string text, int width) { text = text.Length &gt; width ? text.Substring(0, width - 3) + "..." : text; if (string.IsNullOrEmpty(text)) { return new string(' ', width); } else { return text.PadRight(width - (width - text.Length) / 2).PadLeft(width); } } </code></pre>
484,516
Arguments for/against Business Logic in stored procedures
<p>What are the arguments for and against business logic in stored procedures? </p>
484,563
17
1
null
2009-01-27 18:04:23.193 UTC
18
2019-09-25 09:27:55.167 UTC
null
null
null
Gern Blandston
6,624
null
1
45
stored-procedures|business-logic
21,606
<p><strong>Against stored procedures: business logic in programming space</strong></p> <p>I place a high value on the power of expression, and I don't find the SQL space to be all that expressive. Use the best tools you have on hand for the most appropriate tasks. Fiddling with logic and higher order concepts is best done at the highest level. Consequently, storage and mass data manipulation is best done at the server level, probably in stored procedures.</p> <p>But it depends. If you have multiple applications interacting with one storage mechanism and you want to make sure it maintains its integrity and workflow, then you should offload all of the logic into the database server. Or, be prepared to manage concurrent development in multiple applications.</p>
1,337,419
How do you convert numbers between different bases in JavaScript?
<p>I would like to convert numbers between different bases, such as hexadecimal and decimal.</p> <p><strong><em>Example:</em></strong> How do you convert hexadecimal <code>8F</code> to decimal?</p>
1,337,428
18
1
null
2009-08-26 20:52:08.813 UTC
25
2022-08-16 01:27:30.033 UTC
2017-09-17 00:20:43.523 UTC
null
3,167,040
null
1,709,270
null
1
101
javascript
120,837
<p><strong>The API</strong></p> <p><em>To convert to a number from a hex string:</em></p> <pre><code>parseInt(string, radix) </code></pre> <ul> <li><p>string: Required. The string to be parsed</p></li> <li><p>radix: Optional. A number (from 2 to 36) that represents the numeral system to be used</p></li> </ul> <p><em>To convert from a number to a hex string:</em></p> <pre><code>NumberObject.toString(radix) </code></pre> <ul> <li>radix: Optional. Specifies the base radix you would like the number displayed as.</li> </ul> <p><em>Example radix values:</em></p> <ul> <li><strong>2</strong> - The number will show as a binary value</li> <li><strong>8</strong> - The number will show as an octal value</li> <li><strong>16</strong> - The number will show as an hexadecimal value</li> </ul> <hr> <p><strong>Example Usage</strong></p> <p>Integer value to hex:</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-js lang-js prettyprint-override"><code>var i = 10; console.log( i.toString(16) );</code></pre> </div> </div> </p> <p>Hex string to integer value:</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-js lang-js prettyprint-override"><code>var h = "a"; console.log( parseInt(h, 16) );</code></pre> </div> </div> </p> <p>Integer value to decimal:</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-js lang-js prettyprint-override"><code> var d = 16; console.log( d.toString(10) );</code></pre> </div> </div> </p>
201,479
What is base 64 encoding used for?
<p>I've heard people talking about "base 64 encoding" here and there. What is it used for?</p>
201,510
19
1
null
2008-10-14 14:50:52.35 UTC
353
2021-12-08 06:06:17.027 UTC
2015-12-20 09:48:47.79 UTC
null
3,262,406
MrDatabase
22,471
null
1
967
encoding|base64|encode
472,027
<p>When you have some binary data that you want to ship across a network, you generally don't do it by just streaming the bits and bytes over the wire in a raw format. Why? because some media are made for streaming text. You never know -- some protocols may interpret your binary data as control characters (like a modem), or your binary data could be screwed up because the underlying protocol might think that you've entered a special character combination (like how FTP translates line endings). </p> <p>So to get around this, people encode the binary data into characters. Base64 is one of these types of encodings. </p> <p><strong>Why 64?</strong><br> Because you can generally rely on the same 64 characters being present in many character sets, and you can be reasonably confident that your data's going to end up on the other side of the wire uncorrupted.</p>
70,577
Best online resource to learn Python?
<p>I am new to any scripting language. But, Still I worked on scripting a bit like tailoring other scripts to work for my purpose. For me, What is the best online resource to learn Python?</p> <p>[Response Summary:] </p> <p>Some Online Resources:</p> <p><a href="http://docs.python.org/tut/tut.html" rel="nofollow noreferrer"> <a href="http://docs.python.org/tut/tut.html" rel="nofollow noreferrer">http://docs.python.org/tut/tut.html</a></a> - Beginners</p> <p><a href="http://diveintopython3.ep.io/" rel="nofollow noreferrer"> <a href="http://diveintopython3.ep.io/" rel="nofollow noreferrer">http://diveintopython3.ep.io/</a></a> - Intermediate</p> <p><a href="http://www.pythonchallenge.com/" rel="nofollow noreferrer"><a href="http://www.pythonchallenge.com/" rel="nofollow noreferrer">http://www.pythonchallenge.com/</a></a> - Expert Skills</p> <p><a href="http://docs.python.org/" rel="nofollow noreferrer"><a href="http://docs.python.org/" rel="nofollow noreferrer">http://docs.python.org/</a></a> - collection of all knowledge</p> <p>Some more:</p> <p><a href="http://www.swaroopch.com/notes/Python" rel="nofollow noreferrer"> A Byte of Python. </a></p> <p><a href="http://rgruet.free.fr/PQR25/PQR2.5.html" rel="nofollow noreferrer">Python 2.5 Quick Reference</a></p> <p><a href="http://www.edgewall.org/python-sidebar/" rel="nofollow noreferrer">Python Side bar</a></p> <p><a href="http://www.learningpython.com/" rel="nofollow noreferrer">A Nice blog for beginners</a></p> <p><a href="http://www.greenteapress.com/thinkpython/thinkpython.html" rel="nofollow noreferrer">Think Python: An Introduction to Software Design</a></p>
70,616
21
0
null
2008-09-16 09:08:47.377 UTC
144
2012-03-08 13:48:10.493 UTC
2012-03-08 13:47:52.523 UTC
Sreenath
1,288
Sreenath
11,372
null
1
28
python
67,232
<p>If you need to learn python from scratch - you can start here: <a href="http://docs.python.org/tut/tut.html" rel="nofollow noreferrer">http://docs.python.org/tut/tut.html</a> - good begginers guide</p> <p>If you need to extend your knowledge - continue here <a href="http://diveintopython3.ep.io/" rel="nofollow noreferrer">http://diveintopython3.ep.io/</a> - good intermediate level book</p> <p>If you need perfect skills - complete this <a href="http://www.pythonchallenge.com/" rel="nofollow noreferrer">http://www.pythonchallenge.com/</a> - outstanding and interesting challenge</p> <p>And the perfect source of knowledge is <a href="http://docs.python.org/" rel="nofollow noreferrer">http://docs.python.org/</a> - collection of all knowledge</p>
141,291
How to list only top level directories in Python?
<p>I want to be able to list only the directories inside some folder. This means I don't want filenames listed, nor do I want additional sub-folders.</p> <p>Let's see if an example helps. In the current directory we have:</p> <pre><code>&gt;&gt;&gt; os.listdir(os.getcwd()) ['cx_Oracle-doc', 'DLLs', 'Doc', 'include', 'Lib', 'libs', 'LICENSE.txt', 'mod_p ython-wininst.log', 'NEWS.txt', 'pymssql-wininst.log', 'python.exe', 'pythonw.ex e', 'README.txt', 'Removemod_python.exe', 'Removepymssql.exe', 'Scripts', 'tcl', 'Tools', 'w9xpopen.exe'] </code></pre> <p>However, I don't want filenames listed. Nor do I want sub-folders such as \Lib\curses. Essentially what I want works with the following:</p> <pre><code>&gt;&gt;&gt; for root, dirnames, filenames in os.walk('.'): ... print dirnames ... break ... ['cx_Oracle-doc', 'DLLs', 'Doc', 'include', 'Lib', 'libs', 'Scripts', 'tcl', 'Tools'] </code></pre> <p>However, I'm wondering if there's a simpler way of achieving the same results. I get the impression that using os.walk only to return the top level is inefficient/too much.</p>
141,327
21
2
null
2008-09-26 19:01:06.65 UTC
38
2022-03-24 02:25:54.87 UTC
null
null
null
fuentesjr
10,708
null
1
180
python|filesystems
216,253
<p>Filter the result using os.path.isdir() (and use os.path.join() to get the real path):</p> <pre><code>&gt;&gt;&gt; [ name for name in os.listdir(thedir) if os.path.isdir(os.path.join(thedir, name)) ] ['ctypes', 'distutils', 'encodings', 'lib-tk', 'config', 'idlelib', 'xml', 'bsddb', 'hotshot', 'logging', 'doc', 'test', 'compiler', 'curses', 'site-packages', 'email', 'sqlite3', 'lib-dynload', 'wsgiref', 'plat-linux2', 'plat-mac'] </code></pre>
246,007
How to determine whether a given Linux is 32 bit or 64 bit?
<p>When I type <code>uname -a</code>, it gives the following output.</p> <pre><code>Linux mars 2.6.9-67.0.15.ELsmp #1 SMP Tue Apr 22 13:50:33 EDT 2008 i686 i686 i386 GNU/Linux </code></pre> <p>How can I know from this that the given OS is 32 or 64 bit?</p> <p>This is useful when writing <code>configure</code> scripts, for example: what architecture am I building for?</p>
246,014
21
0
2008-10-29 06:59:40.757 UTC
2008-10-29 06:59:40.757 UTC
162
2018-01-05 23:20:29.29 UTC
2011-12-08 21:43:53.07 UTC
swapnonil
387,076
swapnonil
11,602
null
1
472
linux|shell|32bit-64bit|processor
520,290
<p>Try <a href="http://linuxmanpages.net/manpages/fedora16/man1/uname.1.html" rel="noreferrer"><code>uname -m</code></a>. Which is short of <code>uname --machine</code> and it outputs: </p> <pre><code>x86_64 ==&gt; 64-bit kernel i686 ==&gt; 32-bit kernel </code></pre> <hr> <p>Otherwise, <strong>not for the Linux kernel, but for the CPU</strong>, you type:</p> <pre><code>cat /proc/cpuinfo </code></pre> <p>or:</p> <pre><code>grep flags /proc/cpuinfo </code></pre> <p>Under "flags" parameter, you will see various values: see "<a href="https://unix.stackexchange.com/a/43540">What do the flags in /proc/cpuinfo mean?</a>" Among them, one is named <code>lm</code>: <code>Long Mode</code> (<a href="http://en.wikipedia.org/wiki/X86-64" rel="noreferrer">x86-64</a>: amd64, also known as Intel 64, i.e. 64-bit capable)</p> <pre><code>lm ==&gt; 64-bit processor </code></pre> <p>Or <a href="http://linux.die.net/man/1/lshw" rel="noreferrer">using <code>lshw</code></a> (as mentioned <a href="https://stackoverflow.com/a/32717681/6309">below</a> by <a href="https://stackoverflow.com/users/4637585/rolf-of-saxony">Rolf of Saxony</a>), without <code>sudo</code> (just for grepping the cpu width):</p> <pre><code>lshw -class cpu|grep "^ width"|uniq|awk '{print $2}' </code></pre> <p><strong>Note: you can have a 64-bit CPU with a 32-bit kernel installed</strong>.<br> (as <a href="https://stackoverflow.com/users/637866/ysdx">ysdx</a> mentions in <a href="https://stackoverflow.com/a/32665383/6309">his/her own answer</a>, "Nowadays, a system can be <strong><a href="https://wiki.debian.org/Multiarch" rel="noreferrer">multiarch</a></strong> so it does not make sense anyway. You might want to find the default target of the compiler")</p>
774,175
Show a popup/message box from a Windows batch file
<p>Is there a way to display a message box from a batch file (similar to how <code>xmessage</code> can be used from bash-scripts in Linux)?</p>
774,197
23
2
null
2009-04-21 19:21:54.41 UTC
65
2022-06-29 10:26:57.967 UTC
2016-03-14 14:15:54.533 UTC
null
492,336
null
93,896
null
1
166
windows|batch-file|command-line|messagebox
660,680
<p>I would make a very simple VBScript file and call it using CScript to parse the command line parameters.</p> <p>Something like the following saved in <code>MessageBox.vbs</code>:</p> <pre><code>Set objArgs = WScript.Arguments messageText = objArgs(0) MsgBox messageText </code></pre> <p>Which you would call like:</p> <pre><code>cscript MessageBox.vbs "This will be shown in a popup." </code></pre> <p><a href="http://msdn.microsoft.com/en-us/library/sfw6660x%28v=vs.84%29.aspx" rel="noreferrer"><code>MsgBox</code> reference</a> if you are interested in going this route.</p>
18,803
Is UML practical?
<p>In college I've had numerous design and <a href="http://en.wikipedia.org/wiki/Unified_Modeling_Language" rel="noreferrer">UML</a> oriented courses, and I recognize that UML can be used to benefit a software project, especially <a href="http://en.wikipedia.org/wiki/Use_case" rel="noreferrer">use-case</a> mapping, but is it really practical? I've done a few co-op work terms, and it appears that UML is not used heavily in the industry. Is it worth the time during a project to create UML diagrams? Also, I find that class diagrams are generally not useful, because it's just faster to look at the header file for a class. Specifically which diagrams are the most useful?</p> <p><strong>Edit:</strong> My experience is limited to small, under 10 developer projects.</p> <p><strong>Edit:</strong> Many good answers, and though not the most verbose, I belive the one selected is the most balanced.</p>
18,839
31
1
2011-06-03 08:39:55.867 UTC
2008-08-20 20:53:05.04 UTC
46
2019-09-07 04:08:57.767 UTC
2008-08-23 17:55:57.093 UTC
Chris Fournier
2,134
Chris Fournier
2,134
null
1
125
uml|class-design|diagram
33,380
<p>In a sufficiently <strong>complex system</strong> there are some places where some <code>UML</code> is considered useful. </p> <p>The useful diagrams for a system, vary by applicability.<br> But the most widely used ones are: </p> <ul> <li>Class Diagrams</li> <li>State Diagrams</li> <li>Activity Diagrams</li> <li>Sequence Diagrams</li> </ul> <p>There are many enterprises who swear by them and many who outright reject them as an utter waste of time and effort. </p> <p>It's best not to go overboard and think what's best for the project you are on and pick the stuff that is applicable and makes sense.</p>
154,897
What do you do if you cannot resolve a bug?
<p>Did you ever had a bug in your code, you could not resolve? I hope I'm not the only one out there, who made this experience ...</p> <p>There exist some classes of bugs, that are very hard to track down:</p> <ul> <li><strong>timing-related bugs</strong> (that occur during inter-process-communication for example)</li> <li><strong>memory-related bugs</strong> (most of you know appropriate examples, I guess !!!)</li> <li><strong>event-related bugs</strong> (hard to debug, because every break point you run into makes your IDE the target for mouse release/focus events ...)</li> <li><strong>OS-dependent bugs</strong></li> <li><strong>hardware dependent bugs</strong> (occurs on release machine, but not on developer machine)</li> <li>...</li> </ul> <p>To be honest, from time to time I fail to fix such a bug on my own ... After debugging for hours (or sometimes even days) I feel very demoralized.</p> <p>What do you do in this situation (apart from asking others for help which is not always possible)?</p> <p>Do you</p> <ul> <li>use pencil and paper instead of a debugger</li> <li>face for another thing and return to this bug later</li> <li>...</li> </ul> <p>Please let me know!</p>
154,921
32
1
2008-09-30 21:32:21.9 UTC
2008-09-30 20:26:59.967 UTC
14
2016-08-05 04:16:02.1 UTC
2015-04-17 10:20:01.89 UTC
koschi
155,077
koschi
2,012,356
null
1
34
debugging
10,717
<p>Some things that help: </p> <p>1) Take a break, approach the bug from a different angle. </p> <p>2) Get more aggressive with tracing and logging. </p> <p>3) Have another pair of eyes look at it.</p> <p>4) A usual last resort is to figure out a way to make the bug irrelevant by changing the fundamental conditions in which it occurs</p> <p>5) Smash and break things. (Stress relief only!)</p>
6,757,868
Map.clear() vs new Map : Which one will be better?
<p>I have a Map as syntax as <code>Map&lt;String, String&gt; testMap = new HashMap&lt;String, String&gt;();</code>. In this map there can be 1000 data. </p> <p>When my application requires to new list of data, then I must clear the Map. But when I saw the code of Map.clear() as </p> <pre><code>/** * Removes all of the mappings from this map. * The map will be empty after this call returns. */ public void clear() { modCount++; Entry[] tab = table; for (int i = 0; i &lt; tab.length; i++) tab[i] = null; size = 0; } </code></pre> <p>I realize that clear method goes in loop for n times (Where n is number of data in Map). So I thought there can be a way to redefine that Map as <code>testMap = new HashMap&lt;String, String&gt;();</code> and previously used Map will be Garbage collected. </p> <p>But I am not sure this will be a good way. I am working on mobile application. </p> <p>Can you please guide me?</p>
6,758,263
7
1
null
2011-07-20 06:31:43.42 UTC
19
2021-10-13 03:46:39.283 UTC
2011-07-20 09:03:31.34 UTC
null
156,477
null
550,966
null
1
109
java|android|performance|collections
91,062
<p>Complicated question. Let's see what happens.</p> <p>You instantiate a new instance, which is backed with new array. So, garbage collector should clear all the key and values from the previous map, and clear the reference to itself. So O(n) algorithm is executed anyway, but in the garbage collector thread. For 1000 records you won't see any difference. BUT. The performance <a href="http://developer.android.com/guide/practices/design/performance.html" rel="noreferrer">guide</a> tells you that <strong>it is always better not to create new objects</strong>, if you can. So I would go with <code>clear()</code> method.</p> <p>Anyway, try both variants and try to measure. Always measure!</p>
6,568,486
When do we need a private constructor in C++?
<p>I have a question about private constructors in C++. If the constructor is private, how can I create an instance of the class?</p> <p>Should we have a getInstance() method inside the class?</p>
6,568,502
8
0
null
2011-07-04 07:25:35.783 UTC
35
2021-06-28 02:42:36.32 UTC
2021-01-17 09:25:17.557 UTC
null
63,550
user707549
null
null
1
60
c++|constructor|private
56,912
<p>There are a few scenarios for having <code>private</code> constructors:</p> <ol> <li><p>Restricting object creation for all but <code>friend</code>s; in this case all constructors have to be <code>private</code></p> <pre><code>class A { private: A () {} public: // other accessible methods friend class B; }; class B { public: A* Create_A () { return new A; } // creation rights only with `B` }; </code></pre></li> <li><p>Restricting certain type of constructor (i.e. copy constructor, default constructor). e.g. <code>std::fstream</code> doesn't allow copying by such inaccessible constructor</p> <pre><code>class A { public: A(); A(int); private: A(const A&amp;); // C++03: Even `friend`s can't use this A(const A&amp;) = delete; // C++11: making `private` doesn't matter }; </code></pre></li> <li><p>To have a common delegate constructor, which is not supposed to be exposed to the outer world:</p> <pre><code>class A { private: int x_; A (const int x) : x_(x) {} // common delegate; but within limits of `A` public: A (const B&amp; b) : A(b.x_) {} A (const C&amp; c) : A(c.foo()) {} }; </code></pre></li> <li><p>For <a href="https://stackoverflow.com/q/86582/514235">singleton patterns</a> when the singleton <code>class</code> is not inheritible (if it's inheritible then use a <code>protected</code> constructor)</p> <pre><code>class Singleton { public: static Singleton&amp; getInstance() { Singleton object; // lazy initialization or use `new` &amp; null-check return object; } private: Singleton() {} // make `protected` for further inheritance Singleton(const Singleton&amp;); // inaccessible Singleton&amp; operator=(const Singleton&amp;); // inaccessible }; </code></pre></li> </ol>
6,564,794
Android and &nbsp; in TextView
<p>is it possible to add <code>&amp;nbsp;</code> in TextView? Has anyone achieved similar functionality?</p> <p>I want to have non-breakable space in TextView.</p>
6,565,049
8
0
null
2011-07-03 18:38:09.013 UTC
18
2021-01-11 12:07:26.99 UTC
2011-07-04 07:50:31.257 UTC
null
475,837
null
475,837
null
1
127
android|textview
51,591
<p><code>TextView</code> respects the <a href="http://www.fileformat.info/info/unicode/char/A0/index.htm" rel="noreferrer">Unicode no-break space character</a> (<code>\u00A0</code>), which would be a simpler/lighter solution than HTML.</p>
6,865,943
HTML Form: Select-Option vs Datalist-Option
<p>I was wondering what the differences are between Select-Option and Datalist-Option. Is there any situation in which it would be better to use one or the other? An example of each follows:</p> <p><strong>Select-Option</strong></p> <pre><code>&lt;select name=&quot;browser&quot;&gt; &lt;option value=&quot;firefox&quot;&gt;Firefox&lt;/option&gt; &lt;option value=&quot;ie&quot;&gt;IE&lt;/option&gt; &lt;option value=&quot;chrome&quot;&gt;Chrome&lt;/option&gt; &lt;option value=&quot;opera&quot;&gt;Opera&lt;/option&gt; &lt;option value=&quot;safari&quot;&gt;Safari&lt;/option&gt; &lt;/select&gt; </code></pre> <p><strong>Datalist-Option</strong></p> <pre><code>&lt;input type=&quot;text&quot; list=&quot;browsers&quot;&gt; &lt;datalist id=&quot;browsers&quot;&gt; &lt;option value=&quot;Firefox&quot;&gt; &lt;option value=&quot;IE&quot;&gt; &lt;option value=&quot;Chrome&quot;&gt; &lt;option value=&quot;Opera&quot;&gt; &lt;option value=&quot;Safari&quot;&gt; &lt;/datalist&gt; </code></pre>
7,002,118
8
5
null
2011-07-28 21:28:26.847 UTC
37
2022-02-15 16:53:22.24 UTC
2021-06-23 16:35:09.95 UTC
null
584,674
null
784,123
null
1
179
html|html-select|forms|html-datalist
156,663
<p>Think of it as the difference between a requirement and a suggestion. For the <code>select</code> element, the user is required to select one of the options you've given. For the <code>datalist</code> element, it is suggested that the user select one of the options you've given, but he can actually enter anything he wants in the input. </p> <p>Edit 1: So which one you use depends upon your requirements. If the user <em>must</em> enter one of your choices, use the <code>select</code> element. If the use can enter whatever, use the <code>datalist</code> element.</p> <p>Edit 2: Found this tidbit in the <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/the-button-element.html#the-datalist-element">HTML Living Standard</a>: "Each option element that is a descendant of the datalist element...represents a suggestion."</p>
6,896,029
Re-sign IPA (iPhone)
<p>I currently build all my applications with hudson using xcodebuild followed by a xcrun without any problems</p> <p>I've received a couple of IPA files from different people that I would like to re-sign with a enterprise account instead of the corporate account (for the app store, or sometimes ad-hoc distributed).</p> <p>My problem is that when I try to resign the app, it won't install on my device (and it should since it's a Enterprise build). The error message is on the device (not in iTunes) and it tells me simply that it couldn't install the app. No more information is given.</p> <p>I've found some information, ( <a href="http://www.ketzler.de/2011/01/resign-an-iphone-app-insert-new-bundle-id-and-send-to-xcode-organizer-for-upload/" rel="noreferrer">http://www.ketzler.de/2011/01/resign-an-iphone-app-insert-new-bundle-id-and-send-to-xcode-organizer-for-upload/</a> )</p> <p>And this might be possible. The problem I'm facing is that it doesn't seem to embed the mobile provisioning profile as I do with my normal builds (using xcrun) is this possible to control with the codesign tool, or is it possible to re-sign with xcrun?</p> <p>With my resign script i currently do</p> <ul> <li>unzip app.ipa</li> <li>appname=$(ls Payload)</li> <li>xcrun -sdk iphoneos PackageApplication -s "$provisioning_profile" "$project_dir/Payload/$appname" -o "$project_dir/app-resigned.ipa" --sign "$provisioning_profile" --embed "$mobileprovision"</li> </ul> <p>I've looked in the resulting ipa file and it seems to be very similar to the original app. What files should really change here? I initially thought the the _CodeSignature/CodeResources would change, but the content looks pretty much exactly the same.</p> <p>Pointers are much appreciated.</p>
6,921,689
12
0
null
2011-08-01 08:44:42.5 UTC
201
2021-06-08 13:39:43.593 UTC
null
null
null
null
487,353
null
1
147
iphone|build|codesign|ipa
129,991
<p>Finally got this working!</p> <p>Tested with a IPA signed with cert1 for app store submission with no devices added in the provisioning profile. Results in a new IPA signed with a enterprise account and a mobile provisioning profile for in house deployment (the mobile provisioning profile gets embedded to the IPA).</p> <p>Solution:</p> <p>Unzip the IPA</p> <pre><code>unzip Application.ipa </code></pre> <p>Remove old CodeSignature</p> <pre><code>rm -r "Payload/Application.app/_CodeSignature" "Payload/Application.app/CodeResources" 2&gt; /dev/null | true </code></pre> <p>Replace embedded mobile provisioning profile</p> <pre><code>cp "MyEnterprise.mobileprovision" "Payload/Application.app/embedded.mobileprovision" </code></pre> <p>Re-sign</p> <pre><code>/usr/bin/codesign -f -s "iPhone Distribution: Certificate Name" --resource-rules "Payload/Application.app/ResourceRules.plist" "Payload/Application.app" </code></pre> <p>Re-package</p> <pre><code>zip -qr "Application.resigned.ipa" Payload </code></pre> <p>Edit: Removed the Entitlement part (see alleys comment, thanks)</p>
63,917,431
Expected Android API level 21+ but was 30
<p>How is it possible that I get this message? It does not make any sense. I'm using <code>com.squareup.retrofit2:retrofit:2.9.0</code></p> <pre><code> Caused by: java.lang.IllegalStateException: Expected Android API level 21+ but was 30 at okhttp3.internal.platform.AndroidPlatform$Companion.buildIfSupported(AndroidPlatform.kt:370) at okhttp3.internal.platform.Platform$Companion.findPlatform(Platform.kt:204) at okhttp3.internal.platform.Platform$Companion.access$findPlatform(Platform.kt:178) 2020-09-16 12:37:07.645 6480-6480/lv.ltt.gasogmp.dev_v3 E/AndroidRuntime: at okhttp3.internal.platform.Platform.&lt;clinit&gt;(Platform.kt:179) </code></pre>
64,235,713
4
9
null
2020-09-16 09:48:51.547 UTC
2
2022-09-13 12:26:04.903 UTC
2020-11-29 14:46:41.233 UTC
null
11,105,280
null
3,089,034
null
1
62
android|okhttp
22,144
<p>Add an explicit dependency on OkHttp 4.9.0. Or whatever is newest at the time you read this.</p> <p>This bug is embarrassing but it's been fixed for so long that you shouldn’t be encountering it in new code.</p>
51,094,146
Angular - assign custom validator to a FormGroup
<p>I need to assign a custom validator to a FormGroup. I can do this at the time the FormGroup is created like this:</p> <pre><code>let myForm : FormGroup; myForm = this.formBuilder.group({ myControl1: defaultValue, myControl2: defaultValue }, { validator: this.comparisonValidator }) comparisonValidator(g: FormGroup) { if (g.get('myControl1').value &gt; g.get('myControl2'.value)) { g.controls['myControl1'].setErrors({ 'value2GreaterThanValue1': true }); return; } } </code></pre> <p>I have a situation though where I need to add the custom validator <em>after</em> I've instantiated the FormGroup, so I'm trying to do this after instantiating <code>myForm</code>, instead of adding the validator when the form is instantiated:</p> <pre><code>let myForm : FormGroup; myForm = this.formBuilder.group({ myControl1: defaultValue, myControl2: defaultValue }) this.myForm.validator = this.comparisonValidator; </code></pre> <p>This gives me a compiler error:</p> <pre><code>Type '(g: FormGroup) =&gt; void' is not assignable to type 'ValidatorFn'. Type 'void' is not assignable to type 'ValidationErrors'. </code></pre> <p>How do I assign a validator to my <code>FormGroup</code> so that the <code>formGroup</code> is passed as the argument to my <code>comparisonValidator</code> function?</p> <p><strong>Update</strong> - I've added a line showing where I'm doing a <code>setErrors</code> in my <code>comparisonValidator</code>, to make it clearer exactly how I'm trying to set a validation error.</p>
51,094,336
4
2
null
2018-06-29 04:10:46.67 UTC
4
2022-04-04 19:49:18.373 UTC
2018-06-29 04:55:42.223 UTC
null
1,549,918
null
1,549,918
null
1
29
javascript|angular|typescript|angular-reactive-forms|angular-validation
75,735
<p>I've created a <a href="https://stackblitz.com/edit/angular-form-custom-validation" rel="noreferrer">stackblitz</a> take a look.</p> <p>In the component.ts file</p> <pre><code>import { Component } from '@angular/core'; import {FormBuilder,FormGroup, ValidationErrors, ValidatorFn} from '@angular/forms' @Component({ selector: 'my-app', templateUrl: './app.component.html', styleUrls: [ './app.component.css' ] }) export class AppComponent { myForm: FormGroup; defaultValue = 20; constructor(private formBuilder: FormBuilder) { this.myForm = this.formBuilder.group({ myControl1: this.defaultValue, myControl2: this.defaultValue }); debugger this.myForm.setValidators(this.comparisonValidator()) } public comparisonValidator() : ValidatorFn{ return (group: FormGroup): ValidationErrors =&gt; { const control1 = group.controls['myControl1']; const control2 = group.controls['myControl2']; if (control1.value !== control2.value) { control2.setErrors({notEquivalent: true}); } else { control2.setErrors(null); } return; }; } } </code></pre> <p>In the component.html file</p> <pre><code>&lt;div&gt; &lt;form [formGroup]="myForm"&gt; &lt;input formControlName="myControl1" type="number"&gt; &lt;input formControlName="myControl2" type="number"&gt; &lt;br&gt;Errors: {{myForm.get('myControl2').errors | json}} &lt;/form&gt; &lt;/div&gt; </code></pre>
10,665,465
latex tabular width the same as the textwidth
<p>I am generating some table as follow:</p> <pre><code>\begin{tabular}[l]{|l|l|l|} \hline Input &amp; Output&amp; Action return \\ \hline \hline DNF &amp; simulation &amp; jsp\\ \hline \end{tabular} </code></pre> <p>How can can I give this table the same width as the text width? For graphic I use </p> <blockquote> <p>[width=\textwidth]</p> </blockquote> <p>But this doesn't work for table.</p>
10,667,313
1
3
null
2012-05-19 13:09:33.137 UTC
2
2012-05-19 17:15:06.377 UTC
null
null
null
null
1,148,626
null
1
14
latex
115,567
<p>The <code>tabularx</code> package gives you</p> <ol> <li>the total width as a first parameter, and</li> <li>a new column type <code>X</code>, all <code>X</code> columns will grow to fill up the total width.</li> </ol> <p>For your example:</p> <pre><code>\usepackage{tabularx} % ... \begin{document} % ... \begin{tabularx}{\textwidth}{|X|X|X|} \hline Input &amp; Output&amp; Action return \\ \hline \hline DNF &amp; simulation &amp; jsp\\ \hline \end{tabularx} </code></pre>
10,729,247
apache not accepting incoming connections from outside of localhost
<p>I've booted up a CentOS server on rackspace and executed <code>yum install httpd</code>'d. Then <code>services httpd start</code>. So, just the barebones.</p> <p>I can access its IP address remotely over ssh (22) no problem, so there's no problem with the DNS or anything (I think...), but when I try to connect on port 80 (via a browser or something) I get connection refused. </p> <p>From localhost, however, I can use telnet (80), or even lynx on itself and get served with no problem. From outside (my house, my school, a local coffee shop, etc...), telnet connects on 22, but not 80. </p> <p>I use <code>netstat -tulpn</code> (&lt;- I'm not going to lie, I don't understand the <code>-tulpn</code> part, but that's what the internet told me to do...) and see </p> <pre><code>tcp 0 0 :::80 :::* LISTEN - </code></pre> <p>as I believe I should. The <code>httpd.conf</code> says <code>Listen 80</code>. </p> <p>I have <code>services httpd restart</code>'d many a time.</p> <p>Honestly I have no idea what to do. There is NO way that rackspace has a firewall on incoming port 80 requests. I feel like I'm missing something stupid, but I've booted up a barebones server twice now and have done the absolute minimum to get this functioning thinking I had mucked things up with my tinkering, but neither worked. </p> <p>Any help is greatly appreciated! (And sorry for the long winded post...)</p> <p><strong>Edit</strong> I was asked to post the output of <code>iptables -L</code>. So here it is:</p> <pre><code>Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED ACCEPT icmp -- anywhere anywhere ACCEPT all -- anywhere anywhere ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh REJECT all -- anywhere anywhere reject-with icmp-host-prohibited Chain FORWARD (policy ACCEPT) target prot opt source destination REJECT all -- anywhere anywhere reject-with icmp-host-prohibited Chain OUTPUT (policy ACCEPT) target prot opt source destination </code></pre>
19,569,280
11
3
null
2012-05-23 23:25:28.707 UTC
39
2020-06-26 14:26:24.467 UTC
2015-12-19 17:18:58.14 UTC
null
27,385
null
1,413,779
null
1
60
linux|apache|webserver|centos
163,742
<p>In case not solved yet. Your iptables say:</p> <blockquote> <p>state RELATED,ESTABLISHED</p> </blockquote> <p>Which means that it lets pass only connections already established... that's established by you, not by remote machines. Then you can see exceptions to this in the next rules:</p> <pre><code>state NEW tcp dpt:ssh </code></pre> <p>Which counts only for ssh, so you should add a similar rule/line for http, which you can do like this:</p> <pre><code>state NEW tcp dpt:80 </code></pre> <p>Which you can do like this:</p> <pre><code>sudo iptables -I INPUT 4 -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT </code></pre> <p>(In this case I am choosing to add the new rule in the fourth line)</p> <p>Remember that after editing the file you should save it like this:</p> <pre><code>sudo /etc/init.d/iptables save </code></pre>
10,850,328
Inserting multiple select statements into a table as values
<p>Is it possible to do something like this in SQL Server:</p> <pre><code>INSERT INTO MyTable (Col1,Col2,Col3,Col4,Col5,Col6,Col7) VALUES SELECT Col1 FROM Func1(), SELECT Col2 FROM Func2(), SELECT Col3,Col4,Col5 FROM Func3(), SELECT Col6 FROM Func4(), SELECT Col7 FROM Func5() </code></pre> <p>I have a large number of functions which return one-value results and one function which returns 3 columns. I would like to insert all of this data into one row of a table?</p> <p>I can see the function returning muliple columns as possibly being a problem?</p>
10,850,458
3
4
null
2012-06-01 12:32:17.787 UTC
2
2015-07-14 15:58:51.857 UTC
2012-06-01 12:35:41.887 UTC
null
1,107,474
null
1,107,474
null
1
6
sql|sql-server
40,089
<p>If all functions return just one row...</p> <pre><code>INSERT INTO MyTable (Col1,Col2,Col3,Col4,Col5,Col6,Col7) SELECT f1.col1, f2.col2, f3.col3, f3.col4, f3.col5, f4.col6, f5.col7 FROM (SELECT Col1 FROM Func1()) AS f1 CROSS JOIN (SELECT Col2 FROM Func2()) AS f2 CROSS JOIN (SELECT Col3,Col4,Col5 FROM Func3()) AS f3 CROSS JOIN (SELECT Col6 FROM Func4()) AS f4 CROSS JOIN (SELECT Col7 FROM Func5()) AS f5 </code></pre> <p>If the functions return more than one row, you need to join them in the normal way; with predicates that determine which left row gets joined to which right row.</p>
10,288,445
How to get hex integer from a string in JS?
<p>I would like to convert this: <code>"#FFFFFF"</code> to this: <code>0xFFFFFF</code>. How is it possible without using eval?</p> <p>Thanks in advance,</p>
10,288,464
2
4
null
2012-04-23 21:15:48.403 UTC
3
2022-01-06 13:44:49.23 UTC
2012-04-23 21:30:25.503 UTC
null
1,091,828
null
1,091,828
null
1
29
javascript|hex
29,210
<p>Strip off the "#" and use <code>parseInt()</code>.</p> <pre><code>var hex = parseInt(str.replace(/^#/, ''), 16); </code></pre> <p>Then, if you want to <em>see</em> it in hex, you can use <code>.toString()</code>:</p> <pre><code>console.log(hex.toString(16)); </code></pre>
10,281,962
Is there a minlength validation attribute in HTML5?
<p>It seems the <code>minlength</code> attribute for an <code>&lt;input&gt;</code> field doesn't work. </p> <p>Is there any other attribute in HTML5 with the help of which I can set the minimal length of a value for fields?</p>
10,294,291
20
4
null
2012-04-23 13:56:22.683 UTC
195
2022-04-09 04:32:34.77 UTC
2016-03-05 10:44:22.77 UTC
null
63,550
null
613,318
null
1
647
html|html5-validation
685,662
<p>You can use the <a href="http://www.w3.org/TR/2009/WD-html5-20090825/forms.html#attr-input-pattern" rel="noreferrer"><code>pattern</code> attribute</a>. The <a href="http://www.w3.org/TR/2009/WD-html5-20090825/forms.html#attr-input-required" rel="noreferrer"><code>required</code> attribute</a> is also needed, otherwise an input field with an empty value will be excluded from <a href="http://www.w3.org/TR/2011/WD-html5-20110525/association-of-controls-and-forms.html#constraint-validation" rel="noreferrer">constraint validation</a>.</p> <pre><code>&lt;input pattern=".{3,}" required title="3 characters minimum"&gt; &lt;input pattern=".{5,10}" required title="5 to 10 characters"&gt; </code></pre> <p>If you want to create the option to use the pattern for "empty, or minimum length", you could do the following:</p> <pre><code>&lt;input pattern=".{0}|.{5,10}" required title="Either 0 OR (5 to 10 chars)"&gt; &lt;input pattern=".{0}|.{8,}" required title="Either 0 OR (8 chars minimum)"&gt; </code></pre>
10,771,441
Java equivalent of C# system.beep?
<p>I am working on a Java program, and I really need to be able to play a sound by a certain frequency and duration, similarly to the c# method System.Beep, I know how to use it in C#, but I can't find a way to do this in Java. Is there some equivalent, or another way to do this?</p> <pre><code>using System; class Program { static void Main() { // The official music of Dot Net Perls. for (int i = 37; i &lt;= 32767; i += 200) { Console.Beep(i, 100); } } } </code></pre>
10,771,468
8
6
null
2012-05-27 03:24:53.653 UTC
3
2019-11-21 08:02:14.72 UTC
2013-10-17 22:59:36.24 UTC
null
814,702
null
1,219,964
null
1
33
c#|java|audio|frequency|beep
42,112
<p>I don't think there's a way to play tunes<sup>1</sup> with "beep" in portable<sup>2</sup> Java. You'll need to use the <code>javax.sound.*</code> APIs I think ... unless you can find a third-party library that simplifies things for you.</p> <p>If you want to go down this path, then <a href="http://onjava.com/onjava/excerpt/jenut3_ch17/index1.html" rel="nofollow noreferrer">this page</a> might give you some ideas.</p> <hr> <p><sup>1 - Unless your users are all tone-deaf. Of course you can do things like beeping in Morse code ... but that's not a tune.</sup></p> <p><sup>2 - Obviously, you could make native calls to a Windows beep function. But that would not be portable.</sup></p>
10,572,735
JavaScript getElement by href?
<p>I've got the script below</p> <pre><code>var els = document.getElementsByTagName(&quot;a&quot;); for(var i = 0, l = els.length; i &lt; l; i++) { var el = els[i]; el.innerHTML = el.innerHTML.replace(/link1/gi, 'dead link'); } </code></pre> <p>However this searches through the page and takes about 20 seconds to do it as there are LOTS of links.</p> <p>However I only need to target the <code>a</code>'s that have a specific <code>href</code>, for eg. <code>http://domain.example/</code></p> <p>So ideally I'd like to be able to do this in a similar fashion to jQuery, but without using a framework. So something like</p> <pre><code>var els = document.getElementsByTagName(&quot;a[href='http://domain.example']&quot;); </code></pre> <p>How would I go about doing this so it only searches the objects with that matching <code>href</code>?</p>
37,820,644
2
6
null
2012-05-13 14:59:59.55 UTC
15
2022-06-22 01:20:42.407 UTC
2022-06-22 01:20:42.407 UTC
null
1,145,388
null
470,159
null
1
59
javascript|href|getelementsbytagname
128,026
<h1>2016 update</h1> <p>It's been over 4 years since this question was posted and things progressed quite a bit.</p> <p>You <strong>can't</strong> use:</p> <pre><code>var els = document.getElementsByTagName(&quot;a[href='http://domain.example']&quot;); </code></pre> <p>but what you <strong>can</strong> use is:</p> <pre><code>var els = document.querySelectorAll(&quot;a[href='http://domain.example']&quot;); </code></pre> <p>(<strong>Note:</strong> see below for browser support)</p> <p>which would make the code from your question work <strong>exactly as you expect</strong>:</p> <pre><code>for (var i = 0, l = els.length; i &lt; l; i++) { var el = els[i]; el.innerHTML = el.innerHTML.replace(/link1/gi, 'dead link'); } </code></pre> <p>You can even use selectors like <code>a[href^='http://domain.example']</code> if you want all links that <strong>start</strong> with <code>'http://domain.example'</code>:</p> <pre><code>var els = document.querySelectorAll(&quot;a[href^='http://domain.example']&quot;); for (var i = 0, l = els.length; i &lt; l; i++) { var el = els[i]; el.innerHTML = el.innerHTML.replace(/link/gi, 'dead link'); } </code></pre> <p>See: <a href="https://jsbin.com/luqeyuh/edit?html,js,console,output" rel="nofollow noreferrer"><strong>DEMO</strong></a></p> <h2>Browser support</h2> <p>The browser support according to <a href="http://caniuse.com/queryselector" rel="nofollow noreferrer">Can I use</a> as of June 2016 looks pretty good:</p> <p><a href="https://i.stack.imgur.com/cIQXF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cIQXF.png" alt="caniuse.com/queryselector" /></a> (See: <a href="http://caniuse.com/queryselector" rel="nofollow noreferrer">http://caniuse.com/queryselector</a> for up to date info)</p> <p>There is no support in <strong>IE6</strong> and <strong>IE7</strong> but <a href="http://www.ie6death.com/" rel="nofollow noreferrer">IE6 is already dead</a> and IE7 soon will be with its <a href="https://www.netmarketshare.com/browser-market-share.aspx?qprid=2&amp;qpcustomd=0" rel="nofollow noreferrer">0.68% market share</a>.</p> <p><strong>IE8</strong> is over 7 years old and it <strong>partially</strong> supports querySelectorAll - by &quot;partially&quot; I mean that you can use <a href="http://caniuse.com/css-sel2" rel="nofollow noreferrer">CSS 2.1 selectors</a> like <code>[attr]</code>, <code>[attr=&quot;val&quot;]</code>, <code>[attr~=&quot;val&quot;]</code>, <code>[attr|=&quot;bar&quot;]</code> and a small subset of <a href="http://caniuse.com/#feat=css-sel3" rel="nofollow noreferrer">CSS 3 selectors</a> which <strong>luckily</strong> include: <code>[attr^=val]</code>, <code>[attr$=val]</code>, and <code>[attr*=val]</code> so <strong>it seems that IE8 is fine with my examples above.</strong></p> <p><strong>IE9</strong>, <strong>IE10</strong> and <strong>IE11</strong> all <strong>support</strong> querySelectorAll with no problems, as do <strong>Chrome</strong>, <strong>Firefox</strong>, <strong>Safari</strong>, <strong>Opera</strong> and <strong>all</strong> other major browser - <strong>both desktop and mobile</strong>.</p> <p>In other words, it seems that we can safely start to use <code>querySelectorAll</code> in production.</p> <h2>More info</h2> <p>For more info, see:</p> <ul> <li><a href="https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll" rel="nofollow noreferrer">https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll</a></li> <li><a href="https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector" rel="nofollow noreferrer">https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector</a></li> <li><a href="http://caniuse.com/queryselector" rel="nofollow noreferrer">http://caniuse.com/queryselector</a></li> </ul> <p>See also <a href="https://stackoverflow.com/questions/23269785/whats-the-difference-between-queryall-and-queryselectorall/38245620#38245620">this answer</a> for the difference between <code>querySelectorAll</code>, <code>querySelector</code>, <code>queryAll</code> and <code>query</code> and when they were <strong>removed from the DOM specification</strong>.</p>
35,701,730
utf8_(en|de)code removed from php7?
<p>I recently switched to PHP 7 on my development server, which has worked just fine - until now.</p> <p>Since I updated to <code>PHP 7.0.3-10+deb.sury.org~trusty+1</code> (earlier today), the <code>utf8_decode</code> and <code>utf8_encode</code> functions are no longer accessible. They were, however, in previous versions of PHP7. When called, a fatal error is raised.</p> <p>I read that these functions are provided by the <code>mbstring</code> extension, which I checked with <code>var_dump(extension_loaded('mbstring'));</code> is loaded.</p> <p>How can I get the above functions to work again?</p>
36,902,105
7
9
null
2016-02-29 14:11:01.097 UTC
5
2017-11-18 12:43:42.037 UTC
2017-11-18 12:43:42.037 UTC
null
3,902,840
null
3,902,840
null
1
65
php|utf-8|mbstring
74,529
<p>I had the same problem. Just install <code>php7.0-xml</code> package. Ubuntu 16.04:</p> <pre><code>sudo apt-get install php7.0-xml </code></pre> <p>Edit: <strong>Restart apache2</strong> to load the new package.</p>
22,892,120
How to generate a random string of a fixed length in Go?
<p>I want a random string of characters only (uppercase or lowercase), no numbers, in Go. What is the fastest and simplest way to do this?</p>
31,832,326
18
3
null
2014-04-06 09:22:54.36 UTC
201
2022-07-26 16:56:38.067 UTC
2018-07-13 21:38:43.357 UTC
user6169399
142,162
null
3,138,699
null
1
433
string|random|go
324,158
<p><a href="https://stackoverflow.com/a/22892986/1114274">Paul's solution</a> provides a <em>simple</em>, general solution.</p> <p>The question asks for the <em>&quot;the fastest and simplest way&quot;</em>. Let's address the <em>fastest</em> part too. We'll arrive at our final, fastest code in an iterative manner. Benchmarking each iteration can be found at the end of the answer.</p> <p>All the solutions and the benchmarking code can be found on the <a href="https://play.golang.org/p/KcuJ_2c_NDj" rel="noreferrer">Go Playground</a>. The code on the Playground is a test file, not an executable. You have to save it into a file named <code>XX_test.go</code> and run it with</p> <pre><code>go test -bench . -benchmem </code></pre> <p><strong>Foreword</strong>:</p> <blockquote> <p>The fastest solution is not a go-to solution if you just need a random string. For that, Paul's solution is perfect. This is if performance does matter. Although the first 2 steps (<strong>Bytes</strong> and <strong>Remainder</strong>) might be an acceptable compromise: they do improve performance by like 50% (see exact numbers in the <strong>II. Benchmark</strong> section), and they don't increase complexity significantly.</p> </blockquote> <p>Having said that, even if you don't need the fastest solution, reading through this answer might be adventurous and educational.</p> <h2>I. Improvements</h2> <h3>1. Genesis (Runes)</h3> <p>As a reminder, the original, general solution we're improving is this:</p> <pre><code>func init() { rand.Seed(time.Now().UnixNano()) } var letterRunes = []rune(&quot;abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ&quot;) func RandStringRunes(n int) string { b := make([]rune, n) for i := range b { b[i] = letterRunes[rand.Intn(len(letterRunes))] } return string(b) } </code></pre> <h3>2. Bytes</h3> <p>If the characters to choose from and assemble the random string contains only the uppercase and lowercase letters of the English alphabet, we can work with bytes only because the English alphabet letters map to bytes 1-to-1 in the UTF-8 encoding (which is how Go stores strings).</p> <p>So instead of:</p> <pre><code>var letters = []rune(&quot;abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ&quot;) </code></pre> <p>we can use:</p> <pre><code>var letters = []byte(&quot;abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ&quot;) </code></pre> <p>Or even better:</p> <pre><code>const letters = &quot;abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ&quot; </code></pre> <p>Now this is already a big improvement: we could achieve it to be a <code>const</code> (there are <code>string</code> constants but <a href="https://stackoverflow.com/a/29365828/1705598">there are no slice constants</a>). As an extra gain, the expression <code>len(letters)</code> will also be a <code>const</code>! (The expression <code>len(s)</code> is constant if <code>s</code> is a string constant.)</p> <p>And at what cost? Nothing at all. <code>string</code>s can be indexed which indexes its bytes, perfect, exactly what we want.</p> <p>Our next destination looks like this:</p> <pre><code>const letterBytes = &quot;abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ&quot; func RandStringBytes(n int) string { b := make([]byte, n) for i := range b { b[i] = letterBytes[rand.Intn(len(letterBytes))] } return string(b) } </code></pre> <h3>3. Remainder</h3> <p>Previous solutions get a random number to designate a random letter by calling <a href="https://golang.org/pkg/math/rand/#Intn" rel="noreferrer"><code>rand.Intn()</code></a> which delegates to <a href="https://golang.org/pkg/math/rand/#Rand.Intn" rel="noreferrer"><code>Rand.Intn()</code></a> which delegates to <a href="https://golang.org/pkg/math/rand/#Rand.Int31n" rel="noreferrer"><code>Rand.Int31n()</code></a>.</p> <p>This is much slower compared to <a href="https://golang.org/pkg/math/rand/#Int63" rel="noreferrer"><code>rand.Int63()</code></a> which produces a random number with 63 random bits.</p> <p>So we could simply call <code>rand.Int63()</code> and use the remainder after dividing by <code>len(letterBytes)</code>:</p> <pre><code>func RandStringBytesRmndr(n int) string { b := make([]byte, n) for i := range b { b[i] = letterBytes[rand.Int63() % int64(len(letterBytes))] } return string(b) } </code></pre> <p>This works and is significantly faster, the disadvantage is that the probability of all the letters will not be exactly the same (assuming <code>rand.Int63()</code> produces all 63-bit numbers with equal probability). Although the distortion is extremely small as the number of letters <code>52</code> is much-much smaller than <code>1&lt;&lt;63 - 1</code>, so in practice this is perfectly fine.</p> <p><sup>To make this understand easier: let's say you want a random number in the range of <code>0..5</code>. Using 3 random bits, this would produce the numbers <code>0..1</code> with double probability than from the range <code>2..5</code>. Using 5 random bits, numbers in range <code>0..1</code> would occur with <code>6/32</code> probability and numbers in range <code>2..5</code> with <code>5/32</code> probability which is now closer to the desired. Increasing the number of bits makes this less significant, when reaching 63 bits, it is negligible.</sup></p> <h3>4. Masking</h3> <p>Building on the previous solution, we can maintain the equal distribution of letters by using only as many of the lowest bits of the random number as many is required to represent the number of letters. So for example if we have 52 letters, it requires 6 bits to represent it: <code>52 = 110100b</code>. So we will only use the lowest 6 bits of the number returned by <code>rand.Int63()</code>. And to maintain equal distribution of letters, we only &quot;accept&quot; the number if it falls in the range <code>0..len(letterBytes)-1</code>. If the lowest bits are greater, we discard it and query a new random number.</p> <p>Note that the chance of the lowest bits to be greater than or equal to <code>len(letterBytes)</code> is less than <code>0.5</code> in general (<code>0.25</code> on average), which means that even if this would be the case, repeating this &quot;rare&quot; case decreases the chance of not finding a good number. After <code>n</code> repetition, the chance that we still don't have a good index is much less than <code>pow(0.5, n)</code>, and this is just an upper estimation. In case of 52 letters the chance that the 6 lowest bits are not good is only <code>(64-52)/64 = 0.19</code>; which means for example that chances to not have a good number after 10 repetition is <code>1e-8</code>.</p> <p>So here is the solution:</p> <pre><code>const letterBytes = &quot;abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ&quot; const ( letterIdxBits = 6 // 6 bits to represent a letter index letterIdxMask = 1&lt;&lt;letterIdxBits - 1 // All 1-bits, as many as letterIdxBits ) func RandStringBytesMask(n int) string { b := make([]byte, n) for i := 0; i &lt; n; { if idx := int(rand.Int63() &amp; letterIdxMask); idx &lt; len(letterBytes) { b[i] = letterBytes[idx] i++ } } return string(b) } </code></pre> <h3>5. Masking Improved</h3> <p>The previous solution only uses the lowest 6 bits of the 63 random bits returned by <code>rand.Int63()</code>. This is a waste as getting the random bits is the slowest part of our algorithm.</p> <p>If we have 52 letters, that means 6 bits code a letter index. So 63 random bits can designate <code>63/6 = 10</code> different letter indices. Let's use all those 10:</p> <pre><code>const letterBytes = &quot;abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ&quot; const ( letterIdxBits = 6 // 6 bits to represent a letter index letterIdxMask = 1&lt;&lt;letterIdxBits - 1 // All 1-bits, as many as letterIdxBits letterIdxMax = 63 / letterIdxBits // # of letter indices fitting in 63 bits ) func RandStringBytesMaskImpr(n int) string { b := make([]byte, n) // A rand.Int63() generates 63 random bits, enough for letterIdxMax letters! for i, cache, remain := n-1, rand.Int63(), letterIdxMax; i &gt;= 0; { if remain == 0 { cache, remain = rand.Int63(), letterIdxMax } if idx := int(cache &amp; letterIdxMask); idx &lt; len(letterBytes) { b[i] = letterBytes[idx] i-- } cache &gt;&gt;= letterIdxBits remain-- } return string(b) } </code></pre> <h3>6. Source</h3> <p>The <strong>Masking Improved</strong> is pretty good, not much we can improve on it. We could, but not worth the complexity.</p> <p>Now let's find something else to improve. <strong>The source of random numbers.</strong></p> <p>There is a <a href="https://golang.org/pkg/crypto/rand/" rel="noreferrer"><code>crypto/rand</code></a> package which provides a <a href="https://golang.org/pkg/crypto/rand/#Read" rel="noreferrer"><code>Read(b []byte)</code></a> function, so we could use that to get as many bytes with a single call as many we need. This wouldn't help in terms of performance as <code>crypto/rand</code> implements a cryptographically secure pseudorandom number generator so it's much slower.</p> <p>So let's stick to the <code>math/rand</code> package. The <code>rand.Rand</code> uses a <a href="https://golang.org/pkg/math/rand/#Source" rel="noreferrer"><code>rand.Source</code></a> as the source of random bits. <code>rand.Source</code> is an interface which specifies a <code>Int63() int64</code> method: exactly and the only thing we needed and used in our latest solution.</p> <p>So we don't really need a <code>rand.Rand</code> (either explicit or the global, shared one of the <code>rand</code> package), a <code>rand.Source</code> is perfectly enough for us:</p> <pre><code>var src = rand.NewSource(time.Now().UnixNano()) func RandStringBytesMaskImprSrc(n int) string { b := make([]byte, n) // A src.Int63() generates 63 random bits, enough for letterIdxMax characters! for i, cache, remain := n-1, src.Int63(), letterIdxMax; i &gt;= 0; { if remain == 0 { cache, remain = src.Int63(), letterIdxMax } if idx := int(cache &amp; letterIdxMask); idx &lt; len(letterBytes) { b[i] = letterBytes[idx] i-- } cache &gt;&gt;= letterIdxBits remain-- } return string(b) } </code></pre> <p>Also note that this last solution doesn't require you to initialize (seed) the global <code>Rand</code> of the <code>math/rand</code> package as that is not used (and our <code>rand.Source</code> is properly initialized / seeded).</p> <p>One more thing to note here: package doc of <code>math/rand</code> states:</p> <blockquote> <p>The default Source is safe for concurrent use by multiple goroutines.</p> </blockquote> <p>So the default source is slower than a <code>Source</code> that may be obtained by <code>rand.NewSource()</code>, because the default source has to provide safety under concurrent access / use, while <code>rand.NewSource()</code> does not offer this (and thus the <code>Source</code> returned by it is more likely to be faster).</p> <h3>7. Utilizing <code>strings.Builder</code></h3> <p>All previous solutions return a <code>string</code> whose content is first built in a slice (<code>[]rune</code> in <strong>Genesis</strong>, and <code>[]byte</code> in subsequent solutions), and then converted to <code>string</code>. This final conversion has to make a copy of the slice's content, because <code>string</code> values are immutable, and if the conversion would not make a copy, it could not be guaranteed that the string's content is not modified via its original slice. For details, see <a href="https://stackoverflow.com/questions/41460750/how-to-convert-utf8-string-to-byte/41460993#41460993">How to convert utf8 string to []byte?</a> and <a href="https://stackoverflow.com/questions/43470284/golang-bytestring-vs-bytestring/43470344#43470344">golang: []byte(string) vs []byte(*string)</a>.</p> <p><a href="https://golang.org/doc/go1.10#strings" rel="noreferrer">Go 1.10 introduced <code>strings.Builder</code>.</a> <a href="https://golang.org/pkg/strings/#Builder" rel="noreferrer"><code>strings.Builder</code></a> is a new type we can use to build contents of a <code>string</code> similar to <a href="https://golang.org/pkg/bytes/#Buffer" rel="noreferrer"><code>bytes.Buffer</code></a>. Internally it uses a <code>[]byte</code> to build the content, and when we're done, we can obtain the final <code>string</code> value using its <a href="https://golang.org/pkg/strings/#Builder.String" rel="noreferrer"><code>Builder.String()</code></a> method. But what's cool in it is that it does this without performing the copy we just talked about above. It dares to do so because the byte slice used to build the string's content is not exposed, so it is guaranteed that no one can modify it unintentionally or maliciously to alter the produced &quot;immutable&quot; string.</p> <p>So our next idea is to not build the random string in a slice, but with the help of a <code>strings.Builder</code>, so once we're done, we can obtain and return the result without having to make a copy of it. This may help in terms of speed, and it will definitely help in terms of memory usage and allocations.</p> <pre><code>func RandStringBytesMaskImprSrcSB(n int) string { sb := strings.Builder{} sb.Grow(n) // A src.Int63() generates 63 random bits, enough for letterIdxMax characters! for i, cache, remain := n-1, src.Int63(), letterIdxMax; i &gt;= 0; { if remain == 0 { cache, remain = src.Int63(), letterIdxMax } if idx := int(cache &amp; letterIdxMask); idx &lt; len(letterBytes) { sb.WriteByte(letterBytes[idx]) i-- } cache &gt;&gt;= letterIdxBits remain-- } return sb.String() } </code></pre> <p>Do note that after creating a new <code>strings.Buidler</code>, we called its <a href="https://golang.org/pkg/strings/#Builder.Grow" rel="noreferrer"><code>Builder.Grow()</code></a> method, making sure it allocates a big-enough internal slice (to avoid reallocations as we add the random letters).</p> <h3>8. &quot;Mimicing&quot; <code>strings.Builder</code> with package <code>unsafe</code></h3> <p><code>strings.Builder</code> builds the string in an internal <code>[]byte</code>, the same as we did ourselves. So basically doing it via a <code>strings.Builder</code> has some overhead, the only thing we switched to <code>strings.Builder</code> for is to avoid the final copying of the slice.</p> <p><code>strings.Builder</code> avoids the final copy by using package <a href="https://golang.org/pkg/unsafe/" rel="noreferrer"><code>unsafe</code></a>:</p> <pre><code>// String returns the accumulated string. func (b *Builder) String() string { return *(*string)(unsafe.Pointer(&amp;b.buf)) } </code></pre> <p>The thing is, we can also do this ourselves, too. So the idea here is to switch back to building the random string in a <code>[]byte</code>, but when we're done, don't convert it to <code>string</code> to return, but do an unsafe conversion: obtain a <code>string</code> which points to our byte slice as the string data.</p> <p>This is how it can be done:</p> <pre><code>func RandStringBytesMaskImprSrcUnsafe(n int) string { b := make([]byte, n) // A src.Int63() generates 63 random bits, enough for letterIdxMax characters! for i, cache, remain := n-1, src.Int63(), letterIdxMax; i &gt;= 0; { if remain == 0 { cache, remain = src.Int63(), letterIdxMax } if idx := int(cache &amp; letterIdxMask); idx &lt; len(letterBytes) { b[i] = letterBytes[idx] i-- } cache &gt;&gt;= letterIdxBits remain-- } return *(*string)(unsafe.Pointer(&amp;b)) } </code></pre> <h3>(9. Using <code>rand.Read()</code>)</h3> <p><a href="https://golang.org/doc/go1.7#math_rand" rel="noreferrer">Go 1.7 added</a> a <a href="https://golang.org/pkg/math/rand/#Read" rel="noreferrer"><code>rand.Read()</code></a> function and a <a href="https://golang.org/pkg/math/rand/#Rand.Read" rel="noreferrer"><code>Rand.Read()</code></a> method. We should be tempted to use these to read as many bytes as we need in one step, in order to achieve better performance.</p> <p>There is one small &quot;problem&quot; with this: how many bytes do we need? We could say: as many as the number of output letters. We would think this is an upper estimation, as a letter index uses less than 8 bits (1 byte). But at this point we are already doing worse (as getting the random bits is the &quot;hard part&quot;), and we're getting more than needed.</p> <p>Also note that to maintain equal distribution of all letter indices, there might be some &quot;garbage&quot; random data that we won't be able to use, so we would end up skipping some data, and thus end up short when we go through all the byte slice. We would need to further get more random bytes, &quot;recursively&quot;. And now we're even losing the &quot;single call to <code>rand</code> package&quot; advantage...</p> <p>We could &quot;somewhat&quot; optimize the usage of the random data we acquire from <code>math.Rand()</code>. We may estimate how many bytes (bits) we'll need. 1 letter requires <code>letterIdxBits</code> bits, and we need <code>n</code> letters, so we need <code>n * letterIdxBits / 8.0</code> bytes rounding up. We can calculate the probability of a random index not being usable (see above), so we could request more that will &quot;more likely&quot; be enough (if it turns out it's not, we repeat the process). We can process the byte slice as a &quot;bit stream&quot; for example, for which we have a nice 3rd party lib: <a href="https://github.com/icza/bitio" rel="noreferrer"><code>github.com/icza/bitio</code></a> (disclosure: I'm the author).</p> <p>But Benchmark code still shows we're not winning. Why is it so?</p> <p>The answer to the last question is because <code>rand.Read()</code> uses a loop and keeps calling <code>Source.Int63()</code> until it fills the passed slice. Exactly what the <code>RandStringBytesMaskImprSrc()</code> solution does, <em>without</em> the intermediate buffer, and without the added complexity. That's why <code>RandStringBytesMaskImprSrc()</code> remains on the throne. Yes, <code>RandStringBytesMaskImprSrc()</code> uses an unsynchronized <code>rand.Source</code> unlike <code>rand.Read()</code>. But the reasoning still applies; and which is proven if we use <code>Rand.Read()</code> instead of <code>rand.Read()</code> (the former is also unsynchronzed).</p> <h2>II. Benchmark</h2> <p>All right, it's time for benchmarking the different solutions.</p> <p>Moment of truth:</p> <pre><code>BenchmarkRunes-4 2000000 723 ns/op 96 B/op 2 allocs/op BenchmarkBytes-4 3000000 550 ns/op 32 B/op 2 allocs/op BenchmarkBytesRmndr-4 3000000 438 ns/op 32 B/op 2 allocs/op BenchmarkBytesMask-4 3000000 534 ns/op 32 B/op 2 allocs/op BenchmarkBytesMaskImpr-4 10000000 176 ns/op 32 B/op 2 allocs/op BenchmarkBytesMaskImprSrc-4 10000000 139 ns/op 32 B/op 2 allocs/op BenchmarkBytesMaskImprSrcSB-4 10000000 134 ns/op 16 B/op 1 allocs/op BenchmarkBytesMaskImprSrcUnsafe-4 10000000 115 ns/op 16 B/op 1 allocs/op </code></pre> <p>Just by switching from runes to bytes, we immediately have <strong>24%</strong> performance gain, and memory requirement drops to <strong>one third</strong>.</p> <p>Getting rid of <code>rand.Intn()</code> and using <code>rand.Int63()</code> instead gives another <strong>20%</strong> boost.</p> <p>Masking (and repeating in case of big indices) slows down a little (due to repetition calls): <strong>-22%</strong>...</p> <p>But when we make use of all (or most) of the 63 random bits (10 indices from one <code>rand.Int63()</code> call): that speeds up big time: <strong>3 times</strong>.</p> <p>If we settle with a (non-default, new) <code>rand.Source</code> instead of <code>rand.Rand</code>, we again gain <strong>21%.</strong></p> <p>If we utilize <code>strings.Builder</code>, we gain a tiny <strong>3.5%</strong> in <em>speed</em>, but we also achieved <strong>50%</strong> reduction in memory usage and allocations! That's nice!</p> <p>Finally if we dare to use package <code>unsafe</code> instead of <code>strings.Builder</code>, we again gain a nice <strong>14%</strong>.</p> <p>Comparing the final to the initial solution: <code>RandStringBytesMaskImprSrcUnsafe()</code> is <strong>6.3 times faster</strong> than <code>RandStringRunes()</code>, uses <strong>one sixth</strong> memory and <strong>half as few allocations</strong>. Mission accomplished.</p>
13,264,017
Getting selected element from ListView
<p>I modify a <code>ListView</code> with the results from a database search in order to use that selection to make another DB request later on.</p> <p>I want to get the field value of that <code>ListView</code>. What method can I use for that?</p> <p>I just thought I can also add an event to the <code>onclick</code> and keep it on an attribute for the controller. Is that acceptable too?</p>
13,270,833
3
3
null
2012-11-07 06:03:41.023 UTC
3
2019-04-04 20:22:30.353 UTC
2012-11-07 12:10:26.633 UTC
null
1,447,759
null
1,447,759
null
1
21
java|gridview|javafx-2
76,231
<p>Say with list view like this:</p> <pre><code>ListView&lt;String&gt; listView =new ListView&lt;String&gt;(); </code></pre> <p>Getting selected element from ListView:</p> <pre><code>listView.getSelectionModel().getSelectedItem(); </code></pre> <p>Tracking (Listening) the changes in list view selection:</p> <pre><code>listView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener&lt;String&gt;() { @Override public void changed(ObservableValue&lt;? extends String&gt; observable, String oldValue, String newValue) { System.out.println("ListView selection changed from oldValue = " + oldValue + " to newValue = " + newValue); } }); </code></pre>
13,698,790
Importing a CMake project in QtCreator
<p>I'm trying to import my Cmake project in QtCreator, which I'd want to use as code editor, but with completition for Qt classes an the possibility to do the build via Ctrl+R</p> <p>When importing the Cmake project, the QtCreator ide hangs when running CMakeWizard when I try to select RunCmake. If I cancel an empty windows pops up and the project is not generated.</p> <p>Is it possible to import an existing cmake project in QtCreator?</p> <p>Ubuntu 10.10 x86_64, QtCreator 2.6</p>
13,698,852
2
0
null
2012-12-04 08:31:31.613 UTC
9
2019-08-12 17:05:12.757 UTC
null
null
null
null
914,693
null
1
23
qt|ubuntu|build|cmake|qt-creator
33,307
<p>Normally you just do "Open Project" and then select the CMakeLists.txt as the project file. QtCreator will then ask you to run CMake once (to generate a CodeBlocks build file, which is then interpreted by QtCreator). After that you have native support for your CMake project.</p> <p>It even works with rather complicated CMake scripts. If you observe hangs etc., you should probably file a bug report with the QtCreator project.</p>
13,465,221
Is it possible to make a Twitter Bootstrap modal slide from the side or bottom instead of sliding down?
<p>Currently the modal slide down effect is done by adding the <code>fade</code> class to the modal div. Is it possible to change the effect to sliding from the side (or from the bottom) by changing the css? I couldn't find any information online on how to do this and don't know enough css to do this myself.</p> <p>html:</p> <pre><code>&lt;div id='test-modal' class='modal fade hide'&gt; &lt;div&gt;Stuff&lt;/div&gt; &lt;/div&gt; </code></pre>
25,718,426
3
1
null
2012-11-20 01:18:15.437 UTC
30
2017-07-18 06:27:30.123 UTC
null
null
null
null
1,678,772
null
1
56
css|twitter-bootstrap
83,905
<p>Bootstrap 3 now uses CSS transform translate3d instead of CSS transitions for better animations using GPU hardware acceleration. </p> <p>It uses the following CSS (sans easing)</p> <pre><code>.modal.fade .modal-dialog { -webkit-transform: translate3d(0, -25%, 0); transform: translate3d(0, -25%, 0); } </code></pre> <p>Here is CSS you can use to slide in from the LEFT side</p> <pre><code>.modal.fade:not(.in) .modal-dialog { -webkit-transform: translate3d(-25%, 0, 0); transform: translate3d(-25%, 0, 0); } </code></pre> <p>Notice the negative selector. I noticed this was necessary to keep the ".modal.in .modal-dialog" definition from interfering. <em>Note: I am not a CSS guru, so if anyone can better explain this, feel free :)</em></p> <p>How to slide in from different sides:</p> <ul> <li>top: <code>translate3d(0, -25%, 0)</code></li> <li>bottom: <code>translate3d(0, 25%, 0)</code></li> <li>left: <code>translate3d(-25%, 0, 0)</code></li> <li>right: <code>translate3d(25%, 0, 0)</code></li> </ul> <hr> <p>If you want to mix and match different slide directions, you can assign a class like 'left' to the modal...</p> <pre><code>&lt;div class="modal fade left"&gt; ... &lt;/div&gt; </code></pre> <p>...and then target that specifically with CSS:</p> <pre><code>.modal.fade:not(.in).left .modal-dialog { -webkit-transform: translate3d(-25%, 0, 0); transform: translate3d(-25%, 0, 0); } </code></pre> <h2>Fiddle: <a href="http://jsfiddle.net/daverogers/mu5mvba0/">http://jsfiddle.net/daverogers/mu5mvba0/</a></h2> <p><strong>BONUS</strong> - You could get a little zany and slide in at an angle:</p> <ul> <li>top-left: <code>translate3d(-25%, -25%, 0)</code></li> <li>top-right: <code>translate3d(25%, -25%, 0)</code></li> <li>bottom-left: <code>translate3d(-25%, 25%, 0)</code></li> <li>bottom-right: <code>translate3d(25%, 25%, 0)</code></li> </ul> <p><em>UPDATE (05/28/15): I updated the fiddle to display the alternative angles</em></p> <hr> <p>If you want to use this in a LESS template, you can use BS3's vendor-prefix mixin (as long as it's included)</p> <pre><code>.modal.fade:not(.in) .modal-dialog { .translate3d(-25%, 0, 0); } </code></pre>
13,566,862
Where to put iVars in "modern" Objective-C?
<p>The book "iOS6 by Tutorials" by Ray Wenderlich has a very nice chapter about writing more "modern" Objective-C code. In one section the books describes how to move iVars from the header of the class into the implementation file. Since all iVars should be private this seems to be the right thing to do.</p> <p>But so far I found 3 ways of doing so. Everyone is doing it differently.</p> <p>1.) Put iVars under @implementantion inside a block of curly braces (This is how it is done in the book).</p> <p>2.) Put iVars under @implementantion without block of curly braces</p> <p>3.) Put iVars inside private Interface above the @implementantion (a class extension)</p> <p>All these solutions seems to work fine and so far I haven't noticed any difference in the behavior of my application. I guess there is no "right" way of doing it but I need to write some tutorials and I want to choose only one way for my code.</p> <p>Which way should I go?</p> <p><strong>Edit: I am only talking about iVars here. Not properties. Only additional variables the object needs only for itself and that should not be exposed to the outside.</strong></p> <p>Code Samples</p> <p>1)</p> <pre><code>#import "Person.h" @implementation Person { int age; NSString *name; } - (id)init { self = [super init]; if (self) { age = 40; name = @"Holli"; } return self; } @end </code></pre> <p>2)</p> <pre><code>#import "Person.h" @implementation Person int age; NSString *name; - (id)init { self = [super init]; if (self) { age = 40; name = @"Holli"; } return self; } @end </code></pre> <p>3)</p> <pre><code>#import "Person.h" @interface Person() { int age; NSString *name; } @end @implementation Person - (id)init { self = [super init]; if (self) { age = 40; name = @"Holli"; } return self; } @end </code></pre>
13,573,236
5
4
null
2012-11-26 14:26:34.813 UTC
63
2012-11-27 19:21:46.74 UTC
2012-11-26 20:25:47.567 UTC
null
70,414
null
70,414
null
1
83
objective-c
14,311
<p>The ability to put instance variables in the <code>@implementation</code> block, or in a class extension, is a feature of the “modern Objective-C runtime”, which is used by every version of iOS, and by 64-bit Mac OS X programs.</p> <p>If you want to write 32-bit Mac OS X apps, you must put your instance variables in the <code>@interface</code> declaration. Chances are you don't need to support a 32-bit version of your app, though. OS X has supported 64-bit apps since version 10.5 (Leopard), which was released over five years ago.</p> <p>So, let's assume you are only writing apps that will use the modern runtime. Where should you put your ivars?</p> <h2>Option 0: In the <code>@interface</code> (Don't Do It)</h2> <p>First, let's go over why we <em>don't</em> want to put instance variables in an <code>@interface</code> declaration.</p> <ol> <li><p>Putting instance variables in an <code>@interface</code> exposes details of the implementation to users of the class. This may lead those users (even yourself when using your own classes!) to rely on implementation details that they should not. (This is independent of whether we declare the ivars <code>@private</code>.)</p></li> <li><p>Putting instance variables in an <code>@interface</code> makes compiling take longer, because any time we add, change, or remove an ivar declaration, we have to recompile every <code>.m</code> file that imports the interface.</p></li> </ol> <p>So we don't want to put instance variables in the <code>@interface</code>. Where should we put them?</p> <h2>Option 2: In the <code>@implementation</code> without braces (Don't Do It)</h2> <p>Next, let's discuss your option 2, “Put iVars under @implementantion without block of curly braces”. This does <strong>not</strong> declare instance variables! You are talking about this:</p> <pre><code>@implementation Person int age; NSString *name; ... </code></pre> <p>That code defines two global variables. It does not declare any instance variables.</p> <p>It's fine to define global variables in your <code>.m</code> file, even in your <code>@implementation</code>, if you need global variables - for example, because you want all of your instances to share some state, like a cache. But you can't use this option to declare ivars, because it doesn't declare ivars. (Also, global variables private to your implementation should usually be declared <code>static</code> to avoid polluting the global namespace and risking link-time errors.)</p> <p>That leaves your options 1 and 3.</p> <h2>Option 1: In the <code>@implementation</code> with braces (Do It)</h2> <p>Usually we want to use option 1: put them in your main <code>@implementation</code> block, in braces, like this:</p> <pre><code>@implementation Person { int age; NSString *name; } </code></pre> <p>We put them here because it keeps their existence private, preventing the problems I described earlier, and because there's usually no reason to put them in a class extension.</p> <p>So when do we want to use your option 3, putting them in a class extension?</p> <h2>Option 3: In a class extension (Do It Only When Necessary)</h2> <p>There's almost never a reason to put them in a class extension in the same file as the class's <code>@implementation</code>. We might as well just put them in the <code>@implementation</code> in that case.</p> <p>But occasionally we might write a class that's big enough that we want to divide up its source code into multiple files. We can do that using categories. For example, if we were implementing <code>UICollectionView</code> (a rather big class), we might decide that we want to put the code that manages the queues of reusable views (cells and supplementary views) in a separate source file. We could do that by separating out those messages into a category:</p> <pre><code>// UICollectionView.h @interface UICollectionView : UIScrollView - (id)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout; @property (nonatomic, retain) UICollectionView *collectionViewLayout; // etc. @end @interface UICollectionView (ReusableViews) - (void)registerClass:(Class)cellClass forCellWithReuseIdentifier:(NSString *)identifier; - (void)registerNib:(UINib *)nib forCellWithReuseIdentifier:(NSString *)identifier; - (void)registerClass:(Class)viewClass forSupplementaryViewOfKind:(NSString *)elementKind withReuseIdentifier:(NSString *)identifier; - (void)registerNib:(UINib *)nib forSupplementaryViewOfKind:(NSString *)kind withReuseIdentifier:(NSString *)identifier; - (id)dequeueReusableCellWithReuseIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath*)indexPath; - (id)dequeueReusableSupplementaryViewOfKind:(NSString*)elementKind withReuseIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath*)indexPath; @end </code></pre> <p>OK, now we can implement the main <code>UICollectionView</code> methods in <code>UICollectionView.m</code> and we can implement the methods that manage reusable views in <code>UICollectionView+ReusableViews.m</code>, which makes our source code a little more manageable.</p> <p>But our reusable view management code needs some instance variables. Those variables have to be exposed to the main class <code>@implementation</code> in <code>UICollectionView.m</code>, so the compiler will emit them in the <code>.o</code> file. And we also need to expose those instance variables to the code in <code>UICollectionView+ReusableViews.m</code>, so those methods can use the ivars.</p> <p>This is where we need a class extension. We can put the reusable-view-management ivars in a class extension in a private header file:</p> <pre><code>// UICollectionView_ReusableViewsSupport.h @interface UICollectionView () { NSMutableDictionary *registeredCellSources; NSMutableDictionary *spareCellsByIdentifier; NSMutableDictionary *registeredSupplementaryViewSources; NSMutableDictionary *spareSupplementaryViewsByIdentifier; } - (void)initReusableViewSupport; @end </code></pre> <p>We won't ship this header file to users of our library. We'll just import it in <code>UICollectionView.m</code> and in <code>UICollectionView+ReusableViews.m</code>, so that everything that <em>needs</em> to see these ivars can see them. We've also thrown in a method that we want the main <code>init</code> method to call to initialize the reusable-view-management code. We'll call that method from <code>-[UICollectionView initWithFrame:collectionViewLayout:]</code> in <code>UICollectionView.m</code>, and we'll implement it in <code>UICollectionView+ReusableViews.m</code>.</p>
24,167,909
iOS 8 Custom Keyboard: Changing the Height
<p>I have tried to create a custom keyboard in iOS 8 that replaces the stock one. I really searched and could not find out if it is possible to create a keyboard with more height than the stock iOS keyboard. I replaced UIInputView but could never manage to change the height available to me.</p>
25,819,565
17
2
null
2014-06-11 16:22:09.017 UTC
42
2019-04-28 06:46:16.733 UTC
2014-06-19 15:14:56 UTC
null
2,446,155
null
3,730,881
null
1
37
keyboard|ios8|ios-app-extension
34,236
<p>This is my code on Xcode 6.0 GM. Both orientations are supported.</p> <p><strong>Update:</strong> Thanks to @SoftDesigner, we can eliminate the <code>constraint conflict</code> warning now.</p> <p><strong>Warning</strong>: XIB and storyboard are not tested. It's been reported by some folks that this does NOT work with XIB.</p> <p>KeyboardViewController.h</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface KeyboardViewController : UIInputViewController @property (nonatomic) CGFloat portraitHeight; @property (nonatomic) CGFloat landscapeHeight; @property (nonatomic) BOOL isLandscape; @property (nonatomic) NSLayoutConstraint *heightConstraint; @property (nonatomic) UIButton *nextKeyboardButton; @end </code></pre> <p>KeyboardViewController.m</p> <pre><code>#import "KeyboardViewController.h" @interface KeyboardViewController () @end @implementation KeyboardViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Perform custom initialization work here self.portraitHeight = 256; self.landscapeHeight = 203; } return self; } - (void)updateViewConstraints { [super updateViewConstraints]; // Add custom view sizing constraints here if (self.view.frame.size.width == 0 || self.view.frame.size.height == 0) return; [self.inputView removeConstraint:self.heightConstraint]; CGSize screenSize = [[UIScreen mainScreen] bounds].size; CGFloat screenH = screenSize.height; CGFloat screenW = screenSize.width; BOOL isLandscape = !(self.view.frame.size.width == (screenW*(screenW&lt;screenH))+(screenH*(screenW&gt;screenH))); NSLog(isLandscape ? @"Screen: Landscape" : @"Screen: Potriaint"); self.isLandscape = isLandscape; if (isLandscape) { self.heightConstraint.constant = self.landscapeHeight; [self.inputView addConstraint:self.heightConstraint]; } else { self.heightConstraint.constant = self.portraitHeight; [self.inputView addConstraint:self.heightConstraint]; } } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; } - (void)viewDidLoad { [super viewDidLoad]; // Perform custom UI setup here self.nextKeyboardButton = [UIButton buttonWithType:UIButtonTypeSystem]; [self.nextKeyboardButton setTitle:NSLocalizedString(@"Next Keyboard", @"Title for 'Next Keyboard' button") forState:UIControlStateNormal]; [self.nextKeyboardButton sizeToFit]; self.nextKeyboardButton.translatesAutoresizingMaskIntoConstraints = NO; [self.nextKeyboardButton addTarget:self action:@selector(advanceToNextInputMode) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:self.nextKeyboardButton]; NSLayoutConstraint *nextKeyboardButtonLeftSideConstraint = [NSLayoutConstraint constraintWithItem:self.nextKeyboardButton attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0.0]; NSLayoutConstraint *nextKeyboardButtonBottomConstraint = [NSLayoutConstraint constraintWithItem:self.nextKeyboardButton attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0]; [self.view addConstraints:@[nextKeyboardButtonLeftSideConstraint, nextKeyboardButtonBottomConstraint]]; self.heightConstraint = [NSLayoutConstraint constraintWithItem:self.inputView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0.0 constant:self.portraitHeight]; self.heightConstraint.priority = UILayoutPriorityRequired - 1; // This will eliminate the constraint conflict warning. } - (void)textWillChange:(id&lt;UITextInput&gt;)textInput { // The app is about to change the document's contents. Perform any preparation here. } - (void)textDidChange:(id&lt;UITextInput&gt;)textInput { } @end </code></pre> <p>Swift 1.0 version:</p> <pre><code>class KeyboardViewController: UIInputViewController { @IBOutlet var nextKeyboardButton: UIButton! let portraitHeight:CGFloat = 256.0 let landscapeHeight:CGFloat = 203.0 var heightConstraint: NSLayoutConstraint? override func updateViewConstraints() { super.updateViewConstraints() // Add custom view sizing constraints here if (self.view.frame.size.width == 0 || self.view.frame.size.height == 0) { return } inputView.removeConstraint(heightConstraint!) let screenSize = UIScreen.mainScreen().bounds.size let screenH = screenSize.height; let screenW = screenSize.width; let isLandscape = !(self.view.frame.size.width == screenW * ((screenW &lt; screenH) ? 1 : 0) + screenH * ((screenW &gt; screenH) ? 1 : 0)) NSLog(isLandscape ? "Screen: Landscape" : "Screen: Potriaint"); if (isLandscape) { heightConstraint!.constant = landscapeHeight; inputView.addConstraint(heightConstraint!) } else { heightConstraint!.constant = self.portraitHeight; inputView.addConstraint(heightConstraint!) } } override func viewDidLoad() { super.viewDidLoad() // Perform custom UI setup here self.nextKeyboardButton = UIButton.buttonWithType(.System) as UIButton self.nextKeyboardButton.setTitle(NSLocalizedString("Next Keyboard", comment: "Title for 'Next Keyboard' button"), forState: .Normal) self.nextKeyboardButton.sizeToFit() self.nextKeyboardButton.setTranslatesAutoresizingMaskIntoConstraints(false) self.nextKeyboardButton.addTarget(self, action: "advanceToNextInputMode", forControlEvents: .TouchUpInside) self.view.addSubview(self.nextKeyboardButton) var nextKeyboardButtonLeftSideConstraint = NSLayoutConstraint(item: self.nextKeyboardButton, attribute: .Left, relatedBy: .Equal, toItem: self.view, attribute: .Left, multiplier: 1.0, constant: 0.0) var nextKeyboardButtonBottomConstraint = NSLayoutConstraint(item: self.nextKeyboardButton, attribute: .Bottom, relatedBy: .Equal, toItem: self.view, attribute: .Bottom, multiplier: 1.0, constant: 0.0) self.view.addConstraints([nextKeyboardButtonLeftSideConstraint, nextKeyboardButtonBottomConstraint]) heightConstraint = NSLayoutConstraint(item: self.inputView, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1.0, constant: portraitHeight) heightConstraint!.priority = 999.0 } override func textWillChange(textInput: UITextInput) { // The app is about to change the document's contents. Perform any preparation here. } override func textDidChange(textInput: UITextInput) { // The app has just changed the document's contents, the document context has been updated. var textColor: UIColor var proxy = self.textDocumentProxy as UITextDocumentProxy if proxy.keyboardAppearance == UIKeyboardAppearance.Dark { textColor = UIColor.whiteColor() } else { textColor = UIColor.blackColor() } self.nextKeyboardButton.setTitleColor(textColor, forState: .Normal) } } </code></pre>
3,582,344
Draw a Connection Line in RaphaelJS
<p>How would I go about drawing a connection line in Raphael where the mousedown initiates the starting point of the line, the mousemove moves the end point without moving the start point and the mouseup leaves it as it is?</p>
3,582,466
2
0
null
2010-08-27 08:06:26.06 UTC
15
2013-07-29 14:05:32.81 UTC
null
null
null
null
233,427
null
1
16
javascript|svg|line|raphael
20,108
<p>Have a look at the source of <a href="http://www.warfuric.com/taitems/RaphaelJS/arrow_test.htm" rel="noreferrer">http://www.warfuric.com/taitems/RaphaelJS/arrow_test.htm</a>.</p> <p>This might get you started.</p> <p><em>EDIT</em></p> <p>I made a quick example that will give you a head start (still need some work though: validation of parameters, adding comments, etcetera).</p> <p>Note: you still have to adapt the path to raphael.js</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en"&gt; &lt;head&gt; &lt;meta http-equiv="content-type" content="text/html; charset=UTF-8"&gt; &lt;meta http-equiv="edit-Type" edit="text/html; charset=utf-8"&gt; &lt;!-- Update the path to raphael js --&gt; &lt;script type="text/javascript"src="path/to/raphael1.4.js"&gt;&lt;/script&gt; &lt;script type='text/javascript' src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"&gt;&lt;/script&gt; &lt;style type='text/css'&gt; svg { border: solid 1px #000; } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="raphaelContainer"&gt;&lt;/div&gt; &lt;script type='text/javascript'&gt; //&lt;![CDATA[ function Line(startX, startY, endX, endY, raphael) { var start = { x: startX, y: startY }; var end = { x: endX, y: endY }; var getPath = function() { return "M" + start.x + " " + start.y + " L" + end.x + " " + end.y; }; var redraw = function() { node.attr("path", getPath()); } var node = raphael.path(getPath()); return { updateStart: function(x, y) { start.x = x; start.y = y; redraw(); return this; }, updateEnd: function(x, y) { end.x = x; end.y = y; redraw(); return this; } }; }; $(document).ready(function() { var paper = Raphael("raphaelContainer",0, 0, 300, 400); $("#raphaelContainer").mousedown( function(e) { x = e.offsetX; y = e.offsetY; line = Line(x, y, x, y, paper); $("#raphaelContainer").bind('mousemove', function(e) { x = e.offsetX; y = e.offsetY; line.updateEnd(x, y); }); }); $("#raphaelContainer").mouseup( function(e) { $("#raphaelContainer").unbind('mousemove'); }); }); //]]&gt; &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>See example: <a href="http://jsfiddle.net/rRtAq/9358/" rel="noreferrer">http://jsfiddle.net/rRtAq/9358/</a></p>
3,781,218
Java long to MySql
<p>What is the equivalent of a Java long in the context of MySql variables?</p>
3,781,240
2
0
null
2010-09-23 18:00:34.59 UTC
9
2018-04-19 19:01:13.633 UTC
2018-04-18 18:54:20.597 UTC
null
8,160,553
null
305,555
null
1
65
java|mysql
70,852
<p><a href="http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html" rel="noreferrer"><code>SIGNED BIGINT</code></a> is a 8-bytes long integer just like Java's <code>long</code>.</p>
28,815,838
Embedding video player html5 iframe in facebook share like YouTube
<p>When something is shared from youtube to facebook, facebook is now showing the youtube html5 player.</p> <p>If you look up one of their urls (<a href="https://www.youtube.com/watch?v=uuS5ZyQhvsk" rel="nofollow noreferrer">https://www.youtube.com/watch?v=uuS5ZyQhvsk</a>) in the <a href="https://developers.facebook.com/tools/debug/og/object/" rel="nofollow noreferrer">open graph debugger</a> you can see that they are now providing open graph meta data for their html player as well as the flash one. <img src="https://i.stack.imgur.com/ZeKah.png" alt="Facebook youtube open graph screenshot"></p> <p>I also have a player that sits in an iframe, and am now including the same tags that youtube is, minus the flash ones as we don't have a flash player, but it isn't working and facebook is giving me this error which doesn't make sense:</p> <blockquote> <p>Share has playable media but will not play inline because it would cause a mixed content warning if embedded. Add a secure_src or make the video src secure to fix this.</p> </blockquote> <p><img src="https://i.stack.imgur.com/FaglN.png" alt="open graph error for our site"></p> <p>This is the information facebook is reading: <img src="https://i.stack.imgur.com/83k8z.png" alt="facebook open graph screenshot for our site"></p> <p>This is the url as an example that is generating that error: <a href="https://www.la1tv.co.uk/player/124/260" rel="nofollow noreferrer">https://www.la1tv.co.uk/player/124/260</a></p> <p>All I can think is that Facebook has made some kind of deal with youtube and this isn't available for everyone yet, but that isn't clear from that error.</p> <p>All of the content on our site is served over https.</p> <p>Anyone know what's going on or got this working?</p> <p>I can't find any documentation anywhere on facebook how to do this.</p> <p><em>I posted a <a href="https://stackoverflow.com/q/26789256/1048589">similar question</a> a while back when I was trying to get this working but at this time youtube was still only providing the flash player to facebook.</em></p> <p><em>It looks like someone else was having a similar issue <a href="https://stackoverflow.com/questions/27525006/facebook-video-share">here</a>.</em></p>
28,902,272
1
6
null
2015-03-02 17:25:47.423 UTC
9
2015-12-20 09:42:31.76 UTC
2017-05-23 10:31:10.31 UTC
null
-1
null
1,048,589
null
1
12
html|facebook|facebook-graph-api|youtube|facebook-opengraph
6,751
<p>According to WizKid this is currently in a trial period for YouTube and hopefully will be rolled out to everyone at a future date.</p>
16,255,423
Finding if element is visible (JavaScript )
<p>I have a javascript function that tries to determine whether a div is visible and does various processes with that variable. I am successfully able to swap an elements visibility by changing it's display between none and block; but I cannot store this value...</p> <p>I have tried getting the elements display attribute value and finding if the the element ID is visible but neither has worked. When I try .getAttribute it always returns null; I am not sure why because I know that id is defined and it has a display attribute.</p> <p>Here is the code of the two different methods I have tried:</p> <pre><code>var myvar = $("#mydivID").is(":visible"); var myvar = document.getElementById("mydivID").getAttribute("display"); </code></pre> <p>Any guidance or assistance would be greatly appreciated.</p>
16,255,475
5
10
null
2013-04-27 18:18:59.893 UTC
5
2021-04-23 06:33:34.303 UTC
null
null
null
null
1,407,020
null
1
13
javascript|jquery|dom|visible|getattribute
72,866
<p>Display is not an attribute, it's a CSS property inside the <code>style</code> attribute.</p> <p>You may be looking for</p> <pre><code>var myvar = document.getElementById("mydivID").style.display; </code></pre> <p>or</p> <pre><code>var myvar = $("#mydivID").css('display'); </code></pre>
16,078,269
Android Unique Serial Number
<p>I am developing an android application that targets Android 4.0 (API 14) and above.</p> <p>I am looking for a serial number that is unique per device and that persists for ever (dies with the device, does not change after factory resets).</p> <p>I have found lots of results on the web concerning unique identifiers for android devices, but very little on the <strong>android.os.Build.SERIAL</strong> number.</p> <p>So far, I eliminated the use of the <strong>ANDROID_ID</strong> because it might change after factory resets. I also eliminated the use of the <strong>IMEI</strong> because the android device might be non-phone. I cannot use the wifi or bluetooth <strong>MAC ADDRESS</strong> because the device might not have such hardware and/or such mac addresses might not be readable if the hardware is not enabled (based on what I found on the web).</p> <p>I believe I might go for the android device serial number.</p> <p>It is easily accessible using <strong>android.os.Build.SERIAL</strong> (since it is added in API level 9 and does not need any additional permission).</p> <p>My questions are :</p> <ul> <li><p>Taking into consideration that my application targets Android 4.0 (API 14) and above, is the <strong>android.os.Build.SERIAL</strong> number for the android devices unique for each device ?</p></li> <li><p>Currently, documentation of <strong>android.os.Build.SERIAL</strong> indicates : <strong>A hardware serial number, if available. Alphanumeric only, case-insensitive.</strong> Does this mean that the serial number might not be available ?</p></li> <li><p>What could be another alternative that meets the conditions mentioned above ?</p></li> </ul>
16,929,647
4
2
null
2013-04-18 08:41:21.277 UTC
28
2022-06-04 21:57:11.733 UTC
null
null
null
null
1,542,438
null
1
53
android|uniqueidentifier|serial-number
50,549
<blockquote> <p>Taking into consideration that my application targets Android 4.0 (API 14) and above, is the android.os.Build.SERIAL number for the android devices unique for each device ?</p> </blockquote> <p>According to this useful <a href="https://android-developers.blogspot.com/2011/03/identifying-app-installations.html" rel="noreferrer">article</a> in the Android Developers blog, <code>android.os.Build.SERIAL</code> <strong>should</strong> be unique if it is available. From the article:</p> <p><strong><em>Devices without telephony are required to report a unique device ID here; some phones may do so also.</em></strong></p> <blockquote> <p>Does this mean that the serial number might not be available ?</p> </blockquote> <p>Correct, it may not be available. Notice that they say <strong>"Devices without telephony are required..."</strong>, so only devices without "telephony" (like wifi only tablets) are required to supply a <code>SERIAL</code> number, although some phones still do (like the Nexus 4).</p> <p>Documentation is definitely lacking on this topic, but from the wording it's possible that only "devices without telephony" are required to submit a unique ID, while phones that do submit one might not be unique.</p> <blockquote> <p>What could be another alternative that meets the conditions mentioned above ?</p> </blockquote> <p>For your situation I think your best bet is to first check for a <code>deviceId</code> (IMEI, or what not) and if <code>deviceId</code> doesn't exist then you fallback to using <code>android.os.Build.SERIAL</code> (since this is probably a tablet) like so:</p> <pre><code>public static String getDeviceId(Context context) { final String deviceId = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId(); if (deviceId != null) { return deviceId; } else { return android.os.Build.SERIAL; } } </code></pre> <p>Keep in mind to use <code>deviceId</code> you need the permission <code>android.permission.READ_PHONE_STATE</code>.</p> <p><strong>So</strong> since your app's minSDK is 14, you can safely use the field <code>android.os.Build.SERIAL</code>. And if we assume that devices without telephony truly do always provide unique ids in <code>SERIAL</code> then I think this would be a safe bet on always getting a unique device id (bar any bugs of course).</p>
16,208,144
How do I merge multiple branches into master?
<pre><code> C---D =&gt;b1 / / E---F =&gt;b2 | / A--B =======&gt; master | \ \ G---H =&gt;b3 \ I---J =&gt;b4 </code></pre> <p>I want to merge <code>b1</code>,<code>b2</code>,<code>b3</code>,<code>b4</code> into <code>master</code>, is it possible merge at once?</p> <p>something like:</p> <pre><code>git checkout master git merge b1 b2 b3 b4 </code></pre>
16,238,928
2
4
null
2013-04-25 06:47:30.11 UTC
25
2013-04-27 12:35:02.74 UTC
null
null
null
null
1,583,453
null
1
60
git
49,770
<p>Git's <code>merge</code> command supports multiple <a href="https://www.kernel.org/pub/software/scm/git/docs/git-merge.html#_merge_strategies" rel="noreferrer">merging strategies</a>. There are two strategies that can merge more than two branches at a time.</p> <p>See also this <a href="https://stackoverflow.com/questions/366860/when-would-you-use-the-different-git-merge-strategies">question</a> for a less formal description of each one.</p> <h3>octopus</h3> <blockquote> <p>This resolves cases with more than two heads, but refuses to do a complex merge that needs manual resolution. It is primarily meant to be used for bundling topic branch heads together. This is the default merge strategy when pulling or merging more than one branch. </p> </blockquote> <p>The last statement implies that if you do <code>git merge branch1 branch2 ...</code>, it'll use the <strong>octopus</strong> strategy.</p> <h3>ours</h3> <blockquote> <p>This resolves any number of heads, but the resulting tree of the merge is always that of the current branch head, effectively ignoring all changes from all other branches. It is meant to be used to supersede old development history of side branches.</p> </blockquote> <p>See this <a href="https://stackoverflow.com/questions/1295171/git-merge-to-master-while-automatically-choosing-to-overwrite-master-files-with">question</a> for a use case example.</p>
16,180,502
Why can I execute code after "res.send"?
<p>I'm wondering what the mechanics behind the behaviour of the following code are:</p> <pre><code>res.send(200, { data: 'test data' }); console.log('still here...'); </code></pre> <p>My understanding is that <code>res.send</code> doesn't <em>return</em> the function, but does <em>close the connection / end the request</em>. This could explain why I can still execute code after a <code>res.send</code> command (I looked through the express source and it doesn't seem to be an asynchronous function). </p> <p>Is there something else at play that I may be missing?</p>
16,180,550
3
1
null
2013-04-23 22:54:13.773 UTC
21
2020-12-19 17:48:11.7 UTC
2017-07-24 18:38:37.38 UTC
null
91,403
null
193,856
null
1
96
node.js|express
54,827
<p>Sure <code>end</code> ends the HTTP response, but it doesn't do anything special to your code.</p> <p>You can continue doing other things even after you've ended a response.</p> <p>What you <em>can't</em> do, however, is do anything useful with <code>res</code>. Since the response is over, you can't write more data to it.</p> <pre><code>res.send(...); res.write('more stuff'); // throws an error since res is now closed </code></pre> <p>This behavior is unlike other traditional frameworks (PHP, ASP, etc) which allocate a thread to a HTTP request and terminate the thread when the response is over. If you call an equivalent function like ASP's <code>Response.End</code>, the thread terminates and your code stops running. In node, there is no thread to stop. <code>req</code> and <code>res</code> won't fire any more events, but the code in your callbacks is free to continue running (so long as it does not attempt to call methods on <code>res</code> that require a valid response to be open).</p>
53,289,524
Xcode 10.2.1 Command PhaseScriptExecution failed with a nonzero exit code
<pre><code>Showing Recent Messages:-1: mkdir -p /Users/spritzindia/Library/Developer/Xcode/DerivedData/Contigo-atftiouzrdopcmcpprphpilawwzm/Build/Products/Debug-iphonesimulator/Contigo.app/Frameworks Showing Recent Messages:-1: rsync --delete -av --filter P .*.?????? --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "/Users/pothi/Library/Developer/Xcode/DerivedData/Contigo-atftiouzrdopcmcpprphpilawwzm/Build/Products/Debug-iphonesimulator/IQKeyboardManagerSwift/IQKeyboardManagerSwift.framework" "/Users/pothi/Library/Developer/Xcode/DerivedData/Contigo-atftiouzrdopcmcpprphpilawwzm/Build/Products/Debug-iphonesimulator/Contigo.app/Frameworks" </code></pre> <p>Command <code>PhaseScriptExecution</code> failed with a <code>nonzero</code> exit code</p> <p>I deleted derived data. i have tried : </p> <blockquote> <p>keychain access -> right click on login -> lock &amp; unlock again -> clear Xcode project</p> </blockquote> <p>Restarted machine, no use</p> <p>How do I resolve "<code>Command PhaseScriptExecution failed with a nonzero exit code</code>" error when trying to archive project. </p> <p>And I am using those librarys </p> <pre><code>pod 'IQKeyboardManagerSwift' pod 'SDWebImage', '~&gt; 4.0' pod 'KRPullLoader' pod 'Paytm-Payments' </code></pre>
60,090,102
58
8
null
2018-11-13 21:09:42.987 UTC
31
2022-09-17 08:12:57.057 UTC
2019-12-31 13:44:19.563 UTC
null
5,022,689
null
9,119,533
null
1
160
ios|swift|xcode|cocoapods|xcode10.2.1
371,293
<p>After trying all the <strong>solutions</strong>, I was missing is to enable this option in: </p> <p><strong>Targets -> Build Phases -> Embedded pods frameworks</strong></p> <p>In newer versions it may be listed as: </p> <p><strong>Targets -> Build Phases -> Bundle React Native code and images</strong></p> <ul> <li>Run script only when installing</li> </ul> <p><a href="https://i.stack.imgur.com/WBFOq.png" rel="noreferrer"><img src="https://i.stack.imgur.com/WBFOq.png" alt="Build Phases"></a></p>
29,140,377
.sh File Not Found
<p>I'm trying to execute test.sh on terminal.</p> <p>My test.sh is in the /Home/monty folder and I made it executable:</p> <pre><code>chmod 755 test.sh </code></pre> <p>I try to execute it using: $./test.sh I get an error:</p> <pre><code>bash: ./test.sh: /usr/bin/bash: bad interpreter: No such file or directory </code></pre> <p>I tried to do this on terminal:</p> <pre><code>$ PATH=$PATH:/Home/monty </code></pre> <p>But to no avail. How do I solve this issue?</p>
29,141,699
3
9
null
2015-03-19 08:57:37.517 UTC
5
2020-12-19 01:51:23.907 UTC
2015-03-19 10:14:16.463 UTC
null
3,477,763
null
3,477,763
null
1
16
shell|ubuntu|sh
61,077
<p>You probably have set the wrong shabang. In ubuntu bash is normally located in <code>/bin/bash</code> so at the top of the file you should have:</p> <pre><code>#!/bin/bash </code></pre> <p>instead of:</p> <pre><code>#!/usr/bin/bash </code></pre> <hr> <p>Another way to run the script is to just tell <code>bash</code> (or <code>sh</code>) to execute it:</p> <pre><code>bash ./test.sh </code></pre>
24,714,166
Full text search with weight in mongoose
<p>As I find out, since version 3.8.9, mongoose support full text search. But I can't find a good documentation for it!<br> I want to do something like:</p> <pre><code>db.collection.ensureIndex( // Fields to index { animal: "text", color: "text", pattern: "text", size: "text" }, // Options { name: "best_match_index", // Adjust field weights (default is 1) weights: { animal: 5, // Most relevant search field size: 4 // Also relevant } } ) </code></pre> <p>Can I do it with pure mongoose? Or I have to use some plugin like <a href="https://www.npmjs.org/package/mongoose-text-search">mongoose-text-search</a>? How about without weight?<br> And how should I do it?</p>
25,509,618
4
4
null
2014-07-12 14:58:18.187 UTC
30
2019-05-16 19:10:24.45 UTC
2019-05-16 19:10:24.45 UTC
null
2,370,483
null
3,531,690
null
1
62
mongodb|mongoose|full-text-search
51,656
<p>Yes, you can use full text search in Mongoose >= 3.8.9. Firstly, a collection can have at most one text index (see <a href="http://docs.mongodb.org/manual/core/index-text/#create-text-index" rel="noreferrer">docs</a>). So, to define text index for <a href="http://docs.mongodb.org/manual/tutorial/create-text-index-on-multiple-fields/" rel="noreferrer">several fields</a>, you need compound index:</p> <pre class="lang-js prettyprint-override"><code>schema.index({ animal: 'text', color: 'text', pattern: 'text', size: 'text' }); </code></pre> <p>Now you can use <a href="http://docs.mongodb.org/manual/reference/operator/query/text/#op._S_text" rel="noreferrer"><strong>$text</strong> query operator</a> like this:</p> <pre class="lang-js prettyprint-override"><code>Model .find( { $text : { $search : "text to look for" } }, { score : { $meta: "textScore" } } ) .sort({ score : { $meta : 'textScore' } }) .exec(function(err, results) { // callback }); </code></pre> <p>This will also sort results by relevance score.</p> <p>As for <a href="http://docs.mongodb.org/manual/tutorial/control-results-of-text-search/" rel="noreferrer">weights</a>, you can try to pass weights options object to <a href="http://mongoosejs.com/docs/api.html#schema_Schema-index" rel="noreferrer"><code>index()</code></a> method (where you define compound index) (working at least with v4.0.1 of mongoose):</p> <pre class="lang-js prettyprint-override"><code>schema.index({ animal: 'text', color: 'text', pattern: 'text', size: 'text' }, {name: 'My text index', weights: {animal: 10, color: 4, pattern: 2, size: 1}}); </code></pre>
24,653,064
Document ready form submission and browser history
<p>I have the following code in my page to submit the form on the page automatically when the DOM is ready:</p> <pre><code>$(function () { $('form').submit(); }); </code></pre> <p>However, on the next page if the user clicks <kbd>back</kbd> on their browser it goes back to the page before this one rather than the page with this code on (with Chrome/IE anyway). i.e. the page with the form on is missing in the browser history.</p> <p><strong>This is great</strong>, although I wondered is this something all modern browsers now do? <strong>I am looking for an answer that cites official sources such as from internet standards documents or from browser vendors that state the mechanism they have implemented.</strong></p> <p>This appears to only happen if I call the <code>submit()</code> function in the DOM ready or Window load events.</p> <p>e.g. this code will show the form page in browser history after the page is clicked (back/forward):-</p> <pre><code>document.addEventListener('click', function () { document.forms[0].submit(); }, false); </code></pre> <p>the following snippets won't:-</p> <pre><code>document.addEventListener('DOMContentLoaded', function () { document.forms[0].submit(); }, false); window.addEventListener('load', function() { document.forms[0].submit(); }, false); window.onload = function () { document.forms[0].submit(); }; </code></pre>
25,278,548
4
5
null
2014-07-09 11:57:21.627 UTC
9
2014-08-13 07:43:27.143 UTC
2014-08-02 10:49:59.837 UTC
null
413,180
null
413,180
null
1
16
javascript|jquery|html|forms|browser-history
2,162
<p>I've dealt with this before. I did not want the <code>back button</code> to take the user back to previous page. Using <code>onbeforeunload</code> solved the issue for me... </p> <p>But your issue is related to the following concepts </p> <ul> <li><em>Browsing Context</em> </li> <li><em>Session History</em> </li> <li><em>Replacement Enabled (flag)</em> </li> </ul> <hr> <ol> <li><p>A "Browsing Context" is an environment in which "Document" objects are presented to the user. </p></li> <li><p>The sequence of "Document"s in a "Browsing Context" is its "Session History". The "Session History" lists these "Document"s as flat entries. </p></li> <li><p>"Replacement Enabled" comes into effect when we propagate from one "Document" to another in the "Session History". If the traversal was initiated with "Replacement Enabled", the entry immediately before the specified entry (in the "Session History") is removed. </p></li> </ol> <blockquote> <p><strong>Note</strong> A tab or window in a Web browser typically contains a browsing context, as does an iframe or frames in a frameset. </p> </blockquote> <hr> <p>Logically thinking, by calling any of these </p> <pre><code>document.addEventListener( 'DOMContentLoaded', function() {document.forms[0].submit();}, false ); window.addEventListener( 'load', function() {document.forms[0].submit();}, false ); window.onload = function() {document.forms[0].submit();}; </code></pre> <p>you are <em>suggesting</em> the browser to perform <code>#3</code>, because what those calls mean is that propagate away from the page as soon as it loads. Even to me that code is obviously :) asking to be cleared off from the "Session History". </p> <p>Further reading... </p> <ul> <li><a href="https://developer.mozilla.org/en-US/docs/Web/API/Window.onbeforeunload">onbeforeunload</a></li> <li><a href="http://dev.w3.org/html5/spec-LC/browsers.html">browsers</a></li> <li><a href="http://dev.w3.org/html5/spec-LC/browsers.html#browsing-context">browsing-context</a></li> <li><a href="http://dev.w3.org/html5/spec-LC/history.html#unloading-documents">unloading-documents</a></li> <li><a href="http://dev.w3.org/html5/spec-LC/history.html#replacement-enabled">replacement-enabled</a></li> </ul>
24,503,865
How to get all the values of input array element jquery
<p>Here is my html input elements</p> <pre><code>&lt;input type="text" name="pname[]" value="" /&gt; &lt;input type="text" name="pname[]" value="" /&gt; &lt;input type="text" name="pname[]" value="" /&gt; &lt;input type="text" name="pname[]" value="" /&gt; &lt;input type="text" name="pname[]" value="" /&gt; &lt;input type="text" name="pname[]" value="" /&gt; </code></pre> <p>How can I get all the values of <code>pname</code> array using Jquery</p>
24,503,913
3
7
null
2014-07-01 06:38:30.513 UTC
22
2022-01-28 12:28:27.67 UTC
2022-01-28 12:28:27.67 UTC
null
3,689,450
null
3,707,303
null
1
64
javascript|html|jquery
193,243
<p>By Using map</p> <pre><code>var values = $("input[name='pname[]']") .map(function(){return $(this).val();}).get(); </code></pre>
19,469,495
CSS - Slow Hover effect
<p>I am creating a CSS dynamic menu and would like to delay the on hover action. The reaction of the menu to when hovering over it's links is to provide a sub menu(drop down). </p> <p>I would like to slow down the drop down process so that the sub menu would not appear instantly, but would take 1 second to drop down. Help is greatly appreciated.</p> <p>Code is below:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;style&gt; #navMenu{ margin:0; padding:0; } #navMenu ul{ margin:0; padding:0; } #navMenu li{ margin-right:2px; padding:0; list-style:none; float:left; position:relative; background:#CCC; } #navMenu ul li a{ text-align:center; font-family:sans-serif, cursive; text-decoration:none; height:30px; width:150px; display:block; color:#000; border:10px; -webkit-transition: background-color 0.1s; -moz-transition: background-color 0.1s; -o-transition: background-color 0.1s; transition: background-color 0.1s; } #navMenu ul ul{ position:absolute; visibility:hidden; -webkit-transition: background-color 0.1s; -moz-transition: background-color 0.1s; -o-transition: background-color 0.1s; transition: background-color 0.1s; } #navMenu ul li:hover ul{ visibility:visible; -webkit-transition: background-color 0.1s; -moz-transition: background-color 0.1s; -o-transition: background-color 0.1s; transition: background-color 0.1s; } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="wrapper"&gt;&lt;!--beginning of wrapper div--&gt; &lt;div id="navMenu"&gt;&lt;!--Beginning of Nav Menu--&gt; &lt;ul&gt;&lt;!--Beginning of main UL--&gt; &lt;li&gt;&lt;a href="#"&gt;About Us&lt;/a&gt; &lt;ul&gt;&lt;!--Begining of Internal UL--&gt; &lt;li&gt;&lt;a href="#"&gt;Link item &lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Link item &lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Link item &lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Link item &lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Contact Us&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;&lt;!--End of Main UL --&gt;&lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Thanks in advance :)</p> <p>Regards,</p> <p>Joseph</p>
19,469,527
6
3
null
2013-10-19 18:25:37.3 UTC
4
2021-12-01 07:21:40.057 UTC
2013-10-19 18:42:08.497 UTC
null
2,802,040
null
2,612,009
null
1
16
html|css
91,341
<p>you can use css transition-delay property as follows:</p> <pre><code>transition-delay: 1s; /* delays for 1 second */ -webkit-transition-delay: 1s; /* for Safari &amp; Chrome */ </code></pre> <p>Find more info here <a href="http://www.w3schools.com/cssref/css3_pr_transition-delay.asp">http://www.w3schools.com/cssref/css3_pr_transition-delay.asp</a></p>
19,814,673
HTML5 input required, scroll to input with fixed navbar on submit
<p>When trying to submit a form with missing required fields, my browser (Chrome), displays a message mentionning there is a field missing, and if it's out of my screen, it scrolls up to it.</p> <p>My problem is that I have a 50px fixed header in my webpage, and as a result, the input field is hidden, and the message seems to come out of nowhere:</p> <p><img src="https://i.stack.imgur.com/Hobe1.png" alt="Input field hidden"></p> <p>Instead of</p> <p><img src="https://i.stack.imgur.com/nii5n.png" alt="Input field shown"></p> <p>Is there a way around this? </p> <p>I tried both applying the 50px margin to <code>&lt;html&gt;</code> and to <code>&lt;body&gt;</code></p> <p>Cheers</p> <hr> <p>EDIT</p> <p>Here's a fiddle of the problem: <a href="http://jsfiddle.net/LL5S6/1/" rel="noreferrer">http://jsfiddle.net/LL5S6/1/</a></p>
61,913,557
9
4
null
2013-11-06 14:27:43.583 UTC
9
2020-05-26 05:53:13.637 UTC
2013-11-06 16:53:14.893 UTC
null
1,620,081
null
1,620,081
null
1
59
javascript|css|html
26,628
<p>In <a href="https://caniuse.com/#search=scroll-padding" rel="noreferrer">modern browsers</a> there is a new CSS property for that use case:</p> <pre><code>html { scroll-padding-top: 50px; } </code></pre> <p>Your JSFiddle updated: <a href="http://jsfiddle.net/5o10ydbk/" rel="noreferrer">http://jsfiddle.net/5o10ydbk/</a></p> <p>Browser Support for <code>scroll-padding</code>: <a href="https://caniuse.com/#search=scroll-padding" rel="noreferrer">https://caniuse.com/#search=scroll-padding</a></p>
17,330,810
XNA for Visual Studio 2013
<p>Is XNA available to be used from within Visual Studio 2013 (Ultimate) Preview? I have not heard, nor seen anything about XNA for VS 2013.</p> <p>I have just installed VS 2013 and it's not there; I have it in VS 2012, so maybe there's a way to get it to work with 2013?</p>
17,332,570
6
4
null
2013-06-26 21:31:10.37 UTC
8
2015-07-18 08:50:24.997 UTC
2013-06-26 22:00:56.183 UTC
null
76,337
null
2,516,128
null
1
19
.net|visual-studio|xna|visual-studio-2013
50,823
<p>I'm running it successfully under Express 2013 Preview for Windows Desktop after following the same steps listed here for 2012: <a href="https://stackoverflow.com/questions/10881005/how-to-install-xna-game-studio-on-visual-studio-2012">How to install XNA game studio on Visual Studio 2012?</a>.</p> <p>The only difference is that the version number in the paths and manifest is now 12 instead of 11.</p>