input
stringlengths
51
42.3k
output
stringlengths
18
55k
Using Java Domain Object Instead of Scala Case Class in Spark DataSet Creation <p>I'm trying to create a Spark DataSet from an RDD using the RDD#toDS method.</p> <p>However, instead of using the Scala case class to specify the schema, I want to use an existing domain object defined in a 3rd party library. But, when I ...
<p>It might work to create a case class that extends your java object.</p> <p>Java:</p> <pre><code>public class Patient { private final String name; private final String status; public Patient(String name, String status) { this.name = name; this.status = status; } public String getName() { re...
Java Linked List unique Keyword Sorting <p>I'm trying to read a file (in this case a text file with song lyrics) and create a linked list using only unique strings from said file. There cannot be any two same strings in the list. It needs to be stored in a Linked List and can't use the built-in one for it. Right now th...
<p>You can solve your problem in a few lines:</p> <ul> <li>read values into a <code>LinkedHashSet</code> (set preserving the order of insertion)</li> <li>convert the result <code>new LinkedList&lt;&gt;(linkedHashSet)</code></li> </ul>
WPF Listbox memory leak <p>Here's my xaml:</p> <pre><code>&lt;ListBox Grid.Row="4" HorizontalAlignment="Stretch" Margin="10,132,10,10" ScrollViewer.VerticalScrollBarVisibility="Disabled" Name="lbStatus" VerticalAlignment="Stretch" VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode=...
<p>This isn't a 'leak' per se. If you are continually adding entries to a <code>ListBox</code>, overnight even, you're likely going to have thousands of entries, which will of course require memory to store.</p> <p>To avoid this, you could remove old entries as you add new ones:</p> <pre><code>if (listbox.Items.Count...
readHTMLTable and rvest not working for HTML Table scraping <p>I've been attempting to scrape the data from a HTML table with issues.</p> <pre><code>url &lt;- "http://www.njweather.org/data/daily" Precip &lt;- url %&gt;% html() %&gt;% html_nodes(xpath='//*[@id="dataout"]') %&gt;% html_table() </code></pre>...
<p>Unfortunately, that "Save to CSV" is a shockwave/flash control that just extracts the JSON content from the page, so there's no way to call that directly (via URL) but it would be clickable in a Firefox RSelenium web drive context (but…ugh!).</p> <p>Rather than use RSelenium or the newer webdriver packages, might...
display a hidden input field when enter value on a particuloar input filed <p>anyone could help me out on how i could achieve this with either javascript or jquery maybe to get the following as mentioned below</p> <p>say i have this field1</p> <pre><code>&lt;input type="text" name="field1" value=""&gt; </code></pre> ...
<p>You'd get the first field, check if it has a value, and toggle the second field based on that, but you should not be using a hidden input, but instead hide it with CSS</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippe...
Sort function for array of structures <p>I have a structure called rain. It is defines like this</p> <pre><code> struct Rain{ string month; string year; double rainfall; } </code></pre> <p>I have an array of these (rain [240]) and I would like to sort using the sort algorithm. This is what I tried:</p> ...
<p>Often it's most convenient to embed the function into the class/struct:</p> <pre><code>struct Rain { string month; string year; double rainfall; bool operator &lt; (const Rain&amp; r1) const { return (rainfall &lt; r1.rainfall); } }; </code></pre> <p>Now they can be sorted like the basi...
Processing file with large amount of data on one line (in Python) <p>I've inherited a 593 MB txt file in which all the data was written to <em>one</em> line. </p> <p>What's the best way to process it (preferably in Python)?</p>
<pre><code>CHUNKSIZE=1024 # read 1024 bytes at a time while True: chunk = f.read(CHUNKSIZE) if not chunk: break # end of file ... process(chunk) </code></pre> <p>is one way... alternatively 593MB is not all that huge... you can probably just load it all in at once without much difficulty (again it depen...
Reading information from a file in C language <p>So I have the txt file from which I need to read the number of students written in that file, and because every student is in separate line, it means that I need to read the number of lines in that document. So I need to:</p> <ol> <li><p>Print all lines from that docume...
<p>OP's code is close but needs to use <code>fgets()</code> rather than <code>fgetc()</code> and use the return value of <code>fgets()</code> to detect when to quit, it will be <code>NULL</code> <a href="http://stackoverflow.com/questions/40139500/reading-information-from-a-file-in-c-language/40140587#comment67549285_4...
Wordpress Plugin error. Backup Buddy <p>I am having a error when using <code>BackupBuddy</code> plugin for wordpress. I can not find the error anywhere online.</p> <blockquote> <p>Error #82389: A javascript error occured which may prevent the backup from continuing. Check your browser error console for details. Th...
<p>I can't give you the exact fix for the problem, but I can point you in the right direction and seeing that nobody has answered in 1 hour, I hope it helps. The issue is that there are 2 libraries that need to load; one for backupbuddy and one for another plugin or theme(I'm pretty sure its your theme). The library fo...
Load a SOAP XML message into two different C# objects <p>I have a Java backend es a C# Silverlight UI which are communicating with each other via SOAP XML messages. The message contains a large object which contains lots of smaller objects which contains lots of even smaller objects and so on. My aim is to have two ins...
<p>Sure you can...</p> <pre><code>var myFirstInstance = MyDeserializeMethod(incomingXML); var mySecondInstance = MyDeserializeMethod(incomingXML); </code></pre> <p>Since it is being deserialized first, it is not a direct reference to incomingXML - you are assigning the object which is returned from MyDeserializeMetho...
Setting Image background for a line plot in matplotlib <p>I am trying to set a background image to a line plot that I have done in matplotlib. While importing the image and using zorder argument also, I am getting two seperate images, in place of a single combined image. Please suggest me a way out. My code is -- </p> ...
<p>You're creating two separate figures in your code. The first one with <code>fig, ax = plt.subplots(1)</code> and the second with <code>plt.figure(2)</code></p> <p>If you delete that second figure, you should be getting closer to your goal</p>
How to expand first div in accordion? <p>My current accordion container works. <a href="https://jsfiddle.net/c9bwogte/" rel="nofollow">https://jsfiddle.net/c9bwogte/</a></p> <p>Im using a query to group the head and body, it works good. How do I get it to expand the first head by default? The first head would end up b...
<p>You can add <code>.click()</code> at the end to trigger the accordion:</p> <pre><code>$(".accordion_head").click(function () { if ($('.accordion_body').is(':visible')) { $(".accordion_body").slideUp(200); $(".plusminus").text('+'); } if ($(this).next(".accordion_body").is(':visible')) { ...
SQL - Duplicates when Querying 3 Tables <p>I have a pretty simple query that pulls data from 3 tables. I decided to use From and Where Clauses to Select what I want instead of Join but when I run the query it pulls duplicate data. DISTINCT was tried as well but it still pulled duplicate data.</p> <p>Here is the Query...
<p>Try this : WHERE IV00101.ITEMNMBR = IV00102.ITEMNMBR AND IV00102.ITEMNMBR = ItmPrice.ITEMNMBR group by IV00101.ITEMNMBR ORDER BY IV00101.ITEMNMBR</p>
Trying to send random string in C# Discord <p>I am trying to make a bot in Discord. I now am working on making a random url. And to make this url, I first want to be sure the random generator works good. The random generated chars will be outputted as an array, but I want it as a string but I do not know how. I want th...
<p>You need to give your <code>LinkString()</code> method a parameter, an <code>int</code> as you've specified. Change it to this:</p> <pre><code> await e.Channel.SendMessage(LinkString(5)); </code></pre>
Find & Replace across entire workbook in specific row <pre><code> Dim sht As Worksheet Dim fnd As Variant Dim rplc As Variant fnd = "April" rplc = "May" For Each sht In ActiveWorkbook.Worksheets   sht.Cells.Replace what:=fnd, Replacement:=rplc, _     LookAt:=xlPart, SearchOrder:=x...
<p>Two things.</p> <p>First, don't use variants for fnd and rplc; use Strings.</p> <p>Second, specify the range you want to do the replace on, rather than just using "Cells".</p> <pre><code>Sub Replacer() Const csFnd As String = "April" Const csRpl As String = "May" Const csRow As String = "A30" Dim...
Iterating through one variable in a vector of struct with lower/upper bound <p>I have 2 structs, one simply has 2 values:</p> <pre><code>struct combo { int output; int input; }; </code></pre> <p>And another that sorts the input element based on the index of the output element:</p> <pre><code>struct organize { bool...
<p>I think that if you sort it in smallest to largest (x is an integer after all) that you should be able to use <a href="http://en.cppreference.com/w/cpp/algorithm/adjacent_find" rel="nofollow">std::adjacent_find</a> to find duplicates in the array, and process them properly. For the performance issues, you might c...
Hash function issue - adding functionality <p>I tried adding functionality to the djb2 hash function, but it doesn't appear to like the changes. Specifically, I'm trying to include a loop that converts words (strings) to lower case. It throws the following two errors: </p> <ol> <li>Incompatible integer to pointer con...
<p>This:</p> <pre><code>char* string[45]; </code></pre> <p>means "array of 45 character pointers", you should drop the asterisk.</p> <p>And you can't iterate over an array by incrementing the variable, the array variable cannot be changed. You can use a separate pointer:</p> <pre><code>const char *s = string; while...
Y-axis ticks' labels visible partially <p>Which parameter should I manipulate to have whole labels visible here? As you see, hundreds are displayed as "00", "20" and so on:</p> <p><a href="https://i.stack.imgur.com/24dBR.jpg" rel="nofollow"><img src="https://i.stack.imgur.com/24dBR.jpg" alt="enter image description he...
<p>There is a related question linked here: <a href="http://stackoverflow.com/questions/25322535/how-to-increase-tick-label-width-in-d3-js-axis?rq=1">How to increase tick label width in d3.js axis</a></p> <p>Eventually it lead me to this piece of code (<code>padding</code> was already defined in my script):</p> <pre>...
Inheriting from Db class - Two databases connection | PHP <p>In my app I used one database only, and I created class to provide some common methods. Now I need to implement additional database. </p> <p>So instead of creating separate Db class to do same things, I want to call that Db class with db related parameters....
<p>@u_mulder described the technical issue you are facing correctly. The parent <code>Db</code> constructor is not automatically called from a child constructor. You could try to get around this by calling the parent constructor explicitly:</p> <pre><code>class Main extends DB { public function __construct() ...
SQL Case Statement in a Function <p>I am trying to write a function that takes two parameters and returns a calculated result based on a case statement (please see below). I keep getting a syntax error: </p> <blockquote> <p>You have an error in your SQL syntax; check the manual that corresponds to your MySQL server...
<p>Create a table instead, and join to it. You will get much faster performance using a CROSS APPLY operation, as scalar-valued user-defined functions suffer from RBAR (Row By Agonizing Row) performance penalties</p>
How to stop SIGTERM and SIGKILL? <p>I need to run a huge process which will run for like 10+ minutes. I maxed the <code>max_execution_time</code>, but in my error logs I get a SIGTERM and then a SIGKILL. </p> <p>I read a little about SIGTERM and SIGKILL that they come from the daemon, but i Didn't figure out how to st...
<p>Rather than trying to ignore signals, you need to find who sends them and why. If you're starting php from the command line, no one will send that signal and your script time will have <em>all the time</em>.</p> <p>But if you're actually starting this process as a response to an http request, it's probably the web ...
How to replace symbols by their value in a R function body <p>This code reveals that <code>f</code> doesn't yet look up <code>q</code> before it's called.</p> <pre><code>q &lt;- 2 f &lt;- function(x) q + x f </code></pre> <p>I want to tell R which symbols in the body to look up right away (in this case <code>list("q"...
<p>In Common Lisp this would look like:</p> <pre><code>CL-USER&gt; (defparameter q 4) Q CL-USER&gt; (let ((bar q)) (defmacro f (x) `(+ ,bar ,x))) F CL-USER&gt; (macroexpand-1 `(f 4)) (+ 4 4) T </code></pre> <p>In R this could look like:</p> <pre><code>&gt; q = 2 &gt; f = eval(bquote(functi...
Print random line from txt file? <p>I'm using random.randint to generate a random number, and then assigning that number to a variable. Then I want to print the line with the number I assigned to the variable, but I keep getting the error:</p> <blockquote> <p>list index out of range</p> </blockquote> <p>Here's what...
<p>You want to use <code>random.choice</code></p> <pre><code>import random with open(filename) as f: lines = f.readlines() print(random.choice(lines)) </code></pre>
Reading the code declarations and definitions in order to get the result of the expression without using GHCi <pre><code>data Tree a b = Branch b (Tree a b) (Tree a b) | Leaf a myorder :: (a -&gt; c) -&gt; (b -&gt; c) -&gt; Tree a b -&gt; [c] myorder p q (Leaf x) = [p x] myorder p q (Branch x l r) = myorder p q l ++ [q...
<p>We need to evaluate</p> <pre><code>myorder id length (Branch "Hi" (Branch "All" (Leaf (1::Int)) (Leaf (2::Int))) (Leaf (3::Int))) </code></pre> <p>Try to apply the equations in order from top to bottom.</p> <pre><code>myorder p q (Leaf x) = [p x] </code></pre> <p>This equa...
Adding int and int? in Kotlin <p>I ran into a problem, which seems so simple that everyone should have ran into it at some point or another, yet failed to find a solution anywhere.</p> <p>Copied from the REPL:</p> <pre><code>var a : Int = 1 var c : Int? = 3 a + if (c != null) {c} else {0} ERROR: None of the followin...
<p>The problem is that kotlin can only assume a variable is never null after a null check if there is no way that variable can change value between operations.</p> <p>I don't exactly know how the REPL is implemented but my guess is that variables are inserted as members into a context class. This means the compiler ca...
How do I get a JSON object from a function? <p>I have the following component and I'm trying to retrieve a list of movies from an API. However, the variable <code>movies</code> does not contain the expected result.</p> <p>What am I doing wrong?</p> <p>Here's the code:</p> <pre><code>import React, { Component, } from...
<p>In your fetch call, you should return the response with a <code>then()</code> call. Here's an example from an app I wrote:</p> <pre><code>// inside Utils/api.js getAllSchools(accessToken){ var url = `${baseUrl}/schools` return fetch(url).then((res) =&gt; res.json()) .catch((e) =&gt; { console.log('an error occu...
Combine selectableItemBackground with shape for final background <p>I have a simple RecyclerView in which each row displays a line of text. Each row is selectable and so I want to use </p> <pre><code>android:background="?attr/selectableItemBackground" </code></pre> <p>The problem is that RecyclerViews do not allow fo...
<p>You can add dividers in several ways.</p> <p>One way is that your cell layout can have a divider in it, which is just a View with 1dp height and gray background. So you don't have to worry about combining background drawables.</p>
How do I get the 'initials' of a contact's middle name outlook vba <p><a href="https://i.stack.imgur.com/rErXE.png" rel="nofollow">Image</a></p> <p>From the image linked, I want to get the exchange user's middle name initials</p> <pre><code>Function getFullName(exchangeUser As ExchangeUser) As String Dim firstNam...
<p>Retrieve the <code>PR_MIDDLE_NAME</code> MAPI property using AddressEntry.PropertyAccessor.GetProperty. The DALS property name is <code>http://schemas.microsoft.com/mapi/proptag/0x3A44001F</code> </p>
autoplay the contents within a div with jquery <p>I have some contents within different divs that i will like to display without clicking on any tab. I have been able to toggle the visibility of these contents by clicking, but I will really prefer it to be display automatically in a loop by using jquery. Below are my c...
<p>@Yemmy here is a quick example this will loop over these animations 10 times until i = 10. You'll need to edit the delays so it displays as you like it.</p> <pre><code>$(document).ready(function(){ var i = 0; while (i &lt; 10){ $('#featureContent').fadeOut(400).addClass('hidden').delay(4...
HTML select options from a python list <p>I'm writing a python cgi script to setup a Hadoop cluster. I want to create an HTML select dropdown where the options are taken from a python list. Is this possible?? I've looked around a lot. Couldn't find any proper answer to this.</p> <p>This is what i've found so far on ...
<p>You need to generate a list of "option"s and pass them over to your javascript to make the list</p> <pre><code>values = {"A": "One", "B": "Two", "C": "Three"} options = [] for value in sorted(values.keys()): options.append("&lt;option value='" + value + "'&gt;" + values[value] + "&lt;/option&gt;") </code></pre...
Simple Flatbuffers over ZeroMQ C example - Copy struct to flatbuffer over zmq and back to a struct again <p>Posting my work for posterity. Realized after finishing my last example in C++ that I actually needed to do it in C all along (awesome, right?). Both iterations took me considerable effort as a Java programmer an...
<p>Car.fbs</p> <pre><code>namespace Test; table Car { name: string; model: string; year: int; } root_type Car; </code></pre> <p>Subscriber.c (listens for incoming structs)</p> <pre><code>// Hello World client #include "flatbuffers/Car_builder.h" // Generated by `flatcc`. #include "flatbuffers/flatbuffe...
Why can't node can't find the static directory? <p>I set up node so that it serves my public folder. Now I am trying to access the files in the public/data/event folder structure but it can't find it.</p> <pre><code>Here is my file structure public/ data/ event/ src/ scripts/eventController.js w...
<p>It's because fs.readFile('public/data/event/') from src/scripts/eventController.js looks for the stuff in 'src/scripts/public/data/event/', not 'public/data/event'. You should go with fs.readFile('../../public/data/event'). Or better yet, always use absolute paths.</p>
selenium run chrome on raspberry pi <p>If your seeing this I guess you are looking to run chromium on a raspberry pi with selenium.</p> <p>like this <code>Driver = webdriver.Chrome("path/to/chomedriver")</code> or like this <code>webdriver.Chrome()</code></p>
<p>I have concluded that after hours and a hole night of debugging that you can't because there is no chromedriver compatible with a raspberry pi processor. Even if you download the linux 32bit. You can confirm this by running this in a terminal window <code>path/to/chromedriver</code> it will give you this error </p> ...
jq - How to select objects based on a 'blacklist' of property values <p>Similar to the question answered here: <a href="http://stackoverflow.com/questions/34878915/jq-how-to-select-objects-based-on-a-whitelist-of-property-values" title="jq - How to select objects based on a &#39;whitelist&#39; of property values">jq - ...
<p>One solution would simply be to use <code>index</code> with <code>not</code>:</p> <pre><code>.[] | .author.login | select( . as $i | $blacklist | index($i) | not) </code></pre> <p>However, assuming your jq has <code>all/2</code>, there is something to be said for using it:</p> <pre><code>.[] | .author.login | sel...
Have a user create files with 777 permission in linux <p>I have an application. The processes for the application have cacheusr as user. When I create files in the application I get the following ownership and permission:</p> <pre><code>aless80&gt; ls -FGlAhpa test.xml -rwxrw-r-- 1 cacheusr 1.6K Oct 19 16:41 test.xml ...
<p>you can control the permissions of newly created files with the <code>umask</code> command:</p> <pre><code>$ umask u+rwx,g+rwx,o+rwx $ touch foo; mkdir bar $ ls -ld foo bar -rw-rw-rw- 1 user user 0 Oct 20 00:00 foo drwxrwxrwx 2 user user 1024 Oct 20 00:00 bar $ </code></pre>
Google Compute Engine canceling execution (Linux - execute on background) <p>[Solved] - It was actually a Linux question</p> <p>I have an instance on Google Compute Engine that I want to execute 50000 iterations of a Genetic Algorithm. The thing is everytime I lose the SSH connection, it cancels the execution and I do...
<p>This is a Linux question, not specific to GCE. Just use the <code>nohup &lt;command&gt; &amp;</code> pattern. For example, the following command will start a HTTP server on port 8080, even if you disconnect from SSH, it remains running in the background:</p> <pre><code>nohup python -m SimpleHTTPServer 8080 &amp; </...
Easier way to check if a string contains only one type of letter in python <p>I have a string <code>'829383&amp;&amp;*&amp;@&lt;&lt;&lt;&lt;&gt;&gt;&lt;&gt;GG'</code>. I want a way to measure if a string has only one type of letter. For example the string above would return True, because it only has two Gs, but this st...
<p>use <code>filter</code> with <code>str.isalpha</code> function to create a sublist containing only letters, then create a set. Final length must be one or your condition isn't met.</p> <pre><code>v="829383&amp;&amp;&amp;@&lt;&lt;&lt;&lt;&gt;&gt;&lt;&gt;GG" print(len(set(filter(str.isalpha,v)))==1) </code></pre>
Using the OVER clause in T-SQL to SELECT DISTINCT on all columns except one <p>I have a table with colA, colB, colC, colD. I need to SELECT DISTINCT on all columns except for colA. I've found some examples that demonstrate the use of the OVER clause in T-SQL to achieve this; however, they have been pretty specific, a...
<p>You can use DENSE_RANK twice, one with ASC order, the other with DESC order, than add them up and subtract 1. That way, you got the SELECT DISTINCT with the OVER clause.</p>
C++ - Assignment of raw pointers to unique_ptr nodes in a Linked List <p>I'm trying to figure out how to update my tail raw pointer to a new tail after removing a node in my linked list. (is homework)</p> <p>I've defined the head and tail as</p> <pre><code> std::unique_ptr&lt;Node&gt; head ; Node* tail ; </cod...
<p>The error messages imply that <code>Node::next</code> is a <code>std::unique_ptr&lt;Node&gt;</code>. You cannot compare/assign a <code>std::unique_ptr</code> directly to a raw pointer. You need to use the <code>std::unique_ptr::get()</code> method instead:</p> <pre><code>while (p-&gt;next.get() != tail) { p =...
gettext.tostring method cannot resolved <p>I am trying to send data to firebase. I want to call the time and date in a method and then the method that is responsible for sending data to fire base. When I try to call time and date it gives me an error.</p> <p>Here is my code.</p> <pre><code>public class Room1 extends...
<pre><code>public void sendDataToFireBase() { ft1 // &lt;-----get rid of this if </code></pre>
Yes or No answer from user with Validation and restart option? <p>(py) At the moment, the code below does not validate/output error messages when the user inputs something other than the two choices "y" and "n" because it's in a while loop. </p> <pre><code>again2=input("Would you like to calculate another GTIN-8 code?...
<pre><code>def get_choice(prompt="Enter y/n?",choices=["Y","y","n","N"],error="Invalid choice"): while True: result = input(prompt) if result in choices: return result print(error) </code></pre> <p>is probably a nice generic way to approach this problem</p> <pre><code>result = get_choice("...
C# DataTable - How to set a column to value without for loop? <p>I have a DataTable called dataTable that has two columns Col1 and Col2 and it contains five rows all initialized to null. How would I set the values in Col1 and Col2 to "1" and "2" respectively without using a for loop or foreach loop for each DataRow?</p...
<p>Use 10 assignment statements. No loop required.</p>
Ng-submit called twice with Routeprovider <p>I use the same <code>form</code> to create and update users in database. I can update properly, but when I create one user, submit send twice and create two same users in database.</p> <p>I have this in <code>RouteProvider</code>.</p> <pre><code> .config(function($routePro...
<p>You have declared two controllers, one for saving the user (<em>NewUserControlador</em>) and one for updating <em>(UserControlador)</em>. Both methods are called saveUser() and they are declared on the $scope. </p> <p>There might be a conflict because of the same name. Why don't you use one Controller for those ope...
Windows - Where can I find a system() list of parameters? <p>This is my first question here in StackOverflow, so if this question has already been made or is in the wrong topic, please excuse me.</p> <p>I'm studying C using Windows and I'm looking for a list/book/manual of usable parameters for the system() function. ...
<p>The purpose of system() API is to execute an external command, the parameters are the arguments of the command that you are trying to execute, just like if you were typed in shell prompt, there is not anything special to pass, just put into the string.</p>
writing data into mysql with mysqli_real_escape_string() but without & <p>iam using this code below, but the character "&amp;" will not be inserted into the db, also when i copy/paste some text from other pages and put it into the db the text ends for example in the middle of the text, dont know why, i tried also addsl...
<p>SQL Injection is merely just improperly formatted queries. What you're doing is not enough, stop now. Get into the practice of using prepared statements.. </p> <pre><code>$Connection = new mysqli("server","user","password","db"); $Query = $Connection-&gt;prepare("SELECT Email FROM test_tbl WHERE username=?"); $Quer...
Bootstrap multiple root modules each with different providers (provided from outside) <p>My application is not a SPA but I use Angular 2 for some parts of the page. I have created multiple root modules that I bootstrap with injectable providers which contain informations from the outside world:</p> <p>Root module 1:</...
<p>I came up with a very dirty workaround. Before bootstraping the module I add the provider directly to the annotations of the class using the Reflect API:</p> <pre><code>import "reflect-metadata"; import { MySecondRootModule } from "MySecondRootModule"; import { ServiceTwo } from "ServiceTwo"; export class MySecond...
Passing string from spinner to second activity <p>I'm building an app in which the first activity contains a spinner with strings "Red", "Yellow", "Blue" and "Green". When the user selects a spinner item, the second activity's background will be that color. I'm having issues with passing that value from the MainActivit...
<p>In case you wonder how to retrieve the spinner value : </p> <pre><code>String pickedColor = yourSpinner.getSelectedItem().toString(); </code></pre> <p>In your first Activity, when building intent do something like : </p> <pre><code>Intent intent = new Intent(MainActivity.this, DisplayActivity.class); intent.put...
InputStream reading file and counting lines/words <p>I'm working on a project and I'm trying to count </p> <p>1) The number of words. 2) The number of lines in a text file. </p> <p>My problem is that I can't figure out how to detect when the file goes to the next line so I can increment lines correctly. Basically if ...
<p>Do you have to use InputStream? (Yes) It is better to use a BufferedReader with an InputStreamReader passed in so you can read the file line by line and increment while doing so.</p> <pre><code>numLines = 0; try (BufferedReader br = new BufferedReader(new InputStreamReader(inputStream))) { String line; ...
How to get the Original Row and the Modified Row of DataRowView using DataRowViewVersion <p>I have a datatable that is filled from a database. I load a bindingsource with that table.</p> <pre><code>Sub LoadData() Dim bsTemp As BindingSource = New BindingSource bsTemp.DataSource = dtTemp End Sub </code></pre> <p>I t...
<p>The <code>New DataView(..)</code> does not determine which rows to copy, it only says what the state of the rows after they are in the view will have. Your first parameter says which rows <code>dtTemp.Copy</code>.</p> <p>Since the <code>copy</code> method of a datatable is a copy of all rows, you might want to use ...
How to convert a txt stream web request containing json to a jObject? <p>Trying to use a query Google has available, but they return an attached txt file containing the JSON results. I'm a newbie programmer, so I can't figure out why any of the shots I took aren't working.</p> <pre><code> public async Task&lt;YouTu...
<p>Problem one - you use <code>reader.ReadToEnd()</code> twice. First when you attempt to read errorMessage, Then on the next line you use it again. By the second time you have already read everything. Delete the line:</p> <pre><code>errorMessage = JsonConvert.SerializeObject(reader.ReadToEnd()); </code></pre> <p>Pro...
c# outlook addin xml dynamic menu not populating <p>I am using ribbon xml to make a dynamic context menu and the menu appears, but is showing up inside the menu itself. I see "Dynamic Menu" and hover over the context menu button, but there are no contents.</p> <p>My xml:</p> <pre><code>&lt;contextMenus&gt; &lt;con...
<p>fixed by using:</p> <pre><code>StringBuilder xmlString = new StringBuilder(@"&lt;menu xmlns=""http://schemas.microsoft.com/office/2009/07/customui"" &gt;"); for (int i = 0; i &lt; AddInDefs.thisProjectList.Count; i++) { xmlString.Append(@"&lt;button id='proj" + i.ToString() + "' label='"...
Angular 1.5 directive loop issue repeating the first element <p>referring to this plunker: <a href="https://plnkr.co/edit/kBoDTXmm2XbxXjpDA4M9?p=preview" rel="nofollow">https://plnkr.co/edit/kBoDTXmm2XbxXjpDA4M9?p=preview</a></p> <p>I am trying to create a directive that takes an array of json objects, syntax highligh...
<p>moving the timeout into a function helped with the specific problem I had</p> <pre><code>$scope.arrData=[]; function addIt(x) { $timeout(function(){ $scope.arrData.push({id:x}); }, 100); } for(var i=0; i &lt; 100; i++){ addIt(i) } </code></pre>
Is it idiomatic in go to handle all returned errors? <p>Many functions in go return errors to fit an interface, but these errors are always nil. Should these errors still be checked?</p> <p>An example for this is the <a href="https://golang.org/src/crypto/sha1/sha1.go?s=1064:1418" rel="nofollow">crypto/sha1 Write() fu...
<p>In situation that you described, you will probably be fine with not checking error, same as not checking errors when using <code>fmt.Println</code>. </p> <p>However, when you use <code>fmt.Println</code> you know which concrete implementations are being used. When you are using <code>Writer</code> interface (which ...
permission issue with docker under windows <p>I'm using this scheme : </p> <p>1/ I'm working on windows 7</p> <p>2/ I'm using vagrant to mount a "ubuntu/trusty64" box</p> <p>3/ I apt-get install ansible</p> <p>4/ I install docker and docker-compose with ansibe</p> <p>5/ I create a docker image with this dockerfile...
<p>This happens also in Linux. Docker copies the files and put root as owner. The only way I have found to overcome this without chmod, is archiving the files in a tar file and then use</p> <pre><code>ADD content.tgz /var/www/html </code></pre> <p>I will expand it automatically </p> <p>Regards </p>
What does the "e" flag mean in fopen <p>I saw a code snippet using <code>fopen(file_name, "r+e")</code>. What does the <code>e</code> flag mean in fopen? I couldn't find any information from the linux man page.</p>
<p>It's documented in the man page on my system (release 3.54 of the Linux man-pages project).</p> <blockquote> <p><strong>e</strong> (since glibc 2.7)<br> Open the file with the <code>O_CLOEXEC</code> flag. See <code>open(2)</code> for more information. This flag is ignored for <code>fdopen()</code>.</p> </blo...
Setting up Derby on MacOS Sierra <p>I am following Java: How To Program - Chapter 24. The chapter deals with database implementation in Java. I followed the steps to setup "Derby", but I get the error <code>java.sql.SQLException: Database 'books' not found.</code>. </p> <p>I checked $PATH to make sure it includes $DER...
<p>I figured the problem was. When the creating the database via <code>ij</code> I had to be in the same directory that the source file is. Now under eclipse I thought that this would mean I need to be under package folder(JAVAProject/src/package), but that was wrong. I had to be under (JAVAProject). </p>
Get multiple cursors (carets) at each find result in Intellij Idea editors? <p>I want to select all the string resource keys that contain the word key at the same time. I had a hard time figuring this out so I figured I'd post this for others. The <a href="https://www.jetbrains.com/help/idea/2016.2/multicursor.html" re...
<p>Intellij Idea calls this <a href="https://www.jetbrains.com/help/idea/2016.2/selecting-text-in-the-editor.html#d1743632e270" rel="nofollow"><em>multiselection</em></a>.</p> <p>Select the term to search for with your cursor. In my example, the word <em>key</em><br> <a href="https://i.stack.imgur.com/Rb6R3.png" rel="...
Cannot find module `dist/bin/x.js` when trying to use the command that comes with the package after npm global install <p>You did <code>npm install -g aVeryCoolPackage</code> and when you want to use <code>aVeryCoolPackage</code>'s command in your shell you get an error like this:</p> <pre><code>Error: Cannot find mod...
<p>In my case I had cloned the repo from github. And I did <code>npm install -g aVeryCoolPackage</code> at the same directory as where the repo is, so it actually installed my local copy of it where it has <code>.gitignore</code> the <code>dist</code> folder. As a result I didn't have <code>dist</code> in <code>/usr/lo...
How to split files according to a field and edit content <p>I am not sure if I can do this using unix commands or I need a more complicated code, like python.</p> <p>I have a big input file with 3 columns - id, different sequences (second column) grouped in different groups (3rd column).</p> <pre><code>Seq1 MV...
<p>This shell script should do the trick:</p> <pre><code>#!/usr/bin/env bash filename="data.txt" while read line; do id=$(echo "${line}" | awk '{print $1}') sequence=$(echo "${line}" | awk '{print $2}') group=$(echo "${line}" | awk '{print $3}') printf "&gt;${id}\n${sequence}\n" &gt;&gt; "${group}.txt...
C# thread report found items <p>Lets say I want to make a program that finds primes and shows them in a list as soon as one is found. I could make a thread that finds the primes, but how can I report them to the GUI thread? I was thinking about an event that raises when a prime is found, but now the event is on another...
<p>The <a href="https://msdn.microsoft.com/en-us/library/hh242985(v=vs.103).aspx" rel="nofollow">Reactive Extensions</a> framework is designed for creating and observing asynchronous sequences.</p>
d3 chart and google font not visible on github page <p>I uploaded a page onto Github and the HTML, CSS and Jquery and Jquery UI run very well. However, the d3 chart does not run. (PS: the chart is hidden, and becomes visible once the card on the middle is clicked. The data on the d3 chart was entered manually, it was n...
<p>you've got a <code>https</code> issue (trying to load <code>http</code> assets on a <code>https</code> site).</p> <p>Instead of defining the protocol as <code>http://</code> or <code>https://</code> that you reference your assets from, try using the protocol agnostic <code>//</code></p>
Left join in MySQL doesn't give me expected result <p>I have the following SQL:</p> <pre><code>SELECT t.teilnehmer_id, t.familienname, t.vorname, t.ort, t.ortsteil, t.kontrolle_ertrag, t.kontrolle_1j, t.kontrolle_brache, SUM(fe.nutzflaeche) AS nutzflaeche_ertrag, GROUP_CONCAT(fe.nutzflaeche) AS einzelfl_ertrag, ...
<p>As indicated in my comment, unavoidable 1:N joins usually need subqueries to calculate aggregate values appropriately; but it looks like your need can be solved with conditional aggregation, like so:</p> <pre><code>SELECT t.teilnehmer_id, t.familienname, t.vorname, t.ort, t.ortsteil, t.kontrolle_ertrag, t.kontrolle...
Get object initialization syntax from C# list <p>I have a List of type employee. </p> <pre><code>public class Employee { public string Name { get; set; } public int Id { get; set; } public string Level { get; set; } } List&lt;Employee&gt; empList = new List&lt;Employee&gt;(); </code><...
<p>I don't understand how having this code will help you, but here it is:</p> <pre><code>String.Join( Environment.NewLine, empList.Select(x =&gt; $"Employee e = new Employee() {{ Name = \"{x.Name}\", Id = {x.Id}, Level = \"{x.Level}\" }};")); </code></pre> <p>I'm going to suggest that a better option ...
Adding large data in Excel <p>I have around 200,000 data in excel which is separated in per 15min for each day for two years. Now, I want to add for each day(including all the 15mins data at once) eg. 01/01/2014 to 12/31/2016. I did it using a basic formula (=sum(range)) but it is very time consuming. Can anyone help m...
<p>It's faster and more reliable to work with big data sets using <a href="https://support.office.com/en-us/article/Introduction-to-Microsoft-Power-Query-for-Excel-6e92e2f4-2079-4e1f-bad5-89f6269cd605?ui=en-US&amp;rs=en-US&amp;ad=US" rel="nofollow">Ms Power Query</a> in which you can perform data analitics and process ...
LinkedIN Encounter error: Your application has not been authorized for the scope "r_basicprofile" <p>I was able to connect to the LinkedIn API for about two months and everything was correct. Was wondering if there has been any change to the API lately to block my app like so? </p> <p>The app was in development stage ...
<p>It's not you, it's LinkedIn. See others complaining about the same issue: <a href="https://twitter.com/search?q=linkedin%20oauth" rel="nofollow">https://twitter.com/search?q=linkedin%20oauth</a></p>
Validation for must_be_below_user_limit allowing users to exceed user limit Rails 4 <p>So I Am building a multi-tenant app in Rails 4 with Apartment, Devise and Devise_Invitable. </p> <p>I Want to Limit the number of users in each account based on the plan type. </p> <p>When I create a user the validation should look...
<p>Try add <code>retrun false</code> in the <code>must_be_below_user_limit</code> method.</p> <pre><code>def must_be_below_user_limit if account.present? &amp;&amp; persisted? &amp;&amp; account.users.count &gt; user_limit errors[:user_limit] = "can not have more than #{user_limit} users" return false end ...
Drawing an iscosceles triangle of asteriks on C++ <p>I am learning c++ and I'm trying draw an iscosceles triangle using asteriks. My code looks like:</p> <pre><code>int main(){ for(int i=1;i&lt;11;i++){ for(int j=0;j&lt;i;j++) { cout &lt;&lt; "*"; } cout &lt;&lt; endl; } return 0; } </code></pr...
<p>Alternative to @space_voyager this code support dynamic size so you can have as large as you can define with the size. </p> <p>The algorithm here is</p> <ol> <li>Check if current index or iteration is in the middle (in this case, 11. Programmatically is 10).</li> <li>If true, iterate j from 0 to current index of I...
How to execute multiline python code from a bash script? <p>I need to extend a shell script (bash). As I am much more familiar with python I want to do this by writing some lines of python code which depends on variables from the shell script. Adding an extra python file is not an option.</p> <pre><code>result=`python...
<p>Use a here-doc:</p> <pre><code>result=$(python &lt;&lt;EOF import stuff print('all $code in one very long line') EOF ) </code></pre>