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
4,480,363
Android Java UTF-8 HttpClient Problem
<p>I am having weird character encoding issues with a JSON array that is grabbed from a web page. The server is sending back this header: </p> <p>Content-Type text/javascript; charset=UTF-8</p> <p>Also I can look at the JSON output in Firefox or any browser and Unicode characters display properly. The response will sometimes contain words from another language with accent symbols and such. However I am getting those weird question marks when I pull it down and put it to a string in Java. Here is my code:</p> <pre><code>HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, "utf-8"); params.setBooleanParameter("http.protocol.expect-continue", false); HttpClient httpclient = new DefaultHttpClient(params); HttpGet httpget = new HttpGet("http://www.example.com/json_array.php"); HttpResponse response; try { response = httpclient.execute(httpget); if(response.getStatusLine().getStatusCode() == 200){ // Connection was established. Get the content. HttpEntity entity = response.getEntity(); // If the response does not enclose an entity, there is no need // to worry about connection release if (entity != null) { // A Simple JSON Response Read InputStream instream = entity.getContent(); String jsonText = convertStreamToString(instream); Toast.makeText(getApplicationContext(), "Response: "+jsonText, Toast.LENGTH_LONG).show(); } } } catch (MalformedURLException e) { Toast.makeText(getApplicationContext(), "ERROR: Malformed URL - "+e.getMessage(), Toast.LENGTH_LONG).show(); e.printStackTrace(); } catch (IOException e) { Toast.makeText(getApplicationContext(), "ERROR: IO Exception - "+e.getMessage(), Toast.LENGTH_LONG).show(); e.printStackTrace(); } catch (JSONException e) { Toast.makeText(getApplicationContext(), "ERROR: JSON - "+e.getMessage(), Toast.LENGTH_LONG).show(); e.printStackTrace(); } private static String convertStreamToString(InputStream is) { /* * To convert the InputStream to String we use the BufferedReader.readLine() * method. We iterate until the BufferedReader return null which means * there's no more data to read. Each line will appended to a StringBuilder * and returned as String. */ BufferedReader reader; try { reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); } catch (UnsupportedEncodingException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } StringBuilder sb = new StringBuilder(); String line; try { while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } } catch (IOException e) { e.printStackTrace(); } finally { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } return sb.toString(); } </code></pre> <p>As you can see, I am specifying UTF-8 on the InputStreamReader but every time I view the returned JSON text via Toast it has strange question marks. I am thinking that I need to send the InputStream to a byte[] instead?</p> <p>Thanks in advance for any help.</p>
4,480,517
5
0
null
2010-12-18 21:50:48.94 UTC
12
2015-12-03 01:43:42.303 UTC
null
null
null
null
547,276
null
1
16
java|android|httpclient
31,483
<p>Try this:</p> <pre><code>if (entity != null) { // A Simple JSON Response Read // InputStream instream = entity.getContent(); // String jsonText = convertStreamToString(instream); String jsonText = EntityUtils.toString(entity, HTTP.UTF_8); // ... toast code here } </code></pre>
14,534,767
How to append a newline to StringBuilder
<p>I have a <a href="http://docs.oracle.com/javase/8/docs/api/java/lang/StringBuilder.html"><code>StringBuilder</code></a> object,</p> <pre><code>StringBuilder result = new StringBuilder(); result.append(someChar); </code></pre> <p>Now I want to append a newline character to the <code>StringBuilder</code>. How can I do it?</p> <pre><code>result.append("/n"); </code></pre> <p>Does not work. So, I was thinking about writing a newline using Unicode. Will this help? If so, how can I add one?</p>
14,534,798
7
2
null
2013-01-26 07:13:35.42 UTC
37
2021-02-02 17:29:15.033 UTC
2014-08-11 16:41:24.677 UTC
null
1,073,386
null
844,872
null
1
273
java|stringbuilder
481,774
<p>It should be </p> <pre><code>r.append("\n"); </code></pre> <p>But I recommend you to do as below,</p> <pre><code>r.append(System.getProperty("line.separator")); </code></pre> <p><code>System.getProperty("line.separator")</code> gives you system-dependent newline in java. Also from Java 7 there's a method that returns the value directly: <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/System.html#lineSeparator%28%29" rel="noreferrer"><code>System.lineSeparator()</code></a> </p>
14,725,969
How to count every checked checkboxes
<p>Here is my code :</p> <p>It actually count checked checkboxes and write it inside <code>&lt;span class="counter"&gt;&lt;/span&gt;</code>. This code works on Firefox, but not on Chrome.</p> <p>On Chrome, the .select_all check all checkboxes I want, but doesn't update the counter. Actually counter get updated when I uncheck the .select_all, which is weird.</p> <p>IMPORTANT FACT: I don't want to count the .Select_all checkboxes inside my .counter</p> <pre><code>jQuery(document).ready(function($){ $(function() { $('#general i .counter').text(' '); var generallen = $("#general-content input[name='wpmm[]']:checked").length; if(generallen&gt;0){$("#general i .counter").text('('+generallen+')');}else{$("#general i .counter").text(' ');} }) $("#general-content input:checkbox").on("change", function() { var len = $("#general-content input[name='wpmm[]']:checked").length; if(len&gt;0){$("#general i .counter").text('('+len+')');}else{$("#general i .counter").text(' ');} }); $(function() { $('.select_all').change(function() { var checkthis = $(this); var checkboxes = $(this).parent().next('ul').find("input[name='wpmm[]']"); if(checkthis.is(':checked')) { checkboxes.attr('checked', true); } else { checkboxes.attr('checked', false); } }); }); }); </code></pre> <p>EDIT: Here is a example document of the code : <a href="http://jsfiddle.net/8PVDy/1/">http://jsfiddle.net/8PVDy/1/</a></p>
14,726,294
7
6
null
2013-02-06 09:49:35.98 UTC
6
2020-12-31 09:19:44.917 UTC
2016-02-03 13:31:02.683 UTC
user57508
null
null
2,046,287
null
1
29
javascript|jquery|checkbox
106,319
<p>You can use a function to update the counter :</p> <pre><code>function updateCounter() { var len = $(&quot;#general-content input[name='wpmm[]']:checked&quot;).length; if(len &gt; 0){ $(&quot;#general i .counter&quot;).text('('+len+')'); } else { $(&quot;#general i .counter&quot;).text(' '); } } </code></pre> <p>and call this function when a checkbox's state is changed (including the selectAll checkboxes)</p> <p>Here is an updated jsFiddle : <a href="http://jsfiddle.net/8PVDy/4/" rel="nofollow noreferrer">http://jsfiddle.net/8PVDy/4/</a></p>
14,535,485
How to turn off a weird "box" cursor and selection behavior in Netbeans?
<p>I have some kind of weird behavior in Netbeans. I guess I accidentally entered some key combination which messed up the cursor and selection behavior. In the image you'll see what I mean: normally, if you select text across multiple lines, you'll see the behavior on the right screenshot.</p> <p>But I have the behavior on the left screenshot. Also, trying to insert text at a certain position with Shift, inserts it some positions to the right (= not where the cursor is). Additionally, when the cursor blinks, it appears dashed.</p> <p><img src="https://i.stack.imgur.com/TUmvv.png" alt="Netbeans comparison"></p> <p>The fact that the selection in the left screenshot is drawn nicely doesn't make me think of a bug, but rather of a feature. I can't seem to find the key combination to turn it off again. </p> <p>So my question is, what is this feature? Why does it exist and with what key combination did I turn it on?</p>
14,535,622
3
0
null
2013-01-26 09:15:33.43 UTC
10
2019-04-08 18:03:39.73 UTC
2017-03-30 15:59:26.93 UTC
null
472,495
null
704,335
null
1
81
netbeans
30,822
<p>One possibility is you have <a href="http://plugins.netbeans.org/PluginPortal/faces/PluginDetailPage.jsp?pluginid=1174" rel="noreferrer">the Rectangular Selection plugin</a> installed.</p> <p>However, the more likely candidate is the <a href="https://blogs.oracle.com/netbeansphp/entry/rectangular_selection" rel="noreferrer">rectangular selection feature</a> in the editor core. Find the button on your edit toolbar, and toggle it off. As per helpful comments below, this can accidentally be switched on (and toggled back off again) using:</p> <ul> <li>On Windows and Linux: <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>R</kbd></li> <li>On Mac: <kbd>Shift</kbd> + <kbd>Meta</kbd> + <kbd>R</kbd></li> <li>On Mac, if the above does not work: some folks have reported that <kbd>Shift</kbd> + <kbd>Command</kbd> + <kbd>R</kbd> worked for them</li> </ul>
14,544,221
How to enable Ad Hoc Distributed Queries
<p>When I run a query with <code>OPENROWSET</code> in SQL Server 2000 it works.</p> <p>But the same query in SQL Server 2008 generates the following error:</p> <blockquote> <p>SQL Server blocked access to STATEMENT 'OpenRowset/OpenDatasource' of component 'Ad Hoc Distributed Queries' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of <strong>'Ad Hoc Distributed Queries'</strong> by using <strong>sp_configure</strong></p> </blockquote>
14,544,245
4
4
null
2013-01-27 03:48:05.43 UTC
32
2017-01-27 14:41:43.247 UTC
2013-01-27 04:06:40.617 UTC
null
61,305
null
1,816,372
null
1
118
sql|sql-server-2008
246,728
<p>The following command may help you..</p> <pre><code>EXEC sp_configure 'show advanced options', 1 RECONFIGURE GO EXEC sp_configure 'ad hoc distributed queries', 1 RECONFIGURE GO </code></pre>
2,805,172
What are the js recursion limits for Firefox, Chrome, Safari, IE, etc?
<p>I've got some Javascript code which uses fairly deep recursion and I'd like to find out what the recursion limits in the various browsers are (i.e. the point at which the error "too much recursion" will happen).</p> <p>Anyone have any solid numbers on this, by version?</p>
2,805,230
2
0
null
2010-05-10 18:06:53.723 UTC
9
2019-02-22 00:05:31.853 UTC
null
null
null
null
50,505
null
1
41
javascript|recursion
19,973
<p><a href="http://www.nczonline.net/blog/2009/05/19/javascript-stack-overflow-error/" rel="noreferrer">Nicholas C. Zakas writes in his blog</a>:</p> <blockquote> <ul> <li>Internet Explorer 7: 1,789</li> <li>Firefox 3: 3,000</li> <li>Chrome 1: 21,837</li> <li>Opera 9.62: 10,000</li> <li>Safari 3.2: 500</li> </ul> </blockquote> <p>There's some more data on different browsers and OSs <a href="https://web.archive.org/web/20110128022845/http://www.javascriptrules.com/2009/06/30/limitation-on-call-stacks/" rel="noreferrer">here</a>.</p> <p>I've created a Browserscope test to get more data. <a href="http://adamrich.name/recursion.html" rel="noreferrer">Please run it here</a>.</p> <h3>Update:</h3> <p>The results above are now obsolete, but <a href="http://adamrich.name/recursion.html" rel="noreferrer">the browserscope results</a> are updated :</p> <ul> <li>IE 11: 12,064</li> <li>Firefox 65: 20,614</li> <li>Chrome 72: 9,643</li> <li>Opera 57: 9,638</li> <li>Safari 12: 32,035</li> </ul>
3,118,968
SessionTimeout: web.xml vs session.maxInactiveInterval()
<p>I'm trying to timeout an <em>HttpSession</em> in Java. My container is WebLogic.</p> <p>Currently, we have our session timeout set in the <em>web.xml</em> file, like this </p> <pre><code>&lt;session-config&gt; &lt;session-timeout&gt;15&lt;/session-timeout&gt; &lt;/session-config&gt; </code></pre> <p>Now, I'm being told that this will terminate the session (or is it all sessions?) in the 15th minute of use, regardless their activity.</p> <p>I'm wondering if this approach is the correct one, or should I programatically set the time limit of inactivity by </p> <pre><code>session.setMaxInactiveInterval(15 * 60); //15 minutes </code></pre> <p>I don't want to drop all sessions at 15 minutes, only those that have been inactive for 15 minutes.</p> <p>Are these methods equivalent? Should I favour the <em>web.xml</em> config?</p>
3,119,074
2
0
null
2010-06-25 14:51:16.983 UTC
25
2016-02-11 06:16:28.563 UTC
2013-07-06 19:18:22.827 UTC
null
814,702
null
63,309
null
1
65
java|session|servlets|weblogic|session-timeout
112,994
<blockquote> <p>Now, i'm being told that this will terminate the session (or is it all sessions?) in the 15th minute of use, <em>regardless their activity</em>.</p> </blockquote> <p>This is <strong>wrong</strong>. It will just kill the session when the associated client (webbrowser) has not accessed the website for more than 15 minutes. The activity certainly counts, exactly as you initially expected, seeing your attempt to solve this.</p> <p>The <a href="http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpSession.html#setMaxInactiveInterval%28int%29" rel="noreferrer"><code>HttpSession#setMaxInactiveInterval()</code></a> doesn't change much here by the way. It does exactly the same as <code>&lt;session-timeout&gt;</code> in <code>web.xml</code>, with the only difference that you can change/set it programmatically during runtime. The change by the way only affects the current session instance, not globally (else it would have been a <code>static</code> method).</p> <hr /> <p>To play around and experience this <em>yourself</em>, try to set <code>&lt;session-timeout&gt;</code> to 1 minute and create a <a href="http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpSessionListener.html" rel="noreferrer"><code>HttpSessionListener</code></a> like follows:</p> <pre><code>@WebListener public class HttpSessionChecker implements HttpSessionListener { public void sessionCreated(HttpSessionEvent event) { System.out.printf(&quot;Session ID %s created at %s%n&quot;, event.getSession().getId(), new Date()); } public void sessionDestroyed(HttpSessionEvent event) { System.out.printf(&quot;Session ID %s destroyed at %s%n&quot;, event.getSession().getId(), new Date()); } } </code></pre> <p><em>(if you're not on Servlet 3.0 yet and thus can't use <code>@WebListener</code>, then register in <code>web.xml</code> as follows)</em>:</p> <pre class="lang-xml prettyprint-override"><code>&lt;listener&gt; &lt;listener-class&gt;com.example.HttpSessionChecker&lt;/listener-class&gt; &lt;/listener&gt; </code></pre> <p>Note that the servletcontainer won't immediately destroy sessions after <em>exactly</em> the timeout value. It's a background job which runs at certain intervals (e.g. 5~15 minutes depending on load and the servletcontainer make/type). So don't be surprised when you don't see <code>destroyed</code> line in the console immediately after exactly one minute of inactivity. However, when you fire a HTTP request on a timed-out-but-not-destroyed-yet session, it will be destroyed immediately.</p> <h3>See also:</h3> <ul> <li><a href="https://stackoverflow.com/questions/3106452/how-do-servlets-work-instantiation-session-variables-and-multithreading/3106909#3106909">How do servlets work? Instantiation, sessions, shared variables and multithreading</a></li> </ul>
19,284,270
django template if or statement
<p>Basically to make this quick and simple, I'm looking to run an XOR conditional in django template. Before you ask why don't I just do it in the code, this isn't an option. </p> <p>Basically I need to check if a user is in one of two many-to-many objects.</p> <pre><code>req.accepted.all </code></pre> <p>and </p> <pre><code>req.declined.all </code></pre> <p>Now they can only be in one or the other (hence the XOR conditional). From the looking around on the docs the only thing I can figure out is the following</p> <pre><code>{% if user.username in req.accepted.all or req.declined.all %} </code></pre> <p>The problem I'm having here is that if user.username does indeed appear in req.accepted.all then it escapes the conditional but if it's in req.declined.all then it will follow the conditional clause.</p> <p>Am I missing something here?</p>
19,284,388
2
0
null
2013-10-09 23:01:29.857 UTC
3
2018-03-05 09:48:21.557 UTC
2013-10-10 00:37:19.177 UTC
null
1,459,786
null
1,459,786
null
1
39
python|django|if-statement|django-templates|xor
75,380
<p><code>and</code> has higher precedence than <code>or</code>, so you can just write the decomposed version:</p> <pre><code>{% if user.username in req.accepted.all and user.username not in req.declined.all or user.username not in req.accepted.all and user.username in req.declined.all %} </code></pre> <p>For efficiency, using <code>with</code> to skip reevaluating the querysets:</p> <pre><code>{% with accepted=req.accepted.all declined=req.declined.all username=user.username %} {% if username in accepted and username not in declined or username not in accepted and username in declined %} ... {% endif %} {% endwith %} </code></pre>
27,135,185
How can I specify the minimum SDK in phonegap? It is ignoring android-minsdkversion in config.xml
<p>This is a phonegap 3.5 / cordova 3 android app. In www/config.xml I have:</p> <pre><code>&lt;preference name="android-minSdkVersion" value="19"&gt; &lt;preference name="android-targetSdkVersion" value="19"&gt; </code></pre> <p>However, when I build it, it creates an AndroidManifest.xml with:</p> <pre><code>&lt;uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" /&gt; </code></pre> <p>The result is that people with SDK versions below 19 can install my app from the store. Where is it getting that 10 from and how can I change it? Due to weirdness with Viewport, my app's behavior is suspect on OSes below 4.4 and I am already getting 1-star reviews from 4.2.2 users.</p>
27,137,393
6
0
null
2014-11-25 19:36:21.677 UTC
8
2019-12-13 14:28:40.527 UTC
null
null
null
null
928,144
null
1
42
cordova|cordova-3.5
78,544
<p>With older version of cordova CLI, I used to modify manually <code>AndroidManifest.xml</code> to change a few settings (launch mode, minsdk...) like you do in your answer.</p> <p>And with <strong>Cordova 3.5.<em>something</em></strong> things started to go wrong, and some changes were lost each time I built the project.</p> <p>Now I added those lines in <code>config.xml</code> and the settings are updated automatically :</p> <pre><code>&lt;platform name="android"&gt; &lt;preference name="AndroidLaunchMode" value="singleTop"/&gt; &lt;preference name="android-minSdkVersion" value="14" /&gt; &lt;icon src="res/android/xhdpi.png" /&gt; &lt;icon src="res/android/ldpi.png" density="ldpi" /&gt; &lt;icon src="res/android/mdpi.png" density="mdpi" /&gt; &lt;icon src="res/android/hdpi.png" density="hdpi" /&gt; &lt;icon src="res/android/xhdpi.png" density="xhdpi" /&gt; &lt;/platform&gt; </code></pre> <p>The advantage is that I can now delete the android platform and recreate it without loosing any setting.</p> <p>As Phonegap is being updated to be inline with cordova, preferences in <code>config.xml</code> should work with the new version, and maybe you will see your manual updated be lost like it happened to me...</p>
57,291,304
Vue, Vuetify is not properly initialized
<p>I have setup <code>Vuetify</code> on my <code>Vue</code> webpack application.</p> <p>My project is setup with <code>vue init webpack my-project</code> running <code>Vue 2.5.2</code> and using <code>Vuetify 2.0.2</code>.</p> <p>I have installed <code>Vuetify</code> in my <code>App.js</code></p> <pre><code>import Vue from 'vue' import '../node_modules/vuetify/dist/vuetify.min.css'; import App from './App' import router from './router' import store from './store' import Vuetify from 'vuetify' Vue.use(Vuetify) /* eslint-disable no-new */ new Vue({ el: '#app', router, store, render: h =&gt; h(App) }) </code></pre> <p>Everything seems to be working fine. I'm able to call <code>Vuetify</code>components in one of my components.</p> <pre><code>&lt;template&gt; &lt;v-container&gt; &lt;v-card width="400" height="150" raised&gt; &lt;h4&gt;Hello&lt;/h4&gt; &lt;/v-card&gt; &lt;/v-container&gt; &lt;/template&gt; </code></pre> <p>I then read that I need to wrap my <code>App.js</code> with the v-app component, but when I do that I get an error saying: <code>Error: Vuetify is not properly initialized</code>.</p> <pre><code>&lt;template&gt; &lt;div id="app"&gt; &lt;v-app&gt; &lt;NavigationBar /&gt; &lt;v-content&gt; &lt;router-view /&gt; &lt;/v-content&gt; &lt;/v-app&gt; &lt;/div&gt; &lt;/template&gt; </code></pre> <p>Maybe <code>Vuetify</code> isn't installed correctly, I hope some of you can bring some light on my issue.</p>
59,445,948
8
0
null
2019-07-31 12:58:13.717 UTC
11
2021-08-10 05:59:14.77 UTC
2019-07-31 13:04:42.577 UTC
user11717245
null
null
10,652,658
null
1
21
javascript|vue.js|vuetify.js
43,495
<p>There is lot of changes with new version.</p> <p>try this</p> <pre><code>import Vue from 'vue'; import Vuetify from 'vuetify'; Vue.use(Vuetify); new Vue({ vuetify : new Vuetify(), ... }); </code></pre> <p>good luck</p>
48,098,288
Properly use Async calls with Angular 5
<p>I have been googling for a few days and found many different scenarios about how to use Async API calls with Angular 5 ( or 2-3-4, whatever ).</p> <p>Can anyone give me some correct example ( some good use-case ) about it?</p> <p>ex.</p> <ul> <li>making an API call using ( async - try - catch )</li> <li>how to 'subscribe' to that call in a Component level</li> </ul> <p>Thank You !</p>
48,098,667
1
0
null
2018-01-04 15:18:35.913 UTC
12
2018-12-31 05:25:14.89 UTC
null
null
null
null
7,097,236
null
1
11
angular|asynchronous|async-await
32,872
<p>I will give you an asnwer based on <strong>my opinion</strong> and <strong>how I learnt</strong>. So don't take it for the absolute truth, but rather question it ! </p> <p>First, you should know that in Typescript, there's two ways of making async calls : <strong>Promises</strong> and <strong>Observables</strong>. </p> <p>Promises are native in ES6, Observables are part of Rx JS. </p> <h1>But which one to use ?</h1> <p>Since it's my opinion, I will tell you to use <strong>Observables</strong>, because</p> <ul> <li>They can be stopped</li> <li>They can be played again</li> <li>They have lot of useful operators</li> <li>They can handle several values</li> </ul> <p>All of this, Promises can't do. </p> <h1>Making an API call</h1> <h2>Import the module</h2> <p>Very simple : first, you need to import the module responsible for that : </p> <pre><code>import { HttpClientModule } from '@angular/common/http'; // ... imports: [HttpClientModule] </code></pre> <p>This is the <strong>new and improved http service in Angular 5</strong>. I highly recommend you to use it, since the older one (<code>Http</code>) will soon be obsolete. </p> <h2>Use the HttpClient service</h2> <p>Now, in your services, you can use the <code>HttpClient</code> like so </p> <pre><code>import { HttpClient } from '@angular/common/http'; // ... constructor( private http: HttpClient ) {} // ... getAny(): Observable&lt;any&gt; { return this.http.get&lt;any&gt;('url'); // request options as second parameter } </code></pre> <h2>Use the business service</h2> <p>In your component, you can now do</p> <pre><code>import { MyService } from '../myservice/myservice.service'; // .. constructor(private myService: MyService) { this.myService.getAny().subscribe(() =&gt; {}); } // .. </code></pre> <h1>Complementary information</h1> <h2>Handling errors or loaders</h2> <p>Say you want to show a progress bar, or handle errors : to do that, you will have to use <strong>Interceptors</strong>. Interceptors are services that will catch your request before (or after) sending it, and will do something. </p> <p>Here is a simple interceptor for errors : </p> <pre><code>import { Injectable } from '@angular/core'; import { HttpInterceptor, HttpHandler, HttpRequest, HttpEvent, HttpResponse } from '@angular/common/http'; import { Observable } from 'rxjs/Observable'; @Injectable() export class ErrorHandlerService implements HttpInterceptor { constructor() { } intercept(req: HttpRequest&lt;any&gt;, next: HttpHandler): Observable&lt;HttpEvent&lt;any&gt;&gt; { return next .handle(req) .catch(err =&gt; { console.log('error occured'); return Observable.throw(err); }); } } </code></pre> <p>To use it, simply provide it with your value in your module : </p> <pre><code>providers: [ { provide: HTTP_INTERCEPTORS, useClass: ErrorHandlerService, multi: true } ] </code></pre> <p>I think you guessed, but you can use it to handle progress bars also ;) </p> <h2>Subscribing to an Observable and using async</h2> <p>As you've seen before, you can subscribe to an http call. </p> <p>If you want to handle specific errors and do some logic in your component, here is how : </p> <pre><code>myService.getAny().subscribe( responseAfterSuccess =&gt; {}, responseAfterError =&gt; {} ); </code></pre> <p>With this code, you will handle the success and the error. </p> <p>Last thing, the <strong>async pipe</strong> : the async pipe transforms an Observable into data. To use it, do so </p> <pre><code>this.myVar = myService.getAny(); </code></pre> <p>Your variable <code>myVar</code> will contain an Observable. Now, in your HTML, with this </p> <pre><code>&lt;div *ngFor="let item of myVar | async"&gt;{{ item }}&lt;/div&gt; </code></pre> <p>Angular will wiat for data to arrive before displaying anything, and will transform the Observable into data, as if you did it by hand. </p>
42,719,803
VSTS - prevent push to master but allow PR merge
<p>We have branch policies set up in VSTS to prevent pull requests being merged into master unless a build passes and work items are linked. However, I can't work out how to prevent developers pushing directly to master. Setting the "Contribute" permission to Deny does not allow pull requests to be merged.</p> <p>All developers should be allowed to merge PRs into master but none should be permitted to push directly to master. Is this possible?</p>
42,725,044
3
0
null
2017-03-10 13:41:21.54 UTC
null
2021-06-14 16:56:53.177 UTC
null
null
null
null
5,219,693
null
1
47
git|tfs|azure-devops
34,797
<p><a href="https://docs.microsoft.com/en-us/vsts/repos/git/branch-policies?view=vsts" rel="noreferrer">Branch policies</a> already do exactly what you're saying. When a branch policy is in place, PRs are required.</p> <p>Make sure your developers don't have the "Exempt From Policy Enforcement" permission.</p>
21,136,225
Is there any Node.js client library to make OAuth and OAuth2 API calls to Twitter, Facebook, Google, LinkedIn, etc.?
<p>I did a lot of googling and the best I could find was: <a href="https://github.com/ciaranj/node-oauth" rel="noreferrer">https://github.com/ciaranj/node-oauth</a></p> <p>Are there any libraries on top of this, which provide wrappers to make API calls to Twitter, Facebook, Google, LinkedIn, etc. to say post a tweet or DM somebody or get friends list or post a link to Facebook/G+ et al.?</p> <p>I'm aware of Passport.js, but its usage is limited to obtaining authentication and authorization from these social sites. Beyond that, currently we will have to individualize API calls via node-oauth to perform activities mentioned above.</p> <p>Have I missed something? Are you aware of any such libraries?</p>
21,166,211
3
0
null
2014-01-15 11:28:42.333 UTC
8
2016-08-09 14:13:59.91 UTC
2016-08-01 23:16:18.977 UTC
null
63,550
null
88,159
null
1
13
javascript|node.js|oauth|oauth-2.0|twitter-oauth
17,353
<p>Once you have used <a href="http://passportjs.org/" rel="noreferrer">Passport.js</a> to obtain an access token, I recommend (and personally use) <a href="https://github.com/mikeal/request" rel="noreferrer">request</a> to make all API calls to third-party services.</p> <p>In my opinion, provider-specific wrappers just add unnecessary complication. Most RESTful APIs are very simple HTTP requests. Extra layers only get in the way and add bugs to track down. Further, by sticking with <code>request</code>, you can integrate with <em>any</em> third party using the same, familiar module.</p>
26,372,729
Setting view value an input field in a unit test of an angular form directive
<p>I have a directive that builds a form:</p> <pre><code>app.directive('config', function() { return { restrict: 'E', scope: { data: '=' }, template: '&lt;form name="configForm"&gt;' + '&lt;input type="number" max="10" ng-model="config.item" name="configItem"/&gt;' + '&lt;div class="form-error" ng-show="configForm.$error.max"&gt;Error&lt;/div&gt;' + '&lt;/form&gt;', controller: 'ConfigDirectiveController', }; }); </code></pre> <p>What I want to do is validate via a unit test that the error message will show up given some input. With angular 1.2 I could modify $scope.config.item and it would update the view value and show the error.</p> <p>As near as I can tell, with angular 1.3, if the model does not pass validation the view value does not get updated...so I need to modify the view value to make sure the error message shows up.</p> <p>How can I get access to the "configItem" input so that I can set the view value to ensure that the error message will show up?</p> <p><strong>Edited to show unit test</strong></p> <p>I see that the value is set properly, but the error still has an ng-hide applied to the tag. When I am viewing the page and manually changing the input value, the ng-hide will be removed and the error will display if I enter in something greater than 10.</p> <pre><code> beforeEach(inject(function($compile, $rootScope) { element = angular.element('&lt;config data="myData"&gt;&lt;/config&gt;'); $scope = $rootScope.$new(); $scope.myData = {}; element = $compile(element)($scope); })); it('should warn that we have a large number', function() { var input = element.find('[name="configItem"]')[0]; $scope.$apply(function() { angular.element(input).val('9000000001'); }); errors = element.find('[class="form-error ng-binding"]'); expect(errors.length).toBe(1); }) </code></pre>
26,376,249
2
0
null
2014-10-15 00:48:54.857 UTC
8
2015-07-08 11:42:55.783 UTC
2014-10-16 14:14:30.09 UTC
null
1,392,862
null
1,392,862
null
1
34
angularjs|unit-testing|angular-directive
30,709
<p>Here's how I've been unit testing my input-based directives (Lots of code omitted for clarity!) The important line you are after is:</p> <pre><code>angular.element(dirElementInput).val('Some text').trigger('input'); </code></pre> <p>Here's the full unit test:</p> <pre><code> it('Should show a red cross when invalid', function () { dirElement = angular.element('&lt;ng-form name="dummyForm"&gt;&lt;my-text-entry ng-model="name"&gt;&lt;/my-text-entry&gt;&lt;/ng-form&gt;'); compile(dirElement)(scope); scope.$digest(); // Find the input control: var dirElementInput = dirElement.find('input'); // Set some text! angular.element(dirElementInput).val('Some text').trigger('input'); scope.$apply(); // Check the outcome is what you expect! (in my case, that a specific class has been applied) expect(dirElementInput.hasClass('ng-valid')).toEqual(true); }); </code></pre>
44,882,176
Set column names in pandas data frame from_dict with orient = 'index'
<p>I looked already at this question: <a href="https://stackoverflow.com/questions/20340844/pandas-create-named-columns-in-dataframe-from-dict/32280888">pandas create named columns in dataframe from dict</a>. However, my example is slightly different.</p> <p>I have a dictionary: <code>my_dict = {'key1' : [1,2,3], 'key2' : [4,5,6], 'key3' :[7,8,9]}</code></p> <p>And I created a pandas dataframe: <code>df = pd.DataFrame.from_dict(my_dict, orient='index')</code>, which is row oriented. However, when writing <code>columns = ['one', 'two', 'three']</code> I get an error, as in the link above.</p> <p>How do I name them?</p>
44,882,285
3
1
null
2017-07-03 09:32:40.197 UTC
3
2020-05-26 10:30:03.9 UTC
2018-08-01 13:30:29.21 UTC
null
604,687
null
6,435,921
null
1
28
python|dictionary|key
65,046
<p>Is there a reason you can't set the column names on the next line?</p> <pre><code>my_dict = {'key1' : [1,2,3], 'key2' : [4,5,6], 'key3' :[7,8,9]} df = pd.DataFrame.from_dict(my_dict, orient='index') df.columns = ['one', 'two', 'three'] </code></pre> <p>Should work.</p>
7,454,946
How to create multiple apps from same shared code in Xcode?
<p>I'm developing 2 different apps that share 95% of the same code and views. What is the best way to go about this using Xcode?</p>
7,454,969
1
0
null
2011-09-17 13:01:40.733 UTC
10
2011-09-17 14:50:33.377 UTC
2011-09-17 14:50:33.377 UTC
null
90,413
null
34,548
null
1
19
iphone|ios|xcode|ipad
6,742
<p>Use targets. That's exactly what they are for.</p> <p><a href="http://developer.apple.com/library/ios/#featuredarticles/XcodeConcepts/Concept-Targets.html" rel="noreferrer">Learn more about the concept of targets here</a>.</p> <p>Typically, the majority of projects have a single Target, which corresponds to one product/application. If you define multiple targets, you can:</p> <ul> <li>include some of your source code files (or maybe all) in both targets, some in one target and some in the other</li> <li>you can play with Build Settings to compile the two targets using different settings.</li> </ul> <hr> <p>For example you may define Precompiler Macros for one target and other macros for the other (let's say <code>OTHER_C_FLAGS = -DPREMIUM</code> in target "PremiumVersion" and <code>OTHER_C_FLAGS = -DLITE</code> to define the <code>LITE</code> macro in the "LiteVersion" target) and then include similar code in your source:</p> <pre><code>-(IBAction)commonCodeToBothTargetsHere { ... } -(void)doStuffOnlyAvailableForPremiumVersion { #if PREMIUM // This code will only be compiled if the PREMIUM macro is defined // namely only when you compile the "PremiumVersion" target .... // do real stuff #else // This code will only be compiled if the PREMIUM macro is NOT defined // namely when you compile the "LiteVersion" target [[[[UIAlertView alloc] initWithTitle:@"Only for premium" message:@"Sorry, this feature is reserved for premium users. Go buy the premium version on the AppStore!" delegate:self cancelButtonTitle:@"Doh!" otherButtonTitles:@"Go buy it!",nil] autorelease] show]; #endif } -(void)otherCommonCodeToBothTargetsHere { ... } </code></pre>
24,763,743
Simulator error FBSSystemServiceDomain code 4
<p>I'm trying to run an app in the simulator but get this error message:</p> <pre><code>Unable to run app in Simulator An error was encountered while running (Domain = FBSSystemServiceDomain, Code = 4) </code></pre> <p><img src="https://i.stack.imgur.com/U5pHD.png" alt="Screenshot for error"></p> <p>I've not seen any previous references to this from googling around.</p> <p>Its using XCode 6 Beta, the app is in Swift which links to a Obj-C static library. It runs fine on the device.</p> <p>Any ideas?</p>
24,765,397
6
0
null
2014-07-15 16:45:01.843 UTC
32
2016-04-22 20:53:35.353 UTC
2014-11-14 05:57:57.537 UTC
null
1,753,005
null
1,082,219
null
1
230
ios|ios-simulator|xcode6|ios8.1
48,885
<p>Go to the iOS Simulator menu and select Reset Content and Settings.</p> <p>Alternatively, you could quit and reopen the Simulator.</p> <p><img src="https://i.stack.imgur.com/AnjIX.png" alt="enter image description here"></p>
38,863,345
iOS: How to detect if a user is subscribed to an auto-renewable subscription
<p>Hopefully the title is self-explanatory. I'm trying to do something like this:</p> <pre><code>checkIfUserIsSubscribedToProduct(productID, transactionID: "some-unique-transaction-string", completion: { error, status in if error == nil { if status == .Subscribed { // do something fun } } } </code></pre> <p>does anything like the hypothetical code I've provided exist? I feel like I'm taking crazy pills</p> <p><strong>Edit</strong></p> <p>In similar questions I keep seeing a generic answer of "oh you gotta validate the receipt" but no explanation on how, or even what a receipt is. Could someone provide me with how to "validate the receipt"? I tried <a href="https://developer.apple.com/library/ios/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateRemotely.html#//apple_ref/doc/uid/TP40010573-CH104-SW1">this tutorial</a> but didn't seem to work.</p> <p><strong>Edit - For Bounty</strong></p> <p>Please address the following situation: A user subscribes to my auto-renewable subscription and gets more digital content because of it - cool, implemented. But how do I check whether that subscription is still valid (i.e. they did not cancel their subscription) each time they open the app? <strong>What is the simplest solution to check this?</strong> Is there something like the hypothetical code I provided in my question? Please walk me through this and provide any further details on the subject that may be helpful.</p>
38,956,977
4
0
null
2016-08-10 02:30:59.307 UTC
11
2019-11-06 09:37:20.007 UTC
2016-08-14 23:26:11.33 UTC
null
3,063,560
null
3,063,560
null
1
40
ios|swift|storekit
14,386
<p>I know everyone was very concerned about me and how I was doing on this - fear not, solved my problem. Main problem was that I tried Apple's example code from the <a href="https://developer.apple.com/library/ios/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateRemotely.html#//apple_ref/doc/uid/TP40010573-CH104-SW1" rel="noreferrer">documentation</a>, but it wasn't working so I gave up on it. Then I came back to it and implemented it with <code>Alamofire</code> and it works great. Here's the code solution:</p> <p><strong>Swift 3:</strong></p> <pre><code>let receiptURL = Bundle.main.appStoreReceiptURL let receipt = NSData(contentsOf: receiptURL!) let requestContents: [String: Any] = [ "receipt-data": receipt!.base64EncodedString(options: []), "password": "your iTunes Connect shared secret" ] let appleServer = receiptURL?.lastPathComponent == "sandboxReceipt" ? "sandbox" : "buy" let stringURL = "https://\(appleServer).itunes.apple.com/verifyReceipt" print("Loading user receipt: \(stringURL)...") Alamofire.request(stringURL, method: .post, parameters: requestContents, encoding: JSONEncoding.default) .responseJSON { response in if let value = response.result.value as? NSDictionary { print(value) } else { print("Receiving receipt from App Store failed: \(response.result)") } } </code></pre>
49,885,795
Access Uint8Array in javascript ArrayBuffer
<p>I've got a javascript ArrayBuffer generated from a FileReader ReadAsArrayBuffer method on a jpeg file.</p> <p>I'm trying to access the UInt32 array of the ArrayBuffer and send to a WCF service (ultimately to be inserted into a database on the server). </p> <p>I've seen an example here on stackoverflow (<a href="https://i.stack.imgur.com/DoGMs.jpg" rel="noreferrer">byte array method</a>) where a UnInt32 array is converted to a byte array which I think would work.</p> <p>I'm trying to access the [[Uint8Array]] of my arrayBuffer variable below so I can send it to the WCF, but I'm not having much luck. I've tried:</p> <pre><code> var arrayBuffer = reader.result[[Uint8Array]];//nope var arrayBuffer = reader.result[Uint8Array];//nope var arrayBuffer = reader.result.Uint8Array;//nope var arrayBuffer = reader.result[1];//nope </code></pre> <p>Any ideas on how to access that [[Uint8Array]] would be appreciated. When the entire ArrayBuffer is sent to WCF Service I get a 0 byte array -- cant read it </p> <p>Thanks</p> <p>Pete</p> <p><a href="https://i.stack.imgur.com/DoGMs.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/DoGMs.jpg" alt="enter image description here"></a></p>
49,886,067
1
0
null
2018-04-17 19:11:23.773 UTC
2
2018-04-17 19:28:16.947 UTC
null
null
null
null
3,614,100
null
1
35
javascript|wcf|filereader
35,466
<p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer#Properties" rel="noreferrer">Those properties do not actually exist on the ArrayBuffer object</a>. They are put there by the Dev Tools window for viewing the ArrayBuffer contents.</p> <p>You need to actually create the TypedArray of your choice through its <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray#Syntax" rel="noreferrer">constructor syntax</a></p> <blockquote> <pre><code>new TypedArray(buffer [, byteOffset [, length]]); </code></pre> </blockquote> <p>So in your case if you want <code>Uint8Array</code> you would need to do:</p> <pre><code>var uint8View = new Uint8Array(arrayBuffer); </code></pre>
38,941,071
Kotlin: Can you use named arguments for varargs?
<p>For example, you might have function with a complicated signature and varargs:</p> <pre><code>fun complicated(easy: Boolean = false, hard: Boolean = true, vararg numbers: Int) </code></pre> <p>It would make sense that you should be able to call this function like so:</p> <pre><code>complicated(numbers = 1, 2, 3, 4, 5) </code></pre> <p>Unfortunately the compiler doesn't allow this.</p> <p>Is it possible to use named arguments for varargs? Are there any clever workarounds?</p>
38,941,244
4
0
null
2016-08-14 09:54:13.563 UTC
2
2018-02-20 05:05:26.263 UTC
null
null
null
null
1,938,929
null
1
38
function|kotlin|default-value|variadic-functions|named-parameters
14,261
<p>It can be worked around by moving optional arguments after the <code>vararg</code>:</p> <pre><code>fun complicated(vararg numbers: Int, easy: Boolean = false, hard: Boolean = true) = {} </code></pre> <p>Then it can be called like this:</p> <pre><code>complicated(1, 2, 3, 4, 5) complicated(1, 2, 3, hard = true) complicated(1, easy = true) </code></pre> <p>Note that trailing optional params need to be always passed with name. This won't compile:</p> <pre><code>complicated(1, 2, 3, 4, true, true) // compile error </code></pre> <p>Another option is to spare <code>vararg</code> sugar for explicit array param:</p> <pre><code>fun complicated(easy: Boolean = false, hard: Boolean = true, numbers: IntArray) = {} complicated(numbers = intArrayOf(1, 2, 3, 4, 5)) </code></pre>
54,876,820
How to disable button in vuejs
<p>I want to make the button disabled during the form filling when all the inputs are filled the button will be enabled using vuejs and on laravel framework</p> <p>I tried achive that by simply making the button disabled in the </p> <pre><code>&lt;button type="submit" class="btn btn-info" disabled&gt;Next&lt;/button&gt; </code></pre> <p>but i didn't know how to do it in vuejs</p>
54,876,874
5
0
null
2019-02-26 00:32:44.973 UTC
8
2022-07-15 01:05:28.147 UTC
null
null
null
null
11,053,834
null
1
43
laravel|vue.js
75,812
<p>Just bind the <code>disabled</code> attribute to a boolean value like</p> <pre><code>&lt;button :disabled='isDisabled'&gt;Send Form&lt;/button&gt; </code></pre> <p>as in <a href="https://jsfiddle.net/willywg/2g7m5qy5/" rel="noreferrer">this example</a></p>
36,691,118
Is it possible to show heap memory size in Intellij IDE (Android Studio)?
<p>I am searching for a way to display Heap Memory/force garbage collection.</p> <p>I have already tried to search through settings, however all I could gather was about setting JVM parameters in Android Studio config.</p> <p>Does Android Studio have such functionality?</p>
36,692,342
3
0
null
2016-04-18 10:16:05.487 UTC
4
2020-11-25 15:35:02.937 UTC
2020-11-25 15:32:23.667 UTC
null
1,788,806
null
5,691,018
null
1
73
android-studio|intellij-idea|heap-memory
49,153
<p>It's exist but not visible by default. go to Setting > Appearance &amp; Behavior > Appearance > In Window Option Segment > tick "Show memory indicator" and save setting.</p> <p><a href="https://i.stack.imgur.com/oWoNh.png" rel="noreferrer"><img src="https://i.stack.imgur.com/oWoNh.png" alt=""></a></p> <p>After that you can view memory indicator in bottom right corner, you can trigger garbage collector by click on memory bar.</p>
31,907,762
Pylint to show only warnings and errors
<p>I would like to use pylint to check my code but I am only interested in error and warning levels. Is there a way to do that in command line or in pylintrc?</p> <p>I am not interested in filtering given issues (like listing all messages in MESSAGE CONTROL), I just want pylint to ignore <strong>all</strong> convention and refactor messages.</p> <p>Note: I don't think that's a duplicate of <a href="https://stackoverflow.com/questions/20639173/using-pylint-to-display-error-and-warnings">Using Pylint to display error and warnings</a></p>
31,908,039
2
0
null
2015-08-09 18:57:13.52 UTC
14
2021-11-10 16:12:31.693 UTC
2017-05-23 10:31:29.113 UTC
null
-1
null
968,772
null
1
48
python|pylint
33,328
<p>Use the <code>-d</code> / <code>--disable</code> option to turn off the "C" and "R" message classes (convention and refactor):</p> <pre><code>-d &lt;msg ids&gt;, --disable=&lt;msg ids&gt; Disable the message, report, category or checker with the given id(s). You can either give multiple identifiers separated by comma (,) or put this option multiple times (only on the command line, not in the configuration file where it should appear only once).You can also use "--disable=all" to disable everything first and then reenable specific checks. For example, if you want to run only the similarities checker, you can use "--disable=all --enable=similarities". If you want to run only the classes checker, but have no Warning level messages displayed, use"--disable=all --enable=classes --disable=W" </code></pre> <p>Without the <code>disable</code> option (6 convention, 1 refactor, 2 warning, 1 error):</p> <pre><code>$ pylint x.py C: 1, 0: Missing module docstring (missing-docstring) C: 3, 0: Missing function docstring (missing-docstring) R: 3, 0: Too many statements (775/50) (too-many-statements) W:780,15: Redefining name 'path' from outer scope (line 796) (redefined-outer-name) C:780, 0: Invalid function name "getSection" (invalid-name) C:780, 0: Empty function docstring (empty-docstring) C:782,23: Invalid variable name "inPath" (invalid-name) W:785, 4: Statement seems to have no effect (pointless-statement) E:785, 4: Undefined variable 'something' (undefined-variable) C:796, 4: Invalid constant name "path" (invalid-name) </code></pre> <p>After using the <code>disable</code> option (0 convention, 0 refactor, 2 warning, 1 error):</p> <pre><code>$ pylint --disable=R,C x.py W:780,15: Redefining name 'path' from outer scope (line 796) (redefined-outer-name) W:785, 4: Statement seems to have no effect (pointless-statement) E:785, 4: Undefined variable 'something' (undefined-variable) </code></pre> <p>To set this option in <code>pylintrc</code>:</p> <pre><code>disable=R,C </code></pre>
47,792,212
What exactly is namespacing of modules in vuex
<p>I have recently started with <code>vuex</code>.</p> <p>The official <a href="https://vuex.vuejs.org/en/modules.html" rel="noreferrer"><code>docs</code></a> explains well what <em>modules</em> are but i am not sure if i understood the <em>namespaces</em> in modules right.</p> <p>Can anybody put some light on namespaces in a better way? <em>When/why</em> to use it?</p> <p>Much appreciated.</p>
47,792,484
4
0
null
2017-12-13 11:45:34.2 UTC
6
2021-03-31 02:04:00.873 UTC
null
null
null
null
3,094,731
null
1
29
javascript|vue.js|vuex
17,474
<p>When you have a big app with a very large state object, you will often divide it into <a href="https://vuex.vuejs.org/en/modules.html" rel="noreferrer">modules</a>.</p> <p>Which basically means you break the state into smaller pieces. One of the caveats is that you can't use the same method name for a module since it is integrated into the same state, so for example:</p> <pre><code>moduleA { actions:{ save(){} } } moduleB { actions:{ //this will throw an error that you have the same action defined twice save(){} } } </code></pre> <p>So in order to enable this you have the option to define the module as namespaced, and then you can use the same method in different modules:</p> <pre><code>moduleA { actions:{ save(){} }, namespaced: true } moduleB { actions:{ save(){} }, namespaced: true } </code></pre> <p>and then you call it like this:</p> <pre><code>this.$store.dispatch('moduleA/save') this.$store.dispatch('moduleB/save') </code></pre> <p>Please note that it might complicate things a bit if you're using <code>mapGetter</code> or <code>mapActions</code> since the getters are now in the form of <code>['moduleA/client']</code></p> <p>So use it only if you really need to.</p>
24,808,661
Make div 100% Width of Browser Window
<p>I'm trying to make one of my containers 100% of the width of the screen.</p> <p>Here is my SASS</p> <pre><code>body, html { width: 100%; height: 100%; padding: 0; margin: 0; } #neo_wrapper { width: 960px; height: 1500px; margin: 0 auto; #neo_main_container1 { /* Slide1 container */ width: 100%; height: 100%; margin: 0 auto; background: #999999; z-index: 350; #neo_scroll_button { /* Div that enables scroll */ position: absolute; bottom: 35px; left: 0; right: 0; margin: 0 auto; width: 150px; height: 15px; background: #F00; color: #FFF; text-align: center; line-height: 15px; display: table; a { &amp;:link {text-decoration: none; color: #FFF;} &amp;:visited {text-decoration: none; color: #FFF;} } } } #neo_main_container2 { width: 100%; height: 100%; margin: 0 auto; background: #CCC; z-index: 300; #neo_img_container { float: left; width: 350px; height: 500px; margin: 0 auto; margin-right: 15px; } #neo_text_container { float: left; width: 50%; height: 500px; margin: 0 auto; } } } </code></pre> <p>And HTML </p> <pre><code>&lt;body&gt; &lt;div id="neo_wrapper"&gt; &lt;div id="neo_main_container1"&gt; &lt;!-- Start container1 --&gt; &lt;div id="neo_scroll_button" onClick="scrollBelow()"&gt; &lt;p&gt;Enter&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;!-- End of container1 --&gt; &lt;div id="neo_main_container2"&gt; &lt;!-- Start container2 --&gt; &lt;div id="neo_img_container"&gt; &lt;img src="http://fpoimagery.com/?t=px&amp;w=350&amp;h=250&amp;bg=0ff&amp;fg=000000" /&gt; &lt;/div&gt; &lt;div id="neo_text_container"&gt; &lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;!-- End container2 --&gt; &lt;/div&gt; </code></pre> <p></p> <p>I want #neo_main_container1 to be the full width of the screen. Obviously because it's a child of #neo_wrapper, setting width to 100% will make it 960px. I'm sure how to circumvent this issue, so any help would be appreciated.</p> <p>Updated: Here is my JS fiddle: <a href="http://jsfiddle.net/VkqjH/" rel="noreferrer">http://jsfiddle.net/VkqjH/</a></p>
24,808,717
5
0
null
2014-07-17 16:15:49.78 UTC
7
2020-05-05 15:58:02.25 UTC
2014-07-17 18:10:43.88 UTC
null
2,161,288
null
2,161,288
null
1
22
html|css|sass|fullscreen
158,763
<p>There are new units that you can use:</p> <p><code>vw</code> - viewport width</p> <p><code>vh</code> - viewport height</p> <pre><code>#neo_main_container1 { width: 100%; //fallback width: 100vw; } </code></pre> <p><a href="http://snook.ca/archives/html_and_css/vm-vh-units" rel="noreferrer">Help</a> / <a href="https://developer.mozilla.org/en/docs/Web/CSS/length#Viewport-percentage_lengths" rel="noreferrer">MDN</a></p> <p>Opera Mini does not support this, but you can use it in all other modern browsers.</p> <p><a href="http://caniuse.com/viewport-units" rel="noreferrer">CanIUse</a></p> <p><a href="https://i.stack.imgur.com/Y0FIA.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Y0FIA.png" alt="enter image description here"></a></p>
28,760,966
Mixed language framework
<p>I have a framework (let's call it MyKit) written in Objective-C that I'm extending with some Swift classes. I'm trying to get my head around it using this documentation: <a href="https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html#//apple_ref/doc/uid/TP40014216-CH10-XID_77">https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html#//apple_ref/doc/uid/TP40014216-CH10-XID_77</a></p> <p>As far as I understand, I'm not supposed to have a bridging header class, and instead put all my includes in the umbrella header file (that I understand to be ).</p> <p>So I write in MyKit.h:</p> <pre><code>#import &lt;MyKit/ModelObjectA.h&gt; #import &lt;MyKit/ModelObjectB.h&gt; #import &lt;MyKit/ControllerObjectC.h&gt; </code></pre> <p>I don't list ControllerObjectD.swift, even though it goes into here as well? Or should I include</p> <pre><code>#import &lt;MyKit/ControllerObjectD-Swift.h&gt; </code></pre> <p>?</p> <p>ControllerObjectD uses ModelObjectA and ModelObjectB. Now that I don't have a bridge headerfile, I get compile errors in it because it cannot find these objects.</p> <p>The documentation says "Swift will see every header you expose publicly in your umbrella header." and this is true when I import the framework into other projects, but the framework project cannot compile because it doesn't see it. I have turned on the "Define Modules" build setting.</p> <p>Is there something I've misunderstood about the umbrella header, perhaps? Where can I say "hi project, this is the umbrella header file"? The framework compiles if I set the umbrella header file as bridging header, but that sounds like I've come back to the beginning this way?</p> <p>Cheers</p> <p>Nik</p>
28,762,928
3
0
null
2015-02-27 08:56:34.387 UTC
10
2020-05-25 12:46:05.76 UTC
null
null
null
null
80,246
null
1
10
ios|objective-c|swift|frameworks
6,731
<p>I believe your problem may be down to the Access Modifiers in your Swift class, however I've written a short guide and sample project to help you:</p> <p>Sample project can be found <a href="https://github.com/elliott-minns/SwiftObjCTestFramework" rel="noreferrer">here</a></p> <p>There are two parts to having a mixed language framework: </p> <ol> <li>Importing Objective-C into Swift </li> <li>Importing Swift into Objective-C</li> </ol> <hr> <h1>1. Importing Objective-C into Swift</h1> <p>This is, for example, if you have an Objective-C class named <code>Player</code> that you want to add to a swift class called <code>Game</code>.</p> <p>According to the documentation, you need to do these two steps to import the <code>Player</code> object into the <code>Game</code> object.</p> <ol> <li>Under Build Settings, in Packaging, make sure the Defines Module setting for that framework target is set to Yes.</li> </ol> <p><img src="https://i.stack.imgur.com/U3UaW.png" alt="Defines Module"></p> <ol start="2"> <li><p>In your umbrella header file, import every Objective-C header you want to expose to Swift.</p> <pre><code>#import &lt;Framework/Player.h&gt; </code></pre></li> </ol> <p>Make sure your <code>Player</code> header file in Objective-C is marked for public target membership in the framework:</p> <p><img src="https://i.stack.imgur.com/WQVtA.png" alt="Public Header File Setting"></p> <p>Following these steps, it's possible to import the <code>Player</code> Objective-C class into the <code>Game</code> Swift Class:</p> <pre><code>import UIKit public class Game: NSObject { public let player: Player public init(player: Player) { self.player = player super.init(); } } </code></pre> <hr> <h1>2. Importing Swift into Objective-C</h1> <p>For importing the Swift <code>Game</code> class into the <code>Player</code> object, we can follow a similar procedure. </p> <ol> <li>As before; Under Build Settings, in Packaging, make sure the Defines Module setting for that framework target is set to Yes.</li> </ol> <p><img src="https://i.stack.imgur.com/U3UaW.png" alt="Defines Module"></p> <ol start="2"> <li><p>Import the Swift code from that framework target into any Objective-C .m file within that framework target using this syntax and substituting the appropriate names:</p> <pre><code>#import &lt;ProductName/ProductModuleName-Swift.h&gt; </code></pre> <p>In my case, this works as:</p> <pre><code>#import &lt;SwiftObjC/SwiftObjC-Swift.h&gt; </code></pre> <p>and I assume, for you:</p> <pre><code>#import &lt;MyKit/MyKit-Swift.h&gt; </code></pre> <p>Therefore, make sure that all the properties, methods and classes you want to access are defined as public in your swift file or else they won't be visible to Objective-C . </p></li> </ol> <p>I have uploaded my sample project showing how this all works on GitHub <a href="https://github.com/elliott-minns/SwiftObjCTestFramework" rel="noreferrer">https://github.com/elliott-minns/SwiftObjCTestFramework</a></p> <p>I hope this helps you with your problem.</p>
2,522,749
Updating data source on multiple pivot tables within Excel
<p>Is there an easy way to update the data source for multiple pivot tables on a single Excel sheet at the same time?</p> <p>All of the pivot tables reference the same named range, but I need to create a second worksheet that has the same pivot tables, but accessing a different named range.</p> <p>Ideally I would like to be able to do some kind of search and replace operation (like you can do on formulae), rather than updating each individual pivot table by hand.</p> <p>Any suggestions?</p>
2,524,227
4
0
null
2010-03-26 11:13:26.59 UTC
2
2020-02-14 12:54:23.44 UTC
null
null
null
null
38,900
null
1
7
excel|pivot-table
66,345
<p>The following VBA code will change the data source of all pivot tables on a single worksheet.</p> <p>You will need to update the <code>Sheet2</code> parameter to the name of the sheet with your new pivot tables and the <code>Data2</code> parameter to your new named range.</p> <pre class="lang-vb prettyprint-override"><code>Sub Change_Pivot_Source() Dim pt As PivotTable For Each pt In ActiveWorkbook.Worksheets("Sheet2").PivotTables pt.ChangePivotCache ActiveWorkbook.PivotCaches.Create _ (SourceType:=xlDatabase, SourceData:="Data2") Next pt End Sub </code></pre>
2,340,930
Stray '\342' in C++ program
<p>I'm getting these errors in my program after pasting in some code:</p> <pre class="lang-none prettyprint-override"><code>showdata.cpp:66: error: stray ‘\342’ in program showdata.cpp:66: error: stray ‘\200’ in program showdata.cpp:66: error: stray ‘\235’ in program showdata.cpp:66: error: stray ‘\’ in program showdata.cpp:66: error: stray ‘\342’ in program showdata.cpp:66: error: stray ‘\200’ in program showdata.cpp:66: error: stray ‘\235’ in program showdata.cpp:67: error: stray ‘\342’ in program showdata.cpp:67: error: stray ‘\200’ in program showdata.cpp:67: error: stray ‘\235’ in program showdata.cpp:67: error: stray ‘\’ in program showdata.cpp:67: error: stray ‘\342’ in program showdata.cpp:67: error: stray ‘\200’ in program showdata.cpp:67: error: stray ‘\235’ in program </code></pre> <p>Here are the two lines that are causing the errors.</p> <pre class="lang-c++ prettyprint-override"><code>size_t startpos = str.find_first_not_of(” \t”); size_t endpos = str.find_last_not_of(” \t”); </code></pre> <p>How can I fix this?</p>
2,340,942
4
3
null
2010-02-26 10:35:55.853 UTC
3
2021-03-06 21:11:53.593 UTC
2021-03-05 04:12:43.683 UTC
null
63,550
null
209,512
null
1
17
c++|compiler-errors
80,486
<p>The symbol <code>”</code> is not <code>"</code>. Those are called 'smart quotes' and are usually found in rich documents or blogs.</p>
2,528,039
Why is FLT_MIN equal to zero?
<p><code>limits.h</code> specifies limits for non-floating point math types, e.g. <code>INT_MIN</code> and <code>INT_MAX</code>. These values are the most negative and most positive values that you can represent using an int.</p> <p>In <code>float.h</code>, there are definitions for <code>FLT_MIN</code> and <code>FLT_MAX</code>. If you do the following:</p> <pre><code>NSLog(@"%f %f", FLT_MIN, FLT_MAX); </code></pre> <p>You get the following output:</p> <pre><code>FLT_MIN = 0.000000, FLT_MAX = 340282346638528859811704183484516925440.000000 </code></pre> <p><code>FLT_MAX</code> is equal to a really large number, as you would expect, but why does <code>FLT_MIN</code> equal zero instead of a really large negative number?</p>
2,528,046
4
6
null
2010-03-27 03:28:43.293 UTC
10
2021-05-25 21:40:18.287 UTC
2012-05-14 20:27:55.113 UTC
null
44,390
null
86,046
null
1
31
c|floating-point|numeric-limits
30,935
<p>It's not actually zero, but it might look like zero if you inspect it using <code>printf</code> or <code>NSLog</code> by using <code>%f</code>.<br> According to <code>float.h</code> (at least in Mac OS X 10.6.2), <code>FLT_MIN</code> is described as:</p> <pre><code>/* Minimum normalized positive floating-point number, b**(emin - 1). */ </code></pre> <p>Note the <em>positive</em> in that sentence: <code>FLT_MIN</code> refers to the minimum (normalized) number <em>greater than zero</em>. (There are much smaller non-normalized numbers).</p> <p>If you want the minimum floating point number (including negative numbers), use <code>-FLT_MAX</code>.</p>
3,046,001
What does "Document-oriented" vs. Key-Value mean when talking about MongoDB vs Cassandra?
<p>What does going with a document based NoSQL option buy you over a KV store, and vice-versa?</p>
3,076,781
4
2
null
2010-06-15 14:14:57.667 UTC
41
2021-08-20 12:34:54.723 UTC
2017-09-22 18:01:22.247 UTC
null
-1
null
304,435
null
1
153
mongodb|cassandra|nosql
53,465
<p>A <em>key-value store</em> provides the simplest possible data model and is exactly what the name suggests: it's a storage system that stores values indexed by a key. You're limited to query by key and the values are <strong>opaque</strong>, the store doesn't know <em>anything</em> about them. This allows very fast read and write operations (a simple disk access) and I see this model as a kind of non volatile cache (i.e. well suited if you need fast accesses by key to long-lived data).</p> <p>A <em>document-oriented database</em> extends the previous model and values are stored in a <em>structured</em> format (a document, hence the name) that the database can understand. For example, a document could be a blog post <strong>and</strong> the comments <strong>and</strong> the tags stored in a denormalized way. Since the data are <strong>transparent</strong>, the store can do more work (like indexing fields of the document) and you're not limited to query by key. As I hinted, such databases allows to fetch an entire page's data with a single query and are well suited for content oriented applications (which is why big sites like Facebook or Amazon like them).</p> <p>Other kinds of NoSQL databases include <em>column-oriented stores</em>, <em>graph databases</em> and even <em>object databases</em>. But this goes beyond the question.</p> <h3>See also</h3> <ul> <li><a href="http://nosql.mypopescu.com/post/659390374/comparing-document-databases-to-key-value-stores" rel="noreferrer">Comparing Document Databases to Key-Value Stores</a></li> <li><a href="http://blog.knuthaugen.no/2010/03/the-nosql-landscape.html" rel="noreferrer">Analysis of the NoSQL Landscape</a></li> </ul>
56,816,537
Can't find kaggle.json file in google colab
<p>I'm trying to download the kaggle imagenet object localization challenge data into google colab so that I can use it to train my model. Kaggle uses an API for easy and fast access to their datasets. (<a href="https://github.com/Kaggle/kaggle-api" rel="noreferrer">https://github.com/Kaggle/kaggle-api</a>) However, when calling the command "kaggle competitions download -c imagenet-object-localization-challenge" in google colab, it can't find the kaggle.json file which contains my username and api-key. </p> <p>I haven't had this problem on my mac when running a jupyter notebook, but since I want to use google's gpu for my model, I started using google colab. Because the kaggle API expects the username and api-key to be in a kaggle.json file located in a .kaggle directory, I first created the directory .kaggle and then the file kaggle.json, into which I wrote my username and api-key (The example below doesn't display my username and api-key). I then tried to configure the path to my json file for kaggle to use when calling the kaggle download command.</p> <pre class="lang-py prettyprint-override"><code>!pip install kaggle !mkdir .kaggle !touch .kaggle/kaggle.json api_token = {"username":"username","key":"api-key"} import json import zipfile import os with open('/content/.kaggle/kaggle.json', 'w') as file: json.dump(api_token, file) !chmod 600 /content/.kaggle/kaggle.json !kaggle config path -p /content </code></pre> <p>However, when running the last command, I got the error:</p> <pre><code>IOError: Could not find kaggle.json. Make sure it's located in /root/.kaggle. Or use the environment method. </code></pre> <p>My goal was to use the following commands to get the dataset from kaggle:</p> <pre><code>!kaggle competitions download -c imagenet-object-localization-challenge os.chdir('/content/competitions/imagenet-object-localization-challenge') for file in os.listdir(): zip_ref = zipfile.ZipFile(file, 'r') zip_ref.extractall() zip_ref.close() </code></pre> <p>I don't understand why the kaggle API can't find my json file. How can I use the API in google colab?</p>
56,819,431
6
0
null
2019-06-29 09:43:34.497 UTC
7
2022-06-17 14:53:30.423 UTC
null
null
null
null
11,692,276
null
1
29
python|google-colaboratory|kaggle
26,071
<p>As the error said, you need to put kaggle.json in the right place.</p> <p>Try:</p> <pre><code>!mv .kaggle /root/ </code></pre> <p>Then run your code again.</p>
36,343,556
How to use oauth2 to access StackExchange API?
<p>I'm following the instructions mentioned here: <a href="https://api.stackexchange.com/docs/authentication">https://api.stackexchange.com/docs/authentication</a></p> <p>But since there is no code provided, I'm not able to understand the flow correctly.</p> <p>I've been trying to get the authentication part done using two methods below but I have hit a deadend.</p> <h1>1)</h1> <pre><code>import requests from pprint import pprint resp = requests.get('https://stackexchange.com/oauth/dialog?client_id=6667&amp;scope=private_info&amp;redirect_uri=https://stackexchange.com/oauth/login_success/') pprint(vars(resp)) </code></pre> <h1>2)</h1> <pre><code>import oauth2 as oauth from pprint import pprint url = 'https://www.stackexchange.com' request_token_url = '%s/oauth/' % url access_token_url = '%s/' % url consumer = oauth.Consumer(key='mykey', secret='mysecret') client = oauth.Client(consumer) response, content = client.request(request_token_url, 'GET') print(response, content) </code></pre> <p>I'm not sure how to go forward from here? I need to use the access token that is returned and use it to query the API. A sample code would really really help! Thanks.</p> <p>EDIT: This is the code I'm using currently:</p> <pre><code>from requests_oauthlib import OAuth2Session from pprint import pprint client_id = 'x' client_secret = 'x' redirect_uri = 'https://stackexchange.com/oauth/login_success' scope = 'no_expiry' oauth = OAuth2Session(client_id, redirect_uri=redirect_uri, scope=scope) pprint(vars(oauth)) authorization_url, state = oauth.authorization_url('https://stackexchange.com/oauth/dialog') print(authorization_url) </code></pre> <p>Instead of having to click on the authorization_url and get the token, is there a way I can directly fetch the token within the script itself? </p>
36,345,455
2
1
null
2016-03-31 20:52:21.85 UTC
11
2021-09-19 03:14:41.117 UTC
2016-04-01 17:40:10.333 UTC
null
3,188,761
null
3,188,761
null
1
8
python|oauth-2.0|stackexchange-api
2,305
<p>Of the two methods you used, the first is the recommended method for desktop applications. It is probably correct.</p> <p>OAuth is intended to force the user to go to a specific webpage and acknowledge that they are giving permission (usually through clicking a button) for an application to access their data. The HTTP responses you print are merely the webpage where a user needs to click accept.</p> <p>To get a feeling for the flow, put the first address (<a href="https://stackexchange.com/oauth/dialog?client_id=6667&amp;scope=&amp;redirect_uri=https://stackexchange.com/oauth/login_success/">https://stackexchange.com/oauth/dialog?client_id=6667&amp;scope=&amp;redirect_uri=https://stackexchange.com/oauth/login_success/</a>) in the address bar and click accept on the loaded page. The <code>access_token</code> will be in the URL right after that.</p> <p>If you are making the application only for yourself, the <code>access_token</code> can be copied into your Python script. The token expires in one day; if that is too short add <code>no_expiry</code> to <code>scope</code> to make it last forever. DO NOT share the token with anyone else, since it gives them access to details of your account! Each user of the script must generate their own token.</p> <p>Test the <code>access_token</code> by inserting in your app's <code>key</code> and the <code>access_token</code> you just obtained into the url: <a href="https://api.stackexchange.com/2.2/me?key=key&amp;site=stackoverflow&amp;order=desc&amp;sort=reputation&amp;access_token=&amp;filter=default">https://api.stackexchange.com/2.2/me?key=key&amp;site=stackoverflow&amp;order=desc&amp;sort=reputation&amp;access_token=&amp;filter=default</a></p> <p>If you need a more automated, integrated, user-friendly solution, I would look at <a href="http://selenium-python.readthedocs.org/index.html" rel="nofollow noreferrer">selenium webdriver</a> to open a browser window and get the resulting credentials.</p>
2,984,994
iPhone UITableViewCell: repositioning the textLabel
<p>I am new to iPhone development and I am currently working on a simple RSS reader app. The problem I am having is that I need to reposition the <code>textLabel</code> inside the <code>UITableViewCells</code>. I have tried <code>setFrame</code> or <code>setCenter</code> but it doesn't do anything. Does anyone know what I need to do inside the <code>tableView:cellForRowAtIndexPath:</code> method to reposition the <code>textLabel</code> at the top of the cell (x = 0, y = 0)? </p> <p>Thank you</p> <p>PS: The <code>UITableViewCell</code> is referenced by a variable called <code>cell</code>. I have tried <code>[cell setFrame:CGRectMake(0, 0, 320, 20)]</code> with no success.</p>
3,525,764
5
0
null
2010-06-06 16:52:29.72 UTC
8
2017-10-24 19:00:32.923 UTC
2013-06-26 05:57:54.107 UTC
null
1,355,704
null
359,784
null
1
38
iphone|uitableview
33,492
<p>You can create a subclass for UITableViewCell and customize de textLabel frame. See that answer: <a href="https://stackoverflow.com/questions/1132029/labels-aligning-in-uitableviewcell/1139740#1139740">Labels aligning in UITableViewCell</a>. It's works perfectly to me.</p> <p>It's my subclass</p> <pre><code>#import "UITableViewCellFixed.h" @implementation UITableViewCellFixed - (void) layoutSubviews { [super layoutSubviews]; self.textLabel.frame = CGRectMake(0, 0, 320, 20); } @end </code></pre> <p>It's my UITableViewControllerClass:</p> <pre><code>UITableViewCellFixed *cell = (UITableViewCellFixed *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCellFixed alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } </code></pre>
3,009,543
Passing integers as constant references versus copying
<p>This might be a stupid question, but I notice that in a good number of APIs, a lot of method signatures that take integer parameters that aren't intended to be modified look like:</p> <p><code>void method(int x);</code></p> <p>rather than:</p> <p><code>void method(const int &amp;x);</code></p> <p>To me, it looks like both of these would <em>function</em> exactly the same. (EDIT: apparently not in some cases, see answer by R Samuel Klatchko) In the former, the value is copied and thus can't change the original. In the latter, a constant reference is passed, so the original can't be changed.</p> <p>What I want to know is why one over the other - is it because the performance is basically the same or even better with the former? e.g. passing a 16-bit value or 32-bit value rather than a 32-bit or 64-bit address? This was the only logical reason I could think of, I just want to know if this is correct, and if not, why and when one should prefer <code>int x</code> over <code>const int &amp;x</code> and vice versa.</p>
3,009,568
5
2
null
2010-06-09 20:12:51.097 UTC
22
2018-11-29 21:36:43 UTC
2018-11-29 21:36:43 UTC
null
397,817
null
343,845
null
1
70
c++
24,539
<p>It's not just the cost of passing a pointer (that's essentially what a reference is), but also the de-referencing in the called method's body to retrieve the underlying value.</p> <p>That's why passing an <code>int</code> by value will be virtually guaranteed to be faster (Also, the compiler can optimize and simply pass the <code>int</code> via processor registers, eliminating the need to push it onto the stack).</p>
2,358,684
Can I share a file descriptor to another process on linux or are they local to the process?
<p>Say I have 2 processes, ProcessA and ProcessB. If I perform <code>int fd=open(somefile)</code> in ProcessA, can I then pass the value of file descriptor <code>fd</code> over IPC to ProcessB and have it manipulate the same file?</p>
2,358,843
6
2
null
2010-03-01 20:05:31.68 UTC
18
2022-05-06 03:25:20.683 UTC
2010-03-01 20:30:29.72 UTC
null
126,769
null
272,934
null
1
66
c|linux
50,368
<p>You can pass a file descriptor to another process over <a href="http://en.wikipedia.org/wiki/Unix_domain_socket" rel="noreferrer">unix domain</a> sockets. Here's the code to pass such a file descriptor, taken from <a href="http://www.kohala.com/start/unpv12e.html" rel="noreferrer">Unix Network Programming</a></p> <pre><code>ssize_t write_fd(int fd, void *ptr, size_t nbytes, int sendfd) { struct msghdr msg; struct iovec iov[1]; #ifdef HAVE_MSGHDR_MSG_CONTROL union { struct cmsghdr cm; char control[CMSG_SPACE(sizeof(int))]; } control_un; struct cmsghdr *cmptr; msg.msg_control = control_un.control; msg.msg_controllen = sizeof(control_un.control); cmptr = CMSG_FIRSTHDR(&amp;msg); cmptr-&gt;cmsg_len = CMSG_LEN(sizeof(int)); cmptr-&gt;cmsg_level = SOL_SOCKET; cmptr-&gt;cmsg_type = SCM_RIGHTS; *((int *) CMSG_DATA(cmptr)) = sendfd; #else msg.msg_accrights = (caddr_t) &amp;sendfd; msg.msg_accrightslen = sizeof(int); #endif msg.msg_name = NULL; msg.msg_namelen = 0; iov[0].iov_base = ptr; iov[0].iov_len = nbytes; msg.msg_iov = iov; msg.msg_iovlen = 1; return(sendmsg(fd, &amp;msg, 0)); } /* end write_fd */ </code></pre> <p>And here's the code to receive the file descriptor</p> <pre><code>ssize_t read_fd(int fd, void *ptr, size_t nbytes, int *recvfd) { struct msghdr msg; struct iovec iov[1]; ssize_t n; int newfd; #ifdef HAVE_MSGHDR_MSG_CONTROL union { struct cmsghdr cm; char control[CMSG_SPACE(sizeof(int))]; } control_un; struct cmsghdr *cmptr; msg.msg_control = control_un.control; msg.msg_controllen = sizeof(control_un.control); #else msg.msg_accrights = (caddr_t) &amp;newfd; msg.msg_accrightslen = sizeof(int); #endif msg.msg_name = NULL; msg.msg_namelen = 0; iov[0].iov_base = ptr; iov[0].iov_len = nbytes; msg.msg_iov = iov; msg.msg_iovlen = 1; if ( (n = recvmsg(fd, &amp;msg, 0)) &lt;= 0) return(n); #ifdef HAVE_MSGHDR_MSG_CONTROL if ( (cmptr = CMSG_FIRSTHDR(&amp;msg)) != NULL &amp;&amp; cmptr-&gt;cmsg_len == CMSG_LEN(sizeof(int))) { if (cmptr-&gt;cmsg_level != SOL_SOCKET) err_quit("control level != SOL_SOCKET"); if (cmptr-&gt;cmsg_type != SCM_RIGHTS) err_quit("control type != SCM_RIGHTS"); *recvfd = *((int *) CMSG_DATA(cmptr)); } else *recvfd = -1; /* descriptor was not passed */ #else /* *INDENT-OFF* */ if (msg.msg_accrightslen == sizeof(int)) *recvfd = newfd; else *recvfd = -1; /* descriptor was not passed */ /* *INDENT-ON* */ #endif return(n); } /* end read_fd */ </code></pre>
2,873,249
Is memcached a dinosaur in comparison to Redis?
<p>I have worked quite a bit with memcached the last weeks and just found out about Redis. When I read this part of their readme, I suddenly got a warm, cozy feeling in my stomach:</p> <blockquote> <p>Redis can be used as a memcached on steroids because is as fast as memcached but with a number of features more. Like memcached, Redis also supports setting timeouts to keys so that this key will be automatically removed when a given amount of time passes.</p> </blockquote> <p>This sounds amazing. I'd also found this page with benchmarks: <a href="http://www.ruturaj.net/redis-memcached-tokyo-tyrant-mysql-comparison" rel="noreferrer">http://www.ruturaj.net/redis-memcached-tokyo-tyrant-mysql-comparison</a></p> <p>So, honestly - Is memcache really that old dinousaur that is a bad choice from a performance perspective when compared to this newcomer called Redis?</p> <p>I haven't heard lot about Redis previously, thereby the approach for my question!</p>
2,875,728
6
9
null
2010-05-20 11:35:17.583 UTC
139
2018-06-25 23:32:08.063 UTC
null
null
null
null
198,128
null
1
190
performance|memcached|redis
74,297
<p>Memcache is an excellent tool still and VERY reliable.</p> <p>instead of looking at this issue from the perspective getting down the who is faster at the &lt; 100 ms range, look at the performance per "class" of the software.</p> <ul> <li>Does it use only local ram? -> fastest</li> <li>Does it use remote ram? -> fast</li> <li>Does it use ram plus hardddisk -> oh hurm.</li> <li>Does it use only harddisk -> run!</li> </ul>
2,436,385
Android - getting from a Uri to an InputStream to a byte array?
<p>I'm trying to get from an Android Uri to a byte array. </p> <p>I have the following code, but it keeps telling me that the byte array is 61 bytes long, even though the file is quite large - so I think it may be turning the Uri <strong>string</strong> into a byte array, rather than the file :(</p> <pre><code> Log.d(LOG_TAG, "fileUriString = " + fileUriString); Uri tempuri = Uri.parse(fileUriString); InputStream is = cR.openInputStream(tempuri); String str=is.toString(); byte[] b3=str.getBytes(); Log.d(LOG_TAG, "len of data is " + imageByteArray.length + " bytes"); </code></pre> <p>Please can someone help me work out what to do?</p> <p>The output is "fileUriString = content://media/external/video/media/53" and "len of data is 61 bytes".</p> <p>Thanks!</p>
2,436,413
7
2
null
2010-03-12 22:46:05.967 UTC
10
2019-06-13 07:13:01.29 UTC
null
null
null
null
267,831
null
1
36
android
60,336
<p><code>is.toString()</code> will give you a String representation of the InputStream instance, not its content.</p> <p>You need to read() bytes from the InputStream into your array. There's two read methods to do that, <a href="http://developer.android.com/reference/java/io/InputStream.html#read%28%29" rel="noreferrer">read()</a> which reads a single byte at a time, and <a href="http://developer.android.com/reference/java/io/InputStream.html#read%28byte[]%29" rel="noreferrer">read(byte[] bytes)</a> which reads bytes from the InputStream into the byte array you pass to it. </p> <hr> <p>Update: to read the bytes given that an InputStream does not have a length as such, you need to read the bytes until there is nothing left. I suggest creating a method for yourself something like this is a nice simple starting point (this is how I would do it in Java at least).</p> <pre><code>public byte[] readBytes(InputStream inputStream) throws IOException { // this dynamically extends to take the bytes you read ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream(); // this is storage overwritten on each iteration with bytes int bufferSize = 1024; byte[] buffer = new byte[bufferSize]; // we need to know how may bytes were read to write them to the byteBuffer int len = 0; while ((len = inputStream.read(buffer)) != -1) { byteBuffer.write(buffer, 0, len); } // and then we can return your byte array. return byteBuffer.toByteArray(); } </code></pre>
2,338,942
Access a JavaScript variable from PHP
<p>I need to access a <strong>JavaScript</strong> variable with <strong>PHP</strong>. Here's a stripped-down version of the code I'm currently trying, which isn't working:</p> <pre><code>&lt;script type="text/javascript" charset="utf-8"&gt; var test = "tester"; &lt;/script&gt; &lt;?php echo $_GET['test']; ?&gt; </code></pre> <p>I'm a completely new to both JavaScript and PHP, so I would really appreciate any advice.</p> <p><strong>UPDATE</strong>: OK, I guess I simplified that too much. What I'm trying to do is create a form that will update a Twitter status when submitted. I've got the form working OK, but I want to also add geolocation data. Since I'm using Javascript (specifically, the Google Geolocation API) to get the location, how do I access that information with PHP when I'm submitting the form?</p>
2,338,960
9
1
null
2010-02-26 01:30:03.86 UTC
9
2021-08-10 09:21:10.387 UTC
2011-04-11 22:24:16.923 UTC
null
63,550
null
145,750
null
1
27
php|javascript|variables
149,813
<p>The short answer is <strong>you can't</strong>.</p> <p>I don't know any PHP syntax, but what I can tell you is that PHP is executed on the server and JavaScript is executed on the client (on the browser).</p> <p>You're doing a $_GET, which is used to <a href="http://www.w3schools.com/PHP/php_get.asp" rel="noreferrer">retrieve form values</a>:</p> <blockquote> <p>The built-in $_GET function is used to collect values in a form with method="get".</p> </blockquote> <p>In other words, if on your page you had:</p> <pre><code>&lt;form method="get" action="blah.php"&gt; &lt;input name="test"&gt;&lt;/input&gt; &lt;/form&gt; </code></pre> <p>Your $_GET call would retrieve the value in that input field.</p> <p>So how to retrieve a value from JavaScript?</p> <p>Well, you could stick the javascript value in a hidden form field...</p> <pre><code>&lt;script type="text/javascript" charset="utf-8"&gt; var test = "tester"; // find the 'test' input element and set its value to the above variable document.getElementByID("test").value = test; &lt;/script&gt; ... elsewhere on your page ... &lt;form method="get" action="blah.php"&gt; &lt;input id="test" name="test" visibility="hidden"&gt;&lt;/input&gt; &lt;input type="submit" value="Click me!"&gt;&lt;/input&gt; &lt;/form&gt; </code></pre> <p>Then, when the user clicks your submit button, he/she will be issuing a "GET" request to blah.php, sending along the value in 'test'.</p>
2,954,879
How Session Works?
<p>Any body can explain me how session works in PHP. for eg. 3 users logged into gmail. how the server identifies these 3 uers. what are the internel process behind that. </p>
2,954,903
9
0
null
2010-06-02 03:52:42.563 UTC
12
2016-12-09 22:28:49.133 UTC
2012-12-24 21:48:51.59 UTC
null
168,868
null
669,388
null
1
32
php|apache
20,620
<p>Sessions are made up of two components, a <strong>client-side session ID</strong> and <strong>server-side session data</strong>. Clients can send a session ID to the server as a URL param, cookie, or even HTTP headers. The server then uses this session ID to find the appropriate session data to return to the client.</p> <p>You can tweak session behavior via the various <a href="http://php.net/manual/en/ref.session.php" rel="noreferrer"><code>session_</code> functions</a>.</p>
2,710,940
Python `if x is not None` or `if not x is None`?
<p>I've always thought of the <code>if not x is None</code> version to be more clear, but Google's <a href="https://google.github.io/styleguide/pyguide.html?showone=True/False_evaluations#True/False_evaluations" rel="noreferrer">style guide</a> and <a href="https://www.python.org/dev/peps/pep-0008/#programming-recommendations" rel="noreferrer">PEP-8</a> both use <code>if x is not None</code>. Are there any minor performance differences (I'm assuming not), and is there any case where one really doesn't fit (making the other a clear winner for my convention)?*</p> <p>*I'm referring to any singleton, rather than just <code>None</code>.</p> <blockquote> <p>...to compare singletons like None. Use is or is not.</p> </blockquote>
2,711,073
9
4
null
2010-04-26 03:10:30.463 UTC
171
2021-08-12 22:20:47.543 UTC
2021-08-12 22:20:47.543 UTC
null
128,463
null
128,463
null
1
939
python|coding-style|nonetype|boolean-expression|pep8
1,221,829
<p>There's no performance difference, as they compile to the same bytecode:</p> <pre><code>&gt;&gt;&gt; import dis &gt;&gt;&gt; dis.dis(&quot;not x is None&quot;) 1 0 LOAD_NAME 0 (x) 2 LOAD_CONST 0 (None) 4 COMPARE_OP 9 (is not) 6 RETURN_VALUE &gt;&gt;&gt; dis.dis(&quot;x is not None&quot;) 1 0 LOAD_NAME 0 (x) 2 LOAD_CONST 0 (None) 4 COMPARE_OP 9 (is not) 6 RETURN_VALUE </code></pre> <p>Stylistically, I try to avoid <code>not x is y</code>, a human reader might misunderstand it as <code>(not x) is y</code>. If I write <code>x is not y</code> then there is no ambiguity.</p>
2,497,211
How to profile multi-threaded C++ application on Linux?
<p>I used to do all my Linux profiling with <a href="https://sourceware.org/binutils/docs/gprof/" rel="nofollow noreferrer">gprof</a>.</p> <p>However, with my <em><strong>multi-threaded</strong></em> application, it's output appears to be inconsistent.</p> <p>Now, I dug this up:</p> <p><a href="http://sam.zoy.org/writings/programming/gprof.html" rel="nofollow noreferrer">http://sam.zoy.org/writings/programming/gprof.html</a></p> <p>However, it's from a long time ago and in my gprof output, it appears my gprof is listing functions used by non-main threads.</p> <p>So, my questions are:</p> <ol> <li>In 2010, can I easily use gprof to profile multi-threaded Linux C++ applications? (<a href="http://en.wikipedia.org/wiki/Ubuntu_%28operating_system%29#Releases" rel="nofollow noreferrer">Ubuntu 9.10</a>)</li> <li>What other tools should I look into for profiling?</li> </ol>
2,498,022
10
11
null
2010-03-23 02:33:50.287 UTC
35
2021-06-09 06:29:12.04 UTC
2021-06-09 06:29:12.04 UTC
null
1,971,003
null
247,265
null
1
48
c++|multithreading|profiling|gprof
60,405
<p><strong>Edit:</strong> added another <a href="https://stackoverflow.com/questions/2497211/how-to-profile-multi-threaded-c-application-on-linux/7399733#7399733">answer</a> on poor man's profiler, which IMHO is better for multithreaded apps.</p> <p>Have a look at <a href="http://oprofile.sourceforge.net/" rel="noreferrer">oprofile</a>. The profiling overhead of this tool is negligible and it supports multithreaded applications---as long as you don't want to profile mutex contention (which is a very important part of profiling multithreaded applications)</p>
2,621,682
Import MySQL database into a SQL Server
<p>I have a <code>.sql</code> file from a MySQL dump containing tables, definitions and data to be inserted in these tables. How can I convert this database represented in the dump file to a SQL Server database?</p>
2,640,073
10
2
null
2010-04-12 11:37:20.917 UTC
29
2022-03-19 08:47:36.57 UTC
2022-03-19 08:46:29.733 UTC
null
1,127,428
null
213,717
null
1
94
mysql|sql-server
261,365
<p>I found a way for this on the net</p> <p>It demands a little bit of work, because it has to be done table by table. But anyway, I could copy the tables, data and constraints into a SQL Server database.</p> <p>Here is the link</p> <p><a href="http://www.codeproject.com/KB/database/migrate-mysql-to-mssql.aspx" rel="nofollow noreferrer">http://www.codeproject.com/KB/database/migrate-mysql-to-mssql.aspx</a></p>
2,761,360
Could I ever want to access the address zero?
<p>The constant 0 is used as the null pointer in C and C++. But as in the question <a href="https://stackoverflow.com/questions/2389251/pointer-to-a-specific-fixed-address"><em>"Pointer to a specific fixed address</em>"</a> there seems to be some possible use of assigning fixed addresses. Is there ever any conceivable need, in any system, for whatever low level task, for accessing the address 0?</p> <p>If there is, how is that solved with 0 being the null pointer and all?</p> <p>If not, what makes it certain that there is not such a need?</p>
2,761,494
17
11
null
2010-05-03 21:31:09.667 UTC
18
2015-04-23 20:35:30.307 UTC
2017-05-23 11:54:31.607 UTC
null
-1
null
229,741
null
1
58
c++|c|memory|pointers
11,196
<p>Neither in C nor in C++ null-pointer value is in any way tied to physical address <code>0</code>. The fact that you use constant <code>0</code> <em>in the source code</em> to set a pointer to null-pointer value is nothing more than just a piece of <strong><em>syntactic sugar</em></strong>. The compiler is required to translate it into the actual physical address used as null-pointer value on the specific platform.</p> <p>In other words, <code>0</code> in the source code has no physical importance whatsoever. It could have been <code>42</code> or <code>13</code>, for example. I.e. the language authors, if they so pleased, could have made it so that you'd have to do <code>p = 42</code> in order to set the pointer <code>p</code> to null-pointer value. Again, this does not mean that the physical address <code>42</code> would have to be reserved for null pointers. The compiler would be required to translate source code <code>p = 42</code> into machine code that would stuff the actual physical null-pointer value (<code>0x0000</code> or <code>0xBAAD</code>) into the pointer <code>p</code>. That's exactly how it is now with constant <code>0</code>.</p> <p>Also note, that neither C nor C++ provides a strictly defined feature that would allow you to assign a specific physical address to a pointer. So your question about "how one would assign 0 address to a pointer" formally has no answer. You simply can't assign a specific address to a pointer in C/C++. However, in the realm of implementation-defined features, the explicit integer-to-pointer conversion is intended to have that effect. So, you'd do it as follows</p> <pre><code>uintptr_t address = 0; void *p = (void *) address; </code></pre> <p>Note, that this is not the same as doing</p> <pre><code>void *p = 0; </code></pre> <p>The latter always produces the null-pointer value, while the former in general case does not. The former will normally produce a pointer to physical address <code>0</code>, which might or might not be the null-pointer value on the given platform.</p>
45,287,832
pyspark approxQuantile function
<p>I have dataframe with these columns <code>id</code>, <code>price</code>, <code>timestamp</code>.</p> <p>I would like to find median value grouped by <code>id</code>.</p> <p>I am using this code to find it but it's giving me this error.</p> <pre class="lang-python prettyprint-override"><code>from pyspark.sql import DataFrameStatFunctions as statFunc windowSpec = Window.partitionBy("id") median = statFunc.approxQuantile("price", [0.5], 0) \ .over(windowSpec) return df.withColumn("Median", median) </code></pre> <p>Is it not possible to use <code>DataFrameStatFunctions</code> to fill values in new column?</p> <pre class="lang-python prettyprint-override"><code>TypeError: unbound method approxQuantile() must be called with DataFrameStatFunctions instance as first argument (got str instance instead) </code></pre>
45,506,281
4
0
null
2017-07-24 18:43:08.997 UTC
5
2022-09-15 10:55:13.06 UTC
2022-09-15 10:55:13.06 UTC
null
2,753,501
null
6,051,375
null
1
12
apache-spark|pyspark|apache-spark-sql
47,555
<p>Well, indeed it is <strong>not</strong> possible to use <code>approxQuantile</code> to fill values in a new dataframe column, but this is not why you are getting this error. Unfortunately, the whole underneath story is a rather frustrating one, as <a href="https://www.nodalpoint.com/spark-classification/" rel="noreferrer">I have argued</a> that is the case with many Spark (especially PySpark) features and their lack of adequate documentation.</p> <p>To start with, there is not one, but <strong>two</strong> <code>approxQuantile</code> methods; the <a href="http://spark.apache.org/docs/2.1.1/api/python/pyspark.sql.html#pyspark.sql.DataFrame.approxQuantile" rel="noreferrer">first one</a> is part of the standard DataFrame class, i.e. you don't need to import DataFrameStatFunctions:</p> <pre class="lang-python prettyprint-override"><code>spark.version # u'2.1.1' sampleData = [("bob","Developer",125000),("mark","Developer",108000),("carl","Tester",70000),("peter","Developer",185000),("jon","Tester",65000),("roman","Tester",82000),("simon","Developer",98000),("eric","Developer",144000),("carlos","Tester",75000),("henry","Developer",110000)] df = spark.createDataFrame(sampleData, schema=["Name","Role","Salary"]) df.show() # +------+---------+------+ # | Name| Role|Salary| # +------+---------+------+ # | bob|Developer|125000| # | mark|Developer|108000| # | carl| Tester| 70000| # | peter|Developer|185000| # | jon| Tester| 65000| # | roman| Tester| 82000| # | simon|Developer| 98000| # | eric|Developer|144000| # |carlos| Tester| 75000| # | henry|Developer|110000| # +------+---------+------+ med = df.approxQuantile("Salary", [0.5], 0.25) # no need to import DataFrameStatFunctions med # [98000.0] </code></pre> <p><a href="https://spark.apache.org/docs/2.1.1/api/python/pyspark.sql.html#pyspark.sql.DataFrameStatFunctions" rel="noreferrer">The second one</a> is part of <code>DataFrameStatFunctions</code>, but if you use it as you do, you get the error you report:</p> <pre class="lang-python prettyprint-override"><code>from pyspark.sql import DataFrameStatFunctions as statFunc med2 = statFunc.approxQuantile( "Salary", [0.5], 0.25) # TypeError: unbound method approxQuantile() must be called with DataFrameStatFunctions instance as first argument (got str instance instead) </code></pre> <p>because the correct usage is</p> <pre class="lang-python prettyprint-override"><code>med2 = statFunc(df).approxQuantile( "Salary", [0.5], 0.25) med2 # [82000.0] </code></pre> <p>although you won't be able to find a simple example in the PySpark documentation about this (it took me some time to figure it out myself)... The best part? The two values are <strong>not equal</strong>:</p> <pre class="lang-python prettyprint-override"><code>med == med2 # False </code></pre> <p>I suspect this is due to the non-deterministic algorithm used (after all, it is supposed to be an <em>approximate</em> median), and even if you re-run the commands with the same toy data you may get different values (and different from the ones I report here) - I suggest to experiment a little to get the feeling...</p> <p>But, as I already said, this is not the reason why you cannot use <code>approxQuantile</code> to fill values in a new dataframe column - even if you use the correct syntax, you will get a different error:</p> <pre class="lang-python prettyprint-override"><code>df2 = df.withColumn('median_salary', statFunc(df).approxQuantile( "Salary", [0.5], 0.25)) # AssertionError: col should be Column </code></pre> <p>Here, <code>col</code> refers to the second argument of the <code>withColumn</code> operation, i.e. the <code>approxQuantile</code> one, and the error message says that it is not a <code>Column</code> type - indeed, it is a list:</p> <pre class="lang-python prettyprint-override"><code>type(statFunc(df).approxQuantile( "Salary", [0.5], 0.25)) # list </code></pre> <p>So, when filling column values, Spark expects arguments of type <code>Column</code>, and you cannot use lists; here is an example of creating a new column with mean values per Role instead of median ones:</p> <pre class="lang-python prettyprint-override"><code>import pyspark.sql.functions as func from pyspark.sql import Window windowSpec = Window.partitionBy(df['Role']) df2 = df.withColumn('mean_salary', func.mean(df['Salary']).over(windowSpec)) df2.show() # +------+---------+------+------------------+ # | Name| Role|Salary| mean_salary| # +------+---------+------+------------------+ # | carl| Tester| 70000| 73000.0| # | jon| Tester| 65000| 73000.0| # | roman| Tester| 82000| 73000.0| # |carlos| Tester| 75000| 73000.0| # | bob|Developer|125000|128333.33333333333| # | mark|Developer|108000|128333.33333333333| # | peter|Developer|185000|128333.33333333333| # | simon|Developer| 98000|128333.33333333333| # | eric|Developer|144000|128333.33333333333| # | henry|Developer|110000|128333.33333333333| # +------+---------+------+------------------+ </code></pre> <p>which works because, contrary to <code>approxQuantile</code>, <code>mean</code> returns a <code>Column</code>:</p> <pre class="lang-python prettyprint-override"><code>type(func.mean(df['Salary']).over(windowSpec)) # pyspark.sql.column.Column </code></pre>
40,203,827
How to stop CountDownTimer in android
<p>How to stop this timer , any idea ?</p> <p>I want to reset timer in every query but it continues. Every new query it adds new timer. How to solve this?</p> <pre><code> new CountDownTimer(zaman, 1000) { //geriye sayma public void onTick(long millisUntilFinished) { NumberFormat f = new DecimalFormat("00"); long hour = (millisUntilFinished / 3600000) % 24; long min = (millisUntilFinished / 60000) % 60; long sec = (millisUntilFinished / 1000) % 60; cMeter.setText(f.format(hour) + ":" + f.format(min) + ":" + f.format(sec)); } public void onFinish() { cMeter.setText("00:00:00"); } }.start(); </code></pre>
40,203,853
4
0
null
2016-10-23 14:09:12.387 UTC
7
2021-10-26 12:59:07.033 UTC
null
null
null
null
6,648,571
null
1
29
android|android-studio|countdowntimer
54,914
<p>You can assign it to a variable and then call <code>cancel()</code> on the variable</p> <pre><code>CountDownTimer yourCountDownTimer = new CountDownTimer(zaman, 1000) { public void onTick(long millisUntilFinished) {} public void onFinish() {} }.start(); yourCountDownTimer.cancel(); </code></pre> <p>or you can call <code>cancel()</code> inside of your counter scope</p> <pre><code>new CountDownTimer(zaman, 1000) { public void onTick(long millisUntilFinished) { cancel(); } public void onFinish() {} }.start(); </code></pre> <p>Read more: <a href="https://developer.android.com/reference/android/os/CountDownTimer.html" rel="noreferrer">https://developer.android.com/reference/android/os/CountDownTimer.html</a></p>
10,402,379
Is there an equivalent source command in Windows CMD as in bash or tcsh?
<p>I know that in the unix world, if you edit your <code>.profile</code> or <code>.cshrc</code> file, you can do a <code>source ~/.profile</code> or <code>source ~/.cshrc</code> to get the effect on your current session. If I changed something in the system variable on Windows, how can I have it effect the current command prompt session without exiting the command prompt session and opening another command prompt session?</p>
10,402,476
8
0
null
2012-05-01 18:33:19.58 UTC
11
2021-11-28 13:14:57.067 UTC
2021-11-28 13:14:57.067 UTC
null
13,442,245
null
1,366,950
null
1
48
windows|bash|unix|cmd|tcsh
108,000
<p>I am afraid not, but you can start using Powershell, which does support dot sourcing. Since powershell window is really based on cmd so all your dos command will continue to work, and you gain new power, much more power.</p>
5,675,208
Expected initializer before function name
<pre><code>#include &lt;iostream&gt; #include &lt;string&gt; using namespace std; struct sotrudnik { string name; string speciality; string razread; int zarplata; } sotrudnik create(string n,string spec,string raz,int sal) { sotrudnik temp; temp.name=n; temp.speciality=spec; temp.razread=raz; temp.zarplata=sal; return temp; } *sotrudnik str_compare (string str1, string str2, sotrudnik sot1, sotrudnik sot2) </code></pre> <p>I try to learn C++. But when i try to compile this code with GCC-4.4.5 by using the options &quot; g++ -Wall -c &quot;, I get the following error:</p> <blockquote> <p>g++ -Wall -c &quot;lab2.cc&quot; (in directory: /home/ion/Univer/Cpp)</p> <p>lab2.cc:11: error: expected initializer before <code>create</code> <br />lab2.cc:20: error: expected constructor, destructor, or type conversion before <code>str_compare</code> <br />Compilation failed.</p> </blockquote> <p>Both errors are tied to the function declarations. (round 11 is the declaration of function create, round 20 - of the function <code>str_compare</code>). Tried to google for these kinds of errors, but couldn't find examples of similar errors, as the error messages are very generic. How can I understand their meaning and how to solve them? Thank you very much for your attention.</p>
5,675,215
2
0
null
2011-04-15 10:08:24.18 UTC
null
2022-07-01 20:54:27.55 UTC
2020-06-20 09:12:55.06 UTC
null
-1
null
680,282
null
1
17
c++|gcc|compilation
130,600
<p>You are missing a semicolon at the end of your 'struct' definition.</p> <p>Also,</p> <pre><code>*sotrudnik </code></pre> <p>needs to be </p> <pre><code>sotrudnik* </code></pre>
31,123,872
Postgres SQL state: 22P02
<p>I need to run the following query in Postgres:</p> <pre><code>select left(file_date, 10) as date, lob_name, devicesegment, sum(conversion_units::numeric) as units from bac_search.dash_search_data where (lob_name= 'Mortgage' and file_date::date between (CURRENT_DATE - INTERVAL '30 days') and CURRENT_DATE) or (lob_name= 'Loans' and file_date::date between (CURRENT_DATE - INTERVAL '30 days') and CURRENT_DATE) group by file_date, lob_name, devicesegment order by file_date, lob_name, devicesegment; </code></pre> <p>Despite setting conversion_units to numeric, it is giving me the following error:</p> <blockquote> <pre><code>ERROR: invalid input syntax for type numeric: "" ********** Error ********** ERROR: invalid input syntax for type numeric: "" SQL state: 22P02 </code></pre> </blockquote> <p>Of note, I've done some unit testing and when I run this query for Mortgage and delete the line for Loans, it works fine. I've isolated the problem to <code>conversion_units::numeric</code> for <code>Loans</code>. Besides the usual conversion (as I've specified here), I'm not sure what else to try. I read through the questions with this error, but they don't seem to mirror my problem. Any help is appreciated! Thanks!</p>
31,124,669
3
0
null
2015-06-29 19:23:18.547 UTC
null
2021-12-01 08:50:27.473 UTC
2015-06-29 19:49:13.327 UTC
null
4,998,761
null
2,573,355
null
1
11
postgresql
41,156
<p>Apparently <code>conversion_units</code> is a string which can hold values not convertible to <code>numeric</code>.</p> <p>You immediate problem can be solved this way:</p> <pre><code>SUM(NULLIF(conversion_units, '')::numeric) </code></pre> <p>but there can be other values.</p> <p>You might try to use regexp to match convertible strings:</p> <pre><code>SUM((CASE WHEN conversion_units ~ E'^\\d(?:\\.\\d)*$' THEN conversion_units END)::numeric) </code></pre>
32,749,350
Check if a string is in a file with Python
<p>I'm new to Python and I'm trying to figure out how I can search for a string in a file and use it as a condition in a if clause: If "String" is in the file, Print("Blablabla")</p>
32,749,413
2
0
null
2015-09-23 20:58:24.057 UTC
3
2018-12-21 11:19:15.847 UTC
2015-09-23 21:00:25.327 UTC
user4639281
null
null
5,369,506
null
1
14
python|file|if-statement
83,081
<p>As you yourself said, just open the file and check if it is in it.</p> <pre><code>with open('myfile.txt') as myfile: if 'String' in myfile.read(): print('Blahblah') </code></pre> <p>Isn't <code>Python</code> delightful?</p>
35,481,924
Write a string to a file
<p>I want to write something to a file. I found this code: </p> <pre><code>private void writeToFile(String data) { try { OutputStreamWriter outputStreamWriter = new OutputStreamWriter(context.openFileOutput("config.txt", Context.MODE_PRIVATE)); outputStreamWriter.write(data); outputStreamWriter.close(); } catch (IOException e) { Log.e("Exception", "File write failed: " + e.toString()); } } </code></pre> <p>The code seems very logical, but I can't find the config.txt file in my phone.<br> How can I retrieve that file which includes the string?</p>
35,481,977
4
1
null
2016-02-18 12:47:27.853 UTC
10
2020-06-05 18:14:51.557 UTC
2016-02-19 11:31:09.193 UTC
null
2,649,012
null
1,954,132
null
1
27
android|streamwriter
64,313
<p>Not having specified a <strong>path</strong>, your file will be saved in your app space (<code>/data/data/your.app.name/</code>). </p> <p>Therefore, you better save your file onto an external storage (which is not necessarily the SD card, it can be the default storage).</p> <p>You might want to dig into the subject, by reading the <a href="http://developer.android.com/guide/topics/data/data-storage.html#filesExternal" rel="noreferrer">official docs</a></p> <p>In synthesis:</p> <p>Add this permission to your Manifest:</p> <pre><code> &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt; </code></pre> <p>It includes the READ permission, so no need to specify it too.</p> <p>Save the file in a location you specify (this is taken from my live cod, so I'm sure it works):</p> <pre><code>public void writeToFile(String data) { // Get the directory for the user's public pictures directory. final File path = Environment.getExternalStoragePublicDirectory ( //Environment.DIRECTORY_PICTURES Environment.DIRECTORY_DCIM + "/YourFolder/" ); // Make sure the path directory exists. if(!path.exists()) { // Make it, if it doesn't exit path.mkdirs(); } final File file = new File(path, "config.txt"); // Save your stream, don't forget to flush() it before closing it. try { file.createNewFile(); FileOutputStream fOut = new FileOutputStream(file); OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut); myOutWriter.append(data); myOutWriter.close(); fOut.flush(); fOut.close(); } catch (IOException e) { Log.e("Exception", "File write failed: " + e.toString()); } } </code></pre> <p><strong>[EDIT]</strong> OK Try like this (different path - a folder on the external storage):</p> <pre><code> String path = Environment.getExternalStorageDirectory() + File.separator + "yourFolder"; // Create the folder. File folder = new File(path); folder.mkdirs(); // Create the file. File file = new File(folder, "config.txt"); </code></pre>
19,099,607
Creating a table in h2 database using predefined sequence for primary key
<p>I am trying to create a table in an H2 database. How do I specify that the primary key should be generated from a sequence that has been created?</p> <p>The sequence is called group_seq, and I created it using this statement:</p> <pre><code>CREATE SEQUENCE GROUP_SEQ; </code></pre> <p>So when I create the table, how do I specify that I want my primary key col (ID) to use that sequence?</p>
19,100,026
1
0
null
2013-09-30 16:52:10.197 UTC
2
2016-12-13 08:44:10.463 UTC
2016-12-13 08:44:10.463 UTC
null
601,288
null
1,154,644
null
1
17
sequence|h2|ddl
43,651
<p>If you want to use your own sequence:</p> <pre><code>create sequence group_seq; create table test3(id bigint default group_seq.nextval primary key); </code></pre> <p>And if not:</p> <pre><code>create table test1(id identity); </code></pre> <p>or</p> <pre><code>create table test2(id bigint auto_increment primary key); </code></pre> <p>All this is documented in the <a href="http://h2database.com/html/grammar.html#create_table" rel="noreferrer">H2 SQL grammar railroad diagrams</a>.</p>
53,200,585
Terraform conditionals - if variable does not exist
<p>I have the following condition:</p> <pre><code>resource &quot;aws_elastic_beanstalk_application&quot; &quot;service&quot; { appversion_lifecycle { service_role = &quot;service-role&quot; delete_source_from_s3 = &quot;${var.env == &quot;production&quot; ? false : true}&quot; } } </code></pre> <p>If <code>var.env</code> is set to <code>production</code>, I get the result I want.</p> <p>However if <code>var.env</code> is not defined, <code>terraform plan</code> will fail because the variable was never defined.<br /> How can I get this to work, without ever having to define that variable?</p>
64,767,271
3
1
null
2018-11-08 02:12:21.767 UTC
2
2021-09-15 11:48:19.703 UTC
2021-09-15 11:48:19.703 UTC
null
2,123,530
null
2,397,245
null
1
34
terraform
85,341
<p>Seems these days you can also use <code>try</code> to check if something is set.</p> <pre><code>try(var.env, false) </code></pre> <p>After that your code will work since <code>var.env</code> is now defined with the value <code>false</code> even if <code>var.env</code> was never defined somewhere.</p> <p><a href="https://www.terraform.io/docs/configuration/functions/try.html" rel="noreferrer">https://www.terraform.io/docs/configuration/functions/try.html</a></p>
29,826,971
Ionic requests return 404 only on android, in Chrome it works fine
<p>So, i have cloned the tutorial app repo from ionic. I ran</p> <pre><code>ionic start conference sidemenu </code></pre> <p>and then i added a simple $http.get('myserver')(I tried with ngResources too). </p> <p>It worked perfect on chrome, I got all the data back but on angular i only got null data and 404 status on any request I tried to do.</p> <p>Note: I tried with my hosted server and with a local one. Both fail on Android. Server is a node.js REST API.</p> <p>Nothing is printed on the console, so the request does not even get to the server.</p> <p>Has anyone experienced that or could tell me how can I debug Android apps built with Ionic?</p> <p>EDIT 1: I don`t know why do you need it but here it is</p> <pre><code>$http.get('http://server.com/route').success(function (data) { //handle success }).error(function (data, status) { // handle error }); </code></pre>
29,896,923
4
1
null
2015-04-23 14:47:02.92 UTC
11
2019-08-02 04:44:34.283 UTC
2015-04-27 13:07:30.63 UTC
null
4,658,431
null
4,658,431
null
1
44
android|angularjs|http|ionic-framework
39,527
<p>The thing is that there were some major changes in Cordova 4.0.0:</p> <blockquote> <p>Major Changes [...] - Whitelist functionality is now provided via plugin (CB-7747) The whitelist has been enhanced to be more secure and configurable Setting of Content-Security-Policy is now supported by the framework (see details in plugin readme) You will need to add the new cordova-plugin-whitelist plugin Legacy whitelist behaviour is still available via plugin (although not recommended).</p> </blockquote> <p>So I installed the <a href="https://github.com/apache/cordova-plugin-whitelist">Cordova Whitelist plugin</a>. And added </p> <pre><code>&lt;allow-navigation href="http://*/*" /&gt; </code></pre> <p>in my <code>config.xml</code> file.</p>
25,577,578
Access class variable from instance
<p>I have this class:</p> <pre><code>class ReallyLongClassName: static_var = 5 def instance_method(self): ReallyLongClassName.static_var += 1 </code></pre> <p>Is there some way to access the static variable using the self variable? I'd rather do something like <code>class(self).static_var += 1</code>, because long names are unreadable.</p>
36,728,121
2
0
null
2014-08-29 23:40:35.937 UTC
11
2019-10-21 09:52:40.043 UTC
2019-10-21 09:52:40.043 UTC
null
7,851,470
null
1,335,431
null
1
46
python
40,610
<p>Use <code>self.__class__.classAttr</code>. This should work for both old &amp; new style classes.</p>
28,326,800
odata - combining $expand and $select
<p>In odata v4.0 is there an option for combining $expand and $select together? </p> <blockquote> <p>I have a scenario wherein I'm trying to get specific columns in productItemChoices and item. The below query will give you all the columns in productItemChoices. I only need one column in the productItemChoices</p> </blockquote> <pre><code>odata/Products(08f80b45-68a9-4a9f-a516-556e69e6bd58)?$expand=productItemChoices($expand=item($select=name)) </code></pre>
28,372,712
2
0
null
2015-02-04 16:44:40.18 UTC
7
2020-12-02 12:41:45.51 UTC
2020-12-02 12:41:45.51 UTC
null
5,846,045
null
1,005,967
null
1
39
select|asp.net-web-api|odata|expand
38,397
<p>After going through a lot of time on this, I finally got the answer. We can nest <code>select</code> within <code>expand</code> using <code>;</code> as a separator, something like</p> <pre><code>odata/Products(8)?$expand=choices($select=col1,col2;$expand=item($select=name)) </code></pre> <p>This is documented in the <a href="http://docs.oasis-open.org/odata/odata/v4.01/cs01/part2-url-conventions/odata-v4.01-cs01-part2-url-conventions.html#_Toc505773297" rel="noreferrer">OData v4 <code>$expand</code> documentation</a>. The documentation also lists other useful examples such as</p> <pre><code>Categories?$expand=Products($filter=DiscontinuedDate eq null) Categories?$expand=Products/$count($search=blue) </code></pre>
51,692,018
multiple pages in Vue.js CLI
<p>I'm having trouble figuring out how to have multiple pages in a Vue CLI project. Right now I have my home page with a few components and I want to create another page but I do not know how to do that. Am I supposed to create multiple html files where the index.html by default is? In a simple file structure with css js img folder and html files as pages I know that creating another html file means making another page. But I don't understand how this works with Vue CLI project.</p> <p>I saw stuff like vue-router and "pages" in Vue documentation but I do not understand them very well. What are my alternatives? Is there a guide that explains that in detail, because I wasn't able to find any, let alone detailed. Would be very happy if you could help! Thank you!</p>
51,692,866
4
0
null
2018-08-05 06:42:33.593 UTC
42
2020-10-08 05:42:25.117 UTC
null
null
null
null
7,052,348
null
1
62
javascript|html|vue.js|vue-cli|multi-page-application
99,821
<p><strong>Note pointing users to what should be the accepted answer</strong><br> At the moment of posting my initial answer I wasn't aware of the possibility of actually building MPAs in VueJS. My answer doesn't address the question asked therefore I will recommend to take a look at the answer provided by PJ.Wanderson bellow which <strong>should be the accepted answer</strong></p> <p><strong>Inital Answer</strong><br> Vue.js projects are SPAs(single page applications). You only have one <code>.html</code> file in the entire project which is the <code>index.html</code> file you mentioned. The "pages" you want to create, in vue.js are referred to as components. They will be plugged into the <code>index.html</code> file and rendered in the browser. A vue.js component comprises 3 parts: </p> <pre><code>&lt;template&gt; &lt;/template&gt; &lt;script&gt; export default { } &lt;/script&gt; &lt;style&gt; &lt;/style&gt; </code></pre> <ul> <li>Template: it contains all the html your page should display (this is where you put the html of your pages)</li> <li>Script: it contains all JavaScript code that will be executed on the page/component</li> <li>Style: it contains the CSS that will style that specific component/page</li> </ul> <p>You can check this tutorial out for a quick-start <a href="https://medium.com/codingthesmartway-com-blog/vue-js-2-quickstart-tutorial-2017-246195cfbdd2" rel="nofollow noreferrer">Vue.js 2 Quickstart Tutorial 2017</a></p> <p>It explains vue.js project structure and how the various files relate to each other</p>
43,230,622
ReactJS how to delete item from list
<p>I have have code that creates <code>&lt;li&gt;</code> elements. I need to delete elements one by one by clicking. For each element I have <code>Delete button</code>. I understand that I need some function to delete items by <code>id</code>. How to do this function to delete elements in ReactJS? My code:</p> <pre><code>class TodoApp extends React.Component { constructor(props) { super(props); this.handleChange = this.handleChange.bind(this); this.handleSubmit = this.handleSubmit.bind(this); this.state = {items: [], text: ''}; } render() { return ( &lt;div&gt; &lt;h3&gt;TODO&lt;/h3&gt; &lt;TodoList items={this.state.items} /&gt; &lt;form onSubmit={this.handleSubmit}&gt; &lt;input onChange={this.handleChange} value={this.state.text} /&gt; &lt;button&gt;{'Add #' + (this.state.items.length + 1)}&lt;/button&gt; &lt;/form&gt; &lt;/div&gt; ); } handleChange(e) { this.setState({text: e.target.value}); } handleSubmit(e) { e.preventDefault(); var newItem = { text: this.props.w +''+this.props.t, id: Date.now() }; this.setState((prevState) =&gt; ({ items: prevState.items.concat(newItem), text: '' })); } delete(id){ // How that function knows id of item that need to delete and how to delete item? this.setState(this.item.id) } } class TodoList extends React.Component { render() { return ( &lt;ul&gt; {this.props.items.map(item =&gt; ( &lt;li key={item.id}&gt;{item.text}&lt;button onClick={this.delete.bind(this)}&gt;Delete&lt;/button&gt;&lt;/li&gt; ))} &lt;/ul&gt; ); } } </code></pre>
43,230,714
1
0
null
2017-04-05 12:01:48.4 UTC
10
2019-04-22 16:55:59.66 UTC
null
null
null
null
6,485,248
null
1
20
javascript|reactjs|ecmascript-6
72,182
<p>You are managing the data in Parent component and rendering the UI in Child component, so to delete item from child component you need to pass a function along with data, call that function from child and pass any unique identifier of list item, inside parent component delete the item using that unique identifier.</p> <p><strong>Step1:</strong> Pass a function from parent component along with data, like this:</p> <pre><code>&lt;TodoList items={this.state.items} _handleDelete={this.delete.bind(this)}/&gt; </code></pre> <p><strong>Step2:</strong> Define <code>delete</code> function in parent component like this:</p> <pre><code>delete(id){ this.setState(prevState =&gt; ({ data: prevState.data.filter(el =&gt; el != id ) })); } </code></pre> <p><strong>Step3:</strong> Call that function from child component using <code>this.props._handleDelete()</code>:</p> <pre><code>class TodoList extends React.Component { _handleDelete(id){ this.props._handleDelete(id); } render() { return ( &lt;ul&gt; {this.props.items.map(item =&gt; ( &lt;li key={item.id}&gt;{item.text}&lt;button onClick={this._handleDelete.bind(this, item.id)}&gt;Delete&lt;/button&gt;&lt;/li&gt; ))} &lt;/ul&gt; ); } } </code></pre> <p>Check this working example:</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="true"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>class App extends React.Component{ constructor(){ super(); this.state = { data: [1,2,3,4,5] } this.delete = this.delete.bind(this); } delete(id){ this.setState(prevState =&gt; ({ data: prevState.data.filter(el =&gt; el != id ) })); } render(){ return( &lt;Child delete={this.delete} data={this.state.data}/&gt; ); } } class Child extends React.Component{ delete(id){ this.props.delete(id); } render(){ return( &lt;div&gt; { this.props.data.map(el=&gt; &lt;p onClick={this.delete.bind(this, el)}&gt;{el}&lt;/p&gt; ) } &lt;/div&gt; ) } } ReactDOM.render(&lt;App/&gt;, document.getElementById('app'))</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"&gt;&lt;/script&gt; &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"&gt;&lt;/script&gt; &lt;div id='app'/&gt;</code></pre> </div> </div> </p>
8,740,377
How to remove JSONArray element using Java
<p>My JsonArray is </p> <pre><code>[{ "Id": null, "Name": "One New task", "StartDate": "2010-02-03T05:30:00", "EndDate": "2010-02-04T05:30:00", "Duration": 1, "DurationUnit": "d", "PercentDone": 0, "ManuallyScheduled": false, "Priority": 1, "parentId": 8, "index": 0, "depth": 3, "checked": null },{ "Id": null, "Name": "New task", "StartDate": "2010-02-04T05:30:00", "EndDate": "2010-02-04T05:30:00", "Duration": 0, "DurationUnit": "d", "PercentDone": 0, "ManuallyScheduled": false, "Priority": 1, "parentId": 8, "index": 1, "depth": 3, "checked": null }] </code></pre> <p>Now from this JsonArray I want to remove Id, ManuallyScheduled, checked,</p> <p>I tried using <code>jsonArray.remove(1)</code> and also <code>jsonArray.discard("Id")</code> in JAVA. but nothing happens. what am I doing wrong to remove array items?</p> <p>I am using JAVA as my technology.</p>
8,740,464
3
0
null
2012-01-05 09:46:01.663 UTC
2
2017-11-08 19:45:22.91 UTC
2012-01-10 17:54:19.897 UTC
null
633,239
null
626,214
null
1
6
java|json|hibernate|extjs4
40,532
<p>What you have there is an array of objects. Therefore you'll have to loop through the array and remove the necessary data from <strong>each</strong> object, e.g.</p> <pre><code>for (int i = 0, len = jsonArr.length(); i &lt; len; i++) { JSONObject obj = jsonArr.getJSONObject(i); // Do your removals obj.remove("id"); // etc. } </code></pre> <p>I've assumed you're using <code>org.json.JSONObject</code> and <code>org.json.JSONArray</code> here, but the principal remains the same whatever JSON processing library you're using.</p> <p>If you wanted to convert something like <code>[{"id":215},{"id":216}]</code> to <code>[215,216]</code> you could so something like:</p> <pre><code>JSONArray intArr = new JSONArray(); for (int i = 0, len = objArr.length(); i &lt; len; i++) { intArr.put(objArr.getJSONObject(i).getInt("id")); } </code></pre>
8,996,963
How to perform case-insensitive sorting array of string in JavaScript?
<p>I have an array of strings I need to sort in JavaScript, but in a case-insensitive way. How to perform this?</p>
9,645,447
15
0
null
2012-01-25 01:52:13.543 UTC
43
2022-06-22 15:04:36.973 UTC
2021-12-03 18:30:57.74 UTC
null
12,897,204
null
520,957
null
1
299
javascript|sorting|case-insensitive
158,378
<p>In (almost :) a one-liner </p> <pre><code>["Foo", "bar"].sort(function (a, b) { return a.toLowerCase().localeCompare(b.toLowerCase()); }); </code></pre> <p>Which results in</p> <pre><code>[ 'bar', 'Foo' ] </code></pre> <p>While</p> <pre><code>["Foo", "bar"].sort(); </code></pre> <p>results in</p> <pre><code>[ 'Foo', 'bar' ] </code></pre>
8,722,806
How to compare two dates in php
<p>How to compare two dates in php if dates are in format <code>'03_01_12'</code> and <code>'31_12_11'</code> .</p> <p>I am using this code:</p> <pre><code>$date1=date('d_m_y'); $date2='31_12_11'; if(strtotime($date1) &lt; strtotime($date2)) echo '1 is small ='.strtotime($date1).','.$date1; else echo '2 is small ='.strtotime($date2).','.$date2; </code></pre> <p>But its not working..</p>
8,723,327
16
0
null
2012-01-04 06:18:56.427 UTC
16
2021-01-12 01:41:40.193 UTC
2016-09-27 11:58:29.113 UTC
null
3,611,036
null
1,817,690
null
1
121
php
391,043
<p>You will have to make sure that your dates are valid date objects.</p> <p>Try this:</p> <pre><code>$date1=date('d/m/y'); $tempArr=explode('_', '31_12_11'); $date2 = date("d/m/y", mktime(0, 0, 0, $tempArr[1], $tempArr[0], $tempArr[2])); </code></pre> <p>You can then perform the <code>strtotime()</code> method to get the difference.</p>
43,900,806
Cannot use as type in assignment in go
<p>when I compile my code, I get the following error message, not sure why it happens. Can someone help me point why? Thank you in advance.</p> <blockquote> <p>cannot use px.InitializePaxosInstance(val) (type PaxosInstance) as type *PaxosInstance in assignment</p> </blockquote> <pre><code>type Paxos struct { instance map[int]*PaxosInstance } type PaxosInstance struct { value interface{} decided bool } func (px *Paxos) InitializePaxosInstance(val interface{}) PaxosInstance { return PaxosInstance {decided:false, value: val} } func (px *Paxos) PartAProcess(seq int, val interface{}) error { px.instance[seq] = px.InitializePaxosInstance(val) return nil </code></pre> <p>}</p>
43,900,906
3
0
null
2017-05-10 19:04:57.577 UTC
1
2021-03-02 23:38:13.923 UTC
null
null
null
null
7,176,437
null
1
20
go
48,825
<p>Your map is expecting a pointer to a <code>PaxosInstance</code> (<code>*PaxosInstance</code>), but you are passing a struct value to it. Change your Initialize function to return a pointer.</p> <pre><code>func (px *Paxos) InitializePaxosInstance(val interface{}) *PaxosInstance { return &amp;PaxosInstance {decided:false, value: val} } </code></pre> <p>Now it returns a pointer. You can take the pointer of a variable using <code>&amp;</code> and, should you need the struct value itself, dereference it again with <code>*</code>.</p> <p>After a line like</p> <pre><code>x := &amp;PaxosInstance{} </code></pre> <p>or</p> <pre><code>p := PaxosInstance{} x := &amp;p </code></pre> <p>the value type of <code>x</code> is <code>*PaxosInstance</code>. And if you ever need to, you can dereference it back into a <code>PaxosInstance</code> struct value with</p> <pre><code>p = *x </code></pre> <p>You usually do not want to pass structs around as actual values, because Go is pass-by-value, which means it will copy the whole thing. Using struct values with maps and slices often results in logic errors because a copy is made should you iterate them or otherwise reference them except via index. It depends on your use-case, but your identifier <code>Instance</code> would infer that you would want to avoid duplications and such logic errors.</p> <p>As for reading the compiler errors, you can see what it was telling you. The type <code>PaxosInstance</code> and type <code>*PaxosInstance</code> are not the same.</p>
339,089
Can the iPhone SDK obtain the Wi-Fi SSID currently connected to?
<p>In the iPhone SDK I don't see the same <code>SCDynamicStore</code> used on Mac OS X to get the SSID name that your wireless network is currently connected to isn't available. </p> <p>Is there a way to get the SSID name that the iPhone is currently connected to? </p> <p>I see some apps do it (<a href="http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=296273148&amp;mt=8" rel="noreferrer">Easy Wi-Fi for AT&amp;T</a> for one) but I can't find how it's done in the iPhone SDK docs. A private or unpublish method would be acceptable just as a proof of concept (although I know that likely wouldn't make it to the AppStore).</p>
11,012,983
3
0
null
2008-12-03 23:12:21.893 UTC
13
2016-06-29 11:30:32.78 UTC
2013-03-02 22:02:19.903 UTC
Chris Hanson
119,114
danimal
29,263
null
1
13
iphone|ios|wifi
31,725
<p>This is now possible (iOS 4.1+) via the <a href="http://developer.apple.com/library/ios/#documentation/SystemConfiguration/Reference/CaptiveNetworkRef/Reference/reference.html" rel="nofollow noreferrer">Captive Network API</a>.</p> <p>See <a href="https://stackoverflow.com/questions/5198716/iphone-get-ssid-without-private-library">an example of how to use it on this similar question</a>.</p> <p><strong>This is not a private API.</strong></p>
336,288
How can I use Mock Objects in my unit tests and still use Code Coverage?
<p>Presently I'm starting to introduce the concept of Mock objects into my Unit Tests. In particular I'm using the Moq framework. However, one of the things I've noticed is that suddenly the classes I'm testing using this framework are showing code coverage of 0%.</p> <p>Now I understand that since I'm just mocking the class, its not running the actual class itself....but how do I write these tests and have Code Coverage return accurate results? Do I have to write one set of tests that use Mocks and one set to instantiate the class directly.</p> <p>Perhaps I am doing something wrong without realizing it?</p> <p>Here is an example of me trying to Unit Test a class called "MyClass":</p> <pre><code>using Moq; using NUnitFramework; namespace MyNameSpace { [TestFixture] public class MyClassTests { [Test] public void TestGetSomeString() { const string EXPECTED_STRING = "Some String!"; Mock&lt;MyClass&gt; myMock = new Mock&lt;MyClass&gt;(); myMock.Expect(m =&gt; m.GetSomeString()).Returns(EXPECTED_STRING); string someString = myMock.Object.GetSomeString(); Assert.AreEqual(EXPECTED_STRING, someString); myMock.VerifyAll(); } } public class MyClass { public virtual string GetSomeString() { return "Hello World!"; } } } </code></pre> <p>Does anyone know what I should be doing differently?</p>
336,314
3
0
null
2008-12-03 05:20:09.78 UTC
4
2019-11-09 22:37:34.99 UTC
2009-06-06 01:48:23.123 UTC
null
27,687
mezoid
39,532
null
1
16
c#|.net|unit-testing|moq|code-coverage
49,804
<p>You are not using your mock objects correctly. When you are using mock objects you meant to be testing how your code interacts with other objects without actually using the real objects. See the code below:</p> <pre><code>using Moq; using NUnitFramework; namespace MyNameSpace { [TestFixture] public class MyClassTests { [Test] public void TestGetSomeString() { const string EXPECTED_STRING = "Some String!"; Mock&lt;IDependance&gt; myMock = new Mock&lt;IDependance&gt;(); myMock.Expect(m =&gt; m.GiveMeAString()).Returns("Hello World"); MyClass myobject = new MyClass(); string someString = myobject.GetSomeString(myMock.Object); Assert.AreEqual(EXPECTED_STRING, someString); myMock.VerifyAll(); } } public class MyClass { public virtual string GetSomeString(IDependance objectThatITalkTo) { return objectThatITalkTo.GiveMeAString(); } } public interface IDependance { string GiveMeAString(); } } </code></pre> <p>It doesn't look like it is doing anything useful when your code is just returning a string without any logic behind it. </p> <p>The real power comes if you <code>GetSomeString()</code> method did some logic that may change the result of the output string depending on the return from the <code>IDependdance</code> .<code>GiveMeAString()</code> method, then you can see how your method handles bad data being sent from the <code>IDependdance</code> interface. </p> <p>Something like:</p> <pre><code> public virtual string GetSomeString(IDependance objectThatITalkTo) { if (objectThatITalkTo.GiveMeAString() == "Hello World") return "Hi"; return null; } </code></pre> <p>Now if you have this line in your test:</p> <pre><code>myMock.Expect(m =&gt; m.GiveMeAString()).Returns(null); </code></pre> <p>What will happen to your <code>GetSomeString()</code> method?</p>
845,622
Join an Array in Objective-C
<p>I'm looking for a method of turning a NSMutableArray into a string. Is there anything on a par with this Ruby array method?</p> <pre><code>&gt;&gt; array1 = [1, 2, 3] &gt;&gt; array1.join(',') =&gt; "1,2,3" </code></pre> <p>Cheers!</p>
845,645
3
0
null
2009-05-10 16:38:06.393 UTC
17
2014-09-27 18:34:04.857 UTC
2013-12-06 09:56:58.51 UTC
null
49,485
null
12,037
null
1
130
objective-c|nsmutablearray|nsarray
53,407
<pre><code>NSArray *array1 = [NSArray arrayWithObjects:@"1", @"2", @"3", nil]; NSString *joinedString = [array1 componentsJoinedByString:@","]; </code></pre> <p><a href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/NSArray.html#//apple_ref/occ/instm/NSArray/componentsJoinedByString:" rel="noreferrer"><code>componentsJoinedByString:</code></a> will join the components in the array by the specified string and return a string representation of the array.</p>
6,908,986
How to convert a namedtuple into a list of values and preserving the order of properties?
<pre><code>from collections import namedtuple Gaga = namedtuple('Gaga', ['id', 'subject', 'recipient']) g = Gaga(id=1, subject='hello', recipient='Janitor') </code></pre> <p>I want to be able to obtain this list (which preserves the order of the properties):</p> <pre><code>[1, 'hello', 'Janitor'] </code></pre> <p>I could create this list myself manually but there must be an easier way. I tried:</p> <pre><code>g._asdict().values() </code></pre> <p>but the properties are not in the order I want.</p>
6,909,027
1
2
null
2011-08-02 08:08:19.247 UTC
0
2016-01-10 19:08:21.817 UTC
null
null
null
null
834,839
null
1
28
python
18,201
<p>Why not just <code>list</code>?</p> <pre><code>&gt;&gt;&gt; list(g) [1, 'hello', 'Janitor'] </code></pre>
6,421,693
Why are LIB files beasts of such a duplicitous nature?
<p>I'm trying to understand this LIB file business on Microsoft Windows, and I've just made a discovery that will - I hope - dispel the confusion that hitherto has prevented me from getting a clear grasp of the issue. To wit, LIB files are not the one kind of file that their file extension suggests they are.</p> <pre><code>:: cd "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib" :: lib /nologo /list Ad1.Lib obj\i386\activdbgid.obj obj\i386\activscpid.obj obj\i386\ad1exid.obj obj\i386\dbgpropid.obj obj\i386\dispexid.obj :: lib /nologo /list oledb.lib o:\winmain.obj.x86fre\enduser\…\oledb\uuid\objfre\i386\oledbiid.obj o:\winmain.obj.x86fre\enduser\…\oledb\uuid\objfre\i386\oledbnewiid.obj o:\winmain.obj.x86fre\enduser\…\oledb\uuid\objfre\i386\cmdtreeiid.obj o:\winmain.obj.x86fre\enduser\…\oledb\uuid\objfre\i386\oledbdepiid.obj :: lib /nologo /list AdvAPI32.Lib | sort | uniq -c 731 ADVAPI32.dll </code></pre> <p>The first two examples contain object files (appearing as relative or absolute paths when displayed by the <code>lib.exe</code> utility). The third example, however, only contains 731 references to a DLL. (I guess <code>lib.exe</code> isn't designed to display more useful information for this kind of file.)</p> <p>Some contain object files, and they are static libraries. Others contain symbols, and they are import libraries. (There's a <a href="https://stackoverflow.com/questions/2240737/2240777#2240777">short explanation here</a>.)</p> <p>So static libraries appear to be the equivalents of <code>.a</code> files on Linux, and DLLs appear to map to <code>.so</code> files on Linux. (By the way, how would import libraries fit into this Windows/Linux equivalence picture?)</p> <p>Now I'm wondering why this is so? Why did Microsoft decide to give import libraries the same file extension as static libraries? (I understand that historically, static libraries were first, like primitive forms of life preceded more complex forms.) Why wouldn't they say, okay, here's these new kind of libraries, they shall be referred to as import libraries, and they shall bear the file extension <code>.ILB</code> (or whatever)?</p>
6,427,158
1
5
null
2011-06-21 07:19:14.923 UTC
22
2011-07-02 19:01:41.793 UTC
2017-05-23 12:09:48.173 UTC
null
-1
null
269,126
null
1
67
c|dll|shared-libraries|static-libraries
11,162
<p>Because they <em>are</em> libraries. Why invent a whole new vendor-specific extension for what is exactly the same thing as their already-vendor-specific libraries?</p>
20,869,907
Adding bootstrap in bundleconfig doesn't work in asp.net mvc
<p>I met an issue, strange in my point of view.</p> <p>I installed bootstrap via nuget package console.</p> <p>After that, in <code>BundleConfig.cs</code> file, I added two items to <code>bundles</code> list: </p> <pre><code>bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include( "~/Scripts/bootstrap.min.js")); bundles.Add(new StyleBundle("~/Content/bootstrap").Include( "~/Content/bootstrap.min.css", "~/Content/bootstrap-theme.min.css")); </code></pre> <p>Of course, these files exist locally.</p> <p>The <code>_Layout.cshtml</code> file contains</p> <pre class="lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta charset="utf-8" /&gt; &lt;meta name="viewport" content="width=device-width" /&gt; &lt;title&gt;@ViewBag.Title&lt;/title&gt; @Styles.Render("~/Content/css") @Scripts.Render("~/bundles/modernizr") @Styles.Render("~/Content/bootstrap") &lt;/head&gt; &lt;body&gt; @RenderBody() @Scripts.Render("~/bundles/jquery") @Scripts.Render("~/bundles/bootstrap") @RenderSection("scripts", required: false) &lt;/body&gt; &lt;/html&gt; </code></pre> <p>But when I see a view (for example login page), I see that bundle doesn't append bootstrap part.</p> <pre class="lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta charset="utf-8" /&gt; &lt;meta name="viewport" content="width=device-width" /&gt; &lt;title&gt;Login&lt;/title&gt; &lt;link href="/Content/Site.css" rel="stylesheet"/&gt; &lt;script src="/Scripts/modernizr-2.6.2.js"&gt;&lt;/script&gt; &lt;!-- I expect bootstrap here but it is not displayed --&gt; &lt;/head&gt; &lt;body&gt; ... &lt;script src="/Scripts/jquery-1.9.1.js"&gt;&lt;/script&gt; &lt;!-- I expect bootstrap here but it is not displayed --&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
20,869,946
1
0
null
2014-01-01 14:59:01.597 UTC
10
2015-11-25 13:34:15.583 UTC
2015-11-25 13:34:15.583 UTC
null
1,679,310
null
998,696
null
1
34
c#|asp.net-mvc|twitter-bootstrap|asp.net-mvc-4
47,772
<p>When using Bundle, do not append the <code>.min</code></p> <pre><code>bundles.Add(new StyleBundle("~/Content/bootstrap").Include( "~/Content/bootstrap.css", "~/Content/bootstrap-theme.css")); </code></pre> <p>Based on the debug setting, (mostly web.config)</p> <ul> <li><code>debug="true"</code> - the non minified version will be used. </li> <li><code>debug="false"</code> - <code>*.min.css</code> will be searched, and if not found, the current will be minified</li> </ul> <p>web.config setting: </p> <pre><code>&lt;system.web&gt; &lt;compilation debug="true"... </code></pre>
20,858,395
How to use ng-repeat with filter and $index?
<p>I want to use ng-repeat in Angular, while I only want to output some elements of the array. An Example:</p> <pre><code>ng-repeat="item in items | filter:($index%3 == 0)" </code></pre> <p>However, this does not work. Please tell me how to do this; only output exact index of elements.</p>
20,858,450
6
0
null
2013-12-31 13:49:55.1 UTC
10
2015-12-24 00:49:56.73 UTC
2015-12-24 00:49:56.73 UTC
null
4,224,424
null
1,856,785
null
1
28
javascript|angularjs|ng-repeat
71,868
<p>In your code, filter apply on 'items' array, not on each array item, that's why it does not work as you expect.</p> <p>Instead, you can use ng-show (or ng-if):</p> <pre><code>&lt;ul&gt; &lt;li ng-repeat="item in items" ng-show="$index % 3 == 0"&gt;{{item}}&lt;/li&gt; &lt;/ul&gt; </code></pre> <p>See: <a href="http://jsfiddle.net/H7d26" rel="noreferrer">http://jsfiddle.net/H7d26</a></p> <p>EDIT: Use ng-if directive if you do not want to add invisible dom elements:</p> <pre><code>&lt;ul&gt; &lt;li ng-repeat="item in items" ng-if="$index % 3 == 0"&gt;{{item}}&lt;/li&gt; &lt;/ul&gt; </code></pre>
20,865,507
Angular.js - ng-change not firing when ng-pattern is $invalid
<p>I am using ng-pattern to validate some form fields, and I am using ng-change with it to watch and process any changes, however ng-change (or $scope.$watch) will only fire when the form element is in the $valid state! I'm new to angular, so I don't know how to solve this issue, although I suspect a new directive is the way to go.</p> <p>How can I get ng-change to fire in both $invalid and $valid form element states, with ng-pattern still setting the form element states as before?</p> <p>Html:</p> <pre><code>&lt;div ng-app="test"&gt; &lt;div ng-controller="controller"&gt; &lt;form name="form"&gt; &lt;input type="text" name="textbox" ng-pattern="/^[0-9]+$/" ng-change="change()" ng-model="inputtext"&gt; Changes: {{ changes }} &lt;/form&gt; &lt;br&gt; Type in any amount of numbers, and changes should increment. &lt;br&gt;&lt;br&gt; Now enter anything that isn't a number, and changes will stop incrementing. When the form is in the $invalid state, ng-change doesn't fire. &lt;br&gt;&lt;br&gt; Now remove all characters that aren't numbers. It will increment like normal again. When the form is in the $valid state, ng-change will fire. &lt;br&gt;&lt;br&gt; I would like ng-change to fire even when the the form is $invalid. &lt;br&gt;&lt;br&gt; form.$valid: &lt;font color="red"&gt;{{ form.$valid }}&lt;/font&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>Javascript:</p> <pre><code>angular.module('test', []).controller('controller', function ($scope) { $scope.changes = 0; $scope.change = function () { $scope.changes += 1; }; }); </code></pre> <p>I have created a working JS Fiddle which shows the problem I am having.</p> <p><a href="http://jsfiddle.net/JAN3x/1/">http://jsfiddle.net/JAN3x/1/</a></p> <p>By the way, this angular issue also seems to be relevant: <a href="https://github.com/angular/angular.js/issues/1296">https://github.com/angular/angular.js/issues/1296</a></p>
20,898,509
4
0
null
2014-01-01 04:24:20.997 UTC
12
2017-05-11 15:33:43.537 UTC
null
null
null
null
2,276,141
null
1
35
angularjs
23,997
<p><strong>Edit</strong> This was answered when <code>ng-model-options</code> was not available. Please see the top-voted answer.</p> <p>you can write a simple directive to listen <code>input</code> event.</p> <p>HTML:</p> <pre><code>&lt;input type="text" name="textbox" ng-pattern="/^[0-9]+$/" watch-change="change()" ng-model="inputtext"&gt; Changes: {{ changes }} </code></pre> <p>JS:</p> <pre><code>app.directive('watchChange', function() { return { scope: { onchange: '&amp;watchChange' }, link: function(scope, element, attrs) { element.on('input', function() { scope.$apply(function () { scope.onchange(); }); }); } }; }); </code></pre> <p><a href="http://jsfiddle.net/H2EAB/" rel="nofollow noreferrer">http://jsfiddle.net/H2EAB/</a></p>
5,881,235
Oracle current_timestamp to seconds conversion
<p>We are using Oracle database.</p> <p>In our table timestamp is stored as seconds since 1970, how can I convert the time stamp obtained through current_timestamp() function to seconds</p>
5,881,292
3
1
null
2011-05-04 09:21:55.107 UTC
1
2019-10-28 17:17:26.547 UTC
null
null
null
null
7,965
null
1
15
oracle
52,144
<p>This would do it:</p> <pre><code>select round((cast(current_timestamp as date) - date '1970-01-01')*24*60*60) from dual </code></pre> <p>Though I wouldn't use current_timestamp if I was only interested in seconds, I would use SYSDATE:</p> <pre><code>select round((SYSDATE - date '1970-01-01')*24*60*60) from dual </code></pre>
6,036,357
Making an Entity Framework Model span multiple databases
<p>Is it valid to do something such as </p> <p><code>CREATE SYNONYM [dbo].[MyTable] FOR [AnotherDatabase].dbo.[MyTable]</code></p> <p>and then modify Entity Framework's edmx file to read this object like it would any other table? </p> <p>I did a quick sample test and it seems to work fine for selecting and updating, but I wanted to know if there was any reason why I shouldn't be doing this</p> <p>I am getting the table definition by creating an edmx file pointing to the 2nd database, building out the entities there, then copy/pasting the definition into the 1st database's edmx file.</p> <p><strong>UPDATE</strong> </p> <p>If anyone is interested, I wrote up what I did to make an edmx file span mulitple databases <a href="http://rachel53461.wordpress.com/2011/05/22/tricking-ef-to-span-multiple-databases/" rel="noreferrer">here</a>. It includes scripts for generating synonyms and merging edmx files.</p>
6,036,422
3
6
null
2011-05-17 19:56:38.947 UTC
10
2017-12-09 18:05:48.89 UTC
2011-05-25 03:38:15.807 UTC
null
302,677
null
302,677
null
1
29
sql-server|entity-framework|multiple-databases|synonym
20,120
<p>If you made a test and it worked you probably showed something nobody else know about. Till now I always answered this type of question: It is not possible to use single model with two databases (with some more ugly workaround based on views hiding tables from the second database). Now I know two workarounds.</p> <p>The only disadvantage of this approach is that all changes made manually to SSDL part of your EDMX are always lost if you run <em>Update model from database</em>. This means either manual development of EDMX (which is quite hard work) or using some tool / script which will add your changes after each update from database.</p>
5,789,647
Visual Studio 2010 Web Publish missing a file
<p>I'm finding that when publishing a website from Visual Studio its not uploading one of my files. Its a Razor file with a '.cshtml' extension (its doing the others!) and its part of the project.</p> <p>Any ideas why it would exclude it?</p>
5,789,693
3
0
null
2011-04-26 11:29:11.13 UTC
6
2017-01-10 06:42:52.23 UTC
2015-10-22 09:45:46.457 UTC
null
221,683
null
221,683
null
1
37
asp.net-mvc|visual-studio-2010|web-deployment
12,257
<p>In Visual Studio, right-click on the file and go to <em>Properties</em>.</p> <p>Under the file's properties, make sure that <em>Build Action</em> is set to <strong>Content</strong>. Otherwise it won't be published via web deploy.</p>
1,670,163
Loop through NSMutableArray of custom objects in the most memory efficient way
<p>What is the most memory efficient way to loop through an NSMutableArray of custom objects? I need to check a value in each object in the array and return how many of that type of object is in the array.</p>
1,670,175
2
0
null
2009-11-03 21:12:27.64 UTC
11
2009-11-03 21:24:29.143 UTC
null
null
null
null
143,273
null
1
14
iphone|objective-c|memory-management
34,918
<pre><code>for (WhateverYourClassNameIs *whateverNameYouWant in yourArrayName) { [whateverNameYouWant performSelector]; more code here; } </code></pre> <p>It's called fast enumeration and was a new feature with Objective C 2.0, which is available on the iPhone.</p>
1,827,102
Managed C++ to form a bridge between c# and C++
<p>I'm a bit rusty, actually really rusty with my C++. Haven't touched it since Freshman year of college so it's been a while.</p> <p>Anyway, I'm doing the reverse of what most people do. Calling C# code from C++. I've done some research online and it seems like I need to create some managed C++ to form a bridge. Use __declspec(dllexport) and then create a dll from that and use the whole thing as a wrapper.</p> <p>But my problem is - I'm really having a hard time finding examples. I found some basic stuff where someone wanted to use the C# version to String.ToUpper() but that was VERY basic and was only a small code snippet.</p> <p>Anyone have any ideas of where I can look for something a bit more concrete? Note, I do NOT want to use COM. The goal is to not touch the C# code at all.</p>
1,827,589
2
2
null
2009-12-01 15:55:50.743 UTC
13
2016-10-21 05:16:49.557 UTC
2010-04-16 20:32:38.78 UTC
null
1,288
null
103,165
null
1
16
c#|clr|c++-cli|unmanaged
24,107
<p>While lain beat me to writing an example, I'll post it anyhow just in case...</p> <p>The process of writing a wrapper to access your own library is the same as accessing one of the standard .Net libraries. </p> <p>Example C# class code in a project called CsharpProject:</p> <pre><code>using System; namespace CsharpProject { public class CsharpClass { public string Name { get; set; } public int Value { get; set; } public string GetDisplayString() { return string.Format("{0}: {1}", this.Name, this.Value); } } } </code></pre> <p>You would create a managed C++ class library project (example is CsharpWrapper) and add your C# project as a reference to it. In order to use the same header file for internal use and in the referencing project, you need a way to use the right declspec. This can be done by defining a preprocessor directive (<code>CSHARPWRAPPER_EXPORTS</code> in this case) and using a <code>#ifdef</code> to set the export macro in your C/C++ interface in a header file. The unmanaged interface header file must contain unmanaged stuff (or have it filtered out by the preprocessor).</p> <p>Unmanaged C++ Interface Header file (CppInterface.h):</p> <pre><code>#pragma once #include &lt;string&gt; // Sets the interface function's decoration as export or import #ifdef CSHARPWRAPPER_EXPORTS #define EXPORT_SPEC __declspec( dllexport ) #else #define EXPORT_SPEC __declspec( dllimport ) #endif // Unmanaged interface functions must use all unmanaged types EXPORT_SPEC std::string GetDisplayString(const char * pName, int iValue); </code></pre> <p>Then you can create an internal header file to be able to include in your managed library files. This will add the <code>using namespace</code> statements and can include helper functions that you need.</p> <p>Managed C++ Interface Header file (CsharpInterface.h):</p> <pre><code>#pragma once #include &lt;string&gt; // .Net System Namespaces using namespace System; using namespace System::Runtime::InteropServices; // C# Projects using namespace CsharpProject; ////////////////////////////////////////////////// // String Conversion Functions inline String ^ ToManagedString(const char * pString) { return Marshal::PtrToStringAnsi(IntPtr((char *) pString)); } inline const std::string ToStdString(String ^ strString) { IntPtr ptrString = IntPtr::Zero; std::string strStdString; try { ptrString = Marshal::StringToHGlobalAnsi(strString); strStdString = (char *) ptrString.ToPointer(); } finally { if (ptrString != IntPtr::Zero) { Marshal::FreeHGlobal(ptrString); } } return strStdString; } </code></pre> <p>Then you just write your interface code that does the wrapping.</p> <p>Managed C++ Interface Source file (CppInterface.cpp):</p> <pre><code>#include "CppInterface.h" #include "CsharpInterface.h" std::string GetDisplayString(const char * pName, int iValue) { CsharpClass ^ oCsharpObject = gcnew CsharpClass(); oCsharpObject-&gt;Name = ToManagedString(pName); oCsharpObject-&gt;Value = iValue; return ToStdString(oCsharpObject-&gt;GetDisplayString()); } </code></pre> <p>Then just include the unmanaged header in your unmanaged project, tell the linker to use the generated .lib file when linking, and make sure the .Net and wrapper DLLs are in the same folder as your unmanaged application.</p> <pre><code>#include &lt;stdlib.h&gt; // Include the wrapper header #include "CppInterface.h" void main() { // Call the unmanaged wrapper function std::string strDisplayString = GetDisplayString("Test", 123); // Do something with it printf("%s\n", strDisplayString.c_str()); } </code></pre>
45,778,679
Dotnet core 2.0 authentication multiple schemas identity cookies and jwt
<p>In dotnet core 1.1 asp, I was able to configure and use identity middleware followed by jwt middleware by doing the following:</p> <pre><code> app.UseIdentity(); app.UseJwtBearerAuthentication(new JwtBearerOptions() {}); </code></pre> <p>This has now changed in that we implement the middleware with:</p> <pre><code> app.UseAuthentication(); </code></pre> <p>Configuration of the settings is done via the ConfigureServices section of Startup.cs.</p> <p>There are some references to the use of authorization schema's in the migration documentation:</p> <p><a href="https://docs.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/identity-2x#authentication-middleware-and-services" rel="noreferrer">https://docs.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/identity-2x#authentication-middleware-and-services</a></p> <blockquote> <p>In 2.0 projects, authentication is configured via services. Each authentication scheme is registered in the ConfigureServices method of Startup.cs. The UseIdentity method is replaced with UseAuthentication.</p> </blockquote> <p>Additionally there is a reference to:</p> <blockquote> <h3>Setting Default Authentication Schemes</h3> <p>In 1.x, the AutomaticAuthenticate and AutomaticChallenge properties were intended to be set on a single authentication scheme. There was no good way to enforce this. </p> <p>In 2.0, these two properties have been removed as flags on the individual AuthenticationOptions instance and have moved into the base AuthenticationOptions class. The properties can be configured in the AddAuthentication method call within the ConfigureServices method of Startup.cs:</p> <p>Alternatively, use an overloaded version of the AddAuthentication method to set more than one property. In the following overloaded method example, the default scheme is set to CookieAuthenticationDefaults.AuthenticationScheme. The authentication scheme may alternatively be specified within your individual [Authorize] attributes or authorization policies.</p> </blockquote> <p>Is it still possible in dotnet core 2.0 to use multiple authentication schemas? I cannot get the policy to respect the JWT configuration ("Bearer" schema), and only Identity is working at present with both configured. I can't find any samples of multiple authentication schemas.</p> <p>Edit:</p> <p>I've reread the documentation, and now understand that the:</p> <pre><code>app.UseAuthentication() </code></pre> <p>adds automatic authentication against a default schema. Identity configures the default schemas for you.</p> <p>I have gotten around the issue with what seems like a hack working against the new api's by doing the following in Startup.cs Configure:</p> <pre><code> app.UseAuthentication(); app.Use(async (context, next) =&gt; { if (!context.User.Identity.IsAuthenticated) { var result = await context.AuthenticateAsync(JwtBearerDefaults.AuthenticationScheme); if (result?.Principal != null) { context.User = result.Principal; } } await next.Invoke(); }); </code></pre> <p>Is this the correct way to do this, or should I be utilising the framework, DI and interfaces for custom implementations of IAuthenticationSchemeProvider?</p> <p>Edit - Futher details of the implementation and where to find it.</p> <p>The JWT Config can be found here, and I am using policies to define the authorization, which include the accepted auth schema's:</p> <p><a href="https://github.com/Arragro/ArragroCMS/blob/master/src/ArragroCMS.Management/Startup.cs" rel="noreferrer">https://github.com/Arragro/ArragroCMS/blob/master/src/ArragroCMS.Management/Startup.cs</a></p> <p>Custom middleware is still implemented. The Auth controller is here:</p> <p><a href="https://github.com/Arragro/ArragroCMS/blob/master/src/ArragroCMS.Web.Management/ApiControllers/AuthController.cs" rel="noreferrer">https://github.com/Arragro/ArragroCMS/blob/master/src/ArragroCMS.Web.Management/ApiControllers/AuthController.cs</a></p> <p>It uses API Keys generated by the app to get read only access to data. You can find the implementation of a controller utilising the policy here:</p> <p><a href="https://github.com/Arragro/ArragroCMS/blob/master/src/ArragroCMS.Web.Management/ApiControllers/SitemapController.cs" rel="noreferrer">https://github.com/Arragro/ArragroCMS/blob/master/src/ArragroCMS.Web.Management/ApiControllers/SitemapController.cs</a></p> <p>Change the DB Connection string to point to your SQL Server, and run the application. It migrates the DB automatically and configures an admin user ([email protected] - ArragroPassword1!). Then go to the Settings tab in the menu bar and click "Configure the JWT ReadOnly API Key Settings" to get a key. In postman, get a jwt token by configuring a new tab and setting it to POST with the following address:</p> <p><a href="http://localhost:5000/api/auth/readonly-token" rel="noreferrer">http://localhost:5000/api/auth/readonly-token</a></p> <p>Supply the headers: Content-Type: application/json</p> <p>Supply the body: </p> <pre><code>{ "apiKey": "the api token from the previous step" } </code></pre> <p>Copy the token in the response, and then use the following in postman:</p> <p><a href="http://localhost:5000/api/sitemap/flat" rel="noreferrer">http://localhost:5000/api/sitemap/flat</a></p> <pre><code>Authorization: "bearer - The token you received in the previous request" </code></pre> <p>It will work inititally because of the custom middleware. Comment out the code mentioned above and try again and you will receive a 401.</p> <p>Edit -@DonnyTian's answer below covers my solution in his comments. The problem I was having was setting a default policy on UseMvc, but not supplying the schema's:</p> <pre><code> services.AddMvc(config =&gt; { var defaultPolicy = new AuthorizationPolicyBuilder(new[] { JwtBearerDefaults.AuthenticationScheme, IdentityConstants.ApplicationScheme }) .RequireAuthenticatedUser() .Build(); config.Filters.Add(new AuthorizeFilter(defaultPolicy)); config.Filters.Add(new AutoValidateAntiforgeryTokenAttribute()); config.Filters.Add(new ValidateModelAttribute()); }); </code></pre> <p>Following the advice, this works without custom middleware.</p>
45,853,589
5
2
null
2017-08-20 05:09:34.593 UTC
11
2022-03-30 15:19:27.417 UTC
2017-09-05 14:20:39.133 UTC
null
3,263,578
null
542,512
null
1
31
asp.net|authentication|asp.net-identity|.net-core|jwt
18,027
<p>Asp.Net Core 2.0 definitely support multiple authentication schemes. Rather than a hacking with authenticate middleware, you can try to specify the schema in <code>Authorize</code> attribute:</p> <pre><code>[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] </code></pre> <p>I gave a try and it worked fine. Assuming you have added both Identity and JWT as below:</p> <pre><code>services.AddIdentity&lt;ApplicationUser, ApplicationRole&gt;() services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) </code></pre> <p>Since <code>AddIdentity()</code> already set cookie authentication as the default schema, we have to specify schema in <code>Authorize</code> attribute of controllers. For now, I have no idea how to overwrite the default schema set by <code>AddIdentity()</code>, or maybe we'd better not to do that.</p> <p>A work around is to compose a new class (you can call it JwtAuthorize) that derives from <code>Authorize</code> and have <strong>Bearer</strong> as the default schema, so you don't have to specify it every time.</p> <p><strong>UPDATE</strong></p> <p>Found the way to override Identity default authentication scheme!</p> <p>Instead of below line:</p> <pre><code>services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) </code></pre> <p>Use below overload to set default schema:</p> <pre><code>services.AddAuthentication(option =&gt; { option.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(options =&gt;.... </code></pre> <p><strong>UPDATE 2</strong> As mentioned in comments, you can enable both Identity and JWT auth by join them together. <code> [Authorize(AuthenticationSchemes = "Identity.Application" + "," + JwtBearerDefaults.AuthenticationScheme)] </code></p>
6,265,717
how to start up a desktop application in client side
<p>In my web page, I have to start a desktop application on the client's computer if it's installed. Any idea how I can do this?</p> <p>If the application is MS Office or Adobe Reader, I know how to start them, but the application I want to start is a custom application. You can not find it on the internet.</p> <p>How can I open the application?</p>
6,265,845
6
2
null
2011-06-07 13:13:05.013 UTC
11
2022-02-03 10:42:30.287 UTC
2011-06-07 13:17:57.457 UTC
null
206,403
null
306,719
null
1
20
javascript
57,812
<p>The browser sandbox prohibits you from executing local resources, for good reason - to thwart a website destroying your box with malicious code. I've been researching the same functionality. </p> <p>The only solution I've found is to build an extension in Mozilla Firefox which can launch your app. Extensions live outside the sandbox so they can execute local resources. See <a href="https://developer.mozilla.org/en/building_an_extension" rel="nofollow noreferrer">this page</a> for how to do that. You may be able to do it cross-browser using <a href="http://www.crossrider.com" rel="nofollow noreferrer">crossrider</a>, though I haven't had success with that yet.</p> <p>You could alternatively build a thick client populated from a web service, and launched from the browser through an extension as mentioned above. This is what I'm doing to get around the sandbox. I'm using <a href="https://developer.mozilla.org/en/XUL" rel="nofollow noreferrer">local XUL</a> for this. </p> <p>See <a href="https://stackoverflow.com/questions/5970544/is-it-possible-to-use-local-resources-from-a-web-delivered-xul-app">my question</a> for additional discussion.</p>
6,163,055
php string matching with wildcard *?
<p>I want to give the possibility to match string with wildcard <code>*</code>.</p> <p>Example</p> <pre><code>$mystring = 'dir/folder1/file'; $pattern = 'dir/*/file'; stringMatchWithWildcard($mystring,$pattern); //&gt; Returns true </code></pre> <p>Example 2:</p> <pre><code>$mystring = 'string bl#abla;y'; $pattern = 'string*y'; stringMatchWithWildcard($mystring,$pattern); //&gt; Returns true </code></pre> <p>I thought something like:</p> <pre><code>function stringMatch($source,$pattern) { $pattern = preg_quote($pattern,'/'); $pattern = str_replace( '\*' , '.*?', $pattern); //&gt; This is the important replace return (bool)preg_match( '/^' . $pattern . '$/i' , $source ); } </code></pre> <p>Basically replacing <code>*</code> to <code>.*?</code> (considering in <code>*nix</code> environment <code>*</code> matches <code>empty</code> string) <em>©vbence</em></p> <p>Any improvments/suggests?</p> <p>// Added <code>return (bool)</code> because preg_match returns int</p>
6,163,624
6
0
null
2011-05-28 17:00:24.29 UTC
4
2019-02-25 08:52:58.163 UTC
2011-05-28 17:56:25.923 UTC
null
496,223
null
496,223
null
1
36
php|regex|string-matching
66,488
<p>There is no need for <code>preg_match</code> here. PHP has a wildcard comparison function, specifically made for such cases:</p> <blockquote> <p><a href="http://php.net/fnmatch"><code>fnmatch()</code></a> </p> </blockquote> <p>And <code>fnmatch('dir/*/file', 'dir/folder1/file')</code> would likely already work for you. But beware that the <code>*</code> wildcard would likewise add further slashes, like preg_match would.</p>
5,698,452
Count cumulative total in Postgresql
<p>I am using <code>count</code> and <code>group by</code> to get the number of subscribers registered each day:</p> <pre><code> SELECT created_at, COUNT(email) FROM subscriptions GROUP BY created at; </code></pre> <p>Result:</p> <pre><code>created_at count ----------------- 04-04-2011 100 05-04-2011 50 06-04-2011 50 07-04-2011 300 </code></pre> <p>I want to get the cumulative total of subscribers every day instead. How do I get this?</p> <pre><code>created_at count ----------------- 04-04-2011 100 05-04-2011 150 06-04-2011 200 07-04-2011 500 </code></pre>
5,700,744
6
0
null
2011-04-18 04:14:47.137 UTC
24
2021-07-22 18:37:05.71 UTC
2011-04-18 04:18:14.967 UTC
null
135,152
null
154,250
null
1
75
sql|postgresql|aggregate-functions
76,320
<p>With larger datasets, <a href="https://www.postgresql.org/docs/current/static/tutorial-window.html" rel="noreferrer"><strong>window functions</strong></a> are the most efficient way to perform these kinds of queries -- the table will be scanned only once, instead of once for each date, like a self-join would do. It also looks a lot simpler. :) PostgreSQL 8.4 and up have support for window functions.</p> <p>This is what it looks like:</p> <pre><code>SELECT created_at, sum(count(email)) OVER (ORDER BY created_at) FROM subscriptions GROUP BY created_at; </code></pre> <p>Here <code>OVER</code> creates the window; <code>ORDER BY created_at</code> means that it has to sum up the counts in <code>created_at</code> order.</p> <hr> <p><strong>Edit:</strong> If you want to remove duplicate emails within a single day, you can use <code>sum(count(distinct email))</code>. Unfortunately this won't remove duplicates that cross different dates.</p> <p>If you want to remove <em>all</em> duplicates, I think the easiest is to use a subquery and <code>DISTINCT ON</code>. This will attribute emails to their earliest date (because I'm sorting by created_at in ascending order, it'll choose the earliest one):</p> <pre><code>SELECT created_at, sum(count(email)) OVER (ORDER BY created_at) FROM ( SELECT DISTINCT ON (email) created_at, email FROM subscriptions ORDER BY email, created_at ) AS subq GROUP BY created_at; </code></pre> <p>If you create an index on <code>(email, created_at)</code>, this query shouldn't be too slow either.</p> <hr> <p>(If you want to test, this is how I created the sample dataset)</p> <pre><code>create table subscriptions as select date '2000-04-04' + (i/10000)::int as created_at, '[email protected]' || (i%700000)::text as email from generate_series(1,1000000) i; create index on subscriptions (email, created_at); </code></pre>
5,905,861
How do I add two weeks to Time.now?
<p>How can I add two weeks to the current Time.now in Ruby? I have a small Sinatra project that uses DataMapper and before saving, I have a field populated with the current time PLUS two weeks, but is not working as needed. Any help is greatly appreciated! I get the following error:</p> <pre><code>NoMethodError at / undefined method `weeks' for 2:Fixnum </code></pre> <p>Here is the code for the Model: </p> <pre><code>class Job include DataMapper::Resource property :id, Serial property :position, String property :location, String property :email, String property :phone, String property :description, Text property :expires_on, Date property :status, Boolean property :created_on, DateTime property :updated_at, DateTime before :save do t = Time.now self.expires_on = t + 2.week self.status = '0' end end </code></pre>
5,906,119
8
0
null
2011-05-06 01:17:47.373 UTC
9
2017-11-24 09:05:41.99 UTC
2011-05-12 23:58:30.713 UTC
null
38,765
null
266,889
null
1
43
ruby|time
76,047
<p>You don't have such nice helpers in plain Ruby. You can add seconds:</p> <pre><code>Time.now + (2*7*24*60*60) </code></pre> <p>But, fortunately, there are many date helper libraries out there (or build your own ;) )</p>
5,917,412
Can CSS3 box-shadow:inset do only one or two sides? like border-top?
<p>I'm wondering about the support for side specific inner shadows in css3.</p> <p>I know this works great on supported browsers.</p> <pre><code>div { box-shadow:inset 0px 1px 5px black; } </code></pre> <p>I'm just curious as to whether there is a way to achieve something like: </p> <pre><code>div { box-shadow-top:inset 0px 1px 5px black; } </code></pre>
12,109,280
11
1
null
2011-05-06 21:55:25.58 UTC
19
2018-03-30 13:32:53.163 UTC
2012-06-30 02:03:13.497 UTC
null
918,414
null
726,402
null
1
84
css
94,338
<p>This is what worked for me:</p> <pre><code>box-shadow: inset 1px 4px 9px -6px; </code></pre> <p>Example: <a href="http://jsfiddle.net/23Egu/" rel="noreferrer">http://jsfiddle.net/23Egu/</a></p>
6,111,408
Maven2: Missing artifact but jars are in place
<p>From now to then, my Maven 2 started to mess around.</p> <p>I am using SPring STS 2.6.1 and have a single project based on Spring 3, Hibernate, DWR, Cometd and all that stuff.</p> <p>Today I just updated from Git und all of a sudden, I got that scary <code>mvn</code> exclamation mark (!) next to my project.</p> <p>After hitting "Project -> Maven -> Update dependencies" I just receive:</p> <pre><code>24.05.11 15:26:58 MESZ: Missing artifact org.jdom:jdom:jar:1.1:compile 24.05.11 15:26:58 MESZ: Missing artifact org.apache.solr:solr-common:jar:1.3.0:compile 24.05.11 15:26:58 MESZ: Missing artifact org.apache.solr:solr-core:jar:1.3.0:compile 24.05.11 15:26:58 MESZ: Missing artifact org.apache.solr:solr-solrj:jar:1.3.0:compile 24.05.11 15:26:58 MESZ: Missing artifact stax:stax:jar:1.2.0:compile 24.05.11 15:26:58 MESZ: Missing artifact stax:stax-api:jar:1.0.1:compile 24.05.11 15:26:58 MESZ: Missing artifact org.apache.solr:solr-lucene-analyzers:jar:1.3.0:compile 24.05.11 15:26:58 MESZ: Missing artifact org.apache.solr:solr-lucene-core:jar:1.3.0:compile 24.05.11 15:26:58 MESZ: Missing artifact org.apache.solr:solr-lucene-highlighter:jar:1.3.0:compile 24.05.11 15:26:58 MESZ: Missing artifact org.apache.solr:solr-lucene-queries:jar:1.3.0:compile 24.05.11 15:26:58 MESZ: Missing artifact org.apache.solr:solr-lucene-snowball:jar:1.3.0:compile 24.05.11 15:26:58 MESZ: Missing artifact org.apache.solr:solr-lucene-spellchecker:jar:1.3.0:compile 24.05.11 15:26:58 MESZ: Missing artifact commons-httpclient:commons-httpclient:jar:3.1:compile 24.05.11 15:26:58 MESZ: Missing artifact org.apache.commons:commons-io:jar:1.3.2:compile 24.05.11 15:26:58 MESZ: Missing artifact commons-logging:commons-logging:jar:1.0.4:compile 24.05.11 15:26:58 MESZ: Missing artifact org.apache.solr:solr-commons-csv:jar:1.3.0:compile 24.05.11 15:26:58 MESZ: Missing artifact org.apache.geronimo.specs:geronimo-stax-api_1.0_spec:jar:1.0.1:compile 24.05.11 15:26:58 MESZ: Missing artifact net.java.dev.stax-utils:stax-utils:jar:20040917:compile 24.05.11 15:26:58 MESZ: Missing artifact org.apache.lucene:lucene-snowball:jar:2.4.1:compile 24.05.11 15:26:58 MESZ: Missing artifact org.apache.lucene:lucene-core:jar:2.4.1:compile 24.05.11 15:26:58 MESZ: Missing artifact org.slf4j:slf4j-api:jar:1.6.1:compile 24.05.11 15:26:58 MESZ: Missing artifact org.springframework:spring-expression:jar:3.0.5.RELEASE:compile 24.05.11 15:26:58 MESZ: Missing artifact org.springframework:spring-core:jar:3.0.5.RELEASE:compile 24.05.11 15:26:58 MESZ: Missing artifact org.springframework:spring-beans:jar:3.0.5.RELEASE:compile 24.05.11 15:26:58 MESZ: Missing artifact org.springframework:spring-aop:jar:3.0.5.RELEASE:compile 24.05.11 15:26:58 MESZ: Missing artifact aopalliance:aopalliance:jar:1.0:compile 24.05.11 15:26:58 MESZ: Missing artifact org.springframework:spring-asm:jar:3.0.5.RELEASE:compile 24.05.11 15:26:58 MESZ: Missing artifact org.springframework:spring-aspects:jar:3.0.5.RELEASE:compile 24.05.11 15:26:58 MESZ: Missing artifact org.springframework:spring-test:jar:3.0.5.RELEASE:compile 24.05.11 15:26:58 MESZ: Missing artifact org.springframework:spring-context:jar:3.0.5.RELEASE:compile 24.05.11 15:26:58 MESZ: Missing artifact org.springframework:spring-context-support:jar:3.0.5.RELEASE:compile 24.05.11 15:26:58 MESZ: Missing artifact org.springframework:spring-tx:jar:3.0.5.RELEASE:compile 24.05.11 15:26:58 MESZ: Missing artifact org.springframework:spring-jdbc:jar:3.0.5.RELEASE:compile 24.05.11 15:26:58 MESZ: Missing artifact org.springframework:spring-orm:jar:3.0.5.RELEASE:compile 24.05.11 15:26:58 MESZ: Missing artifact org.springframework:spring-oxm:jar:3.0.5.RELEASE:compile 24.05.11 15:26:58 MESZ: Missing artifact org.springframework:spring-web:jar:3.0.5.RELEASE:compile 24.05.11 15:26:58 MESZ: Missing artifact org.springframework:spring-webmvc:jar:3.0.5.RELEASE:compile 24.05.11 15:26:58 MESZ: Missing artifact org.springframework:spring-instrument:jar:3.0.5.RELEASE:compile 24.05.11 15:26:58 MESZ: Missing artifact org.springframework.security:spring-security-core:jar:3.0.5.RELEASE:compile 24.05.11 15:26:58 MESZ: Missing artifact org.springframework.security:spring-security-web:jar:3.0.5.RELEASE:compile 24.05.11 15:26:58 MESZ: Missing artifact org.springframework.security:spring-security-taglibs:jar:3.0.5.RELEASE:compile 24.05.11 15:26:58 MESZ: Missing artifact org.springframework.security:spring-security-acl:jar:3.0.5.RELEASE:compile 24.05.11 15:26:58 MESZ: Missing artifact org.springframework.security:spring-security-parent:pom:3.0.5.RELEASE:compile 24.05.11 15:26:58 MESZ: Missing artifact org.springframework.security:spring-security-config:jar:3.0.5.RELEASE:system 24.05.11 15:26:58 MESZ: Missing artifact org.hibernate:hibernate-core:jar:3.3.2.GA:compile 24.05.11 15:26:58 MESZ: Missing artifact antlr:antlr:jar:2.7.6:compile 24.05.11 15:26:58 MESZ: Missing artifact commons-collections:commons-collections:jar:3.1:compile 24.05.11 15:26:58 MESZ: Missing artifact dom4j:dom4j:jar:1.6.1:compile 24.05.11 15:26:58 MESZ: Missing artifact javax.transaction:jta:jar:1.1:compile 24.05.11 15:26:58 MESZ: Missing artifact org.hibernate:hibernate-annotations:jar:3.4.0.GA:compile 24.05.11 15:26:58 MESZ: Missing artifact org.hibernate:ejb3-persistence:jar:1.0.2.GA:compile 24.05.11 15:26:58 MESZ: Missing artifact org.hibernate:hibernate-commons-annotations:jar:3.1.0.GA:compile 24.05.11 15:26:58 MESZ: Missing artifact org.hibernate:ejb3-persistence:pom:1.0.2.GA:compile 24.05.11 15:26:58 MESZ: Missing artifact commons-dbcp:commons-dbcp:jar:1.4:compile 24.05.11 15:26:58 MESZ: Missing artifact commons-pool:commons-pool:jar:1.5.4:compile 24.05.11 15:26:58 MESZ: Missing artifact org.aspectj:aspectjweaver:jar:1.6.10:compile 24.05.11 15:26:58 MESZ: Missing artifact org.slf4j:slf4j-log4j12:jar:1.6.1:compile 24.05.11 15:26:58 MESZ: Missing artifact log4j:log4j:jar:1.2.16:compile 24.05.11 15:26:58 MESZ: Missing artifact javax.persistence:persistence-api:jar:1.0:compile 24.05.11 15:26:58 MESZ: Missing artifact javassist:javassist:jar:3.12.1.GA:compile 24.05.11 15:26:58 MESZ: Missing artifact postgresql:postgresql:jar:9.0-801.jdbc4:compile 24.05.11 15:26:58 MESZ: Missing artifact commons-codec:commons-codec:jar:1.4:compile 24.05.11 15:26:58 MESZ: Missing artifact org.directwebremoting:dwr:jar:2.0.3:compile 24.05.11 15:26:58 MESZ: Missing artifact org.beanshell:bsh:jar:2.0b4:compile 24.05.11 15:26:58 MESZ: Missing artifact org.jasypt:jasypt:jar:1.7:compile 24.05.11 15:26:58 MESZ: Missing artifact cglib:cglib:jar:2.2:compile 24.05.11 15:26:58 MESZ: Missing artifact asm:asm:jar:3.1:compile 24.05.11 15:26:58 MESZ: Missing artifact commons-fileupload:commons-fileupload:jar:1.2.2:compile 24.05.11 15:26:58 MESZ: Missing artifact org.apache.poi:poi:jar:3.8-beta1:compile 24.05.11 15:26:58 MESZ: Missing artifact jasperreports:jasperreports:jar:3.5.3:compile 24.05.11 15:26:58 MESZ: Missing artifact commons-beanutils:commons-beanutils:jar:1.8.0:compile 24.05.11 15:26:58 MESZ: Missing artifact commons-digester:commons-digester:jar:1.7:compile 24.05.11 15:26:58 MESZ: Missing artifact jfree:jcommon:jar:1.0.15:compile 24.05.11 15:26:58 MESZ: Missing artifact jfree:jfreechart:jar:1.0.12:compile 24.05.11 15:26:58 MESZ: Missing artifact xml-apis:xml-apis:jar:1.3.02:compile 24.05.11 15:26:58 MESZ: Missing artifact eclipse:jdtcore:jar:3.1.0:compile 24.05.11 15:26:58 MESZ: Missing artifact junit:junit:jar:4.8.2:test 24.05.11 15:26:58 MESZ: Missing artifact org.easymock:easymock:jar:3.0:test 24.05.11 15:26:58 MESZ: Missing artifact cglib:cglib-nodep:jar:2.2:test 24.05.11 15:26:58 MESZ: Missing artifact org.objenesis:objenesis:jar:1.2:test 24.05.11 15:26:58 MESZ: Missing artifact net.sf.ehcache:ehcache:pom:2.3.1:compile 24.05.11 15:26:58 MESZ: Missing artifact net.sf.ehcache:ehcache-core:jar:2.3.1:compile 24.05.11 15:26:58 MESZ: Missing artifact net.sf.ehcache:ehcache-terracotta:jar:2.3.1:compile 24.05.11 15:26:58 MESZ: Missing artifact org.opensymphony.quartz:quartz-all:jar:1.6.1:compile 24.05.11 15:26:58 MESZ: Missing artifact javax.servlet:jstl:jar:1.1.2:compile 24.05.11 15:26:58 MESZ: Missing artifact taglibs:standard:jar:1.1.2:compile 24.05.11 15:26:58 MESZ: Missing artifact org.aspectj:aspectjrt:jar:1.6.5:compile 24.05.11 15:26:58 MESZ: Missing artifact org.apache.velocity:velocity:jar:1.6.2:compile 24.05.11 15:26:58 MESZ: Missing artifact commons-lang:commons-lang:jar:2.4:compile 24.05.11 15:26:58 MESZ: Missing artifact oro:oro:jar:2.0.8:compile 24.05.11 15:26:58 MESZ: Missing artifact javax.mail:mail:jar:1.4.1:compile 24.05.11 15:26:58 MESZ: Missing artifact javax.activation:activation:jar:1.1:compile 24.05.11 15:26:58 MESZ: Missing artifact com.lowagie:itext:jar:2.0.7:compile 24.05.11 15:26:58 MESZ: Missing artifact bouncycastle:bcmail-jdk14:jar:138:compile 24.05.11 15:26:58 MESZ: Missing artifact bouncycastle:bcprov-jdk14:jar:138:compile 24.05.11 15:26:58 MESZ: Missing artifact org.cometd.java:cometd-java-server:jar:1.0.1:compile 24.05.11 15:26:58 MESZ: Missing artifact org.cometd.java:cometd-api:jar:1.0.1:compile 24.05.11 15:26:58 MESZ: Missing artifact org.eclipse.jetty:jetty-util:jar:7.0.1.v20091125:compile 24.05.11 15:26:58 MESZ: Missing artifact org.eclipse.jetty:jetty-continuation:jar:7.0.1.v20091125:compile 24.05.11 15:26:58 MESZ: Missing artifact org.apache.velocity:velocity-tools:jar:2.0:compile 24.05.11 15:26:58 MESZ: Missing artifact commons-chain:commons-chain:jar:1.1:compile 24.05.11 15:26:58 MESZ: Missing artifact commons-validator:commons-validator:jar:1.3.1:compile 24.05.11 15:26:58 MESZ: Missing artifact sslext:sslext:jar:1.2-0:compile 24.05.11 15:26:58 MESZ: Missing artifact org.apache.struts:struts-core:jar:1.3.8:compile 24.05.11 15:26:58 MESZ: Missing artifact org.apache.struts:struts-taglib:jar:1.3.8:compile 24.05.11 15:26:58 MESZ: Missing artifact org.apache.struts:struts-tiles:jar:1.3.8:compile 24.05.11 15:26:58 MESZ: Missing artifact net.htmlparser.jericho:jericho-html:jar:3.1:compile 24.05.11 15:26:58 MESZ: Missing artifact ro.isdc.wro4j:wro4j-core:jar:1.3.3:compile 24.05.11 15:26:58 MESZ: Missing artifact commons-io:commons-io:jar:2.0:compile 24.05.11 15:26:58 MESZ: Missing artifact com.google.collections:google-collections:jar:1.0:compile 24.05.11 15:26:58 MESZ: Missing artifact javax.servlet:servlet-api:jar:2.5:compile 24.05.11 15:26:58 MESZ: Missing artifact redis.clients:jedis:jar:1.5.2:compile 24.05.11 15:26:58 MESZ: Missing artifact org.mongodb:mongo-java-driver:jar:2.5.2:compile 24.05.11 15:26:58 MESZ: Missing artifact org.xhtmlrenderer:core-renderer:jar:R8pre2:compile 24.05.11 15:26:58 MESZ: Missing artifact org.apache.sanselan:sanselan:jar:0.97-incubator:compile 24.05.11 15:26:58 MESZ: Missing artifact com.kenai.nbpwr:com-sun-pdfview:jar:1.0.5-201003191900:compile 24.05.11 15:26:58 MESZ: Missing artifact org.swinglabs:pdf-renderer:jar:1.0.5:compile 24.05.11 15:26:58 MESZ: Missing artifact org.safehaus.jug:jug:jar:2.0.0:system 24.05.11 15:26:58 MESZ: Missing artifact de.dankomannhaupt:JDBCAppender:jar:1.0:system 24.05.11 15:26:58 MESZ: Missing artifact spy:memcahed:jar:2.5:system 24.05.11 15:26:58 MESZ: Missing artifact net.sf.beanlib:beanlib:jar:5.0.2beta:compile 24.05.11 15:26:58 MESZ: Missing artifact xstream:xstream:jar:1.1.2:compile 24.05.11 15:26:58 MESZ: Missing artifact net.jcip:jcip-annotations:jar:1.0:compile 24.05.11 15:26:58 MESZ: Missing artifact net.sf.beanlib:beanlib-hibernate:jar:5.0.2beta:compile </code></pre> <p>My <code>pom.xml</code> looks like:</p> <pre><code>&lt;properties&gt; &lt;org.springframework.version&gt;3.0.5.RELEASE&lt;/org.springframework.version&gt; &lt;hibernate.version&gt;3.3.2.GA&lt;/hibernate.version&gt; &lt;/properties&gt; &lt;repositories&gt; &lt;repository&gt; &lt;id&gt;JBoss&lt;/id&gt; &lt;name&gt;JBoss Repsitory&lt;/name&gt; &lt;layout&gt;default&lt;/layout&gt; &lt;url&gt;http://repository.jboss.org/maven2&lt;/url&gt; &lt;/repository&gt; &lt;/repositories&gt; &lt;!-- Bezeichnung --&gt; &lt;artifactId&gt;project-dao&lt;/artifactId&gt; &lt;name&gt;Vevention Dao&lt;/name&gt; &lt;groupId&gt;com.corp.dao&lt;/groupId&gt; &lt;version&gt;1.0Beta&lt;/version&gt; &lt;dependencies&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework&lt;/groupId&gt; &lt;artifactId&gt;spring-expression&lt;/artifactId&gt; &lt;version&gt;${org.springframework.version}&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework&lt;/groupId&gt; &lt;artifactId&gt;spring-beans&lt;/artifactId&gt; &lt;version&gt;${org.springframework.version}&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework&lt;/groupId&gt; &lt;artifactId&gt;spring-aop&lt;/artifactId&gt; &lt;version&gt;${org.springframework.version}&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework&lt;/groupId&gt; &lt;artifactId&gt;spring-aspects&lt;/artifactId&gt; &lt;version&gt;${org.springframework.version}&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework&lt;/groupId&gt; &lt;artifactId&gt;spring-context&lt;/artifactId&gt; &lt;version&gt;${org.springframework.version}&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework&lt;/groupId&gt; &lt;artifactId&gt;spring-context-support&lt;/artifactId&gt; &lt;version&gt;${org.springframework.version}&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework&lt;/groupId&gt; &lt;artifactId&gt;spring-tx&lt;/artifactId&gt; &lt;version&gt;${org.springframework.version}&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework&lt;/groupId&gt; &lt;artifactId&gt;spring-jdbc&lt;/artifactId&gt; &lt;version&gt;${org.springframework.version}&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework&lt;/groupId&gt; &lt;artifactId&gt;spring-orm&lt;/artifactId&gt; &lt;version&gt;${org.springframework.version}&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework&lt;/groupId&gt; &lt;artifactId&gt;spring-oxm&lt;/artifactId&gt; &lt;version&gt;${org.springframework.version}&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework&lt;/groupId&gt; &lt;artifactId&gt;spring-web&lt;/artifactId&gt; &lt;version&gt;${org.springframework.version}&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework&lt;/groupId&gt; &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt; &lt;version&gt;${org.springframework.version}&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework&lt;/groupId&gt; &lt;artifactId&gt;spring-instrument&lt;/artifactId&gt; &lt;version&gt;${org.springframework.version}&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework.security&lt;/groupId&gt; &lt;artifactId&gt;spring-security-core&lt;/artifactId&gt; &lt;version&gt;${org.springframework.version}&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework.security&lt;/groupId&gt; &lt;artifactId&gt;spring-security-web&lt;/artifactId&gt; &lt;version&gt;${org.springframework.version}&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework.security&lt;/groupId&gt; &lt;artifactId&gt;spring-security-taglibs&lt;/artifactId&gt; &lt;version&gt;${org.springframework.version}&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework.security&lt;/groupId&gt; &lt;artifactId&gt;spring-security-config&lt;/artifactId&gt; &lt;version&gt;${org.springframework.version}&lt;/version&gt; &lt;scope&gt;system&lt;/scope&gt; &lt;systemPath&gt;${basedir}/lib/spring-security-config-3.0.5.RELEASE.jar&lt;/systemPath&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;javax.servlet&lt;/groupId&gt; &lt;artifactId&gt;servlet-api&lt;/artifactId&gt; &lt;version&gt;2.5&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.hibernate&lt;/groupId&gt; &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt; &lt;version&gt;${hibernate.version}&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.hibernate&lt;/groupId&gt; &lt;artifactId&gt;hibernate-annotations&lt;/artifactId&gt; &lt;version&gt;3.4.0.GA&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.hibernate&lt;/groupId&gt; &lt;artifactId&gt;ejb3-persistence&lt;/artifactId&gt; &lt;version&gt;1.0.2.GA&lt;/version&gt; &lt;type&gt;pom&lt;/type&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.slf4j&lt;/groupId&gt; &lt;artifactId&gt;slf4j-log4j12&lt;/artifactId&gt; &lt;version&gt;1.6.1&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;commons-logging&lt;/groupId&gt; &lt;artifactId&gt;commons-logging&lt;/artifactId&gt; &lt;version&gt;1.1.1&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;commons-dbcp&lt;/groupId&gt; &lt;artifactId&gt;commons-dbcp&lt;/artifactId&gt; &lt;version&gt;1.4&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;jdom&lt;/groupId&gt; &lt;artifactId&gt;jdom&lt;/artifactId&gt; &lt;version&gt;1.1&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;commons-lang&lt;/groupId&gt; &lt;artifactId&gt;commons-lang&lt;/artifactId&gt; &lt;version&gt;2.4&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.hibernate&lt;/groupId&gt; &lt;artifactId&gt;hibernate-search&lt;/artifactId&gt; &lt;version&gt;3.1.0.GA&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.apache.solr&lt;/groupId&gt; &lt;artifactId&gt;solr-common&lt;/artifactId&gt; &lt;version&gt;1.3.0&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.apache.solr&lt;/groupId&gt; &lt;artifactId&gt;solr-core&lt;/artifactId&gt; &lt;version&gt;1.3.0&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.apache.lucene&lt;/groupId&gt; &lt;artifactId&gt;lucene-snowball&lt;/artifactId&gt; &lt;version&gt;2.4.1&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;javax.transaction&lt;/groupId&gt; &lt;artifactId&gt;jta&lt;/artifactId&gt; &lt;version&gt;1.0.1B&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;junit&lt;/groupId&gt; &lt;artifactId&gt;junit&lt;/artifactId&gt; &lt;version&gt;4.4&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework&lt;/groupId&gt; &lt;artifactId&gt;spring-test&lt;/artifactId&gt; &lt;version&gt;2.5.6.SEC01&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;memcached&lt;/groupId&gt; &lt;artifactId&gt;memcached&lt;/artifactId&gt; &lt;version&gt;2.3.1&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.aspectj&lt;/groupId&gt; &lt;artifactId&gt;aspectjrt&lt;/artifactId&gt; &lt;version&gt;1.6.5&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;redis.clients&lt;/groupId&gt; &lt;artifactId&gt;jedis&lt;/artifactId&gt; &lt;version&gt;1.5.2&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;voldemort&lt;/groupId&gt; &lt;artifactId&gt;voldemort&lt;/artifactId&gt; &lt;version&gt;0.81&lt;/version&gt; &lt;/dependency&gt; &lt;/dependencies&gt; &lt;/project&gt; </code></pre> <p>I then checked on my Mac <code>/Users/XYZ/.m2</code> and all jar files are in place as expected.</p> <p>I am using the current Maven release shipped with STS. I also enabled debug output but there was nothing suspicious.</p>
6,112,344
35
1
null
2011-05-24 13:47:12.213 UTC
52
2022-05-31 13:14:00.07 UTC
2015-11-13 07:41:19.917 UTC
null
3,885,376
null
739,356
null
1
148
eclipse|maven|m2eclipse|sts-springsourcetoolsuite
593,223
<p>There are a few other options apart from <strong>Project</strong>-><strong>Clean</strong>, some of which are more along the lines of turning it off and on again. </p> <ul> <li>Try right-clicking on the project and selecting <strong>Maven</strong>-><strong>Update Project Configuration</strong>.</li> <li>Disable then re-enable dependency management (right-click <strong>Maven</strong>-><strong>Disable Dependency Management</strong> then <strong>Maven</strong>-><strong>Enable Dependency Management</strong></li> <li>Close the project and reopen it.</li> <li>Check that your Maven settings are configured correctly. If you are behind a proxy you'll need to <a href="http://maven.apache.org/guides/mini/guide-proxies.html" rel="noreferrer">configure the proxy settings</a> in the global or user settings.</li> <li>Check you're using the Maven installation you expect. By default m2eclipse uses the embedder, if you have a separate installation you may want to <a href="https://books.sonatype.com/m2eclipse-book/reference/preferences.html#preferences-sect-maven-preferences" rel="noreferrer">configure m2eclipse</a> to use the external installation so that CLI and Eclipse builds are consistent. This also ensures you're configured to connect through any proxy as above.</li> </ul>
55,839,111
Installing psycopg2 fails on MacOS with unclear error message
<p>Trying to install psycopg2 using pip 19.1 on MacOS 10.14.4 returns the lengthy error message below. I understand there are warnings related to gcc, but given the actual error messages I cannot find any clues what the underlying problem is. </p> <p>I have tried the following actions without any luck:</p> <ul> <li>Upgraded Xcode to the latest version (10.2.1)</li> <li>Upgrade Postgresql to 11.2.1</li> <li>Uninstalled psycopg2-binary to prevent any dependency issues</li> <li>Cleared all files left by a previously successful install at <code>/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages</code> (Yes, I had it installed at some point and it worked, not sure why I uninstalled)</li> </ul> <p>There seem to be quite some issues around pip and psycopg2 but no question I found on Stackoverflow showed similar error messages, nor did any of the suggested fixes help. Any pointers to potential fixes are very much appreciated!</p> <pre><code>pip install psycopg2 Collecting psycopg2 Using cached https://files.pythonhosted.org/packages/23/7e/93c325482c328619870b6cd09370f6dbe1148283daca65115cd63642e60f/psycopg2-2.8.2.tar.gz Installing collected packages: psycopg2 Running setup.py install for psycopg2 ... error ERROR: Complete output from command /Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7 -u -c 'import setuptools, tokenize;__file__='"'"'/private/var/folders/y4/3pcgz9d54zj29hfq1lmlxpk80000gn/T/pip-install-ci93cz6u/psycopg2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/y4/3pcgz9d54zj29hfq1lmlxpk80000gn/T/pip-record-ztnpuu7u/install-record.txt --single-version-externally-managed --compile: ERROR: running install running build running build_py creating build creating build/lib.macosx-10.9-x86_64-3.7 creating build/lib.macosx-10.9-x86_64-3.7/psycopg2 copying lib/_json.py -&gt; build/lib.macosx-10.9-x86_64-3.7/psycopg2 copying lib/extras.py -&gt; build/lib.macosx-10.9-x86_64-3.7/psycopg2 copying lib/compat.py -&gt; build/lib.macosx-10.9-x86_64-3.7/psycopg2 copying lib/errorcodes.py -&gt; build/lib.macosx-10.9-x86_64-3.7/psycopg2 copying lib/tz.py -&gt; build/lib.macosx-10.9-x86_64-3.7/psycopg2 copying lib/_range.py -&gt; build/lib.macosx-10.9-x86_64-3.7/psycopg2 copying lib/_ipaddress.py -&gt; build/lib.macosx-10.9-x86_64-3.7/psycopg2 copying lib/_lru_cache.py -&gt; build/lib.macosx-10.9-x86_64-3.7/psycopg2 copying lib/__init__.py -&gt; build/lib.macosx-10.9-x86_64-3.7/psycopg2 copying lib/extensions.py -&gt; build/lib.macosx-10.9-x86_64-3.7/psycopg2 copying lib/errors.py -&gt; build/lib.macosx-10.9-x86_64-3.7/psycopg2 copying lib/sql.py -&gt; build/lib.macosx-10.9-x86_64-3.7/psycopg2 copying lib/pool.py -&gt; build/lib.macosx-10.9-x86_64-3.7/psycopg2 running build_ext building 'psycopg2._psycopg' extension creating build/temp.macosx-10.9-x86_64-3.7 creating build/temp.macosx-10.9-x86_64-3.7/psycopg gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.2 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=110002 -DHAVE_LO64=1 -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -I. -I/usr/local/Cellar/postgresql/11.2_1/include -I/usr/local/Cellar/postgresql/11.2_1/include/server -c psycopg/psycopgmodule.c -o build/temp.macosx-10.9-x86_64-3.7/psycopg/psycopgmodule.o gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.2 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=110002 -DHAVE_LO64=1 -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -I. -I/usr/local/Cellar/postgresql/11.2_1/include -I/usr/local/Cellar/postgresql/11.2_1/include/server -c psycopg/green.c -o build/temp.macosx-10.9-x86_64-3.7/psycopg/green.o gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.2 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=110002 -DHAVE_LO64=1 -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -I. -I/usr/local/Cellar/postgresql/11.2_1/include -I/usr/local/Cellar/postgresql/11.2_1/include/server -c psycopg/pqpath.c -o build/temp.macosx-10.9-x86_64-3.7/psycopg/pqpath.o psycopg/pqpath.c:135:17: warning: implicit conversion from enumeration type 'ConnStatusType' to different enumeration type 'ExecStatusType' [-Wenum-conversion] PQstatus(conn-&gt;pgconn) : PQresultStatus(*pgres))); ^~~~~~~~~~~~~~~~~~~~~~ psycopg/pqpath.c:1710:11: warning: code will never be executed [-Wunreachable-code] ret = 1; ^ psycopg/pqpath.c:1815:17: warning: implicit conversion from enumeration type 'ConnStatusType' to different enumeration type 'ExecStatusType' [-Wenum-conversion] PQstatus(curs-&gt;conn-&gt;pgconn) : PQresultStatus(curs-&gt;pgres))); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3 warnings generated. gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.2 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=110002 -DHAVE_LO64=1 -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -I. -I/usr/local/Cellar/postgresql/11.2_1/include -I/usr/local/Cellar/postgresql/11.2_1/include/server -c psycopg/utils.c -o build/temp.macosx-10.9-x86_64-3.7/psycopg/utils.o gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.2 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=110002 -DHAVE_LO64=1 -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -I. -I/usr/local/Cellar/postgresql/11.2_1/include -I/usr/local/Cellar/postgresql/11.2_1/include/server -c psycopg/bytes_format.c -o build/temp.macosx-10.9-x86_64-3.7/psycopg/bytes_format.o In file included from psycopg/bytes_format.c:81: In file included from ./psycopg/psycopg.h:37: ./psycopg/config.h:81:13: warning: unused function 'Dprintf' [-Wunused-function] static void Dprintf(const char *fmt, ...) {} ^ 1 warning generated. gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.2 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=110002 -DHAVE_LO64=1 -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -I. -I/usr/local/Cellar/postgresql/11.2_1/include -I/usr/local/Cellar/postgresql/11.2_1/include/server -c psycopg/libpq_support.c -o build/temp.macosx-10.9-x86_64-3.7/psycopg/libpq_support.o In file included from psycopg/libpq_support.c:29: In file included from ./psycopg/psycopg.h:37: ./psycopg/config.h:81:13: warning: unused function 'Dprintf' [-Wunused-function] static void Dprintf(const char *fmt, ...) {} ^ 1 warning generated. gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.2 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=110002 -DHAVE_LO64=1 -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -I. -I/usr/local/Cellar/postgresql/11.2_1/include -I/usr/local/Cellar/postgresql/11.2_1/include/server -c psycopg/win32_support.c -o build/temp.macosx-10.9-x86_64-3.7/psycopg/win32_support.o In file included from psycopg/win32_support.c:27: In file included from ./psycopg/psycopg.h:37: ./psycopg/config.h:81:13: warning: unused function 'Dprintf' [-Wunused-function] static void Dprintf(const char *fmt, ...) {} ^ 1 warning generated. gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.2 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=110002 -DHAVE_LO64=1 -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -I. -I/usr/local/Cellar/postgresql/11.2_1/include -I/usr/local/Cellar/postgresql/11.2_1/include/server -c psycopg/solaris_support.c -o build/temp.macosx-10.9-x86_64-3.7/psycopg/solaris_support.o In file included from psycopg/solaris_support.c:28: In file included from ./psycopg/psycopg.h:37: ./psycopg/config.h:81:13: warning: unused function 'Dprintf' [-Wunused-function] static void Dprintf(const char *fmt, ...) {} ^ 1 warning generated. gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.2 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=110002 -DHAVE_LO64=1 -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -I. -I/usr/local/Cellar/postgresql/11.2_1/include -I/usr/local/Cellar/postgresql/11.2_1/include/server -c psycopg/connection_int.c -o build/temp.macosx-10.9-x86_64-3.7/psycopg/connection_int.o gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.2 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=110002 -DHAVE_LO64=1 -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -I. -I/usr/local/Cellar/postgresql/11.2_1/include -I/usr/local/Cellar/postgresql/11.2_1/include/server -c psycopg/connection_type.c -o build/temp.macosx-10.9-x86_64-3.7/psycopg/connection_type.o gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.2 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=110002 -DHAVE_LO64=1 -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -I. -I/usr/local/Cellar/postgresql/11.2_1/include -I/usr/local/Cellar/postgresql/11.2_1/include/server -c psycopg/cursor_int.c -o build/temp.macosx-10.9-x86_64-3.7/psycopg/cursor_int.o gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.2 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=110002 -DHAVE_LO64=1 -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -I. -I/usr/local/Cellar/postgresql/11.2_1/include -I/usr/local/Cellar/postgresql/11.2_1/include/server -c psycopg/cursor_type.c -o build/temp.macosx-10.9-x86_64-3.7/psycopg/cursor_type.o gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.2 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=110002 -DHAVE_LO64=1 -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -I. -I/usr/local/Cellar/postgresql/11.2_1/include -I/usr/local/Cellar/postgresql/11.2_1/include/server -c psycopg/column_type.c -o build/temp.macosx-10.9-x86_64-3.7/psycopg/column_type.o In file included from psycopg/column_type.c:27: In file included from ./psycopg/psycopg.h:37: ./psycopg/config.h:81:13: warning: unused function 'Dprintf' [-Wunused-function] static void Dprintf(const char *fmt, ...) {} ^ 1 warning generated. gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.2 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=110002 -DHAVE_LO64=1 -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -I. -I/usr/local/Cellar/postgresql/11.2_1/include -I/usr/local/Cellar/postgresql/11.2_1/include/server -c psycopg/replication_connection_type.c -o build/temp.macosx-10.9-x86_64-3.7/psycopg/replication_connection_type.o In file included from psycopg/replication_connection_type.c:27: In file included from ./psycopg/psycopg.h:37: ./psycopg/config.h:81:13: warning: unused function 'Dprintf' [-Wunused-function] static void Dprintf(const char *fmt, ...) {} ^ 1 warning generated. gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.2 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=110002 -DHAVE_LO64=1 -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -I. -I/usr/local/Cellar/postgresql/11.2_1/include -I/usr/local/Cellar/postgresql/11.2_1/include/server -c psycopg/replication_cursor_type.c -o build/temp.macosx-10.9-x86_64-3.7/psycopg/replication_cursor_type.o gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.2 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=110002 -DHAVE_LO64=1 -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -I. -I/usr/local/Cellar/postgresql/11.2_1/include -I/usr/local/Cellar/postgresql/11.2_1/include/server -c psycopg/replication_message_type.c -o build/temp.macosx-10.9-x86_64-3.7/psycopg/replication_message_type.o In file included from psycopg/replication_message_type.c:27: In file included from ./psycopg/psycopg.h:37: ./psycopg/config.h:81:13: warning: unused function 'Dprintf' [-Wunused-function] static void Dprintf(const char *fmt, ...) {} ^ 1 warning generated. gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.2 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=110002 -DHAVE_LO64=1 -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -I. -I/usr/local/Cellar/postgresql/11.2_1/include -I/usr/local/Cellar/postgresql/11.2_1/include/server -c psycopg/diagnostics_type.c -o build/temp.macosx-10.9-x86_64-3.7/psycopg/diagnostics_type.o In file included from psycopg/diagnostics_type.c:27: In file included from ./psycopg/psycopg.h:37: ./psycopg/config.h:81:13: warning: unused function 'Dprintf' [-Wunused-function] static void Dprintf(const char *fmt, ...) {} ^ 1 warning generated. gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.2 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=110002 -DHAVE_LO64=1 -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -I. -I/usr/local/Cellar/postgresql/11.2_1/include -I/usr/local/Cellar/postgresql/11.2_1/include/server -c psycopg/error_type.c -o build/temp.macosx-10.9-x86_64-3.7/psycopg/error_type.o In file included from psycopg/error_type.c:27: In file included from ./psycopg/psycopg.h:37: ./psycopg/config.h:81:13: warning: unused function 'Dprintf' [-Wunused-function] static void Dprintf(const char *fmt, ...) {} ^ 1 warning generated. gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.2 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=110002 -DHAVE_LO64=1 -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -I. -I/usr/local/Cellar/postgresql/11.2_1/include -I/usr/local/Cellar/postgresql/11.2_1/include/server -c psycopg/conninfo_type.c -o build/temp.macosx-10.9-x86_64-3.7/psycopg/conninfo_type.o In file included from psycopg/conninfo_type.c:27: In file included from ./psycopg/psycopg.h:37: ./psycopg/config.h:81:13: warning: unused function 'Dprintf' [-Wunused-function] static void Dprintf(const char *fmt, ...) {} ^ 1 warning generated. gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.2 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=110002 -DHAVE_LO64=1 -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -I. -I/usr/local/Cellar/postgresql/11.2_1/include -I/usr/local/Cellar/postgresql/11.2_1/include/server -c psycopg/lobject_int.c -o build/temp.macosx-10.9-x86_64-3.7/psycopg/lobject_int.o gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.2 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=110002 -DHAVE_LO64=1 -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -I. -I/usr/local/Cellar/postgresql/11.2_1/include -I/usr/local/Cellar/postgresql/11.2_1/include/server -c psycopg/lobject_type.c -o build/temp.macosx-10.9-x86_64-3.7/psycopg/lobject_type.o gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.2 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=110002 -DHAVE_LO64=1 -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -I. -I/usr/local/Cellar/postgresql/11.2_1/include -I/usr/local/Cellar/postgresql/11.2_1/include/server -c psycopg/notify_type.c -o build/temp.macosx-10.9-x86_64-3.7/psycopg/notify_type.o In file included from psycopg/notify_type.c:27: In file included from ./psycopg/psycopg.h:37: ./psycopg/config.h:81:13: warning: unused function 'Dprintf' [-Wunused-function] static void Dprintf(const char *fmt, ...) {} ^ 1 warning generated. gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.2 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=110002 -DHAVE_LO64=1 -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -I. -I/usr/local/Cellar/postgresql/11.2_1/include -I/usr/local/Cellar/postgresql/11.2_1/include/server -c psycopg/xid_type.c -o build/temp.macosx-10.9-x86_64-3.7/psycopg/xid_type.o gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.2 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=110002 -DHAVE_LO64=1 -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -I. -I/usr/local/Cellar/postgresql/11.2_1/include -I/usr/local/Cellar/postgresql/11.2_1/include/server -c psycopg/adapter_asis.c -o build/temp.macosx-10.9-x86_64-3.7/psycopg/adapter_asis.o gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.2 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=110002 -DHAVE_LO64=1 -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -I. -I/usr/local/Cellar/postgresql/11.2_1/include -I/usr/local/Cellar/postgresql/11.2_1/include/server -c psycopg/adapter_binary.c -o build/temp.macosx-10.9-x86_64-3.7/psycopg/adapter_binary.o gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.2 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=110002 -DHAVE_LO64=1 -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -I. -I/usr/local/Cellar/postgresql/11.2_1/include -I/usr/local/Cellar/postgresql/11.2_1/include/server -c psycopg/adapter_datetime.c -o build/temp.macosx-10.9-x86_64-3.7/psycopg/adapter_datetime.o gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.2 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=110002 -DHAVE_LO64=1 -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -I. -I/usr/local/Cellar/postgresql/11.2_1/include -I/usr/local/Cellar/postgresql/11.2_1/include/server -c psycopg/adapter_list.c -o build/temp.macosx-10.9-x86_64-3.7/psycopg/adapter_list.o gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.2 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=110002 -DHAVE_LO64=1 -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -I. -I/usr/local/Cellar/postgresql/11.2_1/include -I/usr/local/Cellar/postgresql/11.2_1/include/server -c psycopg/adapter_pboolean.c -o build/temp.macosx-10.9-x86_64-3.7/psycopg/adapter_pboolean.o gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.2 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=110002 -DHAVE_LO64=1 -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -I. -I/usr/local/Cellar/postgresql/11.2_1/include -I/usr/local/Cellar/postgresql/11.2_1/include/server -c psycopg/adapter_pdecimal.c -o build/temp.macosx-10.9-x86_64-3.7/psycopg/adapter_pdecimal.o gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.2 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=110002 -DHAVE_LO64=1 -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -I. -I/usr/local/Cellar/postgresql/11.2_1/include -I/usr/local/Cellar/postgresql/11.2_1/include/server -c psycopg/adapter_pint.c -o build/temp.macosx-10.9-x86_64-3.7/psycopg/adapter_pint.o gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.2 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=110002 -DHAVE_LO64=1 -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -I. -I/usr/local/Cellar/postgresql/11.2_1/include -I/usr/local/Cellar/postgresql/11.2_1/include/server -c psycopg/adapter_pfloat.c -o build/temp.macosx-10.9-x86_64-3.7/psycopg/adapter_pfloat.o gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.2 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=110002 -DHAVE_LO64=1 -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -I. -I/usr/local/Cellar/postgresql/11.2_1/include -I/usr/local/Cellar/postgresql/11.2_1/include/server -c psycopg/adapter_qstring.c -o build/temp.macosx-10.9-x86_64-3.7/psycopg/adapter_qstring.o gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.2 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=110002 -DHAVE_LO64=1 -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -I. -I/usr/local/Cellar/postgresql/11.2_1/include -I/usr/local/Cellar/postgresql/11.2_1/include/server -c psycopg/microprotocols.c -o build/temp.macosx-10.9-x86_64-3.7/psycopg/microprotocols.o gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.2 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=110002 -DHAVE_LO64=1 -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -I. -I/usr/local/Cellar/postgresql/11.2_1/include -I/usr/local/Cellar/postgresql/11.2_1/include/server -c psycopg/microprotocols_proto.c -o build/temp.macosx-10.9-x86_64-3.7/psycopg/microprotocols_proto.o In file included from psycopg/microprotocols_proto.c:27: In file included from ./psycopg/psycopg.h:37: ./psycopg/config.h:81:13: warning: unused function 'Dprintf' [-Wunused-function] static void Dprintf(const char *fmt, ...) {} ^ 1 warning generated. gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.2 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=110002 -DHAVE_LO64=1 -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -I. -I/usr/local/Cellar/postgresql/11.2_1/include -I/usr/local/Cellar/postgresql/11.2_1/include/server -c psycopg/typecast.c -o build/temp.macosx-10.9-x86_64-3.7/psycopg/typecast.o gcc -bundle -undefined dynamic_lookup -arch x86_64 -g build/temp.macosx-10.9-x86_64-3.7/psycopg/psycopgmodule.o build/temp.macosx-10.9-x86_64-3.7/psycopg/green.o build/temp.macosx-10.9-x86_64-3.7/psycopg/pqpath.o build/temp.macosx-10.9-x86_64-3.7/psycopg/utils.o build/temp.macosx-10.9-x86_64-3.7/psycopg/bytes_format.o build/temp.macosx-10.9-x86_64-3.7/psycopg/libpq_support.o build/temp.macosx-10.9-x86_64-3.7/psycopg/win32_support.o build/temp.macosx-10.9-x86_64-3.7/psycopg/solaris_support.o build/temp.macosx-10.9-x86_64-3.7/psycopg/connection_int.o build/temp.macosx-10.9-x86_64-3.7/psycopg/connection_type.o build/temp.macosx-10.9-x86_64-3.7/psycopg/cursor_int.o build/temp.macosx-10.9-x86_64-3.7/psycopg/cursor_type.o build/temp.macosx-10.9-x86_64-3.7/psycopg/column_type.o build/temp.macosx-10.9-x86_64-3.7/psycopg/replication_connection_type.o build/temp.macosx-10.9-x86_64-3.7/psycopg/replication_cursor_type.o build/temp.macosx-10.9-x86_64-3.7/psycopg/replication_message_type.o build/temp.macosx-10.9-x86_64-3.7/psycopg/diagnostics_type.o build/temp.macosx-10.9-x86_64-3.7/psycopg/error_type.o build/temp.macosx-10.9-x86_64-3.7/psycopg/conninfo_type.o build/temp.macosx-10.9-x86_64-3.7/psycopg/lobject_int.o build/temp.macosx-10.9-x86_64-3.7/psycopg/lobject_type.o build/temp.macosx-10.9-x86_64-3.7/psycopg/notify_type.o build/temp.macosx-10.9-x86_64-3.7/psycopg/xid_type.o build/temp.macosx-10.9-x86_64-3.7/psycopg/adapter_asis.o build/temp.macosx-10.9-x86_64-3.7/psycopg/adapter_binary.o build/temp.macosx-10.9-x86_64-3.7/psycopg/adapter_datetime.o build/temp.macosx-10.9-x86_64-3.7/psycopg/adapter_list.o build/temp.macosx-10.9-x86_64-3.7/psycopg/adapter_pboolean.o build/temp.macosx-10.9-x86_64-3.7/psycopg/adapter_pdecimal.o build/temp.macosx-10.9-x86_64-3.7/psycopg/adapter_pint.o build/temp.macosx-10.9-x86_64-3.7/psycopg/adapter_pfloat.o build/temp.macosx-10.9-x86_64-3.7/psycopg/adapter_qstring.o build/temp.macosx-10.9-x86_64-3.7/psycopg/microprotocols.o build/temp.macosx-10.9-x86_64-3.7/psycopg/microprotocols_proto.o build/temp.macosx-10.9-x86_64-3.7/psycopg/typecast.o -L/usr/local/lib -lpq -lssl -lcrypto -o build/lib.macosx-10.9-x86_64-3.7/psycopg2/_psycopg.cpython-37m-darwin.so ld: library not found for -lssl clang: error: linker command failed with exit code 1 (use -v to see invocation) error: command 'gcc' failed with exit status 1 ---------------------------------------- ERROR: Command "/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7 -u -c 'import setuptools, tokenize;__file__='"'"'/private/var/folders/y4/3pcgz9d54zj29hfq1lmlxpk80000gn/T/pip-install-ci93cz6u/psycopg2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/y4/3pcgz9d54zj29hfq1lmlxpk80000gn/T/pip-record-ztnpuu7u/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/y4/3pcgz9d54zj29hfq1lmlxpk80000gn/T/pip-install-ci93cz6u/psycopg2/ </code></pre>
55,839,410
3
5
null
2019-04-24 21:54:41.037 UTC
9
2019-11-29 13:12:57.517 UTC
null
null
null
null
11,159,842
null
1
14
postgresql|macos|pip|psycopg2
6,876
<p>Thanks for adding the error log, without which it would have been very hard to find the issue. Nice work.</p> <p>This part of the log was really interesting:</p> <pre><code> gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.2 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=110002 -DHAVE_LO64=1 -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -I. -I/usr/local/Cellar/postgresql/11.2_1/include -I/usr/local/Cellar/postgresql/11.2_1/include/server -c psycopg/typecast.c -o build/temp.macosx-10.9-x86_64-3.7/psycopg/typecast.o gcc -bundle -undefined dynamic_lookup -arch x86_64 -g build/temp.macosx-10.9-x86_64-3.7/psycopg/psycopgmodule.o build/temp.macosx-10.9-x86_64-3.7/psycopg/green.o build/temp.macosx-10.9-x86_64-3.7/psycopg/pqpath.o build/temp.macosx-10.9-x86_64-3.7/psycopg/utils.o build/temp.macosx-10.9-x86_64-3.7/psycopg/bytes_format.o build/temp.macosx-10.9-x86_64-3.7/psycopg/libpq_support.o build/temp.macosx-10.9-x86_64-3.7/psycopg/win32_support.o build/temp.macosx-10.9-x86_64-3.7/psycopg/solaris_support.o build/temp.macosx-10.9-x86_64-3.7/psycopg/connection_int.o build/temp.macosx-10.9-x86_64-3.7/psycopg/connection_type.o build/temp.macosx-10.9-x86_64-3.7/psycopg/cursor_int.o build/temp.macosx-10.9-x86_64-3.7/psycopg/cursor_type.o build/temp.macosx-10.9-x86_64-3.7/psycopg/column_type.o build/temp.macosx-10.9-x86_64-3.7/psycopg/replication_connection_type.o build/temp.macosx-10.9-x86_64-3.7/psycopg/replication_cursor_type.o build/temp.macosx-10.9-x86_64-3.7/psycopg/replication_message_type.o build/temp.macosx-10.9-x86_64-3.7/psycopg/diagnostics_type.o build/temp.macosx-10.9-x86_64-3.7/psycopg/error_type.o build/temp.macosx-10.9-x86_64-3.7/psycopg/conninfo_type.o build/temp.macosx-10.9-x86_64-3.7/psycopg/lobject_int.o build/temp.macosx-10.9-x86_64-3.7/psycopg/lobject_type.o build/temp.macosx-10.9-x86_64-3.7/psycopg/notify_type.o build/temp.macosx-10.9-x86_64-3.7/psycopg/xid_type.o build/temp.macosx-10.9-x86_64-3.7/psycopg/adapter_asis.o build/temp.macosx-10.9-x86_64-3.7/psycopg/adapter_binary.o build/temp.macosx-10.9-x86_64-3.7/psycopg/adapter_datetime.o build/temp.macosx-10.9-x86_64-3.7/psycopg/adapter_list.o build/temp.macosx-10.9-x86_64-3.7/psycopg/adapter_pboolean.o build/temp.macosx-10.9-x86_64-3.7/psycopg/adapter_pdecimal.o build/temp.macosx-10.9-x86_64-3.7/psycopg/adapter_pint.o build/temp.macosx-10.9-x86_64-3.7/psycopg/adapter_pfloat.o build/temp.macosx-10.9-x86_64-3.7/psycopg/adapter_qstring.o build/temp.macosx-10.9-x86_64-3.7/psycopg/microprotocols.o build/temp.macosx-10.9-x86_64-3.7/psycopg/microprotocols_proto.o build/temp.macosx-10.9-x86_64-3.7/psycopg/typecast.o -L/usr/local/lib -lpq -lssl -lcrypto -o build/lib.macosx-10.9-x86_64-3.7/psycopg2/_psycopg.cpython-37m-darwin.so ld: library not found for -lssl </code></pre> <p>The 2nd <code>gcc</code> had a mention of this:</p> <pre><code>-L/usr/local/lib -lpq -lssl -lcrypto -o ... </code></pre> <p>That means, compilation process was looking for a library (<code>-l</code>) that happens to be <code>ssl</code>. See gcc manual (<a href="https://linux.die.net/man/1/gcc" rel="noreferrer">https://linux.die.net/man/1/gcc</a>). It says that <code>-l</code> is to search the library named library (in our case <code>ssl</code>) when linking.</p> <p>Something with <code>ssl</code> library was missing.</p> <p>Google search lead to a reported issue: <a href="https://github.com/psycopg/psycopg2/issues/492" rel="noreferrer">https://github.com/psycopg/psycopg2/issues/492</a>. Joe Kemp's answer (<a href="https://github.com/psycopg/psycopg2/issues/492#issuecomment-278481164" rel="noreferrer">https://github.com/psycopg/psycopg2/issues/492#issuecomment-278481164</a>) suggests setting an environment variable like so:</p> <pre><code>export LDFLAGS="-L/usr/local/opt/openssl/lib" </code></pre> <p>Other options were listed here: <a href="https://stackoverflow.com/questions/9678408/cant-install-psycopg2-with-pip-in-virtualenv-on-mac-os-x-10-7">Can&#39;t install psycopg2 with pip in virtualenv on Mac OS X 10.7</a>.</p> <p>It appears that your setting LDFLAGS solved the issue.</p>
44,257,660
Azure Functions - Limiting parallel execution
<p>Is it possible to limit the maximum number of Functions that run in parallel?</p> <p>I read the documentation and came across this:</p> <blockquote> <p>When multiple triggering events occur faster than a single-threaded function runtime can process them, the runtime may invoke the function multiple times in parallel.</p> <p>If a function app is using the Consumption hosting plan, the function app could scale out automatically. Each instance of the function app, whether the app runs on the Consumption hosting plan or a regular App Service hosting plan, might process concurrent function invocations in parallel using multiple threads.</p> <p>The maximum number of concurrent function invocations in each function app instance varies based on the type of trigger being used as well as the resources used by other functions within the function app.</p> </blockquote> <p><a href="https://docs.microsoft.com/en-gb/azure/azure-functions/functions-reference#parallel-execution" rel="noreferrer">https://docs.microsoft.com/en-gb/azure/azure-functions/functions-reference#parallel-execution</a></p> <p>I am using a Function on an App Service plan with an Event Hub input binding and only have a single Function within my Function App. If I can't limit it, does anyone know what the maximum number of concurrent function invocations will be for this kind of setup?</p>
44,269,471
4
0
null
2017-05-30 08:52:11.103 UTC
5
2021-04-06 17:25:05.707 UTC
2020-06-20 09:12:55.06 UTC
null
-1
null
2,854,993
null
1
37
azure|azure-functions
42,988
<p>There isn't a way to specify a maximum concurrency for Event Hubs triggered functions, but you can control batch size and fetching options as <a href="https://github.com/Azure/azure-webjobs-sdk-script/wiki/host.json" rel="noreferrer">described here</a>.</p> <p>The maximum number of concurrent invocations may also vary depending on your workload and resource utilization.</p> <p>If concurrency limits are needed, this is (currently) something you'd need to handle, and the following posts discuss some patterns you may find useful:</p> <p><a href="https://stackoverflow.com/questions/40094041/throttling-azure-storage-queue-processing-in-azure-function-app">Throttling Azure Storage Queue processing in Azure Function App</a></p> <p><a href="https://stackoverflow.com/questions/42234413/limiting-the-number-of-concurrent-jobs-on-azure-functions-queue">Limiting the number of concurrent jobs on Azure Functions queue</a></p>
43,930,011
Sort by memory usage in docker stats
<p>Is there a way to display the docker stats sorted by memory usage of the containers?</p> <p>I am using the following command to display the container with their names and I want to sort the result by memory usage.</p> <pre><code>docker stats --format "table {{.Name}}\t{{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}" </code></pre> <p>The unsorted result is the following.</p> <pre><code>NAME CONTAINER CPU % MEM USAGE / LIMIT kafka3.interactive.8a38c338742464ffb04d6f23fc6485391318d103 0d68b7fd49a0 1.39% 359.5 MiB / 4.833 GiB kafka2.interactive.8a38c338742464ffb04d6f23fc6485391318d103 7e5541b0b883 1.22% 309.4 MiB / 4.833 GiB kafka1.interactive.8a38c338742464ffb04d6f23fc6485391318d103 dff07c6d639c 0.68% 267.4 MiB / 4.833 GiB service2.interactive.8a38c338742464ffb04d6f23fc6485391318d103 0f20a7e75823 0.06% 617.8 MiB / 4.833 GiB consulakms.interactive.8a38c338742464ffb04d6f23fc6485391318d103 b5972262194d 3.82% 10.32 MiB / 4.833 GiB service1.interactive.8a38c338742464ffb04d6f23fc6485391318d103 be56185a37bf 0.09% 596.3 MiB / 4.833 GiB consumer1.interactive.8a38c338742464ffb04d6f23fc6485391318d103 05145beb209c 0.06% 574.6 MiB / 4.833 GiB consul1.interactive.8a38c338742464ffb04d6f23fc6485391318d103 3298a8159064 0.67% 10.57 MiB / 4.833 GiB consul3.interactive.8a38c338742464ffb04d6f23fc6485391318d103 4a1bbbd131ad 3.12% 9.664 MiB / 4.833 GiB zookeeper2.interactive.8a38c338742464ffb04d6f23fc6485391318d103 040f00b4bbc7 0.09% 42.45 MiB / 4.833 GiB consulbootstrap.interactive.8a38c338742464ffb04d6f23fc6485391318d103 45268a11f2f4 3.62% 11.46 MiB / 4.833 GiB zookeeper3.interactive.8a38c338742464ffb04d6f23fc6485391318d103 331772b27079 0.12% 51.27 MiB / 4.833 GiB consul2.interactive.8a38c338742464ffb04d6f23fc6485391318d103 77b63171e6b5 1.07% 12.59 MiB / 4.833 GiB zookeeper1.interactive.8a38c338742464ffb04d6f23fc6485391318d103 c5ad82730598 0.08% 43.17 MiB / 4.833 GiB service3.interactive.8a38c338742464ffb04d6f23fc6485391318d103 610da86c6949 3.79% 546.7 MiB / 4.833 GiB squid.interactive.8a38c338742464ffb04d6f23fc6485391318d103 928ddbb197fa 0.01% 144.2 MiB / 4.833 GiB </code></pre>
43,932,310
5
1
null
2017-05-12 05:35:45.973 UTC
7
2022-01-22 16:59:01.673 UTC
2017-05-12 08:42:52.343 UTC
null
1,630,604
null
1,630,604
null
1
30
docker
17,213
<p>To sort by <code>Mem Usage</code> field you can use the following command: </p> <p>GNU/Linux:</p> <p><code>docker stats --no-stream --format "table {{.Name}}\t{{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}" | sort -k 4 -h</code></p> <p>MacOS:</p> <p><code>docker stats --no-stream --format "table {{.Name}}\t{{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.M‌​emPerc}}" | sort -k 9 -n</code></p> <p>Check this link to view all available options to <code>--format</code> option of <code>docker stats</code>: <a href="https://docs.docker.com/engine/reference/commandline/stats/#formatting" rel="noreferrer">https://docs.docker.com/engine/reference/commandline/stats/#formatting</a></p>
49,773,231
Typescript:Cannot invoke an expression whose type lacks a call signature. Type 'Number' has no compatible call signatures
<p>I know these type of questions are asked before but still it is not clear to me.</p> <p>I am a beginner and i was trying to learn import and export in typescript. So i have written the following code. Kindly have a look in to this.</p> <p>I have three files:-</p> <pre><code> 1.animal.ts 2.bird.ts 3.application.ts </code></pre> <p>Animal.ts:-</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>export class Animal { name:string age:number constructor(name:string,age:number){ this.name=name; this.age=age } sleep(){ console.log("I do sleep") } eat(){ console.log("I do eat") } }</code></pre> </div> </div> </p> <p>bird.ts</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>import {Animal} from "./animal" export class Bird extends Animal{ constructor(name:string,age:number){ super(name,age) } fly(){ console.log("I can fly also") } }</code></pre> </div> </div> </p> <p>aplication.ts</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>import { Animal } from "./animal" import { Bird } from "./bird" class Application { constructor() { console.log("Hi i am a bird !!") } } var animal = new Animal("Rhino", 10); var bird = new Bird("Pigeon", 3) animal.age(); //Cannot invoke an expression whose type lacks a call signature. Type 'Number' has no compatible call signatures animal.name(); //Cannot invoke an expression whose type lacks a call signature. Type 'String' has no compatible call signatures. bird.age(); //Cannot invoke an expression whose type lacks a call signature. Type 'Number' has no compatible call signatures bird.fly(); bird.sleep();</code></pre> </div> </div> </p> <p>How do i solve this problem ? and what this error actually means ? </p>
49,773,306
3
1
null
2018-04-11 10:55:28.743 UTC
3
2018-09-18 08:34:13.383 UTC
null
null
null
null
9,247,465
null
1
8
typescript
50,615
<p><code>bird.age()</code> does not work because it is a number. <code>console.log(bird.age)</code> will work.</p> <p><code>bird.fly()</code> works because it is a function.</p> <p>Similar pattern for all other issues.</p>
25,201,903
Reference to uninitialized collection PL/SQL
<p>I receive <code>ORA-06531: Reference to uninitialized collection</code> when I run a stored procedure with the following details:</p> <p>User-defined datatype:</p> <pre><code>CREATE OR REPLACE TYPE T IS TABLE OF VARCHAR2; </code></pre> <p>Stored procedure definition:</p> <pre><code>CREATE OR REPLACE PROCEDURE TEST ( u IN T, v OUT T) IS BEGIN FOR i IN u.FIRST..u.LAST LOOP v(i) := u(i); END LOOP; END; </code></pre> <p>I use the following to invoke the procedure:</p> <pre><code>DECLARE v_t T; u_t T; BEGIN v_t := T(); v_t.EXTEND(2); v_t(1) := "This is test1"; v_t(2) := "This is test2"; TEST(v_t, u_t); END; </code></pre>
25,202,544
2
1
null
2014-08-08 10:55:34.87 UTC
null
2019-08-09 08:20:24.53 UTC
2019-08-09 08:20:24.53 UTC
null
10,810,447
null
2,051,843
null
1
10
oracle|stored-procedures|plsql
74,746
<p>In your TEST procedure you have <code>v</code> declared as an OUT parameter - this means that the procedure needs to initialize the output collection in the procedure (e.g. <code>v := T();</code>). Even if you change the calling block to initialize <code>u_t</code> this won't help, as the <code>u_t</code> collection isn't passed in to the procedure - it only receives what the procedure passes back out.</p> <p>Change your code as follows:</p> <pre><code>CREATE OR REPLACE PROCEDURE TEST ( u IN T, v OUT T) IS i NUMBER := u.FIRST; BEGIN v := T(); v.EXTEND(u.COUNT); IF i IS NOT NULL THEN LOOP v(i) := u(i); i := u.NEXT(i); EXIT WHEN i IS NULL; END LOOP; END IF; END TEST; DECLARE v_t T; u_t T; BEGIN v_t := T(); v_t.EXTEND(2); v_t(1) := 'This is test1'; v_t(2) := 'This is test2'; TEST(v_t, u_t); FOR i IN u_t.FIRST..u_t.LAST LOOP DBMS_OUTPUT.PUT_LINE(u_t(i)); END LOOP; END; </code></pre> <p>Please note that string constants in PL/SQL must be enclosed in single-quotes, not double-quotes.</p> <p>Also - using similar variable names which have opposite meanings in the procedure and the calling block just adds to the confusion. Get in the habit of using meaningful names and you'll save yourself a lot of confusion later.</p> <p>Share and enjoy.</p>
24,888,560
Usage of protocols as array types and function parameters in swift
<p>I want to create a class that can store objects conforming to a certain protocol. The objects should be stored in a typed array. According to the Swift documentation protocols can be used as types: </p> <blockquote> <p>Because it is a type, you can use a protocol in many places where other types are allowed, including:</p> <ul> <li>As a parameter type or return type in a function, method, or initializer</li> <li>As the type of a constant, variable, or property</li> <li>As the type of items in an array, dictionary, or other container</li> </ul> </blockquote> <p>However the following generates compiler errors:</p> <blockquote> <p>Protocol 'SomeProtocol' can only be used as a generic constraint because it has Self or associated type requirements</p> </blockquote> <p>How are you supposed to solve this:</p> <pre><code>protocol SomeProtocol: Equatable { func bla() } class SomeClass { var protocols = [SomeProtocol]() func addElement(element: SomeProtocol) { self.protocols.append(element) } func removeElement(element: SomeProtocol) { if let index = find(self.protocols, element) { self.protocols.removeAtIndex(index) } } } </code></pre>
73,094,789
8
1
null
2014-07-22 13:21:06.887 UTC
34
2022-07-23 23:06:47.84 UTC
2020-06-20 09:12:55.06 UTC
null
-1
null
385,307
null
1
145
ios|swift|generics|swift-protocols
35,286
<p>As of <strong>Swift 5.7 / Xcode 14</strong> this can now elegantly be solved using <code>any</code>.</p> <pre class="lang-swift prettyprint-override"><code>protocol SomeProtocol: Equatable { func bla() } class SomeClass { var protocols = [any SomeProtocol]() func addElement(element: any SomeProtocol) { protocols.append(element) } func removeElement(element: any SomeProtocol) { if let index = find(protocols, element) { protocols.remove(at: index) } } } </code></pre>
24,910,769
bootstrap data-toggle="tab" - how to make a tab active with a JS call
<p>I have a JSP page which uses bootstraps data-toggle="tab" functionality. Upon page load I make one tab active.</p> <pre><code>&lt;ul class="nav st-nav-tabs"&gt; &lt;li class="active"&gt;&lt;a href="#tab1" data-toggle="tab"&gt;First Tab&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#tab2" data-toggle="tab"&gt;Second Tab&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;div class="tab-content"&gt; &lt;div class="tab-pane active" id="tab1"&gt;&lt;/div&gt; &lt;div class="tab-pane active" id="tab2"&gt;&lt;/div&gt; &lt;/div&gt; </code></pre> <p>I have a Highcharts chart on the page, whenever a user clicks on one of the columns I call a JS function which makes tab2 the active tab on the page. Inside this function I've tried a few different commands but none seem to work. I'm quite new to jQuery so I'm hoping someone might be able to point out where I'm going wrong with my syntax.</p> <pre><code>function handleClick(){ //I've tried the following, none seem to work $('#tab2').toggleClass('active'); $('#tab2').show(); $('#tab2').tab('show'); } </code></pre>
24,910,903
1
1
null
2014-07-23 12:41:45.017 UTC
1
2016-03-18 11:37:03.317 UTC
2014-07-23 12:45:54.493 UTC
null
1,366,033
null
1,244,104
null
1
11
javascript|jquery|twitter-bootstrap|highcharts
52,714
<p>First you need to give your tabs an <code>id</code>, i will call it myTabs:</p> <pre><code>&lt;ul class="nav st-nav-tabs" id="myTabs"&gt; </code></pre> <p>Then you can call and show your tabs by name to show them:</p> <pre><code>$('#myTabs a[href="#name"]').tab('show'); </code></pre> <p>You can read about tabs in bootstrap's <a href="http://getbootstrap.com/javascript/#tabs" rel="noreferrer">documentation</a>.</p>
21,767,485
Gson - deserialization to specific object type based on field value
<p>I want to deserialize json objects to specific types of objects (using Gson library) based on <code>type</code> field value, eg.:</p> <pre><code>[ { "type": "type1", "id": "131481204101", "url": "http://something.com", "name": "BLAH BLAH", "icon": "SOME_STRING", "price": "FREE", "backgroundUrl": "SOME_STRING" }, { .... } ] </code></pre> <p>So <code>type</code> field will have different (but known) values. Based on that value I need to deserialize that json object to appropriate model object, eg.: Type1Model, Type2Model etc. I know I can easily do that before deserialization by converting it to <code>JSONArray</code>, iterate through it and resolve which type it should be deserialized to. But I think it's ugly approach and I'm looking for better way. Any suggestions?</p>
21,787,292
4
1
null
2014-02-13 23:05:14.767 UTC
10
2020-05-14 16:38:52.437 UTC
2014-02-13 23:13:16.697 UTC
null
1,136,139
null
1,136,139
null
1
21
java|json|deserialization|gson
22,302
<p>You may implement a <code>JsonDeserializer</code> and use it while parsing your Json value to a Java instance. I'll try to show it with a code which is going to give you the idea:</p> <p>1) Define your custom <code>JsonDeserializer</code> class which creates different instance of classes by incoming json value's id property:</p> <pre><code>class MyTypeModelDeserializer implements JsonDeserializer&lt;MyBaseTypeModel&gt; { @Override public MyBaseTypeModel deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObject = json.getAsJsonObject(); JsonElement jsonType = jsonObject.get("type"); String type = jsonType.getAsString(); MyBaseTypeModel typeModel = null; if("type1".equals(type)) { typeModel = new Type1Model(); } else if("type2".equals(type)) { typeModel = new Type2Model(); } // TODO : set properties of type model return typeModel; } } </code></pre> <p>2) Define a base class for your different instance of java objects:</p> <pre><code>class MyBaseTypeModel { private String type; // TODO : add other shared fields here } </code></pre> <p>3) Define your different instance of java objects' classes which extend your base class:</p> <pre><code>class Type1Model extends MyBaseTypeModel { // TODO: add specific fields for this class } class Type2Model extends MyBaseTypeModel { // TODO: add specific fields for this class } </code></pre> <p>4) Use these classes while parsing your json value to a bean:</p> <pre><code>GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapter(MyBaseTypeModel.class, new MyTypeModelDeserializer()); Gson gson = gsonBuilder.create(); MyBaseTypeModel myTypeModel = gson.fromJson(myJsonString, MyBaseTypeModel.class); </code></pre> <p>I can not test it right now but I hope you get the idea. Also <a href="https://javacreed.com/gson-typeadapter-example" rel="noreferrer">this link</a> would be very helpful.</p>
21,586,085
Difference between binary search and binary search tree?
<p>What is the difference between binary search and binary search tree?</p> <p>Are they the same? Reading the internet it seems the second is only for trees (up to 2 children nodes) and binary search doesn't follow this rule. I didn't quite get it.</p>
21,588,248
4
2
null
2014-02-05 18:57:42.3 UTC
21
2020-03-31 20:27:24.893 UTC
2018-03-12 01:04:52.293 UTC
null
717,523
null
1,248,959
null
1
37
algorithm|data-structures|binary-search-tree|binary-search
26,664
<h2>Binary Search Trees</h2> <p>A node in a binary tree is a data structure that has an element, and a reference to two other binary trees, typically called the left and right subtrees. I.e., a node presents an interface like this:</p> <pre><code>Node: element (an element of some type) left (a binary tree, or NULL) right (a binary tree, or NULL) </code></pre> <p>A binary <em>search</em> tree is a binary tree (i.e., a node, typically called the root) with the property that the left and right subtrees are also binary search trees, and that all the elements of all the nodes in the left subtree are less than the root's element, and all the elements of all the nodes in the right subtree are greater than the root's element. E.g., </p> <pre><code> 5 / \ / \ 2 8 / \ / \ 1 3 6 9 </code></pre> <h2>Binary Search</h2> <p>Binary search is an algorithm for finding an element in binary search tree. (It's often expressed as a way of searching an ordered collection, and this is an equivalent description. I'll describe the equivalence afterward.) It's this:</p> <pre><code>search( element, tree ) { if ( tree == NULL ) { return NOT_FOUND } else if ( element == tree.element ) { return FOUND_IT } else if ( element &lt; tree.element ) { return search( element, tree.left ) } else { return search( element, tree.right ) } } </code></pre> <p>This is typically an efficient method of search because at each step, you can remove half the search space. Of course, if you have a poorly balanced binary search tree, it can be inefficient (it can degrade to linear search). For instance, it has poor performance in a tree like:</p> <pre><code>3 \ 4 \ 5 \ 6 </code></pre> <h2>Binary Search on Arrays</h2> <p>Binary search is often presented as a search method for sorted arrays. This does not contradict the description above. In fact, it highlights the fact that we don't actually care how a binary search tree is implemented; we just care that we can take an object and do three things with it: get a element, get a left sub-object, and get a right sub-object (subject, of course, to the constraints about the elements in the left being less than the element, and the elements in the right being greater, etc.).</p> <p>We can do all three things with a sorted array. With a sorted array, the "element" is the middle element of the array, the left sub-object is the subarray to the left of it, and the right sub-object is the subarray to the right of it. E.g., the array </p> <pre><code>[1 3 4 5 7 8 11] </code></pre> <p>corresponds to the tree:</p> <pre><code> 5 / \ / \ 3 8 / \ / \ 1 4 7 11 </code></pre> <p>Thus, we can write a binary search method for arrays like this:</p> <pre><code>search( element, array, begin, end ) { if ( end &lt;= begin ) { return NOT_FOUND } else { midpoint = begin+(end-begin)/2 a_element = array[midpoint] if ( element == midpoint ) { return FOUND_IT } else if ( element &lt; midpoint ) { return search( element, array, begin, midpoint ) } else { return search( element, array, midpoint, end ) } } } </code></pre> <h2>Conclusion</h2> <p>As often presented, binary search refers to the array based algorithm presented here, and binary search tree refers to a tree based data structure with certain properties. However, the properties that binary search requires and the properties that binary search trees have make these two sides of the same coin. Being a binary search tree often implies a particular implementation, but really it's a matter of providing certain operations and satisfying certain constraints. Binary search is an algorithm that functions on data structures that have these operations and meet these constraints.</p>
9,632,489
How to run existing windows 7 task using command prompt
<p>I created a task in Windows 7 task scheduler.</p> <p>How do I run it using the command prompt?</p>
9,639,097
1
0
null
2012-03-09 10:25:57.847 UTC
4
2014-02-22 04:25:39.523 UTC
2012-10-20 13:25:18.143 UTC
null
419
null
197,559
null
1
20
windows-7|command-line|scheduled-tasks
42,745
<p>The syntax is: <code>schtasks /Run /TN "task name"</code></p> <p>For more information see:</p> <blockquote> <p><a href="http://technet.microsoft.com/en-us/library/cc721884.aspx" rel="noreferrer">Run a Task on Demand (MS TechNet)</a></p> </blockquote>
9,552,877
Edit selected rows manually in SQL Server
<p>I have a database in which some editing operations have to be done manually on some rows. I have the SQL Server Management Studio Express. In SSMS, to edit the rows, normally the option is:</p> <p><code>Select DB &gt; Table &gt; Right Click &gt; Edit top 200 rows</code></p> <p>But, the problem here is that I only have to edit some selected rows. I am able to retrieve these selected rows by the following query:</p> <pre><code>/****** Script for SelectTopNRows command from SSMS ******/ SELECT * FROM [test].[dbo].[Sheet1] WHERE Item1 IS NULL OR Item2 IS NULL </code></pre> <p>Now, I have to perform some edit operations (moving some data from some columns to others) which can't be performed with a query because of no single observable pattern for editting. So, the question remains, how can I get these rows in edit mode to do my task?</p>
9,552,972
5
0
null
2012-03-04 06:31:59.823 UTC
6
2021-06-01 15:08:24.517 UTC
null
null
null
null
458,790
null
1
27
sql|sql-server-2008
65,841
<p>Click edit rows on the table and then open the sql tab of that query and add your predicate there. And that's how you can edit filtered records.</p> <p><img src="https://i.stack.imgur.com/Hohgw.png" alt="enter image description here"></p>
30,805,287
What is the difference between "mvn clean install" & "mvn eclipse:clean eclipse:eclipse" command?
<p>I have a maven project in eclipse. I use <strong><code>mvn clean install</code></strong> for installing dependencies in <code>pom.xml</code>.</p> <p>I want to know what <strong><code>mvn eclipse:clean eclipse:eclipse</code></strong> command does and also the difference between these two?</p>
30,805,489
1
1
null
2015-06-12 14:17:37.04 UTC
7
2020-04-10 18:25:03.567 UTC
2019-05-21 07:43:27.673 UTC
null
3,929,393
null
3,929,393
null
1
23
maven
43,418
<p><code>mvn eclipse:clean eclipse:eclipse</code><br> The second command is completely different from the first one.<br> First, it <a href="https://maven.apache.org/plugins/maven-eclipse-plugin/clean-mojo.html" rel="noreferrer">deletes previously generated Eclipse files</a> (like <code>.project</code> and <code>.classpath</code> and <code>.settings</code>) and then <a href="https://maven.apache.org/plugins/maven-eclipse-plugin/eclipse-mojo.html" rel="noreferrer">generates new ones</a>, thus, effectively <em>updating</em> them. It may be useful if you introduced some changes in <code>pom.xml</code> (like new dependencies or plugins) and want Eclipse to be aware of them.</p> <p><code>mvn clean install</code><br> The first command <a href="http://maven.apache.org/plugins/maven-clean-plugin/usage.html" rel="noreferrer">deletes <code>target</code> directory</a> and then builds all you code and <a href="http://maven.apache.org/plugins/maven-install-plugin/usage.html" rel="noreferrer">installs artifacts into local repository</a>.</p>
10,261,521
How to run DOS/CMD/Command Prompt commands from VB.NET?
<p>The question is self-explanatory. It would be great if the code was one line long (something to do with "<code>Process.Start("...")</code>"?). I researched the web but only found old examples and such ones that do not work (at least for me). I want to use this in my class library, to run Git commands (if that helps?).</p>
10,263,144
5
1
null
2012-04-21 17:55:12.123 UTC
9
2019-05-16 11:52:27.273 UTC
2014-02-08 15:10:14.74 UTC
null
321,731
user1072207
null
null
1
17
vb.net|cmd|command
158,249
<p>You could try this method:</p> <pre><code>Public Class MyUtilities Shared Sub RunCommandCom(command as String, arguments as String, permanent as Boolean) Dim p as Process = new Process() Dim pi as ProcessStartInfo = new ProcessStartInfo() pi.Arguments = " " + if(permanent = true, "/K" , "/C") + " " + command + " " + arguments pi.FileName = "cmd.exe" p.StartInfo = pi p.Start() End Sub End Class </code></pre> <p>call, for example, in this way:</p> <pre><code>MyUtilities.RunCommandCom("DIR", "/W", true) </code></pre> <p><strong>EDIT:</strong> For the multiple command on one line the key are the &amp; | &amp;&amp; and || command connectors</p> <ul> <li><strong>A &amp; B</strong> &rarr; execute command A, then execute command B. </li> <li><strong>A | B</strong> &rarr; execute command A, and redirect all it's output into the input of command B.</li> <li><strong>A &amp;&amp; B</strong> &rarr; execute command A, evaluate the errorlevel after running Command A, and if the exit code (errorlevel) is 0, only then execute command B.</li> <li><strong>A || B</strong> &rarr; execute Command A, evaluate the exit code of this command and if it's anything but 0, only then execute command B.</li> </ul>
10,259,504
Delimiters in MySQL
<p>I often see people are using Delimiters. I tried myself to find out what are delimiters and what is their purpose. After 20 minutes of googling, I was not able to find an answer which satisfies me. So, my question is now: What are delimiters and when should I use them?</p>
10,259,528
4
1
null
2012-04-21 13:51:24.843 UTC
49
2020-06-21 12:11:49.157 UTC
2018-04-19 00:03:21.363 UTC
null
8,464,442
null
466,939
null
1
191
mysql|delimiter
205,916
<p>Delimiters other than the default <code>;</code> are typically used when defining functions, stored procedures, and triggers wherein you must define multiple statements. You define a different delimiter like <code>$$</code> which is used to define the end of the entire procedure, but inside it, individual statements are each terminated by <code>;</code>. That way, when the code is run in the <code>mysql</code> client, the client can tell where the entire procedure ends and execute it as a unit rather than executing the individual statements inside.</p> <p>Note that the <code>DELIMITER</code> keyword is a function of the command line <code>mysql</code> client (and some other clients) only and not a regular MySQL language feature. It won't work if you tried to pass it through a programming language API to MySQL. Some other clients like PHPMyAdmin have other methods to specify a non-default delimiter.</p> <h3>Example:</h3> <pre><code>DELIMITER $$ /* This is a complete statement, not part of the procedure, so use the custom delimiter $$ */ DROP PROCEDURE my_procedure$$ /* Now start the procedure code */ CREATE PROCEDURE my_procedure () BEGIN /* Inside the procedure, individual statements terminate with ; */ CREATE TABLE tablea ( col1 INT, col2 INT ); INSERT INTO tablea SELECT * FROM table1; CREATE TABLE tableb ( col1 INT, col2 INT ); INSERT INTO tableb SELECT * FROM table2; /* whole procedure ends with the custom delimiter */ END$$ /* Finally, reset the delimiter to the default ; */ DELIMITER ; </code></pre> <p>Attempting to use <code>DELIMITER</code> with a client that doesn't support it will cause it to be sent to the server, which will report a syntax error. For example, using PHP and MySQLi:</p> <pre><code>$mysqli = new mysqli('localhost', 'user', 'pass', 'test'); $result = $mysqli-&gt;query('DELIMITER $$'); echo $mysqli-&gt;error; </code></pre> <p>Errors with:</p> <blockquote> <p>You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DELIMITER $$' at line 1</p> </blockquote>
23,378,271
How do I display ANSI color codes in emacs for any mode?
<p>I have a log file that uses ANSI escape color codes to format the text. The mode is <code>fundamental</code>. There are other answered questions that address this issue but I'm not sure how to apply it to this mode or any other mode. I know the solution has something to do with configuring <code>ansi-color</code> in some way.</p> <ul> <li><a href="https://stackoverflow.com/questions/256264/how-do-i-get-emacs-shell-mode-to-either-render-or-ignore-my-colors-instead-of" title="ASCII codes in shell mode">ANSI codes in shell mode</a></li> <li><a href="https://stackoverflow.com/questions/5674255/display-ascii-control-characters-in-emacs-gud-gdb-mode">ANSI codes in gdb mode</a></li> </ul>
23,382,008
4
1
null
2014-04-30 01:44:52.257 UTC
9
2020-05-04 14:24:09.623 UTC
2017-05-23 12:26:32.797 UTC
null
-1
null
155,823
null
1
36
emacs|ansi
12,889
<p>You could use code below</p> <pre><code>(require 'ansi-color) (defun display-ansi-colors () (interactive) (ansi-color-apply-on-region (point-min) (point-max))) </code></pre> <p>Then you can execute <code>display-ansi-colors</code> via M-x, via a key-binding of your choosing, or via some programmatic condition (maybe your log files have a extension or name that matches some regexp)</p> <p>If you want to do this with read-only buffers (log files, grep results), you may use <code>inhibit-read-only</code>, so the function will be:</p> <pre><code>(defun display-ansi-colors () (interactive) (let ((inhibit-read-only t)) (ansi-color-apply-on-region (point-min) (point-max)))) </code></pre>
40,790,031
pandas.to_numeric - find out which string it was unable to parse
<p>Applying <code>pandas.to_numeric</code> to a dataframe column which contains strings that represent numbers (and possibly other unparsable strings) results in an error message like this:</p> <pre><code>--------------------------------------------------------------------------- ValueError Traceback (most recent call last) &lt;ipython-input-66-07383316d7b6&gt; in &lt;module&gt;() 1 for column in shouldBeNumericColumns: ----&gt; 2 trainData[column] = pandas.to_numeric(trainData[column]) /usr/local/lib/python3.5/site-packages/pandas/tools/util.py in to_numeric(arg, errors) 113 try: 114 values = lib.maybe_convert_numeric(values, set(), --&gt; 115 coerce_numeric=coerce_numeric) 116 except: 117 if errors == 'raise': pandas/src/inference.pyx in pandas.lib.maybe_convert_numeric (pandas/lib.c:53558)() pandas/src/inference.pyx in pandas.lib.maybe_convert_numeric (pandas/lib.c:53344)() ValueError: Unable to parse string </code></pre> <p>Wouldn't it be helpful to see which value failed to parse? </p>
40,790,068
2
1
null
2016-11-24 15:28:48.213 UTC
9
2016-11-24 15:40:43.54 UTC
null
null
null
null
626,537
null
1
19
python|pandas|data-science|data-cleaning
76,132
<p>I think you can add parameter <code>errors='coerce'</code> for convert bad non numeric values to <code>NaN</code>, then check this values by <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.isnull.html" rel="noreferrer"><code>isnull</code></a> and use <a href="http://pandas.pydata.org/pandas-docs/stable/indexing.html#boolean-indexing" rel="noreferrer"><code>boolean indexing</code></a>:</p> <pre><code>print (df[pd.to_numeric(df.col, errors='coerce').isnull()]) </code></pre> <p>Sample:</p> <pre><code>df = pd.DataFrame({'B':['a','7','8'], 'C':[7,8,9]}) print (df) B C 0 a 7 1 7 8 2 8 9 print (df[pd.to_numeric(df.B, errors='coerce').isnull()]) B C 0 a 7 </code></pre> <p>Or if need find all string in mixed column - numerice with string values check <code>type</code> of values if is <code>string</code>:</p> <pre><code>df = pd.DataFrame({'B':['a',7, 8], 'C':[7,8,9]}) print (df) B C 0 a 7 1 7 8 2 8 9 print (df[df.B.apply(lambda x: isinstance(x, str))]) B C 0 a 7 </code></pre>
41,155,985
Python TA-Lib install problems
<p>Frustratingly having a lot of difficult installing the TA-Lib package in python. </p> <p><a href="https://pypi.python.org/pypi/TA-Lib" rel="noreferrer">https://pypi.python.org/pypi/TA-Lib</a></p> <p>I have read through all the forum posts I can find on this but no such luck for my particular problem..</p> <p>Windows 10 Python 3.5.2 Anaconda 4.2.0 Cython 0.24.1 Microsoft Visual Studio 14.0</p> <p>I have downloaded and extracted  ta-lib-0.4.0-msvc.zip to C:/TA-Lib (common problems seem to be people not installing the underlying TA-Lib file <a href="http://www.ta-lib.org/hdr_dw.html" rel="noreferrer">http://www.ta-lib.org/hdr_dw.html</a>)</p> <p>If someone could help me solve this I would be very appreciative!</p> <p>Using 'pip install ta-lib' I get the following: </p> <pre><code>C:\Users\Matt&gt;pip install ta-lib Collecting ta-lib Using cached TA-Lib-0.4.10.tar.gz Building wheels for collected packages: ta-lib Running setup.py bdist_wheel for ta-lib ... error Complete output from command c:\users\matt\anaconda3\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\Matt\\AppData\\Local\\Temp\\pip-build-vv02ktg_\\ta-lib\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d C:\Users\Matt\AppData\Local\Temp\tmpqstzmsgspip-wheel- --python-tag cp35: running bdist_wheel running build running build_py creating build creating build\lib.win-amd64-3.5 creating build\lib.win-amd64-3.5\talib copying talib\deprecated.py -&gt; build\lib.win-amd64-3.5\talib copying talib\test_abstract.py -&gt; build\lib.win-amd64-3.5\talib copying talib\test_data.py -&gt; build\lib.win-amd64-3.5\talib copying talib\test_func.py -&gt; build\lib.win-amd64-3.5\talib copying talib\test_stream.py -&gt; build\lib.win-amd64-3.5\talib copying talib\__init__.py -&gt; build\lib.win-amd64-3.5\talib running build_ext skipping 'talib\common.c' Cython extension (up-to-date) building 'talib.common' extension creating build\temp.win-amd64-3.5 creating build\temp.win-amd64-3.5\Release creating build\temp.win-amd64-3.5\Release\talib C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Ic:\users\matt\anaconda3\lib\site-packages\numpy\core\include -Ic:\ta-lib\c\include -Ic:\users\matt\anaconda3\include -Ic:\users\matt\anaconda3\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\8.1\include\shared" "-IC:\Program Files (x86)\Windows Kits\8.1\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\winrt" /Tctalib\common.c /Fobuild\temp.win-amd64-3.5\Release\talib\common.obj common.c C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:c:\ta-lib\c\lib /LIBPATH:c:\users\matt\anaconda3\libs /LIBPATH:c:\users\matt\anaconda3\PCbuild\amd64 "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\LIB\amd64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.10240.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\8.1\lib\winv6.3\um\x64" ta_libc_cdr.lib /EXPORT:PyInit_common build\temp.win-amd64-3.5\Release\talib\common.obj /OUT:build\lib.win-amd64-3.5\talib\common.cp35-win_amd64.pyd /IMPLIB:build\temp.win-amd64-3.5\Release\talib\common.cp35-win_amd64.lib common.obj : warning LNK4197: export 'PyInit_common' specified multiple times; using first specification Creating library build\temp.win-amd64-3.5\Release\talib\common.cp35-win_amd64.lib and object build\temp.win-amd64-3.5\Release\talib\common.cp35-win_amd64.exp common.obj : error LNK2001: unresolved external symbol TA_SetUnstablePeriod common.obj : error LNK2001: unresolved external symbol TA_Shutdown common.obj : error LNK2001: unresolved external symbol TA_Initialize common.obj : error LNK2001: unresolved external symbol TA_GetUnstablePeriod common.obj : error LNK2001: unresolved external symbol TA_GetVersionString build\lib.win-amd64-3.5\talib\common.cp35-win_amd64.pyd : fatal error LNK1120: 5 unresolved externals error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\link.exe' failed with exit status 1120 ---------------------------------------- Failed building wheel for ta-lib Running setup.py clean for ta-lib Failed to build ta-lib Installing collected packages: ta-lib Running setup.py install for ta-lib ... error Complete output from command c:\users\matt\anaconda3\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\Matt\\AppData\\Local\\Temp\\pip-build-vv02ktg_\\ta-lib\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\Matt\AppData\Local\Temp\pip-qxmjmn5m-record\install-record.txt --single-version-externally-managed --compile: running install running build running build_py creating build creating build\lib.win-amd64-3.5 creating build\lib.win-amd64-3.5\talib copying talib\deprecated.py -&gt; build\lib.win-amd64-3.5\talib copying talib\test_abstract.py -&gt; build\lib.win-amd64-3.5\talib copying talib\test_data.py -&gt; build\lib.win-amd64-3.5\talib copying talib\test_func.py -&gt; build\lib.win-amd64-3.5\talib copying talib\test_stream.py -&gt; build\lib.win-amd64-3.5\talib copying talib\__init__.py -&gt; build\lib.win-amd64-3.5\talib running build_ext skipping 'talib\common.c' Cython extension (up-to-date) building 'talib.common' extension creating build\temp.win-amd64-3.5 creating build\temp.win-amd64-3.5\Release creating build\temp.win-amd64-3.5\Release\talib C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Ic:\users\matt\anaconda3\lib\site-packages\numpy\core\include -Ic:\ta-lib\c\include -Ic:\users\matt\anaconda3\include -Ic:\users\matt\anaconda3\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\8.1\include\shared" "-IC:\Program Files (x86)\Windows Kits\8.1\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\winrt" /Tctalib\common.c /Fobuild\temp.win-amd64-3.5\Release\talib\common.obj common.c C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:c:\ta-lib\c\lib /LIBPATH:c:\users\matt\anaconda3\libs /LIBPATH:c:\users\matt\anaconda3\PCbuild\amd64 "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\LIB\amd64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.10240.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\8.1\lib\winv6.3\um\x64" ta_libc_cdr.lib /EXPORT:PyInit_common build\temp.win-amd64-3.5\Release\talib\common.obj /OUT:build\lib.win-amd64-3.5\talib\common.cp35-win_amd64.pyd /IMPLIB:build\temp.win-amd64-3.5\Release\talib\common.cp35-win_amd64.lib common.obj : warning LNK4197: export 'PyInit_common' specified multiple times; using first specification Creating library build\temp.win-amd64-3.5\Release\talib\common.cp35-win_amd64.lib and object build\temp.win-amd64-3.5\Release\talib\common.cp35-win_amd64.exp common.obj : error LNK2001: unresolved external symbol TA_SetUnstablePeriod common.obj : error LNK2001: unresolved external symbol TA_Shutdown common.obj : error LNK2001: unresolved external symbol TA_Initialize common.obj : error LNK2001: unresolved external symbol TA_GetUnstablePeriod common.obj : error LNK2001: unresolved external symbol TA_GetVersionString build\lib.win-amd64-3.5\talib\common.cp35-win_amd64.pyd : fatal error LNK1120: 5 unresolved externals error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\link.exe' failed with exit status 1120 ---------------------------------------- Command "c:\users\matt\anaconda3\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\Matt\\AppData\\Local\\Temp\\pip-build-vv02ktg_\\ta-lib\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\Matt\AppData\Local\Temp\pip-qxmjmn5m-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\Matt\AppData\Local\Temp\pip-build-vv02ktg_\ta-lib\ </code></pre>
41,451,120
12
1
null
2016-12-15 03:30:56.69 UTC
6
2022-07-22 15:35:49.01 UTC
null
null
null
null
7,273,219
null
1
11
python|pip|installation|windows-10|ta-lib
44,787
<p>You could try the <em>&quot;<a href="http://www.lfd.uci.edu/%7Egohlke/pythonlibs/#ta-lib" rel="nofollow noreferrer">Unofficial Windows Binaries for Python Extension Packages</a> by Christoph Gohlke, Laboratory for Fluorescence Dynamics, University of California, Irvine.&quot;</em></p> <p><a href="http://www.lfd.uci.edu/%7Egohlke/pythonlibs/#ta-lib" rel="nofollow noreferrer">http://www.lfd.uci.edu/~gohlke/pythonlibs/#ta-lib</a></p> <p>He has different versions compiled depending on OS and Python versions. You probably need <code>TA_Lib‑0.4.10‑cp35‑cp35m‑win_amd64.whl</code></p> <p>Good luck.</p>
18,496,282
Why do I get "a label can only be part of a statement and a declaration is not a statement" if I have a variable that is initialized after a label?
<p>I have the following simplified code:</p> <pre><code>#include &lt;stdio.h&gt; int main () { printf("Hello "); goto Cleanup; Cleanup: char *str = "World\n"; printf("%s\n", str); } </code></pre> <p>I get an error because a new variable is declared after the label. If I put the content (mainly initialization) after the label in a {} block, compilation succeeds.</p> <p>I think I understand the reason for the block in case of a switch, but why should it be applicable in case of a label ?</p> <p>This error is from a gcc compiler</p>
18,496,437
2
1
null
2013-08-28 19:09:49.86 UTC
32
2013-08-28 19:17:50.52 UTC
null
null
null
null
1,952,500
null
1
127
c|gcc
175,634
<p>The language standard simply doesn't allow for it. Labels can only be followed by statements, and declarations do not count as statements in C. The easiest way to get around this is by inserting an empty statement after your label, which relieves you from keeping track of the scope the way you would need to inside a block.</p> <pre><code>#include &lt;stdio.h&gt; int main () { printf("Hello "); goto Cleanup; Cleanup: ; //This is an empty statement. char *str = "World\n"; printf("%s\n", str); } </code></pre>
1,730,547
Check if files with absolute and relative path exists
<p>Is there a way to check whether files (with either an absolute or relative path) exists? Im using PHP. I found a couple of method but either they only accept absolute or relative but not both. Thanks.</p>
1,730,594
3
1
null
2009-11-13 16:57:47.297 UTC
4
2018-10-01 13:32:52.103 UTC
null
null
null
null
199,053
null
1
16
php|path
40,022
<p><code>file_exists($file);</code> does the trick for both relative and absolute paths.</p> <p>What's more useful, however, is having absolute paths without hardcoding it. The best way to do that is use <code>dirname(__FILE__)</code> which gets the directory's full path of the current file in ether UNIX or Windows format. Then we can use <a href="http://us2.php.net/realpath" rel="noreferrer"><code>realpath()</code></a> which conveniently returns false if file does not exist. All you have to do then is specify a relative path from that file's directory and put it all together: </p> <pre><code>$path = dirname(__FILE__) . '/include.php'; if (realpath($path)) { include($path); } </code></pre>