Cassandra unlimited row response

Question: I'm using the Cassandra python driver working containing a table with 38500000 rows. I'm benchmarking various databases with a product I'm we're developing. To benchmark selection I use a filter that should return around half the rows with 3 selection columns (then I vary the selection columns to see which perform best). However when working with Cassandra I only get 57016 results each time per query (which must be some cap). I've tried using SimpleStatement and setting fetch_size = 38500000 but this didn't work. I was wondering if there's some parameter I should be changing as I can't find anything in the documentation apart from how Cassandra breaks down pages that go beyond the fetch_size.
[EDIT]
To add some more information the query returns:
cassandra.ReadFailure: Error from server: code=1300 [Replica(s) failed to execute read] message="Operation failed - received 0 responses and 1 failures" info={'consistency': 'LOCAL_ONE', 'required_responses': 1, 'received_responses': 0, 'failures': 1}
after I used session.default_fetch_size = None. Then after increasing tombstones to tombstone_failure_threshold: 10000000 and letting gc_grace_seconds = 0 I still get the same error. I've also gone into Cluster.py and set the _default_timeout = 1000 but that didn't lead to anything.
[EDIT 2]
Going through the debug console the error is:
<SELECT * FROM mydb.facttable WHERE int64 > 0 LIMIT 38500000>, total time 5007 msec, timeout 5000 msec, so again where can I modify the timeout 5000msec parameter?
Answer: Hy there.
Good news is I think I can explain your situation and problems but the bad news is I don't think there is an easy fix.
To give you the short answer and solution:
The read fails because Cassandra has safeguards in place to prevent "malfunctioning" or "rogue" queries from compromising the performance of the whole cluster. For this reason there is a read timeout (as you discovered yourself in EDIT2) that defaults to 5000ms.
If you need to increase that value, you need to modify read_request_timeout_in_ms in cassandra.yaml.
This however is not a real solution.
Now, for the long answer:
From what I understand you are targeting with your query 38M rows that you want Cassandra to filter and then return approximately 19M rows. I could see this value achieved on production hardware with well designed tables and a lot of fine-tuning.
Given the info in EDIT1, it looks like you are using a one node cluster so I imagine this is a small development node maybe even hosted on your laptop/pc. While sharing the table schema and query could have provided more info and lead to more advice, overall the problem remains that you are trying to run a task on a clearly under-powered cluster(node actually).
From you data, the node was able to process just over 20k rows per second(and return 10k) before timing out. From my experience this seems consistent with a low resource devel node. Extrapolating from this, it would take your node around half an hour to go trough 38M records assuming it will have the memory to do so and no other configuration will pose problems (if I didn't messe up the calculations). That is a very long time for a query, even for an administrative one.
When trying to work with so many rows you should not only try to have proportional HW to run the queries against but also:

Avoid full scans (you should always try and hit a single partition, if that is not the case you should probably rethink the DB model);
Most partitions should be under 10MB and all should be under 100MB;
Partitions while hard-capped at 2 billion cells((no. of rows) * (avg. no. of cells per row)) should usually remain under 100k cells.

Given the 3 "best practices" generally accepted as such, and the data you provided, I am inclined to believe that you are not implementing at least 2 of the 3. That and combined with under-powered HW leads to a lack of a simple solution (like just increasing the timeout value).
My suggestion to really resolve the problem is:

If you are only doing this to test your code or different approaches, then use a proportional amount of data with the power of the devel "server" compared to your production one. You should still make sure the model you are using cold be effectively run in production given that the large amount of required rows make me think there might be a problem with the DB model.
Open another question with information about your situation, current schema and desired outcome and you could receive help on modeling your use-case. While Cassandra can be very powerful when used right, it can be extremely inefficient when badly used.

Hope this helped,
Cheers.
Comment: Thanks this clears a few things up. I edited all the cassandra.yaml parameters but this lead to nothing (which is why I went edited the python package). The table is on a single node, a GP-BM1-S terraform sever (https://www.scaleway.com/en/pricing/). The issue is when I use Clickhouse or LocustDB I get response times of 4-7s, and on MariaDB around 40s. So why does Cassandra take so much longer? Also when setting up the table I have 16 rows of which a composite key, with the partition key being 100000 rows long and the composite key iterating this 385 times which works fine on all other setups.
Comment: @JohnMiller  Well, first of, did you edit read_request_timeout_in_ms and if yes did it produce any changes? It should have. Looking at the specs it really is strager that you got such bad results. On specs like that you should have been able to process way more even if you were doing it inefficiently. Well if the partition has 100k rows it means that you are doing a full table scan. Can you pelase explain what you mean by "composite key iterating this 385"? Could you also make a quick calculation of the size of a partition?( sum of the avg. size of the 16 columns *100k)
Comment: @JohnMiller Could you also provide some info about your setup? How is cassandra installed on the instance and most important did you monitor the resource usage during the query? (i recommend dstat with the memory option (-am) over using top). As another idea, please run the query with trace on and try and provide at least part of the return values. Tkx.
Comment: Sorry but I'm closing the question, I have strict deadlines for my internship and Cassandra doesn't look like a good DBMS to compete with LocustDB, Clickhouse etc.

Cassandra unlimited row response


Paperclip styles not being created

Question: Paperclip works fine in my rails 3 app, but its only creating one file.  The original file is 1600x1280, and only one file sized to 200 is being created.
<code>  :styles => { :preview => "500x500>", :full => "100%", :pdf_thumbnail => ["200x200>", :jpg] },
</code>
The style being created is pdf_thumbnail.  And, for some reason paperclip is not creating an original.
<code> paperclip (3.3.0)
 rails 3.2.8
 heroku, s3
</code>
Has something changed in 3.3.0?  Anyone know why paperclip is not creating the files?
Comment: I added rmagick gem...no change
Comment: I thought you had to add has_attached_file :photo to your model.rb file then has_attached_file :photo, :styles => { :full => "100%", :small => "150x150>" }
Comment: Ya, my set up is - has_attached_file :document, :styles => ...
Comment: what happens if you explicitly say :full => ["100%", :jpg]
Answer: I am embarrassed to admin I have paperclip in six projects and I was able to overlook this.  I did not have a style in the path.  Therefor, each style was being created but was overwriting the previously created image (because they all would have the same name).  As a result only one image with the last style was being created.  Adding :style to my path fixed everything allowed each image to be created.
Answer: Try add rmagick gem in your gemfile
Comment: try change 300x300> -> 300x300! OR 300x300#
Comment: I played with the image styles (like Cezinha recommended)...nothing seems to be changing anything.  PaperClip is not creating an original, and not creating styles.  I agree with Cezinha that it seems like rmagick is not doing its job.

Paperclip styles not being created


First contest problem

Question: I downloaded a contest and worked the first problem which is:

There exists a digit Y such that, for any digit X, the seven-digit number 1 2 3 X 5 Y 7 is not a multiple of 11.
  Compute Y.

My attempt:
$$\begin{align}
1+3+5+7&=2+X+Y \\
16&=2+X+Y \\
14&=X+Y \\
\implies\quad Y&=14-X \\
\end{align}$$
The values of Y for which the number can be divided by $11$ are: $5,6,7,8,9.$
How would I deduce that the only value of Y for which the number can't be divided by $11$ is only $4$?
Comment: It's not equal, but congruent modulo $11$
Comment: @Mathink Consider the number $209=11\cdot 19$ - a multiple of $11$. If you write out the sums of alternating digits, you get $2+9=0$ or $11=0$ which isn't true. The point is that the number on the left and the number on the right must differ by a multiple of $11$ - they needn't be equal. (And the idea of "differ by a multiple of $11$" is expressed as "are congruent mod $11$" and written as $x\equiv y\pmod{11}$)
Comment: What is the contest, may I ask? It looks familiar
Comment: Looks like its from 2014: http://associations.missouristate.edu/assets/moarml/2014-9-14s.doc
Comment: Oh yes, ARML, I remember this now.
Comment: @muaddib: Yes, That is the contest
Comment: @ Thomas Andrews: Sorry I don't understand. I'm still on intermediate algebra.
Comment: @Meelo: Oh! I see, thanks.
Answer: It looks like you're almost done. We can express the problem, from where you've left off, to find a $Y$ such that the equation
$$Y\equiv 14-X\pmod{11}$$
has no solution. Notice that we have to work mod 11 - the two sums you list don't have to be equal for a number to be divisible by $11$ - the sums may differ by a multiple of $11$. Doing this is relatively easy though - we can simply list the values the right hand side could obtain. These are, in particular:
$$14,\,13,\,12,\,11,\,10,\,9,\,8,\,7,\,6,\,5$$
where $X$ ranges from $0$ to $9$. Notably, none of these values are congruent to $4$ mod $11$, so if we set $Y=4$, we cannot match that value on the right side. Thus, $Y=4$ is the answer.
Answer: You say $Y =14-X$ if the number is divisible. Because X is a digit (in base ten), it ranges from $0$ to $9$; thus $Y$ ranges from $14-0=14$ to $14-9=5$. But note that $14$, $13$, $12$, $11$, and $10$ are not accepted values for a single digit. If the number has to be divisible by $11$, $Y$ must be $11$ less than the numbers above. Thus $Y$ can be 3, 2, 1, 0, -1 (this is still invalid), or from 5 to 9 as before.
To make the number not divisible, $Y$ must therefore be 4.

First contest problem


How can I find google business/place ID for a service area?

Question: I need your help about how can I get the business/PlaceID for a business that doesn't have a specific address.
It's a service provider (contractor) for the whole city. Therefore, the address is the name of the city and I can't find it using the placeid search.
Here is one of the for example:
Google Map Search Results Link
As you can see it show the whole Las Vegas city as the business location, Now if you try to search using google placeid finder you won't find it:
Google Place ID Finder Link
Your help would be appreciated
Answer: You have to use the Place ID finder on the Google My Business support page:
https://developers.google.com/my-business/content/faq#how-to-find-placeid
https://support.google.com/business/answer/7035772#place_id
This Place ID finder shows also the Service Area Businesses. I tried with your example and it worked fine
Comment: Unfortunately, Places API excludes SABs from their search. There was a feature request in Google issue tracker, but Google rejected it. Please have a look at this comment from Google: https://issuetracker.google.com/issues/35828187#comment20
Comment: It's working on the google place id page however I want to use it on my own web app and the same code with my API key doesn't work, I can't find this business.
Comment: They mentioned there that those who have been authorized to use GMB API will have an option to view SAB, my project has been authorized too but I still can't see SAB in my results.


An inequality about the gradient of a harmonic function

Question: Let $G$ a open and connected set. Consider a function $z=2R^{-\alpha}v-v^2$ with $R$ that will be chosen suitably small, where $v$ is a harmonic function in $G$, and satisfies
$$|x|^\alpha\leqslant v(x)\leqslant C_0|x|^\alpha. \ \ (*)$$
Then,
$$\Delta z+f(z)=-2|\nabla v|^2+f(z)\leqslant-C|x|^{2\alpha-2}f(0)+Kz,$$
where $K$ is the Lipschitz constant of the function $f$. ($f$ is a Lipschitz-continuous function).
I have no idea how to obtain this second inequality and I don't know if $(*)$ is really necessary.
Comment: what is C in the last inequality RHS term??
Comment: $C$ is an arbitrary constant.
Comment: What do we know about $\alpha$?
Comment: We just know that $\alpha>0$. I really dont know how to prove this second inequality. In the article H. Beresticky, L. A. Caffareli and L. Nirenberg, Monotonocity for elliptic equations in unbounded lipschitz domains, page: $1102$, he says that is a direct computation.
Answer: It's good that you gave a reference. In many questions of the kind "I don't follow the argument here" the underlying reason is that the OP did not notice the relevance of some information from the paper. Hence, the information included in the post is usually insufficient to give an explanation.
Here, the missing piece is that $v$ is homogeneous of degree $\alpha$. This means $v(tx)=t^\alpha v(x)$ for all $t\ge 0$. Differentiating with respect to $t$, we find $\frac{d}{dt}v(tx) = \alpha t^{-1} v(tx)$. Specializing this to $|x|=1$ and writing $y=tx$, we obtain $\frac{\partial}{\partial n}v(y)=\alpha |y|^{-1}v(y)$ where $\frac{\partial}{\partial n}$ is the derivative in radial direction. As a consequence, $|\nabla v(y)|\ge \alpha |y|^{-1}v(y)$ for all $y$. Notice that harmonicity is not used here; only homogeneity is needed.
Recalling that $|v(x)|\ge |x|^{\alpha}$, we get $|\nabla v(x)|\ge \alpha |x|^{\alpha-1}$. Therefore,
$$-2|\nabla v|^2 \leqslant -2\alpha^2|x|^{2\alpha-2}$$
At the same time, the Lipschitz property of $f$ tells us that
$$f(z)\le f(0)+Kz$$
Add  the inequalities:
$$-2|\nabla v|^2 + f(z) \leqslant -2\alpha^2|x|^{2\alpha-2}+f(0)+Kz$$
The plus sign before $f(0)$ is missing in the paper. Typos happen. If you look at the very next displayed formula in the paper, you will see the plus sign reappearing there.
Comment: Thank you very much @Pavel M, you helped me a lot. As you have this article, could you explain something about this problem? In the page $1101$, he explains how to obtain the expression $(4.5)$ and talk about the constants $k'$ and $\alpha$. Do you understand this? Thank you!!!
Comment: @JoséCarlos Since this is a separate question, I wrote a separate answer. The proof of Lemma 2.1 is relevant, too.
Answer: This is an answer to a question raised in comment to another answer. Since it is of independent interest (perhaps of more interest than the original answer), I post it as a separate answer.

Question: How do we construct homogeneous harmonic functions that are positive on a cone?

Answer. Say, we want a positive homogeneous harmonic function $v$ on the cone $K=\{x\in\mathbb R^n:x_n>\kappa|x|\}$ where $\kappa\in (-1,1)$. Let $\alpha$ denote the degree of homogeneity of $v$: that is,  $v(rx)=r^\alpha v(x)$ for all $x\in K$. The function $v$ is determined by the number $\alpha$ and by the restriction of $v$ to the unit spherical cap $S\cap K$. The Laplacian of $v$ can be decomposed into radial and tangential terms: $$\Delta v = v_{rr}+\frac{n-1}{r}v_r+\frac{1}{r^2}\Delta_S v$$ where $\Delta_S$ is the Laplace-Beltrami operator on the unit sphere $S$. Using the homogeneity of $v$, we find $v_r = \frac{\alpha }{r}v$ and $v_{rr}=\frac{\alpha(\alpha-1)}{r^2}v$. On the unit sphere $r=1$, and  the radial term of $\Delta v$ simplifies to $\alpha(n+\alpha-2)v$.
Therefore, the restriction of $v$ to $S\cap K$ must be an eigenfunction of $\Delta_S$:
$$\Delta_S v + \mu v =0, \ \ \ \ \mu = \alpha(n+\alpha-2) $$
Where do we get such a thing from?
Well, there is a well-developed theory of eigenfunctions and eigenvalues for $\Delta_S$ with the Dirichlet boundary conditions. In particular, it is known that the eigenfunction corresponding to the lowest eigenvalue $\mu_1$ has constant sign. So this is what we use for $v$. There are two drawbacks:

(a) we cannot choose $\alpha$ ourselves, because $\alpha(n+\alpha-2)=\mu_1$ and $\mu_1$ is determined by the domain $S\cap K$.
(b) the function $v$ vanishes on the boundary of spherical cap, and therefore is not bounded away from $0$.

Concerning (a), we know that $\mu_1$ is monotone with respect to domain: larger domains (in the sense of inclusion) have lower value of $\mu_1$. (Physical interpretation: a bigger drum emits lower frequencies.) Therefore, the value of $\alpha$ decreases when the domain is enlarged. Also, when $K$ is exactly half-space $\{x_n>0\}$, we know our positive harmonic function directly: it's $v(x)=x_n$, which is homogeneous of degree $\alpha=1$. Therefore, in the cones that are smaller than half-space we have $\alpha>1$, and in the cones that are larger than half-space we have $\alpha<1$.
Concerning (b), we do the following: carry out the above construction in a slightly larger cone $K'$ and then restrict $v$ to $K$. Since the closure of $K\cap S$ is a compact subset of $K'\cap S$, the function $v$ attains a positive minimum there. We can multiply $v$ by a constant and achieve $1\le v\le C$ on $K\cap S$, hence $|x|^\alpha\le v(x)\le C|x|^\alpha$ on all of $K$.
Comment: one more time,thank you very much! You are helped me.I just didn't understand two steps in your answer.

First: When you said that the function $v$ is determined by the number α and by the restriction of v to the unit spherical cap $S\cap K$. Why $v$ satisfies this? Because $v$ is homogeneous?

Second: When you obtain the inequality $1\leq v\leq C$, the $v$ is restrict in the spherical cap $K\cap S$. How did you obtain the inequality $|x|^\alpha\leq v(x)\leq C|x|^\alpha$ in all $K$? We were in a small domain and $K$ can be as big as we want. I didn't understand this consequence.
Comment: The answer to both questions is: by homogeneity. For example: once you know that $u(0.6,0.8)=7$ and that the degree of homogeneity is $\alpha=2$, you can conclude that $u(3,4)=5^2\cdot 7 = 175$, and $u(30,40)=17500$. That is, the values on the entire half-line from $(0,0)$ through $(0.6,0.8)$ are determined. Similarly, if I only know that $1\le u(0.6,0.8)\le 7$, I can conclude that $25\le u(3,4)\le 175$, etc.
Comment: I'm sorry for one more question but I'm trying to type this article and I really need understand this step. If $x\in K$, then $x=tz$, for some $t\geq0$ and $z\in S$. For each $z\in S$, the values $tz$ are determined, ok? But, in the end, we have
$$|t|^\alpha\leq u(x)=u(tz)\leq C|t|^\alpha,$$
and I need $|x|^\alpha\leq u(x)\leq C|x|^\alpha,$ for all $x\in K$.
Comment: @JoséCarlos What is $|x|$, given that $x=tz$ where $z$ is a unit vector ($z\in S$)?
Comment: Im sorry, Im getting retarded. LoL Thank you!
Comment: In the beginning of your arguments, you are considering the existence of a function $v$ that is homogeneous and harmonic in the set $K$. What guarantees this existence? If this is possible, I understood the rest of the demonstration. Because starting at the existence of this function, we discovery the eigenfunction of the laplace-beltrami operator.
Comment: @Jose It is precisely the other way around: we get a harmonic function from an eigenfunction of Laplace-Beltrami on a spherical cap.
Comment: I see now! We have two ways to study this function!!
Comment: I have been thinking about your answer and I have one last doubt. When you get $\mu=\alpha(n+\alpha-2)$, this represent an eigenvalue. Why this can represent the Principal eigenvalue? Why $\alpha=1$ give us the lowest eigenvalue to the function $v(x)=x_n$?
Comment: @JoséCarlos We let $\mu$ be the principal eigenvalue, and then solve for $\alpha$ from this relation.
Comment: But all the eigenvalues can be represent by $\mu=\alpha(n+\alpha-2)$?
Comment: @JoséCarlos For any positive number $\mu$ the quadratic equation $\alpha(n+\alpha-2)=\mu$ has a positive solution.
Comment: So we define this to the lowest value? And, Why $\alpha=1$ give us the lowest eigenvalue to the function $v(x)=x_n$?
Comment: @JoséCarlos I will refrain from reacting to your further questions.
Comment: Anyway, thank you for the patience.


How to Reproduce Following JAVA Encryption into NODEJS Equivalent (Either Using node-rsa or crypto module)?

Question: I have following java method where i need to convert into nodejs, the problems was the output from nodejs seems rather odd.
Here is my java code
private static final String SIGN_ALGORITHMS = "MD5WithRSA";

    public static String sign(String content, String privateKey, String input_charset) {
            try {
                PKCS8EncodedKeySpec priPKCS8 = new PKCS8EncodedKeySpec(Base64.decode(privateKey));
                KeyFactory keyf = KeyFactory.getInstance("RSA");
                PrivateKey priKey = keyf.generatePrivate(priPKCS8);
                java.security.Signature signature = java.security.Signature.getInstance(SIGN_ALGORITHMS);
                signature.initSign(priKey);
                signature.update(content.getBytes(input_charset));
                byte[] signed = signature.sign();
                return Base64.encode(signed);
            } catch (Exception e) {
                e.printStackTrace();
            }

            return null;
        }

where:
content is just regular string to encrypt e.g: lorem ipsum,
privateKey is string representation of private key, and
input_charset is UTF-8
How do i get the value of Base64.encode(signed) in nodejs?
Comment: Hi @xcode Did you get this working? iam also working on this. can you share the solution if you got it working?
Answer: Just use NodeJS in built Crypto functions:
https://nodejs.org/dist/latest-v10.x/docs/api/crypto.html#crypto_crypto


Product decomposition of a nonnegative matrix

Question: Suppose $A\neq 0$ is a nonnegative matrix which can be decomposed as $BC$ with $B\neq 0$ nonnegative and $C$ orthogonal. Then, is $C$ also nonnegative?
I think yes. The case when $B$ is invertible is trivial. But, if $B$ is not invertible, it does not seem obvious. Any hints? Thanks beforehand.
Answer: No. For example, if $A = B = 0$, then $C$ can be anything.
Comment: Then you can still do $A' \oplus 0 = (B' \oplus 0)(C' \oplus D)$ and $D$ can be anything.
Comment: ok. Suppose I make the assumption that $A\neq 0$ and $B\neq 0$, then? edited the post


In a triangle $ABC$, prove that $\sin A \times \cos A + 2 \cos B \times \cos C \leq 1$

Question: I've stumbled upon an exercise I don't really know how to handle. It's the following inequality:
If $A, B$ and $C$ are the angles of a triangle, prove $$\sin A \times \cos A + 2 \cos B \times \cos C \leq 1.$$
I've tried using triangle relations with its corresponding angles and other trigonometric formulas to reduce the problem to a simpler relation, but I've only made it worse so far.
Any help or suggestions? Cheers!
Comment: Welcome to MSE! Here's an admittedly rather long but very helpful tutorial on using MathJax formatting to make the mathematics in your questions easier for everyone (including you, likely) to read: https://math.meta.stackexchange.com/questions/5020/mathjax-basic-tutorial-and-quick-reference
Comment: Thanks for the tutorial. Sorry for being careless about this!
Comment: It's okay, I appreciate that you're making an effort to learn! (That's more than can be said for some users)
Answer: using the formulas
$$S=\frac{bc}{2}\sin(A)$$
and
$$\cos(A)=\frac{b^2+c^2-a^2}{2bc}$$ ect.
you will have $$\frac{2A}{bc}\frac{b^2+c^2-a^2}{2bc}+2\frac{a^2+c^2-b^2}{2ac}\frac{a^2+b^2-c^2}{2ab}\le 1$$
and $$S=\sqrt{s(s-a)(s-b)(s-c)}$$ where $$s=\frac{a+b+c}{2}$$
we get $$4a^2(b^2+c^2-a^2)S\le bc(4a^2bc-2(a^2+c^2-b^2)(a^2+b^2-c^2))$$
now i would consider the cases:
$$b^2+c^2=a^2$$
$$b^2+c^2<a^2$$
$$b^2+c^2>a^2$$
the first case gives us $$0\le (b-c)^2$$ which is true.


How to infer and convert dtypes in pandas dataframe?

Question: Here is my sample dataframe. I would like to convert the dtypes to boolean in column A and B, string in C and integer in D and E.
I am trying to use panda's method convert_dtypes() but it returns string for every one. How can I "automatically" convert the types?
{'A': {0: nan,
      1: nan,
      2: nan,
      3: nan,
      4: nan,
      5: nan,
      6: nan,
      7: 'true',
      8: nan,
      9: 'true'},
     'B': {0: nan,
      1: nan,
      2: nan,
      3: nan,
      4: nan,
      5: nan,
      6: nan,
      7: 'true',
      8: nan,
      9: 'true'},
     'C': {0: 'CustomersData',
      1: 'CustomersData',
      2: 'CustomersData',
      3: 'CustomersData',
      4: 'CustomersData',
      5: 'CustomersData',
      6: 'CustomersData',
      7: 'TestData',
      8: 'CustomersData',
      9: 'CustomersData'},
     'D': {0: '4014',
      1: '4014',
      2: '4014',
      3: '4014',
      4: '4014',
      5: '4014',
      6: '4014',
      7: '500',
      8: '4014',
      9: '500'},
     'E': {0: '8',
      1: '8',
      2: '8',
      3: '8',
      4: '8',
      5: '8',
      6: '13',
      7: '13',
      8: '8',
      9: '13'}}

df.convert_types().dtypes gives:
A string
B string
C string
D string
E string

Comment: https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.convert_dtypes.html doesn't do what you think it does - it converts types from the "old" types to the corresponding "new" types that support `pd.NA` - when you load in the data, you should specify the specific dtypes you want
Comment: @ifly6 I get it as key-value columns for each request and this is the result of preprocessing. How can I infer and convert each column to the most appropriate dtype?
Comment: with the original object columns (ie before attempting to call `convert_dtypes`) try https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.infer_objects.html.
Comment: @ifly6 no change. Same behaviour. Please advise.
Comment: you'll have to specify them explicitly then
Comment: The only way to solve it is: Save it as csv, load again and you get the right inference. @ifly6
Comment: https://stackoverflow.com/questions/70367183/is-there-any-way-to-extract-the-dtype-conversion-functionality-from-pandas-rea
Answer: The only way that worked for me is a "workaround" to save it as csv and load again.
Pandas read_csv infers the types of the columns and worked for me.
Will be happy to know if I can solve it without this workaround.
Answer: You could use pandas.DataFrame.convert_dtypes : it returns a new dataframe with columns as types guessed by pandas, the same way it does when loading from a csv.
See the example from the doc :
df = pd.DataFrame(
    {
        "a": pd.Series([1, 2, 3], dtype=np.dtype("int32")),
        "b": pd.Series(["x", "y", "z"], dtype=np.dtype("O")),
        "c": pd.Series([True, False, np.nan], dtype=np.dtype("O")),
        "d": pd.Series(["h", "i", np.nan], dtype=np.dtype("O")),
        "e": pd.Series([10, np.nan, 20], dtype=np.dtype("float")),
        "f": pd.Series([np.nan, 100.5, 200], dtype=np.dtype("float")),
    }
)

guessed_dtypes_df = df.convert_dtypes()

print(df.dtypes)
print(guessed_dtypes_df.dtypes)

which gives :
# before dtypes      # after dtypes
a       int32        a      Int32
b      object        b     string
c      object        c    boolean
d      object        d     string
e     float64        e      Int64
f     float64        f    Float64
dtype: object        dtype: object

Answer: First check which dtypes the dataframe holds per column.
print(df.dtypes)

Then change all column value types.
df['A'] = df['A'].astype(bool)
df['B'] = df['B'].astype(bool)
df['C'] = df['C'].astype(str)
df['D'] = df['D'].astype(int)
df['E'] = df['E'].astype(int)

Then check if if values properly converted.
print(df.dtypes)

This should work. Let me know if it does not.
Reference
Comment: Sorry but all my dtypes are objects, so I am sorry but your answer doesn't help me. I have checked it already. @richard-scholtens
Comment: No problem. Good luck!


What is this stubbed out copper line?

Question: I removed an old shower tub combo and discovered a stubbed out pipe coming through the floor. What is it? Is it an old drain pipe or old incoming pipe
Comment: @manassehkatz-Moving2Codidact  Has been some pictures on here of old copper looking big drain pipes.  Guess they were for rich folks homes.
Comment: Copper is nearly always supply. Old drains before pvc were typically cast iron.
Answer: Too small for a drain pipe, probably an old water pipe.
Would be nice to find where it comes from, and disable it at source/beginning, with a proper cap.
Will probably want to keep it easy to look at, incase it ever starts leaking,if not removed, no burying it in cement/under a expensive floor.
To test if it still connected to house water, turn off water, cut pipe for cap, turn on water.  If no water probably has been disconnected somewhere else.  If water, add cap or shut off valve for future work.
Comment: Consider if water comes out to put a valve on it, that will make using it later much easier.

What is this stubbed out copper line?


Finding percentage of similarity among some text files

Question: I have made a program in C++ which generates a text file based on a sequence of values of an integer variable v varying between 1 and 100. The text file format is as follows:
file1.txt
1 2 3 4 5

file2.txt
4 5 6 7 8

file3.txt
8 4 5 7 1

.......

Say, I have generated 100 text files (file1.txt to file100.txt). I want to check the text files one by one and find the percentage of similarities between them.
I don't want to check all the 100 text files rather I want to stop my checking when I am getting more or less similar result for some consecutive files.
How can I perform the check for similarity? say, I have calculated the percentage of similarity between file1 and file2. Now will I calculate the similarity for file2 and file3 or file1 and file3 and so on?
To be more precise, what is the logic of performing this checking?
Comment: How do you consider similarity? Is it share some letters ?  Share some words ? Or is order relevant as well ? E.g. Is 12345 more similar to 54321 or to 12457 ?
Comment: 12345 more similar to 54321. by similarity, i mean to say both files will contain maximum same digits @Christophe
Comment: Why is there the tag standard-deviation ?  Do you intend to do statistical calculation of standard deviations ?
Comment: You'll have to define "similar" more precisely, and you also need to define what you want your output to be. Do you want to know which file is most similar to file1, which is most similar to file2, etc., so that you'd have a list that shows each file and which file is most similar to it? What do you do if files 1, 17, and 26 are identical? What if file 1 contains `12345`, and none of the other files contain any of those numbers? Without clearly specifying your output, any advice we give you will likely be wrong.
Answer: According to your comments, the degree of similarity is calculated based on the common number of digits, regardless of their order.
Similarity between two files
The easiest way to do it, would be to load two consecutive files (say two open ifstream sfs1 and sts2) into two vectors:
std::vector<int> v1{1,2,3,4,5,6,7,8};

    copy(istream_iterator<int>(sfs1), istream_iterator<int>(), back_inserter(v1));
    copy(istream_iterator<int>(sfs2), istream_iterator<int>(), back_inserter(v2));

Sort the vectors:
    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());

Then take the intersection of the two sorted vectors using the standard algorithm:
    set_intersection(v1.cbegin(), v1.cend(), v2.cbegin(), v2.cend(), back_inserter(sim));

You then just have to look for the sizes:
    cout << "Similar elements: " << sim.size()<<endl;
    cout << "Similarity coefficient: "<< (double)sim.size()/max(v1.size(), v2.size())*100 <<"%"<<endl;

Now you have to add some error handling in case both vectors would be empty (which would lead to a divide by 0 here).
Here an online demo using stringstreams instead of filestreams:
How to do for several files
According to your question, you don't need to look for similarities in each possible pair of files, but only between subsequent files.
So after you have compared the two first files, you just need to copy v2 into v1, read the next file into v2 and sort it.  And calculate new similarity.
You also need to have a counter to count consecutive near-matches.  Increment it, every time the similarity is beyond a certain threshold (e.g. 90%).  Reset it to 0 every time the similarity is below.  As soon as your counter reaches the number of consecutive near-matches that you expect, just stop :-)


Show result after button action to table view cell

Question: var monthsOfNonWorking = ["1. mēnesis","2. mēnesis","3. mēnesis","4. mēnesis","5. mēnesis","6. mēnesis","7. mēnesis","8. mēnesis","9. mēnesis",]

@IBAction func nonWorkingAllowanceCalculate(_ sender: Any) {

    var firstThreeMonths :Double
    var secondThreeMonths :Double
    var LastThreeMonths :Double

    let bezdarbienieka_alga = Double(bezd_alga.text!)

    if (staza_masiva_lasisana == 0) {

        firstThreeMonths = Double(bezdarbienieka_alga! / 2)

        secondThreeMonths = Double(firstThreeMonths / 2)

        LastThreeMonths = Double(bezdarbienieka_alga! / 1.6 - secondThreeMonths) }}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! MonthTableViewCell

    switch indexPath.row {
    case 0: cell.nonWorkingAllowance?.text = String()

    }

    cell.monthLabel?.text = monthsOfNonWorking[indexPath.row]

    return cell
}

How to show result on table view cell after calculation with button action?
For example, I want to show data firstThreeMonths on tableViewCell?
Answer: Just add tableView.reloadData() in the end of the button action.
@IBAction func nonWorkingAllowanceCalculate(_ sender: Any) {

var firstThreeMonths :Double
var secondThreeMonths :Double
var LastThreeMonths :Double

let bezdarbienieka_alga = Double(bezd_alga.text!)

if (staza_masiva_lasisana == 0) {

    firstThreeMonths = Double(bezdarbienieka_alga! / 2)

    secondThreeMonths = Double(firstThreeMonths / 2)

    LastThreeMonths = Double(bezdarbienieka_alga! / 1.6 - secondThreeMonths)
 }

 tableView.reloadData()

}

Comment: @user3465573 if the answer solves your issue, please don't forget to accept it (green tick).
Comment: Thank you, maybe this question is not so hard, but I'm studying. Thank you.


Ubuntu 22.04: How to change login screen background?

Question: How to change the login screen background on Ubuntu 22.04?
Answer: I changed the login background images with these commands:
<code>sudo apt update && sudo apt upgrade
sudo apt install libglib2.0-dev-bin
wget -qO - https://github.com/PRATAP-KUMAR/ubuntu-gdm-set-background/archive/main.tar.gz | tar zx --strip-components=1 ubuntu-gdm-set-background-main/ubuntu-gdm-set-background
sudo ./ubuntu-gdm-set-background --image IMAGE_PATH
</code>
replace IMAGE_PATH with the actual path of the image you want to set as background.
Its explained here : https://ubuntuhandbook.org/index.php/2022/04/login-screen-background-ubuntu-22-04/


Navigator.pop(context) Not returning to the Previous Screen Flutter

Question: I have a Contacts Page with List of contacts and a FloatingActionButton which goes to Add_Contact() page.
There is a form and a FlatButton SAVE on the AppBar which when clicked posts the form data and should return back to the previous list of contacts page.
But whenever I click on the save button it just stays on that page doesn't return back to the previous page. I had also tried adding a SnackBar and then a FlushBar to show that the contact is saved but even that doesn't show up on the screen.
contacts_page.dart:
 //Rest of the code above
 floatingActionButton: _bottomButtons(context),
        ));
  }

  Widget _bottomButtons(BuildContext context) {
    return _tabController.index == 0
        ? FloatingActionButton(
            shape: StadiumBorder(),
            onPressed: () {
              Navigator.push(context, MaterialPageRoute(builder: (_) {
                return AddContacts();
              }));
            },
            backgroundColor: Colors.cyan,
            child: Icon(
              Icons.person_add,
              color: Colors.white,
            ))
        : FloatingActionButton(
            shape: StadiumBorder(),
            onPressed: () {
              Navigator.push(context, MaterialPageRoute(builder: (_) {
                return AddCompany();
              }));
            },
            backgroundColor: Colors.cyan,
            child: Icon(
              Icons.add,
              color: Colors.white,
            ),
          );
  }

add_contacts.dart:
 Future saveContact() async {
    final String firstName = _firstName.text;
    final String lastName = _lastName.text;
    final String email = _email.text;

    final AddContactModel contact =
        await API_Manager().addContact(firstName, lastName, email);
    Navigator.pop(context); //Not working
    setState(() {
      _contact = contact;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Form(
        key: _formKey,
        autovalidateMode: AutovalidateMode.onUserInteraction,
        child: Scaffold(
          appBar: AppBar(
            title: Text('Add Contact'),
            actions: <Widget>[
              FlatButton(
                textColor: Colors.white,
                onPressed: () async {
                  if (_formKey.currentState.validate()) {
                    await saveContact();
                  }
                },
                child: Text(
                  'SAVE',
                  style: TextStyle(
                    fontSize: 18,
                    color: Colors.white,
                    fontWeight: FontWeight.w600,
                  ),
                ),
                shape:
                    CircleBorder(side: BorderSide(color: Colors.transparent)),
              )
            ],
          ),
          body: SingleChildScrollView(
            child: Container(
              margin: EdgeInsets.all(5),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  TextFormField(
                    onSaved: null,
                    controller: _ipCountryCode,
                    keyboardType: TextInputType.text,
                    decoration: InputDecoration(
                        labelText: 'IP Country Code',
                        fillColor: Colors.white,
                        filled: true,
                        contentPadding: EdgeInsets.all(8)),
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: <Widget>[
                      Expanded(
                        child: DateTimeFormField(
                          decoration: InputDecoration(
                              labelText: 'Time First Seen',
                              fillColor: Colors.white,
                              filled: true,
                              contentPadding: EdgeInsets.all(8)),
                          onDateSelected: (DateTime value) {
                            setState(() {
                              timeFirstSeen = value;
                            });
                          },
                        ),
                      ),
                    ],
                  ),
                  //Rest of the Code Below

Here are the screenshots for the two screens:
First Screen
Second Screen
Also offtopic, is there a better way to post form data having huge amount of fields? Currently I'm using HttpClient and I'm only able to post 3 field values firstname, lastname and email. I tried adding other fields which are present in the form into the request's body and parameters but it just wouldnt post them.I also tried giving the entire JSON model to the request's body and function's parameter but i didnt know how to actually call the request function and assign the TextFormField controllers to its values to post the data. If you can help me out with this as well it would be great.
EDIT:
API_Manager():
 Future<AddContactModel> addContact(
      String firstName, String lastName, String email) async {
    var client = http.Client();
    String addContactUrl =
        "https://example.com/ma/api/contacts/new";
    String basicAuth = 'Basic examplebasicauthkey';
    var response = await client.post(addContactUrl, headers: <String, String>{
      'authorization': basicAuth,
      "Accept": "application/json",
      "Content-Type": "application/x-www-form-urlencoded",
    }, body: {
      "firstname": firstName,
      "lastname": lastName,
      "email": email,
    });
    // print(response.statusCode);
    //developer.log(response.body);
    if (response.statusCode == 201) {
      final String responseString = response.body;
      return addContactModelFromJson(responseString);
    } else {
      return null;
    }
  }

Comment: Are you sure that `_formKey.currentState.validate()` is true?
Comment: I don't see any validator function assign in your form field. I wrote a test app, and the `_formKey.currentState.validate()` will return true if there are no validator. Probably  an error in your `API_Manager()`
Comment: Are you getting any errors? if not, maybe the call to `API_Manager().addContact` never resolves
Comment: Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/232012/discussion-between-luis-a-chaglla-and-shreyas-bhardwaj).
Comment: @LuisA.Chaglla Yes it is true because the data is being posted to the server.
Comment: @AlexanderDischberg should I attach my `addContact()`  function from `API_Manager()` ?
Comment: @LuisA.Chaglla No errors but when I try to add more parameters to the request's function and body, they don't get posted to the server. I've been having several problems with the POST function lately and also it's my first time working with API's. I'll edit the question and attach the function. It probably might have some problems. Please have a look, Thank you.
Comment: Comment the line `API_Manager().addContact` of `saveContact` and see if it works.
I don't see any reson for `Navigator.pop(context)` to not work
Comment: @LuisA.Chaglla Yess, it worked! But how do i make it work with `API_Manager().addContact`?
Comment: I just added 'Navigator.pop(context) before this `API_Manager().addContact` line and it worked! Thank you so much!
Comment: Well it "works".
Answer: Push
Navigator.push(
            context,
            MaterialPageRoute(
              builder: (context) => ProductDetailView(),
            ));

Pop
Navigator.of(context).pop();

Can you check if this works?
Comment: Nope, Still not working. Does it have something to do with `RefreshIndicator`. Cause i saw another post where `Navigator.pop` didn't work when he used a `RefreshIndicator`.


insert .jpeg files to Oracle

Question: hi
I inserted into oracle database image file on delphi7 with OpenPictureDialog1. All files are .bmp I want to insert .jpeg(.jpg) files. How can I insert this?
Thanks in advance.
Answer: Add jpeg to the uses clause.
uses
    jpeg;

Answer: convert bmp to jpg
function BMPtoJPG
   (var BMPpic, JPGpic: string):boolean;
var Bitmap: TBitmap;
    JpegImg: TJpegImage;
begin
  Result:=False;
  Bitmap := TBitmap.Create;
  try
   Bitmap.LoadFromFile(BMPpic) ;
   JpegImg := TJpegImage.Create;
   try
    JpegImg.Assign(Bitmap) ;
    JpegImg.SaveToFile(JPGpic) ;
    Result:=True;
   finally
    JpegImg.Free
   end;
  finally
   Bitmap.Free
  end;
end;

Usage: BMPtoJPG('mybitmap.bmp','myjpeg.jpg')
very useful link about jpeg unit
http://www.hamslab.com/lab/delphi/jpeg/jpeg_del.html
how to send jpeg to oracle
1) save jpeg to a file.
2) here you have how to save a file to Oracle:
http://www.delphi3000.com/articles/article_1523.asp?SK=
best regards,
Radu
Answer: FWIW, unless Jpeg is a requirement, I would use PNG for storage. Jpeg will lose quality in compression. It will be ok for photos, but for diagrams, screenshots, or anything with text, quality will suffer.

insert .jpeg files to Oracle


How do I rebuild and test Nautilus source?

Question: I'm new to OS level programming so apologies for the noobness.
Ultimately I would like to change the behaviour of clicking on "Change Desktop Background" from the desktop context menu. It would appear the Nautilus package contains the source and I have even found the line which calls the Desktop Control Panel after clicking on "Change Desktop Background".
Is it possible to re-compile the modified version of Nautilus, test it, and install it on my own system? This could be ultra noob asking a question like this but I just don't know yet!
Answer: In order to download the source and re-build it, do this:

Install all build-dependencies for nautilus: sudo apt-get build-dep nautilus
Run apt-get source nautilus in a directory you want the source.
cd into the nautilus- directory.
Run debuild -uc -us. This creates an unsigned source, unsigned changes file and one or more binary packages. You'll find these one level of a folder lower.
Install the package(s) using sudo dpkg -i /path/to/binary-package1.deb /path/to/binary-package2.deb [...].
Make changes to the source, and rebuild/install as many times as you like.

You can apply this recipe to any Debian/Ubuntu package.
To undo the installation of your modified version, simply revert to the main upstream Ubuntu version of the package by reinstalling and selecting that version in your package management. This keeps your system clean without files everywhere unmanaged by your package management.
Answer: You can pull the source by simply running apt-get source nautilus.  This will create a directory called nautilus-.  You can then cd into there, make your changes, then ./configure, sudo make, and then sudo make install
Comment: No! Don't just install it like that. It will install files everywhere and potentially break your package management! See my answer for a more elegant Debian/Ubuntu-way of doing this.


Typescript inference issue - Return type of exported function has or is using name ... but cannot be named

Question: I want to create a function which transform a Promise based function, in my example from mongodb node client, into an Observable.
The code is very simple
export function updateOneObs(filter: Object, object: Object, collection: Collection<any>) {
    return Observable.fromPromise(collection.updateOne(filter, object));
}

If I put this in VSCode, I get an error message that says
"Return type of exported function has or is using name 'UpdateWriteOpResult' from external module ".../npm-packages/observable-mongo/node_modules/@types/mongodb/index" but cannot be named."
To fix this I need to explicitly import the missing type via
import {UpdateWriteOpResult} from 'mongodb';
Considering that the error message clearly suggests that Typescript knows where to look for the missing type, is there a way to have resolved via inference without an explicit import?
In my case the import has ad additional small disadvantage: since I have set up the Typescript compiler with "noUnusedLocals": true, once I import the missing type I have to use it somewhere if I want to avoid another error.
Answer: This error only occurs if you have "declaration": true,. If you don't need declarations you can disable this option. If you do need declarations then you must create local names for the type. To generate declaration typescript will need to use a local name for the return type. The compiler knows where the original type lives (as it points it out in the error), but to generate the declaration it would have to give the type an alias within the module which it will not do by design (the compiler is not in the business giving names to types, especially when there may be conflicts with other names in your file)
Comment: I actually use `"declaration": true"` as a compiler option, since I need to generate declarations or better I find convenient TS compiler to generate the declarations. Considering that to fix the problem the only thing I have to do is `import {UpdateWriteOpResult} from 'mongodb'`, then I am wondering whether the compiler could incorporate this as a default behavior, i.e. add the import statement automatically. Thanks anyway for your answer.


Generate Public "ID Text" (like Stackoverflow)

Question: I'm trying to create a simple method to turn a name (first name, last name, middle initial) into a public URL-friendly ID (like Stackoverflow does with question titles). Now people could enter all kinds of crazy characters, umlauts etc., is there something in .NET I can use to normalize it to URL-acceptable/english characters or do I need to write my own method to get this done?
Thank you!
Edit: An example (e.g. via RegEx or other way) would be super helpful!!! :)
Answer: Sounds like what you're after is a Slug Generator!
Comment: Isn't there a danger when removing characters that you could get the same return value from two different inputs and hence end up with a non-unique identifier?
Comment: My understanding is that you use a slug with a unique ID number, not in place of. For example, there are two URLs to get to this question - http://stackoverflow.com/questions/1188283/generate-public-id-text-like-stackoverflow and http://stackoverflow.com/questions/1188283/
Comment: @Dan - You're right, but I'd assume that the input to the "GenerateSlug" function would already have ensured some level of uniqueness that would come from characters that are not going to be removed (ie. numbers etc).
Answer: Simple method using UrlEncode
You obviously have to do something to deal with the collisions (prevent them on user creation being sensible but that means you are tied to this structure)
<code>s => Regex.Replace(HttpUtility.UrlEncode(s), "%..", "")
</code>
This is relying on the output of UrlEncode always using two characters for the encoded form and that you are happy to have space convert to '+'
Answer: A regular expression to validate the string with the characters and lengths you wish to allow.
Answer: Think you'll have to write your own method...
Safelist of characters...
A to Z
For Each c As char In SafeList
  If safe ... etc.
Next


How to pass more than one parameter on frame navigation in Metro Style Apps?

Question: I am building a Metro Style App for Win8 which requires to pass two textblock values on frame navigation. For one parameter, it works but for two parameters its not working. Please help!
I have tried like the following:
       this.Frame.Navigate(typeof(SecondPage),textblock1.Text + textblock2.Text);
I doesn't show any error but its not working.
Answer: Create a new class with 2 properties and set the properties to the textblock values. Then you pass this object when you navigate.
Create the payload class:
public class Payload
{
 public string text1 { get;set;}
 public string text2 { get;set;}
}

Then populate the payload class:
Payload payload = new Payload();
payload.text1 = textblock1.Text;
payload.text2 = textblock2.Text;

Then when you call Navigate pass your instance of payload like this:
this.Frame.Navigate(typeof(SecondPage),payload);

Comment: how to get values in secondpage?
Comment: @rams http://social.msdn.microsoft.com/Forums/da/winappswithcsharp/thread/8cb42356-82bc-4d77-9bbc-ae186990cfd5
Comment: Override the OnNavigate event on SecondPage to load the values from e.Parameter and cast it as the Payload, make sure to check for null. Hope that helps anyone out there.
Answer: I have taken a dictionary object like this.
Dictionary<string, string> newDictionary = new Dictionary<string, string>();
newDictionary.Add("time", itemObj.repTime);
newDictionary.Add("message", itemObj.repMessage);
Frame.Navigate(typeof(ViewDetails),newDictionary);

On ViewDetails.xaml.cs page I had retrieved the data like this,
protected override void OnNavigatedTo(NavigationEventArgs e)
    {
         Dictionary<string, string> myDictionary = new Dictionary<string, string>();
         myDictionary = e.Parameter as Dictionary<string, string>;
         timeTB.Text = myDictionary["time"].ToString();
         messageTB.Text = myDictionary["message"].ToString();
    }

Comment: Only works if both params as of same type, like in your example. But doesn't work for different value types (int, float, etc....)
Comment: Yes, you are right. But the OP wanted to pass two text parameters in the question. I answered accordingly :)
Answer: http://social.msdn.microsoft.com/Forums/windowsapps/en-US/8cb42356-82bc-4d77-9bbc-ae186990cfd5/passing-parameters-during-navigation-in-windows-8?forum=winappswithcsharp
same here ;)
i think this is what you want
Comment: Have you checked the link given by 4imble on Allan Muller's answer ? Moreover, if you think this is the answer to the original question, please copy/paste the relevant explanation (and code) in case the link disappear someday, thanks.


Show that $\{x^{2k}\}_{k\ge 0}$ is complete in $C([0,1])$.

Question: This is Exercise 2.4 in A Basis Theory Primer, Christopher Heil. I am just reading this book and not a homework.

The Weierstrauss Approximation Theorem implies that $\{x^{k}\}_{k\ge 0}$ is complete in $C[0,1]$. Show that $\{x^{2k}\}_{k\ge 0}$ is also complete in $C[0,1]$.

In the book it is defined $\{a_k\}\subset X$ is complete in a normed linear space $X$ if the set of all finite linear combination of $\{a_k\}$ is dense in $X$.
Attempt: It suffices to show that given arbitrary $\epsilon>0$ and $x^k$, with some $x^{2\ell}$ we have
$$
\sup_{x\in[0,1]}|x^k-x^{2\ell}|<\epsilon.
$$
If $k$ is even, we can let $\ell:=\frac{k}2$. But if $k$ is odd, I am stuck and not sure if this approach is a good idea.
Answer: Hint: Let $f\in C([0,1])$. As $g(u)=f(\sqrt{u})$ is also in $C([0,1])$, for every $\varepsilon>0$, there exist a polynomial $P$
such that for all $u\in [0,1]$, we have $|g(u)-P(u)|<\varepsilon$.
Comment: How do we know that $g$ needs only even powers in $P$?
Comment: We want to approximate $f$, not $g$. In the inequality above, for an $x\in [0,1]$, put $u=x^2$.
Comment: Oh! Thanks. +1....
Comment: @zoli You are welcome


What size breaker and wire do I need for central air conditioning?

Question: I am getting ready to hang drywall in my basement but before I do that, I need to run wire from the main panel upstairs to the future location of the central AC furnace through the basement ceiling joists.  I do not know yet who will be installing my AC but I will probably outsource it.  At this point I just need to know what the electrical requirements for AC are so that I can bring the cable and hang the drywall.  The house has three bedrooms and two living rooms, 1800 sq ft, two floors.
What amperage/AWG am I looking at?  The wire distance from the panel to the furnace is only about 20' +/- and then I plan to sit the condenser on the roof (it is a low pitched mod bit roof so I can do this, many of my neighbors with similar homes do) directly above the furnace, two floors above (so another 16-20' total).  It also may be worth mentioning that I plan to use this for just AC and not heat -- I have already a radiator system in place and I love radiant heat.
Comment: What would the length of this wire be? It's important to know for the calculation.
Comment: Company installed spilt unit on inside wall and the condensor outside atop a wall the man that installed unit requires a 30 amp line 208 1ph lime
Comment: You need no extra wire to the furnace. The power will be needed outside at the compressor.
Comment: Where is this house located?
Answer: You should either sort out what the AC is going to be, so you can get specific power supply and cabling needs sorted out now, or line up your joist holes nicely and follow the excellent suggestion from @longneck to run conduit, leaving the wiring for later. Use flexible conduit, if needed to get it in place. Run at least two - there may well be low voltage control circuits that need to be run separated from the power supply. Alternatively, leave a section of the drywall open for now, allowing for both cabling and refrigeration tubing to be run before you close it up.
Answer: It's going to completely depend on the unit that's being installed, but commonly it'll be 30-60 amp with 10-4 AWG wire. You're probably looking at a 3.5 ton unit, so you'll be in the 30-40A (10-8 AWG) range. It might be worth it to get a few quotes from local HVAC companies, and see what they want to install. The companies may have a preferred breaker and wire size, so they may want to redo any work you do anyway.
Don't forget you'll also need high and low pressure tubing, and control wires between the indoor and the outdoor units.
Comment: An alternative to installing wiring now would be to install conduit instead.
Comment: @amphibient I'm not familiar with this type of installation, all my experience is with installations where the A/C is an add-on to an existing furnace.  In which case the furnace and condensing unit are on separate circuits.  I'm guessing the indoor and outdoor units will still be separate, but I'm not positive.  The air handler will likely only require a 120V 15-20A circuit, whereas the condensing unit will require 240V  20-50A circuit.  If you're running cable for both, you'll probably want to run one 12/2 to the indoor unit and one 10/2 cable to the outdoor unit.
Comment: no, @longneck, it needs to go through ceiling joist holes
Comment: do the condenser and air handler run on the same or separate circuits?
Comment: @amphibient Usually the furnace is on a 120V circuit, and the condensing unit is on a separate 240V circuit.
Comment: but do you run just a single cable (10-4?) hooked into two circuits from the panel to the air handler inside and then another cable from the air handler to the condenser?
Comment: @amphibient -- you can run conduit through joists, no problem -- ENT (smurf) into the back of the disconnect outside works just fine
Answer: Most likely you need 8-3 with ground thnn or thwn with 50 amp disconnect mounted within several feet from unit with a 50 amp circuit breaker in the main distribution panel. This is good for 50 amp rated unit. Use 10 awg for 30 amp unit or 6 awg for 60 amp unit. These rating are adequate for runs of up to appx 60 ft
Answer: First the wire size depends on the size and requirements of the unit itself. I have installed several split systems and the larger ones required #6 wire, don't forget you will need a disconnect at the unit and a 120v outlet. I use a combination 240v disconnect and. 120v GFCI outlet that is weather and tamper resistant similar to Eaton dpf222rgf20wtst this is good for up to 60 amps but most split systems don't require a disconnect this large. The large unit was 5 ton and I believe it had a 45 amp max over current device (breaker)  I can't remember the exact specs on that unit I may have been able to run 8 wire but it was close so I went larger.
Answer: The ac should be installed prior to any finish work from what is being said here. A 240 line is needed for the condenser directly to breaker panel with a disconnect at outside unit. Breaker size depends on what is installed and length of wire.
Answer: I see you did not get a good firm answer. I see the date so you are done with your project by now I hope. All I have to say is you have to many variables. You can't give a precise answer with out the exact spects, so you have to pick the unit you are going to use you have to know this to calculate the wire gage after you calculate the unit amp's with the full wire run. I my self if you are getting close to the max amp's for your run of wire i go up 1 size in wire because if the wire is to small it may feel a little worm the one thing no one told you stay in the mid,of specs if you draw to many amp its hard on the compressorand fan and will shorten the unit life and most of all if you are running to close to it will increase your elect, cost. Because if the wires are to small you will use more elect'worm wire ohms resistance will increase and all the money you spent to have a hi efficient unit you threw out the window. I figure all my work after I have all my parts on hand .Dave I hope all worked out for you
Comment: Can you please [edit] to explain what "Because if the wires are to small you will use more elect'worm wire ohms resistance will increase" means?


AngularJS i18n: ngLocale FIRSTDAYOFWEEK and WEEKENDRANGE

Question: Somewhere in the v1.4.0-betas, Angular i18n files acquired some new attributes like DATETIME_FORMATS.FIRSTDAYOFWEEK.  Latest version as of now.
Does anyone understand how FIRSTDAYOFWEEK and WEEKENDRANGE work?  From my observation, here's what I think was intended

DATETIME_FORMATS.DAY always starts on Sunday (consistent with 0 = Sunday in javascript), no matter what day of the week is considered the first day of the week in that locale
DATETIME_FORMATS.FIRSTDAYOFWEEK should indicate the first day of the week in the locale, so that if it's 0, the week starts on Sunday, 1 = Monday and so on.
DATETIME_FORMATS.WEEKENDRANGE should be the days of the week that are considered weekend days in the locale

My problems are that

DATETIME_FORMATS.FIRSTDAYOFWEEK for en-au is 6.  That would be Saturday, and the first day of the week isn't Saturday here in Australia (they argue about Sunday or Monday being the start)
DATETIME_FORMATS.WEEKENDRANGE for en-au is [5, 6] and Friday isn't a weekend day here either (despite the fact that workers slack off and drink beer in the afternoons).

So are there just a bunch of errors in the files?  Or do I not understand the scheme being implemented here?
Answer: For ngLocale files, "Monday is day 0 as specified by ISO-8601"
...as opposed to Javascript, where Date.prototype.getDay() returns 0 for Sunday. Watch out!
I asked for this to be added to the documentation.
Answer: Actually the ISO 8601 states that Monday is 1 not 0 as it is declared in angular's i18n.
3.2.2 - The week calendar - Table 2 - Calendar days
| **Ordinal day number in the week** | **Calendar day name** |
| --- | --------- |
|   1 | Monday    |
|   2 | Tuesday   |
|   3 | Wednesday |
|   4 | Thursday  |
|   5 | Friday    |
|   6 | Saturday  |
|   7 | Sunday    |


How to use array of data from different Views - Swift

Question: I have application that has 2 Views. One just keeps an empty array and shows it, and the other one view should add data in this array. In the end I want added info to show on the view that keeps this array.
I've already tried to create an variable of another view inside of the first one, and try to change array, but as i experienced, it doesn't work, because it just created a new instance of view, that has nothing in common with the one that I want to update.
`
//View that keeps array "savedArticles"

struct SavedNewsView: View {
    @State var savedArticles: [Article] = []

    func removeArticle(at offsets:IndexSet) {
        savedArticles.remove(atOffsets: offsets)
    }

    var body: some View {
        NavigationView {
            List {
                ForEach(savedArticles, id: \.self) {article in
                    NewsComponentView(title: article.title, description: article.description, urlToImage: article.urlToImage, url: article.url)
                }
                .onDelete(perform: removeArticle)
            }
            .listStyle(.plain)
        }
        .navigationTitle("Saved News")
    }
}

`
And this is the view that updates this array:
`
struct NewsView: View {
    @StateObject var viewModel = ViewModel()
    @State var savedArray = SavedNewsView()

    var body: some View {
        List {
            ForEach(viewModel.news, id: \.self) {article in
                if article.urlToImage != nil {
                    NewsComponentView(title: article.title, description: article.description, urlToImage: article.urlToImage, url: article.url)
                        .swipeActions() {
                            Button {
                                savedArray.savedArticles.append(Article(title: article.title, description: article.description, url: article.url, urlToImage: article.urlToImage))
                            } label: {
                                Label("Save", systemImage: "bookmark")
                            }
                            .tint(.yellow)
                        }
                }
            }
        }
        .listStyle(.plain)
        .onAppear {
            viewModel.fetch()
        }
    }

`
Comment: You don't use an instance of a view to pass data but instead a class conforming to  ObservableObject that you use as a StateObject/ObservedObject or EnvironmentObject depending on your exact use case.
Answer: You can pass write access to an @State to a subview using @Binding, e.g.
struct NewsView: View {
    @Binding var savedArticles: [Article]

NewsView(savedArticles: $savedArticles)


Save 2D array as xls file

Question: I have 2d array and I need save this array data as xls file
I am trying make this using PHPExcel
include 'PHPExcel.php';

  $data = array(
    array("firstname" => "Mary", "lastname" => "Johnson", "age" => 25),
    array("firstname" => "Amanda", "lastname" => "Miller", "age" => 18),
  );

$objPHPExcel = new PHPExcel();

$objPHPExcel->getActiveSheet()->fromArray($data);

$objPHPExcel->save("test.xls");

But this gives error:  Call to undefined method PHPExcel::save()
What is right way for saving array as xls using PHPExcel ?
Answer: It seems as if there is no such function.
if u check the Hallo World example at http://phpexcel.codeplex.com/ u may see that they are not using $objPHPExcel->save("test.xls");
but
include 'PHPExcel.php';
include 'PHPExcel/Writer/Excel2007.php';
$objPHPExcel = new PHPExcel();

$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
$objWriter->save(str_replace('.php', '.xlsx', __FILE__));

Answer: similar to Sailinthorns answer
  include 'PHPExcel.php';

  $data = array(
    array("firstname" => "Mary", "lastname" => "Johnson", "age" => 25),
    array("firstname" => "Amanda", "lastname" => "Miller", "age" => 18),
  );

  $objPHPExcel = new PHPExcel();

  $objPHPExcel->getActiveSheet()->fromArray($data);

  // Redirect output to a client's web browser (Excel5)
  header('Content-Type: application/vnd.ms-excel');
  header('Content-Disposition: attachment;filename="test.xls"');
  header('Cache-Control: max-age=0');
  // If you're serving to IE 9, then the following may be needed
  header('Cache-Control: max-age=1');

  // If you're serving to IE over SSL, then the following may be needed
  header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
  header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
  header ('Pragma: public'); // HTTP/1.0

  $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  $objWriter->save("test.xls");

Comment: it creates the xls file in the same directory as the php file running it, check the web for the 'test.xls'
Comment: try using at the end header('Location: test.xls'); not the cleanest way to do it, but just to get you thinking
Comment: just updated my answer based on the documentation on how to properly set the headers for download, note this downloads the file and saves a copy on the website

Save 2D array as xls file


Structured text and unstructured text

Question: With respect to the data mining, what are the differences between structured text and unstructured text? What are the major considerations when choosing/developing data mining approaches for analyzing these different texts?
Comment: This Q is an exact duplicate of this recent Q: http://stackoverflow.com/questions/5353124/how-are-structured-and-unstructured-data-distinguished/5354909#5354909
Answer: I'll preface this by saying that the specific domain you are dealing with matters a great deal when answering these types of questions. Adding some context to your question will allow much more helpful responses.
The central difference between structured and unstructured text, in the general case, is the simple fact that structured text has an easily digested form and unstructured text does not. For some text mining, this may be as simple as a bag-of-words model (how many times does each word occur?), all the way up to extremely complicated NLP approaches that attempt to pull out deeper language structures like parts of speech or entity detection/resolution. An every-day example of structured data could be the metadata of a post on Twitter (username/time stamp/retweet info/etc.) where the related unstructured data would be the text of the post itself.
Without knowing exactly what you are interested in, a large consideration is the simple fact that structured text is often in a convenient form for simple machine learning models, while unstructured text rarely is, since it cannot be easily treated as a bunch of binary/real-valued features and thrown into your favorite statistical model.
Hope this helps on a high level -- feel free to update the original post with details if I'm being too broad with my response =)

Structured text and unstructured text


How to find maximum number of groups needed to sort an Array?

Question: Suppose I had an array:
[1, 8, 5, 6, 10, 9, 11, 12];

I want to sort it by ascending order, but find out the maximum groups I would need to sort. In this example, the answer would be:
[1], [8,5,6], [10,9], [11], [12]: so 5

[3, 2, 1] would come out to be 1 because the entire array would need sorting.
I am at a complete loss of how to do this a nudge in the right direction would be greatly appreciated.
Comment: you could just iterate through the array and count the number of times n[i+1] > n[i]
Comment: Is it the maximum *consecutive* groups that need to be sorted ?
Comment: Looks like a good case for Tarjan's Strongly Connected Components algorithm.
Comment: @GrumpyWelshGit that doesn't work because a larger number could be in the middle of a group
Comment: @Dvorog it is just all groups that can be made. So even if certain numbers are sorted, such as [1] and [11], they still count as a group of 1. A group like [8,5,6] is made because within that group, you can sort all of them to their proper locations. If I added a 2 after the 9, then that entire section would be 1 group instead.
Comment: So if you added 2, the result would be [1,8,5,6,10,9,2],[11],[12] = 3 ?
Comment: @Dvorog it would be [1], [8,5,6,10,9,2], [11], [12] = 4. The 1 is already in its correct place, so it is its own group, same as 11 and 12.
Answer: My solution uses the insertion sort algorithm, which keeps sorted elements on their places and moves unsorted elements towards the beginning of the array until they get in their place. We can use this behavior to detect groups that need to be sorted.
At each iteration, we check whether the current element is greater than or equal to the previous one. If so, we may have encountered a new group. We push the current index to a stack.
If the current element is less than previous, then we're still in the same group. We start to swap this element with previous elements until it gets in place. And at each step we check if we have crossed the boundary of the previous group. If the boundary is crossed, it means that these two groups are actually one group, so we pop the last value from the stack.
Finally, the number of groups equals to the stack size.
Here is the implementation:
public static int countGroups(int[] a) {
    if (a.length < 2) return a.length;
    Stack<Integer> stack = new Stack<>();
    stack.push(0);
    for (int i = 1; i = a[i - 1]) stack.push(i);
        for (int j = i; j > 0 && a[j] < a[j - 1]; j--) {
            swap(a, j, j - 1);
            if (j <= stack.peek()) stack.pop();
        }
    }
    return stack.size();
}

private static void swap(int[] a, int i, int j) {
    int t = a[i];
    a[i] = a[j];
    a[j] = t;
}

And here is a JavaScript snippet with some examples:

console.log(countGroups([1, 8, 5, 6, 10, 9, 11, 12]));    //5 - [1], [8, 5, 6], [10, 9], [11], [12]
console.log(countGroups([1, 8, 5, 6, 10, 9, 2, 11, 12])); //4 - [1], [8, 5, 6, 10, 9, 2], [11], [12]
console.log(countGroups([3, 8, 5, 6, 10, 9, 2, 11, 1]));  //1 - [3, 8, 5, 6, 10, 9, 2, 11, 1]
console.log(countGroups([1, 2, 8, 6, 10, 9, 11]));        //5 - [1], [2], [8, 6], [10, 9], [11]
console.log(countGroups([1, 2, 1, 1, 10, 9, 10]));        //4 - [1], [2, 1, 1], [10, 9], [10]

function countGroups(a) {
    if (a.length < 2) return a.length;
    let stack = [0];
    for (let i = 1; i = a[i - 1]) stack.push(i);
        for (let j = i; j > 0 && a[j] < a[j - 1]; j--) {
            swap(a, j, j - 1);
            if (j <= stack[stack.length - 1]) stack.pop();
        }
    }
    return stack.length;
}

function swap(a, i, j) {
   let t = a[i];
   a[i] = a[j];
   a[j] = t;
}

UPDATE: If you don't need to actually sort the array, it seems that the problem can be solved in linear time:
public static int countGroupsLinear(int[] a) {
    Stack<Integer> stack = new Stack<>();
    stack.push(a[0]);
    for (int i = 1; i = stack.peek()) stack.push(a[i]);
        else {
            int last = stack.pop();
            while (stack.size() > 0 && a[i] < stack.peek()) stack.pop();
            stack.push(last);
        }
    }
    return stack.size();
}

Comment: @thebenman your statement is incorrect; the stack solution is linear time since each number is pushed to the stack once and popped at most once.
Comment: You're right. I din't notice it in first go. it looked strangely like insertion sort. That's a beautiful solution too
Comment: The stack solution isn't linear time, it's quadratic in worst case if the array is reverse sorted.
Answer: Here is the code that works out well with an array of n distinct integers. This is in C.
#include <stdio.h>
//code for the case where each element of the array is distinct
//and greater than 0
//finding index of the maximum value in array
int maximum(int *a,int n)
{
    int i,max;
    max=0;
    for(i=0;i<n;i++)
    {
        if(a[i]>a[max])
        {
            max=i;
        }
    }
    return max;
}

//finding index of the minimum value in array(excluding zeros)
int minimum(int *a,int n)
{
    int i,min,index;
    min=100000;
    for(i=0;i<n;i++)
    {
        if(a[i]!=0 && a[i]<min)
        {
            min=a[i];
            index=i;
        }
    }
    return index;
}

//checks for the presence of a non-zero element in array
int check(int *a,int n)
{
    for(int i=0;i<n;i++)
    {
        if(a[i]!=0)
        return 1;
    }
    return 0;
}

//main function
int main()
{
    int n,j,k,max,min,slices;
    slices=0;
    scanf("%d",&n);
    int a[n];
    for(int j=0;j<n;j++)
    {
        scanf("%d",&a[j]);
    }
    //until all the elements of the array become 0
    //continue iterating to find slices
    while(check(a,n))
    {
        max=maximum(a,n);
        min=minimum(a,n);
        //if index of minimum value is greater than
        //index of maximum value
        if(max<min)
        {
            slices=slices+1;
            for(j=0;j<n;j++)
            a[j]=0;
        }
        else
        {
            for(j=0;j<=min;j++)
            {
                a[j]=0;
            }
            slices=slices+1;
            if(check(a,n))
            {
                for(j=max;j<n;j++)
                {
                    a[j]=0;
                }
                slices=slices+1;
            }
        }
    }
    printf("slices %d",slices);
    return 0;
}

Answer: This can be done by piggybacking on MergeSort Routine.
The real action takes places in the merge stage of the merge sort routine.
The idea here is for any index i of the merged array

If the element to be added has the same index as the index being inserted to then we know that it forms a group and we increment the group count by 1.

Suppose i/p = [1, 7, 5, 4, 2, 12]
We create a new array which stores the indices of the elements [0, 1, 2, 3, 4, 5, 6]
for the given input the first merge function will be called for
left  SubArray => 0
right SubArray => 1
For the 0th element of the new merged array we look at the which element we can use.
so for 0th of the new element comes from index 0, i.e. 1, which are the same so we increment the number of groups by 1. Same for index 1

Suppose for index i in the merged array the element from index j, where j > i has to be inserted, we for now know that the subarray from i to j could be a group if all the elements in the range [i, j] in the merged array falls with this range. In case we encounter another index to be added k which is greater that j we will update the index we are looking for to include k i.e. [i, k]. Because, if we consider only range [i, j] we will have a element at k where input[k] > input[j] thereby not forming a valid group.

Example input = [3, 2, 0, 1] which will become [0, 1, 2, 3]
for the last merge
the left subarray will be[1, 0]
the right subarray will be[2, 3 ]`
for index 0 of the merged array we look at minimum of input[1] or input[2] which is input[2] and the index is 2, so we now know that the minimum this array comes from index 2. We continue to look until the index 3 in the merged array and updating the highest index the which contributes a group and stop when both the indices become the same
at index 1, we have choose between index 1, 3 and we find out index [3] is the next least minimum and we update the highest index to 3 and continue until index i of the merged index becomes equal to the index of the element being inserted.
It runs in O(N log N) and we get result of the indices array is the sorted indices of the input array
Answer: This solution is O(N). But it works only for array with distinct numbers.
public static List<List<Integer>> countGroups(int[] arr) {

    List<List<Integer>> result = new ArrayList<List<Integer>>();

    if (arr.length < 1)
        return result;

    // create mins from right to left
    int[] mins = new int[arr.length];
    int tempMin = arr[arr.length - 1];
    for (int i = arr.length - 1; i >= 0; i--) {
        tempMin = Math.min(tempMin, arr[i]);
        mins[i] = tempMin;
    }

    // create max from left to right
    int[] maxs = new int[arr.length];
    int tempMax = arr[0];
    for (int i = 0; i < arr.length; i++) {
        tempMax = Math.max(tempMax, arr[i]);
        maxs[i] = tempMax;
    }

    // now that you have the start of intervals (mins) and end of intervals, you can
    // simply check if you are
    // still in the interval

    List<Integer> list = new ArrayList<Integer>();
    for (int i = 0; i < arr.length - 1; i++) {
        list.add(arr[i]);
        if (mins[i] != mins[i + 1] && maxs[i] != maxs[i + 1]) {
            result.add(new ArrayList<Integer>(list));
            list.clear();
        }
    }

    list.add(arr[arr.length - 1]);
    result.add(new ArrayList<Integer>(list));

    return result;
}

`
Answer: Here is the solution I was able to come up with, the idea is to keep an active index of the array whose value is in between current maximum and minimum values, the tricky part is keeping the current maximum that is out of context as currentCheckableMaxIndex which becomes currentMaxIndex whenever it falls in context
public static int countSubArray(int[] A) {

    int len = A.length;
    int currentActiveIndex = 0;
    int count = 0;
    for(int i = 0; i < len;){
        int currentCheckableMaxIndex = i;
        int currentMinIndex = i, currentMaxIndex = i;
        for(int j = i; j < len; j++){
            // if there is a new min value, set its index,
            // also check if there is a checkable max that we can change to the new max
            if(A[currentMinIndex] > A[j]) {
                currentMinIndex = j;

                if(A[currentMaxIndex]  currentCheckableMaxIndex
            if(A[currentCheckableMaxIndex] = A[j] && A[j] >= A[currentMinIndex]) currentActiveIndex = j;
        }
        // i should continue from the current valid index + 1
        i = currentActiveIndex + 1;

        count++;

        // loop will not get here again if i == len - 1, so we count the last group that would have be omitted
        if(i == len - 1) {
            count++;
            break;
        }
    }

    return count;

}

Answer: Same solution as proposed above, but implemented in Python 3:
def solution(A) -> int:
    if len(A) < 2:
        return len(A)

    stack = [A[0]]
    for num in A[1:]:
        if num >= stack[-1]:
            stack.append(num)
        else:
            smallest = stack.pop()
            while len(stack) > 0 and num < stack[-1]:
                stack.pop()
            stack.append(smallest)

    return len(stack)


Where can I find Wujeeta in Riften?

Question: I have been trying to become Thane in Riften, and, in order to do this, I have to find Wujeeta to start the Skooma Trade Quest. I looked online and found that she might be in Helga's Bunker or at the fishery. However, I haven't been able to find her.
Is there another place where she might be, or is there a glitch in the game?
Answer: I've never played Skyrim but I could find something that may be usefull for you:

Well, I read today on elderscrolls wikia that I have to complete the Civil War questline first. I was wondering if this was true as I've only played that line up through the conquering of Whiterun (I'm on the Stormcloak side).

and he replies to himself:

Well, I decided after not finding her to go way back to one of my earliest saves in the game, right after escaping Helgen), went to Whiterun to get a carriage to Riften right away and she was there in the docks around the fishery. Sadly, that means all the hours of grinding I did need to be redone now, but I can get all the houses. My advice to anyone first starting the game, go to Riften as early as you can (before any other quests, inclunding the main story questline) and start the Skooma quest you get from talking to Wujeeta 2 times before doing anything else in order to lock in the chance of getting Honeyside as early as possible.

More than this, all I could find was:

Do you have a quest (miscellaneous or otherwise) that directs you to Wujeeta? And if so, is there a quest marker? If not, then it's possible that they are dead, or otherwise glitched.

and, of course:

Maybe she got clipped into a surface and was sent to the void, the game has a nasty sense of humor when that happens, so she might be lost forever.

Hope it was helpfull.
Source
Comment: I edited the question providing all I could find.
Comment: Thank you. I guess it might be that she is either dead or has glitched. I'll look elsewhere for a suitable house. Thank you.

Where can I find Wujeeta in Riften?


Counterexample separation theorem

Question: I am trying to understand, why the Separation Theorem from Hahn-Banach needs one of the sets to be open.
The theorem states:
$$\text{Re}\langle x',x_1 \rangle < \alpha \leq\text{Re}\langle x', x_{2} \rangle$$
for $x_1 \in C_1, x_2 \in C_2$ and  $C_1,C_2$ convex, disjoint sets with $C_1$ open.
Now I am looking at the example in $c_{00}$ referenced here:
https://mathoverflow.net/questions/37551/a-counter-example-to-hahn-banach-separation-theorem-of-convex-sets
My trouble lies in understanding why $\mathcal{l}(x) = 0$ follows from $\pm \mathcal{l}(x) + \delta \mathcal{l}(y) \geq 0$.
Answer: Since the inequality
$$
\pm l(x)\leq \delta\,l(y)
$$
holdsl for all $\delta>0$, you get that $\pm l(x)\leq0$. This forces $l(x)=0$.
The above is argued in the real case. In the complex case you would get $\operatorname{Re} l(x)=0$. As this can be done for the element $ix$, we also get $$0=\operatorname{Re}l(ix)=-\operatorname{Im} l(x).$$
Comment: Yes, you can formalize it that way if you want. The way I think about it, $l(x)$ is less than all positive real numbers, so $l(x)\leq0$. Similarly, $-l(x)\leq0$, so $l(x)\geq0$. And this gives you $l(x)=0$.
Comment: Okay, thank you for your answer! Further would I have $\inf_{\delta >0} l(x) \leq 0$ and $\inf_{\delta >0} l(x) \geq 0$ or how would you formalize another step before $l(x)=0$?
Comment: I am having another question, if we have the sequence $a_n = (1/n,0,0,,...,0) n$ in $ \mathbb{N} $. Then the sequence should be in $C$ but $\lim_{n \to \infty} a_n = (0,0,...,0)$ isn't. Isn't that a contradiction to $C$ being closed?
Comment: Assuming $C$ is the $K$ in fedja's answer, of course it is not closed. If it were closed you could apply Hahn-Banach between the closed convex set $C$ and the compact convex set $\{0\}$.
Comment: Okay... . in my textbook its described as an example of the first separation theorem, which assumes two open sets.
Comment: Well, none of the sets is open, so it is also a counterexample the negating some of the hypotheses of that theorem.

Counterexample separation theorem


Azure Kinect Recording Color Format

Question: I'm attempting to read an Azure Kinect recording and save images from the frames. But, it is not possible to set the color_format, which causes problems when using imwrite.
I have read the recording documentation here: https://learn.microsoft.com/en-us/azure/Kinect-dk/azure-kinect-recorder.
By default, the format seems to be K4A_IMAGE_FORMAT_COLOR_MJPG. But I am unsure what parameter to pass in when creating the material. For BGRA32 it is CV_8UC4 and for depth images it is CV_16U.
I assume there are two ways to solve this problem, either by setting the color_format or figuring out what parameter is correct for the default format made by the recording.
Answer: You can access the rgb with OpenCV as if it were a normal webcam:
VideoCapture cap(0); // open the default camera
cap.set(CV_CAP_PROP_FRAME_WIDTH, 3840);
cap.set(CV_CAP_PROP_FRAME_HEIGHT, 2160);
if (!cap.isOpened())  // check if we succeeded
    return -1;
Mat frame, img;
for (;;)
{

    cap >> frame; // get a new frame from camera
    cout << frame.cols << " x " << frame.rows << endl;
    resize(frame, img, Size(), 0.25, 0.25);
    imshow("frame", img);
    if (waitKey(30) >= 0) break;
}

No k4a function is called, no need to set the color format.
If you want to use their SDK with jpeg format, they provide a function in one of their sample codes:
long WriteToFile(const char *fileName, void *buffer, size_t bufferSize)
{
    cout << bufferSize << endl;
    assert(buffer != NULL);

    std::ofstream hFile;
    hFile.open(fileName, std::ios::out | std::ios::trunc | std::ios::binary);
    if (hFile.is_open())
    {
        hFile.write((char *)buffer, static_cast<std::streamsize>(bufferSize));
        hFile.close();
    }
    std::cout << "[Streaming Service] Color frame is stored in " << fileName << std::endl;

    return 0;
}

You just call:
image = k4a_capture_get_color_image(capture);
WriteToFile("color.jpg", k4a_image_get_buffer(image), k4a_image_get_size(image));

Finally, you can set the format to RGBA32:
config.color_format = K4A_IMAGE_FORMAT_COLOR_BGRA32;

and convert it into a OpenCV Mat:
color_image = k4a_capture_get_color_image(capture);
    if (color_image)
    {
        uint8_t* buffer = k4a_image_get_buffer(color_image);        // get raw buffer
        cv::Mat colorMat(Hrgb, Wrgb, CV_8UC4, (void*)buffer, cv::Mat::AUTO_STEP);
        //do something with colorMat
        k4a_image_release(color_image);
    }

More details on the last option here: How to convert k4a_image_t to opencv matrix? (Azure Kinect Sensor SDK)
The data is slightly better with the last solution, but the buffer is significantly larger (33M vs ~1.5M) for 3840x2160.
Comment: https://github.com/microsoft/Azure-Kinect-Sensor-SDK/blob/develop/tools/k4afastcapture_streaming/k4afastcapture.cpp
Comment: Fantastic answer, thanks! Could you provide a link to the sample code that had the WriteToFile() method.

Azure Kinect Recording Color Format


What's a polite way to ask the user to verify that they're not abusing my system?

Question: My app is a game for kids in classrooms, and we offer a demo mode for teachers, so they can try before they buy. We've found that lots of kids are signing up for a demo so they can play the game for free, and then they abandon it when the demo is up. We have people who go through these demo registrations, and it's a big waste of their time, and messes up our metrics on the value of having the demo mode in the first place.
We would like to prevent this by asking the teacher to enter an email address or phone number, so that, before they can get the demo, we message them a short code, and then require them to enter that code. The idea is that a legitimate adult user would have no problem going through this step, but a kid who's just playing around will think twice before identifying himself.
So, what is a polite way to ask for this information and explain why we want it, without sounding off-putting, like "we don't trust you"?
(Alternatively, is there a better way to solve this problem?)
Comment: Not an answer to your actual question, but I'd like to point out that your users have a goal (get the demo) and you're putting hurdles in the path of that goal (enter an address, wait for the email, open the email, go back to the app and enter the code). Each hurdle is going to turn away some number of users. So it will take a certain level of motivation to actually get the demo. I'm not saying you shouldn't do it. I'd like to hear back from you about what happens when you do.
Comment: @KenMohnkern: Very valid points. We tried it with no hurdles for that exact reason, and found a lot of abuse. So this is a second attempt, to cut back on that abuse, hopefully without also deterring legitimate leads.
Answer: It is very rational to require verifying an identity via an email address or a phone number for a demo run. Since it is a quite common practice, no reasoning is expected, neither needed (besides required privacy policy and terms of service checkboxes).
Otherwise, it may lead to a situation when you providing your service (or its most exciting part) for free and only a few would ever sign-up and pay for it.
Answer: Lessening the pain
You can ask verifying information, and don't need to offer justification for why — you don't need to say, for example "we ask this to make sure you're a serious prospect." You can make it less painful by:

Asking for info with an upbeat tone, e.g. instead of "Please enter your phone number for verification purposes", you can have something like "Let's get started with your free demo! First, what's your phone number? We'll use this to send you an access code."
Make the purpose plain and stick to it, e.g. if you're asking for email or phone number for verification only, make it clear that you'll only use it for verification and don't intend to spam the user later. It doesn't always need to be spelled in legalese, e.g. "We won't spam, promise!". Informing users of the purpose of info collection is good UX practice in general but note that some regulations such as GDPR or plain-old consumer protection regulations might make this a stronger requirement.
You can let the user into the demo for a few seconds and then ask them for the phone number to continue. Maybe this way you can hook them faster.

Increasing the value
You can also ask yourself — since you're going to ask the user to jump through some hoops and provide information required for verification — what else would you be able to offer to that user that would be valuable to them? For example, if your product sends email reports, could you use the email to send an example report and make that part of the value proposition for your demo? That might increase the value to the user of doing the legwork to verify themselves.
But really, do you need this?
Think carefully about the cost of these measures compared with the cost of your current situation. From what you are saying ("waste of [users'] time, and messes up our metrics on the value of having the demo"), this sounds like at least the demo isn't causing you to bleed cash and maybe you have more of a metrics problem. I wouldn't worry about users' time, it seems like they're having fun playing your game, you should be proud! I'd be tempted to say: so what if your conversion rate from demo to sales looks bad — will the change increase your sales? I doubt that "fixing" the conversion rate by adding a verification roadblock in front of your demo, to make sure that your denominator only includes "serious" people, will increase your sales.
Comment: "You can ask verifying information, and don't need to offer justification for why." Now that the GDPR has come into force, is that still true?
Comment: @Schmuddi ah what I meant was, it's not necessary to tell the user that it's because there are people abusing the demo. Otherwise there should be an indication of purpose not just because of regulation but because it's good UX. Will clarify
Comment: @Schmuddi added
Answer: I get your "abuse" and "trust" perspective but your app should avoid sounding or acting negative or accusatory in any way. Always figure out the positive way.
If you want the most users to try your app, don't make them sign up. Email addresses and phone numbers are like money and their value varies wildly.
Figure out some questions that are easy for teachers to answer and gamify your teacher authentication. Ask them the question with a timer. Give them a few shots at it. Users get rewarded instantly for knowing the question and access to the app. That's a user coming off a positive experience versus a user who just gave you something.
Offer an email or phone signup to the users who couldn't do the questions.
Comment: I've never encountered an authentication system that stressed my mental processes/focus/attention first, then offered phone or email as a backup. I'd feel somewhat offended if I got an "Oh no! We weren't able to verify you're smart enough to use our app! Please enter your phone number/email address." Dress it up as much as you want, but that seems like an unreliable test and difficult to execute without risk of leaving a bad taste. Especially since that "test" isn't part of the actual app at all. Creative idea, but I don't know if this use case is a fitting candidate for that suggestion.
Comment: These are interesting ideas, and I agree that it has to be phrased in a positive way (thus my original post). I think I agree with @maxathousand that someone could take it the wrong way. Plus, answering a question is something you know, but the email or text message is less spoofable because it's something you have.
Comment: @maxathousand That's quite a reaction to whatever design you imagined. What questions are you imagining that would induce stress? When your angry user fails to pass your questions you give your user an angry message? If you can't think of how this could be done, just ask for examples or clarification. I'd love to give some examples if you'd like.
Comment: @moot I'm sorry if that comment came off brash. Perhaps that was an exaggerated reaction. My only point is that it seems like it could come across as an IQ test and could cause offense to a legitimate user who failed to complete it successfully. Feel free to edit some examples into your answer if you have some.
Comment: @maxathousand Brash? Maybe read it again. You're upset that my solution stressed you, offended you, and is unreliable and unexecutable without leaving a "bad taste." Are you arguing that asking for email isn't a huge deal?
Comment: @moot Sorry, perhaps I was unclear: I was offering my apologies for the tone of my first comment. I'm not upset :)
Answer: How do the teachers get the app? Do they just find it on the app store or is there some kind of promo invite? If there's an invite, you can consider adding a key which needs to be entered.
I think asking for an email address is reasonable. If the teachers want to upgrade to the full version, they will need to provide some particulars. You could word it in a friendly way like they do with captchas: "We need to know you are a real human!"
It's interesting how the kids are also signing up for the demo, presumably after their teacher showed it to them in class? This means they like the game!
Answer: I think your problem aren't the kids or the (technical) costs they produce. It's more the noise in your data and sales effort. I assume your business model is to sell to the teachers. So those kids (if not instructed by the teacher - do not harm your profits)
Situation: Too many kids signups.
Thought #1:
Simply use mail signup. But as you described this is a additional potential point of conversion loss.
Thought #2: As you described your problem purely from the side of sales effort due to kids accounts you don't need their mail for further sales process. Any other kind of verification will do.
Thought #3: Kids are smart. They'll find a mail adress or google a given questions.
Conclusion:
Your primary goal is to get rid of the kids accounts, but keep the conversion convenient for the teachers.
Try to separate those groups. Do two signups. One for teachers. One for kids. And make the first one (at least in the description) less attractive for the kids. And for sales and metrics use just the data from the first one.
Based on the given information this could solve your task. It's based on your problem - not on your given question :-)