input_text_instruct
stringlengths
288
45.8k
output_text
stringlengths
37
33.2k
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Restrict a bit field to true in only one child record at a time<p>I have a <code>Person</code> table, each of who's records belongs to a parent record from t...
<p>So seeing as no-one has given an answer here, I'll post what I eventually did:</p> <p>Created a separate table called Organizer, with only two fields:</p> <pre><code>CREATE TABLE Organizer ( Company int NOT NULL UNIQUE, Person int NOT NULL, CONSTRAINT FK_Organizer_Company FOREIGN KEY (Company) REFERENC...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Calculate Euclidean Distance between all the elements in a list of lists python<p>I have a list of lists. I want to find the euclidean distance between all t...
<p>You can use numpy directly to calculate the distances:</p> <pre><code>pts = [[0, 42908],[1, 3],[1, 69],[1, 11],[0, 1379963888],[0, 1309937401],[0, 1],[0, 3],[0, 3],[0, 77]] x = np.array([pt[0] for pt in pts]) y = np.array([pt[1] for pt in pts]) np.sqrt(np.square(x - x.reshape(-1,1)) + np.square(y - y.reshape(-1,1))...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: How to scale controls with maintained aspect ratio and position without viewbox?<p>I am trying to replicate the display <em>rearranger UI</em> in <strong>dis...
<p>I have finally achieved it, I got rid of the viewbox and managed to do it through code</p> <p>The Code :</p> <pre class="lang-vb prettyprint-override"><code> Private Sub LoadScreens() Dim ox As Integer = 0 Dim oy As Integer = 0 Dim canvaswidth As Integer = 0 Dim canvasheight As I...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Passing a variable from php to javascript on button click<p>Hi I am trying to pass a variable on button click from a php function to javascript. The output i...
<p>jQuery's <a href="https://api.jquery.com/data/" rel="nofollow noreferrer"><code>.data()</code></a> accesses an element's <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset" rel="nofollow noreferrer"><code>dataset</code></a> but the <code>id</code> in your link appears to be in the URL frag...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Django rest framework endpoints and passing the values<p>i am very new to Django and REST. I started working with rest-auth recently just to explore. Can som...
<p>It seems like you incorrectly posted code example. This looks like a rout (the part before and including <code>$</code> sign) and another part is a <a href="https://docs.djangoproject.com/en/3.0/topics/http/urls/#naming-url-patterns" rel="nofollow noreferrer">url pattern name</a> for this rout (for <a href="https://...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Can't select related category in Django<p>I have 2 models with custom ProductManager</p> <pre><code>class ProductManager(models.Manager): def get_queryse...
<p>Your query seems to be correct and will fetch a subset of Products and their Categories. The query returns a <a href="https://docs.djangoproject.com/en/4.0/topics/db/queries/#retrieving-objects" rel="nofollow noreferrer">QuerySet</a> and you tried to access a non-existent attribute on it.</p> <p>Depending on what yo...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: How to get the max value of 3 fields<p>I have a table with integer fields like this:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr>...
<p>As pointed out by <a href="https://stackoverflow.com/users/13964273/user13964273">user13964273</a> in the comments, you can use <a href="https://www.firebirdsql.org/file/documentation/chunk/en/refdocs/fblangref30/fblangref30-dml.html#fblangref30-dml-select-orderby" rel="nofollow noreferrer"><code>order by</code></a>...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Pre-formatted UITextView content from file<p>I have a file with text that should be displayed in a UITextView. I would like to add support of formatting of t...
<p>Enclose all text in file content in HTML <code>&lt;b&gt;&lt;/b&gt;</code> tag and load it in <code>NSAttributedString</code> using some <code>initWithHTML:</code> initializer, like</p> <blockquote> <pre><code>- (nullable instancetype)initWithHTML:(NSData *)data documentAttributes:(NSDictionary&lt;NSAttributed...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: How to change tab in the Flutter Default Tab Controller?<p>I'm using Flutter Default Tab Controller for shows the tab View. And I need to change the tab whil...
<p>You can do this without stateful widgets by retrieving the controller with <code>DefaultTabController.of(context)</code> and then calling <code>.animateTo(index)</code> on it.</p> <pre><code>class TabPage extends StatelessWidget { @override Widget build(BuildContext context) { return DefaultTabController( ...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: How to read multiple Bar Code from Newland MT90?<p>I have a Newland MT90 barcode reader android mobile. I am creating an application in which I want to scan ...
<p>Assuming the same <code>Intent</code> is being returned, you'd just have to change the <code>Intent</code> being issued:</p> <pre><code>Intent intent = new Intent("nlscan.action.SCANNER_TRIG"); intent.putExtra("SCAN_TIMEOUT", 4); // SCAN_TIMEOUT value: int, 1-9; unit: second intent.putExtra("SCAN_TYPE ", 1); // SCA...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: How do I change the color of an icon for only the tab that's pressed in React?<p>I have a footer at the bottom of my react app that has four icons that act a...
<p>In <code>handleClick()</code>, you toggle <code>isActive</code> and you set the rest of them to inactive.</p> <pre class="lang-js prettyprint-override"><code>const handleClick = () =&gt; { setIsActive(current =&gt; !current); setIsActive(false); setIsActive(false); } </code></pre> <p>The same goes with the oth...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Installing font-awesome with Laravel 9 (Vite)<p>i'm using Laravel 9 which doesn't use mix anymore, but vite, to bundle resources, i'm also not using any prep...
<p>add fontawesome library</p> <pre><code>npm install @fortawesome/fontawesome-free </code></pre> <p>in the file /resources/css/app.css:</p> <pre><code>@import &quot;@fortawesome/fontawesome-free/css/all.css&quot;; @tailwind base; @tailwind components; @tailwind utilities; </code></pre> <p>then run</p> <pre><code>npm ...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Messageback like feature of Adaptive Card in Slack BlockKit<p>I am trying to implement messageBack feature of Adaptive Card in Slack Builder Kit where on cli...
<p>When the button is clicked, you can update the message that you sent with &quot;Thank you for clicking&quot; using the <a href="https://api.slack.com/methods/chat.update" rel="nofollow noreferrer"><code>chat.update</code> method</a>. After that, you could update it once more to show the response from the API or jus...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Convert string to pygame.key<p>For my game I need to take a string, consisting of one character, and check, if a key with this character was pressed (I'm usi...
<p>You can use <a href="https://docs.python.org/3/library/functions.html#ord" rel="nofollow noreferrer"><code>ord(c)</code></a> to get the ordinary number, that represents a character. e.g:</p> <pre class="lang-py prettyprint-override"><code>ch = 'a' while True: for event in pygame.event.get(): if event....
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: No such module 'FacebookCore' in swift 5<p>I am doing my own test app as part of my learning process in iOS development (using swift 5 on Xcode 11.0). I want...
<p>So it turned out that I have to import <em>FBSDKCoreKit</em> instead of <em>FacebookCore</em> which was not mentioned in facebook's documentation. And it should be imported strictly using the <strong>.xcworkspace</strong> file which was also not mentioned in the documentation.</p>
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Cannot understand how to write a testcase for weekdays in python using unittest module<p>I have a function in python which takes weekday as a parameter and r...
<p>Here is the solution:</p> <pre><code>import unittest class Utils(unittest.TestCase): def test_dayNameFromWeekday(self, weekday): if weekday == "Monday": return 0 elif weekday == "Tuesday": return 1 elif weekday == "Wednesday": return 2 elif wee...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: How can I change the range of the number in a column in R?<p>I have numbers in a column whose range from -5 to 7. I want to range them from 0 to 13. How can ...
<p>as in a new column of data, or add 5 to current column?</p> <p>Both below</p> <pre><code>df$col &lt;- df$col+5 df$new &lt;- sample(0:13, 10) </code></pre> <p>hope this helps</p>
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: GTK4 - how to get coordinates of a moving window<p>In previous versions of GTK, we added a necessary event mask, attached to a <code>configure-event</code>.<...
<p>You can't. This is because not all window managers/compositors provide this information, for privacy and/or technical reasons.</p> <p>Wayland, for example, does not provide window coordinates, because not every Wayland compositor is even a 2D rectangle - for example, kiosk compositors like <a href="https://github.co...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Find monday of current week in Python<p>I am trying to get the timestamp of monday at 00:00 of the current week in python. I know that for a specific date, t...
<blockquote> <p>I am trying to get the timestamp of monday at 00:00 of the current week in python</p> </blockquote> <p>You could use <code>timedelta</code> method from <code>datetime</code> package.</p> <pre><code>from datetime import datetime, timedelta now = datetime.now() monday = now - timedelta(days = now.week...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Django: Table template<p>I have this table in my template</p> <pre><code>&lt;tr&gt; &lt;th&gt;SCHEDULE OF FEES&lt;/th&gt; &lt;th colspan="2"&gt;SCHEDU...
<p>You can't use one <code>&lt;table&gt;</code> for this, because tables work row by row and in your case your columns are unrelated. Either put two tables next to each other or use two <code>&lt;div&gt;</code> blocks that you put next to each other.</p> <p>In both cases, I'd recommend using <a href="https://css-trick...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: How to get .htaccess to return 404 instead of 500 for missing files<p><strong>Background</strong></p> <p>I am building a <code>PHP</code> application that us...
<p><a href="https://stackoverflow.com/a/73061701/3193156">arkascha's answer</a> helped point me in the right direction; using <code>END</code> instead of <code>L</code> in the correct locations. For those looking to create a similar security focused MVC structure my working <code>.htacces</code> file is below. It provi...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: TypeScript Custom useStateIfMounted React Hook - Not all constituents of type 'T | ((value: SetStateAction<T>) => void)' are callable<p>The full error:</p> <...
<p>Type the return as a tuple:</p> <pre><code>return [state, setState] as const; </code></pre> <p>You need to specify this otherwise both <code>state</code> and <code>setState</code> are of type <code>boolean | ((value: React.SetStateAction&lt;boolean&gt;) =&gt; void)</code> for instance, and only one part of that unio...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Return Image from Function in Swift<p>I have tried to return an Image or UIImage from the function below but there is an issue that says<br /> &quot;Unexpect...
<p>The thing to understand is that your call to <code>getData(maxSize:)</code> is a separate <strong>asynchronous</strong> function. That function does not, and cannot, return the image in its return. It needs to start a network request. It starts that network request and then returns immediately. When the function ret...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Data is not binding in ViewModel Nested Class for POST method<p>When saving the details from the view, the details is not binding into the nested class (<em>...
<p>Remove a name attirbute from ALL web controls, for example should be just</p> <pre><code> &lt;input class=&quot;form-control form-control-sm&quot; asp-for=&quot;BOUser.LastName&quot; /&gt; </code></pre>
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Implement a generic trait but only for a specific type<p>I'm trying to wrap a generic layer with a type specific layer that crops values to a range. I want t...
<p>Instead if trying to make your <code>impl</code> generic, you can instead pass the trait a concrete type:</p> <pre class="lang-rust prettyprint-override"><code>impl BaseLayer&lt;f32&gt; for Rangedf32Layer { fn get_mut(self: &amp;Self, index: u32) -&gt; Option&lt;&amp;mut f32&gt; { self.layer.get_mut(inde...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: How to reuse steps definition of one feature file implementation in another one in pytest_bdd?<p>I am having the below folder structure</p> <pre><code>folde...
<p><strong>Option 1:</strong></p> <p>You can create common steps in <code>conftest.py</code></p> <pre><code>@given("User is logged-in") def logging_in(): print('logging_in') @given("User is in Home page") def homepage(): print('homepage') </code></pre> <p>And add common features file <code>common_steps.fea...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Modifiable Python application architecture<p>I develop an application in Python, but I want to make it so that other users can later modify its functionality...
<p>Welcome to Stack Overflow.</p> <p>Now I have to put a disclaimer on the top that I am not a professional in architecture. I am just sharing some of my personal understanding and experience here. Do not take it all as correct answer as there are no strict architecture suitable for everything.</p> <p>Now First, I beli...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Why is my React component library not tree-shakable?<p>I have a <a href="https://gitlab.com/liquid-design/liquid-design-react/" rel="noreferrer">React compon...
<p>I found one possible solution to my problem. It has nothing to do with tree-shaking though. I’m simply <strong>splitting the library into several independent chunks</strong> by making use of a rather new feature of rollup (I had to upgrade a bunch of dependencies in order for it to work) and providing an object, map...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: How to log the current step in SAS?<p>I'm trying to monitor the progression of a long SAS script. At the beginning, I used something like:</p> <pre><code>DA...
<p>There is no explicit introspection or callback mechanism in SAS for supervisory level source code processing, step statement gathering time (pre-compile) or at step compile time.</p> <p>However, you can implement and utilize (adopt) a name specifying framework that performs the desired actions.</p> <p>Concept:</p>...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: How to get the date between the from date and to date?<p>I'm working on <code>DayPicker</code> to get all the range dates, but I couldn't have any good idea ...
<p>Use date-fns and create a function.</p> <pre><code> const getDatesInRange = (startDate: Date, numberOfDays: number) =&gt; { const dates: Date[] = []; [...Array(numberOfDays + 1)].forEach((_, i) =&gt; { dates.push(addDays(startDate, i)); }); console.log(dates); // For debugging purposes re...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: what is the best code to write this conditional rowwise function in a tibble?<p>I want to calculate the geometrical mean of two vectors in a tibble using the...
<p>You could also (just) use <code>mutate</code> instead of looping over each row.</p> <p>In your case, there is no need to <code>map</code> or to use <code>rowwise</code>, and as <code>case_when</code> is evaluating from the bottom and up, you can simplify your <code>is.na</code> calls as well.</p> <pre class="lang-r ...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Copying user input text to output text file (java)<p>This is an assigment for my java class. I'm having to create user input and put that into an input file(...
<p>Alright, first thing is that there is not library in Java called "java.util.io". What you are probably looking for is <a href="https://docs.oracle.com/javase/7/docs/api/java/io/package-summary.html" rel="nofollow noreferrer">"java.io"</a>.</p> <p>Another thing about your code is that you misspelled the Scanner obje...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: make the contents of the dropdown of a tab be displayed from its bottom right extending to the left side<p>I got this code example from <a href="https://www....
<p>You can overwrite bootstrap css like this:</p> <pre><code>.dropdown-menu { left: auto; right: 0; } </code></pre>
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: You may need an additional loader to handle the result of these loaders. Angular 14<p>I updated from Angular 7 to Angular 14 after removing all the errors in...
<p>I have resolved this error of Loaders by adding my &quot;/src/app/shared/styles/themes/theme-f.scss&quot; file in angular.json file</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"...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: How to get datatype for specific field name from schema attribute of pyspark dataframe (from parquet files)?<p>Have a folder of parquet files that I am readi...
<h3>Method 1:</h3> <p>You can use the <code>df.dtypes</code> method to get the field name along with it's datatype and the same can be converted to a <code>dict</code> object as shown below,</p> <pre><code>myschema = dict(df.dtypes) </code></pre> <p>Now, you can obtain the datatypes as shown below,</p> <pre><code>m...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Why doesn't the read and write mode work?<pre><code>handler = open('test.txt', 'a+') for idx, line in enumerate(handler): print(idx, line.strip()) </cod...
<p>When you open a file in <code>a</code> mode, the file cursor is positioned at the end, not the beginning. You need to seek to the beginning to read the file.</p> <pre><code>handler = open('test.txt', 'a+') handler.seek(0) for idx, line in enumerate(handler): print(idx, line.strip()) </code></pre>
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Passing a struct containing a vector to the GPU<p>I'm making my first steps with GPU programming in Julia. I've been successful in passing a vector to the GP...
<p>I can't claim to grasp all the nuances of CUDA.jl/Adapt.jl, but what sticks out to me is that you are wrapping your values inconsistently: <code>Data</code> turns into a different type <code>DataOnGPU</code>.</p> <p>The 2 different but sort-of-the-same structs also stick out like a clear anti-pattern: you really jus...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Run a task only when registered output (which is a list) has changed<p>I am running the below task which registers the output to a <code>status</code> variab...
<p>Before doing anything, you have to realise that you do have a string representation of a JSON array, not a JSON array.</p> <p>So, in order to get a list, like you claim you have in your question, you should use:</p> <pre class="lang-yaml prettyprint-override"><code>status.stdout | from_json </code></pre> <p>and not<...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: How to keep background image from moving when a scroll is added?<p>I have a website with two pages. Both pages share the same CSS body properties.</p> <p>Whe...
<p>The only way to avoid that is to use <code>overflow-y: scroll</code> for the <code>body</code> also on those pages whose contents is equal to or <em>not</em> more than 100% high.</p> <p>That way a vertical scollbar will be displayed on <em>each</em> page and therefore the background will remain the same. Not a pret...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: How a generic void type can make an arg optional in typescript<p>I'm trying to create a class that returns an instance that receives an argument with generic...
<p>In order to do that, you need to overload your <code>constructor</code> and <code>ok</code> methods:</p> <pre class="lang-js prettyprint-override"><code> class Result&lt;A = void&gt;{ private readonly data: A | void; private constructor() private constructor(data: A) private constructor(data?: A) { this...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Twitter API - load X posts each time<p>I have three Twitter posts as follows:</p> <pre><code>-&gt; Twitter with message 3 -&gt; Twitter with message 2 -&g...
<p><strong>Solved</strong>.</p> <p>The solution is in this post <a href="https://stackoverflow.com/q/9717488/3355243">using since_id and max_id in Twitter API</a>. The only thing I needed to change was this:</p> <pre><code>$data['max_id'] = $lastTwitterId; </code></pre> <p>Into this:</p> <pre><code>$data['max_id'] ...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Sending json data via post .ajax() and also receiving a json response<p>Pls i need help with a registration page which i am coding currently. I have been at ...
<p>To send data as <code>JSON</code> you need to edit your JS code <code>NOTE:</code> You can't use <code>$_POST</code> in this case</p> <pre><code> url: &quot;signup-exec.php&quot;, method: &quot;POST&quot;, data: JSON.stringify(sendInfo), contentType: &quot;application/json&quot;, </code></pre> <p>and parse it...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: How to use a 'hard-coded' dictionary/enum<p>I am wanting to create a 'dictionary' of strings, however I have only ever learned how to use strings to referenc...
<p>There are <strong>compiletime</strong> constants and <strong>runtime</strong> constants. </p> <p>Your wish for Autocrrection/Intellisense support <em>requires</em> a compile time constants. Those are the only ones Intellisence, Syntax Highlighting and the Compiler double check for you.</p> <p>But your requriement ...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: How to click an element that is not visible in cypress<p>I am trying to click an action menu option and getting this error in cypress:</p> <pre class="lang-j...
<p>You have information on how you can workaround this problem. Add optional 'option' param.</p> <pre><code>Element.click({force: true}); </code></pre> <p>There you can find more information: <a href="https://docs.cypress.io/api/commands/click#Usage" rel="nofollow noreferrer">https://docs.cypress.io/api/commands/click#...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Calculating the size of an element depending on the number of elements and the total width<p>Let X be a known value which represents how many columns will be...
<p>As the number of possibilities is quite limited, you could just identify those. It is clear that it does not matter how many rows you have to produce, only the last or last two rows will need to have double sized boxes to make it fit. All the other rows can just have 1-column sized boxes.</p> <p>Here is a function ...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Want to show only the first latest post on my main page<p>i am trying to show only the first latest post the main page but still loops all. please i need hel...
<p>You need to simply change your query:</p> <pre><code>def index(request): context = { 'info': info.objects.order_by('-date_posted').first(), } return render(request, 'blog/index.html', context) </code></pre> <blockquote> <p>Note: ordering by <code>date_posted</code> was proposed by Toni Sredanović in other an...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Using window as type in d.ts<p>I have a function that requires to pass a Node or the window object. My types for this function are:</p> <pre><code>function ...
<p>The type of <code>window</code> is <code>Window</code>:</p> <pre><code>function myFunc(node: Node | Window): void { } myFunc(window); </code></pre> <p><a href="https://www.typescriptlang.org/play/#code/GYVwdgxgLglg9mABAWwJ4DFwQBRjgEwFMAuRAOQMMQB9EB1GMfOAdwEpSA3OGfRAbwCwAKAC+IkWkyRsLRs3YBuREA" rel="nofollow norefe...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: How to specify axis limits in geoviews (python)?<p>I have been using geopandas, but I am trying to switch to geoviews because it is more interactive. I'm won...
<p>Your are very close to a working solution. Try to add <code>xlim</code> and <code>ylim</code> as tuple to the <code>opts</code> call.</p> <p><strong>Minimal Example</strong></p> <p>Comment: GeoViews is based on Holoviews, see the <a href="https://github.com/holoviz/geoviews#what-is-it" rel="nofollow noreferrer">docu...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Crop the Detected area python<pre><code>import cv2 import pytesseract import numpy as np from pytesseract import Output import re from pytesseract import ima...
<p>You can draw the bounding box but does not know how to crop it? That's weird. </p> <p>Anyway, I added the relevant code below. If it's not the right loop at least you now know how to crop an image in numpy:</p> <pre><code>n_boxes = len(d['text']) # make the boxes around till the lenght text, put n_boxes in for loo...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: echo $(date +%s -d "+1 day 6:30") using sudo crontab -e<p><strong>Main-agenda:</strong> I am trying to automate shutdown and restart of my computer using <co...
<p>Your intuition about the % is correct. See <code>man 5 crontab</code>:</p> <blockquote> <p>A &quot;%&quot; character in the command, unless escaped with a backslash (), will be changed into newline characters, and all data after the first % will be sent to the command as standard input.</p> </blockquote> <p>This wil...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: How to export Sympy equation to an image<p>I would like to export an equation to a PNG image so, for example:</p> <pre><code>from math import pi, sin from s...
<p>This is somewhat obscure but SymPy's <code>preview</code> function can do this:</p> <pre class="lang-py prettyprint-override"><code>with open('solution.png', 'wb') as outputfile: preview(solution, viewer='BytesIO', outputbuffer=outputfile) </code></pre> <p>Behind the scenes this uses LaTeX so you'll need to have...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Can you track and label a single alluvium using the ggalluvial package for ggplot2 in R?<p>I'm working on an alluvial diagram in R, based off of the "student...
<p>Certainly each alluvium should correspond to a single case, whatever the parameter settings. The issue here is that the alluvium stat (statistical transformation) is being used to produce two layers in the plot under <em>different</em> parameter settings: the flow layer with <code>lode.guidance</code> set to <code>"...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: How to use ^[]$ format to compare string with numbers greater than 9?<p>Say I have a simple statement:</p> <pre><code>read number [[ ! $number =~ ^[1-3245][...
<p>Assuming your criteria is: integer between 1 and 3245 (included), comma, integer between 1 and 3245 (included), you can use a mixture of regular expression and arithmetic:</p> <pre><code>$ foo() { [[ &quot;$1&quot; =~ ^([0-9]*),([0-9]*)$ ]] || return 1 a=${BASH_REMATCH[1]}; b=${BASH_REMATCH[2]} (( a &gt;= 1 &a...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Div alignment in html and css<p>I tried this html and CSS ,</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="fal...
<p>Add a additional class to your parent div, defining the column layout.</p> <p>CSS:</p> <pre><code>.divcss { width: 48%; margin-right: 5px; margin-bottom: 8px; vertical-align: top; display: inline-block; } .layout { columns: 2; height: 50%; } </code></pre> <p>HTML:</p> <pre><code> &lt;div class="layout"&gt; ...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: How to fill an array using a for loop in Vuejs<p>I have a while loop which I am trying to set up an array within VueJS. The hope is to have 3 objects in the ...
<p>You need to move the random number generation inside the <code>while</code> loop. This line <code>const randomValue = Math.random();</code> should be inside the <code>while</code> loop:</p> <pre><code>methods: { createMonster() { while (this.i &lt; 3) { let randomValue = Math.random(); if (randomV...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Do microprocessors disable interrupts while compare and swap instructions are executed?<p>Does the 1.4 GHz Intel Core i5 (64 bit) CPU disable interrupts, whe...
<p>The following two things are not necessarily the same:</p> <ol> <li>Atomic operations on a C++ level (std::atomic)</li> <li>Assembler CPU instructions that are guaranteed to be atomic</li> </ol> <p>For example, a modern Intel processor guarantees that 64-bit reads/writes to a 64-bit aligned address is atomic. It a...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: In Shiny/R how to synchronize two sets of tab panels?<p>I need to click on the tabpanel label &quot;Panel 2&quot; and on the right the plot on &quot;Panel Ri...
<p>As @DanAdams pointed you to, and you responded with Laura, <code>updateTabsetPanel</code> is key. When I've done this in the past, I would use <code>observeEvent</code>, whenever a tab on the first set of tabs is chosen, then it updates the second set of tabs with the corresponding choice. Here's it is with your cod...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: `Intent.ACTION_VIEW` fails with a `no file received` error<h3>My current code :</h3> <p>Just focus on the <code>fileOpener</code> variable. The <code>SafeFil...
<p>Adding this might have helped -</p> <pre><code>intent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION </code></pre> <p>My final code is -</p> <pre><code>fileOpener = { file: File -&gt; val uri: Uri = FileProvider.getUriForFile( requireContext(), &quot;com.example.cryptile.fileProvider&quot;, ...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: How to load a Category Page with Products using pagination and filtering? Laravel<p>// CategoryController</p> <pre><code>class CategoryController extends Co...
<p>Reverse it, meaning query for products instead:</p> <pre><code>class CategoryController extends Controller { public function show($slug) { $products = Product::with(['categories'])-&gt;whereHas('categories', function ($query) use ($slug) { $query-&gt;where(['slug' =&gt; $slug]); ...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: How can I render query data using map in a React App<p>I've just started learning how to use React, and I encountered the following problem: I need to rende...
<p>Your <code>data</code> is optional. And it is undefined while the query is loading.</p> <pre><code> const { data, loading } = useQuery(GET_SUBSCRIBERS_QUERY); </code></pre> <p>You may consider adding a loading state, as follow:</p> <pre><code>if (loading) { return &lt;p&gt;Loading...&lt;/p&gt; // Or whatever you w...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: AWS Amplify: How custom Resolver?<p>I'm learning to use AWS Amplify and need some guidance. <br /> This is my <strong>schema.graphql</strong> file content (i...
<p><strong>Solution here:</strong> Override Amplify-generated resolvers</p> <p>Link: <a href="https://docs.amplify.aws/cli/graphql/custom-business-logic/#override-amplify-generated-resolvers" rel="nofollow noreferrer">https://docs.amplify.aws/cli/graphql/custom-business-logic/#override-amplify-generated-resolvers</a></...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: How do I use bootstrap 5.02 with npm and webpack<p>I'm trying to bundle my webapp with webpack, but the bootstrap code doesn't seem to be importing properly....
<p>I figured out my problems so far by reading the <a href="https://getbootstrap.com/docs/5.2/getting-started/javascript/" rel="nofollow noreferrer">bootstrap documentation</a>!: (summarized below)</p> <p>the bootstrap script</p> <pre><code>&lt;/script&gt; &lt;script type=&quot;module&quot; src=&quot;/node_modules/...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Singleton pattern no more working with php 8.1<p>Here is some simple code that works with php 7.4, but not with php 8.1:</p> <pre><code>&lt;?php class A { ...
<p>Static varibales should always work the same way. Test this code in 7.4 an 8.1 and you will see the difference in the behavior, and that was fixed by php developers. And the code has also the solution to your issue, using <code>static::class</code>.</p> <pre><code>&lt;?php class A { public $name = &quot;I'm A&q...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Easier way to transform array into a distribution?<p>I have an array, vox_betas, that contains 21600 floats (ranging from ~0 to ~2), and when sorted by the a...
<p>This is called <strong><a href="https://en.wikipedia.org/wiki/Inverse_transform_sampling" rel="nofollow noreferrer">inverse transform sampling</a></strong>:</p> <blockquote> <p>is a basic method for pseudo-random number sampling, i.e., for generating sample numbers at random from any probability distribution ...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: What is best way to move an Object in libGDX<p>I just wrote a simple app to test moving a graphic Texture by the input given from the user. There is a circle...
<ol> <li>I don't find 15 objects that much, especially as you are only using 2d textures and some simple math. However, when you code base grows you should think about refactoring it and move the logic to dedicated classes.</li> <li>The <code>draw</code> function always uses the bottom-left corner. But you could use th...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Java Structured Method Chaining<p>A bit of a question on working with objects in java. Suppose I have the following class.</p> <pre><code>public class Examp...
<p>You can use interfaces to divide up the methods.</p> <pre><code>// you can probably come up with better names, taking your real situation into account interface Logicable { SubLogicOneAble logicOne(/*same input variables as logicOne*/); SubLogicTwoAble logicTwo(/*same input variables as logicTwo*/); } inter...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Jest failing when comparing result of toLocaleString<p>I want to test a method that uses <code>toLocaleString</code>, but when comparing the result jest I ge...
<p>To understand what the problem is you can try </p> <pre><code>result.charCodeAt(9); // 160 </code></pre> <p>which is an UTF "Non-breaking space", you can just copy the result from your console and paste it into the unit test.</p> <p><strong>Edit</strong> as future reminder you can add an assertion</p> <pre><code...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: What exactly does X_FRAME_OPTIONS = 'SAMEORIGIN'?<p>I created a site in Django that I deployed on heroku. I am looking to display this site in an iframe in a...
<p>Modern browsers respect Content-Security-Policy frame-ancestors directive. With the retirement of IE there is no longer a need for the inflexible X-Frame-Options.</p> <p>For details on how to implement, see the answers to this question: <a href="https://stackoverflow.com/questions/33267383/how-to-configure-x-frame-o...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: div grid inside div grid<p>For hours and hours I've trying to get the style as I wanted. I'm trying to get the grid inside the grid for example like this</p>...
<p>I'm pretty sure your code works?</p> <p>I changed the <code>grid</code> css to have a background of red to make things more visible, it seems you only have 1 column? If you add another column, like your first in your desired image, It should work.</p> <p>I also removed the php references and just hard coded a <code>...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: How to calculate old date from current date in typescript or angular4+<p>How can i get the 90 days old date from current date in typescript or angular4</p> ...
<p>Here is an exmaple:</p> <p>subtract-days.ts:</p> <pre class="lang-ts prettyprint-override"><code>export function subtractDays(days: number, fromDate: Date = new Date()): Date { return new Date(fromDate.getTime() - (days * 24 * 60 * 60 * 1000)); } </code></pre> <p>And in your angular component import the funct...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: SQL Server - Calculate AVG() using Joins<p>I have a Cab transport application</p> <p>Each driver has a Trip and for each trip, there can be multiple custome...
<p>Try this. You need to include all the ratings in order to calculate the percentage:</p> <pre><code>SELECT r.[DriverId], 100.0*r.five_stars/r.total_ratings AS Percentage FROM ( SELECT TR.[DriverId] SUM(CASE WHEN FE.Rating =5 THEN 1 ELSE 0 END) AS five_stars, SUM(*) AS total_ratings FROM tblFeedback FE ...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Make Google Full Row Number Drop Down List<p>I want to use the Google Apps script to put all the row numbers in the active sheet in the drop-down list. What ...
<p>In your script, <code>rowArr</code> has all values like <code>[[1], [2],,,]</code>. By this, your situation occurs. I think that this is the reason for your issue. In order to achieve your goal, how about the following modification?</p> <h3>From:</h3> <pre><code>var arr =[]; var rowArr = []; for(var i=1;i&lt;ss.getM...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Htaccess rewriting rule for localhost<p>The project is already running in prod, the developer who added that rule is no longer working with us but it is pret...
<p>the rule is correct but try to add this just before your rule</p> <pre><code> RewriteBase / # If the request is not for a valid directory RewriteCond %{REQUEST_FILENAME} !-d # If the request is not for a valid file RewriteCond %{REQUEST_FILENAME} !-f </code></pre>
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: REST API (Lambda integration) deployment using Terraform - POST is giving 200, but GET is giving 500<p>I am trying to create a REST API with 2 methods GET an...
<p>According to the <a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_integration" rel="nofollow noreferrer">documentation</a>:</p> <blockquote> <p>integration_http_method - (Optional) The integration HTTP method (GET, POST, PUT, DELETE, HEAD, OPTIONs, ANY, PATCH) specifyi...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Should a Haskell parser allow Unicode digits in numeric literals?<p>As an exercise, I am writing a parser for Haskell from scratch. In making the lexer, I no...
<p>In the GHC source code file <code>compiler/parser/Lexer.x</code>, you can find the following code:</p> <pre><code>ascdigit = 0-9 $unidigit = \x03 -- Trick Alex into handling Unicode. See [Unicode in Alex]. $decdigit = $ascdigit -- for now, should really be $digit (ToDo) $digit = [$ascdigit $unidigit] ... $bi...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: How to calculate hash while saving file to disk using streams?<p>How to calculate hash using streams while saving file to disk?</p> <p>I don't want to: Save ...
<p>You have a few bugs in your code:</p> <ol> <li><p>You never copy to the <code>CryptoStream</code>, you only copy to the underlying <code>fileStream</code>. So naturally no hash is ever calculated.</p> </li> <li><p>You do not close the <code>CryptoStream</code> before attempting to determine the hash. The stream mu...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: How to increase the value of one field with one request<p>I'd like to make EF generate a SQL query like this:</p> <pre><code>UPDATE Users SET CurrentTurn =...
<p>If you want to do it in one DB roundtrip as far I know you'll need to install a 3rd party library like <a href="https://github.com/zzzprojects/EntityFramework-Plus" rel="nofollow noreferrer">EntityFramework-Plus</a>:</p> <pre><code>_storageContext.Users.Where(x =&gt; x.Id==userId) .Update(x =&gt; new...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Stuck on typescript generic signature for GroupBy function<p>Having some trouble after a few hours wrapping my head around what I'm doing wrong with this TS ...
<p>I notice that &quot;admin&quot; and &quot;user&quot; can only be obtained from the values of the data array (possible values of <code>data[number]['type']</code>).<br> TypeScript by default won't assume much from the values other than the values are strings. (The situation for 'type' and 'name' is different as they ...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Get all the buckets for a aggregate elastic search<p>I want to get all the buckets available for a particular aggregate. Is there any query or endpoint to ge...
<p>A possible solution would be not to set the filter in the <code>query</code> section of your payload but rather perform <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filter-aggregation.html#search-aggregations-bucket-filter-aggregation" rel="nofollow noreferrer">...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Unable to add elements to a List in Flutter<p><strong>Issue:</strong> I am trying to add items to wishlist and cart on pressing relevant icons of an instrume...
<p>To call a method inside tap you need to use <code>()</code>. Do it like</p> <pre class="lang-dart prettyprint-override"><code> onTap: () { setState(() { isCarted = !isCarted; }); widget.onCartTap(); //this </code></pre>
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: How to sort words by frequency in a csv file<p>I have .csv files that look like this but I can't figure out how to read and sort by frequency the words of th...
<p>So the task is to read CSV file from second line to first occurrence of empty line and count all words.</p> <p>To read CSV file you can use built-in <a href="https://docs.python.org/3/library/csv.html#csv.reader" rel="nofollow noreferrer"><code>csv.reader()</code></a>. Basically returned <code>reader</code> is an <a...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: How to use v-for in SweetAlert2<pre class="lang-js prettyprint-override"><code>this.$swal .fire({ title: '학교를 검색해주세요.', input: 'text', inputAttributes:...
<p><code>vue-sweetalert2</code> doesn't support rendering HTML templates dynamically, so you can't pass Vue templates this way; but you don't really need to in this case. Instead, you could generate the HTML string in JavaScript like this:</p> <pre class="lang-js prettyprint-override"><code>axios .get(apiUrl) .th...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Understanding syntax of function parameter: vector<vector<int>> A[]<p>I'm solving a question where a function is defined as following:</p> <pre><code>vector ...
<p>Just as <code>int foo(char str[])</code> is a function that takes a (c-style) array of characters, so <code>int foo(vector&lt;vector&lt;int&gt;&gt; B[])</code> takes an array of vectors of vectors ... of integers. This means that it's three-dimensional data, requiring 3 indices to access the elements (fundamental da...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: How to compare a string value to an element of an string array in c#?<p>In the following program i want to check (via defencing programming) if the user inpu...
<p>You can use Linq <a href="https://docs.microsoft.com/en-us/dotnet/api/system.linq.enumerable.any?view=netframework-4.8" rel="nofollow noreferrer"><code>.Any()</code></a> function:</p> <pre><code>using System.Linq; ... string[] weekdays = new string[7] { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Python Dict Key Error. How do I loop through nested dict and check for a key<p>I have the following nested dict below which I'm trying to loop through. Well,...
<p>Thanks everyone especially @tennoshi.</p> <p>This works: </p> <pre><code>whatsapp_contact_id = message.data list_data = whatsapp_contact_id.get("messages") for dictionary_data in list_data: dictionary_data_2 = dictionary_data.get("_vnd").get("v1") labels_data = dictionary_data_2.get("labels...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Block HTTP Requests or make them run synchron<p>I have two HTTP-Requests and i have to execute them in the ordert that I execute the first one, wait till its...
<p>I simply had to change my calls to this:</p> <pre><code>func doHTTPRecentProjectsCall(employeeId: String) async{ let date : Date = Date() let dateFormatter = DateFormatter() dateFormatter.dateFormat = &quot;yyyyMMdd&quot; let todaysDate = dateFormatter.string(from: date) var url = &quot...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Radio button is showing div on selection but not hiding after selecting a different radio button<p>I have three divs I want to show based on a radio selectio...
<p>You need to <code>hide</code> <code>2nd</code> &amp; <code>3rd</code> div by <code>CSS</code> and when user change other button then find <code>ID</code> so according to <code>ID</code> show that div and rest div will <code>hide</code> as below snippet.</p> <p><div class="snippet" data-lang="js" data-hide="false" d...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: How can I add a new line to an already existing section in a .ini file, with batch commands?<p>I have a file <em>MyFile.ini</em> with a section in it <em>[My...
<p>Here's an example based upon my commented methodology:</p> <pre class="lang-bat prettyprint-override"><code>@Echo Off Set "file=MyFile.ini" Set "section=[MySection]" Set "newline=MyNewValue=MyNewSetting" Copy /Y "%file%" "%file%.bak"&gt;NUL 2&gt;&amp;1||Exit /B 1 (For /F "Tokens=1*Delims=]" %%G In ( '^""%_...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Django group by and count(*), includes zero counts<pre><code>class Author(models.Model): name = models.CharField(max_length=50) class Book(models.Model):...
<p>Maybe you can try like this(using <a href="https://docs.djangoproject.com/en/3.0/ref/models/relations/" rel="nofollow noreferrer"><strong><code>related objects</code></strong></a>):</p> <pre><code>authors = Author.objects.annotate( book_count=Count( 'book', filter=Q(book__is_deleted=False) )...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Create an image composed by different images<p>I have the a list of images (each of these image is a separate file), let's say they are some jigsaw puzzle pi...
<p>This depends on how you want to handle it when there's an overlapping transparent area.</p> <p>Suppose all pixels are either transparent or opaque, and</p> <p>Suppose each image has RGBA (4-channels including alpha), then you can set all RGB values to zero whenever the pixel is transparent.</p> <p>Then proceed to ad...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: load huge xml files with BeautifulSoup<p>I'm trying to extract posts from the stackoverflow data dumps. These are composed of large .xml files, notably a fil...
<p>You can use a SAX parser for this, like so:</p> <pre class="lang-py prettyprint-override"><code>from xml import sax from xml.sax.handler import ContentHandler class PostDescriber(ContentHandler): def startElement(self, name, attrs): if name == 'row' and attrs.get('PostTypeId') == '1': print(...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: How to insert documents in batches (Size of 10) in mongodb using c#<p>Below code snippet generates a BsonDocument List of 3000 records.</p> <pre><code>List&l...
<p>You can split your list of 3k into chunks like so:</p> <pre><code>var batches = batch.Chunk(10); </code></pre>
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: 3 level nested object to cascade drop downs with jQuery - 3rd level not working<p>I'm creating cascading drop down list from 3 level nested object. I'm unabl...
<p>The pattern for selecting the type is the same as you are doing for manufacturer, however you need to use a delegated event handler as the <code>#model</code> element doesn't exist in the DOM when the page loads. </p> <p>However you should note that the act of appending the different selects tot he DOM when an opti...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Main and secondary manager of an employee<p>I want to regroup the main and secondary manager of an employee :</p> <pre><code>EmployeeName ManagerStatus M...
<p>You want conditional aggregation :</p> <pre><code>select EmployeeName, max(case when ManagerStatus = 'Primary' then Manager end) as PrimaryManager, max(case when ManagerStatus = 'Secondary' then Manager end) asSecondaryManager from table t group by EmployeeName; </code></pre> <p>This assumes em...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: How to set a type to be a string but not allowing some specific values?<p>I commonly use type aliases to restrict possible string values :</p> <pre><code>typ...
<p>You can't exclude specific string literals from the <code>string</code> type. (It would be cool, but you can't [edit: at least, <a href="https://github.com/microsoft/TypeScript/issues/48073" rel="nofollow noreferrer">not yet</a>, thanks as always <a href="https://stackoverflow.com/users/2887218/jcalz">jcalz</a>!]. :...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Flatten a list objects that have multiple nested objects<p>I am hoping someone can help me. I have a list of objects that has nested lists of objects at the ...
<p>You can do it in <strong>one flatten</strong> operation with the help of <a href="https://www.terraform.io/language/functions/setproduct" rel="nofollow noreferrer">setproduct</a>:</p> <pre><code>locals { dbs = merge([ for db in var.databases: { for idx, shema_env in setproduct(db.schemas, db.en...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Footer and page size<p>Feels like should already know how to achieve this effect, but I don't, so here goes:</p> <p>I want footer to be placed at the bottom ...
<p>This can be achieved easily using Flexbox and setting <code>min-height: 100vh</code> to the main container.</p> <p>I would suggest having a look at the <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Basic_Concepts_of_Flexbox" rel="nofollow noreferrer">Flexbox documentation</a> (fro...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: InternalLinkedHashMap<String, dynamic> is not a subtype of custom object<p>I am new to flutter and working on converting my native iOS app to it. I am trying...
<p>It looks like the ProviderJobsJson.fromJson is not parsing the list of jobs for you.</p> <p>You might do it like this:</p> <pre><code>var model = ProviderJobsJson.fromJson(jsonDecode(response.body)); var jsonJobs = model.jobs; List&lt;JobModel&gt; jobs = List&lt;JobModel&gt;.from(jsonJobs.map((x) =&gt; JobModel.from...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Merge Object array based on id<p>Hi I am calling an API where it returns an Object containing questions and answers like so</p> <pre><code>{ &quot;questio...
<p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter" rel="nofollow noreferrer"><code>Array#filter</code></a> can be used to find all the answers with a specific question id. (Note that <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global...
Please answer the following Stackoverflow question on Programming. Answer it like you are a developer answering Stackoverflow questions. Stackoverflow question: Testing react component with jest<p>I am following the test documentation on react, the data fetching part: <a href="https://reactjs.org/docs/testing-recipes...
<p>Well I solved the problem. The solution was to mock the <code>axios</code> and mock implement the response with <code>mockImplementation</code></p> <pre><code>import React from "react"; import { render, unmountComponentAtNode } from "react-dom"; import { act } from "react-dom/test-utils"; import User from "./User";...