Python Tkinter - Using time.clock with tkinter

Question: I wanted to create a tkinter function where you have some variables dependent upon time. I wanted it so that every so often the people variable will update with every increment of time. For this example I wanted to make it so that it mimicked customers coming into a store every 5 seconds. Thing is when I click on the menu for customers it doesn't update. How do I get it to update? The time.clock() function updates.
import time
from Tkinter import *
import tkMessageBox

mGui = Tk()
mGui.title("Experiment")
mGui.geometry('450x450+500+300')

def customers():
        tkMessageBox.showinfo(title="Customers", message=people)

def timer():
        tkMessageBox.showinfo(title="Customers", message=time.clock())

people = time.clock()/5

label1 = Label(mGui, text = "label 1").pack()

##Menu
menubar = Menu(mGui)
filemenu = Menu(menubar, tearoff = 0)

menubar.add_cascade(label="In Line", menu=filemenu)

filemenu.add_command(label="Customers", command = customers)
filemenu.add_command(label="Time", command = timer)
mGui.config(menu=menubar)

mGui.mainloop()

Comment: You're diving into the deep end here! To make this work you'll have to glean some knowledge of threading and messaging, as well as delta time. It's not impossible, but it is BROAD.
Comment: No `time.clock()`, no `time.sleep()` only `tkinter.after(millisecond, function name)`
Comment: @furas I wouldn't trust `tkinter.after` to run every `millisecond` interval. Better to run some sort of timedelta function every short period of time and rely on that instead. Even if you're calling `after(5000, foo)` and your `foo` is running every 5,005ms, you're quickly running behind.
Answer: Essentially because you're only calling it once. Your variable people is set to be time.clock() exactly one time -- it does not update the way you think it should, so when you call customers it displays the same old value as always.
A quick fix could be:
def customers():
    people = time.clock()//5 # // is integer division. Equivalent to math.floor(x/y)
    tkMessageBox.showinfo(title="Customers", message=people)
def timer():
    tkMessageBox.showinfo(title="Timer", message=time.clock()

That said, this is probably not the BEST way to implement it, since you have to click a button to see each update. How about setting them to StringVars instead?
mGui = Tk() # set geometry as needed

people = StringVar(master=mGui, value='')
timer = StringVar(master=mGui, value=time.clock())

def update_customers():
    global mGui
    people.set(time.clock()//5)
    mGui.after(1000, update_customers)
    # this sets the function to run again after ~1s and re-evaluate
def update_timer():
    global mGui
    timer.set(5 - (time.clock() % 5))
    mGui.after(1000, update_timer)
    # this sets the function to run again after ~1s and re-evaluate

def start():
    global mGui, people, timer
    update_customers()
    update_timer()
    Label(mGui, text="Customers:").pack()
    Label(mGui, textvariable=people).pack()
    Label(mGui, text="Time 'till Next Customer:").pack()
    Label(mGui, textvariable=timer).pack()
    mGui.mainloop()

start()

Comment: That looks like a great way to go about it. Thanks for the feedback Adam! It is really helpful.


Tela branca em transição entre activities

Question: Tenho um projeto no qual desenvolvi um método para salvar uma referência da activity atual e quando eu utilizasse o HOME da próxima tela, ele retornasse para a activity utilizando essa referência salva.
Porém quando aperto para voltar, a tela fica totalmente branca e logo segue o fluxo desejado. Esse problema só ocorre em versões android 8.0 +.
Segue o OnOptionsItemsSelected criado:
case Android.Resource.Id.Home:
                DroidApplication.current.navigation.StartActivity(ownerActivity, DroidApplication.current.CurrentTypeActivity);
                return true;

                default:
                return base.OnOptionsItemSelected(item);

Segue o StartActivity:
 public void StartActivity(Activity activity, Type activityDestino, Dictionary<string, object> prefs)
    {
        StartActivity(activity, new Intent(activity, activityDestino), prefs);
    }

    public void StartActivity(Activity activity, Type activityDestino)
    {
        StartActivity(activity, new Intent(activity, activityDestino), null);
    }

    public void StartActivity(Activity activity, Intent intent, Dictionary<string, object> prefs)
    {
        int animationIn = Resource.Animation.fade_in;
        int animationOut = Resource.Animation.fade_out;

        StartActivity( activity, intent, animationIn, animationOut, prefs);
    }

    public void StartActivity(Activity activity, Intent intent, int animationIn, int animationOut, Dictionary<string, object> prefs)
    {
        SavePreferences(activity, prefs);
        intent.AddFlags(ActivityFlags.NoAnimation);
        intent.AddFlags(ActivityFlags.NewTask | ActivityFlags.ClearTop);
        activity.StartActivity(intent);
        //activity.OverridePendingTransition(animationIn, animationOut);
    }

Quando eu starto uma activity, não ocorre nenhum problema e eu utilizo o mesmo método:
Exemplo:
else if (codigoAcao == CODIGO_ACAO_ACTIVITY_MAIN)
        {
            DroidApplication.retornarInicial = false;
            StartActivity(activity, typeof(MainActivity));
        }

Answer: Consegui resolver meu problema...
Quando eu utilizava isso:
 intent.AddFlags(ActivityFlags.NoAnimation);
 intent.AddFlags(ActivityFlags.NewTask | ActivityFlags.ClearTop);

Toda a pilha de activities era limpada. Isso fazia com que minhas referências ficassem perdidas e quando eu retornava para a activity, eu teria que recarregá-la... Esse tempo de criação da tela ficava branco e só depois o layout aparecia...
Então a solução foi retirar essas linhas de código que foi resolvido.
Comment: Só precisa remover isso intent.AddFlags(ActivityFlags.NewTask | ActivityFlags.ClearTop); a Flag NoAnimation não precisa remover.


rbash with sftp

Question: I would like to know if it's possible to have sftp access with rbash enabled on the users, if not Is there any alternative to rbash?
Thanks
Comment: Try it, see what happens, and if you run into any errors let us know and we'll try to help out.
Comment: I tried but Its not allowing it, I found an alternative here: http://wiki.tony-su.com/How_to_restrict_sftp_user_in_Ubuntu
Answer: from what i've learned - rbash won't work with sftp.  a shell, scp, yes.  sftp; no.
probably the best alternative is rssh.  it allows for chrooting and specific access to any/all of:  scp, sftp, cvs, rdist, and rsync.
the trickiest part is creating per-user chroot "jails", as each jail must contain everything (directory structure and shared libraries) to the binaries you allow to be run (e.g. sftp which usually resides in /usr/libexec/sftp-server).  but you can even use "hard links" among the several jails to save the space of having a copy of every shared library in each jail.
Answer: Old topic, but it is worth putting correct answer here:
in order to allow SFTP working with SSH, one need to change the Subsystem in sshd_config:
<code>~$ grep Subsystem /etc/ssh/sshd_config
# Subsystem sftp /usr/lib/openssh/sftp-server
Subsystem sftp internal-sftp
</code>

rbash with sftp


Does this inequality hold for two finite sequences?

Question: Does this inequality hold?
Parameter conditions: $a>0$, $x_i\in(-\frac{1}{a},\frac{1}{a})$, $y_i\geq 0$, integer $N\geq 2$.
The inequality:
$$
\displaystyle \frac{\frac{\sum_{i=1}^{N}y_i}{N^2}}{1-a^2(\frac{\sum_{i=1}^N x_i}{N})^2}\leq \frac{1}{N}\sum_{i=1}^N \frac{y_i}{1-a^2 x_i^2}
$$
I have not found any simulation example to disprove this inequality. I have only found out under certain conditions, the inequality holds. I am wondering whether this inequality exists for general conditions as listed above.
Answer: First, the Cauchy-Schwarz Inequality asserts that:
$$
\left(\sum_{i=1}^N x_i\right)^2 \leq N\sum_{i=1}^N x_i^2
$$
Therefore:
\begin{align*}
\frac{\frac{\sum_{i=1}^{N}y_i}{N^2}}{1-a^2\left(\frac{\sum_{i=1}^N x_i}{N}\right)^2} \leq \frac{\frac{\sum_{i=1}^{N}y_i}{N^2}}{1-a^2\frac{\sum_{i=1}^N x_i^2}{N}} = \frac{1}{N} \frac{\sum_{i=1}^N y_i}{N - a^2\sum_{i=1}^N x_i^2} = \frac{1}{N} \frac{\sum_{i=1}^N y_i}{\sum_{i=1}^N (1 - a^2x_i^2)}
\end{align*}
Since $x_i \in \left(\frac{1}{a}, \frac{1}{a}\right) \implies 1 - a^2x_i^2 > 0$, we have:
$$
\left(\sum_{i=1}^N \frac{y_i}{1 - a^2x_i^2}\right)\left(\sum_{i=1}^N (1 - a^2x_i^2)\right) \geq \sum_{i=1}^N y_i
$$
The result follows.
Comment: Thank you very much!!! You really helped me a lot!


Use a laptop as a loop pedal

Question: I saw this video of Peter Bence using a loop pedal to play different sounds on a piano, then loop the sounds and play new sounds over the top of the recordings:

I would like to try looping sounds like this. Ihave a Yamaha Clavinova CVP-605 digital piano, which I can connect to my Windows 10 laptop using a USB cable. Is it possible to use my laptop as a loop pedal via the USB connection?
Answer: You can do this using a computer running a sequencer program.
The one I have to hand is Cubase 9.5.    Without going into program-specific detail, it allows me to set up markers on the sequencer timeline, and to loop constantly between them while recording data.  On eack loop I hear the previously recorded passes as well as what I'm currently playing.  When I've built up enough layers, I can drop out of Record mode but continue playing the loop.
You can do this with either audio (as Peter Bence is) or MIDI.   The USB port on your Clavinova offers a direct MIDI connection, there are also the older type round MIDI connectors, which will require a MIDI interface add-on for the computer.  Or you can  connect the audio output of the Clavinova to an audio interface on the computer. (USB does MIDI, not audio).
Answer: As far as I can see the Yamaha Clavinova CVP-605 doesn't have the ability to send audio over USB to a laptop. It does have what they call a "USB audio recorder" which I'm nearly certain just means that you can plug in a USB thumb drive and record to that so that you can manually transfer it over to a computer.
But you do have some other options:

Your Clavinova has the ability to do multitrack recording internally. I'm not sure if you can instantly loop like you could with a pedal. But you could still layer parts. I'm guessing you know about that already.
You could get an audio interface for your laptop and use the analog audio outs of the Clavinova. Then you'd use a software looper on the computer. I'm not up to speed on the software loopers available for Windows, but there's surely something.
You could get an actual loop pedal and use the analog audio outputs of the Clavinova. You'd need some kind of amp after the pedal, of course.
You could use the MIDI output of the Clavinova to use it as a controller for your laptop. Ableton Live is probably an obvious choice for this kind of thing but there are surely some free/cheap options as well. Either way the idea is that the MIDI would be looped instead of audio and the sound would also be generated from the computer using a software instrument instead of the Clavinova's sounds.

Another factor if you want to loop live like he's doing is that you'll need a pedal so that it's hands-free. It may be possible to trigger MIDI from one of the Clavinova's pedals that you aren't using and map that to the loop function in whatever software you choose. But there are dedicated MIDI pedals as well (be aware that some of these need their own MIDI interface and some already have one built in).
Comment: The MIDI/computer method doesn't HAVE to use the computer's software instruments.  MIDI can be looped back to the Clavinova.
Comment: @user37496 Thanks for the detailed answer. I wasn't actually aware of the multi-track ability on the Clavinova, but it handy even though it doesn't loop. I'm testing a few free/trial software loopers as well.
Comment: @LaurencePayne but this probably depends on the software - I haven't had much luck with Midi looping yet - audio seems to work "out of the box" with most of the software loopers I've tried. If you know more about making this work i'd be interested to know?
Answer: A lot of performers seem to be standardizing on  Ableton Live  for laptop looping in live situations.
Here's an example of what you can do for hands-free looping.  In this case, they're using a Mac but Ableton Live and Zen Audio are also available on Windows 10.

Use a laptop as a loop pedal


Display plugin block markup raw

Question: I have built a custom block plugin in Drupal 8. However, I needed to insert some svg elements in the markup, which get all filtered out. Is there a way for me to specify to display the raw output, so that the svg does not get filtered out?
  public function build() {

    return array(
      '#type' => 'markup',
      '#markup' => '
<svg>.....</svg>
',
    );
 }
?>

I have tried adding '#template' => '{{ value|raw }}' and played some with it - but could not get it to work. There must be some way to allow me to insert svg in there...
Answer: You can use an inline template:
  public function build() {

  return array(
    '#type' => 'inline_template',
    '#template' => '
<svg>{{ var }}</svg>
',
    '#context' => array(
      'var' => $svg,
    ),
  );

You can use the inline template with an empty context, if you have no vars that need to be escaped:
  return array(
        '#type' => 'inline_template',
        '#template' => '
<svg>...</svg>
',
        '#context' => array(),
      );

Display plugin block markup raw


How to query another Azure Active Directory tenant from Graph Explorer

Question: I am using Azure Graph API Explorer. I want to query the apps list in a tenant. I am user in tenant_x (where user was originally created) as well as admin in tenant_y (created later with my user). I understand that when I log in I go directly in the origin tenant (so tenant_x) therefore Graph Explorer does not allow me to query tenant_y. So as admin of tenant_y I have added a new user in tenant_y. I log in now with that user but still I am not able to query the applications that are in tenant_y. So how can I query apps in tenant_y? Is there a way? thanks.
The API I am calling (with new user log-in) to first retrieve all applications:
https://graph.microsoft.com/beta/applications

Response is:
{
"@odata.context": "https://graph.microsoft.com/beta/$metadata#applications",
"value": []
}

Of course I have apps in that tenant.
Comment: Yes, your guest user is treated as personal by Microsoft Graph Explorer. You have to use a guest user to query the apps list? Why not use a user under tenant_y to query the apps list? Just create (not invite) a user in tenant_y.
Comment: The new user you just created doesn't have enough permission. Based on https://learn.microsoft.com/en-us/graph/api/application-list?view=graph-rest-beta&tabs=http#permissions, it requires delegated permissions: `Directory.Read.All, Directory.ReadWrite.All, Directory.AccessAsUser.All`. So you need to give it the one of the permissions listed like this: https://i.stack.imgur.com/Jt9Iz.png.
Comment: Please add the details of your request to query the apps list in a tenant_y with the new user created in tenant_y, including the response.
Comment: Based on your response, it successfully returns an empty result because there are no Azure AD applications in your tenant_y. Please check the applications list on Azure Portal: https://portal.azure.com/#blade/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/RegisteredApps to see if you have any applications.
Comment: for sure there are applications. I have 3 apps.
Comment: Is your new user added in tenant_y a guest user? If it's a personal account, the result will be empty because Microsoft Graph Explorer will treat it as personal account rather than a guest user in tenant_y. Please share more details about the new user. Is it invited into tenant_y? Maybe you could provide the user name.
Comment: I have created a new gmail.com user account for me. And added it as guest in the tenant. Is this treated as personal? Then how can I have real guest?
Comment: ok i did it. Now i get error when I call this API: https://graph.microsoft.com/beta/applications, {
    "error": {
        "code": "Authorization_RequestDenied",
        "message": "Insufficient privileges to complete the operation.",
        "innerError": {
            "request-id": "4b580be2-03ce-4ff7-98c2-fd7b33a9764f",
            "date": "2020-04-01T09:55:45"
        }
    }
} Strange since I gave the user Global Reader role.
Comment: wonderful, i can finally see it! thanks lot.
Answer: Today that's possible if you pass the tenant query string parameter like this:
https://developer.microsoft.com/en-us/graph/graph-explorer?tenant=mydomainname.onmicrosoft.com

Note that you need to logout before going to this URL with the tenant query string. It'll ask you to login again. After login you can issue queries against the other tenant you have access to (not your home tenant where your account was originally created on).
If you get a 401 while running the specific query, make sure you grant the required permissions on "Modify permissions" tab and click the Consent button in each required permission. After that your query should return a 200 success result.
Answer: Based on our communication, you have used a personal account as guest of tenant_y to query the apps list in tenant_y.
Unfortunately, Microsoft Graph Explorer will not recognize your personal account as a guest user. It will still treat it as a personal account.
So it will query the apps list for the personal account rather than tenant_y.
So now you have two choices:

Create a new user in tenant_y by following add a new user and
then use this new user to log into Microsoft Graph Explorer to query
the apps list.
Implement Get access on behalf of a user and make sure that you
call {your tenant} endpoint rather than common endpoint while
requesting the access token. And you should use another tool (for
example Postman) instead of Microsoft Graph Explorer.

Update:
You can modify the permissions in Microsoft Graph Explorer like this:
Click on the "modify permissions" under your username in Microsoft Graph Explorer and check the Directory.Read.All permission.
Comment: This feature is supported now. see my answer
Answer: Graph Explorer today does not support signing in to the tenanted endpoint. A tenanted endpoint is used in the following format

https://login.microsoftonline.com/{tenantId}/V2.0

Once your user account from tenant_x is made a guest user in tenant_y, to effectively query tenant_y using your guest user account, an app (like Graph explorer) has to sign you in the other tenant. Instead Graph Explorer uses the /Common endpoint, which will always sign you in your home tenant (tenant_x).
The only available workaround is to develop a application quickly and sign-in to a tenant of your choice and run Apis in it.
Graph explorer is a tool to help developer's discover and learn about the Graph Api and thus might shy away from introducing too much complexity. But it does not hurt to ask for this feature at their Github repo.
Comment: this feature is supported now


Which is the covariate, dependent and fixed factor in GLM

Question: I am new to using SPSS and am getting confused when inputting variables. I am looking at how latitude impacts tree diversity, and how they differ between hemispheres, so want to look at the interaction.
My data is non-normal, and I am using a general linear model.
So my understanding is that tree diversity is the dependent variable. Would hemisphere (N or S) be the fixed factor or covariate? And then where does latitude come in in the model?
Any guidance would be hugely appreciated :)
Answer: Both hemisphere and latitude are fixed factors here, and tree diversity is your dependent variable.
It sounds like you're running an ANOVA, but a multiple regression might be more appropriate. In this case, add a third factor, which is hemisphere multiplied by latitude: this is the interaction term.


Why is the pearson correlation between the 40 and 60 percentile much lower than with the full range?

Question: Intuitively given the definition of pearson correlation coefficient, I thought at first that partitioning the full range to the data between the 20 and 40 percentile (closer to the median/mean for gaussian distributions) would yield a higher pearson correlation coefficient. Actually, is the other way round.
Why is this?
See the following example:
import numpy as np
from scipy.stats import pearsonr

mu_x=3
sigma_x=0.01
x = np.random.normal(mu_x, sigma_x, 100000)

mu_y= 0
sigma_y = 0.1
y = 3*x + 0.2*np.random.normal(mu_y, sigma_y, 100000)

pearsonr(x,y)
(0.83099291398880859, 0.0)

x2=x[ np.where( (x >= np.percentile(x,40)) & (x <= np.percentile(x,60)))]
y2=y[ np.where( (y >= np.percentile(y,40)) & (y <= np.percentile(y,60)))]

pearsonr(x2,y2)

(-0.0029887929213811139, 0.67254795967257908)

Added this following @NickCox suggestion:
for p in range(0,50):
 x2=x[ np.where( (x >= np.percentile(x,p)) & (x <= np.percentile(x,100-p)))]
 y2=y[ np.where( (y >= np.percentile(y,p)) & (y <= np.percentile(y,100-p)))]
 print p,100-p,pearsonr(x2,y2)

 0 100 (0.83235076737608205, 0.0)
 1 99 (0.022661699597148071, 1.2930035229909938e-12)
 2 98 (0.0080658659891794712, 0.01245002894257673)
 .
 .
 .
 continue oscillating around zero.

Comment: Plot what you did to get intuition here.
Comment: For an illustrated example of this phenomenon, please see http://stats.stackexchange.com/questions/13314/is-r2-useful-or-dangerous/13317#13317.
Comment: Hi @NickCox I will. Anyway I suspect that you think that it is totally ok with your expectations these results. If so, why?
Comment: Why not reduce the scatter to the two medians? What happens to the correlation as you approach that limit?
Comment: Hey @NickCox I follow your sugesstion to see the behavior when approaching the medians limit and now I´m more confused :/. The drop in the coefficient happens at the first iteration, droping values outside [1,99] percentile! Any help is appreciated here :)
Comment: See now the full answer below.
Comment: @NickCox which one the one from Robert?
Answer: If you truly have a linear association, Pearson's correlation will get smaller when you subset to smaller ranges. This is a classic way to attenuate the estimated slope of a line and a pitfall to watch out for when thinking about subgroup analyses.
# Pearson's correlation attentuated with subsampling
# example in R
set.seed(1)
library(MASS)
Sigma <- matrix(c(10,3,3,2),2,2)
Sigma
d <- mvrnorm(n = 1000, rep(0, 2), Sigma)
colnames(d)<-c('x','y')
dim(d)
head(d)
plot(d)
cor.test(d[,1],d[,2]) # r = 0.67

# just trimming on X starkly reduces the observed correlation
xTrimmed <- (d[,1] > quantile(d[,1],0.25) & d[,1] < quantile(d[,1],0.75))
dTrimX <- d[xTrimmed,]
dim(dTrimX)
plot(dTrimX)
cor.test(dTrimX[,1],dTrimX[,2]) # r = 0.29

# further trimming on Y does more so
xyTrimmed <- (dTrimX[,2] > quantile(dTrimX[,2],0.25) & dTrimX[,2] < quantile(d[,1],0.75))
dTrimXY <- dTrimX[xyTrimmed,]
dim(dTrimXY)
plot(dTrimXY)
cor.test(dTrimXY[,1],dTrimXY[,2]) # r = 0.21

# quick plot to illustrate what's happening
plot(d, xlim=c(min(d[,1]),max(d[,1])), , ylim=c(min(d[,2]),max(d[,2])), col='blue')
abline( lm(d[,2]~d[,1]), col='blue' )
par(new=T)
plot(dTrimXY, xlim=c(min(d[,1]),max(d[,1])), , ylim=c(min(d[,2]),max(d[,2])), col='red')
abline( lm(dTrimXY[,2]~dTrimXY[,1]), col='red' )

However, here is a case where the trimming reveals a lack of association for all other points.
# generate data with no correlation
set.seed(8)
x <- rnorm(20)
y <- rnorm(20)
cor.test(x,y) # r = 0.003
# add two outliers
x[21] <- y[21] <- -7
x[22] <- y[22] <- 7
plot(x,y)
abline(lm(y~x))
cor.test(x,y) # r = 0.82

Comment: I've updated my answer to show an example where two outliers create the impression of a strong linear association.
Comment: Thank you Robert! I guess this is what is happening. However, the correlation dropping from 0.83 to 0.022 by removing the values lower/higher than 1/99 percentile, is something that you would expect?
Comment: I wouldn't expect that extreme of a drop if the association is truly linear. It could happen if there was not a linear association and a few outliers were driving the correlation of 0.83.
Answer: I think that there is a bug in the example code of the question.
You can not compare x2 and y2 after
x2=x[ np.where( (x >= np.percentile(x,40)) & (x <= np.percentile(x,60)))]
y2=y[ np.where( (y >= np.percentile(y,40)) & (y <= np.percentile(y,60)))]

since they are no more "sincronized" as x and y were.
np.where return a subset of indices, the two subset for x and y are not guaranteed to be equal (usually they are not equal), then you probably lose the correlation because you do not compare anymore the same array components as before.
Comment: I agree Pablo, the full discussion is interesting besides the bug.
Comment: Thanks mox! yes you are absolutely right. I give you a plus point for it. However the accepted answer did the triming the right way. I think his answer holds besides my example was wrong. Don't you agree?


Input do tipo text, com o mesmo comportamento de um input do tipo password

Question: Existe alguma maneira em Java Script onde eu possa ter um campo do tipo text, e ao digitar os caracteres eles serem transformados em *(Asterisco). E Depois conseguir recuperar esses valores para fazer algumas validações.
OBS: Não quero usar o tipo password, pois o browser sempre pergunta se deseja salvar esta senha.
Minha aplicação é em Java + JSF + PrimeFaces...
Exemplos:
Quero digitar esta senha no input do tipo password..

Porem a medida que o usuario for digitando ele vai transformando os caracter digitados em asterisco tendo um resultado final assim:

Obrigado !
Comment: Isso seria uma opção tbm, porém a resposta do @placementw me ajudou resolver o problema.

Muito obrigado pela dica também...
Comment: Uma forma seria você criar mais um input do tipo hidden, que armazenaria o valor real digitado e capturar o evento keyup, keypress ou keydown deste campo atual e jogar o valor digitado para o hidden e depois substituir tudo por asterisco no input visível. Mas sinceramente, acho melhor deixar como tipo password e deixar o navegador perguntar se quer armazenar, não é culpa dos desenvolvedores esse comportamento.
Answer: Acredito que alterar o tipo do caracter exibido no campo deve funcionar, testei em alguns browsers e deu certo, mas não tenho certeza se é uma solução 100% compatível
<code><input type="text" name="password" style="text-security:disc; -webkit-text-security:disc;">
</code>
Edit: Importante você analisar se realmente precisa desse comportamento, os navegadores oferecem essa função por alguns bons motivos, um deles, por exemplo, é proporcionar ao usuário a "segurança" de poder utilizar senhas mais complexas que não vão precisar lembrar todas as vezes que forem acessar um serviço.
Comment: Isso msmo que estava precisando... O fato de não querer usar o type password, é porque tenho uma tela de fazer vendas, e utilizo este password quando o usuario deseja cancelar uma venda e seu acesso não permite...

O Problema que esta me causando ao usar o password, é que estava jogando valores aleatorios em outros campos que não tem nada haver com a senha.

Exemplo: o usuario digitava a senha e salvava no navegador, da proxima vez que ele entrar na tela o valor salvo era jogados em outros campos, tais como: Valor, qtde, Cliente entre outros. Não sei o porque deste comportamento.
Comment: Tranquilo! imaginei que fosse algo do tipo mas deixei o edit pra certificar que não ia ser usado de uma maneira a comprometer a segurança da tua aplicação : )


Send AWS new feature announcement to Slack channel

Question: I would like to send the aws new featured announcement from https://aws.amazon.com/new to a channel in Slack.
I couldn't find any source in google. Is there anyone who knows how that can be done?
Comment: This doesn't answer your question, but there's a great newsletter called [Last Week in AWS](https://www.lastweekinaws.com/) you might enjoy.
Comment: This site is also used for such questions when I checked the question's lists and people are willing to help each other by providing useful answers. an example is here: https://stackoverflow.com/questions/32146706/slack-url-to-open-a-channel-from-browser and there are more... why should this be on hold?!
Answer: There should be an rss feed for these new features, add the RSS feed module to slack, and subscribe.
https://get.slack.help/hc/en-gb/articles/218688467-Add-RSS-feeds-to-Slack
AWS new feature RSS feed
Comment: Thanks for a good reply, I did it and it is working fine.


Good list of music suitable for a 45-key clavichord such as ZHI's KOS?

Question: Pretty much the title says it all, but to be more clear....
Is there somewhere a good list of music which can be played on a 45-key clavichord (such as Zuckermann's King of Sweden) 3-and-half-octave with a E-c''' range?
Searching onlines does not yield anything relevant (or I am using utterly wrong search terms). The Boston Clavichord Society does not have anything (perhaps too obvious?) -- The Mutopia Project, The Petrucci and MuseScore libraries either don't have a section for clavichord or even if the do (Petrucci) don't allow to search for and neither show the used range (which would be easy for Mutopia and perhaps MuseScore)
Where do people find music for such an instrument?
PS: somebody with more reputation, please create the clavichord tag and add this question to it.
Comment: Creating new tags is typically a collaborative process triggered by a tag request on meta. If the tag was not considered as urgent up to now, I doubt the proposal is considered. I added the keyboard tag instead, which seems to fit judging from its short description.
Answer: Not really a good answer, but what I found is better than the nothing else obtained so far.
Some questionably-looking PDF sheet music retailers have the range for some of the piano pieces they offer, for example this one (many other pieces from the same retailer do not have the range).
Another retailer (also questionably-looking, but at least with a real-looking team in their about page and some connections with the semi-famous Robert Estrin) appears to have the range for all of their piano music, or at least all that I saw, see for example the same song linked from the business above (note that the arrangement and hence the range is different). This would be "good enough" if they allowed search-by-range or search-by-lowest-note and search-by-highest-note, but sadly they don't. I contacted them asking to add such a possibility.
I was very pleasantly surprised to see that the full Book I of Preludes and Fugues does fit on that small clavichord!!


Show: If $u \in W^{1,p}(B_4(0))$ then $\int_{B_4(0)} \frac{|\nabla u|^p}{|x-a|^{n-1}} dx < \infty$ for a.e. $a \in B_1(0)$.

Question: I'm currently working through the article "Topology and Sobolev Spaces" by Brezis and Li and as basis for the proof of an important result the following fact is used:

If $u \in W^{1,p}(B_4(0))$ then $\int_{B_4(0)} \frac{\mid\nabla u(x) \mid^p}{\mid x-a \mid^{n-1}} dx < \infty$ for a.e. $a \in B_1(0)$.
  (p. 330, remark 1.1)

How does one show that / Why is that evident?
I'd appreciate any help!
Answer: The function $$F(a) = \int_{B_4(0)} \frac{\mid\nabla u(x) \mid^p}{\mid x-a \mid^{n-1}} dx$$ is the convolution of $|\nabla u|^p$ (restricted to the ball) with the Riesz potential $I(y) = 1/|y|^{n-1}$. Moreover, since only the values of $x,a$ with $|x-a|\le 8$ appear in the integral, we can just as well convolve with the restriction of the $I$, namely
$$J(y) = \begin{cases}1/|y|^{n-1},\quad & |y|\le 8, \\ 0,\quad & |y|>8\end{cases}$$
With this setup, it remains to observe that

Both $|\nabla u|^p$ and $J$ are in $L^1$.
The convolution of $L^1$ functions in again in $L^1$.
A function that is in $L^1$ is finite almost everywhere.

More generally, the above shows that the Riesz potential of an integrable function with bounded support is finite almost everywhere.


Can a card given out by the referee be taken back?

Question: It is a common sight in football that when a referee calls a foul and shows a card to an offending player, that player as well as other players from the offender's team surround and argue with the referee. What is the motive behind the exchange with the referee?
The three questions I have are

Can the players make a case with the referee and force him to reverse his decision?
Is a referee allowed to change his decision of a card after he has already shown it?
If it cannot be reversed, what do players hope to achieve when they surround and argue with the referee after a card decision?
Comment: Looks like there are at least some good Google finds: https://www.theguardian.com/football/2014/apr/09/referee-changed-mind-about-red-card and http://www.dailymail.co.uk/sport/football/article-2594637/League-One-round-Referee-REVERSES-penalty-red-card-decision-Brentford-hold-Sheffield-United-goalless-draw.html as well as Quora and Reddit results.
Comment: "What's the motive....?" - competitive, hot-headed, often egotistical superstars might not have a thought-out, logical reason driving their engagement in an escalated verbal dispute with an official.
Answer:
No. Crowding the referee to effect a decision or retraction of a decision, is pointless (see below). Moreover, they could be cautioned for any of delaying the restart of play, dissent by word or action, or unsporting behaviour.
Law 5 of the IFAB Laws states

The referee may only change a decision on realising that it is incorrect or on the advice of another match official, provided play has not restarted or the referee has signalled the end of the first or second half (including extra time) and left the field of play or terminated the match.

The referee may retract a caution or sending-off if they or their assistants or other officials realise this is not correct, and the referee chooses to do so, provided neither play has restarted nor the period of play declared to be over.

Players do this to instil doubts in the referee about whether decisions against that team are correct, or to encourage decisions in their favour, or even on rare occasion, because the decision is incorrect and they would like the referee to seek advice from the other officials.
Comment: It looks like the law you've cited says that a referee *can* change a decision if he realizes that it is incorrect. So, isn't the answer: Yes, a card can be reversed, and yes, a player could theoretically talk a ref into realizing the card was a mistake?
Comment: The question says "can the players make a case and force the decision to be changed", and the answer is clearly "no, they do not have any right to appeal, and they do not have any ability to force a change in decision".
Comment: I can understand the caution for *delaying the restart of play*, or *dissent by word* - or even *failure to respect the required distance* if they're standing in front an opponents' free kick to argue. However, why would the referee caution for *unsporting behaviour* when the behaviour they're engaging in is covered more specifically by any one of the other offences?
Comment: @BenMiller This is a semantic argument, but it's one worth having. Imagine a referee gives a penalty kick for a careless trip in the penalty area. If one team crowd the referee and state "but he didn't touch him", the referee is not going to change their mind, and is not permitted in law to change their mind. The referee cannot change a decision based on the advice of a player.
Comment: However, if the referee gives an indirect free kick for a deliberate handling in the penalty area and the player says "ref, isn't that a direct free kick offence - shouldn't it be a penalty?", the referee, upon realising their moment of forgetfulness, would be permitted to and absolutely should correct the restart to a penalty kick. This is because they haven't changed their decision, but simply corrected an error in procedure. The decision still remains that a player deliberately handled the ball, but the incorrect application of the law has been corrected.
Answer: Yes it can happen, sometimes happens when the wrong player got the card and the one who should have got it goes to the ref.
edit:what I said, I have  seen it happen in regular amateur games, similar to the shetfield incident, but on the same team. Have not found any video or case in pro-football, maybe because they are also more aware that an error giving a second yellow card can cause an expulsion.
can the player affect a decision: Ben Davis says he told him to check with his linesmenn.
https://www.youtube.com/watch?v=D5zSfJszOg8
Comment: Welcome to SE.Sport. Can you add any references please?


How to use the Menu Badges to show the number of recieved messages via Privatemsg?

Question: I use Privatemsg on my site to allow users to communicate with one another. New messages appear in the "Inbox" tab.
I also have the Menu Badges module installed to have a count of unread messages displayed in a badge. The Tab Menu Badges edit page does not list the inbox path (it's /messages/received). It lists other paths like /messages/list, /messages/blocked, /messages/sent, etc. (all being Privatemsg paths). But there is no path for Received messages.
So, I cannot display a badge on the inbox tab.
Is this a common error? Is there a fix or a workaround for this?
Answer: After peeking into the database, it appears the path /messages/received does not exist. This is probably due to the fact that the inbox being the first tab (default tab,) the path defaults to /messages. This path is also the path of the main menu tab. The Menu Badge module does not have an uninstall file, therefore uninstalling it does not clear up the database.
The work around I used is by putting the badge on the All Messages tab (/messages/list) The count of unread messages is the same as with the Inbox tab. Then, I used a little css to move the badge 222px to the left (position: relative) so that it falls on the Inbox tab instead.
It's like using scotch tape, but it works. :)
Answer: If you don't want to use that "scotch tape" anymore (as in your own answer), then have a look at some of the comments in issue # 1719112, which detail how you may get it to work "as it is supposed to work":

(Comment # 6): The tab menu badges are meant for tabs specifically, not links in the menu. You need to edit the Messages menu item and select a badge there if you want the badge to appear up in your header.
(Comment # 9) You have to create your own menu item. Disable the one created by Privatemsg.


react-moment where to set moment.locale

Question: After reading react-datepicker doc's I have tried changing my date picker language as the doc's instructions:

Globally by calling moment.locale(lang) Picker-specific by providing
  the locale prop

My question is where to write this setting in a react app.
1- app.js (constructor).
2- date-picker component(constructor).
3-somewhere else...
And how to set it as prop, I have tried :
<DatePicker locale='gr'
      minDate={this.props.minDate}
        selected={this.state.startDate}
        onChange={this.handleChange}
        disabled = {this.props.disabled}
    />;

and it is still showing up as English.
BTW - anyone know what is the language string to Hebrew? thanks.
Answer: Using this question I was able to figure this so, import langue like:
import 'moment/locale/he';

And for each new moment just set -
moment().locale('he')

It is not really global(one signal setting) for all uses.
moment doc
Comment: if you do the import 'moment/locale/he' in the root component it would be enough to set the local for all components (I've just tested it)
Comment: Also notice that you can import it dynamically with import(`moment/locale/${navigator.language.toLocaleLowerCase()}`).then();
Answer: I think the correct answer if the goal is to set it globally would be to put it in App.js just after the imports.
import moment from 'moment';
// Set moment to FR
moment().locale('fr');
...

function App() {
  return (
...
  )
}

Answer: If you need moment.locale(lang) globally then try react context api (for React v16.3 or greater). For Hebrew locale code is he, I think.

react-moment where to set moment.locale


Consulta em banco de dados com java

Question: Vou fazer uma comparação com o meu problema utilizando uma funcionalidade do banco de dados e JQuery do html.
Com o JQuery temos a possibilidade de visitar o banco de dados e trazer os dados para o frontend no HTML, e isso pode ser feito constantemente sem influenciar na interface do usuário(HTML) ou que tudo pare até que a consulta seja realizada.
O meu problema no java é que tenho uma JTable e os dados dela são pegos num banco de dados e a tabela consultada esta em constante mudança, com novos dados sendo inseridos e eu preciso que a JTable aconpanhe essas mudanças.
Existe alguma maneira ou algo que possibilite isso?
Answer: Não sei se entendi corretamente qual a sua dúvida, mas caso seja simplesmente atualizar os dados de uma JTable, é só fazer uma nova consulta no banco de dados e passar o resultado para JTable. Como exemplo tenho o trecho de código de um projeto meu que utiliza o padrão MVC.
<code>//método para listar os alunos que atuam como monitores de disciplinas
public void listar(String str){
    //instancio um objeto que me permita fazer consulta no banco de dados
    MonitorDAO dao = new MonitorDAO();
    //realizo a consulta e coloco o resultado num ArrayList
    monitores = dao.consultaMonitores(str);
    //seto para a JTable um novo TableModel que vai receber o resultado da consulta anterior
    tela.getTabela().setModel(new MonitorTableModel(monitores));
}
</code>
Tendo este método, eu o chamo sempre que for necessário atualizar os dados da JTable.

Consulta em banco de dados com java


Add dataEmptyMessage in FusionCharts Django

Question: How can I display status and error messages that can be set for any chart in the Django FusionCharts constructor?
Answer: We can use from addMessage method of FusionCharts class:
<code>chartObject = FusionCharts(type, id, width, height, renderAt, dataFormat, dataSource)

chartObject.addMessage("dataEmptyMessage", "put your custom text here")
</code>


Filter some unique Data with LINQ and C#

Question: i am very new with C# and MVC.
My Problem:
I have a list OF IDs
int[] mylist = {10, 23}

I try to query some data from DB
var result = db.tableName.Where(o => mylist.Any(y => y == o.item_ID && o.readed)).ToList();

This is what I get with the query:
item_ID Product_ID readed
277     1232       1
277     1233       1
277     1235       1
280     1235       1

What I need is:
item_ID Product_ID readed
277     1235       1
280     1235       1

If I change "any" to "all" i don't get any results, but I have definitely one item where the condition fits.
I think its more like make a query with id 277, then a query with 280 and then merge the list and return only where where "Product_ID" match.
Any ideas?
Comment: I would recommend checking what query actually runs against the database, with either of the answers below. For example, you can use SQL Server Profiler if your DB is SQL Server.
Comment: Please could you post a http://sscce.org/ along with the EXPECTED results. Try posting on https://dotnetfiddle.net/
Comment: Does your `myList` includes in 272 and 280?
Comment: @FarhadJabiyev yes, as I said, I get the correct list, but its more like a list this items for 1 ID and a list this items for second ID. The SQL i show do the stuff correct
Comment: @Fincha I have updated my answer as you need.
Answer: I assume that what you need is this:
var temp = db.tableName.Where(o => mylist.Any(y => y == o.item_ID && o.readed))
                       .ToList();

// Find the Product_id which appeared more than one time
// By the way, this assumes that there is at least one product_Id whihc has appeared more than one time
var neededProductID = temp.GroupBy(x => x.Product_ID)
                          .Where(x => x.Count() > 1)
                          .First()
                          .Key;

// Filter the result by neededProductID
var result = temp.Where(x => x.Product_ID == neededProductID).ToList();

Also, if there could be more tha one Product_ID which has apperaed more than one time, then you can consider this:
var neededProductID = temp.GroupBy(x => x.Product_ID)
                          .Where(x => x.Count() > 1)
                          .Select(x => x.Key)
                          .ToList();

var result = temp.Where(x => neededProductID.Any(y => y == x.Product_ID)).ToList();

By the way, you don't need All(). It tells you if all the elements in a collection match a certain condition.
Comment: Then, please update your question with inputs and outputs sample?
Comment: I have added an image to my question, I currently use your solution, makes the most sense.
Comment: @Fincha Why you need 2 equals? COuld you please explain us? You have not explained what output you want and why?
Comment: I have added some sql, I think it makes this really clear. I need items of special kind with readed = 1
Comment: @Fincha
Does your myList includes in 272 and 280?
Comment: @Fincha Your LINQ query is OK. But, it means that your `myList` includes all 8 ids in your result. Not only 272 and 280.
Comment: Sorry my mistake, I was testing with 272 but using the 277 in my test case!
Comment: I think I was to early to celebrate... I have updated my question, have you any idea?
Comment: @Fincha Do you need maximum one?
Comment: I added an explaination to the questtion
Comment: @Fincha What you need is GroupBy and find the maximum one. CHeck my update.
Comment: I dont think it works this way, cos of "max" it dont have to be the max value, as I said, its more a merge maybe concat? of to lists
Comment: @Fincha Mut it be a last value? Or must be same productId?
Comment: It must be the same product_id
Answer: You can use the following
var result = db.tableName.Where(o => mylist.conains(o.item_ID)
                && o.readed).ToList();
Comment: Can you try to compare the SQL version with what you want to achieve
Comment: can you take a look at the question now?


Can I use linear regression analysis if the predictors and criteria change during time?

Question: Can I use linear regression analysis to analyze the relationship between two variables if both of them are changing in time (each day)?
Predictor = Number of unemployed people (in a country)
Criteria = Life satisfaction
We run this survey for a month and see how life satisfaction in a country changes with the growing number of unemployed people. We have data for number of unemployed people every day (single number - sometimes it grows from day to day, sometimes it stays the same), and every day a number of people participates in the survey (multiple answers per day).
If I want to model Life satisfaction ~ No_unemployed, can I do it with the classic lm() function, or do I somehow need to account for the fact that this is an example of a time-series?
What do I need to take care of when conducting these analyses?
EDIT: I am primarily interested in the technical (can I use linear regression, and in which cases), and not the conceptual aspect of this question (which other variables would be valuable to have a look at).
Answer: Yes, you should be able to use linear regression analysis, however, I suspect, more work on the variables is needed.
To begin, I would, apriori, expect a Life Satisfaction (a rating index) to be a function of two drivers. First, cable news content including major announcements, and second, direct personal experience (for example, job status, sickness in the family, problems in acquiring basic necessities, lack of access to healthcare, a crime/accident event,...).
Your successful use of unemployment data is too be expected, however, perhaps some smoothing using a weighted average series and even a lagged effect, as someone may have completed the online survey due to their current availability to be online, perhaps due to job loss. This smoothing could address your concern of observed variables changing in time each day.
Other potential explanatory variables are random except data on the crime rate, pandemic reported cases/deaths, hospital closings, and, gasoline price. So, a rule to turn-on a dummy variable (a very bad news day with, for example, reported shortages in food stocks) could be tested as an added variable to account for the variation in the Life Satisfaction Index.
Further efforts could include the construction of a quantitative misery index for other indicators available expected to induce distress (so, for example, overnight pandemic related deaths).
The use of a Stepwise Regression routine may be of assistance in identifying contributing variables if you become so interested.
Comment: Thank you for you answer. However, I am primarily interested in the technical (can I use linear regression, and in which cases), and not the conceptual aspect of this question (which other variables would be valuable to have a look at). Could you elaborate on that part? For example, when should one use weighted average series and lagged effect? What are these?


How to use Boto3 pagination

Question: BACKGROUND:
The AWS operation to list IAM users returns a max of 50 by default.
Reading the docs (links) below I ran following code and returned a complete set data by setting the "MaxItems" to 1000.
paginator = client.get_paginator('list_users')
response_iterator = paginator.paginate(
 PaginationConfig={
     'MaxItems': 1000,
     'PageSize': 123})
for page in response_iterator:
    u = page['Users']
    for user in u:
        print(user['UserName'])

http://boto3.readthedocs.io/en/latest/guide/paginators.html
https://boto3.readthedocs.io/en/latest/reference/services/iam.html#IAM.Paginator.ListUsers
QUESTION:
If the "MaxItems" was set to 10, for example, what would be the best method to loop through the results?
I tested with the following but it only loops 2 iterations before 'IsTruncated' == False and results in "KeyError: 'Marker'". Not sure why this is happening because I know there are over 200 results.
marker = None

while True:
    paginator = client.get_paginator('list_users')
    response_iterator = paginator.paginate(
        PaginationConfig={
            'MaxItems': 10,
            'StartingToken': marker})
    #print(response_iterator)
    for page in response_iterator:
        u = page['Users']
        for user in u:
            print(user['UserName'])
            print(page['IsTruncated'])
            marker = page['Marker']
            print(marker)
        else:
            break

Comment: in boto3.client.get_paginator,  MaxItems seems become a data listing threshold/limiter, it is not use as paginator. You need to use `PageSize` for pagination
Comment: See also: https://stackoverflow.com/a/59816089/75033
Answer: (Answer rewrite)
**NOTE **, the paginator contains a bug that doesn't tally with the documentation (or vice versa). MaxItems doesn't return the Marker or NextToken when total items exceed MaxItems number. Indeed PageSize is the one that controlling return of Marker/NextToken indictator.
import sys
import boto3
iam = boto3.client("iam")
marker = None
while True:
    paginator = iam.get_paginator('list_users')
    response_iterator = paginator.paginate(
        PaginationConfig={
            'PageSize': 10,
            'StartingToken': marker})
    for page in response_iterator:
        print("Next Page : {} ".format(page['IsTruncated']))
        u = page['Users']
        for user in u:
            print(user['UserName'])
    try:
        marker = response_iterator['Marker']
        print(marker)
    except KeyError:
        sys.exit()

It is not your mistake that your code doesn't works. MaxItems in the paginator seems become a "threshold" indicator.  Ironically, the MaxItems inside original boto3.iam.list_users still works as mentioned.
If you check boto3.iam.list_users, you will notice either you omit Marker, otherwise you must put a value. Apparently, paginator is NOT a wrapper for all boto3 class list_* method.
import sys
import boto3
iam = boto3.client("iam")
marker = None
while True:
    if marker:
        response_iterator = iam.list_users(
            MaxItems=10,
            Marker=marker
        )
    else:
        response_iterator = iam.list_users(
            MaxItems=10
        )
    print("Next Page : {} ".format(response_iterator['IsTruncated']))
    for user in response_iterator['Users']:
        print(user['UserName'])

    try:
        marker = response_iterator['Marker']
        print(marker)
    except KeyError:
        sys.exit()

You can follow up the issue I filed in boto3 github. According to the member, you can call build_full_result after paginate(), that will show the desire behavior.
Comment: Example of using  build_full_result:
`paginator = client.get_paginator('list_users');
users = paginator.paginate().build_full_result()`
Comment: You can deal with the extra arg as follows:
kwargs = {'MaxItems': 10} \
if bool(marker): \
  kwargs['Marker'] = marker \
response_iterator = iam.list_users(**kwargs)
Comment: Thanks for the suggestion above but it doesn't seem to work.  I have run this code and only get the "MaxItems" + 1.  So if MaxItems is set to 10, I'll get 11 users returned before it stops.
Comment: For each page returned by "response_iterator = paginator.paginate" there is a bunch of data included in the dict outside of the 'Users' list.  For example: `RequestId, HTTPSStatusCode, HTTPHeaders` and a string called `'Marker'`.  You can see this by dropping in `print(page)`
Comment: @user45097 : I just realise the mistake, list_user are slightly different than S3 list_object next_token stuff . I will update my answer.
Comment: This library is bugged to the point of being unusable.
If it does not fail in delivering all the elements in a paginated format (so you think you processed all elements when in reality you haven't) it will surely deliver the same elements multiple times, making you process duplicates (in a 21 elements list it actually returned 43, some elements being duplicated 4 times while others actually being unique).

Beware of these problems before using it.
Answer: This code wasn't working for me.  It always drops off the remainder of the items on the last page and doesn't include them in the results. Gives me a result of 60 accounts when I know I have 68. That last result page doesn't get appended to my list of account UserName's.  I have concerns that these above examples are doing the same thing and people aren't noticing this in the results.
That and it seems overly complex to paginate through with an arbitrary size for what purpose?
This should be simple and gives you a complete listing.
import boto3
iam = boto3.client("iam")
paginator = iam.get_paginator('list_users')
response_iterator = paginator.paginate()
accounts=[]
for page in response_iterator:
    for user in page['Users']:
        accounts.append(user['UserName'])
len(accounts)
68

Answer: This post is pretty old but due to the lack of concise documetation I want to share my code for all of those that are struggling with this
Here are two simple examples of how I solved it using Boto3's paginator hoping this helps you understand how it works
Boto3 official pagination documentation:
https://boto3.amazonaws.com/v1/documentation/api/latest/guide/paginators.html
AWS API specifying that the first token should be $null (None in Python):
https://docs.aws.amazon.com/powershell/latest/reference/items/Get-SSMParametersByPath.html
Examples:
First example with little complexity for people like me who struggled to understand how this works:
def read_ssm_parameters():
    page_iterator = paginator.paginate(
        Path='path_to_the_parameters',
        Recursive=True,
        PaginationConfig={
        'MaxItems': 10,
        'PageSize': 10,
        }
    )

    while myNextToken:
        for page in page_iterator:
             print('# This is new page')
             print(page['Parameters'])
             if 'NextToken' in page.keys():
                 print(page['NextToken'])
                 myNextToken=page['NextToken']
             else:
                 myNextToken=False

    page_iterator = paginator.paginate(
        Path=baseSSMPath,
        Recursive=True,
        PaginationConfig={
            'MaxItems': 10,
            'PageSize': 10,
            'StartingToken': myNextToken
        }
    )

Second example with reduced code but without the complexity of using recursion
def read_ssm_parameters(myNextToken='None'):
    while myNextToken:
        page_iterator = paginator.paginate(
            Path='path_to_the_parameters',
            Recursive=True,
            PaginationConfig={
                'MaxItems': 10,
                'PageSize': 10,
                'StartingToken': myNextToken
            }
        )

        for page in page_iterator:
            if 'NextToken' in page.keys():
                print('# This is a new page')
                myNextToken=page['NextToken']
                print(page['Parameters'])
            else:
                # Exit if there are no more pages to read
                myNextToken=False

Hope this helps!
Answer: The correct answer was stated in one of the comments above. I have ran into this issue myself before. I manage 56 aws accounts and was looping through all of them and noticed that 'list_users' would only return 100 users. After digging into the issue I discovered this thread and the boto3 github issue related to this problem. Calling build_full_result() will return a complete list of users.
paginator = client.get_paginator('list_users')
users = paginator.paginate().build_full_result()

Answer: I will post my solution here and hopefully help other people do their job faster instead of fiddling around with the amazingly written boto3 api calls.
My use case was to list all the Security Hub ControlIds using the SecurityHub.Client.describe_standards_controls function.

controlsResponse = sh_client.describe_standards_controls(
StandardsSubscriptionArn = enabledStandardSubscriptionArn)

controls = controlsResponse.get('Controls')

# This is the token for the 101st item in the list.
nextToken = controlsResponse.get('NextToken')

# Call describe_standards_controls with the token set at item 101 to get the next 100 results
controlsResponse1 = sh_client.describe_standards_controls(
StandardsSubscriptionArn = enabledStandardSubscriptionArn, NextToken=nextToken)

controls1 = controlsResponse1.get('Controls')

# And make the two lists into one
controls.extend(controls1)

No you have a list of all the SH standards controls for the specified Subscription Standard(e.g., AWS foundational Standard)
For example if I want to get all the ControlIds I can just iterate the 'controls' list and do
controlId=control.get("ControlId")
same for other field in the response as it is described here
Comment: This answer is not using Paginators.

How to use Boto3 pagination


What are the disadvantages of voice leading, when is it inappropriate?

Question: As per the title.  I've seen much about why it's a good thing, and I employ it an awful lot on guitar. I think it can get a bit much and samey.  I'd like to read a more learned analysis.
For example, on guitar I am playing triads in the same position through a chord progression and obviously this is voice leading as exactly the same notes are being reused regularly and so often a chord change is almost indiscernible.  I know this is the nature of voice leading, but I just want to see someone talk about the benefits of deliberately not playing with the closest possible voice leading, as you never see that angle.
Comment: You certainly don't always need to follow classical voice leading rules, but if you say voice leading "can get a bit much and samey" then you evidently haven't explored much of the enourmously wide range of things that can be done with voice leading.
Comment: This is a pretty broad question. Perhaps you could give an example of where you feel like you're getting a result you don't like and ask for more disruptive ways of dealing withit.
Comment: This is a broad question. I attempted to answer, but perhaps you may want to 1. learn more about various individual voice leading guidelines (there are plenty of questions on this site about it), 2. if still in doubt, ask questions about specific voice leading guideline.
Comment: You can go for smooth transitions, you can go for jagged ones. Both sound like what they sound like! Do whichever sounds like what YOU want at that time in that piece of music.
Comment: I edited to specify **"closest possible voice leading"**, since I gather this question is about music using *individual voices less smoothly than traditional voice-leading*. If this is not the right interpretation of the question, OP should roll it back and clarify the intended meaning. If I'm right, though, I think the question's narrow enough to stay up!
Comment: I think OP learned approximately what I was taught on piano: That "voice leading" for chord changes is about picking the inversion of the next chord that minimizes hand and note movement from one chord to the next. If you then play something like a C-F-G chord progression you'll play it the same way every time because at each chord change there is only one alternative for "minimal change". (E.g if the C chord is in root position the F chord has to be in second inversion, since it keeps the C note and the other two notes move a whole tone each, that's the smallest possible change.)
Comment: I like all the answers tbh. It does seem like a daft question. It's just that when you watch stuff on you tube etc, they always concentrate on how good voice leading is, and you never get the counter argument.
Comment: "so often a chord change is almost indiscernible" -- how closely do you listen to music? how much distortion do you have? this really just, shouldnt be the case for a lot of ordinary playing, even a single inner voice changing ought be a pretty distinctive change in sound.
Answer:
For example, on guitar I am playing through triads in the same position through a chord progression and obviously this is voice leading as exactly the same notes are being reused regularly and so often a chord change is almost indiscernible.

It's not really obvious unless you give some more detail, ideally notation of some kind. But I don't think we need to know what you're playing to answer.
Voice leading just means to move voices, or parts, to move them melodically. Technically, if you move voices any way it would be voice leading, because the voices moved. "Good" voice leading is usually meant to describe the counterpoint conventions of the Renaissance, Baroque and Classical periods. In a nutshell, it's triadic harmony, hold one or two voices, move the others by step, no parallel perfect fifths and octaves.
To literally not voice lead would be harmonically all voices singing a unison or a static chord. To move the voices, but without the independence of parts achieved with "good" voice leading will be parallelism. That is found in a variety of styles: organum, folk music, Impressionism (like composer Debussy), Modernism (like composer Bartok), or rock music.
Why, do some styles not use "good" voice leading? Some possible reasons:

To deliberately not sound like Renaissance, Baroque, or Classical style, especially the "learned" or Church styles, which is the actual origin of the voice leading, contrapuntal methods. If you don't want to sound like you're playing a hymn, avoiding "good" voice leading is one way to do it.
To "thicken" the texture of a line. Sometimes, even in the context of a symphony, the texture can change to unisons or octaves for a passage, such passages can be thickened, for example, by playing in thirds, if the style were modern, doublings in fourth, fifth, sevens, etc. might be used. Harmonically the passage will be thicker with multiple parts, but it won't involve voice leading.
From a linear point of view you might try to make a line more emphatic by moving everything in the same direction. When various parts move by contrary or oblique motion, you could think of that are parts sort of "contradicting" one another by not moving in the same direction. Of course that variety of directions is what creates the special texture of the contrapuntal style. But it is a sort of constant churning of various directions. If you move all parts in the same direction, it would be considered ham-fisted voice leading by conventional standards, but it would give an emphatic, single direction to a line.

There is a particular type of movement that I think should be pointed out: moving across the various positions of a chord. Technically, it isn't quite parallelism. It's similar motion, but the important thing is a single chord is maintained. Debussy did it a lot in the Impressionistic style. You can also hear an example of it in the vocal harmonies of the Beatles song Because. In terms of conventional voice leading all the parts move in one locked direction, but harmonically it's a very rich sound.
Answer: Voice leading is a broad term, and depending on the context or music style it may mean different things. The answer I can give will be therefore broad and general as well.
The general goals of voice leading are to:

connect consecutive chords smoothly
create an impression the chords are composed of voices which move independently of each other
allow the individual lines to be easily sung, or performed by an instrument in a way that they feel like belonging to the same voice

Various voice leading "rules" are tools helping to achieve the above. Not following the voice leading guidelines results in the opposite: having consecutive chords disconnected and not creating an impression of voice independence, or maybe even any kind of voice continuity.
As in art there are no rules, there is nothing wrong with following, or not following voice leading guidelines. It's all matter of an effect you want to achieve. In particular, inconsistent applying the guidelines may lead to sharp contrasts.
Answer:
Q. What are the disadvantages of voice leading, when is it inappropriate?
For example, on guitar I am playing through triads in the same
position through a chord progression and obviously this is voice
leading as exactly the same notes are being reused regularly and so
often a chord change is almost indiscernible.

You've answered the question yourself, the disadvantage is that it can result in monotony.
The solution
then, is how to avoid monotony in the accompaniment.
As others here have suggested, you can go for:

Exaggerated contrary motion.
Oblique motion by keeping a pedal point or ostinato bass.
Parallel movement.
Change the bass to move quicker than the chords.
This can be a walking bass or jumping to other notes to create different roots.
This could be as simple as selecting the relative major or minor.
Use differentiated note values to achieve a polyphonic texture.
Or just go for true polyphony, even imitation, if you can make it work.
Add non-chord tones or accidentals to make the harmony more interesting.
In some cases, the underlying issue may not be smooth voice leading, but a
problem with the harmony not being dynamic enough.
Add unique rhythms to the chords, creating a distraction from static harmony
Arpeggiate the accompaniment, putting focus on whatever notes are changing.
Combinations of any of the above or other variations.
Comment: almost nothing that you list is an alternative to/distinct from voice leading. voice leading encompasses literally every single point you raise except arguably parallel movement (which, voice leading allows for a pretty large subset of parallel movement, but sure i can concede that harmony built primarily around parallelism isn't really voice leading any more even when it technically "follows the rules").


Solving $a^5 \equiv 15 \pmod{385}$

Question: Is there a general way of approaching problems like $a^5 \equiv 15 \pmod{385}$? I know the first step is to break up the modulus into its prime factors ($5, 7,$ and $11$, in this case). How do I deal with the exponent though? It's been a while since I looked at number theory, but I remember the whole question of singular and nonsingular roots comes up.
Comment: $a^5\equiv 15\pmod{11}\implies a^5\equiv 4\pmod{11} \implies a^{10}\equiv 16\pmod{11}$ which is false by Fermat's little theorem, so there are no solutions.
Comment: Now solve $a^5 \equiv 15$ modulo each of the three factors.  Then combine the results using the Chinese Remainder Theorem
Comment: As Ross suggests, make a little table of $0^5, 1^5, 2^5, 3^5, 4^5 \pmod 5.$ It is not hard, any time you go over $5$ you just reduce. Same for $0^5, 1^5, 2^5, 3^5, 4^5, 5^5, 6^5 \pmod 7.$ If you prefer, $1^5, 2^5, 3^5,(-3)^5, (-2)^5, (-1)^5 \pmod 7.$ Similar for 11. You don't need a calculator and you don't need formulas
Comment: Oh, I see. Thank you, so much!
Comment: I was wondering about that!  I only saw the title on the main page, and was working on this for a couple of minutes (I'm really no good at number theory) and wondering how there could be any solutions.
Answer: Taking into account that $\mathbf Z/p\mathbf Z$ is a field if $p$ is prime, it is equivalent to solving
\begin{cases}
a^5\equiv 0\mod 5\iff a\equiv 0\mod 5, \\
a^5\equiv 1\mod 7\iff a^6\equiv 1\equiv a \mod 7 &\text{ by Fermat},\\
a^5\equiv 4\mod 11.
\end{cases}
However, Fermat asserts that if $a\not\equiv 0\mod 11$, we have $a^{10}=(a^5)^2\equiv 1$, whence $a^5\equiv \pm 1\mod 11$. Therefore there's no solution modulo $11$, and consequently, no solution modulo $385$.
Answer: The "general way" is to use indices.  For each prime power, find a primitive root $r$ and generate the table of indices.  Then you can solve
$$x^k \equiv a \pmod{p}$$
by taking "logs" of both sides.  For instance, take $p=7$.  The smallest primitive root of $7$ is $3$, so compute mod $7$:
$3^0 =1$, $3^1=3$, $3^2=2$, $3^3=6$, $3^4=4$, $3^5=5$.
So your indices are
$\mbox{ind}_3 1=0$, $\mbox{ind}_3 3=1$, $\mbox{ind}_3 2=2$,$\mbox{ind}_3 6=3$,$\mbox{ind}_3 4=4$,$\mbox{ind}_3 5=5$.
Now if you want to solve $x^5\equiv 3 \pmod{7}$ you can take indices of both sides:
$$\mbox{ind}_3 x^5 \equiv \mbox{ind}_3 3 \pmod{6}$$
$$5\mbox{ind}_3 x \equiv 1 \pmod{6}$$
$$\mbox{ind}_3 x \equiv 5 \pmod{6}$$
$$x \equiv 5 \pmod{7}.$$

Solving $a^5 \equiv 15 \pmod{385}$


classic multi dimensional scaling example

Question: I am reading this note.
http://fourier.eng.hmc.edu/e176/lectures/MultidimensionScaling.pdf
P.17
it has a Distance matrix,
D = array([[0, 1,1,1], [1, 0, 1,1], [1, 1,0,1], [1,1,1,0]])

then it mentioned "leading to the gram matrix B(4×4) with eigenvalues (.5, .5, .5, 0)."
I would like to ask how get the gram matrix from D?
I tried to appl G = I -D/2(?).
(from here: https://math.stackexchange.com/questions/2240429/pairwise-distance-matrix)
But when i get the PCA, i got [ 0.062  0.062  0.062  0.   ]
from sklearn.decomposition import PCA
G = 1-D/2
pca = PCA()
pca.fit(G)
print(pca.explained_variance_)

must be something wrong.
Answer: My understanding of the Gram matrix, is that it comes from a product $X^{T}X$ where $X$ is a $k\times n$ matrix of coordinates (assuming your points lie in k dimensions).  In your case $n$ would be 4 since the distance matrix is $4\times 4$ (pairwise distances between four points).  In order to find a/the Gram matrix, you first need to find the location of the 4 points (in your case $k=3$ since you have a tetrahedron) so that their pairwise distances give you the distance matrix you have.
Edit: Since this is a tetrahedron with all unit distances, you can fairly easily compute locations of those vertices by hand.  Otherwise, if you don't want to (or can't) do it by hand, then use Multidimensional Scaling.  Note: PCA doesn't do this.
Edit: To reproduce the eigenvalues demonstrated (computationally) you can do the following:
from sklearn.manifold import MDS
import numpy as np

# Given distance matrix
D = np.array( [ [0, 1, 1, 1], [1, 0, 1, 1], [1, 1, 0, 1], [1, 1, 1, 0]] )

# n_components = 3 says your are finding points in 3 dimensions
# dissimilarity = 'precomputed' alerts the algorithm that you are handing it a distance matrix
embedding = MDS(n_components=3, dissimilarity='precomputed')

# Fitting the distance matrix give you a list of points realizing the distances (note that this process is random and approximate).
Xt = embedding.fit_transform( D ) #Xt is a 4x3 matrix (so it's X^T)

# Get the transpose of that value (for computing X^T X)
X  = np.transpose( Xt )

# Compute the Gram Matrix
Gram_Matrix = np.matmul( Xt, X )

# Check the eigenvalues
print( np.linalg.eigvalsh( Gram_Matrix ) )

Comment: thx for answering, but i am confused, do you know how to get eigenvalues (.5, .5, .5, 0). based on the distance matrix on P17 of this slide? http://fourier.eng.hmc.edu/e176/lectures/MultidimensionScaling.pdf
Comment: p.s. i know i can use sklearn.to do so, but i would like to know how to do the calculation, so i insisted to ask about P17 of the slide, many thx.
Comment: Doing MDS by hand is terrible; but lucky for you, the points come from a tetrahedron (looking at the picture on your slide).  So what you need to do is compute the x,y,z location of each of the 4 corners of the tetrahedron.  Put those coordinates into a $3\times 4$ matrix $X$, then compute $X^T X$.
Comment: Edited my answer slightly.  I'll leave it to you to determine the exact locations of those points... if your question is "how do I find the location of vertices of a unit tetrahedron?" then that's probably a separate question.
Comment: many thx for help, my refined question is, what is the step-by-step to get eigenvalues (.5, .5, .5, 0)? why the slide showed (.5, .5, .5, 0)?
Comment: or in slide 18, that is another pairwise distance matrix, and then another eigenvalues answer, what are the steps to derive that eigenvalues answer?
Comment: Roughly, the steps are: find the coordinates of the points whose pairwise distances make up the distance matrix, put those coordinates into a matrix $X$, compute $X^T X$, then compute the eigenvalues of $X^T X$.
Comment: i would like to know the exact steps...to get the exact solution eigenvalues (.5, .5, .5, 0)...that is what i am struggling..
Comment: @pianobegginer The exact steps are illustrated in code.  Feel free to attempt this by hand if you like.  It's not terrible, but imo also not enlightening.  If you are having trouble with eigenvalues/matrix multiplication/etc you should consider taking a linear algebra course (or working through a linear algebra text).
Comment: thx so much for the hint. the code returned [0.    0.487 0.498 0.515] which is slightly different than  (.5, .5, .5, 0). why is this? i am still trying my best to figure it out. anyway, thx for attempt to help. appreciated.
Comment: @pianobegginer It's because the MDS algorithm is finding approximate points (to some tolerance, default is $\epsilon=.001$.  You can (probably) improve those by adding `eps=.0001` (or something similar or smaller) to the line `embedding = MDS( ... )`
Comment: in the note, it said "Using dimension p = 3, we have perfectly retrieved the tetrahedron", is it always true that for n=4 points, we can use n-1 = 4-1 = 3 dimensions to have a perfect retrieval? thx.


Pass props from child to parent without re-rendreing all children

Question: I am trying to make a sudoku web app, It consists from a parent component which renders all blocks. Even though every child keeps its own state with the current value inside (all that player could change) I have to update the complete array. It looks something like this
const playerTable = [
  [0, 1, 6, 0, 0, 3, 0, 9, 0],
  [0, 0, 0, 7, 8, 9, 5, 0, 0],
  [7, 9, 0, 0, 0, 6, 3, 2, 4],
  [0, 0, 7, 5, 0, 8, 2, 6, 9],
  [1, 0, 9, 0, 0, 0, 8, 0, 3],
  [0, 8, 2, 0, 3, 7, 0, 0, 0],
  [9, 0, 1, 3, 0, 4, 6, 0, 5],
  [0, 7, 3, 0, 0, 0, 1, 0, 2],
  [4, 6, 5, 0, 2, 1, 9, 0, 7],
]

My idea was to pass the position and new value when state in cube changes and then parent updates the playerTable
playerTable[row][col] = newVal
The problem is all children are re-rendered on any change of state from child to parent, which would be about 36 re-renders.
Is there a way to optimize this or should I leave it like that?
Thanks in advance!
Comment: Why do you have the same state both in the parent and in children?
Comment: @KonradLinkowski I think we misunderstood each other, every block has a state of its own value, and every time it changes value it updates the state in parent, every time state in parent updates it gets which position and value it should change in the playerTable. It does work as expected except it re-renders all children, and only 1 changed its value.
Comment: So you have duplicated state which should be the case. I would consider using ref instead of state in the parent. You can have `useRerender` hook in every child that will be called onclick
Comment: Ok, so it won't work, you have to have the state in the parent
Comment: @KonradLinkowski Never heard of such hook, I will look into it. Thanks for advice.
Comment: https://codesandbox.io/s/epic-greider-n8x8l4?file=/src/App.js
Comment: @KonradLinkowski That should solve it. Once again thank you for your time.
Answer: Speaking from my knowledge of React...
If your parent component must hold the entire array in its state, whenever that state is updated, all child components will re-render, no matter what. This is a key part of the React diffing algorithm for the virtual DOM.
If you want to make your renders more efficient, then I would say you need to segment and lower your component state, or turn that parent component array state into just data logic that isn't tied to state and re-renders.
Ultimately though, especially with React, I would only bother optimising render cycles if your application is screaming for that optimisation. If your app performs well, then you probably shouldn't waste the time.
Comment: It doesn't reaaally need it, but would probably be posted on heroku, I am just trying really hard to optimise it as best as possible. Thank you for your answer
Comment: If you are really trying to tackle render optimisation, then you will need to ask a much more specific question with all relevant source code, detailed context, and clear requirements. There are many resources online going over the React optimisation and the best practices around it, so I'm sure you will gain more clarity on the subject this way.


Reconhecimento de imagens dentro de uma imagem maior

Question: Gostaria de fazer uma parte da minha aplicação, em que o usuário faria upload de uma imagem cheia de desenhos dentro, ele então, selecionaria uma área da imagem e eu procuraria em toda a imagem uppada, pontos iniciais nos quais essa imagem selecionada se repete dentro da imagem maior. Alguém poderia me ajudar? Alguma biblioteca JS? As que achei fazem reconhecimento de face e não de objetos em geral...
Answer: Não conheço nenhuma solução client-side (JS) que possa realizar, com um grau decente de precisão, este tipo de funcionalidade.
Você pode, entretanto, utilizar uma solução server-side.
Uma das possibilidades é OpenCV, uma biblioteca opensource (BSD) multiplataforma desenvolvida pela Intel que possui vários módulos interessantes para processamento de imagens. No seu caso específico, o módulo cvMatchTemplate pode ser uma solução viável.
Este é um exemplo de detecção via OpenCV::cvMatchTemplate:
Original:

Alvo:

Versão normalizada:
Comment: Eu consegui fazer usando métodos da gd2 (lib php) e transformando as imagens em duas matrizes com valores inteiros (inicialmente peguei a imagem, tranformei em grayscale [também com métodos da gd2] para facilitar) e com laços fui verificando... Deu certo! Obrigada pela ajuda
Comment: Obrigada, vou dar uma olhada porque meu projeto é PHP :(
Comment: @user3326192 Sugiro então dar uma olhada neste link - é um wrapper da biblioteca OpenCV para PHP: http://www.xarg.org/project/php-facedetect/
Comment: @user3326192 Que bom que você conseguiu encontrar uma solução! Sinta-se à vontade para caso você tenha mais dúvidas.


Nginx proxy_pass with dynamic fallback

Question: I'm running nginx as reverse proxy on 3 different hosts. The DNS resolves production.example.com to all 3 hosts' IP addresses. Thus I have some sort of load balancing and fallback if one host is not available.
Every host is running several docker containers. Some of them are running on all three hosts, some only on two or even just one host.
Utilizing nginx's proxy_pass I forward all requests to the container's internal name (I'm using Rancher thus every container is accessable via container_name.stack_name via internal DNS).
Every now and then, a container is not available or does not respond and thus nginx returns an error 502.
Is there any way to have and automatic fallback for this? Unfortunately nginx ignores all other resolved addresses for an internal Docker container name and thus does not forward the request to a different address.
Answer: You should use the proxy_next_upstream directive

Specifies in which cases a request should be passed to the next server

location / {
    proxy_pass http://backends;
    proxy_next_upstream error timeout http_502;
}

Comment: In my case, I don't know the "backends". They're dynamically specified via DNS. In other words, I don't use the `upstream` directive right now and even If I would use it, it would only specifiy a single server in it.

Nginx proxy_pass with dynamic fallback


Sending email in a goroutine

Question: I am trying to programming an authentication system with golang.
After user successfully sign up, it will send an email confirmation to the user.
I am thinking to execute the send mail function in a goroutine. The code of send mail function looks like
<code>func Send(email, link string) error {

    // Connect to the remote SMTP server.
    c, err := smtp.Dial("127.0.0.1:2525")
    if err != nil {
        return err
    }
    // Set the sender and recipient.
    c.Mail("email@example.com")
    c.Rcpt(email)
    // Send the email body.
    wc, err := c.Data()
    if err != nil {
        return err
    }
    defer wc.Close()
    buf := bytes.NewBufferString("Please confirm this email " + link)
    if _, err = buf.WriteTo(wc); err != nil {
        return err
    }
    return nil
}
</code>
If here an error is going to occur in the goroutine and response is already done(the user receive the response), how can I then handle the error?
Comment: Well that is up to you. You certainly should log the error. In terms of user experience - perhaps provide a "Request confirmation email resend" page where they can enter their email address and if their account is still "pending" the system can attempt to resend the email. I dare say the question as stated though is off-topic here.
Comment: How do you want to handle it?  You could send a push notification to the client, you could write something to the database, you could have a separate long-running background process waiting to handle errors in email goroutines, where the errors are communicated over a channel.  The only direct way to expose the error to another Go process is over a channel.  `Send` would take in an extra parameter (a channel) and rather than returning an error, it would send the error over the channel.
Comment: how can I send a push notification to the client, do you have some sample?
Answer: I'm assuming:

A person signs up for an account
You send them a confirmation e-mail with an activation link
Once they click the link their account can now "do stuff"

If this is the case:
You should probably record the failure or success of this send mail operation to some kind of stateful store (SQL DB, mongo, leveldb, etc), then when a user logs in (or navigates to a page) you can notify them their account still needs to be confirmed (assuming either the send operation OR the URL clicking the confirmation link never happened) and offer to resend the e-mail.
Another option would be to make response to submitting the e-mail address wait for the e-mail to be sent (don't start a goroutine), but that might not scale well if you have many signups.. AND you would still need to maintain the state of who as clicked the activation link anyway. So the first option is better.

Sending email in a goroutine


Correlation/similarity between binary and non-binary vectors

Question: I have a pool of thousands of binary vectors, all of the same length l.
I would like to sort them, by their correlation/similarity to a test vector v that also has length of l.
Also the vectors (test vector and the binary vector) are sparse - containing a majority of over 90% zeros while the test vector could be less sparse but also above 70%
Condensed example, v is the test vector:
v = [-1, 5, 0, 0, 10, 0, -7]
v1 = [1, 0, 0, 0 ,0 ,0 ,0]
v2 = [0, 1, 0, 0 ,1 ,0 ,0]
v3 = [1, 1, 0, 0 ,0 ,0 ,1]

I would expect to get here v2 for first place and and v3 for second, the reason why I want v3 to be second is that -7 matching 0 is more significant to 5 matching 1.
The logic behind what I'm looking for is that the higher the positive value is the more similar it would be for a 1 and the more negative a value is the more similar it would be to a 0.
Is there any method/correlation that is suited for this kind of purpose?
Comment: What is the formula behind "-7 matching 0 is more significant than (?) 5 matching 1"? This is not a normal correlation.
Comment: I know it's not that why I am having a problem with the solution... Simply put I want the bigger the absolute value is in the test vector to have more significance in the correlation calculation where negative values match zeros and positive to 1 - the example with -7 and +5 is to show that I want that -7 matching 0 is "stronger" than +5 matching 1
Answer: Absolute value of Pearson correlation solved this problem