Error handling in PySpark reading in non existent files

Question: I have a massive list of directories and files to potentially read from. However some of them may not actually exist which is not a problem - I would simply ignore any error - using a try method. Is there a way I can allow this in PySpark.
Here is the returned error message:
py4j.protocol.Py4JJavaError: An error occurred while calling z:org.apache.spark.api.python.PythonRDD.collectAndServe.
: org.apache.hadoop.mapred.InvalidInputException: Input path does not exist: file:

I am building the series of files to look at with the following:
scI = sc.textFile(",".join(paths))

where paths is a list of paths to possible files. Now I could check the file system and see if they exist, but is there a more elegent way of doing this?
Answer: The following should work:
for f in file_list:
   Try:
       read_file(f)
   except org.apache.hadoop.mapred.InvalidInputException:
       deal_with_absent_file(f)

Comment: I could do this with the standard os.path.isfile(fname), is there a way that I can handle this within the textFile call?


Problema em imagem SVG. Evento mouseenter(), mousemove() e mouseleave()

Question: Tenho uma imagem SVG com os Estados do País e preciso que, ao passar o mouse sobre um Estado, a imagem com o nome do Estado apareça e siga o mouse.
Já fiz a imagem aparecer e desaparecer com os eventos mouseenter e mouseleave, porém, não consigo fazer ela seguir o mouse dentro do Estado com mousemove.
Segue o código:
$('path.str0').mouseenter(function(){
            var thisClass = $(this).attr('class');
            var pieces = thisClass.split(' ');

            //Estou mexendo aqui. Ewerton Melo
            $('img').filter( '.' + pieces[2]).css("display", "block");
            //Até aqui

            $(this).attr('fill', "#00d4ff");
        }).mousemove(function(e){
            var mousex = e.pageX + 20; //Get X coodrinates
            var mousey = e.pageY + 20; //Get Y coordinates
            var tipWidth = $(this).width(); //Find width of tooltip
            var tipHeight = $(this).height(); //Find height of tooltip

            //Distance of element from the right edge of viewport
            var tipVisX = $(window).width() - (mousex + tipWidth);
            //Distance of element from the bottom of viewport
            var tipVisY = $(window).height() - (mousey + tipHeight);

            if ( tipVisX < 20 ) { //If tooltip exceeds the X coordinate of viewport
                mousex = e.pageX - tipWidth - 20;
            } if ( tipVisY < 20 ) { //If tooltip exceeds the Y coordinate of viewport
                mousey = e.pageY - tipHeight - 20;
            }
            //Absolute position the tooltip according to mouse position
            $(this).css({  top: mousey, left: mousex });
        }).mouseleave(function(){
            var thisClass = $(this).attr('class');
            var pieces = thisClass.split(' ');
            //console.log($('img').filter( '.' + pieces[2]).css("display", "none"));
            $('img').filter( '.' + pieces[2]).css("display", "none");
            $(this).attr('fill', "#00b2d6");
        });

Comment: O código JavaScript não é suficiente. Inclua também o código SVG e o HTML da página (`img`).
Answer: Como você não incluiu o CSS ou o HTML, vou assumir que o SVG é uma imagem qualquer, e que você não tem um CSS pré-definido.
Pelo seu JavaScript, você também tem uma imagem img.
$('img').filter( ... );

Eu criei um SVG simples (um círculo) que representa o SVG que você está usando:
<svg viewBox="0 0 200 200" width="200" height="200">
    <circle class="a b c" r="100" cx="100" cy="100" fill="red" />
</svg>

e troquei a referência path.str0 do seu código por ele para este exemplo:
$('circle').mouseenter(function(){
   var thisClass = $(this).attr('class');
   var pieces = thisClass.split(' ');

Também criei uma imagem, um  e pus três classes arbitrárias a, b e c no SVG, já que seu código tenta extrair a terceira classe do svg para referenciar a img:
$('img').filter( '.' + pieces[2]).css("display", "block");

Aparentemente está tudo funcionando corretamente (o SVG muda de cor no mouseover e mouseout, a imagem desaparece, e as coordenadas mudam durante o mousemove. Eu inclui um DIV para monitorar a mudança de coordenadas do mousemove:
$('#coords').html('y: '+mousey+', x: '+mousex);

A mudança de coordenadas está acontecendo, mas não foi definido o tipo de posicionamento (estou assumindo que você não definiu isto no CSS). Portanto, não é um erro de SVG, mas de CSS. Para posicionar em CSS você precisa definir position além das coordenadas (top,left,bottom ou right). Vai funcionar se você acrescentar um CSS com:
img {
    position: absolute;
}

Veja aqui neste JSFiddle uma tentativa de reproduzir o seu problema e solução. Acho que você conseguirá adaptá-lo para o seu problema.
Comment: helderdarocha, muito obrigado, sua ajuda foi providencial para solução do meu problema.


Applet JavaCV não exibe vídeo no browser, apenas no desktop

Question: Eu estou desenvolvendo uma aplicação web que se conecta com uma câmera de segurança via JavaCV. O applet que desenvolvi executa normalmente no desktop, mas quando eu tento executar no browser, apesar de não dar nenhum erro, ele renderiza todos os componentes swing (panels, botões, etc), mas não exibe vídeo. A instância de OpenCVFrameGrabber não executa o método start.
Abaixo está o código que uso para chamar o applet de dentro da minha página JSF (Obs.: todas as dependências já estão no .jar):
<code>    <applet code="com.br.spacnet.camera.CameraApplet"   archive="CameraApplet.jar" width="1000" height="1000">
</code>
Abaixo segue o código que conecta com a câmera e exibe o vídeo (estou usando conexão local para fins de teste):
<code>    try {

        OpenCVFrameGrabber grabber = new OpenCVFrameGrabber(0);
        jLabel1.setText(jLabel1.getText() + "; instanciou o grabber");
        //grabber.setFormat("mjpeg");
        grabber.start();
        jLabel1.setText(jLabel1.getText() + "; iniciou o Grab");
        opencv_core.IplImage frame = grabber.grab();

        while (jPanel1.isVisible()) {
            jLabel1.setText(jLabel1.getText() + "; entrou no laço");

            jPanel1.getGraphics().drawImage(frame.getBufferedImage(), 0, 0, 320, 240, null);
            jLabel1.setText(jLabel1.getText() + "; redesenhou painel");

        }
        grabber.stop();
        jLabel1.setText(jLabel1.getText() + "; parou o grabber");
        System.exit(0);
    } catch (Exception ex) {

        jLabel1.setText("Erro " + ex.getMessage());
    }
</code>
Answer: Seguindo um conselho do usuário Andrew Thompson, habilitei a exibição do console Java e pude ver vários bloqueios de segurança do JRE. Assim, adicionei as seguintes linhas no arquivo java.policy e funcionou perfeitamente:
permission java.util.PropertyPermission "org.bytedeco.javacpp.loadlibraries", "read";
permission java.util.PropertyPermission "org.bytedeco.javacpp.platform", "read";
permission java.security.AllPermission;
permission java.lang.RuntimePermission "shutdownHooks";
Para evitar que o usuário final do sistema tenha que alterar as configurações de arquivos do java, a solução definitiva requer a assinatura do .jar do applet. Este tutorial mostra como autenticar um applet auto assinado: http://www.devmedia.com.br/trabalhando-com-applet-auto-assinado-em-java/28660.


how to configure tomcat6 for ubuntu

Question: i have installed apache tomcat6 for ubuntu 9.04 recenty.But it seems that some API's like servelet and http are not included althogh i have installed openJDK 1.6. somebody advised me to set JAVA_HOME path variable. BUT i am not able to do that and from where to do that. please explain the procedure.
Answer: Are you using the ubuntu-provided version ("sudo aptitude install tomcat6") or a version that you downloaded yourself? The ubuntu-provided version should run out of the box - you'll probably have to search for the locations where the different filetypes are buried. They are spread all over the system.
If you've downloaded a version from http://tomcat.apache.org, you've probably unzipped it somewhere and want to run it now. If you allow a shameless plug: Some time ago I've created a tomcat deployment checklist.
In both cases, try java -version to see what java version is installed. If it's sun-java, you're set. If it's not found, sudo aptitude install sun-java6-jre . If it's some gcj-related, you're most likely better off to choose the sun version as default. (no pun intended for that project, I've just had way better experience with sun's variant).
sudo update-java-alternatives is your friend in choosing which of the installed jres to choose (sudo update-java-alternatives -s sun-java6)
If none of these help, please rephrase your question. To me it's not really clear what your exact problem might be. Please tell us, what version of tomcat you use (ubuntu's or a downloaded one?)

how to configure tomcat6 for ubuntu


Should I keep dBFS level on vocals relatively same?

Question: While recording vocals, should I gain whispering so dBFS meter is on similar level as when I do a scream? Like should it always sit, let's say about -15 dBFS, or is it fine when whispers are much quiter than screams in mix?
How much of a dynamics in here are the "rule of thumb" if there's something like that.
Comment: Are you asking about the recording process or the mixing process? You mention both in the question and the answer depends on which one you're asking about.
Comment: Both, to be honest. If you could say something about both I would be very grateful.
Answer: When humans sing, they naturally have a wide dynamic range. You want to capture that dynamic range, so after you have finished recording a vocal track, it should have a good bit of dynamics in it. It is pretty close to impossible to record vocals that don't have widely varying levels in it. Better singers will keep their voice intensity more even and may use mic techniques to even it out, and then you can use compression and limiting at the time to even things out, but you can never keep the levels at exactly one spot, and you don't want to.
These days, it is pretty popular to capture all the dynamic range you can get when you record, and then if you want to reduce it for the mix, you would use processing afterwards to do that.
When mixing, there is no answer to the question of what the dynamic range should be. It depends on the mix. So there's no rule of thumb, but you'll never be able to get it to be at exactly one level the whole time. Even if you could do that, that's not music. Music has dynamics.
Comment: "Music has dynamics" – tell that to a bagpipes player...
Comment: Thank you for your answer, Todd! Your answer and Leftaroundbaout's answer explained it all to me :)
Answer: I would in most cases recommend sticking to a single gain setting for each instrument/voice during tracking. Technically speaking, there is a benefit to increasing the gain when recording a quiet passage: unused headroom means you're wasting SNR, but if you have good preamps and ADCs in your interface (and use ≥24 bit!) then their SNR should anyways be more than enough for almost all recordings. Manually changing the gain is easy to get wrong – you may end up clipping the input at an unexpected louder note, which is much worse than a bit more than optimal preamp noise. And even if you get it essentially right, it may be non-obvious from the track where you changed the gain. But such manual "step"-changes can end up standing out surprisingly jarring in the final mix, and you need to go back and figure out where exactly the change happened and how to "undo" it.
The proper way to reduce excessive dynamic range is to do it smoothly. This can be done pretty well with volume automation in any modern DAW, but even better and much simpler with an ordinary compressor plugin. A compressor can do more than just bringing out a whispered passage over a loud mix, it can also bring out single syllables that would get swallowed between e.g. loud plosives. Doing that with automation would be hard, and with manual gain it's basically impossible.
Many engineers prefer having an analogue hardware compressor before the audio interface. This is like having the compressor automate the gain instead of volume. Thus is has in principle the advantage of better SNR. (Or to put it another way, compressing in digital effectively decimates the ADC's SNR, and a hardware compressor in the input circumvents this.) But frankly, I don't think this advantage is objectively measurable nowadays. When I set up such a compressor, I do it mostly for the singer's monitor signal: many singers prefer having a compressor there; it allows them to sing more dynamical in the first place because they'll hear themselves well even when singing quietly. And, because it's always easy to reduce dynamic range after the fact but less so to increase it, you should always encourage as much dynamics as possible in a studio performance.
(Good singers are able to do that by themselves though, by changing the distance to the microphone according to dynamic level. Whether that's better than a compressor is a matter of taste.)
As for how much dynamic range the vocal track should have in the final mix – that really depends heavily on the musical setting. In a metal or pop mix, you'll usually need to compress the vocals pretty heavily, in classical, Folk or Jazz much less. Apply as much compression as needed for the vocals to sit nicely in the mix, no more. Don't worry about absolute numbers, that should be only the mastering engineer's concern if at all.
Comment: Thank you so much for your comprehensive answer! It helped me a lot! I'm so glad there are people like you willing to help :)
Answer: dBFS, or "decibels relative to full-scale", measures how close to the maximum possible sample value your digital audio is. In other words, 0 dBFS means some peaks of your audio are hitting the numeric limit of what your audio format can represent. So, you never want to get too close to 0 dBFS or you'll start distorting.
That said, the relationship between dBFS and how "loud" something sounds is somewhat loose. Audio with the same dBFS measurement can sound louder or softer depending on the waveform. So, when you're trying to balance one signal with another in an ear-pleasing way, dBFS isn't the unit you should be using; dBu (relative to some standard level) would probably be the way to go.
And, THAT said, you're asking a pretty subjective question. What do you want your whispering to sound like, relative to your screaming? What else is happening in the mix? There may be times when you want your whispering to sound like God speaking to all mankind; there may be times when you want your screaming to sound like it's coming from a sealed tomb.
Comment: You mentioned an important thing with this "whispering loud and screaming quiet" in the mix. That's really something to considerate but my question is more like: what difference in vocal loudness (dynamics) is appropriate in music. And I was talking about typical rock/pop/metal song. I mentioned dBFS cause it's like it is showed in DAW and I know it's relative but I didn't know how to put it in other words.
Comment: dBFS is trivial to measure, and uncontroversially defined, which is why it's commonly displayed. It doesn't mean it's a good measurement for your purposes, though.


Pull Sharepoint out of infinite loop

Question: ...This one was my fault..
I have a SharePoint 2013 calendar page which I want to auto refresh.  The refresh was working but I kept getting the retry/cancel message if the view was adjusted in any way.  I found a solution suggestion of window.location.href = window.location.href;
From this question:Reload browser window after POST without prompting user to resend POST data

Unfortunately, I put that logic outside of my loop as well which now has the page indefinitely refreshing..
  With the constant refresh I cannot edit / discard the check out to remove the looping logic

I logged in as a different user thinking I could override the checkout, but the option is not available to override and i'm still looping.

I am hoping for a URL command which will either bring up the edit page option or somehow discard the checkout

Worst case I can delete and recreate the page, its still in test but I would rather not. (I am able to get into site settings and site content, just can't edit the page)
Answer: I opened the page is SharePoint Designer and edited the .aspx in Advanced mode, found my function and removed the loop

Pull Sharepoint out of infinite loop


Evaluate the limit $\lim\limits_{n \to \infty} \frac{1}{1+n^2} +\frac{2}{2+n^2}+ \ldots +\frac{n}{n+n^2}$

Question: Evaluate the limit
$$\lim_{n \to \infty} \dfrac{1}{1+n^2} +\dfrac{2}{2+n^2}+ \ldots+\dfrac{n}{n+n^2}$$
My approach :
If I divide numerator and denominator by $n^2$ I get :
$$\lim_{ n \to \infty} \dfrac{\frac{1}{n^2}}{\frac{1}{n^2} +1} +\dfrac{\frac{2}{n^2}}{\frac{2}{n^2} +1} + \ldots+ \dfrac{\frac{1}{n}}{\frac{1}{n} + 1}=0$$
but the answer is $\dfrac{1}{2}$ please suggest how to solve this.. thanks.
Comment: And what is $\lim_{n\to\infty}\frac{1}{n}+\frac{1}{n}+\cdots+ \frac{1}{n}$, where $\frac{1}{n}$ appears $n$ times?
Comment: Do you familiar with Riemann's sums?
Answer: For each $1\leq i\leq n$, $\frac{1}{n^2+i}\leq \frac{1}{n^2}$ and $\frac{1}{n^2+i}\geq \frac{1}{n^2+n}$, and so we may bound the sum from above and below by $$\sum_{i=1}^{n}\frac{i}{n+n^{2}}\leq\sum_{i=1}^{n}\frac{i}{i+n^{2}}\leq\sum_{i=1}^{n}\frac{i}{n^{2}}.$$ Since $\sum_{i=1}^{n}i=\frac{n(n+1)}{2},$ this becomes $$\frac{1}{2}=\frac{n(n+1)}{2n(n+1)}\leq\sum_{i=1}^{n}\frac{i}{i+n^{2}}\leq\frac{n(n+1)}{2n^{2}}=\frac{1}{2}\left(1+\frac{1}{n}\right),$$ and so it follows from the squeeze theorem that the limit is $\frac{1}{2}$.
Comment: brilliant! (all that follows is extra text inserted to satisfy the software censor's rule that "comments MUST BE at least 15 characters in length". I'm sure this excellent, and absolutely non-arbitrary rule must keep a lot of footling short comments from wasting certain peoples' very valuable time). I only wish there were far more such rules applied to comments, to encourage a more structured approach to the process of commenting.
Comment: Short and sweet!
Comment: @David, I believe the rule is to avoid myriad comments such as "me too" that will typically appear in any public forum, adding little or nothing to the information content and obscuring potentially more valuable contributions
Answer: $$ S_n=\sum_{k=1}^n \frac{k}{k+n^2} = \sum_{k=1}^n \left( 1 -\frac{n^2}{k+n^2} \right) \\
= n - \sum_{k=1}^n \left(\frac{n^2}{k+n^2} \right)
$$
but
$$\sum_{k=1}^n \left(\frac{n^2}{k+n^2} \right) = \sum_{k=1}^n \frac1{1+\frac{k}{n^2}}$$
$$ =  \sum_{k=1}^n \sum_{j=0}^{\infty} \left(\frac{-k}{n^2} \right)^j \\
= n  -\frac1{n^2}\frac{n(n+1)}{2} +O\left(\frac1{n}\right) = n - \frac12 +O\left(\frac1{n}\right) $$
so
$$ \lim_{n \rightarrow \infty} S_n = n - (n - \frac12) = \frac12 $$
Answer: Since
$$
1+n^2 \le k+n^2\le n+n^2 \quad \forall k \in \{1,2,\ldots,n\},
$$
it follows that
$$
\frac{n(n+1)}{2(n+n^2)}=\sum_{k=1}^n\frac{k}{n+n^2}\le \sum_{k=1}^n\frac{k}{k+n^2}\le\sum_{k=1}^n\frac{k}{1+n^2}=\frac{n(n+1)}{2(1+n^2)} \quad \forall n \ge 1.
$$
Thus
$$
\lim_n\sum_{k=1}^n\frac{k}{k+n^2}=\frac12.
$$
Comment: But, $$\lim_{n \to \infty} \frac1n\sum_{r=1}^n f\left(\frac rn\right)=\int_0^1f(x)dx$$
Comment: This is just Eric's answer.
Comment: @lab (+1) thank you for that succinct statement. I have previously had to go through the angst of detail every time i have applied this line of reasoning. now I can just apply this result.
Comment: @labbhattacharjee This is not a Riemann sum.  So, one would need to be careful in applying such a framework.
Answer: Use Riemann sums to show that $S\in\Big[\tfrac{\ln2}2,\tfrac12\Big]$ :
$$\sum_{k=1}^n\frac k{k^2+n^2}<\sum_{k=1}^n\frac k{k+n^2}<\sum_{k=1}^n\frac k{n^2}\quad\iff\quad\int_0^1\frac x{1+x^2}dx<S<\int_0^1xdx$$
Comment: This provides bounds, but does not yield the limit.  Apology in advance if I've missed something here.  -Mark
Comment: @Dr.MV: I was able to determine $\tfrac12$ as the upper limit, but was unable, at the time, to provide a better lower limit. Meanwhile, other answers, showing that the latter is also $\tfrac12,$ have already been posted.
Comment: No worry.  Your answers are often bedazzling.  So, I thought I might have missed something.  -Mark
Answer: Answer
$$\lim_{n \to \infty} \dfrac{1}{1+n^2} +\dfrac{2}{2+n^2}+ \ldots+\dfrac{n}{n+n^2}$$
$$\lim_{n \to \infty} \dfrac{1}{n^2}(\dfrac{1}{1/n^2 + 1} +\dfrac{2}{2/n^2+1}+ \ldots+\dfrac{n}{n/n^2+1})$$
$$\lim_{n \to \infty} \dfrac{1}{n^2}\dfrac{n*(n+1)}{2}$$
$$\lim_{n \to \infty}\dfrac{1}{2}*(1+\dfrac{1}{n})$$
$$=\dfrac {1}{2}$$
Comment: What happened from line 2 to 3?
Comment: maybe he or she use limit first as $1/n^2\to 0$, big mistake!
Comment: Not the way you are doing it here.
Comment: Can I not use product of limits?
Comment: Understood,  David's method is what I intended but applied limits improperly


Why is git pull needed to update a (different) branch (moving branch to latest commit without git pull)?

Question: I would gladly have written a more precise topic for this question, but I cannot express it better at the moment.
Basically, let's say you have a repo where you have several branches, say "master" and "mybranch".
So, let's say you're on master:
$ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

Then you do git pull here; new commits are retrieved both for master branch, and the mybranch. Since you are already in branch master, master has its HEAD automatically updated by git to the latest received commit.
Now, let's say you change branch using checkout:
$ git checkout mybranch
Switched to branch 'mybranch'
Your branch is behind 'origin/mybranch' by 2 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)

Now this is what puzzles me - in the previous pull, (apparently) all of the latest commits - including those in mybranch - had been retrieved; otherwise my local git would not "know" that my local branch "is behind ... by 2 commits".
So my question is: why would I need to do "git pull" again, having a needless roundtrip to the server - when we already have those new commits for mybranch downloaded? Isn't there a "git update-head" or some command, which would do it locally, without a round-trip to the server?
Answer: You're missing remote-tracking branches in the picture, that's what causes your confusion.
(Remider : git pull is a convenient way of doing two operations : git fetch then git merge origin/<currentBranch>)
When you fetch, you're not modifying your local branch, you're updating the remote-tracking branches which are mirrored images of remote branches.
These branches are not to be checked out or modified by you, they're used for purpose of, as you mentioned, comparisons, or other inspections.
git pull goes one step further than git fetch, though, and merges the remote-tracking branch into its local counterpart.
Which explains why you need to explicitly change branch then pull again (or simply merge) to update your other branch.
Comment: Thanks @RomainValeri - great explanation (upvoted!), however I accepted the other answer because there was a bit more command line examples.
Comment: @sdbbs No worries, Tim's answer is excellent and we all learned more in the process :-)
Answer: Your explanation of what happens in the first step is incorrect.  When you did git pull from the master branch, you were really doing git pull origin master.  This updates the local tracking branch origin/master, then merges this branch into your local master to fast-forward it.  It does not affect other branches.
If you only want to make a single round trip to the Git server, then you could try doing:
git fetch origin   # update all local tracking branches
# from e.g. mybranch
git merge origin/mybranch

Then, if you also wanted to update your local master branch, you would only need to checkout and merge:
git checkout master
git merge origin/master

Note that the above two steps happened completely locally, independent of the remote Git server.
Comment: Yes, that is correct. `git pull` should be the same `git fetch` + `git merge` (unless you configure rebase to the be the default pull strategy).
Comment: Thanks @TimBiegeleisen - so that means, in the OP example, if I already did a `git pull` in `master` (which did a `git fetch` and `git merge`) - I can just do `git merge origin/mybranch` once I `git checkout mybranch`, is that correct?


How to show that some nested radicals simplify to other

Question: Show that $\sqrt{8}\cdot\sqrt{9-\sqrt{77}}=2\cdot\sqrt{11}-2\cdot\sqrt{7}$
I have tried multiplying the radicals but that didn't work.
The resulting radicals do not add up or get subtracted.
I have tried taking commons also but that also doesn't work.
Answer: $\textbf {HINT:}$ Try to show that
$$\big( \sqrt 8 \cdot \sqrt{9-\sqrt{77}} \big)^2 =\big(2\sqrt{11}-2\sqrt7\big)^2$$
Answer: multiply both side of the fraction to $\sqrt {2}$
$$\sqrt { 8 } \cdot \sqrt { 9-\sqrt { 77 }  } =\sqrt { 8 } \frac { \sqrt { 18-2\sqrt { 77 }  }  }{ \sqrt { 2 }  } =\sqrt { 8 } \frac { \sqrt { { \left( \sqrt { 7 } -\sqrt { 11 }  \right)  }^{ 2 } }  }{ \sqrt { 2 }  } =\frac { \sqrt { 8 }  }{ \sqrt { 2 }  } \left| \sqrt { 7 } -\sqrt { 11 }  \right| =2\left( \sqrt { 11 } -\sqrt { 7 }  \right) $$


How to maximize band rehearsal time?

Question: So, I've been playing in bands for a while now, sometimes with people who have PhDs in music performance, sometimes with people who only play by ear.
Regardless of the level of professionalism, I have noticed that there's always a tendency to get songs to the 'good enough' state, and move on. But I'm a bit of a perfectionist. Good enough doesn't cut it for me. If we're playing originals, I want it to sound unique. And if we're playing covers, I want it to sound just like it does in the radio.
I'd like to collect suggestions on how to make the best of band rehearsal time to get to the point where everyone in the band shares this passion.
Answer: In order to rehearse for maximum effect, we need to first identify the purpose of rehearsal and the objectives we seek to achieve.
Here are the key things that group rehearsals should address:

Collective practice up to a point where a piece can be performed as a group,
Perfection of performance nuances, especially those that involve more than one performer,
Perfection of the group sound,
Repetition of prepared repertoire in order to facilitate playing from memory,
Preparation of an anticipated performance in terms of the repertoire to be played, set order, transitions, endings etc.

Furthermore, rehearsals may be used creatively for:

Group composition, where songs are created collectively in rehearsal, or
Group improvisation, where musical ideas are explored ad lib by the group.

Most often, rehearsal is seen mostly in terms of practicing a new song until everyone can play it and adding it to a list of "ready" material that is played through every now and again to make sure everyone remembers it. Occasionally, the group may also jam on some new ideas as well.
As we can see from the above list, this only covers part of the goals that should be strived for in rehearsal and getting a group to sound "great" requires focus on the other issues.
Unless the piece to be played has a specific written arrangement, it's likely that the individual parts will have been prepared individually by the musicians, based on their conception of what "fits". This can produce acceptable results, assuming the musicians are competent. However, such an arrangement will probably lack a true group feel, given how it is a collection of individual takes on the piece, rather than an overarching vision.
In the absence of a pre-written arrangement, rehearsals should be used to work out the details of each part so as to achieve the most effective group result. We should be focusing on issues such as:

Rhythmic interplay between instruments - the placement of unison accents, complementary accents between different instruments or groups of instruments, possible counter-rhythms etc.
The melodic and harmonic functions of each instrument - insufficient discipline on the part of musicians preparing their parts individually can lead to an overly dense collective sound, with possible "train-wrecks" as the worst case scenario. Even if this is avoided, it's possible that the resulting arrangement will not be as effective as it could be, unless the parts are evaluated in the context of a group performance.
Instrumentation and sound - there is a temptation to have all instruments playing all the time, which rarely produces the optimal result. Changing instrumentation at different points in the piece is an effective way of introducing variety and highlighting its key elements, but again it requires critical evaluation of the sound of the group as a whole. Moreover, the tones and techniques utilised by the individual musicians should also be evaluated in terms of how they contribute to or detract from the group sound.
Tempo and dynamics - depending on the requirements of the piece, there will be a need to ensure that tempo is kept constant or changed accordingly by everyone in the group. Since the musicians are listening to one another, it is possible for one musician's off performance to drag the rest of the group with it. Thus, care must be taken to ensure that everyone is working towards maintaining the desired tempo or its changes. The same applies to the issue of group dynamics.

The evaluation of the above issues requires someone to undertake the role of a musical director, listening to the group performance critically and identifying any items in need of correction. Once the details of each part have been worked out, extra time will be needed to practice the key spots and ensure they are played perfectly.
Preparing for a performance will involve several additional considerations. A set list should be prepared in advance and evaluated in terms of the appeal of the performance as a whole. Technical considerations, such as changing instruments, should be accounted for. Performance considerations, like the ability to play physically demanding pieces without rest, will need to be addressed. Any show-specific issues - beginning and ending various pieces (including potential count-offs), transitions, possible audience participation fragments - will need to be worked out. If at all possible, the entire set should be played through several times - in a dress-rehearsal fashion - in order to make sure that any potential difficulties have been accounted for.
Ultimately, making the most of rehearsal time requires a vision of the desired sound and attention to detail. Priorities will differ depending on context (perhaps you have a show coming up and need to focus on that), but the overarching objective is to make the group sound the best it possibly can.
Answer: To echo what Faza wrote, it depends on the conductor, as I saw a lecture of Benjamin Zander "it is the conductor which brings out the best of the players".

How to maximize band rehearsal time?


Create CSOM ClientContext with re-usability like singleton pattern

Question: I have multiple methods being called on different user actions which is using ClientContext.
Creating it on every method execution was causing performance issue.
So I added it as static variable for re-usability, the performance improved with an average of 5seconds but then in some methods it start giving random issue of "Version conflict" on ExecuteQuery().
But if I remove the static and null check, then it get refreshed every time and performance becomes an issue
Is there any way to create one time object of this or at-least not on every call?
And what is the default expiry of ClientContext?
Code for creating object of ClientContext:
    public class SPConnection
    {
    public static ClientContext SharepointClientContext { get; set; }
    public static ClientContext GetSharePointContext()
    {
        try
        {
            if (SharepointClientContext == null)
            {
                string appId = System.Configuration.ConfigurationManager.AppSettings["appId"];
                string appSecret = System.Configuration.ConfigurationManager.AppSettings["appSecret"];
                string siteUrl = System.Configuration.ConfigurationManager.AppSettings["siteUrl"];

                var authManager = new OfficeDevPnP.Core.AuthenticationManager();
                using (ClientContext clientContext = authManager.GetAppOnlyAuthenticatedContext(siteUrl, appId, appSecret))
                {
                    SharepointClientContext = clientContext;
                    return clientContext;
                }
            }
            else
                return SharepointClientContext;
        }
        catch (Exception ex)
        {
            iChange.Web.API.Authentication.SPConnection.InsertRecordToTableErrorLog("Mucebat:"+ex.Message, ex.StackTrace.ToString());
            throw ex;
        }

    }

Code for one of the method consuming it:
    public bool UpdateProfilePic(updateprofilepicmodel model)
    {
        using (ClientContext context = SPConnection.GetSharePointContext())
        {
            List list = context.Web.Lists.GetByTitle("Members");
            ListItemCreationInformation info = new ListItemCreationInformation();
            ListItem item = list.GetItemById(model.MemberId);

            item["ProfilePicture"] = model.ProfilepicUrl;
            item.Update();
            context.ExecuteQuery();
            return true;
        }

    }

Comment: With `using` you are disposing static `SharepointClientContext` anyway.
Answer: Can you try using ExecuteQueryAsync in combination with async tasks for performance improvement? e.g.
     public async Task <bool> UpdateProfilePic(updateprofilepicmodel model)
{
    using (ClientContext context = SPConnection.GetSharePointContext())
    {
        List list = context.Web.Lists.GetByTitle("Members");
        ListItem item = list.GetItemById(model.MemberId);
        context.Load(item);
        Task t1 = context.ExecuteQueryAsync();
        await t1.ContinueWith((t) =>
            {
                item["ProfilePicture"] = model.ProfilepicUrl;
                item.Update();
                Task t2 = context.ExecuteQueryAsync();
            });

        await t2.ContinueWith((t) =>
            {
               // do some stuff here if needed
            });

        return true;
    }
}

P.S: i have not tested this code, but in case if this works for you
Comment: Yes it is one of the other things I am doing to boost performance.
Comment: Nice, please let me know about your results or update the post in case of success. I am more into using JSOM and this is very much possible there but have doubts about CSOM (.net). Following this question, and also upvoted this :)
Answer: You can try to Load the list item before update it. Modify the code as below to check if it works.
public bool UpdateProfilePic(updateprofilepicmodel model)
{
    using (ClientContext context = SPConnection.GetSharePointContext())
    {
        List list = context.Web.Lists.GetByTitle("Members");
        ListItem item = list.GetItemById(model.MemberId);
        context.Load(item);
        context.ExecuteQuery();
        item["ProfilePicture"] = model.ProfilepicUrl;
        item.Update();
        context.ExecuteQuery();
        return true;
    }
}

If the code above not works, you can enable the version of the "Members" list in list settings to check if the issue still exists.
Comment: I can do that, but this is not the only place and calling context.ExecuteQuery(); multiple times in each will be an overhead.
Answer: You cannot use ClientContext as static object. In code you are writing your code in Using segment. ClientContext object will destroy once the execution of us using block is completed.
Comment: I am assigning it to another variable "SharepointClientContext " in using statement. And further using that public parameter.
Comment: Exactly. The client context you use is on stack and memory is allocated to it. When using statement is destroyed the memory is deallocated. Using is use to save the memory.
Comment: Send me the exact code.and the list structure you are using to understand the problem
Comment: It is the exact code and it will work fine for like hours and then start failing out of sudden.
All the purpose was to use static ClientContext object in every method, but I guess that's not possible. We have to initialize it every time.
Comment: @Amna just remove `using` statement. Just by assigning context to another variable is no help because it is reference type. You just make new pointer.


Find the minimum value of the function a(x).

Question: $$a(x)= \sqrt{x^3}+\sqrt{x^{-3}}-4(x+\frac{1}{x})$$

One of the ways I could think of was to find out the global extreme
      values and proceed.But as I began doing it that it takes a lot of
       efforts and time. Is there a simpler way to proceed?
  Further please suggest better tags if needed.
Comment: It does have a minimum value... Observe that the function is not defined over all reals. The minimum value is -10 as a matter of fact. (As per graphing calc)
Comment: You're right. I messed up the expression when I graphed it.
Comment: It's alright...
Answer: Since $x\gt 0$, we can pick $y\gt 0$ such that $x=y^2$; then the given expression becomes $$(y + {1\over y})^3 - 3(y+{1\over y}) - 4(y+{1\over y})^2 + 8$$
That's equivalent to finding the minimum of
$$t^3-4t^2-3t+8$$
for $t\ge 2$
Comment: Nice approach. We could directly set $t=\sqrt{x}+\frac{1}{\sqrt{x}}$, giving us the same expression in terms of $t$.
Comment: Nicely done. Thank you for your efforts.
Comment: I feel th approach used here has its own restrictions as well.
Comment: yw:) I'm still hoping somebody posts a more elegant method using AM-GM...
Comment: Hmm. That would be nice.
Comment: @DareDevil right, domain restrictions apply. updated the ans
Comment: here t also is greater than or equal to 2 not just greater than 0.(Using AM-GM on positive quantities)
Comment: @bjorn93 Oh yes, that looks way better! sleep time here in India haha
Answer: Hint: It is $$\sqrt{x^3}+\frac{1}{\sqrt{x^3}}-4\left(x+\frac{1}{x}\right)\geq -10$$ and this is equivalent to
$$\frac{(x-1)^2(1-7x+x^2)^2}{x^3}\geq 0$$
Comment: Method I'm asking about..
Comment: That method I get and understand but i was looking for an alternative to it. Or may be i don't understand exactly what you wish to convey. Thank you for your efforts.
Comment: Where did you get the -10 from?
Comment: I got it by calculus, what else?
Comment: Differentiating and solving $a'(x)=0$ for $x$
Comment: At first i tried to use $$a+\frac{1}{a}\geq 2$$ for $a>0$.
Comment: Hmm I tried that way but I couldn't get anything useful


Unable to ping Active Directory Server with Domain Name

Question: Domain Controller - Windows Server 2008 R2 Standard
Client OS - Window Server 2003 ( Terminal Server )
I am unable to ping my Active Directory Domain Name i.e corp.abc.com. ( Please see the print-screen )
I am successfully able to nslookup & ping my DC server ip address ( Please see the print-screen )
I am also attaching print-screen of IP configuration.

Can you tell me why i am unable to ping, but successfully able to resolve through nslookup command and also able to ping with DC server ip address
Comment: Does it work if you ping some other server's FQDN (DNS name)?
Answer: You can also use following command to resolve this problem.
1) net stop dnscache
2) net start dnscache
Comment: I faced with the issue several times on different machines. What is the reason of this behavior?
Answer: Ping uses the DNS Client service and I think nslookup establishes a winsock connection.  Try to stop DNS client service to see if it might help. Make sure you are trying to ping from a client that is joined with the ADC.
Use these commands to reset some of the network states:
As Torai suggested try to flush DNS resolver cache : ipconfig /flushdns
Reset TCP/IP stack to defaults : netsh int ip reset reset.log
Flush routing table : route /f (reboot required)
Reset WINSOCK entries to defaults : netsh winsock reset catalog

I hope that helps.
Answer: I had an issue like this recently turned out to be the netbios cache was out of date.
Try flushing it using
nbtstat -R

then ping again
http://technet.microsoft.com/en-us/library/cc757819(v=ws.10).aspx
Answer: Please restart Dnscache services. Go to services.msc --> Click on DNS Client and than restart.
Answer: From the Domain controller ping domain.com
If still the issue then run below command from cmd
devmgmt.msc
uninstall the network card from the console.
Later select "Scan for hardware changes" and the network will be back again.
Regards
Sufyan.samad
Answer: You probably need to flush your DNS. nslookup is going to the server for it, but local DNS has it cached.
ipconfig /flushdns

Answer: I had the same problem. I went and turned off firewall and it worked. Usually systems with FireWall enabled do not allow pinging in certain cases.
Go to PowerShell. Type in the following.

netsh advfirewall set allprofiles state off

The next line should be generated as

Ok.

Try pinging your domain name now.
Hope this helps! Thanks.
Comment: OP states that a ping by IP works.
Comment: Also disabling the firewall because you can't ping is a bit of a stretch.


how to add data in datagridview from textbox & save it from datagridview

Question: i am saving data from datagridview to table but There is text box from that will add data data in datagridview & I need to save data in table for particular added row.but it is not showing proper result.
<code>private void btnadd_Click(object sender, EventArgs e)
{
    String[] row = new String[7];
    row[0] = cmbsfno.SelectedItem.ToString();
    row[1] = cmbstandard.SelectedItem.ToString();
    row[2] = cmbprority.SelectedItem.ToString();
    row[3] = comboBox3.SelectedItem.ToString();
    row[4] = cmbpartfamily.SelectedItem.ToString();
    row[5] = comboBox2.SelectedItem.ToString();
    row[6] = txtremark.Text;

    dataGridView1.Rows.Add(row);
    cnt++;
}
</code>
when user added some record in datagridview how to save it in table .its saving but textbox data saving properly
Comment: "not showing proper result" what does it show?
Comment: Do you mean you want to save the data to an SQL table?
Comment: I want to save data from datagrid view to table ...but when I will 2 rows in  datagridview it shows the textbox value but i want the value added in datagridview.
Comment: u want to store datagridview datatable or dataset value to sql DB after retrieve for disply on gridview that time only it will working fine,u directly enter and shows mean it will display present txtremark value only..
Comment: suppose for 1st record i have remark as "test" and added data in datagridview & for 2nd time i have added remark "testing"....that time i want result like 1st recod having remark test & 2nd having remark testing.....but now it is showing the value present in textbox remark its because i have added row[6]=txtremark.text.
Comment: i know i need to change something Like row[6]= dataGridView1.Rows[i].Cells[2].Value.tosting()...but its not working ..
Answer: <code>    private void btnadd_Click(object sender, EventArgs e)
    {
        String[] row = new String[7];
        dataGridView1.Rows[cnt].Cell[0].value = cmbsfno.SelectedItem.ToString();
        dataGridView1.Rows[cnt].Cell[1].value = cmbstandard.SelectedItem.ToString();
        dataGridView1.Rows[cnt].Cell[2].value = cmbprority.SelectedItem.ToString();
        dataGridView1.Rows[cnt].Cell[3].value = comboBox3.SelectedItem.ToString();
        dataGridView1.Rows[cnt].Cell[4].value = cmbpartfamily.SelectedItem.ToString();
        dataGridView1.Rows[cnt].Cell[5].value = comboBox2.SelectedItem.ToString();
        dataGridView1.Rows[cnt].Cell[6].value = txtremark.Text;
        dataGridView1.Rows.Add(row);
        cnt++;
    }
</code>
Comment: i dont want txtremark.text value in datagridview 6 row. i want the value added in gridview from datatxtremark to datagridview.when I will add two rows its not showing the added value in datagridview.it showing the result from txtremak.
Comment: I want to replacedataGridView1.Rows[cnt].Cell[6].value = txtremark.Text; to added value of datagridview


Solr AND operator not working

Question: http://localhost:8080/products/select?indent=on&q=text:30MM X 533MM Abrasives&fl=*,[docid]

returns docid 187095
http://localhost:8080/products/select?indent=on&q=textfields:30MM X 533MM Abrasives&fl=*,[docid]

returns docid 187095
http://localhost:8080/products/select?indent=on&q=textfields:30MM X 533MM Abrasives AND text:30MM X 533MM Abrasives&fl=*,[docid]

returns no result.
Am I not applying AND correctly ?
Comment: With Beranrdo Comment I came to understand what I was thinking was wrong I must have used double quotes
Answer: If you use fielded data in your query and you don't use double quotes ("), the only word being searched in that field is the first one. For example, in your first request, it looks for the keyword 30MM in the "text" field, and for the rest of the keywords in the default field.
In your example, I think that if you make the query as follows should work:
http://localhost:8080/products/select?indent=on&q=textfields:"30MM X 533MM Abrasives" AND text:"30MM X 533MM Abrasives"&fl=*,[docid]

Solr AND operator not working


Array-instance of class

Question: I found an instantiation wich I do not understand how works.
The instantiation looks like this:
public static Class instance[] = new Class[arraySize];

If my guessing is right, the instance is an array?
How will this work?
Comment: It creates an array of Class references ("pointers" to Class objects), with `arraySize` number of elements.
Answer: This declares an array of Class objects references. It is equivalent to the other syntax of [] after the type.
You would access it just like a normal array:
 instance[0] = ...
 instance[1] = ...

Comment: @KickButtowski, I added a link.
Comment: can you provide a link so I can read more about it please?
Comment: is it like int[] instance = new int[90] ?
Comment: Ahh, sweet! That is actually something I have wondered in a long time if it's possible!
Comment: @OleKristianMøller-Hansen - No difference whatsoever from creating an array of String, say.
Answer: public static Class instance[] = new Class[arraySize];

public is the access modifier. This one means that this variable is visible in your entire project
static means that this variable is a "class" field it means that it belongs to the entire class and you can access it by ClassName.nameOfTheVariable or if you are accessing it from inside of class it is declared you could use just nameOfTheVariable.
Class in this context is a type and you should treat is as a type of object
[] means that this is an array you could also write Class[]
= is assignment operator
new is the word that annunciates that there will be memory allocation and constructor invokation after it
After new there is initialization of array of arraySize length.
Comment: Good point:  Java allows the declarations `ClassName[] instanceName` and `ClassName instanceName[]` to be used interchangeably -- both mean an array of object references to `ClassName` objects.
Comment: @Yoda ..Nice answer. I wonder why this answer was never upvoted!!

Array-instance of class


C Programming Book Error or Programming Error?

Question: int main()
{
// Initialize & Declare variable
int m = 5;

// Allocates memory for storage of an integer variable
int *itemp;

// Stores memory address of variable m in memory address itemp
itemp = &m;
// Notice after declaring pointer you don't need to reference it as a pointer

// asterick is also known as indirection operator
// indirect reference: Accessing the contents of a memory cell through a pointer variable that stores it's address

// We can rewrite the contents in the memory cell as such
*itemp = 35;
printf("%d",*itemp);

// Doubles the value of m
*itemp = 2 * *itemp;
printf("%d",*itemp);

return 0;
}

It's returning 3570 instead of 70, which is what the book says it should be returning. What am I doing wrong?
Comment: you are printing`*itemp` 2 times. first time its value is `35` , second times its `70` . So its printing `3570`.
Comment: Your comment for the pointer is wrong. It "allocates" memory for the storage of a *pointer to an `int`*.
Comment: You're not programming if you don't say "Wow, stupid me..." at least a few times a day.
Comment: Just change first printf("%d",*itemp); to printf("%d\n",*itemp); and see the magic. ;)
Answer: The program is correct. It is printing what it is coded to print.
To clarify,

You have two printf()s, printing 35 and 70.
You don't have a "seperator" [for example, a newline (\n)] in your printf()s to distinguish the outputs of two print statements.

Result: You're seeing the final output 3570 as the combination of the output from two print statements, 35 and 70.
Solution: Add a \n or \t at the end of the format string supplied in printf() to  add a visual seperator after each printf() to avoid confusion.
Comment: Buffering is irrelevant here. As there is no pause between printf's, the human is unable to see '35' printed before '70' anyway.
Comment: I think he/she means that it's nothing to do with buffering because nothing happens between the two printtfs, without buffering it'd be identical.
Comment: @teppic Aah, I see. Was thinking too much maybe. I'll simplify.
Answer: Just do
printf("%d\n",*itemp);

You are seeing 35 and 70 as output in the same line either add a space between them or a newline.


$P(T_{1}<T_{2})=\frac{\omega_{1}}{\omega_{1}+\omega_{2}}$

Question: Supposing that $ T_{1} $ and $T_{2}$ are independent and exponentially distributed, with parameters $\omega_{1} $ and $\omega_{2}$ respectively. Then,
$$P(T_{1}<T_{2})=\frac{\omega_{1}}{\omega_{1}+\omega_{2}}$$
I have recently been looking into exponential and gamma distributions and came across this statement, but am unsure on how to prove it. I was thinking of using the memory-less property.
$$P(T>t+s|T>s)=P(T>t)$$
Would this be a correct way to start?
Comment: I think it's easiest to observe $P(T_1 < T_2) = E[P(T_1 < T_2 | T_2 = t)]$ and compute the latter term.
Answer: Compute the following integral.
$$
\begin{align}
P(T_1<T_2)&=\int_{0}^\infty \int_{0}^y \omega_1e^{-w_1x}\omega_2e^{-w_2y}\, dx\, dy\\
\end{align}
$$


Are the linear combinations of iid random variables independent?

Question: Suppose $X_1, X_2, ... , X_n$ are independently and identically distributed random variables.
Let $\bar{X} = \frac{1}{n} \sum_{i=1} ^{n} X_i$. Are $\bar{X} $ and $X_1 - \bar{X}$ independent?
I realize that this is true if $X_1, X_2, ... , X_n$ are i.i.d. normal. However, does it work for the general case?
I have tried to prove (or disprove) this using moment generating functions. But I always end up with a very messy mgf.
Before I conclude that since the joint mgf of $\bar{X} $ and $X_1 - \bar{X}$ cannot be expressed as the product of both mgf, therefore they are both independent, I am worried that I may be missing something.
Can someone please help me out?
Comment: They aren't independent even for normal distribution (unless you meant $\bar{X} = \frac1n\sum_{i=1} ^{n} X_i$, as the usual definition of a sample mean would suggest).
Comment: Your notation is confusing.  You have an $X$ and you have some $X_i$.  The sum $\sum_{i=1}^nX=nX$, no?  What did you mean?
Comment: @lulu sorry, I have updated the question. Thanks for pointing that out
Comment: @HenningMakholm  Right, thanks.  Will edit.
Comment: @HenningMakholm  Actually, just deleting my comment as your posted solution actually did the calculation correctly.
Comment: @ProfessorVector Yes I have updated $\bar{X}$. Sorry for the typo
Comment: Keep $X_2,X_3,X_n$ fixed and modify $X_1$. What happens to $\bar X$ ?
Answer: Suppose $n=2$ and each $X_i$ is a random bit, uniformly distributed on $\{0,1\}$.
Then $\bar X = \frac12(X_1+X_2)$ and $X_1-\bar X=\frac12(X_1-X_2)$ are certainly not independent -- for example because if we know that $\bar X=0$, then necessarily $X_1-\bar X$ will be $0$ too.


How to add rounded corners to BottomAppBar with CircularNotchedRectangle in Flutter

Question: I want to create BottomAppBar with rounded corners, circular notched rectangle and material shadow.
The problem is that when I add rounded corners to BottomAppBar by wrapping it with ClipRRect widget I lose material shadow.
BottomAppBar without rounded corners, but with Material shadow. Please ignore wrong aligned notch.

BottomAppBar wrapped in ClipRRect widget, but without shadow. Again please ignore wrong aligned notch:

How to achieve rounded corners with notch and material shadow?
Full code:
import 'package:flutter/material.dart';

void main() {
  runApp(new MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: Scaffold(
        extendBody: true,
        body: Container(
          color: Colors.amber,
        ),
        floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
        floatingActionButton: Transform.translate(
          offset: Offset(0, -10),
          child: FloatingActionButton(
            onPressed: () {},
            child: Icon(Icons.add),
            elevation: 2.0,
          ),
        ),
        bottomNavigationBar: BottomNavigationView(),
      ),
    );
  }
}

class BottomNavigationView extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return Transform.translate(
      offset: Offset(0.0, -10),
      child: Container(
        margin: EdgeInsets.only(left: 20, right: 20),
        child: ClipRRect(
          borderRadius: BorderRadius.all(Radius.circular(30),
          ),
          child: BottomAppBar(
            shape: CircularNotchedRectangle(),
            child: Row(
              mainAxisSize: MainAxisSize.max,
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: <Widget>[
                Column(
                  mainAxisSize: MainAxisSize.min,
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: <Widget>[
                    Icon(Icons.accessibility_new),
                  ],
                ),
                _buildMiddleTabItem(),
                Column(
                  mainAxisSize: MainAxisSize.min,
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: <Widget>[
                    Icon(Icons.accessibility_new),
                  ],
                )
              ],
            ),
          ),
        ),
      ),
    );
  }

  Widget _buildMiddleTabItem() {
    return Expanded(
      child: SizedBox(
        height: 60,
        child: Column(
          mainAxisSize: MainAxisSize.min,
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            SizedBox(height: 24),
            Text(''),
          ],
        ),
      ),
    );
  }
}

Comment: How did you get the shadow in your first version? I can't even get that to work, shadow goes missing.
Comment: @Lee Just remove ClipRRect widget
Comment: I wasn't using ClipRRect, just CircularNotchedRectangle, and it doesn't show a shadow. Flutter is infuriating at times.
Answer: You can create your own ShapeBorder.

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        extendBody: true,
        body: Container(
          color: Colors.amber,
        ),
        floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
        floatingActionButton: Transform.translate(
          offset: Offset(0, -10),
          child: FloatingActionButton(
            onPressed: () {},
            child: Icon(Icons.add),
            elevation: 2.0,
          ),
        ),
        bottomNavigationBar: BottomNavigationView(),
      ),
    );
  }
}

class BottomNavigationView extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Transform.translate(
      offset: Offset(0.0, -10),
      child: Container(
        margin: EdgeInsets.symmetric(horizontal: 10),
        padding: EdgeInsets.symmetric(horizontal: 20),
        decoration: ShapeDecoration(
          color: Colors.white,
          shape: MyBorderShape(),
          shadows: [
            BoxShadow(
                color: Colors.black38, blurRadius: 8.0, offset: Offset(1, 1)),
          ],
        ),
        child: Row(
          mainAxisSize: MainAxisSize.max,
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: <Widget>[
            Column(
              mainAxisSize: MainAxisSize.min,
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Icon(Icons.accessibility_new),
              ],
            ),
            _buildMiddleTabItem(),
            Column(
              mainAxisSize: MainAxisSize.min,
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Icon(Icons.accessibility_new),
              ],
            )
          ],
        ),
      ),
    );
  }

  Widget _buildMiddleTabItem() {
    return Expanded(
      child: SizedBox(
        height: 60,
        child: Column(
          mainAxisSize: MainAxisSize.min,
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            SizedBox(height: 24),
            Text(''),
          ],
        ),
      ),
    );
  }
}

class MyBorderShape extends ShapeBorder {
  MyBorderShape();

  @override
  EdgeInsetsGeometry get dimensions => EdgeInsets.zero;

  @override
  Path getInnerPath(Rect rect, {TextDirection textDirection}) => null;

  double holeSize = 70;

  @override
  Path getOuterPath(Rect rect, {TextDirection textDirection}) {
    print(rect.height);
    return Path.combine(
      PathOperation.difference,
      Path()
        ..addRRect(
            RRect.fromRectAndRadius(rect, Radius.circular(rect.height / 2)))
        ..close(),
      Path()
        ..addOval(Rect.fromCenter(
            center: rect.center.translate(0, -rect.height / 2),
            height: holeSize,
            width: holeSize))
        ..close(),
    );
  }

  @override
  void paint(Canvas canvas, Rect rect, {TextDirection textDirection}) {}

  @override
  ShapeBorder scale(double t) => this;
}


Nagios vs Splunk

Question: I am looking to implement log tracking at my current company. After some research it seems Nagios and Splunk are the two best options. I was wondering if there is a consensus with which is better.
I understand that Splunk can be quite pricey if the non-free version is used. That being said I can imagine the answer to my question will be "If you have the money use Splunk, if not use Nagios"
Comment: Do you mean "Nagios Log Server" vs Splunk?
Answer: These are two different things so it's not an either or situation.
Splunk is to centralize and analyze your logs.  It is capable of generating alerts so I can see how this functionality can be confused with Nagios.  But Nagios is an infrastructure and services monitoring and alerting solution.  It can monitor things that don't necessarily have logs like cpu usage, number of processes, even check for ssl certificates about to expire.  Logs may not tell you that apache has stopped responding to http requests where Nagios can.
So in most situations you'll want to have something that does each of these jobs.  For log correlation and analysis there aren't a lot of open source options but Octopussy looks pretty good.  For infrastructure monitoring, alerts, and escalations there are a number of solutions out there.  Both commercial and free/opensource.
Comment: Does that mean these two can/should be used in concert?
Comment: At the end of the day it depends on what you're trying to accomplish.  Both are good to have in any environment and both become more important as the environment gets larger and more complex.  Also just to throw this out there there's a third type of tool for dealing with RRD graphs which are used for trending.  Nagios is starting to do more of this natively and through plugins but the best known tool for this in the open source world is Cacti.
Comment: You really should be using two tools - Nagios for SNMP and LogZilla for the syslog solution which is about 1/10 of the cost of Splunk. Also, +1 for Cacti - awesome tool!
Comment: @dan_vitch the two can indeed be using in concert; I currently use both nagios and splunk; nagios to monitor services and availability, etc, and splunk to graph contents of logs (eg number of users picking up licenses for certain software packages from network license servers over time, etc). I also use cacti, which I'd recommend too - but only on my personal kit!
Comment: Apparently there's some integration available to view nagios data in splunk.  I haven't tried it, but it certainly looks relevant: https://apps.splunk.com/app/352/
Answer: Nagios and Splunk are two completely different products.  Nagios is more networking monitoring while Splunk is more of a log console and a place to correlate events from multiple sources (including Nagios).  We use Nagios for monitoring and the free version of Splunk to consolidate syslog messages from all servers,network devices, and IPS equipment to one central location

Nagios vs Splunk


Re-calling a jquery plugin after dom manipulation

Question: I'm working on a portfolio script which uses dynamic sorting of elements. I have a list of items on the page which can be sorted with jquery. When the user clicks on one of those elements, a large image loads in a specific div on the page. There is a default image loaded at first. What I'd like to do is use slides.js by Nathan Searles to create a slideshow of 2 to 3 images. The issue I'm having is re-calling the script after a new set of images have been loaded into the div. Here's the base code which loads the items in the div.

div class="clickContent">List of images go here

div class="clickContent">List of images go here

$("ul.webbies li a").click(function(e) {
e.preventDefault();
var content = $(this).next('.clickContent').html();
if(content) $("#slidesTarget").html(content);
});
$("#slides").slides();

So, based on this example of code (I may have missed some pieces but hopefully you'll get the idea), The initial div loads up the slides.js script to create a nice slideshow. Whe the user clicks on one of the items in the ul.webbies, a new set of images is loaded into #slidesTarget. What I need to do is re-set the slides.js script to create the slideshow based on the new list of images. Hope this makes sense. Thanks in advance for any help/suggestions.
Answer: Well, this depends on the plugin your're using and what kind of hooks they allow. jquery Cycle, which I use a lot, allows you to dynamically add slides once it's initialized. Can you give a link to the plugin you're using?
jquery Cycle : http://jquery.malsup.com/cycle/
EDIT
Ok noticed the plugin.
Can't you just reinitialize the plugin on the container after you've added the slides to slides_container? Just call  $("#slidesTarget").slides();
Comment: here is the link for reference: http://slidesjs.com/. When I try to re-call the plugin, it just adds to the list instead of replacing it. I may need to look for a different slider.
Comment: hmm, a bit hard to understand what exactly you want. Would be nice if you have a working demo we could look at.
Comment: Yeah, I figured. Let me see if I can set something up.


Getting L2 switch info from the data port on a Cisco IP phone?

Question: Here's what I'm trying to do: I'm trying to get the information on which switch/port that a jack wired to.  On that jack, there is a Cisco IP phone (7942), and a computer plugged into its data port.
When I look at the CDP packets from the computer attached to it, I get the phone's CDP information (i.e. it sees the phone as a switch).
Is there a way to CDP packets, or the information on the switch behind the phone?
Comment: Show CDP neighbors from the switch and find the phone that you have identified?  Otherwise you might be able to turn on LLDP on the switch and see that through the phone, but that's not a 100% answer.
Answer: While you could just bypass the phone and plug the computer directly into the wall jack and look at the CDP packets, the simplest solution is to run 'terminal monitor' on the switch and then unplug and plug the phone back into the wall socket. You'll see which interface goes up/down.
I've done this dozens of times when troubleshooting legacy networks with dubious documentation.


How to find the Laurent series $\frac{1}{1+z^{2}}$ at point $z_0 = i$?

Question: How to find the Laurent series $\frac{1}{1+z^{2}}$ in point $z_0 = i$?
My sketch
$$1/(1+z^{2}) = \sum_{n=1}^{\infty}(-1)^{n}z^{2n}$$
I tried:
$$w = z - i$$
$$z = w + i$$
So the Laurent series about $-i$ is:
$$\sum_{n=1}^{\infty}(-1)^{n}(w+i)^{2n}$$
This is correct?
Comment: Hint: What is the partial fraction decomposition of $1/(1+z^2)$?
Answer: \begin{align*}
\dfrac{1}{z^{2}+1}&=\dfrac{1}{z-i}\dfrac{1}{z+i}\\
&=\dfrac{1}{2i}\dfrac{1}{z-i}\dfrac{1}{1+\dfrac{z-i}{2i}}\\
&=\dfrac{1}{2i}\dfrac{1}{z-i}\left(1-\dfrac{z-i}{2i}+\left(\dfrac{z-i}{2i}\right)^{2}-\cdots\right)
\end{align*}


Why is the Edit View link not appearing in Panels?

Question: I've got a Views block display placed inside a Panels pane.  It works well, and I wanted to add two similar blocks, so I cloned the View and changed the necessary settings. The original block has the cogwheel "Edit View" contextual link, but the clones do not. Any ideas? I can still go to Structure -> Views -> name to edit, but it's much easier to use the contextual link. If anyone knows why it isn't appearing and how to get it back, I'd appreciate it!
Answer: I discovered the answer by accident yesterday. When adding a Views block to a Panels pane, Panels will ask you if you want the "Master" or "Block" display. I'm not sure there's a difference in the output at all, but if you select the "Block" display, the contextual cogwheel "Edit View" link will not show up.  If you select "Master", it will.  Unfortunately, you can't change the display once it has been added, so you need to remove the "Block" display and re-add it, selecting the "Master" display.  This could cause you to have to redo some work, if you had spent any time configuring things already.


Python - falha de update() em unir dicionários

Question: Olá
Pesquisei e encontrei que dicionárioA.update(dicionárioB) é capaz de unir os dois dicionários. Testei e de fato funciona. Mas no programinha exercício abaixo, ele não une, mas guarda apenas o último dicionário que guardo. A parte do programa que mostro isso parece complexo, mas é bem simples, do meu nível. É um cadastro de um jogador de futebol e gols que fez em algumas partidas. Em tese eu teria um dicionário com vários dicionário_jogador inseridos nele, mas só consigo fazer isso em uma lista (no exemplo nomeada cadastrados), mas não no dicionário (no exemplo nomeado in_dict. Eis o código:
# declaração de variáveis
gols = 0
marcou = 0
ficha = dict()
jogos = list()
gols = list()
jogo = ''
cadastrados = list()
in_dict = dict()
# cadastro de jogador
while True:
    part = 1
    #ficha.clear()
    ficha['nome'] = input('Nome: $: ')
    ficha['ano'] = int(input('Ano: $: '))
    ficha['time'] = input('Time: $: ')
    ficha['torneio'] = input('Torneio: $: ')
    ficha['jogadas'] = int(input('Partidas realizadas: $: '))
    print('Gols marcados por partida: ')
    while True:
        jogos.append('jogo_'+str(part))
        gols.append(int(input('Gols: $ ')))
        part += 1
        sn = input('Novo jogo? [S/N] $ ').upper()
        if sn in 'Nn':
            break
# criação do dicionário
    ficha.update(zip(jogos, gols))
    # dicionário1.update(dicionário2) une os 2 dicionários
    # zip transforma duas listas em tuplas {key: valor} gerando um dicionário
    print('ficha_1', ficha) <--- PRINT DE CONTROLE
    jogos.clear()
    gols.clear()
    cadastrados.append(ficha.copy()) <--- AQUI A FICHA É ACRESCIDA A UMA LISTA E ok EM JUNTAR VÁRIOS DICIONÁRIOS NA LISTA
    in_dict.update(ficha) <--- AQUI APENAS O ÚLTIMO CADASTRO(FICHA) DO JOGADOR FICA NO DICIONÁRIO in_dict
    print('cadas', cadastrados, 'in_dict', in_dict) <--- PRINT DE CONTROLE
    sn = input('Novo cadastro? $ ').upper()
    if sn in 'Nn':
        break
print('ficha_2',ficha) <--- PRINT DE CONTROLE

resposta do terminal para um teste (para identificar onde são gerados ver PRINTS DE CONTROLE):
ficha_1 {'nome': 'b', 'ano': 2, 'time': 's', 'torneio': 's', 'jogadas': 2, 'jogo_1': 2, 'jogo_2': 3} (último cadastro criado)
cadas [{'nome': 'a', 'ano': 1, 'time': 's', 'torneio': 'r', 'jogadas': 2, 'jogo_1': 0, 'jogo_2': 1}, {'nome': 'b', 'ano': 2, 'time': 's', 'torneio': 's', 'jogadas': 2, 'jogo_1': 2, 'jogo_2': 3}] lista com os dois cadastros do teste
in_dict {'nome': 'b', 'ano': 2, 'time': 's', 'torneio': 's', 'jogadas': 2, 'jogo_1': 2, 'jogo_2': 3} dicionário apenas com o último cadastro

Answer: Vamos lá, primeiro você tem de entender como um dicionário funciona.
O dicionário tem a seguinte estrutura:
Dicionário[Chave] = valor

ou também pode ser mostrado da seguinte forma:
Dicionário = {Chave: valor}

Chaves em um Dicionário são únicas, não há como duplicar uma chave num dicionário.
De forma resumida, se eu fizer um dicionário com uma chave X e valor Y, e logo então utilizar a mesma chave com um valor Z, ele irá sobrescrever o valor Y que estava dentro da chave, pois não é possível criar uma chave que já tem no dicionário; apenas modifica-la ou sobrescreve-la.
Pelo que vi no seu script mais recomendado é criar dicionários dentro de dicionário, utilizando o nome da pessoa como indentificação:
Exemplo:
Dicionario['Antonio'] = {}
Dicionario['Antonio']['jogo'] = valor
...

vai indo...
Dicionário serve exatamente para facilitar a busca, e se você está fazendo um dicionário de usuários, qual a melhor forma de procura-los no dicionário? usando CPF, nome do usuário, id do usuário no banco de dados...
Um exemplo que uso bastante no trabalho é usar dicionários para dividir usuários por estado.  Exemplo:
# pegar todos e-mails de clientes de São Paulo
for i in dicionario['SP']
     i['e-mail']

Mas é isso, boa sorte.
Comment: Muito obrigado. Deixe-me enganar pelo teste que fiz com update. Criei 3 dicionários com o mesmo nome (a), mas com valores internos diferentes, não me dei conta disso; assim fiz 3 vezes a.update(a) e OK, ai fiz inicialmente ficha.update(ficha) e depois o do exemplo in_dict.update(ficha), dando sempre substituição. Fiz como sugeriu e funcionou OK.


File is not ignored despite adding it to .gitignore

Question: I want to ignore the file workspace which is inside the folder .obsidian/ of my git project. I have modified my .gitignore file with that purpose.
This is my .gitignore file:
 .obsidian/cache
 .obsidian/workspace
 .trash/
 .DS_Store

However, I am still getting this message when the file gets changed:
➜ git status
On branch main
Your branch is ahead of 'origin/main' by 2 commits.
  (use "git push" to publish your local commits)

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
    modified:   .obsidian/workspace

no changes added to commit (use "git add" and/or "git commit -a")

I don't know why this is happening or what to do.
Answer: .obsidian/workspace is a tracked file.  A file that is tracked is never ignored.
A tracked file is any file that is in Git's index right now.
Git's index is initially filled in from the commit you check out.  So if some file exists in some commit, and you git checkout that commit or git switch to it, that file, from that commit, goes into Git's index.  It is now in Git's index and by definition, is tracked.  Note that Git fills in both its index and your working tree, at the same time, during this checkout / switch operation.
You may manipulate a file that is in Git's index at any time:

Running git add on some file in your working tree—this is the version of the file that you can see and edit—kicks any existing copy of that file out of Git's index, then puts the working tree version of the file into Git's index.  So now the index and working tree copies match.  The file is also tracked, since it exists in Git's index.

Running git rm on some file that is in both Git's index and your working tree, removes the copy of the file from Git's index, and removes the copy of the file from your working tree.  The file is now gone entirely and therefore is not tracked.

Running git rm --cached on some file that is in both Git's index and your working tree, removes the copy of the file from Git's index, but leaves the copy in your working tree alone.  The file is now untracked by definition, as it exists in your working tree, but no longer exists in Git's index.

Last—this is redundant but worth noting—if you remove the working tree copy of some file that was in both places, then use git add on that file, Git will remove the copy from its index.  So this has the same effect as git rm (without --cached) on that file.

When you run git commit, Git—at that time—freezes a snapshot copy of every file that exists in Git's index, exactly as it appears in Git's index.  These are the files that go into the new commit.  So the index always holds the files that you propose to include in your next commit.  That's why Git fills in the index from the current commit when you check out that commit: so that the proposed next commit, matches the current commit that you just checked out.1
If you want a file to be ignored, but it's currently tracked, you must remove the file from Git's index.  Note, however, that if that file exists in some existing commits, those commits will continue to contain that file.  New commits you make, having removed the file from Git's index, will omit the file.  Comparing the existing commits to the new commits will show the file as being removed.
If you ever check out one of the older commits that has the file, then switch to one of the newer commits that lacks the file, Git will remove the file—because that's the difference between the older and newer commit!  So be careful after removing files that should never have been committed.  The existing commits do have the file, even if they shouldn't.  Checking out the older, existing commits that do have the file will cause pain in the future.

1There are some special cases here: see Checkout another branch when there are uncommitted changes on the current branch for the gory details.
Comment: In short, use `git rm --cached` on that file/folder, then add it to your `.gitignore` file.


Remover somente elementos numéricos de um array

Question: Tenho um array desta forma:
$arr = array('prolongar-se', 'durante, 4, 'a', 7, 'dias',
    'dependendo', 'da', 'dose', 'administrada', 'e', 'do',
    'pH', 'da', 'água', 'sendo', 7.5, 'ml', 'por','cada','paciente');

Gostaria de remover os valores numéricos 4, 7 e 7.5, e retornasse desta forma abaixo:
$arr = array('prolongar-se', 'durante, 'a', 'dias', 'dependendo',
    'da', 'dose', 'administrada', 'e', 'do', 'pH', 'da', 'água',
    'sendo', 'ml', 'por','cada','paciente');

Como posso remover elementos do tipo numérico de um array?
Comment: Não quis postar uma resposta falando a respeito, porque não cabe ao caso, mas depois dê uma pesquisada na função `preg_grep`. Eu gosto dela porque ela retorna os elementos do `array` que casam com a expressão regular passada!
Answer: Você pode utilizar o array_filter(), por exemplo:
$arr = array('prolongar-se', 'durante', 4, 'a', 7, 'dias',
    'dependendo', 'da', 'dose', 'administrada', 'e', 'do',
    'pH', 'da', 'água', 'sendo', 7.5, 'ml', 'por','cada','paciente');

function remover_numero($string) {

    return !is_numeric($string);

}

$arr = array_filter($arr, 'remover_numero');

O array_filter espera um retorno de true ou false, no caso de false ele remove o valor da array. No caso de true ele mantem. Dessa forma o remover_numero faz o trabalho de verificar se é ou não um número e então retornar true se não for numérico ou false se for numérico.
Você também pode utilizar algo do tipo: array_filter($arr, function($string) { return !is_numeric($string); }) que terá o mesmo efeito.

Resultado:
array(18) {
  [0]=>
  string(12) "prolongar-se"
  [1]=>
  string(7) "durante"
  [3]=>
  string(1) "a"
  [5]=>
  string(4) "dias"
  [6]=>
  string(10) "dependendo"
  [7]=>
  string(2) "da"
  [8]=>
  string(4) "dose"
  [9]=>
  string(12) "administrada"
  [10]=>
  string(1) "e"
  [11]=>
  string(2) "do"
  [12]=>
  string(2) "pH"
  [13]=>
  string(2) "da"
  [14]=>
  string(5) "água"
  [15]=>
  string(5) "sendo"
  [17]=>
  string(2) "ml"
  [18]=>
  string(3) "por"
  [19]=>
  string(4) "cada"
  [20]=>
  string(8) "paciente"
}

Teste isto!
Comment: É forma legal de resolver meu problema. Existe alguma alternativa nesta mesma linha de raciocínio para não remover valores que estejam como *string* por exemplo: `"8"`?
Comment: Se quer apenas remover se for `int` ou `float` pode utilizar a resposta do [@Wallace Maxters](http://pt.stackoverflow.com/a/187936/15089), que remove tudo que não for `string`. O `is_numeric` vai remover mesmo se for `string`.
Answer: Se no seu caso, os números que estiverem presentes no array sempre forem int ou float (e não um número dentro de uma string), você pode fazer de forma mais simples ainda:
$sem_numeros = array_filter($arr, 'is_string');

Answer: Você pode fazer uso da função unset do php para remover os elementos do vetor, mas antes de remover, você precisa verificar se o elemento é um número, uma string numérica ou apenas uma string, para isso, você pode usar a função is_numeric e por último, você precisa "reindexar" o vetor, já que a função unset remove um elemento do vetor e deixa um "buraco", para isso, você pode usar a função array_values que vai retornar todos os valores do vetor e vai indexá-lo numericamente.
PS: Se você não quiser remover as strings numéricas do vetor, como: "42", "20"..., você precisará trocar a função is_numeric por is_int e is_float
function removeNumberFromArray(&$array) {

    foreach($array as $key => $item) {
        if(is_numeric($item)) {
            unset($array[$key]);
        }
    }

    $array = array_values($array);
}

Comment: Amigão, realmente acha necessário escrever tanto código para fazer uma operação simples assim?  O PHP conta com algumas funções que podem facilitar esse tipo de operação. Usar o `unset` dentro de um `foreach` pode prejudicar a performance, dependendo do tamanho do `array`.
Comment: Necessário não é, as outras respostas mostram isso. Mas tem seu valor didático. E é sempre bom ter respostas alternativas.
Comment: Sim, concordo com você Wallace, mas se o programador iniciante não sabe como remover os elementos do vetor, ele não conhece todas as funções que abordei em minha resposta, como: unset, is_numeric, is_int, is_float, array_values e também a passagem de valor por referência, sem contar que ele vai precisar ter um pensamento estruturado para organizar tudo isso. Resumindo, isso tudo vai agregar mais conhecimento a ele. E por isso é uma resposta alternativa.


Permission denied for unix socket mounted in docker container as volume

Question: I try to containerize my nginx running currently on my server. For this I created the following docker compose file:
version: "3.8"
services:
  nginx:
    image: nginx:stable-alpine
    container_name: nginx
    restart: unless-stopped
    group_add: ["33"]
    volumes:
      - "/etc/nginx-docker:/etc/nginx/conf.d:ro"
      - "/run/php:/run/php"
      - "/var/www:/var/www:ro"
    ports:
      - "8111:80"
      - "8443:443"

Everything works fine but the problem is, that I still have php-fpm's running "natively" (not dockerized) on my host system and I want to use their sockets for my nginx container (hence the line volumes: - "/run/php:/run/php").
The sockets' permissions are srw-rw---- www-data:www-data. Therefore I added the container user to the group 33 (which is www-data on my host system -> group_add: ["33"]). When I check in the container the group ids, the id 33 is indeed added to the currently logged in user:
/ # id -G
0 1 2 3 4 6 10 11 20 26 27 33
/ # id -u
0
/ # whoami
root

Nonetheless when I call a website powered by PHP I get in the nginx logs following error message:
2024/01/21 08:58:53 [crit] 21#21: *1 connect() to unix:/run/php/php8.2-fpm.sock failed (13: Permission denied) while connecting to upstream, client: 192.168.192.68, server: _, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/run/php/php8.2-fpm.sock:", host: "op---s:8111"

Any hints or solutions what could be missing to make it work?
Comment: On what distribution are you running (Fedora/Ubuntu/...)? If you're on a RHEL-derivative, is SELinux enabled (what is the output of `getenforce`)?
Comment: @larsks I'm on Debian.
Answer: I've done some digging :)
If you enter the container running the nginx image, you can see that there's a couple of nginx processes running:
docker exec -it 43b5b971c433 /bin/sh

/ # ps -ef |grep nginx
    1 root      0:00 nginx: master process nginx -g daemon off;
   21 nginx     0:00 nginx: worker process
   22 nginx     0:00 nginx: worker process
   23 nginx     0:00 nginx: worker process
   24 nginx     0:00 nginx: worker process
   42 root      0:00 grep nginx

Some are run as root, and some as nginx user.
You have added the user root into the www-data group inside your docker-compose file, but even without doing that, root user should have all the permissions necessary to access the php unix socket.
You can test permissions with the test command. Output the exit code to see if the command has succeeded or not. As you can see, root user can read the socket file, but not execute it:
/run/php # whoami
root
/run/php # test -r  php8.1-fpm.sock; echo $?
0
/run/php # test -x  php8.1-fpm.sock; echo $?
1

So the permission denied error probably comes from the nginx worker process, run as nginx user.
Let's check the permissions for the files inside docker container first ...
ls -al gives the following output:
srw-rw----    1 xfs      xfs              0 Jan 25 08:58 php8.1-fpm.sock

saying that the socket file is owned by the "xfs".
A quick look at the /etc/group file inside the container shows the ID of the xfs group being 33 - same as the ID on the host machine for the group www-data.
Inside the container, you can add the nginx user to the xfs group:
addgroup nginx xfs

The problem should be fixed now.
I'm not sure how to add this directly into your compose file (how do you specify which user to add to the group?) - but you could do it in your Dockerfile if you can make a new image.
After restarting the container, the permissions seem to persist, though.
Comment: If I add the xfs group to the root user and the nginx user and restart the container it indeed works. But I would prefer to not write my own Dockerfile for this.
Comment: I mounted a bash script into /entrypoint.d/ of the nginx container where I run the two `addgroup` commands and it seems to work.
Comment: I see - that's a good idea. Unless there's a command that works in docker compose for modifying (specified) users and their groups, I think you're stuck with bash scripts or Dockerfiles. Also, does it work with adding the xfs group to nginx user only?
Answer: Determine the user and group that PHP-FPM is running as on the host. You can usually find this information in your PHP-FPM configuration file (commonly located at /etc/php/7.x/fpm/pool.d/www.conf)
Then update your docker-compose and add this
user: "your_php_user:your_php_group"

Answer:
Everything works fine but the problem is, that I still have php-fpm's running "natively" (not dockerized) on my host system and I want to use their sockets for my nginx container (hence the line volumes: - "/run/php:/run/php").

This isn't possible or sensible.
Docker spawns its own network namespace, so you get your own firewall stack, IP stack and Unix network stack.
Even if you fix the permissions issue, lets say for example you login to the container manually with docker exec and chmod the socket file 666 and for the sake of brevity lets assume there are no user namespaces in the way too..
What you're asking to do is the equivalent of:

Running a php-fpm instance on system1 with a Unix socket on /var/run/php-fpm.sock
Exporting the /var/run path over NFS on system1.
Mounting system1:/var/run on system2. A completely separate system.
Trying to connect() to said Unix socket socket on system2 and expecting system1 to respond with php-fpm.

The way you should actually do this (should actually want to do this, which is a separate matter) is to listen on the php-fpm instance using IP -- so binding it to host_system:12345 for example. Then using nginx in container to connect to host_system:12345.

This is all just wrong. Dont listen to me.
If you create a well-named unix socket, exposed in either namespace and the path is shared between both namespaces, connecting to that unix socket connect to the other namespace!
https://email@example.com/T/
This patch specifically addresses it. Clearly when I tested this was a long long time ago! :)
The only time this doesn't appear to be the case is in the anonymous Unix socket creation case however that one is a pretty linux specific and not often used feature of unix sockets.
Comment: https://docs.docker.com/desktop/extensions-sdk/guides/use-docker-socket-from-backend/
Comment: There are plenty of documented cases of people running docker commands on the host by bind-mounting the socket to a container and running docker buildx from a container, for CI/CD processes, for instance: https://www.kenmuse.com/blog/docker-from-docker-in-alpine-dev-containers/
Comment: @marcel I tried and tested, you're totally right! Providing the sockets path is not in the anonymous space, this really is valid. The more you know!
Comment: I would prefer sockets for performance reason. I've seen tutorials on the internet where they actually use sockets. But maybe they all were between a php-fpm docker container and a nginx container and not between a host php-fpm and a nginx docker container. Is it possible to do what I want by using a php-fpm docker container instead of running php-fpm natively on the host?
Comment: Personally I'd run the `php-fpm` instance in a pod associated with the nginx container. They will live in the same network namespace. Pods are a kubernetes/podman thing though.
Comment: Connecting via unix sockets means the connection doesn't have to go through the network stack. Not sure what happens if you connect to unix socket on the host system inside a docker container, but if you compare unix socket vs "localhost", sockets have less overhead.
Comment: @GChuf what happens if you cant do that. You're running two different network stacks.  A container stack and a host stack. See `man 7 network_namespaces` in any recent distro.
Comment: @MatthewIfe I think you might not be quite right there... it is possible, as far as I know that is exactly how Docker in Docker works. You can issue docker commands from within a container and have docker daemon on the host execute them by bind-mounting the socket from the host to the container.
Comment: @Marcel I dont imagine it works like that, rather its done with a `setns` call. Do you have the relevant documentation/link?
Comment: There's one use-case tho that I'm not really sure how they pulled it off, on MACOS the socket has an absolute path but it's restricted per user. So I'm guessing some kind of `setns` as you mentioned where two users simultaneously on the macos would maybe have two distinct namespaces and a completely isolated docker experience.


Shouldn't ROUGE-1 precision be equal to BLEU with w=(1, 0, 0, 0) when brevity penalty is 1?

Question: I am trying to evaluate a NLP model using BLEU and ROUGE. However, I am a bit confused about the difference between those scores. While I am aware that ROUGE is aimed at recall whilst BLEU measures precision, all ROUGE implementations I have come across also output precision and the F-score. The original ROUGE paper only briefly mentions precision and the F-score, therefore I am a bit unsure about what meaning they have to ROUGE. Is ROUGE mainly about recall and the precision and F-score are just added as a compliment, or is the ROUGE considered to be the combination of those three scores?
What confuses me even more is that to my understanding ROUGE-1 precision should be equal to BLEU when using the weights (1, 0, 0, 0), but that does not seem to be the case.
The only explanation I could have for this is the brevity penalty. However, I checked that the accumulated lengths of the references are shorter than the length of the hypothesis, which means that the brevity penalty is 1.
Nonetheless, BLEU with w = (1, 0, 0, 0) scores 0.55673 while ROUGE-1 precision scores 0.7249.
What am I getting wrong?
I am using nltk to evaluate BLEU and rouge-metric for ROUGE.
Disclaimer: I already posted this question on Data Science, however after not receiving any replies and doing some additional research on the differences between Data Science and Cross Validated, I figured that this question might be better suited for Cross Validated (correct me if I am wrong).
Comment: What data are you using to calculate BLEU and ROGUE-1? Your calculations may be incorrect.
Answer: BLEU computes a similarity score based on 1) n-gram precision(usually for 1, 2, 3, and 4-grams); 2) a penalty for too-short system translations.
$$\text{BLEU}=\text{BP}*\exp(\sum_{n=1}^N w_n \log p_n)$$
where $p_n$ is the modified precision for n-gram, the base of log is the natural base $e$, $w_n$ is weight between 0 and 1 for $\log p_n$ and $\sum_{n=1}^N w_n =1$, and BP is the brevity penalty to penalize short machine translations.
\begin{equation}
\text{BP} =
    \begin{cases}
    1 & \text{if $c>r$}\\
    \exp(1-\frac{r}{c}) & \text{if $c\le r$}
    \end{cases}
\end{equation}
Plug in $w = (1, 0, 0, 0)$ and $\text{BP} = 1$, we obtain this: $\text{BLEU}=p_1$ which is the precision of the uni-gram overlap.
I thought in your case the BP might be not 1. The penalty is not one if $r$, the effective reference length which is the length of the reference that's closest to the hypothesis, is greater than the length of the candidate sentence. I don't know how you calculated the accumulated lengths of the references to get the brevity penalty 1.

Is ROUGE mainly about recall and the precision and F-score are just added as a compliment, or is the ROUGE considered to be the combination of those three scores?

ROUGE is based on recall but sometimes $F_1$ version (combination of precision and recall) of it is reported anyway. Please refer to this answer.
References:

Bilingual Evaluation Understudy (BLEU)
BLEU: a Method for Automatic Evaluation of Machine Translation
What is ROUGE and how it works for evaluation of summarization tasks?
Lecture 15: Natural language generation
Comment: Thanks for the detailed reply. However, as stated in my initial post, I made sure that the brevity penalty is 1 in my case. So it is not the cause for the differences in precision scores.
By now I have a theory based on a discussion I had over on the datascience exchange: BLEU uses a micro-average while the ROUGE implementation I use employs a macro-average. However, I am still uncertain whether this is an error in that ROUGE implementation or if that's correct. From reading the ROUGE paper I would've guessed it's micro-averaged as well, but a few implementations I found use a macro-average.


Does a run scored on a tag out on a forced runner?

Question: The situation:
Runners at third and first, ball is hit to the second basemen, 2nd basemen goes to tag the runner out. Runner stops, runner on third scores and then 2nd basement tags the runner, does not step on base.Does the run count?
Comment: Are we correct to assume that in this scenario there are two outs (as it would count if there are not in any event)?
Answer: No the run does not count because the runner is forced to advance by the batter, constituting a "force out".  A run cannot score on a force play (commonly called a force out) that results in a third out of an inning.  A force out does not have to end in the touching of a base, it can end in a tag.
Rule 2.0 - Force Play
Check out the second example on this site
The above link is similar and the scoring is the same.
Also in Rule 4.09 you can see part (2):

4.09 HOW A TEAM SCORES.
(a) One run shall be scored each time a runner legally advances to and
  touches first, second, third and home base before three men are put
  out to end the inning. EXCEPTION: A run is not scored if the runner
  advances to home base during a play in which the third out is made (1)
  by the batter-runner before he touches first base; (2) by any runner
  being forced out; or (3) by a preceding runner who is declared out
  because he failed to touch one of the bases.

Also see this question regarding scoring runs

Edit
Along with the comments, if a force out does not end the inning then the run will count. A force out does not keep a run from scoring in any situation besides ending the inning. I assumed the scenario was with two outs, because this is a common question about baseball. With less than two outs (ie zero outs or one out), the run will count.
Comment: Would it be different if there weren't any outs yet before this scenario happens?
Comment: @BenMiller if there are no outs and this happens, then the run counts and there is one out after the play is over.