Array image to generate image in folder using html2canvas

Question: I am storing all child Images src in Array ,i have created sample template and in array loop i am changing src and them want to convert them in image . but only last 4 array value is saved as an image . is this ajax issue or what??
HTML code:

JQuery code :
 $('#convert').click(function()
 {
 var images = $('#links a').children('img').map(function(){
 return $(this).attr('src') }).get();
    console.log(images);

    //$('#gallery_pic').append(images);
     var side=1;
      var data;
     for (i = 0; i < images.length; i++) {

        console.log('Top i is '+i);
        console.log('Group*******');
        console.log(i+','+images[i]);
        $('#one').attr("src", images[i++]);
        console.log(i+','+images[i]);
        $('#two').attr("src", images[i++]);
        console.log(i+','+images[i]);
        $('#three').attr("src", images[i++]);
        console.log(i+','+images[i]);
        $('#four').attr("src", images[i]);
        console.log('Group Ends');
        html2canvas([document.getElementById('present_sample')], {
    onrendered: function (canvas) {
        $('canvas').html(canvas);
        var data = canvas.toDataURL('image/png');
        // AJAX call to send `data` to a PHP file that creates an image from the dataURI string and saves it to a directory on the server

        $.ajax({
          type: "POST",
          url: 'download.php',
          data: {
          image: data},
           success:function(data)   {
          alert('Ajax return is'+data);

            }
            });

        }

       });

});

PHP code :
<?php
if ( isset($_POST["image"]) && !empty($_POST["image"]) ) {

    // get the image data
    $data = $_POST['image'];

    list($type, $data) = explode(';', $data);
    list(, $data)      = explode(',', $data);
    $data = base64_decode($data);

    //Image name
    //$filename ="image". md5(uniqid()) . '.png';
    $filename ="image". md5(uniqid()) . '.jpg';

    $file = "download/".$filename;

  // decode the image data and save it to file
    file_put_contents($file,$data);

    echo "successfully downloaded in folder";

}
?>

Comment: Why are you declaring twice variable data?
Answer: you can very well avoid the problem by using only one ajax request, i.e. , make your ajax call after the for loop ends, till then append all the data to your data variable, and at the end of the loop , make only one ajax call.
NOTE: this issue with ajax calls inside for loops has been discussed in many threads, take a look if it helps:
http://www.ravenglass.com/blog/index.cfm/2013/3/5/FOR-Loops-Overwriting-Ajax-Responses-and-how-to-fix
Ajax call within jquery each loop
jQuery AJAX solution inside each() loop
Comment: If i simply remove ajax and check data by setting in image src , 2 images are created but both are same . i dont understand why first 4 image is getting overlapped by last
Comment: you mean 2 sets of 4 images are created, but both sets are same?
Comment: what about two declarations of var data? you removed one?
Comment: your for loop iterates twice? what is the value for images.length? can you post the code for links a


Using Timestamps to Prevent Session Hijacking?

Question: I have been looking at ways to guard against session-hijacking, where someone steals a session cookie and uses it to gain access to the system.
Programs such as http://codebutler.com/firesheep make it easy to sniff sessions on open Wireless networks, and other ways of getting sessions include cross-site scripting attacks, or just physically lifting them from a victim's computer.
Using SSL to secure all session-cookie/server communications is critical for preventing the Firesheep sniff, and setting HTTPOnly on the cookie helps prevent JavaScript from being able to read the session cookie in XSS attacks, but it's still vulnerable to AJAX-based attacks.
Another layer is to include a security token or a nonce in the session cookie that gets updated on each request. You store the token in a server-side datastore and in the cookie, and on each request you compare that the token in the cookie matches the token in the datastore.
If the tokens don't match that could be an indicator that someone stole the session and is trying to use it so you can either ignore the request or invalidate the session and require the user to re-authenticate. However, mismatched tokens could also result from a slow/flaky connection.
For example, you could have a case where the server receives a request from a real user, updates the session token in the server datastore and responds to the user with a session cookie that contains the updated token. But the user doesn't receive the response due to a slow/flaky connection so the user still has the old session token while the new one is stored on the server. When the user retries the request, the tokens won't match.
One way to mitigate this problem is for the sever to keep a history of the last few tokens and check that to see if they match, but then it becomes a situation of how many tokens to keep, and depending on how flaky the connection is or how click-happy the user is, the server may cycle through the history before the connection comes back and the user's session gets updated by the browser.
An alternative to keeping a token history is to timestamp each session and check if the timestamps are within some short, specified range, say 30 seconds. If the user's session cookie timestamp is within 30 seconds of the server's stored session timestamp, then the session is deemed authentic.
Example pseudocode
<code>def authenticate_request():

    if (stored_session.timestamp - session.timestamp > 30 seconds):
        return False
    return True
</code>
This avoids having to keep a token history -- the timestamp becomes the token -- but attackers have a 30 second window of opportunity to hijack the session after it's stolen. While this is true, the token-history alternative isn't any better because it gives attackers a potentially longer window of opportunity.
Other approaches of checking for IP address and User-Agent changes have issues too. User Agents are easily spoofed, and if an attacker is able to get a user's session, they can easily determine the User Agent through the same XSS code or some other means.
If the user is on a mobile device, their IP address may change frequently so that would result in many false positives. Furthermore, the attacker could be behind the same company firewall so the user and attacker's IP are the same to the external Web server.
Is using a timestamp token the right approach or is there a better way? Is the 30-second buffer about right? What edge cases am I missing?
Answer: I don't see how a timestamp would work. It would require the user to never spend more than 30 seconds on a page before sending another request to the server. I'm sure I spent a lot more than 30 seconds reading this page and typing up this response before pressing "Post".
It seems to me that there's an inherent problem that any data you send over the line could be intercepted and duplicated. Encryting a password doesn't solve the problem, because a hacker could intercept the encrypted value and then send that encrypted value. He doesn't necessarily care what the unencrypted value is.
Same story for any token you send. The hacker could intercept the token and duplicate it.
The only idea I've heard that seems to solve the problem is a challenge-and-response system using public and private keys: A creates a random character string, encrypts it using B's public key, and sends it to B. B decrypts that string using his private key and sends the decrypted value back along with his application data. A then validates that the decrypted value matches the original value. If it doesn't validate, he rejects the associated data.
A hacker can't intercept the message from A and spoof the response if he doesn't know B's private key. A hacker can't use a previosly-intercepted reply from B because the random string is different every time.
Comment: It doesn't require them to reload the page every 30 seconds -- they can be gone for any length of time. What's important is that the timestamp in their session matches the timestamp stored on the server on the next request.
Comment: And yes, any unencrpyted data could be intercepted and duplicated, but unless they intercept the session from the last request the user makes, the token/timestamp will have been updated on the user's next request so the intercepted token will not be valid. The only time it will be valid is if they are able to intercept and use it within the 30-second window of the user's last request.
Comment: I guess I don't understand what time your timestamp represents then, and what you are comparing it too. I just reread your original post and you say "timestamp each session". But the time of what? When it was created? When you last sent a page to the user? Etc. In any case, you say this timestamp would be sent back to the server. But then anyone sniffing the line could see the session id and the timestamp. I don't see what you've gained. Anyway, I think you need to clarify what you're up to a little more.
Comment: A session cookie consists of a user_id, session_id, and a timestamp in an AES encrypted bundle with a SHA-1 signature. When the user logs in, the session is created and the cookie is timestamped. When the Web application responds to each request, the session cookie is updated with a new timestamp and a server-side datastore is also updated with the same info (user_id, session_id, timestamp).
Comment: So after the page loads, there will be an encrypted session cookie in the user's browser with a timestamp of let's say 12345678 and the server will also have record of the stored session and its last timestamp of 12345678. On the next request, the server will check that the user's session cookie timestamp matches the session timestamp that is stored on the server.
Comment: If they match, the request is deemed authentic. If they don't, it could be a sign that an attacker had stolen a session cookie and is trying to use it, but the server won't authenticate the request because the attacker's stolen session cookie has an old timestamp. Unless the attacker manages to steal the session cookie on the user's last request, the user will have made another request and updated the timestamp so previous session cookies will not be valid.
Comment: Hmm, okay. That guards against a hacker intercepting the message from the client to the server. It doesn't guard against a hacker intercepting the message from the server to the client, as long as he got his response back before the "legitimate" client. Also, if the client opens multiple windows within one session, it wouldn't work. Though I guess you could say that's not allowed.
Comment: If you're sending the timestamp from the server, I don't know why you'd give a 30-second window, or any window at all. The client should have the exact value sent from the server.
Comment: If you're talking about putting encryptian on the message in addition to or distinct from the encryptian you get with HTTPS, this would mean that you'd have to override the normal handling of session ids done by the client and the server. But I suppose that's not an insurmountable obstacle. If you're thinking you'd let the systems exchange the session id in the usual manner and then this would be an additional message, that would probably be a bad idea, because a hacker could see the unencrypted session id and would have that information to help him in decrypting the encrypted ...
Comment: ... message. But this would be a trivial problem: just have a different session identifier, unrelated to the J2EE session id.
Comment: A session is shared between multiple browser tabs so this shouldn't be a problem. If the user opens a new tab/browser in incognito mode, then the browser will ask them to login in again b/c it can't read their session to authenticate their identity, and then when they login they will have two separate sessions going, each with a unique token/timestamp so multiple sessions isn't a problem either.
Comment: Regarding using timestamps and a 30-second window, consider the case where the user requests a page from the server, the server updates the session timestamp/token and returns it in the response, but the connection between the user and the  server is slow/flaky. If a impatient/click-happy user gets tired of waiting and sends another request by reloading the page before receiving the response from the server, then they will be sending the old token/timestamp and it won't match because the server updated it on the previous request attempt, even though the user hadn't received it yet.
Comment: While SSL will protect sessions from being sniffed in transit, it doesn't protect sessions that are stolen in cross-site scripting (XSS) attacks. If the server encrypts the session data or at least signs the plaintext session data with something like a SHA-1 or MD5 signature, the server can be reasonably sure that session data hasn't been tampered with or changed by a man-in-the middle attacker.
Comment: Most XSS attacks are of the form where an attacker manages to insert a bit of JavaScript on a Web page through a form, and the JavaScript code steals any user's session data that tries to load that page. The attacker's code then the user's session data to an external server and then the attacker tries to use the session cookie to gain access as that user. It is not a case where the attacker is intercepting server responses and then sending them back to the user.
Comment: However, if an attacker manages to steal a users's session cookie, and there a two active sessions going under the same session ID (one by the legit user and one by the attacker), the timestamps/tokens will get out of whack and the server will invalidate the session so this timestamp/token layer protects the user if it gets that far.


If $X$ is a set of linearly independent vectors in a vector space $V$, then can vectors can be added to $X$ to give a basis for $V$?

Question: Normally, by the basis extension theorem, I would argue that this is possible, but I am not sure whether or not it will still be true if V is not finitely generated.
Comment: It's true. In order to prove it, use Zorn's lemma. (in the infinite dimensional case)
Answer: If the global space is finite dimensional you have a $constructive$ proof using the Steinitz exchange lemma. If the global space is not finite dimensional it is still possible to prove the "basis extension theorem" but it is not constructive anymore and done by Zorn.


Garageband 10 pitch correction

Question: I am mixing some vocals (live recorded) with a backing track in GarageBand 10 - and there is a falsetto vocal that has a slight 'wobble' half way through.
I know you can use the pitch correction controls on a track and/or region in GarageBand, but is there a way of correcting the pitch halfway through a sung word?
I've tried splitting the region where the correction needs to take place and applying pitch correction but then you can distinctly hear where the regions start/end and I can't see anyway of blending them to sound continuous.
Any suggestions on how to 'nudge' a note so to speak?

N.B. I also have Logic Pro if this of any advantage, I could drop the audio file in there and export out again if there is an easier way of achieving this...
Comment: I haven't used the features in Logic for pitch correction but I'm fairly certain they have some.  In any event, you are much better off trying to do any sort of complicated process in Logic.  Garageband is very much a laymen's DAW, not that it can't produce a good sounding product, just doesn't have the same tools available and those that are available usually don't have as much depth.  I would suggest mixing it all in Logic, not that that has to do with your question.
Comment: @Basstickler Basically Logic Pro stopped working with the recent OS X Yosemite updates, and I wasn't paying £139.99 to upgrade just on principle which is why I've had to use GarageBand for this project. A further OS update seems to have fixed the problem and now Logic is working again for the most part. I'm not really familiar with Logic either but I'll have a look in the meantime and see what I can play with - thanks for looking!
Comment: I use Logic 9 but haven't looked for this feature in particular.  I have seen others talk about a feature in Pro Tools where you can basically draw in changes in pitch or volume.  There is definitely a lot more in Logic, which often makes it harder to find.  I thoroughly recommend trying to find some good youtube tutorials, as I have learned a lot from them.  I also experienced some issues when I upgraded to Mavericks, which I have heard Apple just told others to upgrade to resolve... I was unimpressed.
Answer: Logic Pro X + Flex Pitch:
If the wobble in the note is vibrato, try dragging the upper-mid hotspot vertically - this will straighten out the wobble.
If you can split the note after the wobble without artifacts, you could then treat the wobble as pitch drift and straighten that out using the upper-right hotspot.
Try treating the wobble as a formant shift and adjusting it by dragging the lower-right hotspot vertically. This is not a likely fix but still try it - you can always undo!
Other procedures:
Mute the bad part of the note and carefully apply some delay/reverb to the good part of the note to extend it, masking the mistake. Create the illusion of a good note with automation.
Logic Pro X also has a suite of vocal processing effects that may help to fix this note. Try playing with the vocal transformer, pitch shifter, and pitch correction FX. I'd be surprised if you couldn't at least partially remove the offending sound in that note with these tools.
As a last resort consider punching in a good vocal. Even with live recordings this can be done with good effect if the original vocal track is somewhat isolated.
Comment: I've marked this as the answer as it closely reflects what I ended up doing at the time. The project was sat in GarageBand unfortunately and so I silenced the bad note and used reverb to smooth it over. Lesson going forward: use Logic! Thanks again :)

Garageband 10 pitch correction


Understanding a specific step in the proof of a Theorem about Field Theory

Question: The part that I don't understand is how the author gets to the equality in 10.6. Lemma 10.3 simply states that a system of $m$ homogeneous linear equations in $n$ indeterminates has a solution in which not all the variables are zero if $n>m$. Since this lemma is used to derive the equation 10.6 my guess is that there had to be some system of linear equations the author used to arrive at 10.6, but what is such system?

I would really appreciate any help/thoughts.
Answer: (10.6) is literally a system of homogeneous linear equations.  Namely, the variables are $y_1,\dots,y_n$, and for each $j=1,\dots,m$, we have the homogeneous equation $$y_1g_1(x_j)+\dots+y_ng_n(x_j)=0$$ in these variables (with the scalars $g_1(x_j),\dots,g_n(x_j)$ as the coefficients).  This is a system of $m$ linear equations in $n$ variables, so since $n>m$, it has a nonzero solution.


Difference between Null-space(A) and Null space$(A^T)$

Question: Given two linearly independent vectors $v_1$ and $v_2$ in $R^3$; span a plane $P^1$. Then any vector normal to the plane $P^1$ will be in the $N(A)$ or in the $N(A^T)$ ? (Here, $N(.) = Nullspace$.)
On the same line; If I take a matrix $A$ made up of $v_1$ and $v_2$ in $R^3$; as columns of $A$. Then $A = QR $; The full QR factorisation will result in a 3rd vector $v_3$; which will be in the normal direction. Which sub-space will this vector be in? $N(A)$ or $N(A^T)$ ?
As an extension to this question; If we have 2 sets of linearly independent vectors in $R^3$ ; $ (x_1 , y_1) $ and $ (x_2 , y_2) $ such that they span planes $P^1$ and $P^2$ respectively; then the vector q1 coming from a full QR factorisation of a matrix A with $ (x_1 , y_1) $ as columns; i.e Q will have the vector $q_1$ which will be orthogonal to both $x_1$ and $y_1$ and similarly the vector $q_2$ coming from QR factorisation of matrix B with $ (x_2 , y_2) $ ;
Further is we take another QR factorisation with  $ (q_1 , q_2) $ as columns; then we will find a vector $q_3$ which will be orthogonal to both $ q_1$ and $q_2$ ; But is this enough to prove that the vector lie on the intersections of planes $ P^1$ and $ P^2$ ? Can't the vector $q_3$ lie parallel to both planes and not on any one of them or not on both of them!
Comment: Hint: $A$ is $3 \times 2$ and hence $N(A)$ is a subspace of $\Bbb{R}^2$.
Comment: How do you get this third vector? $Q$ is $3\times2$ and $R$ is $2\times2$
Comment: What does it mean for a vector to "come from a QR factorization"?
Comment: @GeorgeTsoutsinos I am doing full QR.
Comment: @user7530 I have updated the question accordingly. Actually I meant; the full QR factorisations 'Q' will have the vector 1 which will be orthogonal to both 1 and 1
Comment: I hope the question is clear; if not kindly tell me! I'll update and make it better. Thanks for the help!
Answer: You can think of matrix multiplication by a vector, $Av$, as taking a linear combination of the columns (with the weights of the combination in the vector). So if $A$'s columns are linearly-independent vectors, $A$ has no null space.
You can also think of matrix multiplication as dot products of rows of $A$ with $v$. A vector $v$ perpendicular to the columns of $A$ is therefore in the nullspace of $A^T$, since $A^Tv = 0$ (the entries of $A^Tv$ are dot products of the columns of $A$ with $v$).


Linear System of Equations over a Finite Field

Question:
If $AX=B$ has an integer solution and $A$ and $B$ are matrices with integer entries, show that the system has a solution in $\mathbb{F}_p\ \forall p$.

My attempt: Suppose we have the following map
$$\phi: \mathbb{Z} \rightarrow \mathbb{Z}/n\mathbb{Z}$$
Let $a,b \in \mathbb{Z}$
$\phi(ab):=ab \mod n$
$\phi(a):=x \equiv a \mod n$
$\phi(b):= y \equiv b \mod n$
By definition of modular congruence,
$\phi(a)\phi(b)=xy\equiv ab \mod n=\phi(ab)$
Thus, $\phi$ is a homomorphism and since $\mathbb{Z}/n\mathbb{Z}\cong\mathbb{F_p}$ if $AX=B$ has an integer solution then it also has a solution in $\mathbb{F_p}$.
Point: I feel like there is still more to show to this proof.
Answer: Yes, you just need to use the fact that the map $\phi$ from $\mathbb{Z}$ into $\mathbb{Z}/p\mathbb{Z}$ defined by $x \mapsto x \pmod p$ is a homomorphism.  So suppose $a_{11} x_1 + a_{12} x_2 + \cdots +a_{1n} x_n = b_1$. We can apply $\phi$ to both sides of this equation, and we have $\phi(LHS)=\phi(RHS)$. Now use the fact that $\phi$ preserves sums and products, and we get a solution over $\mathbb{Z}/p\mathbb{Z}$ also.


Função para incrementar o nome do ficheiro - python(opencv)

Question: eu tenho este código que me guarda um video cada vez que corro o programa com o nome video0.
out = cv2.VideoWriter(video0.avi', fourcc, fps, (int(width), int(height)))

Queria agora cada vez que corresse o programa ele guardasse o video com outro nome.
1ª vez :video0
2ª vez :video1
3ª vez :video2
Answer: Só precisas de fazer o seguinte:
import os

filename = 'video0.avi'
if os.path.exists(filename):
  tmp = filename.split('.avi')
  count = tmp[0].replace('video', '') or 0
  count = int(count) + 1
  new_filename = 'video{0}.avi'.format(count)

Basicamente, verificas se existe em disco, vais precisar do path para a localização do ficheiro, depois fazes um split pelo ponto e a entensão do ficheiro depois removes o nome base e incrementas o resultado, se não existir com o "or 0" adiciona um defalt.
O mesmo com função.
import os

def load_file(filename):
  if os.path.exists(filename):
    tmp = filename.split('.avi')
    count = tmp[0].replace('video', '') or 0
    count = int(count) + 1
    return 'video{0}.avi'.format(count)
  return filename

filename = 'video.avi'
print(load_file(filename))

Percorrendo toda a diretoria.
import os, re, os.path

def load_file(file):
  number = []
  onlyfiles = [f for f in os.listdir('.') if os.path.isfile(os.path.join('.', f))]  # load all dir files
  filename, file_extension = os.path.splitext(file)                                 # load filename and extension from parameter file
  total_files = len(onlyfiles)                                                      # get total files in dir
  splitter = re.compile(r'\d+')                                                     # build a splitter to get digits part of file name
  number = splitter.findall(filename) or ['0']                                      # get number part from filename
  only_name = filename.replace(number[0], '')                                       # get only name from filename removing the number from it
  i = 0
  matching = [s for s in onlyfiles if only_name in s]                               # build array only with files names that match the only_name (from file name)
  if len(matching) == 0:                                                            # if no files matchs the criteria returns the name itself, don't exist any
      return file
  while i < len(matching):                                                          # interates only the array of matching files and extracts the number from it
    number.append((splitter.findall(matching[i]) or [0])[0])                        # add to number array the numbers from file found
    i += 1
  number = [int(i) for i in number]                                                 # converts all number array to int (cast), some of then are strings
  largest_number = max(number)                                                      # get the max value from array
  return '{0}{1}{2}'.format(only_name, str(largest_number + 1), file_extension)     # returns the new file number

filename = 'video.avi'
print(load_file(filename))

out = cv2.VideoWriter(load_file(filename), fourcc, fps, (int(width), int(height)))

Comment: e isso em forma de função?? alguma ideia? em que o argumento fosse o nome do output.
Comment: Isso é muito fácil, dá um olhada agora.
Comment: oh sim claro xd, muito obrigado!
Comment: ok, funciona porem pega sempre no video do filename. Depois de ser executado novamente ele pega no video0 outra vez em vez de no video1b (que deveria gerar o video2).
basicamente queria pegar no ULTIMO e incrementar.
alguma ideia?? desculpa lá já agora e obrigado :c
Comment: Precisas de percorrer toda a diretoria e verificar se existe um ficheiro com esse nome, esta função fó verifica se aquele que lhe passas existe.
Comment: e como iria percorrer a diretoria?
Comment: Dá uma olhada, já coloquei essa função com pesquisa, confirma se funciona. Não tenho como testar.
Comment: hmm obrigado, vou testar agora
Comment: ele vai sempre buscar o filename = 'video1.avi', cria o video2.avi, mas depois nunca cria o video3.avi etcc,  substitui o video2.avi
Comment: Já percebi porquê, estava a validar com o if fora do while, tem de ser primeiro o while, percorre toda a diretoria à procura do ficheiro, se encontrar passa para o maximo encontrado para o if e retorna esse máximo + 1. Testa agora.
Comment: continua igual, tambem nao percebo porque, o codigo parece.me estar correto, substitui na mesma o ultimo video gerado (video2.avi)
Comment: quer dizer, agora nem encrementa para o video2, continua modificando o video1, enganei-me no ultimo comentario
Comment: Lol...que erro básico...esqueci do i += 1, ficava sempre no zero....he eh, tenta agora
Comment: só está a alterar o video1 :(  já estou sem fé ahah :c, ja nao entendo nada xd
Comment: Faz debug, tenta perceber o que falta aí.
Comment: sim é o que estou a fazer, obrigado pela ajuda!
Comment: Oi, resolvi. A solução estava um pouco longe. Dá uma olhada agora. Tive de criar um projeto local para testar, ontem não conseguia. Deixei notas no código para poderes perceber o que é feito step by step. Pode não resolver tudo, mas pelo menos existindo um ficheiro video.avi e outro video10.avi, ele vai encontrar o maior e vai retornar video11.avi.
Comment: desde já já obrigado! o que me está a fazer é pegar no video com o numero mais alto (ex: video1), cria um video2(que n funciona) e cria tambem um video3(que é, o que é suposto ser)..
consecutivamente pega no video3, cria um video4 que nao funciona e cria tambem um video5 que é o que é suposto..  mas isto com um bocado de debug deve ir ao sitio hehe
Comment: Agora como consegui testar, parece-me que não estás a fazer qualquer coisa bem. Repara na linha que adicionei ao código, é assim que estás a utilizar, com o nome base, 'video.avi'...se passares assim, parece-me que está ok.
Comment: o problema é que chamo a função duas vezes, mas já percebi o erro, vou já alterar o meu código. obrigado pela ajuda


does p-value distribution indicate the suitability of the statistical test

Question: This post suggests that p-value follows uniform distribution in case of point null hypothesis and continuous data.
In my project, I have millions of p-values from actual data. I don't want to get into the details of my data and statistic test. I just want to know the following:
In general, for point null hypothesis and continuous data, if the p-values do not follow uniform distribution, does it imply that 1) the null hypothesis is not correct, and/or 2)that applied statistic test is not appropriate? could there be other reasons?
Thanks,
Comment: I don't understand your question. Under these conditions the p-value under the null hypothesis is uniformly distributed *by definition*, as explained in the comments on & answers to the question you linked to.
Comment: I want to raise pretty much the same points as @Scortchi. How do you know "if the p-value of a statistic test does not follow uniform distribution"? You should make it clear whether you are talking about running a simulation to generate simulated p-values, or if you intend to use p-values from actual studies.
Comment: As @MichaelM says, the distribution under an alternative hypothesis won't necessarily be uniform - indeed shouldn't be if it's an alternative you want your test to have power against. I'm also puzzled as to how you're getting the distribution of actual p-values. Perhaps add an illustration of what you mean to your question.
Comment: No, it could mean that the null hypothesis is wrong... but to compare the p-value distribution with the uniform distribution, you need to perform the same study dozends of times, which is normally pathetic.
Comment: Are you obtaining different p values for the same hypothesis or just the same *type* of hypothesis (but e.g. from different variables)?
Comment: I think it's strictly speaking the distribution of the test statistic that needs to be continuous (consider e.g. testing a one-sided hypothesis about a normal mean) - having thought about it a bit since my earlier comment. Anyway, see [Fisher's method](https://en.wikipedia.org/wiki/Fisher%27s_method) for meta-analysis. If I were you I *would* go into a bit more detail about exactly what I was doing. Does "point null" mean the distribution of the test statistic is fully specified under the null?
Comment: Thanks for the comment! my question is that if the actual p-value does not follow uniform distribution, does it mean one used the wrong test?
Comment: If you really have millions of p-values, then look into ideas such as *empiricall null*s, FDR, ... https://stats.stackexchange.com/questions/123402/how-do-fdr-procedures-estimate-a-false-discovery-rate-without-a-model-of-base-ra/178375#178375
Answer: P-values may be skewed for reasons that do not imply anything about whether the null hypothesis is correct or not; researchers only do research when the have a good reason to believe their hypothesis is valid. In that situation, we would expect p-values to be skewed high, because bad hypotheses have been filtered out by other means (like common sense, or domain knowledge). In this case the lack of normality is due to skill.
On the other hand, there could be a bias in published results one explanation is that  researchers are more likely to publish p-values that are significant, and put the non-significant ones in a filing cabinet. That would inflate p-values and tend to cast doubt on results. Take this example: If a hundred scientists did the same research project, and only 5% got high p-values, and only those 5% published the results would look to be well established, but in fact just represent random variation.
Overall, I am skeptical if any conclusion can be drawn from the distribution of p-values alone.
Answer: The distribution of the p-value under the null hypothesis can tell you whether the test achieves its actual size or not. If, say, less than 5% of the distribution falls under the 0.05 mark, the test is said to be anticonservative (rejects too often), and it's conservative for more than 5%. Fisher's Exact Test is a commonly accepted conservative test. P-under-null having a uniform distribution isn't a requirement. It also doesn't make a test "suitable" either - it could have no power, or less power than another test of the same size.


Dovecot mdbox to mbox/MailDir/eml conversion

Question: Is there any way to convert Dovecot's mdbox/dbox to mbox, MailDir or eml format (or any other easy to import format)?
Answer: The dsync utility is intended to do this transformation.  If you have it installed you should have a man page that explains the options.  There is a section covering migrations such as you are looking for.
The process needs to be done per user.  Multiple runs are recommended.
From a quick review of the documentation it is possible to sync with a remote IMAP server.
It appears the Dovecot wiki is malfunctioning, but the Wiki documentation may be packaged with the install.  On my Ubuntu server it is in /usr/share/doc/dovecot-core/wiki.
Comment: If I understand good that wiki page it will migrate all mailboxes set at `mail_location` to desired format. How about converting only selecting mailboxes? Is it possible?
Comment: @JackTheKnife Depending on the folder stucture you should be able to point to specific folders and convert them.  You could also backup to an Maildir structure and delete the folders you don't want after the conversion.


Mathematical notation for length?

Question: I would like to write an equation to sum the values of each number in a vector divided by the length of the vector. What is the proper way to write this formula?
As an example, consider vector v:
<code>v = [1, 2, 3, 4]

2.5 = 1/4 + 2/4 + 3/4 + 4/4
</code>
Is this the proper way to write this?
$$\sum_{i=1}^N \frac{i}{length}$$
Comment: $|v|$ is often used to denote $\lVert v\rVert_2$, the $2$-norm or Euclidean length of $v$, whereas it seems you want its length in the sense of the number of its components -- I'm not aware of any notation for that.
Comment: As far as I have seen in many calculus book from R.A Silverman to Adams; $|V|$ is what you want.
Comment: Thanks. I've seen this, but in my actual use case I am also using absolute values in my equations, so it would be very confusing to use this notation.
Comment: And when you present $V$ as a vector in your context firstly; there won't happen any confusing point for example with numbers,...
Answer: As noted, this is the arithmetic mean of the elements in $v$. You can indicate this in a number of ways such as:
$$\sum_{x\in v} \frac{x}{|v|} = \sum_{i=1}^{|v|} \frac{v_i}{|v|}$$
Comment: Thanks. Yes, I'm aware it's the mean. I choose a simplified example to depict what I am trying to convey. My actual use case is more complex. Thus, I was looking for the clearest way to convey vector length.
Answer: I would be tempted to use the notation $\overline{{\bf v}}$, as is done with the arithmetic mean $\overline{x}.$ If your vector is given by ${\bf v} = (v_1,\ldots,v_n)$ and you are calculating
$$\frac{v_1+\cdots+v_n}{n}$$
then you are calculating the arithmetic mean of the data set whose datum are the components of the vector. It seems perfectly reasonable to represent data sets by vectors and to write $\overline{{\bf v}}.$
Answer: You could use $N$, since you are already using it in the summation bound.  Another notation to consider depending on the context is $dim(v)$.
Comment: Do you mean $\dim V$ where $v \in V$?
Comment: Yes fbn, you are absolutely correct and I hereby recant my advocacy for considering $dim~v$ as a reasonable notation.
Comment: Yes, that's more accurate, although I think $dim(v)$ is clear enough, depending on context.
Comment: The symbol $v$ denotes a vector. Then $\dim v$ denotes the "dimension of a vector". IMHO, the only way to reconcile that is to take it to mean the dimension of the span of that vector.

Mathematical notation for length?


How does taking out a group of observations bias your regression?

Question: Assume you have a set of observations at time $t_1$ and you use it to estimate a regression $R1: y=b_0+b_1x$. The regression is used to predict the y-value for the future. You gather a set of (new) observations at time $t_2$. For this data, you are not able to observe the observations with a low estimated y-value anymore. For example, assume the case that getting data is expensive so you won't bother collecting those data, where you estimate y to be low (based on regression R1). However, for $t_3$ you still need to estimate a y-value for all observations and select which observations you spent money on to select.
How does that affect the predictions for $t_3$ that are made with the second regression $R2: y=b_0+b_1x$ that is based on the second, censored data?
I assume these are biased but are there any statistical results on the extent of the bias?
I am not expecting a full answer (though I'd be happy to hear it if you have it), but would enjoy getting some input or paths what I can look for. In general, I looked for censored regression models, but this case is a bit different as we only estimate the y-value to be lower, but cannot be sure. Is there anything in statistics I am not aware of that can describe this? Or there any  applications that this problem relates to? Anything that comes to your mind is helpful.
Comment: Is y only measured at t1?
Comment: Yes & no. Right now it is measured at all three time points, but I'd like to introduce what Frank below calls "context dependent sampling", then at t2 and t3 only special y-values are measured and I'd like to see how that affects the estimates that are based on this censored sample.
Answer: To answer the more straightforward part of your question:

the $t_3$ equation will bias upwards $b_0$
$b_1$ should only be thought to generalize to those observations that survived through $t_2$
The bias on $b_0$ will be proportional to the degree to which low $y$ was associated with not collecting the data

There are many possible approaches to your problem. Some of the things that matter are:

whether you are collecting $y$ at both $t_1$ and $t_2$
whether $x_1$ is the same observation at both times, or if they are observations of the same variable at different points in time, e.g. $x_t1$ and $x_t2$

Sometimes if you want to characterize something about the observations that drop out it is helpful to include an indicator variable (syntehtic 0s and 1s in a new column) to reflect whether the observation was collected. So long as you center (i.e. make your column for x equal to the mean of values of x), then you can often allow the indicator value to reflect information about the uncollected group. Be aware that depending on your usage and your data doing so can cause issues with homoscedasticity, the interpretation of your results, and your slope error estimates (and corresponding p-values).
Comment: For longitudinal analysis there is a specialty called outcome-dependent sampling that is worth searching.
Comment: Thanks for the helpful comments! Maybe to clarify: all observations are new observations with a different set of features. So the second point, the regression R2 will also be used to make predictions for those that would likely not make it through, basically to select which  observations to keep. These are basically decision made over time and after certain points in time, we want to determine which decision should be made in the future based on those in the past. I see we run into a sort of selection bias after t2. The comment on the outcome-dependent sampling is also very helpful!


Employing optimal packing, how many circles (51 mm diameter) can I cut from a rectangle (330 mm×530 mm)

Question: I know that I should use some kind of honeycomb structure but can't work out in which orientation I should arrange it. I've looked at a few websites now and although I have a slightly better idea of the options, I can't work out how to model the problem and therefore calculate how many circles I could cut.
Specifically I would like to know:
~ How could I model this and what mathematics are involved?
~ What is the maximum number of 51 mm-diameter circles I can cut from a 330 mm × 530 mm rectangle?
~ What is the minimum size rectangle from which I could cut 16 circles?
(As you might suspect this is a real-life problem that I must solve, the disks that I will cut are to be used in a physics experiment but the material from which they are made is very expensive. It can however be purchased in any size rectangle, up to 330 mm × 530 mm.)
EDIT
OK so I just discovered this question and the Wikipedia link contained therein. Whilst it is certainly related I am no closer to solving my current queries. (Other than if I were to order a square sheet of the material measuring 204 mm × 204 mm but I'm sure a rectangle would be more efficient.)
Comment: In the title, and once in the text, you say that the long edge is 530 mm; but later you say 550 mm.
Comment: Right you are @John, I'll correct the typo, thanks.
Answer: For your problem, one choice is to order a rectangle with both dimensions a multiple of 51 mm, use a square pack, and get a density of $\frac{\pi}{4}\approx 0.785$
Another alternative is to use a hexagonal pack.  If you have $k$ rows alternating $n$ and $n-1$ you want a sheet $51n \times (1+\frac{k \sqrt{3}}{2})51\ \ $mm, which packs $\lfloor n(k-\frac{1}{2})\rfloor$ circles.  For your case, $n=6, k=12$ will fit $66$ circles in $306 \times 537$ mm, with a packing density of about $0.8205$
For $16$ circles, you could also use a $4 \times 4$ hexagonal pack.  This would require $230=4.5\cdot 51 \times 184\ \ $mm, giving a density of $0.772$, so you could just buy $204 \times 204\ \ $mm and be better off.
Comment: I haven't proven that there is not a more efficient way that doesn't follow the standard packs.  However, those usually just use up the border around a standard pack.  Since you can buy any size you want, it is probably better to choose a standard layout and buy the proper sheet.  I have rounded up to the even mm in my answer.
Comment: The square packing has a constant density.  The hexagonal pack will have a basic waste for a large area, plus waste proportional to the boundary.  So you want the largest sheet (assuming it beats the square pack) because there are more interior points.
Comment: Thanks @Ross, that's exactly the info I needed. I don't quite understand what you've written in this phase though: "$230=4.5\cdot 51 \times 184\ \ $mm", could you please clarify?
Comment: @qftme:  I was just indicating where 230 came from as $4.5\cdot 51$, then that you needed 184 in the other direction.  I agree it wasn't clear.
Answer: Since you don't say which websites you've looked at, I don't know whether you've discovered this one. Or this one. The main thing I get from these pages is that packing is hard, there are no general rules for optimal packings, but there are patterns that often work or are at any rate near-optimal.
Comment: I hadn't seen those particular links @Gerry. Thanks and +1.
Answer: The spacing between the circles and the spacing to the edges has been left undefined in your problem. For real-life problems the spacing is non-zero. For Laser-cutting the kerf (width of cut) is generally 0.3mm.
In addition, generally in that industry 5mm spacing is used, perhaps less.
Using dedicated circle nesting software trying multiple packing arrangements:
For 51mm circles into 530x330 sheet with 0mm inter-part spacing = 67 circles.
For 51mm circles into 530x330 sheet with 5mm inter-part spacing = 54 circles.
For 51mm circles into 204x204 sheet with 0mm inter-part spacing = 16 circles.
For 51mm circles into 204x204 sheet with 5mm inter-part spacing = 11 circles.


Azure VM CPU utlilization metrics (no data)

Question: I am running several VM's in Azure. Size DS14 and my cpu metrics look like this. "No Available Data" What am I missing? How can I get it to show the CPU utilization of the box?
Comment: I didnt ask Azure support, as they require a support contract...which I don't have. This is why I am asking here first.
Comment: What did Azure support say?
Comment: Not sure why I got a down vote. This seems to be a perfectly reasonable question to me...
Comment: I think the vm agent is not working properly. Try reinstalling. Had a similar problem a few months back
Comment: @BrunoFaria how do I do that?
Comment: I see docs all over for updating the VM after installing the Agent, but none seem to work for me. (I am using ResourceManager)
Comment: I don't understand why this is closed. It is so hard to find up-to-date azure documentation anywhere. I ask a question here, and it gets closed. What more information do you need? I don't have any more info.
Comment: @ChrisKooken I have to agree - the moderators seem to have been overzealous in closing this topic.
Comment: same for me. shame on the person who voted you down. we pay for this as part of azure and it's disgraceful that we can't log a ticket
Answer: As Bruno Faria responded earlier, this sounds to me also like the VM Agent is not working properly.
Here https://azure.microsoft.com/en-us/blog/vm-agent-and-extensions-part-2/ are some information on how you can check if the agent is installed properly in a VM and how to install it, if needed.
Comment: I am using ResourceManager instead of classic. $x.VM.ProvisionGuestAgent doesn't exist in resourceManager
Answer: I think you can enable vm diagnostic first, then choose any fields you want to monitor. Some of the information can be displayed on the screen immediately.
Comment: Enable basic metrics, and select the data that you want to monitor, then refresh the portal for a few times.
Comment: It has been enabled for about 12 hours, and still no luck. I have updated my screenshots.


Linear isomorphism and isometry between real inner product spaces

Question: Let $V$ and $V'$ be real (positive definite) inner product spaces of (same) finite dimensions with inner products $(-,-)_1$ and $(-,-)_2$.
Let $T:V\rightarrow V'$ be a $\mathbb{R}$-linear isomorphism of underlying vector spaces.
Then $T$ may not preserve the inner product, i.e. it may not be isometry.
Q. Is it always possible to replace the inner product $(-,-)_1$ by
$r(-,-)$ for positive real $r$, and $(-,-)_2$ by $s(-,-)_2$ so that
$T$ becomes isometry between $(V,r(-,-)_1)$ and $(V',s(-,-)_2)$?
Comment: Can you please clarify the question ?
Answer: No. For example, let $T$ be the identity map on $\mathbb{R}^2$. It is not an isometry between inner-product spaces with inner products
$$
(x, y)_1 = x_1y_1+x_2y_2
$$
and
$$
(x, y)_2 = 2x_1y_1 + x_2y_2
$$
and multiplying either of the inner products by a scalar cannot fix that.


SQL Query to Return Unique Dates based on another Datetime column for the current date?

Question: I have the following table (well the below is a scaled down example):
CID | LogDate       | RemDate
1   | 2015-05-06    | 2015-10-01
2   | 2015-05-06    | 2015-10-01
2   | 2015-05-06    | 2015-10-30
1   | 2015-01-03    | 2015-10-01
1   | 2015-01-03    | 2015-10-01
2   | 2015-04-06    | 2015-10-01
2   | 2014-04-06    | 2015-10-01
3   | 2015-05-06    | 2015-12-01

I need to return only rows that have a unique [remdate] on the current date & ignore the others even when they have a matching [CID]....
I'd expect to have back the two unique remdates (2015-12-01 & 2015-10-30)
I hope I'm not missing something obvious here, any help or pointers would be greatly appreciated.
Comment: With your sample data, what are the desired results?
Comment: Sorry I should have added that! Basically, I'd expect to have back the two unique remdates (2015-12-01 & 2015-10-30)
Comment: Seems like he wants no duplicated remdates in his query.
Comment: I think he might be after any date with only a single entry on today's date.  Need more clarification.
Comment: Yes KingOfAllTrades, that's what I'm after! Sorry to all for not being able to explain.
Answer: If you only want to return those remdates that appear once in the table, you can use aggregation for that with count:
select remdate
from yourtable
group by remdate
having count(remdate) = 1

SQL Fiddle Demo

If you want to return those remdates that appear once per logdate, just add that field to your group by clause.
Answer: If you only need to remove duplicates then use DISTINCT.
SELECT distinct remdate, * FROM table

Comment: saying `distinct remdate, *` will not give you only distinct remdates (because of the `*`).. rather it will look across the whole row and make sure you have unique rows.  Mysql has an option that produces something similar, but sql server does not.
Comment: No sorry, my fault for not explaining, only if the remdate hasn't previously been added on another logdate, I want those to be ignored totally on the return.


Relationship Between Tangent, Cotangent, and Modulo

Question: Would appreciate any feedback or prof of the following equation:
$\tan\left(\operatorname{mod}\left(x,\pi\right)-\left(\frac{\pi}{2}\right)\right)=-\cot\left(x\right)$
$mod(x,\pi)$=x modulo $(\pi)$
Comment: Tan has period $\pi$; tan and cot are co-functions
Comment: @J.W. Tamer: It will be most appreciated if you can you expand on the relationship of co-function and modulo?
Answer: The equation follows from some well-known properties of the tangent
(and its reciprocal, the cotangent) function:
(a)  it has period $\pi$; that means $\tan(x+n\pi)=\tan(x)$, where $n$ is any integer;
(b)  it is odd; that means $\tan(-x)=-\tan(x)$; and
(c)  tangent and cotangent are cofunctions; that means $\tan\left(\frac\pi2-x\right)=\cot(x)$.


Positive definite operator on vector space of matrices

Question: I'm reading a paper now that works with operators on the vector space of real $d\times d$ matrices (such an operator can be thought of as a 4-dimensional tensor). The definition of positive-definiteness in this setting would seem to be the analogue of the usual one: we have the standard inner product $\langle A,B\rangle = \text{tr}(A^TB)$ and we say the operator $\mathcal{M}$ is positive-definite if for all matrices $A$ we have $\text{tr}(A^T\mathcal{M}A)>0$.
However, the definition this paper uses is that the above holds for all symmetric matrices $A$. What's the difference (if any?)? Why should this be the right definition (and is it?)?
More generally, is there a good reference on linear algebra over such spaces with special structure as the space of matrices?
Answer: There is no difference between your definition and the definition given in the paper. The reason is the following.
Given any matrix $T$ you can write it as $T=PO$ where $P$ is a positive matrix and $O$ is an orthogonal matrix. This is known as polar decomposition. Usually the proof is given for complex matrices but the same proof works for real  matrices as well. See this post for details.
Now in your situation if you start with any matrix $T$, you have $$tr(T^TMT)=tr([PO]^TM[PO])=tr\big(O^T\bigg(P^TMP\bigg)O\big)=tr(P^TMP).$$
The last equality  is due to the fact that $tr(AB)=tr(BA)$ and $O^TO=OO^T=Id$ . Therefore it is enough to check the inequality for positive matrices.


QtCreator: static library but still asking for DLL

Question: I'm using QtCreator and I got two projects, each with an own PRO file.
The Viewer is a normal Qt app.
The other one, let's call it Utilities, is supposed to be a static library which is used in the Viewer.
However when I compile and run the Viewer (everything compiles fine), I get an error message telling me Utilities.dll was not found.
This is the first part of the PRO-file for Utilities:

QT       -= core gui

TARGET = Utilities
TEMPLATE = lib
CONFIG += staticlib warn_on $$(QMAKESPEC)

Shouldn't it work that way?

Why is it compiling the Utilities.a file fine but asking me for the DLL at runtime? It's supposed to be a static library :(
 Since I did not specify some needed libraries in Utilities.pro, it apparently did not link as you'd expect for a static library.
My platform is W7-x64, latest Qt SDK and MingW 4.4 bundled with it.
Hope anyone can help :/
Thanks!
Answer: The CONFIG += staticlib request your target library to be a static lib not the entire dependency chain ... I am pretty sure your .a lib will require mingw dlls to run ...
If you want to reduce dependencies try the MSVC tool chain (Qt provide pre-compiled package for that) you will end with one or two mandatory dll dependencies. Or you can link again static mingw SDK (you will probably have to build it your-self ...).


unable to print Html table which contains inputs fields in pdf conversion in angular using jspdf

Question: This is the function written in invoice.component.ts file for converting the table to pdf. This is code works fine when the table does not contain any input fields.
pdfCreationClick() {
  var doc = new jspdf.jsPDF('p','mm','a4');
  doc.text("this is siva",15,15);
  var element = document.getElementById('secondTable') as HTMLCanvasElement;
  html2canvas(element).then((canvas) => {
     console.log(canvas)
     var imgWidth = 208;
     var pageHeight = 295;
     var imgData = canvas.toDataURL('image/png')
     var imgHeight = canvas.height * imgWidth/canvas.width;
     var heightLeft = imgHeight
     doc.addImage(imgData, 'PNG',0,0,208,imgHeight)
     var position =0;
     doc.save('first.pdf');
  })
}

This is the code written in html page i.e invoice.component.html
I had tried to keep the form tag in the place of table tag. Even though also i am not able print the table when it contains input fields.

                        <input class='sno' type='text' name='name' value={{i+1}}>

                        <input type='text' name='salary{{i}}' [(ngModel)]=obj.product>

                        <input type='text' name='age{{i}}' [(ngModel)]=obj.description>

                        <input type='text' name='quantity{{i}}' [(ngModel)]=obj.quantity>

                        <input type='text' name='rate{{i}}' (change)='totalAmountChange()' [(ngModel)]=obj.rate>

                        <input type='text' name='amount{{i}}'  [(ngModel)]=obj.rate*obj.quantity>

                        <input type='text' name='tax{{i}}' [(ngModel)]=obj.tax>

                        <button class="table_button"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-trash" viewBox="0 0 16 16">
                            <path d="M5.5 5.5A.5.5 0 0 1 6 6v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm2.5 0a.5.5 0 0 1 .5.5v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm3 .5a.5.5 0 0 0-1 0v6a.5.5 0 0 0 1 0V6z"/>
                            <path fill-rule="evenodd" d="M14.5 3a1 1 0 0 1-1 1H13v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V4h-.5a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1H6a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1h3.5a1 1 0 0 1 1 1v1zM4.118 4L4 4.059V13a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1V4.059L11.882 4H4.118zM2.5 3V2h11v1h-11z"/>
                          </svg></button>

<button (click)='pdfCreationClick()'>Save and Send</button>

This is the HTML content that contains the input fields so after typing the data in input fields if we click on the save, it needs to convert into a pdf page which must contain the table whatever the data I had given.
please help me. I am unable to find the answer, for three days.
any suggestions other than this jspdf also encouraged
Here the issue is not to click event. The main issue is when the table contains the input tags the data which is present in the input tags is not printing in pdf.
Comment: Why don't use just an onclick=""?
Answer: Add an on click event in your save button to call your pdf creator function i.e.,
<button class="table_button" (click)="pdfCreationClick()">
   ...
</button>


ThreeJS Updates Outside Loop

Question: It's not clear if it's ok to update values outside of the animate() loop.
Would updates outside the loop affect render performance?
The only disadvantage I can see is some updates may be partially complete, having to wait for the next animate call to fully appear.
Any disadvantage I am missing?
function animate() {
    requestAnimationFrame( animate )
    updatePositions()
}

vs.
function animate() {
    requestAnimationFrame( animate )
}

function onWebSocketUpdate() {
    updatePositions()
}

Another way of looking at it:
onWebSocketUpdate(data) {

  // Option 1
  // ws directly applies the update
  model.update(data)

  // Option 2
  // ws saves data to buffer
  buffer.push(data)
  // when animate() runs, it pops buffer data
  model.update(buffer.pop())
}

Answer: If your web socket sends updates to change an object position (which is the case I guess) you have two cases:

If the updates come with higher frequency then your frame rate, you should run updatePositions() inside the animate(). You don't need more than one position update in between frames.
If the updates come with lower frequency then your frame rate, It's better to update positions outside of the animate(). You'll save some performance by not calling updatePositions() on every frame

ThreeJS Updates Outside Loop


Within a field template, how can I print the value of another field from the same node?

Question: I have an email field that I would like to present on the node as a name that links to the email address. As such, I am trying to edit the email field template to embed the name from a text field. However, I'm having difficulty figuring out how to access the content of this text field. I've gotten as far as figuring out that twig(_context['element']['#object']) will give me some info about the node object, but I cannot figure out how to access the field values. Am I even in the right ballpark for accessing this data?
Comment: Use preprocess function to get to the node object from the field(i think it's either getParent() or getEntity() method) and either put the whole node into the variables or just the field you want to access...or just the value of course.
Comment: As of drupal 8.4+ the following debug string will show properties of the node in a field html twig file:

`{{ dump(_context['element']['#object']) }}`

Note that twig debugging should be enabled in the sitewide services.yml file.
Answer: This is the node object that you have found in the field template.
You can access the field values like this:
{{ element['#object'].field_field1.value }}

Comment: Perfect, thanks! Do you have any good resources for this aspect of theming in D8?


Qual a ordem de retorno dos atributos da função getelementbyid?

Question: O site do w3cschools tem um exemplo da função getelementbyid(). Acontece que em cada navegador esse exemplo tem um retorno diferente e eu não consigui encontrar uma resposta do pq disso. Alguém faz ideia do pq isso acontece?
o exemplo é esse:
<!DOCTYPE html>

Click the button to display each attribute's name and value of the image above.

<button onclick="myFunction()">Try it</button>

As respostas de cada browser são essas:
- Firefox 30.0:

    width = 150
    height = 113
    src = klematis.jpg
    alt = Flower
    id = myImg

 - Chrome 36.0.1985.125:

    id = myImg
    alt = Flower
    src = klematis.jpg
    width = 150
    height = 113

 - IE 11.0.9600.17207

    width = 150
    height = 113
    id = myImg
    alt = Flower
    src = klematis.jpg

Por exemplo, se eu quiser ter acesso ao atributo id no ff o índice vai ser 4, no chrome vai ser 0 e no IE vai ser 2.
Comment: A ordem é irrelevante nesse caso não acha? uma vez que você pode acessar os atributos do objeto associativamente pelo nome. Creio que as ordens diferentes se dão pelo simples fato de como cada navegador ordena os atributos na memória.
Answer: Todo elemento do DOM, acessível via JavaScript (seja retornado por document.getElementById seja por outros meios) possuem uma propriedade attribute que é do tipo NamedNodeMap. Traduzindo livremente da especificação linkada acima (ênfase minha):

Objetos implementando a interface NamedNodeMap são usados para representar coleções de Nodes que podem ser acessados via nome. Note que o NamedNodeMap não herda de NodeList; NamedNodeMaps não são mantidos em nenhuma ordem em particular. Objetos contidos em um objeto implementando NamedNodeMap podem também ser acessados por um índice ordinal, mas isso é simplesmente para permitir uma enumeração conveniente dos conteúdos de um NamedNodeMap, o que não implica que o DOM especifica uma ordem a esses Nodes.

Ou seja, como a especificação não impõe nenhuma ordem, cada browser é livre para implementar do jeito que quiser (inclusive mudar a ordem dinamicamente durante o ciclo de vida da página). Não se deve portanto depender de uma ordem específica ao se fazer uso dessa API.
Como apontado por Cahe nos comentários, a melhor maneira de se acessar esses atributos é por nome, e não por índice. Exemplo:
var x = document.getElementById("myImg");
var txt = "";
txt = txt + "id = "     + x.attributes.getNamedItem("id").value + "
";
txt = txt + "src = "    + x.attributes.getNamedItem("src").value + "
";
txt = txt + "width = "  + x.attributes.getNamedItem("width").value + "
";
txt = txt + "height = " + x.attributes.getNamedItem("height").value + "
";
txt = txt + "alt = "    + x.attributes.getNamedItem("src").value + "
";
document.getElementById("demo").innerHTML = txt;

Ou simplesmente (cuidado com colisões de nomes):
var x = document.getElementById("myImg");
var txt = "";
txt = txt + "id = "     + x.attributes.id.value + "
";
txt = txt + "src = "    + x.attributes.src.value + "
";
txt = txt + "width = "  + x.attributes.width.value + "
";
txt = txt + "height = " + x.attributes.height.value + "
";
txt = txt + "alt = "    + x.attributes.src.value + "
";
document.getElementById("demo").innerHTML = txt;


why is the node id missing from the comment:edit action?

Question: When I setup a trigger on comment creation and edit that fires the action "send email" I have the folling tags available in the action editor that seem to be missing the nid on output:
<code>[comment:edit-url]
[comment:url]
[comment:url:absolute]
</code>
This gives me the following output in emails
<code>http://example.com/comment//edit
http://example.com/comment/#comment-
http://example.com/comment/#comment-
</code>
Is this a flaw in the D7 or and I not doing it right?
Thanks in advance for any insights.
Answer: @Denford: You are right in saying that comments do have ids. They are just called cids and not nids :-)
What is the trigger that you are firing? My guess is that for a new comment posted, you are not seeing the 'cids' because they would be available only to the trigger 'after saving a new comment' and not the trigger 'when either saving a new comment or updating.. blah blah'.
Comment: Cheers Sumeet, that was the solution.
Answer: I may be wrong, but I don't believe comments are considered "nodes" in the traditional Drupal sense.
The terminology is in flux, but traditionally nodes refer to pieces of content.
I believe comments now fit into the scheme as an entity, as just about everything else in Drupal now does.
This ambiguity is sort of an issue now with the advent of the entity system.
Comment: Hi David, thanks for you thoughts. When I add in the (not nid?) id to the // part of the first url it works as I would expect, taking me to the a page with just the comment to be edited. So comments seem to have id's, actions just seems to not know about them though.


How to export 1 or several specific rules?

Question: I want to export one or more specific rules or components using Drush.
I do have a script to export all the rules and components.
drush --pipe rules-list | xargs -I{}  sh -c "drush rules-export '{}' > '20210623-new-Rules-export-offline/{}.txt'"

20210623-new-Rules-export-offline is the directory where the exported rules are saved.
Is there something I need to change to this code in order to export the specific rules I want to export?
I created a Rules VBO View to have better access to all those rules, but the export to a file feature doesn't seem to be provided.
Comment: If I understand the question correctly, instead of exporting all the rules, you want to export only specific rules for which you provide the name. Is that what you are trying to achieve?
Answer: drush rules-list is used to list all the Rules on your site.
drush rules-export <rule-machine-name> will export a specific Rule.
The command you show above simply takes the output of the rules-list command and passes it to rules-export, in effect looping over all the Rules and exporting each one.
Comment: Thank you @anonymous
Comment: I tried this for 1 rule and this does indeed work but it shows the exported code in the Terminal so that I still have to copy and paste it into its own text file. This is what I've done to export 1 rule into its own text file with the machine name as its file: `drush rules-export my_rule_1 > my_rule_1.txt`. If I try 2 rules and I use this command, it only exports the first one: `drush rules-export my_rule_1 my_rule_2 > my_exported_rules.txt`. I must be missing the correct delimiter.
Answer: To export more than one rule, but only the rules whose name is given in a list, I would use the following code.
#!/usr/bin/bash

# The list of item names to export
items=(item1 item2 item3)
for item in "${items[@]}"; do
  drush rules-export "$item" > "${item}.txt"
done

This is simpler than getting the list of existing rules from drush rules-list --pipe, remove the items in that list that don't match the rule names you want to export, and then run drush rules-export on the left items.
If you had a list of names, which could be either component names or rule names, and you wanted to export only rules, the code would be similar to the following one.
#!/usr/bin/bash

# The list of items to export, which could include component names
names=(name1 name2 name3)

# Get a list of rule names only, and convert it in an array.
rules=( $(drush rules-list --pipe --type=rule) )

# Create an array with items that are in both the arrays.
exports=( $(comm -12 <(printf '%s\n' "${names[@]}" | LC_ALL=C sort) <(printf '%s\n' "${rules[@]}" | LC_ALL=C sort)) )

# Export the items whose names are in the exports array, which contains only rule names.
for export in "${exports[@]}"; do
  drush rules-export "$export" > "${export}.txt"
done

Comment: While this is all true, this answer is really about shell programming rather than drush or Rules or even Drupal. There are of course many ways to use the basic drush rules-export command to loop over a set of inputs, but these are operating-system dependent and scripting-language dependent (can be done with bash, csh, python, perl .. even PHP ... etc.).
Comment: Yes, but what the question is asking requires to explain how to achieve something with the shell, given that the command shown in the question is `drush --pipe rules-list | xargs -I{}  sh -c "drush rules-export '{}' > '20210623-new-Rules-export-offline/{}.txt'"` and the question is _Is there something I need to change to this code in order to export the specific rules I want to export?_
Comment: This answer isn't just about shell, since it shows how to use a parameter accepted by `drush rules-list`.


customer commerce profile = user profile

Question: is it possible to get all registered users into commerce profiles? /admin/commerce/customer-profiles
I mean when I create an account for user drupal will automatically create a commerce profile
Answer: You've got some ways to do this, I'd look first to Commerce Extra module which allows you to have an address in the user entity and prepopulate information in the commerce checkout with this.
If you want to actually duplicate the information and have a customer profile entity for each user registered, you can use Rules module for this (it is required by Commerce), you can then create a new rule, for instance in the "After saving a new user account" event that triggers an action "Create a new entity" of type commerce customer profile and then another action, "Save entity".
You can check Drupal commerce default rule "Create a new account for an anonymous order" for a similar concept.


SQL get unique month year combos

Question: SELECT     MONTH(sessionStart) AS Expr1, YEAR(sessionStart) AS Expr2
FROM         tblStatSessions
WHERE     (projectID = 187)
GROUP BY sessionStart

This returns:

11  |  2010
11  |  2010
11  |  2010
12  |  2010
12  |  2010

But I need it to only return each instance once, IE:

11   |  2010
12   |  2010

If that makes sense!
Answer: The following should be what you want:
SELECT     MONTH(sessionStart) AS Expr1, YEAR(sessionStart) AS Expr2
FROM         tblStatSessions
WHERE     (projectID = 187)
GROUP BY MONTH(sessionStart), YEAR(sessionStart)

in general you need to group by every non-aggregate column that you are selecting. Some DBMSs, such as Oracle, enforce this, i.e. not doing so results in an error rather than 'strange' query execution.
Answer: Try:
SELECT     MONTH(sessionStart) AS Expr1, YEAR(sessionStart) AS Expr2
FROM         tblStatSessions
WHERE     (projectID = 187)
GROUP BY Expr1

SQL get unique month year combos


Spearman Correlation Coefficient is more than one

Question: I am comparing the ranking of two lists. The lists are not very nicely correlated and the number of items is very large (6630). Is it possible to have a correlation coefficient of more than one. I followed the following link:
https://en.wikipedia.org/wiki/Spearman%27s_rank_correlation_coefficient#Definition_and_calculation
My code gives correct result for the hours and tv example. However, when I run the same on the large list, the ranking correlation is more than one. I am not able to figure out why.
Comment: It's going to be difficult to figure out on the information given. Note that from the formula on the page you link to, to get a value bigger than 1, $\sum d_i^2$ would have to be negative (which is not possible). What value did you get for $\sum d_i^2$?
Comment: I made a mistake while computing.
Comment: It would be interesting to see how you can have had the correct answer on the example from the wikipedia page if the code was wrong.
Comment: I still don't know. Do you want me to share the code?
Comment: It would be off topic here, so probably best not. It was more idle curiosity. Thanks anyway.
Answer: Note that from the formula on the page you link to the sample value of $\rho_s$ is $1-\frac{\sum_i 6d_i^2}{n(n^2-1)}$.
Consequently, to get a value bigger than 1, $\sum d_i^2$ would have to be negative (which is not possible).
This suggests a problem with the calculation.


Access libvirt+KVM virtual machines with DNS

Question: I have an Ubuntu Trusty machine running KVM + Libvirt to manage small virtual machines, and using the standard NetworkManager to connect to regular networks.
I want to be able to access the virtual machines via DNS from the host.
Libvirt uses a virtual private subnet (192.168.122.0/24), NAT'd to access the rest of the world via a bridge (virbr0) on my eth0. Dnamasq priveds DHCP+DNS to this virtual network.
This is the libvirt config for the virtual network:
<network>
  <name>default</name>
  <uuid>400c59ff-c276-4154-ab73-9a8a8d1c6be3</uuid>
  <forward mode='nat'>
    <nat>
      <port start='1024' end='65535'/>
    </nat>
  </forward>
  <bridge name='virbr0' stp='on' delay='0'/>
  <mac address='52:54:00:f4:bd:37'/>
  <domain name='kvm'/>
  <dns forwardPlainNames='no'>
    <forwarder addr='127.0.1.1'/>
    <host ip='192.168.122.1'>
      <hostname>host</hostname>
      <hostname>host.kvm</hostname>
    </host>
  </dns>
  <ip address='192.168.122.1' netmask='255.255.255.0'>
    <dhcp>
      <range start='192.168.122.2' end='192.168.122.254'/>
    </dhcp>
  </ip>
</network>

Libvirt starts a dnsmasq instance listening on 192.168.122.1:53 which answers all requests for .knv and forwards any other requests to my host. This dnsmasq config is automatically generated by libvirt:
/var/lib/libvirt/dnsmasq/default.conf
##WARNING:  THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
##OVERWRITTEN AND LOST.  Changes to this configuration should be made using:
##    virsh net-edit default
## or other application using the libvirt API.
##
## dnsmasq conf file created by libvirt
strict-order
user=libvirt-dnsmasq
no-resolv
server=127.0.1.1
domain=kvm
expand-hosts
domain-needed
local=//
pid-file=/var/run/libvirt/network/default.pid
except-interface=lo
bind-dynamic
interface=virbr0
dhcp-range=192.168.122.2,192.168.122.254
dhcp-no-override
dhcp-leasefile=/var/lib/libvirt/dnsmasq/default.leases
dhcp-lease-max=253
dhcp-hostsfile=/var/lib/libvirt/dnsmasq/default.hostsfile
addn-hosts=/var/lib/libvirt/dnsmasq/default.addnhosts

NetworkManager has an instance of dnsmasq listening on 127.0.1.1:53 which it uses for all DNS quieries before passing to whichever DNS servers my host gets assigned by the external DHCP system.
In order for my host Ubuntu system to use the dnsmasq of libvirt, I point the dnsmasq of NetworkManager to use 192.168.122.1 for the domain kvm:
/etc/NetworkManager/dnsmasq.d/libvirt.conf
server=/kvm/192.168.122.1

And this works, for the most part...
me@host ~ $ ps aufx
...cut...
root     11010  0.2  0.0 342084  6348 ?        Ssl  10:59   0:00 NetworkManager
root     11018  0.0  0.0  10232  3732 ?        S    10:59   0:00  \_ /sbin/dhclient -d -sf /usr/lib/NetworkManager/nm-dhcp-client.action -pf /run/sendsigs.omit.d/network-manager.dhclient-eth0.pid -lf /var/lib/NetworkManager/dhclient-b8043
nobody   11228  0.0  0.0  32252  1564 ?        S    10:59   0:00  \_ /usr/sbin/dnsmasq --no-resolv --keep-in-foreground --no-hosts --bind-interfaces --pid-file=/run/sendsigs.omit.d/network-manager.dnsmasq.pid --listen-address=127.0.1.1 --
root     11033  1.0  0.1 513356 15160 ?        Sl   10:59   0:01 /usr/sbin/libvirtd -d
libvirt+ 11085  0.0  0.0  28208   948 ?        S    10:59   0:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf

me@host ~ $ sudo netstat -nulpd | grep dnsmasq
udp  0  0  127.0.1.1:53      0.0.0.0:*  11228/dnsmasq
udp  0  0  192.168.122.1:53  0.0.0.0:*  11085/dnsmasq
udp  0  0  0.0.0.0:67        0.0.0.0:*  11085/dnsmasq

me@host ~ $ host test.kvm
test.kvm has address 192.168.122.193
;; connection timed out; no servers could be reached
;; connection timed out; no servers could be reached

But creates a massive number of dnsmasq AAAA queries all waiting for a response.
me@host ~ $ sudo netstat -nulpd | grep dnsmasq
udp  0  0  0.0.0.0:39329  0.0.0.0:*  11228/dnsmasq
udp  0  0  0.0.0.0:2469   0.0.0.0:*  11085/dnsmasq
udp  0  0  0.0.0.0:14805  0.0.0.0:*  11228/dnsmasq
...cut...
udp  0  0  0.0.0.0:51569  0.0.0.0:*  11228/dnsmasq
udp  0  0  0.0.0.0:31091  0.0.0.0:*  11085/dnsmasq
udp  0  0  0.0.0.0:39305  0.0.0.0:*  11085/dnsmasq

me@host ~ $ sudo netstat -nulpd | grep dnsmasq | wc -l
131

And a tcpdump shows them to be mainly AAAA requests:
me@host ~ $ sudo tcpdump -vni any udp port 53
tcpdump: listening on any, link-type LINUX_SLL (Linux cooked), capture size 65535 bytes
11:04:49.453864 IP (tos 0x0, ttl 64, id 56217, offset 0, flags [none], proto UDP (17), length 55)
    127.0.0.1.58535 > 127.0.1.1.53: 31275+ A? mysql.kvm. (27)
11:04:49.453948 IP (tos 0x0, ttl 64, id 20062, offset 0, flags [DF], proto UDP (17), length 55)
    192.168.122.1.7098 > 192.168.122.1.53: 41491+ A? mysql.kvm. (27)
11:04:49.454013 IP (tos 0x0, ttl 64, id 20063, offset 0, flags [DF], proto UDP (17), length 71)
    192.168.122.1.53 > 192.168.122.1.7098: 41491* 1/0/0 mysql.kvm. A 192.168.122.193 (43)
11:04:49.454068 IP (tos 0x0, ttl 64, id 37088, offset 0, flags [DF], proto UDP (17), length 71)
    127.0.1.1.53 > 127.0.0.1.58535: 31275* 1/0/0 mysql.kvm. A 192.168.122.193 (43)
11:04:49.454321 IP (tos 0x0, ttl 64, id 56218, offset 0, flags [none], proto UDP (17), length 55)
    127.0.0.1.56040 > 127.0.1.1.53: 47999+ AAAA? mysql.kvm. (27)
11:04:49.454381 IP (tos 0x0, ttl 64, id 20064, offset 0, flags [DF], proto UDP (17), length 55)
    192.168.122.1.19631 > 192.168.122.1.53: 20542+ AAAA? mysql.kvm. (27)
...cut...
11:05:09.510237 IP (tos 0x0, ttl 64, id 20515, offset 0, flags [DF], proto UDP (17), length 55)
    192.168.122.1.19631 > 192.168.122.1.53: 35761+ MX? mysql.kvm. (27)
11:05:09.510237 IP (tos 0x0, ttl 64, id 56674, offset 0, flags [DF], proto UDP (17), length 55)
    127.0.0.1.46085 > 127.0.1.1.53: 53641+ AAAA? mysql.kvm. (27)
11:05:09.510315 IP (tos 0x0, ttl 64, id 56675, offset 0, flags [DF], proto UDP (17), length 55)
    127.0.0.1.46085 > 127.0.1.1.53: 26166+ MX? mysql.kvm. (27)
11:05:09.510334 IP (tos 0x0, ttl 64, id 20516, offset 0, flags [DF], proto UDP (17), length 55)
    192.168.122.1.19631 > 192.168.122.1.53: 4247+ AAAA? mysql.kvm. (27)
11:05:09.510407 IP (tos 0x0, ttl 64, id 56676, offset 0, flags [DF], proto UDP (17), length 55)
    127.0.0.1.46085 > 127.0.1.1.53: 49331+ AAAA? mysql.kvm. (27)
11:05:09.510433 IP (tos 0x0, ttl 64, id 20517, offset 0, flags [DF], proto UDP (17), length 55)
    192.168.122.1.19631 > 192.168.122.1.53: 63294+ MX? mysql.kvm. (27)
^C
934 packets captured
1857 packets received by filter
0 packets dropped by kernel

I tried lowering the priority of AAAA records in /etc/gai.conf
precedence ::ffff:0:0/96  100

Even tried disabling IPv6 entirely /etc/sysctl.conf:
# Disable IPv6
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1

But the AAAA requests are still being sent and name resolution becomes unbearably slow.
Is there a way for either libvirt or NetworkManager to ignore or respond negatively to these requests so I don't have to wait for all the requests to time out before using the A record that was already received?
Answer: If a forwarder is configured, dnsmasq will forward all DNS queries that it has no explicit data for. This includes records for configured static DHCP clients that have no active lease, AAAA records unless IPv6 addresses are defined explicitly, and more.
There are several ways to avoid this:
Don't configure a forwarder
Simply omit the fowarder entries in the network definition. Probably not desirable, unless the virtual network is really isolated. This is the only possibility that libvirt currently supports (12/2014), AFAIK.
local domain in dnsmasq.conf
Configure the domain as "local" in dnsmasq:
 domain=local.net,192.168.10.0/24
 local=/local.net/
 local=/10.168.192.in-addr.arpa/

In theory, this could be abbreviated as domain=local.net,192.168.10.0/24,local, but a dnsmasq bug fixed only recently causes this to fail.
libvirt doesn't support this. In order to use this configuration, you need to set up the bridge manually in your OS and configure the libvirt network like this:
   <network>
     <name>local</name>
     <forward mode='bridge'/>
     <bridge name='br0'/>
   </network>

You don't have to create a libvirt virtual network at all in this configuration, just use <interface 'type=bridge'> in your VM definition files.
auth zone in dnsmasq.conf
The auth-zone parameter has a similar effect to local. However it has other implications that I don't claim to fully understand. I suppose this configuration would be desirable if names in the virtual network are supposed to be resolved from the outside.
domain=local.net
auth-zone=local.net

This setup isn't supported by libvirt either, so the same procedure for setting up the bridge must be applied as above.
Answer: I think there's two positive goals for a DNS setup like this:

Resolving name.vm on the host (and in a guest) should return the IP address for the VM called name
Resolving example.com in the guest (and on the host) should return the IP address for example.com

Straightforwardly pointing the host resolver at the dnsmasq instance for the guest network as a forwarder, and the dnsmasq for the guest network at the host resolver, will result in unknown hosts bouncing back and forth and hanging.
This suggests two issues to avoid:

Resolving a nonexistent VM (or the AAAA record for an existent, IPv4-only VM) should promptly return NXDOMAIN/nodata
Resolving a nonexistent hostname (nonexistent.example.com) should also promptly return NXDOMAIN/nodata

Resolving name.vm at all is achieved by putting <domain name='vm' localOnly='yes'/> in the libvirtd network configuration (virsh net-edit default or whatever). I believe name='vm' is both (a) the search domain handed out over DHCP and (b) gets appended to DHCP hostnames to generate the FQDN that dnsmasq uses to put VMs in DNS. Setting localOnly means that if a name doesn't appear in the local zone, dnsmasq won't ask the upstream server -- this is the key setting to prevent dig name.vm AAAA looping.
Making name.vm resolve from the host depends on the host's resolver configuration. If using systemd-resolved, try resolvectl dns virbr0 192.168.122.1; resolvectl domain virbr0 vm; resolvectl default-route virbr0 no'. The first piece tells systemd-resolved to use the guest network's dnsmasq as a resolver. The second piece says the search domain associated with that interface is vm. With just these pieces, the host can successfully resolve name.vm and example.com. However, the third piece tells systemd-resolved to only use the guest network DNS server for the configured domains -- without this, lookups for nonexistent.example.com will loop between the host and guest network DNS resolvers.
(FWIW, another way to make name.vm ~resolve is with the libvirt NSS module https://libvirt.org/nss.html, though that doesn't use DNS as such and I haven't tried it.)
Comment: I think the "localOnly" setting I mention in my answer is "local domain" approach mentioned in the other answer (https://serverfault.com/a/653262/531369) -- looks like libvirtd added support in the last decade or so.


DialogBox positioning. Adding Class ?

Question: Might be a noobie question ... but I didnt find the solution .
I have a dialogBox ...
 $("#dialogId").dialog({ position: ['top', 80] });

Any chance I can put the position in a class ?
Answer: According to jQuery UI documentation, you can use the dialogClass option:
$("#dialogId" ).dialog({ dialogClass: "myClass" });

And in your myClass specify the position..
.myClass { top: 80px }

Comment: Doesn't work. It doesn't recognize my CSS method. Once I get that working I will accept your answer
Comment: I see, it might be more complicated with positioning.. The class is applied correctly, but the position is being overridden: http://jsfiddle.net/uS8AW/ The position option of dialog seem to be the best way how to deal with it.. You might extract the position from css with jquery and pass it.
Comment: I had to use !important .. I dont really like using it ... but , for this it got the job done
Answer: $("#dialogId").addClass("className");

And in this className set position you want.
Answer: Yes, it would be .my_positioned_dialog { position:absolute; top:80px; }

DialogBox positioning. Adding Class ?


How to add a side bar to main webpage using css

Question: This might be a straight forward question however I cannot seem to solve this so any help welcome.
I have a webpage (fluidgrid layout), what I want to do is add a side bar on either side of the main page using CSS. I want to show the side bar on either side when the screen is bigger then 1300px. I would like these side bars to be as tall as the page is. Is there a way to do this using CSS.
html

Mainpage code here

CSS
@media only screen and (min-width:981px){
.gridContainer{width:98%;max-width:1300px;padding-left:1%;padding-right:1%;margin:auto}

Any help welcome
Comment: Have you tried floating the sidebar to either left or right side? Then set height to be the height of its parent(the page)
Comment: I have tried to put the sidebars in with div's however they stay within the 1300px of the page I just want them to go on outside of the page.
Comment: Questions seeking code help must include the shortest code necessary to reproduce it **in the question itself**.  See [**How to create a Minimal, Complete, and Verifiable example**](http://stackoverflow.com/help/mcve)
Answer: The ideas is simple, give the main container a fixed width and set the left and right margins to auto, that way, the left and right divs occupy the remaining space on each side. Then, add equal margins to the left and right of the sidebars. See example below:
HTML

side bar content

Mainpage code here

Side bar content

CSS
 @media only screen and (min-width:1300px)
{
   .left-sidebar  { display:inline-block; margin-right:10px; }
   .gridContainer { display:inline-block; width:75%; margin-left:auto; margin-right:auto; border:1px solid black; }
   .right-sidebar { display:inline-block; margin-left:10px; }
}

Comment: I would like to sidebar to set their width auto so it evens out left and right and keep the gridContainer at 1300px. So for example when screen width is 1500 the sidebars on each side a 100 but this will be set automatically.
Comment: In that case, you set the .gridContainer to width of auto, and let the left and right sidebars fill the remaining space. Updating my code to reflect it.
Comment: thanks for your quick reply, however this didn't work. I left the div's empty so the background color can take over (black). Only if you set a height for them it fills. The problem is it does fill the whole div from left to right so I ended up with a bar on the top and bottom. I just want to fill out the sides next to the page once the page exceeds 1300px. Thanks for helping
Comment: That's because a `` is a block level element. To fix it, set it to display as `inline-block`. I assumed you already knew that. Anyway, I have updated my answer.
Comment: Sorry, that's not done the trick, the main page is now moved to the left with 10px margin (I presume) to the left. No auto fill with black to the left or right as I set the background-color:#000000;
Comment: I've updated my code, and tested it out and it works.


Finding a volume using the method of cylindrical shells which is generated by a parabola

Question: This problem is from the 7th edition of the book "Calculus and Analytic Geometry" by George Thomas
and Ross Finney. It is problem number 3 of section 5.4
Problem:
Find the volume generated when the region bounded by the given curves and lines is revolved about the
x-axis. (Note: $x = 0$ is the y-axis and $y = 0$ is the x-axis.)
\begin{align*}
y &= 3x - x^2 \\
y &= x
\end{align*}
Answer:
I am going to use the method of cylindrical shells to compute the volume. Let $V$ be the volume we are asked to find.
The general form for $V$ when we are revolving about the x-axis is:
$$ V = \int_a^b 2 \pi x f(x) \,\, dx $$
where $2 \pi x$ represents the circumference of the region. Since we are going around the x-axis $a = 0$. To find $b$ be we set up the following equation:
\begin{align*}
3x - x^2 &= x \\
2x - x^2 &= 0 \\
x^2 - 2x &= 0 \\
x(x-2) &= 0 \\
x = 0 \,&\text{ or } \, x = 2 \\
V &= \int_0^2 2 \pi x (  3x - x^2 - x) \,\, dx \\
V &= 2 \pi \int_0^2 x (  2x - x^2 ) \,\, dx \\
\int_0^2 x (  2x - x^2 ) \,\, dx &= \int_0^2 2x^2 - x^3 \,\, dx \\
\int_0^2 x (  2x - x^2 ) \,\, dx &= \frac{2x^3}{3} - \frac{x^4}{4} \Big|_0^2 \\
\int_0^2 x (  2x - x^2 ) \,\, dx &=  \frac{2(8)}{3} - \frac{16}{4} = \frac{16}{3} - 4 \\
\int_0^2 x (  2x - x^2 ) \,\, dx &= \frac{4}{3} \\
%
V &=  2 \pi \left(   \frac{4}{3} \right)  \\
V &= \frac{8 \pi}{3}
\end{align*}
The book's answer is:  $\frac{56\pi}{15}$
Where did I go wrong?
Comment: You can do it fine by integrating with respect to $x$, but then you need to look at cross-sections (which will be washers in this case).
Comment: at one point you said about the $x$-axis, and, at another, $y$-axis !?
Comment: It is the x-axis. I corrected the post. I am starting to think I should integrate with respect to $dy$ not $dx$.
Answer: You said that you would use shells but you have actually used washers. The volume should be $$V=\int_0^2 2\pi y f(x) dx$$ Here $f(x)=(3x-x^2)-x$ is the length of the rotated vertical element and $y=\frac12 ((3x-x^2)+x)$ is the distance of the centroid (= mid-point) of the rotated element from the $x$ axis.
If you were to use shells then the volume would be $$V=\int_0^{9/4} 2\pi y g(y) dy$$ This is more difficult. The upper limit of integration is the peak of the parabola. $y$ is the distance of the rotated horizontal element from the $x$ axis. $g(y)$ is the length of the rotated horizontal element. It is a compound function. For $y=0..2$ it spans between the left side of the parabola and the straight line : $g(y)=x_0-x_1$ where $x_0=y$ and $x_1$ is the smaller solution of $x^2-3x+y=0$. For $y=2..9/4$ it spans between the left and right sides of the parabola : $g(y)=x_2-x_1$ where $x_2$ is the larger solution of $x^2-3x+y=0$.


How do I output a single value from a DoFn and use that as a parameter in another DoFn?

Question: I have a pub/sub with line delimited jsons. Each pub/sub message has an attribute value with the bigquery table name to write to.
How would I get the individual table name value, and pass it to a new pipeline?
Is it ok to create a new PCollection and apply it... from within a DoFn itself?
Answer:
You can apply a transformation to retrieve the table name within a DoFn and pass a KV pair of <tableName, record> downstream. Then use the dynamic destination support within BigQueryIO to route each record to the correct destination. Alternatively, you can also do the retrieval of the table attribute within the BigQuery.withFormatFunction(). Below is an example of doing just that.
Here is the overall pipeline structure where JSON messages are consumed from Pub/Sub and then routed to the proper table destination based on a Pub/Sub message attribute. Similarly, you could change the getTableDestination(..) logic to retrieve the table name from within the JSON record instead.
You can view this entire example here.
  /**
   * Runs the pipeline to completion with the specified options. This method does not wait until the
   * pipeline is finished before returning. Invoke {@code result.waitUntilFinish()} on the result
   * object to block until the pipeline is finished running if blocking programmatic execution is
   * required.
   *
   * @param options The execution options.
   * @return The pipeline result.
   */
  public static PipelineResult run(Options options) {

    // Create the pipeline
    Pipeline pipeline = Pipeline.create(options);

    // Retrieve non-serializable parameters
    String tableNameAttr = options.getTableNameAttr();
    String outputTableProject = options.getOutputTableProject();
    String outputTableDataset = options.getOutputTableDataset();

    // Build & execute pipeline
    pipeline
        .apply(
            "ReadMessages",
            PubsubIO.readMessagesWithAttributes().fromSubscription(options.getSubscription()))
        .apply(
            "WriteToBigQuery",
            BigQueryIO.<PubsubMessage>write()
                .to(
                    input ->
                        getTableDestination(
                            input,
                            tableNameAttr,
                            outputTableProject,
                            outputTableDataset))
                .withFormatFunction(
                    (PubsubMessage msg) -> convertJsonToTableRow(new String(msg.getPayload())))
                .withCreateDisposition(CreateDisposition.CREATE_NEVER)
                .withWriteDisposition(WriteDisposition.WRITE_APPEND));

    return pipeline.run();
  }

  /**
   * Retrieves the {@link TableDestination} for the {@link PubsubMessage} by extracting and
   * formatting the value of the {@code tableNameAttr} attribute. If the message is null, a {@link
   * RuntimeException} will be thrown because the message is unable to be routed.
   *
   * @param value The message to extract the table name from.
   * @param tableNameAttr The name of the attribute within the message which contains the table
   *     name.
   * @param outputProject The project which the table resides.
   * @param outputDataset The dataset which the table resides.
   * @return The destination to route the input message to.
   */
  @VisibleForTesting
   static TableDestination getTableDestination(
      ValueInSingleWindow<PubsubMessage> value,
      String tableNameAttr,
      String outputProject,
      String outputDataset) {
    PubsubMessage message = value.getValue();

    TableDestination destination;
    if (message != null) {
      destination =
          new TableDestination(
              String.format(
                  "%s:%s.%s",
                  outputProject, outputDataset, message.getAttributeMap().get(tableNameAttr)),
              null);
    } else {
      throw new RuntimeException(
          "Cannot retrieve the dynamic table destination of an null message!");
    }

    return destination;
  }


CSS is imported in different order between dev and production

Question: When I run "npm run dev" my node.js components are styled in the order:

custom scss styling
custom muiTheme.tsx
then the component styles.

However, when I run "run build" + "npm run start" my node.js components are styled in the order:

custom muiTheme.tsx
then the component styles.
custom scss styling

The order in which they are imported messes up the css as the custom styles are expected to be imported first. now it shows the styling in development of node.js correctly, but not in production, because my custom styling is overwritten by the default Mui styling.
I import my custom styling file and custom muitheme into the _app.tsx.
my custom styling file: styles/styles.scss
my custom mui theme: styles/muiTheme.tsx
I've tried switching the order of the files in _app.tsx, but it makes no difference. I also looked at my local version and tried to run it in production, but this didn't work either. My research didn't come up with a good answer that worked either.
related github issues:

https://github.com/vercel/next-plugins/issues/399
https://github.com/vercel/next.js/issues/16630
Answer: I found a solution, but it's not the best. If anyone has a better way I'd like to know.
you can use double classes, double ids, id instead of classes or !important to give your own styling more importance.

double class name will trump single class name:

.custom-selector.custom-selector > .custom-selector

ID trumps class:

#custom-id > .custom-class

IDs can be duplicated, too:

#id#id > #id

stack overflow answer where i found this solution.


Joint PDF and Conditional Expectation

Question: Let joint probability density function $X_1, X_2$ be
$$f_{1,2}(x_1, x_2) = 2e^{-x_1-x_2}I_{(0<x_1<x_2<\infty)}$$
When $Y_1 = X_1/X_2, Y_2 = X_2$,
(a) Derive PDF of $Y_1$
(b) Derive $E(Y_2 \mid Y_1)$  and $Var(Y_2 \mid Y_1)$

For the (a) I had used Jacobian Transformation and get joint pdf of $y_1$ and $y_2$ which is equal to $pdf(y_1,y_2) = 2y_2e^{-y_2(y_1+1)}I_{(0<y_1<1,\; 0<y<\infty)}$then, marginalize it about $y_1$ then I get $pdf(y_1) = \dfrac{2}{(y_1+1)^2}I_{(0<y_1<1)}$
However, for (b), to derive E(Y_2\mid Y_1), do I have to find $pdf(Y2\cap Y_1)/pdf(Y_1)$ then find expectation or any other approach is possible to shorten or simplify the procedure? Any hint? (Because to find $pdf(Y_2 \cap Y_1)$, I had checked these two variables are not independent..I have some problem to proceed)
Answer: For the first part note that the quotient distribution always has the form
$$
f_Z(z) = \int_{-\infty}^{\infty} |y| f_{X_1, X_2}(zy, y) dy
$$
(it is easy to see this by calculating $P(X_1 < z X_2)$ and then differentiating by $z$ to obtain the PDF).
In this case, this is
$$
\int_{-\infty}^{\infty} |y| 2e^{-zy -y} I_{(0<zy < y <\infty)} dy.
$$
Since $0 < y$, the integrand is non-zero for $z < 1$, and for that we have
$$
\int_{0}^{\infty} y 2e^{-y(z + 1)} dy,
$$
which is easy to solve.

For the second part, note that
$$
E[Y_2|Y_1=y_1] = E[X_2|X_1 = y_1 X_2] =
\int x_2 2e^{-y_1 x_2 -x_2}I_{(0<y_1 x_2 <x_2<\infty)} d x_2
$$
which is very similar to the first part.

Joint PDF and Conditional Expectation


proof of infinite Primes of the Form 4n-1

Question: would like help on the proof, I have most of it but got stuck in one part.
my proof is:
lets assume there are finite number of primes in the form 4n-1. let P be their product, define N=4P-1. so none of the primes of the form 4n-1 divide N yet there is a prime that divide N, say q.
I know I need to show that q is of the form 4n-1 but have no idea how to prove it, would greatly appreciate your help
Comment: The product of two primes of the form $4n+1$ is again of the form $4n+1,$ so it can't be the case that every prime dividing $4P-1$ is of the form $4n+1.$
Comment: How does it help me? sorry for the lack of knowledge but i'm just starting to learn number theory
Comment: Well, $P-1$ is divisible by an odd prime, and if not every prime dividing it is of the form $4n+1$ at least one must be of the form $4n-1$.
Comment: saulspatz, why must it be of the form 4n+1 or 4n-1? can't there be other forms?
Answer: Suppose toward a contradiction that there is no prime of the form $4n-1$ that divides $N=4P-1$. Then every prime that divides $N=4P-1$ is of the form $4n+1$. But then the product of these primes is also of the form $4n+1$, contradicting the fact that their product is $N=4P-1$. Hence there exists a prime of the form $4n-1$ that divides $N=4P-1$.
Comment: Okay, I wasn't familiar that every prime must be of the form 4n+1 or 4n-1. why is it true?
Comment: @IdanDaniel Because every number is of the form $4n$, $4n+1$, $4n+2$ or $4n+3$.
Comment: ... and $4n$ or $4n+2$ can't be prime as they are divisible by $4$ and $2$ respectively.
Comment: ...except if they equal $2$.
Comment: so what about the form 4n+3? are we saying it can always be replaced by the form 4n-1?
Comment: @IdanDaniel I do not understand what you are asking.
Comment: I mean every prime number of the form 4n+3 can be written as 4t-1?
Comment: Yes, exactly; take $t=n+1$.
Comment: Ok, sorry for I guess obvious questions. My professor never bothered to say every prime number must be of the two forms
Comment: @IdanDaniel and Servaes Please *search* before asking and answering FAQs. Rampant duplication is not good for the site.
Comment: @BillDubuque As similar as these questions are (as are a dozen others), OP's specific question about this proof is not adressed in the supposed duplicate questions. Though the answers in  the second question do seem helpful, at least.
Comment: @Servaes Your answer is a dupe of tens (if not hundres) of prior answers.
Comment: @BillDubuque Ok, I don't see it in the linked questions, but I also don't see a problem if it were.