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
5,403,636
Cause CMAKE to generate an error
<p>How can I get CMAKE to generate an error on a particular condition. That is, I want something like this:</p> <pre><code>if( SOME_COND ) error( "You can't do that" ) endif() </code></pre>
5,403,778
1
0
null
2011-03-23 10:14:24.373 UTC
18
2022-09-19 05:46:45.407 UTC
null
null
null
null
229,686
null
1
165
cmake
103,215
<p>The <a href="https://cmake.org/cmake/help/latest/command/message.html" rel="nofollow noreferrer"><code>message()</code></a> method has an optional argument for the mode, allowing <code>STATUS</code>, <code>WARNING</code>, <code>AUTHOR_WARNING</code>, <code>SEND_ERROR</code>, and <code>FATAL_ERROR</code>. <code>STATU...
25,201,438
Python: How to get values of an array at certain index positions?
<p>I have a numpy array like this:</p> <pre><code>a = [0,88,26,3,48,85,65,16,97,83,91] </code></pre> <p>How can I get the values at certain index positions in ONE step? For example:</p> <pre><code>ind_pos = [1,5,7] </code></pre> <p>The result should be:</p> <pre><code>[88,85,16] </code></pre>
25,201,473
5
1
null
2014-08-08 10:31:08.963 UTC
3
2020-12-18 15:08:53.607 UTC
null
null
null
null
2,952,871
null
1
28
python|arrays|numpy|indexing
181,837
<p>Just index using you <code>ind_pos</code> </p> <pre><code>ind_pos = [1,5,7] print (a[ind_pos]) [88 85 16] In [55]: a = [0,88,26,3,48,85,65,16,97,83,91] In [56]: import numpy as np In [57]: arr = np.array(a) In [58]: ind_pos = [1,5,7] In [59]: arr[ind_pos] Out[59]: array([88, 85, 16]) </code></pre>
27,614,936
Laravel rule validation for numbers
<p>I have the following rules :</p> <pre><code>'Fno' =&gt; 'digits:10' 'Lno' =&gt; 'min:2|max5' // this seems invalid </code></pre> <p>But how to have the rule that</p> <p>Fno should be a digit with minimum 2 digits to maximum 5 digits and</p> <p>Lno should be a digit only with min 2 digits</p>
27,615,084
6
1
null
2014-12-23 06:02:24.347 UTC
16
2022-08-20 11:23:10.88 UTC
2022-08-20 11:23:10.88 UTC
null
9,521,512
null
3,492,495
null
1
75
php|laravel|laravel-4
263,905
<p>If I correctly got what you want:</p> <pre><code>$rules = ['Fno' =&gt; 'digits_between:2,5', 'Lno' =&gt; 'numeric|min:2']; </code></pre> <p>or</p> <pre><code>$rules = ['Fno' =&gt; 'numeric|min:2|max:5', 'Lno' =&gt; 'numeric|min:2']; </code></pre> <p>For all the available rules: <a href="http://laravel.com/docs/4...
44,618,542
How to change the color of an AlertDialog message?
<p>I have an <code>AlertDialog</code> and it's message is displayed, but the color of the text is white. It blends in with the background. I've tried changing the theme but it doesn't work. How do I change the color of the message?</p> <p>The relevant code:</p> <pre><code>AlertDialog.Builder builder; builder = new Al...
44,618,722
4
1
null
2017-06-18 19:09:35.757 UTC
9
2021-04-27 07:02:13.977 UTC
2017-06-19 06:04:47.953 UTC
null
5,869,325
null
7,656,601
null
1
26
java|android|android-alertdialog
26,296
<p>you can give style to your alert dialog like this:</p> <pre><code>AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.AlertDialogStyle); </code></pre> <p>and the style is like always:</p> <pre><code>&lt;style name="AlertDialogStyle" parent="Theme.AppCompat.Light.Dialog"&gt; &lt;item n...
21,732,123
Convert True/False value read from file to boolean
<p>I'm reading a <code>True - False</code> value from a file and I need to convert it to boolean. Currently it always converts it to <code>True</code> even if the value is set to <code>False</code>.</p> <p>Here's a <code>MWE</code> of what I'm trying to do:</p> <pre><code>with open('file.dat', mode="r") as f: for...
21,732,183
17
1
null
2014-02-12 15:26:16.07 UTC
17
2022-08-12 10:44:03.757 UTC
2017-04-27 15:47:22.797 UTC
null
1,391,441
null
1,391,441
null
1
94
python|string|boolean
170,289
<p><code>bool('True')</code> and <code>bool('False')</code> always return <code>True</code> because strings 'True' and 'False' are not empty.</p> <p>To quote a great man (and Python <a href="http://docs.python.org/2/library/stdtypes.html#truth-value-testing" rel="noreferrer">documentation</a>):</p> <blockquote> <h3...
51,476,234
Subclass a class that extends StatelessWidget or StatefulWidget class
<p>Is it possible to create a class that extends a class extending StatelessWidget or StatefulWidget.</p> <p>For example:</p> <pre><code>class MyButton extends StatelessWidget { final String label; Button({this.label}); @override Widget build(BuildContext context) { return ButtonExample("label");} } </code></pre>...
51,477,727
5
3
null
2018-07-23 10:06:11.957 UTC
8
2021-11-15 09:39:19.07 UTC
2018-07-23 10:24:09.257 UTC
null
5,482,015
null
5,482,015
null
1
33
flutter
26,132
<p>In Flutter composition is preferred over inheritance.<br> Widgets are not supposed to be extended, this is why there are no examples or tutorials how to do it.</p> <p>Flutter has a strong focus on composition and the included widget library contains a lot of smaller widgets that do one thing well, that allow to com...
32,614,752
F12 - Go to Implementation of Interface
<p>When not running an application, pressing F12 (Go To Definition) on a method on an interface type will take you to the interface itself. </p> <p>Is there any key combo that exists (or one that I can make) that will allow me to provide a default implementation to jump to, or allow me to quickly pick an implementatio...
32,614,836
6
2
null
2015-09-16 17:12:22.21 UTC
1
2021-09-24 17:50:06.637 UTC
2015-09-16 17:19:12.66 UTC
null
2,642,204
null
1,786,428
null
1
32
visual-studio|interface|keyboard-shortcuts
18,970
<p><strong>If using VS 2015 and above:</strong> <br/><br/> <a href="https://stackoverflow.com/a/37794970/970191">See answer below</a>:</p> <blockquote> <p>Visual Studio 2015 Update 1 added Edit.GoToImplementation which appeared in the context menu, but there was no keyboard shortcut associated with it by default.</p> <...
33,432,983
Docker apps logging with Filebeat and Logstash
<p>I have a set of dockerized applications scattered across multiple servers and trying to setup production-level centralized logging with ELK. I'm ok with the ELK part itself, but I'm a little confused about how to forward the logs to my logstashes. I'm trying to use Filebeat, because of its loadbalance feature. I'd a...
33,433,254
6
2
null
2015-10-30 09:47:46.97 UTC
18
2017-09-13 22:14:56.57 UTC
null
null
null
null
311,151
null
1
22
docker|logstash|elastic-stack|logstash-forwarder
25,682
<p>Docker allows you to specify the <a href="https://docs.docker.com/reference/logging/overview/" rel="noreferrer">logDriver</a> in use. This answer does not care about Filebeat or load balancing.</p> <p>In a presentation I used syslog to forward the logs to a Logstash (ELK) instance listening on port 5000. The follo...
9,037,605
How I can clear the value of TextView?
<p>The value of the TextView is inserted by selecting the Item on List (ArrayList). When I close and open the app again the value in the TextView is still there. There is some way to clear the value of TextView?</p>
9,037,643
3
0
null
2012-01-27 17:40:26.83 UTC
1
2020-07-04 13:18:14.427 UTC
2020-07-04 13:18:14.427 UTC
null
8,422,953
null
1,112,535
null
1
9
android|textview
44,256
<pre><code>TextView myTextView = (TextView) findViewById(R.id.myTextView); myTextView.setText(""); </code></pre>
9,193,769
disabling view with in action in ZF2
<p>I am struggling with disabling view in ZF2 <code>$this-&gt;_helper-&gt;viewRenderer-&gt;setNoRender(); or (true)</code> with no luck as it always says there </p> <pre><code>PHP Fatal error: Call to a member function setNoRender() on a non-object in ../module/Location/src/Location/Controller/LocationController.php ...
9,870,758
9
0
null
2012-02-08 12:59:16.26 UTC
11
2016-03-12 04:45:12 UTC
2014-04-17 09:44:39.597 UTC
null
3,351,765
null
1,197,203
null
1
20
zend-framework2
20,265
<p>To disable the view completely, from within a controller action, you should return a Response object:</p> <pre><code>&lt;?php namespace SomeModule\Controller; use Zend\Mvc\Controller\ActionController, Zend\View\Model\ViewModel; class SomeController extends ActionController { public function someAction() ...
9,486,498
How to properly set JSESSIONID cookie path behind reverse proxy
<p>My web app is running in Tomcat at <code>http://localhost:8080/example.com/</code> but it is being reverse proxied from Apache that is serving up <code>http://example.com/</code> on port 80. My web app looks at the <code>request.getHeader("x-forwarded-host")</code> header to know that it is behind a reverse proxy. ...
9,487,204
3
0
null
2012-02-28 17:12:04.2 UTC
15
2015-01-20 20:59:50.17 UTC
2015-01-20 20:59:50.17 UTC
null
1,145,388
null
1,145,388
null
1
24
tomcat|reverse-proxy|jsessionid
48,956
<p>Tomcat6 uses the Servlet 2.3 spec. It does not support changing the cookie path either through code or Tomcat configuration.</p> <p>I got it to work from the Apache side with some <code>mod_proxy</code> directives. The <code>ProxyPassReverseCookiePath</code> directive does exactly what I want. It takes the cook...
9,013,916
Do arrays stored in MongoDB keep their order?
<p>Simple question, do arrays keep their order when stored in MongoDB?</p>
9,013,993
3
0
null
2012-01-26 04:23:05.833 UTC
3
2019-10-03 09:58:55.753 UTC
null
null
null
null
255,344
null
1
79
mongodb
18,869
<p>yep MongoDB keeps the order of the array.. just like Javascript engines..</p>
29,972,404
Xamarin Forms Swipe Left/Swipe Right Gestures
<p>I want to preface this by saying I'm completely new to mobile development, Xamarin, C#, .Net.</p> <p>I'm working on creating a mobile app using Xamarain Forms and have run into the problem of not having the swipe gesture available to me, at least according to the documentation I've seen. </p> <p>I found this site:...
53,971,252
6
4
null
2015-04-30 15:54:47.57 UTC
9
2020-01-31 19:06:36.963 UTC
2017-08-26 13:05:05.48 UTC
null
6,761,181
null
4,738,177
null
1
34
c#|xaml|xamarin|xamarin.forms
52,381
<p>Xamarin.Forms has introduced SwipeGestureRecognizer :</p> <pre><code>&lt;BoxView Color="Teal" ...&gt; &lt;BoxView.GestureRecognizers&gt; &lt;SwipeGestureRecognizer Direction="Left" Swiped="OnSwiped"/&gt; &lt;/BoxView.GestureRecognizers&gt; &lt;/BoxView&gt; </code></pre>
30,909,492
mongoError: Topology was destroyed
<p>I have a REST service built in node.js with Restify and Mongoose and a mongoDB with a collection with about 30.000 regular sized documents. I have my node service running through pmx and pm2.</p> <p>Yesterday, suddenly, node started crapping out errors with the message "MongoError: Topology was destroyed", nothing ...
31,950,062
17
2
null
2015-06-18 07:50:32.317 UTC
29
2020-11-13 03:50:53.1 UTC
2015-06-29 09:08:49.127 UTC
null
940,833
null
940,833
null
1
174
node.js|mongodb|mongoose|restify|pm2
163,679
<p>It seems to mean your node server's connection to your MongoDB instance was interrupted while it was trying to write to it.</p> <p>Take a look at the <a href="https://github.com/christkv/mongodb-core/blob/V2.2.1/lib/topologies/mongos.js#L664" rel="noreferrer">Mongo source code that generates that error</a></p> <pr...
34,305,351
What does [::] mean in my nginx config file
<p>I was looking at my nginx config file I noticed two this.</p> <pre><code>server { listen 80 default_server; listen [::]:80 default_server; index index.html; } </code></pre> <p>I understand this part <code>listen 80 default_server;</code> it tells nginx to listen on port 80 and set that as the "default...
34,305,428
1
1
null
2015-12-16 06:33:25.403 UTC
8
2018-10-22 14:27:47.783 UTC
null
null
null
null
1,914,652
null
1
59
nginx
19,798
<p>It is for the IPv6 configs</p> <p>from the nginx <a href="http://nginx.org/en/docs/http/ngx_http_core_module.html#listen" rel="noreferrer">docs</a> </p> <pre><code>IPv6 addresses (0.7.36) are specified in square brackets: listen [::]:8000; listen [::1]; </code></pre>
34,294,054
How to implement single-line ellipsis with CSS
<p>I want to be able to add three dots and maintain a text in a single line in a responsive design.</p> <p>So for example:</p> <p>I have a link with a link inside a container element (e.g. <code>&lt;span&gt;</code>). If the text is long, it will shown in two lines one a small screen:</p> <pre><code>This is a very l...
34,294,113
1
1
null
2015-12-15 16:12:23.853 UTC
3
2015-12-15 16:36:37.7 UTC
2015-12-15 16:36:37.7 UTC
null
4,768,433
null
865,939
null
1
39
css
28,884
<p>You actually don't need <code>width</code> to be "set" here. All the elements in the responsive design have their width. You can just do it around with the following rules:</p> <pre><code>white-space: nowrap; overflow: hidden; text-overflow: ellipsis; </code></pre> <p><strong>Comment:</strong> This doesn't work wi...
22,514,803
Maximum size of size_t
<p>I know in <code>C</code> return type of <code>sizeof</code> operator is <code>size_t</code> being unsigned integer type defined in <code>&lt;stdint.h&gt;</code>. Which means max size of it should be <code>65535</code> as stated in <code>C99</code> standard <a href="http://port70.net/~nsz/c/c99/n1256.html#7.18.3" rel...
22,514,848
1
1
null
2014-03-19 18:20:17.533 UTC
6
2020-07-01 20:34:09.287 UTC
2015-02-16 07:06:46.997 UTC
null
1,079,907
null
1,079,907
null
1
49
c|gcc|sizeof|c99|size-t
79,544
<p>The standard says that <code>SIZE_MAX</code> must be <em>at least</em> 65535.</p> <p>It specifies no upper bound, and gcc's implementation is perfectly valid.</p> <p>Quoting the reference you cited (emphasis added):</p> <blockquote> <p>Its implementation-defined value shall be <strong>equal to or greater</stron...
7,219,431
Why connection to localhost is refused?
<p>I have a server, to which a client machine connects. Recently I decided to encrypt the connection with stunnel, so now client program connects not directly to the server, but to localhost:8045 (I checked, and this port is not occupied).</p> <p>Java code:</p> <pre><code>URL url = new URL("http://localhost:8045/mali...
7,219,513
2
5
null
2011-08-28 06:42:10.113 UTC
2
2017-10-07 05:50:26.317 UTC
2011-08-28 07:00:23.567 UTC
null
486,057
null
486,057
null
1
8
java|url|networking|localhost|stunnel
79,242
<p>The listening socket is bound to the IPv6 loopback address (::1). I recall some issues with Java not supporting dual-stack IPv4/IPv6 systems correctly; this is probably such a case. It is connecting to 127.0.0.1 only (IPv4).</p> <p>Everything else you have tried (curl, telnet...) will try the IPv6 address first, ...
23,408,756
Create a general class for custom Dialog in java Android
<p>My app shows many custom dialog like Yes/No or Accept/Cancel decissions and, while I was coding, I realized that there are so much code repeated, following the same schema. </p> <p>I want to build a general class but I don't know how to do it or, more exactly, the correct way that I have to do it(interfaces, abstra...
23,408,864
6
1
null
2014-05-01 13:31:54.873 UTC
13
2018-08-23 07:08:15.1 UTC
null
null
null
null
1,196,978
null
1
27
java|android|generics|dialog
47,310
<p>First create an Base <code>DialogFragment</code> to keep hold of the instance of the <code>Activity</code>. So when the Dialog is attached to the <code>Activity</code> , you will know the instance of the <code>Activity</code> which created it.</p> <pre><code>public abstract class BaseDialogFragment&lt;T&gt; extend...
31,309,034
In release mode, code behavior is not as expected
<p>The following code generates different results under debug mode and release mode (using Visual Studio 2008):</p> <pre><code>int _tmain(int argc, _TCHAR* argv[]) { for( int i = 0; i &lt; 17; i++ ) { int result = i * 16; if( result &gt; 255 ) { result = 255; } ...
31,310,432
2
4
null
2015-07-09 05:41:21.05 UTC
18
2015-07-09 11:02:27.667 UTC
2015-07-09 11:02:27.667 UTC
null
2,659,313
null
5,078,289
null
1
132
c++|c|optimization|visual-studio-2008|compiler-bug
10,470
<p>This is interesting, at least from a historical perspective. I can reproduce the problem with VC 2008 (15.00.30729.01) <strong><em>and</em></strong> VC 2010 (16.00.40219.01) (targeting either 32-bit x86 or 64-bit x64). The problem doesn't occur with any of the compilers I have tried starting with VC 2012 (17.00.610...
19,147,280
How do you pipe "echo" into "openssl"?
<p>I am simply trying to submit the "OPTIONS / HTTP/1.0" request to SSL-enabled web servers; however, when running this, I am just simply getting "DONE" At the end of the connection. </p> <p>Here's the exact command that I'm using:</p> <pre><code>echo -e "OPTIONS / HTTP/1.0\r\n\r\n" | openssl s_client -connect site.c...
19,148,270
3
1
null
2013-10-02 21:38:33.083 UTC
5
2016-11-17 14:37:30.55 UTC
null
null
null
null
1,493,116
null
1
32
openssl
32,531
<p>the problem is discussed in this thread (the linked email has the only simple answer, which i'll repeat below): <a href="http://www.mail-archive.com/openssl-users@openssl.org/msg02937.html">http://www.mail-archive.com/openssl-users@openssl.org/msg02937.html</a></p> <pre><code>(echo "GET /"; sleep 10) | openssl s_cl...
3,901,101
Python+Celery: Chaining jobs?
<p>The <a href="http://celery.readthedocs.org/en/latest/userguide/tasks.html#avoid-launching-synchronous-subtasks" rel="noreferrer">Celery documentation</a> suggests that it's a bad idea to have tasks wait on the results of other tasks… But the suggested solution (see “good” heading) leaves a something to be desired. S...
12,034,239
1
2
null
2010-10-10 16:24:24.12 UTC
19
2016-12-22 21:19:52.643 UTC
2016-12-22 21:19:52.643 UTC
null
71,522
null
71,522
null
1
40
python|celery
34,751
<p>You can do it with a celery chain. See <a href="https://celery.readthedocs.org/en/latest/userguide/canvas.html#chains">https://celery.readthedocs.org/en/latest/userguide/canvas.html#chains</a></p> <pre><code>@task() def add(a, b): time.sleep(5) # simulate long time processing return a + b </code></pre> <p>...
1,558,481
self-taught compiler courses / good introductory compiler books?
<p>Does anyone know of online course / university lectures that comprise a typical compiler course? I've had theory of computing but unfortunately my school didn't offer a course in compiler construction. </p> <p>I know there are lectures out there; I was hoping for recommendations for particularly good offerings.</...
1,558,560
3
4
null
2009-10-13 06:28:21.267 UTC
14
2019-03-11 21:22:15.197 UTC
null
null
null
null
172,617
null
1
9
compiler-construction|context-free-grammar|dfa
6,096
<p><strong>Edit</strong>: in case this SO questions doesn't get closed, do check this <a href="https://stackoverflow.com/questions/1669/learning-to-write-a-compiler">duplicate SO posting</a> which answers the question in a much more exhaustive fashion.</p> <p>A couple of ressources on MIT's OpenCourseWare site:</p> <...
1,826,008
UpdatePanel Exception Handling
<p>Where exceptions occur in the UpdatePanels I've implemented in the ASP.NET web app I'm building, they cause a JavaScript error on the page with some high level error output available in the alert. This is OKish for development, but as soon as the system is in Production, it's obviously no good for multiple reasons. ...
1,827,097
3
0
null
2009-12-01 12:51:27.027 UTC
9
2018-06-08 19:50:04.79 UTC
2011-06-09 13:14:41.593 UTC
user1228
null
null
202,055
null
1
17
asp.net|exception|asp.net-ajax|error-handling|updatepanel
14,607
<p>You can use a combination of the AsyncPostBackError event on the ScriptManager (server-side) and the EndRequest event on the PageRequestManager (client-side) to fully handle server-side errors when using the UpdatePanel.</p> <p>Here are a couple resources that should help you:</p> <p><a href="http://msdn.microsoft...
2,075,836
Read contents of a URL in Android
<p>I'm new to android and I'm trying to figure out how to get the contents of a URL as a String. For example if my URL is <a href="http://www.google.com/" rel="noreferrer">http://www.google.com/</a> I want to get the HTML for the page as a String. Could anyone help me with this?</p>
2,075,847
3
0
null
2010-01-16 01:25:54.257 UTC
4
2018-06-07 22:55:31.033 UTC
null
null
null
null
200,565
null
1
23
android
61,380
<p>From the Java Docs : <a href="http://java.sun.com/docs/books/tutorial/networking/urls/readingURL.html" rel="noreferrer">readingURL</a></p> <pre><code>URL yahoo = new URL("http://www.yahoo.com/"); BufferedReader in = new BufferedReader( new InputStreamReader( yahoo.openStream())); String inp...
1,753,186
Dynamic Scoping - Deep Binding vs Shallow Binding
<p>I've been trying to get my head around shallow binding and deep binding, wikipedia doesn't do a good job of explaining it properly. Say I have the following code, what would the output be if the language uses dynamic scoping with</p> <p>a) deep binding</p> <p>b) shallow binding?</p> <pre><code>x: integer := 1 y: ...
1,753,505
3
1
null
2009-11-18 02:12:18.65 UTC
9
2020-10-03 12:18:41.52 UTC
2011-04-02 15:53:03.343 UTC
null
94,687
null
100,758
null
1
30
language-agnostic|binding|scoping|dynamic-scope
34,225
<p>Deep binding binds the environment at the time the procedure is passed as an argument</p> <p>Shallow binding binds the environment at the time the procedure is actually called</p> <p>So for dynamic scoping with deep binding when add is passed into a second the environment is x = 1, y = 3 and the x is the global x ...
8,964,191
Test type of elements python tuple/list
<p>How do you verify that the type of all elements in a list or a tuple are the same and of a certain type? </p> <p>for example:</p> <pre><code>(1, 2, 3) # test for all int = True (1, 3, 'a') # test for all int = False </code></pre>
8,964,208
5
1
null
2012-01-22 19:59:00.71 UTC
9
2021-09-30 18:51:23.943 UTC
2016-07-19 13:31:16.027 UTC
null
100,297
null
801,820
null
1
34
python
58,823
<pre><code>all(isinstance(n, int) for n in lst) </code></pre> <p>Demo:</p> <pre><code>In [3]: lst = (1,2,3) In [4]: all(isinstance(n, int) for n in lst) Out[4]: True In [5]: lst = (1,2,'3') In [6]: all(isinstance(n, int) for n in lst) Out[6]: False </code></pre> <p>Instead of <code>isinstance(n, int)</code> you c...
8,963,400
The correct way to read a data file into an array
<p>I have a data file, with each line having one number, like</p> <pre><code>10 20 30 40 </code></pre> <p>How do I read this file and store the data into an array? </p> <p>So that I can conduct some operations on this array.</p>
8,963,627
5
1
null
2012-01-22 18:18:49.953 UTC
16
2022-02-07 03:41:20.883 UTC
2014-02-02 18:39:19.38 UTC
null
63,550
null
297,850
null
1
38
perl
148,233
<p>Just reading the file into an array, one line per element, is trivial:</p> <pre><code>open my $handle, '&lt;', $path_to_file; chomp(my @lines = &lt;$handle&gt;); close $handle; </code></pre> <p>Now the lines of the file are in the array <code>@lines</code>.</p> <p>If you want to make sure there is error handling ...
19,468,209
Spring Security configuration: HTTP 403 error
<p>I'm trying to secure my website using Spring Security following the guides on the web.</p> <p>So on my server side I have the following classes.</p> <p>My <code>WebSecurityConfigurerAdapter</code>:</p> <pre><code>@Configuration @EnableWebSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter im...
19,496,356
6
1
null
2013-10-19 16:18:58.42 UTC
23
2022-06-15 17:37:15.897 UTC
2022-06-15 17:37:15.897 UTC
null
814,702
null
2,531,174
null
1
94
spring|spring-mvc|spring-security
152,591
<p>The issue is likely due to <a href="https://spring.io/blog/2013/08/21/spring-security-3-2-0-rc1-highlights-csrf-protection/" rel="noreferrer">CSRF protection</a>. If users will not be using your application in a web browser, <a href="https://spring.io/blog/2013/08/21/spring-security-3-2-0-rc1-highlights-csrf-protect...
62,345,581
Node.js + Puppeteer on Docker, No usable sandbox
<p>i'm building a node.js LTS application. I followed puppeteer documentation, so my Dockerfile has this content:</p> <pre><code>FROM node:12.18.0 WORKDIR /home/node/app ADD package*.json ./ # Install latest chrome dev package and fonts to support major charsets (Chinese, Japanese, Arabic, Hebrew, Thai and a few oth...
62,383,642
4
1
null
2020-06-12 13:47:42.65 UTC
11
2022-07-29 08:20:33.647 UTC
2020-06-12 14:27:02.027 UTC
null
12,048,220
null
12,048,220
null
1
15
node.js|docker|google-chrome|docker-compose|puppeteer
28,909
<p>I found a way that allows the use of chrome sandbox, thanks to usethe4ce's answer in <a href="https://stackoverflow.com/questions/50662388/running-headless-chrome-puppeteer-with-no-sandbox">here</a></p> <p>Initially i needed to install chrome separately from puppeteer, i edited my Dockerfile as following:</p> <pre><...
390,534
Aggregate functions in WHERE clause in SQLite
<p>Simply put, I have a table with, among other things, a column for timestamps. I want to get the row with the most recent (i.e. greatest value) timestamp. Currently I'm doing this:</p> <pre><code>SELECT * FROM table ORDER BY timestamp DESC LIMIT 1 </code></pre> <p>But I'd much rather do something like this:</p> <p...
390,542
4
0
null
2008-12-24 00:57:33.743 UTC
4
2012-10-18 13:18:47.95 UTC
null
null
null
nobody
658
null
1
13
sql|sqlite|where-clause|aggregate-functions
41,439
<pre><code>SELECT * from foo where timestamp = (select max(timestamp) from foo) </code></pre> <p>or, if SQLite insists on treating subselects as sets, </p> <pre><code>SELECT * from foo where timestamp in (select max(timestamp) from foo) </code></pre>
671,694
Passing Credentials to Sql Report Server 2008
<p>I am pretty new in C# and my English is not so good - sorry in advance if I miss a point.</p> <p>I tried to build an ASP.NET web site with a <code>ReportService</code> control. As you might already know, SSRS 2008 does not allow anonymous login. So, I tried to pass Credentials to SSRS which will be stored inside my...
671,761
4
2
null
2009-03-22 22:16:48.063 UTC
5
2017-10-09 06:26:26.123 UTC
2016-06-23 09:55:35.743 UTC
Mark Brackett
1,698,143
adopilot
69,433
null
1
21
c#|asp.net|reporting-services|ssrs-2008
52,856
<p>I really haven't messed with SSRS - but my ASP.NET hat tells me you may want to wrap that stuff in an <code>if (!IsPostBack)</code> block to keep it from running on the page refresh. My guess is that <code>ReportViewer1.ServerReport.Refresh()</code> pulls the default values again.</p> <pre><code>protected void Page...
1,096,899
Back to revision in Subversion
<p>suppose you update your code to revision 10 which is broken. You want to go back to revision 9, work on the code and wait until someone will fix the build:</p> <pre><code>svn merge -rHEAD:9 . </code></pre> <p>But it won't work, why?</p>
1,096,921
4
0
null
2009-07-08 08:48:32.237 UTC
5
2018-04-02 19:37:37.413 UTC
2018-04-02 19:37:37.413 UTC
null
59,087
null
61,628
null
1
56
svn|version-control
65,884
<p>If you simply want to go back to an other revision, <code>update</code> is what you are looking for:</p> <pre><code>svn update -r 9 </code></pre> <p>You can work on the code but you can't commit changes. Well, if revision 10 didn't change the same file you changed, you could commit but it's better if you wait for ...
54,419,027
How to reset a spy in Jasmine?
<p>I have an issue where I've set up a mock service as a spy.</p> <pre><code> mockSelectionsService = jasmine.createSpyObj(['updateSelections']); </code></pre> <p>I then call that stub method twice, each time in a different test. The problem is that when i <code>expect()</code> the spy with <code>.toHaveBeenCalledWit...
54,419,453
5
2
null
2019-01-29 10:32:48.613 UTC
4
2022-09-23 19:27:18.387 UTC
2020-05-29 09:54:57.77 UTC
null
542,251
null
2,066,039
null
1
53
javascript|angular|jasmine
39,919
<p><code>const spy = spyOn(somethingService, "doSomething");</code></p> <p><code>spy.calls.reset();</code></p> <p>This resets the already made calls to the spy. This way you can reuse the spy between tests. The other way would be to nest the tests in another <code>describe()</code> and put a <code>beforeEach()</code>...
873,828
Inserting a row into DB2 from a sub-select - NULL error
<p>I am trying to insert a row into a table, using a value that is derived from another table. Here is the SQL statement that I am trying to use:</p> <pre><code>INSERT INTO NextKeyValue(KeyName, KeyValue) SELECT 'DisplayWorkItemId' AS KeyName, (MAX(work_item_display_id) + 1) AS KeyValue FROM work_item; </code></pre> ...
873,945
1
1
null
2009-05-17 03:13:47.63 UTC
null
2009-05-17 17:29:27.033 UTC
2009-05-17 17:29:27.033 UTC
null
4,257
null
4,257
null
1
7
sql|db2
80,232
<p>The most probable explanation is that you have additional columns in NextKeyValue table that can't accept NULL values, and this INSERT statement is "trying" to put NULL in them. </p> <p>Is that the case by any chance?</p>
57,453,141
Using React Hooks To Update w/ Scroll
<p>I'm trying to control the visibility of a React Component based on whether an individual is scrolling down on the component. The visibility is passed into the <code>Fade</code> element as the "in" property.</p> <p>I've set up a listener using the UseEffect Hook, which adds the listener onMount. The actual onScroll ...
57,453,199
2
0
null
2019-08-11 19:53:33.547 UTC
9
2021-01-07 09:11:08.07 UTC
2019-08-11 23:05:47.547 UTC
null
7,860,026
null
7,860,026
null
1
29
javascript|reactjs|react-hooks
52,269
<p>You're missing the dependencies in your hook. Try this: </p> <pre><code> useEffect(() =&gt; { const onScroll = e =&gt; { setScrollTop(e.target.documentElement.scrollTop); setScrolling(e.target.documentElement.scrollTop &gt; scrollTop); }; window.addEventListener("scroll", onScroll); re...
29,855,098
Is there a built-in javascript function similar to os.path.join?
<p>Is there a built-in javascript (client-side) function that functions similarly to Node's <code>path.join</code>? I know I can join strings in the following manner:</p> <pre><code>['a', 'b'].join('/') </code></pre> <p>The problem is that if the strings already contain a leading/trailing &quot;/&quot;, then they will ...
29,855,282
10
1
null
2015-04-24 18:39:10.527 UTC
1
2022-06-10 18:29:35.147 UTC
2022-02-08 14:04:29.443 UTC
null
2,059,996
null
1,459,601
null
1
43
javascript|node.js
36,899
<p>There isn't currently a built-in that will perform a join while preventing duplicate separators. If you want concise, I'd just write your own:</p> <pre><code>function pathJoin(parts, sep){ var separator = sep || '/'; var replace = new RegExp(separator+'{1,}', 'g'); return parts.join(separator).replace(re...
40,025,762
angular2-cli gives @multi styles error
<p>I started using angular2-cli recently and created a new project. I wanted to use bootstrap in my project hence I installed bootstrap and then wanted to import the bootstrap css file like it is shown in the the angular2-cli guide here. <a href="https://github.com/angular/angular-cli#global-library-installation" rel="...
42,698,103
16
0
null
2016-10-13 15:58:13.207 UTC
3
2021-03-22 12:24:28.397 UTC
null
null
null
null
3,979,221
null
1
18
css|angular|styles|angular2-cli
44,096
<p>Add ../ before path.</p> <p>In angular-cli.json,</p> <pre><code>"styles": [ "../node_modules/bootstrap/dist/css/bootstrap.min.css", "styles.scss" ] </code></pre> <p><strong>Update</strong></p> <p>In angular7, there is angular.json file and you do not need to add ../ before path</p>
39,882,618
paste text with a newline/return in formatted text
<p>I want to do a column that is formatted to use for a mailing address and I can not get the newline/return carriage or <code>&lt;br/&gt;</code> to work when making a new column.</p> <pre><code>name = c("John Smith", "Patty Smith", "Sam Smith") address = c("111 Main St.", "222 Main St.", "555 C Street") cityState = c...
39,882,657
2
1
null
2016-10-05 19:55:58.433 UTC
3
2016-10-14 19:40:54.48 UTC
2016-10-14 19:40:54.48 UTC
null
1,016,716
null
5,151,945
null
1
25
r|text|text-processing
67,754
<p>To get a new line (or return) we use <code>\n</code>. So</p> <pre><code>addr = paste(name, address, cityState, sep="\n") </code></pre> <p>To view the result just use <code>cat</code></p> <pre><code>&gt; cat(addr[1]) #John Smith #111 Main St. #Portland, OR 97212 </code></pre> <p>The function <code>cat</code> jus...
23,757,345
Android does not correctly scroll on input focus if not body element
<p>When a mobile browser brings up a keyboard it tries to move the scrollbars so that the input is still in view.</p> <p>On iOS Safari it seems to do this properly by finding the <strong>nearest</strong> scrolling parent.</p> <p>On Android native or Chrome mobile browser it seems to just try the body element and then g...
25,032,766
4
1
null
2014-05-20 10:30:41.32 UTC
10
2017-08-22 13:41:38.04 UTC
2020-06-20 09:12:55.06 UTC
null
-1
null
414,062
null
1
21
android|google-chrome|input|scroll|focus
32,229
<p>This is a bug in the Android native browser. By the way, the input scrolls into the view after a character is typed on the soft keyboard.</p> <p>The following code snippet placed somewhere in the page should help:</p> <pre><code>if(/Android 4\.[0-3]/.test(navigator.appVersion)){ window.addEventListener("resize"...
42,720,421
Could not load file or assembly System.Net.Http version 4.1.1.0
<p>I'm porting a Net Framework 4 dll to Net Core. When porting my unit tests project I get an exception running some specific tests (not all).</p> <blockquote> <p>System.IO.FileLoadException: Could not load file or assembly 'System.Net.Http, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one o...
42,721,262
10
3
null
2017-03-10 14:13:05.803 UTC
4
2022-01-26 20:30:14.15 UTC
2019-01-18 15:22:39.08 UTC
null
1,448,943
null
1,535,132
null
1
42
c#|.net|.net-core|porting|.net-framework-version
47,165
<p>Fixed it by updating System.Net.Http to 4.3.1</p>
37,333,339
How to install latest JMeter in Ubuntu 15.10?
<p>When I try to install Apache JMeter in Ubuntu 15.10 using apt-get install JMeter it installs the older version 2.11. However, I tried to download the latest JMeter 3.0 version and when tried to run <code>jmeter.jar</code> file it won't open.</p> <p>I am trying to install this on a Ubuntu 15.10 server. I can't upgra...
37,342,086
4
1
null
2016-05-19 20:24:21.36 UTC
2
2019-09-11 18:24:27.533 UTC
2018-09-07 08:20:59.697 UTC
null
5,180,017
null
3,584,034
null
1
18
ubuntu|jmeter
54,076
<p>Looking into <a href="http://packages.ubuntu.com/search?keywords=jmeter" rel="noreferrer">jmeter package details</a> you won't be able to get latest JMeter via apt.</p> <p>Follow the next simple installation steps:</p> <ol> <li><code>sudo apt-get update</code> - to refresh packages metadata</li> <li><code>sudo apt-g...
37,268,572
How to use data binding for Switch onCheckedChageListener event?
<p>As question indicates, how to bind checked change listener to Switch button in xml ? </p> <p>I am not using recycler view. Just a simple layout.</p> <p>Any help appreciated.</p>
37,288,929
4
2
null
2016-05-17 06:21:28.067 UTC
7
2020-06-24 19:18:09.32 UTC
2018-09-21 04:56:37.813 UTC
null
6,891,563
null
5,907,852
null
1
42
android|data-binding|android-switch
30,570
<p>You can do it with a method reference:</p> <pre><code>&lt;CheckBox android:onCheckedChanged="@{callback::checkedChangedListener}".../&gt; </code></pre> <p>or with a lambda expression if you want to pass different parameters:</p> <pre><code>&lt;CheckBox android:onCheckedChanged="@{() -&gt; callback.checked()}".../...
30,305,217
Is it possible to use Mockito in Kotlin?
<p>The problem I'm facing is that <code>Matchers.anyObject()</code> returns <code>null</code>. When used to mock method that only accepts non-nullable types it causes a "Should not be null" exception to be thrown. </p> <pre><code>`when`(mockedBackend.login(anyObject())).thenAnswer { invocationOnMock -&gt; someResponse...
30,308,199
6
2
null
2015-05-18 13:58:34.37 UTC
23
2020-09-03 17:17:50.65 UTC
null
null
null
null
1,356,130
null
1
92
java|mocking|mockito|kotlin
47,214
<p>There are two possible workarounds:</p> <pre><code>private fun &lt;T&gt; anyObject(): T { Mockito.anyObject&lt;T&gt;() return uninitialized() } private fun &lt;T&gt; uninitialized(): T = null as T @Test fun myTest() { `when`(mockedBackend).login(anyObject())).thenAnswer { ... } } </code></pre> <p>The...
20,793,306
How to append content to querySelectorAll element with innerHTML/innerText?
<p>I currently have my class element:</p> <pre><code>var frame_2 = document.querySelectorAll(".name"); </code></pre> <p>Currently this div is empty. I now want to "append/add" some content to that div - I had a go with <code>innerHTML</code> + <code>innerText</code> but for some reason nothing seems to be added.</p> ...
20,793,362
2
1
null
2013-12-27 01:01:49.287 UTC
5
2021-11-11 13:54:00.017 UTC
null
null
null
null
1,231,561
null
1
9
javascript|append|innerhtml|innertext
51,304
<p>this gives you a list of elements that contain the class name</p> <pre><code>var name=document.querySelectorAll(".name"); </code></pre> <p>you want the first element?</p> <pre><code>name[0].textContent='some text'; </code></pre> <p>This gives you one single element, the first one.</p> <pre><code>var name=docume...
47,062,532
Multiple Lines for Text per Legend Label in ggplot2
<p>I'm trying to deal with very long labels for a legend in a bar plot (see picture included and the code i used to produce it. I need to break them down in multiple (rows of) lines (2 or 3), other wise the whole picture will be to wide. Some help would be very helpful. Actually I also suspect that my code is not as co...
47,064,251
1
3
null
2017-11-01 19:45:12.733 UTC
14
2017-11-01 21:49:12.563 UTC
null
null
null
null
5,235,404
null
1
27
r|ggplot2|legend
38,405
<p>You can use <code>str_wrap</code> for automated wrapping of long strings or you can hard code breaks by adding <code>\n</code> (the line break character) to a string. To add space between the legend keys, you can use the <code>legend.key.height</code> theme element. Here's an example with the built-in <code>iris</co...
32,448,414
What does colon at assignment for list[:] = [...] do in Python
<p>I came accross the following code:</p> <pre><code># O(n) space def rotate(self, nums, k): deque = collections.deque(nums) k %= len(nums) for _ in xrange(k): deque.appendleft(deque.pop()) nums[:] = list(deque) # &lt;- Code in question </code></pre> <p>What does <code>nums[:] =</code> ...
32,448,477
2
3
null
2015-09-08 02:36:27.893 UTC
22
2022-08-03 15:26:31.773 UTC
2017-12-06 22:20:27.337 UTC
null
2,202,071
null
1,218,699
null
1
28
python|python-3.x
37,048
<p>This syntax is a slice assignment. A slice of <code>[:]</code> means the entire list. The difference between <code>nums[:] =</code> and <code>nums =</code> is that the latter doesn't replace elements in the original list. This is observable when there are two references to the list</p> <pre><code>&gt;&gt;&gt; orig...
34,764,796
Why does declaring main as an array compile?
<p>I saw <a href="https://codegolf.stackexchange.com/a/69193/13441">a snippet of code on CodeGolf</a> that's intended as a compiler bomb, where <code>main</code> is declared as a huge array. I tried the following (non-bomb) version:</p> <pre><code>int main[1] = { 0 }; </code></pre> <p>It seems to compile fine under C...
34,764,930
6
4
null
2016-01-13 10:55:04.573 UTC
12
2018-04-25 07:56:21.013 UTC
2017-04-13 12:38:59.36 UTC
null
-1
null
1,892,179
null
1
62
c|gcc|clang|program-entry-point
11,756
<p>It's because C allows for "non-hosted" or freestanding environment which doesn't require the <code>main</code> function. This means that the name <code>main</code> is freed for other uses. This is why the language as such allows for such declarations. Most compilers are designed to support both (the difference is mo...
25,297,705
mean( ,na.rm=TRUE) still returns NA
<p>I'm very new to R (moving over from SPSS). I'm using RStudio on a Mac running Mavericks. Please answer my question in words of 2 syllables as this is my first real attempt at anything like this. I've worked through some basic tutorials and can make things work on all the sample data.</p> <p>I have a data set wit...
25,297,762
2
4
null
2014-08-13 23:13:42.023 UTC
4
2017-05-29 23:58:01.373 UTC
null
null
null
null
3,939,345
null
1
9
r|mean|na
46,418
<p>Hello Rnovice unfortunatly there are several errors... Lets resolve them one by one:</p> <pre><code>&gt; mean(as.numeric(data_Apr_Jun$hold_time,NA.rm=TRUE)) [1] NA </code></pre> <p>This is because you use <code>na.rm</code> in a wrong manner: it should be </p> <pre><code>mean(as.numeric(data_Apr_Jun$hold_time),n...
39,072,001
Dependency injection resolving by name
<p>How can I inject different implementation of object for a specific class?</p> <p>For example, in Unity, I can define two implementations of <code>IRepository</code></p> <pre><code>container.RegisterType&lt;IRepository, TestSuiteRepositor(&quot;TestSuiteRepository&quot;); container.RegisterType&lt;IRepository, BaseRe...
39,072,950
5
4
null
2016-08-22 05:37:02.05 UTC
13
2020-11-12 01:11:17.833 UTC
2020-11-12 01:07:14.643 UTC
null
1,402,846
null
2,924,700
null
1
35
c#|dependency-injection|asp.net-core
39,518
<p>As @Tseng pointed, there is no built-in solution for named binding. However using factory method may be helpful for your case. Example should be something like below:</p> <p>Create a repository resolver:</p> <pre><code>public interface IRepositoryResolver { IRepository GetRepositoryByName(string name); } publ...
6,929,180
REST and SOAP webservice in android
<p>I found tutorial to use kSOAP api to use SOAP webservice. Can anyone provide me sample programs (tutorial) on getting REST webservice and SOAP webservice in android. I have googled lot but didn't find such type of tutorial.</p>
6,978,711
2
1
null
2011-08-03 15:38:20.39 UTC
15
2012-10-28 10:06:13.523 UTC
2012-04-03 08:45:21.817 UTC
user831722
948,041
user831722
null
null
1
10
android|web-services|rest|soap
22,977
<p><strong>SOAP</strong></p> <p>Pros:</p> <blockquote> <ul> <li>Langauge, platform, and transport agnostic</li> <li>Designed to handle distributed computing environments</li> <li>Is the prevailing standard for web services, and hence has better support from other standards (WSDL, WS-*) and tooling from vendor...
6,545,741
Django catch-all URL without breaking APPEND_SLASH
<p>I have an entry in my urls.py that acts as a catch-all which loads a simple view if it finds an appropriate page in the database. The problem with this approach is that the URL solver will then never fail, meaning that the APPEND_SLASH functionality won't kick in - which I need.</p> <p>I'd rather not have to resort...
10,199,446
2
0
null
2011-07-01 08:59:39.27 UTC
7
2012-04-17 21:28:14.023 UTC
2011-07-01 09:38:46.447 UTC
null
77,533
null
77,533
null
1
32
django
18,387
<p>Make sure that your catch-all URL pattern has a slash at the end, and that the pattern is the last in your URLconf. If the catch-all pattern doesn't end with a slash, then it will match stray URLs before the middleware tries appending a slash.</p> <p>For example, use <code>r'^.*/$'</code> instead of <code>r'^.*'</c...
7,613,359
Why Can't I access src/test/resources in Junit test run with Maven?
<p>I am having a problems running the following code:</p> <pre><code>configService.setMainConfig("src/test/resources/MainConfig.xml"); </code></pre> <p>From within a Junit @Before method.</p> <p>Is this the way Maven builds out its target folder?</p>
7,613,426
3
0
null
2011-09-30 16:29:37.82 UTC
14
2019-08-02 19:44:29.433 UTC
null
null
null
null
1,399,539
null
1
48
java|junit4|mockito
85,231
<p>Access <code>MainConfig.xml</code> directly. The <code>src/test/resources</code> directory contents are placed in the root of your CLASSPATH.</p> <p>More precisely: contents of <code>src/test/resources</code> are copied into <code>target/test-classes</code>, so if you have the following project structure:</p> <pre...
7,500,081
Scala: what is the best way to append an element to an Array?
<p>Say I have an <code>Array[Int]</code> like</p> <pre><code>val array = Array( 1, 2, 3 ) </code></pre> <p>Now I would like to append an element to the array, say the value <code>4</code>, as in the following example: </p> <pre><code>val array2 = array + 4 // will not compile </code></pre> <p>I can of course us...
7,500,143
3
6
null
2011-09-21 12:53:10.943 UTC
32
2017-11-24 11:47:29.183 UTC
2014-12-19 08:07:42.29 UTC
null
402,884
null
820,380
null
1
121
arrays|scala|append
185,266
<p>You can use <code>:+</code> to append element to array and <code>+:</code> to prepend it:</p> <pre><code>0 +: array :+ 4 </code></pre> <p>should produce:</p> <pre><code>res3: Array[Int] = Array(0, 1, 2, 3, 4) </code></pre> <p>It's the same as with any other implementation of <code>Seq</code>. </p>
7,575,589
How does JavaScript handle AJAX responses in the background?
<p>Since JavaScript runs in a single thread, after an AJAX request is made, what actually happens in the background? I would like to get a deeper insight into this, can anyone shed some light? </p>
7,575,649
3
4
null
2011-09-27 20:58:11.563 UTC
104
2020-05-03 07:46:18.157 UTC
2016-06-29 00:23:41.13 UTC
null
914,272
null
914,272
null
1
145
javascript|xmlhttprequest
24,667
<p>Below the covers, javascript has an event queue. Each time a javascript thread of execution finishes, it checks to see if there is another event in the queue to process. If there is, it pulls it off the queue and triggers that event (like a mouse click, for example).</p> <p>The native code networking that lies un...
24,282,121
Why use tanh for activation function of MLP?
<p>Im personally studying theories of neural network and got some questions. </p> <p>In many books and references, for activation function of hidden layer, hyper-tangent functions were used. </p> <p>Books came up with really simple reason that linear combinations of tanh functions can describe nearly all shape of fun...
24,282,337
7
1
null
2014-06-18 09:38:06.29 UTC
18
2020-03-05 20:27:08.177 UTC
null
null
null
null
3,709,740
null
1
20
machine-learning|neural-network|hyperbolic-function
28,220
<p>In truth both tanh and logistic functions can be used. The idea is that you can map any real number ( [-Inf, Inf] ) to a number between [-1 1] or [0 1] for the tanh and logistic respectively. In this way, it can be shown that a combination of such functions can approximate any non-linear function. Now regarding the ...
24,222,088
Capture program stdout and stderr to separate variables
<p>Is it possible to redirect stdout from an external program to a variable and stderr from external programs to another variable in one run?</p> <p>For example:</p> <pre><code>$global:ERRORS = @(); $global:PROGERR = @(); function test() { # Can we redirect errors to $PROGERR here, leaving stdout for $OUTPUT? ...
24,223,482
7
1
null
2014-06-14 16:44:00.87 UTC
8
2021-05-03 23:36:30.417 UTC
2018-12-09 13:23:10.25 UTC
null
1,630,171
null
2,245,659
null
1
48
windows|powershell|command-line|stdout|stderr
52,321
<p>The easiest way to do this is to use a file for the stderr output, e.g.:</p> <pre><code>$output = &amp; myprogram.exe 'argv[0]', 'argv[1]' 2&gt;stderr.txt $err = get-content stderr.txt if ($LastExitCode -ne 0) { ... handle error ... } </code></pre> <p>I would also use $LastExitCode to check for errors from native ...
24,390,005
Checking for empty or null List<string>
<p>I have a List where sometimes it is empty or null. I want to be able to check if it contains any List-item and if not then add an object to the List.</p> <pre><code> // I have a list, sometimes it doesn't have any data added to it var myList = new List&lt;object&gt;(); // Expression is always false if (my...
24,390,071
25
1
null
2014-06-24 15:00:51.427 UTC
22
2022-03-22 11:24:20.82 UTC
2018-10-13 19:33:32.967 UTC
null
2,768,516
null
3,131,062
null
1
97
c#|list
416,385
<p>Try the following code:</p> <pre><code> if ( (myList!= null) &amp;&amp; (!myList.Any()) ) { // Add new item myList.Add(&quot;new item&quot;); } </code></pre> <p>A late EDIT because for these checks I now like to use the following solution. First, add a small reusable extension method called Safe():</p> ...
1,850,732
How to position a div dynamically below another?
<p>I'm trying to use jQuery to detect the position of a div (<code>#olddiv</code>), so I can use that position to place another div (<code>#newdiv</code>) exactly below it. The right borders of the 2 divs are aligned (right border). </p> <p>I'm trying to get the <code>#olddiv</code> bottom and right locations to use t...
1,850,766
4
0
null
2009-12-05 01:21:17.717 UTC
4
2016-04-29 09:15:36.11 UTC
2013-07-22 14:34:47.013 UTC
null
448,144
null
225,215
null
1
11
jquery|dom
39,404
<p>I've used offset() to position elements dynamically. Try this:</p> <pre><code>var offset = $('#olddiv').offset(); var height = $('#olddiv').height(); var width = $('#olddiv').width(); var top = offset.top + height + "px"; var right = offset.left + width + "px"; $('#ID').css( { 'position': 'absolute', 'righ...
2,231,460
gdb: howto list open files
<p>I am wondering if it might be possible to get a list of files/directories that the debugged application has opened but not closed from GDB itself ?</p> <p>Currently I set a breakpoint and then I use an external program like <code>lsof</code> to check for opened files.</p> <p>But this approach is really annoying.</...
2,232,734
4
0
null
2010-02-09 18:28:36.657 UTC
11
2017-07-21 15:29:38.117 UTC
2010-02-09 18:37:25.65 UTC
anon
null
anon
null
null
1
22
gdb
26,050
<p>due to the help of Nicholas I was able to fully automate the task by defining a macro.</p> <p><code>.gdbinit</code>:</p> <pre><code>define lsof shell rm -f pidfile set logging file pidfile set logging on info proc set logging off shell lsof -p `cat pidfile | perl -n -e 'print $1 if /process (.+)/'` end...
52,724,312
Webpack: TypeError: Cannot read property 'properties' of undefined
<p>Here is the branch and repo in question: <a href="https://github.com/Futuratum/moon.holdings/tree/dev" rel="noreferrer">https://github.com/Futuratum/moon.holdings/tree/dev</a></p> <blockquote> <p>/Users/leongaban/projects/Futuratum/moon.holdings/node_modules/webpack-cli/bin/config-yargs.js:89 ...
52,841,778
6
5
null
2018-10-09 15:14:02.74 UTC
null
2022-09-22 20:50:57.333 UTC
null
null
null
null
168,738
null
1
24
javascript|webpack
45,682
<p>Try to install latest LTS version of Node and test again. Works perfectly fine for me with latest LTS node and npm.</p>
10,723,088
401 response for CORS request in IIS with Windows Auth enabled
<p>I'm trying to enable CORS support in my WebAPI project, and if I enable Anonymous Authentication then everything works fine, but with Windows Auth + disabled anonymous authentication, the OPTIONS request sent always returns a 401 unauthorized response. The site requesting it is on the DOMAIN so should be able to mak...
10,820,339
14
2
null
2012-05-23 15:25:16.157 UTC
22
2021-11-07 08:24:57.077 UTC
null
null
null
null
88,170
null
1
51
iis-7.5|windows-authentication|asp.net-web-api|ntlm|cors
53,696
<p>From MS:</p> <p>If you disable anonymous authentication, it’s by design that IIS would return a 401 to any request. If they have enabled Windows auth, the 401 response in that case would have a WWW-Authenticate header to allow the client to start an authentication handshake. The question then becomes whether the ...
7,372,268
how to convert hex to base64
<p>how to convert hex string into base64 ? I found this page <a href="http://home2.paulschou.net/tools/xlate/" rel="noreferrer">http://home2.paulschou.net/tools/xlate/</a> but I need some function in java: <code>String base64 = ...decoder(String hex);</code> I found something in the Internet but they are to difficult a...
7,372,374
6
1
null
2011-09-10 14:09:45.34 UTC
5
2022-01-22 11:40:53.527 UTC
null
null
null
null
431,769
null
1
17
java|base64
38,939
<p>Have a look at <a href="http://commons.apache.org/codec/" rel="noreferrer">Commons Codec</a> :</p> <pre><code> import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Hex; byte[] decodedHex = Hex.decodeHex(hex); byte[] encodedHexB64 = Base64.encodeBase64(decodedHex); </code></pre>
7,694,843
using array_search for multi dimensional array
<p>using array_search in a 1 dimensional array is simple</p> <pre><code>$array = array("apple", "banana", "cherry"); $searchValue = "cherry"; $key = array_search($searchValue, $array); echo $key; </code></pre> <p>but how about an multi dimensional array?</p> <pre><code> #RaceRecord [CarID] [ColorID] [Positi...
7,694,864
6
2
null
2011-10-08 04:34:50.233 UTC
8
2019-04-15 05:39:49.513 UTC
2017-07-11 08:52:50.733 UTC
null
4,474,165
null
946,159
null
1
35
php|arrays|multidimensional-array
104,137
<pre><code>function find_car_with_position($cars, $position) { foreach($cars as $index =&gt; $car) { if($car['Position'] == $position) return $index; } return FALSE; } </code></pre>
7,331,425
Twitter bootstrap CSS + jQuery
<p>I just discover twitter-boostrap </p> <p><a href="https://github.com/twbs/bootstrap" rel="nofollow">https://github.com/twbs/bootstrap</a></p> <p>and I'm wondering if there is a jquery library to use with it.</p> <p>For popovers, modals, tool tips, alerts messages, tabs...</p> <p>or for example, use this as jquer...
9,113,210
7
1
null
2011-09-07 09:17:07.42 UTC
10
2015-08-15 20:44:12.6 UTC
2013-09-09 17:22:10.73 UTC
null
1,430,996
null
210,456
null
1
26
jquery|jquery-ui|twitter-bootstrap
36,484
<p>There is Jquery UI Bootstrap: <a href="https://github.com/jquery-ui-bootstrap/jquery-ui-bootstrap" rel="nofollow noreferrer">https://github.com/jquery-ui-bootstrap/jquery-ui-bootstrap</a></p> <p>It's a Bootstrap port on jQuery UI.</p>
7,090,883
How can I get package name in android?
<p>I need to write some util class by myself and I need the packagename of android app. While I found the packageManager which only can be used in Activity and so on that has context. I only want to get packagename in my class which will be used in android app. So how can I do this? Thank you!</p>
7,090,983
9
1
null
2011-08-17 09:53:04.853 UTC
2
2018-01-18 15:55:27.79 UTC
2011-08-17 10:33:03.44 UTC
null
811,854
null
898,366
null
1
9
java|android
50,310
<p>Use : <code>getPackageManager().getPackageInfo(getPackageName(), 0).packageName</code> Or just <code>MyContext.getPackageName()</code></p> <p>You can also create a function:</p> <pre><code>public String getPackageName(Context context) { return context.getPackageName(); } </code></pre>
7,186,648
How to remove first 10 characters from a string?
<p>How to ignore the first 10 characters of a string?</p> <p>Input:</p> <pre><code>str = "hello world!"; </code></pre> <p>Output:</p> <pre><code>d! </code></pre>
7,186,711
12
4
null
2011-08-25 07:35:04.053 UTC
16
2020-06-01 08:31:35.27 UTC
2015-08-17 10:58:25.937 UTC
null
1,080,354
null
898,129
null
1
113
c#|asp.net|.net|string|substring
281,670
<pre><code>str = "hello world!"; str.Substring(10, str.Length-10) </code></pre> <p>you will need to perform the length checks else this would throw an error</p>
14,089,342
Refresh ComboBox Items, easiest way
<p>I've googled a lot. Found a lot as well. Unfortunately nothing is straight, easy and most importantly, simple. I want some guy write a <code>method</code> that takes a <code>List&lt;string&gt;</code> and removes previous <code>Items</code>, then set this <code>List&lt;string&gt;</code>.</p> <p>Currently I have a me...
14,089,398
5
1
null
2012-12-30 08:25:54.09 UTC
3
2018-06-08 12:22:33.95 UTC
2015-07-15 12:04:41.273 UTC
null
2,723,943
null
1,928,378
null
1
11
c#|winforms|c#-4.0|combobox
70,049
<p>You don't need albumList.Items.Clear();</p> <p>This code works just fine</p> <pre><code>public void refreshList(List&lt;string&gt; list){ albumList.DataSource = list; } </code></pre>
14,018,394
Android SQLite Query - Getting latest 10 records
<p>I have a database saved in my Android application and want to retrieve the last 10 messages inserted into the DB.</p> <p>When I use:</p> <pre><code>Select * from tblmessage DESC limit 10; </code></pre> <p>it gives me the 10 messages but from the <strong>TOP</strong>. But I want the <strong>LAST</strong> 10 messag...
14,018,868
9
3
null
2012-12-24 07:25:22.977 UTC
9
2020-11-16 00:55:03.147 UTC
2017-05-20 15:46:00.743 UTC
null
165,071
null
1,114,329
null
1
26
android|sql|sqlite|android-sqlite
41,518
<p>Change the DESC to ASC and you will get the records that you want, but if you need them ordered, then you will need to reverse the order that they come in. You can either do that in your own code or simply extend your query like so:</p> <pre><code>select * from ( select * from tblmessage order by sortfie...
13,887,365
Circular Heatmap that looks like a donut
<p>I'm trying to create circular heatmap with ggplot2 so I can use a larger number of labels around the circumference of a circle. I'd like to have it look more like a donut with an empty hole in the middle but at the same time not losing any rows (they would need to be compressed).</p> <p>Code for what I have is belo...
13,888,860
2
0
null
2012-12-14 22:51:21.347 UTC
20
2021-04-27 21:52:05.527 UTC
2018-12-21 13:23:57.493 UTC
null
4,076,315
null
1,905,004
null
1
33
r|ggplot2|heatmap|donut-chart
8,172
<p>Here is a solution accomplished by (1) converting factor to numeric and adding an offset, (2) manually specifying y-limits and (3) manually setting y-axis breaks and labels:</p> <pre><code>library(reshape) library(ggplot2) # Using ggplot2 0.9.2.1 nba &lt;- read.csv("http://datasets.flowingdata.com/ppg2008.csv") nb...
43,040,685
How can I change php-cli version on Ubuntu 14.04?
<p>I am new to using Linux and I broke some php settings while tampering. </p> <p>If I execute a php script containing: <code>phpinfo();</code> it shows the php versions as 5.6, but via the command line, if I run <code>php -v</code> it returns a version of 7.0.</p> <p>I want to have both versions match.<br> How can i...
43,168,301
7
2
null
2017-03-27 07:49:32.743 UTC
30
2020-04-27 16:16:11 UTC
2017-03-29 17:41:39.72 UTC
null
1,590,950
null
6,197,481
null
1
99
php|linux|ubuntu
90,177
<pre><code>sudo update-alternatives --set php /usr/bin/php5.6 </code></pre> <p>Please see: <a href="https://tecadmin.net/switch-between-multiple-php-version-on-ubuntu/" rel="noreferrer">Source</a></p>
44,463,987
Homestead installation
<p>I could not figure out where I made a mistake here. My command <code>vagrant up</code> replies with the following lines</p> <pre><code>$ vagrant up Check your Homestead.yaml file, the path to your private key does not exist. Check your Homestead.yaml file, the path to your private key does not exist. </code></pre> ...
44,466,436
4
5
null
2017-06-09 17:50:44.467 UTC
37
2021-01-31 17:31:22.497 UTC
2017-06-09 18:30:46.027 UTC
null
345,812
null
3,775,790
null
1
110
laravel|homestead
83,484
<p>You want to follow these steps from terminal</p> <p>Generate a ssh key <code>ssh-keygen -t rsa -b 4096 -C "your_email@example.com"</code></p> <p>Start ssh agent <code>eval "$(ssh-agent -s)"</code></p> <p>Add your SSH private key to the ssh-agent <code>ssh-add -k ~/.ssh/id_rsa</code></p> <p>Then run <code>vagrant...
19,739,371
Dismiss Ongoing Android Notification Via Action Button Without Opening App
<p>I have an app that has an ongoing notification to help with memorization. I want to be able to dismiss this notification with one of the action button, but I don't want to open the app when the button is hit. I would prefer to use the built-in notification action buttons and not create a RemoteViews object to popula...
19,745,745
3
2
null
2013-11-02 05:54:38.263 UTC
10
2022-06-25 18:16:50.827 UTC
null
null
null
null
2,469,169
null
1
23
android|notifications|broadcastreceiver
31,440
<p>Start with this:</p> <pre><code>int final NOTIFICATION_ID = 1; //Create an Intent for the BroadcastReceiver Intent buttonIntent = new Intent(context, ButtonReceiver.class); buttonIntent.putExtra("notificationId",NOTIFICATION_ID); //Create the PendingIntent PendingIntent btPendingIntent = PendingIntent.getBroadcas...
56,227,419
Why does Python's hash of infinity have the digits of π?
<p>The hash of infinity in Python has digits matching <a href="https://en.wikipedia.org/wiki/Pi" rel="noreferrer">pi</a>:</p> <pre><code>&gt;&gt;&gt; inf = float('inf') &gt;&gt;&gt; hash(inf) 314159 &gt;&gt;&gt; int(math.pi*1e5) 314159 </code></pre> <p>Is that just a coincidence or is it intentional?</p>
56,227,651
3
6
null
2019-05-20 20:00:20.537 UTC
22
2021-03-15 22:45:56.6 UTC
2019-05-24 01:24:26.663 UTC
null
8,454
null
674,039
null
1
243
python|math|hash|floating-point|pi
29,093
<p><code>_PyHASH_INF</code> is <a href="https://github.com/python/cpython/blob/35d5068928ab5485e5f28b60b1e33062bc2c46cc/Include/pyhash.h#L31" rel="nofollow noreferrer">defined as a constant</a> equal to <code>314159</code>.</p> <p>I can't find any discussion about this, or comments giving a reason. I think it was chos...
34,984,552
What is the difference between quote and list?
<p>I know that you can use <code>'</code> (aka <code>quote</code>) to create a list, and I use this all the time, like this:</p> <pre><code>&gt; (car '(1 2 3)) 1 </code></pre> <p>But it doesn’t always work like I’d expect. For example, I tried to create a list of functions, like this, but it didn’t work:</p> <pre><c...
34,984,553
2
3
null
2016-01-25 03:18:35.543 UTC
35
2021-03-23 04:18:12.873 UTC
2016-09-04 10:23:43.02 UTC
null
849,891
null
465,378
null
1
60
scheme|racket|evaluation|quote
15,836
<h1>TL;DR: They are different; use <code>list</code> when in doubt.</h1> <p>A rule of thumb: use <code>list</code> whenever you want the arguments to be evaluated; <code>quote</code> “distributes” over its arguments, so <code>'(+ 1 2)</code> is like <code>(list '+ '1 '2)</code>. You’ll end up with a symbol in your lis...
429,478
Do I need to dispose a web service reference in ASP.NET?
<p>Does the garbage collector clean up web service references or do I need to call dispose on the service reference after I'm finished calling whatever method I call?</p>
429,499
5
0
null
2009-01-09 19:58:14.1 UTC
10
2021-07-03 04:22:40.84 UTC
null
null
null
BeaverProj
32,908
null
1
10
c#|asp.net|web-services|dispose
16,014
<p>Instead of worrying about disposing your web services, you could keep only a single instance of each web service, using a <a href="http://csharpindepth.com/Articles/General/Singleton.aspx" rel="nofollow noreferrer">singleton pattern</a>. Web services are stateless, so they can safely be shared between connections an...
1,320,621
Throw a NullReferenceException while calling the set_item method of a Dictionary object in a multi-threading scenario
<p>Our website has a configuration page such as "config.aspx", when the page initializing will load some information from a configuration file. To cache the loaded information we provided a factory class and we call a public method of the factory to get the configuration instance when the page loaded. But sometimes whe...
1,320,701
5
0
null
2009-08-24 05:32:47.663 UTC
4
2015-10-19 14:52:40.717 UTC
2015-10-19 14:52:40.717 UTC
null
70,345
null
161,849
null
1
53
c#|multithreading|dictionary|locking
18,593
<p>As the exception occurs internally in the <code>Dictionary</code> code, it means that you are accessing the same <code>Dictionary</code> instance from more than one thread at the same time.</p> <p>You need to synchronise the code in the <code>GetInstance</code> method so that only one thread at a time accesses the ...
354,224
Combining UNION ALL and ORDER BY in Firebird
<p>This is my first attempt at answering my own question, since someone may well run into this and so it might be of help. Using Firebird, I want to combine the results of two queries using UNION ALL, then sort the resulting output on a given column. Something like:</p> <pre><code>(select C1, C2, C3 from T1) union all...
354,242
6
0
null
2008-12-09 21:00:58.94 UTC
3
2021-10-26 15:45:31.5 UTC
null
null
null
Chris
8,415
null
1
16
sql|database|database-design|firebird
46,304
<pre><code>SELECT C1, C2, C3 FROM ( select C1, C2, C3 from T1 union all select C1, C2, C3 from T2 ) order by C3 </code></pre>
373,126
How to design a database schema to support tagging with categories?
<p>I am trying to so something like <a href="https://stackoverflow.com/questions/48475/database-design-for-tagging">Database Design for Tagging</a>, except each of my tags are grouped into categories.</p> <p>For example, let's say I have a database about vehicles. Let's say we actually don't know very much about vehi...
373,291
6
1
null
2008-12-16 23:18:40.737 UTC
30
2021-01-11 18:53:56.357 UTC
2017-05-23 12:16:25.973 UTC
Bill Karwin
-1
Pyrolistical
21,838
null
1
16
sql|schema|tags|foreign-keys|entity-attribute-value
13,102
<p>This is yet another variation on the <a href="http://en.wikipedia.org/wiki/Entity-attribute-value_model" rel="nofollow noreferrer">Entity-Attribute-Value</a> design.</p> <p>A more recognizable EAV table looks like the following:</p> <pre><code>CREATE TABLE vehicleEAV ( vid INTEGER, attr_name VARCHAR(20...
950,928
How to specify Windows credentials in WCF client configuration file
<p>I have a WCF service using BasicHttpBinding with Windows authentication. Most clients are domain accounts and connect to the service using their default credentials.</p> <p>Now I want to connect to the service from an ASP.NET client that is running under a local account. I want to connect to the WCF service using ...
950,966
6
0
null
2009-06-04 14:23:39.73 UTC
6
2016-06-01 01:57:50.07 UTC
2012-03-01 18:41:41.147 UTC
null
13,087
null
13,087
null
1
25
wcf|credentials
65,938
<p>You can't specify your credentials in the config file, unfortunately - you have to do this in code (most likely because otherwise you might end up with credentials in your config file, in plain text - not a good thing....).</p>
468,993
Is there a way to enable the JavaScript Error/Debug Console for Safari within Android?
<p>I'm developing a JavaScript application that needs to run on the Google Android Phone OS. Is there a way to enable the JavaScript Error/Debug console within Safari on either the Android Emulator or an actual device? If so any instructions on how to do so would be appreciated.</p>
487,622
6
0
null
2009-01-22 12:52:33.457 UTC
16
2018-01-10 05:34:29.047 UTC
2009-01-27 05:56:26.313 UTC
Soviut
46,914
Kevin
2,723
null
1
43
javascript|android|safari
27,718
<p>A quick Google turns up this <a href="https://web.archive.org/web/20120413212614/http://www.nanaze.com/2009/01/debugging-javascript-on-android.html" rel="noreferrer">blog post</a> (posted after you asked your question), that should at least let you see any Javascript errors via the Android Debug Bridge using the com...
17,733,509
$ is not defined - asp.net MVC 4
<p>With this code below, I get an error: <code>$ is not defined</code>. My question is: How it is possible? </p> <pre><code>... &lt;script type="text/javascript"&gt; $(document).ready(function () { $(function () { $('#cb').click(function () { if (this.checked) { ...
17,733,652
3
0
null
2013-07-18 20:42:41.197 UTC
3
2017-01-13 14:17:29.14 UTC
null
null
null
null
1,503,095
null
1
29
jquery|asp.net-mvc
62,313
<p>You've placed your script in the view body and not inside the <code>Scripts</code> section which is where it belongs and <strong>after</strong> referencing jQuery:</p> <pre><code>@section Scripts { @Scripts.Render("~/Scripts/jquery-1.7.1.min.js") @Scripts.Render("~/Scripts/jquery-ui-1.8.20.min.js") @Scr...
46,990,995
On Android 8.1 API 27 notification does not display
<p>I get Toast on Android 8.1 API 27: </p> <blockquote> <p>Developer warning for package "my_package_name"<br> Failed to post notification on ...</p> </blockquote> <p>Logcat includes next strings:</p> <blockquote> <p>Notification: Use of stream types is deprecated for operations other than volume control </...
46,991,229
4
3
null
2017-10-28 14:50:49.387 UTC
16
2018-12-29 08:35:35.107 UTC
2017-12-15 06:04:13.413 UTC
null
6,829,540
null
6,829,540
null
1
41
android|notifications|android-notifications|android-8.0-oreo
50,094
<p>If you get this error should be paid attention to 2 items and them order:</p> <ol> <li><code>NotificationChannel mChannel = new NotificationChannel(id, name, importance);</code></li> <li><code>builder = new NotificationCompat.Builder(context, id);</code></li> </ol> <p>Also NotificationManager notifManager and Noti...
46,914,025
Node exits without error and doesn't await promise (Event callback)
<p>I've got a really weird issue whereby awaiting a Promise that has passed its <code>resolve</code> to an event-emitter callback just exits the process without error. </p> <pre><code>const {EventEmitter} = require('events'); async function main() { console.log("entry"); let ev = new EventEmitter(); let task ...
46,916,601
3
5
null
2017-10-24 15:07:45.67 UTC
10
2021-05-11 20:35:46.863 UTC
2019-01-24 10:44:12.783 UTC
null
1,657,476
null
1,657,476
null
1
35
javascript|node.js|promise
8,684
<p>This question is basically: how does node decide whether to exit the event loop or go around again?</p> <p>Basically node keeps a reference count of scheduled async requests — <code>setTimeouts</code>, network requests, etc.. Each time one is scheduled, that count increases, and each time one is finished, the count...
1,846,077
Size of empty UDP and TCP packet?
<p>What is the size of an empty UDP datagram? And that of an empty TCP packet?</p> <p>I can only find info about the MTU, but I want to know what is the "base" size of these, in order to estimate bandwidth consumption for protocols on top of them.</p>
1,846,139
5
5
null
2009-12-04 10:21:01.857 UTC
14
2022-06-20 06:11:18.05 UTC
2018-06-04 20:04:23.397 UTC
null
212,378
null
134,763
null
1
34
tcp|udp|size
93,962
<p><strong>TCP:</strong></p> <p>Size of Ethernet frame - 24 Bytes<br> Size of IPv4 Header (without any options) - 20 bytes<br> Size of TCP Header (without any options) - 20 Bytes </p> <p>Total size of an Ethernet Frame carrying an IP Packet with an empty TCP Segment - 24 + 20 + 20 = 64 bytes</p> <p><strong>UDP:</st...
1,645,230
Rails Migrations: Check Existence and Keep Going?
<p>I was doing this kind of thing in my migrations:</p> <pre><code>add_column :statuses, :hold_reason, :string rescue puts "column already added" </code></pre> <p>but it turns out that, <strong>while this works for SQLite, it does not work for PostgreSQL</strong>. It seems like if the add_column blows up, <strong>eve...
5,958,436
5
2
null
2009-10-29 17:12:12.537 UTC
14
2021-01-21 07:48:00.437 UTC
null
null
null
null
8,047
null
1
88
ruby-on-rails|migration
36,453
<p>As of Rails 3.0 and later, you can use <a href="http://apidock.com/rails/ActiveRecord/ConnectionAdapters/SchemaStatements/column_exists%3F" rel="noreferrer"><code>column_exists?</code></a> to check for the existance of a column.</p> <pre><code>unless column_exists? :statuses, :hold_reason add_column :statuses, :h...
2,183,503
Substitute values in a string with placeholders in Scala
<p>I have just started using Scala and wish to better understand the functional approach to problem solving. I have pairs of strings the first has placeholders for parameter and it's pair has the values to substitute. e.g. "select col1 from tab1 where id > $1 and name like $2" "parameters: $1 = '250', $2 = 'some%'"</p>...
2,185,067
6
1
null
2010-02-02 11:12:26.72 UTC
11
2022-08-11 10:41:36.43 UTC
null
null
null
null
264,264
null
1
17
scala|functional-programming
16,901
<p>Speaking strictly to the replacement problem, my preferred solution is one enabled by a feature that should probably be available in the upcoming Scala 2.8, which is the ability to replace regex patterns using a function. Using it, the problem can be reduced to this:</p> <pre><code>def replaceRegex(input: String, v...
2,195,568
How do I add slashes to a string in Javascript?
<p>Just a string. Add \' to it every time there is a single quote.</p>
2,195,580
8
3
null
2010-02-03 21:24:31.7 UTC
6
2016-09-15 08:03:18.81 UTC
2016-09-15 08:03:18.81 UTC
null
1,045,444
null
179,736
null
1
41
javascript|jquery|formatting|string-formatting|backslash
141,049
<p><code>replace</code> works for the first quote, so you need a tiny regular expression:</p> <pre><code>str = str.replace(/'/g, "\\'"); </code></pre>
2,161,634
How to check if element has any children in Javascript?
<p>Simple question, I have an element which I am grabbing via <code>.getElementById ()</code>. How do I check if it has any children?</p>
2,161,646
8
0
null
2010-01-29 11:43:30.72 UTC
35
2021-02-09 16:11:17.767 UTC
2015-10-12 19:19:12.96 UTC
null
2,619,939
null
175,562
null
1
145
javascript|dom
220,379
<p>A couple of ways:</p> <pre><code>if (element.firstChild) { // It has at least one } </code></pre> <p>or the <code>hasChildNodes()</code> function:</p> <pre><code>if (element.hasChildNodes()) { // It has at least one } </code></pre> <p>or the <code>length</code> property of <code>childNodes</code>:</p> <pre><...
1,470,768
How to escape apostrophe or quotes on a JSP (used by JavaScript)
<p>I have a user form. If the user types in a string with <code>'</code> or <code>"</code> as part of it I have no problem. The form is submitted and saved correctly to the database. My problem is when I reload the page (all entries can be modified and are loaded into a list in the JSP before being displayed). On loadi...
1,473,192
9
4
null
2009-09-24 10:01:52.923 UTC
13
2021-12-20 02:05:49.937 UTC
2015-05-04 16:35:50.147 UTC
null
63,550
null
174,292
null
1
36
java|javascript|forms|jsp|escaping
86,710
<p>Use the Apache <a href="https://commons.apache.org/proper/commons-lang/javadocs/api-2.6/org/apache/commons/lang/StringEscapeUtils.html#escapeJavaScript(java.lang.String)" rel="noreferrer">StringEscapeUtils.escapeJavaScript</a> function.</p> <blockquote> <pre><code>Escapes the characters in a String using JavaScript...
1,396,718
Generic Key/Value pair collection in that preserves insertion order?
<p>I'm looking for something like a Dictionary&lt;K,V&gt; however with a guarantee that it preserves insertion order. Since Dictionary is a hashtable, I do not think it does.</p> <p>Is there a generic collection for this, or do I need to use one of the old .NET 1.1 collections?</p>
1,396,743
9
0
null
2009-09-08 22:42:41.89 UTC
7
2018-11-21 00:25:23.29 UTC
null
null
null
null
1,965
null
1
44
c#|.net|data-structures
35,453
<p>There is not. However, <a href="http://msdn.microsoft.com/en-us/library/system.collections.specialized.ordereddictionary.aspx" rel="noreferrer">System.Collections.Specialized.OrderedDictionary</a> should solve most need for it.</p> <p>EDIT: Another option is to turn this into a Generic. I haven't tested it but it c...
1,793,119
Could not find a base address that matches scheme net.tcp
<p>I have moved my file transfer service from basicHttpBinding to netTcpBinding as I am trying to set up a duplex mode channel. I have also started my net.tcp port sharing service.</p> <p>I am currently in dev and am self hosting on an xp box until we move the app to a dev server. so, for now, I do not have access t...
1,793,146
10
2
null
2009-11-24 21:43:32.05 UTC
6
2021-03-08 08:40:20.25 UTC
2009-11-25 11:46:54.527 UTC
null
150,510
null
150,510
null
1
34
c#|wcf|duplex|net.tcp
75,011
<p>You need to define just the <strong>base address</strong> (not the <strong>whole</strong> address) for your service, and then the rest in the service endpoint. The address you have with the <code>filetransfer.svc</code> file at the end is not a valid base address (it's a file address, really)</p> <pre><code>&lt;ser...
1,935,918
PHP substring extraction. Get the string before the first '/' or the whole string
<p>I am trying to extract a substring. I need some help with doing it in PHP.</p> <p>Here are some sample strings I am working with and the results I need: </p> <pre><code>home/cat1/subcat2 =&gt; home test/cat2 =&gt; test startpage =&gt; startpage </code></pre> <p>I want to get the string till the first <code>/</c...
1,935,929
13
1
null
2009-12-20 14:07:02.017 UTC
38
2020-10-03 12:43:17.84 UTC
2010-09-02 08:21:05.047 UTC
anon355079
null
anon355079
null
null
1
207
php|string|substring
361,287
<p>Use <a href="http://php.net/explode"><code>explode()</code></a></p> <pre><code>$arr = explode("/", $string, 2); $first = $arr[0]; </code></pre> <p>In this case, I'm using the <code>limit</code> parameter to <code>explode</code> so that php won't scan the string any more than what's needed.</p>
1,594,917
What features should Java 7 onwards have to encourage switching from C#?
<p>C# has a good momentum at the moment. What are the features that you would <em>need</em> to have in order to switch (or return) to Java?</p> <p>It would also be quite useful if people posted workarounds for these for the current Java versions, e.g. Nullables being wrapped around custom classes, to make this a much ...
1,595,050
24
8
null
2009-10-20 14:15:33.327 UTC
11
2010-09-10 21:32:26.947 UTC
null
null
null
null
182,094
null
1
24
c#|java|programming-languages|language-features
3,065
<p>As a .NET/C# developer here are the missing features that annoy me. This list in no particular order - just as thoughts come to mind:</p> <ol> <li>The Java library is too small. For common things I have to choose between 5 competing open source products because the base library is lacking in so many ways.</li> <li>...
33,687,496
Get fullUrl in laravel 5.1
<p>i have multiple bootstrap tabs where each one do different action from others tabs for exmaple </p> <p><code>app-url/users#creat-admin-users-tab</code> <code>app-url/users#creat-regular-users-tab</code> </p> <p><strong>Is there any way in Laravel to get full url including the #tab-name</strong></p> <p>Thanks for ...
33,902,542
3
2
null
2015-11-13 07:07:48.71 UTC
8
2016-10-24 15:43:17.833 UTC
2015-11-13 07:46:29.573 UTC
null
3,516,962
null
3,144,496
null
1
31
php|laravel|laravel-5|laravel-routing
45,819
<p>Check the following</p> <p><code>$_SERVER['HTTP_HOST'] =&gt; Host name from the current request.</code> </p> <p><code>$_SERVER['HTTP'] =&gt; Set to a non-empty value if the protocol is HTTP</code></p> <p><code>$_SERVER['HTTPS'] =&gt; Set to a non-empty value if the protocol is HTTPS</code></p> <p><code>$_SERVE...
18,090,672
Convert dictionary entries into variables
<p>Is there a Pythonic way to assign the values of a dictionary to its keys, in order to convert the dictionary entries into variables? I tried this out:</p> <pre><code>&gt;&gt;&gt; d = {'a':1, 'b':2} &gt;&gt;&gt; for key,val in d.items(): exec('exec(key)=val') exec(key)=val ...
18,647,701
7
6
null
2013-08-06 21:17:42.243 UTC
42
2021-11-29 05:49:39.157 UTC
2021-11-28 22:07:08.837 UTC
null
6,243,352
null
2,635,863
null
1
89
python|dictionary
98,674
<p>This was what I was looking for:</p> <pre><code>&gt;&gt;&gt; d = {'a':1, 'b':2} &gt;&gt;&gt; for key,val in d.items(): exec(key + '=val') </code></pre>
18,135,551
How to call python script on excel vba?
<p>Trying to call a python script on Vba and I am a newb. I tried converting the main script to an exe using py2exe and then calling it from VBA (shell) but the main script calls other scripts therefore it becomes complicated and I messed it up (my exe is not functional). Besides, the the main script is a large file an...
18,135,876
11
2
null
2013-08-08 20:31:35.767 UTC
37
2022-06-23 13:51:55.68 UTC
2021-08-27 20:32:42.157 UTC
null
3,739,391
null
2,665,094
null
1
40
python|excel|vba|shell|py2exe
161,655
<p>Try this:</p> <pre><code>RetVal = Shell("&lt;full path to python.exe&gt; " &amp; "&lt;full path to your python script&gt;") </code></pre> <p>Or if the python script is in the same folder as the workbook, then you can try :</p> <pre><code>RetVal = Shell("&lt;full path to python.exe&gt; " &amp; ActiveWorkBook.Path ...
6,934,477
How can i get DataGridView row values and store in variables?
<p>How can i loop through a DataGridView's rows at a time (I have 2 columns) then store those 2 columns in a variable which I will be using as a parameter for an sql query?</p> <pre><code> foreach (DataGridViewRow Datarow in contentTable_grd.Rows) { contentValue1 = Datarow.Cells[0].Value.T...
6,934,705
3
6
null
2011-08-03 23:20:38.527 UTC
1
2011-08-03 23:56:45.18 UTC
2011-08-03 23:47:48.03 UTC
null
52,249
null
541,408
null
1
7
c#|datagridview
53,516
<p>Found the problem I needed an if statement to prevent empty cells from going through</p> <pre><code> foreach (DataGridViewRow Datarow in contentTable_grd.Rows) { if (Datarow.Cells[0].Value != null &amp;&amp; Datarow.Cells[1].Value != null) { contentValue1 = Datarow.Cells[0].Value....
6,671,232
Youtube api - stop video
<p>I need some help with Youtube API and embeded videos. I want to stop video when clicked on some element (div,link,td etc.). I am trying to get it work just for 1 video now, but the final function of this script should be to stop all videos loaded on current page. I have read thru the YT API documentation but Im real...
6,671,815
3
2
null
2011-07-12 21:15:05.54 UTC
1
2012-07-25 09:01:47.773 UTC
null
null
null
null
841,585
null
1
9
javascript|api|video|youtube
60,752
<p>You can't control it if you embed it with an iframe. You have to use object embedding, like this:</p> <pre><code>&lt;object id="ytplayer" style="height: 390px; width: 640px"&gt; &lt;param name="movie" value="http://www.youtube.com/v/8Ax-dAR3ABs?version=3&amp;enablejsapi=1"&gt; &lt;param name="allowScriptAcc...
15,568,159
How to get FB User ID using Facebook Login Button in android application
<p>I'm developing an application in which I'm using <code>Facebook</code> log in button from SDK. I'm able to get <code>access_token</code> of the user but I want <code>userID</code> too. I have tried almost everything but was not successful. I have used facebook tutorial for achieving that. Here is the link: <a href=...
15,570,742
8
0
null
2013-03-22 10:32:09.92 UTC
5
2017-10-04 03:31:16.413 UTC
2013-07-01 04:36:16.31 UTC
null
964,741
null
1,321,290
null
1
11
android|facebook|facebook-android-sdk
41,818
<p>After successful login, you need to call following code. You can get the logged-in user details with id in response.</p> <pre><code>Session session = Session.getActiveSession(); Request request = Request.newGraphPathRequest(session, "me", null); com.facebook.Response response = Request.executeAndWait(request) </cod...