Going from daily probability to annual rate: more complicated than I thought?

Question: I am trying to go from a functional relationship between a predictor variable and a probability of an event occurring ($P = f(X)$) to an overall rate at which the event occurs. My scenario is estimating annual rates of fish escapement from a reservoir given a relationship between daily mean discharge $Q$ and probability of a fish escaping given said discharge, i.e. $P = f(Q)$. Let's assume that $P = f(Q)$ is a discrete relationship, i.e. I have discretized the continuous function $f(Q)$.
I am getting very low values for my annual escapement rate compared to what empirical data suggests (~3 % vs over 13%), so I am concerned that my methodology for upscaling from daily to annual escapement probability is flawed.
My original thinking for calculating the annual probability of escapement is the formula
$$
P_{annual} = \sum_i 1 - [1 - P(Q_i)]^{d_i}
$$
where $Q_i$ is a given discharge from the discretization of $f(Q)$ and $d_i$ is the total number of days in a year that reservoir discharge was held at that rate. Without any better information and given a fairly large fish population in the reservoir, I assume that the annual rate of escapement is equal to the annual probability of escapement, i.e.
$$
N_{escaped} = N*P{annual}
$$
where $N$ is the starting population of fish that year and $N_{escaped}$ is the number of fish that escaped that year.
Looking around the site, there seems to be some debate on whether my definition of $N_{escaped}$ is acceptable, and I'm not sure I am correctly defining $P_{annual}$ or that it doesn't translate to $N_{escaped}$ the way I have defined. Can any probability gurus clarify things for me?
EDIT
Thanks to @Creosote's answer the correct formulation of the annual escapement probability should actually be
$$
P_{annual} = 1 - \prod_i \left[1 - f(Q_i) \right]^{d_i}
$$
However, this changes my results on the order of 0.01%, so my problem is not solved (or perhaps the issue is not with the formulation). I obtained the discharge-escapement curve from this paper. The 13% annual escapement estimate for years 2009--2011 from the paper is based on mark-recapture studies, and the curve (with 95% confidence interval) is based on a multi-state model the authors generated from the same data (I have obtained the curve generated by the discharge-only model, which predicts slightly higher escapements that the figure in the paper). I use the reservoir release record to calculate the number of days that a release is within a given "flow band", e.g. the number of days in the year the flow is between 1000 cfs and 1250 cfs. The flow bands are actually defined such that the bounds of each band span a change in the escapement probability of 0.005%.
I don't get much above 4% for any of the years even when using the upper confidence limit of the curve. I recognize that there should be some discrepancy between the two results, but I would actually expect my escapement rates to be higher because the model accounts for tag loss and mortality. Any ideas?
EDIT 2
I'm accepting Creosote's answer because it provides the correct way to scale up from daily to annual probability. EdM's answer was also very helpful in pointing out that the issue probably has more to do with the underlying the escapement-discharge model than with the upscaling procedure. I'll post another edit if I get more information on my problem, but the daily-->annual probability question seems solved.
Answer: A randomly-chosen fish on a randomly-chosen day with discharge $Q_i$ will remain in place with probability $1-f(Q_i)$.  So it'll remain in place for the whole year with probability $\prod_i \left( 1-f(Q_i) \right)^{d_i}$, and so your $P_\textrm{annual}$ is one minus that.  Assuming I've understood your notation, that is.
Comment: Thanks @Creosote, this yields some slight differences at the 100th of a percent (for the final annual percent chance of escapement, 100*P_annual), but for practical purposes this doesn't change my results. I appreciate the correct specification however and will update my analysis to reflect your formulation.
Comment: Glad to have been of (some) help.  So ... I wonder if the problem is with your $f(Q)$.  You don't say how you derived it.  Could you expand on that?
Comment: thanks for the continued interest. I have updated the post to provide information on the curve.
Answer: As a sanity check, consider a constant daily "escapement probability" of 0.0004 (0.04%), without replacement of escaped fish back into the lake. After 365 days, the probability that an individual hasn't escaped is $(1-0.0004)^{365}$, 0.864, or a 13.6% probability of having escaped. That's about equivalent to the annual escape probability based on tagging and recapture in the cited paper. So you should be looking for a typical daily escape probability of 0.04% to account for an annual rate of about 13%.
From page 646 of the cited paper: "Model averaging indicated that daily escapement probability was approximately 0.01%"; that's only a 3.6% annualized rate, similar to what you are finding. You should note, however, that the authors state earlier on that page, at the end of Methods: "Escapement estimates obtained from Program MARK ... only provided a daily estimate of escapement that could not be extrapolated to an annual escapement rate." (Emphasis added). I am not familiar with the analysis program, but evidently its estimates as provided in this paper cannot reliably be used in the way that you intend. You might want to check with the authors of the study (or of the analysis program) for why this is the case.
Also, you should note that for 3 months during the study "daily discharge rates increased to 85 $m^3/s$"  (page 649), above the upper limit of the plot in Figure 5 showing the relation deduced between "emigration probability" and discharge. "Escapement increased exponentially as mean daily discharge increased from 8 to 61 $m^3/s$" (page 646), so it's maybe not surprising that daily escapement estimates based mostly on low-discharge conditions would underestimate the annual escape rate.
Comment: Thanks @EdM---I've contacted the authors to request more information on why the daily estimates can't be extrapolated to annual rates. My original assumption was that they did not have data/time to perform the flow analysis I am doing. Based on their curve, a daily escapement probability of 0.0004 is well outside the range of their observed flows and much higher than the normal operating range of the reservoir. I have extrapolated their curve to higher flows using a few different methods, but it doesn't make a big difference because those flows only account for < 1% of the historical record.


Erro na passagem de parâmetro para um Shell Script

Question: Estou criando um script para pegar umas imagens na pasta e com isso gerar uma outra imagem, estou usando o Imagemagick, mas o problema que estou tendo é na passagem de um dos parâmetros desse script que estou montando e me da esse erro:
<code>montage: unrecognized color `$BACKGROUND' @ warning/color.c/GetColorCompliance/1046.
</code>
basicamente, eu chamo o script e passo o parametro de cor, assim: ./meuScript.sh -b 00FFFF
e o script é esse, deixei somente o necessário
<code>#!/bin/bash

MSG_USO="
Uso: $(basename "$0") [-h | -d | -b ]
-b | --background  cor de fundo da imagem gerada
"

BACKGROUND="4E9A06"

while test -n "$1"
do
    case $1 in
        -b | --background)
            shift
            BACKGROUND="$1"
        ;;

    esac

    # opção $1 já processada, a fila deve andar
    shift
done

# remove montagem existente
rm Montagem.png
# cria nova montagem
montage -background '#"$BACKGROUND"' -geometry +4+4 *.jpg Montagem.png
</code>
Answer: O problema está na última linha do script:
<code>$ montage -background '#"$BACKGROUND"' -geometry +4+4 *.jpg Montagem.png
</code>
Tudo dentro de aspas simples é preservado, sem exceção. Veja a diferença:
<code>$ echo '#"$BACKGROUND"'
$ echo "#$BACKGROUND"
</code>
Output:
<code>$ #"$BACKGROUND"
$ #00FFFF
</code>
Logo, basta alterar para:
<code>$ montage -background "#$BACKGROUND" -geometry +4+4 *.jpg Montagem.png
</code>
Também sugiro algumas modificações:
<code>#!/bin/bash

background="4E9A06"
output_name="Montagem.png"

function remove_old_file() {
    if [ -f "$output_name" ]; then
        rm $output_name
    fi
}

function generate_image() {
    montage -background "#$background" -geometry +4+4 *.jpg "$output_name"
}

function usage() {
    echo "Uso: $(basename $0) [-h | -d | -b ]"
    echo "-b | --background  cor de fundo da imagem gerada"
}

function run() {
    remove_old_file

    while test -n "$1"; do
        case $1 in
            -b | --background)
                shift
                background="$1"
            ;;
        esac

        shift # opção $1 já processada, a fila deve andar
    done

    generate_image
}

if [ -z "$1" ]; then
    usage
else
    run $*
fi
</code>
Comment: Valew, funcionou, agora vou estudar essas alterações, mas ainda estou estudando Shell script


Dummy Update(any DML) command for Oracle for testing

Question: I would like to know if it is possible to write dummy update command for Oracle for sake of unit testing.
Something similar to
<code>        SELECT * FROM DUAL
</code>
Answer: Assuming you have a table somewhere,
<code>UPDATE mytable SET myfield = 'foo'
 WHERE 1 = 0
</code>
Answer: Option 1: create a dummy table, insert a row into it. Voila, you can update it.
Option 2: create a dummy view, add an "instead of update" trigger to it that does nothing.


Every Integral equals to zero?

Question: $$\int_a^b{f(x)}dx$$
let $u=k(x),$ where $ k(a)=0, k(b)=0 \\
k^{-1}(u)=x \\ (k^{-1})'(u) du =dx$
$$\int_{k(a)}^{k(b)} f(k^{-1}(u))\times (k^{-1})'(u)  du$$
$$=\int_{0}^{0} f(k^{-1}(u))\times (k^{-1})'(u) du$$
$$=0$$
If this is correct, then every integral would equal to zero, thus it has to be incorrect.
Comment: You'll have hard time finding an invertible map $k$ which has two inverse images for $0$.
Comment: Well, since $k(a)=k(b),$ $k$ can't be injective, and thus, $k^{-1}$ isn't actually well-defined.
Comment: Possible duplicate of ["Proof" all integrals are $0$](https://math.stackexchange.com/questions/2380669/proof-all-integrals-are-0)
Answer: If $k(a) = 0 = k(b)$ then there is not exist $k^{-1}$
Well this $k$ is not inyective
Answer: Let us play the game with
$$k(x):=(x-a)(b-x)$$ so that
$$dk=(a+b-2x)\,dx.$$
When $x$ moves from $a$ to $b$, $k$ increases from $0$ to $\dfrac{(b-a)^2}4$, then decreases back to $0$. At the same time, the sign of $dk$ changes from positive to negative.
Hence we will have a partial integral from $a$ to $\dfrac{a+b}2$ with a positive sign and another from $\dfrac{a+b}2$ to $0$ with a negative sign. Hence these two integrals do not cancel each other.

Every Integral equals to zero?


R Shiny Plotly 3D : Change the title of x , y , z axis to actual variable name and add legend title

Question: I have created a 3D scatter plot using plotly() on R shiny App. The code is as below :
output$threeDscatterPlot <- renderPlotly({
    data <- dataInput()$data
      plot.obj <<-list()
      plot.obj$data <<- data
      var7 <<- with(plot.obj$data,get(input$variable7))
      var8 <<- with(plot.obj$data,get(input$variable8))
      var9 <<- with(plot.obj$data,get(input$variable9))
      var10 <<- with(plot.obj$data,get(input$variable10))
      var10 <-  as.factor(var10)
      print(names(plot.obj$data))
p <- plot_ly(plot.obj$data, x = var7, y = var8 , z = var9 , type = "scatter3d", mode = "markers" ,
              color = var10 , colors = "Paired" )
       p %>%  layout(legend = list(x = 1, y = 0.5 , bgcolor = "#E2E2E2"))

 })

var7 , var8 , var9 are continous variable & var 10(categorical variable.
3D Plotly graph is coming very clearly but xaxis labels , yaxis labels and zaxis labels are comingas var 7 , var8 , var 9
My question is :
How can we change the title of x , y , z axis to the actual variable name of var7/8/9 as in dataset/dataframe? I tried using xaxis .zaxis , yaxis but it does not seem to work
How can we add the legend title just above the legend?
All done in R Shiny App
Thanks in Advance
Answer: Add the following to your layout object:
layout(scene = list(xaxis = list(title = 'your title')))

more info here: https://plot.ly/r/reference/#layout-scene-xaxis-title


SignatureNotFound with fog-aws and carrierwave

Question: I am using carrierwave and fog-aws while uploading a file to aws and storing the aws url in my local DB table.I have created carrierwave.rb file to config all fog-aws credentials.
begin
 CarrierWave.configure do |config|                      # required
 config.storage = :fog

 config.fog_credentials = {
  :provider               => 'AWS',       # required
  :aws_access_key_id      => 'Key_id',       # required
  :aws_secret_access_key  => 'access_key',       # required
  :region                 => 'us-west-2'  # o\tional, defaults to 'us-east-1'
  # :fog                   => 'host',
  # :endpoint               => 'host'
 }
 config.fog_directory  = 'my-images-server' # required
 # see https://github.com/jnicklas/carrierwave#using-amazon-s3
 # for more optional configuration
 config.fog_public     = true   # optional, defaults to true

My uploader file contains
class QueryUploader < CarrierWave::Uploader::Base
 storage :fog
 def store_dir
  base_dir = File.join(Rails.root, "public", "uploads")
  "#{base_dir}/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
 end
 def cache_dir
  "/tmp/service-quep"
 end
 def extension_white_list
   %w(sql)
 end
end

I read many articles and breaking my head from 2days, still could not find any solution.My access key is without space and bucket name is not trailing with a slash.Can anyone please tell why this

Expected(200) <=> Actual(403 Forbidden) excon.error.response :body => "\nSignatureDoesNotMatchThe request signature we calculated does not match the signature you provided. Check your key and signing method.YTUUYUDTDYJBKJNUFYD

error is coming.
Answer: Look, on this method you don't need to write extra code because of Rails directory mapping automatically like if you use "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" then it automatically mapping /public/uploads/...
your code
def store_dir
    base_dir = File.join(Rails.root, "public", "uploads")
    "#{base_dir}/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end

it will be
def store_dir
  "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end

You can check this gist this is great for working with Rails, CarrierWave and AWS, also you can check this
Comment: Yeah its working but then i donot understan what is the issue with the old store directory?Can you please explain.
Comment: I think that's issue is overriding store directory because of I don't found anywhere with this which you wrote to your question, the ideal and valid is `public/...`  or `uploads/...` see this https://github.com/carrierwaveuploader/carrierwave#changing-the-storage-directory
Comment: Yeah, it may be. Thanks a lot fool-dev


Missing glue at child name server

Question: I was running a quick check on Pingdom.com for a new website/server setup and have run into these two errors for the name servers:

Missing glue at child: ns1.MYDOMAIN.co.uk
The IP address of the name servers was not found at the child. This is a configuration error and should be corrected as soon as possible.
Missing glue at child: ns2.MYDOMAIN.co.uk
The IP address of the name servers was not found at the child. This is a configuration error and should be corrected as soon as possible.

The domain is with Godaddy, server is elsewhere, and the website resolves just fine. I am wondering if i'm missing a DNS configuration maybe?
Answer: What they mean is that you are missing the so named glue records.
A glue record is the ip address of a name server held at the domain name registry. These are used to avoid some circular dependencies in name resolving.
Here's an example, from the wikipedia page:

Name servers in delegations are
  identified by name, rather than by IP
  address. This means that a resolving
  name server must issue another DNS
  request to find out the IP address of
  the server to which it has been
  referred. If the name given in the
  delegation is a subdomain of the
  domain for which the delegation is
  being provided, there is a circular
  dependency. In this case the
  nameserver providing the delegation
  must also provide one or more IP
  addresses for the authoritative
  nameserver mentioned in the
  delegation. This information is called
  glue. The delegating name server
  provides this glue in the form of
  records in the additional section of
  the DNS response, and provides the
  delegation in the answer section of
  the response.
For example, if the authoritative name
  server for example.org is
  ns1.example.org, a computer trying to
  resolve www.example.org first resolves
  ns1.example.org. Since ns1 is
  contained in example.org, this
  requires resolving example.org first,
  which presents a circular dependency.
  To break the dependency, the
  nameserver for the org top level
  domain includes glue along with the
  delegation for example.org. The glue
  records are address records that
  provide IP addresses for
  ns1.example.org. The resolver uses one
  or more of these IP addresses to query
  one of domain's authoritative servers,
  which allows it to complete the DNS
  query.

Hope this helps!
Answer: You need to make sure the nameservers ns1.MYDOMAIN.co.uk and ns2.MYDOMAIN.co.uk answer authoritatively for themselves.  For each nameserver to which a domain is delegated there must exist authoritative A or AAAA records for those nameservers.  The addresses in glue records are not authoritative and do not fulfill this requirement.
Answer: Although you name it an 'error' (with quotes) it in deed is just a notice.
If the glue truly was missing, then your website would impossible work.
In the past .de's would not be activated in such condition, but they policy is less strict now.
And .fi's are still regularly checked by the registry.
Any decent registry would not allow glue'less delegations at registration.
And more important: you should never provide glue for out-of-zone nameservers (though most registries ask for it - but operationally ignore it). Just don't give it, then you know a little more sure they won't mess things up.
You can enable automatic glue processing in you nameservers configuration, such that the glue would be provided as additional answer, preventing another separate query (before the DNS resolver can provide information to the end user).
For hosting providers this may not be the most extreme efficient (but still faster), but for TLD's it if useful and will ease the load.

Missing glue at child name server


Question on Indefinite Integration: $\int\frac{2x^{12}+5x^9}{\left(x^5+x^3+1\right)^3}\,\mathrm{d}x$

Question: Give me some hints to start with this problem: $${\displaystyle\int}\dfrac{2x^{12}+5x^9}{\left(x^5+x^3+1\right)^3}\,\mathrm{d}x$$
Comment: I guess I'll be the one to point out that your order does not contain a question.
Answer: Let $x=1/t$. Then $dx=-dt/t^2$. Our integral becomes
$$ \int -\frac{2t+5t^4}{(1+t^2+t^5)^3}\,dt.$$
Comment: Well, just looked, didn't write down anything, the numbers made it clear. Hundreds of MSE users would have done it the same way.
Comment: How did you come up with such a substitution?
Comment: @André Nicolas Pls tell us how you get to this substitution ?
Comment: @TaylorTed it's [probably](https://xkcd.com/1201/) the world-famous [*integration by guessing*](http://royalpathtomath.org/docs/Integration%20by%20Guessing.pdf) or the even more famous [*integration by trying everything until finding something that works*](http://www.intmath.com/methods-integration/methods-integration-intro.php) ***chuckles***
Answer: Because of the cube in denominator, you can say that $$\int \frac{2x^{12}+5x^9}{\left(x^5+x^3+1\right)^3}\,dx=\frac{P_n(x)}{(x^5+x^3+1)^2}$$ where $P_n(x)$ is a polynomial fo degree $n$.
Now differentiate both sides to get $$\frac{2x^{12}+5x^9}{\left(x^5+x^3+1\right)^3}=\frac{\left(x^5+x^3+1\right) P_n'(x)-2 x^2 \left(5 x^2+3\right)
   P_n(x)}{\left(x^5+x^3+1\right)^3}$$ So, the right hand side is of degree $n+4$; then, since the left hand side is of degree $12$, this implies $n=8$.
So, set $P_8(x)=\sum_{i=0}^8 a_i x^i$; replacing and comparing the terms of same power then gives the $a_i$'s.
Edit
This works but it is just junk when compared to the so beautiful solution given by André Nicolas.
Answer: HINT: $$x^5+x^3+1=x^5(1+x^{-2}+x^{-5})$$
Choose $1+x^{-2}+x^{-5}=u$
Answer: Hint
Take $x^5$ common from denominator so that it's cube it will come out as $15$ and take $x^{15}$ common from  the numerator. Put the remaining denominator as $t$ numerator becomes $dt$. Hope you can do the rest.


How to remove button correctly using js

Question: I have block with 8 container's(project_block) and  with slick slider.Also in bottom I have a small button.
Slick slider trigger only in 990 pixels. And when it start to slide I need to remove button which in bottom.But how to remove that button that he's place not be empty.?
When I remove with method btn.remove() button place is stay in my slider like this look at white area in left side
Please Help
Here is Codepen snippet

$(window).on('load', function() {
  if ($(window).width() < 990) {
    $('.container-slick').slick({
      centerMode: true,
      infinite: true,
      prevArrow: false,
      nextArrow: false,
      speed: 200,
      slidesToShow: 2,
      slidesToScroll: 1,
      autoplay: true,
      responsive: [{
        breakpoint: 568,
        settings: {
          slidesToShow: 1
        }
      }]
    });
  }
});
$(window).on('resize', function() {
  if ($(window).width() < 990) {
    $('.container-slick').not('.slick-initialized').slick({
      centerMode: true,
      infinite: true,
      prevArrow: false,
      nextArrow: false,
      speed: 200,
      slidesToShow: 2,
      slidesToScroll: 1,
      responsive: [{
        breakpoint: 568,
        settings: {
          slidesToShow: 1
        }
      }]
    });
  } else {
    $(".container-slick.slick-initialized").slick("unslick");
  }
});
.projects {
  position: relative;
  width: 100%;
}

.projects .projects_title {
  font-family: 'montserrat';
  position: relative;
  bottom: 10%;
  font-size: 26px;
  font-weight: bold;
  font-style: normal;
  font-stretch: normal;
  line-height: 2.69;
  letter-spacing: 1.3px;
  text-align: left;
  color: #2a323d;
  text-transform: uppercase;
}

.projects .projects_title span {
  color: #ffb338;
}

.no-padding {
  padding: 0 !important;
}

.projects_block {
  margin-bottom: 2%;
  display: flex;
  flex-wrap: wrap;
}

.projects_block .project_block {
  width: 23%;
  display: flex;
  flex-direction: column;
  height: 100px;
  transition: background-image, box-shadow 0.3s ease-in-out;
  background-image: none;
  margin: 0 1%;
  background-size: cover;
  background-position: 58% 30%;
  background-blend-mode: multiply;
}

@media only screen and (max-width: 768px) {
  .projects_block .project_block {
    width: none;
  }
}

.projects_block .project_block:first-child {
  margin-left: 0 !important;
}

.projects_block .project_block:last-child {
  margin-right: 0 !important;
}

.projects_block .project_block:hover {
  cursor: pointer;
  border-bottom-left-radius: 40px;
  background-blend-mode: multiply;
  border-top-right-radius: 40px;
  border: 2px solid #fff;
  background-repeat: no-repeat;
  box-shadow: 15px 16px 30px 0px rgba(0, 0, 0, 0.4);
  background-image: linear-gradient(to top, #151515, rgba(255, 255, 255, 0)), url(https://milan-holidays.com/wp-content/uploads/2017/07/milan_tournimage_16_1920x1015.jpg);
}

.projects_block .project_block:hover .project_title {
  color: #fff;
  padding: 20px 0 0 20px;
}

.projects_block .project_block:hover .project_name {
  color: #fff;
  padding-left: 20px;
}

.projects_block .project_block .project_title {
  font-size: 14px;
  font-weight: normal;
  font-style: normal;
  font-stretch: normal;
  line-height: normal;
  letter-spacing: 0.7px;
  text-align: left;
  color: #666666;
}

.projects_block .project_block .project_name {
  font-size: 14px;
  font-weight: bold;
  font-style: normal;
  font-stretch: normal;
  line-height: normal;
  letter-spacing: 0.7px;
  text-align: left;
  color: #2a323d;
}

.projects_block .project_block a {
  opacity: 0;
  transition: opacity .3s ease-in-out;
  font-family: 'montserrat';
}

.projects_block .project_block:hover a {
  opacity: 1;
  font-size: 12px;
  font-weight: bold;
  font-style: normal;
  font-stretch: normal;
  line-height: normal;
  letter-spacing: 0.6px;
  text-align: left;
  color: #ffb338;
  padding-left: 24px;
  padding-top: 6px;
  text-decoration: none;
}

.project_block:nth-child(1):hover {
  cursor: pointer;
  border-bottom-left-radius: 40px;
  background-blend-mode: multiply;
  border-top-right-radius: 40px;
  border: 2px solid #fff;
  background-repeat: no-repeat;
  box-shadow: 15px 16px 30px 0px rgba(0, 0, 0, 0.4);
  background-image: linear-gradient(to top, #151515, rgba(255, 255, 255, 0)), url(https://milan-holidays.com/wp-content/uploads/2017/07/milan_tournimage_16_1920x1015.jpg);
}

.project_block:nth-child(2):hover {
  cursor: pointer;
  border-bottom-left-radius: 40px;
  background-blend-mode: multiply;
  border-top-right-radius: 40px;
  border: 2px solid #fff;
  background-repeat: no-repeat;
  box-shadow: 15px 16px 30px 0px rgba(0, 0, 0, 0.4);
  background-image: linear-gradient(to top, #151515, rgba(255, 255, 255, 0)), url(https://milan-holidays.com/wp-content/uploads/2017/07/milan_tournimage_16_1920x1015.jpg);
  background-position: 78% 0%;
}

.project_block:nth-child(3):hover {
  cursor: pointer;
  border-bottom-left-radius: 40px;
  background-blend-mode: multiply;
  border-top-right-radius: 40px;
  border: 2px solid #fff;
  background-repeat: no-repeat;
  box-shadow: 15px 16px 30px 0px rgba(0, 0, 0, 0.4);
  background-image: linear-gradient(to top, #151515, rgba(255, 255, 255, 0)), url(https://milan-holidays.com/wp-content/uploads/2017/07/milan_tournimage_16_1920x1015.jpg);
  background-position: 78% 0%;
}

.project_block:nth-child(4):hover {
  cursor: pointer;
  border-bottom-left-radius: 40px;
  background-blend-mode: multiply;
  border-top-right-radius: 40px;
  border: 2px solid #fff;
  background-repeat: no-repeat;
  box-shadow: 15px 16px 30px 0px rgba(0, 0, 0, 0.4);
  background-image: linear-gradient(to top, #151515, rgba(255, 255, 255, 0)), url(https://milan-holidays.com/wp-content/uploads/2017/07/milan_tournimage_16_1920x1015.jpg);
}

.project_block:nth-child(5) {
  margin-left: 0 !important;
}

.project_block:nth-child(5):hover {
  cursor: pointer;
  border-bottom-left-radius: 40px;
  background-blend-mode: multiply;
  border-top-right-radius: 40px;
  border: 2px solid #fff;
  background-repeat: no-repeat;
  box-shadow: 15px 16px 30px 0px rgba(0, 0, 0, 0.4);
  background-image: linear-gradient(to top, #151515, rgba(255, 255, 255, 0)), url(https://milan-holidays.com/wp-content/uploads/2017/07/milan_tournimage_16_1920x1015.jpg);
}

.project_block:nth-child(6):hover {
  cursor: pointer;
  border-bottom-left-radius: 40px;
  background-blend-mode: multiply;
  border-top-right-radius: 40px;
  border: 2px solid #fff;
  background-repeat: no-repeat;
  box-shadow: 15px 16px 30px 0px rgba(0, 0, 0, 0.4);
  background-image: linear-gradient(to top, #151515, rgba(255, 255, 255, 0)), url(https://milan-holidays.com/wp-content/uploads/2017/07/milan_tournimage_16_1920x1015.jpg);
}

.project_block:nth-child(7):hover {
  cursor: pointer;
  border-bottom-left-radius: 40px;
  background-blend-mode: multiply;
  border-top-right-radius: 40px;
  border: 2px solid #fff;
  background-repeat: no-repeat;
  box-shadow: 15px 16px 30px 0px rgba(0, 0, 0, 0.4);
  background-image: linear-gradient(to top, #151515, rgba(255, 255, 255, 0)), url(https://milan-holidays.com/wp-content/uploads/2017/07/milan_tournimage_16_1920x1015.jpg);
  background-position: 50% 100%;
}

.project_block:nth-child(8):hover {
  cursor: pointer;
  border-bottom-left-radius: 40px;
  background-blend-mode: multiply;
  border-top-right-radius: 40px;
  border: 2px solid #fff;
  background-repeat: no-repeat;
  box-shadow: 15px 16px 30px 0px rgba(0, 0, 0, 0.4);
  background-image: linear-gradient(to top, #151515, rgba(255, 255, 255, 0)), url(https://milan-holidays.com/wp-content/uploads/2017/07/milan_tournimage_16_1920x1015.jpg);
  background-position: 17% 60%;
}

@media (max-width:768px) {
  .container-slick {
    max-width: 90% !important;
    margin: auto;
    border: 1px solid red;
  }
  .projects_block .slide {
    max-width: 95% !important;
    height: 100%;
    background-size: 100% 100% !important;
    margin: 0 -20px !important;
    outline: none;
  }
}

@media (max-width:555px) {
  .container-slick {
    max-width: 95% !important;
    margin: auto;
    border: 1px solid red;
  }
  .projects_block .slide {
    max-width: 95% !important;
    margin: 0 -30px !important;
    outline: none;
  }
}

.btn_container {
  margin-top: 100px;
}

<link href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick.min.css" rel="stylesheet" />

Festival

Discover Milan's religious sites

        View →

Festival

Saint Petersburg Philharmonic Orchestra

        View →

Festival

Grand Hall Music

        View →

Festival

Hand-made art & design workshop

        View →

Festival

Discover Milan's religious sites

        View →

Festival

Saint Petersburg Philharmonic Orchestra

        View →

Festival

Grand Hall Music

        View →

Festival

Hand-made art & design workshop

        View →

        <button class="more_posts">
          More
        </button>

Comment: maybe just set width to 100% after removing the button.
Comment: @wayneOS which width ?Body or project_block or another ?
Comment: from your slider, if i got your question right.
Comment: @wayneOS Should you tell me where I can write the width?
Answer: 1) Consider using css media query to set display: none to the button you want to remove
2) Consider adding style display: none to the button upon resize using JS (totally bad idea)
3) Consider NOT TO remove button with js when you just need to hide it
4) Consider searching web before posting to SO
-------edit--------
just tried following, it hided btn successfully
@media screen and (max-width: 990px){
  .btn_container {
    display: none !important;
  }
}

Comment: @Spectr try snippet I've just added to the answer, hope it's what you're looking
Comment: Unfortunately same thing like in Matus Dubrava answer the button left white space .It just take 1 slide width but empty
Comment: @Spectr the button is actually a slide, am I correct?
So maybe you should also remove that slide?
Comment: @Spectr maybe you should move button out from slider? Try it on top of what I suggested

How to remove button correctly using js


How to notate a Da Capo al Fine and fade (or Repeat and Fade)?

Question: Short version
How would I notate a repeat and fade in a music sheet, for the entire piece? Is there a standard way to do it?
Long version
I've been transcribing a piece of music of a SNES game, and like many of its contemporaries it loops at the end to keep the music going.
Since there is no actual end, I'm thinking of having it fade out as a third loop begins, or the second finishes. And that's actually what it does from the OST files I have available. The piece loops once, and then fades at the end of the second loop. Because of this I added a Da Capo al Fine, but I'm at a loss as to how to represent the fade out of the third loop, other than explicitly writing "Fade out after/before finishing the second loop".
How can this be notated?

This is what I have right now of the (incomplete) transcription, from this piece. In case the link dies, it's the Town Theme, from Illusion of Gaia.
Comment: A repeat& fadeout is sometimes referred to as a "vamp," although a vamp is more commonly a section that's repeated ad nauseum until someone (onstage actor) is ready to go.   Fadeouts are almost always effected in studio editing not in the actual performance, BTW.
Comment: Agree with Carl, you could designate any section as "vamp (and fade last time)" or "fade after DC".
Comment: Related: [What does F.O. mean, and is it related to a repeat?](https://music.stackexchange.com/questions/118995/what-does-f-o-mean-and-is-it-related-to-a-repeat)
Answer: I would suggest writing it out explicitly, as you mentioned. DC al Fine literally translates as something like "from the top to the end". So in order to follow these instructions you need to designate a Fine or end. If you did put a fine in then you could put a long decrescendo on to indicate a fade out, but then you would want to indicate that this would only be for the 2nd time. I think explicitly writing something like "fade out 2ndX through" would take care of this. You may still want to designate a fine just so the musicians have a target to end together.
Answer: Good answer from jomki, I'll just add an example here:

(Excerpt for illustration purposes from Pink Floyd, Wish You Were Here (C) Copyright 1975 PINK FLOYD MUSIC PUBLISHERS LTD.)
Answer: If you want a fade ending at a specific place, write it precisely as a decrescendo 'al niente'.    If you want the common pop song 'repeat and fade' just write that over the top.  I've also seen 'RTF' (repeat to fade) used.
Do you want the players or the recording engineer to perform the fade?  If the engineer, perhaps better to put nothing on the music, just let them play to the end and tell the engineer what you want.


Wrap Commerce widget attributes

Question:
Clicking on Whislist, it adds product to wishlist, and hides the wishlist button and replace it with text 'Already in wishlist' which I need to style and position, so to do that I at least need it to be in a div.
Is there a template?
Answer: This video should sort you out. You need to use the hook form alter
http://www.youtube.com/watch?v=xYMd6WDqxKY

Wrap Commerce widget attributes


How to generate my own primary key for ASP.NET Identity 2

Question: I have already updated my ASP.NET Identity code to use a long (bigint in SQL) instead of a GUID/string for the user primary key. Now I would like to use a key generator to create my own primary keys rather than have the Entity Framework generate sequential keys. I'm not sure what class(es) or method(s) to edit or override to accomplish this.
Google keeps pointing me to how to change the PK type which I've already figured out. A similar question on SO wants to know how the key gets generated (answer: by EF), but doesn't ask how to do it themselves.
Answer: Here you will find all clases you have to "implement" (at least inherit from). And some small needed changes.
ASP.NET Identity 2 Change Primary Key Type to Integer on CodeProject
If you also want to generate your own Id's (don't let SQL Server let generate them), may you have to adjust the PK like in your linked post.
Comment: modelBuilder.Entity<*entityname*>().Property(m => m.*fieldname*)
             .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None); don't work?!
Comment: Thanks for your response, but I mentioned twice in my post that I've already changed the type. I'm looking for how to generate my own keys.
Answer: If you are targeting a SQL database you can use sequence. This will allow you to create a base PK and set increments for the next PK.
Comment: I want to programmatically assign my keys in code (C#).


Updating a set of  with JQuery chosen

Question: I have a page with two set of <select mutiple> which has the JQuery chosen function attached to it.
When the user clicks on a checkbox, I need to
a) take a list of one of the two set of select
b) for each select read the selected options
c) mark as selected one of the actually unselected options
d) mark a unselected one of the actually selected options
The only part I made is "a)":
var regioni = document.getElementsByClassName('regioni');

In regioni I have the list of select, but now I have no idea how do the other parts.
Please ONLY solutions of plain javascript or JQuery.
Comment: Share your code...
Answer: a) If you want a list of one of the selects you could do something like:
var arr_select = [];
$("#select_id option").each(function(i,e){arr_select.push($(e).val())});

b) If you want the values of each select:
var select_1_value = $("#select_1_id").val();
var select_2_value = $("#select_2_id").val();

But if you want the text of each element, you could try something like:
var select_1_text_selected = [];
$("#select_id_1 option:selected").each(function(i,e){
   select_1_text_selected.push($(e).text())
});

var select_2_text_selected = [];
$("#select_id_2 option:selected").each(function(i,e){
   select_2_text_selected.push($(e).text())
});

c) You need to give the property as selected to the option element, and then you need to refresh that chosen, you need to do something like:
$("#select_id option[value='1001']").prop('selected',true);
$("#select_id").trigger('chosen:updated');

'1001' is a value from an existing option element.
d) You could build the select with an empty option, and validate it later, and give a message to the user asking him for an option.
someting like this
<select id='select_1' class='chosen' data-placeholder='Please select something'>
    <option value=''></option>
    <option value='1001'> phone</option>
</select>

So you can unselect something selected, with this:
$("#select_id option[value='']").prop('selected',true);
$("#select_id option[value='1001']").prop('selected',false);
$("#select_id").trigger('chosen:updated');

Updating a set of  with JQuery chosen


How to check in real time if a user exists in a JavaScript object through an input element (raw js)

Question: I'm quite new to JS and am trying to check if a user or any value exists in a JavaScript object in real time, the goal is to implement this in Firebase in order to prevent user registration if that username has already been taken but I am doing it locally first because Im learning. This is what I have so far.

let input = document.getElementById('input')
let btn = document.getElementById('btn')
btn.disabled = false

let users = [
    {
        uname: "mark"
    },
    {
        uname: "sarah"
    },
    {
    ...others uname
    }
]

input.addEventListener('input', () => {

    input.value = input.value.replace(regex, "")
    check(input.value)

})

function check(val) {

    users.forEach((item) => {
        let uname = item.uname

        if (uname.indexOf(val) > -1 && uname === val) {
            console.log('That user name has been taken')
            btn.disabled = true
        } else {
            console.log('Ok')
            btn.disabled = false
        }
    })
}

The problem with that is when I typed in the input element Im getting both the if and else triggered and while (val) matches some key/value pairs the others won't and then I am able to use whatever username Im typing which is not what I want.
How can I solved this? Thanks.
Answer: You aren't checking to see if the username has been found.
function isUsernameAvailable (val) {
    for (var i = 0; i < users.length; i++) {
        var uname = users[i].name;

        if (uname === val) {
            console.log('That user name has been taken')
            btn.disabled = true

            return false; // the username is taken, we can stop checking
        }
    }

    console.log('Ok')
    btn.disabled = false

    return true;
}

Also, forEach doesn't let you exit the loop early and you don't need to check every user after you found a match (if you find a match).


media query css for small screens

Question: Question: How does one use css @media to target all screens below 1024x600?
I need to tell all small monitor screens to use overflow-x:scroll.
Context: I had to use the following CSS rule on both the HTML and BODY tags:
overflow-x:hidden !important;
(Otherwise certain animations cause ugly horizontal scrollbars to appear on the page.)
But now, when viewing my site using smaller screens, it would be nice if the user could scroll the page horizontally.
I'll keep looking for a css snippet that does this, but I'm posting this because the site just went live and it's about to get hit with tons of traffic, so I need something quick.
Answer: I found answers pretty quickly (http://www.javascriptkit.com/dhtmltutors/cssmediaqueries.shtml), but I still need to figure out how to test this online.
<code>/* CSS that's applied when the viewing area's width is 800px or less */
@media screen and (max-width: 800px){
  html{
  overflow-x:auto !important;
  }
  body{
  overflow-x:auto !important;
  }
}
</code>
Where does one go to test if this actually works, because testsize.com doesn't show the scrollbars (and I'm not sure if it's their limitation or my own).
Comment: You just have to resize your browser window to test media-queries. You can also try some bookmarklet : http://codebomber.com/jquery/resizer/
Comment: Ctrl+Shift+M is also a neat trick for testing in Firefox (not sure from which version).

media query css for small screens


How could these chords in Debussy's "Reverie" be analyzed?

Question: I am working on a harmonic analysis of "Reverie" by Debussy, and I am trying to find ways to analyze two things.

In the first image (mm. 24–35), the first few measures are in the key of B-flat Major, and it is a Imaj7 chord. Then there is a transition that leads to the key of C-Major. How would you analyze these chords with the C-sharps? Would you call it F+/G? And would you say that it is followed by G7sus2? Is there a good way of explaining the function of the augmented chord?

In the second image (mm. 48–58), the first three measures are in the key of F-Major. This then moves to the next section of the piece, which starts with the Dm and E chords. Would it be best to analyze the start of this section as the key of A harmonic minor? The first cadence here is a PAC in F-Major, and the second one is a PAC in E-Major. I don't know if there is a good way to analyze the function of these Dm and E chords.

If anyone has thoughts on ways to analyze these different chords, I'd love to hear them! Thanks in advance!
Question #1

Question #2
Comment: 1st piece has key sig. of F - or Dm. Maybe that's where the C# comes from? This is where playing comes in handy - listen to the sonority.
Comment: This is a piece from an Impressionistic composer. Given the harmony you've already analyzed, I'd say that Reverie is an Impressionistic piece. Accept the weirdness in the Reverie's harmonic analysis - Impressionism often doesn't follow common practice period harmony (e.g. planed chords appear too often).
Comment: A harmonic minor is not a key. A minor is.
Answer: The augmented chords
The overall harmonic progression in mm. 24–32 is:

mm. 24–26    27    28    29    30–32    32(beats 3–4)
    Bb       F+/G  Dm/G  F+/G  Dm/G     G

The Gs that appear in bars 27–32(beats 1–2) serve the function of a pedal tone. This can be tested by playing the passage without them — just replace them with F+ or Dm chord tones: the overall harmonic sense is maintained.
The chords themselves are understood in terms of the voice leading:

Bb  F+  Dm
--  --  --
F   F   F
D   C#  D
Bb  A   A

The Dm/E chords
These are set up by mm. 35–36 and mm. 37–38, shown below, which move from Cm to D, respectively — the same relationship as Dm to E. Mm. 41–42 introduce the pitch G# into the piece, which also helps prepare the ear.
The Dm is initially the relative minor of F, where we just cadenced, so the ear accepts it easily. And the transition to E has been prepared as described above.
A key detail in the oscillation between Dm and E is the "alto voice", which has moves between the pitches D and B. This happens several times over the course of the next few measures, and the intervallic relationship sets one up to hear the "soprano voice" at the end of the section, which moves between E and C#.
Reverie mm. 36–39

(Image source: IMSLP)
Comment: @Dekkadeci In light of your comment, I've added measure numbers to the OP. Do you think that's sufficient?
Comment: I think they're sufficient (although I wish I got to see pictures of mm. 36-38 now).
Comment: @Dekkadeci Wish granted.
Comment: Right, for those of us without the full sheet music of this Debussy Reverie handy, where in the question's sheet music are mm. 35–36 and mm. 37–38, bars 27–32, etc.?


Is there/can there be a model-theoretic proof of this theorem of arithmetic ?

Question: I read on MO that if an integer $a$ is a square mod $p$ for sufficiently large primes $p$, then $a$ is a square. Now that's a statement that looks awfully like a Lefschetz-principle-type statement; and so I'm wondering whether there'd be a model-theoretic proof.
It could start as follow: fix such an $a$;  let $T$ be a theory looking like the theory of rings + $\exists x, (x^2 = 1+...+1)  \land P(x)$ (there are $a$ $1$'s) + for all $p$, $char \neq p$; where $P$ is a nice formula expressing something that looks like "$x$ is an integer".
One reason this might work is that for instance $\mathbb{N}$ is definable in $(\mathbb{Q},+,\times)$, and so we may expect that such a "nice" formula $P$ may exist. With a bit of luck, using compactness would then allow us to conclude.
Of course I haven't done much here, I just threw a bunch of ideas but it's mostly because I don't see how to do better for the moment.
So my question is :

Is there a known model-theoretic proof of this fact? Has one ever been attempted ? Are there number-theoretic obstructions to the existence of such a proof ? (like for instance "this theorem implies such and such deep theorems that for some reason are essentially number-theoretic")
Comment: https://math.stackexchange.com/a/1311239/622
Comment: @AsafKaragila this is related but going in the wrong direction if I'm not mistaken ;)
Answer: I don't think this can be done. The problem is that if $a$ is not a square, then there are still infinitely many primes $p$ for which $a$ is a square modulo $p$.
Let us make this argument more formal. Suppose we have such a formula $P(x)$ that expresses that $x$ is an integer. As you proposed, we can now look at the theory given by

the theory of fields,
the statement $\exists x: (x^2 = 2 \wedge P(x))$ and
for each prime $p$, the statement $p \neq 0$.

The point is now that this theory does not have a model, since there is no field of characteristic zero in which 2 is the square of an integer. However, every finite subtheory does have a model. Namely, $2$ is the square of an integer in every field $\mathbb{F}_p$ for $p \equiv 1,7 \pmod 8$, and it is well-known that there are infinitely many such primes, so we can just take $p$ big enough. This contradicts the compactness theorem, hence such a formula $P(x)$ does not exists.
Maybe another approach would lead to a model-theoretic proof, but I don't see how one could avoid the above problem.
Comment: Well. The set of primes for which $a$ is a square modulo $p$ is an ideal. So that gives us countably many ideals. It is conceivable by diagonalization to find an ideal that avoids all of these sets.
Answer: I don't believe this can work. It is hard to prove that something can't be done, but here is what persuaded me: For every prime $p$, we can solve $x^2+y^2 \equiv -1 \bmod p$, but there is no solution to $x^2+y^2 = -1$ in the integers.
To give an example that uses only one variable, for all primes $p$, we can solve $(z^2-2)(z^2-3)(z^2-6) \equiv 0 \bmod p$, but we can't solve $(z^2-2)(z^2-3)(z^2-6) =0$ in the integers.
So there is no logical principle that let us go from $\forall_p \exists_{x,y} \ (\mbox{polynomial relation}) \bmod p$ to $\exists_{x,y} \ (\mbox{same polynomial relation})$ in the integers. You have to use some special properties of the quadratic polynomial in question, and that strikes me as too specific for model theory.
Proof of the statement that $x^2+y^2 \equiv -1 \bmod p$ is solvable: Clear for $p=2$, so we focus on $p$ odd. The function $x^2+1$ takes $(p+1)/2$ distinct values, and $-y^2$ does as well, so by the pigeonhole principle, we can solve $x^2+1 \equiv -y^2 \bmod p$.
Proof of the statement that $(z^2-2)(z^2-3)(z^2-6) \equiv 0 \bmod p$ is solvable: Clear for $p=2$ or $3$. For $p$ larger than that, note that
$$\left( \frac{2}{p} \right) \left( \frac{3}{p} \right) \left( \frac{6}{p} \right) = \left( \frac{36}{p} \right) =1$$
so the residue symbols on the left hand side cannot all be $-1$.


Beginner wants app recommendation for making electronic music

Question: I make mathematical pictures and want to back them with some music of my own composition. I play no instruments besides doodling with pianos. Actually, if I could get an app that would record my doodlings pitch-by-pitch and play them back in piano I'd be happy.
I tried this on an app that gave me a shortened piano keyboard for input, and I hit the record key, but the playback wasn't what I put in because the timing of my key presses were completely ignored. It all came out very robotic.
I'd like to put in a series of <100 notes, and have that recorded at exactly the timing I used in the input. And then put that or portions or distortions of that on repeat. Can it be done? Thx.
P.S. (In response to the responses) I don't have access to a real keyboard.
Comment: Please read about [the topics covered here](https://music.stackexchange.com/help/on-topic). But plenty such solutions exist; a few minutes research should find one. And why does it need to be an app? Why not a digital keyboard?
Comment: Do you want app playback or just music recordings? What prevents you from videotaping yourself on the keyboard with the default camera app?
Answer: My suggestion is to learn some scripting language like Python. You can see an image basically like a 2d matrix, in which each cell has 3 values, RGB.
You can parse the image via Python, get the data, perform processing you like (that's the artistic part I think) and then generate a MIDI file with music.
In this way the music will be somehow linked to the images.


http put request to upload a file flutter

Question: How to write this in dart with the http package the -F takes the file not the file path.
curl -X PUT "https://api.groupdocs.cloud/v1.0/parser/storage/file/hello.pdf"
-H "accept: application/json"
-H "authorization: Bearer [Access_Token]"
-H "Content-Type: multipart/form-data"
-H "x-aspose-client: Containerize.Swagger"
-F "file"="@C:/Temp/wavenet.pdf"

Answer: var headers = {
  'Authorization': 'Bearer [Access_Token]'
};
var request = http.MultipartRequest('PUT', Uri.parse('https://api.groupdocs.cloud/v1.0/parser/storage/file'));
request.files.add(await http.MultipartFile.fromPath('file', '/Users/bholendraofficial/Desktop/BHOLENDRA SINGH RESUME.pdf'));
request.headers.addAll(headers);

http.StreamedResponse response = await request.send();

if (response.statusCode == 200) {
  print(await response.stream.bytesToString());
}
else {
  print(response.reasonPhrase);
}


Does $\sum_{n=1}^\infty \left(e^{\frac{1}{n}} - 1\right)$ converge?

Question: Evaluate $\sum_{n=1}^\infty \left(e^{\frac{1}{n}} - 1\right)$
$ \lim e^{\frac{1}{n}} = 1$
$\sum_{n=1}^\infty \left(e^{\frac{1}{n}} - 1\right) > \sum_{n=1}^\infty(-1) = -\infty$
I'm not sure how to solve it. I tried two no convergence ways. what do u guys think about it?
Comment: is $-1$ inside or outside of the sum?
Answer: Since $e^x\geq 1+x$ we have $e^{1/n}-1\geq 1/n$ and hence the sum diverges by the comparison test.
Answer: Your idea of using a comparison is a good one, however, the comparison $$e^{\frac{1}n}-1>-1$$
is not particularly helpful, since the sum over $-1$ diverges to $-\infty$, so the comparison doesn't actually tell us anything. A more useful comparison would be
$$e^{\frac{1}n}-1>\frac{1}n$$
since $e^x=1+x+\frac{x^2}{2!}+\frac{x^3}{3!}+\ldots$ and if $x$ is positive, this is just $1+x+\text{positive terms}$ so $e^x>1+x$.
In general, notice that $f(x)=e^x-1$ is a function which has $f(0)=0$ and $f'(0)\neq 0$. One can use the bounds provided by the derivative to show that $\sum_{i=0}^{\infty}f(a_i)$ converges absolutely exactly when $\sum_{i=0}^{\infty}a_i$ converges absolutely.
Answer: In THIS ANSWER, I showed using standard, non-calculus based tools that the exponential function satisfies the inequality
$$e^{x}\ge 1+x$$
Therefore, we have with $x=1/n$
$$e^{1/n}-1\ge \frac1n$$
Since the harmonic series, $\sum_{n=1}^\infty \frac1n$, diverges, then by the Comparison Test, the series of interest diverges.


How to subscribe and unsubscribe from EventStream on the first event received?

Question: I am trying to figure it out if there is a function in the Bacon.js API that allows to subscribe to an EventStream and when the first event fires up, the handle is unsubscribed. The way to do it that I know is the following:
let stream = new Bacon.Bus();

stream.onValue(val => {
    doSomething(val);
    return Bacon.noMore;
});

But is there something like stream.onValueOnce that automatically unsubscribe the handler after it is executed?
I also know that there is the Bacon.once that creates a EventStream that returns a single value and then ends the stream but this is not what I am looking for.
Update
As Bless Yahu sais, take or first methods can be used. To be more specific, you have to call it from the created eventStream like that:
let stream = new Bacon.Bus();

stream.first().onValue(val => {
    doSomething(val);
});

Here is a fiddle that shows it:
https://fiddle.jshell.net/3kjtwcwy/
Answer: How about stream.take(1)?  https://baconjs.github.io/api.html#observable-take
Or stream.first()? https://baconjs.github.io/api.html#observable-first
Comment: perfect. that is what I was looking for


O que é Event-Dispatching Thread (EDT) em interfaces gráficas?

Question: Quando se está aprendendo a construir interfaces gráficas com swing/AWT, ouve-se muito falar sobre a Event-Dispatching Thread (ou EDT).  Apesar de já ter uma certa convivência com swing, confesso que não compreendo bem o que vem a ser a EDT. Sei que existe explicação na documentação(em inglês), mas não encontrei boas explicações e completas em português.
A partir disso questiono: O que é a EDT e como ela funciona durante a execução de uma interface gráfica construída usando swing/AWT?
Comment: Tem uma boa resposta aqui. http://stackoverflow.com/questions/7217013/java-event-dispatching-thread-explanation
Comment: @Marconi eu vi, mas gostaria de uma boa resposta em português, infelizmente nem todos(onde me incluo) temos domínio do inglês, e tradutores as vezes retornam traduções confusas, pra quem não faz ideia do assunto, acaba atrapalhando mais ainda.
Answer: TL;DR
É a única thread que pode manipular diretamente a interface gráfica para evitar problemas de concorrência. Ela fica num loop esperando por eventos que vem da tela (cliques, teclas, etc.) ou diretamente do programa e aplica todas as alterações sequencialmente.
Motivação
Confesso que até ler um artigo citado na resposta da questão que o @Marconi deixou no comentário eu não sabia porque a EDT é do jeito que é.
Se você quer mesmo entender isso, faça um esforço e leia:

Multithreaded toolkits: A failed dream?

Em resumo: desenvolver um framework GUI multithreading, onde várias threads podem manipular os componentes da tela, não funciona na prática.
O autor argumenta que, a princípio, criar uma interface gráfica multithreading parece quase trivial, apenas uma questão de colocar os locks no lugar certo.
Entretanto, telas têm uma natureza que faz com que isso não seja tão simples: ela aceita eventos concorrentes opostos.

O programa altera a tela e a alteração é propagada dos componentes de mais alto nível na hierarquia até os de mais baixo nível. Por exemplo: Da janela, depois para o painel e depois para o botão.
Os eventos gerados pelo usuário vão dos componentes de mais baixo nível da hierarquia para os de mais  alto nível. Por exemplo: do botão, para o painel e do painel para o frame.

Tudo isso faz com que os locks não funcionem bem, gerando deadlocks e glitches com frequência.
O autor conta que foram colocados muitos esforços na época em que o AWT era multithreading e eles chegaram num tipo de beco sem saída. A solução foi fazer o que praticamente todos os outros frameworks de GUI faziam: mudar para um modelo EDT.
Ele ainda argumenta que existem implementações de GUI multithreading, porém elas só funcionam bem se as pessoas que desenvolvem a GUI forem as mesmas que desenvolvem o framework, pois isto exige conhecimento específico e detalhado do modelo. Porém, num framework de propósito geral feito para uso em larga escala, isso nunca iria funcionar bem.
Portanto, no modelo usando EDT, as alterações na GUI são feitas todas usando uma única thread (single threaded) gerenciada pelo framework e quando as outras threads (como a thread principal do programa) querem realizar alguma alteração, elas devem disparar um evento para a thread do AWT.
Uma das formas de fazer isso é usando invokeLater, porém dentro de manipuladores de eventos (listeners) isto não é necessário porque eles executam dentro da thread do AWT, o que também implica que qualquer processamento demorado dentro da EDT bloqueia todo o programa.
Comment: Ótima explicação!


MySQL - How do I give users in SQL access to different files

Question: I am a drumline instructor for a local high school and I am in the process of making a webpage for the students to access their music.
I am making a user list in a table and need to add permissions to the users so that they can only access music (PDF files) that I assign to them. Initially, I thought about maybe using an array for filenames, but after seeing how much controversy there is over arrays in SQL, I decided to reach out and see if there are better recommendations.
As of right now, I have a table with all of the users'
there columns are
emails,
passwords,
first/last names,
and instruments.
I would like to be able to just add another field to this that controls what files they have access to.
Comment: Don't add a column, add a junction table (e.g. `student_music`) where you link users to files.
Comment: you can add a column of bit /boolean type to give access and set their value to true /false on permission
Comment: You can add a field to define usergroup, then give access of certain files only to the defined group
Comment: @smile regarding a junction table, would making another table with the filenames as individual rows then the users' emails that are allowed to access that file as columns be what you mean by that? In which case, loading the files would scan the columns after each song title for that user's name, right? If that's the case, would this be easier to do with XML?
Answer: What you have here is a many-to-many relationship between students and files. The way we generally solve this in MySql is by creating a pivot table. Here is a small example:
CREATE TABLE users (
    id INTEGER PRIMARY KEY,
    email VARCHAR(100) NOT NULL
);

CREATE TABLE assignments (
    id INTEGER PRIMARY KEY,
    filepath VARCHAR(100) NOT NULL
);

CREATE TABLE user_assignment (
    id INTEGER PRIMARY KEY,
    user_id INTEGER NOT NULL,
    assignment_id INTEGER NOT NULL,
    FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE RESTRICT ON UPDATE CASCADE,
    FOREIGN KEY (assignment_id) REFERENCES assignments (id) ON DELETE RESTRICT ON UPDATE CASCADE,
);

So, each entry in the user_assignment pivot table signifies that the user with the id user_id has access to the assignment with the id assignment_id.


What is $delta for in Field API hook_field_widget_form?

Question: d.o defines it as such:

$delta The order of this item in the array of subelements (0, 1, 2, etc).

So that you can use it as an index into the $items array, but i can't seem to wrap my head around when the $items array would have more than one element.
Answer: See the answer to my question re; delta field in views.  I got an answer for $delta as well.
Comment: I read yours but i didn't quite understand at the time...  do you know how to specify a multi-valued field?  None of the hooks in the Field API seem to explain a way.
Comment: Sorry, I am just beginning to venture into php coding. I am at the idiot level.
Comment: Lol, well atm it seems that i can successfully disregard it and still able to create my custom field.  If i run into an issue, i'll comment back.


How to store form in order

Question: I have customers filling out an entry form before sending them to checkout.  Is it possible to store, or serialize, the $form_state array in the order?  There is a 'data' field in the order.  Is it simple as me calling:
$order->data = serialize($form_state);
commerce_order_save($order);

EDIT:
The data field in the order is an array that gets serialized.  So, it looks like I can do:
$order->data['myform'] = $form_state;

Answer: There is the data attribute on entities, which you cannot access through Entity Metadata Wrappers (per previous answer.)
Do you need the full form state or just values? Also, you do not need to serialize the data, as the entity controller will do this for you.
I would do something like:
form_state_values_clean($form_state);
$order->data['myform_values'] = $form_state['values'];

form_state_values_clean() will remove build IDs and such.
Comment: I didn't even know about the _clean() function.  Very cool. Thanks!
Comment: I've asked a related question about the $order->data property and where documentation for it can be found: http://drupal.stackexchange.com/questions/163176/where-is-documentation-for-entity-data-property-i-e-commerce-order-data
Answer: You would need to add a field to commerce_order called field_data and then save it, yes.
The pattern might be more like:
$order_wrapper = entity_metadata_wrapper('commerce_wrapper', $order_id);
$order_wrapper->field_data = serialize($form_state);
$order_wrapper->save();

Comment: There is already a data field in the order.  Am I not able to use that one?

How to store form in order


With a 500GB SSD and a 250GB SSD is it possible to mirror a 250GB partition on the 500GB with the 250GB SSD using ZFS?

Question: So I have a Samsung 250GB 850 Evo SSD and a 500GB 860 EVO SSD. I'm looking at using Solaris for this server (so looking at whether doing this with ZFS is possible). Is it possible to mirror the 250GB SSD with a 250GB partition on the 500GB SSD, while leaving the other half of the 500GB drive useable (it would used rather infrequently so not too worried about a performance hit)?
Comment: This isn't a good idea. Can you acquire equally-sized disks?
Comment: a) If they can't sell you what you requested then they can give you 2 x 500GB SSDs and b) Solaris? *checks watch* it's 2019, why do you want Solaris?
Comment: SmartOS - it's an OpenSolaris based OS
Comment: It was supposed to be 2 x 250GB SSDs but they were out of stock so they gave me a 500GB one instead. So I'm hoping to actually be able to use that extra space.
Answer: First things first: this is not a good idea. You should really use same-capacity disks, if possible.
That said, what you ask is indeed possible: you need to partition both disks each with a ~250 GB partition, and setup ZFS to use these two partitions as block devices for the mirrored vdev.
For example:

disk #1 will have a single, 250 GB partition;
disk #2 will have two 250 GB partitions;
a zpool is created using the first partition on each drive (ie: zpool create tank mirror /dev/sda1 /dev/sdb1);
the second 250 GB partition on disk #2 is available for other uses: you can create another zpool (ie: zpool create scratch /dev/sdb2), or even use it for with another filesystem (ie: mkfs.xfs /dev/sdb2). But remember that this will not be mirrored in any way.
Comment: Why would it not be a good idea? Would it be an IO performance issue? If the second partition is not being read to or written to (apart from maybe 5% of the time) would there still be a problem? Or is it because the second partition would not be mirrored (there wouldn't be any important data on the partition)?
Comment: It's a bad idea because you're starting with a flawed solution. For the effort spent in asking what's possible, you could just acquire disks of equal size and not worry about the ramifications.
Comment: Although I agree with the other comments that this is far from an ideal solution, if IO isn't an issue then I don't see a problem with this particular use case. @shodanshok is already familiar enough with RAID to understand its benefits and should therefore also understand that everything on the second partition is to be treated as volatile. For example, all important data to be held on the RAID with the second partition for downlaods, games, Steam library, etc.
Comment: Also of note, this could be used as both a cost-savings measure and a way to *increase* performance in the case of a laptop with an SATA SSD and a second NVMe drive. Performance is expected to be excellent on the NVMe but hobbled by the IO limitations of the SATA disk. By intentionally choosing an oversized NVMe, a second partition can be used there for data which would benefit from IO but doesn't need to be mirred (games as an example). You would need to run benchmarks to confirm, but the extra IO bandwidth on the NVMe drive may mitigate any issue with simultaneous writes to the ZFS array.
Comment: Also may be good to point out that if you only use the 500GB disk for the 250G partition (or don't use much of the other 250G partition), that disk will last longer than the other due to SSD ware-leveling.
Comment: @ewwhite (and shodan): You're just saying it's flawed without explaining why you think so.  You want to give ZFS two equal-capacity partitions, but why would the size of the whole device containing those partitions make any difference?  The larger device is also faster in this case (I think), leaving some extra margin for occasional I/O to other partition(s) on the larger device if I/O is bottlenecked (by the slower device) on writes.
Comment: its possible, not good practice... but its possible as they written you can always use bigger disk if you plan to grow, i did that already a yonks ago ;l
Comment: @PeterCordes I do not recommend this configuration because it adds additional complexity into the storage stack. For example, it can be more challenging to expand the zpool. Please note that both I and ewwhite are approaching the problem from an enterprise/supportable angle. For a personal PC with a Steam library, feel free to use whatever setup do you want ;)


How to access web.config key in JavaScript without using .aspx page?

Question: I'm trying to access a web.config key in JavaScript, but don't want to add code to a .aspx file. Here's my code:
Web.config file:
<add key="key" value="password"/>

JavaScript file:
var param = '<%= System.Configuration.ConfigurationManager.AppSettings["key"].ToString() %>';

Thoughts on what could be going wrong?
Thanks!
Comment: Yep, it's under `appSettings`.
Answer: You can not access web.config or any serverside related data from js files directly. You can assign all data you want to access from client on .aspx mester page to window object and then access it in js files.
Answer: Your code looks good, that is exactly how I do it, see below my sample code from my old web.forms project.

And this is the key value in my web.config for my case;
<configuration>
...
<appSettings>
  ...

  <add key="GoogleAnalyticsTrackingEnabled" value="true" />
  ...
</appSettings>
...
</configuration>


ContentPresenter.ContentSource vs Content

Question: Basically, I don't understand what the real difference here is:
The Microsoft code for TabItem uses:
<ContentPresenter ContentSource="Header" ... />

So, when would one use the Content property instead of (or in addition to) ContentSource?
Answer:
This property should only be used when
  the ContentPresenter is in a template.
  When a template contains a
  ContentPresenter with ContentSource
  set to "Abc", the Content,
  ContentTemplate, and
  ContentTemplateSelector properties of
  the ContentPresenter are automatically
  aliased to Abc, AbcTemplate, and
  AbcTemplateSelector, respectively.
  Beginning with the .NET Framework
  version 3.5 Service Pack 1, setting
  ContentSource to "Abc" also causes the
  ContentStringFormat property to be
  aliased to AbcStringFormat.
The two most useful values for this
  property are "Content" and "Header".

(MSDN)
ContentSource apparently sets more properties at once for convenience.

Practically, The declaration:
<ContentPresenter ContentSource="Header" />

Performs the following initialization.
<ContentPresenter Content="{TemplateBinding Header}"
                  ContentTemplate="{TemplateBinding HeaderTemplate}"
                  ContentTemplateSelector="{TemplateBinding HeaderTemplateSelector}"
                  ContentStringFormat="{TemplateBinding HeaderStringFormat}" />

It does this for each property separately only if the dependency property exists on the templated control.
Comment: Man, this explains so much (that the docs don't!) I always wondered why just having a `ContentPresenter` in a template without setting `Content` still worked.  Now I know it's because it *does* set `Content`, just implicitly from this property (along with the others as well.)  They really should update the docs because it's not clear that by 'aliased' they really mean the equivalent of using a `TemplateBinding`. Had they stated that or even mentioned `TemplateBinding`, it would've been so much clearer. Your code example does so perfectly. Bravo!


Mathematical Induction divisibility $8\mid 3^{2n}-1$

Question: So I'm trying to use mathematical induction to show that for all integers $n \ge 1$ ,
$$ 8|(3^{2n} - 1)$$
(is divisible by 8)
I have my base case:
[P(1)],  $3^2 - 1 = 9 - 1 = 8$, since $8|8$, the base case proves true
Assume [P(k)], $ 8 | (3^{2k} - 1)$.
I know that I need to show [P(k+1)], $ 8| (3^{2(k+1)}-1) $, but I'm not sure how to prove this. I've only been using induction for summation, so how could I prove divisibility?
Comment: Try factoring out $3^2=8+1$.
Comment: Note also that $3^{2n}-1=(3^2)^n-1=9^n-1$. Now the claim follows from $a^n-b^n=(a-b)(a^{n-1}+a^{n-2}b+\cdots+b^{n-1})$.
Comment: @Integrator it's correct though the identity in my comment is more elementary than the binomial theorem.
Answer: Hint: Note that:
$$3^{2(n+1)} -1=9\cdot3^{2n}-1=(3^{2n}-1)+8\cdot3^{2n}$$
Comment: $3^{2(n+1)} - 1 = 3^{2n+2} - 1 = 3^{2n}\cdot3^{2} - 1 = 9\cdot 3^{2n} - 1$ $ = (8+1)\cdot 3^{2n} - 1 = 8\cdot 3^{2n} + 1\cdot 3^{2n} - 1 = (3^{2n}-1) + 8\cdot 3^{2n}$
Comment: How did you factor 9*3^(2n) -1 to equal (3^(2n) - 1)+ 8*3^(n)?      (the last part) I don't understand how you were able to set them equal
Comment: so i can make deduction that we assumed that  8|P(k) is true and so 8| 8*3^(2*n) so P(n) is true?
Comment: @talmudist Assumed that $8|P(k)$ is true and show that $8| [P(k+1)=(3^{2k}-1)+8\cdot3^{2k}]=P(k)+8\cdot3^{2k}$ is true, then  P(n) is true?
Comment: from the question ,  yes
Comment: @talmudist Yes, are the steps of a by induction proof.
Answer: Here is an alternative approach to that given by AsdrubalBeltran.
Write $3^{2n}-1$ is base three notations as :
$$3^{2n}-1 = \underbrace{22\dots2_{base 3}}_{2n \text{ times}}$$
Then since $ 8 = 22_3 $, we can see the result at once.  Now use induction on n.
Answer: If you don't mind I'm gonna do some magic
$$3^{2n}=(3^2)^n=(8+1)^n=\binom{n}{o}8^n+\binom{n}{1}8^{n-1}+\cdots+\binom{n}{n-1}8^{1}+\binom{n}{n}8^0$$
$$3^{2n}=\binom{n}{0}8^n+\binom{n}{1}8^{n-1}+\cdots+\binom{n}{n-1}8^{1}+1$$
$$3^{2n}-1=\binom{n}{0}8^n+\binom{n}{1}8^{n-1}+\cdots+\binom{n}{n-1}8=8(k)$$
$$\implies8|(3^{2n} - 1)$$


Pygame pixel perfect collision not working as expected

Question: I am creating tetris using pygame. i want to use collision detection so that when the shape in play comes into contact with any other previously played shapes, i can stop the shape, as per the logic of tetris. i came across pixel perfect collision using masks. i have followed some tutorials online, however the pixel detection returns true every time a new shape comes into play, not when any shapes collide.  sorry in advance for the long code, its the bare minimum for the code to actually and still containing the game element of it. i think there is something wrong with my approach which is causing this error. I basically have a function that everytime the shape in play comes into contact with the 'floor' that shape is held in that position and a new shape is created. i think ive overcomplicated it, in turn creating this error. thanks in advance
import pygame
import sys
import shapelogic

pygame.init()

screensize = width, height = 800, 595

screen = pygame.display.set_mode(screensize)

background_image =pygame.image.load("/Users/marceason/PycharmProjects/Tetris/Wooden_background.jpg").convert_alpha()

myshape = 0
stop_movement = 0
blit_count = 0
stored_shapes = pygame.sprite.Group()
stored_shapes_with_coords = []
extra_blit_required = False

index = 0
count = 0
listofshapes = []

class shapemanager():

    def __init__(self):

        self.listofshapes = []

    def create_another_instance(self):

        global count
        count += 1
        string = "Shape_{0},".format(count)

        another_shape = Shape(string)
        self.listofshapes.append(another_shape)
        global index
        object = self.listofshapes[index]
        index += 1
        return object

def load_shape(self):
    shape = self.create_another_instance()
    shape.load_shapes()

class Shape(pygame.sprite.Sprite):

def __init__(self, name):
    pygame.sprite.Sprite.__init__(self)

    self.name = name
    self.x = 50
    self.y = 100
    self.move_event = pygame.USEREVENT + 1
    self.reached_bottom_event = pygame.USEREVENT + 2
    self.one_sec_timer = 1000
    self.half_sec_timer = 500

    self.reachbottomflag = False
    self.movement_possible = True

    self.image = pygame.image.load(
"/Users/marceason/PycharmProjects/Tetris/Tetris_Shapes/Green_Shape_1_Position_1.png")
    self.mask = pygame.mask.from_surface(self.image)
    self.rect = self.image.get_rect()

def move_shape(self):
    if self.movement_possible:
        key_input = pygame.key.get_pressed()
        if key_input[pygame.K_LEFT]:
            self.x -= 16
        if key_input[pygame.K_RIGHT]:
            self.x += 16
        if not self.reachbottomflag:
            if key_input[pygame.K_DOWN]:
                self.y += 16

def reachbottom(self):

    if self.y >= 560:
        self.reachbottomflag = True

def no_movement_possible(self):

    self.movement_possible = False

def assign_shape():

global myshape
global stop_movement
myshape = sl.create_another_instance()
pygame.time.set_timer(myshape.move_event, myshape.one_sec_timer)
stop_movement = pygame.time.set_timer(myshape.reached_bottom_event, myshape.half_sec_timer)

def blit_used_shapes():

global screen
global blit_count
blit_count = len(stored_shapes_with_coords)
local_count = 0
while local_count < blit_count:
    screen.blit(stored_shapes_with_coords[local_count][0], (stored_shapes_with_coords[local_count][1], stored_shapes_with_coords[local_count][2]))
    local_count += 1

sl = shapemanager()

##### HERE IS THE PIXEL DETECTION #####
result = pygame.sprite.spritecollide(myshape, stored_shapes, False, pygame.sprite.collide_mask)

## Main loop ##

assign_shape()

while True:

for event in pygame.event.get():
    if event.type == pygame.QUIT: sys.exit()
    screen.blit(background_image, (0, 0))
    screen.blit(myshape.image, (myshape.x, myshape.y))
    myshape.move_shape()

    key_input = pygame.key.get_pressed()
    if key_input[pygame.K_SPACE]:
        myshape.rotate_shape()

    myshape.reachbottom()
    if myshape.reachbottomflag:
        if event.type == myshape.reached_bottom_event:
            myshape.no_movement_possible()
            stored_shape_tuple = [myshape.image, myshape.x, myshape.y]
            stored_shapes_with_coords.append(stored_shape_tuple)
            stored_shapes.add(myshape)

            extra_blit_required = True

            assign_shape()
            ####### PIXEL DETECTION IS HERE IN FOR LOOP ####
            if result:
                print("this should only execute when two shapes touch!!")

    if extra_blit_required:
        blit_used_shapes()

    pygame.display.update()

Comment: why to use perfect collision for squares ? It is only waste of time.
Comment: you should use `print()` to check values in variables - it is called `print debuging`. OR learn how to use real debuger. Maybe it checks collision with different elements then you expect and this gives always `True`.  Sometimes people use `.x`, `.y` to move object but they forgot that pygame uses `.rect` to check collision and they forgot to change `.rect.x`, `.rect.y`. You should use only `.rect.x` and `.rect.y` to move and draw it `blit(shape.image, shape.rect)`
Comment: BTW: instead of checking `self.x >= 560` you could check `self.rect.bottom >= 595` (widow's height)
Comment: BTW: if you use classes then instead of global `index`, `count` you could  use `self.index` and `self.count`
Comment: your code has wrong indentations so it is useless - we can't run it. Always put code with correct indentations and use button `{}` or shortcut `Ctrl+K` to format it in question.
Comment: BTW: to make code more readagle put all classes and function before `pygame.init()` - see more [PEP 8 -- Style Guide for Python Code](https://www.python.org/dev/peps/pep-0008/)
Comment: Thanks for the comments furas. I will take note for next time
Answer: The issue is that you are not updating the sprites rect attribute. The sprites rects all have position (0, 0) (since you do not set it in the call to self.image.get_rect()) and as a result the masks will all overlap and collide.
If you read the docs for pygame.sprite.collide_mask you will note that it says that your sprites need to have mask and rect attributes. You have a rect in your sprite and you set it in the __init__(), but you do not keep it updated when you move the sprite. You just change the x and y attributes without adjusting the rect position. The reason that the collide_mask wants a rect is that it uses that to determine the offset parameter for the pygame.mask.Mask.overlap() call that it uses. The important thing to realize is that masks themselves do not have a position, they need the rects to determine the relative positions of the masks.
This is similar to images/surfaces not having a position and needing a rect to track that for them.
On a separate issue, the way you are blit'ing the sprites to the screen makes no sense. You are not using the abilities of the sprite groups to draw and worse you are keeping the image, x and y of the sprite in a separate list and not containing it in the sprite itself. You should go look at some examples of pygame sprite based code. There are lots of examples out there.
Comment: @Pyson The rect is also used to simplify the collision. Doing a mask-based collision is a relatively expensive operation, so the rects are first checked to see if they collide.  If the rect's do not collide, then there is not even a  need to check the masks.
Comment: Thanks for this detailed answer, you have helped me understand masks a little bit more.i have amended the code as to update rects and have changed the way images are blitted to the screen (using a for loop through the sprite group ). the funny thing is now the collision NEVER activates.....


MongoDB Locking - Very, very, slow to read

Question: This is the output from db.currentOp():
> db.currentOp()
{
    "inprog" : [
        {
            "opid" : 2153,
            "active" : false,
            "op" : "update",
            "ns" : "",
            "query" : {
                "name" : "Run_KPIS",
                "profile" : "totals"
            },
            "client" : ":34140",
            "desc" : "conn127",
            "threadId" : "0x7f1d0f03c700",
            "connectionId" : 127,
            "locks" : {
                "^cached_data" : "W"
            },
            "waitingForLock" : true,
            "numYields" : 0,
            "lockStats" : {
                "timeLockedMicros" : {

                },
                "timeAcquiringMicros" : {

                }
            }
        },
        {
            "opid" : 2154,
            "active" : false,
            "op" : "getmore",
            "ns" : "",
            "query" : {

            },
            "client" : ":34129",
            "desc" : "conn118",
            "threadId" : "0x7f1e32785700",
            "connectionId" : 118,
            "locks" : {
                "^cached_data" : "R"
            },
            "waitingForLock" : true,
            "numYields" : 0,
            "lockStats" : {
                "timeLockedMicros" : {

                },
                "timeAcquiringMicros" : {

                }
            }
        },
        {
            "opid" : 1751,
            "active" : true,
            "secs_running" : 98,
            "op" : "query",
            "ns" : "cached_data.webtraffic",
            "query" : {
                "mapreduce" : "webtraffic",
                "map" : function () {
        if (this.Pages)
            for (var i in this.Pages)
                if (i.match(/(\/blogs\/|\/news\/)/))
                    emit({
                        'page':i,
                        'profile':this.Profile
                    },this.Pages[i]);
    },
                "reduce" : function (k,vals) {
        for(var i=0,sum=0;i<vals.length;sum+=vals[i++]);
        return sum;
    },
                "out" : {
                    "inline" : 1
                },
                "query" : {
                    "$or" : [
                        {
                            "Profile" : "MEMBER"
                        },
                        {
                            "Profile" : "WEB"
                        }
                    ]
                }
            },
            "client" : ":34111",
            "desc" : "conn112",
            "threadId" : "0x7f1d1768d700",
            "connectionId" : 112,
            "locks" : {
                "^" : "r",
                "^cached_data" : "R"
            },
            "waitingForLock" : false,
            "msg" : "m/r: (1/3) emit phase M/R: (1/3) Emit Progress: 801/830 96%",
            "progress" : {
                "done" : 801,
                "total" : 830
            },
            "numYields" : 148,
            "lockStats" : {
                "timeLockedMicros" : {
                    "r" : NumberLong(183690739),
                    "w" : NumberLong(0)
                },
                "timeAcquiringMicros" : {
                    "r" : NumberLong(92296403),
                    "w" : NumberLong(0)
                }
            }
        }
    ]
}

I have indexes on all the relevant collections, yet there is still a huge delay in reading from our MongoDB when the above operations are running.
It can take ~5 minutes before the database is readable again.
Would the above map reduce function be causing this read lock? And if so how can I run a non-locking map reduce on the collection?
What is strange is that MongoDB still accepts connections, it just won't allow us to query whilst the above operations are running.
Edited to say this is Mongo version 2.4.1.
Answer: First of all, there is the query being run here.  It uses the $or operator over two values of the same field.  If that is typical, change that to the $in operator (as recommended here).  That should help significantly - when you use $or like that you are running two queries in parallel and merging the results, when you use in you do a single query.
Next, since this is an inline Map Reduce job, I would recommend running this on a secondary (if you are not already) and have any applications with a more real-time requirement run elsewhere.  You can do this in a variety of ways, but the most flexible is tag based read preferences.
In terms of interpreting the currentOp() output, the capital letters represent global locks and that is the what is likely holding things up (though it will try to yield), you can also see that it spent a lot of time trying to acquire the lock in the first place.  I assume that this represents a large table scan of the data in question and that the data does not all fit in RAM and is being paged in from disk.  Hence the number of yields for that query (MongoDB will try to yield whenever it sees a fault to disk).
Take a look at the page faults metrics in MMS or mongostat to see the trend there, in fact MMS would be a good place to get a picture of what is going on over time on this instance overall.
The changes in terms of $in above should help a bit on this, but may only kick the can down the road.  If you are going to be doing aggregations across large amounts of data, it either needs to be in RAM where this kind of thing is fast, or you need to get it onto a secondary so that the slow disk access does not drag everything down with it.


Implementing a Highly Available backend gateway for a cloud app on AWS

Question: I have 2 EIPs allocated for a cloud app, which are used in round robin DNS. I'd like to have some sort of high availability mode for our 2 gateways (proxies) which are associated with those EIPs, so I was thinking to have a gateway in each of the 3 AWS availability zones and stick 2 NLBs in front of them: EIP 1 is attached to NLB 1, which round robins across Gateway A and Gateway C and EIP 2 is attached to NLB 2, which round robins across Gateway B and Gateway C.
According to the docs (see NLB section):

Network Load Balancer automatically provides a static IP per
  Availability Zone to the load balancer and also enables assigning an
  Elastic IP to the load balancer per Availability Zone.

From this, I gather that an NLB can only associate an EIP with an availability zone, which makes me think that I can't use it for my setup. Is this correct?
What alternatives would I have, assuming that I want the 3 Gateway instances (one being redundant) and I'd like each of them to be in a separate availability zone?
Answer: It turns out that NLBs can be used in this scenario because they now support Cross-Zone Load Balancing.
NLBs offer builtin High Availability and they are designed to not go down when a whole Availability Zone is impacted, so I decided it's sufficient to use a single instance. Since an EIP can only be associated with a single Availability Zone, I ended up with the following setup:

2 public EIPs allocated, which are used in round robin DNS
one NLB set up to associate EIP_1 with AZ_a and EIP2 with AZ_b
4 gateway instances, 2 being deployed in AZ_a and 2 in AZ_b, and associated with the NLB's target group

This setup ensures that each instance takes 25% of the traffic in normal situations and, by enabling cross-zone load balancing on the NLB, we can tolerate one AZ going down, since the NLB will just forward all the traffic to the remaining two gateways in the other healthy AZ. Note that regional data transfer charges may apply when cross-zone load balancing is enabled. See the documentation for details.


Different CDF Notations

Question: I understand that $F_X(x)$ is the CDF of the random variable X and $F_Y(y)$ is the CDF of the random variable Y.
What do these mean?
1. $F_X(y)$
2. $F_X(X)$
3. $F_x(Y)$
Comment: In 3., do you mean $F_X$? $F_x$ is not defined in your question.
Answer: $F_X(y)$ is the value of $P\{X \leq y\}$, the probability that $X$ is no larger than the real number $y$.
$F_X(X)$ is a function of the random variable $X$ and is thus also a random
variable; call it $Z$.  It is an interesting fact that if $F_X(x)$ is a
continuous strictly increasing function of $x$, then
$Z$ is a uniformly
distributed random variable on the interval $(0,1)$.
$F_x(Y)$ is a function of the random variable $Y$ and thus also a random
variable but you have not provided a definition of the function $F_x$
and so there is not much more that can be said. Perhaps you meant
$F_X(Y)$? Well, there is not much more that can be said except that $F_X(Y)$
also takes on values in $(0,1)$ or $[0,1)$ or $(0,1]$ or $[0,1]$ depending
on what the function $F_X$ looks like.
Comment: It is incorrect to state that $F_X(X)$ is uniformly distributed on $(0,1)$. See the case of a Poisson random variable as a counter-example. It only happens when $F_X$ is invertible, i.e., when $F_X^{-1}$ exists.
Comment: @Xi'an Thanks for pointing out that out. I had forgotten to include this restriction. I have edited my answer.
Answer: $F_X$ and $F_Y$ are just short names that refer to mathematical expressions. You can pretty much always plug a number into an expression, even if doing so doesn't make sense. The meaning of the expression doesn't say anything about what you can plug into it.*
$F_X$ describes the distribution of $X$. It's also just a function like any other; it just happens to be associated with $X$. Think of another example: given the perimeter of a circle (denoted $p_C$), you can compute the area with the function
$$
a_C{\left(p_C\right)} = \pi \left(\frac{p_C}{2\pi}\right)^2 = \frac{p_C^2}{4\pi}
$$
And you can compute the area of a square from the perimeter (denoted $p_S$) with
$$
a_S{\left(p_S\right)} = \left(\frac{p_S}{4}\right)^2 = \frac{p_s^2}{16}
$$
In these expressions $p_C$ and $p_S$ are really just placeholders. They could just as easily have been called $\aleph$ and $\beth$. Using $p_C$ and $p_S$ just makes it clear that the intended inputs are the perimeter of a circle and the perimeter of a square, respectively.
The thing is that you can't get too hung up on those placeholders. $a_C{\left(\cdot\right)}$ is only meaningful when $\cdot$ is the perimeter of a circle. But it always has a value, whether $\cdot$ is the perimeter of a square, the speed of light, or the number of words in this answer.
*This isn't always true, but it is close enough to true that you can use it to fix the idea.

So to answer the first question: $F_X(y)$ is the expression denoted $F_X$ (which just happens to be the CDF of $X$) evaluated at some value $y$.
The second question has an added level of complexity. It is conventional to use capital letters ($X$) to refer to random variables, and lower-case letters ($x$) to refer to realizations of random variables. Realizations are just numbers, so $F_X(x)$ is just a number (in this case, a probability). But the result of applying a function to a random variable, as in $F_X(X)$, is actually another random variable. The distinction is easy to see if you define $U = F_X(X)$. $U$ is a random variable, and every realization $u$ is equal to some $F_X(x)$. So $F_X(X)$ is the random variable produced by applying $F_X$ to $X$.
The same principle applies to the third question. $F_X(Y)$ is the random variable produced by applying $F_X$ to $Y$. All the stuff up there about squares and circles applies in this case, too.
Incidentally, my first ever question on this site was about the distribution of $F_X(X)$.

Different CDF Notations


Lilypond: How to engrave lowercase chord symbols

Question: My goal is to engrave music for accordion and I would like to have my chords symbols as follows:
Bass tone: always uppercase: e.g. A E D
Chords: always lower case:
e.g. major chords a e d; minor chords am em dm
And together: A am E e D d7
In Lilypond you can force the lowercase only for the minors: \set chordNameLowercaseMinor = ##t
But I would like to have this possibility for the majors, sevens etc. as well...The bass tone is always uppercase, which is fine.
Comment: You can probably achieve something by overriding chordRootNamer and chordNoteNamer. Can you create a small snippet to show how you want to encode it with lilypond ?
Comment: Is this a standard chord format for accordian music? Lead sheets typically follow the guitar chord convention of using upper case for the primary note of the chord, followed by a combination of #, b (flat), m (minor), aug (augmented), maj (major), dim (diminished) etc, and then if an inversion is to be applied, a forward slash and the bass note. For example, D/F# would be first inversion of D, i.e. an F# bass tone with a D chord. This is easy to achieve in Lilypond as is the default behaviour for chords.
Answer: (This was asked and answered elsewhere, but in case it helps any future visitors, I'll add their results.)
Fix #1
\version "2.19.58"

\layout {
  \context {
    \Score
    chordNoteNamer = #note-name->markup
    chordRootNamer =
      #(lambda (pitch lowercase?) (note-name->markup pitch #t))
  }
}

\new ChordNames \chordmode { c:7 c:m7 c:7/+c c:m7/+c }

But this one has some problems with single bass pitch inputs, resulting in
Fix #2
\version "2.19.58"

#(define-public (my-note-name->german-markup pitch lowercase?)
  (let* ((name (ly:pitch-notename pitch))
         (alt-semitones (inexact->exact (round (* (ly:pitch-alteration
pitch) 2))))
         (n-a (if (member (cons name alt-semitones) `((6 . -1) (6 . -2)))
                  (cons 7 (+ 1 alt-semitones))
                  (cons name alt-semitones)))
         (basic-list '("c" "d" "e" "f" "g" "a" "h" "b"))
         (list-to-use
           (if lowercase?
               basic-list
               (map string-upcase basic-list))))

    (make-line-markup
     (list
      (string-append
       (list-ref list-to-use (car n-a))
       (if (or (equal? (car n-a) 2) (equal? (car n-a) 5))
           (list-ref '( "ses" "s" "" "is" "isis") (+ 2 (cdr n-a)))
           (list-ref '("eses" "es" "" "is" "isis") (+ 2 (cdr n-a)))))))))

\layout {
  \context {
    \Score
    chordNameFunction =
      #(lambda (in-pitches bass inversion context)
        (if (= (length in-pitches) 1)
            (my-note-name->german-markup (car in-pitches) #f)
            (ignatzek-chord-names
              in-pitches bass inversion context)))
    chordNoteNamer =
      #(lambda (pitch lowercase?)
      (my-note-name->german-markup pitch #f))
    chordRootNamer =
      #(lambda (pitch lowercase?)
      (my-note-name->german-markup pitch #t))
  }
}

\new ChordNames \chordmode { cis:7 cis:m7 c:7/+c c:m7/+c <ces> cis:1 }

This allows for single pitch inputs as <c> and c:1. Note that this latter example uses German notation, which one can adjust as necessary in the Scheme code.


What does it mean to call something "Naive" in mathematics?

Question: I've seen the term "naive" come up repeatedly in mathematics textbooks and lectures without any knowledge of what it indicates.
There is always the dictionary definition, but my impression of the word based on how I've seen it used is that it's similar to "trivial," where it has connotations in mathematics that differ significantly from those in natural language, even if it doesn't have a formal definition as such.
Can anyone who's spent more time immersed in the jargon of mathematics give me an impression of what naive means in this context?
Comment: I don't agree with the proposed synonyms.  Rather,  I think it means  something like "trusting that technical considerations don't get in the way".  Thus "naive arguments" need not be technically correct, as details are neglected.    Indeed, naive arguments may lead to false conclusions.
Comment: It should also be emphasized that "naive" in the quasi-technical sense @lulu describes is generally _not_ a pejorative term. It carries an undertone of "it's entirely reasonable to _attempt_ to do things this way at first, hoping that the technicalities will work out eventually, and it takes a nontrivial amount of thought to discover that they actually don't".
Comment: I would say that "naive" refers to what is usually the easiest approach, the one that takes the least effort to attempt, or the one that doesn't take into account the potential intricacies that are revealed by a more careful study of the question.
Comment: Welcome to Mathematics Stack Exchange.  Cf. [this](https://en.wikipedia.org/wiki/Naive_set_theory)
Comment: Naïve is used when one lets one's intuition become more important than their rigour - applying theorems where the theorem is not defined or assuming the "obvious" when the reality is more subtle, etc.
Comment: To support @Troposphere's point, note that a very well-loved book by the great Paul Halmos is called *Naive Set Theory*.
Comment: It's pretty much always "obvious" or "natural."
Answer: Among other uses, there are two quite specific uses that have become almost formalized themselves: "naive set theory" and "naive category theory". For naive set theory, it means not axiomatized, and not worrying too much about potential paradoxes (such as "the set of all sets that do not contain themselves as elements"), but focusing more on the positive possibilities. Similarly, beginning several decades later, "naive category theory" (a less universal convention) again avoids too much concern for foundations, either from set theory (Grothendieck universes, large cardinals, ...?!?), or more innately category-theoretic, as from Lawvere et al.
There is also a related-but-different "naivete", of physicists' computations that mathematicians could only genuinely justify after Schwartz and Grothendieck, using distributions and function-valued and operator-valued functions, etc. In these cases, in the happy outcomes, the computations could eventually be justified (and had matched physical facts all along!), but required much-more-sophisticated viewpoints to achieve the justification, or even to understand what might go wrong... but doesn't :)
Comment: (+1) ... but beware that "Naive Set Theory" is _also_ the title of an influential textbook by Paul Halmos, which does _not_ present the kind of "naive set theory" this answer describes.
Comment: @Troposphere, ha! Indeed! Tho' I'd claim that the Halmos book hijacks the sense of the phrase. :)  And, yes, certainly, there are _degrees_ of formalization of the language, of the meta-language, etc.
Comment: @RobArthan, ... :)
Comment: How an earth could Halmos have "hijacked" this term? Do you have relevant references for the use of the term before the publication of his book?
Comment: @RobArthan, my main point is that the popularity of his book "took over" the sense of the phrase. Indeed, I do not offhand know of prior use! And, as well, in my abstract algebra book (also on-line) I use that phrase somewhat similarly to Halmos' use, since I wanted to make an accurate reference. But certainly this usage is "less naive" than Cantor's, and less than many sources prior to the 1950s. Specifically, few parts of mathematics had felt a need to specify first-order logic, etc., as a language, nor explicitly specifying any meta-language at all.
Comment: Thanks for the explanation. Perhaps we can agree to say that Halmos "commandeered" or "pioneered" the use of the word "naive" in "naive set theory" and leave it there. $\ddot{\smile}$.