Não permitir que o comando curl faça o download do meu site inteiro. É possível?

Question: Como eu poderia alterar meu código HTML, para que quando faça uma consulta com curl não traga o site inteiro HTML para o console? Uma falha de segurança que não sei resolver no meu site pessoal que estou criando, alguém pode ajudar por favor?
No código $ curl http://www.uol.com.br a resposta é:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">

<title>301 Moved Permanently</title>

Moved Permanently

The document has moved here.

Na Amazon, $ curl http://amazon.com a resposta é:

<title>301 Moved Permanently</title>

301 Moved Permanently

Server

Quando consulto o site pessoal que estou criando, so html, css e js, e armazenei num S3 bucket da AWS, baixa o site inteiro, como posso resolver isso? Muito obrigado.
Answer: Acontece que a url que tentou acessar tem um redirect, e o curl retornou essa primeira resposta que encontrou, sem tratar esse redirect.
Tenta a url correta, por exemplo: curl https://www.amazon.com/, ou ainda usar o parâmetro L para tratar os redirects: curl -L http://amazon.com e vai ver que funciona.
Acho que está entendendo errado o conceito, pra que quer impedir de devovler o response do html do site, para um request correto?
curl é apenas um client, poderia ser o navegador, e ia então impedir que alguém tivesse acesso ao teu site.
Além disso, o curl não vai fazer "download do seu site interiro", só var retorar o tiver na url, igual se fosse aberta no navegador.
Comment: Obrigado Ricardo, fiquei preocupado somente com seguranca, fiz um website simples e hospedei na AWS num S3 bucket, mas coloquei TLS e habilitei HTTPS com um certificado deles mesmo usando cloudfront, acho que vai ficar desse jeito mesmo por enquanto. Obrigado pelo feedback.
Answer: O curl sempre retorna o HTML do site. O que você está vendo no seu teste é um redirecionamento do http para https. Caso altere esses seus testes para fazer o request com https no lugar de http pegará o html que você espera. ex: curl https://www.uol.com.br.
Note que o mesmo também pode ocorrer para incluir ou remover www, a barra no final e outras coisas. Para certificar-se, abra o site em questão no seu navegador e verifique o endereço que aparece (ou siga o "rastro" pela resposta do curl).
Quanto à primeira pergunta, não é possível "proteger" o HTML, CSS ou JS do seu site. Entretanto é possível dificultar o entendimento e a leitura do mesmo, mas é o tipo de coisa que não faz muito sentido e inclusive costuma ser motivo de piada (o Scott Hanselman, inclusive, fez essa piada na abertura do NDC Porto 2020).
Caso seja mesmo o objetivo, é possível diferenciar a resposta do servidor quando se usa um navegador ou outro, ou até mesmo um programa que não seja um navegador. Em geral se faz isso pelos headers, entretanto, não serve como "proteção", uma vez que podem ser adicionados os headers para se passar por um navegador.
Outra possibilidade é não ter somente uma "base" no HTML original e carregar todo o site com JS, substituindo o conteúdo do , por exemplo. Um bom exemplo disso são os sites gerados na plataforma WIX.
Um exemplo outro exemplo onde o curl não retorna o esperado é o amazon.com, onde o resultado de curl https://www.amazon.com/ é a imagem abaixo.
Comment: "Isso pode ser feito pelo user-agent" - só se for pra espantar curioso. Não tem como diferenciar de um browser pelo user-agent pelo simples fato de que basta por um igual do browser ao usar o cURL. A única resposta válida para essa pergunta seria "Não tem como" (e poderia ser complementada com "quase certeza que não tem motivo também"). SE a pessoa quiser evitar scrap de dados, pode fazer outras coisas para minimizar automação (colocar um captcha, por exemplo), mas realmente são poucos casos de uso que justificam.
Comment: Aí é falha no teste, e não proteção da Amazon. Experimente por os headers iguais os de um navegador comum e verá o mesmo source que no browser (que não vai ter muita graça pq é cheio de JS, mas será o mesmo).
Comment: Complementarei a resposta @Bacco, uma vez que esqueci de responder a 1a pergunta e respondi somente a parte do curl ao uol e Amazon. E como vc pode ver no exemplo da Amazon, não só é possível, como eles o fizeram. Não testei todas as possibilidades para confirmar como fizeram.
Comment: Sim, e as 2 questões foram respondidas. E obrigado por comentar. Quando não há comentários é impossível saber o que está mal na resposta.
Comment: De qualquer forma, só pra constar, esses negativos aí não são meus. Eu tou comentando pra apontar os problemas apenas. O problema maior mesmo é a premissa da pergunta.
Comment: obrigado de qualquer forma. complementarei a resposta com mais alguns comentários :)
Comment: Dias, obrigado pela forca e pela resposta bem detalhada, sou nubao em webpage, fiz um negocio caseiro, e hospedei na AWS, vou estudar mais e dar um tapa no website, acho que vou usar o wordpress. E' isso que preciso fazer, dar uma enganada no curl quando usa o console do linux, vou pesquisar mais a respeito, obrigado pela forca.


Captar um clique em 3D no openGL

Question: estou fazendo um trabalho em openGL. Queria clicar em uma janela e um desenho aparecer onde foi clicado. Como o cenario eh em 3D queria saber como faco para obter o valor da coordenada em Z.
Alguem poderia dizer um passo-a-passo de como fazer? =)
Comment: bem vinda ao *StackOvarflow*, seria interessante você colocar jundo da sua pergunda, um trecho do código que você já tem feito. Isso ajuda para dar uma resposta final.
Answer: Existem diferentes técnicas para trabalhar com seleção de objetos em OpenGL. Conheço essas duas:

Cada objeto na cena deve possuir um id em memória, quando você capturar o clique, você deve percorrer todos os objetos que estão sendo renderizados e verificar se há colisão entre a coordenada de clique e cada objeto. Você deverá aplicar a sua matriz de projeção, antes de verificar a colisão.
Desenhar em um buffer separado, utilizando cores diferentes para cada objeto, ao receber o evento do clique, leia a cor do pixel naquela posição e consulte a cor em uma dicionário de cores->objetos
Answer: Você tem que trabalhar sobre uma textura OpenGL da viewport que possa ser usada pelas funções OpenGL.
Então eu conheço 2 soluções:

Usar uma função que leia um pixel (glReadPixel se eu não me engano). Mas geralmente essa comunicação entre GPU e CPU é lenta.
Criar um código glsl que passa como uniformes as coordenadas do mouse e a textura (criada com o glGenTextures). O trabalho seria feito diretamente na GPU, então seria uma forma mais eficiente.

Captar um clique em 3D no openGL


Feature extracted by max pooling vs mean pooling

Question: In deep learning, and it's application to computer vision, is it possible to tell what kind of features these two types of pooling extract? e.g. is it possible to say that max pool extracts edges? Can we say something similar regarding mean pooling?
P.S. feel free to recommend if stackoverflow is more suitable.
Answer: I wouldn't say the either extract features.  Instead, it is the convolutional layers that construct/extract features, and the pooling layers compress them to a lower fidelity.  The difference is in the way the compression happens, and what type of fidelity is retained:

A max-pool layer compressed by taking the maximum activation in a block.  If you have a block with mostly small activation, but a small bit of large activation, you will loose the information on the low activations.  I think of this as saying "this type of feature was detected in this general area".
A mean-pool layer compresses by taking the mean activation in a block.  If large activations are balanced by negative activations, the overall compressed activations will look like no activation at all.  On the other hand, you retain some information about low activations in the previous example.
Answer: my opinion is that max&mean  pooling is nothing to do with the type of features, but with translation invariance.
Imagine learning to recognise an 'A' vs 'B' (no variation in A's and in B's pixels).  First in a fixed position in the image. This can be done by a logistic regression (1 neuron): the weights end up being a template of the difference A - B.
Now what happens if you train to recognise on different locations in the image. You cannot do this with logistic regression, sweeping over the image (ie approximating a convolutional layer with one filter) and labelling all sweeps of the image A or B as appropriate, because learning from the different positions interferes - effectively you try to learn the average of A-B as A/B are passed across your filter - but this is just a blur.
with max pooling learning is only performed on the location of max activation (which is hopefully centred on  the letter). I am not so sure about mean pooling - I would imagine that more learning (ie weight adjustment ) is done at the max activation location and that avoids the blurring)...
I would encourage you to just implement such a simple network with 2 classes and 1 filter for convolutional layer, then max/mean pooling and 1 output node and inspect the weights/performance.


A few questions on an application of the residue theorem

Question: I have got the following closed curve $\gamma$

and I am supposed to calculate
\begin{equation}
\int_\gamma\frac{\cos(z)}{z^3(z^2 +1)}dz
\end{equation}
with the help of the residue theorem.
Now, I've got a few questions

$0$, i and -i are the isolated singularities of our given function. As far as I understand it, the winding number of $0$ is $-2$, the winding number of $-$i is $-1$ and the winding number of i is $0$. Is this correct?
How can I determine the residue in this case? For a start, I tried finding the Laurent expansion for $z_0=0$, but I have no idea how to rearrange the equation further. I only got as far as
\begin{equation}
\frac{\cos(z)}{z^3(z^2 +1)}=\frac{1}{z^2+1}\sum\limits_{n=0}^{\infty}(-1)^n\cdot\frac{z^{2n-3}}{(2n)!}.
\end{equation}
Could someone give me a hint on how to find the Laurent expansion?

Thanks in advance!
Comment: @José has given you a good answer. If you don't like using "rules" to calculate the residue, but want to see the relevant bit of the Laurent Series , just expand $(1+z^2)^{-1}$ as a GP as usual. You'll get the same residue (!).
Answer: Your conclusions about the winding numbers and singularities are correct.
At $z=0$, $\cos(z)=1-\frac12z^2++O\!\left(z^4\right)$ and $\frac1{1+z^2}=1-z^2+O\!\left(z^4\right)$. Thus,
$$
\frac{\cos(z)}{z^3(1+z^2)}=\frac1{z^3}-\frac32\frac1z+O(z)
$$
At $z=\omega$, where $\omega^2+1=0$, the residue is
$$
\begin{align}
\lim_{z\to\omega}(z-\omega)\frac{\cos(z)}{z^3(z^2+1)}
&=\frac{\cos(\omega)}{\omega^3}\lim_{z\to\omega}\frac{z-\omega}{z^2+1}\\
&=\frac{\cos(\omega)}{\omega^3}\frac1{2\omega}\\[3pt]
&=\frac{\cosh(1)}2
\end{align}
$$
Answer:
You are right.
Let $f(z)=\frac{\cos(z)}{z^2+1}$. Then\begin{align}\operatorname{res}_{z=0}\left(\frac{\cos(z)}{z^3(z^2+1)}\right)&=\operatorname{res}_{z=0}\left(\frac{f(z)}{z^3}\right)\\&=\frac{f''(0)}{2!}\\&=-\frac32.\end{align}


When counting in, why do people often do it at two speeds? (1_2_1234)

Question: Something simple that I've found curious:
When people 'count in' a tune, to get all the players ready to start at the same time, I often hear them do it first at half-speed, then at full speed.
e.g. if the tune is in 4/4, and there are 4 characters to a bar below, they'll say:
1_2_1234
        ^everyone starts playing here

i.e.
1_2_        (either 2 beats (counts) at half the expected tempo;or a whole
            bar of the 'right' tempo, but saying 'two' on the 3rd beat)
1234        (a 4-beat bar at the 'right' tempo for the upcoming tune)

I realise not everyone does this; some just go: 1234 or 12341234 at 'full-speed', but it's quite common, and I wondered why. I guess it's a just a getting-you-ready introduction.
When I hear someone start with their initial 'one two', is there a way to tell immediately whether that 'one two' is the first two beats at the real tempo, or just the half-speed into, with a doubling of the speed about to follow?
Comment: Strictly speaking, it should be 1,**3**, 1234.
Comment: Because 1, 3, 1234 doesn't have the right ring to it.
Comment: Not all time signatures are counted this way. 3/4 is usually fully counted twice. I don't think I've ever counted 5/4 or 7/4, I usually sing something distinctive, such part of the melody or bass line, while snapping fingers. As for 4/4, I'd say the first 1-2 gives a general indication of the tempo while the following 1-2-3-4 allows for a tight start.
Comment: @isanae - for 5/4 and 7/4 it's usually a whole bar. premise being, it's long enough to cotton on to the pulse. All a hundred piece orchestra gets is an upbeat !
Comment: Used to work with a band where the leader would just go **uh**,  uh,  **uh**- uh- uh- uh. Worked fine! ( for 4 time - obviously!)
Comment: @isanae I played Pink Floyd's Money on bass before, and I can't imagine how we'd even try to count in for that other than the bass player just kind of ... start playing when he's ready and everyone else comes in when they should.
Comment: I don't know how often people actually do that. It's used a lot in film and TV, which means it's often seen as 'the way' to count a band in.
Comment: @isanae in my prog band we always count 3-2-1-♩ for this reason, or up to 7654321♩ depending on the time signature and tempo, but it's always unambiguous where to start.
Comment: It depends on the song. My band used to play a song that started with 3 notes on 3-4-1. Then drum roll around on like 1.5-2-3-4-1-2 and then the 3 notes again on 3-4-1, then into the song.  Then The Beatles had 1,2,3,4,1,2 4! to start Taxman.
Answer: I can't prove this, but it's possible it's an outgrowth of the military cadence tradition, where the drill sergeant calls out

Left (pause) Left (pause) Left Right Left

As I understand it, the two lefts are isolated a) to help beginners in the military focus on which foot hits when, and b) because the drill sergeant just plain needs to take a breath somewhere.
This could have made its way into musical tradition through the use of marches, specifically marches played by military bands.
But perhaps this is a chicken-and-egg scenario, in which case I don't actually know which one came first...
Answer: When recording a song, you have to know the tempo you're going to play before the song start, as well as when to start playing.
Since there is sometimes a pickup measure, a single measure of count-in (also called "pre-roll" in recording) would be too little, so a two measure count in is standard.
You could count "one two three four one two three four" or "one two three four two two three four" but both of those can be confusing for different reasons. Convention is that the first measure is counted on the half notes and the second measure is counted on the quarter notes.
If there is a pickup (aka anacrusis), then the count may be interrupted before the first note is played. E.g., "one --- two --- | one two three" and first note on four.
Another way to do the same thing is with a click track that has a pre-roll. In those cases, the two measure pre-roll usually has emphasized clicks on all of the downbeats, and since there is no other articulation for clicks, it's even more important for the click pattern to change between the first and second measure of pre-roll. So that means you get click --- click --- | click click click click.
Click tracks typically play during the whole track as a reference, especially for any breaks. Sometimes click tracks are suppressed for some parts of overdubs if the musician needs to follow an existing track more closely than the click, and the click might just be used for count in and breaks.
Regarding how to tell what the real tempo is from the first count/click, normally all the musicians who are about to play at the end of the count-in have practiced the song and should know the approximate tempo. Anyone who can't immediately tell that the tempo is about half the speed they expect it to be isn't ready to perform or record.
Comment: In some informal settings, the initial count may be used not only to set tempo, but also to get all the performers' attention.  If it doesn't seem like everyone is immediately ready, the count may end up going "one, two, one, two, one, two, one two three four!" with the shift to the faster counting indicating that since everyone is finally ready, the performance can (and should) begin.
Comment: There are many ways to skin this cat. Conductors give nothing more than one upbeat, and when Menuhin tried to give the Berlin Phil a full bar they didn't know what he was talking about. Hal Blaine of the LA Wreckng Crew used to give the first 5 quarter notes and then three beats of silence.
Comment: But it would be arguably more correct to count "one --- *three* --- | one two three [four]".
Comment: @EJP: "Conductors give nothing more than one upbeat" - that's a big generalisation! I've known plenty of conductors who gave a full bar or more. Perhaps you're referring to conductors of professional orchestras?
Comment: @EJP The question is about why people use this count in technique, not about all the other types of count ins used in different areas of music. But yes, there are many different ways people synchronize the beginning of an ensemble performance.
Comment: @ToddWilcox That's why I posted a comment, not an answer.
Comment: @psmears I'm referring to symphonic conductors, the guys with batons.
Comment: BTW, I should have mentioned another advantage of the pre-count: letting the *audience* know the song is starting, and let the performers know the leader thinks the audience is ready.
Answer: I think most of this is personal preference.  People find that it works, so they do it.  However, your question sentence about how to tell if they are giving you the "real" tempo or "half speed" tempo is actually a rather interesting one.  Music doesn't have just one tempo.  That's part of what makes it beautiful.  There's the tempo you are playing quarter notes at, then there's the tempo you are playing half notes at.  Then there's bars.  Then there's phrases.  Theres's lots of valid tempos, any one of which could be considered to be the "real" tempo, if it wasn't for that pesky written score which defines the tempo based on a specific note.
Again, it's all personal preference, but I find that tempos build up from the slow to the rapid in a form similar to how the higher voices like the sopranos build upon the foundation made by the bases.  In that sense, it makes sense to lay down the lower frequencies before the higher ones.
In that vein, I have heard it counted "1 -- 2 -- 1 2 3 and 4 and," where the "and's" provided the expected feel for eighth notes.
But as EJP points out in his comments, there are indeed conductors who give nothing more than a single upbeat.  They convey the tempo (and more) via other body language and an expectation that the orchestra is skilled in following their lead.  So you really do see all kinds.
However, in general, I find all conductors do what is necessary to give you a hint that the song is actually starting, no matter how they call out the time.  As such, if you find that you are getting "fooled" by this counting style, you can practice what it feels like to double your frequency.  When you hear the 2nd '2' appearing way too early, that's your sign that you need to begin doubling your tempo when they call out '3'.  After a while, it can become automatic.
And you can always ask =)
Comment: +1 I *always* count 6/8 as 3/4, and then mentally adjust the length of each note. Somehow that's easier.
Comment: I assume you mean counting the eightnotes?  Counting quarters before entering in 6/8 would seem very awkward.
Answer: I love questions like this! I count like this when I'm counting in for a band, and I just had to take a step back and evaluate, and I think the reason I do it is this:
A count of just '1234' would be too fast, from starting the count to expecting people to play on the next '1', meaning the start would be sloppy.
If I count '12341234', unless it's explicitly defined with everyone I might count in for ever that I give 2 bars of count, every so often I'd get some people starting on the second '1' in the middle of my count. Not just sloppy, ugly.
If I count 1_2_3_4_, then that doesn't convey the feel of the song that I clearly want to, in which the measures are quite short (i.e. 1234), and the feel is as such. Risks getting the feel wrong.
Therefore, the logical conclusion is to use the style put forward in your question, to both give people time to get ready to play, and to convey the feel that the measures are short.
As for your second sub-question, no, it's not possible to tell after the 2_ that I'm going to count double after that, but either way, unless you're counting a song in 2 (i.e. 1_2_1_2_), you're not going to play on the next beat, meaning you don't strictly need to know what's coming next.
Comment: If a small band needs two whole bars, how does a large orchestra manage with just an upbeat?
Comment: @Tim: Orchestras often do much more rehearsal, and will be much more focused on the conductor when he's about to start.  Small informal groups will often get requests for songs that the members know, but which they might never previously have performed together.  Further, if group members aren't all immediately focused on the next song, having the leader just start counting may come across better than "Hey guys--can we start now"?
Comment: @supercat - I used to go to plenty of orchestra rehearsals, and two or three hours did it for the evening's performance. Most bands seem to rehearse for a lot more than that, to achieve far less playing time. And, really, at a gig, surely it's important that the group members do concentrate on what's next?
Comment: @Tim: Sure, two or three hours might be sufficient, but that would imply that the group has played each piece together at least once.  In many cases, gigging groups may be performing songs that some members have *never* heard the rest of the group play.  Further, after writing the above I realized another important role--letting the *audience* know that the performance is about to begin.  At a symphony concert, audience members are there primarily for the performance, but at a restaurant or nightclub many audience members will be present for other reasons but still be interested in the music.
Comment: Having a band leader call out "Could everyone be quiet please--I'm about to start playing" could be somewhat awkward for all concerned; having the band leader simply start counting very loudly would be faster and generally less awkward.
Answer: It's mostly showmanship for the audience, tradition for certain genres (jazz big band comes to mind), and maybe a little bit of pep for the group. For merely getting the group to start together, it's certainly excessive.

When I hear someone start with their initial 'one two', is there a way to tell immediately whether that 'one two' is the first two beats at the real tempo, or just the half-speed into, with a doubling of the speed about to follow?

No way to tell.
Comment: Funny I hear this only in recording situations where a two measure pre-roll is extremely popular.
Comment: It's not just showmanship--in informal situations, it's a matter-of-fact way to let the audience know that the music is about to start.  At a symphony orchestra concert, the audience will presumably be waiting for the performance, but in a nightclub people would often be expected to converse until the music starts.  If a performer were to say "Okay everyone--finish up your conversations because we'd like to start", that could create some awkwardness all around.  Having the performer give a count-in will give the audience a chance to very quickly put their conversations on hold.
Comment: A couple of times lately, a bandleader has counted in like this, but *very* quietly, and I've missed the intro. Worse - I've been the only one playing, or supposed to be! Please make it clear - or I'll have to start using my hearing aid.
Answer: I am not a musician, but a swing dancer, thus this answer may provide a
somewhat different perspective.
Swing dancers count beats from 1 to 8, as an 8-beat "phrase" is, to a
dancer's point of view, a more fundamental unit than the 4-beat bar.
When training, swing dance instructors always count in like:
5 6 5678
        ^first rock-step goes on beat "1" here

There is no ambiguity about whether the first "5 6" is the real
tempo or half tempo, because:

everybody starts counting half-tempo
if counting on top of the music, we do hear the music
if counting without music, the initial tempo would likely be too slow
to be reasonable.

I always felt this was quite natural because, once I hear "5 6", my
mind extrapolates up to the next "1":
5 6        <- heard
    7 8 1  <- extrapolated

so I already know when is the right time to start. When I hear the
second "56", the same kind of extrapolation puts the 1 on the same place
as before:
5 6        <- heard
    7 8 1  <- extrapolated
    56     <- heard
      781  <- extrapolated

So it would appear that the initial "5 6" and the subsequent "5678"
work like a coarse countdown and a finer-grained countdown that are
aligned to converge to the same start time.
Once, when I was training fellow dancers, I tried to count in like
1 3 5678

It looked more natural to me, as it has the same rhythm as
"5 6 5678", and it also has more logical counts (beat 1 is
counted "1" instead of "5"). Every one got confused and missed the
start, so I reverted to the traditional way of counting in.
Answer: Often when the tempo of a piece of music is quite fast it is convenient for the musicians to think of the pulse/beat of the music as being in 2 minims (half notes) per bar rather than 4 crotchets (quarter notes) and this is often notated onto the music by giving it a time signature of C with a line through it (Cut Common) rather than 4/4.
In these cases, for the avoidance of doubt and to get the musicians thinking of both the main pulse and how fast the crotchets (quarter notes) are going to be, so they can choose whether they want to keep thinking of the pulse personally as being in 2 beats per bar or 4 beats per bar it is helpful to count in as 1-2-1234, with the initial 1-2 being in the minim (half note) speed and the final 1234 being in the crotchet (quarter note) speed.
Over time it has become the custom and also sounds cool!
Comment: Even when music is counted in 4, it seems the primary large unit of structure is often the breve (8 crotchets) rather than the semi-breve ("whole" note).  It's too bad that when bar lines were added there wasn't a convention to use breve-length measures along with a mid-measure mark.
Answer: Others have given pretty much the same answer to the first half of your question that I would give, but in answer to the second half of your question:

When I hear someone start with their initial 'one two', is there a way
  to tell immediately whether that 'one two' is the first two beats at
  the real tempo, or just the half-speed into, with a doubling of the
  speed about to follow?

I, and all the directors I had before me who would ever "count in" a song like this would actually start with a finger snap (or if it's the drummer, a hi-hat or stick click) on 2 & 4.  We'd keep that finger snap/click going for a measure or more to get the tempo ingrained and make sure the musicians got ready for the count in.
So if the count ended up being "1" (snap) "2" (snap) "1 2 3 4".. then you knew as soon as you heard the snap between 1 and 2, that the count had started at half-tempo.  If the count were starting at full tempo, then that first "2" would be simultaneous with a snap.
Now if somebody did just a verbal count with no accompanying snap/click to indicate the tempo, then there would be no way to know, but honestly, I don't think I've ever seen anybody do that, though I'm sure somebody somewhere has done it.
Answer: To answer the specific question: A piece in 4/4 time is normally played with 2 or 4 beats per measure (or more rarely, 1 or 8 beats per measure). Different players in the group might "feel" it differently, and the two-speed count-off (1 - 2 - 1 2 3 4") lets them internalize the intended tempo in whichever manner they're most comfortable with. The "1 - 2 -" is for those feeling it in two, and the "1 2 3 4" is for those feeling it in four.
As far as the question of "how do you know how much count-off to expect", the person doing the count-off should state this up front if it isn't already obvious from context or previous experience.
To address the broader issue: A long count-off is used in two broad situations. The first is when the group does not have a conductor. One of the players does the count-off so that everyone can internalize the tempo and start in sync, after which they rely on listening to each other to maintain the tempo and stay in sync.
In the second situation — when the group has a conductor — there could be a number of issues at play:

It could just be a showy effect for the audience's benefit, common with jazz groups.
It could be a group of players with low levels of experience, such as a school or community band.
It could be a group of players (even professionals) who have not had much (or any) rehearsal together — they might have subs or they've just gotten together for this particular performance and are essentially sight-reading.

In general, in an experienced group that has a good conductor and has rehearsed together before — especially orchestras and wind ensembles — the conductor can convey the tempo using just a single preparatory gesture of the baton. This is the most "professional" way to do it.


How Hybris is managing Application Contexts between the application and integration tests

Question: I am currently new to Hybris and I am writing integration tests, which is awesome however it is hard for me to understand the concept of junit tenant and how Hybris is managing the application context for that tenant.
I come from a spring background, and there I can say it was easy to load a separate test configuration or any configuration, and just to test it without affecting the main run time application context that is used lets say for debugging at the same time.
However in Hybris, I am kind of confused because while the server is running you can easily swap between tenants and execute integration test at the same time when lets say some user is buying something.
Does Hybris has separate application context for junit and master tenant ?
And regardless of yes or no, how is Hybris managing the application contexts between tenants ?
I first encounter this problem when I was declaring the ehCacheManager bean, and suddenly all my tests started to fail - something that the cache is in SHUTDOWN mode ... which was strange.
Is the application context shared between tenants ?
Is it shared between two separate integration tests ?
Is it destroyed after one test, then created for another integration test ?
I know that some of this questions might seems confusing or even stupid, but I will be glad if someone can explain me how hybris is managing the application context between tenant and tests, furthermore I will be really grateful if you can share some resources or books on this topic.
Thanks in advance !!!
Answer:
Does Hybris has separate application context for junit and master tenant ? And regardless of yes or no, how is Hybris managing the application contexts between tenants ?

Yes, please find below a scheme representing it (source SAP : https://help.hybris.com/1811/hcd/8c63621986691014a7e0a18695d7d410.html Cf. Figure: Hierarchy of Application Contexts.).

Not that in your case junit is what we call a "slave" tenant.

Is the application context shared between tenants ? Is it shared between two separate integration tests ? Is it destroyed after one test, then created for another integration test ?

As you can see in the scheme, the global application context is shared but web (case of ehCacheManager I think) and core application context are not shared. These don't change when you run tests.
Comment: Thank you alain.janinm
It is way more clear now for me.
Answer: Firstly it is not good way to making test while customer buying somethings on same or pre-prod server.
Tenant is different concept rather than spring for hybris. hybris tenant is using multiple database-schema for same code base. You can run multiple hybris on same db with tenant. One of them is junit tenant for making test. hybris not rollback/reset db changes on junit. You need to initialize it look like normal tenant in hac or with ant.

You need to manually manage test data in unit test.
You can run test with ant or front end after start at url https://localhost:9002/test

hybris junit test documentation here.


Erro ao usar o

Question: Estou tendo dificuldades com algo que parece ser simples de resolver, mas já perdi um tempo considerável nisso, espero que alguém possa me ajudar.., bom.., na minha View utilizo o pra chamar um método antes de renderizar a tela pro usuário, mas apresenta a seguinte mensagem direcionada ao
Method must have signature "void method(ComponentSystemEvent)" but has signature "void method()"

já troquei a dependência do jsf pra uma versão inferior mas continua com o mesmo problema(versão atual é 2.2.8), adicionei o argumento ComponentSystemEvent event no método mas não resolveu, segue a tela e a Bean..
package com.mwcc.pedidovenda.controller;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.faces.view.ViewScoped;
import javax.inject.Inject;
import javax.inject.Named;
import javax.validation.constraints.NotNull;

import com.mwcc.pedidovenda.model.Categoria;
import com.mwcc.pedidovenda.model.Produto;
import com.mwcc.pedidovenda.repository.CategoriaRepository;
import com.mwcc.pedidovenda.service.CadastroProdutoService;
import com.mwcc.pedidovenda.util.jsf.FacesUtil;

@Named
@ViewScoped
public class CadastroProdutoBean implements Serializable {

    /**
     *
     */
    private static final long serialVersionUID = 1L;

    @Inject
    private CategoriaRepository categorias;

    @Inject
    private CadastroProdutoService cadastroProdutoService;

    private Produto produto;

    private Categoria categoriaPai;

    private List<Categoria> categoriasRaizes;
    private List<Categoria> subcategorias;

    public CadastroProdutoBean() {
        limpar();
    }

    public void salvar() {
        this.produto = cadastroProdutoService.salvar(this.produto);
        limpar();

        FacesUtil.addInfoMessage("Produto salvo com suceso!");
    }

    public void inicializar() {
        if (FacesUtil.isNotPostback()) {
            categoriasRaizes = categorias.raizes();

            if (this.categoriaPai != null) {
                carregarSubcategorias();
            }
        }

    }

    public void carregarSubcategorias() {
        subcategorias = categorias.subcategorias(categoriaPai);
    }

    private void limpar() {
        this.produto = new Produto();
        this.categoriaPai = new Categoria();
        this.subcategorias = new ArrayList<>();
        this.categoriasRaizes = new ArrayList<>();
    }

    public Produto getProduto() {
        return produto;
    }

    public void setProduto(Produto produto) {

        this.produto = produto;
        if (this.produto != null) {
            this.categoriaPai = this.produto.getCategoria().getCategoriaPai();
        }

    }

    public List<Categoria> getCategoriasRaizes() {
        return categoriasRaizes;
    }

    public List<Categoria> getSubcategorias() {
        return subcategorias;
    }

    @NotNull
    public Categoria getCategoriaPai() {
        return categoriaPai;
    }

    public void setCategoriaPai(Categoria categoriaPai) {
        this.categoriaPai = categoriaPai;
    }

}

    <ui:composition template="/WEB-INF/template/LayoutPadrao.xhtml"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:o="http://omnifaces.org/ui">

    <ui:define name="titulo">Novo produto</ui:define>

    <ui:define name="corpo">
        <f:metadata>
            <o:viewParam name="produto" value="#{cadastroProdutoBean.produto}" />
            <f:event listener="#{cadastroProdutoBean.inicializar}" type="PreRenderView"></f:event>
        </f:metadata>

        <h:form>

Novo produto

                    <f:selectItem itemLabel="Selecione a categoria" />
                    <f:selectItems var="categoria"
                        value="#{cadastroProdutoBean.categoriasRaizes}"
                        itemLabel="#{categoria.descricao}" itemValue="#{categoria}" />

                    <f:selectItem itemLabel="Selecione a subcategoria" />
                    <f:selectItems var="subcategoria"
                        value="#{cadastroProdutoBean.subcategorias}"
                        itemLabel="#{subcategoria.descricao}" itemValue="#{subcategoria}" />

                    <f:convertNumber maxFractionDigits="2" minFractionDigits="2" />

        </h:form>
    </ui:define>
</ui:composition>

Answer: O log de erro te ajuda a resolver o problema: Method must have signature "void method(ComponentSystemEvent)" but has signature "void method()"
Tenta reescrever o método com a seguinte assinatura:
 public void inicializar(ComponentSystemEvent event) {...}

Erro ao usar o


oozie job submission fails with check your configuration for mapreduce.framework.name and the correspond server addresses

Question: 2013-04-29 14:47:28,686  WARN ActionStartXCommand:542 - USER[oozie] GROUP[-] TOKEN[] APP[map-reduce-wf] JOB[0000000-130429144458254-oozie-oozi-W] ACTION[0000000-130429144458254-oozie-oozi-W@mr-node] Error starting action [mr-node]. ErrorType [TRANSIENT], ErrorCode [JA009], Message [JA009: Cannot initialize Cluster. Please check your configuration for mapreduce.framework.name and the correspond server addresses.]
org.apache.oozie.action.ActionExecutorException: JA009: Cannot initialize Cluster. Please check your configuration for mapreduce.framework.name and the correspond server addresses.
  at org.apache.oozie.action.ActionExecutor.convertExceptionHelper(ActionExecutor.java:412)
  at org.apache.oozie.action.ActionExecutor.convertException(ActionExecutor.java:392)
  at org.apache.oozie.action.hadoop.JavaActionExecutor.submitLauncher(JavaActionExecutor.java:760)
  at org.apache.oozie.action.hadoop.JavaActionExecutor.start(JavaActionExecutor.java:911)
  at org.apache.oozie.command.wf.ActionStartXCommand.execute(ActionStartXCommand.java:211)
  at org.apache.oozie.command.wf.ActionStartXCommand.execute(ActionStartXCommand.java:59)
  at org.apache.oozie.command.XCommand.call(XCommand.java:277)
  at org.apache.oozie.service.CallableQueueService$CallableWrapper.run(CallableQueueService.java:175)
  at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
  at java.lang.Thread.run(Thread.java:662)
Caused by: java.io.IOException: Cannot initialize Cluster. Please check your configuration for mapreduce.framework.name and the correspond server addresses.
  at org.apache.hadoop.mapreduce.Cluster.initialize(Cluster.java:121)
  at org.apache.hadoop.mapreduce.Cluster.<init>(Cluster.java:83)
  at org.apache.hadoop.mapreduce.Cluster.<init>(Cluster.java:76)
  at org.apache.hadoop.mapred.JobClient.init(JobClient.java:495)
  at org.apache.hadoop.mapred.JobClient.<init>(JobClient.java:474)
  at org.apache.oozie.service.HadoopAccessorService$1.run(HadoopAccessorService.java:362)
  at org.apache.oozie.service.HadoopAccessorService$1.run(HadoopAccessorService.java:360)
  at java.security.AccessController.doPrivileged(Native Method)
  at javax.security.auth.Subject.doAs(Subject.java:396)
  at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1408)
  at org.apache.oozie.service.HadoopAccessorService.createJobClient(HadoopAccessorService.java:360)
  at org.apache.oozie.action.hadoop.JavaActionExecutor.createJobClient(JavaActionExecutor.java:954)
  at org.apache.oozie.action.hadoop.JavaActionExecutor.submitLauncher(JavaActionExecutor.java:711)

Comment: Try this: http://stackoverflow.com/questions/12831226/running-wordcount-sample-using-mrv1-on-cdh4-0-1-vm-solved
Comment: Unfortunately i dont have a hadoop-env.sh .How do i add the variable mentioned in the above post ?
Comment: What versions / distributions of Hadoop and Oozie are you currently using?
Answer: In my case, this error was given by a typo in workflow.xml: <name-node>{$nameNode}</name-node> instead of <name-node>${nameNode}</name-node>.


Private enum inside class

Question: I have a lot of classes where each class contains a map with completely different search keys. Each map has 4 items on average => 4 search keys on average.
Example:
class A
{
 private final static Map<String, String> properties;
 static
  {
    Map<String, String> tmp = new HashMap<>();
    tmp.put("NearestNeighbour", "INTER_NEAREST");
    tmp.put("Bilinear", "INTER_LINEAR");
    tmp.put("Bicubic4x4", "INTER_CUBIC");
    properties = Collections.unmodifiableMap(tmp);
  }

  private enum InterpolationMode
  {
    NN("NearestNeighbour"),
    Bilinear("Bilinear"),
    Bicubic("Bicubic");

    private String mode;
    InterpolationMode(String mode) {
      this.mode = mode;
    }

    public String getMode(){
      return mode;
    }
  }
}

In this class my keys for map are NearestNeighbour, Bilinear, Bicubic4x4 so I created a private enum and retrieve the value from map like this properties.get(InterpolationMode.Bilinear.getMode());
The problem is that I have about 20 classes and each class has it's own map with different keys ( they are not related ). The global package enum does not make sense for me since those search keys are not related in any way. Is it a good idea to create private enum like that in each class? Or is there a better way to do that and does not use enum at all?
Answer: Using enums for this purpose is totally fine. What you could consider is using enums as keys (instead of strings) and using EnumMap instead of HashMap.
Map<InterpolationMode, String> tmp = new EnumMap<>(InterpolationMode.class);
tmp.put(InterpolationMode.NN, "INTER_NEAREST");
tmp.put(InterpolationMode.Bilinear, "INTER_LINEAR");
tmp.put(InterpolationMode.Bicubic, "INTER_CUBIC");

The advantage of EnumMap is that it is more compact and efficient.
Answer: Are you creating many classes just to hold different maps of data? If so, it is better to create only one class, then create many objects from that class.
Using global enums is ok, as long as the enums have real meanings (e.g. gender, types of bank accounts).
Comment: It is quite fine to create different classes as "scopes" for different enums/keys.

Private enum inside class


Azure Data Factory: Configure Frequency

Question: I am planning to use Azure Data Factory as a trigger for data lake analytics jobs in a project.
The data lake jobs will calculate key figures based on sensor input data that is processed by StreamAnalytics and stored in Data Lake.
These jobs should calculate the values every ~5 minutes.
According to Microsoft documentation it is not possible to configure intervals / frequencies smaller than 15 minutes.
Anybody faced the same problem and found a solution or is it better to use a different tool as Azure Data Factory in this scenario?
Answer: As you already noticed - the minimal configurable interval is 15 minutes. If you look for tinier intervals you should look at streaming solutions amd not Data Factory. Because there is nit real context in your question, I cannot suggest you which service you should look at. But Azure Logic apps may be a good candidate as there you can have down to 1 interval.
Comment: Two comments: First, ADF v2 Scheduler now shows an interval option of "Every Minute". Second, we use Logic Apps to trigger our Data Factories, so this is definitely viable. A couple of caveats though: 1) ADF execution directly from logic apps is still in preview and currently does not support passing parameters [we overcame this with an Azure Function] and 2) the logic app will not wait for the data factory to complete, it will just start the pipeline [this probably does not matter in your scenario, just sharing the info].
Comment: Instead of commenting you could post an answer whuch is relevant **today**. As you can see this question and its answer were publ7shed more than an year ago. When neither ADF v2 nor ADF execution from logic apps were there.
Answer: In ADF one cant have a frequency lesser than 15 mins advisable.
https://learn.microsoft.com/en-us/azure/data-factory/data-factory-scheduling-and-execution
For your use case you can take a look at Azure Stream Analytics which is meant for streaming ingestion from IOT
https://learn.microsoft.com/en-us/azure/stream-analytics/
Answer: You could do this with multiple copies of your pipeline with different names and different availability configurations in your output datasets. For example, 3 pipelines with 3 datasets set to these 3 availability configs would cover each 5-min interval:
<code>"availability":
{
    "frequency": "Minute",
    "interval": 15,
    "anchorDateTime":"2017-10-01T00:00:00"
}
"availability":
{
    "frequency": "Minute",
    "interval": 15,
    "anchorDateTime":"2017-10-01T00:00:05"
}
"availability":
{
    "frequency": "Minute",
    "interval": 15,
    "anchorDateTime":"2017-10-01T00:00:10"
}
</code>
Note you might need to implement some kind of synchronization lock if you don't want the executions to overlap.
Answer: I am using ADF v2 and I can have a frequency lesser than 15 mins. for example you can see that I have a trigger for each minute.

Azure Data Factory: Configure Frequency


jQuery .submit() woes with IE8

Question: I am trying to submit a delete link click via a http post to my asp.net mvc controller. While my code below works for chrome it does not work in IE8. Any pointer will be very useful.
Setup:

Browser: IE8
jQuery: 1.4.1
MVC: 2.0

The delete link is:-
<a title="Delete contact" href="/Contacts/Delete/<%= Model.Contact.Id %>" class="delete" rel="Are you sure you want to delete <%= Html.Encode(Model.Contact.Name) %>?">Delete

and the jQuery handler for the click of delete is
$("a.delete").click(function() {
if (confirm($(this).attr("rel"))) {
    var form = "<form method='POST' action='" + $(this).attr("href") + '" style='display:none;'></form>";
        $(form).submit();
    }
    return false; });

Comment: "It does not work" questions are difficult. How does it not work? What errors do you get? What does it do in IE8? Do you have any idea which of those lines IE breaks on, if it is showing you a script error.
Comment: Your quotes are mixed up. You say it works in chrome, so maybe a copy/paste error? Also jQuery 1.4 allows you to break up element creation with attributes like this - `$("", { "method" : "post", action: "...", style: ".." })`. It is a much cleaner way compared to the quote-soup.
Answer: IE does not submit disabled elements in a form, so maybe it's the same with empty forms.
It's not exactly a solution, but I would do that without creating a form. You can just use $.ajax or $.post and build the required URL with Url.Action(...), then call document.reload().
Comment: This is how I would do it. Easier to debug and manage with `$.post`
Comment: *"IE does not submit disabled elements in a form..."* No browser submits disabled elements in a form -- at least, not if they want to follow the specification, which says not to: http://www.w3.org/TR/html5/forms.html#form-submission-algorithm (that's a link to the HTML5 spec, but this is old, old behavior)
Answer: Aren't you supposed to append the form to body before you can submit it? Not sure how it works in Chrome without that, but try doing something like this-
$('<form/>', {
    action: "...",
    method: "...",
    style: "...",
})
.appendTo("body")
.submit();

jQuery .submit() woes with IE8


Alterar paginas padrão criadas por MVC no Visual Studio C#

Question: Quando crio o controller e uso MVC 5 Controller with views, using Entity Framework, as paginas de Index, Create, Edit, Delete e Details são criadas automaticamente com uma configuração padrão, e tenho que incluir uma class nova para alterar o css dos botões.
Gostaria de saber se existe alguma forma para que estas paginas sempre utilizem um modo personalizado.
Comment: Esse link vai te ajudar: https://www.c-sharpcorner.com/UploadFile/4fcb5a/step-by-step-implementing-t4-custom-templates-in-mvc5-projec/
Comment: Perfeito, era exatamente isto que eu procurava. Obrigado.
Answer:
Gostaria de saber se existe alguma forma para que estas paginas sempre
  utilizem um modo personalizado.

Sim, existe. Você pode usar para isso o T4 Templates do Visual Studio para personalizar a geração automática das Views de um projeto específico.
O caminho com esses templates podem mudar de acordo com a versão do Visual Studio:
{VS_PATH}\Common7\IDE\Extensions\Microsoft\Web\Mvc\Scaffolding\Templates
Leia esse conteúdo para um passo-a-passo detalhado de como personalizar os templates para um projeto MVC5.
Segue abaixo um resumo dos passos:

Criar um pasta no seu projeto com o nome 'CodeTemplate' e copie para ela todo conteúdo da pasta Templates passada acima.
Efetue o Build da solution.
Localize no conteúdo copiado (arquivos cs.t4) os trechos que deseja personalizar. Obs.: os nomes das pastas indicam a geração que está sendo alterada


How to make the back function and set the last contentView

Question: I hawe many view's in my application and now the problem is how to go back from one view to another.
What I could do it by set back Buttons in every view but i would like to use the android back hard button.
I have tried something like this:
public boolean onKeyDown(int keyCode, KeyEvent event)
{
  if(keyCode==KeyEvent.KEYCODE_BACK)
          {
      finish();
          }
return false;
}

But the problem is that this will close my application.
Could you please guide me for a  proper solution, for example to memorize the last view was set and then to come back to this view or something like this.
Here is the code with which I am changing the view (it's a method in my main activity):
public void CheckIfUserIsLogedIn ()
{
    int userPresence = localDatabase.CheckUserPresence();
    if (userPresence == 0)
    {
        setContentView(R.layout.main);
    }
    else
    {
        setContentView(R.layout.userlogedon);
    }
}

Thank you.
Comment: Means you want show previous view on back button?
Comment: Are you finishing the current activity while moving to next activity ? Please put the code with which you are starting the new or next activity.
Comment: I edited my question @iDroid Explorer
Answer: Look!
You are doing this wrong way..
An Activity class should only have on content View. (because it is recommended way and easy to use and implement).
And if you want to go to next View, show it under another separate Activity.
when you will finish it, you will be automatically redirected to previous Activity.
(and you don't need to memorize the Previous View :) )
See here, how to work with Activity Stacks.
Comment: Thank you for your answer @Adil, Ok so if I understand, I have to use a different class for every View i have?
Comment: @Ana: Yes. If you want to show say a Login view the you should have a `LoginActivity` which will show your `R.layout.userlogedon` as content view. Happy coding! Cheers! :)
Comment: @Ana: Yes. You should have to use the different activity for all respective View.
Answer: I am not sure to understand your problem correctly because Android do all that for you automatically. Once a view is opened when you switch to another view it is paused (on screen but has not focus) or stopped (has no focus)
http://developer.android.com/reference/android/app/Activity.html
If the current view (activity) has been launched by the previous view (activity), pressing the back button will make you "close" the current view and go back to the previous one automatically.
Now two things :

Perhaps your are simply opening all views wihtin the same activity by showing on or off components which is a bad way of doing and is not recommended by android. What you should do is 1 view = 1 activity.
You are thinking like "iPhone/iPad" where you have to implements back buttons in the "views". In android you don't need to do so. Putting the "finish" command in your code at that point seem to close the application which make me think you have programmed as explained in point 1.

Hope it helps
EDIT:
To start a new activity do it like this
startActivity(new Intent(this, MyOtherActivity.class));

you put this in your code where you want to load the new view (activity)
Now if you want to transfer some information between activities you must do something like this :
Intent myIntent; //intent declaration

int aNumber = 10; // info to send to other activity
String aString = "abcd"; // info to send to other activity

// link Intent to the other activity
myIntent = new Intent(view.getContext(), MyOtherActivity.class)

//put the extra info
myIntent.putExtra("myNumber", aNumber);
myIntent.putExtra("myString", aString);

//start the new view/activity
startActivity(myIntent);

and in the new opened activity you retrieve the infos like this (in the oncreate usually)
int aNumber;
String aString;

@Override
public void onCreate(Bundle savedInstanceState) {
    aNumber= getIntent().getExtras().getInt("myNumber");
    aString= getIntent().getExtras().getString("myString");
}

Comment: Thank you @HpTeam, yes, you're right, I have one activity for all my views. I will try to change this.
Answer: Actually i m not sure that understand exactly but..
take a map or a shared preference and at the back button set last View on map or Shared preference .
At the calling or at start activity fetch the data which have stored you.
this will helps you.


Como verificar em C se o ficheiro está vazio?

Question: Boa noite,
Estou a trabalhar com C, e acontece que tenho uma função ou método que tem de imprimir para um ficheiro os dados, as marcações de refeição,respeitantes a alunos que marcaram refeição no sistema.
No metodo o sistema têm de verificar se esse ficheiro está vazio e se estiver vazio simplesmente imprime para o ficheiro fprintf(filetmp, "%d %s %s %s \n", num, nome, subnome, meal);
Se o ficheiro já tiver por exemplo 2 refeicoes marcadas pelos alunos, o sistema tem que as ler e imprimir também para filetmp
Acontece que já tentei comparar o ficheiro verificando se o mesmo está vazio, ou se tem alguma refeicao, verifiquei e consultei a internet para tal e apesar de existir, segundo sei uma funcao ftell(file) que permite determinar segundo me pareceu se o ficheiro esta vazio ou nao eu nao estou a conseguir de nenhuma maneira testar se o ficheiro tem ou nao alguma refeicao.
Tentei tambem o feof(file) mas acontece que simplesmente fico sem o ficheiro. Como será que posso alterar o código para ele verificar se o ficheiro está vazio, e para verificar se o ficheiro tem alguma refeicao.
void PrintMealToFIle(int num, char nome[100], char subnome[250])
    {
        size_t size;
        int i=0, j=0;
        struct Food f;
        struct CantinaAlunoFood aluno;
        const char *filename = "db-cantinameals.txt";
        FILE *file, *filetmp;
        filetmp = fopen("cantinatmp.txt", "w");
        file = fopen(filename, "r");
        size = ftell(file);
        fseek(file, 0, SEEK_END);
        //size = ftell(file);
        while (!(feof(file)))
        {

            if (ftell(file)==0)//se esta vazio
                //fseek(file, 0, SEEK_END);
                //size = ftell(file);

                fprintf(filetmp, "%d %s %s %s \n", num, nome, subnome, meal);

            if (ftell(file)!=0)
            {
                fscanf(file, "%d %s %s %s ", &aluno.id, aluno.name, aluno.subname, aluno.refeicao);
                fprintf(filetmp, "%d %s %s %s \n", num, nome, subnome, meal);
                fclose(filetmp);
                fclose(file);

                if (remove(filename) == 0)
                {
                    printf("\n");
                    printf("Ficheiro removido com sucesso\n");
                }

                else
                    perror("Problema a remover ficheiro ");

                if (rename("cantinatmp.txt", filename) == 0)
                {
                    printf("\n");
                    printf("Ficheiro bem renomeado");
                }

                else
                    perror("Problema ");

            }

        }

    }

Comment: Não vou nem tentar analisar o código porque ele parece estar em estado semi acabado mas o caminho que você está tentando parece correto. Acho que você precisaria detalhar mais o problema ou produzir um código mais fácil de analisar o problema. http://pt.stackoverflow.com/help/mcve Fazer `fseek(file, 0, SEEK_END); if(ftell(file) == 0)` certamente funciona.
Comment: `fopen(..., "a")` ... abrir o ficheiro em mode *"append"* acrescenta o que se escrever no fim do que já lá existe.
Answer: Você pode verificar qual o tamanho do arquivo e então verificar se está vazio.
int get_size(const char* file_name)
{
    FILE *file = fopen(file_name, "r");

    if(file == NULL)
        return 0;

    fseek(file, 0, SEEK_END);
    int size = ftell(file);
    fclose(file);

    return size;
}

Exemplo, verificando se o arquivo teste.txt está vazio:
if(get_size("teste.txt") == 0)
{
    printf("O arquivo esta vazio.");
}
else
{
    printf("O arquivo nao esta vazio.");
}

Comment: O segundo `fseek` é desnecessário.
Comment: Realmente, removi.
Answer: Você pode fazer um sistema de repetição básica para verificar se há algo existente no arquivo
int main(){

   char Arquivo(Array);    //Variáveis
   int i=0;

   FILE *Abrir;   //Abrir e ler o arquivo
   Abrir=fopen(Arquivo,"rt");

      fscanf(Abrir,%c,&Arquivo(i));

      if (Arquivo(i) == Null){ // Condição Se
         printf("Arquivo Vazio");
      } else {printf("Arquivo com dados");}
      break;

   printf("A partir daqui vc resolve o que fazer");

   fclose(Abrir);   //fechando ponteiro
   return 0;
}

Comment: Aquele `break` dentro do seu loop não vai dar muito certo, não testei mas só de 'bater o olho' dá pra ver que o loop será rodado uma única vez.
Comment: Esse código tem outros erros.
Comment: Não acho que este código compile do jeito que está.


Create a field linked to a vocabulary with Drush

Question: Let's say I have created a taxonomy vocabulary called ABC.
For this vocabulary ABC, i want to create many fields using Drush.
I've tried
drush field-create ABC myfield,text,text_textfield

It works, doesn't give any error, but if I go to the admin panel, I click on structure => taxonomy then in the list I see ABC, I click on "Edit" then I click on the tab "Manage fields" where I expect to see my field. Because (correct me if I'm wrong) I think that the drush command line field-create ABC myfield should have added it. But no.
It's not there. But if I click on the combo of the "Add existing field" option, in the list, there's the myfield that I've just created!
It seems there "link" between ABC and myfield is not created. myfield is  created, but it's not "included" in the ABC fields.
Am I doing something wrong, or missing something?
Answer: You are missing Entity type. See the documentation from drush

Create fields and instances. Returns urls for field editing.
Examples:  drush field-create article                Define new
  article fields via interactive prompts.                        open
  drush field-create article         Define new article fields and
  then open field edit form for refinement.   drush field-create article
  Create two new fields.
  city,text,text_textfield
  subtitle,text,text_textfield
Arguments:  bundle                                    Content type
  (for nodes). Name of bundle to attach fields to. Required.
  field_spec                                Comma delimited triple in
  the form: field_name,field_type,widget_name. If widget_name is
  omitted, the default widget
                                             will be used. Separate multiple fields by space. If omitted, a wizard will prompt you.
Options:  --entity_type                             Type of entity
  (e.g. node, user, comment). Defaults to node.

As you can see the entity type defaults to node . So you have to specify the entity type as taxonomy_term.

drush field-create ABC myfield,text,text_textfield --entity_type=taxonomy_term
Comment: Do you know how to get a list of all availaible `entity_type`?
Comment: entity_get_info($entity_type = NULL) can do it.


Why i will get StaticInjectorError in angular 6. what it means

Question: My Routing Structure
App-> main -> dashboard
I'm trying to implement this in dashboard.component.ts but it's showing error below I didn't understand why
Can anyone help me out to get this done?

core.js:1624 ERROR Error: Uncaught (in promise): Error: StaticInjectorError(AppModule)[DashboardComponent -> FileUploader]:
    StaticInjectorError(Platform: core)[DashboardComponent -> FileUploader]:
      NullInjectorError: No provider for FileUploader!
  Error: StaticInjectorError(AppModule)[DashboardComponent -> FileUploader]:
    StaticInjectorError(Platform: core)[DashboardComponent -> FileUploader]:
      NullInjectorError: No provider for FileUploader!
      at NullInjector.push../node_modules/@angular/core/fesm5/core.js.NullInjector.get (core.js:1034)
      at resolveToken (core.js:1273)
      at tryResolveToken (core.js:1218)
      at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (core.js:1113)
      at resolveToken (core.js:1273)
      at tryResolveToken (core.js:1218)
      at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (core.js:1113)
      at resolveNgModuleDep (core.js:8168)
      at NgModuleRef_.push../node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get (core.js:8856)
      at resolveDep (core.js:9221)
      at NullInjector.push../node_modules/@angular/core/fesm5/core.js.NullInjector.get (core.js:1034)
      at resolveToken (core.js:1273)
      at tryResolveToken (core.js:1218)
      at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (core.js:1113)
      at resolveToken (core.js:1273)
      at tryResolveToken (core.js:1218)
      at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (core.js:1113)
      at resolveNgModuleDep (core.js:8168)
      at NgModuleRef_.push../node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get (core.js:8856)
      at resolveDep (core.js:9221)
      at resolvePromise (zone.js:814)
      at resolvePromise (zone.js:771)
      at zone.js:873
      at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:421)
      at Object.onInvokeTask (core.js:3748)
      at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:420)
      at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:188)
      at drainMicroTaskQueue (zone.js:595)
      at ZoneTask.push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask [as invoke] (zone.js:500)
      at invokeTask (zone.js:1540)```

Thanks
Surya Teja.K
Comment: post your code here app.module.ts
Comment: https://angular.io/guide/dependency-injection
Answer: FileUploader service has to be provided - add it to providers list of your AppModule.
If you don't do that, Angular would not know how to inject an instance of it in your component, and hence, it complains with NullInjectorError


VBA Macro timer as a function() instead of a sub() - losing the first variable

Question: I'm attempting to clean up some recorded macros, and would like to test if my optimizations are actually speeding this up.  I want to add a macro timer to test, but ideally I'd add it as a set of two public function()s, rather than inside the code.
THe problem arises when the code fails to recall the time1 variable. I assume that there's a way to get the first time as a constant, but I'm not sure how
when I attempt to change the "dim timer1" to "const timer1" I get an error that I've been unable to resolve.  Am I going about this the wrong way?  Do I need to abandon the idea of having this as functions?
<code> Sub timertestSub()

    Dim time1 As Double
    Dim time2 As Double
    Dim totaltime As String

    time1 = Timer()

    Application.Wait Now + TimeValue("00:00:10")

    time2 = Timer()

    totaltime = Format((time2 - time1) / 86400, "hh:mm:ss")

    MsgBox "code ran in " & totaltime
    End Sub

Function startTime()

    Dim time1 As Double

    time1 = Timer()

    Debug.Print "time1 is: " & time1

    End Function

Function endTIme()

    Dim time2 As Double
    Dim totaltime As Double

    'confirm orig variable
    Debug.Print "time1 recalled as: " & time1

    time2 = Timer()
    Debug.Print "time2 is: " & time2

    totaltime = (time2 - time1)
    Debug.Print "TotalTime is: " & totaltime

    MsgBox "code ran in " & Format(totaltime / 86400, "hh:mm:ss")

    End Function

Sub timertestFunction()

    Call startTime

    Application.Wait Now + TimeValue("00:00:10")

    Call endTIme

    End Sub
</code>
the sub timertestSub() works as expected, but the sub timertestFunction() loses the time1 variable; so the final output is just the current time
Trying to chance the code from dim timer1 as double to const timer1 as double is also giving me errors.
Comment: Define it as a `Static` variable.
Comment: You are not passing anything to, or returning anything from your functions.
Comment: that's a great idea, it's giving the same results though.  Like the static variable is also being forgotten by the end of the first function
Comment: I just ran your code and had no issues - however "Trying to chance the code from `dim timer1 as double` to `const timer1 as double`" implies a spelling error in your original code (not the code presented here) which `Option Explicit` at the top of the module will bring to the surface.
Comment: @chrisneilsen can you explain a little more what you mean by that?
Comment: @AJD when you ran the sub timertestFunction() you got 10 seconds?  not the current time?  Because every time I run it, I'm only getting the current time, or basically timer2 - null  Re: option explicit, I actually turned that off because it seemed to be preventing the sub timertestfunction() from correctly identifying timer1; I presume for the same reason that it runs as empty; I'm just not sure what the workaround is
Comment: I actually got 9 seconds, but that might have been due to a rounding error. But yes, the result was elapsed time, not current time. So the code you are running must be different from the code you presented here.
Comment: just to be clear, there are two subs in the code above; the first sub runs as expected, and is really there for me to test my assumptions about the two functions; and the second sub is an attempt to run the two functions.
Answer: I was finally able to run the code by simply moving the "dim time1 as double" ABOVE all the functions as "public time1 as double"  which allowed the function endtime to reference it; and also resolved the option explicit error.  in the end it wasn't that the time1 value was being lost, it was that because it was not a public variable, it couldn't be referenced properly by the other functions/subs
<code>public time1 as double

Function startTime()

    time1 = Timer()

    Debug.Print "time1 is: " & time1

    End Function

Function endTIme()

    Dim time2 As Double
    Dim totaltime As Double

    'confirm orig variable
    Debug.Print "time1 recalled as: " & time1

    time2 = Timer()
    Debug.Print "time2 is: " & time2

    totaltime = (time2 - time1)
    Debug.Print "TotalTime is: " & totaltime

    MsgBox "code ran in " & Format(totaltime / 86400, "hh:mm:ss")

    End Function

Sub timertestFunction()

    Call startTime

    Application.Wait Now + TimeValue("00:00:10")

    Call endTIme

    End Sub
</code>


How can I get the last n characters of the selected text from a contextMenu?

Question: I am writing a chrome extension that shows a contextMenu when there is a selection, which was pretty straight forward:
var item = chrome.contextMenus.create({
   "title": "myTitle",
   "contexts": ["selection"],
   "id": "myItem"
});

Now, I want to create a submenu item for that one, but based on the selected text. I found I was able to do this by adding the callback when it loads, and display the selected text as a submenu item like this:
var item = chrome.contextMenus.create({
   "title": "myTitle",
   "contexts": ["selection"],
   "id": "myItem"
}, function() {
   // Create item with the selected text
   var subItem = chrome.contextMenus.create({
      "title": "%s",
      "contexts": ["selection"],
      "parentId": "myItem",
      "id": "mySubItem"
   });
});

This is working, however I want to do something based on the last two characters of the selected string, but I can't. By adding something inside the function like this:
var selection = "%s";
if(selection.splice(-2) == "ab") { }
var subItem...

It doesn't work, because selection.splice(-2) returns the selected string. It does that, because it's doing "%s".splice(-2) which is just "%s" so it's never actually operating on the selected text. I have verified this because selection.splice(-1) returns "s", it does not return the last character of what was selected.
How can I work with the selected text here?
Answer: It's going to be difficult.
'%s' only has a specific special meaning when assigned to that property of a context menu. It's obviously not known at the time of creation of the context menu item (nothing is selected yet), so you can't manipulate it.
Chrome is not flexible in terms of text it shows in context menus, as there is no event like onBeforeShowMenu to manipulate that text or a way to specify a function that would return the label for the entry. That is, unless you try and race Chrome on that by updating the context menu when a selection is made.
This is quite complex to do however. This answer shows a potential way to do it.
Answer: Have you tried using pure JavaScript api? window.getSelection
var selectionText = window.getSelection().toString();
console.log(selectionText.slice(-2));

BTW, I think you should you slice(-2) or substring(selectionText.length - 2), since splice(-2) will change the original array.
Comment: I did try that but it didn't seem to work here, I'm not sure why but I was getting 'undefined'.


How to merge 2 date fields

Question: I am working on a D8 instance and i would like to have 2 dates which are in different fields to be displayed at once when the month is the same i.e. :
21-22 december instead of 21 december 22 december.
What is the best way to do that ?
Comment: When/where are you trying to do this? In the node view itself, when saving the node, or somewhere else?
Answer: This isn't a direct answer to your question, but is probably the best option to move forward.
Drupal 8.2.0 (due 2016/10/05) will include the new datetime_range module, which provides date ranges in a single field.
I would wait until this is available, and then migrate your two datetime fields into a single daterange fields (one to the start value and the other to the end value).
Then, I would make a custom formatter for daterange fields that implements your logic to combine month/year when they are the same for start and end.
You can then configure your various vide modes to use this new formatter.
Answer: Add a hook_preprocess_node function to your theme to check if both dates are in the same month. If yes then the function should hide one date and alter the display of the other to display the range.
Here is an example of it.
Alternatively, for views you can use pre_render to alter fields conditionally.

How to merge 2 date fields


How are p-values computed from t-values when doing regressions?

Question: I'm performing a regression analysis using the statsmodels module in Python. The regression gives both t-values and p-values for each coefficient, but I'd like to understand exactly which test is applied under the hood and how the p-values are computed.
I followed this Stack Overflow answer to compute the p-values from t-values and degrees of freedom, but I'm getting different results from the values returned by statsmodels. Why is this, and which test is employed "inside" statsmodels?
EDIT: Tried the same thing with a z-test. This gives accurate results in most cases, but still doesn't consistently yield the same results.
Minimal example in Python 3 to reproduce:
from sklearn import datasets
import statsmodels.api as sm
from scipy import stats

# Load data
data = datasets.load_iris()
X = data.data
X = sm.add_constant(X)
y = data.target

# Fit the logistic regression
est = sm.OLS(y, X)
res = est.fit()

df = res.df_model  # degrees of freedom

for t, p in zip(res.tvalues, res.pvalues):
    # Print t- and p-values returned by statsmodels
    print("Fit t-value=%.2g" % t)
    print("Fit p-value=%.2g" % p)

    # Compute p-value from the returned t-values
    p_manual = stats.t.sf(t, df=df)
    print("t-test Calculated p-value=%.2g" % p_manual)

    # Manually do a (two-tailed) z-test
    pz = stats.norm.sf(abs(t))*2
    print("z-test Calculated p-value=%.2g" % pz)

    print()

This prints the following:
Fit t-value=0.94
Fit p-value=0.35
t-test Calculated p-value=0.2
z-test Calculated p-value=0.35

Fit t-value=-1.9
Fit p-value=0.059
t-test Calculated p-value=0.93
z-test Calculated p-value=0.057

Fit t-value=-0.74
Fit p-value=0.46
t-test Calculated p-value=0.75
z-test Calculated p-value=0.46

Fit t-value=4
Fit p-value=0.00011
t-test Calculated p-value=0.0082
z-test Calculated p-value=6.8e-05

Fit t-value=6.5
Fit p-value=1.5e-09
t-test Calculated p-value=0.0015
z-test Calculated p-value=1.1e-10

Comment: You're not doing the calculations correctly--and your calculations do not match those of the SO post you reference: notice the absolute value and the multiplication by two.  Study the difference between a two-tailed test and one-tailed test, then read the manual from that perspective.
Comment: I don't know about Python but in R logistic regression uses a z-test.
Comment: I tried doing a z-test as well and for most of the coefficients I now get the same p-values as those returned by statsmodels. However, very small p-values seem to be off still.
Answer: So, the two mistakes I made were 1) Making a one-tailed, rather than two-tailed t-test, and 2) using the number of degrees of freedom in the model (5). With 150 data points and 5 model parameters, the correct number is instead 145. The code below correctly computes the same p-values as the ones given by statsmodels.
The reason the Z-test appeared to give correct results for some parameters is that the t-distribution is very close to the normal distribution for large df's, but as the t-distribution is wider than the normal, the difference grows for larger values of t, consistent with z- and t-tests giving very different results only for the last two parameters above.
from sklearn import datasets
import statsmodels.api as sm
from scipy import stats

# Load data
data = datasets.load_iris()
X = data.data
X = sm.add_constant(X)
y = data.target

# Fit the logistic regression
est = sm.OLS(y, X)
res = est.fit()

n_datapoints = X.shape[0]
dim = X.shape[1]
df = n_datapoints - dim

for t, p in zip(res.tvalues, res.pvalues):
    # Print t- and p-values returned by statsmodels
    print("Fit t-value=%.2g" % t)
    print("Fit p-value=%.10g" % p)

    # Compute p-value from the returned t-values
    p_manual = stats.t.sf(abs(t), df=res.df_resid)*2
    print("t-test Calculated p-value=%.10g" % p_manual)

    print()


How to check if a password for an ssh key has been set with only the public key?

Question: We have some SFTP-Chroot Environments where we only allow 4096bit RSA Keys for authentication and we only have the public key part from our users. But we have a policy that the user has to set a password for their private key parts.
Is there a way to check if thats true (that theyve really set a password) only by owning the public key part or maybe by setting something in openssh-server config?
Answer: You can't (with only the public key). The user may change or remove the password for the private key without affecting the server.
There is a similar question: How to tell if a public SSH key has a passphrase
If you are implementing two-factor authentication, maybe you could consider PAM or a custom script. Making it work with some SFTP clients may be a pain though.
Comment: thank you for your answer. i already thought that its not possible but was unsure. thanks for ensure.


Ideal solution for firebase google provider login overriding other sign-in providers

Question: I've been playing around with firebase multi-provider logins. I enabled both email and google.
I've read somewhere that if the email is not yet verified and a user tries to login using google then the user account will be overridden albeit with the same user id.
The reason for this is gmail is a trusted provider and Firebase unlinks the previous unverified email and overrides the data with google user data.
Based from what i've read from this comment, this is a security feature of Firebase and expected behavior.
My question is how do i handle such scenario when a user has been using his account with email and password and all of a sudden if a user logged in using gmail then he'll no longer be able to login using email and password.
Yes, the user can just simply login using google login and is still the same user account and simply was overridden by google but some users may think this is a bug and not a good user experience.
Answer: I had the same problem and I have a solution that might work for you.
I am using Firebase Authentication for my Android app written in Kotlin. I am not sure what platform and language you are using, but if you are able to transfer the logic, the solution should work for you as well.
For android, you use GoogleSignIn.getSignedInAccountFromIntent(data) to authenticate the Google account. Here data is an object of type Intent that has all the required data needed for authentication.
I was able to get the user email from the data and if the same email was previously used to login to the app I deny the login and display an appropriate message.
Following is the line of code I have used to get the user's email.
val googleUser: GoogleSignInAccount = data!!.getParcelableExtra("googleSignInAccount")!!

I hope this points you in the right direction and sorry if the solution is not in the language you were looking for.
Comment: Thanks for your answer. I'm playing around with it in a web app and using javascript. I'm not sure if there's a equivalent method for getting that method. Maybe this is method is somewhat similar `fetchSignInMethodsForEmail`.
Just one clarification, in your approach does it mean you prevent the google authentication if there's already an account with the same email address?
Comment: Yes, the method I have written in my answer does prevent the google authentication if there's already an account with the same email address. `fetchSignInMethodsForEmail` will return sign-in providers for an email. I had to use data intent to get the email that was being used to sign in with Google and pass it to `fetchSigInMethodsForEmail`. You just need to figure ou a way to get the email being used to sign-in with Google. Hope this helps.
Answer: You can use a blocking function to prevent this and show an error to the user to verify their email.
Code example here: https://stackoverflow.com/a/78149428/5651481


Absolutely continuous and differentiation

Question: Let $F$ is absolutely continuous on any closed and bounded interval $[a,b]$ and integrable on $\mathbb R$, and that its derivative $F'$ is also integrable on $\mathbb R$.
I couldn't show why $\displaystyle \lim_{x \to +\infty} F(x)=0$. Any hints please?
Comment: Welcome to MSE! It really helps to format your questions using MahtJax (see FAQ). It might also help to describe your thoughts and what you have tried yourself. Regards
Answer: If $\lim_{x\to +\infty} F(x)$ does not exist, then we can find $\epsilon>0$ and an unbounded increasing sequence $x_k\to+\infty$ such that $|F(x_{k+1})-F(x_k)|\ge\epsilon$ for each $k$. Therefore,
$$\int_{\mathbb R}|F'|\ge \sum_{k=1}^\infty \int_{x_k}^{x_{k+1}}|F'|\ge \sum_{k=1}^\infty\epsilon =\infty$$
a contradiction. Thus, $\lim_{x\to +\infty} F(x)$ exists. If it's a nonzero number, $F$ itself is not integrable on $\mathbb R$: see the answer by Abel.
Answer: You could try using a Cauchy argument. Can you show that $|F(x) - F(y)| \to 0$ as $x,y \to \infty$?
Answer: First note that $\displaystyle\lim_{x\to\infty}F(x)-F(0) = \lim_{x\to\infty}\int_0^x F^\prime(y)\,\mathrm{d}y = \int_0^\infty F^\prime(y)\,\mathrm{d}y\in\mathbb{R}$.
Lets write $\displaystyle\lim_{x\to\infty} F(x) = F(0)+\int_0^\infty F^\prime(y)\,\mathrm{d}y := c$ and suppose $c\neq 0$. Assume without loss of generality that $c>0$ (otherwise we regard $-F$).
By definition of the limit there is an $N\in\mathbb{R}$ such that $F(x)>\frac{c}{2}$ for all $x>N$. Now $\displaystyle\int_N^\infty F(y)\,\mathrm{d}y > \int_0^\infty c\,\mathrm{d}y = \infty$. Contradiction!
Thus our assumption was false and $\displaystyle c=\lim_{x\to\infty} F(x) = 0$.
Comment: "suppose $c\ne 0$": you haven't shown that $c$ (the limit) exists.


Inconsistent behavior with user_logout function

Question: For a drupal 8 site, I have a custom function that does the following:
It logs out the user and sends them to an external url
Inside the controller CustomController, I have:
function custom_logout(){
 if (\Drupal::currentUser()->isAuthenticated()) {
    user_logout();
    return new TrustedRedirectResponse('https://example.com');
 }
}

In the routing.yml
customl.clogout:
  path: '/customlogout'
  defaults:
    _controller: '\Drupal\user\Controller\CustomController::custom_logout'
  requirements:
    _user_is_logged_in: 'TRUE'

When I visit the /customlogout for the first time it logs me out of Drupal and redirects me to example.com. If I revisit my site and login in again, and repeat the process it still redirects me to example.com but when I check my site I am still logged in. I am wondering why this happens? I can still logout using /user/logout though
Thank you
Comment: How exactly do you call this function, what function actually, and from where? An event subscriber? Can you please update your question for clarification?
Comment: Thank you, I have updated the question
Comment: I assume that this issue is caused by this line return new TrustedRedirectResponse('https://example.com'). Do we have any alternative that guarantees logout
Answer: As it turns out,
return new TrustedRedirectResponse('https://example.com');
was the culprit here.
TrustedRedirectResponse extends CacheableSecuredRedirectResponse, as a result the function was cached, and user_logout was not called even when I visited the  /customlogout
The workaround for this is adding the following lines in your routing.yml
options:

  no_cache: TRUE


difference between groupid and consumerid in Kafka consumer

Question: I noticed that the Consumer configuration has two IDs. One is group.id (mandatory) and second one is consumer.id (not Mandatory).
What is the difference between these 2 IDs?
Comment: Based on the consumer groups, we can determine the messaging model of the consumer:
**
If all consumer instances have the same consumer group, then this works just like a traditional queue balancing load over the consumers.

If all consumer instances have different consumer groups, then this works like a publish-subscribe and all messages are broadcast to all the consumers.** . as per above statement, to act as  publish-subscribe  all consumer group should be unique name. then why cant be consumer id. why consumer group id?. what does group means
Answer: Consumers groups is a Kafka abstraction that enables supporting both point-to-point and publish/subscribe messaging. A consumer can join a consumer group (let us say group_1) by setting its group.id to group_1. Consumer groups is also a way of supporting parallel consumption of the data i.e. different consumers of the same consumer group consume data in parallel from different partitions.
In addition to group.id, each consumer also identifies itself to the Kafka broker using consumer.id. This is used by Kafka to identify the currently ACTIVE consumers of a particular consumer group.
Read this documentation for more details.
Comment: Reading the documentation, for `consumer.id`, description states "Generated automatically if not set." I assume this probably means if manually set, consumer.id should be unique for each consumer? Curious to wonder what happens if you reuse the consumer ID across consumers (like how one shares the consumer group ID) - problems arise or it will work fine but just messy for tracking/debugging active consumers in the group?
Comment: if you haven't partitioned the topic, then only 1 consumer is going to consume messages. if you want both consumers (belonging to the same consumer group) consume messages in parallel then you need to partition your topic. I'd recommend you read the documentation
Comment: Please give more example to understand. what is **different consumers of the same consumer group consume data in parallel from different partitions.**. How to add different consumer in same consumer group ? I ran Java Consumer program with group.id=group1. it consumed message. I ran same program without changing goup.id. first program consume message. second consumer couldn't consume message. what does group means here ?
Comment: Thanks for additional information. I have created one Topic demo with 3 partition in one broker. I ran the program with demo-group, it is consuming message. I ran again program with same group id. but, Second program couldn't consume message. if change the group id name to demo-group1. it works good. please tell me the consumer group concept.
Comment: I read tutorial. I need to understand how to create consumer group that has more consumer using java API. I am using java simple consumer API. Please help me on that.
Comment: @David That might be worth creating a new post for
Comment: There is no `consumer.id` in the documentation. Has it been replaced by `client_id`? but then it is same for every consumer by default.
Answer: The figure below describes the difference between group.id and consumer.id really well.

In this example, we have one topic with four partitions, one consumer group and three consumers inside the consumer group. Consumer 0 and consumer 2 read from one partition each, whereas consumer 1 reads from two partitions.
The group.id is equal to Consumer group. Your group.id always represents a unique name/ID of your consumer group across your Kafka cluster. A consumer group can have one or multiple consumers, but only as many consumers as partitions are available in the topic.
Here we have four partitions and three consumers joined the consumer group: Consumer 0, Consumer 1 and Consumer 2. Each ID (or name) of a consumer represents the consumer.id. We can have a maximum of four consumers (i.e. consumer.ids) because the topic has four partitions.
Each consumer has a unique consumer.id across its consumer group. If you don't define a consumer.id, the Kafka client (Java, Python, Node.js, etc) usually chooses a random ID.
Another good example to understand the relationship between group.id and consumer.id is the following figure:

Topic T1 has four partitions, and two consumer groups exist, group 1 and group 2. Group 1 holds four consumers (maxed out), while group 2 holds two consumers (space for 2 more consumers). Both consumers in group 2 read from two partitions each. In group 1, each consumer just reads from one partition.
This is a good example showcasing why we cannot have two or more consumer groups (group.ids) with the same name. If Kafka allows groups to have the same name, the offset tracking for a partition would get out of whack because a consumer in group 1 would overwrite the offset of a consumer in group 2 (and vice versa).
Comment: In your last example, is "Consumer X" the consumer id? Does that mean that in that picture the group 2 has 2 consumers which have the same consumer.id of the consumers of group 1?
Answer: group.id
specifies the name of the consumer group a Kafka consumer belongs to.
When the Kafka consumer is constructed and group.id does not exist yet (i.e. there are no existing consumers that are part of the group), the consumer group will be created automatically.
A unique string that identifies the consumer group this consumer belongs to. This property is required if the consumer uses either the group management functionality by using subscribe(topic) or the Kafka-based offset management strategy.
Type:   string
Default:    null
Valid Values:
Importance: high
Consumer id
Each consumer has a unique consumer.id across its consumer group. If you don't define a consumer.id, the Kafka client (Java, Python, Node.js, etc) usually chooses a random ID.


How to run Psiphon from CMD command line (for curl only)?

Question: How to run Psiphon from command line (to connect to a proxy server) and make it be applied to curl only (keeping other programs' connections un-proxy-ed)?

Purpose:
I'm using a script (written in perl) that uses curl by calling CMD command lines to perform web requests. I am looking for using Psiphon also via CMD command line, this way the script could call CMD command lines to connect to a server and use curl through Psiphon proxy.
Note:
I need Psiphon proxy to be working for curl only, keeping my other programs' connections normal as is.
My attempt for solution:
I've noticed that Psiphon uses an executable psiphon-tunnel-core.exe. I tried to run this executable file from CMD it tells me {"data":{"data":{"message":"configuration file is required"},"noticeType":"Error","showUser":false,"timestamp":"2018-03-11T21:24:27.441Z"}
Answer: I just like to add something from above. Since you need Psiphon proxy to be working for curl only, the easiest way is start Psiphon3 main application (whichever command you want), then use proxifier/proxycap/freecap/widecap...to control which application uses your local proxy, or just use curl' --proxy flag (i.e. --proxy 127.0.0.1:8080). Be sure you followed the SkipProxySettings registry instructions here: https://psiphon.ca/en/faq.html
For the cmd query, in https://github.com/Psiphon-Labs/psiphon-tunnel-core, there's a simple script to run the consoleclient (psiphon-tunnel-core). Try placing the "consoleclient" in the Psiphon3 "Roaming" folder and run it from there. Be sure that your http proxy port is the same as in the config file. Configuration infos are found here in case you need it: https://godoc.org/github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon#Config. The rest is all up to the user, but it's not recommended. (And even if this works, you still need to control the proxy for curl "only".)
Answer: Open cmd and type:
psiphon-tunnel-core.exe -help

You should be prompted the following:
Usage of C:\Users\dell\Desktop\test\psiphon-tunnel-core.exe:
  -config string
        configuration input file
  -formatNotices
        emit notices in human-readable format
  -homepages string
        homepages notices output file
  -listenInterface string
        bind local proxies to specified interface
  -notices string
        notices output file (defaults to stderr)
  -rotating string
        rotating notices output file
  -rotatingFileSize int
        rotating notices file size (default 1048576)
  -rotatingSyncFrequency int
        rotating notices file sync frequency (default 100)
  -serverList string
        embedded server entry list input file
  -v    print build information and exit
  -version
        print build information and exit


HAProxy, health checking multiple servers with different host names

Question: I need to load balance between multiple running servers with different host names. I cannot set-up the same virtual host on each one.
Is it possible to have only one listen configuration with multiple server and make the Health Checks  apply the http-send-name-header Host directive? I am using HAProxy 1.5.
I came up with this working haproxy.cfg, as you can see, I had to set a different hostname for each health check as the health check ignores the http-send-name-header Host. I would have preferred to use variables or other methods and keep things more concise.
global
    log 127.0.0.1 local0 notice
    maxconn 2000
    user haproxy
    group haproxy

defaults
    log     global
    mode    http
    option  httplog
    option  dontlognull
    retries 3
    option redispatch
    timeout connect  5000
    timeout client  10000
    timeout server  10000
    stats enable
    stats uri /haproxy?stats
    stats refresh 5s
    balance roundrobin
    option httpclose

listen inbound :80
    option httpchk HEAD / HTTP/1.1\r\n
    server instance1 127.0.0.101 check inter 3000 fall 1 rise 1
    server instance2 127.0.0.102 check inter 3000 fall 1 rise 1

listen instance1 127.0.0.101:80
    option forwardfor
    http-send-name-header Host
    option httpchk HEAD / HTTP/1.1\r\nHost:\ www.example.com
    server www.example.com www.example.com:80 check inter 5000 fall 3 rise 2

listen instance2 127.0.0.102:80
    option forwardfor
    http-send-name-header Host
    option httpchk HEAD / HTTP/1.1\r\nHost:\ www.bing.com
    server www.bing.com www.bing.com:80 check inter 5000 fall 3 rise 2

Answer: defaults
log global
retries 2
timeout connect 3000
timeout server 5000
timeout client 5000

listen any-name-1
bind IP-Address:port
mode tcp or http
option user-check user haproxy_check
balance roundrobin
server hostname IpAddress:port check
server hostname  IpAddress:port check
listen any-name-2
bind IP-Address:port
mode tcp or http
option user-check user haproxy_check
balance roundrobin
server hostname IpAddress:port check
server hostanme  IpAddress:port check

listen any-name-3
bind IP-Address:port
mode tcp or http
option user-check user haproxy_check
balance roundrobin
server hostname IpAddress:port check
server hostname  IpAddress:port check

listen any-name-4
bind IP-Address:port
mode tcp or http
option user-check user haproxy_check
balance roundrobin
server hostname IpAddress:port check
server hostname  IpAddress:port check

listen any-name-5
bind IP-Address:port
mode tcp or http
option user-check user haproxy_check
balance roundrobin
server hostname IpAddress:port check
server hostname  IpAddress:port check

listen haproxyadmin
bind HAproxyServerIP:HaproxyPort
mode http
stats enable
stats uri /haproxy
stats realm Strictly\ Private
stats auth username:password

Answer: Update: In the case you described, you need HTTP/1.1 checks which require the host name hardcoded. Given the documentation of version 1.5, there doesn't seem to be a way to avoid this unless you can afford to drop the http checks (which of course is generally not recommended).
Original answer:
While I am not familiar with the 1.5 changes of haproxy, what I would do in 1.4 (and I'm fairly sure it still applies in 1.5) is the following. Note that the frontend/backend separation is just a personal convenience and you could just use listen.
defaults
    mode http
    option  httplog
    timeout connect  5000
    timeout client  10000
    timeout server  10000

frontend inbound
    bind 127.0.0.1:8000
    default_backend webservers

backend webservers
    option forwardfor
    option httpchk HEAD / HTTP/1.0
    http-send-name-header Host
    server google www.google.com:80 check inter 5000 fall 3 rise 2
    server bing www.bing.com:80 check inter 5000 fall 3 rise 2

And the result:
$ curl -i localhost:8000
HTTP/1.1 301 Moved Permanently
Cache-Control: no-cache
Content-Length: 0
Location: http://www.bing.com/
Server: Microsoft-IIS/8.0
P3P: CP="NON UNI COM NAV STA LOC CURa DEVa PSAa PSDa OUR IND"
Set-Cookie: _HOP=I=1&TS=1399981378; path=/
Edge-control: no-store
X-MSEdge-Ref: Ref A: 26CEE14531BF45EFAC91FAC3D1945EDF Ref B: 42CE8D142D427C30F7851B56F38837A6 Ref C: Tue May 13 04:42:58 2014 PST
Date: Tue, 13 May 2014 11:42:57 GMT

$ curl -i localhost:8000
HTTP/1.1 301 Moved Permanently
Location: http://www.google.com/
Content-Type: text/html; charset=UTF-8
X-Content-Type-Options: nosniff
Date: Tue, 13 May 2014 11:43:00 GMT
Expires: Thu, 12 Jun 2014 11:43:00 GMT
Cache-Control: public, max-age=2592000
Server: sffe
Content-Length: 219
X-XSS-Protection: 1; mode=block
Alternate-Protocol: 80:quic

<meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE>

301 Moved

The document has moved
here.

$

Comment: I cannot drop HTTP/1.1 checks. I will stick with my implementation for now.
Comment: I think that your method would not work as it is not setting the Host header. Without a host header the request will never be reaching the intended web server. You can test this with `example.heroku.com`
Comment: You are right, the httpchk requires the Host header in the heroku example, and there isn't any workaround for it. Dropping the check directive would let the proxy work as intended, but you wouldn't be able to detect in advance a failure.
Comment: that is exactly my problem, ensuring health check to cloud instances that require the correct host headers.


Looking for support

Question: After a long illness and hospitalization, I have resumed the maintenance of the D7 website of a small patient association. Migration to D10 was partially successful. Article content has been transferred, but photos are still missing. Where can I place a call for someone who can help me specifically? The aim is to be back online quickly and then take the time to keep up with the developments of Drupal of recent years.
Sorry if this is not the place for this question.
Answer: Drupal is a software maintained by a diverse community rather than a company with a support telephone number.
All sources of Drupal support are categorized.
You may post a request for paid services in this forum, and stipulate the telephone requirement.

Looking for support