How to get a notification when user is blocked following flood

Question: I'm trying to get an email sent to me every time an account is banned following a flood (5 tries).
Unfortunately, a user that is blocked isn't set to "status = 0", so I cannot use a rule based on user status. I did a few search and couldn't find Rules integration with the Flood Module.
Is it part of the core? Is there anything other way to provide Rules integration with Flood?
Answer: Yes, Flood is part of core (it lives in includes/common.inc, and because Rules is a contrib module, there is no set way to integrate cleanly in Drupal 7.
The one thing you might be able to do is to do a form_alter() on functions like user_login_final_validate($form, &$form_state), since if a flood event has been triggered they will include a form value such as $form_state['flood_control_triggered'] which, when it is not empty, will indicate that a login attempt has been blocked. Then of course your custom form_alter implementation can call any Rules events it likes.
This is totally untested so I can't verify that it would work, but for now there doesn't seem to be an easy or clean way to do this in D7.


Confidence Intervals in k-fold Cross Validation and Bootstrap

Question: I'm searching for the best parameters of a classifier and I chose as comparison criterion the value of the specificity at 90% sensitivity (there are various reasons behind this choice). To assess the variability of the estimate I normally used a 10-fold Cross Validation, but having a highly unbalanced dataset, I feel that I was over-estimating the variance of my measures so I'm deciding to switch to Bootstrap (.632+ method). To calculate Confidence Intervals of my 10-fold Cross Validation results I used the classical formula
CI = [mean(spec) +/- t * std(spec) / sqrt(N)]

where spec are the 10 specificity values @ 90% sensitivity, N=10 and t is the critical value of Student's t distribution for alpha=0.05 and d.o.f.=9. mean and std are the sample mean and standard deviation of the 10 estimates.
My questions are:

is it correct to use this formula to calculate Confidence Intervals?
can I use it also for Boostrap estimates? And if not, why?

My second question arises from the fact that a lot of sources I checked suggest another formula, the "Basic Bootstrap" at the following Wikipedia link: https://en.wikipedia.org/wiki/Bootstrapping_(statistics)#Methods_for_bootstrap_confidence_intervals
Thanks!
Answer: I'm assuming the notation of mean(spec) and sd(spec) refers to the notation of empirical means and SDs of the bootstrapped spec distribution. Is that correct? If so, unfortunately, that is not the correct way to calculate confidence intervals for the bootstrap (or for any other resampling based statistics) when the actual distribution under the null is not normal. The main strength of the bootstrap is the belief that it is robust to these types of distributional assumptions. The correct methods to calculate bootstraps for the general quantities have been discussed elsewhere on the site. The boot package has options to generate student, BCa, and percentile bootstrap confidence intervals. All of these are superior to normal approximations.
Comment: Yes, your assumptions were correct. Is the above formula instead always valid for k-fold Cross Validation? If I were sure that my statistic follows a normal distribution could I use it? I'm asking because with a high number of resamplings the denominator gets pretty big. Thank you for your help!
Comment: @Marco you should use the approach which is correct even if it is computationally expensive. You never actually know if a statistic actually follows a normal distribution or not.


Prove that $\sum_{n=1}^{\infty} (\frac{\ln x}{x})^n$ converge uniformly

Question: How to prove that $\sum_{n=1}^{\infty} (\frac{\ln x}{x})^n$ is uniformly convergent for $ x \in [1,+\infty)$, I tried the Weierstrass M-test but it doesn't work. Is there another way to prove this?
Comment: Why you don't try the root test?
Answer: Observe
\begin{align}
\log x \leq
\begin{cases}
x-1 & \text{ if } 1 \leq x \leq 2\\
\frac{1}{2}x & \text{ if } x> 2
\end{cases}
\end{align}
which means
\begin{align}
\frac{\log x}{x} \leq \frac{1}{2}
\end{align}
for all $x\geq 1$. Then it follows
\begin{align}
\sum^\infty_{n=1}\left(\frac{\log x}{x}\right)^n \leq \sum^\infty_{n=1}\frac{1}{2^n}.
\end{align}
Answer: If you consider $$f(x)=\frac{\log(x)} x\implies f'(x)=\frac{1-\log (x)}{x^2}\implies f''(x)= \frac{2 \log (x)-3}{x^3}$$ So,$f'(x)=0$ if $x=e$ and this a maximum (by the second derivative test). So, for $x \in [1,+\infty)$, $f(x)\leq \frac 1 e$.
Then,  for any $x \in [1,+\infty)$,
$$\begin{align}
\sum^\infty_{n=1}\left(\frac{\log x}{x}\right)^n \lt \sum^\infty_{n=1}\frac{1}{e^n}=\frac{1}{e-1}
\end{align}$$


Change a function to component React

Question: I'm new at React and I created a project where I'm using two functions which are defined inside the main component. I was wondering how I could change the functions into components.
Those are the two functions I'm trying to change into components:
function AnswerFrame(props) {

  var selectedNumbers = props.selectedNumbers.map(function(i) {
    return {i};
  });

  return (

{selectedNumbers}

  );
}

function NumbersFrame(props) {
  var selectNumber = props.selectNumber,
    usedNumbers = props.usedNumbers,
    selectedNumbers = props.selectedNumbers,
    numbers = [],
    className = null;

  for (var i = 1; i <= 9; i++) {
    className = "number selected-" + (selectedNumbers.indexOf(i) >= 0);
    className += " used-" + (usedNumbers.indexOf(i) >= 0);
    numbers.push(

        {i}

    );
  }

  return (

{numbers}

  );
}

I've changed the both to components following the structure of one of the answers
import React, { Component } from 'react'; import '../App.css';

export default class NumbersFrame extends Component{

constructor(props) {
        super(props);
    }

render(){

var selectNumber = this.props.selectNumber,
    usedNumbers = this.props.usedNumbers,
    selectedNumbers =  this.props.selectedNumbers,
    numbers = [],
    className = null;

  for (var i=1; i <=9; i++){
    className = "number selected-" + (selectedNumbers.indexOf(i)>=0);
    className += " used-" + (usedNumbers.indexOf(i)>=0);
    numbers.push(

          {i}

      )
     }

  return(

          {numbers}

      );
 }

}
class AnswerFrame extends React {

  constructor(props) {
        super(props);
  }

  render() {

  var selectedNumbers = this.props.selectedNumbers.map(function(i){
    return(

        {i}

    )
  });

  return(

        {selectedNumbers}

  );

}

After using both Components I'm getting the following error in the AnwserFrame component:
TypeError: Cannot read property 'props' of undefined
in the line

I think it is because before I was using the function with the props as a parameter and now when I change to a component, the props are undefined.
Any idea about how I could handle that error before with the functions it was working well.
Comment: Since both the functional components doesn't play with state so I would recommend you to keep them remain as stateless component
Comment: I'm confused. Do it the same way you did the other functions that are components.
Comment: Try logging the props from the constructor: `constructor(props) { super(props); console.log("My Component", props)}`, to see whether you get the props. Also I'm sure that you still need to pass the props like usual: ``
Comment: If I change to that, I'll get the following:

My Component
{selectedNumbers: Array(4)}
selectedNumbers: (4) [1, 2, 3, 4]
__proto__: Object
Answer: Both are Components in themselves, called functional components.
If you need to convert it into class components here is a sample for one,
class AnswerFrame extends React.Component{
    render(){

    var selectedNumbers = this.props.selectedNumbers.map(function(i){
      return(

          {i}

        )
    });

    return(

          {selectedNumbers}

      );

}

Change a function to component React


O que são e quais são as principais diferenças entre Programação Funcional e Programação Reativa?

Question: Queria uma explicação de forma clara e objetiva?
Li casos separados, mas queria saber os principais pontos que diferenciam os dois
Comment: https://pt.stackoverflow.com/tags/programa%C3%A7%C3%A3o-funcional/info e https://pt.stackoverflow.com/questions/55332/o-que-%C3%A9-reactive-programming-programa%C3%A7%C3%A3o-reativa, o que não entendeu mais exatamente?
Comment: A resposta resolveu o que estava em dúvida? Precisa que algo mais seja melhorado? Acha que é possível aceitá-la agora?
Answer: É complicado responder isso porque é como perguntar quais as diferenças entre laranjas e beterrabas. É, ambos são de comer, acabou.
Programação funcional é algo que tem como base o uso de funções para expressar código, que limitam a mudança de estado, ou seja é uma paradigma mesmo. E, ao contrário do que muita gente pensa, não é só usar função, tem uma série de critérios. E funcional muito menos é o que usa função e procedural é o que usa procedimentos.
A programação reativa é um estilo de organização do código, não é um paradigma (embora alguns classifique como se fosse), por isso podem ser usados juntos, é como usar a laranja para dar um sabor na beterraba. Programação reativa tem até mais a ver com arquitetura, com a forma como os dados são manipulados pela aplicação e como ela reage a eles. A linguagem ou código pode até ajudar fazer isso de forma mais simples.
De forma clara e objetiva é melhor aprender o que é cada um em isolado porque elas só se relacional por acaso, e não se antagonizam. Os links estão acima.
Coloquei no GitHub para referência futura.


Javascript: how to add an element to an object if it not exist

Question: Javascript: how to add an element to an object if it not exist
I would like to populate the object as I did with the array
(if is not present add to it)

// push : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push

let items = ['aa','xx'];

function newList(item) {

 if (items.indexOf(item) === -1) {
  items.push(item);
 }
 return console.log(items)

}

newList('aa');
newList('bb');
newList('aa');

// how i can do the same with this object?

let itemsObj =
[
 {id: 'Id AA', name: 'Name AA'},
 {id: 'Id BB', name: 'Name BB'},
 {id: 'Id CC', name: 'Name CC'},
 {id: 'Id DD', name: 'Name DD'},
 {id: 'Id EE', name: 'Name EE'},

];

let newItemA = {id: 'Id XX', name: 'Name XX'};
let newItemB = {id: 'Id AA', name: 'Name AA'};

// TODO
Comment: Are you trying to add to an existing object if the key is not already present? For example, adding `name` if not defined?
Answer: You can use "Array.reduce" and "Array.from" to achieve this with the help of "Sets"

let itemsObj =
[
 {id: 'Id AA', name: 'Name AA'},
 {id: 'Id BB', name: 'Name BB'},
 {id: 'Id CC', name: 'Name CC'},
 {id: 'Id DD', name: 'Name DD'},
 {id: 'Id EE', name: 'Name EE'},

];

let newItemA = {id: 'Id XX', name: 'Name XX'};
let newItemB = {id: 'Id AA', name: 'Name AA'};

function addItem(item) {
  return Array.from(
            (itemsObj.concat(item)).reduce((s, d) => s.add(JSON.stringify(d)) , new Set)
            , (d) => JSON.parse(d))
}

console.log(addItem(newItemA))

console.log(addItem(newItemB))
Comment: your solution works fine thanks
Comment: Great your issue is resolved!!


Como passar um array como argumento de uma função por cópia?

Question: Como sabemos um array é usado como um ponteiro em diversas situações. Um parâmetro que espera um array na verdade é um ponteiro, então o que copia é o endereço de memória e não os dados do array, é uma passagem da referência.
Mas e se eu quiser passar os dados mesmo? Eu sei o tamanho do array e que ele será pequeno, eu tenho certeza que ele será mais eficiente copiando. Como eu faço?
Answer: Realmente há essa limitação, mas ao mesmo tempo C é uma linguagem muito inteligente e fornece um truque como solução. Alguns dirão que é gambiarra, outros dirão que é uma boa forma de tornar tudo simples e favorecer o uso padrão, dando a chance da exceção ser expressada de uma forma que dá um pouco mais de trabalho e o normal (passar array por referência) ser expressado de forma simples.
Mas antes de fazer tenha certeza que o tamanho é adequado. Dependendo de quem estiver dizendo colocará um limite de 4, 8 ou 16 bytes para compensar fazer a cópia. Minha experiência é que 32 ou 64 bytes pode ser interessante, dependendo da arquitetura usada. Mas não torne isso um padrão quando o tamanho permite. A cópia deve ser usada se for a semântica correta para o caso.
A única forma de passar um dado de um tipo não escalar (composto) por valor é quando usa uma estrutura. Por padrão struct é copiado e só se usar um ponteiro é que ela se transforma em referência. Então a solução é encapsular o array dentro de uma estrutura.
Isso traz algumas vantagens extras já que cria uma abstração e não precisa se preocupar com o tamanho do array. Já vi gente usando essa técnica mesmo que depois acabe passando a estrutura por referência, só para não ter que ficar informando o tamanho do array em todo lugar do código já que ele tem uma forma canônica do tamanho. Obviamente que qualquer tamanho diferente precisará de uma estrutura diferente.
Alguém pode pensar que isso gera um custo para a aplicação, mas não gera. Não ocupa um byte a mais, nem gasta um ciclo a mais para processar. Claro que existe a diferença de estar copiando o dado e não o ponteiro, isso pode dar alguma diferença e é sua obrigação escolher a mais correta para sua situação.
#include <stdio.h>

typedef struct {
    char array[16];
} Tipo;

void funcao(Tipo p) {
    printf("%zd\n", sizeof(p));
    printf("%s", p.array);
}

int main(void) {
    Tipo dado = { .array = "teste de array" };
    funcao(dado);
}

Veja funcionando no ideone. E no repl.it. Também coloquei no GitHub para referência futura.
Answer: Em c++ é só usar std::vector e passar como parâmetro :
void foo(vector<int> v) { ... }  // aqui v é copiado
int main () {
  vector x = {1, 2, 3, 4, 5};
  foo(x);
}

Comment: A pergunta é sobre array.
Comment: Sim, e toda vez q aparece "array" e "C++" junto nas tags, temos q lembrar que o std::vector existe
Comment: Não quando o objetivo é usar um *array*. Eu sempre lembro que tem o `vector` quando o objetivo é usar uma coleção de dados, essa pergunta é especificamente sobre o mecanismo de *array*.
Comment: Normalmente também falo do std::array que é uma implementação padrão desse encapsulamento, mas tem um monte de vantagens   https://ideone.com/KpAJXv


Logit model intercept use

Question: I want to estimate a Logit model where the independent variables are binary and one of them is categorical, so the whole data set consists of dummy variables.
First of all, I am puzzled whether I should include an intercept in my model.
Secondly, if both options are possible, how does it affect the interpretation of the coefficients?
And does it affect whether I need to choose a reference group or not?
Comment: Also:  https://stats.stackexchange.com/questions/260209/the-difference-between-with-or-without-intercept-model-in-logistic-regression/260214#260214
Answer: You definitely need the intercept.  Say you have two binary $X$'s and a binary $Y$. Without the intercept, your model is
$\log(p/(1-p)) = \beta_1 X_1 + \beta_2 X_2$.
When both $X$'s are at their reference levels, you get
$\log(p/(1-p)) = \beta_1 0 + \beta_2 0 = 0$.
This implies that $p = 0.5$ when both of your independent variables are at their reference levels. So unless you have  super strong rationale for forcing a 0.5 probability on "success" for your dependent variable when your independent variables are at their reference levels, you should include the intercept in your model.
(On the other hand, if you do not "leave one out" in your modeling of the dummy and categorical $X$ variables, then you need to exclude the intercept to avoid a perfect multicollinearity. In this case the problem noted above vanishes.)
Comment: thank you for the reply! It makes perfect sense

Logit model intercept use


reload table view after modal view dismissal

Question: I've looked at a lot of other questions on this subject. But they all lead to the same thing "view did load" "view did appear" and  "view will appear" and Ive put
tableview.reloadData()

in all of them but after dismissal of the modal view it still doesn't reload till I terminate the app and then I run again. I have seen that you can do this with notification center and have seen that Here and I tried that method but it didn't seem to work for me.
Thanks for any Help in advance!!!
import UIKit

class mainScreen: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var tableview: UITableView!

func numberOfSections(in tableView: UITableView) -> Int {
    return 1
}
// MARK: - Table View Setup
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    if allPeople.count == theAssignments.count {
        return allPeople.count
    }else {
        print("else in number of rows in section BAD")
        return allPeople.count
    }
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "PeopleTVCell", for: indexPath)
    cell.textLabel?.text = theAssignments[indexPath.row]
    cell.detailTextLabel?.text = allPeople[indexPath.row]
    return cell
}
// MARK: - System setup
override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view, typically from a nib.
    tableview.allowsSelection = false
    /////////here
    tableview.reloadData()
}
override func viewWillAppear(_ animated: Bool) {
    ////////here
    tableview.reloadData()
}

override func viewDidAppear(_ animated: Bool) {

    let NamesObject = UserDefaults.standard.object(forKey: "Name" + whatGroup)

    if let tempItems = NamesObject as? [String] {

        allPeople = tempItems

        print("saved data in main (Name)")
    }
    let AssignmentObject = UserDefaults.standard.object(forKey: whatGroup + "Assignment")

    if let tempItems = AssignmentObject as? [String] {

        theAssignments = tempItems

        print("saved data in main (Assignments)")
    }
    ////////here
    tableview.reloadData()
}
// MARK: - the Exit Segue
@IBAction func exitSegue(segue: UIStoryboardSegue) {
    /////////here
    tableview.reloadData()
    isAddingName = 2
    print("Exited to main")
}

}

this is where I would add things
@IBAction func saveButton(_ sender: UIButton) {
    if isInMain == true {

        if IsAddingAssignment == true {
// MARK: Add Assignment
            let AssignmentObject = UserDefaults.standard.object(forKey: whatGroup + "Assignment")  as? [String]

            var Assignment: [String]

            if let tempItems = AssignmentObject {

                Assignment = tempItems

                Assignment.append("\(EnteredObjectTextFeild.text!)")

                print(Assignment)

            } else {

                Assignment = [EnteredObjectTextFeild.text!]
                print("user defaults error 2")
            }

            UserDefaults.standard.set(Assignment, forKey: whatGroup + "Assignment")

            EnteredObjectTextFeild.text = ""
        }else {
// MARK: Add Name
            if AllNames.contains("\(EnteredObjectTextFeild.text!)"){
                if namesForEachGroup.contains(EnteredObjectTextFeild.text!) {
                    EnteredObjectTextFeild.text = ""
                    AlertAction(Title: "Name Exists", Message: "This name already exists in this group", alerTitle: "OK")
                }else {
                    addNameToGroup()
                    EnteredObjectTextFeild.text = ""
                }
            }else {
                let NameObject = UserDefaults.standard.object(forKey: "Name")  as? [String]

                var Name: [String]

                if let tempItems = NameObject {

                    Name = tempItems

                    Name.append("\(EnteredObjectTextFeild.text!)")

                    print(Name)

                } else {

                    Name = [EnteredObjectTextFeild.text!]
                    print("user defaults error 3")
                }

                UserDefaults.standard.set(Name, forKey: "Name")
                addNameToGroup()
                EnteredObjectTextFeild.text = ""
                NamePicker.reloadAllComponents()
                AsignmentPicker.reloadAllComponents()
            }

        }
        }else if isInMain == false {
// MARK: Add Group
        if allGroups.contains("\(EnteredObjectTextFeild.text!)"){
                EnteredObjectTextFeild.text = ""
                AlertAction(Title: "Group Exists", Message: "This Group already exists", alerTitle: "OK")
        }else {
            let groupsObject = UserDefaults.standard.object(forKey: "Groups")  as? [String]

            var groups: [String]

            if let tempItems = groupsObject {

                groups = tempItems

                groups.append(EnteredObjectTextFeild.text!)

                print(groups)

            } else {

                groups = [EnteredObjectTextFeild.text!]
                print("Bad")
            }

            UserDefaults.standard.set(groups, forKey: "Groups")

            EnteredObjectTextFeild.text = ""

        }
        NamePicker.reloadAllComponents()
        AsignmentPicker.reloadAllComponents()
    }
    NamePicker.reloadAllComponents()
    AsignmentPicker.reloadAllComponents()
    }
// MARK: Add Name func
func addNameToGroup(){
    let nameObject = UserDefaults.standard.object(forKey: "Name" + whatGroup)  as? [String]

    var NameForGroup: [String]

    if let tempItems = nameObject {

        NameForGroup = tempItems

        NameForGroup.append("\(EnteredObjectTextFeild.text!)")

        print(NameForGroup)

    } else {

        NameForGroup = [EnteredObjectTextFeild.text!]
        print("user defaults error 4")
    }

    UserDefaults.standard.set(NameForGroup, forKey: "Name" + whatGroup)
    namesForEachGroup = NameForGroup
    print("saved to group")
    EnteredObjectTextFeild.text = ""
    NamePicker.reloadAllComponents()
    AsignmentPicker.reloadAllComponents()
}

and this is where I get back to the first VC
@IBAction func BackPressed(_ sender: UIButton) {
    if isInMain == true {

        performSegue(withIdentifier: "FromAddToMain", sender: UIButton())

    }else {

        performSegue(withIdentifier: "FromAddToGroup", sender: UIButton())

    }
}

Comment: Where from do you get your `allPeople` array? And, how it's changed?
Comment: Add some breakpoints to make sure that the code you think should be happening is happening. My guess is that the code to pull stuff out of userdefualts isn't working. Hope this helps!
Comment: create an instance of first view controller in second and when you exit the modal reload the table view using the instance of first view controller. like if firstVC is an instance of first controller then call firstVC.tableview.reloadData()
Comment: You may need to force user defaults to save to disk in order for your reload code to pick up changes. Something like: UserDefaults.standard.synchronize() though I thought that wasn't required anymore.
Comment: I left out some code but its in there
Comment: and Its changed in the second view controller.
Answer: The simplest solution is how to pass the data in a undwin-perform,
the configuration is;
a function is created in the parent controller that will be the one that receives the execution focus:
  @IBAction func close (segue: UIStoryboard) {
     tableView.reload ()
  }

Then in the son controller the undwin is created segue (backwards) assigning the close function previously created, and in the output function execute the line.
performsegue (whithIdentifier: "undwinSegueclose", sender: self)

Answer: I added this code to each exit segue
theAssignments = UserDefaults.standard.array(forKey: whatGroup + "Assignments") as! [String]


How do I use custom configuration in Ktor?

Question: I'm digging the built-in configuration support, and want to use it (instead of just rolling my own alongside Ktor's), but I'm having a hard time figuring out how to do it in a clean way. I've got this, and it's working, but it's really ugly and I feel like there has to be a better way:
val myBatisConfig = MyBatisConfig(
        environment.config.property("mybatis.url").getString(),
        environment.config.property("mybatis.driver").getString(),
        environment.config.property("mybatis.poolSize").getString().toInt())

installKoin(listOf(mybatisModule(myBatisConfig), appModule), logger = SLF4JLogger())

Thanks for any help!
Answer: Okay, I think I have a good, clean way of doing this now. The trick is to not bother going through the framework itself. You can get your entire configuration, as these cool HOCON files, extremely easily:
val config = ConfigFactory.load()

And then you can walk the tree yourself and build your objects, or use a project called config4k which will build your model classes for you. So, my setup above has added more configuration, but gotten much simpler and more maintainable:
installKoin(listOf(
            mybatisModule(config.extract("mybatis")),
            zendeskModule(config.extract("zendesk")),
            appModule),
        logger = SLF4JLogger())

Hope someone finds this useful!
Answer: Adding to the existing accepted answer. An implementation using ConfigFactory.load() could look like this (Without libs):

object Config {
    @KtorExperimentalAPI
    val config = HoconApplicationConfig(ConfigFactory.load())

    @KtorExperimentalAPI
    fun getProperty(key: String): String? = config.propertyOrNull(key)?.getString()

    @KtorExperimentalAPI
    fun requireProperty(key: String): String = getProperty(key)
            ?: throw IllegalStateException("Missing property $key")
}

So, theconfig class would become:
val myBatisConfig = MyBatisConfig(
        requireProperty("mybatis.url"),
        requireProperty("mybatis.driver"),
        requireProperty("mybatis.poolSize").toInt())

Comment: There's no need to use a Config object. IMO objects without state just add unnecessary boiler plate code. You can just use top level functions for this.
Answer: You could also try this solution:
class MyService(val url: String)

fun KoinApplication.loadMyKoins(environment: ApplicationEnvironment): KoinApplication {
    val myFirstModule = module {
        single { MyService(environment.config.property("mybatis.url").getString()) }
    }
    val mySecondModule = module {}
    return modules(listOf(myFirstModule, mySecondModule))
}

fun Application.main() {
    install(DefaultHeaders)
    install(Koin) {
        loadMyKoins(environment)
        SLF4JLogger()
    }
    routing {
        val service by inject<MyService>()
        get("/") {
            call.respond("Hello world! This is my service url: ${service.url}")
        }
    }
}

fun main(args: Array<String>) {
    embeddedServer(Netty, commandLineEnvironment(args)).start()
}


Volatility as an Envelope for a Time Series

Question: In time-series analysis, I keep running into graphs that look roughly like...

Recalling a trig computation from an ODE book which explored the acoustic phenomena of beats, I noticed the orange volatility line looks like an approximate envelope for the maxima of the blue data.  This makes qualitative sense, since the data is stationary with mean $0$, thus a higher volatility correlates to a higher absolute value of the data.
Still, I'm curious whether there's a nice way to represent volatility and its reflection around the $x$-axis as an envelope for the extrema of the data.  An implicit approach would be to just scale the data by a constant factor until it fits within the volatility envelope, or define an error as the amount by which the data breeches the envelope, but this feels arbitrary.  Is there a natural way to transform the data or volatility to make the envelope pattern emerge?  Alternatively, is there anything special about a time-series for which volatility and its reflection automatically form an envelope for the data?
Answer: Imagine a simplified abstract scenario where, every minute, you extract the value of a random variable distributed like a normal (Gaussian) distribution with mean $0$ and standard deviation $\sigma$. This is an elementary example of what is called a stochastic process. If you keep a chart where you record the outcomes of your extraction as a function of time, after a while you will get a jagged line similar to the one in your picture, one of many possible realizations of that stochastic process. The line will however look more "regular," in the sense that always lands roughly in the same ballpark of the mean, without ebbs and flows. More precisely, if you draw two lines at height $+\sigma$ and $-\sigma$ about the mean value, assuming you have let the process run long enough, roughly 68% of the time the value of the random variable will have landed within that strip, and 32% of the time it will have landed outside; if you draw two further lines at $\pm 2\sigma$, roughly 95% of the realization will lie within that larger strip; and so on, with predictable, time-independent statistical behavior.
Now suppose you extract the random variable from a normal distribution with mean $0$ and standard deviation $\sigma_t$, allowing the latter parameter to depend on time. Then, the time series of one realization of that stochastic process will look a lot more like the one in your picture. Toward the beginning of the series, the standard deviation seems to be relatively small, whereas it increases toward the end, leading to a larger, well, deviation of real values from the mean around that time. If you graph $\pm\sigma_t$ against time, you get something similar to the yellow curve, instead of a simple band about the mean; yet, once again, about 68% of the data will have landed within the variable-sized strip. (Observe that these percentages are highly dependent on the fact that in our thought experiment extractions are performed from a normal distribution, instead of, say, a uniform distribution, a Weibull distribution, a Student $t$-distribution, ...)
The volatility of a financial asset is essentially the standard deviation of the stochastic process that regulates (the logarithm of) its market price over time. The situation I have described above is a thought experiment that hopefully clarifies the statistics behind the fact that increased volatility at a particular time is intrinsically connected with higher fluctuations in (the logarithm of) stock value. In real situations, you do not know the actual, intrinsic volatility behind the value of the asset: you have to rely on estimations based on time series (historic volatility) or comparisons between data and models (implied volatility). This seems to be the case with your picture: observe that bursts in volatility seem to lag behind spikes in returns.
So, assuming the stochastic process underlying returns is Gaussian at all times (a somewhat strong hypothesis to make, but a good starting point), to get the volatility curve to make a nice envelope around the returns, I'd try multiplying the latter by a constant factor of $2/3$.


Can we scrape linkdin/ jobs using scrapy? i was looking for tutorial on it but failed to find any?

Question: can we scrape linkdin/ jobs  using scrapy? i was looking for tutorial on it but failed to find any?
i search on github aswell but could'nt find any related repository.
can anyone tell me the reason? or can provide a simple spider of scrapy so that i can use and  modify that . but using SCRAPY only
Answer: You can't scrape linkedin/ jobs using scrapy only because scrapy can't render JavaScript but can scrape linkedin/ jobs using scrapy-seleniumRequest because Linkedin completely depends on JavaScript.
scrapy-selenium documentation is here
Comment: Isn't there any possibility to scrape some API endpoints on Linkedin?
Comment: No, they didn't use API endpoint. Everything is controlled dynamically by JS.
Comment: waht about scrapy-splash? isn't it a good option?
Comment: I recomand you not to use spalsh because no one is   taking care to maintain it
Comment: I am not familiar with scrapy-selenium , so I was trying to scrape this using splash but I am unable to locate the next-page url can you help me finding next page url ?  I will definetly try to do with scrapy-selenium but for time being i want to do it with scrapy-splash


Windows Certificate Authority - Auto Enroll RDP certificates trusted CA error

Question: So I'm running into an odd issue. I just setup a Windows Certificate Authority server and am able to use the web interface to issue Web SSL certs. My Fortigate and Fortianalyzer both have certs from this server and Google Chrome is all happy. I have already installed the Root CA into my workstations Trusted Root store. I am trying now to setup auto-enroll for RDP certificates so my servers can all automatically get RDP certs. This works, I am able to see a request come in and a cert get issued for a server. The problem is, when I RDP, I still get the warning that the certificate is not from a trusted certifying authority. If I view the certificate chain, Windows says "Certificate is OK". Am I missing something?
Root CA is installed.
Web apps show a valid certificate and CA. (Google Chrome is happy)
Windows Server auto-enrolls and obtains an RDP cert.
I try to connect but still get a root CA error.
RDP-Error-Screenshot
Answer: I suspect that your root certificate installed in Local Machine\Trusted Root CAs. It may be installed in Current User\Trusted Root CAs. This is sufficient for Chrome and certificate viewer, however RDP clients looks for valid roots in Local Machine store.
Open certlm.msc and confirm if your root certificate is there. If not, then install it.
What process you use for RDP certificate deployment? Keep in mind that you cannot use classic certificate autoenrollment process and you must use dedicated GPO configuration to automatically provision RDP certificates.
Comment: That was it. I had my CA in the personal store. I installed it into the Local Machine store and RDP works flawlessly now.


Provider dependency injection & uglify special case

Question: I use the security functionality from angular-app, and there is some funky stuff going on in the authorizationProvider
angular.module('security.authorization', ['security.service'])

// You can add them as resolves to routes to require authorization levels
// before allowing a route change to complete
.provider('securityAuthorization', {

  requireUser: ['securityAuthorization', function(securityAuthorization) {
    return securityAuthorization.requireUser();
  }],

  $get: ['security', 'securityRetryQueue', function(security, queue) {
    var service = {

      requireUser: function() {
        //Stuff ...
        return true;
    };

    return service;
  }]
});

The provider injects itself into the property 'requireUser', which calls a function returned by the $get factory method. Now, when I try to uglify this (grunt-contrib-uglify), it fails at
  requireUser: ['securityAuthorization', function(securityAuthorization) {
    return securityAuthorization.requireUser();
  }]

with Unknown provider: eProvider <- e. How can I minify this? I have tried the alternative provider declaration (since 1.1.x, it's possible to declare providers like normal factories, i.e. inject the dependencies and let the provider be a function), but that doesn't work either, because it looks for the dependencies in the security.authorization module.
Comment: So, in your `securityAuthorization` provider you are defining a `requireUser`function which is injected with the parent `securityAuthorization` itself, and than, inside the very same `requireUser` function you are calling `requireUser()`? Do you see the problem here.
Answer: One of the options for grunt-contrib-uglify is mangle
Try adding this into your Uglify config:
uglify: {
  options: {
    mangle: false
  }
}


Linq Data Source WhereParameters with "\" in value

Question: ASP.NET/C# project utilizing LinQ to SQL
I have listbox, with values from database, which is used to filter Linq Data Source.
Everything works fine until I have value in the listbox that contain "\". eg "DOMAIN\Group Name". any help would be appreciated!
if (ddlAppGroup.SelectedValue != "*")
            {
                LinqDataSource1.WhereParameters.Add(new Parameter("ApplicationGroup", System.Data.DbType.Int16));
                LinqDataSource1.WhereParameters["ApplicationGroup"].DefaultValue = ddlAppGroup.SelectedValue;

                if (LinqDataSource1.Where == "")
                {
                    LinqDataSource1.Where = "ApplicationGroup == @ApplicationGroup";
                }
                else
                { LinqDataSource1.Where = LinqDataSource1.Where + " && ApplicationGroup == @ApplicationGroup"; }
            }

This is what  parameters look like:
    LinqDataSource1.WhereParameters[0]
{ApplicationGroup}
    ConvertEmptyStringToNull: true
    DbType: Int16
    DefaultValue: "DOMAIN\\Group-Name"
    Direction: Input
    Name: "ApplicationGroup"
    Size: 0
    Type: Empty

and this is what error is reported
    {"Input string was not in a correct format."}
    [System.FormatException]: {"Input string was not in a correct format."}
    Data: {System.Collections.ListDictionaryInternal}
    HelpLink: null
    HResult: -2146233033
    InnerException: null
    Message: "Input string was not in a correct format."
    Source: "mscorlib"
    StackTrace: "   at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)\r\n   at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)\r\n   at System.Int16.Parse(String s, NumberStyles style, NumberFormatInfo info)\r\n   at System.String.System.IConvertible.ToInt16(IFormatProvider provider)\r\n   at System.Convert.ChangeType(Object value, TypeCode typeCode, IFormatProvider provider)\r\n   at System.Web.UI.WebControls.Parameter.GetValue(Object value, String defaultValue, TypeCode type, Boolean convertEmptyStringToNull, Boolean ignoreNullableTypeChanges)\r\n   at System.Web.UI.WebControls.Parameter.GetValue(Object value, String defaultValue, DbType dbType, Boolean convertEmptyStringToNull, Boolean ignoreNullableTypeChanges)\r\n   at System.Web.UI.WebControls.Parameter.GetValue(Object value, Boolean ignoreNullableTypeChanges)\r\n   at System.Web.UI.WebControls.Parameter.get_ParameterValue()\r\n   at System.We
b.UI.WebControls.ParameterCollection.GetValues(HttpContext context, Control control)\r\n   at System.Web.UI.WebControls.QueryableDataSourceView.CreateQueryContext(DataSourceSelectArguments arguments)\r\n   at System.Web.UI.WebControls.LinqDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments)\r\n   at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback)\r\n   at System.Web.UI.WebControls.DataBoundControl.PerformSelect()\r\n   at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()\r\n   at System.Web.UI.WebControls.GridView.DataBind()\r\n   at PYOCEnrollment.Admin.AllRequests.btnApply_Click(Object sender, EventArgs e) in C:\\Projects\\PYOCEnrollment\\PYOCEnrollment\\EUE\\AllRequests.aspx.cs:line 265"
    TargetSite: {Void StringToNumber(System.String, System.Globalization.NumberStyles, NumberBuffer ByRef, System.Globalization.NumberFormatInfo, Boolean)}

Comment: [Nice name](http://www.wowpedia.org/Vol'jin) ;)
Answer: This is not going to fly:
DbType: Int16
DefaultValue: "DOMAIN\\Group-Name"

Consider changing the DbType to one of the nvarchar types.


Pandas Time Series DataFrame Missing Values

Question: I have a dataset of Total Sales from 2008-2015. I have an entry for each day, and so I have a created a pandas DataFrame with a DatetimeIndex and a column for sales. So it looks like this
The problem is that I am missing data for most of 2010. These missing values are currently represented by 0.0 so if I plot the DataFrame I get

I want to try forecast values for 2016, possibly using an ARIMA model, so the first step I took was to perform a decomposition of this time series

Obviously if I leave 2010 in the DataFrame any attempted prediction will be skewed by the apparent, albeit erroneous, drop in sales.
What is the recommended approach in this situation? I think I should just drop 2010 altogether, but then I don't know if my time series is valid going from 2009 to 2011. I don't want to fill the missing values, because I don't believe I can do so accurately.
If I just delete 2010, however, the plot 'fills in' 2010 which doesn't help me
sales = sales.drop(sales['2010'].index)

Comment: [tag:Imputation] is the statistical fields which attempts to make inferences in the presence of missing data. Perhaps that might be helpful here.
Answer: Keep the 2010 dates - but make the values 'nan' .  If you have a timeseries Dataframe, then it's as simple as:
newDf = old.set_value('2010', 'Total Sales', float('nan').

if your data drop out isn't exactly 2010, you can replace 0s with nans:
new = old.replace([0], float('nan'))

This will cause a "pen lift" (if you can imagine an old pen plotter, nan caused a pen lift, therefore matlab, and consequently matplotlib, emulated that behavior).
If you do this, you need to make sure your analysis routines can handle nans properly.  (particularly any time filtering, like MA, across the gap.
Finally, I would strongly suggest moving this kind of question to StackOverflow, since it's more of a Pandas question than an analytical question.


Is this Hilbert space construction legal?

Question: Let $X=\ell^2=\{(\xi_i)_{i\in\mathbb{N}}\in\mathbb{R}^\mathbb{N}\, | \, \sum_{i\in\mathbb{N}}|\xi_i|^2<\infty\}$ be the real Hilbert space of square-summable sequences, and for every $j\in\mathbb{N}$ set
$$ X_j=\{(\xi_i)_{i\in\mathbb{N}}\in X\, | \, \forall i\neq j, \xi_i=0\}.$$
It follows that $(X_j)_{j\in \mathbb{N}}$ are closed mutually orthogonal vector subspaces of $X$, and hence they are also real Hilbert spaces in their own right using the subspace topology inherited from $\ell^2$ (same norm, inner product, etc). Now, consider the "direct sum" of the $X_i$s: $(\hat{X}, \langle\cdot\, |\, \cdot \rangle)$ where
$$\hat{X}=\{ (x_j)_{j\in \mathbb{N}} \in \times_{j\in\mathbb{N}}X_j \, | \,\|(x_j)_{j\in J}\|^2_{\hat{X}}= \sum_{j\in\mathbb{N}} \|x_j\|^2_{\ell^2} < +\infty\}.\tag{1}$$
and
$$\langle (x_j)_{j\in J} \, | (y_j)_{j\in J} \rangle = \sum_{j\in\mathbb{N}} \langle x_j \, | \, y_j\rangle_{\ell_2}.\tag{2}$$

Is $(\hat{X}, \langle\cdot\, |\, \cdot \rangle)$ a valid real Hilbert space?

My colleague claims that it is not: The elements of $\hat{X}$ are a countable product of countable sequences, so in a sense it is impossible to sum them formally. Essentially they're saying that we can not append a sequence onto another sequence countably many times as done in (1). However, I have seen this direct sum construction in several books, and proofs showing it is a valid Hilbert space do not rely on the structure of the underlying $X_i$'s at all (other than the fact that they are real Hilbert spaces to start with). What do you think?
Comment: I don't understand the objection.  Each element of $\hat{X}$ is simply a sequence of elements; I don't know where the "product of sequences" idea came from.  And it is perfectly easy to sum two sequences: pointwise.  I don't understand what you mean by "append" in reference to (1).
Comment: But that's precisely what a countable Cartesian product of sets **is**!  Are they doubting that countable Cartesian products exist?  That's silly.  I mean, you do need the axiom of (countable) choice to prove that they do, but you need it to do pretty much anything in analysis.
Comment: @NateEldredge e.g. appending $x_1\in\ell^2$ and $x_2\in\ell^2$ would be $(x_1,x_2)$. They take issue with doing this countably many times.
Comment: @NateEldredge I think it's rather silly as well. Thanks for the comment, I thought this construction was fine but I guess their doubts made me ask for third opinions.
Answer: I guess you have a typo and want to have
$$\hat X = \{(x_j) \mid \sum_j \lVert x_j \rVert^2_{\ell^2} < \infty \}.$$
Then $\hat X$ is a Hilbert space. Your construction works for any collection of Hilbert spaces $X_j$, not only for the subspaces $X_j \subset \ell^2$ defined in your question.
See for example section "Direct sums" in https://en.wikipedia.org/wiki/Hilbert_space#Direct_sums.
Note that if you define
$$\tilde X  = \{(x_j) \mid \sum_j \lVert x_j \rVert_{\ell^2} < \infty \},$$
then $\tilde X \subset \hat X$, thus your definition
$$\langle (x_j), (y_j) \rangle = \sum_{j\in\mathbb{N}} \langle x_j , y_j\rangle_{\ell_2}$$
defines an inner product on $\tilde X$. However, $\tilde X$ is not a Hilbert space  - it lacks completeness.
By the way, in your example the $X_j$ are one-dimensional subpaces of $\ell^2$ and therefore isomorphic to $\mathbb R$. Thus $\hat X$ is nothing else than a copy of $\ell^2$.
Comment: @Zim Your colleague is wrong. It does not matter what the elements of $X_j$ look like, we only need to know that they have a norm. By the way, the elements of $\hat X$ do not have uncountably many entries. The $(x_j)$ are systems of real numbers indexed by $\mathbb N \times \mathbb N$ which is a countable set. Moreover, each $x_j \in X_j$ has at most one non-zero entry.
Comment: Thanks for pointing out the typo! Squares were supposed to be included in the norm, oops. This was also my impression -- the direct sum **always** yields a valid Hilbert space. My colleague takes issue with this construction though, since there is an uncountable number of items in each element of $\hat{X}$ and hence they claim it is not formally summable.
Comment: Okay, thanks for the clarification!
Answer: Some thoughts: The norm you are considering in (1) is the $\ell_1$ norm and doesn't coincide with the norm induced by the product in (2), which is the $\ell_2$ norm.
Also direct sums of infinitely many vector space are usually defined by taking sums of finitely many components.
Besides that your construction works.


Erro no IEnumerable

Question: using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations;

namespace Rotas.Models
{
    public class Noticia
    {
        public class Noticia
        {
            public int NoticiaId { get; set; }
            public string Titulo { get; set; }
            public string Conteudo { get; set; }
            public string Categoria { get; set; }
            [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}")]
            public DateTime Data { get; set; }
            /* Cria uma array do tipo IEnumerable que é mais sofisticado e que joga um tanto de objetos do tipo Noticia dentro*/
            public IEnumerable<Noticia> TodasAsNoticias()
            {

                // instancia uma coleção de noticias
                var retorno = new Collection<Noticia>
                {
                    new Noticia
                        {
                            NoticiaId = 1,
                            Categoria = "Esportes",
                            Titulo = "Felipe Massa ganha F1",
                            Conteudo = "Numa tarde de chuva Felipe Massa ganha F1 no Brasil...",
                            Data = new DateTime(2012,7,5)

                        },
                    new Noticia
                        {
                            NoticiaId = 2,
                            Categoria = "Política",
                            Titulo = "Presidente assina convênios",
                            Conteudo = "Durante reunião o presidente Ismael Freitas assinou os convênios...",
                            Data = new DateTime(2012,7,3)
                        },
                    new Noticia
                        {
                            NoticiaId = 3,
                            Categoria = "Política",
                            Titulo = "Vereador é eleito pela 4ª vez",
                            Conteudo = "Vereador Fabio Pratt é eleito pela quarta vez...",
                            Data = new DateTime(2012,7,20)
                        },
                    new Noticia
                        {
                            NoticiaId = 4,
                            Categoria = "Esportes",
                            Titulo = "O tão sonhado titulo chegou",
                            Conteudo = "Em um jogo que levou os torcedores ao delirio...",
                            Data = new DateTime(2012,7,18)
                        },
                    new Noticia
                        {
                            NoticiaId = 5,
                            Categoria = "Humor",
                            Titulo = "O Comediante Anderson Renato fará shou hoje",
                            Conteudo = "O comediante mais engraçados dos comentários do Youtube fará show...",
                            Data = new DateTime(2012,7,14)
                        },
                    new Noticia
                        {
                            NoticiaId = 6,
                            Categoria = "Policial",
                            Titulo = "Tenente coronel Lucas Farias Santos assume o controle",
                            Conteudo = "Durante a retomada do morro o tenente coronel disse...",
                            Data = new DateTime(2012,7,19)
                        },
                    new Noticia
                        {
                            NoticiaId = 7,
                            Categoria = "Esportes",
                            Titulo = "Atacante do Barcelona faz 4 gols",
                            Conteudo = "O atacante Lucas Farias Santos Messi, fez 4 gols e decidiu o titulo...",
                            Data = new DateTime(2012,7,8)
                        }
                };
                return retorno;
            }
        }
    }
}

Comment: A classe Noticia é estática? Qual o código de "Rotas"?
Comment: Rotas é o nome do projeto, ela nao é estatica
Comment: Por favor, poste o código em texto, não imagens.
Answer: Faltou um set de parentesis na construção do objeto Noticia:
todasAsNoticias = new Noticia.TodasAsNoticias().OrderByDescending(x => x.Data);

Deveria ser:
todasAsNoticias = new Noticia().TodasAsNoticias().OrderByDescending(x => x.Data);

Edição 1
Também segundo a sua imagem, você criou uma classe Noticia... dentro de uma outra classe Notícia:
public class Noticia
{
  public class Noticia
  {
    public IEnumerable<Noticia> TodasAsNoticias()
    {
      // Implementação...
    }
  }
}

Quando provalmente você quis dizer:
public class Noticia
{
  public IEnumerable<Noticia> TodasAsNoticias()
  {
    // Implementação...
  }
}

Comment: @ThalesSilveira nesse caso não deveria dar este erro. Pode editar a sua pergunta e adicionar a classe `Noticia` inteira?
Comment: Error 1 'Rotas.Models.Noticia' does not contain a definition for 'TodasAsNoticias' and no extension method 'TodasAsNoticias' accepting a first argument of type 'Rotas.Models.Noticia' could be found (are you missing a using directive or an assembly reference?) Agora da esse erro
Comment: `TodasAsNoticias` é um método de instância da classe `Noticia`?
Comment: Sim sim, TodasAsNoticias esta no model(classe Noticia)
Comment: Você poderia postar o código completo da classe Noticia?
Comment: @Genos pronto editei, da uma olhada
Answer: Tem uma bagunça aí. Você declara duas vezes a classe Noticia, uma dentro da outra.
Remova a declaração mais externa, deixando o código assim:
namespace Rotas.Model
{
    public class Noticia
    {
        // Membros da classe

        public IEnumerable<Noticia> TodasAsNoticias()
        {
            // Todo o código do método
        }
    }
}

No controller, faltam os parênteses para inicializar a classe
todasAsNoticias = new Noticia().TodasAsNoticias().OrderByDescending(x => x.Data);

Note que este método poderia ser estático. Desta forma, não seria neessário criar uma instância da classe para chamá-lo, já que não é preciso uma instância de notícia, acho que é muito mais sensato criar o método sendo estático.
A chamada ficaria assim
todasAsNoticias = new Noticia.TodasAsNoticias().OrderByDescending(x => x.Data);

Comment: Sim agora que postei o codigo eu consegui ver rsrsrs obrigado !

Erro no IEnumerable


filepatterns to exclude a match

Question: Shake uses various forms of matching, filepath against pattern. Is there one which can be used to exclude a pattern?
Example:
I have three directories a, b, c (somewhere in directory x) and each needs html files. There is a rule
(dir <> "//*.html") %> \out -> do -- deal with a and b

which should only deal with the directories a and b and a similar rule to process the files in c.
Is there a way (perhaps using ?>) to separate the two rules for one
(\f -> "x" prefixOf f && not "x/c" prefixOf f) <> "//*.html")
(\f -> "x/x" prefixOf f ) <> "//*.html")

and the other similarly?
The recommended approach to use xx.a.html and xx.b.html is here not possible, because files are processed with other programs which expect the regular html extension.
Alternatively
Answer: The rule:
pattern %> action

Is equivalent to:
(pattern ?==) ?> action

So you can write:
(\x -> "//*.html" ?== x && not ("c//*.html" ?== x) ?> action

To match rules matching //*.html, but not c//*.html.
More generally, there is no requirement to use the FilePattern ?== operator at all, so arbitrary matching predicates can be used instead.
Comment: I recommend using `**/*.html` and avoiding `//` entirely - partly because it fights horribly with the `` operator. They aren't equivalent, and the second doesn't remotely do what you expect. A future version of Shake will eliminate `//` entirely.
Comment: I have now two rules (\x -> ((bakedD <> "//*.html") ?== x) && (not ((staticD <> "//*.html") ?== x)))
                     ?> \out -> do
 ...
        (staticD  "//*.html" ) %> \out -> do
 ...
where `staticD =   bakedD  staticDirName` and have overlap with a file
`baked <> /SSGdesign/index.html`. what is wrong? (sorry for poor presentation, how to improve?)
Comment: There was a `/` in the first rule. Now I have a `Rules may not be recursive` error. Working on it...
Comment: is `(bakedD <> "//*.html")` and `(bakedD)  "//*.html")` equivalent?
Answer: With the advice (especially the hint about using **/*.html) I have it working.
The path bakedD is a prefix of staticD and the first rule deals only with files in bakedD which are not in staticD, the other only with these:
(\x -> ((bakedD <> "**/*.html") ?== x)
     && not  ((staticD <> "**/*.html") ?== x)) ?> \out -> do
            let md =   doughD </>  (makeRelative bakedD $ out -<.> "md")
            runErr2action $ bakeOneFileFPs  md  doughD templatesD out

(staticD <> "**/*.html" ) %> \out -> do
        copyFileChanged (replaceDirectory out doughD) out

There is no overlap between the two rules.
I hope this is useful for others with the same type of issue.

filepatterns to exclude a match


Listen to the radio with Dialogflow and a webhook

Question: I want to listen to the radio in my own app made with dialogflow using a webhook (hosted on firebase).
I saw the prebuilt-agent sample of dialogflow but it only helps creating the intent, not on how to play the radio.
I know that we can stream audio with SSML or mp3 files but I never saw anything concerning the radio?
I know it is possible because I can ask my Google Home Mini to play a radio station, but is it possible to create an app that does it?
Any indications would be appreciated.
Comment: Accoring to a comment on [this answer](https://stackoverflow.com/a/42058545/43846) by a [Google Developer Programs Engineer](https://stackoverflow.com/users/594751/leon-nicholls), _"Streaming is not supported yet [in Actions on Google]"_.
Comment: @stuartd Ok! thanks for your answer!
Comment: What do you mean by "the radio". What is the source of the audio? (As in - you're providing the audio. How do you want to send it?)
Comment: @Prisoner I'd like to have something similar to what is built-in in my Google Home, like when I say "Ok Google, je veux écouter France-Inter" (Ok Google, I want to hear France-Inter), I want to hear the same output. The audio is on the server of France Inter and I can probably retrieve it with it's IP, but I have for now no way to play it. Otherwise I wanted to play my playlist (a list of audio files) but I can't put more than one music in a Media Response and the SSML's limitation is a problem
Answer: You have two slightly different problems you're trying to solve.
Radio streams such as the France-Inter stream you're talking about still need to be coordinated with Google directly or with one of the existing streaming services.
For your own audio files, SSML is certainly an issue, but you can handle what you want with the Media Response. Dialogflow will be called with an Event of actions_intent_MEDIA_STATUS which you can create an Intent to capture. You can then send another Media Response with the next song in the playlist.
Update based on your comment.
To maintain your position in the playlist you should not use a global variable. Firebase cloud functions do not guarantee that you will get the same instance two calls in a row. There are a few good approaches which boil down to one of

Using a Dialogflow Context to store the location
Store the location in some data store (like a Firestore database) and index it using the session ID or
Use the Actions on Google library app.data object
Comment: That is exactly what I was thinking concerning the media response! My problem now would be to know my position in my playlist because for each https request received, I instantiate a new class and therefore I can't save my position as an attribute. As my code is on firebase, maybe I can use a kind of global variable for it. Thanks for your pointers!
Comment: Answer updated to address your playlist question. (Going into details might best be done as another question, however)
Comment: Thanks! I'll check that and if I have any problem, I'll ask another question
Comment: How do you use the app.data object to store info? When I create my app I initialize my playlist index at 0, when i start the playlist I increment it. Then at the end of the audio I receive the end media event and I check the index value but it is always 0... Do I have to add it as JSON or does it not store the data of a session?
Comment: Using `app.data` is best asked as another question.


Node Add / Edit Options Vertical Tab Problem

Question: For just one of my content types -- the built-in Article content type -- the node option vertical tabs at the bottom of the add / edit form are not displaying correctly.
As shown in the attached screenshot, the first node option for whether to create a menu link for the node is displayed as a tab. All other node option fieldsets are displayed WITHIN the first vertical tab as collapsible fieldsets, not as additional tabs. This only happens for the Article content type.
I cannot figure out why this is happening. Clearly, some module is form_altering the node add / edit form, but I have no idea which one or why only for Article.
Comment: where is screenshot?
Comment: Were you ever able to find a solution, or offending module?
Comment: I cannot see the screenshot here either, unfortunately... and I would suggest 2 things; dumping a list of contrib modules using drush and reviewing them carefully, and searching the contrib code for a _form_alter.  (ie using grep in the contrib directory)
Answer: Here is a series of things I would try. Check tabs after each test.

Try with a different browser.
Flush all caches (that one often solves a lot of problems).
Put your site in maintenance mode and Run updates (update.php).
Disable the Overlay module.
Disable all modules. Flush all caches. Re-enable all modules.
Update to the latest version of core if you can (currently 7.22).

Number 5 is a bit time consuming but it has solved issues for me in the past. First, make a list of all enabled modules. I do this with screen captures. Second, start disabling modules (except maybe Admin menu). You won't be able to disable all modules at once. It may take half a dozen Save configuration to completely disable all modules. When done, Flush all caches and while you're at it, clear your browser's cache too. Finally, re-enable all required modules. Run updates. Run cron. Flush all caches.
Hope this helps.
Answer: On the content type's configuration page (eg: yoursite.org/blog/admin/structure/types/manage/article/fields), make sure you have nested your tabs correctly. Each vertical tab should be within a vertical tab group. Drupal treats the administrative tabs (like menu items, authoring, etc.) as a tab group, but if your other tabs are free-floating, they'll all go together.
On your Manage Fields tab, scroll to the bottom and create a new group, selecting Vertical tabs group option. See screenshot below. Then put your node's fields inside the group. The admin tabs will be outside it and will go into their own group.


What sports court is this, with a white circle inside a white square or triangle, and diagonal colored lines?

Question: I saw this sports court the other day and I can't figure out the rules for the game. I have no idea where I would even start looking.
Below are satellite images of the court. I've tried to trace one to make it more visible (there are more smaller lines that can't be seen but they appear to be minor).
Comment: Personally it looks like a version of four square. Can you provide a link to the actual image you are looking at? Is this a school?
Comment: Are you 100% sure it's a sports layout? My first thought, on seeing the top photo, is that it's laid out on a car park, and that it might be something like an odd layout for a helicopter landing pad?
Comment: @TrueDub it's definitely for sports -- there is no way you could land a helicopter through those trees, and there are three of them.
Comment: @diggers3 This is in a church parking lot. Next time I'm there I'll post a picture. I thought four square at first but although it would work for that, there are way more lines than necessary.
Comment: What about tetherball? If there are 3 of them that would make  sense and the four quadrants for each player.
Comment: @PaulWitry There is no pole, or a space for one.
Answer: This is an Awana Game Square (your mention of this being in a church parking lot may corroborate this).
More information can be found at the aforementioned link, but as for rules:

Teams stand outside the large square along the line of their team color. In relay games, the center pin and bean bag are placed on the very center of the circle. Each team member, in turn, runs from his starting pin, around the complete circle, past his starting pin and along his color diagonal into the center of the circle for the center pin or bean bag.


Proving a set of points is not closed in $\Bbb{R}$

Question: Can someone please help me prove that the set of points $\{\frac{1}{n} \mid n\geq 1\}$, $n$ being a positive integer, is not closed in $\Bbb{R}$?
I understand that in order for a set to be closed it must contain all of its limit points, but I am not sure if I should prove this statement through its complement or another way.
Thank you!
Comment: [Here's a MathJax tutorial](http://meta.math.stackexchange.com/questions/5020/mathjax-basic-tutorial-and-quick-reference) :)
Comment: Find a limit point that is not in the set.  The set actually only *has* one limit point and it isn't in the set.  Do you know what that limit point is.  (Hint:  What is $\lim \frac 1n$?)
Answer: Hint: Is $0$ a limit point of your set?
Answer: You can clearly see that as $n\rightarrow \infty$, we get the sequence converging to $0$ i.e. $0$ is a limit point. However if you write out the sequence you have $\{1, 1/2, 1/3, .........\}$ you will see that $1/n$ ONLY TENDS to zero but never actually equals zero. Therefore it is not present in the following set. So by your definition of closed sets, this set is not closed.


What is the most convoluted standard musical form?

Question: In musical composition, we tend to reuse sections of a piece in patterns that are referred to as "musical forms". Some basic examples of these that I know of are ABA, AABA, ABAB, and the rondo form ABACAB'A. While I recently became interested in finding out about more varying musical forms, the only one I was able to find that somewhat matches what I'm looking for is the Sonata Rondo form's infinitely varying ABACADAEA... pattern.
In short, what I would like to discover (if any exist at all):

A musical form containing a large number of variations.
Ideally the musical form should have a set end, rather than formulaic variance into infinity like the sonata rondo.

With that said, are there any musical forms that meet both of these requirements and contain more variations than the Rondo form?
Comment: Your question still isn't quite straightforward, I think, because the first thing that comes to my mind is American Old time music, where the basic form is usually AABB, but it is repeated until the players run out of variations. So while it is AABBAABBA..., each AABB is different than the last. When good players are jamming, this can be 10 to 30 minutes with no identical repetitions. Anecdotally, I've heard of players spending an hour on the same song, with people leaving and joining in the middle. But it sounds like you want a more simplistic definition of complexity.
Comment: Would "symphony" or "opera" count as possible answers? If "rondo" is a candidate then there's definitely a case to be made for "symphony".
Comment: Look into the "formes fixes" of the 14th and 15th centuries, like virelai, rondeaux (not the same as rondos), ballatas, and madrigals.
Comment: I feel like rondos are defined by their musical form, whereas symphonies and operas aren't. If they are, though, they would make an excellent answer.
Comment: Sonata form is a large-scale structure (sometimes used by symphonies!) that has seen frequent use.
Comment: I'm starting to get an "unclear what you're asking" vibe based on your comments. Do you feel like there are a lot of standard musical forms out there of which you are not aware? If they are standard musical forms, you've probably heard of them, and in that case you can easily evaluate for yourself which one best fits your definition of "most convoluted".
Comment: What about theme and variations? It's a very open form with lots of variations. An extreme case of many very different variations would be Rzewski's "The People United Will Never Be Defeated".
Comment: Looked into it, and the "formes fixes" are exactly the kind of thing I was looking for. Do you think you could add an answer so that I can mark this as resolved?
Answer: According to the Wikipedia page for "Symphony", during the 17th century, the symphony had a fairly set structure:

The four-movement form that emerged from this evolution was as
  follows:

an opening sonata or allegro
a slow movement, such as adagio
a minuet or scherzo with trio
an allegro, rondo, or sonata

While it may not completely fit the above structure, Mahler's Symphony No. 3 often runs 90 to 100 minutes. So "symphony" is a candidate answer. Operas often run longer than 90 to 100 minutes, but might not have a clearly set structure.
Opera Seria is an Italian form of opera, also with a fairly set structure. From the Wikipedia page:

Opera seria built upon the conventions of the High Baroque era by developing and exploiting the da capo aria, with its A-B-A form. The first section presented a theme, the second a complementary one, and the third a repeat of the first with ornamentation and elaboration of the music by the singer. As the genre developed and arias grew longer, a typical opera seria would contain not more than thirty musical movements.
A typical opera would start with an instrumental overture of three movements (fast-slow-fast) and then a series of recitatives containing dialogue interspersed with arias expressing the emotions of the character, this pattern only broken by the occasional duet for the leading amatory couple. The recitative was typically secco: that is, accompanied only by continuo (harpsichord and cello, sometimes supported by further bass instruments). At moments of especially violent passion secco was replaced by stromentato recitative, where the singer was accompanied by the entire body of strings. After an aria was sung, accompanied by strings and oboe (and sometimes with horns or flutes), the character usually exited the stage, encouraging the audience to applaud. This continued for three acts before concluding with an upbeat chorus, to celebrate the jubilant climax.
Comment: Maybe the real confusion is what you mean by "form", not necessarily what you men by "longest".
Comment: I guess I wasn't exactly clear by what I meant by "longest" form- I really meant long as in the number of variations to the theme (ABACA being more convoluted than ABA, and so on). I'll edit the question to reflect this more clearly. This is informative, though- thank you.
Comment: Oh, then I think Opera might win in terms of being able to repeat recitative - aria or recitative - opera - chorus as many times as necessary, so it's like a potentially infinite series of smaller structures. See: http://www.cfa.ilstu.edu/mhdicke/152/notes/operatic.html
Comment: I've been going by Wikipedia's definition of musical form [here](https://en.wikipedia.org/wiki/Musical_form), particularly the passage on single forms.
Comment: Based on that page, and considering a work like *Pictures at an Exhibition* to be a non-formal collection of through-composed sections, I still think it's either symphony or opera, depending on how you look at it. Opera is less complicated but has potentially more sections of similar structure. Symphony has a more multi-layered structure than opera but has a (mostly) fixed structural length. If you want the most complex form that has the least variations in its implementation, then the winner is probably sonata-allegro.
Comment: I understand "form" to apply to a single movement. The largest unit with a _formal_ ending. Maybe "genre" is the term to apply for 'symphony', 'opera', 'suite', etc.
Comment: @MichaelCurtis If you look at the time stamps, you'll see the question was changed after I answered. The question originally asked for the "longest form", and in a comment the asker suggested that symphony and opera seemed like good answers.
Answer: Sonata-rondo form is the most convoluted form I know of where you have something like this:
A B A C A B A
where C is the development and might have a form of something like this:
A B C A Close
Besides that, I think complex ternary form is the most convoluted of all the non-rondo forms.
On the large scale you have this:
A B A
A simple ternary form. You might not think that is complicated, but in complex ternary form, each of these large scale sections is itself in Ternary form. So the small scale form is this:
A B A C D C A B A
There is one famous piece I know of that is in Complex ternary form. It is Chopin's Military Polonaise. The large scale A sections are both in A major and the large scale B section is in D major. And each of these sections is itself in ternary form.

You wouldn't think the polonaise is simple at all just listening to it. But it is in complex ternary form and out of the forms that aren't rondo or sonata-rondo, it is the most complicated.
Comment: The Military Polonaise is just in compound ternary form, with each section being in rounded binary form. Now, for more complicated than even the (I-)A-B-C-A-B'(-Z) of sonata-allegro form...I've heard decent arguments that each *outer section* of the 2nd movement of Beethoven's 9th Symphony is in sonata-allegro form. (The inner section is in a binary form of some sort.)
Comment: I do beleive it is in complex ternary form because the A section comes back fully, not only half of it comes back. And that is the differing factor between rounded binary form and ternary form is whether or not the A section comes back fully. If it does, it is in ternary form. If not, if only part of it comes back, then it is in rounded binary form. Here in the polonaise, it comes back in its entirety both on the large and small scales.
Comment: ...Looked it up just now. Darn, I didn't previously know that ternary form could come with repeats a la AABABA.
Comment: My understanding of the question is 'form' meaning a single movement, so not a multi-movement symphony. In that case sonata-rondo seems the _standard_ form which is most complex. +1


r - ggplot with two data.frames, legend wrong identifiers

Question: I am using ggplot and I was able to get the plot that I want.
But when I tried to add a legend, something went wrong. The legend has different shapes, sizes and linetypes; the only correct match is the color.
Here is the code, with simulated data:
library(ggplot)
set.seed(5703)
# DATA 1
x1 <- seq(1, 100)
y1 <- rnorm(mean = 50, sd = 10, length(x1))
df1 <- data.frame(x1, y1)
head(df1)

# DATA 2
x2 <- seq(1, 100, 5)
y2 <- rnorm(mean = 50, sd = 2, length(x2))
df2 <- data.frame(x2, y2)
head(df2)

# Plot: DATA 1 and DATA 2
p101 <- ggplot (df1, aes( x = x1, y = y1) ) +
  geom_point(aes(color="Vals every 1sec - shape circle"), shape = 1, size = 4 ) +
  geom_line (aes(color="Vals every 1sec - shape circle"), size = 0.5, linetype= "dotdash") +
  geom_point(data= df2, aes(x = x2, y = y2, color="Vals every 5sec - shape: triangle & bigger, line: thicker"), shape= 2, size= 6 ) +
  geom_line (data= df2, aes(x = x2, y = y2, color="Vals every 5sec - shape: triangle & bigger, line: thicker"), size = 1.25, linetype = "solid" ) +
  scale_colour_manual("", values=c("Vals every 1sec - shape circle" = "#e66101",
                                   "Vals every 5sec - shape: triangle & bigger, line: thicker" = "#5e3c99" ) )+
  theme(legend.position = c(0.7,0.1) )+
  labs (title = "Graph Nr. 101", x = "Time [s]", y = "Values")
p101
# legend is mixed up, it is not showing the correct shapes and sizes for each data

Here is the image:

You will notice that both items on the legend have a circle and a triangle, same size and linetype.
Maybe the plot code is entirely wrong, so I am open to any suggestions and ready to learn :)
Comment: It would be simpler to `rbind` your data together with an identifier variable for which data.frame it came from, e.g. `library(dplyr); bind_rows(setNames(df1, c('x', 'y')), setNames(df2, c('x', 'y')), .id = 'line') %>% ggplot(aes(x = x, y = y, linetype = line, color = line, shape = line)) + geom_point() + geom_line() `, though you'll need to clean up scales to match your preferences.
Comment: Ohh thanks for your fast reply @alistaire it seems pretty  similar to what has coded. Thumb up !
Answer: You will have to add in the legend and theme changes but this should get you to where you want.
library(ggplot)
library(dplyr)
set.seed(5703)
# DATA 1
x1 <- seq(1, 100)
y1 <- rnorm(mean = 50, sd = 10, length(x1))
df1 <- data.frame(x = x1, y = y1, group = "A")
head(df1)

# DATA 2
x2 <- seq(1, 100, 5)
y2 <- rnorm(mean = 50, sd = 2, length(x2))
df2 <- data.frame(x = x2, y = y2, group = "B")
head(df2)

df <- bind_rows(df1, df2)

# Plot: DATA 1 and DATA 2
p101 <- ggplot (df, aes( x = x, y = y, color = group) ) +
  geom_line(aes(linetype = group), size = 0.5) +
  geom_point(aes(shape = group), size = 4 )

Comment: I have seen a lot of ggplots using melt or bind_rows, in order to get the expected results. What was wrong on my code? Could please tell me what I was not thinking clear? Any reading suggestions? Thanks


Can the t-test be used to test the difference between percentiles of 2 samples?

Question: For example, instead of testing the difference in mean, I want to test the difference in the 75th percentile of the 2 groups.
Does the central limit theorem hold? and what would be the equation for the standard error?
Comment: If you assume normality and the usual assumptions of the two-sample t test, then a difference in the mean implies a difference in any percentile.
Answer: Quoting from Theorem 7.5.1 (p243) of Bain & Englehardt (1992), except for notation:
Let $X_1, X_2, \dots, X_n$ be a random sample from a continuous distribution with PDF $f(x)$ that is continuous and nonzero at the $p$th percentile $x_p,$ for $0 < p < 1.$ If $k/n \rightarrow p$
(with $k-np$ bounded), then the $k$th order statistic $X_{(k)}$ is asymptotically normal with mean $x_p$ and variance $c^2/n,$
where $$c = p(1-p)/f(x_p).$$
So there is a CLT for the 75th percentile and the asymptotic
variance is as specified in the theorem. Instead of requiring
a finite population variance $\sigma^2,$ as in the CLT for
means, the requirement is roughly that the quantile $x_p$ of the distribution be precisely defined, with $f(x_p) > 0.$
Suppose you have a sample of size $n=625$ from a population distributed as $\mathsf{Norm}(\mu = 100, \sigma = 15),$ with 75th
percentile $110.1173$ and $$c^2/n = \frac{3/16}{0.0212n} = 0.6684.$$
f = dnorm(qnorm(.75, 100,15), 100,15); f
[1] 0.0211851
(3/16)/(625*f^2)
[1] 0.6684363

If we simulate $m=100\,000$ such samples, we see that the variance
of the resulting $m$ 75th quantiles is in good agreement with the theoretical
asymptotic variance.
q = replicate(10^5, as.numeric(
     quantile(rnorm(625, 100,15),.75) ))
var(q)
[1] 0.6679301

I am not sure exactly what null and alternative hypotheses
you will test and for what distribution. Of course, the 2-sample t test programmed into statistical software programs uses means and variances. I suppose power will be poorer using 75th percentiles than using means. Notice that the variance of a sample mean of $n=625$ observations from the normal distribution of my example above has variance $\sigma^2/n = 15^2/625 = 0.360 < 0.668.$
So I will leave
the rest to you.
Comment: very cool. Thank you very much!
Comment: Considering the heat around here today, I thought something very cool would be a good idea.
Comment: Maybe should have pointed out explicitly that the condition $0 < p < 1$ of the theorem excludes the max and the min. No CLT applies to max or min. They have 'extreme value' distributions.


How can I retrieve the profile2 fields selected in a custom module?

Question: I am totally new to entities in Drupal.  I have used the Profile2 module to add a few profile types.  This is displayed in the add/user screen as Customer.
After adding the profile type I manage the fields and add a new entry called cust with a field_id of field_cid.  This is setup as a list(text) and checkbox widget.
When I edit a user I have a checkbox list for Customer that can be selected by each user.  I have a custom module that I am trying to read the selected value by $user->uid from the profile2 field.
The idea is to retrieve the selected item in my module and format the return values to the user from a custom DB table.  Here is what I have tried and got results but cannot get all the values.
In my module using:
$profile = profile2_load_by_user($user->uid);$list = field_view_field('profile2', $profile['customer'], 'field_cid');print_r($list)

I get this result:
Array ( [#theme] => field [#weight] => 0 [#title] => cust [#access] => 1 [#label_display] => above [#view_mode] => _custom_display [#language] => und [#field_name] => field_cid [#field_type] => list_text [#field_translatable] => 0 [#entity_type] => profile2 [#bundle] => customer [#object] => Profile Object ( [pid] => 9 [type] => customer [label] => Customer [uid] => 1 [created] => 1409542969 [changed] => 1409545821 [entityType:protected] => profile2 [entityInfo:protected] => Array ( [label] => Profile [plural label] => Profiles [description] => Profile2 user profiles. [entity class] => Profile [controller class] => EntityAPIController [base table] => profile [fieldable] => 1 [view modes] => Array ( [account] => Array ( [label] => User account [custom settings] => ) ) [entity keys] => Array ( [id] => pid [bundle] => type [label] => label [revision] => ) [bundles] => Array ( [customer] => Array ( [label] => Customer [admin] => Array ( [path] => admin/structure/profiles/manage/%profile2_type [real path] => admin/structure/profiles/manage/customer [bundle argument] => 4 [access arguments] => Array ( [0] => administer profiles ) ) [rdf_mapping] => Array ( ) ) ) [bundle keys] => Array ( [bundle] => type ) [label callback] => entity_class_label [uri callback] => entity_class_uri [access callback] => profile2_access [module] => profile2 [metadata controller class] => Profile2MetadataController [static cache] => 1 [field cache] => 1 [load hook] => profile2_load [translation] => Array ( ) [schema_fields_sql] => Array ( [base table] => Array ( [0] => pid [1] => type [2] => uid [3] => label [4] => created [5] => changed ) ) [configuration] => ) [idKey:protected] => pid [nameKey:protected] => pid [statusKey:protected] => status [defaultLabel:protected] => [field_cid] => Array ( [und] => Array ( [0] => Array ( [value] => 1 ) [1] => Array ( [value] => 2 ) ) ) [field_test] => Array ( [und] => Array ( [0] => Array ( [value] => 3 ) ) ) [rdf_mapping] => Array ( ) ) [#items] => Array ( [0] => Array ( [value] => 1 ) [1] => Array ( [value] => 2 ) ) [#formatter] => list_default [0] => Array ( [#markup] => Disney ) [1] => Array ( [#markup] => Burger King ) )

I want the name in the last line [#markup] only returned to my function.  In the above output the returned values should be Disney and Burger King.
How can I retrieve these values only?
Answer: Finally this is giving me the results I am after:
$profile = profile2_load_by_user($user->uid);
$customer = field_get_items('profile2', $profile['customer'], 'field_cid');
$key = array();
foreach($customer as $item=>$value){
  $output = field_view_value('profile2', $profile['customer'], 'field_cid', $customer[$item]);
  $key[] = strip_tags(render($output));
}
foreach($key as $word) {
  echo $word . "
";
}


Calculate note timestamps

Question: I'm trying to develop an application that reads data from guitar pro file and then for each note in there, it gives me timestamps (with some other useful infos for sure).
However, it isn't trivial to get timestamps for each note, because calculating note duration doesn't look easy as I've tried a lot of ways already. None of them matched completely to what Guitar Pro app actually shows.
The easiest formula (that actually ignores time signature) I've tried is:
Let's say T is tempo, P is note duration (1 for whole, 0.5 for half, 0.25 for quarter and so on), then I tried two formulas (60 / T) × P and (60 / T) × P × 4. This doesn't work obviously, but I still tried because I've seen it somewhere on web.
Other formula I came up with is calculating measure (bar) durations in seconds, so I went like this:
If tempo is T and time signature numerator N, then formula looked like (60 / T) × N. And the idea behind this is that (60 / T) is duration of one beat, and because we have N beats in measure, I multiply those two values. Although I want note durations and not measure durations, if this was correct for measures, I would somehow split it with notes, but measure duration is already incorrect. One important factor regarding this formula though is that it actually works for common time (4/4) as long as it's something else (like 6/8) it messes up.
Also, I doubt in time signature the numerator doesn't always tell me the number of beats, although that's what its definition looks like. Because if I assume in guitar pro file with 6/8 time signature, 3 beats per measure, instead of 6, it looks correct. So I would like to clear doubts on this part as well.
Thanks a lot.
EDIT:
Sharing the code, using alphatab library.
//..omitted imports

const tempos = new Map();

function getPairValue(x, y) {
    return tempos.get([x, y].toString()) || null;
}

function bpmToQnpm(bpm, numerator, denominator) {
    let conversionFactor = 1; // Default for 4/4 time

    switch (denominator) {
        case 2: // Half note gets the beat
            conversionFactor = 2;
            break;
        case 4: // Quarter note gets the beat
            conversionFactor = 1; // This applies to 2/4, 3/4, and 4/4
            break;
        case 8: // Eighth note gets the beat
            if (numerator === 6 || numerator === 12) {
                // For 6/8 and 12/8, the dotted quarter note gets the beat
                conversionFactor = 1.5;
            } else {
                conversionFactor = 0.5;
            }
            break;
    }

    return bpm * conversionFactor;
}

function parseGpFile(filePath) {
    //..omitted

    let tempo = score.tempo;
    let currentTime = 0;

    const data = [];
    for (const measure of measures) {

        const beats = measure.voices.flatMap(voice => voice.beats);

        //In guitar pro as I see beat is just a group of notes played as the same time
        for (let i = 0; i < beats.length; i++) {
            const beat = beats[i];

            if (beat.isRest)
                continue;

            {
                let newTempo = getPairValue(measure.index, beat.index);
                if (newTempo)
                    tempo = newTempo;
            }

            let part = 1 / beat.duration;
            if (beat.dots === 1) {
                part += part / 2;
            } else if (beats.dots === 2) {
                part += part / 4;
            }

            const qnpm = bpmToQnpm(
                tempo,
                measure.masterBar.timeSignatureNumerator,
                measure.masterBar.timeSignatureDenominator);

            part *= 4;

            const beatDuration = (60 / qnpm) * part;

            let chord = [];
            for (const note of beat.notes) {
                chord.push({
                    'string': 7 - note.string,
                    'fret': note.fret,
                    'timestamp': currentTime
                });
            }

            data.push(chord);

            currentTime += beatDuration;
        }

    }

    return data;
}

Comment: Related:  [What is the connection between time-signature, beat, and tempo?](https://music.stackexchange.com/questions/3346),
[How to calculate music sheet symbols duration, in Midi file](https://music.stackexchange.com/questions/118776),
[How can I find the length in seconds of a quarter-note (crotchet) if I have a tempo marking?](https://music.stackexchange.com/questions/24140),
[How to figure out the length (time in ms) of a bar from bpm and time signature?](https://music.stackexchange.com/questions/109729)
Comment: What unit does T have? Quarters per minute, Measures per minute?
Comment: @Lazy Beats per minute
Answer: The reason your 6/8 calculation works when you assume 3 beats is that your formula assumes that a quarter note is always 1 beat. In 6/8 time, there are the mathematical equivalent of three quarter notes per measure, but not three beats per measure.
There is a similar problem with the first formula. 60/T gives "beats per second", so 60/T * P is clearly incorrect. Since P = whole note = 1, this formula assumes a whole note is one beat long.
Multiplying by 4 is correct, but only if the time signature denominator is 4.
What T should be, rather than "beats per minute" is "quarter-notes per minute". Then P = the proportion of the given note to a quarter note.
With those stipulations, the formula (60 / T) * P will work.
Comment: I tried but couldn't get it to work. First I converted bpm to "qnpm" (for example I got 78 qnpm for 52 bpm and 6/8) then I multiplied it with note duration (1 for whole, 0.5 for half, 0.25 for quarter and so on) and then by 4 and it still doesn't work. In the guitar pro file there are some time signature changes and the overall result I get is 6:37 while it should be 5:26.
Comment: @SandroJ My understanding is that tempi in Guitar Pro are already QNPM no matter what the time signature. What happens if you just treat the BPM and QNPM?
Comment: It says bpm, but as unit it says quarter note. I also tried without converting but no success.
Comment: @SandroJ Hmm.... Are you including rests in your calculation? If yes, it seems like there's some hidden issue. Are the calculations still as far off as described in your first comment?
Comment: If I don't actually include rest note, in overall it's close to what I'm aiming for but it's not perfect. I can share Javascript code if you can read it, I'm using alphatab library.
Comment: @SandroJ Weird. I would expect including rests to make it closer. Go ahead and share your code (put the link in your original question so others will see it, too), and I'll see if I can find anything.
Comment: Added to original question.
Comment: Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/147844/discussion-between-aaron-and-sandro-j).
Comment: Chat is closed unfortunately. Looks like different guitar pro file formats (gp3, gp4, gp5, gpx, etc) give different results for me. I don't know why this happens to be honest.

Calculate note timestamps


return statement missing in while loop

Question: I wrote some code for a "GPS Bluetooth receiver" it sends me continued data and I receive it, but I can not show that in my text-box.
Suggest me how to improve my code for continue data while 'while loop' not ended.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Enumeration;
import java.util.TooManyListenersException;

public class communication {
  public static CommPortIdentifier portId = null;

  public String com() throws UnsupportedCommOperationException, IOException,
      TooManyListenersException
  {
    int c = 1;

    String wantedPortName = "COM16";

    Enumeration portIdentifiers = CommPortIdentifier.getPortIdentifiers();

    while (portIdentifiers.hasMoreElements()) {
      CommPortIdentifier pid = (CommPortIdentifier) portIdentifiers.nextElement();
      if (pid.getPortType() == CommPortIdentifier.PORT_SERIAL
          && pid.getName().equals(wantedPortName)) {
        portId = pid;
        break;
      }
    }
    if (portId == null) {
      System.err.println("Could not find serial port " + wantedPortName);
      System.exit(1);
    } else {
      System.out.println("system find gps reciever");
    }
    SerialPort port = null;
    try {
      port = (SerialPort) portId.open("RMC", 1);
      System.out.println("all are ok");
    } catch (PortInUseException e) {
      System.err.println("Port already in use: " + e);
      System.exit(1);
    }
    // int i=Integer.parseInt(new vps().baud_rate.getItemAt(new vps().baud_rate.getItemCount()));
    port.setSerialPortParams(4800, SerialPort.DATABITS_8, SerialPort.STOPBITS_1,
        SerialPort.PARITY_NONE);

    BufferedReader is = null;

    try {
      is = new BufferedReader(new InputStreamReader(port.getInputStream()));
      System.out.println("data is ok");
    } catch (IOException e) {
      System.err.println("Can't open input stream: write-only");
      is = null;
    }

    while (new test().bp)// this is variable is ouside of class and define by public it work
    {

      String st = is.readLine();

      // System.out.println(st);
      // st = st.replace(st, "");

      return st;

    }
    if (is != null)
      is.close();

    if (port != null)
      port.close();

  }
}

test class code...
import java.io.IOException;
import java.util.TooManyListenersException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.comm.UnsupportedCommOperationException;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * test.java
 *
 * Created on Mar 11, 2013, 9:08:52 AM
 */
/**
 *
 * @author DJ ROCKS
 */
public class test extends javax.swing.JFrame {
    public boolean bp=false;

    /** Creates new form test */
    public test() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        ok = new javax.swing.JButton();
        a = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        ok.setText("ok");
        ok.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okActionPerformed(evt);
            }
        });

        a.setText(" ");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(62, 62, 62)
                        .addComponent(a, javax.swing.GroupLayout.PREFERRED_SIZE, 394, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(238, 238, 238)
                        .addComponent(ok)))
                .addContainerGap(124, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(a, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(67, 67, 67)
                .addComponent(ok)
                .addContainerGap(160, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>

    private void okActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        bp=true;
        if(evt.getSource()==ok)
        {
            try {
                a.setText(new communication().com());
            } catch (UnsupportedCommOperationException ex) {
                Logger.getLogger(test.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(test.class.getName()).log(Level.SEVERE, null, ex);
            } catch (TooManyListenersException ex) {
                Logger.getLogger(test.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new test().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify
    private javax.swing.JTextField a;
    private javax.swing.JButton ok;
    // End of variables declaration
}

when i run this code compiler display such error....
Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Uncompilable source code - missing return statement
at communication.com(communication.java:14)
at test.okActionPerformed(test.java:86)
at test.access$000(test.java:22)
at test$1.actionPerformed(test.java:47)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:723)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:682)
at java.awt.EventQueue$3.run(EventQueue.java:680)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:696)
at java.awt.EventQueue$4.run(EventQueue.java:694)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:693)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)

Answer: This is the end of your function:
while(new test().bp)//this is variable is ouside of class and define by public it work
{

   st = is.readLine();
   return st;
}
if (is != null) is.close();
if (port != null) port.close();

If bp is false, you exit the while loop without returning.  In that case you close is and port, and then... don't have a return statement.   So the compiler doesn't know what it should return if that happens.
Incidentally, that loop logic makes no sense, as it's a glorified "if" - if you return, you can't possibly loop again.
Comment: so how can i get continue loop??

return statement missing in while loop