Parts of Application mysteriously fail to repaint

Question: I've been on this a couple of hours now, and not making any progress.
I have a very simple application which loads a large (2000x2500px) image from disk.
It loads into a JPanel, which is contained by a JScrollPanel, which in turn is contained by the outermost JPanel.
This code is in Scala, but should be easy enough for a Java developer to read.
When I move the scrollbar, the application prints out an indication that it is being repainted, but the image is left partially blank. When I resize the application pane, everything is drawn correctly.
Is this a bug or am I missing something really basic?

import java.awt._
import java.util.Date
import javax.imageio.ImageIO
import javax.swing._

object DisplayAnImage {
  def main(args: Array[String]) = {
    val rackStream = DisplayAnImage.getClass.getResourceAsStream("racks.jpg")
    val bi = ImageIO.read(rackStream)
    val outerMost = new  JFrame("Image display")
    outerMost.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE)
    outerMost.setLayout(new BorderLayout())

    val imagePane = new JPanel(true) {
      val c = new Canvas() {
        override def paint(g: Graphics): Unit = {
          println(s"drawing the image ${new Date()}")
          g.drawImage(bi, 0, 0, null)
        }
      }
      c.setSize(bi.getWidth, bi.getHeight)
      this.add(c)
    }

    val scroller = new JScrollPane(imagePane)
    scroller.setAutoscrolls(true)

    outerMost.add(scroller, BorderLayout.CENTER)
    outerMost.pack()
    outerMost.setSize(300, 300)
    outerMost.setVisible(true)
  }

}

Solution
With thanks to camackr - I modified the code to the following, it's simpler and works perfectly.
import java.awt._
import javax.imageio.ImageIO
import javax.swing._

object DisplayAnImage {
  def main(args: Array[String]) = {
    val rackStream = DisplayAnImage.getClass.getResourceAsStream("racks.jpg")
    val bi = ImageIO.read(rackStream)
    val outerMost = new  JFrame("Image display")
    outerMost.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE)
    outerMost.setLayout(new BorderLayout())

    val imagePane = new JPanel(true) {
      val jl = new JLabel() {
        override def paintComponent(g: Graphics): Unit = {
          g.drawImage(bi, 0, 0, null)
        }
        this.setPreferredSize(new Dimension(bi.getWidth,bi.getHeight))
      }
      this.add(jl)
    }

    val scroller = new JScrollPane(imagePane)
    scroller.setAutoscrolls(true)
    outerMost.add(scroller, BorderLayout.CENTER)
    outerMost.pack()
    outerMost.setSize(300, 300)
    outerMost.setVisible(true)
  }

}

Answer: A scrollpane works based on the preferred size of the component added to the scroll pane. You are doing custom painting but not providing a preferred size for your component.
Why are you doing custom painting? Why would you use a Canvas? Why are you overriding paint(), custom painting is done by overriding paintComponent() when using Swing.
Anyway, just use a JLabel to display the image and add the label to the scrollpane. The label will automatically determine the preferred size of itself based on the size of the image.
Comment: Could give a fancy answer, but it's mainly cause I did AWT a decade ago, then read a Swing book about 6 years ago, and the API is HUGE! ;-)
Comment: @binarytemple_picsolve, yes, and many things are different in Swing. You should keep a link to the [Swing Tutorial](http://docs.oracle.com/javase/tutorial/uiswing/TOC.html) handy.
Comment: Thanks for your help, that was really causing me grief. Took a look a the link, it's a good reference. I'm off to do SplitPane stuff now.


Embeddability of the cone of Klein bottle to $\mathbb R^4$

Question: By using Alexander Duality, we can show that $K\not\hookrightarrow \mathbb R^3$ and we can also give an explicit formula for $K\hookrightarrow\mathbb R^4$ (here $K$ is the Klein bottle). How about the cone $CK$? Can it be embedded in $\mathbb R^4$?
It cannot be embedded in $\mathbb R^4$ 'nicely', which means if one considers any $\epsilon$-ball of the coning point, $K$ cannot be embedded into the boundary of the ball. I have also tried homology and cohomology exact sequences, and they did not give me any result.
Comment: Not sure if this is useful, but the embedding also cannot be too nice as to allow two copies to be joined end to end (with a modification at coning points), to become an embedding of $S^1 \times K$ in $\mathbb{R}^4$. This is because any embedded hypersurface must be orientable.
Comment: @Tsang Can you elaborate on that comment? I don't see how gluing two copies of the cone together produces $S^1\times K$. It seems to me that the cone is not a topological manifold to begin with, but my intuition has failed before...
Comment: @JoonasIlmavirta Gluing two cones together does not produce $S^1 \times K$, one needs to modify the 'singularity' at which the two coning points connect. I don't know how nice the embedding needs to be in order to allow such a modification, therefore I am unsure about the usefulness of my original remark!
Comment: What are the simplest possible fundamental groups of the complement of $K$ in $\mathbb{R}^4$?
Comment: Just a remark: There is no piecewise-linear embedding of $CK$ into the 4-space. It suggests that there is no topological embedding either.
Answer: The following lemma is an analogue of Corollary 3.46 in Hatcher's "Algebraic Topology" and is proven by exactly the same method, using Alexander Duality (using cohomology with compact support instead of the ordinary cohomology as Hatcher does):
Lemma. Let $X$ be a locally contractible closed subset of $R^n$. Then $H_c^{n-2}(X)$ is torsion free.
Corollary. If $X$ is a nonorientable connected pseudomanifold of dimension $n-1$, it cannot be properly embedded in $R^n$.
Proof. Such $X$ will have $2$-torsion in $H_c^{n-2}(X,{\mathbb Z})$. qed
Now, turning to the open cone $CK$ over the Klein bottle, i.e.
$(K\times [0,1))/(K\times 0)$. This space is nonorientable connected pseudomanifold. Each open subset of $CK$ containing the apex $a$ of this cone (the projection of $K\times 0$) is also a nonorientable pseudomanifold.
Suppose that $CK$ embeds in $R^4$. Take the intersection $Y$ of $CK$ with a sufficiently small open ball $B(a,r)$ in $R^4$. Use the homeomorphism $B(a,r)\to R^4$ to identify $Y$ with a closed subset $X\subset R^4$.  We obtain a contradiction with Corollary above. Hence $CK$ does not embed in $R^4$.
Note that this argument is much more general applies to cones over compact nonorientable manifolds of any dimension.
Edit. Here is a better argument replacing Lemma and Corollary. I will use functoriality of the Alexander duality isomorphism AD: Given any closed subset $X\subset R^n$, we have a commutative square
$$
\begin{array}{ccc}
\check{H}^{n-1}_c(X; {\mathbb Z}) &\stackrel{AD}{\to} & \tilde{H}_0(R^n - X; {\mathbb Z}) \\
\alpha\downarrow &  & \beta\downarrow \\
\check{H}^{n-1}_c(X; {\mathbb Z}/2)&\stackrel{AD}{\to} & \tilde{H}_0(R^n - X; {\mathbb Z}/2)
\end{array}
$$
Here cohomology is the compactly supported Chech cohomology. In the case when $X$ is locally contractible, it is naturally isomorphic to the compactly supported singular cohomology.
Now, if $X$ is homeomorphic to a nonorientable connected pseudomanifold of dimension $n-1$, then the homomorphism $\alpha$ is not surjective (since it is a homomorphism $0\to {\mathbb Z}/2$). On the other hand, the homomorphism $\beta$ is always surjective (as a homomorphism of $0$-degree reduced homology groups). Therefore, a nonorientable connected pseudomanifold of dimension $n-1$ cannot be properly topologically embedded in $R^n$. The rest of the argument is as above.
Comment: I don't quite see how the corollary follows. Are you saying that if $X$ is a nonorientable connected pseudomanifold of dimension $n-1$, then $H_c^{n-1}(X)$ has torsion?
Comment: @MoisheCohen How does the corollary follow from the lemma? Since $CK$ is contractable, won't $H^{n-1}_c(CK)$ be a trivial group?
Comment: @UnemChan It should be n-2 with compact support.
Answer: I have a suggestion for your problem.
The idea is due, to my knowledge, to Hassler Whitney from the 1940's, and it was used in a paper of William Massey from the 1960's about an estimate on the signature of a closed four manifold  constructed from a surface in $S^4$.
Whitney observed an embedded closed surface in four space has a well-defined intersection number that does not require a global orientation for the surface.
Choose a local orientation near each point of transversal intersection of the surface with a pushed off copy of itself.
Both branches now have orientations which give a local orientation of four space which can be compared to a background orientation of four space. This gives a well-defined sign to the intersection point, note the order of branches does not affect the sign because they are even dimensional.
Changing the local orientation on the surface changes the orientation on each branch, so two minus signs.
It is a subtle and beautiful construction.
I am thinking if the algebraic sum of these is nonzero then it obstructs embedding a cone, because from a cone embedding one would get a embedding of the surface $\times$ $\epsilon$-interval, which would move the surface off of itself locally, forcing the Whitney sum to be zero.

The following lemma is an analogue of Corollary 3.46 in Hatcher's "Algebraic Topology" and is proven by exactly the same method, using Alexander Duality (using cohomology with compact support instead of the ordinary cohomology as Hatcher does):
Lemma. Let $X$ be a locally contractible closed subset of $R^n$. Then $H_c^{n-2}(X)$ is torsion-free.
Corollary. If $X$ is a nonorientable connected pseudomanifold of dimension $n-1$, it cannot be properly embedded in $R^n$.
Proof. Such $X$ will have $2$-torsion in $H_c^{n-2}(X,{\mathbb Z})$. qed
Now, turning to the open cone $CK$ over the Klein bottle, i.e.
  $(K\times [0,1))/(K\times 0)$. This space is nonorientable connected pseudomanifold. Each open subset of $CK$ containing the apex $a$ of this cone (the projection of $K\times 0$) is also a nonorientable pseudomanifold.
Suppose that $CK$ embeds in $R^4$. Take the intersection $Y$ of $CK$ with a sufficiently small open ball $B(a,r)$ in $R^4$. Use the homeomorphism $B(a,r)\to R^4$ to identify $Y$ with a closed subset $X\subset R^4$.  We obtain a contradiction with Corollary above. Hence $CK$ does not embed in $R^4$.
Note that this argument is much more general applies to cones over compact nonorientable manifolds of any dimension.
Edit. Here is a better argument replacing Lemma and Corollary. I will use functoriality of the Alexander duality isomorphism AD: Given any closed subset $X\subset R^n$, we have a commutative square
  $$
\begin{array}{ccc}
\check{H}^{n-1}_c(X; {\mathbb Z}) &\stackrel{AD}{\to} & \tilde{H}_0(R^n - X; {\mathbb Z}) \\
\alpha\downarrow &  & \beta\downarrow \\
\check{H}^{n-1}_c(X; {\mathbb Z}/2)&\stackrel{AD}{\to} & \tilde{H}_0(R^n - X; {\mathbb Z}/2)
\end{array}
$$
  Here cohomology is the compactly supported Chech cohomology. In the case when $X$ is locally contractible, it is naturally isomorphic to the compactly supported singular cohomology.
Now, if $X$ is homeomorphic to a nonorientable connected pseudomanifold of dimension $n-1$, then the homomorphism $\alpha$ is not surjective (since it is a homomorphism $0\to {\mathbb Z}/2$). On the other hand, the homomorphism $\beta$ is always surjective (as a homomorphism of $0$-degree reduced homology groups). Therefore, a nonorientable connected pseudomanifold of dimension $n-1$ cannot be properly topologically embedded in $R^n$. The rest of the argument is as above.

The cone on a manifold is not really a closed psuedomanifold.
Can you describe the embedding of the Klein bottle $\times$ interval?
With regards to the "better argument" that has been written, I like this proof. It shows the intersection with the link argument disproving nice embeddings, also works in spirit for all topological embeddings using cohomology etc.
It also shows $X$ locally separates $\mathbb{R}^n$, which is of course intuitive.
Comment: If you think your old comment (previously answer) is obsolete, you can delete it. In fact, you can also flag other users' comments if they have become unnecessary, and a moderator will see if it should be deleted. And please don't call voters and moderators imbeciles; it helps no one. I recommend deleting your first paragraph and the comment and leaving it at that.
Comment: Interesting idea but it will not work, as the product of the Klein bottle with an interval does embed in the 4-space.


Best way of storing logged in users in MVC

Question: I'm writing an MVC web application which requires people to login. I want the logged in people to be stored in a database and wondered what the best way of doing this was.
So far I've stored the users session ID and user ID in a table called LoggedOn. Then I can determine if a person is logged on by checking if their sessionID exists in the LoggedOn table.
Is this the best way to do is or is there a better way?
Answer: I would store the id and the timestamp of the last action, and delete them if the timestamp is older than a certain amount of minutes, or if they log out.


Javascript return illegal statement

Question: if(choice1 === choice2) {
return"The result is a tie!";

}
else if (choice1 === "rock") {
if (choice2 === "scissors") {
    return "rock wins";

}
else {
    return "paper wins";
}

}
please help mee
Comment: `return` should be used inside a function
Comment: Problem is: illegal return statement
Comment: What are you trying to return to? You may only return to a function
Answer: A return statement returns control to the calling context. In the case of global code, there is no calling context to return to, so they are illegal there. They are part of the production for FunctionDeclaration, so you can only use them inside functions.
To get to the relevant parts of ECMA-262, start with §14.1 Function Definitions, one of which is FunctionDeclaration which consists of, among other things, a FunctionBody, which is made up of a FunctionStatementList, which contains a StatementList. Now that is made up (surprisingly) of zero or more StatementListItems which are Statements, and one type of statement is ReturnStatement, which is described in §13.10.
So return statements can only appear in function bodies, and function bodies can only appear in code that is a FunctionDeclaration, FunctionExpression or ArrowFunction. So from that it can be stated more generally that return statements can only appear inside functions.

Javascript return illegal statement


Probability of recapturing 5 tagged fish out of 100

Question: I'm a maths student and I've been stuck at this problem for some days now, and haven't yet worked out a way of solving it. The problem comes form the book; "Probability and statistics, a course for physicists and engineers" by Arak M.Mathai and Hans J.Haubold.
2.5.12- In a lake there are n fishes, 50 of them are caught and tagged. Later, in the same lake, 100 fishes are caught;
(i) What is the probability that exactly 5 out of theese 100 are tagged (Assume no reproduction between them)?
(ii) How can the total number n of fishes in the lake be obatined with this information (the information being the solution to problem (i))?
Comment: https://en.wikipedia.org/wiki/Mark_and_recapture
Answer: If $X$ is the number of tagged fish in the 100 fishes $X\sim\text{Hypergeometric}(50, n-50, 100)$. The probability that 5 are tagged is
$$\Pr(X=5)=\frac{{50\choose 5}{n-50\choose 95}}{{n\choose 100}}$$
Then $n$ can be found by solving for $n$ in the above equation if the probability is known.
Comment: This question seems not to meet the standards for the site. Instead of answering it, why not look for a good duplicate target, or help the user by posting comments suggesting improvements? Please also read the [meta announcement](https://math.meta.stackexchange.com/questions/33508/) regarding quality standards.
Answer: Assuming that you mean exactly 5 fish in (i) you can use Binomial distribution to calculate the probability depending on $n$. You should also include some sort of Indicator function here to exclude the possibility of $n < 100$. For (ii) the first comment will probably help you. Good luck!
Comment: Hypergeometric, not binomial.
Answer: Capture-Recapture Method to estimate population size.
If there has been time between tagging and recapture for the fish to randomize themselves for random recapture then the proportion $50/n$ of tagged fish in the lake should be about the same as the proportion $x/100$ in
the lake. You say $x=5,$ so solve for $n.$
Also, following the Answer of @stacker (+1), to use the hypergeometric PDF (or PMF): From dhyper in R, you can find the $n$ to maximize $P(X = 5)$ as follows:
n = 100:2000
p = dhyper(5,50,n-50,100)
n[p == max(p)]
[1] 999

To avoid the (presumably unlikely) outcome that
there are $x=0$ tagged fish upon recapture, a slight
modification is helpful. (Chapman method instead of Lincoln-Petersen.) For this and other insights, please do read the Wikipedia link suggested by @JMoravitz.
Comment: Nice R method !
Comment: This question seems not to meet the standards for the site. Instead of answering it, why not look for a good duplicate target, or help the user by posting comments suggesting improvements? Please also read the [meta announcement](https://math.meta.stackexchange.com/questions/33508/) regarding quality standards.


Noisy kinect color (rgb) images

Question: i'm using opencv interface (http://docs.opencv.org/doc/user_guide/ug_highgui.html?highlight=kinect) to get color (rgb) and depth frames from a kinect camera. For a standard VGA 640x480 resolution and with code like
<code>capture.retrieve( bgrImage, OPENNI_BGR_IMAGE );
</code>
i get this :

I think this is really noisy. Is this normal quality for a kinect rgb camera?
I tried various filtering (blurring, sharpening, opening..) procedures but i got minor improvements.
Comment: What is the light like in your room?  That looks to me to be pretty typical of a low light image.  Try adding a few flood lights.  Have you tried other cameras in the same space?
Comment: Do you want to know whether this is the expected image for kinect or are you interested in knowing which filters can be applied in this situation ?
Comment: @Evil Closet Monkey: light was surely insufficient, but i also wanted to know which filters could be applied (@mmgp). Thank you both.
Answer: The conditions under which this image was taken are unknown to me, and I cannot attest the quality of the images taken using Kinect, so I'm ignoring this part of the question.
A very simple thing you can do to likely improve the image quality is to average several frames you might be getting. That is it.
Another options include, for example, Bilateral Filtering or Mean Shift Filtering (and I'm not sure how you would do the later purely with ready OpenCV functions) that can handle well this kind of noise. For instance, here are three rows of images. In the second column you see the edges found by Canny for the image in the first column. The first row shows the input image as is, the second row is the result of a particular Mean Shift, and the last one is for Bilateral Filtering.

While the results are particularly good, the problem is that these filtering techniques are slow for the typical computers used nowadays.

Noisy kinect color (rgb) images


Intervalo em minutos de um periodo

Question: Estou tentando fazer um select que liste num intervalo de 10 minutos um valor do banco, só que desta maneira aparece displicente, existe alguma maneira de mostrar os dados mesmo não tendo dados no intervalo corretamente?
Exemplo:

00:00:00 = 0
00:10:00 = 0
00:20:00 = 0
06:00:00 = 5
06:10:00 = 70

 SELECT
    datetime_entry_queue,SUM(duration) AS segundos,
    sec_to_time(SUM(duration)) AS horas,
    COUNT(callerid) AS tot_chamadas
FROM
    call_center.call_entry
WHERE
 GROUP BY
    UNIX_TIMESTAMP(datetime_entry_queue) DIV 600;

Dados select:

    CREATE TABLE `call_entry` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `id_agent` int(10) unsigned default NULL,
  `id_queue_call_entry` int(10) unsigned NOT NULL,
  `id_contact` int(10) unsigned default NULL,
  `callerid` varchar(15) NOT NULL,
  `datetime_init` datetime default NULL,
  `datetime_end` datetime default NULL,
  `duration` int(10) unsigned default NULL,
  `status` varchar(32) default NULL,
  `transfer` varchar(6) default NULL,
  `datetime_entry_queue` datetime default NULL,
  `duration_wait` int(11) default NULL,
  `uniqueid` varchar(32) default NULL,
  `id_campaign` int(10) unsigned default NULL,
  `trunk` varchar(20) NOT NULL,
  PRIMARY KEY  (`id`),
  KEY `id_agent` (`id_agent`),
  KEY `id_queue_call_entry` (`id_queue_call_entry`),
  KEY `id_contact` (`id_contact`),
  KEY `call_entry_ibfk_4` (`id_campaign`),
  KEY `datetime_init` (`datetime_init`),
  KEY `datetime_entry_queue` (`datetime_entry_queue`),
  CONSTRAINT `call_entry_ibfk_1` FOREIGN KEY (`id_agent`) REFERENCES `agent` (`id`),
  CONSTRAINT `call_entry_ibfk_2` FOREIGN KEY (`id_queue_call_entry`) REFERENCES `queue_call_entry` (`id`),
  CONSTRAINT `call_entry_ibfk_3` FOREIGN KEY (`id_contact`) REFERENCES `contact` (`id`),
  CONSTRAINT `call_entry_ibfk_4` FOREIGN KEY (`id_campaign`) REFERENCES `campaign_entry` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=966709 DEFAULT CHARSET=utf8;
   datetime_entry_queue BETWEEN '2016-10-01' AND '2016-10-15'

Comment: Se possível coloque o script de criação da sua tabela e inserção de algumas linhas para que possamos verificar o que dá pra fazer
Answer: O problema é o primeiro campo da sua query. O datetime_entry_queue acaba prejudicando o agrupamento. Remova-o para obter os resultados agrupados:
SELECT SUM(duration) AS segundos,
       SEC_TO_TIME(SUM(duration)) AS horas,
       COUNT(callerid) AS tot_chamadas
  FROM call_center.call_entry
 WHERE datetime_entry_queue BETWEEN '2016-10-01' AND '2016-10-15'
 GROUP BY UNIX_TIMESTAMP(datetime_entry_queue) DIV 600;

Caso precise deste campo utilize uma subquery:
SELECT x.intervalo,
       SUM(x.duration) AS segundos,
       SEC_TO_TIME(SUM(x.duration)) AS horas,
       COUNT(x.callerid) AS tot_chamadas
  FROM (SELECT UNIX_TIMESTAMP(ce.datetime_entry_queue) DIV 600 AS intervalo,
               ce.duration,
               ce.callerid
          FROM call_center.call_entry ce
         WHERE ce.datetime_entry_queue BETWEEN '2016-10-01' AND '2016-10-15') x
 GROUP BY x.intervalo;

Comment: Obrigado pela resposta Sorack, mais eu preciso saber qual foi o intervalo de tempo de cada valor nas linhas.. adicionei o create acima.
Comment: Valeu pela ajuda @Sorack vou adaptar aqui!!
Comment: @RafaelVergoPolan adicionado exemplo com o intervalo

Intervalo em minutos de um periodo


How can I resolve my CGI error during installation of Drupal 7 on WinXp?

Question: I'm installing a local instance of Drupal 7 on my WinXp machine. PHP 5.4 and MySql 5.5 are installed already.
I've unpacked the downloaded Drupal 7 site files into a virtual directory and used IIS 6 to make this directory a PHP site.
However, the result is not encouraging:

CGI Error The specified CGI application misbehaved by not returning a
  complete set of HTTP headers. The headers it did return are:
Could not open input file: Files\PHP\php-win.exe

The web address I'm using is:
<code>http://localhost/drupal7/install.php
</code>
Where "drupal7" is the name of my application in IIS.
Any ideas on what the problem might be?
Comment: If possible I'd switch to Apache instead of IIS
Comment: @Ajit, you should put this comment into the question as an Answer.  I just got done installing Acquia Dev Desktop and got my Drupal site up and running with no problems whatsoever.  I'd like to Accept your comment as the Accepted Answer if I could.
Comment: Apache on Windows?  Hmmm.  Can you even run Apache and IIS on the same machine?
Comment: Yuppers. http://httpd.apache.org/download.cgi#apache24

I do all my development with Apache 2.4, PHP 5.3 and MySQL 5.5 on Windows XP.
Comment: Use XAMP, WAMP...
Comment: you could try using [WAMP server](http://www.wampserver.com/en/) or [Acquia Dev Desktop](http://www.acquia.com/downloads). I would recomend using Acquia, as it contains all the necessary settings already configured.
Comment: @MikeClark Look for my [answer](http://drupal.stackexchange.com/questions/31791/having-problem-installing-drupal-7-on-winxp-getting-cgi-error/31928#31928). Also added another option of installing on windows which could be configured for IIS. Apache is mostly recommended though.
Answer: As in my comment above, you should try using WAMP server or Acquia Dev Desktop, which uses Apache (more suitable for PHP development).
To install Drupal on Windows, you could install it with Microsoft web platform installer by following this procedure.
Answer: Commenters are right : try to use Apache.
About your error, my guess is a there is a path problem with the "Program Files" folder which contains a space which must not have been escaped correctly.
Did you try to change the place of your installation and/or correct the setting for the path to the php executable ?


Removing duplicate entries from MySQL database

Question: I have a table with 8 columns in, but over time I have picked up numerous duplicates. I have looked at the other question with a similar topic, but it does not solve the issue I am currently having.
+---------------------------------------------------------------------------------------+
| id | market | agent | report_name | producer_code | report_date | entered_date | sync |
+---------------------------------------------------------------------------------------+

What defines a unique entry is based on the market, agent, report_name, producer_code, and report_date fields. What I am looking for is a way to list all the duplicate entries and delete them. Or to just delete the duplicate entries.
I have thought about doing it with a script, but the table contains 2.5mil entries, and the time it would take would be unfeasible.
Could anybody suggest any alternatives? I have seen people get a list of duplicates using the following query, but not sure on how to adapt it to my situation:
SELECT id, count(*) AS n
 FROM table_name
GROUP BY id
HAVING n > 1

Answer: Here are two strategies you might think about.  You will have to adjust the columns used to select duplicates based upon what you actually consider a duplicate.  I just included all of your listed columns other than the id column.
The first simply creates a new table without duplicates.  Sometimes this is actually faster and easier than trying to delete all the offending rows.  Just create a new table, insert the unique rows (I used min(id) for the id of the resulting row), rename the two tables, and (once you are satisfied that everything worked correctly) drop the original table.  Of course, if you have any foreign key constraints you'll have to deal with those as well.
create table table_copy like table_name;

insert into table_copy
(id, market, agent, report_name, producer_code, report_date, entered_date, sync)
select min(id), market, agent, report_name, producer_code, report_date,
       entered_date, sync
from table_name
group by market, agent, report_name, producer_code, report_date,
         entered_date, sync;

RENAME TABLE table_name TO table_old, table_copy TO table_name;

drop table table_old;

The second strategy, which just deletes the duplicates, uses a temporary table to hold the information about what rows have duplicates since MySQL won't allow you to select from the same table you are deleting from in a subquery.  Simply create a temporary table with the columns that identify the duplicates plus an id column that will actually hold the id to keep and then you can do a multi-table delete where you join the two tables to select just the duplicates.
create temporary table dups
select min(id), market, agent, report_name, producer_code, report_date,
       entered_date, sync
from table_name
group by market, agent, report_name, producer_code, report_date,
         entered_date, sync
having count(*) > 1;

delete t
from table_name t, dups d
where t.id != d.id
and t.market = d.market
and t.agent = d.agent
and t.report_name = d.report_name
and t.producer_code = d.producer_code
and t.report_date = d.report_date
and t.entered_date = d.entered_date
and t.sync = d.sync;

Comment: Great, just tried your first method and it seems to have worked perfectly and only took about 30min to execute. Thanks man.
Comment: Just had to do the same thing on a different database and your second method also works flawlessly. Thanks again.
Answer: You can find the dupes, based on your "key" fields, by doing:
select id, count(*) as row_count
from table
group by market, agent, report_name, producer_code, report_date
having (row_count > 1)

which you could then use in a delete script. Of course, you'd have to be very careful doing this, as it'll return ALL the duplicate rows, and you'd want to save at least ONE of those rows from each grouping.
Answer: Another easy way would be to

create a new table
put a UNIQUE index on the fields you need to be unique (a primary key is a special kind of unique index)
use INSERT IGNORE INTO newtable SELECT * FROM oldtable (ORDER BY if you want the last/first records to remain - should there be a difference in the other columns)
DROP the old table and RENAME the new table to the old table
Answer: You may also use Primary key on the columns the unique entries are based on, this will prevent adding new records with duplicate details.
Comment: Could you please give an example on how I would go about doing this please?
Comment: @Surim: Though primary keys are great way to prevent redundancy of data, if your database is acting as a back-end to any application, it is good idea to prevent duplication from front-end, that is, using application logic, you may take a look at http://databases.about.com/cs/administration/g/primarykey.htm to know more about primary keys, and here: http://www.danielschneller.com/2007/05/mysql-add-primary-key-to-table-with.html for ways to add them to your table.
Comment: This system is a little old and originally didnt have any checks to prevent dupes. I have added it in now, so that is all good, it was just a case of having to remove the current duplicates that had accumulated over time.


Show that $g=f\mid_{B_{1}(0)}$ is injective and determines the range of $g$ where $f(x) = \Vert x \Vert^{2}x$

Question:
Let $f: \mathbb{R}^{n}\to \mathbb{R}^{n}$ defined by $\Vert x \Vert^{2} x$.
(a) Show that $f$ is of class $C^{\infty}$.
(b) Show that $g=f\mid_{B_{1}(0)}$ is injective and determines the range  of $g$.
(c) Prove that $g^{-1}$ (defined on $g(B_{1}(0))$) is not differentiable in $0$.

My attempt.
(a) Write $f = \phi\cdot \psi$ where $\phi(x) = \Vert x \Vert^2$ and $\psi = x$. But $D_{x}\phi(h) = 2\langle x : h \rangle$, that is,$D_{x}\phi(h) \in C^{\infty}$ and obviously, $\psi(x) \in C^{\infty}$. Therefore, $f \in C^{\infty}$

(b) Take $x, y \in B_{1}(0)\setminus\{0\}$ such that $g(x) = g(y)$, that is, $\Vert x \Vert^{2}x = \Vert y \Vert^{2}y$. But $\Vert x^{2} \Vert = k_{1} \leq 1$ and $\Vert y \Vert^{2} = k_{2} \leq 1$, then $\displaystyle x_{i} = \frac{k_{2}}{k_{1}}y_{i}$. Is there a way to show that $\displaystyle \frac{k_{2}}{k_{1}} = 1$ or is there a better way to show injectivity?
Im not sure about the range of $g$. We have $\Vert x \Vert \leq 1$ so, $\Vert \Vert x \Vert^{2} x \Vert = \Vert x \Vert^{3} \leq 1$, then $g(B_{1}(0)) \subset B_{1}(0)$?

I have not tried it since Im not sure about the range of $g$. But I think I should try to show that some of the partial derivatives are not continuous at $0$.
Comment: Pretty much. Looks like mapping the unit vectors the give the direction of the vector with a cubic resizing factor based on its norm. Also your argument about the ball centered at 0 is correct.
Answer: The range is all of $\mathbb R^{n}$. Clearly, $0$ is in the range. If $y \neq 0$ let $x=\|y\|^{-2/3} y$. Then $\|x||^{2}x=y$. Also, if $y \in B_1(0) \setminus \{0\}$ then $x \in B_1(0)$ (and $g(x)=y$) so $g$ maps $B_1(0)$ onto itself. Injectivity of $f$ and $g$: let $\|x\|^{2}x=\|y\|^{2}y$. Take norm on both sides. We get $\|x\|^{3}=\|y\|^{3}$ which implies $\|x\|=\|y\|$. If $x=0$ then so is $y$. Otherise, we can divide by $\|x\|^{3}$ to get $x=y$.
Comment: @LucasCorrêa I have now included a proof of injectivity.
Comment: Thank you, Kavi! Do you have any hints for injectivity?


SQL Server MaxDop does not generate Parallelism

Question: In SQL Server 2008, I've added OPTION (MAXDOP 4) to my query.
However, there is no "Parallelism" step in estimated execution plan.
Does it mean that SQL Server chooses not to execute the query in parallel even if I say that "MAXDOP 4"?
How can I force SQL Server to use parallelism?
Answer: OPTION (MAXDOP 4) is used to limit CPU during execution.
if you want to force SQL Server to use parallelism you can do the following. OPTION(RECOMPILE, QUERYTRACEON 8649) you can read more about it http://web.archive.org/web/20180404164406/http://sqlblog.com/blogs/paul_white/archive/2011/12/23/forcing-a-parallel-query-execution-plan.aspx
Answer: MAXDOP is maximum degree of parralelism.
Some queries cannot use parrallel processing (example Selects with ORDER BY).
Parrelelism also adds some overhead. SQL Server will not use it unless it sees it as necessary (using Statistics).
Answer: From SQL Server 2016 CU2 you could use undocumented query hint:
SELECT ...
-- rest of the query
option(use hint('ENABLE_PARALLEL_PLAN_PREFERENCE'));

More info:
http://www.queryprocessor.com/how-to-get-a-parallel-plan/
https://connect.microsoft.com/SQLServer/feedback/details/714968/provide-a-hint-to-force-generation-of-a-parallel-plan


trying to set up a newsletter server, hotmail blocks me

Question: I have little experience setting up an email server so I'm having a lot of dificulties right now.
A client from a political party wants to send a newsletter to 8000 people with a very limited budget (all legit, no spam so people wont mark it as spam), What I did was I set up a server with mail enable free edition with port 26, no-ip with a free domain, had bulkmailer instaled and sent tons of emails (most where to hotmail).
Some did arrive to private emails, but none to hotmail, gmail and yahoo mail (not even spam folder).
My guess as to why they dont work, is that its a dynamic ip and a free subdomain. I thought about just buying a domain, but I need to be sure.
So, anyone know what I should do or look into?
thanks
Answer: My Advice:  Leave it to the experts
As someone who has set up their own PHPList, GroupMail, and several other products and projects... let me give you one piece of valuable advice.
If you're looking for the "brain damage free" solution go with a 3rd party provider such as "Constant Contact":
http://www.constantcontact.com
I personally have not used them but several of my clients do and LOVE it.  For myself, I continue to use GroupMail and PHPList to send out thousands of newsletters but let me tell you... that's after YEARS of struggling and fighting to get it all "dialed in".
First of all... make sure you're CAN-SPAM compliant (assuming you're in the USA).
Second... make sure your IP address is static and has a reverse DNS for the IP.
Third... make sure your mail server is properly configured... and by properly I mean SERIOUSLY properly configured... not just something that sends out email.
Fourth... make sure your ISP knows who you are and what you're doing.  Many ISPs have policies build into their TOS to deal with people who send bulk email... even opt-in newsletters.  Just because you're CAN-SPAM compliant and have the user's permission doesn't mean your ISP will like you.  I'm on a first name basis with most of the tech guys from my ISP.
Fifth... be prepared to fight every little "wanna-be" blacklist in on the internet.  Some don't matter... some do.  If you end up on them... its sometimes a complete pain to try and get OFF them.
Sixth... clean your email list!  Process those bounces.  The big guys will ban you quickly if you start sending to too many "bad" email addresses.
Seventh... get signed up with the "big boys" as far as bulk mail and understand how they work.
Eights... I can go on and on... but I think you're getting the idea...

Summary:
If you have a client and he only wants to email 8,000 people... you're probably WAY better off going with someone like Constant Contact (or someone similar) and letting THEM deal with any potential brain damage.
Keep it simple. :-)
Answer: You pretty much answered your own question.
Large commercial email providers expect that you aren't going to do a dump and run spam like your describing.
Do this right.  Obtain a list server from a respectable email hosting provider and send the email out that way from a list-serv that supports opt-out.
It's not expensive at all.  A list-serv from a respectable email provider can be had for $24.95 or less.  Probably less!
If you truly are sending this from/for a political party they have a few dollars to spend.  If not then you should probably spend the $20 bucks to do it for them.
The plus side to using a hosted solution is most of the work will be done for you by experienced email administrators.
Comment: do you have any examples of a respectable email hosting provider? mediatemple allows 500 mails an hour, thats like 16 hours to complete... do yo know any that allows something like 2000 emails an hour?
Comment: I have used iContact in the past.  They don't suck, they have an XML-API that is mostly ok.

My only problem with them is that they don't support MIME-email, so I cannot include small images inline.
Comment: Two things... 1) Be VERY careful how fast you send out email.  Too fast can get you banned temporarily (Yahoo loves to do this).  2) I suspect the reason constant contact doesn't allow small images inline is because that is starting to trigger more and more spam filters.  Just guessing on #2 based on personal experience with my own newsletters.
Answer: The reason that your emails never made it to yahoo and hotmail is because you aren't making use of DomainKeys.  As others have already suggested, you're better off using someone like ConstantContact or MailChimp.  I have already recommended MailChimp to others here because I have about 1.5 years experience with them so far.
If you insist on doing this yourself, you're going to have to set up DomainKeys on your server
Answer: You can decrease the probability that your email will be considered as SPAM by adopting some of the best practices (like SPF, DKIM, etc.)
To test how your Email server fares against these, try the Online test at http://www.allaboutspam.com/email-server-test.


nginx: Redirecting without changing the address line in the browser

Question: I have a support system installed with a different hoster and want the address from my web application to contain a link to that support system. However, the domain name I registered together with this support system is completely unrelated to the name of my web application and might confuse people.
Is it possible to enter a link like www.example.com/support and then have nginx redirect to the designated domain without changing the address line itself?
I tried rewrite, but it completely redirects you.
Answer: You can try proxying it, but this is just a tip, I haven't tried it yet.
<code>location / {
  proxy_pass        http://desired_domain;
  proxy_set_header  X-Real-IP  $remote_addr;

  # original host uses built-in $host variable, replace it with desired name
  # proxy_set_header Host $host;
  proxy_set_header  Host       desired_hostname;
}
</code>
Answer: Use frames. frameset hosted on your machine with one frame inside pulling contents From URL you want to hide.


Modified Sturms Comparison Theorem

Question: Suppose that we have some smooth $x(t), y(t)$ satisfying
$$
x''+Px=0, \; \; y''+Qy=0
$$
with $Q(t)\geq P(t)$ for all $t$ and $x(0)=y(0)=0$, $x'(0)=y'(0)>0$. I would like to show that $x(t)\geq y(t)$ for all $t\geq 0$. I know that this is similar to Sturms comparison theorem which compares the zeros of the functions $x$ and $y$ but how would you go about proving this directly?
I have tried multiplying the first equation by $y$ and the second by $x$ and subtracting to get
$$
(x'y-y'x)'=x''y-y''x=(Q-P)xy.
$$
Then I can integrate this expression (say from $0$ to $s$) and use the fact that $x(0)=y(0)=0$ to see that
$$
x'(s)y(s)-y'(s)x(s)=\int_0^s (Q-P) xy \; dt.
$$
I know that $x,y$ are positive for short time after $0$ (since $x'(0)=y'(0)>0$) so I was thinking of using this fact and choose $s$ to be the first 0 of either $x$ or $y$ so that the RHS is positive.
I am not sure if this is the correct approach or if this works at all but this is the only way I see to use the fact that $Q\geq P$. I would love a hint!
Comment: For some $\epsilon>0$, RHS is positive as $x(t)$ and $y(t)$ are positive for all $t \in (0,\epsilon)$. But then, after proving RHS is positive, how you show $x(t)>=y(t)$?
Answer: My hint is $Q(t)=4\ge1=P(t)$, $x(t)=\sin t$, $y(t)=\frac12\sin2t$, $x(0)=y(0)=1$, $x^{\prime}(0)=y^{\prime}(0)=1>0$ but $y(3\pi/2)=0>x(3\pi/2)=-1$. When $x(t)$ and $y(t)$ are oscillatory it's a bit of a toss-up as to who's on top.
Comment: Well that is not optimal. No wonder all attempts at solving this problem were failing. Thank you!

Modified Sturms Comparison Theorem


Ordering Table by column

Question: I try to add the possibility to order by column in the header of my table element.
I started to use Drupal 8 and I can't find any clear documentation about table on the API site to do what i want...
Thanks in advance.
Answer: You have to do this while defining the header array like
<code>$header = array(
     array(
       'data'  => t('Url'),
       'field' => 'd.path',
       'sort'  => 'asc',
     ),
     array(
       'data'  => t('Text'),
       'field' => 'd.text',
     ),
    );
</code>
So, this table will have two columns, Url & Text. And it will be sorted in ascending order by column Url.

Ordering Table by column


To find the arrangement of given letters so that there is fixed number of transition between them.

Question: A 10 letter word is composed of $P,\ Q,\ R,\ S$. The problem is to find the number of arrangements of these letters which could lead to a fixed number of transitions between each pair of letters.
Example,  consider the following arrangement of $P,\ Q,\ R,\ S$ given as
$PQPRSPQRSS$ has $3\ P$, $2\ Q$, $2\ R$, $3\ S$ has $3$ transitions between $P$ and $Q$, $1$ transition between $P$ and $R$, $1$ transition between $P$ and $S$, $2$ transition between $R$ and $S$ and $1$ transition between $Q$ and $R$.
The question here is to find the number of ways it can be arranged so that the transition between alphabets remains conserved.
Comment: By alphabet do you mean letter?
Comment: In the above question, I have 10  letter word comprising of P,Q,R,S as given. The problem is to find all the combinations which maintains same number of transitions between the letters as given in the question.
Answer: Consider a $4 \times 4$ symmetric matrix $M$ with entries $m_{ij}$ and diagonal entries $1$.
I'll label the indices $1,2,3,4$ as $P,Q,R,S$.  Each entry
of $M^{9}$ is a polynomial of total degree $ \le 9$ in the $m_{ij}$, where the coefficient of each monomial in $M^9_{ij}$ gives the number of $10$-letter words starting with $i$, ending with $j$, and with the numbers of transitions specified by the monomial.  Thus for the number with $3$ transitions between $P$ and $Q$, $1$ between $P$ and $R$, $1$ between $P$ and $S$, $1$ between $Q$ and $R$, $2$ between $R$ and $S$, and $0$ for the other pairs, you would take the coefficient of $m_{PQ}^3 m_{PR} m_{PS} m_{QR} m_{RS}^2$.  Since you don't care where you start and end, add these for all $i,j$.  Using Maple I get $288$.
Comment: can u give me some reference so that I can understand the solution well.


What is the "grid column label" for Microsoft?

Question: I am learning ASP.NET Core, the ways to display the Model properties on a View...
So, I discovered the DisplayAttribute.ShortName property that

Gets or sets a value that is used for the grid column label.

More than that

The short name is used as the grid column label for a UI element that is bound to the property that is annotated with this attribute. The Dynamic Data Insert.aspx and Edit.aspx page templates use the ShortName for the field label.

What should MS mean by "grid column label"?
I used that in my view, but obtained the Name instead of the ShortName

                @Html.DisplayNameFor(model => model.Date)

                @Html.DisplayNameFor(model => model.Name)

for the defined Model like this
[Display(Name = "Creation Date", ShortName = "Date")]
public DateTime Date { get { return this.Timestamp.DateTime; } }

[Display(Name = "Project Name", ShortName = "Name")]
public string Name { get; set; }

Custom Helper
I already saw a very helpful answer on how to build a custom helper that could use it do the custom @Html.DisplayShortNameFor(), but I wonder what for it was created, if no possibility to use it without creating additional and, mainly, same shared by the community custom helpers, that, probably, should be included in the framework?! Am I missing something?
What are the "grid column label" and Insert.aspx and Edit.aspx templates (for the "asp.net core" usage)?
Comment: By Googling "ASP.NET Core docs" and picking the **first** result?
Comment: The documentation you linked is for .NET Framework/ASP.NET, not for ASP.NET Core and/or .NET Core. aspx are code behind files of ASP.NET WebForms (and ASP.NET Core had a global.aspx too). Neither WebForms nor aspx are there anymore in ASP.NET Core
Comment: @Tseng so where should I find that `ShortName` documentation for ASP.NET Core?
Comment: [Introduction to ASP.NET Core](https://learn.microsoft.com/en-us/aspnet/core/)
Comment: @Tseng I am learning for weeks already from the ASP.NET Core MS documentation, but I ask now about the `DisplayAttribute.ShortName` attribute. Thanks.
Comment: The api reference is on the same page Anderson linked, just scroll down (https://learn.microsoft.com/en-us/aspnet/core/api/). But DisplayAttribute isn't there, since it's not a ASP.NET Core class but part of corefx. In essence there is no code generation like there used to be in ASP.NET WebForms, so I'd be surprised to see that property used automatically unless you specifically call it with the custom extension method you already found out.
Comment: @Tseng thanks for trying to help, but your links did't really brought light on the OP question...
Comment: Like I said, `DisplayAttribute` isn't something ASP.NET Core specific. It resides in the `System.ComponentModel` namespace and is a set of generic attributes which can be used for multiple purposes, i.e. in WPF, WinForms, for Serialization (XML/JSON) or validation/localization (MVC). Just because the property is always there doesn't mean every consumer must use it. And unless the ASP.NET Core docs mention the property being used, it's most likely unused. But ASP.NET Core is open source, so feel free to dig through the source and see if its used anywhere
Comment: As I understood from the Anderson answer, it was created and used for the Dynamic Data projects. Only people that works with this kind of project can understand what is about the MS documentation for that attribute. The documentation should be understood by all the people potentially using that attribute, including ASP.NET/ASP.NET Core users.
Answer: When it states that:

The Dynamic Data Insert.aspx and Edit.aspx page templates use the
  ShortName for the field label

It's probably about ASP.NET Dynamic Data:

ASP.NET Dynamic Data lets you create extensible data-driven Web applications by inferring at run time the appearance and behavior of data entities from the database schema and deriving UI behavior from it.

Never used it and seems not to be available on VS2017.
Probably, Nome, Email and Blog on the following screenshot:
Comment: thanks for bringing the light on that DynamicData... What do you think are the *grid column labels* then?
Comment: Updated the answer with a screenshot.
Comment: So, probably they use it only for that specific Dynamic Data type of projects... Worth mentioning that in the documentation because is very confuse now as is... :(
Comment: In fact, attributes are just metadata. You can use it, as long as you make something with it somewhere else. In that case, they documented that they were using on DynamicData, but that doesn't mean anybody else is using it.
Comment: The description of the property in documentation is not clear. The documentation don't target specific users, so there are readers that never heard about Dynamic Data projects or the mysterious column labels...


Segmentation fault ao trocar system call the "int" para "syscall" em assembly x86 linux

Question: Quando eu mudo a system call de int $0x80 para syscall ou sysenter neste código:
    mov $4, %rax
    mov $1, %rbx
    mov $String1, %rcx
    mov $16, %rdx
    int $0x80

o programa acaba em segmentation fault. No GDB mostra:

Program received signal SIGSEGV, Segmentation fault.
  0x00000000f7ffdbe9 in ?? ()

Por que esta mudança está causando este impacto? Obrigado
Answer:
syscall é para x86_64
sysenter é para 32 bits
int 0x80 funciona para ambos

Isso é um resumo da mesma pergunta em:
https://stackoverflow.com/questions/12806584/what-is-better-int-0x80-or-syscall


How to form Cayley graph from group

Question: Define a Cayley graph as follows:
$G$ is finite group. $C \subseteq G$ such that $C$ does not contain identity element of $G$ and $g^{-1} \in C$ for all $g \in C$. Cayley graph $X(G,C)$ is formed with vertices $V(X)=G$, edges $E(X)=\{(a,b): a,b \in G, ab^{-1} \in C\}$.
a. Prove that the graph $X(C,G)$ is well-defined.
b. A graph is vertex transitive if $\text{Aut}(X)$ acts transitively on vertices. Show that $X(G,C)$ is vertex transitive.
Comment: You probably want to assume that $C$ is a generating set for $G$.
Answer: It is not clear to me what "proving the graph is well-defined" entails, since the definition does not involve any sort of actions or maps on equivalence classes. Perhaps it wants you to show that if the segment $(a,b)$ is an edge of $X(G,C)$ then so is $(b,a)$, or something (this follows from the hypothesis on $C$ that it is closed under taking inverses). I'll let a graph theorist comment.
For part (b), show that right-multiplication by any element $g\in G$ induces a graph automorphism on $X(G,C)$. First of all this is a bijection on the vertices, and second of all you want to show $(a,b)$ is an edge of $X(G,C)$ if and only if $(ag,bg)$ is an edge of $X(G,C)$, for all $g\in G$. The utility of this is that the group $G$ acts transitively on itself by (both left and right) multiplication, so to create an automorphism of $X(G,C)$ that sends vertex $a$ to the vertex $b$ (here with $a,b\in G$ arbitrary), just pick a $g\in G$ such that $ag=b$, i.e. consider right-multiplication by $a^{-1}b$.

How to form Cayley graph from group


Error when installing ipywidgets jupyterlab extension on windows 10. I get this error message generated. Any way to go about it?

Question: c:\users\shamsa\appdata\local\programs\python\python38-32\lib\site-packages (from stack-data->ipython>=4.0.0->ipywidgets) (2.0.5)
Requirement already satisfied: pure-eval in c:\users\shamsa\appdata\local\programs\python\python38-32\lib\site-packages (from stack-data->ipython>=4.0.0->ipywidgets) (0.2.2)
Collecting zipp>=3.1.0
  Using cached zipp-3.7.0-py3-none-any.whl (5.3 kB)
Requirement already satisfied: six>=1.5 in c:\users\shamsa\appdata\local\programs\python\python38-32\lib\site-packages (from python-dateutil>=2.1->jupyter-client<8.0->ipykernel>=4.5.1->ipywidgets) (1.16.0)
Collecting pywinpty>=1.1.0
  Using cached pywinpty-2.0.2.tar.gz (22 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Preparing metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [6 lines of output]

      Cargo, the Rust package manager, is not installed or is not on PATH.
      This package requires Rust and Cargo to compile extensions. Install it through
      the system's package manager or via https://rustup.rs/

      Checking for Rust toolchain....
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

My pip version is 22.0.3, python version 3.8.0
the error persists even though i installed (abd followed the instructions)from the link in the error message provided.
this is my cargo version
PS C:\Users\Shamsa> cargo -V
cargo 1.59.0 (49d8809dc 2022-02-10)

and installed rustup
PS C:\Users\Shamsa> rustup show
Default host: x86_64-pc-windows-msvc
rustup home:  C:\Users\Shamsa\.rustup

stable-x86_64-pc-windows-msvc (default)
rustc 1.59.0 (9d1b2106e 2022-02-23)

UPDATE ON THE ERROR
i haven't changed anything, just ran the command pip install ipywidgets  again and it generated this error
Collecting pywinpty>=1.1.0
  Using cached pywinpty-2.0.2.tar.gz (22 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Preparing metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [24 lines of output]
      💥 maturin failed
        Caused by: Cargo metadata failed. Does your crate
compile with `cargo build`?
        Caused by: `cargo metadata` exited with an error:
    Updating crates.io index
      warning: spurious network error (2 tries remaining): failed to read data: The server returned an invalid or unrecognized response
      ; class=Os (2)
      warning: spurious network error (1 tries remaining): failed to read data: The server returned an invalid or unrecognized response
      ; class=Os (2)
      error: failed to get `pyo3` as a dependency of package `pywinpty v2.0.2 (C:\Users\Shamsa\AppData\Local\Temp\pip-install-mrl995n0\pywinpty_2079790bb492449abb31454ef2581cb6)`

      Caused by:
        failed to load source for dependency `pyo3`

      Caused by:
        Unable to update registry `crates-io`

      Caused by:
        failed to fetch `https://github.com/rust-lang/crates.io-index`

      Caused by:
        failed to read data: The server returned an invalid or unrecognized response
        ; class=Os (2)
      Error running maturin: Command '['maturin', 'pep517'hamsa\\AppData\\Local\\Temp\\pip-modern-metadata-_naf8t69'hamsa\\AppData\\Local\\Temp\\pip-modern-metadata-_naf8t69', '--interpreter', 'c:\\users\\shamsa\\agrams\\python\\python38-32\\python.exe']' returned non-zerocal\\programs\\python\\python38-32\\python.exe']o exit status 1.
      Checking for Rust toolchain....                                                                      odern-metadata-_naf8t69 --interpreter c:\users\sh
      Running `maturin pep517 write-dist-info --metadata-directory C:\Users\Shamsa\AppData\Local\Temp\pip-mirectory C:\Users\Shamsa\AppData\Local\Temp\pip-modern-metata\local\programs\python\python38-32\python.exe`\programs\python\python38-32\python.exe`
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.kely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

Comment: Does this answer your question? [How to add Cargo to PATH required for pywinpty when deploying to Heroku?](https://stackoverflow.com/questions/72212383/how-to-add-cargo-to-path-required-for-pywinpty-when-deploying-to-heroku)
Answer: Have you checked that cargo is on your PATH as stated by the error message?
Add to the PATH environment variable like so:

On the Start menu, right-click Computer.
On the context menu, click Properties.
In the System dialogue box, click Advanced system settings.
On the Advanced tab of the System Properties dialogue box, click Environment Variables.
In the System Variables box of the Environment Variables dialogue box, scroll to Path and select it.
Click the lower of the two Edit buttons in the dialogue box.
In the Edit System Variable dialogue box, scroll to the end of the string in the Variable value box and add a semicolon (;).
Add the path to your cargo installation after the semicolon.
Click OK in three successive dialogue boxes, and then close the System dialogue box.

If not, make sure it is installed from here as stated in the message. The link contains instructions for doing so.
If the issue persists, try upgrading pip via,
pip install --upgrade pip

Then run the command,
pip install ipywidgets

As suggested by these answers to a similar question.
If the error message persists, or changes, please update your answer.
It would also be useful if you provided your Python and pip versions.
Comment: My pip version is 22.0.3 and python 3.8.0, installed rust using the link provided and followed instructions (used default instead of customized), problem still persists


Container group results in a "No more IP addresses available on network" error

Question: I'm unable to create the container group like the one in the screenshot below:

I get the following error:
<code>Failure message: Resource CREATE failed: Error: Resource CREATE failed:
Error: Resource CREATE failed: IpAddressGenerationFailureClient: No more IP
addresses available on network a2e7d252-f230-4136-b809-6ba569cf4770.
</code>
By setting a unique host name for the container group, the group should then be accessible using that name without the requirement of allocating a public IP address to the group, correct?
Thus, this error message doesn't make sense to me. Any idea what's wrong?
Answer: Thanks for posting. I'm from the IBM Containers team and we noticed this as well starting around 4:30am this morning eastern time. We have resolved the issue with IP allocations and you should have success again!


zipfile is leaving the last few lines off my file - why?

Question: So I'm having an issue with using the zipfile module in Python. Currently when I try to compress a KML file to create a new KMZ file I'm missing the last few lines. It doesn't seem to matter how long the KML is. I assume this is because zipfile isn't writing the last zipped block.
kmz = zipfile.ZipFile(kmzPath , 'w')
kmz.write(kmlPath, 'CORS.kml', zipfile.ZIP_DEFLATED)

And yes before you ask I have imported zlib to do the compression. I've tried to use zlib at the lower level too but have the same issue. I'm stuck.
Any ideas?
Answer: Make sure that you called
kmz.close()

after the .write(...) command, otherwise the full contents of the file won't be flushed to disk. To make sure this happens automatically, always use the with context manager, as the file will be closed when the loop is exited:
with zipfile.ZipFile(kmzPath, 'w') as kmz:
    kmz.write(kmlPath, 'CORS.kml', zipfile.ZIP_DEFLATED)

Comment: Hey yeah alright. Thats worked. I usually use **with** as well but got an _AttributeError: ZipFile instance has no attribute '__exit__'_ so thats why it was left out. Since I almost never use *.close() I forgot. Bugger. Thanks!
Answer: This is just a guess, but according to the zipfile documentation:

You must call close() before exiting your program or essential records will not be written.

You don't indicate that you are in fact calling kmz.close() - could that be the problem?


Content Type Segmentation

Question: I need to know if there is a way to create a content type and within the content type to create a field which this field should be segment.
For Example :
at the beginning i will have an image,  this will be the default image.
and in case i will choose an option like to display only for authenticated user another image field will be opened , and in the display all unauthenticated users will see the default image and authenticated users will see the second image.
Is there something like this ?
Thanks
Comment: are you using 7 or 8?
Comment: I am using on 7 But i will be glad to hear also about 8
Answer: You can create a template for that specific content type like
<code>node--yourcontenttype.tpl.php
</code>
and inside you can check for the user roles like so
<code>// Load the currently logged in user.
global $user;

// Check if the user has the 'editor' role.
if (in_array('editor', $user->roles)) {
  // print one image
} else {
  //print the other one
}
</code>
Comment: But in this situtation if i have multi segmentation the ui will be very long. Also in case i am pulling this data in a view i need to create a nother template for that view

Content Type Segmentation


How to make the node author's email show up as a replacement token in a Rules Action?

Question: I have set up a rule that is as follows:

Rules Event: After saving new content of type Article.
Rules Conditions: User has role(s), with role = Authenticated user.
Rules Actions: Send mail to all users of a role, with role = Administrator.

When anyone adds an article to the site, all the admins are notified and I have used token replacements for the email fields like so:

Mail Subject: [node:author] has just created a piece of content entitled "[node:title]"
Message Body:
[node:author] has just created a piece of content entitled "[node:title]"
You can see the article here and proof read: [node:edit-url]
The article is here: [node:url]

This all works perfectly, however I want to also add the author of the node into this email so that any of the admins can email this person if they need to. I cannot work out how to get the author's email into the email body as it doesn't seem to show up in replacement patterns.
Anyone any idea how I can achieve this?
Answer: It is not listed among the replacement tokens, but you can use the [node:author:mail] token.
Answer: The Rules module is great, but it also has its hidden features ... Yes the "token for the eMail Id of the node author" is available to use it in the Rules Action (as in this question here). However you won't find it by simply expanding the typical "REPLACEMENT PATTERNS"-link that show up by default.
Instead, whenever you're looking for some token that at first doesn't seem to be available, you should try to use the Switch to data selection button as in this screenprint:

Then select "node...(Created content)" from the Data selector selection list (or if you know part of what you're looking for just start typing "node:"). After doing so, the list of possible values (= tokens starting with "node:") will change and start to show (dozens of) other values such as:

node:nid (Node ID)
node:type (Content Type)
node:author... (Node Author)
node:comment (Comments allowed)
node:comments... (Comments)

In the above list, note the ones that have a "...": those are the ones that, after you select any of them, will bring up yet another list of tokens that start with what you selected. So if you select "node:author... (Node Author)", it'll show (many) other values (some with yet another "..."), such as:

node:author:uid (User ID)
node:author:name (Name)
node:author:mail (Email)
node:author:roles... (User roles)

So there you are: using the drill-down approach as shown above, node:author:mail (Email) is what you're looking for. All that's needed now, is to select it from this list. Though in this case there is no more Label and Description for the token, you only have what's shown between "(" and ")" to decide about which token to select.
PS: If you don't find what you're looking for (after using the Switch to data selection button), you can always return to the previous display by using the Switch to the direct input mode button.


How to find out the amount of SWAP an AWS RDS instance has?

Question: How to find out the amount of SWAP an AWS RDS instance has?
In EC2 one can SSH and find out the amount of SWAP an instance has but how does one find out is RDS?
The purpose is to configure SWAP usage monitoring for RDS in AWS Cloudwatch
Answer: It depends on the RDS database you use.  The bad news is if you're using Aurora with MySQL compatibility it doesn't have a swap metric.  For the other RDS Linux types, you can find Swap Usage in the Monitoring-> CloudWatch section.

According to the Troubleshooting guide linked below:

To monitor swap memory, enable Enhanced Monitoring to review metrics in intervals with a granularity of as little as one second. Enhanced Monitoring collects statistics at the host level, and CloudWatch collects data from the hypervisor level every 60 seconds. You can use Enhanced Monitoring to identify increases or decreases that occur for only one second and to see the CPU and memory that are used by individual processes.

References
Aurora Monitoring
RDS Monitoring
Troubleshoot RDS Swap Memory


Does the "C" code algorithm in RFC1071 work well on big-endian machine?

Question: As described in RFC1071, an extra 0-byte should be added to the last byte when calculating checksum in the situation of odd count of bytes:

But in the "C" code algorithm, only the last byte is added:

The above code does work on little-endian machine where [Z,0] equals Z, but I think there's some problem on big-endian one where [Z,0] equals Z*256.
So I wonder whether the example "C" code in RFC1071 only works on little-endian machine?
-------------New Added---------------
There's one more example of "breaking the sum into two groups" described in RFC1071:

We can just take the data here (addr[]={0x00, 0x01, 0xf2}) for example:

Here, "standard" represents the situation described in the formula [2], while "C-code" representing the C code algorithm situation.
As we can see, in "standard" situation, the final sum is f201 regardless of endian-difference since there's no endian-issue with the abstract form of [Z,0] after "Swap". But it matters in "C-code" situation because f2 is always the low-byte whether in big-endian or in little-endian.
Thus, the checksum is variable with the same data(addr&count) on different endian.
Comment: Isn't the data in network byte order already when the checksum is calculated?
Comment: AFAIK you only care about endianess with C ( and C++ ) when you deal with the bitfields, everything else is supposed to be a compiler problem.
Answer: I think you're right.  The code in the RFC adds the last byte in as low-order, regardless of whether it is on a litte-endian or big-endian machine.
In these examples of code on the web we see they have taken special care with the last byte:
https://github.com/sjaeckel/wireshark/blob/master/epan/in_cksum.c
and in
http://www.opensource.apple.com/source/tcpdump/tcpdump-23/tcpdump/print-ip.c
it does this:
if (nleft == 1)
    sum += htons(*(u_char *)w<<8);

Which means that this text in the RFC is incorrect:

Therefore, the sum may be calculated in exactly the same way
          regardless of the byte order ("big-endian" or "little-endian")
          of the underlaying hardware.  For example, assume a "little-
          endian" machine summing data that is stored in memory in network
          ("big-endian") order.  Fetching each 16-bit word will swap
          bytes, resulting in the sum; however, storing the result
          back into memory will swap the sum back into network byte order.
Comment: Thank you! Some more details are added in my description, by which I hope it will help you understand my point:)
Answer: The following code in place of the original odd byte handling is portable (i.e. will work on both big- and little-endian machines), and doesn't depend on an external function:
if (count > 0)
{
    char buf2[2] = {*addr, 0};
    sum += *(unsigned short *)buf2;
}

(Assumes addr is char * or const char *).


Deploying to live and available modules

Question: In Drupal 8 you can export configuration and move that to a production server. In core.extensions.yml there is an exported list of the enabled modules. If on development I have devel and other auxiliary modules installed these are added in that file but I do not want that to be part of the production environment.
Is there a switch to do that? How can master module from Drupal 7 replicated here?
Comment: Well, obviously you have a flow in your workflow. I think you should look at environment indicator module https://www.drupal.org/project/environment but it's not D8-ready yet.
Comment: In Drupal 7 there is `master` module (https://www.drupal.org/project/master) that takes care of enabling and disabling modules per environment. It actually works really well with `features` and `strongarm`. I am looking to see if I am missing something and something like that is possible with configuration management or a solution that replicates that behaviour.
Comment: What about the config_split module?
Is this something that can cover your use case?
Answer: I think there is not really a good option for this yet.
It's tricky, because you can't just override the config and have those modules enabled since they also provide their config (which would and install/uninstall processes that can't be skipped. In fact, providing config overrides for core.extension is explicitly prevented.
Maybe someone will come up with a good way to do this, I currently don't really know how that should work.
Comment: I guess it makes sense to disable modules according to the deployment script that one uses. In Acquia there are cloud hooks that can run only on production deployments that could disable some modules.

Deploying to live and available modules


Hypergeometric Distribution - Probability of Teams Ending in Same Group - Need help with part b)

Question: No answers to refer to. I would be really greatful if someone could take a look if my procedure looks fine to solve this problem. Also, for part b) I got a bit confused in regards to how to proceed so any tips would be amazing! Thanks in advance for your time!
18 teams, 5 of which are professional, take part in a football tournament. At the beginning of the tournament the 18 teams are randomly divided into two groups (A and B) of 9 teams each. Determine the probabilities of the following events:
a) all professional teams end up in one group
It looks to me that this is a Hypergeometric Distribution as we have no replications and order doesn't matter. From here it follows that:
$N=18 $
$K=5$ $n=9$ $k=5$
By using: $P(k)=[\binom{K}{k}\binom{N-K}{n-k}]:\binom{N}{n}$ and plug in the above values we get:
$P(5)=[\binom{5}{5}\binom{18-5}{9-5}]:\binom{18}{9}=0.01470$
b) two of the professional teams are in one group, and the other tree professional teams are in the other group.
So basically, we use the formula from above, just with different values.
This time we have: $N=18 $
$K=5$ $n=9$ $k=2$
$P(2)=[\binom{5}{2}\binom{18-5}{9-2}]:\binom{18}{9}=0.03529$
However, I'm a bit confused now: do I just do the same for the other condition (that 3 teams are in the other group)? Or perhaps just 1 - P(2)? Or is it something different?
Answer: Your answers are almost okay.
Concerning a)
Your answer is actually the probability that all professional teams end up in team $A$ and also equals the probability that all professional teams end up in team $B$.
But needed is the probability that all professional teams end up in team $A$ or end up in team $B$.
These events are mutually exclusive and equiprobable so your answer will be okay if it is multiplied by $2$.
In your interpretation $9$ teams are selected out of $18$ and the selected teams (among which $5$ are professional and $13$ are not) will receive label $A$ (or - if you like that better - label $B$).
b) similarly the answer is here: $$\frac{\binom52\binom{13}3+\binom53\binom{13}2}{\binom{18}5}$$i.e. the probability that $2$ professional teams receive label $A$ plus the probability that $3$ professional teams receive label $A$.
In both cases $2$ of the professional teams are in one group and the other $3$ are in the other group.
Comment: Thank you so much for explaning! Makes sense now :)
Comment: You are very welcome.


sendmail only relaying messages bound for one specific domain

Question: I was wondering if you could please help me with what could be a simple problem but i cant seem to figure it out.
We have a few centos servers running sendmail (all internal servers on the local lan)- with a very simplistic sendmail configuration (all default) except for a relay everything to our exchange server option i.e DSourexchangeserver
Now what i want to do is have these centos servers sendmail configurations ONLY relay emails destined for our companys domain i.e email@example.com
I do not want mail relayed to anywhere else.
Is there anyway to get sendmail to check mails being passed to it and only relay ones on to our exchange server that meet the requirement of being destined for our companies domain and stop everything else ?
Answer: See:
http://www.sendmail.org/tips/relaying

The simplest approach is to list the domains you are willing to relay
  in the file /etc/mail/relay-domains. Anything listed in this file will
  be accepted for relaying. N.B.: Sendmail must be restarted after this
  file is modified.

This and other tips on that page should get you started.  Otherwise, you may want to check into SMTP AUTH if you need to control who can relay email.
Comment: Relay-domains is what you want. Put your companies name in there and disable all other relaying.
Answer: You do not need a milter for that.  You can do it via sendmail.mc. Add these lines in your sendmail.mc:
#Define the smart host
define(`SMART_HOST', `exchange server here')dnl

#Define a class of domains we want to relay to the smart host
C{Exchange} example.com example.org

#Decide whether to delete outgoing email or not
LOCAL_RULE_0
#test the behavior of your system to see if you need the following line
R$* < @ $=w . > $*              $#OK
R$* < @ $={Exchange} . > $*     $#OK
R$*                             $#local $: bit-bucket

bit-bucket should be aliased to /dev/null in /etc/mail/aliases:
bit-bucket: /dev/null

Remember to rebuild sendmail.cf from the sendmail.mv file afterwards and restart sendmail. I do not know how this is done in CentOS. Debian's sendmailconfg has made me a little lazy. Also remember that sendmail rules are divided with tabs and not spaces so do not copy-paste. Type by hand and separate the "left" and "right" parts after LOCAL_RULE_0 with tabs.
Comment: This looks good adamo, and looks what i want to do but when i make the changes - regenerate sendmail - then start the daemon i get an error saying :
451 4.0.0 /etc/mail/sendmail.cf: line 63: fileclass: cannot open 'domain_i_want_mail_sent_to.com': No such file or directory

Is there a file i have to create ?

Thanks for your help
Comment: My mistake! Change F{Exchange} to C{Exchange}. C stands for class definition within the configuration file, while F stands for class definition from an outside file. I've edited my answer accordingly.
Comment: i have bit more time to work on this problem now - its so close to working but doesnt if i run the ruleset it looks like it works perfectly ie :
Comment: > 3,0 email@example.com
canonify           input: me @ mydomain . com
Canonify2          input: me < @ mydomain . com >
Canonify2        returns: me < @ mydomain . com . >
canonify         returns: me < @ mydomain . com . >
parse              input: me < @ mydomain . com . >
Parse0             input: me < @ mydomain . com . >
Parse0           returns: me < @ mydomain . com . >
ParseLocal         input: me < @ mydomain . com . >
ParseLocal       returns: $# OK
parse            returns: $# OK
Comment: Thanks adamo! , however now i get the following in maillog whenever i try to send an email anywhere :

Jan 16 10:33:39 myserver sendmail[3213]: q0FLXd3Z003213: from=myuser, size=49, class=0, nrcpts=1, msgid=<email@example.com>, relay=myuser@localhost
Jan 16 10:33:39 myserver sendmail[3214]: q0FLXdMU003214: SYSERR(root): buildaddr: no user
Jan 16 10:33:39 myserver sendmail[3213]: q0FLXd3Z003213: email@example.com, ctladdr=myuser (4686/100), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30049, relay=[127.0.0.1] [127.0.0.1], dsn=5.0.0, stat=Service unavailable
Comment: maybe it has something to do with the bit-bucket alias ? i didnt actually have an /etc/mail/aliases file so i made it and just added
bit-bucket: /dev/null
is that ok ?
Comment: > 3,0 firstname.lastname@example.com
canonify           input: me @ gmail . com
Canonify2          input: me < @ gmail . com >
Canonify2        returns: me < @ gmail . com . >
canonify         returns: me < @ gmail . com . >
parse              input: me < @ gmail . com . >
Parse0             input: me < @ gmail . com . >
Parse0           returns: me < @ gmail . com . >
ParseLocal         input: me < @ gmail . com . >
ParseLocal       returns: $# local $: bit-bucket
parse            returns: $# local $: bit-bucket

this output looks like the rules should work fine - but they dont :(
Comment: If it is not in _/etc/mail/aliases_, then it must be in _/etc/aliases_. After editing the aliases file you have to rebuild the aliases database by running _newaliases_
Comment: Im not sure what to do , i put it into /etc/aliases and rebuilt it using newaliases and thats what its looking at but email to anywhere doesnt work.
Comment: somehow i think that local rule syntax R$ blah is blocking everything
Comment: [root@myserver ]# /usr/sbin/sendmail -bt
ADDRESS TEST MODE (ruleset 3 NOT automatically invoked)
Enter
> 0 firstname.lastname@example.com
parse              input: me . lastname @ mydomain . com
Parse0             input: me . lastname @ mydomain . com
Parse0           returns: me . lastname @ mydomain . com
ParseLocal         input: me . lastname @ mydomain . com
ParseLocal       returns: $# local $: bit-bucket
parse            returns: $# local $: bit-bucket
Comment: Exactly. That is because you have not put in the C{Exchange} line the domains you are interested in being relayed to your Exchange server. You should _substitute_ example.com and example.org with your domains.
Comment: Yeah i did swap out the example.com and example.org for my domain\s
Comment: could i be because i havent done the proper tabs in the mc ?
Comment: Ive tried going through it line by line (the local rule) and it seems that first line of rules the one with $=w in it - if that line is present all email doesnt work.
Comment: Question: According to the test it should be working, but the actual run does not, right? Do you see any error message in the logs? Have you restarted the sendmail process?
Comment: You run the test as 3,0 email@example.com Keep in mind $=w contains the _local_ names, the one the host considers that it is supposed to manage. These should be sent to the Exchange server too. However if removing this line works for you, fine too.
Answer: The problem with relay-domains is that it permits relaying if the sending system is in that domain.
Using an access database may be the solution. In it put:
To: mycompaniesdomain.com    RELAY
Be sure to have all other relay options off. Sendmail is a complex beast and it may be good to post your mc file.
Comment: mc is too long to post but here are the relevant parts i added from   adamos suggestions :

`define(`SMART_HOST', `myexchangeserver')
C{Exchange} mydomain.com
LOCAL_RULE_0
R$* < @ $=w . > $*  $#OK
R$* < @ $={Exchange} . > $* $#OK
R$*    $#local $: bit-bucket`
Comment: dont worry about the backtick syntax so much - that is correct - i just dont know how format the comment correctly with mini-markdown.
However any help with the actual syntax of what im doing would be much appreciated.
Answer: This is how I set it up :
1 sendmail server that all email from nix machines goes to and gets relayed to the exchange server depending on where the email is bound for.
All clients sendmail configs have a DS option for the server above.
On the 1 sendmail server (that all your sendmail configs will point to for the DS option that will act as the filter do the following :

Make sure in sendmail.mc under /etc/mail it has the : Feature('mailertable', 'hash -o /etc/mailertable.db' dnl line in it.

Comment out the line that says DAEMON_OPTIONS(``Port=smtp,Addr=127.0.0.1, Name=MTA')dnl (so that it can relay for all machines - obviously this wouldn't be a good idea for a machine that has a public IP - but that's not what I'm doing here)

vi mailertable and put in the following line : yourdomain.com ESMTP:[yourexchangeserverip]

Create a file under /etc/mail called relay-domains and put in the following line : yourdomain.com

Run m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf

Run makemap hash /etc/mail/mailertabledb < /etc/mail/mailertable

start or restart the sendmail daemon , /etc/init.d/sendmail restart

Then on all the machines you want to have email filter for just go into the sendmail.cf and set the DS option to the ip or hostname of your server above. Then restart sendmail.


Repeating a call to a function to produce current time difference in Swift playground

Question: In a swift playground, why does this code not update. I am trying to get this to output the exact time (in the future to have a countdown) but I can't get the current time to update, it just repeats the same time difference several times.
// initialize the date formatter and set the style
let formatter = NSDateFormatter()
formatter.timeStyle = NSDateFormatterStyle.MediumStyle
formatter.dateStyle = NSDateFormatterStyle.ShortStyle

// get the date time String from the date object
let currentDate = formatter.stringFromDate(currentDateTime)

let dateMakerFormatter = NSDateFormatter()
dateMakerFormatter.calendar = userCalendar
dateMakerFormatter.dateFormat = "mm/dd/yy, hh:mm:ss a"
let endTime = dateMakerFormatter.dateFromString("01/08/16, 11:00:00 PM")
let startTime = dateMakerFormatter.dateFromString(currentDate)
let hourMinuteComponents: NSCalendarUnit = [.Month,.Day, .Hour, .Minute, .Second]
let timeDifference = userCalendar.components(
    hourMinuteComponents,
    fromDate: startTime!,
    toDate: endTime!,
    options: [])
timeDifference.month
timeDifference.day
timeDifference.hour
timeDifference.minute
timeDifference.second
func printTimeDifference() {
    print("\(timeDifference.month) Months, \(timeDifference.day) Days, \(timeDifference.minute) minutes, \(timeDifference.second) seconds")
}

var done = 0
//printTimeDifference()
var counter:Int = 0

while done != 10 {
    sleep(1)
    printTimeDifference()
    done++
}

I may have put too much code in this, but the major part would be the loop. How come when I call printTimeDifference() it doesn't print the current difference to the second, it just prints what the current date was at (I'm assuming) the first call. To the best of my knowledge the variables live and die with the function, and each time I call the function it should be recreating the variables, i.e getting the actual current difference in time. My speculation is this could have something to do with Strong and Weak links but I am relatively new to swift and have done more in C. Any help is appreciated.
Comment: That's because `timeDifference` is computed only once, before the loop.
Answer: In your question you write:

To the best of my knowledge the variables live and die with the
  function, and each time I call the function it should be recreating
  the variables

This is true, but only if the variable is created within the function. In your case you do not create a new variable inside the function printTimeDifference and you are using already created timeDifference which was once assigned a value. Naturally after the function returns, this variable will not be deleted, as created outside the function. And when you next time to call this function it is used the same variable with the same value. It is one single variable timeDifference
You get the desired effect if the transfer of the creation of all necessary variables into the function printTimeDifference like:
func printTimeDifference() {
    // Here your code with all variables creation
    ...
    // with this variable you need to print
    let timeDifference = userCalendar.components(
        hourMinuteComponents,
        fromDate: startTime!,
        toDate: endTime!,
        options: [])
    print("\(timeDifference.month) Months, \(timeDifference.day) Days, \(timeDifference.minute) minutes, \(timeDifference.second) seconds")
}


Who assigns private IP addresses?

Question: Suppose I have a router and a local network, can I freely assign my devices private IP addresses (as many as I want, up till there are no more private IP addresses left)? Who decides how many private IP addresses I can have?
Comment: I would be happy to sell you some PABs if you need more ;)
Answer: They are PRIVATE. If you wire a house, who decides how many doors you can have?
The IP address spaces that are NOT USED ON THE INTERNET are defined in an RFC. Private addresses are part of that (actually THE part of it) and are in there.
You can use whatever you want from that. There is no authority. They are not existing on the internet.
Obviously if you VPN etc. to another entity, they can do the same, so you better coordinate.
Comment: @ryn take a note of https://en.m.wikipedia.org/wiki/Private_network feel free to assign so many ips as you like, but remind to choose the correct subnet.

Who assigns private IP addresses?


Printing invoice fromAndroid Tablet

Question: How to connect the thermal printer to Android tablet for getting print my invoice.
if any one know please give me a procedure and code samples for taking print from Tablet..
Thanks a lot.
Answer: In market no of thermal printer are available like EPSON, Casio, STAR or Chinese printers. These printers have their own SDK. By simply import that sdk in project you can print from the application.

Printing invoice fromAndroid Tablet


Multiple Azure Private DNS Zones

Question: I was wondering is it possible to have multiple Private DNS Zones in a hub and spoke topology, where we have a separate DNS zone for an application (splint), but splint will be retired in a year, so we are creating a DNS zone separate for all other Azure apps and would like a separate DNS zone for everything else in the connectivity Spoke. If we had two how would they talk to each to resolve addresses or would we just "link" the vnets to both DNS zones, but if we did that where would the privatelink.microsoft.com (private endpoint DNS entry be hosted)
Sorry if this seems like a brain dump just trying to understand
Comment: Show what you have configured (trying to configure) and the problem. By configure, list the zone details. As written your question is too confusing and will lead to guessing.
Comment: @JohnHanley thanks and apologies it does sound a bit random now I read it back. We have a dns zone configured in splint subscription, we want to set up another private dns zone in the hub subscription, can we have multiple vnets linked to both zones and can the two zones communicate with each other?
Comment: DNS requires facts/details. Descriptions do not help.
Answer: If your hub and spoke are completely isolated it should work fine to have separate private DNS zones for the same Azure service. However it doesn't sound like that's your scenario.
This page has several quotes that have convinced me not to try to have two different private DNS zones for the same Azure service tied with VNET links to the same VNET.

Important A single private DNS zone is required for this
configuration. Creating multiple zones with the same name for
different virtual networks would need manual operations to merge the
DNS records.

Important If you're using a private endpoint in a
hub-and-spoke model from a different subscription or even within the
same subscription, link the same private DNS zones to all spokes and
hub virtual networks that contain clients that need DNS resolution
from the zones.

Multiple Azure Private DNS Zones


Using the Python exception hierarchy

Question:
Python offers an extensive list of built-in exceptions.
It appears to me that most of the built-in exceptions are intended to be raised only by the interpreter or by Python's built-in functions.
So, which of these built-in exceptions should be raised in user code? Does the guidance differ between Python 2.7 and 3.x?
Coming from .NET, I believed this to be an important question. For .NET, Microsoft provides explicit guidance for what exceptions to throw and not to throw in Using Standard Exception Types.
For Python, it seems to me intuitively and from examples that I have seen that the following built-in exceptions would be appropriate to raise in user code:
IndexError
LookupError
NotImplementedError
TypeError
ValueError

...but these would not as each indicates a type of system failure:
ArithmeticError
    FloatingPointError
    OverflowError
    ZeroDivisionError
MemoryError
OSError

Comment: Do you ask for opinions or stats? Besides the very link you provide says: "*User code can raise built-in exceptions. This can be used to test an exception handler or to report an error condition "just like" the situation in which the interpreter raises the same exception; [...]*". It just makes sense, that those used by the intepreter are there, because they are needed anyways. I really have troubles finding the goal of this question. The only sense is to run some grep or something on some large projects.
Comment: This is an opinion, but... IMO it's python, everything is dynamic, it's like cloud of electrons, there no absolutely wrong or right, there are better and worse approaches, which when you apply them will turn out right or wrong, good or bad. I don't understand why would you not throw Arithmetic exceptions if you were implementing e.g. vector class. The latter part of the quote says "*[...] but beware that there is nothing to prevent user code from raising an inappropriate error.*" The documentation explicitly says, user code might use them exceptions, and even might abuse them.
Comment: Not adding this as an answer since it's just my opinion, but other than possibly DeprecationWarning I would just stick to subclassing Exception with your own custom exceptions (it's only two lines of code, after all)
Comment: @luk32: Please see my edit and my motivation for asking. I did not intend this question to be opinion-based.
Comment: @Moritz: Your answer could potentially lead to another question: *"When should I define my own exception type instead of using a built-in exception type?"*
Comment: @luk32: Yes, we can do all sort of inadvisable things as programmers. That is why in part SO exists...to help its users distinguish between good and bad practices. Just because something is *possible*, doesn't mean it is a *good idea*.
Answer: The Python programmer is given a lot of flexibility with respect to exceptions that can be raised from user code. However, that flexibility doesn't mean that "anything goes." From the version 3 documentation for the Python standard library, the article 5. Built-in Exceptions offers this general guidance.
On what exceptions a programmer can raise:

User code can raise built-in exceptions. This can be used to test an
exception handler or to report an error condition "just like" the
situation in which the interpreter raises the same exception; but
beware that there is nothing to prevent user code from raising an
inappropriate error. (emphasis mine)

On programmer-defined exceptions:

The built-in exception classes can be subclassed to define new
exceptions; programmers are encouraged to derive new exceptions from
the Exception class or one of its subclasses, and not from
BaseException. More information on defining exceptions is
available in the Python Tutorial under User-defined Exceptions.

Clause 5.1. Base classes suggests that base class exceptions should not typically be raised:

The following exceptions are used mostly as base classes for other
exceptions.
BaseException, Exception, ArithmeticError, BufferError, LookupError

Instead, per the guidance in Clause 5.2. Concrete exceptions, it is concrete exceptions that should typically be raised:

The following exceptions are the exceptions that are usually raised.
AssertionError, AttributeError, EOFError, ... OSError, ..., ZeroDivisionError

So, for instance, instead of raising ArithmeticError, consider raising one of its derived classes: FloatingPointError, OverflowError, and ZeroDivisionError. (Or, perhaps a class that you derive from ArithmeticError.)
(And see clause 5.2.1. OS exceptions for more on OSError.)
And finally, on warning messages from the article 29.5. warnings — Warning control:

Warning messages are typically issued in situations where it is useful
to alert the user of some condition in a program, where that condition
(normally) doesn't warrant raising an exception and terminating the
program. For example, one might want to issue a warning when a program
uses an obsolete module.
...
User code can define additional warning categories by subclassing one
of the standard warning categories. A warning category must always be
a subclass of the Warning class.
Comment: The guidance is quite hard to follow, but the answer is obviously more correct than mine was.
Comment: @FilipHaglund By "hard to follow," I'm not sure if you are referring to the Python documentation itself, or my attempt to summarize it. That said, the guidance given in the Python docs appears to me to be looser and less precise than that given by Microsoft for .NET programmers. (For the latter, see the linked article in my question.)
Comment: The Python documentation itself. That rule is complicated enough that I'm going to have trouble remembering it for future code reviews.

Using the Python exception hierarchy


Remove numbers found in string column

Question: What would be the SQL to remove all numbers found in an otherwise string column using Sqlite (an Oracle example would be appreciated too)?
Example : I would like to remove all numbers from entries like this :
291 HELP,1456 CALL
Expected output:
HELP,CALL
edit: I have edited the question because it is not only from one entry that I want to remove numbers but many of them.
Answer: Either you do it in the language, you embedded sqlite, or you use this SQLite code, that removes all numbers:
UPDATE table SET column = replace(column, '0', '' );
UPDATE table SET column = replace(column, '1', '' );
UPDATE table SET column = replace(column, '2', '' );
UPDATE table SET column = replace(column, '3', '' );
UPDATE table SET column = replace(column, '4', '' );
UPDATE table SET column = replace(column, '5', '' );
UPDATE table SET column = replace(column, '6', '' );
UPDATE table SET column = replace(column, '7', '' );
UPDATE table SET column = replace(column, '8', '' );
UPDATE table SET column = replace(column, '9', '' );

Comment: Some other ways of achieving this: http://stackoverflow.com/questions/13240298/remove-numbers-from-string-sql-server
Answer: Using TRANSLATE and REPLACE
SQL> WITH DATA AS(
  2  SELECT '291 HELP' str FROM dual UNION ALL
  3  SELECT '1456 CALL' str FROM dual
  4  )
  5  SELECT REPLACE(translate(str, '0123456789', ' '), ' ', NULL) str
  6  FROM DATA
  7  /

STR
---------
HELP
CALL

SQL>

Using REGEXP_REPLACE
SQL> WITH DATA AS(
  2  SELECT '291 HELP' str FROM dual UNION ALL
  3  SELECT '1456 CALL' str FROM dual
  4  )
  5  SELECT trim(regexp_replace(str, '[0-9]+')) str
  6  FROM DATA
  7  /

STR
---------
HELP
CALL

SQL>

POSIX character class
SQL> WITH DATA AS(
  2  SELECT '291 HELP' str FROM dual UNION ALL
  3  SELECT '1456 CALL' str FROM dual
  4  )
  5  SELECT trim(regexp_replace(str, '^[[:digit:]]+')) str
  6  FROM DATA
  7  /

STR
---------
HELP
CALL

SQL>

Perl-extensions
SQL> WITH DATA AS(
  2  SELECT '291 HELP' str FROM dual UNION ALL
  3  SELECT '1456 CALL' str FROM dual
  4  )
  5  SELECT trim(regexp_replace(str, '\d+')) str
  6  FROM DATA
  7  /

STR
---------
HELP
CALL

SQL>

Comment: ERROR: function regexp_replace(text, unknown) does not exist
Comment: @Luffydude That's not an Oracle error, any Oracle error starts with `ORA-` error code followed by error message. Post your use case with the Oracle version and explain what you are actually trying to do.
Answer: select '''' || regexp_replace('123 help 321', '\d+') || '''' from dual;

Comment: It will always have a space on both sides, you need to trim the spaces.

Remove numbers found in string column


Can I run a two-factor ANCOVA analysis with two continuous independent variables?

Question: I have a dataset that includes in situ measurements of:
Dependent variable- growth rates (continuous)
Independent variable - temperature (continuous)
Independent variable - food concentration (continuous)
and I want to test the effect of food concentration on growth rates, while accounting for the different temperatures (study organism is known to grow faster at higher temperatures). Can I do an ANCOVA analysis with two continuous (i.e. not categorical) independent variables? If not, what is an alternative analysis/method to statistically account for temperature?
Note: It's been suggested that I run an ANOVA with an interaction term between temperature and food concentration, but I'm not convinced that this sufficiently standardizes growth rates to temperature rather than testing any relationships between temperature and food concentration. Is ANOVA actually the right choice?
Thanks!
Answer: You can definitely do this, but if there are no categorical predictors then it's just called multiple regression.
Comment: Good to know, thanks! So, just to make sure I understand, you're confirming that running a multiple regression with food concentration and temperature will statistically 'normalize' growth rates to temperature and then test the effect of food concentration? I'm essentially looking for a growth/degree that I can test against food concentration.
Comment: @user182007 Yes, the estimated slope for food concentration in the multiple regression will represent the change in temperature per unit change in concentration, while "[controlling for](https://stats.stackexchange.com/questions/17336/how-exactly-does-one-control-for-other-variables?noredirect=1&lq=1)" growth rate.
Comment: Thanks again, that's a good way to explain it. Sorry for being a needy OP, but it seems like I would actually want a slope that represents the change in **growth** per unit change in concentration, while "controlling for" **temperature**, slight reversal of what you described for the multiple regression. Is this still the analysis I should run? Thanks again!
Comment: @user182007 Sorry, I misspoke! What you said (not what I said) is what the slope will tell you. I accidentally reversed the DV and the covariate.